diff --git a/solution/0200-0299/0237.Delete Node in a Linked List/README.md b/solution/0200-0299/0237.Delete Node in a Linked List/README.md index d6779914fcde8..49aeda52a5de0 100644 --- a/solution/0200-0299/0237.Delete Node in a Linked List/README.md +++ b/solution/0200-0299/0237.Delete Node in a Linked List/README.md @@ -128,4 +128,24 @@ func deleteNode(node *ListNode) { } ``` +### **C++** + +```cpp +/** + * Definition for singly-linked list. + * struct ListNode { + * int val; + * ListNode *next; + * ListNode(int x) : val(x), next(NULL) {} + * }; + */ +class Solution { +public: + void deleteNode(ListNode* node) { + node->val = node->next->val; + node->next = node->next->next; + } +}; +``` + diff --git a/solution/0200-0299/0237.Delete Node in a Linked List/README_EN.md b/solution/0200-0299/0237.Delete Node in a Linked List/README_EN.md index 3226d4d1bed31..165906c7e1d6d 100644 --- a/solution/0200-0299/0237.Delete Node in a Linked List/README_EN.md +++ b/solution/0200-0299/0237.Delete Node in a Linked List/README_EN.md @@ -135,4 +135,24 @@ func deleteNode(node *ListNode) { } ``` +### **C++** + +```cpp +/** + * Definition for singly-linked list. + * struct ListNode { + * int val; + * ListNode *next; + * ListNode(int x) : val(x), next(NULL) {} + * }; + */ +class Solution { +public: + void deleteNode(ListNode* node) { + node->val = node->next->val; + node->next = node->next->next; + } +}; +``` + diff --git a/solution/0200-0299/0237.Delete Node in a Linked List/Solution.c b/solution/0200-0299/0237.Delete Node in a Linked List/Solution.c new file mode 100644 index 0000000000000..365959e73a289 --- /dev/null +++ b/solution/0200-0299/0237.Delete Node in a Linked List/Solution.c @@ -0,0 +1,11 @@ +/** + * Definition for singly-linked list. + * struct ListNode { + * int val; + * struct ListNode *next; + * }; + */ +void deleteNode(struct ListNode* node) { + node->val = node->next->val; + node->next = node->next->next; +} \ No newline at end of file diff --git a/solution/0200-0299/0237.Delete Node in a Linked List/Solution.cpp b/solution/0200-0299/0237.Delete Node in a Linked List/Solution.cpp new file mode 100644 index 0000000000000..cfc84af6b77ac --- /dev/null +++ b/solution/0200-0299/0237.Delete Node in a Linked List/Solution.cpp @@ -0,0 +1,15 @@ +/** + * Definition for singly-linked list. + * struct ListNode { + * int val; + * ListNode *next; + * ListNode(int x) : val(x), next(NULL) {} + * }; + */ +class Solution { +public: + void deleteNode(ListNode* node) { + node->val = node->next->val; + node->next = node->next->next; + } +}; \ No newline at end of file diff --git a/solution/1800-1899/1884.Egg Drop With 2 Eggs and N Floors/README.md b/solution/1800-1899/1884.Egg Drop With 2 Eggs and N Floors/README.md index bd433b66c88a8..472bdd5c73829 100644 --- a/solution/1800-1899/1884.Egg Drop With 2 Eggs and N Floors/README.md +++ b/solution/1800-1899/1884.Egg Drop With 2 Eggs and N Floors/README.md @@ -1,4 +1,4 @@ -# [1884. ](https://leetcode-cn.com/problems/egg-drop-with-2-eggs-and-n-floors) +# [1884. 鸡蛋掉落-两枚鸡蛋](https://leetcode-cn.com/problems/egg-drop-with-2-eggs-and-n-floors) [English Version](/solution/1800-1899/1884.Egg%20Drop%20With%202%20Eggs%20and%20N%20Floors/README_EN.md) @@ -6,7 +6,42 @@ -None +

给你 2 枚相同 的鸡蛋,和一栋从第 1 层到第 n 层共有 n 层楼的建筑。

+ +

已知存在楼层 f ,满足 0 <= f <= n ,任何从 高于 f 的楼层落下的鸡蛋都 会碎 ,从 f 楼层或比它低 的楼层落下的鸡蛋都 不会碎

+ +

每次操作,你可以取一枚 没有碎 的鸡蛋并把它从任一楼层 x 扔下(满足 1 <= x <= n)。如果鸡蛋碎了,你就不能再次使用它。如果某枚鸡蛋扔下后没有摔碎,则可以在之后的操作中 重复使用 这枚鸡蛋。

+ +

请你计算并返回要确定 f 确切的值 最小操作次数 是多少?

+ +

 

+ +

示例 1:

+ +
+输入:n = 2
+输出:2
+解释:我们可以将第一枚鸡蛋从 1 楼扔下,然后将第二枚从 2 楼扔下。
+如果第一枚鸡蛋碎了,可知 f = 0;
+如果第二没鸡蛋碎了,但第一枚没碎,可知 f = 1;
+否则,当两个鸡蛋都没碎时,可知 f = 2。
+
+ +

示例 2:

+ +
+输入:n = 100
+输出:14
+
+ +

 

+ +

提示:

+ + + ## 解法 diff --git a/solution/1800-1899/1886.Determine Whether Matrix Can Be Obtained By Rotation/README.md b/solution/1800-1899/1886.Determine Whether Matrix Can Be Obtained By Rotation/README.md new file mode 100644 index 0000000000000..a50dcefaed3e1 --- /dev/null +++ b/solution/1800-1899/1886.Determine Whether Matrix Can Be Obtained By Rotation/README.md @@ -0,0 +1,130 @@ +# [1886. 判断矩阵经轮转后是否一致](https://leetcode-cn.com/problems/determine-whether-matrix-can-be-obtained-by-rotation) + +[English Version](/solution/1800-1899/1886.Determine%20Whether%20Matrix%20Can%20Be%20Obtained%20By%20Rotation/README_EN.md) + +## 题目描述 + + + +

给你两个大小为 n x n 的二进制矩阵 mattarget 。现 以 90 度顺时针轮转 矩阵 mat 中的元素 若干次 ,如果能够使 mat 与 target 一致,返回 true ;否则,返回 false

+ +

 

+ +

示例 1:

+ +
+输入:mat = [[0,1],[1,0]], target = [[1,0],[0,1]]
+输出:true
+解释:顺时针轮转 90 度一次可以使 mat 和 target 一致。
+
+ +

示例 2:

+ +
+输入:mat = [[0,1],[1,1]], target = [[1,0],[0,1]]
+输出:false
+解释:无法通过轮转矩阵中的元素使 equal 与 target 一致。
+
+ +

示例 3:

+ +
+输入:mat = [[0,0,0],[0,1,0],[1,1,1]], target = [[1,1,1],[0,1,0],[0,0,0]]
+输出:true
+解释:顺时针轮转 90 度两次可以使 mat 和 target 一致。
+
+ +

 

+ +

提示:

+ + + + +## 解法 + + + +旋转矩阵,判断矩阵是否一致。 + + + +### **Python3** + + + +```python +class Solution: + def findRotation(self, mat: List[List[int]], target: List[List[int]]) -> bool: + def rotate(matrix): + n = len(matrix) + for i in range(n // 2): + for j in range(i, n - 1 - i): + t = matrix[i][j] + matrix[i][j] = matrix[n - j - 1][i] + matrix[n - j - 1][i] = matrix[n - i - 1][n - j - 1] + matrix[n - i - 1][n - j - 1] = matrix[j][n - i - 1] + matrix[j][n - i - 1] = t + for _ in range(4): + if mat == target: + return True + rotate(mat) + return False +``` + +### **Java** + + + +```java +class Solution { + public boolean findRotation(int[][] mat, int[][] target) { + int times = 4; + while (times-- > 0) { + if (equals(mat, target)) { + return true; + } + rotate(mat); + } + return false; + } + + private void rotate(int[][] matrix) { + int n = matrix.length; + for (int i = 0; i < n / 2; ++i) { + for (int j = i; j < n - 1 - i; ++j) { + int t = matrix[i][j]; + matrix[i][j] = matrix[n - j - 1][i]; + matrix[n - j - 1][i] = matrix[n - i - 1][n - j - 1]; + matrix[n - i - 1][n - j - 1] = matrix[j][n - i - 1]; + matrix[j][n - i - 1] = t; + } + } + } + + private boolean equals(int[][] nums1, int[][] nums2) { + int n = nums1.length; + for (int i = 0; i < n; ++i) { + for (int j = 0; j < n; ++j) { + if (nums1[i][j] != nums2[i][j]) { + return false; + } + } + } + return true; + } +} +``` + +### **...** + +``` + +``` + + diff --git a/solution/1800-1899/1886.Determine Whether Matrix Can Be Obtained By Rotation/README_EN.md b/solution/1800-1899/1886.Determine Whether Matrix Can Be Obtained By Rotation/README_EN.md new file mode 100644 index 0000000000000..9103fc2bf7a4c --- /dev/null +++ b/solution/1800-1899/1886.Determine Whether Matrix Can Be Obtained By Rotation/README_EN.md @@ -0,0 +1,118 @@ +# [1886. Determine Whether Matrix Can Be Obtained By Rotation](https://leetcode.com/problems/determine-whether-matrix-can-be-obtained-by-rotation) + +[中文文档](/solution/1800-1899/1886.Determine%20Whether%20Matrix%20Can%20Be%20Obtained%20By%20Rotation/README.md) + +## Description + +

Given two n x n binary matrices mat and target, return true if it is possible to make mat equal to target by rotating mat in 90-degree increments, or false otherwise.

+ +

 

+

Example 1:

+ +
+Input: mat = [[0,1],[1,0]], target = [[1,0],[0,1]]
+Output: true
+Explanation: We can rotate mat 90 degrees clockwise to make mat equal target.
+
+ +

Example 2:

+ +
+Input: mat = [[0,1],[1,1]], target = [[1,0],[0,1]]
+Output: false
+Explanation: It is impossible to make mat equal to target by rotating mat.
+
+ +

Example 3:

+ +
+Input: mat = [[0,0,0],[0,1,0],[1,1,1]], target = [[1,1,1],[0,1,0],[0,0,0]]
+Output: true
+Explanation: We can rotate mat 90 degrees clockwise two times to make mat equal target.
+
+ +

 

+

Constraints:

+ + + + +## Solutions + + + +### **Python3** + +```python +class Solution: + def findRotation(self, mat: List[List[int]], target: List[List[int]]) -> bool: + def rotate(matrix): + n = len(matrix) + for i in range(n // 2): + for j in range(i, n - 1 - i): + t = matrix[i][j] + matrix[i][j] = matrix[n - j - 1][i] + matrix[n - j - 1][i] = matrix[n - i - 1][n - j - 1] + matrix[n - i - 1][n - j - 1] = matrix[j][n - i - 1] + matrix[j][n - i - 1] = t + for _ in range(4): + if mat == target: + return True + rotate(mat) + return False +``` + +### **Java** + +```java +class Solution { + public boolean findRotation(int[][] mat, int[][] target) { + int times = 4; + while (times-- > 0) { + if (equals(mat, target)) { + return true; + } + rotate(mat); + } + return false; + } + + private void rotate(int[][] matrix) { + int n = matrix.length; + for (int i = 0; i < n / 2; ++i) { + for (int j = i; j < n - 1 - i; ++j) { + int t = matrix[i][j]; + matrix[i][j] = matrix[n - j - 1][i]; + matrix[n - j - 1][i] = matrix[n - i - 1][n - j - 1]; + matrix[n - i - 1][n - j - 1] = matrix[j][n - i - 1]; + matrix[j][n - i - 1] = t; + } + } + } + + private boolean equals(int[][] nums1, int[][] nums2) { + int n = nums1.length; + for (int i = 0; i < n; ++i) { + for (int j = 0; j < n; ++j) { + if (nums1[i][j] != nums2[i][j]) { + return false; + } + } + } + return true; + } +} +``` + +### **...** + +``` + +``` + + diff --git a/solution/1800-1899/1886.Determine Whether Matrix Can Be Obtained By Rotation/Solution.java b/solution/1800-1899/1886.Determine Whether Matrix Can Be Obtained By Rotation/Solution.java new file mode 100644 index 0000000000000..7693913020371 --- /dev/null +++ b/solution/1800-1899/1886.Determine Whether Matrix Can Be Obtained By Rotation/Solution.java @@ -0,0 +1,37 @@ +class Solution { + public boolean findRotation(int[][] mat, int[][] target) { + int times = 4; + while (times-- > 0) { + if (equals(mat, target)) { + return true; + } + rotate(mat); + } + return false; + } + + private void rotate(int[][] matrix) { + int n = matrix.length; + for (int i = 0; i < n / 2; ++i) { + for (int j = i; j < n - 1 - i; ++j) { + int t = matrix[i][j]; + matrix[i][j] = matrix[n - j - 1][i]; + matrix[n - j - 1][i] = matrix[n - i - 1][n - j - 1]; + matrix[n - i - 1][n - j - 1] = matrix[j][n - i - 1]; + matrix[j][n - i - 1] = t; + } + } + } + + private boolean equals(int[][] nums1, int[][] nums2) { + int n = nums1.length; + for (int i = 0; i < n; ++i) { + for (int j = 0; j < n; ++j) { + if (nums1[i][j] != nums2[i][j]) { + return false; + } + } + } + return true; + } +} \ No newline at end of file diff --git a/solution/1800-1899/1886.Determine Whether Matrix Can Be Obtained By Rotation/Solution.py b/solution/1800-1899/1886.Determine Whether Matrix Can Be Obtained By Rotation/Solution.py new file mode 100644 index 0000000000000..5f3584316c233 --- /dev/null +++ b/solution/1800-1899/1886.Determine Whether Matrix Can Be Obtained By Rotation/Solution.py @@ -0,0 +1,16 @@ +class Solution: + def findRotation(self, mat: List[List[int]], target: List[List[int]]) -> bool: + def rotate(matrix): + n = len(matrix) + for i in range(n // 2): + for j in range(i, n - 1 - i): + t = matrix[i][j] + matrix[i][j] = matrix[n - j - 1][i] + matrix[n - j - 1][i] = matrix[n - i - 1][n - j - 1] + matrix[n - i - 1][n - j - 1] = matrix[j][n - i - 1] + matrix[j][n - i - 1] = t + for _ in range(4): + if mat == target: + return True + rotate(mat) + return False diff --git a/solution/1800-1899/1886.Determine Whether Matrix Can Be Obtained By Rotation/images/grid3.png b/solution/1800-1899/1886.Determine Whether Matrix Can Be Obtained By Rotation/images/grid3.png new file mode 100644 index 0000000000000..740655873133d Binary files /dev/null and b/solution/1800-1899/1886.Determine Whether Matrix Can Be Obtained By Rotation/images/grid3.png differ diff --git a/solution/1800-1899/1886.Determine Whether Matrix Can Be Obtained By Rotation/images/grid4-1.png b/solution/1800-1899/1886.Determine Whether Matrix Can Be Obtained By Rotation/images/grid4-1.png new file mode 100644 index 0000000000000..1e6eccbccbee0 Binary files /dev/null and b/solution/1800-1899/1886.Determine Whether Matrix Can Be Obtained By Rotation/images/grid4-1.png differ diff --git a/solution/1800-1899/1886.Determine Whether Matrix Can Be Obtained By Rotation/images/grid4.png b/solution/1800-1899/1886.Determine Whether Matrix Can Be Obtained By Rotation/images/grid4.png new file mode 100644 index 0000000000000..469e5ed88e798 Binary files /dev/null and b/solution/1800-1899/1886.Determine Whether Matrix Can Be Obtained By Rotation/images/grid4.png differ diff --git a/solution/1800-1899/1887.Reduction Operations to Make the Array Elements Equal/README.md b/solution/1800-1899/1887.Reduction Operations to Make the Array Elements Equal/README.md new file mode 100644 index 0000000000000..f3eb143419ac8 --- /dev/null +++ b/solution/1800-1899/1887.Reduction Operations to Make the Array Elements Equal/README.md @@ -0,0 +1,114 @@ +# [1887. 使数组元素相等的减少操作次数](https://leetcode-cn.com/problems/reduction-operations-to-make-the-array-elements-equal) + +[English Version](/solution/1800-1899/1887.Reduction%20Operations%20to%20Make%20the%20Array%20Elements%20Equal/README_EN.md) + +## 题目描述 + + + +

给你一个整数数组 nums ,你的目标是令 nums 中的所有元素相等。完成一次减少操作需要遵照下面的几个步骤:

+ +
    +
  1. 找出 nums 中的 最大 值。记这个值为 largest 并取其下标 i下标从 0 开始计数)。如果有多个元素都是最大值,则取最小的 i
  2. +
  3. 找出 nums 中的 下一个最大 值,这个值 严格小于 largest ,记为 nextLargest
  4. +
  5. nums[i] 减少到 nextLargest
  6. +
+ +

返回使 nums 中的所有元素相等的操作次数。

+ +

 

+ +

示例 1:

+ +
+输入:nums = [5,1,3]
+输出:3
+解释:需要 3 次操作使 nums 中的所有元素相等:
+1. largest = 5 下标为 0 。nextLargest = 3 。将 nums[0] 减少到 3 。nums = [3,1,3] 。
+2. largest = 3 下标为 0 。nextLargest = 1 。将 nums[0] 减少到 1 。nums = [1,1,3] 。
+3. largest = 3 下标为 2 。nextLargest = 1 。将 nums[2] 减少到 1 。nums = [1,1,1] 。
+
+ +

示例 2:

+ +
+输入:nums = [1,1,1]
+输出:0
+解释:nums 中的所有元素已经是相等的。
+
+ +

示例 3:

+ +
+输入:nums = [1,1,2,2,3]
+输出:4
+解释:需要 4 次操作使 nums 中的所有元素相等:
+1. largest = 3 下标为 4 。nextLargest = 2 。将 nums[4] 减少到 2 。nums = [1,1,2,2,2] 。
+2. largest = 2 下标为 2 。nextLargest = 1 。将 nums[2] 减少到 1 。nums = [1,1,1,2,2] 。 
+3. largest = 2 下标为 3 。nextLargest = 1 。将 nums[3] 减少到 1 。nums = [1,1,1,1,2] 。 
+4. largest = 2 下标为 4 。nextLargest = 1 。将 nums[4] 减少到 1 。nums = [1,1,1,1,1] 。
+
+ +

 

+ +

提示:

+ + + + +## 解法 + + + +“有序字典”实现。 + + + +### **Python3** + + + +```python +class Solution: + def reductionOperations(self, nums: List[int]) -> int: + counter = collections.Counter(nums) + f = res = 0 + n = len(nums) + for _, v in sorted(counter.items(), key=lambda x: x[0]): + f += v + res += (n - f) + return res +``` + +### **Java** + + + +```java +class Solution { + public int reductionOperations(int[] nums) { + TreeMap counter = new TreeMap<>(); + for (int num : nums) { + counter.put(num, counter.getOrDefault(num, 0) + 1); + } + int n = nums.length; + int f = 0, res = 0; + while (counter.size() != 0) { + f += counter.pollFirstEntry().getValue(); + res += (n - f); + } + return res; + } +} +``` + +### **...** + +``` + +``` + + diff --git a/solution/1800-1899/1887.Reduction Operations to Make the Array Elements Equal/README_EN.md b/solution/1800-1899/1887.Reduction Operations to Make the Array Elements Equal/README_EN.md new file mode 100644 index 0000000000000..b25fffe4a18f1 --- /dev/null +++ b/solution/1800-1899/1887.Reduction Operations to Make the Array Elements Equal/README_EN.md @@ -0,0 +1,102 @@ +# [1887. Reduction Operations to Make the Array Elements Equal](https://leetcode.com/problems/reduction-operations-to-make-the-array-elements-equal) + +[中文文档](/solution/1800-1899/1887.Reduction%20Operations%20to%20Make%20the%20Array%20Elements%20Equal/README.md) + +## Description + +

Given an integer array nums, your goal is to make all elements in nums equal. To complete one operation, follow these steps:

+ +
    +
  1. Find the largest value in nums. Let its index be i (0-indexed) and its value be largest. If there are multiple elements with the largest value, pick the smallest i.
  2. +
  3. Find the next largest value in nums strictly smaller than largest. Let its value be nextLargest.
  4. +
  5. Reduce nums[i] to nextLargest.
  6. +
+ +

Return the number of operations to make all elements in nums equal.

+ +

 

+

Example 1:

+ +
+Input: nums = [5,1,3]
+Output: 3
+Explanation: It takes 3 operations to make all elements in nums equal:
+1. largest = 5 at index 0. nextLargest = 3. Reduce nums[0] to 3. nums = [3,1,3].
+2. largest = 3 at index 0. nextLargest = 1. Reduce nums[0] to 1. nums = [1,1,3].
+3. largest = 3 at index 2. nextLargest = 1. Reduce nums[2] to 1. nums = [1,1,1].
+
+ +

Example 2:

+ +
+Input: nums = [1,1,1]
+Output: 0
+Explanation: All elements in nums are already equal.
+
+ +

Example 3:

+ +
+Input: nums = [1,1,2,2,3]
+Output: 4
+Explanation: It takes 4 operations to make all elements in nums equal:
+1. largest = 3 at index 4. nextLargest = 2. Reduce nums[4] to 2. nums = [1,1,2,2,2].
+2. largest = 2 at index 2. nextLargest = 1. Reduce nums[2] to 1. nums = [1,1,1,2,2].
+3. largest = 2 at index 3. nextLargest = 1. Reduce nums[3] to 1. nums = [1,1,1,1,2].
+4. largest = 2 at index 4. nextLargest = 1. Reduce nums[4] to 1. nums = [1,1,1,1,1].
+
+ +

 

+

Constraints:

+ + + + +## Solutions + + + +### **Python3** + +```python +class Solution: + def reductionOperations(self, nums: List[int]) -> int: + counter = collections.Counter(nums) + f = res = 0 + n = len(nums) + for _, v in sorted(counter.items(), key=lambda x: x[0]): + f += v + res += (n - f) + return res +``` + +### **Java** + +```java +class Solution { + public int reductionOperations(int[] nums) { + TreeMap counter = new TreeMap<>(); + for (int num : nums) { + counter.put(num, counter.getOrDefault(num, 0) + 1); + } + int n = nums.length; + int f = 0, res = 0; + while (counter.size() != 0) { + f += counter.pollFirstEntry().getValue(); + res += (n - f); + } + return res; + } +} +``` + +### **...** + +``` + +``` + + diff --git a/solution/1800-1899/1887.Reduction Operations to Make the Array Elements Equal/Solution.java b/solution/1800-1899/1887.Reduction Operations to Make the Array Elements Equal/Solution.java new file mode 100644 index 0000000000000..c73506fdce1a2 --- /dev/null +++ b/solution/1800-1899/1887.Reduction Operations to Make the Array Elements Equal/Solution.java @@ -0,0 +1,15 @@ +class Solution { + public int reductionOperations(int[] nums) { + TreeMap counter = new TreeMap<>(); + for (int num : nums) { + counter.put(num, counter.getOrDefault(num, 0) + 1); + } + int n = nums.length; + int f = 0, res = 0; + while (counter.size() != 0) { + f += counter.pollFirstEntry().getValue(); + res += (n - f); + } + return res; + } +} \ No newline at end of file diff --git a/solution/1800-1899/1887.Reduction Operations to Make the Array Elements Equal/Solution.py b/solution/1800-1899/1887.Reduction Operations to Make the Array Elements Equal/Solution.py new file mode 100644 index 0000000000000..1e24f2fb87756 --- /dev/null +++ b/solution/1800-1899/1887.Reduction Operations to Make the Array Elements Equal/Solution.py @@ -0,0 +1,9 @@ +class Solution: + def reductionOperations(self, nums: List[int]) -> int: + counter = collections.Counter(nums) + f = res = 0 + n = len(nums) + for _, v in sorted(counter.items(), key=lambda x: x[0]): + f += v + res += (n - f) + return res diff --git a/solution/1800-1899/1888.Minimum Number of Flips to Make the Binary String Alternating/README.md b/solution/1800-1899/1888.Minimum Number of Flips to Make the Binary String Alternating/README.md new file mode 100644 index 0000000000000..17d8353b4d00f --- /dev/null +++ b/solution/1800-1899/1888.Minimum Number of Flips to Make the Binary String Alternating/README.md @@ -0,0 +1,117 @@ +# [1888. 使二进制字符串字符交替的最少反转次数](https://leetcode-cn.com/problems/minimum-number-of-flips-to-make-the-binary-string-alternating) + +[English Version](/solution/1800-1899/1888.Minimum%20Number%20of%20Flips%20to%20Make%20the%20Binary%20String%20Alternating/README_EN.md) + +## 题目描述 + + + +

给你一个二进制字符串 s 。你可以按任意顺序执行以下两种操作任意次:

+ +
    +
  • 类型 1 :删除 字符串 s 的第一个字符并将它 添加 到字符串结尾。
  • +
  • 类型 2 :选择 字符串 s 中任意一个字符并将该字符 反转 ,也就是如果值为 '0' ,则反转得到 '1' ,反之亦然。
  • +
+ +

请你返回使 s 变成 交替 字符串的前提下, 类型 2 最少 操作次数 。

+ +

我们称一个字符串是 交替 的,需要满足任意相邻字符都不同。

+ +
    +
  • 比方说,字符串 "010" 和 "1010" 都是交替的,但是字符串 "0100" 不是。
  • +
+ +

 

+ +

示例 1:

+ +
输入:s = "111000"
+输出:2
+解释:执行第一种操作两次,得到 s = "100011" 。
+然后对第三个和第六个字符执行第二种操作,得到 s = "101010" 。
+
+ +

示例 2:

+ +
输入:s = "010"
+输出:0
+解释:字符串已经是交替的。
+
+ +

示例 3:

+ +
输入:s = "1110"
+输出:1
+解释:对第二个字符执行第二种操作,得到 s = "1010" 。
+
+ +

 

+ +

提示:

+ +
    +
  • 1 <= s.length <= 105
  • +
  • s[i] 要么是 '0' ,要么是 '1' 。
  • +
+ +## 解法 + + + +“双倍字符串 + 滑动窗口”实现。 + + + +### **Python3** + + + +```python +class Solution: + def minFlips(self, s: str) -> int: + n = len(s) + target = '01' + cnt = 0 + for i, c in enumerate(s): + cnt += c != target[i & 1] + res = min(cnt, n - cnt) + s *= 2 + for i in range(n): + cnt -= s[i] != target[i & 1] + cnt += s[i + n] != target[(i + n) & 1] + res = min(res, cnt, n - cnt) + return res +``` + +### **Java** + + + +```java +class Solution { + public int minFlips(String s) { + int n = s.length(); + String target = "01"; + int cnt = 0; + for (int i = 0; i < n; ++i) { + cnt += (s.charAt(i) == target.charAt(i & 1) ? 0 : 1); + } + int res = Math.min(cnt, n - cnt); + s += s; + for (int i = 0; i < n; ++i) { + cnt -= (s.charAt(i) == target.charAt(i & 1) ? 0 : 1); + cnt += (s.charAt(i + n) == target.charAt((i + n) & 1) ? 0 : 1); + res = Math.min(res, Math.min(cnt, n - cnt)); + } + return res; + } +} +``` + +### **...** + +``` + +``` + + diff --git a/solution/1800-1899/1888.Minimum Number of Flips to Make the Binary String Alternating/README_EN.md b/solution/1800-1899/1888.Minimum Number of Flips to Make the Binary String Alternating/README_EN.md new file mode 100644 index 0000000000000..00e3bf656bd39 --- /dev/null +++ b/solution/1800-1899/1888.Minimum Number of Flips to Make the Binary String Alternating/README_EN.md @@ -0,0 +1,109 @@ +# [1888. Minimum Number of Flips to Make the Binary String Alternating](https://leetcode.com/problems/minimum-number-of-flips-to-make-the-binary-string-alternating) + +[中文文档](/solution/1800-1899/1888.Minimum%20Number%20of%20Flips%20to%20Make%20the%20Binary%20String%20Alternating/README.md) + +## Description + +

You are given a binary string s. You are allowed to perform two types of operations on the string in any sequence:

+ +
    +
  • Type-1: Remove the character at the start of the string s and append it to the end of the string.
  • +
  • Type-2: Pick any character in s and flip its value, i.e., if its value is '0' it becomes '1' and vice-versa.
  • +
+ +

Return the minimum number of type-2 operations you need to perform such that s becomes alternating.

+ +

The string is called alternating if no two adjacent characters are equal.

+ +
    +
  • For example, the strings "010" and "1010" are alternating, while the string "0100" is not.
  • +
+ +

 

+

Example 1:

+ +
+Input: s = "111000"
+Output: 2
+Explanation: Use the first operation two times to make s = "100011".
+Then, use the second operation on the third and sixth elements to make s = "101010".
+
+ +

Example 2:

+ +
+Input: s = "010"
+Output: 0
+Explanation: The string is already alternating.
+
+ +

Example 3:

+ +
+Input: s = "1110"
+Output: 1
+Explanation: Use the second operation on the second element to make s = "1010".
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 105
  • +
  • s[i] is either '0' or '1'.
  • +
+ + +## Solutions + + + +### **Python3** + +```python +class Solution: + def minFlips(self, s: str) -> int: + n = len(s) + target = '01' + cnt = 0 + for i, c in enumerate(s): + cnt += c != target[i & 1] + res = min(cnt, n - cnt) + s *= 2 + for i in range(n): + cnt -= s[i] != target[i & 1] + cnt += s[i + n] != target[(i + n) & 1] + res = min(res, cnt, n - cnt) + return res +``` + +### **Java** + +```java +class Solution { + public int minFlips(String s) { + int n = s.length(); + String target = "01"; + int cnt = 0; + for (int i = 0; i < n; ++i) { + cnt += (s.charAt(i) == target.charAt(i & 1) ? 0 : 1); + } + int res = Math.min(cnt, n - cnt); + s += s; + for (int i = 0; i < n; ++i) { + cnt -= (s.charAt(i) == target.charAt(i & 1) ? 0 : 1); + cnt += (s.charAt(i + n) == target.charAt((i + n) & 1) ? 0 : 1); + res = Math.min(res, Math.min(cnt, n - cnt)); + } + return res; + } +} +``` + +### **...** + +``` + +``` + + diff --git a/solution/1800-1899/1888.Minimum Number of Flips to Make the Binary String Alternating/Solution.java b/solution/1800-1899/1888.Minimum Number of Flips to Make the Binary String Alternating/Solution.java new file mode 100644 index 0000000000000..821fbf234d0af --- /dev/null +++ b/solution/1800-1899/1888.Minimum Number of Flips to Make the Binary String Alternating/Solution.java @@ -0,0 +1,18 @@ +class Solution { + public int minFlips(String s) { + int n = s.length(); + String target = "01"; + int cnt = 0; + for (int i = 0; i < n; ++i) { + cnt += (s.charAt(i) == target.charAt(i & 1) ? 0 : 1); + } + int res = Math.min(cnt, n - cnt); + s += s; + for (int i = 0; i < n; ++i) { + cnt -= (s.charAt(i) == target.charAt(i & 1) ? 0 : 1); + cnt += (s.charAt(i + n) == target.charAt((i + n) & 1) ? 0 : 1); + res = Math.min(res, Math.min(cnt, n - cnt)); + } + return res; + } +} \ No newline at end of file diff --git a/solution/1800-1899/1888.Minimum Number of Flips to Make the Binary String Alternating/Solution.py b/solution/1800-1899/1888.Minimum Number of Flips to Make the Binary String Alternating/Solution.py new file mode 100644 index 0000000000000..59d195271fbbc --- /dev/null +++ b/solution/1800-1899/1888.Minimum Number of Flips to Make the Binary String Alternating/Solution.py @@ -0,0 +1,14 @@ +class Solution: + def minFlips(self, s: str) -> int: + n = len(s) + target = '01' + cnt = 0 + for i, c in enumerate(s): + cnt += c != target[i & 1] + res = min(cnt, n - cnt) + s *= 2 + for i in range(n): + cnt -= s[i] != target[i & 1] + cnt += s[i + n] != target[(i + n) & 1] + res = min(res, cnt, n - cnt) + return res diff --git a/solution/1800-1899/1889.Minimum Space Wasted From Packaging/README.md b/solution/1800-1899/1889.Minimum Space Wasted From Packaging/README.md new file mode 100644 index 0000000000000..5a4be5b865f10 --- /dev/null +++ b/solution/1800-1899/1889.Minimum Space Wasted From Packaging/README.md @@ -0,0 +1,150 @@ +# [1889. 装包裹的最小浪费空间](https://leetcode-cn.com/problems/minimum-space-wasted-from-packaging) + +[English Version](/solution/1800-1899/1889.Minimum%20Space%20Wasted%20From%20Packaging/README_EN.md) + +## 题目描述 + + + +

给你 n 个包裹,你需要把它们装在箱子里,每个箱子装一个包裹。总共有 m 个供应商提供 不同尺寸 的箱子(每个规格都有无数个箱子)。如果一个包裹的尺寸 小于等于 一个箱子的尺寸,那么这个包裹就可以放入这个箱子之中。

+ +

包裹的尺寸用一个整数数组 packages 表示,其中 packages[i] 是第 i 个包裹的尺寸。供应商用二维数组 boxes 表示,其中 boxes[j] 是第 j 个供应商提供的所有箱子尺寸的数组。

+ +

你想要选择 一个供应商 并只使用该供应商提供的箱子,使得 总浪费空间最小 。对于每个装了包裹的箱子,我们定义 浪费的 空间等于 箱子的尺寸 - 包裹的尺寸 。总浪费空间 为 所有 箱子中浪费空间的总和。

+ +
    +
  • 比方说,如果你想要用尺寸数组为 [4,8] 的箱子装下尺寸为 [2,3,5] 的包裹,你可以将尺寸为 2 和 3 的两个包裹装入两个尺寸为 4 的箱子中,同时把尺寸为 5 的包裹装入尺寸为 8 的箱子中。总浪费空间为 (4-2) + (4-3) + (8-5) = 6 。
  • +
+ +

请你选择 最优 箱子供应商,使得 总浪费空间最小 。如果 无法 将所有包裹放入箱子中,请你返回 -1 。由于答案可能会 很大 ,请返回它对 109 + 7 取余 的结果。

+ +

 

+ +

示例 1:

+ +
+输入:packages = [2,3,5], boxes = [[4,8],[2,8]]
+输出:6
+解释:选择第一个供应商最优,用两个尺寸为 4 的箱子和一个尺寸为 8 的箱子。
+总浪费空间为 (4-2) + (4-3) + (8-5) = 6 。
+
+ +

示例 2:

+ +
+输入:packages = [2,3,5], boxes = [[1,4],[2,3],[3,4]]
+输出:-1
+解释:没有箱子能装下尺寸为 5 的包裹。
+
+ +

示例 3:

+ +
+输入:packages = [3,5,8,10,11,12], boxes = [[12],[11,9],[10,5,14]]
+输出:9
+解释:选择第三个供应商最优,用两个尺寸为 5 的箱子,两个尺寸为 10 的箱子和两个尺寸为 14 的箱子。
+总浪费空间为 (5-3) + (5-5) + (10-8) + (10-10) + (14-11) + (14-12) = 9 。
+
+ +

 

+ +

提示:

+ +
    +
  • n == packages.length
  • +
  • m == boxes.length
  • +
  • 1 <= n <= 105
  • +
  • 1 <= m <= 105
  • +
  • 1 <= packages[i] <= 105
  • +
  • 1 <= boxes[j].length <= 105
  • +
  • 1 <= boxes[j][k] <= 105
  • +
  • sum(boxes[j].length) <= 105
  • +
  • boxes[j] 中的元素 互不相同 。
  • +
+ + +## 解法 + + + +“排序 + 二分查找 + 前缀和”实现。 + + + +### **Python3** + + + +```python +class Solution: + def minWastedSpace(self, packages: List[int], boxes: List[List[int]]) -> int: + packages.sort() + res = float('inf') + for box in boxes: + box.sort() + if packages[-1] > box[-1]: + continue + t = last = 0 + for b in box: + idx = bisect.bisect_right(packages, b, lo=last) + t += (idx - last) * b + last = idx + res = min(res, t) + return -1 if res == float('inf') else (res - sum(packages)) % (10 ** 9 + 7) +``` + +### **Java** + + + +```java +class Solution { + public int minWastedSpace(int[] packages, int[][] boxes) { + int n = packages.length; + Arrays.sort(packages); + long[] preSum = new long[n + 1]; + for (int i = 0; i < n; ++i) { + preSum[i + 1] = preSum[i] + packages[i]; + } + + long res = Long.MAX_VALUE; + for (int[] box : boxes) { + Arrays.sort(box); + if (packages[n - 1] > box[box.length - 1]) { + continue; + } + long t = 0; + int low = 0; + for (int b : box) { + int idx = searchRight(packages, b, low); + // 这里需要手动转 long + t += ((idx - low) * (long) b - (preSum[idx] - preSum[low])); + low = idx; + } + res = Math.min(res, t); + } + return res == Long.MAX_VALUE ? -1 : (int) (res % 1000000007); + } + + private int searchRight(int[] packages, int target, int low) { + int high = packages.length; + while (low < high) { + int mid = (low + high) >> 1; + if (packages[mid] <= target) { + low = mid + 1; + } else { + high = mid; + } + } + return low; + } +} +``` + +### **...** + +``` + +``` + + diff --git a/solution/1800-1899/1889.Minimum Space Wasted From Packaging/README_EN.md b/solution/1800-1899/1889.Minimum Space Wasted From Packaging/README_EN.md new file mode 100644 index 0000000000000..9f8ba7e8d8428 --- /dev/null +++ b/solution/1800-1899/1889.Minimum Space Wasted From Packaging/README_EN.md @@ -0,0 +1,137 @@ +# [1889. Minimum Space Wasted From Packaging](https://leetcode.com/problems/minimum-space-wasted-from-packaging) + +[中文文档](/solution/1800-1899/1889.Minimum%20Space%20Wasted%20From%20Packaging/README.md) + +## Description + +

You have n packages that you are trying to place in boxes, one package in each box. There are m suppliers that each produce boxes of different sizes (with infinite supply). A package can be placed in a box if the size of the package is less than or equal to the size of the box.

+ +

The package sizes are given as an integer array packages, where packages[i] is the size of the ith package. The suppliers are given as a 2D integer array boxes, where boxes[j] is an array of box sizes that the jth supplier produces.

+ +

You want to choose a single supplier and use boxes from them such that the total wasted space is minimized. For each package in a box, we define the space wasted to be size of the box - size of the package. The total wasted space is the sum of the space wasted in all the boxes.

+ +
    +
  • For example, if you have to fit packages with sizes [2,3,5] and the supplier offers boxes of sizes [4,8], you can fit the packages of size-2 and size-3 into two boxes of size-4 and the package with size-5 into a box of size-8. This would result in a waste of (4-2) + (4-3) + (8-5) = 6.
  • +
+ +

Return the minimum total wasted space by choosing the box supplier optimally, or -1 if it is impossible to fit all the packages inside boxes. Since the answer may be large, return it modulo 109 + 7.

+ +

 

+

Example 1:

+ +
+Input: packages = [2,3,5], boxes = [[4,8],[2,8]]
+Output: 6
+Explanation: It is optimal to choose the first supplier, using two size-4 boxes and one size-8 box.
+The total waste is (4-2) + (4-3) + (8-5) = 6.
+
+ +

Example 2:

+ +
+Input: packages = [2,3,5], boxes = [[1,4],[2,3],[3,4]]
+Output: -1
+Explanation: There is no box that the package of size 5 can fit in.
+
+ +

Example 3:

+ +
+Input: packages = [3,5,8,10,11,12], boxes = [[12],[11,9],[10,5,14]]
+Output: 9
+Explanation: It is optimal to choose the third supplier, using two size-5 boxes, two size-10 boxes, and two size-14 boxes.
+The total waste is (5-3) + (5-5) + (10-8) + (10-10) + (14-11) + (14-12) = 9.
+
+ +

 

+

Constraints:

+ +
    +
  • n == packages.length
  • +
  • m == boxes.length
  • +
  • 1 <= n <= 105
  • +
  • 1 <= m <= 105
  • +
  • 1 <= packages[i] <= 105
  • +
  • 1 <= boxes[j].length <= 105
  • +
  • 1 <= boxes[j][k] <= 105
  • +
  • sum(boxes[j].length) <= 105
  • +
  • The elements in boxes[j] are distinct.
  • +
+ + +## Solutions + + + +### **Python3** + +```python +class Solution: + def minWastedSpace(self, packages: List[int], boxes: List[List[int]]) -> int: + packages.sort() + res = float('inf') + for box in boxes: + box.sort() + if packages[-1] > box[-1]: + continue + t = last = 0 + for b in box: + idx = bisect.bisect_right(packages, b, lo=last) + t += (idx - last) * b + last = idx + res = min(res, t) + return -1 if res == float('inf') else (res - sum(packages)) % (10 ** 9 + 7) +``` + +### **Java** + +```java +class Solution { + public int minWastedSpace(int[] packages, int[][] boxes) { + int n = packages.length; + Arrays.sort(packages); + long[] preSum = new long[n + 1]; + for (int i = 0; i < n; ++i) { + preSum[i + 1] = preSum[i] + packages[i]; + } + + long res = Long.MAX_VALUE; + for (int[] box : boxes) { + Arrays.sort(box); + if (packages[n - 1] > box[box.length - 1]) { + continue; + } + long t = 0; + int low = 0; + for (int b : box) { + int idx = searchRight(packages, b, low); + t += ((idx - low) * (long) b - (preSum[idx] - preSum[low])); + low = idx; + } + res = Math.min(res, t); + } + return res == Long.MAX_VALUE ? -1 : (int) (res % 1000000007); + } + + private int searchRight(int[] packages, int target, int low) { + int high = packages.length; + while (low < high) { + int mid = (low + high) >> 1; + if (packages[mid] <= target) { + low = mid + 1; + } else { + high = mid; + } + } + return low; + } +} +``` + +### **...** + +``` + +``` + + diff --git a/solution/1800-1899/1889.Minimum Space Wasted From Packaging/Solution.java b/solution/1800-1899/1889.Minimum Space Wasted From Packaging/Solution.java new file mode 100644 index 0000000000000..ed7bf0942ec62 --- /dev/null +++ b/solution/1800-1899/1889.Minimum Space Wasted From Packaging/Solution.java @@ -0,0 +1,40 @@ +class Solution { + public int minWastedSpace(int[] packages, int[][] boxes) { + int n = packages.length; + Arrays.sort(packages); + long[] preSum = new long[n + 1]; + for (int i = 0; i < n; ++i) { + preSum[i + 1] = preSum[i] + packages[i]; + } + + long res = Long.MAX_VALUE; + for (int[] box : boxes) { + Arrays.sort(box); + if (packages[n - 1] > box[box.length - 1]) { + continue; + } + long t = 0; + int low = 0; + for (int b : box) { + int idx = searchRight(packages, b, low); + t += ((idx - low) * (long) b - (preSum[idx] - preSum[low])); + low = idx; + } + res = Math.min(res, t); + } + return res == Long.MAX_VALUE ? -1 : (int) (res % 1000000007); + } + + private int searchRight(int[] packages, int target, int low) { + int high = packages.length; + while (low < high) { + int mid = (low + high) >> 1; + if (packages[mid] <= target) { + low = mid + 1; + } else { + high = mid; + } + } + return low; + } +} \ No newline at end of file diff --git a/solution/1800-1899/1889.Minimum Space Wasted From Packaging/Solution.py b/solution/1800-1899/1889.Minimum Space Wasted From Packaging/Solution.py new file mode 100644 index 0000000000000..c8ab32e85105b --- /dev/null +++ b/solution/1800-1899/1889.Minimum Space Wasted From Packaging/Solution.py @@ -0,0 +1,15 @@ +class Solution: + def minWastedSpace(self, packages: List[int], boxes: List[List[int]]) -> int: + packages.sort() + res = float('inf') + for box in boxes: + box.sort() + if packages[-1] > box[-1]: + continue + t = last = 0 + for b in box: + idx = bisect.bisect_right(packages, b, lo=last) + t += (idx - last) * b + last = idx + res = min(res, t) + return -1 if res == float('inf') else (res - sum(packages)) % (10 ** 9 + 7) diff --git a/solution/README.md b/solution/README.md index c8d692177bd69..7d557893db0d1 100644 --- a/solution/README.md +++ b/solution/README.md @@ -1894,7 +1894,11 @@ | [1881](https://leetcode-cn.com/problems/maximum-value-after-insertion) | [插入后的最大值](/solution/1800-1899/1881.Maximum%20Value%20after%20Insertion/README.md) | `贪心算法` | 中等 | | | [1882](https://leetcode-cn.com/problems/process-tasks-using-servers) | [使用服务器处理任务](/solution/1800-1899/1882.Process%20Tasks%20Using%20Servers/README.md) | `堆` | 中等 | | | [1883](https://leetcode-cn.com/problems/minimum-skips-to-arrive-at-meeting-on-time) | [准时抵达会议现场的最小跳过休息次数](/solution/1800-1899/1883.Minimum%20Skips%20to%20Arrive%20at%20Meeting%20On%20Time/README.md) | `动态规划` | 困难 | | -| [1884](https://leetcode-cn.com/problems/egg-drop-with-2-eggs-and-n-floors) | [Egg Drop With 2 Eggs and N Floors](/solution/1800-1899/1884.Egg%20Drop%20With%202%20Eggs%20and%20N%20Floors/README_EN.md) | `数学`,`二分查找`,`动态规划` | 中等 | | +| [1884](https://leetcode-cn.com/problems/egg-drop-with-2-eggs-and-n-floors) | [鸡蛋掉落-两枚鸡蛋](/solution/1800-1899/1884.Egg%20Drop%20With%202%20Eggs%20and%20N%20Floors/README.md) | `数学`,`二分查找`,`动态规划` | 中等 | | +| [1886](https://leetcode-cn.com/problems/determine-whether-matrix-can-be-obtained-by-rotation) | [判断矩阵经轮转后是否一致](/solution/1800-1899/1886.Determine%20Whether%20Matrix%20Can%20Be%20Obtained%20By%20Rotation/README.md) | `数组` | 简单 | | +| [1887](https://leetcode-cn.com/problems/reduction-operations-to-make-the-array-elements-equal) | [使数组元素相等的减少操作次数](/solution/1800-1899/1887.Reduction%20Operations%20to%20Make%20the%20Array%20Elements%20Equal/README.md) | `贪心算法`,`排序` | 中等 | | +| [1888](https://leetcode-cn.com/problems/minimum-number-of-flips-to-make-the-binary-string-alternating) | [使二进制字符串字符交替的最少反转次数](/solution/1800-1899/1888.Minimum%20Number%20of%20Flips%20to%20Make%20the%20Binary%20String%20Alternating/README.md) | `贪心算法`,`数组` | 中等 | | +| [1889](https://leetcode-cn.com/problems/minimum-space-wasted-from-packaging) | [装包裹的最小浪费空间](/solution/1800-1899/1889.Minimum%20Space%20Wasted%20From%20Packaging/README.md) | `二分查找` | 困难 | | ## 版权 diff --git a/solution/README_EN.md b/solution/README_EN.md index e87dab25a3daa..b192c31b12a8f 100644 --- a/solution/README_EN.md +++ b/solution/README_EN.md @@ -1893,6 +1893,10 @@ Press Control+F(or Command+F on the | [1882](https://leetcode.com/problems/process-tasks-using-servers) | [Process Tasks Using Servers](/solution/1800-1899/1882.Process%20Tasks%20Using%20Servers/README_EN.md) | `Heap` | Medium | | | [1883](https://leetcode.com/problems/minimum-skips-to-arrive-at-meeting-on-time) | [Minimum Skips to Arrive at Meeting On Time](/solution/1800-1899/1883.Minimum%20Skips%20to%20Arrive%20at%20Meeting%20On%20Time/README_EN.md) | `Dynamic Programming` | Hard | | | [1884](https://leetcode.com/problems/egg-drop-with-2-eggs-and-n-floors) | [Egg Drop With 2 Eggs and N Floors](/solution/1800-1899/1884.Egg%20Drop%20With%202%20Eggs%20and%20N%20Floors/README_EN.md) | `Math`,`Binary Search`,`Dynamic Programming` | Medium | | +| [1886](https://leetcode.com/problems/determine-whether-matrix-can-be-obtained-by-rotation) | [Determine Whether Matrix Can Be Obtained By Rotation](/solution/1800-1899/1886.Determine%20Whether%20Matrix%20Can%20Be%20Obtained%20By%20Rotation/README_EN.md) | `Array` | Easy | | +| [1887](https://leetcode.com/problems/reduction-operations-to-make-the-array-elements-equal) | [Reduction Operations to Make the Array Elements Equal](/solution/1800-1899/1887.Reduction%20Operations%20to%20Make%20the%20Array%20Elements%20Equal/README_EN.md) | `Greedy`,`Sort` | Medium | | +| [1888](https://leetcode.com/problems/minimum-number-of-flips-to-make-the-binary-string-alternating) | [Minimum Number of Flips to Make the Binary String Alternating](/solution/1800-1899/1888.Minimum%20Number%20of%20Flips%20to%20Make%20the%20Binary%20String%20Alternating/README_EN.md) | `Greedy`,`Array` | Medium | | +| [1889](https://leetcode.com/problems/minimum-space-wasted-from-packaging) | [Minimum Space Wasted From Packaging](/solution/1800-1899/1889.Minimum%20Space%20Wasted%20From%20Packaging/README_EN.md) | `Binary Search` | Hard | | ## Copyright diff --git a/solution/result.json b/solution/result.json index 29856ca99e70c..00be6cbf37206 100644 --- a/solution/result.json +++ b/solution/result.json @@ -1 +1 @@ -[{"question_id": "2031", "frontend_question_id": "1884", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/egg-drop-with-2-eggs-and-n-floors", "url_en": "https://leetcode.com/problems/egg-drop-with-2-eggs-and-n-floors", "relative_path_cn": "/solution/1800-1899/1884.Egg%20Drop%20With%202%20Eggs%20and%20N%20Floors/README.md", "relative_path_en": "/solution/1800-1899/1884.Egg%20Drop%20With%202%20Eggs%20and%20N%20Floors/README_EN.md", "title_cn": "", "title_en": "Egg Drop With 2 Eggs and N Floors", "question_title_slug": "egg-drop-with-2-eggs-and-n-floors", "content_en": "

You are given two identical eggs and you have access to a building with n floors labeled from 1 to n.

\n\n

You know that there exists a floor f where 0 <= f <= n such that any egg dropped at a floor higher than f will break, and any egg dropped at or below floor f will not break.

\n\n

In each move, you may take an unbroken egg and drop it from any floor x (where 1 <= x <= n). If the egg breaks, you can no longer use it. However, if the egg does not break, you may reuse it in future moves.

\n\n

Return the minimum number of moves that you need to determine with certainty what the value of f is.

\n\n

 

\n

Example 1:

\n\n
\nInput: n = 2\nOutput: 2\nExplanation: We can drop the first egg from floor 1 and the second egg from floor 2.\nIf the first egg breaks, we know that f = 0.\nIf the second egg breaks but the first egg didn't, we know that f = 1.\nOtherwise, if both eggs survive, we know that f = 2.\n
\n\n

Example 2:

\n\n
\nInput: n = 100\nOutput: 14\nExplanation: One optimal strategy is:\n- Drop the 1st egg at floor 9. If it breaks, we know f is between 0 and 8. Drop the 2nd egg starting\n  from floor 1 and going up one at a time to find f within 7 more drops. Total drops is 1 + 7 = 8.\n- If the 1st egg does not break, drop the 1st egg again at floor 22. If it breaks, we know f is between 9\n  and 21. Drop the 2nd egg starting from floor 10 and going up one at a time to find f within 12 more\n  drops. Total drops is 2 + 12 = 14.\n- If the 1st egg does not break again, follow a similar process dropping the 1st egg from floors 34, 45,\n  55, 64, 72, 79, 85, 90, 94, 97, 99, and 100.\nRegardless of the outcome, it takes at most 14 drops to determine f.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 1000
  • \n
\n", "content_cn": null, "tags_en": ["Math", "Binary Search", "Dynamic Programming"], "tags_cn": ["\u6570\u5b66", "\u4e8c\u5206\u67e5\u627e", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int twoEggDrop(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int twoEggDrop(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def twoEggDrop(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def twoEggDrop(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint twoEggDrop(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int TwoEggDrop(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar twoEggDrop = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef two_egg_drop(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func twoEggDrop(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func twoEggDrop(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def twoEggDrop(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun twoEggDrop(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn two_egg_drop(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function twoEggDrop($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function twoEggDrop(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (two-egg-drop n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1884](https://leetcode-cn.com/problems/egg-drop-with-2-eggs-and-n-floors)", "[Egg Drop With 2 Eggs and N Floors](/solution/1800-1899/1884.Egg%20Drop%20With%202%20Eggs%20and%20N%20Floors/README_EN.md)", "`\u6570\u5b66`,`\u4e8c\u5206\u67e5\u627e`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1884](https://leetcode.com/problems/egg-drop-with-2-eggs-and-n-floors)", "[Egg Drop With 2 Eggs and N Floors](/solution/1800-1899/1884.Egg%20Drop%20With%202%20Eggs%20and%20N%20Floors/README_EN.md)", "`Math`,`Binary Search`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "2030", "frontend_question_id": "1875", "paid_only": true, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/group-employees-of-the-same-salary", "url_en": "https://leetcode.com/problems/group-employees-of-the-same-salary", "relative_path_cn": "/solution/1800-1899/1875.Group%20Employees%20of%20the%20Same%20Salary/README.md", "relative_path_en": "/solution/1800-1899/1875.Group%20Employees%20of%20the%20Same%20Salary/README_EN.md", "title_cn": "", "title_en": "Group Employees of the Same Salary", "question_title_slug": "group-employees-of-the-same-salary", "content_en": "

Table: Employees

\r\n\r\n
\r\n+-------------+---------+\r\n| Column Name | Type    |\r\n+-------------+---------+\r\n| employee_id | int     |\r\n| name        | varchar |\r\n| salary      | int     |\r\n+-------------+---------+\r\nemployee_id is the primary key for this table.\r\nEach row of this table indicates the employee ID, employee name, and salary.\r\n
\r\n\r\n

 

\r\n\r\n

A company wants to divide the employees into teams such that all the members on each team have the same salary. The teams should follow these criteria:

\r\n\r\n
    \r\n\t
  • Each team should consist of at least two employees.
  • \r\n\t
  • All the employees on a team should have the same salary.
  • \r\n\t
  • All the employees of the same salary should be assigned to the same team.
  • \r\n\t
  • If the salary of an employee is unique, we do not assign this employee to any team.
  • \r\n\t
  • A team's ID is assigned based on the rank of the team's salary relative to the other teams' salaries, where the team with the lowest salary has team_id = 1. Note that the salaries for employees not on a team are not included in this ranking.
  • \r\n
\r\n\r\n

Write an SQL query to get the team_id of each employee that is in a team.

\r\n\r\n

Return the result table ordered by team_id in ascending order. In case of a tie, order it by employee_id in ascending order.

\r\n\r\n

The query result format is in the following example:

\r\n\r\n

 

\r\n\r\n
\r\nEmployees table:\r\n+-------------+---------+--------+\r\n| employee_id | name    | salary |\r\n+-------------+---------+--------+\r\n| 2           | Meir    | 3000   |\r\n| 3           | Michael | 3000   |\r\n| 7           | Addilyn | 7400   |\r\n| 8           | Juan    | 6100   |\r\n| 9           | Kannon  | 7400   |\r\n+-------------+---------+--------+\r\n\r\nResult table:\r\n+-------------+---------+--------+---------+\r\n| employee_id | name    | salary | team_id |\r\n+-------------+---------+--------+---------+\r\n| 2           | Meir    | 3000   | 1       |\r\n| 3           | Michael | 3000   | 1       |\r\n| 7           | Addilyn | 7400   | 2       |\r\n| 9           | Kannon  | 7400   | 2       |\r\n+-------------+---------+--------+---------+\r\n\r\nMeir (employee_id=2) and Michael (employee_id=3) are in the same team because they have the same salary of 3000.\r\nAddilyn (employee_id=7) and Kannon (employee_id=9) are in the same team because they have the same salary of 7400.\r\nJuan (employee_id=8) is not included in any team because their salary of 6100 is unique (i.e. no other employee has the same salary).\r\nThe team IDs are assigned as follows (based on salary ranking, lowest first):\r\n- team_id=1: Meir and Michael, salary of 3000\r\n- team_id=2: Addilyn and Kannon, salary of 7400\r\nJuan's salary of 6100 is not included in the ranking because they are not on a team.
", "content_cn": null, "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1875](https://leetcode-cn.com/problems/group-employees-of-the-same-salary)", "[Group Employees of the Same Salary](/solution/1800-1899/1875.Group%20Employees%20of%20the%20Same%20Salary/README_EN.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1875](https://leetcode.com/problems/group-employees-of-the-same-salary)", "[Group Employees of the Same Salary](/solution/1800-1899/1875.Group%20Employees%20of%20the%20Same%20Salary/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "2029", "frontend_question_id": "1874", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/minimize-product-sum-of-two-arrays", "url_en": "https://leetcode.com/problems/minimize-product-sum-of-two-arrays", "relative_path_cn": "/solution/1800-1899/1874.Minimize%20Product%20Sum%20of%20Two%20Arrays/README.md", "relative_path_en": "/solution/1800-1899/1874.Minimize%20Product%20Sum%20of%20Two%20Arrays/README_EN.md", "title_cn": "", "title_en": "Minimize Product Sum of Two Arrays", "question_title_slug": "minimize-product-sum-of-two-arrays", "content_en": "

The product sum of two equal-length arrays a and b is equal to the sum of a[i] * b[i] for all 0 <= i < a.length (0-indexed).

\r\n\r\n
    \r\n\t
  • For example, if a = [1,2,3,4] and b = [5,2,3,1], the product sum would be 1*5 + 2*2 + 3*3 + 4*1 = 22.
  • \r\n
\r\n\r\n

Given two arrays nums1 and nums2 of length n, return the minimum product sum if you are allowed to rearrange the order of the elements in nums1

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: nums1 = [5,3,4,2], nums2 = [4,2,2,5]\r\nOutput: 40\r\nExplanation: We can rearrange nums1 to become [3,5,4,2]. The product sum of [3,5,4,2] and [4,2,2,5] is 3*4 + 5*2 + 4*2 + 2*5 = 40.\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: nums1 = [2,1,4,5,7], nums2 = [3,2,4,8,6]\r\nOutput: 65\r\nExplanation: We can rearrange nums1 to become [5,7,4,1,2]. The product sum of [5,7,4,1,2] and [3,2,4,8,6] is 5*3 + 7*2 + 4*4 + 1*8 + 2*6 = 65.\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • n == nums1.length == nums2.length
  • \r\n\t
  • 1 <= n <= 105
  • \r\n\t
  • 1 <= nums1[i], nums2[i] <= 100
  • \r\n
", "content_cn": null, "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minProductSum(vector& nums1, vector& nums2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minProductSum(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minProductSum(self, nums1, nums2):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minProductSum(self, nums1: List[int], nums2: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minProductSum(int* nums1, int nums1Size, int* nums2, int nums2Size){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinProductSum(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums1\n * @param {number[]} nums2\n * @return {number}\n */\nvar minProductSum = function(nums1, nums2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums1\n# @param {Integer[]} nums2\n# @return {Integer}\ndef min_product_sum(nums1, nums2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minProductSum(_ nums1: [Int], _ nums2: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minProductSum(nums1 []int, nums2 []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minProductSum(nums1: Array[Int], nums2: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minProductSum(nums1: IntArray, nums2: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_product_sum(nums1: Vec, nums2: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums1\n * @param Integer[] $nums2\n * @return Integer\n */\n function minProductSum($nums1, $nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minProductSum(nums1: number[], nums2: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-product-sum nums1 nums2)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1874](https://leetcode-cn.com/problems/minimize-product-sum-of-two-arrays)", "[Minimize Product Sum of Two Arrays](/solution/1800-1899/1874.Minimize%20Product%20Sum%20of%20Two%20Arrays/README_EN.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1874](https://leetcode.com/problems/minimize-product-sum-of-two-arrays)", "[Minimize Product Sum of Two Arrays](/solution/1800-1899/1874.Minimize%20Product%20Sum%20of%20Two%20Arrays/README_EN.md)", "`Greedy`", "Medium", "\ud83d\udd12"]}, {"question_id": "2024", "frontend_question_id": "1873", "paid_only": true, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/calculate-special-bonus", "url_en": "https://leetcode.com/problems/calculate-special-bonus", "relative_path_cn": "/solution/1800-1899/1873.Calculate%20Special%20Bonus/README.md", "relative_path_en": "/solution/1800-1899/1873.Calculate%20Special%20Bonus/README_EN.md", "title_cn": "", "title_en": "Calculate Special Bonus", "question_title_slug": "calculate-special-bonus", "content_en": "

Table: Employees

\r\n\r\n
\r\n+-------------+---------+\r\n| Column Name | Type    |\r\n+-------------+---------+\r\n| employee_id | int     |\r\n| name        | varchar |\r\n| salary      | int     |\r\n+-------------+---------+\r\nemployee_id is the primary key for this table.\r\nEach row of this table indicates the employee ID, employee name, and salary.\r\n
\r\n\r\n

 

\r\n\r\n

Write an SQL query to calculate the bonus of each employee. The bonus of an employee is 100% of their salary if the ID of the employee is an odd number and the employee name does not start with the character 'M'. The bonus of an employee is 0 otherwise.

\r\n\r\n

Return the result table ordered by employee_id.

\r\n\r\n

The query result format is in the following example:

\r\n\r\n

 

\r\n\r\n
\r\nEmployees table:\r\n+-------------+---------+--------+\r\n| employee_id | name    | salary |\r\n+-------------+---------+--------+\r\n| 2           | Meir    | 3000   |\r\n| 3           | Michael | 3800   |\r\n| 7           | Addilyn | 7400   |\r\n| 8           | Juan    | 6100   |\r\n| 9           | Kannon  | 7700   |\r\n+-------------+---------+--------+\r\n\r\nResult table:\r\n+-------------+-------+\r\n| employee_id | bonus |\r\n+-------------+-------+\r\n| 2           | 0     |\r\n| 3           | 0     |\r\n| 7           | 7400  |\r\n| 8           | 0     |\r\n| 9           | 7700  |\r\n+-------------+-------+\r\n\r\nThe employees with IDs 2 and 8 get 0 bonus because they have an even employee_id.\r\nThe employee with ID 3 gets 0 bonus because their name starts with 'M'.\r\nThe rest of the employees get a 100% bonus.\r\n
", "content_cn": null, "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1873](https://leetcode-cn.com/problems/calculate-special-bonus)", "[Calculate Special Bonus](/solution/1800-1899/1873.Calculate%20Special%20Bonus/README_EN.md)", "", "\u7b80\u5355", ""], "md_table_row_en": ["[1873](https://leetcode.com/problems/calculate-special-bonus)", "[Calculate Special Bonus](/solution/1800-1899/1873.Calculate%20Special%20Bonus/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "2019", "frontend_question_id": "1868", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/product-of-two-run-length-encoded-arrays", "url_en": "https://leetcode.com/problems/product-of-two-run-length-encoded-arrays", "relative_path_cn": "/solution/1800-1899/1868.Product%20of%20Two%20Run-Length%20Encoded%20Arrays/README.md", "relative_path_en": "/solution/1800-1899/1868.Product%20of%20Two%20Run-Length%20Encoded%20Arrays/README_EN.md", "title_cn": "", "title_en": "Product of Two Run-Length Encoded Arrays", "question_title_slug": "product-of-two-run-length-encoded-arrays", "content_en": "

Run-length encoding is a compression algorithm that allows for an integer array nums with many segments of consecutive repeated numbers to be represented by a (generally smaller) 2D array encoded. Each encoded[i] = [vali, freqi] describes the ith segment of repeated numbers in nums where vali is the value that is repeated freqi times.

\n\n
    \n\t
  • For example, nums = [1,1,1,2,2,2,2,2] is represented by the run-length encoded array encoded = [[1,3],[2,5]]. Another way to read this is "three 1's followed by five 2's".
  • \n
\n\n

The product of two run-length encoded arrays encoded1 and encoded2 can be calculated using the following steps:

\n\n
    \n\t
  1. Expand both encoded1 and encoded2 into the full arrays nums1 and nums2 respectively.
  2. \n\t
  3. Create a new array prodNums of length nums1.length and set prodNums[i] = nums1[i] * nums2[i].
  4. \n\t
  5. Compress prodNums into a run-length encoded array and return it.
  6. \n
\n\n

You are given two run-length encoded arrays encoded1 and encoded2 representing full arrays nums1 and nums2 respectively. Both nums1 and nums2 have the same length. Each encoded1[i] = [vali, freqi] describes the ith segment of nums1, and each encoded2[j] = [valj, freqj] describes the jth segment of nums2.

\n\n

Return the product of encoded1 and encoded2.

\n\n

Note: Compression should be done such that the run-length encoded array has the minimum possible length.

\n\n

 

\n

Example 1:

\n\n
\nInput: encoded1 = [[1,3],[2,3]], encoded2 = [[6,3],[3,3]]\nOutput: [[6,6]]\nExplanation: encoded1 expands to [1,1,1,2,2,2] and encoded2 expands to [6,6,6,3,3,3].\nprodNums = [6,6,6,6,6,6], which is compressed into the run-length encoded array [[6,6]].\n
\n\n

Example 2:

\n\n
\nInput: encoded1 = [[1,3],[2,1],[3,2]], encoded2 = [[2,3],[3,3]]\nOutput: [[2,3],[6,1],[9,2]]\nExplanation: encoded1 expands to [1,1,1,2,3,3] and encoded2 expands to [2,2,2,3,3,3].\nprodNums = [2,2,2,6,9,9], which is compressed into the run-length encoded array [[2,3],[6,1],[9,2]].\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= encoded1.length, encoded2.length <= 105
  • \n\t
  • encoded1[i].length == 2
  • \n\t
  • encoded2[j].length == 2
  • \n\t
  • 1 <= vali, freqi <= 104 for each encoded1[i].
  • \n\t
  • 1 <= valj, freqj <= 104 for each encoded2[j].
  • \n\t
  • The full arrays that encoded1 and encoded2 represent are the same length.
  • \n
\n", "content_cn": null, "tags_en": ["Two Pointers"], "tags_cn": ["\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> findRLEArray(vector>& encoded1, vector>& encoded2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> findRLEArray(int[][] encoded1, int[][] encoded2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findRLEArray(self, encoded1, encoded2):\n \"\"\"\n :type encoded1: List[List[int]]\n :type encoded2: List[List[int]]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findRLEArray(self, encoded1: List[List[int]], encoded2: List[List[int]]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** findRLEArray(int** encoded1, int encoded1Size, int* encoded1ColSize, int** encoded2, int encoded2Size, int* encoded2ColSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> FindRLEArray(int[][] encoded1, int[][] encoded2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} encoded1\n * @param {number[][]} encoded2\n * @return {number[][]}\n */\nvar findRLEArray = function(encoded1, encoded2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} encoded1\n# @param {Integer[][]} encoded2\n# @return {Integer[][]}\ndef find_rle_array(encoded1, encoded2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findRLEArray(_ encoded1: [[Int]], _ encoded2: [[Int]]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findRLEArray(encoded1 [][]int, encoded2 [][]int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findRLEArray(encoded1: Array[Array[Int]], encoded2: Array[Array[Int]]): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findRLEArray(encoded1: Array, encoded2: Array): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_rle_array(encoded1: Vec>, encoded2: Vec>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $encoded1\n * @param Integer[][] $encoded2\n * @return Integer[][]\n */\n function findRLEArray($encoded1, $encoded2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findRLEArray(encoded1: number[][], encoded2: number[][]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-rle-array encoded1 encoded2)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1868](https://leetcode-cn.com/problems/product-of-two-run-length-encoded-arrays)", "[Product of Two Run-Length Encoded Arrays](/solution/1800-1899/1868.Product%20of%20Two%20Run-Length%20Encoded%20Arrays/README_EN.md)", "`\u53cc\u6307\u9488`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1868](https://leetcode.com/problems/product-of-two-run-length-encoded-arrays)", "[Product of Two Run-Length Encoded Arrays](/solution/1800-1899/1868.Product%20of%20Two%20Run-Length%20Encoded%20Arrays/README_EN.md)", "`Two Pointers`", "Medium", "\ud83d\udd12"]}, {"question_id": "2014", "frontend_question_id": "1867", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/orders-with-maximum-quantity-above-average", "url_en": "https://leetcode.com/problems/orders-with-maximum-quantity-above-average", "relative_path_cn": "/solution/1800-1899/1867.Orders%20With%20Maximum%20Quantity%20Above%20Average/README.md", "relative_path_en": "/solution/1800-1899/1867.Orders%20With%20Maximum%20Quantity%20Above%20Average/README_EN.md", "title_cn": "", "title_en": "Orders With Maximum Quantity Above Average", "question_title_slug": "orders-with-maximum-quantity-above-average", "content_en": "

Table: OrdersDetails

\n\n
\n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| order_id    | int  |\n| product_id  | int  |\n| quantity    | int  |\n+-------------+------+\n(order_id, product_id) is the primary key for this table.\nA single order is represented as multiple rows, one row for each product in the order.\nEach row of this table contains the quantity ordered of the product product_id in the order order_id.\n
\n\n

 

\n\n

You are running an ecommerce site that is looking for imbalanced orders. An imbalanced order is one whose maximum quantity is strictly greater than the average quantity of every order (including itself).

\n\n

The average quantity of an order is calculated as (total quantity of all products in the order) / (number of different products in the order). The maximum quantity of an order is the highest quantity of any single product in the order.

\n\n

Write an SQL query to find the order_id of all imbalanced orders.

\n\n

Return the result table in any order.

\n\n

The query result format is in the following example:

\n\n

 

\n\n
\nOrdersDetails table:\n+----------+------------+----------+\n| order_id | product_id | quantity |\n+----------+------------+----------+\n| 1        | 1          | 12       |\n| 1        | 2          | 10       |\n| 1        | 3          | 15       |\n| 2        | 1          | 8        |\n| 2        | 4          | 4        |\n| 2        | 5          | 6        |\n| 3        | 3          | 5        |\n| 3        | 4          | 18       |\n| 4        | 5          | 2        |\n| 4        | 6          | 8        |\n| 5        | 7          | 9        |\n| 5        | 8          | 9        |\n| 3        | 9          | 20       |\n| 2        | 9          | 4        |\n+----------+------------+----------+\n\nResult table:\n+----------+\n| order_id |\n+----------+\n| 1        |\n| 3        |\n+----------+\n\nThe average quantity of each order is:\n- order_id=1: (12+10+15)/3 = 12.3333333\n- order_id=2: (8+4+6+4)/4 = 5.5\n- order_id=3: (5+18+20)/3 = 14.333333\n- order_id=4: (2+8)/2 = 5\n- order_id=5: (9+9)/2 = 9\n\nThe maximum quantity of each order is:\n- order_id=1: max(12, 10, 15) = 15\n- order_id=2: max(8, 4, 6, 4) = 8\n- order_id=3: max(5, 18, 20) = 20\n- order_id=4: max(2, 8) = 8\n- order_id=5: max(9, 9) = 9\n\nOrders 1 and 3 are imbalanced because they have a maximum quantity that exceeds the average quantity of every order.\n
\n", "content_cn": null, "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1867](https://leetcode-cn.com/problems/orders-with-maximum-quantity-above-average)", "[Orders With Maximum Quantity Above Average](/solution/1800-1899/1867.Orders%20With%20Maximum%20Quantity%20Above%20Average/README_EN.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1867](https://leetcode.com/problems/orders-with-maximum-quantity-above-average)", "[Orders With Maximum Quantity Above Average](/solution/1800-1899/1867.Orders%20With%20Maximum%20Quantity%20Above%20Average/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "2013", "frontend_question_id": "1883", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-skips-to-arrive-at-meeting-on-time", "url_en": "https://leetcode.com/problems/minimum-skips-to-arrive-at-meeting-on-time", "relative_path_cn": "/solution/1800-1899/1883.Minimum%20Skips%20to%20Arrive%20at%20Meeting%20On%20Time/README.md", "relative_path_en": "/solution/1800-1899/1883.Minimum%20Skips%20to%20Arrive%20at%20Meeting%20On%20Time/README_EN.md", "title_cn": "\u51c6\u65f6\u62b5\u8fbe\u4f1a\u8bae\u73b0\u573a\u7684\u6700\u5c0f\u8df3\u8fc7\u4f11\u606f\u6b21\u6570", "title_en": "Minimum Skips to Arrive at Meeting On Time", "question_title_slug": "minimum-skips-to-arrive-at-meeting-on-time", "content_en": "

You are given an integer hoursBefore, the number of hours you have to travel to your meeting. To arrive at your meeting, you have to travel through n roads. The road lengths are given as an integer array dist of length n, where dist[i] describes the length of the ith road in kilometers. In addition, you are given an integer speed, which is the speed (in km/h) you will travel at.

\n\n

After you travel road i, you must rest and wait for the next integer hour before you can begin traveling on the next road. Note that you do not have to rest after traveling the last road because you are already at the meeting.

\n\n
    \n\t
  • For example, if traveling a road takes 1.4 hours, you must wait until the 2 hour mark before traveling the next road. If traveling a road takes exactly 2 hours, you do not need to wait.
  • \n
\n\n

However, you are allowed to skip some rests to be able to arrive on time, meaning you do not need to wait for the next integer hour. Note that this means you may finish traveling future roads at different hour marks.

\n\n
    \n\t
  • For example, suppose traveling the first road takes 1.4 hours and traveling the second road takes 0.6 hours. Skipping the rest after the first road will mean you finish traveling the second road right at the 2 hour mark, letting you start traveling the third road immediately.
  • \n
\n\n

Return the minimum number of skips required to arrive at the meeting on time, or -1 if it is impossible.

\n\n

 

\n

Example 1:

\n\n
\nInput: dist = [1,3,2], speed = 4, hoursBefore = 2\nOutput: 1\nExplanation:\nWithout skipping any rests, you will arrive in (1/4 + 3/4) + (3/4 + 1/4) + (2/4) = 2.5 hours.\nYou can skip the first rest to arrive in ((1/4 + 0) + (3/4 + 0)) + (2/4) = 1.5 hours.\nNote that the second rest is shortened because you finish traveling the second road at an integer hour due to skipping the first rest.\n
\n\n

Example 2:

\n\n
\nInput: dist = [7,3,5,5], speed = 2, hoursBefore = 10\nOutput: 2\nExplanation:\nWithout skipping any rests, you will arrive in (7/2 + 1/2) + (3/2 + 1/2) + (5/2 + 1/2) + (5/2) = 11.5 hours.\nYou can skip the first and third rest to arrive in ((7/2 + 0) + (3/2 + 0)) + ((5/2 + 0) + (5/2)) = 10 hours.\n
\n\n

Example 3:

\n\n
\nInput: dist = [7,3,5,5], speed = 1, hoursBefore = 10\nOutput: -1\nExplanation: It is impossible to arrive at the meeting on time even if you skip all the rests.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == dist.length
  • \n\t
  • 1 <= n <= 1000
  • \n\t
  • 1 <= dist[i] <= 105
  • \n\t
  • 1 <= speed <= 106
  • \n\t
  • 1 <= hoursBefore <= 107
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 hoursBefore \uff0c\u8868\u793a\u4f60\u8981\u524d\u5f80\u4f1a\u8bae\u6240\u5269\u4e0b\u7684\u53ef\u7528\u5c0f\u65f6\u6570\u3002\u8981\u60f3\u6210\u529f\u62b5\u8fbe\u4f1a\u8bae\u73b0\u573a\uff0c\u4f60\u5fc5\u987b\u9014\u7ecf n \u6761\u9053\u8def\u3002\u9053\u8def\u7684\u957f\u5ea6\u7528\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u6574\u6570\u6570\u7ec4 dist \u8868\u793a\uff0c\u5176\u4e2d dist[i] \u8868\u793a\u7b2c i \u6761\u9053\u8def\u7684\u957f\u5ea6\uff08\u5355\u4f4d\uff1a\u5343\u7c73\uff09\u3002\u53e6\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 speed \uff0c\u8868\u793a\u4f60\u5728\u9053\u8def\u4e0a\u524d\u8fdb\u7684\u901f\u5ea6\uff08\u5355\u4f4d\uff1a\u5343\u7c73\u6bcf\u5c0f\u65f6\uff09\u3002

\n\n

\u5f53\u4f60\u901a\u8fc7\u7b2c i \u6761\u8def\u4e4b\u540e\uff0c\u5c31\u5fc5\u987b\u4f11\u606f\u5e76\u7b49\u5f85\uff0c\u76f4\u5230 \u4e0b\u4e00\u4e2a\u6574\u6570\u5c0f\u65f6 \u624d\u80fd\u5f00\u59cb\u7ee7\u7eed\u901a\u8fc7\u4e0b\u4e00\u6761\u9053\u8def\u3002\u6ce8\u610f\uff1a\u4f60\u4e0d\u9700\u8981\u5728\u901a\u8fc7\u6700\u540e\u4e00\u6761\u9053\u8def\u540e\u4f11\u606f\uff0c\u56e0\u4e3a\u90a3\u65f6\u4f60\u5df2\u7ecf\u62b5\u8fbe\u4f1a\u8bae\u73b0\u573a\u3002

\n\n
    \n\t
  • \u4f8b\u5982\uff0c\u5982\u679c\u4f60\u901a\u8fc7\u4e00\u6761\u9053\u8def\u7528\u53bb 1.4 \u5c0f\u65f6\uff0c\u90a3\u4f60\u5fc5\u987b\u505c\u4e0b\u6765\u7b49\u5f85\uff0c\u5230\u00a02 \u5c0f\u65f6\u624d\u53ef\u4ee5\u7ee7\u7eed\u901a\u8fc7\u4e0b\u4e00\u6761\u9053\u8def\u3002\u5982\u679c\u901a\u8fc7\u4e00\u6761\u9053\u8def\u6070\u597d\u7528\u53bb 2 \u5c0f\u65f6\uff0c\u5c31\u65e0\u9700\u7b49\u5f85\uff0c\u53ef\u4ee5\u76f4\u63a5\u7ee7\u7eed\u3002
  • \n
\n\n

\u7136\u800c\uff0c\u4e3a\u4e86\u80fd\u51c6\u65f6\u5230\u8fbe\uff0c\u4f60\u53ef\u4ee5\u9009\u62e9 \u8df3\u8fc7 \u4e00\u4e9b\u8def\u7684\u4f11\u606f\u65f6\u95f4\uff0c\u8fd9\u610f\u5473\u7740\u4f60\u4e0d\u5fc5\u7b49\u5f85\u4e0b\u4e00\u4e2a\u6574\u6570\u5c0f\u65f6\u3002\u6ce8\u610f\uff0c\u8fd9\u610f\u5473\u7740\u4e0e\u4e0d\u8df3\u8fc7\u4efb\u4f55\u4f11\u606f\u65f6\u95f4\u76f8\u6bd4\uff0c\u4f60\u53ef\u80fd\u5728\u4e0d\u540c\u65f6\u523b\u5230\u8fbe\u63a5\u4e0b\u6765\u7684\u9053\u8def\u3002

\n\n
    \n\t
  • \u4f8b\u5982\uff0c\u5047\u8bbe\u901a\u8fc7\u7b2c 1 \u6761\u9053\u8def\u7528\u53bb 1.4 \u5c0f\u65f6\uff0c\u4e14\u901a\u8fc7\u7b2c 2 \u6761\u9053\u8def\u7528\u53bb 0.6 \u5c0f\u65f6\u3002\u8df3\u8fc7\u7b2c 1 \u6761\u9053\u8def\u7684\u4f11\u606f\u65f6\u95f4\u610f\u5473\u7740\u4f60\u5c06\u4f1a\u5728\u6070\u597d\u00a02 \u5c0f\u65f6\u5b8c\u6210\u901a\u8fc7\u7b2c 2 \u6761\u9053\u8def\uff0c\u4e14\u4f60\u80fd\u591f\u7acb\u5373\u5f00\u59cb\u901a\u8fc7\u7b2c 3 \u6761\u9053\u8def\u3002
  • \n
\n\n

\u8fd4\u56de\u51c6\u65f6\u62b5\u8fbe\u4f1a\u8bae\u73b0\u573a\u6240\u9700\u8981\u7684 \u6700\u5c0f\u8df3\u8fc7\u6b21\u6570 \uff0c\u5982\u679c \u65e0\u6cd5\u51c6\u65f6\u53c2\u4f1a \uff0c\u8fd4\u56de -1 \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1adist = [1,3,2], speed = 4, hoursBefore = 2\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\n\u4e0d\u8df3\u8fc7\u4efb\u4f55\u4f11\u606f\u65f6\u95f4\uff0c\u4f60\u5c06\u7528 (1/4 + 3/4) + (3/4 + 1/4) + (2/4) = 2.5 \u5c0f\u65f6\u624d\u80fd\u62b5\u8fbe\u4f1a\u8bae\u73b0\u573a\u3002\n\u53ef\u4ee5\u8df3\u8fc7\u7b2c 1 \u6b21\u4f11\u606f\u65f6\u95f4\uff0c\u5171\u7528 ((1/4 + 0) + (3/4 + 0)) + (2/4) = 1.5 \u5c0f\u65f6\u62b5\u8fbe\u4f1a\u8bae\u73b0\u573a\u3002\n\u6ce8\u610f\uff0c\u7b2c 2 \u6b21\u4f11\u606f\u65f6\u95f4\u7f29\u77ed\u4e3a 0 \uff0c\u7531\u4e8e\u8df3\u8fc7\u7b2c 1 \u6b21\u4f11\u606f\u65f6\u95f4\uff0c\u4f60\u662f\u5728\u6574\u6570\u5c0f\u65f6\u5904\u5b8c\u6210\u901a\u8fc7\u7b2c 2 \u6761\u9053\u8def\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1adist = [7,3,5,5], speed = 2, hoursBefore = 10\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n\u4e0d\u8df3\u8fc7\u4efb\u4f55\u4f11\u606f\u65f6\u95f4\uff0c\u4f60\u5c06\u7528 (7/2 + 1/2) + (3/2 + 1/2) + (5/2 + 1/2) + (5/2) = 11.5 \u5c0f\u65f6\u624d\u80fd\u62b5\u8fbe\u4f1a\u8bae\u73b0\u573a\u3002\n\u53ef\u4ee5\u8df3\u8fc7\u7b2c 1 \u6b21\u548c\u7b2c 3 \u6b21\u4f11\u606f\u65f6\u95f4\uff0c\u5171\u7528 ((7/2 + 0) + (3/2 + 0)) + ((5/2 + 0) + (5/2)) = 10 \u5c0f\u65f6\u62b5\u8fbe\u4f1a\u8bae\u73b0\u573a\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1adist = [7,3,5,5], speed = 1, hoursBefore = 10\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u5373\u4f7f\u8df3\u8fc7\u6240\u6709\u7684\u4f11\u606f\u65f6\u95f4\uff0c\u4e5f\u65e0\u6cd5\u51c6\u65f6\u53c2\u52a0\u4f1a\u8bae\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • n == dist.length
  • \n\t
  • 1 <= n <= 1000
  • \n\t
  • 1 <= dist[i] <= 105
  • \n\t
  • 1 <= speed <= 106
  • \n\t
  • 1 <= hoursBefore <= 107
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minSkips(vector& dist, int speed, int hoursBefore) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minSkips(int[] dist, int speed, int hoursBefore) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minSkips(self, dist, speed, hoursBefore):\n \"\"\"\n :type dist: List[int]\n :type speed: int\n :type hoursBefore: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minSkips(self, dist: List[int], speed: int, hoursBefore: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minSkips(int* dist, int distSize, int speed, int hoursBefore){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinSkips(int[] dist, int speed, int hoursBefore) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} dist\n * @param {number} speed\n * @param {number} hoursBefore\n * @return {number}\n */\nvar minSkips = function(dist, speed, hoursBefore) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} dist\n# @param {Integer} speed\n# @param {Integer} hours_before\n# @return {Integer}\ndef min_skips(dist, speed, hours_before)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minSkips(_ dist: [Int], _ speed: Int, _ hoursBefore: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minSkips(dist []int, speed int, hoursBefore int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minSkips(dist: Array[Int], speed: Int, hoursBefore: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minSkips(dist: IntArray, speed: Int, hoursBefore: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_skips(dist: Vec, speed: i32, hours_before: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $dist\n * @param Integer $speed\n * @param Integer $hoursBefore\n * @return Integer\n */\n function minSkips($dist, $speed, $hoursBefore) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minSkips(dist: number[], speed: number, hoursBefore: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-skips dist speed hoursBefore)\n (-> (listof exact-integer?) exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1883](https://leetcode-cn.com/problems/minimum-skips-to-arrive-at-meeting-on-time)", "[\u51c6\u65f6\u62b5\u8fbe\u4f1a\u8bae\u73b0\u573a\u7684\u6700\u5c0f\u8df3\u8fc7\u4f11\u606f\u6b21\u6570](/solution/1800-1899/1883.Minimum%20Skips%20to%20Arrive%20at%20Meeting%20On%20Time/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1883](https://leetcode.com/problems/minimum-skips-to-arrive-at-meeting-on-time)", "[Minimum Skips to Arrive at Meeting On Time](/solution/1800-1899/1883.Minimum%20Skips%20to%20Arrive%20at%20Meeting%20On%20Time/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "2012", "frontend_question_id": "1882", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/process-tasks-using-servers", "url_en": "https://leetcode.com/problems/process-tasks-using-servers", "relative_path_cn": "/solution/1800-1899/1882.Process%20Tasks%20Using%20Servers/README.md", "relative_path_en": "/solution/1800-1899/1882.Process%20Tasks%20Using%20Servers/README_EN.md", "title_cn": "\u4f7f\u7528\u670d\u52a1\u5668\u5904\u7406\u4efb\u52a1", "title_en": "Process Tasks Using Servers", "question_title_slug": "process-tasks-using-servers", "content_en": "

You are given two 0-indexed integer arrays servers and tasks of lengths n\u200b\u200b\u200b\u200b\u200b\u200b and m\u200b\u200b\u200b\u200b\u200b\u200b respectively. servers[i] is the weight of the i\u200b\u200b\u200b\u200b\u200b\u200bth\u200b\u200b\u200b\u200b server, and tasks[j] is the time needed to process the j\u200b\u200b\u200b\u200b\u200b\u200bth\u200b\u200b\u200b\u200b task in seconds.

\n\n

Tasks are assigned to the servers using a task queue. Initially, all servers are free, and the queue is empty.

\n\n

At second j, the jth task is inserted into the queue (starting with the 0th task being inserted at second 0). As long as there are free servers and the queue is not empty, the task in the front of the queue will be assigned to a free server with the smallest weight, and in case of a tie, it is assigned to a free server with the smallest index.

\n\n

If there are no free servers and the queue is not empty, we wait until a server becomes free and immediately assign the next task. If multiple servers become free at the same time, then multiple tasks from the queue will be assigned in order of insertion following the weight and index priorities above.

\n\n

A server that is assigned task j at second t will be free again at second t + tasks[j].

\n\n

Build an array ans\u200b\u200b\u200b\u200b of length m, where ans[j] is the index of the server the j\u200b\u200b\u200b\u200b\u200b\u200bth task will be assigned to.

\n\n

Return the array ans\u200b\u200b\u200b\u200b.

\n\n

 

\n

Example 1:

\n\n
\nInput: servers = [3,3,2], tasks = [1,2,3,2,1,2]\nOutput: [2,2,0,2,1,2]\nExplanation: Events in chronological order go as follows:\n- At second 0, task 0 is added and processed using server 2 until second 1.\n- At second 1, server 2 becomes free. Task 1 is added and processed using server 2 until second 3.\n- At second 2, task 2 is added and processed using server 0 until second 5.\n- At second 3, server 2 becomes free. Task 3 is added and processed using server 2 until second 5.\n- At second 4, task 4 is added and processed using server 1 until second 5.\n- At second 5, all servers become free. Task 5 is added and processed using server 2 until second 7.
\n\n

Example 2:

\n\n
\nInput: servers = [5,1,4,3,2], tasks = [2,1,2,4,5,2,1]\nOutput: [1,4,1,4,1,3,2]\nExplanation: Events in chronological order go as follows: \n- At second 0, task 0 is added and processed using server 1 until second 2.\n- At second 1, task 1 is added and processed using server 4 until second 2.\n- At second 2, servers 1 and 4 become free. Task 2 is added and processed using server 1 until second 4. \n- At second 3, task 3 is added and processed using server 4 until second 7.\n- At second 4, server 1 becomes free. Task 4 is added and processed using server 1 until second 9. \n- At second 5, task 5 is added and processed using server 3 until second 7.\n- At second 6, task 6 is added and processed using server 2 until second 7.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • servers.length == n
  • \n\t
  • tasks.length == m
  • \n\t
  • 1 <= n, m <= 2 * 105
  • \n\t
  • 1 <= servers[i], tasks[j] <= 2 * 105
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e24\u4e2a \u4e0b\u6807\u4ece 0 \u5f00\u59cb \u7684\u6574\u6570\u6570\u7ec4 servers \u548c tasks \uff0c\u957f\u5ea6\u5206\u522b\u4e3a n\u200b\u200b\u200b\u200b\u200b\u200b \u548c m\u200b\u200b\u200b\u200b\u200b\u200b \u3002servers[i] \u662f\u7b2c i\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b \u53f0\u670d\u52a1\u5668\u7684 \u6743\u91cd \uff0c\u800c tasks[j] \u662f\u5904\u7406\u7b2c j\u200b\u200b\u200b\u200b\u200b\u200b \u9879\u4efb\u52a1 \u6240\u9700\u8981\u7684\u65f6\u95f4\uff08\u5355\u4f4d\uff1a\u79d2\uff09\u3002

\n\n

\u4f60\u6b63\u5728\u8fd0\u884c\u4e00\u4e2a\u4eff\u771f\u7cfb\u7edf\uff0c\u5728\u5904\u7406\u5b8c\u6240\u6709\u4efb\u52a1\u540e\uff0c\u8be5\u7cfb\u7edf\u5c06\u4f1a\u5173\u95ed\u3002\u6bcf\u53f0\u670d\u52a1\u5668\u53ea\u80fd\u540c\u65f6\u5904\u7406\u4e00\u9879\u4efb\u52a1\u3002\u7b2c 0 \u9879\u4efb\u52a1\u5728\u7b2c 0 \u79d2\u53ef\u4ee5\u5f00\u59cb\u5904\u7406\uff0c\u76f8\u5e94\u5730\uff0c\u7b2c j \u9879\u4efb\u52a1\u5728\u7b2c j\u00a0\u79d2\u53ef\u4ee5\u5f00\u59cb\u5904\u7406\u3002\u5904\u7406\u7b2c j \u9879\u4efb\u52a1\u65f6\uff0c\u4f60\u9700\u8981\u4e3a\u5b83\u5206\u914d\u4e00\u53f0 \u6743\u91cd\u6700\u5c0f \u7684\u7a7a\u95f2\u670d\u52a1\u5668\u3002\u5982\u679c\u5b58\u5728\u591a\u53f0\u76f8\u540c\u6743\u91cd\u7684\u7a7a\u95f2\u670d\u52a1\u5668\uff0c\u8bf7\u9009\u62e9 \u4e0b\u6807\u6700\u5c0f \u7684\u670d\u52a1\u5668\u3002\u5982\u679c\u4e00\u53f0\u7a7a\u95f2\u670d\u52a1\u5668\u5728\u7b2c t \u79d2\u5206\u914d\u5230\u7b2c j \u9879\u4efb\u52a1\uff0c\u90a3\u4e48\u5728 t + tasks[j] \u65f6\u5b83\u5c06\u6062\u590d\u7a7a\u95f2\u72b6\u6001\u3002

\n\n

\u5982\u679c\u6ca1\u6709\u7a7a\u95f2\u670d\u52a1\u5668\uff0c\u5219\u5fc5\u987b\u7b49\u5f85\uff0c\u76f4\u5230\u51fa\u73b0\u4e00\u53f0\u7a7a\u95f2\u670d\u52a1\u5668\uff0c\u5e76 \u5c3d\u53ef\u80fd\u65e9\u00a0\u5730\u5904\u7406\u5269\u4f59\u4efb\u52a1\u3002 \u5982\u679c\u6709\u591a\u9879\u4efb\u52a1\u7b49\u5f85\u5206\u914d\uff0c\u5219\u6309\u7167 \u4e0b\u6807\u9012\u589e \u7684\u987a\u5e8f\u5b8c\u6210\u5206\u914d\u3002

\n\n

\u5982\u679c\u540c\u4e00\u65f6\u523b\u5b58\u5728\u591a\u53f0\u7a7a\u95f2\u670d\u52a1\u5668\uff0c\u53ef\u4ee5\u540c\u65f6\u5c06\u591a\u9879\u4efb\u52a1\u5206\u522b\u5206\u914d\u7ed9\u5b83\u4eec\u3002

\n\n

\u6784\u5efa\u957f\u5ea6\u4e3a\u00a0m \u7684\u7b54\u6848\u6570\u7ec4 ans \uff0c\u5176\u4e2d ans[j] \u662f\u7b2c j \u9879\u4efb\u52a1\u5206\u914d\u7684\u670d\u52a1\u5668\u7684\u4e0b\u6807\u3002

\n\n

\u8fd4\u56de\u7b54\u6848\u6570\u7ec4 ans\u200b\u200b\u200b\u200b \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aservers = [3,3,2], tasks = [1,2,3,2,1,2]\n\u8f93\u51fa\uff1a[2,2,0,2,1,2]\n\u89e3\u91ca\uff1a\u4e8b\u4ef6\u6309\u65f6\u95f4\u987a\u5e8f\u5982\u4e0b\uff1a\n- 0 \u79d2\u65f6\uff0c\u7b2c 0 \u9879\u4efb\u52a1\u52a0\u5165\u5230\u4efb\u52a1\u961f\u5217\uff0c\u4f7f\u7528\u7b2c 2 \u53f0\u670d\u52a1\u5668\u5904\u7406\u5230 1 \u79d2\u3002\n- 1 \u79d2\u65f6\uff0c\u7b2c 2 \u53f0\u670d\u52a1\u5668\u7a7a\u95f2\uff0c\u7b2c 1 \u9879\u4efb\u52a1\u52a0\u5165\u5230\u4efb\u52a1\u961f\u5217\uff0c\u4f7f\u7528\u7b2c 2 \u53f0\u670d\u52a1\u5668\u5904\u7406\u5230 3 \u79d2\u3002\n- 2 \u79d2\u65f6\uff0c\u7b2c 2 \u9879\u4efb\u52a1\u52a0\u5165\u5230\u4efb\u52a1\u961f\u5217\uff0c\u4f7f\u7528\u7b2c 0 \u53f0\u670d\u52a1\u5668\u5904\u7406\u5230 5 \u79d2\u3002\n- 3 \u79d2\u65f6\uff0c\u7b2c 2 \u53f0\u670d\u52a1\u5668\u7a7a\u95f2\uff0c\u7b2c 3 \u9879\u4efb\u52a1\u52a0\u5165\u5230\u4efb\u52a1\u961f\u5217\uff0c\u4f7f\u7528\u7b2c 2 \u53f0\u670d\u52a1\u5668\u5904\u7406\u5230 5 \u79d2\u3002\n- 4 \u79d2\u65f6\uff0c\u7b2c 4 \u9879\u4efb\u52a1\u52a0\u5165\u5230\u4efb\u52a1\u961f\u5217\uff0c\u4f7f\u7528\u7b2c 1 \u53f0\u670d\u52a1\u5668\u5904\u7406\u5230 5 \u79d2\u3002\n- 5 \u79d2\u65f6\uff0c\u6240\u6709\u670d\u52a1\u5668\u90fd\u7a7a\u95f2\uff0c\u7b2c 5 \u9879\u4efb\u52a1\u52a0\u5165\u5230\u4efb\u52a1\u961f\u5217\uff0c\u4f7f\u7528\u7b2c 2 \u53f0\u670d\u52a1\u5668\u5904\u7406\u5230 7 \u79d2\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aservers = [5,1,4,3,2], tasks = [2,1,2,4,5,2,1]\n\u8f93\u51fa\uff1a[1,4,1,4,1,3,2]\n\u89e3\u91ca\uff1a\u4e8b\u4ef6\u6309\u65f6\u95f4\u987a\u5e8f\u5982\u4e0b\uff1a\n- 0 \u79d2\u65f6\uff0c\u7b2c 0 \u9879\u4efb\u52a1\u52a0\u5165\u5230\u4efb\u52a1\u961f\u5217\uff0c\u4f7f\u7528\u7b2c 1 \u53f0\u670d\u52a1\u5668\u5904\u7406\u5230 2 \u79d2\u3002\n- 1 \u79d2\u65f6\uff0c\u7b2c 1 \u9879\u4efb\u52a1\u52a0\u5165\u5230\u4efb\u52a1\u961f\u5217\uff0c\u4f7f\u7528\u7b2c 4 \u53f0\u670d\u52a1\u5668\u5904\u7406\u5230 2 \u79d2\u3002\n- 2 \u79d2\u65f6\uff0c\u7b2c 1 \u53f0\u548c\u7b2c 4 \u53f0\u670d\u52a1\u5668\u7a7a\u95f2\uff0c\u7b2c 2 \u9879\u4efb\u52a1\u52a0\u5165\u5230\u4efb\u52a1\u961f\u5217\uff0c\u4f7f\u7528\u7b2c 1 \u53f0\u670d\u52a1\u5668\u5904\u7406\u5230 4 \u79d2\u3002\n- 3 \u79d2\u65f6\uff0c\u7b2c 3 \u9879\u4efb\u52a1\u52a0\u5165\u5230\u4efb\u52a1\u961f\u5217\uff0c\u4f7f\u7528\u7b2c 4 \u53f0\u670d\u52a1\u5668\u5904\u7406\u5230 7 \u79d2\u3002\n- 4 \u79d2\u65f6\uff0c\u7b2c 1 \u53f0\u670d\u52a1\u5668\u7a7a\u95f2\uff0c\u7b2c 4 \u9879\u4efb\u52a1\u52a0\u5165\u5230\u4efb\u52a1\u961f\u5217\uff0c\u4f7f\u7528\u7b2c 1 \u53f0\u670d\u52a1\u5668\u5904\u7406\u5230 9 \u79d2\u3002\n- 5 \u79d2\u65f6\uff0c\u7b2c 5 \u9879\u4efb\u52a1\u52a0\u5165\u5230\u4efb\u52a1\u961f\u5217\uff0c\u4f7f\u7528\u7b2c 3 \u53f0\u670d\u52a1\u5668\u5904\u7406\u5230 7 \u79d2\u3002\n- 6 \u79d2\u65f6\uff0c\u7b2c 6 \u9879\u4efb\u52a1\u52a0\u5165\u5230\u4efb\u52a1\u961f\u5217\uff0c\u4f7f\u7528\u7b2c 2 \u53f0\u670d\u52a1\u5668\u5904\u7406\u5230 7 \u79d2\u3002
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • servers.length == n
  • \n\t
  • tasks.length == m
  • \n\t
  • 1 <= n, m <= 2 * 105
  • \n\t
  • 1 <= servers[i], tasks[j] <= 2 * 105
  • \n
\n", "tags_en": ["Heap"], "tags_cn": ["\u5806"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector assignTasks(vector& servers, vector& tasks) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] assignTasks(int[] servers, int[] tasks) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def assignTasks(self, servers, tasks):\n \"\"\"\n :type servers: List[int]\n :type tasks: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def assignTasks(self, servers: List[int], tasks: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* assignTasks(int* servers, int serversSize, int* tasks, int tasksSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] AssignTasks(int[] servers, int[] tasks) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} servers\n * @param {number[]} tasks\n * @return {number[]}\n */\nvar assignTasks = function(servers, tasks) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} servers\n# @param {Integer[]} tasks\n# @return {Integer[]}\ndef assign_tasks(servers, tasks)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func assignTasks(_ servers: [Int], _ tasks: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func assignTasks(servers []int, tasks []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def assignTasks(servers: Array[Int], tasks: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun assignTasks(servers: IntArray, tasks: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn assign_tasks(servers: Vec, tasks: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $servers\n * @param Integer[] $tasks\n * @return Integer[]\n */\n function assignTasks($servers, $tasks) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function assignTasks(servers: number[], tasks: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (assign-tasks servers tasks)\n (-> (listof exact-integer?) (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1882](https://leetcode-cn.com/problems/process-tasks-using-servers)", "[\u4f7f\u7528\u670d\u52a1\u5668\u5904\u7406\u4efb\u52a1](/solution/1800-1899/1882.Process%20Tasks%20Using%20Servers/README.md)", "`\u5806`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1882](https://leetcode.com/problems/process-tasks-using-servers)", "[Process Tasks Using Servers](/solution/1800-1899/1882.Process%20Tasks%20Using%20Servers/README_EN.md)", "`Heap`", "Medium", ""]}, {"question_id": "2011", "frontend_question_id": "1881", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-value-after-insertion", "url_en": "https://leetcode.com/problems/maximum-value-after-insertion", "relative_path_cn": "/solution/1800-1899/1881.Maximum%20Value%20after%20Insertion/README.md", "relative_path_en": "/solution/1800-1899/1881.Maximum%20Value%20after%20Insertion/README_EN.md", "title_cn": "\u63d2\u5165\u540e\u7684\u6700\u5927\u503c", "title_en": "Maximum Value after Insertion", "question_title_slug": "maximum-value-after-insertion", "content_en": "

You are given a very large integer n, represented as a string,\u200b\u200b\u200b\u200b\u200b\u200b and an integer digit x. The digits in n and the digit x are in the inclusive range [1, 9], and n may represent a negative number.

\n\n

You want to maximize n's numerical value by inserting x anywhere in the decimal representation of n\u200b\u200b\u200b\u200b\u200b\u200b. You cannot insert x to the left of the negative sign.

\n\n
    \n\t
  • For example, if n = 73 and x = 6, it would be best to insert it between 7 and 3, making n = 763.
  • \n\t
  • If n = -55 and x = 2, it would be best to insert it before the first 5, making n = -255.
  • \n
\n\n

Return a string representing the maximum value of n\u200b\u200b\u200b\u200b\u200b\u200b after the insertion.

\n\n

 

\n

Example 1:

\n\n
\nInput: n = "99", x = 9\nOutput: "999"\nExplanation: The result is the same regardless of where you insert 9.\n
\n\n

Example 2:

\n\n
\nInput: n = "-13", x = 2\nOutput: "-123"\nExplanation: You can make n one of {-213, -123, -132}, and the largest of those three is -123.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n.length <= 105
  • \n\t
  • 1 <= x <= 9
  • \n\t
  • The digits in n\u200b\u200b\u200b are in the range [1, 9].
  • \n\t
  • n is a valid representation of an integer.
  • \n\t
  • In the case of a negative n,\u200b\u200b\u200b\u200b\u200b\u200b it will begin with '-'.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u975e\u5e38\u5927\u7684\u6574\u6570 n \u548c\u4e00\u4e2a\u6574\u6570\u6570\u5b57 x \uff0c\u5927\u6574\u6570 n\u00a0\u7528\u4e00\u4e2a\u5b57\u7b26\u4e32\u8868\u793a\u3002n \u4e2d\u6bcf\u4e00\u4f4d\u6570\u5b57\u548c\u6570\u5b57 x \u90fd\u5904\u4e8e\u95ed\u533a\u95f4 [1, 9] \u4e2d\uff0c\u4e14 n \u53ef\u80fd\u8868\u793a\u4e00\u4e2a \u8d1f\u6570 \u3002

\n\n

\u4f60\u6253\u7b97\u901a\u8fc7\u5728 n \u7684\u5341\u8fdb\u5236\u8868\u793a\u7684\u4efb\u610f\u4f4d\u7f6e\u63d2\u5165 x \u6765 \u6700\u5927\u5316 n \u7684 \u6570\u503c \u200b\u200b\u200b\u200b\u200b\u200b\u3002\u4f46 \u4e0d\u80fd \u5728\u8d1f\u53f7\u7684\u5de6\u8fb9\u63d2\u5165 x \u3002

\n\n
    \n\t
  • \u4f8b\u5982\uff0c\u5982\u679c n = 73 \u4e14 x = 6 \uff0c\u90a3\u4e48\u6700\u4f73\u65b9\u6848\u662f\u5c06 6 \u63d2\u5165 7 \u548c 3 \u4e4b\u95f4\uff0c\u4f7f n = 763 \u3002
  • \n\t
  • \u5982\u679c n = -55 \u4e14 x = 2 \uff0c\u90a3\u4e48\u6700\u4f73\u65b9\u6848\u662f\u5c06 2 \u63d2\u5728\u7b2c\u4e00\u4e2a 5 \u4e4b\u524d\uff0c\u4f7f n = -255 \u3002
  • \n
\n\n

\u8fd4\u56de\u63d2\u5165\u64cd\u4f5c\u540e\uff0c\u7528\u5b57\u7b26\u4e32\u8868\u793a\u7684\u00a0n \u7684\u6700\u5927\u503c\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1an = \"99\", x = 9\n\u8f93\u51fa\uff1a\"999\"\n\u89e3\u91ca\uff1a\u4e0d\u7ba1\u5728\u54ea\u91cc\u63d2\u5165 9 \uff0c\u7ed3\u679c\u90fd\u662f\u76f8\u540c\u7684\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1an = \"-13\", x = 2\n\u8f93\u51fa\uff1a\"-123\"\n\u89e3\u91ca\uff1a\u5411 n \u4e2d\u63d2\u5165 x \u53ef\u4ee5\u5f97\u5230 -213\u3001-123 \u6216\u8005 -132 \uff0c\u4e09\u8005\u4e2d\u6700\u5927\u7684\u662f -123 \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n.length <= 105
  • \n\t
  • 1 <= x <= 9
  • \n\t
  • n\u200b\u200b\u200b \u4e2d\u6bcf\u4e00\u4f4d\u7684\u6570\u5b57\u90fd\u5728\u95ed\u533a\u95f4 [1, 9] \u4e2d\u3002
  • \n\t
  • n\u00a0\u4ee3\u8868\u4e00\u4e2a\u6709\u6548\u7684\u6574\u6570\u3002
  • \n\t
  • \u5f53 n \u8868\u793a\u8d1f\u6570\u65f6\uff0c\u5c06\u4f1a\u4ee5\u5b57\u7b26 '-' \u5f00\u59cb\u3002
  • \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string maxValue(string n, int x) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String maxValue(String n, int x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxValue(self, n, x):\n \"\"\"\n :type n: str\n :type x: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxValue(self, n: str, x: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * maxValue(char * n, int x){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string MaxValue(string n, int x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} n\n * @param {number} x\n * @return {string}\n */\nvar maxValue = function(n, x) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} n\n# @param {Integer} x\n# @return {String}\ndef max_value(n, x)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxValue(_ n: String, _ x: Int) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxValue(n string, x int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxValue(n: String, x: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxValue(n: String, x: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_value(n: String, x: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $n\n * @param Integer $x\n * @return String\n */\n function maxValue($n, $x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxValue(n: string, x: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-value n x)\n (-> string? exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1881](https://leetcode-cn.com/problems/maximum-value-after-insertion)", "[\u63d2\u5165\u540e\u7684\u6700\u5927\u503c](/solution/1800-1899/1881.Maximum%20Value%20after%20Insertion/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1881](https://leetcode.com/problems/maximum-value-after-insertion)", "[Maximum Value after Insertion](/solution/1800-1899/1881.Maximum%20Value%20after%20Insertion/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "2010", "frontend_question_id": "1880", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/check-if-word-equals-summation-of-two-words", "url_en": "https://leetcode.com/problems/check-if-word-equals-summation-of-two-words", "relative_path_cn": "/solution/1800-1899/1880.Check%20if%20Word%20Equals%20Summation%20of%20Two%20Words/README.md", "relative_path_en": "/solution/1800-1899/1880.Check%20if%20Word%20Equals%20Summation%20of%20Two%20Words/README_EN.md", "title_cn": "\u68c0\u67e5\u67d0\u5355\u8bcd\u662f\u5426\u7b49\u4e8e\u4e24\u5355\u8bcd\u4e4b\u548c", "title_en": "Check if Word Equals Summation of Two Words", "question_title_slug": "check-if-word-equals-summation-of-two-words", "content_en": "

The letter value of a letter is its position in the alphabet starting from 0 (i.e. 'a' -> 0, 'b' -> 1, 'c' -> 2, etc.).

\n\n

The numerical value of some string of lowercase English letters s is the concatenation of the letter values of each letter in s, which is then converted into an integer.

\n\n
    \n\t
  • For example, if s = "acb", we concatenate each letter's letter value, resulting in "021". After converting it, we get 21.
  • \n
\n\n

You are given three strings firstWord, secondWord, and targetWord, each consisting of lowercase English letters 'a' through 'j' inclusive.

\n\n

Return true if the summation of the numerical values of firstWord and secondWord equals the numerical value of targetWord, or false otherwise.

\n\n

 

\n

Example 1:

\n\n
\nInput: firstWord = "acb", secondWord = "cba", targetWord = "cdb"\nOutput: true\nExplanation:\nThe numerical value of firstWord is "acb" -> "021" -> 21.\nThe numerical value of secondWord is "cba" -> "210" -> 210.\nThe numerical value of targetWord is "cdb" -> "231" -> 231.\nWe return true because 21 + 210 == 231.\n
\n\n

Example 2:

\n\n
\nInput: firstWord = "aaa", secondWord = "a", targetWord = "aab"\nOutput: false\nExplanation: \nThe numerical value of firstWord is "aaa" -> "000" -> 0.\nThe numerical value of secondWord is "a" -> "0" -> 0.\nThe numerical value of targetWord is "aab" -> "001" -> 1.\nWe return false because 0 + 0 != 1.\n
\n\n

Example 3:

\n\n
\nInput: firstWord = "aaa", secondWord = "a", targetWord = "aaaa"\nOutput: true\nExplanation: \nThe numerical value of firstWord is "aaa" -> "000" -> 0.\nThe numerical value of secondWord is "a" -> "0" -> 0.\nThe numerical value of targetWord is "aaaa" -> "0000" -> 0.\nWe return true because 0 + 0 == 0.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= firstWord.length, secondWord.length, targetWord.length <= 8
  • \n\t
  • firstWord, secondWord, and targetWord consist of lowercase English letters from 'a' to 'j' inclusive.
  • \n
\n", "content_cn": "

\u5b57\u6bcd\u7684 \u5b57\u6bcd\u503c \u53d6\u51b3\u4e8e\u5b57\u6bcd\u5728\u5b57\u6bcd\u8868\u4e2d\u7684\u4f4d\u7f6e\uff0c\u4ece 0 \u5f00\u59cb \u8ba1\u6570\u3002\u5373\uff0c'a' -> 0\u3001'b' -> 1\u3001'c' -> 2\uff0c\u4ee5\u6b64\u7c7b\u63a8\u3002

\n\n

\u5bf9\u67d0\u4e2a\u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210\u7684\u5b57\u7b26\u4e32\u00a0s \u800c\u8a00\uff0c\u5176 \u6570\u503c \u5c31\u7b49\u4e8e\u5c06 s \u4e2d\u6bcf\u4e2a\u5b57\u6bcd\u7684 \u5b57\u6bcd\u503c \u6309\u987a\u5e8f \u8fde\u63a5 \u5e76 \u8f6c\u6362 \u6210\u5bf9\u5e94\u6574\u6570\u3002

\n\n
    \n\t
  • \u4f8b\u5982\uff0cs = \"acb\" \uff0c\u4f9d\u6b21\u8fde\u63a5\u6bcf\u4e2a\u5b57\u6bcd\u7684\u5b57\u6bcd\u503c\u53ef\u4ee5\u5f97\u5230 \"021\" \uff0c\u8f6c\u6362\u4e3a\u6574\u6570\u5f97\u5230 21 \u3002
  • \n
\n\n

\u7ed9\u4f60\u4e09\u4e2a\u5b57\u7b26\u4e32 firstWord\u3001secondWord \u548c targetWord \uff0c\u6bcf\u4e2a\u5b57\u7b26\u4e32\u90fd\u7531\u4ece 'a' \u5230 'j' \uff08\u542b\u00a0'a' \u548c 'j' \uff09\u7684\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\u3002

\n\n

\u5982\u679c\u00a0firstWord \u548c secondWord \u7684 \u6570\u503c\u4e4b\u548c \u7b49\u4e8e targetWord \u7684\u6570\u503c\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1afirstWord = \"acb\", secondWord = \"cba\", targetWord = \"cdb\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\nfirstWord \u7684\u6570\u503c\u4e3a \"acb\" -> \"021\" -> 21\nsecondWord \u7684\u6570\u503c\u4e3a \"cba\" -> \"210\" -> 210\ntargetWord \u7684\u6570\u503c\u4e3a \"cdb\" -> \"231\" -> 231\n\u7531\u4e8e 21 + 210 == 231 \uff0c\u8fd4\u56de true\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1afirstWord = \"aaa\", secondWord = \"a\", targetWord = \"aab\"\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\nfirstWord \u7684\u6570\u503c\u4e3a \"aaa\" -> \"000\" -> 0\nsecondWord \u7684\u6570\u503c\u4e3a \"a\" -> \"0\" -> 0\ntargetWord \u7684\u6570\u503c\u4e3a \"aab\" -> \"001\" -> 1\n\u7531\u4e8e 0 + 0 != 1 \uff0c\u8fd4\u56de false
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1afirstWord = \"aaa\", secondWord = \"a\", targetWord = \"aaaa\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\nfirstWord \u7684\u6570\u503c\u4e3a \"aaa\" -> \"000\" -> 0\nsecondWord \u7684\u6570\u503c\u4e3a \"a\" -> \"0\" -> 0\ntargetWord \u7684\u6570\u503c\u4e3a \"aaaa\" -> \"0000\" -> 0\n\u7531\u4e8e 0 + 0 == 0 \uff0c\u8fd4\u56de true\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= firstWord.length, secondWord.length, targetWord.length <= 8
  • \n\t
  • firstWord\u3001secondWord \u548c targetWord \u4ec5\u7531\u4ece 'a' \u5230 'j' \uff08\u542b\u00a0'a' \u548c 'j' \uff09\u7684\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\u3002
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isSumEqual(string firstWord, string secondWord, string targetWord) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isSumEqual(String firstWord, String secondWord, String targetWord) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isSumEqual(self, firstWord, secondWord, targetWord):\n \"\"\"\n :type firstWord: str\n :type secondWord: str\n :type targetWord: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isSumEqual(char * firstWord, char * secondWord, char * targetWord){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsSumEqual(string firstWord, string secondWord, string targetWord) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} firstWord\n * @param {string} secondWord\n * @param {string} targetWord\n * @return {boolean}\n */\nvar isSumEqual = function(firstWord, secondWord, targetWord) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} first_word\n# @param {String} second_word\n# @param {String} target_word\n# @return {Boolean}\ndef is_sum_equal(first_word, second_word, target_word)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isSumEqual(_ firstWord: String, _ secondWord: String, _ targetWord: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isSumEqual(firstWord string, secondWord string, targetWord string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isSumEqual(firstWord: String, secondWord: String, targetWord: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isSumEqual(firstWord: String, secondWord: String, targetWord: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_sum_equal(first_word: String, second_word: String, target_word: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $firstWord\n * @param String $secondWord\n * @param String $targetWord\n * @return Boolean\n */\n function isSumEqual($firstWord, $secondWord, $targetWord) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isSumEqual(firstWord: string, secondWord: string, targetWord: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-sum-equal firstWord secondWord targetWord)\n (-> string? string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1880](https://leetcode-cn.com/problems/check-if-word-equals-summation-of-two-words)", "[\u68c0\u67e5\u67d0\u5355\u8bcd\u662f\u5426\u7b49\u4e8e\u4e24\u5355\u8bcd\u4e4b\u548c](/solution/1800-1899/1880.Check%20if%20Word%20Equals%20Summation%20of%20Two%20Words/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1880](https://leetcode.com/problems/check-if-word-equals-summation-of-two-words)", "[Check if Word Equals Summation of Two Words](/solution/1800-1899/1880.Check%20if%20Word%20Equals%20Summation%20of%20Two%20Words/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "2009", "frontend_question_id": "1858", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/longest-word-with-all-prefixes", "url_en": "https://leetcode.com/problems/longest-word-with-all-prefixes", "relative_path_cn": "/solution/1800-1899/1858.Longest%20Word%20With%20All%20Prefixes/README.md", "relative_path_en": "/solution/1800-1899/1858.Longest%20Word%20With%20All%20Prefixes/README_EN.md", "title_cn": "", "title_en": "Longest Word With All Prefixes", "question_title_slug": "longest-word-with-all-prefixes", "content_en": "

Given an array of strings words, find the longest string in words such that every prefix of it is also in words.

\r\n\r\n
    \r\n\t
  • For example, let words = ["a", "app", "ap"]. The string "app" has prefixes "ap" and "a", all of which are in words.
  • \r\n
\r\n\r\n

Return the string described above. If there is more than one string with the same length, return the lexicographically smallest one, and if no string exists, return "".

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: words = ["k","ki","kir","kira", "kiran"]\r\nOutput: "kiran"\r\nExplanation: "kiran" has prefixes "kira", "kir", "ki", and "k", and all of them appear in words.\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: words = ["a", "banana", "app", "appl", "ap", "apply", "apple"]\r\nOutput: "apple"\r\nExplanation: Both "apple" and "apply" have all their prefixes in words.\r\nHowever, "apple" is lexicographically smaller, so we return that.\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: words = ["abc", "bc", "ab", "qwe"]\r\nOutput: ""\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= words.length <= 105
  • \r\n\t
  • 1 <= words[i].length <= 105
  • \r\n\t
  • 1 <= sum(words[i].length) <= 105
  • \r\n
", "content_cn": null, "tags_en": ["Depth-first Search", "Trie", "Hash Table"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5b57\u5178\u6811", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string longestWord(vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String longestWord(String[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestWord(self, words):\n \"\"\"\n :type words: List[str]\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestWord(self, words: List[str]) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * longestWord(char ** words, int wordsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string LongestWord(string[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @return {string}\n */\nvar longestWord = function(words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @return {String}\ndef longest_word(words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestWord(_ words: [String]) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestWord(words []string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestWord(words: Array[String]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestWord(words: Array): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_word(words: Vec) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @return String\n */\n function longestWord($words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestWord(words: string[]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-word words)\n (-> (listof string?) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1858](https://leetcode-cn.com/problems/longest-word-with-all-prefixes)", "[Longest Word With All Prefixes](/solution/1800-1899/1858.Longest%20Word%20With%20All%20Prefixes/README_EN.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5b57\u5178\u6811`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1858](https://leetcode.com/problems/longest-word-with-all-prefixes)", "[Longest Word With All Prefixes](/solution/1800-1899/1858.Longest%20Word%20With%20All%20Prefixes/README_EN.md)", "`Depth-first Search`,`Trie`,`Hash Table`", "Medium", "\ud83d\udd12"]}, {"question_id": "2004", "frontend_question_id": "1853", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/convert-date-format", "url_en": "https://leetcode.com/problems/convert-date-format", "relative_path_cn": "/solution/1800-1899/1853.Convert%20Date%20Format/README.md", "relative_path_en": "/solution/1800-1899/1853.Convert%20Date%20Format/README_EN.md", "title_cn": "", "title_en": "Convert Date Format", "question_title_slug": "convert-date-format", "content_en": "

Table: Days

\n\n
\n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| day         | date |\n+-------------+------+\nday is the primary key for this table.\n
\n\n

 

\n\n

Write an SQL query to convert each date in Days into a string formatted as "day_name, month_name day, year".

\n\n

Return the result table in any order.

\n\n

The query result format is in the following example:

\n\n

 

\n\n
\nDays table:\n+------------+\n| day        |\n+------------+\n| 2022-04-12 |\n| 2021-08-09 |\n| 2020-06-26 |\n+------------+\n\nResult table:\n+-------------------------+\n| day                     |\n+-------------------------+\n| Tuesday, April 12, 2022 |\n| Monday, August 9, 2021  |\n| Friday, June 26, 2020   |\n+-------------------------+\nPlease note that the output is case-sensitive.\n
\n", "content_cn": null, "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1853](https://leetcode-cn.com/problems/convert-date-format)", "[Convert Date Format](/solution/1800-1899/1853.Convert%20Date%20Format/README_EN.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1853](https://leetcode.com/problems/convert-date-format)", "[Convert Date Format](/solution/1800-1899/1853.Convert%20Date%20Format/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "2003", "frontend_question_id": "1852", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/distinct-numbers-in-each-subarray", "url_en": "https://leetcode.com/problems/distinct-numbers-in-each-subarray", "relative_path_cn": "/solution/1800-1899/1852.Distinct%20Numbers%20in%20Each%20Subarray/README.md", "relative_path_en": "/solution/1800-1899/1852.Distinct%20Numbers%20in%20Each%20Subarray/README_EN.md", "title_cn": "", "title_en": "Distinct Numbers in Each Subarray", "question_title_slug": "distinct-numbers-in-each-subarray", "content_en": "

Given an integer array nums and an integer k, you are asked to construct the array ans of size n-k+1 where ans[i] is the number of distinct numbers in the subarray nums[i:i+k-1] = [nums[i], nums[i+1], ..., nums[i+k-1]].

\r\n\r\n

Return the array ans.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: nums = [1,2,3,2,2,1,3], k = 3\r\nOutput: [3,2,2,2,3]\r\nExplanation: The number of distinct elements in each subarray goes as follows:\r\n- nums[0:2] = [1,2,3] so ans[0] = 3\r\n- nums[1:3] = [2,3,2] so ans[1] = 2\r\n- nums[2:4] = [3,2,2] so ans[2] = 2\r\n- nums[3:5] = [2,2,1] so ans[3] = 2\r\n- nums[4:6] = [2,1,3] so ans[4] = 3\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: nums = [1,1,1,1,2,3,4], k = 4\r\nOutput: [1,2,3,4]\r\nExplanation: The number of distinct elements in each subarray goes as follows:\r\n- nums[0:3] = [1,1,1,1] so ans[0] = 1\r\n- nums[1:4] = [1,1,1,2] so ans[1] = 2\r\n- nums[2:5] = [1,1,2,3] so ans[2] = 3\r\n- nums[3:6] = [1,2,3,4] so ans[3] = 4\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= k <= nums.length <= 105
  • \r\n\t
  • 1 <= nums[i] <= 105
  • \r\n
", "content_cn": null, "tags_en": ["Array", "Hash Table", "Line Sweep"], "tags_cn": ["\u6570\u7ec4", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector distinctNumbers(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] distinctNumbers(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def distinctNumbers(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def distinctNumbers(self, nums: List[int], k: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* distinctNumbers(int* nums, int numsSize, int k, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] DistinctNumbers(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number[]}\n */\nvar distinctNumbers = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer[]}\ndef distinct_numbers(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func distinctNumbers(_ nums: [Int], _ k: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func distinctNumbers(nums []int, k int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def distinctNumbers(nums: Array[Int], k: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun distinctNumbers(nums: IntArray, k: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn distinct_numbers(nums: Vec, k: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer[]\n */\n function distinctNumbers($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function distinctNumbers(nums: number[], k: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (distinct-numbers nums k)\n (-> (listof exact-integer?) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1852](https://leetcode-cn.com/problems/distinct-numbers-in-each-subarray)", "[Distinct Numbers in Each Subarray](/solution/1800-1899/1852.Distinct%20Numbers%20in%20Each%20Subarray/README_EN.md)", "`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1852](https://leetcode.com/problems/distinct-numbers-in-each-subarray)", "[Distinct Numbers in Each Subarray](/solution/1800-1899/1852.Distinct%20Numbers%20in%20Each%20Subarray/README_EN.md)", "`Array`,`Hash Table`,`Line Sweep`", "Medium", "\ud83d\udd12"]}, {"question_id": "2002", "frontend_question_id": "1872", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/stone-game-viii", "url_en": "https://leetcode.com/problems/stone-game-viii", "relative_path_cn": "/solution/1800-1899/1872.Stone%20Game%20VIII/README.md", "relative_path_en": "/solution/1800-1899/1872.Stone%20Game%20VIII/README_EN.md", "title_cn": "\u77f3\u5b50\u6e38\u620f VIII", "title_en": "Stone Game VIII", "question_title_slug": "stone-game-viii", "content_en": "

Alice and Bob take turns playing a game, with Alice starting first.

\r\n\r\n

There are n stones arranged in a row. On each player's turn, while the number of stones is more than one, they will do the following:

\r\n\r\n
    \r\n\t
  1. Choose an integer x > 1, and remove the leftmost x stones from the row.
  2. \r\n\t
  3. Add the sum of the removed stones' values to the player's score.
  4. \r\n\t
  5. Place a new stone, whose value is equal to that sum, on the left side of the row.
  6. \r\n
\r\n\r\n

The game stops when only one stone is left in the row.

\r\n\r\n

The score difference between Alice and Bob is (Alice's score - Bob's score). Alice's goal is to maximize the score difference, and Bob's goal is the minimize the score difference.

\r\n\r\n

Given an integer array stones of length n where stones[i] represents the value of the ith stone from the left, return the score difference between Alice and Bob if they both play optimally.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: stones = [-1,2,-3,4,-5]\r\nOutput: 5\r\nExplanation:\r\n- Alice removes the first 4 stones, adds (-1) + 2 + (-3) + 4 = 2 to her score, and places a stone of\r\n  value 2 on the left. stones = [2,-5].\r\n- Bob removes the first 2 stones, adds 2 + (-5) = -3 to his score, and places a stone of value -3 on\r\n  the left. stones = [-3].\r\nThe difference between their scores is 2 - (-3) = 5.\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: stones = [7,-6,5,10,5,-2,-6]\r\nOutput: 13\r\nExplanation:\r\n- Alice removes all stones, adds 7 + (-6) + 5 + 10 + 5 + (-2) + (-6) = 13 to her score, and places a\r\n  stone of value 13 on the left. stones = [13].\r\nThe difference between their scores is 13 - 0 = 13.\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: stones = [-10,-12]\r\nOutput: -22\r\nExplanation:\r\n- Alice can only make one move, which is to remove both stones. She adds (-10) + (-12) = -22 to her\r\n  score and places a stone of value -22 on the left. stones = [-22].\r\nThe difference between their scores is (-22) - 0 = -22.\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • n == stones.length
  • \r\n\t
  • 2 <= n <= 105
  • \r\n\t
  • -104 <= stones[i] <= 104
  • \r\n
", "content_cn": "

Alice \u548c Bob \u73a9\u4e00\u4e2a\u6e38\u620f\uff0c\u4e24\u4eba\u8f6e\u6d41\u64cd\u4f5c\uff0c Alice \u5148\u624b\u00a0\u3002

\n\n

\u603b\u5171\u6709\u00a0n\u00a0\u4e2a\u77f3\u5b50\u6392\u6210\u4e00\u884c\u3002\u8f6e\u5230\u67d0\u4e2a\u73a9\u5bb6\u7684\u56de\u5408\u65f6\uff0c\u5982\u679c\u77f3\u5b50\u7684\u6570\u76ee \u5927\u4e8e 1\u00a0\uff0c\u4ed6\u5c06\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\uff1a

\n\n
    \n\t
  1. \u9009\u62e9\u4e00\u4e2a\u6574\u6570\u00a0x > 1\u00a0\uff0c\u5e76\u4e14 \u79fb\u9664\u00a0\u6700\u5de6\u8fb9\u7684\u00a0x\u00a0\u4e2a\u77f3\u5b50\u3002
  2. \n\t
  3. \u5c06\u00a0\u79fb\u9664\u00a0\u7684\u77f3\u5b50\u4ef7\u503c\u4e4b \u548c\u00a0\u7d2f\u52a0\u5230\u8be5\u73a9\u5bb6\u7684\u5206\u6570\u4e2d\u3002
  4. \n\t
  5. \u5c06\u4e00\u4e2a \u65b0\u7684\u77f3\u5b50\u00a0\u653e\u5728\u6700\u5de6\u8fb9\uff0c\u4e14\u65b0\u77f3\u5b50\u7684\u503c\u4e3a\u88ab\u79fb\u9664\u77f3\u5b50\u503c\u4e4b\u548c\u3002
  6. \n
\n\n

\u5f53\u53ea\u5269\u4e0b \u4e00\u4e2a\u00a0\u77f3\u5b50\u65f6\uff0c\u6e38\u620f\u7ed3\u675f\u3002

\n\n

Alice \u548c Bob \u7684 \u5206\u6570\u4e4b\u5dee\u00a0\u4e3a\u00a0(Alice \u7684\u5206\u6570\u00a0- Bob \u7684\u5206\u6570)\u00a0\u3002\u00a0Alice \u7684\u76ee\u6807\u662f\u00a0\u6700\u5927\u5316\u00a0\u5206\u6570\u5dee\uff0cBob \u7684\u76ee\u6807\u662f \u6700\u5c0f\u5316\u00a0\u5206\u6570\u5dee\u3002

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u4e3a n\u00a0\u7684\u6574\u6570\u6570\u7ec4\u00a0stones\u00a0\uff0c\u5176\u4e2d\u00a0stones[i]\u00a0\u662f \u4ece\u5de6\u8fb9\u8d77\u00a0\u7b2c\u00a0i\u00a0\u4e2a\u77f3\u5b50\u7684\u4ef7\u503c\u3002\u8bf7\u4f60\u8fd4\u56de\u5728\u53cc\u65b9\u90fd\u91c7\u7528 \u6700\u4f18 \u7b56\u7565\u7684\u60c5\u51b5\u4e0b\uff0cAlice \u548c Bob \u7684 \u5206\u6570\u4e4b\u5dee \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1astones = [-1,2,-3,4,-5]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\n- Alice \u79fb\u9664\u6700\u5de6\u8fb9\u7684 4 \u4e2a\u77f3\u5b50\uff0c\u5f97\u5206\u589e\u52a0 (-1) + 2 + (-3) + 4 = 2 \uff0c\u5e76\u4e14\u5c06\u4e00\u4e2a\u4ef7\u503c\u4e3a 2 \u7684\u77f3\u5b50\u653e\u5728\u6700\u5de6\u8fb9\u3002stones = [2,-5] \u3002\n- Bob \u79fb\u9664\u6700\u5de6\u8fb9\u7684 2 \u4e2a\u77f3\u5b50\uff0c\u5f97\u5206\u589e\u52a0 2 + (-5) = -3 \uff0c\u5e76\u4e14\u5c06\u4e00\u4e2a\u4ef7\u503c\u4e3a -3 \u7684\u77f3\u5b50\u653e\u5728\u6700\u5de6\u8fb9\u3002stones = [-3] \u3002\n\u4e24\u8005\u5206\u6570\u4e4b\u5dee\u4e3a 2 - (-3) = 5 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1astones = [7,-6,5,10,5,-2,-6]\n\u8f93\u51fa\uff1a13\n\u89e3\u91ca\uff1a\n- Alice \u79fb\u9664\u6240\u6709\u77f3\u5b50\uff0c\u5f97\u5206\u589e\u52a0 7 + (-6) + 5 + 10 + 5 + (-2) + (-6) = 13 \uff0c\u5e76\u4e14\u5c06\u4e00\u4e2a\u4ef7\u503c\u4e3a 13 \u7684\u77f3\u5b50\u653e\u5728\u6700\u5de6\u8fb9\u3002stones = [13] \u3002\n\u4e24\u8005\u5206\u6570\u4e4b\u5dee\u4e3a 13 - 0 = 13 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1astones = [-10,-12]\n\u8f93\u51fa\uff1a-22\n\u89e3\u91ca\uff1a\n- Alice \u53ea\u6709\u4e00\u79cd\u64cd\u4f5c\uff0c\u5c31\u662f\u79fb\u9664\u6240\u6709\u77f3\u5b50\u3002\u5f97\u5206\u589e\u52a0 (-10) + (-12) = -22 \uff0c\u5e76\u4e14\u5c06\u4e00\u4e2a\u4ef7\u503c\u4e3a -22 \u7684\u77f3\u5b50\u653e\u5728\u6700\u5de6\u8fb9\u3002stones = [-22] \u3002\n\u4e24\u8005\u5206\u6570\u4e4b\u5dee\u4e3a (-22) - 0 = -22 \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • n == stones.length
  • \n\t
  • 2 <= n <= 105
  • \n\t
  • -104 <= stones[i] <= 104
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int stoneGameVIII(vector& stones) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int stoneGameVIII(int[] stones) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def stoneGameVIII(self, stones):\n \"\"\"\n :type stones: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def stoneGameVIII(self, stones: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint stoneGameVIII(int* stones, int stonesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int StoneGameVIII(int[] stones) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} stones\n * @return {number}\n */\nvar stoneGameVIII = function(stones) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} stones\n# @return {Integer}\ndef stone_game_viii(stones)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func stoneGameVIII(_ stones: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func stoneGameVIII(stones []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def stoneGameVIII(stones: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun stoneGameVIII(stones: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn stone_game_viii(stones: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $stones\n * @return Integer\n */\n function stoneGameVIII($stones) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function stoneGameVIII(stones: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (stone-game-viii stones)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1872](https://leetcode-cn.com/problems/stone-game-viii)", "[\u77f3\u5b50\u6e38\u620f VIII](/solution/1800-1899/1872.Stone%20Game%20VIII/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1872](https://leetcode.com/problems/stone-game-viii)", "[Stone Game VIII](/solution/1800-1899/1872.Stone%20Game%20VIII/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "2001", "frontend_question_id": "1871", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/jump-game-vii", "url_en": "https://leetcode.com/problems/jump-game-vii", "relative_path_cn": "/solution/1800-1899/1871.Jump%20Game%20VII/README.md", "relative_path_en": "/solution/1800-1899/1871.Jump%20Game%20VII/README_EN.md", "title_cn": "\u8df3\u8dc3\u6e38\u620f VII", "title_en": "Jump Game VII", "question_title_slug": "jump-game-vii", "content_en": "

You are given a 0-indexed binary string s and two integers minJump and maxJump. In the beginning, you are standing at index 0, which is equal to '0'. You can move from index i to index j if the following conditions are fulfilled:

\n\n
    \n\t
  • i + minJump <= j <= min(i + maxJump, s.length - 1), and
  • \n\t
  • s[j] == '0'.
  • \n
\n\n

Return true if you can reach index s.length - 1 in s, or false otherwise.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "011010", minJump = 2, maxJump = 3\nOutput: true\nExplanation:\nIn the first step, move from index 0 to index 3. \nIn the second step, move from index 3 to index 5.\n
\n\n

Example 2:

\n\n
\nInput: s = "01101110", minJump = 2, maxJump = 3\nOutput: false\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= s.length <= 105
  • \n\t
  • s[i] is either '0' or '1'.
  • \n\t
  • s[0] == '0'
  • \n\t
  • 1 <= minJump <= maxJump < s.length
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u4e0b\u6807\u4ece 0 \u5f00\u59cb\u7684\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32\u00a0s\u00a0\u548c\u4e24\u4e2a\u6574\u6570\u00a0minJump \u548c\u00a0maxJump\u00a0\u3002\u4e00\u5f00\u59cb\uff0c\u4f60\u5728\u4e0b\u6807\u00a00\u00a0\u5904\uff0c\u4e14\u8be5\u4f4d\u7f6e\u7684\u503c\u4e00\u5b9a\u4e3a\u00a0'0'\u00a0\u3002\u5f53\u540c\u65f6\u6ee1\u8db3\u5982\u4e0b\u6761\u4ef6\u65f6\uff0c\u4f60\u53ef\u4ee5\u4ece\u4e0b\u6807\u00a0i\u00a0\u79fb\u52a8\u5230\u4e0b\u6807\u00a0j\u00a0\u5904\uff1a

\n\n
    \n\t
  • i + minJump <= j <= min(i + maxJump, s.length - 1)\u00a0\u4e14
  • \n\t
  • s[j] == '0'.
  • \n
\n\n

\u5982\u679c\u4f60\u53ef\u4ee5\u5230\u8fbe s\u00a0\u7684\u4e0b\u6807\u00a0s.length - 1\u00a0\u5904\uff0c\u8bf7\u4f60\u8fd4\u56de\u00a0true\u00a0\uff0c\u5426\u5219\u8fd4\u56de\u00a0false\u00a0\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"011010\", minJump = 2, maxJump = 3\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\n\u7b2c\u4e00\u6b65\uff0c\u4ece\u4e0b\u6807 0 \u79fb\u52a8\u5230\u4e0b\u6807 3 \u3002\n\u7b2c\u4e8c\u6b65\uff0c\u4ece\u4e0b\u6807 3 \u79fb\u52a8\u5230\u4e0b\u6807 5 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"01101110\", minJump = 2, maxJump = 3\n\u8f93\u51fa\uff1afalse\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= s.length <= 105
  • \n\t
  • s[i]\u00a0\u8981\u4e48\u662f\u00a0'0'\u00a0\uff0c\u8981\u4e48\u662f\u00a0'1'
  • \n\t
  • s[0] == '0'
  • \n\t
  • 1 <= minJump <= maxJump < s.length
  • \n
\n", "tags_en": ["Greedy", "Breadth-first Search", "Line Sweep"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canReach(string s, int minJump, int maxJump) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canReach(String s, int minJump, int maxJump) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canReach(self, s, minJump, maxJump):\n \"\"\"\n :type s: str\n :type minJump: int\n :type maxJump: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canReach(self, s: str, minJump: int, maxJump: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canReach(char * s, int minJump, int maxJump){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanReach(string s, int minJump, int maxJump) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number} minJump\n * @param {number} maxJump\n * @return {boolean}\n */\nvar canReach = function(s, minJump, maxJump) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer} min_jump\n# @param {Integer} max_jump\n# @return {Boolean}\ndef can_reach(s, min_jump, max_jump)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canReach(_ s: String, _ minJump: Int, _ maxJump: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canReach(s string, minJump int, maxJump int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canReach(s: String, minJump: Int, maxJump: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canReach(s: String, minJump: Int, maxJump: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_reach(s: String, min_jump: i32, max_jump: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer $minJump\n * @param Integer $maxJump\n * @return Boolean\n */\n function canReach($s, $minJump, $maxJump) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canReach(s: string, minJump: number, maxJump: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-reach s minJump maxJump)\n (-> string? exact-integer? exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1871](https://leetcode-cn.com/problems/jump-game-vii)", "[\u8df3\u8dc3\u6e38\u620f VII](/solution/1800-1899/1871.Jump%20Game%20VII/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1871](https://leetcode.com/problems/jump-game-vii)", "[Jump Game VII](/solution/1800-1899/1871.Jump%20Game%20VII/README_EN.md)", "`Greedy`,`Breadth-first Search`,`Line Sweep`", "Medium", ""]}, {"question_id": "2000", "frontend_question_id": "1870", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-speed-to-arrive-on-time", "url_en": "https://leetcode.com/problems/minimum-speed-to-arrive-on-time", "relative_path_cn": "/solution/1800-1899/1870.Minimum%20Speed%20to%20Arrive%20on%20Time/README.md", "relative_path_en": "/solution/1800-1899/1870.Minimum%20Speed%20to%20Arrive%20on%20Time/README_EN.md", "title_cn": "\u51c6\u65f6\u5230\u8fbe\u7684\u5217\u8f66\u6700\u5c0f\u65f6\u901f", "title_en": "Minimum Speed to Arrive on Time", "question_title_slug": "minimum-speed-to-arrive-on-time", "content_en": "

You are given a floating-point number hour, representing the amount of time you have to reach the office. To commute to the office, you must take n trains in sequential order. You are also given an integer array dist of length n, where dist[i] describes the distance (in kilometers) of the ith train ride.

\n\n

Each train can only depart at an integer hour, so you may need to wait in between each train ride.

\n\n
    \n\t
  • For example, if the 1st train ride takes 1.5 hours, you must wait for an additional 0.5 hours before you can depart on the 2nd train ride at the 2 hour mark.
  • \n
\n\n

Return the minimum positive integer speed (in kilometers per hour) that all the trains must travel at for you to reach the office on time, or -1 if it is impossible to be on time.

\n\n

Tests are generated such that the answer will not exceed 107 and hour will have at most two digits after the decimal point.

\n\n

 

\n

Example 1:

\n\n
\nInput: dist = [1,3,2], hour = 6\nOutput: 1\nExplanation: At speed 1:\n- The first train ride takes 1/1 = 1 hour.\n- Since we are already at an integer hour, we depart immediately at the 1 hour mark. The second train takes 3/1 = 3 hours.\n- Since we are already at an integer hour, we depart immediately at the 4 hour mark. The third train takes 2/1 = 2 hours.\n- You will arrive at exactly the 6 hour mark.\n
\n\n

Example 2:

\n\n
\nInput: dist = [1,3,2], hour = 2.7\nOutput: 3\nExplanation: At speed 3:\n- The first train ride takes 1/3 = 0.33333 hours.\n- Since we are not at an integer hour, we wait until the 1 hour mark to depart. The second train ride takes 3/3 = 1 hour.\n- Since we are already at an integer hour, we depart immediately at the 2 hour mark. The third train takes 2/3 = 0.66667 hours.\n- You will arrive at the 2.66667 hour mark.\n
\n\n

Example 3:

\n\n
\nInput: dist = [1,3,2], hour = 1.9\nOutput: -1\nExplanation: It is impossible because the earliest the third train can depart is at the 2 hour mark.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == dist.length
  • \n\t
  • 1 <= n <= 105
  • \n\t
  • 1 <= dist[i] <= 105
  • \n\t
  • 1 <= hour <= 109
  • \n\t
  • There will be at most two digits after the decimal point in hour.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6d6e\u70b9\u6570 hour \uff0c\u8868\u793a\u4f60\u5230\u8fbe\u529e\u516c\u5ba4\u53ef\u7528\u7684\u603b\u901a\u52e4\u65f6\u95f4\u3002\u8981\u5230\u8fbe\u529e\u516c\u5ba4\uff0c\u4f60\u5fc5\u987b\u6309\u7ed9\u5b9a\u6b21\u5e8f\u4e58\u5750 n \u8d9f\u5217\u8f66\u3002\u53e6\u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u6574\u6570\u6570\u7ec4 dist \uff0c\u5176\u4e2d dist[i] \u8868\u793a\u7b2c i \u8d9f\u5217\u8f66\u7684\u884c\u9a76\u8ddd\u79bb\uff08\u5355\u4f4d\u662f\u5343\u7c73\uff09\u3002

\n\n

\u6bcf\u8d9f\u5217\u8f66\u5747\u53ea\u80fd\u5728\u6574\u70b9\u53d1\u8f66\uff0c\u6240\u4ee5\u4f60\u53ef\u80fd\u9700\u8981\u5728\u4e24\u8d9f\u5217\u8f66\u4e4b\u95f4\u7b49\u5f85\u4e00\u6bb5\u65f6\u95f4\u3002

\n\n
    \n\t
  • \u4f8b\u5982\uff0c\u7b2c 1 \u8d9f\u5217\u8f66\u9700\u8981 1.5 \u5c0f\u65f6\uff0c\u90a3\u4f60\u5fc5\u987b\u518d\u7b49\u5f85 0.5 \u5c0f\u65f6\uff0c\u642d\u4e58\u5728\u7b2c 2 \u5c0f\u65f6\u53d1\u8f66\u7684\u7b2c 2 \u8d9f\u5217\u8f66\u3002
  • \n
\n\n

\u8fd4\u56de\u80fd\u6ee1\u8db3\u4f60\u51c6\u65f6\u5230\u8fbe\u529e\u516c\u5ba4\u6240\u8981\u6c42\u5168\u90e8\u5217\u8f66\u7684 \u6700\u5c0f\u6b63\u6574\u6570 \u65f6\u901f\uff08\u5355\u4f4d\uff1a\u5343\u7c73\u6bcf\u5c0f\u65f6\uff09\uff0c\u5982\u679c\u65e0\u6cd5\u51c6\u65f6\u5230\u8fbe\uff0c\u5219\u8fd4\u56de -1 \u3002

\n\n

\u751f\u6210\u7684\u6d4b\u8bd5\u7528\u4f8b\u4fdd\u8bc1\u7b54\u6848\u4e0d\u8d85\u8fc7 107 \uff0c\u4e14 hour \u7684 \u5c0f\u6570\u70b9\u540e\u6700\u591a\u5b58\u5728\u4e24\u4f4d\u6570\u5b57 \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1adist = [1,3,2], hour = 6\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u901f\u5ea6\u4e3a 1 \u65f6\uff1a\n- \u7b2c 1 \u8d9f\u5217\u8f66\u8fd0\u884c\u9700\u8981 1/1 = 1 \u5c0f\u65f6\u3002\n- \u7531\u4e8e\u662f\u5728\u6574\u6570\u65f6\u95f4\u5230\u8fbe\uff0c\u53ef\u4ee5\u7acb\u5373\u6362\u4e58\u5728\u7b2c 1 \u5c0f\u65f6\u53d1\u8f66\u7684\u5217\u8f66\u3002\u7b2c 2 \u8d9f\u5217\u8f66\u8fd0\u884c\u9700\u8981 3/1 = 3 \u5c0f\u65f6\u3002\n- \u7531\u4e8e\u662f\u5728\u6574\u6570\u65f6\u95f4\u5230\u8fbe\uff0c\u53ef\u4ee5\u7acb\u5373\u6362\u4e58\u5728\u7b2c 4 \u5c0f\u65f6\u53d1\u8f66\u7684\u5217\u8f66\u3002\u7b2c 3 \u8d9f\u5217\u8f66\u8fd0\u884c\u9700\u8981 2/1 = 2 \u5c0f\u65f6\u3002\n- \u4f60\u5c06\u4f1a\u6070\u597d\u5728\u7b2c 6 \u5c0f\u65f6\u5230\u8fbe\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1adist = [1,3,2], hour = 2.7\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u901f\u5ea6\u4e3a 3 \u65f6\uff1a\n- \u7b2c 1 \u8d9f\u5217\u8f66\u8fd0\u884c\u9700\u8981 1/3 = 0.33333 \u5c0f\u65f6\u3002\n- \u7531\u4e8e\u4e0d\u662f\u5728\u6574\u6570\u65f6\u95f4\u5230\u8fbe\uff0c\u6545\u9700\u8981\u7b49\u5f85\u81f3\u7b2c 1 \u5c0f\u65f6\u624d\u80fd\u642d\u4e58\u5217\u8f66\u3002\u7b2c 2 \u8d9f\u5217\u8f66\u8fd0\u884c\u9700\u8981 3/3 = 1 \u5c0f\u65f6\u3002\n- \u7531\u4e8e\u662f\u5728\u6574\u6570\u65f6\u95f4\u5230\u8fbe\uff0c\u53ef\u4ee5\u7acb\u5373\u6362\u4e58\u5728\u7b2c 2 \u5c0f\u65f6\u53d1\u8f66\u7684\u5217\u8f66\u3002\u7b2c 3 \u8d9f\u5217\u8f66\u8fd0\u884c\u9700\u8981 2/3 = 0.66667 \u5c0f\u65f6\u3002\n- \u4f60\u5c06\u4f1a\u5728\u7b2c 2.66667 \u5c0f\u65f6\u5230\u8fbe\u3002
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1adist = [1,3,2], hour = 1.9\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u4e0d\u53ef\u80fd\u51c6\u65f6\u5230\u8fbe\uff0c\u56e0\u4e3a\u7b2c 3 \u8d9f\u5217\u8f66\u6700\u65e9\u662f\u5728\u7b2c 2 \u5c0f\u65f6\u53d1\u8f66\u3002
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • n == dist.length
  • \n\t
  • 1 <= n <= 105
  • \n\t
  • 1 <= dist[i] <= 105
  • \n\t
  • 1 <= hour <= 109
  • \n\t
  • hours \u4e2d\uff0c\u5c0f\u6570\u70b9\u540e\u6700\u591a\u5b58\u5728\u4e24\u4f4d\u6570\u5b57
  • \n
\n", "tags_en": ["Math", "Binary Search"], "tags_cn": ["\u6570\u5b66", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minSpeedOnTime(vector& dist, double hour) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minSpeedOnTime(int[] dist, double hour) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minSpeedOnTime(self, dist, hour):\n \"\"\"\n :type dist: List[int]\n :type hour: float\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minSpeedOnTime(self, dist: List[int], hour: float) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minSpeedOnTime(int* dist, int distSize, double hour){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinSpeedOnTime(int[] dist, double hour) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} dist\n * @param {number} hour\n * @return {number}\n */\nvar minSpeedOnTime = function(dist, hour) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} dist\n# @param {Float} hour\n# @return {Integer}\ndef min_speed_on_time(dist, hour)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minSpeedOnTime(_ dist: [Int], _ hour: Double) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minSpeedOnTime(dist []int, hour float64) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minSpeedOnTime(dist: Array[Int], hour: Double): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minSpeedOnTime(dist: IntArray, hour: Double): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_speed_on_time(dist: Vec, hour: f64) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $dist\n * @param Float $hour\n * @return Integer\n */\n function minSpeedOnTime($dist, $hour) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minSpeedOnTime(dist: number[], hour: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-speed-on-time dist hour)\n (-> (listof exact-integer?) flonum? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1870](https://leetcode-cn.com/problems/minimum-speed-to-arrive-on-time)", "[\u51c6\u65f6\u5230\u8fbe\u7684\u5217\u8f66\u6700\u5c0f\u65f6\u901f](/solution/1800-1899/1870.Minimum%20Speed%20to%20Arrive%20on%20Time/README.md)", "`\u6570\u5b66`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1870](https://leetcode.com/problems/minimum-speed-to-arrive-on-time)", "[Minimum Speed to Arrive on Time](/solution/1800-1899/1870.Minimum%20Speed%20to%20Arrive%20on%20Time/README_EN.md)", "`Math`,`Binary Search`", "Medium", ""]}, {"question_id": "1999", "frontend_question_id": "1869", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longer-contiguous-segments-of-ones-than-zeros", "url_en": "https://leetcode.com/problems/longer-contiguous-segments-of-ones-than-zeros", "relative_path_cn": "/solution/1800-1899/1869.Longer%20Contiguous%20Segments%20of%20Ones%20than%20Zeros/README.md", "relative_path_en": "/solution/1800-1899/1869.Longer%20Contiguous%20Segments%20of%20Ones%20than%20Zeros/README_EN.md", "title_cn": "\u54ea\u79cd\u8fde\u7eed\u5b50\u5b57\u7b26\u4e32\u66f4\u957f", "title_en": "Longer Contiguous Segments of Ones than Zeros", "question_title_slug": "longer-contiguous-segments-of-ones-than-zeros", "content_en": "

Given a binary string s, return true if the longest contiguous segment of 1s is strictly longer than the longest contiguous segment of 0s in s. Return false otherwise.

\n\n
    \n\t
  • For example, in s = "110100010" the longest contiguous segment of 1s has length 2, and the longest contiguous segment of 0s has length 3.
  • \n
\n\n

Note that if there are no 0s, then the longest contiguous segment of 0s is considered to have length 0. The same applies if there are no 1s.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "1101"\nOutput: true\nExplanation:\nThe longest contiguous segment of 1s has length 2: "1101"\nThe longest contiguous segment of 0s has length 1: "1101"\nThe segment of 1s is longer, so return true.\n
\n\n

Example 2:

\n\n
\nInput: s = "111000"\nOutput: false\nExplanation:\nThe longest contiguous segment of 1s has length 3: "111000"\nThe longest contiguous segment of 0s has length 3: "111000"\nThe segment of 1s is not longer, so return false.\n
\n\n

Example 3:

\n\n
\nInput: s = "110100010"\nOutput: false\nExplanation:\nThe longest contiguous segment of 1s has length 2: "110100010"\nThe longest contiguous segment of 0s has length 3: "110100010"\nThe segment of 1s is not longer, so return false.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 100
  • \n\t
  • s[i] is either '0' or '1'.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32 s \u3002\u5982\u679c\u5b57\u7b26\u4e32\u4e2d\u7531 1 \u7ec4\u6210\u7684 \u6700\u957f \u8fde\u7eed\u5b50\u5b57\u7b26\u4e32 \u4e25\u683c\u957f\u4e8e \u7531 0 \u7ec4\u6210\u7684 \u6700\u957f \u8fde\u7eed\u5b50\u5b57\u7b26\u4e32\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

\n\n
    \n\t
  • \u4f8b\u5982\uff0cs = \"110100010\" \u4e2d\uff0c\u7531 1 \u7ec4\u6210\u7684\u6700\u957f\u8fde\u7eed\u5b50\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u662f 2 \uff0c\u7531 0 \u7ec4\u6210\u7684\u6700\u957f\u8fde\u7eed\u5b50\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u662f 3 \u3002
  • \n
\n\n

\u6ce8\u610f\uff0c\u5982\u679c\u5b57\u7b26\u4e32\u4e2d\u4e0d\u5b58\u5728 0 \uff0c\u6b64\u65f6\u8ba4\u4e3a\u7531 0 \u7ec4\u6210\u7684\u6700\u957f\u8fde\u7eed\u5b50\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u662f 0 \u3002\u5b57\u7b26\u4e32\u4e2d\u4e0d\u5b58\u5728 1 \u7684\u60c5\u51b5\u4e5f\u9002\u7528\u6b64\u89c4\u5219\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"1101\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\n\u7531 1 \u7ec4\u6210\u7684\u6700\u957f\u8fde\u7eed\u5b50\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u662f 2\uff1a\"1101\"\n\u7531 0 \u7ec4\u6210\u7684\u6700\u957f\u8fde\u7eed\u5b50\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u662f 1\uff1a\"1101\"\n\u7531 1 \u7ec4\u6210\u7684\u5b50\u5b57\u7b26\u4e32\u66f4\u957f\uff0c\u6545\u8fd4\u56de true \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"111000\"\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\n\u7531 1 \u7ec4\u6210\u7684\u6700\u957f\u8fde\u7eed\u5b50\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u662f 3\uff1a\"111000\"\n\u7531 0 \u7ec4\u6210\u7684\u6700\u957f\u8fde\u7eed\u5b50\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u662f 3\uff1a\"111000\"\n\u7531 1 \u7ec4\u6210\u7684\u5b50\u5b57\u7b26\u4e32\u4e0d\u6bd4\u7531 0 \u7ec4\u6210\u7684\u5b50\u5b57\u7b26\u4e32\u957f\uff0c\u6545\u8fd4\u56de false \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"110100010\"\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\n\u7531 1 \u7ec4\u6210\u7684\u6700\u957f\u8fde\u7eed\u5b50\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u662f 2\uff1a\"110100010\"\n\u7531 0 \u7ec4\u6210\u7684\u6700\u957f\u8fde\u7eed\u5b50\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u662f 3\uff1a\"110100010\"\n\u7531 1 \u7ec4\u6210\u7684\u5b50\u5b57\u7b26\u4e32\u4e0d\u6bd4\u7531 0 \u7ec4\u6210\u7684\u5b50\u5b57\u7b26\u4e32\u957f\uff0c\u6545\u8fd4\u56de false \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length <= 100
  • \n\t
  • s[i] \u4e0d\u662f '0' \u5c31\u662f '1'
  • \n
\n", "tags_en": ["Array", "Two Pointers"], "tags_cn": ["\u6570\u7ec4", "\u53cc\u6307\u9488"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool checkZeroOnes(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean checkZeroOnes(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def checkZeroOnes(self, s):\n \"\"\"\n :type s: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def checkZeroOnes(self, s: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool checkZeroOnes(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CheckZeroOnes(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {boolean}\n */\nvar checkZeroOnes = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Boolean}\ndef check_zero_ones(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func checkZeroOnes(_ s: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func checkZeroOnes(s string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def checkZeroOnes(s: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun checkZeroOnes(s: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn check_zero_ones(s: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Boolean\n */\n function checkZeroOnes($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function checkZeroOnes(s: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (check-zero-ones s)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1869](https://leetcode-cn.com/problems/longer-contiguous-segments-of-ones-than-zeros)", "[\u54ea\u79cd\u8fde\u7eed\u5b50\u5b57\u7b26\u4e32\u66f4\u957f](/solution/1800-1899/1869.Longer%20Contiguous%20Segments%20of%20Ones%20than%20Zeros/README.md)", "`\u6570\u7ec4`,`\u53cc\u6307\u9488`", "\u7b80\u5355", ""], "md_table_row_en": ["[1869](https://leetcode.com/problems/longer-contiguous-segments-of-ones-than-zeros)", "[Longer Contiguous Segments of Ones than Zeros](/solution/1800-1899/1869.Longer%20Contiguous%20Segments%20of%20Ones%20than%20Zeros/README_EN.md)", "`Array`,`Two Pointers`", "Easy", ""]}, {"question_id": "1998", "frontend_question_id": "1843", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/suspicious-bank-accounts", "url_en": "https://leetcode.com/problems/suspicious-bank-accounts", "relative_path_cn": "/solution/1800-1899/1843.Suspicious%20Bank%20Accounts/README.md", "relative_path_en": "/solution/1800-1899/1843.Suspicious%20Bank%20Accounts/README_EN.md", "title_cn": "", "title_en": "Suspicious Bank Accounts", "question_title_slug": "suspicious-bank-accounts", "content_en": "

Table: Accounts

\r\n\r\n
\r\n+----------------+------+\r\n| Column Name    | Type |\r\n+----------------+------+\r\n| account_id     | int  |\r\n| max_income     | int  |\r\n+----------------+------+\r\naccount_id is the primary key for this table.\r\nEach row contains information about the maximum monthly income for one bank account.\r\n
\r\n\r\n

 

\r\n\r\n

Table: Transactions

\r\n\r\n
\r\n+----------------+----------+\r\n| Column Name    | Type     |\r\n+----------------+----------+\r\n| transaction_id | int      |\r\n| account_id     | int      |\r\n| type           | ENUM     |\r\n| amount         | int      |\r\n| day            | datetime |\r\n+----------------+----------+\r\ntransaction_id is the primary key for this table.\r\nEach row contains information about one transaction.\r\ntype is ENUM ('Creditor','Debtor') where 'Creditor' means the user deposited money into their account and 'Debtor' means the user withdrew money from their account.\r\namount is the amount of money depositied/withdrawn during the transaction.\r\n
\r\n\r\n

 

\r\n\r\n

Write an SQL query to report the IDs of all suspicious bank accounts.

\r\n\r\n

A bank account is suspicious if the total income exceeds the max_income for this account for two or more consecutive months. The total income of an account in some month is the sum of all its deposits in that month (i.e., transactions of the type 'Creditor').

\r\n\r\n

Return the result table in ascending order by transaction_id.

\r\n\r\n

The query result format is in the following example:

\r\n\r\n

 

\r\n\r\n
\r\nAccounts table:\r\n+------------+------------+\r\n| account_id | max_income |\r\n+------------+------------+\r\n| 3          | 21000      |\r\n| 4          | 10400      |\r\n+------------+------------+\r\n\r\nTransactions table:\r\n+----------------+------------+----------+--------+---------------------+\r\n| transaction_id | account_id | type     | amount | day                 |\r\n+----------------+------------+----------+--------+---------------------+\r\n| 2              | 3          | Creditor | 107100 | 2021-06-02 11:38:14 |\r\n| 4              | 4          | Creditor | 10400  | 2021-06-20 12:39:18 |\r\n| 11             | 4          | Debtor   | 58800  | 2021-07-23 12:41:55 |\r\n| 1              | 4          | Creditor | 49300  | 2021-05-03 16:11:04 |\r\n| 15             | 3          | Debtor   | 75500  | 2021-05-23 14:40:20 |\r\n| 10             | 3          | Creditor | 102100 | 2021-06-15 10:37:16 |\r\n| 14             | 4          | Creditor | 56300  | 2021-07-21 12:12:25 |\r\n| 19             | 4          | Debtor   | 101100 | 2021-05-09 15:21:49 |\r\n| 8              | 3          | Creditor | 64900  | 2021-07-26 15:09:56 |\r\n| 7              | 3          | Creditor | 90900  | 2021-06-14 11:23:07 |\r\n+----------------+------------+----------+--------+---------------------+\r\n\r\nResult table:\r\n+------------+\r\n| account_id |\r\n+------------+\r\n| 3          |\r\n+------------+\r\n\r\nFor account 3:\r\n- In 6-2021, the user had an income of 107100 + 102100 + 90900 = 300100.\r\n- In 7-2021, the user had an income of 64900.\r\nWe can see that the income exceeded the max income of 21000 for two consecutive months, so we include 3 in the result table.\r\n\r\nFor account 4:\r\n- In 5-2021, the user had an income of 49300.\r\n- In 6-2021, the user had an income of 10400.\r\n- In 7-2021, the user had an income of 56300.\r\nWe can see that the income exceeded the max income in May and July, but not in June. Since the account did not exceed the max income for two consecutive months, we do not include it in the result table.\r\n
", "content_cn": null, "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1843](https://leetcode-cn.com/problems/suspicious-bank-accounts)", "[Suspicious Bank Accounts](/solution/1800-1899/1843.Suspicious%20Bank%20Accounts/README_EN.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1843](https://leetcode.com/problems/suspicious-bank-accounts)", "[Suspicious Bank Accounts](/solution/1800-1899/1843.Suspicious%20Bank%20Accounts/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1997", "frontend_question_id": "1842", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/next-palindrome-using-same-digits", "url_en": "https://leetcode.com/problems/next-palindrome-using-same-digits", "relative_path_cn": "/solution/1800-1899/1842.Next%20Palindrome%20Using%20Same%20Digits/README.md", "relative_path_en": "/solution/1800-1899/1842.Next%20Palindrome%20Using%20Same%20Digits/README_EN.md", "title_cn": "", "title_en": "Next Palindrome Using Same Digits", "question_title_slug": "next-palindrome-using-same-digits", "content_en": "

You are given a numeric string num, representing a very large palindrome.

\r\n\r\n

Return the smallest palindrome larger than num that can be created by rearranging its digits. If no such palindrome exists, return an empty string "".

\r\n\r\n

A palindrome is a number that reads the same backward as forward.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: num = "1221"\r\nOutput: "2112"\r\nExplanation: The next palindrome larger than "1221" is "2112".\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: num = "32123"\r\nOutput: ""\r\nExplanation: No palindromes larger than "32123" can be made by rearranging the digits.\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: num = "45544554"\r\nOutput: "54455445"\r\nExplanation: The next palindrome larger than "45544554" is "54455445".\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= num.length <= 105
  • \r\n\t
  • num is a palindrome.
  • \r\n
", "content_cn": null, "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string nextPalindrome(string num) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String nextPalindrome(String num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def nextPalindrome(self, num):\n \"\"\"\n :type num: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def nextPalindrome(self, num: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * nextPalindrome(char * num){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string NextPalindrome(string num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} num\n * @return {string}\n */\nvar nextPalindrome = function(num) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} num\n# @return {String}\ndef next_palindrome(num)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func nextPalindrome(_ num: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func nextPalindrome(num string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def nextPalindrome(num: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun nextPalindrome(num: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn next_palindrome(num: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $num\n * @return String\n */\n function nextPalindrome($num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function nextPalindrome(num: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (next-palindrome num)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1842](https://leetcode-cn.com/problems/next-palindrome-using-same-digits)", "[Next Palindrome Using Same Digits](/solution/1800-1899/1842.Next%20Palindrome%20Using%20Same%20Digits/README_EN.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1842](https://leetcode.com/problems/next-palindrome-using-same-digits)", "[Next Palindrome Using Same Digits](/solution/1800-1899/1842.Next%20Palindrome%20Using%20Same%20Digits/README_EN.md)", "`Greedy`", "Hard", "\ud83d\udd12"]}, {"question_id": "1996", "frontend_question_id": "1866", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-ways-to-rearrange-sticks-with-k-sticks-visible", "url_en": "https://leetcode.com/problems/number-of-ways-to-rearrange-sticks-with-k-sticks-visible", "relative_path_cn": "/solution/1800-1899/1866.Number%20of%20Ways%20to%20Rearrange%20Sticks%20With%20K%20Sticks%20Visible/README.md", "relative_path_en": "/solution/1800-1899/1866.Number%20of%20Ways%20to%20Rearrange%20Sticks%20With%20K%20Sticks%20Visible/README_EN.md", "title_cn": "\u6070\u6709 K \u6839\u6728\u68cd\u53ef\u4ee5\u770b\u5230\u7684\u6392\u5217\u6570\u76ee", "title_en": "Number of Ways to Rearrange Sticks With K Sticks Visible", "question_title_slug": "number-of-ways-to-rearrange-sticks-with-k-sticks-visible", "content_en": "

There are n uniquely-sized sticks whose lengths are integers from 1 to n. You want to arrange the sticks such that exactly k sticks are visible from the left. A stick is visible from the left if there are no longer sticks to the left of it.

\n\n
    \n\t
  • For example, if the sticks are arranged [1,3,2,5,4], then the sticks with lengths 1, 3, and 5 are visible from the left.
  • \n
\n\n

Given n and k, return the number of such arrangements. Since the answer may be large, return it modulo 109 + 7.

\n\n

 

\n

Example 1:

\n\n
\nInput: n = 3, k = 2\nOutput: 3\nExplanation: [1,3,2], [2,3,1], and [2,1,3] are the only arrangements such that exactly 2 sticks are visible.\nThe visible sticks are underlined.\n
\n\n

Example 2:

\n\n
\nInput: n = 5, k = 5\nOutput: 1\nExplanation: [1,2,3,4,5] is the only arrangement such that all 5 sticks are visible.\nThe visible sticks are underlined.\n
\n\n

Example 3:

\n\n
\nInput: n = 20, k = 11\nOutput: 647427950\nExplanation: There are 647427950 (mod 109 + 7) ways to rearrange the sticks such that exactly 11 sticks are visible.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 1000
  • \n\t
  • 1 <= k <= n
  • \n
\n", "content_cn": "

\u6709 n \u6839\u957f\u5ea6\u4e92\u4e0d\u76f8\u540c\u7684\u6728\u68cd\uff0c\u957f\u5ea6\u4e3a\u4ece 1 \u5230 n \u7684\u6574\u6570\u3002\u8bf7\u4f60\u5c06\u8fd9\u4e9b\u6728\u68cd\u6392\u6210\u4e00\u6392\uff0c\u5e76\u6ee1\u8db3\u4ece\u5de6\u4fa7 \u53ef\u4ee5\u770b\u5230\u00a0\u6070\u597d k \u6839\u6728\u68cd\u3002\u4ece\u5de6\u4fa7 \u53ef\u4ee5\u770b\u5230 \u6728\u68cd\u7684\u524d\u63d0\u662f\u8fd9\u4e2a\u6728\u68cd\u7684 \u5de6\u4fa7 \u4e0d\u5b58\u5728\u6bd4\u5b83 \u66f4\u957f\u7684 \u6728\u68cd\u3002

\n\n
    \n\t
  • \u4f8b\u5982\uff0c\u5982\u679c\u6728\u68cd\u6392\u5217\u4e3a [1,3,2,5,4] \uff0c\u90a3\u4e48\u4ece\u5de6\u4fa7\u53ef\u4ee5\u770b\u5230\u7684\u5c31\u662f\u957f\u5ea6\u5206\u522b\u4e3a 1\u30013 \u30015 \u7684\u6728\u68cd\u3002
  • \n
\n\n

\u7ed9\u4f60 n \u548c k \uff0c\u8fd4\u56de\u7b26\u5408\u9898\u76ee\u8981\u6c42\u7684\u6392\u5217 \u6570\u76ee \u3002\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u5f88\u5927\uff0c\u8bf7\u8fd4\u56de\u5bf9 109 + 7 \u53d6\u4f59 \u7684\u7ed3\u679c\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1an = 3, k = 2\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a[1,3,2], [2,3,1] \u548c [2,1,3] \u662f\u4ec5\u6709\u7684\u80fd\u6ee1\u8db3\u6070\u597d 2 \u6839\u6728\u68cd\u53ef\u4ee5\u770b\u5230\u7684\u6392\u5217\u3002\n\u53ef\u4ee5\u770b\u5230\u7684\u6728\u68cd\u5df2\u7ecf\u7528\u7c97\u4f53+\u659c\u4f53\u6807\u8bc6\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1an = 5, k = 5\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a[1,2,3,4,5] \u662f\u552f\u4e00\u4e00\u79cd\u80fd\u6ee1\u8db3\u5168\u90e8 5 \u6839\u6728\u68cd\u53ef\u4ee5\u770b\u5230\u7684\u6392\u5217\u3002\n\u53ef\u4ee5\u770b\u5230\u7684\u6728\u68cd\u5df2\u7ecf\u7528\u7c97\u4f53+\u659c\u4f53\u6807\u8bc6\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1an = 20, k = 11\n\u8f93\u51fa\uff1a647427950\n\u89e3\u91ca\uff1a\u603b\u5171\u6709 647427950 (mod 109 + 7) \u79cd\u80fd\u6ee1\u8db3\u6070\u597d\u6709 11 \u6839\u6728\u68cd\u53ef\u4ee5\u770b\u5230\u7684\u6392\u5217\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 1000
  • \n\t
  • 1 <= k <= n
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int rearrangeSticks(int n, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int rearrangeSticks(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def rearrangeSticks(self, n, k):\n \"\"\"\n :type n: int\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def rearrangeSticks(self, n: int, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint rearrangeSticks(int n, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int RearrangeSticks(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} k\n * @return {number}\n */\nvar rearrangeSticks = function(n, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} k\n# @return {Integer}\ndef rearrange_sticks(n, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func rearrangeSticks(_ n: Int, _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func rearrangeSticks(n int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def rearrangeSticks(n: Int, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun rearrangeSticks(n: Int, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn rearrange_sticks(n: i32, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $k\n * @return Integer\n */\n function rearrangeSticks($n, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function rearrangeSticks(n: number, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (rearrange-sticks n k)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1866](https://leetcode-cn.com/problems/number-of-ways-to-rearrange-sticks-with-k-sticks-visible)", "[\u6070\u6709 K \u6839\u6728\u68cd\u53ef\u4ee5\u770b\u5230\u7684\u6392\u5217\u6570\u76ee](/solution/1800-1899/1866.Number%20of%20Ways%20to%20Rearrange%20Sticks%20With%20K%20Sticks%20Visible/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1866](https://leetcode.com/problems/number-of-ways-to-rearrange-sticks-with-k-sticks-visible)", "[Number of Ways to Rearrange Sticks With K Sticks Visible](/solution/1800-1899/1866.Number%20of%20Ways%20to%20Rearrange%20Sticks%20With%20K%20Sticks%20Visible/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1995", "frontend_question_id": "1865", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/finding-pairs-with-a-certain-sum", "url_en": "https://leetcode.com/problems/finding-pairs-with-a-certain-sum", "relative_path_cn": "/solution/1800-1899/1865.Finding%20Pairs%20With%20a%20Certain%20Sum/README.md", "relative_path_en": "/solution/1800-1899/1865.Finding%20Pairs%20With%20a%20Certain%20Sum/README_EN.md", "title_cn": "\u627e\u51fa\u548c\u4e3a\u6307\u5b9a\u503c\u7684\u4e0b\u6807\u5bf9", "title_en": "Finding Pairs With a Certain Sum", "question_title_slug": "finding-pairs-with-a-certain-sum", "content_en": "

You are given two integer arrays nums1 and nums2. You are tasked to implement a data structure that supports queries of two types:

\n\n
    \n\t
  1. Add a positive integer to an element of a given index in the array nums2.
  2. \n\t
  3. Count the number of pairs (i, j) such that nums1[i] + nums2[j] equals a given value (0 <= i < nums1.length and 0 <= j < nums2.length).
  4. \n
\n\n

Implement the FindSumPairs class:

\n\n
    \n\t
  • FindSumPairs(int[] nums1, int[] nums2) Initializes the FindSumPairs object with two integer arrays nums1 and nums2.
  • \n\t
  • void add(int index, int val) Adds val to nums2[index], i.e., apply nums2[index] += val.
  • \n\t
  • int count(int tot) Returns the number of pairs (i, j) such that nums1[i] + nums2[j] == tot.
  • \n
\n\n

 

\n

Example 1:

\n\n
\nInput\n["FindSumPairs", "count", "add", "count", "count", "add", "add", "count"]\n[[[1, 1, 2, 2, 2, 3], [1, 4, 5, 2, 5, 4]], [7], [3, 2], [8], [4], [0, 1], [1, 1], [7]]\nOutput\n[null, 8, null, 2, 1, null, null, 11]\n\nExplanation\nFindSumPairs findSumPairs = new FindSumPairs([1, 1, 2, 2, 2, 3], [1, 4, 5, 2, 5, 4]);\nfindSumPairs.count(7);  // return 8; pairs (2,2), (3,2), (4,2), (2,4), (3,4), (4,4) make 2 + 5 and pairs (5,1), (5,5) make 3 + 4\nfindSumPairs.add(3, 2); // now nums2 = [1,4,5,4,5,4]\nfindSumPairs.count(8);  // return 2; pairs (5,2), (5,4) make 3 + 5\nfindSumPairs.count(4);  // return 1; pair (5,0) makes 3 + 1\nfindSumPairs.add(0, 1); // now nums2 = [2,4,5,4,5,4]\nfindSumPairs.add(1, 1); // now nums2 = [2,5,5,4,5,4]\nfindSumPairs.count(7);  // return 11; pairs (2,1), (2,2), (2,4), (3,1), (3,2), (3,4), (4,1), (4,2), (4,4) make 2 + 5 and pairs (5,3), (5,5) make 3 + 4\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums1.length <= 1000
  • \n\t
  • 1 <= nums2.length <= 105
  • \n\t
  • 1 <= nums1[i] <= 109
  • \n\t
  • 1 <= nums2[i] <= 105
  • \n\t
  • 0 <= index < nums2.length
  • \n\t
  • 1 <= val <= 105
  • \n\t
  • 1 <= tot <= 109
  • \n\t
  • At most 1000 calls are made to add and count each.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e24\u4e2a\u6574\u6570\u6570\u7ec4 nums1 \u548c nums2 \uff0c\u8bf7\u4f60\u5b9e\u73b0\u4e00\u4e2a\u652f\u6301\u4e0b\u8ff0\u4e24\u7c7b\u67e5\u8be2\u7684\u6570\u636e\u7ed3\u6784\uff1a

\n\n
    \n\t
  1. \u7d2f\u52a0 \uff0c\u5c06\u4e00\u4e2a\u6b63\u6574\u6570\u52a0\u5230 nums2 \u4e2d\u6307\u5b9a\u4e0b\u6807\u5bf9\u5e94\u5143\u7d20\u4e0a\u3002
  2. \n\t
  3. \u8ba1\u6570 \uff0c\u7edf\u8ba1\u6ee1\u8db3 nums1[i] + nums2[j] \u7b49\u4e8e\u6307\u5b9a\u503c\u7684\u4e0b\u6807\u5bf9 (i, j) \u6570\u76ee\uff080 <= i < nums1.length \u4e14 0 <= j < nums2.length\uff09\u3002
  4. \n
\n\n

\u5b9e\u73b0 FindSumPairs \u7c7b\uff1a

\n\n
    \n\t
  • FindSumPairs(int[] nums1, int[] nums2) \u4f7f\u7528\u6574\u6570\u6570\u7ec4\u00a0nums1 \u548c nums2 \u521d\u59cb\u5316 FindSumPairs \u5bf9\u8c61\u3002
  • \n\t
  • void add(int index, int val) \u5c06 val \u52a0\u5230 nums2[index] \u4e0a\uff0c\u5373\uff0c\u6267\u884c nums2[index] += val \u3002
  • \n\t
  • int count(int tot) \u8fd4\u56de\u6ee1\u8db3\u00a0nums1[i] + nums2[j] == tot \u7684\u4e0b\u6807\u5bf9 (i, j) \u6570\u76ee\u3002
  • \n
\n\n

\u00a0

\n\n

\u793a\u4f8b\uff1a

\n\n
\n\u8f93\u5165\uff1a\n[\"FindSumPairs\", \"count\", \"add\", \"count\", \"count\", \"add\", \"add\", \"count\"]\n[[[1, 1, 2, 2, 2, 3], [1, 4, 5, 2, 5, 4]], [7], [3, 2], [8], [4], [0, 1], [1, 1], [7]]\n\u8f93\u51fa\uff1a\n[null, 8, null, 2, 1, null, null, 11]\n\n\u89e3\u91ca\uff1a\nFindSumPairs findSumPairs = new FindSumPairs([1, 1, 2, 2, 2, 3], [1, 4, 5, 2, 5, 4]);\nfindSumPairs.count(7);  // \u8fd4\u56de 8 ; \u4e0b\u6807\u5bf9 (2,2), (3,2), (4,2), (2,4), (3,4), (4,4) \u6ee1\u8db3 2 + 5 = 7 \uff0c\u4e0b\u6807\u5bf9 (5,1), (5,5) \u6ee1\u8db3 3 + 4 = 7\nfindSumPairs.add(3, 2); // \u6b64\u65f6 nums2 = [1,4,5,4,5,4]\nfindSumPairs.count(8);  // \u8fd4\u56de 2 \uff1b\u4e0b\u6807\u5bf9 (5,2), (5,4) \u6ee1\u8db3 3 + 5 = 8\nfindSumPairs.count(4);  // \u8fd4\u56de 1 \uff1b\u4e0b\u6807\u5bf9 (5,0) \u6ee1\u8db3 3 + 1 = 4\nfindSumPairs.add(0, 1); // \u6b64\u65f6 nums2 = [2,4,5,4,5,4]\nfindSumPairs.add(1, 1); // \u6b64\u65f6 nums2 = [2,5,5,4,5,4]\nfindSumPairs.count(7);  // \u8fd4\u56de 11 \uff1b\u4e0b\u6807\u5bf9 (2,1), (2,2), (2,4), (3,1), (3,2), (3,4), (4,1), (4,2), (4,4) \u6ee1\u8db3 2 + 5 = 7 \uff0c\u4e0b\u6807\u5bf9 (5,3), (5,5) \u6ee1\u8db3 3 + 4 = 7\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums1.length <= 1000
  • \n\t
  • 1 <= nums2.length <= 105
  • \n\t
  • 1 <= nums1[i] <= 109
  • \n\t
  • 1 <= nums2[i] <= 105
  • \n\t
  • 0 <= index < nums2.length
  • \n\t
  • 1 <= val <= 105
  • \n\t
  • 1 <= tot <= 109
  • \n\t
  • \u6700\u591a\u8c03\u7528\u00a0add \u548c count \u51fd\u6570\u5404 1000 \u6b21
  • \n
\n", "tags_en": ["Design", "Hash Table", "Ordered Map"], "tags_cn": ["\u8bbe\u8ba1", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class FindSumPairs {\npublic:\n FindSumPairs(vector& nums1, vector& nums2) {\n\n }\n \n void add(int index, int val) {\n\n }\n \n int count(int tot) {\n\n }\n};\n\n/**\n * Your FindSumPairs object will be instantiated and called as such:\n * FindSumPairs* obj = new FindSumPairs(nums1, nums2);\n * obj->add(index,val);\n * int param_2 = obj->count(tot);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class FindSumPairs {\n\n public FindSumPairs(int[] nums1, int[] nums2) {\n\n }\n \n public void add(int index, int val) {\n\n }\n \n public int count(int tot) {\n\n }\n}\n\n/**\n * Your FindSumPairs object will be instantiated and called as such:\n * FindSumPairs obj = new FindSumPairs(nums1, nums2);\n * obj.add(index,val);\n * int param_2 = obj.count(tot);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class FindSumPairs(object):\n\n def __init__(self, nums1, nums2):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n \"\"\"\n\n\n def add(self, index, val):\n \"\"\"\n :type index: int\n :type val: int\n :rtype: None\n \"\"\"\n\n\n def count(self, tot):\n \"\"\"\n :type tot: int\n :rtype: int\n \"\"\"\n\n\n\n# Your FindSumPairs object will be instantiated and called as such:\n# obj = FindSumPairs(nums1, nums2)\n# obj.add(index,val)\n# param_2 = obj.count(tot)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class FindSumPairs:\n\n def __init__(self, nums1: List[int], nums2: List[int]):\n\n\n def add(self, index: int, val: int) -> None:\n\n\n def count(self, tot: int) -> int:\n\n\n\n# Your FindSumPairs object will be instantiated and called as such:\n# obj = FindSumPairs(nums1, nums2)\n# obj.add(index,val)\n# param_2 = obj.count(tot)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} FindSumPairs;\n\n\nFindSumPairs* findSumPairsCreate(int* nums1, int nums1Size, int* nums2, int nums2Size) {\n\n}\n\nvoid findSumPairsAdd(FindSumPairs* obj, int index, int val) {\n\n}\n\nint findSumPairsCount(FindSumPairs* obj, int tot) {\n\n}\n\nvoid findSumPairsFree(FindSumPairs* obj) {\n\n}\n\n/**\n * Your FindSumPairs struct will be instantiated and called as such:\n * FindSumPairs* obj = findSumPairsCreate(nums1, nums1Size, nums2, nums2Size);\n * findSumPairsAdd(obj, index, val);\n \n * int param_2 = findSumPairsCount(obj, tot);\n \n * findSumPairsFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class FindSumPairs {\n\n public FindSumPairs(int[] nums1, int[] nums2) {\n\n }\n \n public void Add(int index, int val) {\n\n }\n \n public int Count(int tot) {\n\n }\n}\n\n/**\n * Your FindSumPairs object will be instantiated and called as such:\n * FindSumPairs obj = new FindSumPairs(nums1, nums2);\n * obj.Add(index,val);\n * int param_2 = obj.Count(tot);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums1\n * @param {number[]} nums2\n */\nvar FindSumPairs = function(nums1, nums2) {\n\n};\n\n/** \n * @param {number} index \n * @param {number} val\n * @return {void}\n */\nFindSumPairs.prototype.add = function(index, val) {\n\n};\n\n/** \n * @param {number} tot\n * @return {number}\n */\nFindSumPairs.prototype.count = function(tot) {\n\n};\n\n/**\n * Your FindSumPairs object will be instantiated and called as such:\n * var obj = new FindSumPairs(nums1, nums2)\n * obj.add(index,val)\n * var param_2 = obj.count(tot)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class FindSumPairs\n\n=begin\n :type nums1: Integer[]\n :type nums2: Integer[]\n=end\n def initialize(nums1, nums2)\n\n end\n\n\n=begin\n :type index: Integer\n :type val: Integer\n :rtype: Void\n=end\n def add(index, val)\n\n end\n\n\n=begin\n :type tot: Integer\n :rtype: Integer\n=end\n def count(tot)\n\n end\n\n\nend\n\n# Your FindSumPairs object will be instantiated and called as such:\n# obj = FindSumPairs.new(nums1, nums2)\n# obj.add(index, val)\n# param_2 = obj.count(tot)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass FindSumPairs {\n\n init(_ nums1: [Int], _ nums2: [Int]) {\n\n }\n \n func add(_ index: Int, _ val: Int) {\n\n }\n \n func count(_ tot: Int) -> Int {\n\n }\n}\n\n/**\n * Your FindSumPairs object will be instantiated and called as such:\n * let obj = FindSumPairs(nums1, nums2)\n * obj.add(index, val)\n * let ret_2: Int = obj.count(tot)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type FindSumPairs struct {\n\n}\n\n\nfunc Constructor(nums1 []int, nums2 []int) FindSumPairs {\n\n}\n\n\nfunc (this *FindSumPairs) Add(index int, val int) {\n\n}\n\n\nfunc (this *FindSumPairs) Count(tot int) int {\n\n}\n\n\n/**\n * Your FindSumPairs object will be instantiated and called as such:\n * obj := Constructor(nums1, nums2);\n * obj.Add(index,val);\n * param_2 := obj.Count(tot);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class FindSumPairs(_nums1: Array[Int], _nums2: Array[Int]) {\n\n def add(index: Int, `val`: Int) {\n \n }\n\n def count(tot: Int): Int = {\n \n }\n\n}\n\n/**\n * Your FindSumPairs object will be instantiated and called as such:\n * var obj = new FindSumPairs(nums1, nums2)\n * obj.add(index,`val`)\n * var param_2 = obj.count(tot)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class FindSumPairs(nums1: IntArray, nums2: IntArray) {\n\n fun add(index: Int, `val`: Int) {\n\n }\n\n fun count(tot: Int): Int {\n\n }\n\n}\n\n/**\n * Your FindSumPairs object will be instantiated and called as such:\n * var obj = FindSumPairs(nums1, nums2)\n * obj.add(index,`val`)\n * var param_2 = obj.count(tot)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct FindSumPairs {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl FindSumPairs {\n\n fn new(nums1: Vec, nums2: Vec) -> Self {\n\n }\n \n fn add(&self, index: i32, val: i32) {\n\n }\n \n fn count(&self, tot: i32) -> i32 {\n\n }\n}\n\n/**\n * Your FindSumPairs object will be instantiated and called as such:\n * let obj = FindSumPairs::new(nums1, nums2);\n * obj.add(index, val);\n * let ret_2: i32 = obj.count(tot);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class FindSumPairs {\n /**\n * @param Integer[] $nums1\n * @param Integer[] $nums2\n */\n function __construct($nums1, $nums2) {\n\n }\n\n /**\n * @param Integer $index\n * @param Integer $val\n * @return NULL\n */\n function add($index, $val) {\n\n }\n\n /**\n * @param Integer $tot\n * @return Integer\n */\n function count($tot) {\n\n }\n}\n\n/**\n * Your FindSumPairs object will be instantiated and called as such:\n * $obj = FindSumPairs($nums1, $nums2);\n * $obj->add($index, $val);\n * $ret_2 = $obj->count($tot);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class FindSumPairs {\n constructor(nums1: number[], nums2: number[]) {\n\n }\n\n add(index: number, val: number): void {\n\n }\n\n count(tot: number): number {\n\n }\n}\n\n/**\n * Your FindSumPairs object will be instantiated and called as such:\n * var obj = new FindSumPairs(nums1, nums2)\n * obj.add(index,val)\n * var param_2 = obj.count(tot)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define find-sum-pairs%\n (class object%\n (super-new)\n\n ; nums1 : (listof exact-integer?)\n\n ; nums2 : (listof exact-integer?)\n (init-field\n nums1\n nums2)\n \n ; add : exact-integer? exact-integer? -> void?\n (define/public (add index val)\n\n )\n ; count : exact-integer? -> exact-integer?\n (define/public (count tot)\n\n )))\n\n;; Your find-sum-pairs% object will be instantiated and called as such:\n;; (define obj (new find-sum-pairs% [nums1 nums1] [nums2 nums2]))\n;; (send obj add index val)\n;; (define param_2 (send obj count tot))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1865](https://leetcode-cn.com/problems/finding-pairs-with-a-certain-sum)", "[\u627e\u51fa\u548c\u4e3a\u6307\u5b9a\u503c\u7684\u4e0b\u6807\u5bf9](/solution/1800-1899/1865.Finding%20Pairs%20With%20a%20Certain%20Sum/README.md)", "`\u8bbe\u8ba1`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1865](https://leetcode.com/problems/finding-pairs-with-a-certain-sum)", "[Finding Pairs With a Certain Sum](/solution/1800-1899/1865.Finding%20Pairs%20With%20a%20Certain%20Sum/README_EN.md)", "`Design`,`Hash Table`,`Ordered Map`", "Medium", ""]}, {"question_id": "1994", "frontend_question_id": "1864", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-number-of-swaps-to-make-the-binary-string-alternating", "url_en": "https://leetcode.com/problems/minimum-number-of-swaps-to-make-the-binary-string-alternating", "relative_path_cn": "/solution/1800-1899/1864.Minimum%20Number%20of%20Swaps%20to%20Make%20the%20Binary%20String%20Alternating/README.md", "relative_path_en": "/solution/1800-1899/1864.Minimum%20Number%20of%20Swaps%20to%20Make%20the%20Binary%20String%20Alternating/README_EN.md", "title_cn": "\u6784\u6210\u4ea4\u66ff\u5b57\u7b26\u4e32\u9700\u8981\u7684\u6700\u5c0f\u4ea4\u6362\u6b21\u6570", "title_en": "Minimum Number of Swaps to Make the Binary String Alternating", "question_title_slug": "minimum-number-of-swaps-to-make-the-binary-string-alternating", "content_en": "

Given a binary string s, return the minimum number of character swaps to make it alternating, or -1 if it is impossible.

\n\n

The string is called alternating if no two adjacent characters are equal. For example, the strings "010" and "1010" are alternating, while the string "0100" is not.

\n\n

Any two characters may be swapped, even if they are not adjacent.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "111000"\nOutput: 1\nExplanation: Swap positions 1 and 4: "111000" -> "101010"\nThe string is now alternating.\n
\n\n

Example 2:

\n\n
\nInput: s = "010"\nOutput: 0\nExplanation: The string is already alternating, no swaps are needed.\n
\n\n

Example 3:

\n\n
\nInput: s = "1110"\nOutput: -1\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 1000
  • \n\t
  • s[i] is either '0' or '1'.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32 s \uff0c\u73b0\u9700\u8981\u5c06\u5176\u8f6c\u5316\u4e3a\u4e00\u4e2a \u4ea4\u66ff\u5b57\u7b26\u4e32 \u3002\u8bf7\u4f60\u8ba1\u7b97\u5e76\u8fd4\u56de\u8f6c\u5316\u6240\u9700\u7684 \u6700\u5c0f \u5b57\u7b26\u4ea4\u6362\u6b21\u6570\uff0c\u5982\u679c\u65e0\u6cd5\u5b8c\u6210\u8f6c\u5316\uff0c\u8fd4\u56de -1 \u3002

\n\n

\u4ea4\u66ff\u5b57\u7b26\u4e32 \u662f\u6307\uff1a\u76f8\u90bb\u5b57\u7b26\u4e4b\u95f4\u4e0d\u5b58\u5728\u76f8\u7b49\u60c5\u51b5\u7684\u5b57\u7b26\u4e32\u3002\u4f8b\u5982\uff0c\u5b57\u7b26\u4e32 \"010\" \u548c \"1010\" \u5c5e\u4e8e\u4ea4\u66ff\u5b57\u7b26\u4e32\uff0c\u4f46 \"0100\" \u4e0d\u662f\u3002

\n\n

\u4efb\u610f\u4e24\u4e2a\u5b57\u7b26\u90fd\u53ef\u4ee5\u8fdb\u884c\u4ea4\u6362\uff0c\u4e0d\u5fc5\u76f8\u90bb \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"111000\"\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u4ea4\u6362\u4f4d\u7f6e 1 \u548c 4\uff1a\"111000\" -> \"101010\" \uff0c\u5b57\u7b26\u4e32\u53d8\u4e3a\u4ea4\u66ff\u5b57\u7b26\u4e32\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"010\"\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u5b57\u7b26\u4e32\u5df2\u7ecf\u662f\u4ea4\u66ff\u5b57\u7b26\u4e32\u4e86\uff0c\u4e0d\u9700\u8981\u4ea4\u6362\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"1110\"\n\u8f93\u51fa\uff1a-1\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length <= 1000
  • \n\t
  • s[i] \u7684\u503c\u4e3a '0' \u6216 '1'
  • \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minSwaps(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minSwaps(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minSwaps(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minSwaps(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minSwaps(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinSwaps(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar minSwaps = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef min_swaps(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minSwaps(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minSwaps(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minSwaps(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minSwaps(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_swaps(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function minSwaps($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minSwaps(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-swaps s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1864](https://leetcode-cn.com/problems/minimum-number-of-swaps-to-make-the-binary-string-alternating)", "[\u6784\u6210\u4ea4\u66ff\u5b57\u7b26\u4e32\u9700\u8981\u7684\u6700\u5c0f\u4ea4\u6362\u6b21\u6570](/solution/1800-1899/1864.Minimum%20Number%20of%20Swaps%20to%20Make%20the%20Binary%20String%20Alternating/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1864](https://leetcode.com/problems/minimum-number-of-swaps-to-make-the-binary-string-alternating)", "[Minimum Number of Swaps to Make the Binary String Alternating](/solution/1800-1899/1864.Minimum%20Number%20of%20Swaps%20to%20Make%20the%20Binary%20String%20Alternating/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1993", "frontend_question_id": "1863", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sum-of-all-subset-xor-totals", "url_en": "https://leetcode.com/problems/sum-of-all-subset-xor-totals", "relative_path_cn": "/solution/1800-1899/1863.Sum%20of%20All%20Subset%20XOR%20Totals/README.md", "relative_path_en": "/solution/1800-1899/1863.Sum%20of%20All%20Subset%20XOR%20Totals/README_EN.md", "title_cn": "\u627e\u51fa\u6240\u6709\u5b50\u96c6\u7684\u5f02\u6216\u603b\u548c\u518d\u6c42\u548c", "title_en": "Sum of All Subset XOR Totals", "question_title_slug": "sum-of-all-subset-xor-totals", "content_en": "

The XOR total of an array is defined as the bitwise XOR of all its elements, or 0 if the array is empty.

\n\n
    \n\t
  • For example, the XOR total of the array [2,5,6] is 2 XOR 5 XOR 6 = 1.
  • \n
\n\n

Given an array nums, return the sum of all XOR totals for every subset of nums

\n\n

Note: Subsets with the same elements should be counted multiple times.

\n\n

An array a is a subset of an array b if a can be obtained from b by deleting some (possibly zero) elements of b.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [1,3]\nOutput: 6\nExplanation: The 4 subsets of [1,3] are:\n- The empty subset has an XOR total of 0.\n- [1] has an XOR total of 1.\n- [3] has an XOR total of 3.\n- [1,3] has an XOR total of 1 XOR 3 = 2.\n0 + 1 + 3 + 2 = 6\n
\n\n

Example 2:

\n\n
\nInput: nums = [5,1,6]\nOutput: 28\nExplanation: The 8 subsets of [5,1,6] are:\n- The empty subset has an XOR total of 0.\n- [5] has an XOR total of 5.\n- [1] has an XOR total of 1.\n- [6] has an XOR total of 6.\n- [5,1] has an XOR total of 5 XOR 1 = 4.\n- [5,6] has an XOR total of 5 XOR 6 = 3.\n- [1,6] has an XOR total of 1 XOR 6 = 7.\n- [5,1,6] has an XOR total of 5 XOR 1 XOR 6 = 2.\n0 + 5 + 1 + 6 + 4 + 3 + 7 + 2 = 28\n
\n\n

Example 3:

\n\n
\nInput: nums = [3,4,5,6,7,8]\nOutput: 480\nExplanation: The sum of all XOR totals for every subset is 480.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 12
  • \n\t
  • 1 <= nums[i] <= 20
  • \n
\n", "content_cn": "

\u4e00\u4e2a\u6570\u7ec4\u7684 \u5f02\u6216\u603b\u548c \u5b9a\u4e49\u4e3a\u6570\u7ec4\u4e2d\u6240\u6709\u5143\u7d20\u6309\u4f4d XOR \u7684\u7ed3\u679c\uff1b\u5982\u679c\u6570\u7ec4\u4e3a \u7a7a \uff0c\u5219\u5f02\u6216\u603b\u548c\u4e3a 0 \u3002

\n\n
    \n\t
  • \u4f8b\u5982\uff0c\u6570\u7ec4\u00a0[2,5,6] \u7684 \u5f02\u6216\u603b\u548c \u4e3a 2 XOR 5 XOR 6 = 1 \u3002
  • \n
\n\n

\u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 nums \uff0c\u8bf7\u4f60\u6c42\u51fa nums \u4e2d\u6bcf\u4e2a \u5b50\u96c6 \u7684 \u5f02\u6216\u603b\u548c \uff0c\u8ba1\u7b97\u5e76\u8fd4\u56de\u8fd9\u4e9b\u503c\u76f8\u52a0\u4e4b \u548c \u3002

\n\n

\u6ce8\u610f\uff1a\u5728\u672c\u9898\u4e2d\uff0c\u5143\u7d20 \u76f8\u540c \u7684\u4e0d\u540c\u5b50\u96c6\u5e94 \u591a\u6b21 \u8ba1\u6570\u3002

\n\n

\u6570\u7ec4 a \u662f\u6570\u7ec4 b \u7684\u4e00\u4e2a \u5b50\u96c6 \u7684\u524d\u63d0\u6761\u4ef6\u662f\uff1a\u4ece b \u5220\u9664\u51e0\u4e2a\uff08\u4e5f\u53ef\u80fd\u4e0d\u5220\u9664\uff09\u5143\u7d20\u80fd\u591f\u5f97\u5230 a \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,3]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a[1,3] \u5171\u6709 4 \u4e2a\u5b50\u96c6\uff1a\n- \u7a7a\u5b50\u96c6\u7684\u5f02\u6216\u603b\u548c\u662f 0 \u3002\n- [1] \u7684\u5f02\u6216\u603b\u548c\u4e3a 1 \u3002\n- [3] \u7684\u5f02\u6216\u603b\u548c\u4e3a 3 \u3002\n- [1,3] \u7684\u5f02\u6216\u603b\u548c\u4e3a 1 XOR 3 = 2 \u3002\n0 + 1 + 3 + 2 = 6\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anums = [5,1,6]\n\u8f93\u51fa\uff1a28\n\u89e3\u91ca\uff1a[5,1,6] \u5171\u6709 8 \u4e2a\u5b50\u96c6\uff1a\n- \u7a7a\u5b50\u96c6\u7684\u5f02\u6216\u603b\u548c\u662f 0 \u3002\n- [5] \u7684\u5f02\u6216\u603b\u548c\u4e3a 5 \u3002\n- [1] \u7684\u5f02\u6216\u603b\u548c\u4e3a 1 \u3002\n- [6] \u7684\u5f02\u6216\u603b\u548c\u4e3a 6 \u3002\n- [5,1] \u7684\u5f02\u6216\u603b\u548c\u4e3a 5 XOR 1 = 4 \u3002\n- [5,6] \u7684\u5f02\u6216\u603b\u548c\u4e3a 5 XOR 6 = 3 \u3002\n- [1,6] \u7684\u5f02\u6216\u603b\u548c\u4e3a 1 XOR 6 = 7 \u3002\n- [5,1,6] \u7684\u5f02\u6216\u603b\u548c\u4e3a 5 XOR 1 XOR 6 = 2 \u3002\n0 + 5 + 1 + 6 + 4 + 3 + 7 + 2 = 28\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1anums = [3,4,5,6,7,8]\n\u8f93\u51fa\uff1a480\n\u89e3\u91ca\uff1a\u6bcf\u4e2a\u5b50\u96c6\u7684\u5168\u90e8\u5f02\u6216\u603b\u548c\u503c\u4e4b\u548c\u4e3a 480 \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 12
  • \n\t
  • 1 <= nums[i] <= 20
  • \n
\n", "tags_en": ["Recursion", "Backtracking"], "tags_cn": ["\u9012\u5f52", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int subsetXORSum(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int subsetXORSum(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def subsetXORSum(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def subsetXORSum(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint subsetXORSum(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SubsetXORSum(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar subsetXORSum = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef subset_xor_sum(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func subsetXORSum(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func subsetXORSum(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def subsetXORSum(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun subsetXORSum(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn subset_xor_sum(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function subsetXORSum($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function subsetXORSum(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (subset-xor-sum nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1863](https://leetcode-cn.com/problems/sum-of-all-subset-xor-totals)", "[\u627e\u51fa\u6240\u6709\u5b50\u96c6\u7684\u5f02\u6216\u603b\u548c\u518d\u6c42\u548c](/solution/1800-1899/1863.Sum%20of%20All%20Subset%20XOR%20Totals/README.md)", "`\u9012\u5f52`,`\u56de\u6eaf\u7b97\u6cd5`", "\u7b80\u5355", ""], "md_table_row_en": ["[1863](https://leetcode.com/problems/sum-of-all-subset-xor-totals)", "[Sum of All Subset XOR Totals](/solution/1800-1899/1863.Sum%20of%20All%20Subset%20XOR%20Totals/README_EN.md)", "`Recursion`,`Backtracking`", "Easy", ""]}, {"question_id": "1991", "frontend_question_id": "1841", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/league-statistics", "url_en": "https://leetcode.com/problems/league-statistics", "relative_path_cn": "/solution/1800-1899/1841.League%20Statistics/README.md", "relative_path_en": "/solution/1800-1899/1841.League%20Statistics/README_EN.md", "title_cn": "", "title_en": "League Statistics", "question_title_slug": "league-statistics", "content_en": "

Table: Teams

\r\n\r\n
\r\n+----------------+---------+\r\n| Column Name    | Type    |\r\n+----------------+---------+\r\n| team_id        | int     |\r\n| team_name      | varchar |\r\n+----------------+---------+\r\nteam_id is the primary key for this table.\r\nEach row contains information about one team in the league.\r\n
\r\n\r\n

 

\r\n\r\n

Table: Matches

\r\n\r\n
\r\n+-----------------+---------+\r\n| Column Name     | Type    |\r\n+-----------------+---------+\r\n| home_team_id    | int     |\r\n| away_team_id    | int     |\r\n| home_team_goals | int     |\r\n| away_team_goals | int     |\r\n+-----------------+---------+\r\n(home_team_id, away_team_id) is the primary key for this table.\r\nEach row contains information about one match.\r\nhome_team_goals is the number of goals scored by the home team.\r\naway_team_goals is the number of goals scored by the away team.\r\nThe winner of the match is the team with the higher number of goals.\r\n
\r\n\r\n

 

\r\n\r\n

Write an SQL query to report the statistics of the league. The statistics should be built using the played matches where the winning team gets three points and the losing team gets no points. If a match ends with a draw, both teams get one point.

\r\n\r\n

Each row of the result table should contain:

\r\n\r\n
    \r\n\t
  • team_name - The name of the team in the Teams table.
  • \r\n\t
  • matches_played - The number of matches played as either a home or away team.
  • \r\n\t
  • points - The total points the team has so far.
  • \r\n\t
  • goal_for - The total number of goals scored by the team across all matches.
  • \r\n\t
  • goal_against - The total number of goals scored by opponent teams against this team across all matches.
  • \r\n\t
  • goal_diff - The result of goal_for - goal_against.
  • \r\n
\r\n\r\n

Return the result table in descending order by points. If two or more teams have the same points, order them in descending order by goal_diff. If there is still a tie, order them by team_name in lexicographical order.

\r\n\r\n

The query result format is in the following example:

\r\n\r\n

 

\r\n\r\n
\r\nTeams table:\r\n+---------+-----------+\r\n| team_id | team_name |\r\n+---------+-----------+\r\n| 1       | Ajax      |\r\n| 4       | Dortmund  |\r\n| 6       | Arsenal   |\r\n+---------+-----------+\r\n\r\nMatches table:\r\n+--------------+--------------+-----------------+-----------------+\r\n| home_team_id | away_team_id | home_team_goals | away_team_goals |\r\n+--------------+--------------+-----------------+-----------------+\r\n| 1            | 4            | 0               | 1               |\r\n| 1            | 6            | 3               | 3               |\r\n| 4            | 1            | 5               | 2               |\r\n| 6            | 1            | 0               | 0               |\r\n+--------------+--------------+-----------------+-----------------+\r\n\r\n\r\nResult table:\r\n+-----------+----------------+--------+----------+--------------+-----------+\r\n| team_name | matches_played | points | goal_for | goal_against | goal_diff |\r\n+-----------+----------------+--------+----------+--------------+-----------+\r\n| Dortmund  | 2              | 6      | 6        | 2            | 4         |\r\n| Arsenal   | 2              | 2      | 3        | 3            | 0         |\r\n| Ajax      | 4              | 2      | 5        | 9            | -4        |\r\n+-----------+----------------+--------+----------+--------------+-----------+\r\n\r\nAjax (team_id=1) played 4 matches: 2 losses and 2 draws. Total points = 0 + 0 + 1 + 1 = 2.\r\nDortmund (team_id=4) played 2 matches: 2 wins. Total points = 3 + 3 = 6.\r\nArsenal (team_id=6) played 2 matches: 2 draws. Total points = 1 + 1 = 2.\r\nDortmund is the first team in the table. Ajax and Arsenal have the same points, but since Arsenal has a higher goal_diff than Ajax, Arsenal comes before Ajax in the table.\r\n
", "content_cn": null, "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1841](https://leetcode-cn.com/problems/league-statistics)", "[League Statistics](/solution/1800-1899/1841.League%20Statistics/README_EN.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1841](https://leetcode.com/problems/league-statistics)", "[League Statistics](/solution/1800-1899/1841.League%20Statistics/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1990", "frontend_question_id": "1878", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/get-biggest-three-rhombus-sums-in-a-grid", "url_en": "https://leetcode.com/problems/get-biggest-three-rhombus-sums-in-a-grid", "relative_path_cn": "/solution/1800-1899/1878.Get%20Biggest%20Three%20Rhombus%20Sums%20in%20a%20Grid/README.md", "relative_path_en": "/solution/1800-1899/1878.Get%20Biggest%20Three%20Rhombus%20Sums%20in%20a%20Grid/README_EN.md", "title_cn": "\u77e9\u9635\u4e2d\u6700\u5927\u7684\u4e09\u4e2a\u83f1\u5f62\u548c", "title_en": "Get Biggest Three Rhombus Sums in a Grid", "question_title_slug": "get-biggest-three-rhombus-sums-in-a-grid", "content_en": "

You are given an m x n integer matrix grid\u200b\u200b\u200b.

\n\n

A rhombus sum is the sum of the elements that form the border of a regular rhombus shape in grid\u200b\u200b\u200b. The rhombus must have the shape of a square rotated 45 degrees with each of the corners centered in a grid cell. Below is an image of four valid rhombus shapes with the corresponding colored cells that should be included in each rhombus sum:

\n\"\"\n

Note that the rhombus can have an area of 0, which is depicted by the purple rhombus in the bottom right corner.

\n\n

Return the biggest three distinct rhombus sums in the grid in descending order. If there are less than three distinct values, return all of them.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: grid = [[3,4,5,1,3],[3,3,4,2,3],[20,30,200,40,10],[1,5,5,4,1],[4,3,2,2,5]]\nOutput: [228,216,211]\nExplanation: The rhombus shapes for the three biggest distinct rhombus sums are depicted above.\n- Blue: 20 + 3 + 200 + 5 = 228\n- Red: 200 + 2 + 10 + 4 = 216\n- Green: 5 + 200 + 4 + 2 = 211\n
\n\n

Example 2:

\n\"\"\n
\nInput: grid = [[1,2,3],[4,5,6],[7,8,9]]\nOutput: [20,9,8]\nExplanation: The rhombus shapes for the three biggest distinct rhombus sums are depicted above.\n- Blue: 4 + 2 + 6 + 8 = 20\n- Red: 9 (area 0 rhombus in the bottom right corner)\n- Green: 8 (area 0 rhombus in the bottom middle)\n
\n\n

Example 3:

\n\n
\nInput: grid = [[7,7,7]]\nOutput: [7]\nExplanation: All three possible rhombus sums are the same, so return [7].\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • m == grid.length
  • \n\t
  • n == grid[i].length
  • \n\t
  • 1 <= m, n <= 50
  • \n\t
  • 1 <= grid[i][j] <= 105
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u00a0m x n\u00a0\u7684\u6574\u6570\u77e9\u9635\u00a0grid\u00a0\u3002

\n\n

\u83f1\u5f62\u548c \u6307\u7684\u662f grid\u00a0\u4e2d\u4e00\u4e2a\u6b63\u83f1\u5f62 \u8fb9\u754c\u00a0\u4e0a\u7684\u5143\u7d20\u4e4b\u548c\u3002\u672c\u9898\u4e2d\u7684\u83f1\u5f62\u5fc5\u987b\u4e3a\u6b63\u65b9\u5f62\u65cb\u8f6c45\u5ea6\uff0c\u4e14\u56db\u4e2a\u89d2\u90fd\u5728\u4e00\u4e2a\u683c\u5b50\u5f53\u4e2d\u3002\u4e0b\u56fe\u662f\u56db\u4e2a\u53ef\u884c\u7684\u83f1\u5f62\uff0c\u6bcf\u4e2a\u83f1\u5f62\u548c\u5e94\u8be5\u5305\u542b\u7684\u683c\u5b50\u90fd\u7528\u4e86\u76f8\u5e94\u989c\u8272\u6807\u6ce8\u5728\u56fe\u4e2d\u3002

\n\"\"\n

\u00a0

\n\n

\u6ce8\u610f\uff0c\u83f1\u5f62\u53ef\u4ee5\u662f\u4e00\u4e2a\u9762\u79ef\u4e3a 0 \u7684\u533a\u57df\uff0c\u5982\u4e0a\u56fe\u4e2d\u53f3\u4e0b\u89d2\u7684\u7d2b\u8272\u83f1\u5f62\u6240\u793a\u3002

\n\n

\u8bf7\u4f60\u6309\u7167 \u964d\u5e8f\u00a0\u8fd4\u56de grid\u00a0\u4e2d\u4e09\u4e2a\u6700\u5927\u7684\u00a0\u4e92\u4e0d\u76f8\u540c\u7684\u83f1\u5f62\u548c\u00a0\u3002\u5982\u679c\u4e0d\u540c\u7684\u548c\u5c11\u4e8e\u4e09\u4e2a\uff0c\u5219\u5c06\u5b83\u4eec\u5168\u90e8\u8fd4\u56de\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1agrid = [[3,4,5,1,3],[3,3,4,2,3],[20,30,200,40,10],[1,5,5,4,1],[4,3,2,2,5]]\n\u8f93\u51fa\uff1a[228,216,211]\n\u89e3\u91ca\uff1a\u6700\u5927\u7684\u4e09\u4e2a\u83f1\u5f62\u548c\u5982\u4e0a\u56fe\u6240\u793a\u3002\n- \u84dd\u8272\uff1a20 + 3 + 200 + 5 = 228\n- \u7ea2\u8272\uff1a200 + 2 + 10 + 4 = 216\n- \u7eff\u8272\uff1a5 + 200 + 4 + 2 = 211\n
\n\n

\u793a\u4f8b 2\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1agrid = [[1,2,3],[4,5,6],[7,8,9]]\n\u8f93\u51fa\uff1a[20,9,8]\n\u89e3\u91ca\uff1a\u6700\u5927\u7684\u4e09\u4e2a\u83f1\u5f62\u548c\u5982\u4e0a\u56fe\u6240\u793a\u3002\n- \u84dd\u8272\uff1a4 + 2 + 6 + 8 = 20\n- \u7ea2\u8272\uff1a9 \uff08\u53f3\u4e0b\u89d2\u7ea2\u8272\u7684\u9762\u79ef\u4e3a 0 \u7684\u83f1\u5f62\uff09\n- \u7eff\u8272\uff1a8 \uff08\u4e0b\u65b9\u4e2d\u592e\u9762\u79ef\u4e3a 0 \u7684\u83f1\u5f62\uff09\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1agrid = [[7,7,7]]\n\u8f93\u51fa\uff1a[7]\n\u89e3\u91ca\uff1a\u6240\u6709\u4e09\u4e2a\u53ef\u80fd\u7684\u83f1\u5f62\u548c\u90fd\u76f8\u540c\uff0c\u6240\u4ee5\u8fd4\u56de [7] \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • m == grid.length
  • \n\t
  • n == grid[i].length
  • \n\t
  • 1 <= m, n <= 100
  • \n\t
  • 1 <= grid[i][j] <= 105
  • \n
\n", "tags_en": ["Array", "Math"], "tags_cn": ["\u6570\u7ec4", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector getBiggestThree(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] getBiggestThree(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getBiggestThree(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getBiggestThree(self, grid: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* getBiggestThree(int** grid, int gridSize, int* gridColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] GetBiggestThree(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number[]}\n */\nvar getBiggestThree = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer[]}\ndef get_biggest_three(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getBiggestThree(_ grid: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getBiggestThree(grid [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getBiggestThree(grid: Array[Array[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getBiggestThree(grid: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_biggest_three(grid: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer[]\n */\n function getBiggestThree($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getBiggestThree(grid: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-biggest-three grid)\n (-> (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1878](https://leetcode-cn.com/problems/get-biggest-three-rhombus-sums-in-a-grid)", "[\u77e9\u9635\u4e2d\u6700\u5927\u7684\u4e09\u4e2a\u83f1\u5f62\u548c](/solution/1800-1899/1878.Get%20Biggest%20Three%20Rhombus%20Sums%20in%20a%20Grid/README.md)", "`\u6570\u7ec4`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1878](https://leetcode.com/problems/get-biggest-three-rhombus-sums-in-a-grid)", "[Get Biggest Three Rhombus Sums in a Grid](/solution/1800-1899/1878.Get%20Biggest%20Three%20Rhombus%20Sums%20in%20a%20Grid/README_EN.md)", "`Array`,`Math`", "Medium", ""]}, {"question_id": "1989", "frontend_question_id": "1879", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-xor-sum-of-two-arrays", "url_en": "https://leetcode.com/problems/minimum-xor-sum-of-two-arrays", "relative_path_cn": "/solution/1800-1899/1879.Minimum%20XOR%20Sum%20of%20Two%20Arrays/README.md", "relative_path_en": "/solution/1800-1899/1879.Minimum%20XOR%20Sum%20of%20Two%20Arrays/README_EN.md", "title_cn": "\u4e24\u4e2a\u6570\u7ec4\u6700\u5c0f\u7684\u5f02\u6216\u503c\u4e4b\u548c", "title_en": "Minimum XOR Sum of Two Arrays", "question_title_slug": "minimum-xor-sum-of-two-arrays", "content_en": "

You are given two integer arrays nums1 and nums2 of length n.

\n\n

The XOR sum of the two integer arrays is (nums1[0] XOR nums2[0]) + (nums1[1] XOR nums2[1]) + ... + (nums1[n - 1] XOR nums2[n - 1]) (0-indexed).

\n\n
    \n\t
  • For example, the XOR sum of [1,2,3] and [3,2,1] is equal to (1 XOR 3) + (2 XOR 2) + (3 XOR 1) = 2 + 0 + 2 = 4.
  • \n
\n\n

Rearrange the elements of nums2 such that the resulting XOR sum is minimized.

\n\n

Return the XOR sum after the rearrangement.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums1 = [1,2], nums2 = [2,3]\nOutput: 2\nExplanation: Rearrange nums2 so that it becomes [3,2].\nThe XOR sum is (1 XOR 3) + (2 XOR 2) = 2 + 0 = 2.
\n\n

Example 2:

\n\n
\nInput: nums1 = [1,0,3], nums2 = [5,3,4]\nOutput: 8\nExplanation: Rearrange nums2 so that it becomes [5,4,3]. \nThe XOR sum is (1 XOR 5) + (0 XOR 4) + (3 XOR 3) = 4 + 4 + 0 = 8.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == nums1.length
  • \n\t
  • n == nums2.length
  • \n\t
  • 1 <= n <= 14
  • \n\t
  • 0 <= nums1[i], nums2[i] <= 107
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e24\u4e2a\u6574\u6570\u6570\u7ec4\u00a0nums1 \u548c\u00a0nums2\u00a0\uff0c\u5b83\u4eec\u957f\u5ea6\u90fd\u4e3a\u00a0n\u00a0\u3002

\n\n

\u4e24\u4e2a\u6570\u7ec4\u7684 \u5f02\u6216\u503c\u4e4b\u548c\u00a0\u4e3a\u00a0(nums1[0] XOR nums2[0]) + (nums1[1] XOR nums2[1]) + ... + (nums1[n - 1] XOR nums2[n - 1])\u00a0\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\u3002

\n\n
    \n\t
  • \u6bd4\u65b9\u8bf4\uff0c[1,2,3] \u548c\u00a0[3,2,1]\u00a0\u7684 \u5f02\u6216\u503c\u4e4b\u548c\u00a0\u7b49\u4e8e\u00a0(1 XOR 3) + (2 XOR 2) + (3 XOR 1) = 2 + 0 + 2 = 4\u00a0\u3002
  • \n
\n\n

\u8bf7\u4f60\u5c06\u00a0nums2\u00a0\u4e2d\u7684\u5143\u7d20\u91cd\u65b0\u6392\u5217\uff0c\u4f7f\u5f97 \u5f02\u6216\u503c\u4e4b\u548c\u00a0\u6700\u5c0f\u00a0\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u91cd\u65b0\u6392\u5217\u4e4b\u540e\u7684 \u5f02\u6216\u503c\u4e4b\u548c\u00a0\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anums1 = [1,2], nums2 = [2,3]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5c06 nums2 \u91cd\u65b0\u6392\u5217\u5f97\u5230 [3,2] \u3002\n\u5f02\u6216\u503c\u4e4b\u548c\u4e3a (1 XOR 3) + (2 XOR 2) = 2 + 0 = 2 \u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anums1 = [1,0,3], nums2 = [5,3,4]\n\u8f93\u51fa\uff1a8\n\u89e3\u91ca\uff1a\u5c06 nums2 \u91cd\u65b0\u6392\u5217\u5f97\u5230 [5,4,3] \u3002\n\u5f02\u6216\u503c\u4e4b\u548c\u4e3a (1 XOR 5) + (0 XOR 4) + (3 XOR 3) = 4 + 4 + 0 = 8 \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • n == nums1.length
  • \n\t
  • n == nums2.length
  • \n\t
  • 1 <= n <= 14
  • \n\t
  • 0 <= nums1[i], nums2[i] <= 107
  • \n
\n", "tags_en": ["Bit Manipulation", "Dynamic Programming"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minimumXORSum(vector& nums1, vector& nums2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minimumXORSum(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimumXORSum(self, nums1, nums2):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimumXORSum(self, nums1: List[int], nums2: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minimumXORSum(int* nums1, int nums1Size, int* nums2, int nums2Size){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinimumXORSum(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums1\n * @param {number[]} nums2\n * @return {number}\n */\nvar minimumXORSum = function(nums1, nums2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums1\n# @param {Integer[]} nums2\n# @return {Integer}\ndef minimum_xor_sum(nums1, nums2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimumXORSum(_ nums1: [Int], _ nums2: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimumXORSum(nums1 []int, nums2 []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimumXORSum(nums1: Array[Int], nums2: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimumXORSum(nums1: IntArray, nums2: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimum_xor_sum(nums1: Vec, nums2: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums1\n * @param Integer[] $nums2\n * @return Integer\n */\n function minimumXORSum($nums1, $nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimumXORSum(nums1: number[], nums2: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimum-xor-sum nums1 nums2)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1879](https://leetcode-cn.com/problems/minimum-xor-sum-of-two-arrays)", "[\u4e24\u4e2a\u6570\u7ec4\u6700\u5c0f\u7684\u5f02\u6216\u503c\u4e4b\u548c](/solution/1800-1899/1879.Minimum%20XOR%20Sum%20of%20Two%20Arrays/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1879](https://leetcode.com/problems/minimum-xor-sum-of-two-arrays)", "[Minimum XOR Sum of Two Arrays](/solution/1800-1899/1879.Minimum%20XOR%20Sum%20of%20Two%20Arrays/README_EN.md)", "`Bit Manipulation`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "1988", "frontend_question_id": "1877", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimize-maximum-pair-sum-in-array", "url_en": "https://leetcode.com/problems/minimize-maximum-pair-sum-in-array", "relative_path_cn": "/solution/1800-1899/1877.Minimize%20Maximum%20Pair%20Sum%20in%20Array/README.md", "relative_path_en": "/solution/1800-1899/1877.Minimize%20Maximum%20Pair%20Sum%20in%20Array/README_EN.md", "title_cn": "\u6570\u7ec4\u4e2d\u6700\u5927\u6570\u5bf9\u548c\u7684\u6700\u5c0f\u503c", "title_en": "Minimize Maximum Pair Sum in Array", "question_title_slug": "minimize-maximum-pair-sum-in-array", "content_en": "

The pair sum of a pair (a,b) is equal to a + b. The maximum pair sum is the largest pair sum in a list of pairs.

\r\n\r\n
    \r\n\t
  • For example, if we have pairs (1,5), (2,3), and (4,4), the maximum pair sum would be max(1+5, 2+3, 4+4) = max(6, 5, 8) = 8.
  • \r\n
\r\n\r\n

Given an array nums of even length n, pair up the elements of nums into n / 2 pairs such that:

\r\n\r\n
    \r\n\t
  • Each element of nums is in exactly one pair, and
  • \r\n\t
  • The maximum pair sum is minimized.
  • \r\n
\r\n\r\n

Return the minimized maximum pair sum after optimally pairing up the elements.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: nums = [3,5,2,3]\r\nOutput: 7\r\nExplanation: The elements can be paired up into pairs (3,3) and (5,2).\r\nThe maximum pair sum is max(3+3, 5+2) = max(6, 7) = 7.\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: nums = [3,5,4,2,4,6]\r\nOutput: 8\r\nExplanation: The elements can be paired up into pairs (3,5), (4,4), and (6,2).\r\nThe maximum pair sum is max(3+5, 4+4, 6+2) = max(8, 8, 8) = 8.\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • n == nums.length
  • \r\n\t
  • 2 <= n <= 105
  • \r\n\t
  • n is even.
  • \r\n\t
  • 1 <= nums[i] <= 105
  • \r\n
", "content_cn": "

\u4e00\u4e2a\u6570\u5bf9\u00a0(a,b)\u00a0\u7684 \u6570\u5bf9\u548c\u00a0\u7b49\u4e8e\u00a0a + b\u00a0\u3002\u6700\u5927\u6570\u5bf9\u548c\u00a0\u662f\u4e00\u4e2a\u6570\u5bf9\u6570\u7ec4\u4e2d\u6700\u5927\u7684\u00a0\u6570\u5bf9\u548c\u00a0\u3002

\n\n
    \n\t
  • \u6bd4\u65b9\u8bf4\uff0c\u5982\u679c\u6211\u4eec\u6709\u6570\u5bf9\u00a0(1,5)\u00a0\uff0c(2,3)\u00a0\u548c\u00a0(4,4)\uff0c\u6700\u5927\u6570\u5bf9\u548c\u00a0\u4e3a\u00a0max(1+5, 2+3, 4+4) = max(6, 5, 8) = 8\u00a0\u3002
  • \n
\n\n

\u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u4e3a \u5076\u6570\u00a0n\u00a0\u7684\u6570\u7ec4\u00a0nums\u00a0\uff0c\u8bf7\u4f60\u5c06 nums\u00a0\u4e2d\u7684\u5143\u7d20\u5206\u6210 n / 2\u00a0\u4e2a\u6570\u5bf9\uff0c\u4f7f\u5f97\uff1a

\n\n
    \n\t
  • nums\u00a0\u4e2d\u6bcf\u4e2a\u5143\u7d20\u00a0\u6070\u597d\u00a0\u5728 \u4e00\u4e2a\u00a0\u6570\u5bf9\u4e2d\uff0c\u4e14
  • \n\t
  • \u6700\u5927\u6570\u5bf9\u548c\u00a0\u7684\u503c \u6700\u5c0f\u00a0\u3002
  • \n
\n\n

\u8bf7\u4f60\u5728\u6700\u4f18\u6570\u5bf9\u5212\u5206\u7684\u65b9\u6848\u4e0b\uff0c\u8fd4\u56de\u6700\u5c0f\u7684 \u6700\u5927\u6570\u5bf9\u548c\u00a0\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anums = [3,5,2,3]\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u53ef\u4ee5\u5206\u4e3a\u6570\u5bf9 (3,3) \u548c (5,2) \u3002\n\u6700\u5927\u6570\u5bf9\u548c\u4e3a max(3+3, 5+2) = max(6, 7) = 7 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anums = [3,5,4,2,4,6]\n\u8f93\u51fa\uff1a8\n\u89e3\u91ca\uff1a\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u53ef\u4ee5\u5206\u4e3a\u6570\u5bf9 (3,5)\uff0c(4,4) \u548c (6,2) \u3002\n\u6700\u5927\u6570\u5bf9\u548c\u4e3a max(3+5, 4+4, 6+2) = max(8, 8, 8) = 8 \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • n == nums.length
  • \n\t
  • 2 <= n <= 105
  • \n\t
  • n\u00a0\u662f \u5076\u6570\u00a0\u3002
  • \n\t
  • 1 <= nums[i] <= 105
  • \n
\n", "tags_en": ["Greedy", "Sort"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6392\u5e8f"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minPairSum(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minPairSum(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minPairSum(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minPairSum(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minPairSum(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinPairSum(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar minPairSum = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef min_pair_sum(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minPairSum(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minPairSum(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minPairSum(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minPairSum(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_pair_sum(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function minPairSum($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minPairSum(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-pair-sum nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1877](https://leetcode-cn.com/problems/minimize-maximum-pair-sum-in-array)", "[\u6570\u7ec4\u4e2d\u6700\u5927\u6570\u5bf9\u548c\u7684\u6700\u5c0f\u503c](/solution/1800-1899/1877.Minimize%20Maximum%20Pair%20Sum%20in%20Array/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6392\u5e8f`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1877](https://leetcode.com/problems/minimize-maximum-pair-sum-in-array)", "[Minimize Maximum Pair Sum in Array](/solution/1800-1899/1877.Minimize%20Maximum%20Pair%20Sum%20in%20Array/README_EN.md)", "`Greedy`,`Sort`", "Medium", ""]}, {"question_id": "1987", "frontend_question_id": "1876", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/substrings-of-size-three-with-distinct-characters", "url_en": "https://leetcode.com/problems/substrings-of-size-three-with-distinct-characters", "relative_path_cn": "/solution/1800-1899/1876.Substrings%20of%20Size%20Three%20with%20Distinct%20Characters/README.md", "relative_path_en": "/solution/1800-1899/1876.Substrings%20of%20Size%20Three%20with%20Distinct%20Characters/README_EN.md", "title_cn": "\u957f\u5ea6\u4e3a\u4e09\u4e14\u5404\u5b57\u7b26\u4e0d\u540c\u7684\u5b50\u5b57\u7b26\u4e32", "title_en": "Substrings of Size Three with Distinct Characters", "question_title_slug": "substrings-of-size-three-with-distinct-characters", "content_en": "

A string is good if there are no repeated characters.

\n\n

Given a string s\u200b\u200b\u200b\u200b\u200b, return the number of good substrings of length three in s\u200b\u200b\u200b\u200b\u200b\u200b.

\n\n

Note that if there are multiple occurrences of the same substring, every occurrence should be counted.

\n\n

A substring is a contiguous sequence of characters in a string.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "xyzzaz"\nOutput: 1\nExplanation: There are 4 substrings of size 3: "xyz", "yzz", "zza", and "zaz". \nThe only good substring of length 3 is "xyz".\n
\n\n

Example 2:

\n\n
\nInput: s = "aababcabc"\nOutput: 4\nExplanation: There are 7 substrings of size 3: "aab", "aba", "bab", "abc", "bca", "cab", and "abc".\nThe good substrings are "abc", "bca", "cab", and "abc".\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 100
  • \n\t
  • s\u200b\u200b\u200b\u200b\u200b\u200b consists of lowercase English letters.
  • \n
\n", "content_cn": "

\u5982\u679c\u4e00\u4e2a\u5b57\u7b26\u4e32\u4e0d\u542b\u6709\u4efb\u4f55\u91cd\u590d\u5b57\u7b26\uff0c\u6211\u4eec\u79f0\u8fd9\u4e2a\u5b57\u7b26\u4e32\u4e3a \u597d\u00a0\u5b57\u7b26\u4e32\u3002

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s\u00a0\uff0c\u8bf7\u4f60\u8fd4\u56de s\u00a0\u4e2d\u957f\u5ea6\u4e3a 3\u00a0\u7684 \u597d\u5b50\u5b57\u7b26\u4e32 \u7684\u6570\u91cf\u3002

\n\n

\u6ce8\u610f\uff0c\u5982\u679c\u76f8\u540c\u7684\u597d\u5b50\u5b57\u7b26\u4e32\u51fa\u73b0\u591a\u6b21\uff0c\u6bcf\u4e00\u6b21\u90fd\u5e94\u8be5\u88ab\u8bb0\u5165\u7b54\u6848\u4e4b\u4e2d\u3002

\n\n

\u5b50\u5b57\u7b26\u4e32 \u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\u4e2d\u8fde\u7eed\u7684\u5b57\u7b26\u5e8f\u5217\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"xyzzaz\"\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u603b\u5171\u6709 4 \u4e2a\u957f\u5ea6\u4e3a 3 \u7684\u5b50\u5b57\u7b26\u4e32\uff1a\"xyz\"\uff0c\"yzz\"\uff0c\"zza\" \u548c \"zaz\" \u3002\n\u552f\u4e00\u7684\u957f\u5ea6\u4e3a 3 \u7684\u597d\u5b50\u5b57\u7b26\u4e32\u662f \"xyz\" \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"aababcabc\"\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u603b\u5171\u6709 7 \u4e2a\u957f\u5ea6\u4e3a 3 \u7684\u5b50\u5b57\u7b26\u4e32\uff1a\"aab\"\uff0c\"aba\"\uff0c\"bab\"\uff0c\"abc\"\uff0c\"bca\"\uff0c\"cab\" \u548c \"abc\" \u3002\n\u597d\u5b50\u5b57\u7b26\u4e32\u5305\u62ec \"abc\"\uff0c\"bca\"\uff0c\"cab\" \u548c \"abc\" \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length <= 100
  • \n\t
  • s\u200b\u200b\u200b\u200b\u200b\u200b \u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countGoodSubstrings(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countGoodSubstrings(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countGoodSubstrings(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countGoodSubstrings(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countGoodSubstrings(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountGoodSubstrings(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar countGoodSubstrings = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef count_good_substrings(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countGoodSubstrings(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countGoodSubstrings(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countGoodSubstrings(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countGoodSubstrings(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_good_substrings(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function countGoodSubstrings($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countGoodSubstrings(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-good-substrings s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1876](https://leetcode-cn.com/problems/substrings-of-size-three-with-distinct-characters)", "[\u957f\u5ea6\u4e3a\u4e09\u4e14\u5404\u5b57\u7b26\u4e0d\u540c\u7684\u5b50\u5b57\u7b26\u4e32](/solution/1800-1899/1876.Substrings%20of%20Size%20Three%20with%20Distinct%20Characters/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1876](https://leetcode.com/problems/substrings-of-size-three-with-distinct-characters)", "[Substrings of Size Three with Distinct Characters](/solution/1800-1899/1876.Substrings%20of%20Size%20Three%20with%20Distinct%20Characters/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1986", "frontend_question_id": "1857", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/largest-color-value-in-a-directed-graph", "url_en": "https://leetcode.com/problems/largest-color-value-in-a-directed-graph", "relative_path_cn": "/solution/1800-1899/1857.Largest%20Color%20Value%20in%20a%20Directed%20Graph/README.md", "relative_path_en": "/solution/1800-1899/1857.Largest%20Color%20Value%20in%20a%20Directed%20Graph/README_EN.md", "title_cn": "\u6709\u5411\u56fe\u4e2d\u6700\u5927\u989c\u8272\u503c", "title_en": "Largest Color Value in a Directed Graph", "question_title_slug": "largest-color-value-in-a-directed-graph", "content_en": "

There is a directed graph of n colored nodes and m edges. The nodes are numbered from 0 to n - 1.

\n\n

You are given a string colors where colors[i] is a lowercase English letter representing the color of the ith node in this graph (0-indexed). You are also given a 2D array edges where edges[j] = [aj, bj] indicates that there is a directed edge from node aj to node bj.

\n\n

A valid path in the graph is a sequence of nodes x1 -> x2 -> x3 -> ... -> xk such that there is a directed edge from xi to xi+1 for every 1 <= i < k. The color value of the path is the number of nodes that are colored the most frequently occurring color along that path.

\n\n

Return the largest color value of any valid path in the given graph, or -1 if the graph contains a cycle.

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: colors = "abaca", edges = [[0,1],[0,2],[2,3],[3,4]]\nOutput: 3\nExplanation: The path 0 -> 2 -> 3 -> 4 contains 3 nodes that are colored "a" (red in the above image).\n
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: colors = "a", edges = [[0,0]]\nOutput: -1\nExplanation: There is a cycle from 0 to 0.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == colors.length
  • \n\t
  • m == edges.length
  • \n\t
  • 1 <= n <= 105
  • \n\t
  • 0 <= m <= 105
  • \n\t
  • colors consists of lowercase English letters.
  • \n\t
  • 0 <= aj, bj < n
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u00a0\u6709\u5411\u56fe\u00a0\uff0c\u5b83\u542b\u6709\u00a0n\u00a0\u4e2a\u8282\u70b9\u548c m\u00a0\u6761\u8fb9\u3002\u8282\u70b9\u7f16\u53f7\u4ece\u00a00 \u5230\u00a0n - 1\u00a0\u3002

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32\u00a0colors \uff0c\u5176\u4e2d\u00a0colors[i]\u00a0\u662f\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\uff0c\u8868\u793a\u56fe\u4e2d\u7b2c i\u00a0\u4e2a\u8282\u70b9\u7684 \u989c\u8272\u00a0\uff08\u4e0b\u6807\u4ece 0\u00a0\u5f00\u59cb\uff09\u3002\u540c\u65f6\u7ed9\u4f60\u4e00\u4e2a\u4e8c\u7ef4\u6570\u7ec4\u00a0edges\u00a0\uff0c\u5176\u4e2d\u00a0edges[j] = [aj, bj]\u00a0\u8868\u793a\u4ece\u8282\u70b9\u00a0aj\u00a0\u5230\u8282\u70b9\u00a0bj\u00a0\u6709\u4e00\u6761\u00a0\u6709\u5411\u8fb9\u00a0\u3002

\n\n

\u56fe\u4e2d\u4e00\u6761\u6709\u6548 \u8def\u5f84\u00a0\u662f\u4e00\u4e2a\u70b9\u5e8f\u5217\u00a0x1 -> x2 -> x3 -> ... -> xk\u00a0\uff0c\u5bf9\u4e8e\u6240\u6709\u00a01 <= i < k\u00a0\uff0c\u4ece\u00a0xi \u5230\u00a0xi+1\u00a0\u5728\u56fe\u4e2d\u6709\u4e00\u6761\u6709\u5411\u8fb9\u3002\u8def\u5f84\u7684 \u989c\u8272\u503c\u00a0\u662f\u8def\u5f84\u4e2d \u51fa\u73b0\u6b21\u6570\u6700\u591a \u989c\u8272\u7684\u8282\u70b9\u6570\u76ee\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u7ed9\u5b9a\u56fe\u4e2d\u6709\u6548\u8def\u5f84\u91cc\u9762\u7684\u00a0\u6700\u5927\u989c\u8272\u503c\u00a0\u3002\u5982\u679c\u56fe\u4e2d\u542b\u6709\u73af\uff0c\u8bf7\u8fd4\u56de -1\u00a0\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1acolors = \"abaca\", edges = [[0,1],[0,2],[2,3],[3,4]]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u8def\u5f84 0 -> 2 -> 3 -> 4 \u542b\u6709 3 \u4e2a\u989c\u8272\u4e3a \"a\" \u7684\u8282\u70b9\uff08\u4e0a\u56fe\u4e2d\u7684\u7ea2\u8272\u8282\u70b9\uff09\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1acolors = \"a\", edges = [[0,0]]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u4ece 0 \u5230 0 \u6709\u4e00\u4e2a\u73af\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • n == colors.length
  • \n\t
  • m == edges.length
  • \n\t
  • 1 <= n <= 105
  • \n\t
  • 0 <= m <= 105
  • \n\t
  • colors\u00a0\u53ea\u542b\u6709\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
  • \n\t
  • 0 <= aj, bj\u00a0< n
  • \n
\n", "tags_en": ["Topological Sort", "Dynamic Programming"], "tags_cn": ["\u62d3\u6251\u6392\u5e8f", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int largestPathValue(string colors, vector>& edges) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int largestPathValue(String colors, int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def largestPathValue(self, colors, edges):\n \"\"\"\n :type colors: str\n :type edges: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def largestPathValue(self, colors: str, edges: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint largestPathValue(char * colors, int** edges, int edgesSize, int* edgesColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LargestPathValue(string colors, int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} colors\n * @param {number[][]} edges\n * @return {number}\n */\nvar largestPathValue = function(colors, edges) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} colors\n# @param {Integer[][]} edges\n# @return {Integer}\ndef largest_path_value(colors, edges)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func largestPathValue(_ colors: String, _ edges: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func largestPathValue(colors string, edges [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def largestPathValue(colors: String, edges: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun largestPathValue(colors: String, edges: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn largest_path_value(colors: String, edges: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $colors\n * @param Integer[][] $edges\n * @return Integer\n */\n function largestPathValue($colors, $edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function largestPathValue(colors: string, edges: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (largest-path-value colors edges)\n (-> string? (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1857](https://leetcode-cn.com/problems/largest-color-value-in-a-directed-graph)", "[\u6709\u5411\u56fe\u4e2d\u6700\u5927\u989c\u8272\u503c](/solution/1800-1899/1857.Largest%20Color%20Value%20in%20a%20Directed%20Graph/README.md)", "`\u62d3\u6251\u6392\u5e8f`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1857](https://leetcode.com/problems/largest-color-value-in-a-directed-graph)", "[Largest Color Value in a Directed Graph](/solution/1800-1899/1857.Largest%20Color%20Value%20in%20a%20Directed%20Graph/README_EN.md)", "`Topological Sort`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "1985", "frontend_question_id": "1856", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-subarray-min-product", "url_en": "https://leetcode.com/problems/maximum-subarray-min-product", "relative_path_cn": "/solution/1800-1899/1856.Maximum%20Subarray%20Min-Product/README.md", "relative_path_en": "/solution/1800-1899/1856.Maximum%20Subarray%20Min-Product/README_EN.md", "title_cn": "\u5b50\u6570\u7ec4\u6700\u5c0f\u4e58\u79ef\u7684\u6700\u5927\u503c", "title_en": "Maximum Subarray Min-Product", "question_title_slug": "maximum-subarray-min-product", "content_en": "

The min-product of an array is equal to the minimum value in the array multiplied by the array's sum.

\n\n
    \n\t
  • For example, the array [3,2,5] (minimum value is 2) has a min-product of 2 * (3+2+5) = 2 * 10 = 20.
  • \n
\n\n

Given an array of integers nums, return the maximum min-product of any non-empty subarray of nums. Since the answer may be large, return it modulo 109 + 7.

\n\n

Note that the min-product should be maximized before performing the modulo operation. Testcases are generated such that the maximum min-product without modulo will fit in a 64-bit signed integer.

\n\n

A subarray is a contiguous part of an array.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [1,2,3,2]\nOutput: 14\nExplanation: The maximum min-product is achieved with the subarray [2,3,2] (minimum value is 2).\n2 * (2+3+2) = 2 * 7 = 14.\n
\n\n

Example 2:

\n\n
\nInput: nums = [2,3,3,1,2]\nOutput: 18\nExplanation: The maximum min-product is achieved with the subarray [3,3] (minimum value is 3).\n3 * (3+3) = 3 * 6 = 18.\n
\n\n

Example 3:

\n\n
\nInput: nums = [3,1,5,6,4,2]\nOutput: 60\nExplanation: The maximum min-product is achieved with the subarray [5,6,4] (minimum value is 4).\n4 * (5+6+4) = 4 * 15 = 60.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 105
  • \n\t
  • 1 <= nums[i] <= 107
  • \n
\n", "content_cn": "

\u4e00\u4e2a\u6570\u7ec4\u7684 \u6700\u5c0f\u4e58\u79ef\u00a0\u5b9a\u4e49\u4e3a\u8fd9\u4e2a\u6570\u7ec4\u4e2d \u6700\u5c0f\u503c\u00a0\u4e58\u4ee5\u00a0\u6570\u7ec4\u7684 \u548c\u00a0\u3002

\n\n
    \n\t
  • \u6bd4\u65b9\u8bf4\uff0c\u6570\u7ec4\u00a0[3,2,5]\u00a0\uff08\u6700\u5c0f\u503c\u662f\u00a02\uff09\u7684\u6700\u5c0f\u4e58\u79ef\u4e3a\u00a02 * (3+2+5) = 2 * 10 = 20\u00a0\u3002
  • \n
\n\n

\u7ed9\u4f60\u4e00\u4e2a\u6b63\u6574\u6570\u6570\u7ec4\u00a0nums\u00a0\uff0c\u8bf7\u4f60\u8fd4\u56de\u00a0nums\u00a0\u4efb\u610f\u00a0\u975e\u7a7a\u5b50\u6570\u7ec4\u00a0\u7684\u6700\u5c0f\u4e58\u79ef\u00a0\u7684\u00a0\u6700\u5927\u503c\u00a0\u3002\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u5f88\u5927\uff0c\u8bf7\u4f60\u8fd4\u56de\u7b54\u6848\u5bf9\u00a0\u00a0109 + 7\u00a0\u53d6\u4f59\u00a0\u7684\u7ed3\u679c\u3002

\n\n

\u8bf7\u6ce8\u610f\uff0c\u6700\u5c0f\u4e58\u79ef\u7684\u6700\u5927\u503c\u8003\u8651\u7684\u662f\u53d6\u4f59\u64cd\u4f5c \u4e4b\u524d\u00a0\u7684\u7ed3\u679c\u3002\u9898\u76ee\u4fdd\u8bc1\u6700\u5c0f\u4e58\u79ef\u7684\u6700\u5927\u503c\u5728 \u4e0d\u53d6\u4f59 \u7684\u60c5\u51b5\u4e0b\u53ef\u4ee5\u7528 64 \u4f4d\u6709\u7b26\u53f7\u6574\u6570\u00a0\u4fdd\u5b58\u3002

\n\n

\u5b50\u6570\u7ec4\u00a0\u5b9a\u4e49\u4e3a\u4e00\u4e2a\u6570\u7ec4\u7684 \u8fde\u7eed\u00a0\u90e8\u5206\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [1,2,3,2]\n\u8f93\u51fa\uff1a14\n\u89e3\u91ca\uff1a\u6700\u5c0f\u4e58\u79ef\u7684\u6700\u5927\u503c\u7531\u5b50\u6570\u7ec4 [2,3,2] \uff08\u6700\u5c0f\u503c\u662f 2\uff09\u5f97\u5230\u3002\n2 * (2+3+2) = 2 * 7 = 14 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [2,3,3,1,2]\n\u8f93\u51fa\uff1a18\n\u89e3\u91ca\uff1a\u6700\u5c0f\u4e58\u79ef\u7684\u6700\u5927\u503c\u7531\u5b50\u6570\u7ec4 [3,3] \uff08\u6700\u5c0f\u503c\u662f 3\uff09\u5f97\u5230\u3002\n3 * (3+3) = 3 * 6 = 18 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [3,1,5,6,4,2]\n\u8f93\u51fa\uff1a60\n\u89e3\u91ca\uff1a\u6700\u5c0f\u4e58\u79ef\u7684\u6700\u5927\u503c\u7531\u5b50\u6570\u7ec4 [5,6,4] \uff08\u6700\u5c0f\u503c\u662f 4\uff09\u5f97\u5230\u3002\n4 * (5+6+4) = 4 * 15 = 60 \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 105
  • \n\t
  • 1 <= nums[i] <= 107
  • \n
\n", "tags_en": ["Sort", "Union Find", "Queue", "Binary Search", "Dynamic Programming"], "tags_cn": ["\u6392\u5e8f", "\u5e76\u67e5\u96c6", "\u961f\u5217", "\u4e8c\u5206\u67e5\u627e", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxSumMinProduct(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxSumMinProduct(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxSumMinProduct(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxSumMinProduct(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxSumMinProduct(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxSumMinProduct(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar maxSumMinProduct = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef max_sum_min_product(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxSumMinProduct(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxSumMinProduct(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxSumMinProduct(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxSumMinProduct(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_sum_min_product(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function maxSumMinProduct($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxSumMinProduct(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-sum-min-product nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1856](https://leetcode-cn.com/problems/maximum-subarray-min-product)", "[\u5b50\u6570\u7ec4\u6700\u5c0f\u4e58\u79ef\u7684\u6700\u5927\u503c](/solution/1800-1899/1856.Maximum%20Subarray%20Min-Product/README.md)", "`\u6392\u5e8f`,`\u5e76\u67e5\u96c6`,`\u961f\u5217`,`\u4e8c\u5206\u67e5\u627e`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1856](https://leetcode.com/problems/maximum-subarray-min-product)", "[Maximum Subarray Min-Product](/solution/1800-1899/1856.Maximum%20Subarray%20Min-Product/README_EN.md)", "`Sort`,`Union Find`,`Queue`,`Binary Search`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "1984", "frontend_question_id": "1855", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-distance-between-a-pair-of-values", "url_en": "https://leetcode.com/problems/maximum-distance-between-a-pair-of-values", "relative_path_cn": "/solution/1800-1899/1855.Maximum%20Distance%20Between%20a%20Pair%20of%20Values/README.md", "relative_path_en": "/solution/1800-1899/1855.Maximum%20Distance%20Between%20a%20Pair%20of%20Values/README_EN.md", "title_cn": "\u4e0b\u6807\u5bf9\u4e2d\u7684\u6700\u5927\u8ddd\u79bb", "title_en": "Maximum Distance Between a Pair of Values", "question_title_slug": "maximum-distance-between-a-pair-of-values", "content_en": "

You are given two non-increasing 0-indexed integer arrays nums1\u200b\u200b\u200b\u200b\u200b\u200b and nums2\u200b\u200b\u200b\u200b\u200b\u200b.

\n\n

A pair of indices (i, j), where 0 <= i < nums1.length and 0 <= j < nums2.length, is valid if both i <= j and nums1[i] <= nums2[j]. The distance of the pair is j - i\u200b\u200b\u200b\u200b.

\n\n

Return the maximum distance of any valid pair (i, j). If there are no valid pairs, return 0.

\n\n

An array arr is non-increasing if arr[i-1] >= arr[i] for every 1 <= i < arr.length.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums1 = [55,30,5,4,2], nums2 = [100,20,10,10,5]\nOutput: 2\nExplanation: The valid pairs are (0,0), (2,2), (2,3), (2,4), (3,3), (3,4), and (4,4).\nThe maximum distance is 2 with pair (2,4).\n
\n\n

Example 2:

\n\n
\nInput: nums1 = [2,2,2], nums2 = [10,10,1]\nOutput: 1\nExplanation: The valid pairs are (0,0), (0,1), and (1,1).\nThe maximum distance is 1 with pair (0,1).\n
\n\n

Example 3:

\n\n
\nInput: nums1 = [30,29,19,5], nums2 = [25,25,25,25,25]\nOutput: 2\nExplanation: The valid pairs are (2,2), (2,3), (2,4), (3,3), and (3,4).\nThe maximum distance is 2 with pair (2,4).\n
\n\n

Example 4:

\n\n
\nInput: nums1 = [5,4], nums2 = [3,2]\nOutput: 0\nExplanation: There are no valid pairs, so return 0.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums1.length <= 105
  • \n\t
  • 1 <= nums2.length <= 105
  • \n\t
  • 1 <= nums1[i], nums2[j] <= 105
  • \n\t
  • Both nums1 and nums2 are non-increasing.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e24\u4e2a \u975e\u9012\u589e \u7684\u6574\u6570\u6570\u7ec4 nums1\u200b\u200b\u200b\u200b\u200b\u200b \u548c nums2\u200b\u200b\u200b\u200b\u200b\u200b \uff0c\u6570\u7ec4\u4e0b\u6807\u5747 \u4ece 0 \u5f00\u59cb \u8ba1\u6570\u3002

\n\n

\u4e0b\u6807\u5bf9 (i, j) \u4e2d 0 <= i < nums1.length \u4e14 0 <= j < nums2.length \u3002\u5982\u679c\u8be5\u4e0b\u6807\u5bf9\u540c\u65f6\u6ee1\u8db3 i <= j \u4e14 nums1[i] <= nums2[j] \uff0c\u5219\u79f0\u4e4b\u4e3a \u6709\u6548 \u4e0b\u6807\u5bf9\uff0c\u8be5\u4e0b\u6807\u5bf9\u7684 \u8ddd\u79bb \u4e3a j - i\u200b\u200b \u3002\u200b\u200b

\n\n

\u8fd4\u56de\u6240\u6709 \u6709\u6548 \u4e0b\u6807\u5bf9 (i, j) \u4e2d\u7684 \u6700\u5927\u8ddd\u79bb \u3002\u5982\u679c\u4e0d\u5b58\u5728\u6709\u6548\u4e0b\u6807\u5bf9\uff0c\u8fd4\u56de 0 \u3002

\n\n

\u4e00\u4e2a\u6570\u7ec4 arr \uff0c\u5982\u679c\u6bcf\u4e2a 1 <= i < arr.length \u5747\u6709 arr[i-1] >= arr[i] \u6210\u7acb\uff0c\u90a3\u4e48\u8be5\u6570\u7ec4\u662f\u4e00\u4e2a \u975e\u9012\u589e \u6570\u7ec4\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1anums1 = [55,30,5,4,2], nums2 = [100,20,10,10,5]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6709\u6548\u4e0b\u6807\u5bf9\u662f (0,0), (2,2), (2,3), (2,4), (3,3), (3,4) \u548c (4,4) \u3002\n\u6700\u5927\u8ddd\u79bb\u662f 2 \uff0c\u5bf9\u5e94\u4e0b\u6807\u5bf9 (2,4) \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1anums1 = [2,2,2], nums2 = [10,10,1]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u6709\u6548\u4e0b\u6807\u5bf9\u662f (0,0), (0,1) \u548c (1,1) \u3002\n\u6700\u5927\u8ddd\u79bb\u662f 1 \uff0c\u5bf9\u5e94\u4e0b\u6807\u5bf9 (0,1) \u3002
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1anums1 = [30,29,19,5], nums2 = [25,25,25,25,25]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6709\u6548\u4e0b\u6807\u5bf9\u662f (2,2), (2,3), (2,4), (3,3) \u548c (3,4) \u3002\n\u6700\u5927\u8ddd\u79bb\u662f 2 \uff0c\u5bf9\u5e94\u4e0b\u6807\u5bf9 (2,4) \u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1anums1 = [5,4], nums2 = [3,2]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u4e0d\u5b58\u5728\u6709\u6548\u4e0b\u6807\u5bf9\uff0c\u6240\u4ee5\u8fd4\u56de 0 \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums1.length <= 105
  • \n\t
  • 1 <= nums2.length <= 105
  • \n\t
  • 1 <= nums1[i], nums2[j] <= 105
  • \n\t
  • nums1 \u548c nums2 \u90fd\u662f \u975e\u9012\u589e \u6570\u7ec4
  • \n
\n", "tags_en": ["Greedy", "Two Pointers", "Binary Search"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u53cc\u6307\u9488", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxDistance(vector& nums1, vector& nums2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxDistance(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxDistance(self, nums1, nums2):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxDistance(self, nums1: List[int], nums2: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxDistance(int* nums1, int nums1Size, int* nums2, int nums2Size){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxDistance(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums1\n * @param {number[]} nums2\n * @return {number}\n */\nvar maxDistance = function(nums1, nums2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums1\n# @param {Integer[]} nums2\n# @return {Integer}\ndef max_distance(nums1, nums2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxDistance(_ nums1: [Int], _ nums2: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxDistance(nums1 []int, nums2 []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxDistance(nums1: Array[Int], nums2: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxDistance(nums1: IntArray, nums2: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_distance(nums1: Vec, nums2: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums1\n * @param Integer[] $nums2\n * @return Integer\n */\n function maxDistance($nums1, $nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxDistance(nums1: number[], nums2: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-distance nums1 nums2)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1855](https://leetcode-cn.com/problems/maximum-distance-between-a-pair-of-values)", "[\u4e0b\u6807\u5bf9\u4e2d\u7684\u6700\u5927\u8ddd\u79bb](/solution/1800-1899/1855.Maximum%20Distance%20Between%20a%20Pair%20of%20Values/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u53cc\u6307\u9488`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1855](https://leetcode.com/problems/maximum-distance-between-a-pair-of-values)", "[Maximum Distance Between a Pair of Values](/solution/1800-1899/1855.Maximum%20Distance%20Between%20a%20Pair%20of%20Values/README_EN.md)", "`Greedy`,`Two Pointers`,`Binary Search`", "Medium", ""]}, {"question_id": "1983", "frontend_question_id": "1854", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-population-year", "url_en": "https://leetcode.com/problems/maximum-population-year", "relative_path_cn": "/solution/1800-1899/1854.Maximum%20Population%20Year/README.md", "relative_path_en": "/solution/1800-1899/1854.Maximum%20Population%20Year/README_EN.md", "title_cn": "\u4eba\u53e3\u6700\u591a\u7684\u5e74\u4efd", "title_en": "Maximum Population Year", "question_title_slug": "maximum-population-year", "content_en": "

You are given a 2D integer array logs where each logs[i] = [birthi, deathi] indicates the birth and death years of the ith person.

\n\n

The population of some year x is the number of people alive during that year. The ith person is counted in year x's population if x is in the inclusive range [birthi, deathi - 1]. Note that the person is not counted in the year that they die.

\n\n

Return the earliest year with the maximum population.

\n\n

 

\n

Example 1:

\n\n
\nInput: logs = [[1993,1999],[2000,2010]]\nOutput: 1993\nExplanation: The maximum population is 1, and 1993 is the earliest year with this population.\n
\n\n

Example 2:

\n\n
\nInput: logs = [[1950,1961],[1960,1971],[1970,1981]]\nOutput: 1960\nExplanation: \nThe maximum population is 2, and it had happened in years 1960 and 1970.\nThe earlier year between them is 1960.
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= logs.length <= 100
  • \n\t
  • 1950 <= birthi < deathi <= 2050
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u4e8c\u7ef4\u6574\u6570\u6570\u7ec4 logs \uff0c\u5176\u4e2d\u6bcf\u4e2a logs[i] = [birthi, deathi] \u8868\u793a\u7b2c i \u4e2a\u4eba\u7684\u51fa\u751f\u548c\u6b7b\u4ea1\u5e74\u4efd\u3002

\n\n

\u5e74\u4efd x \u7684 \u4eba\u53e3 \u5b9a\u4e49\u4e3a\u8fd9\u4e00\u5e74\u671f\u95f4\u6d3b\u7740\u7684\u4eba\u7684\u6570\u76ee\u3002\u7b2c i \u4e2a\u4eba\u88ab\u8ba1\u5165\u5e74\u4efd x \u7684\u4eba\u53e3\u9700\u8981\u6ee1\u8db3\uff1ax \u5728\u95ed\u533a\u95f4 [birthi, deathi - 1] \u5185\u3002\u6ce8\u610f\uff0c\u4eba\u4e0d\u5e94\u5f53\u8ba1\u5165\u4ed6\u4eec\u6b7b\u4ea1\u5f53\u5e74\u7684\u4eba\u53e3\u4e2d\u3002

\n\n

\u8fd4\u56de \u4eba\u53e3\u6700\u591a \u4e14 \u6700\u65e9 \u7684\u5e74\u4efd\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1alogs = [[1993,1999],[2000,2010]]\n\u8f93\u51fa\uff1a1993\n\u89e3\u91ca\uff1a\u4eba\u53e3\u6700\u591a\u4e3a 1 \uff0c\u800c 1993 \u662f\u4eba\u53e3\u4e3a 1 \u7684\u6700\u65e9\u5e74\u4efd\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1alogs = [[1950,1961],[1960,1971],[1970,1981]]\n\u8f93\u51fa\uff1a1960\n\u89e3\u91ca\uff1a \n\u4eba\u53e3\u6700\u591a\u4e3a 2 \uff0c\u5206\u522b\u51fa\u73b0\u5728 1960 \u548c 1970 \u3002\n\u5176\u4e2d\u6700\u65e9\u5e74\u4efd\u662f 1960 \u3002
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= logs.length <= 100
  • \n\t
  • 1950 <= birthi < deathi <= 2050
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maximumPopulation(vector>& logs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maximumPopulation(int[][] logs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximumPopulation(self, logs):\n \"\"\"\n :type logs: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximumPopulation(self, logs: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maximumPopulation(int** logs, int logsSize, int* logsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaximumPopulation(int[][] logs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} logs\n * @return {number}\n */\nvar maximumPopulation = function(logs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} logs\n# @return {Integer}\ndef maximum_population(logs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximumPopulation(_ logs: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximumPopulation(logs [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximumPopulation(logs: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximumPopulation(logs: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximum_population(logs: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $logs\n * @return Integer\n */\n function maximumPopulation($logs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximumPopulation(logs: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximum-population logs)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1854](https://leetcode-cn.com/problems/maximum-population-year)", "[\u4eba\u53e3\u6700\u591a\u7684\u5e74\u4efd](/solution/1800-1899/1854.Maximum%20Population%20Year/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1854](https://leetcode.com/problems/maximum-population-year)", "[Maximum Population Year](/solution/1800-1899/1854.Maximum%20Population%20Year/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1982", "frontend_question_id": "1836", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/remove-duplicates-from-an-unsorted-linked-list", "url_en": "https://leetcode.com/problems/remove-duplicates-from-an-unsorted-linked-list", "relative_path_cn": "/solution/1800-1899/1836.Remove%20Duplicates%20From%20an%20Unsorted%20Linked%20List/README.md", "relative_path_en": "/solution/1800-1899/1836.Remove%20Duplicates%20From%20an%20Unsorted%20Linked%20List/README_EN.md", "title_cn": "", "title_en": "Remove Duplicates From an Unsorted Linked List", "question_title_slug": "remove-duplicates-from-an-unsorted-linked-list", "content_en": "

Given the head of a linked list, find all the values that appear more than once in the list and delete the nodes that have any of those values.

\r\n\r\n

Return the linked list after the deletions.

\r\n\r\n

 

\r\n

Example 1:

\r\n\"\"\r\n
\r\nInput: head = [1,2,3,2]\r\nOutput: [1,3]\r\nExplanation: 2 appears twice in the linked list, so all 2's should be deleted. After deleting all 2's, we are left with [1,3].\r\n
\r\n\r\n

Example 2:

\r\n\"\"\r\n
\r\nInput: head = [2,1,1,2]\r\nOutput: []\r\nExplanation: 2 and 1 both appear twice. All the elements should be deleted.\r\n
\r\n\r\n

Example 3:

\r\n\"\"\r\n
\r\nInput: head = [3,2,2,1,3,2,4]\r\nOutput: [1,4]\r\nExplanation: 3 appears twice and 2 appears three times. After deleting all 3's and 2's, we are left with [1,4].\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • The number of nodes in the list is in the range [1, 105]
  • \r\n\t
  • 1 <= Node.val <= 105
  • \r\n
", "content_cn": null, "tags_en": ["Linked List"], "tags_cn": ["\u94fe\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n ListNode* deleteDuplicatesUnsorted(ListNode* head) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public ListNode deleteDuplicatesUnsorted(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def deleteDuplicatesUnsorted(self, head):\n \"\"\"\n :type head: ListNode\n :rtype: ListNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def deleteDuplicatesUnsorted(self, head: ListNode) -> ListNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nstruct ListNode* deleteDuplicatesUnsorted(struct ListNode* head){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public ListNode DeleteDuplicatesUnsorted(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} head\n * @return {ListNode}\n */\nvar deleteDuplicatesUnsorted = function(head) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode} head\n# @return {ListNode}\ndef delete_duplicates_unsorted(head)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func deleteDuplicatesUnsorted(_ head: ListNode?) -> ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc deleteDuplicatesUnsorted(head *ListNode) *ListNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def deleteDuplicatesUnsorted(head: ListNode): ListNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun deleteDuplicatesUnsorted(head: ListNode?): ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn delete_duplicates_unsorted(head: Option>) -> Option> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @return ListNode\n */\n function deleteDuplicatesUnsorted($head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction deleteDuplicatesUnsorted(head: ListNode | null): ListNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (delete-duplicates-unsorted head)\n (-> (or/c list-node? #f) (or/c list-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1836](https://leetcode-cn.com/problems/remove-duplicates-from-an-unsorted-linked-list)", "[Remove Duplicates From an Unsorted Linked List](/solution/1800-1899/1836.Remove%20Duplicates%20From%20an%20Unsorted%20Linked%20List/README_EN.md)", "`\u94fe\u8868`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1836](https://leetcode.com/problems/remove-duplicates-from-an-unsorted-linked-list)", "[Remove Duplicates From an Unsorted Linked List](/solution/1800-1899/1836.Remove%20Duplicates%20From%20an%20Unsorted%20Linked%20List/README_EN.md)", "`Linked List`", "Medium", "\ud83d\udd12"]}, {"question_id": "1981", "frontend_question_id": "1831", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/maximum-transaction-each-day", "url_en": "https://leetcode.com/problems/maximum-transaction-each-day", "relative_path_cn": "/solution/1800-1899/1831.Maximum%20Transaction%20Each%20Day/README.md", "relative_path_en": "/solution/1800-1899/1831.Maximum%20Transaction%20Each%20Day/README_EN.md", "title_cn": "", "title_en": "Maximum Transaction Each Day", "question_title_slug": "maximum-transaction-each-day", "content_en": "

Table: Transactions

\r\n\r\n
\r\n+----------------+----------+\r\n| Column Name    | Type     |\r\n+----------------+----------+\r\n| transaction_id | int      |\r\n| day            | datetime |\r\n| amount         | int      |\r\n+----------------+----------+\r\ntransaction_id is the primary key for this table.\r\nEach row contains information about one transaction.\r\n
\r\n\r\n

 

\r\n\r\n

Write an SQL query to report the IDs of the transactions with the maximum amount on their respective day. If in one day there are multiple such transactions, return all of them.

\r\n\r\n

Return the result table in ascending order by transaction_id.

\r\n\r\n

The query result format is in the following example:

\r\n\r\n

 

\r\n\r\n
\r\nTransactions table:\r\n+----------------+--------------------+--------+\r\n| transaction_id | day                | amount |\r\n+----------------+--------------------+--------+\r\n| 8              | 2021-4-3 15:57:28  | 57     |\r\n| 9              | 2021-4-28 08:47:25 | 21     |\r\n| 1              | 2021-4-29 13:28:30 | 58     |\r\n| 5              | 2021-4-28 16:39:59 | 40     |\r\n| 6              | 2021-4-29 23:39:28 | 58     |\r\n+----------------+--------------------+--------+\r\n\r\nResult table:\r\n+----------------+\r\n| transaction_id |\r\n+----------------+\r\n| 1              |\r\n| 5              |\r\n| 6              |\r\n| 8              |\r\n+----------------+\r\n"2021-4-3"  --> We have one transaction with ID 8, so we add 8 to the result table.\r\n"2021-4-28" --> We have two transactions with IDs 5 and 9. The transaction with ID 5 has an amount of 40, while the transaction with ID 9 has an amount of 21. We only include the transaction with ID 5 as it has the maximum amount this day.\r\n"2021-4-29" --> We have two transactions with IDs 1 and 6. Both transactions have the same amount of 58, so we include both in the result table.\r\nWe order the result table by transaction_id after collecting these IDs.
\r\n\r\n

 

\r\n

Follow up: Could you solve it without using the MAX() function?

", "content_cn": null, "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1831](https://leetcode-cn.com/problems/maximum-transaction-each-day)", "[Maximum Transaction Each Day](/solution/1800-1899/1831.Maximum%20Transaction%20Each%20Day/README_EN.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1831](https://leetcode.com/problems/maximum-transaction-each-day)", "[Maximum Transaction Each Day](/solution/1800-1899/1831.Maximum%20Transaction%20Each%20Day/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1980", "frontend_question_id": "1826", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/faulty-sensor", "url_en": "https://leetcode.com/problems/faulty-sensor", "relative_path_cn": "/solution/1800-1899/1826.Faulty%20Sensor/README.md", "relative_path_en": "/solution/1800-1899/1826.Faulty%20Sensor/README_EN.md", "title_cn": "\u6709\u7f3a\u9677\u7684\u4f20\u611f\u5668", "title_en": "Faulty Sensor", "question_title_slug": "faulty-sensor", "content_en": "

An experiment is being conducted in a lab. To ensure accuracy, there are two sensors collecting data simultaneously. You are given two arrays sensor1 and sensor2, where sensor1[i] and sensor2[i] are the ith data points collected by the two sensors.

\n\n

However, this type of sensor has a chance of being defective, which causes exactly one data point to be dropped. After the data is dropped, all the data points to the right of the dropped data are shifted one place to the left, and the last data point is replaced with some random value. It is guaranteed that this random value will not be equal to the dropped value.

\n\n
    \n\t
  • For example, if the correct data is [1,2,3,4,5] and 3 is dropped, the sensor could return [1,2,4,5,7] (the last position can be any value, not just 7).
  • \n
\n\n

We know that there is a defect in at most one of the sensors. Return the sensor number (1 or 2) with the defect. If there is no defect in either sensor or if it is impossible to determine the defective sensor, return -1.

\n\n

 

\n

Example 1:

\n\n
\nInput: sensor1 = [2,3,4,5], sensor2 = [2,1,3,4]\nOutput: 1\nExplanation: Sensor 2 has the correct values.\nThe second data point from sensor 2 is dropped, and the last value of sensor 1 is replaced by a 5.\n
\n\n

Example 2:

\n\n
\nInput: sensor1 = [2,2,2,2,2], sensor2 = [2,2,2,2,5]\nOutput: -1\nExplanation: It is impossible to determine which sensor has a defect.\nDropping the last value for either sensor could produce the output for the other sensor.\n
\n\n

Example 3:

\n\n
\nInput: sensor1 = [2,3,2,2,3,2], sensor2 = [2,3,2,3,2,7]\nOutput: 2\nExplanation: Sensor 1 has the correct values.\nThe fourth data point from sensor 1 is dropped, and the last value of sensor 1 is replaced by a 7.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • sensor1.length == sensor2.length
  • \n\t
  • 1 <= sensor1.length <= 100
  • \n\t
  • 1 <= sensor1[i], sensor2[i] <= 100
  • \n
\n", "content_cn": "

\u5b9e\u9a8c\u5ba4\u91cc\u6b63\u5728\u8fdb\u884c\u4e00\u9879\u5b9e\u9a8c\u3002\u4e3a\u4e86\u786e\u4fdd\u6570\u636e\u7684\u51c6\u786e\u6027\uff0c\u540c\u65f6\u4f7f\u7528 \u4e24\u4e2a \u4f20\u611f\u5668\u6765\u91c7\u96c6\u6570\u636e\u3002\u60a8\u5c06\u83b7\u5f972\u4e2a\u6570\u7ec4 sensor1 and sensor2\uff0c\u5176\u4e2d sensor1[i]\u00a0\u548c\u00a0sensor2[i]\u00a0\u5206\u522b\u662f\u4e24\u4e2a\u4f20\u611f\u5668\u5bf9\u7b2c i \u4e2a\u6570\u636e\u70b9\u91c7\u96c6\u5230\u7684\u6570\u636e\u3002

\n\n

\u4f46\u662f\uff0c\u8fd9\u79cd\u7c7b\u578b\u7684\u4f20\u611f\u5668\u6709\u53ef\u80fd\u5b58\u5728\u7f3a\u9677\uff0c\u5b83\u4f1a\u5bfc\u81f4 \u67d0\u4e00\u4e2a \u6570\u636e\u70b9\u91c7\u96c6\u7684\u6570\u636e\uff08\u6389\u843d\u503c\uff09\u88ab\u4e22\u5f03\u3002

\n\n

\u6570\u636e\u88ab\u4e22\u5f03\u540e\uff0c\u6240\u6709\u5728\u5176\u53f3\u4fa7\u7684\u6570\u636e\u70b9\u91c7\u96c6\u7684\u6570\u636e\uff0c\u90fd\u4f1a\u88ab\u5411\u5de6\u79fb\u52a8\u4e00\u4e2a\u4f4d\u7f6e\uff0c\u6700\u540e\u4e00\u4e2a\u6570\u636e\u70b9\u91c7\u96c6\u7684\u6570\u636e\u4f1a\u88ab\u4e00\u4e9b\u968f\u673a\u503c\u66ff\u6362\u3002\u53ef\u4ee5\u4fdd\u8bc1\u6b64\u968f\u673a\u503c\u4e0d\u7b49\u4e8e\u6389\u843d\u503c\u3002

\n\n
    \n\t
  • \u4e3e\u4e2a\u4f8b\u5b50, \u5982\u679c\u6b63\u786e\u7684\u6570\u636e\u662f\u00a0[1,2,3,4,5]\u00a0\uff0c\u00a0\u6b64\u65f6 3 \u88ab\u4e22\u5f03\u4e86, \u4f20\u611f\u5668\u4f1a\u8fd4\u56de\u00a0[1,2,4,5,7] (\u6700\u540e\u7684\u4f4d\u7f6e\u53ef\u4ee5\u662f\u4efb\u4f55\u503c, \u4e0d\u4ec5\u4ec5\u662f\u00a07).
  • \n
\n\n

\u53ef\u4ee5\u786e\u5b9a\u7684\u662f\uff0c\u6700\u591a\u6709\u4e00\u4e2a \u4f20\u611f\u5668\u6709\u7f3a\u9677\u3002\u8bf7\u8fd4\u56de\u8fd9\u4e2a\u6709\u7f3a\u9677\u7684\u4f20\u611f\u5668\u7684\u7f16\u53f7 \uff081 \u6216 2\uff09\u3002\u5982\u679c\u4efb\u4e00\u4f20\u611f\u5668 \u6ca1\u6709\u7f3a\u9677 \uff0c\u6216\u8005 \u65e0\u6cd5 \u786e\u5b9a\u6709\u7f3a\u9677\u7684\u4f20\u611f\u5668\uff0c\u5219\u8fd4\u56de -1 \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1asensor1 = [2,3,4,5], sensor2 = [2,1,3,4]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u4f20\u611f\u5668 2 \u8fd4\u56de\u4e86\u6240\u6709\u6b63\u786e\u7684\u6570\u636e.\n\u4f20\u611f\u56682\u5bf9\u7b2c\u4e8c\u4e2a\u6570\u636e\u70b9\u91c7\u96c6\u7684\u6570\u636e\uff0c\u88ab\u4f20\u611f\u56681\u4e22\u5f03\u4e86\uff0c\u4f20\u611f\u56681\u8fd4\u56de\u7684\u6700\u540e\u4e00\u4e2a\u6570\u636e\u88ab\u66ff\u6362\u4e3a 5 \u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1asensor1 = [2,2,2,2,2], sensor2 = [2,2,2,2,5]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u65e0\u6cd5\u5224\u5b9a\u62ff\u4e2a\u4f20\u611f\u5668\u662f\u6709\u7f3a\u9677\u7684\u3002\n\u5047\u8bbe\u4efb\u4e00\u4f20\u611f\u5668\u4e22\u5f03\u7684\u6570\u636e\u662f\u6700\u540e\u4e00\u4f4d\uff0c\u90a3\u4e48\uff0c\u53e6\u4e00\u4e2a\u4f20\u611f\u5668\u5c31\u80fd\u7ed9\u51fa\u4e0e\u4e4b\u5bf9\u5e94\u7684\u8f93\u51fa\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1asensor1 = [2,3,2,2,3,2], sensor2 = [2,3,2,3,2,7]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u4f20\u611f\u5668 1 \u8fd4\u56de\u4e86\u6240\u6709\u6b63\u786e\u7684\u6570\u636e.\n\u4f20\u611f\u5668 1 \u5bf9\u7b2c\u56db\u4e2a\u6570\u636e\u70b9\u7684\u91c7\u96c6\u6570\u636e\uff0c\u88ab\u4f20\u611f\u56682\u4e22\u5931\u4e86, \u4f20\u611f\u5668 2 \u8fd4\u56de\u7684\u6700\u540e\u4e00\u4e2a\u6570\u636e\u88ab\u66ff\u6362\u4e3a 7 \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • sensor1.length == sensor2.length
  • \n\t
  • 1 <= sensor1.length <= 100
  • \n\t
  • 1 <= sensor1[i], sensor2[i] <= 100
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int badSensor(vector& sensor1, vector& sensor2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int badSensor(int[] sensor1, int[] sensor2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def badSensor(self, sensor1, sensor2):\n \"\"\"\n :type sensor1: List[int]\n :type sensor2: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def badSensor(self, sensor1: List[int], sensor2: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint badSensor(int* sensor1, int sensor1Size, int* sensor2, int sensor2Size){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int BadSensor(int[] sensor1, int[] sensor2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} sensor1\n * @param {number[]} sensor2\n * @return {number}\n */\nvar badSensor = function(sensor1, sensor2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} sensor1\n# @param {Integer[]} sensor2\n# @return {Integer}\ndef bad_sensor(sensor1, sensor2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func badSensor(_ sensor1: [Int], _ sensor2: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func badSensor(sensor1 []int, sensor2 []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def badSensor(sensor1: Array[Int], sensor2: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun badSensor(sensor1: IntArray, sensor2: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn bad_sensor(sensor1: Vec, sensor2: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $sensor1\n * @param Integer[] $sensor2\n * @return Integer\n */\n function badSensor($sensor1, $sensor2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function badSensor(sensor1: number[], sensor2: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (bad-sensor sensor1 sensor2)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1826](https://leetcode-cn.com/problems/faulty-sensor)", "[\u6709\u7f3a\u9677\u7684\u4f20\u611f\u5668](/solution/1800-1899/1826.Faulty%20Sensor/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1826](https://leetcode.com/problems/faulty-sensor)", "[Faulty Sensor](/solution/1800-1899/1826.Faulty%20Sensor/README_EN.md)", "`Array`", "Easy", "\ud83d\udd12"]}, {"question_id": "1978", "frontend_question_id": "1850", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-adjacent-swaps-to-reach-the-kth-smallest-number", "url_en": "https://leetcode.com/problems/minimum-adjacent-swaps-to-reach-the-kth-smallest-number", "relative_path_cn": "/solution/1800-1899/1850.Minimum%20Adjacent%20Swaps%20to%20Reach%20the%20Kth%20Smallest%20Number/README.md", "relative_path_en": "/solution/1800-1899/1850.Minimum%20Adjacent%20Swaps%20to%20Reach%20the%20Kth%20Smallest%20Number/README_EN.md", "title_cn": "\u90bb\u4f4d\u4ea4\u6362\u7684\u6700\u5c0f\u6b21\u6570", "title_en": "Minimum Adjacent Swaps to Reach the Kth Smallest Number", "question_title_slug": "minimum-adjacent-swaps-to-reach-the-kth-smallest-number", "content_en": "

You are given a string num, representing a large integer, and an integer k.

\n\n

We call some integer wonderful if it is a permutation of the digits in num and is greater in value than num. There can be many wonderful integers. However, we only care about the smallest-valued ones.

\n\n
    \n\t
  • For example, when num = "5489355142":\n\n\t
      \n\t\t
    • The 1st smallest wonderful integer is "5489355214".
    • \n\t\t
    • The 2nd smallest wonderful integer is "5489355241".
    • \n\t\t
    • The 3rd smallest wonderful integer is "5489355412".
    • \n\t\t
    • The 4th smallest wonderful integer is "5489355421".
    • \n\t
    \n\t
  • \n
\n\n

Return the minimum number of adjacent digit swaps that needs to be applied to num to reach the kth smallest wonderful integer.

\n\n

The tests are generated in such a way that kth smallest wonderful integer exists.

\n\n

 

\n

Example 1:

\n\n
\nInput: num = "5489355142", k = 4\nOutput: 2\nExplanation: The 4th smallest wonderful number is "5489355421". To get this number:\n- Swap index 7 with index 8: "5489355142" -> "5489355412"\n- Swap index 8 with index 9: "5489355412" -> "5489355421"\n
\n\n

Example 2:

\n\n
\nInput: num = "11112", k = 4\nOutput: 4\nExplanation: The 4th smallest wonderful number is "21111". To get this number:\n- Swap index 3 with index 4: "11112" -> "11121"\n- Swap index 2 with index 3: "11121" -> "11211"\n- Swap index 1 with index 2: "11211" -> "12111"\n- Swap index 0 with index 1: "12111" -> "21111"\n
\n\n

Example 3:

\n\n
\nInput: num = "00123", k = 1\nOutput: 1\nExplanation: The 1st smallest wonderful number is "00132". To get this number:\n- Swap index 3 with index 4: "00123" -> "00132"\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= num.length <= 1000
  • \n\t
  • 1 <= k <= 1000
  • \n\t
  • num only consists of digits.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u8868\u793a\u5927\u6574\u6570\u7684\u5b57\u7b26\u4e32 num \uff0c\u548c\u4e00\u4e2a\u6574\u6570 k \u3002

\n\n

\u5982\u679c\u67d0\u4e2a\u6574\u6570\u662f num \u4e2d\u5404\u4f4d\u6570\u5b57\u7684\u4e00\u4e2a \u6392\u5217 \u4e14\u5b83\u7684 \u503c\u5927\u4e8e num \uff0c\u5219\u79f0\u8fd9\u4e2a\u6574\u6570\u4e3a \u5999\u6570 \u3002\u53ef\u80fd\u5b58\u5728\u5f88\u591a\u5999\u6570\uff0c\u4f46\u662f\u53ea\u9700\u8981\u5173\u6ce8 \u503c\u6700\u5c0f \u7684\u90a3\u4e9b\u3002

\n\n
    \n\t
  • \u4f8b\u5982\uff0cnum = \"5489355142\" \uff1a\n\n\t
      \n\t\t
    • \u7b2c 1 \u4e2a\u6700\u5c0f\u5999\u6570\u662f \"5489355214\"
    • \n\t\t
    • \u7b2c 2 \u4e2a\u6700\u5c0f\u5999\u6570\u662f \"5489355241\"
    • \n\t\t
    • \u7b2c 3 \u4e2a\u6700\u5c0f\u5999\u6570\u662f \"5489355412\"
    • \n\t\t
    • \u7b2c 4 \u4e2a\u6700\u5c0f\u5999\u6570\u662f \"5489355421\"
    • \n\t
    \n\t
  • \n
\n\n

\u8fd4\u56de\u8981\u5f97\u5230\u7b2c k \u4e2a \u6700\u5c0f\u5999\u6570 \u9700\u8981\u5bf9 num \u6267\u884c\u7684 \u76f8\u90bb\u4f4d\u6570\u5b57\u4ea4\u6362\u7684\u6700\u5c0f\u6b21\u6570 \u3002

\n\n

\u6d4b\u8bd5\u7528\u4f8b\u662f\u6309\u5b58\u5728\u7b2c k \u4e2a\u6700\u5c0f\u5999\u6570\u800c\u751f\u6210\u7684\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anum = \"5489355142\", k = 4\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u7b2c 4 \u4e2a\u6700\u5c0f\u5999\u6570\u662f \"5489355421\" \uff0c\u8981\u60f3\u5f97\u5230\u8fd9\u4e2a\u6570\u5b57\uff1a\n- \u4ea4\u6362\u4e0b\u6807 7 \u548c\u4e0b\u6807 8 \u5bf9\u5e94\u7684\u4f4d\uff1a\"5489355142\" -> \"5489355412\"\n- \u4ea4\u6362\u4e0b\u6807 8 \u548c\u4e0b\u6807 9 \u5bf9\u5e94\u7684\u4f4d\uff1a\"5489355412\" -> \"5489355421\"\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anum = \"11112\", k = 4\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u7b2c 4 \u4e2a\u6700\u5c0f\u5999\u6570\u662f \"21111\" \uff0c\u8981\u60f3\u5f97\u5230\u8fd9\u4e2a\u6570\u5b57\uff1a\n- \u4ea4\u6362\u4e0b\u6807 3 \u548c\u4e0b\u6807 4 \u5bf9\u5e94\u7684\u4f4d\uff1a\"11112\" -> \"11121\"\n- \u4ea4\u6362\u4e0b\u6807 2 \u548c\u4e0b\u6807 3 \u5bf9\u5e94\u7684\u4f4d\uff1a\"11121\" -> \"11211\"\n- \u4ea4\u6362\u4e0b\u6807 1 \u548c\u4e0b\u6807 2 \u5bf9\u5e94\u7684\u4f4d\uff1a\"11211\" -> \"12111\"\n- \u4ea4\u6362\u4e0b\u6807 0 \u548c\u4e0b\u6807 1 \u5bf9\u5e94\u7684\u4f4d\uff1a\"12111\" -> \"21111\"\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1anum = \"00123\", k = 1\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u7b2c 1 \u4e2a\u6700\u5c0f\u5999\u6570\u662f \"00132\" \uff0c\u8981\u60f3\u5f97\u5230\u8fd9\u4e2a\u6570\u5b57\uff1a\n- \u4ea4\u6362\u4e0b\u6807 3 \u548c\u4e0b\u6807 4 \u5bf9\u5e94\u7684\u4f4d\uff1a\"00123\" -> \"00132\"\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= num.length <= 1000
  • \n\t
  • 1 <= k <= 1000
  • \n\t
  • num \u4ec5\u7531\u6570\u5b57\u7ec4\u6210
  • \n
\n", "tags_en": ["Greedy", "String"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int getMinSwaps(string num, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int getMinSwaps(String num, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getMinSwaps(self, num, k):\n \"\"\"\n :type num: str\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getMinSwaps(self, num: str, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint getMinSwaps(char * num, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int GetMinSwaps(string num, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} num\n * @param {number} k\n * @return {number}\n */\nvar getMinSwaps = function(num, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} num\n# @param {Integer} k\n# @return {Integer}\ndef get_min_swaps(num, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getMinSwaps(_ num: String, _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getMinSwaps(num string, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getMinSwaps(num: String, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getMinSwaps(num: String, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_min_swaps(num: String, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $num\n * @param Integer $k\n * @return Integer\n */\n function getMinSwaps($num, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getMinSwaps(num: string, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-min-swaps num k)\n (-> string? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1850](https://leetcode-cn.com/problems/minimum-adjacent-swaps-to-reach-the-kth-smallest-number)", "[\u90bb\u4f4d\u4ea4\u6362\u7684\u6700\u5c0f\u6b21\u6570](/solution/1800-1899/1850.Minimum%20Adjacent%20Swaps%20to%20Reach%20the%20Kth%20Smallest%20Number/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1850](https://leetcode.com/problems/minimum-adjacent-swaps-to-reach-the-kth-smallest-number)", "[Minimum Adjacent Swaps to Reach the Kth Smallest Number](/solution/1800-1899/1850.Minimum%20Adjacent%20Swaps%20to%20Reach%20the%20Kth%20Smallest%20Number/README_EN.md)", "`Greedy`,`String`", "Medium", ""]}, {"question_id": "1977", "frontend_question_id": "1851", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-interval-to-include-each-query", "url_en": "https://leetcode.com/problems/minimum-interval-to-include-each-query", "relative_path_cn": "/solution/1800-1899/1851.Minimum%20Interval%20to%20Include%20Each%20Query/README.md", "relative_path_en": "/solution/1800-1899/1851.Minimum%20Interval%20to%20Include%20Each%20Query/README_EN.md", "title_cn": "\u5305\u542b\u6bcf\u4e2a\u67e5\u8be2\u7684\u6700\u5c0f\u533a\u95f4", "title_en": "Minimum Interval to Include Each Query", "question_title_slug": "minimum-interval-to-include-each-query", "content_en": "

You are given a 2D integer array intervals, where intervals[i] = [lefti, righti] describes the ith interval starting at lefti and ending at righti (inclusive). The size of an interval is defined as the number of integers it contains, or more formally righti - lefti + 1.

\n\n

You are also given an integer array queries. The answer to the jth query is the size of the smallest interval i such that lefti <= queries[j] <= righti. If no such interval exists, the answer is -1.

\n\n

Return an array containing the answers to the queries.

\n\n

 

\n

Example 1:

\n\n
\nInput: intervals = [[1,4],[2,4],[3,6],[4,4]], queries = [2,3,4,5]\nOutput: [3,3,1,4]\nExplanation: The queries are processed as follows:\n- Query = 2: The interval [2,4] is the smallest interval containing 2. The answer is 4 - 2 + 1 = 3.\n- Query = 3: The interval [2,4] is the smallest interval containing 3. The answer is 4 - 2 + 1 = 3.\n- Query = 4: The interval [4,4] is the smallest interval containing 4. The answer is 4 - 4 + 1 = 1.\n- Query = 5: The interval [3,6] is the smallest interval containing 5. The answer is 6 - 3 + 1 = 4.\n
\n\n

Example 2:

\n\n
\nInput: intervals = [[2,3],[2,5],[1,8],[20,25]], queries = [2,19,5,22]\nOutput: [2,-1,4,6]\nExplanation: The queries are processed as follows:\n- Query = 2: The interval [2,3] is the smallest interval containing 2. The answer is 3 - 2 + 1 = 2.\n- Query = 19: None of the intervals contain 19. The answer is -1.\n- Query = 5: The interval [2,5] is the smallest interval containing 5. The answer is 5 - 2 + 1 = 4.\n- Query = 22: The interval [20,25] is the smallest interval containing 22. The answer is 25 - 20 + 1 = 6.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= intervals.length <= 105
  • \n\t
  • 1 <= queries.length <= 105
  • \n\t
  • intervals[i].length == 2
  • \n\t
  • 1 <= lefti <= righti <= 107
  • \n\t
  • 1 <= queries[j] <= 107
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u4e8c\u7ef4\u6574\u6570\u6570\u7ec4 intervals \uff0c\u5176\u4e2d intervals[i] = [lefti, righti] \u8868\u793a\u7b2c i \u4e2a\u533a\u95f4\u5f00\u59cb\u4e8e lefti \u3001\u7ed3\u675f\u4e8e righti\uff08\u5305\u542b\u4e24\u4fa7\u53d6\u503c\uff0c\u95ed\u533a\u95f4\uff09\u3002\u533a\u95f4\u7684 \u957f\u5ea6 \u5b9a\u4e49\u4e3a\u533a\u95f4\u4e2d\u5305\u542b\u7684\u6574\u6570\u6570\u76ee\uff0c\u66f4\u6b63\u5f0f\u5730\u8868\u8fbe\u662f righti - lefti + 1 \u3002

\n\n

\u518d\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 queries \u3002\u7b2c j \u4e2a\u67e5\u8be2\u7684\u7b54\u6848\u662f\u6ee1\u8db3\u00a0lefti <= queries[j] <= righti \u7684 \u957f\u5ea6\u6700\u5c0f\u533a\u95f4 i \u7684\u957f\u5ea6 \u3002\u5982\u679c\u4e0d\u5b58\u5728\u8fd9\u6837\u7684\u533a\u95f4\uff0c\u90a3\u4e48\u7b54\u6848\u662f -1 \u3002

\n\n

\u4ee5\u6570\u7ec4\u5f62\u5f0f\u8fd4\u56de\u5bf9\u5e94\u67e5\u8be2\u7684\u6240\u6709\u7b54\u6848\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aintervals = [[1,4],[2,4],[3,6],[4,4]], queries = [2,3,4,5]\n\u8f93\u51fa\uff1a[3,3,1,4]\n\u89e3\u91ca\uff1a\u67e5\u8be2\u5904\u7406\u5982\u4e0b\uff1a\n- Query = 2 \uff1a\u533a\u95f4 [2,4] \u662f\u5305\u542b 2 \u7684\u6700\u5c0f\u533a\u95f4\uff0c\u7b54\u6848\u4e3a 4 - 2 + 1 = 3 \u3002\n- Query = 3 \uff1a\u533a\u95f4 [2,4] \u662f\u5305\u542b 3 \u7684\u6700\u5c0f\u533a\u95f4\uff0c\u7b54\u6848\u4e3a 4 - 2 + 1 = 3 \u3002\n- Query = 4 \uff1a\u533a\u95f4 [4,4] \u662f\u5305\u542b 4 \u7684\u6700\u5c0f\u533a\u95f4\uff0c\u7b54\u6848\u4e3a 4 - 4 + 1 = 1 \u3002\n- Query = 5 \uff1a\u533a\u95f4 [3,6] \u662f\u5305\u542b 5 \u7684\u6700\u5c0f\u533a\u95f4\uff0c\u7b54\u6848\u4e3a 6 - 3 + 1 = 4 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aintervals = [[2,3],[2,5],[1,8],[20,25]], queries = [2,19,5,22]\n\u8f93\u51fa\uff1a[2,-1,4,6]\n\u89e3\u91ca\uff1a\u67e5\u8be2\u5904\u7406\u5982\u4e0b\uff1a\n- Query = 2 \uff1a\u533a\u95f4 [2,3] \u662f\u5305\u542b 2 \u7684\u6700\u5c0f\u533a\u95f4\uff0c\u7b54\u6848\u4e3a 3 - 2 + 1 = 2 \u3002\n- Query = 19\uff1a\u4e0d\u5b58\u5728\u5305\u542b 19 \u7684\u533a\u95f4\uff0c\u7b54\u6848\u4e3a -1 \u3002\n- Query = 5 \uff1a\u533a\u95f4 [2,5] \u662f\u5305\u542b 5 \u7684\u6700\u5c0f\u533a\u95f4\uff0c\u7b54\u6848\u4e3a 5 - 2 + 1 = 4 \u3002\n- Query = 22\uff1a\u533a\u95f4 [20,25] \u662f\u5305\u542b 22 \u7684\u6700\u5c0f\u533a\u95f4\uff0c\u7b54\u6848\u4e3a 25 - 20 + 1 = 6 \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= intervals.length <= 105
  • \n\t
  • 1 <= queries.length <= 105
  • \n\t
  • queries[i].length == 2
  • \n\t
  • 1 <= lefti <= righti <= 107
  • \n\t
  • 1 <= queries[j] <= 107
  • \n
\n", "tags_en": ["Line Sweep"], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector minInterval(vector>& intervals, vector& queries) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] minInterval(int[][] intervals, int[] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minInterval(self, intervals, queries):\n \"\"\"\n :type intervals: List[List[int]]\n :type queries: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minInterval(self, intervals: List[List[int]], queries: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* minInterval(int** intervals, int intervalsSize, int* intervalsColSize, int* queries, int queriesSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] MinInterval(int[][] intervals, int[] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} intervals\n * @param {number[]} queries\n * @return {number[]}\n */\nvar minInterval = function(intervals, queries) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} intervals\n# @param {Integer[]} queries\n# @return {Integer[]}\ndef min_interval(intervals, queries)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minInterval(_ intervals: [[Int]], _ queries: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minInterval(intervals [][]int, queries []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minInterval(intervals: Array[Array[Int]], queries: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minInterval(intervals: Array, queries: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_interval(intervals: Vec>, queries: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $intervals\n * @param Integer[] $queries\n * @return Integer[]\n */\n function minInterval($intervals, $queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minInterval(intervals: number[][], queries: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-interval intervals queries)\n (-> (listof (listof exact-integer?)) (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1851](https://leetcode-cn.com/problems/minimum-interval-to-include-each-query)", "[\u5305\u542b\u6bcf\u4e2a\u67e5\u8be2\u7684\u6700\u5c0f\u533a\u95f4](/solution/1800-1899/1851.Minimum%20Interval%20to%20Include%20Each%20Query/README.md)", "", "\u56f0\u96be", ""], "md_table_row_en": ["[1851](https://leetcode.com/problems/minimum-interval-to-include-each-query)", "[Minimum Interval to Include Each Query](/solution/1800-1899/1851.Minimum%20Interval%20to%20Include%20Each%20Query/README_EN.md)", "`Line Sweep`", "Hard", ""]}, {"question_id": "1976", "frontend_question_id": "1849", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/splitting-a-string-into-descending-consecutive-values", "url_en": "https://leetcode.com/problems/splitting-a-string-into-descending-consecutive-values", "relative_path_cn": "/solution/1800-1899/1849.Splitting%20a%20String%20Into%20Descending%20Consecutive%20Values/README.md", "relative_path_en": "/solution/1800-1899/1849.Splitting%20a%20String%20Into%20Descending%20Consecutive%20Values/README_EN.md", "title_cn": "\u5c06\u5b57\u7b26\u4e32\u62c6\u5206\u4e3a\u9012\u51cf\u7684\u8fde\u7eed\u503c", "title_en": "Splitting a String Into Descending Consecutive Values", "question_title_slug": "splitting-a-string-into-descending-consecutive-values", "content_en": "

You are given a string s that consists of only digits.

\n\n

Check if we can split s into two or more non-empty substrings such that the numerical values of the substrings are in descending order and the difference between numerical values of every two adjacent substrings is equal to 1.

\n\n
    \n\t
  • For example, the string s = "0090089" can be split into ["0090", "089"] with numerical values [90,89]. The values are in descending order and adjacent values differ by 1, so this way is valid.
  • \n\t
  • Another example, the string s = "001" can be split into ["0", "01"], ["00", "1"], or ["0", "0", "1"]. However all the ways are invalid because they have numerical values [0,1], [0,1], and [0,0,1] respectively, all of which are not in descending order.
  • \n
\n\n

Return true if it is possible to split s\u200b\u200b\u200b\u200b\u200b\u200b as described above, or false otherwise.

\n\n

A substring is a contiguous sequence of characters in a string.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "1234"\nOutput: false\nExplanation: There is no valid way to split s.\n
\n\n

Example 2:

\n\n
\nInput: s = "050043"\nOutput: true\nExplanation: s can be split into ["05", "004", "3"] with numerical values [5,4,3].\nThe values are in descending order with adjacent values differing by 1.\n
\n\n

Example 3:

\n\n
\nInput: s = "9080701"\nOutput: false\nExplanation: There is no valid way to split s.\n
\n\n

Example 4:

\n\n
\nInput: s = "10009998"\nOutput: true\nExplanation: s can be split into ["100", "099", "98"] with numerical values [100,99,98].\nThe values are in descending order with adjacent values differing by 1.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 20
  • \n\t
  • s only consists of digits.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u4ec5\u7531\u6570\u5b57\u7ec4\u6210\u7684\u5b57\u7b26\u4e32 s \u3002

\n\n

\u8bf7\u4f60\u5224\u65ad\u80fd\u5426\u5c06 s \u62c6\u5206\u6210\u4e24\u4e2a\u6216\u8005\u591a\u4e2a \u975e\u7a7a\u5b50\u5b57\u7b26\u4e32 \uff0c\u4f7f\u5b50\u5b57\u7b26\u4e32\u7684 \u6570\u503c \u6309 \u964d\u5e8f \u6392\u5217\uff0c\u4e14\u6bcf\u4e24\u4e2a \u76f8\u90bb\u5b50\u5b57\u7b26\u4e32 \u7684\u6570\u503c\u4e4b \u5dee \u7b49\u4e8e 1 \u3002

\n\n
    \n\t
  • \u4f8b\u5982\uff0c\u5b57\u7b26\u4e32 s = \"0090089\" \u53ef\u4ee5\u62c6\u5206\u6210 [\"0090\", \"089\"] \uff0c\u6570\u503c\u4e3a [90,89] \u3002\u8fd9\u4e9b\u6570\u503c\u6ee1\u8db3\u6309\u964d\u5e8f\u6392\u5217\uff0c\u4e14\u76f8\u90bb\u503c\u76f8\u5dee 1 \uff0c\u8fd9\u79cd\u62c6\u5206\u65b9\u6cd5\u53ef\u884c\u3002
  • \n\t
  • \u53e6\u4e00\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u5b57\u7b26\u4e32 s = \"001\" \u53ef\u4ee5\u62c6\u5206\u6210 [\"0\", \"01\"]\u3001[\"00\", \"1\"] \u6216 [\"0\", \"0\", \"1\"] \u3002\u7136\u800c\uff0c\u6240\u6709\u8fd9\u4e9b\u62c6\u5206\u65b9\u6cd5\u90fd\u4e0d\u53ef\u884c\uff0c\u56e0\u4e3a\u5bf9\u5e94\u6570\u503c\u5206\u522b\u662f [0,1]\u3001[0,1] \u548c [0,0,1] \uff0c\u90fd\u4e0d\u6ee1\u8db3\u6309\u964d\u5e8f\u6392\u5217\u7684\u8981\u6c42\u3002
  • \n
\n\n

\u5982\u679c\u53ef\u4ee5\u6309\u8981\u6c42\u62c6\u5206 s \uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

\n\n

\u5b50\u5b57\u7b26\u4e32 \u662f\u5b57\u7b26\u4e32\u4e2d\u7684\u4e00\u4e2a\u8fde\u7eed\u5b57\u7b26\u5e8f\u5217\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"1234\"\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u4e0d\u5b58\u5728\u62c6\u5206 s \u7684\u53ef\u884c\u65b9\u6cd5\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"050043\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1as \u53ef\u4ee5\u62c6\u5206\u4e3a [\"05\", \"004\", \"3\"] \uff0c\u5bf9\u5e94\u6570\u503c\u4e3a [5,4,3] \u3002\n\u6ee1\u8db3\u6309\u964d\u5e8f\u6392\u5217\uff0c\u4e14\u76f8\u90bb\u503c\u76f8\u5dee 1 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"9080701\"\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u4e0d\u5b58\u5728\u62c6\u5206 s \u7684\u53ef\u884c\u65b9\u6cd5\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"10009998\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1as \u53ef\u4ee5\u62c6\u5206\u4e3a [\"100\", \"099\", \"98\"] \uff0c\u5bf9\u5e94\u6570\u503c\u4e3a [100,99,98] \u3002\n\u6ee1\u8db3\u6309\u964d\u5e8f\u6392\u5217\uff0c\u4e14\u76f8\u90bb\u503c\u76f8\u5dee 1 \u3002
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length <= 20
  • \n\t
  • s \u4ec5\u7531\u6570\u5b57\u7ec4\u6210
  • \n
\n", "tags_en": ["Recursion", "String", "Backtracking"], "tags_cn": ["\u9012\u5f52", "\u5b57\u7b26\u4e32", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool splitString(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean splitString(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def splitString(self, s):\n \"\"\"\n :type s: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def splitString(self, s: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool splitString(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool SplitString(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {boolean}\n */\nvar splitString = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Boolean}\ndef split_string(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func splitString(_ s: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func splitString(s string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def splitString(s: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun splitString(s: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn split_string(s: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Boolean\n */\n function splitString($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function splitString(s: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (split-string s)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1849](https://leetcode-cn.com/problems/splitting-a-string-into-descending-consecutive-values)", "[\u5c06\u5b57\u7b26\u4e32\u62c6\u5206\u4e3a\u9012\u51cf\u7684\u8fde\u7eed\u503c](/solution/1800-1899/1849.Splitting%20a%20String%20Into%20Descending%20Consecutive%20Values/README.md)", "`\u9012\u5f52`,`\u5b57\u7b26\u4e32`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1849](https://leetcode.com/problems/splitting-a-string-into-descending-consecutive-values)", "[Splitting a String Into Descending Consecutive Values](/solution/1800-1899/1849.Splitting%20a%20String%20Into%20Descending%20Consecutive%20Values/README_EN.md)", "`Recursion`,`String`,`Backtracking`", "Medium", ""]}, {"question_id": "1975", "frontend_question_id": "1848", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-distance-to-the-target-element", "url_en": "https://leetcode.com/problems/minimum-distance-to-the-target-element", "relative_path_cn": "/solution/1800-1899/1848.Minimum%20Distance%20to%20the%20Target%20Element/README.md", "relative_path_en": "/solution/1800-1899/1848.Minimum%20Distance%20to%20the%20Target%20Element/README_EN.md", "title_cn": "\u5230\u76ee\u6807\u5143\u7d20\u7684\u6700\u5c0f\u8ddd\u79bb", "title_en": "Minimum Distance to the Target Element", "question_title_slug": "minimum-distance-to-the-target-element", "content_en": "

Given an integer array nums (0-indexed) and two integers target and start, find an index i such that nums[i] == target and abs(i - start) is minimized. Note that abs(x) is the absolute value of x.

\n\n

Return abs(i - start).

\n\n

It is guaranteed that target exists in nums.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [1,2,3,4,5], target = 5, start = 3\nOutput: 1\nExplanation: nums[4] = 5 is the only value equal to target, so the answer is abs(4 - 3) = 1.\n
\n\n

Example 2:

\n\n
\nInput: nums = [1], target = 1, start = 0\nOutput: 0\nExplanation: nums[0] = 1 is the only value equal to target, so the answer is abs(0 - 0) = 0.\n
\n\n

Example 3:

\n\n
\nInput: nums = [1,1,1,1,1,1,1,1,1,1], target = 1, start = 0\nOutput: 0\nExplanation: Every value of nums is 1, but nums[0] minimizes abs(i - start), which is abs(0 - 0) = 0.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 1000
  • \n\t
  • 1 <= nums[i] <= 104
  • \n\t
  • 0 <= start < nums.length
  • \n\t
  • target is in nums.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \uff08\u4e0b\u6807 \u4ece 0 \u5f00\u59cb \u8ba1\u6570\uff09\u4ee5\u53ca\u4e24\u4e2a\u6574\u6570 target \u548c start \uff0c\u8bf7\u4f60\u627e\u51fa\u4e00\u4e2a\u4e0b\u6807 i \uff0c\u6ee1\u8db3 nums[i] == target \u4e14 abs(i - start) \u6700\u5c0f\u5316 \u3002\u6ce8\u610f\uff1aabs(x) \u8868\u793a x \u7684\u7edd\u5bf9\u503c\u3002

\n\n

\u8fd4\u56de abs(i - start) \u3002

\n\n

\u9898\u76ee\u6570\u636e\u4fdd\u8bc1 target \u5b58\u5728\u4e8e nums \u4e2d\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [1,2,3,4,5], target = 5, start = 3\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1anums[4] = 5 \u662f\u552f\u4e00\u4e00\u4e2a\u7b49\u4e8e target \u7684\u503c\uff0c\u6240\u4ee5\u7b54\u6848\u662f abs(4 - 3) = 1 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [1], target = 1, start = 0\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1anums[0] = 1 \u662f\u552f\u4e00\u4e00\u4e2a\u7b49\u4e8e target \u7684\u503c\uff0c\u6240\u4ee5\u7b54\u6848\u662f abs(0 - 0) = 0 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [1,1,1,1,1,1,1,1,1,1], target = 1, start = 0\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1anums \u4e2d\u7684\u6bcf\u4e2a\u503c\u90fd\u662f 1 \uff0c\u4f46 nums[0] \u4f7f abs(i - start) \u7684\u7ed3\u679c\u5f97\u4ee5\u6700\u5c0f\u5316\uff0c\u6240\u4ee5\u7b54\u6848\u662f abs(0 - 0) = 0 \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 1000
  • \n\t
  • 1 <= nums[i] <= 104
  • \n\t
  • 0 <= start < nums.length
  • \n\t
  • target \u5b58\u5728\u4e8e nums \u4e2d
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int getMinDistance(vector& nums, int target, int start) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int getMinDistance(int[] nums, int target, int start) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getMinDistance(self, nums, target, start):\n \"\"\"\n :type nums: List[int]\n :type target: int\n :type start: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getMinDistance(self, nums: List[int], target: int, start: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint getMinDistance(int* nums, int numsSize, int target, int start){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int GetMinDistance(int[] nums, int target, int start) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} target\n * @param {number} start\n * @return {number}\n */\nvar getMinDistance = function(nums, target, start) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} target\n# @param {Integer} start\n# @return {Integer}\ndef get_min_distance(nums, target, start)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getMinDistance(_ nums: [Int], _ target: Int, _ start: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getMinDistance(nums []int, target int, start int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getMinDistance(nums: Array[Int], target: Int, start: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getMinDistance(nums: IntArray, target: Int, start: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_min_distance(nums: Vec, target: i32, start: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $target\n * @param Integer $start\n * @return Integer\n */\n function getMinDistance($nums, $target, $start) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getMinDistance(nums: number[], target: number, start: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-min-distance nums target start)\n (-> (listof exact-integer?) exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1848](https://leetcode-cn.com/problems/minimum-distance-to-the-target-element)", "[\u5230\u76ee\u6807\u5143\u7d20\u7684\u6700\u5c0f\u8ddd\u79bb](/solution/1800-1899/1848.Minimum%20Distance%20to%20the%20Target%20Element/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1848](https://leetcode.com/problems/minimum-distance-to-the-target-element)", "[Minimum Distance to the Target Element](/solution/1800-1899/1848.Minimum%20Distance%20to%20the%20Target%20Element/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1974", "frontend_question_id": "1821", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/find-customers-with-positive-revenue-this-year", "url_en": "https://leetcode.com/problems/find-customers-with-positive-revenue-this-year", "relative_path_cn": "/solution/1800-1899/1821.Find%20Customers%20With%20Positive%20Revenue%20this%20Year/README.md", "relative_path_en": "/solution/1800-1899/1821.Find%20Customers%20With%20Positive%20Revenue%20this%20Year/README_EN.md", "title_cn": "\u5bfb\u627e\u4eca\u5e74\u5177\u6709\u6b63\u6536\u5165\u7684\u5ba2\u6237", "title_en": "Find Customers With Positive Revenue this Year", "question_title_slug": "find-customers-with-positive-revenue-this-year", "content_en": "

Table: Customers

\n\n
\n+--------------+------+\n| Column Name  | Type |\n+--------------+------+\n| customer_id  | int  |\n| year         | int  |\n| revenue      | int  |\n+--------------+------+\n(customer_id, year) is the primary key for this table.\nThis table contains the customer ID and the revenue of customers in different years.\nNote that this revenue can be negative.\n
\n\n

 

\n\n

Write an SQL query to report the customers with postive revenue in the year 2021.

\n\n

Return the result table in any order.

\n\n

The query result format is in the following example:

\n\n

 

\n\n
\nCustomers\n+-------------+------+---------+\n| customer_id | year | revenue |\n+-------------+------+---------+\n| 1           | 2018 | 50      |\n| 1           | 2021 | 30      |\n| 1           | 2020 | 70      |\n| 2           | 2021 | -50     |\n| 3           | 2018 | 10      |\n| 3           | 2016 | 50      |\n| 4           | 2021 | 20      |\n+-------------+------+---------+\n\nResult table:\n+-------------+\n| customer_id |\n+-------------+\n| 1           |\n| 4           |\n+-------------+\n\nCustomer 1 has revenue equal to 30 in year 2021.\nCustomer 2 has revenue equal to -50 in year 2021.\nCustomer 3 has no revenue in year 2021.\nCustomer 4 has revenue equal to 20 in year 2021.\nThus only customers 1 and 4 have postive revenue in year 2021.
\n", "content_cn": "

\u8868\uff1aCustomers

\n\n
\n+--------------+------+\n| Column Name  | Type |\n+--------------+------+\n| customer_id  | int  |\n| year         | int  |\n| revenue      | int  |\n+--------------+------+\n(customer_id, year) \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\u3002\n\u8fd9\u4e2a\u8868\u5305\u542b\u5ba2\u6237 ID \u548c\u4e0d\u540c\u5e74\u4efd\u7684\u5ba2\u6237\u6536\u5165\u3002\n\u6ce8\u610f\uff0c\u8fd9\u4e2a\u6536\u5165\u53ef\u80fd\u662f\u8d1f\u6570\u3002\n
\n\n

\u00a0

\n\n

\u5199\u4e00\u4e2a SQL \u67e5\u8be2\u6765\u67e5\u8be2 2021 \u5e74\u5177\u6709 \u6b63\u6536\u5165 \u7684\u5ba2\u6237\u3002

\n\n

\u53ef\u4ee5\u6309 \u4efb\u610f\u987a\u5e8f \u8fd4\u56de\u7ed3\u679c\u8868\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u3002

\n\n

\u00a0

\n\n
\nCustomers\n+-------------+------+---------+\n| customer_id | year | revenue |\n+-------------+------+---------+\n| 1           | 2018 | 50      |\n| 1           | 2021 | 30      |\n| 1           | 2020 | 70      |\n| 2           | 2021 | -50     |\n| 3           | 2018 | 10      |\n| 3           | 2016 | 50      |\n| 4           | 2021 | 20      |\n+-------------+------+---------+\n\nResult table:\n+-------------+\n| customer_id |\n+-------------+\n| 1           |\n| 4           |\n+-------------+\n\u5ba2\u6237 1 \u5728 2021 \u5e74\u7684\u6536\u5165\u7b49\u4e8e 30 \u3002\n\u5ba2\u6237 2 \u5728 2021 \u5e74\u7684\u6536\u5165\u7b49\u4e8e -50 \u3002\n\u5ba2\u6237 3 \u5728 2021 \u5e74\u6ca1\u6709\u6536\u5165\u3002\n\u5ba2\u6237 4 \u5728 2021 \u5e74\u7684\u6536\u5165\u7b49\u4e8e 20 \u3002\n\u56e0\u6b64\uff0c\u53ea\u6709\u5ba2\u6237 1 \u548c 4 \u5728 2021 \u5e74\u6709\u6b63\u6536\u5165\u3002
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1821](https://leetcode-cn.com/problems/find-customers-with-positive-revenue-this-year)", "[\u5bfb\u627e\u4eca\u5e74\u5177\u6709\u6b63\u6536\u5165\u7684\u5ba2\u6237](/solution/1800-1899/1821.Find%20Customers%20With%20Positive%20Revenue%20this%20Year/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1821](https://leetcode.com/problems/find-customers-with-positive-revenue-this-year)", "[Find Customers With Positive Revenue this Year](/solution/1800-1899/1821.Find%20Customers%20With%20Positive%20Revenue%20this%20Year/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1972", "frontend_question_id": "1861", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/rotating-the-box", "url_en": "https://leetcode.com/problems/rotating-the-box", "relative_path_cn": "/solution/1800-1899/1861.Rotating%20the%20Box/README.md", "relative_path_en": "/solution/1800-1899/1861.Rotating%20the%20Box/README_EN.md", "title_cn": "\u65cb\u8f6c\u76d2\u5b50", "title_en": "Rotating the Box", "question_title_slug": "rotating-the-box", "content_en": "

You are given an m x n matrix of characters box representing a side-view of a box. Each cell of the box is one of the following:

\r\n\r\n
    \r\n\t
  • A stone '#'
  • \r\n\t
  • A stationary obstacle '*'
  • \r\n\t
  • Empty '.'
  • \r\n
\r\n\r\n

The box is rotated 90 degrees clockwise, causing some of the stones to fall due to gravity. Each stone falls down until it lands on an obstacle, another stone, or the bottom of the box. Gravity does not affect the obstacles' positions, and the inertia from the box's rotation does not affect the stones' horizontal positions.

\r\n\r\n

It is guaranteed that each stone in box rests on an obstacle, another stone, or the bottom of the box.

\r\n\r\n

Return an n x m matrix representing the box after the rotation described above.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n

\"\"

\r\n\r\n
\r\nInput: box = [["#",".","#"]]\r\nOutput: [["."],\r\n         ["#"],\r\n         ["#"]]\r\n
\r\n\r\n

Example 2:

\r\n\r\n

\"\"

\r\n\r\n
\r\nInput: box = [["#",".","*","."],\r\n              ["#","#","*","."]]\r\nOutput: [["#","."],\r\n         ["#","#"],\r\n         ["*","*"],\r\n         [".","."]]\r\n
\r\n\r\n

Example 3:

\r\n\r\n

\"\"

\r\n\r\n
\r\nInput: box = [["#","#","*",".","*","."],\r\n              ["#","#","#","*",".","."],\r\n              ["#","#","#",".","#","."]]\r\nOutput: [[".","#","#"],\r\n         [".","#","#"],\r\n         ["#","#","*"],\r\n         ["#","*","."],\r\n         ["#",".","*"],\r\n         ["#",".","."]]\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • m == box.length
  • \r\n\t
  • n == box[i].length
  • \r\n\t
  • 1 <= m, n <= 500
  • \r\n\t
  • box[i][j] is either '#', '*', or '.'.
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u00a0m x n\u00a0\u7684\u5b57\u7b26\u77e9\u9635\u00a0box\u00a0\uff0c\u5b83\u8868\u793a\u4e00\u4e2a\u7bb1\u5b50\u7684\u4fa7\u89c6\u56fe\u3002\u7bb1\u5b50\u7684\u6bcf\u4e00\u4e2a\u683c\u5b50\u53ef\u80fd\u4e3a\uff1a

\n\n
    \n\t
  • '#'\u00a0\u8868\u793a\u77f3\u5934
  • \n\t
  • '*'\u00a0\u8868\u793a\u56fa\u5b9a\u7684\u969c\u788d\u7269
  • \n\t
  • '.'\u00a0\u8868\u793a\u7a7a\u4f4d\u7f6e
  • \n
\n\n

\u8fd9\u4e2a\u7bb1\u5b50\u88ab \u987a\u65f6\u9488\u65cb\u8f6c 90 \u5ea6\u00a0\uff0c\u7531\u4e8e\u91cd\u529b\u539f\u56e0\uff0c\u90e8\u5206\u77f3\u5934\u7684\u4f4d\u7f6e\u4f1a\u53d1\u751f\u6539\u53d8\u3002\u6bcf\u4e2a\u77f3\u5934\u4f1a\u5782\u76f4\u6389\u843d\uff0c\u76f4\u5230\u5b83\u9047\u5230\u969c\u788d\u7269\uff0c\u53e6\u4e00\u4e2a\u77f3\u5934\u6216\u8005\u7bb1\u5b50\u7684\u5e95\u90e8\u3002\u91cd\u529b \u4e0d\u4f1a\u00a0\u5f71\u54cd\u969c\u788d\u7269\u7684\u4f4d\u7f6e\uff0c\u540c\u65f6\u7bb1\u5b50\u65cb\u8f6c\u4e0d\u4f1a\u4ea7\u751f\u60ef\u6027\u00a0\uff0c\u4e5f\u5c31\u662f\u8bf4\u77f3\u5934\u7684\u6c34\u5e73\u4f4d\u7f6e\u4e0d\u4f1a\u53d1\u751f\u6539\u53d8\u3002

\n\n

\u9898\u76ee\u4fdd\u8bc1\u521d\u59cb\u65f6\u00a0box\u00a0\u4e2d\u7684\u77f3\u5934\u8981\u4e48\u5728\u4e00\u4e2a\u969c\u788d\u7269\u4e0a\uff0c\u8981\u4e48\u5728\u53e6\u4e00\u4e2a\u77f3\u5934\u4e0a\uff0c\u8981\u4e48\u5728\u7bb1\u5b50\u7684\u5e95\u90e8\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u4e00\u4e2a\u00a0n x m\u7684\u77e9\u9635\uff0c\u8868\u793a\u6309\u7167\u4e0a\u8ff0\u65cb\u8f6c\u540e\uff0c\u7bb1\u5b50\u5185\u7684\u7ed3\u679c\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1abox = [[\"#\",\".\",\"#\"]]\n\u8f93\u51fa\uff1a[[\".\"],\n\u00a0     [\"#\"],\n\u00a0     [\"#\"]]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1abox = [[\"#\",\".\",\"*\",\".\"],\n\u00a0           [\"#\",\"#\",\"*\",\".\"]]\n\u8f93\u51fa\uff1a[[\"#\",\".\"],\n\u00a0     [\"#\",\"#\"],\n\u00a0     [\"*\",\"*\"],\n\u00a0     [\".\",\".\"]]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1abox = [[\"#\",\"#\",\"*\",\".\",\"*\",\".\"],\n\u00a0           [\"#\",\"#\",\"#\",\"*\",\".\",\".\"],\n\u00a0           [\"#\",\"#\",\"#\",\".\",\"#\",\".\"]]\n\u8f93\u51fa\uff1a[[\".\",\"#\",\"#\"],\n\u00a0     [\".\",\"#\",\"#\"],\n\u00a0     [\"#\",\"#\",\"*\"],\n\u00a0     [\"#\",\"*\",\".\"],\n\u00a0     [\"#\",\".\",\"*\"],\n\u00a0     [\"#\",\".\",\".\"]]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • m == box.length
  • \n\t
  • n == box[i].length
  • \n\t
  • 1 <= m, n <= 500
  • \n\t
  • box[i][j]\u00a0\u53ea\u53ef\u80fd\u662f\u00a0'#'\u00a0\uff0c'*'\u00a0\u6216\u8005\u00a0'.'\u00a0\u3002
  • \n
\n", "tags_en": ["Array", "Two Pointers"], "tags_cn": ["\u6570\u7ec4", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> rotateTheBox(vector>& box) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public char[][] rotateTheBox(char[][] box) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def rotateTheBox(self, box):\n \"\"\"\n :type box: List[List[str]]\n :rtype: List[List[str]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def rotateTheBox(self, box: List[List[str]]) -> List[List[str]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nchar** rotateTheBox(char** box, int boxSize, int* boxColSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public char[][] RotateTheBox(char[][] box) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {character[][]} box\n * @return {character[][]}\n */\nvar rotateTheBox = function(box) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Character[][]} box\n# @return {Character[][]}\ndef rotate_the_box(box)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func rotateTheBox(_ box: [[Character]]) -> [[Character]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func rotateTheBox(box [][]byte) [][]byte {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def rotateTheBox(box: Array[Array[Char]]): Array[Array[Char]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun rotateTheBox(box: Array): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn rotate_the_box(box: Vec>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $box\n * @return String[][]\n */\n function rotateTheBox($box) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function rotateTheBox(box: string[][]): string[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (rotate-the-box box)\n (-> (listof (listof char?)) (listof (listof char?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1861](https://leetcode-cn.com/problems/rotating-the-box)", "[\u65cb\u8f6c\u76d2\u5b50](/solution/1800-1899/1861.Rotating%20the%20Box/README.md)", "`\u6570\u7ec4`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1861](https://leetcode.com/problems/rotating-the-box)", "[Rotating the Box](/solution/1800-1899/1861.Rotating%20the%20Box/README_EN.md)", "`Array`,`Two Pointers`", "Medium", ""]}, {"question_id": "1971", "frontend_question_id": "1860", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/incremental-memory-leak", "url_en": "https://leetcode.com/problems/incremental-memory-leak", "relative_path_cn": "/solution/1800-1899/1860.Incremental%20Memory%20Leak/README.md", "relative_path_en": "/solution/1800-1899/1860.Incremental%20Memory%20Leak/README_EN.md", "title_cn": "\u589e\u957f\u7684\u5185\u5b58\u6cc4\u9732", "title_en": "Incremental Memory Leak", "question_title_slug": "incremental-memory-leak", "content_en": "

You are given two integers memory1 and memory2 representing the available memory in bits on two memory sticks. There is currently a faulty program running that consumes an increasing amount of memory every second.

\n\n

At the ith second (starting from 1), i bits of memory are allocated to the stick with more available memory (or from the first memory stick if both have the same available memory). If neither stick has at least i bits of available memory, the program crashes.

\n\n

Return an array containing [crashTime, memory1crash, memory2crash], where crashTime is the time (in seconds) when the program crashed and memory1crash and memory2crash are the available bits of memory in the first and second sticks respectively.

\n\n

 

\n

Example 1:

\n\n
\nInput: memory1 = 2, memory2 = 2\nOutput: [3,1,0]\nExplanation: The memory is allocated as follows:\n- At the 1st second, 1 bit of memory is allocated to stick 1. The first stick now has 1 bit of available memory.\n- At the 2nd second, 2 bits of memory are allocated to stick 2. The second stick now has 0 bits of available memory.\n- At the 3rd second, the program crashes. The sticks have 1 and 0 bits available respectively.\n
\n\n

Example 2:

\n\n
\nInput: memory1 = 8, memory2 = 11\nOutput: [6,0,4]\nExplanation: The memory is allocated as follows:\n- At the 1st second, 1 bit of memory is allocated to stick 2. The second stick now has 10 bit of available memory.\n- At the 2nd second, 2 bits of memory are allocated to stick 2. The second stick now has 8 bits of available memory.\n- At the 3rd second, 3 bits of memory are allocated to stick 1. The first stick now has 5 bits of available memory.\n- At the 4th second, 4 bits of memory are allocated to stick 2. The second stick now has 4 bits of available memory.\n- At the 5th second, 5 bits of memory are allocated to stick 1. The first stick now has 0 bits of available memory.\n- At the 6th second, the program crashes. The sticks have 0 and 4 bits available respectively.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 0 <= memory1, memory2 <= 231 - 1
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e24\u4e2a\u6574\u6570\u00a0memory1 \u548c\u00a0memory2\u00a0\u5206\u522b\u8868\u793a\u4e24\u4e2a\u5185\u5b58\u6761\u5269\u4f59\u53ef\u7528\u5185\u5b58\u7684\u4f4d\u6570\u3002\u73b0\u5728\u6709\u4e00\u4e2a\u7a0b\u5e8f\u6bcf\u79d2\u9012\u589e\u7684\u901f\u5ea6\u6d88\u8017\u7740\u5185\u5b58\u3002

\n\n

\u5728\u7b2c\u00a0i\u00a0\u79d2\uff08\u79d2\u6570\u4ece 1 \u5f00\u59cb\uff09\uff0c\u6709 i\u00a0\u4f4d\u5185\u5b58\u88ab\u5206\u914d\u5230\u00a0\u5269\u4f59\u5185\u5b58\u8f83\u591a\u00a0\u7684\u5185\u5b58\u6761\uff08\u5982\u679c\u4e24\u8005\u4e00\u6837\u591a\uff0c\u5219\u5206\u914d\u5230\u7b2c\u4e00\u4e2a\u5185\u5b58\u6761\uff09\u3002\u5982\u679c\u4e24\u8005\u5269\u4f59\u5185\u5b58\u90fd\u4e0d\u8db3 i\u00a0\u4f4d\uff0c\u90a3\u4e48\u7a0b\u5e8f\u5c06 \u610f\u5916\u9000\u51fa\u00a0\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u4e00\u4e2a\u6570\u7ec4\uff0c\u5305\u542b [crashTime, memory1crash, memory2crash]\u00a0\uff0c\u5176\u4e2d\u00a0crashTime\u662f\u7a0b\u5e8f\u610f\u5916\u9000\u51fa\u7684\u65f6\u95f4\uff08\u5355\u4f4d\u4e3a\u79d2\uff09\uff0c\u00a0memory1crash \u548c\u00a0memory2crash\u00a0\u5206\u522b\u662f\u4e24\u4e2a\u5185\u5b58\u6761\u6700\u540e\u5269\u4f59\u5185\u5b58\u7684\u4f4d\u6570\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1amemory1 = 2, memory2 = 2\n\u8f93\u51fa\uff1a[3,1,0]\n\u89e3\u91ca\uff1a\u5185\u5b58\u5206\u914d\u5982\u4e0b\uff1a\n- \u7b2c 1 \u79d2\uff0c\u5185\u5b58\u6761 1 \u88ab\u5360\u7528 1 \u4f4d\u5185\u5b58\u3002\u5185\u5b58\u6761 1 \u73b0\u5728\u6709 1 \u4f4d\u5269\u4f59\u53ef\u7528\u5185\u5b58\u3002\n- \u7b2c 2 \u79d2\uff0c\u5185\u5b58\u6761 2 \u88ab\u5360\u7528 2 \u4f4d\u5185\u5b58\u3002\u5185\u5b58\u6761 2 \u73b0\u5728\u6709 0 \u4f4d\u5269\u4f59\u53ef\u7528\u5185\u5b58\u3002\n- \u7b2c 3 \u79d2\uff0c\u7a0b\u5e8f\u610f\u5916\u9000\u51fa\uff0c\u4e24\u4e2a\u5185\u5b58\u6761\u5206\u522b\u6709 1 \u4f4d\u548c 0 \u4f4d\u5269\u4f59\u53ef\u7528\u5185\u5b58\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1amemory1 = 8, memory2 = 11\n\u8f93\u51fa\uff1a[6,0,4]\n\u89e3\u91ca\uff1a\u5185\u5b58\u5206\u914d\u5982\u4e0b\uff1a\n- \u7b2c 1 \u79d2\uff0c\u5185\u5b58\u6761 2 \u88ab\u5360\u7528 1 \u4f4d\u5185\u5b58\uff0c\u5185\u5b58\u6761 2 \u73b0\u5728\u6709 10 \u4f4d\u5269\u4f59\u53ef\u7528\u5185\u5b58\u3002\n- \u7b2c 2 \u79d2\uff0c\u5185\u5b58\u6761 2 \u88ab\u5360\u7528 2 \u4f4d\u5185\u5b58\uff0c\u5185\u5b58\u6761 2 \u73b0\u5728\u6709 8 \u4f4d\u5269\u4f59\u53ef\u7528\u5185\u5b58\u3002\n- \u7b2c 3 \u79d2\uff0c\u5185\u5b58\u6761 1 \u88ab\u5360\u7528 3 \u4f4d\u5185\u5b58\uff0c\u5185\u5b58\u6761 1 \u73b0\u5728\u6709 5 \u4f4d\u5269\u4f59\u53ef\u7528\u5185\u5b58\u3002\n- \u7b2c 4 \u79d2\uff0c\u5185\u5b58\u6761 2 \u88ab\u5360\u7528 4 \u4f4d\u5185\u5b58\uff0c\u5185\u5b58\u6761 2 \u73b0\u5728\u6709 4 \u4f4d\u5269\u4f59\u53ef\u7528\u5185\u5b58\u3002\n- \u7b2c 5 \u79d2\uff0c\u5185\u5b58\u6761 1 \u88ab\u5360\u7528 5 \u4f4d\u5185\u5b58\uff0c\u5185\u5b58\u6761 1 \u73b0\u5728\u6709 0 \u4f4d\u5269\u4f59\u53ef\u7528\u5185\u5b58\u3002\n- \u7b2c 6 \u79d2\uff0c\u7a0b\u5e8f\u610f\u5916\u9000\u51fa\uff0c\u4e24\u4e2a\u5185\u5b58\u6761\u5206\u522b\u6709 0 \u4f4d\u548c 4 \u4f4d\u5269\u4f59\u53ef\u7528\u5185\u5b58\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 0 <= memory1, memory2 <= 231 - 1
  • \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector memLeak(int memory1, int memory2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] memLeak(int memory1, int memory2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def memLeak(self, memory1, memory2):\n \"\"\"\n :type memory1: int\n :type memory2: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def memLeak(self, memory1: int, memory2: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* memLeak(int memory1, int memory2, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] MemLeak(int memory1, int memory2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} memory1\n * @param {number} memory2\n * @return {number[]}\n */\nvar memLeak = function(memory1, memory2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} memory1\n# @param {Integer} memory2\n# @return {Integer[]}\ndef mem_leak(memory1, memory2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func memLeak(_ memory1: Int, _ memory2: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func memLeak(memory1 int, memory2 int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def memLeak(memory1: Int, memory2: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun memLeak(memory1: Int, memory2: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn mem_leak(memory1: i32, memory2: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $memory1\n * @param Integer $memory2\n * @return Integer[]\n */\n function memLeak($memory1, $memory2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function memLeak(memory1: number, memory2: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (mem-leak memory1 memory2)\n (-> exact-integer? exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1860](https://leetcode-cn.com/problems/incremental-memory-leak)", "[\u589e\u957f\u7684\u5185\u5b58\u6cc4\u9732](/solution/1800-1899/1860.Incremental%20Memory%20Leak/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1860](https://leetcode.com/problems/incremental-memory-leak)", "[Incremental Memory Leak](/solution/1800-1899/1860.Incremental%20Memory%20Leak/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "1970", "frontend_question_id": "1859", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sorting-the-sentence", "url_en": "https://leetcode.com/problems/sorting-the-sentence", "relative_path_cn": "/solution/1800-1899/1859.Sorting%20the%20Sentence/README.md", "relative_path_en": "/solution/1800-1899/1859.Sorting%20the%20Sentence/README_EN.md", "title_cn": "\u5c06\u53e5\u5b50\u6392\u5e8f", "title_en": "Sorting the Sentence", "question_title_slug": "sorting-the-sentence", "content_en": "

A sentence is a list of words that are separated by a single space with no leading or trailing spaces. Each word consists of lowercase and uppercase English letters.

\r\n\r\n

A sentence can be shuffled by appending the 1-indexed word position to each word then rearranging the words in the sentence.

\r\n\r\n
    \r\n\t
  • For example, the sentence "This is a sentence" can be shuffled as "sentence4 a3 is2 This1" or "is2 sentence4 This1 a3".
  • \r\n
\r\n\r\n

Given a shuffled sentence s containing no more than 9 words, reconstruct and return the original sentence.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: s = "is2 sentence4 This1 a3"\r\nOutput: "This is a sentence"\r\nExplanation: Sort the words in s to their original positions "This1 is2 a3 sentence4", then remove the numbers.\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: s = "Myself2 Me1 I4 and3"\r\nOutput: "Me Myself and I"\r\nExplanation: Sort the words in s to their original positions "Me1 Myself2 and3 I4", then remove the numbers.\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 2 <= s.length <= 200
  • \r\n\t
  • s consists of lowercase and uppercase English letters, spaces, and digits from 1 to 9.
  • \r\n\t
  • The number of words in s is between 1 and 9.
  • \r\n\t
  • The words in s are separated by a single space.
  • \r\n\t
  • s contains no leading or trailing spaces.
  • \r\n
", "content_cn": "

\u4e00\u4e2a \u53e5\u5b50\u00a0\u6307\u7684\u662f\u4e00\u4e2a\u5e8f\u5217\u7684\u5355\u8bcd\u7528\u5355\u4e2a\u7a7a\u683c\u8fde\u63a5\u8d77\u6765\uff0c\u4e14\u5f00\u5934\u548c\u7ed3\u5c3e\u6ca1\u6709\u4efb\u4f55\u7a7a\u683c\u3002\u6bcf\u4e2a\u5355\u8bcd\u90fd\u53ea\u5305\u542b\u5c0f\u5199\u6216\u5927\u5199\u82f1\u6587\u5b57\u6bcd\u3002

\n\n

\u6211\u4eec\u53ef\u4ee5\u7ed9\u4e00\u4e2a\u53e5\u5b50\u6dfb\u52a0 \u4ece 1 \u5f00\u59cb\u7684\u5355\u8bcd\u4f4d\u7f6e\u7d22\u5f15 \uff0c\u5e76\u4e14\u5c06\u53e5\u5b50\u4e2d\u6240\u6709\u5355\u8bcd\u00a0\u6253\u4e71\u987a\u5e8f\u00a0\u3002

\n\n
    \n\t
  • \u6bd4\u65b9\u8bf4\uff0c\u53e5\u5b50\u00a0\"This is a sentence\"\u00a0\u53ef\u4ee5\u88ab\u6253\u4e71\u987a\u5e8f\u5f97\u5230\u00a0\"sentence4 a3 is2 This1\"\u00a0\u6216\u8005\u00a0\"is2 sentence4 This1 a3\"\u00a0\u3002
  • \n
\n\n

\u7ed9\u4f60\u4e00\u4e2a \u6253\u4e71\u987a\u5e8f\u00a0\u7684\u53e5\u5b50\u00a0s\u00a0\uff0c\u5b83\u5305\u542b\u7684\u5355\u8bcd\u4e0d\u8d85\u8fc7\u00a09\u00a0\u4e2a\uff0c\u8bf7\u4f60\u91cd\u65b0\u6784\u9020\u5e76\u5f97\u5230\u539f\u672c\u987a\u5e8f\u7684\u53e5\u5b50\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"is2 sentence4 This1 a3\"\n\u8f93\u51fa\uff1a\"This is a sentence\"\n\u89e3\u91ca\uff1a\u5c06 s \u4e2d\u7684\u5355\u8bcd\u6309\u7167\u521d\u59cb\u4f4d\u7f6e\u6392\u5e8f\uff0c\u5f97\u5230 \"This1 is2 a3 sentence4\" \uff0c\u7136\u540e\u5220\u9664\u6570\u5b57\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"Myself2 Me1 I4 and3\"\n\u8f93\u51fa\uff1a\"Me Myself and I\"\n\u89e3\u91ca\uff1a\u5c06 s \u4e2d\u7684\u5355\u8bcd\u6309\u7167\u521d\u59cb\u4f4d\u7f6e\u6392\u5e8f\uff0c\u5f97\u5230 \"Me1 Myself2 and3 I4\" \uff0c\u7136\u540e\u5220\u9664\u6570\u5b57\u3002
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= s.length <= 200
  • \n\t
  • s\u00a0\u53ea\u5305\u542b\u5c0f\u5199\u548c\u5927\u5199\u82f1\u6587\u5b57\u6bcd\u3001\u7a7a\u683c\u4ee5\u53ca\u4ece\u00a01\u00a0\u5230\u00a09\u00a0\u7684\u6570\u5b57\u3002
  • \n\t
  • s\u00a0\u4e2d\u5355\u8bcd\u6570\u76ee\u4e3a\u00a01\u00a0\u5230\u00a09\u00a0\u4e2a\u3002
  • \n\t
  • s\u00a0\u4e2d\u7684\u5355\u8bcd\u7531\u5355\u4e2a\u7a7a\u683c\u5206\u9694\u3002
  • \n\t
  • s\u00a0\u4e0d\u5305\u542b\u4efb\u4f55\u524d\u5bfc\u6216\u8005\u540e\u7f00\u7a7a\u683c\u3002
  • \n
\n", "tags_en": ["Sort", "String"], "tags_cn": ["\u6392\u5e8f", "\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string sortSentence(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String sortSentence(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def sortSentence(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def sortSentence(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * sortSentence(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string SortSentence(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar sortSentence = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef sort_sentence(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func sortSentence(_ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func sortSentence(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def sortSentence(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun sortSentence(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sort_sentence(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function sortSentence($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function sortSentence(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (sort-sentence s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1859](https://leetcode-cn.com/problems/sorting-the-sentence)", "[\u5c06\u53e5\u5b50\u6392\u5e8f](/solution/1800-1899/1859.Sorting%20the%20Sentence/README.md)", "`\u6392\u5e8f`,`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1859](https://leetcode.com/problems/sorting-the-sentence)", "[Sorting the Sentence](/solution/1800-1899/1859.Sorting%20the%20Sentence/README_EN.md)", "`Sort`,`String`", "Easy", ""]}, {"question_id": "1969", "frontend_question_id": "1820", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/maximum-number-of-accepted-invitations", "url_en": "https://leetcode.com/problems/maximum-number-of-accepted-invitations", "relative_path_cn": "/solution/1800-1899/1820.Maximum%20Number%20of%20Accepted%20Invitations/README.md", "relative_path_en": "/solution/1800-1899/1820.Maximum%20Number%20of%20Accepted%20Invitations/README_EN.md", "title_cn": "", "title_en": "Maximum Number of Accepted Invitations", "question_title_slug": "maximum-number-of-accepted-invitations", "content_en": "

There are m boys and n girls in a class attending an upcoming party.

\n\n

You are given an m x n integer matrix grid, where grid[i][j] equals 0 or 1. If grid[i][j] == 1, then that means the ith boy can invite the jth girl to the party. A boy can invite at most one girl, and a girl can accept at most one invitation from a boy.

\n\n

Return the maximum possible number of accepted invitations.

\n\n

 

\n

Example 1:

\n\n
\nInput: grid = [[1,1,1],\n               [1,0,1],\n               [0,0,1]]\nOutput: 3\nExplanation: The invitations are sent as follows:\n- The 1st boy invites the 2nd girl.\n- The 2nd boy invites the 1st girl.\n- The 3rd boy invites the 3rd girl.
\n\n

Example 2:

\n\n
\nInput: grid = [[1,0,1,0],\n               [1,0,0,0],\n               [0,0,1,0],\n               [1,1,1,0]]\nOutput: 3\nExplanation: The invitations are sent as follows:\n-The 1st boy invites the 3rd girl.\n-The 2nd boy invites the 1st girl.\n-The 3rd boy invites no one.\n-The 4th boy invites the 2nd girl.
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • grid.length == m
  • \n\t
  • grid[i].length == n
  • \n\t
  • 1 <= m, n <= 200
  • \n\t
  • grid[i][j] is either 0 or 1.
  • \n
\n", "content_cn": null, "tags_en": ["Graph"], "tags_cn": ["\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maximumInvitations(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maximumInvitations(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximumInvitations(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximumInvitations(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maximumInvitations(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaximumInvitations(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar maximumInvitations = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef maximum_invitations(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximumInvitations(_ grid: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximumInvitations(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximumInvitations(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximumInvitations(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximum_invitations(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function maximumInvitations($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximumInvitations(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximum-invitations grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1820](https://leetcode-cn.com/problems/maximum-number-of-accepted-invitations)", "[Maximum Number of Accepted Invitations](/solution/1800-1899/1820.Maximum%20Number%20of%20Accepted%20Invitations/README_EN.md)", "`\u56fe`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1820](https://leetcode.com/problems/maximum-number-of-accepted-invitations)", "[Maximum Number of Accepted Invitations](/solution/1800-1899/1820.Maximum%20Number%20of%20Accepted%20Invitations/README_EN.md)", "`Graph`", "Medium", "\ud83d\udd12"]}, {"question_id": "1968", "frontend_question_id": "1840", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-building-height", "url_en": "https://leetcode.com/problems/maximum-building-height", "relative_path_cn": "/solution/1800-1899/1840.Maximum%20Building%20Height/README.md", "relative_path_en": "/solution/1800-1899/1840.Maximum%20Building%20Height/README_EN.md", "title_cn": "\u6700\u9ad8\u5efa\u7b51\u9ad8\u5ea6", "title_en": "Maximum Building Height", "question_title_slug": "maximum-building-height", "content_en": "

You want to build n new buildings in a city. The new buildings will be built in a line and are labeled from 1 to n.

\n\n

However, there are city restrictions on the heights of the new buildings:

\n\n
    \n\t
  • The height of each building must be a non-negative integer.
  • \n\t
  • The height of the first building must be 0.
  • \n\t
  • The height difference between any two adjacent buildings cannot exceed 1.
  • \n
\n\n

Additionally, there are city restrictions on the maximum height of specific buildings. These restrictions are given as a 2D integer array restrictions where restrictions[i] = [idi, maxHeighti] indicates that building idi must have a height less than or equal to maxHeighti.

\n\n

It is guaranteed that each building will appear at most once in restrictions, and building 1 will not be in restrictions.

\n\n

Return the maximum possible height of the tallest building.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: n = 5, restrictions = [[2,1],[4,1]]\nOutput: 2\nExplanation: The green area in the image indicates the maximum allowed height for each building.\nWe can build the buildings with heights [0,1,2,1,2], and the tallest building has a height of 2.
\n\n

Example 2:

\n\"\"\n
\nInput: n = 6, restrictions = []\nOutput: 5\nExplanation: The green area in the image indicates the maximum allowed height for each building.\nWe can build the buildings with heights [0,1,2,3,4,5], and the tallest building has a height of 5.\n
\n\n

Example 3:

\n\"\"\n
\nInput: n = 10, restrictions = [[5,3],[2,5],[7,4],[10,3]]\nOutput: 5\nExplanation: The green area in the image indicates the maximum allowed height for each building.\nWe can build the buildings with heights [0,1,2,3,3,4,4,5,4,3], and the tallest building has a height of 5.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= n <= 109
  • \n\t
  • 0 <= restrictions.length <= min(n - 1, 105)
  • \n\t
  • 2 <= idi <= n
  • \n\t
  • idi is unique.
  • \n\t
  • 0 <= maxHeighti <= 109
  • \n
\n", "content_cn": "

\u5728\u4e00\u5ea7\u57ce\u5e02\u91cc\uff0c\u4f60\u9700\u8981\u5efa\u00a0n\u00a0\u680b\u65b0\u7684\u5efa\u7b51\u3002\u8fd9\u4e9b\u65b0\u7684\u5efa\u7b51\u4f1a\u4ece 1\u00a0\u5230 n\u00a0\u7f16\u53f7\u6392\u6210\u4e00\u5217\u3002

\n\n

\u8fd9\u5ea7\u57ce\u5e02\u5bf9\u8fd9\u4e9b\u65b0\u5efa\u7b51\u6709\u4e00\u4e9b\u89c4\u5b9a\uff1a

\n\n
    \n\t
  • \u6bcf\u680b\u5efa\u7b51\u7684\u9ad8\u5ea6\u5fc5\u987b\u662f\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\u3002
  • \n\t
  • \u7b2c\u4e00\u680b\u5efa\u7b51\u7684\u9ad8\u5ea6 \u5fc5\u987b\u00a0\u662f\u00a00\u00a0\u3002
  • \n\t
  • \u4efb\u610f\u4e24\u680b\u76f8\u90bb\u5efa\u7b51\u7684\u9ad8\u5ea6\u5dee \u4e0d\u80fd\u8d85\u8fc7\u00a0\u00a01\u00a0\u3002
  • \n
\n\n

\u9664\u6b64\u4ee5\u5916\uff0c\u67d0\u4e9b\u5efa\u7b51\u8fd8\u6709\u989d\u5916\u7684\u6700\u9ad8\u9ad8\u5ea6\u9650\u5236\u3002\u8fd9\u4e9b\u9650\u5236\u4f1a\u4ee5\u4e8c\u7ef4\u6574\u6570\u6570\u7ec4\u00a0restrictions\u00a0\u7684\u5f62\u5f0f\u7ed9\u51fa\uff0c\u5176\u4e2d\u00a0restrictions[i] = [idi, maxHeighti]\u00a0\uff0c\u8868\u793a\u5efa\u7b51\u00a0idi\u00a0\u7684\u9ad8\u5ea6 \u4e0d\u80fd\u8d85\u8fc7\u00a0maxHeighti\u00a0\u3002

\n\n

\u9898\u76ee\u4fdd\u8bc1\u6bcf\u680b\u5efa\u7b51\u5728 restrictions\u00a0\u4e2d\u00a0\u81f3\u591a\u51fa\u73b0\u4e00\u6b21\u00a0\uff0c\u540c\u65f6\u5efa\u7b51 1\u00a0\u4e0d\u4f1a\u00a0\u51fa\u73b0\u5728\u00a0restrictions\u00a0\u4e2d\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de \u6700\u9ad8\u00a0\u5efa\u7b51\u80fd\u8fbe\u5230\u7684 \u6700\u9ad8\u9ad8\u5ea6\u00a0\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1an = 5, restrictions = [[2,1],[4,1]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u4e0a\u56fe\u4e2d\u7684\u7eff\u8272\u533a\u57df\u4e3a\u6bcf\u680b\u5efa\u7b51\u88ab\u5141\u8bb8\u7684\u6700\u9ad8\u9ad8\u5ea6\u3002\n\u6211\u4eec\u53ef\u4ee5\u4f7f\u5efa\u7b51\u9ad8\u5ea6\u5206\u522b\u4e3a [0,1,2,1,2] \uff0c\u6700\u9ad8\u5efa\u7b51\u7684\u9ad8\u5ea6\u4e3a 2 \u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1an = 6, restrictions = []\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u4e0a\u56fe\u4e2d\u7684\u7eff\u8272\u533a\u57df\u4e3a\u6bcf\u680b\u5efa\u7b51\u88ab\u5141\u8bb8\u7684\u6700\u9ad8\u9ad8\u5ea6\u3002\n\u6211\u4eec\u53ef\u4ee5\u4f7f\u5efa\u7b51\u9ad8\u5ea6\u5206\u522b\u4e3a [0,1,2,3,4,5] \uff0c\u6700\u9ad8\u5efa\u7b51\u7684\u9ad8\u5ea6\u4e3a 5 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1an = 10, restrictions = [[5,3],[2,5],[7,4],[10,3]]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u4e0a\u56fe\u4e2d\u7684\u7eff\u8272\u533a\u57df\u4e3a\u6bcf\u680b\u5efa\u7b51\u88ab\u5141\u8bb8\u7684\u6700\u9ad8\u9ad8\u5ea6\u3002\n\u6211\u4eec\u53ef\u4ee5\u4f7f\u5efa\u7b51\u9ad8\u5ea6\u5206\u522b\u4e3a [0,1,2,3,3,4,4,5,4,3] \uff0c\u6700\u9ad8\u5efa\u7b51\u7684\u9ad8\u5ea6\u4e3a 5 \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= n <= 109
  • \n\t
  • 0 <= restrictions.length <= min(n - 1, 105)
  • \n\t
  • 2 <= idi <= n
  • \n\t
  • idi\u00a0\u662f \u552f\u4e00\u7684\u00a0\u3002
  • \n\t
  • 0 <= maxHeighti <= 109
  • \n
\n", "tags_en": ["Greedy", "Binary Search"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxBuilding(int n, vector>& restrictions) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxBuilding(int n, int[][] restrictions) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxBuilding(self, n, restrictions):\n \"\"\"\n :type n: int\n :type restrictions: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxBuilding(self, n: int, restrictions: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxBuilding(int n, int** restrictions, int restrictionsSize, int* restrictionsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxBuilding(int n, int[][] restrictions) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} restrictions\n * @return {number}\n */\nvar maxBuilding = function(n, restrictions) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} restrictions\n# @return {Integer}\ndef max_building(n, restrictions)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxBuilding(_ n: Int, _ restrictions: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxBuilding(n int, restrictions [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxBuilding(n: Int, restrictions: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxBuilding(n: Int, restrictions: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_building(n: i32, restrictions: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $restrictions\n * @return Integer\n */\n function maxBuilding($n, $restrictions) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxBuilding(n: number, restrictions: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-building n restrictions)\n (-> exact-integer? (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1840](https://leetcode-cn.com/problems/maximum-building-height)", "[\u6700\u9ad8\u5efa\u7b51\u9ad8\u5ea6](/solution/1800-1899/1840.Maximum%20Building%20Height/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u4e8c\u5206\u67e5\u627e`", "\u56f0\u96be", ""], "md_table_row_en": ["[1840](https://leetcode.com/problems/maximum-building-height)", "[Maximum Building Height](/solution/1800-1899/1840.Maximum%20Building%20Height/README_EN.md)", "`Greedy`,`Binary Search`", "Hard", ""]}, {"question_id": "1967", "frontend_question_id": "1839", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-substring-of-all-vowels-in-order", "url_en": "https://leetcode.com/problems/longest-substring-of-all-vowels-in-order", "relative_path_cn": "/solution/1800-1899/1839.Longest%20Substring%20Of%20All%20Vowels%20in%20Order/README.md", "relative_path_en": "/solution/1800-1899/1839.Longest%20Substring%20Of%20All%20Vowels%20in%20Order/README_EN.md", "title_cn": "\u6240\u6709\u5143\u97f3\u6309\u987a\u5e8f\u6392\u5e03\u7684\u6700\u957f\u5b50\u5b57\u7b26\u4e32", "title_en": "Longest Substring Of All Vowels in Order", "question_title_slug": "longest-substring-of-all-vowels-in-order", "content_en": "

A string is considered beautiful if it satisfies the following conditions:

\n\n
    \n\t
  • Each of the 5 English vowels ('a', 'e', 'i', 'o', 'u') must appear at least once in it.
  • \n\t
  • The letters must be sorted in alphabetical order (i.e. all 'a's before 'e's, all 'e's before 'i's, etc.).
  • \n
\n\n

For example, strings "aeiou" and "aaaaaaeiiiioou" are considered beautiful, but "uaeio", "aeoiu", and "aaaeeeooo" are not beautiful.

\n\n

Given a string word consisting of English vowels, return the length of the longest beautiful substring of word. If no such substring exists, return 0.

\n\n

A substring is a contiguous sequence of characters in a string.

\n\n

 

\n

Example 1:

\n\n
\nInput: word = "aeiaaioaaaaeiiiiouuuooaauuaeiu"\nOutput: 13\nExplanation: The longest beautiful substring in word is "aaaaeiiiiouuu" of length 13.
\n\n

Example 2:

\n\n
\nInput: word = "aeeeiiiioooauuuaeiou"\nOutput: 5\nExplanation: The longest beautiful substring in word is "aeiou" of length 5.\n
\n\n

Example 3:

\n\n
\nInput: word = "a"\nOutput: 0\nExplanation: There is no beautiful substring, so return 0.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= word.length <= 5 * 105
  • \n\t
  • word consists of characters 'a', 'e', 'i', 'o', and 'u'.
  • \n
\n", "content_cn": "

\u5f53\u4e00\u4e2a\u5b57\u7b26\u4e32\u6ee1\u8db3\u5982\u4e0b\u6761\u4ef6\u65f6\uff0c\u6211\u4eec\u79f0\u5b83\u662f \u7f8e\u4e3d\u7684\u00a0\uff1a

\n\n
    \n\t
  • \u6240\u6709 5 \u4e2a\u82f1\u6587\u5143\u97f3\u5b57\u6bcd\uff08'a'\u00a0\uff0c'e'\u00a0\uff0c'i'\u00a0\uff0c'o'\u00a0\uff0c'u'\uff09\u90fd\u5fc5\u987b\u00a0\u81f3\u5c11\u00a0\u51fa\u73b0\u4e00\u6b21\u3002
  • \n\t
  • \u8fd9\u4e9b\u5143\u97f3\u5b57\u6bcd\u7684\u987a\u5e8f\u90fd\u5fc5\u987b\u6309\u7167 \u5b57\u5178\u5e8f\u00a0\u5347\u5e8f\u6392\u5e03\uff08\u4e5f\u5c31\u662f\u8bf4\u6240\u6709\u7684 'a'\u00a0\u90fd\u5728 'e'\u00a0\u524d\u9762\uff0c\u6240\u6709\u7684 'e'\u00a0\u90fd\u5728 'i'\u00a0\u524d\u9762\uff0c\u4ee5\u6b64\u7c7b\u63a8\uff09
  • \n
\n\n

\u6bd4\u65b9\u8bf4\uff0c\u5b57\u7b26\u4e32\u00a0\"aeiou\" \u548c\u00a0\"aaaaaaeiiiioou\"\u00a0\u90fd\u662f \u7f8e\u4e3d\u7684\u00a0\uff0c\u4f46\u662f\u00a0\"uaeio\"\u00a0\uff0c\"aeoiu\"\u00a0\u548c\u00a0\"aaaeeeooo\"\u00a0\u4e0d\u662f\u7f8e\u4e3d\u7684\u00a0\u3002

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u53ea\u5305\u542b\u82f1\u6587\u5143\u97f3\u5b57\u6bcd\u7684\u5b57\u7b26\u4e32\u00a0word\u00a0\uff0c\u8bf7\u4f60\u8fd4\u56de\u00a0word \u4e2d \u6700\u957f\u7f8e\u4e3d\u5b50\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u00a0\u3002\u5982\u679c\u4e0d\u5b58\u5728\u8fd9\u6837\u7684\u5b50\u5b57\u7b26\u4e32\uff0c\u8bf7\u8fd4\u56de 0\u00a0\u3002

\n\n

\u5b50\u5b57\u7b26\u4e32 \u662f\u5b57\u7b26\u4e32\u4e2d\u4e00\u4e2a\u8fde\u7eed\u7684\u5b57\u7b26\u5e8f\u5217\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aword = \"aeiaaioaaaaeiiiiouuuooaauuaeiu\"\n\u8f93\u51fa\uff1a13\n\u89e3\u91ca\uff1a\u6700\u957f\u5b50\u5b57\u7b26\u4e32\u662f \"aaaaeiiiiouuu\" \uff0c\u957f\u5ea6\u4e3a 13 \u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aword = \"aeeeiiiioooauuuaeiou\"\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u6700\u957f\u5b50\u5b57\u7b26\u4e32\u662f \"aeiou\" \uff0c\u957f\u5ea6\u4e3a 5 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1aword = \"a\"\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6ca1\u6709\u7f8e\u4e3d\u5b50\u5b57\u7b26\u4e32\uff0c\u6240\u4ee5\u8fd4\u56de 0 \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= word.length <= 5 * 105
  • \n\t
  • word\u00a0\u53ea\u5305\u542b\u5b57\u7b26\u00a0'a'\uff0c'e'\uff0c'i'\uff0c'o'\u00a0\u548c\u00a0'u'\u00a0\u3002
  • \n
\n", "tags_en": ["Two Pointers", "String"], "tags_cn": ["\u53cc\u6307\u9488", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int longestBeautifulSubstring(string word) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int longestBeautifulSubstring(String word) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestBeautifulSubstring(self, word):\n \"\"\"\n :type word: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestBeautifulSubstring(self, word: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint longestBeautifulSubstring(char * word){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LongestBeautifulSubstring(string word) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} word\n * @return {number}\n */\nvar longestBeautifulSubstring = function(word) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} word\n# @return {Integer}\ndef longest_beautiful_substring(word)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestBeautifulSubstring(_ word: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestBeautifulSubstring(word string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestBeautifulSubstring(word: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestBeautifulSubstring(word: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_beautiful_substring(word: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $word\n * @return Integer\n */\n function longestBeautifulSubstring($word) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestBeautifulSubstring(word: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-beautiful-substring word)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1839](https://leetcode-cn.com/problems/longest-substring-of-all-vowels-in-order)", "[\u6240\u6709\u5143\u97f3\u6309\u987a\u5e8f\u6392\u5e03\u7684\u6700\u957f\u5b50\u5b57\u7b26\u4e32](/solution/1800-1899/1839.Longest%20Substring%20Of%20All%20Vowels%20in%20Order/README.md)", "`\u53cc\u6307\u9488`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1839](https://leetcode.com/problems/longest-substring-of-all-vowels-in-order)", "[Longest Substring Of All Vowels in Order](/solution/1800-1899/1839.Longest%20Substring%20Of%20All%20Vowels%20in%20Order/README_EN.md)", "`Two Pointers`,`String`", "Medium", ""]}, {"question_id": "1966", "frontend_question_id": "1838", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/frequency-of-the-most-frequent-element", "url_en": "https://leetcode.com/problems/frequency-of-the-most-frequent-element", "relative_path_cn": "/solution/1800-1899/1838.Frequency%20of%20the%20Most%20Frequent%20Element/README.md", "relative_path_en": "/solution/1800-1899/1838.Frequency%20of%20the%20Most%20Frequent%20Element/README_EN.md", "title_cn": "\u6700\u9ad8\u9891\u5143\u7d20\u7684\u9891\u6570", "title_en": "Frequency of the Most Frequent Element", "question_title_slug": "frequency-of-the-most-frequent-element", "content_en": "

The frequency of an element is the number of times it occurs in an array.

\n\n

You are given an integer array nums and an integer k. In one operation, you can choose an index of nums and increment the element at that index by 1.

\n\n

Return the maximum possible frequency of an element after performing at most k operations.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [1,2,4], k = 5\nOutput: 3\nExplanation: Increment the first element three times and the second element two times to make nums = [4,4,4].\n4 has a frequency of 3.
\n\n

Example 2:

\n\n
\nInput: nums = [1,4,8,13], k = 5\nOutput: 2\nExplanation: There are multiple optimal solutions:\n- Increment the first element three times to make nums = [4,4,8,13]. 4 has a frequency of 2.\n- Increment the second element four times to make nums = [1,8,8,13]. 8 has a frequency of 2.\n- Increment the third element five times to make nums = [1,4,13,13]. 13 has a frequency of 2.\n
\n\n

Example 3:

\n\n
\nInput: nums = [3,9,6], k = 2\nOutput: 1\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 105
  • \n\t
  • 1 <= nums[i] <= 105
  • \n\t
  • 1 <= k <= 105
  • \n
\n", "content_cn": "

\u5143\u7d20\u7684 \u9891\u6570 \u662f\u8be5\u5143\u7d20\u5728\u4e00\u4e2a\u6570\u7ec4\u4e2d\u51fa\u73b0\u7684\u6b21\u6570\u3002

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \u548c\u4e00\u4e2a\u6574\u6570 k \u3002\u5728\u4e00\u6b65\u64cd\u4f5c\u4e2d\uff0c\u4f60\u53ef\u4ee5\u9009\u62e9 nums \u7684\u4e00\u4e2a\u4e0b\u6807\uff0c\u5e76\u5c06\u8be5\u4e0b\u6807\u5bf9\u5e94\u5143\u7d20\u7684\u503c\u589e\u52a0 1 \u3002

\n\n

\u6267\u884c\u6700\u591a k \u6b21\u64cd\u4f5c\u540e\uff0c\u8fd4\u56de\u6570\u7ec4\u4e2d\u6700\u9ad8\u9891\u5143\u7d20\u7684 \u6700\u5927\u53ef\u80fd\u9891\u6570 \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [1,2,4], k = 5\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u5bf9\u7b2c\u4e00\u4e2a\u5143\u7d20\u6267\u884c 3 \u6b21\u9012\u589e\u64cd\u4f5c\uff0c\u5bf9\u7b2c\u4e8c\u4e2a\u5143\u7d20\u6267 2 \u6b21\u9012\u589e\u64cd\u4f5c\uff0c\u6b64\u65f6 nums = [4,4,4] \u3002\n4 \u662f\u6570\u7ec4\u4e2d\u6700\u9ad8\u9891\u5143\u7d20\uff0c\u9891\u6570\u662f 3 \u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [1,4,8,13], k = 5\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5b58\u5728\u591a\u79cd\u6700\u4f18\u89e3\u51b3\u65b9\u6848\uff1a\n- \u5bf9\u7b2c\u4e00\u4e2a\u5143\u7d20\u6267\u884c 3 \u6b21\u9012\u589e\u64cd\u4f5c\uff0c\u6b64\u65f6 nums = [4,4,8,13] \u30024 \u662f\u6570\u7ec4\u4e2d\u6700\u9ad8\u9891\u5143\u7d20\uff0c\u9891\u6570\u662f 2 \u3002\n- \u5bf9\u7b2c\u4e8c\u4e2a\u5143\u7d20\u6267\u884c 4 \u6b21\u9012\u589e\u64cd\u4f5c\uff0c\u6b64\u65f6 nums = [1,8,8,13] \u30028 \u662f\u6570\u7ec4\u4e2d\u6700\u9ad8\u9891\u5143\u7d20\uff0c\u9891\u6570\u662f 2 \u3002\n- \u5bf9\u7b2c\u4e09\u4e2a\u5143\u7d20\u6267\u884c 5 \u6b21\u9012\u589e\u64cd\u4f5c\uff0c\u6b64\u65f6 nums = [1,4,13,13] \u300213 \u662f\u6570\u7ec4\u4e2d\u6700\u9ad8\u9891\u5143\u7d20\uff0c\u9891\u6570\u662f 2 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [3,9,6], k = 2\n\u8f93\u51fa\uff1a1\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 105
  • \n\t
  • 1 <= nums[i] <= 105
  • \n\t
  • 1 <= k <= 105
  • \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxFrequency(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxFrequency(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxFrequency(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxFrequency(self, nums: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxFrequency(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxFrequency(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar maxFrequency = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef max_frequency(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxFrequency(_ nums: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxFrequency(nums []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxFrequency(nums: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxFrequency(nums: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_frequency(nums: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer\n */\n function maxFrequency($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxFrequency(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-frequency nums k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1838](https://leetcode-cn.com/problems/frequency-of-the-most-frequent-element)", "[\u6700\u9ad8\u9891\u5143\u7d20\u7684\u9891\u6570](/solution/1800-1899/1838.Frequency%20of%20the%20Most%20Frequent%20Element/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1838](https://leetcode.com/problems/frequency-of-the-most-frequent-element)", "[Frequency of the Most Frequent Element](/solution/1800-1899/1838.Frequency%20of%20the%20Most%20Frequent%20Element/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1965", "frontend_question_id": "1837", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sum-of-digits-in-base-k", "url_en": "https://leetcode.com/problems/sum-of-digits-in-base-k", "relative_path_cn": "/solution/1800-1899/1837.Sum%20of%20Digits%20in%20Base%20K/README.md", "relative_path_en": "/solution/1800-1899/1837.Sum%20of%20Digits%20in%20Base%20K/README_EN.md", "title_cn": "K \u8fdb\u5236\u8868\u793a\u4e0b\u7684\u5404\u4f4d\u6570\u5b57\u603b\u548c", "title_en": "Sum of Digits in Base K", "question_title_slug": "sum-of-digits-in-base-k", "content_en": "

Given an integer n (in base 10) and a base k, return the sum of the digits of n after converting n from base 10 to base k.

\n\n

After converting, each digit should be interpreted as a base 10 number, and the sum should be returned in base 10.

\n\n

 

\n

Example 1:

\n\n
\nInput: n = 34, k = 6\nOutput: 9\nExplanation: 34 (base 10) expressed in base 6 is 54. 5 + 4 = 9.\n
\n\n

Example 2:

\n\n
\nInput: n = 10, k = 10\nOutput: 1\nExplanation: n is already in base 10. 1 + 0 = 1.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 100
  • \n\t
  • 2 <= k <= 10
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n\uff0810 \u8fdb\u5236\uff09\u548c\u4e00\u4e2a\u57fa\u6570 k \uff0c\u8bf7\u4f60\u5c06 n \u4ece 10 \u8fdb\u5236\u8868\u793a\u8f6c\u6362\u4e3a k \u8fdb\u5236\u8868\u793a\uff0c\u8ba1\u7b97\u5e76\u8fd4\u56de\u8f6c\u6362\u540e\u5404\u4f4d\u6570\u5b57\u7684 \u603b\u548c \u3002

\n\n

\u8f6c\u6362\u540e\uff0c\u5404\u4f4d\u6570\u5b57\u5e94\u5f53\u89c6\u4f5c\u662f 10 \u8fdb\u5236\u6570\u5b57\uff0c\u4e14\u5b83\u4eec\u7684\u603b\u548c\u4e5f\u5e94\u5f53\u6309 10 \u8fdb\u5236\u8868\u793a\u8fd4\u56de\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1an = 34, k = 6\n\u8f93\u51fa\uff1a9\n\u89e3\u91ca\uff1a34 (10 \u8fdb\u5236) \u5728 6 \u8fdb\u5236\u4e0b\u8868\u793a\u4e3a 54 \u30025 + 4 = 9 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1an = 10, k = 10\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1an \u672c\u8eab\u5c31\u662f 10 \u8fdb\u5236\u3002 1 + 0 = 1 \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 100
  • \n\t
  • 2 <= k <= 10
  • \n
\n", "tags_en": ["Bit Manipulation", "Math"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int sumBase(int n, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int sumBase(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def sumBase(self, n, k):\n \"\"\"\n :type n: int\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def sumBase(self, n: int, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint sumBase(int n, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SumBase(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} k\n * @return {number}\n */\nvar sumBase = function(n, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} k\n# @return {Integer}\ndef sum_base(n, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func sumBase(_ n: Int, _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func sumBase(n int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def sumBase(n: Int, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun sumBase(n: Int, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sum_base(n: i32, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $k\n * @return Integer\n */\n function sumBase($n, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function sumBase(n: number, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (sum-base n k)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1837](https://leetcode-cn.com/problems/sum-of-digits-in-base-k)", "[K \u8fdb\u5236\u8868\u793a\u4e0b\u7684\u5404\u4f4d\u6570\u5b57\u603b\u548c](/solution/1800-1899/1837.Sum%20of%20Digits%20in%20Base%20K/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[1837](https://leetcode.com/problems/sum-of-digits-in-base-k)", "[Sum of Digits in Base K](/solution/1800-1899/1837.Sum%20of%20Digits%20in%20Base%20K/README_EN.md)", "`Bit Manipulation`,`Math`", "Easy", ""]}, {"question_id": "1964", "frontend_question_id": "1811", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/find-interview-candidates", "url_en": "https://leetcode.com/problems/find-interview-candidates", "relative_path_cn": "/solution/1800-1899/1811.Find%20Interview%20Candidates/README.md", "relative_path_en": "/solution/1800-1899/1811.Find%20Interview%20Candidates/README_EN.md", "title_cn": "", "title_en": "Find Interview Candidates", "question_title_slug": "find-interview-candidates", "content_en": "

Table: Contests

\n\n
\n+--------------+------+\n| Column Name  | Type |\n+--------------+------+\n| contest_id   | int  |\n| gold_medal   | int  |\n| silver_medal | int  |\n| bronze_medal | int  |\n+--------------+------+\ncontest_id is the primary key for this table.\nThis table contains the LeetCode contest ID and the user IDs of the gold, silver, and bronze medalists.\nIt is guaranteed that any consecutive contests have consecutive IDs and that no ID is skipped.
\n\n

 

\n\n

Table: Users

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| user_id     | int     |\n| mail        | varchar |\n| name        | varchar |\n+-------------+---------+\nuser_id is the primary key for this table.\nThis table contains information about the users.\n
\n\n

 

\n\n

Write an SQL query to report the name and the mail of all interview candidates. A user is an interview candidate if at least one of these two conditions is true:

\n\n
    \n\t
  • The user won any medal in three or more consecutive contests.
  • \n\t
  • The user won the gold medal in three or more different contests (not necessarily consecutive).
  • \n
\n\n

Return the result table in any order.

\n\n

The query result format is in the following example:

\n\n

 

\n\n
\nContests table:\n+------------+------------+--------------+--------------+\n| contest_id | gold_medal | silver_medal | bronze_medal |\n+------------+------------+--------------+--------------+\n| 190        | 1          | 5            | 2            |\n| 191        | 2          | 3            | 5            |\n| 192        | 5          | 2            | 3            |\n| 193        | 1          | 3            | 5            |\n| 194        | 4          | 5            | 2            |\n| 195        | 4          | 2            | 1            |\n| 196        | 1          | 5            | 2            |\n+------------+------------+--------------+--------------+\n\nUsers table:\n+---------+--------------------+-------+\n| user_id | mail               | name  |\n+---------+--------------------+-------+\n| 1       | sarah@leetcode.com | Sarah |\n| 2       | bob@leetcode.com   | Bob   |\n| 3       | alice@leetcode.com | Alice |\n| 4       | hercy@leetcode.com | Hercy |\n| 5       | quarz@leetcode.com | Quarz |\n+---------+--------------------+-------+\n\nResult table:\n+-------+--------------------+\n| name  | mail               |\n+-------+--------------------+\n| Sarah | sarah@leetcode.com |\n| Bob   | bob@leetcode.com   |\n| Alice | alice@leetcode.com |\n| Quarz | quarz@leetcode.com |\n+-------+--------------------+\n\nSarah won 3 gold medals (190, 193, and 196), so we include her in the result table.\nBob won a medal in 3 consecutive contests (190, 191, and 192), so we include him in the result table.\n    - Note that he also won a medal in 3 other consecutive contests (194, 195, and 196).\nAlice won a medal in 3 consecutive contests (191, 192, and 193), so we include her in the result table.\nQuarz won a medal in 5 consecutive contests (190, 191, 192, 193, and 194), so we include them in the result table.\n
\n\n

 

\n

Follow up:

\n\n
    \n\t
  • What if the first condition changed to be "any medal in n or more consecutive contests"? How would you change your solution to get the interview candidates? Imagine that n is the parameter of a stored procedure.
  • \n\t
  • Some users may not participate in every contest but still perform well in the ones they do. How would you change your solution to only consider contests where the user was a participant? Suppose the registered users for each contest are given in another table.
  • \n
\n", "content_cn": null, "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1811](https://leetcode-cn.com/problems/find-interview-candidates)", "[Find Interview Candidates](/solution/1800-1899/1811.Find%20Interview%20Candidates/README_EN.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1811](https://leetcode.com/problems/find-interview-candidates)", "[Find Interview Candidates](/solution/1800-1899/1811.Find%20Interview%20Candidates/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1963", "frontend_question_id": "1835", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-xor-sum-of-all-pairs-bitwise-and", "url_en": "https://leetcode.com/problems/find-xor-sum-of-all-pairs-bitwise-and", "relative_path_cn": "/solution/1800-1899/1835.Find%20XOR%20Sum%20of%20All%20Pairs%20Bitwise%20AND/README.md", "relative_path_en": "/solution/1800-1899/1835.Find%20XOR%20Sum%20of%20All%20Pairs%20Bitwise%20AND/README_EN.md", "title_cn": "\u6240\u6709\u6570\u5bf9\u6309\u4f4d\u4e0e\u7ed3\u679c\u7684\u5f02\u6216\u548c", "title_en": "Find XOR Sum of All Pairs Bitwise AND", "question_title_slug": "find-xor-sum-of-all-pairs-bitwise-and", "content_en": "

The XOR sum of a list is the bitwise XOR of all its elements. If the list only contains one element, then its XOR sum will be equal to this element.

\n\n
    \n\t
  • For example, the XOR sum of [1,2,3,4] is equal to 1 XOR 2 XOR 3 XOR 4 = 4, and the XOR sum of [3] is equal to 3.
  • \n
\n\n

You are given two 0-indexed arrays arr1 and arr2 that consist only of non-negative integers.

\n\n

Consider the list containing the result of arr1[i] AND arr2[j] (bitwise AND) for every (i, j) pair where 0 <= i < arr1.length and 0 <= j < arr2.length.

\n\n

Return the XOR sum of the aforementioned list.

\n\n

 

\n

Example 1:

\n\n
\nInput: arr1 = [1,2,3], arr2 = [6,5]\nOutput: 0\nExplanation: The list = [1 AND 6, 1 AND 5, 2 AND 6, 2 AND 5, 3 AND 6, 3 AND 5] = [0,1,2,0,2,1].\nThe XOR sum = 0 XOR 1 XOR 2 XOR 0 XOR 2 XOR 1 = 0.\n
\n\n

Example 2:

\n\n
\nInput: arr1 = [12], arr2 = [4]\nOutput: 4\nExplanation: The list = [12 AND 4] = [4]. The XOR sum = 4.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= arr1.length, arr2.length <= 105
  • \n\t
  • 0 <= arr1[i], arr2[j] <= 109
  • \n
\n", "content_cn": "

\u5217\u8868\u7684 \u5f02\u6216\u548c\uff08XOR sum\uff09\u6307\u5bf9\u6240\u6709\u5143\u7d20\u8fdb\u884c\u6309\u4f4d XOR \u8fd0\u7b97\u7684\u7ed3\u679c\u3002\u5982\u679c\u5217\u8868\u4e2d\u4ec5\u6709\u4e00\u4e2a\u5143\u7d20\uff0c\u90a3\u4e48\u5176 \u5f02\u6216\u548c \u5c31\u7b49\u4e8e\u8be5\u5143\u7d20\u3002

\n\n
    \n\t
  • \u4f8b\u5982\uff0c[1,2,3,4] \u7684 \u5f02\u6216\u548c \u7b49\u4e8e 1 XOR 2 XOR 3 XOR 4 = 4 \uff0c\u800c [3] \u7684 \u5f02\u6216\u548c \u7b49\u4e8e 3 \u3002
  • \n
\n\n

\u7ed9\u4f60\u4e24\u4e2a\u4e0b\u6807 \u4ece 0 \u5f00\u59cb \u8ba1\u6570\u7684\u6570\u7ec4 arr1 \u548c arr2 \uff0c\u4e24\u6570\u7ec4\u5747\u7531\u975e\u8d1f\u6574\u6570\u7ec4\u6210\u3002

\n\n

\u6839\u636e\u6bcf\u4e2a\u00a0(i, j) \u6570\u5bf9\uff0c\u6784\u9020\u4e00\u4e2a\u7531 arr1[i] AND arr2[j]\uff08\u6309\u4f4d AND \u8fd0\u7b97\uff09\u7ed3\u679c\u7ec4\u6210\u7684\u5217\u8868\u3002\u5176\u4e2d 0 <= i < arr1.length \u4e14 0 <= j < arr2.length \u3002

\n\n

\u8fd4\u56de\u4e0a\u8ff0\u5217\u8868\u7684 \u5f02\u6216\u548c \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aarr1 = [1,2,3], arr2 = [6,5]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u5217\u8868 = [1 AND 6, 1 AND 5, 2 AND 6, 2 AND 5, 3 AND 6, 3 AND 5] = [0,1,2,0,2,1] \uff0c\n\u5f02\u6216\u548c = 0 XOR 1 XOR 2 XOR 0 XOR 2 XOR 1 = 0 \u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aarr1 = [12], arr2 = [4]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u5217\u8868 = [12 AND 4] = [4] \uff0c\u5f02\u6216\u548c = 4 \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= arr1.length, arr2.length <= 105
  • \n\t
  • 0 <= arr1[i], arr2[j] <= 109
  • \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int getXORSum(vector& arr1, vector& arr2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int getXORSum(int[] arr1, int[] arr2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getXORSum(self, arr1, arr2):\n \"\"\"\n :type arr1: List[int]\n :type arr2: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getXORSum(self, arr1: List[int], arr2: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint getXORSum(int* arr1, int arr1Size, int* arr2, int arr2Size){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int GetXORSum(int[] arr1, int[] arr2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr1\n * @param {number[]} arr2\n * @return {number}\n */\nvar getXORSum = function(arr1, arr2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr1\n# @param {Integer[]} arr2\n# @return {Integer}\ndef get_xor_sum(arr1, arr2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getXORSum(_ arr1: [Int], _ arr2: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getXORSum(arr1 []int, arr2 []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getXORSum(arr1: Array[Int], arr2: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getXORSum(arr1: IntArray, arr2: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_xor_sum(arr1: Vec, arr2: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr1\n * @param Integer[] $arr2\n * @return Integer\n */\n function getXORSum($arr1, $arr2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getXORSum(arr1: number[], arr2: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-xor-sum arr1 arr2)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1835](https://leetcode-cn.com/problems/find-xor-sum-of-all-pairs-bitwise-and)", "[\u6240\u6709\u6570\u5bf9\u6309\u4f4d\u4e0e\u7ed3\u679c\u7684\u5f02\u6216\u548c](/solution/1800-1899/1835.Find%20XOR%20Sum%20of%20All%20Pairs%20Bitwise%20AND/README.md)", "`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[1835](https://leetcode.com/problems/find-xor-sum-of-all-pairs-bitwise-and)", "[Find XOR Sum of All Pairs Bitwise AND](/solution/1800-1899/1835.Find%20XOR%20Sum%20of%20All%20Pairs%20Bitwise%20AND/README_EN.md)", "`Math`", "Hard", ""]}, {"question_id": "1962", "frontend_question_id": "1834", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/single-threaded-cpu", "url_en": "https://leetcode.com/problems/single-threaded-cpu", "relative_path_cn": "/solution/1800-1899/1834.Single-Threaded%20CPU/README.md", "relative_path_en": "/solution/1800-1899/1834.Single-Threaded%20CPU/README_EN.md", "title_cn": "\u5355\u7ebf\u7a0b CPU", "title_en": "Single-Threaded CPU", "question_title_slug": "single-threaded-cpu", "content_en": "

You are given n\u200b\u200b\u200b\u200b\u200b\u200b tasks labeled from 0 to n - 1 represented by a 2D integer array tasks, where tasks[i] = [enqueueTimei, processingTimei] means that the i\u200b\u200b\u200b\u200b\u200b\u200bth\u200b\u200b\u200b\u200b task will be available to process at enqueueTimei and will take processingTimei to finish processing.

\n\n

You have a single-threaded CPU that can process at most one task at a time and will act in the following way:

\n\n
    \n\t
  • If the CPU is idle and there are no available tasks to process, the CPU remains idle.
  • \n\t
  • If the CPU is idle and there are available tasks, the CPU will choose the one with the shortest processing time. If multiple tasks have the same shortest processing time, it will choose the task with the smallest index.
  • \n\t
  • Once a task is started, the CPU will process the entire task without stopping.
  • \n\t
  • The CPU can finish a task then start a new one instantly.
  • \n
\n\n

Return the order in which the CPU will process the tasks.

\n\n

 

\n

Example 1:

\n\n
\nInput: tasks = [[1,2],[2,4],[3,2],[4,1]]\nOutput: [0,2,3,1]\nExplanation: The events go as follows: \n- At time = 1, task 0 is available to process. Available tasks = {0}.\n- Also at time = 1, the idle CPU starts processing task 0. Available tasks = {}.\n- At time = 2, task 1 is available to process. Available tasks = {1}.\n- At time = 3, task 2 is available to process. Available tasks = {1, 2}.\n- Also at time = 3, the CPU finishes task 0 and starts processing task 2 as it is the shortest. Available tasks = {1}.\n- At time = 4, task 3 is available to process. Available tasks = {1, 3}.\n- At time = 5, the CPU finishes task 2 and starts processing task 3 as it is the shortest. Available tasks = {1}.\n- At time = 6, the CPU finishes task 3 and starts processing task 1. Available tasks = {}.\n- At time = 10, the CPU finishes task 1 and becomes idle.\n
\n\n

Example 2:

\n\n
\nInput: tasks = [[7,10],[7,12],[7,5],[7,4],[7,2]]\nOutput: [4,3,2,0,1]\nExplanation: The events go as follows:\n- At time = 7, all the tasks become available. Available tasks = {0,1,2,3,4}.\n- Also at time = 7, the idle CPU starts processing task 4. Available tasks = {0,1,2,3}.\n- At time = 9, the CPU finishes task 4 and starts processing task 3. Available tasks = {0,1,2}.\n- At time = 13, the CPU finishes task 3 and starts processing task 2. Available tasks = {0,1}.\n- At time = 18, the CPU finishes task 2 and starts processing task 0. Available tasks = {1}.\n- At time = 28, the CPU finishes task 0 and starts processing task 1. Available tasks = {}.\n- At time = 40, the CPU finishes task 1 and becomes idle.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • tasks.length == n
  • \n\t
  • 1 <= n <= 105
  • \n\t
  • 1 <= enqueueTimei, processingTimei <= 109
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u4e8c\u7ef4\u6570\u7ec4 tasks \uff0c\u7528\u4e8e\u8868\u793a n\u200b\u200b\u200b\u200b\u200b\u200b \u9879\u4ece 0 \u5230 n - 1 \u7f16\u53f7\u7684\u4efb\u52a1\u3002\u5176\u4e2d tasks[i] = [enqueueTimei, processingTimei] \u610f\u5473\u7740\u7b2c i\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b \u9879\u4efb\u52a1\u5c06\u4f1a\u4e8e enqueueTimei \u65f6\u8fdb\u5165\u4efb\u52a1\u961f\u5217\uff0c\u9700\u8981 processingTimei \u7684\u65f6\u957f\u5b8c\u6210\u6267\u884c\u3002

\n\n

\u73b0\u6709\u4e00\u4e2a\u5355\u7ebf\u7a0b CPU \uff0c\u540c\u4e00\u65f6\u95f4\u53ea\u80fd\u6267\u884c \u6700\u591a\u4e00\u9879 \u4efb\u52a1\uff0c\u8be5 CPU \u5c06\u4f1a\u6309\u7167\u4e0b\u8ff0\u65b9\u5f0f\u8fd0\u884c\uff1a

\n\n
    \n\t
  • \u5982\u679c CPU \u7a7a\u95f2\uff0c\u4e14\u4efb\u52a1\u961f\u5217\u4e2d\u6ca1\u6709\u9700\u8981\u6267\u884c\u7684\u4efb\u52a1\uff0c\u5219 CPU \u4fdd\u6301\u7a7a\u95f2\u72b6\u6001\u3002
  • \n\t
  • \u5982\u679c CPU \u7a7a\u95f2\uff0c\u4f46\u4efb\u52a1\u961f\u5217\u4e2d\u6709\u9700\u8981\u6267\u884c\u7684\u4efb\u52a1\uff0c\u5219 CPU \u5c06\u4f1a\u9009\u62e9 \u6267\u884c\u65f6\u95f4\u6700\u77ed \u7684\u4efb\u52a1\u5f00\u59cb\u6267\u884c\u3002\u5982\u679c\u591a\u4e2a\u4efb\u52a1\u5177\u6709\u540c\u6837\u7684\u6700\u77ed\u6267\u884c\u65f6\u95f4\uff0c\u5219\u9009\u62e9\u4e0b\u6807\u6700\u5c0f\u7684\u4efb\u52a1\u5f00\u59cb\u6267\u884c\u3002
  • \n\t
  • \u4e00\u65e6\u67d0\u9879\u4efb\u52a1\u5f00\u59cb\u6267\u884c\uff0cCPU \u5728 \u6267\u884c\u5b8c\u6574\u4e2a\u4efb\u52a1 \u524d\u90fd\u4e0d\u4f1a\u505c\u6b62\u3002
  • \n\t
  • CPU \u53ef\u4ee5\u5728\u5b8c\u6210\u4e00\u9879\u4efb\u52a1\u540e\uff0c\u7acb\u5373\u5f00\u59cb\u6267\u884c\u4e00\u9879\u65b0\u4efb\u52a1\u3002
  • \n
\n\n

\u8fd4\u56de CPU \u5904\u7406\u4efb\u52a1\u7684\u987a\u5e8f\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1atasks = [[1,2],[2,4],[3,2],[4,1]]\n\u8f93\u51fa\uff1a[0,2,3,1]\n\u89e3\u91ca\uff1a\u4e8b\u4ef6\u6309\u4e0b\u8ff0\u6d41\u7a0b\u8fd0\u884c\uff1a \n- time = 1 \uff0c\u4efb\u52a1 0 \u8fdb\u5165\u4efb\u52a1\u961f\u5217\uff0c\u53ef\u6267\u884c\u4efb\u52a1\u9879 = {0}\n- \u540c\u6837\u5728 time = 1 \uff0c\u7a7a\u95f2\u72b6\u6001\u7684 CPU \u5f00\u59cb\u6267\u884c\u4efb\u52a1 0 \uff0c\u53ef\u6267\u884c\u4efb\u52a1\u9879 = {}\n- time = 2 \uff0c\u4efb\u52a1 1 \u8fdb\u5165\u4efb\u52a1\u961f\u5217\uff0c\u53ef\u6267\u884c\u4efb\u52a1\u9879 = {1}\n- time = 3 \uff0c\u4efb\u52a1 2 \u8fdb\u5165\u4efb\u52a1\u961f\u5217\uff0c\u53ef\u6267\u884c\u4efb\u52a1\u9879 = {1, 2}\n- \u540c\u6837\u5728 time = 3 \uff0cCPU \u5b8c\u6210\u4efb\u52a1 0 \u5e76\u5f00\u59cb\u6267\u884c\u961f\u5217\u4e2d\u7528\u65f6\u6700\u77ed\u7684\u4efb\u52a1 2 \uff0c\u53ef\u6267\u884c\u4efb\u52a1\u9879 = {1}\n- time = 4 \uff0c\u4efb\u52a1 3 \u8fdb\u5165\u4efb\u52a1\u961f\u5217\uff0c\u53ef\u6267\u884c\u4efb\u52a1\u9879 = {1, 3}\n- time = 5 \uff0cCPU \u5b8c\u6210\u4efb\u52a1 2 \u5e76\u5f00\u59cb\u6267\u884c\u961f\u5217\u4e2d\u7528\u65f6\u6700\u77ed\u7684\u4efb\u52a1 3 \uff0c\u53ef\u6267\u884c\u4efb\u52a1\u9879 = {1}\n- time = 6 \uff0cCPU \u5b8c\u6210\u4efb\u52a1 3 \u5e76\u5f00\u59cb\u6267\u884c\u4efb\u52a1 1 \uff0c\u53ef\u6267\u884c\u4efb\u52a1\u9879 = {}\n- time = 10 \uff0cCPU \u5b8c\u6210\u4efb\u52a1 1 \u5e76\u8fdb\u5165\u7a7a\u95f2\u72b6\u6001\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1atasks = [[7,10],[7,12],[7,5],[7,4],[7,2]]\n\u8f93\u51fa\uff1a[4,3,2,0,1]\n\u89e3\u91ca\uff1a\u4e8b\u4ef6\u6309\u4e0b\u8ff0\u6d41\u7a0b\u8fd0\u884c\uff1a \n- time = 7 \uff0c\u6240\u6709\u4efb\u52a1\u540c\u65f6\u8fdb\u5165\u4efb\u52a1\u961f\u5217\uff0c\u53ef\u6267\u884c\u4efb\u52a1\u9879  = {0,1,2,3,4}\n- \u540c\u6837\u5728 time = 7 \uff0c\u7a7a\u95f2\u72b6\u6001\u7684 CPU \u5f00\u59cb\u6267\u884c\u4efb\u52a1 4 \uff0c\u53ef\u6267\u884c\u4efb\u52a1\u9879 = {0,1,2,3}\n- time = 9 \uff0cCPU \u5b8c\u6210\u4efb\u52a1 4 \u5e76\u5f00\u59cb\u6267\u884c\u4efb\u52a1 3 \uff0c\u53ef\u6267\u884c\u4efb\u52a1\u9879 = {0,1,2}\n- time = 13 \uff0cCPU \u5b8c\u6210\u4efb\u52a1 3 \u5e76\u5f00\u59cb\u6267\u884c\u4efb\u52a1 2 \uff0c\u53ef\u6267\u884c\u4efb\u52a1\u9879 = {0,1}\n- time = 18 \uff0cCPU \u5b8c\u6210\u4efb\u52a1 2 \u5e76\u5f00\u59cb\u6267\u884c\u4efb\u52a1 0 \uff0c\u53ef\u6267\u884c\u4efb\u52a1\u9879 = {1}\n- time = 28 \uff0cCPU \u5b8c\u6210\u4efb\u52a1 0 \u5e76\u5f00\u59cb\u6267\u884c\u4efb\u52a1 1 \uff0c\u53ef\u6267\u884c\u4efb\u52a1\u9879 = {}\n- time = 40 \uff0cCPU \u5b8c\u6210\u4efb\u52a1 1 \u5e76\u8fdb\u5165\u7a7a\u95f2\u72b6\u6001
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • tasks.length == n
  • \n\t
  • 1 <= n <= 105
  • \n\t
  • 1 <= enqueueTimei, processingTimei <= 109
  • \n
\n", "tags_en": ["Heap"], "tags_cn": ["\u5806"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector getOrder(vector>& tasks) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] getOrder(int[][] tasks) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getOrder(self, tasks):\n \"\"\"\n :type tasks: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getOrder(self, tasks: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* getOrder(int** tasks, int tasksSize, int* tasksColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] GetOrder(int[][] tasks) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} tasks\n * @return {number[]}\n */\nvar getOrder = function(tasks) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} tasks\n# @return {Integer[]}\ndef get_order(tasks)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getOrder(_ tasks: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getOrder(tasks [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getOrder(tasks: Array[Array[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getOrder(tasks: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_order(tasks: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $tasks\n * @return Integer[]\n */\n function getOrder($tasks) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getOrder(tasks: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-order tasks)\n (-> (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1834](https://leetcode-cn.com/problems/single-threaded-cpu)", "[\u5355\u7ebf\u7a0b CPU](/solution/1800-1899/1834.Single-Threaded%20CPU/README.md)", "`\u5806`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1834](https://leetcode.com/problems/single-threaded-cpu)", "[Single-Threaded CPU](/solution/1800-1899/1834.Single-Threaded%20CPU/README_EN.md)", "`Heap`", "Medium", ""]}, {"question_id": "1961", "frontend_question_id": "1833", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-ice-cream-bars", "url_en": "https://leetcode.com/problems/maximum-ice-cream-bars", "relative_path_cn": "/solution/1800-1899/1833.Maximum%20Ice%20Cream%20Bars/README.md", "relative_path_en": "/solution/1800-1899/1833.Maximum%20Ice%20Cream%20Bars/README_EN.md", "title_cn": "\u96ea\u7cd5\u7684\u6700\u5927\u6570\u91cf", "title_en": "Maximum Ice Cream Bars", "question_title_slug": "maximum-ice-cream-bars", "content_en": "

It is a sweltering summer day, and a boy wants to buy some ice cream bars.

\r\n\r\n

At the store, there are n ice cream bars. You are given an array costs of length n, where costs[i] is the price of the ith ice cream bar in coins. The boy initially has coins coins to spend, and he wants to buy as many ice cream bars as possible. 

\r\n\r\n

Return the maximum number of ice cream bars the boy can buy with coins coins.

\r\n\r\n

Note: The boy can buy the ice cream bars in any order.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: costs = [1,3,2,4,1], coins = 7\r\nOutput: 4\r\nExplanation: The boy can buy ice cream bars at indices 0,1,2,4 for a total price of 1 + 3 + 2 + 1 = 7.\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: costs = [10,6,8,7,7,8], coins = 5\r\nOutput: 0\r\nExplanation: The boy cannot afford any of the ice cream bars.\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: costs = [1,6,3,1,2,5], coins = 20\r\nOutput: 6\r\nExplanation: The boy can buy all the ice cream bars for a total price of 1 + 6 + 3 + 1 + 2 + 5 = 18.\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • costs.length == n
  • \r\n\t
  • 1 <= n <= 105
  • \r\n\t
  • 1 <= costs[i] <= 105
  • \r\n\t
  • 1 <= coins <= 108
  • \r\n
", "content_cn": "

\u590f\u65e5\u708e\u708e\uff0c\u5c0f\u7537\u5b69 Tony \u60f3\u4e70\u4e00\u4e9b\u96ea\u7cd5\u6d88\u6d88\u6691\u3002

\n\n

\u5546\u5e97\u4e2d\u65b0\u5230 n \u652f\u96ea\u7cd5\uff0c\u7528\u957f\u5ea6\u4e3a n \u7684\u6570\u7ec4 costs \u8868\u793a\u96ea\u7cd5\u7684\u5b9a\u4ef7\uff0c\u5176\u4e2d costs[i] \u8868\u793a\u7b2c i \u652f\u96ea\u7cd5\u7684\u73b0\u91d1\u4ef7\u683c\u3002Tony \u4e00\u5171\u6709 coins \u73b0\u91d1\u53ef\u4ee5\u7528\u4e8e\u6d88\u8d39\uff0c\u4ed6\u60f3\u8981\u4e70\u5c3d\u53ef\u80fd\u591a\u7684\u96ea\u7cd5\u3002

\n\n

\u7ed9\u4f60\u4ef7\u683c\u6570\u7ec4 costs \u548c\u73b0\u91d1\u91cf coins \uff0c\u8bf7\u4f60\u8ba1\u7b97\u5e76\u8fd4\u56de Tony \u7528 coins \u73b0\u91d1\u80fd\u591f\u4e70\u5230\u7684\u96ea\u7cd5\u7684 \u6700\u5927\u6570\u91cf \u3002

\n\n

\u6ce8\u610f\uff1aTony \u53ef\u4ee5\u6309\u4efb\u610f\u987a\u5e8f\u8d2d\u4e70\u96ea\u7cd5\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1acosts = [1,3,2,4,1], coins = 7\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1aTony \u53ef\u4ee5\u4e70\u4e0b\u6807\u4e3a 0\u30011\u30012\u30014 \u7684\u96ea\u7cd5\uff0c\u603b\u4ef7\u4e3a 1 + 3 + 2 + 1 = 7\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1acosts = [10,6,8,7,7,8], coins = 5\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1aTony \u6ca1\u6709\u8db3\u591f\u7684\u94b1\u4e70\u4efb\u4f55\u4e00\u652f\u96ea\u7cd5\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1acosts = [1,6,3,1,2,5], coins = 20\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1aTony \u53ef\u4ee5\u4e70\u4e0b\u6240\u6709\u7684\u96ea\u7cd5\uff0c\u603b\u4ef7\u4e3a 1 + 6 + 3 + 1 + 2 + 5 = 18 \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • costs.length == n
  • \n\t
  • 1 <= n <= 105
  • \n\t
  • 1 <= costs[i] <= 105
  • \n\t
  • 1 <= coins <= 108
  • \n
\n", "tags_en": ["Sort", "Array"], "tags_cn": ["\u6392\u5e8f", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxIceCream(vector& costs, int coins) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxIceCream(int[] costs, int coins) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxIceCream(self, costs, coins):\n \"\"\"\n :type costs: List[int]\n :type coins: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxIceCream(self, costs: List[int], coins: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxIceCream(int* costs, int costsSize, int coins){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxIceCream(int[] costs, int coins) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} costs\n * @param {number} coins\n * @return {number}\n */\nvar maxIceCream = function(costs, coins) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} costs\n# @param {Integer} coins\n# @return {Integer}\ndef max_ice_cream(costs, coins)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxIceCream(_ costs: [Int], _ coins: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxIceCream(costs []int, coins int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxIceCream(costs: Array[Int], coins: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxIceCream(costs: IntArray, coins: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_ice_cream(costs: Vec, coins: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $costs\n * @param Integer $coins\n * @return Integer\n */\n function maxIceCream($costs, $coins) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxIceCream(costs: number[], coins: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-ice-cream costs coins)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1833](https://leetcode-cn.com/problems/maximum-ice-cream-bars)", "[\u96ea\u7cd5\u7684\u6700\u5927\u6570\u91cf](/solution/1800-1899/1833.Maximum%20Ice%20Cream%20Bars/README.md)", "`\u6392\u5e8f`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1833](https://leetcode.com/problems/maximum-ice-cream-bars)", "[Maximum Ice Cream Bars](/solution/1800-1899/1833.Maximum%20Ice%20Cream%20Bars/README_EN.md)", "`Sort`,`Array`", "Medium", ""]}, {"question_id": "1960", "frontend_question_id": "1832", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/check-if-the-sentence-is-pangram", "url_en": "https://leetcode.com/problems/check-if-the-sentence-is-pangram", "relative_path_cn": "/solution/1800-1899/1832.Check%20if%20the%20Sentence%20Is%20Pangram/README.md", "relative_path_en": "/solution/1800-1899/1832.Check%20if%20the%20Sentence%20Is%20Pangram/README_EN.md", "title_cn": "\u5224\u65ad\u53e5\u5b50\u662f\u5426\u4e3a\u5168\u5b57\u6bcd\u53e5", "title_en": "Check if the Sentence Is Pangram", "question_title_slug": "check-if-the-sentence-is-pangram", "content_en": "

A pangram is a sentence where every letter of the English alphabet appears at least once.

\n\n

Given a string sentence containing only lowercase English letters, return true if sentence is a pangram, or false otherwise.

\n\n

 

\n

Example 1:

\n\n
\nInput: sentence = "thequickbrownfoxjumpsoverthelazydog"\nOutput: true\nExplanation: sentence contains at least one of every letter of the English alphabet.\n
\n\n

Example 2:

\n\n
\nInput: sentence = "leetcode"\nOutput: false\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= sentence.length <= 1000
  • \n\t
  • sentence consists of lowercase English letters.
  • \n
\n", "content_cn": "

\u5168\u5b57\u6bcd\u53e5 \u6307\u5305\u542b\u82f1\u8bed\u5b57\u6bcd\u8868\u4e2d\u6bcf\u4e2a\u5b57\u6bcd\u81f3\u5c11\u4e00\u6b21\u7684\u53e5\u5b50\u3002

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\u7684\u5b57\u7b26\u4e32 sentence \uff0c\u8bf7\u4f60\u5224\u65ad\u00a0sentence \u662f\u5426\u4e3a \u5168\u5b57\u6bcd\u53e5 \u3002

\n\n

\u5982\u679c\u662f\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1asentence = \"thequickbrownfoxjumpsoverthelazydog\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1asentence \u5305\u542b\u82f1\u8bed\u5b57\u6bcd\u8868\u4e2d\u6bcf\u4e2a\u5b57\u6bcd\u81f3\u5c11\u4e00\u6b21\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1asentence = \"leetcode\"\n\u8f93\u51fa\uff1afalse\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= sentence.length <= 1000
  • \n\t
  • sentence \u7531\u5c0f\u5199\u82f1\u8bed\u5b57\u6bcd\u7ec4\u6210
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool checkIfPangram(string sentence) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean checkIfPangram(String sentence) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def checkIfPangram(self, sentence):\n \"\"\"\n :type sentence: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def checkIfPangram(self, sentence: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool checkIfPangram(char * sentence){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CheckIfPangram(string sentence) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} sentence\n * @return {boolean}\n */\nvar checkIfPangram = function(sentence) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} sentence\n# @return {Boolean}\ndef check_if_pangram(sentence)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func checkIfPangram(_ sentence: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func checkIfPangram(sentence string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def checkIfPangram(sentence: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun checkIfPangram(sentence: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn check_if_pangram(sentence: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $sentence\n * @return Boolean\n */\n function checkIfPangram($sentence) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function checkIfPangram(sentence: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (check-if-pangram sentence)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1832](https://leetcode-cn.com/problems/check-if-the-sentence-is-pangram)", "[\u5224\u65ad\u53e5\u5b50\u662f\u5426\u4e3a\u5168\u5b57\u6bcd\u53e5](/solution/1800-1899/1832.Check%20if%20the%20Sentence%20Is%20Pangram/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1832](https://leetcode.com/problems/check-if-the-sentence-is-pangram)", "[Check if the Sentence Is Pangram](/solution/1800-1899/1832.Check%20if%20the%20Sentence%20Is%20Pangram/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1959", "frontend_question_id": "1810", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/minimum-path-cost-in-a-hidden-grid", "url_en": "https://leetcode.com/problems/minimum-path-cost-in-a-hidden-grid", "relative_path_cn": "/solution/1800-1899/1810.Minimum%20Path%20Cost%20in%20a%20Hidden%20Grid/README.md", "relative_path_en": "/solution/1800-1899/1810.Minimum%20Path%20Cost%20in%20a%20Hidden%20Grid/README_EN.md", "title_cn": "", "title_en": "Minimum Path Cost in a Hidden Grid", "question_title_slug": "minimum-path-cost-in-a-hidden-grid", "content_en": "

This is an interactive problem.

\n\n

There is a robot in a hidden grid, and you are trying to get it from its starting cell to the target cell in this grid. The grid is of size m x n, and each cell in the grid is either empty or blocked. It is guaranteed that the starting cell and the target cell are different, and neither of them is blocked.

\n\n

Each cell has a cost that you need to pay each time you move to the cell. The starting cell's cost is not applied before the robot moves.

\n\n

You want to find the minimum total cost to move the robot to the target cell. However, you do not know the grid's dimensions, the starting cell, nor the target cell. You are only allowed to ask queries to the GridMaster object.

\n\n

The GridMaster class has the following functions:

\n\n
    \n\t
  • boolean canMove(char direction) Returns true if the robot can move in that direction. Otherwise, it returns false.
  • \n\t
  • int move(char direction) Moves the robot in that direction and returns the cost of moving to that cell. If this move would move the robot to a blocked cell or off the grid, the move will be ignored, the robot will remain in the same position, and the function will return -1.
  • \n\t
  • boolean isTarget() Returns true if the robot is currently on the target cell. Otherwise, it returns false.
  • \n
\n\n

Note that direction in the above functions should be a character from {'U','D','L','R'}, representing the directions up, down, left, and right, respectively.

\n\n

Return the minimum total cost to get the robot from its initial starting cell to the target cell. If there is no valid path between the cells, return -1.

\n\n

Custom testing:

\n\n

The test input is read as a 2D matrix grid of size m x n and four integers r1, c1, r2, and c2 where:

\n\n
    \n\t
  • grid[i][j] == 0 indicates that the cell (i, j) is blocked.
  • \n\t
  • grid[i][j] >= 1 indicates that the cell (i, j) is empty and grid[i][j] is the cost to move to that cell.
  • \n\t
  • (r1, c1) is the starting cell of the robot.
  • \n\t
  • (r2, c2) is the target cell of the robot.
  • \n
\n\n

Remember that you will not have this information in your code.

\n\n

 

\n

Example 1:

\n\n
\nInput: grid = [[2,3],[1,1]], r1 = 0, c1 = 1, r2 = 1, c2 = 0\nOutput: 2\nExplanation: One possible interaction is described below:\nThe robot is initially standing on cell (0, 1), denoted by the 3.\n- master.canMove('U') returns false.\n- master.canMove('D') returns true.\n- master.canMove('L') returns true.\n- master.canMove('R') returns false.\n- master.move('L') moves the robot to the cell (0, 0) and returns 2.\n- master.isTarget() returns false.\n- master.canMove('U') returns false.\n- master.canMove('D') returns true.\n- master.canMove('L') returns false.\n- master.canMove('R') returns true.\n- master.move('D') moves the robot to the cell (1, 0) and returns 1.\n- master.isTarget() returns true.\n- master.move('L') doesn't move the robot and returns -1.\n- master.move('R') moves the robot to the cell (1, 1) and returns 1.\nWe now know that the target is the cell (0, 1), and the minimum total cost to reach it is 2. 
\n\n

Example 2:

\n\n
\nInput: grid = [[0,3,1],[3,4,2],[1,2,0]], r1 = 2, c1 = 0, r2 = 0, c2 = 2\nOutput: 9\nExplanation: The minimum cost path is (2,0) -> (2,1) -> (1,1) -> (1,2) -> (0,2).\n
\n\n

Example 3:

\n\n
\nInput: grid = [[1,0],[0,1]], r1 = 0, c1 = 0, r2 = 1, c2 = 1\nOutput: -1\nExplanation: There is no path from the robot to the target cell.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n, m <= 100
  • \n\t
  • m == grid.length
  • \n\t
  • n == grid[i].length
  • \n\t
  • 0 <= grid[i][j] <= 100
  • \n
\n", "content_cn": null, "tags_en": ["Heap", "Depth-first Search", "Graph"], "tags_cn": ["\u5806", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * // This is the GridMaster's API interface.\n * // You should not implement it, or speculate about its implementation\n * class GridMaster {\n * public:\n * bool canMove(char direction);\n * int move(char direction);\n * boolean isTarget();\n * };\n */\n\nclass Solution {\npublic:\n int findShortestPath(GridMaster &master) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * // This is the GridMaster's API interface.\n * // You should not implement it, or speculate about its implementation\n * class GridMaster {\n * boolean canMove(char direction);\n * int move(char direction);\n * boolean isTarget();\n * }\n */\n\nclass Solution {\n public int findShortestPath(GridMaster master) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# \"\"\"\n# This is GridMaster's API interface.\n# You should not implement it, or speculate about it's implementation\n# \"\"\"\n#class GridMaster(object):\n# def canMove(self, direction):\n# \"\"\"\n# :type direction: str\n# :rtype bool\n# \"\"\"\n#\n# def move(self, direction):\n# \"\"\"\n# :type direction: str\n#. :rtype int\n# \"\"\"\n#\n# def isTarget(self):\n# \"\"\"\n# :rtype bool\n# \"\"\"\n#\n\nclass Solution(object):\n def findShortestPath(self, master):\n \"\"\"\n :type master: GridMaster\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# \"\"\"\n# This is GridMaster's API interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class GridMaster(object):\n# def canMove(self, direction: str) -> bool:\n# \n#\n# def move(self, direction: str) -> int:\n# \n#\n# def isTarget(self) -> None:\n# \n#\n\nclass Solution(object):\n def findShortestPath(self, master: 'GridMaster') -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * // This is the GridMaster's API interface.\n * // You should not implement it, or speculate about its implementation\n * class GridMaster {\n * bool canMove(char direction);\n * int move(char direction);\n * bool isTarget();\n * };\n */\n\nclass Solution {\n public int FindShortestPath(GridMaster master) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // This is the GridMaster's API interface.\n * // You should not implement it, or speculate about its implementation\n * function GridMaster() {\n *\n * @param {character} direction\n * @return {boolean}\n * this.canMove = function(direction) {\n * ...\n * };\n * @param {character} direction\n * @return {integer}\n * this.move = function(direction) {\n * ...\n * };\n * @return {boolean}\n * this.isTarget = function() {\n * ...\n * };\n * };\n */\n\n/**\n * @param {GridMaster} master\n * @return {integer}\n */\nvar findShortestPath = function(master) {\n \n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1810](https://leetcode-cn.com/problems/minimum-path-cost-in-a-hidden-grid)", "[Minimum Path Cost in a Hidden Grid](/solution/1800-1899/1810.Minimum%20Path%20Cost%20in%20a%20Hidden%20Grid/README_EN.md)", "`\u5806`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u56fe`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1810](https://leetcode.com/problems/minimum-path-cost-in-a-hidden-grid)", "[Minimum Path Cost in a Hidden Grid](/solution/1800-1899/1810.Minimum%20Path%20Cost%20in%20a%20Hidden%20Grid/README_EN.md)", "`Heap`,`Depth-first Search`,`Graph`", "Medium", "\ud83d\udd12"]}, {"question_id": "1958", "frontend_question_id": "1809", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/ad-free-sessions", "url_en": "https://leetcode.com/problems/ad-free-sessions", "relative_path_cn": "/solution/1800-1899/1809.Ad-Free%20Sessions/README.md", "relative_path_en": "/solution/1800-1899/1809.Ad-Free%20Sessions/README_EN.md", "title_cn": "\u6ca1\u6709\u5e7f\u544a\u7684\u5267\u96c6", "title_en": "Ad-Free Sessions", "question_title_slug": "ad-free-sessions", "content_en": "

Table: Playback

\n\n
\n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| session_id  | int  |\n| customer_id | int  |\n| start_time  | int  |\n| end_time    | int  |\n+-------------+------+\nsession_id is the primary key for this table.\ncustomer_id is the ID of the customer watching this session.\nThe session runs during the inclusive interval between start_time and end_time.\nIt is guaranteed that start_time <= end_time and that two sessions for the same customer do not intersect.
\n\n

 

\n\n

Table: Ads

\n\n
\n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| ad_id       | int  |\n| customer_id | int  |\n| timestamp   | int  |\n+-------------+------+\nad_id is the primary key for this table.\ncustomer_id is the ID of the customer viewing this ad.\ntimestamp is the moment of time at which the ad was shown.\n
\n\n

 

\n\n

Write an SQL query to report all the sessions that did not get shown any ads.

\n\n

Return the result table in any order.

\n\n

The query result format is in the following example:

\n\n

 

\n\n
\nPlayback table:\n+------------+-------------+------------+----------+\n| session_id | customer_id | start_time | end_time |\n+------------+-------------+------------+----------+\n| 1          | 1           | 1          | 5        |\n| 2          | 1           | 15         | 23       |\n| 3          | 2           | 10         | 12       |\n| 4          | 2           | 17         | 28       |\n| 5          | 2           | 2          | 8        |\n+------------+-------------+------------+----------+\n\nAds table:\n+-------+-------------+-----------+\n| ad_id | customer_id | timestamp |\n+-------+-------------+-----------+\n| 1     | 1           | 5         |\n| 2     | 2           | 17        |\n| 3     | 2           | 20        |\n+-------+-------------+-----------+\n\nResult table:\n+------------+\n| session_id |\n+------------+\n| 2          |\n| 3          |\n| 5          |\n+------------+\nThe ad with ID 1 was shown to user 1 at time 5 while they were in session 1.\nThe ad with ID 2 was shown to user 2 at time 17 while they were in session 4.\nThe ad with ID 3 was shown to user 2 at time 20 while they were in session 4.\nWe can see that sessions 1 and 4 had at least one ad. Sessions 2, 3, and 5 did not have any ads, so we return them.
\n", "content_cn": "

Table: Playback

\n\n
+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| session_id  | int  |\n| customer_id | int  |\n| start_time  | int  |\n| end_time    | int  |\n+-------------+------+\n\u8be5\u8868\u4e3b\u952e\u4e3a\uff1asession_id \uff08\u5267\u96c6id\uff09\ncustomer_id \u662f\u89c2\u770b\u8be5\u5267\u96c6\u7684\u89c2\u4f17id\n\u5267\u96c6\u64ad\u653e\u65f6\u95f4\u5305\u542bstart_time\uff08\u5f00\u59cb\u65f6\u95f4\uff09 \u53ca end_time\uff08\u7ed3\u675f\u65f6\u95f4\uff09\n\u53ef\u4ee5\u4fdd\u8bc1\u7684\u662f\uff0cstart_time\uff08\u5f00\u59cb\u65f6\u95f4\uff09<= end_time\uff08\u7ed3\u675f\u65f6\u95f4\uff09\uff0c\u4e00\u4e2a\u89c2\u4f17\u89c2\u770b\u7684\u4e24\u4e2a\u5267\u96c6\u7684\u65f6\u95f4\u4e0d\u4f1a\u51fa\u73b0\u91cd\u53e0\u3002
\n\n

\u00a0

\n\n

Table: Ads

\n\n
+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| ad_id       | int  |\n| customer_id | int  |\n| timestamp   | int  |\n+-------------+------+\n\u8be5\u8868\u7684\u4e3b\u952e\u4e3a\uff1aad_id\uff08\u5e7f\u544aid\uff09\ncustomer_id \u4e3a \u89c2\u770b\u5e7f\u544a\u7684\u7528\u6237id\ntimestamp \u8868\u793a\u5e7f\u544a\u51fa\u73b0\u7684\u65f6\u95f4\u70b9\n
\n\n

\u00a0

\n\n

\u8bf7\u67e5\u51fa\uff0c\u6240\u6709\u6ca1\u6709\u5e7f\u544a\u51fa\u73b0\u8fc7\u7684\u5267\u96c6\u3002

\n\n

\u5982\u679c\u89c2\u4f17\u89c2\u770b\u4e86\u5267\u96c6\uff0c\u5e76\u4e14\u5267\u96c6\u91cc\u51fa\u73b0\u4e86\u5e7f\u544a\uff0c\u5c31\u4e00\u5b9a\u4f1a\u6709\u89c2\u4f17\u89c2\u770b\u5e7f\u544a\u7684\u8bb0\u5f55\u3002

\n\n

\u8fd4\u56de\u7ed3\u679c\u6ca1\u6709\u987a\u5e8f\u8981\u6c42\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b\uff1a

\n\n
Playback table:\n+------------+-------------+------------+----------+\n| session_id | customer_id | start_time | end_time |\n+------------+-------------+------------+----------+\n| 1          | 1           | 1          | 5        |\n| 2          | 1           | 15         | 23       |\n| 3          | 2           | 10         | 12       |\n| 4          | 2           | 17         | 28       |\n| 5          | 2           | 2          | 8        |\n+------------+-------------+------------+----------+\n\nAds table:\n+-------+-------------+-----------+\n| ad_id | customer_id | timestamp |\n+-------+-------------+-----------+\n| 1     | 1           | 5         |\n| 2     | 2           | 17        |\n| 3     | 2           | 20        |\n+-------+-------------+-----------+\n\nResult table:\n+------------+\n| session_id |\n+------------+\n| 2          |\n| 3          |\n| 5          |\n+------------+\n\u5e7f\u544a1\u51fa\u73b0\u5728\u4e86\u5267\u96c61\u7684\u65f6\u95f4\u6bb5\uff0c\u88ab\u89c2\u4f171\u770b\u5230\u4e86\u3002\n\u5e7f\u544a2\u51fa\u73b0\u5728\u4e86\u5267\u96c64\u7684\u65f6\u95f4\u6bb5\uff0c\u88ab\u89c2\u4f172\u770b\u5230\u4e86\u3002\n\u5e7f\u544a3\u51fa\u73b0\u5728\u4e86\u5267\u96c64\u7684\u65f6\u95f4\u6bb5\uff0c\u88ab\u89c2\u4f172\u770b\u5230\u4e86\u3002\n\u6211\u4eec\u53ef\u4ee5\u5f97\u51fa\u7ed3\u8bba\uff0c\u5267\u96c61 \u30014 \u5185\uff0c\u8d77\u7801\u67091\u5904\u5e7f\u544a\u3002 \u5267\u96c62 \u30013 \u30015 \u6ca1\u6709\u5e7f\u544a\u3002
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1809](https://leetcode-cn.com/problems/ad-free-sessions)", "[\u6ca1\u6709\u5e7f\u544a\u7684\u5267\u96c6](/solution/1800-1899/1809.Ad-Free%20Sessions/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1809](https://leetcode.com/problems/ad-free-sessions)", "[Ad-Free Sessions](/solution/1800-1899/1809.Ad-Free%20Sessions/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1957", "frontend_question_id": "1847", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/closest-room", "url_en": "https://leetcode.com/problems/closest-room", "relative_path_cn": "/solution/1800-1899/1847.Closest%20Room/README.md", "relative_path_en": "/solution/1800-1899/1847.Closest%20Room/README_EN.md", "title_cn": "\u6700\u8fd1\u7684\u623f\u95f4", "title_en": "Closest Room", "question_title_slug": "closest-room", "content_en": "

There is a hotel with n rooms. The rooms are represented by a 2D integer array rooms where rooms[i] = [roomIdi, sizei] denotes that there is a room with room number roomIdi and size equal to sizei. Each roomIdi is guaranteed to be unique.

\n\n

You are also given k queries in a 2D array queries where queries[j] = [preferredj, minSizej]. The answer to the jth query is the room number id of a room such that:

\n\n
    \n\t
  • The room has a size of at least minSizej, and
  • \n\t
  • abs(id - preferredj) is minimized, where abs(x) is the absolute value of x.
  • \n
\n\n

If there is a tie in the absolute difference, then use the room with the smallest such id. If there is no such room, the answer is -1.

\n\n

Return an array answer of length k where answer[j] contains the answer to the jth query.

\n\n

 

\n

Example 1:

\n\n
\nInput: rooms = [[2,2],[1,2],[3,2]], queries = [[3,1],[3,3],[5,2]]\nOutput: [3,-1,3]\nExplanation: The answers to the queries are as follows:\nQuery = [3,1]: Room number 3 is the closest as abs(3 - 3) = 0, and its size of 2 is at least 1. The answer is 3.\nQuery = [3,3]: There are no rooms with a size of at least 3, so the answer is -1.\nQuery = [5,2]: Room number 3 is the closest as abs(3 - 5) = 2, and its size of 2 is at least 2. The answer is 3.
\n\n

Example 2:

\n\n
\nInput: rooms = [[1,4],[2,3],[3,5],[4,1],[5,2]], queries = [[2,3],[2,4],[2,5]]\nOutput: [2,1,3]\nExplanation: The answers to the queries are as follows:\nQuery = [2,3]: Room number 2 is the closest as abs(2 - 2) = 0, and its size of 3 is at least 3. The answer is 2.\nQuery = [2,4]: Room numbers 1 and 3 both have sizes of at least 4. The answer is 1 since it is smaller.\nQuery = [2,5]: Room number 3 is the only room with a size of at least 5. The answer is 3.
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == rooms.length
  • \n\t
  • 1 <= n <= 105
  • \n\t
  • k == queries.length
  • \n\t
  • 1 <= k <= 104
  • \n\t
  • 1 <= roomIdi, preferredj <= 107
  • \n\t
  • 1 <= sizei, minSizej <= 107
  • \n\t
  •  
  • \n
\n", "content_cn": "

\u4e00\u4e2a\u9152\u5e97\u91cc\u6709\u00a0n\u00a0\u4e2a\u623f\u95f4\uff0c\u8fd9\u4e9b\u623f\u95f4\u7528\u4e8c\u7ef4\u6574\u6570\u6570\u7ec4\u00a0rooms\u00a0\u8868\u793a\uff0c\u5176\u4e2d\u00a0rooms[i] = [roomIdi, sizei]\u00a0\u8868\u793a\u6709\u4e00\u4e2a\u623f\u95f4\u53f7\u4e3a\u00a0roomIdi\u00a0\u7684\u623f\u95f4\u4e14\u5b83\u7684\u9762\u79ef\u4e3a\u00a0sizei\u00a0\u3002\u6bcf\u4e00\u4e2a\u623f\u95f4\u53f7\u00a0roomIdi\u00a0\u4fdd\u8bc1\u662f \u72ec\u4e00\u65e0\u4e8c\u00a0\u7684\u3002

\n\n

\u540c\u65f6\u7ed9\u4f60 k\u00a0\u4e2a\u67e5\u8be2\uff0c\u7528\u4e8c\u7ef4\u6570\u7ec4\u00a0queries\u00a0\u8868\u793a\uff0c\u5176\u4e2d\u00a0queries[j] = [preferredj, minSizej]\u00a0\u3002\u7b2c\u00a0j\u00a0\u4e2a\u67e5\u8be2\u7684\u7b54\u6848\u662f\u6ee1\u8db3\u5982\u4e0b\u6761\u4ef6\u7684\u623f\u95f4\u00a0id\u00a0\uff1a

\n\n
    \n\t
  • \u623f\u95f4\u7684\u9762\u79ef\u00a0\u81f3\u5c11\u00a0\u4e3a\u00a0minSizej\u00a0\uff0c\u4e14
  • \n\t
  • abs(id - preferredj)\u00a0\u7684\u503c \u6700\u5c0f\u00a0\uff0c\u5176\u4e2d\u00a0abs(x)\u00a0\u662f\u00a0x\u00a0\u7684\u7edd\u5bf9\u503c\u3002
  • \n
\n\n

\u5982\u679c\u5dee\u7684\u7edd\u5bf9\u503c\u6709 \u76f8\u7b49\u00a0\u7684\uff0c\u9009\u62e9 \u6700\u5c0f\u00a0\u7684\u00a0id\u00a0\u3002\u5982\u679c \u6ca1\u6709\u6ee1\u8db3\u6761\u4ef6\u7684\u623f\u95f4\u00a0\uff0c\u7b54\u6848\u4e3a -1\u00a0\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u957f\u5ea6\u4e3a k\u00a0\u7684\u6570\u7ec4\u00a0answer\u00a0\uff0c\u5176\u4e2d\u00a0answer[j]\u00a0\u4e3a\u7b2c j\u00a0\u4e2a\u67e5\u8be2\u7684\u7ed3\u679c\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1arooms = [[2,2],[1,2],[3,2]], queries = [[3,1],[3,3],[5,2]]\n\u8f93\u51fa\uff1a[3,-1,3]\n\u89e3\u91ca\uff1a\u67e5\u8be2\u7684\u7b54\u6848\u5982\u4e0b\uff1a\n\u67e5\u8be2 [3,1] \uff1a\u623f\u95f4 3 \u7684\u9762\u79ef\u4e3a 2 \uff0c\u5927\u4e8e\u7b49\u4e8e 1 \uff0c\u4e14\u53f7\u7801\u662f\u6700\u63a5\u8fd1 3 \u7684\uff0c\u4e3a abs(3 - 3) = 0 \uff0c\u6240\u4ee5\u7b54\u6848\u4e3a 3 \u3002\n\u67e5\u8be2 [3,3] \uff1a\u6ca1\u6709\u623f\u95f4\u7684\u9762\u79ef\u81f3\u5c11\u4e3a 3 \uff0c\u6240\u4ee5\u7b54\u6848\u4e3a -1 \u3002\n\u67e5\u8be2 [5,2] \uff1a\u623f\u95f4 3 \u7684\u9762\u79ef\u4e3a 2 \uff0c\u5927\u4e8e\u7b49\u4e8e 2 \uff0c\u4e14\u53f7\u7801\u662f\u6700\u63a5\u8fd1 5 \u7684\uff0c\u4e3a abs(3 - 5) = 2 \uff0c\u6240\u4ee5\u7b54\u6848\u4e3a 3 \u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1arooms = [[1,4],[2,3],[3,5],[4,1],[5,2]], queries = [[2,3],[2,4],[2,5]]\n\u8f93\u51fa\uff1a[2,1,3]\n\u89e3\u91ca\uff1a\u67e5\u8be2\u7684\u7b54\u6848\u5982\u4e0b\uff1a\n\u67e5\u8be2 [2,3] \uff1a\u623f\u95f4 2 \u7684\u9762\u79ef\u4e3a 3 \uff0c\u5927\u4e8e\u7b49\u4e8e 3 \uff0c\u4e14\u53f7\u7801\u662f\u6700\u63a5\u8fd1\u7684\uff0c\u4e3a abs(2 - 2) = 0 \uff0c\u6240\u4ee5\u7b54\u6848\u4e3a 2 \u3002\n\u67e5\u8be2 [2,4] \uff1a\u623f\u95f4 1 \u548c 3 \u7684\u9762\u79ef\u90fd\u81f3\u5c11\u4e3a 4 \uff0c\u7b54\u6848\u4e3a 1 \u56e0\u4e3a\u5b83\u623f\u95f4\u7f16\u53f7\u66f4\u5c0f\u3002\n\u67e5\u8be2 [2,5] \uff1a\u623f\u95f4 3 \u662f\u552f\u4e00\u9762\u79ef\u5927\u4e8e\u7b49\u4e8e 5 \u7684\uff0c\u6240\u4ee5\u7b54\u6848\u4e3a 3 \u3002
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • n == rooms.length
  • \n\t
  • 1 <= n <= 105
  • \n\t
  • k == queries.length
  • \n\t
  • 1 <= k <= 104
  • \n\t
  • 1 <= roomIdi, preferredj <= 107
  • \n\t
  • 1 <= sizei, minSizej <= 107
  • \n
\n", "tags_en": ["Sort", "Binary Search"], "tags_cn": ["\u6392\u5e8f", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector closestRoom(vector>& rooms, vector>& queries) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] closestRoom(int[][] rooms, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def closestRoom(self, rooms, queries):\n \"\"\"\n :type rooms: List[List[int]]\n :type queries: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def closestRoom(self, rooms: List[List[int]], queries: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* closestRoom(int** rooms, int roomsSize, int* roomsColSize, int** queries, int queriesSize, int* queriesColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] ClosestRoom(int[][] rooms, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} rooms\n * @param {number[][]} queries\n * @return {number[]}\n */\nvar closestRoom = function(rooms, queries) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} rooms\n# @param {Integer[][]} queries\n# @return {Integer[]}\ndef closest_room(rooms, queries)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func closestRoom(_ rooms: [[Int]], _ queries: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func closestRoom(rooms [][]int, queries [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def closestRoom(rooms: Array[Array[Int]], queries: Array[Array[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun closestRoom(rooms: Array, queries: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn closest_room(rooms: Vec>, queries: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $rooms\n * @param Integer[][] $queries\n * @return Integer[]\n */\n function closestRoom($rooms, $queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function closestRoom(rooms: number[][], queries: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (closest-room rooms queries)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1847](https://leetcode-cn.com/problems/closest-room)", "[\u6700\u8fd1\u7684\u623f\u95f4](/solution/1800-1899/1847.Closest%20Room/README.md)", "`\u6392\u5e8f`,`\u4e8c\u5206\u67e5\u627e`", "\u56f0\u96be", ""], "md_table_row_en": ["[1847](https://leetcode.com/problems/closest-room)", "[Closest Room](/solution/1800-1899/1847.Closest%20Room/README_EN.md)", "`Sort`,`Binary Search`", "Hard", ""]}, {"question_id": "1956", "frontend_question_id": "1846", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-element-after-decreasing-and-rearranging", "url_en": "https://leetcode.com/problems/maximum-element-after-decreasing-and-rearranging", "relative_path_cn": "/solution/1800-1899/1846.Maximum%20Element%20After%20Decreasing%20and%20Rearranging/README.md", "relative_path_en": "/solution/1800-1899/1846.Maximum%20Element%20After%20Decreasing%20and%20Rearranging/README_EN.md", "title_cn": "\u51cf\u5c0f\u548c\u91cd\u65b0\u6392\u5217\u6570\u7ec4\u540e\u7684\u6700\u5927\u5143\u7d20", "title_en": "Maximum Element After Decreasing and Rearranging", "question_title_slug": "maximum-element-after-decreasing-and-rearranging", "content_en": "

You are given an array of positive integers arr. Perform some operations (possibly none) on arr so that it satisfies these conditions:

\n\n
    \n\t
  • The value of the first element in arr must be 1.
  • \n\t
  • The absolute difference between any 2 adjacent elements must be less than or equal to 1. In other words, abs(arr[i] - arr[i - 1]) <= 1 for each i where 1 <= i < arr.length (0-indexed). abs(x) is the absolute value of x.
  • \n
\n\n

There are 2 types of operations that you can perform any number of times:

\n\n
    \n\t
  • Decrease the value of any element of arr to a smaller positive integer.
  • \n\t
  • Rearrange the elements of arr to be in any order.
  • \n
\n\n

Return the maximum possible value of an element in arr after performing the operations to satisfy the conditions.

\n\n

 

\n

Example 1:

\n\n
\nInput: arr = [2,2,1,2,1]\nOutput: 2\nExplanation: \nWe can satisfy the conditions by rearranging arr so it becomes [1,2,2,2,1].\nThe largest element in arr is 2.\n
\n\n

Example 2:

\n\n
\nInput: arr = [100,1,1000]\nOutput: 3\nExplanation: \nOne possible way to satisfy the conditions is by doing the following:\n1. Rearrange arr so it becomes [1,100,1000].\n2. Decrease the value of the second element to 2.\n3. Decrease the value of the third element to 3.\nNow arr = [1,2,3], which satisfies the conditions.\nThe largest element in arr is 3.\n
\n\n

Example 3:

\n\n
\nInput: arr = [1,2,3,4,5]\nOutput: 5\nExplanation: The array already satisfies the conditions, and the largest element is 5.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= arr.length <= 105
  • \n\t
  • 1 <= arr[i] <= 109
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6b63\u6574\u6570\u6570\u7ec4\u00a0arr\u00a0\u3002\u8bf7\u4f60\u5bf9 arr\u00a0\u6267\u884c\u4e00\u4e9b\u64cd\u4f5c\uff08\u4e5f\u53ef\u4ee5\u4e0d\u8fdb\u884c\u4efb\u4f55\u64cd\u4f5c\uff09\uff0c\u4f7f\u5f97\u6570\u7ec4\u6ee1\u8db3\u4ee5\u4e0b\u6761\u4ef6\uff1a

\n\n
    \n\t
  • arr\u00a0\u4e2d \u7b2c\u4e00\u4e2a\u00a0\u5143\u7d20\u5fc5\u987b\u4e3a\u00a01\u00a0\u3002
  • \n\t
  • \u4efb\u610f\u76f8\u90bb\u4e24\u4e2a\u5143\u7d20\u7684\u5dee\u7684\u7edd\u5bf9\u503c \u5c0f\u4e8e\u7b49\u4e8e\u00a01\u00a0\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u5bf9\u4e8e\u4efb\u610f\u7684 1 <= i < arr.length\u00a0\uff08\u6570\u7ec4\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\uff0c\u90fd\u6ee1\u8db3\u00a0abs(arr[i] - arr[i - 1]) <= 1\u00a0\u3002abs(x)\u00a0\u4e3a\u00a0x\u00a0\u7684\u7edd\u5bf9\u503c\u3002
  • \n
\n\n

\u4f60\u53ef\u4ee5\u6267\u884c\u4ee5\u4e0b 2 \u79cd\u64cd\u4f5c\u4efb\u610f\u6b21\uff1a

\n\n
    \n\t
  • \u51cf\u5c0f arr\u00a0\u4e2d\u4efb\u610f\u5143\u7d20\u7684\u503c\uff0c\u4f7f\u5176\u53d8\u4e3a\u4e00\u4e2a \u66f4\u5c0f\u7684\u6b63\u6574\u6570\u00a0\u3002
  • \n\t
  • \u91cd\u65b0\u6392\u5217\u00a0arr\u00a0\u4e2d\u7684\u5143\u7d20\uff0c\u4f60\u53ef\u4ee5\u4ee5\u4efb\u610f\u987a\u5e8f\u91cd\u65b0\u6392\u5217\u3002
  • \n
\n\n

\u8bf7\u4f60\u8fd4\u56de\u6267\u884c\u4ee5\u4e0a\u64cd\u4f5c\u540e\uff0c\u5728\u6ee1\u8db3\u524d\u6587\u6240\u8ff0\u7684\u6761\u4ef6\u4e0b\uff0carr\u00a0\u4e2d\u53ef\u80fd\u7684 \u6700\u5927\u503c\u00a0\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [2,2,1,2,1]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n\u6211\u4eec\u53ef\u4ee5\u91cd\u65b0\u6392\u5217 arr \u5f97\u5230 [1,2,2,2,1] \uff0c\u8be5\u6570\u7ec4\u6ee1\u8db3\u6240\u6709\u6761\u4ef6\u3002\narr \u4e2d\u6700\u5927\u5143\u7d20\u4e3a 2 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [100,1,1000]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\n\u4e00\u4e2a\u53ef\u884c\u7684\u65b9\u6848\u5982\u4e0b\uff1a\n1. \u91cd\u65b0\u6392\u5217 arr \u5f97\u5230 [1,100,1000] \u3002\n2. \u5c06\u7b2c\u4e8c\u4e2a\u5143\u7d20\u51cf\u5c0f\u4e3a 2 \u3002\n3. \u5c06\u7b2c\u4e09\u4e2a\u5143\u7d20\u51cf\u5c0f\u4e3a 3 \u3002\n\u73b0\u5728 arr = [1,2,3] \uff0c\u6ee1\u8db3\u6240\u6709\u6761\u4ef6\u3002\narr \u4e2d\u6700\u5927\u5143\u7d20\u4e3a 3 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [1,2,3,4,5]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u6570\u7ec4\u5df2\u7ecf\u6ee1\u8db3\u6240\u6709\u6761\u4ef6\uff0c\u6700\u5927\u5143\u7d20\u4e3a 5 \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= arr.length <= 105
  • \n\t
  • 1 <= arr[i] <= 109
  • \n
\n", "tags_en": ["Greedy", "Sort"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6392\u5e8f"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maximumElementAfterDecrementingAndRearranging(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maximumElementAfterDecrementingAndRearranging(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximumElementAfterDecrementingAndRearranging(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximumElementAfterDecrementingAndRearranging(self, arr: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maximumElementAfterDecrementingAndRearranging(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaximumElementAfterDecrementingAndRearranging(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar maximumElementAfterDecrementingAndRearranging = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef maximum_element_after_decrementing_and_rearranging(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximumElementAfterDecrementingAndRearranging(_ arr: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximumElementAfterDecrementingAndRearranging(arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximumElementAfterDecrementingAndRearranging(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximumElementAfterDecrementingAndRearranging(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximum_element_after_decrementing_and_rearranging(arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function maximumElementAfterDecrementingAndRearranging($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximumElementAfterDecrementingAndRearranging(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximum-element-after-decrementing-and-rearranging arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1846](https://leetcode-cn.com/problems/maximum-element-after-decreasing-and-rearranging)", "[\u51cf\u5c0f\u548c\u91cd\u65b0\u6392\u5217\u6570\u7ec4\u540e\u7684\u6700\u5927\u5143\u7d20](/solution/1800-1899/1846.Maximum%20Element%20After%20Decreasing%20and%20Rearranging/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6392\u5e8f`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1846](https://leetcode.com/problems/maximum-element-after-decreasing-and-rearranging)", "[Maximum Element After Decreasing and Rearranging](/solution/1800-1899/1846.Maximum%20Element%20After%20Decreasing%20and%20Rearranging/README_EN.md)", "`Greedy`,`Sort`", "Medium", ""]}, {"question_id": "1955", "frontend_question_id": "1845", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/seat-reservation-manager", "url_en": "https://leetcode.com/problems/seat-reservation-manager", "relative_path_cn": "/solution/1800-1899/1845.Seat%20Reservation%20Manager/README.md", "relative_path_en": "/solution/1800-1899/1845.Seat%20Reservation%20Manager/README_EN.md", "title_cn": "\u5ea7\u4f4d\u9884\u7ea6\u7ba1\u7406\u7cfb\u7edf", "title_en": "Seat Reservation Manager", "question_title_slug": "seat-reservation-manager", "content_en": "

Design a system that manages the reservation state of n seats that are numbered from 1 to n.

\n\n

Implement the SeatManager class:

\n\n
    \n\t
  • SeatManager(int n) Initializes a SeatManager object that will manage n seats numbered from 1 to n. All seats are initially available.
  • \n\t
  • int reserve() Fetches the smallest-numbered unreserved seat, reserves it, and returns its number.
  • \n\t
  • void unreserve(int seatNumber) Unreserves the seat with the given seatNumber.
  • \n
\n\n

 

\n

Example 1:

\n\n
\nInput\n["SeatManager", "reserve", "reserve", "unreserve", "reserve", "reserve", "reserve", "reserve", "unreserve"]\n[[5], [], [], [2], [], [], [], [], [5]]\nOutput\n[null, 1, 2, null, 2, 3, 4, 5, null]\n\nExplanation\nSeatManager seatManager = new SeatManager(5); // Initializes a SeatManager with 5 seats.\nseatManager.reserve();    // All seats are available, so return the lowest numbered seat, which is 1.\nseatManager.reserve();    // The available seats are [2,3,4,5], so return the lowest of them, which is 2.\nseatManager.unreserve(2); // Unreserve seat 2, so now the available seats are [2,3,4,5].\nseatManager.reserve();    // The available seats are [2,3,4,5], so return the lowest of them, which is 2.\nseatManager.reserve();    // The available seats are [3,4,5], so return the lowest of them, which is 3.\nseatManager.reserve();    // The available seats are [4,5], so return the lowest of them, which is 4.\nseatManager.reserve();    // The only available seat is seat 5, so return 5.\nseatManager.unreserve(5); // Unreserve seat 5, so now the available seats are [5].\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 105
  • \n\t
  • 1 <= seatNumber <= n
  • \n\t
  • For each call to reserve, it is guaranteed that there will be at least one unreserved seat.
  • \n\t
  • For each call to unreserve, it is guaranteed that seatNumber will be reserved.
  • \n\t
  • At most 105 calls in total will be made to reserve and unreserve.
  • \n
\n", "content_cn": "

\u8bf7\u4f60\u8bbe\u8ba1\u4e00\u4e2a\u7ba1\u7406 n\u00a0\u4e2a\u5ea7\u4f4d\u9884\u7ea6\u7684\u7cfb\u7edf\uff0c\u5ea7\u4f4d\u7f16\u53f7\u4ece\u00a01\u00a0\u5230\u00a0n\u00a0\u3002

\n\n

\u8bf7\u4f60\u5b9e\u73b0\u00a0SeatManager\u00a0\u7c7b\uff1a

\n\n
    \n\t
  • SeatManager(int n)\u00a0\u521d\u59cb\u5316\u4e00\u4e2a\u00a0SeatManager\u00a0\u5bf9\u8c61\uff0c\u5b83\u7ba1\u7406\u4ece 1\u00a0\u5230 n\u00a0\u7f16\u53f7\u7684\u00a0n\u00a0\u4e2a\u5ea7\u4f4d\u3002\u6240\u6709\u5ea7\u4f4d\u521d\u59cb\u90fd\u662f\u53ef\u9884\u7ea6\u7684\u3002
  • \n\t
  • int reserve()\u00a0\u8fd4\u56de\u53ef\u4ee5\u9884\u7ea6\u5ea7\u4f4d\u7684\u00a0\u6700\u5c0f\u7f16\u53f7\u00a0\uff0c\u6b64\u5ea7\u4f4d\u53d8\u4e3a\u4e0d\u53ef\u9884\u7ea6\u3002
  • \n\t
  • void unreserve(int seatNumber)\u00a0\u5c06\u7ed9\u5b9a\u7f16\u53f7\u00a0seatNumber\u00a0\u5bf9\u5e94\u7684\u5ea7\u4f4d\u53d8\u6210\u53ef\u4ee5\u9884\u7ea6\u3002
  • \n
\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a\n[\"SeatManager\", \"reserve\", \"reserve\", \"unreserve\", \"reserve\", \"reserve\", \"reserve\", \"reserve\", \"unreserve\"]\n[[5], [], [], [2], [], [], [], [], [5]]\n\u8f93\u51fa\uff1a\n[null, 1, 2, null, 2, 3, 4, 5, null]\n\n\u89e3\u91ca\uff1a\nSeatManager seatManager = new SeatManager(5); // \u521d\u59cb\u5316 SeatManager \uff0c\u6709 5 \u4e2a\u5ea7\u4f4d\u3002\nseatManager.reserve();    // \u6240\u6709\u5ea7\u4f4d\u90fd\u53ef\u4ee5\u9884\u7ea6\uff0c\u6240\u4ee5\u8fd4\u56de\u6700\u5c0f\u7f16\u53f7\u7684\u5ea7\u4f4d\uff0c\u4e5f\u5c31\u662f 1 \u3002\nseatManager.reserve();    // \u53ef\u4ee5\u9884\u7ea6\u7684\u5ea7\u4f4d\u4e3a [2,3,4,5] \uff0c\u8fd4\u56de\u6700\u5c0f\u7f16\u53f7\u7684\u5ea7\u4f4d\uff0c\u4e5f\u5c31\u662f 2 \u3002\nseatManager.unreserve(2); // \u5c06\u5ea7\u4f4d 2 \u53d8\u4e3a\u53ef\u4ee5\u9884\u7ea6\uff0c\u73b0\u5728\u53ef\u9884\u7ea6\u7684\u5ea7\u4f4d\u4e3a [2,3,4,5] \u3002\nseatManager.reserve();    // \u53ef\u4ee5\u9884\u7ea6\u7684\u5ea7\u4f4d\u4e3a [2,3,4,5] \uff0c\u8fd4\u56de\u6700\u5c0f\u7f16\u53f7\u7684\u5ea7\u4f4d\uff0c\u4e5f\u5c31\u662f 2 \u3002\nseatManager.reserve();    // \u53ef\u4ee5\u9884\u7ea6\u7684\u5ea7\u4f4d\u4e3a [3,4,5] \uff0c\u8fd4\u56de\u6700\u5c0f\u7f16\u53f7\u7684\u5ea7\u4f4d\uff0c\u4e5f\u5c31\u662f 3 \u3002\nseatManager.reserve();    // \u53ef\u4ee5\u9884\u7ea6\u7684\u5ea7\u4f4d\u4e3a [4,5] \uff0c\u8fd4\u56de\u6700\u5c0f\u7f16\u53f7\u7684\u5ea7\u4f4d\uff0c\u4e5f\u5c31\u662f 4 \u3002\nseatManager.reserve();    // \u552f\u4e00\u53ef\u4ee5\u9884\u7ea6\u7684\u662f\u5ea7\u4f4d 5 \uff0c\u6240\u4ee5\u8fd4\u56de 5 \u3002\nseatManager.unreserve(5); // \u5c06\u5ea7\u4f4d 5 \u53d8\u4e3a\u53ef\u4ee5\u9884\u7ea6\uff0c\u73b0\u5728\u53ef\u9884\u7ea6\u7684\u5ea7\u4f4d\u4e3a [5] \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 105
  • \n\t
  • 1 <= seatNumber <= n
  • \n\t
  • \u6bcf\u4e00\u6b21\u5bf9\u00a0reserve\u00a0\u7684\u8c03\u7528\uff0c\u9898\u76ee\u4fdd\u8bc1\u81f3\u5c11\u5b58\u5728\u4e00\u4e2a\u53ef\u4ee5\u9884\u7ea6\u7684\u5ea7\u4f4d\u3002
  • \n\t
  • \u6bcf\u4e00\u6b21\u5bf9\u00a0unreserve\u00a0\u7684\u8c03\u7528\uff0c\u9898\u76ee\u4fdd\u8bc1\u00a0seatNumber\u00a0\u5728\u8c03\u7528\u51fd\u6570\u524d\u90fd\u662f\u88ab\u9884\u7ea6\u72b6\u6001\u3002
  • \n\t
  • \u5bf9\u00a0reserve \u548c\u00a0unreserve\u00a0\u7684\u8c03\u7528\u00a0\u603b\u5171\u00a0\u4e0d\u8d85\u8fc7\u00a0105\u00a0\u6b21\u3002
  • \n
\n", "tags_en": ["Heap", "Design"], "tags_cn": ["\u5806", "\u8bbe\u8ba1"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class SeatManager {\npublic:\n SeatManager(int n) {\n\n }\n \n int reserve() {\n\n }\n \n void unreserve(int seatNumber) {\n\n }\n};\n\n/**\n * Your SeatManager object will be instantiated and called as such:\n * SeatManager* obj = new SeatManager(n);\n * int param_1 = obj->reserve();\n * obj->unreserve(seatNumber);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class SeatManager {\n\n public SeatManager(int n) {\n\n }\n \n public int reserve() {\n\n }\n \n public void unreserve(int seatNumber) {\n\n }\n}\n\n/**\n * Your SeatManager object will be instantiated and called as such:\n * SeatManager obj = new SeatManager(n);\n * int param_1 = obj.reserve();\n * obj.unreserve(seatNumber);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class SeatManager(object):\n\n def __init__(self, n):\n \"\"\"\n :type n: int\n \"\"\"\n\n\n def reserve(self):\n \"\"\"\n :rtype: int\n \"\"\"\n\n\n def unreserve(self, seatNumber):\n \"\"\"\n :type seatNumber: int\n :rtype: None\n \"\"\"\n\n\n\n# Your SeatManager object will be instantiated and called as such:\n# obj = SeatManager(n)\n# param_1 = obj.reserve()\n# obj.unreserve(seatNumber)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class SeatManager:\n\n def __init__(self, n: int):\n\n\n def reserve(self) -> int:\n\n\n def unreserve(self, seatNumber: int) -> None:\n\n\n\n# Your SeatManager object will be instantiated and called as such:\n# obj = SeatManager(n)\n# param_1 = obj.reserve()\n# obj.unreserve(seatNumber)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} SeatManager;\n\n\nSeatManager* seatManagerCreate(int n) {\n\n}\n\nint seatManagerReserve(SeatManager* obj) {\n\n}\n\nvoid seatManagerUnreserve(SeatManager* obj, int seatNumber) {\n\n}\n\nvoid seatManagerFree(SeatManager* obj) {\n\n}\n\n/**\n * Your SeatManager struct will be instantiated and called as such:\n * SeatManager* obj = seatManagerCreate(n);\n * int param_1 = seatManagerReserve(obj);\n \n * seatManagerUnreserve(obj, seatNumber);\n \n * seatManagerFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class SeatManager {\n\n public SeatManager(int n) {\n\n }\n \n public int Reserve() {\n\n }\n \n public void Unreserve(int seatNumber) {\n\n }\n}\n\n/**\n * Your SeatManager object will be instantiated and called as such:\n * SeatManager obj = new SeatManager(n);\n * int param_1 = obj.Reserve();\n * obj.Unreserve(seatNumber);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n */\nvar SeatManager = function(n) {\n\n};\n\n/**\n * @return {number}\n */\nSeatManager.prototype.reserve = function() {\n\n};\n\n/** \n * @param {number} seatNumber\n * @return {void}\n */\nSeatManager.prototype.unreserve = function(seatNumber) {\n\n};\n\n/**\n * Your SeatManager object will be instantiated and called as such:\n * var obj = new SeatManager(n)\n * var param_1 = obj.reserve()\n * obj.unreserve(seatNumber)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class SeatManager\n\n=begin\n :type n: Integer\n=end\n def initialize(n)\n\n end\n\n\n=begin\n :rtype: Integer\n=end\n def reserve()\n\n end\n\n\n=begin\n :type seat_number: Integer\n :rtype: Void\n=end\n def unreserve(seat_number)\n\n end\n\n\nend\n\n# Your SeatManager object will be instantiated and called as such:\n# obj = SeatManager.new(n)\n# param_1 = obj.reserve()\n# obj.unreserve(seat_number)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass SeatManager {\n\n init(_ n: Int) {\n\n }\n \n func reserve() -> Int {\n\n }\n \n func unreserve(_ seatNumber: Int) {\n\n }\n}\n\n/**\n * Your SeatManager object will be instantiated and called as such:\n * let obj = SeatManager(n)\n * let ret_1: Int = obj.reserve()\n * obj.unreserve(seatNumber)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type SeatManager struct {\n\n}\n\n\nfunc Constructor(n int) SeatManager {\n\n}\n\n\nfunc (this *SeatManager) Reserve() int {\n\n}\n\n\nfunc (this *SeatManager) Unreserve(seatNumber int) {\n\n}\n\n\n/**\n * Your SeatManager object will be instantiated and called as such:\n * obj := Constructor(n);\n * param_1 := obj.Reserve();\n * obj.Unreserve(seatNumber);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class SeatManager(_n: Int) {\n\n def reserve(): Int = {\n\n }\n\n def unreserve(seatNumber: Int) {\n\n }\n\n}\n\n/**\n * Your SeatManager object will be instantiated and called as such:\n * var obj = new SeatManager(n)\n * var param_1 = obj.reserve()\n * obj.unreserve(seatNumber)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class SeatManager(n: Int) {\n\n fun reserve(): Int {\n\n }\n\n fun unreserve(seatNumber: Int) {\n\n }\n\n}\n\n/**\n * Your SeatManager object will be instantiated and called as such:\n * var obj = SeatManager(n)\n * var param_1 = obj.reserve()\n * obj.unreserve(seatNumber)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct SeatManager {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl SeatManager {\n\n fn new(n: i32) -> Self {\n\n }\n \n fn reserve(&self) -> i32 {\n\n }\n \n fn unreserve(&self, seat_number: i32) {\n\n }\n}\n\n/**\n * Your SeatManager object will be instantiated and called as such:\n * let obj = SeatManager::new(n);\n * let ret_1: i32 = obj.reserve();\n * obj.unreserve(seatNumber);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class SeatManager {\n /**\n * @param Integer $n\n */\n function __construct($n) {\n\n }\n\n /**\n * @return Integer\n */\n function reserve() {\n\n }\n\n /**\n * @param Integer $seatNumber\n * @return NULL\n */\n function unreserve($seatNumber) {\n\n }\n}\n\n/**\n * Your SeatManager object will be instantiated and called as such:\n * $obj = SeatManager($n);\n * $ret_1 = $obj->reserve();\n * $obj->unreserve($seatNumber);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class SeatManager {\n constructor(n: number) {\n\n }\n\n reserve(): number {\n\n }\n\n unreserve(seatNumber: number): void {\n\n }\n}\n\n/**\n * Your SeatManager object will be instantiated and called as such:\n * var obj = new SeatManager(n)\n * var param_1 = obj.reserve()\n * obj.unreserve(seatNumber)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define seat-manager%\n (class object%\n (super-new)\n\n ; n : exact-integer?\n (init-field\n n)\n \n ; reserve : -> exact-integer?\n (define/public (reserve)\n\n )\n ; unreserve : exact-integer? -> void?\n (define/public (unreserve seatNumber)\n\n )))\n\n;; Your seat-manager% object will be instantiated and called as such:\n;; (define obj (new seat-manager% [n n]))\n;; (define param_1 (send obj reserve))\n;; (send obj unreserve seat-number)", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1845](https://leetcode-cn.com/problems/seat-reservation-manager)", "[\u5ea7\u4f4d\u9884\u7ea6\u7ba1\u7406\u7cfb\u7edf](/solution/1800-1899/1845.Seat%20Reservation%20Manager/README.md)", "`\u5806`,`\u8bbe\u8ba1`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1845](https://leetcode.com/problems/seat-reservation-manager)", "[Seat Reservation Manager](/solution/1800-1899/1845.Seat%20Reservation%20Manager/README_EN.md)", "`Heap`,`Design`", "Medium", ""]}, {"question_id": "1954", "frontend_question_id": "1844", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/replace-all-digits-with-characters", "url_en": "https://leetcode.com/problems/replace-all-digits-with-characters", "relative_path_cn": "/solution/1800-1899/1844.Replace%20All%20Digits%20with%20Characters/README.md", "relative_path_en": "/solution/1800-1899/1844.Replace%20All%20Digits%20with%20Characters/README_EN.md", "title_cn": "\u5c06\u6240\u6709\u6570\u5b57\u7528\u5b57\u7b26\u66ff\u6362", "title_en": "Replace All Digits with Characters", "question_title_slug": "replace-all-digits-with-characters", "content_en": "

You are given a 0-indexed string s that has lowercase English letters in its even indices and digits in its odd indices.

\n\n

There is a function shift(c, x), where c is a character and x is a digit, that returns the xth character after c.

\n\n
    \n\t
  • For example, shift('a', 5) = 'f' and shift('x', 0) = 'x'.
  • \n
\n\n

For every odd index i, you want to replace the digit s[i] with shift(s[i-1], s[i]).

\n\n

Return s after replacing all digits. It is guaranteed that shift(s[i-1], s[i]) will never exceed 'z'.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "a1c1e1"\nOutput: "abcdef"\nExplanation: The digits are replaced as follows:\n- s[1] -> shift('a',1) = 'b'\n- s[3] -> shift('c',1) = 'd'\n- s[5] -> shift('e',1) = 'f'
\n\n

Example 2:

\n\n
\nInput: s = "a1b2c3d4e"\nOutput: "abbdcfdhe"\nExplanation: The digits are replaced as follows:\n- s[1] -> shift('a',1) = 'b'\n- s[3] -> shift('b',2) = 'd'\n- s[5] -> shift('c',3) = 'f'\n- s[7] -> shift('d',4) = 'h'
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 100
  • \n\t
  • s consists only of lowercase English letters and digits.
  • \n\t
  • shift(s[i-1], s[i]) <= 'z' for all odd indices i.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u4e0b\u6807\u4ece 0\u00a0\u5f00\u59cb\u7684\u5b57\u7b26\u4e32 s\u00a0\uff0c\u5b83\u7684 \u5076\u6570 \u4e0b\u6807\u5904\u4e3a\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\uff0c\u5947\u6570\u00a0\u4e0b\u6807\u5904\u4e3a\u6570\u5b57\u3002

\n\n

\u5b9a\u4e49\u4e00\u4e2a\u51fd\u6570\u00a0shift(c, x)\u00a0\uff0c\u5176\u4e2d\u00a0c\u00a0\u662f\u4e00\u4e2a\u5b57\u7b26\u4e14\u00a0x\u00a0\u662f\u4e00\u4e2a\u6570\u5b57\uff0c\u51fd\u6570\u8fd4\u56de\u5b57\u6bcd\u8868\u4e2d\u00a0c\u00a0\u540e\u9762\u7b2c x\u00a0\u4e2a\u5b57\u7b26\u3002

\n\n
    \n\t
  • \u6bd4\u65b9\u8bf4\uff0cshift('a', 5) = 'f'\u00a0\u548c\u00a0shift('x', 0) = 'x'\u00a0\u3002
  • \n
\n\n

\u5bf9\u4e8e\u6bcf\u4e2a \u5947\u6570\u00a0\u4e0b\u6807\u00a0i\u00a0\uff0c\u4f60\u9700\u8981\u5c06\u6570\u5b57\u00a0s[i] \u7528\u00a0shift(s[i-1], s[i])\u00a0\u66ff\u6362\u3002

\n\n

\u8bf7\u4f60\u66ff\u6362\u6240\u6709\u6570\u5b57\u4ee5\u540e\uff0c\u5c06\u5b57\u7b26\u4e32 s\u00a0\u8fd4\u56de\u3002\u9898\u76ee \u4fdd\u8bc1\u00a0shift(s[i-1], s[i])\u00a0\u4e0d\u4f1a\u8d85\u8fc7 'z'\u00a0\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1as = \"a1c1e1\"\n\u8f93\u51fa\uff1a\"abcdef\"\n\u89e3\u91ca\uff1a\u6570\u5b57\u88ab\u66ff\u6362\u7ed3\u679c\u5982\u4e0b\uff1a\n- s[1] -> shift('a',1) = 'b'\n- s[3] -> shift('c',1) = 'd'\n- s[5] -> shift('e',1) = 'f'
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1as = \"a1b2c3d4e\"\n\u8f93\u51fa\uff1a\"abbdcfdhe\"\n\u89e3\u91ca\uff1a\u6570\u5b57\u88ab\u66ff\u6362\u7ed3\u679c\u5982\u4e0b\uff1a\n- s[1] -> shift('a',1) = 'b'\n- s[3] -> shift('b',2) = 'd'\n- s[5] -> shift('c',3) = 'f'\n- s[7] -> shift('d',4) = 'h'
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length <= 100
  • \n\t
  • s\u00a0\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u548c\u6570\u5b57\u3002
  • \n\t
  • \u5bf9\u6240\u6709 \u5947\u6570 \u4e0b\u6807\u5904\u7684\u00a0i\u00a0\uff0c\u6ee1\u8db3\u00a0shift(s[i-1], s[i]) <= 'z'\u00a0\u3002
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string replaceDigits(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String replaceDigits(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def replaceDigits(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def replaceDigits(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * replaceDigits(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ReplaceDigits(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar replaceDigits = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef replace_digits(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func replaceDigits(_ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func replaceDigits(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def replaceDigits(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun replaceDigits(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn replace_digits(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function replaceDigits($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function replaceDigits(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (replace-digits s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1844](https://leetcode-cn.com/problems/replace-all-digits-with-characters)", "[\u5c06\u6240\u6709\u6570\u5b57\u7528\u5b57\u7b26\u66ff\u6362](/solution/1800-1899/1844.Replace%20All%20Digits%20with%20Characters/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1844](https://leetcode.com/problems/replace-all-digits-with-characters)", "[Replace All Digits with Characters](/solution/1800-1899/1844.Replace%20All%20Digits%20with%20Characters/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1953", "frontend_question_id": "1825", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/finding-mk-average", "url_en": "https://leetcode.com/problems/finding-mk-average", "relative_path_cn": "/solution/1800-1899/1825.Finding%20MK%20Average/README.md", "relative_path_en": "/solution/1800-1899/1825.Finding%20MK%20Average/README_EN.md", "title_cn": "\u6c42\u51fa MK \u5e73\u5747\u503c", "title_en": "Finding MK Average", "question_title_slug": "finding-mk-average", "content_en": "

You are given two integers, m and k, and a stream of integers. You are tasked to implement a data structure that calculates the MKAverage for the stream.

\n\n

The MKAverage can be calculated using these steps:

\n\n
    \n\t
  1. If the number of the elements in the stream is less than m you should consider the MKAverage to be -1. Otherwise, copy the last m elements of the stream to a separate container.
  2. \n\t
  3. Remove the smallest k elements and the largest k elements from the container.
  4. \n\t
  5. Calculate the average value for the rest of the elements rounded down to the nearest integer.
  6. \n
\n\n

Implement the MKAverage class:

\n\n
    \n\t
  • MKAverage(int m, int k) Initializes the MKAverage object with an empty stream and the two integers m and k.
  • \n\t
  • void addElement(int num) Inserts a new element num into the stream.
  • \n\t
  • int calculateMKAverage() Calculates and returns the MKAverage for the current stream rounded down to the nearest integer.
  • \n
\n\n

 

\n

Example 1:

\n\n
\nInput\n["MKAverage", "addElement", "addElement", "calculateMKAverage", "addElement", "calculateMKAverage", "addElement", "addElement", "addElement", "calculateMKAverage"]\n[[3, 1], [3], [1], [], [10], [], [5], [5], [5], []]\nOutput\n[null, null, null, -1, null, 3, null, null, null, 5]\n\nExplanation\nMKAverage obj = new MKAverage(3, 1); \nobj.addElement(3);        // current elements are [3]\nobj.addElement(1);        // current elements are [3,1]\nobj.calculateMKAverage(); // return -1, because m = 3 and only 2 elements exist.\nobj.addElement(10);       // current elements are [3,1,10]\nobj.calculateMKAverage(); // The last 3 elements are [3,1,10].\n                          // After removing smallest and largest 1 element the container will be [3].\n                          // The average of [3] equals 3/1 = 3, return 3\nobj.addElement(5);        // current elements are [3,1,10,5]\nobj.addElement(5);        // current elements are [3,1,10,5,5]\nobj.addElement(5);        // current elements are [3,1,10,5,5,5]\nobj.calculateMKAverage(); // The last 3 elements are [5,5,5].\n                          // After removing smallest and largest 1 element the container will be [5].\n                          // The average of [5] equals 5/1 = 5, return 5\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 3 <= m <= 105
  • \n\t
  • 1 <= k*2 < m
  • \n\t
  • 1 <= num <= 105
  • \n\t
  • At most 105 calls will be made to addElement and calculateMKAverage.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e24\u4e2a\u6574\u6570\u00a0m\u00a0\u548c\u00a0k\u00a0\uff0c\u4ee5\u53ca\u6570\u636e\u6d41\u5f62\u5f0f\u7684\u82e5\u5e72\u6574\u6570\u3002\u4f60\u9700\u8981\u5b9e\u73b0\u4e00\u4e2a\u6570\u636e\u7ed3\u6784\uff0c\u8ba1\u7b97\u8fd9\u4e2a\u6570\u636e\u6d41\u7684 MK \u5e73\u5747\u503c\u00a0\u3002

\n\n

MK \u5e73\u5747\u503c\u00a0\u6309\u7167\u5982\u4e0b\u6b65\u9aa4\u8ba1\u7b97\uff1a

\n\n
    \n\t
  1. \u5982\u679c\u6570\u636e\u6d41\u4e2d\u7684\u6574\u6570\u5c11\u4e8e m\u00a0\u4e2a\uff0cMK \u5e73\u5747\u503c\u00a0\u4e3a -1\u00a0\uff0c\u5426\u5219\u5c06\u6570\u636e\u6d41\u4e2d\u6700\u540e m\u00a0\u4e2a\u5143\u7d20\u62f7\u8d1d\u5230\u4e00\u4e2a\u72ec\u7acb\u7684\u5bb9\u5668\u4e2d\u3002
  2. \n\t
  3. \u4ece\u8fd9\u4e2a\u5bb9\u5668\u4e2d\u5220\u9664\u6700\u5c0f\u7684 k\u00a0\u4e2a\u6570\u548c\u6700\u5927\u7684 k\u00a0\u4e2a\u6570\u3002
  4. \n\t
  5. \u8ba1\u7b97\u5269\u4f59\u5143\u7d20\u7684\u5e73\u5747\u503c\uff0c\u5e76 \u5411\u4e0b\u53d6\u6574\u5230\u6700\u8fd1\u7684\u6574\u6570\u00a0\u3002
  6. \n
\n\n

\u8bf7\u4f60\u5b9e\u73b0\u00a0MKAverage\u00a0\u7c7b\uff1a

\n\n
    \n\t
  • MKAverage(int m, int k)\u00a0\u7528\u4e00\u4e2a\u7a7a\u7684\u6570\u636e\u6d41\u548c\u4e24\u4e2a\u6574\u6570 m\u00a0\u548c k\u00a0\u521d\u59cb\u5316\u00a0MKAverage\u00a0\u5bf9\u8c61\u3002
  • \n\t
  • void addElement(int num)\u00a0\u5f80\u6570\u636e\u6d41\u4e2d\u63d2\u5165\u4e00\u4e2a\u65b0\u7684\u5143\u7d20\u00a0num\u00a0\u3002
  • \n\t
  • int calculateMKAverage()\u00a0\u5bf9\u5f53\u524d\u7684\u6570\u636e\u6d41\u8ba1\u7b97\u5e76\u8fd4\u56de MK \u5e73\u5747\u6570\u00a0\uff0c\u7ed3\u679c\u9700 \u5411\u4e0b\u53d6\u6574\u5230\u6700\u8fd1\u7684\u6574\u6570 \u3002
  • \n
\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1a\n[\"MKAverage\", \"addElement\", \"addElement\", \"calculateMKAverage\", \"addElement\", \"calculateMKAverage\", \"addElement\", \"addElement\", \"addElement\", \"calculateMKAverage\"]\n[[3, 1], [3], [1], [], [10], [], [5], [5], [5], []]\n\u8f93\u51fa\uff1a\n[null, null, null, -1, null, 3, null, null, null, 5]\n\n\u89e3\u91ca\uff1a\nMKAverage obj = new MKAverage(3, 1); \nobj.addElement(3);        // \u5f53\u524d\u5143\u7d20\u4e3a [3]\nobj.addElement(1);        // \u5f53\u524d\u5143\u7d20\u4e3a [3,1]\nobj.calculateMKAverage(); // \u8fd4\u56de -1 \uff0c\u56e0\u4e3a m = 3 \uff0c\u4f46\u6570\u636e\u6d41\u4e2d\u53ea\u6709 2 \u4e2a\u5143\u7d20\nobj.addElement(10);       // \u5f53\u524d\u5143\u7d20\u4e3a [3,1,10]\nobj.calculateMKAverage(); // \u6700\u540e 3 \u4e2a\u5143\u7d20\u4e3a [3,1,10]\n                          // \u5220\u9664\u6700\u5c0f\u4ee5\u53ca\u6700\u5927\u7684 1 \u4e2a\u5143\u7d20\u540e\uff0c\u5bb9\u5668\u4e3a [3]\n                          // [3] \u7684\u5e73\u5747\u503c\u7b49\u4e8e 3/1 = 3 \uff0c\u6545\u8fd4\u56de 3\nobj.addElement(5);        // \u5f53\u524d\u5143\u7d20\u4e3a [3,1,10,5]\nobj.addElement(5);        // \u5f53\u524d\u5143\u7d20\u4e3a [3,1,10,5,5]\nobj.addElement(5);        // \u5f53\u524d\u5143\u7d20\u4e3a [3,1,10,5,5,5]\nobj.calculateMKAverage(); // \u6700\u540e 3 \u4e2a\u5143\u7d20\u4e3a [5,5,5]\n                          // \u5220\u9664\u6700\u5c0f\u4ee5\u53ca\u6700\u5927\u7684 1 \u4e2a\u5143\u7d20\u540e\uff0c\u5bb9\u5668\u4e3a [5]\n                          // [5] \u7684\u5e73\u5747\u503c\u7b49\u4e8e 5/1 = 5 \uff0c\u6545\u8fd4\u56de 5\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 3 <= m <= 105
  • \n\t
  • 1 <= k*2 < m
  • \n\t
  • 1 <= num <= 105
  • \n\t
  • addElement \u4e0e\u00a0calculateMKAverage\u00a0\u603b\u64cd\u4f5c\u6b21\u6570\u4e0d\u8d85\u8fc7 105 \u6b21\u3002
  • \n
\n", "tags_en": ["Heap", "Design", "Queue"], "tags_cn": ["\u5806", "\u8bbe\u8ba1", "\u961f\u5217"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class MKAverage {\npublic:\n MKAverage(int m, int k) {\n\n }\n \n void addElement(int num) {\n\n }\n \n int calculateMKAverage() {\n\n }\n};\n\n/**\n * Your MKAverage object will be instantiated and called as such:\n * MKAverage* obj = new MKAverage(m, k);\n * obj->addElement(num);\n * int param_2 = obj->calculateMKAverage();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class MKAverage {\n\n public MKAverage(int m, int k) {\n\n }\n \n public void addElement(int num) {\n\n }\n \n public int calculateMKAverage() {\n\n }\n}\n\n/**\n * Your MKAverage object will be instantiated and called as such:\n * MKAverage obj = new MKAverage(m, k);\n * obj.addElement(num);\n * int param_2 = obj.calculateMKAverage();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class MKAverage(object):\n\n def __init__(self, m, k):\n \"\"\"\n :type m: int\n :type k: int\n \"\"\"\n\n\n def addElement(self, num):\n \"\"\"\n :type num: int\n :rtype: None\n \"\"\"\n\n\n def calculateMKAverage(self):\n \"\"\"\n :rtype: int\n \"\"\"\n\n\n\n# Your MKAverage object will be instantiated and called as such:\n# obj = MKAverage(m, k)\n# obj.addElement(num)\n# param_2 = obj.calculateMKAverage()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class MKAverage:\n\n def __init__(self, m: int, k: int):\n\n\n def addElement(self, num: int) -> None:\n\n\n def calculateMKAverage(self) -> int:\n\n\n\n# Your MKAverage object will be instantiated and called as such:\n# obj = MKAverage(m, k)\n# obj.addElement(num)\n# param_2 = obj.calculateMKAverage()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} MKAverage;\n\n\nMKAverage* mKAverageCreate(int m, int k) {\n\n}\n\nvoid mKAverageAddElement(MKAverage* obj, int num) {\n\n}\n\nint mKAverageCalculateMKAverage(MKAverage* obj) {\n\n}\n\nvoid mKAverageFree(MKAverage* obj) {\n\n}\n\n/**\n * Your MKAverage struct will be instantiated and called as such:\n * MKAverage* obj = mKAverageCreate(m, k);\n * mKAverageAddElement(obj, num);\n \n * int param_2 = mKAverageCalculateMKAverage(obj);\n \n * mKAverageFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class MKAverage {\n\n public MKAverage(int m, int k) {\n\n }\n \n public void AddElement(int num) {\n\n }\n \n public int CalculateMKAverage() {\n\n }\n}\n\n/**\n * Your MKAverage object will be instantiated and called as such:\n * MKAverage obj = new MKAverage(m, k);\n * obj.AddElement(num);\n * int param_2 = obj.CalculateMKAverage();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} m\n * @param {number} k\n */\nvar MKAverage = function(m, k) {\n\n};\n\n/** \n * @param {number} num\n * @return {void}\n */\nMKAverage.prototype.addElement = function(num) {\n\n};\n\n/**\n * @return {number}\n */\nMKAverage.prototype.calculateMKAverage = function() {\n\n};\n\n/**\n * Your MKAverage object will be instantiated and called as such:\n * var obj = new MKAverage(m, k)\n * obj.addElement(num)\n * var param_2 = obj.calculateMKAverage()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class MKAverage\n\n=begin\n :type m: Integer\n :type k: Integer\n=end\n def initialize(m, k)\n\n end\n\n\n=begin\n :type num: Integer\n :rtype: Void\n=end\n def add_element(num)\n\n end\n\n\n=begin\n :rtype: Integer\n=end\n def calculate_mk_average()\n\n end\n\n\nend\n\n# Your MKAverage object will be instantiated and called as such:\n# obj = MKAverage.new(m, k)\n# obj.add_element(num)\n# param_2 = obj.calculate_mk_average()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass MKAverage {\n\n init(_ m: Int, _ k: Int) {\n\n }\n \n func addElement(_ num: Int) {\n\n }\n \n func calculateMKAverage() -> Int {\n\n }\n}\n\n/**\n * Your MKAverage object will be instantiated and called as such:\n * let obj = MKAverage(m, k)\n * obj.addElement(num)\n * let ret_2: Int = obj.calculateMKAverage()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type MKAverage struct {\n\n}\n\n\nfunc Constructor(m int, k int) MKAverage {\n\n}\n\n\nfunc (this *MKAverage) AddElement(num int) {\n\n}\n\n\nfunc (this *MKAverage) CalculateMKAverage() int {\n\n}\n\n\n/**\n * Your MKAverage object will be instantiated and called as such:\n * obj := Constructor(m, k);\n * obj.AddElement(num);\n * param_2 := obj.CalculateMKAverage();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class MKAverage(_m: Int, _k: Int) {\n\n def addElement(num: Int) {\n \n }\n\n def calculateMKAverage(): Int = {\n \n }\n\n}\n\n/**\n * Your MKAverage object will be instantiated and called as such:\n * var obj = new MKAverage(m, k)\n * obj.addElement(num)\n * var param_2 = obj.calculateMKAverage()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class MKAverage(m: Int, k: Int) {\n\n fun addElement(num: Int) {\n\n }\n\n fun calculateMKAverage(): Int {\n\n }\n\n}\n\n/**\n * Your MKAverage object will be instantiated and called as such:\n * var obj = MKAverage(m, k)\n * obj.addElement(num)\n * var param_2 = obj.calculateMKAverage()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct MKAverage {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl MKAverage {\n\n fn new(m: i32, k: i32) -> Self {\n\n }\n \n fn add_element(&self, num: i32) {\n\n }\n \n fn calculate_mk_average(&self) -> i32 {\n\n }\n}\n\n/**\n * Your MKAverage object will be instantiated and called as such:\n * let obj = MKAverage::new(m, k);\n * obj.add_element(num);\n * let ret_2: i32 = obj.calculate_mk_average();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class MKAverage {\n /**\n * @param Integer $m\n * @param Integer $k\n */\n function __construct($m, $k) {\n\n }\n\n /**\n * @param Integer $num\n * @return NULL\n */\n function addElement($num) {\n\n }\n\n /**\n * @return Integer\n */\n function calculateMKAverage() {\n\n }\n}\n\n/**\n * Your MKAverage object will be instantiated and called as such:\n * $obj = MKAverage($m, $k);\n * $obj->addElement($num);\n * $ret_2 = $obj->calculateMKAverage();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class MKAverage {\n constructor(m: number, k: number) {\n\n }\n\n addElement(num: number): void {\n\n }\n\n calculateMKAverage(): number {\n\n }\n}\n\n/**\n * Your MKAverage object will be instantiated and called as such:\n * var obj = new MKAverage(m, k)\n * obj.addElement(num)\n * var param_2 = obj.calculateMKAverage()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define mk-average%\n (class object%\n (super-new)\n\n ; m : exact-integer?\n\n ; k : exact-integer?\n (init-field\n m\n k)\n \n ; add-element : exact-integer? -> void?\n (define/public (add-element num)\n\n )\n ; calculate-mk-average : -> exact-integer?\n (define/public (calculate-mk-average)\n\n )))\n\n;; Your mk-average% object will be instantiated and called as such:\n;; (define obj (new mk-average% [m m] [k k]))\n;; (send obj add-element num)\n;; (define param_2 (send obj calculate-mk-average))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1825](https://leetcode-cn.com/problems/finding-mk-average)", "[\u6c42\u51fa MK \u5e73\u5747\u503c](/solution/1800-1899/1825.Finding%20MK%20Average/README.md)", "`\u5806`,`\u8bbe\u8ba1`,`\u961f\u5217`", "\u56f0\u96be", ""], "md_table_row_en": ["[1825](https://leetcode.com/problems/finding-mk-average)", "[Finding MK Average](/solution/1800-1899/1825.Finding%20MK%20Average/README_EN.md)", "`Heap`,`Design`,`Queue`", "Hard", ""]}, {"question_id": "1952", "frontend_question_id": "1824", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-sideway-jumps", "url_en": "https://leetcode.com/problems/minimum-sideway-jumps", "relative_path_cn": "/solution/1800-1899/1824.Minimum%20Sideway%20Jumps/README.md", "relative_path_en": "/solution/1800-1899/1824.Minimum%20Sideway%20Jumps/README_EN.md", "title_cn": "\u6700\u5c11\u4fa7\u8df3\u6b21\u6570", "title_en": "Minimum Sideway Jumps", "question_title_slug": "minimum-sideway-jumps", "content_en": "

There is a 3 lane road of length n that consists of n + 1 points labeled from 0 to n. A frog starts at point 0 in the second lane and wants to jump to point n. However, there could be obstacles along the way.

\n\n

You are given an array obstacles of length n + 1 where each obstacles[i] (ranging from 0 to 3) describes an obstacle on the lane obstacles[i] at point i. If obstacles[i] == 0, there are no obstacles at point i. There will be at most one obstacle in the 3 lanes at each point.

\n\n
    \n\t
  • For example, if obstacles[2] == 1, then there is an obstacle on lane 1 at point 2.
  • \n
\n\n

The frog can only travel from point i to point i + 1 on the same lane if there is not an obstacle on the lane at point i + 1. To avoid obstacles, the frog can also perform a side jump to jump to another lane (even if they are not adjacent) at the same point if there is no obstacle on the new lane.

\n\n
    \n\t
  • For example, the frog can jump from lane 3 at point 3 to lane 1 at point 3.
  • \n
\n\n

Return the minimum number of side jumps the frog needs to reach any lane at point n starting from lane 2 at point 0.

\n\n

Note: There will be no obstacles on points 0 and n.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: obstacles = [0,1,2,3,0]\nOutput: 2 \nExplanation: The optimal solution is shown by the arrows above. There are 2 side jumps (red arrows).\nNote that the frog can jump over obstacles only when making side jumps (as shown at point 2).\n
\n\n

Example 2:

\n\"\"\n
\nInput: obstacles = [0,1,1,3,3,0]\nOutput: 0\nExplanation: There are no obstacles on lane 2. No side jumps are required.\n
\n\n

Example 3:

\n\"\"\n
\nInput: obstacles = [0,2,1,0,3,0]\nOutput: 2\nExplanation: The optimal solution is shown by the arrows above. There are 2 side jumps.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • obstacles.length == n + 1
  • \n\t
  • 1 <= n <= 5 * 105
  • \n\t
  • 0 <= obstacles[i] <= 3
  • \n\t
  • obstacles[0] == obstacles[n] == 0
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u4e3a\u00a0n\u00a0\u7684\u00a03 \u8dd1\u9053\u9053\u8def\u00a0\uff0c\u5b83\u603b\u5171\u5305\u542b\u00a0n + 1\u00a0\u4e2a\u00a0\u70b9\u00a0\uff0c\u7f16\u53f7\u4e3a\u00a00\u00a0\u5230\u00a0n\u00a0\u3002\u4e00\u53ea\u9752\u86d9\u4ece\u00a00\u00a0\u53f7\u70b9\u7b2c\u4e8c\u6761\u8dd1\u9053\u00a0\u51fa\u53d1\u00a0\uff0c\u5b83\u60f3\u8981\u8df3\u5230\u70b9\u00a0n\u00a0\u5904\u3002\u7136\u800c\u9053\u8def\u4e0a\u53ef\u80fd\u6709\u4e00\u4e9b\u969c\u788d\u3002

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u4e3a n + 1\u00a0\u7684\u6570\u7ec4\u00a0obstacles\u00a0\uff0c\u5176\u4e2d\u00a0obstacles[i]\u00a0\uff08\u53d6\u503c\u8303\u56f4\u4ece 0 \u5230 3\uff09\u8868\u793a\u5728\u70b9 i\u00a0\u5904\u7684\u00a0obstacles[i]\u00a0\u8dd1\u9053\u4e0a\u6709\u4e00\u4e2a\u969c\u788d\u3002\u5982\u679c\u00a0obstacles[i] == 0\u00a0\uff0c\u90a3\u4e48\u70b9\u00a0i\u00a0\u5904\u6ca1\u6709\u969c\u788d\u3002\u4efb\u4f55\u4e00\u4e2a\u70b9\u7684\u4e09\u6761\u8dd1\u9053\u4e2d\u00a0\u6700\u591a\u6709\u4e00\u4e2a\u00a0\u969c\u788d\u3002

\n\n
    \n\t
  • \u6bd4\u65b9\u8bf4\uff0c\u5982\u679c\u00a0obstacles[2] == 1\u00a0\uff0c\u90a3\u4e48\u8bf4\u660e\u5728\u70b9 2 \u5904\u8dd1\u9053 1 \u6709\u969c\u788d\u3002
  • \n
\n\n

\u8fd9\u53ea\u9752\u86d9\u4ece\u70b9 i\u00a0\u8df3\u5230\u70b9 i + 1\u00a0\u4e14\u8dd1\u9053\u4e0d\u53d8\u7684\u524d\u63d0\u662f\u70b9 i + 1\u00a0\u7684\u540c\u4e00\u8dd1\u9053\u4e0a\u6ca1\u6709\u969c\u788d\u3002\u4e3a\u4e86\u8eb2\u907f\u969c\u788d\uff0c\u8fd9\u53ea\u9752\u86d9\u4e5f\u53ef\u4ee5\u5728\u00a0\u540c\u4e00\u4e2a\u00a0\u70b9\u5904\u00a0\u4fa7\u8df3\u00a0\u5230 \u53e6\u5916\u4e00\u6761\u00a0\u8dd1\u9053\uff08\u8fd9\u4e24\u6761\u8dd1\u9053\u53ef\u4ee5\u4e0d\u76f8\u90bb\uff09\uff0c\u4f46\u524d\u63d0\u662f\u8df3\u8fc7\u53bb\u7684\u8dd1\u9053\u8be5\u70b9\u5904\u6ca1\u6709\u969c\u788d\u3002

\n\n
    \n\t
  • \u6bd4\u65b9\u8bf4\uff0c\u8fd9\u53ea\u9752\u86d9\u53ef\u4ee5\u4ece\u70b9 3 \u5904\u7684\u8dd1\u9053 3 \u8df3\u5230\u70b9 3 \u5904\u7684\u8dd1\u9053 1 \u3002
  • \n
\n\n

\u8fd9\u53ea\u9752\u86d9\u4ece\u70b9 0 \u5904\u8dd1\u9053 2\u00a0\u51fa\u53d1\uff0c\u5e76\u60f3\u5230\u8fbe\u70b9 n\u00a0\u5904\u7684 \u4efb\u4e00\u8dd1\u9053 \uff0c\u8bf7\u4f60\u8fd4\u56de \u6700\u5c11\u4fa7\u8df3\u6b21\u6570\u00a0\u3002

\n\n

\u6ce8\u610f\uff1a\u70b9 0\u00a0\u5904\u548c\u70b9 n\u00a0\u5904\u7684\u4efb\u4e00\u8dd1\u9053\u90fd\u4e0d\u4f1a\u6709\u969c\u788d\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1aobstacles = [0,1,2,3,0]\n\u8f93\u51fa\uff1a2 \n\u89e3\u91ca\uff1a\u6700\u4f18\u65b9\u6848\u5982\u4e0a\u56fe\u7bad\u5934\u6240\u793a\u3002\u603b\u5171\u6709 2 \u6b21\u4fa7\u8df3\uff08\u7ea2\u8272\u7bad\u5934\uff09\u3002\n\u6ce8\u610f\uff0c\u8fd9\u53ea\u9752\u86d9\u53ea\u6709\u5f53\u4fa7\u8df3\u65f6\u624d\u53ef\u4ee5\u8df3\u8fc7\u969c\u788d\uff08\u5982\u4e0a\u56fe\u70b9 2 \u5904\u6240\u793a\uff09\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1aobstacles = [0,1,1,3,3,0]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u8dd1\u9053 2 \u6ca1\u6709\u4efb\u4f55\u969c\u788d\uff0c\u6240\u4ee5\u4e0d\u9700\u8981\u4efb\u4f55\u4fa7\u8df3\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1aobstacles = [0,2,1,0,3,0]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6700\u4f18\u65b9\u6848\u5982\u4e0a\u56fe\u6240\u793a\u3002\u603b\u5171\u6709 2 \u6b21\u4fa7\u8df3\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • obstacles.length == n + 1
  • \n\t
  • 1 <= n <= 5 * 105
  • \n\t
  • 0 <= obstacles[i] <= 3
  • \n\t
  • obstacles[0] == obstacles[n] == 0
  • \n
\n", "tags_en": ["Breadth-first Search", "Dynamic Programming"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minSideJumps(vector& obstacles) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minSideJumps(int[] obstacles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minSideJumps(self, obstacles):\n \"\"\"\n :type obstacles: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minSideJumps(self, obstacles: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minSideJumps(int* obstacles, int obstaclesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinSideJumps(int[] obstacles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} obstacles\n * @return {number}\n */\nvar minSideJumps = function(obstacles) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} obstacles\n# @return {Integer}\ndef min_side_jumps(obstacles)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minSideJumps(_ obstacles: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minSideJumps(obstacles []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minSideJumps(obstacles: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minSideJumps(obstacles: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_side_jumps(obstacles: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $obstacles\n * @return Integer\n */\n function minSideJumps($obstacles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minSideJumps(obstacles: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-side-jumps obstacles)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1824](https://leetcode-cn.com/problems/minimum-sideway-jumps)", "[\u6700\u5c11\u4fa7\u8df3\u6b21\u6570](/solution/1800-1899/1824.Minimum%20Sideway%20Jumps/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1824](https://leetcode.com/problems/minimum-sideway-jumps)", "[Minimum Sideway Jumps](/solution/1800-1899/1824.Minimum%20Sideway%20Jumps/README_EN.md)", "`Breadth-first Search`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "1951", "frontend_question_id": "1823", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-the-winner-of-the-circular-game", "url_en": "https://leetcode.com/problems/find-the-winner-of-the-circular-game", "relative_path_cn": "/solution/1800-1899/1823.Find%20the%20Winner%20of%20the%20Circular%20Game/README.md", "relative_path_en": "/solution/1800-1899/1823.Find%20the%20Winner%20of%20the%20Circular%20Game/README_EN.md", "title_cn": "\u627e\u51fa\u6e38\u620f\u7684\u83b7\u80dc\u8005", "title_en": "Find the Winner of the Circular Game", "question_title_slug": "find-the-winner-of-the-circular-game", "content_en": "

There are n friends that are playing a game. The friends are sitting in a circle and are numbered from 1 to n in clockwise order. More formally, moving clockwise from the ith friend brings you to the (i+1)th friend for 1 <= i < n, and moving clockwise from the nth friend brings you to the 1st friend.

\r\n\r\n

The rules of the game are as follows:

\r\n\r\n
    \r\n\t
  1. Start at the 1st friend.
  2. \r\n\t
  3. Count the next k friends in the clockwise direction including the friend you started at. The counting wraps around the circle and may count some friends more than once.
  4. \r\n\t
  5. The last friend you counted leaves the circle and loses the game.
  6. \r\n\t
  7. If there is still more than one friend in the circle, go back to step 2 starting from the friend immediately clockwise of the friend who just lost and repeat.
  8. \r\n\t
  9. Else, the last friend in the circle wins the game.
  10. \r\n
\r\n\r\n

Given the number of friends, n, and an integer k, return the winner of the game.

\r\n\r\n

 

\r\n

Example 1:

\r\n\"\"\r\n
\r\nInput: n = 5, k = 2\r\nOutput: 3\r\nExplanation: Here are the steps of the game:\r\n1) Start at friend 1.\r\n2) Count 2 friends clockwise, which are friends 1 and 2.\r\n3) Friend 2 leaves the circle. Next start is friend 3.\r\n4) Count 2 friends clockwise, which are friends 3 and 4.\r\n5) Friend 4 leaves the circle. Next start is friend 5.\r\n6) Count 2 friends clockwise, which are friends 5 and 1.\r\n7) Friend 1 leaves the circle. Next start is friend 3.\r\n8) Count 2 friends clockwise, which are friends 3 and 5.\r\n9) Friend 5 leaves the circle. Only friend 3 is left, so they are the winner.
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: n = 6, k = 5\r\nOutput: 1\r\nExplanation: The friends leave in this order: 5, 4, 6, 2, 3. The winner is friend 1.\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= k <= n <= 500
  • \r\n
", "content_cn": "

\u5171\u6709 n \u540d\u5c0f\u4f19\u4f34\u4e00\u8d77\u505a\u6e38\u620f\u3002\u5c0f\u4f19\u4f34\u4eec\u56f4\u6210\u4e00\u5708\uff0c\u6309 \u987a\u65f6\u9488\u987a\u5e8f \u4ece 1 \u5230 n \u7f16\u53f7\u3002\u786e\u5207\u5730\u8bf4\uff0c\u4ece\u7b2c i \u540d\u5c0f\u4f19\u4f34\u987a\u65f6\u9488\u79fb\u52a8\u4e00\u4f4d\u4f1a\u5230\u8fbe\u7b2c (i+1) \u540d\u5c0f\u4f19\u4f34\u7684\u4f4d\u7f6e\uff0c\u5176\u4e2d 1 <= i < n \uff0c\u4ece\u7b2c n \u540d\u5c0f\u4f19\u4f34\u987a\u65f6\u9488\u79fb\u52a8\u4e00\u4f4d\u4f1a\u56de\u5230\u7b2c 1 \u540d\u5c0f\u4f19\u4f34\u7684\u4f4d\u7f6e\u3002

\n\n

\u6e38\u620f\u9075\u5faa\u5982\u4e0b\u89c4\u5219\uff1a

\n\n
    \n\t
  1. \u4ece\u7b2c 1 \u540d\u5c0f\u4f19\u4f34\u6240\u5728\u4f4d\u7f6e \u5f00\u59cb \u3002
  2. \n\t
  3. \u6cbf\u7740\u987a\u65f6\u9488\u65b9\u5411\u6570 k \u540d\u5c0f\u4f19\u4f34\uff0c\u8ba1\u6570\u65f6\u9700\u8981 \u5305\u542b \u8d77\u59cb\u65f6\u7684\u90a3\u4f4d\u5c0f\u4f19\u4f34\u3002\u9010\u4e2a\u7ed5\u5708\u8fdb\u884c\u8ba1\u6570\uff0c\u4e00\u4e9b\u5c0f\u4f19\u4f34\u53ef\u80fd\u4f1a\u88ab\u6570\u8fc7\u4e0d\u6b62\u4e00\u6b21\u3002
  4. \n\t
  5. \u4f60\u6570\u5230\u7684\u6700\u540e\u4e00\u540d\u5c0f\u4f19\u4f34\u9700\u8981\u79bb\u5f00\u5708\u5b50\uff0c\u5e76\u89c6\u4f5c\u8f93\u6389\u6e38\u620f\u3002
  6. \n\t
  7. \u5982\u679c\u5708\u5b50\u4e2d\u4ecd\u7136\u6709\u4e0d\u6b62\u4e00\u540d\u5c0f\u4f19\u4f34\uff0c\u4ece\u521a\u521a\u8f93\u6389\u7684\u5c0f\u4f19\u4f34\u7684 \u987a\u65f6\u9488\u4e0b\u4e00\u4f4d \u5c0f\u4f19\u4f34 \u5f00\u59cb\uff0c\u56de\u5230\u6b65\u9aa4 2 \u7ee7\u7eed\u6267\u884c\u3002
  8. \n\t
  9. \u5426\u5219\uff0c\u5708\u5b50\u4e2d\u6700\u540e\u4e00\u540d\u5c0f\u4f19\u4f34\u8d62\u5f97\u6e38\u620f\u3002
  10. \n
\n\n

\u7ed9\u4f60\u53c2\u4e0e\u6e38\u620f\u7684\u5c0f\u4f19\u4f34\u603b\u6570 n \uff0c\u548c\u4e00\u4e2a\u6574\u6570 k \uff0c\u8fd4\u56de\u6e38\u620f\u7684\u83b7\u80dc\u8005\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1an = 5, k = 2\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6e38\u620f\u8fd0\u884c\u6b65\u9aa4\u5982\u4e0b\uff1a\n1) \u4ece\u5c0f\u4f19\u4f34 1 \u5f00\u59cb\u3002\n2) \u987a\u65f6\u9488\u6570 2 \u540d\u5c0f\u4f19\u4f34\uff0c\u4e5f\u5c31\u662f\u5c0f\u4f19\u4f34 1 \u548c 2 \u3002\n3) \u5c0f\u4f19\u4f34 2 \u79bb\u5f00\u5708\u5b50\u3002\u4e0b\u4e00\u6b21\u4ece\u5c0f\u4f19\u4f34 3 \u5f00\u59cb\u3002\n4) \u987a\u65f6\u9488\u6570 2 \u540d\u5c0f\u4f19\u4f34\uff0c\u4e5f\u5c31\u662f\u5c0f\u4f19\u4f34 3 \u548c 4 \u3002\n5) \u5c0f\u4f19\u4f34 4 \u79bb\u5f00\u5708\u5b50\u3002\u4e0b\u4e00\u6b21\u4ece\u5c0f\u4f19\u4f34 5 \u5f00\u59cb\u3002\n6) \u987a\u65f6\u9488\u6570 2 \u540d\u5c0f\u4f19\u4f34\uff0c\u4e5f\u5c31\u662f\u5c0f\u4f19\u4f34 5 \u548c 1 \u3002\n7) \u5c0f\u4f19\u4f34 1 \u79bb\u5f00\u5708\u5b50\u3002\u4e0b\u4e00\u6b21\u4ece\u5c0f\u4f19\u4f34 3 \u5f00\u59cb\u3002\n8) \u987a\u65f6\u9488\u6570 2 \u540d\u5c0f\u4f19\u4f34\uff0c\u4e5f\u5c31\u662f\u5c0f\u4f19\u4f34 3 \u548c 5 \u3002\n9) \u5c0f\u4f19\u4f34 5 \u79bb\u5f00\u5708\u5b50\u3002\u53ea\u5269\u4e0b\u5c0f\u4f19\u4f34 3 \u3002\u6240\u4ee5\u5c0f\u4f19\u4f34 3 \u662f\u6e38\u620f\u7684\u83b7\u80dc\u8005\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1an = 6, k = 5\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u5c0f\u4f19\u4f34\u79bb\u5f00\u5708\u5b50\u7684\u987a\u5e8f\uff1a5\u30014\u30016\u30012\u30013 \u3002\u5c0f\u4f19\u4f34 1 \u662f\u6e38\u620f\u7684\u83b7\u80dc\u8005\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= k <= n <= 500
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findTheWinner(int n, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findTheWinner(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findTheWinner(self, n, k):\n \"\"\"\n :type n: int\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findTheWinner(self, n: int, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findTheWinner(int n, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindTheWinner(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} k\n * @return {number}\n */\nvar findTheWinner = function(n, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} k\n# @return {Integer}\ndef find_the_winner(n, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findTheWinner(_ n: Int, _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findTheWinner(n int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findTheWinner(n: Int, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findTheWinner(n: Int, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_the_winner(n: i32, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $k\n * @return Integer\n */\n function findTheWinner($n, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findTheWinner(n: number, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-the-winner n k)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1823](https://leetcode-cn.com/problems/find-the-winner-of-the-circular-game)", "[\u627e\u51fa\u6e38\u620f\u7684\u83b7\u80dc\u8005](/solution/1800-1899/1823.Find%20the%20Winner%20of%20the%20Circular%20Game/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1823](https://leetcode.com/problems/find-the-winner-of-the-circular-game)", "[Find the Winner of the Circular Game](/solution/1800-1899/1823.Find%20the%20Winner%20of%20the%20Circular%20Game/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "1950", "frontend_question_id": "1822", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sign-of-the-product-of-an-array", "url_en": "https://leetcode.com/problems/sign-of-the-product-of-an-array", "relative_path_cn": "/solution/1800-1899/1822.Sign%20of%20the%20Product%20of%20an%20Array/README.md", "relative_path_en": "/solution/1800-1899/1822.Sign%20of%20the%20Product%20of%20an%20Array/README_EN.md", "title_cn": "\u6570\u7ec4\u5143\u7d20\u79ef\u7684\u7b26\u53f7", "title_en": "Sign of the Product of an Array", "question_title_slug": "sign-of-the-product-of-an-array", "content_en": "

There is a function signFunc(x) that returns:

\n\n
    \n\t
  • 1 if x is positive.
  • \n\t
  • -1 if x is negative.
  • \n\t
  • 0 if x is equal to 0.
  • \n
\n\n

You are given an integer array nums. Let product be the product of all values in the array nums.

\n\n

Return signFunc(product).

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [-1,-2,-3,-4,3,2,1]\nOutput: 1\nExplanation: The product of all values in the array is 144, and signFunc(144) = 1\n
\n\n

Example 2:

\n\n
\nInput: nums = [1,5,0,2,-3]\nOutput: 0\nExplanation: The product of all values in the array is 0, and signFunc(0) = 0\n
\n\n

Example 3:

\n\n
\nInput: nums = [-1,1,-1,1,-1]\nOutput: -1\nExplanation: The product of all values in the array is -1, and signFunc(-1) = -1\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 1000
  • \n\t
  • -100 <= nums[i] <= 100
  • \n
\n", "content_cn": "

\u5df2\u77e5\u51fd\u6570\u00a0signFunc(x) \u5c06\u4f1a\u6839\u636e x \u7684\u6b63\u8d1f\u8fd4\u56de\u7279\u5b9a\u503c\uff1a

\n\n
    \n\t
  • \u5982\u679c x \u662f\u6b63\u6570\uff0c\u8fd4\u56de 1 \u3002
  • \n\t
  • \u5982\u679c x \u662f\u8d1f\u6570\uff0c\u8fd4\u56de -1 \u3002
  • \n\t
  • \u5982\u679c x \u662f\u7b49\u4e8e 0 \uff0c\u8fd4\u56de 0 \u3002
  • \n
\n\n

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \u3002\u4ee4 product \u4e3a\u6570\u7ec4 nums \u4e2d\u6240\u6709\u5143\u7d20\u503c\u7684\u4e58\u79ef\u3002

\n\n

\u8fd4\u56de signFunc(product) \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [-1,-2,-3,-4,3,2,1]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u6570\u7ec4\u4e2d\u6240\u6709\u503c\u7684\u4e58\u79ef\u662f 144 \uff0c\u4e14 signFunc(144) = 1\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [1,5,0,2,-3]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6570\u7ec4\u4e2d\u6240\u6709\u503c\u7684\u4e58\u79ef\u662f 0 \uff0c\u4e14 signFunc(0) = 0\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [-1,1,-1,1,-1]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u6570\u7ec4\u4e2d\u6240\u6709\u503c\u7684\u4e58\u79ef\u662f -1 \uff0c\u4e14 signFunc(-1) = -1\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 1000
  • \n\t
  • -100 <= nums[i] <= 100
  • \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int arraySign(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int arraySign(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def arraySign(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def arraySign(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint arraySign(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ArraySign(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar arraySign = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef array_sign(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func arraySign(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func arraySign(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def arraySign(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun arraySign(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn array_sign(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function arraySign($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function arraySign(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (array-sign nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1822](https://leetcode-cn.com/problems/sign-of-the-product-of-an-array)", "[\u6570\u7ec4\u5143\u7d20\u79ef\u7684\u7b26\u53f7](/solution/1800-1899/1822.Sign%20of%20the%20Product%20of%20an%20Array/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[1822](https://leetcode.com/problems/sign-of-the-product-of-an-array)", "[Sign of the Product of an Array](/solution/1800-1899/1822.Sign%20of%20the%20Product%20of%20an%20Array/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "1949", "frontend_question_id": "1804", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/implement-trie-ii-prefix-tree", "url_en": "https://leetcode.com/problems/implement-trie-ii-prefix-tree", "relative_path_cn": "/solution/1800-1899/1804.Implement%20Trie%20II%20%28Prefix%20Tree%29/README.md", "relative_path_en": "/solution/1800-1899/1804.Implement%20Trie%20II%20%28Prefix%20Tree%29/README_EN.md", "title_cn": "\u5b9e\u73b0 Trie \uff08\u524d\u7f00\u6811\uff09 II", "title_en": "Implement Trie II (Prefix Tree)", "question_title_slug": "implement-trie-ii-prefix-tree", "content_en": "

A trie (pronounced as "try") or prefix tree is a tree data structure used to efficiently store and retrieve keys in a dataset of strings. There are various applications of this data structure, such as autocomplete and spellchecker.

\n\n

Implement the Trie class:

\n\n
    \n\t
  • Trie() Initializes the trie object.
  • \n\t
  • void insert(String word) Inserts the string word into the trie.
  • \n\t
  • int countWordsEqualTo(String word) Returns the number of instances of the string word in the trie.
  • \n\t
  • int countWordsStartingWith(String prefix) Returns the number of strings in the trie that have the string prefix as a prefix.
  • \n\t
  • void erase(String word) Erases the string word from the trie.
  • \n
\n\n

 

\n

Example 1:

\n\n
\nInput\n["Trie", "insert", "insert", "countWordsEqualTo", "countWordsStartingWith", "erase", "countWordsEqualTo", "countWordsStartingWith", "erase", "countWordsStartingWith"]\n[[], ["apple"], ["apple"], ["apple"], ["app"], ["apple"], ["apple"], ["app"], ["apple"], ["app"]]\nOutput\n[null, null, null, 2, 2, null, 1, 1, null, 0]\n\nExplanation\nTrie trie = new Trie();\ntrie.insert("apple");               // Inserts "apple".\ntrie.insert("apple");               // Inserts another "apple".\ntrie.countWordsEqualTo("apple");    // There are two instances of "apple" so return 2.\ntrie.countWordsStartingWith("app"); // "app" is a prefix of "apple" so return 2.\ntrie.erase("apple");                // Erases one "apple".\ntrie.countWordsEqualTo("apple");    // Now there is only one instance of "apple" so return 1.\ntrie.countWordsStartingWith("app"); // return 1\ntrie.erase("apple");                // Erases "apple". Now the trie is empty.\ntrie.countWordsStartingWith("app"); // return 0\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= word.length, prefix.length <= 2000
  • \n\t
  • word and prefix consist only of lowercase English letters.
  • \n\t
  • At most 3 * 104 calls in total will be made to insert, countWordsEqualTo, countWordsStartingWith, and erase.
  • \n\t
  • It is guaranteed that for any function call to erase, the string word will exist in the trie.
  • \n
\n", "content_cn": "

\u524d\u7f00\u6811\uff08trie\u00a0\uff0c\u53d1\u97f3\u4e3a \"try\"\uff09\u662f\u4e00\u4e2a\u6811\u72b6\u7684\u6570\u636e\u7ed3\u6784\uff0c\u7528\u4e8e\u9ad8\u6548\u5730\u5b58\u50a8\u548c\u68c0\u7d22\u4e00\u7cfb\u5217\u5b57\u7b26\u4e32\u7684\u524d\u7f00\u3002\u524d\u7f00\u6811\u6709\u8bb8\u591a\u5e94\u7528\uff0c\u5982\u81ea\u52a8\u8865\u5168\u548c\u62fc\u5199\u68c0\u67e5\u3002

\n\n

\u5b9e\u73b0\u524d\u7f00\u6811 Trie \u7c7b\uff1a

\n\n
    \n\t
  • Trie()\u00a0\u521d\u59cb\u5316\u524d\u7f00\u6811\u5bf9\u8c61\u3002
  • \n\t
  • void insert(String word)\u00a0\u5c06\u5b57\u7b26\u4e32\u00a0word\u00a0\u63d2\u5165\u524d\u7f00\u6811\u4e2d\u3002
  • \n\t
  • int countWordsEqualTo(String word)\u00a0\u8fd4\u56de\u524d\u7f00\u6811\u4e2d\u5b57\u7b26\u4e32\u00a0word\u00a0\u7684\u5b9e\u4f8b\u4e2a\u6570\u3002
  • \n\t
  • int countWordsStartingWith(String prefix)\u00a0\u8fd4\u56de\u524d\u7f00\u6811\u4e2d\u4ee5\u00a0prefix\u00a0\u4e3a\u524d\u7f00\u7684\u5b57\u7b26\u4e32\u4e2a\u6570\u3002
  • \n\t
  • void erase(String word)\u00a0\u4ece\u524d\u7f00\u6811\u4e2d\u79fb\u9664\u5b57\u7b26\u4e32\u00a0word \u3002
  • \n
\n\n

\u00a0

\n\n

\u793a\u4f8b 1:

\n\n
\u8f93\u5165\n[\"Trie\", \"insert\", \"insert\", \"countWordsEqualTo\", \"countWordsStartingWith\", \"erase\", \"countWordsEqualTo\", \"countWordsStartingWith\", \"erase\", \"countWordsStartingWith\"]\n[[], [\"apple\"], [\"apple\"], [\"apple\"], [\"app\"], [\"apple\"], [\"apple\"], [\"app\"], [\"apple\"], [\"app\"]]\n\u8f93\u51fa\n[null, null, null, 2, 2, null, 1, 1, null, 0]\n\n\u89e3\u91ca\nTrie trie = new Trie();\ntrie.insert(\"apple\");               // \u63d2\u5165 \"apple\"\u3002\ntrie.insert(\"apple\");               // \u63d2\u5165\u53e6\u4e00\u4e2a \"apple\"\u3002\ntrie.countWordsEqualTo(\"apple\");    // \u6709\u4e24\u4e2a \"apple\" \u5b9e\u4f8b\uff0c\u6240\u4ee5\u8fd4\u56de 2\u3002\ntrie.countWordsStartingWith(\"app\"); // \"app\" \u662f \"apple\" \u7684\u524d\u7f00\uff0c\u6240\u4ee5\u8fd4\u56de 2\u3002\ntrie.erase(\"apple\");                // \u79fb\u9664\u4e00\u4e2a \"apple\"\u3002\ntrie.countWordsEqualTo(\"apple\");    // \u73b0\u5728\u53ea\u6709\u4e00\u4e2a \"apple\" \u5b9e\u4f8b\uff0c\u6240\u4ee5\u8fd4\u56de 1\u3002\ntrie.countWordsStartingWith(\"app\"); // \u8fd4\u56de 1\ntrie.erase(\"apple\");                // \u79fb\u9664 \"apple\"\u3002\u73b0\u5728\u524d\u7f00\u6811\u662f\u7a7a\u7684\u3002\ntrie.countWordsStartingWith(\"app\"); // \u8fd4\u56de 0\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= word.length, prefix.length <= 2000
  • \n\t
  • word\u00a0\u548c\u00a0prefix\u00a0\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
  • \n\t
  • insert\u3001\u00a0countWordsEqualTo\u3001\u00a0countWordsStartingWith\u00a0\u548c\u00a0erase\u00a0\u603b\u5171\u8c03\u7528\u6700\u591a\u00a03 * 104\u00a0\u6b21\u3002
  • \n\t
  • \u4fdd\u8bc1\u6bcf\u6b21\u8c03\u7528\u00a0erase\u00a0\u65f6\uff0c\u5b57\u7b26\u4e32\u00a0word\u00a0\u603b\u662f\u5b58\u5728\u4e8e\u524d\u7f00\u6811\u4e2d\u3002
  • \n
\n", "tags_en": ["Trie", "String"], "tags_cn": ["\u5b57\u5178\u6811", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Trie {\npublic:\n Trie() {\n\n }\n \n void insert(string word) {\n\n }\n \n int countWordsEqualTo(string word) {\n\n }\n \n int countWordsStartingWith(string prefix) {\n\n }\n \n void erase(string word) {\n\n }\n};\n\n/**\n * Your Trie object will be instantiated and called as such:\n * Trie* obj = new Trie();\n * obj->insert(word);\n * int param_2 = obj->countWordsEqualTo(word);\n * int param_3 = obj->countWordsStartingWith(prefix);\n * obj->erase(word);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Trie {\n\n public Trie() {\n\n }\n \n public void insert(String word) {\n\n }\n \n public int countWordsEqualTo(String word) {\n\n }\n \n public int countWordsStartingWith(String prefix) {\n\n }\n \n public void erase(String word) {\n\n }\n}\n\n/**\n * Your Trie object will be instantiated and called as such:\n * Trie obj = new Trie();\n * obj.insert(word);\n * int param_2 = obj.countWordsEqualTo(word);\n * int param_3 = obj.countWordsStartingWith(prefix);\n * obj.erase(word);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Trie(object):\n\n def __init__(self):\n\n\n def insert(self, word):\n \"\"\"\n :type word: str\n :rtype: None\n \"\"\"\n\n\n def countWordsEqualTo(self, word):\n \"\"\"\n :type word: str\n :rtype: int\n \"\"\"\n\n\n def countWordsStartingWith(self, prefix):\n \"\"\"\n :type prefix: str\n :rtype: int\n \"\"\"\n\n\n def erase(self, word):\n \"\"\"\n :type word: str\n :rtype: None\n \"\"\"\n\n\n\n# Your Trie object will be instantiated and called as such:\n# obj = Trie()\n# obj.insert(word)\n# param_2 = obj.countWordsEqualTo(word)\n# param_3 = obj.countWordsStartingWith(prefix)\n# obj.erase(word)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Trie:\n\n def __init__(self):\n\n\n def insert(self, word: str) -> None:\n\n\n def countWordsEqualTo(self, word: str) -> int:\n\n\n def countWordsStartingWith(self, prefix: str) -> int:\n\n\n def erase(self, word: str) -> None:\n\n\n\n# Your Trie object will be instantiated and called as such:\n# obj = Trie()\n# obj.insert(word)\n# param_2 = obj.countWordsEqualTo(word)\n# param_3 = obj.countWordsStartingWith(prefix)\n# obj.erase(word)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} Trie;\n\n\nTrie* trieCreate() {\n \n}\n\nvoid trieInsert(Trie* obj, char * word) {\n \n}\n\nint trieCountWordsEqualTo(Trie* obj, char * word) {\n \n}\n\nint trieCountWordsStartingWith(Trie* obj, char * prefix) {\n \n}\n\nvoid trieErase(Trie* obj, char * word) {\n \n}\n\nvoid trieFree(Trie* obj) {\n \n}\n\n/**\n * Your Trie struct will be instantiated and called as such:\n * Trie* obj = trieCreate();\n * trieInsert(obj, word);\n \n * int param_2 = trieCountWordsEqualTo(obj, word);\n \n * int param_3 = trieCountWordsStartingWith(obj, prefix);\n \n * trieErase(obj, word);\n \n * trieFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Trie {\n\n public Trie() {\n\n }\n \n public void Insert(string word) {\n\n }\n \n public int CountWordsEqualTo(string word) {\n\n }\n \n public int CountWordsStartingWith(string prefix) {\n\n }\n \n public void Erase(string word) {\n\n }\n}\n\n/**\n * Your Trie object will be instantiated and called as such:\n * Trie obj = new Trie();\n * obj.Insert(word);\n * int param_2 = obj.CountWordsEqualTo(word);\n * int param_3 = obj.CountWordsStartingWith(prefix);\n * obj.Erase(word);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "\nvar Trie = function() {\n\n};\n\n/** \n * @param {string} word\n * @return {void}\n */\nTrie.prototype.insert = function(word) {\n\n};\n\n/** \n * @param {string} word\n * @return {number}\n */\nTrie.prototype.countWordsEqualTo = function(word) {\n\n};\n\n/** \n * @param {string} prefix\n * @return {number}\n */\nTrie.prototype.countWordsStartingWith = function(prefix) {\n\n};\n\n/** \n * @param {string} word\n * @return {void}\n */\nTrie.prototype.erase = function(word) {\n\n};\n\n/**\n * Your Trie object will be instantiated and called as such:\n * var obj = new Trie()\n * obj.insert(word)\n * var param_2 = obj.countWordsEqualTo(word)\n * var param_3 = obj.countWordsStartingWith(prefix)\n * obj.erase(word)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class Trie\n def initialize()\n\n end\n\n\n=begin\n :type word: String\n :rtype: Void\n=end\n def insert(word)\n\n end\n\n\n=begin\n :type word: String\n :rtype: Integer\n=end\n def count_words_equal_to(word)\n\n end\n\n\n=begin\n :type prefix: String\n :rtype: Integer\n=end\n def count_words_starting_with(prefix)\n\n end\n\n\n=begin\n :type word: String\n :rtype: Void\n=end\n def erase(word)\n\n end\n\n\nend\n\n# Your Trie object will be instantiated and called as such:\n# obj = Trie.new()\n# obj.insert(word)\n# param_2 = obj.count_words_equal_to(word)\n# param_3 = obj.count_words_starting_with(prefix)\n# obj.erase(word)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass Trie {\n\n init() {\n\n }\n \n func insert(_ word: String) {\n\n }\n \n func countWordsEqualTo(_ word: String) -> Int {\n\n }\n \n func countWordsStartingWith(_ prefix: String) -> Int {\n\n }\n \n func erase(_ word: String) {\n\n }\n}\n\n/**\n * Your Trie object will be instantiated and called as such:\n * let obj = Trie()\n * obj.insert(word)\n * let ret_2: Int = obj.countWordsEqualTo(word)\n * let ret_3: Int = obj.countWordsStartingWith(prefix)\n * obj.erase(word)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type Trie struct {\n\n}\n\n\nfunc Constructor() Trie {\n\n}\n\n\nfunc (this *Trie) Insert(word string) {\n\n}\n\n\nfunc (this *Trie) CountWordsEqualTo(word string) int {\n\n}\n\n\nfunc (this *Trie) CountWordsStartingWith(prefix string) int {\n\n}\n\n\nfunc (this *Trie) Erase(word string) {\n\n}\n\n\n/**\n * Your Trie object will be instantiated and called as such:\n * obj := Constructor();\n * obj.Insert(word);\n * param_2 := obj.CountWordsEqualTo(word);\n * param_3 := obj.CountWordsStartingWith(prefix);\n * obj.Erase(word);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class Trie() {\n\n def insert(word: String) {\n \n }\n\n def countWordsEqualTo(word: String): Int = {\n \n }\n\n def countWordsStartingWith(prefix: String): Int = {\n \n }\n\n def erase(word: String) {\n \n }\n\n}\n\n/**\n * Your Trie object will be instantiated and called as such:\n * var obj = new Trie()\n * obj.insert(word)\n * var param_2 = obj.countWordsEqualTo(word)\n * var param_3 = obj.countWordsStartingWith(prefix)\n * obj.erase(word)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Trie() {\n\n fun insert(word: String) {\n\n }\n\n fun countWordsEqualTo(word: String): Int {\n\n }\n\n fun countWordsStartingWith(prefix: String): Int {\n\n }\n\n fun erase(word: String) {\n\n }\n\n}\n\n/**\n * Your Trie object will be instantiated and called as such:\n * var obj = Trie()\n * obj.insert(word)\n * var param_2 = obj.countWordsEqualTo(word)\n * var param_3 = obj.countWordsStartingWith(prefix)\n * obj.erase(word)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct Trie {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl Trie {\n\n fn new() -> Self {\n\n }\n \n fn insert(&self, word: String) {\n\n }\n \n fn count_words_equal_to(&self, word: String) -> i32 {\n\n }\n \n fn count_words_starting_with(&self, prefix: String) -> i32 {\n\n }\n \n fn erase(&self, word: String) {\n\n }\n}\n\n/**\n * Your Trie object will be instantiated and called as such:\n * let obj = Trie::new();\n * obj.insert(word);\n * let ret_2: i32 = obj.count_words_equal_to(word);\n * let ret_3: i32 = obj.count_words_starting_with(prefix);\n * obj.erase(word);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Trie {\n /**\n */\n function __construct() {\n\n }\n\n /**\n * @param String $word\n * @return NULL\n */\n function insert($word) {\n\n }\n\n /**\n * @param String $word\n * @return Integer\n */\n function countWordsEqualTo($word) {\n\n }\n\n /**\n * @param String $prefix\n * @return Integer\n */\n function countWordsStartingWith($prefix) {\n\n }\n\n /**\n * @param String $word\n * @return NULL\n */\n function erase($word) {\n\n }\n}\n\n/**\n * Your Trie object will be instantiated and called as such:\n * $obj = Trie();\n * $obj->insert($word);\n * $ret_2 = $obj->countWordsEqualTo($word);\n * $ret_3 = $obj->countWordsStartingWith($prefix);\n * $obj->erase($word);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class Trie {\n constructor() {\n\n }\n\n insert(word: string): void {\n\n }\n\n countWordsEqualTo(word: string): number {\n\n }\n\n countWordsStartingWith(prefix: string): number {\n\n }\n\n erase(word: string): void {\n\n }\n}\n\n/**\n * Your Trie object will be instantiated and called as such:\n * var obj = new Trie()\n * obj.insert(word)\n * var param_2 = obj.countWordsEqualTo(word)\n * var param_3 = obj.countWordsStartingWith(prefix)\n * obj.erase(word)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define trie%\n (class object%\n (super-new)\n (init-field)\n \n ; insert : string? -> void?\n (define/public (insert word)\n\n )\n ; count-words-equal-to : string? -> exact-integer?\n (define/public (count-words-equal-to word)\n\n )\n ; count-words-starting-with : string? -> exact-integer?\n (define/public (count-words-starting-with prefix)\n\n )\n ; erase : string? -> void?\n (define/public (erase word)\n\n )))\n\n;; Your trie% object will be instantiated and called as such:\n;; (define obj (new trie%))\n;; (send obj insert word)\n;; (define param_2 (send obj count-words-equal-to word))\n;; (define param_3 (send obj count-words-starting-with prefix))\n;; (send obj erase word)", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1804](https://leetcode-cn.com/problems/implement-trie-ii-prefix-tree)", "[\u5b9e\u73b0 Trie \uff08\u524d\u7f00\u6811\uff09 II](/solution/1800-1899/1804.Implement%20Trie%20II%20%28Prefix%20Tree%29/README.md)", "`\u5b57\u5178\u6811`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1804](https://leetcode.com/problems/implement-trie-ii-prefix-tree)", "[Implement Trie II (Prefix Tree)](/solution/1800-1899/1804.Implement%20Trie%20II%20%28Prefix%20Tree%29/README_EN.md)", "`Trie`,`String`", "Medium", "\ud83d\udd12"]}, {"question_id": "1948", "frontend_question_id": "1795", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/rearrange-products-table", "url_en": "https://leetcode.com/problems/rearrange-products-table", "relative_path_cn": "/solution/1700-1799/1795.Rearrange%20Products%20Table/README.md", "relative_path_en": "/solution/1700-1799/1795.Rearrange%20Products%20Table/README_EN.md", "title_cn": "\u6bcf\u4e2a\u4ea7\u54c1\u5728\u4e0d\u540c\u5546\u5e97\u7684\u4ef7\u683c", "title_en": "Rearrange Products Table", "question_title_slug": "rearrange-products-table", "content_en": "

Table: Products

\r\n\r\n
\r\n+-------------+---------+\r\n| Column Name | Type    |\r\n+-------------+---------+\r\n| product_id  | int     |\r\n| store1      | int     |\r\n| store2      | int     |\r\n| store3      | int     |\r\n+-------------+---------+\r\nproduct_id is the primary key for this table.\r\nEach row in this table indicates the product's price in 3 different stores: store1, store2, and store3.\r\nIf the product is not available in a store, the price will be null in that store's column.\r\n
\r\n\r\n

 

\r\n\r\n

Write an SQL query to rearrange the Products table so that each row has (product_id, store, price). If a product is not available in a store, do not include a row with that product_id and store combination in the result table.

\r\n\r\n

Return the result table in any order.

\r\n\r\n

The query result format is in the following example:

\r\n\r\n

 

\r\n\r\n
\r\nProducts table:\r\n+------------+--------+--------+--------+\r\n| product_id | store1 | store2 | store3 |\r\n+------------+--------+--------+--------+\r\n| 0          | 95     | 100    | 105    |\r\n| 1          | 70     | null   | 80     |\r\n+------------+--------+--------+--------+\r\n\r\nResult table:\r\n+------------+--------+-------+\r\n| product_id | store  | price |\r\n+------------+--------+-------+\r\n| 0          | store1 | 95    |\r\n| 0          | store2 | 100   |\r\n| 0          | store3 | 105   |\r\n| 1          | store1 | 70    |\r\n| 1          | store3 | 80    |\r\n+------------+--------+-------+\r\n\r\nProduct 0 is available in all three stores with prices 95, 100, and 105 respectively.\r\nProduct 1 is available in store1 with price 70 and store3 with price 80. The product is not available in store2.\r\n
", "content_cn": "

\u8868\uff1aProducts

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| product_id  | int     |\n| store1      | int     |\n| store2      | int     |\n| store3      | int     |\n+-------------+---------+\n\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\u662fproduct_id\uff08\u4ea7\u54c1Id\uff09\u3002\n\u6bcf\u884c\u5b58\u50a8\u4e86\u8fd9\u4e00\u4ea7\u54c1\u5728\u4e0d\u540c\u5546\u5e97store1, store2, store3\u7684\u4ef7\u683c\u3002\n\u5982\u679c\u8fd9\u4e00\u4ea7\u54c1\u5728\u5546\u5e97\u91cc\u6ca1\u6709\u51fa\u552e\uff0c\u5219\u503c\u5c06\u4e3anull\u3002\n
\n\n

\u00a0

\n\n

\u8bf7\u4f60\u91cd\u6784 Products \u8868\uff0c\u67e5\u8be2\u6bcf\u4e2a\u4ea7\u54c1\u5728\u4e0d\u540c\u5546\u5e97\u7684\u4ef7\u683c\uff0c\u4f7f\u5f97\u8f93\u51fa\u7684\u683c\u5f0f\u53d8\u4e3a(product_id, store, price) \u3002\u5982\u679c\u8fd9\u4e00\u4ea7\u54c1\u5728\u5546\u5e97\u91cc\u6ca1\u6709\u51fa\u552e\uff0c\u5219\u4e0d\u8f93\u51fa\u8fd9\u4e00\u884c\u3002

\n\n

\u8f93\u51fa\u7ed3\u679c\u8868\u4e2d\u7684\u987a\u5e8f\u4e0d\u4f5c\u8981\u6c42\u3002

\n\n

\u67e5\u8be2\u8f93\u51fa\u683c\u5f0f\u8bf7\u53c2\u8003\u4e0b\u9762\u793a\u4f8b\u3002

\n\n

\u00a0

\n\n
\nProducts table:\n+------------+--------+--------+--------+\n| product_id | store1 | store2 | store3 |\n+------------+--------+--------+--------+\n| 0          | 95     | 100    | 105    |\n| 1          | 70     | null   | 80     |\n+------------+--------+--------+--------+\n\nResult table:\n+------------+--------+-------+\n| product_id | store  | price |\n+------------+--------+-------+\n| 0          | store1 | 95    |\n| 0          | store2 | 100   |\n| 0          | store3 | 105   |\n| 1          | store1 | 70    |\n| 1          | store3 | 80    |\n+------------+--------+-------+\n\n\u4ea7\u54c10\u5728store1\uff0cstore2,store3\u7684\u4ef7\u683c\u5206\u522b\u4e3a95,100,105\u3002\n\u4ea7\u54c11\u5728store1\uff0cstore3\u7684\u4ef7\u683c\u5206\u522b\u4e3a70,80\u3002\u5728store2\u65e0\u6cd5\u4e70\u5230\u3002\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1795](https://leetcode-cn.com/problems/rearrange-products-table)", "[\u6bcf\u4e2a\u4ea7\u54c1\u5728\u4e0d\u540c\u5546\u5e97\u7684\u4ef7\u683c](/solution/1700-1799/1795.Rearrange%20Products%20Table/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1795](https://leetcode.com/problems/rearrange-products-table)", "[Rearrange Products Table](/solution/1700-1799/1795.Rearrange%20Products%20Table/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1947", "frontend_question_id": "1819", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-different-subsequences-gcds", "url_en": "https://leetcode.com/problems/number-of-different-subsequences-gcds", "relative_path_cn": "/solution/1800-1899/1819.Number%20of%20Different%20Subsequences%20GCDs/README.md", "relative_path_en": "/solution/1800-1899/1819.Number%20of%20Different%20Subsequences%20GCDs/README_EN.md", "title_cn": "\u5e8f\u5217\u4e2d\u4e0d\u540c\u6700\u5927\u516c\u7ea6\u6570\u7684\u6570\u76ee", "title_en": "Number of Different Subsequences GCDs", "question_title_slug": "number-of-different-subsequences-gcds", "content_en": "

You are given an array nums that consists of positive integers.

\n\n

The GCD of a sequence of numbers is defined as the greatest integer that divides all the numbers in the sequence evenly.

\n\n
    \n\t
  • For example, the GCD of the sequence [4,6,16] is 2.
  • \n
\n\n

A subsequence of an array is a sequence that can be formed by removing some elements (possibly none) of the array.

\n\n
    \n\t
  • For example, [2,5,10] is a subsequence of [1,2,1,2,4,1,5,10].
  • \n
\n\n

Return the number of different GCDs among all non-empty subsequences of nums.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: nums = [6,10,3]\nOutput: 5\nExplanation: The figure shows all the non-empty subsequences and their GCDs.\nThe different GCDs are 6, 10, 3, 2, and 1.\n
\n\n

Example 2:

\n\n
\nInput: nums = [5,15,40,5,6]\nOutput: 7\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 105
  • \n\t
  • 1 <= nums[i] <= 2 * 105
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u7531\u6b63\u6574\u6570\u7ec4\u6210\u7684\u6570\u7ec4 nums \u3002

\n\n

\u6570\u5b57\u5e8f\u5217\u7684 \u6700\u5927\u516c\u7ea6\u6570 \u5b9a\u4e49\u4e3a\u5e8f\u5217\u4e2d\u6240\u6709\u6574\u6570\u7684\u5171\u6709\u7ea6\u6570\u4e2d\u7684\u6700\u5927\u6574\u6570\u3002

\n\n
    \n\t
  • \u4f8b\u5982\uff0c\u5e8f\u5217 [4,6,16] \u7684\u6700\u5927\u516c\u7ea6\u6570\u662f 2 \u3002
  • \n
\n\n

\u6570\u7ec4\u7684\u4e00\u4e2a \u5b50\u5e8f\u5217 \u672c\u8d28\u662f\u4e00\u4e2a\u5e8f\u5217\uff0c\u53ef\u4ee5\u901a\u8fc7\u5220\u9664\u6570\u7ec4\u4e2d\u7684\u67d0\u4e9b\u5143\u7d20\uff08\u6216\u8005\u4e0d\u5220\u9664\uff09\u5f97\u5230\u3002

\n\n
    \n\t
  • \u4f8b\u5982\uff0c[2,5,10] \u662f [1,2,1,2,4,1,5,10] \u7684\u4e00\u4e2a\u5b50\u5e8f\u5217\u3002
  • \n
\n\n

\u8ba1\u7b97\u5e76\u8fd4\u56de nums \u7684\u6240\u6709 \u975e\u7a7a \u5b50\u5e8f\u5217\u4e2d \u4e0d\u540c \u6700\u5927\u516c\u7ea6\u6570\u7684 \u6570\u76ee \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1anums = [6,10,3]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u4e0a\u56fe\u663e\u793a\u4e86\u6240\u6709\u7684\u975e\u7a7a\u5b50\u5e8f\u5217\u4e0e\u5404\u81ea\u7684\u6700\u5927\u516c\u7ea6\u6570\u3002\n\u4e0d\u540c\u7684\u6700\u5927\u516c\u7ea6\u6570\u4e3a 6 \u300110 \u30013 \u30012 \u548c 1 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [5,15,40,5,6]\n\u8f93\u51fa\uff1a7\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 105
  • \n\t
  • 1 <= nums[i] <= 2 * 105
  • \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countDifferentSubsequenceGCDs(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countDifferentSubsequenceGCDs(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countDifferentSubsequenceGCDs(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countDifferentSubsequenceGCDs(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countDifferentSubsequenceGCDs(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountDifferentSubsequenceGCDs(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar countDifferentSubsequenceGCDs = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef count_different_subsequence_gc_ds(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countDifferentSubsequenceGCDs(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countDifferentSubsequenceGCDs(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countDifferentSubsequenceGCDs(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countDifferentSubsequenceGCDs(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_different_subsequence_gc_ds(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function countDifferentSubsequenceGCDs($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countDifferentSubsequenceGCDs(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-different-subsequence-gc-ds nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1819](https://leetcode-cn.com/problems/number-of-different-subsequences-gcds)", "[\u5e8f\u5217\u4e2d\u4e0d\u540c\u6700\u5927\u516c\u7ea6\u6570\u7684\u6570\u76ee](/solution/1800-1899/1819.Number%20of%20Different%20Subsequences%20GCDs/README.md)", "`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[1819](https://leetcode.com/problems/number-of-different-subsequences-gcds)", "[Number of Different Subsequences GCDs](/solution/1800-1899/1819.Number%20of%20Different%20Subsequences%20GCDs/README_EN.md)", "`Math`", "Hard", ""]}, {"question_id": "1946", "frontend_question_id": "1818", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-absolute-sum-difference", "url_en": "https://leetcode.com/problems/minimum-absolute-sum-difference", "relative_path_cn": "/solution/1800-1899/1818.Minimum%20Absolute%20Sum%20Difference/README.md", "relative_path_en": "/solution/1800-1899/1818.Minimum%20Absolute%20Sum%20Difference/README_EN.md", "title_cn": "\u7edd\u5bf9\u5dee\u503c\u548c", "title_en": "Minimum Absolute Sum Difference", "question_title_slug": "minimum-absolute-sum-difference", "content_en": "

You are given two positive integer arrays nums1 and nums2, both of length n.

\n\n

The absolute sum difference of arrays nums1 and nums2 is defined as the sum of |nums1[i] - nums2[i]| for each 0 <= i < n (0-indexed).

\n\n

You can replace at most one element of nums1 with any other element in nums1 to minimize the absolute sum difference.

\n\n

Return the minimum absolute sum difference after replacing at most one element in the array nums1. Since the answer may be large, return it modulo 109 + 7.

\n\n

|x| is defined as:

\n\n
    \n\t
  • x if x >= 0, or
  • \n\t
  • -x if x < 0.
  • \n
\n\n

 

\n

Example 1:

\n\n
\nInput: nums1 = [1,7,5], nums2 = [2,3,5]\nOutput: 3\nExplanation: There are two possible optimal solutions:\n- Replace the second element with the first: [1,7,5] => [1,1,5], or\n- Replace the second element with the third: [1,7,5] => [1,5,5].\nBoth will yield an absolute sum difference of |1-2| + (|1-3| or |5-3|) + |5-5| = 3.\n
\n\n

Example 2:

\n\n
\nInput: nums1 = [2,4,6,8,10], nums2 = [2,4,6,8,10]\nOutput: 0\nExplanation: nums1 is equal to nums2 so no replacement is needed. This will result in an \nabsolute sum difference of 0.\n
\n\n

Example 3:

\n\n
\nInput: nums1 = [1,10,4,4,2,7], nums2 = [9,3,5,1,7,4]\nOutput: 20\nExplanation: Replace the first element with the second: [1,10,4,4,2,7] => [10,10,4,4,2,7].\nThis yields an absolute sum difference of |10-9| + |10-3| + |4-5| + |4-1| + |2-7| + |7-4| = 20\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == nums1.length
  • \n\t
  • n == nums2.length
  • \n\t
  • 1 <= n <= 105
  • \n\t
  • 1 <= nums1[i], nums2[i] <= 105
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e24\u4e2a\u6b63\u6574\u6570\u6570\u7ec4 nums1 \u548c nums2 \uff0c\u6570\u7ec4\u7684\u957f\u5ea6\u90fd\u662f n \u3002

\n\n

\u6570\u7ec4 nums1 \u548c nums2 \u7684 \u7edd\u5bf9\u5dee\u503c\u548c \u5b9a\u4e49\u4e3a\u6240\u6709 |nums1[i] - nums2[i]|\uff080 <= i < n\uff09\u7684 \u603b\u548c\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\u3002

\n\n

\u4f60\u53ef\u4ee5\u9009\u7528 nums1 \u4e2d\u7684 \u4efb\u610f\u4e00\u4e2a \u5143\u7d20\u6765\u66ff\u6362 nums1 \u4e2d\u7684 \u81f3\u591a \u4e00\u4e2a\u5143\u7d20\uff0c\u4ee5 \u6700\u5c0f\u5316 \u7edd\u5bf9\u5dee\u503c\u548c\u3002

\n\n

\u5728\u66ff\u6362\u6570\u7ec4 nums1 \u4e2d\u6700\u591a\u4e00\u4e2a\u5143\u7d20 \u4e4b\u540e \uff0c\u8fd4\u56de\u6700\u5c0f\u7edd\u5bf9\u5dee\u503c\u548c\u3002\u56e0\u4e3a\u7b54\u6848\u53ef\u80fd\u5f88\u5927\uff0c\u6240\u4ee5\u9700\u8981\u5bf9 109 + 7 \u53d6\u4f59 \u540e\u8fd4\u56de\u3002

\n\n

|x| \u5b9a\u4e49\u4e3a\uff1a

\n\n
    \n\t
  • \u5982\u679c x >= 0 \uff0c\u503c\u4e3a x \uff0c\u6216\u8005
  • \n\t
  • \u5982\u679c x <= 0 \uff0c\u503c\u4e3a -x
  • \n
\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1anums1 = [1,7,5], nums2 = [2,3,5]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6709\u4e24\u79cd\u53ef\u80fd\u7684\u6700\u4f18\u65b9\u6848\uff1a\n- \u5c06\u7b2c\u4e8c\u4e2a\u5143\u7d20\u66ff\u6362\u4e3a\u7b2c\u4e00\u4e2a\u5143\u7d20\uff1a[1,7,5] => [1,1,5] \uff0c\u6216\u8005\n- \u5c06\u7b2c\u4e8c\u4e2a\u5143\u7d20\u66ff\u6362\u4e3a\u7b2c\u4e09\u4e2a\u5143\u7d20\uff1a[1,7,5] => [1,5,5]\n\u4e24\u79cd\u65b9\u6848\u7684\u7edd\u5bf9\u5dee\u503c\u548c\u90fd\u662f |1-2| + (|1-3| \u6216\u8005 |5-3|) + |5-5| = 3\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1anums1 = [2,4,6,8,10], nums2 = [2,4,6,8,10]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1anums1 \u548c nums2 \u76f8\u7b49\uff0c\u6240\u4ee5\u4e0d\u7528\u66ff\u6362\u5143\u7d20\u3002\u7edd\u5bf9\u5dee\u503c\u548c\u4e3a 0\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1anums1 = [1,10,4,4,2,7], nums2 = [9,3,5,1,7,4]\n\u8f93\u51fa\uff1a20\n\u89e3\u91ca\uff1a\u5c06\u7b2c\u4e00\u4e2a\u5143\u7d20\u66ff\u6362\u4e3a\u7b2c\u4e8c\u4e2a\u5143\u7d20\uff1a[1,10,4,4,2,7] => [10,10,4,4,2,7]\n\u7edd\u5bf9\u5dee\u503c\u548c\u4e3a |10-9| + |10-3| + |4-5| + |4-1| + |2-7| + |7-4| = 20\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • n == nums1.length
  • \n\t
  • n == nums2.length
  • \n\t
  • 1 <= n <= 105
  • \n\t
  • 1 <= nums1[i], nums2[i] <= 105
  • \n
\n", "tags_en": ["Greedy", "Binary Search"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minAbsoluteSumDiff(vector& nums1, vector& nums2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minAbsoluteSumDiff(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minAbsoluteSumDiff(self, nums1, nums2):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minAbsoluteSumDiff(self, nums1: List[int], nums2: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minAbsoluteSumDiff(int* nums1, int nums1Size, int* nums2, int nums2Size){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinAbsoluteSumDiff(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums1\n * @param {number[]} nums2\n * @return {number}\n */\nvar minAbsoluteSumDiff = function(nums1, nums2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums1\n# @param {Integer[]} nums2\n# @return {Integer}\ndef min_absolute_sum_diff(nums1, nums2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minAbsoluteSumDiff(_ nums1: [Int], _ nums2: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minAbsoluteSumDiff(nums1 []int, nums2 []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minAbsoluteSumDiff(nums1: Array[Int], nums2: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minAbsoluteSumDiff(nums1: IntArray, nums2: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_absolute_sum_diff(nums1: Vec, nums2: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums1\n * @param Integer[] $nums2\n * @return Integer\n */\n function minAbsoluteSumDiff($nums1, $nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minAbsoluteSumDiff(nums1: number[], nums2: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-absolute-sum-diff nums1 nums2)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1818](https://leetcode-cn.com/problems/minimum-absolute-sum-difference)", "[\u7edd\u5bf9\u5dee\u503c\u548c](/solution/1800-1899/1818.Minimum%20Absolute%20Sum%20Difference/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1818](https://leetcode.com/problems/minimum-absolute-sum-difference)", "[Minimum Absolute Sum Difference](/solution/1800-1899/1818.Minimum%20Absolute%20Sum%20Difference/README_EN.md)", "`Greedy`,`Binary Search`", "Medium", ""]}, {"question_id": "1945", "frontend_question_id": "1817", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/finding-the-users-active-minutes", "url_en": "https://leetcode.com/problems/finding-the-users-active-minutes", "relative_path_cn": "/solution/1800-1899/1817.Finding%20the%20Users%20Active%20Minutes/README.md", "relative_path_en": "/solution/1800-1899/1817.Finding%20the%20Users%20Active%20Minutes/README_EN.md", "title_cn": "\u67e5\u627e\u7528\u6237\u6d3b\u8dc3\u5206\u949f\u6570", "title_en": "Finding the Users Active Minutes", "question_title_slug": "finding-the-users-active-minutes", "content_en": "

You are given the logs for users' actions on LeetCode, and an integer k. The logs are represented by a 2D integer array logs where each logs[i] = [IDi, timei] indicates that the user with IDi performed an action at the minute timei.

\n\n

Multiple users can perform actions simultaneously, and a single user can perform multiple actions in the same minute.

\n\n

The user active minutes (UAM) for a given user is defined as the number of unique minutes in which the user performed an action on LeetCode. A minute can only be counted once, even if multiple actions occur during it.

\n\n

You are to calculate a 1-indexed array answer of size k such that, for each j (1 <= j <= k), answer[j] is the number of users whose UAM equals j.

\n\n

Return the array answer as described above.

\n\n

 

\n

Example 1:

\n\n
\nInput: logs = [[0,5],[1,2],[0,2],[0,5],[1,3]], k = 5\nOutput: [0,2,0,0,0]\nExplanation:\nThe user with ID=0 performed actions at minutes 5, 2, and 5 again. Hence, they have a UAM of 2 (minute 5 is only counted once).\nThe user with ID=1 performed actions at minutes 2 and 3. Hence, they have a UAM of 2.\nSince both users have a UAM of 2, answer[2] is 2, and the remaining answer[j] values are 0.\n
\n\n

Example 2:

\n\n
\nInput: logs = [[1,1],[2,2],[2,3]], k = 4\nOutput: [1,1,0,0]\nExplanation:\nThe user with ID=1 performed a single action at minute 1. Hence, they have a UAM of 1.\nThe user with ID=2 performed actions at minutes 2 and 3. Hence, they have a UAM of 2.\nThere is one user with a UAM of 1 and one with a UAM of 2.\nHence, answer[1] = 1, answer[2] = 1, and the remaining values are 0.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= logs.length <= 104
  • \n\t
  • 0 <= IDi <= 109
  • \n\t
  • 1 <= timei <= 105
  • \n\t
  • k is in the range [The maximum UAM for a user, 105].
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u7528\u6237\u5728 LeetCode \u7684\u64cd\u4f5c\u65e5\u5fd7\uff0c\u548c\u4e00\u4e2a\u6574\u6570 k \u3002\u65e5\u5fd7\u7528\u4e00\u4e2a\u4e8c\u7ef4\u6574\u6570\u6570\u7ec4 logs \u8868\u793a\uff0c\u5176\u4e2d\u6bcf\u4e2a logs[i] = [IDi, timei] \u8868\u793a ID \u4e3a IDi \u7684\u7528\u6237\u5728 timei \u5206\u949f\u65f6\u6267\u884c\u4e86\u67d0\u4e2a\u64cd\u4f5c\u3002

\n\n

\u591a\u4e2a\u7528\u6237 \u53ef\u4ee5\u540c\u65f6\u6267\u884c\u64cd\u4f5c\uff0c\u5355\u4e2a\u7528\u6237\u53ef\u4ee5\u5728\u540c\u4e00\u5206\u949f\u5185\u6267\u884c \u591a\u4e2a\u64cd\u4f5c \u3002

\n\n

\u6307\u5b9a\u7528\u6237\u7684 \u7528\u6237\u6d3b\u8dc3\u5206\u949f\u6570\uff08user active minutes\uff0cUAM\uff09 \u5b9a\u4e49\u4e3a\u7528\u6237\u5bf9 LeetCode \u6267\u884c\u64cd\u4f5c\u7684 \u552f\u4e00\u5206\u949f\u6570 \u3002 \u5373\u4f7f\u4e00\u5206\u949f\u5185\u6267\u884c\u591a\u4e2a\u64cd\u4f5c\uff0c\u4e5f\u53ea\u80fd\u6309\u4e00\u5206\u949f\u8ba1\u6570\u3002

\n\n

\u8bf7\u4f60\u7edf\u8ba1\u7528\u6237\u6d3b\u8dc3\u5206\u949f\u6570\u7684\u5206\u5e03\u60c5\u51b5\uff0c\u7edf\u8ba1\u7ed3\u679c\u662f\u4e00\u4e2a\u957f\u5ea6\u4e3a k \u4e14 \u4e0b\u6807\u4ece 1 \u5f00\u59cb\u8ba1\u6570 \u7684\u6570\u7ec4 answer \uff0c\u5bf9\u4e8e\u6bcf\u4e2a j\uff081 <= j <= k\uff09\uff0canswer[j] \u8868\u793a \u7528\u6237\u6d3b\u8dc3\u5206\u949f\u6570 \u7b49\u4e8e j \u7684\u7528\u6237\u6570\u3002

\n\n

\u8fd4\u56de\u4e0a\u9762\u63cf\u8ff0\u7684\u7b54\u6848\u6570\u7ec4 answer \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1alogs = [[0,5],[1,2],[0,2],[0,5],[1,3]], k = 5\n\u8f93\u51fa\uff1a[0,2,0,0,0]\n\u89e3\u91ca\uff1a\nID=0 \u7684\u7528\u6237\u6267\u884c\u64cd\u4f5c\u7684\u5206\u949f\u5206\u522b\u662f\uff1a5 \u30012 \u548c 5 \u3002\u56e0\u6b64\uff0c\u8be5\u7528\u6237\u7684\u7528\u6237\u6d3b\u8dc3\u5206\u949f\u6570\u4e3a 2\uff08\u5206\u949f 5 \u53ea\u8ba1\u6570\u4e00\u6b21\uff09\nID=1 \u7684\u7528\u6237\u6267\u884c\u64cd\u4f5c\u7684\u5206\u949f\u5206\u522b\u662f\uff1a2 \u548c 3 \u3002\u56e0\u6b64\uff0c\u8be5\u7528\u6237\u7684\u7528\u6237\u6d3b\u8dc3\u5206\u949f\u6570\u4e3a 2\n2 \u4e2a\u7528\u6237\u7684\u7528\u6237\u6d3b\u8dc3\u5206\u949f\u6570\u90fd\u662f 2 \uff0canswer[2] \u4e3a 2 \uff0c\u5176\u4f59 answer[j] \u7684\u503c\u90fd\u662f 0\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1alogs = [[1,1],[2,2],[2,3]], k = 4\n\u8f93\u51fa\uff1a[1,1,0,0]\n\u89e3\u91ca\uff1a\nID=1 \u7684\u7528\u6237\u4ec5\u5728\u5206\u949f 1 \u6267\u884c\u5355\u4e2a\u64cd\u4f5c\u3002\u56e0\u6b64\uff0c\u8be5\u7528\u6237\u7684\u7528\u6237\u6d3b\u8dc3\u5206\u949f\u6570\u4e3a 1\nID=2 \u7684\u7528\u6237\u6267\u884c\u64cd\u4f5c\u7684\u5206\u949f\u5206\u522b\u662f\uff1a2 \u548c 3 \u3002\u56e0\u6b64\uff0c\u8be5\u7528\u6237\u7684\u7528\u6237\u6d3b\u8dc3\u5206\u949f\u6570\u4e3a 2\n1 \u4e2a\u7528\u6237\u7684\u7528\u6237\u6d3b\u8dc3\u5206\u949f\u6570\u662f 1 \uff0c1 \u4e2a\u7528\u6237\u7684\u7528\u6237\u6d3b\u8dc3\u5206\u949f\u6570\u662f 2 \n\u56e0\u6b64\uff0canswer[1] = 1 \uff0canswer[2] = 1 \uff0c\u5176\u4f59\u7684\u503c\u90fd\u662f 0\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= logs.length <= 104
  • \n\t
  • 0 <= IDi <= 109
  • \n\t
  • 1 <= timei <= 105
  • \n\t
  • k \u7684\u53d6\u503c\u8303\u56f4\u662f [\u7528\u6237\u7684\u6700\u5927\u7528\u6237\u6d3b\u8dc3\u5206\u949f\u6570, 105]
  • \n
\n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findingUsersActiveMinutes(vector>& logs, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] findingUsersActiveMinutes(int[][] logs, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findingUsersActiveMinutes(self, logs, k):\n \"\"\"\n :type logs: List[List[int]]\n :type k: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findingUsersActiveMinutes(self, logs: List[List[int]], k: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* findingUsersActiveMinutes(int** logs, int logsSize, int* logsColSize, int k, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] FindingUsersActiveMinutes(int[][] logs, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} logs\n * @param {number} k\n * @return {number[]}\n */\nvar findingUsersActiveMinutes = function(logs, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} logs\n# @param {Integer} k\n# @return {Integer[]}\ndef finding_users_active_minutes(logs, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findingUsersActiveMinutes(_ logs: [[Int]], _ k: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findingUsersActiveMinutes(logs [][]int, k int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findingUsersActiveMinutes(logs: Array[Array[Int]], k: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findingUsersActiveMinutes(logs: Array, k: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn finding_users_active_minutes(logs: Vec>, k: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $logs\n * @param Integer $k\n * @return Integer[]\n */\n function findingUsersActiveMinutes($logs, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findingUsersActiveMinutes(logs: number[][], k: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (finding-users-active-minutes logs k)\n (-> (listof (listof exact-integer?)) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1817](https://leetcode-cn.com/problems/finding-the-users-active-minutes)", "[\u67e5\u627e\u7528\u6237\u6d3b\u8dc3\u5206\u949f\u6570](/solution/1800-1899/1817.Finding%20the%20Users%20Active%20Minutes/README.md)", "`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1817](https://leetcode.com/problems/finding-the-users-active-minutes)", "[Finding the Users Active Minutes](/solution/1800-1899/1817.Finding%20the%20Users%20Active%20Minutes/README_EN.md)", "`Hash Table`", "Medium", ""]}, {"question_id": "1944", "frontend_question_id": "1816", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/truncate-sentence", "url_en": "https://leetcode.com/problems/truncate-sentence", "relative_path_cn": "/solution/1800-1899/1816.Truncate%20Sentence/README.md", "relative_path_en": "/solution/1800-1899/1816.Truncate%20Sentence/README_EN.md", "title_cn": "\u622a\u65ad\u53e5\u5b50", "title_en": "Truncate Sentence", "question_title_slug": "truncate-sentence", "content_en": "

A sentence is a list of words that are separated by a single space with no leading or trailing spaces. Each of the words consists of only uppercase and lowercase English letters (no punctuation).

\n\n
    \n\t
  • For example, "Hello World", "HELLO", and "hello world hello world" are all sentences.
  • \n
\n\n

You are given a sentence s\u200b\u200b\u200b\u200b\u200b\u200b and an integer k\u200b\u200b\u200b\u200b\u200b\u200b. You want to truncate s\u200b\u200b\u200b\u200b\u200b\u200b such that it contains only the first k\u200b\u200b\u200b\u200b\u200b\u200b words. Return s\u200b\u200b\u200b\u200b\u200b\u200b after truncating it.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "Hello how are you Contestant", k = 4\nOutput: "Hello how are you"\nExplanation:\nThe words in s are ["Hello", "how" "are", "you", "Contestant"].\nThe first 4 words are ["Hello", "how", "are", "you"].\nHence, you should return "Hello how are you".\n
\n\n

Example 2:

\n\n
\nInput: s = "What is the solution to this problem", k = 4\nOutput: "What is the solution"\nExplanation:\nThe words in s are ["What", "is" "the", "solution", "to", "this", "problem"].\nThe first 4 words are ["What", "is", "the", "solution"].\nHence, you should return "What is the solution".
\n\n

Example 3:

\n\n
\nInput: s = "chopper is not a tanuki", k = 5\nOutput: "chopper is not a tanuki"\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 500
  • \n\t
  • k is in the range [1, the number of words in s].
  • \n\t
  • s consist of only lowercase and uppercase English letters and spaces.
  • \n\t
  • The words in s are separated by a single space.
  • \n\t
  • There are no leading or trailing spaces.
  • \n
\n", "content_cn": "

\u53e5\u5b50 \u662f\u4e00\u4e2a\u5355\u8bcd\u5217\u8868\uff0c\u5217\u8868\u4e2d\u7684\u5355\u8bcd\u4e4b\u95f4\u7528\u5355\u4e2a\u7a7a\u683c\u9694\u5f00\uff0c\u4e14\u4e0d\u5b58\u5728\u524d\u5bfc\u6216\u5c3e\u968f\u7a7a\u683c\u3002\u6bcf\u4e2a\u5355\u8bcd\u4ec5\u7531\u5927\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\uff08\u4e0d\u542b\u6807\u70b9\u7b26\u53f7\uff09\u3002

\n\n
    \n\t
  • \u4f8b\u5982\uff0c\"Hello World\"\u3001\"HELLO\" \u548c \"hello world hello world\" \u90fd\u662f\u53e5\u5b50\u3002
  • \n
\n\n

\u7ed9\u4f60\u4e00\u4e2a\u53e5\u5b50 s\u200b\u200b\u200b\u200b\u200b\u200b \u548c\u4e00\u4e2a\u6574\u6570 k\u200b\u200b\u200b\u200b\u200b\u200b \uff0c\u8bf7\u4f60\u5c06 s\u200b\u200b \u622a\u65ad \u200b\uff0c\u200b\u200b\u200b\u4f7f\u622a\u65ad\u540e\u7684\u53e5\u5b50\u4ec5\u542b \u524d k\u200b\u200b\u200b\u200b\u200b\u200b \u4e2a\u5355\u8bcd\u3002\u8fd4\u56de \u622a\u65ad s\u200b\u200b\u200b\u200b\u200b\u200b \u540e\u5f97\u5230\u7684\u53e5\u5b50\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1as = \"Hello how are you Contestant\", k = 4\n\u8f93\u51fa\uff1a\"Hello how are you\"\n\u89e3\u91ca\uff1a\ns \u4e2d\u7684\u5355\u8bcd\u4e3a [\"Hello\", \"how\" \"are\", \"you\", \"Contestant\"]\n\u524d 4 \u4e2a\u5355\u8bcd\u4e3a [\"Hello\", \"how\", \"are\", \"you\"]\n\u56e0\u6b64\uff0c\u5e94\u5f53\u8fd4\u56de \"Hello how are you\"\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1as = \"What is the solution to this problem\", k = 4\n\u8f93\u51fa\uff1a\"What is the solution\"\n\u89e3\u91ca\uff1a\ns \u4e2d\u7684\u5355\u8bcd\u4e3a [\"What\", \"is\" \"the\", \"solution\", \"to\", \"this\", \"problem\"]\n\u524d 4 \u4e2a\u5355\u8bcd\u4e3a [\"What\", \"is\", \"the\", \"solution\"]\n\u56e0\u6b64\uff0c\u5e94\u5f53\u8fd4\u56de \"What is the solution\"
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1as = \"chopper is not a tanuki\", k = 5\n\u8f93\u51fa\uff1a\"chopper is not a tanuki\"\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length <= 500
  • \n\t
  • k \u7684\u53d6\u503c\u8303\u56f4\u662f [1,\u00a0 s \u4e2d\u5355\u8bcd\u7684\u6570\u76ee]
  • \n\t
  • s \u4ec5\u7531\u5927\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u548c\u7a7a\u683c\u7ec4\u6210
  • \n\t
  • s \u4e2d\u7684\u5355\u8bcd\u4e4b\u95f4\u7531\u5355\u4e2a\u7a7a\u683c\u9694\u5f00
  • \n\t
  • \u4e0d\u5b58\u5728\u524d\u5bfc\u6216\u5c3e\u968f\u7a7a\u683c
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string truncateSentence(string s, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String truncateSentence(String s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def truncateSentence(self, s, k):\n \"\"\"\n :type s: str\n :type k: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def truncateSentence(self, s: str, k: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * truncateSentence(char * s, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string TruncateSentence(string s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number} k\n * @return {string}\n */\nvar truncateSentence = function(s, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer} k\n# @return {String}\ndef truncate_sentence(s, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func truncateSentence(_ s: String, _ k: Int) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func truncateSentence(s string, k int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def truncateSentence(s: String, k: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun truncateSentence(s: String, k: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn truncate_sentence(s: String, k: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer $k\n * @return String\n */\n function truncateSentence($s, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function truncateSentence(s: string, k: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (truncate-sentence s k)\n (-> string? exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1816](https://leetcode-cn.com/problems/truncate-sentence)", "[\u622a\u65ad\u53e5\u5b50](/solution/1800-1899/1816.Truncate%20Sentence/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1816](https://leetcode.com/problems/truncate-sentence)", "[Truncate Sentence](/solution/1800-1899/1816.Truncate%20Sentence/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1943", "frontend_question_id": "1794", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/count-pairs-of-equal-substrings-with-minimum-difference", "url_en": "https://leetcode.com/problems/count-pairs-of-equal-substrings-with-minimum-difference", "relative_path_cn": "/solution/1700-1799/1794.Count%20Pairs%20of%20Equal%20Substrings%20With%20Minimum%20Difference/README.md", "relative_path_en": "/solution/1700-1799/1794.Count%20Pairs%20of%20Equal%20Substrings%20With%20Minimum%20Difference/README_EN.md", "title_cn": "\u7edf\u8ba1\u8ddd\u79bb\u6700\u5c0f\u7684\u5b50\u4e32\u5bf9\u4e2a\u6570", "title_en": "Count Pairs of Equal Substrings With Minimum Difference", "question_title_slug": "count-pairs-of-equal-substrings-with-minimum-difference", "content_en": "

You are given two strings firstString and secondString that are 0-indexed and consist only of lowercase English letters. Count the number of index quadruples (i,j,a,b) that satisfy the following conditions:

\r\n\r\n
    \r\n\t
  • 0 <= i <= j < firstString.length
  • \r\n\t
  • 0 <= a <= b < secondString.length
  • \r\n\t
  • The substring of firstString that starts at the ith character and ends at the jth character (inclusive) is equal to the substring of secondString that starts at the ath character and ends at the bth character (inclusive).
  • \r\n\t
  • j - a is the minimum possible value among all quadruples that satisfy the previous conditions.
  • \r\n
\r\n\r\n

Return the number of such quadruples.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: firstString = "abcd", secondString = "bccda"\r\nOutput: 1\r\nExplanation: The quadruple (0,0,4,4) is the only one that satisfies all the conditions and minimizes j - a.\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: firstString = "ab", secondString = "cd"\r\nOutput: 0\r\nExplanation: There are no quadruples satisfying all the conditions.\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= firstString.length, secondString.length <= 2 * 105
  • \r\n\t
  • Both strings consist only of lowercase English letters.
  • \r\n
", "content_cn": "

\u8f93\u5165\u6570\u636e\u4e3a\u4e24\u4e2a\u5b57\u7b26\u4e32firstString \u548c secondString\uff0c\u4e24\u4e2a\u5b57\u7b26\u4e32\u4e0b\u6807\u5747\u4ece0\u5f00\u59cb\uff0c\u4e14\u5747\u53ea\u5305\u542b\u5c0f\u5199\u7684\u82f1\u6587\u5b57\u7b26\uff0c\u8bf7\u8ba1\u7b97\u6ee1\u8db3\u4e0b\u5217\u8981\u6c42\u7684\u4e0b\u6807\u56db\u5143\u7ec4(i,j,a,b)\u7684\u4e2a\u6570\uff1a

\n\n
    \n\t
  • 0 <= i <= j < firstString.length
  • \n\t
  • 0 <= a <= b < secondString.length
  • \n\t
  • firstString\u5b57\u7b26\u4e32\u4e2d\u4ecei\u4f4d\u7f6e\u5230j\u4f4d\u7f6e\u7684\u5b50\u4e32(\u5305\u62ecj\u4f4d\u7f6e\u7684\u5b57\u7b26)\u548csecondString\u5b57\u7b26\u4e32\u4ecea\u4f4d\u7f6e\u5230b\u4f4d\u7f6e\u7684\u5b50\u4e32(\u5305\u62ecb\u4f4d\u7f6e\u5b57\u7b26)\u76f8\u7b49
  • \n\t
  • j-a\u7684\u6570\u503c\u662f\u6240\u6709\u7b26\u5408\u524d\u9762\u4e09\u4e2a\u6761\u4ef6\u7684\u56db\u5143\u7ec4\u4e2d\u53ef\u80fd\u7684\u6700\u5c0f\u503c
  • \n
\n\n

\u8fd4\u56de\u7b26\u5408\u4e0a\u8ff0 4 \u4e2a\u6761\u4ef6\u7684\u56db\u5143\u7ec4\u7684 \u4e2a\u6570 \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b1\uff1a

\n\n
\n\u8f93\u5165\uff1afirstString = \"abcd\", secondString = \"bccda\"\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a(0,0,4,4)\u662f\u552f\u4e00\u7b26\u5408\u6761\u4ef6\u7684\u56db\u5143\u7ec4\u4e14\u5176j-a\u7684\u6570\u503c\u662f\u6700\u5c0f\u7684.\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1afirstString = \"ab\", secondString = \"cd\"\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6ca1\u6709\u4efb\u4f55\u4e00\u4e2a\u56db\u5143\u7ec4\u80fd\u6ee1\u8db3\u4e0a\u8ff04\u4e2a\u8981\u6c42.\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= firstString.length, secondString.length <= 2 * 105
  • \n\t
  • \u4e24\u4e2a\u8f93\u5165\u5b57\u7b26\u4e32\u5747\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u7b26.
  • \n
\n", "tags_en": ["Greedy", "String"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countQuadruples(string firstString, string secondString) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countQuadruples(String firstString, String secondString) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countQuadruples(self, firstString, secondString):\n \"\"\"\n :type firstString: str\n :type secondString: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countQuadruples(self, firstString: str, secondString: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countQuadruples(char * firstString, char * secondString){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountQuadruples(string firstString, string secondString) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} firstString\n * @param {string} secondString\n * @return {number}\n */\nvar countQuadruples = function(firstString, secondString) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} first_string\n# @param {String} second_string\n# @return {Integer}\ndef count_quadruples(first_string, second_string)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countQuadruples(_ firstString: String, _ secondString: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countQuadruples(firstString string, secondString string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countQuadruples(firstString: String, secondString: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countQuadruples(firstString: String, secondString: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_quadruples(first_string: String, second_string: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $firstString\n * @param String $secondString\n * @return Integer\n */\n function countQuadruples($firstString, $secondString) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countQuadruples(firstString: string, secondString: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-quadruples firstString secondString)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1794](https://leetcode-cn.com/problems/count-pairs-of-equal-substrings-with-minimum-difference)", "[\u7edf\u8ba1\u8ddd\u79bb\u6700\u5c0f\u7684\u5b50\u4e32\u5bf9\u4e2a\u6570](/solution/1700-1799/1794.Count%20Pairs%20of%20Equal%20Substrings%20With%20Minimum%20Difference/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1794](https://leetcode.com/problems/count-pairs-of-equal-substrings-with-minimum-difference)", "[Count Pairs of Equal Substrings With Minimum Difference](/solution/1700-1799/1794.Count%20Pairs%20of%20Equal%20Substrings%20With%20Minimum%20Difference/README_EN.md)", "`Greedy`,`String`", "Medium", "\ud83d\udd12"]}, {"question_id": "1942", "frontend_question_id": "1789", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/primary-department-for-each-employee", "url_en": "https://leetcode.com/problems/primary-department-for-each-employee", "relative_path_cn": "/solution/1700-1799/1789.Primary%20Department%20for%20Each%20Employee/README.md", "relative_path_en": "/solution/1700-1799/1789.Primary%20Department%20for%20Each%20Employee/README_EN.md", "title_cn": "\u5458\u5de5\u7684\u76f4\u5c5e\u90e8\u95e8", "title_en": "Primary Department for Each Employee", "question_title_slug": "primary-department-for-each-employee", "content_en": "

Table: Employee

\n\n
\n+---------------+---------+\n| Column Name   |  Type   |\n+---------------+---------+\n| employee_id   | int     |\n| department_id | int     |\n| primary_flag  | varchar |\n+---------------+---------+\n(employee_id, department_id) is the primary key for this table.\nemployee_id is the id of the employee.\ndepartment_id is the id of the department to which the employee belongs.\nprimary_flag is an ENUM of type ('Y', 'N'). If the flag is 'Y', the department is the primary department for the employee. If the flag is 'N', the department is not the primary.\n
\n\n

 

\n\n

Employees can belong to multiple departments. When the employee joins other departments, they need to decide which department is their primary department. Note that when an employee belongs to only one department, their primary column is 'N'.

\n\n

Write an SQL query to report all the employees with their primary department. For employees who belong to one department, report their only department.

\n\n

Return the result table in any order.

\n\n

The query result format is in the following example.

\n\n

 

\n\n
\nEmployee table:\n+-------------+---------------+--------------+\n| employee_id | department_id | primary_flag |\n+-------------+---------------+--------------+\n| 1           | 1             | N            |\n| 2           | 1             | Y            |\n| 2           | 2             | N            |\n| 3           | 3             | N            |\n| 4           | 2             | N            |\n| 4           | 3             | Y            |\n| 4           | 4             | N            |\n+-------------+---------------+--------------+\n\nResult table:\n+-------------+---------------+\n| employee_id | department_id |\n+-------------+---------------+\n| 1           | 1             |\n| 2           | 1             |\n| 3           | 3             |\n| 4           | 3             |\n+-------------+---------------+\n- The Primary department for employee 1 is 1.\n- The Primary department for employee 2 is 1.\n- The Primary department for employee 3 is 3.\n- The Primary department for employee 4 is 3.
\n\n

 

\n", "content_cn": "

Table: Employee

\n\n
+---------------+---------+\n| Column Name   |  Type   |\n+---------------+---------+\n| employee_id   | int     |\n| department_id | int     |\n| primary_flag  | varchar |\n+---------------+---------+\n\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\u4e3a employee_id, department_id\nemployee_id \u662f\u5458\u5de5\u7684ID\ndepartment_id \u662f\u90e8\u95e8\u7684ID\uff0c\u8868\u793a\u5458\u5de5\u4e0e\u8be5\u90e8\u95e8\u6709\u5173\u7cfb\nprimary_flag \u662f\u4e00\u4e2a\u679a\u4e3e\u7c7b\u578b\uff0c\u503c\u5206\u522b\u4e3a('Y', 'N'). \u5982\u679c\u503c\u4e3a'Y',\u8868\u793a\u8be5\u90e8\u95e8\u662f\u5458\u5de5\u7684\u76f4\u5c5e\u90e8\u95e8\u3002 \u5982\u679c\u503c\u662f'N',\u5219\u5426\n
\n\n

\u00a0

\n\n

\u4e00\u4e2a\u5458\u5de5\u53ef\u4ee5\u5c5e\u4e8e\u591a\u4e2a\u90e8\u95e8\u3002

\n\n

\u5f53\u4e00\u4e2a\u5458\u5de5\u52a0\u5165\u8d85\u8fc7\u4e00\u4e2a\u90e8\u95e8\u7684\u65f6\u5019\uff0c\u4ed6\u9700\u8981\u51b3\u5b9a\u54ea\u4e2a\u90e8\u95e8\u662f\u4ed6\u7684\u76f4\u5c5e\u90e8\u95e8\u3002

\n\n

\u8bf7\u6ce8\u610f\uff0c\u5f53\u5458\u5de5\u53ea\u52a0\u5165\u4e00\u4e2a\u90e8\u95e8\u7684\u65f6\u5019\uff0c\u90a3\u8fd9\u4e2a\u90e8\u95e8\u5c06\u9ed8\u8ba4\u4e3a\u4ed6\u7684\u76f4\u5c5e\u90e8\u95e8\uff0c\u867d\u7136\u8868\u8bb0\u5f55\u7684\u503c\u4e3a'N'.

\n\n

\u8bf7\u7f16\u5199\u4e00\u6bb5SQL\uff0c\u67e5\u51fa\u5458\u5de5\u6240\u5c5e\u7684\u76f4\u5c5e\u90e8\u95e8\u3002

\n\n

\u8fd4\u56de\u7ed3\u679c\u6ca1\u6709\u987a\u5e8f\u8981\u6c42\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b\uff1a

\n\n
Employee table:\n+-------------+---------------+--------------+\n| employee_id | department_id | primary_flag |\n+-------------+---------------+--------------+\n| 1           | 1             | N            |\n| 2           | 1             | Y            |\n| 2           | 2             | N            |\n| 3           | 3             | N            |\n| 4           | 2             | N            |\n| 4           | 3             | Y            |\n| 4           | 4             | N            |\n+-------------+---------------+--------------+\n\nResult table:\n+-------------+---------------+\n| employee_id | department_id |\n+-------------+---------------+\n| 1           | 1             |\n| 2           | 1             |\n| 3           | 3             |\n| 4           | 3             |\n+-------------+---------------+\n- \u5458\u5de51\u7684\u76f4\u5c5e\u90e8\u95e8\u662f1\n- \u5458\u5de52\u7684\u76f4\u5c5e\u90e8\u95e8\u662f1\n- \u5458\u5de53\u7684\u76f4\u5c5e\u90e8\u95e8\u662f3\n- \u5458\u5de54\u7684\u76f4\u5c5e\u90e8\u95e8\u662f3
\n\n

\u00a0

\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1789](https://leetcode-cn.com/problems/primary-department-for-each-employee)", "[\u5458\u5de5\u7684\u76f4\u5c5e\u90e8\u95e8](/solution/1700-1799/1789.Primary%20Department%20for%20Each%20Employee/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1789](https://leetcode.com/problems/primary-department-for-each-employee)", "[Primary Department for Each Employee](/solution/1700-1799/1789.Primary%20Department%20for%20Each%20Employee/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1941", "frontend_question_id": "1830", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-number-of-operations-to-make-string-sorted", "url_en": "https://leetcode.com/problems/minimum-number-of-operations-to-make-string-sorted", "relative_path_cn": "/solution/1800-1899/1830.Minimum%20Number%20of%20Operations%20to%20Make%20String%20Sorted/README.md", "relative_path_en": "/solution/1800-1899/1830.Minimum%20Number%20of%20Operations%20to%20Make%20String%20Sorted/README_EN.md", "title_cn": "\u4f7f\u5b57\u7b26\u4e32\u6709\u5e8f\u7684\u6700\u5c11\u64cd\u4f5c\u6b21\u6570", "title_en": "Minimum Number of Operations to Make String Sorted", "question_title_slug": "minimum-number-of-operations-to-make-string-sorted", "content_en": "

You are given a string s (0-indexed)\u200b\u200b\u200b\u200b\u200b\u200b. You are asked to perform the following operation on s\u200b\u200b\u200b\u200b\u200b\u200b until you get a sorted string:

\n\n
    \n\t
  1. Find the largest index i such that 1 <= i < s.length and s[i] < s[i - 1].
  2. \n\t
  3. Find the largest index j such that i <= j < s.length and s[k] < s[i - 1] for all the possible values of k in the range [i, j] inclusive.
  4. \n\t
  5. Swap the two characters at indices i - 1\u200b\u200b\u200b\u200b and j\u200b\u200b\u200b\u200b\u200b.
  6. \n\t
  7. Reverse the suffix starting at index i\u200b\u200b\u200b\u200b\u200b\u200b.
  8. \n
\n\n

Return the number of operations needed to make the string sorted. Since the answer can be too large, return it modulo 109 + 7.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "cba"\nOutput: 5\nExplanation: The simulation goes as follows:\nOperation 1: i=2, j=2. Swap s[1] and s[2] to get s="cab", then reverse the suffix starting at 2. Now, s="cab".\nOperation 2: i=1, j=2. Swap s[0] and s[2] to get s="bac", then reverse the suffix starting at 1. Now, s="bca".\nOperation 3: i=2, j=2. Swap s[1] and s[2] to get s="bac", then reverse the suffix starting at 2. Now, s="bac".\nOperation 4: i=1, j=1. Swap s[0] and s[1] to get s="abc", then reverse the suffix starting at 1. Now, s="acb".\nOperation 5: i=2, j=2. Swap s[1] and s[2] to get s="abc", then reverse the suffix starting at 2. Now, s="abc".\n
\n\n

Example 2:

\n\n
\nInput: s = "aabaa"\nOutput: 2\nExplanation: The simulation goes as follows:\nOperation 1: i=3, j=4. Swap s[2] and s[4] to get s="aaaab", then reverse the substring starting at 3. Now, s="aaaba".\nOperation 2: i=4, j=4. Swap s[3] and s[4] to get s="aaaab", then reverse the substring starting at 4. Now, s="aaaab".\n
\n\n

Example 3:

\n\n
\nInput: s = "cdbea"\nOutput: 63
\n\n

Example 4:

\n\n
\nInput: s = "leetcodeleetcodeleetcode"\nOutput: 982157772\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 3000
  • \n\t
  • s\u200b\u200b\u200b\u200b\u200b\u200b consists only of lowercase English letters.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32\u00a0s\u00a0\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\u3002\u4f60\u9700\u8981\u5bf9 s\u00a0\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\u76f4\u5230\u5b83\u53d8\u4e3a\u4e00\u4e2a\u6709\u5e8f\u5b57\u7b26\u4e32\uff1a

\n\n
    \n\t
  1. \u627e\u5230 \u6700\u5927\u4e0b\u6807\u00a0i\u00a0\uff0c\u4f7f\u5f97\u00a01 <= i < s.length \u4e14\u00a0s[i] < s[i - 1]\u00a0\u3002
  2. \n\t
  3. \u627e\u5230 \u6700\u5927\u4e0b\u6807\u00a0j\u00a0\uff0c\u4f7f\u5f97\u00a0i <= j < s.length \u4e14\u5bf9\u4e8e\u6240\u6709\u5728\u95ed\u533a\u95f4\u00a0[i, j]\u00a0\u4e4b\u95f4\u7684\u00a0k\u00a0\u90fd\u6709\u00a0s[k] < s[i - 1]\u00a0\u3002
  4. \n\t
  5. \u4ea4\u6362\u4e0b\u6807\u4e3a\u00a0i - 1\u200b\u200b\u200b\u200b \u548c\u00a0j\u200b\u200b\u200b\u200b \u5904\u7684\u4e24\u4e2a\u5b57\u7b26\u3002
  6. \n\t
  7. \u5c06\u4e0b\u6807 i\u00a0\u5f00\u59cb\u7684\u5b57\u7b26\u4e32\u540e\u7f00\u53cd\u8f6c\u3002
  8. \n
\n\n

\u8bf7\u4f60\u8fd4\u56de\u5c06\u5b57\u7b26\u4e32\u53d8\u6210\u6709\u5e8f\u7684\u6700\u5c11\u64cd\u4f5c\u6b21\u6570\u3002\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u4f1a\u5f88\u5927\uff0c\u8bf7\u8fd4\u56de\u5b83\u5bf9\u00a0109 + 7\u00a0\u53d6\u4f59\u00a0\u7684\u7ed3\u679c\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1as = \"cba\"\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u6a21\u62df\u8fc7\u7a0b\u5982\u4e0b\u6240\u793a\uff1a\n\u64cd\u4f5c 1\uff1ai=2\uff0cj=2\u3002\u4ea4\u6362 s[1] \u548c s[2] \u5f97\u5230 s=\"cab\" \uff0c\u7136\u540e\u53cd\u8f6c\u4e0b\u6807\u4ece 2 \u5f00\u59cb\u7684\u540e\u7f00\u5b57\u7b26\u4e32\uff0c\u5f97\u5230 s=\"cab\" \u3002\n\u64cd\u4f5c 2\uff1ai=1\uff0cj=2\u3002\u4ea4\u6362 s[0] \u548c s[2] \u5f97\u5230 s=\"bac\" \uff0c\u7136\u540e\u53cd\u8f6c\u4e0b\u6807\u4ece 1 \u5f00\u59cb\u7684\u540e\u7f00\u5b57\u7b26\u4e32\uff0c\u5f97\u5230 s=\"bca\" \u3002\n\u64cd\u4f5c 3\uff1ai=2\uff0cj=2\u3002\u4ea4\u6362 s[1] \u548c s[2] \u5f97\u5230 s=\"bac\" \uff0c\u7136\u540e\u53cd\u8f6c\u4e0b\u6807\u4ece 2 \u5f00\u59cb\u7684\u540e\u7f00\u5b57\u7b26\u4e32\uff0c\u5f97\u5230 s=\"bac\" \u3002\n\u64cd\u4f5c 4\uff1ai=1\uff0cj=1\u3002\u4ea4\u6362 s[0] \u548c s[1] \u5f97\u5230 s=\"abc\" \uff0c\u7136\u540e\u53cd\u8f6c\u4e0b\u6807\u4ece 1 \u5f00\u59cb\u7684\u540e\u7f00\u5b57\u7b26\u4e32\uff0c\u5f97\u5230 s=\"acb\" \u3002\n\u64cd\u4f5c 5\uff1ai=2\uff0cj=2\u3002\u4ea4\u6362 s[1] \u548c s[2] \u5f97\u5230 s=\"abc\" \uff0c\u7136\u540e\u53cd\u8f6c\u4e0b\u6807\u4ece 2 \u5f00\u59cb\u7684\u540e\u7f00\u5b57\u7b26\u4e32\uff0c\u5f97\u5230 s=\"abc\" \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1as = \"aabaa\"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6a21\u62df\u8fc7\u7a0b\u5982\u4e0b\u6240\u793a\uff1a\n\u64cd\u4f5c 1\uff1ai=3\uff0cj=4\u3002\u4ea4\u6362 s[2] \u548c s[4] \u5f97\u5230 s=\"aaaab\" \uff0c\u7136\u540e\u53cd\u8f6c\u4e0b\u6807\u4ece 3 \u5f00\u59cb\u7684\u540e\u7f00\u5b57\u7b26\u4e32\uff0c\u5f97\u5230 s=\"aaaba\" \u3002\n\u64cd\u4f5c 2\uff1ai=4\uff0cj=4\u3002\u4ea4\u6362 s[3] \u548c s[4] \u5f97\u5230 s=\"aaaab\" \uff0c\u7136\u540e\u53cd\u8f6c\u4e0b\u6807\u4ece 4 \u5f00\u59cb\u7684\u540e\u7f00\u5b57\u7b26\u4e32\uff0c\u5f97\u5230 s=\"aaaab\" \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1as = \"cdbea\"\n\u8f93\u51fa\uff1a63
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1as = \"leetcodeleetcodeleetcode\"\n\u8f93\u51fa\uff1a982157772\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length <= 3000
  • \n\t
  • s\u200b \u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
  • \n
\n", "tags_en": ["Math", "String"], "tags_cn": ["\u6570\u5b66", "\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int makeStringSorted(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int makeStringSorted(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def makeStringSorted(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def makeStringSorted(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint makeStringSorted(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MakeStringSorted(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar makeStringSorted = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef make_string_sorted(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func makeStringSorted(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func makeStringSorted(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def makeStringSorted(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun makeStringSorted(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn make_string_sorted(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function makeStringSorted($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function makeStringSorted(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (make-string-sorted s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1830](https://leetcode-cn.com/problems/minimum-number-of-operations-to-make-string-sorted)", "[\u4f7f\u5b57\u7b26\u4e32\u6709\u5e8f\u7684\u6700\u5c11\u64cd\u4f5c\u6b21\u6570](/solution/1800-1899/1830.Minimum%20Number%20of%20Operations%20to%20Make%20String%20Sorted/README.md)", "`\u6570\u5b66`,`\u5b57\u7b26\u4e32`", "\u56f0\u96be", ""], "md_table_row_en": ["[1830](https://leetcode.com/problems/minimum-number-of-operations-to-make-string-sorted)", "[Minimum Number of Operations to Make String Sorted](/solution/1800-1899/1830.Minimum%20Number%20of%20Operations%20to%20Make%20String%20Sorted/README_EN.md)", "`Math`,`String`", "Hard", ""]}, {"question_id": "1940", "frontend_question_id": "1829", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-xor-for-each-query", "url_en": "https://leetcode.com/problems/maximum-xor-for-each-query", "relative_path_cn": "/solution/1800-1899/1829.Maximum%20XOR%20for%20Each%20Query/README.md", "relative_path_en": "/solution/1800-1899/1829.Maximum%20XOR%20for%20Each%20Query/README_EN.md", "title_cn": "\u6bcf\u4e2a\u67e5\u8be2\u7684\u6700\u5927\u5f02\u6216\u503c", "title_en": "Maximum XOR for Each Query", "question_title_slug": "maximum-xor-for-each-query", "content_en": "

You are given a sorted array nums of n non-negative integers and an integer maximumBit. You want to perform the following query n times:

\n\n
    \n\t
  1. Find a non-negative integer k < 2maximumBit such that nums[0] XOR nums[1] XOR ... XOR nums[nums.length-1] XOR k is maximized. k is the answer to the ith query.
  2. \n\t
  3. Remove the last element from the current array nums.
  4. \n
\n\n

Return an array answer, where answer[i] is the answer to the ith query.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [0,1,1,3], maximumBit = 2\nOutput: [0,3,2,3]\nExplanation: The queries are answered as follows:\n1st query: nums = [0,1,1,3], k = 0 since 0 XOR 1 XOR 1 XOR 3 XOR 0 = 3.\n2nd query: nums = [0,1,1], k = 3 since 0 XOR 1 XOR 1 XOR 3 = 3.\n3rd query: nums = [0,1], k = 2 since 0 XOR 1 XOR 2 = 3.\n4th query: nums = [0], k = 3 since 0 XOR 3 = 3.\n
\n\n

Example 2:

\n\n
\nInput: nums = [2,3,4,7], maximumBit = 3\nOutput: [5,2,6,5]\nExplanation: The queries are answered as follows:\n1st query: nums = [2,3,4,7], k = 5 since 2 XOR 3 XOR 4 XOR 7 XOR 5 = 7.\n2nd query: nums = [2,3,4], k = 2 since 2 XOR 3 XOR 4 XOR 2 = 7.\n3rd query: nums = [2,3], k = 6 since 2 XOR 3 XOR 6 = 7.\n4th query: nums = [2], k = 5 since 2 XOR 5 = 7.\n
\n\n

Example 3:

\n\n
\nInput: nums = [0,1,2,2,5,7], maximumBit = 3\nOutput: [4,3,6,4,6,7]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • nums.length == n
  • \n\t
  • 1 <= n <= 105
  • \n\t
  • 1 <= maximumBit <= 20
  • \n\t
  • 0 <= nums[i] < 2maximumBit
  • \n\t
  • nums\u200b\u200b\u200b is sorted in ascending order.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a \u6709\u5e8f\u00a0\u6570\u7ec4\u00a0nums\u00a0\uff0c\u5b83\u7531\u00a0n\u00a0\u4e2a\u975e\u8d1f\u6574\u6570\u7ec4\u6210\uff0c\u540c\u65f6\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u00a0maximumBit\u00a0\u3002\u4f60\u9700\u8981\u6267\u884c\u4ee5\u4e0b\u67e5\u8be2 n\u00a0\u6b21\uff1a

\n\n
    \n\t
  1. \u627e\u5230\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\u00a0k < 2maximumBit\u00a0\uff0c\u4f7f\u5f97\u00a0nums[0] XOR nums[1] XOR ... XOR nums[nums.length-1] XOR k\u00a0\u7684\u7ed3\u679c \u6700\u5927\u5316\u00a0\u3002k\u00a0\u662f\u7b2c i\u00a0\u4e2a\u67e5\u8be2\u7684\u7b54\u6848\u3002
  2. \n\t
  3. \u4ece\u5f53\u524d\u6570\u7ec4\u00a0nums\u00a0\u5220\u9664\u00a0\u6700\u540e\u00a0\u4e00\u4e2a\u5143\u7d20\u3002
  4. \n
\n\n

\u8bf7\u4f60\u8fd4\u56de\u4e00\u4e2a\u6570\u7ec4\u00a0answer\u00a0\uff0c\u5176\u4e2d\u00a0answer[i]\u662f\u7b2c\u00a0i\u00a0\u4e2a\u67e5\u8be2\u7684\u7ed3\u679c\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [0,1,1,3], maximumBit = 2\n\u8f93\u51fa\uff1a[0,3,2,3]\n\u89e3\u91ca\uff1a\u67e5\u8be2\u7684\u7b54\u6848\u5982\u4e0b\uff1a\n\u7b2c\u4e00\u4e2a\u67e5\u8be2\uff1anums = [0,1,1,3]\uff0ck = 0\uff0c\u56e0\u4e3a 0 XOR 1 XOR 1 XOR 3 XOR 0 = 3 \u3002\n\u7b2c\u4e8c\u4e2a\u67e5\u8be2\uff1anums = [0,1,1]\uff0ck = 3\uff0c\u56e0\u4e3a 0 XOR 1 XOR 1 XOR 3 = 3 \u3002\n\u7b2c\u4e09\u4e2a\u67e5\u8be2\uff1anums = [0,1]\uff0ck = 2\uff0c\u56e0\u4e3a 0 XOR 1 XOR 2 = 3 \u3002\n\u7b2c\u56db\u4e2a\u67e5\u8be2\uff1anums = [0]\uff0ck = 3\uff0c\u56e0\u4e3a 0 XOR 3 = 3 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [2,3,4,7], maximumBit = 3\n\u8f93\u51fa\uff1a[5,2,6,5]\n\u89e3\u91ca\uff1a\u67e5\u8be2\u7684\u7b54\u6848\u5982\u4e0b\uff1a\n\u7b2c\u4e00\u4e2a\u67e5\u8be2\uff1anums = [2,3,4,7]\uff0ck = 5\uff0c\u56e0\u4e3a 2 XOR 3 XOR 4 XOR 7 XOR 5 = 7\u3002\n\u7b2c\u4e8c\u4e2a\u67e5\u8be2\uff1anums = [2,3,4]\uff0ck = 2\uff0c\u56e0\u4e3a 2 XOR 3 XOR 4 XOR 2 = 7 \u3002\n\u7b2c\u4e09\u4e2a\u67e5\u8be2\uff1anums = [2,3]\uff0ck = 6\uff0c\u56e0\u4e3a 2 XOR 3 XOR 6 = 7 \u3002\n\u7b2c\u56db\u4e2a\u67e5\u8be2\uff1anums = [2]\uff0ck = 5\uff0c\u56e0\u4e3a 2 XOR 5 = 7 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [0,1,2,2,5,7], maximumBit = 3\n\u8f93\u51fa\uff1a[4,3,6,4,6,7]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • nums.length == n
  • \n\t
  • 1 <= n <= 105
  • \n\t
  • 1 <= maximumBit <= 20
  • \n\t
  • 0 <= nums[i] < 2maximumBit
  • \n\t
  • nums\u200b\u200b\u200b \u4e2d\u7684\u6570\u5b57\u5df2\u7ecf\u6309\u00a0\u5347\u5e8f\u00a0\u6392\u597d\u5e8f\u3002
  • \n
\n", "tags_en": ["Bit Manipulation"], "tags_cn": ["\u4f4d\u8fd0\u7b97"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector getMaximumXor(vector& nums, int maximumBit) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] getMaximumXor(int[] nums, int maximumBit) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getMaximumXor(self, nums, maximumBit):\n \"\"\"\n :type nums: List[int]\n :type maximumBit: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getMaximumXor(self, nums: List[int], maximumBit: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* getMaximumXor(int* nums, int numsSize, int maximumBit, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] GetMaximumXor(int[] nums, int maximumBit) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} maximumBit\n * @return {number[]}\n */\nvar getMaximumXor = function(nums, maximumBit) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} maximum_bit\n# @return {Integer[]}\ndef get_maximum_xor(nums, maximum_bit)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getMaximumXor(_ nums: [Int], _ maximumBit: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getMaximumXor(nums []int, maximumBit int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getMaximumXor(nums: Array[Int], maximumBit: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getMaximumXor(nums: IntArray, maximumBit: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_maximum_xor(nums: Vec, maximum_bit: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $maximumBit\n * @return Integer[]\n */\n function getMaximumXor($nums, $maximumBit) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getMaximumXor(nums: number[], maximumBit: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-maximum-xor nums maximumBit)\n (-> (listof exact-integer?) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1829](https://leetcode-cn.com/problems/maximum-xor-for-each-query)", "[\u6bcf\u4e2a\u67e5\u8be2\u7684\u6700\u5927\u5f02\u6216\u503c](/solution/1800-1899/1829.Maximum%20XOR%20for%20Each%20Query/README.md)", "`\u4f4d\u8fd0\u7b97`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1829](https://leetcode.com/problems/maximum-xor-for-each-query)", "[Maximum XOR for Each Query](/solution/1800-1899/1829.Maximum%20XOR%20for%20Each%20Query/README_EN.md)", "`Bit Manipulation`", "Medium", ""]}, {"question_id": "1939", "frontend_question_id": "1828", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/queries-on-number-of-points-inside-a-circle", "url_en": "https://leetcode.com/problems/queries-on-number-of-points-inside-a-circle", "relative_path_cn": "/solution/1800-1899/1828.Queries%20on%20Number%20of%20Points%20Inside%20a%20Circle/README.md", "relative_path_en": "/solution/1800-1899/1828.Queries%20on%20Number%20of%20Points%20Inside%20a%20Circle/README_EN.md", "title_cn": "\u7edf\u8ba1\u4e00\u4e2a\u5706\u4e2d\u70b9\u7684\u6570\u76ee", "title_en": "Queries on Number of Points Inside a Circle", "question_title_slug": "queries-on-number-of-points-inside-a-circle", "content_en": "

You are given an array points where points[i] = [xi, yi] is the coordinates of the ith point on a 2D plane. Multiple points can have the same coordinates.

\n\n

You are also given an array queries where queries[j] = [xj, yj, rj] describes a circle centered at (xj, yj) with a radius of rj.

\n\n

For each query queries[j], compute the number of points inside the jth circle. Points on the border of the circle are considered inside.

\n\n

Return an array answer, where answer[j] is the answer to the jth query.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: points = [[1,3],[3,3],[5,3],[2,2]], queries = [[2,3,1],[4,3,1],[1,1,2]]\nOutput: [3,2,2]\nExplanation: The points and circles are shown above.\nqueries[0] is the green circle, queries[1] is the red circle, and queries[2] is the blue circle.\n
\n\n

Example 2:

\n\"\"\n
\nInput: points = [[1,1],[2,2],[3,3],[4,4],[5,5]], queries = [[1,2,2],[2,2,2],[4,3,2],[4,3,3]]\nOutput: [2,3,2,4]\nExplanation: The points and circles are shown above.\nqueries[0] is green, queries[1] is red, queries[2] is blue, and queries[3] is purple.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= points.length <= 500
  • \n\t
  • points[i].length == 2
  • \n\t
  • 0 <= x\u200b\u200b\u200b\u200b\u200b\u200bi, y\u200b\u200b\u200b\u200b\u200b\u200bi <= 500
  • \n\t
  • 1 <= queries.length <= 500
  • \n\t
  • queries[j].length == 3
  • \n\t
  • 0 <= xj, yj <= 500
  • \n\t
  • 1 <= rj <= 500
  • \n\t
  • All coordinates are integers.
  • \n
\n\n

 

\n

Follow up: Could you find the answer for each query in better complexity than O(n)?

\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4\u00a0points\u00a0\uff0c\u5176\u4e2d\u00a0points[i] = [xi, yi]\u00a0\uff0c\u8868\u793a\u7b2c\u00a0i\u00a0\u4e2a\u70b9\u5728\u4e8c\u7ef4\u5e73\u9762\u4e0a\u7684\u5750\u6807\u3002\u591a\u4e2a\u70b9\u53ef\u80fd\u4f1a\u6709 \u76f8\u540c\u00a0\u7684\u5750\u6807\u3002

\n\n

\u540c\u65f6\u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4\u00a0queries\u00a0\uff0c\u5176\u4e2d\u00a0queries[j] = [xj, yj, rj]\u00a0\uff0c\u8868\u793a\u4e00\u4e2a\u5706\u5fc3\u5728\u00a0(xj, yj)\u00a0\u4e14\u534a\u5f84\u4e3a\u00a0rj\u00a0\u7684\u5706\u3002

\n\n

\u5bf9\u4e8e\u6bcf\u4e00\u4e2a\u67e5\u8be2\u00a0queries[j]\u00a0\uff0c\u8ba1\u7b97\u5728\u7b2c j\u00a0\u4e2a\u5706 \u5185\u00a0\u70b9\u7684\u6570\u76ee\u3002\u5982\u679c\u4e00\u4e2a\u70b9\u5728\u5706\u7684 \u8fb9\u754c\u4e0a\u00a0\uff0c\u6211\u4eec\u540c\u6837\u8ba4\u4e3a\u5b83\u5728\u5706\u00a0\u5185\u00a0\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u4e00\u4e2a\u6570\u7ec4\u00a0answer\u00a0\uff0c\u5176\u4e2d\u00a0answer[j]\u662f\u7b2c\u00a0j\u00a0\u4e2a\u67e5\u8be2\u7684\u7b54\u6848\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\"\"\n
\u8f93\u5165\uff1apoints = [[1,3],[3,3],[5,3],[2,2]], queries = [[2,3,1],[4,3,1],[1,1,2]]\n\u8f93\u51fa\uff1a[3,2,2]\n\u89e3\u91ca\uff1a\u6240\u6709\u7684\u70b9\u548c\u5706\u5982\u4e0a\u56fe\u6240\u793a\u3002\nqueries[0] \u662f\u7eff\u8272\u7684\u5706\uff0cqueries[1] \u662f\u7ea2\u8272\u7684\u5706\uff0cqueries[2] \u662f\u84dd\u8272\u7684\u5706\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\"\"\n
\u8f93\u5165\uff1apoints = [[1,1],[2,2],[3,3],[4,4],[5,5]], queries = [[1,2,2],[2,2,2],[4,3,2],[4,3,3]]\n\u8f93\u51fa\uff1a[2,3,2,4]\n\u89e3\u91ca\uff1a\u6240\u6709\u7684\u70b9\u548c\u5706\u5982\u4e0a\u56fe\u6240\u793a\u3002\nqueries[0] \u662f\u7eff\u8272\u7684\u5706\uff0cqueries[1] \u662f\u7ea2\u8272\u7684\u5706\uff0cqueries[2] \u662f\u84dd\u8272\u7684\u5706\uff0cqueries[3] \u662f\u7d2b\u8272\u7684\u5706\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= points.length <= 500
  • \n\t
  • points[i].length == 2
  • \n\t
  • 0 <= x\u200b\u200b\u200b\u200b\u200b\u200bi, y\u200b\u200b\u200b\u200b\u200b\u200bi <= 500
  • \n\t
  • 1 <= queries.length <= 500
  • \n\t
  • queries[j].length == 3
  • \n\t
  • 0 <= xj, yj <= 500
  • \n\t
  • 1 <= rj <= 500
  • \n\t
  • \u6240\u6709\u7684\u5750\u6807\u90fd\u662f\u6574\u6570\u3002
  • \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector countPoints(vector>& points, vector>& queries) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] countPoints(int[][] points, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countPoints(self, points, queries):\n \"\"\"\n :type points: List[List[int]]\n :type queries: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countPoints(self, points: List[List[int]], queries: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* countPoints(int** points, int pointsSize, int* pointsColSize, int** queries, int queriesSize, int* queriesColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] CountPoints(int[][] points, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} points\n * @param {number[][]} queries\n * @return {number[]}\n */\nvar countPoints = function(points, queries) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} points\n# @param {Integer[][]} queries\n# @return {Integer[]}\ndef count_points(points, queries)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countPoints(_ points: [[Int]], _ queries: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countPoints(points [][]int, queries [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countPoints(points: Array[Array[Int]], queries: Array[Array[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countPoints(points: Array, queries: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_points(points: Vec>, queries: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $points\n * @param Integer[][] $queries\n * @return Integer[]\n */\n function countPoints($points, $queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countPoints(points: number[][], queries: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-points points queries)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1828](https://leetcode-cn.com/problems/queries-on-number-of-points-inside-a-circle)", "[\u7edf\u8ba1\u4e00\u4e2a\u5706\u4e2d\u70b9\u7684\u6570\u76ee](/solution/1800-1899/1828.Queries%20on%20Number%20of%20Points%20Inside%20a%20Circle/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1828](https://leetcode.com/problems/queries-on-number-of-points-inside-a-circle)", "[Queries on Number of Points Inside a Circle](/solution/1800-1899/1828.Queries%20on%20Number%20of%20Points%20Inside%20a%20Circle/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "1938", "frontend_question_id": "1827", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-operations-to-make-the-array-increasing", "url_en": "https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing", "relative_path_cn": "/solution/1800-1899/1827.Minimum%20Operations%20to%20Make%20the%20Array%20Increasing/README.md", "relative_path_en": "/solution/1800-1899/1827.Minimum%20Operations%20to%20Make%20the%20Array%20Increasing/README_EN.md", "title_cn": "\u6700\u5c11\u64cd\u4f5c\u4f7f\u6570\u7ec4\u9012\u589e", "title_en": "Minimum Operations to Make the Array Increasing", "question_title_slug": "minimum-operations-to-make-the-array-increasing", "content_en": "

You are given an integer array nums (0-indexed). In one operation, you can choose an element of the array and increment it by 1.

\r\n\r\n
    \r\n\t
  • For example, if nums = [1,2,3], you can choose to increment nums[1] to make nums = [1,3,3].
  • \r\n
\r\n\r\n

Return the minimum number of operations needed to make nums strictly increasing.

\r\n\r\n

An array nums is strictly increasing if nums[i] < nums[i+1] for all 0 <= i < nums.length - 1. An array of length 1 is trivially strictly increasing.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: nums = [1,1,1]\r\nOutput: 3\r\nExplanation: You can do the following operations:\r\n1) Increment nums[2], so nums becomes [1,1,2].\r\n2) Increment nums[1], so nums becomes [1,2,2].\r\n3) Increment nums[2], so nums becomes [1,2,3].\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: nums = [1,5,2,4,1]\r\nOutput: 14\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: nums = [8]\r\nOutput: 0\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= nums.length <= 5000
  • \r\n\t
  • 1 <= nums[i] <= 104
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0nums\u00a0\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\u3002\u6bcf\u4e00\u6b21\u64cd\u4f5c\u4e2d\uff0c\u4f60\u53ef\u4ee5\u9009\u62e9\u6570\u7ec4\u4e2d\u4e00\u4e2a\u5143\u7d20\uff0c\u5e76\u5c06\u5b83\u589e\u52a0\u00a01\u00a0\u3002

\n\n
    \n\t
  • \u6bd4\u65b9\u8bf4\uff0c\u5982\u679c\u00a0nums = [1,2,3]\u00a0\uff0c\u4f60\u53ef\u4ee5\u9009\u62e9\u589e\u52a0\u00a0nums[1]\u00a0\u5f97\u5230\u00a0nums = [1,3,3]\u00a0\u3002
  • \n
\n\n

\u8bf7\u4f60\u8fd4\u56de\u4f7f nums\u00a0\u4e25\u683c\u9012\u589e\u00a0\u7684 \u6700\u5c11\u00a0\u64cd\u4f5c\u6b21\u6570\u3002

\n\n

\u6211\u4eec\u79f0\u6570\u7ec4\u00a0nums\u00a0\u662f \u4e25\u683c\u9012\u589e\u7684\u00a0\uff0c\u5f53\u5b83\u6ee1\u8db3\u5bf9\u4e8e\u6240\u6709\u7684\u00a00 <= i < nums.length - 1\u00a0\u90fd\u6709\u00a0nums[i] < nums[i+1]\u00a0\u3002\u4e00\u4e2a\u957f\u5ea6\u4e3a 1\u00a0\u7684\u6570\u7ec4\u662f\u4e25\u683c\u9012\u589e\u7684\u4e00\u79cd\u7279\u6b8a\u60c5\u51b5\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,1,1]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u8fdb\u884c\u5982\u4e0b\u64cd\u4f5c\uff1a\n1) \u589e\u52a0 nums[2] \uff0c\u6570\u7ec4\u53d8\u4e3a [1,1,2] \u3002\n2) \u589e\u52a0 nums[1] \uff0c\u6570\u7ec4\u53d8\u4e3a [1,2,2] \u3002\n3) \u589e\u52a0 nums[2] \uff0c\u6570\u7ec4\u53d8\u4e3a [1,2,3] \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,5,2,4,1]\n\u8f93\u51fa\uff1a14\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1anums = [8]\n\u8f93\u51fa\uff1a0\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 5000
  • \n\t
  • 1 <= nums[i] <= 104
  • \n
\n", "tags_en": ["Greedy", "Array"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minOperations(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minOperations(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minOperations(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minOperations(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minOperations(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinOperations(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar minOperations = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef min_operations(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minOperations(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minOperations(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minOperations(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minOperations(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_operations(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function minOperations($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minOperations(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-operations nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1827](https://leetcode-cn.com/problems/minimum-operations-to-make-the-array-increasing)", "[\u6700\u5c11\u64cd\u4f5c\u4f7f\u6570\u7ec4\u9012\u589e](/solution/1800-1899/1827.Minimum%20Operations%20to%20Make%20the%20Array%20Increasing/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1827](https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing)", "[Minimum Operations to Make the Array Increasing](/solution/1800-1899/1827.Minimum%20Operations%20to%20Make%20the%20Array%20Increasing/README_EN.md)", "`Greedy`,`Array`", "Easy", ""]}, {"question_id": "1937", "frontend_question_id": "1788", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/maximize-the-beauty-of-the-garden", "url_en": "https://leetcode.com/problems/maximize-the-beauty-of-the-garden", "relative_path_cn": "/solution/1700-1799/1788.Maximize%20the%20Beauty%20of%20the%20Garden/README.md", "relative_path_en": "/solution/1700-1799/1788.Maximize%20the%20Beauty%20of%20the%20Garden/README_EN.md", "title_cn": "", "title_en": "Maximize the Beauty of the Garden", "question_title_slug": "maximize-the-beauty-of-the-garden", "content_en": "

There is a garden of n flowers, and each flower has an integer beauty value. The flowers are arranged in a line. You are given an integer array flowers of size n and each flowers[i] represents the beauty of the ith flower.

\r\n\r\n

A garden is valid if it meets these conditions:

\r\n\r\n
    \r\n\t
  • The garden has at least two flowers.
  • \r\n\t
  • The first and the last flower of the garden have the same beauty value.
  • \r\n
\r\n\r\n

As the appointed gardener, you have the ability to remove any (possibly none) flowers from the garden. You want to remove flowers in a way that makes the remaining garden valid. The beauty of the garden is the sum of the beauty of all the remaining flowers.

\r\n\r\n

Return the maximum possible beauty of some valid garden after you have removed any (possibly none) flowers.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: flowers = [1,2,3,1,2]\r\nOutput: 8\r\nExplanation: You can produce the valid garden [2,3,1,2] to have a total beauty of 2 + 3 + 1 + 2 = 8.
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: flowers = [100,1,1,-3,1]\r\nOutput: 3\r\nExplanation: You can produce the valid garden [1,1,1] to have a total beauty of 1 + 1 + 1 = 3.\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: flowers = [-1,-2,0,-1]\r\nOutput: -2\r\nExplanation: You can produce the valid garden [-1,-1] to have a total beauty of -1 + -1 = -2.\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 2 <= flowers.length <= 105
  • \r\n\t
  • -104 <= flowers[i] <= 104
  • \r\n\t
  • It is possible to create a valid garden by removing some (possibly none) flowers.
  • \r\n
", "content_cn": null, "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maximumBeauty(vector& flowers) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maximumBeauty(int[] flowers) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximumBeauty(self, flowers):\n \"\"\"\n :type flowers: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximumBeauty(self, flowers: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maximumBeauty(int* flowers, int flowersSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaximumBeauty(int[] flowers) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} flowers\n * @return {number}\n */\nvar maximumBeauty = function(flowers) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} flowers\n# @return {Integer}\ndef maximum_beauty(flowers)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximumBeauty(_ flowers: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximumBeauty(flowers []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximumBeauty(flowers: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximumBeauty(flowers: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximum_beauty(flowers: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $flowers\n * @return Integer\n */\n function maximumBeauty($flowers) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximumBeauty(flowers: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximum-beauty flowers)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1788](https://leetcode-cn.com/problems/maximize-the-beauty-of-the-garden)", "[Maximize the Beauty of the Garden](/solution/1700-1799/1788.Maximize%20the%20Beauty%20of%20the%20Garden/README_EN.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1788](https://leetcode.com/problems/maximize-the-beauty-of-the-garden)", "[Maximize the Beauty of the Garden](/solution/1700-1799/1788.Maximize%20the%20Beauty%20of%20the%20Garden/README_EN.md)", "`Greedy`", "Hard", "\ud83d\udd12"]}, {"question_id": "1936", "frontend_question_id": "1808", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximize-number-of-nice-divisors", "url_en": "https://leetcode.com/problems/maximize-number-of-nice-divisors", "relative_path_cn": "/solution/1800-1899/1808.Maximize%20Number%20of%20Nice%20Divisors/README.md", "relative_path_en": "/solution/1800-1899/1808.Maximize%20Number%20of%20Nice%20Divisors/README_EN.md", "title_cn": "\u597d\u56e0\u5b50\u7684\u6700\u5927\u6570\u76ee", "title_en": "Maximize Number of Nice Divisors", "question_title_slug": "maximize-number-of-nice-divisors", "content_en": "

You are given a positive integer primeFactors. You are asked to construct a positive integer n that satisfies the following conditions:

\r\n\r\n
    \r\n
  • The number of prime factors of n (not necessarily distinct) is at most primeFactors.
  • \r\n
  • The number of nice divisors of n is maximized. Note that a divisor of n is nice if it is divisible by every prime factor of n. For example, if n = 12, then its prime factors are [2,2,3], then 6 and 12 are nice divisors, while 3 and 4 are not.
  • \r\n
\r\n\r\n

Return the number of nice divisors of n. Since that number can be too large, return it modulo 109 + 7.

\r\n\r\n

Note that a prime number is a natural number greater than 1 that is not a product of two smaller natural numbers. The prime factors of a number n is a list of prime numbers such that their product equals n.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: primeFactors = 5\r\nOutput: 6\r\nExplanation: 200 is a valid value of n.\r\nIt has 5 prime factors: [2,2,2,5,5], and it has 6 nice divisors: [10,20,40,50,100,200].\r\nThere is not other value of n that has at most 5 prime factors and more nice divisors.\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: primeFactors = 8\r\nOutput: 18\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= primeFactors <= 109
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6b63\u6574\u6570\u00a0primeFactors\u00a0\u3002\u4f60\u9700\u8981\u6784\u9020\u4e00\u4e2a\u6b63\u6574\u6570\u00a0n\u00a0\uff0c\u5b83\u6ee1\u8db3\u4ee5\u4e0b\u6761\u4ef6\uff1a

\n\n
    \n\t
  • n\u00a0\u8d28\u56e0\u6570\uff08\u8d28\u56e0\u6570\u9700\u8981\u8003\u8651\u91cd\u590d\u7684\u60c5\u51b5\uff09\u7684\u6570\u76ee \u4e0d\u8d85\u8fc7\u00a0primeFactors\u00a0\u4e2a\u3002
  • \n\t
  • n\u00a0\u597d\u56e0\u5b50\u7684\u6570\u76ee\u6700\u5927\u5316\u3002\u5982\u679c n\u00a0\u7684\u4e00\u4e2a\u56e0\u5b50\u53ef\u4ee5\u88ab n\u00a0\u7684\u6bcf\u4e00\u4e2a\u8d28\u56e0\u6570\u6574\u9664\uff0c\u6211\u4eec\u79f0\u8fd9\u4e2a\u56e0\u5b50\u662f \u597d\u56e0\u5b50 \u3002\u6bd4\u65b9\u8bf4\uff0c\u5982\u679c\u00a0n = 12\u00a0\uff0c\u90a3\u4e48\u5b83\u7684\u8d28\u56e0\u6570\u4e3a\u00a0[2,2,3]\u00a0\uff0c\u90a3\u4e48\u00a06\u00a0\u548c\u00a012\u00a0\u662f\u597d\u56e0\u5b50\uff0c\u4f46\u00a03 \u548c\u00a04\u00a0\u4e0d\u662f\u3002
  • \n
\n\n

\u8bf7\u4f60\u8fd4\u56de\u00a0n\u00a0\u7684\u597d\u56e0\u5b50\u7684\u6570\u76ee\u3002\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u4f1a\u5f88\u5927\uff0c\u8bf7\u8fd4\u56de\u7b54\u6848\u5bf9\u00a0109 + 7\u00a0\u53d6\u4f59\u00a0\u7684\u7ed3\u679c\u3002

\n\n

\u8bf7\u6ce8\u610f\uff0c\u4e00\u4e2a\u8d28\u6570\u7684\u5b9a\u4e49\u662f\u5927\u4e8e 1\u00a0\uff0c\u4e14\u4e0d\u80fd\u88ab\u5206\u89e3\u4e3a\u4e24\u4e2a\u5c0f\u4e8e\u8be5\u6570\u7684\u81ea\u7136\u6570\u76f8\u4e58\u3002\u4e00\u4e2a\u6570 n\u00a0\u7684\u8d28\u56e0\u5b50\u662f\u5c06 n\u00a0\u5206\u89e3\u4e3a\u82e5\u5e72\u4e2a\u8d28\u56e0\u5b50\uff0c\u4e14\u5b83\u4eec\u7684\u4e58\u79ef\u4e3a n\u00a0\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aprimeFactors = 5\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a200 \u662f\u4e00\u4e2a\u53ef\u884c\u7684 n \u3002\n\u5b83\u6709 5 \u4e2a\u8d28\u56e0\u5b50\uff1a[2,2,2,5,5] \uff0c\u4e14\u6709 6 \u4e2a\u597d\u56e0\u5b50\uff1a[10,20,40,50,100,200] \u3002\n\u4e0d\u5b58\u5728\u522b\u7684 n \u6709\u81f3\u591a 5 \u4e2a\u8d28\u56e0\u5b50\uff0c\u4e14\u540c\u65f6\u6709\u66f4\u591a\u7684\u597d\u56e0\u5b50\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aprimeFactors = 8\n\u8f93\u51fa\uff1a18\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= primeFactors <= 109
  • \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxNiceDivisors(int primeFactors) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxNiceDivisors(int primeFactors) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxNiceDivisors(self, primeFactors):\n \"\"\"\n :type primeFactors: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxNiceDivisors(self, primeFactors: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxNiceDivisors(int primeFactors){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxNiceDivisors(int primeFactors) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} primeFactors\n * @return {number}\n */\nvar maxNiceDivisors = function(primeFactors) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} prime_factors\n# @return {Integer}\ndef max_nice_divisors(prime_factors)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxNiceDivisors(_ primeFactors: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxNiceDivisors(primeFactors int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxNiceDivisors(primeFactors: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxNiceDivisors(primeFactors: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_nice_divisors(prime_factors: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $primeFactors\n * @return Integer\n */\n function maxNiceDivisors($primeFactors) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxNiceDivisors(primeFactors: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-nice-divisors primeFactors)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1808](https://leetcode-cn.com/problems/maximize-number-of-nice-divisors)", "[\u597d\u56e0\u5b50\u7684\u6700\u5927\u6570\u76ee](/solution/1800-1899/1808.Maximize%20Number%20of%20Nice%20Divisors/README.md)", "`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[1808](https://leetcode.com/problems/maximize-number-of-nice-divisors)", "[Maximize Number of Nice Divisors](/solution/1800-1899/1808.Maximize%20Number%20of%20Nice%20Divisors/README_EN.md)", "`Math`", "Hard", ""]}, {"question_id": "1935", "frontend_question_id": "1806", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-number-of-operations-to-reinitialize-a-permutation", "url_en": "https://leetcode.com/problems/minimum-number-of-operations-to-reinitialize-a-permutation", "relative_path_cn": "/solution/1800-1899/1806.Minimum%20Number%20of%20Operations%20to%20Reinitialize%20a%20Permutation/README.md", "relative_path_en": "/solution/1800-1899/1806.Minimum%20Number%20of%20Operations%20to%20Reinitialize%20a%20Permutation/README_EN.md", "title_cn": "\u8fd8\u539f\u6392\u5217\u7684\u6700\u5c11\u64cd\u4f5c\u6b65\u6570", "title_en": "Minimum Number of Operations to Reinitialize a Permutation", "question_title_slug": "minimum-number-of-operations-to-reinitialize-a-permutation", "content_en": "

You are given an even integer n\u200b\u200b\u200b\u200b\u200b\u200b. You initially have a permutation perm of size n\u200b\u200b where perm[i] == i\u200b (0-indexed)\u200b\u200b\u200b\u200b.

\n\n

In one operation, you will create a new array arr, and for each i:

\n\n
    \n\t
  • If i % 2 == 0, then arr[i] = perm[i / 2].
  • \n\t
  • If i % 2 == 1, then arr[i] = perm[n / 2 + (i - 1) / 2].
  • \n
\n\n

You will then assign arr\u200b\u200b\u200b\u200b to perm.

\n\n

Return the minimum non-zero number of operations you need to perform on perm to return the permutation to its initial value.

\n\n

 

\n

Example 1:

\n\n
\nInput: n = 2\nOutput: 1\nExplanation: perm = [0,1] initially.\nAfter the 1st operation, perm = [0,1]\nSo it takes only 1 operation.\n
\n\n

Example 2:

\n\n
\nInput: n = 4\nOutput: 2\nExplanation: perm = [0,1,2,3] initially.\nAfter the 1st operation, perm = [0,2,1,3]\nAfter the 2nd operation, perm = [0,1,2,3]\nSo it takes only 2 operations.\n
\n\n

Example 3:

\n\n
\nInput: n = 6\nOutput: 4\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= n <= 1000
  • \n\t
  • n\u200b\u200b\u200b\u200b\u200b\u200b is even.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5076\u6570 n\u200b\u200b\u200b\u200b\u200b\u200b \uff0c\u5df2\u77e5\u5b58\u5728\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u6392\u5217 perm \uff0c\u5176\u4e2d perm[i] == i\u200b\uff08\u4e0b\u6807 \u4ece 0 \u5f00\u59cb \u8ba1\u6570\uff09\u3002

\n\n

\u4e00\u6b65\u64cd\u4f5c\u4e2d\uff0c\u4f60\u5c06\u521b\u5efa\u4e00\u4e2a\u65b0\u6570\u7ec4 arr \uff0c\u5bf9\u4e8e\u6bcf\u4e2a i \uff1a

\n\n
    \n\t
  • \u5982\u679c i % 2 == 0 \uff0c\u90a3\u4e48 arr[i] = perm[i / 2]
  • \n\t
  • \u5982\u679c i % 2 == 1 \uff0c\u90a3\u4e48 arr[i] = perm[n / 2 + (i - 1) / 2]
  • \n
\n\n

\u7136\u540e\u5c06 arr\u200b\u200b \u8d4b\u503c\u200b\u200b\u7ed9 perm \u3002

\n\n

\u8981\u60f3\u4f7f perm \u56de\u5230\u6392\u5217\u521d\u59cb\u503c\uff0c\u81f3\u5c11\u9700\u8981\u6267\u884c\u591a\u5c11\u6b65\u64cd\u4f5c\uff1f\u8fd4\u56de\u6700\u5c0f\u7684 \u975e\u96f6 \u64cd\u4f5c\u6b65\u6570\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1an = 2\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u6700\u521d\uff0cperm = [0,1]\n\u7b2c 1\u00a0\u6b65\u64cd\u4f5c\u540e\uff0cperm = [0,1]\n\u6240\u4ee5\uff0c\u4ec5\u9700\u6267\u884c 1 \u6b65\u64cd\u4f5c
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1an = 4\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6700\u521d\uff0cperm = [0,1,2,3]\n\u7b2c 1\u00a0\u6b65\u64cd\u4f5c\u540e\uff0cperm = [0,2,1,3]\n\u7b2c 2\u00a0\u6b65\u64cd\u4f5c\u540e\uff0cperm = [0,1,2,3]\n\u6240\u4ee5\uff0c\u4ec5\u9700\u6267\u884c 2 \u6b65\u64cd\u4f5c
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1an = 6\n\u8f93\u51fa\uff1a4\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= n <= 1000
  • \n\t
  • n\u200b\u200b\u200b\u200b\u200b\u200b \u662f\u4e00\u4e2a\u5076\u6570
  • \n
\n", "tags_en": ["Greedy", "Array"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int reinitializePermutation(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int reinitializePermutation(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def reinitializePermutation(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def reinitializePermutation(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint reinitializePermutation(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ReinitializePermutation(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar reinitializePermutation = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef reinitialize_permutation(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func reinitializePermutation(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func reinitializePermutation(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def reinitializePermutation(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun reinitializePermutation(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn reinitialize_permutation(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function reinitializePermutation($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function reinitializePermutation(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (reinitialize-permutation n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1806](https://leetcode-cn.com/problems/minimum-number-of-operations-to-reinitialize-a-permutation)", "[\u8fd8\u539f\u6392\u5217\u7684\u6700\u5c11\u64cd\u4f5c\u6b65\u6570](/solution/1800-1899/1806.Minimum%20Number%20of%20Operations%20to%20Reinitialize%20a%20Permutation/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1806](https://leetcode.com/problems/minimum-number-of-operations-to-reinitialize-a-permutation)", "[Minimum Number of Operations to Reinitialize a Permutation](/solution/1800-1899/1806.Minimum%20Number%20of%20Operations%20to%20Reinitialize%20a%20Permutation/README_EN.md)", "`Greedy`,`Array`", "Medium", ""]}, {"question_id": "1934", "frontend_question_id": "1807", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/evaluate-the-bracket-pairs-of-a-string", "url_en": "https://leetcode.com/problems/evaluate-the-bracket-pairs-of-a-string", "relative_path_cn": "/solution/1800-1899/1807.Evaluate%20the%20Bracket%20Pairs%20of%20a%20String/README.md", "relative_path_en": "/solution/1800-1899/1807.Evaluate%20the%20Bracket%20Pairs%20of%20a%20String/README_EN.md", "title_cn": "\u66ff\u6362\u5b57\u7b26\u4e32\u4e2d\u7684\u62ec\u53f7\u5185\u5bb9", "title_en": "Evaluate the Bracket Pairs of a String", "question_title_slug": "evaluate-the-bracket-pairs-of-a-string", "content_en": "

You are given a string s that contains some bracket pairs, with each pair containing a non-empty key.

\n\n
    \n\t
  • For example, in the string "(name)is(age)yearsold", there are two bracket pairs that contain the keys "name" and "age".
  • \n
\n\n

You know the values of a wide range of keys. This is represented by a 2D string array knowledge where each knowledge[i] = [keyi, valuei] indicates that key keyi has a value of valuei.

\n\n

You are tasked to evaluate all of the bracket pairs. When you evaluate a bracket pair that contains some key keyi, you will:

\n\n
    \n\t
  • Replace keyi and the bracket pair with the key's corresponding valuei.
  • \n\t
  • If you do not know the value of the key, you will replace keyi and the bracket pair with a question mark "?" (without the quotation marks).
  • \n
\n\n

Each key will appear at most once in your knowledge. There will not be any nested brackets in s.

\n\n

Return the resulting string after evaluating all of the bracket pairs.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "(name)is(age)yearsold", knowledge = [["name","bob"],["age","two"]]\nOutput: "bobistwoyearsold"\nExplanation:\nThe key "name" has a value of "bob", so replace "(name)" with "bob".\nThe key "age" has a value of "two", so replace "(age)" with "two".\n
\n\n

Example 2:

\n\n
\nInput: s = "hi(name)", knowledge = [["a","b"]]\nOutput: "hi?"\nExplanation: As you do not know the value of the key "name", replace "(name)" with "?".\n
\n\n

Example 3:

\n\n
\nInput: s = "(a)(a)(a)aaa", knowledge = [["a","yes"]]\nOutput: "yesyesyesaaa"\nExplanation: The same key can appear multiple times.\nThe key "a" has a value of "yes", so replace all occurrences of "(a)" with "yes".\nNotice that the "a"s not in a bracket pair are not evaluated.\n
\n\n

Example 4:

\n\n
\nInput: s = "(a)(b)", knowledge = [["a","b"],["b","a"]]\nOutput: "ba"
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 105
  • \n\t
  • 0 <= knowledge.length <= 105
  • \n\t
  • knowledge[i].length == 2
  • \n\t
  • 1 <= keyi.length, valuei.length <= 10
  • \n\t
  • s consists of lowercase English letters and round brackets '(' and ')'.
  • \n\t
  • Every open bracket '(' in s will have a corresponding close bracket ')'.
  • \n\t
  • The key in each bracket pair of s will be non-empty.
  • \n\t
  • There will not be any nested bracket pairs in s.
  • \n\t
  • keyi and valuei consist of lowercase English letters.
  • \n\t
  • Each keyi in knowledge is unique.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32\u00a0s\u00a0\uff0c\u5b83\u5305\u542b\u4e00\u4e9b\u62ec\u53f7\u5bf9\uff0c\u6bcf\u4e2a\u62ec\u53f7\u4e2d\u5305\u542b\u4e00\u4e2a \u975e\u7a7a\u00a0\u7684\u952e\u3002

\n\n
    \n\t
  • \u6bd4\u65b9\u8bf4\uff0c\u5b57\u7b26\u4e32\u00a0\"(name)is(age)yearsold\"\u00a0\u4e2d\uff0c\u6709\u00a0\u4e24\u4e2a\u00a0\u62ec\u53f7\u5bf9\uff0c\u5206\u522b\u5305\u542b\u952e\u00a0\"name\" \u548c\u00a0\"age\"\u00a0\u3002
  • \n
\n\n

\u4f60\u77e5\u9053\u8bb8\u591a\u952e\u5bf9\u5e94\u7684\u503c\uff0c\u8fd9\u4e9b\u5173\u7cfb\u7531\u4e8c\u7ef4\u5b57\u7b26\u4e32\u6570\u7ec4\u00a0knowledge\u00a0\u8868\u793a\uff0c\u5176\u4e2d\u00a0knowledge[i] = [keyi, valuei]\u00a0\uff0c\u8868\u793a\u952e\u00a0keyi\u00a0\u5bf9\u5e94\u7684\u503c\u4e3a\u00a0valuei\u00a0\u3002

\n\n

\u4f60\u9700\u8981\u66ff\u6362 \u6240\u6709\u00a0\u7684\u62ec\u53f7\u5bf9\u3002\u5f53\u4f60\u66ff\u6362\u4e00\u4e2a\u62ec\u53f7\u5bf9\uff0c\u4e14\u5b83\u5305\u542b\u7684\u952e\u4e3a\u00a0keyi\u00a0\u65f6\uff0c\u4f60\u9700\u8981\uff1a

\n\n
    \n\t
  • \u5c06\u00a0keyi\u00a0\u548c\u62ec\u53f7\u7528\u5bf9\u5e94\u7684\u503c\u00a0valuei\u00a0\u66ff\u6362\u3002
  • \n\t
  • \u5982\u679c\u4ece knowledge\u00a0\u4e2d\u65e0\u6cd5\u5f97\u77e5\u67d0\u4e2a\u952e\u5bf9\u5e94\u7684\u503c\uff0c\u4f60\u9700\u8981\u5c06\u00a0keyi\u00a0\u548c\u62ec\u53f7\u7528\u95ee\u53f7\u00a0\"?\"\u00a0\u66ff\u6362\uff08\u4e0d\u9700\u8981\u5f15\u53f7\uff09\u3002
  • \n
\n\n

knowledge\u00a0\u4e2d\u6bcf\u4e2a\u952e\u6700\u591a\u53ea\u4f1a\u51fa\u73b0\u4e00\u6b21\u3002s\u00a0\u4e2d\u4e0d\u4f1a\u6709\u5d4c\u5957\u7684\u62ec\u53f7\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u66ff\u6362 \u6240\u6709\u00a0\u62ec\u53f7\u5bf9\u540e\u7684\u7ed3\u679c\u5b57\u7b26\u4e32\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1as = \"(name)is(age)yearsold\", knowledge = [[\"name\",\"bob\"],[\"age\",\"two\"]]\n\u8f93\u51fa\uff1a\"bobistwoyearsold\"\n\u89e3\u91ca\uff1a\n\u952e \"name\" \u5bf9\u5e94\u7684\u503c\u4e3a \"bob\" \uff0c\u6240\u4ee5\u5c06 \"(name)\" \u66ff\u6362\u4e3a \"bob\" \u3002\n\u952e \"age\" \u5bf9\u5e94\u7684\u503c\u4e3a \"two\" \uff0c\u6240\u4ee5\u5c06 \"(age)\" \u66ff\u6362\u4e3a \"two\" \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1as = \"hi(name)\", knowledge = [[\"a\",\"b\"]]\n\u8f93\u51fa\uff1a\"hi?\"\n\u89e3\u91ca\uff1a\u7531\u4e8e\u4e0d\u77e5\u9053\u952e \"name\" \u5bf9\u5e94\u7684\u503c\uff0c\u6240\u4ee5\u7528 \"?\" \u66ff\u6362 \"(name)\" \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1as = \"(a)(a)(a)aaa\", knowledge = [[\"a\",\"yes\"]]\n\u8f93\u51fa\uff1a\"yesyesyesaaa\"\n\u89e3\u91ca\uff1a\u76f8\u540c\u7684\u952e\u5728 s \u4e2d\u53ef\u80fd\u4f1a\u51fa\u73b0\u591a\u6b21\u3002\n\u952e \"a\" \u5bf9\u5e94\u7684\u503c\u4e3a \"yes\" \uff0c\u6240\u4ee5\u5c06\u6240\u6709\u7684 \"(a)\" \u66ff\u6362\u4e3a \"yes\" \u3002\n\u6ce8\u610f\uff0c\u4e0d\u5728\u62ec\u53f7\u91cc\u7684 \"a\" \u4e0d\u9700\u8981\u88ab\u66ff\u6362\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1as = \"(a)(b)\", knowledge = [[\"a\",\"b\"],[\"b\",\"a\"]]\n\u8f93\u51fa\uff1a\"ba\"
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length <= 105
  • \n\t
  • 0 <= knowledge.length <= 105
  • \n\t
  • knowledge[i].length == 2
  • \n\t
  • 1 <= keyi.length, valuei.length <= 10
  • \n\t
  • s\u00a0\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u548c\u5706\u62ec\u53f7\u00a0'('\u00a0\u548c\u00a0')'\u00a0\u3002
  • \n\t
  • s\u00a0\u4e2d\u6bcf\u4e00\u4e2a\u5de6\u5706\u62ec\u53f7\u00a0'('\u00a0\u90fd\u6709\u5bf9\u5e94\u7684\u53f3\u5706\u62ec\u53f7\u00a0')'\u00a0\u3002
  • \n\t
  • s\u00a0\u4e2d\u6bcf\u5bf9\u62ec\u53f7\u5185\u7684\u952e\u90fd\u4e0d\u4f1a\u4e3a\u7a7a\u3002
  • \n\t
  • s\u00a0\u4e2d\u4e0d\u4f1a\u6709\u5d4c\u5957\u62ec\u53f7\u5bf9\u3002
  • \n\t
  • keyi\u00a0\u548c\u00a0valuei\u00a0\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
  • \n\t
  • knowledge\u00a0\u4e2d\u7684\u00a0keyi\u00a0\u4e0d\u4f1a\u91cd\u590d\u3002
  • \n
\n", "tags_en": ["Hash Table", "String"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string evaluate(string s, vector>& knowledge) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String evaluate(String s, List> knowledge) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def evaluate(self, s, knowledge):\n \"\"\"\n :type s: str\n :type knowledge: List[List[str]]\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def evaluate(self, s: str, knowledge: List[List[str]]) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * evaluate(char * s, char *** knowledge, int knowledgeSize, int* knowledgeColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string Evaluate(string s, IList> knowledge) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string[][]} knowledge\n * @return {string}\n */\nvar evaluate = function(s, knowledge) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String[][]} knowledge\n# @return {String}\ndef evaluate(s, knowledge)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func evaluate(_ s: String, _ knowledge: [[String]]) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func evaluate(s string, knowledge [][]string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def evaluate(s: String, knowledge: List[List[String]]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun evaluate(s: String, knowledge: List>): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn evaluate(s: String, knowledge: Vec>) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String[][] $knowledge\n * @return String\n */\n function evaluate($s, $knowledge) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function evaluate(s: string, knowledge: string[][]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (evaluate s knowledge)\n (-> string? (listof (listof string?)) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1807](https://leetcode-cn.com/problems/evaluate-the-bracket-pairs-of-a-string)", "[\u66ff\u6362\u5b57\u7b26\u4e32\u4e2d\u7684\u62ec\u53f7\u5185\u5bb9](/solution/1800-1899/1807.Evaluate%20the%20Bracket%20Pairs%20of%20a%20String/README.md)", "`\u54c8\u5e0c\u8868`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1807](https://leetcode.com/problems/evaluate-the-bracket-pairs-of-a-string)", "[Evaluate the Bracket Pairs of a String](/solution/1800-1899/1807.Evaluate%20the%20Bracket%20Pairs%20of%20a%20String/README_EN.md)", "`Hash Table`,`String`", "Medium", ""]}, {"question_id": "1933", "frontend_question_id": "1805", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-different-integers-in-a-string", "url_en": "https://leetcode.com/problems/number-of-different-integers-in-a-string", "relative_path_cn": "/solution/1800-1899/1805.Number%20of%20Different%20Integers%20in%20a%20String/README.md", "relative_path_en": "/solution/1800-1899/1805.Number%20of%20Different%20Integers%20in%20a%20String/README_EN.md", "title_cn": "\u5b57\u7b26\u4e32\u4e2d\u4e0d\u540c\u6574\u6570\u7684\u6570\u76ee", "title_en": "Number of Different Integers in a String", "question_title_slug": "number-of-different-integers-in-a-string", "content_en": "

You are given a string word that consists of digits and lowercase English letters.

\n\n

You will replace every non-digit character with a space. For example, "a123bc34d8ef34" will become " 123  34 8  34". Notice that you are left with some integers that are separated by at least one space: "123", "34", "8", and "34".

\n\n

Return the number of different integers after performing the replacement operations on word.

\n\n

Two integers are considered different if their decimal representations without any leading zeros are different.

\n\n

 

\n

Example 1:

\n\n
\nInput: word = "a123bc34d8ef34"\nOutput: 3\nExplanation: The three different integers are "123", "34", and "8". Notice that "34" is only counted once.\n
\n\n

Example 2:

\n\n
\nInput: word = "leet1234code234"\nOutput: 2\n
\n\n

Example 3:

\n\n
\nInput: word = "a1b01c001"\nOutput: 1\nExplanation: The three integers "1", "01", and "001" all represent the same integer because\nthe leading zeros are ignored when comparing their decimal values.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= word.length <= 1000
  • \n\t
  • word consists of digits and lowercase English letters.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 word \uff0c\u8be5\u5b57\u7b26\u4e32\u7531\u6570\u5b57\u548c\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\u3002

\n\n

\u8bf7\u4f60\u7528\u7a7a\u683c\u66ff\u6362\u6bcf\u4e2a\u4e0d\u662f\u6570\u5b57\u7684\u5b57\u7b26\u3002\u4f8b\u5982\uff0c\"a123bc34d8ef34\" \u5c06\u4f1a\u53d8\u6210 \" 123\u00a0 34 8\u00a0 34\" \u3002\u6ce8\u610f\uff0c\u5269\u4e0b\u7684\u8fd9\u4e9b\u6574\u6570\u4e3a\uff08\u76f8\u90bb\u5f7c\u6b64\u81f3\u5c11\u6709\u4e00\u4e2a\u7a7a\u683c\u9694\u5f00\uff09\uff1a\"123\"\u3001\"34\"\u3001\"8\" \u548c \"34\" \u3002

\n\n

\u8fd4\u56de\u5bf9 word \u5b8c\u6210\u66ff\u6362\u540e\u5f62\u6210\u7684 \u4e0d\u540c \u6574\u6570\u7684\u6570\u76ee\u3002

\n\n

\u53ea\u6709\u5f53\u4e24\u4e2a\u6574\u6570\u7684 \u4e0d\u542b\u524d\u5bfc\u96f6 \u7684\u5341\u8fdb\u5236\u8868\u793a\u4e0d\u540c\uff0c \u624d\u8ba4\u4e3a\u8fd9\u4e24\u4e2a\u6574\u6570\u4e5f\u4e0d\u540c\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aword = \"a123bc34d8ef34\"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u4e0d\u540c\u7684\u6574\u6570\u6709 \"123\"\u3001\"34\" \u548c \"8\" \u3002\u6ce8\u610f\uff0c\"34\" \u53ea\u8ba1\u6570\u4e00\u6b21\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aword = \"leet1234code234\"\n\u8f93\u51fa\uff1a2\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1aword = \"a1b01c001\"\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\"1\"\u3001\"01\" \u548c \"001\" \u89c6\u4e3a\u540c\u4e00\u4e2a\u6574\u6570\u7684\u5341\u8fdb\u5236\u8868\u793a\uff0c\u56e0\u4e3a\u5728\u6bd4\u8f83\u5341\u8fdb\u5236\u503c\u65f6\u4f1a\u5ffd\u7565\u524d\u5bfc\u96f6\u7684\u5b58\u5728\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= word.length <= 1000
  • \n\t
  • word \u7531\u6570\u5b57\u548c\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numDifferentIntegers(string word) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numDifferentIntegers(String word) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numDifferentIntegers(self, word):\n \"\"\"\n :type word: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numDifferentIntegers(self, word: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numDifferentIntegers(char * word){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumDifferentIntegers(string word) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} word\n * @return {number}\n */\nvar numDifferentIntegers = function(word) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} word\n# @return {Integer}\ndef num_different_integers(word)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numDifferentIntegers(_ word: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numDifferentIntegers(word string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numDifferentIntegers(word: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numDifferentIntegers(word: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_different_integers(word: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $word\n * @return Integer\n */\n function numDifferentIntegers($word) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numDifferentIntegers(word: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-different-integers word)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1805](https://leetcode-cn.com/problems/number-of-different-integers-in-a-string)", "[\u5b57\u7b26\u4e32\u4e2d\u4e0d\u540c\u6574\u6570\u7684\u6570\u76ee](/solution/1800-1899/1805.Number%20of%20Different%20Integers%20in%20a%20String/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1805](https://leetcode.com/problems/number-of-different-integers-in-a-string)", "[Number of Different Integers in a String](/solution/1800-1899/1805.Number%20of%20Different%20Integers%20in%20a%20String/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1932", "frontend_question_id": "1783", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/grand-slam-titles", "url_en": "https://leetcode.com/problems/grand-slam-titles", "relative_path_cn": "/solution/1700-1799/1783.Grand%20Slam%20Titles/README.md", "relative_path_en": "/solution/1700-1799/1783.Grand%20Slam%20Titles/README_EN.md", "title_cn": "\u5927\u6ee1\u8d2f\u6570\u91cf", "title_en": "Grand Slam Titles", "question_title_slug": "grand-slam-titles", "content_en": "

Table: Players

\r\n\r\n
\r\n+----------------+---------+\r\n| Column Name    | Type    |\r\n+----------------+---------+\r\n| player_id      | int     |\r\n| player_name    | varchar |\r\n+----------------+---------+\r\nplayer_id is the primary key for this table.\r\nEach row in this table contains the name and the ID of a tennis player.\r\n
\r\n\r\n

 

\r\n\r\n

Table: Championships

\r\n\r\n
\r\n+---------------+---------+\r\n| Column Name   | Type    |\r\n+---------------+---------+\r\n| year          | int     |\r\n| Wimbledon     | int     |\r\n| Fr_open       | int     |\r\n| US_open       | int     |\r\n| Au_open       | int     |\r\n+---------------+---------+\r\nyear is the primary key for this table.\r\nEach row of this table containts the IDs of the players who won one each tennis tournament of the grand slam.\r\n
\r\n\r\n

 

\r\n\r\n

Write an SQL query to report the number of grand slam tournaments won by each player. Do not include the players who did not win any tournament.

\r\n\r\n

Return the result table in any order.

\r\n\r\n

The query result format is in the following example:

\r\n\r\n

 

\r\n\r\n
\r\nPlayers table:\r\n+-----------+-------------+\r\n| player_id | player_name |\r\n+-----------+-------------+\r\n| 1         | Nadal       |\r\n| 2         | Federer     |\r\n| 3         | Novak       |\r\n+-----------+-------------+\r\n\r\nChampionships table:\r\n+------+-----------+---------+---------+---------+\r\n| year | Wimbledon | Fr_open | US_open | Au_open |\r\n+------+-----------+---------+---------+---------+\r\n| 2018 | 1         | 1       | 1       | 1       |\r\n| 2019 | 1         | 1       | 2       | 2       |\r\n| 2020 | 2         | 1       | 2       | 2       |\r\n+------+-----------+---------+---------+---------+\r\n\r\nResult table:\r\n+-----------+-------------+-------------------+\r\n| player_id | player_name | grand_slams_count |\r\n+-----------+-------------+-------------------+\r\n| 2         | Federer     | 5                 |\r\n| 1         | Nadal       | 7                 |\r\n+-----------+-------------+-------------------+\r\n\r\nPlayer 1 (Nadal) won 7 titles: Wimbledon (2018, 2019), Fr_open (2018, 2019, 2020), US_open (2018), and Au_open (2018).\r\nPlayer 2 (Federer) won 5 titles: Wimbledon (2020), US_open (2019, 2020), and Au_open (2019, 2020).\r\nPlayer 3 (Novak) did not win anything, we did not include them in the result table.\r\n
", "content_cn": "

\u8868\uff1aPlayers

\n\n
\n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| player_id      | int     |\n| player_name    | varchar |\n+----------------+---------+\nplayer_id \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\n\u8fd9\u4e2a\u8868\u7684\u6bcf\u4e00\u884c\u7ed9\u51fa\u4e00\u4e2a\u7f51\u7403\u8fd0\u52a8\u5458\u7684 ID \u548c \u59d3\u540d\n
\n\n

\u8868\uff1aChampionships

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| year          | int     |\n| Wimbledon     | int     |\n| Fr_open       | int     |\n| US_open       | int     |\n| Au_open       | int     |\n+---------------+---------+\nyear \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\n\u8be5\u8868\u7684\u6bcf\u4e00\u884c\u90fd\u5305\u542b\u5728\u6bcf\u573a\u5927\u6ee1\u8d2f\u7f51\u7403\u6bd4\u8d5b\u4e2d\u8d62\u5f97\u6bd4\u8d5b\u7684\u7403\u5458\u7684 ID\n
\n\n

\u00a0

\n\n

\u8bf7\u5199\u51fa\u67e5\u8be2\u8bed\u53e5\uff0c\u67e5\u8be2\u51fa\u6bcf\u4e00\u4e2a\u7403\u5458\u8d62\u5f97\u5927\u6ee1\u8d2f\u6bd4\u8d5b\u7684\u6b21\u6570\u3002\u7ed3\u679c\u4e0d\u5305\u542b\u6ca1\u6709\u8d62\u5f97\u6bd4\u8d5b\u7684\u7403\u5458\u7684ID \u3002

\n\n

\u7ed3\u679c\u96c6\u65e0\u987a\u5e8f\u8981\u6c42\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u7684\u683c\u5f0f\uff0c\u5982\u4e0b\u6240\u793a\uff1a

\n\n

\u00a0

\n\n
\nPlayers \u8868\uff1a\n+-----------+-------------+\n| player_id | player_name |\n+-----------+-------------+\n| 1         | Nadal       |\n| 2         | Federer     |\n| 3         | Novak       |\n+-----------+-------------+\n\nChampionships \u8868\uff1a\n+------+-----------+---------+---------+---------+\n| year | Wimbledon | Fr_open | US_open | Au_open |\n+------+-----------+---------+---------+---------+\n| 2018 | 1         | 1       | 1       | 1       |\n| 2019 | 1         | 1       | 2       | 2       |\n| 2020 | 2         | 1       | 2       | 2       |\n+------+-----------+---------+---------+---------+\n\nResult \u8868\uff1a\n+-----------+-------------+-------------------+\n| player_id | player_name | grand_slams_count |\n+-----------+-------------+-------------------+\n| 2         | Federer     | 5                 |\n| 1         | Nadal       | 7                 |\n+-----------+-------------+-------------------+\n\nPlayer 1 (Nadal) \u83b7\u5f97\u4e86 7 \u6b21\u5927\u6ee1\u8d2f\uff1a\u5176\u4e2d\u6e29\u7f51 2 \u6b21(2018, 2019), \u6cd5\u56fd\u516c\u5f00\u8d5b 3 \u6b21 (2018, 2019, 2020), \u7f8e\u56fd\u516c\u5f00\u8d5b 1 \u6b21 (2018)\u4ee5\u53ca\u6fb3\u7f51\u516c\u5f00\u8d5b 1 \u6b21 (2018) \u3002\nPlayer 2 (Federer) \u83b7\u5f97\u4e86 5 \u6b21\u5927\u6ee1\u8d2f\uff1a\u5176\u4e2d\u6e29\u7f51 1 \u6b21 (2020), \u7f8e\u56fd\u516c\u5f00\u8d5b 2 \u6b21 (2019, 2020) \u4ee5\u53ca\u6fb3\u7f51\u516c\u5f00\u8d5b 2 \u6b21 (2019, 2020) \u3002\nPlayer 3 (Novak)  \u6ca1\u6709\u8d62\u5f97\uff0c\u56e0\u6b64\u4e0d\u5305\u542b\u5728\u7ed3\u679c\u96c6\u4e2d\u3002\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1783](https://leetcode-cn.com/problems/grand-slam-titles)", "[\u5927\u6ee1\u8d2f\u6570\u91cf](/solution/1700-1799/1783.Grand%20Slam%20Titles/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1783](https://leetcode.com/problems/grand-slam-titles)", "[Grand Slam Titles](/solution/1700-1799/1783.Grand%20Slam%20Titles/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1931", "frontend_question_id": "1778", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/shortest-path-in-a-hidden-grid", "url_en": "https://leetcode.com/problems/shortest-path-in-a-hidden-grid", "relative_path_cn": "/solution/1700-1799/1778.Shortest%20Path%20in%20a%20Hidden%20Grid/README.md", "relative_path_en": "/solution/1700-1799/1778.Shortest%20Path%20in%20a%20Hidden%20Grid/README_EN.md", "title_cn": "", "title_en": "Shortest Path in a Hidden Grid", "question_title_slug": "shortest-path-in-a-hidden-grid", "content_en": "

This is an interactive problem.

\n\n

There is a robot in a hidden grid, and you are trying to get it from its starting cell to the target cell in this grid. The grid is of size m x n, and each cell in the grid is either empty or blocked. It is guaranteed that the starting cell and the target cell are different, and neither of them is blocked.

\n\n

You want to find the minimum distance to the target cell. However, you do not know the grid's dimensions, the starting cell, nor the target cell. You are only allowed to ask queries to the GridMaster object.

\n\n

Thr GridMaster class has the following functions:

\n\n
    \n\t
  • boolean canMove(char direction) Returns true if the robot can move in that direction. Otherwise, it returns false.
  • \n\t
  • void move(char direction) Moves the robot in that direction. If this move would move the robot to a blocked cell or off the grid, the move will be ignored, and the robot will remain in the same position.
  • \n\t
  • boolean isTarget() Returns true if the robot is currently on the target cell. Otherwise, it returns false.
  • \n
\n\n

Note that direction in the above functions should be a character from {'U','D','L','R'}, representing the directions up, down, left, and right, respectively.

\n\n

Return the minimum distance between the robot's initial starting cell and the target cell. If there is no valid path between the cells, return -1.

\n\n

Custom testing:

\n\n

The test input is read as a 2D matrix grid of size m x n where:

\n\n
    \n\t
  • grid[i][j] == -1 indicates that the robot is in cell (i, j) (the starting cell).
  • \n\t
  • grid[i][j] == 0 indicates that the cell (i, j) is blocked.
  • \n\t
  • grid[i][j] == 1 indicates that the cell (i, j) is empty.
  • \n\t
  • grid[i][j] == 2 indicates that the cell (i, j) is the target cell.
  • \n
\n\n

There is exactly one -1 and 2 in grid. Remember that you will not have this information in your code.

\n\n

 

\n

Example 1:

\n\n
\nInput: grid = [[1,2],[-1,0]]\nOutput: 2\nExplanation: One possible interaction is described below:\nThe robot is initially standing on cell (1, 0), denoted by the -1.\n- master.canMove('U') returns true.\n- master.canMove('D') returns false.\n- master.canMove('L') returns false.\n- master.canMove('R') returns false.\n- master.move('U') moves the robot to the cell (0, 0).\n- master.isTarget() returns false.\n- master.canMove('U') returns false.\n- master.canMove('D') returns true.\n- master.canMove('L') returns false.\n- master.canMove('R') returns true.\n- master.move('R') moves the robot to the cell (0, 1).\n- master.isTarget() returns true. \nWe now know that the target is the cell (0, 1), and the shortest path to the target cell is 2.\n
\n\n

Example 2:

\n\n
\nInput: grid = [[0,0,-1],[1,1,1],[2,0,0]]\nOutput: 4\nExplanation: The minimum distance between the robot and the target cell is 4.
\n\n

Example 3:

\n\n
\nInput: grid = [[-1,0],[0,2]]\nOutput: -1\nExplanation: There is no path from the robot to the target cell.
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n, m <= 500
  • \n\t
  • m == grid.length
  • \n\t
  • n == grid[i].length
  • \n\t
  • grid[i][j] is either -1, 0, 1, or 2.
  • \n\t
  • There is exactly one -1 in grid.
  • \n\t
  • There is exactly one 2 in grid.
  • \n
\n", "content_cn": null, "tags_en": ["Depth-first Search", "Breadth-first Search", "Graph"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * // This is the GridMaster's API interface.\n * // You should not implement it, or speculate about its implementation\n * class GridMaster {\n * public:\n * bool canMove(char direction);\n * void move(char direction);\n * boolean isTarget();\n * };\n */\n\nclass Solution {\npublic:\n int findShortestPath(GridMaster &master) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * // This is the GridMaster's API interface.\n * // You should not implement it, or speculate about its implementation\n * class GridMaster {\n * boolean canMove(char direction);\n * void move(char direction);\n * boolean isTarget();\n * }\n */\n\nclass Solution {\n public int findShortestPath(GridMaster master) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# \"\"\"\n# This is GridMaster's API interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class GridMaster(object):\n# def canMove(self, direction):\n# \"\"\"\n# :type direction: str\n# :rtype bool\n# \"\"\"\n#\n# def move(self, direction):\n# \"\"\"\n# :type direction: str\n# \"\"\"\n#\n# def isTarget(self):\n# \"\"\"\n# :rtype bool\n# \"\"\"\n#\n\nclass Solution(object):\n def findShortestPath(self, master):\n \"\"\"\n :type master: GridMaster\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# \"\"\"\n# This is GridMaster's API interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class GridMaster(object):\n# def canMove(self, direction: str) -> bool:\n# \n#\n# def move(self, direction: str) -> bool:\n# \n#\n# def isTarget(self) -> None:\n# \n#\n\nclass Solution(object):\n def findShortestPath(self, master: 'GridMaster') -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * // This is the GridMaster's API interface.\n * // You should not implement it, or speculate about its implementation\n * class GridMaster {\n * bool canMove(char direction);\n * void move(char direction);\n * bool isTarget();\n * };\n */\n\nclass Solution {\n public void FindShortestPath(GridMaster master) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // This is the GridMaster's API interface.\n * // You should not implement it, or speculate about its implementation\n * function GridMaster() {\n *\n * @param {character} direction\n * @return {boolean}\n * this.canMove = function(direction) {\n * ...\n * };\n * @param {character} direction\n * @return {void}\n * this.move = function(direction) {\n * ...\n * };\n * @return {boolean}\n * this.isTarget = function() {\n * ...\n * };\n * };\n */\n\n/**\n * @param {GridMaster} master\n * @return {integer}\n */\nvar findShortestPath = function(master) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * // This is the GridMaster's API interface.\n * // You should not implement it, or speculate about its implementation\n * class GridMaster {\n * public func canMove(direction: Character) -> Bool {}\n * public func move(direction: Character) {}\n * public func isTarget() -> Bool {}\n * }\n */\n\nclass Solution {\n func findShortestPath( _ master: gridMaster) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * // This is the master's API interface.\n * // You should not implement it, or speculate about its implementation\n * function gridMaster() {\n *\n * @param {gridMaster} master\n * @return {boolean}\n * this.canMove = function(direction) {\n * ...\n * };\n * @return {void}\n * this.move = function(direction) {\n * ...\n * };\n * @return {boolean}\n * this.isTarget = function() {\n * ...\n * };\n * };\n */\n\n/**\n * @param {gridMaster} master\n * @return {integer}\n */\nvar findShortestPath = function(master) {\n \n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1778](https://leetcode-cn.com/problems/shortest-path-in-a-hidden-grid)", "[Shortest Path in a Hidden Grid](/solution/1700-1799/1778.Shortest%20Path%20in%20a%20Hidden%20Grid/README_EN.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u56fe`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1778](https://leetcode.com/problems/shortest-path-in-a-hidden-grid)", "[Shortest Path in a Hidden Grid](/solution/1700-1799/1778.Shortest%20Path%20in%20a%20Hidden%20Grid/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`,`Graph`", "Medium", "\ud83d\udd12"]}, {"question_id": "1930", "frontend_question_id": "1798", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-number-of-consecutive-values-you-can-make", "url_en": "https://leetcode.com/problems/maximum-number-of-consecutive-values-you-can-make", "relative_path_cn": "/solution/1700-1799/1798.Maximum%20Number%20of%20Consecutive%20Values%20You%20Can%20Make/README.md", "relative_path_en": "/solution/1700-1799/1798.Maximum%20Number%20of%20Consecutive%20Values%20You%20Can%20Make/README_EN.md", "title_cn": "\u4f60\u80fd\u6784\u9020\u51fa\u8fde\u7eed\u503c\u7684\u6700\u5927\u6570\u76ee", "title_en": "Maximum Number of Consecutive Values You Can Make", "question_title_slug": "maximum-number-of-consecutive-values-you-can-make", "content_en": "

You are given an integer array coins of length n which represents the n coins that you own. The value of the ith coin is coins[i]. You can make some value x if you can choose some of your n coins such that their values sum up to x.

\n\n

Return the maximum number of consecutive integer values that you can make with your coins starting from and including 0.

\n\n

Note that you may have multiple coins of the same value.

\n\n

 

\n

Example 1:

\n\n
\nInput: coins = [1,3]\nOutput: 2\nExplanation: You can make the following values:\n- 0: take []\n- 1: take [1]\nYou can make 2 consecutive integer values starting from 0.
\n\n

Example 2:

\n\n
\nInput: coins = [1,1,1,4]\nOutput: 8\nExplanation: You can make the following values:\n- 0: take []\n- 1: take [1]\n- 2: take [1,1]\n- 3: take [1,1,1]\n- 4: take [4]\n- 5: take [4,1]\n- 6: take [4,1,1]\n- 7: take [4,1,1,1]\nYou can make 8 consecutive integer values starting from 0.
\n\n

Example 3:

\n\n
\nInput: nums = [1,4,10,3,1]\nOutput: 20
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • coins.length == n
  • \n\t
  • 1 <= n <= 4 * 104
  • \n\t
  • 1 <= coins[i] <= 4 * 104
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u4e3a n\u00a0\u7684\u6574\u6570\u6570\u7ec4\u00a0coins\u00a0\uff0c\u5b83\u4ee3\u8868\u4f60\u62e5\u6709\u7684\u00a0n\u00a0\u4e2a\u786c\u5e01\u3002\u7b2c\u00a0i\u00a0\u4e2a\u786c\u5e01\u7684\u503c\u4e3a\u00a0coins[i]\u00a0\u3002\u5982\u679c\u4f60\u4ece\u8fd9\u4e9b\u786c\u5e01\u4e2d\u9009\u51fa\u4e00\u90e8\u5206\u786c\u5e01\uff0c\u5b83\u4eec\u7684\u548c\u4e3a\u00a0x\u00a0\uff0c\u90a3\u4e48\u79f0\uff0c\u4f60\u53ef\u4ee5\u00a0\u6784\u9020\u00a0\u51fa\u00a0x\u00a0\u3002

\n\n

\u8bf7\u8fd4\u56de\u4ece 0\u00a0\u5f00\u59cb\uff08\u5305\u62ec\u00a00\u00a0\uff09\uff0c\u4f60\u6700\u591a\u80fd\u00a0\u6784\u9020\u00a0\u51fa\u591a\u5c11\u4e2a\u8fde\u7eed\u6574\u6570\u3002

\n\n

\u4f60\u53ef\u80fd\u6709\u591a\u4e2a\u76f8\u540c\u503c\u7684\u786c\u5e01\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1acoins = [1,3]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u5f97\u5230\u4ee5\u4e0b\u8fd9\u4e9b\u503c\uff1a\n- 0\uff1a\u4ec0\u4e48\u90fd\u4e0d\u53d6 []\n- 1\uff1a\u53d6 [1]\n\u4ece 0 \u5f00\u59cb\uff0c\u4f60\u53ef\u4ee5\u6784\u9020\u51fa 2 \u4e2a\u8fde\u7eed\u6574\u6570\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1acoins = [1,1,1,4]\n\u8f93\u51fa\uff1a8\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u5f97\u5230\u4ee5\u4e0b\u8fd9\u4e9b\u503c\uff1a\n- 0\uff1a\u4ec0\u4e48\u90fd\u4e0d\u53d6 []\n- 1\uff1a\u53d6 [1]\n- 2\uff1a\u53d6 [1,1]\n- 3\uff1a\u53d6 [1,1,1]\n- 4\uff1a\u53d6 [4]\n- 5\uff1a\u53d6 [4,1]\n- 6\uff1a\u53d6 [4,1,1]\n- 7\uff1a\u53d6 [4,1,1,1]\n\u4ece 0 \u5f00\u59cb\uff0c\u4f60\u53ef\u4ee5\u6784\u9020\u51fa 8 \u4e2a\u8fde\u7eed\u6574\u6570\u3002
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [1,4,10,3,1]\n\u8f93\u51fa\uff1a20
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • coins.length == n
  • \n\t
  • 1 <= n <= 4 * 104
  • \n\t
  • 1 <= coins[i] <= 4 * 104
  • \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int getMaximumConsecutive(vector& coins) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int getMaximumConsecutive(int[] coins) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getMaximumConsecutive(self, coins):\n \"\"\"\n :type coins: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getMaximumConsecutive(self, coins: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint getMaximumConsecutive(int* coins, int coinsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int GetMaximumConsecutive(int[] coins) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} coins\n * @return {number}\n */\nvar getMaximumConsecutive = function(coins) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} coins\n# @return {Integer}\ndef get_maximum_consecutive(coins)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getMaximumConsecutive(_ coins: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getMaximumConsecutive(coins []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getMaximumConsecutive(coins: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getMaximumConsecutive(coins: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_maximum_consecutive(coins: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $coins\n * @return Integer\n */\n function getMaximumConsecutive($coins) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getMaximumConsecutive(coins: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-maximum-consecutive coins)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1798](https://leetcode-cn.com/problems/maximum-number-of-consecutive-values-you-can-make)", "[\u4f60\u80fd\u6784\u9020\u51fa\u8fde\u7eed\u503c\u7684\u6700\u5927\u6570\u76ee](/solution/1700-1799/1798.Maximum%20Number%20of%20Consecutive%20Values%20You%20Can%20Make/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1798](https://leetcode.com/problems/maximum-number-of-consecutive-values-you-can-make)", "[Maximum Number of Consecutive Values You Can Make](/solution/1700-1799/1798.Maximum%20Number%20of%20Consecutive%20Values%20You%20Can%20Make/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1929", "frontend_question_id": "1802", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-value-at-a-given-index-in-a-bounded-array", "url_en": "https://leetcode.com/problems/maximum-value-at-a-given-index-in-a-bounded-array", "relative_path_cn": "/solution/1800-1899/1802.Maximum%20Value%20at%20a%20Given%20Index%20in%20a%20Bounded%20Array/README.md", "relative_path_en": "/solution/1800-1899/1802.Maximum%20Value%20at%20a%20Given%20Index%20in%20a%20Bounded%20Array/README_EN.md", "title_cn": "\u6709\u754c\u6570\u7ec4\u4e2d\u6307\u5b9a\u4e0b\u6807\u5904\u7684\u6700\u5927\u503c", "title_en": "Maximum Value at a Given Index in a Bounded Array", "question_title_slug": "maximum-value-at-a-given-index-in-a-bounded-array", "content_en": "

You are given three positive integers: n, index, and maxSum. You want to construct an array nums (0-indexed) that satisfies the following conditions:

\n\n
    \n\t
  • nums.length == n
  • \n\t
  • nums[i] is a positive integer where 0 <= i < n.
  • \n\t
  • abs(nums[i] - nums[i+1]) <= 1 where 0 <= i < n-1.
  • \n\t
  • The sum of all the elements of nums does not exceed maxSum.
  • \n\t
  • nums[index] is maximized.
  • \n
\n\n

Return nums[index] of the constructed array.

\n\n

Note that abs(x) equals x if x >= 0, and -x otherwise.

\n\n

 

\n

Example 1:

\n\n
\nInput: n = 4, index = 2,  maxSum = 6\nOutput: 2\nExplanation: nums = [1,2,2,1] is one array that satisfies all the conditions.\nThere are no arrays that satisfy all the conditions and have nums[2] == 3, so 2 is the maximum nums[2].\n
\n\n

Example 2:

\n\n
\nInput: n = 6, index = 1,  maxSum = 10\nOutput: 3\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= maxSum <= 109
  • \n\t
  • 0 <= index < n
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e09\u4e2a\u6b63\u6574\u6570 n\u3001index \u548c maxSum \u3002\u4f60\u9700\u8981\u6784\u9020\u4e00\u4e2a\u540c\u65f6\u6ee1\u8db3\u4e0b\u8ff0\u6240\u6709\u6761\u4ef6\u7684\u6570\u7ec4 nums\uff08\u4e0b\u6807 \u4ece 0 \u5f00\u59cb \u8ba1\u6570\uff09\uff1a

\n\n
    \n\t
  • nums.length == n
  • \n\t
  • nums[i] \u662f \u6b63\u6574\u6570 \uff0c\u5176\u4e2d 0 <= i < n
  • \n\t
  • abs(nums[i] - nums[i+1]) <= 1 \uff0c\u5176\u4e2d 0 <= i < n-1
  • \n\t
  • nums \u4e2d\u6240\u6709\u5143\u7d20\u4e4b\u548c\u4e0d\u8d85\u8fc7 maxSum
  • \n\t
  • nums[index] \u7684\u503c\u88ab \u6700\u5927\u5316
  • \n
\n\n

\u8fd4\u56de\u4f60\u6240\u6784\u9020\u7684\u6570\u7ec4\u4e2d\u7684 nums[index] \u3002

\n\n

\u6ce8\u610f\uff1aabs(x) \u7b49\u4e8e x \u7684\u524d\u63d0\u662f x >= 0 \uff1b\u5426\u5219\uff0cabs(x) \u7b49\u4e8e -x \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1an = 4, index = 2,  maxSum = 6\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6570\u7ec4 [1,1,2,1] \u548c [1,2,2,1] \u6ee1\u8db3\u6240\u6709\u6761\u4ef6\u3002\u4e0d\u5b58\u5728\u5176\u4ed6\u5728\u6307\u5b9a\u4e0b\u6807\u5904\u5177\u6709\u66f4\u5927\u503c\u7684\u6709\u6548\u6570\u7ec4\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1an = 6, index = 1,  maxSum = 10\n\u8f93\u51fa\uff1a3\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= maxSum <= 109
  • \n\t
  • 0 <= index < n
  • \n
\n", "tags_en": ["Greedy", "Binary Search"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxValue(int n, int index, int maxSum) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxValue(int n, int index, int maxSum) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxValue(self, n, index, maxSum):\n \"\"\"\n :type n: int\n :type index: int\n :type maxSum: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxValue(self, n: int, index: int, maxSum: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxValue(int n, int index, int maxSum){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxValue(int n, int index, int maxSum) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} index\n * @param {number} maxSum\n * @return {number}\n */\nvar maxValue = function(n, index, maxSum) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} index\n# @param {Integer} max_sum\n# @return {Integer}\ndef max_value(n, index, max_sum)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxValue(_ n: Int, _ index: Int, _ maxSum: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxValue(n int, index int, maxSum int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxValue(n: Int, index: Int, maxSum: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxValue(n: Int, index: Int, maxSum: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_value(n: i32, index: i32, max_sum: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $index\n * @param Integer $maxSum\n * @return Integer\n */\n function maxValue($n, $index, $maxSum) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxValue(n: number, index: number, maxSum: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-value n index maxSum)\n (-> exact-integer? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1802](https://leetcode-cn.com/problems/maximum-value-at-a-given-index-in-a-bounded-array)", "[\u6709\u754c\u6570\u7ec4\u4e2d\u6307\u5b9a\u4e0b\u6807\u5904\u7684\u6700\u5927\u503c](/solution/1800-1899/1802.Maximum%20Value%20at%20a%20Given%20Index%20in%20a%20Bounded%20Array/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1802](https://leetcode.com/problems/maximum-value-at-a-given-index-in-a-bounded-array)", "[Maximum Value at a Given Index in a Bounded Array](/solution/1800-1899/1802.Maximum%20Value%20at%20a%20Given%20Index%20in%20a%20Bounded%20Array/README_EN.md)", "`Greedy`,`Binary Search`", "Medium", ""]}, {"question_id": "1928", "frontend_question_id": "1801", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-orders-in-the-backlog", "url_en": "https://leetcode.com/problems/number-of-orders-in-the-backlog", "relative_path_cn": "/solution/1800-1899/1801.Number%20of%20Orders%20in%20the%20Backlog/README.md", "relative_path_en": "/solution/1800-1899/1801.Number%20of%20Orders%20in%20the%20Backlog/README_EN.md", "title_cn": "\u79ef\u538b\u8ba2\u5355\u4e2d\u7684\u8ba2\u5355\u603b\u6570", "title_en": "Number of Orders in the Backlog", "question_title_slug": "number-of-orders-in-the-backlog", "content_en": "

You are given a 2D integer array orders, where each orders[i] = [pricei, amounti, orderTypei] denotes that amounti orders have been placed of type orderTypei at the price pricei. The orderTypei is:

\r\n\r\n
    \r\n\t
  • 0 if it is a batch of buy orders, or
  • \r\n\t
  • 1 if it is a batch of sell orders.
  • \r\n
\r\n\r\n

Note that orders[i] represents a batch of amounti independent orders with the same price and order type. All orders represented by orders[i] will be placed before all orders represented by orders[i+1] for all valid i.

\r\n\r\n

There is a backlog that consists of orders that have not been executed. The backlog is initially empty. When an order is placed, the following happens:

\r\n\r\n
    \r\n\t
  • If the order is a buy order, you look at the sell order with the smallest price in the backlog. If that sell order's price is smaller than or equal to the current buy order's price, they will match and be executed, and that sell order will be removed from the backlog. Else, the buy order is added to the backlog.
  • \r\n\t
  • Vice versa, if the order is a sell order, you look at the buy order with the largest price in the backlog. If that buy order's price is larger than or equal to the current sell order's price, they will match and be executed, and that buy order will be removed from the backlog. Else, the sell order is added to the backlog.
  • \r\n
\r\n\r\n

Return the total amount of orders in the backlog after placing all the orders from the input. Since this number can be large, return it modulo 109 + 7.

\r\n\r\n

 

\r\n

Example 1:

\r\n\"\"\r\n
\r\nInput: orders = [[10,5,0],[15,2,1],[25,1,1],[30,4,0]]\r\nOutput: 6\r\nExplanation: Here is what happens with the orders:\r\n- 5 orders of type buy with price 10 are placed. There are no sell orders, so the 5 orders are added to the backlog.\r\n- 2 orders of type sell with price 15 are placed. There are no buy orders with prices larger than or equal to 15, so the 2 orders are added to the backlog.\r\n- 1 order of type sell with price 25 is placed. There are no buy orders with prices larger than or equal to 25 in the backlog, so this order is added to the backlog.\r\n- 4 orders of type buy with price 30 are placed. The first 2 orders are matched with the 2 sell orders of the least price, which is 15 and these 2 sell orders are removed from the backlog. The 3rd order is matched with the sell order of the least price, which is 25 and this sell order is removed from the backlog. Then, there are no more sell orders in the backlog, so the 4th order is added to the backlog.\r\nFinally, the backlog has 5 buy orders with price 10, and 1 buy order with price 30. So the total number of orders in the backlog is 6.\r\n
\r\n\r\n

Example 2:

\r\n\"\"\r\n
\r\nInput: orders = [[7,1000000000,1],[15,3,0],[5,999999995,0],[5,1,1]]\r\nOutput: 999999984\r\nExplanation: Here is what happens with the orders:\r\n- 109 orders of type sell with price 7 are placed. There are no buy orders, so the 109 orders are added to the backlog.\r\n- 3 orders of type buy with price 15 are placed. They are matched with the 3 sell orders with the least price which is 7, and those 3 sell orders are removed from the backlog.\r\n- 999999995 orders of type buy with price 5 are placed. The least price of a sell order is 7, so the 999999995 orders are added to the backlog.\r\n- 1 order of type sell with price 5 is placed. It is matched with the buy order of the highest price, which is 5, and that buy order is removed from the backlog.\r\nFinally, the backlog has (1000000000-3) sell orders with price 7, and (999999995-1) buy orders with price 5. So the total number of orders = 1999999991, which is equal to 999999984 % (109 + 7).\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= orders.length <= 105
  • \r\n\t
  • orders[i].length == 3
  • \r\n\t
  • 1 <= pricei, amounti <= 109
  • \r\n\t
  • orderTypei is either 0 or 1.
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u4e8c\u7ef4\u6574\u6570\u6570\u7ec4 orders \uff0c\u5176\u4e2d\u6bcf\u4e2a orders[i] = [pricei, amounti, orderTypei] \u8868\u793a\u6709 amounti \u7b14\u7c7b\u578b\u4e3a\u00a0orderTypei \u3001\u4ef7\u683c\u4e3a\u00a0pricei \u7684\u8ba2\u5355\u3002

\n\n

\u8ba2\u5355\u7c7b\u578b orderTypei \u53ef\u4ee5\u5206\u4e3a\u4e24\u79cd\uff1a

\n\n
    \n\t
  • 0 \u8868\u793a\u8fd9\u662f\u4e00\u6279\u91c7\u8d2d\u8ba2\u5355 buy
  • \n\t
  • 1 \u8868\u793a\u8fd9\u662f\u4e00\u6279\u9500\u552e\u8ba2\u5355 sell
  • \n
\n\n

\u6ce8\u610f\uff0corders[i] \u8868\u793a\u4e00\u6279\u5171\u8ba1 amounti \u7b14\u7684\u72ec\u7acb\u8ba2\u5355\uff0c\u8fd9\u4e9b\u8ba2\u5355\u7684\u4ef7\u683c\u548c\u7c7b\u578b\u76f8\u540c\u3002\u5bf9\u4e8e\u6240\u6709\u6709\u6548\u7684 i \uff0c\u7531 orders[i] \u8868\u793a\u7684\u6240\u6709\u8ba2\u5355\u63d0\u4ea4\u65f6\u95f4\u5747\u65e9\u4e8e orders[i+1] \u8868\u793a\u7684\u6240\u6709\u8ba2\u5355\u3002

\n\n

\u5b58\u5728\u7531\u672a\u6267\u884c\u8ba2\u5355\u7ec4\u6210\u7684 \u79ef\u538b\u8ba2\u5355 \u3002\u79ef\u538b\u8ba2\u5355\u6700\u521d\u662f\u7a7a\u7684\u3002\u63d0\u4ea4\u8ba2\u5355\u65f6\uff0c\u4f1a\u53d1\u751f\u4ee5\u4e0b\u60c5\u51b5\uff1a

\n\n
    \n\t
  • \u5982\u679c\u8be5\u8ba2\u5355\u662f\u4e00\u7b14\u91c7\u8d2d\u8ba2\u5355 buy \uff0c\u5219\u53ef\u4ee5\u67e5\u770b\u79ef\u538b\u8ba2\u5355\u4e2d\u4ef7\u683c \u6700\u4f4e \u7684\u9500\u552e\u8ba2\u5355 sell \u3002\u5982\u679c\u8be5\u9500\u552e\u8ba2\u5355 sell \u7684\u4ef7\u683c \u4f4e\u4e8e\u6216\u7b49\u4e8e \u5f53\u524d\u91c7\u8d2d\u8ba2\u5355 buy \u7684\u4ef7\u683c\uff0c\u5219\u5339\u914d\u5e76\u6267\u884c\u8fd9\u4e24\u7b14\u8ba2\u5355\uff0c\u5e76\u5c06\u9500\u552e\u8ba2\u5355 sell \u4ece\u79ef\u538b\u8ba2\u5355\u4e2d\u5220\u9664\u3002\u5426\u5219\uff0c\u91c7\u8d2d\u8ba2\u5355 buy \u5c06\u4f1a\u6dfb\u52a0\u5230\u79ef\u538b\u8ba2\u5355\u4e2d\u3002
  • \n\t
  • \u53cd\u4e4b\u4ea6\u7136\uff0c\u5982\u679c\u8be5\u8ba2\u5355\u662f\u4e00\u7b14\u9500\u552e\u8ba2\u5355 sell \uff0c\u5219\u53ef\u4ee5\u67e5\u770b\u79ef\u538b\u8ba2\u5355\u4e2d\u4ef7\u683c \u6700\u9ad8 \u7684\u91c7\u8d2d\u8ba2\u5355 buy \u3002\u5982\u679c\u8be5\u91c7\u8d2d\u8ba2\u5355 buy \u7684\u4ef7\u683c \u9ad8\u4e8e\u6216\u7b49\u4e8e \u5f53\u524d\u9500\u552e\u8ba2\u5355 sell \u7684\u4ef7\u683c\uff0c\u5219\u5339\u914d\u5e76\u6267\u884c\u8fd9\u4e24\u7b14\u8ba2\u5355\uff0c\u5e76\u5c06\u91c7\u8d2d\u8ba2\u5355 buy \u4ece\u79ef\u538b\u8ba2\u5355\u4e2d\u5220\u9664\u3002\u5426\u5219\uff0c\u9500\u552e\u8ba2\u5355 sell \u5c06\u4f1a\u6dfb\u52a0\u5230\u79ef\u538b\u8ba2\u5355\u4e2d\u3002
  • \n
\n\n

\u8f93\u5165\u6240\u6709\u8ba2\u5355\u540e\uff0c\u8fd4\u56de\u79ef\u538b\u8ba2\u5355\u4e2d\u7684 \u8ba2\u5355\u603b\u6570 \u3002\u7531\u4e8e\u6570\u5b57\u53ef\u80fd\u5f88\u5927\uff0c\u6240\u4ee5\u9700\u8981\u8fd4\u56de\u5bf9 109 + 7 \u53d6\u4f59\u7684\u7ed3\u679c\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1aorders = [[10,5,0],[15,2,1],[25,1,1],[30,4,0]]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u8f93\u5165\u8ba2\u5355\u540e\u4f1a\u53d1\u751f\u4e0b\u8ff0\u60c5\u51b5\uff1a\n- \u63d0\u4ea4 5 \u7b14\u91c7\u8d2d\u8ba2\u5355\uff0c\u4ef7\u683c\u4e3a 10 \u3002\u6ca1\u6709\u9500\u552e\u8ba2\u5355\uff0c\u6240\u4ee5\u8fd9 5 \u7b14\u8ba2\u5355\u6dfb\u52a0\u5230\u79ef\u538b\u8ba2\u5355\u4e2d\u3002\n- \u63d0\u4ea4 2 \u7b14\u9500\u552e\u8ba2\u5355\uff0c\u4ef7\u683c\u4e3a 15 \u3002\u6ca1\u6709\u91c7\u8d2d\u8ba2\u5355\u7684\u4ef7\u683c\u5927\u4e8e\u6216\u7b49\u4e8e 15 \uff0c\u6240\u4ee5\u8fd9 2 \u7b14\u8ba2\u5355\u6dfb\u52a0\u5230\u79ef\u538b\u8ba2\u5355\u4e2d\u3002\n- \u63d0\u4ea4 1 \u7b14\u9500\u552e\u8ba2\u5355\uff0c\u4ef7\u683c\u4e3a 25 \u3002\u6ca1\u6709\u91c7\u8d2d\u8ba2\u5355\u7684\u4ef7\u683c\u5927\u4e8e\u6216\u7b49\u4e8e 25 \uff0c\u6240\u4ee5\u8fd9 1 \u7b14\u8ba2\u5355\u6dfb\u52a0\u5230\u79ef\u538b\u8ba2\u5355\u4e2d\u3002\n- \u63d0\u4ea4 4 \u7b14\u91c7\u8d2d\u8ba2\u5355\uff0c\u4ef7\u683c\u4e3a 30 \u3002\u524d 2 \u7b14\u91c7\u8d2d\u8ba2\u5355\u4e0e\u4ef7\u683c\u6700\u4f4e\uff08\u4ef7\u683c\u4e3a 15\uff09\u7684 2 \u7b14\u9500\u552e\u8ba2\u5355\u5339\u914d\uff0c\u4ece\u79ef\u538b\u8ba2\u5355\u4e2d\u5220\u9664\u8fd9 2 \u7b14\u9500\u552e\u8ba2\u5355\u3002\u7b2c 3 \u7b14\u91c7\u8d2d\u8ba2\u5355\u4e0e\u4ef7\u683c\u6700\u4f4e\u7684 1 \u7b14\u9500\u552e\u8ba2\u5355\u5339\u914d\uff0c\u9500\u552e\u8ba2\u5355\u4ef7\u683c\u4e3a 25 \uff0c\u4ece\u79ef\u538b\u8ba2\u5355\u4e2d\u5220\u9664\u8fd9 1 \u7b14\u9500\u552e\u8ba2\u5355\u3002\u79ef\u538b\u8ba2\u5355\u4e2d\u4e0d\u5b58\u5728\u66f4\u591a\u9500\u552e\u8ba2\u5355\uff0c\u6240\u4ee5\u7b2c 4 \u7b14\u91c7\u8d2d\u8ba2\u5355\u9700\u8981\u6dfb\u52a0\u5230\u79ef\u538b\u8ba2\u5355\u4e2d\u3002\n\u6700\u7ec8\uff0c\u79ef\u538b\u8ba2\u5355\u4e2d\u6709 5 \u7b14\u4ef7\u683c\u4e3a 10 \u7684\u91c7\u8d2d\u8ba2\u5355\uff0c\u548c 1 \u7b14\u4ef7\u683c\u4e3a 30 \u7684\u91c7\u8d2d\u8ba2\u5355\u3002\u6240\u4ee5\u79ef\u538b\u8ba2\u5355\u4e2d\u7684\u8ba2\u5355\u603b\u6570\u4e3a 6 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1aorders = [[7,1000000000,1],[15,3,0],[5,999999995,0],[5,1,1]]\n\u8f93\u51fa\uff1a999999984\n\u89e3\u91ca\uff1a\u8f93\u5165\u8ba2\u5355\u540e\u4f1a\u53d1\u751f\u4e0b\u8ff0\u60c5\u51b5\uff1a\n- \u63d0\u4ea4 109 \u7b14\u9500\u552e\u8ba2\u5355\uff0c\u4ef7\u683c\u4e3a 7 \u3002\u6ca1\u6709\u91c7\u8d2d\u8ba2\u5355\uff0c\u6240\u4ee5\u8fd9 109 \u7b14\u8ba2\u5355\u6dfb\u52a0\u5230\u79ef\u538b\u8ba2\u5355\u4e2d\u3002\n- \u63d0\u4ea4 3 \u7b14\u91c7\u8d2d\u8ba2\u5355\uff0c\u4ef7\u683c\u4e3a 15 \u3002\u8fd9\u4e9b\u91c7\u8d2d\u8ba2\u5355\u4e0e\u4ef7\u683c\u6700\u4f4e\uff08\u4ef7\u683c\u4e3a 7 \uff09\u7684 3 \u7b14\u9500\u552e\u8ba2\u5355\u5339\u914d\uff0c\u4ece\u79ef\u538b\u8ba2\u5355\u4e2d\u5220\u9664\u8fd9 3 \u7b14\u9500\u552e\u8ba2\u5355\u3002\n- \u63d0\u4ea4 999999995 \u7b14\u91c7\u8d2d\u8ba2\u5355\uff0c\u4ef7\u683c\u4e3a 5 \u3002\u9500\u552e\u8ba2\u5355\u7684\u6700\u4f4e\u4ef7\u4e3a 7 \uff0c\u6240\u4ee5\u8fd9 999999995 \u7b14\u8ba2\u5355\u6dfb\u52a0\u5230\u79ef\u538b\u8ba2\u5355\u4e2d\u3002\n- \u63d0\u4ea4 1 \u7b14\u9500\u552e\u8ba2\u5355\uff0c\u4ef7\u683c\u4e3a 5 \u3002\u8fd9\u7b14\u9500\u552e\u8ba2\u5355\u4e0e\u4ef7\u683c\u6700\u9ad8\uff08\u4ef7\u683c\u4e3a 5 \uff09\u7684 1 \u7b14\u91c7\u8d2d\u8ba2\u5355\u5339\u914d\uff0c\u4ece\u79ef\u538b\u8ba2\u5355\u4e2d\u5220\u9664\u8fd9 1 \u7b14\u91c7\u8d2d\u8ba2\u5355\u3002\n\u6700\u7ec8\uff0c\u79ef\u538b\u8ba2\u5355\u4e2d\u6709 (1000000000-3) \u7b14\u4ef7\u683c\u4e3a 7 \u7684\u9500\u552e\u8ba2\u5355\uff0c\u548c (999999995-1) \u7b14\u4ef7\u683c\u4e3a 5 \u7684\u91c7\u8d2d\u8ba2\u5355\u3002\u6240\u4ee5\u79ef\u538b\u8ba2\u5355\u4e2d\u7684\u8ba2\u5355\u603b\u6570\u4e3a 1999999991 \uff0c\u7b49\u4e8e 999999984 % (109 + 7) \u3002
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= orders.length <= 105
  • \n\t
  • orders[i].length == 3
  • \n\t
  • 1 <= pricei, amounti <= 109
  • \n\t
  • orderTypei \u4e3a 0 \u6216 1
  • \n
\n", "tags_en": ["Heap", "Greedy"], "tags_cn": ["\u5806", "\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int getNumberOfBacklogOrders(vector>& orders) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int getNumberOfBacklogOrders(int[][] orders) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getNumberOfBacklogOrders(self, orders):\n \"\"\"\n :type orders: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getNumberOfBacklogOrders(self, orders: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint getNumberOfBacklogOrders(int** orders, int ordersSize, int* ordersColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int GetNumberOfBacklogOrders(int[][] orders) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} orders\n * @return {number}\n */\nvar getNumberOfBacklogOrders = function(orders) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} orders\n# @return {Integer}\ndef get_number_of_backlog_orders(orders)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getNumberOfBacklogOrders(_ orders: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getNumberOfBacklogOrders(orders [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getNumberOfBacklogOrders(orders: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getNumberOfBacklogOrders(orders: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_number_of_backlog_orders(orders: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $orders\n * @return Integer\n */\n function getNumberOfBacklogOrders($orders) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getNumberOfBacklogOrders(orders: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-number-of-backlog-orders orders)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1801](https://leetcode-cn.com/problems/number-of-orders-in-the-backlog)", "[\u79ef\u538b\u8ba2\u5355\u4e2d\u7684\u8ba2\u5355\u603b\u6570](/solution/1800-1899/1801.Number%20of%20Orders%20in%20the%20Backlog/README.md)", "`\u5806`,`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1801](https://leetcode.com/problems/number-of-orders-in-the-backlog)", "[Number of Orders in the Backlog](/solution/1800-1899/1801.Number%20of%20Orders%20in%20the%20Backlog/README_EN.md)", "`Heap`,`Greedy`", "Medium", ""]}, {"question_id": "1927", "frontend_question_id": "1800", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-ascending-subarray-sum", "url_en": "https://leetcode.com/problems/maximum-ascending-subarray-sum", "relative_path_cn": "/solution/1800-1899/1800.Maximum%20Ascending%20Subarray%20Sum/README.md", "relative_path_en": "/solution/1800-1899/1800.Maximum%20Ascending%20Subarray%20Sum/README_EN.md", "title_cn": "\u6700\u5927\u5347\u5e8f\u5b50\u6570\u7ec4\u548c", "title_en": "Maximum Ascending Subarray Sum", "question_title_slug": "maximum-ascending-subarray-sum", "content_en": "

Given an array of positive integers nums, return the maximum possible sum of an ascending subarray in nums.

\n\n

A subarray is defined as a contiguous sequence of numbers in an array.

\n\n

A subarray [numsl, numsl+1, ..., numsr-1, numsr] is ascending if for all i where l <= i < r, numsi < numsi+1. Note that a subarray of size 1 is ascending.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [10,20,30,5,10,50]\nOutput: 65\nExplanation: [5,10,50] is the ascending subarray with the maximum sum of 65.\n
\n\n

Example 2:

\n\n
\nInput: nums = [10,20,30,40,50]\nOutput: 150\nExplanation: [10,20,30,40,50] is the ascending subarray with the maximum sum of 150.\n
\n\n

Example 3:

\n\n
\nInput: nums = [12,17,15,13,10,11,12]\nOutput: 33\nExplanation: [10,11,12] is the ascending subarray with the maximum sum of 33.\n
\n\n

Example 4:

\n\n
\nInput: nums = [100,10,1]\nOutput: 100\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 100
  • \n\t
  • 1 <= nums[i] <= 100
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6b63\u6574\u6570\u7ec4\u6210\u7684\u6570\u7ec4 nums \uff0c\u8fd4\u56de nums \u4e2d\u4e00\u4e2a \u5347\u5e8f \u5b50\u6570\u7ec4\u7684\u6700\u5927\u53ef\u80fd\u5143\u7d20\u548c\u3002

\n\n

\u5b50\u6570\u7ec4\u662f\u6570\u7ec4\u4e2d\u7684\u4e00\u4e2a\u8fde\u7eed\u6570\u5b57\u5e8f\u5217\u3002

\n\n

\u5df2\u77e5\u5b50\u6570\u7ec4 [numsl, numsl+1, ..., numsr-1, numsr] \uff0c\u82e5\u5bf9\u6240\u6709 i\uff08l <= i < r\uff09\uff0cnumsi < numsi+1 \u90fd\u6210\u7acb\uff0c\u5219\u79f0\u8fd9\u4e00\u5b50\u6570\u7ec4\u4e3a \u5347\u5e8f \u5b50\u6570\u7ec4\u3002\u6ce8\u610f\uff0c\u5927\u5c0f\u4e3a 1 \u7684\u5b50\u6570\u7ec4\u4e5f\u89c6\u4f5c \u5347\u5e8f \u5b50\u6570\u7ec4\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [10,20,30,5,10,50]\n\u8f93\u51fa\uff1a65\n\u89e3\u91ca\uff1a[5,10,50] \u662f\u5143\u7d20\u548c\u6700\u5927\u7684\u5347\u5e8f\u5b50\u6570\u7ec4\uff0c\u6700\u5927\u5143\u7d20\u548c\u4e3a 65 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [10,20,30,40,50]\n\u8f93\u51fa\uff1a150\n\u89e3\u91ca\uff1a[10,20,30,40,50] \u662f\u5143\u7d20\u548c\u6700\u5927\u7684\u5347\u5e8f\u5b50\u6570\u7ec4\uff0c\u6700\u5927\u5143\u7d20\u548c\u4e3a 150 \u3002 \n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [12,17,15,13,10,11,12]\n\u8f93\u51fa\uff1a33\n\u89e3\u91ca\uff1a[10,11,12] \u662f\u5143\u7d20\u548c\u6700\u5927\u7684\u5347\u5e8f\u5b50\u6570\u7ec4\uff0c\u6700\u5927\u5143\u7d20\u548c\u4e3a 33 \u3002 \n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [100,10,1]\n\u8f93\u51fa\uff1a100\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 100
  • \n\t
  • 1 <= nums[i] <= 100
  • \n
\n", "tags_en": ["Two Pointers"], "tags_cn": ["\u53cc\u6307\u9488"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxAscendingSum(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxAscendingSum(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxAscendingSum(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxAscendingSum(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxAscendingSum(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxAscendingSum(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar maxAscendingSum = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef max_ascending_sum(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxAscendingSum(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxAscendingSum(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxAscendingSum(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxAscendingSum(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_ascending_sum(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function maxAscendingSum($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxAscendingSum(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-ascending-sum nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1800](https://leetcode-cn.com/problems/maximum-ascending-subarray-sum)", "[\u6700\u5927\u5347\u5e8f\u5b50\u6570\u7ec4\u548c](/solution/1800-1899/1800.Maximum%20Ascending%20Subarray%20Sum/README.md)", "`\u53cc\u6307\u9488`", "\u7b80\u5355", ""], "md_table_row_en": ["[1800](https://leetcode.com/problems/maximum-ascending-subarray-sum)", "[Maximum Ascending Subarray Sum](/solution/1800-1899/1800.Maximum%20Ascending%20Subarray%20Sum/README_EN.md)", "`Two Pointers`", "Easy", ""]}, {"question_id": "1926", "frontend_question_id": "1777", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/products-price-for-each-store", "url_en": "https://leetcode.com/problems/products-price-for-each-store", "relative_path_cn": "/solution/1700-1799/1777.Product%27s%20Price%20for%20Each%20Store/README.md", "relative_path_en": "/solution/1700-1799/1777.Product%27s%20Price%20for%20Each%20Store/README_EN.md", "title_cn": "\u6bcf\u5bb6\u5546\u5e97\u7684\u4ea7\u54c1\u4ef7\u683c", "title_en": "Product's Price for Each Store", "question_title_slug": "products-price-for-each-store", "content_en": "

Table: Products

\r\n\r\n
\r\n+-------------+---------+\r\n| Column Name | Type    |\r\n+-------------+---------+\r\n| product_id  | int     |\r\n| store       | enum    |\r\n| price       | int     |\r\n+-------------+---------+\r\n(product_id,store) is the primary key for this table.\r\nstore is an ENUM of type ('store1', 'store2', 'store3') where each represents the store this product is available at.\r\nprice is the price of the product at this store.
\r\n\r\n

 

\r\n\r\n

Write an SQL query to find the price of each product in each store.

\r\n\r\n

Return the result table in any order.

\r\n\r\n

The query result format is in the following example:

\r\n\r\n

 

\r\n\r\n
\r\nProducts table:\r\n+-------------+--------+-------+\r\n| product_id  | store  | price |\r\n+-------------+--------+-------+\r\n| 0           | store1 | 95    |\r\n| 0           | store3 | 105   |\r\n| 0           | store2 | 100   |\r\n| 1           | store1 | 70    |\r\n| 1           | store3 | 80    |\r\n+-------------+--------+-------+\r\nResult table:\r\n+-------------+--------+--------+--------+\r\n| product_id  | store1 | store2 | store3 |\r\n+-------------+--------+--------+--------+\r\n| 0           | 95     | 100    | 105    |\r\n| 1           | 70     | null   | 80     |\r\n+-------------+--------+--------+--------+\r\nProduct 0 price's are 95 for store1, 100 for store2 and, 105 for store3.\r\nProduct 1 price's are 70 for store1, 80 for store3 and, it's not sold in store2.\r\n
", "content_cn": "

\u8868\uff1aProducts

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| product_id  | int     |\n| store       | enum    |\n| price       | int     |\n+-------------+---------+\n(product_id,store) \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\u3002\nstore \u5b57\u6bb5\u662f\u679a\u4e3e\u7c7b\u578b\uff0c\u5b83\u7684\u53d6\u503c\u4e3a\u4ee5\u4e0b\u4e09\u79cd ('store1', 'store2', 'store3') \u3002\nprice \u662f\u8be5\u5546\u54c1\u5728\u8fd9\u5bb6\u5546\u5e97\u4e2d\u7684\u4ef7\u683c\u3002
\n\n

\u00a0

\n\n

\u5199\u51fa\u4e00\u4e2a SQL \u67e5\u8be2\u8bed\u53e5\uff0c\u67e5\u627e\u6bcf\u79cd\u4ea7\u54c1\u5728\u5404\u4e2a\u5546\u5e97\u4e2d\u7684\u4ef7\u683c\u3002

\n\n

\u53ef\u4ee5\u4ee5 \u4efb\u4f55\u987a\u5e8f \u8f93\u51fa\u7ed3\u679c\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a\uff1a

\n\n
\nProducts \u8868\uff1a\n+-------------+--------+-------+\n| product_id  | store  | price |\n+-------------+--------+-------+\n| 0           | store1 | 95    |\n| 0           | store3 | 105   |\n| 0           | store2 | 100   |\n| 1           | store1 | 70    |\n| 1           | store3 | 80    |\n+-------------+--------+-------+\nResult \u8868\uff1a\n+-------------+--------+--------+--------+\n| product_id  | store1 | store2 | store3 |\n+-------------+--------+--------+--------+\n| 0           | 95     | 100    | 105    |\n| 1           | 70     | null   | 80     |\n+-------------+--------+--------+--------+\n\u4ea7\u54c1 0 \u7684\u4ef7\u683c\u5728\u5546\u5e97 1 \u4e3a 95 \uff0c\u5546\u5e97 2 \u4e3a 100 \uff0c\u5546\u5e97 3 \u4e3a 105 \u3002\n\u4ea7\u54c1 1 \u7684\u4ef7\u683c\u5728\u5546\u5e97 1 \u4e3a 70 \uff0c\u5546\u5e97 3 \u7684\u4ea7\u54c1 1 \u4ef7\u683c\u4e3a 80 \uff0c\u4f46\u5728\u5546\u5e97 2 \u4e2d\u6ca1\u6709\u9500\u552e\u3002\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1777](https://leetcode-cn.com/problems/products-price-for-each-store)", "[\u6bcf\u5bb6\u5546\u5e97\u7684\u4ea7\u54c1\u4ef7\u683c](/solution/1700-1799/1777.Product%27s%20Price%20for%20Each%20Store/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1777](https://leetcode.com/problems/products-price-for-each-store)", "[Product's Price for Each Store](/solution/1700-1799/1777.Product%27s%20Price%20for%20Each%20Store/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1925", "frontend_question_id": "1814", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-nice-pairs-in-an-array", "url_en": "https://leetcode.com/problems/count-nice-pairs-in-an-array", "relative_path_cn": "/solution/1800-1899/1814.Count%20Nice%20Pairs%20in%20an%20Array/README.md", "relative_path_en": "/solution/1800-1899/1814.Count%20Nice%20Pairs%20in%20an%20Array/README_EN.md", "title_cn": "\u7edf\u8ba1\u4e00\u4e2a\u6570\u7ec4\u4e2d\u597d\u5bf9\u5b50\u7684\u6570\u76ee", "title_en": "Count Nice Pairs in an Array", "question_title_slug": "count-nice-pairs-in-an-array", "content_en": "

You are given an array nums that consists of non-negative integers. Let us define rev(x) as the reverse of the non-negative integer x. For example, rev(123) = 321, and rev(120) = 21. A pair of indices (i, j) is nice if it satisfies all of the following conditions:

\n\n
    \n\t
  • 0 <= i < j < nums.length
  • \n\t
  • nums[i] + rev(nums[j]) == nums[j] + rev(nums[i])
  • \n
\n\n

Return the number of nice pairs of indices. Since that number can be too large, return it modulo 109 + 7.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [42,11,1,97]\nOutput: 2\nExplanation: The two pairs are:\n - (0,3) : 42 + rev(97) = 42 + 79 = 121, 97 + rev(42) = 97 + 24 = 121.\n - (1,2) : 11 + rev(1) = 11 + 1 = 12, 1 + rev(11) = 1 + 11 = 12.\n
\n\n

Example 2:

\n\n
\nInput: nums = [13,10,35,24,76]\nOutput: 4\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 105
  • \n\t
  • 0 <= nums[i] <= 109
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4\u00a0nums\u00a0\uff0c\u6570\u7ec4\u4e2d\u53ea\u5305\u542b\u975e\u8d1f\u6574\u6570\u3002\u5b9a\u4e49\u00a0rev(x)\u00a0\u7684\u503c\u4e3a\u5c06\u6574\u6570\u00a0x\u00a0\u5404\u4e2a\u6570\u5b57\u4f4d\u53cd\u8f6c\u5f97\u5230\u7684\u7ed3\u679c\u3002\u6bd4\u65b9\u8bf4\u00a0rev(123) = 321\u00a0\uff0c\u00a0rev(120) = 21\u00a0\u3002\u6211\u4eec\u79f0\u6ee1\u8db3\u4e0b\u9762\u6761\u4ef6\u7684\u4e0b\u6807\u5bf9\u00a0(i, j) \u662f\u00a0\u597d\u7684\u00a0\uff1a

\n\n
    \n\t
  • 0 <= i < j < nums.length
  • \n\t
  • nums[i] + rev(nums[j]) == nums[j] + rev(nums[i])
  • \n
\n\n

\u8bf7\u4f60\u8fd4\u56de\u597d\u4e0b\u6807\u5bf9\u7684\u6570\u76ee\u3002\u7531\u4e8e\u7ed3\u679c\u53ef\u80fd\u4f1a\u5f88\u5927\uff0c\u8bf7\u5c06\u7ed3\u679c\u5bf9\u00a0109 + 7\u00a0\u53d6\u4f59\u00a0\u540e\u8fd4\u56de\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anums = [42,11,1,97]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u4e24\u4e2a\u5750\u6807\u5bf9\u4e3a\uff1a\n - (0,3)\uff1a42 + rev(97) = 42 + 79 = 121, 97 + rev(42) = 97 + 24 = 121 \u3002\n - (1,2)\uff1a11 + rev(1) = 11 + 1 = 12, 1 + rev(11) = 1 + 11 = 12 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anums = [13,10,35,24,76]\n\u8f93\u51fa\uff1a4\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 105
  • \n\t
  • 0 <= nums[i] <= 109
  • \n
\n", "tags_en": ["Array", "Hash Table"], "tags_cn": ["\u6570\u7ec4", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countNicePairs(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countNicePairs(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countNicePairs(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countNicePairs(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countNicePairs(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountNicePairs(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar countNicePairs = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef count_nice_pairs(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countNicePairs(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countNicePairs(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countNicePairs(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countNicePairs(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_nice_pairs(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function countNicePairs($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countNicePairs(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-nice-pairs nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1814](https://leetcode-cn.com/problems/count-nice-pairs-in-an-array)", "[\u7edf\u8ba1\u4e00\u4e2a\u6570\u7ec4\u4e2d\u597d\u5bf9\u5b50\u7684\u6570\u76ee](/solution/1800-1899/1814.Count%20Nice%20Pairs%20in%20an%20Array/README.md)", "`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1814](https://leetcode.com/problems/count-nice-pairs-in-an-array)", "[Count Nice Pairs in an Array](/solution/1800-1899/1814.Count%20Nice%20Pairs%20in%20an%20Array/README_EN.md)", "`Array`,`Hash Table`", "Medium", ""]}, {"question_id": "1924", "frontend_question_id": "1815", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-number-of-groups-getting-fresh-donuts", "url_en": "https://leetcode.com/problems/maximum-number-of-groups-getting-fresh-donuts", "relative_path_cn": "/solution/1800-1899/1815.Maximum%20Number%20of%20Groups%20Getting%20Fresh%20Donuts/README.md", "relative_path_en": "/solution/1800-1899/1815.Maximum%20Number%20of%20Groups%20Getting%20Fresh%20Donuts/README_EN.md", "title_cn": "\u5f97\u5230\u65b0\u9c9c\u751c\u751c\u5708\u7684\u6700\u591a\u7ec4\u6570", "title_en": "Maximum Number of Groups Getting Fresh Donuts", "question_title_slug": "maximum-number-of-groups-getting-fresh-donuts", "content_en": "

There is a donuts shop that bakes donuts in batches of batchSize. They have a rule where they must serve all of the donuts of a batch before serving any donuts of the next batch. You are given an integer batchSize and an integer array groups, where groups[i] denotes that there is a group of groups[i] customers that will visit the shop. Each customer will get exactly one donut.

\n\n

When a group visits the shop, all customers of the group must be served before serving any of the following groups. A group will be happy if they all get fresh donuts. That is, the first customer of the group does not receive a donut that was left over from the previous group.

\n\n

You can freely rearrange the ordering of the groups. Return the maximum possible number of happy groups after rearranging the groups.

\n\n

 

\n

Example 1:

\n\n
\nInput: batchSize = 3, groups = [1,2,3,4,5,6]\nOutput: 4\nExplanation: You can arrange the groups as [6,2,4,5,1,3]. Then the 1st, 2nd, 4th, and 6th groups will be happy.\n
\n\n

Example 2:

\n\n
\nInput: batchSize = 4, groups = [1,3,2,5,2,2,1,6]\nOutput: 4\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= batchSize <= 9
  • \n\t
  • 1 <= groups.length <= 30
  • \n\t
  • 1 <= groups[i] <= 109
  • \n
\n", "content_cn": "

\u6709\u4e00\u4e2a\u751c\u751c\u5708\u5546\u5e97\uff0c\u6bcf\u6279\u6b21\u90fd\u70e4\u00a0batchSize\u00a0\u4e2a\u751c\u751c\u5708\u3002\u8fd9\u4e2a\u5e97\u94fa\u6709\u4e2a\u89c4\u5219\uff0c\u5c31\u662f\u5728\u70e4\u4e00\u6279\u65b0\u7684\u751c\u751c\u5708\u65f6\uff0c\u4e4b\u524d \u6240\u6709\u00a0\u751c\u751c\u5708\u90fd\u5fc5\u987b\u5df2\u7ecf\u5168\u90e8\u9500\u552e\u5b8c\u6bd5\u3002\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 batchSize\u00a0\u548c\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 groups\u00a0\uff0c\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u6574\u6570\u90fd\u4ee3\u8868\u4e00\u6279\u524d\u6765\u8d2d\u4e70\u751c\u751c\u5708\u7684\u987e\u5ba2\uff0c\u5176\u4e2d groups[i]\u00a0\u8868\u793a\u8fd9\u4e00\u6279\u987e\u5ba2\u7684\u4eba\u6570\u3002\u6bcf\u4e00\u4f4d\u987e\u5ba2\u90fd\u6070\u597d\u53ea\u8981\u4e00\u4e2a\u751c\u751c\u5708\u3002

\n\n

\u5f53\u6709\u4e00\u6279\u987e\u5ba2\u6765\u5230\u5546\u5e97\u65f6\uff0c\u4ed6\u4eec\u6240\u6709\u4eba\u90fd\u5fc5\u987b\u5728\u4e0b\u4e00\u6279\u987e\u5ba2\u6765\u4e4b\u524d\u8d2d\u4e70\u5b8c\u751c\u751c\u5708\u3002\u5982\u679c\u4e00\u6279\u987e\u5ba2\u4e2d\u7b2c\u4e00\u4f4d\u987e\u5ba2\u5f97\u5230\u7684\u751c\u751c\u5708\u4e0d\u662f\u4e0a\u4e00\u7ec4\u5269\u4e0b\u7684\uff0c\u90a3\u4e48\u8fd9\u4e00\u7ec4\u4eba\u90fd\u4f1a\u5f88\u5f00\u5fc3\u3002

\n\n

\u4f60\u53ef\u4ee5\u968f\u610f\u5b89\u6392\u6bcf\u6279\u987e\u5ba2\u5230\u6765\u7684\u987a\u5e8f\u3002\u8bf7\u4f60\u8fd4\u56de\u5728\u6b64\u524d\u63d0\u4e0b\uff0c\u6700\u591a\u00a0\u6709\u591a\u5c11\u7ec4\u4eba\u4f1a\u611f\u5230\u5f00\u5fc3\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1abatchSize = 3, groups = [1,2,3,4,5,6]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u5c06\u8fd9\u4e9b\u6279\u6b21\u7684\u987e\u5ba2\u987a\u5e8f\u5b89\u6392\u4e3a [6,2,4,5,1,3] \u3002\u90a3\u4e48\u7b2c 1\uff0c2\uff0c4\uff0c6 \u7ec4\u90fd\u4f1a\u611f\u5230\u5f00\u5fc3\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1abatchSize = 4, groups = [1,3,2,5,2,2,1,6]\n\u8f93\u51fa\uff1a4\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= batchSize <= 9
  • \n\t
  • 1 <= groups.length <= 30
  • \n\t
  • 1 <= groups[i] <= 109
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxHappyGroups(int batchSize, vector& groups) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxHappyGroups(int batchSize, int[] groups) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxHappyGroups(self, batchSize, groups):\n \"\"\"\n :type batchSize: int\n :type groups: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxHappyGroups(self, batchSize: int, groups: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxHappyGroups(int batchSize, int* groups, int groupsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxHappyGroups(int batchSize, int[] groups) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} batchSize\n * @param {number[]} groups\n * @return {number}\n */\nvar maxHappyGroups = function(batchSize, groups) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} batch_size\n# @param {Integer[]} groups\n# @return {Integer}\ndef max_happy_groups(batch_size, groups)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxHappyGroups(_ batchSize: Int, _ groups: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxHappyGroups(batchSize int, groups []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxHappyGroups(batchSize: Int, groups: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxHappyGroups(batchSize: Int, groups: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_happy_groups(batch_size: i32, groups: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $batchSize\n * @param Integer[] $groups\n * @return Integer\n */\n function maxHappyGroups($batchSize, $groups) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxHappyGroups(batchSize: number, groups: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-happy-groups batchSize groups)\n (-> exact-integer? (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1815](https://leetcode-cn.com/problems/maximum-number-of-groups-getting-fresh-donuts)", "[\u5f97\u5230\u65b0\u9c9c\u751c\u751c\u5708\u7684\u6700\u591a\u7ec4\u6570](/solution/1800-1899/1815.Maximum%20Number%20of%20Groups%20Getting%20Fresh%20Donuts/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1815](https://leetcode.com/problems/maximum-number-of-groups-getting-fresh-donuts)", "[Maximum Number of Groups Getting Fresh Donuts](/solution/1800-1899/1815.Maximum%20Number%20of%20Groups%20Getting%20Fresh%20Donuts/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1923", "frontend_question_id": "1813", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sentence-similarity-iii", "url_en": "https://leetcode.com/problems/sentence-similarity-iii", "relative_path_cn": "/solution/1800-1899/1813.Sentence%20Similarity%20III/README.md", "relative_path_en": "/solution/1800-1899/1813.Sentence%20Similarity%20III/README_EN.md", "title_cn": "\u53e5\u5b50\u76f8\u4f3c\u6027 III", "title_en": "Sentence Similarity III", "question_title_slug": "sentence-similarity-iii", "content_en": "

A sentence is a list of words that are separated by a single space with no leading or trailing spaces. For example, "Hello World", "HELLO", "hello world hello world" are all sentences. Words consist of only uppercase and lowercase English letters.

\n\n

Two sentences sentence1 and sentence2 are similar if it is possible to insert an arbitrary sentence (possibly empty) inside one of these sentences such that the two sentences become equal. For example, sentence1 = "Hello my name is Jane" and sentence2 = "Hello Jane" can be made equal by inserting "my name is" between "Hello" and "Jane" in sentence2.

\n\n

Given two sentences sentence1 and sentence2, return true if sentence1 and sentence2 are similar. Otherwise, return false.

\n\n

 

\n

Example 1:

\n\n
\nInput: sentence1 = "My name is Haley", sentence2 = "My Haley"\nOutput: true\nExplanation: sentence2 can be turned to sentence1 by inserting "name is" between "My" and "Haley".\n
\n\n

Example 2:

\n\n
\nInput: sentence1 = "of", sentence2 = "A lot of words"\nOutput: false\nExplanation: No single sentence can be inserted inside one of the sentences to make it equal to the other.\n
\n\n

Example 3:

\n\n
\nInput: sentence1 = "Eating right now", sentence2 = "Eating"\nOutput: true\nExplanation: sentence2 can be turned to sentence1 by inserting "right now" at the end of the sentence.\n
\n\n

Example 4:

\n\n
\nInput: sentence1 = "Luky", sentence2 = "Lucccky"\nOutput: false\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= sentence1.length, sentence2.length <= 100
  • \n\t
  • sentence1 and sentence2 consist of lowercase and uppercase English letters and spaces.
  • \n\t
  • The words in sentence1 and sentence2 are separated by a single space.
  • \n
\n", "content_cn": "

\u4e00\u4e2a\u53e5\u5b50\u662f\u7531\u4e00\u4e9b\u5355\u8bcd\u4e0e\u5b83\u4eec\u4e4b\u95f4\u7684\u5355\u4e2a\u7a7a\u683c\u7ec4\u6210\uff0c\u4e14\u53e5\u5b50\u7684\u5f00\u5934\u548c\u7ed3\u5c3e\u6ca1\u6709\u591a\u4f59\u7a7a\u683c\u3002\u6bd4\u65b9\u8bf4\uff0c\"Hello World\"\u00a0\uff0c\"HELLO\"\u00a0\uff0c\"hello world hello world\"\u00a0\u90fd\u662f\u53e5\u5b50\u3002\u6bcf\u4e2a\u5355\u8bcd\u90fd \u53ea\u00a0\u5305\u542b\u5927\u5199\u548c\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002

\n\n

\u5982\u679c\u4e24\u4e2a\u53e5\u5b50\u00a0sentence1 \u548c\u00a0sentence2\u00a0\uff0c\u53ef\u4ee5\u901a\u8fc7\u5f80\u5176\u4e2d\u4e00\u4e2a\u53e5\u5b50\u63d2\u5165\u4e00\u4e2a\u4efb\u610f\u7684\u53e5\u5b50\uff08\u53ef\u4ee5\u662f\u7a7a\u53e5\u5b50\uff09\u800c\u5f97\u5230\u53e6\u4e00\u4e2a\u53e5\u5b50\uff0c\u90a3\u4e48\u6211\u4eec\u79f0\u8fd9\u4e24\u4e2a\u53e5\u5b50\u662f \u76f8\u4f3c\u7684\u00a0\u3002\u6bd4\u65b9\u8bf4\uff0csentence1 = \"Hello my name is Jane\" \u4e14\u00a0sentence2 = \"Hello Jane\"\u00a0\uff0c\u6211\u4eec\u53ef\u4ee5\u5f80 sentence2\u00a0\u4e2d\u00a0\"Hello\" \u548c\u00a0\"Jane\"\u00a0\u4e4b\u95f4\u63d2\u5165\u00a0\"my name is\"\u00a0\u5f97\u5230 sentence1\u00a0\u3002

\n\n

\u7ed9\u4f60\u4e24\u4e2a\u53e5\u5b50\u00a0sentence1 \u548c\u00a0sentence2\u00a0\uff0c\u5982\u679c\u00a0sentence1 \u548c\u00a0sentence2 \u662f\u76f8\u4f3c\u7684\uff0c\u8bf7\u4f60\u8fd4\u56de\u00a0true\u00a0\uff0c\u5426\u5219\u8fd4\u56de\u00a0false\u00a0\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1asentence1 = \"My name is Haley\", sentence2 = \"My Haley\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u53ef\u4ee5\u5f80 sentence2 \u4e2d \"My\" \u548c \"Haley\" \u4e4b\u95f4\u63d2\u5165 \"name is\" \uff0c\u5f97\u5230 sentence1 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1asentence1 = \"of\", sentence2 = \"A lot of words\"\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u6ca1\u6cd5\u5f80\u8fd9\u4e24\u4e2a\u53e5\u5b50\u4e2d\u7684\u4e00\u4e2a\u53e5\u5b50\u53ea\u63d2\u5165\u4e00\u4e2a\u53e5\u5b50\u5c31\u5f97\u5230\u53e6\u4e00\u4e2a\u53e5\u5b50\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1asentence1 = \"Eating right now\", sentence2 = \"Eating\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u53ef\u4ee5\u5f80 sentence2 \u7684\u7ed3\u5c3e\u63d2\u5165 \"right now\" \u5f97\u5230 sentence1 \u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1asentence1 = \"Luky\", sentence2 = \"Lucccky\"\n\u8f93\u51fa\uff1afalse\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= sentence1.length, sentence2.length <= 100
  • \n\t
  • sentence1\u00a0\u548c\u00a0sentence2\u00a0\u90fd\u53ea\u5305\u542b\u5927\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u548c\u7a7a\u683c\u3002
  • \n\t
  • sentence1\u00a0\u548c\u00a0sentence2\u00a0\u4e2d\u7684\u5355\u8bcd\u90fd\u53ea\u7531\u5355\u4e2a\u7a7a\u683c\u9694\u5f00\u3002
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool areSentencesSimilar(string sentence1, string sentence2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean areSentencesSimilar(String sentence1, String sentence2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def areSentencesSimilar(self, sentence1, sentence2):\n \"\"\"\n :type sentence1: str\n :type sentence2: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def areSentencesSimilar(self, sentence1: str, sentence2: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool areSentencesSimilar(char * sentence1, char * sentence2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool AreSentencesSimilar(string sentence1, string sentence2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} sentence1\n * @param {string} sentence2\n * @return {boolean}\n */\nvar areSentencesSimilar = function(sentence1, sentence2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} sentence1\n# @param {String} sentence2\n# @return {Boolean}\ndef are_sentences_similar(sentence1, sentence2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func areSentencesSimilar(_ sentence1: String, _ sentence2: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func areSentencesSimilar(sentence1 string, sentence2 string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def areSentencesSimilar(sentence1: String, sentence2: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun areSentencesSimilar(sentence1: String, sentence2: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn are_sentences_similar(sentence1: String, sentence2: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $sentence1\n * @param String $sentence2\n * @return Boolean\n */\n function areSentencesSimilar($sentence1, $sentence2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function areSentencesSimilar(sentence1: string, sentence2: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (are-sentences-similar sentence1 sentence2)\n (-> string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1813](https://leetcode-cn.com/problems/sentence-similarity-iii)", "[\u53e5\u5b50\u76f8\u4f3c\u6027 III](/solution/1800-1899/1813.Sentence%20Similarity%20III/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1813](https://leetcode.com/problems/sentence-similarity-iii)", "[Sentence Similarity III](/solution/1800-1899/1813.Sentence%20Similarity%20III/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "1920", "frontend_question_id": "1812", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/determine-color-of-a-chessboard-square", "url_en": "https://leetcode.com/problems/determine-color-of-a-chessboard-square", "relative_path_cn": "/solution/1800-1899/1812.Determine%20Color%20of%20a%20Chessboard%20Square/README.md", "relative_path_en": "/solution/1800-1899/1812.Determine%20Color%20of%20a%20Chessboard%20Square/README_EN.md", "title_cn": "\u5224\u65ad\u56fd\u9645\u8c61\u68cb\u68cb\u76d8\u4e2d\u4e00\u4e2a\u683c\u5b50\u7684\u989c\u8272", "title_en": "Determine Color of a Chessboard Square", "question_title_slug": "determine-color-of-a-chessboard-square", "content_en": "

You are given coordinates, a string that represents the coordinates of a square of the chessboard. Below is a chessboard for your reference.

\n\n

\"\"

\n\n

Return true if the square is white, and false if the square is black.

\n\n

The coordinate will always represent a valid chessboard square. The coordinate will always have the letter first, and the number second.

\n\n

 

\n

Example 1:

\n\n
\nInput: coordinates = "a1"\nOutput: false\nExplanation: From the chessboard above, the square with coordinates "a1" is black, so return false.\n
\n\n

Example 2:

\n\n
\nInput: coordinates = "h3"\nOutput: true\nExplanation: From the chessboard above, the square with coordinates "h3" is white, so return true.\n
\n\n

Example 3:

\n\n
\nInput: coordinates = "c7"\nOutput: false\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • coordinates.length == 2
  • \n\t
  • 'a' <= coordinates[0] <= 'h'
  • \n\t
  • '1' <= coordinates[1] <= '8'
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5750\u6807\u00a0coordinates\u00a0\uff0c\u5b83\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u8868\u793a\u56fd\u9645\u8c61\u68cb\u68cb\u76d8\u4e2d\u4e00\u4e2a\u683c\u5b50\u7684\u5750\u6807\u3002\u4e0b\u56fe\u662f\u56fd\u9645\u8c61\u68cb\u68cb\u76d8\u793a\u610f\u56fe\u3002

\n\n

\"\"

\n\n

\u5982\u679c\u6240\u7ed9\u683c\u5b50\u7684\u989c\u8272\u662f\u767d\u8272\uff0c\u8bf7\u4f60\u8fd4\u56de\u00a0true\uff0c\u5982\u679c\u662f\u9ed1\u8272\uff0c\u8bf7\u8fd4\u56de\u00a0false\u00a0\u3002

\n\n

\u7ed9\u5b9a\u5750\u6807\u4e00\u5b9a\u4ee3\u8868\u56fd\u9645\u8c61\u68cb\u68cb\u76d8\u4e0a\u4e00\u4e2a\u5b58\u5728\u7684\u683c\u5b50\u3002\u5750\u6807\u7b2c\u4e00\u4e2a\u5b57\u7b26\u662f\u5b57\u6bcd\uff0c\u7b2c\u4e8c\u4e2a\u5b57\u7b26\u662f\u6570\u5b57\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1acoordinates = \"a1\"\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u5982\u4e0a\u56fe\u68cb\u76d8\u6240\u793a\uff0c\"a1\" \u5750\u6807\u7684\u683c\u5b50\u662f\u9ed1\u8272\u7684\uff0c\u6240\u4ee5\u8fd4\u56de false \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1acoordinates = \"h3\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u5982\u4e0a\u56fe\u68cb\u76d8\u6240\u793a\uff0c\"h3\" \u5750\u6807\u7684\u683c\u5b50\u662f\u767d\u8272\u7684\uff0c\u6240\u4ee5\u8fd4\u56de true \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1acoordinates = \"c7\"\n\u8f93\u51fa\uff1afalse\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • coordinates.length == 2
  • \n\t
  • 'a' <= coordinates[0] <= 'h'
  • \n\t
  • '1' <= coordinates[1] <= '8'
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool squareIsWhite(string coordinates) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean squareIsWhite(String coordinates) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def squareIsWhite(self, coordinates):\n \"\"\"\n :type coordinates: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def squareIsWhite(self, coordinates: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool squareIsWhite(char * coordinates){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool SquareIsWhite(string coordinates) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} coordinates\n * @return {boolean}\n */\nvar squareIsWhite = function(coordinates) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} coordinates\n# @return {Boolean}\ndef square_is_white(coordinates)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func squareIsWhite(_ coordinates: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func squareIsWhite(coordinates string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def squareIsWhite(coordinates: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun squareIsWhite(coordinates: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn square_is_white(coordinates: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $coordinates\n * @return Boolean\n */\n function squareIsWhite($coordinates) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function squareIsWhite(coordinates: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (square-is-white coordinates)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1812](https://leetcode-cn.com/problems/determine-color-of-a-chessboard-square)", "[\u5224\u65ad\u56fd\u9645\u8c61\u68cb\u68cb\u76d8\u4e2d\u4e00\u4e2a\u683c\u5b50\u7684\u989c\u8272](/solution/1800-1899/1812.Determine%20Color%20of%20a%20Chessboard%20Square/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1812](https://leetcode.com/problems/determine-color-of-a-chessboard-square)", "[Determine Color of a Chessboard Square](/solution/1800-1899/1812.Determine%20Color%20of%20a%20Chessboard%20Square/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1919", "frontend_question_id": "1772", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/sort-features-by-popularity", "url_en": "https://leetcode.com/problems/sort-features-by-popularity", "relative_path_cn": "/solution/1700-1799/1772.Sort%20Features%20by%20Popularity/README.md", "relative_path_en": "/solution/1700-1799/1772.Sort%20Features%20by%20Popularity/README_EN.md", "title_cn": "\u6309\u53d7\u6b22\u8fce\u7a0b\u5ea6\u6392\u5217\u529f\u80fd", "title_en": "Sort Features by Popularity", "question_title_slug": "sort-features-by-popularity", "content_en": "

You are given a string array features where features[i] is a single word that represents the name of a feature of the latest product you are working on. You have made a survey where users have reported which features they like. You are given a string array responses, where each responses[i] is a string containing space-separated words.

\n\n

The popularity of a feature is the number of responses[i] that contain the feature. You want to sort the features in non-increasing order by their popularity. If two features have the same popularity, order them by their original index in features. Notice that one response could contain the same feature multiple times; this feature is only counted once in its popularity.

\n\n

Return the features in sorted order.

\n\n

 

\n

Example 1:

\n\n
\nInput: features = ["cooler","lock","touch"], responses = ["i like cooler cooler","lock touch cool","locker like touch"]\nOutput: ["touch","cooler","lock"]\nExplanation: appearances("cooler") = 1, appearances("lock") = 1, appearances("touch") = 2. Since "cooler" and "lock" both had 1 appearance, "cooler" comes first because "cooler" came first in the features array.\n
\n\n

Example 2:

\n\n
\nInput: features = ["a","aa","b","c"], responses = ["a","a aa","a a a a a","b a"]\nOutput: ["a","aa","b","c"]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= features.length <= 104
  • \n\t
  • 1 <= features[i].length <= 10
  • \n\t
  • features contains no duplicates.
  • \n\t
  • features[i] consists of lowercase letters.
  • \n\t
  • 1 <= responses.length <= 102
  • \n\t
  • 1 <= responses[i].length <= 103
  • \n\t
  • responses[i] consists of lowercase letters and spaces.
  • \n\t
  • responses[i] contains no two consecutive spaces.
  • \n\t
  • responses[i] has no leading or trailing spaces.
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4\u00a0features\u00a0\uff0c\u5176\u4e2d\u00a0features[i]\u00a0\u662f\u4e00\u4e2a\u5355\u8bcd\uff0c\u63cf\u8ff0\u4f60\u6700\u8fd1\u53c2\u4e0e\u5f00\u53d1\u7684\u9879\u76ee\u4e2d\u4e00\u4e2a\u529f\u80fd\u7684\u540d\u79f0\u3002\u4f60\u8c03\u67e5\u4e86\u7528\u6237\u559c\u6b22\u54ea\u4e9b\u529f\u80fd\u3002\u53e6\u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4\u00a0responses\uff0c\u5176\u4e2d\u00a0responses[i]\u00a0\u662f\u4e00\u4e2a\u5305\u542b\u4ee5\u7a7a\u683c\u5206\u9694\u7684\u4e00\u7cfb\u5217\u5355\u8bcd\u7684\u5b57\u7b26\u4e32\u3002

\n\n

\u4f60\u60f3\u8981\u6309\u7167\u53d7\u6b22\u8fce\u7a0b\u5ea6\u6392\u5217\u8fd9\u4e9b\u529f\u80fd\u3002\u00a0\u4e25\u683c\u5730\u8bf4\uff0c\u4ee4\u00a0appearances(word)\u00a0\u662f\u6ee1\u8db3 responses[i]\u00a0\u4e2d\u5305\u542b\u5355\u8bcd\u00a0word\u00a0\u7684\u00a0i\u00a0\u7684\u4e2a\u6570\uff0c\u5219\u5f53\u00a0appearances(features[x]) > appearances(features[y])\u00a0\u65f6\uff0c\u7b2c\u00a0x\u00a0\u4e2a\u529f\u80fd\u6bd4\u7b2c\u00a0y\u00a0\u4e2a\u529f\u80fd\u66f4\u53d7\u6b22\u8fce\u3002

\n\n

\u8fd4\u56de\u4e00\u4e2a\u6570\u7ec4\u00a0sortedFeatures\u00a0\uff0c\u5305\u542b\u6309\u53d7\u6b22\u8fce\u7a0b\u5ea6\u6392\u5217\u7684\u529f\u80fd\u540d\u79f0\u3002\u5f53\u7b2c\u00a0x\u00a0 \u4e2a\u529f\u80fd\u548c\u7b2c\u00a0y\u00a0\u4e2a\u529f\u80fd\u7684\u53d7\u6b22\u8fce\u7a0b\u5ea6\u76f8\u540c\u4e14\u00a0x < y\u00a0\u65f6\uff0c\u4f60\u5e94\u5f53\u5c06\u7b2c\u00a0x\u00a0\u4e2a\u529f\u80fd\u653e\u5728\u7b2c\u00a0y\u00a0\u4e2a\u529f\u80fd\u4e4b\u524d\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1afeatures = [\"cooler\",\"lock\",\"touch\"], responses = [\"i like cooler cooler\",\"lock touch cool\",\"locker like touch\"]\n\u8f93\u51fa\uff1a[\"touch\",\"cooler\",\"lock\"]\n\u89e3\u91ca\uff1aappearances(\"cooler\") = 1\uff0cappearances(\"lock\") = 1\uff0cappearances(\"touch\") = 2\u3002\u7531\u4e8e \"cooler\" \u548c \"lock\" \u90fd\u51fa\u73b0\u4e86 1 \u6b21\uff0c\u4e14 \"cooler\" \u5728\u539f\u6570\u7ec4\u7684\u524d\u9762\uff0c\u6240\u4ee5 \"cooler\" \u4e5f\u5e94\u8be5\u5728\u7ed3\u679c\u6570\u7ec4\u7684\u524d\u9762\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1afeatures = [\"a\",\"aa\",\"b\",\"c\"], responses = [\"a\",\"a aa\",\"a a a a a\",\"b a\"]\n\u8f93\u51fa\uff1a[\"a\",\"aa\",\"b\",\"c\"]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= features.length\u00a0<= 104
  • \n\t
  • 1 <= features[i].length <= 10
  • \n\t
  • features\u00a0\u4e0d\u5305\u542b\u91cd\u590d\u9879\u3002
  • \n\t
  • features[i]\u00a0\u7531\u5c0f\u5199\u5b57\u6bcd\u6784\u6210\u3002
  • \n\t
  • 1 <= responses.length <= 102
  • \n\t
  • 1 <= responses[i].length <= 103
  • \n\t
  • responses[i]\u00a0\u7531\u5c0f\u5199\u5b57\u6bcd\u548c\u7a7a\u683c\u7ec4\u6210\u3002
  • \n\t
  • responses[i]\u00a0\u4e0d\u5305\u542b\u4e24\u4e2a\u8fde\u7eed\u7684\u7a7a\u683c\u3002
  • \n\t
  • responses[i]\u00a0\u6ca1\u6709\u524d\u7f6e\u6216\u540e\u7f6e\u7a7a\u683c\u3002
  • \n
\n", "tags_en": ["Sort", "Hash Table"], "tags_cn": ["\u6392\u5e8f", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector sortFeatures(vector& features, vector& responses) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String[] sortFeatures(String[] features, String[] responses) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def sortFeatures(self, features, responses):\n \"\"\"\n :type features: List[str]\n :type responses: List[str]\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def sortFeatures(self, features: List[str], responses: List[str]) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** sortFeatures(char ** features, int featuresSize, char ** responses, int responsesSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string[] SortFeatures(string[] features, string[] responses) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} features\n * @param {string[]} responses\n * @return {string[]}\n */\nvar sortFeatures = function(features, responses) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} features\n# @param {String[]} responses\n# @return {String[]}\ndef sort_features(features, responses)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func sortFeatures(_ features: [String], _ responses: [String]) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func sortFeatures(features []string, responses []string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def sortFeatures(features: Array[String], responses: Array[String]): Array[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun sortFeatures(features: Array, responses: Array): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sort_features(features: Vec, responses: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $features\n * @param String[] $responses\n * @return String[]\n */\n function sortFeatures($features, $responses) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function sortFeatures(features: string[], responses: string[]): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (sort-features features responses)\n (-> (listof string?) (listof string?) (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1772](https://leetcode-cn.com/problems/sort-features-by-popularity)", "[\u6309\u53d7\u6b22\u8fce\u7a0b\u5ea6\u6392\u5217\u529f\u80fd](/solution/1700-1799/1772.Sort%20Features%20by%20Popularity/README.md)", "`\u6392\u5e8f`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1772](https://leetcode.com/problems/sort-features-by-popularity)", "[Sort Features by Popularity](/solution/1700-1799/1772.Sort%20Features%20by%20Popularity/README_EN.md)", "`Sort`,`Hash Table`", "Medium", "\ud83d\udd12"]}, {"question_id": "1918", "frontend_question_id": "1793", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-score-of-a-good-subarray", "url_en": "https://leetcode.com/problems/maximum-score-of-a-good-subarray", "relative_path_cn": "/solution/1700-1799/1793.Maximum%20Score%20of%20a%20Good%20Subarray/README.md", "relative_path_en": "/solution/1700-1799/1793.Maximum%20Score%20of%20a%20Good%20Subarray/README_EN.md", "title_cn": "\u597d\u5b50\u6570\u7ec4\u7684\u6700\u5927\u5206\u6570", "title_en": "Maximum Score of a Good Subarray", "question_title_slug": "maximum-score-of-a-good-subarray", "content_en": "

You are given an array of integers nums (0-indexed) and an integer k.

\n\n

The score of a subarray (i, j) is defined as min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1). A good subarray is a subarray where i <= k <= j.

\n\n

Return the maximum possible score of a good subarray.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [1,4,3,7,4,5], k = 3\nOutput: 15\nExplanation: The optimal subarray is (1, 5) with a score of min(4,3,7,4,5) * (5-1+1) = 3 * 5 = 15. \n
\n\n

Example 2:

\n\n
\nInput: nums = [5,5,4,5,4,1,1,1], k = 0\nOutput: 20\nExplanation: The optimal subarray is (0, 4) with a score of min(5,5,4,5,4) * (4-0+1) = 4 * 5 = 20.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 105
  • \n\t
  • 1 <= nums[i] <= 2 * 104
  • \n\t
  • 0 <= k < nums.length
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0nums\u00a0\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\u548c\u4e00\u4e2a\u6574\u6570\u00a0k\u00a0\u3002

\n\n

\u4e00\u4e2a\u5b50\u6570\u7ec4 (i, j)\u00a0\u7684 \u5206\u6570\u00a0\u5b9a\u4e49\u4e3a\u00a0min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)\u00a0\u3002\u4e00\u4e2a\u00a0\u597d\u00a0\u5b50\u6570\u7ec4\u7684\u4e24\u4e2a\u7aef\u70b9\u4e0b\u6807\u9700\u8981\u6ee1\u8db3\u00a0i <= k <= j\u00a0\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de \u597d\u00a0\u5b50\u6570\u7ec4\u7684\u6700\u5927\u53ef\u80fd \u5206\u6570\u00a0\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,4,3,7,4,5], k = 3\n\u8f93\u51fa\uff1a15\n\u89e3\u91ca\uff1a\u6700\u4f18\u5b50\u6570\u7ec4\u7684\u5de6\u53f3\u7aef\u70b9\u4e0b\u6807\u662f (1, 5) \uff0c\u5206\u6570\u4e3a min(4,3,7,4,5) * (5-1+1) = 3 * 5 = 15 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anums = [5,5,4,5,4,1,1,1], k = 0\n\u8f93\u51fa\uff1a20\n\u89e3\u91ca\uff1a\u6700\u4f18\u5b50\u6570\u7ec4\u7684\u5de6\u53f3\u7aef\u70b9\u4e0b\u6807\u662f (0, 4) \uff0c\u5206\u6570\u4e3a min(5,5,4,5,4) * (4-0+1) = 4 * 5 = 20 \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 105
  • \n\t
  • 1 <= nums[i] <= 2 * 104
  • \n\t
  • 0 <= k < nums.length
  • \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maximumScore(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maximumScore(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximumScore(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximumScore(self, nums: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maximumScore(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaximumScore(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar maximumScore = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef maximum_score(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximumScore(_ nums: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximumScore(nums []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximumScore(nums: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximumScore(nums: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximum_score(nums: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer\n */\n function maximumScore($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximumScore(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximum-score nums k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1793](https://leetcode-cn.com/problems/maximum-score-of-a-good-subarray)", "[\u597d\u5b50\u6570\u7ec4\u7684\u6700\u5927\u5206\u6570](/solution/1700-1799/1793.Maximum%20Score%20of%20a%20Good%20Subarray/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[1793](https://leetcode.com/problems/maximum-score-of-a-good-subarray)", "[Maximum Score of a Good Subarray](/solution/1700-1799/1793.Maximum%20Score%20of%20a%20Good%20Subarray/README_EN.md)", "`Greedy`", "Hard", ""]}, {"question_id": "1917", "frontend_question_id": "1792", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-average-pass-ratio", "url_en": "https://leetcode.com/problems/maximum-average-pass-ratio", "relative_path_cn": "/solution/1700-1799/1792.Maximum%20Average%20Pass%20Ratio/README.md", "relative_path_en": "/solution/1700-1799/1792.Maximum%20Average%20Pass%20Ratio/README_EN.md", "title_cn": "\u6700\u5927\u5e73\u5747\u901a\u8fc7\u7387", "title_en": "Maximum Average Pass Ratio", "question_title_slug": "maximum-average-pass-ratio", "content_en": "

There is a school that has classes of students and each class will be having a final exam. You are given a 2D integer array classes, where classes[i] = [passi, totali]. You know beforehand that in the ith class, there are totali total students, but only passi number of students will pass the exam.

\n\n

You are also given an integer extraStudents. There are another extraStudents brilliant students that are guaranteed to pass the exam of any class they are assigned to. You want to assign each of the extraStudents students to a class in a way that maximizes the average pass ratio across all the classes.

\n\n

The pass ratio of a class is equal to the number of students of the class that will pass the exam divided by the total number of students of the class. The average pass ratio is the sum of pass ratios of all the classes divided by the number of the classes.

\n\n

Return the maximum possible average pass ratio after assigning the extraStudents students. Answers within 10-5 of the actual answer will be accepted.

\n\n

 

\n

Example 1:

\n\n
\nInput: classes = [[1,2],[3,5],[2,2]], extraStudents = 2\nOutput: 0.78333\nExplanation: You can assign the two extra students to the first class. The average pass ratio will be equal to (3/4 + 3/5 + 2/2) / 3 = 0.78333.\n
\n\n

Example 2:

\n\n
\nInput: classes = [[2,4],[3,9],[4,5],[2,10]], extraStudents = 4\nOutput: 0.53485\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= classes.length <= 105
  • \n\t
  • classes[i].length == 2
  • \n\t
  • 1 <= passi <= totali <= 105
  • \n\t
  • 1 <= extraStudents <= 105
  • \n
\n", "content_cn": "

\u4e00\u6240\u5b66\u6821\u91cc\u6709\u4e00\u4e9b\u73ed\u7ea7\uff0c\u6bcf\u4e2a\u73ed\u7ea7\u91cc\u6709\u4e00\u4e9b\u5b66\u751f\uff0c\u73b0\u5728\u6bcf\u4e2a\u73ed\u90fd\u4f1a\u8fdb\u884c\u4e00\u573a\u671f\u672b\u8003\u8bd5\u3002\u7ed9\u4f60\u4e00\u4e2a\u4e8c\u7ef4\u6570\u7ec4 classes\u00a0\uff0c\u5176\u4e2d\u00a0classes[i] = [passi, totali]\u00a0\uff0c\u8868\u793a\u4f60\u63d0\u524d\u77e5\u9053\u4e86\u7b2c\u00a0i\u00a0\u4e2a\u73ed\u7ea7\u603b\u5171\u6709\u00a0totali\u00a0\u4e2a\u5b66\u751f\uff0c\u5176\u4e2d\u53ea\u6709\u00a0passi\u00a0\u4e2a\u5b66\u751f\u53ef\u4ee5\u901a\u8fc7\u8003\u8bd5\u3002

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u00a0extraStudents\u00a0\uff0c\u8868\u793a\u989d\u5916\u6709\u00a0extraStudents\u00a0\u4e2a\u806a\u660e\u7684\u5b66\u751f\uff0c\u4ed6\u4eec \u4e00\u5b9a\u00a0\u80fd\u901a\u8fc7\u4efb\u4f55\u73ed\u7ea7\u7684\u671f\u672b\u8003\u3002\u4f60\u9700\u8981\u7ed9\u8fd9\u00a0extraStudents\u00a0\u4e2a\u5b66\u751f\u6bcf\u4eba\u90fd\u5b89\u6392\u4e00\u4e2a\u73ed\u7ea7\uff0c\u4f7f\u5f97 \u6240\u6709\u00a0\u73ed\u7ea7\u7684 \u5e73\u5747\u00a0\u901a\u8fc7\u7387 \u6700\u5927\u00a0\u3002

\n\n

\u4e00\u4e2a\u73ed\u7ea7\u7684\u00a0\u901a\u8fc7\u7387\u00a0\u7b49\u4e8e\u8fd9\u4e2a\u73ed\u7ea7\u901a\u8fc7\u8003\u8bd5\u7684\u5b66\u751f\u4eba\u6570\u9664\u4ee5\u8fd9\u4e2a\u73ed\u7ea7\u7684\u603b\u4eba\u6570\u3002\u5e73\u5747\u901a\u8fc7\u7387\u00a0\u662f\u6240\u6709\u73ed\u7ea7\u7684\u901a\u8fc7\u7387\u4e4b\u548c\u9664\u4ee5\u73ed\u7ea7\u6570\u76ee\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u5728\u5b89\u6392\u8fd9 extraStudents \u4e2a\u5b66\u751f\u53bb\u5bf9\u5e94\u73ed\u7ea7\u540e\u7684 \u6700\u5927\u00a0\u5e73\u5747\u901a\u8fc7\u7387\u3002\u4e0e\u6807\u51c6\u7b54\u6848\u8bef\u5dee\u8303\u56f4\u5728\u00a010-5\u00a0\u4ee5\u5185\u7684\u7ed3\u679c\u90fd\u4f1a\u89c6\u4e3a\u6b63\u786e\u7ed3\u679c\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aclasses = [[1,2],[3,5],[2,2]], extraStudents = 2\n\u8f93\u51fa\uff1a0.78333\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u5c06\u989d\u5916\u7684\u4e24\u4e2a\u5b66\u751f\u90fd\u5b89\u6392\u5230\u7b2c\u4e00\u4e2a\u73ed\u7ea7\uff0c\u5e73\u5747\u901a\u8fc7\u7387\u4e3a (3/4 + 3/5 + 2/2) / 3 = 0.78333 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aclasses = [[2,4],[3,9],[4,5],[2,10]], extraStudents = 4\n\u8f93\u51fa\uff1a0.53485\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= classes.length <= 105
  • \n\t
  • classes[i].length == 2
  • \n\t
  • 1 <= passi <= totali <= 105
  • \n\t
  • 1 <= extraStudents <= 105
  • \n
\n", "tags_en": ["Heap"], "tags_cn": ["\u5806"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n double maxAverageRatio(vector>& classes, int extraStudents) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double maxAverageRatio(int[][] classes, int extraStudents) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxAverageRatio(self, classes, extraStudents):\n \"\"\"\n :type classes: List[List[int]]\n :type extraStudents: int\n :rtype: float\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxAverageRatio(self, classes: List[List[int]], extraStudents: int) -> float:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\ndouble maxAverageRatio(int** classes, int classesSize, int* classesColSize, int extraStudents){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double MaxAverageRatio(int[][] classes, int extraStudents) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} classes\n * @param {number} extraStudents\n * @return {number}\n */\nvar maxAverageRatio = function(classes, extraStudents) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} classes\n# @param {Integer} extra_students\n# @return {Float}\ndef max_average_ratio(classes, extra_students)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxAverageRatio(_ classes: [[Int]], _ extraStudents: Int) -> Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxAverageRatio(classes [][]int, extraStudents int) float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxAverageRatio(classes: Array[Array[Int]], extraStudents: Int): Double = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxAverageRatio(classes: Array, extraStudents: Int): Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_average_ratio(classes: Vec>, extra_students: i32) -> f64 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $classes\n * @param Integer $extraStudents\n * @return Float\n */\n function maxAverageRatio($classes, $extraStudents) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxAverageRatio(classes: number[][], extraStudents: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-average-ratio classes extraStudents)\n (-> (listof (listof exact-integer?)) exact-integer? flonum?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1792](https://leetcode-cn.com/problems/maximum-average-pass-ratio)", "[\u6700\u5927\u5e73\u5747\u901a\u8fc7\u7387](/solution/1700-1799/1792.Maximum%20Average%20Pass%20Ratio/README.md)", "`\u5806`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1792](https://leetcode.com/problems/maximum-average-pass-ratio)", "[Maximum Average Pass Ratio](/solution/1700-1799/1792.Maximum%20Average%20Pass%20Ratio/README_EN.md)", "`Heap`", "Medium", ""]}, {"question_id": "1916", "frontend_question_id": "1791", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-center-of-star-graph", "url_en": "https://leetcode.com/problems/find-center-of-star-graph", "relative_path_cn": "/solution/1700-1799/1791.Find%20Center%20of%20Star%20Graph/README.md", "relative_path_en": "/solution/1700-1799/1791.Find%20Center%20of%20Star%20Graph/README_EN.md", "title_cn": "\u627e\u51fa\u661f\u578b\u56fe\u7684\u4e2d\u5fc3\u8282\u70b9", "title_en": "Find Center of Star Graph", "question_title_slug": "find-center-of-star-graph", "content_en": "

There is an undirected star graph consisting of n nodes labeled from 1 to n. A star graph is a graph where there is one center node and exactly n - 1 edges that connect the center node with every other node.

\r\n\r\n

You are given a 2D integer array edges where each edges[i] = [ui, vi] indicates that there is an edge between the nodes ui and vi. Return the center of the given star graph.

\r\n\r\n

 

\r\n

Example 1:

\r\n\"\"\r\n
\r\nInput: edges = [[1,2],[2,3],[4,2]]\r\nOutput: 2\r\nExplanation: As shown in the figure above, node 2 is connected to every other node, so 2 is the center.\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: edges = [[1,2],[5,1],[1,3],[1,4]]\r\nOutput: 1\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 3 <= n <= 105
  • \r\n\t
  • edges.length == n - 1
  • \r\n\t
  • edges[i].length == 2
  • \r\n\t
  • 1 <= ui, vi <= n
  • \r\n\t
  • ui != vi
  • \r\n\t
  • The given edges represent a valid star graph.
  • \r\n
", "content_cn": "

\u6709\u4e00\u4e2a\u65e0\u5411\u7684 \u661f\u578b \u56fe\uff0c\u7531 n \u4e2a\u7f16\u53f7\u4ece 1 \u5230 n \u7684\u8282\u70b9\u7ec4\u6210\u3002\u661f\u578b\u56fe\u6709\u4e00\u4e2a \u4e2d\u5fc3 \u8282\u70b9\uff0c\u5e76\u4e14\u6070\u6709 n - 1 \u6761\u8fb9\u5c06\u4e2d\u5fc3\u8282\u70b9\u4e0e\u5176\u4ed6\u6bcf\u4e2a\u8282\u70b9\u8fde\u63a5\u8d77\u6765\u3002

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u4e8c\u7ef4\u6574\u6570\u6570\u7ec4 edges \uff0c\u5176\u4e2d\u00a0edges[i] = [ui, vi] \u8868\u793a\u5728\u8282\u70b9 ui \u548c vi \u4e4b\u95f4\u5b58\u5728\u4e00\u6761\u8fb9\u3002\u8bf7\u4f60\u627e\u51fa\u5e76\u8fd4\u56de\u00a0edges \u6240\u8868\u793a\u661f\u578b\u56fe\u7684\u4e2d\u5fc3\u8282\u70b9\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1aedges = [[1,2],[2,3],[4,2]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5982\u4e0a\u56fe\u6240\u793a\uff0c\u8282\u70b9 2 \u4e0e\u5176\u4ed6\u6bcf\u4e2a\u8282\u70b9\u90fd\u76f8\u8fde\uff0c\u6240\u4ee5\u8282\u70b9 2 \u662f\u4e2d\u5fc3\u8282\u70b9\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aedges = [[1,2],[5,1],[1,3],[1,4]]\n\u8f93\u51fa\uff1a1\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 3 <= n <= 105
  • \n\t
  • edges.length == n - 1
  • \n\t
  • edges[i].length == 2
  • \n\t
  • 1 <= ui, vi <= n
  • \n\t
  • ui != vi
  • \n\t
  • \u9898\u76ee\u6570\u636e\u7ed9\u51fa\u7684 edges \u8868\u793a\u4e00\u4e2a\u6709\u6548\u7684\u661f\u578b\u56fe
  • \n
\n", "tags_en": ["Graph"], "tags_cn": ["\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findCenter(vector>& edges) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findCenter(int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findCenter(self, edges):\n \"\"\"\n :type edges: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findCenter(self, edges: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findCenter(int** edges, int edgesSize, int* edgesColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindCenter(int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} edges\n * @return {number}\n */\nvar findCenter = function(edges) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} edges\n# @return {Integer}\ndef find_center(edges)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findCenter(_ edges: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findCenter(edges [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findCenter(edges: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findCenter(edges: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_center(edges: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $edges\n * @return Integer\n */\n function findCenter($edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findCenter(edges: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-center edges)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1791](https://leetcode-cn.com/problems/find-center-of-star-graph)", "[\u627e\u51fa\u661f\u578b\u56fe\u7684\u4e2d\u5fc3\u8282\u70b9](/solution/1700-1799/1791.Find%20Center%20of%20Star%20Graph/README.md)", "`\u56fe`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1791](https://leetcode.com/problems/find-center-of-star-graph)", "[Find Center of Star Graph](/solution/1700-1799/1791.Find%20Center%20of%20Star%20Graph/README_EN.md)", "`Graph`", "Medium", ""]}, {"question_id": "1915", "frontend_question_id": "1790", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/check-if-one-string-swap-can-make-strings-equal", "url_en": "https://leetcode.com/problems/check-if-one-string-swap-can-make-strings-equal", "relative_path_cn": "/solution/1700-1799/1790.Check%20if%20One%20String%20Swap%20Can%20Make%20Strings%20Equal/README.md", "relative_path_en": "/solution/1700-1799/1790.Check%20if%20One%20String%20Swap%20Can%20Make%20Strings%20Equal/README_EN.md", "title_cn": "\u4ec5\u6267\u884c\u4e00\u6b21\u5b57\u7b26\u4e32\u4ea4\u6362\u80fd\u5426\u4f7f\u4e24\u4e2a\u5b57\u7b26\u4e32\u76f8\u7b49", "title_en": "Check if One String Swap Can Make Strings Equal", "question_title_slug": "check-if-one-string-swap-can-make-strings-equal", "content_en": "

You are given two strings s1 and s2 of equal length. A string swap is an operation where you choose two indices in a string (not necessarily different) and swap the characters at these indices.

\n\n

Return true if it is possible to make both strings equal by performing at most one string swap on exactly one of the strings. Otherwise, return false.

\n\n

 

\n

Example 1:

\n\n
\nInput: s1 = "bank", s2 = "kanb"\nOutput: true\nExplanation: For example, swap the first character with the last character of s2 to make "bank".\n
\n\n

Example 2:

\n\n
\nInput: s1 = "attack", s2 = "defend"\nOutput: false\nExplanation: It is impossible to make them equal with one string swap.\n
\n\n

Example 3:

\n\n
\nInput: s1 = "kelb", s2 = "kelb"\nOutput: true\nExplanation: The two strings are already equal, so no string swap operation is required.\n
\n\n

Example 4:

\n\n
\nInput: s1 = "abcd", s2 = "dcba"\nOutput: false\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s1.length, s2.length <= 100
  • \n\t
  • s1.length == s2.length
  • \n\t
  • s1 and s2 consist of only lowercase English letters.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u957f\u5ea6\u76f8\u7b49\u7684\u4e24\u4e2a\u5b57\u7b26\u4e32 s1 \u548c s2 \u3002\u4e00\u6b21 \u5b57\u7b26\u4e32\u4ea4\u6362 \u64cd\u4f5c\u7684\u6b65\u9aa4\u5982\u4e0b\uff1a\u9009\u51fa\u67d0\u4e2a\u5b57\u7b26\u4e32\u4e2d\u7684\u4e24\u4e2a\u4e0b\u6807\uff08\u4e0d\u5fc5\u4e0d\u540c\uff09\uff0c\u5e76\u4ea4\u6362\u8fd9\u4e24\u4e2a\u4e0b\u6807\u6240\u5bf9\u5e94\u7684\u5b57\u7b26\u3002

\n\n

\u5982\u679c\u5bf9 \u5176\u4e2d\u4e00\u4e2a\u5b57\u7b26\u4e32 \u6267\u884c \u6700\u591a\u4e00\u6b21\u5b57\u7b26\u4e32\u4ea4\u6362 \u5c31\u53ef\u4ee5\u4f7f\u4e24\u4e2a\u5b57\u7b26\u4e32\u76f8\u7b49\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1as1 = \"bank\", s2 = \"kanb\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u4f8b\u5982\uff0c\u4ea4\u6362 s2 \u4e2d\u7684\u7b2c\u4e00\u4e2a\u548c\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\u53ef\u4ee5\u5f97\u5230 \"bank\"\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1as1 = \"attack\", s2 = \"defend\"\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u4e00\u6b21\u5b57\u7b26\u4e32\u4ea4\u6362\u65e0\u6cd5\u4f7f\u4e24\u4e2a\u5b57\u7b26\u4e32\u76f8\u7b49\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1as1 = \"kelb\", s2 = \"kelb\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u4e24\u4e2a\u5b57\u7b26\u4e32\u5df2\u7ecf\u76f8\u7b49\uff0c\u6240\u4ee5\u4e0d\u9700\u8981\u8fdb\u884c\u5b57\u7b26\u4e32\u4ea4\u6362\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1as1 = \"abcd\", s2 = \"dcba\"\n\u8f93\u51fa\uff1afalse\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s1.length, s2.length <= 100
  • \n\t
  • s1.length == s2.length
  • \n\t
  • s1 \u548c s2 \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool areAlmostEqual(string s1, string s2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean areAlmostEqual(String s1, String s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def areAlmostEqual(self, s1, s2):\n \"\"\"\n :type s1: str\n :type s2: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def areAlmostEqual(self, s1: str, s2: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool areAlmostEqual(char * s1, char * s2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool AreAlmostEqual(string s1, string s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s1\n * @param {string} s2\n * @return {boolean}\n */\nvar areAlmostEqual = function(s1, s2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s1\n# @param {String} s2\n# @return {Boolean}\ndef are_almost_equal(s1, s2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func areAlmostEqual(_ s1: String, _ s2: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func areAlmostEqual(s1 string, s2 string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def areAlmostEqual(s1: String, s2: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun areAlmostEqual(s1: String, s2: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn are_almost_equal(s1: String, s2: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s1\n * @param String $s2\n * @return Boolean\n */\n function areAlmostEqual($s1, $s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function areAlmostEqual(s1: string, s2: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (are-almost-equal s1 s2)\n (-> string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1790](https://leetcode-cn.com/problems/check-if-one-string-swap-can-make-strings-equal)", "[\u4ec5\u6267\u884c\u4e00\u6b21\u5b57\u7b26\u4e32\u4ea4\u6362\u80fd\u5426\u4f7f\u4e24\u4e2a\u5b57\u7b26\u4e32\u76f8\u7b49](/solution/1700-1799/1790.Check%20if%20One%20String%20Swap%20Can%20Make%20Strings%20Equal/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1790](https://leetcode.com/problems/check-if-one-string-swap-can-make-strings-equal)", "[Check if One String Swap Can Make Strings Equal](/solution/1700-1799/1790.Check%20if%20One%20String%20Swap%20Can%20Make%20Strings%20Equal/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1914", "frontend_question_id": "1767", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/find-the-subtasks-that-did-not-execute", "url_en": "https://leetcode.com/problems/find-the-subtasks-that-did-not-execute", "relative_path_cn": "/solution/1700-1799/1767.Find%20the%20Subtasks%20That%20Did%20Not%20Execute/README.md", "relative_path_en": "/solution/1700-1799/1767.Find%20the%20Subtasks%20That%20Did%20Not%20Execute/README_EN.md", "title_cn": "\u5bfb\u627e\u6ca1\u6709\u88ab\u6267\u884c\u7684\u4efb\u52a1\u5bf9", "title_en": "Find the Subtasks That Did Not Execute", "question_title_slug": "find-the-subtasks-that-did-not-execute", "content_en": "

Table: Tasks

\n\n
\n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| task_id        | int     |\n| subtasks_count | int     |\n+----------------+---------+\ntask_id is the primary key for this table.\nEach row in this table indicates that task_id was divided into subtasks_count subtasks labelled from 1 to subtasks_count.\nIt is guaranteed that 2 <= subtasks_count <= 20.\n
\n\n

 

\n\n

Table: Executed

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| task_id       | int     |\n| subtask_id    | int     |\n+---------------+---------+\n(task_id, subtask_id) is the primary key for this table.\nEach row in this table indicates that for the task task_id, the subtask with ID subtask_id was executed successfully.\nIt is guaranteed that subtask_id <= subtasks_count for each task_id.
\n\n

 

\n\n

Write an SQL query to report the IDs of the missing subtasks for each task_id.

\n\n

Return the result table in any order.

\n\n

The query result format is in the following example:

\n\n

 

\n\n
\nTasks table:\n+---------+----------------+\n| task_id | subtasks_count |\n+---------+----------------+\n| 1       | 3              |\n| 2       | 2              |\n| 3       | 4              |\n+---------+----------------+\n\nExecuted table:\n+---------+------------+\n| task_id | subtask_id |\n+---------+------------+\n| 1       | 2          |\n| 3       | 1          |\n| 3       | 2          |\n| 3       | 3          |\n| 3       | 4          |\n+---------+------------+\n\nResult table:\n+---------+------------+\n| task_id | subtask_id |\n+---------+------------+\n| 1       | 1          |\n| 1       | 3          |\n| 2       | 1          |\n| 2       | 2          |\n+---------+------------+\nTask 1 was divided into 3 subtasks (1, 2, 3). Only subtask 2 was executed successfully, so we include (1, 1) and (1, 3) in the answer.\nTask 2 was divided into 2 subtasks (1, 2). No subtask was executed successfully, so we include (2, 1) and (2, 2) in the answer.\nTask 3 was divided into 4 subtasks (1, 2, 3, 4). All of the subtasks were executed successfully.\n
\n", "content_cn": "

\u8868\uff1aTasks

\n\n
\n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| task_id        | int     |\n| subtasks_count | int     |\n+----------------+---------+\ntask_id \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\u3002\ntask_id \u8868\u793a\u7684\u4e3a\u4e3b\u4efb\u52a1\u7684id,\u6bcf\u4e00\u4e2atask_id\u88ab\u5206\u4e3a\u4e86\u591a\u4e2a\u5b50\u4efb\u52a1(subtasks)\uff0csubtasks_count\u8868\u793a\u4e3a\u5b50\u4efb\u52a1\u7684\u4e2a\u6570\uff08n\uff09\uff0c\u5b83\u7684\u503c\u8868\u793a\u4e86\u5b50\u4efb\u52a1\u7684\u7d22\u5f15\u4ece1\u5230n\u3002\n\u672c\u8868\u4fdd\u8bc12 <=subtasks_count<= 20\u3002\n
\n\n

\u8868\uff1a Executed

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| task_id       | int     |\n| subtask_id    | int     |\n+---------------+---------+\n(task_id, subtask_id) \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\u3002\n\u6bcf\u4e00\u884c\u8868\u793a\u6807\u8bb0\u4e3atask_id\u7684\u4e3b\u4efb\u52a1\u4e0e\u6807\u8bb0\u4e3asubtask_id\u7684\u5b50\u4efb\u52a1\u88ab\u6210\u529f\u6267\u884c\u3002\n\u672c\u8868\u4fdd\u8bc1\uff0c\u5bf9\u4e8e\u6bcf\u4e00\u4e2atask_id\uff0csubtask_id <= subtasks_count\u3002\n
\n\n

\u00a0

\n\n

\u8bf7\u8bd5\u5199\u4e00\u4e2aSQL\u67e5\u8be2\u8bed\u53e5\u62a5\u544a\u6ca1\u6709\u88ab\u6267\u884c\u7684\uff08\u4e3b\u4efb\u52a1\uff0c\u5b50\u4efb\u52a1\uff09\u5bf9\uff0c\u5373\u6ca1\u6709\u88ab\u6267\u884c\u7684\uff08task_id, subtask_id\uff09\u3002

\n\n

\u4ee5 \u4efb\u4f55\u987a\u5e8f \u8fd4\u56de\u5373\u53ef\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\uff1a

\n\n

\u00a0

\n\n
\nTasks table:\n+---------+----------------+\n| task_id | subtasks_count |\n+---------+----------------+\n| 1       | 3              |\n| 2       | 2              |\n| 3       | 4              |\n+---------+----------------+\n\nExecuted table:\n+---------+------------+\n| task_id | subtask_id |\n+---------+------------+\n| 1       | 2          |\n| 3       | 1          |\n| 3       | 2          |\n| 3       | 3          |\n| 3       | 4          |\n+---------+------------+\n\nResult table:\n+---------+------------+\n| task_id | subtask_id |\n+---------+------------+\n| 1       | 1          |\n| 1       | 3          |\n| 2       | 1          |\n| 2       | 2          |\n+---------+------------+\nTask 1 \u88ab\u5206\u6210\u4e86 3 subtasks (1, 2, 3)\u3002\u53ea\u6709 subtask 2 \u88ab\u6210\u529f\u6267\u884c, \u6240\u4ee5\u6211\u4eec\u8fd4\u56de (1, 1) \u548c (1, 3) \u8fd9\u4e24\u4e2a\u4e3b\u4efb\u52a1\u5b50\u4efb\u52a1\u5bf9\u3002\nTask 2 \u88ab\u5206\u6210\u4e86 2 subtasks (1, 2)\u3002\u6ca1\u6709\u4e00\u4e2asubtask\u88ab\u6210\u529f\u6267\u884c, \u56e0\u6b64\u6211\u4eec\u8fd4\u56de(2, 1)\u548c(2, 2)\u3002\nTask 3 \u88ab\u5206\u6210\u4e86 4 subtasks (1, 2, 3, 4)\u3002\u6240\u6709\u7684subtask\u90fd\u88ab\u6210\u529f\u6267\u884c\uff0c\u56e0\u6b64\u5bf9\u4e8eTask 3,\u6211\u4eec\u4e0d\u8fd4\u56de\u4efb\u4f55\u503c\u3002\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1767](https://leetcode-cn.com/problems/find-the-subtasks-that-did-not-execute)", "[\u5bfb\u627e\u6ca1\u6709\u88ab\u6267\u884c\u7684\u4efb\u52a1\u5bf9](/solution/1700-1799/1767.Find%20the%20Subtasks%20That%20Did%20Not%20Execute/README.md)", "", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1767](https://leetcode.com/problems/find-the-subtasks-that-did-not-execute)", "[Find the Subtasks That Did Not Execute](/solution/1700-1799/1767.Find%20the%20Subtasks%20That%20Did%20Not%20Execute/README_EN.md)", "", "Hard", "\ud83d\udd12"]}, {"question_id": "1913", "frontend_question_id": "1787", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/make-the-xor-of-all-segments-equal-to-zero", "url_en": "https://leetcode.com/problems/make-the-xor-of-all-segments-equal-to-zero", "relative_path_cn": "/solution/1700-1799/1787.Make%20the%20XOR%20of%20All%20Segments%20Equal%20to%20Zero/README.md", "relative_path_en": "/solution/1700-1799/1787.Make%20the%20XOR%20of%20All%20Segments%20Equal%20to%20Zero/README_EN.md", "title_cn": "\u4f7f\u6240\u6709\u533a\u95f4\u7684\u5f02\u6216\u7ed3\u679c\u4e3a\u96f6", "title_en": "Make the XOR of All Segments Equal to Zero", "question_title_slug": "make-the-xor-of-all-segments-equal-to-zero", "content_en": "

You are given an array nums\u200b\u200b\u200b and an integer k\u200b\u200b\u200b\u200b\u200b. The XOR of a segment [left, right] where left <= right is the XOR of all the elements with indices between left and right, inclusive: nums[left] XOR nums[left+1] XOR ... XOR nums[right].

\n\n

Return the minimum number of elements to change in the array such that the XOR of all segments of size k\u200b\u200b\u200b\u200b\u200b\u200b is equal to zero.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [1,2,0,3,0], k = 1\nOutput: 3\nExplanation: Modify the array from [1,2,0,3,0] to from [0,0,0,0,0].\n
\n\n

Example 2:

\n\n
\nInput: nums = [3,4,5,2,1,7,3,4,7], k = 3\nOutput: 3\nExplanation: Modify the array from [3,4,5,2,1,7,3,4,7] to [3,4,7,3,4,7,3,4,7].\n
\n\n

Example 3:

\n\n
\nInput: nums = [1,2,4,1,2,5,1,2,6], k = 3\nOutput: 3\nExplanation: Modify the array from [1,2,4,1,2,5,1,2,6] to [1,2,3,1,2,3,1,2,3].
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= k <= nums.length <= 2000
  • \n\t
  • \u200b\u200b\u200b\u200b\u200b\u200b0 <= nums[i] < 210
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums\u200b\u200b\u200b \u548c\u4e00\u4e2a\u6574\u6570 k\u200b\u200b\u200b\u200b\u200b \u3002\u533a\u95f4 [left, right]\uff08left <= right\uff09\u7684 \u5f02\u6216\u7ed3\u679c \u662f\u5bf9\u4e0b\u6807\u4f4d\u4e8e\u00a0left \u548c right\uff08\u5305\u62ec left \u548c right \uff09\u4e4b\u95f4\u6240\u6709\u5143\u7d20\u8fdb\u884c XOR \u8fd0\u7b97\u7684\u7ed3\u679c\uff1anums[left] XOR nums[left+1] XOR ... XOR nums[right] \u3002

\n\n

\u8fd4\u56de\u6570\u7ec4\u4e2d \u8981\u66f4\u6539\u7684\u6700\u5c0f\u5143\u7d20\u6570 \uff0c\u4ee5\u4f7f\u6240\u6709\u957f\u5ea6\u4e3a k \u7684\u533a\u95f4\u5f02\u6216\u7ed3\u679c\u7b49\u4e8e\u96f6\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [1,2,0,3,0], k = 1\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u5c06\u6570\u7ec4 [1,2,0,3,0] \u4fee\u6539\u4e3a [0,0,0,0,0]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [3,4,5,2,1,7,3,4,7], k = 3\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u5c06\u6570\u7ec4 [3,4,5,2,1,7,3,4,7] \u4fee\u6539\u4e3a [3,4,7,3,4,7,3,4,7]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [1,2,4,1,2,5,1,2,6], k = 3\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u5c06\u6570\u7ec4[1,2,4,1,2,5,1,2,6] \u4fee\u6539\u4e3a [1,2,3,1,2,3,1,2,3]
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= k <= nums.length <= 2000
  • \n\t
  • \u200b\u200b\u200b\u200b\u200b\u200b0 <= nums[i] < 210
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minChanges(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minChanges(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minChanges(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minChanges(self, nums: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minChanges(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinChanges(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar minChanges = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef min_changes(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minChanges(_ nums: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minChanges(nums []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minChanges(nums: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minChanges(nums: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_changes(nums: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer\n */\n function minChanges($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minChanges(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-changes nums k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1787](https://leetcode-cn.com/problems/make-the-xor-of-all-segments-equal-to-zero)", "[\u4f7f\u6240\u6709\u533a\u95f4\u7684\u5f02\u6216\u7ed3\u679c\u4e3a\u96f6](/solution/1700-1799/1787.Make%20the%20XOR%20of%20All%20Segments%20Equal%20to%20Zero/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1787](https://leetcode.com/problems/make-the-xor-of-all-segments-equal-to-zero)", "[Make the XOR of All Segments Equal to Zero](/solution/1700-1799/1787.Make%20the%20XOR%20of%20All%20Segments%20Equal%20to%20Zero/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1912", "frontend_question_id": "1786", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-restricted-paths-from-first-to-last-node", "url_en": "https://leetcode.com/problems/number-of-restricted-paths-from-first-to-last-node", "relative_path_cn": "/solution/1700-1799/1786.Number%20of%20Restricted%20Paths%20From%20First%20to%20Last%20Node/README.md", "relative_path_en": "/solution/1700-1799/1786.Number%20of%20Restricted%20Paths%20From%20First%20to%20Last%20Node/README_EN.md", "title_cn": "\u4ece\u7b2c\u4e00\u4e2a\u8282\u70b9\u51fa\u53d1\u5230\u6700\u540e\u4e00\u4e2a\u8282\u70b9\u7684\u53d7\u9650\u8def\u5f84\u6570", "title_en": "Number of Restricted Paths From First to Last Node", "question_title_slug": "number-of-restricted-paths-from-first-to-last-node", "content_en": "

There is an undirected weighted connected graph. You are given a positive integer n which denotes that the graph has n nodes labeled from 1 to n, and an array edges where each edges[i] = [ui, vi, weighti] denotes that there is an edge between nodes ui and vi with weight equal to weighti.

\n\n

A path from node start to node end is a sequence of nodes [z0, z1, z2, ..., zk] such that z0 = start and zk = end and there is an edge between zi and zi+1 where 0 <= i <= k-1.

\n\n

The distance of a path is the sum of the weights on the edges of the path. Let distanceToLastNode(x) denote the shortest distance of a path between node n and node x. A restricted path is a path that also satisfies that distanceToLastNode(zi) > distanceToLastNode(zi+1) where 0 <= i <= k-1.

\n\n

Return the number of restricted paths from node 1 to node n. Since that number may be too large, return it modulo 109 + 7.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: n = 5, edges = [[1,2,3],[1,3,3],[2,3,1],[1,4,2],[5,2,2],[3,5,1],[5,4,10]]\nOutput: 3\nExplanation: Each circle contains the node number in black and its distanceToLastNode value in blue. The three restricted paths are:\n1) 1 --> 2 --> 5\n2) 1 --> 2 --> 3 --> 5\n3) 1 --> 3 --> 5\n
\n\n

Example 2:

\n\"\"\n
\nInput: n = 7, edges = [[1,3,1],[4,1,2],[7,3,4],[2,5,3],[5,6,1],[6,7,2],[7,5,3],[2,6,4]]\nOutput: 1\nExplanation: Each circle contains the node number in black and its distanceToLastNode value in blue. The only restricted path is 1 --> 3 --> 7.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 2 * 104
  • \n\t
  • n - 1 <= edges.length <= 4 * 104
  • \n\t
  • edges[i].length == 3
  • \n\t
  • 1 <= ui, vi <= n
  • \n\t
  • ui != vi
  • \n\t
  • 1 <= weighti <= 105
  • \n\t
  • There is at most one edge between any two nodes.
  • \n\t
  • There is at least one path between any two nodes.
  • \n
\n", "content_cn": "

\u73b0\u6709\u4e00\u4e2a\u52a0\u6743\u65e0\u5411\u8fde\u901a\u56fe\u3002\u7ed9\u4f60\u4e00\u4e2a\u6b63\u6574\u6570 n \uff0c\u8868\u793a\u56fe\u4e2d\u6709 n \u4e2a\u8282\u70b9\uff0c\u5e76\u6309\u4ece 1 \u5230 n \u7ed9\u8282\u70b9\u7f16\u53f7\uff1b\u53e6\u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 edges \uff0c\u5176\u4e2d\u6bcf\u4e2a edges[i] = [ui, vi, weighti] \u8868\u793a\u5b58\u5728\u4e00\u6761\u4f4d\u4e8e\u8282\u70b9 ui \u548c vi \u4e4b\u95f4\u7684\u8fb9\uff0c\u8fd9\u6761\u8fb9\u7684\u6743\u91cd\u4e3a weighti \u3002

\n\n

\u4ece\u8282\u70b9 start \u51fa\u53d1\u5230\u8282\u70b9 end \u7684\u8def\u5f84\u662f\u4e00\u4e2a\u5f62\u5982 [z0, z1, z2, ..., zk] \u7684\u8282\u70b9\u5e8f\u5217\uff0c\u6ee1\u8db3 z0 = start \u3001zk = end \u4e14\u5728\u6240\u6709\u7b26\u5408 0 <= i <= k-1 \u7684\u8282\u70b9 zi \u548c zi+1 \u4e4b\u95f4\u5b58\u5728\u4e00\u6761\u8fb9\u3002

\n\n

\u8def\u5f84\u7684\u8ddd\u79bb\u5b9a\u4e49\u4e3a\u8fd9\u6761\u8def\u5f84\u4e0a\u6240\u6709\u8fb9\u7684\u6743\u91cd\u603b\u548c\u3002\u7528 distanceToLastNode(x) \u8868\u793a\u8282\u70b9 n \u548c x \u4e4b\u95f4\u8def\u5f84\u7684\u6700\u77ed\u8ddd\u79bb\u3002\u53d7\u9650\u8def\u5f84 \u4e3a\u6ee1\u8db3 distanceToLastNode(zi) > distanceToLastNode(zi+1) \u7684\u4e00\u6761\u8def\u5f84\uff0c\u5176\u4e2d 0 <= i <= k-1 \u3002

\n\n

\u8fd4\u56de\u4ece\u8282\u70b9 1 \u51fa\u53d1\u5230\u8282\u70b9 n \u7684 \u53d7\u9650\u8def\u5f84\u6570 \u3002\u7531\u4e8e\u6570\u5b57\u53ef\u80fd\u5f88\u5927\uff0c\u8bf7\u8fd4\u56de\u5bf9 109 + 7 \u53d6\u4f59 \u7684\u7ed3\u679c\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1an = 5, edges = [[1,2,3],[1,3,3],[2,3,1],[1,4,2],[5,2,2],[3,5,1],[5,4,10]]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6bcf\u4e2a\u5706\u5305\u542b\u9ed1\u8272\u7684\u8282\u70b9\u7f16\u53f7\u548c\u84dd\u8272\u7684 distanceToLastNode \u503c\u3002\u4e09\u6761\u53d7\u9650\u8def\u5f84\u5206\u522b\u662f\uff1a\n1) 1 --> 2 --> 5\n2) 1 --> 2 --> 3 --> 5\n3) 1 --> 3 --> 5\n
\n\n

\u793a\u4f8b 2\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1an = 7, edges = [[1,3,1],[4,1,2],[7,3,4],[2,5,3],[5,6,1],[6,7,2],[7,5,3],[2,6,4]]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u6bcf\u4e2a\u5706\u5305\u542b\u9ed1\u8272\u7684\u8282\u70b9\u7f16\u53f7\u548c\u84dd\u8272\u7684 distanceToLastNode \u503c\u3002\u552f\u4e00\u4e00\u6761\u53d7\u9650\u8def\u5f84\u662f\uff1a1 --> 3 --> 7 \u3002
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 2 * 104
  • \n\t
  • n - 1 <= edges.length <= 4 * 104
  • \n\t
  • edges[i].length == 3
  • \n\t
  • 1 <= ui, vi <= n
  • \n\t
  • ui != vi
  • \n\t
  • 1 <= weighti <= 105
  • \n\t
  • \u4efb\u610f\u4e24\u4e2a\u8282\u70b9\u4e4b\u95f4\u81f3\u591a\u5b58\u5728\u4e00\u6761\u8fb9
  • \n\t
  • \u4efb\u610f\u4e24\u4e2a\u8282\u70b9\u4e4b\u95f4\u81f3\u5c11\u5b58\u5728\u4e00\u6761\u8def\u5f84
  • \n
\n", "tags_en": ["Graph", "Dynamic Programming"], "tags_cn": ["\u56fe", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countRestrictedPaths(int n, vector>& edges) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countRestrictedPaths(int n, int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countRestrictedPaths(self, n, edges):\n \"\"\"\n :type n: int\n :type edges: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countRestrictedPaths(self, n: int, edges: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countRestrictedPaths(int n, int** edges, int edgesSize, int* edgesColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountRestrictedPaths(int n, int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} edges\n * @return {number}\n */\nvar countRestrictedPaths = function(n, edges) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} edges\n# @return {Integer}\ndef count_restricted_paths(n, edges)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countRestrictedPaths(_ n: Int, _ edges: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countRestrictedPaths(n int, edges [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countRestrictedPaths(n: Int, edges: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countRestrictedPaths(n: Int, edges: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_restricted_paths(n: i32, edges: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $edges\n * @return Integer\n */\n function countRestrictedPaths($n, $edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countRestrictedPaths(n: number, edges: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-restricted-paths n edges)\n (-> exact-integer? (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1786](https://leetcode-cn.com/problems/number-of-restricted-paths-from-first-to-last-node)", "[\u4ece\u7b2c\u4e00\u4e2a\u8282\u70b9\u51fa\u53d1\u5230\u6700\u540e\u4e00\u4e2a\u8282\u70b9\u7684\u53d7\u9650\u8def\u5f84\u6570](/solution/1700-1799/1786.Number%20of%20Restricted%20Paths%20From%20First%20to%20Last%20Node/README.md)", "`\u56fe`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1786](https://leetcode.com/problems/number-of-restricted-paths-from-first-to-last-node)", "[Number of Restricted Paths From First to Last Node](/solution/1700-1799/1786.Number%20of%20Restricted%20Paths%20From%20First%20to%20Last%20Node/README_EN.md)", "`Graph`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "1911", "frontend_question_id": "1785", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-elements-to-add-to-form-a-given-sum", "url_en": "https://leetcode.com/problems/minimum-elements-to-add-to-form-a-given-sum", "relative_path_cn": "/solution/1700-1799/1785.Minimum%20Elements%20to%20Add%20to%20Form%20a%20Given%20Sum/README.md", "relative_path_en": "/solution/1700-1799/1785.Minimum%20Elements%20to%20Add%20to%20Form%20a%20Given%20Sum/README_EN.md", "title_cn": "\u6784\u6210\u7279\u5b9a\u548c\u9700\u8981\u6dfb\u52a0\u7684\u6700\u5c11\u5143\u7d20", "title_en": "Minimum Elements to Add to Form a Given Sum", "question_title_slug": "minimum-elements-to-add-to-form-a-given-sum", "content_en": "

You are given an integer array nums and two integers limit and goal. The array nums has an interesting property that abs(nums[i]) <= limit.

\n\n

Return the minimum number of elements you need to add to make the sum of the array equal to goal. The array must maintain its property that abs(nums[i]) <= limit.

\n\n

Note that abs(x) equals x if x >= 0, and -x otherwise.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [1,-1,1], limit = 3, goal = -4\nOutput: 2\nExplanation: You can add -2 and -3, then the sum of the array will be 1 - 1 + 1 - 2 - 3 = -4.\n
\n\n

Example 2:

\n\n
\nInput: nums = [1,-10,9,1], limit = 100, goal = 0\nOutput: 1\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 105
  • \n\t
  • 1 <= limit <= 106
  • \n\t
  • -limit <= nums[i] <= limit
  • \n\t
  • -109 <= goal <= 109
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \uff0c\u548c\u4e24\u4e2a\u6574\u6570 limit \u4e0e goal \u3002\u6570\u7ec4 nums \u6709\u4e00\u6761\u91cd\u8981\u5c5e\u6027\uff1aabs(nums[i]) <= limit \u3002

\n\n

\u8fd4\u56de\u4f7f\u6570\u7ec4\u5143\u7d20\u603b\u548c\u7b49\u4e8e goal \u6240\u9700\u8981\u5411\u6570\u7ec4\u4e2d\u6dfb\u52a0\u7684 \u6700\u5c11\u5143\u7d20\u6570\u91cf \uff0c\u6dfb\u52a0\u5143\u7d20 \u4e0d\u5e94\u6539\u53d8 \u6570\u7ec4\u4e2d abs(nums[i]) <= limit \u8fd9\u4e00\u5c5e\u6027\u3002

\n\n

\u6ce8\u610f\uff0c\u5982\u679c x >= 0 \uff0c\u90a3\u4e48 abs(x) \u7b49\u4e8e x \uff1b\u5426\u5219\uff0c\u7b49\u4e8e -x \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [1,-1,1], limit = 3, goal = -4\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u53ef\u4ee5\u5c06 -2 \u548c -3 \u6dfb\u52a0\u5230\u6570\u7ec4\u4e2d\uff0c\u6570\u7ec4\u7684\u5143\u7d20\u603b\u548c\u53d8\u4e3a 1 - 1 + 1 - 2 - 3 = -4 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [1,-10,9,1], limit = 100, goal = 0\n\u8f93\u51fa\uff1a1\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 105
  • \n\t
  • 1 <= limit <= 106
  • \n\t
  • -limit <= nums[i] <= limit
  • \n\t
  • -109 <= goal <= 109
  • \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minElements(vector& nums, int limit, int goal) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minElements(int[] nums, int limit, int goal) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minElements(self, nums, limit, goal):\n \"\"\"\n :type nums: List[int]\n :type limit: int\n :type goal: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minElements(self, nums: List[int], limit: int, goal: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minElements(int* nums, int numsSize, int limit, int goal){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinElements(int[] nums, int limit, int goal) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} limit\n * @param {number} goal\n * @return {number}\n */\nvar minElements = function(nums, limit, goal) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} limit\n# @param {Integer} goal\n# @return {Integer}\ndef min_elements(nums, limit, goal)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minElements(_ nums: [Int], _ limit: Int, _ goal: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minElements(nums []int, limit int, goal int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minElements(nums: Array[Int], limit: Int, goal: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minElements(nums: IntArray, limit: Int, goal: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_elements(nums: Vec, limit: i32, goal: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $limit\n * @param Integer $goal\n * @return Integer\n */\n function minElements($nums, $limit, $goal) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minElements(nums: number[], limit: number, goal: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-elements nums limit goal)\n (-> (listof exact-integer?) exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1785](https://leetcode-cn.com/problems/minimum-elements-to-add-to-form-a-given-sum)", "[\u6784\u6210\u7279\u5b9a\u548c\u9700\u8981\u6dfb\u52a0\u7684\u6700\u5c11\u5143\u7d20](/solution/1700-1799/1785.Minimum%20Elements%20to%20Add%20to%20Form%20a%20Given%20Sum/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1785](https://leetcode.com/problems/minimum-elements-to-add-to-form-a-given-sum)", "[Minimum Elements to Add to Form a Given Sum](/solution/1700-1799/1785.Minimum%20Elements%20to%20Add%20to%20Form%20a%20Given%20Sum/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1910", "frontend_question_id": "1784", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/check-if-binary-string-has-at-most-one-segment-of-ones", "url_en": "https://leetcode.com/problems/check-if-binary-string-has-at-most-one-segment-of-ones", "relative_path_cn": "/solution/1700-1799/1784.Check%20if%20Binary%20String%20Has%20at%20Most%20One%20Segment%20of%20Ones/README.md", "relative_path_en": "/solution/1700-1799/1784.Check%20if%20Binary%20String%20Has%20at%20Most%20One%20Segment%20of%20Ones/README_EN.md", "title_cn": "\u68c0\u67e5\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32\u5b57\u6bb5", "title_en": "Check if Binary String Has at Most One Segment of Ones", "question_title_slug": "check-if-binary-string-has-at-most-one-segment-of-ones", "content_en": "

Given a binary string s \u200b\u200b\u200b\u200b\u200bwithout leading zeros, return true\u200b\u200b\u200b if s contains at most one contiguous segment of ones. Otherwise, return false.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "1001"\nOutput: false\nExplanation: The ones do not form a contiguous segment.\n
\n\n

Example 2:

\n\n
\nInput: s = "110"\nOutput: true
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 100
  • \n\t
  • s[i]\u200b\u200b\u200b\u200b is either '0' or '1'.
  • \n\t
  • s[0] is '1'.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32 s \uff0c\u8be5\u5b57\u7b26\u4e32 \u4e0d\u542b\u524d\u5bfc\u96f6 \u3002

\n\n

\u5982\u679c s \u6700\u591a\u5305\u542b \u4e00\u4e2a\u7531\u8fde\u7eed\u7684 '1' \u7ec4\u6210\u7684\u5b57\u6bb5 \uff0c\u8fd4\u56de true\u200b\u200b\u200b \u3002\u5426\u5219\uff0c\u8fd4\u56de false \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"1001\"\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u5b57\u7b26\u4e32\u4e2d\u7684 1 \u6ca1\u6709\u5f62\u6210\u4e00\u4e2a\u8fde\u7eed\u5b57\u6bb5\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"110\"\n\u8f93\u51fa\uff1atrue
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length <= 100
  • \n\t
  • s[i]\u200b\u200b\u200b\u200b \u4e3a '0' \u6216 '1'
  • \n\t
  • s[0] \u4e3a '1'
  • \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool checkOnesSegment(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean checkOnesSegment(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def checkOnesSegment(self, s):\n \"\"\"\n :type s: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def checkOnesSegment(self, s: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool checkOnesSegment(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CheckOnesSegment(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {boolean}\n */\nvar checkOnesSegment = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Boolean}\ndef check_ones_segment(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func checkOnesSegment(_ s: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func checkOnesSegment(s string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def checkOnesSegment(s: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun checkOnesSegment(s: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn check_ones_segment(s: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Boolean\n */\n function checkOnesSegment($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function checkOnesSegment(s: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (check-ones-segment s)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1784](https://leetcode-cn.com/problems/check-if-binary-string-has-at-most-one-segment-of-ones)", "[\u68c0\u67e5\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32\u5b57\u6bb5](/solution/1700-1799/1784.Check%20if%20Binary%20String%20Has%20at%20Most%20One%20Segment%20of%20Ones/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u7b80\u5355", ""], "md_table_row_en": ["[1784](https://leetcode.com/problems/check-if-binary-string-has-at-most-one-segment-of-ones)", "[Check if Binary String Has at Most One Segment of Ones](/solution/1700-1799/1784.Check%20if%20Binary%20String%20Has%20at%20Most%20One%20Segment%20of%20Ones/README_EN.md)", "`Greedy`", "Easy", ""]}, {"question_id": "1909", "frontend_question_id": "1762", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/buildings-with-an-ocean-view", "url_en": "https://leetcode.com/problems/buildings-with-an-ocean-view", "relative_path_cn": "/solution/1700-1799/1762.Buildings%20With%20an%20Ocean%20View/README.md", "relative_path_en": "/solution/1700-1799/1762.Buildings%20With%20an%20Ocean%20View/README_EN.md", "title_cn": "\u80fd\u770b\u5230\u6d77\u666f\u7684\u5efa\u7b51\u7269", "title_en": "Buildings With an Ocean View", "question_title_slug": "buildings-with-an-ocean-view", "content_en": "

There are n buildings in a line. You are given an integer array heights of size n that represents the heights of the buildings in the line.

\r\n\r\n

The ocean is to the right of the buildings. A building has an ocean view if the building can see the ocean without obstructions. Formally, a building has an ocean view if all the buildings to its right have a smaller height.

\r\n\r\n

Return a list of indices (0-indexed) of buildings that have an ocean view, sorted in increasing order.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: heights = [4,2,3,1]\r\nOutput: [0,2,3]\r\nExplanation: Building 1 (0-indexed) does not have an ocean view because building 2 is taller.\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: heights = [4,3,2,1]\r\nOutput: [0,1,2,3]\r\nExplanation: All the buildings have an ocean view.
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: heights = [1,3,2,4]\r\nOutput: [3]\r\nExplanation: Only building 3 has an ocean view.
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: heights = [2,2,2,2]\r\nOutput: [3]\r\nExplanation: Buildings cannot see the ocean if there are buildings of the same height to its right.
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= heights.length <= 105
  • \r\n\t
  • 1 <= heights[i] <= 109
  • \r\n
", "content_cn": "

\u6709 n \u5ea7\u5efa\u7b51\u7269\u3002\u7ed9\u4f60\u4e00\u4e2a\u5927\u5c0f\u4e3a n \u7684\u6574\u6570\u6570\u7ec4 heights \u8868\u793a\u6bcf\u4e00\u4e2a\u5efa\u7b51\u7269\u7684\u9ad8\u5ea6\u3002

\n\n

\u5efa\u7b51\u7269\u7684\u53f3\u8fb9\u662f\u6d77\u6d0b\u3002\u5982\u679c\u5efa\u7b51\u7269\u53ef\u4ee5\u65e0\u969c\u788d\u5730\u770b\u5230\u6d77\u6d0b\uff0c\u5219\u5efa\u7b51\u7269\u80fd\u770b\u5230\u6d77\u666f\u3002\u786e\u5207\u5730\u8bf4\uff0c\u5982\u679c\u4e00\u5ea7\u5efa\u7b51\u7269\u53f3\u8fb9\u7684\u6240\u6709\u5efa\u7b51\u90fd\u6bd4\u5b83 \u77ee \u65f6\uff0c\u5c31\u8ba4\u4e3a\u5b83\u80fd\u770b\u5230\u6d77\u666f\u3002

\n\n

\u8fd4\u56de\u80fd\u770b\u5230\u6d77\u666f\u5efa\u7b51\u7269\u7684\u4e0b\u6807\u5217\u8868\uff08\u4e0b\u6807 \u4ece 0 \u5f00\u59cb \uff09\uff0c\u5e76\u6309\u5347\u5e8f\u6392\u5217\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aheights = [4,2,3,1]\n\u8f93\u51fa\uff1a[0,2,3]\n\u89e3\u91ca\uff1a1 \u53f7\u5efa\u7b51\u7269\u770b\u4e0d\u5230\u6d77\u666f\uff0c\u56e0\u4e3a 2 \u53f7\u5efa\u7b51\u7269\u6bd4\u5b83\u9ad8\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aheights = [4,3,2,1]\n\u8f93\u51fa\uff1a[0,1,2,3]\n\u89e3\u91ca\uff1a\u6240\u6709\u7684\u5efa\u7b51\u7269\u90fd\u80fd\u770b\u5230\u6d77\u666f\u3002
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1aheights = [1,3,2,4]\n\u8f93\u51fa\uff1a[3]\n\u89e3\u91ca\uff1a\u53ea\u6709 3 \u53f7\u5efa\u7b51\u7269\u80fd\u770b\u5230\u6d77\u666f\u3002
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1aheights = [2,2,2,2]\n\u8f93\u51fa\uff1a[3]\n\u89e3\u91ca\uff1a\u5982\u679c\u5efa\u7b51\u7269\u53f3\u8fb9\u6709\u76f8\u540c\u9ad8\u5ea6\u7684\u5efa\u7b51\u7269\u5219\u65e0\u6cd5\u770b\u5230\u6d77\u666f\u3002
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= heights.length <= 105
  • \n\t
  • 1 <= heights[i] <= 109
  • \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findBuildings(vector& heights) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] findBuildings(int[] heights) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findBuildings(self, heights):\n \"\"\"\n :type heights: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findBuildings(self, heights: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* findBuildings(int* heights, int heightsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] FindBuildings(int[] heights) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} heights\n * @return {number[]}\n */\nvar findBuildings = function(heights) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} heights\n# @return {Integer[]}\ndef find_buildings(heights)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findBuildings(_ heights: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findBuildings(heights []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findBuildings(heights: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findBuildings(heights: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_buildings(heights: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $heights\n * @return Integer[]\n */\n function findBuildings($heights) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findBuildings(heights: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-buildings heights)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1762](https://leetcode-cn.com/problems/buildings-with-an-ocean-view)", "[\u80fd\u770b\u5230\u6d77\u666f\u7684\u5efa\u7b51\u7269](/solution/1700-1799/1762.Buildings%20With%20an%20Ocean%20View/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1762](https://leetcode.com/problems/buildings-with-an-ocean-view)", "[Buildings With an Ocean View](/solution/1700-1799/1762.Buildings%20With%20an%20Ocean%20View/README_EN.md)", "`Greedy`", "Medium", "\ud83d\udd12"]}, {"question_id": "1908", "frontend_question_id": "1757", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/recyclable-and-low-fat-products", "url_en": "https://leetcode.com/problems/recyclable-and-low-fat-products", "relative_path_cn": "/solution/1700-1799/1757.Recyclable%20and%20Low%20Fat%20Products/README.md", "relative_path_en": "/solution/1700-1799/1757.Recyclable%20and%20Low%20Fat%20Products/README_EN.md", "title_cn": "\u53ef\u56de\u6536\u4e14\u4f4e\u8102\u7684\u4ea7\u54c1", "title_en": "Recyclable and Low Fat Products", "question_title_slug": "recyclable-and-low-fat-products", "content_en": "

Table: Products

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| product_id  | int     |\n| low_fats    | enum    |\n| recyclable  | enum    |\n+-------------+---------+\nproduct_id is the primary key for this table.\nlow_fats is an ENUM of type ('Y', 'N') where 'Y' means this product is low fat and 'N' means it is not.\nrecyclable is an ENUM of types ('Y', 'N') where 'Y' means this product is recyclable and 'N' means it is not.
\n\n

 

\n\n

Write an SQL query to find the ids of products that are both low fat and recyclable.

\n\n

Return the result table in any order.

\n\n

The query result format is in the following example:

\n\n

 

\n\n
\nProducts table:\n+-------------+----------+------------+\n| product_id  | low_fats | recyclable |\n+-------------+----------+------------+\n| 0           | Y        | N          |\n| 1           | Y        | Y          |\n| 2           | N        | Y          |\n| 3           | Y        | Y          |\n| 4           | N        | N          |\n+-------------+----------+------------+\nResult table:\n+-------------+\n| product_id  |\n+-------------+\n| 1           |\n| 3           |\n+-------------+\nOnly products 1 and 3 are both low fat and recyclable.\n
\n", "content_cn": "

\u8868\uff1aProducts

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| product_id  | int     |\n| low_fats    | enum    |\n| recyclable  | enum    |\n+-------------+---------+\nproduct_id \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\u3002\nlow_fats \u662f\u679a\u4e3e\u7c7b\u578b\uff0c\u53d6\u503c\u4e3a\u4ee5\u4e0b\u4e24\u79cd ('Y', 'N')\uff0c\u5176\u4e2d 'Y' \u8868\u793a\u8be5\u4ea7\u54c1\u662f\u4f4e\u8102\u4ea7\u54c1\uff0c'N' \u8868\u793a\u4e0d\u662f\u4f4e\u8102\u4ea7\u54c1\u3002\nrecyclable \u662f\u679a\u4e3e\u7c7b\u578b\uff0c\u53d6\u503c\u4e3a\u4ee5\u4e0b\u4e24\u79cd ('Y', 'N')\uff0c\u5176\u4e2d 'Y' \u8868\u793a\u8be5\u4ea7\u54c1\u53ef\u56de\u6536\uff0c\u800c 'N' \u8868\u793a\u4e0d\u53ef\u56de\u6536\u3002
\n\n

\u00a0

\n\n

\u5199\u51fa SQL \u8bed\u53e5\uff0c\u67e5\u627e\u65e2\u662f\u4f4e\u8102\u53c8\u662f\u53ef\u56de\u6536\u7684\u4ea7\u54c1\u7f16\u53f7\u3002

\n\n

\u8fd4\u56de\u7ed3\u679c \u65e0\u987a\u5e8f\u8981\u6c42 \u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a\uff1a

\n\n
\nProducts \u8868\uff1a\n+-------------+----------+------------+\n| product_id  | low_fats | recyclable |\n+-------------+----------+------------+\n| 0           | Y        | N          |\n| 1           | Y        | Y          |\n| 2           | N        | Y          |\n| 3           | Y        | Y          |\n| 4           | N        | N          |\n+-------------+----------+------------+\nResult \u8868\uff1a\n+-------------+\n| product_id  |\n+-------------+\n| 1           |\n| 3           |\n+-------------+\n\u53ea\u6709\u4ea7\u54c1 id \u4e3a 1 \u548c 3 \u7684\u4ea7\u54c1\uff0c\u65e2\u662f\u4f4e\u8102\u53c8\u662f\u53ef\u56de\u6536\u7684\u4ea7\u54c1\u3002\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1757](https://leetcode-cn.com/problems/recyclable-and-low-fat-products)", "[\u53ef\u56de\u6536\u4e14\u4f4e\u8102\u7684\u4ea7\u54c1](/solution/1700-1799/1757.Recyclable%20and%20Low%20Fat%20Products/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1757](https://leetcode.com/problems/recyclable-and-low-fat-products)", "[Recyclable and Low Fat Products](/solution/1700-1799/1757.Recyclable%20and%20Low%20Fat%20Products/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1907", "frontend_question_id": "1803", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-pairs-with-xor-in-a-range", "url_en": "https://leetcode.com/problems/count-pairs-with-xor-in-a-range", "relative_path_cn": "/solution/1800-1899/1803.Count%20Pairs%20With%20XOR%20in%20a%20Range/README.md", "relative_path_en": "/solution/1800-1899/1803.Count%20Pairs%20With%20XOR%20in%20a%20Range/README_EN.md", "title_cn": "\u7edf\u8ba1\u5f02\u6216\u503c\u5728\u8303\u56f4\u5185\u7684\u6570\u5bf9\u6709\u591a\u5c11", "title_en": "Count Pairs With XOR in a Range", "question_title_slug": "count-pairs-with-xor-in-a-range", "content_en": "

Given a (0-indexed) integer array nums and two integers low and high, return the number of nice pairs.

\r\n\r\n

A nice pair is a pair (i, j) where 0 <= i < j < nums.length and low <= (nums[i] XOR nums[j]) <= high.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: nums = [1,4,2,7], low = 2, high = 6\r\nOutput: 6\r\nExplanation: All nice pairs (i, j) are as follows:\r\n    - (0, 1): nums[0] XOR nums[1] = 5 \r\n    - (0, 2): nums[0] XOR nums[2] = 3\r\n    - (0, 3): nums[0] XOR nums[3] = 6\r\n    - (1, 2): nums[1] XOR nums[2] = 6\r\n    - (1, 3): nums[1] XOR nums[3] = 3\r\n    - (2, 3): nums[2] XOR nums[3] = 5\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: nums = [9,8,4,2,1], low = 5, high = 14\r\nOutput: 8\r\nExplanation: All nice pairs (i, j) are as follows:\r\n\u200b\u200b\u200b\u200b\u200b    - (0, 2): nums[0] XOR nums[2] = 13\r\n    - (0, 3): nums[0] XOR nums[3] = 11\r\n    - (0, 4): nums[0] XOR nums[4] = 8\r\n    - (1, 2): nums[1] XOR nums[2] = 12\r\n    - (1, 3): nums[1] XOR nums[3] = 10\r\n    - (1, 4): nums[1] XOR nums[4] = 9\r\n    - (2, 3): nums[2] XOR nums[3] = 6\r\n    - (2, 4): nums[2] XOR nums[4] = 5
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= nums.length <= 2 * 104
  • \r\n\t
  • 1 <= nums[i] <= 2 * 104
  • \r\n\t
  • 1 <= low <= high <= 2 * 104
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \uff08\u4e0b\u6807 \u4ece 0 \u5f00\u59cb \u8ba1\u6570\uff09\u4ee5\u53ca\u4e24\u4e2a\u6574\u6570\uff1alow \u548c high \uff0c\u8bf7\u8fd4\u56de \u6f02\u4eae\u6570\u5bf9 \u7684\u6570\u76ee\u3002

\n\n

\u6f02\u4eae\u6570\u5bf9 \u662f\u4e00\u4e2a\u5f62\u5982 (i, j) \u7684\u6570\u5bf9\uff0c\u5176\u4e2d 0 <= i < j < nums.length \u4e14 low <= (nums[i] XOR nums[j]) <= high \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,4,2,7], low = 2, high = 6\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u6240\u6709\u6f02\u4eae\u6570\u5bf9 (i, j) \u5217\u51fa\u5982\u4e0b\uff1a\n    - (0, 1): nums[0] XOR nums[1] = 5 \n    - (0, 2): nums[0] XOR nums[2] = 3\n    - (0, 3): nums[0] XOR nums[3] = 6\n    - (1, 2): nums[1] XOR nums[2] = 6\n    - (1, 3): nums[1] XOR nums[3] = 3\n    - (2, 3): nums[2] XOR nums[3] = 5\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anums = [9,8,4,2,1], low = 5, high = 14\n\u8f93\u51fa\uff1a8\n\u89e3\u91ca\uff1a\u6240\u6709\u6f02\u4eae\u6570\u5bf9 (i, j) \u5217\u51fa\u5982\u4e0b\uff1a\n\u200b\u200b\u200b\u200b\u200b    - (0, 2): nums[0] XOR nums[2] = 13\n\u00a0   - (0, 3): nums[0] XOR nums[3] = 11\n\u00a0   - (0, 4): nums[0] XOR nums[4] = 8\n\u00a0   - (1, 2): nums[1] XOR nums[2] = 12\n\u00a0   - (1, 3): nums[1] XOR nums[3] = 10\n\u00a0   - (1, 4): nums[1] XOR nums[4] = 9\n\u00a0   - (2, 3): nums[2] XOR nums[3] = 6\n\u00a0   - (2, 4): nums[2] XOR nums[4] = 5
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 2 * 104
  • \n\t
  • 1 <= nums[i] <= 2 * 104
  • \n\t
  • 1 <= low <= high <= 2 * 104
  • \n
\n", "tags_en": ["Trie"], "tags_cn": ["\u5b57\u5178\u6811"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countPairs(vector& nums, int low, int high) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countPairs(int[] nums, int low, int high) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countPairs(self, nums, low, high):\n \"\"\"\n :type nums: List[int]\n :type low: int\n :type high: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countPairs(self, nums: List[int], low: int, high: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countPairs(int* nums, int numsSize, int low, int high){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountPairs(int[] nums, int low, int high) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} low\n * @param {number} high\n * @return {number}\n */\nvar countPairs = function(nums, low, high) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} low\n# @param {Integer} high\n# @return {Integer}\ndef count_pairs(nums, low, high)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countPairs(_ nums: [Int], _ low: Int, _ high: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countPairs(nums []int, low int, high int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countPairs(nums: Array[Int], low: Int, high: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countPairs(nums: IntArray, low: Int, high: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_pairs(nums: Vec, low: i32, high: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $low\n * @param Integer $high\n * @return Integer\n */\n function countPairs($nums, $low, $high) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countPairs(nums: number[], low: number, high: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-pairs nums low high)\n (-> (listof exact-integer?) exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1803](https://leetcode-cn.com/problems/count-pairs-with-xor-in-a-range)", "[\u7edf\u8ba1\u5f02\u6216\u503c\u5728\u8303\u56f4\u5185\u7684\u6570\u5bf9\u6709\u591a\u5c11](/solution/1800-1899/1803.Count%20Pairs%20With%20XOR%20in%20a%20Range/README.md)", "`\u5b57\u5178\u6811`", "\u56f0\u96be", ""], "md_table_row_en": ["[1803](https://leetcode.com/problems/count-pairs-with-xor-in-a-range)", "[Count Pairs With XOR in a Range](/solution/1800-1899/1803.Count%20Pairs%20With%20XOR%20in%20a%20Range/README_EN.md)", "`Trie`", "Hard", ""]}, {"question_id": "1906", "frontend_question_id": "1799", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximize-score-after-n-operations", "url_en": "https://leetcode.com/problems/maximize-score-after-n-operations", "relative_path_cn": "/solution/1700-1799/1799.Maximize%20Score%20After%20N%20Operations/README.md", "relative_path_en": "/solution/1700-1799/1799.Maximize%20Score%20After%20N%20Operations/README_EN.md", "title_cn": "N \u6b21\u64cd\u4f5c\u540e\u7684\u6700\u5927\u5206\u6570\u548c", "title_en": "Maximize Score After N Operations", "question_title_slug": "maximize-score-after-n-operations", "content_en": "

You are given nums, an array of positive integers of size 2 * n. You must perform n operations on this array.

\n\n

In the ith operation (1-indexed), you will:

\n\n
    \n\t
  • Choose two elements, x and y.
  • \n\t
  • Receive a score of i * gcd(x, y).
  • \n\t
  • Remove x and y from nums.
  • \n
\n\n

Return the maximum score you can receive after performing n operations.

\n\n

The function gcd(x, y) is the greatest common divisor of x and y.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [1,2]\nOutput: 1\nExplanation: The optimal choice of operations is:\n(1 * gcd(1, 2)) = 1\n
\n\n

Example 2:

\n\n
\nInput: nums = [3,4,6,8]\nOutput: 11\nExplanation: The optimal choice of operations is:\n(1 * gcd(3, 6)) + (2 * gcd(4, 8)) = 3 + 8 = 11\n
\n\n

Example 3:

\n\n
\nInput: nums = [1,2,3,4,5,6]\nOutput: 14\nExplanation: The optimal choice of operations is:\n(1 * gcd(1, 5)) + (2 * gcd(2, 4)) + (3 * gcd(3, 6)) = 1 + 4 + 9 = 14\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 7
  • \n\t
  • nums.length == 2 * n
  • \n\t
  • 1 <= nums[i] <= 106
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u00a0nums\u00a0\uff0c\u5b83\u662f\u4e00\u4e2a\u5927\u5c0f\u4e3a\u00a02 * n\u00a0\u7684\u6b63\u6574\u6570\u6570\u7ec4\u3002\u4f60\u5fc5\u987b\u5bf9\u8fd9\u4e2a\u6570\u7ec4\u6267\u884c n\u00a0\u6b21\u64cd\u4f5c\u3002

\n\n

\u5728\u7b2c\u00a0i\u00a0\u6b21\u64cd\u4f5c\u65f6\uff08\u64cd\u4f5c\u7f16\u53f7\u4ece 1\u00a0\u5f00\u59cb\uff09\uff0c\u4f60\u9700\u8981\uff1a

\n\n
    \n\t
  • \u9009\u62e9\u4e24\u4e2a\u5143\u7d20\u00a0x \u548c\u00a0y\u00a0\u3002
  • \n\t
  • \u83b7\u5f97\u5206\u6570\u00a0i * gcd(x, y)\u00a0\u3002
  • \n\t
  • \u5c06\u00a0x\u00a0\u548c\u00a0y \u4ece\u00a0nums\u00a0\u4e2d\u5220\u9664\u3002
  • \n
\n\n

\u8bf7\u4f60\u8fd4\u56de n\u00a0\u6b21\u64cd\u4f5c\u540e\u4f60\u80fd\u83b7\u5f97\u7684\u5206\u6570\u548c\u6700\u5927\u4e3a\u591a\u5c11\u3002

\n\n

\u51fd\u6570\u00a0gcd(x, y)\u00a0\u662f\u00a0x \u548c\u00a0y\u00a0\u7684\u6700\u5927\u516c\u7ea6\u6570\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,2]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u6700\u4f18\u64cd\u4f5c\u662f\uff1a\n(1 * gcd(1, 2)) = 1\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anums = [3,4,6,8]\n\u8f93\u51fa\uff1a11\n\u89e3\u91ca\uff1a\u6700\u4f18\u64cd\u4f5c\u662f\uff1a\n(1 * gcd(3, 6)) + (2 * gcd(4, 8)) = 3 + 8 = 11\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,2,3,4,5,6]\n\u8f93\u51fa\uff1a14\n\u89e3\u91ca\uff1a\u6700\u4f18\u64cd\u4f5c\u662f\uff1a\n(1 * gcd(1, 5)) + (2 * gcd(2, 4)) + (3 * gcd(3, 6)) = 1 + 4 + 9 = 14\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 7
  • \n\t
  • nums.length == 2 * n
  • \n\t
  • 1 <= nums[i] <= 106
  • \n
\n", "tags_en": ["Recursion", "Dynamic Programming", "Backtracking"], "tags_cn": ["\u9012\u5f52", "\u52a8\u6001\u89c4\u5212", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxScore(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxScore(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxScore(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxScore(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxScore(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxScore(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar maxScore = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef max_score(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxScore(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxScore(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxScore(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxScore(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_score(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function maxScore($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxScore(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-score nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1799](https://leetcode-cn.com/problems/maximize-score-after-n-operations)", "[N \u6b21\u64cd\u4f5c\u540e\u7684\u6700\u5927\u5206\u6570\u548c](/solution/1700-1799/1799.Maximize%20Score%20After%20N%20Operations/README.md)", "`\u9012\u5f52`,`\u52a8\u6001\u89c4\u5212`,`\u56de\u6eaf\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[1799](https://leetcode.com/problems/maximize-score-after-n-operations)", "[Maximize Score After N Operations](/solution/1700-1799/1799.Maximize%20Score%20After%20N%20Operations/README_EN.md)", "`Recursion`,`Dynamic Programming`,`Backtracking`", "Hard", ""]}, {"question_id": "1905", "frontend_question_id": "1797", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/design-authentication-manager", "url_en": "https://leetcode.com/problems/design-authentication-manager", "relative_path_cn": "/solution/1700-1799/1797.Design%20Authentication%20Manager/README.md", "relative_path_en": "/solution/1700-1799/1797.Design%20Authentication%20Manager/README_EN.md", "title_cn": "\u8bbe\u8ba1\u4e00\u4e2a\u9a8c\u8bc1\u7cfb\u7edf", "title_en": "Design Authentication Manager", "question_title_slug": "design-authentication-manager", "content_en": "

There is an authentication system that works with authentication tokens. For each session, the user will receive a new authentication token that will expire timeToLive seconds after the currentTime. If the token is renewed, the expiry time will be extended to expire timeToLive seconds after the (potentially different) currentTime.

\n\n

Implement the AuthenticationManager class:

\n\n
    \n\t
  • AuthenticationManager(int timeToLive) constructs the AuthenticationManager and sets the timeToLive.
  • \n\t
  • generate(string tokenId, int currentTime) generates a new token with the given tokenId at the given currentTime in seconds.
  • \n\t
  • renew(string tokenId, int currentTime) renews the unexpired token with the given tokenId at the given currentTime in seconds. If there are no unexpired tokens with the given tokenId, the request is ignored, and nothing happens.
  • \n\t
  • countUnexpiredTokens(int currentTime) returns the number of unexpired tokens at the given currentTime.
  • \n
\n\n

Note that if a token expires at time t, and another action happens on time t (renew or countUnexpiredTokens), the expiration takes place before the other actions.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput\n["AuthenticationManager", "renew", "generate", "countUnexpiredTokens", "generate", "renew", "renew", "countUnexpiredTokens"]\n[[5], ["aaa", 1], ["aaa", 2], [6], ["bbb", 7], ["aaa", 8], ["bbb", 10], [15]]\nOutput\n[null, null, null, 1, null, null, null, 0]\n\nExplanation\nAuthenticationManager authenticationManager = new AuthenticationManager(5); // Constructs the AuthenticationManager with timeToLive = 5 seconds.\nauthenticationManager.renew("aaa", 1); // No token exists with tokenId "aaa" at time 1, so nothing happens.\nauthenticationManager.generate("aaa", 2); // Generates a new token with tokenId "aaa" at time 2.\nauthenticationManager.countUnexpiredTokens(6); // The token with tokenId "aaa" is the only unexpired one at time 6, so return 1.\nauthenticationManager.generate("bbb", 7); // Generates a new token with tokenId "bbb" at time 7.\nauthenticationManager.renew("aaa", 8); // The token with tokenId "aaa" expired at time 7, and 8 >= 7, so at time 8 the renew request is ignored, and nothing happens.\nauthenticationManager.renew("bbb", 10); // The token with tokenId "bbb" is unexpired at time 10, so the renew request is fulfilled and now the token will expire at time 15.\nauthenticationManager.countUnexpiredTokens(15); // The token with tokenId "bbb" expires at time 15, and the token with tokenId "aaa" expired at time 7, so currently no token is unexpired, so return 0.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= timeToLive <= 108
  • \n\t
  • 1 <= currentTime <= 108
  • \n\t
  • 1 <= tokenId.length <= 5
  • \n\t
  • tokenId consists only of lowercase letters.
  • \n\t
  • All calls to generate will contain unique values of tokenId.
  • \n\t
  • The values of currentTime across all the function calls will be strictly increasing.
  • \n\t
  • At most 2000 calls will be made to all functions combined.
  • \n
\n", "content_cn": "

\u4f60\u9700\u8981\u8bbe\u8ba1\u4e00\u4e2a\u5305\u542b\u9a8c\u8bc1\u7801\u7684\u9a8c\u8bc1\u7cfb\u7edf\u3002\u6bcf\u4e00\u6b21\u9a8c\u8bc1\u4e2d\uff0c\u7528\u6237\u4f1a\u6536\u5230\u4e00\u4e2a\u65b0\u7684\u9a8c\u8bc1\u7801\uff0c\u8fd9\u4e2a\u9a8c\u8bc1\u7801\u5728 currentTime\u00a0\u65f6\u523b\u4e4b\u540e timeToLive\u00a0\u79d2\u8fc7\u671f\u3002\u5982\u679c\u9a8c\u8bc1\u7801\u88ab\u66f4\u65b0\u4e86\uff0c\u90a3\u4e48\u5b83\u4f1a\u5728 currentTime\u00a0\uff08\u53ef\u80fd\u4e0e\u4e4b\u524d\u7684 currentTime\u00a0\u4e0d\u540c\uff09\u65f6\u523b\u5ef6\u957f\u00a0timeToLive\u00a0\u79d2\u3002

\n\n

\u8bf7\u4f60\u5b9e\u73b0\u00a0AuthenticationManager\u00a0\u7c7b\uff1a

\n\n
    \n\t
  • AuthenticationManager(int timeToLive)\u00a0\u6784\u9020\u00a0AuthenticationManager\u00a0\u5e76\u8bbe\u7f6e\u00a0timeToLive\u00a0\u53c2\u6570\u3002
  • \n\t
  • generate(string tokenId, int currentTime)\u00a0\u7ed9\u5b9a tokenId\u00a0\uff0c\u5728\u5f53\u524d\u65f6\u95f4\u00a0currentTime \u751f\u6210\u4e00\u4e2a\u65b0\u7684\u9a8c\u8bc1\u7801\u3002
  • \n\t
  • renew(string tokenId, int currentTime)\u00a0\u5c06\u7ed9\u5b9a tokenId\u00a0\u4e14 \u672a\u8fc7\u671f\u00a0\u7684\u9a8c\u8bc1\u7801\u5728 currentTime\u00a0\u65f6\u523b\u66f4\u65b0\u3002\u5982\u679c\u7ed9\u5b9a\u00a0tokenId\u00a0\u5bf9\u5e94\u7684\u9a8c\u8bc1\u7801\u4e0d\u5b58\u5728\u6216\u5df2\u8fc7\u671f\uff0c\u8bf7\u4f60\u5ffd\u7565\u8be5\u64cd\u4f5c\uff0c\u4e0d\u4f1a\u6709\u4efb\u4f55\u66f4\u65b0\u64cd\u4f5c\u53d1\u751f\u3002
  • \n\t
  • countUnexpiredTokens(int currentTime)\u00a0\u8bf7\u8fd4\u56de\u5728\u7ed9\u5b9a\u00a0currentTime\u00a0\u65f6\u523b\uff0c\u672a\u8fc7\u671f\u00a0\u7684\u9a8c\u8bc1\u7801\u6570\u76ee\u3002
  • \n
\n\n

\u5982\u679c\u4e00\u4e2a\u9a8c\u8bc1\u7801\u5728\u65f6\u523b\u00a0t\u00a0\u8fc7\u671f\uff0c\u4e14\u53e6\u4e00\u4e2a\u64cd\u4f5c\u6070\u597d\u5728\u65f6\u523b\u00a0t\u00a0\u53d1\u751f\uff08renew\u00a0\u6216\u8005\u00a0countUnexpiredTokens\u00a0\u64cd\u4f5c\uff09\uff0c\u8fc7\u671f\u4e8b\u4ef6\u00a0\u4f18\u5148\u4e8e\u00a0\u5176\u4ed6\u64cd\u4f5c\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1a\n[\"AuthenticationManager\", \"renew\", \"generate\", \"countUnexpiredTokens\", \"generate\", \"renew\", \"renew\", \"countUnexpiredTokens\"]\n[[5], [\"aaa\", 1], [\"aaa\", 2], [6], [\"bbb\", 7], [\"aaa\", 8], [\"bbb\", 10], [15]]\n\u8f93\u51fa\uff1a\n[null, null, null, 1, null, null, null, 0]\n\n\u89e3\u91ca\uff1a\nAuthenticationManager authenticationManager = new AuthenticationManager(5); // \u6784\u9020 AuthenticationManager \uff0c\u8bbe\u7f6e timeToLive = 5 \u79d2\u3002\nauthenticationManager.renew(\"aaa\", 1); // \u65f6\u523b 1 \u65f6\uff0c\u6ca1\u6709\u9a8c\u8bc1\u7801\u7684 tokenId \u4e3a \"aaa\" \uff0c\u6ca1\u6709\u9a8c\u8bc1\u7801\u88ab\u66f4\u65b0\u3002\nauthenticationManager.generate(\"aaa\", 2); // \u65f6\u523b 2 \u65f6\uff0c\u751f\u6210\u4e00\u4e2a tokenId \u4e3a \"aaa\" \u7684\u65b0\u9a8c\u8bc1\u7801\u3002\nauthenticationManager.countUnexpiredTokens(6); // \u65f6\u523b 6 \u65f6\uff0c\u53ea\u6709 tokenId \u4e3a \"aaa\" \u7684\u9a8c\u8bc1\u7801\u672a\u8fc7\u671f\uff0c\u6240\u4ee5\u8fd4\u56de 1 \u3002\nauthenticationManager.generate(\"bbb\", 7); // \u65f6\u523b 7 \u65f6\uff0c\u751f\u6210\u4e00\u4e2a tokenId \u4e3a \"bbb\" \u7684\u65b0\u9a8c\u8bc1\u7801\u3002\nauthenticationManager.renew(\"aaa\", 8); // tokenId \u4e3a \"aaa\" \u7684\u9a8c\u8bc1\u7801\u5728\u65f6\u523b 7 \u8fc7\u671f\uff0c\u4e14 8 >= 7 \uff0c\u6240\u4ee5\u65f6\u523b 8 \u7684renew \u64cd\u4f5c\u88ab\u5ffd\u7565\uff0c\u6ca1\u6709\u9a8c\u8bc1\u7801\u88ab\u66f4\u65b0\u3002\nauthenticationManager.renew(\"bbb\", 10); // tokenId \u4e3a \"bbb\" \u7684\u9a8c\u8bc1\u7801\u5728\u65f6\u523b 10 \u6ca1\u6709\u8fc7\u671f\uff0c\u6240\u4ee5 renew \u64cd\u4f5c\u4f1a\u6267\u884c\uff0c\u8be5 token \u5c06\u5728\u65f6\u523b 15 \u8fc7\u671f\u3002\nauthenticationManager.countUnexpiredTokens(15); // tokenId \u4e3a \"bbb\" \u7684\u9a8c\u8bc1\u7801\u5728\u65f6\u523b 15 \u8fc7\u671f\uff0ctokenId \u4e3a \"aaa\" \u7684\u9a8c\u8bc1\u7801\u5728\u65f6\u523b 7 \u8fc7\u671f\uff0c\u6240\u6709\u9a8c\u8bc1\u7801\u5747\u5df2\u8fc7\u671f\uff0c\u6240\u4ee5\u8fd4\u56de 0 \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= timeToLive <= 108
  • \n\t
  • 1 <= currentTime <= 108
  • \n\t
  • 1 <= tokenId.length <= 5
  • \n\t
  • tokenId\u00a0\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
  • \n\t
  • \u6240\u6709\u00a0generate\u00a0\u51fd\u6570\u7684\u8c03\u7528\u90fd\u4f1a\u5305\u542b\u72ec\u4e00\u65e0\u4e8c\u7684\u00a0tokenId\u00a0\u503c\u3002
  • \n\t
  • \u6240\u6709\u51fd\u6570\u8c03\u7528\u4e2d\uff0ccurrentTime\u00a0\u7684\u503c \u4e25\u683c\u9012\u589e\u00a0\u3002
  • \n\t
  • \u6240\u6709\u51fd\u6570\u7684\u8c03\u7528\u6b21\u6570\u603b\u5171\u4e0d\u8d85\u8fc7\u00a02000\u00a0\u6b21\u3002
  • \n
\n", "tags_en": ["Design", "Hash Table"], "tags_cn": ["\u8bbe\u8ba1", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class AuthenticationManager {\npublic:\n AuthenticationManager(int timeToLive) {\n\n }\n \n void generate(string tokenId, int currentTime) {\n\n }\n \n void renew(string tokenId, int currentTime) {\n\n }\n \n int countUnexpiredTokens(int currentTime) {\n\n }\n};\n\n/**\n * Your AuthenticationManager object will be instantiated and called as such:\n * AuthenticationManager* obj = new AuthenticationManager(timeToLive);\n * obj->generate(tokenId,currentTime);\n * obj->renew(tokenId,currentTime);\n * int param_3 = obj->countUnexpiredTokens(currentTime);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class AuthenticationManager {\n\n public AuthenticationManager(int timeToLive) {\n\n }\n \n public void generate(String tokenId, int currentTime) {\n\n }\n \n public void renew(String tokenId, int currentTime) {\n\n }\n \n public int countUnexpiredTokens(int currentTime) {\n\n }\n}\n\n/**\n * Your AuthenticationManager object will be instantiated and called as such:\n * AuthenticationManager obj = new AuthenticationManager(timeToLive);\n * obj.generate(tokenId,currentTime);\n * obj.renew(tokenId,currentTime);\n * int param_3 = obj.countUnexpiredTokens(currentTime);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class AuthenticationManager(object):\n\n def __init__(self, timeToLive):\n \"\"\"\n :type timeToLive: int\n \"\"\"\n\n\n def generate(self, tokenId, currentTime):\n \"\"\"\n :type tokenId: str\n :type currentTime: int\n :rtype: None\n \"\"\"\n\n\n def renew(self, tokenId, currentTime):\n \"\"\"\n :type tokenId: str\n :type currentTime: int\n :rtype: None\n \"\"\"\n\n\n def countUnexpiredTokens(self, currentTime):\n \"\"\"\n :type currentTime: int\n :rtype: int\n \"\"\"\n\n\n\n# Your AuthenticationManager object will be instantiated and called as such:\n# obj = AuthenticationManager(timeToLive)\n# obj.generate(tokenId,currentTime)\n# obj.renew(tokenId,currentTime)\n# param_3 = obj.countUnexpiredTokens(currentTime)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class AuthenticationManager:\n\n def __init__(self, timeToLive: int):\n\n\n def generate(self, tokenId: str, currentTime: int) -> None:\n\n\n def renew(self, tokenId: str, currentTime: int) -> None:\n\n\n def countUnexpiredTokens(self, currentTime: int) -> int:\n\n\n\n# Your AuthenticationManager object will be instantiated and called as such:\n# obj = AuthenticationManager(timeToLive)\n# obj.generate(tokenId,currentTime)\n# obj.renew(tokenId,currentTime)\n# param_3 = obj.countUnexpiredTokens(currentTime)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} AuthenticationManager;\n\n\nAuthenticationManager* authenticationManagerCreate(int timeToLive) {\n \n}\n\nvoid authenticationManagerGenerate(AuthenticationManager* obj, char * tokenId, int currentTime) {\n \n}\n\nvoid authenticationManagerRenew(AuthenticationManager* obj, char * tokenId, int currentTime) {\n \n}\n\nint authenticationManagerCountUnexpiredTokens(AuthenticationManager* obj, int currentTime) {\n \n}\n\nvoid authenticationManagerFree(AuthenticationManager* obj) {\n \n}\n\n/**\n * Your AuthenticationManager struct will be instantiated and called as such:\n * AuthenticationManager* obj = authenticationManagerCreate(timeToLive);\n * authenticationManagerGenerate(obj, tokenId, currentTime);\n \n * authenticationManagerRenew(obj, tokenId, currentTime);\n \n * int param_3 = authenticationManagerCountUnexpiredTokens(obj, currentTime);\n \n * authenticationManagerFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class AuthenticationManager {\n\n public AuthenticationManager(int timeToLive) {\n\n }\n \n public void Generate(string tokenId, int currentTime) {\n\n }\n \n public void Renew(string tokenId, int currentTime) {\n\n }\n \n public int CountUnexpiredTokens(int currentTime) {\n\n }\n}\n\n/**\n * Your AuthenticationManager object will be instantiated and called as such:\n * AuthenticationManager obj = new AuthenticationManager(timeToLive);\n * obj.Generate(tokenId,currentTime);\n * obj.Renew(tokenId,currentTime);\n * int param_3 = obj.CountUnexpiredTokens(currentTime);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} timeToLive\n */\nvar AuthenticationManager = function(timeToLive) {\n\n};\n\n/** \n * @param {string} tokenId \n * @param {number} currentTime\n * @return {void}\n */\nAuthenticationManager.prototype.generate = function(tokenId, currentTime) {\n\n};\n\n/** \n * @param {string} tokenId \n * @param {number} currentTime\n * @return {void}\n */\nAuthenticationManager.prototype.renew = function(tokenId, currentTime) {\n\n};\n\n/** \n * @param {number} currentTime\n * @return {number}\n */\nAuthenticationManager.prototype.countUnexpiredTokens = function(currentTime) {\n\n};\n\n/**\n * Your AuthenticationManager object will be instantiated and called as such:\n * var obj = new AuthenticationManager(timeToLive)\n * obj.generate(tokenId,currentTime)\n * obj.renew(tokenId,currentTime)\n * var param_3 = obj.countUnexpiredTokens(currentTime)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class AuthenticationManager\n\n=begin\n :type time_to_live: Integer\n=end\n def initialize(time_to_live)\n\n end\n\n\n=begin\n :type token_id: String\n :type current_time: Integer\n :rtype: Void\n=end\n def generate(token_id, current_time)\n\n end\n\n\n=begin\n :type token_id: String\n :type current_time: Integer\n :rtype: Void\n=end\n def renew(token_id, current_time)\n\n end\n\n\n=begin\n :type current_time: Integer\n :rtype: Integer\n=end\n def count_unexpired_tokens(current_time)\n\n end\n\n\nend\n\n# Your AuthenticationManager object will be instantiated and called as such:\n# obj = AuthenticationManager.new(time_to_live)\n# obj.generate(token_id, current_time)\n# obj.renew(token_id, current_time)\n# param_3 = obj.count_unexpired_tokens(current_time)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass AuthenticationManager {\n\n init(_ timeToLive: Int) {\n\n }\n \n func generate(_ tokenId: String, _ currentTime: Int) {\n\n }\n \n func renew(_ tokenId: String, _ currentTime: Int) {\n\n }\n \n func countUnexpiredTokens(_ currentTime: Int) -> Int {\n\n }\n}\n\n/**\n * Your AuthenticationManager object will be instantiated and called as such:\n * let obj = AuthenticationManager(timeToLive)\n * obj.generate(tokenId, currentTime)\n * obj.renew(tokenId, currentTime)\n * let ret_3: Int = obj.countUnexpiredTokens(currentTime)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type AuthenticationManager struct {\n\n}\n\n\nfunc Constructor(timeToLive int) AuthenticationManager {\n\n}\n\n\nfunc (this *AuthenticationManager) Generate(tokenId string, currentTime int) {\n\n}\n\n\nfunc (this *AuthenticationManager) Renew(tokenId string, currentTime int) {\n\n}\n\n\nfunc (this *AuthenticationManager) CountUnexpiredTokens(currentTime int) int {\n\n}\n\n\n/**\n * Your AuthenticationManager object will be instantiated and called as such:\n * obj := Constructor(timeToLive);\n * obj.Generate(tokenId,currentTime);\n * obj.Renew(tokenId,currentTime);\n * param_3 := obj.CountUnexpiredTokens(currentTime);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class AuthenticationManager(_timeToLive: Int) {\n\n def generate(tokenId: String, currentTime: Int) {\n \n }\n\n def renew(tokenId: String, currentTime: Int) {\n \n }\n\n def countUnexpiredTokens(currentTime: Int): Int = {\n \n }\n\n}\n\n/**\n * Your AuthenticationManager object will be instantiated and called as such:\n * var obj = new AuthenticationManager(timeToLive)\n * obj.generate(tokenId,currentTime)\n * obj.renew(tokenId,currentTime)\n * var param_3 = obj.countUnexpiredTokens(currentTime)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class AuthenticationManager(timeToLive: Int) {\n\n fun generate(tokenId: String, currentTime: Int) {\n\n }\n\n fun renew(tokenId: String, currentTime: Int) {\n\n }\n\n fun countUnexpiredTokens(currentTime: Int): Int {\n\n }\n\n}\n\n/**\n * Your AuthenticationManager object will be instantiated and called as such:\n * var obj = AuthenticationManager(timeToLive)\n * obj.generate(tokenId,currentTime)\n * obj.renew(tokenId,currentTime)\n * var param_3 = obj.countUnexpiredTokens(currentTime)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct AuthenticationManager {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl AuthenticationManager {\n\n fn new(timeToLive: i32) -> Self {\n\n }\n \n fn generate(&self, token_id: String, current_time: i32) {\n\n }\n \n fn renew(&self, token_id: String, current_time: i32) {\n\n }\n \n fn count_unexpired_tokens(&self, current_time: i32) -> i32 {\n\n }\n}\n\n/**\n * Your AuthenticationManager object will be instantiated and called as such:\n * let obj = AuthenticationManager::new(timeToLive);\n * obj.generate(tokenId, currentTime);\n * obj.renew(tokenId, currentTime);\n * let ret_3: i32 = obj.count_unexpired_tokens(currentTime);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class AuthenticationManager {\n /**\n * @param Integer $timeToLive\n */\n function __construct($timeToLive) {\n\n }\n\n /**\n * @param String $tokenId\n * @param Integer $currentTime\n * @return NULL\n */\n function generate($tokenId, $currentTime) {\n\n }\n\n /**\n * @param String $tokenId\n * @param Integer $currentTime\n * @return NULL\n */\n function renew($tokenId, $currentTime) {\n\n }\n\n /**\n * @param Integer $currentTime\n * @return Integer\n */\n function countUnexpiredTokens($currentTime) {\n\n }\n}\n\n/**\n * Your AuthenticationManager object will be instantiated and called as such:\n * $obj = AuthenticationManager($timeToLive);\n * $obj->generate($tokenId, $currentTime);\n * $obj->renew($tokenId, $currentTime);\n * $ret_3 = $obj->countUnexpiredTokens($currentTime);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class AuthenticationManager {\n constructor(timeToLive: number) {\n\n }\n\n generate(tokenId: string, currentTime: number): void {\n\n }\n\n renew(tokenId: string, currentTime: number): void {\n\n }\n\n countUnexpiredTokens(currentTime: number): number {\n\n }\n}\n\n/**\n * Your AuthenticationManager object will be instantiated and called as such:\n * var obj = new AuthenticationManager(timeToLive)\n * obj.generate(tokenId,currentTime)\n * obj.renew(tokenId,currentTime)\n * var param_3 = obj.countUnexpiredTokens(currentTime)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define authentication-manager%\n (class object%\n (super-new)\n\n ; time-to-live : exact-integer?\n (init-field\n time-to-live)\n \n ; generate : string? exact-integer? -> void?\n (define/public (generate tokenId currentTime)\n\n )\n ; renew : string? exact-integer? -> void?\n (define/public (renew tokenId currentTime)\n\n )\n ; count-unexpired-tokens : exact-integer? -> exact-integer?\n (define/public (count-unexpired-tokens currentTime)\n\n )))\n\n;; Your authentication-manager% object will be instantiated and called as such:\n;; (define obj (new authentication-manager% [timeToLive timeToLive]))\n;; (send obj generate token-id current-time)\n;; (send obj renew token-id current-time)\n;; (define param_3 (send obj count-unexpired-tokens current-time))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1797](https://leetcode-cn.com/problems/design-authentication-manager)", "[\u8bbe\u8ba1\u4e00\u4e2a\u9a8c\u8bc1\u7cfb\u7edf](/solution/1700-1799/1797.Design%20Authentication%20Manager/README.md)", "`\u8bbe\u8ba1`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1797](https://leetcode.com/problems/design-authentication-manager)", "[Design Authentication Manager](/solution/1700-1799/1797.Design%20Authentication%20Manager/README_EN.md)", "`Design`,`Hash Table`", "Medium", ""]}, {"question_id": "1904", "frontend_question_id": "1796", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/second-largest-digit-in-a-string", "url_en": "https://leetcode.com/problems/second-largest-digit-in-a-string", "relative_path_cn": "/solution/1700-1799/1796.Second%20Largest%20Digit%20in%20a%20String/README.md", "relative_path_en": "/solution/1700-1799/1796.Second%20Largest%20Digit%20in%20a%20String/README_EN.md", "title_cn": "\u5b57\u7b26\u4e32\u4e2d\u7b2c\u4e8c\u5927\u7684\u6570\u5b57", "title_en": "Second Largest Digit in a String", "question_title_slug": "second-largest-digit-in-a-string", "content_en": "

Given an alphanumeric string s, return the second largest numerical digit that appears in s, or -1 if it does not exist.

\n\n

An alphanumeric string is a string consisting of lowercase English letters and digits.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "dfa12321afd"\nOutput: 2\nExplanation: The digits that appear in s are [1, 2, 3]. The second largest digit is 2.\n
\n\n

Example 2:

\n\n
\nInput: s = "abc1111"\nOutput: -1\nExplanation: The digits that appear in s are [1]. There is no second largest digit. \n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 500
  • \n\t
  • s consists of only lowercase English letters and/or digits.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6df7\u5408\u5b57\u7b26\u4e32\u00a0s\u00a0\uff0c\u8bf7\u4f60\u8fd4\u56de s\u00a0\u4e2d \u7b2c\u4e8c\u5927 \u7684\u6570\u5b57\uff0c\u5982\u679c\u4e0d\u5b58\u5728\u7b2c\u4e8c\u5927\u7684\u6570\u5b57\uff0c\u8bf7\u4f60\u8fd4\u56de -1\u00a0\u3002

\n\n

\u6df7\u5408\u5b57\u7b26\u4e32 \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u548c\u6570\u5b57\u7ec4\u6210\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"dfa12321afd\"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u51fa\u73b0\u5728 s \u4e2d\u7684\u6570\u5b57\u5305\u62ec [1, 2, 3] \u3002\u7b2c\u4e8c\u5927\u7684\u6570\u5b57\u662f 2 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"abc1111\"\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u51fa\u73b0\u5728 s \u4e2d\u7684\u6570\u5b57\u53ea\u5305\u542b [1] \u3002\u6ca1\u6709\u7b2c\u4e8c\u5927\u7684\u6570\u5b57\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length <= 500
  • \n\t
  • s\u00a0\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u548c\uff08\u6216\uff09\u6570\u5b57\u3002
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int secondHighest(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int secondHighest(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def secondHighest(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def secondHighest(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint secondHighest(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SecondHighest(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar secondHighest = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef second_highest(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func secondHighest(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func secondHighest(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def secondHighest(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun secondHighest(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn second_highest(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function secondHighest($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function secondHighest(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (second-highest s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1796](https://leetcode-cn.com/problems/second-largest-digit-in-a-string)", "[\u5b57\u7b26\u4e32\u4e2d\u7b2c\u4e8c\u5927\u7684\u6570\u5b57](/solution/1700-1799/1796.Second%20Largest%20Digit%20in%20a%20String/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1796](https://leetcode.com/problems/second-largest-digit-in-a-string)", "[Second Largest Digit in a String](/solution/1700-1799/1796.Second%20Largest%20Digit%20in%20a%20String/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1903", "frontend_question_id": "1756", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/design-most-recently-used-queue", "url_en": "https://leetcode.com/problems/design-most-recently-used-queue", "relative_path_cn": "/solution/1700-1799/1756.Design%20Most%20Recently%20Used%20Queue/README.md", "relative_path_en": "/solution/1700-1799/1756.Design%20Most%20Recently%20Used%20Queue/README_EN.md", "title_cn": "\u8bbe\u8ba1\u6700\u8fd1\u4f7f\u7528\uff08MRU\uff09\u961f\u5217", "title_en": "Design Most Recently Used Queue", "question_title_slug": "design-most-recently-used-queue", "content_en": "

Design a queue-like data structure that moves the most recently used element to the end of the queue.

\n\n

Implement the MRUQueue class:

\n\n
    \n\t
  • MRUQueue(int n) constructs the MRUQueue with n elements: [1,2,3,...,n].
  • \n\t
  • int fetch(int k) moves the kth element (1-indexed) to the end of the queue and returns it.
  • \n
\n\n

 

\n

Example 1:

\n\n
\nInput:\n["MRUQueue", "fetch", "fetch", "fetch", "fetch"]\n[[8], [3], [5], [2], [8]]\nOutput:\n[null, 3, 6, 2, 2]\n\nExplanation:\nMRUQueue mRUQueue = new MRUQueue(8); // Initializes the queue to [1,2,3,4,5,6,7,8].\nmRUQueue.fetch(3); // Moves the 3rd element (3) to the end of the queue to become [1,2,4,5,6,7,8,3] and returns it.\nmRUQueue.fetch(5); // Moves the 5th element (6) to the end of the queue to become [1,2,4,5,7,8,3,6] and returns it.\nmRUQueue.fetch(2); // Moves the 2nd element (2) to the end of the queue to become [1,4,5,7,8,3,6,2] and returns it.\nmRUQueue.fetch(8); // The 8th element (2) is already at the end of the queue so just return it.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 2000
  • \n\t
  • 1 <= k <= n
  • \n\t
  • At most 2000 calls will be made to fetch.
  • \n
\n\n

 

\nFollow up: Finding an O(n) algorithm per fetch is a bit easy. Can you find an algorithm with a better complexity for each fetch call?", "content_cn": "

\u8bbe\u8ba1\u4e00\u79cd\u7c7b\u4f3c\u961f\u5217\u7684\u6570\u636e\u7ed3\u6784\uff0c\u8be5\u6570\u636e\u7ed3\u6784\u5c06\u6700\u8fd1\u4f7f\u7528\u7684\u5143\u7d20\u79fb\u5230\u961f\u5217\u5c3e\u90e8\u3002

\n\n

\u5b9e\u73b0\u00a0MRUQueue\u00a0\u7c7b\uff1a

\n\n
    \n\t
  • MRUQueue(int n)\u00a0\u00a0\u4f7f\u7528\u00a0n\u00a0\u4e2a\u5143\u7d20\uff1a\u00a0[1,2,3,...,n]\u00a0\u6784\u9020\u00a0MRUQueue\u00a0\u3002
  • \n\t
  • fetch(int k)\u00a0\u5c06\u7b2c\u00a0k\u00a0\u4e2a\u5143\u7d20\uff08\u4ece 1 \u5f00\u59cb\u7d22\u5f15\uff09\u79fb\u5230\u961f\u5c3e\uff0c\u5e76\u8fd4\u56de\u8be5\u5143\u7d20\u3002
  • \n
\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1a\n[\"MRUQueue\", \"fetch\", \"fetch\", \"fetch\", \"fetch\"]\n[[8], [3], [5], [2], [8]]\n\u8f93\u51fa\uff1a\n[null, 3, 6, 2, 2]\n\n\u89e3\u91ca\uff1a\nMRUQueue mRUQueue = new MRUQueue(8); // \u521d\u59cb\u5316\u961f\u5217\u4e3a [1,2,3,4,5,6,7,8]\u3002\nmRUQueue.fetch(3); // \u5c06\u7b2c 3 \u4e2a\u5143\u7d20 (3) \u79fb\u5230\u961f\u5c3e\uff0c\u4f7f\u961f\u5217\u53d8\u4e3a [1,2,4,5,6,7,8,3] \u5e76\u8fd4\u56de\u8be5\u5143\u7d20\u3002\nmRUQueue.fetch(5); // \u5c06\u7b2c 5 \u4e2a\u5143\u7d20 (6) \u79fb\u5230\u961f\u5c3e\uff0c\u4f7f\u961f\u5217\u53d8\u4e3a [1,2,4,5,7,8,3,6] \u5e76\u8fd4\u56de\u8be5\u5143\u7d20\u3002\nmRUQueue.fetch(2); // \u5c06\u7b2c 2 \u4e2a\u5143\u7d20 (2) \u79fb\u5230\u961f\u5c3e\uff0c\u4f7f\u961f\u5217\u53d8\u4e3a [1,4,5,7,8,3,6,2] \u5e76\u8fd4\u56de\u8be5\u5143\u7d20\u3002\nmRUQueue.fetch(8); // \u7b2c 8 \u4e2a\u5143\u7d20 (2) \u5df2\u7ecf\u5728\u961f\u5217\u5c3e\u90e8\u4e86\uff0c\u6240\u4ee5\u76f4\u63a5\u8fd4\u56de\u8be5\u5143\u7d20\u5373\u53ef\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 2000
  • \n\t
  • 1 <= k <= n
  • \n\t
  • \u6700\u591a\u8c03\u7528\u00a02000\u00a0\u6b21\u00a0fetch
  • \n
\n\n

\u00a0

\n\u8fdb\u9636\uff1a\u627e\u5230\u6bcf\u6b21\u00a0fetch\u00a0\u7684\u590d\u6742\u5ea6\u4e3a\u00a0O(n)\u00a0\u7684\u7b97\u6cd5\u6bd4\u8f83\u7b80\u5355\u3002\u4f60\u53ef\u4ee5\u627e\u5230\u6bcf\u6b21\u00a0fetch\u00a0\u7684\u590d\u6742\u5ea6\u66f4\u4f73\u7684\u7b97\u6cd5\u5417\uff1f", "tags_en": ["Design", "Array"], "tags_cn": ["\u8bbe\u8ba1", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class MRUQueue {\npublic:\n MRUQueue(int n) {\n\n }\n \n int fetch(int k) {\n\n }\n};\n\n/**\n * Your MRUQueue object will be instantiated and called as such:\n * MRUQueue* obj = new MRUQueue(n);\n * int param_1 = obj->fetch(k);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class MRUQueue {\n\n public MRUQueue(int n) {\n\n }\n \n public int fetch(int k) {\n\n }\n}\n\n/**\n * Your MRUQueue object will be instantiated and called as such:\n * MRUQueue obj = new MRUQueue(n);\n * int param_1 = obj.fetch(k);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class MRUQueue(object):\n\n def __init__(self, n):\n \"\"\"\n :type n: int\n \"\"\"\n\n\n def fetch(self, k):\n \"\"\"\n :type k: int\n :rtype: int\n \"\"\"\n\n\n\n# Your MRUQueue object will be instantiated and called as such:\n# obj = MRUQueue(n)\n# param_1 = obj.fetch(k)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class MRUQueue:\n\n def __init__(self, n: int):\n\n\n def fetch(self, k: int) -> int:\n\n\n\n# Your MRUQueue object will be instantiated and called as such:\n# obj = MRUQueue(n)\n# param_1 = obj.fetch(k)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} MRUQueue;\n\n\nMRUQueue* mRUQueueCreate(int n) {\n\n}\n\nint mRUQueueFetch(MRUQueue* obj, int k) {\n\n}\n\nvoid mRUQueueFree(MRUQueue* obj) {\n\n}\n\n/**\n * Your MRUQueue struct will be instantiated and called as such:\n * MRUQueue* obj = mRUQueueCreate(n);\n * int param_1 = mRUQueueFetch(obj, k);\n \n * mRUQueueFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class MRUQueue {\n\n public MRUQueue(int n) {\n\n }\n \n public int Fetch(int k) {\n\n }\n}\n\n/**\n * Your MRUQueue object will be instantiated and called as such:\n * MRUQueue obj = new MRUQueue(n);\n * int param_1 = obj.Fetch(k);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n */\nvar MRUQueue = function(n) {\n\n};\n\n/** \n * @param {number} k\n * @return {number}\n */\nMRUQueue.prototype.fetch = function(k) {\n\n};\n\n/**\n * Your MRUQueue object will be instantiated and called as such:\n * var obj = new MRUQueue(n)\n * var param_1 = obj.fetch(k)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class MRUQueue\n\n=begin\n :type n: Integer\n=end\n def initialize(n)\n\n end\n\n\n=begin\n :type k: Integer\n :rtype: Integer\n=end\n def fetch(k)\n\n end\n\n\nend\n\n# Your MRUQueue object will be instantiated and called as such:\n# obj = MRUQueue.new(n)\n# param_1 = obj.fetch(k)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass MRUQueue {\n\n init(_ n: Int) {\n\n }\n \n func fetch(_ k: Int) -> Int {\n\n }\n}\n\n/**\n * Your MRUQueue object will be instantiated and called as such:\n * let obj = MRUQueue(n)\n * let ret_1: Int = obj.fetch(k)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type MRUQueue struct {\n\n}\n\n\nfunc Constructor(n int) MRUQueue {\n\n}\n\n\nfunc (this *MRUQueue) Fetch(k int) int {\n\n}\n\n\n/**\n * Your MRUQueue object will be instantiated and called as such:\n * obj := Constructor(n);\n * param_1 := obj.Fetch(k);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class MRUQueue(_n: Int) {\n\n def fetch(k: Int): Int = {\n \n }\n\n}\n\n/**\n * Your MRUQueue object will be instantiated and called as such:\n * var obj = new MRUQueue(n)\n * var param_1 = obj.fetch(k)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class MRUQueue(n: Int) {\n\n fun fetch(k: Int): Int {\n\n }\n\n}\n\n/**\n * Your MRUQueue object will be instantiated and called as such:\n * var obj = MRUQueue(n)\n * var param_1 = obj.fetch(k)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct MRUQueue {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl MRUQueue {\n\n fn new(n: i32) -> Self {\n\n }\n \n fn fetch(&self, k: i32) -> i32 {\n\n }\n}\n\n/**\n * Your MRUQueue object will be instantiated and called as such:\n * let obj = MRUQueue::new(n);\n * let ret_1: i32 = obj.fetch(k);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class MRUQueue {\n /**\n * @param Integer $n\n */\n function __construct($n) {\n\n }\n\n /**\n * @param Integer $k\n * @return Integer\n */\n function fetch($k) {\n\n }\n}\n\n/**\n * Your MRUQueue object will be instantiated and called as such:\n * $obj = MRUQueue($n);\n * $ret_1 = $obj->fetch($k);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class MRUQueue {\n constructor(n: number) {\n\n }\n\n fetch(k: number): number {\n\n }\n}\n\n/**\n * Your MRUQueue object will be instantiated and called as such:\n * var obj = new MRUQueue(n)\n * var param_1 = obj.fetch(k)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define mru-queue%\n (class object%\n (super-new)\n\n ; n : exact-integer?\n (init-field\n n)\n \n ; fetch : exact-integer? -> exact-integer?\n (define/public (fetch k)\n\n )))\n\n;; Your mru-queue% object will be instantiated and called as such:\n;; (define obj (new mru-queue% [n n]))\n;; (define param_1 (send obj fetch k))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1756](https://leetcode-cn.com/problems/design-most-recently-used-queue)", "[\u8bbe\u8ba1\u6700\u8fd1\u4f7f\u7528\uff08MRU\uff09\u961f\u5217](/solution/1700-1799/1756.Design%20Most%20Recently%20Used%20Queue/README.md)", "`\u8bbe\u8ba1`,`\u6570\u7ec4`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1756](https://leetcode.com/problems/design-most-recently-used-queue)", "[Design Most Recently Used Queue](/solution/1700-1799/1756.Design%20Most%20Recently%20Used%20Queue/README_EN.md)", "`Design`,`Array`", "Medium", "\ud83d\udd12"]}, {"question_id": "1902", "frontend_question_id": "1776", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/car-fleet-ii", "url_en": "https://leetcode.com/problems/car-fleet-ii", "relative_path_cn": "/solution/1700-1799/1776.Car%20Fleet%20II/README.md", "relative_path_en": "/solution/1700-1799/1776.Car%20Fleet%20II/README_EN.md", "title_cn": "\u8f66\u961f II", "title_en": "Car Fleet II", "question_title_slug": "car-fleet-ii", "content_en": "

There are n cars traveling at different speeds in the same direction along a one-lane road. You are given an array cars of length n, where cars[i] = [positioni, speedi] represents:

\n\n
    \n\t
  • positioni is the distance between the ith car and the beginning of the road in meters. It is guaranteed that positioni < positioni+1.
  • \n\t
  • speedi is the initial speed of the ith car in meters per second.
  • \n
\n\n

For simplicity, cars can be considered as points moving along the number line. Two cars collide when they occupy the same position. Once a car collides with another car, they unite and form a single car fleet. The cars in the formed fleet will have the same position and the same speed, which is the initial speed of the slowest car in the fleet.

\n\n

Return an array answer, where answer[i] is the time, in seconds, at which the ith car collides with the next car, or -1 if the car does not collide with the next car. Answers within 10-5 of the actual answers are accepted.

\n\n

 

\n

Example 1:

\n\n
\nInput: cars = [[1,2],[2,1],[4,3],[7,2]]\nOutput: [1.00000,-1.00000,3.00000,-1.00000]\nExplanation: After exactly one second, the first car will collide with the second car, and form a car fleet with speed 1 m/s. After exactly 3 seconds, the third car will collide with the fourth car, and form a car fleet with speed 2 m/s.\n
\n\n

Example 2:

\n\n
\nInput: cars = [[3,4],[5,4],[6,3],[9,1]]\nOutput: [2.00000,1.00000,1.50000,-1.00000]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= cars.length <= 105
  • \n\t
  • 1 <= positioni, speedi <= 106
  • \n\t
  • positioni < positioni+1
  • \n
\n", "content_cn": "

\u5728\u4e00\u6761\u5355\u8f66\u9053\u4e0a\u6709 n\u00a0\u8f86\u8f66\uff0c\u5b83\u4eec\u671d\u7740\u540c\u6837\u7684\u65b9\u5411\u884c\u9a76\u3002\u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u4e3a n\u00a0\u7684\u6570\u7ec4 cars\u00a0\uff0c\u5176\u4e2d\u00a0cars[i] = [positioni, speedi]\u00a0\uff0c\u5b83\u8868\u793a\uff1a

\n\n
    \n\t
  • positioni\u00a0\u662f\u7b2c i\u00a0\u8f86\u8f66\u548c\u9053\u8def\u8d77\u70b9\u4e4b\u95f4\u7684\u8ddd\u79bb\uff08\u5355\u4f4d\uff1a\u7c73\uff09\u3002\u9898\u76ee\u4fdd\u8bc1\u00a0positioni < positioni+1\u00a0\u3002
  • \n\t
  • speedi\u00a0\u662f\u7b2c i\u00a0\u8f86\u8f66\u7684\u521d\u59cb\u901f\u5ea6\uff08\u5355\u4f4d\uff1a\u7c73/\u79d2\uff09\u3002
  • \n
\n\n

\u7b80\u5355\u8d77\u89c1\uff0c\u6240\u6709\u8f66\u5b50\u53ef\u4ee5\u89c6\u4e3a\u5728\u6570\u8f74\u4e0a\u79fb\u52a8\u7684\u70b9\u3002\u5f53\u4e24\u8f86\u8f66\u5360\u636e\u540c\u4e00\u4e2a\u4f4d\u7f6e\u65f6\uff0c\u6211\u4eec\u79f0\u5b83\u4eec\u76f8\u9047\u4e86\u3002\u4e00\u65e6\u4e24\u8f86\u8f66\u76f8\u9047\uff0c\u5b83\u4eec\u4f1a\u5408\u5e76\u6210\u4e00\u4e2a\u8f66\u961f\uff0c\u8fd9\u4e2a\u8f66\u961f\u91cc\u7684\u8f66\u6709\u7740\u540c\u6837\u7684\u4f4d\u7f6e\u548c\u76f8\u540c\u7684\u901f\u5ea6\uff0c\u901f\u5ea6\u4e3a\u8fd9\u4e2a\u8f66\u961f\u91cc\u00a0\u6700\u6162\u00a0\u4e00\u8f86\u8f66\u7684\u901f\u5ea6\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u4e00\u4e2a\u6570\u7ec4\u00a0answer\u00a0\uff0c\u5176\u4e2d\u00a0answer[i]\u00a0\u662f\u7b2c i\u00a0\u8f86\u8f66\u4e0e\u4e0b\u4e00\u8f86\u8f66\u76f8\u9047\u7684\u65f6\u95f4\uff08\u5355\u4f4d\uff1a\u79d2\uff09\uff0c\u5982\u679c\u8fd9\u8f86\u8f66\u4e0d\u4f1a\u4e0e\u4e0b\u4e00\u8f86\u8f66\u76f8\u9047\uff0c\u5219 answer[i]\u00a0\u4e3a -1\u00a0\u3002\u7b54\u6848\u7cbe\u5ea6\u8bef\u5dee\u9700\u5728 10-5\u00a0\u4ee5\u5185\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1acars = [[1,2],[2,1],[4,3],[7,2]]\n\u8f93\u51fa\uff1a[1.00000,-1.00000,3.00000,-1.00000]\n\u89e3\u91ca\uff1a\u7ecf\u8fc7\u6070\u597d 1 \u79d2\u4ee5\u540e\uff0c\u7b2c\u4e00\u8f86\u8f66\u4f1a\u4e0e\u7b2c\u4e8c\u8f86\u8f66\u76f8\u9047\uff0c\u5e76\u5f62\u6210\u4e00\u4e2a 1 m/s \u7684\u8f66\u961f\u3002\u7ecf\u8fc7\u6070\u597d 3 \u79d2\u4ee5\u540e\uff0c\u7b2c\u4e09\u8f86\u8f66\u4f1a\u4e0e\u7b2c\u56db\u8f86\u8f66\u76f8\u9047\uff0c\u5e76\u5f62\u6210\u4e00\u4e2a 2 m/s \u7684\u8f66\u961f\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1acars = [[3,4],[5,4],[6,3],[9,1]]\n\u8f93\u51fa\uff1a[2.00000,1.00000,1.50000,-1.00000]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= cars.length <= 105
  • \n\t
  • 1 <= positioni, speedi <= 106
  • \n\t
  • positioni < positioni+1
  • \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector getCollisionTimes(vector>& cars) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double[] getCollisionTimes(int[][] cars) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getCollisionTimes(self, cars):\n \"\"\"\n :type cars: List[List[int]]\n :rtype: List[float]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getCollisionTimes(self, cars: List[List[int]]) -> List[float]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\ndouble* getCollisionTimes(int** cars, int carsSize, int* carsColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double[] GetCollisionTimes(int[][] cars) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} cars\n * @return {number[]}\n */\nvar getCollisionTimes = function(cars) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} cars\n# @return {Float[]}\ndef get_collision_times(cars)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getCollisionTimes(_ cars: [[Int]]) -> [Double] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getCollisionTimes(cars [][]int) []float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getCollisionTimes(cars: Array[Array[Int]]): Array[Double] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getCollisionTimes(cars: Array): DoubleArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_collision_times(cars: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $cars\n * @return Float[]\n */\n function getCollisionTimes($cars) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getCollisionTimes(cars: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-collision-times cars)\n (-> (listof (listof exact-integer?)) (listof flonum?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1776](https://leetcode-cn.com/problems/car-fleet-ii)", "[\u8f66\u961f II](/solution/1700-1799/1776.Car%20Fleet%20II/README.md)", "`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[1776](https://leetcode.com/problems/car-fleet-ii)", "[Car Fleet II](/solution/1700-1799/1776.Car%20Fleet%20II/README_EN.md)", "`Math`", "Hard", ""]}, {"question_id": "1901", "frontend_question_id": "1775", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/equal-sum-arrays-with-minimum-number-of-operations", "url_en": "https://leetcode.com/problems/equal-sum-arrays-with-minimum-number-of-operations", "relative_path_cn": "/solution/1700-1799/1775.Equal%20Sum%20Arrays%20With%20Minimum%20Number%20of%20Operations/README.md", "relative_path_en": "/solution/1700-1799/1775.Equal%20Sum%20Arrays%20With%20Minimum%20Number%20of%20Operations/README_EN.md", "title_cn": "\u901a\u8fc7\u6700\u5c11\u64cd\u4f5c\u6b21\u6570\u4f7f\u6570\u7ec4\u7684\u548c\u76f8\u7b49", "title_en": "Equal Sum Arrays With Minimum Number of Operations", "question_title_slug": "equal-sum-arrays-with-minimum-number-of-operations", "content_en": "

You are given two arrays of integers nums1 and nums2, possibly of different lengths. The values in the arrays are between 1 and 6, inclusive.

\n\n

In one operation, you can change any integer's value in any of the arrays to any value between 1 and 6, inclusive.

\n\n

Return the minimum number of operations required to make the sum of values in nums1 equal to the sum of values in nums2. Return -1\u200b\u200b\u200b\u200b\u200b if it is not possible to make the sum of the two arrays equal.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums1 = [1,2,3,4,5,6], nums2 = [1,1,2,2,2,2]\nOutput: 3\nExplanation: You can make the sums of nums1 and nums2 equal with 3 operations. All indices are 0-indexed.\n- Change nums2[0] to 6. nums1 = [1,2,3,4,5,6], nums2 = [6,1,2,2,2,2].\n- Change nums1[5] to 1. nums1 = [1,2,3,4,5,1], nums2 = [6,1,2,2,2,2].\n- Change nums1[2] to 2. nums1 = [1,2,2,4,5,1], nums2 = [6,1,2,2,2,2].\n
\n\n

Example 2:

\n\n
\nInput: nums1 = [1,1,1,1,1,1,1], nums2 = [6]\nOutput: -1\nExplanation: There is no way to decrease the sum of nums1 or to increase the sum of nums2 to make them equal.\n
\n\n

Example 3:

\n\n
\nInput: nums1 = [6,6], nums2 = [1]\nOutput: 3\nExplanation: You can make the sums of nums1 and nums2 equal with 3 operations. All indices are 0-indexed. \n- Change nums1[0] to 2. nums1 = [2,6], nums2 = [1].\n- Change nums1[1] to 2. nums1 = [2,2], nums2 = [1].\n- Change nums2[0] to 4. nums1 = [2,2], nums2 = [4].\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums1.length, nums2.length <= 105
  • \n\t
  • 1 <= nums1[i], nums2[i] <= 6
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e24\u4e2a\u957f\u5ea6\u53ef\u80fd\u4e0d\u7b49\u7684\u6574\u6570\u6570\u7ec4\u00a0nums1 \u548c\u00a0nums2\u00a0\u3002\u4e24\u4e2a\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u503c\u90fd\u5728\u00a01\u00a0\u5230\u00a06\u00a0\u4e4b\u95f4\uff08\u5305\u542b\u00a01\u00a0\u548c\u00a06\uff09\u3002

\n\n

\u6bcf\u6b21\u64cd\u4f5c\u4e2d\uff0c\u4f60\u53ef\u4ee5\u9009\u62e9 \u4efb\u610f\u00a0\u6570\u7ec4\u4e2d\u7684\u4efb\u610f\u4e00\u4e2a\u6574\u6570\uff0c\u5c06\u5b83\u53d8\u6210 1\u00a0\u5230 6\u00a0\u4e4b\u95f4 \u4efb\u610f\u00a0\u7684\u503c\uff08\u5305\u542b 1\u00a0\u548c 6\uff09\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u4f7f nums1\u00a0\u4e2d\u6240\u6709\u6570\u7684\u548c\u4e0e\u00a0nums2\u00a0\u4e2d\u6240\u6709\u6570\u7684\u548c\u76f8\u7b49\u7684\u6700\u5c11\u64cd\u4f5c\u6b21\u6570\u3002\u5982\u679c\u65e0\u6cd5\u4f7f\u4e24\u4e2a\u6570\u7ec4\u7684\u548c\u76f8\u7b49\uff0c\u8bf7\u8fd4\u56de -1\u00a0\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anums1 = [1,2,3,4,5,6], nums2 = [1,1,2,2,2,2]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u901a\u8fc7 3 \u6b21\u64cd\u4f5c\u4f7f nums1 \u4e2d\u6240\u6709\u6570\u7684\u548c\u4e0e nums2 \u4e2d\u6240\u6709\u6570\u7684\u548c\u76f8\u7b49\u3002\u4ee5\u4e0b\u6570\u7ec4\u4e0b\u6807\u90fd\u4ece 0 \u5f00\u59cb\u3002\n- \u5c06 nums2[0] \u53d8\u4e3a 6 \u3002 nums1 = [1,2,3,4,5,6], nums2 = [6,1,2,2,2,2] \u3002\n- \u5c06 nums1[5] \u53d8\u4e3a 1 \u3002 nums1 = [1,2,3,4,5,1], nums2 = [6,1,2,2,2,2] \u3002\n- \u5c06 nums1[2] \u53d8\u4e3a 2 \u3002 nums1 = [1,2,2,4,5,1], nums2 = [6,1,2,2,2,2] \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anums1 = [1,1,1,1,1,1,1], nums2 = [6]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u6ca1\u6709\u529e\u6cd5\u51cf\u5c11 nums1 \u7684\u548c\u6216\u8005\u589e\u52a0 nums2 \u7684\u548c\u4f7f\u4e8c\u8005\u76f8\u7b49\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1anums1 = [6,6], nums2 = [1]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u901a\u8fc7 3 \u6b21\u64cd\u4f5c\u4f7f nums1 \u4e2d\u6240\u6709\u6570\u7684\u548c\u4e0e nums2 \u4e2d\u6240\u6709\u6570\u7684\u548c\u76f8\u7b49\u3002\u4ee5\u4e0b\u6570\u7ec4\u4e0b\u6807\u90fd\u4ece 0 \u5f00\u59cb\u3002\n- \u5c06 nums1[0] \u53d8\u4e3a 2 \u3002 nums1 = [2,6], nums2 = [1] \u3002\n- \u5c06 nums1[1] \u53d8\u4e3a 2 \u3002 nums1 = [2,2], nums2 = [1] \u3002\n- \u5c06 nums2[0] \u53d8\u4e3a 4 \u3002 nums1 = [2,2], nums2 = [4] \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums1.length, nums2.length <= 105
  • \n\t
  • 1 <= nums1[i], nums2[i] <= 6
  • \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minOperations(vector& nums1, vector& nums2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minOperations(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minOperations(self, nums1, nums2):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minOperations(self, nums1: List[int], nums2: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minOperations(int* nums1, int nums1Size, int* nums2, int nums2Size){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinOperations(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums1\n * @param {number[]} nums2\n * @return {number}\n */\nvar minOperations = function(nums1, nums2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums1\n# @param {Integer[]} nums2\n# @return {Integer}\ndef min_operations(nums1, nums2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minOperations(_ nums1: [Int], _ nums2: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minOperations(nums1 []int, nums2 []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minOperations(nums1: Array[Int], nums2: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minOperations(nums1: IntArray, nums2: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_operations(nums1: Vec, nums2: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums1\n * @param Integer[] $nums2\n * @return Integer\n */\n function minOperations($nums1, $nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minOperations(nums1: number[], nums2: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-operations nums1 nums2)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1775](https://leetcode-cn.com/problems/equal-sum-arrays-with-minimum-number-of-operations)", "[\u901a\u8fc7\u6700\u5c11\u64cd\u4f5c\u6b21\u6570\u4f7f\u6570\u7ec4\u7684\u548c\u76f8\u7b49](/solution/1700-1799/1775.Equal%20Sum%20Arrays%20With%20Minimum%20Number%20of%20Operations/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1775](https://leetcode.com/problems/equal-sum-arrays-with-minimum-number-of-operations)", "[Equal Sum Arrays With Minimum Number of Operations](/solution/1700-1799/1775.Equal%20Sum%20Arrays%20With%20Minimum%20Number%20of%20Operations/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1900", "frontend_question_id": "1774", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/closest-dessert-cost", "url_en": "https://leetcode.com/problems/closest-dessert-cost", "relative_path_cn": "/solution/1700-1799/1774.Closest%20Dessert%20Cost/README.md", "relative_path_en": "/solution/1700-1799/1774.Closest%20Dessert%20Cost/README_EN.md", "title_cn": "\u6700\u63a5\u8fd1\u76ee\u6807\u4ef7\u683c\u7684\u751c\u70b9\u6210\u672c", "title_en": "Closest Dessert Cost", "question_title_slug": "closest-dessert-cost", "content_en": "

You would like to make dessert and are preparing to buy the ingredients. You have n ice cream base flavors and m types of toppings to choose from. You must follow these rules when making your dessert:

\n\n
    \n\t
  • There must be exactly one ice cream base.
  • \n\t
  • You can add one or more types of topping or have no toppings at all.
  • \n\t
  • There are at most two of each type of topping.
  • \n
\n\n

You are given three inputs:

\n\n
    \n\t
  • baseCosts, an integer array of length n, where each baseCosts[i] represents the price of the ith ice cream base flavor.
  • \n\t
  • toppingCosts, an integer array of length m, where each toppingCosts[i] is the price of one of the ith topping.
  • \n\t
  • target, an integer representing your target price for dessert.
  • \n
\n\n

You want to make a dessert with a total cost as close to target as possible.

\n\n

Return the closest possible cost of the dessert to target. If there are multiple, return the lower one.

\n\n

 

\n

Example 1:

\n\n
\nInput: baseCosts = [1,7], toppingCosts = [3,4], target = 10\nOutput: 10\nExplanation: Consider the following combination (all 0-indexed):\n- Choose base 1: cost 7\n- Take 1 of topping 0: cost 1 x 3 = 3\n- Take 0 of topping 1: cost 0 x 4 = 0\nTotal: 7 + 3 + 0 = 10.\n
\n\n

Example 2:

\n\n
\nInput: baseCosts = [2,3], toppingCosts = [4,5,100], target = 18\nOutput: 17\nExplanation: Consider the following combination (all 0-indexed):\n- Choose base 1: cost 3\n- Take 1 of topping 0: cost 1 x 4 = 4\n- Take 2 of topping 1: cost 2 x 5 = 10\n- Take 0 of topping 2: cost 0 x 100 = 0\nTotal: 3 + 4 + 10 + 0 = 17. You cannot make a dessert with a total cost of 18.\n
\n\n

Example 3:

\n\n
\nInput: baseCosts = [3,10], toppingCosts = [2,5], target = 9\nOutput: 8\nExplanation: It is possible to make desserts with cost 8 and 10. Return 8 as it is the lower cost.\n
\n\n

Example 4:

\n\n
\nInput: baseCosts = [10], toppingCosts = [1], target = 1\nOutput: 10\nExplanation: Notice that you don't have to have any toppings, but you must have exactly one base.
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == baseCosts.length
  • \n\t
  • m == toppingCosts.length
  • \n\t
  • 1 <= n, m <= 10
  • \n\t
  • 1 <= baseCosts[i], toppingCosts[i] <= 104
  • \n\t
  • 1 <= target <= 104
  • \n
\n", "content_cn": "

\u4f60\u6253\u7b97\u505a\u751c\u70b9\uff0c\u73b0\u5728\u9700\u8981\u8d2d\u4e70\u914d\u6599\u3002\u76ee\u524d\u5171\u6709 n \u79cd\u51b0\u6fc0\u51cc\u57fa\u6599\u548c m \u79cd\u914d\u6599\u53ef\u4f9b\u9009\u8d2d\u3002\u800c\u5236\u4f5c\u751c\u70b9\u9700\u8981\u9075\u5faa\u4ee5\u4e0b\u51e0\u6761\u89c4\u5219\uff1a

\n\n
    \n\t
  • \u5fc5\u987b\u9009\u62e9 \u4e00\u79cd \u51b0\u6fc0\u51cc\u57fa\u6599\u3002
  • \n\t
  • \u53ef\u4ee5\u6dfb\u52a0 \u4e00\u79cd\u6216\u591a\u79cd \u914d\u6599\uff0c\u4e5f\u53ef\u4ee5\u4e0d\u6dfb\u52a0\u4efb\u4f55\u914d\u6599\u3002
  • \n\t
  • \u6bcf\u79cd\u7c7b\u578b\u7684\u914d\u6599 \u6700\u591a\u4e24\u4efd \u3002
  • \n
\n\n

\u7ed9\u4f60\u4ee5\u4e0b\u4e09\u4e2a\u8f93\u5165\uff1a

\n\n
    \n\t
  • baseCosts \uff0c\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u6574\u6570\u6570\u7ec4\uff0c\u5176\u4e2d\u6bcf\u4e2a baseCosts[i] \u8868\u793a\u7b2c i \u79cd\u51b0\u6fc0\u51cc\u57fa\u6599\u7684\u4ef7\u683c\u3002
  • \n\t
  • toppingCosts\uff0c\u4e00\u4e2a\u957f\u5ea6\u4e3a m \u7684\u6574\u6570\u6570\u7ec4\uff0c\u5176\u4e2d\u6bcf\u4e2a toppingCosts[i] \u8868\u793a \u4e00\u4efd \u7b2c i \u79cd\u51b0\u6fc0\u51cc\u914d\u6599\u7684\u4ef7\u683c\u3002
  • \n\t
  • target \uff0c\u4e00\u4e2a\u6574\u6570\uff0c\u8868\u793a\u4f60\u5236\u4f5c\u751c\u70b9\u7684\u76ee\u6807\u4ef7\u683c\u3002
  • \n
\n\n

\u4f60\u5e0c\u671b\u81ea\u5df1\u505a\u7684\u751c\u70b9\u603b\u6210\u672c\u5c3d\u53ef\u80fd\u63a5\u8fd1\u76ee\u6807\u4ef7\u683c target \u3002

\n\n

\u8fd4\u56de\u6700\u63a5\u8fd1 target \u7684\u751c\u70b9\u6210\u672c\u3002\u5982\u679c\u6709\u591a\u79cd\u65b9\u6848\uff0c\u8fd4\u56de\u00a0\u6210\u672c\u76f8\u5bf9\u8f83\u4f4e \u7684\u4e00\u79cd\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1abaseCosts = [1,7], toppingCosts = [3,4], target = 10\n\u8f93\u51fa\uff1a10\n\u89e3\u91ca\uff1a\u8003\u8651\u4e0b\u9762\u7684\u65b9\u6848\u7ec4\u5408\uff08\u6240\u6709\u4e0b\u6807\u5747\u4ece 0 \u5f00\u59cb\uff09\uff1a\n- \u9009\u62e9 1 \u53f7\u57fa\u6599\uff1a\u6210\u672c 7\n- \u9009\u62e9 1 \u4efd 0 \u53f7\u914d\u6599\uff1a\u6210\u672c 1 x 3 = 3\n- \u9009\u62e9 0 \u4efd 1 \u53f7\u914d\u6599\uff1a\u6210\u672c 0 x 4 = 0\n\u603b\u6210\u672c\uff1a7 + 3 + 0 = 10 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1abaseCosts = [2,3], toppingCosts = [4,5,100], target = 18\n\u8f93\u51fa\uff1a17\n\u89e3\u91ca\uff1a\u8003\u8651\u4e0b\u9762\u7684\u65b9\u6848\u7ec4\u5408\uff08\u6240\u6709\u4e0b\u6807\u5747\u4ece 0 \u5f00\u59cb\uff09\uff1a\n- \u9009\u62e9 1 \u53f7\u57fa\u6599\uff1a\u6210\u672c 3\n- \u9009\u62e9 1 \u4efd 0 \u53f7\u914d\u6599\uff1a\u6210\u672c 1 x 4 = 4\n- \u9009\u62e9 2 \u4efd 1 \u53f7\u914d\u6599\uff1a\u6210\u672c 2 x 5 = 10\n- \u9009\u62e9 0 \u4efd 2 \u53f7\u914d\u6599\uff1a\u6210\u672c 0 x 100 = 0\n\u603b\u6210\u672c\uff1a3 + 4 + 10 + 0 = 17 \u3002\u4e0d\u5b58\u5728\u603b\u6210\u672c\u4e3a 18 \u7684\u751c\u70b9\u5236\u4f5c\u65b9\u6848\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1abaseCosts = [3,10], toppingCosts = [2,5], target = 9\n\u8f93\u51fa\uff1a8\n\u89e3\u91ca\uff1a\u53ef\u4ee5\u5236\u4f5c\u603b\u6210\u672c\u4e3a 8 \u548c 10 \u7684\u751c\u70b9\u3002\u8fd4\u56de 8 \uff0c\u56e0\u4e3a\u8fd9\u662f\u6210\u672c\u66f4\u4f4e\u7684\u65b9\u6848\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1abaseCosts = [10], toppingCosts = [1], target = 1\n\u8f93\u51fa\uff1a10\n\u89e3\u91ca\uff1a\u6ce8\u610f\uff0c\u4f60\u53ef\u4ee5\u9009\u62e9\u4e0d\u6dfb\u52a0\u4efb\u4f55\u914d\u6599\uff0c\u4f46\u4f60\u5fc5\u987b\u9009\u62e9\u4e00\u79cd\u57fa\u6599\u3002
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • n == baseCosts.length
  • \n\t
  • m == toppingCosts.length
  • \n\t
  • 1 <= n, m <= 10
  • \n\t
  • 1 <= baseCosts[i], toppingCosts[i] <= 104
  • \n\t
  • 1 <= target <= 104
  • \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int closestCost(vector& baseCosts, vector& toppingCosts, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int closestCost(int[] baseCosts, int[] toppingCosts, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def closestCost(self, baseCosts, toppingCosts, target):\n \"\"\"\n :type baseCosts: List[int]\n :type toppingCosts: List[int]\n :type target: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def closestCost(self, baseCosts: List[int], toppingCosts: List[int], target: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint closestCost(int* baseCosts, int baseCostsSize, int* toppingCosts, int toppingCostsSize, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ClosestCost(int[] baseCosts, int[] toppingCosts, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} baseCosts\n * @param {number[]} toppingCosts\n * @param {number} target\n * @return {number}\n */\nvar closestCost = function(baseCosts, toppingCosts, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} base_costs\n# @param {Integer[]} topping_costs\n# @param {Integer} target\n# @return {Integer}\ndef closest_cost(base_costs, topping_costs, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func closestCost(_ baseCosts: [Int], _ toppingCosts: [Int], _ target: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func closestCost(baseCosts []int, toppingCosts []int, target int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def closestCost(baseCosts: Array[Int], toppingCosts: Array[Int], target: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun closestCost(baseCosts: IntArray, toppingCosts: IntArray, target: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn closest_cost(base_costs: Vec, topping_costs: Vec, target: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $baseCosts\n * @param Integer[] $toppingCosts\n * @param Integer $target\n * @return Integer\n */\n function closestCost($baseCosts, $toppingCosts, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function closestCost(baseCosts: number[], toppingCosts: number[], target: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (closest-cost baseCosts toppingCosts target)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1774](https://leetcode-cn.com/problems/closest-dessert-cost)", "[\u6700\u63a5\u8fd1\u76ee\u6807\u4ef7\u683c\u7684\u751c\u70b9\u6210\u672c](/solution/1700-1799/1774.Closest%20Dessert%20Cost/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1774](https://leetcode.com/problems/closest-dessert-cost)", "[Closest Dessert Cost](/solution/1700-1799/1774.Closest%20Dessert%20Cost/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1899", "frontend_question_id": "1773", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-items-matching-a-rule", "url_en": "https://leetcode.com/problems/count-items-matching-a-rule", "relative_path_cn": "/solution/1700-1799/1773.Count%20Items%20Matching%20a%20Rule/README.md", "relative_path_en": "/solution/1700-1799/1773.Count%20Items%20Matching%20a%20Rule/README_EN.md", "title_cn": "\u7edf\u8ba1\u5339\u914d\u68c0\u7d22\u89c4\u5219\u7684\u7269\u54c1\u6570\u91cf", "title_en": "Count Items Matching a Rule", "question_title_slug": "count-items-matching-a-rule", "content_en": "

You are given an array items, where each items[i] = [typei, colori, namei] describes the type, color, and name of the ith item. You are also given a rule represented by two strings, ruleKey and ruleValue.

\n\n

The ith item is said to match the rule if one of the following is true:

\n\n
    \n\t
  • ruleKey == "type" and ruleValue == typei.
  • \n\t
  • ruleKey == "color" and ruleValue == colori.
  • \n\t
  • ruleKey == "name" and ruleValue == namei.
  • \n
\n\n

Return the number of items that match the given rule.

\n\n

 

\n

Example 1:

\n\n
\nInput: items = [["phone","blue","pixel"],["computer","silver","lenovo"],["phone","gold","iphone"]], ruleKey = "color", ruleValue = "silver"\nOutput: 1\nExplanation: There is only one item matching the given rule, which is ["computer","silver","lenovo"].\n
\n\n

Example 2:

\n\n
\nInput: items = [["phone","blue","pixel"],["computer","silver","phone"],["phone","gold","iphone"]], ruleKey = "type", ruleValue = "phone"\nOutput: 2\nExplanation: There are only two items matching the given rule, which are ["phone","blue","pixel"] and ["phone","gold","iphone"]. Note that the item ["computer","silver","phone"] does not match.
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= items.length <= 104
  • \n\t
  • 1 <= typei.length, colori.length, namei.length, ruleValue.length <= 10
  • \n\t
  • ruleKey is equal to either "type", "color", or "name".
  • \n\t
  • All strings consist only of lowercase letters.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 items \uff0c\u5176\u4e2d\u00a0items[i] = [typei, colori, namei] \uff0c\u63cf\u8ff0\u7b2c i \u4ef6\u7269\u54c1\u7684\u7c7b\u578b\u3001\u989c\u8272\u4ee5\u53ca\u540d\u79f0\u3002

\n\n

\u53e6\u7ed9\u4f60\u4e00\u6761\u7531\u4e24\u4e2a\u5b57\u7b26\u4e32\u00a0ruleKey \u548c ruleValue \u8868\u793a\u7684\u68c0\u7d22\u89c4\u5219\u3002

\n\n

\u5982\u679c\u7b2c i \u4ef6\u7269\u54c1\u80fd\u6ee1\u8db3\u4e0b\u8ff0\u6761\u4ef6\u4e4b\u4e00\uff0c\u5219\u8ba4\u4e3a\u8be5\u7269\u54c1\u4e0e\u7ed9\u5b9a\u7684\u68c0\u7d22\u89c4\u5219 \u5339\u914d \uff1a

\n\n
    \n\t
  • ruleKey == \"type\" \u4e14 ruleValue == typei \u3002
  • \n\t
  • ruleKey == \"color\" \u4e14 ruleValue == colori \u3002
  • \n\t
  • ruleKey == \"name\" \u4e14 ruleValue == namei \u3002
  • \n
\n\n

\u7edf\u8ba1\u5e76\u8fd4\u56de \u5339\u914d\u68c0\u7d22\u89c4\u5219\u7684\u7269\u54c1\u6570\u91cf \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aitems = [[\"phone\",\"blue\",\"pixel\"],[\"computer\",\"silver\",\"lenovo\"],[\"phone\",\"gold\",\"iphone\"]], ruleKey = \"color\", ruleValue = \"silver\"\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u53ea\u6709\u4e00\u4ef6\u7269\u54c1\u5339\u914d\u68c0\u7d22\u89c4\u5219\uff0c\u8fd9\u4ef6\u7269\u54c1\u662f [\"computer\",\"silver\",\"lenovo\"] \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aitems = [[\"phone\",\"blue\",\"pixel\"],[\"computer\",\"silver\",\"phone\"],[\"phone\",\"gold\",\"iphone\"]], ruleKey = \"type\", ruleValue = \"phone\"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u53ea\u6709\u4e24\u4ef6\u7269\u54c1\u5339\u914d\u68c0\u7d22\u89c4\u5219\uff0c\u8fd9\u4e24\u4ef6\u7269\u54c1\u5206\u522b\u662f [\"phone\",\"blue\",\"pixel\"] \u548c [\"phone\",\"gold\",\"iphone\"] \u3002\u6ce8\u610f\uff0c[\"computer\",\"silver\",\"phone\"] \u672a\u5339\u914d\u68c0\u7d22\u89c4\u5219\u3002
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= items.length <= 104
  • \n\t
  • 1 <= typei.length, colori.length, namei.length, ruleValue.length <= 10
  • \n\t
  • ruleKey \u7b49\u4e8e \"type\"\u3001\"color\" \u6216 \"name\"
  • \n\t
  • \u6240\u6709\u5b57\u7b26\u4e32\u4ec5\u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210
  • \n
\n", "tags_en": ["Array", "String"], "tags_cn": ["\u6570\u7ec4", "\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countMatches(vector>& items, string ruleKey, string ruleValue) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countMatches(List> items, String ruleKey, String ruleValue) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countMatches(self, items, ruleKey, ruleValue):\n \"\"\"\n :type items: List[List[str]]\n :type ruleKey: str\n :type ruleValue: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countMatches(self, items: List[List[str]], ruleKey: str, ruleValue: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countMatches(char *** items, int itemsSize, int* itemsColSize, char * ruleKey, char * ruleValue){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountMatches(IList> items, string ruleKey, string ruleValue) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[][]} items\n * @param {string} ruleKey\n * @param {string} ruleValue\n * @return {number}\n */\nvar countMatches = function(items, ruleKey, ruleValue) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[][]} items\n# @param {String} rule_key\n# @param {String} rule_value\n# @return {Integer}\ndef count_matches(items, rule_key, rule_value)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countMatches(_ items: [[String]], _ ruleKey: String, _ ruleValue: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countMatches(items [][]string, ruleKey string, ruleValue string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countMatches(items: List[List[String]], ruleKey: String, ruleValue: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countMatches(items: List>, ruleKey: String, ruleValue: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_matches(items: Vec>, rule_key: String, rule_value: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $items\n * @param String $ruleKey\n * @param String $ruleValue\n * @return Integer\n */\n function countMatches($items, $ruleKey, $ruleValue) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countMatches(items: string[][], ruleKey: string, ruleValue: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-matches items ruleKey ruleValue)\n (-> (listof (listof string?)) string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1773](https://leetcode-cn.com/problems/count-items-matching-a-rule)", "[\u7edf\u8ba1\u5339\u914d\u68c0\u7d22\u89c4\u5219\u7684\u7269\u54c1\u6570\u91cf](/solution/1700-1799/1773.Count%20Items%20Matching%20a%20Rule/README.md)", "`\u6570\u7ec4`,`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1773](https://leetcode.com/problems/count-items-matching-a-rule)", "[Count Items Matching a Rule](/solution/1700-1799/1773.Count%20Items%20Matching%20a%20Rule/README_EN.md)", "`Array`,`String`", "Easy", ""]}, {"question_id": "1898", "frontend_question_id": "1747", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/leetflex-banned-accounts", "url_en": "https://leetcode.com/problems/leetflex-banned-accounts", "relative_path_cn": "/solution/1700-1799/1747.Leetflex%20Banned%20Accounts/README.md", "relative_path_en": "/solution/1700-1799/1747.Leetflex%20Banned%20Accounts/README_EN.md", "title_cn": "\u5e94\u8be5\u88ab\u7981\u6b62\u7684Leetflex\u8d26\u6237", "title_en": "Leetflex Banned Accounts", "question_title_slug": "leetflex-banned-accounts", "content_en": "

Table: LogInfo

\r\n\r\n
\r\n+-------------+----------+\r\n| Column Name | Type     |\r\n+-------------+----------+\r\n| account_id  | int      |\r\n| ip_address  | int      |\r\n| login       | datetime |\r\n| logout      | datetime |\r\n+-------------+----------+\r\nThere is no primary key for this table, and it may contain duplicates.\r\nThe table contains information about the login and logout dates of Leetflex accounts. It also contains the IP address from which the account logged in and out.\r\nIt is guaranteed that the logout time is after the login time.\r\n
\r\n\r\n

 

\r\n\r\n

Write an SQL query to find the account_id of the accounts that should be banned from Leetflex. An account should be banned if it was logged in at some moment from two different IP addresses.

\r\n\r\n

Return the result table in any order.

\r\n\r\n

The query result format is in the following example:

\r\n\r\n

 

\r\n\r\n
\r\nLogInfo table:\r\n+------------+------------+---------------------+---------------------+\r\n| account_id | ip_address | login               | logout              |\r\n+------------+------------+---------------------+---------------------+\r\n| 1          | 1          | 2021-02-01 09:00:00 | 2021-02-01 09:30:00 |\r\n| 1          | 2          | 2021-02-01 08:00:00 | 2021-02-01 11:30:00 |\r\n| 2          | 6          | 2021-02-01 20:30:00 | 2021-02-01 22:00:00 |\r\n| 2          | 7          | 2021-02-02 20:30:00 | 2021-02-02 22:00:00 |\r\n| 3          | 9          | 2021-02-01 16:00:00 | 2021-02-01 16:59:59 |\r\n| 3          | 13         | 2021-02-01 17:00:00 | 2021-02-01 17:59:59 |\r\n| 4          | 10         | 2021-02-01 16:00:00 | 2021-02-01 17:00:00 |\r\n| 4          | 11         | 2021-02-01 17:00:00 | 2021-02-01 17:59:59 |\r\n+------------+------------+---------------------+---------------------+\r\n\r\nResult table:\r\n+------------+\r\n| account_id |\r\n+------------+\r\n| 1          |\r\n| 4          |\r\n+------------+\r\nAccount ID 1 --> The account was active from "2021-02-01 09:00:00" to "2021-02-01 09:30:00" with two different IP addresses (1 and 2). It should be banned.\r\nAccount ID 2 --> The account was active from two different addresses (6, 7) but in two different times.\r\nAccount ID 3 --> The account was active from two different addresses (9, 13) on the same day but they do not intersect at any moment.\r\nAccount ID 4 --> The account was active from "2021-02-01 17:00:00" to "2021-02-01 17:00:00" with two different IP addresses (10 and 11). It should be banned.\r\n
", "content_cn": "

\u8868: LogInfo

\n\n
+-------------+----------+\n| Column Name | Type     |\n+-------------+----------+\n| account_id  | int      |\n| ip_address  | int      |\n| login       | datetime |\n| logout      | datetime |\n+-------------+----------+\n\u8be5\u8868\u662f\u6ca1\u6709\u4e3b\u952e\u7684\uff0c\u5b83\u53ef\u80fd\u5305\u542b\u91cd\u590d\u9879\u3002\n\u8be5\u8868\u5305\u542b\u6709\u5173Leetflex\u5e10\u6237\u7684\u767b\u5f55\u548c\u6ce8\u9500\u65e5\u671f\u7684\u4fe1\u606f\u3002 \u5b83\u8fd8\u5305\u542b\u4e86\u8be5\u8d26\u6237\u7528\u4e8e\u767b\u5f55\u548c\u6ce8\u9500\u7684\u7f51\u7edc\u5730\u5740\u7684\u4fe1\u606f\u3002\n\u9898\u76ee\u786e\u4fdd\u6bcf\u4e00\u4e2a\u6ce8\u9500\u65f6\u95f4\u90fd\u5728\u767b\u5f55\u65f6\u95f4\u4e4b\u540e\u3002\n
\n\n

\u00a0

\n\n

\u7f16\u5199\u4e00\u4e2aSQL\u67e5\u8be2\u8bed\u53e5\uff0c\u67e5\u627e\u90a3\u4e9b\u5e94\u8be5\u88ab\u7981\u6b62\u7684Leetflex\u5e10\u6237\u7f16\u53f7account_id\u3002 \u5982\u679c\u67d0\u4e2a\u5e10\u6237\u5728\u67d0\u4e00\u65f6\u523b\u4ece\u4e24\u4e2a\u4e0d\u540c\u7684\u7f51\u7edc\u5730\u5740\u767b\u5f55\u4e86\uff0c\u5219\u8fd9\u4e2a\u5e10\u6237\u5e94\u8be5\u88ab\u7981\u6b62\u3002

\n\n

\u53ef\u4ee5\u4ee5\u4efb\u4f55\u987a\u5e8f\u8fd4\u56de\u7ed3\u679c\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a:

\n\n

\u00a0

\n\n
LogInfo table:\n+------------+------------+---------------------+---------------------+\n| account_id | ip_address | login               | logout              |\n+------------+------------+---------------------+---------------------+\n| 1          | 1          | 2021-02-01 09:00:00 | 2021-02-01 09:30:00 |\n| 1          | 2          | 2021-02-01 08:00:00 | 2021-02-01 11:30:00 |\n| 2          | 6          | 2021-02-01 20:30:00 | 2021-02-01 22:00:00 |\n| 2          | 7          | 2021-02-02 20:30:00 | 2021-02-02 22:00:00 |\n| 3          | 9          | 2021-02-01 16:00:00 | 2021-02-01 16:59:59 |\n| 3          | 13         | 2021-02-01 17:00:00 | 2021-02-01 17:59:59 |\n| 4          | 10         | 2021-02-01 16:00:00 | 2021-02-01 17:00:00 |\n| 4          | 11         | 2021-02-01 17:00:00 | 2021-02-01 17:59:59 |\n+------------+------------+---------------------+---------------------+\n\nResult table:\n+------------+\n| account_id |\n+------------+\n| 1          |\n| 4          |\n+------------+\nAccount ID 1 --> \u8be5\u8d26\u6237\u4ece \"2021-02-01 09:00:00\" \u5230 \"2021-02-01 09:30:00\" \u5728\u4e24\u4e2a\u4e0d\u540c\u7684\u7f51\u7edc\u5730\u5740(1 and 2)\u4e0a\u6fc0\u6d3b\u4e86\u3002\u5b83\u5e94\u8be5\u88ab\u7981\u6b62.\nAccount ID 2 --> \u8be5\u8d26\u6237\u5728\u4e24\u4e2a\u4e0d\u540c\u7684\u7f51\u7edc\u5730\u5740 (6, 7) \u6fc0\u6d3b\u4e86\uff0c\u4f46\u5728\u4e0d\u540c\u7684\u65f6\u95f4\u4e0a.\nAccount ID 3 --> \u8be5\u8d26\u6237\u5728\u4e24\u4e2a\u4e0d\u540c\u7684\u7f51\u7edc\u5730\u5740 (9, 13) \u6fc0\u6d3b\u4e86\uff0c\u867d\u7136\u662f\u540c\u4e00\u5929\uff0c\u4f46\u65f6\u95f4\u4e0a\u6ca1\u6709\u4ea4\u96c6.\nAccount ID 4 --> \u8be5\u8d26\u6237\u4ece \"2021-02-01 17:00:00\" \u5230 \"2021-02-01 17:00:00\" \u5728\u4e24\u4e2a\u4e0d\u540c\u7684\u7f51\u7edc\u5730\u5740 (10 and 11)\u4e0a\u6fc0\u6d3b\u4e86\u3002\u5b83\u5e94\u8be5\u88ab\u7981\u6b62.\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1747](https://leetcode-cn.com/problems/leetflex-banned-accounts)", "[\u5e94\u8be5\u88ab\u7981\u6b62\u7684Leetflex\u8d26\u6237](/solution/1700-1799/1747.Leetflex%20Banned%20Accounts/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1747](https://leetcode.com/problems/leetflex-banned-accounts)", "[Leetflex Banned Accounts](/solution/1700-1799/1747.Leetflex%20Banned%20Accounts/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1897", "frontend_question_id": "1771", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximize-palindrome-length-from-subsequences", "url_en": "https://leetcode.com/problems/maximize-palindrome-length-from-subsequences", "relative_path_cn": "/solution/1700-1799/1771.Maximize%20Palindrome%20Length%20From%20Subsequences/README.md", "relative_path_en": "/solution/1700-1799/1771.Maximize%20Palindrome%20Length%20From%20Subsequences/README_EN.md", "title_cn": "\u7531\u5b50\u5e8f\u5217\u6784\u9020\u7684\u6700\u957f\u56de\u6587\u4e32\u7684\u957f\u5ea6", "title_en": "Maximize Palindrome Length From Subsequences", "question_title_slug": "maximize-palindrome-length-from-subsequences", "content_en": "

You are given two strings, word1 and word2. You want to construct a string in the following manner:

\n\n
    \n\t
  • Choose some non-empty subsequence subsequence1 from word1.
  • \n\t
  • Choose some non-empty subsequence subsequence2 from word2.
  • \n\t
  • Concatenate the subsequences: subsequence1 + subsequence2, to make the string.
  • \n
\n\n

Return the length of the longest palindrome that can be constructed in the described manner. If no palindromes can be constructed, return 0.

\n\n

A subsequence of a string s is a string that can be made by deleting some (possibly none) characters from s without changing the order of the remaining characters.

\n\n

A palindrome is a string that reads the same forward as well as backward.

\n\n

 

\n

Example 1:

\n\n
\nInput: word1 = "cacb", word2 = "cbba"\nOutput: 5\nExplanation: Choose "ab" from word1 and "cba" from word2 to make "abcba", which is a palindrome.
\n\n

Example 2:

\n\n
\nInput: word1 = "ab", word2 = "ab"\nOutput: 3\nExplanation: Choose "ab" from word1 and "a" from word2 to make "aba", which is a palindrome.
\n\n

Example 3:

\n\n
\nInput: word1 = "aa", word2 = "bb"\nOutput: 0\nExplanation: You cannot construct a palindrome from the described method, so return 0.
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= word1.length, word2.length <= 1000
  • \n\t
  • word1 and word2 consist of lowercase English letters.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e24\u4e2a\u5b57\u7b26\u4e32 word1 \u548c word2 \uff0c\u8bf7\u4f60\u6309\u4e0b\u8ff0\u65b9\u6cd5\u6784\u9020\u4e00\u4e2a\u5b57\u7b26\u4e32\uff1a

\n\n
    \n\t
  • \u4ece word1 \u4e2d\u9009\u51fa\u67d0\u4e2a \u975e\u7a7a \u5b50\u5e8f\u5217 subsequence1 \u3002
  • \n\t
  • \u4ece word2 \u4e2d\u9009\u51fa\u67d0\u4e2a \u975e\u7a7a \u5b50\u5e8f\u5217 subsequence2 \u3002
  • \n\t
  • \u8fde\u63a5\u4e24\u4e2a\u5b50\u5e8f\u5217 subsequence1 + subsequence2 \uff0c\u5f97\u5230\u5b57\u7b26\u4e32\u3002
  • \n
\n\n

\u8fd4\u56de\u53ef\u6309\u4e0a\u8ff0\u65b9\u6cd5\u6784\u9020\u7684\u6700\u957f \u56de\u6587\u4e32 \u7684 \u957f\u5ea6 \u3002\u5982\u679c\u65e0\u6cd5\u6784\u9020\u56de\u6587\u4e32\uff0c\u8fd4\u56de 0 \u3002

\n\n

\u5b57\u7b26\u4e32 s \u7684\u4e00\u4e2a \u5b50\u5e8f\u5217 \u662f\u901a\u8fc7\u4ece s \u4e2d\u5220\u9664\u4e00\u4e9b\uff08\u4e5f\u53ef\u80fd\u4e0d\u5220\u9664\uff09\u5b57\u7b26\u800c\u4e0d\u66f4\u6539\u5176\u4f59\u5b57\u7b26\u7684\u987a\u5e8f\u751f\u6210\u7684\u5b57\u7b26\u4e32\u3002

\n\n

\u56de\u6587\u4e32 \u662f\u6b63\u7740\u8bfb\u548c\u53cd\u7740\u8bfb\u7ed3\u679c\u4e00\u81f4\u7684\u5b57\u7b26\u4e32\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aword1 = \"cacb\", word2 = \"cbba\"\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u4ece word1 \u4e2d\u9009\u51fa \"ab\" \uff0c\u4ece word2 \u4e2d\u9009\u51fa \"cba\" \uff0c\u5f97\u5230\u56de\u6587\u4e32 \"abcba\" \u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aword1 = \"ab\", word2 = \"ab\"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u4ece word1 \u4e2d\u9009\u51fa \"ab\" \uff0c\u4ece word2 \u4e2d\u9009\u51fa \"a\" \uff0c\u5f97\u5230\u56de\u6587\u4e32 \"aba\" \u3002
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aword1 = \"aa\", word2 = \"bb\"\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u65e0\u6cd5\u6309\u9898\u9762\u6240\u8ff0\u65b9\u6cd5\u6784\u9020\u56de\u6587\u4e32\uff0c\u6240\u4ee5\u8fd4\u56de 0 \u3002
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= word1.length, word2.length <= 1000
  • \n\t
  • word1 \u548c word2 \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int longestPalindrome(string word1, string word2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int longestPalindrome(String word1, String word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestPalindrome(self, word1, word2):\n \"\"\"\n :type word1: str\n :type word2: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestPalindrome(self, word1: str, word2: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint longestPalindrome(char * word1, char * word2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LongestPalindrome(string word1, string word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} word1\n * @param {string} word2\n * @return {number}\n */\nvar longestPalindrome = function(word1, word2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} word1\n# @param {String} word2\n# @return {Integer}\ndef longest_palindrome(word1, word2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestPalindrome(_ word1: String, _ word2: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestPalindrome(word1 string, word2 string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestPalindrome(word1: String, word2: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestPalindrome(word1: String, word2: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_palindrome(word1: String, word2: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $word1\n * @param String $word2\n * @return Integer\n */\n function longestPalindrome($word1, $word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestPalindrome(word1: string, word2: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-palindrome word1 word2)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1771](https://leetcode-cn.com/problems/maximize-palindrome-length-from-subsequences)", "[\u7531\u5b50\u5e8f\u5217\u6784\u9020\u7684\u6700\u957f\u56de\u6587\u4e32\u7684\u957f\u5ea6](/solution/1700-1799/1771.Maximize%20Palindrome%20Length%20From%20Subsequences/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1771](https://leetcode.com/problems/maximize-palindrome-length-from-subsequences)", "[Maximize Palindrome Length From Subsequences](/solution/1700-1799/1771.Maximize%20Palindrome%20Length%20From%20Subsequences/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1896", "frontend_question_id": "1770", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-score-from-performing-multiplication-operations", "url_en": "https://leetcode.com/problems/maximum-score-from-performing-multiplication-operations", "relative_path_cn": "/solution/1700-1799/1770.Maximum%20Score%20from%20Performing%20Multiplication%20Operations/README.md", "relative_path_en": "/solution/1700-1799/1770.Maximum%20Score%20from%20Performing%20Multiplication%20Operations/README_EN.md", "title_cn": "\u6267\u884c\u4e58\u6cd5\u8fd0\u7b97\u7684\u6700\u5927\u5206\u6570", "title_en": "Maximum Score from Performing Multiplication Operations", "question_title_slug": "maximum-score-from-performing-multiplication-operations", "content_en": "

You are given two integer arrays nums and multipliers of size n and m respectively, where n >= m. The arrays are 1-indexed.

\n\n

You begin with a score of 0. You want to perform exactly m operations. On the ith operation (1-indexed), you will:

\n\n
    \n\t
  • Choose one integer x from either the start or the end of the array nums.
  • \n\t
  • Add multipliers[i] * x to your score.
  • \n\t
  • Remove x from the array nums.
  • \n
\n\n

Return the maximum score after performing m operations.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [1,2,3], multipliers = [3,2,1]\nOutput: 14\nExplanation: An optimal solution is as follows:\n- Choose from the end, [1,2,3], adding 3 * 3 = 9 to the score.\n- Choose from the end, [1,2], adding 2 * 2 = 4 to the score.\n- Choose from the end, [1], adding 1 * 1 = 1 to the score.\nThe total score is 9 + 4 + 1 = 14.
\n\n

Example 2:

\n\n
\nInput: nums = [-5,-3,-3,-2,7,1], multipliers = [-10,-5,3,4,6]\nOutput: 102\nExplanation: An optimal solution is as follows:\n- Choose from the start, [-5,-3,-3,-2,7,1], adding -5 * -10 = 50 to the score.\n- Choose from the start, [-3,-3,-2,7,1], adding -3 * -5 = 15 to the score.\n- Choose from the start, [-3,-2,7,1], adding -3 * 3 = -9 to the score.\n- Choose from the end, [-2,7,1], adding 1 * 4 = 4 to the score.\n- Choose from the end, [-2,7], adding 7 * 6 = 42 to the score. \nThe total score is 50 + 15 - 9 + 4 + 42 = 102.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == nums.length
  • \n\t
  • m == multipliers.length
  • \n\t
  • 1 <= m <= 103
  • \n\t
  • m <= n <= 105
  • \n\t
  • -1000 <= nums[i], multipliers[i] <= 1000
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e24\u4e2a\u957f\u5ea6\u5206\u522b n \u548c m \u7684\u6574\u6570\u6570\u7ec4 nums \u548c multipliers \uff0c\u5176\u4e2d n >= m \uff0c\u6570\u7ec4\u4e0b\u6807 \u4ece 1 \u5f00\u59cb \u8ba1\u6570\u3002

\n\n

\u521d\u59cb\u65f6\uff0c\u4f60\u7684\u5206\u6570\u4e3a 0 \u3002\u4f60\u9700\u8981\u6267\u884c\u6070\u597d m \u6b65\u64cd\u4f5c\u3002\u5728\u7b2c i \u6b65\u64cd\u4f5c\uff08\u4ece 1 \u5f00\u59cb \u8ba1\u6570\uff09\u4e2d\uff0c\u9700\u8981\uff1a

\n\n
    \n\t
  • \u9009\u62e9\u6570\u7ec4 nums \u5f00\u5934\u5904\u6216\u8005\u672b\u5c3e\u5904 \u7684\u6574\u6570 x \u3002
  • \n\t
  • \u4f60\u83b7\u5f97 multipliers[i] * x \u5206\uff0c\u5e76\u7d2f\u52a0\u5230\u4f60\u7684\u5206\u6570\u4e2d\u3002
  • \n\t
  • \u5c06 x \u4ece\u6570\u7ec4 nums \u4e2d\u79fb\u9664\u3002
  • \n
\n\n

\u5728\u6267\u884c m \u6b65\u64cd\u4f5c\u540e\uff0c\u8fd4\u56de \u6700\u5927 \u5206\u6570\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,2,3], multipliers = [3,2,1]\n\u8f93\u51fa\uff1a14\n\u89e3\u91ca\uff1a\u4e00\u79cd\u6700\u4f18\u89e3\u51b3\u65b9\u6848\u5982\u4e0b\uff1a\n- \u9009\u62e9\u672b\u5c3e\u5904\u7684\u6574\u6570 3 \uff0c[1,2,3] \uff0c\u5f97 3 * 3 = 9 \u5206\uff0c\u7d2f\u52a0\u5230\u5206\u6570\u4e2d\u3002\n- \u9009\u62e9\u672b\u5c3e\u5904\u7684\u6574\u6570 2 \uff0c[1,2] \uff0c\u5f97 2 * 2 = 4 \u5206\uff0c\u7d2f\u52a0\u5230\u5206\u6570\u4e2d\u3002\n- \u9009\u62e9\u672b\u5c3e\u5904\u7684\u6574\u6570 1 \uff0c[1] \uff0c\u5f97 1 * 1 = 1 \u5206\uff0c\u7d2f\u52a0\u5230\u5206\u6570\u4e2d\u3002\n\u603b\u5206\u6570\u4e3a 9 + 4 + 1 = 14 \u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anums = [-5,-3,-3,-2,7,1], multipliers = [-10,-5,3,4,6]\n\u8f93\u51fa\uff1a102\n\u89e3\u91ca\uff1a\u4e00\u79cd\u6700\u4f18\u89e3\u51b3\u65b9\u6848\u5982\u4e0b\uff1a\n- \u9009\u62e9\u5f00\u5934\u5904\u7684\u6574\u6570 -5 \uff0c[-5,-3,-3,-2,7,1] \uff0c\u5f97 -5 * -10 = 50 \u5206\uff0c\u7d2f\u52a0\u5230\u5206\u6570\u4e2d\u3002\n- \u9009\u62e9\u5f00\u5934\u5904\u7684\u6574\u6570 -3 \uff0c[-3,-3,-2,7,1] \uff0c\u5f97 -3 * -5 = 15 \u5206\uff0c\u7d2f\u52a0\u5230\u5206\u6570\u4e2d\u3002\n- \u9009\u62e9\u5f00\u5934\u5904\u7684\u6574\u6570 -3 \uff0c[-3,-2,7,1] \uff0c\u5f97 -3 * 3 = -9 \u5206\uff0c\u7d2f\u52a0\u5230\u5206\u6570\u4e2d\u3002\n- \u9009\u62e9\u672b\u5c3e\u5904\u7684\u6574\u6570 1 \uff0c[-2,7,1] \uff0c\u5f97 1 * 4 = 4 \u5206\uff0c\u7d2f\u52a0\u5230\u5206\u6570\u4e2d\u3002\n- \u9009\u62e9\u672b\u5c3e\u5904\u7684\u6574\u6570 7 \uff0c[-2,7] \uff0c\u5f97 7 * 6 = 42 \u5206\uff0c\u7d2f\u52a0\u5230\u5206\u6570\u4e2d\u3002\n\u603b\u5206\u6570\u4e3a 50 + 15 - 9 + 4 + 42 = 102 \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • n == nums.length
  • \n\t
  • m == multipliers.length
  • \n\t
  • 1 <= m <= 103
  • \n\t
  • m <= n <= 105
  • \n\t
  • -1000 <= nums[i], multipliers[i] <= 1000
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maximumScore(vector& nums, vector& multipliers) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maximumScore(int[] nums, int[] multipliers) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximumScore(self, nums, multipliers):\n \"\"\"\n :type nums: List[int]\n :type multipliers: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximumScore(self, nums: List[int], multipliers: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maximumScore(int* nums, int numsSize, int* multipliers, int multipliersSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaximumScore(int[] nums, int[] multipliers) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number[]} multipliers\n * @return {number}\n */\nvar maximumScore = function(nums, multipliers) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer[]} multipliers\n# @return {Integer}\ndef maximum_score(nums, multipliers)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximumScore(_ nums: [Int], _ multipliers: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximumScore(nums []int, multipliers []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximumScore(nums: Array[Int], multipliers: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximumScore(nums: IntArray, multipliers: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximum_score(nums: Vec, multipliers: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer[] $multipliers\n * @return Integer\n */\n function maximumScore($nums, $multipliers) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximumScore(nums: number[], multipliers: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximum-score nums multipliers)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1770](https://leetcode-cn.com/problems/maximum-score-from-performing-multiplication-operations)", "[\u6267\u884c\u4e58\u6cd5\u8fd0\u7b97\u7684\u6700\u5927\u5206\u6570](/solution/1700-1799/1770.Maximum%20Score%20from%20Performing%20Multiplication%20Operations/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1770](https://leetcode.com/problems/maximum-score-from-performing-multiplication-operations)", "[Maximum Score from Performing Multiplication Operations](/solution/1700-1799/1770.Maximum%20Score%20from%20Performing%20Multiplication%20Operations/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "1895", "frontend_question_id": "1769", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-number-of-operations-to-move-all-balls-to-each-box", "url_en": "https://leetcode.com/problems/minimum-number-of-operations-to-move-all-balls-to-each-box", "relative_path_cn": "/solution/1700-1799/1769.Minimum%20Number%20of%20Operations%20to%20Move%20All%20Balls%20to%20Each%20Box/README.md", "relative_path_en": "/solution/1700-1799/1769.Minimum%20Number%20of%20Operations%20to%20Move%20All%20Balls%20to%20Each%20Box/README_EN.md", "title_cn": "\u79fb\u52a8\u6240\u6709\u7403\u5230\u6bcf\u4e2a\u76d2\u5b50\u6240\u9700\u7684\u6700\u5c0f\u64cd\u4f5c\u6570", "title_en": "Minimum Number of Operations to Move All Balls to Each Box", "question_title_slug": "minimum-number-of-operations-to-move-all-balls-to-each-box", "content_en": "

You have n boxes. You are given a binary string boxes of length n, where boxes[i] is '0' if the ith box is empty, and '1' if it contains one ball.

\n\n

In one operation, you can move one ball from a box to an adjacent box. Box i is adjacent to box j if abs(i - j) == 1. Note that after doing so, there may be more than one ball in some boxes.

\n\n

Return an array answer of size n, where answer[i] is the minimum number of operations needed to move all the balls to the ith box.

\n\n

Each answer[i] is calculated considering the initial state of the boxes.

\n\n

 

\n

Example 1:

\n\n
\nInput: boxes = "110"\nOutput: [1,1,3]\nExplanation: The answer for each box is as follows:\n1) First box: you will have to move one ball from the second box to the first box in one operation.\n2) Second box: you will have to move one ball from the first box to the second box in one operation.\n3) Third box: you will have to move one ball from the first box to the third box in two operations, and move one ball from the second box to the third box in one operation.\n
\n\n

Example 2:

\n\n
\nInput: boxes = "001011"\nOutput: [11,8,5,4,3,4]
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == boxes.length
  • \n\t
  • 1 <= n <= 2000
  • \n\t
  • boxes[i] is either '0' or '1'.
  • \n
\n", "content_cn": "

\u6709 n \u4e2a\u76d2\u5b50\u3002\u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32 boxes \uff0c\u5176\u4e2d boxes[i] \u7684\u503c\u4e3a '0' \u8868\u793a\u7b2c i \u4e2a\u76d2\u5b50\u662f \u7a7a \u7684\uff0c\u800c boxes[i] \u7684\u503c\u4e3a '1' \u8868\u793a\u76d2\u5b50\u91cc\u6709 \u4e00\u4e2a \u5c0f\u7403\u3002

\n\n

\u5728\u4e00\u6b65\u64cd\u4f5c\u4e2d\uff0c\u4f60\u53ef\u4ee5\u5c06 \u4e00\u4e2a \u5c0f\u7403\u4ece\u67d0\u4e2a\u76d2\u5b50\u79fb\u52a8\u5230\u4e00\u4e2a\u4e0e\u4e4b\u76f8\u90bb\u7684\u76d2\u5b50\u4e2d\u3002\u7b2c i \u4e2a\u76d2\u5b50\u548c\u7b2c j \u4e2a\u76d2\u5b50\u76f8\u90bb\u9700\u6ee1\u8db3 abs(i - j) == 1 \u3002\u6ce8\u610f\uff0c\u64cd\u4f5c\u6267\u884c\u540e\uff0c\u67d0\u4e9b\u76d2\u5b50\u4e2d\u53ef\u80fd\u4f1a\u5b58\u5728\u4e0d\u6b62\u4e00\u4e2a\u5c0f\u7403\u3002

\n\n

\u8fd4\u56de\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u6570\u7ec4 answer \uff0c\u5176\u4e2d answer[i] \u662f\u5c06\u6240\u6709\u5c0f\u7403\u79fb\u52a8\u5230\u7b2c i \u4e2a\u76d2\u5b50\u6240\u9700\u7684 \u6700\u5c0f \u64cd\u4f5c\u6570\u3002

\n\n

\u6bcf\u4e2a answer[i] \u90fd\u9700\u8981\u6839\u636e\u76d2\u5b50\u7684 \u521d\u59cb\u72b6\u6001 \u8fdb\u884c\u8ba1\u7b97\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aboxes = \"110\"\n\u8f93\u51fa\uff1a[1,1,3]\n\u89e3\u91ca\uff1a\u6bcf\u4e2a\u76d2\u5b50\u5bf9\u5e94\u7684\u6700\u5c0f\u64cd\u4f5c\u6570\u5982\u4e0b\uff1a\n1) \u7b2c 1 \u4e2a\u76d2\u5b50\uff1a\u5c06\u4e00\u4e2a\u5c0f\u7403\u4ece\u7b2c 2 \u4e2a\u76d2\u5b50\u79fb\u52a8\u5230\u7b2c 1 \u4e2a\u76d2\u5b50\uff0c\u9700\u8981 1 \u6b65\u64cd\u4f5c\u3002\n2) \u7b2c 2 \u4e2a\u76d2\u5b50\uff1a\u5c06\u4e00\u4e2a\u5c0f\u7403\u4ece\u7b2c 1 \u4e2a\u76d2\u5b50\u79fb\u52a8\u5230\u7b2c 2 \u4e2a\u76d2\u5b50\uff0c\u9700\u8981 1 \u6b65\u64cd\u4f5c\u3002\n3) \u7b2c 3 \u4e2a\u76d2\u5b50\uff1a\u5c06\u4e00\u4e2a\u5c0f\u7403\u4ece\u7b2c 1 \u4e2a\u76d2\u5b50\u79fb\u52a8\u5230\u7b2c 3 \u4e2a\u76d2\u5b50\uff0c\u9700\u8981 2 \u6b65\u64cd\u4f5c\u3002\u5c06\u4e00\u4e2a\u5c0f\u7403\u4ece\u7b2c 2 \u4e2a\u76d2\u5b50\u79fb\u52a8\u5230\u7b2c 3 \u4e2a\u76d2\u5b50\uff0c\u9700\u8981 1 \u6b65\u64cd\u4f5c\u3002\u5171\u8ba1 3 \u6b65\u64cd\u4f5c\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aboxes = \"001011\"\n\u8f93\u51fa\uff1a[11,8,5,4,3,4]
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • n == boxes.length
  • \n\t
  • 1 <= n <= 2000
  • \n\t
  • boxes[i] \u4e3a '0' \u6216 '1'
  • \n
\n", "tags_en": ["Greedy", "Array"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector minOperations(string boxes) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] minOperations(String boxes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minOperations(self, boxes):\n \"\"\"\n :type boxes: str\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minOperations(self, boxes: str) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* minOperations(char * boxes, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] MinOperations(string boxes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} boxes\n * @return {number[]}\n */\nvar minOperations = function(boxes) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} boxes\n# @return {Integer[]}\ndef min_operations(boxes)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minOperations(_ boxes: String) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minOperations(boxes string) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minOperations(boxes: String): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minOperations(boxes: String): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_operations(boxes: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $boxes\n * @return Integer[]\n */\n function minOperations($boxes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minOperations(boxes: string): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-operations boxes)\n (-> string? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1769](https://leetcode-cn.com/problems/minimum-number-of-operations-to-move-all-balls-to-each-box)", "[\u79fb\u52a8\u6240\u6709\u7403\u5230\u6bcf\u4e2a\u76d2\u5b50\u6240\u9700\u7684\u6700\u5c0f\u64cd\u4f5c\u6570](/solution/1700-1799/1769.Minimum%20Number%20of%20Operations%20to%20Move%20All%20Balls%20to%20Each%20Box/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1769](https://leetcode.com/problems/minimum-number-of-operations-to-move-all-balls-to-each-box)", "[Minimum Number of Operations to Move All Balls to Each Box](/solution/1700-1799/1769.Minimum%20Number%20of%20Operations%20to%20Move%20All%20Balls%20to%20Each%20Box/README_EN.md)", "`Greedy`,`Array`", "Medium", ""]}, {"question_id": "1894", "frontend_question_id": "1768", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/merge-strings-alternately", "url_en": "https://leetcode.com/problems/merge-strings-alternately", "relative_path_cn": "/solution/1700-1799/1768.Merge%20Strings%20Alternately/README.md", "relative_path_en": "/solution/1700-1799/1768.Merge%20Strings%20Alternately/README_EN.md", "title_cn": "\u4ea4\u66ff\u5408\u5e76\u5b57\u7b26\u4e32", "title_en": "Merge Strings Alternately", "question_title_slug": "merge-strings-alternately", "content_en": "

You are given two strings word1 and word2. Merge the strings by adding letters in alternating order, starting with word1. If a string is longer than the other, append the additional letters onto the end of the merged string.

\r\n\r\n

Return the merged string.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: word1 = "abc", word2 = "pqr"\r\nOutput: "apbqcr"\r\nExplanation: The merged string will be merged as so:\r\nword1:  a   b   c\r\nword2:    p   q   r\r\nmerged: a p b q c r\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: word1 = "ab", word2 = "pqrs"\r\nOutput: "apbqrs"\r\nExplanation: Notice that as word2 is longer, "rs" is appended to the end.\r\nword1:  a   b \r\nword2:    p   q   r   s\r\nmerged: a p b q   r   s\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: word1 = "abcd", word2 = "pq"\r\nOutput: "apbqcd"\r\nExplanation: Notice that as word1 is longer, "cd" is appended to the end.\r\nword1:  a   b   c   d\r\nword2:    p   q \r\nmerged: a p b q c   d\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= word1.length, word2.length <= 100
  • \r\n\t
  • word1 and word2 consist of lowercase English letters.
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e24\u4e2a\u5b57\u7b26\u4e32 word1 \u548c word2 \u3002\u8bf7\u4f60\u4ece word1 \u5f00\u59cb\uff0c\u901a\u8fc7\u4ea4\u66ff\u6dfb\u52a0\u5b57\u6bcd\u6765\u5408\u5e76\u5b57\u7b26\u4e32\u3002\u5982\u679c\u4e00\u4e2a\u5b57\u7b26\u4e32\u6bd4\u53e6\u4e00\u4e2a\u5b57\u7b26\u4e32\u957f\uff0c\u5c31\u5c06\u591a\u51fa\u6765\u7684\u5b57\u6bcd\u8ffd\u52a0\u5230\u5408\u5e76\u540e\u5b57\u7b26\u4e32\u7684\u672b\u5c3e\u3002

\n\n

\u8fd4\u56de \u5408\u5e76\u540e\u7684\u5b57\u7b26\u4e32 \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aword1 = \"abc\", word2 = \"pqr\"\n\u8f93\u51fa\uff1a\"apbqcr\"\n\u89e3\u91ca\uff1a\u5b57\u7b26\u4e32\u5408\u5e76\u60c5\u51b5\u5982\u4e0b\u6240\u793a\uff1a\nword1\uff1a  a   b   c\nword2\uff1a    p   q   r\n\u5408\u5e76\u540e\uff1a  a p b q c r\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aword1 = \"ab\", word2 = \"pqrs\"\n\u8f93\u51fa\uff1a\"apbqrs\"\n\u89e3\u91ca\uff1a\u6ce8\u610f\uff0cword2 \u6bd4 word1 \u957f\uff0c\"rs\" \u9700\u8981\u8ffd\u52a0\u5230\u5408\u5e76\u540e\u5b57\u7b26\u4e32\u7684\u672b\u5c3e\u3002\nword1\uff1a  a   b \nword2\uff1a    p   q   r   s\n\u5408\u5e76\u540e\uff1a  a p b q   r   s\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1aword1 = \"abcd\", word2 = \"pq\"\n\u8f93\u51fa\uff1a\"apbqcd\"\n\u89e3\u91ca\uff1a\u6ce8\u610f\uff0cword1 \u6bd4 word2 \u957f\uff0c\"cd\" \u9700\u8981\u8ffd\u52a0\u5230\u5408\u5e76\u540e\u5b57\u7b26\u4e32\u7684\u672b\u5c3e\u3002\nword1\uff1a  a   b   c   d\nword2\uff1a    p   q \n\u5408\u5e76\u540e\uff1a  a p b q c   d\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= word1.length, word2.length <= 100
  • \n\t
  • word1 \u548c word2 \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string mergeAlternately(string word1, string word2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String mergeAlternately(String word1, String word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def mergeAlternately(self, word1, word2):\n \"\"\"\n :type word1: str\n :type word2: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def mergeAlternately(self, word1: str, word2: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * mergeAlternately(char * word1, char * word2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string MergeAlternately(string word1, string word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} word1\n * @param {string} word2\n * @return {string}\n */\nvar mergeAlternately = function(word1, word2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} word1\n# @param {String} word2\n# @return {String}\ndef merge_alternately(word1, word2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func mergeAlternately(_ word1: String, _ word2: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func mergeAlternately(word1 string, word2 string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def mergeAlternately(word1: String, word2: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun mergeAlternately(word1: String, word2: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn merge_alternately(word1: String, word2: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $word1\n * @param String $word2\n * @return String\n */\n function mergeAlternately($word1, $word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function mergeAlternately(word1: string, word2: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (merge-alternately word1 word2)\n (-> string? string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1768](https://leetcode-cn.com/problems/merge-strings-alternately)", "[\u4ea4\u66ff\u5408\u5e76\u5b57\u7b26\u4e32](/solution/1700-1799/1768.Merge%20Strings%20Alternately/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1768](https://leetcode.com/problems/merge-strings-alternately)", "[Merge Strings Alternately](/solution/1700-1799/1768.Merge%20Strings%20Alternately/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1893", "frontend_question_id": "1746", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/maximum-subarray-sum-after-one-operation", "url_en": "https://leetcode.com/problems/maximum-subarray-sum-after-one-operation", "relative_path_cn": "/solution/1700-1799/1746.Maximum%20Subarray%20Sum%20After%20One%20Operation/README.md", "relative_path_en": "/solution/1700-1799/1746.Maximum%20Subarray%20Sum%20After%20One%20Operation/README_EN.md", "title_cn": "\u7ecf\u8fc7\u4e00\u6b21\u64cd\u4f5c\u540e\u7684\u6700\u5927\u5b50\u6570\u7ec4\u548c", "title_en": "Maximum Subarray Sum After One Operation", "question_title_slug": "maximum-subarray-sum-after-one-operation", "content_en": "

You are given an integer array nums. You must perform exactly one operation where you can replace one element nums[i] with nums[i] * nums[i]

\r\n\r\n

Return the maximum possible subarray sum after exactly one operation. The subarray must be non-empty.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: nums = [2,-1,-4,-3]\r\nOutput: 17\r\nExplanation: You can perform the operation on index 2 (0-indexed) to make nums = [2,-1,16,-3]. Now, the maximum subarray sum is 2 + -1 + 16 = 17.
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: nums = [1,-1,1,1,-1,-1,1]\r\nOutput: 4\r\nExplanation: You can perform the operation on index 1 (0-indexed) to make nums = [1,1,1,1,-1,-1,1]. Now, the maximum subarray sum is 1 + 1 + 1 + 1 = 4.
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= nums.length <= 105
  • \r\n\t
  • -104 <= nums[i] <= 104
  • \r\n
", "content_cn": "

\u4f60\u6709\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0nums\u3002\u4f60\u53ea\u80fd\u5c06\u4e00\u4e2a\u5143\u7d20\u00a0nums[i] \u66ff\u6362\u4e3a\u00a0nums[i] * nums[i]\u3002

\n\n

\u8fd4\u56de\u66ff\u6362\u540e\u7684\u6700\u5927\u5b50\u6570\u7ec4\u548c\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [2,-1,-4,-3]\n\u8f93\u51fa\uff1a17\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u628a-4\u66ff\u6362\u4e3a16(-4*(-4))\uff0c\u4f7fnums = [2,-1,16,-3]. \u73b0\u5728\uff0c\u6700\u5927\u5b50\u6570\u7ec4\u548c\u4e3a 2 + -1 + 16 = 17.
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [1,-1,1,1,-1,-1,1]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u628a\u7b2c\u4e00\u4e2a-1\u66ff\u6362\u4e3a1\uff0c\u4f7f nums = [1,1,1,1,-1,-1,1]. \u73b0\u5728\uff0c\u6700\u5927\u5b50\u6570\u7ec4\u548c\u4e3a 1 + 1 + 1 + 1 = 4.
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 105
  • \n\t
  • -104\u00a0<= nums[i] <= 104
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxSumAfterOperation(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxSumAfterOperation(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxSumAfterOperation(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxSumAfterOperation(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxSumAfterOperation(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxSumAfterOperation(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar maxSumAfterOperation = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef max_sum_after_operation(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxSumAfterOperation(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxSumAfterOperation(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxSumAfterOperation(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxSumAfterOperation(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_sum_after_operation(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function maxSumAfterOperation($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxSumAfterOperation(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-sum-after-operation nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1746](https://leetcode-cn.com/problems/maximum-subarray-sum-after-one-operation)", "[\u7ecf\u8fc7\u4e00\u6b21\u64cd\u4f5c\u540e\u7684\u6700\u5927\u5b50\u6570\u7ec4\u548c](/solution/1700-1799/1746.Maximum%20Subarray%20Sum%20After%20One%20Operation/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1746](https://leetcode.com/problems/maximum-subarray-sum-after-one-operation)", "[Maximum Subarray Sum After One Operation](/solution/1700-1799/1746.Maximum%20Subarray%20Sum%20After%20One%20Operation/README_EN.md)", "`Dynamic Programming`", "Medium", "\ud83d\udd12"]}, {"question_id": "1892", "frontend_question_id": "1741", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/find-total-time-spent-by-each-employee", "url_en": "https://leetcode.com/problems/find-total-time-spent-by-each-employee", "relative_path_cn": "/solution/1700-1799/1741.Find%20Total%20Time%20Spent%20by%20Each%20Employee/README.md", "relative_path_en": "/solution/1700-1799/1741.Find%20Total%20Time%20Spent%20by%20Each%20Employee/README_EN.md", "title_cn": "\u67e5\u627e\u6bcf\u4e2a\u5458\u5de5\u82b1\u8d39\u7684\u603b\u65f6\u95f4", "title_en": "Find Total Time Spent by Each Employee", "question_title_slug": "find-total-time-spent-by-each-employee", "content_en": "

Table: Employees

\n\n
\n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| emp_id      | int  |\n| event_day   | date |\n| in_time     | int  |\n| out_time    | int  |\n+-------------+------+\n(emp_id, event_day, in_time) is the primary key of this table.\nThe table shows the employees' entries and exits in an office.\nevent_day is the day at which this event happened, in_time is the minute at which the employee entered the office, and out_time is the minute at which they left the office.\nin_time and out_time are between 1 and 1440.\nIt is guaranteed that no two events on the same day intersect in time, and in_time < out_time.\n
\n\n

 

\n\n

Write an SQL query to calculate the total time in minutes spent by each employee on each day at the office. Note that within one day, an employee can enter and leave more than once. The time spent in the office for a single entry is out_time - in_time.

\n\n

Return the result table in any order.

\n\n

The query result format is in the following example:

\n\n
\nEmployees table:\n+--------+------------+---------+----------+\n| emp_id | event_day  | in_time | out_time |\n+--------+------------+---------+----------+\n| 1      | 2020-11-28 | 4       | 32       |\n| 1      | 2020-11-28 | 55      | 200      |\n| 1      | 2020-12-03 | 1       | 42       |\n| 2      | 2020-11-28 | 3       | 33       |\n| 2      | 2020-12-09 | 47      | 74       |\n+--------+------------+---------+----------+\nResult table:\n+------------+--------+------------+\n| day        | emp_id | total_time |\n+------------+--------+------------+\n| 2020-11-28 | 1      | 173        |\n| 2020-11-28 | 2      | 30         |\n| 2020-12-03 | 1      | 41         |\n| 2020-12-09 | 2      | 27         |\n+------------+--------+------------+\nEmployee 1 has three events: two on day 2020-11-28 with a total of (32 - 4) + (200 - 55) = 173, and one on day 2020-12-03 with a total of (42 - 1) = 41.\nEmployee 2 has two events: one on day 2020-11-28 with a total of (33 - 3) = 30, and one on day 2020-12-09 with a total of (74 - 47) = 27.\n
\n", "content_cn": "

\u8868: Employees

\n\n
+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| emp_id      | int  |\n| event_day   | date |\n| in_time     | int  |\n| out_time    | int  |\n+-------------+------+\n(emp_id, event_day, in_time) \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\u3002\n\u8be5\u8868\u663e\u793a\u4e86\u5458\u5de5\u5728\u529e\u516c\u5ba4\u7684\u51fa\u5165\u60c5\u51b5\u3002\nevent_day \u662f\u6b64\u4e8b\u4ef6\u53d1\u751f\u7684\u65e5\u671f\uff0cin_time \u662f\u5458\u5de5\u8fdb\u5165\u529e\u516c\u5ba4\u7684\u65f6\u95f4\uff0c\u800c out_time \u662f\u4ed6\u4eec\u79bb\u5f00\u529e\u516c\u5ba4\u7684\u65f6\u95f4\u3002\nin_time \u548c out_time \u7684\u53d6\u503c\u57281\u52301440\u4e4b\u95f4\u3002\n\u9898\u76ee\u4fdd\u8bc1\u540c\u4e00\u5929\u6ca1\u6709\u4e24\u4e2a\u4e8b\u4ef6\u5728\u65f6\u95f4\u4e0a\u662f\u76f8\u4ea4\u7684\uff0c\u5e76\u4e14\u4fdd\u8bc1 in_time \u5c0f\u4e8e out_time\u3002\n
\n\n

\u00a0

\n\n

\u7f16\u5199\u4e00\u4e2aSQL\u67e5\u8be2\u4ee5\u8ba1\u7b97\u6bcf\u4f4d\u5458\u5de5\u6bcf\u5929\u5728\u529e\u516c\u5ba4\u82b1\u8d39\u7684\u603b\u65f6\u95f4\uff08\u4ee5\u5206\u949f\u4e3a\u5355\u4f4d\uff09\u3002 \u8bf7\u6ce8\u610f\uff0c\u5728\u4e00\u5929\u4e4b\u5185\uff0c\u540c\u4e00\u5458\u5de5\u662f\u53ef\u4ee5\u591a\u6b21\u8fdb\u5165\u548c\u79bb\u5f00\u529e\u516c\u5ba4\u7684\u3002 \u5728\u529e\u516c\u5ba4\u91cc\u4e00\u6b21\u8fdb\u51fa\u6240\u82b1\u8d39\u7684\u65f6\u95f4\u4e3aout_time \u51cf\u53bb in_time\u3002

\n\n

\u8fd4\u56de\u7ed3\u679c\u8868\u5355\u7684\u987a\u5e8f\u65e0\u8981\u6c42\u3002
\n\u67e5\u8be2\u7ed3\u679c\u7684\u683c\u5f0f\u5982\u4e0b\uff1a

\n\n
Employees table:\n+--------+------------+---------+----------+\n| emp_id | event_day  | in_time | out_time |\n+--------+------------+---------+----------+\n| 1      | 2020-11-28 | 4       | 32       |\n| 1      | 2020-11-28 | 55      | 200      |\n| 1      | 2020-12-03 | 1       | 42       |\n| 2      | 2020-11-28 | 3       | 33       |\n| 2      | 2020-12-09 | 47      | 74       |\n+--------+------------+---------+----------+\nResult table:\n+------------+--------+------------+\n| day        | emp_id | total_time |\n+------------+--------+------------+\n| 2020-11-28 | 1      | 173        |\n| 2020-11-28 | 2      | 30         |\n| 2020-12-03 | 1      | 41         |\n| 2020-12-09 | 2      | 27         |\n+------------+--------+------------+\n\u96c7\u5458 1 \u6709\u4e09\u6b21\u8fdb\u51fa: \u6709\u4e24\u6b21\u53d1\u751f\u5728 2020-11-28 \u82b1\u8d39\u7684\u65f6\u95f4\u4e3a (32 - 4) + (200 - 55) = 173, \u6709\u4e00\u6b21\u53d1\u751f\u5728 2020-12-03 \u82b1\u8d39\u7684\u65f6\u95f4\u4e3a (42 - 1) = 41\u3002\n\u96c7\u5458 2 \u6709\u4e24\u6b21\u8fdb\u51fa: \u6709\u4e00\u6b21\u53d1\u751f\u5728 2020-11-28 \u82b1\u8d39\u7684\u65f6\u95f4\u4e3a (33 - 3) = 30,  \u6709\u4e00\u6b21\u53d1\u751f\u5728 2020-12-09 \u82b1\u8d39\u7684\u65f6\u95f4\u4e3a (74 - 47) = 27\u3002\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1741](https://leetcode-cn.com/problems/find-total-time-spent-by-each-employee)", "[\u67e5\u627e\u6bcf\u4e2a\u5458\u5de5\u82b1\u8d39\u7684\u603b\u65f6\u95f4](/solution/1700-1799/1741.Find%20Total%20Time%20Spent%20by%20Each%20Employee/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1741](https://leetcode.com/problems/find-total-time-spent-by-each-employee)", "[Find Total Time Spent by Each Employee](/solution/1700-1799/1741.Find%20Total%20Time%20Spent%20by%20Each%20Employee/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1891", "frontend_question_id": "1782", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-pairs-of-nodes", "url_en": "https://leetcode.com/problems/count-pairs-of-nodes", "relative_path_cn": "/solution/1700-1799/1782.Count%20Pairs%20Of%20Nodes/README.md", "relative_path_en": "/solution/1700-1799/1782.Count%20Pairs%20Of%20Nodes/README_EN.md", "title_cn": "\u7edf\u8ba1\u70b9\u5bf9\u7684\u6570\u76ee", "title_en": "Count Pairs Of Nodes", "question_title_slug": "count-pairs-of-nodes", "content_en": "

You are given an undirected graph represented by an integer n, which is the number of nodes, and edges, where edges[i] = [ui, vi] which indicates that there is an undirected edge between ui and vi. You are also given an integer array queries.

\n\n

The answer to the jth query is the number of pairs of nodes (a, b) that satisfy the following conditions:

\n\n
    \n\t
  • a < b
  • \n\t
  • cnt is strictly greater than queries[j], where cnt is the number of edges incident to a or b.
  • \n
\n\n

Return an array answers such that answers.length == queries.length and answers[j] is the answer of the jth query.

\n\n

Note that there can be repeated edges.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: n = 4, edges = [[1,2],[2,4],[1,3],[2,3],[2,1]], queries = [2,3]\nOutput: [6,5]\nExplanation: The number of edges incident to at least one of each pair is shown above.\n
\n\n

Example 2:

\n\n
\nInput: n = 5, edges = [[1,5],[1,5],[3,4],[2,5],[1,3],[5,1],[2,3],[2,5]], queries = [1,2,3,4,5]\nOutput: [10,10,9,8,6]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= n <= 2 * 104
  • \n\t
  • 1 <= edges.length <= 105
  • \n\t
  • 1 <= ui, vi <= n
  • \n\t
  • ui != vi
  • \n\t
  • 1 <= queries.length <= 20
  • \n\t
  • 0 <= queries[j] < edges.length
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u65e0\u5411\u56fe\uff0c\u65e0\u5411\u56fe\u7531\u6574\u6570\u00a0n\u00a0\u00a0\uff0c\u8868\u793a\u56fe\u4e2d\u8282\u70b9\u7684\u6570\u76ee\uff0c\u548c\u00a0edges\u00a0\u7ec4\u6210\uff0c\u5176\u4e2d\u00a0edges[i] = [ui, vi]\u00a0\u8868\u793a\u00a0ui \u548c\u00a0vi\u00a0\u4e4b\u95f4\u6709\u4e00\u6761\u65e0\u5411\u8fb9\u3002\u540c\u65f6\u7ed9\u4f60\u4e00\u4e2a\u4ee3\u8868\u67e5\u8be2\u7684\u6574\u6570\u6570\u7ec4\u00a0queries\u00a0\u3002

\n\n

\u7b2c j \u4e2a\u67e5\u8be2\u7684\u7b54\u6848\u662f\u6ee1\u8db3\u5982\u4e0b\u6761\u4ef6\u7684\u70b9\u5bf9 (a, b) \u7684\u6570\u76ee\uff1a

\n\n
    \n\t
  • a < b
  • \n\t
  • cnt\u00a0\u662f\u4e0e a\u00a0\u6216\u8005\u00a0b\u00a0\u76f8\u8fde\u7684\u8fb9\u7684\u6570\u76ee\uff0c\u4e14 cnt\u00a0\u4e25\u683c\u5927\u4e8e\u00a0queries[j]\u00a0\u3002
  • \n
\n\n

\u8bf7\u4f60\u8fd4\u56de\u4e00\u4e2a\u6570\u7ec4\u00a0answers\u00a0\uff0c\u5176\u4e2d\u00a0answers.length == queries.length \u4e14\u00a0answers[j]\u00a0\u662f\u7b2c j\u00a0\u4e2a\u67e5\u8be2\u7684\u7b54\u6848\u3002

\n\n

\u8bf7\u6ce8\u610f\uff0c\u56fe\u4e2d\u53ef\u80fd\u4f1a\u6709 \u91cd\u590d\u8fb9\u00a0\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1an = 4, edges = [[1,2],[2,4],[1,3],[2,3],[2,1]], queries = [2,3]\n\u8f93\u51fa\uff1a[6,5]\n\u89e3\u91ca\uff1a\u6bcf\u4e2a\u70b9\u5bf9\u4e2d\uff0c\u4e0e\u81f3\u5c11\u4e00\u4e2a\u70b9\u76f8\u8fde\u7684\u8fb9\u7684\u6570\u76ee\u5982\u4e0a\u56fe\u6240\u793a\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1an = 5, edges = [[1,5],[1,5],[3,4],[2,5],[1,3],[5,1],[2,3],[2,5]], queries = [1,2,3,4,5]\n\u8f93\u51fa\uff1a[10,10,9,8,6]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= n <= 2 * 104
  • \n\t
  • 1 <= edges.length <= 105
  • \n\t
  • 1 <= ui, vi <= n
  • \n\t
  • ui != vi
  • \n\t
  • 1 <= queries.length <= 20
  • \n\t
  • 0 <= queries[j] < edges.length
  • \n
\n", "tags_en": ["Graph"], "tags_cn": ["\u56fe"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector countPairs(int n, vector>& edges, vector& queries) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] countPairs(int n, int[][] edges, int[] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countPairs(self, n, edges, queries):\n \"\"\"\n :type n: int\n :type edges: List[List[int]]\n :type queries: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countPairs(self, n: int, edges: List[List[int]], queries: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* countPairs(int n, int** edges, int edgesSize, int* edgesColSize, int* queries, int queriesSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] CountPairs(int n, int[][] edges, int[] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} edges\n * @param {number[]} queries\n * @return {number[]}\n */\nvar countPairs = function(n, edges, queries) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} edges\n# @param {Integer[]} queries\n# @return {Integer[]}\ndef count_pairs(n, edges, queries)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countPairs(_ n: Int, _ edges: [[Int]], _ queries: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countPairs(n int, edges [][]int, queries []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countPairs(n: Int, edges: Array[Array[Int]], queries: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countPairs(n: Int, edges: Array, queries: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_pairs(n: i32, edges: Vec>, queries: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $edges\n * @param Integer[] $queries\n * @return Integer[]\n */\n function countPairs($n, $edges, $queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countPairs(n: number, edges: number[][], queries: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-pairs n edges queries)\n (-> exact-integer? (listof (listof exact-integer?)) (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1782](https://leetcode-cn.com/problems/count-pairs-of-nodes)", "[\u7edf\u8ba1\u70b9\u5bf9\u7684\u6570\u76ee](/solution/1700-1799/1782.Count%20Pairs%20Of%20Nodes/README.md)", "`\u56fe`", "\u56f0\u96be", ""], "md_table_row_en": ["[1782](https://leetcode.com/problems/count-pairs-of-nodes)", "[Count Pairs Of Nodes](/solution/1700-1799/1782.Count%20Pairs%20Of%20Nodes/README_EN.md)", "`Graph`", "Hard", ""]}, {"question_id": "1890", "frontend_question_id": "1781", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sum-of-beauty-of-all-substrings", "url_en": "https://leetcode.com/problems/sum-of-beauty-of-all-substrings", "relative_path_cn": "/solution/1700-1799/1781.Sum%20of%20Beauty%20of%20All%20Substrings/README.md", "relative_path_en": "/solution/1700-1799/1781.Sum%20of%20Beauty%20of%20All%20Substrings/README_EN.md", "title_cn": "\u6240\u6709\u5b50\u5b57\u7b26\u4e32\u7f8e\u4e3d\u503c\u4e4b\u548c", "title_en": "Sum of Beauty of All Substrings", "question_title_slug": "sum-of-beauty-of-all-substrings", "content_en": "

The beauty of a string is the difference in frequencies between the most frequent and least frequent characters.

\n\n
    \n\t
  • For example, the beauty of "abaacc" is 3 - 1 = 2.
  • \n
\n\n

Given a string s, return the sum of beauty of all of its substrings.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "aabcb"\nOutput: 5\nExplanation: The substrings with non-zero beauty are ["aab","aabc","aabcb","abcb","bcb"], each with beauty equal to 1.
\n\n

Example 2:

\n\n
\nInput: s = "aabcbaa"\nOutput: 17\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 500
  • \n\t
  • s consists of only lowercase English letters.
  • \n
\n", "content_cn": "

\u4e00\u4e2a\u5b57\u7b26\u4e32\u7684 \u7f8e\u4e3d\u503c\u00a0\u5b9a\u4e49\u4e3a\uff1a\u51fa\u73b0\u9891\u7387\u6700\u9ad8\u5b57\u7b26\u4e0e\u51fa\u73b0\u9891\u7387\u6700\u4f4e\u5b57\u7b26\u7684\u51fa\u73b0\u6b21\u6570\u4e4b\u5dee\u3002

\n\n
    \n\t
  • \u6bd4\u65b9\u8bf4\uff0c\"abaacc\"\u00a0\u7684\u7f8e\u4e3d\u503c\u4e3a\u00a03 - 1 = 2\u00a0\u3002
  • \n
\n\n

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32\u00a0s\u00a0\uff0c\u8bf7\u4f60\u8fd4\u56de\u5b83\u6240\u6709\u5b50\u5b57\u7b26\u4e32\u7684\u00a0\u7f8e\u4e3d\u503c\u00a0\u4e4b\u548c\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"aabcb\"\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u7f8e\u4e3d\u503c\u4e0d\u4e3a\u96f6\u7684\u5b57\u7b26\u4e32\u5305\u62ec [\"aab\",\"aabc\",\"aabcb\",\"abcb\",\"bcb\"] \uff0c\u6bcf\u4e00\u4e2a\u5b57\u7b26\u4e32\u7684\u7f8e\u4e3d\u503c\u90fd\u4e3a 1 \u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"aabcbaa\"\n\u8f93\u51fa\uff1a17\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length <= 500
  • \n\t
  • s\u00a0\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
  • \n
\n", "tags_en": ["Hash Table", "String"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int beautySum(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int beautySum(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def beautySum(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def beautySum(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint beautySum(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int BeautySum(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar beautySum = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef beauty_sum(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func beautySum(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func beautySum(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def beautySum(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun beautySum(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn beauty_sum(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function beautySum($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function beautySum(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (beauty-sum s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1781](https://leetcode-cn.com/problems/sum-of-beauty-of-all-substrings)", "[\u6240\u6709\u5b50\u5b57\u7b26\u4e32\u7f8e\u4e3d\u503c\u4e4b\u548c](/solution/1700-1799/1781.Sum%20of%20Beauty%20of%20All%20Substrings/README.md)", "`\u54c8\u5e0c\u8868`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1781](https://leetcode.com/problems/sum-of-beauty-of-all-substrings)", "[Sum of Beauty of All Substrings](/solution/1700-1799/1781.Sum%20of%20Beauty%20of%20All%20Substrings/README_EN.md)", "`Hash Table`,`String`", "Medium", ""]}, {"question_id": "1889", "frontend_question_id": "1780", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/check-if-number-is-a-sum-of-powers-of-three", "url_en": "https://leetcode.com/problems/check-if-number-is-a-sum-of-powers-of-three", "relative_path_cn": "/solution/1700-1799/1780.Check%20if%20Number%20is%20a%20Sum%20of%20Powers%20of%20Three/README.md", "relative_path_en": "/solution/1700-1799/1780.Check%20if%20Number%20is%20a%20Sum%20of%20Powers%20of%20Three/README_EN.md", "title_cn": "\u5224\u65ad\u4e00\u4e2a\u6570\u5b57\u662f\u5426\u53ef\u4ee5\u8868\u793a\u6210\u4e09\u7684\u5e42\u7684\u548c", "title_en": "Check if Number is a Sum of Powers of Three", "question_title_slug": "check-if-number-is-a-sum-of-powers-of-three", "content_en": "

Given an integer n, return true if it is possible to represent n as the sum of distinct powers of three. Otherwise, return false.

\n\n

An integer y is a power of three if there exists an integer x such that y == 3x.

\n\n

 

\n

Example 1:

\n\n
\nInput: n = 12\nOutput: true\nExplanation: 12 = 31 + 32\n
\n\n

Example 2:

\n\n
\nInput: n = 91\nOutput: true\nExplanation: 91 = 30 + 32 + 34\n
\n\n

Example 3:

\n\n
\nInput: n = 21\nOutput: false\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 107
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u00a0n\u00a0\uff0c\u5982\u679c\u4f60\u53ef\u4ee5\u5c06\u00a0n\u00a0\u8868\u793a\u6210\u82e5\u5e72\u4e2a\u4e0d\u540c\u7684\u4e09\u7684\u5e42\u4e4b\u548c\uff0c\u8bf7\u4f60\u8fd4\u56de\u00a0true\u00a0\uff0c\u5426\u5219\u8bf7\u8fd4\u56de false\u00a0\u3002

\n\n

\u5bf9\u4e8e\u4e00\u4e2a\u6574\u6570 y\u00a0\uff0c\u5982\u679c\u5b58\u5728\u6574\u6570 x\u00a0\u6ee1\u8db3 y == 3x\u00a0\uff0c\u6211\u4eec\u79f0\u8fd9\u4e2a\u6574\u6570 y\u00a0\u662f\u4e09\u7684\u5e42\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1an = 12\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a12 = 31 + 32\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1an = 91\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a91 = 30 + 32 + 34\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1an = 21\n\u8f93\u51fa\uff1afalse\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 107
  • \n
\n", "tags_en": ["Recursion", "Math", "Backtracking"], "tags_cn": ["\u9012\u5f52", "\u6570\u5b66", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool checkPowersOfThree(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean checkPowersOfThree(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def checkPowersOfThree(self, n):\n \"\"\"\n :type n: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def checkPowersOfThree(self, n: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool checkPowersOfThree(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CheckPowersOfThree(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {boolean}\n */\nvar checkPowersOfThree = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Boolean}\ndef check_powers_of_three(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func checkPowersOfThree(_ n: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func checkPowersOfThree(n int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def checkPowersOfThree(n: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun checkPowersOfThree(n: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn check_powers_of_three(n: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Boolean\n */\n function checkPowersOfThree($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function checkPowersOfThree(n: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (check-powers-of-three n)\n (-> exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1780](https://leetcode-cn.com/problems/check-if-number-is-a-sum-of-powers-of-three)", "[\u5224\u65ad\u4e00\u4e2a\u6570\u5b57\u662f\u5426\u53ef\u4ee5\u8868\u793a\u6210\u4e09\u7684\u5e42\u7684\u548c](/solution/1700-1799/1780.Check%20if%20Number%20is%20a%20Sum%20of%20Powers%20of%20Three/README.md)", "`\u9012\u5f52`,`\u6570\u5b66`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1780](https://leetcode.com/problems/check-if-number-is-a-sum-of-powers-of-three)", "[Check if Number is a Sum of Powers of Three](/solution/1700-1799/1780.Check%20if%20Number%20is%20a%20Sum%20of%20Powers%20of%20Three/README_EN.md)", "`Recursion`,`Math`,`Backtracking`", "Medium", ""]}, {"question_id": "1888", "frontend_question_id": "1779", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-nearest-point-that-has-the-same-x-or-y-coordinate", "url_en": "https://leetcode.com/problems/find-nearest-point-that-has-the-same-x-or-y-coordinate", "relative_path_cn": "/solution/1700-1799/1779.Find%20Nearest%20Point%20That%20Has%20the%20Same%20X%20or%20Y%20Coordinate/README.md", "relative_path_en": "/solution/1700-1799/1779.Find%20Nearest%20Point%20That%20Has%20the%20Same%20X%20or%20Y%20Coordinate/README_EN.md", "title_cn": "\u627e\u5230\u6700\u8fd1\u7684\u6709\u76f8\u540c X \u6216 Y \u5750\u6807\u7684\u70b9", "title_en": "Find Nearest Point That Has the Same X or Y Coordinate", "question_title_slug": "find-nearest-point-that-has-the-same-x-or-y-coordinate", "content_en": "

You are given two integers, x and y, which represent your current location on a Cartesian grid: (x, y). You are also given an array points where each points[i] = [ai, bi] represents that a point exists at (ai, bi). A point is valid if it shares the same x-coordinate or the same y-coordinate as your location.

\n\n

Return the index (0-indexed) of the valid point with the smallest Manhattan distance from your current location. If there are multiple, return the valid point with the smallest index. If there are no valid points, return -1.

\n\n

The Manhattan distance between two points (x1, y1) and (x2, y2) is abs(x1 - x2) + abs(y1 - y2).

\n\n

 

\n

Example 1:

\n\n
\nInput: x = 3, y = 4, points = [[1,2],[3,1],[2,4],[2,3],[4,4]]\nOutput: 2\nExplanation: Of all the points, only [3,1], [2,4] and [4,4] are valid. Of the valid points, [2,4] and [4,4] have the smallest Manhattan distance from your current location, with a distance of 1. [2,4] has the smallest index, so return 2.
\n\n

Example 2:

\n\n
\nInput: x = 3, y = 4, points = [[3,4]]\nOutput: 0\nExplanation: The answer is allowed to be on the same location as your current location.
\n\n

Example 3:

\n\n
\nInput: x = 3, y = 4, points = [[2,3]]\nOutput: -1\nExplanation: There are no valid points.
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= points.length <= 104
  • \n\t
  • points[i].length == 2
  • \n\t
  • 1 <= x, y, ai, bi <= 104
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e24\u4e2a\u6574\u6570\u00a0x \u548c\u00a0y\u00a0\uff0c\u8868\u793a\u4f60\u5728\u4e00\u4e2a\u7b1b\u5361\u5c14\u5750\u6807\u7cfb\u4e0b\u7684\u00a0(x, y)\u00a0\u5904\u3002\u540c\u65f6\uff0c\u5728\u540c\u4e00\u4e2a\u5750\u6807\u7cfb\u4e0b\u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4\u00a0points\u00a0\uff0c\u5176\u4e2d\u00a0points[i] = [ai, bi]\u00a0\u8868\u793a\u5728\u00a0(ai, bi)\u00a0\u5904\u6709\u4e00\u4e2a\u70b9\u3002\u5f53\u4e00\u4e2a\u70b9\u4e0e\u4f60\u6240\u5728\u7684\u4f4d\u7f6e\u6709\u76f8\u540c\u7684 x \u5750\u6807\u6216\u8005\u76f8\u540c\u7684 y \u5750\u6807\u65f6\uff0c\u6211\u4eec\u79f0\u8fd9\u4e2a\u70b9\u662f \u6709\u6548\u7684\u00a0\u3002

\n\n

\u8bf7\u8fd4\u56de\u8ddd\u79bb\u4f60\u5f53\u524d\u4f4d\u7f6e\u00a0\u66fc\u54c8\u987f\u8ddd\u79bb\u00a0\u6700\u8fd1\u7684\u00a0\u6709\u6548\u00a0\u70b9\u7684\u4e0b\u6807\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\u3002\u5982\u679c\u6709\u591a\u4e2a\u6700\u8fd1\u7684\u6709\u6548\u70b9\uff0c\u8bf7\u8fd4\u56de\u4e0b\u6807\u00a0\u6700\u5c0f\u00a0\u7684\u4e00\u4e2a\u3002\u5982\u679c\u6ca1\u6709\u6709\u6548\u70b9\uff0c\u8bf7\u8fd4\u56de\u00a0-1\u00a0\u3002

\n\n

\u4e24\u4e2a\u70b9 (x1, y1)\u00a0\u548c (x2, y2)\u00a0\u4e4b\u95f4\u7684 \u66fc\u54c8\u987f\u8ddd\u79bb\u00a0\u4e3a\u00a0abs(x1 - x2) + abs(y1 - y2)\u00a0\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1ax = 3, y = 4, points = [[1,2],[3,1],[2,4],[2,3],[4,4]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6240\u6709\u70b9\u4e2d\uff0c[3,1]\uff0c[2,4] \u548c [4,4] \u662f\u6709\u6548\u70b9\u3002\u6709\u6548\u70b9\u4e2d\uff0c[2,4] \u548c [4,4] \u8ddd\u79bb\u4f60\u5f53\u524d\u4f4d\u7f6e\u7684\u66fc\u54c8\u987f\u8ddd\u79bb\u6700\u5c0f\uff0c\u90fd\u4e3a 1 \u3002[2,4] \u7684\u4e0b\u6807\u6700\u5c0f\uff0c\u6240\u4ee5\u8fd4\u56de 2 \u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1ax = 3, y = 4, points = [[3,4]]\n\u8f93\u51fa\uff1a0\n\u63d0\u793a\uff1a\u7b54\u6848\u53ef\u4ee5\u4e0e\u4f60\u5f53\u524d\u6240\u5728\u4f4d\u7f6e\u5750\u6807\u76f8\u540c\u3002
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1ax = 3, y = 4, points = [[2,3]]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u6ca1\u6709\u6709\u6548\u70b9\u3002
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= points.length <= 104
  • \n\t
  • points[i].length == 2
  • \n\t
  • 1 <= x, y, ai, bi <= 104
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int nearestValidPoint(int x, int y, vector>& points) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int nearestValidPoint(int x, int y, int[][] points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def nearestValidPoint(self, x, y, points):\n \"\"\"\n :type x: int\n :type y: int\n :type points: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def nearestValidPoint(self, x: int, y: int, points: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint nearestValidPoint(int x, int y, int** points, int pointsSize, int* pointsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NearestValidPoint(int x, int y, int[][] points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} x\n * @param {number} y\n * @param {number[][]} points\n * @return {number}\n */\nvar nearestValidPoint = function(x, y, points) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} x\n# @param {Integer} y\n# @param {Integer[][]} points\n# @return {Integer}\ndef nearest_valid_point(x, y, points)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func nearestValidPoint(_ x: Int, _ y: Int, _ points: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func nearestValidPoint(x int, y int, points [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def nearestValidPoint(x: Int, y: Int, points: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun nearestValidPoint(x: Int, y: Int, points: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn nearest_valid_point(x: i32, y: i32, points: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $x\n * @param Integer $y\n * @param Integer[][] $points\n * @return Integer\n */\n function nearestValidPoint($x, $y, $points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function nearestValidPoint(x: number, y: number, points: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (nearest-valid-point x y points)\n (-> exact-integer? exact-integer? (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1779](https://leetcode-cn.com/problems/find-nearest-point-that-has-the-same-x-or-y-coordinate)", "[\u627e\u5230\u6700\u8fd1\u7684\u6709\u76f8\u540c X \u6216 Y \u5750\u6807\u7684\u70b9](/solution/1700-1799/1779.Find%20Nearest%20Point%20That%20Has%20the%20Same%20X%20or%20Y%20Coordinate/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1779](https://leetcode.com/problems/find-nearest-point-that-has-the-same-x-or-y-coordinate)", "[Find Nearest Point That Has the Same X or Y Coordinate](/solution/1700-1799/1779.Find%20Nearest%20Point%20That%20Has%20the%20Same%20X%20or%20Y%20Coordinate/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1887", "frontend_question_id": "1761", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-degree-of-a-connected-trio-in-a-graph", "url_en": "https://leetcode.com/problems/minimum-degree-of-a-connected-trio-in-a-graph", "relative_path_cn": "/solution/1700-1799/1761.Minimum%20Degree%20of%20a%20Connected%20Trio%20in%20a%20Graph/README.md", "relative_path_en": "/solution/1700-1799/1761.Minimum%20Degree%20of%20a%20Connected%20Trio%20in%20a%20Graph/README_EN.md", "title_cn": "\u4e00\u4e2a\u56fe\u4e2d\u8fde\u901a\u4e09\u5143\u7ec4\u7684\u6700\u5c0f\u5ea6\u6570", "title_en": "Minimum Degree of a Connected Trio in a Graph", "question_title_slug": "minimum-degree-of-a-connected-trio-in-a-graph", "content_en": "

You are given an undirected graph. You are given an integer n which is the number of nodes in the graph and an array edges, where each edges[i] = [ui, vi] indicates that there is an undirected edge between ui and vi.

\n\n

A connected trio is a set of three nodes where there is an edge between every pair of them.

\n\n

The degree of a connected trio is the number of edges where one endpoint is in the trio, and the other is not.

\n\n

Return the minimum degree of a connected trio in the graph, or -1 if the graph has no connected trios.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: n = 6, edges = [[1,2],[1,3],[3,2],[4,1],[5,2],[3,6]]\nOutput: 3\nExplanation: There is exactly one trio, which is [1,2,3]. The edges that form its degree are bolded in the figure above.\n
\n\n

Example 2:

\n\"\"\n
\nInput: n = 7, edges = [[1,3],[4,1],[4,3],[2,5],[5,6],[6,7],[7,5],[2,6]]\nOutput: 0\nExplanation: There are exactly three trios:\n1) [1,4,3] with degree 0.\n2) [2,5,6] with degree 2.\n3) [5,6,7] with degree 2.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= n <= 400
  • \n\t
  • edges[i].length == 2
  • \n\t
  • 1 <= edges.length <= n * (n-1) / 2
  • \n\t
  • 1 <= ui, vi <= n
  • \n\t
  • ui != vi
  • \n\t
  • There are no repeated edges.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u65e0\u5411\u56fe\uff0c\u6574\u6570 n\u00a0\u8868\u793a\u56fe\u4e2d\u8282\u70b9\u7684\u6570\u76ee\uff0cedges\u00a0\u6570\u7ec4\u8868\u793a\u56fe\u4e2d\u7684\u8fb9\uff0c\u5176\u4e2d\u00a0edges[i] = [ui, vi]\u00a0\uff0c\u8868\u793a\u00a0ui \u548c\u00a0vi\u00a0\u4e4b\u95f4\u6709\u4e00\u6761\u65e0\u5411\u8fb9\u3002

\n\n

\u4e00\u4e2a \u8fde\u901a\u4e09\u5143\u7ec4\u00a0\u6307\u7684\u662f \u4e09\u4e2a\u00a0\u8282\u70b9\u7ec4\u6210\u7684\u96c6\u5408\u4e14\u8fd9\u4e09\u4e2a\u70b9\u4e4b\u95f4 \u4e24\u4e24\u00a0\u6709\u8fb9\u3002

\n\n

\u8fde\u901a\u4e09\u5143\u7ec4\u7684\u5ea6\u6570\u00a0\u662f\u6240\u6709\u6ee1\u8db3\u6b64\u6761\u4ef6\u7684\u8fb9\u7684\u6570\u76ee\uff1a\u4e00\u4e2a\u9876\u70b9\u5728\u8fd9\u4e2a\u4e09\u5143\u7ec4\u5185\uff0c\u800c\u53e6\u4e00\u4e2a\u9876\u70b9\u4e0d\u5728\u8fd9\u4e2a\u4e09\u5143\u7ec4\u5185\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u6240\u6709\u8fde\u901a\u4e09\u5143\u7ec4\u4e2d\u5ea6\u6570\u7684 \u6700\u5c0f\u503c\u00a0\uff0c\u5982\u679c\u56fe\u4e2d\u6ca1\u6709\u8fde\u901a\u4e09\u5143\u7ec4\uff0c\u90a3\u4e48\u8fd4\u56de -1\u00a0\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1an = 6, edges = [[1,2],[1,3],[3,2],[4,1],[5,2],[3,6]]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u53ea\u6709\u4e00\u4e2a\u4e09\u5143\u7ec4 [1,2,3] \u3002\u6784\u6210\u5ea6\u6570\u7684\u8fb9\u5728\u4e0a\u56fe\u4e2d\u5df2\u88ab\u52a0\u7c97\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1an = 7, edges = [[1,3],[4,1],[4,3],[2,5],[5,6],[6,7],[7,5],[2,6]]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6709 3 \u4e2a\u4e09\u5143\u7ec4\uff1a\n1) [1,4,3]\uff0c\u5ea6\u6570\u4e3a 0 \u3002\n2) [2,5,6]\uff0c\u5ea6\u6570\u4e3a 2 \u3002\n3) [5,6,7]\uff0c\u5ea6\u6570\u4e3a 2 \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= n <= 400
  • \n\t
  • edges[i].length == 2
  • \n\t
  • 1 <= edges.length <= n * (n-1) / 2
  • \n\t
  • 1 <= ui, vi <= n
  • \n\t
  • ui != vi
  • \n\t
  • \u56fe\u4e2d\u6ca1\u6709\u91cd\u590d\u7684\u8fb9\u3002
  • \n
\n", "tags_en": ["Graph"], "tags_cn": ["\u56fe"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minTrioDegree(int n, vector>& edges) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minTrioDegree(int n, int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minTrioDegree(self, n, edges):\n \"\"\"\n :type n: int\n :type edges: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minTrioDegree(self, n: int, edges: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minTrioDegree(int n, int** edges, int edgesSize, int* edgesColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinTrioDegree(int n, int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} edges\n * @return {number}\n */\nvar minTrioDegree = function(n, edges) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} edges\n# @return {Integer}\ndef min_trio_degree(n, edges)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minTrioDegree(_ n: Int, _ edges: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minTrioDegree(n int, edges [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minTrioDegree(n: Int, edges: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minTrioDegree(n: Int, edges: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_trio_degree(n: i32, edges: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $edges\n * @return Integer\n */\n function minTrioDegree($n, $edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minTrioDegree(n: number, edges: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-trio-degree n edges)\n (-> exact-integer? (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1761](https://leetcode-cn.com/problems/minimum-degree-of-a-connected-trio-in-a-graph)", "[\u4e00\u4e2a\u56fe\u4e2d\u8fde\u901a\u4e09\u5143\u7ec4\u7684\u6700\u5c0f\u5ea6\u6570](/solution/1700-1799/1761.Minimum%20Degree%20of%20a%20Connected%20Trio%20in%20a%20Graph/README.md)", "`\u56fe`", "\u56f0\u96be", ""], "md_table_row_en": ["[1761](https://leetcode.com/problems/minimum-degree-of-a-connected-trio-in-a-graph)", "[Minimum Degree of a Connected Trio in a Graph](/solution/1700-1799/1761.Minimum%20Degree%20of%20a%20Connected%20Trio%20in%20a%20Graph/README_EN.md)", "`Graph`", "Hard", ""]}, {"question_id": "1886", "frontend_question_id": "1760", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-limit-of-balls-in-a-bag", "url_en": "https://leetcode.com/problems/minimum-limit-of-balls-in-a-bag", "relative_path_cn": "/solution/1700-1799/1760.Minimum%20Limit%20of%20Balls%20in%20a%20Bag/README.md", "relative_path_en": "/solution/1700-1799/1760.Minimum%20Limit%20of%20Balls%20in%20a%20Bag/README_EN.md", "title_cn": "\u888b\u5b50\u91cc\u6700\u5c11\u6570\u76ee\u7684\u7403", "title_en": "Minimum Limit of Balls in a Bag", "question_title_slug": "minimum-limit-of-balls-in-a-bag", "content_en": "

You are given an integer array nums where the ith bag contains nums[i] balls. You are also given an integer maxOperations.

\n\n

You can perform the following operation at most maxOperations times:

\n\n
    \n\t
  • Take any bag of balls and divide it into two new bags with a positive number of balls.\n\n\t
      \n\t\t
    • For example, a bag of 5 balls can become two new bags of 1 and 4 balls, or two new bags of 2 and 3 balls.
    • \n\t
    \n\t
  • \n
\n\n

Your penalty is the maximum number of balls in a bag. You want to minimize your penalty after the operations.

\n\n

Return the minimum possible penalty after performing the operations.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [9], maxOperations = 2\nOutput: 3\nExplanation: \n- Divide the bag with 9 balls into two bags of sizes 6 and 3. [9] -> [6,3].\n- Divide the bag with 6 balls into two bags of sizes 3 and 3. [6,3] -> [3,3,3].\nThe bag with the most number of balls has 3 balls, so your penalty is 3 and you should return 3.\n
\n\n

Example 2:

\n\n
\nInput: nums = [2,4,8,2], maxOperations = 4\nOutput: 2\nExplanation:\n- Divide the bag with 8 balls into two bags of sizes 4 and 4. [2,4,8,2] -> [2,4,4,4,2].\n- Divide the bag with 4 balls into two bags of sizes 2 and 2. [2,4,4,4,2] -> [2,2,2,4,4,2].\n- Divide the bag with 4 balls into two bags of sizes 2 and 2. [2,2,2,4,4,2] -> [2,2,2,2,2,4,2].\n- Divide the bag with 4 balls into two bags of sizes 2 and 2. [2,2,2,2,2,4,2] -> [2,2,2,2,2,2,2,2].\nThe bag with the most number of balls has 2 balls, so your penalty is 2 an you should return 2.\n
\n\n

Example 3:

\n\n
\nInput: nums = [7,17], maxOperations = 2\nOutput: 7\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 105
  • \n\t
  • 1 <= maxOperations, nums[i] <= 109
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0nums\u00a0\uff0c\u5176\u4e2d\u00a0nums[i]\u00a0\u8868\u793a\u7b2c\u00a0i\u00a0\u4e2a\u888b\u5b50\u91cc\u7403\u7684\u6570\u76ee\u3002\u540c\u65f6\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u00a0maxOperations\u00a0\u3002

\n\n

\u4f60\u53ef\u4ee5\u8fdb\u884c\u5982\u4e0b\u64cd\u4f5c\u81f3\u591a\u00a0maxOperations\u00a0\u6b21\uff1a

\n\n
    \n\t
  • \u9009\u62e9\u4efb\u610f\u4e00\u4e2a\u888b\u5b50\uff0c\u5e76\u5c06\u888b\u5b50\u91cc\u7684\u7403\u5206\u5230\u00a02 \u4e2a\u65b0\u7684\u888b\u5b50\u4e2d\uff0c\u6bcf\u4e2a\u888b\u5b50\u91cc\u90fd\u6709 \u6b63\u6574\u6570\u00a0\u4e2a\u7403\u3002\n\n\t
      \n\t\t
    • \u6bd4\u65b9\u8bf4\uff0c\u4e00\u4e2a\u888b\u5b50\u91cc\u6709\u00a05\u00a0\u4e2a\u7403\uff0c\u4f60\u53ef\u4ee5\u628a\u5b83\u4eec\u5206\u5230\u4e24\u4e2a\u65b0\u888b\u5b50\u91cc\uff0c\u5206\u522b\u6709 1\u00a0\u4e2a\u548c 4\u00a0\u4e2a\u7403\uff0c\u6216\u8005\u5206\u522b\u6709 2\u00a0\u4e2a\u548c 3\u00a0\u4e2a\u7403\u3002
    • \n\t
    \n\t
  • \n
\n\n

\u4f60\u7684\u5f00\u9500\u662f\u5355\u4e2a\u888b\u5b50\u91cc\u7403\u6570\u76ee\u7684 \u6700\u5927\u503c\u00a0\uff0c\u4f60\u60f3\u8981 \u6700\u5c0f\u5316\u00a0\u5f00\u9500\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u8fdb\u884c\u4e0a\u8ff0\u64cd\u4f5c\u540e\u7684\u6700\u5c0f\u5f00\u9500\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [9], maxOperations = 2\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\n- \u5c06\u88c5\u6709 9 \u4e2a\u7403\u7684\u888b\u5b50\u5206\u6210\u88c5\u6709 6 \u4e2a\u548c 3 \u4e2a\u7403\u7684\u888b\u5b50\u3002[9] -> [6,3] \u3002\n- \u5c06\u88c5\u6709 6 \u4e2a\u7403\u7684\u888b\u5b50\u5206\u6210\u88c5\u6709 3 \u4e2a\u548c 3 \u4e2a\u7403\u7684\u888b\u5b50\u3002[6,3] -> [3,3,3] \u3002\n\u88c5\u6709\u6700\u591a\u7403\u7684\u888b\u5b50\u91cc\u88c5\u6709 3 \u4e2a\u7403\uff0c\u6240\u4ee5\u5f00\u9500\u4e3a 3 \u5e76\u8fd4\u56de 3 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [2,4,8,2], maxOperations = 4\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n- \u5c06\u88c5\u6709 8 \u4e2a\u7403\u7684\u888b\u5b50\u5206\u6210\u88c5\u6709 4 \u4e2a\u548c 4 \u4e2a\u7403\u7684\u888b\u5b50\u3002[2,4,8,2] -> [2,4,4,4,2] \u3002\n- \u5c06\u88c5\u6709 4 \u4e2a\u7403\u7684\u888b\u5b50\u5206\u6210\u88c5\u6709 2 \u4e2a\u548c 2 \u4e2a\u7403\u7684\u888b\u5b50\u3002[2,4,4,4,2] -> [2,2,2,4,4,2] \u3002\n- \u5c06\u88c5\u6709 4 \u4e2a\u7403\u7684\u888b\u5b50\u5206\u6210\u88c5\u6709 2 \u4e2a\u548c 2 \u4e2a\u7403\u7684\u888b\u5b50\u3002[2,2,2,4,4,2] -> [2,2,2,2,2,4,2] \u3002\n- \u5c06\u88c5\u6709 4 \u4e2a\u7403\u7684\u888b\u5b50\u5206\u6210\u88c5\u6709 2 \u4e2a\u548c 2 \u4e2a\u7403\u7684\u888b\u5b50\u3002[2,2,2,2,2,4,2] -> [2,2,2,2,2,2,2,2] \u3002\n\u88c5\u6709\u6700\u591a\u7403\u7684\u888b\u5b50\u91cc\u88c5\u6709 2 \u4e2a\u7403\uff0c\u6240\u4ee5\u5f00\u9500\u4e3a 2 \u5e76\u8fd4\u56de 2 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [7,17], maxOperations = 2\n\u8f93\u51fa\uff1a7\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 105
  • \n\t
  • 1 <= maxOperations, nums[i] <= 109
  • \n
\n", "tags_en": ["Heap", "Binary Search"], "tags_cn": ["\u5806", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minimumSize(vector& nums, int maxOperations) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minimumSize(int[] nums, int maxOperations) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimumSize(self, nums, maxOperations):\n \"\"\"\n :type nums: List[int]\n :type maxOperations: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimumSize(self, nums: List[int], maxOperations: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minimumSize(int* nums, int numsSize, int maxOperations){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinimumSize(int[] nums, int maxOperations) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} maxOperations\n * @return {number}\n */\nvar minimumSize = function(nums, maxOperations) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} max_operations\n# @return {Integer}\ndef minimum_size(nums, max_operations)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimumSize(_ nums: [Int], _ maxOperations: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimumSize(nums []int, maxOperations int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimumSize(nums: Array[Int], maxOperations: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimumSize(nums: IntArray, maxOperations: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimum_size(nums: Vec, max_operations: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $maxOperations\n * @return Integer\n */\n function minimumSize($nums, $maxOperations) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimumSize(nums: number[], maxOperations: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimum-size nums maxOperations)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1760](https://leetcode-cn.com/problems/minimum-limit-of-balls-in-a-bag)", "[\u888b\u5b50\u91cc\u6700\u5c11\u6570\u76ee\u7684\u7403](/solution/1700-1799/1760.Minimum%20Limit%20of%20Balls%20in%20a%20Bag/README.md)", "`\u5806`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1760](https://leetcode.com/problems/minimum-limit-of-balls-in-a-bag)", "[Minimum Limit of Balls in a Bag](/solution/1700-1799/1760.Minimum%20Limit%20of%20Balls%20in%20a%20Bag/README_EN.md)", "`Heap`,`Binary Search`", "Medium", ""]}, {"question_id": "1885", "frontend_question_id": "1759", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-number-of-homogenous-substrings", "url_en": "https://leetcode.com/problems/count-number-of-homogenous-substrings", "relative_path_cn": "/solution/1700-1799/1759.Count%20Number%20of%20Homogenous%20Substrings/README.md", "relative_path_en": "/solution/1700-1799/1759.Count%20Number%20of%20Homogenous%20Substrings/README_EN.md", "title_cn": "\u7edf\u8ba1\u540c\u6784\u5b50\u5b57\u7b26\u4e32\u7684\u6570\u76ee", "title_en": "Count Number of Homogenous Substrings", "question_title_slug": "count-number-of-homogenous-substrings", "content_en": "

Given a string s, return the number of homogenous substrings of s. Since the answer may be too large, return it modulo 109 + 7.

\r\n\r\n

A string is homogenous if all the characters of the string are the same.

\r\n\r\n

A substring is a contiguous sequence of characters within a string.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: s = "abbcccaa"\r\nOutput: 13\r\nExplanation: The homogenous substrings are listed as below:\r\n"a"   appears 3 times.\r\n"aa"  appears 1 time.\r\n"b"   appears 2 times.\r\n"bb"  appears 1 time.\r\n"c"   appears 3 times.\r\n"cc"  appears 2 times.\r\n"ccc" appears 1 time.\r\n3 + 1 + 2 + 1 + 3 + 2 + 1 = 13.
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: s = "xy"\r\nOutput: 2\r\nExplanation: The homogenous substrings are "x" and "y".
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: s = "zzzzz"\r\nOutput: 15\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= s.length <= 105
  • \r\n\t
  • s consists of lowercase letters.
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \uff0c\u8fd4\u56de s \u4e2d \u540c\u6784\u5b50\u5b57\u7b26\u4e32 \u7684\u6570\u76ee\u3002\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u5f88\u5927\uff0c\u53ea\u9700\u8fd4\u56de\u5bf9 109 + 7 \u53d6\u4f59 \u540e\u7684\u7ed3\u679c\u3002

\n\n

\u540c\u6784\u5b57\u7b26\u4e32 \u7684\u5b9a\u4e49\u4e3a\uff1a\u5982\u679c\u4e00\u4e2a\u5b57\u7b26\u4e32\u4e2d\u7684\u6240\u6709\u5b57\u7b26\u90fd\u76f8\u540c\uff0c\u90a3\u4e48\u8be5\u5b57\u7b26\u4e32\u5c31\u662f\u540c\u6784\u5b57\u7b26\u4e32\u3002

\n\n

\u5b50\u5b57\u7b26\u4e32 \u662f\u5b57\u7b26\u4e32\u4e2d\u7684\u4e00\u4e2a\u8fde\u7eed\u5b57\u7b26\u5e8f\u5217\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1as = \"abbcccaa\"\n\u8f93\u51fa\uff1a13\n\u89e3\u91ca\uff1a\u540c\u6784\u5b50\u5b57\u7b26\u4e32\u5982\u4e0b\u6240\u5217\uff1a\n\"a\"   \u51fa\u73b0 3 \u6b21\u3002\n\"aa\"  \u51fa\u73b0 1 \u6b21\u3002\n\"b\"   \u51fa\u73b0 2 \u6b21\u3002\n\"bb\"  \u51fa\u73b0 1 \u6b21\u3002\n\"c\"   \u51fa\u73b0 3 \u6b21\u3002\n\"cc\"  \u51fa\u73b0 2 \u6b21\u3002\n\"ccc\" \u51fa\u73b0 1 \u6b21\u3002\n3 + 1 + 2 + 1 + 3 + 2 + 1 = 13
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1as = \"xy\"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u540c\u6784\u5b50\u5b57\u7b26\u4e32\u662f \"x\" \u548c \"y\" \u3002
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1as = \"zzzzz\"\n\u8f93\u51fa\uff1a15\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length <= 105
  • \n\t
  • s \u7531\u5c0f\u5199\u5b57\u7b26\u4e32\u7ec4\u6210
  • \n
\n", "tags_en": ["Greedy", "String"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countHomogenous(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countHomogenous(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countHomogenous(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countHomogenous(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countHomogenous(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountHomogenous(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar countHomogenous = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef count_homogenous(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countHomogenous(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countHomogenous(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countHomogenous(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countHomogenous(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_homogenous(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function countHomogenous($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countHomogenous(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-homogenous s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1759](https://leetcode-cn.com/problems/count-number-of-homogenous-substrings)", "[\u7edf\u8ba1\u540c\u6784\u5b50\u5b57\u7b26\u4e32\u7684\u6570\u76ee](/solution/1700-1799/1759.Count%20Number%20of%20Homogenous%20Substrings/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1759](https://leetcode.com/problems/count-number-of-homogenous-substrings)", "[Count Number of Homogenous Substrings](/solution/1700-1799/1759.Count%20Number%20of%20Homogenous%20Substrings/README_EN.md)", "`Greedy`,`String`", "Medium", ""]}, {"question_id": "1884", "frontend_question_id": "1758", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-changes-to-make-alternating-binary-string", "url_en": "https://leetcode.com/problems/minimum-changes-to-make-alternating-binary-string", "relative_path_cn": "/solution/1700-1799/1758.Minimum%20Changes%20To%20Make%20Alternating%20Binary%20String/README.md", "relative_path_en": "/solution/1700-1799/1758.Minimum%20Changes%20To%20Make%20Alternating%20Binary%20String/README_EN.md", "title_cn": "\u751f\u6210\u4ea4\u66ff\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32\u7684\u6700\u5c11\u64cd\u4f5c\u6570", "title_en": "Minimum Changes To Make Alternating Binary String", "question_title_slug": "minimum-changes-to-make-alternating-binary-string", "content_en": "

You are given a string s consisting only of the characters '0' and '1'. In one operation, you can change any '0' to '1' or vice versa.

\n\n

The string is called alternating if no two adjacent characters are equal. For example, the string "010" is alternating, while the string "0100" is not.

\n\n

Return the minimum number of operations needed to make s alternating.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "0100"\nOutput: 1\nExplanation: If you change the last character to '1', s will be "0101", which is alternating.\n
\n\n

Example 2:

\n\n
\nInput: s = "10"\nOutput: 0\nExplanation: s is already alternating.\n
\n\n

Example 3:

\n\n
\nInput: s = "1111"\nOutput: 2\nExplanation: You need two operations to reach "0101" or "1010".\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 104
  • \n\t
  • s[i] is either '0' or '1'.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u4ec5\u7531\u5b57\u7b26 '0' \u548c '1' \u7ec4\u6210\u7684\u5b57\u7b26\u4e32 s \u3002\u4e00\u6b65\u64cd\u4f5c\u4e2d\uff0c\u4f60\u53ef\u4ee5\u5c06\u4efb\u4e00 '0' \u53d8\u6210 '1' \uff0c\u6216\u8005\u5c06 '1' \u53d8\u6210 '0' \u3002

\n\n

\u4ea4\u66ff\u5b57\u7b26\u4e32 \u5b9a\u4e49\u4e3a\uff1a\u5982\u679c\u5b57\u7b26\u4e32\u4e2d\u4e0d\u5b58\u5728\u76f8\u90bb\u4e24\u4e2a\u5b57\u7b26\u76f8\u7b49\u7684\u60c5\u51b5\uff0c\u90a3\u4e48\u8be5\u5b57\u7b26\u4e32\u5c31\u662f\u4ea4\u66ff\u5b57\u7b26\u4e32\u3002\u4f8b\u5982\uff0c\u5b57\u7b26\u4e32 \"010\" \u662f\u4ea4\u66ff\u5b57\u7b26\u4e32\uff0c\u800c\u5b57\u7b26\u4e32 \"0100\" \u4e0d\u662f\u3002

\n\n

\u8fd4\u56de\u4f7f s \u53d8\u6210 \u4ea4\u66ff\u5b57\u7b26\u4e32 \u6240\u9700\u7684 \u6700\u5c11 \u64cd\u4f5c\u6570\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1as = \"0100\"\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u5982\u679c\u5c06\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\u53d8\u4e3a '1' \uff0cs \u5c31\u53d8\u6210 \"0101\" \uff0c\u5373\u7b26\u5408\u4ea4\u66ff\u5b57\u7b26\u4e32\u5b9a\u4e49\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1as = \"10\"\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1as \u5df2\u7ecf\u662f\u4ea4\u66ff\u5b57\u7b26\u4e32\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1as = \"1111\"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u9700\u8981 2 \u6b65\u64cd\u4f5c\u5f97\u5230 \"0101\" \u6216 \"1010\" \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length <= 104
  • \n\t
  • s[i] \u662f '0' \u6216 '1'
  • \n
\n", "tags_en": ["Greedy", "Array"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minOperations(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minOperations(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minOperations(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minOperations(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minOperations(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinOperations(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar minOperations = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef min_operations(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minOperations(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minOperations(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minOperations(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minOperations(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_operations(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function minOperations($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minOperations(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-operations s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1758](https://leetcode-cn.com/problems/minimum-changes-to-make-alternating-binary-string)", "[\u751f\u6210\u4ea4\u66ff\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32\u7684\u6700\u5c11\u64cd\u4f5c\u6570](/solution/1700-1799/1758.Minimum%20Changes%20To%20Make%20Alternating%20Binary%20String/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1758](https://leetcode.com/problems/minimum-changes-to-make-alternating-binary-string)", "[Minimum Changes To Make Alternating Binary String](/solution/1700-1799/1758.Minimum%20Changes%20To%20Make%20Alternating%20Binary%20String/README_EN.md)", "`Greedy`,`Array`", "Easy", ""]}, {"question_id": "1883", "frontend_question_id": "1740", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/find-distance-in-a-binary-tree", "url_en": "https://leetcode.com/problems/find-distance-in-a-binary-tree", "relative_path_cn": "/solution/1700-1799/1740.Find%20Distance%20in%20a%20Binary%20Tree/README.md", "relative_path_en": "/solution/1700-1799/1740.Find%20Distance%20in%20a%20Binary%20Tree/README_EN.md", "title_cn": "\u627e\u5230\u4e8c\u53c9\u6811\u4e2d\u7684\u8ddd\u79bb", "title_en": "Find Distance in a Binary Tree", "question_title_slug": "find-distance-in-a-binary-tree", "content_en": "

Given the root of a binary tree and two integers p and q, return the distance between the nodes of value p and value q in the tree.

\n\n

The distance between two nodes is the number of edges on the path from one to the other.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 0\nOutput: 3\nExplanation: There are 3 edges between 5 and 0: 5-3-1-0.
\n\n

Example 2:

\n\"\"\n
\nInput: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 7\nOutput: 2\nExplanation: There are 2 edges between 5 and 7: 5-2-7.
\n\n

Example 3:

\n\"\"\n
\nInput: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 5\nOutput: 0\nExplanation: The distance between a node and itself is 0.
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The number of nodes in the tree is in the range [1, 104].
  • \n\t
  • 0 <= Node.val <= 109
  • \n\t
  • All Node.val are unique.
  • \n\t
  • p and q are values in the tree.
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u68f5\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9 root \u4ee5\u53ca\u4e24\u4e2a\u6574\u6570 p \u548c q \uff0c\u8fd4\u56de\u8be5\u4e8c\u53c9\u6811\u4e2d\u503c\u4e3a p \u7684\u7ed3\u70b9\u4e0e\u503c\u4e3a q \u7684\u7ed3\u70b9\u95f4\u7684 \u8ddd\u79bb \u3002

\n\n

\u4e24\u4e2a\u7ed3\u70b9\u95f4\u7684 \u8ddd\u79bb \u5c31\u662f\u4ece\u4e00\u4e2a\u7ed3\u70b9\u5230\u53e6\u4e00\u4e2a\u7ed3\u70b9\u7684\u8def\u5f84\u4e0a\u8fb9\u7684\u6570\u76ee\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1aroot = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 0\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u5728 5 \u548c 0 \u4e4b\u95f4\u6709 3 \u6761\u8fb9\uff1a5-3-1-0
\n\n

\u793a\u4f8b 2\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1aroot = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 7\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5728 5 \u548c 7 \u4e4b\u95f4\u6709 2 \u6761\u8fb9\uff1a5-2-7
\n\n

\u793a\u4f8b 3\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1aroot = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 5\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u4e00\u4e2a\u7ed3\u70b9\u4e0e\u5b83\u672c\u8eab\u4e4b\u95f4\u7684\u8ddd\u79bb\u4e3a 0
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u6811\u4e2d\u7ed3\u70b9\u4e2a\u6570\u7684\u8303\u56f4\u5728\u00a0[1, 104].
  • \n\t
  • 0 <= Node.val <= 109
  • \n\t
  • \u6811\u4e2d\u6240\u6709\u7ed3\u70b9\u7684\u503c\u90fd\u662f\u552f\u4e00\u7684.
  • \n\t
  • p \u548cq \u662f\u6811\u4e2d\u7ed3\u70b9\u7684\u503c.
  • \n
\n", "tags_en": ["Tree", "Depth-first Search", "Breadth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int findDistance(TreeNode* root, int p, int q) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int findDistance(TreeNode root, int p, int q) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def findDistance(self, root, p, q):\n \"\"\"\n :type root: TreeNode\n :type p: int\n :type q: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def findDistance(self, root: TreeNode, p: int, q: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint findDistance(struct TreeNode* root, int p, int q){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int FindDistance(TreeNode root, int p, int q) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number} p\n * @param {number} q\n * @return {number}\n */\nvar findDistance = function(root, p, q) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @param {Integer} p\n# @param {Integer} q\n# @return {Integer}\ndef find_distance(root, p, q)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func findDistance(_ root: TreeNode?, _ p: Int, _ q: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc findDistance(root *TreeNode, p int, q int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def findDistance(root: TreeNode, p: Int, q: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun findDistance(root: TreeNode?, p: Int, q: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn find_distance(root: Option>>, p: i32, q: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param Integer $p\n * @param Integer $q\n * @return Integer\n */\n function findDistance($root, $p, $q) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction findDistance(root: TreeNode | null, p: number, q: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (find-distance root p q)\n (-> (or/c tree-node? #f) exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1740](https://leetcode-cn.com/problems/find-distance-in-a-binary-tree)", "[\u627e\u5230\u4e8c\u53c9\u6811\u4e2d\u7684\u8ddd\u79bb](/solution/1700-1799/1740.Find%20Distance%20in%20a%20Binary%20Tree/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1740](https://leetcode.com/problems/find-distance-in-a-binary-tree)", "[Find Distance in a Binary Tree](/solution/1700-1799/1740.Find%20Distance%20in%20a%20Binary%20Tree/README_EN.md)", "`Tree`,`Depth-first Search`,`Breadth-first Search`", "Medium", "\ud83d\udd12"]}, {"question_id": "1882", "frontend_question_id": "1731", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/the-number-of-employees-which-report-to-each-employee", "url_en": "https://leetcode.com/problems/the-number-of-employees-which-report-to-each-employee", "relative_path_cn": "/solution/1700-1799/1731.The%20Number%20of%20Employees%20Which%20Report%20to%20Each%20Employee/README.md", "relative_path_en": "/solution/1700-1799/1731.The%20Number%20of%20Employees%20Which%20Report%20to%20Each%20Employee/README_EN.md", "title_cn": "\u6bcf\u4f4d\u7ecf\u7406\u7684\u4e0b\u5c5e\u5458\u5de5\u6570\u91cf", "title_en": "The Number of Employees Which Report to Each Employee", "question_title_slug": "the-number-of-employees-which-report-to-each-employee", "content_en": "

Table: Employees

\n\n
\n+-------------+----------+\n| Column Name | Type     |\n+-------------+----------+\n| employee_id | int      |\n| name        | varchar  |\n| reports_to  | int      |\n| age         | int      |\n+-------------+----------+\nemployee_id is the primary key for this table.\nThis table contains information about the employees and the id of the manager they report to. Some employees do not report to anyone (reports_to is null). \n
\n\n

 

\n\n

For this problem, we will consider a manager an employee who has at least 1 other employee reporting to them.

\n\n

Write an SQL query to report the ids and the names of all managers, the number of employees who report directly to them, and the average age of the reports rounded to the nearest integer.

\n\n

Return the result table ordered by employee_id.

\n\n

The query result format is in the following example:

\n\n

 

\n\n
\nEmployees table:\n+-------------+---------+------------+-----+\n| employee_id | name    | reports_to | age |\n+-------------+---------+------------+-----+\n| 9           | Hercy   | null       | 43  |\n| 6           | Alice   | 9          | 41  |\n| 4           | Bob     | 9          | 36  |\n| 2           | Winston | null       | 37  |\n+-------------+---------+------------+-----+\n\nResult table:\n+-------------+-------+---------------+-------------+\n| employee_id | name  | reports_count | average_age |\n+-------------+-------+---------------+-------------+\n| 9           | Hercy | 2             | 39          |\n+-------------+-------+---------------+-------------+\nHercy has 2 people report directly to him, Alice and Bob. Their average age is (41+36)/2 = 38.5, which is 39 after rounding it to the nearest integer.\n
\n", "content_cn": "

Table: Employees

\n\n
+-------------+----------+\n| Column Name | Type     |\n+-------------+----------+\n| employee_id | int      |\n| name        | varchar  |\n| reports_to  | int      |\n| age         | int      |\n+-------------+----------+\nemployee_id \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e.\n\u8be5\u8868\u5305\u542b\u5458\u5de5\u4ee5\u53ca\u9700\u8981\u542c\u53d6\u4ed6\u4eec\u6c47\u62a5\u7684\u4e0a\u7ea7\u7ecf\u7406\u7684ID\u7684\u4fe1\u606f\u3002 \u6709\u4e9b\u5458\u5de5\u4e0d\u9700\u8981\u5411\u4efb\u4f55\u4eba\u6c47\u62a5\uff08reports_to \u4e3a\u7a7a\uff09\u3002\n
\n\n

\u00a0

\n\n

\u5bf9\u4e8e\u6b64\u95ee\u9898\uff0c\u6211\u4eec\u5c06\u81f3\u5c11\u6709\u4e00\u4e2a\u5176\u4ed6\u5458\u5de5\u9700\u8981\u5411\u4ed6\u6c47\u62a5\u7684\u5458\u5de5\uff0c\u89c6\u4e3a\u4e00\u4e2a\u7ecf\u7406\u3002

\n\n

\u7f16\u5199SQL\u67e5\u8be2\u9700\u8981\u542c\u53d6\u6c47\u62a5\u7684\u6240\u6709\u7ecf\u7406\u7684ID\u3001\u540d\u79f0\u3001\u76f4\u63a5\u5411\u8be5\u7ecf\u7406\u6c47\u62a5\u7684\u5458\u5de5\u4eba\u6570\uff0c\u4ee5\u53ca\u8fd9\u4e9b\u5458\u5de5\u7684\u5e73\u5747\u5e74\u9f84\uff0c\u5176\u4e2d\u8be5\u5e73\u5747\u5e74\u9f84\u9700\u8981\u56db\u820d\u4e94\u5165\u5230\u6700\u63a5\u8fd1\u7684\u6574\u6570\u3002

\n\n

\u8fd4\u56de\u7684\u7ed3\u679c\u96c6\u9700\u8981\u6309\u7167\u00a0employee_id \u8fdb\u884c\u6392\u5e8f\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u7684\u683c\u5f0f\u5982\u4e0b\uff1a

\n\n

\u00a0

\n\n
Employees table:\n+-------------+---------+------------+-----+\n| employee_id | name    | reports_to | age |\n+-------------+---------+------------+-----+\n| 9           | Hercy   | null       | 43  |\n| 6           | Alice   | 9          | 41  |\n| 4           | Bob     | 9          | 36  |\n| 2           | Winston | null       | 37  |\n+-------------+---------+------------+-----+\n\nResult table:\n+-------------+-------+---------------+-------------+\n| employee_id | name  | reports_count | average_age |\n+-------------+-------+---------------+-------------+\n| 9           | Hercy | 2             | 39          |\n+-------------+-------+---------------+-------------+\nHercy \u6709\u4e24\u4e2a\u9700\u8981\u5411\u4ed6\u6c47\u62a5\u7684\u5458\u5de5, \u4ed6\u4eec\u662f Alice and Bob. \u4ed6\u4eec\u7684\u5e73\u5747\u5e74\u9f84\u662f (41+36)/2 = 38.5, \u56db\u820d\u4e94\u5165\u7684\u7ed3\u679c\u662f 39.\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1731](https://leetcode-cn.com/problems/the-number-of-employees-which-report-to-each-employee)", "[\u6bcf\u4f4d\u7ecf\u7406\u7684\u4e0b\u5c5e\u5458\u5de5\u6570\u91cf](/solution/1700-1799/1731.The%20Number%20of%20Employees%20Which%20Report%20to%20Each%20Employee/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1731](https://leetcode.com/problems/the-number-of-employees-which-report-to-each-employee)", "[The Number of Employees Which Report to Each Employee](/solution/1700-1799/1731.The%20Number%20of%20Employees%20Which%20Report%20to%20Each%20Employee/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1881", "frontend_question_id": "1755", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/closest-subsequence-sum", "url_en": "https://leetcode.com/problems/closest-subsequence-sum", "relative_path_cn": "/solution/1700-1799/1755.Closest%20Subsequence%20Sum/README.md", "relative_path_en": "/solution/1700-1799/1755.Closest%20Subsequence%20Sum/README_EN.md", "title_cn": "\u6700\u63a5\u8fd1\u76ee\u6807\u503c\u7684\u5b50\u5e8f\u5217\u548c", "title_en": "Closest Subsequence Sum", "question_title_slug": "closest-subsequence-sum", "content_en": "

You are given an integer array nums and an integer goal.

\n\n

You want to choose a subsequence of nums such that the sum of its elements is the closest possible to goal. That is, if the sum of the subsequence's elements is sum, then you want to minimize the absolute difference abs(sum - goal).

\n\n

Return the minimum possible value of abs(sum - goal).

\n\n

Note that a subsequence of an array is an array formed by removing some elements (possibly all or none) of the original array.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [5,-7,3,5], goal = 6\nOutput: 0\nExplanation: Choose the whole array as a subsequence, with a sum of 6.\nThis is equal to the goal, so the absolute difference is 0.\n
\n\n

Example 2:

\n\n
\nInput: nums = [7,-9,15,-2], goal = -5\nOutput: 1\nExplanation: Choose the subsequence [7,-9,-2], with a sum of -4.\nThe absolute difference is abs(-4 - (-5)) = abs(1) = 1, which is the minimum.\n
\n\n

Example 3:

\n\n
\nInput: nums = [1,2,3], goal = -7\nOutput: 7\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 40
  • \n\t
  • -107 <= nums[i] <= 107
  • \n\t
  • -109 <= goal <= 109
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \u548c\u4e00\u4e2a\u76ee\u6807\u503c goal \u3002

\n\n

\u4f60\u9700\u8981\u4ece nums \u4e2d\u9009\u51fa\u4e00\u4e2a\u5b50\u5e8f\u5217\uff0c\u4f7f\u5b50\u5e8f\u5217\u5143\u7d20\u603b\u548c\u6700\u63a5\u8fd1 goal \u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u5982\u679c\u5b50\u5e8f\u5217\u5143\u7d20\u548c\u4e3a sum \uff0c\u4f60\u9700\u8981 \u6700\u5c0f\u5316\u7edd\u5bf9\u5dee abs(sum - goal) \u3002

\n\n

\u8fd4\u56de abs(sum - goal) \u53ef\u80fd\u7684 \u6700\u5c0f\u503c \u3002

\n\n

\u6ce8\u610f\uff0c\u6570\u7ec4\u7684\u5b50\u5e8f\u5217\u662f\u901a\u8fc7\u79fb\u9664\u539f\u59cb\u6570\u7ec4\u4e2d\u7684\u67d0\u4e9b\u5143\u7d20\uff08\u53ef\u80fd\u5168\u90e8\u6216\u65e0\uff09\u800c\u5f62\u6210\u7684\u6570\u7ec4\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anums = [5,-7,3,5], goal = 6\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u9009\u62e9\u6574\u4e2a\u6570\u7ec4\u4f5c\u4e3a\u9009\u51fa\u7684\u5b50\u5e8f\u5217\uff0c\u5143\u7d20\u548c\u4e3a 6 \u3002\n\u5b50\u5e8f\u5217\u548c\u4e0e\u76ee\u6807\u503c\u76f8\u7b49\uff0c\u6240\u4ee5\u7edd\u5bf9\u5dee\u4e3a 0 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anums = [7,-9,15,-2], goal = -5\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u9009\u51fa\u5b50\u5e8f\u5217 [7,-9,-2] \uff0c\u5143\u7d20\u548c\u4e3a -4 \u3002\n\u7edd\u5bf9\u5dee\u4e3a abs(-4 - (-5)) = abs(1) = 1 \uff0c\u662f\u53ef\u80fd\u7684\u6700\u5c0f\u503c\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,2,3], goal = -7\n\u8f93\u51fa\uff1a7\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 40
  • \n\t
  • -107 <= nums[i] <= 107
  • \n\t
  • -109 <= goal <= 109
  • \n
\n", "tags_en": ["Divide and Conquer"], "tags_cn": ["\u5206\u6cbb\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minAbsDifference(vector& nums, int goal) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minAbsDifference(int[] nums, int goal) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minAbsDifference(self, nums, goal):\n \"\"\"\n :type nums: List[int]\n :type goal: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minAbsDifference(self, nums: List[int], goal: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minAbsDifference(int* nums, int numsSize, int goal){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinAbsDifference(int[] nums, int goal) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} goal\n * @return {number}\n */\nvar minAbsDifference = function(nums, goal) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} goal\n# @return {Integer}\ndef min_abs_difference(nums, goal)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minAbsDifference(_ nums: [Int], _ goal: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minAbsDifference(nums []int, goal int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minAbsDifference(nums: Array[Int], goal: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minAbsDifference(nums: IntArray, goal: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_abs_difference(nums: Vec, goal: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $goal\n * @return Integer\n */\n function minAbsDifference($nums, $goal) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minAbsDifference(nums: number[], goal: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-abs-difference nums goal)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1755](https://leetcode-cn.com/problems/closest-subsequence-sum)", "[\u6700\u63a5\u8fd1\u76ee\u6807\u503c\u7684\u5b50\u5e8f\u5217\u548c](/solution/1700-1799/1755.Closest%20Subsequence%20Sum/README.md)", "`\u5206\u6cbb\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[1755](https://leetcode.com/problems/closest-subsequence-sum)", "[Closest Subsequence Sum](/solution/1700-1799/1755.Closest%20Subsequence%20Sum/README_EN.md)", "`Divide and Conquer`", "Hard", ""]}, {"question_id": "1880", "frontend_question_id": "1754", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/largest-merge-of-two-strings", "url_en": "https://leetcode.com/problems/largest-merge-of-two-strings", "relative_path_cn": "/solution/1700-1799/1754.Largest%20Merge%20Of%20Two%20Strings/README.md", "relative_path_en": "/solution/1700-1799/1754.Largest%20Merge%20Of%20Two%20Strings/README_EN.md", "title_cn": "\u6784\u9020\u5b57\u5178\u5e8f\u6700\u5927\u7684\u5408\u5e76\u5b57\u7b26\u4e32", "title_en": "Largest Merge Of Two Strings", "question_title_slug": "largest-merge-of-two-strings", "content_en": "

You are given two strings word1 and word2. You want to construct a string merge in the following way: while either word1 or word2 are non-empty, choose one of the following options:

\n\n
    \n\t
  • If word1 is non-empty, append the first character in word1 to merge and delete it from word1.\n\n\t
      \n\t\t
    • For example, if word1 = "abc" and merge = "dv", then after choosing this operation, word1 = "bc" and merge = "dva".
    • \n\t
    \n\t
  • \n\t
  • If word2 is non-empty, append the first character in word2 to merge and delete it from word2.\n\t
      \n\t\t
    • For example, if word2 = "abc" and merge = "", then after choosing this operation, word2 = "bc" and merge = "a".
    • \n\t
    \n\t
  • \n
\n\n

Return the lexicographically largest merge you can construct.

\n\n

A string a is lexicographically larger than a string b (of the same length) if in the first position where a and b differ, a has a character strictly larger than the corresponding character in b. For example, "abcd" is lexicographically larger than "abcc" because the first position they differ is at the fourth character, and d is greater than c.

\n\n

 

\n

Example 1:

\n\n
\nInput: word1 = "cabaa", word2 = "bcaaa"\nOutput: "cbcabaaaaa"\nExplanation: One way to get the lexicographically largest merge is:\n- Take from word1: merge = "c", word1 = "abaa", word2 = "bcaaa"\n- Take from word2: merge = "cb", word1 = "abaa", word2 = "caaa"\n- Take from word2: merge = "cbc", word1 = "abaa", word2 = "aaa"\n- Take from word1: merge = "cbca", word1 = "baa", word2 = "aaa"\n- Take from word1: merge = "cbcab", word1 = "aa", word2 = "aaa"\n- Append the remaining 5 a's from word1 and word2 at the end of merge.\n
\n\n

Example 2:

\n\n
\nInput: word1 = "abcabc", word2 = "abdcaba"\nOutput: "abdcabcabcaba"\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= word1.length, word2.length <= 3000
  • \n\t
  • word1 and word2 consist only of lowercase English letters.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e24\u4e2a\u5b57\u7b26\u4e32 word1 \u548c word2 \u3002\u4f60\u9700\u8981\u6309\u4e0b\u8ff0\u65b9\u5f0f\u6784\u9020\u4e00\u4e2a\u65b0\u5b57\u7b26\u4e32 merge \uff1a\u5982\u679c word1 \u6216 word2 \u975e\u7a7a\uff0c\u9009\u62e9 \u4e0b\u9762\u9009\u9879\u4e4b\u4e00 \u7ee7\u7eed\u64cd\u4f5c\uff1a

\n\n
    \n\t
  • \u5982\u679c word1 \u975e\u7a7a\uff0c\u5c06 word1 \u4e2d\u7684\u7b2c\u4e00\u4e2a\u5b57\u7b26\u9644\u52a0\u5230 merge \u7684\u672b\u5c3e\uff0c\u5e76\u5c06\u5176\u4ece word1 \u4e2d\u79fb\u9664\u3002\n\n\t
      \n\t\t
    • \u4f8b\u5982\uff0cword1 = \"abc\" \u4e14 merge = \"dv\" \uff0c\u5728\u6267\u884c\u6b64\u9009\u9879\u64cd\u4f5c\u4e4b\u540e\uff0cword1 = \"bc\" \uff0c\u540c\u65f6 merge = \"dva\" \u3002
    • \n\t
    \n\t
  • \n\t
  • \u5982\u679c word2 \u975e\u7a7a\uff0c\u5c06 word2 \u4e2d\u7684\u7b2c\u4e00\u4e2a\u5b57\u7b26\u9644\u52a0\u5230 merge \u7684\u672b\u5c3e\uff0c\u5e76\u5c06\u5176\u4ece word2 \u4e2d\u79fb\u9664\u3002\n\t
      \n\t\t
    • \u4f8b\u5982\uff0cword2 = \"abc\" \u4e14 merge = \"\" \uff0c\u5728\u6267\u884c\u6b64\u9009\u9879\u64cd\u4f5c\u4e4b\u540e\uff0cword2 = \"bc\" \uff0c\u540c\u65f6 merge = \"a\" \u3002
    • \n\t
    \n\t
  • \n
\n\n

\u8fd4\u56de\u4f60\u53ef\u4ee5\u6784\u9020\u7684\u5b57\u5178\u5e8f \u6700\u5927 \u7684\u5408\u5e76\u5b57\u7b26\u4e32 merge \u3002

\n\n

\u957f\u5ea6\u76f8\u540c\u7684\u4e24\u4e2a\u5b57\u7b26\u4e32 a \u548c b \u6bd4\u8f83\u5b57\u5178\u5e8f\u5927\u5c0f\uff0c\u5982\u679c\u5728 a \u548c b \u51fa\u73b0\u4e0d\u540c\u7684\u7b2c\u4e00\u4e2a\u4f4d\u7f6e\uff0ca \u4e2d\u5b57\u7b26\u5728\u5b57\u6bcd\u8868\u4e2d\u7684\u51fa\u73b0\u987a\u5e8f\u4f4d\u4e8e b \u4e2d\u76f8\u5e94\u5b57\u7b26\u4e4b\u540e\uff0c\u5c31\u8ba4\u4e3a\u5b57\u7b26\u4e32 a \u6309\u5b57\u5178\u5e8f\u6bd4\u5b57\u7b26\u4e32 b \u66f4\u5927\u3002\u4f8b\u5982\uff0c\"abcd\" \u6309\u5b57\u5178\u5e8f\u6bd4 \"abcc\" \u66f4\u5927\uff0c\u56e0\u4e3a\u4e24\u4e2a\u5b57\u7b26\u4e32\u51fa\u73b0\u4e0d\u540c\u7684\u7b2c\u4e00\u4e2a\u4f4d\u7f6e\u662f\u7b2c\u56db\u4e2a\u5b57\u7b26\uff0c\u800c d \u5728\u5b57\u6bcd\u8868\u4e2d\u7684\u51fa\u73b0\u987a\u5e8f\u4f4d\u4e8e c \u4e4b\u540e\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aword1 = \"cabaa\", word2 = \"bcaaa\"\n\u8f93\u51fa\uff1a\"cbcabaaaaa\"\n\u89e3\u91ca\uff1a\u6784\u9020\u5b57\u5178\u5e8f\u6700\u5927\u7684\u5408\u5e76\u5b57\u7b26\u4e32\uff0c\u53ef\u884c\u7684\u4e00\u79cd\u65b9\u6cd5\u5982\u4e0b\u6240\u793a\uff1a\n- \u4ece word1 \u4e2d\u53d6\u7b2c\u4e00\u4e2a\u5b57\u7b26\uff1amerge = \"c\"\uff0cword1 = \"abaa\"\uff0cword2 = \"bcaaa\"\n- \u4ece word2 \u4e2d\u53d6\u7b2c\u4e00\u4e2a\u5b57\u7b26\uff1amerge = \"cb\"\uff0cword1 = \"abaa\"\uff0cword2 = \"caaa\"\n- \u4ece word2 \u4e2d\u53d6\u7b2c\u4e00\u4e2a\u5b57\u7b26\uff1amerge = \"cbc\"\uff0cword1 = \"abaa\"\uff0cword2 = \"aaa\"\n- \u4ece word1 \u4e2d\u53d6\u7b2c\u4e00\u4e2a\u5b57\u7b26\uff1amerge = \"cbca\"\uff0cword1 = \"baa\"\uff0cword2 = \"aaa\"\n- \u4ece word1 \u4e2d\u53d6\u7b2c\u4e00\u4e2a\u5b57\u7b26\uff1amerge = \"cbcab\"\uff0cword1 = \"aa\"\uff0cword2 = \"aaa\"\n- \u5c06 word1 \u548c word2 \u4e2d\u5269\u4e0b\u7684 5 \u4e2a a \u9644\u52a0\u5230 merge \u7684\u672b\u5c3e\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aword1 = \"abcabc\", word2 = \"abdcaba\"\n\u8f93\u51fa\uff1a\"abdcabcabcaba\"\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= word1.length, word2.length <= 3000
  • \n\t
  • word1 \u548c word2 \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u7ec4\u6210
  • \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string largestMerge(string word1, string word2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String largestMerge(String word1, String word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def largestMerge(self, word1, word2):\n \"\"\"\n :type word1: str\n :type word2: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def largestMerge(self, word1: str, word2: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * largestMerge(char * word1, char * word2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string LargestMerge(string word1, string word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} word1\n * @param {string} word2\n * @return {string}\n */\nvar largestMerge = function(word1, word2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} word1\n# @param {String} word2\n# @return {String}\ndef largest_merge(word1, word2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func largestMerge(_ word1: String, _ word2: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func largestMerge(word1 string, word2 string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def largestMerge(word1: String, word2: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun largestMerge(word1: String, word2: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn largest_merge(word1: String, word2: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $word1\n * @param String $word2\n * @return String\n */\n function largestMerge($word1, $word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function largestMerge(word1: string, word2: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (largest-merge word1 word2)\n (-> string? string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1754](https://leetcode-cn.com/problems/largest-merge-of-two-strings)", "[\u6784\u9020\u5b57\u5178\u5e8f\u6700\u5927\u7684\u5408\u5e76\u5b57\u7b26\u4e32](/solution/1700-1799/1754.Largest%20Merge%20Of%20Two%20Strings/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1754](https://leetcode.com/problems/largest-merge-of-two-strings)", "[Largest Merge Of Two Strings](/solution/1700-1799/1754.Largest%20Merge%20Of%20Two%20Strings/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1879", "frontend_question_id": "1753", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-score-from-removing-stones", "url_en": "https://leetcode.com/problems/maximum-score-from-removing-stones", "relative_path_cn": "/solution/1700-1799/1753.Maximum%20Score%20From%20Removing%20Stones/README.md", "relative_path_en": "/solution/1700-1799/1753.Maximum%20Score%20From%20Removing%20Stones/README_EN.md", "title_cn": "\u79fb\u9664\u77f3\u5b50\u7684\u6700\u5927\u5f97\u5206", "title_en": "Maximum Score From Removing Stones", "question_title_slug": "maximum-score-from-removing-stones", "content_en": "

You are playing a solitaire game with three piles of stones of sizes a\u200b\u200b\u200b\u200b\u200b\u200b, b,\u200b\u200b\u200b\u200b\u200b\u200b and c\u200b\u200b\u200b\u200b\u200b\u200b respectively. Each turn you choose two different non-empty piles, take one stone from each, and add 1 point to your score. The game stops when there are fewer than two non-empty piles (meaning there are no more available moves).

\n\n

Given three integers a\u200b\u200b\u200b\u200b\u200b, b,\u200b\u200b\u200b\u200b\u200b and c\u200b\u200b\u200b\u200b\u200b, return the maximum score you can get.

\n\n

 

\n

Example 1:

\n\n
\nInput: a = 2, b = 4, c = 6\nOutput: 6\nExplanation: The starting state is (2, 4, 6). One optimal set of moves is:\n- Take from 1st and 3rd piles, state is now (1, 4, 5)\n- Take from 1st and 3rd piles, state is now (0, 4, 4)\n- Take from 2nd and 3rd piles, state is now (0, 3, 3)\n- Take from 2nd and 3rd piles, state is now (0, 2, 2)\n- Take from 2nd and 3rd piles, state is now (0, 1, 1)\n- Take from 2nd and 3rd piles, state is now (0, 0, 0)\nThere are fewer than two non-empty piles, so the game ends. Total: 6 points.\n
\n\n

Example 2:

\n\n
\nInput: a = 4, b = 4, c = 6\nOutput: 7\nExplanation: The starting state is (4, 4, 6). One optimal set of moves is:\n- Take from 1st and 2nd piles, state is now (3, 3, 6)\n- Take from 1st and 3rd piles, state is now (2, 3, 5)\n- Take from 1st and 3rd piles, state is now (1, 3, 4)\n- Take from 1st and 3rd piles, state is now (0, 3, 3)\n- Take from 2nd and 3rd piles, state is now (0, 2, 2)\n- Take from 2nd and 3rd piles, state is now (0, 1, 1)\n- Take from 2nd and 3rd piles, state is now (0, 0, 0)\nThere are fewer than two non-empty piles, so the game ends. Total: 7 points.\n
\n\n

Example 3:

\n\n
\nInput: a = 1, b = 8, c = 8\nOutput: 8\nExplanation: One optimal set of moves is to take from the 2nd and 3rd piles for 8 turns until they are empty.\nAfter that, there are fewer than two non-empty piles, so the game ends.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= a, b, c <= 105
  • \n
\n", "content_cn": "

\u4f60\u6b63\u5728\u73a9\u4e00\u4e2a\u5355\u4eba\u6e38\u620f\uff0c\u9762\u524d\u653e\u7f6e\u7740\u5927\u5c0f\u5206\u522b\u4e3a a\u200b\u200b\u200b\u200b\u200b\u200b\u3001b \u548c c\u200b\u200b\u200b\u200b\u200b\u200b \u7684 \u4e09\u5806 \u77f3\u5b50\u3002

\n\n

\u6bcf\u56de\u5408\u4f60\u90fd\u8981\u4ece\u4e24\u4e2a \u4e0d\u540c\u7684\u975e\u7a7a\u5806 \u4e2d\u53d6\u51fa\u4e00\u9897\u77f3\u5b50\uff0c\u5e76\u5728\u5f97\u5206\u4e0a\u52a0 1 \u5206\u3002\u5f53\u5b58\u5728 \u4e24\u4e2a\u6216\u66f4\u591a \u7684\u7a7a\u5806\u65f6\uff0c\u6e38\u620f\u505c\u6b62\u3002

\n\n

\u7ed9\u4f60\u4e09\u4e2a\u6574\u6570 a \u3001b \u548c c \uff0c\u8fd4\u56de\u53ef\u4ee5\u5f97\u5230\u7684 \u6700\u5927\u5206\u6570 \u3002

\n\u00a0\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aa = 2, b = 4, c = 6\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u77f3\u5b50\u8d77\u59cb\u72b6\u6001\u662f (2, 4, 6) \uff0c\u6700\u4f18\u7684\u4e00\u7ec4\u64cd\u4f5c\u662f\uff1a\n- \u4ece\u7b2c\u4e00\u548c\u7b2c\u4e09\u5806\u53d6\uff0c\u77f3\u5b50\u72b6\u6001\u73b0\u5728\u662f (1, 4, 5)\n- \u4ece\u7b2c\u4e00\u548c\u7b2c\u4e09\u5806\u53d6\uff0c\u77f3\u5b50\u72b6\u6001\u73b0\u5728\u662f (0, 4, 4)\n- \u4ece\u7b2c\u4e8c\u548c\u7b2c\u4e09\u5806\u53d6\uff0c\u77f3\u5b50\u72b6\u6001\u73b0\u5728\u662f (0, 3, 3)\n- \u4ece\u7b2c\u4e8c\u548c\u7b2c\u4e09\u5806\u53d6\uff0c\u77f3\u5b50\u72b6\u6001\u73b0\u5728\u662f (0, 2, 2)\n- \u4ece\u7b2c\u4e8c\u548c\u7b2c\u4e09\u5806\u53d6\uff0c\u77f3\u5b50\u72b6\u6001\u73b0\u5728\u662f (0, 1, 1)\n- \u4ece\u7b2c\u4e8c\u548c\u7b2c\u4e09\u5806\u53d6\uff0c\u77f3\u5b50\u72b6\u6001\u73b0\u5728\u662f (0, 0, 0)\n\u603b\u5206\uff1a6 \u5206 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aa = 4, b = 4, c = 6\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\u77f3\u5b50\u8d77\u59cb\u72b6\u6001\u662f (4, 4, 6) \uff0c\u6700\u4f18\u7684\u4e00\u7ec4\u64cd\u4f5c\u662f\uff1a\n- \u4ece\u7b2c\u4e00\u548c\u7b2c\u4e8c\u5806\u53d6\uff0c\u77f3\u5b50\u72b6\u6001\u73b0\u5728\u662f (3, 3, 6)\n- \u4ece\u7b2c\u4e00\u548c\u7b2c\u4e09\u5806\u53d6\uff0c\u77f3\u5b50\u72b6\u6001\u73b0\u5728\u662f (2, 3, 5)\n- \u4ece\u7b2c\u4e00\u548c\u7b2c\u4e09\u5806\u53d6\uff0c\u77f3\u5b50\u72b6\u6001\u73b0\u5728\u662f (1, 3, 4)\n- \u4ece\u7b2c\u4e00\u548c\u7b2c\u4e09\u5806\u53d6\uff0c\u77f3\u5b50\u72b6\u6001\u73b0\u5728\u662f (0, 3, 3)\n- \u4ece\u7b2c\u4e8c\u548c\u7b2c\u4e09\u5806\u53d6\uff0c\u77f3\u5b50\u72b6\u6001\u73b0\u5728\u662f (0, 2, 2)\n- \u4ece\u7b2c\u4e8c\u548c\u7b2c\u4e09\u5806\u53d6\uff0c\u77f3\u5b50\u72b6\u6001\u73b0\u5728\u662f (0, 1, 1)\n- \u4ece\u7b2c\u4e8c\u548c\u7b2c\u4e09\u5806\u53d6\uff0c\u77f3\u5b50\u72b6\u6001\u73b0\u5728\u662f (0, 0, 0)\n\u603b\u5206\uff1a7 \u5206 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1aa = 1, b = 8, c = 8\n\u8f93\u51fa\uff1a8\n\u89e3\u91ca\uff1a\u6700\u4f18\u7684\u4e00\u7ec4\u64cd\u4f5c\u662f\u8fde\u7eed\u4ece\u7b2c\u4e8c\u548c\u7b2c\u4e09\u5806\u53d6 8 \u56de\u5408\uff0c\u76f4\u5230\u5c06\u5b83\u4eec\u53d6\u7a7a\u3002\n\u6ce8\u610f\uff0c\u7531\u4e8e\u7b2c\u4e8c\u548c\u7b2c\u4e09\u5806\u5df2\u7ecf\u7a7a\u4e86\uff0c\u6e38\u620f\u7ed3\u675f\uff0c\u4e0d\u80fd\u7ee7\u7eed\u4ece\u7b2c\u4e00\u5806\u4e2d\u53d6\u77f3\u5b50\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= a, b, c <= 105
  • \n
\n", "tags_en": ["Heap", "Math"], "tags_cn": ["\u5806", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maximumScore(int a, int b, int c) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maximumScore(int a, int b, int c) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximumScore(self, a, b, c):\n \"\"\"\n :type a: int\n :type b: int\n :type c: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximumScore(self, a: int, b: int, c: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maximumScore(int a, int b, int c){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaximumScore(int a, int b, int c) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} a\n * @param {number} b\n * @param {number} c\n * @return {number}\n */\nvar maximumScore = function(a, b, c) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} a\n# @param {Integer} b\n# @param {Integer} c\n# @return {Integer}\ndef maximum_score(a, b, c)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximumScore(_ a: Int, _ b: Int, _ c: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximumScore(a int, b int, c int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximumScore(a: Int, b: Int, c: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximumScore(a: Int, b: Int, c: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximum_score(a: i32, b: i32, c: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $a\n * @param Integer $b\n * @param Integer $c\n * @return Integer\n */\n function maximumScore($a, $b, $c) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximumScore(a: number, b: number, c: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximum-score a b c)\n (-> exact-integer? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1753](https://leetcode-cn.com/problems/maximum-score-from-removing-stones)", "[\u79fb\u9664\u77f3\u5b50\u7684\u6700\u5927\u5f97\u5206](/solution/1700-1799/1753.Maximum%20Score%20From%20Removing%20Stones/README.md)", "`\u5806`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1753](https://leetcode.com/problems/maximum-score-from-removing-stones)", "[Maximum Score From Removing Stones](/solution/1700-1799/1753.Maximum%20Score%20From%20Removing%20Stones/README_EN.md)", "`Heap`,`Math`", "Medium", ""]}, {"question_id": "1878", "frontend_question_id": "1752", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/check-if-array-is-sorted-and-rotated", "url_en": "https://leetcode.com/problems/check-if-array-is-sorted-and-rotated", "relative_path_cn": "/solution/1700-1799/1752.Check%20if%20Array%20Is%20Sorted%20and%20Rotated/README.md", "relative_path_en": "/solution/1700-1799/1752.Check%20if%20Array%20Is%20Sorted%20and%20Rotated/README_EN.md", "title_cn": "\u68c0\u67e5\u6570\u7ec4\u662f\u5426\u7ecf\u6392\u5e8f\u548c\u8f6e\u8f6c\u5f97\u5230", "title_en": "Check if Array Is Sorted and Rotated", "question_title_slug": "check-if-array-is-sorted-and-rotated", "content_en": "

Given an array nums, return true if the array was originally sorted in non-decreasing order, then rotated some number of positions (including zero). Otherwise, return false.

\n\n

There may be duplicates in the original array.

\n\n

Note: An array A rotated by x positions results in an array B of the same length such that A[i] == B[(i+x) % A.length], where % is the modulo operation.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [3,4,5,1,2]\nOutput: true\nExplanation: [1,2,3,4,5] is the original sorted array.\nYou can rotate the array by x = 3 positions to begin on the the element of value 3: [3,4,5,1,2].\n
\n\n

Example 2:

\n\n
\nInput: nums = [2,1,3,4]\nOutput: false\nExplanation: There is no sorted array once rotated that can make nums.\n
\n\n

Example 3:

\n\n
\nInput: nums = [1,2,3]\nOutput: true\nExplanation: [1,2,3] is the original sorted array.\nYou can rotate the array by x = 0 positions (i.e. no rotation) to make nums.\n
\n\n

Example 4:

\n\n
\nInput: nums = [1,1,1]\nOutput: true\nExplanation: [1,1,1] is the original sorted array.\nYou can rotate any number of positions to make nums.\n
\n\n

Example 5:

\n\n
\nInput: nums = [2,1]\nOutput: true\nExplanation: [1,2] is the original sorted array.\nYou can rotate the array by x = 5 positions to begin on the element of value 2: [2,1].\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 100
  • \n\t
  • 1 <= nums[i] <= 100
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 nums \u3002nums \u7684\u6e90\u6570\u7ec4\u4e2d\uff0c\u6240\u6709\u5143\u7d20\u4e0e nums \u76f8\u540c\uff0c\u4f46\u6309\u975e\u9012\u51cf\u987a\u5e8f\u6392\u5217\u3002

\n\n

\u5982\u679c\u00a0nums \u80fd\u591f\u7531\u6e90\u6570\u7ec4\u8f6e\u8f6c\u82e5\u5e72\u4f4d\u7f6e\uff08\u5305\u62ec 0 \u4e2a\u4f4d\u7f6e\uff09\u5f97\u5230\uff0c\u5219\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

\n\n

\u6e90\u6570\u7ec4\u4e2d\u53ef\u80fd\u5b58\u5728 \u91cd\u590d\u9879 \u3002

\n\n

\u6ce8\u610f\uff1a\u6211\u4eec\u79f0\u6570\u7ec4 A \u5728\u8f6e\u8f6c x \u4e2a\u4f4d\u7f6e\u540e\u5f97\u5230\u957f\u5ea6\u76f8\u540c\u7684\u6570\u7ec4 B \uff0c\u5f53\u5b83\u4eec\u6ee1\u8db3 A[i] == B[(i+x) % A.length] \uff0c\u5176\u4e2d % \u4e3a\u53d6\u4f59\u8fd0\u7b97\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [3,4,5,1,2]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a[1,2,3,4,5] \u4e3a\u6709\u5e8f\u7684\u6e90\u6570\u7ec4\u3002\n\u53ef\u4ee5\u8f6e\u8f6c x = 3 \u4e2a\u4f4d\u7f6e\uff0c\u4f7f\u65b0\u6570\u7ec4\u4ece\u503c\u4e3a 3 \u7684\u5143\u7d20\u5f00\u59cb\uff1a[3,4,5,1,2] \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [2,1,3,4]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u6e90\u6570\u7ec4\u65e0\u6cd5\u7ecf\u8f6e\u8f6c\u5f97\u5230 nums \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [1,2,3]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a[1,2,3] \u4e3a\u6709\u5e8f\u7684\u6e90\u6570\u7ec4\u3002\n\u53ef\u4ee5\u8f6e\u8f6c x = 0 \u4e2a\u4f4d\u7f6e\uff08\u5373\u4e0d\u8f6e\u8f6c\uff09\u5f97\u5230 nums \u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [1,1,1]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a[1,1,1] \u4e3a\u6709\u5e8f\u7684\u6e90\u6570\u7ec4\u3002\n\u8f6e\u8f6c\u4efb\u610f\u4e2a\u4f4d\u7f6e\u90fd\u53ef\u4ee5\u5f97\u5230 nums \u3002\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [2,1]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a[1,2] \u4e3a\u6709\u5e8f\u7684\u6e90\u6570\u7ec4\u3002\n\u53ef\u4ee5\u8f6e\u8f6c x = 5 \u4e2a\u4f4d\u7f6e\uff0c\u4f7f\u65b0\u6570\u7ec4\u4ece\u503c\u4e3a 2 \u7684\u5143\u7d20\u5f00\u59cb\uff1a[2,1] \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 100
  • \n\t
  • 1 <= nums[i] <= 100
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool check(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean check(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def check(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def check(self, nums: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool check(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool Check(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {boolean}\n */\nvar check = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Boolean}\ndef check(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func check(_ nums: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func check(nums []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def check(nums: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun check(nums: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn check(nums: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Boolean\n */\n function check($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function check(nums: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (check nums)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1752](https://leetcode-cn.com/problems/check-if-array-is-sorted-and-rotated)", "[\u68c0\u67e5\u6570\u7ec4\u662f\u5426\u7ecf\u6392\u5e8f\u548c\u8f6e\u8f6c\u5f97\u5230](/solution/1700-1799/1752.Check%20if%20Array%20Is%20Sorted%20and%20Rotated/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1752](https://leetcode.com/problems/check-if-array-is-sorted-and-rotated)", "[Check if Array Is Sorted and Rotated](/solution/1700-1799/1752.Check%20if%20Array%20Is%20Sorted%20and%20Rotated/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1877", "frontend_question_id": "1729", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/find-followers-count", "url_en": "https://leetcode.com/problems/find-followers-count", "relative_path_cn": "/solution/1700-1799/1729.Find%20Followers%20Count/README.md", "relative_path_en": "/solution/1700-1799/1729.Find%20Followers%20Count/README_EN.md", "title_cn": "\u6c42\u5173\u6ce8\u8005\u7684\u6570\u91cf", "title_en": "Find Followers Count", "question_title_slug": "find-followers-count", "content_en": "

Table: Followers

\n\n
\n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| user_id     | int  |\n| follower_id | int  |\n+-------------+------+\n(user_id, follower_id) is the primary key for this table.\nThis table contains the IDs of a user and a follower in a social media app where the follower follows the user.
\n\n

Write an SQL query that will, for each user, return the number of followers.

\n\n

Return the result table ordered by user_id.

\n\n

The query result format is in the following example:

\n\n

 

\n\n
\nFollowers table:\n+---------+-------------+\n| user_id | follower_id |\n+---------+-------------+\n| 0       | 1           |\n| 1       | 0           |\n| 2       | 0           |\n| 2       | 1           |\n+---------+-------------+\nResult table:\n+---------+----------------+\n| user_id | followers_count|\n+---------+----------------+\n| 0       | 1              |\n| 1       | 1              |\n| 2       | 2              |\n+---------+----------------+\nThe followers of 0 are {1}\nThe followers of 1 are {0}\nThe followers of 2 are {0,1}\n
\n\n

 

\n", "content_cn": "

\u8868\uff1a\u00a0Followers

\n\n
+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| user_id     | int  |\n| follower_id | int  |\n+-------------+------+\n(user_id, follower_id) \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\u3002\n\u8be5\u8868\u5305\u542b\u4e00\u4e2a\u5173\u6ce8\u5173\u7cfb\u4e2d\u5173\u6ce8\u8005\u548c\u7528\u6237\u7684\u7f16\u53f7\uff0c\u5176\u4e2d\u5173\u6ce8\u8005\u5173\u6ce8\u7528\u6237\u3002
\n\n

\u5199\u51fa SQL \u8bed\u53e5\uff0c\u5bf9\u4e8e\u6bcf\u4e00\u4e2a\u7528\u6237\uff0c\u8fd4\u56de\u8be5\u7528\u6237\u7684\u5173\u6ce8\u8005\u6570\u91cf\u3002

\n\n

\u6309\u00a0user_id\u00a0\u7684\u987a\u5e8f\u8fd4\u56de\u7ed3\u679c\u8868\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u7684\u683c\u5f0f\u5982\u4e0b\u793a\u4f8b\u6240\u793a\uff1a

\n\n

\u00a0

\n\n
Followers \u8868\uff1a\n+---------+-------------+\n| user_id | follower_id |\n+---------+-------------+\n| 0       | 1           |\n| 1       | 0           |\n| 2       | 0           |\n| 2       | 1           |\n+---------+-------------+\n\u7ed3\u679c\u8868\uff1a\n+---------+----------------+\n| user_id | followers_count|\n+---------+----------------+\n| 0       | 1              |\n| 1       | 1              |\n| 2       | 2              |\n+---------+----------------+\n0 \u7684\u5173\u6ce8\u8005\u6709 {1}\n1 \u7684\u5173\u6ce8\u8005\u6709 {0}\n2 \u7684\u5173\u6ce8\u8005\u6709 {0,1}\n
\n\n

\u00a0

\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1729](https://leetcode-cn.com/problems/find-followers-count)", "[\u6c42\u5173\u6ce8\u8005\u7684\u6570\u91cf](/solution/1700-1799/1729.Find%20Followers%20Count/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1729](https://leetcode.com/problems/find-followers-count)", "[Find Followers Count](/solution/1700-1799/1729.Find%20Followers%20Count/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1876", "frontend_question_id": "1765", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/map-of-highest-peak", "url_en": "https://leetcode.com/problems/map-of-highest-peak", "relative_path_cn": "/solution/1700-1799/1765.Map%20of%20Highest%20Peak/README.md", "relative_path_en": "/solution/1700-1799/1765.Map%20of%20Highest%20Peak/README_EN.md", "title_cn": "\u5730\u56fe\u4e2d\u7684\u6700\u9ad8\u70b9", "title_en": "Map of Highest Peak", "question_title_slug": "map-of-highest-peak", "content_en": "

You are given an integer matrix isWater of size m x n that represents a map of land and water cells.

\n\n
    \n\t
  • If isWater[i][j] == 0, cell (i, j) is a land cell.
  • \n\t
  • If isWater[i][j] == 1, cell (i, j) is a water cell.
  • \n
\n\n

You must assign each cell a height in a way that follows these rules:

\n\n
    \n\t
  • The height of each cell must be non-negative.
  • \n\t
  • If the cell is a water cell, its height must be 0.
  • \n\t
  • Any two adjacent cells must have an absolute height difference of at most 1. A cell is adjacent to another cell if the former is directly north, east, south, or west of the latter (i.e., their sides are touching).
  • \n
\n\n

Find an assignment of heights such that the maximum height in the matrix is maximized.

\n\n

Return an integer matrix height of size m x n where height[i][j] is cell (i, j)'s height. If there are multiple solutions, return any of them.

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: isWater = [[0,1],[0,0]]\nOutput: [[1,0],[2,1]]\nExplanation: The image shows the assigned heights of each cell.\nThe blue cell is the water cell, and the green cells are the land cells.\n
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: isWater = [[0,0,1],[1,0,0],[0,0,0]]\nOutput: [[1,1,0],[0,1,1],[1,2,2]]\nExplanation: A height of 2 is the maximum possible height of any assignment.\nAny height assignment that has a maximum height of 2 while still meeting the rules will also be accepted.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • m == isWater.length
  • \n\t
  • n == isWater[i].length
  • \n\t
  • 1 <= m, n <= 1000
  • \n\t
  • isWater[i][j] is 0 or 1.
  • \n\t
  • There is at least one water cell.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5927\u5c0f\u4e3a\u00a0m x n\u00a0\u7684\u6574\u6570\u77e9\u9635\u00a0isWater\u00a0\uff0c\u5b83\u4ee3\u8868\u4e86\u4e00\u4e2a\u7531 \u9646\u5730\u00a0\u548c \u6c34\u57df\u00a0\u5355\u5143\u683c\u7ec4\u6210\u7684\u5730\u56fe\u3002

\n\n
    \n\t
  • \u5982\u679c\u00a0isWater[i][j] == 0\u00a0\uff0c\u683c\u5b50\u00a0(i, j)\u00a0\u662f\u4e00\u4e2a \u9646\u5730\u00a0\u683c\u5b50\u3002
  • \n\t
  • \u5982\u679c\u00a0isWater[i][j] == 1\u00a0\uff0c\u683c\u5b50\u00a0(i, j)\u00a0\u662f\u4e00\u4e2a \u6c34\u57df\u00a0\u683c\u5b50\u3002
  • \n
\n\n

\u4f60\u9700\u8981\u6309\u7167\u5982\u4e0b\u89c4\u5219\u7ed9\u6bcf\u4e2a\u5355\u5143\u683c\u5b89\u6392\u9ad8\u5ea6\uff1a

\n\n
    \n\t
  • \u6bcf\u4e2a\u683c\u5b50\u7684\u9ad8\u5ea6\u90fd\u5fc5\u987b\u662f\u975e\u8d1f\u7684\u3002
  • \n\t
  • \u5982\u679c\u4e00\u4e2a\u683c\u5b50\u662f\u662f \u6c34\u57df\u00a0\uff0c\u90a3\u4e48\u5b83\u7684\u9ad8\u5ea6\u5fc5\u987b\u4e3a 0\u00a0\u3002
  • \n\t
  • \u4efb\u610f\u76f8\u90bb\u7684\u683c\u5b50\u9ad8\u5ea6\u5dee \u81f3\u591a\u00a0\u4e3a 1\u00a0\u3002\u5f53\u4e24\u4e2a\u683c\u5b50\u5728\u6b63\u4e1c\u3001\u5357\u3001\u897f\u3001\u5317\u65b9\u5411\u4e0a\u76f8\u4e92\u7d27\u6328\u7740\uff0c\u5c31\u79f0\u5b83\u4eec\u4e3a\u76f8\u90bb\u7684\u683c\u5b50\u3002\uff08\u4e5f\u5c31\u662f\u8bf4\u5b83\u4eec\u6709\u4e00\u6761\u516c\u5171\u8fb9\uff09
  • \n
\n\n

\u627e\u5230\u4e00\u79cd\u5b89\u6392\u9ad8\u5ea6\u7684\u65b9\u6848\uff0c\u4f7f\u5f97\u77e9\u9635\u4e2d\u7684\u6700\u9ad8\u9ad8\u5ea6\u503c\u00a0\u6700\u5927\u00a0\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u4e00\u4e2a\u5927\u5c0f\u4e3a\u00a0m x n\u00a0\u7684\u6574\u6570\u77e9\u9635 height\u00a0\uff0c\u5176\u4e2d height[i][j]\u00a0\u662f\u683c\u5b50 (i, j)\u00a0\u7684\u9ad8\u5ea6\u3002\u5982\u679c\u6709\u591a\u79cd\u89e3\u6cd5\uff0c\u8bf7\u8fd4\u56de\u00a0\u4efb\u610f\u4e00\u4e2a\u00a0\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1aisWater = [[0,1],[0,0]]\n\u8f93\u51fa\uff1a[[1,0],[2,1]]\n\u89e3\u91ca\uff1a\u4e0a\u56fe\u5c55\u793a\u4e86\u7ed9\u5404\u4e2a\u683c\u5b50\u5b89\u6392\u7684\u9ad8\u5ea6\u3002\n\u84dd\u8272\u683c\u5b50\u662f\u6c34\u57df\u683c\uff0c\u7eff\u8272\u683c\u5b50\u662f\u9646\u5730\u683c\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1aisWater = [[0,0,1],[1,0,0],[0,0,0]]\n\u8f93\u51fa\uff1a[[1,1,0],[0,1,1],[1,2,2]]\n\u89e3\u91ca\uff1a\u6240\u6709\u5b89\u6392\u65b9\u6848\u4e2d\uff0c\u6700\u9ad8\u53ef\u884c\u9ad8\u5ea6\u4e3a 2 \u3002\n\u4efb\u610f\u5b89\u6392\u65b9\u6848\u4e2d\uff0c\u53ea\u8981\u6700\u9ad8\u9ad8\u5ea6\u4e3a 2 \u4e14\u7b26\u5408\u4e0a\u8ff0\u89c4\u5219\u7684\uff0c\u90fd\u4e3a\u53ef\u884c\u65b9\u6848\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • m == isWater.length
  • \n\t
  • n == isWater[i].length
  • \n\t
  • 1 <= m, n <= 1000
  • \n\t
  • isWater[i][j]\u00a0\u8981\u4e48\u662f\u00a00\u00a0\uff0c\u8981\u4e48\u662f\u00a01\u00a0\u3002
  • \n\t
  • \u81f3\u5c11\u6709 1\u00a0\u4e2a\u6c34\u57df\u683c\u5b50\u3002
  • \n
\n", "tags_en": ["Breadth-first Search", "Graph"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> highestPeak(vector>& isWater) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[][] highestPeak(int[][] isWater) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def highestPeak(self, isWater):\n \"\"\"\n :type isWater: List[List[int]]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def highestPeak(self, isWater: List[List[int]]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** highestPeak(int** isWater, int isWaterSize, int* isWaterColSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[][] HighestPeak(int[][] isWater) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} isWater\n * @return {number[][]}\n */\nvar highestPeak = function(isWater) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} is_water\n# @return {Integer[][]}\ndef highest_peak(is_water)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func highestPeak(_ isWater: [[Int]]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func highestPeak(isWater [][]int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def highestPeak(isWater: Array[Array[Int]]): Array[Array[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun highestPeak(isWater: Array): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn highest_peak(is_water: Vec>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $isWater\n * @return Integer[][]\n */\n function highestPeak($isWater) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function highestPeak(isWater: number[][]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (highest-peak isWater)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1765](https://leetcode-cn.com/problems/map-of-highest-peak)", "[\u5730\u56fe\u4e2d\u7684\u6700\u9ad8\u70b9](/solution/1700-1799/1765.Map%20of%20Highest%20Peak/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u56fe`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1765](https://leetcode.com/problems/map-of-highest-peak)", "[Map of Highest Peak](/solution/1700-1799/1765.Map%20of%20Highest%20Peak/README_EN.md)", "`Breadth-first Search`,`Graph`", "Medium", ""]}, {"question_id": "1875", "frontend_question_id": "1766", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/tree-of-coprimes", "url_en": "https://leetcode.com/problems/tree-of-coprimes", "relative_path_cn": "/solution/1700-1799/1766.Tree%20of%20Coprimes/README.md", "relative_path_en": "/solution/1700-1799/1766.Tree%20of%20Coprimes/README_EN.md", "title_cn": "\u4e92\u8d28\u6811", "title_en": "Tree of Coprimes", "question_title_slug": "tree-of-coprimes", "content_en": "

There is a tree (i.e., a connected, undirected graph that has no cycles) consisting of n nodes numbered from 0 to n - 1 and exactly n - 1 edges. Each node has a value associated with it, and the root of the tree is node 0.

\n\n

To represent this tree, you are given an integer array nums and a 2D array edges. Each nums[i] represents the ith node's value, and each edges[j] = [uj, vj] represents an edge between nodes uj and vj in the tree.

\n\n

Two values x and y are coprime if gcd(x, y) == 1 where gcd(x, y) is the greatest common divisor of x and y.

\n\n

An ancestor of a node i is any other node on the shortest path from node i to the root. A node is not considered an ancestor of itself.

\n\n

Return an array ans of size n, where ans[i] is the closest ancestor to node i such that nums[i] and nums[ans[i]] are coprime, or -1 if there is no such ancestor.

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: nums = [2,3,3,2], edges = [[0,1],[1,2],[1,3]]\nOutput: [-1,0,0,1]\nExplanation: In the above figure, each node's value is in parentheses.\n- Node 0 has no coprime ancestors.\n- Node 1 has only one ancestor, node 0. Their values are coprime (gcd(2,3) == 1).\n- Node 2 has two ancestors, nodes 1 and 0. Node 1's value is not coprime (gcd(3,3) == 3), but node 0's\n  value is (gcd(2,3) == 1), so node 0 is the closest valid ancestor.\n- Node 3 has two ancestors, nodes 1 and 0. It is coprime with node 1 (gcd(3,2) == 1), so node 1 is its\n  closest valid ancestor.\n
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: nums = [5,6,10,2,3,6,15], edges = [[0,1],[0,2],[1,3],[1,4],[2,5],[2,6]]\nOutput: [-1,0,-1,0,0,0,-1]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • nums.length == n
  • \n\t
  • 1 <= nums[i] <= 50
  • \n\t
  • 1 <= n <= 105
  • \n\t
  • edges.length == n - 1
  • \n\t
  • edges[j].length == 2
  • \n\t
  • 0 <= uj, vj < n
  • \n\t
  • uj != vj
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a n\u00a0\u4e2a\u8282\u70b9\u7684\u6811\uff08\u4e5f\u5c31\u662f\u4e00\u4e2a\u65e0\u73af\u8fde\u901a\u65e0\u5411\u56fe\uff09\uff0c\u8282\u70b9\u7f16\u53f7\u4ece 0\u00a0\u5230 n - 1\u00a0\uff0c\u4e14\u6070\u597d\u6709 n - 1\u00a0\u6761\u8fb9\uff0c\u6bcf\u4e2a\u8282\u70b9\u6709\u4e00\u4e2a\u503c\u3002\u6811\u7684 \u6839\u8282\u70b9\u00a0\u4e3a 0 \u53f7\u70b9\u3002

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0nums\u00a0\u548c\u4e00\u4e2a\u4e8c\u7ef4\u6570\u7ec4\u00a0edges\u00a0\u6765\u8868\u793a\u8fd9\u68f5\u6811\u3002nums[i]\u00a0\u8868\u793a\u7b2c\u00a0i\u00a0\u4e2a\u70b9\u7684\u503c\uff0cedges[j] = [uj, vj]\u00a0\u8868\u793a\u8282\u70b9\u00a0uj\u00a0\u548c\u8282\u70b9\u00a0vj\u00a0\u5728\u6811\u4e2d\u6709\u4e00\u6761\u8fb9\u3002

\n\n

\u5f53\u00a0gcd(x, y) == 1\u00a0\uff0c\u6211\u4eec\u79f0\u4e24\u4e2a\u6570\u00a0x \u548c\u00a0y\u00a0\u662f \u4e92\u8d28\u7684\u00a0\uff0c\u5176\u4e2d\u00a0gcd(x, y)\u00a0\u662f x\u00a0\u548c y\u00a0\u7684 \u6700\u5927\u516c\u7ea6\u6570\u00a0\u3002

\n\n

\u4ece\u8282\u70b9\u00a0i\u00a0\u5230 \u6839\u00a0\u6700\u77ed\u8def\u5f84\u4e0a\u7684\u70b9\u90fd\u662f\u8282\u70b9 i\u00a0\u7684\u7956\u5148\u8282\u70b9\u3002\u4e00\u4e2a\u8282\u70b9 \u4e0d\u662f \u5b83\u81ea\u5df1\u7684\u7956\u5148\u8282\u70b9\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u4e00\u4e2a\u5927\u5c0f\u4e3a n\u00a0\u7684\u6570\u7ec4 ans\u00a0\uff0c\u5176\u4e2d\u00a0ans[i]\u662f\u79bb\u8282\u70b9\u00a0i\u00a0\u6700\u8fd1\u7684\u7956\u5148\u8282\u70b9\u4e14\u6ee1\u8db3\u00a0nums[i] \u548c\u00a0nums[ans[i]]\u00a0\u662f \u4e92\u8d28\u7684\u00a0\uff0c\u5982\u679c\u4e0d\u5b58\u5728\u8fd9\u6837\u7684\u7956\u5148\u8282\u70b9\uff0cans[i]\u00a0\u4e3a -1\u00a0\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1anums = [2,3,3,2], edges = [[0,1],[1,2],[1,3]]\n\u8f93\u51fa\uff1a[-1,0,0,1]\n\u89e3\u91ca\uff1a\u4e0a\u56fe\u4e2d\uff0c\u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u5728\u62ec\u53f7\u4e2d\u8868\u793a\u3002\n- \u8282\u70b9 0 \u6ca1\u6709\u4e92\u8d28\u7956\u5148\u3002\n- \u8282\u70b9 1 \u53ea\u6709\u4e00\u4e2a\u7956\u5148\u8282\u70b9 0 \u3002\u5b83\u4eec\u7684\u503c\u662f\u4e92\u8d28\u7684\uff08gcd(2,3) == 1\uff09\u3002\n- \u8282\u70b9 2 \u6709\u4e24\u4e2a\u7956\u5148\u8282\u70b9\uff0c\u5206\u522b\u662f\u8282\u70b9 1 \u548c\u8282\u70b9 0 \u3002\u8282\u70b9 1 \u7684\u503c\u4e0e\u5b83\u7684\u503c\u4e0d\u662f\u4e92\u8d28\u7684\uff08gcd(3,3) == 3\uff09\u4f46\u8282\u70b9 0 \u7684\u503c\u662f\u4e92\u8d28\u7684(gcd(2,3) == 1)\uff0c\u6240\u4ee5\u8282\u70b9 0 \u662f\u6700\u8fd1\u7684\u7b26\u5408\u8981\u6c42\u7684\u7956\u5148\u8282\u70b9\u3002\n- \u8282\u70b9 3 \u6709\u4e24\u4e2a\u7956\u5148\u8282\u70b9\uff0c\u5206\u522b\u662f\u8282\u70b9 1 \u548c\u8282\u70b9 0 \u3002\u5b83\u4e0e\u8282\u70b9 1 \u4e92\u8d28\uff08gcd(3,2) == 1\uff09\uff0c\u6240\u4ee5\u8282\u70b9 1 \u662f\u79bb\u5b83\u6700\u8fd1\u7684\u7b26\u5408\u8981\u6c42\u7684\u7956\u5148\u8282\u70b9\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1anums = [5,6,10,2,3,6,15], edges = [[0,1],[0,2],[1,3],[1,4],[2,5],[2,6]]\n\u8f93\u51fa\uff1a[-1,0,-1,0,0,0,-1]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • nums.length == n
  • \n\t
  • 1 <= nums[i] <= 50
  • \n\t
  • 1 <= n <= 105
  • \n\t
  • edges.length == n - 1
  • \n\t
  • edges[j].length == 2
  • \n\t
  • 0 <= uj, vj < n
  • \n\t
  • uj != vj
  • \n
\n", "tags_en": ["Tree", "Depth-first Search", "Breadth-first Search", "Math"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector getCoprimes(vector& nums, vector>& edges) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] getCoprimes(int[] nums, int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getCoprimes(self, nums, edges):\n \"\"\"\n :type nums: List[int]\n :type edges: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getCoprimes(self, nums: List[int], edges: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* getCoprimes(int* nums, int numsSize, int** edges, int edgesSize, int* edgesColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] GetCoprimes(int[] nums, int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number[][]} edges\n * @return {number[]}\n */\nvar getCoprimes = function(nums, edges) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer[][]} edges\n# @return {Integer[]}\ndef get_coprimes(nums, edges)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getCoprimes(_ nums: [Int], _ edges: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getCoprimes(nums []int, edges [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getCoprimes(nums: Array[Int], edges: Array[Array[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getCoprimes(nums: IntArray, edges: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_coprimes(nums: Vec, edges: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer[][] $edges\n * @return Integer[]\n */\n function getCoprimes($nums, $edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getCoprimes(nums: number[], edges: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-coprimes nums edges)\n (-> (listof exact-integer?) (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1766](https://leetcode-cn.com/problems/tree-of-coprimes)", "[\u4e92\u8d28\u6811](/solution/1700-1799/1766.Tree%20of%20Coprimes/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[1766](https://leetcode.com/problems/tree-of-coprimes)", "[Tree of Coprimes](/solution/1700-1799/1766.Tree%20of%20Coprimes/README_EN.md)", "`Tree`,`Depth-first Search`,`Breadth-first Search`,`Math`", "Hard", ""]}, {"question_id": "1874", "frontend_question_id": "1764", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/form-array-by-concatenating-subarrays-of-another-array", "url_en": "https://leetcode.com/problems/form-array-by-concatenating-subarrays-of-another-array", "relative_path_cn": "/solution/1700-1799/1764.Form%20Array%20by%20Concatenating%20Subarrays%20of%20Another%20Array/README.md", "relative_path_en": "/solution/1700-1799/1764.Form%20Array%20by%20Concatenating%20Subarrays%20of%20Another%20Array/README_EN.md", "title_cn": "\u901a\u8fc7\u8fde\u63a5\u53e6\u4e00\u4e2a\u6570\u7ec4\u7684\u5b50\u6570\u7ec4\u5f97\u5230\u4e00\u4e2a\u6570\u7ec4", "title_en": "Form Array by Concatenating Subarrays of Another Array", "question_title_slug": "form-array-by-concatenating-subarrays-of-another-array", "content_en": "

You are given a 2D integer array groups of length n. You are also given an integer array nums.

\n\n

You are asked if you can choose n disjoint subarrays from the array nums such that the ith subarray is equal to groups[i] (0-indexed), and if i > 0, the (i-1)th subarray appears before the ith subarray in nums (i.e. the subarrays must be in the same order as groups).

\n\n

Return true if you can do this task, and false otherwise.

\n\n

Note that the subarrays are disjoint if and only if there is no index k such that nums[k] belongs to more than one subarray. A subarray is a contiguous sequence of elements within an array.

\n\n

 

\n

Example 1:

\n\n
\nInput: groups = [[1,-1,-1],[3,-2,0]], nums = [1,-1,0,1,-1,-1,3,-2,0]\nOutput: true\nExplanation: You can choose the 0th subarray as [1,-1,0,1,-1,-1,3,-2,0] and the 1st one as [1,-1,0,1,-1,-1,3,-2,0].\nThese subarrays are disjoint as they share no common nums[k] element.\n
\n\n

Example 2:

\n\n
\nInput: groups = [[10,-2],[1,2,3,4]], nums = [1,2,3,4,10,-2]\nOutput: false\nExplanation: Note that choosing the subarrays [1,2,3,4,10,-2] and [1,2,3,4,10,-2] is incorrect because they are not in the same order as in groups.\n[10,-2] must come before [1,2,3,4].\n
\n\n

Example 3:

\n\n
\nInput: groups = [[1,2,3],[3,4]], nums = [7,7,1,2,3,4,7,7]\nOutput: false\nExplanation: Note that choosing the subarrays [7,7,1,2,3,4,7,7] and [7,7,1,2,3,4,7,7] is invalid because they are not disjoint.\nThey share a common elements nums[4] (0-indexed).\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • groups.length == n
  • \n\t
  • 1 <= n <= 103
  • \n\t
  • 1 <= groups[i].length, sum(groups[i].length) <= 103
  • \n\t
  • 1 <= nums.length <= 103
  • \n\t
  • -107 <= groups[i][j], nums[k] <= 107
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u4e3a n\u00a0\u7684\u4e8c\u7ef4\u6574\u6570\u6570\u7ec4\u00a0groups\u00a0\uff0c\u540c\u65f6\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0nums\u00a0\u3002

\n\n

\u4f60\u662f\u5426\u53ef\u4ee5\u4ece nums\u00a0\u4e2d\u9009\u51fa n\u00a0\u4e2a \u4e0d\u76f8\u4ea4 \u7684\u5b50\u6570\u7ec4\uff0c\u4f7f\u5f97\u7b2c i\u00a0\u4e2a\u5b50\u6570\u7ec4\u4e0e groups[i]\u00a0\uff08\u4e0b\u6807\u4ece 0\u00a0\u5f00\u59cb\uff09\u5b8c\u5168\u76f8\u540c\uff0c\u4e14\u5982\u679c\u00a0i > 0\u00a0\uff0c\u90a3\u4e48\u7b2c\u00a0(i-1)\u00a0\u4e2a\u5b50\u6570\u7ec4\u5728 nums\u00a0\u4e2d\u51fa\u73b0\u7684\u4f4d\u7f6e\u5728\u7b2c i\u00a0\u4e2a\u5b50\u6570\u7ec4\u524d\u9762\u3002\uff08\u4e5f\u5c31\u662f\u8bf4\uff0c\u8fd9\u4e9b\u5b50\u6570\u7ec4\u5728 nums\u00a0\u4e2d\u51fa\u73b0\u7684\u987a\u5e8f\u9700\u8981\u4e0e groups \u987a\u5e8f\u76f8\u540c\uff09

\n\n

\u5982\u679c\u4f60\u53ef\u4ee5\u627e\u51fa\u8fd9\u6837\u7684 n \u4e2a\u5b50\u6570\u7ec4\uff0c\u8bf7\u4f60\u8fd4\u56de\u00a0true \uff0c\u5426\u5219\u8fd4\u56de\u00a0false\u00a0\u3002

\n\n

\u5982\u679c\u4e0d\u5b58\u5728\u4e0b\u6807\u4e3a k\u00a0\u7684\u5143\u7d20 nums[k]\u00a0\u5c5e\u4e8e\u4e0d\u6b62\u4e00\u4e2a\u5b50\u6570\u7ec4\uff0c\u5c31\u79f0\u8fd9\u4e9b\u5b50\u6570\u7ec4\u662f \u4e0d\u76f8\u4ea4 \u7684\u3002\u5b50\u6570\u7ec4\u6307\u7684\u662f\u539f\u6570\u7ec4\u4e2d\u8fde\u7eed\u5143\u7d20\u7ec4\u6210\u7684\u4e00\u4e2a\u5e8f\u5217\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1agroups = [[1,-1,-1],[3,-2,0]], nums = [1,-1,0,1,-1,-1,3,-2,0]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u5206\u522b\u5728 nums \u4e2d\u9009\u51fa\u7b2c 0 \u4e2a\u5b50\u6570\u7ec4 [1,-1,0,1,-1,-1,3,-2,0] \u548c\u7b2c 1 \u4e2a\u5b50\u6570\u7ec4 [1,-1,0,1,-1,-1,3,-2,0] \u3002\n\u8fd9\u4e24\u4e2a\u5b50\u6570\u7ec4\u662f\u4e0d\u76f8\u4ea4\u7684\uff0c\u56e0\u4e3a\u5b83\u4eec\u6ca1\u6709\u4efb\u4f55\u5171\u540c\u7684\u5143\u7d20\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1agroups = [[10,-2],[1,2,3,4]], nums = [1,2,3,4,10,-2]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u9009\u62e9\u5b50\u6570\u7ec4 [1,2,3,4,10,-2] \u548c [1,2,3,4,10,-2] \u662f\u4e0d\u6b63\u786e\u7684\uff0c\u56e0\u4e3a\u5b83\u4eec\u51fa\u73b0\u7684\u987a\u5e8f\u4e0e groups \u4e2d\u987a\u5e8f\u4e0d\u540c\u3002\n[10,-2] \u5fc5\u987b\u51fa\u73b0\u5728 [1,2,3,4] \u4e4b\u524d\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1agroups = [[1,2,3],[3,4]], nums = [7,7,1,2,3,4,7,7]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u9009\u62e9\u5b50\u6570\u7ec4 [7,7,1,2,3,4,7,7] \u548c [7,7,1,2,3,4,7,7] \u662f\u4e0d\u6b63\u786e\u7684\uff0c\u56e0\u4e3a\u5b83\u4eec\u4e0d\u662f\u4e0d\u76f8\u4ea4\u5b50\u6570\u7ec4\u3002\n\u5b83\u4eec\u6709\u4e00\u4e2a\u5171\u540c\u7684\u5143\u7d20 nums[4] \uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • groups.length == n
  • \n\t
  • 1 <= n <= 103
  • \n\t
  • 1 <= groups[i].length, sum(groups[i].length) <= 103
  • \n\t
  • 1 <= nums.length <= 103
  • \n\t
  • -107 <= groups[i][j], nums[k] <= 107
  • \n
\n", "tags_en": ["Greedy", "Array"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canChoose(vector>& groups, vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canChoose(int[][] groups, int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canChoose(self, groups, nums):\n \"\"\"\n :type groups: List[List[int]]\n :type nums: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canChoose(self, groups: List[List[int]], nums: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canChoose(int** groups, int groupsSize, int* groupsColSize, int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanChoose(int[][] groups, int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} groups\n * @param {number[]} nums\n * @return {boolean}\n */\nvar canChoose = function(groups, nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} groups\n# @param {Integer[]} nums\n# @return {Boolean}\ndef can_choose(groups, nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canChoose(_ groups: [[Int]], _ nums: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canChoose(groups [][]int, nums []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canChoose(groups: Array[Array[Int]], nums: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canChoose(groups: Array, nums: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_choose(groups: Vec>, nums: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $groups\n * @param Integer[] $nums\n * @return Boolean\n */\n function canChoose($groups, $nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canChoose(groups: number[][], nums: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-choose groups nums)\n (-> (listof (listof exact-integer?)) (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1764](https://leetcode-cn.com/problems/form-array-by-concatenating-subarrays-of-another-array)", "[\u901a\u8fc7\u8fde\u63a5\u53e6\u4e00\u4e2a\u6570\u7ec4\u7684\u5b50\u6570\u7ec4\u5f97\u5230\u4e00\u4e2a\u6570\u7ec4](/solution/1700-1799/1764.Form%20Array%20by%20Concatenating%20Subarrays%20of%20Another%20Array/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1764](https://leetcode.com/problems/form-array-by-concatenating-subarrays-of-another-array)", "[Form Array by Concatenating Subarrays of Another Array](/solution/1700-1799/1764.Form%20Array%20by%20Concatenating%20Subarrays%20of%20Another%20Array/README_EN.md)", "`Greedy`,`Array`", "Medium", ""]}, {"question_id": "1873", "frontend_question_id": "1763", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-nice-substring", "url_en": "https://leetcode.com/problems/longest-nice-substring", "relative_path_cn": "/solution/1700-1799/1763.Longest%20Nice%20Substring/README.md", "relative_path_en": "/solution/1700-1799/1763.Longest%20Nice%20Substring/README_EN.md", "title_cn": "\u6700\u957f\u7684\u7f8e\u597d\u5b50\u5b57\u7b26\u4e32", "title_en": "Longest Nice Substring", "question_title_slug": "longest-nice-substring", "content_en": "

A string s is nice if, for every letter of the alphabet that s contains, it appears both in uppercase and lowercase. For example, "abABB" is nice because 'A' and 'a' appear, and 'B' and 'b' appear. However, "abA" is not because 'b' appears, but 'B' does not.

\n\n

Given a string s, return the longest substring of s that is nice. If there are multiple, return the substring of the earliest occurrence. If there are none, return an empty string.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "YazaAay"\nOutput: "aAa"\nExplanation: "aAa" is a nice string because 'A/a' is the only letter of the alphabet in s, and both 'A' and 'a' appear.\n"aAa" is the longest nice substring.\n
\n\n

Example 2:

\n\n
\nInput: s = "Bb"\nOutput: "Bb"\nExplanation: "Bb" is a nice string because both 'B' and 'b' appear. The whole string is a substring.
\n\n

Example 3:

\n\n
\nInput: s = "c"\nOutput: ""\nExplanation: There are no nice substrings.
\n\n

Example 4:

\n\n
\nInput: s = "dDzeE"\nOutput: "dD"\nExplanation: Both "dD" and "eE" are the longest nice substrings.\nAs there are multiple longest nice substrings, return "dD" since it occurs earlier.
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 100
  • \n\t
  • s consists of uppercase and lowercase English letters.
  • \n
\n", "content_cn": "

\u5f53\u4e00\u4e2a\u5b57\u7b26\u4e32 s\u00a0\u5305\u542b\u7684\u6bcf\u4e00\u79cd\u5b57\u6bcd\u7684\u5927\u5199\u548c\u5c0f\u5199\u5f62\u5f0f \u540c\u65f6\u00a0\u51fa\u73b0\u5728 s\u00a0\u4e2d\uff0c\u5c31\u79f0\u8fd9\u4e2a\u5b57\u7b26\u4e32\u00a0s\u00a0\u662f \u7f8e\u597d \u5b57\u7b26\u4e32\u3002\u6bd4\u65b9\u8bf4\uff0c\"abABB\"\u00a0\u662f\u7f8e\u597d\u5b57\u7b26\u4e32\uff0c\u56e0\u4e3a\u00a0'A' \u548c\u00a0'a'\u00a0\u540c\u65f6\u51fa\u73b0\u4e86\uff0c\u4e14\u00a0'B' \u548c\u00a0'b'\u00a0\u4e5f\u540c\u65f6\u51fa\u73b0\u4e86\u3002\u7136\u800c\uff0c\"abA\"\u00a0\u4e0d\u662f\u7f8e\u597d\u5b57\u7b26\u4e32\u56e0\u4e3a\u00a0'b'\u00a0\u51fa\u73b0\u4e86\uff0c\u800c\u00a0'B'\u00a0\u6ca1\u6709\u51fa\u73b0\u3002

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32\u00a0s\u00a0\uff0c\u8bf7\u4f60\u8fd4\u56de\u00a0s\u00a0\u6700\u957f\u7684\u00a0\u7f8e\u597d\u5b50\u5b57\u7b26\u4e32\u00a0\u3002\u5982\u679c\u6709\u591a\u4e2a\u7b54\u6848\uff0c\u8bf7\u4f60\u8fd4\u56de\u00a0\u6700\u65e9\u00a0\u51fa\u73b0\u7684\u4e00\u4e2a\u3002\u5982\u679c\u4e0d\u5b58\u5728\u7f8e\u597d\u5b50\u5b57\u7b26\u4e32\uff0c\u8bf7\u4f60\u8fd4\u56de\u4e00\u4e2a\u7a7a\u5b57\u7b26\u4e32\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"YazaAay\"\n\u8f93\u51fa\uff1a\"aAa\"\n\u89e3\u91ca\uff1a\"aAa\" \u662f\u4e00\u4e2a\u7f8e\u597d\u5b57\u7b26\u4e32\uff0c\u56e0\u4e3a\u8fd9\u4e2a\u5b50\u4e32\u4e2d\u4ec5\u542b\u4e00\u79cd\u5b57\u6bcd\uff0c\u5176\u5c0f\u5199\u5f62\u5f0f 'a' \u548c\u5927\u5199\u5f62\u5f0f 'A' \u4e5f\u540c\u65f6\u51fa\u73b0\u4e86\u3002\n\"aAa\" \u662f\u6700\u957f\u7684\u7f8e\u597d\u5b50\u5b57\u7b26\u4e32\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"Bb\"\n\u8f93\u51fa\uff1a\"Bb\"\n\u89e3\u91ca\uff1a\"Bb\" \u662f\u7f8e\u597d\u5b57\u7b26\u4e32\uff0c\u56e0\u4e3a 'B' \u548c 'b' \u90fd\u51fa\u73b0\u4e86\u3002\u6574\u4e2a\u5b57\u7b26\u4e32\u4e5f\u662f\u539f\u5b57\u7b26\u4e32\u7684\u5b50\u5b57\u7b26\u4e32\u3002
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"c\"\n\u8f93\u51fa\uff1a\"\"\n\u89e3\u91ca\uff1a\u6ca1\u6709\u7f8e\u597d\u5b50\u5b57\u7b26\u4e32\u3002
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"dDzeE\"\n\u8f93\u51fa\uff1a\"dD\"\n\u89e3\u91ca\uff1a\"dD\" \u548c \"eE\" \u90fd\u662f\u6700\u957f\u7f8e\u597d\u5b50\u5b57\u7b26\u4e32\u3002\n\u7531\u4e8e\u6709\u591a\u4e2a\u7f8e\u597d\u5b50\u5b57\u7b26\u4e32\uff0c\u8fd4\u56de \"dD\" \uff0c\u56e0\u4e3a\u5b83\u51fa\u73b0\u5f97\u6700\u65e9\u3002
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length <= 100
  • \n\t
  • s\u00a0\u53ea\u5305\u542b\u5927\u5199\u548c\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string longestNiceSubstring(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String longestNiceSubstring(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestNiceSubstring(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestNiceSubstring(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * longestNiceSubstring(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string LongestNiceSubstring(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar longestNiceSubstring = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef longest_nice_substring(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestNiceSubstring(_ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestNiceSubstring(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestNiceSubstring(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestNiceSubstring(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_nice_substring(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function longestNiceSubstring($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestNiceSubstring(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-nice-substring s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1763](https://leetcode-cn.com/problems/longest-nice-substring)", "[\u6700\u957f\u7684\u7f8e\u597d\u5b50\u5b57\u7b26\u4e32](/solution/1700-1799/1763.Longest%20Nice%20Substring/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1763](https://leetcode.com/problems/longest-nice-substring)", "[Longest Nice Substring](/solution/1700-1799/1763.Longest%20Nice%20Substring/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1872", "frontend_question_id": "1744", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/can-you-eat-your-favorite-candy-on-your-favorite-day", "url_en": "https://leetcode.com/problems/can-you-eat-your-favorite-candy-on-your-favorite-day", "relative_path_cn": "/solution/1700-1799/1744.Can%20You%20Eat%20Your%20Favorite%20Candy%20on%20Your%20Favorite%20Day/README.md", "relative_path_en": "/solution/1700-1799/1744.Can%20You%20Eat%20Your%20Favorite%20Candy%20on%20Your%20Favorite%20Day/README_EN.md", "title_cn": "\u4f60\u80fd\u5728\u4f60\u6700\u559c\u6b22\u7684\u90a3\u5929\u5403\u5230\u4f60\u6700\u559c\u6b22\u7684\u7cd6\u679c\u5417\uff1f", "title_en": "Can You Eat Your Favorite Candy on Your Favorite Day", "question_title_slug": "can-you-eat-your-favorite-candy-on-your-favorite-day", "content_en": "

You are given a (0-indexed) array of positive integers candiesCount where candiesCount[i] represents the number of candies of the ith type you have. You are also given a 2D array queries where queries[i] = [favoriteTypei, favoriteDayi, dailyCapi].

\n\n

You play a game with the following rules:

\n\n
    \n\t
  • You start eating candies on day 0.
  • \n\t
  • You cannot eat any candy of type i unless you have eaten all candies of type i - 1.
  • \n\t
  • You must eat at least one candy per day until you have eaten all the candies.
  • \n
\n\n

Construct a boolean array answer such that answer.length == queries.length and answer[i] is true if you can eat a candy of type favoriteTypei on day favoriteDayi without eating more than dailyCapi candies on any day, and false otherwise. Note that you can eat different types of candy on the same day, provided that you follow rule 2.

\n\n

Return the constructed array answer.

\n\n

 

\n

Example 1:

\n\n
\nInput: candiesCount = [7,4,5,3,8], queries = [[0,2,2],[4,2,4],[2,13,1000000000]]\nOutput: [true,false,true]\nExplanation:\n1- If you eat 2 candies (type 0) on day 0 and 2 candies (type 0) on day 1, you will eat a candy of type 0 on day 2.\n2- You can eat at most 4 candies each day.\n   If you eat 4 candies every day, you will eat 4 candies (type 0) on day 0 and 4 candies (type 0 and type 1) on day 1.\n   On day 2, you can only eat 4 candies (type 1 and type 2), so you cannot eat a candy of type 4 on day 2.\n3- If you eat 1 candy each day, you will eat a candy of type 2 on day 13.\n
\n\n

Example 2:

\n\n
\nInput: candiesCount = [5,2,6,4,1], queries = [[3,1,2],[4,10,3],[3,10,100],[4,100,30],[1,3,1]]\nOutput: [false,true,true,false,false]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= candiesCount.length <= 105
  • \n\t
  • 1 <= candiesCount[i] <= 105
  • \n\t
  • 1 <= queries.length <= 105
  • \n\t
  • queries[i].length == 3
  • \n\t
  • 0 <= favoriteTypei < candiesCount.length
  • \n\t
  • 0 <= favoriteDayi <= 109
  • \n\t
  • 1 <= dailyCapi <= 109
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u4e0b\u6807\u4ece 0 \u5f00\u59cb\u7684\u6b63\u6574\u6570\u6570\u7ec4\u00a0candiesCount\u00a0\uff0c\u5176\u4e2d\u00a0candiesCount[i]\u00a0\u8868\u793a\u4f60\u62e5\u6709\u7684\u7b2c\u00a0i\u00a0\u7c7b\u7cd6\u679c\u7684\u6570\u76ee\u3002\u540c\u65f6\u7ed9\u4f60\u4e00\u4e2a\u4e8c\u7ef4\u6570\u7ec4\u00a0queries\u00a0\uff0c\u5176\u4e2d\u00a0queries[i] = [favoriteTypei, favoriteDayi, dailyCapi]\u00a0\u3002

\n\n

\u4f60\u6309\u7167\u5982\u4e0b\u89c4\u5219\u8fdb\u884c\u4e00\u573a\u6e38\u620f\uff1a

\n\n
    \n\t
  • \u4f60\u4ece\u7b2c\u00a00\u00a0\u5929\u5f00\u59cb\u5403\u7cd6\u679c\u3002
  • \n\t
  • \u4f60\u5728\u5403\u5b8c \u6240\u6709\u00a0\u7b2c i - 1\u00a0\u7c7b\u7cd6\u679c\u4e4b\u524d\uff0c\u4e0d\u80fd\u00a0\u5403\u4efb\u4f55\u4e00\u9897\u7b2c i\u00a0\u7c7b\u7cd6\u679c\u3002
  • \n\t
  • \u5728\u5403\u5b8c\u6240\u6709\u7cd6\u679c\u4e4b\u524d\uff0c\u4f60\u5fc5\u987b\u6bcf\u5929 \u81f3\u5c11\u00a0\u5403 \u4e00\u9897\u00a0\u7cd6\u679c\u3002
  • \n
\n\n

\u8bf7\u4f60\u6784\u5efa\u4e00\u4e2a\u5e03\u5c14\u578b\u6570\u7ec4\u00a0answer\u00a0\uff0c\u6ee1\u8db3\u00a0answer.length == queries.length \u3002answer[i]\u00a0\u4e3a\u00a0true\u00a0\u7684\u6761\u4ef6\u662f\uff1a\u5728\u6bcf\u5929\u5403 \u4e0d\u8d85\u8fc7 dailyCapi\u00a0\u9897\u7cd6\u679c\u7684\u524d\u63d0\u4e0b\uff0c\u4f60\u53ef\u4ee5\u5728\u7b2c\u00a0favoriteDayi\u00a0\u5929\u5403\u5230\u7b2c\u00a0favoriteTypei\u00a0\u7c7b\u7cd6\u679c\uff1b\u5426\u5219 answer[i]\u00a0\u4e3a false\u00a0\u3002\u6ce8\u610f\uff0c\u53ea\u8981\u6ee1\u8db3\u4e0a\u9762 3 \u6761\u89c4\u5219\u4e2d\u7684\u7b2c\u4e8c\u6761\u89c4\u5219\uff0c\u4f60\u5c31\u53ef\u4ee5\u5728\u540c\u4e00\u5929\u5403\u4e0d\u540c\u7c7b\u578b\u7684\u7cd6\u679c\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u5f97\u5230\u7684\u6570\u7ec4\u00a0answer\u00a0\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1acandiesCount = [7,4,5,3,8], queries = [[0,2,2],[4,2,4],[2,13,1000000000]]\n\u8f93\u51fa\uff1a[true,false,true]\n\u63d0\u793a\uff1a\n1- \u5728\u7b2c 0 \u5929\u5403 2 \u9897\u7cd6\u679c(\u7c7b\u578b 0\uff09\uff0c\u7b2c 1 \u5929\u5403 2 \u9897\u7cd6\u679c\uff08\u7c7b\u578b 0\uff09\uff0c\u7b2c 2 \u5929\u4f60\u53ef\u4ee5\u5403\u5230\u7c7b\u578b 0 \u7684\u7cd6\u679c\u3002\n2- \u6bcf\u5929\u4f60\u6700\u591a\u5403 4 \u9897\u7cd6\u679c\u3002\u5373\u4f7f\u7b2c 0 \u5929\u5403 4 \u9897\u7cd6\u679c\uff08\u7c7b\u578b 0\uff09\uff0c\u7b2c 1 \u5929\u5403 4 \u9897\u7cd6\u679c\uff08\u7c7b\u578b 0 \u548c\u7c7b\u578b 1\uff09\uff0c\u4f60\u4e5f\u6ca1\u529e\u6cd5\u5728\u7b2c 2 \u5929\u5403\u5230\u7c7b\u578b 4 \u7684\u7cd6\u679c\u3002\u6362\u8a00\u4e4b\uff0c\u4f60\u6ca1\u6cd5\u5728\u6bcf\u5929\u5403 4 \u9897\u7cd6\u679c\u7684\u9650\u5236\u4e0b\u5728\u7b2c 2 \u5929\u5403\u5230\u7b2c 4 \u7c7b\u7cd6\u679c\u3002\n3- \u5982\u679c\u4f60\u6bcf\u5929\u5403 1 \u9897\u7cd6\u679c\uff0c\u4f60\u53ef\u4ee5\u5728\u7b2c 13 \u5929\u5403\u5230\u7c7b\u578b 2 \u7684\u7cd6\u679c\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1acandiesCount = [5,2,6,4,1], queries = [[3,1,2],[4,10,3],[3,10,100],[4,100,30],[1,3,1]]\n\u8f93\u51fa\uff1a[false,true,true,false,false]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= candiesCount.length <= 105
  • \n\t
  • 1 <= candiesCount[i] <= 105
  • \n\t
  • 1 <= queries.length <= 105
  • \n\t
  • queries[i].length == 3
  • \n\t
  • 0 <= favoriteTypei < candiesCount.length
  • \n\t
  • 0 <= favoriteDayi <= 109
  • \n\t
  • 1 <= dailyCapi <= 109
  • \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector canEat(vector& candiesCount, vector>& queries) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean[] canEat(int[] candiesCount, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canEat(self, candiesCount, queries):\n \"\"\"\n :type candiesCount: List[int]\n :type queries: List[List[int]]\n :rtype: List[bool]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canEat(self, candiesCount: List[int], queries: List[List[int]]) -> List[bool]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nbool* canEat(int* candiesCount, int candiesCountSize, int** queries, int queriesSize, int* queriesColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool[] CanEat(int[] candiesCount, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} candiesCount\n * @param {number[][]} queries\n * @return {boolean[]}\n */\nvar canEat = function(candiesCount, queries) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} candies_count\n# @param {Integer[][]} queries\n# @return {Boolean[]}\ndef can_eat(candies_count, queries)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canEat(_ candiesCount: [Int], _ queries: [[Int]]) -> [Bool] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canEat(candiesCount []int, queries [][]int) []bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canEat(candiesCount: Array[Int], queries: Array[Array[Int]]): Array[Boolean] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canEat(candiesCount: IntArray, queries: Array): BooleanArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_eat(candies_count: Vec, queries: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $candiesCount\n * @param Integer[][] $queries\n * @return Boolean[]\n */\n function canEat($candiesCount, $queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canEat(candiesCount: number[], queries: number[][]): boolean[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-eat candiesCount queries)\n (-> (listof exact-integer?) (listof (listof exact-integer?)) (listof boolean?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1744](https://leetcode-cn.com/problems/can-you-eat-your-favorite-candy-on-your-favorite-day)", "[\u4f60\u80fd\u5728\u4f60\u6700\u559c\u6b22\u7684\u90a3\u5929\u5403\u5230\u4f60\u6700\u559c\u6b22\u7684\u7cd6\u679c\u5417\uff1f](/solution/1700-1799/1744.Can%20You%20Eat%20Your%20Favorite%20Candy%20on%20Your%20Favorite%20Day/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1744](https://leetcode.com/problems/can-you-eat-your-favorite-candy-on-your-favorite-day)", "[Can You Eat Your Favorite Candy on Your Favorite Day](/solution/1700-1799/1744.Can%20You%20Eat%20Your%20Favorite%20Candy%20on%20Your%20Favorite%20Day/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "1871", "frontend_question_id": "1745", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/palindrome-partitioning-iv", "url_en": "https://leetcode.com/problems/palindrome-partitioning-iv", "relative_path_cn": "/solution/1700-1799/1745.Palindrome%20Partitioning%20IV/README.md", "relative_path_en": "/solution/1700-1799/1745.Palindrome%20Partitioning%20IV/README_EN.md", "title_cn": "\u56de\u6587\u4e32\u5206\u5272 IV", "title_en": "Palindrome Partitioning IV", "question_title_slug": "palindrome-partitioning-iv", "content_en": "

Given a string s, return true if it is possible to split the string s into three non-empty palindromic substrings. Otherwise, return false.\u200b\u200b\u200b\u200b\u200b

\n\n

A string is said to be palindrome if it the same string when reversed.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "abcbdd"\nOutput: true\nExplanation: "abcbdd" = "a" + "bcb" + "dd", and all three substrings are palindromes.\n
\n\n

Example 2:

\n\n
\nInput: s = "bcbddxy"\nOutput: false\nExplanation: s cannot be split into 3 palindromes.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 3 <= s.length <= 2000
  • \n\t
  • s\u200b\u200b\u200b\u200b\u200b\u200b consists only of lowercase English letters.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32\u00a0s\u00a0\uff0c\u5982\u679c\u53ef\u4ee5\u5c06\u5b83\u5206\u5272\u6210\u4e09\u4e2a\u00a0\u975e\u7a7a\u00a0\u56de\u6587\u5b50\u5b57\u7b26\u4e32\uff0c\u90a3\u4e48\u8fd4\u56de\u00a0true\u00a0\uff0c\u5426\u5219\u8fd4\u56de\u00a0false\u00a0\u3002

\n\n

\u5f53\u4e00\u4e2a\u5b57\u7b26\u4e32\u6b63\u7740\u8bfb\u548c\u53cd\u7740\u8bfb\u662f\u4e00\u6a21\u4e00\u6837\u7684\uff0c\u5c31\u79f0\u5176\u4e3a \u56de\u6587\u5b57\u7b26\u4e32 \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"abcbdd\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\"abcbdd\" = \"a\" + \"bcb\" + \"dd\"\uff0c\u4e09\u4e2a\u5b50\u5b57\u7b26\u4e32\u90fd\u662f\u56de\u6587\u7684\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"bcbddxy\"\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1as \u6ca1\u529e\u6cd5\u88ab\u5206\u5272\u6210 3 \u4e2a\u56de\u6587\u5b50\u5b57\u7b26\u4e32\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 3 <= s.length <= 2000
  • \n\t
  • s\u200b\u200b\u200b\u200b\u200b\u200b \u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
  • \n
\n", "tags_en": ["String", "Dynamic Programming"], "tags_cn": ["\u5b57\u7b26\u4e32", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool checkPartitioning(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean checkPartitioning(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def checkPartitioning(self, s):\n \"\"\"\n :type s: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def checkPartitioning(self, s: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool checkPartitioning(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CheckPartitioning(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {boolean}\n */\nvar checkPartitioning = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Boolean}\ndef check_partitioning(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func checkPartitioning(_ s: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func checkPartitioning(s string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def checkPartitioning(s: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun checkPartitioning(s: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn check_partitioning(s: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Boolean\n */\n function checkPartitioning($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function checkPartitioning(s: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (check-partitioning s)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1745](https://leetcode-cn.com/problems/palindrome-partitioning-iv)", "[\u56de\u6587\u4e32\u5206\u5272 IV](/solution/1700-1799/1745.Palindrome%20Partitioning%20IV/README.md)", "`\u5b57\u7b26\u4e32`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1745](https://leetcode.com/problems/palindrome-partitioning-iv)", "[Palindrome Partitioning IV](/solution/1700-1799/1745.Palindrome%20Partitioning%20IV/README_EN.md)", "`String`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "1866", "frontend_question_id": "1743", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/restore-the-array-from-adjacent-pairs", "url_en": "https://leetcode.com/problems/restore-the-array-from-adjacent-pairs", "relative_path_cn": "/solution/1700-1799/1743.Restore%20the%20Array%20From%20Adjacent%20Pairs/README.md", "relative_path_en": "/solution/1700-1799/1743.Restore%20the%20Array%20From%20Adjacent%20Pairs/README_EN.md", "title_cn": "\u4ece\u76f8\u90bb\u5143\u7d20\u5bf9\u8fd8\u539f\u6570\u7ec4", "title_en": "Restore the Array From Adjacent Pairs", "question_title_slug": "restore-the-array-from-adjacent-pairs", "content_en": "

There is an integer array nums that consists of n unique elements, but you have forgotten it. However, you do remember every pair of adjacent elements in nums.

\n\n

You are given a 2D integer array adjacentPairs of size n - 1 where each adjacentPairs[i] = [ui, vi] indicates that the elements ui and vi are adjacent in nums.

\n\n

It is guaranteed that every adjacent pair of elements nums[i] and nums[i+1] will exist in adjacentPairs, either as [nums[i], nums[i+1]] or [nums[i+1], nums[i]]. The pairs can appear in any order.

\n\n

Return the original array nums. If there are multiple solutions, return any of them.

\n\n

 

\n

Example 1:

\n\n
\nInput: adjacentPairs = [[2,1],[3,4],[3,2]]\nOutput: [1,2,3,4]\nExplanation: This array has all its adjacent pairs in adjacentPairs.\nNotice that adjacentPairs[i] may not be in left-to-right order.\n
\n\n

Example 2:

\n\n
\nInput: adjacentPairs = [[4,-2],[1,4],[-3,1]]\nOutput: [-2,4,1,-3]\nExplanation: There can be negative numbers.\nAnother solution is [-3,1,4,-2], which would also be accepted.\n
\n\n

Example 3:

\n\n
\nInput: adjacentPairs = [[100000,-100000]]\nOutput: [100000,-100000]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • nums.length == n
  • \n\t
  • adjacentPairs.length == n - 1
  • \n\t
  • adjacentPairs[i].length == 2
  • \n\t
  • 2 <= n <= 105
  • \n\t
  • -105 <= nums[i], ui, vi <= 105
  • \n\t
  • There exists some nums that has adjacentPairs as its pairs.
  • \n
\n", "content_cn": "

\u5b58\u5728\u4e00\u4e2a\u7531 n \u4e2a\u4e0d\u540c\u5143\u7d20\u7ec4\u6210\u7684\u6574\u6570\u6570\u7ec4 nums \uff0c\u4f46\u4f60\u5df2\u7ecf\u8bb0\u4e0d\u6e05\u5177\u4f53\u5185\u5bb9\u3002\u597d\u5728\u4f60\u8fd8\u8bb0\u5f97 nums \u4e2d\u7684\u6bcf\u4e00\u5bf9\u76f8\u90bb\u5143\u7d20\u3002

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u4e8c\u7ef4\u6574\u6570\u6570\u7ec4 adjacentPairs \uff0c\u5927\u5c0f\u4e3a n - 1 \uff0c\u5176\u4e2d\u6bcf\u4e2a adjacentPairs[i] = [ui, vi] \u8868\u793a\u5143\u7d20 ui \u548c vi \u5728 nums \u4e2d\u76f8\u90bb\u3002

\n\n

\u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u6240\u6709\u7531\u5143\u7d20 nums[i] \u548c nums[i+1] \u7ec4\u6210\u7684\u76f8\u90bb\u5143\u7d20\u5bf9\u90fd\u5b58\u5728\u4e8e adjacentPairs \u4e2d\uff0c\u5b58\u5728\u5f62\u5f0f\u53ef\u80fd\u662f [nums[i], nums[i+1]] \uff0c\u4e5f\u53ef\u80fd\u662f [nums[i+1], nums[i]] \u3002\u8fd9\u4e9b\u76f8\u90bb\u5143\u7d20\u5bf9\u53ef\u4ee5 \u6309\u4efb\u610f\u987a\u5e8f \u51fa\u73b0\u3002

\n\n

\u8fd4\u56de \u539f\u59cb\u6570\u7ec4 nums \u3002\u5982\u679c\u5b58\u5728\u591a\u79cd\u89e3\u7b54\uff0c\u8fd4\u56de \u5176\u4e2d\u4efb\u610f\u4e00\u4e2a \u5373\u53ef\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aadjacentPairs = [[2,1],[3,4],[3,2]]\n\u8f93\u51fa\uff1a[1,2,3,4]\n\u89e3\u91ca\uff1a\u6570\u7ec4\u7684\u6240\u6709\u76f8\u90bb\u5143\u7d20\u5bf9\u90fd\u5728 adjacentPairs \u4e2d\u3002\n\u7279\u522b\u8981\u6ce8\u610f\u7684\u662f\uff0cadjacentPairs[i] \u53ea\u8868\u793a\u4e24\u4e2a\u5143\u7d20\u76f8\u90bb\uff0c\u5e76\u4e0d\u4fdd\u8bc1\u5176 \u5de6-\u53f3 \u987a\u5e8f\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aadjacentPairs = [[4,-2],[1,4],[-3,1]]\n\u8f93\u51fa\uff1a[-2,4,1,-3]\n\u89e3\u91ca\uff1a\u6570\u7ec4\u4e2d\u53ef\u80fd\u5b58\u5728\u8d1f\u6570\u3002\n\u53e6\u4e00\u79cd\u89e3\u7b54\u662f [-3,1,4,-2] \uff0c\u4e5f\u4f1a\u88ab\u89c6\u4f5c\u6b63\u786e\u7b54\u6848\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1aadjacentPairs = [[100000,-100000]]\n\u8f93\u51fa\uff1a[100000,-100000]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • nums.length == n
  • \n\t
  • adjacentPairs.length == n - 1
  • \n\t
  • adjacentPairs[i].length == 2
  • \n\t
  • 2 <= n <= 105
  • \n\t
  • -105 <= nums[i], ui, vi <= 105
  • \n\t
  • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u5b58\u5728\u4e00\u4e9b\u4ee5\u00a0adjacentPairs \u4f5c\u4e3a\u5143\u7d20\u5bf9\u7684\u6570\u7ec4 nums
  • \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector restoreArray(vector>& adjacentPairs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] restoreArray(int[][] adjacentPairs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def restoreArray(self, adjacentPairs):\n \"\"\"\n :type adjacentPairs: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def restoreArray(self, adjacentPairs: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* restoreArray(int** adjacentPairs, int adjacentPairsSize, int* adjacentPairsColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] RestoreArray(int[][] adjacentPairs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} adjacentPairs\n * @return {number[]}\n */\nvar restoreArray = function(adjacentPairs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} adjacent_pairs\n# @return {Integer[]}\ndef restore_array(adjacent_pairs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func restoreArray(_ adjacentPairs: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func restoreArray(adjacentPairs [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def restoreArray(adjacentPairs: Array[Array[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun restoreArray(adjacentPairs: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn restore_array(adjacent_pairs: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $adjacentPairs\n * @return Integer[]\n */\n function restoreArray($adjacentPairs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function restoreArray(adjacentPairs: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (restore-array adjacentPairs)\n (-> (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1743](https://leetcode-cn.com/problems/restore-the-array-from-adjacent-pairs)", "[\u4ece\u76f8\u90bb\u5143\u7d20\u5bf9\u8fd8\u539f\u6570\u7ec4](/solution/1700-1799/1743.Restore%20the%20Array%20From%20Adjacent%20Pairs/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1743](https://leetcode.com/problems/restore-the-array-from-adjacent-pairs)", "[Restore the Array From Adjacent Pairs](/solution/1700-1799/1743.Restore%20the%20Array%20From%20Adjacent%20Pairs/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1865", "frontend_question_id": "1724", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/checking-existence-of-edge-length-limited-paths-ii", "url_en": "https://leetcode.com/problems/checking-existence-of-edge-length-limited-paths-ii", "relative_path_cn": "/solution/1700-1799/1724.Checking%20Existence%20of%20Edge%20Length%20Limited%20Paths%20II/README.md", "relative_path_en": "/solution/1700-1799/1724.Checking%20Existence%20of%20Edge%20Length%20Limited%20Paths%20II/README_EN.md", "title_cn": "\u68c0\u67e5\u8fb9\u957f\u5ea6\u9650\u5236\u7684\u8def\u5f84\u662f\u5426\u5b58\u5728 II", "title_en": "Checking Existence of Edge Length Limited Paths II", "question_title_slug": "checking-existence-of-edge-length-limited-paths-ii", "content_en": "

An undirected graph of n nodes is defined by edgeList, where edgeList[i] = [ui, vi, disi] denotes an edge between nodes ui and vi with distance disi. Note that there may be multiple edges between two nodes, and the graph may not be connected.

\n\n

Implement the DistanceLimitedPathsExist class:

\n\n
    \n\t
  • DistanceLimitedPathsExist(int n, int[][] edgeList) Initializes the class with an undirected graph.
  • \n\t
  • boolean query(int p, int q, int limit) Returns true if there exists a path from p to q such that each edge on the path has a distance strictly less than limit, and otherwise false.
  • \n
\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput\n["DistanceLimitedPathsExist", "query", "query", "query", "query"]\n[[6, [[0, 2, 4], [0, 3, 2], [1, 2, 3], [2, 3, 1], [4, 5, 5]]], [2, 3, 2], [1, 3, 3], [2, 0, 3], [0, 5, 6]]\nOutput\n[null, true, false, true, false]\n\nExplanation\nDistanceLimitedPathsExist distanceLimitedPathsExist = new DistanceLimitedPathsExist(6, [[0, 2, 4], [0, 3, 2], [1, 2, 3], [2, 3, 1], [4, 5, 5]]);\ndistanceLimitedPathsExist.query(2, 3, 2); // return true. There is an edge from 2 to 3 of distance 1, which is less than 2.\ndistanceLimitedPathsExist.query(1, 3, 3); // return false. There is no way to go from 1 to 3 with distances strictly less than 3.\ndistanceLimitedPathsExist.query(2, 0, 3); // return true. There is a way to go from 2 to 0 with distance < 3: travel from 2 to 3 to 0.\ndistanceLimitedPathsExist.query(0, 5, 6); // return false. There are no paths from 0 to 5.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= n <= 104
  • \n\t
  • 0 <= edgeList.length <= 104
  • \n\t
  • edgeList[i].length == 3
  • \n\t
  • 0 <= ui, vi, p, q <= n-1
  • \n\t
  • ui != vi
  • \n\t
  • p != q
  • \n\t
  • 1 <= disi, limit <= 109
  • \n\t
  • At most 104 calls will be made to query.
  • \n
\n", "content_cn": "

\u4e00\u5f20\u6709\u00a0n\u00a0\u4e2a\u8282\u70b9\u7684\u65e0\u5411\u56fe\u4ee5\u8fb9\u7684\u5217\u8868\u00a0edgeList\u00a0\u7684\u5f62\u5f0f\u5b9a\u4e49\uff0c\u5176\u4e2d\u00a0edgeList[i] = [ui, vi, disi]\u00a0\u8868\u793a\u4e00\u6761\u8fde\u63a5\u00a0ui\u00a0\u548c\u00a0vi\u00a0\uff0c\u8ddd\u79bb\u4e3a\u00a0disi\u00a0\u7684\u8fb9\u3002\u6ce8\u610f\uff0c\u540c\u4e00\u5bf9\u8282\u70b9\u95f4\u53ef\u80fd\u6709\u591a\u6761\u8fb9\uff0c\u4e14\u8be5\u56fe\u53ef\u80fd\u4e0d\u662f\u8fde\u901a\u7684\u3002

\n\n

\u5b9e\u73b0\u00a0DistanceLimitedPathsExist\u00a0\u7c7b\uff1a

\n\n
    \n\t
  • DistanceLimitedPathsExist(int n, int[][] edgeList)\u00a0\u4ee5\u7ed9\u5b9a\u7684\u65e0\u5411\u56fe\u521d\u59cb\u5316\u5bf9\u8c61\u3002
  • \n\t
  • boolean query(int p, int q, int limit)\u00a0\u5f53\u5b58\u5728\u4e00\u6761\u4ece\u00a0p\u00a0\u5230 q \u7684\u8def\u5f84\uff0c\u4e14\u8def\u5f84\u4e2d\u6bcf\u6761\u8fb9\u7684\u8ddd\u79bb\u90fd\u4e25\u683c\u5c0f\u4e8e limit \u65f6\uff0c\u8fd4\u56de true \uff0c\u5426\u5219\u8fd4\u56de false \u3002
  • \n
\n\n

\u00a0

\n\n

\u793a\u4f8b 1:

\n\n

\"\"

\n\n
\u8f93\u5165\uff1a\n[\"DistanceLimitedPathsExist\", \"query\", \"query\", \"query\", \"query\"]\n[[6, [[0, 2, 4], [0, 3, 2], [1, 2, 3], [2, 3, 1], [4, 5, 5]]], [2, 3, 2], [1, 3, 3], [2, 0, 3], [0, 5, 6]]\n\u8f93\u51fa\uff1a\n[null, true, false, true, false]\n\n\u89e3\u91ca\uff1a\nDistanceLimitedPathsExist distanceLimitedPathsExist = new DistanceLimitedPathsExist(6, [[0, 2, 4], [0, 3, 2], [1, 2, 3], [2, 3, 1], [4, 5, 5]]);\ndistanceLimitedPathsExist.query(2, 3, 2); // \u8fd4\u56de true\u3002\u5b58\u5728\u4e00\u6761\u4ece 2 \u5230 3 \uff0c\u8ddd\u79bb\u4e3a 1 \u7684\u8fb9\uff0c\n\u00a0                                         // \u8fd9\u6761\u8fb9\u7684\u8ddd\u79bb\u5c0f\u4e8e 2\u3002\ndistanceLimitedPathsExist.query(1, 3, 3); // \u8fd4\u56de false\u3002\u4ece 1 \u5230 3 \u4e4b\u95f4\u4e0d\u5b58\u5728\u6bcf\u6761\u8fb9\u7684\u8ddd\u79bb\u90fd\n                                          // \u4e25\u683c\u5c0f\u4e8e 3 \u7684\u8def\u5f84\u3002\ndistanceLimitedPathsExist.query(2, 0, 3); // \u8fd4\u56de true\u3002\u5b58\u5728\u4e00\u6761\u4ece 2 \u5230 0 \u7684\u8def\u5f84\uff0c\u4f7f\u5f97\u6bcf\u6761\u8fb9\u7684\n                                          // \u8ddd\u79bb < 3\uff1a\u4ece 2 \u5230 3 \u5230 0 \u884c\u8fdb\u5373\u53ef\u3002\ndistanceLimitedPathsExist.query(0, 5, 6); // \u8fd4\u56de false\u3002\u4ece 0 \u5230 5 \u4e4b\u95f4\u4e0d\u5b58\u5728\u8def\u5f84\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= n <= 104
  • \n\t
  • 0 <= edgeList.length <= 104
  • \n\t
  • edgeList[i].length == 3
  • \n\t
  • 0 <= ui, vi, p, q <= n-1
  • \n\t
  • ui != vi
  • \n\t
  • p != q
  • \n\t
  • 1 <= disi, limit <= 109
  • \n\t
  • \u6700\u591a\u8c03\u7528\u00a0104\u00a0\u6b21\u00a0query\u00a0\u3002
  • \n
\n", "tags_en": ["Union Find", "Graph", "Dynamic Programming"], "tags_cn": ["\u5e76\u67e5\u96c6", "\u56fe", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class DistanceLimitedPathsExist {\npublic:\n DistanceLimitedPathsExist(int n, vector>& edgeList) {\n\n }\n \n bool query(int p, int q, int limit) {\n\n }\n};\n\n/**\n * Your DistanceLimitedPathsExist object will be instantiated and called as such:\n * DistanceLimitedPathsExist* obj = new DistanceLimitedPathsExist(n, edgeList);\n * bool param_1 = obj->query(p,q,limit);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class DistanceLimitedPathsExist {\n\n public DistanceLimitedPathsExist(int n, int[][] edgeList) {\n\n }\n \n public boolean query(int p, int q, int limit) {\n\n }\n}\n\n/**\n * Your DistanceLimitedPathsExist object will be instantiated and called as such:\n * DistanceLimitedPathsExist obj = new DistanceLimitedPathsExist(n, edgeList);\n * boolean param_1 = obj.query(p,q,limit);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class DistanceLimitedPathsExist(object):\n\n def __init__(self, n, edgeList):\n \"\"\"\n :type n: int\n :type edgeList: List[List[int]]\n \"\"\"\n\n\n def query(self, p, q, limit):\n \"\"\"\n :type p: int\n :type q: int\n :type limit: int\n :rtype: bool\n \"\"\"\n\n\n\n# Your DistanceLimitedPathsExist object will be instantiated and called as such:\n# obj = DistanceLimitedPathsExist(n, edgeList)\n# param_1 = obj.query(p,q,limit)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class DistanceLimitedPathsExist:\n\n def __init__(self, n: int, edgeList: List[List[int]]):\n\n\n def query(self, p: int, q: int, limit: int) -> bool:\n\n\n\n# Your DistanceLimitedPathsExist object will be instantiated and called as such:\n# obj = DistanceLimitedPathsExist(n, edgeList)\n# param_1 = obj.query(p,q,limit)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} DistanceLimitedPathsExist;\n\n\nDistanceLimitedPathsExist* distanceLimitedPathsExistCreate(int n, int** edgeList, int edgeListSize, int* edgeListColSize) {\n\n}\n\nbool distanceLimitedPathsExistQuery(DistanceLimitedPathsExist* obj, int p, int q, int limit) {\n\n}\n\nvoid distanceLimitedPathsExistFree(DistanceLimitedPathsExist* obj) {\n\n}\n\n/**\n * Your DistanceLimitedPathsExist struct will be instantiated and called as such:\n * DistanceLimitedPathsExist* obj = distanceLimitedPathsExistCreate(n, edgeList, edgeListSize, edgeListColSize);\n * bool param_1 = distanceLimitedPathsExistQuery(obj, p, q, limit);\n \n * distanceLimitedPathsExistFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class DistanceLimitedPathsExist {\n\n public DistanceLimitedPathsExist(int n, int[][] edgeList) {\n\n }\n \n public bool Query(int p, int q, int limit) {\n\n }\n}\n\n/**\n * Your DistanceLimitedPathsExist object will be instantiated and called as such:\n * DistanceLimitedPathsExist obj = new DistanceLimitedPathsExist(n, edgeList);\n * bool param_1 = obj.Query(p,q,limit);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} edgeList\n */\nvar DistanceLimitedPathsExist = function(n, edgeList) {\n\n};\n\n/** \n * @param {number} p \n * @param {number} q \n * @param {number} limit\n * @return {boolean}\n */\nDistanceLimitedPathsExist.prototype.query = function(p, q, limit) {\n\n};\n\n/**\n * Your DistanceLimitedPathsExist object will be instantiated and called as such:\n * var obj = new DistanceLimitedPathsExist(n, edgeList)\n * var param_1 = obj.query(p,q,limit)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class DistanceLimitedPathsExist\n\n=begin\n :type n: Integer\n :type edge_list: Integer[][]\n=end\n def initialize(n, edge_list)\n\n end\n\n\n=begin\n :type p: Integer\n :type q: Integer\n :type limit: Integer\n :rtype: Boolean\n=end\n def query(p, q, limit)\n\n end\n\n\nend\n\n# Your DistanceLimitedPathsExist object will be instantiated and called as such:\n# obj = DistanceLimitedPathsExist.new(n, edge_list)\n# param_1 = obj.query(p, q, limit)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass DistanceLimitedPathsExist {\n\n init(_ n: Int, _ edgeList: [[Int]]) {\n\n }\n \n func query(_ p: Int, _ q: Int, _ limit: Int) -> Bool {\n\n }\n}\n\n/**\n * Your DistanceLimitedPathsExist object will be instantiated and called as such:\n * let obj = DistanceLimitedPathsExist(n, edgeList)\n * let ret_1: Bool = obj.query(p, q, limit)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type DistanceLimitedPathsExist struct {\n\n}\n\n\nfunc Constructor(n int, edgeList [][]int) DistanceLimitedPathsExist {\n\n}\n\n\nfunc (this *DistanceLimitedPathsExist) Query(p int, q int, limit int) bool {\n\n}\n\n\n/**\n * Your DistanceLimitedPathsExist object will be instantiated and called as such:\n * obj := Constructor(n, edgeList);\n * param_1 := obj.Query(p,q,limit);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class DistanceLimitedPathsExist(_n: Int, _edgeList: Array[Array[Int]]) {\n\n def query(p: Int, q: Int, limit: Int): Boolean = {\n \n }\n\n}\n\n/**\n * Your DistanceLimitedPathsExist object will be instantiated and called as such:\n * var obj = new DistanceLimitedPathsExist(n, edgeList)\n * var param_1 = obj.query(p,q,limit)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class DistanceLimitedPathsExist(n: Int, edgeList: Array) {\n\n fun query(p: Int, q: Int, limit: Int): Boolean {\n\n }\n\n}\n\n/**\n * Your DistanceLimitedPathsExist object will be instantiated and called as such:\n * var obj = DistanceLimitedPathsExist(n, edgeList)\n * var param_1 = obj.query(p,q,limit)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct DistanceLimitedPathsExist {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl DistanceLimitedPathsExist {\n\n fn new(n: i32, edgeList: Vec>) -> Self {\n\n }\n \n fn query(&self, p: i32, q: i32, limit: i32) -> bool {\n\n }\n}\n\n/**\n * Your DistanceLimitedPathsExist object will be instantiated and called as such:\n * let obj = DistanceLimitedPathsExist::new(n, edgeList);\n * let ret_1: bool = obj.query(p, q, limit);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class DistanceLimitedPathsExist {\n /**\n * @param Integer $n\n * @param Integer[][] $edgeList\n */\n function __construct($n, $edgeList) {\n\n }\n\n /**\n * @param Integer $p\n * @param Integer $q\n * @param Integer $limit\n * @return Boolean\n */\n function query($p, $q, $limit) {\n\n }\n}\n\n/**\n * Your DistanceLimitedPathsExist object will be instantiated and called as such:\n * $obj = DistanceLimitedPathsExist($n, $edgeList);\n * $ret_1 = $obj->query($p, $q, $limit);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class DistanceLimitedPathsExist {\n constructor(n: number, edgeList: number[][]) {\n\n }\n\n query(p: number, q: number, limit: number): boolean {\n\n }\n}\n\n/**\n * Your DistanceLimitedPathsExist object will be instantiated and called as such:\n * var obj = new DistanceLimitedPathsExist(n, edgeList)\n * var param_1 = obj.query(p,q,limit)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define distance-limited-paths-exist%\n (class object%\n (super-new)\n\n ; n : exact-integer?\n\n ; edge-list : (listof (listof exact-integer?))\n (init-field\n n\n edge-list)\n \n ; query : exact-integer? exact-integer? exact-integer? -> boolean?\n (define/public (query p q limit)\n\n )))\n\n;; Your distance-limited-paths-exist% object will be instantiated and called as such:\n;; (define obj (new distance-limited-paths-exist% [n n] [edgeList edgeList]))\n;; (define param_1 (send obj query p q limit))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1724](https://leetcode-cn.com/problems/checking-existence-of-edge-length-limited-paths-ii)", "[\u68c0\u67e5\u8fb9\u957f\u5ea6\u9650\u5236\u7684\u8def\u5f84\u662f\u5426\u5b58\u5728 II](/solution/1700-1799/1724.Checking%20Existence%20of%20Edge%20Length%20Limited%20Paths%20II/README.md)", "`\u5e76\u67e5\u96c6`,`\u56fe`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1724](https://leetcode.com/problems/checking-existence-of-edge-length-limited-paths-ii)", "[Checking Existence of Edge Length Limited Paths II](/solution/1700-1799/1724.Checking%20Existence%20of%20Edge%20Length%20Limited%20Paths%20II/README_EN.md)", "`Union Find`,`Graph`,`Dynamic Programming`", "Hard", "\ud83d\udd12"]}, {"question_id": "1862", "frontend_question_id": "1715", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/count-apples-and-oranges", "url_en": "https://leetcode.com/problems/count-apples-and-oranges", "relative_path_cn": "/solution/1700-1799/1715.Count%20Apples%20and%20Oranges/README.md", "relative_path_en": "/solution/1700-1799/1715.Count%20Apples%20and%20Oranges/README_EN.md", "title_cn": "\u82f9\u679c\u548c\u6a58\u5b50\u7684\u4e2a\u6570", "title_en": "Count Apples and Oranges", "question_title_slug": "count-apples-and-oranges", "content_en": "

Table: Boxes

\n\n
\n+--------------+------+\n| Column Name  | Type |\n+--------------+------+\n| box_id       | int  |\n| chest_id     | int  |\n| apple_count  | int  |\n| orange_count | int  |\n+--------------+------+\nbox_id is the primary key for this table.\nchest_id is a foreign key of the chests table.\nThis table contains information about the boxes and the number of oranges and apples they contain. Each box may contain a chest, which also can contain oranges and apples.\n
\n\n

 

\n\n

Table: Chests

\n\n
\n+--------------+------+\n| Column Name  | Type |\n+--------------+------+\n| chest_id     | int  |\n| apple_count  | int  |\n| orange_count | int  |\n+--------------+------+\nchest_id is the primary key for this table.\nThis table contains information about the chests we have, and the corresponding number if oranges and apples they contain.\n
\n\n

 

\n\n

Write an SQL query to count the number of apples and oranges in all the boxes. If a box contains a chest, you should also include the number of apples and oranges it has.

\n\n

Return the result table in any order.

\n\n

The query result format is in the following example:

\n\n

 

\n\n
\nBoxes table:\n+--------+----------+-------------+--------------+\n| box_id | chest_id | apple_count | orange_count |\n+--------+----------+-------------+--------------+\n| 2      | null     | 6           | 15           |\n| 18     | 14       | 4           | 15           |\n| 19     | 3        | 8           | 4            |\n| 12     | 2        | 19          | 20           |\n| 20     | 6        | 12          | 9            |\n| 8      | 6        | 9           | 9            |\n| 3      | 14       | 16          | 7            |\n+--------+----------+-------------+--------------+\n\nChests table:\n+----------+-------------+--------------+\n| chest_id | apple_count | orange_count |\n+----------+-------------+--------------+\n| 6        | 5           | 6            |\n| 14       | 20          | 10           |\n| 2        | 8           | 8            |\n| 3        | 19          | 4            |\n| 16       | 19          | 19           |\n+----------+-------------+--------------+\n\nResult table:\n+-------------+--------------+\n| apple_count | orange_count |\n+-------------+--------------+\n| 151         | 123          |\n+-------------+--------------+\nbox 2 has 6 apples and 15 oranges.\nbox 18 has 4 + 20 (from the chest) = 24 apples and 15 + 10 (from the chest) = 25 oranges.\nbox 19 has 8 + 19 (from the chest) = 27 apples and 4 + 4 (from the chest) = 8 oranges.\nbox 12 has 19 + 8 (from the chest) = 27 apples and 20 + 8 (from the chest) = 28 oranges.\nbox 20 has 12 + 5 (from the chest) = 17 apples and 9 + 6 (from the chest) = 15 oranges.\nbox 8 has 9 + 5 (from the chest) = 14 apples and 9 + 6 (from the chest) = 15 oranges.\nbox 3 has 16 + 20 (from the chest) = 36 apples and 7 + 10 (from the chest) = 17 oranges.\nTotal number of apples = 6 + 24 + 27 + 27 + 17 + 14 + 36 = 151\nTotal number of oranges = 15 + 25 + 8 + 28 + 15 + 15 + 17 = 123\n
\n", "content_cn": "

\u8868\uff1a\u00a0Boxes

\n\n
+--------------+------+\n| Column Name  | Type |\n+--------------+------+\n| box_id       | int  |\n| chest_id     | int  |\n| apple_count  | int  |\n| orange_count | int  |\n+--------------+------+\nbox_id \u662f\u8be5\u8868\u7684\u4e3b\u952e\u3002\nchest_id \u662f chests \u8868\u7684\u5916\u952e\u3002\n\u8be5\u8868\u5305\u542b\u5927\u7bb1\u5b50 (box) \u4e2d\u5305\u542b\u7684\u82f9\u679c\u548c\u6a58\u5b50\u7684\u4e2a\u6570\u3002\u6bcf\u4e2a\u5927\u7bb1\u5b50\u4e2d\u53ef\u80fd\u5305\u542b\u4e00\u4e2a\u5c0f\u76d2\u5b50 (chest) \uff0c\u5c0f\u76d2\u5b50\u4e2d\u4e5f\u5305\u542b\u82e5\u5e72\u82f9\u679c\u548c\u6a58\u5b50\u3002
\n\n

\u00a0

\n\n

\u8868\uff1a\u00a0Chests

\n\n
+--------------+------+\n| Column Name  | Type |\n+--------------+------+\n| chest_id     | int  |\n| apple_count  | int  |\n| orange_count | int  |\n+--------------+------+\nchest_id \u662f\u8be5\u8868\u7684\u4e3b\u952e\u3002\n\u8be5\u8868\u5305\u542b\u5c0f\u76d2\u5b50\u7684\u4fe1\u606f\uff0c\u4ee5\u53ca\u5c0f\u76d2\u5b50\u4e2d\u5305\u542b\u7684\u82f9\u679c\u548c\u6a58\u5b50\u7684\u4e2a\u6570\u3002
\n\n

\u00a0

\n\n

\u7f16\u5199 SQL \u8bed\u53e5\uff0c\u67e5\u8be2\u6bcf\u4e2a\u5927\u7bb1\u5b50\u4e2d\u82f9\u679c\u548c\u6a58\u5b50\u7684\u4e2a\u6570\u3002\u5982\u679c\u5927\u7bb1\u5b50\u4e2d\u5305\u542b\u5c0f\u76d2\u5b50\uff0c\u8fd8\u5e94\u5f53\u5305\u542b\u5c0f\u76d2\u5b50\u4e2d\u82f9\u679c\u548c\u6a58\u5b50\u7684\u4e2a\u6570\u3002

\n\n

\u4ee5\u4efb\u610f\u987a\u5e8f\u8fd4\u56de\u7ed3\u679c\u8868\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u7684\u683c\u5f0f\u5982\u4e0b\u793a\u4f8b\u6240\u793a\uff1a

\n\n

\u00a0

\n\n
Boxes \u8868\uff1a\n+--------+----------+-------------+--------------+\n| box_id | chest_id | apple_count | orange_count |\n+--------+----------+-------------+--------------+\n| 2      | null     | 6           | 15           |\n| 18     | 14       | 4           | 15           |\n| 19     | 3        | 8           | 4            |\n| 12     | 2        | 19          | 20           |\n| 20     | 6        | 12          | 9            |\n| 8      | 6        | 9           | 9            |\n| 3      | 14       | 16          | 7            |\n+--------+----------+-------------+--------------+\n\nChests \u8868\uff1a\n+----------+-------------+--------------+\n| chest_id | apple_count | orange_count |\n+----------+-------------+--------------+\n| 6        | 5           | 6            |\n| 14       | 20          | 10           |\n| 2        | 8           | 8            |\n| 3        | 19          | 4            |\n| 16       | 19          | 19           |\n+----------+-------------+--------------+\n\n\u7ed3\u679c\u8868\uff1a\n+-------------+--------------+\n| apple_count | orange_count |\n+-------------+--------------+\n| 151         | 123          |\n+-------------+--------------+\n\u5927\u7bb1\u5b50 2 \u4e2d\u6709 6 \u4e2a\u82f9\u679c\u548c 15 \u4e2a\u6a58\u5b50\u3002\n\u5927\u7bb1\u5b50 18 \u4e2d\u6709 4 + 20 (\u5728\u5c0f\u76d2\u5b50\u4e2d) = 24 \u4e2a\u82f9\u679c\u548c 15 + 10 (\u5728\u5c0f\u76d2\u5b50\u4e2d) = 25 \u4e2a\u6a58\u5b50\u3002\n\u5927\u7bb1\u5b50 19 \u4e2d\u6709 8 + 19 (\u5728\u5c0f\u76d2\u5b50\u4e2d) = 27 \u4e2a\u82f9\u679c\u548c 4 + 4 (\u5728\u5c0f\u76d2\u5b50\u4e2d) = 8 \u4e2a\u6a58\u5b50\u3002\n\u5927\u7bb1\u5b50 12 \u4e2d\u6709 19 + 8 (\u5728\u5c0f\u76d2\u5b50\u4e2d) = 27 \u4e2a\u82f9\u679c\u548c 20 + 8 (\u5728\u5c0f\u76d2\u5b50\u4e2d) = 28 \u4e2a\u6a58\u5b50\u3002\n\u5927\u7bb1\u5b50 20 \u4e2d\u6709 12 + 5 (\u5728\u5c0f\u76d2\u5b50\u4e2d) = 17 \u4e2a\u82f9\u679c\u548c 9 + 6 (\u5728\u5c0f\u76d2\u5b50\u4e2d) = 15 \u4e2a\u6a58\u5b50\u3002\n\u5927\u7bb1\u5b50 8 \u4e2d\u6709 9 + 5 (\u5728\u5c0f\u76d2\u5b50\u4e2d) = 14 \u4e2a\u82f9\u679c\u548c 9 + 6 (\u5728\u5c0f\u76d2\u5b50\u4e2d) = 15 \u4e2a\u6a58\u5b50\u3002\n\u5927\u7bb1\u5b50 3 \u4e2d\u6709 16 + 20 (\u5728\u5c0f\u76d2\u5b50\u4e2d) = 36 \u4e2a\u82f9\u679c\u548c 7 + 10 (\u5728\u5c0f\u76d2\u5b50\u4e2d) = 17 \u4e2a\u6a58\u5b50\u3002\n\u82f9\u679c\u7684\u603b\u4e2a\u6570 = 6 + 24 + 27 + 27 + 17 + 14 + 36 = 151\n\u6a58\u5b50\u7684\u603b\u4e2a\u6570 = 15 + 25 + 8 + 28 + 15 + 15 + 17 = 123\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1715](https://leetcode-cn.com/problems/count-apples-and-oranges)", "[\u82f9\u679c\u548c\u6a58\u5b50\u7684\u4e2a\u6570](/solution/1700-1799/1715.Count%20Apples%20and%20Oranges/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1715](https://leetcode.com/problems/count-apples-and-oranges)", "[Count Apples and Oranges](/solution/1700-1799/1715.Count%20Apples%20and%20Oranges/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1861", "frontend_question_id": "1739", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/building-boxes", "url_en": "https://leetcode.com/problems/building-boxes", "relative_path_cn": "/solution/1700-1799/1739.Building%20Boxes/README.md", "relative_path_en": "/solution/1700-1799/1739.Building%20Boxes/README_EN.md", "title_cn": "\u653e\u7f6e\u76d2\u5b50", "title_en": "Building Boxes", "question_title_slug": "building-boxes", "content_en": "

You have a cubic storeroom where the width, length, and height of the room are all equal to n units. You are asked to place n boxes in this room where each box is a cube of unit side length. There are however some rules to placing the boxes:

\n\n
    \n\t
  • You can place the boxes anywhere on the floor.
  • \n\t
  • If box x is placed on top of the box y, then each side of the four vertical sides of the box y must either be adjacent to another box or to a wall.
  • \n
\n\n

Given an integer n, return the minimum possible number of boxes touching the floor.

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: n = 3\nOutput: 3\nExplanation: The figure above is for the placement of the three boxes.\nThese boxes are placed in the corner of the room, where the corner is on the left side.\n
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: n = 4\nOutput: 3\nExplanation: The figure above is for the placement of the four boxes.\nThese boxes are placed in the corner of the room, where the corner is on the left side.\n
\n\n

Example 3:

\n\n

\"\"

\n\n
\nInput: n = 10\nOutput: 6\nExplanation: The figure above is for the placement of the ten boxes.\nThese boxes are placed in the corner of the room, where the corner is on the back side.
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 109
  • \n
\n", "content_cn": "

\u6709\u4e00\u4e2a\u7acb\u65b9\u4f53\u623f\u95f4\uff0c\u5176\u957f\u5ea6\u3001\u5bbd\u5ea6\u548c\u9ad8\u5ea6\u90fd\u7b49\u4e8e n \u4e2a\u5355\u4f4d\u3002\u8bf7\u4f60\u5728\u623f\u95f4\u91cc\u653e\u7f6e n \u4e2a\u76d2\u5b50\uff0c\u6bcf\u4e2a\u76d2\u5b50\u90fd\u662f\u4e00\u4e2a\u5355\u4f4d\u8fb9\u957f\u7684\u7acb\u65b9\u4f53\u3002\u653e\u7f6e\u89c4\u5219\u5982\u4e0b\uff1a

\n\n
    \n\t
  • \u4f60\u53ef\u4ee5\u628a\u76d2\u5b50\u653e\u5728\u5730\u677f\u4e0a\u7684\u4efb\u4f55\u5730\u65b9\u3002
  • \n\t
  • \u5982\u679c\u76d2\u5b50 x \u9700\u8981\u653e\u7f6e\u5728\u76d2\u5b50 y \u7684\u9876\u90e8\uff0c\u90a3\u4e48\u76d2\u5b50 y \u7ad6\u76f4\u7684\u56db\u4e2a\u4fa7\u9762\u90fd \u5fc5\u987b \u4e0e\u53e6\u4e00\u4e2a\u76d2\u5b50\u6216\u5899\u76f8\u90bb\u3002
  • \n
\n\n

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n \uff0c\u8fd4\u56de\u63a5\u89e6\u5730\u9762\u7684\u76d2\u5b50\u7684 \u6700\u5c11 \u53ef\u80fd\u6570\u91cf\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1an = 3\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u4e0a\u56fe\u662f 3 \u4e2a\u76d2\u5b50\u7684\u6446\u653e\u4f4d\u7f6e\u3002\n\u8fd9\u4e9b\u76d2\u5b50\u653e\u5728\u623f\u95f4\u7684\u4e00\u89d2\uff0c\u5bf9\u5e94\u5de6\u4fa7\u4f4d\u7f6e\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1an = 4\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u4e0a\u56fe\u662f 3 \u4e2a\u76d2\u5b50\u7684\u6446\u653e\u4f4d\u7f6e\u3002\n\u8fd9\u4e9b\u76d2\u5b50\u653e\u5728\u623f\u95f4\u7684\u4e00\u89d2\uff0c\u5bf9\u5e94\u5de6\u4fa7\u4f4d\u7f6e\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1an = 10\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u4e0a\u56fe\u662f 10 \u4e2a\u76d2\u5b50\u7684\u6446\u653e\u4f4d\u7f6e\u3002\n\u8fd9\u4e9b\u76d2\u5b50\u653e\u5728\u623f\u95f4\u7684\u4e00\u89d2\uff0c\u5bf9\u5e94\u540e\u65b9\u4f4d\u7f6e\u3002
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 109
  • \n
\n", "tags_en": ["Math", "Binary Search"], "tags_cn": ["\u6570\u5b66", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minimumBoxes(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minimumBoxes(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimumBoxes(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimumBoxes(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minimumBoxes(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinimumBoxes(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar minimumBoxes = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef minimum_boxes(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimumBoxes(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimumBoxes(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimumBoxes(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimumBoxes(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimum_boxes(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function minimumBoxes($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimumBoxes(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimum-boxes n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1739](https://leetcode-cn.com/problems/building-boxes)", "[\u653e\u7f6e\u76d2\u5b50](/solution/1700-1799/1739.Building%20Boxes/README.md)", "`\u6570\u5b66`,`\u4e8c\u5206\u67e5\u627e`", "\u56f0\u96be", ""], "md_table_row_en": ["[1739](https://leetcode.com/problems/building-boxes)", "[Building Boxes](/solution/1700-1799/1739.Building%20Boxes/README_EN.md)", "`Math`,`Binary Search`", "Hard", ""]}, {"question_id": "1860", "frontend_question_id": "1738", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-kth-largest-xor-coordinate-value", "url_en": "https://leetcode.com/problems/find-kth-largest-xor-coordinate-value", "relative_path_cn": "/solution/1700-1799/1738.Find%20Kth%20Largest%20XOR%20Coordinate%20Value/README.md", "relative_path_en": "/solution/1700-1799/1738.Find%20Kth%20Largest%20XOR%20Coordinate%20Value/README_EN.md", "title_cn": "\u627e\u51fa\u7b2c K \u5927\u7684\u5f02\u6216\u5750\u6807\u503c", "title_en": "Find Kth Largest XOR Coordinate Value", "question_title_slug": "find-kth-largest-xor-coordinate-value", "content_en": "

You are given a 2D matrix of size m x n, consisting of non-negative integers. You are also given an integer k.

\n\n

The value of coordinate (a, b) of the matrix is the XOR of all matrix[i][j] where 0 <= i <= a < m and 0 <= j <= b < n (0-indexed).

\n\n

Find the kth largest value (1-indexed) of all the coordinates of matrix.

\n\n

 

\n

Example 1:

\n\n
\nInput: matrix = [[5,2],[1,6]], k = 1\nOutput: 7\nExplanation: The value of coordinate (0,1) is 5 XOR 2 = 7, which is the largest value.
\n\n

Example 2:

\n\n
\nInput: matrix = [[5,2],[1,6]], k = 2\nOutput: 5\nExplanation: The value of coordinate (0,0) is 5 = 5, which is the 2nd largest value.
\n\n

Example 3:

\n\n
\nInput: matrix = [[5,2],[1,6]], k = 3\nOutput: 4\nExplanation: The value of coordinate (1,0) is 5 XOR 1 = 4, which is the 3rd largest value.
\n\n

Example 4:

\n\n
\nInput: matrix = [[5,2],[1,6]], k = 4\nOutput: 0\nExplanation: The value of coordinate (1,1) is 5 XOR 2 XOR 1 XOR 6 = 0, which is the 4th largest value.
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • m == matrix.length
  • \n\t
  • n == matrix[i].length
  • \n\t
  • 1 <= m, n <= 1000
  • \n\t
  • 0 <= matrix[i][j] <= 106
  • \n\t
  • 1 <= k <= m * n
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u4e8c\u7ef4\u77e9\u9635 matrix \u548c\u4e00\u4e2a\u6574\u6570 k \uff0c\u77e9\u9635\u5927\u5c0f\u4e3a\u00a0m x n \u7531\u975e\u8d1f\u6574\u6570\u7ec4\u6210\u3002

\n\n

\u77e9\u9635\u4e2d\u5750\u6807 (a, b) \u7684 \u503c \u53ef\u7531\u5bf9\u6240\u6709\u6ee1\u8db3 0 <= i <= a < m \u4e14 0 <= j <= b < n \u7684\u5143\u7d20 matrix[i][j]\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\u8ba1\u6570\uff09\u6267\u884c\u5f02\u6216\u8fd0\u7b97\u5f97\u5230\u3002

\n\n

\u8bf7\u4f60\u627e\u51fa\u00a0matrix \u7684\u6240\u6709\u5750\u6807\u4e2d\u7b2c k \u5927\u7684\u503c\uff08k \u7684\u503c\u4ece 1 \u5f00\u59cb\u8ba1\u6570\uff09\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1amatrix = [[5,2],[1,6]], k = 1\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\u5750\u6807 (0,1) \u7684\u503c\u662f 5 XOR 2 = 7 \uff0c\u4e3a\u6700\u5927\u7684\u503c\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1amatrix = [[5,2],[1,6]], k = 2\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u5750\u6807 (0,0) \u7684\u503c\u662f 5 = 5 \uff0c\u4e3a\u7b2c 2 \u5927\u7684\u503c\u3002
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1amatrix = [[5,2],[1,6]], k = 3\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u5750\u6807 (1,0) \u7684\u503c\u662f 5 XOR 1 = 4 \uff0c\u4e3a\u7b2c 3 \u5927\u7684\u503c\u3002
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1amatrix = [[5,2],[1,6]], k = 4\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u5750\u6807 (1,1) \u7684\u503c\u662f 5 XOR 2 XOR 1 XOR 6 = 0 \uff0c\u4e3a\u7b2c 4 \u5927\u7684\u503c\u3002
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • m == matrix.length
  • \n\t
  • n == matrix[i].length
  • \n\t
  • 1 <= m, n <= 1000
  • \n\t
  • 0 <= matrix[i][j] <= 106
  • \n\t
  • 1 <= k <= m * n
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int kthLargestValue(vector>& matrix, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int kthLargestValue(int[][] matrix, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def kthLargestValue(self, matrix, k):\n \"\"\"\n :type matrix: List[List[int]]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def kthLargestValue(self, matrix: List[List[int]], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint kthLargestValue(int** matrix, int matrixSize, int* matrixColSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int KthLargestValue(int[][] matrix, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} matrix\n * @param {number} k\n * @return {number}\n */\nvar kthLargestValue = function(matrix, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} matrix\n# @param {Integer} k\n# @return {Integer}\ndef kth_largest_value(matrix, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func kthLargestValue(_ matrix: [[Int]], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func kthLargestValue(matrix [][]int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def kthLargestValue(matrix: Array[Array[Int]], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun kthLargestValue(matrix: Array, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn kth_largest_value(matrix: Vec>, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $matrix\n * @param Integer $k\n * @return Integer\n */\n function kthLargestValue($matrix, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function kthLargestValue(matrix: number[][], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (kth-largest-value matrix k)\n (-> (listof (listof exact-integer?)) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1738](https://leetcode-cn.com/problems/find-kth-largest-xor-coordinate-value)", "[\u627e\u51fa\u7b2c K \u5927\u7684\u5f02\u6216\u5750\u6807\u503c](/solution/1700-1799/1738.Find%20Kth%20Largest%20XOR%20Coordinate%20Value/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1738](https://leetcode.com/problems/find-kth-largest-xor-coordinate-value)", "[Find Kth Largest XOR Coordinate Value](/solution/1700-1799/1738.Find%20Kth%20Largest%20XOR%20Coordinate%20Value/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "1859", "frontend_question_id": "1737", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/change-minimum-characters-to-satisfy-one-of-three-conditions", "url_en": "https://leetcode.com/problems/change-minimum-characters-to-satisfy-one-of-three-conditions", "relative_path_cn": "/solution/1700-1799/1737.Change%20Minimum%20Characters%20to%20Satisfy%20One%20of%20Three%20Conditions/README.md", "relative_path_en": "/solution/1700-1799/1737.Change%20Minimum%20Characters%20to%20Satisfy%20One%20of%20Three%20Conditions/README_EN.md", "title_cn": "\u6ee1\u8db3\u4e09\u6761\u4ef6\u4e4b\u4e00\u9700\u6539\u53d8\u7684\u6700\u5c11\u5b57\u7b26\u6570", "title_en": "Change Minimum Characters to Satisfy One of Three Conditions", "question_title_slug": "change-minimum-characters-to-satisfy-one-of-three-conditions", "content_en": "

You are given two strings a and b that consist of lowercase letters. In one operation, you can change any character in a or b to any lowercase letter.

\n\n

Your goal is to satisfy one of the following three conditions:

\n\n
    \n\t
  • Every letter in a is strictly less than every letter in b in the alphabet.
  • \n\t
  • Every letter in b is strictly less than every letter in a in the alphabet.
  • \n\t
  • Both a and b consist of only one distinct letter.
  • \n
\n\n

Return the minimum number of operations needed to achieve your goal.

\n\n

 

\n

Example 1:

\n\n
\nInput: a = "aba", b = "caa"\nOutput: 2\nExplanation: Consider the best way to make each condition true:\n1) Change b to "ccc" in 2 operations, then every letter in a is less than every letter in b.\n2) Change a to "bbb" and b to "aaa" in 3 operations, then every letter in b is less than every letter in a.\n3) Change a to "aaa" and b to "aaa" in 2 operations, then a and b consist of one distinct letter.\nThe best way was done in 2 operations (either condition 1 or condition 3).\n
\n\n

Example 2:

\n\n
\nInput: a = "dabadd", b = "cda"\nOutput: 3\nExplanation: The best way is to make condition 1 true by changing b to "eee".\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= a.length, b.length <= 105
  • \n\t
  • a and b consist only of lowercase letters.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e24\u4e2a\u5b57\u7b26\u4e32 a \u548c b \uff0c\u4e8c\u8005\u5747\u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210\u3002\u4e00\u6b65\u64cd\u4f5c\u4e2d\uff0c\u4f60\u53ef\u4ee5\u5c06 a \u6216 b \u4e2d\u7684 \u4efb\u4e00\u5b57\u7b26 \u6539\u53d8\u4e3a \u4efb\u4e00\u5c0f\u5199\u5b57\u6bcd \u3002

\n\n

\u64cd\u4f5c\u7684\u6700\u7ec8\u76ee\u6807\u662f\u6ee1\u8db3\u4e0b\u5217\u4e09\u4e2a\u6761\u4ef6 \u4e4b\u4e00 \uff1a

\n\n
    \n\t
  • a \u4e2d\u7684 \u6bcf\u4e2a\u5b57\u6bcd \u5728\u5b57\u6bcd\u8868\u4e2d \u4e25\u683c\u5c0f\u4e8e b \u4e2d\u7684 \u6bcf\u4e2a\u5b57\u6bcd \u3002
  • \n\t
  • b \u4e2d\u7684 \u6bcf\u4e2a\u5b57\u6bcd \u5728\u5b57\u6bcd\u8868\u4e2d \u4e25\u683c\u5c0f\u4e8e a \u4e2d\u7684 \u6bcf\u4e2a\u5b57\u6bcd \u3002
  • \n\t
  • a \u548c b \u90fd \u7531 \u540c\u4e00\u4e2a \u5b57\u6bcd\u7ec4\u6210\u3002
  • \n
\n\n

\u8fd4\u56de\u8fbe\u6210\u76ee\u6807\u6240\u9700\u7684 \u6700\u5c11 \u64cd\u4f5c\u6570\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aa = \"aba\", b = \"caa\"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6ee1\u8db3\u6bcf\u4e2a\u6761\u4ef6\u7684\u6700\u4f73\u65b9\u6848\u5206\u522b\u662f\uff1a\n1) \u5c06 b \u53d8\u4e3a \"ccc\"\uff0c2 \u6b21\u64cd\u4f5c\uff0c\u6ee1\u8db3 a \u4e2d\u7684\u6bcf\u4e2a\u5b57\u6bcd\u90fd\u5c0f\u4e8e b \u4e2d\u7684\u6bcf\u4e2a\u5b57\u6bcd\uff1b\n2) \u5c06 a \u53d8\u4e3a \"bbb\" \u5e76\u5c06 b \u53d8\u4e3a \"aaa\"\uff0c3 \u6b21\u64cd\u4f5c\uff0c\u6ee1\u8db3 b \u4e2d\u7684\u6bcf\u4e2a\u5b57\u6bcd\u90fd\u5c0f\u4e8e a \u4e2d\u7684\u6bcf\u4e2a\u5b57\u6bcd\uff1b\n3) \u5c06 a \u53d8\u4e3a \"aaa\" \u5e76\u5c06 b \u53d8\u4e3a \"aaa\"\uff0c2 \u6b21\u64cd\u4f5c\uff0c\u6ee1\u8db3 a \u548c b \u7531\u540c\u4e00\u4e2a\u5b57\u6bcd\u7ec4\u6210\u3002\n\u6700\u4f73\u7684\u65b9\u6848\u53ea\u9700\u8981 2 \u6b21\u64cd\u4f5c\uff08\u6ee1\u8db3\u6761\u4ef6 1 \u6216\u8005\u6761\u4ef6 3\uff09\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aa = \"dabadd\", b = \"cda\"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6ee1\u8db3\u6761\u4ef6 1 \u7684\u6700\u4f73\u65b9\u6848\u662f\u5c06 b \u53d8\u4e3a \"eee\" \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= a.length, b.length <= 105
  • \n\t
  • a \u548c b \u53ea\u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210
  • \n
\n", "tags_en": ["Greedy", "String"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minCharacters(string a, string b) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minCharacters(String a, String b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minCharacters(self, a, b):\n \"\"\"\n :type a: str\n :type b: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minCharacters(self, a: str, b: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minCharacters(char * a, char * b){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinCharacters(string a, string b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} a\n * @param {string} b\n * @return {number}\n */\nvar minCharacters = function(a, b) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} a\n# @param {String} b\n# @return {Integer}\ndef min_characters(a, b)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minCharacters(_ a: String, _ b: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minCharacters(a string, b string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minCharacters(a: String, b: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minCharacters(a: String, b: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_characters(a: String, b: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $a\n * @param String $b\n * @return Integer\n */\n function minCharacters($a, $b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minCharacters(a: string, b: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-characters a b)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1737](https://leetcode-cn.com/problems/change-minimum-characters-to-satisfy-one-of-three-conditions)", "[\u6ee1\u8db3\u4e09\u6761\u4ef6\u4e4b\u4e00\u9700\u6539\u53d8\u7684\u6700\u5c11\u5b57\u7b26\u6570](/solution/1700-1799/1737.Change%20Minimum%20Characters%20to%20Satisfy%20One%20of%20Three%20Conditions/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1737](https://leetcode.com/problems/change-minimum-characters-to-satisfy-one-of-three-conditions)", "[Change Minimum Characters to Satisfy One of Three Conditions](/solution/1700-1799/1737.Change%20Minimum%20Characters%20to%20Satisfy%20One%20of%20Three%20Conditions/README_EN.md)", "`Greedy`,`String`", "Medium", ""]}, {"question_id": "1858", "frontend_question_id": "1736", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/latest-time-by-replacing-hidden-digits", "url_en": "https://leetcode.com/problems/latest-time-by-replacing-hidden-digits", "relative_path_cn": "/solution/1700-1799/1736.Latest%20Time%20by%20Replacing%20Hidden%20Digits/README.md", "relative_path_en": "/solution/1700-1799/1736.Latest%20Time%20by%20Replacing%20Hidden%20Digits/README_EN.md", "title_cn": "\u66ff\u6362\u9690\u85cf\u6570\u5b57\u5f97\u5230\u7684\u6700\u665a\u65f6\u95f4", "title_en": "Latest Time by Replacing Hidden Digits", "question_title_slug": "latest-time-by-replacing-hidden-digits", "content_en": "

You are given a string time in the form of hh:mm, where some of the digits in the string are hidden (represented by ?).

\n\n

The valid times are those inclusively between 00:00 and 23:59.

\n\n

Return the latest valid time you can get from time by replacing the hidden digits.

\n\n

 

\n

Example 1:

\n\n
\nInput: time = "2?:?0"\nOutput: "23:50"\nExplanation: The latest hour beginning with the digit '2' is 23 and the latest minute ending with the digit '0' is 50.\n
\n\n

Example 2:

\n\n
\nInput: time = "0?:3?"\nOutput: "09:39"\n
\n\n

Example 3:

\n\n
\nInput: time = "1?:22"\nOutput: "19:22"\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • time is in the format hh:mm.
  • \n\t
  • It is guaranteed that you can produce a valid time from the given string.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 time \uff0c\u683c\u5f0f\u4e3a hh:mm\uff08\u5c0f\u65f6\uff1a\u5206\u949f\uff09\uff0c\u5176\u4e2d\u67d0\u51e0\u4f4d\u6570\u5b57\u88ab\u9690\u85cf\uff08\u7528 ? \u8868\u793a\uff09\u3002

\n\n

\u6709\u6548\u7684\u65f6\u95f4\u4e3a 00:00 \u5230 23:59 \u4e4b\u95f4\u7684\u6240\u6709\u65f6\u95f4\uff0c\u5305\u62ec 00:00 \u548c 23:59 \u3002

\n\n

\u66ff\u6362\u00a0time \u4e2d\u9690\u85cf\u7684\u6570\u5b57\uff0c\u8fd4\u56de\u4f60\u53ef\u4ee5\u5f97\u5230\u7684\u6700\u665a\u6709\u6548\u65f6\u95f4\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1atime = \"2?:?0\"\n\u8f93\u51fa\uff1a\"23:50\"\n\u89e3\u91ca\uff1a\u4ee5\u6570\u5b57 '2' \u5f00\u5934\u7684\u6700\u665a\u4e00\u5c0f\u65f6\u662f 23 \uff0c\u4ee5 '0' \u7ed3\u5c3e\u7684\u6700\u665a\u4e00\u5206\u949f\u662f 50 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1atime = \"0?:3?\"\n\u8f93\u51fa\uff1a\"09:39\"\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1atime = \"1?:22\"\n\u8f93\u51fa\uff1a\"19:22\"\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • time \u7684\u683c\u5f0f\u4e3a hh:mm
  • \n\t
  • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u4f60\u53ef\u4ee5\u7531\u8f93\u5165\u7684\u5b57\u7b26\u4e32\u751f\u6210\u6709\u6548\u7684\u65f6\u95f4
  • \n
\n", "tags_en": ["Greedy", "String"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string maximumTime(string time) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String maximumTime(String time) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximumTime(self, time):\n \"\"\"\n :type time: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximumTime(self, time: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * maximumTime(char * time){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string MaximumTime(string time) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} time\n * @return {string}\n */\nvar maximumTime = function(time) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} time\n# @return {String}\ndef maximum_time(time)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximumTime(_ time: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximumTime(time string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximumTime(time: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximumTime(time: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximum_time(time: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $time\n * @return String\n */\n function maximumTime($time) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximumTime(time: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximum-time time)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1736](https://leetcode-cn.com/problems/latest-time-by-replacing-hidden-digits)", "[\u66ff\u6362\u9690\u85cf\u6570\u5b57\u5f97\u5230\u7684\u6700\u665a\u65f6\u95f4](/solution/1700-1799/1736.Latest%20Time%20by%20Replacing%20Hidden%20Digits/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1736](https://leetcode.com/problems/latest-time-by-replacing-hidden-digits)", "[Latest Time by Replacing Hidden Digits](/solution/1700-1799/1736.Latest%20Time%20by%20Replacing%20Hidden%20Digits/README_EN.md)", "`Greedy`,`String`", "Easy", ""]}, {"question_id": "1852", "frontend_question_id": "1709", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/biggest-window-between-visits", "url_en": "https://leetcode.com/problems/biggest-window-between-visits", "relative_path_cn": "/solution/1700-1799/1709.Biggest%20Window%20Between%20Visits/README.md", "relative_path_en": "/solution/1700-1799/1709.Biggest%20Window%20Between%20Visits/README_EN.md", "title_cn": "\u8bbf\u95ee\u65e5\u671f\u4e4b\u95f4\u6700\u5927\u7684\u7a7a\u6863\u671f", "title_en": "Biggest Window Between Visits", "question_title_slug": "biggest-window-between-visits", "content_en": "

Table: UserVisits

\n\n
\n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| user_id     | int  |\n| visit_date  | date |\n+-------------+------+\nThis table does not have a primary key.\nThis table contains logs of the dates that users vistied a certain retailer.\n
\n\n

 

\n\n

Assume today's date is '2021-1-1'.

\n\n

Write an SQL query that will, for each user_id, find out the largest window of days between each visit and the one right after it (or today if you are considering the last visit).

\n\n

Return the result table ordered by user_id.

\n\n

The query result format is in the following example:

\n\n

 

\n\n
\nUserVisits table:\n+---------+------------+\n| user_id | visit_date |\n+---------+------------+\n| 1       | 2020-11-28 |\n| 1       | 2020-10-20 |\n| 1       | 2020-12-3  |\n| 2       | 2020-10-5  |\n| 2       | 2020-12-9  |\n| 3       | 2020-11-11 |\n+---------+------------+\nResult table:\n+---------+---------------+\n| user_id | biggest_window|\n+---------+---------------+\n| 1       | 39            |\n| 2       | 65            |\n| 3       | 51            |\n+---------+---------------+\nFor the first user, the windows in question are between dates:\n    - 2020-10-20 and 2020-11-28 with a total of 39 days. \n    - 2020-11-28 and 2020-12-3 with a total of 5 days. \n    - 2020-12-3 and 2021-1-1 with a total of 29 days.\nMaking the biggest window the one with 39 days.\nFor the second user, the windows in question are between dates:\n    - 2020-10-5 and 2020-12-9 with a total of 65 days.\n    - 2020-12-9 and 2021-1-1 with a total of 23 days.\nMaking the biggest window the one with 65 days.\nFor the third user, the only window in question is between dates 2020-11-11 and 2021-1-1 with a total of 51 days.
\n", "content_cn": "

\u8868\uff1a\u00a0UserVisits

\n\n
+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| user_id     | int  |\n| visit_date  | date |\n+-------------+------+\n\u8be5\u8868\u6ca1\u6709\u4e3b\u952e\u3002\n\u8be5\u8868\u5305\u542b\u7528\u6237\u8bbf\u95ee\u67d0\u7279\u5b9a\u96f6\u552e\u5546\u7684\u65e5\u671f\u65e5\u5fd7\u3002
\n\n

\u00a0

\n\n

\u5047\u8bbe\u4eca\u5929\u7684\u65e5\u671f\u662f\u00a0'2021-1-1'\u00a0\u3002

\n\n

\u7f16\u5199 SQL \u8bed\u53e5\uff0c\u5bf9\u4e8e\u6bcf\u4e2a\u00a0user_id\u00a0\uff0c\u6c42\u51fa\u6bcf\u6b21\u8bbf\u95ee\u53ca\u5176\u4e0b\u4e00\u4e2a\u8bbf\u95ee\uff08\u82e5\u8be5\u6b21\u8bbf\u95ee\u662f\u6700\u540e\u4e00\u6b21\uff0c\u5219\u4e3a\u4eca\u5929\uff09\u4e4b\u95f4\u6700\u5927\u7684\u7a7a\u6863\u671f\u5929\u6570\u00a0window\u00a0\u3002

\n\n

\u8fd4\u56de\u7ed3\u679c\u8868\uff0c\u6309\u7528\u6237\u7f16\u53f7\u00a0user_id\u00a0\u6392\u5e8f\u3002

\n\n

\u67e5\u8be2\u683c\u5f0f\u5982\u4e0b\u793a\u4f8b\u6240\u793a\uff1a

\n\n

\u00a0

\n\n
UserVisits \u8868\uff1a\n+---------+------------+\n| user_id | visit_date |\n+---------+------------+\n| 1       | 2020-11-28 |\n| 1       | 2020-10-20 |\n| 1       | 2020-12-3  |\n| 2       | 2020-10-5  |\n| 2       | 2020-12-9  |\n| 3       | 2020-11-11 |\n+---------+------------+\n\u7ed3\u679c\u8868\uff1a\n+---------+---------------+\n| user_id | biggest_window|\n+---------+---------------+\n| 1       | 39            |\n| 2       | 65            |\n| 3       | 51            |\n+---------+---------------+\n\u5bf9\u4e8e\u7b2c\u4e00\u4e2a\u7528\u6237\uff0c\u95ee\u9898\u4e2d\u7684\u7a7a\u6863\u671f\u5728\u4ee5\u4e0b\u65e5\u671f\u4e4b\u95f4\uff1a\n    - 2020-10-20 \u81f3 2020-11-28 \uff0c\u5171\u8ba1 39 \u5929\u3002\n    - 2020-11-28 \u81f3 2020-12-3 \uff0c\u5171\u8ba1 5 \u5929\u3002\n    - 2020-12-3 \u81f3 2021-1-1 \uff0c\u5171\u8ba1 29 \u5929\u3002\n\u7531\u6b64\u5f97\u51fa\uff0c\u6700\u5927\u7684\u7a7a\u6863\u671f\u4e3a 39 \u5929\u3002\n\u5bf9\u4e8e\u7b2c\u4e8c\u4e2a\u7528\u6237\uff0c\u95ee\u9898\u4e2d\u7684\u7a7a\u6863\u671f\u5728\u4ee5\u4e0b\u65e5\u671f\u4e4b\u95f4\uff1a\n    - 2020-10-5 \u81f3 2020-12-9 \uff0c\u5171\u8ba1 65 \u5929\u3002\n    - 2020-12-9 \u81f3 2021-1-1 \uff0c\u5171\u8ba1 23 \u5929\u3002\n\u7531\u6b64\u5f97\u51fa\uff0c\u6700\u5927\u7684\u7a7a\u6863\u671f\u4e3a 65 \u5929\u3002\n\u5bf9\u4e8e\u7b2c\u4e09\u4e2a\u7528\u6237\uff0c\u95ee\u9898\u4e2d\u7684\u552f\u4e00\u7a7a\u6863\u671f\u5728 2020-11-11 \u81f3 2021-1-1 \u4e4b\u95f4\uff0c\u5171\u8ba1 51 \u5929\u3002
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1709](https://leetcode-cn.com/problems/biggest-window-between-visits)", "[\u8bbf\u95ee\u65e5\u671f\u4e4b\u95f4\u6700\u5927\u7684\u7a7a\u6863\u671f](/solution/1700-1799/1709.Biggest%20Window%20Between%20Visits/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1709](https://leetcode.com/problems/biggest-window-between-visits)", "[Biggest Window Between Visits](/solution/1700-1799/1709.Biggest%20Window%20Between%20Visits/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1851", "frontend_question_id": "1751", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-number-of-events-that-can-be-attended-ii", "url_en": "https://leetcode.com/problems/maximum-number-of-events-that-can-be-attended-ii", "relative_path_cn": "/solution/1700-1799/1751.Maximum%20Number%20of%20Events%20That%20Can%20Be%20Attended%20II/README.md", "relative_path_en": "/solution/1700-1799/1751.Maximum%20Number%20of%20Events%20That%20Can%20Be%20Attended%20II/README_EN.md", "title_cn": "\u6700\u591a\u53ef\u4ee5\u53c2\u52a0\u7684\u4f1a\u8bae\u6570\u76ee II", "title_en": "Maximum Number of Events That Can Be Attended II", "question_title_slug": "maximum-number-of-events-that-can-be-attended-ii", "content_en": "

You are given an array of events where events[i] = [startDayi, endDayi, valuei]. The ith event starts at startDayi and ends at endDayi, and if you attend this event, you will receive a value of valuei. You are also given an integer k which represents the maximum number of events you can attend.

\n\n

You can only attend one event at a time. If you choose to attend an event, you must attend the entire event. Note that the end day is inclusive: that is, you cannot attend two events where one of them starts and the other ends on the same day.

\n\n

Return the maximum sum of values that you can receive by attending events.

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: events = [[1,2,4],[3,4,3],[2,3,1]], k = 2\nOutput: 7\nExplanation: Choose the green events, 0 and 1 (0-indexed) for a total value of 4 + 3 = 7.
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: events = [[1,2,4],[3,4,3],[2,3,10]], k = 2\nOutput: 10\nExplanation: Choose event 2 for a total value of 10.\nNotice that you cannot attend any other event as they overlap, and that you do not have to attend k events.
\n\n

Example 3:

\n\n

\"\"

\n\n
\nInput: events = [[1,1,1],[2,2,2],[3,3,3],[4,4,4]], k = 3\nOutput: 9\nExplanation: Although the events do not overlap, you can only attend 3 events. Pick the highest valued three.
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= k <= events.length
  • \n\t
  • 1 <= k * events.length <= 106
  • \n\t
  • 1 <= startDayi <= endDayi <= 109
  • \n\t
  • 1 <= valuei <= 106
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u00a0events\u00a0\u6570\u7ec4\uff0c\u5176\u4e2d\u00a0events[i] = [startDayi, endDayi, valuei]\u00a0\uff0c\u8868\u793a\u7b2c\u00a0i\u00a0\u4e2a\u4f1a\u8bae\u5728\u00a0startDayi\u00a0\u5929\u5f00\u59cb\uff0c\u7b2c\u00a0endDayi\u00a0\u5929\u7ed3\u675f\uff0c\u5982\u679c\u4f60\u53c2\u52a0\u8fd9\u4e2a\u4f1a\u8bae\uff0c\u4f60\u80fd\u5f97\u5230\u4ef7\u503c\u00a0valuei\u00a0\u3002\u540c\u65f6\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u00a0k\u00a0\u8868\u793a\u4f60\u80fd\u53c2\u52a0\u7684\u6700\u591a\u4f1a\u8bae\u6570\u76ee\u3002

\n\n

\u4f60\u540c\u4e00\u65f6\u95f4\u53ea\u80fd\u53c2\u52a0\u4e00\u4e2a\u4f1a\u8bae\u3002\u5982\u679c\u4f60\u9009\u62e9\u53c2\u52a0\u67d0\u4e2a\u4f1a\u8bae\uff0c\u90a3\u4e48\u4f60\u5fc5\u987b \u5b8c\u6574\u00a0\u5730\u53c2\u52a0\u5b8c\u8fd9\u4e2a\u4f1a\u8bae\u3002\u4f1a\u8bae\u7ed3\u675f\u65e5\u671f\u662f\u5305\u542b\u5728\u4f1a\u8bae\u5185\u7684\uff0c\u4e5f\u5c31\u662f\u8bf4\u4f60\u4e0d\u80fd\u540c\u65f6\u53c2\u52a0\u4e00\u4e2a\u5f00\u59cb\u65e5\u671f\u4e0e\u53e6\u4e00\u4e2a\u7ed3\u675f\u65e5\u671f\u76f8\u540c\u7684\u4e24\u4e2a\u4f1a\u8bae\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u80fd\u5f97\u5230\u7684\u4f1a\u8bae\u4ef7\u503c\u00a0\u6700\u5927\u548c\u00a0\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1aevents = [[1,2,4],[3,4,3],[2,3,1]], k = 2\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\u9009\u62e9\u7eff\u8272\u7684\u6d3b\u52a8\u4f1a\u8bae 0 \u548c 1\uff0c\u5f97\u5230\u603b\u4ef7\u503c\u548c\u4e3a 4 + 3 = 7 \u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1aevents = [[1,2,4],[3,4,3],[2,3,10]], k = 2\n\u8f93\u51fa\uff1a10\n\u89e3\u91ca\uff1a\u53c2\u52a0\u4f1a\u8bae 2 \uff0c\u5f97\u5230\u4ef7\u503c\u548c\u4e3a 10 \u3002\n\u4f60\u6ca1\u6cd5\u518d\u53c2\u52a0\u522b\u7684\u4f1a\u8bae\u4e86\uff0c\u56e0\u4e3a\u8ddf\u4f1a\u8bae 2 \u6709\u91cd\u53e0\u3002\u4f60 \u4e0d\u00a0\u9700\u8981\u53c2\u52a0\u6ee1 k \u4e2a\u4f1a\u8bae\u3002
\n\n

\u793a\u4f8b 3\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1aevents = [[1,1,1],[2,2,2],[3,3,3],[4,4,4]], k = 3\n\u8f93\u51fa\uff1a9\n\u89e3\u91ca\uff1a\u5c3d\u7ba1\u4f1a\u8bae\u4e92\u4e0d\u91cd\u53e0\uff0c\u4f60\u53ea\u80fd\u53c2\u52a0 3 \u4e2a\u4f1a\u8bae\uff0c\u6240\u4ee5\u9009\u62e9\u4ef7\u503c\u6700\u5927\u7684 3 \u4e2a\u4f1a\u8bae\u3002
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= k <= events.length
  • \n\t
  • 1 <= k * events.length <= 106
  • \n\t
  • 1 <= startDayi <= endDayi <= 109
  • \n\t
  • 1 <= valuei <= 106
  • \n
\n", "tags_en": ["Binary Search", "Dynamic Programming"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxValue(vector>& events, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxValue(int[][] events, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxValue(self, events, k):\n \"\"\"\n :type events: List[List[int]]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxValue(self, events: List[List[int]], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxValue(int** events, int eventsSize, int* eventsColSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxValue(int[][] events, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} events\n * @param {number} k\n * @return {number}\n */\nvar maxValue = function(events, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} events\n# @param {Integer} k\n# @return {Integer}\ndef max_value(events, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxValue(_ events: [[Int]], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxValue(events [][]int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxValue(events: Array[Array[Int]], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxValue(events: Array, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_value(events: Vec>, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $events\n * @param Integer $k\n * @return Integer\n */\n function maxValue($events, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxValue(events: number[][], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-value events k)\n (-> (listof (listof exact-integer?)) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1751](https://leetcode-cn.com/problems/maximum-number-of-events-that-can-be-attended-ii)", "[\u6700\u591a\u53ef\u4ee5\u53c2\u52a0\u7684\u4f1a\u8bae\u6570\u76ee II](/solution/1700-1799/1751.Maximum%20Number%20of%20Events%20That%20Can%20Be%20Attended%20II/README.md)", "`\u4e8c\u5206\u67e5\u627e`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1751](https://leetcode.com/problems/maximum-number-of-events-that-can-be-attended-ii)", "[Maximum Number of Events That Can Be Attended II](/solution/1700-1799/1751.Maximum%20Number%20of%20Events%20That%20Can%20Be%20Attended%20II/README_EN.md)", "`Binary Search`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "1850", "frontend_question_id": "1750", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-length-of-string-after-deleting-similar-ends", "url_en": "https://leetcode.com/problems/minimum-length-of-string-after-deleting-similar-ends", "relative_path_cn": "/solution/1700-1799/1750.Minimum%20Length%20of%20String%20After%20Deleting%20Similar%20Ends/README.md", "relative_path_en": "/solution/1700-1799/1750.Minimum%20Length%20of%20String%20After%20Deleting%20Similar%20Ends/README_EN.md", "title_cn": "\u5220\u9664\u5b57\u7b26\u4e32\u4e24\u7aef\u76f8\u540c\u5b57\u7b26\u540e\u7684\u6700\u77ed\u957f\u5ea6", "title_en": "Minimum Length of String After Deleting Similar Ends", "question_title_slug": "minimum-length-of-string-after-deleting-similar-ends", "content_en": "

Given a string s consisting only of characters 'a', 'b', and 'c'. You are asked to apply the following algorithm on the string any number of times:

\n\n
    \n\t
  1. Pick a non-empty prefix from the string s where all the characters in the prefix are equal.
  2. \n\t
  3. Pick a non-empty suffix from the string s where all the characters in this suffix are equal.
  4. \n\t
  5. The prefix and the suffix should not intersect at any index.
  6. \n\t
  7. The characters from the prefix and suffix must be the same.
  8. \n\t
  9. Delete both the prefix and the suffix.
  10. \n
\n\n

Return the minimum length of s after performing the above operation any number of times (possibly zero times).

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "ca"\nOutput: 2\nExplanation: You can't remove any characters, so the string stays as is.\n
\n\n

Example 2:

\n\n
\nInput: s = "cabaabac"\nOutput: 0\nExplanation: An optimal sequence of operations is:\n- Take prefix = "c" and suffix = "c" and remove them, s = "abaaba".\n- Take prefix = "a" and suffix = "a" and remove them, s = "baab".\n- Take prefix = "b" and suffix = "b" and remove them, s = "aa".\n- Take prefix = "a" and suffix = "a" and remove them, s = "".
\n\n

Example 3:

\n\n
\nInput: s = "aabccabba"\nOutput: 3\nExplanation: An optimal sequence of operations is:\n- Take prefix = "aa" and suffix = "a" and remove them, s = "bccabb".\n- Take prefix = "b" and suffix = "bb" and remove them, s = "cca".\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 105
  • \n\t
  • s only consists of characters 'a', 'b', and 'c'.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u53ea\u5305\u542b\u5b57\u7b26 'a'\uff0c'b'\u00a0\u548c 'c'\u00a0\u7684\u5b57\u7b26\u4e32\u00a0s\u00a0\uff0c\u4f60\u53ef\u4ee5\u6267\u884c\u4e0b\u9762\u8fd9\u4e2a\u64cd\u4f5c\uff085 \u4e2a\u6b65\u9aa4\uff09\u4efb\u610f\u6b21\uff1a

\n\n
    \n\t
  1. \u9009\u62e9\u5b57\u7b26\u4e32 s\u00a0\u4e00\u4e2a \u975e\u7a7a \u7684\u524d\u7f00\uff0c\u8fd9\u4e2a\u524d\u7f00\u7684\u6240\u6709\u5b57\u7b26\u90fd\u76f8\u540c\u3002
  2. \n\t
  3. \u9009\u62e9\u5b57\u7b26\u4e32 s\u00a0\u4e00\u4e2a \u975e\u7a7a \u7684\u540e\u7f00\uff0c\u8fd9\u4e2a\u540e\u7f00\u7684\u6240\u6709\u5b57\u7b26\u90fd\u76f8\u540c\u3002
  4. \n\t
  5. \u524d\u7f00\u548c\u540e\u7f00\u5728\u5b57\u7b26\u4e32\u4e2d\u4efb\u610f\u4f4d\u7f6e\u90fd\u4e0d\u80fd\u6709\u4ea4\u96c6\u3002
  6. \n\t
  7. \u524d\u7f00\u548c\u540e\u7f00\u5305\u542b\u7684\u6240\u6709\u5b57\u7b26\u90fd\u8981\u76f8\u540c\u3002
  8. \n\t
  9. \u540c\u65f6\u5220\u9664\u524d\u7f00\u548c\u540e\u7f00\u3002
  10. \n
\n\n

\u8bf7\u4f60\u8fd4\u56de\u5bf9\u5b57\u7b26\u4e32 s\u00a0\u6267\u884c\u4e0a\u9762\u64cd\u4f5c\u4efb\u610f\u6b21\u4ee5\u540e\uff08\u53ef\u80fd 0 \u6b21\uff09\uff0c\u80fd\u5f97\u5230\u7684 \u6700\u77ed\u957f\u5ea6\u00a0\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"ca\"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u4f60\u6ca1\u6cd5\u5220\u9664\u4efb\u4f55\u4e00\u4e2a\u5b57\u7b26\uff0c\u6240\u4ee5\u5b57\u7b26\u4e32\u957f\u5ea6\u4ecd\u7136\u4fdd\u6301\u4e0d\u53d8\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"cabaabac\"\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6700\u4f18\u64cd\u4f5c\u5e8f\u5217\u4e3a\uff1a\n- \u9009\u62e9\u524d\u7f00 \"c\" \u548c\u540e\u7f00 \"c\" \u5e76\u5220\u9664\u5b83\u4eec\uff0c\u5f97\u5230 s = \"abaaba\" \u3002\n- \u9009\u62e9\u524d\u7f00 \"a\" \u548c\u540e\u7f00 \"a\" \u5e76\u5220\u9664\u5b83\u4eec\uff0c\u5f97\u5230 s = \"baab\" \u3002\n- \u9009\u62e9\u524d\u7f00 \"b\" \u548c\u540e\u7f00 \"b\" \u5e76\u5220\u9664\u5b83\u4eec\uff0c\u5f97\u5230 s = \"aa\" \u3002\n- \u9009\u62e9\u524d\u7f00 \"a\" \u548c\u540e\u7f00 \"a\" \u5e76\u5220\u9664\u5b83\u4eec\uff0c\u5f97\u5230 s = \"\" \u3002
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"aabccabba\"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6700\u4f18\u64cd\u4f5c\u5e8f\u5217\u4e3a\uff1a\n- \u9009\u62e9\u524d\u7f00 \"aa\" \u548c\u540e\u7f00 \"a\" \u5e76\u5220\u9664\u5b83\u4eec\uff0c\u5f97\u5230 s = \"bccabb\" \u3002\n- \u9009\u62e9\u524d\u7f00 \"b\" \u548c\u540e\u7f00 \"bb\" \u5e76\u5220\u9664\u5b83\u4eec\uff0c\u5f97\u5230 s = \"cca\" \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length <= 105
  • \n\t
  • s\u00a0\u53ea\u5305\u542b\u5b57\u7b26\u00a0'a'\uff0c'b'\u00a0\u548c\u00a0'c'\u00a0\u3002
  • \n
\n", "tags_en": ["Two Pointers"], "tags_cn": ["\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minimumLength(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minimumLength(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimumLength(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimumLength(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minimumLength(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinimumLength(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar minimumLength = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef minimum_length(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimumLength(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimumLength(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimumLength(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimumLength(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimum_length(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function minimumLength($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimumLength(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimum-length s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1750](https://leetcode-cn.com/problems/minimum-length-of-string-after-deleting-similar-ends)", "[\u5220\u9664\u5b57\u7b26\u4e32\u4e24\u7aef\u76f8\u540c\u5b57\u7b26\u540e\u7684\u6700\u77ed\u957f\u5ea6](/solution/1700-1799/1750.Minimum%20Length%20of%20String%20After%20Deleting%20Similar%20Ends/README.md)", "`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1750](https://leetcode.com/problems/minimum-length-of-string-after-deleting-similar-ends)", "[Minimum Length of String After Deleting Similar Ends](/solution/1700-1799/1750.Minimum%20Length%20of%20String%20After%20Deleting%20Similar%20Ends/README_EN.md)", "`Two Pointers`", "Medium", ""]}, {"question_id": "1849", "frontend_question_id": "1749", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-absolute-sum-of-any-subarray", "url_en": "https://leetcode.com/problems/maximum-absolute-sum-of-any-subarray", "relative_path_cn": "/solution/1700-1799/1749.Maximum%20Absolute%20Sum%20of%20Any%20Subarray/README.md", "relative_path_en": "/solution/1700-1799/1749.Maximum%20Absolute%20Sum%20of%20Any%20Subarray/README_EN.md", "title_cn": "\u4efb\u610f\u5b50\u6570\u7ec4\u548c\u7684\u7edd\u5bf9\u503c\u7684\u6700\u5927\u503c", "title_en": "Maximum Absolute Sum of Any Subarray", "question_title_slug": "maximum-absolute-sum-of-any-subarray", "content_en": "

You are given an integer array nums. The absolute sum of a subarray [numsl, numsl+1, ..., numsr-1, numsr] is abs(numsl + numsl+1 + ... + numsr-1 + numsr).

\n\n

Return the maximum absolute sum of any (possibly empty) subarray of nums.

\n\n

Note that abs(x) is defined as follows:

\n\n
    \n\t
  • If x is a negative integer, then abs(x) = -x.
  • \n\t
  • If x is a non-negative integer, then abs(x) = x.
  • \n
\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [1,-3,2,3,-4]\nOutput: 5\nExplanation: The subarray [2,3] has absolute sum = abs(2+3) = abs(5) = 5.\n
\n\n

Example 2:

\n\n
\nInput: nums = [2,-5,1,-4,3,-2]\nOutput: 8\nExplanation: The subarray [-5,1,-4] has absolute sum = abs(-5+1-4) = abs(-8) = 8.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 105
  • \n\t
  • -104 <= nums[i] <= 104
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0nums\u00a0\u3002\u4e00\u4e2a\u5b50\u6570\u7ec4\u00a0[numsl, numsl+1, ..., numsr-1, numsr]\u00a0\u7684 \u548c\u7684\u7edd\u5bf9\u503c\u00a0\u4e3a\u00a0abs(numsl + numsl+1 + ... + numsr-1 + numsr)\u00a0\u3002

\n\n

\u8bf7\u4f60\u627e\u51fa nums\u00a0\u4e2d \u548c\u7684\u7edd\u5bf9\u503c \u6700\u5927\u7684\u4efb\u610f\u5b50\u6570\u7ec4\uff08\u53ef\u80fd\u4e3a\u7a7a\uff09\uff0c\u5e76\u8fd4\u56de\u8be5 \u6700\u5927\u503c\u00a0\u3002

\n\n

abs(x)\u00a0\u5b9a\u4e49\u5982\u4e0b\uff1a

\n\n
    \n\t
  • \u5982\u679c\u00a0x\u00a0\u662f\u8d1f\u6574\u6570\uff0c\u90a3\u4e48\u00a0abs(x) = -x\u00a0\u3002
  • \n\t
  • \u5982\u679c\u00a0x\u00a0\u662f\u975e\u8d1f\u6574\u6570\uff0c\u90a3\u4e48\u00a0abs(x) = x\u00a0\u3002
  • \n
\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [1,-3,2,3,-4]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u5b50\u6570\u7ec4 [2,3] \u548c\u7684\u7edd\u5bf9\u503c\u6700\u5927\uff0c\u4e3a abs(2+3) = abs(5) = 5 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [2,-5,1,-4,3,-2]\n\u8f93\u51fa\uff1a8\n\u89e3\u91ca\uff1a\u5b50\u6570\u7ec4 [-5,1,-4] \u548c\u7684\u7edd\u5bf9\u503c\u6700\u5927\uff0c\u4e3a abs(-5+1-4) = abs(-8) = 8 \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 105
  • \n\t
  • -104 <= nums[i] <= 104
  • \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxAbsoluteSum(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxAbsoluteSum(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxAbsoluteSum(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxAbsoluteSum(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxAbsoluteSum(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxAbsoluteSum(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar maxAbsoluteSum = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef max_absolute_sum(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxAbsoluteSum(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxAbsoluteSum(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxAbsoluteSum(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxAbsoluteSum(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_absolute_sum(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function maxAbsoluteSum($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxAbsoluteSum(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-absolute-sum nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1749](https://leetcode-cn.com/problems/maximum-absolute-sum-of-any-subarray)", "[\u4efb\u610f\u5b50\u6570\u7ec4\u548c\u7684\u7edd\u5bf9\u503c\u7684\u6700\u5927\u503c](/solution/1700-1799/1749.Maximum%20Absolute%20Sum%20of%20Any%20Subarray/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1749](https://leetcode.com/problems/maximum-absolute-sum-of-any-subarray)", "[Maximum Absolute Sum of Any Subarray](/solution/1700-1799/1749.Maximum%20Absolute%20Sum%20of%20Any%20Subarray/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1848", "frontend_question_id": "1748", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sum-of-unique-elements", "url_en": "https://leetcode.com/problems/sum-of-unique-elements", "relative_path_cn": "/solution/1700-1799/1748.Sum%20of%20Unique%20Elements/README.md", "relative_path_en": "/solution/1700-1799/1748.Sum%20of%20Unique%20Elements/README_EN.md", "title_cn": "\u552f\u4e00\u5143\u7d20\u7684\u548c", "title_en": "Sum of Unique Elements", "question_title_slug": "sum-of-unique-elements", "content_en": "

You are given an integer array nums. The unique elements of an array are the elements that appear exactly once in the array.

\n\n

Return the sum of all the unique elements of nums.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [1,2,3,2]\nOutput: 4\nExplanation: The unique elements are [1,3], and the sum is 4.\n
\n\n

Example 2:

\n\n
\nInput: nums = [1,1,1,1,1]\nOutput: 0\nExplanation: There are no unique elements, and the sum is 0.\n
\n\n

Example 3:

\n\n
\nInput: nums = [1,2,3,4,5]\nOutput: 15\nExplanation: The unique elements are [1,2,3,4,5], and the sum is 15.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 100
  • \n\t
  • 1 <= nums[i] <= 100
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0nums\u00a0\u3002\u6570\u7ec4\u4e2d\u552f\u4e00\u5143\u7d20\u662f\u90a3\u4e9b\u53ea\u51fa\u73b0\u00a0\u6070\u597d\u4e00\u6b21\u00a0\u7684\u5143\u7d20\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de nums\u00a0\u4e2d\u552f\u4e00\u5143\u7d20\u7684 \u548c\u00a0\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,2,3,2]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u552f\u4e00\u5143\u7d20\u4e3a [1,3] \uff0c\u548c\u4e3a 4 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,1,1,1,1]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6ca1\u6709\u552f\u4e00\u5143\u7d20\uff0c\u548c\u4e3a 0 \u3002\n
\n\n

\u793a\u4f8b 3 \uff1a

\n\n
\u8f93\u5165\uff1anums = [1,2,3,4,5]\n\u8f93\u51fa\uff1a15\n\u89e3\u91ca\uff1a\u552f\u4e00\u5143\u7d20\u4e3a [1,2,3,4,5] \uff0c\u548c\u4e3a 15 \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 100
  • \n\t
  • 1 <= nums[i] <= 100
  • \n
\n", "tags_en": ["Array", "Hash Table"], "tags_cn": ["\u6570\u7ec4", "\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int sumOfUnique(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int sumOfUnique(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def sumOfUnique(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def sumOfUnique(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint sumOfUnique(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SumOfUnique(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar sumOfUnique = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef sum_of_unique(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func sumOfUnique(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func sumOfUnique(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def sumOfUnique(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun sumOfUnique(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sum_of_unique(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function sumOfUnique($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function sumOfUnique(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (sum-of-unique nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1748](https://leetcode-cn.com/problems/sum-of-unique-elements)", "[\u552f\u4e00\u5143\u7d20\u7684\u548c](/solution/1700-1799/1748.Sum%20of%20Unique%20Elements/README.md)", "`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[1748](https://leetcode.com/problems/sum-of-unique-elements)", "[Sum of Unique Elements](/solution/1700-1799/1748.Sum%20of%20Unique%20Elements/README_EN.md)", "`Array`,`Hash Table`", "Easy", ""]}, {"question_id": "1847", "frontend_question_id": "1708", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/largest-subarray-length-k", "url_en": "https://leetcode.com/problems/largest-subarray-length-k", "relative_path_cn": "/solution/1700-1799/1708.Largest%20Subarray%20Length%20K/README.md", "relative_path_en": "/solution/1700-1799/1708.Largest%20Subarray%20Length%20K/README_EN.md", "title_cn": "\u957f\u5ea6\u4e3a K \u7684\u6700\u5927\u5b50\u6570\u7ec4", "title_en": "Largest Subarray Length K", "question_title_slug": "largest-subarray-length-k", "content_en": "

An array A is larger than some array B if for the first index i where A[i] != B[i], A[i] > B[i].

\n\n

For example, consider 0-indexing:

\n\n
    \n\t
  • [1,3,2,4] > [1,2,2,4], since at index 1, 3 > 2.
  • \n\t
  • [1,4,4,4] < [2,1,1,1], since at index 0, 1 < 2.
  • \n
\n\n

A subarray is a contiguous subsequence of the array.

\n\n

Given an integer array nums of distinct integers, return the largest subarray of nums of length k.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [1,4,5,2,3], k = 3\nOutput: [5,2,3]\nExplanation: The subarrays of size 3 are: [1,4,5], [4,5,2], and [5,2,3].\nOf these, [5,2,3] is the largest.
\n\n

Example 2:

\n\n
\nInput: nums = [1,4,5,2,3], k = 4\nOutput: [4,5,2,3]\nExplanation: The subarrays of size 4 are: [1,4,5,2], and [4,5,2,3].\nOf these, [4,5,2,3] is the largest.
\n\n

Example 3:

\n\n
\nInput: nums = [1,4,5,2,3], k = 1\nOutput: [5]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= k <= nums.length <= 105
  • \n\t
  • 1 <= nums[i] <= 109
  • \n\t
  • All the integers of nums are unique.
  • \n
\n\n

 

\nFollow up: What if the integers in nums are not distinct?", "content_cn": "

\u5728\u6570\u7ec4\u00a0A\u00a0\u548c\u6570\u7ec4 B\u00a0\u4e2d\uff0c\u5bf9\u4e8e\u7b2c\u4e00\u4e2a\u6ee1\u8db3 A[i] != B[i]\u00a0\u7684\u7d22\u5f15\u00a0i\u00a0\uff0c\u5f53 A[i] > B[i]\u00a0\u65f6\uff0c\u6570\u7ec4 A \u5927\u4e8e\u6570\u7ec4 B\u3002

\n\n

\u4f8b\u5982\uff0c\u5bf9\u4e8e\u7d22\u5f15\u4ece 0 \u5f00\u59cb\u7684\u6570\u7ec4\uff1a

\n\n
    \n\t
  • [1,3,2,4] > [1,2,2,4]\u00a0\uff0c\u56e0\u4e3a\u5728\u7d22\u5f15\u00a01\u00a0\u4e0a\uff0c\u00a03 > 2\u3002
  • \n\t
  • [1,4,4,4] < [2,1,1,1]\u00a0\uff0c\u56e0\u4e3a\u5728\u7d22\u5f15 0 \u4e0a\uff0c\u00a01 < 2\u3002
  • \n
\n\n

\u4e00\u4e2a\u6570\u7ec4\u7684\u5b50\u6570\u7ec4\u662f\u539f\u6570\u7ec4\u4e0a\u7684\u4e00\u4e2a\u8fde\u7eed\u5b50\u5e8f\u5217\u3002

\n\n

\u7ed9\u5b9a\u4e00\u4e2a\u5305\u542b\u4e0d\u540c\u6574\u6570\u7684\u6574\u6570\u7c7b\u578b\u6570\u7ec4\u00a0nums\u00a0\uff0c\u8fd4\u56de\u00a0nums\u00a0\u4e2d\u957f\u5ea6\u4e3a k \u7684\u6700\u5927\u5b50\u6570\u7ec4\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1:

\n\n
\u8f93\u5165: nums = [1,4,5,2,3], k = 3\n\u8f93\u51fa: [5,2,3]\n\u89e3\u91ca: \u957f\u5ea6\u4e3a 3 \u7684\u5b50\u6570\u7ec4\u6709\uff1a [1,4,5]\u3001 [4,5,2] \u548c [5,2,3]\u3002\n\u5728\u8fd9\u4e9b\u6570\u7ec4\u4e2d\uff0c [5,2,3] \u662f\u6700\u5927\u7684\u3002
\n\n

Example 2:

\n\n
\u8f93\u5165: nums = [1,4,5,2,3], k = 4\n\u8f93\u51fa: [4,5,2,3]\n\u89e3\u91ca: \u957f\u5ea6\u4e3a 4 \u7684\u5b50\u6570\u7ec4\u6709\uff1a [1,4,5,2] \u548c [4,5,2,3]\u3002\n\u5728\u8fd9\u4e9b\u6570\u7ec4\u4e2d\uff0c [4,5,2,3] \u662f\u6700\u5927\u7684\u3002
\n\n

\u793a\u4f8b 3:

\n\n
\u8f93\u5165: nums = [1,4,5,2,3], k = 1\n\u8f93\u51fa: [5]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= k <= nums.length <= 105
  • \n\t
  • 1 <= nums[i] <= 109
  • \n\t
  • nums\u00a0\u4e2d\u7684\u6240\u6709\u6574\u6570\u90fd\u662f\u4e0d\u540c\u7684\u3002
  • \n
\n\n

\u00a0

\n\u8fdb\u9636\uff1a\u5982\u679c\u5141\u8bb8\u00a0nums\u00a0\u4e2d\u5b58\u5728\u76f8\u540c\u5143\u7d20\uff0c\u4f60\u8be5\u5982\u4f55\u89e3\u51b3\u8be5\u95ee\u9898\uff1f", "tags_en": ["Greedy", "Array"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector largestSubarray(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] largestSubarray(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def largestSubarray(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def largestSubarray(self, nums: List[int], k: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* largestSubarray(int* nums, int numsSize, int k, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] LargestSubarray(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number[]}\n */\nvar largestSubarray = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer[]}\ndef largest_subarray(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func largestSubarray(_ nums: [Int], _ k: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func largestSubarray(nums []int, k int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def largestSubarray(nums: Array[Int], k: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun largestSubarray(nums: IntArray, k: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn largest_subarray(nums: Vec, k: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer[]\n */\n function largestSubarray($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function largestSubarray(nums: number[], k: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (largest-subarray nums k)\n (-> (listof exact-integer?) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1708](https://leetcode-cn.com/problems/largest-subarray-length-k)", "[\u957f\u5ea6\u4e3a K \u7684\u6700\u5927\u5b50\u6570\u7ec4](/solution/1700-1799/1708.Largest%20Subarray%20Length%20K/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u7ec4`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1708](https://leetcode.com/problems/largest-subarray-length-k)", "[Largest Subarray Length K](/solution/1700-1799/1708.Largest%20Subarray%20Length%20K/README_EN.md)", "`Greedy`,`Array`", "Easy", "\ud83d\udd12"]}, {"question_id": "1845", "frontend_question_id": "1727", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/largest-submatrix-with-rearrangements", "url_en": "https://leetcode.com/problems/largest-submatrix-with-rearrangements", "relative_path_cn": "/solution/1700-1799/1727.Largest%20Submatrix%20With%20Rearrangements/README.md", "relative_path_en": "/solution/1700-1799/1727.Largest%20Submatrix%20With%20Rearrangements/README_EN.md", "title_cn": "\u91cd\u65b0\u6392\u5217\u540e\u7684\u6700\u5927\u5b50\u77e9\u9635", "title_en": "Largest Submatrix With Rearrangements", "question_title_slug": "largest-submatrix-with-rearrangements", "content_en": "

You are given a binary matrix matrix of size m x n, and you are allowed to rearrange the columns of the matrix in any order.

\n\n

Return the area of the largest submatrix within matrix where every element of the submatrix is 1 after reordering the columns optimally.

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: matrix = [[0,0,1],[1,1,1],[1,0,1]]\nOutput: 4\nExplanation: You can rearrange the columns as shown above.\nThe largest submatrix of 1s, in bold, has an area of 4.\n
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: matrix = [[1,0,1,0,1]]\nOutput: 3\nExplanation: You can rearrange the columns as shown above.\nThe largest submatrix of 1s, in bold, has an area of 3.\n
\n\n

Example 3:

\n\n
\nInput: matrix = [[1,1,0],[1,0,1]]\nOutput: 2\nExplanation: Notice that you must rearrange entire columns, and there is no way to make a submatrix of 1s larger than an area of 2.
\n\n

Example 4:

\n\n
\nInput: matrix = [[0,0],[0,0]]\nOutput: 0\nExplanation: As there are no 1s, no submatrix of 1s can be formed and the area is 0.
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • m == matrix.length
  • \n\t
  • n == matrix[i].length
  • \n\t
  • 1 <= m * n <= 105
  • \n\t
  • matrix[i][j] is 0 or 1.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u4e8c\u8fdb\u5236\u77e9\u9635\u00a0matrix\u00a0\uff0c\u5b83\u7684\u5927\u5c0f\u4e3a\u00a0m x n\u00a0\uff0c\u4f60\u53ef\u4ee5\u5c06 matrix\u00a0\u4e2d\u7684 \u5217\u00a0\u6309\u4efb\u610f\u987a\u5e8f\u91cd\u65b0\u6392\u5217\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u6700\u4f18\u65b9\u6848\u4e0b\u5c06 matrix\u00a0\u91cd\u65b0\u6392\u5217\u540e\uff0c\u5168\u662f 1\u00a0\u7684\u5b50\u77e9\u9635\u9762\u79ef\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1amatrix = [[0,0,1],[1,1,1],[1,0,1]]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u6309\u7167\u4e0a\u56fe\u65b9\u5f0f\u91cd\u65b0\u6392\u5217\u77e9\u9635\u7684\u6bcf\u4e00\u5217\u3002\n\u6700\u5927\u7684\u5168 1 \u5b50\u77e9\u9635\u662f\u4e0a\u56fe\u4e2d\u52a0\u7c97\u7684\u90e8\u5206\uff0c\u9762\u79ef\u4e3a 4 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1amatrix = [[1,0,1,0,1]]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u6309\u7167\u4e0a\u56fe\u65b9\u5f0f\u91cd\u65b0\u6392\u5217\u77e9\u9635\u7684\u6bcf\u4e00\u5217\u3002\n\u6700\u5927\u7684\u5168 1 \u5b50\u77e9\u9635\u662f\u4e0a\u56fe\u4e2d\u52a0\u7c97\u7684\u90e8\u5206\uff0c\u9762\u79ef\u4e3a 3 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1amatrix = [[1,1,0],[1,0,1]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u7531\u4e8e\u4f60\u53ea\u80fd\u6574\u5217\u6574\u5217\u91cd\u65b0\u6392\u5e03\uff0c\u6240\u4ee5\u6ca1\u6709\u6bd4\u9762\u79ef\u4e3a 2 \u66f4\u5927\u7684\u5168 1 \u5b50\u77e9\u5f62\u3002
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1amatrix = [[0,0],[0,0]]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u7531\u4e8e\u77e9\u9635\u4e2d\u6ca1\u6709 1 \uff0c\u6ca1\u6709\u4efb\u4f55\u5168 1 \u7684\u5b50\u77e9\u9635\uff0c\u6240\u4ee5\u9762\u79ef\u4e3a 0 \u3002
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • m == matrix.length
  • \n\t
  • n == matrix[i].length
  • \n\t
  • 1 <= m * n <= 105
  • \n\t
  • matrix[i][j]\u00a0\u8981\u4e48\u662f\u00a00\u00a0\uff0c\u8981\u4e48\u662f\u00a01 \u3002
  • \n
\n", "tags_en": ["Greedy", "Sort"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6392\u5e8f"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int largestSubmatrix(vector>& matrix) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int largestSubmatrix(int[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def largestSubmatrix(self, matrix):\n \"\"\"\n :type matrix: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def largestSubmatrix(self, matrix: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint largestSubmatrix(int** matrix, int matrixSize, int* matrixColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LargestSubmatrix(int[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} matrix\n * @return {number}\n */\nvar largestSubmatrix = function(matrix) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} matrix\n# @return {Integer}\ndef largest_submatrix(matrix)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func largestSubmatrix(_ matrix: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func largestSubmatrix(matrix [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def largestSubmatrix(matrix: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun largestSubmatrix(matrix: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn largest_submatrix(matrix: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $matrix\n * @return Integer\n */\n function largestSubmatrix($matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function largestSubmatrix(matrix: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (largest-submatrix matrix)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1727](https://leetcode-cn.com/problems/largest-submatrix-with-rearrangements)", "[\u91cd\u65b0\u6392\u5217\u540e\u7684\u6700\u5927\u5b50\u77e9\u9635](/solution/1700-1799/1727.Largest%20Submatrix%20With%20Rearrangements/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6392\u5e8f`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1727](https://leetcode.com/problems/largest-submatrix-with-rearrangements)", "[Largest Submatrix With Rearrangements](/solution/1700-1799/1727.Largest%20Submatrix%20With%20Rearrangements/README_EN.md)", "`Greedy`,`Sort`", "Medium", ""]}, {"question_id": "1844", "frontend_question_id": "1742", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-number-of-balls-in-a-box", "url_en": "https://leetcode.com/problems/maximum-number-of-balls-in-a-box", "relative_path_cn": "/solution/1700-1799/1742.Maximum%20Number%20of%20Balls%20in%20a%20Box/README.md", "relative_path_en": "/solution/1700-1799/1742.Maximum%20Number%20of%20Balls%20in%20a%20Box/README_EN.md", "title_cn": "\u76d2\u5b50\u4e2d\u5c0f\u7403\u7684\u6700\u5927\u6570\u91cf", "title_en": "Maximum Number of Balls in a Box", "question_title_slug": "maximum-number-of-balls-in-a-box", "content_en": "

You are working in a ball factory where you have n balls numbered from lowLimit up to highLimit inclusive (i.e., n == highLimit - lowLimit + 1), and an infinite number of boxes numbered from 1 to infinity.

\n\n

Your job at this factory is to put each ball in the box with a number equal to the sum of digits of the ball's number. For example, the ball number 321 will be put in the box number 3 + 2 + 1 = 6 and the ball number 10 will be put in the box number 1 + 0 = 1.

\n\n

Given two integers lowLimit and highLimit, return the number of balls in the box with the most balls.

\n\n

 

\n

Example 1:

\n\n
\nInput: lowLimit = 1, highLimit = 10\nOutput: 2\nExplanation:\nBox Number:  1 2 3 4 5 6 7 8 9 10 11 ...\nBall Count:  2 1 1 1 1 1 1 1 1 0  0  ...\nBox 1 has the most number of balls with 2 balls.
\n\n

Example 2:

\n\n
\nInput: lowLimit = 5, highLimit = 15\nOutput: 2\nExplanation:\nBox Number:  1 2 3 4 5 6 7 8 9 10 11 ...\nBall Count:  1 1 1 1 2 2 1 1 1 0  0  ...\nBoxes 5 and 6 have the most number of balls with 2 balls in each.\n
\n\n

Example 3:

\n\n
\nInput: lowLimit = 19, highLimit = 28\nOutput: 2\nExplanation:\nBox Number:  1 2 3 4 5 6 7 8 9 10 11 12 ...\nBall Count:  0 1 1 1 1 1 1 1 1 2  0  0  ...\nBox 10 has the most number of balls with 2 balls.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= lowLimit <= highLimit <= 105
  • \n
\n", "content_cn": "

\u4f60\u5728\u4e00\u5bb6\u751f\u4ea7\u5c0f\u7403\u7684\u73a9\u5177\u5382\u5de5\u4f5c\uff0c\u6709 n \u4e2a\u5c0f\u7403\uff0c\u7f16\u53f7\u4ece lowLimit \u5f00\u59cb\uff0c\u5230 highLimit \u7ed3\u675f\uff08\u5305\u62ec lowLimit \u548c\u00a0highLimit \uff0c\u5373\u00a0n == highLimit - lowLimit + 1\uff09\u3002\u53e6\u6709\u65e0\u9650\u6570\u91cf\u7684\u76d2\u5b50\uff0c\u7f16\u53f7\u4ece 1 \u5230 infinity \u3002

\n\n

\u4f60\u7684\u5de5\u4f5c\u662f\u5c06\u6bcf\u4e2a\u5c0f\u7403\u653e\u5165\u76d2\u5b50\u4e2d\uff0c\u5176\u4e2d\u76d2\u5b50\u7684\u7f16\u53f7\u5e94\u5f53\u7b49\u4e8e\u5c0f\u7403\u7f16\u53f7\u4e0a\u6bcf\u4f4d\u6570\u5b57\u7684\u548c\u3002\u4f8b\u5982\uff0c\u7f16\u53f7 321 \u7684\u5c0f\u7403\u5e94\u5f53\u653e\u5165\u7f16\u53f7 3 + 2 + 1 = 6 \u7684\u76d2\u5b50\uff0c\u800c\u7f16\u53f7 10 \u7684\u5c0f\u7403\u5e94\u5f53\u653e\u5165\u7f16\u53f7 1 + 0 = 1 \u7684\u76d2\u5b50\u3002

\n\n

\u7ed9\u4f60\u4e24\u4e2a\u6574\u6570 lowLimit \u548c highLimit \uff0c\u8fd4\u56de\u653e\u6709\u6700\u591a\u5c0f\u7403\u7684\u76d2\u5b50\u4e2d\u7684\u5c0f\u7403\u6570\u91cf\u3002\u5982\u679c\u6709\u591a\u4e2a\u76d2\u5b50\u90fd\u6ee1\u8db3\u653e\u6709\u6700\u591a\u5c0f\u7403\uff0c\u53ea\u9700\u8fd4\u56de\u5176\u4e2d\u4efb\u4e00\u76d2\u5b50\u7684\u5c0f\u7403\u6570\u91cf\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1alowLimit = 1, highLimit = 10\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n\u76d2\u5b50\u7f16\u53f7\uff1a1 2 3 4 5 6 7 8 9 10 11 ...\n\u5c0f\u7403\u6570\u91cf\uff1a2 1 1 1 1 1 1 1 1 0  0  ...\n\u7f16\u53f7 1 \u7684\u76d2\u5b50\u653e\u6709\u6700\u591a\u5c0f\u7403\uff0c\u5c0f\u7403\u6570\u91cf\u4e3a 2 \u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1alowLimit = 5, highLimit = 15\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n\u76d2\u5b50\u7f16\u53f7\uff1a1 2 3 4 5 6 7 8 9 10 11 ...\n\u5c0f\u7403\u6570\u91cf\uff1a1 1 1 1 2 2 1 1 1 0  0  ...\n\u7f16\u53f7 5 \u548c 6 \u7684\u76d2\u5b50\u653e\u6709\u6700\u591a\u5c0f\u7403\uff0c\u6bcf\u4e2a\u76d2\u5b50\u4e2d\u7684\u5c0f\u7403\u6570\u91cf\u90fd\u662f 2 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1alowLimit = 19, highLimit = 28\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n\u76d2\u5b50\u7f16\u53f7\uff1a1 2 3 4 5 6 7 8 9 10 11 12 ...\n\u5c0f\u7403\u6570\u91cf\uff1a0 1 1 1 1 1 1 1 1 2  0  0  ...\n\u7f16\u53f7 10 \u7684\u76d2\u5b50\u653e\u6709\u6700\u591a\u5c0f\u7403\uff0c\u5c0f\u7403\u6570\u91cf\u4e3a 2 \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= lowLimit <= highLimit <= 105
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countBalls(int lowLimit, int highLimit) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countBalls(int lowLimit, int highLimit) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countBalls(self, lowLimit, highLimit):\n \"\"\"\n :type lowLimit: int\n :type highLimit: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countBalls(self, lowLimit: int, highLimit: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countBalls(int lowLimit, int highLimit){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountBalls(int lowLimit, int highLimit) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} lowLimit\n * @param {number} highLimit\n * @return {number}\n */\nvar countBalls = function(lowLimit, highLimit) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} low_limit\n# @param {Integer} high_limit\n# @return {Integer}\ndef count_balls(low_limit, high_limit)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countBalls(_ lowLimit: Int, _ highLimit: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countBalls(lowLimit int, highLimit int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countBalls(lowLimit: Int, highLimit: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countBalls(lowLimit: Int, highLimit: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_balls(low_limit: i32, high_limit: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $lowLimit\n * @param Integer $highLimit\n * @return Integer\n */\n function countBalls($lowLimit, $highLimit) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countBalls(lowLimit: number, highLimit: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-balls lowLimit highLimit)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1742](https://leetcode-cn.com/problems/maximum-number-of-balls-in-a-box)", "[\u76d2\u5b50\u4e2d\u5c0f\u7403\u7684\u6700\u5927\u6570\u91cf](/solution/1700-1799/1742.Maximum%20Number%20of%20Balls%20in%20a%20Box/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1742](https://leetcode.com/problems/maximum-number-of-balls-in-a-box)", "[Maximum Number of Balls in a Box](/solution/1700-1799/1742.Maximum%20Number%20of%20Balls%20in%20a%20Box/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1843", "frontend_question_id": "1725", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-rectangles-that-can-form-the-largest-square", "url_en": "https://leetcode.com/problems/number-of-rectangles-that-can-form-the-largest-square", "relative_path_cn": "/solution/1700-1799/1725.Number%20Of%20Rectangles%20That%20Can%20Form%20The%20Largest%20Square/README.md", "relative_path_en": "/solution/1700-1799/1725.Number%20Of%20Rectangles%20That%20Can%20Form%20The%20Largest%20Square/README_EN.md", "title_cn": "\u53ef\u4ee5\u5f62\u6210\u6700\u5927\u6b63\u65b9\u5f62\u7684\u77e9\u5f62\u6570\u76ee", "title_en": "Number Of Rectangles That Can Form The Largest Square", "question_title_slug": "number-of-rectangles-that-can-form-the-largest-square", "content_en": "

You are given an array rectangles where rectangles[i] = [li, wi] represents the ith rectangle of length li and width wi.

\r\n\r\n

You can cut the ith rectangle to form a square with a side length of k if both k <= li and k <= wi. For example, if you have a rectangle [4,6], you can cut it to get a square with a side length of at most 4.

\r\n\r\n

Let maxLen be the side length of the largest square you can obtain from any of the given rectangles.

\r\n\r\n

Return the number of rectangles that can make a square with a side length of maxLen.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: rectangles = [[5,8],[3,9],[5,12],[16,5]]\r\nOutput: 3\r\nExplanation: The largest squares you can get from each rectangle are of lengths [5,3,5,5].\r\nThe largest possible square is of length 5, and you can get it out of 3 rectangles.\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: rectangles = [[2,3],[3,7],[4,3],[3,7]]\r\nOutput: 3\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= rectangles.length <= 1000
  • \r\n\t
  • rectangles[i].length == 2
  • \r\n\t
  • 1 <= li, wi <= 109
  • \r\n\t
  • li != wi
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 rectangles \uff0c\u5176\u4e2d rectangles[i] = [li, wi] \u8868\u793a\u7b2c i \u4e2a\u77e9\u5f62\u7684\u957f\u5ea6\u4e3a li \u3001\u5bbd\u5ea6\u4e3a wi \u3002

\n\n

\u5982\u679c\u5b58\u5728 k \u540c\u65f6\u6ee1\u8db3 k <= li \u548c k <= wi \uff0c\u5c31\u53ef\u4ee5\u5c06\u7b2c i \u4e2a\u77e9\u5f62\u5207\u6210\u8fb9\u957f\u4e3a k \u7684\u6b63\u65b9\u5f62\u3002\u4f8b\u5982\uff0c\u77e9\u5f62 [4,6] \u53ef\u4ee5\u5207\u6210\u8fb9\u957f\u6700\u5927\u4e3a 4 \u7684\u6b63\u65b9\u5f62\u3002

\n\n

\u8bbe maxLen \u4e3a\u53ef\u4ee5\u4ece\u77e9\u5f62\u6570\u7ec4\u00a0rectangles \u5207\u5206\u5f97\u5230\u7684 \u6700\u5927\u6b63\u65b9\u5f62 \u7684\u8fb9\u957f\u3002

\n\n

\u8bf7\u4f60\u7edf\u8ba1\u6709\u591a\u5c11\u4e2a\u77e9\u5f62\u80fd\u591f\u5207\u51fa\u8fb9\u957f\u4e3a maxLen \u7684\u6b63\u65b9\u5f62\uff0c\u5e76\u8fd4\u56de\u77e9\u5f62 \u6570\u76ee \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1arectangles = [[5,8],[3,9],[5,12],[16,5]]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u80fd\u4ece\u6bcf\u4e2a\u77e9\u5f62\u4e2d\u5207\u51fa\u7684\u6700\u5927\u6b63\u65b9\u5f62\u8fb9\u957f\u5206\u522b\u662f [5,3,5,5] \u3002\n\u6700\u5927\u6b63\u65b9\u5f62\u7684\u8fb9\u957f\u4e3a 5 \uff0c\u53ef\u4ee5\u7531 3 \u4e2a\u77e9\u5f62\u5207\u5206\u5f97\u5230\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1arectangles = [[2,3],[3,7],[4,3],[3,7]]\n\u8f93\u51fa\uff1a3\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= rectangles.length <= 1000
  • \n\t
  • rectangles[i].length == 2
  • \n\t
  • 1 <= li, wi <= 109
  • \n\t
  • li != wi
  • \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countGoodRectangles(vector>& rectangles) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countGoodRectangles(int[][] rectangles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countGoodRectangles(self, rectangles):\n \"\"\"\n :type rectangles: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countGoodRectangles(self, rectangles: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countGoodRectangles(int** rectangles, int rectanglesSize, int* rectanglesColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountGoodRectangles(int[][] rectangles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} rectangles\n * @return {number}\n */\nvar countGoodRectangles = function(rectangles) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} rectangles\n# @return {Integer}\ndef count_good_rectangles(rectangles)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countGoodRectangles(_ rectangles: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countGoodRectangles(rectangles [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countGoodRectangles(rectangles: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countGoodRectangles(rectangles: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_good_rectangles(rectangles: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $rectangles\n * @return Integer\n */\n function countGoodRectangles($rectangles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countGoodRectangles(rectangles: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-good-rectangles rectangles)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1725](https://leetcode-cn.com/problems/number-of-rectangles-that-can-form-the-largest-square)", "[\u53ef\u4ee5\u5f62\u6210\u6700\u5927\u6b63\u65b9\u5f62\u7684\u77e9\u5f62\u6570\u76ee](/solution/1700-1799/1725.Number%20Of%20Rectangles%20That%20Can%20Form%20The%20Largest%20Square/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u7b80\u5355", ""], "md_table_row_en": ["[1725](https://leetcode.com/problems/number-of-rectangles-that-can-form-the-largest-square)", "[Number Of Rectangles That Can Form The Largest Square](/solution/1700-1799/1725.Number%20Of%20Rectangles%20That%20Can%20Form%20The%20Largest%20Square/README_EN.md)", "`Greedy`", "Easy", ""]}, {"question_id": "1842", "frontend_question_id": "1699", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/number-of-calls-between-two-persons", "url_en": "https://leetcode.com/problems/number-of-calls-between-two-persons", "relative_path_cn": "/solution/1600-1699/1699.Number%20of%20Calls%20Between%20Two%20Persons/README.md", "relative_path_en": "/solution/1600-1699/1699.Number%20of%20Calls%20Between%20Two%20Persons/README_EN.md", "title_cn": "\u4e24\u4eba\u4e4b\u95f4\u7684\u901a\u8bdd\u6b21\u6570", "title_en": "Number of Calls Between Two Persons", "question_title_slug": "number-of-calls-between-two-persons", "content_en": "

Table: Calls

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| from_id     | int     |\n| to_id       | int     |\n| duration    | int     |\n+-------------+---------+\nThis table does not have a primary key, it may contain duplicates.\nThis table contains the duration of a phone call between from_id and to_id.\nfrom_id != to_id\n
\n\n

 

\n\n

Write an SQL query to report the number of calls and the total call duration between each pair of distinct persons (person1, person2) where person1 < person2.

\n\n

Return the result table in any order.

\n\n

The query result format is in the following example:

\n\n

 

\n\n
\nCalls table:\n+---------+-------+----------+\n| from_id | to_id | duration |\n+---------+-------+----------+\n| 1       | 2     | 59       |\n| 2       | 1     | 11       |\n| 1       | 3     | 20       |\n| 3       | 4     | 100      |\n| 3       | 4     | 200      |\n| 3       | 4     | 200      |\n| 4       | 3     | 499      |\n+---------+-------+----------+\n\nResult table:\n+---------+---------+------------+----------------+\n| person1 | person2 | call_count | total_duration |\n+---------+---------+------------+----------------+\n| 1       | 2       | 2          | 70             |\n| 1       | 3       | 1          | 20             |\n| 3       | 4       | 4          | 999            |\n+---------+---------+------------+----------------+\nUsers 1 and 2 had 2 calls and the total duration is 70 (59 + 11).\nUsers 1 and 3 had 1 call and the total duration is 20.\nUsers 3 and 4 had 4 calls and the total duration is 999 (100 + 200 + 200 + 499).\n
\n", "content_cn": "

\u8868\uff1a\u00a0Calls

\n\n
+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| from_id     | int     |\n| to_id       | int     |\n| duration    | int     |\n+-------------+---------+\n\u8be5\u8868\u6ca1\u6709\u4e3b\u952e\uff0c\u53ef\u80fd\u5b58\u5728\u91cd\u590d\u9879\u3002\n\u8be5\u8868\u5305\u542b from_id \u4e0e to_id \u95f4\u7684\u4e00\u6b21\u7535\u8bdd\u7684\u65f6\u957f\u3002\nfrom_id != to_id\n
\n\n

\u00a0

\n\n

\u7f16\u5199 SQL \u8bed\u53e5\uff0c\u67e5\u8be2\u6bcf\u4e00\u5bf9\u7528\u6237\u00a0(person1, person2)\u00a0\u4e4b\u95f4\u7684\u901a\u8bdd\u6b21\u6570\u548c\u901a\u8bdd\u603b\u65f6\u957f\uff0c\u5176\u4e2d\u00a0person1 < person2\u00a0\u3002

\n\n

\u4ee5\u4efb\u610f\u987a\u5e8f\u8fd4\u56de\u7ed3\u679c\u8868\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u793a\u4f8b\u6240\u793a\uff1a

\n\n

\u00a0

\n\n
Calls \u8868\uff1a\n+---------+-------+----------+\n| from_id | to_id | duration |\n+---------+-------+----------+\n| 1       | 2     | 59       |\n| 2       | 1     | 11       |\n| 1       | 3     | 20       |\n| 3       | 4     | 100      |\n| 3       | 4     | 200      |\n| 3       | 4     | 200      |\n| 4       | 3     | 499      |\n+---------+-------+----------+\n\n\u7ed3\u679c\u8868\uff1a\n+---------+---------+------------+----------------+\n| person1 | person2 | call_count | total_duration |\n+---------+---------+------------+----------------+\n| 1       | 2       | 2          | 70             |\n| 1       | 3       | 1          | 20             |\n| 3       | 4       | 4          | 999            |\n+---------+---------+------------+----------------+\n\u7528\u6237 1 \u548c 2 \u6253\u8fc7 2 \u6b21\u7535\u8bdd\uff0c\u603b\u65f6\u957f\u4e3a 70 (59 + 11)\u3002\n\u7528\u6237 1 \u548c 3 \u6253\u8fc7 1 \u6b21\u7535\u8bdd\uff0c\u603b\u65f6\u957f\u4e3a 20\u3002\n\u7528\u6237 3 \u548c 4 \u6253\u8fc7 4 \u6b21\u7535\u8bdd\uff0c\u603b\u65f6\u957f\u4e3a 999 (100 + 200 + 200 + 499)\u3002\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1699](https://leetcode-cn.com/problems/number-of-calls-between-two-persons)", "[\u4e24\u4eba\u4e4b\u95f4\u7684\u901a\u8bdd\u6b21\u6570](/solution/1600-1699/1699.Number%20of%20Calls%20Between%20Two%20Persons/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1699](https://leetcode.com/problems/number-of-calls-between-two-persons)", "[Number of Calls Between Two Persons](/solution/1600-1699/1699.Number%20of%20Calls%20Between%20Two%20Persons/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1840", "frontend_question_id": "1722", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimize-hamming-distance-after-swap-operations", "url_en": "https://leetcode.com/problems/minimize-hamming-distance-after-swap-operations", "relative_path_cn": "/solution/1700-1799/1722.Minimize%20Hamming%20Distance%20After%20Swap%20Operations/README.md", "relative_path_en": "/solution/1700-1799/1722.Minimize%20Hamming%20Distance%20After%20Swap%20Operations/README_EN.md", "title_cn": "\u6267\u884c\u4ea4\u6362\u64cd\u4f5c\u540e\u7684\u6700\u5c0f\u6c49\u660e\u8ddd\u79bb", "title_en": "Minimize Hamming Distance After Swap Operations", "question_title_slug": "minimize-hamming-distance-after-swap-operations", "content_en": "

You are given two integer arrays, source and target, both of length n. You are also given an array allowedSwaps where each allowedSwaps[i] = [ai, bi] indicates that you are allowed to swap the elements at index ai and index bi (0-indexed) of array source. Note that you can swap elements at a specific pair of indices multiple times and in any order.

\n\n

The Hamming distance of two arrays of the same length, source and target, is the number of positions where the elements are different. Formally, it is the number of indices i for 0 <= i <= n-1 where source[i] != target[i] (0-indexed).

\n\n

Return the minimum Hamming distance of source and target after performing any amount of swap operations on array source.

\n\n

 

\n

Example 1:

\n\n
\nInput: source = [1,2,3,4], target = [2,1,4,5], allowedSwaps = [[0,1],[2,3]]\nOutput: 1\nExplanation: source can be transformed the following way:\n- Swap indices 0 and 1: source = [2,1,3,4]\n- Swap indices 2 and 3: source = [2,1,4,3]\nThe Hamming distance of source and target is 1 as they differ in 1 position: index 3.\n
\n\n

Example 2:

\n\n
\nInput: source = [1,2,3,4], target = [1,3,2,4], allowedSwaps = []\nOutput: 2\nExplanation: There are no allowed swaps.\nThe Hamming distance of source and target is 2 as they differ in 2 positions: index 1 and index 2.\n
\n\n

Example 3:

\n\n
\nInput: source = [5,1,2,4,3], target = [1,5,4,2,3], allowedSwaps = [[0,4],[4,2],[1,3],[1,4]]\nOutput: 0\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == source.length == target.length
  • \n\t
  • 1 <= n <= 105
  • \n\t
  • 1 <= source[i], target[i] <= 105
  • \n\t
  • 0 <= allowedSwaps.length <= 105
  • \n\t
  • allowedSwaps[i].length == 2
  • \n\t
  • 0 <= ai, bi <= n - 1
  • \n\t
  • ai != bi
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e24\u4e2a\u6574\u6570\u6570\u7ec4 source \u548c target \uff0c\u957f\u5ea6\u90fd\u662f n \u3002\u8fd8\u6709\u4e00\u4e2a\u6570\u7ec4 allowedSwaps \uff0c\u5176\u4e2d\u6bcf\u4e2a allowedSwaps[i] = [ai, bi] \u8868\u793a\u4f60\u53ef\u4ee5\u4ea4\u6362\u6570\u7ec4 source \u4e2d\u4e0b\u6807\u4e3a ai \u548c bi\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\u7684\u4e24\u4e2a\u5143\u7d20\u3002\u6ce8\u610f\uff0c\u4f60\u53ef\u4ee5\u6309 \u4efb\u610f \u987a\u5e8f \u591a\u6b21 \u4ea4\u6362\u4e00\u5bf9\u7279\u5b9a\u4e0b\u6807\u6307\u5411\u7684\u5143\u7d20\u3002

\n\n

\u76f8\u540c\u957f\u5ea6\u7684\u4e24\u4e2a\u6570\u7ec4\u00a0source \u548c target \u95f4\u7684 \u6c49\u660e\u8ddd\u79bb \u662f\u5143\u7d20\u4e0d\u540c\u7684\u4e0b\u6807\u6570\u91cf\u3002\u5f62\u5f0f\u4e0a\uff0c\u5176\u503c\u7b49\u4e8e\u6ee1\u8db3\u00a0source[i] != target[i] \uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\u7684\u4e0b\u6807 i\uff080 <= i <= n-1\uff09\u7684\u6570\u91cf\u3002

\n\n

\u5728\u5bf9\u6570\u7ec4 source \u6267\u884c \u4efb\u610f \u6570\u91cf\u7684\u4ea4\u6362\u64cd\u4f5c\u540e\uff0c\u8fd4\u56de source \u548c target \u95f4\u7684 \u6700\u5c0f\u6c49\u660e\u8ddd\u79bb \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1asource = [1,2,3,4], target = [2,1,4,5], allowedSwaps = [[0,1],[2,3]]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1asource \u53ef\u4ee5\u6309\u4e0b\u8ff0\u65b9\u5f0f\u8f6c\u6362\uff1a\n- \u4ea4\u6362\u4e0b\u6807 0 \u548c 1 \u6307\u5411\u7684\u5143\u7d20\uff1asource = [2,1,3,4]\n- \u4ea4\u6362\u4e0b\u6807 2 \u548c 3 \u6307\u5411\u7684\u5143\u7d20\uff1asource = [2,1,4,3]\nsource \u548c target \u95f4\u7684\u6c49\u660e\u8ddd\u79bb\u662f 1 \uff0c\u4e8c\u8005\u6709 1 \u5904\u5143\u7d20\u4e0d\u540c\uff0c\u5728\u4e0b\u6807 3 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1asource = [1,2,3,4], target = [1,3,2,4], allowedSwaps = []\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u4e0d\u80fd\u5bf9 source \u6267\u884c\u4ea4\u6362\u64cd\u4f5c\u3002\nsource \u548c target \u95f4\u7684\u6c49\u660e\u8ddd\u79bb\u662f 2 \uff0c\u4e8c\u8005\u6709 2 \u5904\u5143\u7d20\u4e0d\u540c\uff0c\u5728\u4e0b\u6807 1 \u548c\u4e0b\u6807 2 \u3002
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1asource = [5,1,2,4,3], target = [1,5,4,2,3], allowedSwaps = [[0,4],[4,2],[1,3],[1,4]]\n\u8f93\u51fa\uff1a0\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • n == source.length == target.length
  • \n\t
  • 1 <= n <= 105
  • \n\t
  • 1 <= source[i], target[i] <= 105
  • \n\t
  • 0 <= allowedSwaps.length <= 105
  • \n\t
  • allowedSwaps[i].length == 2
  • \n\t
  • 0 <= ai, bi <= n - 1
  • \n\t
  • ai != bi
  • \n
\n", "tags_en": ["Greedy", "Depth-first Search", "Union Find"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e76\u67e5\u96c6"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minimumHammingDistance(vector& source, vector& target, vector>& allowedSwaps) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minimumHammingDistance(int[] source, int[] target, int[][] allowedSwaps) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimumHammingDistance(self, source, target, allowedSwaps):\n \"\"\"\n :type source: List[int]\n :type target: List[int]\n :type allowedSwaps: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimumHammingDistance(self, source: List[int], target: List[int], allowedSwaps: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minimumHammingDistance(int* source, int sourceSize, int* target, int targetSize, int** allowedSwaps, int allowedSwapsSize, int* allowedSwapsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinimumHammingDistance(int[] source, int[] target, int[][] allowedSwaps) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} source\n * @param {number[]} target\n * @param {number[][]} allowedSwaps\n * @return {number}\n */\nvar minimumHammingDistance = function(source, target, allowedSwaps) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} source\n# @param {Integer[]} target\n# @param {Integer[][]} allowed_swaps\n# @return {Integer}\ndef minimum_hamming_distance(source, target, allowed_swaps)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimumHammingDistance(_ source: [Int], _ target: [Int], _ allowedSwaps: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimumHammingDistance(source []int, target []int, allowedSwaps [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimumHammingDistance(source: Array[Int], target: Array[Int], allowedSwaps: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimumHammingDistance(source: IntArray, target: IntArray, allowedSwaps: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimum_hamming_distance(source: Vec, target: Vec, allowed_swaps: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $source\n * @param Integer[] $target\n * @param Integer[][] $allowedSwaps\n * @return Integer\n */\n function minimumHammingDistance($source, $target, $allowedSwaps) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimumHammingDistance(source: number[], target: number[], allowedSwaps: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimum-hamming-distance source target allowedSwaps)\n (-> (listof exact-integer?) (listof exact-integer?) (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1722](https://leetcode-cn.com/problems/minimize-hamming-distance-after-swap-operations)", "[\u6267\u884c\u4ea4\u6362\u64cd\u4f5c\u540e\u7684\u6700\u5c0f\u6c49\u660e\u8ddd\u79bb](/solution/1700-1799/1722.Minimize%20Hamming%20Distance%20After%20Swap%20Operations/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e76\u67e5\u96c6`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1722](https://leetcode.com/problems/minimize-hamming-distance-after-swap-operations)", "[Minimize Hamming Distance After Swap Operations](/solution/1700-1799/1722.Minimize%20Hamming%20Distance%20After%20Swap%20Operations/README_EN.md)", "`Greedy`,`Depth-first Search`,`Union Find`", "Medium", ""]}, {"question_id": "1839", "frontend_question_id": "1720", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/decode-xored-array", "url_en": "https://leetcode.com/problems/decode-xored-array", "relative_path_cn": "/solution/1700-1799/1720.Decode%20XORed%20Array/README.md", "relative_path_en": "/solution/1700-1799/1720.Decode%20XORed%20Array/README_EN.md", "title_cn": "\u89e3\u7801\u5f02\u6216\u540e\u7684\u6570\u7ec4", "title_en": "Decode XORed Array", "question_title_slug": "decode-xored-array", "content_en": "

There is a hidden integer array arr that consists of n non-negative integers.

\n\n

It was encoded into another integer array encoded of length n - 1, such that encoded[i] = arr[i] XOR arr[i + 1]. For example, if arr = [1,0,2,1], then encoded = [1,2,3].

\n\n

You are given the encoded array. You are also given an integer first, that is the first element of arr, i.e. arr[0].

\n\n

Return the original array arr. It can be proved that the answer exists and is unique.

\n\n

 

\n

Example 1:

\n\n
\nInput: encoded = [1,2,3], first = 1\nOutput: [1,0,2,1]\nExplanation: If arr = [1,0,2,1], then first = 1 and encoded = [1 XOR 0, 0 XOR 2, 2 XOR 1] = [1,2,3]\n
\n\n

Example 2:

\n\n
\nInput: encoded = [6,2,7,3], first = 4\nOutput: [4,2,0,7,4]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= n <= 104
  • \n\t
  • encoded.length == n - 1
  • \n\t
  • 0 <= encoded[i] <= 105
  • \n\t
  • 0 <= first <= 105
  • \n
\n", "content_cn": "

\u672a\u77e5 \u6574\u6570\u6570\u7ec4 arr \u7531 n \u4e2a\u975e\u8d1f\u6574\u6570\u7ec4\u6210\u3002

\n\n

\u7ecf\u7f16\u7801\u540e\u53d8\u4e3a\u957f\u5ea6\u4e3a n - 1 \u7684\u53e6\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 encoded \uff0c\u5176\u4e2d encoded[i] = arr[i] XOR arr[i + 1] \u3002\u4f8b\u5982\uff0carr = [1,0,2,1] \u7ecf\u7f16\u7801\u540e\u5f97\u5230 encoded = [1,2,3] \u3002

\n\n

\u7ed9\u4f60\u7f16\u7801\u540e\u7684\u6570\u7ec4 encoded \u548c\u539f\u6570\u7ec4 arr \u7684\u7b2c\u4e00\u4e2a\u5143\u7d20 first\uff08arr[0]\uff09\u3002

\n\n

\u8bf7\u89e3\u7801\u8fd4\u56de\u539f\u6570\u7ec4 arr \u3002\u53ef\u4ee5\u8bc1\u660e\u7b54\u6848\u5b58\u5728\u5e76\u4e14\u662f\u552f\u4e00\u7684\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aencoded = [1,2,3], first = 1\n\u8f93\u51fa\uff1a[1,0,2,1]\n\u89e3\u91ca\uff1a\u82e5 arr = [1,0,2,1] \uff0c\u90a3\u4e48 first = 1 \u4e14 encoded = [1 XOR 0, 0 XOR 2, 2 XOR 1] = [1,2,3]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aencoded = [6,2,7,3], first = 4\n\u8f93\u51fa\uff1a[4,2,0,7,4]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= n <= 104
  • \n\t
  • encoded.length == n - 1
  • \n\t
  • 0 <= encoded[i] <= 105
  • \n\t
  • 0 <= first <= 105
  • \n
\n", "tags_en": ["Bit Manipulation"], "tags_cn": ["\u4f4d\u8fd0\u7b97"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector decode(vector& encoded, int first) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] decode(int[] encoded, int first) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def decode(self, encoded, first):\n \"\"\"\n :type encoded: List[int]\n :type first: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def decode(self, encoded: List[int], first: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* decode(int* encoded, int encodedSize, int first, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] Decode(int[] encoded, int first) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} encoded\n * @param {number} first\n * @return {number[]}\n */\nvar decode = function(encoded, first) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} encoded\n# @param {Integer} first\n# @return {Integer[]}\ndef decode(encoded, first)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func decode(_ encoded: [Int], _ first: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func decode(encoded []int, first int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def decode(encoded: Array[Int], first: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun decode(encoded: IntArray, first: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn decode(encoded: Vec, first: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $encoded\n * @param Integer $first\n * @return Integer[]\n */\n function decode($encoded, $first) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function decode(encoded: number[], first: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (decode encoded first)\n (-> (listof exact-integer?) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1720](https://leetcode-cn.com/problems/decode-xored-array)", "[\u89e3\u7801\u5f02\u6216\u540e\u7684\u6570\u7ec4](/solution/1700-1799/1720.Decode%20XORed%20Array/README.md)", "`\u4f4d\u8fd0\u7b97`", "\u7b80\u5355", ""], "md_table_row_en": ["[1720](https://leetcode.com/problems/decode-xored-array)", "[Decode XORed Array](/solution/1700-1799/1720.Decode%20XORed%20Array/README_EN.md)", "`Bit Manipulation`", "Easy", ""]}, {"question_id": "1838", "frontend_question_id": "1698", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/number-of-distinct-substrings-in-a-string", "url_en": "https://leetcode.com/problems/number-of-distinct-substrings-in-a-string", "relative_path_cn": "/solution/1600-1699/1698.Number%20of%20Distinct%20Substrings%20in%20a%20String/README.md", "relative_path_en": "/solution/1600-1699/1698.Number%20of%20Distinct%20Substrings%20in%20a%20String/README_EN.md", "title_cn": "\u5b57\u7b26\u4e32\u7684\u4e0d\u540c\u5b50\u5b57\u7b26\u4e32\u4e2a\u6570", "title_en": "Number of Distinct Substrings in a String", "question_title_slug": "number-of-distinct-substrings-in-a-string", "content_en": "

Given a string s, return the number of distinct substrings of s.

\n\n

A substring of a string is obtained by deleting any number of characters (possibly zero) from the front of the string and any number (possibly zero) from the back of the string.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "aabbaba"\nOutput: 21\nExplanation: The set of distinct strings is ["a","b","aa","bb","ab","ba","aab","abb","bab","bba","aba","aabb","abba","bbab","baba","aabba","abbab","bbaba","aabbab","abbaba","aabbaba"]\n
\n\n

Example 2:

\n\n
\nInput: s = "abcdefg"\nOutput: 28\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 500
  • \n\t
  • s consists of lowercase English letters.
  • \n
\n\n

 

\nFollow up: Can you solve this problem in O(n) time complexity?", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\u00a0s\uff0c\u8fd4\u56de\u00a0s\u00a0\u7684\u4e0d\u540c\u5b50\u5b57\u7b26\u4e32\u7684\u4e2a\u6570\u3002

\n\n

\u5b57\u7b26\u4e32\u7684 \u5b50\u5b57\u7b26\u4e32 \u662f\u7531\u539f\u5b57\u7b26\u4e32\u5220\u9664\u5f00\u5934\u82e5\u5e72\u4e2a\u5b57\u7b26\uff08\u53ef\u80fd\u662f 0 \u4e2a\uff09\u5e76\u5220\u9664\u7ed3\u5c3e\u82e5\u5e72\u4e2a\u5b57\u7b26\uff08\u53ef\u80fd\u662f 0 \u4e2a\uff09\u5f62\u6210\u7684\u5b57\u7b26\u4e32\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"aabbaba\"\n\u8f93\u51fa\uff1a21\n\u89e3\u91ca\uff1a\u4e0d\u540c\u5b50\u5b57\u7b26\u4e32\u7684\u96c6\u5408\u662f [\"a\",\"b\",\"aa\",\"bb\",\"ab\",\"ba\",\"aab\",\"abb\",\"bab\",\"bba\",\"aba\",\"aabb\",\"abba\",\"bbab\",\"baba\",\"aabba\",\"abbab\",\"bbaba\",\"aabbab\",\"abbaba\",\"aabbaba\"]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"abcdefg\"\n\u8f93\u51fa\uff1a28\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length <= 500
  • \n\t
  • s\u00a0\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\u3002
  • \n
\n\n

\u8fdb\u9636\uff1a\u4f60\u53ef\u4ee5\u4ee5\u00a0O(n)\u00a0\u65f6\u95f4\u590d\u6742\u5ea6\u89e3\u51b3\u6b64\u95ee\u9898\u5417\uff1f

\n", "tags_en": ["Trie", "String"], "tags_cn": ["\u5b57\u5178\u6811", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countDistinct(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countDistinct(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countDistinct(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countDistinct(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countDistinct(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountDistinct(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar countDistinct = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef count_distinct(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countDistinct(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countDistinct(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countDistinct(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countDistinct(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_distinct(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function countDistinct($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countDistinct(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-distinct s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1698](https://leetcode-cn.com/problems/number-of-distinct-substrings-in-a-string)", "[\u5b57\u7b26\u4e32\u7684\u4e0d\u540c\u5b50\u5b57\u7b26\u4e32\u4e2a\u6570](/solution/1600-1699/1698.Number%20of%20Distinct%20Substrings%20in%20a%20String/README.md)", "`\u5b57\u5178\u6811`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1698](https://leetcode.com/problems/number-of-distinct-substrings-in-a-string)", "[Number of Distinct Substrings in a String](/solution/1600-1699/1698.Number%20of%20Distinct%20Substrings%20in%20a%20String/README_EN.md)", "`Trie`,`String`", "Medium", "\ud83d\udd12"]}, {"question_id": "1837", "frontend_question_id": "1693", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/daily-leads-and-partners", "url_en": "https://leetcode.com/problems/daily-leads-and-partners", "relative_path_cn": "/solution/1600-1699/1693.Daily%20Leads%20and%20Partners/README.md", "relative_path_en": "/solution/1600-1699/1693.Daily%20Leads%20and%20Partners/README_EN.md", "title_cn": "\u6bcf\u5929\u7684\u9886\u5bfc\u548c\u5408\u4f19\u4eba", "title_en": "Daily Leads and Partners", "question_title_slug": "daily-leads-and-partners", "content_en": "

Table: DailySales

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| date_id     | date    |\n| make_name   | varchar |\n| lead_id     | int     |\n| partner_id  | int     |\n+-------------+---------+\nThis table does not have a primary key.\nThis table contains the date and the name of the product sold and the IDs of the lead and partner it was sold to.\nThe name consists of only lowercase English letters.\n
\n\n

 

\n\n

Write an SQL query that will, for each date_id and make_name, return the number of distinct lead_id's and distinct partner_id's.

\n\n

Return the result table in any order.

\n\n

The query result format is in the following example:

\n\n

 

\n\n
\nDailySales table:\n+-----------+-----------+---------+------------+\n| date_id   | make_name | lead_id | partner_id |\n+-----------+-----------+---------+------------+\n| 2020-12-8 | toyota    | 0       | 1          |\n| 2020-12-8 | toyota    | 1       | 0          |\n| 2020-12-8 | toyota    | 1       | 2          |\n| 2020-12-7 | toyota    | 0       | 2          |\n| 2020-12-7 | toyota    | 0       | 1          |\n| 2020-12-8 | honda     | 1       | 2          |\n| 2020-12-8 | honda     | 2       | 1          |\n| 2020-12-7 | honda     | 0       | 1          |\n| 2020-12-7 | honda     | 1       | 2          |\n| 2020-12-7 | honda     | 2       | 1          |\n+-----------+-----------+---------+------------+\nResult table:\n+-----------+-----------+--------------+-----------------+\n| date_id   | make_name | unique_leads | unique_partners |\n+-----------+-----------+--------------+-----------------+\n| 2020-12-8 | toyota    | 2            | 3               |\n| 2020-12-7 | toyota    | 1            | 2               |\n| 2020-12-8 | honda     | 2            | 2               |\n| 2020-12-7 | honda     | 3            | 2               |\n+-----------+-----------+--------------+-----------------+\nFor 2020-12-8, toyota gets leads = [0, 1] and partners = [0, 1, 2] while honda gets leads = [1, 2] and partners = [1, 2].\nFor 2020-12-7, toyota gets leads = [0] and partners = [1, 2] while honda gets leads = [0, 1, 2] and partners = [1, 2].\n
\n", "content_cn": "

\u8868\uff1aDailySales

\n\n
+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| date_id     | date    |\n| make_name   | varchar |\n| lead_id     | int     |\n| partner_id  | int     |\n+-------------+---------+\n\u8be5\u8868\u6ca1\u6709\u4e3b\u952e\u3002\n\u8be5\u8868\u5305\u542b\u65e5\u671f\u3001\u4ea7\u54c1\u7684\u540d\u79f0\uff0c\u4ee5\u53ca\u552e\u7ed9\u7684\u9886\u5bfc\u548c\u5408\u4f19\u4eba\u7684\u7f16\u53f7\u3002\n\u540d\u79f0\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
\n\n

\u00a0

\n\n

\u5199\u4e00\u6761 SQL \u8bed\u53e5\uff0c\u4f7f\u5f97\u5bf9\u4e8e\u6bcf\u4e00\u4e2a\u00a0date_id\u00a0\u548c\u00a0make_name\uff0c\u8fd4\u56de\u4e0d\u540c\u7684\u00a0lead_id\u00a0\u4ee5\u53ca\u4e0d\u540c\u7684\u00a0partner_id\u00a0\u7684\u6570\u91cf\u3002

\n\n

\u6309\u4efb\u610f\u987a\u5e8f\u8fd4\u56de\u7ed3\u679c\u8868\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u793a\u4f8b\u6240\u793a\uff1a

\n\n

\u00a0

\n\n
DailySales \u8868\uff1a\n+-----------+-----------+---------+------------+\n| date_id   | make_name | lead_id | partner_id |\n+-----------+-----------+---------+------------+\n| 2020-12-8 | toyota    | 0       | 1          |\n| 2020-12-8 | toyota    | 1       | 0          |\n| 2020-12-8 | toyota    | 1       | 2          |\n| 2020-12-7 | toyota    | 0       | 2          |\n| 2020-12-7 | toyota    | 0       | 1          |\n| 2020-12-8 | honda     | 1       | 2          |\n| 2020-12-8 | honda     | 2       | 1          |\n| 2020-12-7 | honda     | 0       | 1          |\n| 2020-12-7 | honda     | 1       | 2          |\n| 2020-12-7 | honda     | 2       | 1          |\n+-----------+-----------+---------+------------+\n\u7ed3\u679c\u8868\uff1a\n+-----------+-----------+--------------+-----------------+\n| date_id   | make_name | unique_leads | unique_partners |\n+-----------+-----------+--------------+-----------------+\n| 2020-12-8 | toyota    | 2            | 3               |\n| 2020-12-7 | toyota    | 1            | 2               |\n| 2020-12-8 | honda     | 2            | 2               |\n| 2020-12-7 | honda     | 3            | 2               |\n+-----------+-----------+--------------+-----------------+\n\u5728 2020-12-8\uff0c\u4e30\u7530\uff08toyota\uff09\u6709\u9886\u5bfc\u8005 = [0, 1] \u548c\u5408\u4f19\u4eba = [0, 1, 2] \uff0c\u540c\u65f6\u672c\u7530\uff08honda\uff09\u6709\u9886\u5bfc\u8005 = [1, 2] \u548c\u5408\u4f19\u4eba = [1, 2]\u3002\n\u5728 2020-12-7\uff0c\u4e30\u7530\uff08toyota\uff09\u6709\u9886\u5bfc\u8005 = [0] \u548c\u5408\u4f19\u4eba = [1, 2] \uff0c\u540c\u65f6\u672c\u7530\uff08honda\uff09\u6709\u9886\u5bfc\u8005 = [0, 1, 2] \u548c\u5408\u4f19\u4eba = [1, 2]\u3002
\n\n

\u00a0

\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1693](https://leetcode-cn.com/problems/daily-leads-and-partners)", "[\u6bcf\u5929\u7684\u9886\u5bfc\u548c\u5408\u4f19\u4eba](/solution/1600-1699/1693.Daily%20Leads%20and%20Partners/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1693](https://leetcode.com/problems/daily-leads-and-partners)", "[Daily Leads and Partners](/solution/1600-1699/1693.Daily%20Leads%20and%20Partners/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1836", "frontend_question_id": "1735", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-ways-to-make-array-with-product", "url_en": "https://leetcode.com/problems/count-ways-to-make-array-with-product", "relative_path_cn": "/solution/1700-1799/1735.Count%20Ways%20to%20Make%20Array%20With%20Product/README.md", "relative_path_en": "/solution/1700-1799/1735.Count%20Ways%20to%20Make%20Array%20With%20Product/README_EN.md", "title_cn": "\u751f\u6210\u4e58\u79ef\u6570\u7ec4\u7684\u65b9\u6848\u6570", "title_en": "Count Ways to Make Array With Product", "question_title_slug": "count-ways-to-make-array-with-product", "content_en": "

You are given a 2D integer array, queries. For each queries[i], where queries[i] = [ni, ki], find the number of different ways you can place positive integers into an array of size ni such that the product of the integers is ki. As the number of ways may be too large, the answer to the ith query is the number of ways modulo 109 + 7.

\n\n

Return an integer array answer where answer.length == queries.length, and answer[i] is the answer to the ith query.

\n\n

 

\n

Example 1:

\n\n
\nInput: queries = [[2,6],[5,1],[73,660]]\nOutput: [4,1,50734910]\nExplanation: Each query is independent.\n[2,6]: There are 4 ways to fill an array of size 2 that multiply to 6: [1,6], [2,3], [3,2], [6,1].\n[5,1]: There is 1 way to fill an array of size 5 that multiply to 1: [1,1,1,1,1].\n[73,660]: There are 1050734917 ways to fill an array of size 73 that multiply to 660. 1050734917 modulo 109 + 7 = 50734910.\n
\n\n

Example 2:

\n\n
\nInput: queries = [[1,1],[2,2],[3,3],[4,4],[5,5]]\nOutput: [1,2,3,10,5]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= queries.length <= 104
  • \n\t
  • 1 <= ni, ki <= 104
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u4e8c\u7ef4\u6574\u6570\u6570\u7ec4\u00a0queries\u00a0\uff0c\u5176\u4e2d queries[i] = [ni, ki] \u3002\u7b2c\u00a0i\u00a0\u4e2a\u67e5\u8be2\u00a0queries[i] \u8981\u6c42\u6784\u9020\u957f\u5ea6\u4e3a\u00a0ni \u3001\u6bcf\u4e2a\u5143\u7d20\u90fd\u662f\u6b63\u6574\u6570\u7684\u6570\u7ec4\uff0c\u4e14\u6ee1\u8db3\u6240\u6709\u5143\u7d20\u7684\u4e58\u79ef\u4e3a\u00a0ki\u00a0\uff0c\u8bf7\u4f60\u627e\u51fa\u6709\u591a\u5c11\u79cd\u53ef\u884c\u7684\u65b9\u6848\u3002\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u4f1a\u5f88\u5927\uff0c\u65b9\u6848\u6570\u9700\u8981\u5bf9 109 + 7\u00a0\u53d6\u4f59 \u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0answer\uff0c\u6ee1\u8db3\u00a0answer.length == queries.length\u00a0\uff0c\u5176\u4e2d\u00a0answer[i]\u662f\u7b2c\u00a0i\u00a0\u4e2a\u67e5\u8be2\u7684\u7ed3\u679c\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aqueries = [[2,6],[5,1],[73,660]]\n\u8f93\u51fa\uff1a[4,1,50734910]\n\u89e3\u91ca\uff1a\u6bcf\u4e2a\u67e5\u8be2\u4e4b\u95f4\u5f7c\u6b64\u72ec\u7acb\u3002\n[2,6]\uff1a\u603b\u5171\u6709 4 \u79cd\u65b9\u6848\u5f97\u5230\u957f\u5ea6\u4e3a 2 \u4e14\u4e58\u79ef\u4e3a 6 \u7684\u6570\u7ec4\uff1a[1,6]\uff0c[2,3]\uff0c[3,2]\uff0c[6,1]\u3002\n[5,1]\uff1a\u603b\u5171\u6709 1 \u79cd\u65b9\u6848\u5f97\u5230\u957f\u5ea6\u4e3a 5 \u4e14\u4e58\u79ef\u4e3a 1 \u7684\u6570\u7ec4\uff1a[1,1,1,1,1]\u3002\n[73,660]\uff1a\u603b\u5171\u6709 1050734917 \u79cd\u65b9\u6848\u5f97\u5230\u957f\u5ea6\u4e3a 73 \u4e14\u4e58\u79ef\u4e3a 660 \u7684\u6570\u7ec4\u30021050734917 \u5bf9 109 + 7 \u53d6\u4f59\u5f97\u5230 50734910 \u3002\n
\n\n

\u793a\u4f8b 2\u00a0\uff1a

\n\n
\n\u8f93\u5165\uff1aqueries = [[1,1],[2,2],[3,3],[4,4],[5,5]]\n\u8f93\u51fa\uff1a[1,2,3,10,5]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= queries.length <= 104
  • \n\t
  • 1 <= ni, ki <= 104
  • \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector waysToFillArray(vector>& queries) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] waysToFillArray(int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def waysToFillArray(self, queries):\n \"\"\"\n :type queries: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def waysToFillArray(self, queries: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* waysToFillArray(int** queries, int queriesSize, int* queriesColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] WaysToFillArray(int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} queries\n * @return {number[]}\n */\nvar waysToFillArray = function(queries) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} queries\n# @return {Integer[]}\ndef ways_to_fill_array(queries)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func waysToFillArray(_ queries: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func waysToFillArray(queries [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def waysToFillArray(queries: Array[Array[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun waysToFillArray(queries: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn ways_to_fill_array(queries: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $queries\n * @return Integer[]\n */\n function waysToFillArray($queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function waysToFillArray(queries: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (ways-to-fill-array queries)\n (-> (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1735](https://leetcode-cn.com/problems/count-ways-to-make-array-with-product)", "[\u751f\u6210\u4e58\u79ef\u6570\u7ec4\u7684\u65b9\u6848\u6570](/solution/1700-1799/1735.Count%20Ways%20to%20Make%20Array%20With%20Product/README.md)", "`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[1735](https://leetcode.com/problems/count-ways-to-make-array-with-product)", "[Count Ways to Make Array With Product](/solution/1700-1799/1735.Count%20Ways%20to%20Make%20Array%20With%20Product/README_EN.md)", "`Math`", "Hard", ""]}, {"question_id": "1835", "frontend_question_id": "1734", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/decode-xored-permutation", "url_en": "https://leetcode.com/problems/decode-xored-permutation", "relative_path_cn": "/solution/1700-1799/1734.Decode%20XORed%20Permutation/README.md", "relative_path_en": "/solution/1700-1799/1734.Decode%20XORed%20Permutation/README_EN.md", "title_cn": "\u89e3\u7801\u5f02\u6216\u540e\u7684\u6392\u5217", "title_en": "Decode XORed Permutation", "question_title_slug": "decode-xored-permutation", "content_en": "

There is an integer array perm that is a permutation of the first n positive integers, where n is always odd.

\n\n

It was encoded into another integer array encoded of length n - 1, such that encoded[i] = perm[i] XOR perm[i + 1]. For example, if perm = [1,3,2], then encoded = [2,1].

\n\n

Given the encoded array, return the original array perm. It is guaranteed that the answer exists and is unique.

\n\n

 

\n

Example 1:

\n\n
\nInput: encoded = [3,1]\nOutput: [1,2,3]\nExplanation: If perm = [1,2,3], then encoded = [1 XOR 2,2 XOR 3] = [3,1]\n
\n\n

Example 2:

\n\n
\nInput: encoded = [6,5,4,6]\nOutput: [2,4,1,5,3]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 3 <= n < 105
  • \n\t
  • n is odd.
  • \n\t
  • encoded.length == n - 1
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0perm\u00a0\uff0c\u5b83\u662f\u524d\u00a0n\u00a0\u4e2a\u6b63\u6574\u6570\u7684\u6392\u5217\uff0c\u4e14\u00a0n\u00a0\u662f\u4e2a \u5947\u6570\u00a0\u3002

\n\n

\u5b83\u88ab\u52a0\u5bc6\u6210\u53e6\u4e00\u4e2a\u957f\u5ea6\u4e3a n - 1\u00a0\u7684\u6574\u6570\u6570\u7ec4\u00a0encoded\u00a0\uff0c\u6ee1\u8db3\u00a0encoded[i] = perm[i] XOR perm[i + 1]\u00a0\u3002\u6bd4\u65b9\u8bf4\uff0c\u5982\u679c\u00a0perm = [1,3,2]\u00a0\uff0c\u90a3\u4e48\u00a0encoded = [2,1]\u00a0\u3002

\n\n

\u7ed9\u4f60\u00a0encoded\u00a0\u6570\u7ec4\uff0c\u8bf7\u4f60\u8fd4\u56de\u539f\u59cb\u6570\u7ec4\u00a0perm\u00a0\u3002\u9898\u76ee\u4fdd\u8bc1\u7b54\u6848\u5b58\u5728\u4e14\u552f\u4e00\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aencoded = [3,1]\n\u8f93\u51fa\uff1a[1,2,3]\n\u89e3\u91ca\uff1a\u5982\u679c perm = [1,2,3] \uff0c\u90a3\u4e48 encoded = [1 XOR 2,2 XOR 3] = [3,1]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aencoded = [6,5,4,6]\n\u8f93\u51fa\uff1a[2,4,1,5,3]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 3 <= n <\u00a0105
  • \n\t
  • n\u00a0\u662f\u5947\u6570\u3002
  • \n\t
  • encoded.length == n - 1
  • \n
\n", "tags_en": ["Bit Manipulation"], "tags_cn": ["\u4f4d\u8fd0\u7b97"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector decode(vector& encoded) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] decode(int[] encoded) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def decode(self, encoded):\n \"\"\"\n :type encoded: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def decode(self, encoded: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* decode(int* encoded, int encodedSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] Decode(int[] encoded) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} encoded\n * @return {number[]}\n */\nvar decode = function(encoded) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} encoded\n# @return {Integer[]}\ndef decode(encoded)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func decode(_ encoded: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func decode(encoded []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def decode(encoded: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun decode(encoded: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn decode(encoded: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $encoded\n * @return Integer[]\n */\n function decode($encoded) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function decode(encoded: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (decode encoded)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1734](https://leetcode-cn.com/problems/decode-xored-permutation)", "[\u89e3\u7801\u5f02\u6216\u540e\u7684\u6392\u5217](/solution/1700-1799/1734.Decode%20XORed%20Permutation/README.md)", "`\u4f4d\u8fd0\u7b97`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1734](https://leetcode.com/problems/decode-xored-permutation)", "[Decode XORed Permutation](/solution/1700-1799/1734.Decode%20XORed%20Permutation/README_EN.md)", "`Bit Manipulation`", "Medium", ""]}, {"question_id": "1834", "frontend_question_id": "1733", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-number-of-people-to-teach", "url_en": "https://leetcode.com/problems/minimum-number-of-people-to-teach", "relative_path_cn": "/solution/1700-1799/1733.Minimum%20Number%20of%20People%20to%20Teach/README.md", "relative_path_en": "/solution/1700-1799/1733.Minimum%20Number%20of%20People%20to%20Teach/README_EN.md", "title_cn": "\u9700\u8981\u6559\u8bed\u8a00\u7684\u6700\u5c11\u4eba\u6570", "title_en": "Minimum Number of People to Teach", "question_title_slug": "minimum-number-of-people-to-teach", "content_en": "

On a social network consisting of m users and some friendships between users, two users can communicate with each other if they know a common language.

\n\n

You are given an integer n, an array languages, and an array friendships where:

\n\n
    \n\t
  • There are n languages numbered 1 through n,
  • \n\t
  • languages[i] is the set of languages the i\u200b\u200b\u200b\u200b\u200b\u200bth\u200b\u200b\u200b\u200b user knows, and
  • \n\t
  • friendships[i] = [u\u200b\u200b\u200b\u200b\u200b\u200bi\u200b\u200b\u200b, v\u200b\u200b\u200b\u200b\u200b\u200bi] denotes a friendship between the users u\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200bi\u200b\u200b\u200b\u200b\u200b and vi.
  • \n
\n\n

You can choose one language and teach it to some users so that all friends can communicate with each other. Return the minimum number of users you need to teach.

\nNote that friendships are not transitive, meaning if x is a friend of y and y is a friend of z, this doesn't guarantee that x is a friend of z.\n

 

\n

Example 1:

\n\n
\nInput: n = 2, languages = [[1],[2],[1,2]], friendships = [[1,2],[1,3],[2,3]]\nOutput: 1\nExplanation: You can either teach user 1 the second language or user 2 the first language.\n
\n\n

Example 2:

\n\n
\nInput: n = 3, languages = [[2],[1,3],[1,2],[3]], friendships = [[1,4],[1,2],[3,4],[2,3]]\nOutput: 2\nExplanation: Teach the third language to users 1 and 3, yielding two users to teach.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= n <= 500
  • \n\t
  • languages.length == m
  • \n\t
  • 1 <= m <= 500
  • \n\t
  • 1 <= languages[i].length <= n
  • \n\t
  • 1 <= languages[i][j] <= n
  • \n\t
  • 1 <= u\u200b\u200b\u200b\u200b\u200b\u200bi < v\u200b\u200b\u200b\u200b\u200b\u200bi <= languages.length
  • \n\t
  • 1 <= friendships.length <= 500
  • \n\t
  • All tuples (u\u200b\u200b\u200b\u200b\u200bi, v\u200b\u200b\u200b\u200b\u200b\u200bi) are unique
  • \n\t
  • languages[i] contains only unique values
  • \n
\n", "content_cn": "

\u5728\u4e00\u4e2a\u7531\u00a0m\u00a0\u4e2a\u7528\u6237\u7ec4\u6210\u7684\u793e\u4ea4\u7f51\u7edc\u91cc\uff0c\u6211\u4eec\u83b7\u53d6\u5230\u4e00\u4e9b\u7528\u6237\u4e4b\u95f4\u7684\u597d\u53cb\u5173\u7cfb\u3002\u4e24\u4e2a\u7528\u6237\u4e4b\u95f4\u53ef\u4ee5\u76f8\u4e92\u6c9f\u901a\u7684\u6761\u4ef6\u662f\u4ed6\u4eec\u90fd\u638c\u63e1\u540c\u4e00\u95e8\u8bed\u8a00\u3002

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u00a0n\u00a0\uff0c\u6570\u7ec4\u00a0languages\u00a0\u548c\u6570\u7ec4\u00a0friendships\u00a0\uff0c\u5b83\u4eec\u7684\u542b\u4e49\u5982\u4e0b\uff1a

\n\n
    \n\t
  • \u603b\u5171\u6709\u00a0n\u00a0\u79cd\u8bed\u8a00\uff0c\u7f16\u53f7\u4ece\u00a01 \u5230\u00a0n\u00a0\u3002
  • \n\t
  • languages[i]\u00a0\u662f\u7b2c i\u00a0\u4f4d\u7528\u6237\u638c\u63e1\u7684\u8bed\u8a00\u96c6\u5408\u3002
  • \n\t
  • friendships[i] = [u\u200b\u200b\u200b\u200b\u200b\u200bi\u200b\u200b\u200b, v\u200b\u200b\u200b\u200b\u200b\u200bi]\u00a0\u8868\u793a\u00a0u\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200bi\u200b\u200b\u200b\u200b\u200b \u548c\u00a0vi\u00a0\u4e3a\u597d\u53cb\u5173\u7cfb\u3002
  • \n
\n\n

\u4f60\u53ef\u4ee5\u9009\u62e9 \u4e00\u95e8\u00a0\u8bed\u8a00\u5e76\u6559\u4f1a\u4e00\u4e9b\u7528\u6237\uff0c\u4f7f\u5f97\u6240\u6709\u597d\u53cb\u4e4b\u95f4\u90fd\u53ef\u4ee5\u76f8\u4e92\u6c9f\u901a\u3002\u8bf7\u8fd4\u56de\u4f60 \u6700\u5c11\u00a0\u9700\u8981\u6559\u4f1a\u591a\u5c11\u540d\u7528\u6237\u3002

\n\u8bf7\u6ce8\u610f\uff0c\u597d\u53cb\u5173\u7cfb\u6ca1\u6709\u4f20\u9012\u6027\uff0c\u4e5f\u5c31\u662f\u8bf4\u5982\u679c\u00a0x \u548c\u00a0y\u00a0\u662f\u597d\u53cb\uff0c\u4e14\u00a0y\u00a0\u548c\u00a0z\u00a0\u662f\u597d\u53cb\uff0c\u00a0x \u548c\u00a0z\u00a0\u4e0d\u4e00\u5b9a\u662f\u597d\u53cb\u3002\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1an = 2, languages = [[1],[2],[1,2]], friendships = [[1,2],[1,3],[2,3]]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u9009\u62e9\u6559\u7528\u6237 1 \u7b2c\u4e8c\u95e8\u8bed\u8a00\uff0c\u4e5f\u53ef\u4ee5\u9009\u62e9\u6559\u7528\u6237 2 \u7b2c\u4e00\u95e8\u8bed\u8a00\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1an = 3, languages = [[2],[1,3],[1,2],[3]], friendships = [[1,4],[1,2],[3,4],[2,3]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6559\u7528\u6237 1 \u548c\u7528\u6237 3 \u7b2c\u4e09\u95e8\u8bed\u8a00\uff0c\u9700\u8981\u6559 2 \u540d\u7528\u6237\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= n <= 500
  • \n\t
  • languages.length == m
  • \n\t
  • 1 <= m <= 500
  • \n\t
  • 1 <= languages[i].length <= n
  • \n\t
  • 1 <= languages[i][j] <= n
  • \n\t
  • 1 <= u\u200b\u200b\u200b\u200b\u200b\u200bi < v\u200b\u200b\u200b\u200b\u200b\u200bi <= languages.length
  • \n\t
  • 1 <= friendships.length <= 500
  • \n\t
  • \u6240\u6709\u7684\u597d\u53cb\u5173\u7cfb\u00a0(u\u200b\u200b\u200b\u200b\u200bi, v\u200b\u200b\u200b\u200b\u200b\u200bi)\u00a0\u90fd\u662f\u552f\u4e00\u7684\u3002
  • \n\t
  • languages[i]\u00a0\u4e2d\u5305\u542b\u7684\u503c\u4e92\u4e0d\u76f8\u540c\u3002
  • \n
\n", "tags_en": ["Greedy", "Array"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minimumTeachings(int n, vector>& languages, vector>& friendships) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minimumTeachings(int n, int[][] languages, int[][] friendships) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimumTeachings(self, n, languages, friendships):\n \"\"\"\n :type n: int\n :type languages: List[List[int]]\n :type friendships: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimumTeachings(self, n: int, languages: List[List[int]], friendships: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minimumTeachings(int n, int** languages, int languagesSize, int* languagesColSize, int** friendships, int friendshipsSize, int* friendshipsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinimumTeachings(int n, int[][] languages, int[][] friendships) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} languages\n * @param {number[][]} friendships\n * @return {number}\n */\nvar minimumTeachings = function(n, languages, friendships) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} languages\n# @param {Integer[][]} friendships\n# @return {Integer}\ndef minimum_teachings(n, languages, friendships)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimumTeachings(_ n: Int, _ languages: [[Int]], _ friendships: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimumTeachings(n int, languages [][]int, friendships [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimumTeachings(n: Int, languages: Array[Array[Int]], friendships: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimumTeachings(n: Int, languages: Array, friendships: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimum_teachings(n: i32, languages: Vec>, friendships: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $languages\n * @param Integer[][] $friendships\n * @return Integer\n */\n function minimumTeachings($n, $languages, $friendships) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimumTeachings(n: number, languages: number[][], friendships: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimum-teachings n languages friendships)\n (-> exact-integer? (listof (listof exact-integer?)) (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1733](https://leetcode-cn.com/problems/minimum-number-of-people-to-teach)", "[\u9700\u8981\u6559\u8bed\u8a00\u7684\u6700\u5c11\u4eba\u6570](/solution/1700-1799/1733.Minimum%20Number%20of%20People%20to%20Teach/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1733](https://leetcode.com/problems/minimum-number-of-people-to-teach)", "[Minimum Number of People to Teach](/solution/1700-1799/1733.Minimum%20Number%20of%20People%20to%20Teach/README_EN.md)", "`Greedy`,`Array`", "Medium", ""]}, {"question_id": "1833", "frontend_question_id": "1732", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-the-highest-altitude", "url_en": "https://leetcode.com/problems/find-the-highest-altitude", "relative_path_cn": "/solution/1700-1799/1732.Find%20the%20Highest%20Altitude/README.md", "relative_path_en": "/solution/1700-1799/1732.Find%20the%20Highest%20Altitude/README_EN.md", "title_cn": "\u627e\u5230\u6700\u9ad8\u6d77\u62d4", "title_en": "Find the Highest Altitude", "question_title_slug": "find-the-highest-altitude", "content_en": "

There is a biker going on a road trip. The road trip consists of n + 1 points at different altitudes. The biker starts his trip on point 0 with altitude equal 0.

\n\n

You are given an integer array gain of length n where gain[i] is the net gain in altitude between points i\u200b\u200b\u200b\u200b\u200b\u200b and i + 1 for all (0 <= i < n). Return the highest altitude of a point.

\n\n

 

\n

Example 1:

\n\n
\nInput: gain = [-5,1,5,0,-7]\nOutput: 1\nExplanation: The altitudes are [0,-5,-4,1,1,-6]. The highest is 1.\n
\n\n

Example 2:

\n\n
\nInput: gain = [-4,-3,-2,-1,4,3,2]\nOutput: 0\nExplanation: The altitudes are [0,-4,-7,-9,-10,-6,-3,-1]. The highest is 0.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == gain.length
  • \n\t
  • 1 <= n <= 100
  • \n\t
  • -100 <= gain[i] <= 100
  • \n
\n", "content_cn": "

\u6709\u4e00\u4e2a\u81ea\u884c\u8f66\u624b\u6253\u7b97\u8fdb\u884c\u4e00\u573a\u516c\u8def\u9a91\u884c\uff0c\u8fd9\u6761\u8def\u7ebf\u603b\u5171\u7531\u00a0n + 1\u00a0\u4e2a\u4e0d\u540c\u6d77\u62d4\u7684\u70b9\u7ec4\u6210\u3002\u81ea\u884c\u8f66\u624b\u4ece\u6d77\u62d4\u4e3a 0\u00a0\u7684\u70b9\u00a00\u00a0\u5f00\u59cb\u9a91\u884c\u3002

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u4e3a n\u00a0\u7684\u6574\u6570\u6570\u7ec4\u00a0gain\u00a0\uff0c\u5176\u4e2d gain[i]\u00a0\u662f\u70b9 i\u00a0\u548c\u70b9 i + 1\u00a0\u7684 \u51c0\u6d77\u62d4\u9ad8\u5ea6\u5dee\uff080 <= i < n\uff09\u3002\u8bf7\u4f60\u8fd4\u56de \u6700\u9ad8\u70b9\u7684\u6d77\u62d4 \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1again = [-5,1,5,0,-7]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u6d77\u62d4\u9ad8\u5ea6\u4f9d\u6b21\u4e3a [0,-5,-4,1,1,-6] \u3002\u6700\u9ad8\u6d77\u62d4\u4e3a 1 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1again = [-4,-3,-2,-1,4,3,2]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6d77\u62d4\u9ad8\u5ea6\u4f9d\u6b21\u4e3a [0,-4,-7,-9,-10,-6,-3,-1] \u3002\u6700\u9ad8\u6d77\u62d4\u4e3a 0 \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • n == gain.length
  • \n\t
  • 1 <= n <= 100
  • \n\t
  • -100 <= gain[i] <= 100
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int largestAltitude(vector& gain) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int largestAltitude(int[] gain) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def largestAltitude(self, gain):\n \"\"\"\n :type gain: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def largestAltitude(self, gain: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint largestAltitude(int* gain, int gainSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LargestAltitude(int[] gain) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} gain\n * @return {number}\n */\nvar largestAltitude = function(gain) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} gain\n# @return {Integer}\ndef largest_altitude(gain)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func largestAltitude(_ gain: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func largestAltitude(gain []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def largestAltitude(gain: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun largestAltitude(gain: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn largest_altitude(gain: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $gain\n * @return Integer\n */\n function largestAltitude($gain) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function largestAltitude(gain: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (largest-altitude gain)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1732](https://leetcode-cn.com/problems/find-the-highest-altitude)", "[\u627e\u5230\u6700\u9ad8\u6d77\u62d4](/solution/1700-1799/1732.Find%20the%20Highest%20Altitude/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1732](https://leetcode.com/problems/find-the-highest-altitude)", "[Find the Highest Altitude](/solution/1700-1799/1732.Find%20the%20Highest%20Altitude/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1832", "frontend_question_id": "1713", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-operations-to-make-a-subsequence", "url_en": "https://leetcode.com/problems/minimum-operations-to-make-a-subsequence", "relative_path_cn": "/solution/1700-1799/1713.Minimum%20Operations%20to%20Make%20a%20Subsequence/README.md", "relative_path_en": "/solution/1700-1799/1713.Minimum%20Operations%20to%20Make%20a%20Subsequence/README_EN.md", "title_cn": "\u5f97\u5230\u5b50\u5e8f\u5217\u7684\u6700\u5c11\u64cd\u4f5c\u6b21\u6570", "title_en": "Minimum Operations to Make a Subsequence", "question_title_slug": "minimum-operations-to-make-a-subsequence", "content_en": "

You are given an array target that consists of distinct integers and another integer array arr that can have duplicates.

\n\n

In one operation, you can insert any integer at any position in arr. For example, if arr = [1,4,1,2], you can add 3 in the middle and make it [1,4,3,1,2]. Note that you can insert the integer at the very beginning or end of the array.

\n\n

Return the minimum number of operations needed to make target a subsequence of arr.

\n\n

A subsequence of an array is a new array generated from the original array by deleting some elements (possibly none) without changing the remaining elements' relative order. For example, [2,7,4] is a subsequence of [4,2,3,7,2,1,4] (the underlined elements), while [2,4,2] is not.

\n\n

 

\n

Example 1:

\n\n
\nInput: target = [5,1,3], arr = [9,4,2,3,4]\nOutput: 2\nExplanation: You can add 5 and 1 in such a way that makes arr = [5,9,4,1,2,3,4], then target will be a subsequence of arr.\n
\n\n

Example 2:

\n\n
\nInput: target = [6,4,8,1,3,2], arr = [4,7,6,2,3,8,6,1]\nOutput: 3\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= target.length, arr.length <= 105
  • \n\t
  • 1 <= target[i], arr[i] <= 109
  • \n\t
  • target contains no duplicates.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4\u00a0target\u00a0\uff0c\u5305\u542b\u82e5\u5e72 \u4e92\u4e0d\u76f8\u540c\u00a0\u7684\u6574\u6570\uff0c\u4ee5\u53ca\u53e6\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0arr\u00a0\uff0carr\u00a0\u53ef\u80fd \u5305\u542b\u91cd\u590d\u5143\u7d20\u3002

\n\n

\u6bcf\u4e00\u6b21\u64cd\u4f5c\u4e2d\uff0c\u4f60\u53ef\u4ee5\u5728 arr\u00a0\u7684\u4efb\u610f\u4f4d\u7f6e\u63d2\u5165\u4efb\u4e00\u6574\u6570\u3002\u6bd4\u65b9\u8bf4\uff0c\u5982\u679c\u00a0arr = [1,4,1,2]\u00a0\uff0c\u90a3\u4e48\u4f60\u53ef\u4ee5\u5728\u4e2d\u95f4\u6dfb\u52a0 3\u00a0\u5f97\u5230\u00a0[1,4,3,1,2]\u00a0\u3002\u4f60\u53ef\u4ee5\u5728\u6570\u7ec4\u6700\u5f00\u59cb\u6216\u6700\u540e\u9762\u6dfb\u52a0\u6574\u6570\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de \u6700\u5c11\u00a0\u64cd\u4f5c\u6b21\u6570\uff0c\u4f7f\u5f97\u00a0target\u00a0\u6210\u4e3a\u00a0arr\u00a0\u7684\u4e00\u4e2a\u5b50\u5e8f\u5217\u3002

\n\n

\u4e00\u4e2a\u6570\u7ec4\u7684 \u5b50\u5e8f\u5217\u00a0\u6307\u7684\u662f\u5220\u9664\u539f\u6570\u7ec4\u7684\u67d0\u4e9b\u5143\u7d20\uff08\u53ef\u80fd\u4e00\u4e2a\u5143\u7d20\u90fd\u4e0d\u5220\u9664\uff09\uff0c\u540c\u65f6\u4e0d\u6539\u53d8\u5176\u4f59\u5143\u7d20\u7684\u76f8\u5bf9\u987a\u5e8f\u5f97\u5230\u7684\u6570\u7ec4\u3002\u6bd4\u65b9\u8bf4\uff0c[2,7,4]\u00a0\u662f\u00a0[4,2,3,7,2,1,4]\u00a0\u7684\u5b50\u5e8f\u5217\uff08\u52a0\u7c97\u5143\u7d20\uff09\uff0c\u4f46\u00a0[2,4,2]\u00a0\u4e0d\u662f\u5b50\u5e8f\u5217\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1atarget = [5,1,3], arr = [9,4,2,3,4]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u6dfb\u52a0 5 \u548c 1 \uff0c\u4f7f\u5f97 arr \u53d8\u4e3a [5,9,4,1,2,3,4] \uff0ctarget \u4e3a arr \u7684\u5b50\u5e8f\u5217\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1atarget = [6,4,8,1,3,2], arr = [4,7,6,2,3,8,6,1]\n\u8f93\u51fa\uff1a3\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= target.length, arr.length <= 105
  • \n\t
  • 1 <= target[i], arr[i] <= 109
  • \n\t
  • target\u00a0\u4e0d\u5305\u542b\u4efb\u4f55\u91cd\u590d\u5143\u7d20\u3002
  • \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minOperations(vector& target, vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minOperations(int[] target, int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minOperations(self, target, arr):\n \"\"\"\n :type target: List[int]\n :type arr: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minOperations(self, target: List[int], arr: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minOperations(int* target, int targetSize, int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinOperations(int[] target, int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} target\n * @param {number[]} arr\n * @return {number}\n */\nvar minOperations = function(target, arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} target\n# @param {Integer[]} arr\n# @return {Integer}\ndef min_operations(target, arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minOperations(_ target: [Int], _ arr: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minOperations(target []int, arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minOperations(target: Array[Int], arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minOperations(target: IntArray, arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_operations(target: Vec, arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $target\n * @param Integer[] $arr\n * @return Integer\n */\n function minOperations($target, $arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minOperations(target: number[], arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-operations target arr)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1713](https://leetcode-cn.com/problems/minimum-operations-to-make-a-subsequence)", "[\u5f97\u5230\u5b50\u5e8f\u5217\u7684\u6700\u5c11\u64cd\u4f5c\u6b21\u6570](/solution/1700-1799/1713.Minimum%20Operations%20to%20Make%20a%20Subsequence/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[1713](https://leetcode.com/problems/minimum-operations-to-make-a-subsequence)", "[Minimum Operations to Make a Subsequence](/solution/1700-1799/1713.Minimum%20Operations%20to%20Make%20a%20Subsequence/README_EN.md)", "`Greedy`", "Hard", ""]}, {"question_id": "1831", "frontend_question_id": "1712", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/ways-to-split-array-into-three-subarrays", "url_en": "https://leetcode.com/problems/ways-to-split-array-into-three-subarrays", "relative_path_cn": "/solution/1700-1799/1712.Ways%20to%20Split%20Array%20Into%20Three%20Subarrays/README.md", "relative_path_en": "/solution/1700-1799/1712.Ways%20to%20Split%20Array%20Into%20Three%20Subarrays/README_EN.md", "title_cn": "\u5c06\u6570\u7ec4\u5206\u6210\u4e09\u4e2a\u5b50\u6570\u7ec4\u7684\u65b9\u6848\u6570", "title_en": "Ways to Split Array Into Three Subarrays", "question_title_slug": "ways-to-split-array-into-three-subarrays", "content_en": "

A split of an integer array is good if:

\r\n\r\n
    \r\n\t
  • The array is split into three non-empty contiguous subarrays - named left, mid, right respectively from left to right.
  • \r\n\t
  • The sum of the elements in left is less than or equal to the sum of the elements in mid, and the sum of the elements in mid is less than or equal to the sum of the elements in right.
  • \r\n
\r\n\r\n

Given nums, an array of non-negative integers, return the number of good ways to split nums. As the number may be too large, return it modulo 109 + 7.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: nums = [1,1,1]\r\nOutput: 1\r\nExplanation: The only good way to split nums is [1] [1] [1].
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: nums = [1,2,2,2,5,0]\r\nOutput: 3\r\nExplanation: There are three good ways of splitting nums:\r\n[1] [2] [2,2,5,0]\r\n[1] [2,2] [2,5,0]\r\n[1,2] [2,2] [5,0]\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: nums = [3,2,1]\r\nOutput: 0\r\nExplanation: There is no good way to split nums.
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 3 <= nums.length <= 105
  • \r\n\t
  • 0 <= nums[i] <= 104
  • \r\n
", "content_cn": "

\u6211\u4eec\u79f0\u4e00\u4e2a\u5206\u5272\u6574\u6570\u6570\u7ec4\u7684\u65b9\u6848\u662f \u597d\u7684\u00a0\uff0c\u5f53\u5b83\u6ee1\u8db3\uff1a

\n\n
    \n\t
  • \u6570\u7ec4\u88ab\u5206\u6210\u4e09\u4e2a \u975e\u7a7a\u00a0\u8fde\u7eed\u5b50\u6570\u7ec4\uff0c\u4ece\u5de6\u81f3\u53f3\u5206\u522b\u547d\u540d\u4e3a\u00a0left\u00a0\uff0c\u00a0mid\u00a0\uff0c\u00a0right\u00a0\u3002
  • \n\t
  • left\u00a0\u4e2d\u5143\u7d20\u548c\u5c0f\u4e8e\u7b49\u4e8e\u00a0mid\u00a0\u4e2d\u5143\u7d20\u548c\uff0cmid\u00a0\u4e2d\u5143\u7d20\u548c\u5c0f\u4e8e\u7b49\u4e8e\u00a0right\u00a0\u4e2d\u5143\u7d20\u548c\u3002
  • \n
\n\n

\u7ed9\u4f60\u4e00\u4e2a \u975e\u8d1f \u6574\u6570\u6570\u7ec4\u00a0nums\u00a0\uff0c\u8bf7\u4f60\u8fd4\u56de\u00a0\u597d\u7684 \u5206\u5272 nums\u00a0\u65b9\u6848\u6570\u76ee\u3002\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u4f1a\u5f88\u5927\uff0c\u8bf7\u4f60\u5c06\u7ed3\u679c\u5bf9 109\u00a0+ 7\u00a0\u53d6\u4f59\u540e\u8fd4\u56de\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [1,1,1]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u552f\u4e00\u4e00\u79cd\u597d\u7684\u5206\u5272\u65b9\u6848\u662f\u5c06 nums \u5206\u6210 [1] [1] [1] \u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [1,2,2,2,5,0]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1anums \u603b\u5171\u6709 3 \u79cd\u597d\u7684\u5206\u5272\u65b9\u6848\uff1a\n[1] [2] [2,2,5,0]\n[1] [2,2] [2,5,0]\n[1,2] [2,2] [5,0]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [3,2,1]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6ca1\u6709\u597d\u7684\u5206\u5272\u65b9\u6848\u3002
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 3 <= nums.length <= 105
  • \n\t
  • 0 <= nums[i] <= 104
  • \n
\n", "tags_en": ["Two Pointers", "Binary Search"], "tags_cn": ["\u53cc\u6307\u9488", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int waysToSplit(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int waysToSplit(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def waysToSplit(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def waysToSplit(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint waysToSplit(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int WaysToSplit(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar waysToSplit = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef ways_to_split(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func waysToSplit(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func waysToSplit(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def waysToSplit(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun waysToSplit(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn ways_to_split(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function waysToSplit($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function waysToSplit(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (ways-to-split nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1712](https://leetcode-cn.com/problems/ways-to-split-array-into-three-subarrays)", "[\u5c06\u6570\u7ec4\u5206\u6210\u4e09\u4e2a\u5b50\u6570\u7ec4\u7684\u65b9\u6848\u6570](/solution/1700-1799/1712.Ways%20to%20Split%20Array%20Into%20Three%20Subarrays/README.md)", "`\u53cc\u6307\u9488`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1712](https://leetcode.com/problems/ways-to-split-array-into-three-subarrays)", "[Ways to Split Array Into Three Subarrays](/solution/1700-1799/1712.Ways%20to%20Split%20Array%20Into%20Three%20Subarrays/README_EN.md)", "`Two Pointers`,`Binary Search`", "Medium", ""]}, {"question_id": "1830", "frontend_question_id": "1711", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-good-meals", "url_en": "https://leetcode.com/problems/count-good-meals", "relative_path_cn": "/solution/1700-1799/1711.Count%20Good%20Meals/README.md", "relative_path_en": "/solution/1700-1799/1711.Count%20Good%20Meals/README_EN.md", "title_cn": "\u5927\u9910\u8ba1\u6570", "title_en": "Count Good Meals", "question_title_slug": "count-good-meals", "content_en": "

A good meal is a meal that contains exactly two different food items with a sum of deliciousness equal to a power of two.

\n\n

You can pick any two different foods to make a good meal.

\n\n

Given an array of integers deliciousness where deliciousness[i] is the deliciousness of the i\u200b\u200b\u200b\u200b\u200b\u200bth\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b item of food, return the number of different good meals you can make from this list modulo 109 + 7.

\n\n

Note that items with different indices are considered different even if they have the same deliciousness value.

\n\n

 

\n

Example 1:

\n\n
\nInput: deliciousness = [1,3,5,7,9]\nOutput: 4\nExplanation: The good meals are (1,3), (1,7), (3,5) and, (7,9).\nTheir respective sums are 4, 8, 8, and 16, all of which are powers of 2.\n
\n\n

Example 2:

\n\n
\nInput: deliciousness = [1,1,1,3,3,3,7]\nOutput: 15\nExplanation: The good meals are (1,1) with 3 ways, (1,3) with 9 ways, and (1,7) with 3 ways.
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= deliciousness.length <= 105
  • \n\t
  • 0 <= deliciousness[i] <= 220
  • \n
\n", "content_cn": "

\u5927\u9910 \u662f\u6307 \u6070\u597d\u5305\u542b\u4e24\u9053\u4e0d\u540c\u9910\u54c1 \u7684\u4e00\u9910\uff0c\u5176\u7f8e\u5473\u7a0b\u5ea6\u4e4b\u548c\u7b49\u4e8e 2 \u7684\u5e42\u3002

\n\n

\u4f60\u53ef\u4ee5\u642d\u914d \u4efb\u610f \u4e24\u9053\u9910\u54c1\u505a\u4e00\u987f\u5927\u9910\u3002

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 deliciousness \uff0c\u5176\u4e2d deliciousness[i] \u662f\u7b2c i\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b \u9053\u9910\u54c1\u7684\u7f8e\u5473\u7a0b\u5ea6\uff0c\u8fd4\u56de\u4f60\u53ef\u4ee5\u7528\u6570\u7ec4\u4e2d\u7684\u9910\u54c1\u505a\u51fa\u7684\u4e0d\u540c \u5927\u9910 \u7684\u6570\u91cf\u3002\u7ed3\u679c\u9700\u8981\u5bf9 109 + 7 \u53d6\u4f59\u3002

\n\n

\u6ce8\u610f\uff0c\u53ea\u8981\u9910\u54c1\u4e0b\u6807\u4e0d\u540c\uff0c\u5c31\u53ef\u4ee5\u8ba4\u4e3a\u662f\u4e0d\u540c\u7684\u9910\u54c1\uff0c\u5373\u4fbf\u5b83\u4eec\u7684\u7f8e\u5473\u7a0b\u5ea6\u76f8\u540c\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1adeliciousness = [1,3,5,7,9]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u5927\u9910\u7684\u7f8e\u5473\u7a0b\u5ea6\u7ec4\u5408\u4e3a (1,3) \u3001(1,7) \u3001(3,5) \u548c (7,9) \u3002\n\u5b83\u4eec\u5404\u81ea\u7684\u7f8e\u5473\u7a0b\u5ea6\u4e4b\u548c\u5206\u522b\u4e3a 4 \u30018 \u30018 \u548c 16 \uff0c\u90fd\u662f 2 \u7684\u5e42\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1adeliciousness = [1,1,1,3,3,3,7]\n\u8f93\u51fa\uff1a15\n\u89e3\u91ca\uff1a\u5927\u9910\u7684\u7f8e\u5473\u7a0b\u5ea6\u7ec4\u5408\u4e3a 3 \u79cd (1,1) \uff0c9 \u79cd (1,3) \uff0c\u548c 3 \u79cd (1,7) \u3002
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= deliciousness.length <= 105
  • \n\t
  • 0 <= deliciousness[i] <= 220
  • \n
\n", "tags_en": ["Array", "Hash Table", "Two Pointers"], "tags_cn": ["\u6570\u7ec4", "\u54c8\u5e0c\u8868", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countPairs(vector& deliciousness) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countPairs(int[] deliciousness) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countPairs(self, deliciousness):\n \"\"\"\n :type deliciousness: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countPairs(self, deliciousness: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countPairs(int* deliciousness, int deliciousnessSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountPairs(int[] deliciousness) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} deliciousness\n * @return {number}\n */\nvar countPairs = function(deliciousness) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} deliciousness\n# @return {Integer}\ndef count_pairs(deliciousness)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countPairs(_ deliciousness: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countPairs(deliciousness []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countPairs(deliciousness: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countPairs(deliciousness: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_pairs(deliciousness: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $deliciousness\n * @return Integer\n */\n function countPairs($deliciousness) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countPairs(deliciousness: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-pairs deliciousness)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1711](https://leetcode-cn.com/problems/count-good-meals)", "[\u5927\u9910\u8ba1\u6570](/solution/1700-1799/1711.Count%20Good%20Meals/README.md)", "`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1711](https://leetcode.com/problems/count-good-meals)", "[Count Good Meals](/solution/1700-1799/1711.Count%20Good%20Meals/README_EN.md)", "`Array`,`Hash Table`,`Two Pointers`", "Medium", ""]}, {"question_id": "1829", "frontend_question_id": "1710", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-units-on-a-truck", "url_en": "https://leetcode.com/problems/maximum-units-on-a-truck", "relative_path_cn": "/solution/1700-1799/1710.Maximum%20Units%20on%20a%20Truck/README.md", "relative_path_en": "/solution/1700-1799/1710.Maximum%20Units%20on%20a%20Truck/README_EN.md", "title_cn": "\u5361\u8f66\u4e0a\u7684\u6700\u5927\u5355\u5143\u6570", "title_en": "Maximum Units on a Truck", "question_title_slug": "maximum-units-on-a-truck", "content_en": "

You are assigned to put some amount of boxes onto one truck. You are given a 2D array boxTypes, where boxTypes[i] = [numberOfBoxesi, numberOfUnitsPerBoxi]:

\n\n
    \n\t
  • numberOfBoxesi is the number of boxes of type i.
  • \n\t
  • numberOfUnitsPerBoxi is the number of units in each box of the type i.
  • \n
\n\n

You are also given an integer truckSize, which is the maximum number of boxes that can be put on the truck. You can choose any boxes to put on the truck as long as the number of boxes does not exceed truckSize.

\n\n

Return the maximum total number of units that can be put on the truck.

\n\n

 

\n

Example 1:

\n\n
\nInput: boxTypes = [[1,3],[2,2],[3,1]], truckSize = 4\nOutput: 8\nExplanation: There are:\n- 1 box of the first type that contains 3 units.\n- 2 boxes of the second type that contain 2 units each.\n- 3 boxes of the third type that contain 1 unit each.\nYou can take all the boxes of the first and second types, and one box of the third type.\nThe total number of units will be = (1 * 3) + (2 * 2) + (1 * 1) = 8.\n
\n\n

Example 2:

\n\n
\nInput: boxTypes = [[5,10],[2,5],[4,7],[3,9]], truckSize = 10\nOutput: 91\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= boxTypes.length <= 1000
  • \n\t
  • 1 <= numberOfBoxesi, numberOfUnitsPerBoxi <= 1000
  • \n\t
  • 1 <= truckSize <= 106
  • \n
\n", "content_cn": "

\u8bf7\u4f60\u5c06\u4e00\u4e9b\u7bb1\u5b50\u88c5\u5728 \u4e00\u8f86\u5361\u8f66 \u4e0a\u3002\u7ed9\u4f60\u4e00\u4e2a\u4e8c\u7ef4\u6570\u7ec4 boxTypes \uff0c\u5176\u4e2d boxTypes[i] = [numberOfBoxesi, numberOfUnitsPerBoxi] \uff1a

\n\n
    \n\t
  • numberOfBoxesi \u662f\u7c7b\u578b i \u7684\u7bb1\u5b50\u7684\u6570\u91cf\u3002
  • \n\t
  • numberOfUnitsPerBoxi \u662f\u7c7b\u578b i\u00a0\u6bcf\u4e2a\u7bb1\u5b50\u53ef\u4ee5\u88c5\u8f7d\u7684\u5355\u5143\u6570\u91cf\u3002
  • \n
\n\n

\u6574\u6570 truckSize \u8868\u793a\u5361\u8f66\u4e0a\u53ef\u4ee5\u88c5\u8f7d \u7bb1\u5b50 \u7684 \u6700\u5927\u6570\u91cf \u3002\u53ea\u8981\u7bb1\u5b50\u6570\u91cf\u4e0d\u8d85\u8fc7 truckSize \uff0c\u4f60\u5c31\u53ef\u4ee5\u9009\u62e9\u4efb\u610f\u7bb1\u5b50\u88c5\u5230\u5361\u8f66\u4e0a\u3002

\n\n

\u8fd4\u56de\u5361\u8f66\u53ef\u4ee5\u88c5\u8f7d\u00a0\u5355\u5143 \u7684 \u6700\u5927 \u603b\u6570\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aboxTypes = [[1,3],[2,2],[3,1]], truckSize = 4\n\u8f93\u51fa\uff1a8\n\u89e3\u91ca\uff1a\u7bb1\u5b50\u7684\u60c5\u51b5\u5982\u4e0b\uff1a\n- 1 \u4e2a\u7b2c\u4e00\u7c7b\u7684\u7bb1\u5b50\uff0c\u91cc\u9762\u542b 3 \u4e2a\u5355\u5143\u3002\n- 2 \u4e2a\u7b2c\u4e8c\u7c7b\u7684\u7bb1\u5b50\uff0c\u6bcf\u4e2a\u91cc\u9762\u542b 2 \u4e2a\u5355\u5143\u3002\n- 3 \u4e2a\u7b2c\u4e09\u7c7b\u7684\u7bb1\u5b50\uff0c\u6bcf\u4e2a\u91cc\u9762\u542b 1 \u4e2a\u5355\u5143\u3002\n\u53ef\u4ee5\u9009\u62e9\u7b2c\u4e00\u7c7b\u548c\u7b2c\u4e8c\u7c7b\u7684\u6240\u6709\u7bb1\u5b50\uff0c\u4ee5\u53ca\u7b2c\u4e09\u7c7b\u7684\u4e00\u4e2a\u7bb1\u5b50\u3002\n\u5355\u5143\u603b\u6570 = (1 * 3) + (2 * 2) + (1 * 1) = 8
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aboxTypes = [[5,10],[2,5],[4,7],[3,9]], truckSize = 10\n\u8f93\u51fa\uff1a91\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= boxTypes.length <= 1000
  • \n\t
  • 1 <= numberOfBoxesi, numberOfUnitsPerBoxi <= 1000
  • \n\t
  • 1 <= truckSize <= 106
  • \n
\n", "tags_en": ["Greedy", "Sort"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6392\u5e8f"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maximumUnits(vector>& boxTypes, int truckSize) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maximumUnits(int[][] boxTypes, int truckSize) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximumUnits(self, boxTypes, truckSize):\n \"\"\"\n :type boxTypes: List[List[int]]\n :type truckSize: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximumUnits(self, boxTypes: List[List[int]], truckSize: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maximumUnits(int** boxTypes, int boxTypesSize, int* boxTypesColSize, int truckSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaximumUnits(int[][] boxTypes, int truckSize) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} boxTypes\n * @param {number} truckSize\n * @return {number}\n */\nvar maximumUnits = function(boxTypes, truckSize) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} box_types\n# @param {Integer} truck_size\n# @return {Integer}\ndef maximum_units(box_types, truck_size)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximumUnits(_ boxTypes: [[Int]], _ truckSize: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximumUnits(boxTypes [][]int, truckSize int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximumUnits(boxTypes: Array[Array[Int]], truckSize: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximumUnits(boxTypes: Array, truckSize: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximum_units(box_types: Vec>, truck_size: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $boxTypes\n * @param Integer $truckSize\n * @return Integer\n */\n function maximumUnits($boxTypes, $truckSize) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximumUnits(boxTypes: number[][], truckSize: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximum-units boxTypes truckSize)\n (-> (listof (listof exact-integer?)) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1710](https://leetcode-cn.com/problems/maximum-units-on-a-truck)", "[\u5361\u8f66\u4e0a\u7684\u6700\u5927\u5355\u5143\u6570](/solution/1700-1799/1710.Maximum%20Units%20on%20a%20Truck/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6392\u5e8f`", "\u7b80\u5355", ""], "md_table_row_en": ["[1710](https://leetcode.com/problems/maximum-units-on-a-truck)", "[Maximum Units on a Truck](/solution/1700-1799/1710.Maximum%20Units%20on%20a%20Truck/README_EN.md)", "`Greedy`,`Sort`", "Easy", ""]}, {"question_id": "1828", "frontend_question_id": "1692", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/count-ways-to-distribute-candies", "url_en": "https://leetcode.com/problems/count-ways-to-distribute-candies", "relative_path_cn": "/solution/1600-1699/1692.Count%20Ways%20to%20Distribute%20Candies/README.md", "relative_path_en": "/solution/1600-1699/1692.Count%20Ways%20to%20Distribute%20Candies/README_EN.md", "title_cn": "\u8ba1\u7b97\u5206\u914d\u7cd6\u679c\u7684\u4e0d\u540c\u65b9\u5f0f", "title_en": "Count Ways to Distribute Candies", "question_title_slug": "count-ways-to-distribute-candies", "content_en": "

There are n unique candies (labeled 1 through n) and k bags. You are asked to distribute all the candies into the bags such that every bag has at least one candy.

\n\n

There can be multiple ways to distribute the candies. Two ways are considered different if the candies in one bag in the first way are not all in the same bag in the second way. The order of the bags and the order of the candies within each bag do not matter.

\n\n

For example, (1), (2,3) and (2), (1,3) are considered different because candies 2 and 3 in the bag (2,3) in the first way are not in the same bag in the second way (they are split between the bags (2) and (1,3)). However, (1), (2,3) and (3,2), (1) are considered the same because the candies in each bag are all in the same bags in both ways.

\n\n

Given two integers, n and k, return the number of different ways to distribute the candies. As the answer may be too large, return it modulo 109 + 7.

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: n = 3, k = 2\nOutput: 3\nExplanation: You can distribute 3 candies into 2 bags in 3 ways:\n(1), (2,3)\n(1,2), (3)\n(1,3), (2)\n
\n\n

Example 2:

\n\n
\nInput: n = 4, k = 2\nOutput: 7\nExplanation: You can distribute 4 candies into 2 bags in 7 ways:\n(1), (2,3,4)\n(1,2), (3,4)\n(1,3), (2,4)\n(1,4), (2,3)\n(1,2,3), (4)\n(1,2,4), (3)\n(1,3,4), (2)\n
\n\n

Example 3:

\n\n
\nInput: n = 20, k = 5\nOutput: 206085257\nExplanation: You can distribute 20 candies into 5 bags in 1881780996 ways. 1881780996 modulo 109 + 7 = 206085257.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= k <= n <= 1000
  • \n
\n", "content_cn": "

\u73b0\u6709 n \u9897 \u4e0d\u540c \u7cd6\u679c\uff08\u5206\u522b\u6807\u8bb0\u4e3a 1 \u5230 n \uff09\u548c k \u4e2a\u76f8\u540c\u7684\u624b\u888b\u3002\u8bf7\u628a\u7cd6\u679c\u5206\u914d\u5230\u5404\u4e2a\u624b\u888b\u4e2d\u5e76\u4fdd\u8bc1\u6bcf\u4e2a\u624b\u888b\u91cc\u81f3\u5c11\u6709\u4e00\u9897\u7cd6\u679c\u3002

\n\n

\u4e0d\u8003\u8651\u624b\u888b\u548c\u7cd6\u679c\u7684\u6446\u653e\u987a\u5e8f\uff0c\u4f1a\u6709\u591a\u79cd\u4e0d\u540c\u7684\u5206\u914d\u65b9\u5f0f\u3002\u5982\u679c\u67d0\u79cd\u5206\u914d\u65b9\u5f0f\u4e2d\u5176\u4e2d\u4e00\u4e2a\u624b\u888b\u91cc\u7684\u7cd6\u679c\u4e0e\u53e6\u4e00\u79cd\u5206\u914d\u65b9\u5f0f\u4e2d\u6240\u6709\u624b\u888b\u91cc\u7684\u7cd6\u679c\u90fd\u4e0d\u76f8\u540c\uff0c\u5219\u8ba4\u4e3a\u8fd9\u4e24\u79cd\u5206\u914d\u65b9\u5f0f\u4e0d\u540c\u3002

\n\n

\u4f8b\u5982\uff0c(1), (2,3)\u00a0\u4e0e(2), (1,3)\u7684\u5206\u914d\u65b9\u5f0f\u662f\u4e0d\u540c\u7684\uff0c\u56e0\u4e3a\u7b2c\u4e00\u79cd\u5206\u914d\u65b9\u5f0f\u4e2d\u624b\u888b(2,3)\u91cc\u7684\u7cd6\u679c2\u548c3\uff0c\u5728\u7b2c\u4e8c\u79cd\u5206\u914d\u65b9\u5f0f\u4e2d\u88ab\u5206\u914d\u5230\u4e86\u624b\u888b(2)\u548c(1,3)\u00a0\u4e2d\u3002

\n\n

\u5df2\u77e5\u6574\u6570\u00a0n\u00a0\u548c\u00a0k, \u8bf7\u8fd4\u56de\u5206\u914d\u7cd6\u679c\u7684\u4e0d\u540c\u65b9\u5f0f\u3002\u8fd4\u56de\u7684\u7b54\u6848\u5982\u679c\u6570\u503c\u592a\u5927\uff0c\u8bf7\u53d6109 + 7\u7684\u6a21\uff0c\u5e76\u8fd4\u56de\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b\u00a01\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1an = 3, k = 2\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u628a\u7cd6\u679c 3 \u5206\u914d\u5230 2 \u4e2a\u624b\u888b\u4e2d\u7684\u4e00\u4e2a\uff0c\u5171\u6709 3 \u79cd\u65b9\u5f0f:\n(1), (2,3)\n(1,2), (3)\n(1,3), (2)\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1an = 4, k = 2\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u628a\u7cd6\u679c 4 \u5206\u914d\u5230 2 \u4e2a\u624b\u888b\u4e2d\u7684\u4e00\u4e2a\uff0c\u5171\u6709 7 \u79cd\u65b9\u5f0f:\n(1), (2,3,4)s\n(1,2), (3,4)\n(1,3), (2,4)\n(1,4), (2,3)\n(1,2,3), (4)\n(1,2,4), (3)\n(1,3,4), (2)\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1an = 20, k = 5\n\u8f93\u51fa\uff1a206085257\n\u89e3\u91ca\uff1a\u628a 20 \u9897\u7cd6\u679c\u5206\u914d\u5230 5 \u4e2a\u624b\u888b\u79cd\uff0c\u5171\u6709 1881780996 \u79cd\u65b9\u5f0f\u30021881780996 \u53d6 109 + 7\u7684\u6a21\uff0c\u7b49\u4e8e 206085257\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= k <= n <= 1000
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int waysToDistribute(int n, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int waysToDistribute(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def waysToDistribute(self, n, k):\n \"\"\"\n :type n: int\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def waysToDistribute(self, n: int, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint waysToDistribute(int n, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int WaysToDistribute(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} k\n * @return {number}\n */\nvar waysToDistribute = function(n, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} k\n# @return {Integer}\ndef ways_to_distribute(n, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func waysToDistribute(_ n: Int, _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func waysToDistribute(n int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def waysToDistribute(n: Int, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun waysToDistribute(n: Int, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn ways_to_distribute(n: i32, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $k\n * @return Integer\n */\n function waysToDistribute($n, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function waysToDistribute(n: number, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (ways-to-distribute n k)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1692](https://leetcode-cn.com/problems/count-ways-to-distribute-candies)", "[\u8ba1\u7b97\u5206\u914d\u7cd6\u679c\u7684\u4e0d\u540c\u65b9\u5f0f](/solution/1600-1699/1692.Count%20Ways%20to%20Distribute%20Candies/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1692](https://leetcode.com/problems/count-ways-to-distribute-candies)", "[Count Ways to Distribute Candies](/solution/1600-1699/1692.Count%20Ways%20to%20Distribute%20Candies/README_EN.md)", "`Dynamic Programming`", "Hard", "\ud83d\udd12"]}, {"question_id": "1827", "frontend_question_id": "1683", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/invalid-tweets", "url_en": "https://leetcode.com/problems/invalid-tweets", "relative_path_cn": "/solution/1600-1699/1683.Invalid%20Tweets/README.md", "relative_path_en": "/solution/1600-1699/1683.Invalid%20Tweets/README_EN.md", "title_cn": "\u65e0\u6548\u7684\u63a8\u6587", "title_en": "Invalid Tweets", "question_title_slug": "invalid-tweets", "content_en": "

Table: Tweets

\n\n
\n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| tweet_id       | int     |\n| content        | varchar |\n+----------------+---------+\ntweet_id is the primary key for this table.\nThis table contains all the tweets in a social media app.\n
\n\n

 

\n\n

Write an SQL query to find the IDs of the invalid tweets. The tweet is invalid if the number of characters used in the content of the tweet is strictly greater than 15.

\n\n

Return the result table in any order.

\n\n

The query result format is in the following example:

\n\n

 

\n\n
\nTweets table:\n+----------+----------------------------------+\n| tweet_id | content                          |\n+----------+----------------------------------+\n| 1        | Vote for Biden                   |\n| 2        | Let us make America great again! |\n+----------+----------------------------------+\n\nResult table:\n+----------+\n| tweet_id |\n+----------+\n| 2        |\n+----------+\nTweet 1 has length = 14. It is a valid tweet.\nTweet 2 has length = 32. It is an invalid tweet.\n
\n", "content_cn": "

\u8868\uff1aTweets

\n\n
+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| tweet_id       | int     |\n| content        | varchar |\n+----------------+---------+\ntweet_id \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\u3002\n\u8fd9\u4e2a\u8868\u5305\u542b\u67d0\u793e\u4ea4\u5a92\u4f53 App \u4e2d\u6240\u6709\u7684\u63a8\u6587\u3002
\n\n

\u00a0

\n\n

\u5199\u4e00\u6761\u00a0SQL \u8bed\u53e5\uff0c\u67e5\u8be2\u6240\u6709\u65e0\u6548\u63a8\u6587\u7684\u7f16\u53f7\uff08ID\uff09\u3002\u5f53\u63a8\u6587\u5185\u5bb9\u4e2d\u7684\u5b57\u7b26\u6570\u4e25\u683c\u5927\u4e8e 15 \u65f6\uff0c\u8be5\u63a8\u6587\u662f\u65e0\u6548\u7684\u3002

\n\n

\u4ee5\u4efb\u610f\u987a\u5e8f\u8fd4\u56de\u7ed3\u679c\u8868\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u793a\u4f8b\u6240\u793a\uff1a

\n\n

\u00a0

\n\n
Tweets \u8868\uff1a\n+----------+----------------------------------+\n| tweet_id | content                          |\n+----------+----------------------------------+\n| 1        | Vote for Biden                   |\n| 2        | Let us make America great again! |\n+----------+----------------------------------+\n\n\u7ed3\u679c\u8868\uff1a\n+----------+\n| tweet_id |\n+----------+\n| 2        |\n+----------+\n\u63a8\u6587 1 \u7684\u957f\u5ea6 length = 14\u3002\u8be5\u63a8\u6587\u662f\u6709\u6548\u7684\u3002\n\u63a8\u6587 2 \u7684\u957f\u5ea6 length = 32\u3002\u8be5\u63a8\u6587\u662f\u65e0\u6548\u7684\u3002\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1683](https://leetcode-cn.com/problems/invalid-tweets)", "[\u65e0\u6548\u7684\u63a8\u6587](/solution/1600-1699/1683.Invalid%20Tweets/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1683](https://leetcode.com/problems/invalid-tweets)", "[Invalid Tweets](/solution/1600-1699/1683.Invalid%20Tweets/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1826", "frontend_question_id": "1707", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-xor-with-an-element-from-array", "url_en": "https://leetcode.com/problems/maximum-xor-with-an-element-from-array", "relative_path_cn": "/solution/1700-1799/1707.Maximum%20XOR%20With%20an%20Element%20From%20Array/README.md", "relative_path_en": "/solution/1700-1799/1707.Maximum%20XOR%20With%20an%20Element%20From%20Array/README_EN.md", "title_cn": "\u4e0e\u6570\u7ec4\u4e2d\u5143\u7d20\u7684\u6700\u5927\u5f02\u6216\u503c", "title_en": "Maximum XOR With an Element From Array", "question_title_slug": "maximum-xor-with-an-element-from-array", "content_en": "

You are given an array nums consisting of non-negative integers. You are also given a queries array, where queries[i] = [xi, mi].

\n\n

The answer to the ith query is the maximum bitwise XOR value of xi and any element of nums that does not exceed mi. In other words, the answer is max(nums[j] XOR xi) for all j such that nums[j] <= mi. If all elements in nums are larger than mi, then the answer is -1.

\n\n

Return an integer array answer where answer.length == queries.length and answer[i] is the answer to the ith query.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [0,1,2,3,4], queries = [[3,1],[1,3],[5,6]]\nOutput: [3,3,7]\nExplanation:\n1) 0 and 1 are the only two integers not greater than 1. 0 XOR 3 = 3 and 1 XOR 3 = 2. The larger of the two is 3.\n2) 1 XOR 2 = 3.\n3) 5 XOR 2 = 7.\n
\n\n

Example 2:

\n\n
\nInput: nums = [5,2,4,6,6,3], queries = [[12,4],[8,1],[6,3]]\nOutput: [15,-1,5]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length, queries.length <= 105
  • \n\t
  • queries[i].length == 2
  • \n\t
  • 0 <= nums[j], xi, mi <= 109
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u7531\u975e\u8d1f\u6574\u6570\u7ec4\u6210\u7684\u6570\u7ec4 nums \u3002\u53e6\u6709\u4e00\u4e2a\u67e5\u8be2\u6570\u7ec4 queries \uff0c\u5176\u4e2d queries[i] = [xi, mi] \u3002

\n\n

\u7b2c i \u4e2a\u67e5\u8be2\u7684\u7b54\u6848\u662f xi \u548c\u4efb\u4f55 nums \u6570\u7ec4\u4e2d\u4e0d\u8d85\u8fc7 mi \u7684\u5143\u7d20\u6309\u4f4d\u5f02\u6216\uff08XOR\uff09\u5f97\u5230\u7684\u6700\u5927\u503c\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u7b54\u6848\u662f max(nums[j] XOR xi) \uff0c\u5176\u4e2d\u6240\u6709 j \u5747\u6ee1\u8db3 nums[j] <= mi \u3002\u5982\u679c nums \u4e2d\u7684\u6240\u6709\u5143\u7d20\u90fd\u5927\u4e8e mi\uff0c\u6700\u7ec8\u7b54\u6848\u5c31\u662f -1 \u3002

\n\n

\u8fd4\u56de\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 answer \u4f5c\u4e3a\u67e5\u8be2\u7684\u7b54\u6848\uff0c\u5176\u4e2d answer.length == queries.length \u4e14 answer[i] \u662f\u7b2c i \u4e2a\u67e5\u8be2\u7684\u7b54\u6848\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anums = [0,1,2,3,4], queries = [[3,1],[1,3],[5,6]]\n\u8f93\u51fa\uff1a[3,3,7]\n\u89e3\u91ca\uff1a\n1) 0 \u548c 1 \u662f\u4ec5\u6709\u7684\u4e24\u4e2a\u4e0d\u8d85\u8fc7 1 \u7684\u6574\u6570\u30020 XOR 3 = 3 \u800c 1 XOR 3 = 2 \u3002\u4e8c\u8005\u4e2d\u7684\u66f4\u5927\u503c\u662f 3 \u3002\n2) 1 XOR 2 = 3.\n3) 5 XOR 2 = 7.\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anums = [5,2,4,6,6,3], queries = [[12,4],[8,1],[6,3]]\n\u8f93\u51fa\uff1a[15,-1,5]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length, queries.length <= 105
  • \n\t
  • queries[i].length == 2
  • \n\t
  • 0 <= nums[j], xi, mi <= 109
  • \n
\n", "tags_en": ["Bit Manipulation", "Trie"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u5b57\u5178\u6811"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector maximizeXor(vector& nums, vector>& queries) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] maximizeXor(int[] nums, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximizeXor(self, nums, queries):\n \"\"\"\n :type nums: List[int]\n :type queries: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximizeXor(self, nums: List[int], queries: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* maximizeXor(int* nums, int numsSize, int** queries, int queriesSize, int* queriesColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] MaximizeXor(int[] nums, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number[][]} queries\n * @return {number[]}\n */\nvar maximizeXor = function(nums, queries) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer[][]} queries\n# @return {Integer[]}\ndef maximize_xor(nums, queries)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximizeXor(_ nums: [Int], _ queries: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximizeXor(nums []int, queries [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximizeXor(nums: Array[Int], queries: Array[Array[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximizeXor(nums: IntArray, queries: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximize_xor(nums: Vec, queries: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer[][] $queries\n * @return Integer[]\n */\n function maximizeXor($nums, $queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximizeXor(nums: number[], queries: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximize-xor nums queries)\n (-> (listof exact-integer?) (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1707](https://leetcode-cn.com/problems/maximum-xor-with-an-element-from-array)", "[\u4e0e\u6570\u7ec4\u4e2d\u5143\u7d20\u7684\u6700\u5927\u5f02\u6216\u503c](/solution/1700-1799/1707.Maximum%20XOR%20With%20an%20Element%20From%20Array/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u5b57\u5178\u6811`", "\u56f0\u96be", ""], "md_table_row_en": ["[1707](https://leetcode.com/problems/maximum-xor-with-an-element-from-array)", "[Maximum XOR With an Element From Array](/solution/1700-1799/1707.Maximum%20XOR%20With%20an%20Element%20From%20Array/README_EN.md)", "`Bit Manipulation`,`Trie`", "Hard", ""]}, {"question_id": "1825", "frontend_question_id": "1723", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-minimum-time-to-finish-all-jobs", "url_en": "https://leetcode.com/problems/find-minimum-time-to-finish-all-jobs", "relative_path_cn": "/solution/1700-1799/1723.Find%20Minimum%20Time%20to%20Finish%20All%20Jobs/README.md", "relative_path_en": "/solution/1700-1799/1723.Find%20Minimum%20Time%20to%20Finish%20All%20Jobs/README_EN.md", "title_cn": "\u5b8c\u6210\u6240\u6709\u5de5\u4f5c\u7684\u6700\u77ed\u65f6\u95f4", "title_en": "Find Minimum Time to Finish All Jobs", "question_title_slug": "find-minimum-time-to-finish-all-jobs", "content_en": "

You are given an integer array jobs, where jobs[i] is the amount of time it takes to complete the ith job.

\n\n

There are k workers that you can assign jobs to. Each job should be assigned to exactly one worker. The working time of a worker is the sum of the time it takes to complete all jobs assigned to them. Your goal is to devise an optimal assignment such that the maximum working time of any worker is minimized.

\n\n

Return the minimum possible maximum working time of any assignment.

\n\n

 

\n

Example 1:

\n\n
\nInput: jobs = [3,2,3], k = 3\nOutput: 3\nExplanation: By assigning each person one job, the maximum time is 3.\n
\n\n

Example 2:

\n\n
\nInput: jobs = [1,2,4,7,8], k = 2\nOutput: 11\nExplanation: Assign the jobs the following way:\nWorker 1: 1, 2, 8 (working time = 1 + 2 + 8 = 11)\nWorker 2: 4, 7 (working time = 4 + 7 = 11)\nThe maximum working time is 11.
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= k <= jobs.length <= 12
  • \n\t
  • 1 <= jobs[i] <= 107
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 jobs \uff0c\u5176\u4e2d jobs[i] \u662f\u5b8c\u6210\u7b2c i \u9879\u5de5\u4f5c\u8981\u82b1\u8d39\u7684\u65f6\u95f4\u3002

\n\n

\u8bf7\u4f60\u5c06\u8fd9\u4e9b\u5de5\u4f5c\u5206\u914d\u7ed9 k \u4f4d\u5de5\u4eba\u3002\u6240\u6709\u5de5\u4f5c\u90fd\u5e94\u8be5\u5206\u914d\u7ed9\u5de5\u4eba\uff0c\u4e14\u6bcf\u9879\u5de5\u4f5c\u53ea\u80fd\u5206\u914d\u7ed9\u4e00\u4f4d\u5de5\u4eba\u3002\u5de5\u4eba\u7684 \u5de5\u4f5c\u65f6\u95f4 \u662f\u5b8c\u6210\u5206\u914d\u7ed9\u4ed6\u4eec\u7684\u6240\u6709\u5de5\u4f5c\u82b1\u8d39\u65f6\u95f4\u7684\u603b\u548c\u3002\u8bf7\u4f60\u8bbe\u8ba1\u4e00\u5957\u6700\u4f73\u7684\u5de5\u4f5c\u5206\u914d\u65b9\u6848\uff0c\u4f7f\u5de5\u4eba\u7684 \u6700\u5927\u5de5\u4f5c\u65f6\u95f4 \u5f97\u4ee5 \u6700\u5c0f\u5316 \u3002

\n\n

\u8fd4\u56de\u5206\u914d\u65b9\u6848\u4e2d\u5c3d\u53ef\u80fd \u6700\u5c0f \u7684 \u6700\u5927\u5de5\u4f5c\u65f6\u95f4 \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1ajobs = [3,2,3], k = 3\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u7ed9\u6bcf\u4f4d\u5de5\u4eba\u5206\u914d\u4e00\u9879\u5de5\u4f5c\uff0c\u6700\u5927\u5de5\u4f5c\u65f6\u95f4\u662f 3 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1ajobs = [1,2,4,7,8], k = 2\n\u8f93\u51fa\uff1a11\n\u89e3\u91ca\uff1a\u6309\u4e0b\u8ff0\u65b9\u5f0f\u5206\u914d\u5de5\u4f5c\uff1a\n1 \u53f7\u5de5\u4eba\uff1a1\u30012\u30018\uff08\u5de5\u4f5c\u65f6\u95f4 = 1 + 2 + 8 = 11\uff09\n2 \u53f7\u5de5\u4eba\uff1a4\u30017\uff08\u5de5\u4f5c\u65f6\u95f4 = 4 + 7 = 11\uff09\n\u6700\u5927\u5de5\u4f5c\u65f6\u95f4\u662f 11 \u3002
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= k <= jobs.length <= 12
  • \n\t
  • 1 <= jobs[i] <= 107
  • \n
\n", "tags_en": ["Recursion", "Backtracking"], "tags_cn": ["\u9012\u5f52", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minimumTimeRequired(vector& jobs, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minimumTimeRequired(int[] jobs, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimumTimeRequired(self, jobs, k):\n \"\"\"\n :type jobs: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimumTimeRequired(self, jobs: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minimumTimeRequired(int* jobs, int jobsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinimumTimeRequired(int[] jobs, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} jobs\n * @param {number} k\n * @return {number}\n */\nvar minimumTimeRequired = function(jobs, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} jobs\n# @param {Integer} k\n# @return {Integer}\ndef minimum_time_required(jobs, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimumTimeRequired(_ jobs: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimumTimeRequired(jobs []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimumTimeRequired(jobs: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimumTimeRequired(jobs: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimum_time_required(jobs: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $jobs\n * @param Integer $k\n * @return Integer\n */\n function minimumTimeRequired($jobs, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimumTimeRequired(jobs: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimum-time-required jobs k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1723](https://leetcode-cn.com/problems/find-minimum-time-to-finish-all-jobs)", "[\u5b8c\u6210\u6240\u6709\u5de5\u4f5c\u7684\u6700\u77ed\u65f6\u95f4](/solution/1700-1799/1723.Find%20Minimum%20Time%20to%20Finish%20All%20Jobs/README.md)", "`\u9012\u5f52`,`\u56de\u6eaf\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[1723](https://leetcode.com/problems/find-minimum-time-to-finish-all-jobs)", "[Find Minimum Time to Finish All Jobs](/solution/1700-1799/1723.Find%20Minimum%20Time%20to%20Finish%20All%20Jobs/README_EN.md)", "`Recursion`,`Backtracking`", "Hard", ""]}, {"question_id": "1824", "frontend_question_id": "1705", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-number-of-eaten-apples", "url_en": "https://leetcode.com/problems/maximum-number-of-eaten-apples", "relative_path_cn": "/solution/1700-1799/1705.Maximum%20Number%20of%20Eaten%20Apples/README.md", "relative_path_en": "/solution/1700-1799/1705.Maximum%20Number%20of%20Eaten%20Apples/README_EN.md", "title_cn": "\u5403\u82f9\u679c\u7684\u6700\u5927\u6570\u76ee", "title_en": "Maximum Number of Eaten Apples", "question_title_slug": "maximum-number-of-eaten-apples", "content_en": "

There is a special kind of apple tree that grows apples every day for n days. On the ith day, the tree grows apples[i] apples that will rot after days[i] days, that is on day i + days[i] the apples will be rotten and cannot be eaten. On some days, the apple tree does not grow any apples, which are denoted by apples[i] == 0 and days[i] == 0.

\n\n

You decided to eat at most one apple a day (to keep the doctors away). Note that you can keep eating after the first n days.

\n\n

Given two integer arrays days and apples of length n, return the maximum number of apples you can eat.

\n\n

 

\n

Example 1:

\n\n
\nInput: apples = [1,2,3,5,2], days = [3,2,1,4,2]\nOutput: 7\nExplanation: You can eat 7 apples:\n- On the first day, you eat an apple that grew on the first day.\n- On the second day, you eat an apple that grew on the second day.\n- On the third day, you eat an apple that grew on the second day. After this day, the apples that grew on the third day rot.\n- On the fourth to the seventh days, you eat apples that grew on the fourth day.\n
\n\n

Example 2:

\n\n
\nInput: apples = [3,0,0,0,0,2], days = [3,0,0,0,0,2]\nOutput: 5\nExplanation: You can eat 5 apples:\n- On the first to the third day you eat apples that grew on the first day.\n- Do nothing on the fouth and fifth days.\n- On the sixth and seventh days you eat apples that grew on the sixth day.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • apples.length == n
  • \n\t
  • days.length == n
  • \n\t
  • 1 <= n <= 2 * 104
  • \n\t
  • 0 <= apples[i], days[i] <= 2 * 104
  • \n\t
  • days[i] = 0 if and only if apples[i] = 0.
  • \n
\n", "content_cn": "

\u6709\u4e00\u68f5\u7279\u6b8a\u7684\u82f9\u679c\u6811\uff0c\u4e00\u8fde n \u5929\uff0c\u6bcf\u5929\u90fd\u53ef\u4ee5\u957f\u51fa\u82e5\u5e72\u4e2a\u82f9\u679c\u3002\u5728\u7b2c i \u5929\uff0c\u6811\u4e0a\u4f1a\u957f\u51fa apples[i] \u4e2a\u82f9\u679c\uff0c\u8fd9\u4e9b\u82f9\u679c\u5c06\u4f1a\u5728 days[i] \u5929\u540e\uff08\u4e5f\u5c31\u662f\u8bf4\uff0c\u7b2c i + days[i] \u5929\u65f6\uff09\u8150\u70c2\uff0c\u53d8\u5f97\u65e0\u6cd5\u98df\u7528\u3002\u4e5f\u53ef\u80fd\u6709\u90a3\u4e48\u51e0\u5929\uff0c\u6811\u4e0a\u4e0d\u4f1a\u957f\u51fa\u65b0\u7684\u82f9\u679c\uff0c\u6b64\u65f6\u7528 apples[i] == 0 \u4e14 days[i] == 0 \u8868\u793a\u3002

\n\n

\u4f60\u6253\u7b97\u6bcf\u5929 \u6700\u591a \u5403\u4e00\u4e2a\u82f9\u679c\u6765\u4fdd\u8bc1\u8425\u517b\u5747\u8861\u3002\u6ce8\u610f\uff0c\u4f60\u53ef\u4ee5\u5728\u8fd9 n \u5929\u4e4b\u540e\u7ee7\u7eed\u5403\u82f9\u679c\u3002

\n\n

\u7ed9\u4f60\u4e24\u4e2a\u957f\u5ea6\u4e3a n \u7684\u6574\u6570\u6570\u7ec4 days \u548c apples \uff0c\u8fd4\u56de\u4f60\u53ef\u4ee5\u5403\u6389\u7684\u82f9\u679c\u7684\u6700\u5927\u6570\u76ee\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aapples = [1,2,3,5,2], days = [3,2,1,4,2]\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u5403\u6389 7 \u4e2a\u82f9\u679c\uff1a\n- \u7b2c\u4e00\u5929\uff0c\u4f60\u5403\u6389\u7b2c\u4e00\u5929\u957f\u51fa\u6765\u7684\u82f9\u679c\u3002\n- \u7b2c\u4e8c\u5929\uff0c\u4f60\u5403\u6389\u4e00\u4e2a\u7b2c\u4e8c\u5929\u957f\u51fa\u6765\u7684\u82f9\u679c\u3002\n- \u7b2c\u4e09\u5929\uff0c\u4f60\u5403\u6389\u4e00\u4e2a\u7b2c\u4e8c\u5929\u957f\u51fa\u6765\u7684\u82f9\u679c\u3002\u8fc7\u4e86\u8fd9\u4e00\u5929\uff0c\u7b2c\u4e09\u5929\u957f\u51fa\u6765\u7684\u82f9\u679c\u5c31\u5df2\u7ecf\u8150\u70c2\u4e86\u3002\n- \u7b2c\u56db\u5929\u5230\u7b2c\u4e03\u5929\uff0c\u4f60\u5403\u7684\u90fd\u662f\u7b2c\u56db\u5929\u957f\u51fa\u6765\u7684\u82f9\u679c\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aapples = [3,0,0,0,0,2], days = [3,0,0,0,0,2]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u5403\u6389 5 \u4e2a\u82f9\u679c\uff1a\n- \u7b2c\u4e00\u5929\u5230\u7b2c\u4e09\u5929\uff0c\u4f60\u5403\u7684\u90fd\u662f\u7b2c\u4e00\u5929\u957f\u51fa\u6765\u7684\u82f9\u679c\u3002\n- \u7b2c\u56db\u5929\u548c\u7b2c\u4e94\u5929\u4e0d\u5403\u82f9\u679c\u3002\n- \u7b2c\u516d\u5929\u548c\u7b2c\u4e03\u5929\uff0c\u4f60\u5403\u7684\u90fd\u662f\u7b2c\u516d\u5929\u957f\u51fa\u6765\u7684\u82f9\u679c\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • apples.length == n
  • \n\t
  • days.length == n
  • \n\t
  • 1 <= n <= 2 * 104
  • \n\t
  • 0 <= apples[i], days[i] <= 2 * 104
  • \n\t
  • \u53ea\u6709\u5728 apples[i] = 0 \u65f6\uff0cdays[i] = 0 \u624d\u6210\u7acb
  • \n
\n", "tags_en": ["Heap", "Greedy"], "tags_cn": ["\u5806", "\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int eatenApples(vector& apples, vector& days) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int eatenApples(int[] apples, int[] days) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def eatenApples(self, apples, days):\n \"\"\"\n :type apples: List[int]\n :type days: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def eatenApples(self, apples: List[int], days: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint eatenApples(int* apples, int applesSize, int* days, int daysSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int EatenApples(int[] apples, int[] days) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} apples\n * @param {number[]} days\n * @return {number}\n */\nvar eatenApples = function(apples, days) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} apples\n# @param {Integer[]} days\n# @return {Integer}\ndef eaten_apples(apples, days)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func eatenApples(_ apples: [Int], _ days: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func eatenApples(apples []int, days []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def eatenApples(apples: Array[Int], days: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun eatenApples(apples: IntArray, days: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn eaten_apples(apples: Vec, days: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $apples\n * @param Integer[] $days\n * @return Integer\n */\n function eatenApples($apples, $days) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function eatenApples(apples: number[], days: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (eaten-apples apples days)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1705](https://leetcode-cn.com/problems/maximum-number-of-eaten-apples)", "[\u5403\u82f9\u679c\u7684\u6700\u5927\u6570\u76ee](/solution/1700-1799/1705.Maximum%20Number%20of%20Eaten%20Apples/README.md)", "`\u5806`,`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1705](https://leetcode.com/problems/maximum-number-of-eaten-apples)", "[Maximum Number of Eaten Apples](/solution/1700-1799/1705.Maximum%20Number%20of%20Eaten%20Apples/README_EN.md)", "`Heap`,`Greedy`", "Medium", ""]}, {"question_id": "1823", "frontend_question_id": "1704", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/determine-if-string-halves-are-alike", "url_en": "https://leetcode.com/problems/determine-if-string-halves-are-alike", "relative_path_cn": "/solution/1700-1799/1704.Determine%20if%20String%20Halves%20Are%20Alike/README.md", "relative_path_en": "/solution/1700-1799/1704.Determine%20if%20String%20Halves%20Are%20Alike/README_EN.md", "title_cn": "\u5224\u65ad\u5b57\u7b26\u4e32\u7684\u4e24\u534a\u662f\u5426\u76f8\u4f3c", "title_en": "Determine if String Halves Are Alike", "question_title_slug": "determine-if-string-halves-are-alike", "content_en": "

You are given a string s of even length. Split this string into two halves of equal lengths, and let a be the first half and b be the second half.

\n\n

Two strings are alike if they have the same number of vowels ('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'). Notice that s contains uppercase and lowercase letters.

\n\n

Return true if a and b are alike. Otherwise, return false.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "book"\nOutput: true\nExplanation: a = "bo" and b = "ok". a has 1 vowel and b has 1 vowel. Therefore, they are alike.\n
\n\n

Example 2:

\n\n
\nInput: s = "textbook"\nOutput: false\nExplanation: a = "text" and b = "book". a has 1 vowel whereas b has 2. Therefore, they are not alike.\nNotice that the vowel o is counted twice.\n
\n\n

Example 3:

\n\n
\nInput: s = "MerryChristmas"\nOutput: false\n
\n\n

Example 4:

\n\n
\nInput: s = "AbCdEfGh"\nOutput: true\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= s.length <= 1000
  • \n\t
  • s.length is even.
  • \n\t
  • s consists of uppercase and lowercase letters.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5076\u6570\u957f\u5ea6\u7684\u5b57\u7b26\u4e32 s \u3002\u5c06\u5176\u62c6\u5206\u6210\u957f\u5ea6\u76f8\u540c\u7684\u4e24\u534a\uff0c\u524d\u4e00\u534a\u4e3a a \uff0c\u540e\u4e00\u534a\u4e3a b \u3002

\n\n

\u4e24\u4e2a\u5b57\u7b26\u4e32 \u76f8\u4f3c \u7684\u524d\u63d0\u662f\u5b83\u4eec\u90fd\u542b\u6709\u76f8\u540c\u6570\u76ee\u7684\u5143\u97f3\uff08'a'\uff0c'e'\uff0c'i'\uff0c'o'\uff0c'u'\uff0c'A'\uff0c'E'\uff0c'I'\uff0c'O'\uff0c'U'\uff09\u3002\u6ce8\u610f\uff0cs \u53ef\u80fd\u540c\u65f6\u542b\u6709\u5927\u5199\u548c\u5c0f\u5199\u5b57\u6bcd\u3002

\n\n

\u5982\u679c a \u548c b \u76f8\u4f3c\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1as = \"book\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1aa = \"bo\" \u4e14 b = \"ok\" \u3002a \u4e2d\u6709 1 \u4e2a\u5143\u97f3\uff0cb \u4e5f\u6709 1 \u4e2a\u5143\u97f3\u3002\u6240\u4ee5\uff0ca \u548c b \u76f8\u4f3c\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1as = \"textbook\"\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1aa = \"text\" \u4e14 b = \"book\" \u3002a \u4e2d\u6709 1 \u4e2a\u5143\u97f3\uff0cb \u4e2d\u6709 2 \u4e2a\u5143\u97f3\u3002\u56e0\u6b64\uff0ca \u548c b \u4e0d\u76f8\u4f3c\u3002\n\u6ce8\u610f\uff0c\u5143\u97f3 o \u5728 b \u4e2d\u51fa\u73b0\u4e24\u6b21\uff0c\u8bb0\u4e3a 2 \u4e2a\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1as = \"MerryChristmas\"\n\u8f93\u51fa\uff1afalse\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1as = \"AbCdEfGh\"\n\u8f93\u51fa\uff1atrue\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= s.length <= 1000
  • \n\t
  • s.length \u662f\u5076\u6570
  • \n\t
  • s \u7531 \u5927\u5199\u548c\u5c0f\u5199 \u5b57\u6bcd\u7ec4\u6210
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool halvesAreAlike(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean halvesAreAlike(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def halvesAreAlike(self, s):\n \"\"\"\n :type s: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def halvesAreAlike(self, s: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool halvesAreAlike(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool HalvesAreAlike(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {boolean}\n */\nvar halvesAreAlike = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Boolean}\ndef halves_are_alike(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func halvesAreAlike(_ s: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func halvesAreAlike(s string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def halvesAreAlike(s: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun halvesAreAlike(s: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn halves_are_alike(s: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Boolean\n */\n function halvesAreAlike($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function halvesAreAlike(s: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (halves-are-alike s)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1704](https://leetcode-cn.com/problems/determine-if-string-halves-are-alike)", "[\u5224\u65ad\u5b57\u7b26\u4e32\u7684\u4e24\u534a\u662f\u5426\u76f8\u4f3c](/solution/1700-1799/1704.Determine%20if%20String%20Halves%20Are%20Alike/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1704](https://leetcode.com/problems/determine-if-string-halves-are-alike)", "[Determine if String Halves Are Alike](/solution/1700-1799/1704.Determine%20if%20String%20Halves%20Are%20Alike/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1822", "frontend_question_id": "1682", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/longest-palindromic-subsequence-ii", "url_en": "https://leetcode.com/problems/longest-palindromic-subsequence-ii", "relative_path_cn": "/solution/1600-1699/1682.Longest%20Palindromic%20Subsequence%20II/README.md", "relative_path_en": "/solution/1600-1699/1682.Longest%20Palindromic%20Subsequence%20II/README_EN.md", "title_cn": "\u6700\u957f\u56de\u6587\u5b50\u5e8f\u5217 II", "title_en": "Longest Palindromic Subsequence II", "question_title_slug": "longest-palindromic-subsequence-ii", "content_en": "

A subsequence of a string s is considered a good palindromic subsequence if:

\r\n\r\n
    \r\n\t
  • It is a subsequence of s.
  • \r\n\t
  • It is a palindrome (has the same value if reversed).
  • \r\n\t
  • It has an even length.
  • \r\n\t
  • No two consecutive characters are equal, except the two middle ones.
  • \r\n
\r\n\r\n

For example, if s = "abcabcabb", then "abba" is considered a good palindromic subsequence, while "bcb" (not even length) and "bbbb" (has equal consecutive characters) are not.

\r\n\r\n

Given a string s, return the length of the longest good palindromic subsequence in s.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: s = "bbabab"\r\nOutput: 4\r\nExplanation: The longest good palindromic subsequence of s is "baab".\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: s = "dcbccacdb"\r\nOutput: 4\r\nExplanation: The longest good palindromic subsequence of s is "dccd".\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= s.length <= 250
  • \r\n\t
  • s consists of lowercase English letters.
  • \r\n
", "content_cn": "

\u5b57\u7b26\u4e32\u00a0s\u00a0\u7684\u67d0\u4e2a\u5b50\u5e8f\u5217\u7b26\u5408\u4e0b\u5217\u6761\u4ef6\u65f6\uff0c\u79f0\u4e3a\u201c\u597d\u7684\u56de\u6587\u5b50\u5e8f\u5217\u201d\uff1a

\n\n
    \n\t
  • \u5b83\u662f\u00a0s\u00a0\u7684\u5b50\u5e8f\u5217\u3002
  • \n\t
  • \u5b83\u662f\u56de\u6587\u5e8f\u5217\uff08\u53cd\u8f6c\u540e\u4e0e\u539f\u5e8f\u5217\u76f8\u7b49\uff09\u3002
  • \n\t
  • \u957f\u5ea6\u4e3a\u5076\u6570\u3002
  • \n\t
  • \u9664\u4e2d\u95f4\u7684\u4e24\u4e2a\u5b57\u7b26\u5916\uff0c\u5176\u4f59\u4efb\u610f\u4e24\u4e2a\u8fde\u7eed\u5b57\u7b26\u4e0d\u76f8\u7b49\u3002
  • \n
\n\n

\u4f8b\u5982\uff0c\u82e5\u00a0s = \"abcabcabb\"\uff0c\u5219\u00a0\"abba\"\u00a0\u53ef\u79f0\u4e3a\u201c\u597d\u7684\u56de\u6587\u5b50\u5e8f\u5217\u201d\uff0c\u800c\u00a0\"bcb\"\u00a0\uff08\u957f\u5ea6\u4e0d\u662f\u5076\u6570\uff09\u548c\u00a0\"bbbb\"\u00a0\uff08\u542b\u6709\u76f8\u7b49\u7684\u8fde\u7eed\u5b57\u7b26\uff09\u4e0d\u80fd\u79f0\u4e3a\u201c\u597d\u7684\u56de\u6587\u5b50\u5e8f\u5217\u201d\u3002

\n\n

\u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\u00a0s\uff0c \u8fd4\u56de\u00a0s\u00a0\u7684\u6700\u957f\u201c\u597d\u7684\u56de\u6587\u5b50\u5e8f\u5217\u201d\u7684\u957f\u5ea6\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1:

\n\n
\u8f93\u5165: s = \"bbabab\"\n\u8f93\u51fa: 4\n\u89e3\u91ca: s \u7684\u6700\u957f\u201c\u597d\u7684\u56de\u6587\u5b50\u5e8f\u5217\u201d\u662f \"baab\"\u3002\n
\n\n

\u793a\u4f8b 2:

\n\n
\u8f93\u5165: s = \"dcbccacdb\"\n\u8f93\u51fa: 4\n\u89e3\u91ca: The longest good palindromic subsequence of s is \"dccd\".\n
\n\n

\u00a0

\n\n

\u63d0\u793a:

\n\n
    \n\t
  • 1 <= s.length <= 250
  • \n\t
  • s\u00a0\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
  • \n
\n", "tags_en": ["String", "Dynamic Programming"], "tags_cn": ["\u5b57\u7b26\u4e32", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int longestPalindromeSubseq(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int longestPalindromeSubseq(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestPalindromeSubseq(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestPalindromeSubseq(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint longestPalindromeSubseq(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LongestPalindromeSubseq(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar longestPalindromeSubseq = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef longest_palindrome_subseq(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestPalindromeSubseq(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestPalindromeSubseq(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestPalindromeSubseq(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestPalindromeSubseq(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_palindrome_subseq(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function longestPalindromeSubseq($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestPalindromeSubseq(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-palindrome-subseq s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1682](https://leetcode-cn.com/problems/longest-palindromic-subsequence-ii)", "[\u6700\u957f\u56de\u6587\u5b50\u5e8f\u5217 II](/solution/1600-1699/1682.Longest%20Palindromic%20Subsequence%20II/README.md)", "`\u5b57\u7b26\u4e32`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1682](https://leetcode.com/problems/longest-palindromic-subsequence-ii)", "[Longest Palindromic Subsequence II](/solution/1600-1699/1682.Longest%20Palindromic%20Subsequence%20II/README_EN.md)", "`String`,`Dynamic Programming`", "Medium", "\ud83d\udd12"]}, {"question_id": "1821", "frontend_question_id": "1677", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/products-worth-over-invoices", "url_en": "https://leetcode.com/problems/products-worth-over-invoices", "relative_path_cn": "/solution/1600-1699/1677.Product%27s%20Worth%20Over%20Invoices/README.md", "relative_path_en": "/solution/1600-1699/1677.Product%27s%20Worth%20Over%20Invoices/README_EN.md", "title_cn": "\u53d1\u7968\u4e2d\u7684\u4ea7\u54c1\u91d1\u989d", "title_en": "Product's Worth Over Invoices", "question_title_slug": "products-worth-over-invoices", "content_en": "

Table: Product

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| product_id  | int     |\n| name        | varchar |\n+-------------+---------+\nproduct_id is the primary key for this table.\nThis table contains the ID and the name of the product. The name consists of only lowercase English letters. No two products have the same name.\n
\n\n

 

\n\n

Table: Invoice

\n\n
\n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| invoice_id  | int  |\n| product_id  | int  |\n| rest        | int  |\n| paid        | int  |\n| canceled    | int  |\n| refunded    | int  |\n+-------------+------+\ninvoice_id is the primary key for this table and the id of this invoice.\nproduct_id is the id of the product for this invoice.\nrest is the amount left to pay for this invoice.\npaid is the amount paid for this invoice.\ncanceled is the amount canceled for this invoice.\nrefunded is the amount refunded for this invoice.\n
\n\n

 

\n\n

Write an SQL query that will, for all products, return each product name with total amount due, paid, canceled, and refunded across all invoices.

\n\n

Return the result table ordered by product_name.

\n\n

The query result format is in the following example:

\n\n

 

\n\n
\nProduct table:\n+------------+-------+\n| product_id | name  |\n+------------+-------+\n| 0          | ham   |\n| 1          | bacon |\n+------------+-------+\nInvoice table:\n+------------+------------+------+------+----------+----------+\n| invoice_id | product_id | rest | paid | canceled | refunded |\n+------------+------------+------+------+----------+----------+\n| 23         | 0          | 2    | 0    | 5        | 0        |\n| 12         | 0          | 0    | 4    | 0        | 3        |\n| 1          | 1          | 1    | 1    | 0        | 1        |\n| 2          | 1          | 1    | 0    | 1        | 1        |\n| 3          | 1          | 0    | 1    | 1        | 1        |\n| 4          | 1          | 1    | 1    | 1        | 0        |\n+------------+------------+------+------+----------+----------+\nResult table:\n+-------+------+------+----------+----------+\n| name  | rest | paid | canceled | refunded |\n+-------+------+------+----------+----------+\n| bacon | 3    | 3    | 3        | 3        |\n| ham   | 2    | 4    | 5        | 3        |\n+-------+------+------+----------+----------+\n- The amount of money left to pay for bacon is 1 + 1 + 0 + 1 = 3\n- The amount of money paid for bacon is 1 + 0 + 1 + 1 = 3\n- The amount of money canceled for bacon is 0 + 1 + 1 + 1 = 3\n- The amount of money refunded for bacon is 1 + 1 + 1 + 0 = 3\n- The amount of money left to pay for ham is 2 + 0 = 2\n- The amount of money paid for ham is 0 + 4 = 4\n- The amount of money canceled for ham is 5 + 0 = 5\n- The amount of money refunded for ham is 0 + 3 = 3\n
\n", "content_cn": "

Product \u8868\uff1a

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| product_id  | int     |\n| name        | varchar |\n+-------------+---------+\nproduct_id \u662f\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\n\u8868\u4e2d\u542b\u6709\u4ea7\u54c1 id \u3001\u4ea7\u54c1\u540d\u79f0\u3002\u4ea7\u54c1\u540d\u79f0\u90fd\u662f\u5c0f\u5199\u7684\u82f1\u6587\u5b57\u6bcd\uff0c\u4ea7\u54c1\u540d\u79f0\u90fd\u662f\u552f\u4e00\u7684\n
\n\n

\u00a0

\n\n

Invoice \u8868\uff1a

\n\n
\n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| invoice_id  | int  |\n| product_id  | int  |\n| rest        | int  |\n| paid        | int  |\n| canceled    | int  |\n| refunded    | int  |\n+-------------+------+\ninvoice_id \u53d1\u7968 id \uff0c\u662f\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\nproduct_id \u4ea7\u54c1 id\nrest \u5e94\u7f34\u6b3e\u9879\npaid \u5df2\u652f\u4ed8\u91d1\u989d\ncanceled \u5df2\u53d6\u6d88\u91d1\u989d\nrefunded \u5df2\u9000\u6b3e\u91d1\u989d\n
\n\n

\u00a0

\n\n

\u8981\u6c42\u5199\u4e00\u4e2aSQL\u67e5\u8be2\uff0c\u8fd4\u56de\u5168\u90e8\u53d1\u7968\u4e2d\u6bcf\u4e2a\u4ea7\u54c1\u7684\u4ea7\u54c1\u540d\u79f0\u3001\u603b\u5e94\u7f34\u6b3e\u9879\u3001\u603b\u5df2\u652f\u4ed8\u91d1\u989d\u3001\u603b\u5df2\u53d6\u6d88\u91d1\u989d\u3001\u603b\u5df2\u9000\u6b3e\u91d1\u989d

\n\n

\u67e5\u8be2\u7ed3\u679c\u6309 product_name\u6392\u5e8f

\n\n

\u793a\u4f8b\uff1a

\n\n
\nProduct \u8868\uff1a\n+------------+-------+\n| product_id | name  |\n+------------+-------+\n| 0          | ham   |\n| 1          | bacon |\n+------------+-------+\nInvoice table:\n+------------+------------+------+------+----------+----------+\n| invoice_id | product_id | rest | paid | canceled | refunded |\n+------------+------------+------+------+----------+----------+\n| 23         | 0          | 2    | 0    | 5        | 0        |\n| 12         | 0          | 0    | 4    | 0        | 3        |\n| 1          | 1          | 1    | 1    | 0        | 1        |\n| 2          | 1          | 1    | 0    | 1        | 1        |\n| 3          | 1          | 0    | 1    | 1        | 1        |\n| 4          | 1          | 1    | 1    | 1        | 0        |\n+------------+------------+------+------+----------+----------+\nResult \u8868\uff1a\n+-------+------+------+----------+----------+\n| name  | rest | paid | canceled | refunded |\n+-------+------+------+----------+----------+\n| bacon | 3    | 3    | 3        | 3        |\n| ham   | 2    | 4    | 5        | 3        |\n+-------+------+------+----------+----------+\n- bacon \u7684\u603b\u5e94\u7f34\u6b3e\u9879\u4e3a 1 + 1 + 0 + 1 = 3\n- bacon \u7684\u603b\u5df2\u652f\u4ed8\u91d1\u989d\u4e3a 1 + 0 + 1 + 1 = 3\n- bacon \u7684\u603b\u5df2\u53d6\u6d88\u91d1\u989d\u4e3a 0 + 1 + 1 + 1 = 3\n- bacon \u7684\u603b\u5df2\u9000\u6b3e\u91d1\u989d\u4e3a 1 + 1 + 1 + 0 = 3\n- ham \u7684\u603b\u5e94\u7f34\u6b3e\u9879\u4e3a 2 + 0 = 2\n- ham \u7684\u603b\u5df2\u652f\u4ed8\u91d1\u989d\u4e3a 0 + 4 = 4\n- ham \u7684\u603b\u5df2\u53d6\u6d88\u91d1\u989d\u4e3a 5 + 0 = 5\n- ham \u7684\u603b\u5df2\u9000\u6b3e\u91d1\u989d\u4e3a 0 + 3 = 3\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1677](https://leetcode-cn.com/problems/products-worth-over-invoices)", "[\u53d1\u7968\u4e2d\u7684\u4ea7\u54c1\u91d1\u989d](/solution/1600-1699/1677.Product%27s%20Worth%20Over%20Invoices/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1677](https://leetcode.com/problems/products-worth-over-invoices)", "[Product's Worth Over Invoices](/solution/1600-1699/1677.Product%27s%20Worth%20Over%20Invoices/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1820", "frontend_question_id": "1719", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-ways-to-reconstruct-a-tree", "url_en": "https://leetcode.com/problems/number-of-ways-to-reconstruct-a-tree", "relative_path_cn": "/solution/1700-1799/1719.Number%20Of%20Ways%20To%20Reconstruct%20A%20Tree/README.md", "relative_path_en": "/solution/1700-1799/1719.Number%20Of%20Ways%20To%20Reconstruct%20A%20Tree/README_EN.md", "title_cn": "\u91cd\u6784\u4e00\u68f5\u6811\u7684\u65b9\u6848\u6570", "title_en": "Number Of Ways To Reconstruct A Tree", "question_title_slug": "number-of-ways-to-reconstruct-a-tree", "content_en": "

You are given an array pairs, where pairs[i] = [xi, yi], and:

\n\n
    \n\t
  • There are no duplicates.
  • \n\t
  • xi < yi
  • \n
\n\n

Let ways be the number of rooted trees that satisfy the following conditions:

\n\n
    \n\t
  • The tree consists of nodes whose values appeared in pairs.
  • \n\t
  • A pair [xi, yi] exists in pairs if and only if xi is an ancestor of yi or yi is an ancestor of xi.
  • \n\t
  • Note: the tree does not have to be a binary tree.
  • \n
\n\n

Two ways are considered to be different if there is at least one node that has different parents in both ways.

\n\n

Return:

\n\n
    \n\t
  • 0 if ways == 0
  • \n\t
  • 1 if ways == 1
  • \n\t
  • 2 if ways > 1
  • \n
\n\n

A rooted tree is a tree that has a single root node, and all edges are oriented to be outgoing from the root.

\n\n

An ancestor of a node is any node on the path from the root to that node (excluding the node itself). The root has no ancestors.

\n\n

 

\n

Example 1:

\n\n
\nInput: pairs = [[1,2],[2,3]]\nOutput: 1\nExplanation: There is exactly one valid rooted tree, which is shown in the above figure.\n
\n\n

Example 2:

\n\"\"\n
\nInput: pairs = [[1,2],[2,3],[1,3]]\nOutput: 2\nExplanation: There are multiple valid rooted trees. Three of them are shown in the above figures.\n
\n\n

Example 3:

\n\n
\nInput: pairs = [[1,2],[2,3],[2,4],[1,5]]\nOutput: 0\nExplanation: There are no valid rooted trees.
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= pairs.length <= 105
  • \n\t
  • 1 <= xi < yi <= 500
  • \n\t
  • The elements in pairs are unique.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4\u00a0pairs \uff0c\u5176\u4e2d\u00a0pairs[i] = [xi, yi]\u00a0\uff0c\u5e76\u4e14\u6ee1\u8db3\uff1a

\n\n
    \n\t
  • pairs\u00a0\u4e2d\u6ca1\u6709\u91cd\u590d\u5143\u7d20
  • \n\t
  • xi < yi
  • \n
\n\n

\u4ee4\u00a0ways\u00a0\u4e3a\u6ee1\u8db3\u4e0b\u9762\u6761\u4ef6\u7684\u6709\u6839\u6811\u7684\u65b9\u6848\u6570\uff1a

\n\n
    \n\t
  • \u6811\u6240\u5305\u542b\u7684\u6240\u6709\u8282\u70b9\u503c\u90fd\u5728 pairs\u00a0\u4e2d\u3002
  • \n\t
  • \u4e00\u4e2a\u6570\u5bf9\u00a0[xi, yi] \u51fa\u73b0\u5728\u00a0pairs\u00a0\u4e2d\u00a0\u5f53\u4e14\u4ec5\u5f53\u00a0xi\u00a0\u662f\u00a0yi\u00a0\u7684\u7956\u5148\u6216\u8005\u00a0yi\u00a0\u662f\u00a0xi\u00a0\u7684\u7956\u5148\u3002
  • \n\t
  • \u6ce8\u610f\uff1a\u6784\u9020\u51fa\u6765\u7684\u6811\u4e0d\u4e00\u5b9a\u662f\u4e8c\u53c9\u6811\u3002
  • \n
\n\n

\u4e24\u68f5\u6811\u88ab\u89c6\u4e3a\u4e0d\u540c\u7684\u65b9\u6848\u5f53\u5b58\u5728\u81f3\u5c11\u4e00\u4e2a\u8282\u70b9\u5728\u4e24\u68f5\u6811\u4e2d\u6709\u4e0d\u540c\u7684\u7236\u8282\u70b9\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\uff1a

\n\n
    \n\t
  • \u5982\u679c\u00a0ways == 0\u00a0\uff0c\u8fd4\u56de\u00a00\u00a0\u3002
  • \n\t
  • \u5982\u679c\u00a0ways == 1\u00a0\uff0c\u8fd4\u56de 1\u00a0\u3002
  • \n\t
  • \u5982\u679c\u00a0ways > 1\u00a0\uff0c\u8fd4\u56de\u00a02\u00a0\u3002
  • \n
\n\n

\u4e00\u68f5 \u6709\u6839\u6811\u00a0\u6307\u7684\u662f\u53ea\u6709\u4e00\u4e2a\u6839\u8282\u70b9\u7684\u6811\uff0c\u6240\u6709\u8fb9\u90fd\u662f\u4ece\u6839\u5f80\u5916\u7684\u65b9\u5411\u3002

\n\n

\u6211\u4eec\u79f0\u4ece\u6839\u5230\u4e00\u4e2a\u8282\u70b9\u8def\u5f84\u4e0a\u7684\u4efb\u610f\u4e00\u4e2a\u8282\u70b9\uff08\u9664\u53bb\u8282\u70b9\u672c\u8eab\uff09\u90fd\u662f\u8be5\u8282\u70b9\u7684 \u7956\u5148\u00a0\u3002\u6839\u8282\u70b9\u6ca1\u6709\u7956\u5148\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1apairs = [[1,2],[2,3]]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u5982\u4e0a\u56fe\u6240\u793a\uff0c\u6709\u4e14\u53ea\u6709\u4e00\u4e2a\u7b26\u5408\u89c4\u5b9a\u7684\u6709\u6839\u6811\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1apairs = [[1,2],[2,3],[1,3]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6709\u591a\u4e2a\u7b26\u5408\u89c4\u5b9a\u7684\u6709\u6839\u6811\uff0c\u5176\u4e2d\u4e09\u4e2a\u5982\u4e0a\u56fe\u6240\u793a\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1apairs = [[1,2],[2,3],[2,4],[1,5]]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6ca1\u6709\u7b26\u5408\u89c4\u5b9a\u7684\u6709\u6839\u6811\u3002
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= pairs.length <= 105
  • \n\t
  • 1 <= xi < yi <= 500
  • \n\t
  • pairs\u00a0\u4e2d\u7684\u5143\u7d20\u4e92\u4e0d\u76f8\u540c\u3002
  • \n
\n", "tags_en": ["Tree", "Graph"], "tags_cn": ["\u6811", "\u56fe"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int checkWays(vector>& pairs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int checkWays(int[][] pairs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def checkWays(self, pairs):\n \"\"\"\n :type pairs: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def checkWays(self, pairs: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint checkWays(int** pairs, int pairsSize, int* pairsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CheckWays(int[][] pairs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} pairs\n * @return {number}\n */\nvar checkWays = function(pairs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} pairs\n# @return {Integer}\ndef check_ways(pairs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func checkWays(_ pairs: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func checkWays(pairs [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def checkWays(pairs: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun checkWays(pairs: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn check_ways(pairs: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $pairs\n * @return Integer\n */\n function checkWays($pairs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function checkWays(pairs: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (check-ways pairs)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1719](https://leetcode-cn.com/problems/number-of-ways-to-reconstruct-a-tree)", "[\u91cd\u6784\u4e00\u68f5\u6811\u7684\u65b9\u6848\u6570](/solution/1700-1799/1719.Number%20Of%20Ways%20To%20Reconstruct%20A%20Tree/README.md)", "`\u6811`,`\u56fe`", "\u56f0\u96be", ""], "md_table_row_en": ["[1719](https://leetcode.com/problems/number-of-ways-to-reconstruct-a-tree)", "[Number Of Ways To Reconstruct A Tree](/solution/1700-1799/1719.Number%20Of%20Ways%20To%20Reconstruct%20A%20Tree/README_EN.md)", "`Tree`,`Graph`", "Hard", ""]}, {"question_id": "1819", "frontend_question_id": "1718", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/construct-the-lexicographically-largest-valid-sequence", "url_en": "https://leetcode.com/problems/construct-the-lexicographically-largest-valid-sequence", "relative_path_cn": "/solution/1700-1799/1718.Construct%20the%20Lexicographically%20Largest%20Valid%20Sequence/README.md", "relative_path_en": "/solution/1700-1799/1718.Construct%20the%20Lexicographically%20Largest%20Valid%20Sequence/README_EN.md", "title_cn": "\u6784\u5efa\u5b57\u5178\u5e8f\u6700\u5927\u7684\u53ef\u884c\u5e8f\u5217", "title_en": "Construct the Lexicographically Largest Valid Sequence", "question_title_slug": "construct-the-lexicographically-largest-valid-sequence", "content_en": "

Given an integer n, find a sequence that satisfies all of the following:

\n\n
    \n\t
  • The integer 1 occurs once in the sequence.
  • \n\t
  • Each integer between 2 and n occurs twice in the sequence.
  • \n\t
  • For every integer i between 2 and n, the distance between the two occurrences of i is exactly i.
  • \n
\n\n

The distance between two numbers on the sequence, a[i] and a[j], is the absolute difference of their indices, |j - i|.

\n\n

Return the lexicographically largest sequence. It is guaranteed that under the given constraints, there is always a solution.

\n\n

A sequence a is lexicographically larger than a sequence b (of the same length) if in the first position where a and b differ, sequence a has a number greater than the corresponding number in b. For example, [0,1,9,0] is lexicographically larger than [0,1,5,6] because the first position they differ is at the third number, and 9 is greater than 5.

\n\n

 

\n

Example 1:

\n\n
\nInput: n = 3\nOutput: [3,1,2,3,2]\nExplanation: [2,3,2,1,3] is also a valid sequence, but [3,1,2,3,2] is the lexicographically largest valid sequence.\n
\n\n

Example 2:

\n\n
\nInput: n = 5\nOutput: [5,3,1,4,3,5,2,4,2]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 20
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u00a0n\u00a0\uff0c\u8bf7\u4f60\u627e\u5230\u6ee1\u8db3\u4e0b\u9762\u6761\u4ef6\u7684\u4e00\u4e2a\u5e8f\u5217\uff1a

\n\n
    \n\t
  • \u6574\u6570\u00a01\u00a0\u5728\u5e8f\u5217\u4e2d\u53ea\u51fa\u73b0\u4e00\u6b21\u3002
  • \n\t
  • 2\u00a0\u5230\u00a0n\u00a0\u4e4b\u95f4\u6bcf\u4e2a\u6574\u6570\u90fd\u6070\u597d\u51fa\u73b0\u4e24\u6b21\u3002
  • \n\t
  • \u5bf9\u4e8e\u6bcf\u4e2a\u00a02\u00a0\u5230\u00a0n\u00a0\u4e4b\u95f4\u7684\u6574\u6570\u00a0i\u00a0\uff0c\u4e24\u4e2a\u00a0i\u00a0\u4e4b\u95f4\u51fa\u73b0\u7684\u8ddd\u79bb\u6070\u597d\u4e3a\u00a0i\u00a0\u3002
  • \n
\n\n

\u5e8f\u5217\u91cc\u9762\u4e24\u4e2a\u6570 a[i]\u00a0\u548c a[j]\u00a0\u4e4b\u95f4\u7684 \u8ddd\u79bb\u00a0\uff0c\u6211\u4eec\u5b9a\u4e49\u4e3a\u5b83\u4eec\u4e0b\u6807\u7edd\u5bf9\u503c\u4e4b\u5dee\u00a0|j - i|\u00a0\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u6ee1\u8db3\u4e0a\u8ff0\u6761\u4ef6\u4e2d\u00a0\u5b57\u5178\u5e8f\u6700\u5927\u00a0\u7684\u5e8f\u5217\u3002\u9898\u76ee\u4fdd\u8bc1\u5728\u7ed9\u5b9a\u9650\u5236\u6761\u4ef6\u4e0b\uff0c\u4e00\u5b9a\u5b58\u5728\u89e3\u3002

\n\n

\u4e00\u4e2a\u5e8f\u5217\u00a0a\u00a0\u88ab\u8ba4\u4e3a\u6bd4\u5e8f\u5217\u00a0b\u00a0\uff08\u4e24\u8005\u957f\u5ea6\u76f8\u540c\uff09\u5b57\u5178\u5e8f\u66f4\u5927\u7684\u6761\u4ef6\u662f\uff1a\u00a0a \u548c\u00a0b\u00a0\u4e2d\u7b2c\u4e00\u4e2a\u4e0d\u4e00\u6837\u7684\u6570\u5b57\u5904\uff0ca\u00a0\u5e8f\u5217\u7684\u6570\u5b57\u6bd4\u00a0b\u00a0\u5e8f\u5217\u7684\u6570\u5b57\u5927\u3002\u6bd4\u65b9\u8bf4\uff0c[0,1,9,0]\u00a0\u6bd4\u00a0[0,1,5,6]\u00a0\u5b57\u5178\u5e8f\u66f4\u5927\uff0c\u56e0\u4e3a\u7b2c\u4e00\u4e2a\u4e0d\u540c\u7684\u4f4d\u7f6e\u662f\u7b2c\u4e09\u4e2a\u6570\u5b57\uff0c\u4e14\u00a09\u00a0\u6bd4\u00a05\u00a0\u5927\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1an = 3\n\u8f93\u51fa\uff1a[3,1,2,3,2]\n\u89e3\u91ca\uff1a[2,3,2,1,3] \u4e5f\u662f\u4e00\u4e2a\u53ef\u884c\u7684\u5e8f\u5217\uff0c\u4f46\u662f [3,1,2,3,2] \u662f\u5b57\u5178\u5e8f\u6700\u5927\u7684\u5e8f\u5217\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1an = 5\n\u8f93\u51fa\uff1a[5,3,1,4,3,5,2,4,2]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 20
  • \n
\n", "tags_en": ["Recursion", "Backtracking"], "tags_cn": ["\u9012\u5f52", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector constructDistancedSequence(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] constructDistancedSequence(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def constructDistancedSequence(self, n):\n \"\"\"\n :type n: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def constructDistancedSequence(self, n: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* constructDistancedSequence(int n, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] ConstructDistancedSequence(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number[]}\n */\nvar constructDistancedSequence = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer[]}\ndef construct_distanced_sequence(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func constructDistancedSequence(_ n: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func constructDistancedSequence(n int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def constructDistancedSequence(n: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun constructDistancedSequence(n: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn construct_distanced_sequence(n: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer[]\n */\n function constructDistancedSequence($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function constructDistancedSequence(n: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (construct-distanced-sequence n)\n (-> exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1718](https://leetcode-cn.com/problems/construct-the-lexicographically-largest-valid-sequence)", "[\u6784\u5efa\u5b57\u5178\u5e8f\u6700\u5927\u7684\u53ef\u884c\u5e8f\u5217](/solution/1700-1799/1718.Construct%20the%20Lexicographically%20Largest%20Valid%20Sequence/README.md)", "`\u9012\u5f52`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1718](https://leetcode.com/problems/construct-the-lexicographically-largest-valid-sequence)", "[Construct the Lexicographically Largest Valid Sequence](/solution/1700-1799/1718.Construct%20the%20Lexicographically%20Largest%20Valid%20Sequence/README_EN.md)", "`Recursion`,`Backtracking`", "Medium", ""]}, {"question_id": "1818", "frontend_question_id": "1717", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-score-from-removing-substrings", "url_en": "https://leetcode.com/problems/maximum-score-from-removing-substrings", "relative_path_cn": "/solution/1700-1799/1717.Maximum%20Score%20From%20Removing%20Substrings/README.md", "relative_path_en": "/solution/1700-1799/1717.Maximum%20Score%20From%20Removing%20Substrings/README_EN.md", "title_cn": "\u5220\u9664\u5b50\u5b57\u7b26\u4e32\u7684\u6700\u5927\u5f97\u5206", "title_en": "Maximum Score From Removing Substrings", "question_title_slug": "maximum-score-from-removing-substrings", "content_en": "

You are given a string s and two integers x and y. You can perform two types of operations any number of times.

\n\n
    \n\t
  • Remove substring "ab" and gain x points.\n\n\t
      \n\t\t
    • For example, when removing "ab" from "cabxbae" it becomes "cxbae".
    • \n\t
    \n\t
  • \n\t
  • Remove substring "ba" and gain y points.\n\t
      \n\t\t
    • For example, when removing "ba" from "cabxbae" it becomes "cabxe".
    • \n\t
    \n\t
  • \n
\n\n

Return the maximum points you can gain after applying the above operations on s.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "cdbcbbaaabab", x = 4, y = 5\nOutput: 19\nExplanation:\n- Remove the "ba" underlined in "cdbcbbaaabab". Now, s = "cdbcbbaaab" and 5 points are added to the score.\n- Remove the "ab" underlined in "cdbcbbaaab". Now, s = "cdbcbbaa" and 4 points are added to the score.\n- Remove the "ba" underlined in "cdbcbbaa". Now, s = "cdbcba" and 5 points are added to the score.\n- Remove the "ba" underlined in "cdbcba". Now, s = "cdbc" and 5 points are added to the score.\nTotal score = 5 + 4 + 5 + 5 = 19.
\n\n

Example 2:

\n\n
\nInput: s = "aabbaaxybbaabb", x = 5, y = 4\nOutput: 20\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 105
  • \n\t
  • 1 <= x, y <= 104
  • \n\t
  • s consists of lowercase English letters.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32\u00a0s\u00a0\u548c\u4e24\u4e2a\u6574\u6570\u00a0x \u548c\u00a0y\u00a0\u3002\u4f60\u53ef\u4ee5\u6267\u884c\u4e0b\u9762\u4e24\u79cd\u64cd\u4f5c\u4efb\u610f\u6b21\u3002

\n\n
    \n\t
  • \u5220\u9664\u5b50\u5b57\u7b26\u4e32\u00a0\"ab\"\u00a0\u5e76\u5f97\u5230\u00a0x\u00a0\u5206\u3002\n\n\t
      \n\t\t
    • \u6bd4\u65b9\u8bf4\uff0c\u4ece\u00a0\"cabxbae\"\u00a0\u5220\u9664 ab\u00a0\uff0c\u5f97\u5230\u00a0\"cxbae\"\u00a0\u3002
    • \n\t
    \n\t
  • \n\t
  • \u5220\u9664\u5b50\u5b57\u7b26\u4e32\"ba\"\u00a0\u5e76\u5f97\u5230\u00a0y\u00a0\u5206\u3002\n\t
      \n\t\t
    • \u6bd4\u65b9\u8bf4\uff0c\u4ece\u00a0\"cabxbae\"\u00a0\u5220\u9664 ba\u00a0\uff0c\u5f97\u5230\u00a0\"cabxe\"\u00a0\u3002
    • \n\t
    \n\t
  • \n
\n\n

\u8bf7\u8fd4\u56de\u5bf9 s\u00a0\u5b57\u7b26\u4e32\u6267\u884c\u4e0a\u9762\u64cd\u4f5c\u82e5\u5e72\u6b21\u80fd\u5f97\u5230\u7684\u6700\u5927\u5f97\u5206\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1as = \"cdbcbbaaabab\", x = 4, y = 5\n\u8f93\u51fa\uff1a19\n\u89e3\u91ca\uff1a\n- \u5220\u9664 \"cdbcbbaaabab\" \u4e2d\u52a0\u7c97\u7684 \"ba\" \uff0c\u5f97\u5230 s = \"cdbcbbaaab\" \uff0c\u52a0 5 \u5206\u3002\n- \u5220\u9664 \"cdbcbbaaab\" \u4e2d\u52a0\u7c97\u7684 \"ab\" \uff0c\u5f97\u5230 s = \"cdbcbbaa\" \uff0c\u52a0 4 \u5206\u3002\n- \u5220\u9664 \"cdbcbbaa\" \u4e2d\u52a0\u7c97\u7684 \"ba\" \uff0c\u5f97\u5230 s = \"cdbcba\" \uff0c\u52a0 5 \u5206\u3002\n- \u5220\u9664 \"cdbcba\" \u4e2d\u52a0\u7c97\u7684 \"ba\" \uff0c\u5f97\u5230 s = \"cdbc\" \uff0c\u52a0 5 \u5206\u3002\n\u603b\u5f97\u5206\u4e3a 5 + 4 + 5 + 5 = 19 \u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1as = \"aabbaaxybbaabb\", x = 5, y = 4\n\u8f93\u51fa\uff1a20\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length <= 105
  • \n\t
  • 1 <= x, y <= 104
  • \n\t
  • s\u00a0\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
  • \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maximumGain(string s, int x, int y) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maximumGain(String s, int x, int y) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximumGain(self, s, x, y):\n \"\"\"\n :type s: str\n :type x: int\n :type y: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximumGain(self, s: str, x: int, y: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maximumGain(char * s, int x, int y){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaximumGain(string s, int x, int y) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number} x\n * @param {number} y\n * @return {number}\n */\nvar maximumGain = function(s, x, y) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer} x\n# @param {Integer} y\n# @return {Integer}\ndef maximum_gain(s, x, y)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximumGain(_ s: String, _ x: Int, _ y: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximumGain(s string, x int, y int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximumGain(s: String, x: Int, y: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximumGain(s: String, x: Int, y: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximum_gain(s: String, x: i32, y: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer $x\n * @param Integer $y\n * @return Integer\n */\n function maximumGain($s, $x, $y) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximumGain(s: string, x: number, y: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximum-gain s x y)\n (-> string? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1717](https://leetcode-cn.com/problems/maximum-score-from-removing-substrings)", "[\u5220\u9664\u5b50\u5b57\u7b26\u4e32\u7684\u6700\u5927\u5f97\u5206](/solution/1700-1799/1717.Maximum%20Score%20From%20Removing%20Substrings/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1717](https://leetcode.com/problems/maximum-score-from-removing-substrings)", "[Maximum Score From Removing Substrings](/solution/1700-1799/1717.Maximum%20Score%20From%20Removing%20Substrings/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1817", "frontend_question_id": "1716", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/calculate-money-in-leetcode-bank", "url_en": "https://leetcode.com/problems/calculate-money-in-leetcode-bank", "relative_path_cn": "/solution/1700-1799/1716.Calculate%20Money%20in%20Leetcode%20Bank/README.md", "relative_path_en": "/solution/1700-1799/1716.Calculate%20Money%20in%20Leetcode%20Bank/README_EN.md", "title_cn": "\u8ba1\u7b97\u529b\u6263\u94f6\u884c\u7684\u94b1", "title_en": "Calculate Money in Leetcode Bank", "question_title_slug": "calculate-money-in-leetcode-bank", "content_en": "

Hercy wants to save money for his first car. He puts money in the Leetcode bank every day.

\n\n

He starts by putting in $1 on Monday, the first day. Every day from Tuesday to Sunday, he will put in $1 more than the day before. On every subsequent Monday, he will put in $1 more than the previous Monday.

\n\n

Given n, return the total amount of money he will have in the Leetcode bank at the end of the nth day.

\n\n

 

\n

Example 1:

\n\n
\nInput: n = 4\nOutput: 10\nExplanation: After the 4th day, the total is 1 + 2 + 3 + 4 = 10.\n
\n\n

Example 2:

\n\n
\nInput: n = 10\nOutput: 37\nExplanation: After the 10th day, the total is (1 + 2 + 3 + 4 + 5 + 6 + 7) + (2 + 3 + 4) = 37. Notice that on the 2nd Monday, Hercy only puts in $2.\n
\n\n

Example 3:

\n\n
\nInput: n = 20\nOutput: 96\nExplanation: After the 20th day, the total is (1 + 2 + 3 + 4 + 5 + 6 + 7) + (2 + 3 + 4 + 5 + 6 + 7 + 8) + (3 + 4 + 5 + 6 + 7 + 8) = 96.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 1000
  • \n
\n", "content_cn": "

Hercy \u60f3\u8981\u4e3a\u8d2d\u4e70\u7b2c\u4e00\u8f86\u8f66\u5b58\u94b1\u3002\u4ed6 \u6bcf\u5929 \u90fd\u5f80\u529b\u6263\u94f6\u884c\u91cc\u5b58\u94b1\u3002

\n\n

\u6700\u5f00\u59cb\uff0c\u4ed6\u5728\u5468\u4e00\u7684\u65f6\u5019\u5b58\u5165 1\u00a0\u5757\u94b1\u3002\u4ece\u5468\u4e8c\u5230\u5468\u65e5\uff0c\u4ed6\u6bcf\u5929\u90fd\u6bd4\u524d\u4e00\u5929\u591a\u5b58\u5165 1\u00a0\u5757\u94b1\u3002\u5728\u63a5\u4e0b\u6765\u6bcf\u4e00\u4e2a\u5468\u4e00\uff0c\u4ed6\u90fd\u4f1a\u6bd4 \u524d\u4e00\u4e2a\u5468\u4e00 \u591a\u5b58\u5165 1\u00a0\u5757\u94b1\u3002

\n\n

\u7ed9\u4f60\u00a0n\u00a0\uff0c\u8bf7\u4f60\u8fd4\u56de\u5728\u7b2c n\u00a0\u5929\u7ed3\u675f\u7684\u65f6\u5019\u4ed6\u5728\u529b\u6263\u94f6\u884c\u603b\u5171\u5b58\u4e86\u591a\u5c11\u5757\u94b1\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1an = 4\n\u8f93\u51fa\uff1a10\n\u89e3\u91ca\uff1a\u7b2c 4 \u5929\u540e\uff0c\u603b\u989d\u4e3a 1 + 2 + 3 + 4 = 10 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1an = 10\n\u8f93\u51fa\uff1a37\n\u89e3\u91ca\uff1a\u7b2c 10 \u5929\u540e\uff0c\u603b\u989d\u4e3a (1 + 2 + 3 + 4 + 5 + 6 + 7) + (2 + 3 + 4) = 37 \u3002\u6ce8\u610f\u5230\u7b2c\u4e8c\u4e2a\u661f\u671f\u4e00\uff0cHercy \u5b58\u5165 2 \u5757\u94b1\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1an = 20\n\u8f93\u51fa\uff1a96\n\u89e3\u91ca\uff1a\u7b2c 20 \u5929\u540e\uff0c\u603b\u989d\u4e3a (1 + 2 + 3 + 4 + 5 + 6 + 7) + (2 + 3 + 4 + 5 + 6 + 7 + 8) + (3 + 4 + 5 + 6 + 7 + 8) = 96 \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 1000
  • \n
\n", "tags_en": ["Greedy", "Math"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int totalMoney(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int totalMoney(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def totalMoney(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def totalMoney(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint totalMoney(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int TotalMoney(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar totalMoney = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef total_money(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func totalMoney(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func totalMoney(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def totalMoney(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun totalMoney(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn total_money(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function totalMoney($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function totalMoney(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (total-money n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1716](https://leetcode-cn.com/problems/calculate-money-in-leetcode-bank)", "[\u8ba1\u7b97\u529b\u6263\u94f6\u884c\u7684\u94b1](/solution/1700-1799/1716.Calculate%20Money%20in%20Leetcode%20Bank/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[1716](https://leetcode.com/problems/calculate-money-in-leetcode-bank)", "[Calculate Money in Leetcode Bank](/solution/1700-1799/1716.Calculate%20Money%20in%20Leetcode%20Bank/README_EN.md)", "`Greedy`,`Math`", "Easy", ""]}, {"question_id": "1816", "frontend_question_id": "1676", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-tree-iv", "url_en": "https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree-iv", "relative_path_cn": "/solution/1600-1699/1676.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree%20IV/README.md", "relative_path_en": "/solution/1600-1699/1676.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree%20IV/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148 IV", "title_en": "Lowest Common Ancestor of a Binary Tree IV", "question_title_slug": "lowest-common-ancestor-of-a-binary-tree-iv", "content_en": "

Given the root of a binary tree and an array of TreeNode objects nodes, return the lowest common ancestor (LCA) of all the nodes in nodes. All the nodes will exist in the tree, and all values of the tree's nodes are unique.

\n\n

Extending the definition of LCA on Wikipedia: "The lowest common ancestor of n nodes p1, p2, ..., pn in a binary tree T is the lowest node that has every pi as a descendant (where we allow a node to be a descendant of itself) for every valid i". A descendant of a node x is a node y that is on the path from node x to some leaf node.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: root = [3,5,1,6,2,0,8,null,null,7,4], nodes = [4,7]\nOutput: 2\nExplanation: The lowest common ancestor of nodes 4 and 7 is node 2.\n
\n\n

Example 2:

\n\"\"\n
\nInput: root = [3,5,1,6,2,0,8,null,null,7,4], nodes = [1]\nOutput: 1\nExplanation: The lowest common ancestor of a single node is the node itself.\n\n
\n\n

Example 3:

\n\"\"\n
\nInput: root = [3,5,1,6,2,0,8,null,null,7,4], nodes = [7,6,2,4]\nOutput: 5\nExplanation: The lowest common ancestor of the nodes 7, 6, 2, and 4 is node 5.\n
\n\n

Example 4:

\n\"\"\n
\nInput: root = [3,5,1,6,2,0,8,null,null,7,4], nodes = [0,1,2,3,4,5,6,7,8]\nOutput: 3\nExplanation: The lowest common ancestor of all the nodes is the root node.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The number of nodes in the tree is in the range [1, 104].
  • \n\t
  • -109 <= Node.val <= 109
  • \n\t
  • All Node.val are unique.
  • \n\t
  • All nodes[i] will exist in the tree.
  • \n\t
  • All nodes[i] are distinct.
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u68f5\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9\u00a0root\u00a0\u548c\u00a0TreeNode\u00a0\u7c7b\u5bf9\u8c61\u7684\u6570\u7ec4\uff08\u5217\u8868\uff09\u00a0nodes\uff0c\u8fd4\u56de\u00a0nodes\u00a0\u4e2d\u6240\u6709\u8282\u70b9\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148\uff08LCA\uff09\u3002\u6570\u7ec4\uff08\u5217\u8868\uff09\u4e2d\u6240\u6709\u8282\u70b9\u90fd\u5b58\u5728\u4e8e\u8be5\u4e8c\u53c9\u6811\u4e2d\uff0c\u4e14\u4e8c\u53c9\u6811\u4e2d\u6240\u6709\u8282\u70b9\u7684\u503c\u90fd\u662f\u4e92\u4e0d\u76f8\u540c\u7684\u3002

\n\n

\u6211\u4eec\u6269\u5c55\u4e8c\u53c9\u6811\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148\u8282\u70b9\u5728\u7ef4\u57fa\u767e\u79d1\u4e0a\u7684\u5b9a\u4e49\uff1a\u201c\u5bf9\u4e8e\u4efb\u610f\u5408\u7406\u7684 i \u503c\uff0c\u00a0n\u00a0\u4e2a\u8282\u70b9\u00a0p1\u00a0\u3001\u00a0p2\u3001...\u3001\u00a0pn\u00a0\u5728\u4e8c\u53c9\u6811\u00a0T\u00a0\u4e2d\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148\u8282\u70b9\u662f\u540e\u4ee3\u4e2d\u5305\u542b\u6240\u6709\u8282\u70b9\u00a0pi\u00a0\u7684\u6700\u6df1\u8282\u70b9\uff08\u6211\u4eec\u5141\u8bb8\u4e00\u4e2a\u8282\u70b9\u662f\u5176\u81ea\u8eab\u7684\u540e\u4ee3\uff09\u201d\u3002\u4e00\u4e2a\u8282\u70b9 x\u00a0\u7684\u540e\u4ee3\u8282\u70b9\u662f\u8282\u70b9\u00a0x \u5230\u67d0\u4e00\u53f6\u8282\u70b9\u95f4\u7684\u8def\u5f84\u4e2d\u7684\u8282\u70b9 y\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1:

\n\"\"\n
\u8f93\u5165: root = [3,5,1,6,2,0,8,null,null,7,4], nodes = [4,7]\n\u8f93\u51fa: 2\n\u89e3\u91ca:\u00a0\u8282\u70b9 4 \u548c 7 \u7684\u6700\u8fd1\u516c\u5171\u7956\u5148\u662f 2\u3002\n
\n\n

\u793a\u4f8b 2:

\n\"\"\n
\u8f93\u5165: root = [3,5,1,6,2,0,8,null,null,7,4], nodes = [1]\n\u8f93\u51fa: 1\n\u89e3\u91ca:\u00a0\u5355\u4e2a\u8282\u70b9\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148\u662f\u8be5\u8282\u70b9\u672c\u8eab\u3002\n\n
\n\n

\u793a\u4f8b 3:

\n\"\"\n
\u8f93\u5165: root = [3,5,1,6,2,0,8,null,null,7,4], nodes = [7,6,2,4]\n\u8f93\u51fa: 5\n\u89e3\u91ca:\u00a0\u8282\u70b9 7\u30016\u30012 \u548c 4 \u7684\u6700\u8fd1\u516c\u5171\u7956\u5148\u8282\u70b9\u662f 5\u3002\n
\n\n

\u793a\u4f8b 4:

\n\"\"\n
\u8f93\u5165: root = [3,5,1,6,2,0,8,null,null,7,4], nodes = [0,1,2,3,4,5,6,7,8]\n\u8f93\u51fa: 3\n\u89e3\u91ca:\u00a0\u6811\u4e2d\u6240\u6709\u8282\u70b9\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148\u662f\u6839\u8282\u70b9\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a:

\n\n
    \n\t
  • \u6811\u4e2d\u8282\u70b9\u4e2a\u6570\u7684\u8303\u56f4\u662f\u00a0[1, 104]\u00a0\u3002
  • \n\t
  • -109 <= Node.val <= 109
  • \n\t
  • \u6240\u6709\u7684\u00a0Node.val\u00a0\u90fd\u662f\u4e92\u4e0d\u76f8\u540c\u7684\u3002
  • \n\t
  • \u6240\u6709\u7684\u00a0nodes[i]\u00a0\u90fd\u5b58\u5728\u4e8e\u8be5\u6811\u4e2d\u3002
  • \n\t
  • \u6240\u6709\u7684\u00a0nodes[i]\u00a0\u90fd\u662f\u4e92\u4e0d\u76f8\u540c\u7684\u3002
  • \n
\n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* lowestCommonAncestor(TreeNode* root, vector &nodes) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode(int x) { val = x; }\n * }\n */\nclass Solution {\n public TreeNode lowestCommonAncestor(TreeNode root, TreeNode[] nodes) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution(object):\n def lowestCommonAncestor(self, root, nodes):\n \"\"\"\n :type root: TreeNode\n :type nodes: List[TreeNode]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution:\n def lowestCommonAncestor(self, root: 'TreeNode', nodes: 'List[TreeNode]') -> 'TreeNode':\n ", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int x) { val = x; }\n * }\n */\npublic class Solution {\n public TreeNode LowestCommonAncestor(TreeNode root, TreeNode[] nodes) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val) {\n * this.val = val;\n * this.left = this.right = null;\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {TreeNode[]} nodes\n * @return {TreeNode}\n */\nvar lowestCommonAncestor = function(root, nodes) {\n \n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1676](https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-tree-iv)", "[\u4e8c\u53c9\u6811\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148 IV](/solution/1600-1699/1676.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree%20IV/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1676](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree-iv)", "[Lowest Common Ancestor of a Binary Tree IV](/solution/1600-1699/1676.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree%20IV/README_EN.md)", "`Tree`,`Depth-first Search`", "Medium", "\ud83d\udd12"]}, {"question_id": "1815", "frontend_question_id": "1697", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/checking-existence-of-edge-length-limited-paths", "url_en": "https://leetcode.com/problems/checking-existence-of-edge-length-limited-paths", "relative_path_cn": "/solution/1600-1699/1697.Checking%20Existence%20of%20Edge%20Length%20Limited%20Paths/README.md", "relative_path_en": "/solution/1600-1699/1697.Checking%20Existence%20of%20Edge%20Length%20Limited%20Paths/README_EN.md", "title_cn": "\u68c0\u67e5\u8fb9\u957f\u5ea6\u9650\u5236\u7684\u8def\u5f84\u662f\u5426\u5b58\u5728", "title_en": "Checking Existence of Edge Length Limited Paths", "question_title_slug": "checking-existence-of-edge-length-limited-paths", "content_en": "

An undirected graph of n nodes is defined by edgeList, where edgeList[i] = [ui, vi, disi] denotes an edge between nodes ui and vi with distance disi. Note that there may be multiple edges between two nodes.

\n\n

Given an array queries, where queries[j] = [pj, qj, limitj], your task is to determine for each queries[j] whether there is a path between pj and qj such that each edge on the path has a distance strictly less than limitj .

\n\n

Return a boolean array answer, where answer.length == queries.length and the jth value of answer is true if there is a path for queries[j] is true, and false otherwise.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: n = 3, edgeList = [[0,1,2],[1,2,4],[2,0,8],[1,0,16]], queries = [[0,1,2],[0,2,5]]\nOutput: [false,true]\nExplanation: The above figure shows the given graph. Note that there are two overlapping edges between 0 and 1 with distances 2 and 16.\nFor the first query, between 0 and 1 there is no path where each distance is less than 2, thus we return false for this query.\nFor the second query, there is a path (0 -> 1 -> 2) of two edges with distances less than 5, thus we return true for this query.\n
\n\n

Example 2:

\n\"\"\n
\nInput: n = 5, edgeList = [[0,1,10],[1,2,5],[2,3,9],[3,4,13]], queries = [[0,4,14],[1,4,13]]\nOutput: [true,false]\nExaplanation: The above figure shows the given graph.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= n <= 105
  • \n\t
  • 1 <= edgeList.length, queries.length <= 105
  • \n\t
  • edgeList[i].length == 3
  • \n\t
  • queries[j].length == 3
  • \n\t
  • 0 <= ui, vi, pj, qj <= n - 1
  • \n\t
  • ui != vi
  • \n\t
  • pj != qj
  • \n\t
  • 1 <= disi, limitj <= 109
  • \n\t
  • There may be multiple edges between two nodes.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a n\u00a0\u4e2a\u70b9\u7ec4\u6210\u7684\u65e0\u5411\u56fe\u8fb9\u96c6\u00a0edgeList\u00a0\uff0c\u5176\u4e2d\u00a0edgeList[i] = [ui, vi, disi]\u00a0\u8868\u793a\u70b9\u00a0ui \u548c\u70b9\u00a0vi\u00a0\u4e4b\u95f4\u6709\u4e00\u6761\u957f\u5ea6\u4e3a\u00a0disi\u00a0\u7684\u8fb9\u3002\u8bf7\u6ce8\u610f\uff0c\u4e24\u4e2a\u70b9\u4e4b\u95f4\u53ef\u80fd\u6709 \u8d85\u8fc7\u4e00\u6761\u8fb9\u00a0\u3002

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u67e5\u8be2\u6570\u7ec4queries\u00a0\uff0c\u5176\u4e2d\u00a0queries[j] = [pj, qj, limitj]\u00a0\uff0c\u4f60\u7684\u4efb\u52a1\u662f\u5bf9\u4e8e\u6bcf\u4e2a\u67e5\u8be2\u00a0queries[j]\u00a0\uff0c\u5224\u65ad\u662f\u5426\u5b58\u5728\u4ece\u00a0pj\u00a0\u5230\u00a0qj\u00a0\u7684\u8def\u5f84\uff0c\u4e14\u8fd9\u6761\u8def\u5f84\u4e0a\u7684\u6bcf\u4e00\u6761\u8fb9\u90fd \u4e25\u683c\u5c0f\u4e8e\u00a0limitj\u00a0\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u4e00\u4e2a \u5e03\u5c14\u6570\u7ec4\u00a0answer\u00a0\uff0c\u5176\u4e2d\u00a0answer.length == queries.length\u00a0\uff0c\u5f53\u00a0queries[j]\u00a0\u7684\u67e5\u8be2\u7ed3\u679c\u4e3a\u00a0true\u00a0\u65f6\uff0c\u00a0answer \u7b2c\u00a0j\u00a0\u4e2a\u503c\u4e3a\u00a0true\u00a0\uff0c\u5426\u5219\u4e3a\u00a0false\u00a0\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1an = 3, edgeList = [[0,1,2],[1,2,4],[2,0,8],[1,0,16]], queries = [[0,1,2],[0,2,5]]\n\u8f93\u51fa\uff1a[false,true]\n\u89e3\u91ca\uff1a\u4e0a\u56fe\u4e3a\u7ed9\u5b9a\u7684\u8f93\u5165\u6570\u636e\u3002\u6ce8\u610f\u5230 0 \u548c 1 \u4e4b\u95f4\u6709\u4e24\u6761\u91cd\u8fb9\uff0c\u5206\u522b\u4e3a 2 \u548c 16 \u3002\n\u5bf9\u4e8e\u7b2c\u4e00\u4e2a\u67e5\u8be2\uff0c0 \u548c 1 \u4e4b\u95f4\u6ca1\u6709\u5c0f\u4e8e 2 \u7684\u8fb9\uff0c\u6240\u4ee5\u6211\u4eec\u8fd4\u56de false \u3002\n\u5bf9\u4e8e\u7b2c\u4e8c\u4e2a\u67e5\u8be2\uff0c\u6709\u4e00\u6761\u8def\u5f84\uff080 -> 1 -> 2\uff09\u4e24\u6761\u8fb9\u90fd\u5c0f\u4e8e 5 \uff0c\u6240\u4ee5\u8fd9\u4e2a\u67e5\u8be2\u6211\u4eec\u8fd4\u56de true \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1an = 5, edgeList = [[0,1,10],[1,2,5],[2,3,9],[3,4,13]], queries = [[0,4,14],[1,4,13]]\n\u8f93\u51fa\uff1a[true,false]\n\u89e3\u91ca\uff1a\u4e0a\u56fe\u4e3a\u7ed9\u5b9a\u6570\u636e\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= n <= 105
  • \n\t
  • 1 <= edgeList.length, queries.length <= 105
  • \n\t
  • edgeList[i].length == 3
  • \n\t
  • queries[j].length == 3
  • \n\t
  • 0 <= ui, vi, pj, qj <= n - 1
  • \n\t
  • ui != vi
  • \n\t
  • pj != qj
  • \n\t
  • 1 <= disi, limitj <= 109
  • \n\t
  • \u4e24\u4e2a\u70b9\u4e4b\u95f4\u53ef\u80fd\u6709 \u591a\u6761\u00a0\u8fb9\u3002
  • \n
\n", "tags_en": ["Sort", "Union Find"], "tags_cn": ["\u6392\u5e8f", "\u5e76\u67e5\u96c6"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector distanceLimitedPathsExist(int n, vector>& edgeList, vector>& queries) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean[] distanceLimitedPathsExist(int n, int[][] edgeList, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def distanceLimitedPathsExist(self, n, edgeList, queries):\n \"\"\"\n :type n: int\n :type edgeList: List[List[int]]\n :type queries: List[List[int]]\n :rtype: List[bool]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def distanceLimitedPathsExist(self, n: int, edgeList: List[List[int]], queries: List[List[int]]) -> List[bool]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nbool* distanceLimitedPathsExist(int n, int** edgeList, int edgeListSize, int* edgeListColSize, int** queries, int queriesSize, int* queriesColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool[] DistanceLimitedPathsExist(int n, int[][] edgeList, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} edgeList\n * @param {number[][]} queries\n * @return {boolean[]}\n */\nvar distanceLimitedPathsExist = function(n, edgeList, queries) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} edge_list\n# @param {Integer[][]} queries\n# @return {Boolean[]}\ndef distance_limited_paths_exist(n, edge_list, queries)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func distanceLimitedPathsExist(_ n: Int, _ edgeList: [[Int]], _ queries: [[Int]]) -> [Bool] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func distanceLimitedPathsExist(n int, edgeList [][]int, queries [][]int) []bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def distanceLimitedPathsExist(n: Int, edgeList: Array[Array[Int]], queries: Array[Array[Int]]): Array[Boolean] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun distanceLimitedPathsExist(n: Int, edgeList: Array, queries: Array): BooleanArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn distance_limited_paths_exist(n: i32, edge_list: Vec>, queries: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $edgeList\n * @param Integer[][] $queries\n * @return Boolean[]\n */\n function distanceLimitedPathsExist($n, $edgeList, $queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function distanceLimitedPathsExist(n: number, edgeList: number[][], queries: number[][]): boolean[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (distance-limited-paths-exist n edgeList queries)\n (-> exact-integer? (listof (listof exact-integer?)) (listof (listof exact-integer?)) boolean[])\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1697](https://leetcode-cn.com/problems/checking-existence-of-edge-length-limited-paths)", "[\u68c0\u67e5\u8fb9\u957f\u5ea6\u9650\u5236\u7684\u8def\u5f84\u662f\u5426\u5b58\u5728](/solution/1600-1699/1697.Checking%20Existence%20of%20Edge%20Length%20Limited%20Paths/README.md)", "`\u6392\u5e8f`,`\u5e76\u67e5\u96c6`", "\u56f0\u96be", ""], "md_table_row_en": ["[1697](https://leetcode.com/problems/checking-existence-of-edge-length-limited-paths)", "[Checking Existence of Edge Length Limited Paths](/solution/1600-1699/1697.Checking%20Existence%20of%20Edge%20Length%20Limited%20Paths/README_EN.md)", "`Sort`,`Union Find`", "Hard", ""]}, {"question_id": "1814", "frontend_question_id": "1696", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/jump-game-vi", "url_en": "https://leetcode.com/problems/jump-game-vi", "relative_path_cn": "/solution/1600-1699/1696.Jump%20Game%20VI/README.md", "relative_path_en": "/solution/1600-1699/1696.Jump%20Game%20VI/README_EN.md", "title_cn": "\u8df3\u8dc3\u6e38\u620f VI", "title_en": "Jump Game VI", "question_title_slug": "jump-game-vi", "content_en": "

You are given a 0-indexed integer array nums and an integer k.

\n\n

You are initially standing at index 0. In one move, you can jump at most k steps forward without going outside the boundaries of the array. That is, you can jump from index i to any index in the range [i + 1, min(n - 1, i + k)] inclusive.

\n\n

You want to reach the last index of the array (index n - 1). Your score is the sum of all nums[j] for each index j you visited in the array.

\n\n

Return the maximum score you can get.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [1,-1,-2,4,-7,3], k = 2\nOutput: 7\nExplanation: You can choose your jumps forming the subsequence [1,-1,4,3] (underlined above). The sum is 7.\n
\n\n

Example 2:

\n\n
\nInput: nums = [10,-5,-2,4,0,3], k = 3\nOutput: 17\nExplanation: You can choose your jumps forming the subsequence [10,4,3] (underlined above). The sum is 17.\n
\n\n

Example 3:

\n\n
\nInput: nums = [1,-5,-20,4,-1,3,-6,-3], k = 2\nOutput: 0\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  •  1 <= nums.length, k <= 105
  • \n\t
  • -104 <= nums[i] <= 104
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u4e0b\u6807\u4ece 0 \u5f00\u59cb\u7684\u6574\u6570\u6570\u7ec4 nums\u00a0\u548c\u4e00\u4e2a\u6574\u6570 k\u00a0\u3002

\n\n

\u4e00\u5f00\u59cb\u4f60\u5728\u4e0b\u6807\u00a00\u00a0\u5904\u3002\u6bcf\u4e00\u6b65\uff0c\u4f60\u6700\u591a\u53ef\u4ee5\u5f80\u524d\u8df3\u00a0k\u00a0\u6b65\uff0c\u4f46\u4f60\u4e0d\u80fd\u8df3\u51fa\u6570\u7ec4\u7684\u8fb9\u754c\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u4f60\u53ef\u4ee5\u4ece\u4e0b\u6807\u00a0i\u00a0\u8df3\u5230\u00a0[i + 1\uff0c min(n - 1, i + k)]\u00a0\u5305\u542b \u4e24\u4e2a\u7aef\u70b9\u7684\u4efb\u610f\u4f4d\u7f6e\u3002

\n\n

\u4f60\u7684\u76ee\u6807\u662f\u5230\u8fbe\u6570\u7ec4\u6700\u540e\u4e00\u4e2a\u4f4d\u7f6e\uff08\u4e0b\u6807\u4e3a n - 1\u00a0\uff09\uff0c\u4f60\u7684 \u5f97\u5206\u00a0\u4e3a\u7ecf\u8fc7\u7684\u6240\u6709\u6570\u5b57\u4e4b\u548c\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u4f60\u80fd\u5f97\u5230\u7684 \u6700\u5927\u5f97\u5206\u00a0\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [1,-1,-2,4,-7,3], k = 2\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u9009\u62e9\u5b50\u5e8f\u5217 [1,-1,4,3] \uff08\u4e0a\u9762\u52a0\u7c97\u7684\u6570\u5b57\uff09\uff0c\u548c\u4e3a 7 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [10,-5,-2,4,0,3], k = 3\n\u8f93\u51fa\uff1a17\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u9009\u62e9\u5b50\u5e8f\u5217 [10,4,3] \uff08\u4e0a\u9762\u52a0\u7c97\u6570\u5b57\uff09\uff0c\u548c\u4e3a 17 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [1,-5,-20,4,-1,3,-6,-3], k = 2\n\u8f93\u51fa\uff1a0\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u00a01 <= nums.length, k <= 105
  • \n\t
  • -104\u00a0<= nums[i]\u00a0<= 104
  • \n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxResult(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxResult(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxResult(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxResult(self, nums: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxResult(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxResult(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar maxResult = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef max_result(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxResult(_ nums: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxResult(nums []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxResult(nums: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxResult(nums: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_result(nums: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer\n */\n function maxResult($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxResult(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-result nums k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1696](https://leetcode-cn.com/problems/jump-game-vi)", "[\u8df3\u8dc3\u6e38\u620f VI](/solution/1600-1699/1696.Jump%20Game%20VI/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1696](https://leetcode.com/problems/jump-game-vi)", "[Jump Game VI](/solution/1600-1699/1696.Jump%20Game%20VI/README_EN.md)", "", "Medium", ""]}, {"question_id": "1813", "frontend_question_id": "1695", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-erasure-value", "url_en": "https://leetcode.com/problems/maximum-erasure-value", "relative_path_cn": "/solution/1600-1699/1695.Maximum%20Erasure%20Value/README.md", "relative_path_en": "/solution/1600-1699/1695.Maximum%20Erasure%20Value/README_EN.md", "title_cn": "\u5220\u9664\u5b50\u6570\u7ec4\u7684\u6700\u5927\u5f97\u5206", "title_en": "Maximum Erasure Value", "question_title_slug": "maximum-erasure-value", "content_en": "

You are given an array of positive integers nums and want to erase a subarray containing unique elements. The score you get by erasing the subarray is equal to the sum of its elements.

\n\n

Return the maximum score you can get by erasing exactly one subarray.

\n\n

An array b is called to be a subarray of a if it forms a contiguous subsequence of a, that is, if it is equal to a[l],a[l+1],...,a[r] for some (l,r).

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [4,2,4,5,6]\nOutput: 17\nExplanation: The optimal subarray here is [2,4,5,6].\n
\n\n

Example 2:

\n\n
\nInput: nums = [5,2,1,2,5,2,1,2,5]\nOutput: 8\nExplanation: The optimal subarray here is [5,2,1] or [1,2,5].\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 105
  • \n\t
  • 1 <= nums[i] <= 104
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6b63\u6574\u6570\u6570\u7ec4 nums \uff0c\u8bf7\u4f60\u4ece\u4e2d\u5220\u9664\u4e00\u4e2a\u542b\u6709 \u82e5\u5e72\u4e0d\u540c\u5143\u7d20 \u7684\u5b50\u6570\u7ec4\u3002\u5220\u9664\u5b50\u6570\u7ec4\u7684 \u5f97\u5206 \u5c31\u662f\u5b50\u6570\u7ec4\u5404\u5143\u7d20\u4e4b \u548c \u3002

\n\n

\u8fd4\u56de \u53ea\u5220\u9664\u4e00\u4e2a \u5b50\u6570\u7ec4\u53ef\u83b7\u5f97\u7684 \u6700\u5927\u5f97\u5206 \u3002

\n\n

\u5982\u679c\u6570\u7ec4 b \u662f\u6570\u7ec4 a \u7684\u4e00\u4e2a\u8fde\u7eed\u5b50\u5e8f\u5217\uff0c\u5373\u5982\u679c\u5b83\u7b49\u4e8e a[l],a[l+1],...,a[r] \uff0c\u90a3\u4e48\u5b83\u5c31\u662f\u00a0a \u7684\u4e00\u4e2a\u5b50\u6570\u7ec4\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [4,2,4,5,6]\n\u8f93\u51fa\uff1a17\n\u89e3\u91ca\uff1a\u6700\u4f18\u5b50\u6570\u7ec4\u662f [2,4,5,6]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [5,2,1,2,5,2,1,2,5]\n\u8f93\u51fa\uff1a8\n\u89e3\u91ca\uff1a\u6700\u4f18\u5b50\u6570\u7ec4\u662f [5,2,1] \u6216 [1,2,5]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 105
  • \n\t
  • 1 <= nums[i] <= 104
  • \n
\n", "tags_en": ["Two Pointers"], "tags_cn": ["\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maximumUniqueSubarray(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maximumUniqueSubarray(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximumUniqueSubarray(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximumUniqueSubarray(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maximumUniqueSubarray(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaximumUniqueSubarray(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar maximumUniqueSubarray = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef maximum_unique_subarray(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximumUniqueSubarray(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximumUniqueSubarray(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximumUniqueSubarray(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximumUniqueSubarray(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximum_unique_subarray(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function maximumUniqueSubarray($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximumUniqueSubarray(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximum-unique-subarray nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1695](https://leetcode-cn.com/problems/maximum-erasure-value)", "[\u5220\u9664\u5b50\u6570\u7ec4\u7684\u6700\u5927\u5f97\u5206](/solution/1600-1699/1695.Maximum%20Erasure%20Value/README.md)", "`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1695](https://leetcode.com/problems/maximum-erasure-value)", "[Maximum Erasure Value](/solution/1600-1699/1695.Maximum%20Erasure%20Value/README_EN.md)", "`Two Pointers`", "Medium", ""]}, {"question_id": "1812", "frontend_question_id": "1694", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reformat-phone-number", "url_en": "https://leetcode.com/problems/reformat-phone-number", "relative_path_cn": "/solution/1600-1699/1694.Reformat%20Phone%20Number/README.md", "relative_path_en": "/solution/1600-1699/1694.Reformat%20Phone%20Number/README_EN.md", "title_cn": "\u91cd\u65b0\u683c\u5f0f\u5316\u7535\u8bdd\u53f7\u7801", "title_en": "Reformat Phone Number", "question_title_slug": "reformat-phone-number", "content_en": "

You are given a phone number as a string number. number consists of digits, spaces ' ', and/or dashes '-'.

\n\n

You would like to reformat the phone number in a certain manner. Firstly, remove all spaces and dashes. Then, group the digits from left to right into blocks of length 3 until there are 4 or fewer digits. The final digits are then grouped as follows:

\n\n
    \n\t
  • 2 digits: A single block of length 2.
  • \n\t
  • 3 digits: A single block of length 3.
  • \n\t
  • 4 digits: Two blocks of length 2 each.
  • \n
\n\n

The blocks are then joined by dashes. Notice that the reformatting process should never produce any blocks of length 1 and produce at most two blocks of length 2.

\n\n

Return the phone number after formatting.

\n\n

 

\n

Example 1:

\n\n
\nInput: number = "1-23-45 6"\nOutput: "123-456"\nExplanation: The digits are "123456".\nStep 1: There are more than 4 digits, so group the next 3 digits. The 1st block is "123".\nStep 2: There are 3 digits remaining, so put them in a single block of length 3. The 2nd block is "456".\nJoining the blocks gives "123-456".\n
\n\n

Example 2:

\n\n
\nInput: number = "123 4-567"\nOutput: "123-45-67"\nExplanation: The digits are "1234567".\nStep 1: There are more than 4 digits, so group the next 3 digits. The 1st block is "123".\nStep 2: There are 4 digits left, so split them into two blocks of length 2. The blocks are "45" and "67".\nJoining the blocks gives "123-45-67".\n
\n\n

Example 3:

\n\n
\nInput: number = "123 4-5678"\nOutput: "123-456-78"\nExplanation: The digits are "12345678".\nStep 1: The 1st block is "123".\nStep 2: The 2nd block is "456".\nStep 3: There are 2 digits left, so put them in a single block of length 2. The 3rd block is "78".\nJoining the blocks gives "123-456-78".\n
\n\n

Example 4:

\n\n
\nInput: number = "12"\nOutput: "12"\n
\n\n

Example 5:

\n\n
\nInput: number = "--17-5 229 35-39475 "\nOutput: "175-229-353-94-75"\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= number.length <= 100
  • \n\t
  • number consists of digits and the characters '-' and ' '.
  • \n\t
  • There are at least two digits in number.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32\u5f62\u5f0f\u7684\u7535\u8bdd\u53f7\u7801 number \u3002number \u7531\u6570\u5b57\u3001\u7a7a\u683c ' '\u3001\u548c\u7834\u6298\u53f7 '-' \u7ec4\u6210\u3002

\n\n

\u8bf7\u4f60\u6309\u4e0b\u8ff0\u65b9\u5f0f\u91cd\u65b0\u683c\u5f0f\u5316\u7535\u8bdd\u53f7\u7801\u3002

\n\n
    \n\t
  • \u9996\u5148\uff0c\u5220\u9664 \u6240\u6709\u7684\u7a7a\u683c\u548c\u7834\u6298\u53f7\u3002
  • \n\t
  • \u5176\u6b21\uff0c\u5c06\u6570\u7ec4\u4ece\u5de6\u5230\u53f3 \u6bcf 3 \u4e2a\u4e00\u7ec4 \u5206\u5757\uff0c\u76f4\u5230 \u5269\u4e0b 4 \u4e2a\u6216\u66f4\u5c11\u6570\u5b57\u3002\u5269\u4e0b\u7684\u6570\u5b57\u5c06\u6309\u4e0b\u8ff0\u89c4\u5b9a\u518d\u5206\u5757\uff1a\n\t
      \n\t\t
    • 2 \u4e2a\u6570\u5b57\uff1a\u5355\u4e2a\u542b 2 \u4e2a\u6570\u5b57\u7684\u5757\u3002
    • \n\t\t
    • 3 \u4e2a\u6570\u5b57\uff1a\u5355\u4e2a\u542b 3 \u4e2a\u6570\u5b57\u7684\u5757\u3002
    • \n\t\t
    • 4 \u4e2a\u6570\u5b57\uff1a\u4e24\u4e2a\u5206\u522b\u542b 2 \u4e2a\u6570\u5b57\u7684\u5757\u3002
    • \n\t
    \n\t
  • \n
\n\n

\u6700\u540e\u7528\u7834\u6298\u53f7\u5c06\u8fd9\u4e9b\u5757\u8fde\u63a5\u8d77\u6765\u3002\u6ce8\u610f\uff0c\u91cd\u65b0\u683c\u5f0f\u5316\u8fc7\u7a0b\u4e2d \u4e0d\u5e94\u8be5 \u751f\u6210\u4ec5\u542b 1 \u4e2a\u6570\u5b57\u7684\u5757\uff0c\u5e76\u4e14 \u6700\u591a \u751f\u6210\u4e24\u4e2a\u542b 2 \u4e2a\u6570\u5b57\u7684\u5757\u3002

\n\n

\u8fd4\u56de\u683c\u5f0f\u5316\u540e\u7684\u7535\u8bdd\u53f7\u7801\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1anumber = \"1-23-45 6\"\n\u8f93\u51fa\uff1a\"123-456\"\n\u89e3\u91ca\uff1a\u6570\u5b57\u662f \"123456\"\n\u6b65\u9aa4 1\uff1a\u5171\u6709\u8d85\u8fc7 4 \u4e2a\u6570\u5b57\uff0c\u6240\u4ee5\u5148\u53d6 3 \u4e2a\u6570\u5b57\u5206\u4e3a\u4e00\u7ec4\u3002\u7b2c 1 \u4e2a\u5757\u662f \"123\" \u3002\n\u6b65\u9aa4 2\uff1a\u5269\u4e0b 3 \u4e2a\u6570\u5b57\uff0c\u5c06\u5b83\u4eec\u653e\u5165\u5355\u4e2a\u542b 3 \u4e2a\u6570\u5b57\u7684\u5757\u3002\u7b2c 2 \u4e2a\u5757\u662f \"456\" \u3002\n\u8fde\u63a5\u8fd9\u4e9b\u5757\u540e\u5f97\u5230 \"123-456\" \u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1anumber = \"123 4-567\"\n\u8f93\u51fa\uff1a\"123-45-67\"\n\u89e3\u91ca\uff1a\u6570\u5b57\u662f \"1234567\".\n\u6b65\u9aa4 1\uff1a\u5171\u6709\u8d85\u8fc7 4 \u4e2a\u6570\u5b57\uff0c\u6240\u4ee5\u5148\u53d6 3 \u4e2a\u6570\u5b57\u5206\u4e3a\u4e00\u7ec4\u3002\u7b2c 1 \u4e2a\u5757\u662f \"123\" \u3002\n\u6b65\u9aa4 2\uff1a\u5269\u4e0b 4 \u4e2a\u6570\u5b57\uff0c\u6240\u4ee5\u5c06\u5b83\u4eec\u5206\u6210\u4e24\u4e2a\u542b 2 \u4e2a\u6570\u5b57\u7684\u5757\u3002\u8fd9 2 \u5757\u5206\u522b\u662f \"45\" \u548c \"67\" \u3002\n\u8fde\u63a5\u8fd9\u4e9b\u5757\u540e\u5f97\u5230 \"123-45-67\" \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1anumber = \"123 4-5678\"\n\u8f93\u51fa\uff1a\"123-456-78\"\n\u89e3\u91ca\uff1a\u6570\u5b57\u662f \"12345678\" \u3002\n\u6b65\u9aa4 1\uff1a\u7b2c 1 \u4e2a\u5757 \"123\" \u3002\n\u6b65\u9aa4 2\uff1a\u7b2c 2 \u4e2a\u5757 \"456\" \u3002\n\u6b65\u9aa4 3\uff1a\u5269\u4e0b 2 \u4e2a\u6570\u5b57\uff0c\u5c06\u5b83\u4eec\u653e\u5165\u5355\u4e2a\u542b 2 \u4e2a\u6570\u5b57\u7684\u5757\u3002\u7b2c 3 \u4e2a\u5757\u662f \"78\" \u3002\n\u8fde\u63a5\u8fd9\u4e9b\u5757\u540e\u5f97\u5230 \"123-456-78\" \u3002
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1anumber = \"12\"\n\u8f93\u51fa\uff1a\"12\"\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\n\u8f93\u5165\uff1anumber = \"--17-5 229 35-39475 \"\n\u8f93\u51fa\uff1a\"175-229-353-94-75\"\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= number.length <= 100
  • \n\t
  • number \u7531\u6570\u5b57\u548c\u5b57\u7b26 '-' \u53ca ' ' \u7ec4\u6210\u3002
  • \n\t
  • number \u4e2d\u81f3\u5c11\u542b 2 \u4e2a\u6570\u5b57\u3002
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string reformatNumber(string number) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String reformatNumber(String number) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def reformatNumber(self, number):\n \"\"\"\n :type number: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def reformatNumber(self, number: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * reformatNumber(char * number){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ReformatNumber(string number) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} number\n * @return {string}\n */\nvar reformatNumber = function(number) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} number\n# @return {String}\ndef reformat_number(number)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func reformatNumber(_ number: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func reformatNumber(number string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def reformatNumber(number: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun reformatNumber(number: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn reformat_number(number: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $number\n * @return String\n */\n function reformatNumber($number) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function reformatNumber(number: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (reformat-number number)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1694](https://leetcode-cn.com/problems/reformat-phone-number)", "[\u91cd\u65b0\u683c\u5f0f\u5316\u7535\u8bdd\u53f7\u7801](/solution/1600-1699/1694.Reformat%20Phone%20Number/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1694](https://leetcode.com/problems/reformat-phone-number)", "[Reformat Phone Number](/solution/1600-1699/1694.Reformat%20Phone%20Number/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1811", "frontend_question_id": "1667", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/fix-names-in-a-table", "url_en": "https://leetcode.com/problems/fix-names-in-a-table", "relative_path_cn": "/solution/1600-1699/1667.Fix%20Names%20in%20a%20Table/README.md", "relative_path_en": "/solution/1600-1699/1667.Fix%20Names%20in%20a%20Table/README_EN.md", "title_cn": "\u4fee\u590d\u8868\u4e2d\u7684\u540d\u5b57", "title_en": "Fix Names in a Table", "question_title_slug": "fix-names-in-a-table", "content_en": "

Table: Users

\n\n
\n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| user_id        | int     |\n| name           | varchar |\n+----------------+---------+\nuser_id is the primary key for this table.\nThis table contains the ID and the name of the user. The name consists of only lowercase and uppercase characters.\n
\n\n

 

\n\n

Write an SQL query to fix the names so that only the first character is uppercase and the rest are lowercase.

\n\n

Return the result table ordered by user_id.

\n\n

The query result format is in the following example:

\n\n

 

\n\n
\nUsers table:\n+---------+-------+\n| user_id | name  |\n+---------+-------+\n| 1       | aLice |\n| 2       | bOB   |\n+---------+-------+\n\nResult table:\n+---------+-------+\n| user_id | name  |\n+---------+-------+\n| 1       | Alice |\n| 2       | Bob   |\n+---------+-------+\n
\n", "content_cn": "

\u8868\uff1a Users

\n\n
\n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| user_id        | int     |\n| name           | varchar |\n+----------------+---------+\nuser_id \u662f\u8be5\u8868\u7684\u4e3b\u952e\u3002\n\u8be5\u8868\u5305\u542b\u7528\u6237\u7684 ID \u548c\u540d\u5b57\u3002\u540d\u5b57\u4ec5\u7531\u5c0f\u5199\u548c\u5927\u5199\u5b57\u7b26\u7ec4\u6210\u3002\n
\n\n

\u00a0

\n\n

\u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\u6765\u4fee\u590d\u540d\u5b57\uff0c\u4f7f\u5f97\u53ea\u6709\u7b2c\u4e00\u4e2a\u5b57\u7b26\u662f\u5927\u5199\u7684\uff0c\u5176\u4f59\u90fd\u662f\u5c0f\u5199\u7684\u3002

\n\n

\u8fd4\u56de\u6309 user_id \u6392\u5e8f\u7684\u7ed3\u679c\u8868\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u793a\u4f8b\u5982\u4e0b\uff1a

\n\n
\nUsers table:\n+---------+-------+\n| user_id | name  |\n+---------+-------+\n| 1       | aLice |\n| 2       | bOB   |\n+---------+-------+\n\nResult table:\n+---------+-------+\n| user_id | name  |\n+---------+-------+\n| 1       | Alice |\n| 2       | Bob   |\n+---------+-------+\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1667](https://leetcode-cn.com/problems/fix-names-in-a-table)", "[\u4fee\u590d\u8868\u4e2d\u7684\u540d\u5b57](/solution/1600-1699/1667.Fix%20Names%20in%20a%20Table/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1667](https://leetcode.com/problems/fix-names-in-a-table)", "[Fix Names in a Table](/solution/1600-1699/1667.Fix%20Names%20in%20a%20Table/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1810", "frontend_question_id": "1666", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/change-the-root-of-a-binary-tree", "url_en": "https://leetcode.com/problems/change-the-root-of-a-binary-tree", "relative_path_cn": "/solution/1600-1699/1666.Change%20the%20Root%20of%20a%20Binary%20Tree/README.md", "relative_path_en": "/solution/1600-1699/1666.Change%20the%20Root%20of%20a%20Binary%20Tree/README_EN.md", "title_cn": "\u6539\u53d8\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9", "title_en": "Change the Root of a Binary Tree", "question_title_slug": "change-the-root-of-a-binary-tree", "content_en": "

Given the root of a binary tree and a leaf node, reroot the tree so that the leaf is the new root.

\n\n

You can reroot the tree with the following steps for each node cur on the path starting from the leaf up to the root\u200b\u200b\u200b excluding the root:

\n\n
    \n\t
  1. If cur has a left child, then that child becomes cur's right child.
  2. \n\t
  3. cur's original parent becomes cur's left child. Note that in this process the original parent's pointer to cur becomes null, making it have at most one child.
  4. \n
\n\n

Return the new root of the rerooted tree.

\n\n

Note: Ensure that your solution sets the Node.parent pointers correctly after rerooting or you will receive "Wrong Answer".

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: root = [3,5,1,6,2,0,8,null,null,7,4], leaf = 7\nOutput: [7,2,null,5,4,3,6,null,null,null,1,null,null,0,8]\n
\n\n

Example 2:

\n\n
\nInput: root = [3,5,1,6,2,0,8,null,null,7,4], leaf = 0\nOutput: [0,1,null,3,8,5,null,null,null,6,2,null,null,7,4]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The number of nodes in the tree is in the range [2, 100].
  • \n\t
  • -109 <= Node.val <= 109
  • \n\t
  • All Node.val are unique.
  • \n\t
  • leaf exist in the tree.
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u68f5\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9\u00a0root\u00a0\u548c\u4e00\u4e2a\u53f6\u8282\u70b9\u00a0leaf \uff0c\u66f4\u6539\u4e8c\u53c9\u6811\uff0c\u4f7f\u5f97\u00a0leaf\u00a0\u4e3a\u65b0\u7684\u6839\u8282\u70b9\u3002

\n\n

\u4f60\u53ef\u4ee5\u6309\u7167\u4e0b\u5217\u6b65\u9aa4\u4fee\u6539\u4ece leaf\u00a0\u5230 root\u00a0\u7684\u8def\u5f84\u4e2d\u9664 root \u5916\u7684\u6bcf\u4e2a\u8282\u70b9 cur\u00a0\uff1a

\n\n
    \n\t
  1. \u5982\u679c\u00a0cur\u00a0\u6709\u5de6\u5b50\u8282\u70b9\uff0c\u5219\u8be5\u5b50\u8282\u70b9\u53d8\u4e3a\u00a0cur\u00a0\u7684\u53f3\u5b50\u8282\u70b9\u3002\u6ce8\u610f\u6211\u4eec\u4fdd\u8bc1\u00a0cur\u00a0\u81f3\u591a\u6709\u4e00\u4e2a\u5b50\u8282\u70b9\u3002
  2. \n\t
  3. cur\u00a0\u7684\u539f\u7236\u8282\u70b9\u53d8\u4e3a\u00a0cur\u00a0\u7684\u5de6\u5b50\u8282\u70b9\u3002
  4. \n
\n\n

\u8fd4\u56de\u4fee\u6539\u540e\u65b0\u6811\u7684\u6839\u8282\u70b9\u3002

\n\n

\u6ce8\u610f\uff1a\u786e\u4fdd\u4f60\u7684\u7b54\u6848\u5728\u64cd\u4f5c\u540e\u6b63\u786e\u5730\u8bbe\u5b9a\u4e86\u00a0Node.parent\u00a0\uff08\u7236\u8282\u70b9\uff09\u6307\u9488\uff0c\u5426\u5219\u4f1a\u88ab\u5224\u4e3a\u9519\u8bef\u7b54\u6848\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1:

\n\"\"\n
\u8f93\u5165: root = [3,5,1,6,2,0,8,null,null,7,4], leaf = 7\n\u8f93\u51fa: [7,2,null,5,4,3,6,null,null,null,1,null,null,0,8]\n
\n\n

\u793a\u4f8b 2:

\n\n
\u8f93\u5165: root = [3,5,1,6,2,0,8,null,null,7,4], leaf = 0\n\u8f93\u51fa: [0,1,null,3,8,5,null,null,null,6,2,null,null,7,4]\n
\n\n

\u00a0

\n\n

\u63d0\u793a:

\n\n
    \n\t
  • \u6811\u4e2d\u8282\u70b9\u7684\u4e2a\u6570\u5728\u8303\u56f4\u00a0[2, 100]\u00a0\u5185\u3002
  • \n\t
  • -109 <= Node.val <= 109
  • \n\t
  • \u6240\u6709\u7684\u00a0Node.val\u00a0\u90fd\u662f\u552f\u4e00\u7684\u3002
  • \n\t
  • leaf\u00a0\u5b58\u5728\u4e8e\u6811\u4e2d\u3002
  • \n
\n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* parent;\n};\n*/\n\nclass Solution {\npublic:\n Node* flipBinaryTree(Node* root, Node * leaf) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/*\n// Definition for a Node.\nclass Node {\n public int val;\n public Node left;\n public Node right;\n public Node parent;\n};\n*/\n\nclass Solution {\n public Node flipBinaryTree(Node root, Node leaf) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "\"\"\"\n# Definition for a Node.\nclass Node:\n def __init__(self, val):\n self.val = val\n self.left = None\n self.right = None\n self.parent = None\n\"\"\"\n\nclass Solution(object):\n def flipBinaryTree(self, root, leaf):\n \"\"\"\n :type node: Node\n :rtype: Node\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "\"\"\"\n# Definition for a Node.\nclass Node:\n def __init__(self, val):\n self.val = val\n self.left = None\n self.right = None\n self.parent = None\n\"\"\"\n\nclass Solution:\n def flipBinaryTree(self, root: 'Node', leaf: 'Node') -> 'Node':\n ", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/*\n// Definition for a Node.\npublic class Node {\n public int val;\n public Node left;\n public Node right;\n public Node parent;\n}\n*/\n\npublic class Solution {\n public Node FlipBinaryTree(Node root, Node leaf) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // Definition for a Node.\n * function Node(val) {\n * this.val = val;\n * this.left = null;\n * this.right = null;\n * this.parent = null;\n * };\n */\n\n/**\n * @param {Node} node\n * @return {Node}\n */\nvar flipBinaryTree = function(root, leaf) {\n \n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1666](https://leetcode-cn.com/problems/change-the-root-of-a-binary-tree)", "[\u6539\u53d8\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9](/solution/1600-1699/1666.Change%20the%20Root%20of%20a%20Binary%20Tree/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1666](https://leetcode.com/problems/change-the-root-of-a-binary-tree)", "[Change the Root of a Binary Tree](/solution/1600-1699/1666.Change%20the%20Root%20of%20a%20Binary%20Tree/README_EN.md)", "`Tree`,`Depth-first Search`", "Medium", "\ud83d\udd12"]}, {"question_id": "1809", "frontend_question_id": "1714", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/sum-of-special-evenly-spaced-elements-in-array", "url_en": "https://leetcode.com/problems/sum-of-special-evenly-spaced-elements-in-array", "relative_path_cn": "/solution/1700-1799/1714.Sum%20Of%20Special%20Evenly-Spaced%20Elements%20In%20Array/README.md", "relative_path_en": "/solution/1700-1799/1714.Sum%20Of%20Special%20Evenly-Spaced%20Elements%20In%20Array/README_EN.md", "title_cn": "\u6570\u7ec4\u4e2d\u7279\u6b8a\u7b49\u95f4\u8ddd\u5143\u7d20\u7684\u548c", "title_en": "Sum Of Special Evenly-Spaced Elements In Array", "question_title_slug": "sum-of-special-evenly-spaced-elements-in-array", "content_en": "

You are given a 0-indexed integer array nums consisting of n non-negative integers.

\n\n

You are also given an array queries, where queries[i] = [xi, yi]. The answer to the ith query is the sum of all nums[j] where xi <= j < n and (j - xi) is divisible by yi.

\n\n

Return an array answer where answer.length == queries.length and answer[i] is the answer to the ith query modulo 109 + 7.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [0,1,2,3,4,5,6,7], queries = [[0,3],[5,1],[4,2]]\nOutput: [9,18,10]\nExplanation: The answers of the queries are as follows:\n1) The j indices that satisfy this query are 0, 3, and 6. nums[0] + nums[3] + nums[6] = 9\n2) The j indices that satisfy this query are 5, 6, and 7. nums[5] + nums[6] + nums[7] = 18\n3) The j indices that satisfy this query are 4 and 6. nums[4] + nums[6] = 10\n
\n\n

Example 2:

\n\n
\nInput: nums = [100,200,101,201,102,202,103,203], queries = [[0,7]]\nOutput: [303]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == nums.length
  • \n\t
  • 1 <= n <= 5 * 104
  • \n\t
  • 0 <= nums[i] <= 109
  • \n\t
  • 1 <= queries.length <= 1.5 * 105
  • \n\t
  • 0 <= xi < n
  • \n\t
  • 1 <= yi <= 5 * 104
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u7d22\u5f15\u4ece 0 \u5f00\u59cb\u7684\u6574\u6570\u7c7b\u578b\u6570\u7ec4\u00a0nums\u00a0\uff0c\u5305\u542b\u00a0n\u00a0\u4e2a\u975e\u8d1f\u6574\u6570\u3002

\n\n

\u53e6\u5916\u7ed9\u5b9a\u4e00\u4e2a\uff08\u5305\u542b\u67e5\u8be2\u6307\u4ee4\u7684\uff09\u6570\u7ec4\u00a0queries\u00a0\uff0c\u5176\u4e2d\u00a0queries[i] = [xi, yi]\u3002 \u7b2c\u00a0i\u00a0\u4e2a\u67e5\u8be2\u6307\u4ee4\u7684\u7b54\u6848\u662f\u00a0nums[j]\u00a0\u4e2d\u6ee1\u8db3\u8be5\u6761\u4ef6\u7684\u6240\u6709\u5143\u7d20\u7684\u548c\uff1a\u00a0xi <= j < n\u00a0\u4e14\u00a0(j - xi)\u00a0\u80fd\u88ab\u00a0yi\u00a0\u6574\u9664\u3002

\n\n

\u8fd4\u56de\u4e00\u4e2a\u6570\u7ec4\u00a0answer\uff0c\u5176\u4e2d\u00a0\u00a0answer.length == queries.length\u00a0\u4e14\u00a0answer[i]\u00a0\u662f\u7b2c\u00a0i\u00a0\u4e2a\u67e5\u8be2\u6307\u4ee4\u7684\u7b54\u6848\u5bf9\u00a0109 + 7\u00a0\u53d6\u6a21\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1:

\n\n
\u8f93\u5165: nums = [0,1,2,3,4,5,6,7], queries = [[0,3],[5,1],[4,2]]\n\u8f93\u51fa: [9,18,10]\n\u89e3\u91ca: \u6bcf\u6b21\u67e5\u8be2\u7684\u7b54\u6848\u5982\u4e0b\uff1a\n1) \u7b26\u5408\u67e5\u8be2\u6761\u4ef6\u7684\u7d22\u5f15 j \u6709 0\u3001 3 \u548c 6\u3002 nums[0] + nums[3] + nums[6] = 9\n2) \u7b26\u5408\u67e5\u8be2\u6761\u4ef6\u7684\u7d22\u5f15 j \u6709 5\u3001 6 \u548c 7\u3002 nums[5] + nums[6] + nums[7] = 18\n3) \u7b26\u5408\u67e5\u8be2\u6761\u4ef6\u7684\u7d22\u5f15 j \u6709 4 \u548c 6\u3002 nums[4] + nums[6] = 10\n
\n\n

\u793a\u4f8b 2:

\n\n
\u8f93\u5165: nums = [100,200,101,201,102,202,103,203], queries = [[0,7]]\n\u8f93\u51fa: [303]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • n == nums.length
  • \n\t
  • 1 <= n <= 5 * 104
  • \n\t
  • 0 <= nums[i] <= 109
  • \n\t
  • 1 <= queries.length <= 1.5 * 105
  • \n\t
  • 0 <= xi < n
  • \n\t
  • 1 <= yi <= 5 * 104
  • \n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector solve(vector& nums, vector>& queries) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] solve(int[] nums, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def solve(self, nums, queries):\n \"\"\"\n :type nums: List[int]\n :type queries: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def solve(self, nums: List[int], queries: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* solve(int* nums, int numsSize, int** queries, int queriesSize, int* queriesColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] Solve(int[] nums, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number[][]} queries\n * @return {number[]}\n */\nvar solve = function(nums, queries) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer[][]} queries\n# @return {Integer[]}\ndef solve(nums, queries)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func solve(_ nums: [Int], _ queries: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func solve(nums []int, queries [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def solve(nums: Array[Int], queries: Array[Array[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun solve(nums: IntArray, queries: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn solve(nums: Vec, queries: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer[][] $queries\n * @return Integer[]\n */\n function solve($nums, $queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function solve(nums: number[], queries: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (solve nums queries)\n (-> (listof exact-integer?) (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1714](https://leetcode-cn.com/problems/sum-of-special-evenly-spaced-elements-in-array)", "[\u6570\u7ec4\u4e2d\u7279\u6b8a\u7b49\u95f4\u8ddd\u5143\u7d20\u7684\u548c](/solution/1700-1799/1714.Sum%20Of%20Special%20Evenly-Spaced%20Elements%20In%20Array/README.md)", "", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1714](https://leetcode.com/problems/sum-of-special-evenly-spaced-elements-in-array)", "[Sum Of Special Evenly-Spaced Elements In Array](/solution/1700-1799/1714.Sum%20Of%20Special%20Evenly-Spaced%20Elements%20In%20Array/README_EN.md)", "", "Hard", "\ud83d\udd12"]}, {"question_id": "1808", "frontend_question_id": "1690", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/stone-game-vii", "url_en": "https://leetcode.com/problems/stone-game-vii", "relative_path_cn": "/solution/1600-1699/1690.Stone%20Game%20VII/README.md", "relative_path_en": "/solution/1600-1699/1690.Stone%20Game%20VII/README_EN.md", "title_cn": "\u77f3\u5b50\u6e38\u620f VII", "title_en": "Stone Game VII", "question_title_slug": "stone-game-vii", "content_en": "

Alice and Bob take turns playing a game, with Alice starting first.

\n\n

There are n stones arranged in a row. On each player's turn, they can remove either the leftmost stone or the rightmost stone from the row and receive points equal to the sum of the remaining stones' values in the row. The winner is the one with the higher score when there are no stones left to remove.

\n\n

Bob found that he will always lose this game (poor Bob, he always loses), so he decided to minimize the score's difference. Alice's goal is to maximize the difference in the score.

\n\n

Given an array of integers stones where stones[i] represents the value of the ith stone from the left, return the difference in Alice and Bob's score if they both play optimally.

\n\n

 

\n

Example 1:

\n\n
\nInput: stones = [5,3,1,4,2]\nOutput: 6\nExplanation: \n- Alice removes 2 and gets 5 + 3 + 1 + 4 = 13 points. Alice = 13, Bob = 0, stones = [5,3,1,4].\n- Bob removes 5 and gets 3 + 1 + 4 = 8 points. Alice = 13, Bob = 8, stones = [3,1,4].\n- Alice removes 3 and gets 1 + 4 = 5 points. Alice = 18, Bob = 8, stones = [1,4].\n- Bob removes 1 and gets 4 points. Alice = 18, Bob = 12, stones = [4].\n- Alice removes 4 and gets 0 points. Alice = 18, Bob = 12, stones = [].\nThe score difference is 18 - 12 = 6.\n
\n\n

Example 2:

\n\n
\nInput: stones = [7,90,5,1,100,10,10,2]\nOutput: 122
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == stones.length
  • \n\t
  • 2 <= n <= 1000
  • \n\t
  • 1 <= stones[i] <= 1000
  • \n
\n", "content_cn": "

\u77f3\u5b50\u6e38\u620f\u4e2d\uff0c\u7231\u4e3d\u4e1d\u548c\u9c8d\u52c3\u8f6e\u6d41\u8fdb\u884c\u81ea\u5df1\u7684\u56de\u5408\uff0c\u7231\u4e3d\u4e1d\u5148\u5f00\u59cb \u3002

\n\n

\u6709 n \u5757\u77f3\u5b50\u6392\u6210\u4e00\u6392\u3002\u6bcf\u4e2a\u73a9\u5bb6\u7684\u56de\u5408\u4e2d\uff0c\u53ef\u4ee5\u4ece\u884c\u4e2d \u79fb\u9664 \u6700\u5de6\u8fb9\u7684\u77f3\u5934\u6216\u6700\u53f3\u8fb9\u7684\u77f3\u5934\uff0c\u5e76\u83b7\u5f97\u4e0e\u8be5\u884c\u4e2d\u5269\u4f59\u77f3\u5934\u503c\u4e4b \u548c \u76f8\u7b49\u7684\u5f97\u5206\u3002\u5f53\u6ca1\u6709\u77f3\u5934\u53ef\u79fb\u9664\u65f6\uff0c\u5f97\u5206\u8f83\u9ad8\u8005\u83b7\u80dc\u3002

\n\n

\u9c8d\u52c3\u53d1\u73b0\u4ed6\u603b\u662f\u8f93\u6389\u6e38\u620f\uff08\u53ef\u601c\u7684\u9c8d\u52c3\uff0c\u4ed6\u603b\u662f\u8f93\uff09\uff0c\u6240\u4ee5\u4ed6\u51b3\u5b9a\u5c3d\u529b \u51cf\u5c0f\u5f97\u5206\u7684\u5dee\u503c \u3002\u7231\u4e3d\u4e1d\u7684\u76ee\u6807\u662f\u6700\u5927\u9650\u5ea6\u5730 \u6269\u5927\u5f97\u5206\u7684\u5dee\u503c \u3002

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0stones \uff0c\u5176\u4e2d stones[i] \u8868\u793a \u4ece\u5de6\u8fb9\u5f00\u59cb \u7684\u7b2c i \u4e2a\u77f3\u5934\u7684\u503c\uff0c\u5982\u679c\u7231\u4e3d\u4e1d\u548c\u9c8d\u52c3\u90fd \u53d1\u6325\u51fa\u6700\u4f73\u6c34\u5e73 \uff0c\u8bf7\u8fd4\u56de\u4ed6\u4eec \u5f97\u5206\u7684\u5dee\u503c \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1astones = [5,3,1,4,2]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\n- \u7231\u4e3d\u4e1d\u79fb\u9664 2 \uff0c\u5f97\u5206 5 + 3 + 1 + 4 = 13 \u3002\u6e38\u620f\u60c5\u51b5\uff1a\u7231\u4e3d\u4e1d = 13 \uff0c\u9c8d\u52c3 = 0 \uff0c\u77f3\u5b50 = [5,3,1,4] \u3002\n- \u9c8d\u52c3\u79fb\u9664 5 \uff0c\u5f97\u5206 3 + 1 + 4 = 8 \u3002\u6e38\u620f\u60c5\u51b5\uff1a\u7231\u4e3d\u4e1d = 13 \uff0c\u9c8d\u52c3 = 8 \uff0c\u77f3\u5b50 = [3,1,4] \u3002\n- \u7231\u4e3d\u4e1d\u79fb\u9664 3 \uff0c\u5f97\u5206 1 + 4 = 5 \u3002\u6e38\u620f\u60c5\u51b5\uff1a\u7231\u4e3d\u4e1d = 18 \uff0c\u9c8d\u52c3 = 8 \uff0c\u77f3\u5b50 = [1,4] \u3002\n- \u9c8d\u52c3\u79fb\u9664 1 \uff0c\u5f97\u5206 4 \u3002\u6e38\u620f\u60c5\u51b5\uff1a\u7231\u4e3d\u4e1d = 18 \uff0c\u9c8d\u52c3 = 12 \uff0c\u77f3\u5b50 = [4] \u3002\n- \u7231\u4e3d\u4e1d\u79fb\u9664 4 \uff0c\u5f97\u5206 0 \u3002\u6e38\u620f\u60c5\u51b5\uff1a\u7231\u4e3d\u4e1d = 18 \uff0c\u9c8d\u52c3 = 12 \uff0c\u77f3\u5b50 = [] \u3002\n\u5f97\u5206\u7684\u5dee\u503c 18 - 12 = 6 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1astones = [7,90,5,1,100,10,10,2]\n\u8f93\u51fa\uff1a122
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • n == stones.length
  • \n\t
  • 2 <= n <= 1000
  • \n\t
  • 1 <= stones[i] <= 1000
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int stoneGameVII(vector& stones) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int stoneGameVII(int[] stones) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def stoneGameVII(self, stones):\n \"\"\"\n :type stones: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def stoneGameVII(self, stones: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint stoneGameVII(int* stones, int stonesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int StoneGameVII(int[] stones) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} stones\n * @return {number}\n */\nvar stoneGameVII = function(stones) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} stones\n# @return {Integer}\ndef stone_game_vii(stones)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func stoneGameVII(_ stones: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func stoneGameVII(stones []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def stoneGameVII(stones: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun stoneGameVII(stones: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn stone_game_vii(stones: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $stones\n * @return Integer\n */\n function stoneGameVII($stones) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function stoneGameVII(stones: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (stone-game-vii stones)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1690](https://leetcode-cn.com/problems/stone-game-vii)", "[\u77f3\u5b50\u6e38\u620f VII](/solution/1600-1699/1690.Stone%20Game%20VII/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1690](https://leetcode.com/problems/stone-game-vii)", "[Stone Game VII](/solution/1600-1699/1690.Stone%20Game%20VII/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "1807", "frontend_question_id": "1689", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers", "url_en": "https://leetcode.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers", "relative_path_cn": "/solution/1600-1699/1689.Partitioning%20Into%20Minimum%20Number%20Of%20Deci-Binary%20Numbers/README.md", "relative_path_en": "/solution/1600-1699/1689.Partitioning%20Into%20Minimum%20Number%20Of%20Deci-Binary%20Numbers/README_EN.md", "title_cn": "\u5341-\u4e8c\u8fdb\u5236\u6570\u7684\u6700\u5c11\u6570\u76ee", "title_en": "Partitioning Into Minimum Number Of Deci-Binary Numbers", "question_title_slug": "partitioning-into-minimum-number-of-deci-binary-numbers", "content_en": "

A decimal number is called deci-binary if each of its digits is either 0 or 1 without any leading zeros. For example, 101 and 1100 are deci-binary, while 112 and 3001 are not.

\n\n

Given a string n that represents a positive decimal integer, return the minimum number of positive deci-binary numbers needed so that they sum up to n.

\n\n

 

\n

Example 1:

\n\n
\nInput: n = "32"\nOutput: 3\nExplanation: 10 + 11 + 11 = 32\n
\n\n

Example 2:

\n\n
\nInput: n = "82734"\nOutput: 8\n
\n\n

Example 3:

\n\n
\nInput: n = "27346209830709182346"\nOutput: 9\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n.length <= 105
  • \n\t
  • n consists of only digits.
  • \n\t
  • n does not contain any leading zeros and represents a positive integer.
  • \n
\n", "content_cn": "

\u5982\u679c\u4e00\u4e2a\u5341\u8fdb\u5236\u6570\u5b57\u4e0d\u542b\u4efb\u4f55\u524d\u5bfc\u96f6\uff0c\u4e14\u6bcf\u4e00\u4f4d\u4e0a\u7684\u6570\u5b57\u4e0d\u662f 0 \u5c31\u662f 1 \uff0c\u90a3\u4e48\u8be5\u6570\u5b57\u5c31\u662f\u4e00\u4e2a \u5341-\u4e8c\u8fdb\u5236\u6570 \u3002\u4f8b\u5982\uff0c101 \u548c 1100 \u90fd\u662f \u5341-\u4e8c\u8fdb\u5236\u6570\uff0c\u800c 112 \u548c 3001 \u4e0d\u662f\u3002

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u8868\u793a\u5341\u8fdb\u5236\u6574\u6570\u7684\u5b57\u7b26\u4e32 n \uff0c\u8fd4\u56de\u548c\u4e3a n \u7684 \u5341-\u4e8c\u8fdb\u5236\u6570 \u7684\u6700\u5c11\u6570\u76ee\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1an = \"32\"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a10 + 11 + 11 = 32\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1an = \"82734\"\n\u8f93\u51fa\uff1a8\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1an = \"27346209830709182346\"\n\u8f93\u51fa\uff1a9\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n.length <= 105
  • \n\t
  • n \u4ec5\u7531\u6570\u5b57\u7ec4\u6210
  • \n\t
  • n \u4e0d\u542b\u4efb\u4f55\u524d\u5bfc\u96f6\u5e76\u603b\u662f\u8868\u793a\u6b63\u6574\u6570
  • \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minPartitions(string n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minPartitions(String n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minPartitions(self, n):\n \"\"\"\n :type n: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minPartitions(self, n: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minPartitions(char * n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinPartitions(string n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} n\n * @return {number}\n */\nvar minPartitions = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} n\n# @return {Integer}\ndef min_partitions(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minPartitions(_ n: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minPartitions(n string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minPartitions(n: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minPartitions(n: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_partitions(n: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $n\n * @return Integer\n */\n function minPartitions($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minPartitions(n: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-partitions n)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1689](https://leetcode-cn.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers)", "[\u5341-\u4e8c\u8fdb\u5236\u6570\u7684\u6700\u5c11\u6570\u76ee](/solution/1600-1699/1689.Partitioning%20Into%20Minimum%20Number%20Of%20Deci-Binary%20Numbers/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1689](https://leetcode.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers)", "[Partitioning Into Minimum Number Of Deci-Binary Numbers](/solution/1600-1699/1689.Partitioning%20Into%20Minimum%20Number%20Of%20Deci-Binary%20Numbers/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1806", "frontend_question_id": "1688", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-of-matches-in-tournament", "url_en": "https://leetcode.com/problems/count-of-matches-in-tournament", "relative_path_cn": "/solution/1600-1699/1688.Count%20of%20Matches%20in%20Tournament/README.md", "relative_path_en": "/solution/1600-1699/1688.Count%20of%20Matches%20in%20Tournament/README_EN.md", "title_cn": "\u6bd4\u8d5b\u4e2d\u7684\u914d\u5bf9\u6b21\u6570", "title_en": "Count of Matches in Tournament", "question_title_slug": "count-of-matches-in-tournament", "content_en": "

You are given an integer n, the number of teams in a tournament that has strange rules:

\n\n
    \n\t
  • If the current number of teams is even, each team gets paired with another team. A total of n / 2 matches are played, and n / 2 teams advance to the next round.
  • \n\t
  • If the current number of teams is odd, one team randomly advances in the tournament, and the rest gets paired. A total of (n - 1) / 2 matches are played, and (n - 1) / 2 + 1 teams advance to the next round.
  • \n
\n\n

Return the number of matches played in the tournament until a winner is decided.

\n\n

 

\n

Example 1:

\n\n
\nInput: n = 7\nOutput: 6\nExplanation: Details of the tournament: \n- 1st Round: Teams = 7, Matches = 3, and 4 teams advance.\n- 2nd Round: Teams = 4, Matches = 2, and 2 teams advance.\n- 3rd Round: Teams = 2, Matches = 1, and 1 team is declared the winner.\nTotal number of matches = 3 + 2 + 1 = 6.\n
\n\n

Example 2:

\n\n
\nInput: n = 14\nOutput: 13\nExplanation: Details of the tournament:\n- 1st Round: Teams = 14, Matches = 7, and 7 teams advance.\n- 2nd Round: Teams = 7, Matches = 3, and 4 teams advance.\n- 3rd Round: Teams = 4, Matches = 2, and 2 teams advance.\n- 4th Round: Teams = 2, Matches = 1, and 1 team is declared the winner.\nTotal number of matches = 7 + 3 + 2 + 1 = 13.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 200
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n \uff0c\u8868\u793a\u6bd4\u8d5b\u4e2d\u7684\u961f\u4f0d\u6570\u3002\u6bd4\u8d5b\u9075\u5faa\u4e00\u79cd\u72ec\u7279\u7684\u8d5b\u5236\uff1a

\n\n
    \n\t
  • \u5982\u679c\u5f53\u524d\u961f\u4f0d\u6570\u662f \u5076\u6570 \uff0c\u90a3\u4e48\u6bcf\u652f\u961f\u4f0d\u90fd\u4f1a\u4e0e\u53e6\u4e00\u652f\u961f\u4f0d\u914d\u5bf9\u3002\u603b\u5171\u8fdb\u884c n / 2 \u573a\u6bd4\u8d5b\uff0c\u4e14\u4ea7\u751f n / 2 \u652f\u961f\u4f0d\u8fdb\u5165\u4e0b\u4e00\u8f6e\u3002
  • \n\t
  • \u5982\u679c\u5f53\u524d\u961f\u4f0d\u6570\u4e3a \u5947\u6570 \uff0c\u90a3\u4e48\u5c06\u4f1a\u968f\u673a\u8f6e\u7a7a\u5e76\u664b\u7ea7\u4e00\u652f\u961f\u4f0d\uff0c\u5176\u4f59\u7684\u961f\u4f0d\u914d\u5bf9\u3002\u603b\u5171\u8fdb\u884c (n - 1) / 2 \u573a\u6bd4\u8d5b\uff0c\u4e14\u4ea7\u751f (n - 1) / 2 + 1 \u652f\u961f\u4f0d\u8fdb\u5165\u4e0b\u4e00\u8f6e\u3002
  • \n
\n\n

\u8fd4\u56de\u5728\u6bd4\u8d5b\u4e2d\u8fdb\u884c\u7684\u914d\u5bf9\u6b21\u6570\uff0c\u76f4\u5230\u51b3\u51fa\u83b7\u80dc\u961f\u4f0d\u4e3a\u6b62\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1an = 7\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u6bd4\u8d5b\u8be6\u60c5\uff1a\n- \u7b2c 1 \u8f6e\uff1a\u961f\u4f0d\u6570 = 7 \uff0c\u914d\u5bf9\u6b21\u6570 = 3 \uff0c4 \u652f\u961f\u4f0d\u664b\u7ea7\u3002\n- \u7b2c 2 \u8f6e\uff1a\u961f\u4f0d\u6570 = 4 \uff0c\u914d\u5bf9\u6b21\u6570 = 2 \uff0c2 \u652f\u961f\u4f0d\u664b\u7ea7\u3002\n- \u7b2c 3 \u8f6e\uff1a\u961f\u4f0d\u6570 = 2 \uff0c\u914d\u5bf9\u6b21\u6570 = 1 \uff0c\u51b3\u51fa 1 \u652f\u83b7\u80dc\u961f\u4f0d\u3002\n\u603b\u914d\u5bf9\u6b21\u6570 = 3 + 2 + 1 = 6\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1an = 14\n\u8f93\u51fa\uff1a13\n\u89e3\u91ca\uff1a\u6bd4\u8d5b\u8be6\u60c5\uff1a\n- \u7b2c 1 \u8f6e\uff1a\u961f\u4f0d\u6570 = 14 \uff0c\u914d\u5bf9\u6b21\u6570 = 7 \uff0c7 \u652f\u961f\u4f0d\u664b\u7ea7\u3002\n- \u7b2c 2 \u8f6e\uff1a\u961f\u4f0d\u6570 = 7 \uff0c\u914d\u5bf9\u6b21\u6570 = 3 \uff0c4 \u652f\u961f\u4f0d\u664b\u7ea7\u3002 \n- \u7b2c 3 \u8f6e\uff1a\u961f\u4f0d\u6570 = 4 \uff0c\u914d\u5bf9\u6b21\u6570 = 2 \uff0c2 \u652f\u961f\u4f0d\u664b\u7ea7\u3002\n- \u7b2c 4 \u8f6e\uff1a\u961f\u4f0d\u6570 = 2 \uff0c\u914d\u5bf9\u6b21\u6570 = 1 \uff0c\u51b3\u51fa 1 \u652f\u83b7\u80dc\u961f\u4f0d\u3002\n\u603b\u914d\u5bf9\u6b21\u6570 = 7 + 3 + 2 + 1 = 13\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 200
  • \n
\n", "tags_en": ["Backtracking"], "tags_cn": ["\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numberOfMatches(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numberOfMatches(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numberOfMatches(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numberOfMatches(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numberOfMatches(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumberOfMatches(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar numberOfMatches = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef number_of_matches(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numberOfMatches(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numberOfMatches(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numberOfMatches(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numberOfMatches(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn number_of_matches(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function numberOfMatches($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numberOfMatches(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (number-of-matches n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1688](https://leetcode-cn.com/problems/count-of-matches-in-tournament)", "[\u6bd4\u8d5b\u4e2d\u7684\u914d\u5bf9\u6b21\u6570](/solution/1600-1699/1688.Count%20of%20Matches%20in%20Tournament/README.md)", "`\u56de\u6eaf\u7b97\u6cd5`", "\u7b80\u5355", ""], "md_table_row_en": ["[1688](https://leetcode.com/problems/count-of-matches-in-tournament)", "[Count of Matches in Tournament](/solution/1600-1699/1688.Count%20of%20Matches%20in%20Tournament/README_EN.md)", "`Backtracking`", "Easy", ""]}, {"question_id": "1805", "frontend_question_id": "1703", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-adjacent-swaps-for-k-consecutive-ones", "url_en": "https://leetcode.com/problems/minimum-adjacent-swaps-for-k-consecutive-ones", "relative_path_cn": "/solution/1700-1799/1703.Minimum%20Adjacent%20Swaps%20for%20K%20Consecutive%20Ones/README.md", "relative_path_en": "/solution/1700-1799/1703.Minimum%20Adjacent%20Swaps%20for%20K%20Consecutive%20Ones/README_EN.md", "title_cn": "\u5f97\u5230\u8fde\u7eed K \u4e2a 1 \u7684\u6700\u5c11\u76f8\u90bb\u4ea4\u6362\u6b21\u6570", "title_en": "Minimum Adjacent Swaps for K Consecutive Ones", "question_title_slug": "minimum-adjacent-swaps-for-k-consecutive-ones", "content_en": "

You are given an integer array, nums, and an integer k. nums comprises of only 0's and 1's. In one move, you can choose two adjacent indices and swap their values.

\n\n

Return the minimum number of moves required so that nums has k consecutive 1's.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [1,0,0,1,0,1], k = 2\nOutput: 1\nExplanation: In 1 move, nums could be [1,0,0,0,1,1] and have 2 consecutive 1's.\n
\n\n

Example 2:

\n\n
\nInput: nums = [1,0,0,0,0,0,1,1], k = 3\nOutput: 5\nExplanation: In 5 moves, the leftmost 1 can be shifted right until nums = [0,0,0,0,0,1,1,1].\n
\n\n

Example 3:

\n\n
\nInput: nums = [1,1,0,1], k = 2\nOutput: 0\nExplanation: nums already has 2 consecutive 1's.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 105
  • \n\t
  • nums[i] is 0 or 1.
  • \n\t
  • 1 <= k <= sum(nums)
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0nums\u00a0\u548c\u4e00\u4e2a\u6574\u6570\u00a0k\u00a0\u3002\u00a0nums \u4ec5\u5305\u542b\u00a00\u00a0\u548c\u00a01\u00a0\u3002\u6bcf\u4e00\u6b21\u79fb\u52a8\uff0c\u4f60\u53ef\u4ee5\u9009\u62e9 \u76f8\u90bb\u00a0\u4e24\u4e2a\u6570\u5b57\u5e76\u5c06\u5b83\u4eec\u4ea4\u6362\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u4f7f\u00a0nums\u00a0\u4e2d\u5305\u542b\u00a0k\u00a0\u4e2a \u8fde\u7eed\u00a01\u00a0\u7684 \u6700\u5c11\u00a0\u4ea4\u6362\u6b21\u6570\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,0,0,1,0,1], k = 2\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u5728\u7b2c\u4e00\u6b21\u64cd\u4f5c\u65f6\uff0cnums \u53ef\u4ee5\u53d8\u6210 [1,0,0,0,1,1] \u5f97\u5230\u8fde\u7eed\u4e24\u4e2a 1 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,0,0,0,0,0,1,1], k = 3\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u901a\u8fc7 5 \u6b21\u64cd\u4f5c\uff0c\u6700\u5de6\u8fb9\u7684 1 \u53ef\u4ee5\u79fb\u5230\u53f3\u8fb9\u76f4\u5230 nums \u53d8\u4e3a [0,0,0,0,0,1,1,1] \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,1,0,1], k = 2\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1anums \u5df2\u7ecf\u6709\u8fde\u7eed 2 \u4e2a 1 \u4e86\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 105
  • \n\t
  • nums[i] \u8981\u4e48\u662f\u00a00\u00a0\uff0c\u8981\u4e48\u662f\u00a01\u00a0\u3002
  • \n\t
  • 1 <= k <= sum(nums)
  • \n
\n", "tags_en": ["Stack"], "tags_cn": ["\u6808"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minMoves(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minMoves(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minMoves(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minMoves(self, nums: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minMoves(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinMoves(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar minMoves = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef min_moves(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minMoves(_ nums: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minMoves(nums []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minMoves(nums: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minMoves(nums: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_moves(nums: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer\n */\n function minMoves($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minMoves(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-moves nums k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1703](https://leetcode-cn.com/problems/minimum-adjacent-swaps-for-k-consecutive-ones)", "[\u5f97\u5230\u8fde\u7eed K \u4e2a 1 \u7684\u6700\u5c11\u76f8\u90bb\u4ea4\u6362\u6b21\u6570](/solution/1700-1799/1703.Minimum%20Adjacent%20Swaps%20for%20K%20Consecutive%20Ones/README.md)", "`\u6808`", "\u56f0\u96be", ""], "md_table_row_en": ["[1703](https://leetcode.com/problems/minimum-adjacent-swaps-for-k-consecutive-ones)", "[Minimum Adjacent Swaps for K Consecutive Ones](/solution/1700-1799/1703.Minimum%20Adjacent%20Swaps%20for%20K%20Consecutive%20Ones/README_EN.md)", "`Stack`", "Hard", ""]}, {"question_id": "1804", "frontend_question_id": "1702", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-binary-string-after-change", "url_en": "https://leetcode.com/problems/maximum-binary-string-after-change", "relative_path_cn": "/solution/1700-1799/1702.Maximum%20Binary%20String%20After%20Change/README.md", "relative_path_en": "/solution/1700-1799/1702.Maximum%20Binary%20String%20After%20Change/README_EN.md", "title_cn": "\u4fee\u6539\u540e\u7684\u6700\u5927\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32", "title_en": "Maximum Binary String After Change", "question_title_slug": "maximum-binary-string-after-change", "content_en": "

You are given a binary string binary consisting of only 0's or 1's. You can apply each of the following operations any number of times:

\n\n
    \n\t
  • Operation 1: If the number contains the substring "00", you can replace it with "10".\n\n\t
      \n\t\t
    • For example, "00010" -> "10010"
    • \n\t
    \n\t
  • \n\t
  • Operation 2: If the number contains the substring "10", you can replace it with "01".\n\t
      \n\t\t
    • For example, "00010" -> "00001"
    • \n\t
    \n\t
  • \n
\n\n

Return the maximum binary string you can obtain after any number of operations. Binary string x is greater than binary string y if x's decimal representation is greater than y's decimal representation.

\n\n

 

\n

Example 1:

\n\n
\nInput: binary = "000110"\nOutput: "111011"\nExplanation: A valid transformation sequence can be:\n"000110" -> "000101" \n"000101" -> "100101" \n"100101" -> "110101" \n"110101" -> "110011" \n"110011" -> "111011"\n
\n\n

Example 2:

\n\n
\nInput: binary = "01"\nOutput: "01"\nExplanation: "01" cannot be transformed any further.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= binary.length <= 105
  • \n\t
  • binary consist of '0' and '1'.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32\u00a0binary\u00a0\uff0c\u5b83\u4ec5\u6709\u00a00\u00a0\u6216\u8005\u00a01\u00a0\u7ec4\u6210\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u4e0b\u9762\u7684\u64cd\u4f5c\u4efb\u610f\u6b21\u5bf9\u5b83\u8fdb\u884c\u4fee\u6539\uff1a

\n\n
    \n\t
  • \u64cd\u4f5c 1 \uff1a\u5982\u679c\u4e8c\u8fdb\u5236\u4e32\u5305\u542b\u5b50\u5b57\u7b26\u4e32\u00a0\"00\"\u00a0\uff0c\u4f60\u53ef\u4ee5\u7528\u00a0\"10\"\u00a0\u5c06\u5176\u66ff\u6362\u3002\n\n\t
      \n\t\t
    • \u6bd4\u65b9\u8bf4\uff0c\u00a0\"00010\" -> \"10010\"
    • \n\t
    \n\t
  • \n\t
  • \u64cd\u4f5c 2 \uff1a\u5982\u679c\u4e8c\u8fdb\u5236\u4e32\u5305\u542b\u5b50\u5b57\u7b26\u4e32\u00a0\"10\"\u00a0\uff0c\u4f60\u53ef\u4ee5\u7528\u00a0\"01\"\u00a0\u5c06\u5176\u66ff\u6362\u3002\n\t
      \n\t\t
    • \u6bd4\u65b9\u8bf4\uff0c\u00a0\"00010\" -> \"00001\"
    • \n\t
    \n\t
  • \n
\n\n

\u8bf7\u4f60\u8fd4\u56de\u6267\u884c\u4e0a\u8ff0\u64cd\u4f5c\u4efb\u610f\u6b21\u4ee5\u540e\u80fd\u5f97\u5230\u7684 \u6700\u5927\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32\u00a0\u3002\u5982\u679c\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32 x\u00a0\u5bf9\u5e94\u7684\u5341\u8fdb\u5236\u6570\u5b57\u5927\u4e8e\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32 y\u00a0\u5bf9\u5e94\u7684\u5341\u8fdb\u5236\u6570\u5b57\uff0c\u90a3\u4e48\u6211\u4eec\u79f0\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32\u00a0x\u00a0\u5927\u4e8e\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32\u00a0y\u00a0\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1abinary = \"000110\"\n\u8f93\u51fa\uff1a\"111011\"\n\u89e3\u91ca\uff1a\u4e00\u4e2a\u53ef\u884c\u7684\u8f6c\u6362\u4e3a\uff1a\n\"000110\" -> \"000101\" \n\"000101\" -> \"100101\" \n\"100101\" -> \"110101\" \n\"110101\" -> \"110011\" \n\"110011\" -> \"111011\"\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1abinary = \"01\"\n\u8f93\u51fa\uff1a\"01\"\n\u89e3\u91ca\uff1a\"01\" \u6ca1\u529e\u6cd5\u8fdb\u884c\u4efb\u4f55\u8f6c\u6362\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= binary.length <= 105
  • \n\t
  • binary \u4ec5\u5305\u542b\u00a0'0' \u548c\u00a0'1' \u3002
  • \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string maximumBinaryString(string binary) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String maximumBinaryString(String binary) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximumBinaryString(self, binary):\n \"\"\"\n :type binary: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximumBinaryString(self, binary: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * maximumBinaryString(char * binary){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string MaximumBinaryString(string binary) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} binary\n * @return {string}\n */\nvar maximumBinaryString = function(binary) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} binary\n# @return {String}\ndef maximum_binary_string(binary)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximumBinaryString(_ binary: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximumBinaryString(binary string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximumBinaryString(binary: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximumBinaryString(binary: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximum_binary_string(binary: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $binary\n * @return String\n */\n function maximumBinaryString($binary) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximumBinaryString(binary: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximum-binary-string binary)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1702](https://leetcode-cn.com/problems/maximum-binary-string-after-change)", "[\u4fee\u6539\u540e\u7684\u6700\u5927\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32](/solution/1700-1799/1702.Maximum%20Binary%20String%20After%20Change/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1702](https://leetcode.com/problems/maximum-binary-string-after-change)", "[Maximum Binary String After Change](/solution/1700-1799/1702.Maximum%20Binary%20String%20After%20Change/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1803", "frontend_question_id": "1701", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/average-waiting-time", "url_en": "https://leetcode.com/problems/average-waiting-time", "relative_path_cn": "/solution/1700-1799/1701.Average%20Waiting%20Time/README.md", "relative_path_en": "/solution/1700-1799/1701.Average%20Waiting%20Time/README_EN.md", "title_cn": "\u5e73\u5747\u7b49\u5f85\u65f6\u95f4", "title_en": "Average Waiting Time", "question_title_slug": "average-waiting-time", "content_en": "

There is a restaurant with a single chef. You are given an array customers, where customers[i] = [arrivali, timei]:

\n\n
    \n\t
  • arrivali is the arrival time of the ith customer. The arrival times are sorted in non-decreasing order.
  • \n\t
  • timei is the time needed to prepare the order of the ith customer.
  • \n
\n\n

When a customer arrives, he gives the chef his order, and the chef starts preparing it once he is idle. The customer waits till the chef finishes preparing his order. The chef does not prepare food for more than one customer at a time. The chef prepares food for customers in the order they were given in the input.

\n\n

Return the average waiting time of all customers. Solutions within 10-5 from the actual answer are considered accepted.

\n\n

 

\n

Example 1:

\n\n
\nInput: customers = [[1,2],[2,5],[4,3]]\nOutput: 5.00000\nExplanation:\n1) The first customer arrives at time 1, the chef takes his order and starts preparing it immediately at time 1, and finishes at time 3, so the waiting time of the first customer is 3 - 1 = 2.\n2) The second customer arrives at time 2, the chef takes his order and starts preparing it at time 3, and finishes at time 8, so the waiting time of the second customer is 8 - 2 = 6.\n3) The third customer arrives at time 4, the chef takes his order and starts preparing it at time 8, and finishes at time 11, so the waiting time of the third customer is 11 - 4 = 7.\nSo the average waiting time = (2 + 6 + 7) / 3 = 5.\n
\n\n

Example 2:

\n\n
\nInput: customers = [[5,2],[5,4],[10,3],[20,1]]\nOutput: 3.25000\nExplanation:\n1) The first customer arrives at time 5, the chef takes his order and starts preparing it immediately at time 5, and finishes at time 7, so the waiting time of the first customer is 7 - 5 = 2.\n2) The second customer arrives at time 5, the chef takes his order and starts preparing it at time 7, and finishes at time 11, so the waiting time of the second customer is 11 - 5 = 6.\n3) The third customer arrives at time 10, the chef takes his order and starts preparing it at time 11, and finishes at time 14, so the waiting time of the third customer is 14 - 10 = 4.\n4) The fourth customer arrives at time 20, the chef takes his order and starts preparing it immediately at time 20, and finishes at time 21, so the waiting time of the fourth customer is 21 - 20 = 1.\nSo the average waiting time = (2 + 6 + 4 + 1) / 4 = 3.25.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= customers.length <= 105
  • \n\t
  • 1 <= arrivali, timei <= 104
  • \n\t
  • arrival<= arrivali+1
  • \n
\n", "content_cn": "

\u6709\u4e00\u4e2a\u9910\u5385\uff0c\u53ea\u6709\u4e00\u4f4d\u53a8\u5e08\u3002\u4f60\u6709\u4e00\u4e2a\u987e\u5ba2\u6570\u7ec4\u00a0customers\u00a0\uff0c\u5176\u4e2d\u00a0customers[i] = [arrivali, timei]\u00a0\uff1a

\n\n
    \n\t
  • arrivali\u00a0\u662f\u7b2c\u00a0i\u00a0\u4f4d\u987e\u5ba2\u5230\u8fbe\u7684\u65f6\u95f4\uff0c\u5230\u8fbe\u65f6\u95f4\u6309 \u975e\u9012\u51cf \u987a\u5e8f\u6392\u5217\u3002
  • \n\t
  • timei\u00a0\u662f\u7ed9\u7b2c i\u00a0\u4f4d\u987e\u5ba2\u505a\u83dc\u9700\u8981\u7684\u65f6\u95f4\u3002
  • \n
\n\n

\u5f53\u4e00\u4f4d\u987e\u5ba2\u5230\u8fbe\u65f6\uff0c\u4ed6\u5c06\u4ed6\u7684\u8ba2\u5355\u7ed9\u53a8\u5e08\uff0c\u53a8\u5e08\u4e00\u65e6\u7a7a\u95f2\u7684\u65f6\u5019\u5c31\u5f00\u59cb\u505a\u8fd9\u4f4d\u987e\u5ba2\u7684\u83dc\u3002\u6bcf\u4f4d\u987e\u5ba2\u4f1a\u4e00\u76f4\u7b49\u5f85\u5230\u53a8\u5e08\u5b8c\u6210\u4ed6\u7684\u8ba2\u5355\u3002\u53a8\u5e08\u540c\u65f6\u53ea\u80fd\u505a\u4e00\u4e2a\u4eba\u7684\u8ba2\u5355\u3002\u53a8\u5e08\u4f1a\u4e25\u683c\u6309\u7167 \u8ba2\u5355\u7ed9\u4ed6\u7684\u987a\u5e8f\u00a0\u505a\u83dc\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u6240\u6709\u987e\u5ba2\u9700\u8981\u7b49\u5f85\u7684 \u5e73\u5747\u00a0\u65f6\u95f4\u3002\u4e0e\u6807\u51c6\u7b54\u6848\u8bef\u5dee\u5728\u00a010-5\u00a0\u8303\u56f4\u4ee5\u5185\uff0c\u90fd\u89c6\u4e3a\u6b63\u786e\u7ed3\u679c\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1acustomers = [[1,2],[2,5],[4,3]]\n\u8f93\u51fa\uff1a5.00000\n\u89e3\u91ca\uff1a\n1) \u7b2c\u4e00\u4f4d\u987e\u5ba2\u5728\u65f6\u523b 1 \u5230\u8fbe\uff0c\u53a8\u5e08\u62ff\u5230\u4ed6\u7684\u8ba2\u5355\u5e76\u5728\u65f6\u523b 1 \u7acb\u9a6c\u5f00\u59cb\u505a\u83dc\uff0c\u5e76\u5728\u65f6\u523b 3 \u5b8c\u6210\uff0c\u7b2c\u4e00\u4f4d\u987e\u5ba2\u7b49\u5f85\u65f6\u95f4\u4e3a 3 - 1 = 2 \u3002\n2) \u7b2c\u4e8c\u4f4d\u987e\u5ba2\u5728\u65f6\u523b 2 \u5230\u8fbe\uff0c\u53a8\u5e08\u5728\u65f6\u523b 3 \u5f00\u59cb\u4e3a\u4ed6\u505a\u83dc\uff0c\u5e76\u5728\u65f6\u523b 8 \u5b8c\u6210\uff0c\u7b2c\u4e8c\u4f4d\u987e\u5ba2\u7b49\u5f85\u65f6\u95f4\u4e3a 8 - 2 = 6 \u3002\n3) \u7b2c\u4e09\u4f4d\u987e\u5ba2\u5728\u65f6\u523b 4 \u5230\u8fbe\uff0c\u53a8\u5e08\u5728\u65f6\u523b 8 \u5f00\u59cb\u4e3a\u4ed6\u505a\u83dc\uff0c\u5e76\u5728\u65f6\u523b 11 \u5b8c\u6210\uff0c\u7b2c\u4e09\u4f4d\u987e\u5ba2\u7b49\u5f85\u65f6\u95f4\u4e3a 11 - 4 = 7 \u3002\n\u5e73\u5747\u7b49\u5f85\u65f6\u95f4\u4e3a (2 + 6 + 7) / 3 = 5 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1acustomers = [[5,2],[5,4],[10,3],[20,1]]\n\u8f93\u51fa\uff1a3.25000\n\u89e3\u91ca\uff1a\n1) \u7b2c\u4e00\u4f4d\u987e\u5ba2\u5728\u65f6\u523b 5 \u5230\u8fbe\uff0c\u53a8\u5e08\u62ff\u5230\u4ed6\u7684\u8ba2\u5355\u5e76\u5728\u65f6\u523b 5 \u7acb\u9a6c\u5f00\u59cb\u505a\u83dc\uff0c\u5e76\u5728\u65f6\u523b 7 \u5b8c\u6210\uff0c\u7b2c\u4e00\u4f4d\u987e\u5ba2\u7b49\u5f85\u65f6\u95f4\u4e3a 7 - 5 = 2 \u3002\n2) \u7b2c\u4e8c\u4f4d\u987e\u5ba2\u5728\u65f6\u523b 5 \u5230\u8fbe\uff0c\u53a8\u5e08\u5728\u65f6\u523b 7 \u5f00\u59cb\u4e3a\u4ed6\u505a\u83dc\uff0c\u5e76\u5728\u65f6\u523b 11 \u5b8c\u6210\uff0c\u7b2c\u4e8c\u4f4d\u987e\u5ba2\u7b49\u5f85\u65f6\u95f4\u4e3a 11 - 5 = 6 \u3002\n3) \u7b2c\u4e09\u4f4d\u987e\u5ba2\u5728\u65f6\u523b 10 \u5230\u8fbe\uff0c\u53a8\u5e08\u5728\u65f6\u523b 11 \u5f00\u59cb\u4e3a\u4ed6\u505a\u83dc\uff0c\u5e76\u5728\u65f6\u523b 14 \u5b8c\u6210\uff0c\u7b2c\u4e09\u4f4d\u987e\u5ba2\u7b49\u5f85\u65f6\u95f4\u4e3a 14 - 10 = 4 \u3002\n4) \u7b2c\u56db\u4f4d\u987e\u5ba2\u5728\u65f6\u523b 20 \u5230\u8fbe\uff0c\u53a8\u5e08\u62ff\u5230\u4ed6\u7684\u8ba2\u5355\u5e76\u5728\u65f6\u523b 20 \u7acb\u9a6c\u5f00\u59cb\u505a\u83dc\uff0c\u5e76\u5728\u65f6\u523b 21 \u5b8c\u6210\uff0c\u7b2c\u56db\u4f4d\u987e\u5ba2\u7b49\u5f85\u65f6\u95f4\u4e3a 21 - 20 = 1 \u3002\n\u5e73\u5747\u7b49\u5f85\u65f6\u95f4\u4e3a (2 + 6 + 4 + 1) / 4 = 3.25 \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= customers.length <= 105
  • \n\t
  • 1 <= arrivali, timei <= 104
  • \n\t
  • arrivali\u00a0<= arrivali+1
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n double averageWaitingTime(vector>& customers) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double averageWaitingTime(int[][] customers) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def averageWaitingTime(self, customers):\n \"\"\"\n :type customers: List[List[int]]\n :rtype: float\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def averageWaitingTime(self, customers: List[List[int]]) -> float:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\ndouble averageWaitingTime(int** customers, int customersSize, int* customersColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double AverageWaitingTime(int[][] customers) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} customers\n * @return {number}\n */\nvar averageWaitingTime = function(customers) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} customers\n# @return {Float}\ndef average_waiting_time(customers)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func averageWaitingTime(_ customers: [[Int]]) -> Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func averageWaitingTime(customers [][]int) float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def averageWaitingTime(customers: Array[Array[Int]]): Double = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun averageWaitingTime(customers: Array): Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn average_waiting_time(customers: Vec>) -> f64 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $customers\n * @return Float\n */\n function averageWaitingTime($customers) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function averageWaitingTime(customers: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (average-waiting-time customers)\n (-> (listof (listof exact-integer?)) flonum?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1701](https://leetcode-cn.com/problems/average-waiting-time)", "[\u5e73\u5747\u7b49\u5f85\u65f6\u95f4](/solution/1700-1799/1701.Average%20Waiting%20Time/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1701](https://leetcode.com/problems/average-waiting-time)", "[Average Waiting Time](/solution/1700-1799/1701.Average%20Waiting%20Time/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "1802", "frontend_question_id": "1700", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-students-unable-to-eat-lunch", "url_en": "https://leetcode.com/problems/number-of-students-unable-to-eat-lunch", "relative_path_cn": "/solution/1700-1799/1700.Number%20of%20Students%20Unable%20to%20Eat%20Lunch/README.md", "relative_path_en": "/solution/1700-1799/1700.Number%20of%20Students%20Unable%20to%20Eat%20Lunch/README_EN.md", "title_cn": "\u65e0\u6cd5\u5403\u5348\u9910\u7684\u5b66\u751f\u6570\u91cf", "title_en": "Number of Students Unable to Eat Lunch", "question_title_slug": "number-of-students-unable-to-eat-lunch", "content_en": "

The school cafeteria offers circular and square sandwiches at lunch break, referred to by numbers 0 and 1 respectively. All students stand in a queue. Each student either prefers square or circular sandwiches.

\n\n

The number of sandwiches in the cafeteria is equal to the number of students. The sandwiches are placed in a stack. At each step:

\n\n
    \n\t
  • If the student at the front of the queue prefers the sandwich on the top of the stack, they will take it and leave the queue.
  • \n\t
  • Otherwise, they will leave it and go to the queue's end.
  • \n
\n\n

This continues until none of the queue students want to take the top sandwich and are thus unable to eat.

\n\n

You are given two integer arrays students and sandwiches where sandwiches[i] is the type of the i\u200b\u200b\u200b\u200b\u200b\u200bth sandwich in the stack (i = 0 is the top of the stack) and students[j] is the preference of the j\u200b\u200b\u200b\u200b\u200b\u200bth student in the initial queue (j = 0 is the front of the queue). Return the number of students that are unable to eat.

\n\n

 

\n

Example 1:

\n\n
\nInput: students = [1,1,0,0], sandwiches = [0,1,0,1]\nOutput: 0 \nExplanation:\n- Front student leaves the top sandwich and returns to the end of the line making students = [1,0,0,1].\n- Front student leaves the top sandwich and returns to the end of the line making students = [0,0,1,1].\n- Front student takes the top sandwich and leaves the line making students = [0,1,1] and sandwiches = [1,0,1].\n- Front student leaves the top sandwich and returns to the end of the line making students = [1,1,0].\n- Front student takes the top sandwich and leaves the line making students = [1,0] and sandwiches = [0,1].\n- Front student leaves the top sandwich and returns to the end of the line making students = [0,1].\n- Front student takes the top sandwich and leaves the line making students = [1] and sandwiches = [1].\n- Front student takes the top sandwich and leaves the line making students = [] and sandwiches = [].\nHence all students are able to eat.\n
\n\n

Example 2:

\n\n
\nInput: students = [1,1,1,0,0,1], sandwiches = [1,0,0,0,1,1]\nOutput: 3\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= students.length, sandwiches.length <= 100
  • \n\t
  • students.length == sandwiches.length
  • \n\t
  • sandwiches[i] is 0 or 1.
  • \n\t
  • students[i] is 0 or 1.
  • \n
\n", "content_cn": "

\u5b66\u6821\u7684\u81ea\u52a9\u5348\u9910\u63d0\u4f9b\u5706\u5f62\u548c\u65b9\u5f62\u7684\u4e09\u660e\u6cbb\uff0c\u5206\u522b\u7528\u6570\u5b57\u00a00\u00a0\u548c\u00a01\u00a0\u8868\u793a\u3002\u6240\u6709\u5b66\u751f\u7ad9\u5728\u4e00\u4e2a\u961f\u5217\u91cc\uff0c\u6bcf\u4e2a\u5b66\u751f\u8981\u4e48\u559c\u6b22\u5706\u5f62\u7684\u8981\u4e48\u559c\u6b22\u65b9\u5f62\u7684\u3002
\n\u9910\u5385\u91cc\u4e09\u660e\u6cbb\u7684\u6570\u91cf\u4e0e\u5b66\u751f\u7684\u6570\u91cf\u76f8\u540c\u3002\u6240\u6709\u4e09\u660e\u6cbb\u90fd\u653e\u5728\u4e00\u4e2a\u00a0\u6808\u00a0\u91cc\uff0c\u6bcf\u4e00\u8f6e\uff1a

\n\n
    \n\t
  • \u5982\u679c\u961f\u5217\u6700\u524d\u9762\u7684\u5b66\u751f\u00a0\u559c\u6b22\u00a0\u6808\u9876\u7684\u4e09\u660e\u6cbb\uff0c\u90a3\u4e48\u4f1a\u00a0\u62ff\u8d70\u5b83\u00a0\u5e76\u79bb\u5f00\u961f\u5217\u3002
  • \n\t
  • \u5426\u5219\uff0c\u8fd9\u540d\u5b66\u751f\u4f1a\u00a0\u653e\u5f03\u8fd9\u4e2a\u4e09\u660e\u6cbb\u00a0\u5e76\u56de\u5230\u961f\u5217\u7684\u5c3e\u90e8\u3002
  • \n
\n\n

\u8fd9\u4e2a\u8fc7\u7a0b\u4f1a\u4e00\u76f4\u6301\u7eed\u5230\u961f\u5217\u91cc\u6240\u6709\u5b66\u751f\u90fd\u4e0d\u559c\u6b22\u6808\u9876\u7684\u4e09\u660e\u6cbb\u4e3a\u6b62\u3002

\n\n

\u7ed9\u4f60\u4e24\u4e2a\u6574\u6570\u6570\u7ec4\u00a0students \u548c\u00a0sandwiches\u00a0\uff0c\u5176\u4e2d\u00a0sandwiches[i]\u00a0\u662f\u6808\u91cc\u9762\u7b2c\u00a0i\u200b\u200b\u200b\u200b\u200b\u200b\u00a0\u4e2a\u4e09\u660e\u6cbb\u7684\u7c7b\u578b\uff08i = 0\u00a0\u662f\u6808\u7684\u9876\u90e8\uff09\uff0c\u00a0students[j]\u00a0\u662f\u521d\u59cb\u961f\u5217\u91cc\u7b2c\u00a0j\u200b\u200b\u200b\u200b\u200b\u200b\u00a0\u540d\u5b66\u751f\u5bf9\u4e09\u660e\u6cbb\u7684\u559c\u597d\uff08j = 0\u00a0\u662f\u961f\u5217\u7684\u6700\u5f00\u59cb\u4f4d\u7f6e\uff09\u3002\u8bf7\u4f60\u8fd4\u56de\u65e0\u6cd5\u5403\u5348\u9910\u7684\u5b66\u751f\u6570\u91cf\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1astudents = [1,1,0,0], sandwiches = [0,1,0,1]\n\u8f93\u51fa\uff1a0 \n\u89e3\u91ca\uff1a\n- \u6700\u524d\u9762\u7684\u5b66\u751f\u653e\u5f03\u6700\u9876\u4e0a\u7684\u4e09\u660e\u6cbb\uff0c\u5e76\u56de\u5230\u961f\u5217\u7684\u672b\u5c3e\uff0c\u5b66\u751f\u961f\u5217\u53d8\u4e3a students = [1,0,0,1]\u3002\n- \u6700\u524d\u9762\u7684\u5b66\u751f\u653e\u5f03\u6700\u9876\u4e0a\u7684\u4e09\u660e\u6cbb\uff0c\u5e76\u56de\u5230\u961f\u5217\u7684\u672b\u5c3e\uff0c\u5b66\u751f\u961f\u5217\u53d8\u4e3a students = [0,0,1,1]\u3002\n- \u6700\u524d\u9762\u7684\u5b66\u751f\u62ff\u8d70\u6700\u9876\u4e0a\u7684\u4e09\u660e\u6cbb\uff0c\u5269\u4f59\u5b66\u751f\u961f\u5217\u4e3a students = [0,1,1]\uff0c\u4e09\u660e\u6cbb\u6808\u4e3a sandwiches = [1,0,1]\u3002\n- \u6700\u524d\u9762\u7684\u5b66\u751f\u653e\u5f03\u6700\u9876\u4e0a\u7684\u4e09\u660e\u6cbb\uff0c\u5e76\u56de\u5230\u961f\u5217\u7684\u672b\u5c3e\uff0c\u5b66\u751f\u961f\u5217\u53d8\u4e3a students = [1,1,0]\u3002\n- \u6700\u524d\u9762\u7684\u5b66\u751f\u62ff\u8d70\u6700\u9876\u4e0a\u7684\u4e09\u660e\u6cbb\uff0c\u5269\u4f59\u5b66\u751f\u961f\u5217\u4e3a students = [1,0]\uff0c\u4e09\u660e\u6cbb\u6808\u4e3a sandwiches = [0,1]\u3002\n- \u6700\u524d\u9762\u7684\u5b66\u751f\u653e\u5f03\u6700\u9876\u4e0a\u7684\u4e09\u660e\u6cbb\uff0c\u5e76\u56de\u5230\u961f\u5217\u7684\u672b\u5c3e\uff0c\u5b66\u751f\u961f\u5217\u53d8\u4e3a students = [0,1]\u3002\n- \u6700\u524d\u9762\u7684\u5b66\u751f\u62ff\u8d70\u6700\u9876\u4e0a\u7684\u4e09\u660e\u6cbb\uff0c\u5269\u4f59\u5b66\u751f\u961f\u5217\u4e3a students = [1]\uff0c\u4e09\u660e\u6cbb\u6808\u4e3a sandwiches = [1]\u3002\n- \u6700\u524d\u9762\u7684\u5b66\u751f\u62ff\u8d70\u6700\u9876\u4e0a\u7684\u4e09\u660e\u6cbb\uff0c\u5269\u4f59\u5b66\u751f\u961f\u5217\u4e3a students = []\uff0c\u4e09\u660e\u6cbb\u6808\u4e3a sandwiches = []\u3002\n\u6240\u4ee5\u6240\u6709\u5b66\u751f\u90fd\u6709\u4e09\u660e\u6cbb\u5403\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1astudents = [1,1,1,0,0,1], sandwiches = [1,0,0,0,1,1]\n\u8f93\u51fa\uff1a3\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= students.length, sandwiches.length <= 100
  • \n\t
  • students.length == sandwiches.length
  • \n\t
  • sandwiches[i]\u00a0\u8981\u4e48\u662f\u00a00\u00a0\uff0c\u8981\u4e48\u662f\u00a01\u00a0\u3002
  • \n\t
  • students[i]\u00a0\u8981\u4e48\u662f\u00a00\u00a0\uff0c\u8981\u4e48\u662f\u00a01\u00a0\u3002
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countStudents(vector& students, vector& sandwiches) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countStudents(int[] students, int[] sandwiches) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countStudents(self, students, sandwiches):\n \"\"\"\n :type students: List[int]\n :type sandwiches: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countStudents(self, students: List[int], sandwiches: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countStudents(int* students, int studentsSize, int* sandwiches, int sandwichesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountStudents(int[] students, int[] sandwiches) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} students\n * @param {number[]} sandwiches\n * @return {number}\n */\nvar countStudents = function(students, sandwiches) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} students\n# @param {Integer[]} sandwiches\n# @return {Integer}\ndef count_students(students, sandwiches)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countStudents(_ students: [Int], _ sandwiches: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countStudents(students []int, sandwiches []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countStudents(students: Array[Int], sandwiches: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countStudents(students: IntArray, sandwiches: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_students(students: Vec, sandwiches: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $students\n * @param Integer[] $sandwiches\n * @return Integer\n */\n function countStudents($students, $sandwiches) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countStudents(students: number[], sandwiches: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-students students sandwiches)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1700](https://leetcode-cn.com/problems/number-of-students-unable-to-eat-lunch)", "[\u65e0\u6cd5\u5403\u5348\u9910\u7684\u5b66\u751f\u6570\u91cf](/solution/1700-1799/1700.Number%20of%20Students%20Unable%20to%20Eat%20Lunch/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1700](https://leetcode.com/problems/number-of-students-unable-to-eat-lunch)", "[Number of Students Unable to Eat Lunch](/solution/1700-1799/1700.Number%20of%20Students%20Unable%20to%20Eat%20Lunch/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1801", "frontend_question_id": "1661", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/average-time-of-process-per-machine", "url_en": "https://leetcode.com/problems/average-time-of-process-per-machine", "relative_path_cn": "/solution/1600-1699/1661.Average%20Time%20of%20Process%20per%20Machine/README.md", "relative_path_en": "/solution/1600-1699/1661.Average%20Time%20of%20Process%20per%20Machine/README_EN.md", "title_cn": "\u6bcf\u53f0\u673a\u5668\u7684\u8fdb\u7a0b\u5e73\u5747\u8fd0\u884c\u65f6\u95f4", "title_en": "Average Time of Process per Machine", "question_title_slug": "average-time-of-process-per-machine", "content_en": "

Table: Activity

\n\n
\n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| machine_id     | int     |\n| process_id     | int     |\n| activity_type  | enum    |\n| timestamp      | float   |\n+----------------+---------+\nThe table shows the user activities for a factory website.\n(machine_id, process_id, activity_type) is the primary key of this table.\nmachine_id is the ID of a machine.\nprocess_id is the ID of a process running on the machine with ID machine_id.\nactivity_type is an ENUM of type ('start', 'end').\ntimestamp is a float representing the current time in seconds.\n'start' means the machine starts the process at the given timestamp and 'end' means the machine ends the process at the given timestamp.\nThe 'start' timestamp will always be before the 'end' timestamp for every (machine_id, process_id) pair.
\n\n

 

\n\n

There is a factory website that has several machines each running the same number of processes. Write an SQL query to find the average time each machine takes to complete a process.

\n\n

The time to complete a process is the 'end' timestamp minus the 'start' timestamp. The average time is calculated by the total time to complete every process on the machine divided by the number of processes that were run.

\n\n

The resulting table should have the machine_id along with the average time as processing_time, which should be rounded to 3 decimal places.

\n\n

The query result format is in the following example:

\n\n

 

\n\n
\nActivity table:\n+------------+------------+---------------+-----------+\n| machine_id | process_id | activity_type | timestamp |\n+------------+------------+---------------+-----------+\n| 0          | 0          | start         | 0.712     |\n| 0          | 0          | end           | 1.520     |\n| 0          | 1          | start         | 3.140     |\n| 0          | 1          | end           | 4.120     |\n| 1          | 0          | start         | 0.550     |\n| 1          | 0          | end           | 1.550     |\n| 1          | 1          | start         | 0.430     |\n| 1          | 1          | end           | 1.420     |\n| 2          | 0          | start         | 4.100     |\n| 2          | 0          | end           | 4.512     |\n| 2          | 1          | start         | 2.500     |\n| 2          | 1          | end           | 5.000     |\n+------------+------------+---------------+-----------+\n\nResult table:\n+------------+-----------------+\n| machine_id | processing_time |\n+------------+-----------------+\n| 0          | 0.894           |\n| 1          | 0.995           |\n| 2          | 1.456           |\n+------------+-----------------+\n\nThere are 3 machines running 2 processes each.\nMachine 0's average time is ((1.520 - 0.712) + (4.120 - 3.140)) / 2 = 0.894\nMachine 1's average time is ((1.550 - 0.550) + (1.420 - 0.430)) / 2 = 0.995\nMachine 2's average time is ((4.512 - 4.100) + (5.000 - 2.500)) / 2 = 1.456\n
\n", "content_cn": "

\u8868: Activity

\n\n
+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| machine_id     | int     |\n| process_id     | int     |\n| activity_type  | enum    |\n| timestamp      | float   |\n+----------------+---------+\n\u8be5\u8868\u5c55\u793a\u4e86\u4e00\u5bb6\u5de5\u5382\u7f51\u7ad9\u7684\u7528\u6237\u6d3b\u52a8.\n(machine_id, process_id, activity_type) \u662f\u5f53\u524d\u8868\u7684\u4e3b\u952e.\nmachine_id \u662f\u4e00\u53f0\u673a\u5668\u7684ID\u53f7.\nprocess_id \u662f\u8fd0\u884c\u5728\u5404\u673a\u5668\u4e0a\u7684\u8fdb\u7a0bID\u53f7.\nactivity_type \u662f\u679a\u4e3e\u7c7b\u578b ('start', 'end').\ntimestamp \u662f\u6d6e\u70b9\u7c7b\u578b,\u4ee3\u8868\u5f53\u524d\u65f6\u95f4(\u4ee5\u79d2\u4e3a\u5355\u4f4d).\n'start' \u4ee3\u8868\u8be5\u8fdb\u7a0b\u5728\u8fd9\u53f0\u673a\u5668\u4e0a\u7684\u5f00\u59cb\u8fd0\u884c\u65f6\u95f4\u6233 , 'end' \u4ee3\u8868\u8be5\u8fdb\u7a0b\u5728\u8fd9\u53f0\u673a\u5668\u4e0a\u7684\u7ec8\u6b62\u8fd0\u884c\u65f6\u95f4\u6233.\n\u540c\u4e00\u53f0\u673a\u5668\uff0c\u540c\u4e00\u4e2a\u8fdb\u7a0b\u90fd\u6709\u4e00\u5bf9\u5f00\u59cb\u65f6\u95f4\u6233\u548c\u7ed3\u675f\u65f6\u95f4\u6233\uff0c\u800c\u4e14\u5f00\u59cb\u65f6\u95f4\u6233\u6c38\u8fdc\u5728\u7ed3\u675f\u65f6\u95f4\u6233\u524d\u9762.
\n\n

\u00a0

\n\n

\u73b0\u5728\u6709\u4e00\u4e2a\u5de5\u5382\u7f51\u7ad9\u7531\u51e0\u53f0\u673a\u5668\u8fd0\u884c\uff0c\u6bcf\u53f0\u673a\u5668\u4e0a\u8fd0\u884c\u7740\u76f8\u540c\u6570\u91cf\u7684\u8fdb\u7a0b. \u8bf7\u5199\u51fa\u4e00\u6761SQL\u8ba1\u7b97\u6bcf\u53f0\u673a\u5668\u5404\u81ea\u5b8c\u6210\u4e00\u4e2a\u8fdb\u7a0b\u4efb\u52a1\u7684\u5e73\u5747\u8017\u65f6.

\n\n

\u5b8c\u6210\u4e00\u4e2a\u8fdb\u7a0b\u4efb\u52a1\u7684\u65f6\u95f4\u6307\u8fdb\u7a0b\u7684'end' \u65f6\u95f4\u6233 \u51cf\u53bb\u00a0'start' \u65f6\u95f4\u6233. \u5e73\u5747\u8017\u65f6\u901a\u8fc7\u8ba1\u7b97\u6bcf\u53f0\u673a\u5668\u4e0a\u6240\u6709\u8fdb\u7a0b\u4efb\u52a1\u7684\u603b\u8017\u8d39\u65f6\u95f4\u9664\u4ee5\u673a\u5668\u4e0a\u7684\u603b\u8fdb\u7a0b\u6570\u91cf\u83b7\u5f97.

\n\n

\u7ed3\u679c\u8868\u5fc5\u987b\u5305\u542bmachine_id\uff08\u673a\u5668ID\uff09 \u548c\u5bf9\u5e94\u7684\u00a0average time\uff08\u5e73\u5747\u8017\u65f6\uff09\u00a0\u522b\u540d\u00a0processing_time, \u4e14\u56db\u820d\u4e94\u5165\u4fdd\u75593\u4f4d\u5c0f\u6570.

\n\n

\u5177\u4f53\u53c2\u8003\u4f8b\u5b50\u5982\u4e0b:

\n\n

\u00a0

\n\n
Activity table:\n+------------+------------+---------------+-----------+\n| machine_id | process_id | activity_type | timestamp |\n+------------+------------+---------------+-----------+\n| 0          | 0          | start         | 0.712     |\n| 0          | 0          | end           | 1.520     |\n| 0          | 1          | start         | 3.140     |\n| 0          | 1          | end           | 4.120     |\n| 1          | 0          | start         | 0.550     |\n| 1          | 0          | end           | 1.550     |\n| 1          | 1          | start         | 0.430     |\n| 1          | 1          | end           | 1.420     |\n| 2          | 0          | start         | 4.100     |\n| 2          | 0          | end           | 4.512     |\n| 2          | 1          | start         | 2.500     |\n| 2          | 1          | end           | 5.000     |\n+------------+------------+---------------+-----------+\n\nResult table:\n+------------+-----------------+\n| machine_id | processing_time |\n+------------+-----------------+\n| 0          | 0.894           |\n| 1          | 0.995           |\n| 2          | 1.456           |\n+------------+-----------------+\n\n\u4e00\u5171\u67093\u53f0\u673a\u5668,\u6bcf\u53f0\u673a\u5668\u8fd0\u884c\u7740\u4e24\u4e2a\u8fdb\u7a0b.\n\u673a\u5668 0 \u7684\u5e73\u5747\u8017\u65f6: ((1.520 - 0.712) + (4.120 - 3.140)) / 2 = 0.894\n\u673a\u5668 1 \u7684\u5e73\u5747\u8017\u65f6: ((1.550 - 0.550) + (1.420 - 0.430)) / 2 = 0.995\n\u673a\u5668 2 \u7684\u5e73\u5747\u8017\u65f6: ((4.512 - 4.100) + (5.000 - 2.500)) / 2 = 1.456\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1661](https://leetcode-cn.com/problems/average-time-of-process-per-machine)", "[\u6bcf\u53f0\u673a\u5668\u7684\u8fdb\u7a0b\u5e73\u5747\u8fd0\u884c\u65f6\u95f4](/solution/1600-1699/1661.Average%20Time%20of%20Process%20per%20Machine/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1661](https://leetcode.com/problems/average-time-of-process-per-machine)", "[Average Time of Process per Machine](/solution/1600-1699/1661.Average%20Time%20of%20Process%20per%20Machine/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1800", "frontend_question_id": "1680", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/concatenation-of-consecutive-binary-numbers", "url_en": "https://leetcode.com/problems/concatenation-of-consecutive-binary-numbers", "relative_path_cn": "/solution/1600-1699/1680.Concatenation%20of%20Consecutive%20Binary%20Numbers/README.md", "relative_path_en": "/solution/1600-1699/1680.Concatenation%20of%20Consecutive%20Binary%20Numbers/README_EN.md", "title_cn": "\u8fde\u63a5\u8fde\u7eed\u4e8c\u8fdb\u5236\u6570\u5b57", "title_en": "Concatenation of Consecutive Binary Numbers", "question_title_slug": "concatenation-of-consecutive-binary-numbers", "content_en": "

Given an integer n, return the decimal value of the binary string formed by concatenating the binary representations of 1 to n in order, modulo 109 + 7.

\n\n

 

\n

Example 1:

\n\n
\nInput: n = 1\nOutput: 1\nExplanation: "1" in binary corresponds to the decimal value 1. \n
\n\n

Example 2:

\n\n
\nInput: n = 3\nOutput: 27\nExplanation: In binary, 1, 2, and 3 corresponds to "1", "10", and "11".\nAfter concatenating them, we have "11011", which corresponds to the decimal value 27.\n
\n\n

Example 3:

\n\n
\nInput: n = 12\nOutput: 505379714\nExplanation: The concatenation results in "1101110010111011110001001101010111100".\nThe decimal value of that is 118505380540.\nAfter modulo 109 + 7, the result is 505379714.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 105
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u00a0n\u00a0\uff0c\u8bf7\u4f60\u5c06\u00a01\u00a0\u5230 n\u00a0\u7684\u4e8c\u8fdb\u5236\u8868\u793a\u8fde\u63a5\u8d77\u6765\uff0c\u5e76\u8fd4\u56de\u8fde\u63a5\u7ed3\u679c\u5bf9\u5e94\u7684 \u5341\u8fdb\u5236\u00a0\u6570\u5b57\u5bf9 109\u00a0+ 7\u00a0\u53d6\u4f59\u7684\u7ed3\u679c\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u4e8c\u8fdb\u5236\u7684 \"1\" \u5bf9\u5e94\u7740\u5341\u8fdb\u5236\u7684 1 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1an = 3\n\u8f93\u51fa\uff1a27\n\u89e3\u91ca\uff1a\u4e8c\u8fdb\u5236\u4e0b\uff0c1\uff0c2 \u548c 3 \u5206\u522b\u5bf9\u5e94 \"1\" \uff0c\"10\" \u548c \"11\" \u3002\n\u5c06\u5b83\u4eec\u4f9d\u6b21\u8fde\u63a5\uff0c\u6211\u4eec\u5f97\u5230 \"11011\" \uff0c\u5bf9\u5e94\u7740\u5341\u8fdb\u5236\u7684 27 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1an = 12\n\u8f93\u51fa\uff1a505379714\n\u89e3\u91ca\uff1a\u8fde\u63a5\u7ed3\u679c\u4e3a \"1101110010111011110001001101010111100\" \u3002\n\u5bf9\u5e94\u7684\u5341\u8fdb\u5236\u6570\u5b57\u4e3a 118505380540 \u3002\n\u5bf9 109 + 7 \u53d6\u4f59\u540e\uff0c\u7ed3\u679c\u4e3a 505379714 \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 105
  • \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int concatenatedBinary(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int concatenatedBinary(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def concatenatedBinary(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def concatenatedBinary(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint concatenatedBinary(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ConcatenatedBinary(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar concatenatedBinary = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef concatenated_binary(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func concatenatedBinary(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func concatenatedBinary(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def concatenatedBinary(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun concatenatedBinary(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn concatenated_binary(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function concatenatedBinary($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function concatenatedBinary(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (concatenated-binary n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1680](https://leetcode-cn.com/problems/concatenation-of-consecutive-binary-numbers)", "[\u8fde\u63a5\u8fde\u7eed\u4e8c\u8fdb\u5236\u6570\u5b57](/solution/1600-1699/1680.Concatenation%20of%20Consecutive%20Binary%20Numbers/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1680](https://leetcode.com/problems/concatenation-of-consecutive-binary-numbers)", "[Concatenation of Consecutive Binary Numbers](/solution/1600-1699/1680.Concatenation%20of%20Consecutive%20Binary%20Numbers/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "1799", "frontend_question_id": "1681", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-incompatibility", "url_en": "https://leetcode.com/problems/minimum-incompatibility", "relative_path_cn": "/solution/1600-1699/1681.Minimum%20Incompatibility/README.md", "relative_path_en": "/solution/1600-1699/1681.Minimum%20Incompatibility/README_EN.md", "title_cn": "\u6700\u5c0f\u4e0d\u517c\u5bb9\u6027", "title_en": "Minimum Incompatibility", "question_title_slug": "minimum-incompatibility", "content_en": "

You are given an integer array nums\u200b\u200b\u200b and an integer k. You are asked to distribute this array into k subsets of equal size such that there are no two equal elements in the same subset.

\n\n

A subset's incompatibility is the difference between the maximum and minimum elements in that array.

\n\n

Return the minimum possible sum of incompatibilities of the k subsets after distributing the array optimally, or return -1 if it is not possible.

\n\n

A subset is a group integers that appear in the array with no particular order.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [1,2,1,4], k = 2\nOutput: 4\nExplanation: The optimal distribution of subsets is [1,2] and [1,4].\nThe incompatibility is (2-1) + (4-1) = 4.\nNote that [1,1] and [2,4] would result in a smaller sum, but the first subset contains 2 equal elements.
\n\n

Example 2:

\n\n
\nInput: nums = [6,3,8,1,3,1,2,2], k = 4\nOutput: 6\nExplanation: The optimal distribution of subsets is [1,2], [2,3], [6,8], and [1,3].\nThe incompatibility is (2-1) + (3-2) + (8-6) + (3-1) = 6.\n
\n\n

Example 3:

\n\n
\nInput: nums = [5,3,3,6,3,3], k = 3\nOutput: -1\nExplanation: It is impossible to distribute nums into 3 subsets where no two elements are equal in the same subset.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= k <= nums.length <= 16
  • \n\t
  • nums.length is divisible by k
  • \n\t
  • 1 <= nums[i] <= nums.length
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0nums\u200b\u200b\u200b \u548c\u4e00\u4e2a\u6574\u6570\u00a0k\u00a0\u3002\u4f60\u9700\u8981\u5c06\u8fd9\u4e2a\u6570\u7ec4\u5212\u5206\u5230\u00a0k\u00a0\u4e2a\u76f8\u540c\u5927\u5c0f\u7684\u5b50\u96c6\u4e2d\uff0c\u4f7f\u5f97\u540c\u4e00\u4e2a\u5b50\u96c6\u91cc\u9762\u6ca1\u6709\u4e24\u4e2a\u76f8\u540c\u7684\u5143\u7d20\u3002

\n\n

\u4e00\u4e2a\u5b50\u96c6\u7684 \u4e0d\u517c\u5bb9\u6027\u00a0\u662f\u8be5\u5b50\u96c6\u91cc\u9762\u6700\u5927\u503c\u548c\u6700\u5c0f\u503c\u7684\u5dee\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u5c06\u6570\u7ec4\u5206\u6210 k\u00a0\u4e2a\u5b50\u96c6\u540e\uff0c\u5404\u5b50\u96c6 \u4e0d\u517c\u5bb9\u6027 \u7684 \u548c\u00a0\u7684 \u6700\u5c0f\u503c\u00a0\uff0c\u5982\u679c\u65e0\u6cd5\u5206\u6210\u5206\u6210 k\u00a0\u4e2a\u5b50\u96c6\uff0c\u8fd4\u56de -1\u00a0\u3002

\n\n

\u5b50\u96c6\u7684\u5b9a\u4e49\u662f\u6570\u7ec4\u4e2d\u4e00\u4e9b\u6570\u5b57\u7684\u96c6\u5408\uff0c\u5bf9\u6570\u5b57\u987a\u5e8f\u6ca1\u6709\u8981\u6c42\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [1,2,1,4], k = 2\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u6700\u4f18\u7684\u5206\u914d\u662f [1,2] \u548c [1,4] \u3002\n\u4e0d\u517c\u5bb9\u6027\u548c\u4e3a (2-1) + (4-1) = 4 \u3002\n\u6ce8\u610f\u5230 [1,1] \u548c [2,4] \u53ef\u4ee5\u5f97\u5230\u66f4\u5c0f\u7684\u548c\uff0c\u4f46\u662f\u7b2c\u4e00\u4e2a\u96c6\u5408\u6709 2 \u4e2a\u76f8\u540c\u7684\u5143\u7d20\uff0c\u6240\u4ee5\u4e0d\u53ef\u884c\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [6,3,8,1,3,1,2,2], k = 4\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u6700\u4f18\u7684\u5b50\u96c6\u5206\u914d\u4e3a [1,2]\uff0c[2,3]\uff0c[6,8] \u548c [1,3] \u3002\n\u4e0d\u517c\u5bb9\u6027\u548c\u4e3a (2-1) + (3-2) + (8-6) + (3-1) = 6 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [5,3,3,6,3,3], k = 3\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u6ca1\u529e\u6cd5\u5c06\u8fd9\u4e9b\u6570\u5b57\u5206\u914d\u5230 3 \u4e2a\u5b50\u96c6\u4e14\u6ee1\u8db3\u6bcf\u4e2a\u5b50\u96c6\u91cc\u6ca1\u6709\u76f8\u540c\u6570\u5b57\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= k <= nums.length <= 16
  • \n\t
  • nums.length \u80fd\u88ab\u00a0k \u6574\u9664\u3002
  • \n\t
  • 1 <= nums[i] <= nums.length
  • \n
\n", "tags_en": ["Greedy", "Backtracking"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minimumIncompatibility(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minimumIncompatibility(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimumIncompatibility(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimumIncompatibility(self, nums: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minimumIncompatibility(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinimumIncompatibility(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar minimumIncompatibility = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef minimum_incompatibility(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimumIncompatibility(_ nums: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimumIncompatibility(nums []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimumIncompatibility(nums: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimumIncompatibility(nums: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimum_incompatibility(nums: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer\n */\n function minimumIncompatibility($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimumIncompatibility(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimum-incompatibility nums k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1681](https://leetcode-cn.com/problems/minimum-incompatibility)", "[\u6700\u5c0f\u4e0d\u517c\u5bb9\u6027](/solution/1600-1699/1681.Minimum%20Incompatibility/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u56de\u6eaf\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[1681](https://leetcode.com/problems/minimum-incompatibility)", "[Minimum Incompatibility](/solution/1600-1699/1681.Minimum%20Incompatibility/README_EN.md)", "`Greedy`,`Backtracking`", "Hard", ""]}, {"question_id": "1798", "frontend_question_id": "1679", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/max-number-of-k-sum-pairs", "url_en": "https://leetcode.com/problems/max-number-of-k-sum-pairs", "relative_path_cn": "/solution/1600-1699/1679.Max%20Number%20of%20K-Sum%20Pairs/README.md", "relative_path_en": "/solution/1600-1699/1679.Max%20Number%20of%20K-Sum%20Pairs/README_EN.md", "title_cn": "K \u548c\u6570\u5bf9\u7684\u6700\u5927\u6570\u76ee", "title_en": "Max Number of K-Sum Pairs", "question_title_slug": "max-number-of-k-sum-pairs", "content_en": "

You are given an integer array nums and an integer k.

\n\n

In one operation, you can pick two numbers from the array whose sum equals k and remove them from the array.

\n\n

Return the maximum number of operations you can perform on the array.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [1,2,3,4], k = 5\nOutput: 2\nExplanation: Starting with nums = [1,2,3,4]:\n- Remove numbers 1 and 4, then nums = [2,3]\n- Remove numbers 2 and 3, then nums = []\nThere are no more pairs that sum up to 5, hence a total of 2 operations.
\n\n

Example 2:

\n\n
\nInput: nums = [3,1,3,4,3], k = 6\nOutput: 1\nExplanation: Starting with nums = [3,1,3,4,3]:\n- Remove the first two 3's, then nums = [1,4,3]\nThere are no more pairs that sum up to 6, hence a total of 1 operation.
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 105
  • \n\t
  • 1 <= nums[i] <= 109
  • \n\t
  • 1 <= k <= 109
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \u548c\u4e00\u4e2a\u6574\u6570 k \u3002

\n\n

\u6bcf\u4e00\u6b65\u64cd\u4f5c\u4e2d\uff0c\u4f60\u9700\u8981\u4ece\u6570\u7ec4\u4e2d\u9009\u51fa\u548c\u4e3a k \u7684\u4e24\u4e2a\u6574\u6570\uff0c\u5e76\u5c06\u5b83\u4eec\u79fb\u51fa\u6570\u7ec4\u3002

\n\n

\u8fd4\u56de\u4f60\u53ef\u4ee5\u5bf9\u6570\u7ec4\u6267\u884c\u7684\u6700\u5927\u64cd\u4f5c\u6570\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [1,2,3,4], k = 5\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5f00\u59cb\u65f6 nums = [1,2,3,4]\uff1a\n- \u79fb\u51fa 1 \u548c 4 \uff0c\u4e4b\u540e nums = [2,3]\n- \u79fb\u51fa 2 \u548c 3 \uff0c\u4e4b\u540e nums = []\n\u4e0d\u518d\u6709\u548c\u4e3a 5 \u7684\u6570\u5bf9\uff0c\u56e0\u6b64\u6700\u591a\u6267\u884c 2 \u6b21\u64cd\u4f5c\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [3,1,3,4,3], k = 6\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u5f00\u59cb\u65f6 nums = [3,1,3,4,3]\uff1a\n- \u79fb\u51fa\u524d\u4e24\u4e2a 3 \uff0c\u4e4b\u540enums = [1,4,3]\n\u4e0d\u518d\u6709\u548c\u4e3a 6 \u7684\u6570\u5bf9\uff0c\u56e0\u6b64\u6700\u591a\u6267\u884c 1 \u6b21\u64cd\u4f5c\u3002
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 105
  • \n\t
  • 1 <= nums[i] <= 109
  • \n\t
  • 1 <= k <= 109
  • \n
\n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxOperations(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxOperations(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxOperations(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxOperations(self, nums: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxOperations(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxOperations(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar maxOperations = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef max_operations(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxOperations(_ nums: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxOperations(nums []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxOperations(nums: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxOperations(nums: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_operations(nums: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer\n */\n function maxOperations($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxOperations(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-operations nums k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1679](https://leetcode-cn.com/problems/max-number-of-k-sum-pairs)", "[K \u548c\u6570\u5bf9\u7684\u6700\u5927\u6570\u76ee](/solution/1600-1699/1679.Max%20Number%20of%20K-Sum%20Pairs/README.md)", "`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1679](https://leetcode.com/problems/max-number-of-k-sum-pairs)", "[Max Number of K-Sum Pairs](/solution/1600-1699/1679.Max%20Number%20of%20K-Sum%20Pairs/README_EN.md)", "`Hash Table`", "Medium", ""]}, {"question_id": "1797", "frontend_question_id": "1678", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/goal-parser-interpretation", "url_en": "https://leetcode.com/problems/goal-parser-interpretation", "relative_path_cn": "/solution/1600-1699/1678.Goal%20Parser%20Interpretation/README.md", "relative_path_en": "/solution/1600-1699/1678.Goal%20Parser%20Interpretation/README_EN.md", "title_cn": "\u8bbe\u8ba1 Goal \u89e3\u6790\u5668", "title_en": "Goal Parser Interpretation", "question_title_slug": "goal-parser-interpretation", "content_en": "

You own a Goal Parser that can interpret a string command. The command consists of an alphabet of "G", "()" and/or "(al)" in some order. The Goal Parser will interpret "G" as the string "G", "()" as the string "o", and "(al)" as the string "al". The interpreted strings are then concatenated in the original order.

\n\n

Given the string command, return the Goal Parser's interpretation of command.

\n\n

 

\n

Example 1:

\n\n
\nInput: command = "G()(al)"\nOutput: "Goal"\nExplanation: The Goal Parser interprets the command as follows:\nG -> G\n() -> o\n(al) -> al\nThe final concatenated result is "Goal".\n
\n\n

Example 2:

\n\n
\nInput: command = "G()()()()(al)"\nOutput: "Gooooal"\n
\n\n

Example 3:

\n\n
\nInput: command = "(al)G(al)()()G"\nOutput: "alGalooG"\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= command.length <= 100
  • \n\t
  • command consists of "G", "()", and/or "(al)" in some order.
  • \n
\n", "content_cn": "

\u8bf7\u4f60\u8bbe\u8ba1\u4e00\u4e2a\u53ef\u4ee5\u89e3\u91ca\u5b57\u7b26\u4e32 command \u7684 Goal \u89e3\u6790\u5668 \u3002command \u7531 \"G\"\u3001\"()\" \u548c/\u6216 \"(al)\" \u6309\u67d0\u79cd\u987a\u5e8f\u7ec4\u6210\u3002Goal \u89e3\u6790\u5668\u4f1a\u5c06 \"G\" \u89e3\u91ca\u4e3a\u5b57\u7b26\u4e32 \"G\"\u3001\"()\" \u89e3\u91ca\u4e3a\u5b57\u7b26\u4e32 \"o\" \uff0c\"(al)\" \u89e3\u91ca\u4e3a\u5b57\u7b26\u4e32 \"al\" \u3002\u7136\u540e\uff0c\u6309\u539f\u987a\u5e8f\u5c06\u7ecf\u89e3\u91ca\u5f97\u5230\u7684\u5b57\u7b26\u4e32\u8fde\u63a5\u6210\u4e00\u4e2a\u5b57\u7b26\u4e32\u3002

\n\n

\u7ed9\u4f60\u5b57\u7b26\u4e32 command \uff0c\u8fd4\u56de Goal \u89e3\u6790\u5668 \u5bf9 command \u7684\u89e3\u91ca\u7ed3\u679c\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1acommand = \"G()(al)\"\n\u8f93\u51fa\uff1a\"Goal\"\n\u89e3\u91ca\uff1aGoal \u89e3\u6790\u5668\u89e3\u91ca\u547d\u4ee4\u7684\u6b65\u9aa4\u5982\u4e0b\u6240\u793a\uff1a\nG -> G\n() -> o\n(al) -> al\n\u6700\u540e\u8fde\u63a5\u5f97\u5230\u7684\u7ed3\u679c\u662f \"Goal\"\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1acommand = \"G()()()()(al)\"\n\u8f93\u51fa\uff1a\"Gooooal\"\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1acommand = \"(al)G(al)()()G\"\n\u8f93\u51fa\uff1a\"alGalooG\"\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= command.length <= 100
  • \n\t
  • command \u7531 \"G\"\u3001\"()\" \u548c/\u6216 \"(al)\" \u6309\u67d0\u79cd\u987a\u5e8f\u7ec4\u6210
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string interpret(string command) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String interpret(String command) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def interpret(self, command):\n \"\"\"\n :type command: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def interpret(self, command: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * interpret(char * command){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string Interpret(string command) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} command\n * @return {string}\n */\nvar interpret = function(command) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} command\n# @return {String}\ndef interpret(command)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func interpret(_ command: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func interpret(command string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def interpret(command: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun interpret(command: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn interpret(command: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $command\n * @return String\n */\n function interpret($command) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function interpret(command: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (interpret command)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1678](https://leetcode-cn.com/problems/goal-parser-interpretation)", "[\u8bbe\u8ba1 Goal \u89e3\u6790\u5668](/solution/1600-1699/1678.Goal%20Parser%20Interpretation/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1678](https://leetcode.com/problems/goal-parser-interpretation)", "[Goal Parser Interpretation](/solution/1600-1699/1678.Goal%20Parser%20Interpretation/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1796", "frontend_question_id": "1660", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/correct-a-binary-tree", "url_en": "https://leetcode.com/problems/correct-a-binary-tree", "relative_path_cn": "/solution/1600-1699/1660.Correct%20a%20Binary%20Tree/README.md", "relative_path_en": "/solution/1600-1699/1660.Correct%20a%20Binary%20Tree/README_EN.md", "title_cn": "\u7ea0\u6b63\u4e8c\u53c9\u6811", "title_en": "Correct a Binary Tree", "question_title_slug": "correct-a-binary-tree", "content_en": "

You have a binary tree with a small defect. There is exactly one invalid node where its right child incorrectly points to another node at the same depth but to the invalid node's right.

\r\n\r\n

Given the root of the binary tree with this defect, root, return the root of the binary tree after removing this invalid node and every node underneath it (minus the node it incorrectly points to).

\r\n\r\n

Custom testing:

\r\n\r\n

The test input is read as 3 lines:

\r\n\r\n
    \r\n\t
  • TreeNode root
  • \r\n\t
  • int fromNode (not available to correctBinaryTree)
  • \r\n\t
  • int toNode (not available to correctBinaryTree)
  • \r\n
\r\n\r\n

After the binary tree rooted at root is parsed, the TreeNode with value of fromNode will have its right child pointer pointing to the TreeNode with a value of toNode. Then, root is passed to correctBinaryTree.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n

\"\"

\r\n\r\n
\r\nInput: root = [1,2,3], fromNode = 2, toNode = 3\r\nOutput: [1,null,3]\r\nExplanation: The node with value 2 is invalid, so remove it.\r\n
\r\n\r\n

Example 2:

\r\n\r\n

\"\"

\r\n\r\n
\r\nInput: root = [8,3,1,7,null,9,4,2,null,null,null,5,6], fromNode = 7, toNode = 4\r\nOutput: [8,3,1,null,null,9,4,null,null,5,6]\r\nExplanation: The node with value 7 is invalid, so remove it and the node underneath it, node 2.\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • The number of nodes in the tree is in the range [3, 104].
  • \r\n\t
  • -109 <= Node.val <= 109
  • \r\n\t
  • All Node.val are unique.
  • \r\n\t
  • fromNode != toNode
  • \r\n\t
  • fromNode and toNode will exist in the tree and will be on the same depth.
  • \r\n\t
  • toNode is to the right of fromNode.
  • \r\n\t
  • fromNode.right is null in the initial tree from the test data.
  • \r\n
", "content_cn": "

\u4f60\u6709\u4e00\u68f5\u4e8c\u53c9\u6811\uff0c\u8fd9\u68f5\u4e8c\u53c9\u6811\u6709\u4e2a\u5c0f\u95ee\u9898\uff0c\u5176\u4e2d\u6709\u4e14\u53ea\u6709\u4e00\u4e2a\u65e0\u6548\u8282\u70b9\uff0c\u5b83\u7684\u53f3\u5b50\u8282\u70b9\u9519\u8bef\u5730\u6307\u5411\u4e86\u4e0e\u5176\u5728\u540c\u4e00\u5c42\u4e14\u5728\u5176\u53f3\u4fa7\u7684\u4e00\u4e2a\u5176\u4ed6\u8282\u70b9\u3002

\n\n

\u7ed9\u5b9a\u4e00\u68f5\u8fd9\u6837\u7684\u95ee\u9898\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9\u00a0root\u00a0\uff0c\u5c06\u8be5\u65e0\u6548\u8282\u70b9\u53ca\u5176\u6240\u6709\u5b50\u8282\u70b9\u79fb\u9664\uff08\u9664\u88ab\u9519\u8bef\u6307\u5411\u7684\u8282\u70b9\u5916\uff09\uff0c\u7136\u540e\u8fd4\u56de\u65b0\u4e8c\u53c9\u6811\u7684\u6839\u7ed3\u70b9\u3002

\n\n

\u81ea\u5b9a\u4e49\u6d4b\u8bd5\u7528\u4f8b\uff1a

\n\n

\u6d4b\u8bd5\u7528\u4f8b\u7684\u8f93\u5165\u7531\u4e09\u884c\u7ec4\u6210\uff1a

\n\n
    \n\t
  • TreeNode root
  • \n\t
  • int fromNode\u00a0\uff08\u5728\u00a0correctBinaryTree\u00a0\u4e2d\u4e0d\u53ef\u89c1\uff09
  • \n\t
  • int toNode\u00a0\uff08\u5728\u00a0correctBinaryTree\u00a0\u4e2d\u4e0d\u53ef\u89c1\uff09
  • \n
\n\n

\u5f53\u4ee5\u00a0root\u00a0\u4e3a\u6839\u7684\u4e8c\u53c9\u6811\u88ab\u89e3\u6790\u540e\uff0c\u503c\u4e3a\u00a0fromNode\u00a0\u7684\u8282\u70b9\u00a0TreeNode\u00a0\u5c06\u5176\u53f3\u5b50\u8282\u70b9\u6307\u5411\u503c\u4e3a\u00a0toNode\u00a0\u7684\u8282\u70b9\u00a0TreeNode\u00a0\u3002\u7136\u540e\uff0c\u00a0root\u00a0\u4f20\u5165\u00a0correctBinaryTree\u00a0\u7684\u53c2\u6570\u4e2d\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1:

\n\n

\"\"

\n\n
\n\u8f93\u5165: root = [1,2,3], fromNode = 2, toNode = 3\n\u8f93\u51fa: [1,null,3]\n\u89e3\u91ca: \u503c\u4e3a 2 \u7684\u8282\u70b9\u662f\u65e0\u6548\u7684\uff0c\u6240\u4ee5\u79fb\u9664\u4e4b\u3002\n
\n\n

\u793a\u4f8b 2:

\n\n

\"\"

\n\n
\n\u8f93\u5165: root = [8,3,1,7,null,9,4,2,null,null,null,5,6], fromNode = 7, toNode = 4\n\u8f93\u51fa: [8,3,1,null,null,9,4,null,null,5,6]\n\u89e3\u91ca: \u503c\u4e3a 7 \u7684\u8282\u70b9\u662f\u65e0\u6548\u7684\uff0c\u6240\u4ee5\u79fb\u9664\u8fd9\u4e2a\u8282\u70b9\u53ca\u5176\u5b50\u8282\u70b9 2\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a:

\n\n
    \n\t
  • \u6811\u4e2d\u8282\u70b9\u4e2a\u6570\u7684\u8303\u56f4\u662f\u00a0[3, 104]\u00a0\u3002
  • \n\t
  • -109 <= Node.val <= 109
  • \n\t
  • \u6240\u6709\u7684\u00a0Node.val\u00a0\u90fd\u662f\u4e92\u4e0d\u76f8\u540c\u7684\u3002
  • \n\t
  • fromNode != toNode
  • \n\t
  • fromNode\u00a0\u548c\u00a0toNode\u00a0\u5c06\u51fa\u73b0\u5728\u6811\u4e2d\u7684\u540c\u4e00\u5c42\u3002
  • \n\t
  • toNode\u00a0\u5728\u00a0fromNode\u00a0\u7684\u53f3\u4fa7\u3002
  • \n\t
  • fromNode.right\u00a0\u5728\u6d4b\u8bd5\u7528\u4f8b\u7684\u6811\u4e2d\u5efa\u7acb\u540e\u4e3a\u00a0null\u00a0\u3002
  • \n
\n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* correctBinaryTree(TreeNode* root) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode correctBinaryTree(TreeNode root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def correctBinaryTree(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: TreeNode\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def correctBinaryTree(self, root: TreeNode) -> TreeNode:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode CorrectBinaryTree(TreeNode root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number} from\n * @param {number} to\n * @return {TreeNode}\n */\nvar correctBinaryTree = function(root) {\n \n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1660](https://leetcode-cn.com/problems/correct-a-binary-tree)", "[\u7ea0\u6b63\u4e8c\u53c9\u6811](/solution/1600-1699/1660.Correct%20a%20Binary%20Tree/README.md)", "`\u6811`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1660](https://leetcode.com/problems/correct-a-binary-tree)", "[Correct a Binary Tree](/solution/1600-1699/1660.Correct%20a%20Binary%20Tree/README_EN.md)", "`Tree`", "Medium", "\ud83d\udd12"]}, {"question_id": "1795", "frontend_question_id": "1651", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/hopper-company-queries-iii", "url_en": "https://leetcode.com/problems/hopper-company-queries-iii", "relative_path_cn": "/solution/1600-1699/1651.Hopper%20Company%20Queries%20III/README.md", "relative_path_en": "/solution/1600-1699/1651.Hopper%20Company%20Queries%20III/README_EN.md", "title_cn": "", "title_en": "Hopper Company Queries III", "question_title_slug": "hopper-company-queries-iii", "content_en": "

Table: Drivers

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| driver_id   | int     |\n| join_date   | date    |\n+-------------+---------+\ndriver_id is the primary key for this table.\nEach row of this table contains the driver's ID and the date they joined the Hopper company.\n
\n\n

 

\n\n

Table: Rides

\n\n
\n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| ride_id      | int     |\n| user_id      | int     |\n| requested_at | date    |\n+--------------+---------+\nride_id is the primary key for this table.\nEach row of this table contains the ID of a ride, the user's ID that requested it, and the day they requested it.\nThere may be some ride requests in this table that were not accepted.\n
\n\n

 

\n\n

Table: AcceptedRides

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| ride_id       | int     |\n| driver_id     | int     |\n| ride_distance | int     |\n| ride_duration | int     |\n+---------------+---------+\nride_id is the primary key for this table.\nEach row of this table contains some information about an accepted ride.\nIt is guaranteed that each accepted ride exists in the Rides table.\n
\n\n

 

\n\n

Write an SQL query to compute the average_ride_distance and average_ride_duration of every 3-month window starting from January - March 2020 to October - December 2020. Round average_ride_distance and average_ride_duration to the nearest two decimal places.

\n\n

The average_ride_distance is calculated by summing up the total ride_distance values from the three months and dividing it by 3. The average_ride_duration is calculated in a similar way.

\n\n

Return the result table ordered by month in ascending order, where month is the starting month's number (January is 1, February is 2, etc.).

\n\n

The query result format is in the following example.

\n\n

 

\n\n
\nDrivers table:\n+-----------+------------+\n| driver_id | join_date  |\n+-----------+------------+\n| 10        | 2019-12-10 |\n| 8         | 2020-1-13  |\n| 5         | 2020-2-16  |\n| 7         | 2020-3-8   |\n| 4         | 2020-5-17  |\n| 1         | 2020-10-24 |\n| 6         | 2021-1-5   |\n+-----------+------------+\n\nRides table:\n+---------+---------+--------------+\n| ride_id | user_id | requested_at |\n+---------+---------+--------------+\n| 6       | 75      | 2019-12-9    |\n| 1       | 54      | 2020-2-9     |\n| 10      | 63      | 2020-3-4     |\n| 19      | 39      | 2020-4-6     |\n| 3       | 41      | 2020-6-3     |\n| 13      | 52      | 2020-6-22    |\n| 7       | 69      | 2020-7-16    |\n| 17      | 70      | 2020-8-25    |\n| 20      | 81      | 2020-11-2    |\n| 5       | 57      | 2020-11-9    |\n| 2       | 42      | 2020-12-9    |\n| 11      | 68      | 2021-1-11    |\n| 15      | 32      | 2021-1-17    |\n| 12      | 11      | 2021-1-19    |\n| 14      | 18      | 2021-1-27    |\n+---------+---------+--------------+\n\nAcceptedRides table:\n+---------+-----------+---------------+---------------+\n| ride_id | driver_id | ride_distance | ride_duration |\n+---------+-----------+---------------+---------------+\n| 10      | 10        | 63            | 38            |\n| 13      | 10        | 73            | 96            |\n| 7       | 8         | 100           | 28            |\n| 17      | 7         | 119           | 68            |\n| 20      | 1         | 121           | 92            |\n| 5       | 7         | 42            | 101           |\n| 2       | 4         | 6             | 38            |\n| 11      | 8         | 37            | 43            |\n| 15      | 8         | 108           | 82            |\n| 12      | 8         | 38            | 34            |\n| 14      | 1         | 90            | 74            |\n+---------+-----------+---------------+---------------+\n\nResult table:\n+-------+-----------------------+-----------------------+\n| month | average_ride_distance | average_ride_duration |\n+-------+-----------------------+-----------------------+\n| 1     | 21.00                 | 12.67                 |\n| 2     | 21.00                 | 12.67                 |\n| 3     | 21.00                 | 12.67                 |\n| 4     | 24.33                 | 32.00                 |\n| 5     | 57.67                 | 41.33                 |\n| 6     | 97.33                 | 64.00                 |\n| 7     | 73.00                 | 32.00                 |\n| 8     | 39.67                 | 22.67                 |\n| 9     | 54.33                 | 64.33                 |\n| 10    | 56.33                 | 77.00                 |\n+-------+-----------------------+-----------------------+\n\nBy the end of January --> average_ride_distance = (0+0+63)/3=21, average_ride_duration = (0+0+38)/3=12.67\nBy the end of February --> average_ride_distance = (0+63+0)/3=21, average_ride_duration = (0+38+0)/3=12.67\nBy the end of March --> average_ride_distance = (63+0+0)/3=21, average_ride_duration = (38+0+0)/3=12.67\nBy the end of April --> average_ride_distance = (0+0+73)/3=24.33, average_ride_duration = (0+0+96)/3=32.00\nBy the end of May --> average_ride_distance = (0+73+100)/3=57.67, average_ride_duration = (0+96+28)/3=41.33\nBy the end of June --> average_ride_distance = (73+100+119)/3=97.33, average_ride_duration = (96+28+68)/3=64.00\nBy the end of July --> average_ride_distance = (100+119+0)/3=73.00, average_ride_duration = (28+68+0)/3=32.00\nBy the end of August --> average_ride_distance = (119+0+0)/3=39.67, average_ride_duration = (68+0+0)/3=22.67\nBy the end of Septemeber --> average_ride_distance = (0+0+163)/3=54.33, average_ride_duration = (0+0+193)/3=64.33\nBy the end of October --> average_ride_distance = (0+163+6)/3=56.33, average_ride_duration = (0+193+38)/3=77.00\n
\n", "content_cn": null, "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1651](https://leetcode-cn.com/problems/hopper-company-queries-iii)", "[Hopper Company Queries III](/solution/1600-1699/1651.Hopper%20Company%20Queries%20III/README_EN.md)", "", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1651](https://leetcode.com/problems/hopper-company-queries-iii)", "[Hopper Company Queries III](/solution/1600-1699/1651.Hopper%20Company%20Queries%20III/README_EN.md)", "", "Hard", "\ud83d\udd12"]}, {"question_id": "1794", "frontend_question_id": "1675", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimize-deviation-in-array", "url_en": "https://leetcode.com/problems/minimize-deviation-in-array", "relative_path_cn": "/solution/1600-1699/1675.Minimize%20Deviation%20in%20Array/README.md", "relative_path_en": "/solution/1600-1699/1675.Minimize%20Deviation%20in%20Array/README_EN.md", "title_cn": "\u6570\u7ec4\u7684\u6700\u5c0f\u504f\u79fb\u91cf", "title_en": "Minimize Deviation in Array", "question_title_slug": "minimize-deviation-in-array", "content_en": "

You are given an array nums of n positive integers.

\n\n

You can perform two types of operations on any element of the array any number of times:

\n\n
    \n\t
  • If the element is even, divide it by 2.\n\n\t
      \n\t\t
    • For example, if the array is [1,2,3,4], then you can do this operation on the last element, and the array will be [1,2,3,2].
    • \n\t
    \n\t
  • \n\t
  • If the element is odd, multiply it by 2.\n\t
      \n\t\t
    • For example, if the array is [1,2,3,4], then you can do this operation on the first element, and the array will be [2,2,3,4].
    • \n\t
    \n\t
  • \n
\n\n

The deviation of the array is the maximum difference between any two elements in the array.

\n\n

Return the minimum deviation the array can have after performing some number of operations.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [1,2,3,4]\nOutput: 1\nExplanation: You can transform the array to [1,2,3,2], then to [2,2,3,2], then the deviation will be 3 - 2 = 1.\n
\n\n

Example 2:

\n\n
\nInput: nums = [4,1,5,20,3]\nOutput: 3\nExplanation: You can transform the array after two operations to [4,2,5,5,3], then the deviation will be 5 - 2 = 3.\n
\n\n

Example 3:

\n\n
\nInput: nums = [2,10,8]\nOutput: 3\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == nums.length
  • \n\t
  • 2 <= n <= 105
  • \n\t
  • 1 <= nums[i] <= 109
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u7531 n \u4e2a\u6b63\u6574\u6570\u7ec4\u6210\u7684\u6570\u7ec4 nums \u3002

\n\n

\u4f60\u53ef\u4ee5\u5bf9\u6570\u7ec4\u7684\u4efb\u610f\u5143\u7d20\u6267\u884c\u4efb\u610f\u6b21\u6570\u7684\u4e24\u7c7b\u64cd\u4f5c\uff1a

\n\n
    \n\t
  • \u5982\u679c\u5143\u7d20\u662f \u5076\u6570 \uff0c\u9664\u4ee5 2\n\n\t
      \n\t\t
    • \u4f8b\u5982\uff0c\u5982\u679c\u6570\u7ec4\u662f [1,2,3,4] \uff0c\u90a3\u4e48\u4f60\u53ef\u4ee5\u5bf9\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u6267\u884c\u6b64\u64cd\u4f5c\uff0c\u4f7f\u5176\u53d8\u6210 [1,2,3,2]
    • \n\t
    \n\t
  • \n\t
  • \u5982\u679c\u5143\u7d20\u662f \u5947\u6570 \uff0c\u4e58\u4e0a 2\n\t
      \n\t\t
    • \u4f8b\u5982\uff0c\u5982\u679c\u6570\u7ec4\u662f [1,2,3,4] \uff0c\u90a3\u4e48\u4f60\u53ef\u4ee5\u5bf9\u7b2c\u4e00\u4e2a\u5143\u7d20\u6267\u884c\u6b64\u64cd\u4f5c\uff0c\u4f7f\u5176\u53d8\u6210 [2,2,3,4]
    • \n\t
    \n\t
  • \n
\n\n

\u6570\u7ec4\u7684 \u504f\u79fb\u91cf \u662f\u6570\u7ec4\u4e2d\u4efb\u610f\u4e24\u4e2a\u5143\u7d20\u4e4b\u95f4\u7684 \u6700\u5927\u5dee\u503c \u3002

\n\n

\u8fd4\u56de\u6570\u7ec4\u5728\u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\u4e4b\u540e\u53ef\u4ee5\u62e5\u6709\u7684 \u6700\u5c0f\u504f\u79fb\u91cf \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,2,3,4]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u5c06\u6570\u7ec4\u8f6c\u6362\u4e3a [1,2,3,2]\uff0c\u7136\u540e\u8f6c\u6362\u6210 [2,2,3,2]\uff0c\u504f\u79fb\u91cf\u662f 3 - 2 = 1\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anums = [4,1,5,20,3]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u4e24\u6b21\u64cd\u4f5c\u540e\uff0c\u4f60\u53ef\u4ee5\u5c06\u6570\u7ec4\u8f6c\u6362\u4e3a [4,2,5,5,3]\uff0c\u504f\u79fb\u91cf\u662f 5 - 2 = 3\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1anums = [2,10,8]\n\u8f93\u51fa\uff1a3\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • n == nums.length
  • \n\t
  • 2 <= n <= 105
  • \n\t
  • 1 <= nums[i] <= 109
  • \n
\n", "tags_en": ["Heap", "Ordered Map"], "tags_cn": ["\u5806"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minimumDeviation(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minimumDeviation(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimumDeviation(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimumDeviation(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minimumDeviation(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinimumDeviation(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar minimumDeviation = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef minimum_deviation(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimumDeviation(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimumDeviation(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimumDeviation(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimumDeviation(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimum_deviation(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function minimumDeviation($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimumDeviation(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimum-deviation nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1675](https://leetcode-cn.com/problems/minimize-deviation-in-array)", "[\u6570\u7ec4\u7684\u6700\u5c0f\u504f\u79fb\u91cf](/solution/1600-1699/1675.Minimize%20Deviation%20in%20Array/README.md)", "`\u5806`", "\u56f0\u96be", ""], "md_table_row_en": ["[1675](https://leetcode.com/problems/minimize-deviation-in-array)", "[Minimize Deviation in Array](/solution/1600-1699/1675.Minimize%20Deviation%20in%20Array/README_EN.md)", "`Heap`,`Ordered Map`", "Hard", ""]}, {"question_id": "1793", "frontend_question_id": "1674", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-moves-to-make-array-complementary", "url_en": "https://leetcode.com/problems/minimum-moves-to-make-array-complementary", "relative_path_cn": "/solution/1600-1699/1674.Minimum%20Moves%20to%20Make%20Array%20Complementary/README.md", "relative_path_en": "/solution/1600-1699/1674.Minimum%20Moves%20to%20Make%20Array%20Complementary/README_EN.md", "title_cn": "\u4f7f\u6570\u7ec4\u4e92\u8865\u7684\u6700\u5c11\u64cd\u4f5c\u6b21\u6570", "title_en": "Minimum Moves to Make Array Complementary", "question_title_slug": "minimum-moves-to-make-array-complementary", "content_en": "

You are given an integer array nums of even length n and an integer limit. In one move, you can replace any integer from nums with another integer between 1 and limit, inclusive.

\n\n

The array nums is complementary if for all indices i (0-indexed), nums[i] + nums[n - 1 - i] equals the same number. For example, the array [1,2,3,4] is complementary because for all indices i, nums[i] + nums[n - 1 - i] = 5.

\n\n

Return the minimum number of moves required to make nums complementary.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [1,2,4,3], limit = 4\nOutput: 1\nExplanation: In 1 move, you can change nums to [1,2,2,3] (underlined elements are changed).\nnums[0] + nums[3] = 1 + 3 = 4.\nnums[1] + nums[2] = 2 + 2 = 4.\nnums[2] + nums[1] = 2 + 2 = 4.\nnums[3] + nums[0] = 3 + 1 = 4.\nTherefore, nums[i] + nums[n-1-i] = 4 for every i, so nums is complementary.\n
\n\n

Example 2:

\n\n
\nInput: nums = [1,2,2,1], limit = 2\nOutput: 2\nExplanation: In 2 moves, you can change nums to [2,2,2,2]. You cannot change any number to 3 since 3 > limit.\n
\n\n

Example 3:

\n\n
\nInput: nums = [1,2,1,2], limit = 2\nOutput: 0\nExplanation: nums is already complementary.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == nums.length
  • \n\t
  • 2 <= n <= 105
  • \n\t
  • 1 <= nums[i] <= limit <= 105
  • \n\t
  • n is even.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u4e3a \u5076\u6570 n \u7684\u6574\u6570\u6570\u7ec4 nums \u548c\u4e00\u4e2a\u6574\u6570 limit \u3002\u6bcf\u4e00\u6b21\u64cd\u4f5c\uff0c\u4f60\u53ef\u4ee5\u5c06 nums \u4e2d\u7684\u4efb\u4f55\u6574\u6570\u66ff\u6362\u4e3a\u00a01\u00a0\u5230\u00a0limit \u4e4b\u95f4\u7684\u53e6\u4e00\u4e2a\u6574\u6570\u3002

\n\n

\u5982\u679c\u5bf9\u4e8e\u6240\u6709\u4e0b\u6807 i\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\uff0cnums[i] + nums[n - 1 - i]\u00a0\u90fd\u7b49\u4e8e\u540c\u4e00\u4e2a\u6570\uff0c\u5219\u6570\u7ec4 nums \u662f \u4e92\u8865\u7684 \u3002\u4f8b\u5982\uff0c\u6570\u7ec4 [1,2,3,4] \u662f\u4e92\u8865\u7684\uff0c\u56e0\u4e3a\u5bf9\u4e8e\u6240\u6709\u4e0b\u6807\u00a0i \uff0cnums[i] + nums[n - 1 - i] = 5 \u3002

\n\n

\u8fd4\u56de\u4f7f\u6570\u7ec4 \u4e92\u8865 \u7684 \u6700\u5c11\u00a0\u64cd\u4f5c\u6b21\u6570\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [1,2,4,3], limit = 4\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u7ecf\u8fc7 1 \u6b21\u64cd\u4f5c\uff0c\u4f60\u53ef\u4ee5\u5c06\u6570\u7ec4 nums \u53d8\u6210 [1,2,2,3]\uff08\u52a0\u7c97\u5143\u7d20\u662f\u53d8\u66f4\u7684\u6570\u5b57\uff09\uff1a\nnums[0] + nums[3] = 1 + 3 = 4.\nnums[1] + nums[2] = 2 + 2 = 4.\nnums[2] + nums[1] = 2 + 2 = 4.\nnums[3] + nums[0] = 3 + 1 = 4.\n\u5bf9\u4e8e\u6bcf\u4e2a i \uff0cnums[i] + nums[n-1-i] = 4 \uff0c\u6240\u4ee5 nums \u662f\u4e92\u8865\u7684\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [1,2,2,1], limit = 2\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u7ecf\u8fc7 2 \u6b21\u64cd\u4f5c\uff0c\u4f60\u53ef\u4ee5\u5c06\u6570\u7ec4 nums \u53d8\u6210 [2,2,2,2] \u3002\u4f60\u4e0d\u80fd\u5c06\u4efb\u4f55\u6570\u5b57\u53d8\u66f4\u4e3a 3 \uff0c\u56e0\u4e3a 3 > limit \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [1,2,1,2], limit = 2\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1anums \u5df2\u7ecf\u662f\u4e92\u8865\u7684\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • n == nums.length
  • \n\t
  • 2 <= n\u00a0<=\u00a0105
  • \n\t
  • 1 <= nums[i]\u00a0<= limit <=\u00a0105
  • \n\t
  • n \u662f\u5076\u6570\u3002
  • \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minMoves(vector& nums, int limit) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minMoves(int[] nums, int limit) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minMoves(self, nums, limit):\n \"\"\"\n :type nums: List[int]\n :type limit: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minMoves(self, nums: List[int], limit: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minMoves(int* nums, int numsSize, int limit){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinMoves(int[] nums, int limit) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} limit\n * @return {number}\n */\nvar minMoves = function(nums, limit) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} limit\n# @return {Integer}\ndef min_moves(nums, limit)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minMoves(_ nums: [Int], _ limit: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minMoves(nums []int, limit int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minMoves(nums: Array[Int], limit: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minMoves(nums: IntArray, limit: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_moves(nums: Vec, limit: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $limit\n * @return Integer\n */\n function minMoves($nums, $limit) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minMoves(nums: number[], limit: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-moves nums limit)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1674](https://leetcode-cn.com/problems/minimum-moves-to-make-array-complementary)", "[\u4f7f\u6570\u7ec4\u4e92\u8865\u7684\u6700\u5c11\u64cd\u4f5c\u6b21\u6570](/solution/1600-1699/1674.Minimum%20Moves%20to%20Make%20Array%20Complementary/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1674](https://leetcode.com/problems/minimum-moves-to-make-array-complementary)", "[Minimum Moves to Make Array Complementary](/solution/1600-1699/1674.Minimum%20Moves%20to%20Make%20Array%20Complementary/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1792", "frontend_question_id": "1673", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-the-most-competitive-subsequence", "url_en": "https://leetcode.com/problems/find-the-most-competitive-subsequence", "relative_path_cn": "/solution/1600-1699/1673.Find%20the%20Most%20Competitive%20Subsequence/README.md", "relative_path_en": "/solution/1600-1699/1673.Find%20the%20Most%20Competitive%20Subsequence/README_EN.md", "title_cn": "\u627e\u51fa\u6700\u5177\u7ade\u4e89\u529b\u7684\u5b50\u5e8f\u5217", "title_en": "Find the Most Competitive Subsequence", "question_title_slug": "find-the-most-competitive-subsequence", "content_en": "

Given an integer array nums and a positive integer k, return the most competitive subsequence of nums of size k.

\n\n

An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the array.

\n\n

We define that a subsequence a is more competitive than a subsequence b (of the same length) if in the first position where a and b differ, subsequence a has a number less than the corresponding number in b. For example, [1,3,4] is more competitive than [1,3,5] because the first position they differ is at the final number, and 4 is less than 5.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [3,5,2,6], k = 2\nOutput: [2,6]\nExplanation: Among the set of every possible subsequence: {[3,5], [3,2], [3,6], [5,2], [5,6], [2,6]}, [2,6] is the most competitive.\n
\n\n

Example 2:

\n\n
\nInput: nums = [2,4,3,3,5,4,9,6], k = 4\nOutput: [2,3,3,4]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 105
  • \n\t
  • 0 <= nums[i] <= 109
  • \n\t
  • 1 <= k <= nums.length
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \u548c\u4e00\u4e2a\u6b63\u6574\u6570 k \uff0c\u8fd4\u56de\u957f\u5ea6\u4e3a k \u4e14\u6700\u5177 \u7ade\u4e89\u529b \u7684 nums \u5b50\u5e8f\u5217\u3002

\n\n

\u6570\u7ec4\u7684\u5b50\u5e8f\u5217\u662f\u4ece\u6570\u7ec4\u4e2d\u5220\u9664\u4e00\u4e9b\u5143\u7d20\uff08\u53ef\u80fd\u4e0d\u5220\u9664\u5143\u7d20\uff09\u5f97\u5230\u7684\u5e8f\u5217\u3002

\n\n

\u5728\u5b50\u5e8f\u5217\u00a0a \u548c\u5b50\u5e8f\u5217\u00a0b \u7b2c\u4e00\u4e2a\u4e0d\u76f8\u540c\u7684\u4f4d\u7f6e\u4e0a\uff0c\u5982\u679c\u00a0a\u00a0\u4e2d\u7684\u6570\u5b57\u5c0f\u4e8e b \u4e2d\u5bf9\u5e94\u7684\u6570\u5b57\uff0c\u90a3\u4e48\u6211\u4eec\u79f0\u5b50\u5e8f\u5217 a \u6bd4\u5b50\u5e8f\u5217 b\uff08\u76f8\u540c\u957f\u5ea6\u4e0b\uff09\u66f4\u5177 \u7ade\u4e89\u529b \u3002 \u4f8b\u5982\uff0c[1,3,4] \u6bd4 [1,3,5] \u66f4\u5177\u7ade\u4e89\u529b\uff0c\u5728\u7b2c\u4e00\u4e2a\u4e0d\u76f8\u540c\u7684\u4f4d\u7f6e\uff0c\u4e5f\u5c31\u662f\u6700\u540e\u4e00\u4e2a\u4f4d\u7f6e\u4e0a\uff0c\u00a04 \u5c0f\u4e8e 5 \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [3,5,2,6], k = 2\n\u8f93\u51fa\uff1a[2,6]\n\u89e3\u91ca\uff1a\u5728\u6240\u6709\u53ef\u80fd\u7684\u5b50\u5e8f\u5217\u96c6\u5408 {[3,5], [3,2], [3,6], [5,2], [5,6], [2,6]} \u4e2d\uff0c[2,6] \u6700\u5177\u7ade\u4e89\u529b\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [2,4,3,3,5,4,9,6], k = 4\n\u8f93\u51fa\uff1a[2,3,3,4]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 105
  • \n\t
  • 0 <= nums[i] <= 109
  • \n\t
  • 1 <= k <= nums.length
  • \n
\n", "tags_en": ["Stack", "Heap", "Greedy", "Queue"], "tags_cn": ["\u6808", "\u5806", "\u8d2a\u5fc3\u7b97\u6cd5", "\u961f\u5217"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector mostCompetitive(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] mostCompetitive(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def mostCompetitive(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def mostCompetitive(self, nums: List[int], k: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* mostCompetitive(int* nums, int numsSize, int k, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] MostCompetitive(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number[]}\n */\nvar mostCompetitive = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer[]}\ndef most_competitive(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func mostCompetitive(_ nums: [Int], _ k: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func mostCompetitive(nums []int, k int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def mostCompetitive(nums: Array[Int], k: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun mostCompetitive(nums: IntArray, k: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn most_competitive(nums: Vec, k: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer[]\n */\n function mostCompetitive($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function mostCompetitive(nums: number[], k: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (most-competitive nums k)\n (-> (listof exact-integer?) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1673](https://leetcode-cn.com/problems/find-the-most-competitive-subsequence)", "[\u627e\u51fa\u6700\u5177\u7ade\u4e89\u529b\u7684\u5b50\u5e8f\u5217](/solution/1600-1699/1673.Find%20the%20Most%20Competitive%20Subsequence/README.md)", "`\u6808`,`\u5806`,`\u8d2a\u5fc3\u7b97\u6cd5`,`\u961f\u5217`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1673](https://leetcode.com/problems/find-the-most-competitive-subsequence)", "[Find the Most Competitive Subsequence](/solution/1600-1699/1673.Find%20the%20Most%20Competitive%20Subsequence/README_EN.md)", "`Stack`,`Heap`,`Greedy`,`Queue`", "Medium", ""]}, {"question_id": "1791", "frontend_question_id": "1672", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/richest-customer-wealth", "url_en": "https://leetcode.com/problems/richest-customer-wealth", "relative_path_cn": "/solution/1600-1699/1672.Richest%20Customer%20Wealth/README.md", "relative_path_en": "/solution/1600-1699/1672.Richest%20Customer%20Wealth/README_EN.md", "title_cn": "\u6700\u5bcc\u6709\u5ba2\u6237\u7684\u8d44\u4ea7\u603b\u91cf", "title_en": "Richest Customer Wealth", "question_title_slug": "richest-customer-wealth", "content_en": "

You are given an m x n integer grid accounts where accounts[i][j] is the amount of money the i\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200bth\u200b\u200b\u200b\u200b customer has in the j\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200bth\u200b\u200b\u200b\u200b bank. Return the wealth that the richest customer has.

\n\n

A customer's wealth is the amount of money they have in all their bank accounts. The richest customer is the customer that has the maximum wealth.

\n\n

 

\n

Example 1:

\n\n
\nInput: accounts = [[1,2,3],[3,2,1]]\nOutput: 6\nExplanation:\n1st customer has wealth = 1 + 2 + 3 = 6\n2nd customer has wealth = 3 + 2 + 1 = 6\nBoth customers are considered the richest with a wealth of 6 each, so return 6.\n
\n\n

Example 2:

\n\n
\nInput: accounts = [[1,5],[7,3],[3,5]]\nOutput: 10\nExplanation: \n1st customer has wealth = 6\n2nd customer has wealth = 10 \n3rd customer has wealth = 8\nThe 2nd customer is the richest with a wealth of 10.
\n\n

Example 3:

\n\n
\nInput: accounts = [[2,8,7],[7,1,3],[1,9,5]]\nOutput: 17\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • m == accounts.length
  • \n\t
  • n == accounts[i].length
  • \n\t
  • 1 <= m, n <= 50
  • \n\t
  • 1 <= accounts[i][j] <= 100
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a m x n \u7684\u6574\u6570\u7f51\u683c accounts \uff0c\u5176\u4e2d accounts[i][j] \u662f\u7b2c i\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b \u4f4d\u5ba2\u6237\u5728\u7b2c j \u5bb6\u94f6\u884c\u6258\u7ba1\u7684\u8d44\u4ea7\u6570\u91cf\u3002\u8fd4\u56de\u6700\u5bcc\u6709\u5ba2\u6237\u6240\u62e5\u6709\u7684 \u8d44\u4ea7\u603b\u91cf \u3002

\n\n

\u5ba2\u6237\u7684 \u8d44\u4ea7\u603b\u91cf \u5c31\u662f\u4ed6\u4eec\u5728\u5404\u5bb6\u94f6\u884c\u6258\u7ba1\u7684\u8d44\u4ea7\u6570\u91cf\u4e4b\u548c\u3002\u6700\u5bcc\u6709\u5ba2\u6237\u5c31\u662f \u8d44\u4ea7\u603b\u91cf \u6700\u5927\u7684\u5ba2\u6237\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aaccounts = [[1,2,3],[3,2,1]]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\n\u7b2c 1 \u4f4d\u5ba2\u6237\u7684\u8d44\u4ea7\u603b\u91cf = 1 + 2 + 3 = 6\n\u7b2c 2 \u4f4d\u5ba2\u6237\u7684\u8d44\u4ea7\u603b\u91cf = 3 + 2 + 1 = 6\n\u4e24\u4f4d\u5ba2\u6237\u90fd\u662f\u6700\u5bcc\u6709\u7684\uff0c\u8d44\u4ea7\u603b\u91cf\u90fd\u662f 6 \uff0c\u6240\u4ee5\u8fd4\u56de 6 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aaccounts = [[1,5],[7,3],[3,5]]\n\u8f93\u51fa\uff1a10\n\u89e3\u91ca\uff1a\n\u7b2c 1 \u4f4d\u5ba2\u6237\u7684\u8d44\u4ea7\u603b\u91cf = 6\n\u7b2c 2 \u4f4d\u5ba2\u6237\u7684\u8d44\u4ea7\u603b\u91cf = 10 \n\u7b2c 3 \u4f4d\u5ba2\u6237\u7684\u8d44\u4ea7\u603b\u91cf = 8\n\u7b2c 2 \u4f4d\u5ba2\u6237\u662f\u6700\u5bcc\u6709\u7684\uff0c\u8d44\u4ea7\u603b\u91cf\u662f 10
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aaccounts = [[2,8,7],[7,1,3],[1,9,5]]\n\u8f93\u51fa\uff1a17\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • m ==\u00a0accounts.length
  • \n\t
  • n ==\u00a0accounts[i].length
  • \n\t
  • 1 <= m, n <= 50
  • \n\t
  • 1 <= accounts[i][j] <= 100
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maximumWealth(vector>& accounts) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maximumWealth(int[][] accounts) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximumWealth(self, accounts):\n \"\"\"\n :type accounts: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximumWealth(self, accounts: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maximumWealth(int** accounts, int accountsSize, int* accountsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaximumWealth(int[][] accounts) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} accounts\n * @return {number}\n */\nvar maximumWealth = function(accounts) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} accounts\n# @return {Integer}\ndef maximum_wealth(accounts)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximumWealth(_ accounts: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximumWealth(accounts [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximumWealth(accounts: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximumWealth(accounts: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximum_wealth(accounts: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $accounts\n * @return Integer\n */\n function maximumWealth($accounts) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximumWealth(accounts: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximum-wealth accounts)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1672](https://leetcode-cn.com/problems/richest-customer-wealth)", "[\u6700\u5bcc\u6709\u5ba2\u6237\u7684\u8d44\u4ea7\u603b\u91cf](/solution/1600-1699/1672.Richest%20Customer%20Wealth/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1672](https://leetcode.com/problems/richest-customer-wealth)", "[Richest Customer Wealth](/solution/1600-1699/1672.Richest%20Customer%20Wealth/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1790", "frontend_question_id": "1650", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-tree-iii", "url_en": "https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree-iii", "relative_path_cn": "/solution/1600-1699/1650.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree%20III/README.md", "relative_path_en": "/solution/1600-1699/1650.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree%20III/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148 III", "title_en": "Lowest Common Ancestor of a Binary Tree III", "question_title_slug": "lowest-common-ancestor-of-a-binary-tree-iii", "content_en": "

Given two nodes of a binary tree p and q, return their lowest common ancestor (LCA).

\n\n

Each node will have a reference to its parent node. The definition for Node is below:

\n\n
\nclass Node {\n    public int val;\n    public Node left;\n    public Node right;\n    public Node parent;\n}\n
\n\n

According to the definition of LCA on Wikipedia: "The lowest common ancestor of two nodes p and q in a tree T is the lowest node that has both p and q as descendants (where we allow a node to be a descendant of itself)."

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 1\nOutput: 3\nExplanation: The LCA of nodes 5 and 1 is 3.\n
\n\n

Example 2:

\n\"\"\n
\nInput: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 4\nOutput: 5\nExplanation: The LCA of nodes 5 and 4 is 5 since a node can be a descendant of itself according to the LCA definition.\n
\n\n

Example 3:

\n\n
\nInput: root = [1,2], p = 1, q = 2\nOutput: 1\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The number of nodes in the tree is in the range [2, 105].
  • \n\t
  • -109 <= Node.val <= 109
  • \n\t
  • All Node.val are unique.
  • \n\t
  • p != q
  • \n\t
  • p and q exist in the tree.
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u68f5\u4e8c\u53c9\u6811\u4e2d\u7684\u4e24\u4e2a\u8282\u70b9 p \u548c q\uff0c\u8fd4\u56de\u5b83\u4eec\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148\u8282\u70b9\uff08LCA\uff09\u3002

\n\n

\u6bcf\u4e2a\u8282\u70b9\u90fd\u5305\u542b\u5176\u7236\u8282\u70b9\u7684\u5f15\u7528\uff08\u6307\u9488\uff09\u3002Node\u00a0\u7684\u5b9a\u4e49\u5982\u4e0b\uff1a

\n\n
class Node {\n    public int val;\n    public Node left;\n    public Node right;\n    public Node parent;\n}\n
\n\n

\u6839\u636e\u7ef4\u57fa\u767e\u79d1\u4e2d\u5bf9\u6700\u8fd1\u516c\u5171\u7956\u5148\u8282\u70b9\u7684\u5b9a\u4e49\uff1a\u201c\u4e24\u4e2a\u8282\u70b9 p \u548c q \u5728\u4e8c\u53c9\u6811 T \u4e2d\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148\u8282\u70b9\u662f\u540e\u4ee3\u8282\u70b9\u4e2d\u65e2\u5305\u62ec p\u00a0\u53c8\u5305\u62ec\u00a0q\u00a0\u7684\u6700\u6df1\u8282\u70b9\uff08\u6211\u4eec\u5141\u8bb8\u4e00\u4e2a\u8282\u70b9\u4e3a\u81ea\u8eab\u7684\u4e00\u4e2a\u540e\u4ee3\u8282\u70b9\uff09\u201d\u3002\u4e00\u4e2a\u8282\u70b9 x\u00a0\u7684\u540e\u4ee3\u8282\u70b9\u662f\u8282\u70b9\u00a0x \u5230\u67d0\u4e00\u53f6\u8282\u70b9\u95f4\u7684\u8def\u5f84\u4e2d\u7684\u8282\u70b9 y\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1:

\n\"\"\n
\u8f93\u5165: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 1\n\u8f93\u51fa: 3\n\u89e3\u91ca: \u8282\u70b9 5 \u548c 1 \u7684\u6700\u8fd1\u516c\u5171\u7956\u5148\u662f 3\u3002\n
\n\n

\u793a\u4f8b 2:

\n\"\"\n
\u8f93\u5165: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 4\n\u8f93\u51fa: 5\n\u89e3\u91ca: \u8282\u70b9 5 \u548c 4 \u7684\u6700\u8fd1\u516c\u5171\u7956\u5148\u662f 5\uff0c\u6839\u636e\u5b9a\u4e49\uff0c\u4e00\u4e2a\u8282\u70b9\u53ef\u4ee5\u662f\u81ea\u8eab\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148\u3002\n
\n\n

\u793a\u4f8b 3:

\n\n
\u8f93\u5165: root = [1,2], p = 1, q = 2\n\u8f93\u51fa: 1\n
\n\n

\u00a0

\n\n

\u63d0\u793a:

\n\n
    \n\t
  • \u6811\u4e2d\u8282\u70b9\u4e2a\u6570\u7684\u8303\u56f4\u662f\u00a0[2, 105]\u3002
  • \n\t
  • -109 <= Node.val <= 109
  • \n\t
  • \u6240\u6709\u7684\u00a0Node.val\u00a0\u90fd\u662f\u4e92\u4e0d\u76f8\u540c\u7684\u3002
  • \n\t
  • p != q
  • \n\t
  • p\u00a0\u548c\u00a0q\u00a0\u5b58\u5728\u4e8e\u6811\u4e2d\u3002
  • \n
\n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* parent;\n};\n*/\n\nclass Solution {\npublic:\n Node* lowestCommonAncestor(Node* p, Node * q) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/*\n// Definition for a Node.\nclass Node {\n public int val;\n public Node left;\n public Node right;\n public Node parent;\n};\n*/\n\nclass Solution {\n public Node lowestCommonAncestor(Node p, Node q) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "\"\"\"\n# Definition for a Node.\nclass Node:\n def __init__(self, val):\n self.val = val\n self.left = None\n self.right = None\n self.parent = None\n\"\"\"\n\nclass Solution(object):\n def lowestCommonAncestor(self, p, q):\n \"\"\"\n :type node: Node\n :rtype: Node\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "\"\"\"\n# Definition for a Node.\nclass Node:\n def __init__(self, val):\n self.val = val\n self.left = None\n self.right = None\n self.parent = None\n\"\"\"\n\nclass Solution:\n def lowestCommonAncestor(self, p: 'Node', q: 'Node') -> 'Node':\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/*\n// Definition for a Node.\nstruct Node {\n int val;\n struct Node* left;\n struct Node* right;\n struct Node* parent;\n};\n*/\n\nstruct Node* lowestCommonAncestor(struct Node* p,struct Node* q) {\n\t\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/*\n// Definition for a Node.\npublic class Node {\n public int val;\n public Node left;\n public Node right;\n public Node parent;\n}\n*/\n\npublic class Solution {\n public Node LowestCommonAncestor(Node p, Node q) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // Definition for a Node.\n * function Node(val) {\n * this.val = val;\n * this.left = null;\n * this.right = null;\n * this.parent = null;\n * };\n */\n\n/**\n * @param {Node} node\n * @return {Node}\n */\nvar lowestCommonAncestor = function(p, q) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a Node.\n# class Node\n# attr_accessor :val, :left, :right, :parent\n# def initialize(val=0)\n# @val = val\n# @left, @right, parent = nil, nil, nil\n# end\n# end\n\n# @param {Node} root\n# @return {Node}\ndef lowest_common_ancestor(p, q)\n\t\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a Node.\n * public class Node {\n * public var val: Int\n * public var left: Node?\n * public var right: Node?\n * public var parent: Node?\n * public init(_ val: Int) {\n * self.val = val\n * self.left = nil\n * self.right = nil\n * self.parent = nil\n * }\n * }\n */\n\nclass Solution {\n func lowestCommonAncestor(_ p: Node?,_ q: Node?) -> Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for Node.\n * type Node struct {\n * Val int\n * Left *Node\n * Right *Node\n * Parent *Node\n * }\n */\n\nfunc lowestCommonAncestor(p *Node, q *Node) *Node {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a Node.\n * class Node(var _value: Int) {\n * var value: Int = _value\n * var left: Node = null\n * var right: Node = null\n * var parent: Node = null\n * }\n */\n\nobject Solution {\n def lowestCommonAncestor(p: Node, q: Node): Node = {\n\t\t\n\t}\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a Node.\n * class Node(var `val`: Int) {\n *\t\tvar left: TreeNode? = null\n *\t\tvar right: TreeNode? = null\n *\t\tvar parent: Node? = null\n * }\n */\n\nclass Solution {\n fun lowestCommonAncestor(p: Node?, q: Node?): Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a Node.\n * class Node {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * public $parent = null;\n * function __construct($val = 0) {\n * $this->val = $val;\n * $this->left = null;\n * $this->right = null;\n * $this->parent = null;\n * }\n * }\n */\n\nclass Solution {\n /**\n * @param Node $node\n * @return Node\n */\n function lowestCommonAncestor($p, $q) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class Node {\n * val: number\n * left: Node | null\n * right: Node | null\n * parent: Node | null\n * constructor(val?: number, left?: Node | null, right?: Node | null, parent?: Node | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * this.parent = (parent===undefined ? null : parent)\n * }\n * }\n */\n\nfunction lowestCommonAncestor(p: Node | null, q: Node | null): Node | null {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1650](https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-tree-iii)", "[\u4e8c\u53c9\u6811\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148 III](/solution/1600-1699/1650.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree%20III/README.md)", "`\u6811`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1650](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree-iii)", "[Lowest Common Ancestor of a Binary Tree III](/solution/1600-1699/1650.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree%20III/README_EN.md)", "`Tree`", "Medium", "\ud83d\udd12"]}, {"question_id": "1789", "frontend_question_id": "1687", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/delivering-boxes-from-storage-to-ports", "url_en": "https://leetcode.com/problems/delivering-boxes-from-storage-to-ports", "relative_path_cn": "/solution/1600-1699/1687.Delivering%20Boxes%20from%20Storage%20to%20Ports/README.md", "relative_path_en": "/solution/1600-1699/1687.Delivering%20Boxes%20from%20Storage%20to%20Ports/README_EN.md", "title_cn": "\u4ece\u4ed3\u5e93\u5230\u7801\u5934\u8fd0\u8f93\u7bb1\u5b50", "title_en": "Delivering Boxes from Storage to Ports", "question_title_slug": "delivering-boxes-from-storage-to-ports", "content_en": "

You have the task of delivering some boxes from storage to their ports using only one ship. However, this ship has a limit on the number of boxes and the total weight that it can carry.

\n\n

You are given an array boxes, where boxes[i] = [ports\u200b\u200bi\u200b, weighti], and three integers portsCount, maxBoxes, and maxWeight.

\n\n
    \n\t
  • ports\u200b\u200bi is the port where you need to deliver the ith box and weightsi is the weight of the ith box.
  • \n\t
  • portsCount is the number of ports.
  • \n\t
  • maxBoxes and maxWeight are the respective box and weight limits of the ship.
  • \n
\n\n

The boxes need to be delivered in the order they are given. The ship will follow these steps:

\n\n
    \n\t
  • The ship will take some number of boxes from the boxes queue, not violating the maxBoxes and maxWeight constraints.
  • \n\t
  • For each loaded box in order, the ship will make a trip to the port the box needs to be delivered to and deliver it. If the ship is already at the correct port, no trip is needed, and the box can immediately be delivered.
  • \n\t
  • The ship then makes a return trip to storage to take more boxes from the queue.
  • \n
\n\n

The ship must end at storage after all the boxes have been delivered.

\n\n

Return the minimum number of trips the ship needs to make to deliver all boxes to their respective ports.

\n\n

 

\n

Example 1:

\n\n
\nInput: boxes = [[1,1],[2,1],[1,1]], portsCount = 2, maxBoxes = 3, maxWeight = 3\nOutput: 4\nExplanation: The optimal strategy is as follows: \n- The ship takes all the boxes in the queue, goes to port 1, then port 2, then port 1 again, then returns to storage. 4 trips.\nSo the total number of trips is 4.\nNote that the first and third boxes cannot be delivered together because the boxes need to be delivered in order (i.e. the second box needs to be delivered at port 2 before the third box).\n
\n\n

Example 2:

\n\n
\nInput: boxes = [[1,2],[3,3],[3,1],[3,1],[2,4]], portsCount = 3, maxBoxes = 3, maxWeight = 6\nOutput: 6\nExplanation: The optimal strategy is as follows: \n- The ship takes the first box, goes to port 1, then returns to storage. 2 trips.\n- The ship takes the second, third and fourth boxes, goes to port 3, then returns to storage. 2 trips.\n- The ship takes the fifth box, goes to port 3, then returns to storage. 2 trips.\nSo the total number of trips is 2 + 2 + 2 = 6.\n
\n\n

Example 3:

\n\n
\nInput: boxes = [[1,4],[1,2],[2,1],[2,1],[3,2],[3,4]], portsCount = 3, maxBoxes = 6, maxWeight = 7\nOutput: 6\nExplanation: The optimal strategy is as follows:\n- The ship takes the first and second boxes, goes to port 1, then returns to storage. 2 trips.\n- The ship takes the third and fourth boxes, goes to port 2, then returns to storage. 2 trips.\n- The ship takes the fifth and sixth boxes, goes to port 3, then returns to storage. 2 trips.\nSo the total number of trips is 2 + 2 + 2 = 6.\n
\n\n

Example 4:

\n\n
\nInput: boxes = [[2,4],[2,5],[3,1],[3,2],[3,7],[3,1],[4,4],[1,3],[5,2]], portsCount = 5, maxBoxes = 5, maxWeight = 7\nOutput: 14\nExplanation: The optimal strategy is as follows:\n- The ship takes the first box, goes to port 2, then storage. 2 trips.\n- The ship takes the second box, goes to port 2, then storage. 2 trips.\n- The ship takes the third and fourth boxes, goes to port 3, then storage. 2 trips.\n- The ship takes the fifth box, goes to port 3, then storage. 2 trips.\n- The ship takes the sixth and seventh boxes, goes to port 3, then port 4, then storage. 3 trips. \n- The ship takes the eighth and ninth boxes, goes to port 1, then port 5, then storage. 3 trips.\nSo the total number of trips is 2 + 2 + 2 + 2 + 3 + 3 = 14.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= boxes.length <= 105
  • \n\t
  • 1 <= portsCount, maxBoxes, maxWeight <= 105
  • \n\t
  • 1 <= ports\u200b\u200bi <= portsCount
  • \n\t
  • 1 <= weightsi <= maxWeight
  • \n
\n", "content_cn": "

\u4f60\u6709\u4e00\u8f86\u8d27\u8fd0\u5361\u8f66\uff0c\u4f60\u9700\u8981\u7528\u8fd9\u4e00\u8f86\u8f66\u628a\u4e00\u4e9b\u7bb1\u5b50\u4ece\u4ed3\u5e93\u8fd0\u9001\u5230\u7801\u5934\u3002\u8fd9\u8f86\u5361\u8f66\u6bcf\u6b21\u8fd0\u8f93\u6709\u00a0\u7bb1\u5b50\u6570\u76ee\u7684\u9650\u5236\u00a0\u548c \u603b\u91cd\u91cf\u7684\u9650\u5236\u00a0\u3002

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u7bb1\u5b50\u6570\u7ec4\u00a0boxes\u00a0\u548c\u4e09\u4e2a\u6574\u6570 portsCount, maxBoxes\u00a0\u548c\u00a0maxWeight\u00a0\uff0c\u5176\u4e2d\u00a0boxes[i] = [ports\u200b\u200bi\u200b, weighti]\u00a0\u3002

\n\n
    \n\t
  • ports\u200b\u200bi\u00a0\u8868\u793a\u7b2c\u00a0i\u00a0\u4e2a\u7bb1\u5b50\u9700\u8981\u9001\u8fbe\u7684\u7801\u5934\uff0c\u00a0weightsi\u00a0\u662f\u7b2c\u00a0i\u00a0\u4e2a\u7bb1\u5b50\u7684\u91cd\u91cf\u3002
  • \n\t
  • portsCount\u00a0\u662f\u7801\u5934\u7684\u6570\u76ee\u3002
  • \n\t
  • maxBoxes \u548c\u00a0maxWeight\u00a0\u5206\u522b\u662f\u5361\u8f66\u6bcf\u8d9f\u8fd0\u8f93\u7bb1\u5b50\u6570\u76ee\u548c\u91cd\u91cf\u7684\u9650\u5236\u3002
  • \n
\n\n

\u7bb1\u5b50\u9700\u8981\u6309\u7167 \u6570\u7ec4\u987a\u5e8f\u00a0\u8fd0\u8f93\uff0c\u540c\u65f6\u6bcf\u6b21\u8fd0\u8f93\u9700\u8981\u9075\u5faa\u4ee5\u4e0b\u6b65\u9aa4\uff1a

\n\n
    \n\t
  • \u5361\u8f66\u4ece\u00a0boxes\u00a0\u961f\u5217\u4e2d\u6309\u987a\u5e8f\u53d6\u51fa\u82e5\u5e72\u4e2a\u7bb1\u5b50\uff0c\u4f46\u4e0d\u80fd\u8fdd\u53cd\u00a0maxBoxes \u548c\u00a0maxWeight\u00a0\u9650\u5236\u3002
  • \n\t
  • \u5bf9\u4e8e\u5728\u5361\u8f66\u4e0a\u7684\u7bb1\u5b50\uff0c\u6211\u4eec\u9700\u8981 \u6309\u987a\u5e8f\u00a0\u5904\u7406\u5b83\u4eec\uff0c\u5361\u8f66\u4f1a\u901a\u8fc7 \u4e00\u8d9f\u884c\u7a0b\u00a0\u5c06\u6700\u524d\u9762\u7684\u7bb1\u5b50\u9001\u5230\u76ee\u7684\u5730\u7801\u5934\u5e76\u5378\u8d27\u3002\u5982\u679c\u5361\u8f66\u5df2\u7ecf\u5728\u5bf9\u5e94\u7684\u7801\u5934\uff0c\u90a3\u4e48\u4e0d\u9700\u8981 \u989d\u5916\u884c\u7a0b\u00a0\uff0c\u7bb1\u5b50\u4e5f\u4f1a\u7acb\u9a6c\u88ab\u5378\u8d27\u3002
  • \n\t
  • \u5361\u8f66\u4e0a\u6240\u6709\u7bb1\u5b50\u90fd\u88ab\u5378\u8d27\u540e\uff0c\u5361\u8f66\u9700\u8981 \u4e00\u8d9f\u884c\u7a0b\u00a0\u56de\u5230\u4ed3\u5e93\uff0c\u4ece\u7bb1\u5b50\u961f\u5217\u91cc\u518d\u53d6\u51fa\u4e00\u4e9b\u7bb1\u5b50\u3002
  • \n
\n\n

\u5361\u8f66\u5728\u5c06\u6240\u6709\u7bb1\u5b50\u8fd0\u8f93\u5e76\u5378\u8d27\u540e\uff0c\u6700\u540e\u5fc5\u987b\u56de\u5230\u4ed3\u5e93\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u5c06\u6240\u6709\u7bb1\u5b50\u9001\u5230\u76f8\u5e94\u7801\u5934\u7684\u00a0\u6700\u5c11\u884c\u7a0b\u00a0\u6b21\u6570\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aboxes = [[1,1],[2,1],[1,1]], portsCount = 2, maxBoxes = 3, maxWeight = 3\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u6700\u4f18\u7b56\u7565\u5982\u4e0b\uff1a\n- \u5361\u8f66\u5c06\u6240\u6709\u7bb1\u5b50\u88c5\u4e0a\u8f66\uff0c\u5230\u8fbe\u7801\u5934 1 \uff0c\u7136\u540e\u53bb\u7801\u5934 2 \uff0c\u7136\u540e\u518d\u56de\u5230\u7801\u5934 1 \uff0c\u6700\u540e\u56de\u5230\u4ed3\u5e93\uff0c\u603b\u5171\u9700\u8981 4 \u8d9f\u884c\u7a0b\u3002\n\u6240\u4ee5\u603b\u884c\u7a0b\u6570\u4e3a 4 \u3002\n\u6ce8\u610f\u5230\u7b2c\u4e00\u4e2a\u548c\u7b2c\u4e09\u4e2a\u7bb1\u5b50\u4e0d\u80fd\u540c\u65f6\u88ab\u5378\u8d27\uff0c\u56e0\u4e3a\u7bb1\u5b50\u9700\u8981\u6309\u987a\u5e8f\u5904\u7406\uff08\u4e5f\u5c31\u662f\u7b2c\u4e8c\u4e2a\u7bb1\u5b50\u9700\u8981\u5148\u88ab\u9001\u5230\u7801\u5934 2 \uff0c\u7136\u540e\u624d\u80fd\u5904\u7406\u7b2c\u4e09\u4e2a\u7bb1\u5b50\uff09\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aboxes = [[1,2],[3,3],[3,1],[3,1],[2,4]], portsCount = 3, maxBoxes = 3, maxWeight = 6\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u6700\u4f18\u7b56\u7565\u5982\u4e0b\uff1a\n- \u5361\u8f66\u9996\u5148\u8fd0\u8f93\u7b2c\u4e00\u4e2a\u7bb1\u5b50\uff0c\u5230\u8fbe\u7801\u5934 1 \uff0c\u7136\u540e\u56de\u5230\u4ed3\u5e93\uff0c\u603b\u5171 2 \u8d9f\u884c\u7a0b\u3002\n- \u5361\u8f66\u8fd0\u8f93\u7b2c\u4e8c\u3001\u7b2c\u4e09\u3001\u7b2c\u56db\u4e2a\u7bb1\u5b50\uff0c\u5230\u8fbe\u7801\u5934 3 \uff0c\u7136\u540e\u56de\u5230\u4ed3\u5e93\uff0c\u603b\u5171 2 \u8d9f\u884c\u7a0b\u3002\n- \u5361\u8f66\u8fd0\u8f93\u7b2c\u4e94\u4e2a\u7bb1\u5b50\uff0c\u5230\u8fbe\u7801\u5934 3 \uff0c\u56de\u5230\u4ed3\u5e93\uff0c\u603b\u5171 2 \u8d9f\u884c\u7a0b\u3002\n\u603b\u884c\u7a0b\u6570\u4e3a 2 + 2 + 2 = 6 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aboxes = [[1,4],[1,2],[2,1],[2,1],[3,2],[3,4]], portsCount = 3, maxBoxes = 6, maxWeight = 7\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u6700\u4f18\u7b56\u7565\u5982\u4e0b\uff1a\n- \u5361\u8f66\u8fd0\u8f93\u7b2c\u4e00\u548c\u7b2c\u4e8c\u4e2a\u7bb1\u5b50\uff0c\u5230\u8fbe\u7801\u5934 1 \uff0c\u7136\u540e\u56de\u5230\u4ed3\u5e93\uff0c\u603b\u5171 2 \u8d9f\u884c\u7a0b\u3002\n- \u5361\u8f66\u8fd0\u8f93\u7b2c\u4e09\u548c\u7b2c\u56db\u4e2a\u7bb1\u5b50\uff0c\u5230\u8fbe\u7801\u5934 2 \uff0c\u7136\u540e\u56de\u5230\u4ed3\u5e93\uff0c\u603b\u5171 2 \u8d9f\u884c\u7a0b\u3002\n- \u5361\u8f66\u8fd0\u8f93\u7b2c\u4e94\u548c\u7b2c\u516d\u4e2a\u7bb1\u5b50\uff0c\u5230\u8fbe\u7801\u5934 3 \uff0c\u7136\u540e\u56de\u5230\u4ed3\u5e93\uff0c\u603b\u5171 2 \u8d9f\u884c\u7a0b\u3002\n\u603b\u884c\u7a0b\u6570\u4e3a 2 + 2 + 2 = 6 \u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1aboxes = [[2,4],[2,5],[3,1],[3,2],[3,7],[3,1],[4,4],[1,3],[5,2]], portsCount = 5, maxBoxes = 5, maxWeight = 7\n\u8f93\u51fa\uff1a14\n\u89e3\u91ca\uff1a\u6700\u4f18\u7b56\u7565\u5982\u4e0b\uff1a\n- \u5361\u8f66\u8fd0\u8f93\u7b2c\u4e00\u4e2a\u7bb1\u5b50\uff0c\u5230\u8fbe\u7801\u5934 2 \uff0c\u7136\u540e\u56de\u5230\u4ed3\u5e93\uff0c\u603b\u5171 2 \u8d9f\u884c\u7a0b\u3002\n- \u5361\u8f66\u8fd0\u8f93\u7b2c\u4e8c\u4e2a\u7bb1\u5b50\uff0c\u5230\u8fbe\u7801\u5934 2 \uff0c\u7136\u540e\u56de\u5230\u4ed3\u5e93\uff0c\u603b\u5171 2 \u8d9f\u884c\u7a0b\u3002\n- \u5361\u8f66\u8fd0\u8f93\u7b2c\u4e09\u548c\u7b2c\u56db\u4e2a\u7bb1\u5b50\uff0c\u5230\u8fbe\u7801\u5934 3 \uff0c\u7136\u540e\u56de\u5230\u4ed3\u5e93\uff0c\u603b\u5171 2 \u8d9f\u884c\u7a0b\u3002\n- \u5361\u8f66\u8fd0\u8f93\u7b2c\u4e94\u4e2a\u7bb1\u5b50\uff0c\u5230\u8fbe\u7801\u5934 3 \uff0c\u7136\u540e\u56de\u5230\u4ed3\u5e93\uff0c\u603b\u5171 2 \u8d9f\u884c\u7a0b\u3002\n- \u5361\u8f66\u8fd0\u8f93\u7b2c\u516d\u548c\u7b2c\u4e03\u4e2a\u7bb1\u5b50\uff0c\u5230\u8fbe\u7801\u5934 3 \uff0c\u7136\u540e\u53bb\u7801\u5934 4 \uff0c\u7136\u540e\u56de\u5230\u4ed3\u5e93\uff0c\u603b\u5171 3 \u8d9f\u884c\u7a0b\u3002\n- \u5361\u8f66\u8fd0\u8f93\u7b2c\u516b\u548c\u7b2c\u4e5d\u4e2a\u7bb1\u5b50\uff0c\u5230\u8fbe\u7801\u5934 1 \uff0c\u7136\u540e\u53bb\u7801\u5934 5 \uff0c\u7136\u540e\u56de\u5230\u4ed3\u5e93\uff0c\u603b\u5171 3 \u8d9f\u884c\u7a0b\u3002\n\u603b\u884c\u7a0b\u6570\u4e3a 2 + 2 + 2 + 2 + 3 + 3 = 14 \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= boxes.length <= 105
  • \n\t
  • 1 <= portsCount, maxBoxes, maxWeight <= 105
  • \n\t
  • 1 <= ports\u200b\u200bi <= portsCount
  • \n\t
  • 1 <= weightsi <= maxWeight
  • \n
\n", "tags_en": ["Segment Tree", "Two Pointers", "Dynamic Programming"], "tags_cn": ["\u7ebf\u6bb5\u6811", "\u53cc\u6307\u9488", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int boxDelivering(vector>& boxes, int portsCount, int maxBoxes, int maxWeight) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int boxDelivering(int[][] boxes, int portsCount, int maxBoxes, int maxWeight) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def boxDelivering(self, boxes, portsCount, maxBoxes, maxWeight):\n \"\"\"\n :type boxes: List[List[int]]\n :type portsCount: int\n :type maxBoxes: int\n :type maxWeight: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def boxDelivering(self, boxes: List[List[int]], portsCount: int, maxBoxes: int, maxWeight: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint boxDelivering(int** boxes, int boxesSize, int* boxesColSize, int portsCount, int maxBoxes, int maxWeight){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int BoxDelivering(int[][] boxes, int portsCount, int maxBoxes, int maxWeight) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} boxes\n * @param {number} portsCount\n * @param {number} maxBoxes\n * @param {number} maxWeight\n * @return {number}\n */\nvar boxDelivering = function(boxes, portsCount, maxBoxes, maxWeight) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} boxes\n# @param {Integer} ports_count\n# @param {Integer} max_boxes\n# @param {Integer} max_weight\n# @return {Integer}\ndef box_delivering(boxes, ports_count, max_boxes, max_weight)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func boxDelivering(_ boxes: [[Int]], _ portsCount: Int, _ maxBoxes: Int, _ maxWeight: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func boxDelivering(boxes [][]int, portsCount int, maxBoxes int, maxWeight int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def boxDelivering(boxes: Array[Array[Int]], portsCount: Int, maxBoxes: Int, maxWeight: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun boxDelivering(boxes: Array, portsCount: Int, maxBoxes: Int, maxWeight: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn box_delivering(boxes: Vec>, ports_count: i32, max_boxes: i32, max_weight: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $boxes\n * @param Integer $portsCount\n * @param Integer $maxBoxes\n * @param Integer $maxWeight\n * @return Integer\n */\n function boxDelivering($boxes, $portsCount, $maxBoxes, $maxWeight) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function boxDelivering(boxes: number[][], portsCount: number, maxBoxes: number, maxWeight: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (box-delivering boxes portsCount maxBoxes maxWeight)\n (-> (listof (listof exact-integer?)) exact-integer? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1687](https://leetcode-cn.com/problems/delivering-boxes-from-storage-to-ports)", "[\u4ece\u4ed3\u5e93\u5230\u7801\u5934\u8fd0\u8f93\u7bb1\u5b50](/solution/1600-1699/1687.Delivering%20Boxes%20from%20Storage%20to%20Ports/README.md)", "`\u7ebf\u6bb5\u6811`,`\u53cc\u6307\u9488`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1687](https://leetcode.com/problems/delivering-boxes-from-storage-to-ports)", "[Delivering Boxes from Storage to Ports](/solution/1600-1699/1687.Delivering%20Boxes%20from%20Storage%20to%20Ports/README_EN.md)", "`Segment Tree`,`Two Pointers`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "1788", "frontend_question_id": "1686", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/stone-game-vi", "url_en": "https://leetcode.com/problems/stone-game-vi", "relative_path_cn": "/solution/1600-1699/1686.Stone%20Game%20VI/README.md", "relative_path_en": "/solution/1600-1699/1686.Stone%20Game%20VI/README_EN.md", "title_cn": "\u77f3\u5b50\u6e38\u620f VI", "title_en": "Stone Game VI", "question_title_slug": "stone-game-vi", "content_en": "

Alice and Bob take turns playing a game, with Alice starting first.

\n\n

There are n stones in a pile. On each player's turn, they can remove a stone from the pile and receive points based on the stone's value. Alice and Bob may value the stones differently.

\n\n

You are given two integer arrays of length n, aliceValues and bobValues. Each aliceValues[i] and bobValues[i] represents how Alice and Bob, respectively, value the ith stone.

\n\n

The winner is the person with the most points after all the stones are chosen. If both players have the same amount of points, the game results in a draw. Both players will play optimally. Both players know the other's values.

\n\n

Determine the result of the game, and:

\n\n
    \n\t
  • If Alice wins, return 1.
  • \n\t
  • If Bob wins, return -1.
  • \n\t
  • If the game results in a draw, return 0.
  • \n
\n\n

 

\n

Example 1:

\n\n
\nInput: aliceValues = [1,3], bobValues = [2,1]\nOutput: 1\nExplanation:\nIf Alice takes stone 1 (0-indexed) first, Alice will receive 3 points.\nBob can only choose stone 0, and will only receive 2 points.\nAlice wins.\n
\n\n

Example 2:

\n\n
\nInput: aliceValues = [1,2], bobValues = [3,1]\nOutput: 0\nExplanation:\nIf Alice takes stone 0, and Bob takes stone 1, they will both have 1 point.\nDraw.\n
\n\n

Example 3:

\n\n
\nInput: aliceValues = [2,4,3], bobValues = [1,6,7]\nOutput: -1\nExplanation:\nRegardless of how Alice plays, Bob will be able to have more points than Alice.\nFor example, if Alice takes stone 1, Bob can take stone 2, and Alice takes stone 0, Alice will have 6 points to Bob's 7.\nBob wins.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == aliceValues.length == bobValues.length
  • \n\t
  • 1 <= n <= 105
  • \n\t
  • 1 <= aliceValues[i], bobValues[i] <= 100
  • \n
\n", "content_cn": "

Alice \u548c\u00a0Bob \u8f6e\u6d41\u73a9\u4e00\u4e2a\u6e38\u620f\uff0cAlice \u5148\u624b\u3002

\n\n

\u4e00\u5806\u77f3\u5b50\u91cc\u603b\u5171\u6709\u00a0n\u00a0\u4e2a\u77f3\u5b50\uff0c\u8f6e\u5230\u67d0\u4e2a\u73a9\u5bb6\u65f6\uff0c\u4ed6\u53ef\u4ee5 \u79fb\u51fa\u00a0\u4e00\u4e2a\u77f3\u5b50\u5e76\u5f97\u5230\u8fd9\u4e2a\u77f3\u5b50\u7684\u4ef7\u503c\u3002Alice \u548c Bob \u5bf9\u77f3\u5b50\u4ef7\u503c\u6709 \u4e0d\u4e00\u6837\u7684\u7684\u8bc4\u5224\u6807\u51c6\u00a0\u3002\u53cc\u65b9\u90fd\u77e5\u9053\u5bf9\u65b9\u7684\u8bc4\u5224\u6807\u51c6\u3002

\n\n

\u7ed9\u4f60\u4e24\u4e2a\u957f\u5ea6\u4e3a n\u00a0\u7684\u6574\u6570\u6570\u7ec4\u00a0aliceValues \u548c\u00a0bobValues\u00a0\u3002aliceValues[i] \u548c\u00a0bobValues[i]\u00a0\u5206\u522b\u8868\u793a Alice \u548c Bob \u8ba4\u4e3a\u7b2c\u00a0i\u00a0\u4e2a\u77f3\u5b50\u7684\u4ef7\u503c\u3002

\n\n

\u6240\u6709\u77f3\u5b50\u90fd\u88ab\u53d6\u5b8c\u540e\uff0c\u5f97\u5206\u8f83\u9ad8\u7684\u4eba\u4e3a\u80dc\u8005\u3002\u5982\u679c\u4e24\u4e2a\u73a9\u5bb6\u5f97\u5206\u76f8\u540c\uff0c\u90a3\u4e48\u4e3a\u5e73\u5c40\u3002\u4e24\u4f4d\u73a9\u5bb6\u90fd\u4f1a\u91c7\u7528 \u6700\u4f18\u7b56\u7565\u00a0\u8fdb\u884c\u6e38\u620f\u3002

\n\n

\u8bf7\u4f60\u63a8\u65ad\u6e38\u620f\u7684\u7ed3\u679c\uff0c\u7528\u5982\u4e0b\u7684\u65b9\u5f0f\u8868\u793a\uff1a

\n\n
    \n\t
  • \u5982\u679c Alice \u8d62\uff0c\u8fd4\u56de\u00a01\u00a0\u3002
  • \n\t
  • \u5982\u679c Bob \u8d62\uff0c\u8fd4\u56de\u00a0-1\u00a0\u3002
  • \n\t
  • \u5982\u679c\u6e38\u620f\u5e73\u5c40\uff0c\u8fd4\u56de\u00a00\u00a0\u3002
  • \n
\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aaliceValues = [1,3], bobValues = [2,1]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\n\u5982\u679c Alice \u62ff\u77f3\u5b50 1 \uff08\u4e0b\u6807\u4ece 0\u5f00\u59cb\uff09\uff0c\u90a3\u4e48 Alice \u53ef\u4ee5\u5f97\u5230 3 \u5206\u3002\nBob \u53ea\u80fd\u9009\u62e9\u77f3\u5b50 0 \uff0c\u5f97\u5230 2 \u5206\u3002\nAlice \u83b7\u80dc\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aaliceValues = [1,2], bobValues = [3,1]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\nAlice \u62ff\u77f3\u5b50 0 \uff0c Bob \u62ff\u77f3\u5b50 1 \uff0c\u4ed6\u4eec\u5f97\u5206\u90fd\u4e3a 1 \u5206\u3002\n\u6253\u5e73\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1aaliceValues = [2,4,3], bobValues = [1,6,7]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\n\u4e0d\u7ba1 Alice \u600e\u4e48\u64cd\u4f5c\uff0cBob \u90fd\u53ef\u4ee5\u5f97\u5230\u6bd4 Alice \u66f4\u9ad8\u7684\u5f97\u5206\u3002\n\u6bd4\u65b9\u8bf4\uff0cAlice \u62ff\u77f3\u5b50 1 \uff0cBob \u62ff\u77f3\u5b50 2 \uff0c Alice \u62ff\u77f3\u5b50 0 \uff0cAlice \u4f1a\u5f97\u5230 6 \u5206\u800c Bob \u5f97\u5206\u4e3a 7 \u5206\u3002\nBob \u4f1a\u83b7\u80dc\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • n == aliceValues.length == bobValues.length
  • \n\t
  • 1 <= n <= 105
  • \n\t
  • 1 <= aliceValues[i], bobValues[i] <= 100
  • \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int stoneGameVI(vector& aliceValues, vector& bobValues) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int stoneGameVI(int[] aliceValues, int[] bobValues) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def stoneGameVI(self, aliceValues, bobValues):\n \"\"\"\n :type aliceValues: List[int]\n :type bobValues: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def stoneGameVI(self, aliceValues: List[int], bobValues: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint stoneGameVI(int* aliceValues, int aliceValuesSize, int* bobValues, int bobValuesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int StoneGameVI(int[] aliceValues, int[] bobValues) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} aliceValues\n * @param {number[]} bobValues\n * @return {number}\n */\nvar stoneGameVI = function(aliceValues, bobValues) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} alice_values\n# @param {Integer[]} bob_values\n# @return {Integer}\ndef stone_game_vi(alice_values, bob_values)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func stoneGameVI(_ aliceValues: [Int], _ bobValues: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func stoneGameVI(aliceValues []int, bobValues []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def stoneGameVI(aliceValues: Array[Int], bobValues: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun stoneGameVI(aliceValues: IntArray, bobValues: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn stone_game_vi(alice_values: Vec, bob_values: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $aliceValues\n * @param Integer[] $bobValues\n * @return Integer\n */\n function stoneGameVI($aliceValues, $bobValues) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function stoneGameVI(aliceValues: number[], bobValues: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (stone-game-vi aliceValues bobValues)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1686](https://leetcode-cn.com/problems/stone-game-vi)", "[\u77f3\u5b50\u6e38\u620f VI](/solution/1600-1699/1686.Stone%20Game%20VI/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1686](https://leetcode.com/problems/stone-game-vi)", "[Stone Game VI](/solution/1600-1699/1686.Stone%20Game%20VI/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1787", "frontend_question_id": "1685", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sum-of-absolute-differences-in-a-sorted-array", "url_en": "https://leetcode.com/problems/sum-of-absolute-differences-in-a-sorted-array", "relative_path_cn": "/solution/1600-1699/1685.Sum%20of%20Absolute%20Differences%20in%20a%20Sorted%20Array/README.md", "relative_path_en": "/solution/1600-1699/1685.Sum%20of%20Absolute%20Differences%20in%20a%20Sorted%20Array/README_EN.md", "title_cn": "\u6709\u5e8f\u6570\u7ec4\u4e2d\u5dee\u7edd\u5bf9\u503c\u4e4b\u548c", "title_en": "Sum of Absolute Differences in a Sorted Array", "question_title_slug": "sum-of-absolute-differences-in-a-sorted-array", "content_en": "

You are given an integer array nums sorted in non-decreasing order.

\n\n

Build and return an integer array result with the same length as nums such that result[i] is equal to the summation of absolute differences between nums[i] and all the other elements in the array.

\n\n

In other words, result[i] is equal to sum(|nums[i]-nums[j]|) where 0 <= j < nums.length and j != i (0-indexed).

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [2,3,5]\nOutput: [4,3,5]\nExplanation: Assuming the arrays are 0-indexed, then\nresult[0] = |2-2| + |2-3| + |2-5| = 0 + 1 + 3 = 4,\nresult[1] = |3-2| + |3-3| + |3-5| = 1 + 0 + 2 = 3,\nresult[2] = |5-2| + |5-3| + |5-5| = 3 + 2 + 0 = 5.\n
\n\n

Example 2:

\n\n
\nInput: nums = [1,4,6,8,10]\nOutput: [24,15,13,15,21]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= nums.length <= 105
  • \n\t
  • 1 <= nums[i] <= nums[i + 1] <= 104
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a \u975e\u9012\u51cf\u00a0\u6709\u5e8f\u6574\u6570\u6570\u7ec4\u00a0nums\u00a0\u3002

\n\n

\u8bf7\u4f60\u5efa\u7acb\u5e76\u8fd4\u56de\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0result\uff0c\u5b83\u8ddf\u00a0nums\u00a0\u957f\u5ea6\u76f8\u540c\uff0c\u4e14result[i]\u00a0\u7b49\u4e8e\u00a0nums[i]\u00a0\u4e0e\u6570\u7ec4\u4e2d\u6240\u6709\u5176\u4ed6\u5143\u7d20\u5dee\u7684\u7edd\u5bf9\u503c\u4e4b\u548c\u3002

\n\n

\u6362\u53e5\u8bdd\u8bf4\uff0c\u00a0result[i]\u00a0\u7b49\u4e8e\u00a0sum(|nums[i]-nums[j]|) \uff0c\u5176\u4e2d\u00a00 <= j < nums.length \u4e14\u00a0j != i\u00a0\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [2,3,5]\n\u8f93\u51fa\uff1a[4,3,5]\n\u89e3\u91ca\uff1a\u5047\u8bbe\u6570\u7ec4\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff0c\u90a3\u4e48\nresult[0] = |2-2| + |2-3| + |2-5| = 0 + 1 + 3 = 4\uff0c\nresult[1] = |3-2| + |3-3| + |3-5| = 1 + 0 + 2 = 3\uff0c\nresult[2] = |5-2| + |5-3| + |5-5| = 3 + 2 + 0 = 5\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [1,4,6,8,10]\n\u8f93\u51fa\uff1a[24,15,13,15,21]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= nums.length <= 105
  • \n\t
  • 1 <= nums[i] <= nums[i + 1] <= 104
  • \n
\n", "tags_en": ["Greedy", "Math"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector getSumAbsoluteDifferences(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] getSumAbsoluteDifferences(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getSumAbsoluteDifferences(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getSumAbsoluteDifferences(self, nums: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* getSumAbsoluteDifferences(int* nums, int numsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] GetSumAbsoluteDifferences(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar getSumAbsoluteDifferences = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer[]}\ndef get_sum_absolute_differences(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getSumAbsoluteDifferences(_ nums: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getSumAbsoluteDifferences(nums []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getSumAbsoluteDifferences(nums: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getSumAbsoluteDifferences(nums: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_sum_absolute_differences(nums: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer[]\n */\n function getSumAbsoluteDifferences($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getSumAbsoluteDifferences(nums: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-sum-absolute-differences nums)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1685](https://leetcode-cn.com/problems/sum-of-absolute-differences-in-a-sorted-array)", "[\u6709\u5e8f\u6570\u7ec4\u4e2d\u5dee\u7edd\u5bf9\u503c\u4e4b\u548c](/solution/1600-1699/1685.Sum%20of%20Absolute%20Differences%20in%20a%20Sorted%20Array/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1685](https://leetcode.com/problems/sum-of-absolute-differences-in-a-sorted-array)", "[Sum of Absolute Differences in a Sorted Array](/solution/1600-1699/1685.Sum%20of%20Absolute%20Differences%20in%20a%20Sorted%20Array/README_EN.md)", "`Greedy`,`Math`", "Medium", ""]}, {"question_id": "1786", "frontend_question_id": "1684", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-the-number-of-consistent-strings", "url_en": "https://leetcode.com/problems/count-the-number-of-consistent-strings", "relative_path_cn": "/solution/1600-1699/1684.Count%20the%20Number%20of%20Consistent%20Strings/README.md", "relative_path_en": "/solution/1600-1699/1684.Count%20the%20Number%20of%20Consistent%20Strings/README_EN.md", "title_cn": "\u7edf\u8ba1\u4e00\u81f4\u5b57\u7b26\u4e32\u7684\u6570\u76ee", "title_en": "Count the Number of Consistent Strings", "question_title_slug": "count-the-number-of-consistent-strings", "content_en": "

You are given a string allowed consisting of distinct characters and an array of strings words. A string is consistent if all characters in the string appear in the string allowed.

\n\n

Return the number of consistent strings in the array words.

\n\n

 

\n

Example 1:

\n\n
\nInput: allowed = "ab", words = ["ad","bd","aaab","baa","badab"]\nOutput: 2\nExplanation: Strings "aaab" and "baa" are consistent since they only contain characters 'a' and 'b'.\n
\n\n

Example 2:

\n\n
\nInput: allowed = "abc", words = ["a","b","c","ab","ac","bc","abc"]\nOutput: 7\nExplanation: All strings are consistent.\n
\n\n

Example 3:

\n\n
\nInput: allowed = "cad", words = ["cc","acd","b","ba","bac","bad","ac","d"]\nOutput: 4\nExplanation: Strings "cc", "acd", "ac", and "d" are consistent.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= words.length <= 104
  • \n\t
  • 1 <= allowed.length <= 26
  • \n\t
  • 1 <= words[i].length <= 10
  • \n\t
  • The characters in allowed are distinct.
  • \n\t
  • words[i] and allowed contain only lowercase English letters.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u7531\u4e0d\u540c\u5b57\u7b26\u7ec4\u6210\u7684\u5b57\u7b26\u4e32\u00a0allowed\u00a0\u548c\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4\u00a0words\u00a0\u3002\u5982\u679c\u4e00\u4e2a\u5b57\u7b26\u4e32\u7684\u6bcf\u4e00\u4e2a\u5b57\u7b26\u90fd\u5728 allowed\u00a0\u4e2d\uff0c\u5c31\u79f0\u8fd9\u4e2a\u5b57\u7b26\u4e32\u662f \u4e00\u81f4\u5b57\u7b26\u4e32 \u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u00a0words\u00a0\u6570\u7ec4\u4e2d\u00a0\u4e00\u81f4\u5b57\u7b26\u4e32 \u7684\u6570\u76ee\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aallowed = \"ab\", words = [\"ad\",\"bd\",\"aaab\",\"baa\",\"badab\"]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5b57\u7b26\u4e32 \"aaab\" \u548c \"baa\" \u90fd\u662f\u4e00\u81f4\u5b57\u7b26\u4e32\uff0c\u56e0\u4e3a\u5b83\u4eec\u53ea\u5305\u542b\u5b57\u7b26 'a' \u548c 'b' \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aallowed = \"abc\", words = [\"a\",\"b\",\"c\",\"ab\",\"ac\",\"bc\",\"abc\"]\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\u6240\u6709\u5b57\u7b26\u4e32\u90fd\u662f\u4e00\u81f4\u7684\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1aallowed = \"cad\", words = [\"cc\",\"acd\",\"b\",\"ba\",\"bac\",\"bad\",\"ac\",\"d\"]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u5b57\u7b26\u4e32 \"cc\"\uff0c\"acd\"\uff0c\"ac\" \u548c \"d\" \u662f\u4e00\u81f4\u5b57\u7b26\u4e32\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= words.length <= 104
  • \n\t
  • 1 <= allowed.length <= 26
  • \n\t
  • 1 <= words[i].length <= 10
  • \n\t
  • allowed\u00a0\u4e2d\u7684\u5b57\u7b26 \u4e92\u4e0d\u76f8\u540c\u00a0\u3002
  • \n\t
  • words[i] \u548c\u00a0allowed\u00a0\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countConsistentStrings(string allowed, vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countConsistentStrings(String allowed, String[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countConsistentStrings(self, allowed, words):\n \"\"\"\n :type allowed: str\n :type words: List[str]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countConsistentStrings(self, allowed: str, words: List[str]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countConsistentStrings(char * allowed, char ** words, int wordsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountConsistentStrings(string allowed, string[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} allowed\n * @param {string[]} words\n * @return {number}\n */\nvar countConsistentStrings = function(allowed, words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} allowed\n# @param {String[]} words\n# @return {Integer}\ndef count_consistent_strings(allowed, words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countConsistentStrings(_ allowed: String, _ words: [String]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countConsistentStrings(allowed string, words []string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countConsistentStrings(allowed: String, words: Array[String]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countConsistentStrings(allowed: String, words: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_consistent_strings(allowed: String, words: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $allowed\n * @param String[] $words\n * @return Integer\n */\n function countConsistentStrings($allowed, $words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countConsistentStrings(allowed: string, words: string[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-consistent-strings allowed words)\n (-> string? (listof string?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1684](https://leetcode-cn.com/problems/count-the-number-of-consistent-strings)", "[\u7edf\u8ba1\u4e00\u81f4\u5b57\u7b26\u4e32\u7684\u6570\u76ee](/solution/1600-1699/1684.Count%20the%20Number%20of%20Consistent%20Strings/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1684](https://leetcode.com/problems/count-the-number-of-consistent-strings)", "[Count the Number of Consistent Strings](/solution/1600-1699/1684.Count%20the%20Number%20of%20Consistent%20Strings/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1785", "frontend_question_id": "1645", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/hopper-company-queries-ii", "url_en": "https://leetcode.com/problems/hopper-company-queries-ii", "relative_path_cn": "/solution/1600-1699/1645.Hopper%20Company%20Queries%20II/README.md", "relative_path_en": "/solution/1600-1699/1645.Hopper%20Company%20Queries%20II/README_EN.md", "title_cn": "", "title_en": "Hopper Company Queries II", "question_title_slug": "hopper-company-queries-ii", "content_en": "

Table: Drivers

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| driver_id   | int     |\n| join_date   | date    |\n+-------------+---------+\ndriver_id is the primary key for this table.\nEach row of this table contains the driver's ID and the date they joined the Hopper company.\n
\n\n

 

\n\n

Table: Rides

\n\n
\n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| ride_id      | int     |\n| user_id      | int     |\n| requested_at | date    |\n+--------------+---------+\nride_id is the primary key for this table.\nEach row of this table contains the ID of a ride, the user's ID that requested it, and the day they requested it.\nThere may be some ride requests in this table that were not accepted.\n
\n\n

 

\n\n

Table: AcceptedRides

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| ride_id       | int     |\n| driver_id     | int     |\n| ride_distance | int     |\n| ride_duration | int     |\n+---------------+---------+\nride_id is the primary key for this table.\nEach row of this table contains some information about an accepted ride.\nIt is guaranteed that each accepted ride exists in the Rides table.\n
\n\n

 

\n\n

Write an SQL query to report the percentage of working drivers (working_percentage) for each month of 2020 where:

\n\"\"\n

Note that if the number of available drivers during a month is zero, we consider the working_percentage to be 0.

\n\n

Return the result table ordered by month in ascending order, where month is the month's number (January is 1, February is 2, etc.). Round working_percentage to the nearest 2 decimal places.

\n\n

The query result format is in the following example.

\n\n

 

\n\n
\nDrivers table:\n+-----------+------------+\n| driver_id | join_date  |\n+-----------+------------+\n| 10        | 2019-12-10 |\n| 8         | 2020-1-13  |\n| 5         | 2020-2-16  |\n| 7         | 2020-3-8   |\n| 4         | 2020-5-17  |\n| 1         | 2020-10-24 |\n| 6         | 2021-1-5   |\n+-----------+------------+\n\nRides table:\n+---------+---------+--------------+\n| ride_id | user_id | requested_at |\n+---------+---------+--------------+\n| 6       | 75      | 2019-12-9    |\n| 1       | 54      | 2020-2-9     |\n| 10      | 63      | 2020-3-4     |\n| 19      | 39      | 2020-4-6     |\n| 3       | 41      | 2020-6-3     |\n| 13      | 52      | 2020-6-22    |\n| 7       | 69      | 2020-7-16    |\n| 17      | 70      | 2020-8-25    |\n| 20      | 81      | 2020-11-2    |\n| 5       | 57      | 2020-11-9    |\n| 2       | 42      | 2020-12-9    |\n| 11      | 68      | 2021-1-11    |\n| 15      | 32      | 2021-1-17    |\n| 12      | 11      | 2021-1-19    |\n| 14      | 18      | 2021-1-27    |\n+---------+---------+--------------+\n\nAcceptedRides table:\n+---------+-----------+---------------+---------------+\n| ride_id | driver_id | ride_distance | ride_duration |\n+---------+-----------+---------------+---------------+\n| 10      | 10        | 63            | 38            |\n| 13      | 10        | 73            | 96            |\n| 7       | 8         | 100           | 28            |\n| 17      | 7         | 119           | 68            |\n| 20      | 1         | 121           | 92            |\n| 5       | 7         | 42            | 101           |\n| 2       | 4         | 6             | 38            |\n| 11      | 8         | 37            | 43            |\n| 15      | 8         | 108           | 82            |\n| 12      | 8         | 38            | 34            |\n| 14      | 1         | 90            | 74            |\n+---------+-----------+---------------+---------------+\n\nResult table:\n+-------+--------------------+\n| month | working_percentage |\n+-------+--------------------+\n| 1     | 0.00               |\n| 2     | 0.00               |\n| 3     | 25.00              |\n| 4     | 0.00               |\n| 5     | 0.00               |\n| 6     | 20.00              |\n| 7     | 20.00              |\n| 8     | 20.00              |\n| 9     | 0.00               |\n| 10    | 0.00               |\n| 11    | 33.33              |\n| 12    | 16.67              |\n+-------+--------------------+\n\nBy the end of January --> two active drivers (10, 8) and no accepted rides. The percentage is 0%.\nBy the end of February --> three active drivers (10, 8, 5) and no accepted rides. The percentage is 0%.\nBy the end of March --> four active drivers (10, 8, 5, 7) and one accepted ride by driver (10). The percentage is (1 / 4) * 100 = 25%.\nBy the end of April --> four active drivers (10, 8, 5, 7) and no accepted rides. The percentage is 0%.\nBy the end of May --> five active drivers (10, 8, 5, 7, 4) and no accepted rides. The percentage is 0%.\nBy the end of June --> five active drivers (10, 8, 5, 7, 4) and one accepted ride by driver (10). The percentage is (1 / 5) * 100 = 20%.\nBy the end of July --> five active drivers (10, 8, 5, 7, 4) and one accepted ride by driver (8). The percentage is (1 / 5) * 100 = 20%.\nBy the end of August --> five active drivers (10, 8, 5, 7, 4) and one accepted ride by driver (7). The percentage is (1 / 5) * 100 = 20%.\nBy the end of Septemeber --> five active drivers (10, 8, 5, 7, 4) and no accepted rides. The percentage is 0%.\nBy the end of October --> six active drivers (10, 8, 5, 7, 4, 1) and no accepted rides. The percentage is 0%.\nBy the end of November --> six active drivers (10, 8, 5, 7, 4, 1) and two accepted rides by two different drivers (1, 7). The percentage is (2 / 6) * 100 = 33.33%.\nBy the end of December --> six active drivers (10, 8, 5, 7, 4, 1) and one accepted ride by driver (4). The percentage is (1 / 6) * 100 = 16.67%.\n
\n", "content_cn": null, "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1645](https://leetcode-cn.com/problems/hopper-company-queries-ii)", "[Hopper Company Queries II](/solution/1600-1699/1645.Hopper%20Company%20Queries%20II/README_EN.md)", "", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1645](https://leetcode.com/problems/hopper-company-queries-ii)", "[Hopper Company Queries II](/solution/1600-1699/1645.Hopper%20Company%20Queries%20II/README_EN.md)", "", "Hard", "\ud83d\udd12"]}, {"question_id": "1784", "frontend_question_id": "1665", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-initial-energy-to-finish-tasks", "url_en": "https://leetcode.com/problems/minimum-initial-energy-to-finish-tasks", "relative_path_cn": "/solution/1600-1699/1665.Minimum%20Initial%20Energy%20to%20Finish%20Tasks/README.md", "relative_path_en": "/solution/1600-1699/1665.Minimum%20Initial%20Energy%20to%20Finish%20Tasks/README_EN.md", "title_cn": "\u5b8c\u6210\u6240\u6709\u4efb\u52a1\u7684\u6700\u5c11\u521d\u59cb\u80fd\u91cf", "title_en": "Minimum Initial Energy to Finish Tasks", "question_title_slug": "minimum-initial-energy-to-finish-tasks", "content_en": "

You are given an array tasks where tasks[i] = [actuali, minimumi]:

\n\n
    \n\t
  • actuali is the actual amount of energy you spend to finish the ith task.
  • \n\t
  • minimumi is the minimum amount of energy you require to begin the ith task.
  • \n
\n\n

For example, if the task is [10, 12] and your current energy is 11, you cannot start this task. However, if your current energy is 13, you can complete this task, and your energy will be 3 after finishing it.

\n\n

You can finish the tasks in any order you like.

\n\n

Return the minimum initial amount of energy you will need to finish all the tasks.

\n\n

 

\n

Example 1:

\n\n
\nInput: tasks = [[1,2],[2,4],[4,8]]\nOutput: 8\nExplanation:\nStarting with 8 energy, we finish the tasks in the following order:\n    - 3rd task. Now energy = 8 - 4 = 4.\n    - 2nd task. Now energy = 4 - 2 = 2.\n    - 1st task. Now energy = 2 - 1 = 1.\nNotice that even though we have leftover energy, starting with 7 energy does not work because we cannot do the 3rd task.
\n\n

Example 2:

\n\n
\nInput: tasks = [[1,3],[2,4],[10,11],[10,12],[8,9]]\nOutput: 32\nExplanation:\nStarting with 32 energy, we finish the tasks in the following order:\n    - 1st task. Now energy = 32 - 1 = 31.\n    - 2nd task. Now energy = 31 - 2 = 29.\n    - 3rd task. Now energy = 29 - 10 = 19.\n    - 4th task. Now energy = 19 - 10 = 9.\n    - 5th task. Now energy = 9 - 8 = 1.
\n\n

Example 3:

\n\n
\nInput: tasks = [[1,7],[2,8],[3,9],[4,10],[5,11],[6,12]]\nOutput: 27\nExplanation:\nStarting with 27 energy, we finish the tasks in the following order:\n    - 5th task. Now energy = 27 - 5 = 22.\n    - 2nd task. Now energy = 22 - 2 = 20.\n    - 3rd task. Now energy = 20 - 3 = 17.\n    - 1st task. Now energy = 17 - 1 = 16.\n    - 4th task. Now energy = 16 - 4 = 12.\n    - 6th task. Now energy = 12 - 6 = 6.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= tasks.length <= 105
  • \n\t
  • 1 <= actual\u200bi <= minimumi <= 104
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u4efb\u52a1\u6570\u7ec4\u00a0tasks \uff0c\u5176\u4e2d\u00a0tasks[i] = [actuali, minimumi]\u00a0\uff1a

\n\n
    \n\t
  • actuali\u00a0\u662f\u5b8c\u6210\u7b2c i\u00a0\u4e2a\u4efb\u52a1 \u9700\u8981\u8017\u8d39\u00a0\u7684\u5b9e\u9645\u80fd\u91cf\u3002
  • \n\t
  • minimumi\u00a0\u662f\u5f00\u59cb\u7b2c i\u00a0\u4e2a\u4efb\u52a1\u524d\u9700\u8981\u8fbe\u5230\u7684\u6700\u4f4e\u80fd\u91cf\u3002
  • \n
\n\n

\u6bd4\u65b9\u8bf4\uff0c\u5982\u679c\u4efb\u52a1\u4e3a\u00a0[10, 12]\u00a0\u4e14\u4f60\u5f53\u524d\u7684\u80fd\u91cf\u4e3a\u00a011\u00a0\uff0c\u90a3\u4e48\u4f60\u4e0d\u80fd\u5f00\u59cb\u8fd9\u4e2a\u4efb\u52a1\u3002\u5982\u679c\u4f60\u5f53\u524d\u7684\u80fd\u91cf\u4e3a\u00a013\u00a0\uff0c\u4f60\u53ef\u4ee5\u5b8c\u6210\u8fd9\u4e2a\u4efb\u52a1\uff0c\u4e14\u5b8c\u6210\u5b83\u540e\u5269\u4f59\u80fd\u91cf\u4e3a 3\u00a0\u3002

\n\n

\u4f60\u53ef\u4ee5\u6309\u7167 \u4efb\u610f\u987a\u5e8f\u00a0\u5b8c\u6210\u4efb\u52a1\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u5b8c\u6210\u6240\u6709\u4efb\u52a1\u7684 \u6700\u5c11\u00a0\u521d\u59cb\u80fd\u91cf\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1atasks = [[1,2],[2,4],[4,8]]\n\u8f93\u51fa\uff1a8\n\u89e3\u91ca\uff1a\n\u4e00\u5f00\u59cb\u6709 8 \u80fd\u91cf\uff0c\u6211\u4eec\u6309\u7167\u5982\u4e0b\u987a\u5e8f\u5b8c\u6210\u4efb\u52a1\uff1a\n    - \u5b8c\u6210\u7b2c 3 \u4e2a\u4efb\u52a1\uff0c\u5269\u4f59\u80fd\u91cf\u4e3a 8 - 4 = 4 \u3002\n    - \u5b8c\u6210\u7b2c 2 \u4e2a\u4efb\u52a1\uff0c\u5269\u4f59\u80fd\u91cf\u4e3a 4 - 2 = 2 \u3002\n    - \u5b8c\u6210\u7b2c 1 \u4e2a\u4efb\u52a1\uff0c\u5269\u4f59\u80fd\u91cf\u4e3a 2 - 1 = 1 \u3002\n\u6ce8\u610f\u5230\u5c3d\u7ba1\u6211\u4eec\u6709\u80fd\u91cf\u5269\u4f59\uff0c\u4f46\u662f\u5982\u679c\u4e00\u5f00\u59cb\u53ea\u6709 7 \u80fd\u91cf\u662f\u4e0d\u80fd\u5b8c\u6210\u6240\u6709\u4efb\u52a1\u7684\uff0c\u56e0\u4e3a\u6211\u4eec\u65e0\u6cd5\u5f00\u59cb\u7b2c 3 \u4e2a\u4efb\u52a1\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1atasks = [[1,3],[2,4],[10,11],[10,12],[8,9]]\n\u8f93\u51fa\uff1a32\n\u89e3\u91ca\uff1a\n\u4e00\u5f00\u59cb\u6709 32 \u80fd\u91cf\uff0c\u6211\u4eec\u6309\u7167\u5982\u4e0b\u987a\u5e8f\u5b8c\u6210\u4efb\u52a1\uff1a\n    - \u5b8c\u6210\u7b2c 1 \u4e2a\u4efb\u52a1\uff0c\u5269\u4f59\u80fd\u91cf\u4e3a 32 - 1 = 31 \u3002\n    - \u5b8c\u6210\u7b2c 2 \u4e2a\u4efb\u52a1\uff0c\u5269\u4f59\u80fd\u91cf\u4e3a 31 - 2 = 29 \u3002\n    - \u5b8c\u6210\u7b2c 3 \u4e2a\u4efb\u52a1\uff0c\u5269\u4f59\u80fd\u91cf\u4e3a 29 - 10 = 19 \u3002\n    - \u5b8c\u6210\u7b2c 4 \u4e2a\u4efb\u52a1\uff0c\u5269\u4f59\u80fd\u91cf\u4e3a 19 - 10 = 9 \u3002\n    - \u5b8c\u6210\u7b2c 5 \u4e2a\u4efb\u52a1\uff0c\u5269\u4f59\u80fd\u91cf\u4e3a 9 - 8 = 1 \u3002
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1atasks = [[1,7],[2,8],[3,9],[4,10],[5,11],[6,12]]\n\u8f93\u51fa\uff1a27\n\u89e3\u91ca\uff1a\n\u4e00\u5f00\u59cb\u6709 27 \u80fd\u91cf\uff0c\u6211\u4eec\u6309\u7167\u5982\u4e0b\u987a\u5e8f\u5b8c\u6210\u4efb\u52a1\uff1a\n    - \u5b8c\u6210\u7b2c 5 \u4e2a\u4efb\u52a1\uff0c\u5269\u4f59\u80fd\u91cf\u4e3a 27 - 5 = 22 \u3002\n    - \u5b8c\u6210\u7b2c 2 \u4e2a\u4efb\u52a1\uff0c\u5269\u4f59\u80fd\u91cf\u4e3a 22 - 2 = 20 \u3002\n    - \u5b8c\u6210\u7b2c 3 \u4e2a\u4efb\u52a1\uff0c\u5269\u4f59\u80fd\u91cf\u4e3a 20 - 3 = 17 \u3002\n    - \u5b8c\u6210\u7b2c 1 \u4e2a\u4efb\u52a1\uff0c\u5269\u4f59\u80fd\u91cf\u4e3a 17 - 1 = 16 \u3002\n    - \u5b8c\u6210\u7b2c 4 \u4e2a\u4efb\u52a1\uff0c\u5269\u4f59\u80fd\u91cf\u4e3a 16 - 4 = 12 \u3002\n    - \u5b8c\u6210\u7b2c 6 \u4e2a\u4efb\u52a1\uff0c\u5269\u4f59\u80fd\u91cf\u4e3a 12 - 6 = 6 \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= tasks.length <= 105
  • \n\t
  • 1 <= actual\u200bi\u00a0<= minimumi\u00a0<= 104
  • \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minimumEffort(vector>& tasks) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minimumEffort(int[][] tasks) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimumEffort(self, tasks):\n \"\"\"\n :type tasks: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimumEffort(self, tasks: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minimumEffort(int** tasks, int tasksSize, int* tasksColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinimumEffort(int[][] tasks) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} tasks\n * @return {number}\n */\nvar minimumEffort = function(tasks) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} tasks\n# @return {Integer}\ndef minimum_effort(tasks)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimumEffort(_ tasks: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimumEffort(tasks [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimumEffort(tasks: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimumEffort(tasks: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimum_effort(tasks: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $tasks\n * @return Integer\n */\n function minimumEffort($tasks) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimumEffort(tasks: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimum-effort tasks)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1665](https://leetcode-cn.com/problems/minimum-initial-energy-to-finish-tasks)", "[\u5b8c\u6210\u6240\u6709\u4efb\u52a1\u7684\u6700\u5c11\u521d\u59cb\u80fd\u91cf](/solution/1600-1699/1665.Minimum%20Initial%20Energy%20to%20Finish%20Tasks/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[1665](https://leetcode.com/problems/minimum-initial-energy-to-finish-tasks)", "[Minimum Initial Energy to Finish Tasks](/solution/1600-1699/1665.Minimum%20Initial%20Energy%20to%20Finish%20Tasks/README_EN.md)", "`Greedy`", "Hard", ""]}, {"question_id": "1783", "frontend_question_id": "1664", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/ways-to-make-a-fair-array", "url_en": "https://leetcode.com/problems/ways-to-make-a-fair-array", "relative_path_cn": "/solution/1600-1699/1664.Ways%20to%20Make%20a%20Fair%20Array/README.md", "relative_path_en": "/solution/1600-1699/1664.Ways%20to%20Make%20a%20Fair%20Array/README_EN.md", "title_cn": "\u751f\u6210\u5e73\u8861\u6570\u7ec4\u7684\u65b9\u6848\u6570", "title_en": "Ways to Make a Fair Array", "question_title_slug": "ways-to-make-a-fair-array", "content_en": "

You are given an integer array nums. You can choose exactly one index (0-indexed) and remove the element. Notice that the index of the elements may change after the removal.

\n\n

For example, if nums = [6,1,7,4,1]:

\n\n
    \n\t
  • Choosing to remove index 1 results in nums = [6,7,4,1].
  • \n\t
  • Choosing to remove index 2 results in nums = [6,1,4,1].
  • \n\t
  • Choosing to remove index 4 results in nums = [6,1,7,4].
  • \n
\n\n

An array is fair if the sum of the odd-indexed values equals the sum of the even-indexed values.

\n\n

Return the number of indices that you could choose such that after the removal, nums is fair.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [2,1,6,4]\nOutput: 1\nExplanation:\nRemove index 0: [1,6,4] -> Even sum: 1 + 4 = 5. Odd sum: 6. Not fair.\nRemove index 1: [2,6,4] -> Even sum: 2 + 4 = 6. Odd sum: 6. Fair.\nRemove index 2: [2,1,4] -> Even sum: 2 + 4 = 6. Odd sum: 1. Not fair.\nRemove index 3: [2,1,6] -> Even sum: 2 + 6 = 8. Odd sum: 1. Not fair.\nThere is 1 index that you can remove to make nums fair.\n
\n\n

Example 2:

\n\n
\nInput: nums = [1,1,1]\nOutput: 3\nExplanation: You can remove any index and the remaining array is fair.\n
\n\n

Example 3:

\n\n
\nInput: nums = [1,2,3]\nOutput: 0\nExplanation: You cannot make a fair array after removing any index.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 105
  • \n\t
  • 1 <= nums[i] <= 104
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0nums\u00a0\u3002\u4f60\u9700\u8981\u9009\u62e9 \u6070\u597d\u00a0\u4e00\u4e2a\u4e0b\u6807\uff08\u4e0b\u6807\u4ece 0\u00a0\u5f00\u59cb\uff09\u5e76\u5220\u9664\u5bf9\u5e94\u7684\u5143\u7d20\u3002\u8bf7\u6ce8\u610f\u5269\u4e0b\u5143\u7d20\u7684\u4e0b\u6807\u53ef\u80fd\u4f1a\u56e0\u4e3a\u5220\u9664\u64cd\u4f5c\u800c\u53d1\u751f\u6539\u53d8\u3002

\n\n

\u6bd4\u65b9\u8bf4\uff0c\u5982\u679c\u00a0nums = [6,1,7,4,1]\u00a0\uff0c\u90a3\u4e48\uff1a

\n\n
    \n\t
  • \u9009\u62e9\u5220\u9664\u4e0b\u6807 1 \uff0c\u5269\u4e0b\u7684\u6570\u7ec4\u4e3a\u00a0nums = [6,7,4,1]\u00a0\u3002
  • \n\t
  • \u9009\u62e9\u5220\u9664\u4e0b\u6807\u00a02\u00a0\uff0c\u5269\u4e0b\u7684\u6570\u7ec4\u4e3a\u00a0nums = [6,1,4,1]\u00a0\u3002
  • \n\t
  • \u9009\u62e9\u5220\u9664\u4e0b\u6807\u00a04\u00a0\uff0c\u5269\u4e0b\u7684\u6570\u7ec4\u4e3a\u00a0nums = [6,1,7,4]\u00a0\u3002
  • \n
\n\n

\u5982\u679c\u4e00\u4e2a\u6570\u7ec4\u6ee1\u8db3\u5947\u6570\u4e0b\u6807\u5143\u7d20\u7684\u548c\u4e0e\u5076\u6570\u4e0b\u6807\u5143\u7d20\u7684\u548c\u76f8\u7b49\uff0c\u8be5\u6570\u7ec4\u5c31\u662f\u4e00\u4e2a \u5e73\u8861\u6570\u7ec4 \u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u5220\u9664\u64cd\u4f5c\u540e\uff0c\u5269\u4e0b\u7684\u6570\u7ec4\u00a0nums\u00a0\u662f\u00a0\u5e73\u8861\u6570\u7ec4 \u7684\u00a0\u65b9\u6848\u6570\u00a0\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [2,1,6,4]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\n\u5220\u9664\u4e0b\u6807 0 \uff1a[1,6,4] -> \u5076\u6570\u5143\u7d20\u4e0b\u6807\u4e3a\uff1a1 + 4 = 5 \u3002\u5947\u6570\u5143\u7d20\u4e0b\u6807\u4e3a\uff1a6 \u3002\u4e0d\u5e73\u8861\u3002\n\u5220\u9664\u4e0b\u6807 1 \uff1a[2,6,4] -> \u5076\u6570\u5143\u7d20\u4e0b\u6807\u4e3a\uff1a2 + 4 = 6 \u3002\u5947\u6570\u5143\u7d20\u4e0b\u6807\u4e3a\uff1a6 \u3002\u5e73\u8861\u3002\n\u5220\u9664\u4e0b\u6807 2 \uff1a[2,1,4] -> \u5076\u6570\u5143\u7d20\u4e0b\u6807\u4e3a\uff1a2 + 4 = 6 \u3002\u5947\u6570\u5143\u7d20\u4e0b\u6807\u4e3a\uff1a1 \u3002\u4e0d\u5e73\u8861\u3002\n\u5220\u9664\u4e0b\u6807 3 \uff1a[2,1,6] -> \u5076\u6570\u5143\u7d20\u4e0b\u6807\u4e3a\uff1a2 + 6 = 8 \u3002\u5947\u6570\u5143\u7d20\u4e0b\u6807\u4e3a\uff1a1 \u3002\u4e0d\u5e73\u8861\u3002\n\u53ea\u6709\u4e00\u79cd\u8ba9\u5269\u4f59\u6570\u7ec4\u6210\u4e3a\u5e73\u8861\u6570\u7ec4\u7684\u65b9\u6848\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [1,1,1]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u5220\u9664\u4efb\u610f\u5143\u7d20\uff0c\u5269\u4f59\u6570\u7ec4\u90fd\u662f\u5e73\u8861\u6570\u7ec4\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [1,2,3]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u4e0d\u7ba1\u5220\u9664\u54ea\u4e2a\u5143\u7d20\uff0c\u5269\u4e0b\u6570\u7ec4\u90fd\u4e0d\u662f\u5e73\u8861\u6570\u7ec4\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 105
  • \n\t
  • 1 <= nums[i] <= 104
  • \n
\n", "tags_en": ["Greedy", "Dynamic Programming"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int waysToMakeFair(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int waysToMakeFair(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def waysToMakeFair(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def waysToMakeFair(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint waysToMakeFair(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int WaysToMakeFair(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar waysToMakeFair = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef ways_to_make_fair(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func waysToMakeFair(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func waysToMakeFair(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def waysToMakeFair(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun waysToMakeFair(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn ways_to_make_fair(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function waysToMakeFair($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function waysToMakeFair(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (ways-to-make-fair nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1664](https://leetcode-cn.com/problems/ways-to-make-a-fair-array)", "[\u751f\u6210\u5e73\u8861\u6570\u7ec4\u7684\u65b9\u6848\u6570](/solution/1600-1699/1664.Ways%20to%20Make%20a%20Fair%20Array/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1664](https://leetcode.com/problems/ways-to-make-a-fair-array)", "[Ways to Make a Fair Array](/solution/1600-1699/1664.Ways%20to%20Make%20a%20Fair%20Array/README_EN.md)", "`Greedy`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "1782", "frontend_question_id": "1663", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/smallest-string-with-a-given-numeric-value", "url_en": "https://leetcode.com/problems/smallest-string-with-a-given-numeric-value", "relative_path_cn": "/solution/1600-1699/1663.Smallest%20String%20With%20A%20Given%20Numeric%20Value/README.md", "relative_path_en": "/solution/1600-1699/1663.Smallest%20String%20With%20A%20Given%20Numeric%20Value/README_EN.md", "title_cn": "\u5177\u6709\u7ed9\u5b9a\u6570\u503c\u7684\u6700\u5c0f\u5b57\u7b26\u4e32", "title_en": "Smallest String With A Given Numeric Value", "question_title_slug": "smallest-string-with-a-given-numeric-value", "content_en": "

The numeric value of a lowercase character is defined as its position (1-indexed) in the alphabet, so the numeric value of a is 1, the numeric value of b is 2, the numeric value of c is 3, and so on.

\n\n

The numeric value of a string consisting of lowercase characters is defined as the sum of its characters' numeric values. For example, the numeric value of the string "abe" is equal to 1 + 2 + 5 = 8.

\n\n

You are given two integers n and k. Return the lexicographically smallest string with length equal to n and numeric value equal to k.

\n\n

Note that a string x is lexicographically smaller than string y if x comes before y in dictionary order, that is, either x is a prefix of y, or if i is the first position such that x[i] != y[i], then x[i] comes before y[i] in alphabetic order.

\n\n

 

\n

Example 1:

\n\n
\nInput: n = 3, k = 27\nOutput: "aay"\nExplanation: The numeric value of the string is 1 + 1 + 25 = 27, and it is the smallest string with such a value and length equal to 3.\n
\n\n

Example 2:

\n\n
\nInput: n = 5, k = 73\nOutput: "aaszz"\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 105
  • \n\t
  • n <= k <= 26 * n
  • \n
\n", "content_cn": "

\u5c0f\u5199\u5b57\u7b26 \u7684 \u6570\u503c \u662f\u5b83\u5728\u5b57\u6bcd\u8868\u4e2d\u7684\u4f4d\u7f6e\uff08\u4ece 1 \u5f00\u59cb\uff09\uff0c\u56e0\u6b64 a \u7684\u6570\u503c\u4e3a 1 \uff0cb \u7684\u6570\u503c\u4e3a 2 \uff0cc \u7684\u6570\u503c\u4e3a 3 \uff0c\u4ee5\u6b64\u7c7b\u63a8\u3002

\n\n

\u5b57\u7b26\u4e32\u7531\u82e5\u5e72\u5c0f\u5199\u5b57\u7b26\u7ec4\u6210\uff0c\u5b57\u7b26\u4e32\u7684\u6570\u503c \u4e3a\u5404\u5b57\u7b26\u7684\u6570\u503c\u4e4b\u548c\u3002\u4f8b\u5982\uff0c\u5b57\u7b26\u4e32 \"abe\" \u7684\u6570\u503c\u7b49\u4e8e 1 + 2 + 5 = 8 \u3002

\n\n

\u7ed9\u4f60\u4e24\u4e2a\u6574\u6570 n \u548c k \u3002\u8fd4\u56de \u957f\u5ea6 \u7b49\u4e8e n \u4e14 \u6570\u503c \u7b49\u4e8e k \u7684 \u5b57\u5178\u5e8f\u6700\u5c0f \u7684\u5b57\u7b26\u4e32\u3002

\n\n

\u6ce8\u610f\uff0c\u5982\u679c\u5b57\u7b26\u4e32 x \u5728\u5b57\u5178\u6392\u5e8f\u4e2d\u4f4d\u4e8e y \u4e4b\u524d\uff0c\u5c31\u8ba4\u4e3a x \u5b57\u5178\u5e8f\u6bd4 y \u5c0f\uff0c\u6709\u4ee5\u4e0b\u4e24\u79cd\u60c5\u51b5\uff1a

\n\n
    \n\t
  • x \u662f y \u7684\u4e00\u4e2a\u524d\u7f00\uff1b
  • \n\t
  • \u5982\u679c i \u662f\u00a0x[i] != y[i] \u7684\u7b2c\u4e00\u4e2a\u4f4d\u7f6e\uff0c\u4e14 x[i]\u00a0\u5728\u5b57\u6bcd\u8868\u4e2d\u7684\u4f4d\u7f6e\u6bd4\u00a0y[i]\u00a0\u9760\u524d\u3002
  • \n
\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1an = 3, k = 27\n\u8f93\u51fa\uff1a\"aay\"\n\u89e3\u91ca\uff1a\u5b57\u7b26\u4e32\u7684\u6570\u503c\u4e3a 1 + 1 + 25 = 27\uff0c\u5b83\u662f\u6570\u503c\u6ee1\u8db3\u8981\u6c42\u4e14\u957f\u5ea6\u7b49\u4e8e 3 \u5b57\u5178\u5e8f\u6700\u5c0f\u7684\u5b57\u7b26\u4e32\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1an = 5, k = 73\n\u8f93\u51fa\uff1a\"aaszz\"\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 105
  • \n\t
  • n <= k <= 26 * n
  • \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string getSmallestString(int n, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String getSmallestString(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getSmallestString(self, n, k):\n \"\"\"\n :type n: int\n :type k: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getSmallestString(self, n: int, k: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * getSmallestString(int n, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string GetSmallestString(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} k\n * @return {string}\n */\nvar getSmallestString = function(n, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} k\n# @return {String}\ndef get_smallest_string(n, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getSmallestString(_ n: Int, _ k: Int) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getSmallestString(n int, k int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getSmallestString(n: Int, k: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getSmallestString(n: Int, k: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_smallest_string(n: i32, k: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $k\n * @return String\n */\n function getSmallestString($n, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getSmallestString(n: number, k: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-smallest-string n k)\n (-> exact-integer? exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1663](https://leetcode-cn.com/problems/smallest-string-with-a-given-numeric-value)", "[\u5177\u6709\u7ed9\u5b9a\u6570\u503c\u7684\u6700\u5c0f\u5b57\u7b26\u4e32](/solution/1600-1699/1663.Smallest%20String%20With%20A%20Given%20Numeric%20Value/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1663](https://leetcode.com/problems/smallest-string-with-a-given-numeric-value)", "[Smallest String With A Given Numeric Value](/solution/1600-1699/1663.Smallest%20String%20With%20A%20Given%20Numeric%20Value/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1781", "frontend_question_id": "1662", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/check-if-two-string-arrays-are-equivalent", "url_en": "https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent", "relative_path_cn": "/solution/1600-1699/1662.Check%20If%20Two%20String%20Arrays%20are%20Equivalent/README.md", "relative_path_en": "/solution/1600-1699/1662.Check%20If%20Two%20String%20Arrays%20are%20Equivalent/README_EN.md", "title_cn": "\u68c0\u67e5\u4e24\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4\u662f\u5426\u76f8\u7b49", "title_en": "Check If Two String Arrays are Equivalent", "question_title_slug": "check-if-two-string-arrays-are-equivalent", "content_en": "

Given two string arrays word1 and word2, return true if the two arrays represent the same string, and false otherwise.

\n\n

A string is represented by an array if the array elements concatenated in order forms the string.

\n\n

 

\n

Example 1:

\n\n
\nInput: word1 = ["ab", "c"], word2 = ["a", "bc"]\nOutput: true\nExplanation:\nword1 represents string "ab" + "c" -> "abc"\nword2 represents string "a" + "bc" -> "abc"\nThe strings are the same, so return true.
\n\n

Example 2:

\n\n
\nInput: word1 = ["a", "cb"], word2 = ["ab", "c"]\nOutput: false\n
\n\n

Example 3:

\n\n
\nInput: word1  = ["abc", "d", "defg"], word2 = ["abcddefg"]\nOutput: true\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= word1.length, word2.length <= 103
  • \n\t
  • 1 <= word1[i].length, word2[i].length <= 103
  • \n\t
  • 1 <= sum(word1[i].length), sum(word2[i].length) <= 103
  • \n\t
  • word1[i] and word2[i] consist of lowercase letters.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e24\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4 word1 \u548c word2 \u3002\u5982\u679c\u4e24\u4e2a\u6570\u7ec4\u8868\u793a\u7684\u5b57\u7b26\u4e32\u76f8\u540c\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

\n\n

\u6570\u7ec4\u8868\u793a\u7684\u5b57\u7b26\u4e32\u00a0\u662f\u7531\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20 \u6309\u987a\u5e8f \u8fde\u63a5\u5f62\u6210\u7684\u5b57\u7b26\u4e32\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aword1 = [\"ab\", \"c\"], word2 = [\"a\", \"bc\"]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\nword1 \u8868\u793a\u7684\u5b57\u7b26\u4e32\u4e3a \"ab\" + \"c\" -> \"abc\"\nword2 \u8868\u793a\u7684\u5b57\u7b26\u4e32\u4e3a \"a\" + \"bc\" -> \"abc\"\n\u4e24\u4e2a\u5b57\u7b26\u4e32\u76f8\u540c\uff0c\u8fd4\u56de true
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aword1 = [\"a\", \"cb\"], word2 = [\"ab\", \"c\"]\n\u8f93\u51fa\uff1afalse\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1aword1  = [\"abc\", \"d\", \"defg\"], word2 = [\"abcddefg\"]\n\u8f93\u51fa\uff1atrue\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= word1.length, word2.length <= 103
  • \n\t
  • 1 <= word1[i].length, word2[i].length <= 103
  • \n\t
  • 1 <= sum(word1[i].length), sum(word2[i].length) <= 103
  • \n\t
  • word1[i] \u548c word2[i] \u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool arrayStringsAreEqual(vector& word1, vector& word2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean arrayStringsAreEqual(String[] word1, String[] word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def arrayStringsAreEqual(self, word1, word2):\n \"\"\"\n :type word1: List[str]\n :type word2: List[str]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool arrayStringsAreEqual(char ** word1, int word1Size, char ** word2, int word2Size){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool ArrayStringsAreEqual(string[] word1, string[] word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} word1\n * @param {string[]} word2\n * @return {boolean}\n */\nvar arrayStringsAreEqual = function(word1, word2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} word1\n# @param {String[]} word2\n# @return {Boolean}\ndef array_strings_are_equal(word1, word2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func arrayStringsAreEqual(_ word1: [String], _ word2: [String]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func arrayStringsAreEqual(word1 []string, word2 []string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def arrayStringsAreEqual(word1: Array[String], word2: Array[String]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun arrayStringsAreEqual(word1: Array, word2: Array): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn array_strings_are_equal(word1: Vec, word2: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $word1\n * @param String[] $word2\n * @return Boolean\n */\n function arrayStringsAreEqual($word1, $word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function arrayStringsAreEqual(word1: string[], word2: string[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (array-strings-are-equal word1 word2)\n (-> (listof string?) (listof string?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1662](https://leetcode-cn.com/problems/check-if-two-string-arrays-are-equivalent)", "[\u68c0\u67e5\u4e24\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4\u662f\u5426\u76f8\u7b49](/solution/1600-1699/1662.Check%20If%20Two%20String%20Arrays%20are%20Equivalent/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1662](https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent)", "[Check If Two String Arrays are Equivalent](/solution/1600-1699/1662.Check%20If%20Two%20String%20Arrays%20are%20Equivalent/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1780", "frontend_question_id": "1644", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-tree-ii", "url_en": "https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree-ii", "relative_path_cn": "/solution/1600-1699/1644.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree%20II/README.md", "relative_path_en": "/solution/1600-1699/1644.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree%20II/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148 II", "title_en": "Lowest Common Ancestor of a Binary Tree II", "question_title_slug": "lowest-common-ancestor-of-a-binary-tree-ii", "content_en": "

Given the root of a binary tree, return the lowest common ancestor (LCA) of two given nodes, p and q. If either node p or q does not exist in the tree, return null. All values of the nodes in the tree are unique.

\n\n

According to the definition of LCA on Wikipedia: "The lowest common ancestor of two nodes p and q in a binary tree T is the lowest node that has both p and q as descendants (where we allow a node to be a descendant of itself)". A descendant of a node x is a node y that is on the path from node x to some leaf node.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 1\nOutput: 3\nExplanation: The LCA of nodes 5 and 1 is 3.
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 4\nOutput: 5\nExplanation: The LCA of nodes 5 and 4 is 5. A node can be a descendant of itself according to the definition of LCA.
\n\n

Example 3:

\n\n

\"\"

\n\n
\nInput: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 10\nOutput: null\nExplanation: Node 10 does not exist in the tree, so return null.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The number of nodes in the tree is in the range [1, 104].
  • \n\t
  • -109 <= Node.val <= 109
  • \n\t
  • All Node.val are unique.
  • \n\t
  • p != q
  • \n
\n\n

 

\nFollow up: Can you find the LCA traversing the tree, without checking nodes existence?", "content_cn": "

\u7ed9\u5b9a\u4e00\u68f5\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9 root\uff0c\u8fd4\u56de\u7ed9\u5b9a\u8282\u70b9 p \u548c q \u7684\u6700\u8fd1\u516c\u5171\u7956\u5148\uff08LCA\uff09\u8282\u70b9\u3002\u5982\u679c p \u6216 q \u4e4b\u4e00\u4e0d\u5b58\u5728\u4e8e\u8be5\u4e8c\u53c9\u6811\u4e2d\uff0c\u8fd4\u56de null\u3002\u6811\u4e2d\u7684\u6bcf\u4e2a\u8282\u70b9\u503c\u90fd\u662f\u4e92\u4e0d\u76f8\u540c\u7684\u3002

\n\n

\u6839\u636e\u7ef4\u57fa\u767e\u79d1\u4e2d\u5bf9\u6700\u8fd1\u516c\u5171\u7956\u5148\u8282\u70b9\u7684\u5b9a\u4e49\uff1a\u201c\u4e24\u4e2a\u8282\u70b9 p \u548c q \u5728\u4e8c\u53c9\u6811 T \u4e2d\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148\u8282\u70b9\u662f\u540e\u4ee3\u8282\u70b9\u4e2d\u65e2\u5305\u62ec p\u00a0\u53c8\u5305\u62ec\u00a0q\u00a0\u7684\u6700\u6df1\u8282\u70b9\uff08\u6211\u4eec\u5141\u8bb8\u4e00\u4e2a\u8282\u70b9\u4e3a\u81ea\u8eab\u7684\u4e00\u4e2a\u540e\u4ee3\u8282\u70b9\uff09\u201d\u3002\u4e00\u4e2a\u8282\u70b9 x\u00a0\u7684\u540e\u4ee3\u8282\u70b9\u662f\u8282\u70b9\u00a0x \u5230\u67d0\u4e00\u53f6\u8282\u70b9\u95f4\u7684\u8def\u5f84\u4e2d\u7684\u8282\u70b9 y\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1:

\n\"\"\n
\u8f93\u5165\uff1a root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 1\n\u8f93\u51fa\uff1a 3\n\u89e3\u91ca\uff1a \u8282\u70b9 5 \u548c 1 \u7684\u5171\u540c\u7956\u5148\u8282\u70b9\u662f 3\u3002
\n\n

\u793a\u4f8b 2:

\n\n

\"\"

\n\n
\u8f93\u5165\uff1a root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 4\n\u8f93\u51fa\uff1a 5\n\u89e3\u91ca\uff1a \u8282\u70b9 5 \u548c 4 \u7684\u5171\u540c\u7956\u5148\u8282\u70b9\u662f 5\u3002\u6839\u636e\u5171\u540c\u7956\u5148\u8282\u70b9\u7684\u5b9a\u4e49\uff0c\u4e00\u4e2a\u8282\u70b9\u53ef\u4ee5\u662f\u81ea\u8eab\u7684\u540e\u4ee3\u8282\u70b9\u3002
\n\n

\u793a\u4f8b 3:

\n\n

\"\"

\n\n
\u8f93\u5165\uff1a root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 10\n\u8f93\u51fa\uff1a null\n\u89e3\u91ca\uff1a \u8282\u70b9 10 \u4e0d\u5b58\u5728\u4e8e\u6811\u4e2d\uff0c\u6240\u4ee5\u8fd4\u56de null\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a:

\n\n
    \n\t
  • \u6811\u4e2d\u8282\u70b9\u4e2a\u6570\u7684\u8303\u56f4\u662f\u00a0[1, 104]\u3002
  • \n\t
  • -109 <= Node.val <= 109
  • \n\t
  • \u6240\u6709\u8282\u70b9\u7684\u503c\u00a0Node.val\u00a0\u662f\u4e92\u4e0d\u76f8\u540c\u7684\u3002
  • \n\t
  • p != q
  • \n
\n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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 */\nclass Solution {\npublic:\n TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode(int x) { val = x; }\n * }\n */\nclass Solution {\n public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution(object):\n def lowestCommonAncestor(self, root, p, q):\n \"\"\"\n :type root: TreeNode\n :type p: TreeNode\n :type q: TreeNode\n :rtype: TreeNode\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution:\n def lowestCommonAncestor(self, root: 'TreeNode', p: 'TreeNode', q: 'TreeNode') -> 'TreeNode':\n ", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int x) { val = x; }\n * }\n */\npublic class Solution {\n public TreeNode LowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val) {\n * this.val = val;\n * this.left = this.right = null;\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {TreeNode} p\n * @param {TreeNode} q\n * @return {TreeNode}\n */\nvar lowestCommonAncestor = function(root, p, q) {\n \n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1644](https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-tree-ii)", "[\u4e8c\u53c9\u6811\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148 II](/solution/1600-1699/1644.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree%20II/README.md)", "`\u6811`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1644](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree-ii)", "[Lowest Common Ancestor of a Binary Tree II](/solution/1600-1699/1644.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree%20II/README_EN.md)", "`Tree`", "Medium", "\ud83d\udd12"]}, {"question_id": "1779", "frontend_question_id": "1635", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/hopper-company-queries-i", "url_en": "https://leetcode.com/problems/hopper-company-queries-i", "relative_path_cn": "/solution/1600-1699/1635.Hopper%20Company%20Queries%20I/README.md", "relative_path_en": "/solution/1600-1699/1635.Hopper%20Company%20Queries%20I/README_EN.md", "title_cn": "Hopper \u516c\u53f8\u67e5\u8be2 I", "title_en": "Hopper Company Queries I", "question_title_slug": "hopper-company-queries-i", "content_en": "

Table: Drivers

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| driver_id   | int     |\n| join_date   | date    |\n+-------------+---------+\ndriver_id is the primary key for this table.\nEach row of this table contains the driver's ID and the date they joined the Hopper company.\n
\n\n

 

\n\n

Table: Rides

\n\n
\n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| ride_id      | int     |\n| user_id      | int     |\n| requested_at | date    |\n+--------------+---------+\nride_id is the primary key for this table.\nEach row of this table contains the ID of a ride, the user's ID that requested it, and the day they requested it.\nThere may be some ride requests in this table that were not accepted.\n
\n\n

 

\n\n

Table: AcceptedRides

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| ride_id       | int     |\n| driver_id     | int     |\n| ride_distance | int     |\n| ride_duration | int     |\n+---------------+---------+\nride_id is the primary key for this table.\nEach row of this table contains some information about an accepted ride.\nIt is guaranteed that each accepted ride exists in the Rides table.\n
\n\n

 

\n\n

Write an SQL query to report the following statistics for each month of 2020:

\n\n
    \n\t
  • The number of drivers currently with the Hopper company by the end of the month (active_drivers).
  • \n\t
  • The number of accepted rides in that month (accepted_rides).
  • \n
\n\n

Return the result table ordered by month in ascending order, where month is the month's number (January is 1, February is 2, etc.).

\n\n

The query result format is in the following example.

\n\n

 

\n\n
\nDrivers table:\n+-----------+------------+\n| driver_id | join_date  |\n+-----------+------------+\n| 10        | 2019-12-10 |\n| 8         | 2020-1-13  |\n| 5         | 2020-2-16  |\n| 7         | 2020-3-8   |\n| 4         | 2020-5-17  |\n| 1         | 2020-10-24 |\n| 6         | 2021-1-5   |\n+-----------+------------+\n\nRides table:\n+---------+---------+--------------+\n| ride_id | user_id | requested_at |\n+---------+---------+--------------+\n| 6       | 75      | 2019-12-9    |\n| 1       | 54      | 2020-2-9     |\n| 10      | 63      | 2020-3-4     |\n| 19      | 39      | 2020-4-6     |\n| 3       | 41      | 2020-6-3     |\n| 13      | 52      | 2020-6-22    |\n| 7       | 69      | 2020-7-16    |\n| 17      | 70      | 2020-8-25    |\n| 20      | 81      | 2020-11-2    |\n| 5       | 57      | 2020-11-9    |\n| 2       | 42      | 2020-12-9    |\n| 11      | 68      | 2021-1-11    |\n| 15      | 32      | 2021-1-17    |\n| 12      | 11      | 2021-1-19    |\n| 14      | 18      | 2021-1-27    |\n+---------+---------+--------------+\n\nAcceptedRides table:\n+---------+-----------+---------------+---------------+\n| ride_id | driver_id | ride_distance | ride_duration |\n+---------+-----------+---------------+---------------+\n| 10      | 10        | 63            | 38            |\n| 13      | 10        | 73            | 96            |\n| 7       | 8         | 100           | 28            |\n| 17      | 7         | 119           | 68            |\n| 20      | 1         | 121           | 92            |\n| 5       | 7         | 42            | 101           |\n| 2       | 4         | 6             | 38            |\n| 11      | 8         | 37            | 43            |\n| 15      | 8         | 108           | 82            |\n| 12      | 8         | 38            | 34            |\n| 14      | 1         | 90            | 74            |\n+---------+-----------+---------------+---------------+\n\nResult table:\n+-------+----------------+----------------+\n| month | active_drivers | accepted_rides |\n+-------+----------------+----------------+\n| 1     | 2              | 0              |\n| 2     | 3              | 0              |\n| 3     | 4              | 1              |\n| 4     | 4              | 0              |\n| 5     | 5              | 0              |\n| 6     | 5              | 1              |\n| 7     | 5              | 1              |\n| 8     | 5              | 1              |\n| 9     | 5              | 0              |\n| 10    | 6              | 0              |\n| 11    | 6              | 2              |\n| 12    | 6              | 1              |\n+-------+----------------+----------------+\n\nBy the end of January --> two active drivers (10, 8) and no accepted rides.\nBy the end of February --> three active drivers (10, 8, 5) and no accepted rides.\nBy the end of March --> four active drivers (10, 8, 5, 7) and one accepted ride (10).\nBy the end of April --> four active drivers (10, 8, 5, 7) and no accepted rides.\nBy the end of May --> five active drivers (10, 8, 5, 7, 4) and no accepted rides.\nBy the end of June --> five active drivers (10, 8, 5, 7, 4) and one accepted ride (13).\nBy the end of July --> five active drivers (10, 8, 5, 7, 4) and one accepted ride (7).\nBy the end of August --> five active drivers (10, 8, 5, 7, 4) and one accepted ride (17).\nBy the end of Septemeber --> five active drivers (10, 8, 5, 7, 4) and no accepted rides.\nBy the end of October --> six active drivers (10, 8, 5, 7, 4, 1) and no accepted rides.\nBy the end of November --> six active drivers (10, 8, 5, 7, 4, 1) and two accepted rides (20, 5).\nBy the end of December --> six active drivers (10, 8, 5, 7, 4, 1) and one accepted ride (2).\n
\n", "content_cn": "

\u8868: Drivers

\n\n
+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| driver_id   | int     |\n| join_date   | date    |\n+-------------+---------+\ndriver_id\u662f\u8be5\u8868\u7684\u4e3b\u952e\u3002\n\u8be5\u8868\u7684\u6bcf\u4e00\u884c\u5747\u5305\u542b\u9a7e\u9a76\u5458\u7684ID\u4ee5\u53ca\u4ed6\u4eec\u52a0\u5165Hopper\u516c\u53f8\u7684\u65e5\u671f\u3002\n
\n\n

\u00a0

\n\n

\u8868: Rides

\n\n
+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| ride_id      | int     |\n| user_id      | int     |\n| requested_at | date    |\n+--------------+---------+\nride_id\u662f\u8be5\u8868\u7684\u4e3b\u952e\u3002\n\u8be5\u8868\u7684\u6bcf\u4e00\u884c\u5747\u5305\u542b\u884c\u7a0bID(ride_id)\uff0c\u7528\u6237ID(user_id)\u4ee5\u53ca\u8be5\u884c\u7a0b\u7684\u65e5\u671f(requested_at)\u3002\n\u8be5\u8868\u4e2d\u53ef\u80fd\u6709\u4e00\u4e9b\u4e0d\u88ab\u63a5\u53d7\u7684\u4e58\u8f66\u8bf7\u6c42\u3002\n
\n\n

\u00a0

\n\n

\u8868: AcceptedRides

\n\n
+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| ride_id       | int     |\n| driver_id     | int     |\n| ride_distance | int     |\n| ride_duration | int     |\n+---------------+---------+\nride_id\u662f\u8be5\u8868\u7684\u4e3b\u952e\u3002\n\u8be5\u8868\u7684\u6bcf\u4e00\u884c\u90fd\u5305\u542b\u5df2\u63a5\u53d7\u7684\u884c\u7a0b\u4fe1\u606f\u3002\n\u8868\u4e2d\u7684\u884c\u7a0b\u4fe1\u606f\u90fd\u5728\u201cRides\u201d\u8868\u4e2d\u5b58\u5728\u3002\n
\n\n

\u00a0

\n\n

\u7f16\u5199SQL\u67e5\u8be2\u4ee5\u62a5\u544a2020\u5e74\u6bcf\u4e2a\u6708\u7684\u4ee5\u4e0b\u7edf\u8ba1\u4fe1\u606f\uff1a

\n\n
    \n\t
  • \u622a\u81f3\u67d0\u6708\u5e95\uff0c\u5f53\u524d\u5728Hopper\u516c\u53f8\u5de5\u4f5c\u7684\u9a7e\u9a76\u5458\u6570\u91cf\uff08active_drivers\uff09\u3002
  • \n\t
  • \u8be5\u6708\u63a5\u53d7\u7684\u4e58\u8f66\u6b21\u6570\uff08accepted_rides\uff09\u3002
  • \n
\n\n

\u8fd4\u56de\u6309month \u5347\u5e8f\u6392\u5217\u7684\u7ed3\u679c\u8868\uff0c\u5176\u4e2dmonth \u662f\u6708\u4efd\u7684\u6570\u5b57\uff08\u4e00\u6708\u662f1\uff0c\u4e8c\u6708\u662f2\uff0c\u4f9d\u6b64\u7c7b\u63a8\uff09\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a\u3002

\n\n
\u8868 Drivers:\n+-----------+------------+\n| driver_id | join_date  |\n+-----------+------------+\n| 10        | 2019-12-10 |\n| 8         | 2020-1-13  |\n| 5         | 2020-2-16  |\n| 7         | 2020-3-8   |\n| 4         | 2020-5-17  |\n| 1         | 2020-10-24 |\n| 6         | 2021-1-5   |\n+-----------+------------+\n\n\u8868 Rides:\n+---------+---------+--------------+\n| ride_id | user_id | requested_at |\n+---------+---------+--------------+\n| 6       | 75      | 2019-12-9    |\n| 1       | 54      | 2020-2-9     |\n| 10      | 63      | 2020-3-4     |\n| 19      | 39      | 2020-4-6     |\n| 3       | 41      | 2020-6-3     |\n| 13      | 52      | 2020-6-22    |\n| 7       | 69      | 2020-7-16    |\n| 17      | 70      | 2020-8-25    |\n| 20      | 81      | 2020-11-2    |\n| 5       | 57      | 2020-11-9    |\n| 2       | 42      | 2020-12-9    |\n| 11      | 68      | 2021-1-11    |\n| 15      | 32      | 2021-1-17    |\n| 12      | 11      | 2021-1-19    |\n| 14      | 18      | 2021-1-27    |\n+---------+---------+--------------+\n\n\u8868 AcceptedRides:\n+---------+-----------+---------------+---------------+\n| ride_id | driver_id | ride_distance | ride_duration |\n+---------+-----------+---------------+---------------+\n| 10      | 10        | 63            | 38            |\n| 13      | 10        | 73            | 96            |\n| 7       | 8         | 100           | 28            |\n| 17      | 7         | 119           | 68            |\n| 20      | 1         | 121           | 92            |\n| 5       | 7         | 42            | 101           |\n| 2       | 4         | 6             | 38            |\n| 11      | 8         | 37            | 43            |\n| 15      | 8         | 108           | 82            |\n| 12      | 8         | 38            | 34            |\n| 14      | 1         | 90            | 74            |\n+---------+-----------+---------------+---------------+\n\n\u7ed3\u679c\u8868:\n+-------+----------------+----------------+\n| month | active_drivers | accepted_rides |\n+-------+----------------+----------------+\n| 1     | 2              | 0              |\n| 2     | 3              | 0              |\n| 3     | 4              | 1              |\n| 4     | 4              | 0              |\n| 5     | 5              | 0              |\n| 6     | 5              | 1              |\n| 7     | 5              | 1              |\n| 8     | 5              | 1              |\n| 9     | 5              | 0              |\n| 10    | 6              | 0              |\n| 11    | 6              | 2              |\n| 12    | 6              | 1              |\n+-------+----------------+----------------+\n\n\u622a\u81f31\u6708\u5e95->\u4e24\u4e2a\u6d3b\u8dc3\u7684\u9a7e\u9a76\u5458\uff0810,8\uff09\uff0c\u6ca1\u6709\u88ab\u63a5\u53d7\u7684\u884c\u7a0b\u3002\n\u622a\u81f32\u6708\u5e95->\u4e09\u4e2a\u6d3b\u8dc3\u7684\u9a7e\u9a76\u5458\uff0810,8,5\uff09\uff0c\u6ca1\u6709\u88ab\u63a5\u53d7\u7684\u884c\u7a0b\u3002\n\u622a\u81f33\u6708\u5e95->\u56db\u4e2a\u6d3b\u8dc3\u7684\u9a7e\u9a76\u5458\uff0810,8,5,7\uff09\uff0c\u4e00\u4e2a\u88ab\u63a5\u53d7\u7684\u884c\u7a0b\uff0810\uff09\u3002\n\u622a\u81f34\u6708\u5e95->\u56db\u4e2a\u6d3b\u8dc3\u7684\u9a7e\u9a76\u5458\uff0810,8,5,7\uff09\uff0c\u6ca1\u6709\u88ab\u63a5\u53d7\u7684\u884c\u7a0b\u3002\n\u622a\u81f35\u6708\u5e95->\u4e94\u4e2a\u6d3b\u8dc3\u7684\u9a7e\u9a76\u5458\uff0810,8,5,7,4\uff09\uff0c\u6ca1\u6709\u88ab\u63a5\u53d7\u7684\u884c\u7a0b\u3002\n\u622a\u81f36\u6708\u5e95->\u4e94\u4e2a\u6d3b\u8dc3\u7684\u9a7e\u9a76\u5458\uff0810,8,5,7,4\uff09\uff0c\u4e00\u4e2a\u88ab\u63a5\u53d7\u7684\u884c\u7a0b\uff0813\uff09\u3002\n\u622a\u81f37\u6708\u5e95->\u4e94\u4e2a\u6d3b\u8dc3\u7684\u9a7e\u9a76\u5458\uff0810,8,5,7,4\uff09\uff0c\u4e00\u4e2a\u88ab\u63a5\u53d7\u7684\u884c\u7a0b\uff087\uff09\u3002\n\u622a\u81f38\u6708\u5e95->\u4e94\u4e2a\u6d3b\u8dc3\u7684\u9a7e\u9a76\u5458\uff0810,8,5,7,4\uff09\uff0c\u4e00\u4f4d\u63a5\u53d7\u7684\u884c\u7a0b\uff0817\uff09\u3002\n\u622a\u81f39\u6708\u5e95->\u4e94\u4e2a\u6d3b\u8dc3\u7684\u9a7e\u9a76\u5458\uff0810,8,5,7,4\uff09\uff0c\u6ca1\u6709\u88ab\u63a5\u53d7\u7684\u884c\u7a0b\u3002\n\u622a\u81f310\u6708\u5e95->\u516d\u4e2a\u6d3b\u8dc3\u7684\u9a7e\u9a76\u5458\uff0810,8,5,7,4,1\uff09\uff0c\u6ca1\u6709\u88ab\u63a5\u53d7\u7684\u884c\u7a0b\u3002\n\u622a\u81f311\u6708\u5e95->\u516d\u4e2a\u6d3b\u8dc3\u7684\u9a7e\u9a76\u5458\uff0810,8,5,7,4,1\uff09\uff0c\u4e24\u4e2a\u88ab\u63a5\u53d7\u7684\u884c\u7a0b\uff0820,5\uff09\u3002\n\u622a\u81f312\u6708\u5e95->\u516d\u4e2a\u6d3b\u8dc3\u7684\u9a7e\u9a76\u5458\uff0810,8,5,7,4,1\uff09\uff0c\u4e00\u4e2a\u88ab\u63a5\u53d7\u7684\u884c\u7a0b\uff082\uff09\u3002\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1635](https://leetcode-cn.com/problems/hopper-company-queries-i)", "[Hopper \u516c\u53f8\u67e5\u8be2 I](/solution/1600-1699/1635.Hopper%20Company%20Queries%20I/README.md)", "", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1635](https://leetcode.com/problems/hopper-company-queries-i)", "[Hopper Company Queries I](/solution/1600-1699/1635.Hopper%20Company%20Queries%20I/README_EN.md)", "", "Hard", "\ud83d\udd12"]}, {"question_id": "1778", "frontend_question_id": "1659", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximize-grid-happiness", "url_en": "https://leetcode.com/problems/maximize-grid-happiness", "relative_path_cn": "/solution/1600-1699/1659.Maximize%20Grid%20Happiness/README.md", "relative_path_en": "/solution/1600-1699/1659.Maximize%20Grid%20Happiness/README_EN.md", "title_cn": "\u6700\u5927\u5316\u7f51\u683c\u5e78\u798f\u611f", "title_en": "Maximize Grid Happiness", "question_title_slug": "maximize-grid-happiness", "content_en": "

You are given four integers, m, n, introvertsCount, and extrovertsCount. You have an m x n grid, and there are two types of people: introverts and extroverts. There are introvertsCount introverts and extrovertsCount extroverts.

\n\n

You should decide how many people you want to live in the grid and assign each of them one grid cell. Note that you do not have to have all the people living in the grid.

\n\n

The happiness of each person is calculated as follows:

\n\n
    \n\t
  • Introverts start with 120 happiness and lose 30 happiness for each neighbor (introvert or extrovert).
  • \n\t
  • Extroverts start with 40 happiness and gain 20 happiness for each neighbor (introvert or extrovert).
  • \n
\n\n

Neighbors live in the directly adjacent cells north, east, south, and west of a person's cell.

\n\n

The grid happiness is the sum of each person's happiness. Return the maximum possible grid happiness.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: m = 2, n = 3, introvertsCount = 1, extrovertsCount = 2\nOutput: 240\nExplanation: Assume the grid is 1-indexed with coordinates (row, column).\nWe can put the introvert in cell (1,1) and put the extroverts in cells (1,3) and (2,3).\n- Introvert at (1,1) happiness: 120 (starting happiness) - (0 * 30) (0 neighbors) = 120\n- Extrovert at (1,3) happiness: 40 (starting happiness) + (1 * 20) (1 neighbor) = 60\n- Extrovert at (2,3) happiness: 40 (starting happiness) + (1 * 20) (1 neighbor) = 60\nThe grid happiness is 120 + 60 + 60 = 240.\nThe above figure shows the grid in this example with each person's happiness. The introvert stays in the light green cell while the extroverts live on the light purple cells.\n
\n\n

Example 2:

\n\n
\nInput: m = 3, n = 1, introvertsCount = 2, extrovertsCount = 1\nOutput: 260\nExplanation: Place the two introverts in (1,1) and (3,1) and the extrovert at (2,1).\n- Introvert at (1,1) happiness: 120 (starting happiness) - (1 * 30) (1 neighbor) = 90\n- Extrovert at (2,1) happiness: 40 (starting happiness) + (2 * 20) (2 neighbors) = 80\n- Introvert at (3,1) happiness: 120 (starting happiness) - (1 * 30) (1 neighbor) = 90\nThe grid happiness is 90 + 80 + 90 = 260.\n
\n\n

Example 3:

\n\n
\nInput: m = 2, n = 2, introvertsCount = 4, extrovertsCount = 0\nOutput: 240\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= m, n <= 5
  • \n\t
  • 0 <= introvertsCount, extrovertsCount <= min(m * n, 6)
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u56db\u4e2a\u6574\u6570 m\u3001n\u3001introvertsCount \u548c extrovertsCount \u3002\u6709\u4e00\u4e2a m x n \u7f51\u683c\uff0c\u548c\u4e24\u79cd\u7c7b\u578b\u7684\u4eba\uff1a\u5185\u5411\u7684\u4eba\u548c\u5916\u5411\u7684\u4eba\u3002\u603b\u5171\u6709\u00a0introvertsCount \u4e2a\u5185\u5411\u7684\u4eba\u548c extrovertsCount \u4e2a\u5916\u5411\u7684\u4eba\u3002

\n\n

\u8bf7\u4f60\u51b3\u5b9a\u7f51\u683c\u4e2d\u5e94\u5f53\u5c45\u4f4f\u591a\u5c11\u4eba\uff0c\u5e76\u4e3a\u6bcf\u4e2a\u4eba\u5206\u914d\u4e00\u4e2a\u7f51\u683c\u5355\u5143\u3002 \u6ce8\u610f\uff0c\u4e0d\u5fc5 \u8ba9\u6240\u6709\u4eba\u90fd\u751f\u6d3b\u5728\u7f51\u683c\u4e2d\u3002

\n\n

\u6bcf\u4e2a\u4eba\u7684 \u5e78\u798f\u611f \u8ba1\u7b97\u5982\u4e0b\uff1a

\n\n
    \n\t
  • \u5185\u5411\u7684\u4eba \u5f00\u59cb \u65f6\u6709 120 \u4e2a\u5e78\u798f\u611f\uff0c\u4f46\u6bcf\u5b58\u5728\u4e00\u4e2a\u90bb\u5c45\uff08\u5185\u5411\u7684\u6216\u5916\u5411\u7684\uff09\u4ed6\u90fd\u4f1a \u5931\u53bb\u00a0\u00a030 \u4e2a\u5e78\u798f\u611f\u3002
  • \n\t
  • \u5916\u5411\u7684\u4eba \u5f00\u59cb \u65f6\u6709 40 \u4e2a\u5e78\u798f\u611f\uff0c\u6bcf\u5b58\u5728\u4e00\u4e2a\u90bb\u5c45\uff08\u5185\u5411\u7684\u6216\u5916\u5411\u7684\uff09\u4ed6\u90fd\u4f1a \u5f97\u5230\u00a0\u00a020 \u4e2a\u5e78\u798f\u611f\u3002
  • \n
\n\n

\u90bb\u5c45\u662f\u6307\u5c45\u4f4f\u5728\u4e00\u4e2a\u4eba\u6240\u5728\u5355\u5143\u7684\u4e0a\u3001\u4e0b\u3001\u5de6\u3001\u53f3\u56db\u4e2a\u76f4\u63a5\u76f8\u90bb\u7684\u5355\u5143\u4e2d\u7684\u5176\u4ed6\u4eba\u3002

\n\n

\u7f51\u683c\u5e78\u798f\u611f\u00a0\u662f\u6bcf\u4e2a\u4eba\u5e78\u798f\u611f\u7684 \u603b\u548c \u3002 \u8fd4\u56de \u6700\u5927\u53ef\u80fd\u7684\u7f51\u683c\u5e78\u798f\u611f \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1am = 2, n = 3, introvertsCount = 1, extrovertsCount = 2\n\u8f93\u51fa\uff1a240\n\u89e3\u91ca\uff1a\u5047\u8bbe\u7f51\u683c\u5750\u6807 (row, column) \u4ece 1 \u5f00\u59cb\u7f16\u53f7\u3002\n\u5c06\u5185\u5411\u7684\u4eba\u653e\u7f6e\u5728\u5355\u5143 (1,1) \uff0c\u5c06\u5916\u5411\u7684\u4eba\u653e\u7f6e\u5728\u5355\u5143 (1,3) \u548c (2,3) \u3002\n- \u4f4d\u4e8e (1,1) \u7684\u5185\u5411\u7684\u4eba\u7684\u5e78\u798f\u611f\uff1a120\uff08\u521d\u59cb\u5e78\u798f\u611f\uff09- (0 * 30)\uff080 \u4f4d\u90bb\u5c45\uff09= 120\n- \u4f4d\u4e8e (1,3) \u7684\u5916\u5411\u7684\u4eba\u7684\u5e78\u798f\u611f\uff1a40\uff08\u521d\u59cb\u5e78\u798f\u611f\uff09+ (1 * 20)\uff081 \u4f4d\u90bb\u5c45\uff09= 60\n- \u4f4d\u4e8e (2,3) \u7684\u5916\u5411\u7684\u4eba\u7684\u5e78\u798f\u611f\uff1a40\uff08\u521d\u59cb\u5e78\u798f\u611f\uff09+ (1 * 20)\uff081 \u4f4d\u90bb\u5c45\uff09= 60\n\u7f51\u683c\u5e78\u798f\u611f\u4e3a\uff1a120 + 60 + 60 = 240\n\u4e0a\u56fe\u5c55\u793a\u8be5\u793a\u4f8b\u5bf9\u5e94\u7f51\u683c\u4e2d\u6bcf\u4e2a\u4eba\u7684\u5e78\u798f\u611f\u3002\u5185\u5411\u7684\u4eba\u5728\u6d45\u7eff\u8272\u5355\u5143\u4e2d\uff0c\u800c\u5916\u5411\u7684\u4eba\u5728\u6d45\u7d2b\u8272\u5355\u5143\u4e2d\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1am = 3, n = 1, introvertsCount = 2, extrovertsCount = 1\n\u8f93\u51fa\uff1a260\n\u89e3\u91ca\uff1a\u5c06\u5185\u5411\u7684\u4eba\u653e\u7f6e\u5728\u5355\u5143 (1,1) \u548c (3,1) \uff0c\u5c06\u5916\u5411\u7684\u4eba\u653e\u7f6e\u5728\u5355\u5143 (2,1) \u3002\n- \u4f4d\u4e8e (1,1) \u7684\u5185\u5411\u7684\u4eba\u7684\u5e78\u798f\u611f\uff1a120\uff08\u521d\u59cb\u5e78\u798f\u611f\uff09- (1 * 30)\uff081 \u4f4d\u90bb\u5c45\uff09= 90\n- \u4f4d\u4e8e (2,1) \u7684\u5916\u5411\u7684\u4eba\u7684\u5e78\u798f\u611f\uff1a40\uff08\u521d\u59cb\u5e78\u798f\u611f\uff09+ (2 * 20)\uff082 \u4f4d\u90bb\u5c45\uff09= 80\n- \u4f4d\u4e8e (3,1) \u7684\u5185\u5411\u7684\u4eba\u7684\u5e78\u798f\u611f\uff1a120\uff08\u521d\u59cb\u5e78\u798f\u611f\uff09- (1 * 30)\uff081 \u4f4d\u90bb\u5c45\uff09= 90\n\u7f51\u683c\u5e78\u798f\u611f\u4e3a 90 + 80 + 90 = 260\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1am = 2, n = 2, introvertsCount = 4, extrovertsCount = 0\n\u8f93\u51fa\uff1a240\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= m, n <= 5
  • \n\t
  • 0 <= introvertsCount, extrovertsCount <= min(m * n, 6)
  • \n
\n", "tags_en": ["Dynamic Programming", "Backtracking"], "tags_cn": ["\u52a8\u6001\u89c4\u5212", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int getMaxGridHappiness(int m, int n, int introvertsCount, int extrovertsCount) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int getMaxGridHappiness(int m, int n, int introvertsCount, int extrovertsCount) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getMaxGridHappiness(self, m, n, introvertsCount, extrovertsCount):\n \"\"\"\n :type m: int\n :type n: int\n :type introvertsCount: int\n :type extrovertsCount: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getMaxGridHappiness(self, m: int, n: int, introvertsCount: int, extrovertsCount: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint getMaxGridHappiness(int m, int n, int introvertsCount, int extrovertsCount){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int GetMaxGridHappiness(int m, int n, int introvertsCount, int extrovertsCount) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} m\n * @param {number} n\n * @param {number} introvertsCount\n * @param {number} extrovertsCount\n * @return {number}\n */\nvar getMaxGridHappiness = function(m, n, introvertsCount, extrovertsCount) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} m\n# @param {Integer} n\n# @param {Integer} introverts_count\n# @param {Integer} extroverts_count\n# @return {Integer}\ndef get_max_grid_happiness(m, n, introverts_count, extroverts_count)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getMaxGridHappiness(_ m: Int, _ n: Int, _ introvertsCount: Int, _ extrovertsCount: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getMaxGridHappiness(m int, n int, introvertsCount int, extrovertsCount int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getMaxGridHappiness(m: Int, n: Int, introvertsCount: Int, extrovertsCount: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getMaxGridHappiness(m: Int, n: Int, introvertsCount: Int, extrovertsCount: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_max_grid_happiness(m: i32, n: i32, introverts_count: i32, extroverts_count: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $m\n * @param Integer $n\n * @param Integer $introvertsCount\n * @param Integer $extrovertsCount\n * @return Integer\n */\n function getMaxGridHappiness($m, $n, $introvertsCount, $extrovertsCount) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getMaxGridHappiness(m: number, n: number, introvertsCount: number, extrovertsCount: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-max-grid-happiness m n introvertsCount extrovertsCount)\n (-> exact-integer? exact-integer? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1659](https://leetcode-cn.com/problems/maximize-grid-happiness)", "[\u6700\u5927\u5316\u7f51\u683c\u5e78\u798f\u611f](/solution/1600-1699/1659.Maximize%20Grid%20Happiness/README.md)", "`\u52a8\u6001\u89c4\u5212`,`\u56de\u6eaf\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[1659](https://leetcode.com/problems/maximize-grid-happiness)", "[Maximize Grid Happiness](/solution/1600-1699/1659.Maximize%20Grid%20Happiness/README_EN.md)", "`Dynamic Programming`,`Backtracking`", "Hard", ""]}, {"question_id": "1777", "frontend_question_id": "1657", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/determine-if-two-strings-are-close", "url_en": "https://leetcode.com/problems/determine-if-two-strings-are-close", "relative_path_cn": "/solution/1600-1699/1657.Determine%20if%20Two%20Strings%20Are%20Close/README.md", "relative_path_en": "/solution/1600-1699/1657.Determine%20if%20Two%20Strings%20Are%20Close/README_EN.md", "title_cn": "\u786e\u5b9a\u4e24\u4e2a\u5b57\u7b26\u4e32\u662f\u5426\u63a5\u8fd1", "title_en": "Determine if Two Strings Are Close", "question_title_slug": "determine-if-two-strings-are-close", "content_en": "

Two strings are considered close if you can attain one from the other using the following operations:

\n\n
    \n\t
  • Operation 1: Swap any two existing characters.\n\n\t
      \n\t\t
    • For example, abcde -> aecdb
    • \n\t
    \n\t
  • \n\t
  • Operation 2: Transform every occurrence of one existing character into another existing character, and do the same with the other character.\n\t
      \n\t\t
    • For example, aacabb -> bbcbaa (all a's turn into b's, and all b's turn into a's)
    • \n\t
    \n\t
  • \n
\n\n

You can use the operations on either string as many times as necessary.

\n\n

Given two strings, word1 and word2, return true if word1 and word2 are close, and false otherwise.

\n\n

 

\n

Example 1:

\n\n
\nInput: word1 = "abc", word2 = "bca"\nOutput: true\nExplanation: You can attain word2 from word1 in 2 operations.\nApply Operation 1: "abc" -> "acb"\nApply Operation 1: "acb" -> "bca"\n
\n\n

Example 2:

\n\n
\nInput: word1 = "a", word2 = "aa"\nOutput: false\nExplanation: It is impossible to attain word2 from word1, or vice versa, in any number of operations.\n
\n\n

Example 3:

\n\n
\nInput: word1 = "cabbba", word2 = "abbccc"\nOutput: true\nExplanation: You can attain word2 from word1 in 3 operations.\nApply Operation 1: "cabbba" -> "caabbb"\nApply Operation 2: "caabbb" -> "baaccc"\nApply Operation 2: "baaccc" -> "abbccc"\n
\n\n

Example 4:

\n\n
\nInput: word1 = "cabbba", word2 = "aabbss"\nOutput: false\nExplanation: It is impossible to attain word2 from word1, or vice versa, in any amount of operations.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= word1.length, word2.length <= 105
  • \n\t
  • word1 and word2 contain only lowercase English letters.
  • \n
\n", "content_cn": "

\u5982\u679c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u64cd\u4f5c\u4ece\u4e00\u4e2a\u5b57\u7b26\u4e32\u5f97\u5230\u53e6\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u5219\u8ba4\u4e3a\u4e24\u4e2a\u5b57\u7b26\u4e32 \u63a5\u8fd1 \uff1a

\n\n
    \n\t
  • \u64cd\u4f5c 1\uff1a\u4ea4\u6362\u4efb\u610f\u4e24\u4e2a \u73b0\u6709 \u5b57\u7b26\u3002\n\n\t
      \n\t\t
    • \u4f8b\u5982\uff0cabcde -> aecdb
    • \n\t
    \n\t
  • \n\t
  • \u64cd\u4f5c 2\uff1a\u5c06\u4e00\u4e2a \u73b0\u6709 \u5b57\u7b26\u7684\u6bcf\u6b21\u51fa\u73b0\u8f6c\u6362\u4e3a\u53e6\u4e00\u4e2a \u73b0\u6709 \u5b57\u7b26\uff0c\u5e76\u5bf9\u53e6\u4e00\u4e2a\u5b57\u7b26\u6267\u884c\u76f8\u540c\u7684\u64cd\u4f5c\u3002\n\t
      \n\t\t
    • \u4f8b\u5982\uff0caacabb -> bbcbaa\uff08\u6240\u6709 a \u8f6c\u5316\u4e3a b \uff0c\u800c\u6240\u6709\u7684 b \u8f6c\u6362\u4e3a a \uff09
    • \n\t
    \n\t
  • \n
\n\n

\u4f60\u53ef\u4ee5\u6839\u636e\u9700\u8981\u5bf9\u4efb\u610f\u4e00\u4e2a\u5b57\u7b26\u4e32\u591a\u6b21\u4f7f\u7528\u8fd9\u4e24\u79cd\u64cd\u4f5c\u3002

\n\n

\u7ed9\u4f60\u4e24\u4e2a\u5b57\u7b26\u4e32\uff0cword1 \u548c word2 \u3002\u5982\u679c word1 \u548c word2 \u63a5\u8fd1 \uff0c\u5c31\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aword1 = \"abc\", word2 = \"bca\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a2 \u6b21\u64cd\u4f5c\u4ece word1 \u83b7\u5f97 word2 \u3002\n\u6267\u884c\u64cd\u4f5c 1\uff1a\"abc\" -> \"acb\"\n\u6267\u884c\u64cd\u4f5c 1\uff1a\"acb\" -> \"bca\"\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aword1 = \"a\", word2 = \"aa\"\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u4e0d\u7ba1\u6267\u884c\u591a\u5c11\u6b21\u64cd\u4f5c\uff0c\u90fd\u65e0\u6cd5\u4ece word1 \u5f97\u5230 word2 \uff0c\u53cd\u4e4b\u4ea6\u7136\u3002
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1aword1 = \"cabbba\", word2 = \"abbccc\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a3 \u6b21\u64cd\u4f5c\u4ece word1 \u83b7\u5f97 word2 \u3002\n\u6267\u884c\u64cd\u4f5c 1\uff1a\"cabbba\" -> \"caabbb\"\n\u6267\u884c\u64cd\u4f5c 2\uff1a\"caabbb\" -> \"baaccc\"\n\u6267\u884c\u64cd\u4f5c 2\uff1a\"baaccc\" -> \"abbccc\"\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1aword1 = \"cabbba\", word2 = \"aabbss\"\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u4e0d\u7ba1\u6267\u884c\u591a\u5c11\u6b21\u64cd\u4f5c\uff0c\u90fd\u65e0\u6cd5\u4ece word1 \u5f97\u5230 word2 \uff0c\u53cd\u4e4b\u4ea6\u7136\u3002
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= word1.length, word2.length <= 105
  • \n\t
  • word1 \u548c word2 \u4ec5\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd
  • \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool closeStrings(string word1, string word2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean closeStrings(String word1, String word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def closeStrings(self, word1, word2):\n \"\"\"\n :type word1: str\n :type word2: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def closeStrings(self, word1: str, word2: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool closeStrings(char * word1, char * word2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CloseStrings(string word1, string word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} word1\n * @param {string} word2\n * @return {boolean}\n */\nvar closeStrings = function(word1, word2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} word1\n# @param {String} word2\n# @return {Boolean}\ndef close_strings(word1, word2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func closeStrings(_ word1: String, _ word2: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func closeStrings(word1 string, word2 string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def closeStrings(word1: String, word2: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun closeStrings(word1: String, word2: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn close_strings(word1: String, word2: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $word1\n * @param String $word2\n * @return Boolean\n */\n function closeStrings($word1, $word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function closeStrings(word1: string, word2: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (close-strings word1 word2)\n (-> string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1657](https://leetcode-cn.com/problems/determine-if-two-strings-are-close)", "[\u786e\u5b9a\u4e24\u4e2a\u5b57\u7b26\u4e32\u662f\u5426\u63a5\u8fd1](/solution/1600-1699/1657.Determine%20if%20Two%20Strings%20Are%20Close/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1657](https://leetcode.com/problems/determine-if-two-strings-are-close)", "[Determine if Two Strings Are Close](/solution/1600-1699/1657.Determine%20if%20Two%20Strings%20Are%20Close/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1776", "frontend_question_id": "1658", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-operations-to-reduce-x-to-zero", "url_en": "https://leetcode.com/problems/minimum-operations-to-reduce-x-to-zero", "relative_path_cn": "/solution/1600-1699/1658.Minimum%20Operations%20to%20Reduce%20X%20to%20Zero/README.md", "relative_path_en": "/solution/1600-1699/1658.Minimum%20Operations%20to%20Reduce%20X%20to%20Zero/README_EN.md", "title_cn": "\u5c06 x \u51cf\u5230 0 \u7684\u6700\u5c0f\u64cd\u4f5c\u6570", "title_en": "Minimum Operations to Reduce X to Zero", "question_title_slug": "minimum-operations-to-reduce-x-to-zero", "content_en": "

You are given an integer array nums and an integer x. In one operation, you can either remove the leftmost or the rightmost element from the array nums and subtract its value from x. Note that this modifies the array for future operations.

\n\n

Return the minimum number of operations to reduce x to exactly 0 if it's possible, otherwise, return -1.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [1,1,4,2,3], x = 5\nOutput: 2\nExplanation: The optimal solution is to remove the last two elements to reduce x to zero.\n
\n\n

Example 2:

\n\n
\nInput: nums = [5,6,7,8,9], x = 4\nOutput: -1\n
\n\n

Example 3:

\n\n
\nInput: nums = [3,2,20,1,1,3], x = 10\nOutput: 5\nExplanation: The optimal solution is to remove the last three elements and the first two elements (5 operations in total) to reduce x to zero.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 105
  • \n\t
  • 1 <= nums[i] <= 104
  • \n\t
  • 1 <= x <= 109
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \u548c\u4e00\u4e2a\u6574\u6570 x \u3002\u6bcf\u4e00\u6b21\u64cd\u4f5c\u65f6\uff0c\u4f60\u5e94\u5f53\u79fb\u9664\u6570\u7ec4 nums \u6700\u5de6\u8fb9\u6216\u6700\u53f3\u8fb9\u7684\u5143\u7d20\uff0c\u7136\u540e\u4ece x \u4e2d\u51cf\u53bb\u8be5\u5143\u7d20\u7684\u503c\u3002\u8bf7\u6ce8\u610f\uff0c\u9700\u8981 \u4fee\u6539 \u6570\u7ec4\u4ee5\u4f9b\u63a5\u4e0b\u6765\u7684\u64cd\u4f5c\u4f7f\u7528\u3002

\n\n

\u5982\u679c\u53ef\u4ee5\u5c06 x\u00a0\u6070\u597d \u51cf\u5230\u00a00 \uff0c\u8fd4\u56de \u6700\u5c0f\u64cd\u4f5c\u6570 \uff1b\u5426\u5219\uff0c\u8fd4\u56de -1 \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [1,1,4,2,3], x = 5\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6700\u4f73\u89e3\u51b3\u65b9\u6848\u662f\u79fb\u9664\u540e\u4e24\u4e2a\u5143\u7d20\uff0c\u5c06 x \u51cf\u5230 0 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [5,6,7,8,9], x = 4\n\u8f93\u51fa\uff1a-1\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [3,2,20,1,1,3], x = 10\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u6700\u4f73\u89e3\u51b3\u65b9\u6848\u662f\u79fb\u9664\u540e\u4e09\u4e2a\u5143\u7d20\u548c\u524d\u4e24\u4e2a\u5143\u7d20\uff08\u603b\u5171 5 \u6b21\u64cd\u4f5c\uff09\uff0c\u5c06 x \u51cf\u5230 0 \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 105
  • \n\t
  • 1 <= nums[i] <= 104
  • \n\t
  • 1 <= x <= 109
  • \n
\n", "tags_en": ["Greedy", "Two Pointers", "Binary Search", "Sliding Window"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u53cc\u6307\u9488", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minOperations(vector& nums, int x) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minOperations(int[] nums, int x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minOperations(self, nums, x):\n \"\"\"\n :type nums: List[int]\n :type x: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minOperations(self, nums: List[int], x: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minOperations(int* nums, int numsSize, int x){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinOperations(int[] nums, int x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} x\n * @return {number}\n */\nvar minOperations = function(nums, x) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} x\n# @return {Integer}\ndef min_operations(nums, x)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minOperations(_ nums: [Int], _ x: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minOperations(nums []int, x int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minOperations(nums: Array[Int], x: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minOperations(nums: IntArray, x: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_operations(nums: Vec, x: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $x\n * @return Integer\n */\n function minOperations($nums, $x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minOperations(nums: number[], x: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-operations nums x)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1658](https://leetcode-cn.com/problems/minimum-operations-to-reduce-x-to-zero)", "[\u5c06 x \u51cf\u5230 0 \u7684\u6700\u5c0f\u64cd\u4f5c\u6570](/solution/1600-1699/1658.Minimum%20Operations%20to%20Reduce%20X%20to%20Zero/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u53cc\u6307\u9488`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1658](https://leetcode.com/problems/minimum-operations-to-reduce-x-to-zero)", "[Minimum Operations to Reduce X to Zero](/solution/1600-1699/1658.Minimum%20Operations%20to%20Reduce%20X%20to%20Zero/README_EN.md)", "`Greedy`,`Two Pointers`,`Binary Search`,`Sliding Window`", "Medium", ""]}, {"question_id": "1775", "frontend_question_id": "1656", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/design-an-ordered-stream", "url_en": "https://leetcode.com/problems/design-an-ordered-stream", "relative_path_cn": "/solution/1600-1699/1656.Design%20an%20Ordered%20Stream/README.md", "relative_path_en": "/solution/1600-1699/1656.Design%20an%20Ordered%20Stream/README_EN.md", "title_cn": "\u8bbe\u8ba1\u6709\u5e8f\u6d41", "title_en": "Design an Ordered Stream", "question_title_slug": "design-an-ordered-stream", "content_en": "

There is a stream of n (idKey, value) pairs arriving in an arbitrary order, where idKey is an integer between 1 and n and value is a string. No two pairs have the same id.

\n\n

Design a stream that returns the values in increasing order of their IDs by returning a chunk (list) of values after each insertion. The concatenation of all the chunks should result in a list of the sorted values.

\n\n

Implement the OrderedStream class:

\n\n
    \n\t
  • OrderedStream(int n) Constructs the stream to take n values.
  • \n\t
  • String[] insert(int idKey, String value) Inserts the pair (idKey, value) into the stream, then returns the largest possible chunk of currently inserted values that appear next in the order.
  • \n
\n\n

 

\n

Example:

\n\n

\"\"

\n\n
\nInput\n["OrderedStream", "insert", "insert", "insert", "insert", "insert"]\n[[5], [3, "ccccc"], [1, "aaaaa"], [2, "bbbbb"], [5, "eeeee"], [4, "ddddd"]]\nOutput\n[null, [], ["aaaaa"], ["bbbbb", "ccccc"], [], ["ddddd", "eeeee"]]\n\nExplanation\n// Note that the values ordered by ID is ["aaaaa", "bbbbb", "ccccc", "ddddd", "eeeee"].\nOrderedStream os = new OrderedStream(5);\nos.insert(3, "ccccc"); // Inserts (3, "ccccc"), returns [].\nos.insert(1, "aaaaa"); // Inserts (1, "aaaaa"), returns ["aaaaa"].\nos.insert(2, "bbbbb"); // Inserts (2, "bbbbb"), returns ["bbbbb", "ccccc"].\nos.insert(5, "eeeee"); // Inserts (5, "eeeee"), returns [].\nos.insert(4, "ddddd"); // Inserts (4, "ddddd"), returns ["ddddd", "eeeee"].\n// Concatentating all the chunks returned:\n// [] + ["aaaaa"] + ["bbbbb", "ccccc"] + [] + ["ddddd", "eeeee"] = ["aaaaa", "bbbbb", "ccccc", "ddddd", "eeeee"]\n// The resulting order is the same as the order above.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 1000
  • \n\t
  • 1 <= id <= n
  • \n\t
  • value.length == 5
  • \n\t
  • value consists only of lowercase letters.
  • \n\t
  • Each call to insert will have a unique id.
  • \n\t
  • Exactly n calls will be made to insert.
  • \n
\n", "content_cn": "

\u6709 n \u4e2a (id, value) \u5bf9\uff0c\u5176\u4e2d id \u662f 1 \u5230 n \u4e4b\u95f4\u7684\u4e00\u4e2a\u6574\u6570\uff0cvalue \u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\u3002\u4e0d\u5b58\u5728 id \u76f8\u540c\u7684\u4e24\u4e2a\u00a0(id, value) \u5bf9\u3002

\n\n

\u8bbe\u8ba1\u4e00\u4e2a\u6d41\uff0c\u4ee5 \u4efb\u610f \u987a\u5e8f\u83b7\u53d6 n\u00a0\u4e2a\u00a0(id, value)\u00a0\u5bf9\uff0c\u5e76\u5728\u591a\u6b21\u8c03\u7528\u65f6 \u6309 id \u9012\u589e\u7684\u987a\u5e8f \u8fd4\u56de\u4e00\u4e9b\u503c\u3002

\n\n

\u5b9e\u73b0 OrderedStream \u7c7b\uff1a

\n\n
    \n\t
  • OrderedStream(int n) \u6784\u9020\u4e00\u4e2a\u80fd\u63a5\u6536 n \u4e2a\u503c\u7684\u6d41\uff0c\u5e76\u5c06\u5f53\u524d\u6307\u9488 ptr \u8bbe\u4e3a 1 \u3002
  • \n\t
  • String[] insert(int id, String value) \u5411\u6d41\u4e2d\u5b58\u50a8\u65b0\u7684 (id, value) \u5bf9\u3002\u5b58\u50a8\u540e\uff1a\n\t
      \n\t\t
    • \u5982\u679c\u6d41\u5b58\u50a8\u6709 id = ptr \u7684 (id, value) \u5bf9\uff0c\u5219\u627e\u51fa\u4ece id = ptr \u5f00\u59cb\u7684 \u6700\u957f id \u8fde\u7eed\u9012\u589e\u5e8f\u5217 \uff0c\u5e76 \u6309\u987a\u5e8f \u8fd4\u56de\u4e0e\u8fd9\u4e9b id \u5173\u8054\u7684\u503c\u7684\u5217\u8868\u3002\u7136\u540e\uff0c\u5c06 ptr \u66f4\u65b0\u4e3a\u6700\u540e\u90a3\u4e2a\u00a0 id + 1\u00a0\u3002
    • \n\t\t
    • \n\t\t

      \u5426\u5219\uff0c\u8fd4\u56de\u4e00\u4e2a\u7a7a\u5217\u8868\u3002

      \n\t\t
    • \n\t
    \n\t
  • \n
\n\n

\u00a0

\n\n

\u793a\u4f8b\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\n[\"OrderedStream\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\"]\n[[5], [3, \"ccccc\"], [1, \"aaaaa\"], [2, \"bbbbb\"], [5, \"eeeee\"], [4, \"ddddd\"]]\n\u8f93\u51fa\n[null, [], [\"aaaaa\"], [\"bbbbb\", \"ccccc\"], [], [\"ddddd\", \"eeeee\"]]\n\n\u89e3\u91ca\nOrderedStream os= new OrderedStream(5);\nos.insert(3, \"ccccc\"); // \u63d2\u5165 (3, \"ccccc\")\uff0c\u8fd4\u56de []\nos.insert(1, \"aaaaa\"); // \u63d2\u5165 (1, \"aaaaa\")\uff0c\u8fd4\u56de [\"aaaaa\"]\nos.insert(2, \"bbbbb\"); // \u63d2\u5165 (2, \"bbbbb\")\uff0c\u8fd4\u56de [\"bbbbb\", \"ccccc\"]\nos.insert(5, \"eeeee\"); // \u63d2\u5165 (5, \"eeeee\")\uff0c\u8fd4\u56de []\nos.insert(4, \"ddddd\"); // \u63d2\u5165 (4, \"ddddd\")\uff0c\u8fd4\u56de [\"ddddd\", \"eeeee\"]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 1000
  • \n\t
  • 1 <= id <= n
  • \n\t
  • value.length == 5
  • \n\t
  • value \u4ec5\u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210
  • \n\t
  • \u6bcf\u6b21\u8c03\u7528 insert \u90fd\u4f1a\u4f7f\u7528\u4e00\u4e2a\u552f\u4e00\u7684 id
  • \n\t
  • \u6070\u597d\u8c03\u7528 n \u6b21 insert
  • \n
\n", "tags_en": ["Design", "Array"], "tags_cn": ["\u8bbe\u8ba1", "\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class OrderedStream {\npublic:\n OrderedStream(int n) {\n\n }\n \n vector insert(int idKey, string value) {\n\n }\n};\n\n/**\n * Your OrderedStream object will be instantiated and called as such:\n * OrderedStream* obj = new OrderedStream(n);\n * vector param_1 = obj->insert(idKey,value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class OrderedStream {\n\n public OrderedStream(int n) {\n\n }\n \n public List insert(int idKey, String value) {\n\n }\n}\n\n/**\n * Your OrderedStream object will be instantiated and called as such:\n * OrderedStream obj = new OrderedStream(n);\n * List param_1 = obj.insert(idKey,value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class OrderedStream(object):\n\n def __init__(self, n):\n \"\"\"\n :type n: int\n \"\"\"\n\n\n def insert(self, idKey, value):\n \"\"\"\n :type idKey: int\n :type value: str\n :rtype: List[str]\n \"\"\"\n\n\n\n# Your OrderedStream object will be instantiated and called as such:\n# obj = OrderedStream(n)\n# param_1 = obj.insert(idKey,value)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class OrderedStream:\n\n def __init__(self, n: int):\n\n\n def insert(self, idKey: int, value: str) -> List[str]:\n\n\n\n# Your OrderedStream object will be instantiated and called as such:\n# obj = OrderedStream(n)\n# param_1 = obj.insert(idKey,value)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} OrderedStream;\n\n\nOrderedStream* orderedStreamCreate(int n) {\n \n}\n\nchar ** orderedStreamInsert(OrderedStream* obj, int idKey, char * value, int* retSize) {\n \n}\n\nvoid orderedStreamFree(OrderedStream* obj) {\n \n}\n\n/**\n * Your OrderedStream struct will be instantiated and called as such:\n * OrderedStream* obj = orderedStreamCreate(n);\n * char ** param_1 = orderedStreamInsert(obj, idKey, value, retSize);\n \n * orderedStreamFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class OrderedStream {\n\n public OrderedStream(int n) {\n\n }\n \n public IList Insert(int idKey, string value) {\n\n }\n}\n\n/**\n * Your OrderedStream object will be instantiated and called as such:\n * OrderedStream obj = new OrderedStream(n);\n * IList param_1 = obj.Insert(idKey,value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n */\nvar OrderedStream = function(n) {\n\n};\n\n/** \n * @param {number} idKey \n * @param {string} value\n * @return {string[]}\n */\nOrderedStream.prototype.insert = function(idKey, value) {\n\n};\n\n/**\n * Your OrderedStream object will be instantiated and called as such:\n * var obj = new OrderedStream(n)\n * var param_1 = obj.insert(idKey,value)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class OrderedStream\n\n=begin\n :type n: Integer\n=end\n def initialize(n)\n\n end\n\n\n=begin\n :type id_key: Integer\n :type value: String\n :rtype: String[]\n=end\n def insert(id_key, value)\n\n end\n\n\nend\n\n# Your OrderedStream object will be instantiated and called as such:\n# obj = OrderedStream.new(n)\n# param_1 = obj.insert(id_key, value)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass OrderedStream {\n\n init(_ n: Int) {\n\n }\n \n func insert(_ idKey: Int, _ value: String) -> [String] {\n\n }\n}\n\n/**\n * Your OrderedStream object will be instantiated and called as such:\n * let obj = OrderedStream(n)\n * let ret_1: [String] = obj.insert(idKey, value)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type OrderedStream struct {\n\n}\n\n\nfunc Constructor(n int) OrderedStream {\n\n}\n\n\nfunc (this *OrderedStream) Insert(idKey int, value string) []string {\n\n}\n\n\n/**\n * Your OrderedStream object will be instantiated and called as such:\n * obj := Constructor(n);\n * param_1 := obj.Insert(idKey,value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class OrderedStream(_n: Int) {\n\n def insert(idKey: Int, value: String): List[String] = {\n \n }\n\n}\n\n/**\n * Your OrderedStream object will be instantiated and called as such:\n * var obj = new OrderedStream(n)\n * var param_1 = obj.insert(idKey,value)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class OrderedStream(n: Int) {\n\n fun insert(idKey: Int, value: String): List {\n\n }\n\n}\n\n/**\n * Your OrderedStream object will be instantiated and called as such:\n * var obj = OrderedStream(n)\n * var param_1 = obj.insert(idKey,value)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct OrderedStream {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl OrderedStream {\n\n fn new(n: i32) -> Self {\n\n }\n \n fn insert(&self, id_key: i32, value: String) -> Vec {\n\n }\n}\n\n/**\n * Your OrderedStream object will be instantiated and called as such:\n * let obj = OrderedStream::new(n);\n * let ret_1: Vec = obj.insert(idKey, value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class OrderedStream {\n /**\n * @param Integer $n\n */\n function __construct($n) {\n\n }\n\n /**\n * @param Integer $idKey\n * @param String $value\n * @return String[]\n */\n function insert($idKey, $value) {\n\n }\n}\n\n/**\n * Your OrderedStream object will be instantiated and called as such:\n * $obj = OrderedStream($n);\n * $ret_1 = $obj->insert($idKey, $value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class OrderedStream {\n constructor(n: number) {\n\n }\n\n insert(idKey: number, value: string): string[] {\n\n }\n}\n\n/**\n * Your OrderedStream object will be instantiated and called as such:\n * var obj = new OrderedStream(n)\n * var param_1 = obj.insert(idKey,value)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define ordered-stream%\n (class object%\n (super-new)\n\n ; n : exact-integer?\n (init-field\n n)\n \n ; insert : exact-integer? string? -> (listof string?)\n (define/public (insert idKey value)\n\n )))\n\n;; Your ordered-stream% object will be instantiated and called as such:\n;; (define obj (new ordered-stream% [n n]))\n;; (define param_1 (send obj insert id-key value))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1656](https://leetcode-cn.com/problems/design-an-ordered-stream)", "[\u8bbe\u8ba1\u6709\u5e8f\u6d41](/solution/1600-1699/1656.Design%20an%20Ordered%20Stream/README.md)", "`\u8bbe\u8ba1`,`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1656](https://leetcode.com/problems/design-an-ordered-stream)", "[Design an Ordered Stream](/solution/1600-1699/1656.Design%20an%20Ordered%20Stream/README_EN.md)", "`Design`,`Array`", "Easy", ""]}, {"question_id": "1774", "frontend_question_id": "1634", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/add-two-polynomials-represented-as-linked-lists", "url_en": "https://leetcode.com/problems/add-two-polynomials-represented-as-linked-lists", "relative_path_cn": "/solution/1600-1699/1634.Add%20Two%20Polynomials%20Represented%20as%20Linked%20Lists/README.md", "relative_path_en": "/solution/1600-1699/1634.Add%20Two%20Polynomials%20Represented%20as%20Linked%20Lists/README_EN.md", "title_cn": "\u6c42\u4e24\u4e2a\u591a\u9879\u5f0f\u94fe\u8868\u7684\u548c", "title_en": "Add Two Polynomials Represented as Linked Lists", "question_title_slug": "add-two-polynomials-represented-as-linked-lists", "content_en": "

A polynomial linked list is a special type of linked list where every node represents a term in a polynomial expression.

\r\n\r\n

Each node has three attributes:

\r\n\r\n
    \r\n\t
  • coefficient: an integer representing the number multiplier of the term. The coefficient of the term 9x4 is 9.
  • \r\n\t
  • power: an integer representing the exponent. The power of the term 9x4 is 4.
  • \r\n\t
  • next: a pointer to the next node in the list, or null if it is the last node of the list.
  • \r\n
\r\n\r\n

For example, the polynomial 5x3 + 4x - 7 is represented by the polynomial linked list illustrated below:

\r\n\r\n

\"\"

\r\n\r\n

The polynomial linked list must be in its standard form: the polynomial must be in strictly descending order by its power value. Also, terms with a coefficient of 0 are omitted.

\r\n\r\n

Given two polynomial linked list heads, poly1 and poly2, add the polynomials together and return the head of the sum of the polynomials.

\r\n\r\n

PolyNode format:

\r\n\r\n

The input/output format is as a list of n nodes, where each node is represented as its [coefficient, power]. For example, the polynomial 5x3 + 4x - 7 would be represented as: [[5,3],[4,1],[-7,0]].

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n

\"\"

\r\n\r\n
\r\nInput: poly1 = [[1,1]], poly2 = [[1,0]]\r\nOutput: [[1,1],[1,0]]\r\nExplanation: poly1 = x. poly2 = 1. The sum is x + 1.\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: poly1 = [[2,2],[4,1],[3,0]], poly2 = [[3,2],[-4,1],[-1,0]]\r\nOutput: [[5,2],[2,0]]\r\nExplanation: poly1 = 2x2 + 4x + 3. poly2 = 3x2 - 4x - 1. The sum is 5x2 + 2. Notice that we omit the "0x" term.\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: poly1 = [[1,2]], poly2 = [[-1,2]]\r\nOutput: []\r\nExplanation: The sum is 0. We return an empty list.\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 0 <= n <= 104
  • \r\n\t
  • -109 <= PolyNode.coefficient <= 109
  • \r\n\t
  • PolyNode.coefficient != 0
  • \r\n\t
  • 0 <= PolyNode.power <= 109
  • \r\n\t
  • PolyNode.power > PolyNode.next.power
  • \r\n
", "content_cn": "

\u591a\u9879\u5f0f\u94fe\u8868\u662f\u4e00\u79cd\u7279\u6b8a\u5f62\u5f0f\u7684\u94fe\u8868\uff0c\u6bcf\u4e2a\u8282\u70b9\u8868\u793a\u591a\u9879\u5f0f\u7684\u4e00\u9879\u3002

\n\n

\u6bcf\u4e2a\u8282\u70b9\u6709\u4e09\u4e2a\u5c5e\u6027\uff1a

\n\n
    \n\t
  • coefficient\uff1a\u8be5\u9879\u7684\u7cfb\u6570\u3002\u9879\u00a09x4\u00a0\u7684\u7cfb\u6570\u662f\u00a09\u00a0\u3002
  • \n\t
  • power\uff1a\u8be5\u9879\u7684\u6307\u6570\u3002\u9879\u00a09x4\u00a0\u7684\u6307\u6570\u662f\u00a04\u00a0\u3002
  • \n\t
  • next\uff1a\u6307\u5411\u4e0b\u4e00\u4e2a\u8282\u70b9\u7684\u6307\u9488\uff08\u5f15\u7528\uff09\uff0c\u5982\u679c\u5f53\u524d\u8282\u70b9\u4e3a\u94fe\u8868\u7684\u6700\u540e\u4e00\u4e2a\u8282\u70b9\u5219\u4e3a\u00a0null \u3002
  • \n
\n\n

\u4f8b\u5982\uff0c\u591a\u9879\u5f0f\u00a05x3 + 4x - 7\u00a0\u53ef\u4ee5\u8868\u793a\u6210\u5982\u4e0b\u56fe\u6240\u793a\u7684\u591a\u9879\u5f0f\u94fe\u8868\uff1a

\n\n

\"\"

\n\n

\u591a\u9879\u5f0f\u94fe\u8868\u5fc5\u987b\u662f\u6807\u51c6\u5f62\u5f0f\u7684\uff0c\u5373\u591a\u9879\u5f0f\u5fc5\u987b \u4e25\u683c \u6309\u6307\u6570\u00a0power\u00a0\u7684\u9012\u51cf\u987a\u5e8f\u6392\u5217\uff08\u5373\u964d\u5e42\u6392\u5217\uff09\u3002\u53e6\u5916\uff0c\u7cfb\u6570\u00a0coefficient\u00a0\u4e3a\u00a00\u00a0\u7684\u9879\u9700\u8981\u7701\u7565\u3002

\n\n

\u7ed9\u5b9a\u4e24\u4e2a\u591a\u9879\u5f0f\u94fe\u8868\u7684\u5934\u8282\u70b9\u00a0poly1\u00a0\u548c\u00a0poly2\uff0c\u8fd4\u56de\u5b83\u4eec\u7684\u548c\u7684\u5934\u8282\u70b9\u3002

\n\n

PolyNode\u00a0\u683c\u5f0f\uff1a

\n\n

\u8f93\u5165/\u8f93\u51fa\u683c\u5f0f\u8868\u793a\u4e3a\u00a0n\u00a0\u4e2a\u8282\u70b9\u7684\u5217\u8868\uff0c\u5176\u4e2d\u6bcf\u4e2a\u8282\u70b9\u8868\u793a\u4e3a\u00a0[coefficient, power]\u00a0\u3002\u4f8b\u5982\uff0c\u591a\u9879\u5f0f\u00a05x3 + 4x - 7\u00a0\u8868\u793a\u4e3a\uff1a\u00a0[[5,3],[4,1],[-7,0]]\u00a0\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1apoly1 = [[1,1]], poly2 = [[1,0]]\n\u8f93\u51fa\uff1a[[1,1],[1,0]]\n\u89e3\u91ca\uff1apoly1 = x. poly2 = 1. \u548c\u4e3a x + 1.\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1apoly1 = [[2,2],[4,1],[3,0]], poly2 = [[3,2],[-4,1],[-1,0]]\n\u8f93\u51fa\uff1a[[5,2],[2,0]]\n\u89e3\u91ca\uff1apoly1 = 2x2 + 4x + 3. poly2 = 3x2 - 4x - 1. \u548c\u4e3a 5x2 + 2. \u6ce8\u610f\uff0c\u6211\u4eec\u7701\u7565 \"0x\" \u9879\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1apoly1 = [[1,2]], poly2 = [[-1,2]]\n\u8f93\u51fa\uff1a[]\n\u89e3\u91ca\uff1a\u548c\u4e3a 0\u3002\u6211\u4eec\u8fd4\u56de\u7a7a\u94fe\u8868\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 0 <= n <= 104
  • \n\t
  • -109\u00a0<= PolyNode.coefficient <= 109
  • \n\t
  • PolyNode.coefficient != 0
  • \n\t
  • 0\u00a0<= PolyNode.power <= 109
  • \n\t
  • PolyNode.power > PolyNode.next.power
  • \n
\n", "tags_en": ["Linked List"], "tags_cn": ["\u94fe\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for polynomial singly-linked list.\n * struct PolyNode {\n * int coefficient, power;\n * PolyNode *next;\n * PolyNode(): coefficient(0), power(0), next(nullptr) {};\n * PolyNode(int x, int y): coefficient(x), power(y), next(nullptr) {};\n * PolyNode(int x, int y, PolyNode* next): coefficient(x), power(y), next(next) {};\n * };\n */\n\nclass Solution {\npublic:\n PolyNode* addPoly(PolyNode* poly1, PolyNode* poly2) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for polynomial singly-linked list.\n * class PolyNode {\n * int coefficient, power;\n * PolyNode next = null;\n \n * PolyNode() {}\n * PolyNode(int x, int y) { this.coefficient = x; this.power = y; }\n * PolyNode(int x, int y, PolyNode next) { this.coefficient = x; this.power = y; this.next = next; }\n * }\n */\n\nclass Solution {\n public PolyNode addPoly(PolyNode poly1, PolyNode poly2) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for polynomial singly-linked list.\n# class PolyNode:\n# def __init__(self, x=0, y=0, next=None):\n# self.coefficient = x\n# self.power = y\n# self.next = next\n\nclass Solution:\n def addPoly(self, poly1, poly2):\n \"\"\"\n :type poly1: PolyNode\n :type poly2: PolyNode\n :rtype: PolyNode\n \"\"\"\n \n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for polynomial singly-linked list.\n# class PolyNode:\n# def __init__(self, x=0, y=0, next=None):\n# self.coefficient = x\n# self.power = y\n# self.next = next\n\nclass Solution:\n def addPoly(self, poly1: 'PolyNode', poly2: 'PolyNode') -> 'PolyNode':\n \n ", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for polynomial singly-linked list.\n * public class PolyNode {\n * public int coefficient, power;\n * public PolyNode next;\n *\n * public PolyNode(int x=0, int y=0, PolyNode next=null) {\n * this.coefficient = x;\n * this.power = y;\n * this.next = next;\n * }\n * }\n */\n\npublic class Solution {\n public PolyNode AddPoly(PolyNode poly1, PolyNode poly2) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for polynomial singly-linked list.\n * function PolyNode(x=0, y=0, next=null) {\n * this.coefficient = x;\n * this.power = y;\n * this.next = next;\n * }\n */\n\n/**\n * @param {PolyNode} poly1\n * @param {PolyNode} poly2\n * @return {PolyNode}\n */\nvar addPoly = function(poly1, poly2) {\n \n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1634](https://leetcode-cn.com/problems/add-two-polynomials-represented-as-linked-lists)", "[\u6c42\u4e24\u4e2a\u591a\u9879\u5f0f\u94fe\u8868\u7684\u548c](/solution/1600-1699/1634.Add%20Two%20Polynomials%20Represented%20as%20Linked%20Lists/README.md)", "`\u94fe\u8868`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1634](https://leetcode.com/problems/add-two-polynomials-represented-as-linked-lists)", "[Add Two Polynomials Represented as Linked Lists](/solution/1600-1699/1634.Add%20Two%20Polynomials%20Represented%20as%20Linked%20Lists/README_EN.md)", "`Linked List`", "Medium", "\ud83d\udd12"]}, {"question_id": "1773", "frontend_question_id": "1633", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/percentage-of-users-attended-a-contest", "url_en": "https://leetcode.com/problems/percentage-of-users-attended-a-contest", "relative_path_cn": "/solution/1600-1699/1633.Percentage%20of%20Users%20Attended%20a%20Contest/README.md", "relative_path_en": "/solution/1600-1699/1633.Percentage%20of%20Users%20Attended%20a%20Contest/README_EN.md", "title_cn": "\u5404\u8d5b\u4e8b\u7684\u7528\u6237\u6ce8\u518c\u7387", "title_en": "Percentage of Users Attended a Contest", "question_title_slug": "percentage-of-users-attended-a-contest", "content_en": "

Table: Users

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| user_id     | int     |\n| user_name   | varchar |\n+-------------+---------+\nuser_id is the primary key for this table.\nEach row of this table contains the name and the id of a user.\n
\n\n

 

\n\n

Table: Register

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| contest_id  | int     |\n| user_id     | int     |\n+-------------+---------+\n(contest_id, user_id) is the primary key for this table.\nEach row of this table contains the id of a user and the contest they registered into.\n
\n\n

 

\n\n

Write an SQL query to find the percentage of the users registered in each contest rounded to two decimals.

\n\n

Return the result table ordered by percentage in descending order. In case of a tie, order it by contest_id in ascending order.

\n\n

The query result format is in the following example.

\n\n

 

\n\n
\nUsers table:\n+---------+-----------+\n| user_id | user_name |\n+---------+-----------+\n| 6       | Alice     |\n| 2       | Bob       |\n| 7       | Alex      |\n+---------+-----------+\n\nRegister table:\n+------------+---------+\n| contest_id | user_id |\n+------------+---------+\n| 215        | 6       |\n| 209        | 2       |\n| 208        | 2       |\n| 210        | 6       |\n| 208        | 6       |\n| 209        | 7       |\n| 209        | 6       |\n| 215        | 7       |\n| 208        | 7       |\n| 210        | 2       |\n| 207        | 2       |\n| 210        | 7       |\n+------------+---------+\n\nResult table:\n+------------+------------+\n| contest_id | percentage |\n+------------+------------+\n| 208        | 100.0      |\n| 209        | 100.0      |\n| 210        | 100.0      |\n| 215        | 66.67      |\n| 207        | 33.33      |\n+------------+------------+\nAll the users registered in contests 208, 209, and 210. The percentage is 100% and we sort them in the answer table by contest_id in ascending order.\nAlice and Alex registered in contest 215 and the percentage is ((2/3) * 100) = 66.67%\nBob registered in contest 207 and the percentage is ((1/3) * 100) = 33.33%\n
\n", "content_cn": "

\u7528\u6237\u8868\uff1a\u00a0Users

\n\n
+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| user_id     | int     |\n| user_name   | varchar |\n+-------------+---------+\nuser_id \u662f\u8be5\u8868\u7684\u4e3b\u952e\u3002\n\u8be5\u8868\u4e2d\u7684\u6bcf\u884c\u5305\u62ec\u7528\u6237 ID \u548c\u7528\u6237\u540d\u3002
\n\n

\u00a0

\n\n

\u6ce8\u518c\u8868\uff1a\u00a0Register

\n\n
+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| contest_id  | int     |\n| user_id     | int     |\n+-------------+---------+\n(contest_id, user_id) \u662f\u8be5\u8868\u7684\u4e3b\u952e\u3002\n\u8be5\u8868\u4e2d\u7684\u6bcf\u884c\u5305\u542b\u7528\u6237\u7684 ID \u548c\u4ed6\u4eec\u6ce8\u518c\u7684\u8d5b\u4e8b\u3002
\n\n

\u00a0

\n\n

\u5199\u4e00\u6761 SQL \u8bed\u53e5\uff0c\u67e5\u8be2\u5404\u8d5b\u4e8b\u7684\u7528\u6237\u6ce8\u518c\u767e\u5206\u7387\uff0c\u4fdd\u7559\u4e24\u4f4d\u5c0f\u6570\u3002

\n\n

\u8fd4\u56de\u7684\u7ed3\u679c\u8868\u6309\u00a0percentage\u00a0\u7684\u964d\u5e8f\u6392\u5e8f\uff0c\u82e5\u76f8\u540c\u5219\u6309\u00a0contest_id\u00a0\u7684\u5347\u5e8f\u6392\u5e8f\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u5982\u4e0b\u793a\u4f8b\u6240\u793a\uff1a

\n\n

\u00a0

\n\n
Users \u8868\uff1a\n+---------+-----------+\n| user_id | user_name |\n+---------+-----------+\n| 6       | Alice     |\n| 2       | Bob       |\n| 7       | Alex      |\n+---------+-----------+\n\nRegister \u8868\uff1a\n+------------+---------+\n| contest_id | user_id |\n+------------+---------+\n| 215        | 6       |\n| 209        | 2       |\n| 208        | 2       |\n| 210        | 6       |\n| 208        | 6       |\n| 209        | 7       |\n| 209        | 6       |\n| 215        | 7       |\n| 208        | 7       |\n| 210        | 2       |\n| 207        | 2       |\n| 210        | 7       |\n+------------+---------+\n\n\u7ed3\u679c\u8868\uff1a\n+------------+------------+\n| contest_id | percentage |\n+------------+------------+\n| 208        | 100.0      |\n| 209        | 100.0      |\n| 210        | 100.0      |\n| 215        | 66.67      |\n| 207        | 33.33      |\n+------------+------------+\n\u6240\u6709\u7528\u6237\u90fd\u6ce8\u518c\u4e86 208\u3001209 \u548c 210 \u8d5b\u4e8b\uff0c\u56e0\u6b64\u8fd9\u4e9b\u8d5b\u4e8b\u7684\u6ce8\u518c\u7387\u4e3a 100% \uff0c\u6211\u4eec\u6309 contest_id \u7684\u964d\u5e8f\u6392\u5e8f\u52a0\u5165\u7ed3\u679c\u8868\u4e2d\u3002\nAlice \u548c Alex \u6ce8\u518c\u4e86 215 \u8d5b\u4e8b\uff0c\u6ce8\u518c\u7387\u4e3a ((2/3) * 100) = 66.67%\nBob \u6ce8\u518c\u4e86 207 \u8d5b\u4e8b\uff0c\u6ce8\u518c\u7387\u4e3a ((1/3) * 100) = 33.33%\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1633](https://leetcode-cn.com/problems/percentage-of-users-attended-a-contest)", "[\u5404\u8d5b\u4e8b\u7684\u7528\u6237\u6ce8\u518c\u7387](/solution/1600-1699/1633.Percentage%20of%20Users%20Attended%20a%20Contest/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1633](https://leetcode.com/problems/percentage-of-users-attended-a-contest)", "[Percentage of Users Attended a Contest](/solution/1600-1699/1633.Percentage%20of%20Users%20Attended%20a%20Contest/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1772", "frontend_question_id": "1649", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/create-sorted-array-through-instructions", "url_en": "https://leetcode.com/problems/create-sorted-array-through-instructions", "relative_path_cn": "/solution/1600-1699/1649.Create%20Sorted%20Array%20through%20Instructions/README.md", "relative_path_en": "/solution/1600-1699/1649.Create%20Sorted%20Array%20through%20Instructions/README_EN.md", "title_cn": "\u901a\u8fc7\u6307\u4ee4\u521b\u5efa\u6709\u5e8f\u6570\u7ec4", "title_en": "Create Sorted Array through Instructions", "question_title_slug": "create-sorted-array-through-instructions", "content_en": "

Given an integer array instructions, you are asked to create a sorted array from the elements in instructions. You start with an empty container nums. For each element from left to right in instructions, insert it into nums. The cost of each insertion is the minimum of the following:

\r\n\r\n
    \r\n\t
  • The number of elements currently in nums that are strictly less than instructions[i].
  • \r\n\t
  • The number of elements currently in nums that are strictly greater than instructions[i].
  • \r\n
\r\n\r\n

For example, if inserting element 3 into nums = [1,2,3,5], the cost of insertion is min(2, 1) (elements 1 and 2 are less than 3, element 5 is greater than 3) and nums will become [1,2,3,3,5].

\r\n\r\n

Return the total cost to insert all elements from instructions into nums. Since the answer may be large, return it modulo 109 + 7

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: instructions = [1,5,6,2]\r\nOutput: 1\r\nExplanation: Begin with nums = [].\r\nInsert 1 with cost min(0, 0) = 0, now nums = [1].\r\nInsert 5 with cost min(1, 0) = 0, now nums = [1,5].\r\nInsert 6 with cost min(2, 0) = 0, now nums = [1,5,6].\r\nInsert 2 with cost min(1, 2) = 1, now nums = [1,2,5,6].\r\nThe total cost is 0 + 0 + 0 + 1 = 1.
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: instructions = [1,2,3,6,5,4]\r\nOutput: 3\r\nExplanation: Begin with nums = [].\r\nInsert 1 with cost min(0, 0) = 0, now nums = [1].\r\nInsert 2 with cost min(1, 0) = 0, now nums = [1,2].\r\nInsert 3 with cost min(2, 0) = 0, now nums = [1,2,3].\r\nInsert 6 with cost min(3, 0) = 0, now nums = [1,2,3,6].\r\nInsert 5 with cost min(3, 1) = 1, now nums = [1,2,3,5,6].\r\nInsert 4 with cost min(3, 2) = 2, now nums = [1,2,3,4,5,6].\r\nThe total cost is 0 + 0 + 0 + 0 + 1 + 2 = 3.\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: instructions = [1,3,3,3,2,4,2,1,2]\r\nOutput: 4\r\nExplanation: Begin with nums = [].\r\nInsert 1 with cost min(0, 0) = 0, now nums = [1].\r\nInsert 3 with cost min(1, 0) = 0, now nums = [1,3].\r\nInsert 3 with cost min(1, 0) = 0, now nums = [1,3,3].\r\nInsert 3 with cost min(1, 0) = 0, now nums = [1,3,3,3].\r\nInsert 2 with cost min(1, 3) = 1, now nums = [1,2,3,3,3].\r\nInsert 4 with cost min(5, 0) = 0, now nums = [1,2,3,3,3,4].\r\n\u200b\u200b\u200b\u200b\u200b\u200b\u200bInsert 2 with cost min(1, 4) = 1, now nums = [1,2,2,3,3,3,4].\r\n\u200b\u200b\u200b\u200b\u200b\u200b\u200bInsert 1 with cost min(0, 6) = 0, now nums = [1,1,2,2,3,3,3,4].\r\n\u200b\u200b\u200b\u200b\u200b\u200b\u200bInsert 2 with cost min(2, 4) = 2, now nums = [1,1,2,2,2,3,3,3,4].\r\nThe total cost is 0 + 0 + 0 + 0 + 1 + 0 + 1 + 0 + 2 = 4.\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= instructions.length <= 105
  • \r\n\t
  • 1 <= instructions[i] <= 105
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0instructions\u00a0\uff0c\u4f60\u9700\u8981\u6839\u636e\u00a0instructions\u00a0\u4e2d\u7684\u5143\u7d20\u521b\u5efa\u4e00\u4e2a\u6709\u5e8f\u6570\u7ec4\u3002\u4e00\u5f00\u59cb\u4f60\u6709\u4e00\u4e2a\u7a7a\u7684\u6570\u7ec4\u00a0nums\u00a0\uff0c\u4f60\u9700\u8981\u00a0\u4ece\u5de6\u5230\u53f3\u00a0\u904d\u5386\u00a0instructions\u00a0\u4e2d\u7684\u5143\u7d20\uff0c\u5c06\u5b83\u4eec\u4f9d\u6b21\u63d2\u5165\u00a0nums\u00a0\u6570\u7ec4\u4e2d\u3002\u6bcf\u4e00\u6b21\u63d2\u5165\u64cd\u4f5c\u7684\u00a0\u4ee3\u4ef7\u00a0\u662f\u4ee5\u4e0b\u4e24\u8005\u7684 \u8f83\u5c0f\u503c\u00a0\uff1a

\n\n
    \n\t
  • nums\u00a0\u4e2d \u4e25\u683c\u5c0f\u4e8e\u00a0\u00a0instructions[i]\u00a0\u7684\u6570\u5b57\u6570\u76ee\u3002
  • \n\t
  • nums\u00a0\u4e2d \u4e25\u683c\u5927\u4e8e\u00a0\u00a0instructions[i]\u00a0\u7684\u6570\u5b57\u6570\u76ee\u3002
  • \n
\n\n

\u6bd4\u65b9\u8bf4\uff0c\u5982\u679c\u8981\u5c06\u00a03 \u63d2\u5165\u5230\u00a0nums = [1,2,3,5]\u00a0\uff0c\u90a3\u4e48\u63d2\u5165\u64cd\u4f5c\u7684\u00a0\u4ee3\u4ef7\u00a0\u4e3a\u00a0min(2, 1) (\u5143\u7d20\u00a01\u00a0\u548c\u00a0\u00a02\u00a0\u5c0f\u4e8e\u00a03\u00a0\uff0c\u5143\u7d20\u00a05\u00a0\u5927\u4e8e\u00a03\u00a0\uff09\uff0c\u63d2\u5165\u540e\u00a0nums \u53d8\u6210\u00a0[1,2,3,3,5]\u00a0\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u5c06\u00a0instructions\u00a0\u4e2d\u6240\u6709\u5143\u7d20\u4f9d\u6b21\u63d2\u5165\u00a0nums\u00a0\u540e\u7684 \u603b\u6700\u5c0f\u4ee3\u4ef7\u00a0\u3002\u7531\u4e8e\u7b54\u6848\u4f1a\u5f88\u5927\uff0c\u8bf7\u5c06\u5b83\u5bf9\u00a0109 + 7\u00a0\u53d6\u4f59\u00a0\u540e\u8fd4\u56de\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1ainstructions = [1,5,6,2]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u4e00\u5f00\u59cb nums = [] \u3002\n\u63d2\u5165 1 \uff0c\u4ee3\u4ef7\u4e3a min(0, 0) = 0 \uff0c\u73b0\u5728 nums = [1] \u3002\n\u63d2\u5165 5 \uff0c\u4ee3\u4ef7\u4e3a min(1, 0) = 0 \uff0c\u73b0\u5728 nums = [1,5] \u3002\n\u63d2\u5165 6 \uff0c\u4ee3\u4ef7\u4e3a min(2, 0) = 0 \uff0c\u73b0\u5728 nums = [1,5,6] \u3002\n\u63d2\u5165 2 \uff0c\u4ee3\u4ef7\u4e3a min(1, 2) = 1 \uff0c\u73b0\u5728 nums = [1,2,5,6] \u3002\n\u603b\u4ee3\u4ef7\u4e3a 0 + 0 + 0 + 1 = 1 \u3002
\n\n

\u793a\u4f8b 2:

\n\n
\u8f93\u5165\uff1ainstructions = [1,2,3,6,5,4]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u4e00\u5f00\u59cb nums = [] \u3002\n\u63d2\u5165 1 \uff0c\u4ee3\u4ef7\u4e3a min(0, 0) = 0 \uff0c\u73b0\u5728 nums = [1] \u3002\n\u63d2\u5165 2 \uff0c\u4ee3\u4ef7\u4e3a min(1, 0) = 0 \uff0c\u73b0\u5728 nums = [1,2] \u3002\n\u63d2\u5165 3 \uff0c\u4ee3\u4ef7\u4e3a min(2, 0) = 0 \uff0c\u73b0\u5728 nums = [1,2,3] \u3002\n\u63d2\u5165 6 \uff0c\u4ee3\u4ef7\u4e3a min(3, 0) = 0 \uff0c\u73b0\u5728 nums = [1,2,3,6] \u3002\n\u63d2\u5165 5 \uff0c\u4ee3\u4ef7\u4e3a min(3, 1) = 1 \uff0c\u73b0\u5728 nums = [1,2,3,5,6] \u3002\n\u63d2\u5165 4 \uff0c\u4ee3\u4ef7\u4e3a min(3, 2) = 2 \uff0c\u73b0\u5728 nums = [1,2,3,4,5,6] \u3002\n\u603b\u4ee3\u4ef7\u4e3a 0 + 0 + 0 + 0 + 1 + 2 = 3 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1ainstructions = [1,3,3,3,2,4,2,1,2]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u4e00\u5f00\u59cb nums = [] \u3002\n\u63d2\u5165 1 \uff0c\u4ee3\u4ef7\u4e3a min(0, 0) = 0 \uff0c\u73b0\u5728 nums = [1] \u3002\n\u63d2\u5165 3 \uff0c\u4ee3\u4ef7\u4e3a min(1, 0) = 0 \uff0c\u73b0\u5728 nums = [1,3] \u3002\n\u63d2\u5165 3 \uff0c\u4ee3\u4ef7\u4e3a min(1, 0) = 0 \uff0c\u73b0\u5728 nums = [1,3,3] \u3002\n\u63d2\u5165 3 \uff0c\u4ee3\u4ef7\u4e3a min(1, 0) = 0 \uff0c\u73b0\u5728 nums = [1,3,3,3] \u3002\n\u63d2\u5165 2 \uff0c\u4ee3\u4ef7\u4e3a min(1, 3) = 1 \uff0c\u73b0\u5728 nums = [1,2,3,3,3] \u3002\n\u63d2\u5165 4 \uff0c\u4ee3\u4ef7\u4e3a min(5, 0) = 0 \uff0c\u73b0\u5728 nums = [1,2,3,3,3,4] \u3002\n\u200b\u200b\u200b\u200b\u200b\u63d2\u5165 2 \uff0c\u4ee3\u4ef7\u4e3a min(1, 4) = 1 \uff0c\u73b0\u5728 nums = [1,2,2,3,3,3,4] \u3002\n\u63d2\u5165 1 \uff0c\u4ee3\u4ef7\u4e3a min(0, 6) = 0 \uff0c\u73b0\u5728 nums = [1,1,2,2,3,3,3,4] \u3002\n\u63d2\u5165 2 \uff0c\u4ee3\u4ef7\u4e3a min(2, 4) = 2 \uff0c\u73b0\u5728 nums = [1,1,2,2,2,3,3,3,4] \u3002\n\u603b\u4ee3\u4ef7\u4e3a 0 + 0 + 0 + 0 + 1 + 0 + 1 + 0 + 2 = 4 \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= instructions.length <= 105
  • \n\t
  • 1 <= instructions[i] <= 105
  • \n
\n", "tags_en": ["Binary Indexed Tree", "Segment Tree", "Binary Search", "Ordered Map"], "tags_cn": ["\u6811\u72b6\u6570\u7ec4", "\u7ebf\u6bb5\u6811", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int createSortedArray(vector& instructions) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int createSortedArray(int[] instructions) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def createSortedArray(self, instructions):\n \"\"\"\n :type instructions: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def createSortedArray(self, instructions: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint createSortedArray(int* instructions, int instructionsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CreateSortedArray(int[] instructions) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} instructions\n * @return {number}\n */\nvar createSortedArray = function(instructions) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} instructions\n# @return {Integer}\ndef create_sorted_array(instructions)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func createSortedArray(_ instructions: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func createSortedArray(instructions []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def createSortedArray(instructions: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun createSortedArray(instructions: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn create_sorted_array(instructions: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $instructions\n * @return Integer\n */\n function createSortedArray($instructions) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function createSortedArray(instructions: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (create-sorted-array instructions)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1649](https://leetcode-cn.com/problems/create-sorted-array-through-instructions)", "[\u901a\u8fc7\u6307\u4ee4\u521b\u5efa\u6709\u5e8f\u6570\u7ec4](/solution/1600-1699/1649.Create%20Sorted%20Array%20through%20Instructions/README.md)", "`\u6811\u72b6\u6570\u7ec4`,`\u7ebf\u6bb5\u6811`,`\u4e8c\u5206\u67e5\u627e`", "\u56f0\u96be", ""], "md_table_row_en": ["[1649](https://leetcode.com/problems/create-sorted-array-through-instructions)", "[Create Sorted Array through Instructions](/solution/1600-1699/1649.Create%20Sorted%20Array%20through%20Instructions/README_EN.md)", "`Binary Indexed Tree`,`Segment Tree`,`Binary Search`,`Ordered Map`", "Hard", ""]}, {"question_id": "1771", "frontend_question_id": "1648", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sell-diminishing-valued-colored-balls", "url_en": "https://leetcode.com/problems/sell-diminishing-valued-colored-balls", "relative_path_cn": "/solution/1600-1699/1648.Sell%20Diminishing-Valued%20Colored%20Balls/README.md", "relative_path_en": "/solution/1600-1699/1648.Sell%20Diminishing-Valued%20Colored%20Balls/README_EN.md", "title_cn": "\u9500\u552e\u4ef7\u503c\u51cf\u5c11\u7684\u989c\u8272\u7403", "title_en": "Sell Diminishing-Valued Colored Balls", "question_title_slug": "sell-diminishing-valued-colored-balls", "content_en": "

You have an inventory of different colored balls, and there is a customer that wants orders balls of any color.

\n\n

The customer weirdly values the colored balls. Each colored ball's value is the number of balls of that color you currently have in your inventory. For example, if you own 6 yellow balls, the customer would pay 6 for the first yellow ball. After the transaction, there are only 5 yellow balls left, so the next yellow ball is then valued at 5 (i.e., the value of the balls decreases as you sell more to the customer).

\n\n

You are given an integer array, inventory, where inventory[i] represents the number of balls of the ith color that you initially own. You are also given an integer orders, which represents the total number of balls that the customer wants. You can sell the balls in any order.

\n\n

Return the maximum total value that you can attain after selling orders colored balls. As the answer may be too large, return it modulo 109 + 7.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: inventory = [2,5], orders = 4\nOutput: 14\nExplanation: Sell the 1st color 1 time (2) and the 2nd color 3 times (5 + 4 + 3).\nThe maximum total value is 2 + 5 + 4 + 3 = 14.\n
\n\n

Example 2:

\n\n
\nInput: inventory = [3,5], orders = 6\nOutput: 19\nExplanation: Sell the 1st color 2 times (3 + 2) and the 2nd color 4 times (5 + 4 + 3 + 2).\nThe maximum total value is 3 + 2 + 5 + 4 + 3 + 2 = 19.\n
\n\n

Example 3:

\n\n
\nInput: inventory = [2,8,4,10,6], orders = 20\nOutput: 110\n
\n\n

Example 4:

\n\n
\nInput: inventory = [1000000000], orders = 1000000000\nOutput: 21\nExplanation: Sell the 1st color 1000000000 times for a total value of 500000000500000000. 500000000500000000 modulo 109 + 7 = 21.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= inventory.length <= 105
  • \n\t
  • 1 <= inventory[i] <= 109
  • \n\t
  • 1 <= orders <= min(sum(inventory[i]), 109)
  • \n
\n", "content_cn": "

\u4f60\u6709\u4e00\u4e9b\u7403\u7684\u5e93\u5b58\u00a0inventory\u00a0\uff0c\u91cc\u9762\u5305\u542b\u7740\u4e0d\u540c\u989c\u8272\u7684\u7403\u3002\u4e00\u4e2a\u987e\u5ba2\u60f3\u8981\u00a0\u4efb\u610f\u989c\u8272 \u603b\u6570\u4e3a\u00a0orders\u00a0\u7684\u7403\u3002

\n\n

\u8fd9\u4f4d\u987e\u5ba2\u6709\u4e00\u79cd\u7279\u6b8a\u7684\u65b9\u5f0f\u8861\u91cf\u7403\u7684\u4ef7\u503c\uff1a\u6bcf\u4e2a\u7403\u7684\u4ef7\u503c\u662f\u76ee\u524d\u5269\u4e0b\u7684\u00a0\u540c\u8272\u7403\u00a0\u7684\u6570\u76ee\u3002\u6bd4\u65b9\u8bf4\u8fd8\u5269\u4e0b\u00a06\u00a0\u4e2a\u9ec4\u7403\uff0c\u90a3\u4e48\u987e\u5ba2\u4e70\u7b2c\u4e00\u4e2a\u9ec4\u7403\u7684\u65f6\u5019\u8be5\u9ec4\u7403\u7684\u4ef7\u503c\u4e3a\u00a06\u00a0\u3002\u8fd9\u7b14\u4ea4\u6613\u4ee5\u540e\uff0c\u53ea\u5269\u4e0b\u00a05\u00a0\u4e2a\u9ec4\u7403\u4e86\uff0c\u6240\u4ee5\u4e0b\u4e00\u4e2a\u9ec4\u7403\u7684\u4ef7\u503c\u4e3a\u00a05\u00a0\uff08\u4e5f\u5c31\u662f\u7403\u7684\u4ef7\u503c\u968f\u7740\u987e\u5ba2\u8d2d\u4e70\u540c\u8272\u7403\u662f\u9012\u51cf\u7684\uff09

\n\n

\u7ed9\u4f60\u6574\u6570\u6570\u7ec4\u00a0inventory\u00a0\uff0c\u5176\u4e2d\u00a0inventory[i]\u00a0\u8868\u793a\u7b2c\u00a0i\u00a0\u79cd\u989c\u8272\u7403\u4e00\u5f00\u59cb\u7684\u6570\u76ee\u3002\u540c\u65f6\u7ed9\u4f60\u6574\u6570\u00a0orders\u00a0\uff0c\u8868\u793a\u987e\u5ba2\u603b\u5171\u60f3\u4e70\u7684\u7403\u6570\u76ee\u3002\u4f60\u53ef\u4ee5\u6309\u7167 \u4efb\u610f\u987a\u5e8f\u00a0\u5356\u7403\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u5356\u4e86 orders\u00a0\u4e2a\u7403\u4ee5\u540e \u6700\u5927\u00a0\u603b\u4ef7\u503c\u4e4b\u548c\u3002\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u4f1a\u5f88\u5927\uff0c\u8bf7\u4f60\u8fd4\u56de\u7b54\u6848\u5bf9 109\u00a0+ 7\u00a0\u53d6\u4f59\u6570\u00a0\u7684\u7ed3\u679c\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1ainventory = [2,5], orders = 4\n\u8f93\u51fa\uff1a14\n\u89e3\u91ca\uff1a\u5356 1 \u4e2a\u7b2c\u4e00\u79cd\u989c\u8272\u7684\u7403\uff08\u4ef7\u503c\u4e3a 2 )\uff0c\u5356 3 \u4e2a\u7b2c\u4e8c\u79cd\u989c\u8272\u7684\u7403\uff08\u4ef7\u503c\u4e3a 5 + 4 + 3\uff09\u3002\n\u6700\u5927\u603b\u548c\u4e3a 2 + 5 + 4 + 3 = 14 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1ainventory = [3,5], orders = 6\n\u8f93\u51fa\uff1a19\n\u89e3\u91ca\uff1a\u5356 2 \u4e2a\u7b2c\u4e00\u79cd\u989c\u8272\u7684\u7403\uff08\u4ef7\u503c\u4e3a 3 + 2\uff09\uff0c\u5356 4 \u4e2a\u7b2c\u4e8c\u79cd\u989c\u8272\u7684\u7403\uff08\u4ef7\u503c\u4e3a 5 + 4 + 3 + 2\uff09\u3002\n\u6700\u5927\u603b\u548c\u4e3a 3 + 2 + 5 + 4 + 3 + 2 = 19 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1ainventory = [2,8,4,10,6], orders = 20\n\u8f93\u51fa\uff1a110\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1ainventory = [1000000000], orders = 1000000000\n\u8f93\u51fa\uff1a21\n\u89e3\u91ca\uff1a\u5356 1000000000 \u6b21\u7b2c\u4e00\u79cd\u989c\u8272\u7684\u7403\uff0c\u603b\u4ef7\u503c\u4e3a 500000000500000000 \u3002 500000000500000000 \u5bf9 109 + 7 \u53d6\u4f59\u4e3a 21 \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= inventory.length <= 105
  • \n\t
  • 1 <= inventory[i] <= 109
  • \n\t
  • 1 <= orders <= min(sum(inventory[i]), 109)
  • \n
\n", "tags_en": ["Greedy", "Sort", "Math"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6392\u5e8f", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxProfit(vector& inventory, int orders) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxProfit(int[] inventory, int orders) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxProfit(self, inventory, orders):\n \"\"\"\n :type inventory: List[int]\n :type orders: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxProfit(self, inventory: List[int], orders: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxProfit(int* inventory, int inventorySize, int orders){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxProfit(int[] inventory, int orders) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} inventory\n * @param {number} orders\n * @return {number}\n */\nvar maxProfit = function(inventory, orders) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} inventory\n# @param {Integer} orders\n# @return {Integer}\ndef max_profit(inventory, orders)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxProfit(_ inventory: [Int], _ orders: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxProfit(inventory []int, orders int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxProfit(inventory: Array[Int], orders: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxProfit(inventory: IntArray, orders: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_profit(inventory: Vec, orders: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $inventory\n * @param Integer $orders\n * @return Integer\n */\n function maxProfit($inventory, $orders) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxProfit(inventory: number[], orders: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-profit inventory orders)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1648](https://leetcode-cn.com/problems/sell-diminishing-valued-colored-balls)", "[\u9500\u552e\u4ef7\u503c\u51cf\u5c11\u7684\u989c\u8272\u7403](/solution/1600-1699/1648.Sell%20Diminishing-Valued%20Colored%20Balls/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6392\u5e8f`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1648](https://leetcode.com/problems/sell-diminishing-valued-colored-balls)", "[Sell Diminishing-Valued Colored Balls](/solution/1600-1699/1648.Sell%20Diminishing-Valued%20Colored%20Balls/README_EN.md)", "`Greedy`,`Sort`,`Math`", "Medium", ""]}, {"question_id": "1770", "frontend_question_id": "1647", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-deletions-to-make-character-frequencies-unique", "url_en": "https://leetcode.com/problems/minimum-deletions-to-make-character-frequencies-unique", "relative_path_cn": "/solution/1600-1699/1647.Minimum%20Deletions%20to%20Make%20Character%20Frequencies%20Unique/README.md", "relative_path_en": "/solution/1600-1699/1647.Minimum%20Deletions%20to%20Make%20Character%20Frequencies%20Unique/README_EN.md", "title_cn": "\u5b57\u7b26\u9891\u6b21\u552f\u4e00\u7684\u6700\u5c0f\u5220\u9664\u6b21\u6570", "title_en": "Minimum Deletions to Make Character Frequencies Unique", "question_title_slug": "minimum-deletions-to-make-character-frequencies-unique", "content_en": "

A string s is called good if there are no two different characters in s that have the same frequency.

\n\n

Given a string s, return the minimum number of characters you need to delete to make s good.

\n\n

The frequency of a character in a string is the number of times it appears in the string. For example, in the string "aab", the frequency of 'a' is 2, while the frequency of 'b' is 1.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "aab"\nOutput: 0\nExplanation: s is already good.\n
\n\n

Example 2:

\n\n
\nInput: s = "aaabbbcc"\nOutput: 2\nExplanation: You can delete two 'b's resulting in the good string "aaabcc".\nAnother way it to delete one 'b' and one 'c' resulting in the good string "aaabbc".
\n\n

Example 3:

\n\n
\nInput: s = "ceabaacb"\nOutput: 2\nExplanation: You can delete both 'c's resulting in the good string "eabaab".\nNote that we only care about characters that are still in the string at the end (i.e. frequency of 0 is ignored).\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 105
  • \n\t
  • s contains only lowercase English letters.
  • \n
\n", "content_cn": "

\u5982\u679c\u5b57\u7b26\u4e32 s \u4e2d \u4e0d\u5b58\u5728 \u4e24\u4e2a\u4e0d\u540c\u5b57\u7b26 \u9891\u6b21 \u76f8\u540c\u7684\u60c5\u51b5\uff0c\u5c31\u79f0 s \u662f \u4f18\u8d28\u5b57\u7b26\u4e32 \u3002

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s\uff0c\u8fd4\u56de\u4f7f s \u6210\u4e3a \u4f18\u8d28\u5b57\u7b26\u4e32 \u9700\u8981\u5220\u9664\u7684 \u6700\u5c0f \u5b57\u7b26\u6570\u3002

\n\n

\u5b57\u7b26\u4e32\u4e2d\u5b57\u7b26\u7684 \u9891\u6b21 \u662f\u8be5\u5b57\u7b26\u5728\u5b57\u7b26\u4e32\u4e2d\u7684\u51fa\u73b0\u6b21\u6570\u3002\u4f8b\u5982\uff0c\u5728\u5b57\u7b26\u4e32 \"aab\" \u4e2d\uff0c'a' \u7684\u9891\u6b21\u662f 2\uff0c\u800c 'b' \u7684\u9891\u6b21\u662f 1 \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"aab\"\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1as \u5df2\u7ecf\u662f\u4f18\u8d28\u5b57\u7b26\u4e32\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"aaabbbcc\"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u53ef\u4ee5\u5220\u9664\u4e24\u4e2a 'b' , \u5f97\u5230\u4f18\u8d28\u5b57\u7b26\u4e32 \"aaabcc\" \u3002\n\u53e6\u4e00\u79cd\u65b9\u5f0f\u662f\u5220\u9664\u4e00\u4e2a 'b' \u548c\u4e00\u4e2a 'c' \uff0c\u5f97\u5230\u4f18\u8d28\u5b57\u7b26\u4e32 \"aaabbc\" \u3002
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"ceabaacb\"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u53ef\u4ee5\u5220\u9664\u4e24\u4e2a 'c' \u5f97\u5230\u4f18\u8d28\u5b57\u7b26\u4e32 \"eabaab\" \u3002\n\u6ce8\u610f\uff0c\u53ea\u9700\u8981\u5173\u6ce8\u7ed3\u679c\u5b57\u7b26\u4e32\u4e2d\u4ecd\u7136\u5b58\u5728\u7684\u5b57\u7b26\u3002\uff08\u5373\uff0c\u9891\u6b21\u4e3a 0 \u7684\u5b57\u7b26\u4f1a\u5ffd\u7565\u4e0d\u8ba1\u3002\uff09\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length <= 105
  • \n\t
  • s \u4ec5\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd
  • \n
\n", "tags_en": ["Greedy", "Sort"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6392\u5e8f"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minDeletions(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minDeletions(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minDeletions(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minDeletions(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minDeletions(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinDeletions(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar minDeletions = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef min_deletions(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minDeletions(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minDeletions(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minDeletions(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minDeletions(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_deletions(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function minDeletions($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minDeletions(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-deletions s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1647](https://leetcode-cn.com/problems/minimum-deletions-to-make-character-frequencies-unique)", "[\u5b57\u7b26\u9891\u6b21\u552f\u4e00\u7684\u6700\u5c0f\u5220\u9664\u6b21\u6570](/solution/1600-1699/1647.Minimum%20Deletions%20to%20Make%20Character%20Frequencies%20Unique/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6392\u5e8f`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1647](https://leetcode.com/problems/minimum-deletions-to-make-character-frequencies-unique)", "[Minimum Deletions to Make Character Frequencies Unique](/solution/1600-1699/1647.Minimum%20Deletions%20to%20Make%20Character%20Frequencies%20Unique/README_EN.md)", "`Greedy`,`Sort`", "Medium", ""]}, {"question_id": "1769", "frontend_question_id": "1646", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/get-maximum-in-generated-array", "url_en": "https://leetcode.com/problems/get-maximum-in-generated-array", "relative_path_cn": "/solution/1600-1699/1646.Get%20Maximum%20in%20Generated%20Array/README.md", "relative_path_en": "/solution/1600-1699/1646.Get%20Maximum%20in%20Generated%20Array/README_EN.md", "title_cn": "\u83b7\u53d6\u751f\u6210\u6570\u7ec4\u4e2d\u7684\u6700\u5927\u503c", "title_en": "Get Maximum in Generated Array", "question_title_slug": "get-maximum-in-generated-array", "content_en": "

You are given an integer n. An array nums of length n + 1 is generated in the following way:

\n\n
    \n\t
  • nums[0] = 0
  • \n\t
  • nums[1] = 1
  • \n\t
  • nums[2 * i] = nums[i] when 2 <= 2 * i <= n
  • \n\t
  • nums[2 * i + 1] = nums[i] + nums[i + 1] when 2 <= 2 * i + 1 <= n
  • \n
\n\n

Return the maximum integer in the array nums\u200b\u200b\u200b.

\n\n

 

\n

Example 1:

\n\n
\nInput: n = 7\nOutput: 3\nExplanation: According to the given rules:\n  nums[0] = 0\n  nums[1] = 1\n  nums[(1 * 2) = 2] = nums[1] = 1\n  nums[(1 * 2) + 1 = 3] = nums[1] + nums[2] = 1 + 1 = 2\n  nums[(2 * 2) = 4] = nums[2] = 1\n  nums[(2 * 2) + 1 = 5] = nums[2] + nums[3] = 1 + 2 = 3\n  nums[(3 * 2) = 6] = nums[3] = 2\n  nums[(3 * 2) + 1 = 7] = nums[3] + nums[4] = 2 + 1 = 3\nHence, nums = [0,1,1,2,1,3,2,3], and the maximum is 3.\n
\n\n

Example 2:

\n\n
\nInput: n = 2\nOutput: 1\nExplanation: According to the given rules, the maximum between nums[0], nums[1], and nums[2] is 1.\n
\n\n

Example 3:

\n\n
\nInput: n = 3\nOutput: 2\nExplanation: According to the given rules, the maximum between nums[0], nums[1], nums[2], and nums[3] is 2.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 0 <= n <= 100
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n \u3002\u6309\u4e0b\u8ff0\u89c4\u5219\u751f\u6210\u4e00\u4e2a\u957f\u5ea6\u4e3a n + 1 \u7684\u6570\u7ec4 nums \uff1a

\n\n
    \n\t
  • nums[0] = 0
  • \n\t
  • nums[1] = 1
  • \n\t
  • \u5f53 2 <= 2 * i <= n \u65f6\uff0cnums[2 * i] = nums[i]
  • \n\t
  • \u5f53 2 <= 2 * i + 1 <= n \u65f6\uff0cnums[2 * i + 1] = nums[i] + nums[i + 1]
  • \n
\n\n

\u8fd4\u56de\u751f\u6210\u6570\u7ec4 nums \u4e2d\u7684 \u6700\u5927 \u503c\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1an = 7\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6839\u636e\u89c4\u5219\uff1a\n  nums[0] = 0\n  nums[1] = 1\n  nums[(1 * 2) = 2] = nums[1] = 1\n  nums[(1 * 2) + 1 = 3] = nums[1] + nums[2] = 1 + 1 = 2\n  nums[(2 * 2) = 4] = nums[2] = 1\n  nums[(2 * 2) + 1 = 5] = nums[2] + nums[3] = 1 + 2 = 3\n  nums[(3 * 2) = 6] = nums[3] = 2\n  nums[(3 * 2) + 1 = 7] = nums[3] + nums[4] = 2 + 1 = 3\n\u56e0\u6b64\uff0cnums = [0,1,1,2,1,3,2,3]\uff0c\u6700\u5927\u503c 3\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1an = 2\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u6839\u636e\u89c4\u5219\uff0cnums[0]\u3001nums[1] \u548c nums[2] \u4e4b\u4e2d\u7684\u6700\u5927\u503c\u662f 1\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1an = 3\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6839\u636e\u89c4\u5219\uff0cnums[0]\u3001nums[1]\u3001nums[2] \u548c nums[3] \u4e4b\u4e2d\u7684\u6700\u5927\u503c\u662f 2\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 0 <= n <= 100
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int getMaximumGenerated(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int getMaximumGenerated(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getMaximumGenerated(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getMaximumGenerated(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint getMaximumGenerated(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int GetMaximumGenerated(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar getMaximumGenerated = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef get_maximum_generated(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getMaximumGenerated(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getMaximumGenerated(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getMaximumGenerated(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getMaximumGenerated(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_maximum_generated(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function getMaximumGenerated($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getMaximumGenerated(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-maximum-generated n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1646](https://leetcode-cn.com/problems/get-maximum-in-generated-array)", "[\u83b7\u53d6\u751f\u6210\u6570\u7ec4\u4e2d\u7684\u6700\u5927\u503c](/solution/1600-1699/1646.Get%20Maximum%20in%20Generated%20Array/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1646](https://leetcode.com/problems/get-maximum-in-generated-array)", "[Get Maximum in Generated Array](/solution/1600-1699/1646.Get%20Maximum%20in%20Generated%20Array/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1768", "frontend_question_id": "1628", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/design-an-expression-tree-with-evaluate-function", "url_en": "https://leetcode.com/problems/design-an-expression-tree-with-evaluate-function", "relative_path_cn": "/solution/1600-1699/1628.Design%20an%20Expression%20Tree%20With%20Evaluate%20Function/README.md", "relative_path_en": "/solution/1600-1699/1628.Design%20an%20Expression%20Tree%20With%20Evaluate%20Function/README_EN.md", "title_cn": "\u8bbe\u8ba1\u5e26\u89e3\u6790\u51fd\u6570\u7684\u8868\u8fbe\u5f0f\u6811", "title_en": "Design an Expression Tree With Evaluate Function", "question_title_slug": "design-an-expression-tree-with-evaluate-function", "content_en": "

Given the postfix tokens of an arithmetic expression, build and return the binary expression tree that represents this expression.

\r\n\r\n

Postfix notation is a notation for writing arithmetic expressions in which the operands (numbers) appear before their operators. For example, the postfix tokens of the expression 4*(5-(7+2)) are represented in the array postfix = ["4","5","7","2","+","-","*"].

\r\n\r\n

The class Node is an interface you should use to implement the binary expression tree. The returned tree will be tested using the evaluate function, which is supposed to evaluate the tree's value. You should not remove the Node class; however, you can modify it as you wish, and you can define other classes to implement it if needed.

\r\n\r\n

A binary expression tree is a kind of binary tree used to represent arithmetic expressions. Each node of a binary expression tree has either zero or two children. Leaf nodes (nodes with 0 children) correspond to operands (numbers), and internal nodes (nodes with two children) correspond to the operators '+' (addition), '-' (subtraction), '*' (multiplication), and '/' (division).

\r\n\r\n

It's guaranteed that no subtree will yield a value that exceeds 109 in absolute value, and all the operations are valid (i.e., no division by zero).

\r\n\r\n

Follow up: Could you design the expression tree such that it is more modular? For example, is your design able to support additional operators without making changes to your existing evaluate implementation?

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n

\"\"

\r\n\r\n
\r\nInput: s = ["3","4","+","2","*","7","/"]\r\nOutput: 2\r\nExplanation: this expression evaluates to the above binary tree with expression ((3+4)*2)/7) = 14/7 = 2.\r\n
\r\n\r\n

Example 2:

\r\n\r\n

\"\"

\r\n\r\n
\r\nInput: s = ["4","5","7","2","+","-","*"]\r\nOutput: -16\r\nExplanation: this expression evaluates to the above binary tree with expression 4*(5-(2+7)) = 4*(-4) = -16.\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: s = ["4","2","+","3","5","1","-","*","+"]\r\nOutput: 18\r\n
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: s = ["100","200","+","2","/","5","*","7","+"]\r\nOutput: 757\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= s.length < 100
  • \r\n\t
  • s.length is odd.
  • \r\n\t
  • s consists of numbers and the characters '+', '-', '*', and '/'.
  • \r\n\t
  • If s[i] is a number, its integer representation is no more than 105.
  • \r\n\t
  • It is guaranteed that s is a valid expression.
  • \r\n\t
  • The absolute value of the result and intermediate values will not exceed 109.
  • \r\n\t
  • It is guaranteed that no expression will include division by zero.
  • \r\n
", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u7b97\u672f\u8868\u8fbe\u5f0f\u7684\u540e\u7f00\u8868\u793a\u6cd5\u7684\u6807\u8bb0\uff08token\uff09\u00a0postfix\u00a0\uff0c\u6784\u9020\u5e76\u8fd4\u56de\u8be5\u8868\u8fbe\u5f0f\u5bf9\u5e94\u7684\u4e8c\u53c9\u8868\u8fbe\u5f0f\u6811\u3002

\n\n

\u540e\u7f00\u8868\u793a\u6cd5\u662f\u4e00\u79cd\u5c06\u64cd\u4f5c\u6570\u5199\u5728\u8fd0\u7b97\u7b26\u4e4b\u524d\u7684\u8868\u793a\u6cd5\u3002\u4f8b\u5982\uff0c\u8868\u8fbe\u5f0f\u00a04*(5-(2+7))\u00a0\u7684\u540e\u7f00\u8868\u793a\u6cd5\u8868\u793a\u4e3a\u6570\u7ec4\u00a0postfix = [\"4\",\"5\",\"7\",\"2\",\"+\",\"-\",\"*\"]\u00a0\u3002

\n\n

\u62bd\u8c61\u7c7b\u00a0Node\u00a0\u9700\u8981\u7528\u4e8e\u5b9e\u73b0\u4e8c\u53c9\u8868\u8fbe\u5f0f\u6811\u3002\u6211\u4eec\u5c06\u901a\u8fc7\u00a0evaluate\u00a0\u51fd\u6570\u6765\u6d4b\u8bd5\u8fd4\u56de\u7684\u6811\u662f\u5426\u80fd\u591f\u89e3\u6790\u6811\u4e2d\u7684\u503c\u3002\u4f60\u4e0d\u53ef\u4ee5\u79fb\u9664 Node \u7c7b\uff0c\u4f46\u4f60\u53ef\u4ee5\u6309\u9700\u4fee\u6539\u6b64\u7c7b\uff0c\u4e5f\u53ef\u4ee5\u5b9a\u4e49\u5176\u4ed6\u7c7b\u6765\u5b9e\u73b0\u5b83\u3002

\n\n

\u4e8c\u53c9\u8868\u8fbe\u5f0f\u6811\u662f\u4e00\u79cd\u8868\u8fbe\u7b97\u672f\u8868\u8fbe\u5f0f\u7684\u4e8c\u53c9\u6811\u3002\u4e8c\u53c9\u8868\u8fbe\u5f0f\u6811\u4e2d\u7684\u6bcf\u4e00\u4e2a\u8282\u70b9\u90fd\u6709\u96f6\u4e2a\u6216\u4e24\u4e2a\u5b50\u8282\u70b9\u3002\u00a0\u53f6\u8282\u70b9\uff08\u6709 0 \u4e2a\u5b50\u8282\u70b9\u7684\u8282\u70b9\uff09\u8868\u793a\u64cd\u4f5c\u6570\uff0c\u975e\u53f6\u8282\u70b9\uff08\u6709 2 \u4e2a\u5b50\u8282\u70b9\u7684\u8282\u70b9\uff09\u8868\u793a\u8fd0\u7b97\u7b26\uff1a\u00a0'+'\u00a0\uff08\u52a0\uff09\u3001\u00a0'-' \uff08\u51cf\uff09\u3001\u00a0'*' \uff08\u4e58\uff09\u548c\u00a0'/' \uff08\u9664\uff09\u3002

\n\n

\u6211\u4eec\u4fdd\u8bc1\u4efb\u4f55\u5b50\u6811\u5bf9\u5e94\u503c\u7684\u7edd\u5bf9\u503c\u4e0d\u8d85\u8fc7\u00a0109\u00a0\uff0c\u4e14\u6240\u6709\u64cd\u4f5c\u90fd\u662f\u6709\u6548\u7684\uff08\u5373\u6ca1\u6709\u9664\u4ee5\u96f6\u7684\u64cd\u4f5c\uff09

\n\n

\u8fdb\u9636\uff1a\u00a0\u4f60\u53ef\u4ee5\u5c06\u8868\u8fbe\u5f0f\u6811\u8bbe\u8ba1\u5f97\u66f4\u6a21\u5757\u5316\u5417\uff1f\u4f8b\u5982\uff0c\u4f60\u7684\u8bbe\u8ba1\u80fd\u591f\u4e0d\u4fee\u6539\u73b0\u6709\u7684\u00a0evaluate\u00a0\u7684\u5b9e\u73b0\u5c31\u80fd\u652f\u6301\u66f4\u591a\u7684\u64cd\u4f5c\u7b26\u5417\uff1f

\n\n

\u00a0

\n\n

\u793a\u4f8b 1:

\n\n

\"\"

\n\n
\u8f93\u5165\uff1a s = [\"3\",\"4\",\"+\",\"2\",\"*\",\"7\",\"/\"]\n\u8f93\u51fa\uff1a 2\n\u89e3\u91ca\uff1a \u6b64\u8868\u8fbe\u5f0f\u53ef\u89e3\u6790\u4e3a\u4e0a\u8ff0\u4e8c\u53c9\u6811\uff0c\u5176\u5bf9\u5e94\u8868\u8fbe\u5f0f\u4e3a ((3+4)*2)/7) = 14/7 = 2.\n
\n\n

\u793a\u4f8b 2:

\n\n

\"\"

\n\n
\u8f93\u5165: s = [\"4\",\"5\",\"7\",\"2\",\"+\",\"-\",\"*\"]\n\u8f93\u51fa: -16\n\u89e3\u91ca: \u6b64\u8868\u8fbe\u5f0f\u53ef\u89e3\u6790\u4e3a\u4e0a\u8ff0\u4e8c\u53c9\u6811\uff0c\u5176\u5bf9\u5e94\u8868\u8fbe\u5f0f\u4e3a 4*(5-(2+7)) = 4*(-4) = -16.\n
\n\n

\u793a\u4f8b 3:

\n\n
\u8f93\u5165: s = [\"4\",\"2\",\"+\",\"3\",\"5\",\"1\",\"-\",\"*\",\"+\"]\n\u8f93\u51fa: 18\n
\n\n

\u793a\u4f8b 4:

\n\n
\u8f93\u5165: s = [\"100\",\"200\",\"+\",\"2\",\"/\",\"5\",\"*\",\"7\",\"+\"]\n\u8f93\u51fa: 757\n
\n\n

\u00a0

\n\n

\u63d0\u793a:

\n\n
    \n\t
  • 1 <= s.length < 100
  • \n\t
  • s.length\u00a0\u662f\u5947\u6570\u3002
  • \n\t
  • s\u00a0\u5305\u542b\u6570\u5b57\u548c\u5b57\u7b26\u00a0'+'\u00a0\u3001\u00a0'-'\u00a0\u3001\u00a0'*'\u00a0\u4ee5\u53ca\u00a0'/'\u00a0\u3002
  • \n\t
  • \u5982\u679c\u00a0s[i]\u00a0\u662f\u6570\uff0c\u5219\u5bf9\u5e94\u7684\u6574\u6570\u4e0d\u8d85\u8fc7\u00a0105\u00a0\u3002
  • \n\t
  • s\u00a0\u4fdd\u8bc1\u662f\u4e00\u4e2a\u6709\u6548\u7684\u8868\u8fbe\u5f0f\u3002
  • \n\t
  • \u7ed3\u679c\u503c\u548c\u6240\u6709\u8fc7\u7a0b\u503c\u7684\u7edd\u5bf9\u503c\u5747\u4e0d\u8d85\u8fc7\u00a0109\u00a0\u3002
  • \n\t
  • \u4fdd\u8bc1\u8868\u8fbe\u5f0f\u4e0d\u5305\u542b\u9664\u4ee5\u96f6\u7684\u64cd\u4f5c\u3002
  • \n
\n", "tags_en": ["Tree", "Design"], "tags_cn": ["\u6811", "\u8bbe\u8ba1"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * This is the interface for the expression tree Node.\n * You should not remove it, and you can define some classes to implement it.\n */\n\nclass Node {\npublic:\n virtual ~Node () {};\n virtual int evaluate() const = 0;\nprotected:\n // define your fields here\n};\n\n\n/**\n * This is the TreeBuilder class.\n * You can treat it as the driver code that takes the postinfix input \n * and returns the expression tree represnting it as a Node.\n */\n\nclass TreeBuilder {\npublic:\n Node* buildTree(vector& postfix) {\n \n }\n};\n\n\n/**\n * Your TreeBuilder object will be instantiated and called as such:\n * TreeBuilder* obj = new TreeBuilder();\n * Node* expTree = obj->buildTree(postfix);\n * int ans = expTree->evaluate();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * This is the interface for the expression tree Node.\n * You should not remove it, and you can define some classes to implement it.\n */\n\nabstract class Node {\n public abstract int evaluate();\n // define your fields here\n};\n\n\n/**\n * This is the TreeBuilder class.\n * You can treat it as the driver code that takes the postinfix input \n * and returns the expression tree represnting it as a Node.\n */\n\nclass TreeBuilder {\n Node buildTree(String[] postfix) {\n \n }\n};\n\n\n/**\n * Your TreeBuilder object will be instantiated and called as such:\n * TreeBuilder obj = new TreeBuilder();\n * Node expTree = obj.buildTree(postfix);\n * int ans = expTree.evaluate();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "import abc \nfrom abc import ABCMeta, abstractmethod \n\"\"\"\nThis is the interface for the expression tree Node.\nYou should not remove it, and you can define some classes to implement it.\n\"\"\"\n\nclass Node:\n __metaclass__ = ABCMeta\n # define your fields here\n @abstractmethod\n def evaluate(self):\n pass\n\n\n\"\"\" \nThis is the TreeBuilder class.\nYou can treat it as the driver code that takes the postinfix input\nand returns the expression tree represnting it as a Node.\n\"\"\"\n\nclass TreeBuilder(object):\n def buildTree(self, postfix):\n \"\"\"\n :type s: List[str]\n :rtype: int\n \"\"\"\n\n\"\"\"\nYour TreeBuilder object will be instantiated and called as such:\nobj = TreeBuilder();\nexpTree = obj.buildTree(postfix);\nans = expTree.evaluate();\n\"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "import abc \nfrom abc import ABC, abstractmethod \n\"\"\"\nThis is the interface for the expression tree Node.\nYou should not remove it, and you can define some classes to implement it.\n\"\"\"\n\nclass Node(ABC):\n @abstractmethod\n # define your fields here\n def evaluate(self) -> int:\n pass\n\n\n\"\"\" \nThis is the TreeBuilder class.\nYou can treat it as the driver code that takes the postinfix input\nand returns the expression tree represnting it as a Node.\n\"\"\"\n\nclass TreeBuilder(object):\n def buildTree(self, postfix: List[str]) -> 'Node':\n \n\t\t\n\"\"\"\nYour TreeBuilder object will be instantiated and called as such:\nobj = TreeBuilder();\nexpTree = obj.buildTree(postfix);\nans = expTree.evaluate();\n\"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * This is the interface for the expression tree Node.\n * You should not remove it, and you can define some classes to implement it.\n */\n\npublic abstract class Node {\n public abstract int evaluate();\n // define your fields here\n};\n\n\n/**\n * This is the TreeBuilder class.\n * You can treat it as the driver code that takes the postinfix input \n * and returns the expression tree represnting it as a Node.\n */\n\npublic class TreeBuilder {\n public Node buildTree(string[] postfix) {\n \n }\n}\n\n\n/**\n * Your TreeBuilder object will be instantiated and called as such:\n * TreeBuilder obj = new TreeBuilder();\n * Node expTree = obj.buildTree(postfix);\n * int ans = expTree.evaluate();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * This is the interface for the expression tree Node.\n * You should not remove it, and you can define some classes to implement it.\n */\n\nvar Node = function () {\n if (this.constructor === Node) {\n throw new Error('Cannot instanciate abstract class');\n }\n};\n\nNode.prototype.evaluate = function () {\n throw new Error('Cannot call abstract method')\n};\n\n/**\n * This is the TreeBuilder class.\n * You can treat it as the driver code that takes the postinfix input \n * and returns the expression tree represnting it as a Node.\n */\n\nclass TreeBuilder{\n\t/**\n * @param {string[]} s\n * @return {Node}\n */\n\tbuildTree(postfix) {\n \t\n\t}\n \n}\n\n/**\n * Your TreeBuilder object will be instantiated and called as such:\n * var obj = new TreeBuilder();\n * var expTree = obj.buildTree(postfix);\n * var ans = expTree.evaluate();\n */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1628](https://leetcode-cn.com/problems/design-an-expression-tree-with-evaluate-function)", "[\u8bbe\u8ba1\u5e26\u89e3\u6790\u51fd\u6570\u7684\u8868\u8fbe\u5f0f\u6811](/solution/1600-1699/1628.Design%20an%20Expression%20Tree%20With%20Evaluate%20Function/README.md)", "`\u6811`,`\u8bbe\u8ba1`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1628](https://leetcode.com/problems/design-an-expression-tree-with-evaluate-function)", "[Design an Expression Tree With Evaluate Function](/solution/1600-1699/1628.Design%20an%20Expression%20Tree%20With%20Evaluate%20Function/README_EN.md)", "`Tree`,`Design`", "Medium", "\ud83d\udd12"]}, {"question_id": "1767", "frontend_question_id": "1670", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/design-front-middle-back-queue", "url_en": "https://leetcode.com/problems/design-front-middle-back-queue", "relative_path_cn": "/solution/1600-1699/1670.Design%20Front%20Middle%20Back%20Queue/README.md", "relative_path_en": "/solution/1600-1699/1670.Design%20Front%20Middle%20Back%20Queue/README_EN.md", "title_cn": "\u8bbe\u8ba1\u524d\u4e2d\u540e\u961f\u5217", "title_en": "Design Front Middle Back Queue", "question_title_slug": "design-front-middle-back-queue", "content_en": "

Design a queue that supports push and pop operations in the front, middle, and back.

\n\n

Implement the FrontMiddleBack class:

\n\n
    \n\t
  • FrontMiddleBack() Initializes the queue.
  • \n\t
  • void pushFront(int val) Adds val to the front of the queue.
  • \n\t
  • void pushMiddle(int val) Adds val to the middle of the queue.
  • \n\t
  • void pushBack(int val) Adds val to the back of the queue.
  • \n\t
  • int popFront() Removes the front element of the queue and returns it. If the queue is empty, return -1.
  • \n\t
  • int popMiddle() Removes the middle element of the queue and returns it. If the queue is empty, return -1.
  • \n\t
  • int popBack() Removes the back element of the queue and returns it. If the queue is empty, return -1.
  • \n
\n\n

Notice that when there are two middle position choices, the operation is performed on the frontmost middle position choice. For example:

\n\n
    \n\t
  • Pushing 6 into the middle of [1, 2, 3, 4, 5] results in [1, 2, 6, 3, 4, 5].
  • \n\t
  • Popping the middle from [1, 2, 3, 4, 5, 6] returns 3 and results in [1, 2, 4, 5, 6].
  • \n
\n\n

 

\n

Example 1:

\n\n
\nInput:\n["FrontMiddleBackQueue", "pushFront", "pushBack", "pushMiddle", "pushMiddle", "popFront", "popMiddle", "popMiddle", "popBack", "popFront"]\n[[], [1], [2], [3], [4], [], [], [], [], []]\nOutput:\n[null, null, null, null, null, 1, 3, 4, 2, -1]\n\nExplanation:\nFrontMiddleBackQueue q = new FrontMiddleBackQueue();\nq.pushFront(1);   // [1]\nq.pushBack(2);    // [1, 2]\nq.pushMiddle(3);  // [1, 3, 2]\nq.pushMiddle(4);  // [1, 4, 3, 2]\nq.popFront();     // return 1 -> [4, 3, 2]\nq.popMiddle();    // return 3 -> [4, 2]\nq.popMiddle();    // return 4 -> [2]\nq.popBack();      // return 2 -> []\nq.popFront();     // return -1 -> [] (The queue is empty)\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= val <= 109
  • \n\t
  • At most 1000 calls will be made to pushFrontpushMiddlepushBack, popFront, popMiddle, and popBack.
  • \n
\n", "content_cn": "

\u8bf7\u4f60\u8bbe\u8ba1\u4e00\u4e2a\u961f\u5217\uff0c\u652f\u6301\u5728\u524d\uff0c\u4e2d\uff0c\u540e\u4e09\u4e2a\u4f4d\u7f6e\u7684 push\u00a0\u548c pop\u00a0\u64cd\u4f5c\u3002

\n\n

\u8bf7\u4f60\u5b8c\u6210\u00a0FrontMiddleBack\u00a0\u7c7b\uff1a

\n\n
    \n\t
  • FrontMiddleBack()\u00a0\u521d\u59cb\u5316\u961f\u5217\u3002
  • \n\t
  • void pushFront(int val) \u5c06\u00a0val\u00a0\u6dfb\u52a0\u5230\u961f\u5217\u7684 \u6700\u524d\u9762\u00a0\u3002
  • \n\t
  • void pushMiddle(int val) \u5c06\u00a0val\u00a0\u6dfb\u52a0\u5230\u961f\u5217\u7684 \u6b63\u4e2d\u95f4\u00a0\u3002
  • \n\t
  • void pushBack(int val)\u00a0\u5c06\u00a0val\u00a0\u6dfb\u52a0\u5230\u961f\u91cc\u7684 \u6700\u540e\u9762\u00a0\u3002
  • \n\t
  • int popFront()\u00a0\u5c06 \u6700\u524d\u9762 \u7684\u5143\u7d20\u4ece\u961f\u5217\u4e2d\u5220\u9664\u5e76\u8fd4\u56de\u503c\uff0c\u5982\u679c\u5220\u9664\u4e4b\u524d\u961f\u5217\u4e3a\u7a7a\uff0c\u90a3\u4e48\u8fd4\u56de -1\u00a0\u3002
  • \n\t
  • int popMiddle() \u5c06 \u6b63\u4e2d\u95f4\u00a0\u7684\u5143\u7d20\u4ece\u961f\u5217\u4e2d\u5220\u9664\u5e76\u8fd4\u56de\u503c\uff0c\u5982\u679c\u5220\u9664\u4e4b\u524d\u961f\u5217\u4e3a\u7a7a\uff0c\u90a3\u4e48\u8fd4\u56de -1\u00a0\u3002
  • \n\t
  • int popBack() \u5c06 \u6700\u540e\u9762 \u7684\u5143\u7d20\u4ece\u961f\u5217\u4e2d\u5220\u9664\u5e76\u8fd4\u56de\u503c\uff0c\u5982\u679c\u5220\u9664\u4e4b\u524d\u961f\u5217\u4e3a\u7a7a\uff0c\u90a3\u4e48\u8fd4\u56de -1\u00a0\u3002
  • \n
\n\n

\u8bf7\u6ce8\u610f\u5f53\u6709\u00a0\u4e24\u4e2a\u00a0\u4e2d\u95f4\u4f4d\u7f6e\u7684\u65f6\u5019\uff0c\u9009\u62e9\u9760\u524d\u9762\u7684\u4f4d\u7f6e\u8fdb\u884c\u64cd\u4f5c\u3002\u6bd4\u65b9\u8bf4\uff1a

\n\n
    \n\t
  • \u5c06 6\u00a0\u6dfb\u52a0\u5230\u00a0[1, 2, 3, 4, 5]\u00a0\u7684\u4e2d\u95f4\u4f4d\u7f6e\uff0c\u7ed3\u679c\u6570\u7ec4\u4e3a\u00a0[1, 2, 6, 3, 4, 5]\u00a0\u3002
  • \n\t
  • \u4ece\u00a0[1, 2, 3, 4, 5, 6]\u00a0\u7684\u4e2d\u95f4\u4f4d\u7f6e\u5f39\u51fa\u5143\u7d20\uff0c\u8fd4\u56de\u00a03\u00a0\uff0c\u6570\u7ec4\u53d8\u4e3a\u00a0[1, 2, 4, 5, 6]\u00a0\u3002
  • \n
\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1a\n[\"FrontMiddleBackQueue\", \"pushFront\", \"pushBack\", \"pushMiddle\", \"pushMiddle\", \"popFront\", \"popMiddle\", \"popMiddle\", \"popBack\", \"popFront\"]\n[[], [1], [2], [3], [4], [], [], [], [], []]\n\u8f93\u51fa\uff1a\n[null, null, null, null, null, 1, 3, 4, 2, -1]\n\n\u89e3\u91ca\uff1a\nFrontMiddleBackQueue q = new FrontMiddleBackQueue();\nq.pushFront(1);   // [1]\nq.pushBack(2);    // [1, 2]\nq.pushMiddle(3);  // [1, 3, 2]\nq.pushMiddle(4);  // [1, 4, 3, 2]\nq.popFront();     // \u8fd4\u56de 1 -> [4, 3, 2]\nq.popMiddle();    // \u8fd4\u56de 3 -> [4, 2]\nq.popMiddle();    // \u8fd4\u56de 4 -> [2]\nq.popBack();      // \u8fd4\u56de 2 -> []\nq.popFront();     // \u8fd4\u56de -1 -> [] \uff08\u961f\u5217\u4e3a\u7a7a\uff09\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= val <= 109
  • \n\t
  • \u6700\u591a\u8c03\u7528\u00a01000\u00a0\u6b21\u00a0pushFront\uff0c\u00a0pushMiddle\uff0c\u00a0pushBack\uff0c\u00a0popFront\uff0c\u00a0popMiddle\u00a0\u548c\u00a0popBack \u3002
  • \n
\n", "tags_en": ["Design", "Linked List"], "tags_cn": ["\u8bbe\u8ba1", "\u94fe\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class FrontMiddleBackQueue {\npublic:\n FrontMiddleBackQueue() {\n\n }\n \n void pushFront(int val) {\n\n }\n \n void pushMiddle(int val) {\n\n }\n \n void pushBack(int val) {\n\n }\n \n int popFront() {\n\n }\n \n int popMiddle() {\n\n }\n \n int popBack() {\n\n }\n};\n\n/**\n * Your FrontMiddleBackQueue object will be instantiated and called as such:\n * FrontMiddleBackQueue* obj = new FrontMiddleBackQueue();\n * obj->pushFront(val);\n * obj->pushMiddle(val);\n * obj->pushBack(val);\n * int param_4 = obj->popFront();\n * int param_5 = obj->popMiddle();\n * int param_6 = obj->popBack();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class FrontMiddleBackQueue {\n\n public FrontMiddleBackQueue() {\n\n }\n \n public void pushFront(int val) {\n\n }\n \n public void pushMiddle(int val) {\n\n }\n \n public void pushBack(int val) {\n\n }\n \n public int popFront() {\n\n }\n \n public int popMiddle() {\n\n }\n \n public int popBack() {\n\n }\n}\n\n/**\n * Your FrontMiddleBackQueue object will be instantiated and called as such:\n * FrontMiddleBackQueue obj = new FrontMiddleBackQueue();\n * obj.pushFront(val);\n * obj.pushMiddle(val);\n * obj.pushBack(val);\n * int param_4 = obj.popFront();\n * int param_5 = obj.popMiddle();\n * int param_6 = obj.popBack();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class FrontMiddleBackQueue(object):\n\n def __init__(self):\n\n\n def pushFront(self, val):\n \"\"\"\n :type val: int\n :rtype: None\n \"\"\"\n\n\n def pushMiddle(self, val):\n \"\"\"\n :type val: int\n :rtype: None\n \"\"\"\n\n\n def pushBack(self, val):\n \"\"\"\n :type val: int\n :rtype: None\n \"\"\"\n\n\n def popFront(self):\n \"\"\"\n :rtype: int\n \"\"\"\n\n\n def popMiddle(self):\n \"\"\"\n :rtype: int\n \"\"\"\n\n\n def popBack(self):\n \"\"\"\n :rtype: int\n \"\"\"\n\n\n\n# Your FrontMiddleBackQueue object will be instantiated and called as such:\n# obj = FrontMiddleBackQueue()\n# obj.pushFront(val)\n# obj.pushMiddle(val)\n# obj.pushBack(val)\n# param_4 = obj.popFront()\n# param_5 = obj.popMiddle()\n# param_6 = obj.popBack()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class FrontMiddleBackQueue:\n\n def __init__(self):\n\n\n def pushFront(self, val: int) -> None:\n\n\n def pushMiddle(self, val: int) -> None:\n\n\n def pushBack(self, val: int) -> None:\n\n\n def popFront(self) -> int:\n\n\n def popMiddle(self) -> int:\n\n\n def popBack(self) -> int:\n\n\n\n# Your FrontMiddleBackQueue object will be instantiated and called as such:\n# obj = FrontMiddleBackQueue()\n# obj.pushFront(val)\n# obj.pushMiddle(val)\n# obj.pushBack(val)\n# param_4 = obj.popFront()\n# param_5 = obj.popMiddle()\n# param_6 = obj.popBack()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} FrontMiddleBackQueue;\n\n\nFrontMiddleBackQueue* frontMiddleBackQueueCreate() {\n\n}\n\nvoid frontMiddleBackQueuePushFront(FrontMiddleBackQueue* obj, int val) {\n\n}\n\nvoid frontMiddleBackQueuePushMiddle(FrontMiddleBackQueue* obj, int val) {\n\n}\n\nvoid frontMiddleBackQueuePushBack(FrontMiddleBackQueue* obj, int val) {\n\n}\n\nint frontMiddleBackQueuePopFront(FrontMiddleBackQueue* obj) {\n\n}\n\nint frontMiddleBackQueuePopMiddle(FrontMiddleBackQueue* obj) {\n\n}\n\nint frontMiddleBackQueuePopBack(FrontMiddleBackQueue* obj) {\n\n}\n\nvoid frontMiddleBackQueueFree(FrontMiddleBackQueue* obj) {\n\n}\n\n/**\n * Your FrontMiddleBackQueue struct will be instantiated and called as such:\n * FrontMiddleBackQueue* obj = frontMiddleBackQueueCreate();\n * frontMiddleBackQueuePushFront(obj, val);\n \n * frontMiddleBackQueuePushMiddle(obj, val);\n \n * frontMiddleBackQueuePushBack(obj, val);\n \n * int param_4 = frontMiddleBackQueuePopFront(obj);\n \n * int param_5 = frontMiddleBackQueuePopMiddle(obj);\n \n * int param_6 = frontMiddleBackQueuePopBack(obj);\n \n * frontMiddleBackQueueFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class FrontMiddleBackQueue {\n\n public FrontMiddleBackQueue() {\n\n }\n \n public void PushFront(int val) {\n\n }\n \n public void PushMiddle(int val) {\n\n }\n \n public void PushBack(int val) {\n\n }\n \n public int PopFront() {\n\n }\n \n public int PopMiddle() {\n\n }\n \n public int PopBack() {\n\n }\n}\n\n/**\n * Your FrontMiddleBackQueue object will be instantiated and called as such:\n * FrontMiddleBackQueue obj = new FrontMiddleBackQueue();\n * obj.PushFront(val);\n * obj.PushMiddle(val);\n * obj.PushBack(val);\n * int param_4 = obj.PopFront();\n * int param_5 = obj.PopMiddle();\n * int param_6 = obj.PopBack();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "\nvar FrontMiddleBackQueue = function() {\n\n};\n\n/** \n * @param {number} val\n * @return {void}\n */\nFrontMiddleBackQueue.prototype.pushFront = function(val) {\n\n};\n\n/** \n * @param {number} val\n * @return {void}\n */\nFrontMiddleBackQueue.prototype.pushMiddle = function(val) {\n\n};\n\n/** \n * @param {number} val\n * @return {void}\n */\nFrontMiddleBackQueue.prototype.pushBack = function(val) {\n\n};\n\n/**\n * @return {number}\n */\nFrontMiddleBackQueue.prototype.popFront = function() {\n\n};\n\n/**\n * @return {number}\n */\nFrontMiddleBackQueue.prototype.popMiddle = function() {\n\n};\n\n/**\n * @return {number}\n */\nFrontMiddleBackQueue.prototype.popBack = function() {\n\n};\n\n/**\n * Your FrontMiddleBackQueue object will be instantiated and called as such:\n * var obj = new FrontMiddleBackQueue()\n * obj.pushFront(val)\n * obj.pushMiddle(val)\n * obj.pushBack(val)\n * var param_4 = obj.popFront()\n * var param_5 = obj.popMiddle()\n * var param_6 = obj.popBack()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class FrontMiddleBackQueue\n def initialize()\n\n end\n\n\n=begin\n :type val: Integer\n :rtype: Void\n=end\n def push_front(val)\n\n end\n\n\n=begin\n :type val: Integer\n :rtype: Void\n=end\n def push_middle(val)\n\n end\n\n\n=begin\n :type val: Integer\n :rtype: Void\n=end\n def push_back(val)\n\n end\n\n\n=begin\n :rtype: Integer\n=end\n def pop_front()\n\n end\n\n\n=begin\n :rtype: Integer\n=end\n def pop_middle()\n\n end\n\n\n=begin\n :rtype: Integer\n=end\n def pop_back()\n\n end\n\n\nend\n\n# Your FrontMiddleBackQueue object will be instantiated and called as such:\n# obj = FrontMiddleBackQueue.new()\n# obj.push_front(val)\n# obj.push_middle(val)\n# obj.push_back(val)\n# param_4 = obj.pop_front()\n# param_5 = obj.pop_middle()\n# param_6 = obj.pop_back()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass FrontMiddleBackQueue {\n\n init() {\n\n }\n \n func pushFront(_ val: Int) {\n\n }\n \n func pushMiddle(_ val: Int) {\n\n }\n \n func pushBack(_ val: Int) {\n\n }\n \n func popFront() -> Int {\n\n }\n \n func popMiddle() -> Int {\n\n }\n \n func popBack() -> Int {\n\n }\n}\n\n/**\n * Your FrontMiddleBackQueue object will be instantiated and called as such:\n * let obj = FrontMiddleBackQueue()\n * obj.pushFront(val)\n * obj.pushMiddle(val)\n * obj.pushBack(val)\n * let ret_4: Int = obj.popFront()\n * let ret_5: Int = obj.popMiddle()\n * let ret_6: Int = obj.popBack()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type FrontMiddleBackQueue struct {\n\n}\n\n\nfunc Constructor() FrontMiddleBackQueue {\n\n}\n\n\nfunc (this *FrontMiddleBackQueue) PushFront(val int) {\n\n}\n\n\nfunc (this *FrontMiddleBackQueue) PushMiddle(val int) {\n\n}\n\n\nfunc (this *FrontMiddleBackQueue) PushBack(val int) {\n\n}\n\n\nfunc (this *FrontMiddleBackQueue) PopFront() int {\n\n}\n\n\nfunc (this *FrontMiddleBackQueue) PopMiddle() int {\n\n}\n\n\nfunc (this *FrontMiddleBackQueue) PopBack() int {\n\n}\n\n\n/**\n * Your FrontMiddleBackQueue object will be instantiated and called as such:\n * obj := Constructor();\n * obj.PushFront(val);\n * obj.PushMiddle(val);\n * obj.PushBack(val);\n * param_4 := obj.PopFront();\n * param_5 := obj.PopMiddle();\n * param_6 := obj.PopBack();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class FrontMiddleBackQueue() {\n\n def pushFront(`val`: Int) {\n \n }\n\n def pushMiddle(`val`: Int) {\n \n }\n\n def pushBack(`val`: Int) {\n \n }\n\n def popFront(): Int = {\n \n }\n\n def popMiddle(): Int = {\n \n }\n\n def popBack(): Int = {\n \n }\n\n}\n\n/**\n * Your FrontMiddleBackQueue object will be instantiated and called as such:\n * var obj = new FrontMiddleBackQueue()\n * obj.pushFront(`val`)\n * obj.pushMiddle(`val`)\n * obj.pushBack(`val`)\n * var param_4 = obj.popFront()\n * var param_5 = obj.popMiddle()\n * var param_6 = obj.popBack()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class FrontMiddleBackQueue() {\n\n fun pushFront(`val`: Int) {\n\n }\n\n fun pushMiddle(`val`: Int) {\n\n }\n\n fun pushBack(`val`: Int) {\n\n }\n\n fun popFront(): Int {\n\n }\n\n fun popMiddle(): Int {\n\n }\n\n fun popBack(): Int {\n\n }\n\n}\n\n/**\n * Your FrontMiddleBackQueue object will be instantiated and called as such:\n * var obj = FrontMiddleBackQueue()\n * obj.pushFront(`val`)\n * obj.pushMiddle(`val`)\n * obj.pushBack(`val`)\n * var param_4 = obj.popFront()\n * var param_5 = obj.popMiddle()\n * var param_6 = obj.popBack()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct FrontMiddleBackQueue {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl FrontMiddleBackQueue {\n\n fn new() -> Self {\n\n }\n \n fn push_front(&self, val: i32) {\n\n }\n \n fn push_middle(&self, val: i32) {\n\n }\n \n fn push_back(&self, val: i32) {\n\n }\n \n fn pop_front(&self) -> i32 {\n\n }\n \n fn pop_middle(&self) -> i32 {\n\n }\n \n fn pop_back(&self) -> i32 {\n\n }\n}\n\n/**\n * Your FrontMiddleBackQueue object will be instantiated and called as such:\n * let obj = FrontMiddleBackQueue::new();\n * obj.push_front(val);\n * obj.push_middle(val);\n * obj.push_back(val);\n * let ret_4: i32 = obj.pop_front();\n * let ret_5: i32 = obj.pop_middle();\n * let ret_6: i32 = obj.pop_back();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class FrontMiddleBackQueue {\n /**\n */\n function __construct() {\n\n }\n\n /**\n * @param Integer $val\n * @return NULL\n */\n function pushFront($val) {\n\n }\n\n /**\n * @param Integer $val\n * @return NULL\n */\n function pushMiddle($val) {\n\n }\n\n /**\n * @param Integer $val\n * @return NULL\n */\n function pushBack($val) {\n\n }\n\n /**\n * @return Integer\n */\n function popFront() {\n\n }\n\n /**\n * @return Integer\n */\n function popMiddle() {\n\n }\n\n /**\n * @return Integer\n */\n function popBack() {\n\n }\n}\n\n/**\n * Your FrontMiddleBackQueue object will be instantiated and called as such:\n * $obj = FrontMiddleBackQueue();\n * $obj->pushFront($val);\n * $obj->pushMiddle($val);\n * $obj->pushBack($val);\n * $ret_4 = $obj->popFront();\n * $ret_5 = $obj->popMiddle();\n * $ret_6 = $obj->popBack();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class FrontMiddleBackQueue {\n constructor() {\n\n }\n\n pushFront(val: number): void {\n\n }\n\n pushMiddle(val: number): void {\n\n }\n\n pushBack(val: number): void {\n\n }\n\n popFront(): number {\n\n }\n\n popMiddle(): number {\n\n }\n\n popBack(): number {\n\n }\n}\n\n/**\n * Your FrontMiddleBackQueue object will be instantiated and called as such:\n * var obj = new FrontMiddleBackQueue()\n * obj.pushFront(val)\n * obj.pushMiddle(val)\n * obj.pushBack(val)\n * var param_4 = obj.popFront()\n * var param_5 = obj.popMiddle()\n * var param_6 = obj.popBack()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define front-middle-back-queue%\n (class object%\n (super-new)\n (init-field)\n \n ; push-front : exact-integer? -> void?\n (define/public (push-front val)\n\n )\n ; push-middle : exact-integer? -> void?\n (define/public (push-middle val)\n\n )\n ; push-back : exact-integer? -> void?\n (define/public (push-back val)\n\n )\n ; pop-front : -> exact-integer?\n (define/public (pop-front)\n\n )\n ; pop-middle : -> exact-integer?\n (define/public (pop-middle)\n\n )\n ; pop-back : -> exact-integer?\n (define/public (pop-back)\n\n )))\n\n;; Your front-middle-back-queue% object will be instantiated and called as such:\n;; (define obj (new front-middle-back-queue%))\n;; (send obj push-front val)\n;; (send obj push-middle val)\n;; (send obj push-back val)\n;; (define param_4 (send obj pop-front))\n;; (define param_5 (send obj pop-middle))\n;; (define param_6 (send obj pop-back))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1670](https://leetcode-cn.com/problems/design-front-middle-back-queue)", "[\u8bbe\u8ba1\u524d\u4e2d\u540e\u961f\u5217](/solution/1600-1699/1670.Design%20Front%20Middle%20Back%20Queue/README.md)", "`\u8bbe\u8ba1`,`\u94fe\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1670](https://leetcode.com/problems/design-front-middle-back-queue)", "[Design Front Middle Back Queue](/solution/1600-1699/1670.Design%20Front%20Middle%20Back%20Queue/README_EN.md)", "`Design`,`Linked List`", "Medium", ""]}, {"question_id": "1766", "frontend_question_id": "1671", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-number-of-removals-to-make-mountain-array", "url_en": "https://leetcode.com/problems/minimum-number-of-removals-to-make-mountain-array", "relative_path_cn": "/solution/1600-1699/1671.Minimum%20Number%20of%20Removals%20to%20Make%20Mountain%20Array/README.md", "relative_path_en": "/solution/1600-1699/1671.Minimum%20Number%20of%20Removals%20to%20Make%20Mountain%20Array/README_EN.md", "title_cn": "\u5f97\u5230\u5c71\u5f62\u6570\u7ec4\u7684\u6700\u5c11\u5220\u9664\u6b21\u6570", "title_en": "Minimum Number of Removals to Make Mountain Array", "question_title_slug": "minimum-number-of-removals-to-make-mountain-array", "content_en": "

You may recall that an array arr is a mountain array if and only if:

\n\n
    \n\t
  • arr.length >= 3
  • \n\t
  • There exists some index i (0-indexed) with 0 < i < arr.length - 1 such that:\n\t
      \n\t\t
    • arr[0] < arr[1] < ... < arr[i - 1] < arr[i]
    • \n\t\t
    • arr[i] > arr[i + 1] > ... > arr[arr.length - 1]
    • \n\t
    \n\t
  • \n
\n\n

Given an integer array nums\u200b\u200b\u200b, return the minimum number of elements to remove to make nums\u200b\u200b\u200b a mountain array.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [1,3,1]\nOutput: 0\nExplanation: The array itself is a mountain array so we do not need to remove any elements.\n
\n\n

Example 2:

\n\n
\nInput: nums = [2,1,1,5,6,2,3,1]\nOutput: 3\nExplanation: One solution is to remove the elements at indices 0, 1, and 5, making the array nums = [1,5,6,3,1].\n
\n\n

Example 3:

\n\n
\nInput: nums = [4,3,2,1,1,2,3,1]\nOutput: 4\n
\n\n

Example 4:

\n\n
\nInput: nums = [1,2,3,4,4,3,2,1]\nOutput: 1\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 3 <= nums.length <= 1000
  • \n\t
  • 1 <= nums[i] <= 109
  • \n\t
  • It is guaranteed that you can make a mountain array out of nums.
  • \n
\n", "content_cn": "

\u6211\u4eec\u5b9a\u4e49\u00a0arr\u00a0\u662f \u5c71\u5f62\u6570\u7ec4\u00a0\u5f53\u4e14\u4ec5\u5f53\u5b83\u6ee1\u8db3\uff1a

\n\n
    \n\t
  • arr.length >= 3
  • \n\t
  • \u5b58\u5728\u67d0\u4e2a\u4e0b\u6807\u00a0i\u00a0\uff08\u4ece 0 \u5f00\u59cb\uff09\u00a0\u6ee1\u8db3\u00a00 < i < arr.length - 1\u00a0\u4e14\uff1a\n\t
      \n\t\t
    • arr[0] < arr[1] < ... < arr[i - 1] < arr[i]
    • \n\t\t
    • arr[i] > arr[i + 1] > ... > arr[arr.length - 1]
    • \n\t
    \n\t
  • \n
\n\n

\u7ed9\u4f60\u6574\u6570\u6570\u7ec4\u00a0nums\u200b \uff0c\u8bf7\u4f60\u8fd4\u56de\u5c06 nums\u00a0\u53d8\u6210 \u5c71\u5f62\u72b6\u6570\u7ec4\u00a0\u7684\u200b \u6700\u5c11\u00a0\u5220\u9664\u6b21\u6570\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,3,1]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6570\u7ec4\u672c\u8eab\u5c31\u662f\u5c71\u5f62\u6570\u7ec4\uff0c\u6240\u4ee5\u6211\u4eec\u4e0d\u9700\u8981\u5220\u9664\u4efb\u4f55\u5143\u7d20\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anums = [2,1,1,5,6,2,3,1]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u4e00\u79cd\u65b9\u6cd5\u662f\u5c06\u4e0b\u6807\u4e3a 0\uff0c1 \u548c 5 \u7684\u5143\u7d20\u5220\u9664\uff0c\u5269\u4f59\u5143\u7d20\u4e3a [1,5,6,3,1] \uff0c\u662f\u5c71\u5f62\u6570\u7ec4\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1anums = [4,3,2,1,1,2,3,1]\n\u8f93\u51fa\uff1a4\n
\n\n

\u63d0\u793a\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,2,3,4,4,3,2,1]\n\u8f93\u51fa\uff1a1\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 3 <= nums.length <= 1000
  • \n\t
  • 1 <= nums[i] <= 109
  • \n\t
  • \u9898\u76ee\u4fdd\u8bc1\u00a0nums \u5220\u9664\u4e00\u4e9b\u5143\u7d20\u540e\u4e00\u5b9a\u80fd\u5f97\u5230\u5c71\u5f62\u6570\u7ec4\u3002
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minimumMountainRemovals(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minimumMountainRemovals(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimumMountainRemovals(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimumMountainRemovals(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minimumMountainRemovals(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinimumMountainRemovals(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar minimumMountainRemovals = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef minimum_mountain_removals(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimumMountainRemovals(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimumMountainRemovals(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimumMountainRemovals(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimumMountainRemovals(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimum_mountain_removals(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function minimumMountainRemovals($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimumMountainRemovals(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimum-mountain-removals nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1671](https://leetcode-cn.com/problems/minimum-number-of-removals-to-make-mountain-array)", "[\u5f97\u5230\u5c71\u5f62\u6570\u7ec4\u7684\u6700\u5c11\u5220\u9664\u6b21\u6570](/solution/1600-1699/1671.Minimum%20Number%20of%20Removals%20to%20Make%20Mountain%20Array/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1671](https://leetcode.com/problems/minimum-number-of-removals-to-make-mountain-array)", "[Minimum Number of Removals to Make Mountain Array](/solution/1600-1699/1671.Minimum%20Number%20of%20Removals%20to%20Make%20Mountain%20Array/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1765", "frontend_question_id": "1669", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/merge-in-between-linked-lists", "url_en": "https://leetcode.com/problems/merge-in-between-linked-lists", "relative_path_cn": "/solution/1600-1699/1669.Merge%20In%20Between%20Linked%20Lists/README.md", "relative_path_en": "/solution/1600-1699/1669.Merge%20In%20Between%20Linked%20Lists/README_EN.md", "title_cn": "\u5408\u5e76\u4e24\u4e2a\u94fe\u8868", "title_en": "Merge In Between Linked Lists", "question_title_slug": "merge-in-between-linked-lists", "content_en": "

You are given two linked lists: list1 and list2 of sizes n and m respectively.

\n\n

Remove list1's nodes from the ath node to the bth node, and put list2 in their place.

\n\n

The blue edges and nodes in the following figure incidate the result:

\n\"\"\n

Build the result list and return its head.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: list1 = [0,1,2,3,4,5], a = 3, b = 4, list2 = [1000000,1000001,1000002]\nOutput: [0,1,2,1000000,1000001,1000002,5]\nExplanation: We remove the nodes 3 and 4 and put the entire list2 in their place. The blue edges and nodes in the above figure indicate the result.\n
\n\n

Example 2:

\n\"\"\n
\nInput: list1 = [0,1,2,3,4,5,6], a = 2, b = 5, list2 = [1000000,1000001,1000002,1000003,1000004]\nOutput: [0,1,1000000,1000001,1000002,1000003,1000004,6]\nExplanation: The blue edges and nodes in the above figure indicate the result.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 3 <= list1.length <= 104
  • \n\t
  • 1 <= a <= b < list1.length - 1
  • \n\t
  • 1 <= list2.length <= 104
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e24\u4e2a\u94fe\u8868\u00a0list1 \u548c\u00a0list2\u00a0\uff0c\u5b83\u4eec\u5305\u542b\u7684\u5143\u7d20\u5206\u522b\u4e3a\u00a0n \u4e2a\u548c\u00a0m \u4e2a\u3002

\n\n

\u8bf7\u4f60\u5c06\u00a0list1\u00a0\u4e2d\u7b2c\u00a0a\u00a0\u4e2a\u8282\u70b9\u5230\u7b2c\u00a0b\u00a0\u4e2a\u8282\u70b9\u5220\u9664\uff0c\u5e76\u5c06list2\u00a0\u63a5\u5728\u88ab\u5220\u9664\u8282\u70b9\u7684\u4f4d\u7f6e\u3002

\n\n

\u4e0b\u56fe\u4e2d\u84dd\u8272\u8fb9\u548c\u8282\u70b9\u5c55\u793a\u4e86\u64cd\u4f5c\u540e\u7684\u7ed3\u679c\uff1a

\n\"\"\n

\u8bf7\u4f60\u8fd4\u56de\u7ed3\u679c\u94fe\u8868\u7684\u5934\u6307\u9488\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1alist1 = [0,1,2,3,4,5], a = 3, b = 4, list2 = [1000000,1000001,1000002]\n\u8f93\u51fa\uff1a[0,1,2,1000000,1000001,1000002,5]\n\u89e3\u91ca\uff1a\u6211\u4eec\u5220\u9664 list1 \u4e2d\u7b2c\u4e09\u548c\u7b2c\u56db\u4e2a\u8282\u70b9\uff0c\u5e76\u5c06 list2 \u63a5\u5728\u8be5\u4f4d\u7f6e\u3002\u4e0a\u56fe\u4e2d\u84dd\u8272\u7684\u8fb9\u548c\u8282\u70b9\u4e3a\u7b54\u6848\u94fe\u8868\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1alist1 = [0,1,2,3,4,5,6], a = 2, b = 5, list2 = [1000000,1000001,1000002,1000003,1000004]\n\u8f93\u51fa\uff1a[0,1,1000000,1000001,1000002,1000003,1000004,6]\n\u89e3\u91ca\uff1a\u4e0a\u56fe\u4e2d\u84dd\u8272\u7684\u8fb9\u548c\u8282\u70b9\u4e3a\u7b54\u6848\u94fe\u8868\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 3 <= list1.length <= 104
  • \n\t
  • 1 <= a <= b < list1.length - 1
  • \n\t
  • 1 <= list2.length <= 104
  • \n
\n", "tags_en": ["Linked List"], "tags_cn": ["\u94fe\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n ListNode* mergeInBetween(ListNode* list1, int a, int b, ListNode* list2) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public ListNode mergeInBetween(ListNode list1, int a, int b, ListNode list2) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def mergeInBetween(self, list1, a, b, list2):\n \"\"\"\n :type list1: ListNode\n :type a: int\n :type b: int\n :type list2: ListNode\n :rtype: ListNode\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def mergeInBetween(self, list1: ListNode, a: int, b: int, list2: ListNode) -> ListNode:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nstruct ListNode* mergeInBetween(struct ListNode* list1, int a, int b, struct ListNode* list2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public ListNode MergeInBetween(ListNode list1, int a, int b, ListNode list2) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} list1\n * @param {number} a\n * @param {number} b\n * @param {ListNode} list2\n * @return {ListNode}\n */\nvar mergeInBetween = function(list1, a, b, list2) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode} list1\n# @param {Integer} a\n# @param {Integer} b\n# @param {ListNode} list2\n# @return {ListNode}\ndef merge_in_between(list1, a, b, list2)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func mergeInBetween(_ list1: ListNode?, _ a: Int, _ b: Int, _ list2: ListNode?) -> ListNode? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc mergeInBetween(list1 *ListNode, a int, b int, list2 *ListNode) *ListNode {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def mergeInBetween(list1: ListNode, a: Int, b: Int, list2: ListNode): ListNode = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun mergeInBetween(list1: ListNode?, a: Int, b: Int, list2: ListNode?): ListNode? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n// \n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn merge_in_between(list1: Option>, a: i32, b: i32, list2: Option>) -> Option> {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $list1\n * @param Integer $a\n * @param Integer $b\n * @param ListNode $list2\n * @return ListNode\n */\n function mergeInBetween($list1, $a, $b, $list2) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction mergeInBetween(list1: ListNode | null, a: number, b: number, list2: ListNode | null): ListNode | null {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1669](https://leetcode-cn.com/problems/merge-in-between-linked-lists)", "[\u5408\u5e76\u4e24\u4e2a\u94fe\u8868](/solution/1600-1699/1669.Merge%20In%20Between%20Linked%20Lists/README.md)", "`\u94fe\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1669](https://leetcode.com/problems/merge-in-between-linked-lists)", "[Merge In Between Linked Lists](/solution/1600-1699/1669.Merge%20In%20Between%20Linked%20Lists/README_EN.md)", "`Linked List`", "Medium", ""]}, {"question_id": "1764", "frontend_question_id": "1668", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-repeating-substring", "url_en": "https://leetcode.com/problems/maximum-repeating-substring", "relative_path_cn": "/solution/1600-1699/1668.Maximum%20Repeating%20Substring/README.md", "relative_path_en": "/solution/1600-1699/1668.Maximum%20Repeating%20Substring/README_EN.md", "title_cn": "\u6700\u5927\u91cd\u590d\u5b50\u5b57\u7b26\u4e32", "title_en": "Maximum Repeating Substring", "question_title_slug": "maximum-repeating-substring", "content_en": "

For a string sequence, a string word is k-repeating if word concatenated k times is a substring of sequence. The word's maximum k-repeating value is the highest value k where word is k-repeating in sequence. If word is not a substring of sequence, word's maximum k-repeating value is 0.

\n\n

Given strings sequence and word, return the maximum k-repeating value of word in sequence.

\n\n

 

\n

Example 1:

\n\n
\nInput: sequence = "ababc", word = "ab"\nOutput: 2\nExplanation: "abab" is a substring in "ababc".\n
\n\n

Example 2:

\n\n
\nInput: sequence = "ababc", word = "ba"\nOutput: 1\nExplanation: "ba" is a substring in "ababc". "baba" is not a substring in "ababc".\n
\n\n

Example 3:

\n\n
\nInput: sequence = "ababc", word = "ac"\nOutput: 0\nExplanation: "ac" is not a substring in "ababc". \n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= sequence.length <= 100
  • \n\t
  • 1 <= word.length <= 100
  • \n\t
  • sequence and word contains only lowercase English letters.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32\u00a0sequence\u00a0\uff0c\u5982\u679c\u5b57\u7b26\u4e32 word\u00a0\u8fde\u7eed\u91cd\u590d\u00a0k\u00a0\u6b21\u5f62\u6210\u7684\u5b57\u7b26\u4e32\u662f\u00a0sequence\u00a0\u7684\u4e00\u4e2a\u5b50\u5b57\u7b26\u4e32\uff0c\u90a3\u4e48\u5355\u8bcd\u00a0word \u7684 \u91cd\u590d\u503c\u4e3a k \u3002\u5355\u8bcd word\u00a0\u7684 \u6700\u5927\u91cd\u590d\u503c\u00a0\u662f\u5355\u8bcd\u00a0word\u00a0\u5728\u00a0sequence\u00a0\u4e2d\u6700\u5927\u7684\u91cd\u590d\u503c\u3002\u5982\u679c\u00a0word\u00a0\u4e0d\u662f\u00a0sequence\u00a0\u7684\u5b50\u4e32\uff0c\u90a3\u4e48\u91cd\u590d\u503c\u00a0k\u00a0\u4e3a 0 \u3002

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 sequence\u00a0\u548c word\u00a0\uff0c\u8bf7\u4f60\u8fd4\u56de \u6700\u5927\u91cd\u590d\u503c\u00a0k \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1asequence = \"ababc\", word = \"ab\"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\"abab\" \u662f \"ababc\" \u7684\u5b50\u5b57\u7b26\u4e32\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1asequence = \"ababc\", word = \"ba\"\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\"ba\" \u662f \"ababc\" \u7684\u5b50\u5b57\u7b26\u4e32\uff0c\u4f46 \"baba\" \u4e0d\u662f \"ababc\" \u7684\u5b50\u5b57\u7b26\u4e32\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1asequence = \"ababc\", word = \"ac\"\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\"ac\" \u4e0d\u662f \"ababc\" \u7684\u5b50\u5b57\u7b26\u4e32\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= sequence.length <= 100
  • \n\t
  • 1 <= word.length <= 100
  • \n\t
  • sequence \u548c\u00a0word\u00a0\u90fd\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxRepeating(string sequence, string word) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxRepeating(String sequence, String word) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxRepeating(self, sequence, word):\n \"\"\"\n :type sequence: str\n :type word: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxRepeating(self, sequence: str, word: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxRepeating(char * sequence, char * word){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxRepeating(string sequence, string word) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} sequence\n * @param {string} word\n * @return {number}\n */\nvar maxRepeating = function(sequence, word) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} sequence\n# @param {String} word\n# @return {Integer}\ndef max_repeating(sequence, word)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxRepeating(_ sequence: String, _ word: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxRepeating(sequence string, word string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxRepeating(sequence: String, word: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxRepeating(sequence: String, word: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_repeating(sequence: String, word: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $sequence\n * @param String $word\n * @return Integer\n */\n function maxRepeating($sequence, $word) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxRepeating(sequence: string, word: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-repeating sequence word)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1668](https://leetcode-cn.com/problems/maximum-repeating-substring)", "[\u6700\u5927\u91cd\u590d\u5b50\u5b57\u7b26\u4e32](/solution/1600-1699/1668.Maximum%20Repeating%20Substring/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1668](https://leetcode.com/problems/maximum-repeating-substring)", "[Maximum Repeating Substring](/solution/1600-1699/1668.Maximum%20Repeating%20Substring/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1763", "frontend_question_id": "1623", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/all-valid-triplets-that-can-represent-a-country", "url_en": "https://leetcode.com/problems/all-valid-triplets-that-can-represent-a-country", "relative_path_cn": "/solution/1600-1699/1623.All%20Valid%20Triplets%20That%20Can%20Represent%20a%20Country/README.md", "relative_path_en": "/solution/1600-1699/1623.All%20Valid%20Triplets%20That%20Can%20Represent%20a%20Country/README_EN.md", "title_cn": "\u4e09\u4eba\u56fd\u5bb6\u4ee3\u8868\u961f", "title_en": "All Valid Triplets That Can Represent a Country", "question_title_slug": "all-valid-triplets-that-can-represent-a-country", "content_en": "

Table: SchoolA

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| student_id    | int     |\n| student_name  | varchar |\n+---------------+---------+\nstudent_id is the primary key for this table.\nEach row of this table contains the name and the id of a student in school A.\nAll student_name are distinct.\n
\n\n

 

\n\n

Table: SchoolB

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| student_id    | int     |\n| student_name  | varchar |\n+---------------+---------+\nstudent_id is the primary key for this table.\nEach row of this table contains the name and the id of a student in school B.\nAll student_name are distinct.\n
\n\n

 

\n\n

Table: SchoolC

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| student_id    | int     |\n| student_name  | varchar |\n+---------------+---------+\nstudent_id is the primary key for this table.\nEach row of this table contains the name and the id of a student in school C.\nAll student_name are distinct.\n
\n\n

 

\n\n

There is a country with three schools, where each student is enrolled in exactly one school. The country is joining a competition and wants to select one student from each school to represent the country such that:

\n\n
    \n\t
  • member_A is selected from SchoolA,
  • \n\t
  • member_B is selected from SchoolB,
  • \n\t
  • member_C is selected from SchoolC, and
  • \n\t
  • The selected students' names and IDs are pairwise distinct (i.e. no two students share the same name, and no two students share the same ID).
  • \n
\n\n

Write an SQL query to find all the possible triplets representing the country under the given constraints.

\n\n

Return the result table in any order.

\n\n

The query result format is in the following example.

\n\n

 

\n\n
\nSchoolA table:\n+------------+--------------+\n| student_id | student_name |\n+------------+--------------+\n| 1          | Alice        |\n| 2          | Bob          |\n+------------+--------------+\n\nSchoolB table:\n+------------+--------------+\n| student_id | student_name |\n+------------+--------------+\n| 3          | Tom          |\n+------------+--------------+\n\nSchoolC table:\n+------------+--------------+\n| student_id | student_name |\n+------------+--------------+\n| 3          | Tom          |\n| 2          | Jerry        |\n| 10         | Alice        |\n+------------+--------------+\n\nResult table:\n+----------+----------+----------+\n| member_A | member_B | member_C |\n+----------+----------+----------+\n| Alice    | Tom      | Jerry    |\n| Bob      | Tom      | Alice    |\n+----------+----------+----------+\nLet us see all the possible triplets.\n- (Alice, Tom, Tom) --> Rejected because member_B and member_C have the same name and the same ID.\n- (Alice, Tom, Jerry) --> Valid triplet.\n- (Alice, Tom, Alice) --> Rejected because member_A and member_C have the same name.\n- (Bob, Tom, Tom) --> Rejected because member_B and member_C have the same name and the same ID.\n- (Bob, Tom, Jerry) --> Rejected because member_A and member_C have the same ID.\n- (Bob, Tom, Alice) --> Valid triplet.\n
\n", "content_cn": "

\u8868: SchoolA

\n\n
+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| student_id    | int     |\n| student_name  | varchar |\n+---------------+---------+\nstudent_id \u662f\u8868\u7684\u4e3b\u952e\n\u8868\u4e2d\u7684\u6bcf\u4e00\u884c\u5305\u542b\u4e86\u5b66\u6821A\u4e2d\u6bcf\u4e00\u4e2a\u5b66\u751f\u7684\u540d\u5b57\u548cID\n\u6240\u6709student_name\u5728\u8868\u4e2d\u90fd\u662f\u72ec\u4e00\u65e0\u4e8c\u7684\n
\n\n

\u00a0

\n\n

\u8868: SchoolB

\n\n
+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| student_id    | int     |\n| student_name  | varchar |\n+---------------+---------+\nstudent_id \u662f\u8868\u7684\u4e3b\u952e\n\u8868\u4e2d\u7684\u6bcf\u4e00\u884c\u5305\u542b\u4e86\u5b66\u6821B\u4e2d\u6bcf\u4e00\u4e2a\u5b66\u751f\u7684\u540d\u5b57\u548cID\n\u6240\u6709student_name\u5728\u8868\u4e2d\u90fd\u662f\u72ec\u4e00\u65e0\u4e8c\u7684\n
\n\n

\u00a0

\n\n

\u8868: SchoolC

\n\n
+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| student_id    | int     |\n| student_name  | varchar |\n+---------------+---------+\nstudent_id \u662f\u8868\u7684\u4e3b\u952e\n\u8868\u4e2d\u7684\u6bcf\u4e00\u884c\u5305\u542b\u4e86\u5b66\u6821C\u4e2d\u6bcf\u4e00\u4e2a\u5b66\u751f\u7684\u540d\u5b57\u548cID\n\u6240\u6709student_name\u5728\u8868\u4e2d\u90fd\u662f\u72ec\u4e00\u65e0\u4e8c\u7684\n
\n\n

\u00a0

\n\n

\u6709\u4e00\u4e2a\u56fd\u5bb6\u53ea\u6709\u4e09\u6240\u5b66\u6821\uff0c\u8fd9\u4e2a\u56fd\u5bb6\u7684\u6bcf\u4e00\u4e2a\u5b66\u751f\u53ea\u4f1a\u6ce8\u518c\u4e00\u6240\u5b66\u6821\u3002

\n\n

\u8fd9\u4e2a\u56fd\u5bb6\u6b63\u5728\u53c2\u52a0\u4e00\u4e2a\u7ade\u8d5b\uff0c\u4ed6\u4eec\u5e0c\u671b\u4ece\u8fd9\u4e09\u6240\u5b66\u6821\u4e2d\u5404\u9009\u51fa\u4e00\u4e2a\u5b66\u751f\u6765\u7ec4\u5efa\u4e00\u652f\u4e09\u4eba\u7684\u4ee3\u8868\u961f\u3002

\n\n

\u4f8b\u5982\uff1a

\n\n
    \n\t
  • member_A\u662f\u4ece SchoolA\u4e2d\u9009\u51fa\u7684
  • \n\t
  • member_B\u662f\u4ece SchoolB\u4e2d\u9009\u51fa\u7684
  • \n\t
  • member_C\u662f\u4ece SchoolC\u4e2d\u9009\u51fa\u7684
  • \n\t
  • \u88ab\u9009\u4e2d\u7684\u5b66\u751f\u5177\u6709\u4e0d\u540c\u7684\u540d\u5b57\u548cID\uff08\u6ca1\u6709\u4efb\u4f55\u4e24\u4e2a\u5b66\u751f\u62e5\u6709\u76f8\u540c\u7684\u540d\u5b57\u3001\u6ca1\u6709\u4efb\u4f55\u4e24\u4e2a\u5b66\u751f\u62e5\u6709\u76f8\u540c\u7684ID\uff09
  • \n
\n\n

\u4f7f\u7528\u4e0a\u8ff0\u6761\u4ef6\uff0c\u7f16\u5199SQL\u67e5\u8be2\u8bed\u53e5\u6765\u627e\u5230\u6240\u6709\u53ef\u80fd\u7684\u4e09\u4eba\u56fd\u5bb6\u4ee3\u8868\u961f\u7ec4\u5408\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u63a5\u53d7\u4efb\u4f55\u987a\u5e8f\u3002

\n\n

\u00a0

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u6837\u4f8b\uff1a

\n\n
SchoolA table:\n+------------+--------------+\n| student_id | student_name |\n+------------+--------------+\n| 1          | Alice        |\n| 2          | Bob          |\n+------------+--------------+\n\nSchoolB table:\n+------------+--------------+\n| student_id | student_name |\n+------------+--------------+\n| 3          | Tom          |\n+------------+--------------+\n\nSchoolC table:\n+------------+--------------+\n| student_id | student_name |\n+------------+--------------+\n| 3          | Tom          |\n| 2          | Jerry        |\n| 10         | Alice        |\n+------------+--------------+\n\n\u9884\u671f\u7ed3\u679c:\n+----------+----------+----------+\n| member_A | member_B | member_C |\n+----------+----------+----------+\n| Alice    | Tom      | Jerry    |\n| Bob      | Tom      | Alice    |\n+----------+----------+----------+\n\n\u8ba9\u6211\u4eec\u770b\u770b\u6709\u54ea\u4e9b\u53ef\u80fd\u7684\u7ec4\u5408\uff1a\n- (Alice, Tom, Tom) --> \u4e0d\u9002\u7528\uff0c\u56e0\u4e3amember_B\uff08Tom\uff09\u548cmember_C\uff08Tom\uff09\u6709\u76f8\u540c\u7684\u540d\u5b57\u548cID\n- (Alice, Tom, Jerry) --> \u53ef\u80fd\u7684\u7ec4\u5408\n- (Alice, Tom, Alice) --> \u4e0d\u9002\u7528\uff0c\u56e0\u4e3amember_A\u548cmember_C\u6709\u76f8\u540c\u7684\u540d\u5b57\n- (Bob, Tom, Tom) --> \u4e0d\u9002\u7528\uff0c\u56e0\u4e3amember_B\u548cmember_C\u6709\u76f8\u540c\u7684\u540d\u5b57\u548cID\n- (Bob, Tom, Jerry) --> \u4e0d\u9002\u7528\uff0c\u56e0\u4e3amember_A\u548cmember_C\u6709\u76f8\u540c\u7684ID\n- (Bob, Tom, Alice) --> \u53ef\u80fd\u7684\u7ec4\u5408.\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1623](https://leetcode-cn.com/problems/all-valid-triplets-that-can-represent-a-country)", "[\u4e09\u4eba\u56fd\u5bb6\u4ee3\u8868\u961f](/solution/1600-1699/1623.All%20Valid%20Triplets%20That%20Can%20Represent%20a%20Country/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1623](https://leetcode.com/problems/all-valid-triplets-that-can-represent-a-country)", "[All Valid Triplets That Can Represent a Country](/solution/1600-1699/1623.All%20Valid%20Triplets%20That%20Can%20Represent%20a%20Country/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1762", "frontend_question_id": "1642", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/furthest-building-you-can-reach", "url_en": "https://leetcode.com/problems/furthest-building-you-can-reach", "relative_path_cn": "/solution/1600-1699/1642.Furthest%20Building%20You%20Can%20Reach/README.md", "relative_path_en": "/solution/1600-1699/1642.Furthest%20Building%20You%20Can%20Reach/README_EN.md", "title_cn": "\u53ef\u4ee5\u5230\u8fbe\u7684\u6700\u8fdc\u5efa\u7b51", "title_en": "Furthest Building You Can Reach", "question_title_slug": "furthest-building-you-can-reach", "content_en": "

You are given an integer array heights representing the heights of buildings, some bricks, and some ladders.

\n\n

You start your journey from building 0 and move to the next building by possibly using bricks or ladders.

\n\n

While moving from building i to building i+1 (0-indexed),

\n\n
    \n\t
  • If the current building's height is greater than or equal to the next building's height, you do not need a ladder or bricks.
  • \n\t
  • If the current building's height is less than the next building's height, you can either use one ladder or (h[i+1] - h[i]) bricks.
  • \n
\n\n

Return the furthest building index (0-indexed) you can reach if you use the given ladders and bricks optimally.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: heights = [4,2,7,6,9,14,12], bricks = 5, ladders = 1\nOutput: 4\nExplanation: Starting at building 0, you can follow these steps:\n- Go to building 1 without using ladders nor bricks since 4 >= 2.\n- Go to building 2 using 5 bricks. You must use either bricks or ladders because 2 < 7.\n- Go to building 3 without using ladders nor bricks since 7 >= 6.\n- Go to building 4 using your only ladder. You must use either bricks or ladders because 6 < 9.\nIt is impossible to go beyond building 4 because you do not have any more bricks or ladders.\n
\n\n

Example 2:

\n\n
\nInput: heights = [4,12,2,7,3,18,20,3,19], bricks = 10, ladders = 2\nOutput: 7\n
\n\n

Example 3:

\n\n
\nInput: heights = [14,3,19,3], bricks = 17, ladders = 0\nOutput: 3\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= heights.length <= 105
  • \n\t
  • 1 <= heights[i] <= 106
  • \n\t
  • 0 <= bricks <= 109
  • \n\t
  • 0 <= ladders <= heights.length
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 heights \uff0c\u8868\u793a\u5efa\u7b51\u7269\u7684\u9ad8\u5ea6\u3002\u53e6\u6709\u4e00\u4e9b\u7816\u5757 bricks \u548c\u68af\u5b50 ladders \u3002

\n\n

\u4f60\u4ece\u5efa\u7b51\u7269 0 \u5f00\u59cb\u65c5\u7a0b\uff0c\u4e0d\u65ad\u5411\u540e\u9762\u7684\u5efa\u7b51\u7269\u79fb\u52a8\uff0c\u671f\u95f4\u53ef\u80fd\u4f1a\u7528\u5230\u7816\u5757\u6216\u68af\u5b50\u3002

\n\n

\u5f53\u4ece\u5efa\u7b51\u7269 i \u79fb\u52a8\u5230\u5efa\u7b51\u7269 i+1\uff08\u4e0b\u6807 \u4ece 0 \u5f00\u59cb \uff09\u65f6\uff1a

\n\n
    \n\t
  • \u5982\u679c\u5f53\u524d\u5efa\u7b51\u7269\u7684\u9ad8\u5ea6 \u5927\u4e8e\u6216\u7b49\u4e8e \u4e0b\u4e00\u5efa\u7b51\u7269\u7684\u9ad8\u5ea6\uff0c\u5219\u4e0d\u9700\u8981\u68af\u5b50\u6216\u7816\u5757
  • \n\t
  • \u5982\u679c\u5f53\u524d\u5efa\u7b51\u7684\u9ad8\u5ea6 \u5c0f\u4e8e \u4e0b\u4e00\u4e2a\u5efa\u7b51\u7684\u9ad8\u5ea6\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 \u4e00\u67b6\u68af\u5b50 \u6216 (h[i+1] - h[i]) \u4e2a\u7816\u5757
  • \n
\n\u5982\u679c\u4ee5\u6700\u4f73\u65b9\u5f0f\u4f7f\u7528\u7ed9\u5b9a\u7684\u68af\u5b50\u548c\u7816\u5757\uff0c\u8fd4\u56de\u4f60\u53ef\u4ee5\u5230\u8fbe\u7684\u6700\u8fdc\u5efa\u7b51\u7269\u7684\u4e0b\u6807\uff08\u4e0b\u6807 \u4ece 0 \u5f00\u59cb \uff09\u3002\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1aheights = [4,2,7,6,9,14,12], bricks = 5, ladders = 1\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u4ece\u5efa\u7b51\u7269 0 \u51fa\u53d1\uff0c\u4f60\u53ef\u4ee5\u6309\u6b64\u65b9\u6848\u5b8c\u6210\u65c5\u7a0b\uff1a\n- \u4e0d\u4f7f\u7528\u7816\u5757\u6216\u68af\u5b50\u5230\u8fbe\u5efa\u7b51\u7269 1 \uff0c\u56e0\u4e3a 4 >= 2\n- \u4f7f\u7528 5 \u4e2a\u7816\u5757\u5230\u8fbe\u5efa\u7b51\u7269 2 \u3002\u4f60\u5fc5\u987b\u4f7f\u7528\u7816\u5757\u6216\u68af\u5b50\uff0c\u56e0\u4e3a 2 < 7\n- \u4e0d\u4f7f\u7528\u7816\u5757\u6216\u68af\u5b50\u5230\u8fbe\u5efa\u7b51\u7269 3 \uff0c\u56e0\u4e3a 7 >= 6\n- \u4f7f\u7528\u552f\u4e00\u7684\u68af\u5b50\u5230\u8fbe\u5efa\u7b51\u7269 4 \u3002\u4f60\u5fc5\u987b\u4f7f\u7528\u7816\u5757\u6216\u68af\u5b50\uff0c\u56e0\u4e3a 6 < 9\n\u65e0\u6cd5\u8d8a\u8fc7\u5efa\u7b51\u7269 4 \uff0c\u56e0\u4e3a\u6ca1\u6709\u66f4\u591a\u7816\u5757\u6216\u68af\u5b50\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aheights = [4,12,2,7,3,18,20,3,19], bricks = 10, ladders = 2\n\u8f93\u51fa\uff1a7\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1aheights = [14,3,19,3], bricks = 17, ladders = 0\n\u8f93\u51fa\uff1a3\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= heights.length <= 105
  • \n\t
  • 1 <= heights[i] <= 106
  • \n\t
  • 0 <= bricks <= 109
  • \n\t
  • 0 <= ladders <= heights.length
  • \n
\n", "tags_en": ["Heap", "Binary Search"], "tags_cn": ["\u5806", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int furthestBuilding(vector& heights, int bricks, int ladders) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int furthestBuilding(int[] heights, int bricks, int ladders) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def furthestBuilding(self, heights, bricks, ladders):\n \"\"\"\n :type heights: List[int]\n :type bricks: int\n :type ladders: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def furthestBuilding(self, heights: List[int], bricks: int, ladders: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint furthestBuilding(int* heights, int heightsSize, int bricks, int ladders){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FurthestBuilding(int[] heights, int bricks, int ladders) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} heights\n * @param {number} bricks\n * @param {number} ladders\n * @return {number}\n */\nvar furthestBuilding = function(heights, bricks, ladders) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} heights\n# @param {Integer} bricks\n# @param {Integer} ladders\n# @return {Integer}\ndef furthest_building(heights, bricks, ladders)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func furthestBuilding(_ heights: [Int], _ bricks: Int, _ ladders: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func furthestBuilding(heights []int, bricks int, ladders int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def furthestBuilding(heights: Array[Int], bricks: Int, ladders: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun furthestBuilding(heights: IntArray, bricks: Int, ladders: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn furthest_building(heights: Vec, bricks: i32, ladders: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $heights\n * @param Integer $bricks\n * @param Integer $ladders\n * @return Integer\n */\n function furthestBuilding($heights, $bricks, $ladders) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function furthestBuilding(heights: number[], bricks: number, ladders: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (furthest-building heights bricks ladders)\n (-> (listof exact-integer?) exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1642](https://leetcode-cn.com/problems/furthest-building-you-can-reach)", "[\u53ef\u4ee5\u5230\u8fbe\u7684\u6700\u8fdc\u5efa\u7b51](/solution/1600-1699/1642.Furthest%20Building%20You%20Can%20Reach/README.md)", "`\u5806`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1642](https://leetcode.com/problems/furthest-building-you-can-reach)", "[Furthest Building You Can Reach](/solution/1600-1699/1642.Furthest%20Building%20You%20Can%20Reach/README_EN.md)", "`Heap`,`Binary Search`", "Medium", ""]}, {"question_id": "1761", "frontend_question_id": "1641", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-sorted-vowel-strings", "url_en": "https://leetcode.com/problems/count-sorted-vowel-strings", "relative_path_cn": "/solution/1600-1699/1641.Count%20Sorted%20Vowel%20Strings/README.md", "relative_path_en": "/solution/1600-1699/1641.Count%20Sorted%20Vowel%20Strings/README_EN.md", "title_cn": "\u7edf\u8ba1\u5b57\u5178\u5e8f\u5143\u97f3\u5b57\u7b26\u4e32\u7684\u6570\u76ee", "title_en": "Count Sorted Vowel Strings", "question_title_slug": "count-sorted-vowel-strings", "content_en": "

Given an integer n, return the number of strings of length n that consist only of vowels (a, e, i, o, u) and are lexicographically sorted.

\n\n

A string s is lexicographically sorted if for all valid i, s[i] is the same as or comes before s[i+1] in the alphabet.

\n\n

 

\n

Example 1:

\n\n
\nInput: n = 1\nOutput: 5\nExplanation: The 5 sorted strings that consist of vowels only are ["a","e","i","o","u"].\n
\n\n

Example 2:

\n\n
\nInput: n = 2\nOutput: 15\nExplanation: The 15 sorted strings that consist of vowels only are\n["aa","ae","ai","ao","au","ee","ei","eo","eu","ii","io","iu","oo","ou","uu"].\nNote that "ea" is not a valid string since 'e' comes after 'a' in the alphabet.\n
\n\n

Example 3:

\n\n
\nInput: n = 33\nOutput: 66045\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 50 
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n\uff0c\u8bf7\u8fd4\u56de\u957f\u5ea6\u4e3a n \u3001\u4ec5\u7531\u5143\u97f3 (a, e, i, o, u) \u7ec4\u6210\u4e14\u6309 \u5b57\u5178\u5e8f\u6392\u5217 \u7684\u5b57\u7b26\u4e32\u6570\u91cf\u3002

\n\n

\u5b57\u7b26\u4e32 s \u6309 \u5b57\u5178\u5e8f\u6392\u5217 \u9700\u8981\u6ee1\u8db3\uff1a\u5bf9\u4e8e\u6240\u6709\u6709\u6548\u7684 i\uff0cs[i] \u5728\u5b57\u6bcd\u8868\u4e2d\u7684\u4f4d\u7f6e\u603b\u662f\u4e0e s[i+1] \u76f8\u540c\u6216\u5728 s[i+1] \u4e4b\u524d\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u4ec5\u7531\u5143\u97f3\u7ec4\u6210\u7684 5 \u4e2a\u5b57\u5178\u5e8f\u5b57\u7b26\u4e32\u4e3a [\"a\",\"e\",\"i\",\"o\",\"u\"]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1an = 2\n\u8f93\u51fa\uff1a15\n\u89e3\u91ca\uff1a\u4ec5\u7531\u5143\u97f3\u7ec4\u6210\u7684 15 \u4e2a\u5b57\u5178\u5e8f\u5b57\u7b26\u4e32\u4e3a\n[\"aa\",\"ae\",\"ai\",\"ao\",\"au\",\"ee\",\"ei\",\"eo\",\"eu\",\"ii\",\"io\",\"iu\",\"oo\",\"ou\",\"uu\"]\n\u6ce8\u610f\uff0c\"ea\" \u4e0d\u662f\u7b26\u5408\u9898\u610f\u7684\u5b57\u7b26\u4e32\uff0c\u56e0\u4e3a 'e' \u5728\u5b57\u6bcd\u8868\u4e2d\u7684\u4f4d\u7f6e\u6bd4 'a' \u9760\u540e\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1an = 33\n\u8f93\u51fa\uff1a66045\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 50\u00a0
  • \n
\n", "tags_en": ["Math", "Dynamic Programming", "Backtracking"], "tags_cn": ["\u6570\u5b66", "\u52a8\u6001\u89c4\u5212", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countVowelStrings(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countVowelStrings(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countVowelStrings(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countVowelStrings(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countVowelStrings(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountVowelStrings(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar countVowelStrings = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef count_vowel_strings(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countVowelStrings(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countVowelStrings(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countVowelStrings(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countVowelStrings(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_vowel_strings(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function countVowelStrings($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countVowelStrings(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-vowel-strings n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1641](https://leetcode-cn.com/problems/count-sorted-vowel-strings)", "[\u7edf\u8ba1\u5b57\u5178\u5e8f\u5143\u97f3\u5b57\u7b26\u4e32\u7684\u6570\u76ee](/solution/1600-1699/1641.Count%20Sorted%20Vowel%20Strings/README.md)", "`\u6570\u5b66`,`\u52a8\u6001\u89c4\u5212`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1641](https://leetcode.com/problems/count-sorted-vowel-strings)", "[Count Sorted Vowel Strings](/solution/1600-1699/1641.Count%20Sorted%20Vowel%20Strings/README_EN.md)", "`Math`,`Dynamic Programming`,`Backtracking`", "Medium", ""]}, {"question_id": "1760", "frontend_question_id": "1640", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/check-array-formation-through-concatenation", "url_en": "https://leetcode.com/problems/check-array-formation-through-concatenation", "relative_path_cn": "/solution/1600-1699/1640.Check%20Array%20Formation%20Through%20Concatenation/README.md", "relative_path_en": "/solution/1600-1699/1640.Check%20Array%20Formation%20Through%20Concatenation/README_EN.md", "title_cn": "\u80fd\u5426\u8fde\u63a5\u5f62\u6210\u6570\u7ec4", "title_en": "Check Array Formation Through Concatenation", "question_title_slug": "check-array-formation-through-concatenation", "content_en": "

You are given an array of distinct integers arr and an array of integer arrays pieces, where the integers in pieces are distinct. Your goal is to form arr by concatenating the arrays in pieces in any order. However, you are not allowed to reorder the integers in each array pieces[i].

\n\n

Return true if it is possible to form the array arr from pieces. Otherwise, return false.

\n\n

 

\n

Example 1:

\n\n
\nInput: arr = [85], pieces = [[85]]\nOutput: true\n
\n\n

Example 2:

\n\n
\nInput: arr = [15,88], pieces = [[88],[15]]\nOutput: true\nExplanation: Concatenate [15] then [88]\n
\n\n

Example 3:

\n\n
\nInput: arr = [49,18,16], pieces = [[16,18,49]]\nOutput: false\nExplanation: Even though the numbers match, we cannot reorder pieces[0].\n
\n\n

Example 4:

\n\n
\nInput: arr = [91,4,64,78], pieces = [[78],[4,64],[91]]\nOutput: true\nExplanation: Concatenate [91] then [4,64] then [78]
\n\n

Example 5:

\n\n
\nInput: arr = [1,3,5,7], pieces = [[2,4,6,8]]\nOutput: false\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= pieces.length <= arr.length <= 100
  • \n\t
  • sum(pieces[i].length) == arr.length
  • \n\t
  • 1 <= pieces[i].length <= arr.length
  • \n\t
  • 1 <= arr[i], pieces[i][j] <= 100
  • \n\t
  • The integers in arr are distinct.
  • \n\t
  • The integers in pieces are distinct (i.e., If we flatten pieces in a 1D array, all the integers in this array are distinct).
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr \uff0c\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u6574\u6570 \u4e92\u4e0d\u76f8\u540c \u3002\u53e6\u6709\u4e00\u4e2a\u7531\u6574\u6570\u6570\u7ec4\u6784\u6210\u7684\u6570\u7ec4 pieces\uff0c\u5176\u4e2d\u7684\u6574\u6570\u4e5f \u4e92\u4e0d\u76f8\u540c \u3002\u8bf7\u4f60\u4ee5 \u4efb\u610f\u987a\u5e8f \u8fde\u63a5 pieces \u4e2d\u7684\u6570\u7ec4\u4ee5\u5f62\u6210 arr \u3002\u4f46\u662f\uff0c\u4e0d\u5141\u8bb8 \u5bf9\u6bcf\u4e2a\u6570\u7ec4 pieces[i] \u4e2d\u7684\u6574\u6570\u91cd\u65b0\u6392\u5e8f\u3002

\n\n

\u5982\u679c\u53ef\u4ee5\u8fde\u63a5 pieces \u4e2d\u7684\u6570\u7ec4\u5f62\u6210 arr \uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [85], pieces = [[85]]\n\u8f93\u51fa\uff1atrue\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [15,88], pieces = [[88],[15]]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u4f9d\u6b21\u8fde\u63a5 [15] \u548c [88]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [49,18,16], pieces = [[16,18,49]]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u5373\u4fbf\u6570\u5b57\u76f8\u7b26\uff0c\u4e5f\u4e0d\u80fd\u91cd\u65b0\u6392\u5217 pieces[0]\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [91,4,64,78], pieces = [[78],[4,64],[91]]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u4f9d\u6b21\u8fde\u63a5 [91]\u3001[4,64] \u548c [78]
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [1,3,5,7], pieces = [[2,4,6,8]]\n\u8f93\u51fa\uff1afalse\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= pieces.length <= arr.length <= 100
  • \n\t
  • sum(pieces[i].length) == arr.length
  • \n\t
  • 1 <= pieces[i].length <= arr.length
  • \n\t
  • 1 <= arr[i], pieces[i][j] <= 100
  • \n\t
  • arr \u4e2d\u7684\u6574\u6570 \u4e92\u4e0d\u76f8\u540c
  • \n\t
  • pieces \u4e2d\u7684\u6574\u6570 \u4e92\u4e0d\u76f8\u540c\uff08\u4e5f\u5c31\u662f\u8bf4\uff0c\u5982\u679c\u5c06 pieces \u6241\u5e73\u5316\u6210\u4e00\u7ef4\u6570\u7ec4\uff0c\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u6574\u6570\u4e92\u4e0d\u76f8\u540c\uff09
  • \n
\n", "tags_en": ["Sort", "Array", "Hash Table"], "tags_cn": ["\u6392\u5e8f", "\u6570\u7ec4", "\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canFormArray(vector& arr, vector>& pieces) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canFormArray(int[] arr, int[][] pieces) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canFormArray(self, arr, pieces):\n \"\"\"\n :type arr: List[int]\n :type pieces: List[List[int]]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canFormArray(self, arr: List[int], pieces: List[List[int]]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canFormArray(int* arr, int arrSize, int** pieces, int piecesSize, int* piecesColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanFormArray(int[] arr, int[][] pieces) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @param {number[][]} pieces\n * @return {boolean}\n */\nvar canFormArray = function(arr, pieces) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @param {Integer[][]} pieces\n# @return {Boolean}\ndef can_form_array(arr, pieces)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canFormArray(_ arr: [Int], _ pieces: [[Int]]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canFormArray(arr []int, pieces [][]int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canFormArray(arr: Array[Int], pieces: Array[Array[Int]]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canFormArray(arr: IntArray, pieces: Array): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_form_array(arr: Vec, pieces: Vec>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @param Integer[][] $pieces\n * @return Boolean\n */\n function canFormArray($arr, $pieces) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canFormArray(arr: number[], pieces: number[][]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-form-array arr pieces)\n (-> (listof exact-integer?) (listof (listof exact-integer?)) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1640](https://leetcode-cn.com/problems/check-array-formation-through-concatenation)", "[\u80fd\u5426\u8fde\u63a5\u5f62\u6210\u6570\u7ec4](/solution/1600-1699/1640.Check%20Array%20Formation%20Through%20Concatenation/README.md)", "`\u6392\u5e8f`,`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[1640](https://leetcode.com/problems/check-array-formation-through-concatenation)", "[Check Array Formation Through Concatenation](/solution/1600-1699/1640.Check%20Array%20Formation%20Through%20Concatenation/README_EN.md)", "`Sort`,`Array`,`Hash Table`", "Easy", ""]}, {"question_id": "1759", "frontend_question_id": "1613", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/find-the-missing-ids", "url_en": "https://leetcode.com/problems/find-the-missing-ids", "relative_path_cn": "/solution/1600-1699/1613.Find%20the%20Missing%20IDs/README.md", "relative_path_en": "/solution/1600-1699/1613.Find%20the%20Missing%20IDs/README_EN.md", "title_cn": "\u627e\u5230\u9057\u5931\u7684ID", "title_en": "Find the Missing IDs", "question_title_slug": "find-the-missing-ids", "content_en": "

Table: Customers

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| customer_id   | int     |\n| customer_name | varchar |\n+---------------+---------+\ncustomer_id is the primary key for this table.\nEach row of this table contains the name and the id customer.\n
\n\n

 

\n\n

Write an SQL query to find the missing customer IDs. The missing IDs are ones that are not in the Customers table but are in the range between 1 and the maximum customer_id present in the table.

\n\n

Notice that the maximum customer_id will not exceed 100.

\n\n

Return the result table ordered by ids in ascending order.

\n\n

The query result format is in the following example.

\n\n

 

\n\n
\nCustomers table:\n+-------------+---------------+\n| customer_id | customer_name |\n+-------------+---------------+\n| 1           | Alice         |\n| 4           | Bob           |\n| 5           | Charlie       |\n+-------------+---------------+\n\nResult table:\n+-----+\n| ids |\n+-----+\n| 2   |\n| 3   |\n+-----+\nThe maximum customer_id present in the table is 5, so in the range [1,5], IDs 2 and 3 are missing from the table.
\n", "content_cn": "

\u8868: Customers

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| customer_id   | int     |\n| customer_name | varchar |\n+---------------+---------+\ncustomer_id \u662f\u8be5\u8868\u4e3b\u952e.\n\u8be5\u8868\u7b2c\u4e00\u884c\u5305\u542b\u4e86\u987e\u5ba2\u7684\u540d\u5b57\u548cid.\n
\n\n

\u00a0

\n\n

\u5199\u4e00\u4e2a SQL \u8bed\u53e5,\u00a0\u627e\u5230\u6240\u6709\u9057\u5931\u7684\u987e\u5ba2id.\u00a0\u9057\u5931\u7684\u987e\u5ba2id\u662f\u6307\u90a3\u4e9b\u4e0d\u5728\u00a0Customers\u00a0\u8868\u4e2d,\u00a0\u503c\u5374\u5904\u4e8e\u00a01\u00a0\u548c\u8868\u4e2d\u6700\u5927\u00a0customer_id\u00a0\u4e4b\u95f4\u7684id.

\n\n

\u6ce8\u610f:\u00a0\u6700\u5927\u7684\u00a0customer_id\u00a0\u503c\u4e0d\u4f1a\u8d85\u8fc7\u00a0100.

\n\n

\u8fd4\u56de\u7ed3\u679c\u6309\u00a0ids \u5347\u5e8f\u6392\u5217

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a.

\n\n

\u00a0

\n\n
\nCustomers \u8868:\n+-------------+---------------+\n| customer_id | customer_name |\n+-------------+---------------+\n| 1           | Alice         |\n| 4           | Bob           |\n| 5           | Charlie       |\n+-------------+---------------+\n\nResult \u8868:\n+-----+\n| ids |\n+-----+\n| 2   |\n| 3   |\n+-----+\n\u8868\u4e2d\u6700\u5927\u7684customer_id\u662f5, \u6240\u4ee5\u5728\u8303\u56f4[1,5]\u5185, ID2\u548c3\u4ece\u8868\u4e2d\u9057\u5931.
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1613](https://leetcode-cn.com/problems/find-the-missing-ids)", "[\u627e\u5230\u9057\u5931\u7684ID](/solution/1600-1699/1613.Find%20the%20Missing%20IDs/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1613](https://leetcode.com/problems/find-the-missing-ids)", "[Find the Missing IDs](/solution/1600-1699/1613.Find%20the%20Missing%20IDs/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1758", "frontend_question_id": "1655", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/distribute-repeating-integers", "url_en": "https://leetcode.com/problems/distribute-repeating-integers", "relative_path_cn": "/solution/1600-1699/1655.Distribute%20Repeating%20Integers/README.md", "relative_path_en": "/solution/1600-1699/1655.Distribute%20Repeating%20Integers/README_EN.md", "title_cn": "\u5206\u914d\u91cd\u590d\u6574\u6570", "title_en": "Distribute Repeating Integers", "question_title_slug": "distribute-repeating-integers", "content_en": "

You are given an array of n integers, nums, where there are at most 50 unique values in the array. You are also given an array of m customer order quantities, quantity, where quantity[i] is the amount of integers the ith customer ordered. Determine if it is possible to distribute nums such that:

\n\n
    \n\t
  • The ith customer gets exactly quantity[i] integers,
  • \n\t
  • The integers the ith customer gets are all equal, and
  • \n\t
  • Every customer is satisfied.
  • \n
\n\n

Return true if it is possible to distribute nums according to the above conditions.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [1,2,3,4], quantity = [2]\nOutput: false\nExplanation: The 0th customer cannot be given two different integers.\n
\n\n

Example 2:

\n\n
\nInput: nums = [1,2,3,3], quantity = [2]\nOutput: true\nExplanation: The 0th customer is given [3,3]. The integers [1,2] are not used.\n
\n\n

Example 3:

\n\n
\nInput: nums = [1,1,2,2], quantity = [2,2]\nOutput: true\nExplanation: The 0th customer is given [1,1], and the 1st customer is given [2,2].\n
\n\n

Example 4:

\n\n
\nInput: nums = [1,1,2,3], quantity = [2,2]\nOutput: false\nExplanation: Although the 0th customer could be given [1,1], the 1st customer cannot be satisfied.
\n\n

Example 5:

\n\n
\nInput: nums = [1,1,1,1,1], quantity = [2,3]\nOutput: true\nExplanation: The 0th customer is given [1,1], and the 1st customer is given [1,1,1].\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == nums.length
  • \n\t
  • 1 <= n <= 105
  • \n\t
  • 1 <= nums[i] <= 1000
  • \n\t
  • m == quantity.length
  • \n\t
  • 1 <= m <= 10
  • \n\t
  • 1 <= quantity[i] <= 105
  • \n\t
  • There are at most 50 unique values in nums.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u4e3a\u00a0n\u00a0\u7684\u6574\u6570\u6570\u7ec4\u00a0nums\u00a0\uff0c\u8fd9\u4e2a\u6570\u7ec4\u4e2d\u81f3\u591a\u6709\u00a050\u00a0\u4e2a\u4e0d\u540c\u7684\u503c\u3002\u540c\u65f6\u4f60\u6709 m\u00a0\u4e2a\u987e\u5ba2\u7684\u8ba2\u5355 quantity\u00a0\uff0c\u5176\u4e2d\uff0c\u6574\u6570\u00a0quantity[i]\u00a0\u662f\u7b2c\u00a0i\u00a0\u4f4d\u987e\u5ba2\u8ba2\u5355\u7684\u6570\u76ee\u3002\u8bf7\u4f60\u5224\u65ad\u662f\u5426\u80fd\u5c06 nums\u00a0\u4e2d\u7684\u6574\u6570\u5206\u914d\u7ed9\u8fd9\u4e9b\u987e\u5ba2\uff0c\u4e14\u6ee1\u8db3\uff1a

\n\n
    \n\t
  • \u7b2c\u00a0i\u00a0\u4f4d\u987e\u5ba2 \u6070\u597d\u00a0\u6709\u00a0quantity[i]\u00a0\u4e2a\u6574\u6570\u3002
  • \n\t
  • \u7b2c\u00a0i\u00a0\u4f4d\u987e\u5ba2\u62ff\u5230\u7684\u6574\u6570\u90fd\u662f \u76f8\u540c\u7684\u00a0\u3002
  • \n\t
  • \u6bcf\u4f4d\u987e\u5ba2\u90fd\u6ee1\u8db3\u4e0a\u8ff0\u4e24\u4e2a\u8981\u6c42\u3002
  • \n
\n\n

\u5982\u679c\u4f60\u53ef\u4ee5\u5206\u914d nums\u00a0\u4e2d\u7684\u6574\u6570\u6ee1\u8db3\u4e0a\u9762\u7684\u8981\u6c42\uff0c\u90a3\u4e48\u8bf7\u8fd4\u56de\u00a0true\u00a0\uff0c\u5426\u5219\u8fd4\u56de false\u00a0\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,2,3,4], quantity = [2]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u7b2c 0 \u4f4d\u987e\u5ba2\u6ca1\u529e\u6cd5\u5f97\u5230\u4e24\u4e2a\u76f8\u540c\u7684\u6574\u6570\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,2,3,3], quantity = [2]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u7b2c 0 \u4f4d\u987e\u5ba2\u5f97\u5230 [3,3] \u3002\u6574\u6570 [1,2] \u90fd\u6ca1\u6709\u88ab\u4f7f\u7528\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,1,2,2], quantity = [2,2]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u7b2c 0 \u4f4d\u987e\u5ba2\u5f97\u5230 [1,1] \uff0c\u7b2c 1 \u4f4d\u987e\u5ba2\u5f97\u5230 [2,2] \u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,1,2,3], quantity = [2,2]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u5c3d\u7ba1\u7b2c 0 \u4f4d\u987e\u5ba2\u53ef\u4ee5\u5f97\u5230 [1,1] \uff0c\u7b2c 1 \u4f4d\u987e\u5ba2\u6ca1\u6cd5\u5f97\u5230 2 \u4e2a\u4e00\u6837\u7684\u6574\u6570\u3002
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,1,1,1,1], quantity = [2,3]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u7b2c 0 \u4f4d\u987e\u5ba2\u5f97\u5230 [1,1] \uff0c\u7b2c 1 \u4f4d\u987e\u5ba2\u5f97\u5230 [1,1,1] \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • n == nums.length
  • \n\t
  • 1 <= n <= 105
  • \n\t
  • 1 <= nums[i] <= 1000
  • \n\t
  • m == quantity.length
  • \n\t
  • 1 <= m <= 10
  • \n\t
  • 1 <= quantity[i] <= 105
  • \n\t
  • nums\u00a0\u4e2d\u81f3\u591a\u6709\u00a050\u00a0\u4e2a\u4e0d\u540c\u7684\u6570\u5b57\u3002
  • \n
\n", "tags_en": ["Dynamic Programming", "Backtracking"], "tags_cn": ["\u52a8\u6001\u89c4\u5212", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canDistribute(vector& nums, vector& quantity) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canDistribute(int[] nums, int[] quantity) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canDistribute(self, nums, quantity):\n \"\"\"\n :type nums: List[int]\n :type quantity: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canDistribute(self, nums: List[int], quantity: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canDistribute(int* nums, int numsSize, int* quantity, int quantitySize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanDistribute(int[] nums, int[] quantity) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number[]} quantity\n * @return {boolean}\n */\nvar canDistribute = function(nums, quantity) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer[]} quantity\n# @return {Boolean}\ndef can_distribute(nums, quantity)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canDistribute(_ nums: [Int], _ quantity: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canDistribute(nums []int, quantity []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canDistribute(nums: Array[Int], quantity: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canDistribute(nums: IntArray, quantity: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_distribute(nums: Vec, quantity: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer[] $quantity\n * @return Boolean\n */\n function canDistribute($nums, $quantity) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canDistribute(nums: number[], quantity: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-distribute nums quantity)\n (-> (listof exact-integer?) (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1655](https://leetcode-cn.com/problems/distribute-repeating-integers)", "[\u5206\u914d\u91cd\u590d\u6574\u6570](/solution/1600-1699/1655.Distribute%20Repeating%20Integers/README.md)", "`\u52a8\u6001\u89c4\u5212`,`\u56de\u6eaf\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[1655](https://leetcode.com/problems/distribute-repeating-integers)", "[Distribute Repeating Integers](/solution/1600-1699/1655.Distribute%20Repeating%20Integers/README_EN.md)", "`Dynamic Programming`,`Backtracking`", "Hard", ""]}, {"question_id": "1757", "frontend_question_id": "1654", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-jumps-to-reach-home", "url_en": "https://leetcode.com/problems/minimum-jumps-to-reach-home", "relative_path_cn": "/solution/1600-1699/1654.Minimum%20Jumps%20to%20Reach%20Home/README.md", "relative_path_en": "/solution/1600-1699/1654.Minimum%20Jumps%20to%20Reach%20Home/README_EN.md", "title_cn": "\u5230\u5bb6\u7684\u6700\u5c11\u8df3\u8dc3\u6b21\u6570", "title_en": "Minimum Jumps to Reach Home", "question_title_slug": "minimum-jumps-to-reach-home", "content_en": "

A certain bug's home is on the x-axis at position x. Help them get there from position 0.

\n\n

The bug jumps according to the following rules:

\n\n
    \n\t
  • It can jump exactly a positions forward (to the right).
  • \n\t
  • It can jump exactly b positions backward (to the left).
  • \n\t
  • It cannot jump backward twice in a row.
  • \n\t
  • It cannot jump to any forbidden positions.
  • \n
\n\n

The bug may jump forward beyond its home, but it cannot jump to positions numbered with negative integers.

\n\n

Given an array of integers forbidden, where forbidden[i] means that the bug cannot jump to the position forbidden[i], and integers a, b, and x, return the minimum number of jumps needed for the bug to reach its home. If there is no possible sequence of jumps that lands the bug on position x, return -1.

\n\n

 

\n

Example 1:

\n\n
\nInput: forbidden = [14,4,18,1,15], a = 3, b = 15, x = 9\nOutput: 3\nExplanation: 3 jumps forward (0 -> 3 -> 6 -> 9) will get the bug home.\n
\n\n

Example 2:

\n\n
\nInput: forbidden = [8,3,16,6,12,20], a = 15, b = 13, x = 11\nOutput: -1\n
\n\n

Example 3:

\n\n
\nInput: forbidden = [1,6,2,14,5,17,4], a = 16, b = 9, x = 7\nOutput: 2\nExplanation: One jump forward (0 -> 16) then one jump backward (16 -> 7) will get the bug home.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= forbidden.length <= 1000
  • \n\t
  • 1 <= a, b, forbidden[i] <= 2000
  • \n\t
  • 0 <= x <= 2000
  • \n\t
  • All the elements in forbidden are distinct.
  • \n\t
  • Position x is not forbidden.
  • \n
\n", "content_cn": "

\u6709\u4e00\u53ea\u8df3\u86a4\u7684\u5bb6\u5728\u6570\u8f74\u4e0a\u7684\u4f4d\u7f6e\u00a0x\u00a0\u5904\u3002\u8bf7\u4f60\u5e2e\u52a9\u5b83\u4ece\u4f4d\u7f6e\u00a00\u00a0\u51fa\u53d1\uff0c\u5230\u8fbe\u5b83\u7684\u5bb6\u3002

\n\n

\u8df3\u86a4\u8df3\u8dc3\u7684\u89c4\u5219\u5982\u4e0b\uff1a

\n\n
    \n\t
  • \u5b83\u53ef\u4ee5 \u5f80\u524d \u8df3\u6070\u597d a\u00a0\u4e2a\u4f4d\u7f6e\uff08\u5373\u5f80\u53f3\u8df3\uff09\u3002
  • \n\t
  • \u5b83\u53ef\u4ee5 \u5f80\u540e\u00a0\u8df3\u6070\u597d b\u00a0\u4e2a\u4f4d\u7f6e\uff08\u5373\u5f80\u5de6\u8df3\uff09\u3002
  • \n\t
  • \u5b83\u4e0d\u80fd \u8fde\u7eed \u5f80\u540e\u8df3 2 \u6b21\u3002
  • \n\t
  • \u5b83\u4e0d\u80fd\u8df3\u5230\u4efb\u4f55\u00a0forbidden\u00a0\u6570\u7ec4\u4e2d\u7684\u4f4d\u7f6e\u3002
  • \n
\n\n

\u8df3\u86a4\u53ef\u4ee5\u5f80\u524d\u8df3 \u8d85\u8fc7\u00a0\u5b83\u7684\u5bb6\u7684\u4f4d\u7f6e\uff0c\u4f46\u662f\u5b83 \u4e0d\u80fd\u8df3\u5230\u8d1f\u6574\u6570\u00a0\u7684\u4f4d\u7f6e\u3002

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0forbidden\u00a0\uff0c\u5176\u4e2d\u00a0forbidden[i]\u00a0\u662f\u8df3\u86a4\u4e0d\u80fd\u8df3\u5230\u7684\u4f4d\u7f6e\uff0c\u540c\u65f6\u7ed9\u4f60\u6574\u6570\u00a0a\uff0c\u00a0b\u00a0\u548c\u00a0x\u00a0\uff0c\u8bf7\u4f60\u8fd4\u56de\u8df3\u86a4\u5230\u5bb6\u7684\u6700\u5c11\u8df3\u8dc3\u6b21\u6570\u3002\u5982\u679c\u6ca1\u6709\u6070\u597d\u5230\u8fbe x\u00a0\u7684\u53ef\u884c\u65b9\u6848\uff0c\u8bf7\u4f60\u8fd4\u56de -1 \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aforbidden = [14,4,18,1,15], a = 3, b = 15, x = 9\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u5f80\u524d\u8df3 3 \u6b21\uff080 -> 3 -> 6 -> 9\uff09\uff0c\u8df3\u86a4\u5c31\u5230\u5bb6\u4e86\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aforbidden = [8,3,16,6,12,20], a = 15, b = 13, x = 11\n\u8f93\u51fa\uff1a-1\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1aforbidden = [1,6,2,14,5,17,4], a = 16, b = 9, x = 7\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5f80\u524d\u8df3\u4e00\u6b21\uff080 -> 16\uff09\uff0c\u7136\u540e\u5f80\u56de\u8df3\u4e00\u6b21\uff0816 -> 7\uff09\uff0c\u8df3\u86a4\u5c31\u5230\u5bb6\u4e86\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= forbidden.length <= 1000
  • \n\t
  • 1 <= a, b, forbidden[i] <= 2000
  • \n\t
  • 0 <= x <= 2000
  • \n\t
  • forbidden\u00a0\u4e2d\u6240\u6709\u4f4d\u7f6e\u4e92\u4e0d\u76f8\u540c\u3002
  • \n\t
  • \u4f4d\u7f6e\u00a0x\u00a0\u4e0d\u5728 forbidden\u00a0\u4e2d\u3002
  • \n
\n", "tags_en": ["Breadth-first Search", "Dynamic Programming"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minimumJumps(vector& forbidden, int a, int b, int x) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minimumJumps(int[] forbidden, int a, int b, int x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimumJumps(self, forbidden, a, b, x):\n \"\"\"\n :type forbidden: List[int]\n :type a: int\n :type b: int\n :type x: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimumJumps(self, forbidden: List[int], a: int, b: int, x: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minimumJumps(int* forbidden, int forbiddenSize, int a, int b, int x){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinimumJumps(int[] forbidden, int a, int b, int x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} forbidden\n * @param {number} a\n * @param {number} b\n * @param {number} x\n * @return {number}\n */\nvar minimumJumps = function(forbidden, a, b, x) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} forbidden\n# @param {Integer} a\n# @param {Integer} b\n# @param {Integer} x\n# @return {Integer}\ndef minimum_jumps(forbidden, a, b, x)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimumJumps(_ forbidden: [Int], _ a: Int, _ b: Int, _ x: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimumJumps(forbidden []int, a int, b int, x int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimumJumps(forbidden: Array[Int], a: Int, b: Int, x: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimumJumps(forbidden: IntArray, a: Int, b: Int, x: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimum_jumps(forbidden: Vec, a: i32, b: i32, x: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $forbidden\n * @param Integer $a\n * @param Integer $b\n * @param Integer $x\n * @return Integer\n */\n function minimumJumps($forbidden, $a, $b, $x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimumJumps(forbidden: number[], a: number, b: number, x: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimum-jumps forbidden a b x)\n (-> (listof exact-integer?) exact-integer? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1654](https://leetcode-cn.com/problems/minimum-jumps-to-reach-home)", "[\u5230\u5bb6\u7684\u6700\u5c11\u8df3\u8dc3\u6b21\u6570](/solution/1600-1699/1654.Minimum%20Jumps%20to%20Reach%20Home/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1654](https://leetcode.com/problems/minimum-jumps-to-reach-home)", "[Minimum Jumps to Reach Home](/solution/1600-1699/1654.Minimum%20Jumps%20to%20Reach%20Home/README_EN.md)", "`Breadth-first Search`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "1756", "frontend_question_id": "1653", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-deletions-to-make-string-balanced", "url_en": "https://leetcode.com/problems/minimum-deletions-to-make-string-balanced", "relative_path_cn": "/solution/1600-1699/1653.Minimum%20Deletions%20to%20Make%20String%20Balanced/README.md", "relative_path_en": "/solution/1600-1699/1653.Minimum%20Deletions%20to%20Make%20String%20Balanced/README_EN.md", "title_cn": "\u4f7f\u5b57\u7b26\u4e32\u5e73\u8861\u7684\u6700\u5c11\u5220\u9664\u6b21\u6570", "title_en": "Minimum Deletions to Make String Balanced", "question_title_slug": "minimum-deletions-to-make-string-balanced", "content_en": "

You are given a string s consisting only of characters 'a' and 'b'\u200b\u200b\u200b\u200b.

\n\n

You can delete any number of characters in s to make s balanced. s is balanced if there is no pair of indices (i,j) such that i < j and s[i] = 'b' and s[j]= 'a'.

\n\n

Return the minimum number of deletions needed to make s balanced.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "aababbab"\nOutput: 2\nExplanation: You can either:\nDelete the characters at 0-indexed positions 2 and 6 ("aababbab" -> "aaabbb"), or\nDelete the characters at 0-indexed positions 3 and 6 ("aababbab" -> "aabbbb").\n
\n\n

Example 2:

\n\n
\nInput: s = "bbaaaaabb"\nOutput: 2\nExplanation: The only solution is to delete the first two characters.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 105
  • \n\t
  • s[i] is 'a' or 'b'\u200b\u200b.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32\u00a0s\u00a0\uff0c\u5b83\u4ec5\u5305\u542b\u5b57\u7b26\u00a0'a' \u548c\u00a0'b'\u200b\u200b\u200b\u200b \u3002

\n\n

\u4f60\u53ef\u4ee5\u5220\u9664\u00a0s\u00a0\u4e2d\u4efb\u610f\u6570\u76ee\u7684\u5b57\u7b26\uff0c\u4f7f\u5f97\u00a0s \u5e73\u8861\u00a0\u3002\u6211\u4eec\u79f0\u00a0s\u00a0\u5e73\u8861\u7684\u00a0\u5f53\u4e0d\u5b58\u5728\u4e0b\u6807\u5bf9\u00a0(i,j)\u00a0\u6ee1\u8db3\u00a0i < j \u4e14\u00a0s[i] = 'b'\u00a0\u540c\u65f6\u00a0s[j]= 'a'\u00a0\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u4f7f s\u00a0\u5e73\u8861\u00a0\u7684 \u6700\u5c11\u00a0\u5220\u9664\u6b21\u6570\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"aababbab\"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u9009\u62e9\u4ee5\u4e0b\u4efb\u610f\u4e00\u79cd\u65b9\u6848\uff1a\n\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff0c\u5220\u9664\u7b2c 2 \u548c\u7b2c 6 \u4e2a\u5b57\u7b26\uff08\"aababbab\" -> \"aaabbb\"\uff09\uff0c\n\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff0c\u5220\u9664\u7b2c 3 \u548c\u7b2c 6 \u4e2a\u5b57\u7b26\uff08\"aababbab\" -> \"aabbbb\"\uff09\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"bbaaaaabb\"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u552f\u4e00\u7684\u6700\u4f18\u89e3\u662f\u5220\u9664\u6700\u524d\u9762\u4e24\u4e2a\u5b57\u7b26\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length <= 105
  • \n\t
  • s[i]\u00a0\u8981\u4e48\u662f\u00a0'a' \u8981\u4e48\u662f\u00a0'b'\u200b\u00a0\u3002\u200b
  • \n
\n", "tags_en": ["Greedy", "String"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minimumDeletions(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minimumDeletions(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimumDeletions(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimumDeletions(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minimumDeletions(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinimumDeletions(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar minimumDeletions = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef minimum_deletions(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimumDeletions(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimumDeletions(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimumDeletions(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimumDeletions(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimum_deletions(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function minimumDeletions($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimumDeletions(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimum-deletions s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1653](https://leetcode-cn.com/problems/minimum-deletions-to-make-string-balanced)", "[\u4f7f\u5b57\u7b26\u4e32\u5e73\u8861\u7684\u6700\u5c11\u5220\u9664\u6b21\u6570](/solution/1600-1699/1653.Minimum%20Deletions%20to%20Make%20String%20Balanced/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1653](https://leetcode.com/problems/minimum-deletions-to-make-string-balanced)", "[Minimum Deletions to Make String Balanced](/solution/1600-1699/1653.Minimum%20Deletions%20to%20Make%20String%20Balanced/README_EN.md)", "`Greedy`,`String`", "Medium", ""]}, {"question_id": "1755", "frontend_question_id": "1652", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/defuse-the-bomb", "url_en": "https://leetcode.com/problems/defuse-the-bomb", "relative_path_cn": "/solution/1600-1699/1652.Defuse%20the%20Bomb/README.md", "relative_path_en": "/solution/1600-1699/1652.Defuse%20the%20Bomb/README_EN.md", "title_cn": "\u62c6\u70b8\u5f39", "title_en": "Defuse the Bomb", "question_title_slug": "defuse-the-bomb", "content_en": "

You have a bomb to defuse, and your time is running out! Your informer will provide you with a circular array code of length of n and a key k.

\n\n

To decrypt the code, you must replace every number. All the numbers are replaced simultaneously.

\n\n
    \n\t
  • If k > 0, replace the ith number with the sum of the next k numbers.
  • \n\t
  • If k < 0, replace the ith number with the sum of the previous k numbers.
  • \n\t
  • If k == 0, replace the ith number with 0.
  • \n
\n\n

As code is circular, the next element of code[n-1] is code[0], and the previous element of code[0] is code[n-1].

\n\n

Given the circular array code and an integer key k, return the decrypted code to defuse the bomb!

\n\n

 

\n

Example 1:

\n\n
\nInput: code = [5,7,1,4], k = 3\nOutput: [12,10,16,13]\nExplanation: Each number is replaced by the sum of the next 3 numbers. The decrypted code is [7+1+4, 1+4+5, 4+5+7, 5+7+1]. Notice that the numbers wrap around.\n
\n\n

Example 2:

\n\n
\nInput: code = [1,2,3,4], k = 0\nOutput: [0,0,0,0]\nExplanation: When k is zero, the numbers are replaced by 0. \n
\n\n

Example 3:

\n\n
\nInput: code = [2,4,9,3], k = -2\nOutput: [12,5,6,13]\nExplanation: The decrypted code is [3+9, 2+3, 4+2, 9+4]. Notice that the numbers wrap around again. If k is negative, the sum is of the previous numbers.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == code.length
  • \n\t
  • 1 <= n <= 100
  • \n\t
  • 1 <= code[i] <= 100
  • \n\t
  • -(n - 1) <= k <= n - 1
  • \n
\n", "content_cn": "

\u4f60\u6709\u4e00\u4e2a\u70b8\u5f39\u9700\u8981\u62c6\u9664\uff0c\u65f6\u95f4\u7d27\u8feb\uff01\u4f60\u7684\u60c5\u62a5\u5458\u4f1a\u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u4e3a\u00a0n\u00a0\u7684\u00a0\u5faa\u73af\u00a0\u6570\u7ec4\u00a0code\u00a0\u4ee5\u53ca\u4e00\u4e2a\u5bc6\u94a5\u00a0k\u00a0\u3002

\n\n

\u4e3a\u4e86\u83b7\u5f97\u6b63\u786e\u7684\u5bc6\u7801\uff0c\u4f60\u9700\u8981\u66ff\u6362\u6389\u6bcf\u4e00\u4e2a\u6570\u5b57\u3002\u6240\u6709\u6570\u5b57\u4f1a\u00a0\u540c\u65f6\u00a0\u88ab\u66ff\u6362\u3002

\n\n
    \n\t
  • \u5982\u679c\u00a0k > 0\u00a0\uff0c\u5c06\u7b2c\u00a0i\u00a0\u4e2a\u6570\u5b57\u7528 \u63a5\u4e0b\u6765\u00a0k\u00a0\u4e2a\u6570\u5b57\u4e4b\u548c\u66ff\u6362\u3002
  • \n\t
  • \u5982\u679c\u00a0k < 0\u00a0\uff0c\u5c06\u7b2c\u00a0i\u00a0\u4e2a\u6570\u5b57\u7528 \u4e4b\u524d\u00a0k\u00a0\u4e2a\u6570\u5b57\u4e4b\u548c\u66ff\u6362\u3002
  • \n\t
  • \u5982\u679c\u00a0k == 0\u00a0\uff0c\u5c06\u7b2c\u00a0i\u00a0\u4e2a\u6570\u5b57\u7528\u00a00\u00a0\u66ff\u6362\u3002
  • \n
\n\n

\u7531\u4e8e\u00a0code\u00a0\u662f\u5faa\u73af\u7684\uff0c\u00a0code[n-1]\u00a0\u4e0b\u4e00\u4e2a\u5143\u7d20\u662f\u00a0code[0]\u00a0\uff0c\u4e14\u00a0code[0]\u00a0\u524d\u4e00\u4e2a\u5143\u7d20\u662f\u00a0code[n-1]\u00a0\u3002

\n\n

\u7ed9\u4f60 \u5faa\u73af\u00a0\u6570\u7ec4\u00a0code\u00a0\u548c\u6574\u6570\u5bc6\u94a5\u00a0k\u00a0\uff0c\u8bf7\u4f60\u8fd4\u56de\u89e3\u5bc6\u540e\u7684\u7ed3\u679c\u6765\u62c6\u9664\u70b8\u5f39\uff01

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1acode = [5,7,1,4], k = 3\n\u8f93\u51fa\uff1a[12,10,16,13]\n\u89e3\u91ca\uff1a\u6bcf\u4e2a\u6570\u5b57\u90fd\u88ab\u63a5\u4e0b\u6765 3 \u4e2a\u6570\u5b57\u4e4b\u548c\u66ff\u6362\u3002\u89e3\u5bc6\u540e\u7684\u5bc6\u7801\u4e3a [7+1+4, 1+4+5, 4+5+7, 5+7+1]\u3002\u6ce8\u610f\u5230\u6570\u7ec4\u662f\u5faa\u73af\u8fde\u63a5\u7684\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1acode = [1,2,3,4], k = 0\n\u8f93\u51fa\uff1a[0,0,0,0]\n\u89e3\u91ca\uff1a\u5f53 k \u4e3a 0 \u65f6\uff0c\u6240\u6709\u6570\u5b57\u90fd\u88ab 0 \u66ff\u6362\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1acode = [2,4,9,3], k = -2\n\u8f93\u51fa\uff1a[12,5,6,13]\n\u89e3\u91ca\uff1a\u89e3\u5bc6\u540e\u7684\u5bc6\u7801\u4e3a [3+9, 2+3, 4+2, 9+4] \u3002\u6ce8\u610f\u5230\u6570\u7ec4\u662f\u5faa\u73af\u8fde\u63a5\u7684\u3002\u5982\u679c k \u662f\u8d1f\u6570\uff0c\u90a3\u4e48\u548c\u4e3a \u4e4b\u524d \u7684\u6570\u5b57\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • n == code.length
  • \n\t
  • 1 <= n\u00a0<= 100
  • \n\t
  • 1 <= code[i] <= 100
  • \n\t
  • -(n - 1) <= k <= n - 1
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector decrypt(vector& code, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] decrypt(int[] code, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def decrypt(self, code, k):\n \"\"\"\n :type code: List[int]\n :type k: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def decrypt(self, code: List[int], k: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* decrypt(int* code, int codeSize, int k, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] Decrypt(int[] code, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} code\n * @param {number} k\n * @return {number[]}\n */\nvar decrypt = function(code, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} code\n# @param {Integer} k\n# @return {Integer[]}\ndef decrypt(code, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func decrypt(_ code: [Int], _ k: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func decrypt(code []int, k int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def decrypt(code: Array[Int], k: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun decrypt(code: IntArray, k: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn decrypt(code: Vec, k: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $code\n * @param Integer $k\n * @return Integer[]\n */\n function decrypt($code, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function decrypt(code: number[], k: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (decrypt code k)\n (-> (listof exact-integer?) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1652](https://leetcode-cn.com/problems/defuse-the-bomb)", "[\u62c6\u70b8\u5f39](/solution/1600-1699/1652.Defuse%20the%20Bomb/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1652](https://leetcode.com/problems/defuse-the-bomb)", "[Defuse the Bomb](/solution/1600-1699/1652.Defuse%20the%20Bomb/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1753", "frontend_question_id": "1631", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/path-with-minimum-effort", "url_en": "https://leetcode.com/problems/path-with-minimum-effort", "relative_path_cn": "/solution/1600-1699/1631.Path%20With%20Minimum%20Effort/README.md", "relative_path_en": "/solution/1600-1699/1631.Path%20With%20Minimum%20Effort/README_EN.md", "title_cn": "\u6700\u5c0f\u4f53\u529b\u6d88\u8017\u8def\u5f84", "title_en": "Path With Minimum Effort", "question_title_slug": "path-with-minimum-effort", "content_en": "

You are a hiker preparing for an upcoming hike. You are given heights, a 2D array of size rows x columns, where heights[row][col] represents the height of cell (row, col). You are situated in the top-left cell, (0, 0), and you hope to travel to the bottom-right cell, (rows-1, columns-1) (i.e., 0-indexed). You can move up, down, left, or right, and you wish to find a route that requires the minimum effort.

\n\n

A route's effort is the maximum absolute difference in heights between two consecutive cells of the route.

\n\n

Return the minimum effort required to travel from the top-left cell to the bottom-right cell.

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: heights = [[1,2,2],[3,8,2],[5,3,5]]\nOutput: 2\nExplanation: The route of [1,3,5,3,5] has a maximum absolute difference of 2 in consecutive cells.\nThis is better than the route of [1,2,2,2,5], where the maximum absolute difference is 3.\n
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: heights = [[1,2,3],[3,8,4],[5,3,5]]\nOutput: 1\nExplanation: The route of [1,2,3,4,5] has a maximum absolute difference of 1 in consecutive cells, which is better than route [1,3,5,3,5].\n
\n\n

Example 3:

\n\"\"\n
\nInput: heights = [[1,2,1,1,1],[1,2,1,2,1],[1,2,1,2,1],[1,2,1,2,1],[1,1,1,2,1]]\nOutput: 0\nExplanation: This route does not require any effort.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • rows == heights.length
  • \n\t
  • columns == heights[i].length
  • \n\t
  • 1 <= rows, columns <= 100
  • \n\t
  • 1 <= heights[i][j] <= 106
  • \n
\n", "content_cn": "

\u4f60\u51c6\u5907\u53c2\u52a0\u4e00\u573a\u8fdc\u8db3\u6d3b\u52a8\u3002\u7ed9\u4f60\u4e00\u4e2a\u4e8c\u7ef4\u00a0rows x columns\u00a0\u7684\u5730\u56fe\u00a0heights\u00a0\uff0c\u5176\u4e2d\u00a0heights[row][col]\u00a0\u8868\u793a\u683c\u5b50\u00a0(row, col)\u00a0\u7684\u9ad8\u5ea6\u3002\u4e00\u5f00\u59cb\u4f60\u5728\u6700\u5de6\u4e0a\u89d2\u7684\u683c\u5b50\u00a0(0, 0)\u00a0\uff0c\u4e14\u4f60\u5e0c\u671b\u53bb\u6700\u53f3\u4e0b\u89d2\u7684\u683c\u5b50\u00a0(rows-1, columns-1)\u00a0\uff08\u6ce8\u610f\u4e0b\u6807\u4ece 0 \u5f00\u59cb\u7f16\u53f7\uff09\u3002\u4f60\u6bcf\u6b21\u53ef\u4ee5\u5f80 \u4e0a\uff0c\u4e0b\uff0c\u5de6\uff0c\u53f3\u00a0\u56db\u4e2a\u65b9\u5411\u4e4b\u4e00\u79fb\u52a8\uff0c\u4f60\u60f3\u8981\u627e\u5230\u8017\u8d39 \u4f53\u529b \u6700\u5c0f\u7684\u4e00\u6761\u8def\u5f84\u3002

\n\n

\u4e00\u6761\u8def\u5f84\u8017\u8d39\u7684 \u4f53\u529b\u503c\u00a0\u662f\u8def\u5f84\u4e0a\u76f8\u90bb\u683c\u5b50\u4e4b\u95f4 \u9ad8\u5ea6\u5dee\u7edd\u5bf9\u503c\u00a0\u7684 \u6700\u5927\u503c\u00a0\u51b3\u5b9a\u7684\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u4ece\u5de6\u4e0a\u89d2\u8d70\u5230\u53f3\u4e0b\u89d2\u7684\u6700\u5c0f\u00a0\u4f53\u529b\u6d88\u8017\u503c\u00a0\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1aheights = [[1,2,2],[3,8,2],[5,3,5]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u8def\u5f84 [1,3,5,3,5] \u8fde\u7eed\u683c\u5b50\u7684\u5dee\u503c\u7edd\u5bf9\u503c\u6700\u5927\u4e3a 2 \u3002\n\u8fd9\u6761\u8def\u5f84\u6bd4\u8def\u5f84 [1,2,2,2,5] \u66f4\u4f18\uff0c\u56e0\u4e3a\u53e6\u4e00\u6761\u8def\u5f84\u5dee\u503c\u6700\u5927\u503c\u4e3a 3 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1aheights = [[1,2,3],[3,8,4],[5,3,5]]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u8def\u5f84 [1,2,3,4,5] \u7684\u76f8\u90bb\u683c\u5b50\u5dee\u503c\u7edd\u5bf9\u503c\u6700\u5927\u4e3a 1 \uff0c\u6bd4\u8def\u5f84 [1,3,5,3,5] \u66f4\u4f18\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1aheights = [[1,2,1,1,1],[1,2,1,2,1],[1,2,1,2,1],[1,2,1,2,1],[1,1,1,2,1]]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u4e0a\u56fe\u6240\u793a\u8def\u5f84\u4e0d\u9700\u8981\u6d88\u8017\u4efb\u4f55\u4f53\u529b\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • rows == heights.length
  • \n\t
  • columns == heights[i].length
  • \n\t
  • 1 <= rows, columns <= 100
  • \n\t
  • 1 <= heights[i][j] <= 106
  • \n
\n", "tags_en": ["Depth-first Search", "Union Find", "Graph", "Binary Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e76\u67e5\u96c6", "\u56fe", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minimumEffortPath(vector>& heights) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minimumEffortPath(int[][] heights) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimumEffortPath(self, heights):\n \"\"\"\n :type heights: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimumEffortPath(self, heights: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minimumEffortPath(int** heights, int heightsSize, int* heightsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinimumEffortPath(int[][] heights) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} heights\n * @return {number}\n */\nvar minimumEffortPath = function(heights) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} heights\n# @return {Integer}\ndef minimum_effort_path(heights)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimumEffortPath(_ heights: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimumEffortPath(heights [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimumEffortPath(heights: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimumEffortPath(heights: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimum_effort_path(heights: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $heights\n * @return Integer\n */\n function minimumEffortPath($heights) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimumEffortPath(heights: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimum-effort-path heights)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1631](https://leetcode-cn.com/problems/path-with-minimum-effort)", "[\u6700\u5c0f\u4f53\u529b\u6d88\u8017\u8def\u5f84](/solution/1600-1699/1631.Path%20With%20Minimum%20Effort/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e76\u67e5\u96c6`,`\u56fe`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1631](https://leetcode.com/problems/path-with-minimum-effort)", "[Path With Minimum Effort](/solution/1600-1699/1631.Path%20With%20Minimum%20Effort/README_EN.md)", "`Depth-first Search`,`Union Find`,`Graph`,`Binary Search`", "Medium", ""]}, {"question_id": "1752", "frontend_question_id": "1630", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/arithmetic-subarrays", "url_en": "https://leetcode.com/problems/arithmetic-subarrays", "relative_path_cn": "/solution/1600-1699/1630.Arithmetic%20Subarrays/README.md", "relative_path_en": "/solution/1600-1699/1630.Arithmetic%20Subarrays/README_EN.md", "title_cn": "\u7b49\u5dee\u5b50\u6570\u7ec4", "title_en": "Arithmetic Subarrays", "question_title_slug": "arithmetic-subarrays", "content_en": "

A sequence of numbers is called arithmetic if it consists of at least two elements, and the difference between every two consecutive elements is the same. More formally, a sequence s is arithmetic if and only if s[i+1] - s[i] == s[1] - s[0] for all valid i.

\n\n

For example, these are arithmetic sequences:

\n\n
\n1, 3, 5, 7, 9\n7, 7, 7, 7\n3, -1, -5, -9
\n\n

The following sequence is not arithmetic:

\n\n
\n1, 1, 2, 5, 7
\n\n

You are given an array of n integers, nums, and two arrays of m integers each, l and r, representing the m range queries, where the ith query is the range [l[i], r[i]]. All the arrays are 0-indexed.

\n\n

Return a list of boolean elements answer, where answer[i] is true if the subarray nums[l[i]], nums[l[i]+1], ... , nums[r[i]] can be rearranged to form an arithmetic sequence, and false otherwise.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [4,6,5,9,3,7], l = [0,0,2], r = [2,3,5]\nOutput: [true,false,true]\nExplanation:\nIn the 0th query, the subarray is [4,6,5]. This can be rearranged as [6,5,4], which is an arithmetic sequence.\nIn the 1st query, the subarray is [4,6,5,9]. This cannot be rearranged as an arithmetic sequence.\nIn the 2nd query, the subarray is [5,9,3,7]. This can be rearranged as [3,5,7,9], which is an arithmetic sequence.
\n\n

Example 2:

\n\n
\nInput: nums = [-12,-9,-3,-12,-6,15,20,-25,-20,-15,-10], l = [0,1,6,4,8,7], r = [4,4,9,7,9,10]\nOutput: [false,true,false,false,true,true]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == nums.length
  • \n\t
  • m == l.length
  • \n\t
  • m == r.length
  • \n\t
  • 2 <= n <= 500
  • \n\t
  • 1 <= m <= 500
  • \n\t
  • 0 <= l[i] < r[i] < n
  • \n\t
  • -105 <= nums[i] <= 105
  • \n
\n", "content_cn": "

\u5982\u679c\u4e00\u4e2a\u6570\u5217\u7531\u81f3\u5c11\u4e24\u4e2a\u5143\u7d20\u7ec4\u6210\uff0c\u4e14\u6bcf\u4e24\u4e2a\u8fde\u7eed\u5143\u7d20\u4e4b\u95f4\u7684\u5dee\u503c\u90fd\u76f8\u540c\uff0c\u90a3\u4e48\u8fd9\u4e2a\u5e8f\u5217\u5c31\u662f \u7b49\u5dee\u6570\u5217 \u3002\u66f4\u6b63\u5f0f\u5730\uff0c\u6570\u5217 s \u662f\u7b49\u5dee\u6570\u5217\uff0c\u53ea\u9700\u8981\u6ee1\u8db3\uff1a\u5bf9\u4e8e\u6bcf\u4e2a\u6709\u6548\u7684 i \uff0c s[i+1] - s[i] == s[1] - s[0] \u90fd\u6210\u7acb\u3002

\n\n

\u4f8b\u5982\uff0c\u4e0b\u9762\u8fd9\u4e9b\u90fd\u662f \u7b49\u5dee\u6570\u5217 \uff1a

\n\n
1, 3, 5, 7, 9\n7, 7, 7, 7\n3, -1, -5, -9
\n\n

\u4e0b\u9762\u7684\u6570\u5217 \u4e0d\u662f\u7b49\u5dee\u6570\u5217 \uff1a

\n\n
1, 1, 2, 5, 7
\n\n

\u7ed9\u4f60\u4e00\u4e2a\u7531 n \u4e2a\u6574\u6570\u7ec4\u6210\u7684\u6570\u7ec4 nums\uff0c\u548c\u4e24\u4e2a\u7531 m \u4e2a\u6574\u6570\u7ec4\u6210\u7684\u6570\u7ec4 l \u548c r\uff0c\u540e\u4e24\u4e2a\u6570\u7ec4\u8868\u793a m \u7ec4\u8303\u56f4\u67e5\u8be2\uff0c\u5176\u4e2d\u7b2c i \u4e2a\u67e5\u8be2\u5bf9\u5e94\u8303\u56f4 [l[i], r[i]] \u3002\u6240\u6709\u6570\u7ec4\u7684\u4e0b\u6807\u90fd\u662f \u4ece 0 \u5f00\u59cb \u7684\u3002

\n\n

\u8fd4\u56de boolean \u5143\u7d20\u6784\u6210\u7684\u7b54\u6848\u5217\u8868 answer \u3002\u5982\u679c\u5b50\u6570\u7ec4 nums[l[i]], nums[l[i]+1], ... , nums[r[i]] \u53ef\u4ee5 \u91cd\u65b0\u6392\u5217 \u5f62\u6210 \u7b49\u5dee\u6570\u5217 \uff0canswer[i] \u7684\u503c\u5c31\u662f true\uff1b\u5426\u5219answer[i] \u7684\u503c\u5c31\u662f false \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anums = [4,6,5,9,3,7], l = [0,0,2], r = [2,3,5]\n\u8f93\u51fa\uff1a[true,false,true]\n\u89e3\u91ca\uff1a\n\u7b2c 0 \u4e2a\u67e5\u8be2\uff0c\u5bf9\u5e94\u5b50\u6570\u7ec4 [4,6,5] \u3002\u53ef\u4ee5\u91cd\u65b0\u6392\u5217\u4e3a\u7b49\u5dee\u6570\u5217 [6,5,4] \u3002\n\u7b2c 1 \u4e2a\u67e5\u8be2\uff0c\u5bf9\u5e94\u5b50\u6570\u7ec4 [4,6,5,9] \u3002\u65e0\u6cd5\u91cd\u65b0\u6392\u5217\u5f62\u6210\u7b49\u5dee\u6570\u5217\u3002\n\u7b2c 2 \u4e2a\u67e5\u8be2\uff0c\u5bf9\u5e94\u5b50\u6570\u7ec4 [5,9,3,7] \u3002\u53ef\u4ee5\u91cd\u65b0\u6392\u5217\u4e3a\u7b49\u5dee\u6570\u5217 [3,5,7,9] \u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anums = [-12,-9,-3,-12,-6,15,20,-25,-20,-15,-10], l = [0,1,6,4,8,7], r = [4,4,9,7,9,10]\n\u8f93\u51fa\uff1a[false,true,false,false,true,true]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • n == nums.length
  • \n\t
  • m == l.length
  • \n\t
  • m == r.length
  • \n\t
  • 2 <= n <= 500
  • \n\t
  • 1 <= m <= 500
  • \n\t
  • 0 <= l[i] < r[i] < n
  • \n\t
  • -105 <= nums[i] <= 105
  • \n
\n", "tags_en": ["Sort"], "tags_cn": ["\u6392\u5e8f"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector checkArithmeticSubarrays(vector& nums, vector& l, vector& r) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List checkArithmeticSubarrays(int[] nums, int[] l, int[] r) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def checkArithmeticSubarrays(self, nums, l, r):\n \"\"\"\n :type nums: List[int]\n :type l: List[int]\n :type r: List[int]\n :rtype: List[bool]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def checkArithmeticSubarrays(self, nums: List[int], l: List[int], r: List[int]) -> List[bool]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nbool* checkArithmeticSubarrays(int* nums, int numsSize, int* l, int lSize, int* r, int rSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList CheckArithmeticSubarrays(int[] nums, int[] l, int[] r) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number[]} l\n * @param {number[]} r\n * @return {boolean[]}\n */\nvar checkArithmeticSubarrays = function(nums, l, r) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer[]} l\n# @param {Integer[]} r\n# @return {Boolean[]}\ndef check_arithmetic_subarrays(nums, l, r)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func checkArithmeticSubarrays(_ nums: [Int], _ l: [Int], _ r: [Int]) -> [Bool] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func checkArithmeticSubarrays(nums []int, l []int, r []int) []bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def checkArithmeticSubarrays(nums: Array[Int], l: Array[Int], r: Array[Int]): List[Boolean] = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun checkArithmeticSubarrays(nums: IntArray, l: IntArray, r: IntArray): List {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn check_arithmetic_subarrays(nums: Vec, l: Vec, r: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer[] $l\n * @param Integer[] $r\n * @return Boolean[]\n */\n function checkArithmeticSubarrays($nums, $l, $r) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function checkArithmeticSubarrays(nums: number[], l: number[], r: number[]): boolean[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (check-arithmetic-subarrays nums l r)\n (-> (listof exact-integer?) (listof exact-integer?) (listof exact-integer?) (listof boolean?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1630](https://leetcode-cn.com/problems/arithmetic-subarrays)", "[\u7b49\u5dee\u5b50\u6570\u7ec4](/solution/1600-1699/1630.Arithmetic%20Subarrays/README.md)", "`\u6392\u5e8f`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1630](https://leetcode.com/problems/arithmetic-subarrays)", "[Arithmetic Subarrays](/solution/1600-1699/1630.Arithmetic%20Subarrays/README_EN.md)", "`Sort`", "Medium", ""]}, {"question_id": "1751", "frontend_question_id": "1629", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/slowest-key", "url_en": "https://leetcode.com/problems/slowest-key", "relative_path_cn": "/solution/1600-1699/1629.Slowest%20Key/README.md", "relative_path_en": "/solution/1600-1699/1629.Slowest%20Key/README_EN.md", "title_cn": "\u6309\u952e\u6301\u7eed\u65f6\u95f4\u6700\u957f\u7684\u952e", "title_en": "Slowest Key", "question_title_slug": "slowest-key", "content_en": "

A newly designed keypad was tested, where a tester pressed a sequence of n keys, one at a time.

\n\n

You are given a string keysPressed of length n, where keysPressed[i] was the ith key pressed in the testing sequence, and a sorted list releaseTimes, where releaseTimes[i] was the time the ith key was released. Both arrays are 0-indexed. The 0th key was pressed at the time 0, and every subsequent key was pressed at the exact time the previous key was released.

\n\n

The tester wants to know the key of the keypress that had the longest duration. The ith keypress had a duration of releaseTimes[i] - releaseTimes[i - 1], and the 0th keypress had a duration of releaseTimes[0].

\n\n

Note that the same key could have been pressed multiple times during the test, and these multiple presses of the same key may not have had the same duration.

\n\n

Return the key of the keypress that had the longest duration. If there are multiple such keypresses, return the lexicographically largest key of the keypresses.

\n\n

 

\n

Example 1:

\n\n
\nInput: releaseTimes = [9,29,49,50], keysPressed = "cbcd"\nOutput: "c"\nExplanation: The keypresses were as follows:\nKeypress for 'c' had a duration of 9 (pressed at time 0 and released at time 9).\nKeypress for 'b' had a duration of 29 - 9 = 20 (pressed at time 9 right after the release of the previous character and released at time 29).\nKeypress for 'c' had a duration of 49 - 29 = 20 (pressed at time 29 right after the release of the previous character and released at time 49).\nKeypress for 'd' had a duration of 50 - 49 = 1 (pressed at time 49 right after the release of the previous character and released at time 50).\nThe longest of these was the keypress for 'b' and the second keypress for 'c', both with duration 20.\n'c' is lexicographically larger than 'b', so the answer is 'c'.\n
\n\n

Example 2:

\n\n
\nInput: releaseTimes = [12,23,36,46,62], keysPressed = "spuda"\nOutput: "a"\nExplanation: The keypresses were as follows:\nKeypress for 's' had a duration of 12.\nKeypress for 'p' had a duration of 23 - 12 = 11.\nKeypress for 'u' had a duration of 36 - 23 = 13.\nKeypress for 'd' had a duration of 46 - 36 = 10.\nKeypress for 'a' had a duration of 62 - 46 = 16.\nThe longest of these was the keypress for 'a' with duration 16.
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • releaseTimes.length == n
  • \n\t
  • keysPressed.length == n
  • \n\t
  • 2 <= n <= 1000
  • \n\t
  • 1 <= releaseTimes[i] <= 109
  • \n\t
  • releaseTimes[i] < releaseTimes[i+1]
  • \n\t
  • keysPressed contains only lowercase English letters.
  • \n
\n", "content_cn": "

LeetCode \u8bbe\u8ba1\u4e86\u4e00\u6b3e\u65b0\u5f0f\u952e\u76d8\uff0c\u6b63\u5728\u6d4b\u8bd5\u5176\u53ef\u7528\u6027\u3002\u6d4b\u8bd5\u4eba\u5458\u5c06\u4f1a\u70b9\u51fb\u4e00\u7cfb\u5217\u952e\uff08\u603b\u8ba1 n \u4e2a\uff09\uff0c\u6bcf\u6b21\u4e00\u4e2a\u3002

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u5b57\u7b26\u4e32 keysPressed \uff0c\u5176\u4e2d keysPressed[i] \u8868\u793a\u6d4b\u8bd5\u5e8f\u5217\u4e2d\u7b2c i \u4e2a\u88ab\u6309\u4e0b\u7684\u952e\u3002releaseTimes \u662f\u4e00\u4e2a\u5347\u5e8f\u6392\u5217\u7684\u5217\u8868\uff0c\u5176\u4e2d releaseTimes[i] \u8868\u793a\u677e\u5f00\u7b2c i \u4e2a\u952e\u7684\u65f6\u95f4\u3002\u5b57\u7b26\u4e32\u548c\u6570\u7ec4\u7684 \u4e0b\u6807\u90fd\u4ece 0 \u5f00\u59cb \u3002\u7b2c 0 \u4e2a\u952e\u5728\u65f6\u95f4\u4e3a 0 \u65f6\u88ab\u6309\u4e0b\uff0c\u63a5\u4e0b\u6765\u6bcf\u4e2a\u952e\u90fd \u6070\u597d \u5728\u524d\u4e00\u4e2a\u952e\u677e\u5f00\u65f6\u88ab\u6309\u4e0b\u3002

\n\n

\u6d4b\u8bd5\u4eba\u5458\u60f3\u8981\u627e\u51fa\u6309\u952e \u6301\u7eed\u65f6\u95f4\u6700\u957f \u7684\u952e\u3002\u7b2c i \u6b21\u6309\u952e\u7684\u6301\u7eed\u65f6\u95f4\u4e3a releaseTimes[i] - releaseTimes[i - 1] \uff0c\u7b2c 0 \u6b21\u6309\u952e\u7684\u6301\u7eed\u65f6\u95f4\u4e3a releaseTimes[0] \u3002

\n\n

\u6ce8\u610f\uff0c\u6d4b\u8bd5\u671f\u95f4\uff0c\u540c\u4e00\u4e2a\u952e\u53ef\u4ee5\u5728\u4e0d\u540c\u65f6\u523b\u88ab\u591a\u6b21\u6309\u4e0b\uff0c\u800c\u6bcf\u6b21\u7684\u6301\u7eed\u65f6\u95f4\u90fd\u53ef\u80fd\u4e0d\u540c\u3002

\n\n

\u8bf7\u8fd4\u56de\u6309\u952e \u6301\u7eed\u65f6\u95f4\u6700\u957f \u7684\u952e\uff0c\u5982\u679c\u6709\u591a\u4e2a\u8fd9\u6837\u7684\u952e\uff0c\u5219\u8fd4\u56de \u6309\u5b57\u6bcd\u987a\u5e8f\u6392\u5217\u6700\u5927 \u7684\u90a3\u4e2a\u952e\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1areleaseTimes = [9,29,49,50], keysPressed = \"cbcd\"\n\u8f93\u51fa\uff1a\"c\"\n\u89e3\u91ca\uff1a\u6309\u952e\u987a\u5e8f\u548c\u6301\u7eed\u65f6\u95f4\u5982\u4e0b\uff1a\n\u6309\u4e0b 'c' \uff0c\u6301\u7eed\u65f6\u95f4 9\uff08\u65f6\u95f4 0 \u6309\u4e0b\uff0c\u65f6\u95f4 9 \u677e\u5f00\uff09\n\u6309\u4e0b 'b' \uff0c\u6301\u7eed\u65f6\u95f4 29 - 9 = 20\uff08\u677e\u5f00\u4e0a\u4e00\u4e2a\u952e\u7684\u65f6\u95f4 9 \u6309\u4e0b\uff0c\u65f6\u95f4 29 \u677e\u5f00\uff09\n\u6309\u4e0b 'c' \uff0c\u6301\u7eed\u65f6\u95f4 49 - 29 = 20\uff08\u677e\u5f00\u4e0a\u4e00\u4e2a\u952e\u7684\u65f6\u95f4 29 \u6309\u4e0b\uff0c\u65f6\u95f4 49 \u677e\u5f00\uff09\n\u6309\u4e0b 'd' \uff0c\u6301\u7eed\u65f6\u95f4 50 - 49 = 1\uff08\u677e\u5f00\u4e0a\u4e00\u4e2a\u952e\u7684\u65f6\u95f4 49 \u6309\u4e0b\uff0c\u65f6\u95f4 50 \u677e\u5f00\uff09\n\u6309\u952e\u6301\u7eed\u65f6\u95f4\u6700\u957f\u7684\u952e\u662f 'b' \u548c 'c'\uff08\u7b2c\u4e8c\u6b21\u6309\u4e0b\u65f6\uff09\uff0c\u6301\u7eed\u65f6\u95f4\u90fd\u662f 20\n'c' \u6309\u5b57\u6bcd\u987a\u5e8f\u6392\u5217\u6bd4 'b' \u5927\uff0c\u6240\u4ee5\u7b54\u6848\u662f 'c'\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1areleaseTimes = [12,23,36,46,62], keysPressed = \"spuda\"\n\u8f93\u51fa\uff1a\"a\"\n\u89e3\u91ca\uff1a\u6309\u952e\u987a\u5e8f\u548c\u6301\u7eed\u65f6\u95f4\u5982\u4e0b\uff1a\n\u6309\u4e0b 's' \uff0c\u6301\u7eed\u65f6\u95f4 12\n\u6309\u4e0b 'p' \uff0c\u6301\u7eed\u65f6\u95f4 23 - 12 = 11\n\u6309\u4e0b 'u' \uff0c\u6301\u7eed\u65f6\u95f4 36 - 23 = 13\n\u6309\u4e0b 'd' \uff0c\u6301\u7eed\u65f6\u95f4 46 - 36 = 10\n\u6309\u4e0b 'a' \uff0c\u6301\u7eed\u65f6\u95f4 62 - 46 = 16\n\u6309\u952e\u6301\u7eed\u65f6\u95f4\u6700\u957f\u7684\u952e\u662f 'a' \uff0c\u6301\u7eed\u65f6\u95f4 16
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • releaseTimes.length == n
  • \n\t
  • keysPressed.length == n
  • \n\t
  • 2 <= n <= 1000
  • \n\t
  • 1 <= releaseTimes[i] <= 109
  • \n\t
  • releaseTimes[i] < releaseTimes[i+1]
  • \n\t
  • keysPressed \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n char slowestKey(vector& releaseTimes, string keysPressed) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public char slowestKey(int[] releaseTimes, String keysPressed) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def slowestKey(self, releaseTimes, keysPressed):\n \"\"\"\n :type releaseTimes: List[int]\n :type keysPressed: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def slowestKey(self, releaseTimes: List[int], keysPressed: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar slowestKey(int* releaseTimes, int releaseTimesSize, char * keysPressed){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public char SlowestKey(int[] releaseTimes, string keysPressed) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} releaseTimes\n * @param {string} keysPressed\n * @return {character}\n */\nvar slowestKey = function(releaseTimes, keysPressed) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} release_times\n# @param {String} keys_pressed\n# @return {Character}\ndef slowest_key(release_times, keys_pressed)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func slowestKey(_ releaseTimes: [Int], _ keysPressed: String) -> Character {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func slowestKey(releaseTimes []int, keysPressed string) byte {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def slowestKey(releaseTimes: Array[Int], keysPressed: String): Char = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun slowestKey(releaseTimes: IntArray, keysPressed: String): Char {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn slowest_key(release_times: Vec, keys_pressed: String) -> char {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $releaseTimes\n * @param String $keysPressed\n * @return String\n */\n function slowestKey($releaseTimes, $keysPressed) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function slowestKey(releaseTimes: number[], keysPressed: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (slowest-key releaseTimes keysPressed)\n (-> (listof exact-integer?) string? char?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1629](https://leetcode-cn.com/problems/slowest-key)", "[\u6309\u952e\u6301\u7eed\u65f6\u95f4\u6700\u957f\u7684\u952e](/solution/1600-1699/1629.Slowest%20Key/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1629](https://leetcode.com/problems/slowest-key)", "[Slowest Key](/solution/1600-1699/1629.Slowest%20Key/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1750", "frontend_question_id": "1612", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/check-if-two-expression-trees-are-equivalent", "url_en": "https://leetcode.com/problems/check-if-two-expression-trees-are-equivalent", "relative_path_cn": "/solution/1600-1699/1612.Check%20If%20Two%20Expression%20Trees%20are%20Equivalent/README.md", "relative_path_en": "/solution/1600-1699/1612.Check%20If%20Two%20Expression%20Trees%20are%20Equivalent/README_EN.md", "title_cn": "\u68c0\u67e5\u4e24\u68f5\u4e8c\u53c9\u8868\u8fbe\u5f0f\u6811\u662f\u5426\u7b49\u4ef7", "title_en": "Check If Two Expression Trees are Equivalent", "question_title_slug": "check-if-two-expression-trees-are-equivalent", "content_en": "

A binary expression tree is a kind of binary tree used to represent arithmetic expressions. Each node of a binary expression tree has either zero or two children. Leaf nodes (nodes with 0 children) correspond to operands (variables), and internal nodes (nodes with two children) correspond to the operators. In this problem, we only consider the '+' operator (i.e. addition).

\n\n

You are given the roots of two binary expression trees, root1 and root2. Return true if the two binary expression trees are equivalent. Otherwise, return false.

\n\n

Two binary expression trees are equivalent if they evaluate to the same value regardless of what the variables are set to.

\n\n

Follow up: What will you change in your solution if the tree also supports the '-' operator (i.e. subtraction)?

\n\n

 

\n

Example 1:

\n\n
\nInput: root1 = [x], root2 = [x]\nOutput: true\n
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: root1 = [+,a,+,null,null,b,c], root2 = [+,+,a,b,c]\nOutput: true\nExplaination: a + (b + c) == (b + c) + a
\n\n

Example 3:

\n\n

\"\"

\n\n
\nInput: root1 = [+,a,+,null,null,b,c], root2 = [+,+,a,b,d]\nOutput: false\nExplaination: a + (b + c) != (b + d) + a\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The number of nodes in both trees are equal, odd and, in the range [1, 4999].
  • \n\t
  • Node.val is '+' or a lower-case English letter.
  • \n\t
  • It's guaranteed that the tree given is a valid binary expression tree.
  • \n
\n", "content_cn": "

\u4e8c\u53c9\u8868\u8fbe\u5f0f\u6811\u662f\u4e00\u79cd\u8868\u8fbe\u7b97\u672f\u8868\u8fbe\u5f0f\u7684\u4e8c\u53c9\u6811\u3002\u4e8c\u53c9\u8868\u8fbe\u5f0f\u6811\u4e2d\u7684\u6bcf\u4e00\u4e2a\u8282\u70b9\u90fd\u6709\u96f6\u4e2a\u6216\u4e24\u4e2a\u5b50\u8282\u70b9\u3002\u00a0\u53f6\u8282\u70b9\uff08\u6709 0 \u4e2a\u5b50\u8282\u70b9\u7684\u8282\u70b9\uff09\u8868\u793a\u64cd\u4f5c\u6570\uff0c\u975e\u53f6\u8282\u70b9\uff08\u6709 2 \u4e2a\u5b50\u8282\u70b9\u7684\u8282\u70b9\uff09\u8868\u793a\u8fd0\u7b97\u7b26\u3002\u5728\u672c\u9898\u4e2d\uff0c\u6211\u4eec\u53ea\u8003\u8651 '+' \u8fd0\u7b97\u7b26\uff08\u5373\u52a0\u6cd5\uff09\u3002

\n\n

\u7ed9\u5b9a\u4e24\u68f5\u4e8c\u53c9\u8868\u8fbe\u5f0f\u6811\u7684\u6839\u8282\u70b9\u00a0root1\u00a0\u548c\u00a0root2\u00a0\u3002\u5982\u679c\u4e24\u68f5\u4e8c\u53c9\u8868\u8fbe\u5f0f\u6811\u7b49\u4ef7\uff0c\u8fd4\u56de\u00a0true\u00a0\uff0c\u5426\u5219\u8fd4\u56de\u00a0false\u00a0\u3002

\n\n

\u5f53\u4e24\u68f5\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u7684\u53d8\u91cf\u53d6\u4efb\u610f\u503c\uff0c\u5206\u522b\u6c42\u5f97\u7684\u503c\u90fd\u76f8\u7b49\u65f6\uff0c\u6211\u4eec\u79f0\u8fd9\u4e24\u68f5\u4e8c\u53c9\u8868\u8fbe\u5f0f\u6811\u662f\u7b49\u4ef7\u7684\u3002

\n\n

\u8fdb\u9636\uff1a\u5f53\u4f60\u7684\u7b54\u6848\u9700\u540c\u65f6\u652f\u6301\u00a0'-'\u00a0\u8fd0\u7b97\u7b26\uff08\u51cf\u6cd5\uff09\u65f6\uff0c\u4f60\u8be5\u5982\u4f55\u4fee\u6539\u4f60\u7684\u7b54\u6848\uff1f

\n\n

\u00a0

\n\n

\u793a\u4f8b 1:

\n\n
\n\u8f93\u5165\uff1a root1 = [x], root2 = [x]\n\u8f93\u51fa\uff1a true\n
\n\n

\u793a\u4f8b 2:

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1aroot1 = [+,a,+,null,null,b,c], root2 = [+,+,a,b,c]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1aa + (b + c) == (b + c) + a
\n\n

\u793a\u4f8b 3:

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1a root1 = [+,a,+,null,null,b,c], root2 = [+,+,a,b,d]\n\u8f93\u51fa\uff1a false\n\u89e3\u91ca\uff1a a + (b + c) != (b + d) + a\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u4e24\u68f5\u6811\u4e2d\u7684\u8282\u70b9\u4e2a\u6570\u76f8\u7b49\uff0c\u4e14\u8282\u70b9\u4e2a\u6570\u4e3a\u8303\u56f4\u00a0[1, 4999]\u00a0\u5185\u7684\u5947\u6570\u3002
  • \n\t
  • Node.val\u00a0\u662f\u00a0'+'\u00a0\u6216\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
  • \n\t
  • \u7ed9\u5b9a\u7684\u6811\u4fdd\u8bc1\u662f\u6709\u6548\u7684\u4e8c\u53c9\u8868\u8fbe\u5f0f\u6811\u3002
  • \n
\n", "tags_en": ["Tree", "Hash Table"], "tags_cn": ["\u6811", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for a binary tree node.\n * struct Node {\n * char val;\n * Node *left;\n * Node *right;\n * Node() : val(' '), left(nullptr), right(nullptr) {}\n * Node(char x) : val(x), left(nullptr), right(nullptr) {}\n * Node(char x, Node *left, Node *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n bool checkEquivalence(Node* root1, Node* root2) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * class Node {\n * char val;\n * Node left;\n * Node right;\n * Node() {this.val = ' ';}\n * Node(char val) { this.val = val; }\n * Node(char val, Node left, Node right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public boolean checkEquivalence(Node root1, Node root2) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class Node(object):\n# def __init__(self, val=\" \", left=None, right=None):\n# self.val = val\n# self.left = None\n# self.right = None\nclass Solution(object):\n def checkEquivalence(self, root1, root2):\n \"\"\"\n :type root1: Node\n :type root2: Node\n :rtype: bool\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class Node(object):\n# def __init__(self, val=\" \", left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def checkEquivalence(self, root1: 'Node', root2: 'Node') -> bool:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class Node {\n * public char val;\n * public Node left;\n * public Node right;\n * public Node(char val=' ', TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public bool CheckEquivalence(Node root1, Node root2) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function Node(val, left, right) {\n * this.val = (val===undefined ? \" \" : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {Node} root1\n * @param {Node} root2\n * @return {boolean}\n */\nvar checkEquivalence = function(root1, root2) {\n \n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1612](https://leetcode-cn.com/problems/check-if-two-expression-trees-are-equivalent)", "[\u68c0\u67e5\u4e24\u68f5\u4e8c\u53c9\u8868\u8fbe\u5f0f\u6811\u662f\u5426\u7b49\u4ef7](/solution/1600-1699/1612.Check%20If%20Two%20Expression%20Trees%20are%20Equivalent/README.md)", "`\u6811`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1612](https://leetcode.com/problems/check-if-two-expression-trees-are-equivalent)", "[Check If Two Expression Trees are Equivalent](/solution/1600-1699/1612.Check%20If%20Two%20Expression%20Trees%20are%20Equivalent/README_EN.md)", "`Tree`,`Hash Table`", "Medium", "\ud83d\udd12"]}, {"question_id": "1749", "frontend_question_id": "1607", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/sellers-with-no-sales", "url_en": "https://leetcode.com/problems/sellers-with-no-sales", "relative_path_cn": "/solution/1600-1699/1607.Sellers%20With%20No%20Sales/README.md", "relative_path_en": "/solution/1600-1699/1607.Sellers%20With%20No%20Sales/README_EN.md", "title_cn": "\u6ca1\u6709\u5356\u51fa\u7684\u5356\u5bb6", "title_en": "Sellers With No Sales", "question_title_slug": "sellers-with-no-sales", "content_en": "

Table: Customer

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| customer_id   | int     |\n| customer_name | varchar |\n+---------------+---------+\ncustomer_id is the primary key for this table.\nEach row of this table contains the information of each customer in the WebStore.\n
\n\n

 

\n\n

Table: Orders

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| order_id      | int     |\n| sale_date     | date    |\n| order_cost    | int     |\n| customer_id   | int     |\n| seller_id     | int     |\n+---------------+---------+\norder_id is the primary key for this table.\nEach row of this table contains all orders made in the webstore.\nsale_date is the date when the transaction was made between the customer (customer_id) and the seller (seller_id).\n
\n\n

 

\n\n

Table: Seller

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| seller_id     | int     |\n| seller_name   | varchar |\n+---------------+---------+\nseller_id is the primary key for this table.\nEach row of this table contains the information of each seller.\n
\n\n

 

\n\n

Write an SQL query to report the names of all sellers who did not make any sales in 2020.

\n\n

Return the result table ordered by seller_name in ascending order.

\n\n

The query result format is in the following example.

\n\n
\nCustomer table:\n+--------------+---------------+\n| customer_id  | customer_name |\n+--------------+---------------+\n| 101          | Alice         |\n| 102          | Bob           |\n| 103          | Charlie       |\n+--------------+---------------+\n\nOrders table:\n+-------------+------------+--------------+-------------+-------------+\n| order_id    | sale_date  | order_cost   | customer_id | seller_id   |\n+-------------+------------+--------------+-------------+-------------+\n| 1           | 2020-03-01 | 1500         | 101         | 1           |\n| 2           | 2020-05-25 | 2400         | 102         | 2           |\n| 3           | 2019-05-25 | 800          | 101         | 3           |\n| 4           | 2020-09-13 | 1000         | 103         | 2           |\n| 5           | 2019-02-11 | 700          | 101         | 2           |\n+-------------+------------+--------------+-------------+-------------+\n\nSeller table:\n+-------------+-------------+\n| seller_id   | seller_name |\n+-------------+-------------+\n| 1           | Daniel      |\n| 2           | Elizabeth   |\n| 3           | Frank       |\n+-------------+-------------+\n\nResult table:\n+-------------+\n| seller_name |\n+-------------+\n| Frank       |\n+-------------+\nDaniel made 1 sale in March 2020.\nElizabeth made 2 sales in 2020 and 1 sale in 2019.\nFrank made 1 sale in 2019 but no sales in 2020.\n
\n", "content_cn": "

\u8868: Customer

\n\n
+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| customer_id   | int     |\n| customer_name | varchar |\n+---------------+---------+\ncustomer_id \u662f\u8be5\u8868\u4e3b\u952e.\n\u8be5\u8868\u7684\u6bcf\u884c\u5305\u542b\u7f51\u4e0a\u5546\u57ce\u7684\u6bcf\u4e00\u4f4d\u987e\u5ba2\u7684\u4fe1\u606f.\n
\n\n

\u00a0

\n\n

\u8868: Orders

\n\n
+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| order_id      | int     |\n| sale_date     | date    |\n| order_cost    | int     |\n| customer_id   | int     |\n| seller_id     | int     |\n+---------------+---------+\norder_id \u662f\u8be5\u8868\u4e3b\u952e.\n\u8be5\u8868\u7684\u6bcf\u884c\u5305\u542b\u7f51\u4e0a\u5546\u57ce\u7684\u6240\u6709\u8ba2\u5355\u7684\u4fe1\u606f.\nsale_date \u662f\u987e\u5ba2customer_id\u548c\u5356\u5bb6seller_id\u4e4b\u95f4\u4ea4\u6613\u7684\u65e5\u671f.\n
\n\n

\u00a0

\n\n

\u8868: Seller

\n\n
+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| seller_id     | int     |\n| seller_name   | varchar |\n+---------------+---------+\nseller_id \u662f\u8be5\u8868\u4e3b\u952e.\n\u8be5\u8868\u7684\u6bcf\u884c\u5305\u542b\u6bcf\u4e00\u4f4d\u5356\u5bb6\u7684\u4fe1\u606f.\n
\n\n

\u00a0

\n\n

\u5199\u4e00\u4e2aSQL\u8bed\u53e5,\u00a0\u62a5\u544a\u6240\u6709\u57282020\u5e74\u5ea6\u6ca1\u6709\u4efb\u4f55\u5356\u51fa\u7684\u5356\u5bb6\u7684\u540d\u5b57.

\n\n

\u8fd4\u56de\u7ed3\u679c\u6309\u7167\u00a0seller_name\u00a0\u5347\u5e8f\u6392\u5217.

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a.

\n\n

\u00a0

\n\n
Customer \u8868:\n+--------------+---------------+\n| customer_id  | customer_name |\n+--------------+---------------+\n| 101          | Alice         |\n| 102          | Bob           |\n| 103          | Charlie       |\n+--------------+---------------+\n\nOrders \u8868:\n+-------------+------------+--------------+-------------+-------------+\n| order_id    | sale_date  | order_cost   | customer_id | seller_id   |\n+-------------+------------+--------------+-------------+-------------+\n| 1           | 2020-03-01 | 1500         | 101         | 1           |\n| 2           | 2020-05-25 | 2400         | 102         | 2           |\n| 3           | 2019-05-25 | 800          | 101         | 3           |\n| 4           | 2020-09-13 | 1000         | 103         | 2           |\n| 5           | 2019-02-11 | 700          | 101         | 2           |\n+-------------+------------+--------------+-------------+-------------+\n\nSeller \u8868:\n+-------------+-------------+\n| seller_id   | seller_name |\n+-------------+-------------+\n| 1           | Daniel      |\n| 2           | Elizabeth   |\n| 3           | Frank       |\n+-------------+-------------+\n\nResult \u8868:\n+-------------+\n| seller_name |\n+-------------+\n| Frank       |\n+-------------+\nDaniel\u57282020\u5e743\u6708\u5356\u51fa1\u6b21.\nElizabeth\u57282020\u5e74\u5356\u51fa2\u6b21, \u57282019\u5e74\u5356\u51fa1\u6b21.\nFrank\u57282019\u5e74\u5356\u51fa1\u6b21, \u57282020\u5e74\u6ca1\u6709\u5356\u51fa.\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1607](https://leetcode-cn.com/problems/sellers-with-no-sales)", "[\u6ca1\u6709\u5356\u51fa\u7684\u5356\u5bb6](/solution/1600-1699/1607.Sellers%20With%20No%20Sales/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1607](https://leetcode.com/problems/sellers-with-no-sales)", "[Sellers With No Sales](/solution/1600-1699/1607.Sellers%20With%20No%20Sales/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1748", "frontend_question_id": "1626", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/best-team-with-no-conflicts", "url_en": "https://leetcode.com/problems/best-team-with-no-conflicts", "relative_path_cn": "/solution/1600-1699/1626.Best%20Team%20With%20No%20Conflicts/README.md", "relative_path_en": "/solution/1600-1699/1626.Best%20Team%20With%20No%20Conflicts/README_EN.md", "title_cn": "\u65e0\u77db\u76fe\u7684\u6700\u4f73\u7403\u961f", "title_en": "Best Team With No Conflicts", "question_title_slug": "best-team-with-no-conflicts", "content_en": "

You are the manager of a basketball team. For the upcoming tournament, you want to choose the team with the highest overall score. The score of the team is the sum of scores of all the players in the team.

\n\n

However, the basketball team is not allowed to have conflicts. A conflict exists if a younger player has a strictly higher score than an older player. A conflict does not occur between players of the same age.

\n\n

Given two lists, scores and ages, where each scores[i] and ages[i] represents the score and age of the ith player, respectively, return the highest overall score of all possible basketball teams.

\n\n

 

\n

Example 1:

\n\n
\nInput: scores = [1,3,5,10,15], ages = [1,2,3,4,5]\nOutput: 34\nExplanation: You can choose all the players.\n
\n\n

Example 2:

\n\n
\nInput: scores = [4,5,6,5], ages = [2,1,2,1]\nOutput: 16\nExplanation: It is best to choose the last 3 players. Notice that you are allowed to choose multiple people of the same age.\n
\n\n

Example 3:

\n\n
\nInput: scores = [1,2,3,5], ages = [8,9,10,1]\nOutput: 6\nExplanation: It is best to choose the first 3 players. \n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= scores.length, ages.length <= 1000
  • \n\t
  • scores.length == ages.length
  • \n\t
  • 1 <= scores[i] <= 106
  • \n\t
  • 1 <= ages[i] <= 1000
  • \n
\n", "content_cn": "

\u5047\u8bbe\u4f60\u662f\u7403\u961f\u7684\u7ecf\u7406\u3002\u5bf9\u4e8e\u5373\u5c06\u5230\u6765\u7684\u9526\u6807\u8d5b\uff0c\u4f60\u60f3\u7ec4\u5408\u4e00\u652f\u603b\u4f53\u5f97\u5206\u6700\u9ad8\u7684\u7403\u961f\u3002\u7403\u961f\u7684\u5f97\u5206\u662f\u7403\u961f\u4e2d\u6240\u6709\u7403\u5458\u7684\u5206\u6570 \u603b\u548c \u3002

\n\n

\u7136\u800c\uff0c\u7403\u961f\u4e2d\u7684\u77db\u76fe\u4f1a\u9650\u5236\u7403\u5458\u7684\u53d1\u6325\uff0c\u6240\u4ee5\u5fc5\u987b\u9009\u51fa\u4e00\u652f \u6ca1\u6709\u77db\u76fe \u7684\u7403\u961f\u3002\u5982\u679c\u4e00\u540d\u5e74\u9f84\u8f83\u5c0f\u7403\u5458\u7684\u5206\u6570 \u4e25\u683c\u5927\u4e8e \u4e00\u540d\u5e74\u9f84\u8f83\u5927\u7684\u7403\u5458\uff0c\u5219\u5b58\u5728\u77db\u76fe\u3002\u540c\u9f84\u7403\u5458\u4e4b\u95f4\u4e0d\u4f1a\u53d1\u751f\u77db\u76fe\u3002

\n\n

\u7ed9\u4f60\u4e24\u4e2a\u5217\u8868 scores \u548c ages\uff0c\u5176\u4e2d\u6bcf\u7ec4 scores[i] \u548c ages[i] \u8868\u793a\u7b2c i \u540d\u7403\u5458\u7684\u5206\u6570\u548c\u5e74\u9f84\u3002\u8bf7\u4f60\u8fd4\u56de \u6240\u6709\u53ef\u80fd\u7684\u65e0\u77db\u76fe\u7403\u961f\u4e2d\u5f97\u5206\u6700\u9ad8\u90a3\u652f\u7684\u5206\u6570 \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1ascores = [1,3,5,10,15], ages = [1,2,3,4,5]\n\u8f93\u51fa\uff1a34\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u9009\u4e2d\u6240\u6709\u7403\u5458\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1ascores = [4,5,6,5], ages = [2,1,2,1]\n\u8f93\u51fa\uff1a16\n\u89e3\u91ca\uff1a\u6700\u4f73\u7684\u9009\u62e9\u662f\u540e 3 \u540d\u7403\u5458\u3002\u6ce8\u610f\uff0c\u4f60\u53ef\u4ee5\u9009\u4e2d\u591a\u4e2a\u540c\u9f84\u7403\u5458\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1ascores = [1,2,3,5], ages = [8,9,10,1]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u6700\u4f73\u7684\u9009\u62e9\u662f\u524d 3 \u540d\u7403\u5458\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= scores.length, ages.length <= 1000
  • \n\t
  • scores.length == ages.length
  • \n\t
  • 1 <= scores[i] <= 106
  • \n\t
  • 1 <= ages[i] <= 1000
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int bestTeamScore(vector& scores, vector& ages) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int bestTeamScore(int[] scores, int[] ages) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def bestTeamScore(self, scores, ages):\n \"\"\"\n :type scores: List[int]\n :type ages: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def bestTeamScore(self, scores: List[int], ages: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint bestTeamScore(int* scores, int scoresSize, int* ages, int agesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int BestTeamScore(int[] scores, int[] ages) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} scores\n * @param {number[]} ages\n * @return {number}\n */\nvar bestTeamScore = function(scores, ages) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} scores\n# @param {Integer[]} ages\n# @return {Integer}\ndef best_team_score(scores, ages)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func bestTeamScore(_ scores: [Int], _ ages: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func bestTeamScore(scores []int, ages []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def bestTeamScore(scores: Array[Int], ages: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun bestTeamScore(scores: IntArray, ages: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn best_team_score(scores: Vec, ages: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $scores\n * @param Integer[] $ages\n * @return Integer\n */\n function bestTeamScore($scores, $ages) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function bestTeamScore(scores: number[], ages: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (best-team-score scores ages)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1626](https://leetcode-cn.com/problems/best-team-with-no-conflicts)", "[\u65e0\u77db\u76fe\u7684\u6700\u4f73\u7403\u961f](/solution/1600-1699/1626.Best%20Team%20With%20No%20Conflicts/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1626](https://leetcode.com/problems/best-team-with-no-conflicts)", "[Best Team With No Conflicts](/solution/1600-1699/1626.Best%20Team%20With%20No%20Conflicts/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "1747", "frontend_question_id": "1625", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/lexicographically-smallest-string-after-applying-operations", "url_en": "https://leetcode.com/problems/lexicographically-smallest-string-after-applying-operations", "relative_path_cn": "/solution/1600-1699/1625.Lexicographically%20Smallest%20String%20After%20Applying%20Operations/README.md", "relative_path_en": "/solution/1600-1699/1625.Lexicographically%20Smallest%20String%20After%20Applying%20Operations/README_EN.md", "title_cn": "\u6267\u884c\u64cd\u4f5c\u540e\u5b57\u5178\u5e8f\u6700\u5c0f\u7684\u5b57\u7b26\u4e32", "title_en": "Lexicographically Smallest String After Applying Operations", "question_title_slug": "lexicographically-smallest-string-after-applying-operations", "content_en": "

You are given a string s of even length consisting of digits from 0 to 9, and two integers a and b.

\r\n\r\n

You can apply either of the following two operations any number of times and in any order on s:

\r\n\r\n
    \r\n\t
  • Add a to all odd indices of s (0-indexed). Digits post 9 are cycled back to 0. For example, if s = "3456" and a = 5, s becomes "3951".
  • \r\n\t
  • Rotate s to the right by b positions. For example, if s = "3456" and b = 1, s becomes "6345".
  • \r\n
\r\n\r\n

Return the lexicographically smallest string you can obtain by applying the above operations any number of times on s.

\r\n\r\n

A string a is lexicographically smaller than a string b (of the same length) if in the first position where a and b differ, string a has a letter that appears earlier in the alphabet than the corresponding letter in b. For example, "0158" is lexicographically smaller than "0190" because the first position they differ is at the third letter, and '5' comes before '9'.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: s = "5525", a = 9, b = 2\r\nOutput: "2050"\r\nExplanation: We can apply the following operations:\r\nStart:  "5525"\r\nRotate: "2555"\r\nAdd:    "2454"\r\nAdd:    "2353"\r\nRotate: "5323"\r\nAdd:    "5222"\r\n\u200b\u200b\u200b\u200b\u200b\u200b\u200bAdd:    "5121"\r\n\u200b\u200b\u200b\u200b\u200b\u200b\u200bRotate: "2151"\r\n\u200b\u200b\u200b\u200b\u200b\u200b\u200bAdd:    "2050"\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\r\nThere is no way to obtain a string that is lexicographically smaller then "2050".\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: s = "74", a = 5, b = 1\r\nOutput: "24"\r\nExplanation: We can apply the following operations:\r\nStart:  "74"\r\nRotate: "47"\r\n\u200b\u200b\u200b\u200b\u200b\u200b\u200bAdd:    "42"\r\n\u200b\u200b\u200b\u200b\u200b\u200b\u200bRotate: "24"\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\r\nThere is no way to obtain a string that is lexicographically smaller then "24".\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: s = "0011", a = 4, b = 2\r\nOutput: "0011"\r\nExplanation: There are no sequence of operations that will give us a lexicographically smaller string than "0011".\r\n
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: s = "43987654", a = 7, b = 3\r\nOutput: "00553311"\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 2 <= s.length <= 100
  • \r\n\t
  • s.length is even.
  • \r\n\t
  • s consists of digits from 0 to 9 only.
  • \r\n\t
  • 1 <= a <= 9
  • \r\n\t
  • 1 <= b <= s.length - 1
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \u4ee5\u53ca\u4e24\u4e2a\u6574\u6570 a \u548c b \u3002\u5176\u4e2d\uff0c\u5b57\u7b26\u4e32 s \u7684\u957f\u5ea6\u4e3a\u5076\u6570\uff0c\u4e14\u4ec5\u7531\u6570\u5b57 0 \u5230 9 \u7ec4\u6210\u3002

\n\n

\u4f60\u53ef\u4ee5\u5728 s \u4e0a\u6309\u4efb\u610f\u987a\u5e8f\u591a\u6b21\u6267\u884c\u4e0b\u9762\u4e24\u4e2a\u64cd\u4f5c\u4e4b\u4e00\uff1a

\n\n
    \n\t
  • \u7d2f\u52a0\uff1a\u5c06\u00a0 a \u52a0\u5230 s \u4e2d\u6240\u6709\u4e0b\u6807\u4e3a\u5947\u6570\u7684\u5143\u7d20\u4e0a\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\u3002\u6570\u5b57\u4e00\u65e6\u8d85\u8fc7 9 \u5c31\u4f1a\u53d8\u6210 0\uff0c\u5982\u6b64\u5faa\u73af\u5f80\u590d\u3002\u4f8b\u5982\uff0cs = \"3456\" \u4e14 a = 5\uff0c\u5219\u6267\u884c\u6b64\u64cd\u4f5c\u540e s \u53d8\u6210 \"3951\"\u3002
  • \n\t
  • \u8f6e\u8f6c\uff1a\u5c06 s \u5411\u53f3\u8f6e\u8f6c b \u4f4d\u3002\u4f8b\u5982\uff0cs = \"3456\" \u4e14 b = 1\uff0c\u5219\u6267\u884c\u6b64\u64cd\u4f5c\u540e s \u53d8\u6210 \"6345\"\u3002
  • \n
\n\n

\u8bf7\u4f60\u8fd4\u56de\u5728 s \u4e0a\u6267\u884c\u4e0a\u8ff0\u64cd\u4f5c\u4efb\u610f\u6b21\u540e\u53ef\u4ee5\u5f97\u5230\u7684 \u5b57\u5178\u5e8f\u6700\u5c0f \u7684\u5b57\u7b26\u4e32\u3002

\n\n

\u5982\u679c\u4e24\u4e2a\u5b57\u7b26\u4e32\u957f\u5ea6\u76f8\u540c\uff0c\u90a3\u4e48\u5b57\u7b26\u4e32 a \u5b57\u5178\u5e8f\u6bd4\u5b57\u7b26\u4e32 b \u5c0f\u53ef\u4ee5\u8fd9\u6837\u5b9a\u4e49\uff1a\u5728 a \u548c b \u51fa\u73b0\u4e0d\u540c\u7684\u7b2c\u4e00\u4e2a\u4f4d\u7f6e\u4e0a\uff0c\u5b57\u7b26\u4e32 a \u4e2d\u7684\u5b57\u7b26\u51fa\u73b0\u5728\u5b57\u6bcd\u8868\u4e2d\u7684\u65f6\u95f4\u65e9\u4e8e b \u4e2d\u7684\u5bf9\u5e94\u5b57\u7b26\u3002\u4f8b\u5982\uff0c\"0158\u201d \u5b57\u5178\u5e8f\u6bd4 \"0190\" \u5c0f\uff0c\u56e0\u4e3a\u4e0d\u540c\u7684\u7b2c\u4e00\u4e2a\u4f4d\u7f6e\u662f\u5728\u7b2c\u4e09\u4e2a\u5b57\u7b26\uff0c\u663e\u7136 '5' \u51fa\u73b0\u5728 '9' \u4e4b\u524d\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"5525\", a = 9, b = 2\n\u8f93\u51fa\uff1a\"2050\"\n\u89e3\u91ca\uff1a\u6267\u884c\u64cd\u4f5c\u5982\u4e0b\uff1a\n\u521d\u6001\uff1a\"5525\"\n\u8f6e\u8f6c\uff1a\"2555\"\n\u7d2f\u52a0\uff1a\"2454\"\n\u7d2f\u52a0\uff1a\"2353\"\n\u8f6e\u8f6c\uff1a\"5323\"\n\u7d2f\u52a0\uff1a\"5222\"\n\u7d2f\u52a0\uff1a\"5121\"\n\u8f6e\u8f6c\uff1a\"2151\"\n\u7d2f\u52a0\uff1a\"2050\"\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\n\u65e0\u6cd5\u83b7\u5f97\u5b57\u5178\u5e8f\u5c0f\u4e8e \"2050\" \u7684\u5b57\u7b26\u4e32\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"74\", a = 5, b = 1\n\u8f93\u51fa\uff1a\"24\"\n\u89e3\u91ca\uff1a\u6267\u884c\u64cd\u4f5c\u5982\u4e0b\uff1a\n\u521d\u6001\uff1a\"74\"\n\u8f6e\u8f6c\uff1a\"47\"\n\u7d2f\u52a0\uff1a\"42\"\n\u8f6e\u8f6c\uff1a\"24\"\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\n\u65e0\u6cd5\u83b7\u5f97\u5b57\u5178\u5e8f\u5c0f\u4e8e \"24\" \u7684\u5b57\u7b26\u4e32\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"0011\", a = 4, b = 2\n\u8f93\u51fa\uff1a\"0011\"\n\u89e3\u91ca\uff1a\u65e0\u6cd5\u83b7\u5f97\u5b57\u5178\u5e8f\u5c0f\u4e8e \"0011\" \u7684\u5b57\u7b26\u4e32\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"43987654\", a = 7, b = 3\n\u8f93\u51fa\uff1a\"00553311\"\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= s.length <= 100
  • \n\t
  • s.length \u662f\u5076\u6570
  • \n\t
  • s \u4ec5\u7531\u6570\u5b57 0 \u5230 9 \u7ec4\u6210
  • \n\t
  • 1 <= a <= 9
  • \n\t
  • 1 <= b <= s.length - 1
  • \n
\n", "tags_en": ["Depth-first Search", "Breadth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string findLexSmallestString(string s, int a, int b) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String findLexSmallestString(String s, int a, int b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findLexSmallestString(self, s, a, b):\n \"\"\"\n :type s: str\n :type a: int\n :type b: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findLexSmallestString(self, s: str, a: int, b: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "char * findLexSmallestString(char * s, int a, int b){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string FindLexSmallestString(string s, int a, int b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number} a\n * @param {number} b\n * @return {string}\n */\nvar findLexSmallestString = function(s, a, b) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer} a\n# @param {Integer} b\n# @return {String}\ndef find_lex_smallest_string(s, a, b)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findLexSmallestString(_ s: String, _ a: Int, _ b: Int) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findLexSmallestString(s string, a int, b int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findLexSmallestString(s: String, a: Int, b: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findLexSmallestString(s: String, a: Int, b: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_lex_smallest_string(s: String, a: i32, b: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer $a\n * @param Integer $b\n * @return String\n */\n function findLexSmallestString($s, $a, $b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findLexSmallestString(s: string, a: number, b: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-lex-smallest-string s a b)\n (-> string? exact-integer? exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1625](https://leetcode-cn.com/problems/lexicographically-smallest-string-after-applying-operations)", "[\u6267\u884c\u64cd\u4f5c\u540e\u5b57\u5178\u5e8f\u6700\u5c0f\u7684\u5b57\u7b26\u4e32](/solution/1600-1699/1625.Lexicographically%20Smallest%20String%20After%20Applying%20Operations/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1625](https://leetcode.com/problems/lexicographically-smallest-string-after-applying-operations)", "[Lexicographically Smallest String After Applying Operations](/solution/1600-1699/1625.Lexicographically%20Smallest%20String%20After%20Applying%20Operations/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`", "Medium", ""]}, {"question_id": "1746", "frontend_question_id": "1624", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/largest-substring-between-two-equal-characters", "url_en": "https://leetcode.com/problems/largest-substring-between-two-equal-characters", "relative_path_cn": "/solution/1600-1699/1624.Largest%20Substring%20Between%20Two%20Equal%20Characters/README.md", "relative_path_en": "/solution/1600-1699/1624.Largest%20Substring%20Between%20Two%20Equal%20Characters/README_EN.md", "title_cn": "\u4e24\u4e2a\u76f8\u540c\u5b57\u7b26\u4e4b\u95f4\u7684\u6700\u957f\u5b50\u5b57\u7b26\u4e32", "title_en": "Largest Substring Between Two Equal Characters", "question_title_slug": "largest-substring-between-two-equal-characters", "content_en": "

Given a string s, return the length of the longest substring between two equal characters, excluding the two characters. If there is no such substring return -1.

\n\n

A substring is a contiguous sequence of characters within a string.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "aa"\nOutput: 0\nExplanation: The optimal substring here is an empty substring between the two 'a's.
\n\n

Example 2:

\n\n
\nInput: s = "abca"\nOutput: 2\nExplanation: The optimal substring here is "bc".\n
\n\n

Example 3:

\n\n
\nInput: s = "cbzxy"\nOutput: -1\nExplanation: There are no characters that appear twice in s.\n
\n\n

Example 4:

\n\n
\nInput: s = "cabbac"\nOutput: 4\nExplanation: The optimal substring here is "abba". Other non-optimal substrings include "bb" and "".\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 300
  • \n\t
  • s contains only lowercase English letters.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s\uff0c\u8bf7\u4f60\u8fd4\u56de \u4e24\u4e2a\u76f8\u540c\u5b57\u7b26\u4e4b\u95f4\u7684\u6700\u957f\u5b50\u5b57\u7b26\u4e32\u7684\u957f\u5ea6 \uff0c\u8ba1\u7b97\u957f\u5ea6\u65f6\u4e0d\u542b\u8fd9\u4e24\u4e2a\u5b57\u7b26\u3002\u5982\u679c\u4e0d\u5b58\u5728\u8fd9\u6837\u7684\u5b50\u5b57\u7b26\u4e32\uff0c\u8fd4\u56de -1 \u3002

\n\n

\u5b50\u5b57\u7b26\u4e32 \u662f\u5b57\u7b26\u4e32\u4e2d\u7684\u4e00\u4e2a\u8fde\u7eed\u5b57\u7b26\u5e8f\u5217\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1as = \"aa\"\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6700\u4f18\u7684\u5b50\u5b57\u7b26\u4e32\u662f\u4e24\u4e2a 'a' \u4e4b\u95f4\u7684\u7a7a\u5b50\u5b57\u7b26\u4e32\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1as = \"abca\"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6700\u4f18\u7684\u5b50\u5b57\u7b26\u4e32\u662f \"bc\" \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1as = \"cbzxy\"\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1as \u4e2d\u4e0d\u5b58\u5728\u51fa\u73b0\u51fa\u73b0\u4e24\u6b21\u7684\u5b57\u7b26\uff0c\u6240\u4ee5\u8fd4\u56de -1 \u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1as = \"cabbac\"\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u6700\u4f18\u7684\u5b50\u5b57\u7b26\u4e32\u662f \"abba\" \uff0c\u5176\u4ed6\u7684\u975e\u6700\u4f18\u89e3\u5305\u62ec \"bb\" \u548c \"\" \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length <= 300
  • \n\t
  • s \u53ea\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxLengthBetweenEqualCharacters(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxLengthBetweenEqualCharacters(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxLengthBetweenEqualCharacters(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxLengthBetweenEqualCharacters(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxLengthBetweenEqualCharacters(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxLengthBetweenEqualCharacters(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar maxLengthBetweenEqualCharacters = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef max_length_between_equal_characters(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxLengthBetweenEqualCharacters(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxLengthBetweenEqualCharacters(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxLengthBetweenEqualCharacters(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxLengthBetweenEqualCharacters(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_length_between_equal_characters(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function maxLengthBetweenEqualCharacters($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxLengthBetweenEqualCharacters(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-length-between-equal-characters s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1624](https://leetcode-cn.com/problems/largest-substring-between-two-equal-characters)", "[\u4e24\u4e2a\u76f8\u540c\u5b57\u7b26\u4e4b\u95f4\u7684\u6700\u957f\u5b50\u5b57\u7b26\u4e32](/solution/1600-1699/1624.Largest%20Substring%20Between%20Two%20Equal%20Characters/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1624](https://leetcode.com/problems/largest-substring-between-two-equal-characters)", "[Largest Substring Between Two Equal Characters](/solution/1600-1699/1624.Largest%20Substring%20Between%20Two%20Equal%20Characters/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1745", "frontend_question_id": "1602", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/find-nearest-right-node-in-binary-tree", "url_en": "https://leetcode.com/problems/find-nearest-right-node-in-binary-tree", "relative_path_cn": "/solution/1600-1699/1602.Find%20Nearest%20Right%20Node%20in%20Binary%20Tree/README.md", "relative_path_en": "/solution/1600-1699/1602.Find%20Nearest%20Right%20Node%20in%20Binary%20Tree/README_EN.md", "title_cn": "\u627e\u5230\u4e8c\u53c9\u6811\u4e2d\u6700\u8fd1\u7684\u53f3\u4fa7\u8282\u70b9", "title_en": "Find Nearest Right Node in Binary Tree", "question_title_slug": "find-nearest-right-node-in-binary-tree", "content_en": "

Given the root of a binary tree and a node u in the tree, return the nearest node on the same level that is to the right of u, or return null if u is the rightmost node in its level.

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: root = [1,2,3,null,4,5,6], u = 4\nOutput: 5\nExplanation: The nearest node on the same level to the right of node 4 is node 5.\n
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: root = [3,null,4,2], u = 2\nOutput: null\nExplanation: There are no nodes to the right of 2.\n
\n\n

Example 3:

\n\n
\nInput: root = [1], u = 1\nOutput: null\n
\n\n

Example 4:

\n\n
\nInput: root = [3,4,2,null,null,null,1], u = 4\nOutput: 2\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The number of nodes in the tree is in the range [1, 105].
  • \n\t
  • 1 <= Node.val <= 105
  • \n\t
  • All values in the tree are distinct.
  • \n\t
  • u is a node in the binary tree rooted at root.
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u68f5\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9\u00a0root\u00a0\u548c\u6811\u4e2d\u7684\u4e00\u4e2a\u8282\u70b9\u00a0u\u00a0\uff0c\u8fd4\u56de\u4e0e\u00a0u\u00a0\u6240\u5728\u5c42\u4e2d\u8ddd\u79bb\u6700\u8fd1\u7684\u53f3\u4fa7\u8282\u70b9\uff0c\u5f53\u00a0u\u00a0\u662f\u6240\u5728\u5c42\u4e2d\u6700\u53f3\u4fa7\u7684\u8282\u70b9\uff0c\u8fd4\u56de\u00a0null\u00a0\u3002

\n\n

\u793a\u4f8b 1:

\n\n

\"\"

\n\n
\u8f93\u5165: root = [1,2,3,null,4,5,6], u = 4\n\u8f93\u51fa: 5\n\u89e3\u91ca: \u8282\u70b9 4 \u6240\u5728\u5c42\u4e2d\uff0c\u6700\u8fd1\u7684\u53f3\u4fa7\u8282\u70b9\u662f\u8282\u70b9 5\u3002\n
\n\n

\u793a\u4f8b 2:

\n\n

\"\"

\n\n
\u8f93\u5165: root = [3,null,4,2], u = 2\n\u8f93\u51fa: null\n\u89e3\u91ca: 2 \u7684\u53f3\u4fa7\u6ca1\u6709\u8282\u70b9\u3002\n
\n\n

\u793a\u4f8b 3:

\n\n
\u8f93\u5165: root = [1], u = 1\n\u8f93\u51fa: null\n
\n\n

\u793a\u4f8b 4:

\n\n
\u8f93\u5165: root = [3,4,2,null,null,null,1], u = 4\n\u8f93\u51fa: 2\n
\n\n

\u00a0

\n\n

\u63d0\u793a:

\n\n
    \n\t
  • \u6811\u4e2d\u8282\u70b9\u4e2a\u6570\u7684\u8303\u56f4\u662f\u00a0[1, 105]\u00a0\u3002
  • \n\t
  • 1 <= Node.val <= 105
  • \n\t
  • \u6811\u4e2d\u6240\u6709\u8282\u70b9\u7684\u503c\u662f\u552f\u4e00\u7684\u3002
  • \n\t
  • u\u00a0\u662f\u4ee5\u00a0root\u00a0\u4e3a\u6839\u7684\u4e8c\u53c9\u6811\u7684\u4e00\u4e2a\u8282\u70b9\u3002
  • \n
\n", "tags_en": ["Tree", "Breadth-first Search"], "tags_cn": ["\u6811", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* findNearestRightNode(TreeNode* root, TreeNode* u) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode findNearestRightNode(TreeNode root, TreeNode u) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def findNearestRightNode(self, root, u):\n \"\"\"\n :type root: TreeNode\n :type u: TreeNode\n :rtype: TreeNode\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def findNearestRightNode(self, root: TreeNode, u: TreeNode) -> TreeNode:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* findNearestRightNode(struct TreeNode* root, struct TreeNode* u){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode FindNearestRightNode(TreeNode root, TreeNode u) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {TreeNode} u\n * @return {TreeNode}\n */\nvar findNearestRightNode = function(root, u) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @param {TreeNode} u\n# @return {TreeNode}\ndef find_nearest_right_node(root, u)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func findNearestRightNode(_ root: TreeNode?, _ u: TreeNode?) -> TreeNode? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc findNearestRightNode(root *TreeNode, u *TreeNode) *TreeNode {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def findNearestRightNode(root: TreeNode, u: TreeNode): TreeNode = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun findNearestRightNode(root: TreeNode?, u: TreeNode?): TreeNode? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param TreeNode $u\n * @return TreeNode\n */\n function findNearestRightNode($root, $u) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {TreeNode} u\n * @return {TreeNode}\n */\nfunction findNearestRightNode(root: TreeNode, u: TreeNode): TreeNode | null {\n \n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1602](https://leetcode-cn.com/problems/find-nearest-right-node-in-binary-tree)", "[\u627e\u5230\u4e8c\u53c9\u6811\u4e2d\u6700\u8fd1\u7684\u53f3\u4fa7\u8282\u70b9](/solution/1600-1699/1602.Find%20Nearest%20Right%20Node%20in%20Binary%20Tree/README.md)", "`\u6811`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1602](https://leetcode.com/problems/find-nearest-right-node-in-binary-tree)", "[Find Nearest Right Node in Binary Tree](/solution/1600-1699/1602.Find%20Nearest%20Right%20Node%20in%20Binary%20Tree/README_EN.md)", "`Tree`,`Breadth-first Search`", "Medium", "\ud83d\udd12"]}, {"question_id": "1744", "frontend_question_id": "1639", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-ways-to-form-a-target-string-given-a-dictionary", "url_en": "https://leetcode.com/problems/number-of-ways-to-form-a-target-string-given-a-dictionary", "relative_path_cn": "/solution/1600-1699/1639.Number%20of%20Ways%20to%20Form%20a%20Target%20String%20Given%20a%20Dictionary/README.md", "relative_path_en": "/solution/1600-1699/1639.Number%20of%20Ways%20to%20Form%20a%20Target%20String%20Given%20a%20Dictionary/README_EN.md", "title_cn": "\u901a\u8fc7\u7ed9\u5b9a\u8bcd\u5178\u6784\u9020\u76ee\u6807\u5b57\u7b26\u4e32\u7684\u65b9\u6848\u6570", "title_en": "Number of Ways to Form a Target String Given a Dictionary", "question_title_slug": "number-of-ways-to-form-a-target-string-given-a-dictionary", "content_en": "

You are given a list of strings of the same length words and a string target.

\n\n

Your task is to form target using the given words under the following rules:

\n\n
    \n\t
  • target should be formed from left to right.
  • \n\t
  • To form the ith character (0-indexed) of target, you can choose the kth character of the jth string in words if target[i] = words[j][k].
  • \n\t
  • Once you use the kth character of the jth string of words, you can no longer use the xth character of any string in words where x <= k. In other words, all characters to the left of or at index k become unusuable for every string.
  • \n\t
  • Repeat the process until you form the string target.
  • \n
\n\n

Notice that you can use multiple characters from the same string in words provided the conditions above are met.

\n\n

Return the number of ways to form target from words. Since the answer may be too large, return it modulo 109 + 7.

\n\n

 

\n

Example 1:

\n\n
\nInput: words = ["acca","bbbb","caca"], target = "aba"\nOutput: 6\nExplanation: There are 6 ways to form target.\n"aba" -> index 0 ("acca"), index 1 ("bbbb"), index 3 ("caca")\n"aba" -> index 0 ("acca"), index 2 ("bbbb"), index 3 ("caca")\n"aba" -> index 0 ("acca"), index 1 ("bbbb"), index 3 ("acca")\n"aba" -> index 0 ("acca"), index 2 ("bbbb"), index 3 ("acca")\n"aba" -> index 1 ("caca"), index 2 ("bbbb"), index 3 ("acca")\n"aba" -> index 1 ("caca"), index 2 ("bbbb"), index 3 ("caca")\n
\n\n

Example 2:

\n\n
\nInput: words = ["abba","baab"], target = "bab"\nOutput: 4\nExplanation: There are 4 ways to form target.\n"bab" -> index 0 ("baab"), index 1 ("baab"), index 2 ("abba")\n"bab" -> index 0 ("baab"), index 1 ("baab"), index 3 ("baab")\n"bab" -> index 0 ("baab"), index 2 ("baab"), index 3 ("baab")\n"bab" -> index 1 ("abba"), index 2 ("baab"), index 3 ("baab")\n
\n\n

Example 3:

\n\n
\nInput: words = ["abcd"], target = "abcd"\nOutput: 1\n
\n\n

Example 4:

\n\n
\nInput: words = ["abab","baba","abba","baab"], target = "abba"\nOutput: 16\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= words.length <= 1000
  • \n\t
  • 1 <= words[i].length <= 1000
  • \n\t
  • All strings in words have the same length.
  • \n\t
  • 1 <= target.length <= 1000
  • \n\t
  • words[i] and target contain only lowercase English letters.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32\u5217\u8868 words\u00a0\u548c\u4e00\u4e2a\u76ee\u6807\u5b57\u7b26\u4e32\u00a0target \u3002words \u4e2d\u6240\u6709\u5b57\u7b26\u4e32\u90fd\u00a0\u957f\u5ea6\u76f8\u540c\u00a0\u00a0\u3002

\n\n

\u4f60\u7684\u76ee\u6807\u662f\u4f7f\u7528\u7ed9\u5b9a\u7684 words\u00a0\u5b57\u7b26\u4e32\u5217\u8868\u6309\u7167\u4e0b\u8ff0\u89c4\u5219\u6784\u9020\u00a0target\u00a0\uff1a

\n\n
    \n\t
  • \u4ece\u5de6\u5230\u53f3\u4f9d\u6b21\u6784\u9020\u00a0target\u00a0\u7684\u6bcf\u4e00\u4e2a\u5b57\u7b26\u3002
  • \n\t
  • \u4e3a\u4e86\u5f97\u5230\u00a0target \u7b2c\u00a0i\u00a0\u4e2a\u5b57\u7b26\uff08\u4e0b\u6807\u4ece 0\u00a0\u5f00\u59cb\uff09\uff0c\u5f53\u00a0target[i] = words[j][k]\u00a0\u65f6\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u00a0words\u00a0\u5217\u8868\u4e2d\u7b2c j\u00a0\u4e2a\u5b57\u7b26\u4e32\u7684\u7b2c k\u00a0\u4e2a\u5b57\u7b26\u3002
  • \n\t
  • \u4e00\u65e6\u4f60\u4f7f\u7528\u4e86 words\u00a0\u4e2d\u7b2c j\u00a0\u4e2a\u5b57\u7b26\u4e32\u7684\u7b2c k\u00a0\u4e2a\u5b57\u7b26\uff0c\u4f60\u4e0d\u80fd\u518d\u4f7f\u7528 words\u00a0\u5b57\u7b26\u4e32\u5217\u8868\u4e2d\u4efb\u610f\u5355\u8bcd\u7684\u7b2c x\u00a0\u4e2a\u5b57\u7b26\uff08x <= k\uff09\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u6240\u6709\u5355\u8bcd\u4e0b\u6807\u5c0f\u4e8e\u7b49\u4e8e k\u00a0\u7684\u5b57\u7b26\u90fd\u4e0d\u80fd\u518d\u88ab\u4f7f\u7528\u3002
  • \n\t
  • \u8bf7\u4f60\u91cd\u590d\u6b64\u8fc7\u7a0b\u76f4\u5230\u5f97\u5230\u76ee\u6807\u5b57\u7b26\u4e32\u00a0target\u00a0\u3002
  • \n
\n\n

\u8bf7\u6ce8\u610f\uff0c \u5728\u6784\u9020\u76ee\u6807\u5b57\u7b26\u4e32\u7684\u8fc7\u7a0b\u4e2d\uff0c\u4f60\u53ef\u4ee5\u6309\u7167\u4e0a\u8ff0\u89c4\u5b9a\u4f7f\u7528 words\u00a0\u5217\u8868\u4e2d \u540c\u4e00\u4e2a\u5b57\u7b26\u4e32\u00a0\u7684 \u591a\u4e2a\u5b57\u7b26\u00a0\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u4f7f\u7528 words\u00a0\u6784\u9020 target\u00a0\u7684\u65b9\u6848\u6570\u3002\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u4f1a\u5f88\u5927\uff0c\u8bf7\u5bf9 109 + 7\u00a0\u53d6\u4f59\u00a0\u540e\u8fd4\u56de\u3002

\n\n

\uff08\u8bd1\u8005\u6ce8\uff1a\u6b64\u9898\u76ee\u6c42\u7684\u662f\u6709\u591a\u5c11\u4e2a\u4e0d\u540c\u7684 k\u00a0\u5e8f\u5217\uff0c\u8be6\u60c5\u8bf7\u89c1\u793a\u4f8b\u3002\uff09

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1awords = [\"acca\",\"bbbb\",\"caca\"], target = \"aba\"\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u603b\u5171\u6709 6 \u79cd\u65b9\u6cd5\u6784\u9020\u76ee\u6807\u4e32\u3002\n\"aba\" -> \u4e0b\u6807\u4e3a 0 (\"acca\")\uff0c\u4e0b\u6807\u4e3a 1 (\"bbbb\")\uff0c\u4e0b\u6807\u4e3a 3 (\"caca\")\n\"aba\" -> \u4e0b\u6807\u4e3a 0 (\"acca\")\uff0c\u4e0b\u6807\u4e3a 2 (\"bbbb\")\uff0c\u4e0b\u6807\u4e3a 3 (\"caca\")\n\"aba\" -> \u4e0b\u6807\u4e3a 0 (\"acca\")\uff0c\u4e0b\u6807\u4e3a 1 (\"bbbb\")\uff0c\u4e0b\u6807\u4e3a 3 (\"acca\")\n\"aba\" -> \u4e0b\u6807\u4e3a 0 (\"acca\")\uff0c\u4e0b\u6807\u4e3a 2 (\"bbbb\")\uff0c\u4e0b\u6807\u4e3a 3 (\"acca\")\n\"aba\" -> \u4e0b\u6807\u4e3a 1 (\"caca\")\uff0c\u4e0b\u6807\u4e3a 2 (\"bbbb\")\uff0c\u4e0b\u6807\u4e3a 3 (\"acca\")\n\"aba\" -> \u4e0b\u6807\u4e3a 1 (\"caca\")\uff0c\u4e0b\u6807\u4e3a 2 (\"bbbb\")\uff0c\u4e0b\u6807\u4e3a 3 (\"caca\")\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1awords = [\"abba\",\"baab\"], target = \"bab\"\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u603b\u5171\u6709 4 \u79cd\u4e0d\u540c\u5f62\u6210 target \u7684\u65b9\u6cd5\u3002\n\"bab\" -> \u4e0b\u6807\u4e3a 0 (\"baab\")\uff0c\u4e0b\u6807\u4e3a 1 (\"baab\")\uff0c\u4e0b\u6807\u4e3a 2 (\"abba\")\n\"bab\" -> \u4e0b\u6807\u4e3a 0 (\"baab\")\uff0c\u4e0b\u6807\u4e3a 1 (\"baab\")\uff0c\u4e0b\u6807\u4e3a 3 (\"baab\")\n\"bab\" -> \u4e0b\u6807\u4e3a 0 (\"baab\")\uff0c\u4e0b\u6807\u4e3a 2 (\"baab\")\uff0c\u4e0b\u6807\u4e3a 3 (\"baab\")\n\"bab\" -> \u4e0b\u6807\u4e3a 1 (\"abba\")\uff0c\u4e0b\u6807\u4e3a 2 (\"baab\")\uff0c\u4e0b\u6807\u4e3a 3 (\"baab\")\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1awords = [\"abcd\"], target = \"abcd\"\n\u8f93\u51fa\uff1a1\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1awords = [\"abab\",\"baba\",\"abba\",\"baab\"], target = \"abba\"\n\u8f93\u51fa\uff1a16\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= words.length <= 1000
  • \n\t
  • 1 <= words[i].length <= 1000
  • \n\t
  • words\u00a0\u4e2d\u6240\u6709\u5355\u8bcd\u957f\u5ea6\u76f8\u540c\u3002
  • \n\t
  • 1 <= target.length <= 1000
  • \n\t
  • words[i]\u00a0\u548c\u00a0target\u00a0\u90fd\u4ec5\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numWays(vector& words, string target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numWays(String[] words, String target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numWays(self, words, target):\n \"\"\"\n :type words: List[str]\n :type target: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numWays(self, words: List[str], target: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numWays(char ** words, int wordsSize, char * target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumWays(string[] words, string target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @param {string} target\n * @return {number}\n */\nvar numWays = function(words, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @param {String} target\n# @return {Integer}\ndef num_ways(words, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numWays(_ words: [String], _ target: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numWays(words []string, target string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numWays(words: Array[String], target: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numWays(words: Array, target: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_ways(words: Vec, target: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @param String $target\n * @return Integer\n */\n function numWays($words, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numWays(words: string[], target: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-ways words target)\n (-> (listof string?) string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1639](https://leetcode-cn.com/problems/number-of-ways-to-form-a-target-string-given-a-dictionary)", "[\u901a\u8fc7\u7ed9\u5b9a\u8bcd\u5178\u6784\u9020\u76ee\u6807\u5b57\u7b26\u4e32\u7684\u65b9\u6848\u6570](/solution/1600-1699/1639.Number%20of%20Ways%20to%20Form%20a%20Target%20String%20Given%20a%20Dictionary/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1639](https://leetcode.com/problems/number-of-ways-to-form-a-target-string-given-a-dictionary)", "[Number of Ways to Form a Target String Given a Dictionary](/solution/1600-1699/1639.Number%20of%20Ways%20to%20Form%20a%20Target%20String%20Given%20a%20Dictionary/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1743", "frontend_question_id": "1638", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-substrings-that-differ-by-one-character", "url_en": "https://leetcode.com/problems/count-substrings-that-differ-by-one-character", "relative_path_cn": "/solution/1600-1699/1638.Count%20Substrings%20That%20Differ%20by%20One%20Character/README.md", "relative_path_en": "/solution/1600-1699/1638.Count%20Substrings%20That%20Differ%20by%20One%20Character/README_EN.md", "title_cn": "\u7edf\u8ba1\u53ea\u5dee\u4e00\u4e2a\u5b57\u7b26\u7684\u5b50\u4e32\u6570\u76ee", "title_en": "Count Substrings That Differ by One Character", "question_title_slug": "count-substrings-that-differ-by-one-character", "content_en": "

Given two strings s and t, find the number of ways you can choose a non-empty substring of s and replace a single character by a different character such that the resulting substring is a substring of t. In other words, find the number of substrings in s that differ from some substring in t by exactly one character.

\n\n

For example, the underlined substrings in "computer" and "computation" only differ by the 'e'/'a', so this is a valid way.

\n\n

Return the number of substrings that satisfy the condition above.

\n\n

A substring is a contiguous sequence of characters within a string.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "aba", t = "baba"\nOutput: 6\nExplanation: The following are the pairs of substrings from s and t that differ by exactly 1 character:\n("aba", "baba")\n("aba", "baba")\n("aba", "baba")\n("aba", "baba")\n("aba", "baba")\n("aba", "baba")\nThe underlined portions are the substrings that are chosen from s and t.\n
\n\u200b\u200bExample 2:\n\n
\nInput: s = "ab", t = "bb"\nOutput: 3\nExplanation: The following are the pairs of substrings from s and t that differ by 1 character:\n("ab", "bb")\n("ab", "bb")\n("ab", "bb")\n\u200b\u200b\u200b\u200bThe underlined portions are the substrings that are chosen from s and t.\n
\nExample 3:\n\n
\nInput: s = "a", t = "a"\nOutput: 0\n
\n\n

Example 4:

\n\n
\nInput: s = "abe", t = "bbc"\nOutput: 10\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length, t.length <= 100
  • \n\t
  • s and t consist of lowercase English letters only.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e24\u4e2a\u5b57\u7b26\u4e32\u00a0s \u548c\u00a0t\u00a0\uff0c\u8bf7\u4f60\u627e\u51fa s\u00a0\u4e2d\u7684\u975e\u7a7a\u5b50\u4e32\u7684\u6570\u76ee\uff0c\u8fd9\u4e9b\u5b50\u4e32\u6ee1\u8db3\u66ff\u6362 \u4e00\u4e2a\u4e0d\u540c\u5b57\u7b26\u00a0\u4ee5\u540e\uff0c\u662f t\u00a0\u4e32\u7684\u5b50\u4e32\u3002\u6362\u8a00\u4e4b\uff0c\u8bf7\u4f60\u627e\u5230 s\u00a0\u548c t\u00a0\u4e32\u4e2d \u6070\u597d\u00a0\u53ea\u6709\u4e00\u4e2a\u5b57\u7b26\u4e0d\u540c\u7684\u5b50\u5b57\u7b26\u4e32\u5bf9\u7684\u6570\u76ee\u3002

\n\n

\u6bd4\u65b9\u8bf4\uff0c\u00a0\"computer\" \u548c\u00a0\"computation\" \u52a0\u7c97\u90e8\u5206\u53ea\u6709\u4e00\u4e2a\u5b57\u7b26\u4e0d\u540c\uff1a\u00a0'e'/'a'\u00a0\uff0c\u6240\u4ee5\u8fd9\u4e00\u5bf9\u5b50\u5b57\u7b26\u4e32\u4f1a\u7ed9\u7b54\u6848\u52a0 1 \u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u6ee1\u8db3\u4e0a\u8ff0\u6761\u4ef6\u7684\u4e0d\u540c\u5b50\u5b57\u7b26\u4e32\u5bf9\u6570\u76ee\u3002

\n\n

\u4e00\u4e2a \u5b50\u5b57\u7b26\u4e32\u00a0\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\u4e2d\u8fde\u7eed\u7684\u5b57\u7b26\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"aba\", t = \"baba\"\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u4ee5\u4e0b\u4e3a\u53ea\u76f8\u5dee 1 \u4e2a\u5b57\u7b26\u7684 s \u548c t \u4e32\u7684\u5b50\u5b57\u7b26\u4e32\u5bf9\uff1a\n(\"aba\", \"baba\")\n(\"aba\", \"baba\")\n(\"aba\", \"baba\")\n(\"aba\", \"baba\")\n(\"aba\", \"baba\")\n(\"aba\", \"baba\")\n\u52a0\u7c97\u90e8\u5206\u5206\u522b\u8868\u793a s \u548c t \u4e32\u9009\u51fa\u6765\u7684\u5b50\u5b57\u7b26\u4e32\u3002\n
\n\u793a\u4f8b 2\uff1a\n\n
\n\u8f93\u5165\uff1as = \"ab\", t = \"bb\"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u4ee5\u4e0b\u4e3a\u53ea\u76f8\u5dee 1 \u4e2a\u5b57\u7b26\u7684 s \u548c t \u4e32\u7684\u5b50\u5b57\u7b26\u4e32\u5bf9\uff1a\n(\"ab\", \"bb\")\n(\"ab\", \"bb\")\n(\"ab\", \"bb\")\n\u52a0\u7c97\u90e8\u5206\u5206\u522b\u8868\u793a s \u548c t \u4e32\u9009\u51fa\u6765\u7684\u5b50\u5b57\u7b26\u4e32\u3002\n
\n\u793a\u4f8b 3\uff1a\n\n
\n\u8f93\u5165\uff1as = \"a\", t = \"a\"\n\u8f93\u51fa\uff1a0\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"abe\", t = \"bbc\"\n\u8f93\u51fa\uff1a10\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length, t.length <= 100
  • \n\t
  • s \u548c\u00a0t\u00a0\u90fd\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
  • \n
\n", "tags_en": ["Trie", "Hash Table", "String"], "tags_cn": ["\u5b57\u5178\u6811", "\u54c8\u5e0c\u8868", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countSubstrings(string s, string t) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countSubstrings(String s, String t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countSubstrings(self, s, t):\n \"\"\"\n :type s: str\n :type t: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countSubstrings(self, s: str, t: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countSubstrings(char * s, char * t){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountSubstrings(string s, string t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string} t\n * @return {number}\n */\nvar countSubstrings = function(s, t) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String} t\n# @return {Integer}\ndef count_substrings(s, t)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countSubstrings(_ s: String, _ t: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countSubstrings(s string, t string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countSubstrings(s: String, t: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countSubstrings(s: String, t: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_substrings(s: String, t: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String $t\n * @return Integer\n */\n function countSubstrings($s, $t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countSubstrings(s: string, t: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-substrings s t)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1638](https://leetcode-cn.com/problems/count-substrings-that-differ-by-one-character)", "[\u7edf\u8ba1\u53ea\u5dee\u4e00\u4e2a\u5b57\u7b26\u7684\u5b50\u4e32\u6570\u76ee](/solution/1600-1699/1638.Count%20Substrings%20That%20Differ%20by%20One%20Character/README.md)", "`\u5b57\u5178\u6811`,`\u54c8\u5e0c\u8868`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1638](https://leetcode.com/problems/count-substrings-that-differ-by-one-character)", "[Count Substrings That Differ by One Character](/solution/1600-1699/1638.Count%20Substrings%20That%20Differ%20by%20One%20Character/README_EN.md)", "`Trie`,`Hash Table`,`String`", "Medium", ""]}, {"question_id": "1742", "frontend_question_id": "1637", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/widest-vertical-area-between-two-points-containing-no-points", "url_en": "https://leetcode.com/problems/widest-vertical-area-between-two-points-containing-no-points", "relative_path_cn": "/solution/1600-1699/1637.Widest%20Vertical%20Area%20Between%20Two%20Points%20Containing%20No%20Points/README.md", "relative_path_en": "/solution/1600-1699/1637.Widest%20Vertical%20Area%20Between%20Two%20Points%20Containing%20No%20Points/README_EN.md", "title_cn": "\u4e24\u70b9\u4e4b\u95f4\u4e0d\u5305\u542b\u4efb\u4f55\u70b9\u7684\u6700\u5bbd\u5782\u76f4\u9762\u79ef", "title_en": "Widest Vertical Area Between Two Points Containing No Points", "question_title_slug": "widest-vertical-area-between-two-points-containing-no-points", "content_en": "

Given n points on a 2D plane where points[i] = [xi, yi], Return the widest vertical area between two points such that no points are inside the area.

\n\n

A vertical area is an area of fixed-width extending infinitely along the y-axis (i.e., infinite height). The widest vertical area is the one with the maximum width.

\n\n

Note that points on the edge of a vertical area are not considered included in the area.

\n\n

 

\n

Example 1:

\n\"\"\u200b\n
\nInput: points = [[8,7],[9,9],[7,4],[9,7]]\nOutput: 1\nExplanation: Both the red and the blue area are optimal.\n
\n\n

Example 2:

\n\n
\nInput: points = [[3,1],[9,0],[1,0],[1,4],[5,3],[8,8]]\nOutput: 3\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == points.length
  • \n\t
  • 2 <= n <= 105
  • \n\t
  • points[i].length == 2
  • \n\t
  • 0 <= xi, yi <= 109
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u00a0n\u00a0\u4e2a\u4e8c\u7ef4\u5e73\u9762\u4e0a\u7684\u70b9 points \uff0c\u5176\u4e2d\u00a0points[i] = [xi, yi]\u00a0\uff0c\u8bf7\u4f60\u8fd4\u56de\u4e24\u70b9\u4e4b\u95f4\u5185\u90e8\u4e0d\u5305\u542b\u4efb\u4f55\u70b9\u7684\u00a0\u6700\u5bbd\u5782\u76f4\u9762\u79ef\u00a0\u7684\u5bbd\u5ea6\u3002

\n\n

\u5782\u76f4\u9762\u79ef \u7684\u5b9a\u4e49\u662f\u56fa\u5b9a\u5bbd\u5ea6\uff0c\u800c y \u8f74\u4e0a\u65e0\u9650\u5ef6\u4f38\u7684\u4e00\u5757\u533a\u57df\uff08\u4e5f\u5c31\u662f\u9ad8\u5ea6\u4e3a\u65e0\u7a77\u5927\uff09\u3002 \u6700\u5bbd\u5782\u76f4\u9762\u79ef\u00a0\u4e3a\u5bbd\u5ea6\u6700\u5927\u7684\u4e00\u4e2a\u5782\u76f4\u9762\u79ef\u3002

\n\n

\u8bf7\u6ce8\u610f\uff0c\u5782\u76f4\u533a\u57df\u00a0\u8fb9\u4e0a\u00a0\u7684\u70b9\u00a0\u4e0d\u5728\u00a0\u533a\u57df\u5185\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\"\"\u200b\n
\n\u8f93\u5165\uff1apoints = [[8,7],[9,9],[7,4],[9,7]]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u7ea2\u8272\u533a\u57df\u548c\u84dd\u8272\u533a\u57df\u90fd\u662f\u6700\u4f18\u533a\u57df\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1apoints = [[3,1],[9,0],[1,0],[1,4],[5,3],[8,8]]\n\u8f93\u51fa\uff1a3\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • n == points.length
  • \n\t
  • 2 <= n <= 105
  • \n\t
  • points[i].length == 2
  • \n\t
  • 0 <= xi, yi\u00a0<= 109
  • \n
\n", "tags_en": ["Sort"], "tags_cn": ["\u6392\u5e8f"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxWidthOfVerticalArea(vector>& points) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxWidthOfVerticalArea(int[][] points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxWidthOfVerticalArea(self, points):\n \"\"\"\n :type points: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxWidthOfVerticalArea(int** points, int pointsSize, int* pointsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxWidthOfVerticalArea(int[][] points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} points\n * @return {number}\n */\nvar maxWidthOfVerticalArea = function(points) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} points\n# @return {Integer}\ndef max_width_of_vertical_area(points)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxWidthOfVerticalArea(_ points: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxWidthOfVerticalArea(points [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxWidthOfVerticalArea(points: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxWidthOfVerticalArea(points: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_width_of_vertical_area(points: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $points\n * @return Integer\n */\n function maxWidthOfVerticalArea($points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxWidthOfVerticalArea(points: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-width-of-vertical-area points)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1637](https://leetcode-cn.com/problems/widest-vertical-area-between-two-points-containing-no-points)", "[\u4e24\u70b9\u4e4b\u95f4\u4e0d\u5305\u542b\u4efb\u4f55\u70b9\u7684\u6700\u5bbd\u5782\u76f4\u9762\u79ef](/solution/1600-1699/1637.Widest%20Vertical%20Area%20Between%20Two%20Points%20Containing%20No%20Points/README.md)", "`\u6392\u5e8f`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1637](https://leetcode.com/problems/widest-vertical-area-between-two-points-containing-no-points)", "[Widest Vertical Area Between Two Points Containing No Points](/solution/1600-1699/1637.Widest%20Vertical%20Area%20Between%20Two%20Points%20Containing%20No%20Points/README_EN.md)", "`Sort`", "Medium", ""]}, {"question_id": "1741", "frontend_question_id": "1636", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sort-array-by-increasing-frequency", "url_en": "https://leetcode.com/problems/sort-array-by-increasing-frequency", "relative_path_cn": "/solution/1600-1699/1636.Sort%20Array%20by%20Increasing%20Frequency/README.md", "relative_path_en": "/solution/1600-1699/1636.Sort%20Array%20by%20Increasing%20Frequency/README_EN.md", "title_cn": "\u6309\u7167\u9891\u7387\u5c06\u6570\u7ec4\u5347\u5e8f\u6392\u5e8f", "title_en": "Sort Array by Increasing Frequency", "question_title_slug": "sort-array-by-increasing-frequency", "content_en": "

Given an array of integers nums, sort the array in increasing order based on the frequency of the values. If multiple values have the same frequency, sort them in decreasing order.

\n\n

Return the sorted array.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [1,1,2,2,2,3]\nOutput: [3,1,1,2,2,2]\nExplanation: '3' has a frequency of 1, '1' has a frequency of 2, and '2' has a frequency of 3.\n
\n\n

Example 2:

\n\n
\nInput: nums = [2,3,1,3,2]\nOutput: [1,3,3,2,2]\nExplanation: '2' and '3' both have a frequency of 2, so they are sorted in decreasing order.\n
\n\n

Example 3:

\n\n
\nInput: nums = [-1,1,-6,4,5,-6,1,4,1]\nOutput: [5,-1,4,4,-6,-6,1,1,1]
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 100
  • \n\t
  • -100 <= nums[i] <= 100
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0nums\u00a0\uff0c\u8bf7\u4f60\u5c06\u6570\u7ec4\u6309\u7167\u6bcf\u4e2a\u503c\u7684\u9891\u7387 \u5347\u5e8f \u6392\u5e8f\u3002\u5982\u679c\u6709\u591a\u4e2a\u503c\u7684\u9891\u7387\u76f8\u540c\uff0c\u8bf7\u4f60\u6309\u7167\u6570\u503c\u672c\u8eab\u5c06\u5b83\u4eec \u964d\u5e8f \u6392\u5e8f\u3002\u00a0

\n\n

\u8bf7\u4f60\u8fd4\u56de\u6392\u5e8f\u540e\u7684\u6570\u7ec4\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,1,2,2,2,3]\n\u8f93\u51fa\uff1a[3,1,1,2,2,2]\n\u89e3\u91ca\uff1a'3' \u9891\u7387\u4e3a 1\uff0c'1' \u9891\u7387\u4e3a 2\uff0c'2' \u9891\u7387\u4e3a 3 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anums = [2,3,1,3,2]\n\u8f93\u51fa\uff1a[1,3,3,2,2]\n\u89e3\u91ca\uff1a'2' \u548c '3' \u9891\u7387\u90fd\u4e3a 2 \uff0c\u6240\u4ee5\u5b83\u4eec\u4e4b\u95f4\u6309\u7167\u6570\u503c\u672c\u8eab\u964d\u5e8f\u6392\u5e8f\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1anums = [-1,1,-6,4,5,-6,1,4,1]\n\u8f93\u51fa\uff1a[5,-1,4,4,-6,-6,1,1,1]
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 100
  • \n\t
  • -100 <= nums[i] <= 100
  • \n
\n", "tags_en": ["Sort", "Array"], "tags_cn": ["\u6392\u5e8f", "\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector frequencySort(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] frequencySort(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def frequencySort(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def frequencySort(self, nums: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* frequencySort(int* nums, int numsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] FrequencySort(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar frequencySort = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer[]}\ndef frequency_sort(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func frequencySort(_ nums: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func frequencySort(nums []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def frequencySort(nums: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun frequencySort(nums: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn frequency_sort(nums: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer[]\n */\n function frequencySort($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function frequencySort(nums: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (frequency-sort nums)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1636](https://leetcode-cn.com/problems/sort-array-by-increasing-frequency)", "[\u6309\u7167\u9891\u7387\u5c06\u6570\u7ec4\u5347\u5e8f\u6392\u5e8f](/solution/1600-1699/1636.Sort%20Array%20by%20Increasing%20Frequency/README.md)", "`\u6392\u5e8f`,`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1636](https://leetcode.com/problems/sort-array-by-increasing-frequency)", "[Sort Array by Increasing Frequency](/solution/1600-1699/1636.Sort%20Array%20by%20Increasing%20Frequency/README_EN.md)", "`Sort`,`Array`", "Easy", ""]}, {"question_id": "1740", "frontend_question_id": "1617", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-subtrees-with-max-distance-between-cities", "url_en": "https://leetcode.com/problems/count-subtrees-with-max-distance-between-cities", "relative_path_cn": "/solution/1600-1699/1617.Count%20Subtrees%20With%20Max%20Distance%20Between%20Cities/README.md", "relative_path_en": "/solution/1600-1699/1617.Count%20Subtrees%20With%20Max%20Distance%20Between%20Cities/README_EN.md", "title_cn": "\u7edf\u8ba1\u5b50\u6811\u4e2d\u57ce\u5e02\u4e4b\u95f4\u6700\u5927\u8ddd\u79bb", "title_en": "Count Subtrees With Max Distance Between Cities", "question_title_slug": "count-subtrees-with-max-distance-between-cities", "content_en": "

There are n cities numbered from 1 to n. You are given an array edges of size n-1, where edges[i] = [ui, vi] represents a bidirectional edge between cities ui and vi. There exists a unique path between each pair of cities. In other words, the cities form a tree.

\r\n\r\n

A subtree is a subset of cities where every city is reachable from every other city in the subset, where the path between each pair passes through only the cities from the subset. Two subtrees are different if there is a city in one subtree that is not present in the other.

\r\n\r\n

For each d from 1 to n-1, find the number of subtrees in which the maximum distance between any two cities in the subtree is equal to d.

\r\n\r\n

Return an array of size n-1 where the dth element (1-indexed) is the number of subtrees in which the maximum distance between any two cities is equal to d.

\r\n\r\n

Notice that the distance between the two cities is the number of edges in the path between them.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n

\"\"

\r\n\r\n
\r\nInput: n = 4, edges = [[1,2],[2,3],[2,4]]\r\nOutput: [3,4,0]\r\nExplanation:\r\nThe subtrees with subsets {1,2}, {2,3} and {2,4} have a max distance of 1.\r\nThe subtrees with subsets {1,2,3}, {1,2,4}, {2,3,4} and {1,2,3,4} have a max distance of 2.\r\nNo subtree has two nodes where the max distance between them is 3.\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: n = 2, edges = [[1,2]]\r\nOutput: [1]\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: n = 3, edges = [[1,2],[2,3]]\r\nOutput: [2,1]\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 2 <= n <= 15
  • \r\n\t
  • edges.length == n-1
  • \r\n\t
  • edges[i].length == 2
  • \r\n\t
  • 1 <= ui, vi <= n
  • \r\n\t
  • All pairs (ui, vi) are distinct.
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u00a0n\u00a0\u4e2a\u57ce\u5e02\uff0c\u7f16\u53f7\u4e3a\u4ece\u00a01 \u5230\u00a0n\u00a0\u3002\u540c\u65f6\u7ed9\u4f60\u4e00\u4e2a\u5927\u5c0f\u4e3a\u00a0n-1\u00a0\u7684\u6570\u7ec4\u00a0edges\u00a0\uff0c\u5176\u4e2d\u00a0edges[i] = [ui, vi]\u00a0\u8868\u793a\u57ce\u5e02\u00a0ui\u00a0\u548c\u00a0vi\u00a0\u4e4b\u95f4\u6709\u4e00\u6761\u53cc\u5411\u8fb9\u3002\u9898\u76ee\u4fdd\u8bc1\u4efb\u610f\u57ce\u5e02\u4e4b\u95f4\u53ea\u6709\u552f\u4e00\u7684\u4e00\u6761\u8def\u5f84\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u6240\u6709\u57ce\u5e02\u5f62\u6210\u4e86\u4e00\u68f5\u00a0\u6811\u00a0\u3002

\n\n

\u4e00\u68f5\u00a0\u5b50\u6811\u00a0\u662f\u57ce\u5e02\u7684\u4e00\u4e2a\u5b50\u96c6\uff0c\u4e14\u5b50\u96c6\u4e2d\u4efb\u610f\u57ce\u5e02\u4e4b\u95f4\u53ef\u4ee5\u901a\u8fc7\u5b50\u96c6\u4e2d\u7684\u5176\u4ed6\u57ce\u5e02\u548c\u8fb9\u5230\u8fbe\u3002\u4e24\u4e2a\u5b50\u6811\u88ab\u8ba4\u4e3a\u4e0d\u4e00\u6837\u7684\u6761\u4ef6\u662f\u81f3\u5c11\u6709\u4e00\u4e2a\u57ce\u5e02\u5728\u5176\u4e2d\u4e00\u68f5\u5b50\u6811\u4e2d\u5b58\u5728\uff0c\u4f46\u5728\u53e6\u4e00\u68f5\u5b50\u6811\u4e2d\u4e0d\u5b58\u5728\u3002

\n\n

\u5bf9\u4e8e\u00a0d\u00a0\u4ece\u00a01 \u5230\u00a0n-1\u00a0\uff0c\u8bf7\u4f60\u627e\u5230\u57ce\u5e02\u95f4\u00a0\u6700\u5927\u8ddd\u79bb\u00a0\u6070\u597d\u4e3a d\u00a0\u7684\u6240\u6709\u5b50\u6811\u6570\u76ee\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u4e00\u4e2a\u5927\u5c0f\u4e3a\u00a0n-1\u00a0\u7684\u6570\u7ec4\uff0c\u5176\u4e2d\u7b2c\u00a0d\u00a0\u4e2a\u5143\u7d20\uff08\u4e0b\u6807\u4ece 1 \u5f00\u59cb\uff09\u662f\u57ce\u5e02\u95f4 \u6700\u5927\u8ddd\u79bb \u6070\u597d\u7b49\u4e8e\u00a0d\u00a0\u7684\u5b50\u6811\u6570\u76ee\u3002

\n\n

\u8bf7\u6ce8\u610f\uff0c\u4e24\u4e2a\u57ce\u5e02\u95f4\u8ddd\u79bb\u5b9a\u4e49\u4e3a\u5b83\u4eec\u4e4b\u95f4\u9700\u8981\u7ecf\u8fc7\u7684\u8fb9\u7684\u6570\u76ee\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1an = 4, edges = [[1,2],[2,3],[2,4]]\n\u8f93\u51fa\uff1a[3,4,0]\n\u89e3\u91ca\uff1a\n\u5b50\u6811 {1,2}, {2,3} \u548c {2,4} \u6700\u5927\u8ddd\u79bb\u90fd\u662f 1 \u3002\n\u5b50\u6811 {1,2,3}, {1,2,4}, {2,3,4} \u548c {1,2,3,4} \u6700\u5927\u8ddd\u79bb\u90fd\u4e3a 2 \u3002\n\u4e0d\u5b58\u5728\u57ce\u5e02\u95f4\u6700\u5927\u8ddd\u79bb\u4e3a 3 \u7684\u5b50\u6811\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1an = 2, edges = [[1,2]]\n\u8f93\u51fa\uff1a[1]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1an = 3, edges = [[1,2],[2,3]]\n\u8f93\u51fa\uff1a[2,1]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= n <= 15
  • \n\t
  • edges.length == n-1
  • \n\t
  • edges[i].length == 2
  • \n\t
  • 1 <= ui, vi <= n
  • \n\t
  • \u9898\u76ee\u4fdd\u8bc1\u00a0(ui, vi)\u00a0\u6240\u8868\u793a\u7684\u8fb9\u4e92\u4e0d\u76f8\u540c\u3002
  • \n
\n", "tags_en": ["Backtracking"], "tags_cn": ["\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector countSubgraphsForEachDiameter(int n, vector>& edges) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] countSubgraphsForEachDiameter(int n, int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countSubgraphsForEachDiameter(self, n, edges):\n \"\"\"\n :type n: int\n :type edges: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countSubgraphsForEachDiameter(self, n: int, edges: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* countSubgraphsForEachDiameter(int n, int** edges, int edgesSize, int* edgesColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] CountSubgraphsForEachDiameter(int n, int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} edges\n * @return {number[]}\n */\nvar countSubgraphsForEachDiameter = function(n, edges) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} edges\n# @return {Integer[]}\ndef count_subgraphs_for_each_diameter(n, edges)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countSubgraphsForEachDiameter(_ n: Int, _ edges: [[Int]]) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countSubgraphsForEachDiameter(n int, edges [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countSubgraphsForEachDiameter(n: Int, edges: Array[Array[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countSubgraphsForEachDiameter(n: Int, edges: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_subgraphs_for_each_diameter(n: i32, edges: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $edges\n * @return Integer[]\n */\n function countSubgraphsForEachDiameter($n, $edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countSubgraphsForEachDiameter(n: number, edges: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-subgraphs-for-each-diameter n edges)\n (-> exact-integer? (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1617](https://leetcode-cn.com/problems/count-subtrees-with-max-distance-between-cities)", "[\u7edf\u8ba1\u5b50\u6811\u4e2d\u57ce\u5e02\u4e4b\u95f4\u6700\u5927\u8ddd\u79bb](/solution/1600-1699/1617.Count%20Subtrees%20With%20Max%20Distance%20Between%20Cities/README.md)", "`\u56de\u6eaf\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[1617](https://leetcode.com/problems/count-subtrees-with-max-distance-between-cities)", "[Count Subtrees With Max Distance Between Cities](/solution/1600-1699/1617.Count%20Subtrees%20With%20Max%20Distance%20Between%20Cities/README_EN.md)", "`Backtracking`", "Hard", ""]}, {"question_id": "1739", "frontend_question_id": "1616", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/split-two-strings-to-make-palindrome", "url_en": "https://leetcode.com/problems/split-two-strings-to-make-palindrome", "relative_path_cn": "/solution/1600-1699/1616.Split%20Two%20Strings%20to%20Make%20Palindrome/README.md", "relative_path_en": "/solution/1600-1699/1616.Split%20Two%20Strings%20to%20Make%20Palindrome/README_EN.md", "title_cn": "\u5206\u5272\u4e24\u4e2a\u5b57\u7b26\u4e32\u5f97\u5230\u56de\u6587\u4e32", "title_en": "Split Two Strings to Make Palindrome", "question_title_slug": "split-two-strings-to-make-palindrome", "content_en": "

You are given two strings a and b of the same length. Choose an index and split both strings at the same index, splitting a into two strings: aprefix and asuffix where a = aprefix + asuffix, and splitting b into two strings: bprefix and bsuffix where b = bprefix + bsuffix. Check if aprefix + bsuffix or bprefix + asuffix forms a palindrome.

\n\n

When you split a string s into sprefix and ssuffix, either ssuffix or sprefix is allowed to be empty. For example, if s = "abc", then "" + "abc", "a" + "bc", "ab" + "c" , and "abc" + "" are valid splits.

\n\n

Return true if it is possible to form a palindrome string, otherwise return false.

\n\n

Notice that x + y denotes the concatenation of strings x and y.

\n\n

 

\n

Example 1:

\n\n
\nInput: a = "x", b = "y"\nOutput: true\nExplaination: If either a or b are palindromes the answer is true since you can split in the following way:\naprefix = "", asuffix = "x"\nbprefix = "", bsuffix = "y"\nThen, aprefix + bsuffix = "" + "y" = "y", which is a palindrome.\n
\n\n

Example 2:

\n\n
\nInput: a = "abdef", b = "fecab"\nOutput: true\n
\n\n

Example 3:

\n\n
\nInput: a = "ulacfd", b = "jizalu"\nOutput: true\nExplaination: Split them at index 3:\naprefix = "ula", asuffix = "cfd"\nbprefix = "jiz", bsuffix = "alu"\nThen, aprefix + bsuffix = "ula" + "alu" = "ulaalu", which is a palindrome.\n
\n\n

Example 4:

\n\n
\nInput: a = "xbdef", b = "xecab"\nOutput: false\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= a.length, b.length <= 105
  • \n\t
  • a.length == b.length
  • \n\t
  • a and b consist of lowercase English letters
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e24\u4e2a\u5b57\u7b26\u4e32\u00a0a \u548c\u00a0b\u00a0\uff0c\u5b83\u4eec\u957f\u5ea6\u76f8\u540c\u3002\u8bf7\u4f60\u9009\u62e9\u4e00\u4e2a\u4e0b\u6807\uff0c\u5c06\u4e24\u4e2a\u5b57\u7b26\u4e32\u90fd\u5728\u00a0\u76f8\u540c\u7684\u4e0b\u6807 \u5206\u5272\u5f00\u3002\u7531\u00a0a\u00a0\u53ef\u4ee5\u5f97\u5230\u4e24\u4e2a\u5b57\u7b26\u4e32\uff1a\u00a0aprefix\u00a0\u548c\u00a0asuffix\u00a0\uff0c\u6ee1\u8db3\u00a0a = aprefix + asuffix\u00a0\uff0c\u540c\u7406\uff0c\u7531\u00a0b \u53ef\u4ee5\u5f97\u5230\u4e24\u4e2a\u5b57\u7b26\u4e32\u00a0bprefix \u548c\u00a0bsuffix\u00a0\uff0c\u6ee1\u8db3\u00a0b = bprefix + bsuffix\u00a0\u3002\u8bf7\u4f60\u5224\u65ad\u00a0aprefix + bsuffix \u6216\u8005\u00a0bprefix + asuffix\u00a0\u80fd\u5426\u6784\u6210\u56de\u6587\u4e32\u3002

\n\n

\u5f53\u4f60\u5c06\u4e00\u4e2a\u5b57\u7b26\u4e32\u00a0s\u00a0\u5206\u5272\u6210\u00a0sprefix \u548c\u00a0ssuffix\u00a0\u65f6\uff0c\u00a0ssuffix \u6216\u8005\u00a0sprefix \u53ef\u4ee5\u4e3a\u7a7a\u3002\u6bd4\u65b9\u8bf4\uff0c\u00a0s = \"abc\"\u00a0\u90a3\u4e48\u00a0\"\" + \"abc\"\u00a0\uff0c\u00a0\"a\" + \"bc\"\u00a0\uff0c\u00a0\"ab\" + \"c\"\u00a0\u548c\u00a0\"abc\" + \"\"\u00a0\u90fd\u662f\u5408\u6cd5\u5206\u5272\u3002

\n\n

\u5982\u679c \u80fd\u6784\u6210\u56de\u6587\u5b57\u7b26\u4e32 \uff0c\u90a3\u4e48\u8bf7\u8fd4\u56de\u00a0true\uff0c\u5426\u5219\u8fd4\u56de\u00a0false\u00a0\u3002

\n\n

\u6ce8\u610f\uff0c\u00a0x + y\u00a0\u8868\u793a\u8fde\u63a5\u5b57\u7b26\u4e32\u00a0x \u548c\u00a0y\u00a0\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aa = \"x\", b = \"y\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u5982\u679c a \u6216\u8005 b \u662f\u56de\u6587\u4e32\uff0c\u90a3\u4e48\u7b54\u6848\u4e00\u5b9a\u4e3a true \uff0c\u56e0\u4e3a\u4f60\u53ef\u4ee5\u5982\u4e0b\u5206\u5272\uff1a\naprefix = \"\", asuffix = \"x\"\nbprefix = \"\", bsuffix = \"y\"\n\u90a3\u4e48 aprefix + bsuffix = \"\" + \"y\" = \"y\" \u662f\u56de\u6587\u4e32\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aa = \"abdef\", b = \"fecab\"\n\u8f93\u51fa\uff1atrue\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1aa = \"ulacfd\", b = \"jizalu\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u5728\u4e0b\u6807\u4e3a 3 \u5904\u5206\u5272\uff1a\naprefix = \"ula\", asuffix = \"cfd\"\nbprefix = \"jiz\", bsuffix = \"alu\"\n\u90a3\u4e48 aprefix + bsuffix = \"ula\" + \"alu\" = \"ulaalu\" \u662f\u56de\u6587\u4e32\u3002
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1aa = \"xbdef\", b = \"xecab\"\n\u8f93\u51fa\uff1afalse\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= a.length, b.length <= 105
  • \n\t
  • a.length == b.length
  • \n\t
  • a \u548c\u00a0b\u00a0\u90fd\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd
  • \n
\n", "tags_en": ["Greedy", "Two Pointers", "String"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u53cc\u6307\u9488", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool checkPalindromeFormation(string a, string b) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean checkPalindromeFormation(String a, String b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def checkPalindromeFormation(self, a, b):\n \"\"\"\n :type a: str\n :type b: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def checkPalindromeFormation(self, a: str, b: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool checkPalindromeFormation(char * a, char * b){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CheckPalindromeFormation(string a, string b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} a\n * @param {string} b\n * @return {boolean}\n */\nvar checkPalindromeFormation = function(a, b) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} a\n# @param {String} b\n# @return {Boolean}\ndef check_palindrome_formation(a, b)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func checkPalindromeFormation(_ a: String, _ b: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func checkPalindromeFormation(a string, b string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def checkPalindromeFormation(a: String, b: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun checkPalindromeFormation(a: String, b: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn check_palindrome_formation(a: String, b: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $a\n * @param String $b\n * @return Boolean\n */\n function checkPalindromeFormation($a, $b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function checkPalindromeFormation(a: string, b: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (check-palindrome-formation a b)\n (-> string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1616](https://leetcode-cn.com/problems/split-two-strings-to-make-palindrome)", "[\u5206\u5272\u4e24\u4e2a\u5b57\u7b26\u4e32\u5f97\u5230\u56de\u6587\u4e32](/solution/1600-1699/1616.Split%20Two%20Strings%20to%20Make%20Palindrome/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u53cc\u6307\u9488`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1616](https://leetcode.com/problems/split-two-strings-to-make-palindrome)", "[Split Two Strings to Make Palindrome](/solution/1600-1699/1616.Split%20Two%20Strings%20to%20Make%20Palindrome/README_EN.md)", "`Greedy`,`Two Pointers`,`String`", "Medium", ""]}, {"question_id": "1738", "frontend_question_id": "1615", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximal-network-rank", "url_en": "https://leetcode.com/problems/maximal-network-rank", "relative_path_cn": "/solution/1600-1699/1615.Maximal%20Network%20Rank/README.md", "relative_path_en": "/solution/1600-1699/1615.Maximal%20Network%20Rank/README_EN.md", "title_cn": "\u6700\u5927\u7f51\u7edc\u79e9", "title_en": "Maximal Network Rank", "question_title_slug": "maximal-network-rank", "content_en": "

There is an infrastructure of n cities with some number of roads connecting these cities. Each roads[i] = [ai, bi] indicates that there is a bidirectional road between cities ai and bi.

\n\n

The network rank of two different cities is defined as the total number of directly connected roads to either city. If a road is directly connected to both cities, it is only counted once.

\n\n

The maximal network rank of the infrastructure is the maximum network rank of all pairs of different cities.

\n\n

Given the integer n and the array roads, return the maximal network rank of the entire infrastructure.

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: n = 4, roads = [[0,1],[0,3],[1,2],[1,3]]\nOutput: 4\nExplanation: The network rank of cities 0 and 1 is 4 as there are 4 roads that are connected to either 0 or 1. The road between 0 and 1 is only counted once.\n
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: n = 5, roads = [[0,1],[0,3],[1,2],[1,3],[2,3],[2,4]]\nOutput: 5\nExplanation: There are 5 roads that are connected to cities 1 or 2.\n
\n\n

Example 3:

\n\n
\nInput: n = 8, roads = [[0,1],[1,2],[2,3],[2,4],[5,6],[5,7]]\nOutput: 5\nExplanation: The network rank of 2 and 5 is 5. Notice that all the cities do not have to be connected.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= n <= 100
  • \n\t
  • 0 <= roads.length <= n * (n - 1) / 2
  • \n\t
  • roads[i].length == 2
  • \n\t
  • 0 <= ai, bi <= n-1
  • \n\t
  • ai != bi
  • \n\t
  • Each pair of cities has at most one road connecting them.
  • \n
\n", "content_cn": "

n \u5ea7\u57ce\u5e02\u548c\u4e00\u4e9b\u8fde\u63a5\u8fd9\u4e9b\u57ce\u5e02\u7684\u9053\u8def roads \u5171\u540c\u7ec4\u6210\u4e00\u4e2a\u57fa\u7840\u8bbe\u65bd\u7f51\u7edc\u3002\u6bcf\u4e2a roads[i] = [ai, bi] \u90fd\u8868\u793a\u5728\u57ce\u5e02 ai \u548c bi \u4e4b\u95f4\u6709\u4e00\u6761\u53cc\u5411\u9053\u8def\u3002

\n\n

\u4e24\u5ea7\u4e0d\u540c\u57ce\u5e02\u6784\u6210\u7684 \u57ce\u5e02\u5bf9 \u7684 \u7f51\u7edc\u79e9 \u5b9a\u4e49\u4e3a\uff1a\u4e0e\u8fd9\u4e24\u5ea7\u57ce\u5e02 \u76f4\u63a5 \u76f8\u8fde\u7684\u9053\u8def\u603b\u6570\u3002\u5982\u679c\u5b58\u5728\u4e00\u6761\u9053\u8def\u76f4\u63a5\u8fde\u63a5\u8fd9\u4e24\u5ea7\u57ce\u5e02\uff0c\u5219\u8fd9\u6761\u9053\u8def\u53ea\u8ba1\u7b97 \u4e00\u6b21 \u3002

\n\n

\u6574\u4e2a\u57fa\u7840\u8bbe\u65bd\u7f51\u7edc\u7684 \u6700\u5927\u7f51\u7edc\u79e9 \u662f\u6240\u6709\u4e0d\u540c\u57ce\u5e02\u5bf9\u4e2d\u7684 \u6700\u5927\u7f51\u7edc\u79e9 \u3002

\n\n

\u7ed9\u4f60\u6574\u6570 n \u548c\u6570\u7ec4 roads\uff0c\u8fd4\u56de\u6574\u4e2a\u57fa\u7840\u8bbe\u65bd\u7f51\u7edc\u7684 \u6700\u5927\u7f51\u7edc\u79e9 \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1an = 4, roads = [[0,1],[0,3],[1,2],[1,3]]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u57ce\u5e02 0 \u548c 1 \u7684\u7f51\u7edc\u79e9\u662f 4\uff0c\u56e0\u4e3a\u5171\u6709 4 \u6761\u9053\u8def\u4e0e\u57ce\u5e02 0 \u6216 1 \u76f8\u8fde\u3002\u4f4d\u4e8e 0 \u548c 1 \u4e4b\u95f4\u7684\u9053\u8def\u53ea\u8ba1\u7b97\u4e00\u6b21\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1an = 5, roads = [[0,1],[0,3],[1,2],[1,3],[2,3],[2,4]]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u5171\u6709 5 \u6761\u9053\u8def\u4e0e\u57ce\u5e02 1 \u6216 2 \u76f8\u8fde\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1an = 8, roads = [[0,1],[1,2],[2,3],[2,4],[5,6],[5,7]]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a2 \u548c 5 \u7684\u7f51\u7edc\u79e9\u4e3a 5\uff0c\u6ce8\u610f\u5e76\u975e\u6240\u6709\u7684\u57ce\u5e02\u90fd\u9700\u8981\u8fde\u63a5\u8d77\u6765\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= n <= 100
  • \n\t
  • 0 <= roads.length <= n * (n - 1) / 2
  • \n\t
  • roads[i].length == 2
  • \n\t
  • 0 <= ai, bi\u00a0<= n-1
  • \n\t
  • ai\u00a0!=\u00a0bi
  • \n\t
  • \u6bcf\u5bf9\u57ce\u5e02\u4e4b\u95f4 \u6700\u591a\u53ea\u6709\u4e00\u6761\u00a0\u9053\u8def\u76f8\u8fde
  • \n
\n", "tags_en": ["Graph"], "tags_cn": ["\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maximalNetworkRank(int n, vector>& roads) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maximalNetworkRank(int n, int[][] roads) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximalNetworkRank(self, n, roads):\n \"\"\"\n :type n: int\n :type roads: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximalNetworkRank(self, n: int, roads: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maximalNetworkRank(int n, int** roads, int roadsSize, int* roadsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaximalNetworkRank(int n, int[][] roads) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} roads\n * @return {number}\n */\nvar maximalNetworkRank = function(n, roads) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} roads\n# @return {Integer}\ndef maximal_network_rank(n, roads)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximalNetworkRank(_ n: Int, _ roads: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximalNetworkRank(n int, roads [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximalNetworkRank(n: Int, roads: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximalNetworkRank(n: Int, roads: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximal_network_rank(n: i32, roads: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $roads\n * @return Integer\n */\n function maximalNetworkRank($n, $roads) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximalNetworkRank(n: number, roads: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximal-network-rank n roads)\n (-> exact-integer? (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1615](https://leetcode-cn.com/problems/maximal-network-rank)", "[\u6700\u5927\u7f51\u7edc\u79e9](/solution/1600-1699/1615.Maximal%20Network%20Rank/README.md)", "`\u56fe`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1615](https://leetcode.com/problems/maximal-network-rank)", "[Maximal Network Rank](/solution/1600-1699/1615.Maximal%20Network%20Rank/README_EN.md)", "`Graph`", "Medium", ""]}, {"question_id": "1737", "frontend_question_id": "1614", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-nesting-depth-of-the-parentheses", "url_en": "https://leetcode.com/problems/maximum-nesting-depth-of-the-parentheses", "relative_path_cn": "/solution/1600-1699/1614.Maximum%20Nesting%20Depth%20of%20the%20Parentheses/README.md", "relative_path_en": "/solution/1600-1699/1614.Maximum%20Nesting%20Depth%20of%20the%20Parentheses/README_EN.md", "title_cn": "\u62ec\u53f7\u7684\u6700\u5927\u5d4c\u5957\u6df1\u5ea6", "title_en": "Maximum Nesting Depth of the Parentheses", "question_title_slug": "maximum-nesting-depth-of-the-parentheses", "content_en": "

A string is a valid parentheses string (denoted VPS) if it meets one of the following:

\n\n
    \n\t
  • It is an empty string "", or a single character not equal to "(" or ")",
  • \n\t
  • It can be written as AB (A concatenated with B), where A and B are VPS's, or
  • \n\t
  • It can be written as (A), where A is a VPS.
  • \n
\n\n

We can similarly define the nesting depth depth(S) of any VPS S as follows:

\n\n
    \n\t
  • depth("") = 0
  • \n\t
  • depth(C) = 0, where C is a string with a single character not equal to "(" or ")".
  • \n\t
  • depth(A + B) = max(depth(A), depth(B)), where A and B are VPS's.
  • \n\t
  • depth("(" + A + ")") = 1 + depth(A), where A is a VPS.
  • \n
\n\n

For example, "", "()()", and "()(()())" are VPS's (with nesting depths 0, 1, and 2), and ")(" and "(()" are not VPS's.

\n\n

Given a VPS represented as string s, return the nesting depth of s.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "(1+(2*3)+((8)/4))+1"\nOutput: 3\nExplanation: Digit 8 is inside of 3 nested parentheses in the string.\n
\n\n

Example 2:

\n\n
\nInput: s = "(1)+((2))+(((3)))"\nOutput: 3\n
\n\n

Example 3:

\n\n
\nInput: s = "1+(2*3)/(2-1)"\nOutput: 1\n
\n\n

Example 4:

\n\n
\nInput: s = "1"\nOutput: 0\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 100
  • \n\t
  • s consists of digits 0-9 and characters '+', '-', '*', '/', '(', and ')'.
  • \n\t
  • It is guaranteed that parentheses expression s is a VPS.
  • \n
\n", "content_cn": "

\u5982\u679c\u5b57\u7b26\u4e32\u6ee1\u8db3\u4ee5\u4e0b\u6761\u4ef6\u4e4b\u4e00\uff0c\u5219\u53ef\u4ee5\u79f0\u4e4b\u4e3a \u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32\uff08valid parentheses string\uff0c\u53ef\u4ee5\u7b80\u5199\u4e3a VPS\uff09\uff1a

\n\n
    \n\t
  • \u5b57\u7b26\u4e32\u662f\u4e00\u4e2a\u7a7a\u5b57\u7b26\u4e32 \"\"\uff0c\u6216\u8005\u662f\u4e00\u4e2a\u4e0d\u4e3a \"(\" \u6216 \")\" \u7684\u5355\u5b57\u7b26\u3002
  • \n\t
  • \u5b57\u7b26\u4e32\u53ef\u4ee5\u5199\u4e3a AB\uff08A \u4e0e B\u00a0\u5b57\u7b26\u4e32\u8fde\u63a5\uff09\uff0c\u5176\u4e2d A \u548c B \u90fd\u662f \u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32 \u3002
  • \n\t
  • \u5b57\u7b26\u4e32\u53ef\u4ee5\u5199\u4e3a (A)\uff0c\u5176\u4e2d A \u662f\u4e00\u4e2a \u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32 \u3002
  • \n
\n\n

\u7c7b\u4f3c\u5730\uff0c\u53ef\u4ee5\u5b9a\u4e49\u4efb\u4f55\u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32\u00a0S \u7684 \u5d4c\u5957\u6df1\u5ea6 depth(S)\uff1a

\n\n
    \n\t
  • depth(\"\") = 0
  • \n\t
  • depth(C) = 0\uff0c\u5176\u4e2d C \u662f\u5355\u4e2a\u5b57\u7b26\u7684\u5b57\u7b26\u4e32\uff0c\u4e14\u8be5\u5b57\u7b26\u4e0d\u662f \"(\" \u6216\u8005 \")\"
  • \n\t
  • depth(A + B) = max(depth(A), depth(B))\uff0c\u5176\u4e2d A \u548c B \u90fd\u662f \u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32
  • \n\t
  • depth(\"(\" + A + \")\") = 1 + depth(A)\uff0c\u5176\u4e2d A \u662f\u4e00\u4e2a \u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32
  • \n
\n\n

\u4f8b\u5982\uff1a\"\"\u3001\"()()\"\u3001\"()(()())\" \u90fd\u662f \u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32\uff08\u5d4c\u5957\u6df1\u5ea6\u5206\u522b\u4e3a 0\u30011\u30012\uff09\uff0c\u800c \")(\" \u3001\"(()\" \u90fd\u4e0d\u662f \u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32 \u3002

\n\n

\u7ed9\u4f60\u4e00\u4e2a \u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32 s\uff0c\u8fd4\u56de\u8be5\u5b57\u7b26\u4e32\u7684 s \u5d4c\u5957\u6df1\u5ea6 \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"(1+(2*3)+((8)/4))+1\"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6570\u5b57 8 \u5728\u5d4c\u5957\u7684 3 \u5c42\u62ec\u53f7\u4e2d\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"(1)+((2))+(((3)))\"\n\u8f93\u51fa\uff1a3\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"1+(2*3)/(2-1)\"\n\u8f93\u51fa\uff1a1\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"1\"\n\u8f93\u51fa\uff1a0\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length <= 100
  • \n\t
  • s \u7531\u6570\u5b57 0-9 \u548c\u5b57\u7b26 '+'\u3001'-'\u3001'*'\u3001'/'\u3001'('\u3001')' \u7ec4\u6210
  • \n\t
  • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u62ec\u53f7\u8868\u8fbe\u5f0f s \u662f \u6709\u6548\u7684\u62ec\u53f7\u8868\u8fbe\u5f0f
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxDepth(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxDepth(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxDepth(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxDepth(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxDepth(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxDepth(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar maxDepth = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef max_depth(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxDepth(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxDepth(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxDepth(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxDepth(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_depth(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function maxDepth($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxDepth(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-depth s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1614](https://leetcode-cn.com/problems/maximum-nesting-depth-of-the-parentheses)", "[\u62ec\u53f7\u7684\u6700\u5927\u5d4c\u5957\u6df1\u5ea6](/solution/1600-1699/1614.Maximum%20Nesting%20Depth%20of%20the%20Parentheses/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1614](https://leetcode.com/problems/maximum-nesting-depth-of-the-parentheses)", "[Maximum Nesting Depth of the Parentheses](/solution/1600-1699/1614.Maximum%20Nesting%20Depth%20of%20the%20Parentheses/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1736", "frontend_question_id": "1597", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/build-binary-expression-tree-from-infix-expression", "url_en": "https://leetcode.com/problems/build-binary-expression-tree-from-infix-expression", "relative_path_cn": "/solution/1500-1599/1597.Build%20Binary%20Expression%20Tree%20From%20Infix%20Expression/README.md", "relative_path_en": "/solution/1500-1599/1597.Build%20Binary%20Expression%20Tree%20From%20Infix%20Expression/README_EN.md", "title_cn": "\u6839\u636e\u4e2d\u7f00\u8868\u8fbe\u5f0f\u6784\u9020\u4e8c\u53c9\u8868\u8fbe\u5f0f\u6811", "title_en": "Build Binary Expression Tree From Infix Expression", "question_title_slug": "build-binary-expression-tree-from-infix-expression", "content_en": "

A binary expression tree is a kind of binary tree used to represent arithmetic expressions. Each node of a binary expression tree has either zero or two children. Leaf nodes (nodes with 0 children) correspond to operands (numbers), and internal nodes (nodes with 2 children) correspond to the operators '+' (addition), '-' (subtraction), '*' (multiplication), and '/' (division).

\n\n

For each internal node with operator o, the infix expression that it represents is (A o B), where A is the expression the left subtree represents and B is the expression the right subtree represents.

\n\n

You are given a string s, an infix expression containing operands, the operators described above, and parentheses '(' and ')'.

\n\n

Return any valid binary expression tree, which its in-order traversal reproduces s after omitting the parenthesis from it (see examples below).

\n\n

Please note that order of operations applies in s. That is, expressions in parentheses are evaluated first, and multiplication and division happen before addition and subtraction.

\n\n

Operands must also appear in the same order in both s and the in-order traversal of the tree.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: s = "3*4-2*5"\nOutput: [-,*,*,3,4,2,5]\nExplanation: The tree above is the only valid tree whose inorder traversal produces s.\n
\n\n

Example 2:

\n\"\"\n
\nInput: s = "2-3/(5*2)+1"\nOutput: [+,-,1,2,/,null,null,null,null,3,*,null,null,5,2]\nExplanation: The inorder traversal of the tree above is 2-3/5*2+1 which is the same as s without the parenthesis. The tree also produces the correct result and its operands are in the same order as they appear in s.\nThe tree below is also a valid binary expression tree with the same inorder traversal as s, but it not a valid answer because it does not evaluate to the same value.\n\"\"\nThe third tree below is also not valid. Although it produces the same result and is equivalent to the above trees, its inorder traversal does not produce s and its operands are not in the same order as s.\n\"\"\n
\n\n

Example 3:

\n\n
\nInput: s = "1+2+3+4+5"\nOutput: [+,+,5,+,4,null,null,+,3,null,null,1,2]\nExplanation: The tree [+,+,5,+,+,null,null,1,2,3,4] is also one of many other valid trees.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 1000
  • \n\t
  • s consists of digits and the characters '+', '-', '*', and '/'.
  • \n\t
  • Operands in s are exactly 1 digit.
  • \n\t
  • It is guaranteed that s is a valid expression.
  • \n
\n", "content_cn": "

\u4e8c\u53c9\u8868\u8fbe\u5f0f\u6811 \u662f\u4e00\u79cd\u8868\u8fbe\u7b97\u672f\u8868\u8fbe\u5f0f\u7684\u4e8c\u53c9\u6811\u3002\u4e8c\u53c9\u8868\u8fbe\u5f0f\u6811\u4e2d\u7684\u6bcf\u4e00\u4e2a\u8282\u70b9\u90fd\u6709\u96f6\u4e2a\u6216\u4e24\u4e2a\u5b50\u8282\u70b9\u3002\u00a0\u53f6\u8282\u70b9\uff08\u6709 0 \u4e2a\u5b50\u8282\u70b9\u7684\u8282\u70b9\uff09\u8868\u793a\u64cd\u4f5c\u6570\uff0c\u975e\u53f6\u8282\u70b9\uff08\u6709 2 \u4e2a\u5b50\u8282\u70b9\u7684\u8282\u70b9\uff09\u8868\u793a\u8fd0\u7b97\u7b26\uff1a\u00a0'+'\u00a0\uff08\u52a0\uff09\u3001\u00a0'-' \uff08\u51cf\uff09\u3001\u00a0'*' \uff08\u4e58\uff09\u548c\u00a0'/' \uff08\u9664\uff09\u3002

\n\n

\u5bf9\u4e8e\u6bcf\u4e00\u4e2a\u8fd0\u7b97\u7b26\u4e3a o \u7684\u975e\u53f6\u8282\u70b9\uff0c\u5bf9\u5e94\u7684 \u4e2d\u7f00\u8868\u8fbe\u5f0f \u4e3a\u00a0(A o B)\uff0c\u5176\u4e2d\u00a0A\u00a0\u662f\u5de6\u5b50\u6811\u6240\u8868\u8fbe\u7684\u8868\u8fbe\u5f0f\uff0c\u00a0B\u00a0\u662f\u53f3\u5b50\u6811\u6240\u8868\u8fbe\u7684\u8868\u8fbe\u5f0f\u3002

\n\n

\u7ed9\u5b9a\u4e00\u4e2a \u4e2d\u7f00\u8868\u8fbe\u5f0f \u5b57\u7b26\u4e32\u00a0s\uff0c\u5176\u4e2d\u5305\u542b\u64cd\u4f5c\u6570\u3001\u4e0a\u9762\u63d0\u5230\u7684\u8fd0\u7b97\u7b26\uff0c\u4ee5\u53ca\u62ec\u53f7\u00a0'('\u00a0\u4e0e\u00a0')'\u00a0\u3002

\n\n

\u8fd4\u56de\u4e00\u4e2a\u6709\u6548\u7684 \u4e8c\u53c9\u8868\u8fbe\u5f0f\u6811\uff0c\u5176 \u4e2d\u5e8f\u904d\u5386 \u5e8f\u5217\u5bf9\u5e94\u8868\u8fbe\u5f0f s \u6d88\u9664\u62ec\u53f7\u540e\u7684\u5e8f\u5217\uff08\u8be6\u60c5\u53c2\u89c1\u4e0b\u9762\u7684\u793a\u4f8b\uff09\u3002

\n\n

\u6ce8\u610f\uff0c\u8868\u8fbe\u5f0f\u7684\u4e00\u822c\u89e3\u6790\u987a\u5e8f\u9002\u7528\u4e8e\u00a0s\uff0c\u5373\u4f18\u5148\u89e3\u6790\u62ec\u53f7\u5185\u7684\u8868\u8fbe\u5f0f\uff0c\u7136\u540e\u89e3\u6790\u4e58\u9664\u6cd5\uff0c\u6700\u540e\u89e3\u6790\u52a0\u51cf\u6cd5\u3002

\n\n

\u540c\u65f6\uff0c\u64cd\u4f5c\u6570\u5728 s \u548c\u6811\u7684\u4e2d\u5e8f\u904d\u5386\u4e2d \u51fa\u73b0\u987a\u5e8f\u76f8\u540c \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1as = \"3*4-2*5\"\n\u8f93\u51fa\uff1a[-,*,*,3,4,2,5]\n\u89e3\u91ca\uff1a\u4e0a\u9762\u662f\u552f\u4e00\u4e00\u79cd\u6709\u6548\u7684\u4e8c\u53c9\u8868\u8fbe\u5f0f\u6811\uff0c\u5176\u4e2d\u5e8f\u904d\u5386\u751f\u6210 s \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1as = \"2-3/(5*2)+1\"\n\u8f93\u51fa\uff1a[+,-,1,2,/,null,null,null,null,3,*,null,null,5,2]\n\u89e3\u91ca\uff1a\u4e0a\u9762\u7684\u6811\u7684\u4e2d\u5e8f\u904d\u5386\u4e3a 2-3/5*2+1 \uff0c\u4e0e s \u6d88\u9664\u62ec\u53f7\u540e\u76f8\u540c\u3002\u8be5\u6811\u8fd8\u4f1a\u751f\u6210\u6b63\u786e\u7684\u7ed3\u679c\uff0c\u5176\u64cd\u4f5c\u6570\u7684\u987a\u5e8f\u4e0e s \u4e2d\u51fa\u73b0\u7684\u987a\u5e8f\u76f8\u540c\u3002\n\u4e0b\u9762\u7684\u6811\u4e5f\u662f\u4e00\u4e2a\u6709\u6548\u7684\u4e8c\u53c9\u8868\u8fbe\u5f0f\u6811\uff0c\u5177\u6709\u4e0e s \u76f8\u540c\u7684\u4e2d\u5e8f\u904d\u5386\uff0c\u4f46\u5b83\u4e0d\u662f\u4e00\u4e2a\u6709\u6548\u7684\u7b54\u6848\uff0c\u56e0\u4e3a\u5b83\u7684\u6c42\u503c\u7ed3\u679c\u4e0d\u540c\u3002\n\"\"\n\u4e0b\u9762\u7684\u6811\u4e5f\u662f\u65e0\u6548\u7684\u3002\u5c3d\u7ba1\u5b83\u7684\u8ba1\u7b97\u7ed3\u679c\u76f8\u7b49\u5e76\u4e0e\u4e0a\u8ff0\u6811\u7b49\u6548\uff0c\u4f46\u5176\u4e2d\u5e8f\u904d\u5386\u4e0d\u4f1a\u4ea7\u751f s \uff0c\u5e76\u4e14\u5176\u64cd\u4f5c\u6570\u4e0e s \u4e2d\u7684\u987a\u5e8f\u4e5f\u4e0d\u76f8\u540c\u3002\n\"\"\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"1+2+3+4+5\"\n\u8f93\u51fa\uff1a[+,+,5,+,4,null,null,+,3,null,null,1,2]\n\u89e3\u91ca\uff1a\u4e8c\u53c9\u6811 [+,+,5,+,+,null,null,1,2,3,4] \u4e5f\u662f\u8bf8\u591a\u6709\u6548\u7684\u4e8c\u53c9\u8868\u8fbe\u5f0f\u6811\u4e4b\u4e00\u3002
\n\n

\u00a0

\n\n

\u63d0\u793a:

\n\n
    \n\t
  • 1 <= s.length <= 105
  • \n\t
  • s\u00a0\u4e2d\u5305\u542b\u6570\u5b57\u548c\u5b57\u7b26\u00a0'+'\u3001\u00a0'-'\u3001\u00a0'*'\u3001\u00a0'/' \u3002
  • \n\t
  • s\u00a0\u4e2d\u7684\u64cd\u4f5c\u6570 \u6070\u597d \u662f\u4e00\u4f4d\u6570\u5b57\u3002
  • \n\t
  • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1 s \u662f\u4e00\u4e2a\u6709\u6548\u7684\u8868\u8fbe\u5f0f\u3002
  • \n
\n", "tags_en": ["Tree", "String"], "tags_cn": ["\u6811", "\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for a binary tree node.\n * struct Node {\n * char val;\n * Node *left;\n * Node *right;\n * Node() : val(' '), left(nullptr), right(nullptr) {}\n * Node(char x) : val(x), left(nullptr), right(nullptr) {}\n * Node(char x, Node *left, Node *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n Node* expTree(string s) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * class Node {\n * char val;\n * Node left;\n * Node right;\n * Node() {this.val = ' ';}\n * Node(char val) { this.val = val; }\n * Node(char val, Node left, Node right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public Node expTree(String s) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class Node(object):\n# def __init__(self, val=\" \", left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def expTree(self, s):\n \"\"\"\n :type s: str\n :rtype: Node\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class Node(object):\n# def __init__(self, val=\" \", left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def expTree(self, s: str) -> 'Node':\n ", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class Node {\n * public char val;\n * public Node left;\n * public Node right;\n * public Node(char val=' ', TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public Node ExpTree(string s) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function Node(val, left, right) {\n * this.val = (val===undefined ? \" \" : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {string} s\n * @return {Node}\n */\nvar expTree = function(s) {\n \n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1597](https://leetcode-cn.com/problems/build-binary-expression-tree-from-infix-expression)", "[\u6839\u636e\u4e2d\u7f00\u8868\u8fbe\u5f0f\u6784\u9020\u4e8c\u53c9\u8868\u8fbe\u5f0f\u6811](/solution/1500-1599/1597.Build%20Binary%20Expression%20Tree%20From%20Infix%20Expression/README.md)", "`\u6811`,`\u5b57\u7b26\u4e32`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1597](https://leetcode.com/problems/build-binary-expression-tree-from-infix-expression)", "[Build Binary Expression Tree From Infix Expression](/solution/1500-1599/1597.Build%20Binary%20Expression%20Tree%20From%20Infix%20Expression/README_EN.md)", "`Tree`,`String`", "Hard", "\ud83d\udd12"]}, {"question_id": "1735", "frontend_question_id": "1596", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/the-most-frequently-ordered-products-for-each-customer", "url_en": "https://leetcode.com/problems/the-most-frequently-ordered-products-for-each-customer", "relative_path_cn": "/solution/1500-1599/1596.The%20Most%20Frequently%20Ordered%20Products%20for%20Each%20Customer/README.md", "relative_path_en": "/solution/1500-1599/1596.The%20Most%20Frequently%20Ordered%20Products%20for%20Each%20Customer/README_EN.md", "title_cn": "\u6bcf\u4f4d\u987e\u5ba2\u6700\u7ecf\u5e38\u8ba2\u8d2d\u7684\u5546\u54c1", "title_en": "The Most Frequently Ordered Products for Each Customer", "question_title_slug": "the-most-frequently-ordered-products-for-each-customer", "content_en": "

Table: Customers

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| customer_id   | int     |\n| name          | varchar |\n+---------------+---------+\ncustomer_id is the primary key for this table.\nThis table contains information about the customers.\n
\n\n

 

\n\n

Table: Orders

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| order_id      | int     |\n| order_date    | date    |\n| customer_id   | int     |\n| product_id    | int     |\n+---------------+---------+\norder_id is the primary key for this table.\nThis table contains information about the orders made by customer_id.\nNo customer will order the same product more than once in a single day.
\n\n

 

\n\n

Table: Products

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| product_id    | int     |\n| product_name  | varchar |\n| price         | int     |\n+---------------+---------+\nproduct_id is the primary key for this table.\nThis table contains information about the products.\n
\n\n

 

\n\n

Write an SQL query to find the most frequently ordered product(s) for each customer.

\n\n

The result table should have the product_id and product_name for each customer_id who ordered at least one order. Return the result table in any order.

\n\n

The query result format is in the following example:

\n\n
\nCustomers\n+-------------+-------+\n| customer_id | name  |\n+-------------+-------+\n| 1           | Alice |\n| 2           | Bob   |\n| 3           | Tom   |\n| 4           | Jerry |\n| 5           | John  |\n+-------------+-------+\n\nOrders\n+----------+------------+-------------+------------+\n| order_id | order_date | customer_id | product_id |\n+----------+------------+-------------+------------+\n| 1        | 2020-07-31 | 1           | 1          |\n| 2        | 2020-07-30 | 2           | 2          |\n| 3        | 2020-08-29 | 3           | 3          |\n| 4        | 2020-07-29 | 4           | 1          |\n| 5        | 2020-06-10 | 1           | 2          |\n| 6        | 2020-08-01 | 2           | 1          |\n| 7        | 2020-08-01 | 3           | 3          |\n| 8        | 2020-08-03 | 1           | 2          |\n| 9        | 2020-08-07 | 2           | 3          |\n| 10       | 2020-07-15 | 1           | 2          |\n+----------+------------+-------------+------------+\n\nProducts\n+------------+--------------+-------+\n| product_id | product_name | price |\n+------------+--------------+-------+\n| 1          | keyboard     | 120   |\n| 2          | mouse        | 80    |\n| 3          | screen       | 600   |\n| 4          | hard disk    | 450   |\n+------------+--------------+-------+\nResult table:\n+-------------+------------+--------------+\n| customer_id | product_id | product_name |\n+-------------+------------+--------------+\n| 1           | 2          | mouse        |\n| 2           | 1          | keyboard     |\n| 2           | 2          | mouse        |\n| 2           | 3          | screen       |\n| 3           | 3          | screen       |\n| 4           | 1          | keyboard     |\n+-------------+------------+--------------+\n\nAlice (customer 1) ordered the mouse three times and the keyboard one time, so the mouse is the most frquently ordered product for them.\nBob (customer 2) ordered the keyboard, the mouse, and the screen one time, so those are the most frquently ordered products for them.\nTom (customer 3) only ordered the screen (two times), so that is the most frquently ordered product for them.\nJerry (customer 4) only ordered the keyboard (one time), so that is the most frquently ordered product for them.\nJohn (customer 5) did not order anything, so we do not include them in the result table.\n
\n", "content_cn": "

\u8868\uff1aCustomers

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| customer_id   | int     |\n| name          | varchar |\n+---------------+---------+\ncustomer_id \u662f\u8be5\u8868\u4e3b\u952e\n\u8be5\u8868\u5305\u542b\u6240\u6709\u987e\u5ba2\u7684\u4fe1\u606f\n
\n\n

\u00a0

\n\n

\u8868\uff1aOrders

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| order_id      | int     |\n| order_date    | date    |\n| customer_id   | int     |\n| product_id    | int     |\n+---------------+---------+\norder_id \u662f\u8be5\u8868\u4e3b\u952e\n\u8be5\u8868\u5305\u542b\u987e\u5ba2 customer_id \u7684\u8ba2\u5355\u4fe1\u606f\n\u6ca1\u6709\u987e\u5ba2\u4f1a\u5728\u4e00\u5929\u5185\u8ba2\u8d2d\u76f8\u540c\u7684\u5546\u54c1 \u591a\u4e8e\u4e00\u6b21
\n\n

\u00a0

\n\n

\u8868\uff1aProducts

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| product_id    | int     |\n| product_name  | varchar |\n| price         | int     |\n+---------------+---------+\nproduct_id \u662f\u8be5\u8868\u4e3b\u952e\n\u8be5\u8868\u5305\u542b\u4e86\u6240\u6709\u5546\u54c1\u7684\u4fe1\u606f\n
\n\n

\u00a0

\n\n

\u5199\u4e00\u4e2a SQL \u8bed\u53e5\uff0c\u627e\u5230\u6bcf\u4e00\u4e2a\u987e\u5ba2\u6700\u7ecf\u5e38\u8ba2\u8d2d\u7684\u5546\u54c1\u3002

\n\n

\u7ed3\u679c\u8868\u5355\u5e94\u8be5\u6709\u6bcf\u4e00\u4f4d\u81f3\u5c11\u4e0b\u8fc7\u4e00\u6b21\u5355\u7684\u987e\u5ba2 customer_id\u00a0,\u00a0\u4ed6\u6700\u7ecf\u5e38\u8ba2\u8d2d\u7684\u5546\u54c1\u7684\u00a0product_id\u00a0\u548c\u00a0product_name\u3002

\n\n

\u8fd4\u56de\u7ed3\u679c \u6ca1\u6709\u987a\u5e8f\u8981\u6c42\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a\uff1a

\n\n
\nCustomers\n+-------------+-------+\n| customer_id | name  |\n+-------------+-------+\n| 1           | Alice |\n| 2           | Bob   |\n| 3           | Tom   |\n| 4           | Jerry |\n| 5           | John  |\n+-------------+-------+\n\nOrders\n+----------+------------+-------------+------------+\n| order_id | order_date | customer_id | product_id |\n+----------+------------+-------------+------------+\n| 1        | 2020-07-31 | 1           | 1          |\n| 2        | 2020-07-30 | 2           | 2          |\n| 3        | 2020-08-29 | 3           | 3          |\n| 4        | 2020-07-29 | 4           | 1          |\n| 5        | 2020-06-10 | 1           | 2          |\n| 6        | 2020-08-01 | 2           | 1          |\n| 7        | 2020-08-01 | 3           | 3          |\n| 8        | 2020-08-03 | 1           | 2          |\n| 9        | 2020-08-07 | 2           | 3          |\n| 10       | 2020-07-15 | 1           | 2          |\n+----------+------------+-------------+------------+\n\nProducts\n+------------+--------------+-------+\n| product_id | product_name | price |\n+------------+--------------+-------+\n| 1          | keyboard     | 120   |\n| 2          | mouse        | 80    |\n| 3          | screen       | 600   |\n| 4          | hard disk    | 450   |\n+------------+--------------+-------+\nResult \u8868\uff1a\n+-------------+------------+--------------+\n| customer_id | product_id | product_name |\n+-------------+------------+--------------+\n| 1           | 2          | mouse        |\n| 2           | 1          | keyboard     |\n| 2           | 2          | mouse        |\n| 2           | 3          | screen       |\n| 3           | 3          | screen       |\n| 4           | 1          | keyboard     |\n+-------------+------------+--------------+\n\nAlice (customer 1) \u4e09\u6b21\u8ba2\u8d2d\u9f20\u6807, \u4e00\u6b21\u8ba2\u8d2d\u952e\u76d8, \u6240\u4ee5\u9f20\u6807\u662f Alice \u6700\u7ecf\u5e38\u8ba2\u8d2d\u7684\u5546\u54c1.\nBob (customer 2) \u4e00\u6b21\u8ba2\u8d2d\u952e\u76d8, \u4e00\u6b21\u8ba2\u8d2d\u9f20\u6807, \u4e00\u6b21\u8ba2\u8d2d\u663e\u793a\u5668, \u6240\u4ee5\u8fd9\u4e9b\u90fd\u662f Bob \u6700\u7ecf\u5e38\u8ba2\u8d2d\u7684\u5546\u54c1.\nTom (customer 3) \u53ea\u4e24\u6b21\u8ba2\u8d2d\u663e\u793a\u5668, \u6240\u4ee5\u663e\u793a\u5668\u662f Tom \u6700\u7ecf\u5e38\u8ba2\u8d2d\u7684\u5546\u54c1.\nJerry (customer 4) \u53ea\u4e00\u6b21\u8ba2\u8d2d\u952e\u76d8, \u6240\u4ee5\u952e\u76d8\u662f Jerry \u6700\u7ecf\u5e38\u8ba2\u8d2d\u7684\u5546\u54c1.\nJohn (customer 5) \u6ca1\u6709\u8ba2\u8d2d\u8fc7\u5546\u54c1, \u6240\u4ee5\u6211\u4eec\u5e76\u6ca1\u6709\u628a John \u5305\u542b\u5728\u7ed3\u679c\u8868\u4e2d.\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1596](https://leetcode-cn.com/problems/the-most-frequently-ordered-products-for-each-customer)", "[\u6bcf\u4f4d\u987e\u5ba2\u6700\u7ecf\u5e38\u8ba2\u8d2d\u7684\u5546\u54c1](/solution/1500-1599/1596.The%20Most%20Frequently%20Ordered%20Products%20for%20Each%20Customer/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1596](https://leetcode.com/problems/the-most-frequently-ordered-products-for-each-customer)", "[The Most Frequently Ordered Products for Each Customer](/solution/1500-1599/1596.The%20Most%20Frequently%20Ordered%20Products%20for%20Each%20Customer/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1734", "frontend_question_id": "1587", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/bank-account-summary-ii", "url_en": "https://leetcode.com/problems/bank-account-summary-ii", "relative_path_cn": "/solution/1500-1599/1587.Bank%20Account%20Summary%20II/README.md", "relative_path_en": "/solution/1500-1599/1587.Bank%20Account%20Summary%20II/README_EN.md", "title_cn": "\u94f6\u884c\u8d26\u6237\u6982\u8981 II", "title_en": "Bank Account Summary II", "question_title_slug": "bank-account-summary-ii", "content_en": "

Table: Users

\n\n
\n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| account      | int     |\n| name         | varchar |\n+--------------+---------+\naccount is the primary key for this table.\nEach row of this table contains the account number of each user in the bank.\n
\n\n

 

\n\n

Table: Transactions

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| trans_id      | int     |\n| account       | int     |\n| amount        | int     |\n| transacted_on | date    |\n+---------------+---------+\ntrans_id is the primary key for this table.\nEach row of this table contains all changes made to all accounts.\namount is positive if the user received money and negative if they transferred money.\nAll accounts start with a balance 0.\n
\n\n

 

\n\n

Write an SQL query to report the name and balance of users with a balance higher than 10000. The balance of an account is equal to the sum of the amounts of all transactions involving that account.

\n\n

Return the result table in any order.

\n\n

The query result format is in the following example.

\n\n

 

\n\n
\nUsers table:\n+------------+--------------+\n| account    | name         |\n+------------+--------------+\n| 900001     | Alice        |\n| 900002     | Bob          |\n| 900003     | Charlie      |\n+------------+--------------+\n\nTransactions table:\n+------------+------------+------------+---------------+\n| trans_id   | account    | amount     | transacted_on |\n+------------+------------+------------+---------------+\n| 1          | 900001     | 7000       |  2020-08-01   |\n| 2          | 900001     | 7000       |  2020-09-01   |\n| 3          | 900001     | -3000      |  2020-09-02   |\n| 4          | 900002     | 1000       |  2020-09-12   |\n| 5          | 900003     | 6000       |  2020-08-07   |\n| 6          | 900003     | 6000       |  2020-09-07   |\n| 7          | 900003     | -4000      |  2020-09-11   |\n+------------+------------+------------+---------------+\n\nResult table:\n+------------+------------+\n| name       | balance    |\n+------------+------------+\n| Alice      | 11000      |\n+------------+------------+\nAlice's balance is (7000 + 7000 - 3000) = 11000.\nBob's balance is 1000.\nCharlie's balance is (6000 + 6000 - 4000) = 8000.\n
\n", "content_cn": "

\u8868: Users

\n\n
+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| account      | int     |\n| name         | varchar |\n+--------------+---------+\naccount \u662f\u8be5\u8868\u7684\u4e3b\u952e.\n\u8868\u4e2d\u7684\u6bcf\u4e00\u884c\u5305\u542b\u94f6\u884c\u91cc\u4e2d\u6bcf\u4e00\u4e2a\u7528\u6237\u7684\u8d26\u53f7.\n
\n\n

 

\n\n

\u8868: Transactions

\n\n
+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| trans_id      | int     |\n| account       | int     |\n| amount        | int     |\n| transacted_on | date    |\n+---------------+---------+\ntrans_id \u662f\u8be5\u8868\u4e3b\u952e.\n\u8be5\u8868\u7684\u6bcf\u4e00\u884c\u5305\u542b\u4e86\u6240\u6709\u8d26\u6237\u7684\u4ea4\u6613\u6539\u53d8\u60c5\u51b5.\n\u5982\u679c\u7528\u6237\u6536\u5230\u4e86\u94b1, \u90a3\u4e48\u91d1\u989d\u662f\u6b63\u7684; \u5982\u679c\u7528\u6237\u8f6c\u4e86\u94b1, \u90a3\u4e48\u91d1\u989d\u662f\u8d1f\u7684.\n\u6240\u6709\u8d26\u6237\u7684\u8d77\u59cb\u4f59\u989d\u4e3a 0.\n
\n\n

 

\n\n

\u5199\u4e00\u4e2a SQL,  \u62a5\u544a\u4f59\u989d\u9ad8\u4e8e 10000 \u7684\u6240\u6709\u7528\u6237\u7684\u540d\u5b57\u548c\u4f59\u989d. \u8d26\u6237\u7684\u4f59\u989d\u7b49\u4e8e\u5305\u542b\u8be5\u8d26\u6237\u7684\u6240\u6709\u4ea4\u6613\u7684\u603b\u548c.

\n\n

\u8fd4\u56de\u7ed3\u679c\u8868\u5355\u6ca1\u6709\u987a\u5e8f\u8981\u6c42.

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a.

\n\n

 

\n\n
Users table:\n+------------+--------------+\n| account    | name         |\n+------------+--------------+\n| 900001     | Alice        |\n| 900002     | Bob          |\n| 900003     | Charlie      |\n+------------+--------------+\n\nTransactions table:\n+------------+------------+------------+---------------+\n| trans_id   | account    | amount     | transacted_on |\n+------------+------------+------------+---------------+\n| 1          | 900001     | 7000       |  2020-08-01   |\n| 2          | 900001     | 7000       |  2020-09-01   |\n| 3          | 900001     | -3000      |  2020-09-02   |\n| 4          | 900002     | 1000       |  2020-09-12   |\n| 5          | 900003     | 6000       |  2020-08-07   |\n| 6          | 900003     | 6000       |  2020-09-07   |\n| 7          | 900003     | -4000      |  2020-09-11   |\n+------------+------------+------------+---------------+\n\nResult table:\n+------------+------------+\n| name       | balance    |\n+------------+------------+\n| Alice      | 11000      |\n+------------+------------+\nAlice \u7684\u4f59\u989d\u4e3a(7000 + 7000 - 3000) = 11000.\nBob \u7684\u4f59\u989d\u4e3a1000.\nCharlie \u7684\u4f59\u989d\u4e3a(6000 + 6000 - 4000) = 8000.\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1587](https://leetcode-cn.com/problems/bank-account-summary-ii)", "[\u94f6\u884c\u8d26\u6237\u6982\u8981 II](/solution/1500-1599/1587.Bank%20Account%20Summary%20II/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1587](https://leetcode.com/problems/bank-account-summary-ii)", "[Bank Account Summary II](/solution/1500-1599/1587.Bank%20Account%20Summary%20II/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1733", "frontend_question_id": "1610", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-number-of-visible-points", "url_en": "https://leetcode.com/problems/maximum-number-of-visible-points", "relative_path_cn": "/solution/1600-1699/1610.Maximum%20Number%20of%20Visible%20Points/README.md", "relative_path_en": "/solution/1600-1699/1610.Maximum%20Number%20of%20Visible%20Points/README_EN.md", "title_cn": "\u53ef\u89c1\u70b9\u7684\u6700\u5927\u6570\u76ee", "title_en": "Maximum Number of Visible Points", "question_title_slug": "maximum-number-of-visible-points", "content_en": "

You are given an array points, an integer angle, and your location, where location = [posx, posy] and points[i] = [xi, yi] both denote integral coordinates on the X-Y plane.

\n\n

Initially, you are facing directly east from your position. You cannot move from your position, but you can rotate. In other words, posx and posy cannot be changed. Your field of view in degrees is represented by angle, determining how wide you can see from any given view direction. Let d be the amount in degrees that you rotate counterclockwise. Then, your field of view is the inclusive range of angles [d - angle/2, d + angle/2].

\n\n

\n\n

\n\n

You can see some set of points if, for each point, the angle formed by the point, your position, and the immediate east direction from your position is in your field of view.

\n\n

There can be multiple points at one coordinate. There may be points at your location, and you can always see these points regardless of your rotation. Points do not obstruct your vision to other points.

\n\n

Return the maximum number of points you can see.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: points = [[2,1],[2,2],[3,3]], angle = 90, location = [1,1]\nOutput: 3\nExplanation: The shaded region represents your field of view. All points can be made visible in your field of view, including [3,3] even though [2,2] is in front and in the same line of sight.\n
\n\n

Example 2:

\n\n
\nInput: points = [[2,1],[2,2],[3,4],[1,1]], angle = 90, location = [1,1]\nOutput: 4\nExplanation: All points can be made visible in your field of view, including the one at your location.\n
\n\n

Example 3:

\n\"\"\n
\nInput: points = [[1,0],[2,1]], angle = 13, location = [1,1]\nOutput: 1\nExplanation: You can only see one of the two points, as shown above.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= points.length <= 105
  • \n\t
  • points[i].length == 2
  • \n\t
  • location.length == 2
  • \n\t
  • 0 <= angle < 360
  • \n\t
  • 0 <= posx, posy, xi, yi <= 100
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u70b9\u6570\u7ec4 points \u548c\u4e00\u4e2a\u8868\u793a\u89d2\u5ea6\u7684\u6574\u6570 angle \uff0c\u4f60\u7684\u4f4d\u7f6e\u662f location \uff0c\u5176\u4e2d location = [posx, posy] \u4e14 points[i] = [xi, yi] \u90fd\u8868\u793a X-Y \u5e73\u9762\u4e0a\u7684\u6574\u6570\u5750\u6807\u3002

\n\n

\u6700\u5f00\u59cb\uff0c\u4f60\u9762\u5411\u4e1c\u65b9\u8fdb\u884c\u89c2\u6d4b\u3002\u4f60 \u4e0d\u80fd \u8fdb\u884c\u79fb\u52a8\u6539\u53d8\u4f4d\u7f6e\uff0c\u4f46\u53ef\u4ee5\u901a\u8fc7 \u81ea\u8f6c \u8c03\u6574\u89c2\u6d4b\u89d2\u5ea6\u3002\u6362\u53e5\u8bdd\u8bf4\uff0cposx \u548c posy \u4e0d\u80fd\u6539\u53d8\u3002\u4f60\u7684\u89c6\u91ce\u8303\u56f4\u7684\u89d2\u5ea6\u7528 angle \u8868\u793a\uff0c \u8fd9\u51b3\u5b9a\u4e86\u4f60\u89c2\u6d4b\u4efb\u610f\u65b9\u5411\u65f6\u53ef\u4ee5\u591a\u5bbd\u3002\u8bbe d \u4e3a\u4f60\u9006\u65f6\u9488\u81ea\u8f6c\u65cb\u8f6c\u7684\u5ea6\u6570\uff0c\u90a3\u4e48\u4f60\u7684\u89c6\u91ce\u5c31\u662f\u89d2\u5ea6\u8303\u56f4 [d - angle/2, d + angle/2] \u6240\u6307\u793a\u7684\u90a3\u7247\u533a\u57df\u3002

\n\n\n\n

\u5bf9\u4e8e\u6bcf\u4e2a\u70b9\uff0c\u5982\u679c\u7531\u8be5\u70b9\u3001\u4f60\u7684\u4f4d\u7f6e\u4ee5\u53ca\u4ece\u4f60\u7684\u4f4d\u7f6e\u76f4\u63a5\u5411\u4e1c\u7684\u65b9\u5411\u5f62\u6210\u7684\u89d2\u5ea6 \u4f4d\u4e8e\u4f60\u7684\u89c6\u91ce\u4e2d \uff0c\u90a3\u4e48\u4f60\u5c31\u53ef\u4ee5\u770b\u5230\u5b83\u3002

\n\n

\u540c\u4e00\u4e2a\u5750\u6807\u4e0a\u53ef\u4ee5\u6709\u591a\u4e2a\u70b9\u3002\u4f60\u6240\u5728\u7684\u4f4d\u7f6e\u4e5f\u53ef\u80fd\u5b58\u5728\u4e00\u4e9b\u70b9\uff0c\u4f46\u4e0d\u7ba1\u4f60\u7684\u600e\u4e48\u65cb\u8f6c\uff0c\u603b\u662f\u53ef\u4ee5\u770b\u5230\u8fd9\u4e9b\u70b9\u3002\u540c\u65f6\uff0c\u70b9\u4e0d\u4f1a\u963b\u788d\u4f60\u770b\u5230\u5176\u4ed6\u70b9\u3002

\n\n

\u8fd4\u56de\u4f60\u80fd\u770b\u5230\u7684\u70b9\u7684\u6700\u5927\u6570\u76ee\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1apoints = [[2,1],[2,2],[3,3]], angle = 90, location = [1,1]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u9634\u5f71\u533a\u57df\u4ee3\u8868\u4f60\u7684\u89c6\u91ce\u3002\u5728\u4f60\u7684\u89c6\u91ce\u4e2d\uff0c\u6240\u6709\u7684\u70b9\u90fd\u6e05\u6670\u53ef\u89c1\uff0c\u5c3d\u7ba1 [2,2] \u548c [3,3]\u5728\u540c\u4e00\u6761\u76f4\u7ebf\u4e0a\uff0c\u4f60\u4ecd\u7136\u53ef\u4ee5\u770b\u5230 [3,3] \u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1apoints = [[2,1],[2,2],[3,4],[1,1]], angle = 90, location = [1,1]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u5728\u4f60\u7684\u89c6\u91ce\u4e2d\uff0c\u6240\u6709\u7684\u70b9\u90fd\u6e05\u6670\u53ef\u89c1\uff0c\u5305\u62ec\u4f60\u6240\u5728\u4f4d\u7f6e\u7684\u90a3\u4e2a\u70b9\u3002
\n\n

\u793a\u4f8b 3\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1apoints = [[1,0],[2,1]], angle = 13, location = [1,1]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u5982\u56fe\u6240\u793a\uff0c\u4f60\u53ea\u80fd\u770b\u5230\u4e24\u70b9\u4e4b\u4e00\u3002
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= points.length <= 105
  • \n\t
  • points[i].length == 2
  • \n\t
  • location.length == 2
  • \n\t
  • 0 <= angle < 360
  • \n\t
  • 0 <= posx, posy, xi, yi <= 100
  • \n
\n", "tags_en": ["Geometry", "Two Pointers"], "tags_cn": ["\u51e0\u4f55", "\u53cc\u6307\u9488"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int visiblePoints(vector>& points, int angle, vector& location) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int visiblePoints(List> points, int angle, List location) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def visiblePoints(self, points, angle, location):\n \"\"\"\n :type points: List[List[int]]\n :type angle: int\n :type location: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def visiblePoints(self, points: List[List[int]], angle: int, location: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint visiblePoints(int** points, int pointsSize, int* pointsColSize, int angle, int* location, int locationSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int VisiblePoints(IList> points, int angle, IList location) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} points\n * @param {number} angle\n * @param {number[]} location\n * @return {number}\n */\nvar visiblePoints = function(points, angle, location) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} points\n# @param {Integer} angle\n# @param {Integer[]} location\n# @return {Integer}\ndef visible_points(points, angle, location)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func visiblePoints(_ points: [[Int]], _ angle: Int, _ location: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func visiblePoints(points [][]int, angle int, location []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def visiblePoints(points: List[List[Int]], angle: Int, location: List[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun visiblePoints(points: List>, angle: Int, location: List): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn visible_points(points: Vec>, angle: i32, location: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $points\n * @param Integer $angle\n * @param Integer[] $location\n * @return Integer\n */\n function visiblePoints($points, $angle, $location) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function visiblePoints(points: number[][], angle: number, location: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (visible-points points angle location)\n (-> (listof (listof exact-integer?)) exact-integer? (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1610](https://leetcode-cn.com/problems/maximum-number-of-visible-points)", "[\u53ef\u89c1\u70b9\u7684\u6700\u5927\u6570\u76ee](/solution/1600-1699/1610.Maximum%20Number%20of%20Visible%20Points/README.md)", "`\u51e0\u4f55`,`\u53cc\u6307\u9488`", "\u56f0\u96be", ""], "md_table_row_en": ["[1610](https://leetcode.com/problems/maximum-number-of-visible-points)", "[Maximum Number of Visible Points](/solution/1600-1699/1610.Maximum%20Number%20of%20Visible%20Points/README_EN.md)", "`Geometry`,`Two Pointers`", "Hard", ""]}, {"question_id": "1732", "frontend_question_id": "1611", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-one-bit-operations-to-make-integers-zero", "url_en": "https://leetcode.com/problems/minimum-one-bit-operations-to-make-integers-zero", "relative_path_cn": "/solution/1600-1699/1611.Minimum%20One%20Bit%20Operations%20to%20Make%20Integers%20Zero/README.md", "relative_path_en": "/solution/1600-1699/1611.Minimum%20One%20Bit%20Operations%20to%20Make%20Integers%20Zero/README_EN.md", "title_cn": "\u4f7f\u6574\u6570\u53d8\u4e3a 0 \u7684\u6700\u5c11\u64cd\u4f5c\u6b21\u6570", "title_en": "Minimum One Bit Operations to Make Integers Zero", "question_title_slug": "minimum-one-bit-operations-to-make-integers-zero", "content_en": "

Given an integer n, you must transform it into 0 using the following operations any number of times:

\n\n
    \n\t
  • Change the rightmost (0th) bit in the binary representation of n.
  • \n\t
  • Change the ith bit in the binary representation of n if the (i-1)th bit is set to 1 and the (i-2)th through 0th bits are set to 0.
  • \n
\n\n

Return the minimum number of operations to transform n into 0.

\n\n

 

\n

Example 1:

\n\n
\nInput: n = 0\nOutput: 0\n
\n\n

Example 2:

\n\n
\nInput: n = 3\nOutput: 2\nExplanation: The binary representation of 3 is "11".\n"11" -> "01" with the 2nd operation since the 0th bit is 1.\n"01" -> "00" with the 1st operation.\n
\n\n

Example 3:

\n\n
\nInput: n = 6\nOutput: 4\nExplanation: The binary representation of 6 is "110".\n"110" -> "010" with the 2nd operation since the 1st bit is 1 and 0th through 0th bits are 0.\n"010" -> "011" with the 1st operation.\n"011" -> "001" with the 2nd operation since the 0th bit is 1.\n"001" -> "000" with the 1st operation.\n
\n\n

Example 4:

\n\n
\nInput: n = 9\nOutput: 14\n
\n\n

Example 5:

\n\n
\nInput: n = 333\nOutput: 393\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 0 <= n <= 109
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n\uff0c\u4f60\u9700\u8981\u91cd\u590d\u6267\u884c\u591a\u6b21\u4e0b\u8ff0\u64cd\u4f5c\u5c06\u5176\u8f6c\u6362\u4e3a 0 \uff1a

\n\n
    \n\t
  • \u7ffb\u8f6c n \u7684\u4e8c\u8fdb\u5236\u8868\u793a\u4e2d\u6700\u53f3\u4fa7\u4f4d\uff08\u7b2c 0 \u4f4d\uff09\u3002
  • \n\t
  • \u5982\u679c\u7b2c (i-1) \u4f4d\u4e3a 1 \u4e14\u4ece\u7b2c (i-2) \u4f4d\u5230\u7b2c 0 \u4f4d\u90fd\u4e3a 0\uff0c\u5219\u7ffb\u8f6c n \u7684\u4e8c\u8fdb\u5236\u8868\u793a\u4e2d\u7684\u7b2c i \u4f4d\u3002
  • \n
\n\n

\u8fd4\u56de\u5c06 n \u8f6c\u6362\u4e3a 0 \u7684\u6700\u5c0f\u64cd\u4f5c\u6b21\u6570\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1an = 0\n\u8f93\u51fa\uff1a0\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1an = 3\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a3 \u7684\u4e8c\u8fdb\u5236\u8868\u793a\u4e3a \"11\"\n\"11\" -> \"01\" \uff0c\u6267\u884c\u7684\u662f\u7b2c 2 \u79cd\u64cd\u4f5c\uff0c\u56e0\u4e3a\u7b2c 0 \u4f4d\u4e3a 1 \u3002\n\"01\" -> \"00\" \uff0c\u6267\u884c\u7684\u662f\u7b2c 1 \u79cd\u64cd\u4f5c\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1an = 6\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a6 \u7684\u4e8c\u8fdb\u5236\u8868\u793a\u4e3a \"110\".\n\"110\" -> \"010\" \uff0c\u6267\u884c\u7684\u662f\u7b2c 2 \u79cd\u64cd\u4f5c\uff0c\u56e0\u4e3a\u7b2c 1 \u4f4d\u4e3a 1 \uff0c\u7b2c 0 \u5230 0 \u4f4d\u4e3a 0 \u3002\n\"010\" -> \"011\" \uff0c\u6267\u884c\u7684\u662f\u7b2c 1 \u79cd\u64cd\u4f5c\u3002\n\"011\" -> \"001\" \uff0c\u6267\u884c\u7684\u662f\u7b2c 2 \u79cd\u64cd\u4f5c\uff0c\u56e0\u4e3a\u7b2c 0 \u4f4d\u4e3a 1 \u3002\n\"001\" -> \"000\" \uff0c\u6267\u884c\u7684\u662f\u7b2c 1 \u79cd\u64cd\u4f5c\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1an = 9\n\u8f93\u51fa\uff1a14\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\n\u8f93\u5165\uff1an = 333\n\u8f93\u51fa\uff1a393\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 0 <= n <= 109
  • \n
\n", "tags_en": ["Bit Manipulation", "Dynamic Programming"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minimumOneBitOperations(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minimumOneBitOperations(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimumOneBitOperations(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimumOneBitOperations(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minimumOneBitOperations(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinimumOneBitOperations(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar minimumOneBitOperations = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef minimum_one_bit_operations(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimumOneBitOperations(_ n: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimumOneBitOperations(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimumOneBitOperations(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimumOneBitOperations(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimum_one_bit_operations(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function minimumOneBitOperations($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimumOneBitOperations(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimum-one-bit-operations n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1611](https://leetcode-cn.com/problems/minimum-one-bit-operations-to-make-integers-zero)", "[\u4f7f\u6574\u6570\u53d8\u4e3a 0 \u7684\u6700\u5c11\u64cd\u4f5c\u6b21\u6570](/solution/1600-1699/1611.Minimum%20One%20Bit%20Operations%20to%20Make%20Integers%20Zero/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1611](https://leetcode.com/problems/minimum-one-bit-operations-to-make-integers-zero)", "[Minimum One Bit Operations to Make Integers Zero](/solution/1600-1699/1611.Minimum%20One%20Bit%20Operations%20to%20Make%20Integers%20Zero/README_EN.md)", "`Bit Manipulation`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "1731", "frontend_question_id": "1609", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/even-odd-tree", "url_en": "https://leetcode.com/problems/even-odd-tree", "relative_path_cn": "/solution/1600-1699/1609.Even%20Odd%20Tree/README.md", "relative_path_en": "/solution/1600-1699/1609.Even%20Odd%20Tree/README_EN.md", "title_cn": "\u5947\u5076\u6811", "title_en": "Even Odd Tree", "question_title_slug": "even-odd-tree", "content_en": "

A binary tree is named Even-Odd if it meets the following conditions:

\n\n
    \n\t
  • The root of the binary tree is at level index 0, its children are at level index 1, their children are at level index 2, etc.
  • \n\t
  • For every even-indexed level, all nodes at the level have odd integer values in strictly increasing order (from left to right).
  • \n\t
  • For every odd-indexed level, all nodes at the level have even integer values in strictly decreasing order (from left to right).
  • \n
\n\n

Given the root of a binary tree, return true if the binary tree is Even-Odd, otherwise return false.

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: root = [1,10,4,3,null,7,9,12,8,6,null,null,2]\nOutput: true\nExplanation: The node values on each level are:\nLevel 0: [1]\nLevel 1: [10,4]\nLevel 2: [3,7,9]\nLevel 3: [12,8,6,2]\nSince levels 0 and 2 are all odd and increasing, and levels 1 and 3 are all even and decreasing, the tree is Even-Odd.\n
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: root = [5,4,2,3,3,7]\nOutput: false\nExplanation: The node values on each level are:\nLevel 0: [5]\nLevel 1: [4,2]\nLevel 2: [3,3,7]\nNode values in the level 2 must be in strictly increasing order, so the tree is not Even-Odd.\n
\n\n

Example 3:

\n\n

\"\"

\n\n
\nInput: root = [5,9,1,3,5,7]\nOutput: false\nExplanation: Node values in the level 1 should be even integers.\n
\n\n

Example 4:

\n\n
\nInput: root = [1]\nOutput: true\n
\n\n

Example 5:

\n\n
\nInput: root = [11,8,6,1,3,9,11,30,20,18,16,12,10,4,2,17]\nOutput: true\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The number of nodes in the tree is in the range [1, 105].
  • \n\t
  • 1 <= Node.val <= 106
  • \n
\n", "content_cn": "

\u5982\u679c\u4e00\u68f5\u4e8c\u53c9\u6811\u6ee1\u8db3\u4e0b\u8ff0\u51e0\u4e2a\u6761\u4ef6\uff0c\u5219\u53ef\u4ee5\u79f0\u4e3a \u5947\u5076\u6811 \uff1a

\n\n
    \n\t
  • \u4e8c\u53c9\u6811\u6839\u8282\u70b9\u6240\u5728\u5c42\u4e0b\u6807\u4e3a 0 \uff0c\u6839\u7684\u5b50\u8282\u70b9\u6240\u5728\u5c42\u4e0b\u6807\u4e3a 1 \uff0c\u6839\u7684\u5b59\u8282\u70b9\u6240\u5728\u5c42\u4e0b\u6807\u4e3a 2 \uff0c\u4f9d\u6b64\u7c7b\u63a8\u3002
  • \n\t
  • \u5076\u6570\u4e0b\u6807 \u5c42\u4e0a\u7684\u6240\u6709\u8282\u70b9\u7684\u503c\u90fd\u662f \u5947 \u6574\u6570\uff0c\u4ece\u5de6\u5230\u53f3\u6309\u987a\u5e8f \u4e25\u683c\u9012\u589e
  • \n\t
  • \u5947\u6570\u4e0b\u6807 \u5c42\u4e0a\u7684\u6240\u6709\u8282\u70b9\u7684\u503c\u90fd\u662f \u5076 \u6574\u6570\uff0c\u4ece\u5de6\u5230\u53f3\u6309\u987a\u5e8f \u4e25\u683c\u9012\u51cf
  • \n
\n\n

\u7ed9\u4f60\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9\uff0c\u5982\u679c\u4e8c\u53c9\u6811\u4e3a \u5947\u5076\u6811 \uff0c\u5219\u8fd4\u56de true \uff0c\u5426\u5219\u8fd4\u56de false \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1aroot = [1,10,4,3,null,7,9,12,8,6,null,null,2]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u6bcf\u4e00\u5c42\u7684\u8282\u70b9\u503c\u5206\u522b\u662f\uff1a\n0 \u5c42\uff1a[1]\n1 \u5c42\uff1a[10,4]\n2 \u5c42\uff1a[3,7,9]\n3 \u5c42\uff1a[12,8,6,2]\n\u7531\u4e8e 0 \u5c42\u548c 2 \u5c42\u4e0a\u7684\u8282\u70b9\u503c\u90fd\u662f\u5947\u6570\u4e14\u4e25\u683c\u9012\u589e\uff0c\u800c 1 \u5c42\u548c 3 \u5c42\u4e0a\u7684\u8282\u70b9\u503c\u90fd\u662f\u5076\u6570\u4e14\u4e25\u683c\u9012\u51cf\uff0c\u56e0\u6b64\u8fd9\u662f\u4e00\u68f5\u5947\u5076\u6811\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1aroot = [5,4,2,3,3,7]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u6bcf\u4e00\u5c42\u7684\u8282\u70b9\u503c\u5206\u522b\u662f\uff1a\n0 \u5c42\uff1a[5]\n1 \u5c42\uff1a[4,2]\n2 \u5c42\uff1a[3,3,7]\n2 \u5c42\u4e0a\u7684\u8282\u70b9\u503c\u4e0d\u6ee1\u8db3\u4e25\u683c\u9012\u589e\u7684\u6761\u4ef6\uff0c\u6240\u4ee5\u8fd9\u4e0d\u662f\u4e00\u68f5\u5947\u5076\u6811\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1aroot = [5,9,1,3,5,7]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a1 \u5c42\u4e0a\u7684\u8282\u70b9\u503c\u5e94\u4e3a\u5076\u6570\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1aroot = [1]\n\u8f93\u51fa\uff1atrue\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\n\u8f93\u5165\uff1aroot = [11,8,6,1,3,9,11,30,20,18,16,12,10,4,2,17]\n\u8f93\u51fa\uff1atrue\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u6811\u4e2d\u8282\u70b9\u6570\u5728\u8303\u56f4 [1, 105] \u5185
  • \n\t
  • 1 <= Node.val <= 106
  • \n
\n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n bool isEvenOddTree(TreeNode* root) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public boolean isEvenOddTree(TreeNode root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def isEvenOddTree(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: bool\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def isEvenOddTree(self, root: TreeNode) -> bool:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nbool isEvenOddTree(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public bool IsEvenOddTree(TreeNode root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {boolean}\n */\nvar isEvenOddTree = function(root) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Boolean}\ndef is_even_odd_tree(root)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func isEvenOddTree(_ root: TreeNode?) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc isEvenOddTree(root *TreeNode) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def isEvenOddTree(root: TreeNode): Boolean = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun isEvenOddTree(root: TreeNode?): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn is_even_odd_tree(root: Option>>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Boolean\n */\n function isEvenOddTree($root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction isEvenOddTree(root: TreeNode | null): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (is-even-odd-tree root)\n (-> (or/c tree-node? #f) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1609](https://leetcode-cn.com/problems/even-odd-tree)", "[\u5947\u5076\u6811](/solution/1600-1699/1609.Even%20Odd%20Tree/README.md)", "`\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1609](https://leetcode.com/problems/even-odd-tree)", "[Even Odd Tree](/solution/1600-1699/1609.Even%20Odd%20Tree/README_EN.md)", "`Tree`", "Medium", ""]}, {"question_id": "1730", "frontend_question_id": "1608", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/special-array-with-x-elements-greater-than-or-equal-x", "url_en": "https://leetcode.com/problems/special-array-with-x-elements-greater-than-or-equal-x", "relative_path_cn": "/solution/1600-1699/1608.Special%20Array%20With%20X%20Elements%20Greater%20Than%20or%20Equal%20X/README.md", "relative_path_en": "/solution/1600-1699/1608.Special%20Array%20With%20X%20Elements%20Greater%20Than%20or%20Equal%20X/README_EN.md", "title_cn": "\u7279\u6b8a\u6570\u7ec4\u7684\u7279\u5f81\u503c", "title_en": "Special Array With X Elements Greater Than or Equal X", "question_title_slug": "special-array-with-x-elements-greater-than-or-equal-x", "content_en": "

You are given an array nums of non-negative integers. nums is considered special if there exists a number x such that there are exactly x numbers in nums that are greater than or equal to x.

\n\n

Notice that x does not have to be an element in nums.

\n\n

Return x if the array is special, otherwise, return -1. It can be proven that if nums is special, the value for x is unique.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [3,5]\nOutput: 2\nExplanation: There are 2 values (3 and 5) that are greater than or equal to 2.\n
\n\n

Example 2:

\n\n
\nInput: nums = [0,0]\nOutput: -1\nExplanation: No numbers fit the criteria for x.\nIf x = 0, there should be 0 numbers >= x, but there are 2.\nIf x = 1, there should be 1 number >= x, but there are 0.\nIf x = 2, there should be 2 numbers >= x, but there are 0.\nx cannot be greater since there are only 2 numbers in nums.\n
\n\n

Example 3:

\n\n
\nInput: nums = [0,4,3,0,4]\nOutput: 3\nExplanation: There are 3 values that are greater than or equal to 3.\n
\n\n

Example 4:

\n\n
\nInput: nums = [3,6,7,7,0]\nOutput: -1\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 100
  • \n\t
  • 0 <= nums[i] <= 1000
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\u6570\u7ec4 nums \u3002\u5982\u679c\u5b58\u5728\u4e00\u4e2a\u6570 x \uff0c\u4f7f\u5f97 nums \u4e2d\u6070\u597d\u6709 x \u4e2a\u5143\u7d20 \u5927\u4e8e\u6216\u8005\u7b49\u4e8e x \uff0c\u90a3\u4e48\u5c31\u79f0 nums \u662f\u4e00\u4e2a \u7279\u6b8a\u6570\u7ec4 \uff0c\u800c x \u662f\u8be5\u6570\u7ec4\u7684 \u7279\u5f81\u503c \u3002

\n\n

\u6ce8\u610f\uff1a x \u4e0d\u5fc5 \u662f nums \u7684\u4e2d\u7684\u5143\u7d20\u3002

\n\n

\u5982\u679c\u6570\u7ec4 nums \u662f\u4e00\u4e2a \u7279\u6b8a\u6570\u7ec4 \uff0c\u8bf7\u8fd4\u56de\u5b83\u7684\u7279\u5f81\u503c x \u3002\u5426\u5219\uff0c\u8fd4\u56de -1 \u3002\u53ef\u4ee5\u8bc1\u660e\u7684\u662f\uff0c\u5982\u679c nums \u662f\u7279\u6b8a\u6570\u7ec4\uff0c\u90a3\u4e48\u5176\u7279\u5f81\u503c x \u662f \u552f\u4e00\u7684 \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anums = [3,5]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6709 2 \u4e2a\u5143\u7d20\uff083 \u548c 5\uff09\u5927\u4e8e\u6216\u7b49\u4e8e 2 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anums = [0,0]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u6ca1\u6709\u6ee1\u8db3\u9898\u76ee\u8981\u6c42\u7684\u7279\u6b8a\u6570\u7ec4\uff0c\u6545\u800c\u4e5f\u4e0d\u5b58\u5728\u7279\u5f81\u503c x \u3002\n\u5982\u679c x = 0\uff0c\u5e94\u8be5\u6709 0 \u4e2a\u5143\u7d20 >= x\uff0c\u4f46\u5b9e\u9645\u6709 2 \u4e2a\u3002\n\u5982\u679c x = 1\uff0c\u5e94\u8be5\u6709 1 \u4e2a\u5143\u7d20 >= x\uff0c\u4f46\u5b9e\u9645\u6709 0 \u4e2a\u3002\n\u5982\u679c x = 2\uff0c\u5e94\u8be5\u6709 2 \u4e2a\u5143\u7d20 >= x\uff0c\u4f46\u5b9e\u9645\u6709 0 \u4e2a\u3002\nx \u4e0d\u80fd\u53d6\u66f4\u5927\u7684\u503c\uff0c\u56e0\u4e3a nums \u4e2d\u53ea\u6709\u4e24\u4e2a\u5143\u7d20\u3002
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1anums = [0,4,3,0,4]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6709 3 \u4e2a\u5143\u7d20\u5927\u4e8e\u6216\u7b49\u4e8e 3 \u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1anums = [3,6,7,7,0]\n\u8f93\u51fa\uff1a-1\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 100
  • \n\t
  • 0 <= nums[i] <= 1000
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int specialArray(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int specialArray(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def specialArray(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def specialArray(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint specialArray(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SpecialArray(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar specialArray = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef special_array(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func specialArray(_ nums: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func specialArray(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def specialArray(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun specialArray(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn special_array(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function specialArray($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function specialArray(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (special-array nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1608](https://leetcode-cn.com/problems/special-array-with-x-elements-greater-than-or-equal-x)", "[\u7279\u6b8a\u6570\u7ec4\u7684\u7279\u5f81\u503c](/solution/1600-1699/1608.Special%20Array%20With%20X%20Elements%20Greater%20Than%20or%20Equal%20X/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1608](https://leetcode.com/problems/special-array-with-x-elements-greater-than-or-equal-x)", "[Special Array With X Elements Greater Than or Equal X](/solution/1600-1699/1608.Special%20Array%20With%20X%20Elements%20Greater%20Than%20or%20Equal%20X/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1729", "frontend_question_id": "1586", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/binary-search-tree-iterator-ii", "url_en": "https://leetcode.com/problems/binary-search-tree-iterator-ii", "relative_path_cn": "/solution/1500-1599/1586.Binary%20Search%20Tree%20Iterator%20II/README.md", "relative_path_en": "/solution/1500-1599/1586.Binary%20Search%20Tree%20Iterator%20II/README_EN.md", "title_cn": "\u4e8c\u53c9\u641c\u7d22\u6811\u8fed\u4ee3\u5668 II", "title_en": "Binary Search Tree Iterator II", "question_title_slug": "binary-search-tree-iterator-ii", "content_en": "

Implement the BSTIterator class that represents an iterator over the in-order traversal of a binary search tree (BST):

\n\n
    \n\t
  • BSTIterator(TreeNode root) Initializes an object of the BSTIterator class. The root of the BST is given as part of the constructor. The pointer should be initialized to a non-existent number smaller than any element in the BST.
  • \n\t
  • boolean hasNext() Returns true if there exists a number in the traversal to the right of the pointer, otherwise returns false.
  • \n\t
  • int next() Moves the pointer to the right, then returns the number at the pointer.
  • \n\t
  • boolean hasPrev() Returns true if there exists a number in the traversal to the left of the pointer, otherwise returns false.
  • \n\t
  • int prev() Moves the pointer to the left, then returns the number at the pointer.
  • \n
\n\n

Notice that by initializing the pointer to a non-existent smallest number, the first call to next() will return the smallest element in the BST.

\n\n

You may assume that next() and prev() calls will always be valid. That is, there will be at least a next/previous number in the in-order traversal when next()/prev() is called.

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput\n["BSTIterator", "next", "next", "prev", "next", "hasNext", "next", "next", "next", "hasNext", "hasPrev", "prev", "prev"]\n[[[7, 3, 15, null, null, 9, 20]], [null], [null], [null], [null], [null], [null], [null], [null], [null], [null], [null], [null]]\nOutput\n[null, 3, 7, 3, 7, true, 9, 15, 20, false, true, 15, 9]\n\nExplanation\n// The underlined element is where the pointer currently is.\nBSTIterator bSTIterator = new BSTIterator([7, 3, 15, null, null, 9, 20]); // state is   [3, 7, 9, 15, 20]\nbSTIterator.next(); // state becomes [3, 7, 9, 15, 20], return 3\nbSTIterator.next(); // state becomes [3, 7, 9, 15, 20], return 7\nbSTIterator.prev(); // state becomes [3, 7, 9, 15, 20], return 3\nbSTIterator.next(); // state becomes [3, 7, 9, 15, 20], return 7\nbSTIterator.hasNext(); // return true\nbSTIterator.next(); // state becomes [3, 7, 9, 15, 20], return 9\nbSTIterator.next(); // state becomes [3, 7, 9, 15, 20], return 15\nbSTIterator.next(); // state becomes [3, 7, 9, 15, 20], return 20\nbSTIterator.hasNext(); // return false\nbSTIterator.hasPrev(); // return true\nbSTIterator.prev(); // state becomes [3, 7, 9, 15, 20], return 15\nbSTIterator.prev(); // state becomes [3, 7, 9, 15, 20], return 9\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The number of nodes in the tree is in the range [1, 105].
  • \n\t
  • 0 <= Node.val <= 106
  • \n\t
  • At most 105 calls will be made to hasNext, next, hasPrev, and prev.
  • \n
\n\n

 

\nFollow up: Could you solve the problem without precalculating the values of the tree?", "content_cn": "

\u5b9e\u73b0\u4e8c\u53c9\u641c\u7d22\u6811\uff08BST\uff09\u7684\u4e2d\u5e8f\u904d\u5386\u8fed\u4ee3\u5668 BSTIterator \u7c7b\uff1a

\n\n
    \n\t
  • BSTIterator(TreeNode root) \u521d\u59cb\u5316 BSTIterator \u7c7b\u7684\u5b9e\u4f8b\u3002\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6839\u8282\u70b9 root \u4f5c\u4e3a\u6784\u9020\u51fd\u6570\u7684\u53c2\u6570\u4f20\u5165\u3002\u5185\u90e8\u6307\u9488\u4f7f\u7528\u4e00\u4e2a\u4e0d\u5b58\u5728\u4e8e\u6811\u4e2d\u4e14\u5c0f\u4e8e\u6811\u4e2d\u4efb\u610f\u503c\u7684\u6570\u503c\u6765\u521d\u59cb\u5316\u3002
  • \n\t
  • boolean hasNext() \u5982\u679c\u5f53\u524d\u6307\u9488\u5728\u4e2d\u5e8f\u904d\u5386\u5e8f\u5217\u4e2d\uff0c\u5b58\u5728\u53f3\u4fa7\u6570\u503c\uff0c\u8fd4\u56de true \uff0c\u5426\u5219\u8fd4\u56de false \u3002
  • \n\t
  • int next() \u5c06\u6307\u9488\u5728\u4e2d\u5e8f\u904d\u5386\u5e8f\u5217\u4e2d\u5411\u53f3\u79fb\u52a8\uff0c\u7136\u540e\u8fd4\u56de\u79fb\u52a8\u540e\u6307\u9488\u6240\u6307\u6570\u503c\u3002
  • \n\t
  • boolean hasPrev() \u5982\u679c\u5f53\u524d\u6307\u9488\u5728\u4e2d\u5e8f\u904d\u5386\u5e8f\u5217\u4e2d\uff0c\u5b58\u5728\u5de6\u4fa7\u6570\u503c\uff0c\u8fd4\u56de true \uff0c\u5426\u5219\u8fd4\u56de false \u3002
  • \n\t
  • int prev() \u5c06\u6307\u9488\u5728\u4e2d\u5e8f\u904d\u5386\u5e8f\u5217\u4e2d\u5411\u5de6\u79fb\u52a8\uff0c\u7136\u540e\u8fd4\u56de\u79fb\u52a8\u540e\u6307\u9488\u6240\u6307\u6570\u503c\u3002
  • \n
\n\n

\u6ce8\u610f\uff0c\u867d\u7136\u6211\u4eec\u4f7f\u7528\u6811\u4e2d\u4e0d\u5b58\u5728\u7684\u6700\u5c0f\u503c\u6765\u521d\u59cb\u5316\u5185\u90e8\u6307\u9488\uff0c\u7b2c\u4e00\u6b21\u8c03\u7528 next() \u9700\u8981\u8fd4\u56de\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u6700\u5c0f\u7684\u5143\u7d20\u3002

\n\n

\u4f60\u53ef\u4ee5\u5047\u8bbe next() \u548c prev() \u7684\u8c03\u7528\u603b\u662f\u6709\u6548\u7684\u3002\u5373\uff0c\u5f53 next()/prev() \u88ab\u8c03\u7528\u7684\u65f6\u5019\uff0c\u5728\u4e2d\u5e8f\u904d\u5386\u5e8f\u5217\u4e2d\u4e00\u5b9a\u5b58\u5728\u4e0b\u4e00\u4e2a/\u4e0a\u4e00\u4e2a\u5143\u7d20\u3002

\n\n

\u8fdb\u9636\uff1a\u4f60\u53ef\u4ee5\u4e0d\u63d0\u524d\u904d\u5386\u6811\u4e2d\u7684\u503c\u6765\u89e3\u51b3\u95ee\u9898\u5417\uff1f

\n\n

 

\n\n

\u793a\u4f8b 1:

\n\n

\"\"

\n\n
\u8f93\u5165\n["BSTIterator", "next", "next", "prev", "next", "hasNext", "next", "next", "next", "hasNext", "hasPrev", "prev", "prev"]\n[[[7, 3, 15, null, null, 9, 20]], [null], [null], [null], [null], [null], [null], [null], [null], [null], [null], [null], [null]]\n\u8f93\u51fa\n[null, 3, 7, 3, 7, true, 9, 15, 20, false, true, 15, 9]\n\n\u89e3\u91ca\n// \u5212\u7ebf\u7684\u5143\u7d20\u8868\u793a\u6307\u9488\u5f53\u524d\u7684\u4f4d\u7f6e\u3002\nBSTIterator bSTIterator = new BSTIterator([7, 3, 15, null, null, 9, 20]); // \u5f53\u524d\u72b6\u6001\u4e3a <u> </u> [3, 7, 9, 15, 20]\nbSTIterator.next(); // \u72b6\u6001\u53d8\u4e3a [<u>3</u>, 7, 9, 15, 20], \u8fd4\u56de 3\nbSTIterator.next(); // \u72b6\u6001\u53d8\u4e3a [3, <u>7</u>, 9, 15, 20], \u8fd4\u56de 7\nbSTIterator.prev(); // \u72b6\u6001\u53d8\u4e3a [<u>3</u>, 7, 9, 15, 20], \u8fd4\u56de 3\nbSTIterator.next(); // \u72b6\u6001\u53d8\u4e3a [3, <u>7</u>, 9, 15, 20], \u8fd4\u56de 7\nbSTIterator.hasNext(); // \u8fd4\u56de true\nbSTIterator.next(); // \u72b6\u6001\u53d8\u4e3a [3, 7, <u>9</u>, 15, 20], \u8fd4\u56de 9\nbSTIterator.next(); // \u72b6\u6001\u53d8\u4e3a [3, 7, 9, <u>15</u>, 20], \u8fd4\u56de 15\nbSTIterator.next(); // \u72b6\u6001\u53d8\u4e3a [3, 7, 9, 15, <u>20</u>], \u8fd4\u56de 20\nbSTIterator.hasNext(); // \u8fd4\u56de false\nbSTIterator.hasPrev(); // \u8fd4\u56de true\nbSTIterator.prev(); // \u72b6\u6001\u53d8\u4e3a [3, 7, 9, <u>15</u>, 20], \u8fd4\u56de 15\nbSTIterator.prev(); // \u72b6\u6001\u53d8\u4e3a [3, 7, <u>9</u>, 15, 20], \u8fd4\u56de 9\n
\n\n

 

\n\n

\u63d0\u793a:

\n\n
    \n\t
  • \u6811\u4e2d\u8282\u70b9\u4e2a\u6570\u7684\u8303\u56f4\u662f [1, 105] \u3002
  • \n\t
  • 0 <= Node.val <= 106
  • \n\t
  • \u6700\u591a\u8c03\u7528 105 \u6b21 hasNext\u3001 next\u3001 hasPrev \u548c prev \u3002
  • \n
\n", "tags_en": ["Tree", "Design"], "tags_cn": ["\u6811", "\u8bbe\u8ba1"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass BSTIterator {\npublic:\n BSTIterator(TreeNode* root) {\n\n }\n \n bool hasNext() {\n\n }\n \n int next() {\n\n }\n \n bool hasPrev() {\n\n }\n \n int prev() {\n\n }\n};\n\n/**\n * Your BSTIterator object will be instantiated and called as such:\n * BSTIterator* obj = new BSTIterator(root);\n * bool param_1 = obj->hasNext();\n * int param_2 = obj->next();\n * bool param_3 = obj->hasPrev();\n * int param_4 = obj->prev();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass BSTIterator {\n\n public BSTIterator(TreeNode root) {\n\n }\n \n public boolean hasNext() {\n\n }\n \n public int next() {\n\n }\n \n public boolean hasPrev() {\n\n }\n \n public int prev() {\n\n }\n}\n\n/**\n * Your BSTIterator object will be instantiated and called as such:\n * BSTIterator obj = new BSTIterator(root);\n * boolean param_1 = obj.hasNext();\n * int param_2 = obj.next();\n * boolean param_3 = obj.hasPrev();\n * int param_4 = obj.prev();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass BSTIterator(object):\n\n def __init__(self, root):\n \"\"\"\n :type root: TreeNode\n \"\"\"\n\n\n def hasNext(self):\n \"\"\"\n :rtype: bool\n \"\"\"\n\n\n def next(self):\n \"\"\"\n :rtype: int\n \"\"\"\n\n\n def hasPrev(self):\n \"\"\"\n :rtype: bool\n \"\"\"\n\n\n def prev(self):\n \"\"\"\n :rtype: int\n \"\"\"\n\n\n\n# Your BSTIterator object will be instantiated and called as such:\n# obj = BSTIterator(root)\n# param_1 = obj.hasNext()\n# param_2 = obj.next()\n# param_3 = obj.hasPrev()\n# param_4 = obj.prev()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass BSTIterator:\n\n def __init__(self, root: TreeNode):\n\n\n def hasNext(self) -> bool:\n\n\n def next(self) -> int:\n\n\n def hasPrev(self) -> bool:\n\n\n def prev(self) -> int:\n\n\n\n# Your BSTIterator object will be instantiated and called as such:\n# obj = BSTIterator(root)\n# param_1 = obj.hasNext()\n# param_2 = obj.next()\n# param_3 = obj.hasPrev()\n# param_4 = obj.prev()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n\ntypedef struct {\n\n} BSTIterator;\n\n\nBSTIterator* bSTIteratorCreate(struct TreeNode* root) {\n\n}\n\nbool bSTIteratorHasNext(BSTIterator* obj) {\n\n}\n\nint bSTIteratorNext(BSTIterator* obj) {\n\n}\n\nbool bSTIteratorHasPrev(BSTIterator* obj) {\n\n}\n\nint bSTIteratorPrev(BSTIterator* obj) {\n\n}\n\nvoid bSTIteratorFree(BSTIterator* obj) {\n\n}\n\n/**\n * Your BSTIterator struct will be instantiated and called as such:\n * BSTIterator* obj = bSTIteratorCreate(root);\n * bool param_1 = bSTIteratorHasNext(obj);\n \n * int param_2 = bSTIteratorNext(obj);\n \n * bool param_3 = bSTIteratorHasPrev(obj);\n \n * int param_4 = bSTIteratorPrev(obj);\n \n * bSTIteratorFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class BSTIterator {\n\n public BSTIterator(TreeNode root) {\n\n }\n \n public bool HasNext() {\n\n }\n \n public int Next() {\n\n }\n \n public bool HasPrev() {\n\n }\n \n public int Prev() {\n\n }\n}\n\n/**\n * Your BSTIterator object will be instantiated and called as such:\n * BSTIterator obj = new BSTIterator(root);\n * bool param_1 = obj.HasNext();\n * int param_2 = obj.Next();\n * bool param_3 = obj.HasPrev();\n * int param_4 = obj.Prev();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n */\nvar BSTIterator = function(root) {\n\n};\n\n/**\n * @return {boolean}\n */\nBSTIterator.prototype.hasNext = function() {\n\n};\n\n/**\n * @return {number}\n */\nBSTIterator.prototype.next = function() {\n\n};\n\n/**\n * @return {boolean}\n */\nBSTIterator.prototype.hasPrev = function() {\n\n};\n\n/**\n * @return {number}\n */\nBSTIterator.prototype.prev = function() {\n\n};\n\n/**\n * Your BSTIterator object will be instantiated and called as such:\n * var obj = new BSTIterator(root)\n * var param_1 = obj.hasNext()\n * var param_2 = obj.next()\n * var param_3 = obj.hasPrev()\n * var param_4 = obj.prev()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\nclass BSTIterator\n\n=begin\n :type root: TreeNode\n=end\n def initialize(root)\n\n end\n\n\n=begin\n :rtype: Boolean\n=end\n def has_next()\n\n end\n\n\n=begin\n :rtype: Integer\n=end\n def next()\n\n end\n\n\n=begin\n :rtype: Boolean\n=end\n def has_prev()\n\n end\n\n\n=begin\n :rtype: Integer\n=end\n def prev()\n\n end\n\n\nend\n\n# Your BSTIterator object will be instantiated and called as such:\n# obj = BSTIterator.new(root)\n# param_1 = obj.has_next()\n# param_2 = obj.next()\n# param_3 = obj.has_prev()\n# param_4 = obj.prev()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\n\nclass BSTIterator {\n\n init(_ root: TreeNode?) {\n\n }\n \n func hasNext() -> Bool {\n\n }\n \n func next() -> Int {\n\n }\n \n func hasPrev() -> Bool {\n\n }\n \n func prev() -> Int {\n\n }\n}\n\n/**\n * Your BSTIterator object will be instantiated and called as such:\n * let obj = BSTIterator(root)\n * let ret_1: Bool = obj.hasNext()\n * let ret_2: Int = obj.next()\n * let ret_3: Bool = obj.hasPrev()\n * let ret_4: Int = obj.prev()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\ntype BSTIterator struct {\n\n}\n\n\nfunc Constructor(root *TreeNode) BSTIterator {\n\n}\n\n\nfunc (this *BSTIterator) HasNext() bool {\n\n}\n\n\nfunc (this *BSTIterator) Next() int {\n\n}\n\n\nfunc (this *BSTIterator) HasPrev() bool {\n\n}\n\n\nfunc (this *BSTIterator) Prev() int {\n\n}\n\n\n/**\n * Your BSTIterator object will be instantiated and called as such:\n * obj := Constructor(root);\n * param_1 := obj.HasNext();\n * param_2 := obj.Next();\n * param_3 := obj.HasPrev();\n * param_4 := obj.Prev();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nclass BSTIterator(_root: TreeNode) {\n\n def hasNext(): Boolean = {\n\n }\n\n def next(): Int = {\n\n }\n\n def hasPrev(): Boolean = {\n\n }\n\n def prev(): Int = {\n\n }\n\n}\n\n/**\n * Your BSTIterator object will be instantiated and called as such:\n * var obj = new BSTIterator(root)\n * var param_1 = obj.hasNext()\n * var param_2 = obj.next()\n * var param_3 = obj.hasPrev()\n * var param_4 = obj.prev()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass BSTIterator(root: TreeNode?) {\n\n fun hasNext(): Boolean {\n\n }\n\n fun next(): Int {\n\n }\n\n fun hasPrev(): Boolean {\n\n }\n\n fun prev(): Int {\n\n }\n\n}\n\n/**\n * Your BSTIterator object will be instantiated and called as such:\n * var obj = BSTIterator(root)\n * var param_1 = obj.hasNext()\n * var param_2 = obj.next()\n * var param_3 = obj.hasPrev()\n * var param_4 = obj.prev()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nstruct BSTIterator {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl BSTIterator {\n\n fn new(root: Option>>) -> Self {\n\n }\n \n fn has_next(&self) -> bool {\n\n }\n \n fn next(&self) -> i32 {\n\n }\n \n fn has_prev(&self) -> bool {\n\n }\n \n fn prev(&self) -> i32 {\n\n }\n}\n\n/**\n * Your BSTIterator object will be instantiated and called as such:\n * let obj = BSTIterator::new(root);\n * let ret_1: bool = obj.has_next();\n * let ret_2: i32 = obj.next();\n * let ret_3: bool = obj.has_prev();\n * let ret_4: i32 = obj.prev();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass BSTIterator {\n /**\n * @param TreeNode $root\n */\n function __construct($root) {\n\n }\n\n /**\n * @return Boolean\n */\n function hasNext() {\n\n }\n\n /**\n * @return Integer\n */\n function next() {\n\n }\n\n /**\n * @return Boolean\n */\n function hasPrev() {\n\n }\n\n /**\n * @return Integer\n */\n function prev() {\n\n }\n}\n\n/**\n * Your BSTIterator object will be instantiated and called as such:\n * $obj = BSTIterator($root);\n * $ret_1 = $obj->hasNext();\n * $ret_2 = $obj->next();\n * $ret_3 = $obj->hasPrev();\n * $ret_4 = $obj->prev();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nclass BSTIterator {\n constructor(root: TreeNode | null) {\n\n }\n\n hasNext(): boolean {\n\n }\n\n next(): number {\n\n }\n\n hasPrev(): boolean {\n\n }\n\n prev(): number {\n\n }\n}\n\n/**\n * Your BSTIterator object will be instantiated and called as such:\n * var obj = new BSTIterator(root)\n * var param_1 = obj.hasNext()\n * var param_2 = obj.next()\n * var param_3 = obj.hasPrev()\n * var param_4 = obj.prev()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define bst-iterator%\n (class object%\n (super-new)\n\n ; root : (or/c tree-node? #f)\n (init-field\n root)\n \n ; has-next : -> boolean?\n (define/public (has-next)\n\n )\n ; next : -> exact-integer?\n (define/public (next)\n\n )\n ; has-prev : -> boolean?\n (define/public (has-prev)\n\n )\n ; prev : -> exact-integer?\n (define/public (prev)\n\n )))\n\n;; Your bst-iterator% object will be instantiated and called as such:\n;; (define obj (new bst-iterator% [root root]))\n;; (define param_1 (send obj has-next))\n;; (define param_2 (send obj next))\n;; (define param_3 (send obj has-prev))\n;; (define param_4 (send obj prev))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1586](https://leetcode-cn.com/problems/binary-search-tree-iterator-ii)", "[\u4e8c\u53c9\u641c\u7d22\u6811\u8fed\u4ee3\u5668 II](/solution/1500-1599/1586.Binary%20Search%20Tree%20Iterator%20II/README.md)", "`\u6811`,`\u8bbe\u8ba1`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1586](https://leetcode.com/problems/binary-search-tree-iterator-ii)", "[Binary Search Tree Iterator II](/solution/1500-1599/1586.Binary%20Search%20Tree%20Iterator%20II/README_EN.md)", "`Tree`,`Design`", "Medium", "\ud83d\udd12"]}, {"question_id": "1728", "frontend_question_id": "1622", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/fancy-sequence", "url_en": "https://leetcode.com/problems/fancy-sequence", "relative_path_cn": "/solution/1600-1699/1622.Fancy%20Sequence/README.md", "relative_path_en": "/solution/1600-1699/1622.Fancy%20Sequence/README_EN.md", "title_cn": "\u5947\u5999\u5e8f\u5217", "title_en": "Fancy Sequence", "question_title_slug": "fancy-sequence", "content_en": "

Write an API that generates fancy sequences using the append, addAll, and multAll operations.

\n\n

Implement the Fancy class:

\n\n
    \n\t
  • Fancy() Initializes the object with an empty sequence.
  • \n\t
  • void append(val) Appends an integer val to the end of the sequence.
  • \n\t
  • void addAll(inc) Increments all existing values in the sequence by an integer inc.
  • \n\t
  • void multAll(m) Multiplies all existing values in the sequence by an integer m.
  • \n\t
  • int getIndex(idx) Gets the current value at index idx (0-indexed) of the sequence modulo 109 + 7. If the index is greater or equal than the length of the sequence, return -1.
  • \n
\n\n

 

\n

Example 1:

\n\n
\nInput\n["Fancy", "append", "addAll", "append", "multAll", "getIndex", "addAll", "append", "multAll", "getIndex", "getIndex", "getIndex"]\n[[], [2], [3], [7], [2], [0], [3], [10], [2], [0], [1], [2]]\nOutput\n[null, null, null, null, null, 10, null, null, null, 26, 34, 20]\n\nExplanation\nFancy fancy = new Fancy();\nfancy.append(2);   // fancy sequence: [2]\nfancy.addAll(3);   // fancy sequence: [2+3] -> [5]\nfancy.append(7);   // fancy sequence: [5, 7]\nfancy.multAll(2);  // fancy sequence: [5*2, 7*2] -> [10, 14]\nfancy.getIndex(0); // return 10\nfancy.addAll(3);   // fancy sequence: [10+3, 14+3] -> [13, 17]\nfancy.append(10);  // fancy sequence: [13, 17, 10]\nfancy.multAll(2);  // fancy sequence: [13*2, 17*2, 10*2] -> [26, 34, 20]\nfancy.getIndex(0); // return 26\nfancy.getIndex(1); // return 34\nfancy.getIndex(2); // return 20\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= val, inc, m <= 100
  • \n\t
  • 0 <= idx <= 105
  • \n\t
  • At most 105 calls total will be made to append, addAll, multAll, and getIndex.
  • \n
\n", "content_cn": "

\u8bf7\u4f60\u5b9e\u73b0\u4e09\u4e2a API append\uff0caddAll\u00a0\u548c\u00a0multAll\u00a0\u6765\u5b9e\u73b0\u5947\u5999\u5e8f\u5217\u3002

\n\n

\u8bf7\u5b9e\u73b0\u00a0Fancy\u00a0\u7c7b \uff1a

\n\n
    \n\t
  • Fancy()\u00a0\u521d\u59cb\u5316\u4e00\u4e2a\u7a7a\u5e8f\u5217\u5bf9\u8c61\u3002
  • \n\t
  • void append(val) \u5c06\u6574\u6570\u00a0val\u00a0\u6dfb\u52a0\u5728\u5e8f\u5217\u672b\u5c3e\u3002
  • \n\t
  • void addAll(inc)\u00a0\u5c06\u6240\u6709\u5e8f\u5217\u4e2d\u7684\u73b0\u6709\u6570\u503c\u90fd\u589e\u52a0\u00a0inc\u00a0\u3002
  • \n\t
  • void multAll(m)\u00a0\u5c06\u5e8f\u5217\u4e2d\u7684\u6240\u6709\u73b0\u6709\u6570\u503c\u90fd\u4e58\u4ee5\u6574\u6570\u00a0m\u00a0\u3002
  • \n\t
  • int getIndex(idx) \u5f97\u5230\u4e0b\u6807\u4e3a\u00a0idx\u00a0\u5904\u7684\u6570\u503c\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\uff0c\u5e76\u5c06\u7ed3\u679c\u5bf9\u00a0109 + 7\u00a0\u53d6\u4f59\u3002\u5982\u679c\u4e0b\u6807\u5927\u4e8e\u7b49\u4e8e\u5e8f\u5217\u7684\u957f\u5ea6\uff0c\u8bf7\u8fd4\u56de\u00a0-1\u00a0\u3002
  • \n
\n\n

\u00a0

\n\n

\u793a\u4f8b\uff1a

\n\n
\n\u8f93\u5165\uff1a\n[\"Fancy\", \"append\", \"addAll\", \"append\", \"multAll\", \"getIndex\", \"addAll\", \"append\", \"multAll\", \"getIndex\", \"getIndex\", \"getIndex\"]\n[[], [2], [3], [7], [2], [0], [3], [10], [2], [0], [1], [2]]\n\u8f93\u51fa\uff1a\n[null, null, null, null, null, 10, null, null, null, 26, 34, 20]\n\n\u89e3\u91ca\uff1a\nFancy fancy = new Fancy();\nfancy.append(2);   // \u5947\u5999\u5e8f\u5217\uff1a[2]\nfancy.addAll(3);   // \u5947\u5999\u5e8f\u5217\uff1a[2+3] -> [5]\nfancy.append(7);   // \u5947\u5999\u5e8f\u5217\uff1a[5, 7]\nfancy.multAll(2);  // \u5947\u5999\u5e8f\u5217\uff1a[5*2, 7*2] -> [10, 14]\nfancy.getIndex(0); // \u8fd4\u56de 10\nfancy.addAll(3);   // \u5947\u5999\u5e8f\u5217\uff1a[10+3, 14+3] -> [13, 17]\nfancy.append(10);  // \u5947\u5999\u5e8f\u5217\uff1a[13, 17, 10]\nfancy.multAll(2);  // \u5947\u5999\u5e8f\u5217\uff1a[13*2, 17*2, 10*2] -> [26, 34, 20]\nfancy.getIndex(0); // \u8fd4\u56de 26\nfancy.getIndex(1); // \u8fd4\u56de 34\nfancy.getIndex(2); // \u8fd4\u56de 20\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= val, inc, m <= 100
  • \n\t
  • 0 <= idx <= 105
  • \n\t
  • \u603b\u5171\u6700\u591a\u4f1a\u6709\u00a0105\u00a0\u6b21\u5bf9\u00a0append\uff0caddAll\uff0cmultAll\u00a0\u548c\u00a0getIndex\u00a0\u7684\u8c03\u7528\u3002
  • \n
\n", "tags_en": ["Design", "Math"], "tags_cn": ["\u8bbe\u8ba1", "\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Fancy {\npublic:\n Fancy() {\n\n }\n \n void append(int val) {\n\n }\n \n void addAll(int inc) {\n\n }\n \n void multAll(int m) {\n\n }\n \n int getIndex(int idx) {\n\n }\n};\n\n/**\n * Your Fancy object will be instantiated and called as such:\n * Fancy* obj = new Fancy();\n * obj->append(val);\n * obj->addAll(inc);\n * obj->multAll(m);\n * int param_4 = obj->getIndex(idx);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Fancy {\n\n public Fancy() {\n\n }\n \n public void append(int val) {\n\n }\n \n public void addAll(int inc) {\n\n }\n \n public void multAll(int m) {\n\n }\n \n public int getIndex(int idx) {\n\n }\n}\n\n/**\n * Your Fancy object will be instantiated and called as such:\n * Fancy obj = new Fancy();\n * obj.append(val);\n * obj.addAll(inc);\n * obj.multAll(m);\n * int param_4 = obj.getIndex(idx);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Fancy(object):\n\n def __init__(self):\n\n\n def append(self, val):\n \"\"\"\n :type val: int\n :rtype: None\n \"\"\"\n\n\n def addAll(self, inc):\n \"\"\"\n :type inc: int\n :rtype: None\n \"\"\"\n\n\n def multAll(self, m):\n \"\"\"\n :type m: int\n :rtype: None\n \"\"\"\n\n\n def getIndex(self, idx):\n \"\"\"\n :type idx: int\n :rtype: int\n \"\"\"\n\n\n\n# Your Fancy object will be instantiated and called as such:\n# obj = Fancy()\n# obj.append(val)\n# obj.addAll(inc)\n# obj.multAll(m)\n# param_4 = obj.getIndex(idx)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Fancy:\n\n def __init__(self):\n\n\n def append(self, val: int) -> None:\n\n\n def addAll(self, inc: int) -> None:\n\n\n def multAll(self, m: int) -> None:\n\n\n def getIndex(self, idx: int) -> int:\n\n\n\n# Your Fancy object will be instantiated and called as such:\n# obj = Fancy()\n# obj.append(val)\n# obj.addAll(inc)\n# obj.multAll(m)\n# param_4 = obj.getIndex(idx)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} Fancy;\n\n\nFancy* fancyCreate() {\n\n}\n\nvoid fancyAppend(Fancy* obj, int val) {\n\n}\n\nvoid fancyAddAll(Fancy* obj, int inc) {\n\n}\n\nvoid fancyMultAll(Fancy* obj, int m) {\n\n}\n\nint fancyGetIndex(Fancy* obj, int idx) {\n\n}\n\nvoid fancyFree(Fancy* obj) {\n\n}\n\n/**\n * Your Fancy struct will be instantiated and called as such:\n * Fancy* obj = fancyCreate();\n * fancyAppend(obj, val);\n \n * fancyAddAll(obj, inc);\n \n * fancyMultAll(obj, m);\n \n * int param_4 = fancyGetIndex(obj, idx);\n \n * fancyFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Fancy {\n\n public Fancy() {\n\n }\n \n public void Append(int val) {\n\n }\n \n public void AddAll(int inc) {\n\n }\n \n public void MultAll(int m) {\n\n }\n \n public int GetIndex(int idx) {\n\n }\n}\n\n/**\n * Your Fancy object will be instantiated and called as such:\n * Fancy obj = new Fancy();\n * obj.Append(val);\n * obj.AddAll(inc);\n * obj.MultAll(m);\n * int param_4 = obj.GetIndex(idx);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "\nvar Fancy = function() {\n\n};\n\n/** \n * @param {number} val\n * @return {void}\n */\nFancy.prototype.append = function(val) {\n\n};\n\n/** \n * @param {number} inc\n * @return {void}\n */\nFancy.prototype.addAll = function(inc) {\n\n};\n\n/** \n * @param {number} m\n * @return {void}\n */\nFancy.prototype.multAll = function(m) {\n\n};\n\n/** \n * @param {number} idx\n * @return {number}\n */\nFancy.prototype.getIndex = function(idx) {\n\n};\n\n/**\n * Your Fancy object will be instantiated and called as such:\n * var obj = new Fancy()\n * obj.append(val)\n * obj.addAll(inc)\n * obj.multAll(m)\n * var param_4 = obj.getIndex(idx)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class Fancy\n def initialize()\n\n end\n\n\n=begin\n :type val: Integer\n :rtype: Void\n=end\n def append(val)\n\n end\n\n\n=begin\n :type inc: Integer\n :rtype: Void\n=end\n def add_all(inc)\n\n end\n\n\n=begin\n :type m: Integer\n :rtype: Void\n=end\n def mult_all(m)\n\n end\n\n\n=begin\n :type idx: Integer\n :rtype: Integer\n=end\n def get_index(idx)\n\n end\n\n\nend\n\n# Your Fancy object will be instantiated and called as such:\n# obj = Fancy.new()\n# obj.append(val)\n# obj.add_all(inc)\n# obj.mult_all(m)\n# param_4 = obj.get_index(idx)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass Fancy {\n\n init() {\n\n }\n \n func append(_ val: Int) {\n\n }\n \n func addAll(_ inc: Int) {\n\n }\n \n func multAll(_ m: Int) {\n\n }\n \n func getIndex(_ idx: Int) -> Int {\n\n }\n}\n\n/**\n * Your Fancy object will be instantiated and called as such:\n * let obj = Fancy()\n * obj.append(val)\n * obj.addAll(inc)\n * obj.multAll(m)\n * let ret_4: Int = obj.getIndex(idx)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type Fancy struct {\n\n}\n\n\nfunc Constructor() Fancy {\n\n}\n\n\nfunc (this *Fancy) Append(val int) {\n\n}\n\n\nfunc (this *Fancy) AddAll(inc int) {\n\n}\n\n\nfunc (this *Fancy) MultAll(m int) {\n\n}\n\n\nfunc (this *Fancy) GetIndex(idx int) int {\n\n}\n\n\n/**\n * Your Fancy object will be instantiated and called as such:\n * obj := Constructor();\n * obj.Append(val);\n * obj.AddAll(inc);\n * obj.MultAll(m);\n * param_4 := obj.GetIndex(idx);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class Fancy() {\n\n def append(`val`: Int) {\n\n }\n\n def addAll(inc: Int) {\n\n }\n\n def multAll(m: Int) {\n\n }\n\n def getIndex(idx: Int): Int = {\n\n }\n\n}\n\n/**\n * Your Fancy object will be instantiated and called as such:\n * var obj = new Fancy()\n * obj.append(`val`)\n * obj.addAll(inc)\n * obj.multAll(m)\n * var param_4 = obj.getIndex(idx)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Fancy() {\n\n fun append(`val`: Int) {\n\n }\n\n fun addAll(inc: Int) {\n\n }\n\n fun multAll(m: Int) {\n\n }\n\n fun getIndex(idx: Int): Int {\n\n }\n\n}\n\n/**\n * Your Fancy object will be instantiated and called as such:\n * var obj = Fancy()\n * obj.append(`val`)\n * obj.addAll(inc)\n * obj.multAll(m)\n * var param_4 = obj.getIndex(idx)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct Fancy {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl Fancy {\n\n fn new() -> Self {\n\n }\n \n fn append(&self, val: i32) {\n\n }\n \n fn add_all(&self, inc: i32) {\n\n }\n \n fn mult_all(&self, m: i32) {\n\n }\n \n fn get_index(&self, idx: i32) -> i32 {\n\n }\n}\n\n/**\n * Your Fancy object will be instantiated and called as such:\n * let obj = Fancy::new();\n * obj.append(val);\n * obj.add_all(inc);\n * obj.mult_all(m);\n * let ret_4: i32 = obj.get_index(idx);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Fancy {\n /**\n */\n function __construct() {\n\n }\n\n /**\n * @param Integer $val\n * @return NULL\n */\n function append($val) {\n\n }\n\n /**\n * @param Integer $inc\n * @return NULL\n */\n function addAll($inc) {\n\n }\n\n /**\n * @param Integer $m\n * @return NULL\n */\n function multAll($m) {\n\n }\n\n /**\n * @param Integer $idx\n * @return Integer\n */\n function getIndex($idx) {\n\n }\n}\n\n/**\n * Your Fancy object will be instantiated and called as such:\n * $obj = Fancy();\n * $obj->append($val);\n * $obj->addAll($inc);\n * $obj->multAll($m);\n * $ret_4 = $obj->getIndex($idx);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class Fancy {\n constructor() {\n\n }\n\n append(val: number): void {\n\n }\n\n addAll(inc: number): void {\n\n }\n\n multAll(m: number): void {\n\n }\n\n getIndex(idx: number): number {\n\n }\n}\n\n/**\n * Your Fancy object will be instantiated and called as such:\n * var obj = new Fancy()\n * obj.append(val)\n * obj.addAll(inc)\n * obj.multAll(m)\n * var param_4 = obj.getIndex(idx)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define fancy%\n (class object%\n (super-new)\n (init-field)\n \n ; append : exact-integer? -> void?\n (define/public (append val)\n\n )\n ; add-all : exact-integer? -> void?\n (define/public (add-all inc)\n\n )\n ; mult-all : exact-integer? -> void?\n (define/public (mult-all m)\n\n )\n ; get-index : exact-integer? -> exact-integer?\n (define/public (get-index idx)\n\n )))\n\n;; Your fancy% object will be instantiated and called as such:\n;; (define obj (new fancy%))\n;; (send obj append val)\n;; (send obj add-all inc)\n;; (send obj mult-all m)\n;; (define param_4 (send obj get-index idx))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1622](https://leetcode-cn.com/problems/fancy-sequence)", "[\u5947\u5999\u5e8f\u5217](/solution/1600-1699/1622.Fancy%20Sequence/README.md)", "`\u8bbe\u8ba1`,`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[1622](https://leetcode.com/problems/fancy-sequence)", "[Fancy Sequence](/solution/1600-1699/1622.Fancy%20Sequence/README_EN.md)", "`Design`,`Math`", "Hard", ""]}, {"question_id": "1727", "frontend_question_id": "1728", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/cat-and-mouse-ii", "url_en": "https://leetcode.com/problems/cat-and-mouse-ii", "relative_path_cn": "/solution/1700-1799/1728.Cat%20and%20Mouse%20II/README.md", "relative_path_en": "/solution/1700-1799/1728.Cat%20and%20Mouse%20II/README_EN.md", "title_cn": "\u732b\u548c\u8001\u9f20 II", "title_en": "Cat and Mouse II", "question_title_slug": "cat-and-mouse-ii", "content_en": "

A game is played by a cat and a mouse named Cat and Mouse.

\n\n

The environment is represented by a grid of size rows x cols, where each element is a wall, floor, player (Cat, Mouse), or food.

\n\n
    \n\t
  • Players are represented by the characters 'C'(Cat),'M'(Mouse).
  • \n\t
  • Floors are represented by the character '.' and can be walked on.
  • \n\t
  • Walls are represented by the character '#' and cannot be walked on.
  • \n\t
  • Food is represented by the character 'F' and can be walked on.
  • \n\t
  • There is only one of each character 'C', 'M', and 'F' in grid.
  • \n
\n\n

Mouse and Cat play according to the following rules:

\n\n
    \n\t
  • Mouse moves first, then they take turns to move.
  • \n\t
  • During each turn, Cat and Mouse can jump in one of the four directions (left, right, up, down). They cannot jump over the wall nor outside of the grid.
  • \n\t
  • catJump, mouseJump are the maximum lengths Cat and Mouse can jump at a time, respectively. Cat and Mouse can jump less than the maximum length.
  • \n\t
  • Staying in the same position is allowed.
  • \n\t
  • Mouse can jump over Cat.
  • \n
\n\n

The game can end in 4 ways:

\n\n
    \n\t
  • If Cat occupies the same position as Mouse, Cat wins.
  • \n\t
  • If Cat reaches the food first, Cat wins.
  • \n\t
  • If Mouse reaches the food first, Mouse wins.
  • \n\t
  • If Mouse cannot get to the food within 1000 turns, Cat wins.
  • \n
\n\n

Given a rows x cols matrix grid and two integers catJump and mouseJump, return true if Mouse can win the game if both Cat and Mouse play optimally, otherwise return false.

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: grid = ["####F","#C...","M...."], catJump = 1, mouseJump = 2\nOutput: true\nExplanation: Cat cannot catch Mouse on its turn nor can it get the food before Mouse.\n
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: grid = ["M.C...F"], catJump = 1, mouseJump = 4\nOutput: true\n
\n\n

Example 3:

\n\n
\nInput: grid = ["M.C...F"], catJump = 1, mouseJump = 3\nOutput: false\n
\n\n

Example 4:

\n\n
\nInput: grid = ["C...#","...#F","....#","M...."], catJump = 2, mouseJump = 5\nOutput: false\n
\n\n

Example 5:

\n\n
\nInput: grid = [".M...","..#..","#..#.","C#.#.","...#F"], catJump = 3, mouseJump = 1\nOutput: true\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • rows == grid.length
  • \n\t
  • cols = grid[i].length
  • \n\t
  • 1 <= rows, cols <= 8
  • \n\t
  • grid[i][j] consist only of characters 'C', 'M', 'F', '.', and '#'.
  • \n\t
  • There is only one of each character 'C', 'M', and 'F' in grid.
  • \n\t
  • 1 <= catJump, mouseJump <= 8
  • \n
\n", "content_cn": "

\u4e00\u53ea\u732b\u548c\u4e00\u53ea\u8001\u9f20\u5728\u73a9\u4e00\u4e2a\u53eb\u505a\u732b\u548c\u8001\u9f20\u7684\u6e38\u620f\u3002

\n\n

\u5b83\u4eec\u6240\u5904\u7684\u73af\u5883\u8bbe\u5b9a\u662f\u4e00\u4e2a\u00a0rows x cols\u00a0\u7684\u65b9\u683c grid\u00a0\uff0c\u5176\u4e2d\u6bcf\u4e2a\u683c\u5b50\u53ef\u80fd\u662f\u4e00\u5835\u5899\u3001\u4e00\u5757\u5730\u677f\u3001\u4e00\u4f4d\u73a9\u5bb6\uff08\u732b\u6216\u8005\u8001\u9f20\uff09\u6216\u8005\u98df\u7269\u3002

\n\n
    \n\t
  • \u73a9\u5bb6\u7531\u5b57\u7b26\u00a0'C'\u00a0\uff08\u4ee3\u8868\u732b\uff09\u548c\u00a0'M'\u00a0\uff08\u4ee3\u8868\u8001\u9f20\uff09\u8868\u793a\u3002
  • \n\t
  • \u5730\u677f\u7531\u5b57\u7b26\u00a0'.'\u00a0\u8868\u793a\uff0c\u73a9\u5bb6\u53ef\u4ee5\u901a\u8fc7\u8fd9\u4e2a\u683c\u5b50\u3002
  • \n\t
  • \u5899\u7528\u5b57\u7b26\u00a0'#'\u00a0\u8868\u793a\uff0c\u73a9\u5bb6\u4e0d\u80fd\u901a\u8fc7\u8fd9\u4e2a\u683c\u5b50\u3002
  • \n\t
  • \u98df\u7269\u7528\u5b57\u7b26\u00a0'F'\u00a0\u8868\u793a\uff0c\u73a9\u5bb6\u53ef\u4ee5\u901a\u8fc7\u8fd9\u4e2a\u683c\u5b50\u3002
  • \n\t
  • \u5b57\u7b26\u00a0'C'\u00a0\uff0c\u00a0'M'\u00a0\u548c\u00a0'F'\u00a0\u5728\u00a0grid\u00a0\u4e2d\u90fd\u53ea\u4f1a\u51fa\u73b0\u4e00\u6b21\u3002
  • \n
\n\n

\u732b\u548c\u8001\u9f20\u6309\u7167\u5982\u4e0b\u89c4\u5219\u79fb\u52a8\uff1a

\n\n
    \n\t
  • \u8001\u9f20 \u5148\u79fb\u52a8\u00a0\uff0c\u7136\u540e\u4e24\u540d\u73a9\u5bb6\u8f6e\u6d41\u79fb\u52a8\u3002
  • \n\t
  • \u6bcf\u4e00\u6b21\u64cd\u4f5c\u65f6\uff0c\u732b\u548c\u8001\u9f20\u53ef\u4ee5\u8df3\u5230\u4e0a\u4e0b\u5de6\u53f3\u56db\u4e2a\u65b9\u5411\u4e4b\u4e00\u7684\u683c\u5b50\uff0c\u4ed6\u4eec\u4e0d\u80fd\u8df3\u8fc7\u5899\u4e5f\u4e0d\u80fd\u8df3\u51fa\u00a0grid\u00a0\u3002
  • \n\t
  • catJump \u548c\u00a0mouseJump\u00a0\u662f\u732b\u548c\u8001\u9f20\u5206\u522b\u8df3\u4e00\u6b21\u80fd\u5230\u8fbe\u7684\u6700\u8fdc\u8ddd\u79bb\uff0c\u5b83\u4eec\u4e5f\u53ef\u4ee5\u8df3\u5c0f\u4e8e\u6700\u5927\u8ddd\u79bb\u7684\u957f\u5ea6\u3002
  • \n\t
  • \u5b83\u4eec\u53ef\u4ee5\u505c\u7559\u5728\u539f\u5730\u3002
  • \n\t
  • \u8001\u9f20\u53ef\u4ee5\u8df3\u8dc3\u8fc7\u732b\u7684\u4f4d\u7f6e\u3002
  • \n
\n\n

\u6e38\u620f\u6709 4 \u79cd\u65b9\u5f0f\u4f1a\u7ed3\u675f\uff1a

\n\n
    \n\t
  • \u5982\u679c\u732b\u8ddf\u8001\u9f20\u5904\u5728\u76f8\u540c\u7684\u4f4d\u7f6e\uff0c\u90a3\u4e48\u732b\u83b7\u80dc\u3002
  • \n\t
  • \u5982\u679c\u732b\u5148\u5230\u8fbe\u98df\u7269\uff0c\u90a3\u4e48\u732b\u83b7\u80dc\u3002
  • \n\t
  • \u5982\u679c\u8001\u9f20\u5148\u5230\u8fbe\u98df\u7269\uff0c\u90a3\u4e48\u8001\u9f20\u83b7\u80dc\u3002
  • \n\t
  • \u5982\u679c\u8001\u9f20\u4e0d\u80fd\u5728 1000 \u6b21\u64cd\u4f5c\u4ee5\u5185\u5230\u8fbe\u98df\u7269\uff0c\u90a3\u4e48\u732b\u83b7\u80dc\u3002
  • \n
\n\n

\u7ed9\u4f60\u00a0rows x cols\u00a0\u7684\u77e9\u9635\u00a0grid\u00a0\u548c\u4e24\u4e2a\u6574\u6570\u00a0catJump\u00a0\u548c\u00a0mouseJump\u00a0\uff0c\u53cc\u65b9\u90fd\u91c7\u53d6\u6700\u4f18\u7b56\u7565\uff0c\u5982\u679c\u8001\u9f20\u83b7\u80dc\uff0c\u90a3\u4e48\u8bf7\u4f60\u8fd4\u56de\u00a0true\u00a0\uff0c\u5426\u5219\u8fd4\u56de false\u00a0\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1agrid = [\"####F\",\"#C...\",\"M....\"], catJump = 1, mouseJump = 2\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u732b\u65e0\u6cd5\u6293\u5230\u8001\u9f20\uff0c\u4e5f\u6ca1\u6cd5\u6bd4\u8001\u9f20\u5148\u5230\u8fbe\u98df\u7269\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1agrid = [\"M.C...F\"], catJump = 1, mouseJump = 4\n\u8f93\u51fa\uff1atrue\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1agrid = [\"M.C...F\"], catJump = 1, mouseJump = 3\n\u8f93\u51fa\uff1afalse\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1agrid = [\"C...#\",\"...#F\",\"....#\",\"M....\"], catJump = 2, mouseJump = 5\n\u8f93\u51fa\uff1afalse\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\n\u8f93\u5165\uff1agrid = [\".M...\",\"..#..\",\"#..#.\",\"C#.#.\",\"...#F\"], catJump = 3, mouseJump = 1\n\u8f93\u51fa\uff1atrue\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • rows == grid.length
  • \n\t
  • cols = grid[i].length
  • \n\t
  • 1 <= rows, cols <= 8
  • \n\t
  • grid[i][j] \u53ea\u5305\u542b\u5b57\u7b26\u00a0'C'\u00a0\uff0c'M'\u00a0\uff0c'F'\u00a0\uff0c'.'\u00a0\u548c\u00a0'#'\u00a0\u3002
  • \n\t
  • grid\u00a0\u4e2d\u53ea\u5305\u542b\u4e00\u4e2a\u00a0'C'\u00a0\uff0c'M'\u00a0\u548c\u00a0'F'\u00a0\u3002
  • \n\t
  • 1 <= catJump, mouseJump <= 8
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canMouseWin(vector& grid, int catJump, int mouseJump) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canMouseWin(String[] grid, int catJump, int mouseJump) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canMouseWin(self, grid, catJump, mouseJump):\n \"\"\"\n :type grid: List[str]\n :type catJump: int\n :type mouseJump: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canMouseWin(self, grid: List[str], catJump: int, mouseJump: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canMouseWin(char ** grid, int gridSize, int catJump, int mouseJump){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanMouseWin(string[] grid, int catJump, int mouseJump) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} grid\n * @param {number} catJump\n * @param {number} mouseJump\n * @return {boolean}\n */\nvar canMouseWin = function(grid, catJump, mouseJump) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} grid\n# @param {Integer} cat_jump\n# @param {Integer} mouse_jump\n# @return {Boolean}\ndef can_mouse_win(grid, cat_jump, mouse_jump)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canMouseWin(_ grid: [String], _ catJump: Int, _ mouseJump: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canMouseWin(grid []string, catJump int, mouseJump int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canMouseWin(grid: Array[String], catJump: Int, mouseJump: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canMouseWin(grid: Array, catJump: Int, mouseJump: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_mouse_win(grid: Vec, cat_jump: i32, mouse_jump: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $grid\n * @param Integer $catJump\n * @param Integer $mouseJump\n * @return Boolean\n */\n function canMouseWin($grid, $catJump, $mouseJump) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canMouseWin(grid: string[], catJump: number, mouseJump: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-mouse-win grid catJump mouseJump)\n (-> (listof string?) exact-integer? exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1728](https://leetcode-cn.com/problems/cat-and-mouse-ii)", "[\u732b\u548c\u8001\u9f20 II](/solution/1700-1799/1728.Cat%20and%20Mouse%20II/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1728](https://leetcode.com/problems/cat-and-mouse-ii)", "[Cat and Mouse II](/solution/1700-1799/1728.Cat%20and%20Mouse%20II/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1726", "frontend_question_id": "1620", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/coordinate-with-maximum-network-quality", "url_en": "https://leetcode.com/problems/coordinate-with-maximum-network-quality", "relative_path_cn": "/solution/1600-1699/1620.Coordinate%20With%20Maximum%20Network%20Quality/README.md", "relative_path_en": "/solution/1600-1699/1620.Coordinate%20With%20Maximum%20Network%20Quality/README_EN.md", "title_cn": "\u7f51\u7edc\u4fe1\u53f7\u6700\u597d\u7684\u5750\u6807", "title_en": "Coordinate With Maximum Network Quality", "question_title_slug": "coordinate-with-maximum-network-quality", "content_en": "

You are given an array of network towers towers and an integer radius, where towers[i] = [xi, yi, qi] denotes the ith network tower with location (xi, yi) and quality factor qi. All the coordinates are integral coordinates on the X-Y plane, and the distance between two coordinates is the Euclidean distance.

\n\n

The integer radius denotes the maximum distance in which the tower is reachable. The tower is reachable if the distance is less than or equal to radius. Outside that distance, the signal becomes garbled, and the tower is not reachable.

\n\n

The signal quality of the ith tower at a coordinate (x, y) is calculated with the formula ⌊qi / (1 + d)⌋, where d is the distance between the tower and the coordinate. The network quality at a coordinate is the sum of the signal qualities from all the reachable towers.

\n\n

Return the integral coordinate where the network quality is maximum. If there are multiple coordinates with the same network quality, return the lexicographically minimum coordinate.

\n\n

Note:

\n\n
    \n\t
  • A coordinate (x1, y1) is lexicographically smaller than (x2, y2) if either x1 < x2 or x1 == x2 and y1 < y2.
  • \n\t
  • ⌊val⌋ is the greatest integer less than or equal to val (the floor function).
  • \n
\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: towers = [[1,2,5],[2,1,7],[3,1,9]], radius = 2\nOutput: [2,1]\nExplanation: \nAt coordinate (2, 1) the total quality is 13\n- Quality of 7 from (2, 1) results in ⌊7 / (1 + sqrt(0)⌋ = ⌊7⌋ = 7\n- Quality of 5 from (1, 2) results in ⌊5 / (1 + sqrt(2)⌋ = ⌊2.07⌋ = 2\n- Quality of 9 from (3, 1) results in ⌊9 / (1 + sqrt(1)⌋ = ⌊4.5⌋ = 4\nNo other coordinate has higher quality.
\n\n

Example 2:

\n\n
\nInput: towers = [[23,11,21]], radius = 9\nOutput: [23,11]\n
\n\n

Example 3:

\n\n
\nInput: towers = [[1,2,13],[2,1,7],[0,1,9]], radius = 2\nOutput: [1,2]\n
\n\n

Example 4:

\n\n
\nInput: towers = [[2,1,9],[0,1,9]], radius = 2\nOutput: [0,1]\nExplanation: Both (0, 1) and (2, 1) are optimal in terms of quality but (0, 1) is lexicograpically minimal.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= towers.length <= 50
  • \n\t
  • towers[i].length == 3
  • \n\t
  • 0 <= xi, yi, qi <= 50
  • \n\t
  • 1 <= radius <= 50
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 towers\u00a0\u548c\u4e00\u4e2a\u6574\u6570 radius\u00a0\uff0c\u6570\u7ec4\u4e2d\u5305\u542b\u4e00\u4e9b\u7f51\u7edc\u4fe1\u53f7\u5854\uff0c\u5176\u4e2d\u00a0towers[i] = [xi, yi, qi]\u00a0\u8868\u793a\u7b2c\u00a0i\u00a0\u4e2a\u7f51\u7edc\u4fe1\u53f7\u5854\u7684\u5750\u6807\u662f\u00a0(xi, yi)\u00a0\u4e14\u4fe1\u53f7\u5f3a\u5ea6\u53c2\u6570\u4e3a\u00a0qi\u00a0\u3002\u6240\u6709\u5750\u6807\u90fd\u662f\u5728\u00a0 X-Y \u5750\u6807\u7cfb\u5185\u7684\u00a0\u6574\u6570\u00a0\u5750\u6807\u3002\u4e24\u4e2a\u5750\u6807\u4e4b\u95f4\u7684\u8ddd\u79bb\u7528 \u6b27\u51e0\u91cc\u5f97\u8ddd\u79bb\u00a0\u8ba1\u7b97\u3002

\n\n

\u6574\u6570\u00a0radius\u00a0\u8868\u793a\u4e00\u4e2a\u5854 \u80fd\u5230\u8fbe\u00a0\u7684 \u6700\u8fdc\u8ddd\u79bb\u00a0\u3002\u5982\u679c\u4e00\u4e2a\u5750\u6807\u8ddf\u5854\u7684\u8ddd\u79bb\u5728 radius\u00a0\u4ee5\u5185\uff0c\u90a3\u4e48\u8be5\u5854\u7684\u4fe1\u53f7\u53ef\u4ee5\u5230\u8fbe\u8be5\u5750\u6807\u3002\u5728\u8fd9\u4e2a\u8303\u56f4\u4ee5\u5916\u4fe1\u53f7\u4f1a\u5f88\u5fae\u5f31\uff0c\u6240\u4ee5 radius\u00a0\u4ee5\u5916\u7684\u8ddd\u79bb\u8be5\u5854\u662f \u4e0d\u80fd\u5230\u8fbe\u7684\u00a0\u3002

\n\n

\u5982\u679c\u7b2c i\u00a0\u4e2a\u5854\u80fd\u5230\u8fbe (x, y)\u00a0\uff0c\u90a3\u4e48\u8be5\u5854\u5728\u6b64\u5904\u7684\u4fe1\u53f7\u4e3a\u00a0\u230aqi / (1 + d)\u230b\u00a0\uff0c\u5176\u4e2d\u00a0d\u00a0\u662f\u5854\u8ddf\u6b64\u5750\u6807\u7684\u8ddd\u79bb\u3002\u4e00\u4e2a\u5750\u6807\u7684 \u7f51\u7edc\u4fe1\u53f7\u00a0\u662f\u6240\u6709 \u80fd\u5230\u8fbe\u00a0\u8be5\u5750\u6807\u7684\u5854\u7684\u4fe1\u53f7\u5f3a\u5ea6\u4e4b\u548c\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de \u7f51\u7edc\u4fe1\u53f7\u00a0\u6700\u5927\u7684\u6574\u6570\u5750\u6807\u70b9\u3002\u5982\u679c\u6709\u591a\u4e2a\u5750\u6807\u7f51\u7edc\u4fe1\u53f7\u4e00\u6837\u5927\uff0c\u8bf7\u4f60\u8fd4\u56de\u5b57\u5178\u5e8f\u6700\u5c0f\u7684\u4e00\u4e2a\u5750\u6807\u3002

\n\n

\u6ce8\u610f\uff1a

\n\n
    \n\t
  • \u5750\u6807\u00a0(x1, y1)\u00a0\u5b57\u5178\u5e8f\u6bd4\u53e6\u4e00\u4e2a\u5750\u6807\u00a0(x2, y2)\u00a0\u5c0f\uff1a\u8981\u4e48\u00a0x1 < x2\u00a0\uff0c\u8981\u4e48\u00a0x1 == x2 \u4e14\u00a0y1 < y2\u00a0\u3002
  • \n\t
  • \u230aval\u230b\u00a0\u8868\u793a\u5c0f\u4e8e\u7b49\u4e8e\u00a0val\u00a0\u7684\u6700\u5927\u6574\u6570\uff08\u5411\u4e0b\u53d6\u6574\u51fd\u6570\uff09\u3002
  • \n
\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1atowers = [[1,2,5],[2,1,7],[3,1,9]], radius = 2\n\u8f93\u51fa\uff1a[2,1]\n\u89e3\u91ca\uff1a\n\u5750\u6807 (2, 1) \u4fe1\u53f7\u5f3a\u5ea6\u4e4b\u548c\u4e3a 13\n- \u5854 (2, 1) \u5f3a\u5ea6\u53c2\u6570\u4e3a 7 \uff0c\u5728\u8be5\u70b9\u5f3a\u5ea6\u4e3a \u230a7 / (1 + sqrt(0)\u230b = \u230a7\u230b = 7\n- \u5854 (1, 2) \u5f3a\u5ea6\u53c2\u6570\u4e3a 5 \uff0c\u5728\u8be5\u70b9\u5f3a\u5ea6\u4e3a \u230a5 / (1 + sqrt(2)\u230b = \u230a2.07\u230b = 2\n- \u5854 (3, 1) \u5f3a\u5ea6\u53c2\u6570\u4e3a 9 \uff0c\u5728\u8be5\u70b9\u5f3a\u5ea6\u4e3a \u230a9 / (1 + sqrt(1)\u230b = \u230a4.5\u230b = 4\n\u6ca1\u6709\u522b\u7684\u5750\u6807\u6709\u66f4\u5927\u7684\u4fe1\u53f7\u5f3a\u5ea6\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1atowers = [[23,11,21]], radius = 9\n\u8f93\u51fa\uff1a[23,11]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1atowers = [[1,2,13],[2,1,7],[0,1,9]], radius = 2\n\u8f93\u51fa\uff1a[1,2]\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1atowers = [[2,1,9],[0,1,9]], radius = 2\n\u8f93\u51fa\uff1a[0,1]\n\u89e3\u91ca\uff1a\u5750\u6807 (0, 1) \u548c\u5750\u6807 (2, 1) \u90fd\u662f\u5f3a\u5ea6\u6700\u5927\u7684\u4f4d\u7f6e\uff0c\u4f46\u662f (0, 1) \u5b57\u5178\u5e8f\u66f4\u5c0f\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= towers.length <= 50
  • \n\t
  • towers[i].length == 3
  • \n\t
  • 0 <= xi, yi, qi <= 50
  • \n\t
  • 1 <= radius <= 50
  • \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector bestCoordinate(vector>& towers, int radius) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] bestCoordinate(int[][] towers, int radius) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def bestCoordinate(self, towers, radius):\n \"\"\"\n :type towers: List[List[int]]\n :type radius: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def bestCoordinate(self, towers: List[List[int]], radius: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* bestCoordinate(int** towers, int towersSize, int* towersColSize, int radius, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] BestCoordinate(int[][] towers, int radius) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} towers\n * @param {number} radius\n * @return {number[]}\n */\nvar bestCoordinate = function(towers, radius) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} towers\n# @param {Integer} radius\n# @return {Integer[]}\ndef best_coordinate(towers, radius)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func bestCoordinate(_ towers: [[Int]], _ radius: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func bestCoordinate(towers [][]int, radius int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def bestCoordinate(towers: Array[Array[Int]], radius: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun bestCoordinate(towers: Array, radius: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn best_coordinate(towers: Vec>, radius: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $towers\n * @param Integer $radius\n * @return Integer[]\n */\n function bestCoordinate($towers, $radius) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function bestCoordinate(towers: number[][], radius: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (best-coordinate towers radius)\n (-> (listof (listof exact-integer?)) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1620](https://leetcode-cn.com/problems/coordinate-with-maximum-network-quality)", "[\u7f51\u7edc\u4fe1\u53f7\u6700\u597d\u7684\u5750\u6807](/solution/1600-1699/1620.Coordinate%20With%20Maximum%20Network%20Quality/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1620](https://leetcode.com/problems/coordinate-with-maximum-network-quality)", "[Coordinate With Maximum Network Quality](/solution/1600-1699/1620.Coordinate%20With%20Maximum%20Network%20Quality/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1725", "frontend_question_id": "1621", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-sets-of-k-non-overlapping-line-segments", "url_en": "https://leetcode.com/problems/number-of-sets-of-k-non-overlapping-line-segments", "relative_path_cn": "/solution/1600-1699/1621.Number%20of%20Sets%20of%20K%20Non-Overlapping%20Line%20Segments/README.md", "relative_path_en": "/solution/1600-1699/1621.Number%20of%20Sets%20of%20K%20Non-Overlapping%20Line%20Segments/README_EN.md", "title_cn": "\u5927\u5c0f\u4e3a K \u7684\u4e0d\u91cd\u53e0\u7ebf\u6bb5\u7684\u6570\u76ee", "title_en": "Number of Sets of K Non-Overlapping Line Segments", "question_title_slug": "number-of-sets-of-k-non-overlapping-line-segments", "content_en": "

Given n points on a 1-D plane, where the ith point (from 0 to n-1) is at x = i, find the number of ways we can draw exactly k non-overlapping line segments such that each segment covers two or more points. The endpoints of each segment must have integral coordinates. The k line segments do not have to cover all n points, and they are allowed to share endpoints.

\n\n

Return the number of ways we can draw k non-overlapping line segments. Since this number can be huge, return it modulo 109 + 7.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: n = 4, k = 2\nOutput: 5\nExplanation: \nThe two line segments are shown in red and blue.\nThe image above shows the 5 different ways {(0,2),(2,3)}, {(0,1),(1,3)}, {(0,1),(2,3)}, {(1,2),(2,3)}, {(0,1),(1,2)}.
\n\n

Example 2:

\n\n
\nInput: n = 3, k = 1\nOutput: 3\nExplanation: The 3 ways are {(0,1)}, {(0,2)}, {(1,2)}.\n
\n\n

Example 3:

\n\n
\nInput: n = 30, k = 7\nOutput: 796297179\nExplanation: The total number of possible ways to draw 7 line segments is 3796297200. Taking this number modulo 109 + 7 gives us 796297179.\n
\n\n

Example 4:

\n\n
\nInput: n = 5, k = 3\nOutput: 7\n
\n\n

Example 5:

\n\n
\nInput: n = 3, k = 2\nOutput: 1
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= n <= 1000
  • \n\t
  • 1 <= k <= n-1
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u7ef4\u7a7a\u95f4\u7684\u00a0n\u00a0\u4e2a\u70b9\uff0c\u5176\u4e2d\u7b2c\u00a0i\u00a0\u4e2a\u70b9\uff08\u7f16\u53f7\u4ece\u00a00 \u5230\u00a0n-1\uff09\u4f4d\u4e8e\u00a0x = i\u00a0\u5904\uff0c\u8bf7\u4f60\u627e\u5230\u00a0\u6070\u597d\u00a0k\u00a0\u4e2a\u4e0d\u91cd\u53e0\u00a0\u7ebf\u6bb5\u4e14\u6bcf\u4e2a\u7ebf\u6bb5\u81f3\u5c11\u8986\u76d6\u4e24\u4e2a\u70b9\u7684\u65b9\u6848\u6570\u3002\u7ebf\u6bb5\u7684\u4e24\u4e2a\u7aef\u70b9\u5fc5\u987b\u90fd\u662f\u00a0\u6574\u6570\u5750\u6807\u00a0\u3002\u8fd9\u00a0k\u00a0\u4e2a\u7ebf\u6bb5\u4e0d\u9700\u8981\u5168\u90e8\u8986\u76d6\u5168\u90e8\u00a0n\u00a0\u4e2a\u70b9\uff0c\u4e14\u5b83\u4eec\u7684\u7aef\u70b9\u00a0\u53ef\u4ee5\u00a0\u91cd\u5408\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de k\u00a0\u4e2a\u4e0d\u91cd\u53e0\u7ebf\u6bb5\u7684\u65b9\u6848\u6570\u3002\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u5f88\u5927\uff0c\u8bf7\u5c06\u7ed3\u679c\u5bf9\u00a0109 + 7\u00a0\u53d6\u4f59 \u540e\u8fd4\u56de\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1an = 4, k = 2\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\n\u5982\u56fe\u6240\u793a\uff0c\u4e24\u4e2a\u7ebf\u6bb5\u5206\u522b\u7528\u7ea2\u8272\u548c\u84dd\u8272\u6807\u51fa\u3002\n\u4e0a\u56fe\u5c55\u793a\u4e86 5 \u79cd\u4e0d\u540c\u7684\u65b9\u6848 {(0,2),(2,3)}\uff0c{(0,1),(1,3)}\uff0c{(0,1),(2,3)}\uff0c{(1,2),(2,3)}\uff0c{(0,1),(1,2)} \u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1an = 3, k = 1\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u603b\u5171\u6709 3 \u79cd\u4e0d\u540c\u7684\u65b9\u6848 {(0,1)}, {(0,2)}, {(1,2)} \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1an = 30, k = 7\n\u8f93\u51fa\uff1a796297179\n\u89e3\u91ca\uff1a\u753b 7 \u6761\u7ebf\u6bb5\u7684\u603b\u65b9\u6848\u6570\u4e3a 3796297200 \u79cd\u3002\u5c06\u8fd9\u4e2a\u6570\u5bf9 109 + 7 \u53d6\u4f59\u5f97\u5230 796297179 \u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1an = 5, k = 3\n\u8f93\u51fa\uff1a7\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\n\u8f93\u5165\uff1an = 3, k = 2\n\u8f93\u51fa\uff1a1
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= n <= 1000
  • \n\t
  • 1 <= k <= n-1
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numberOfSets(int n, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numberOfSets(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numberOfSets(self, n, k):\n \"\"\"\n :type n: int\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numberOfSets(self, n: int, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numberOfSets(int n, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumberOfSets(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} k\n * @return {number}\n */\nvar numberOfSets = function(n, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} k\n# @return {Integer}\ndef number_of_sets(n, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numberOfSets(_ n: Int, _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numberOfSets(n int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numberOfSets(n: Int, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numberOfSets(n: Int, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn number_of_sets(n: i32, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $k\n * @return Integer\n */\n function numberOfSets($n, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numberOfSets(n: number, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (number-of-sets n k)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1621](https://leetcode-cn.com/problems/number-of-sets-of-k-non-overlapping-line-segments)", "[\u5927\u5c0f\u4e3a K \u7684\u4e0d\u91cd\u53e0\u7ebf\u6bb5\u7684\u6570\u76ee](/solution/1600-1699/1621.Number%20of%20Sets%20of%20K%20Non-Overlapping%20Line%20Segments/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1621](https://leetcode.com/problems/number-of-sets-of-k-non-overlapping-line-segments)", "[Number of Sets of K Non-Overlapping Line Segments](/solution/1600-1699/1621.Number%20of%20Sets%20of%20K%20Non-Overlapping%20Line%20Segments/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "1724", "frontend_question_id": "1581", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/customer-who-visited-but-did-not-make-any-transactions", "url_en": "https://leetcode.com/problems/customer-who-visited-but-did-not-make-any-transactions", "relative_path_cn": "/solution/1500-1599/1581.Customer%20Who%20Visited%20but%20Did%20Not%20Make%20Any%20Transactions/README.md", "relative_path_en": "/solution/1500-1599/1581.Customer%20Who%20Visited%20but%20Did%20Not%20Make%20Any%20Transactions/README_EN.md", "title_cn": "\u8fdb\u5e97\u5374\u672a\u8fdb\u884c\u8fc7\u4ea4\u6613\u7684\u987e\u5ba2", "title_en": "Customer Who Visited but Did Not Make Any Transactions", "question_title_slug": "customer-who-visited-but-did-not-make-any-transactions", "content_en": "

Table: Visits

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| visit_id    | int     |\n| customer_id | int     |\n+-------------+---------+\nvisit_id is the primary key for this table.\nThis table contains information about the customers who visited the mall.\n
\n\n

 

\n\n

Table: Transactions

\n\n
\n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| transaction_id | int     |\n| visit_id       | int     |\n| amount         | int     |\n+----------------+---------+\ntransaction_id is the primary key for this table.\nThis table contains information about the transactions made during the visit_id.\n
\n\n

 

\n\n

Write an SQL query to find the IDs of the users who visited without making any transactions and the number of times they made these types of visits.

\n\n

Return the result table sorted in any order.

\n\n

The query result format is in the following example:

\n\n
\nVisits\n+----------+-------------+\n| visit_id | customer_id |\n+----------+-------------+\n| 1        | 23          |\n| 2        | 9           |\n| 4        | 30          |\n| 5        | 54          |\n| 6        | 96          |\n| 7        | 54          |\n| 8        | 54          |\n+----------+-------------+\n\nTransactions\n+----------------+----------+--------+\n| transaction_id | visit_id | amount |\n+----------------+----------+--------+\n| 2              | 5        | 310    |\n| 3              | 5        | 300    |\n| 9              | 5        | 200    |\n| 12             | 1        | 910    |\n| 13             | 2        | 970    |\n+----------------+----------+--------+\n\nResult table:\n+-------------+----------------+\n| customer_id | count_no_trans |\n+-------------+----------------+\n| 54          | 2              |\n| 30          | 1              |\n| 96          | 1              |\n+-------------+----------------+\nCustomer with id = 23 visited the mall once and made one transaction during the visit with id = 12.\nCustomer with id = 9 visited the mall once and made one transaction during the visit with id = 13.\nCustomer with id = 30 visited the mall once and did not make any transactions.\nCustomer with id = 54 visited the mall three times. During 2 visits they did not make any transactions, and during one visit they made 3 transactions.\nCustomer with id = 96 visited the mall once and did not make any transactions.\nAs we can see, users with IDs 30 and 96 visited the mall one time without making any transactions. Also user 54 visited the mall twice and did not make any transactions.\n
\n", "content_cn": "

\u8868\uff1aVisits

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| visit_id    | int     |\n| customer_id | int     |\n+-------------+---------+\nvisit_id \u662f\u8be5\u8868\u7684\u4e3b\u952e\u3002\n\u8be5\u8868\u5305\u542b\u6709\u5173\u5149\u4e34\u8fc7\u8d2d\u7269\u4e2d\u5fc3\u7684\u987e\u5ba2\u7684\u4fe1\u606f\u3002\n
\n\n

\u00a0

\n\n

\u8868\uff1aTransactions

\n\n
\n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| transaction_id | int     |\n| visit_id       | int     |\n| amount         | int     |\n+----------------+---------+\ntransaction_id \u662f\u6b64\u8868\u7684\u4e3b\u952e\u3002\n\u6b64\u8868\u5305\u542b visit_id \u671f\u95f4\u8fdb\u884c\u7684\u4ea4\u6613\u7684\u4fe1\u606f\u3002\n
\n\n

\u6709\u4e00\u4e9b\u987e\u5ba2\u53ef\u80fd\u5149\u987e\u4e86\u8d2d\u7269\u4e2d\u5fc3\u4f46\u6ca1\u6709\u8fdb\u884c\u4ea4\u6613\u3002\u8bf7\u4f60\u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\uff0c\u6765\u67e5\u627e\u8fd9\u4e9b\u987e\u5ba2\u7684 ID \uff0c\u4ee5\u53ca\u4ed6\u4eec\u53ea\u5149\u987e\u4e0d\u4ea4\u6613\u7684\u6b21\u6570\u3002

\n\n

\u8fd4\u56de\u4ee5\u4efb\u4f55\u987a\u5e8f\u6392\u5e8f\u7684\u7ed3\u679c\u8868\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a\uff1a

\n\n
\nVisits\n+----------+-------------+\n| visit_id | customer_id |\n+----------+-------------+\n| 1        | 23          |\n| 2        | 9           |\n| 4        | 30          |\n| 5        | 54          |\n| 6        | 96          |\n| 7        | 54          |\n| 8        | 54          |\n+----------+-------------+\n\nTransactions\n+----------------+----------+--------+\n| transaction_id | visit_id | amount |\n+----------------+----------+--------+\n| 2              | 5        | 310    |\n| 3              | 5        | 300    |\n| 9              | 5        | 200    |\n| 12             | 1        | 910    |\n| 13             | 2        | 970    |\n+----------------+----------+--------+\n\nResult \u8868\uff1a\n+-------------+----------------+\n| customer_id | count_no_trans |\n+-------------+----------------+\n| 54          | 2              |\n| 30          | 1              |\n| 96          | 1              |\n+-------------+----------------+\nID = 23 \u7684\u987e\u5ba2\u66fe\u7ecf\u901b\u8fc7\u4e00\u6b21\u8d2d\u7269\u4e2d\u5fc3\uff0c\u5e76\u5728 ID = 12 \u7684\u8bbf\u95ee\u671f\u95f4\u8fdb\u884c\u4e86\u4e00\u7b14\u4ea4\u6613\u3002\nID = 9 \u7684\u987e\u5ba2\u66fe\u7ecf\u901b\u8fc7\u4e00\u6b21\u8d2d\u7269\u4e2d\u5fc3\uff0c\u5e76\u5728 ID = 13 \u7684\u8bbf\u95ee\u671f\u95f4\u8fdb\u884c\u4e86\u4e00\u7b14\u4ea4\u6613\u3002\nID = 30 \u7684\u987e\u5ba2\u66fe\u7ecf\u53bb\u8fc7\u8d2d\u7269\u4e2d\u5fc3\uff0c\u5e76\u4e14\u6ca1\u6709\u8fdb\u884c\u4efb\u4f55\u4ea4\u6613\u3002\nID = 54 \u7684\u987e\u5ba2\u4e09\u5ea6\u9020\u8bbf\u4e86\u8d2d\u7269\u4e2d\u5fc3\u3002\u5728 2 \u6b21\u8bbf\u95ee\u4e2d\uff0c\u4ed6\u4eec\u6ca1\u6709\u8fdb\u884c\u4efb\u4f55\u4ea4\u6613\uff0c\u5728 1 \u6b21\u8bbf\u95ee\u4e2d\uff0c\u4ed6\u4eec\u8fdb\u884c\u4e86 3 \u6b21\u4ea4\u6613\u3002\nID = 96 \u7684\u987e\u5ba2\u66fe\u7ecf\u53bb\u8fc7\u8d2d\u7269\u4e2d\u5fc3\uff0c\u5e76\u4e14\u6ca1\u6709\u8fdb\u884c\u4efb\u4f55\u4ea4\u6613\u3002\n\u5982\u6211\u4eec\u6240\u89c1\uff0cID \u4e3a 30 \u548c 96 \u7684\u987e\u5ba2\u4e00\u6b21\u6ca1\u6709\u8fdb\u884c\u4efb\u4f55\u4ea4\u6613\u5c31\u53bb\u4e86\u8d2d\u7269\u4e2d\u5fc3\u3002\u987e\u5ba2 54 \u4e5f\u4e24\u6b21\u8bbf\u95ee\u4e86\u8d2d\u7269\u4e2d\u5fc3\u5e76\u4e14\u6ca1\u6709\u8fdb\u884c\u4efb\u4f55\u4ea4\u6613\u3002\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1581](https://leetcode-cn.com/problems/customer-who-visited-but-did-not-make-any-transactions)", "[\u8fdb\u5e97\u5374\u672a\u8fdb\u884c\u8fc7\u4ea4\u6613\u7684\u987e\u5ba2](/solution/1500-1599/1581.Customer%20Who%20Visited%20but%20Did%20Not%20Make%20Any%20Transactions/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1581](https://leetcode.com/problems/customer-who-visited-but-did-not-make-any-transactions)", "[Customer Who Visited but Did Not Make Any Transactions](/solution/1500-1599/1581.Customer%20Who%20Visited%20but%20Did%20Not%20Make%20Any%20Transactions/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1723", "frontend_question_id": "1601", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-number-of-achievable-transfer-requests", "url_en": "https://leetcode.com/problems/maximum-number-of-achievable-transfer-requests", "relative_path_cn": "/solution/1600-1699/1601.Maximum%20Number%20of%20Achievable%20Transfer%20Requests/README.md", "relative_path_en": "/solution/1600-1699/1601.Maximum%20Number%20of%20Achievable%20Transfer%20Requests/README_EN.md", "title_cn": "\u6700\u591a\u53ef\u8fbe\u6210\u7684\u6362\u697c\u8bf7\u6c42\u6570\u76ee", "title_en": "Maximum Number of Achievable Transfer Requests", "question_title_slug": "maximum-number-of-achievable-transfer-requests", "content_en": "

We have n buildings numbered from 0 to n - 1. Each building has a number of employees. It's transfer season, and some employees want to change the building they reside in.

\n\n

You are given an array requests where requests[i] = [fromi, toi] represents an employee's request to transfer from building fromi to building toi.

\n\n

All buildings are full, so a list of requests is achievable only if for each building, the net change in employee transfers is zero. This means the number of employees leaving is equal to the number of employees moving in. For example if n = 3 and two employees are leaving building 0, one is leaving building 1, and one is leaving building 2, there should be two employees moving to building 0, one employee moving to building 1, and one employee moving to building 2.

\n\n

Return the maximum number of achievable requests.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: n = 5, requests = [[0,1],[1,0],[0,1],[1,2],[2,0],[3,4]]\nOutput: 5\nExplantion: Let's see the requests:\nFrom building 0 we have employees x and y and both want to move to building 1.\nFrom building 1 we have employees a and b and they want to move to buildings 2 and 0 respectively.\nFrom building 2 we have employee z and they want to move to building 0.\nFrom building 3 we have employee c and they want to move to building 4.\nFrom building 4 we don't have any requests.\nWe can achieve the requests of users x and b by swapping their places.\nWe can achieve the requests of users y, a and z by swapping the places in the 3 buildings.\n
\n\n

Example 2:

\n\"\"\n
\nInput: n = 3, requests = [[0,0],[1,2],[2,1]]\nOutput: 3\nExplantion: Let's see the requests:\nFrom building 0 we have employee x and they want to stay in the same building 0.\nFrom building 1 we have employee y and they want to move to building 2.\nFrom building 2 we have employee z and they want to move to building 1.\nWe can achieve all the requests. 
\n\n

Example 3:

\n\n
\nInput: n = 4, requests = [[0,3],[3,1],[1,2],[2,0]]\nOutput: 4\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 20
  • \n\t
  • 1 <= requests.length <= 16
  • \n\t
  • requests[i].length == 2
  • \n\t
  • 0 <= fromi, toi < n
  • \n
\n", "content_cn": "

\u6211\u4eec\u6709 n \u680b\u697c\uff0c\u7f16\u53f7\u4ece 0 \u5230 n - 1 \u3002\u6bcf\u680b\u697c\u6709\u82e5\u5e72\u5458\u5de5\u3002\u7531\u4e8e\u73b0\u5728\u662f\u6362\u697c\u7684\u5b63\u8282\uff0c\u90e8\u5206\u5458\u5de5\u60f3\u8981\u6362\u4e00\u680b\u697c\u5c45\u4f4f\u3002

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 requests \uff0c\u5176\u4e2d requests[i] = [fromi, toi] \uff0c\u8868\u793a\u4e00\u4e2a\u5458\u5de5\u8bf7\u6c42\u4ece\u7f16\u53f7\u4e3a fromi \u7684\u697c\u642c\u5230\u7f16\u53f7\u4e3a toi \u7684\u697c\u3002

\n\n

\u4e00\u5f00\u59cb \u6240\u6709\u697c\u90fd\u662f\u6ee1\u7684\uff0c\u6240\u4ee5\u4ece\u8bf7\u6c42\u5217\u8868\u4e2d\u9009\u51fa\u7684\u82e5\u5e72\u4e2a\u8bf7\u6c42\u662f\u53ef\u884c\u7684\u9700\u8981\u6ee1\u8db3 \u6bcf\u680b\u697c\u5458\u5de5\u51c0\u53d8\u5316\u4e3a 0 \u3002\u610f\u601d\u662f\u6bcf\u680b\u697c \u79bb\u5f00 \u7684\u5458\u5de5\u6570\u76ee \u7b49\u4e8e \u8be5\u697c \u642c\u5165 \u7684\u5458\u5de5\u6570\u6570\u76ee\u3002\u6bd4\u65b9\u8bf4 n = 3 \u4e14\u4e24\u4e2a\u5458\u5de5\u8981\u79bb\u5f00\u697c 0 \uff0c\u4e00\u4e2a\u5458\u5de5\u8981\u79bb\u5f00\u697c 1 \uff0c\u4e00\u4e2a\u5458\u5de5\u8981\u79bb\u5f00\u697c 2 \uff0c\u5982\u679c\u8be5\u8bf7\u6c42\u5217\u8868\u53ef\u884c\uff0c\u5e94\u8be5\u8981\u6709\u4e24\u4e2a\u5458\u5de5\u642c\u5165\u697c 0 \uff0c\u4e00\u4e2a\u5458\u5de5\u642c\u5165\u697c 1 \uff0c\u4e00\u4e2a\u5458\u5de5\u642c\u5165\u697c 2 \u3002

\n\n

\u8bf7\u4f60\u4ece\u539f\u8bf7\u6c42\u5217\u8868\u4e2d\u9009\u51fa\u82e5\u5e72\u4e2a\u8bf7\u6c42\uff0c\u4f7f\u5f97\u5b83\u4eec\u662f\u4e00\u4e2a\u53ef\u884c\u7684\u8bf7\u6c42\u5217\u8868\uff0c\u5e76\u8fd4\u56de\u6240\u6709\u53ef\u884c\u5217\u8868\u4e2d\u6700\u5927\u8bf7\u6c42\u6570\u76ee\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1an = 5, requests = [[0,1],[1,0],[0,1],[1,2],[2,0],[3,4]]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u8bf7\u6c42\u5217\u8868\u5982\u4e0b\uff1a\n\u4ece\u697c 0 \u79bb\u5f00\u7684\u5458\u5de5\u4e3a x \u548c y \uff0c\u4e14\u4ed6\u4eec\u90fd\u60f3\u8981\u642c\u5230\u697c 1 \u3002\n\u4ece\u697c 1 \u79bb\u5f00\u7684\u5458\u5de5\u4e3a a \u548c b \uff0c\u4e14\u4ed6\u4eec\u5206\u522b\u60f3\u8981\u642c\u5230\u697c 2 \u548c 0 \u3002\n\u4ece\u697c 2 \u79bb\u5f00\u7684\u5458\u5de5\u4e3a z \uff0c\u4e14\u4ed6\u60f3\u8981\u642c\u5230\u697c 0 \u3002\n\u4ece\u697c 3 \u79bb\u5f00\u7684\u5458\u5de5\u4e3a c \uff0c\u4e14\u4ed6\u60f3\u8981\u642c\u5230\u697c 4 \u3002\n\u6ca1\u6709\u5458\u5de5\u4ece\u697c 4 \u79bb\u5f00\u3002\n\u6211\u4eec\u53ef\u4ee5\u8ba9 x \u548c b \u4ea4\u6362\u4ed6\u4eec\u7684\u697c\uff0c\u4ee5\u6ee1\u8db3\u4ed6\u4eec\u7684\u8bf7\u6c42\u3002\n\u6211\u4eec\u53ef\u4ee5\u8ba9 y\uff0ca \u548c z \u4e09\u4eba\u5728\u4e09\u680b\u697c\u95f4\u4ea4\u6362\u4f4d\u7f6e\uff0c\u6ee1\u8db3\u4ed6\u4eec\u7684\u8981\u6c42\u3002\n\u6240\u4ee5\u6700\u591a\u53ef\u4ee5\u6ee1\u8db3 5 \u4e2a\u8bf7\u6c42\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1an = 3, requests = [[0,0],[1,2],[2,1]]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u8bf7\u6c42\u5217\u8868\u5982\u4e0b\uff1a\n\u4ece\u697c 0 \u79bb\u5f00\u7684\u5458\u5de5\u4e3a x \uff0c\u4e14\u4ed6\u60f3\u8981\u56de\u5230\u539f\u6765\u7684\u697c 0 \u3002\n\u4ece\u697c 1 \u79bb\u5f00\u7684\u5458\u5de5\u4e3a y \uff0c\u4e14\u4ed6\u60f3\u8981\u642c\u5230\u697c 2 \u3002\n\u4ece\u697c 2 \u79bb\u5f00\u7684\u5458\u5de5\u4e3a z \uff0c\u4e14\u4ed6\u60f3\u8981\u642c\u5230\u697c 1 \u3002\n\u6211\u4eec\u53ef\u4ee5\u6ee1\u8db3\u6240\u6709\u7684\u8bf7\u6c42\u3002
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1an = 4, requests = [[0,3],[3,1],[1,2],[2,0]]\n\u8f93\u51fa\uff1a4\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 20
  • \n\t
  • 1 <= requests.length <= 16
  • \n\t
  • requests[i].length == 2
  • \n\t
  • 0 <= fromi, toi < n
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maximumRequests(int n, vector>& requests) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maximumRequests(int n, int[][] requests) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximumRequests(self, n, requests):\n \"\"\"\n :type n: int\n :type requests: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximumRequests(self, n: int, requests: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maximumRequests(int n, int** requests, int requestsSize, int* requestsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaximumRequests(int n, int[][] requests) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} requests\n * @return {number}\n */\nvar maximumRequests = function(n, requests) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} requests\n# @return {Integer}\ndef maximum_requests(n, requests)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximumRequests(_ n: Int, _ requests: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximumRequests(n int, requests [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximumRequests(n: Int, requests: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximumRequests(n: Int, requests: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximum_requests(n: i32, requests: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $requests\n * @return Integer\n */\n function maximumRequests($n, $requests) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximumRequests(n: number, requests: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximum-requests n requests)\n (-> exact-integer? (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1601](https://leetcode-cn.com/problems/maximum-number-of-achievable-transfer-requests)", "[\u6700\u591a\u53ef\u8fbe\u6210\u7684\u6362\u697c\u8bf7\u6c42\u6570\u76ee](/solution/1600-1699/1601.Maximum%20Number%20of%20Achievable%20Transfer%20Requests/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1601](https://leetcode.com/problems/maximum-number-of-achievable-transfer-requests)", "[Maximum Number of Achievable Transfer Requests](/solution/1600-1699/1601.Maximum%20Number%20of%20Achievable%20Transfer%20Requests/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1722", "frontend_question_id": "1600", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/throne-inheritance", "url_en": "https://leetcode.com/problems/throne-inheritance", "relative_path_cn": "/solution/1600-1699/1600.Throne%20Inheritance/README.md", "relative_path_en": "/solution/1600-1699/1600.Throne%20Inheritance/README_EN.md", "title_cn": "\u7687\u4f4d\u7ee7\u627f\u987a\u5e8f", "title_en": "Throne Inheritance", "question_title_slug": "throne-inheritance", "content_en": "

A kingdom consists of a king, his children, his grandchildren, and so on. Every once in a while, someone in the family dies or a child is born.

\n\n

The kingdom has a well-defined order of inheritance that consists of the king as the first member. Let's define the recursive function Successor(x, curOrder), which given a person x and the inheritance order so far, returns who should be the next person after x in the order of inheritance.

\n\n
\nSuccessor(x, curOrder):\n    if x has no children or all of x's children are in curOrder:\n        if x is the king return null\n        else return Successor(x's parent, curOrder)\n    else return x's oldest child who's not in curOrder\n
\n\n

For example, assume we have a kingdom that consists of the king, his children Alice and Bob (Alice is older than Bob), and finally Alice's son Jack.

\n\n
    \n\t
  1. In the beginning, curOrder will be ["king"].
  2. \n\t
  3. Calling Successor(king, curOrder) will return Alice, so we append to curOrder to get ["king", "Alice"].
  4. \n\t
  5. Calling Successor(Alice, curOrder) will return Jack, so we append to curOrder to get ["king", "Alice", "Jack"].
  6. \n\t
  7. Calling Successor(Jack, curOrder) will return Bob, so we append to curOrder to get ["king", "Alice", "Jack", "Bob"].
  8. \n\t
  9. Calling Successor(Bob, curOrder) will return null. Thus the order of inheritance will be ["king", "Alice", "Jack", "Bob"].
  10. \n
\n\n

Using the above function, we can always obtain a unique order of inheritance.

\n\n

Implement the ThroneInheritance class:

\n\n
    \n\t
  • ThroneInheritance(string kingName) Initializes an object of the ThroneInheritance class. The name of the king is given as part of the constructor.
  • \n\t
  • void birth(string parentName, string childName) Indicates that parentName gave birth to childName.
  • \n\t
  • void death(string name) Indicates the death of name. The death of the person doesn't affect the Successor function nor the current inheritance order. You can treat it as just marking the person as dead.
  • \n\t
  • string[] getInheritanceOrder() Returns a list representing the current order of inheritance excluding dead people.
  • \n
\n\n

 

\n

Example 1:

\n\n
\nInput\n["ThroneInheritance", "birth", "birth", "birth", "birth", "birth", "birth", "getInheritanceOrder", "death", "getInheritanceOrder"]\n[["king"], ["king", "andy"], ["king", "bob"], ["king", "catherine"], ["andy", "matthew"], ["bob", "alex"], ["bob", "asha"], [null], ["bob"], [null]]\nOutput\n[null, null, null, null, null, null, null, ["king", "andy", "matthew", "bob", "alex", "asha", "catherine"], null, ["king", "andy", "matthew", "alex", "asha", "catherine"]]\n\nExplanation\nThroneInheritance t= new ThroneInheritance("king"); // order: king\nt.birth("king", "andy"); // order: king > andy\nt.birth("king", "bob"); // order: king > andy > bob\nt.birth("king", "catherine"); // order: king > andy > bob > catherine\nt.birth("andy", "matthew"); // order: king > andy > matthew > bob > catherine\nt.birth("bob", "alex"); // order: king > andy > matthew > bob > alex > catherine\nt.birth("bob", "asha"); // order: king > andy > matthew > bob > alex > asha > catherine\nt.getInheritanceOrder(); // return ["king", "andy", "matthew", "bob", "alex", "asha", "catherine"]\nt.death("bob"); // order: king > andy > matthew > bob > alex > asha > catherine\nt.getInheritanceOrder(); // return ["king", "andy", "matthew", "alex", "asha", "catherine"]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= kingName.length, parentName.length, childName.length, name.length <= 15
  • \n\t
  • kingName, parentName, childName, and name consist of lowercase English letters only.
  • \n\t
  • All arguments childName and kingName are distinct.
  • \n\t
  • All name arguments of death will be passed to either the constructor or as childName to birth first.
  • \n\t
  • For each call to birth(parentName, childName), it is guaranteed that parentName is alive.
  • \n\t
  • At most 105 calls will be made to birth and death.
  • \n\t
  • At most 10 calls will be made to getInheritanceOrder.
  • \n
\n", "content_cn": "

\u4e00\u4e2a\u738b\u56fd\u91cc\u4f4f\u7740\u56fd\u738b\u3001\u4ed6\u7684\u5b69\u5b50\u4eec\u3001\u4ed6\u7684\u5b59\u5b50\u4eec\u7b49\u7b49\u3002\u6bcf\u4e00\u4e2a\u65f6\u95f4\u70b9\uff0c\u8fd9\u4e2a\u5bb6\u5ead\u91cc\u6709\u4eba\u51fa\u751f\u4e5f\u6709\u4eba\u6b7b\u4ea1\u3002

\n\n

\u8fd9\u4e2a\u738b\u56fd\u6709\u4e00\u4e2a\u660e\u786e\u89c4\u5b9a\u7684\u7687\u4f4d\u7ee7\u627f\u987a\u5e8f\uff0c\u7b2c\u4e00\u7ee7\u627f\u4eba\u603b\u662f\u56fd\u738b\u81ea\u5df1\u3002\u6211\u4eec\u5b9a\u4e49\u9012\u5f52\u51fd\u6570 Successor(x, curOrder) \uff0c\u7ed9\u5b9a\u4e00\u4e2a\u4eba x \u548c\u5f53\u524d\u7684\u7ee7\u627f\u987a\u5e8f\uff0c\u8be5\u51fd\u6570\u8fd4\u56de x \u7684\u4e0b\u4e00\u7ee7\u627f\u4eba\u3002

\n\n
Successor(x, curOrder):\n    \u5982\u679c x \u6ca1\u6709\u5b69\u5b50\u6216\u8005\u6240\u6709 x \u7684\u5b69\u5b50\u90fd\u5728 curOrder \u4e2d\uff1a\n        \u5982\u679c x \u662f\u56fd\u738b\uff0c\u90a3\u4e48\u8fd4\u56de null\n        \u5426\u5219\uff0c\u8fd4\u56de Successor(x \u7684\u7236\u4eb2, curOrder)\n    \u5426\u5219\uff0c\u8fd4\u56de x \u4e0d\u5728 curOrder \u4e2d\u6700\u5e74\u957f\u7684\u5b69\u5b50\n
\n\n

\u6bd4\u65b9\u8bf4\uff0c\u5047\u8bbe\u738b\u56fd\u7531\u56fd\u738b\uff0c\u4ed6\u7684\u5b69\u5b50 Alice \u548c Bob \uff08Alice \u6bd4 Bob \u5e74\u957f\uff09\u548c Alice \u7684\u5b69\u5b50 Jack \u7ec4\u6210\u3002

\n\n
    \n\t
  1. \u4e00\u5f00\u59cb\uff0c curOrder \u4e3a ["king"].
  2. \n\t
  3. \u8c03\u7528 Successor(king, curOrder) \uff0c\u8fd4\u56de Alice \uff0c\u6240\u4ee5\u6211\u4eec\u5c06 Alice \u653e\u5165 curOrder \u4e2d\uff0c\u5f97\u5230 ["king", "Alice"] \u3002
  4. \n\t
  5. \u8c03\u7528 Successor(Alice, curOrder) \uff0c\u8fd4\u56de Jack \uff0c\u6240\u4ee5\u6211\u4eec\u5c06 Jack \u653e\u5165 curOrder \u4e2d\uff0c\u5f97\u5230 ["king", "Alice", "Jack"] \u3002
  6. \n\t
  7. \u8c03\u7528 Successor(Jack, curOrder) \uff0c\u8fd4\u56de Bob \uff0c\u6240\u4ee5\u6211\u4eec\u5c06 Bob \u653e\u5165 curOrder \u4e2d\uff0c\u5f97\u5230 ["king", "Alice", "Jack", "Bob"] \u3002
  8. \n\t
  9. \u8c03\u7528 Successor(Bob, curOrder) \uff0c\u8fd4\u56de null \u3002\u6700\u7ec8\u5f97\u5230\u7ee7\u627f\u987a\u5e8f\u4e3a ["king", "Alice", "Jack", "Bob"] \u3002
  10. \n
\n\n

\u901a\u8fc7\u4ee5\u4e0a\u7684\u51fd\u6570\uff0c\u6211\u4eec\u603b\u662f\u80fd\u5f97\u5230\u4e00\u4e2a\u552f\u4e00\u7684\u7ee7\u627f\u987a\u5e8f\u3002

\n\n

\u8bf7\u4f60\u5b9e\u73b0 ThroneInheritance \u7c7b\uff1a

\n\n
    \n\t
  • ThroneInheritance(string kingName) \u521d\u59cb\u5316\u4e00\u4e2a ThroneInheritance \u7c7b\u7684\u5bf9\u8c61\u3002\u56fd\u738b\u7684\u540d\u5b57\u4f5c\u4e3a\u6784\u9020\u51fd\u6570\u7684\u53c2\u6570\u4f20\u5165\u3002
  • \n\t
  • void birth(string parentName, string childName) \u8868\u793a parentName \u65b0\u62e5\u6709\u4e86\u4e00\u4e2a\u540d\u4e3a childName \u7684\u5b69\u5b50\u3002
  • \n\t
  • void death(string name) \u8868\u793a\u540d\u4e3a name \u7684\u4eba\u6b7b\u4ea1\u3002\u4e00\u4e2a\u4eba\u7684\u6b7b\u4ea1\u4e0d\u4f1a\u5f71\u54cd Successor \u51fd\u6570\uff0c\u4e5f\u4e0d\u4f1a\u5f71\u54cd\u5f53\u524d\u7684\u7ee7\u627f\u987a\u5e8f\u3002\u4f60\u53ef\u4ee5\u53ea\u5c06\u8fd9\u4e2a\u4eba\u6807\u8bb0\u4e3a\u6b7b\u4ea1\u72b6\u6001\u3002
  • \n\t
  • string[] getInheritanceOrder() \u8fd4\u56de \u9664\u53bb \u6b7b\u4ea1\u4eba\u5458\u7684\u5f53\u524d\u7ee7\u627f\u987a\u5e8f\u5217\u8868\u3002
  • \n
\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1a\n["ThroneInheritance", "birth", "birth", "birth", "birth", "birth", "birth", "getInheritanceOrder", "death", "getInheritanceOrder"]\n[["king"], ["king", "andy"], ["king", "bob"], ["king", "catherine"], ["andy", "matthew"], ["bob", "alex"], ["bob", "asha"], [null], ["bob"], [null]]\n\u8f93\u51fa\uff1a\n[null, null, null, null, null, null, null, ["king", "andy", "matthew", "bob", "alex", "asha", "catherine"], null, ["king", "andy", "matthew", "alex", "asha", "catherine"]]\n\n\u89e3\u91ca\uff1a\nThroneInheritance t= new ThroneInheritance("king"); // \u7ee7\u627f\u987a\u5e8f\uff1aking\nt.birth("king", "andy"); // \u7ee7\u627f\u987a\u5e8f\uff1aking > andy\nt.birth("king", "bob"); // \u7ee7\u627f\u987a\u5e8f\uff1aking > andy > bob\nt.birth("king", "catherine"); // \u7ee7\u627f\u987a\u5e8f\uff1aking > andy > bob > catherine\nt.birth("andy", "matthew"); // \u7ee7\u627f\u987a\u5e8f\uff1aking > andy > matthew > bob > catherine\nt.birth("bob", "alex"); // \u7ee7\u627f\u987a\u5e8f\uff1aking > andy > matthew > bob > alex > catherine\nt.birth("bob", "asha"); // \u7ee7\u627f\u987a\u5e8f\uff1aking > andy > matthew > bob > alex > asha > catherine\nt.getInheritanceOrder(); // \u8fd4\u56de ["king", "andy", "matthew", "bob", "alex", "asha", "catherine"]\nt.death("bob"); // \u7ee7\u627f\u987a\u5e8f\uff1aking > andy > matthew > bob\uff08\u5df2\u7ecf\u53bb\u4e16\uff09> alex > asha > catherine\nt.getInheritanceOrder(); // \u8fd4\u56de ["king", "andy", "matthew", "alex", "asha", "catherine"]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= kingName.length, parentName.length, childName.length, name.length <= 15
  • \n\t
  • kingName\uff0cparentName\uff0c childName \u548c name \u4ec5\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
  • \n\t
  • \u6240\u6709\u7684\u53c2\u6570 childName \u548c kingName \u4e92\u4e0d\u76f8\u540c\u3002
  • \n\t
  • \u6240\u6709 death \u51fd\u6570\u4e2d\u7684\u6b7b\u4ea1\u540d\u5b57 name \u8981\u4e48\u662f\u56fd\u738b\uff0c\u8981\u4e48\u662f\u5df2\u7ecf\u51fa\u751f\u4e86\u7684\u4eba\u5458\u540d\u5b57\u3002
  • \n\t
  • \u6bcf\u6b21\u8c03\u7528 birth(parentName, childName) \u65f6\uff0c\u6d4b\u8bd5\u7528\u4f8b\u90fd\u4fdd\u8bc1 parentName \u5bf9\u5e94\u7684\u4eba\u5458\u662f\u6d3b\u7740\u7684\u3002
  • \n\t
  • \u6700\u591a\u8c03\u7528 105 \u6b21birth \u548c death \u3002
  • \n\t
  • \u6700\u591a\u8c03\u7528 10 \u6b21 getInheritanceOrder \u3002
  • \n
\n", "tags_en": ["Tree", "Design"], "tags_cn": ["\u6811", "\u8bbe\u8ba1"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class ThroneInheritance {\npublic:\n ThroneInheritance(string kingName) {\n\n }\n \n void birth(string parentName, string childName) {\n\n }\n \n void death(string name) {\n\n }\n \n vector getInheritanceOrder() {\n\n }\n};\n\n/**\n * Your ThroneInheritance object will be instantiated and called as such:\n * ThroneInheritance* obj = new ThroneInheritance(kingName);\n * obj->birth(parentName,childName);\n * obj->death(name);\n * vector param_3 = obj->getInheritanceOrder();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class ThroneInheritance {\n\n public ThroneInheritance(String kingName) {\n\n }\n \n public void birth(String parentName, String childName) {\n\n }\n \n public void death(String name) {\n\n }\n \n public List getInheritanceOrder() {\n\n }\n}\n\n/**\n * Your ThroneInheritance object will be instantiated and called as such:\n * ThroneInheritance obj = new ThroneInheritance(kingName);\n * obj.birth(parentName,childName);\n * obj.death(name);\n * List param_3 = obj.getInheritanceOrder();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class ThroneInheritance(object):\n\n def __init__(self, kingName):\n \"\"\"\n :type kingName: str\n \"\"\"\n\n\n def birth(self, parentName, childName):\n \"\"\"\n :type parentName: str\n :type childName: str\n :rtype: None\n \"\"\"\n\n\n def death(self, name):\n \"\"\"\n :type name: str\n :rtype: None\n \"\"\"\n\n\n def getInheritanceOrder(self):\n \"\"\"\n :rtype: List[str]\n \"\"\"\n\n\n\n# Your ThroneInheritance object will be instantiated and called as such:\n# obj = ThroneInheritance(kingName)\n# obj.birth(parentName,childName)\n# obj.death(name)\n# param_3 = obj.getInheritanceOrder()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class ThroneInheritance:\n\n def __init__(self, kingName: str):\n\n\n def birth(self, parentName: str, childName: str) -> None:\n\n\n def death(self, name: str) -> None:\n\n\n def getInheritanceOrder(self) -> List[str]:\n\n\n\n# Your ThroneInheritance object will be instantiated and called as such:\n# obj = ThroneInheritance(kingName)\n# obj.birth(parentName,childName)\n# obj.death(name)\n# param_3 = obj.getInheritanceOrder()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} ThroneInheritance;\n\n\nThroneInheritance* throneInheritanceCreate(char * kingName) {\n \n}\n\nvoid throneInheritanceBirth(ThroneInheritance* obj, char * parentName, char * childName) {\n \n}\n\nvoid throneInheritanceDeath(ThroneInheritance* obj, char * name) {\n \n}\n\nchar ** throneInheritanceGetInheritanceOrder(ThroneInheritance* obj, int* retSize) {\n \n}\n\nvoid throneInheritanceFree(ThroneInheritance* obj) {\n \n}\n\n/**\n * Your ThroneInheritance struct will be instantiated and called as such:\n * ThroneInheritance* obj = throneInheritanceCreate(kingName);\n * throneInheritanceBirth(obj, parentName, childName);\n \n * throneInheritanceDeath(obj, name);\n \n * char ** param_3 = throneInheritanceGetInheritanceOrder(obj, retSize);\n \n * throneInheritanceFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class ThroneInheritance {\n\n public ThroneInheritance(string kingName) {\n\n }\n \n public void Birth(string parentName, string childName) {\n\n }\n \n public void Death(string name) {\n\n }\n \n public IList GetInheritanceOrder() {\n\n }\n}\n\n/**\n * Your ThroneInheritance object will be instantiated and called as such:\n * ThroneInheritance obj = new ThroneInheritance(kingName);\n * obj.Birth(parentName,childName);\n * obj.Death(name);\n * IList param_3 = obj.GetInheritanceOrder();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} kingName\n */\nvar ThroneInheritance = function(kingName) {\n\n};\n\n/** \n * @param {string} parentName \n * @param {string} childName\n * @return {void}\n */\nThroneInheritance.prototype.birth = function(parentName, childName) {\n\n};\n\n/** \n * @param {string} name\n * @return {void}\n */\nThroneInheritance.prototype.death = function(name) {\n\n};\n\n/**\n * @return {string[]}\n */\nThroneInheritance.prototype.getInheritanceOrder = function() {\n\n};\n\n/**\n * Your ThroneInheritance object will be instantiated and called as such:\n * var obj = new ThroneInheritance(kingName)\n * obj.birth(parentName,childName)\n * obj.death(name)\n * var param_3 = obj.getInheritanceOrder()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class ThroneInheritance\n\n=begin\n :type king_name: String\n=end\n def initialize(king_name)\n\n end\n\n\n=begin\n :type parent_name: String\n :type child_name: String\n :rtype: Void\n=end\n def birth(parent_name, child_name)\n\n end\n\n\n=begin\n :type name: String\n :rtype: Void\n=end\n def death(name)\n\n end\n\n\n=begin\n :rtype: String[]\n=end\n def get_inheritance_order()\n\n end\n\n\nend\n\n# Your ThroneInheritance object will be instantiated and called as such:\n# obj = ThroneInheritance.new(king_name)\n# obj.birth(parent_name, child_name)\n# obj.death(name)\n# param_3 = obj.get_inheritance_order()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass ThroneInheritance {\n\n init(_ kingName: String) {\n \n }\n \n func birth(_ parentName: String, _ childName: String) {\n \n }\n \n func death(_ name: String) {\n \n }\n \n func getInheritanceOrder() -> [String] {\n \n }\n}\n\n/**\n * Your ThroneInheritance object will be instantiated and called as such:\n * let obj = ThroneInheritance(kingName)\n * obj.birth(parentName, childName)\n * obj.death(name)\n * let ret_3: [String] = obj.getInheritanceOrder()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type ThroneInheritance struct {\n\n}\n\n\nfunc Constructor(kingName string) ThroneInheritance {\n\n}\n\n\nfunc (this *ThroneInheritance) Birth(parentName string, childName string) {\n\n}\n\n\nfunc (this *ThroneInheritance) Death(name string) {\n\n}\n\n\nfunc (this *ThroneInheritance) GetInheritanceOrder() []string {\n\n}\n\n\n/**\n * Your ThroneInheritance object will be instantiated and called as such:\n * obj := Constructor(kingName);\n * obj.Birth(parentName,childName);\n * obj.Death(name);\n * param_3 := obj.GetInheritanceOrder();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class ThroneInheritance(_kingName: String) {\n\n def birth(parentName: String, childName: String) {\n\n }\n\n def death(name: String) {\n\n }\n\n def getInheritanceOrder(): List[String] = {\n\n }\n\n}\n\n/**\n * Your ThroneInheritance object will be instantiated and called as such:\n * var obj = new ThroneInheritance(kingName)\n * obj.birth(parentName,childName)\n * obj.death(name)\n * var param_3 = obj.getInheritanceOrder()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class ThroneInheritance(kingName: String) {\n\n fun birth(parentName: String, childName: String) {\n\n }\n\n fun death(name: String) {\n\n }\n\n fun getInheritanceOrder(): List {\n\n }\n\n}\n\n/**\n * Your ThroneInheritance object will be instantiated and called as such:\n * var obj = ThroneInheritance(kingName)\n * obj.birth(parentName,childName)\n * obj.death(name)\n * var param_3 = obj.getInheritanceOrder()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct ThroneInheritance {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl ThroneInheritance {\n\n fn new(kingName: String) -> Self {\n\n }\n \n fn birth(&self, parent_name: String, child_name: String) {\n\n }\n \n fn death(&self, name: String) {\n\n }\n \n fn get_inheritance_order(&self) -> Vec {\n\n }\n}\n\n/**\n * Your ThroneInheritance object will be instantiated and called as such:\n * let obj = ThroneInheritance::new(kingName);\n * obj.birth(parentName, childName);\n * obj.death(name);\n * let ret_3: Vec = obj.get_inheritance_order();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class ThroneInheritance {\n /**\n * @param String $kingName\n */\n function __construct($kingName) {\n\n }\n\n /**\n * @param String $parentName\n * @param String $childName\n * @return NULL\n */\n function birth($parentName, $childName) {\n\n }\n\n /**\n * @param String $name\n * @return NULL\n */\n function death($name) {\n\n }\n\n /**\n * @return String[]\n */\n function getInheritanceOrder() {\n\n }\n}\n\n/**\n * Your ThroneInheritance object will be instantiated and called as such:\n * $obj = ThroneInheritance($kingName);\n * $obj->birth($parentName, $childName);\n * $obj->death($name);\n * $ret_3 = $obj->getInheritanceOrder();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class ThroneInheritance {\n constructor(kingName: string) {\n\n }\n\n birth(parentName: string, childName: string): void {\n\n }\n\n death(name: string): void {\n\n }\n\n getInheritanceOrder(): string[] {\n\n }\n}\n\n/**\n * Your ThroneInheritance object will be instantiated and called as such:\n * var obj = new ThroneInheritance(kingName)\n * obj.birth(parentName,childName)\n * obj.death(name)\n * var param_3 = obj.getInheritanceOrder()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define throne-inheritance%\n (class object%\n (super-new)\n\n ; king-name : string?\n (init-field\n king-name)\n \n ; birth : string? string? -> void?\n (define/public (birth parentName childName)\n\n )\n ; death : string? -> void?\n (define/public (death name)\n\n )\n ; get-inheritance-order : -> (listof string?)\n (define/public (get-inheritance-order)\n\n )))\n\n;; Your throne-inheritance% object will be instantiated and called as such:\n;; (define obj (new throne-inheritance% [kingName kingName]))\n;; (send obj birth parent-name child-name)\n;; (send obj death name)\n;; (define param_3 (send obj get-inheritance-order))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1600](https://leetcode-cn.com/problems/throne-inheritance)", "[\u7687\u4f4d\u7ee7\u627f\u987a\u5e8f](/solution/1600-1699/1600.Throne%20Inheritance/README.md)", "`\u6811`,`\u8bbe\u8ba1`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1600](https://leetcode.com/problems/throne-inheritance)", "[Throne Inheritance](/solution/1600-1699/1600.Throne%20Inheritance/README_EN.md)", "`Tree`,`Design`", "Medium", ""]}, {"question_id": "1721", "frontend_question_id": "1599", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-profit-of-operating-a-centennial-wheel", "url_en": "https://leetcode.com/problems/maximum-profit-of-operating-a-centennial-wheel", "relative_path_cn": "/solution/1500-1599/1599.Maximum%20Profit%20of%20Operating%20a%20Centennial%20Wheel/README.md", "relative_path_en": "/solution/1500-1599/1599.Maximum%20Profit%20of%20Operating%20a%20Centennial%20Wheel/README_EN.md", "title_cn": "\u7ecf\u8425\u6469\u5929\u8f6e\u7684\u6700\u5927\u5229\u6da6", "title_en": "Maximum Profit of Operating a Centennial Wheel", "question_title_slug": "maximum-profit-of-operating-a-centennial-wheel", "content_en": "

You are the operator of a Centennial Wheel that has four gondolas, and each gondola has room for up to four people. You have the ability to rotate the gondolas counterclockwise, which costs you runningCost dollars.

\n\n

You are given an array customers of length n where customers[i] is the number of new customers arriving just before the ith rotation (0-indexed). This means you must rotate the wheel i times before the customers[i] customers arrive. You cannot make customers wait if there is room in the gondola. Each customer pays boardingCost dollars when they board on the gondola closest to the ground and will exit once that gondola reaches the ground again.

\n\n

You can stop the wheel at any time, including before serving all customers. If you decide to stop serving customers, all subsequent rotations are free in order to get all the customers down safely. Note that if there are currently more than four customers waiting at the wheel, only four will board the gondola, and the rest will wait for the next rotation.

\n\n

Return the minimum number of rotations you need to perform to maximize your profit. If there is no scenario where the profit is positive, return -1.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: customers = [8,3], boardingCost = 5, runningCost = 6\nOutput: 3\nExplanation: The numbers written on the gondolas are the number of people currently there.\n1. 8 customers arrive, 4 board and 4 wait for the next gondola, the wheel rotates. Current profit is 4 * $5 - 1 * $6 = $14.\n2. 3 customers arrive, the 4 waiting board the wheel and the other 3 wait, the wheel rotates. Current profit is 8 * $5 - 2 * $6 = $28.\n3. The final 3 customers board the gondola, the wheel rotates. Current profit is 11 * $5 - 3 * $6 = $37.\nThe highest profit was $37 after rotating the wheel 3 times.
\n\n

Example 2:

\n\n
\nInput: customers = [10,9,6], boardingCost = 6, runningCost = 4\nOutput: 7\nExplanation:\n1. 10 customers arrive, 4 board and 6 wait for the next gondola, the wheel rotates. Current profit is 4 * $6 - 1 * $4 = $20.\n2. 9 customers arrive, 4 board and 11 wait (2 originally waiting, 9 newly waiting), the wheel rotates. Current profit is 8 * $6 - 2 * $4 = $40.\n3. The final 6 customers arrive, 4 board and 13 wait, the wheel rotates. Current profit is 12 * $6 - 3 * $4 = $60.\n4. 4 board and 9 wait, the wheel rotates. Current profit is 16 * $6 - 4 * $4 = $80.\n5. 4 board and 5 wait, the wheel rotates. Current profit is 20 * $6 - 5 * $4 = $100.\n6. 4 board and 1 waits, the wheel rotates. Current profit is 24 * $6 - 6 * $4 = $120.\n7. 1 boards, the wheel rotates. Current profit is 25 * $6 - 7 * $4 = $122.\nThe highest profit was $122 after rotating the wheel 7 times.\n\n
\n\n

Example 3:

\n\n
\nInput: customers = [3,4,0,5,1], boardingCost = 1, runningCost = 92\nOutput: -1\nExplanation:\n1. 3 customers arrive, 3 board and 0 wait, the wheel rotates. Current profit is 3 * $1 - 1 * $92 = -$89.\n2. 4 customers arrive, 4 board and 0 wait, the wheel rotates. Current profit is 7 * $1 - 2 * $92 = -$177.\n3. 0 customers arrive, 0 board and 0 wait, the wheel rotates. Current profit is 7 * $1 - 3 * $92 = -$269.\n4. 5 customers arrive, 4 board and 1 waits, the wheel rotates. Current profit is 11 * $1 - 4 * $92 = -$357.\n5. 1 customer arrives, 2 board and 0 wait, the wheel rotates. Current profit is 13 * $1 - 5 * $92 = -$447.\nThe profit was never positive, so return -1.\n
\n\n

Example 4:

\n\n
\nInput: customers = [10,10,6,4,7], boardingCost = 3, runningCost = 8\nOutput: 9\nExplanation:\n1. 10 customers arrive, 4 board and 6 wait, the wheel rotates. Current profit is 4 * $3 - 1 * $8 = $4.\n2. 10 customers arrive, 4 board and 12 wait, the wheel rotates. Current profit is 8 * $3 - 2 * $8 = $8.\n3. 6 customers arrive, 4 board and 14 wait, the wheel rotates. Current profit is 12 * $3 - 3 * $8 = $12.\n4. 4 customers arrive, 4 board and 14 wait, the wheel rotates. Current profit is 16 * $3 - 4 * $8 = $16.\n5. 7 customers arrive, 4 board and 17 wait, the wheel rotates. Current profit is 20 * $3 - 5 * $8 = $20.\n6. 4 board and 13 wait, the wheel rotates. Current profit is 24 * $3 - 6 * $8 = $24.\n7. 4 board and 9 wait, the wheel rotates. Current profit is 28 * $3 - 7 * $8 = $28.\n8. 4 board and 5 wait, the wheel rotates. Current profit is 32 * $3 - 8 * $8 = $32.\n9. 4 board and 1 waits, the wheel rotates. Current profit is 36 * $3 - 9 * $8 = $36.\n10. 1 board and 0 wait, the wheel rotates. Current profit is 37 * $3 - 10 * $8 = $31.\nThe highest profit was $36 after rotating the wheel 9 times.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == customers.length
  • \n\t
  • 1 <= n <= 105
  • \n\t
  • 0 <= customers[i] <= 50
  • \n\t
  • 1 <= boardingCost, runningCost <= 100
  • \n
\n", "content_cn": "

\u4f60\u6b63\u5728\u7ecf\u8425\u4e00\u5ea7\u6469\u5929\u8f6e\uff0c\u8be5\u6469\u5929\u8f6e\u5171\u6709 4 \u4e2a\u5ea7\u8231 \uff0c\u6bcf\u4e2a\u5ea7\u8231 \u6700\u591a\u53ef\u4ee5\u5bb9\u7eb3 4 \u4f4d\u6e38\u5ba2 \u3002\u4f60\u53ef\u4ee5 \u9006\u65f6\u9488 \u8f6e\u8f6c\u5ea7\u8231\uff0c\u4f46\u6bcf\u6b21\u8f6e\u8f6c\u90fd\u9700\u8981\u652f\u4ed8\u4e00\u5b9a\u7684\u8fd0\u884c\u6210\u672c runningCost \u3002\u6469\u5929\u8f6e\u6bcf\u6b21\u8f6e\u8f6c\u90fd\u6070\u597d\u8f6c\u52a8 1 / 4 \u5468\u3002

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u6570\u7ec4 customers \uff0c customers[i] \u662f\u5728\u7b2c i \u6b21\u8f6e\u8f6c\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\u4e4b\u524d\u5230\u8fbe\u7684\u65b0\u6e38\u5ba2\u7684\u6570\u91cf\u3002\u8fd9\u4e5f\u610f\u5473\u7740\u4f60\u5fc5\u987b\u5728\u65b0\u6e38\u5ba2\u5230\u6765\u524d\u8f6e\u8f6c i \u6b21\u3002\u6bcf\u4f4d\u6e38\u5ba2\u5728\u767b\u4e0a\u79bb\u5730\u9762\u6700\u8fd1\u7684\u5ea7\u8231\u524d\u90fd\u4f1a\u652f\u4ed8\u767b\u8231\u6210\u672c boardingCost \uff0c\u4e00\u65e6\u8be5\u5ea7\u8231\u518d\u6b21\u62b5\u8fbe\u5730\u9762\uff0c\u4ed6\u4eec\u5c31\u4f1a\u79bb\u5f00\u5ea7\u8231\u7ed3\u675f\u6e38\u73a9\u3002

\n\n

\u4f60\u53ef\u4ee5\u968f\u65f6\u505c\u4e0b\u6469\u5929\u8f6e\uff0c\u5373\u4fbf\u662f \u5728\u670d\u52a1\u6240\u6709\u6e38\u5ba2\u4e4b\u524d \u3002\u5982\u679c\u4f60\u51b3\u5b9a\u505c\u6b62\u8fd0\u8425\u6469\u5929\u8f6e\uff0c\u4e3a\u4e86\u4fdd\u8bc1\u6240\u6709\u6e38\u5ba2\u5b89\u5168\u7740\u9646\uff0c\u5c06\u514d\u8d39\u8fdb\u884c\u6240\u6709\u540e\u7eed\u8f6e\u8f6c \u3002\u6ce8\u610f\uff0c\u5982\u679c\u6709\u8d85\u8fc7 4 \u4f4d\u6e38\u5ba2\u5728\u7b49\u6469\u5929\u8f6e\uff0c\u90a3\u4e48\u53ea\u6709 4 \u4f4d\u6e38\u5ba2\u53ef\u4ee5\u767b\u4e0a\u6469\u5929\u8f6e\uff0c\u5176\u4f59\u7684\u9700\u8981\u7b49\u5f85 \u4e0b\u4e00\u6b21\u8f6e\u8f6c \u3002

\n\n

\u8fd4\u56de\u6700\u5927\u5316\u5229\u6da6\u6240\u9700\u6267\u884c\u7684 \u6700\u5c0f\u8f6e\u8f6c\u6b21\u6570 \u3002 \u5982\u679c\u4e0d\u5b58\u5728\u5229\u6da6\u4e3a\u6b63\u7684\u65b9\u6848\uff0c\u5219\u8fd4\u56de -1 \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1acustomers = [8,3], boardingCost = 5, runningCost = 6\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u5ea7\u8231\u4e0a\u6807\u6ce8\u7684\u6570\u5b57\u662f\u8be5\u5ea7\u8231\u7684\u5f53\u524d\u6e38\u5ba2\u6570\u3002\n1. 8 \u4f4d\u6e38\u5ba2\u62b5\u8fbe\uff0c4 \u4f4d\u767b\u8231\uff0c4 \u4f4d\u7b49\u5f85\u4e0b\u4e00\u8231\uff0c\u6469\u5929\u8f6e\u8f6e\u8f6c\u3002\u5f53\u524d\u5229\u6da6\u4e3a 4 * $5 - 1 * $6 = $14 \u3002\n2. 3 \u4f4d\u6e38\u5ba2\u62b5\u8fbe\uff0c4 \u4f4d\u5728\u7b49\u5f85\u7684\u6e38\u5ba2\u767b\u8231\uff0c\u5176\u4ed6 3 \u4f4d\u7b49\u5f85\uff0c\u6469\u5929\u8f6e\u8f6e\u8f6c\u3002\u5f53\u524d\u5229\u6da6\u4e3a 8 * $5 - 2 * $6 = $28 \u3002\n3. \u6700\u540e 3 \u4f4d\u6e38\u5ba2\u767b\u8231\uff0c\u6469\u5929\u8f6e\u8f6e\u8f6c\u3002\u5f53\u524d\u5229\u6da6\u4e3a 11 * $5 - 3 * $6 = $37 \u3002\n\u8f6e\u8f6c 3 \u6b21\u5f97\u5230\u6700\u5927\u5229\u6da6\uff0c\u6700\u5927\u5229\u6da6\u4e3a $37 \u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1acustomers = [10,9,6], boardingCost = 6, runningCost = 4\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\n1. 10 \u4f4d\u6e38\u5ba2\u62b5\u8fbe\uff0c4 \u4f4d\u767b\u8231\uff0c6 \u4f4d\u7b49\u5f85\u4e0b\u4e00\u8231\uff0c\u6469\u5929\u8f6e\u8f6e\u8f6c\u3002\u5f53\u524d\u5229\u6da6\u4e3a 4 * $6 - 1 * $4 = $20 \u3002\n2. 9 \u4f4d\u6e38\u5ba2\u62b5\u8fbe\uff0c4 \u4f4d\u767b\u8231\uff0c11 \u4f4d\u7b49\u5f85\uff082 \u4f4d\u662f\u5148\u524d\u5c31\u5728\u7b49\u5f85\u7684\uff0c9 \u4f4d\u65b0\u52a0\u5165\u7b49\u5f85\u7684\uff09\uff0c\u6469\u5929\u8f6e\u8f6e\u8f6c\u3002\u5f53\u524d\u5229\u6da6\u4e3a 8 * $6 - 2 * $4 = $40 \u3002\n3. \u6700\u540e 6 \u4f4d\u6e38\u5ba2\u62b5\u8fbe\uff0c4 \u4f4d\u767b\u8231\uff0c13 \u4f4d\u7b49\u5f85\uff0c\u6469\u5929\u8f6e\u8f6e\u8f6c\u3002\u5f53\u524d\u5229\u6da6\u4e3a 12 * $6 - 3 * $4 = $60 \u3002\n4. 4 \u4f4d\u767b\u8231\uff0c9 \u4f4d\u7b49\u5f85\uff0c\u6469\u5929\u8f6e\u8f6e\u8f6c\u3002\u5f53\u524d\u5229\u6da6\u4e3a * $6 - 4 * $4 = $80 \u3002\n5. 4 \u4f4d\u767b\u8231\uff0c5 \u4f4d\u7b49\u5f85\uff0c\u6469\u5929\u8f6e\u8f6e\u8f6c\u3002\u5f53\u524d\u5229\u6da6\u4e3a 20 * $6 - 5 * $4 = $100 \u3002\n6. 4 \u4f4d\u767b\u8231\uff0c1 \u4f4d\u7b49\u5f85\uff0c\u6469\u5929\u8f6e\u8f6e\u8f6c\u3002\u5f53\u524d\u5229\u6da6\u4e3a 24 * $6 - 6 * $4 = $120 \u3002\n7. 1 \u4f4d\u767b\u8231\uff0c\u6469\u5929\u8f6e\u8f6e\u8f6c\u3002\u5f53\u524d\u5229\u6da6\u4e3a 25 * $6 - 7 * $4 = $122 \u3002\n\u8f6e\u8f6c 7 \u6b21\u5f97\u5230\u6700\u5927\u5229\u6da6\uff0c\u6700\u5927\u5229\u6da6\u4e3a$122 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1acustomers = [3,4,0,5,1], boardingCost = 1, runningCost = 92\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\n1. 3 \u4f4d\u6e38\u5ba2\u62b5\u8fbe\uff0c3 \u4f4d\u767b\u8231\uff0c0 \u4f4d\u7b49\u5f85\uff0c\u6469\u5929\u8f6e\u8f6e\u8f6c\u3002\u5f53\u524d\u5229\u6da6\u4e3a 3 * $1 - 1 * $92 = -$89 \u3002\n2. 4 \u4f4d\u6e38\u5ba2\u62b5\u8fbe\uff0c4 \u4f4d\u767b\u8231\uff0c0 \u4f4d\u7b49\u5f85\uff0c\u6469\u5929\u8f6e\u8f6e\u8f6c\u3002\u5f53\u524d\u5229\u6da6\u4e3a is 7 * $1 - 2 * $92 = -$177 \u3002\n3. 0 \u4f4d\u6e38\u5ba2\u62b5\u8fbe\uff0c0 \u4f4d\u767b\u8231\uff0c0 \u4f4d\u7b49\u5f85\uff0c\u6469\u5929\u8f6e\u8f6e\u8f6c\u3002\u5f53\u524d\u5229\u6da6\u4e3a 7 * $1 - 3 * $92 = -$269 \u3002\n4. 5 \u4f4d\u6e38\u5ba2\u62b5\u8fbe\uff0c4 \u4f4d\u767b\u8231\uff0c1 \u4f4d\u7b49\u5f85\uff0c\u6469\u5929\u8f6e\u8f6e\u8f6c\u3002\u5f53\u524d\u5229\u6da6\u4e3a 12 * $1 - 4 * $92 = -$356 \u3002\n5. 1 \u4f4d\u6e38\u5ba2\u62b5\u8fbe\uff0c2 \u4f4d\u767b\u8231\uff0c0 \u4f4d\u7b49\u5f85\uff0c\u6469\u5929\u8f6e\u8f6e\u8f6c\u3002\u5f53\u524d\u5229\u6da6\u4e3a 13 * $1 - 5 * $92 = -$447 \u3002\n\u5229\u6da6\u6c38\u4e0d\u4e3a\u6b63\uff0c\u6240\u4ee5\u8fd4\u56de -1 \u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1acustomers = [10,10,6,4,7], boardingCost = 3, runningCost = 8\n\u8f93\u51fa\uff1a9\n\u89e3\u91ca\uff1a\n1. 10 \u4f4d\u6e38\u5ba2\u62b5\u8fbe\uff0c4 \u4f4d\u767b\u8231\uff0c6 \u4f4d\u7b49\u5f85\uff0c\u6469\u5929\u8f6e\u8f6e\u8f6c\u3002\u5f53\u524d\u5229\u6da6\u4e3a 4 * $3 - 1 * $8 = $4 \u3002\n2. 10 \u4f4d\u6e38\u5ba2\u62b5\u8fbe\uff0c4 \u4f4d\u767b\u8231\uff0c12 \u4f4d\u7b49\u5f85\uff0c\u6469\u5929\u8f6e\u8f6e\u8f6c\u3002\u5f53\u524d\u5229\u6da6\u4e3a 8 * $3 - 2 * $8 = $8 \u3002\n3. 6 \u4f4d\u6e38\u5ba2\u62b5\u8fbe\uff0c4 \u4f4d\u767b\u8231\uff0c14 \u4f4d\u7b49\u5f85\uff0c\u6469\u5929\u8f6e\u8f6e\u8f6c\u3002\u5f53\u524d\u5229\u6da6\u4e3a 12 * $3 - 3 * $8 = $12 \u3002\n4. 4 \u4f4d\u6e38\u5ba2\u62b5\u8fbe\uff0c4 \u4f4d\u767b\u8231\uff0c14 \u4f4d\u7b49\u5f85\uff0c\u6469\u5929\u8f6e\u8f6e\u8f6c\u3002\u5f53\u524d\u5229\u6da6\u4e3a 16 * $3 - 4 * $8 = $16 \u3002\n5. 7 \u4f4d\u6e38\u5ba2\u62b5\u8fbe\uff0c4 \u4f4d\u767b\u8231\uff0c17 \u4f4d\u7b49\u5f85\uff0c\u6469\u5929\u8f6e\u8f6e\u8f6c\u3002\u5f53\u524d\u5229\u6da6\u4e3a 20 * $3 - 5 * $8 = $20 \u3002\n6. 4 \u4f4d\u767b\u8231\uff0c13 \u4f4d\u7b49\u5f85\uff0c\u6469\u5929\u8f6e\u8f6e\u8f6c\u3002\u5f53\u524d\u5229\u6da6\u4e3a 24 * $3 - 6 * $8 = $24 \u3002\n7. 4 \u4f4d\u767b\u8231\uff0c9 \u4f4d\u7b49\u5f85\uff0c\u6469\u5929\u8f6e\u8f6e\u8f6c\u3002\u5f53\u524d\u5229\u6da6\u4e3a 28 * $3 - 7 * $8 = $28 \u3002\n8. 4 \u4f4d\u767b\u8231\uff0c5 \u4f4d\u7b49\u5f85\uff0c\u6469\u5929\u8f6e\u8f6e\u8f6c\u3002\u5f53\u524d\u5229\u6da6\u4e3a 32 * $3 - 8 * $8 = $32 \u3002\n9. 4 \u4f4d\u767b\u8231\uff0c1 \u4f4d\u7b49\u5f85\uff0c\u6469\u5929\u8f6e\u8f6e\u8f6c\u3002\u5f53\u524d\u5229\u6da6\u4e3a 36 * $3 - 9 * $8 = $36 \u3002\n\u200b\u200b\u200b\u200b\u200b\u200b\u200b10. 1 \u4f4d\u767b\u8231\uff0c0 \u4f4d\u7b49\u5f85\uff0c\u6469\u5929\u8f6e\u8f6e\u8f6c\u3002\u5f53\u524d\u5229\u6da6\u4e3a 37 * $3 - 10 * $8 = $31 \u3002\n\u8f6e\u8f6c 9 \u6b21\u5f97\u5230\u6700\u5927\u5229\u6da6\uff0c\u6700\u5927\u5229\u6da6\u4e3a $36 \u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • n == customers.length
  • \n\t
  • 1 <= n <= 105
  • \n\t
  • 0 <= customers[i] <= 50
  • \n\t
  • 1 <= boardingCost, runningCost <= 100
  • \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minOperationsMaxProfit(vector& customers, int boardingCost, int runningCost) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minOperationsMaxProfit(int[] customers, int boardingCost, int runningCost) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minOperationsMaxProfit(self, customers, boardingCost, runningCost):\n \"\"\"\n :type customers: List[int]\n :type boardingCost: int\n :type runningCost: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minOperationsMaxProfit(self, customers: List[int], boardingCost: int, runningCost: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minOperationsMaxProfit(int* customers, int customersSize, int boardingCost, int runningCost){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinOperationsMaxProfit(int[] customers, int boardingCost, int runningCost) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} customers\n * @param {number} boardingCost\n * @param {number} runningCost\n * @return {number}\n */\nvar minOperationsMaxProfit = function(customers, boardingCost, runningCost) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} customers\n# @param {Integer} boarding_cost\n# @param {Integer} running_cost\n# @return {Integer}\ndef min_operations_max_profit(customers, boarding_cost, running_cost)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minOperationsMaxProfit(_ customers: [Int], _ boardingCost: Int, _ runningCost: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minOperationsMaxProfit(customers []int, boardingCost int, runningCost int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minOperationsMaxProfit(customers: Array[Int], boardingCost: Int, runningCost: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minOperationsMaxProfit(customers: IntArray, boardingCost: Int, runningCost: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_operations_max_profit(customers: Vec, boarding_cost: i32, running_cost: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $customers\n * @param Integer $boardingCost\n * @param Integer $runningCost\n * @return Integer\n */\n function minOperationsMaxProfit($customers, $boardingCost, $runningCost) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minOperationsMaxProfit(customers: number[], boardingCost: number, runningCost: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-operations-max-profit customers boardingCost runningCost)\n (-> (listof exact-integer?) exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1599](https://leetcode-cn.com/problems/maximum-profit-of-operating-a-centennial-wheel)", "[\u7ecf\u8425\u6469\u5929\u8f6e\u7684\u6700\u5927\u5229\u6da6](/solution/1500-1599/1599.Maximum%20Profit%20of%20Operating%20a%20Centennial%20Wheel/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1599](https://leetcode.com/problems/maximum-profit-of-operating-a-centennial-wheel)", "[Maximum Profit of Operating a Centennial Wheel](/solution/1500-1599/1599.Maximum%20Profit%20of%20Operating%20a%20Centennial%20Wheel/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1720", "frontend_question_id": "1598", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/crawler-log-folder", "url_en": "https://leetcode.com/problems/crawler-log-folder", "relative_path_cn": "/solution/1500-1599/1598.Crawler%20Log%20Folder/README.md", "relative_path_en": "/solution/1500-1599/1598.Crawler%20Log%20Folder/README_EN.md", "title_cn": "\u6587\u4ef6\u5939\u64cd\u4f5c\u65e5\u5fd7\u641c\u96c6\u5668", "title_en": "Crawler Log Folder", "question_title_slug": "crawler-log-folder", "content_en": "

The Leetcode file system keeps a log each time some user performs a change folder operation.

\n\n

The operations are described below:

\n\n
    \n\t
  • "../" : Move to the parent folder of the current folder. (If you are already in the main folder, remain in the same folder).
  • \n\t
  • "./" : Remain in the same folder.
  • \n\t
  • "x/" : Move to the child folder named x (This folder is guaranteed to always exist).
  • \n
\n\n

You are given a list of strings logs where logs[i] is the operation performed by the user at the ith step.

\n\n

The file system starts in the main folder, then the operations in logs are performed.

\n\n

Return the minimum number of operations needed to go back to the main folder after the change folder operations.

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: logs = ["d1/","d2/","../","d21/","./"]\nOutput: 2\nExplanation: Use this change folder operation "../" 2 times and go back to the main folder.\n
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: logs = ["d1/","d2/","./","d3/","../","d31/"]\nOutput: 3\n
\n\n

Example 3:

\n\n
\nInput: logs = ["d1/","../","../","../"]\nOutput: 0\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= logs.length <= 103
  • \n\t
  • 2 <= logs[i].length <= 10
  • \n\t
  • logs[i] contains lowercase English letters, digits, '.', and '/'.
  • \n\t
  • logs[i] follows the format described in the statement.
  • \n\t
  • Folder names consist of lowercase English letters and digits.
  • \n
\n", "content_cn": "

\u6bcf\u5f53\u7528\u6237\u6267\u884c\u53d8\u66f4\u6587\u4ef6\u5939\u64cd\u4f5c\u65f6\uff0cLeetCode \u6587\u4ef6\u7cfb\u7edf\u90fd\u4f1a\u4fdd\u5b58\u4e00\u6761\u65e5\u5fd7\u8bb0\u5f55\u3002

\n\n

\u4e0b\u9762\u7ed9\u51fa\u5bf9\u53d8\u66f4\u64cd\u4f5c\u7684\u8bf4\u660e\uff1a

\n\n
    \n\t
  • "../" \uff1a\u79fb\u52a8\u5230\u5f53\u524d\u6587\u4ef6\u5939\u7684\u7236\u6587\u4ef6\u5939\u3002\u5982\u679c\u5df2\u7ecf\u5728\u4e3b\u6587\u4ef6\u5939\u4e0b\uff0c\u5219 \u7ee7\u7eed\u505c\u7559\u5728\u5f53\u524d\u6587\u4ef6\u5939 \u3002
  • \n\t
  • "./" \uff1a\u7ee7\u7eed\u505c\u7559\u5728\u5f53\u524d\u6587\u4ef6\u5939\u3002
  • \n\t
  • "x/" \uff1a\u79fb\u52a8\u5230\u540d\u4e3a x \u7684\u5b50\u6587\u4ef6\u5939\u4e2d\u3002\u9898\u76ee\u6570\u636e \u4fdd\u8bc1\u603b\u662f\u5b58\u5728\u6587\u4ef6\u5939 x \u3002
  • \n
\n\n

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32\u5217\u8868 logs \uff0c\u5176\u4e2d logs[i] \u662f\u7528\u6237\u5728 ith \u6b65\u6267\u884c\u7684\u64cd\u4f5c\u3002

\n\n

\u6587\u4ef6\u7cfb\u7edf\u542f\u52a8\u65f6\u4f4d\u4e8e\u4e3b\u6587\u4ef6\u5939\uff0c\u7136\u540e\u6267\u884c logs \u4e2d\u7684\u64cd\u4f5c\u3002

\n\n

\u6267\u884c\u5b8c\u6240\u6709\u53d8\u66f4\u6587\u4ef6\u5939\u64cd\u4f5c\u540e\uff0c\u8bf7\u4f60\u627e\u51fa \u8fd4\u56de\u4e3b\u6587\u4ef6\u5939\u6240\u9700\u7684\u6700\u5c0f\u6b65\u6570 \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1alogs = ["d1/","d2/","../","d21/","./"]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6267\u884c "../" \u64cd\u4f5c\u53d8\u66f4\u6587\u4ef6\u5939 2 \u6b21\uff0c\u5373\u53ef\u56de\u5230\u4e3b\u6587\u4ef6\u5939\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1alogs = ["d1/","d2/","./","d3/","../","d31/"]\n\u8f93\u51fa\uff1a3\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1alogs = ["d1/","../","../","../"]\n\u8f93\u51fa\uff1a0\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= logs.length <= 103
  • \n\t
  • 2 <= logs[i].length <= 10
  • \n\t
  • logs[i] \u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\uff0c\u6570\u5b57\uff0c'.' \u548c '/'
  • \n\t
  • logs[i] \u7b26\u5408\u8bed\u53e5\u4e2d\u63cf\u8ff0\u7684\u683c\u5f0f
  • \n\t
  • \u6587\u4ef6\u5939\u540d\u79f0\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u548c\u6570\u5b57\u7ec4\u6210
  • \n
\n", "tags_en": ["Stack"], "tags_cn": ["\u6808"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minOperations(vector& logs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minOperations(String[] logs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minOperations(self, logs):\n \"\"\"\n :type logs: List[str]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minOperations(self, logs: List[str]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minOperations(char ** logs, int logsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinOperations(string[] logs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} logs\n * @return {number}\n */\nvar minOperations = function(logs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} logs\n# @return {Integer}\ndef min_operations(logs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minOperations(_ logs: [String]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minOperations(logs []string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minOperations(logs: Array[String]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minOperations(logs: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_operations(logs: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $logs\n * @return Integer\n */\n function minOperations($logs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minOperations(logs: string[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-operations logs)\n (-> (listof string?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1598](https://leetcode-cn.com/problems/crawler-log-folder)", "[\u6587\u4ef6\u5939\u64cd\u4f5c\u65e5\u5fd7\u641c\u96c6\u5668](/solution/1500-1599/1598.Crawler%20Log%20Folder/README.md)", "`\u6808`", "\u7b80\u5355", ""], "md_table_row_en": ["[1598](https://leetcode.com/problems/crawler-log-folder)", "[Crawler Log Folder](/solution/1500-1599/1598.Crawler%20Log%20Folder/README_EN.md)", "`Stack`", "Easy", ""]}, {"question_id": "1719", "frontend_question_id": "1580", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/put-boxes-into-the-warehouse-ii", "url_en": "https://leetcode.com/problems/put-boxes-into-the-warehouse-ii", "relative_path_cn": "/solution/1500-1599/1580.Put%20Boxes%20Into%20the%20Warehouse%20II/README.md", "relative_path_en": "/solution/1500-1599/1580.Put%20Boxes%20Into%20the%20Warehouse%20II/README_EN.md", "title_cn": "\u628a\u7bb1\u5b50\u653e\u8fdb\u4ed3\u5e93\u91cc II", "title_en": "Put Boxes Into the Warehouse II", "question_title_slug": "put-boxes-into-the-warehouse-ii", "content_en": "

You are given two arrays of positive integers, boxes and warehouse, representing the heights of some boxes of unit width and the heights of n rooms in a warehouse respectively. The warehouse's rooms are labeled from 0 to n - 1 from left to right where warehouse[i] (0-indexed) is the height of the ith room.

\n\n

Boxes are put into the warehouse by the following rules:

\n\n
    \n\t
  • Boxes cannot be stacked.
  • \n\t
  • You can rearrange the insertion order of the boxes.
  • \n\t
  • Boxes can be pushed into the warehouse from either side (left or right)
  • \n\t
  • If the height of some room in the warehouse is less than the height of a box, then that box and all other boxes behind it will be stopped before that room.
  • \n
\n\n

Return the maximum number of boxes you can put into the warehouse.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: boxes = [1,2,2,3,4], warehouse = [3,4,1,2]\nOutput: 4\nExplanation:\n\"\"\nWe can store the boxes in the following order:\n1- Put the yellow box in room 2 from either the left or right side.\n2- Put the orange box in room 3 from the right side.\n3- Put the green box in room 1 from the left side.\n4- Put the red box in room 0 from the left side.\nNotice that there are other valid ways to put 4 boxes such as swapping the red and green boxes or the red and orange boxes.\n
\n\n

Example 2:

\n\"\"\n
\nInput: boxes = [3,5,5,2], warehouse = [2,1,3,4,5]\nOutput: 3\nExplanation:\n\"\"\nIt's not possible to put the two boxes of height 5 in the warehouse since there's only 1 room of height >= 5.\nOther valid solutions are to put the green box in room 2 or to put the orange box first in room 2 before putting the green and red boxes.\n
\n\n

Example 3:

\n\n
\nInput: boxes = [1,2,3], warehouse = [1,2,3,4]\nOutput: 3\n
\n\n

Example 4:

\n\n
\nInput: boxes = [4,5,6], warehouse = [3,3,3,3,3]\nOutput: 0\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == warehouse.length
  • \n\t
  • 1 <= boxes.length, warehouse.length <= 105
  • \n\t
  • 1 <= boxes[i], warehouse[i] <= 109
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e24\u4e2a\u6b63\u6574\u6570\u6570\u7ec4\u00a0boxes \u548c warehouse\u00a0\uff0c\u5206\u522b\u5305\u542b\u5355\u4f4d\u5bbd\u5ea6\u7684\u7bb1\u5b50\u7684\u9ad8\u5ea6\uff0c\u4ee5\u53ca\u4ed3\u5e93\u4e2dn\u4e2a\u623f\u95f4\u5404\u81ea\u7684\u9ad8\u5ea6\u3002\u4ed3\u5e93\u7684\u623f\u95f4\u5206\u522b\u4ece0\u00a0\u5230 n - 1\u81ea\u5de6\u5411\u53f3\u7f16\u53f7\uff0cwarehouse[i]\uff08\u7d22\u5f15\u4ece 0 \u5f00\u59cb\uff09\u662f\u7b2c\u00a0i\u00a0\u4e2a\u623f\u95f4\u7684\u9ad8\u5ea6\u3002

\n\n

\u7bb1\u5b50\u653e\u8fdb\u4ed3\u5e93\u65f6\u9075\u5faa\u4e0b\u5217\u89c4\u5219\uff1a

\n\n
    \n\t
  • \u7bb1\u5b50\u4e0d\u53ef\u53e0\u653e\u3002
  • \n\t
  • \u4f60\u53ef\u4ee5\u91cd\u65b0\u8c03\u6574\u7bb1\u5b50\u7684\u987a\u5e8f\u3002
  • \n\t
  • \u7bb1\u5b50\u53ef\u4ee5\u4ece\u4efb\u610f\u65b9\u5411\uff08\u5de6\u8fb9\u6216\u53f3\u8fb9\uff09\u63a8\u5165\u4ed3\u5e93\u4e2d\u3002
  • \n\t
  • \u5982\u679c\u4ed3\u5e93\u4e2d\u67d0\u623f\u95f4\u7684\u9ad8\u5ea6\u5c0f\u4e8e\u67d0\u7bb1\u5b50\u7684\u9ad8\u5ea6\uff0c\u5219\u8fd9\u4e2a\u7bb1\u5b50\u548c\u4e4b\u540e\u7684\u7bb1\u5b50\u90fd\u4f1a\u505c\u5728\u8fd9\u4e2a\u623f\u95f4\u7684\u524d\u9762\u3002
  • \n
\n\n

\u4f60\u6700\u591a\u53ef\u4ee5\u5728\u4ed3\u5e93\u4e2d\u653e\u8fdb\u591a\u5c11\u4e2a\u7bb1\u5b50\uff1f

\n\n

\u00a0

\n\n

\u793a\u4f8b 1:

\n\"\"\n
\n\u8f93\u5165: boxes = [1,2,2,3,4], warehouse = [3,4,1,2]\n\u8f93\u51fa: 4\n\u89e3\u91ca:\n\"\"\n\u6211\u4eec\u53ef\u4ee5\u6309\u5982\u4e0b\u987a\u5e8f\u63a8\u5165\u7bb1\u5b50:\n1- \u4ece\u5de6\u8fb9\u6216\u53f3\u8fb9\u628a\u9ec4\u8272\u7bb1\u5b50\u63a8\u51652\u53f7\u623f\u95f4\uff1b\n2- \u4ece\u53f3\u8fb9\u628a\u6a59\u8272\u7bb1\u5b50\u63a8\u51653\u53f7\u623f\u95f4\uff1b\n3- \u4ece\u5de6\u8fb9\u628a\u7eff\u8272\u7bb1\u5b50\u63a8\u51651\u53f7\u623f\u95f4\uff1b\n4- \u4ece\u5de6\u8fb9\u628a\u7ea2\u8272\u7bb1\u5b50\u63a8\u51650\u53f7\u623f\u95f4\uff1b\n\u8fd8\u6709\u5176\u4ed6\u65b9\u5f0f\u63a8\u51654\u4e2a\u7bb1\u5b50\uff0c\u6bd4\u5982\u4ea4\u6362\u7ea2\u8272\u4e0e\u7eff\u8272\u7bb1\u5b50\uff0c\u6216\u8005\u4ea4\u6362\u7ea2\u8272\u4e0e\u6a59\u8272\u7bb1\u5b50\u3002\n
\n\n

\u793a\u4f8b 2:

\n\"\"\n
\n\u8f93\u5165: boxes = [3,5,5,2], warehouse = [2,1,3,4,5]\n\u8f93\u51fa: 3\n\u89e3\u91ca:\n\"\"\n\u56e0\u4e3a\u53ea\u6709\u4e00\u4e2a\u9ad8\u5ea6\u5927\u4e8e\u7b49\u4e8e5\u7684\u623f\u95f4\uff0c\u6240\u4ee5\u65e0\u6cd5\u5c06\u4e24\u4e2a\u9ad8\u5ea6\u4e3a5\u7684\u7bb1\u5b50\u90fd\u63a8\u5165\u4ed3\u5e93\u3002\n\u8fd8\u6709\u5176\u4ed6\u65b9\u5f0f\u63a8\u5165\u7bb1\u5b50\uff0c\u6bd4\u5982\u5c06\u7eff\u8272\u7bb1\u5b50\u63a8\u51652\u53f7\u623f\u95f4\uff0c\u6216\u8005\u5728\u7eff\u8272\u53ca\u7ea2\u8272\u7bb1\u5b50\u4e4b\u524d\u5c06\u6a59\u8272\u7bb1\u5b50\u63a8\u51652\u53f7\u623f\u95f4\u3002\n
\n\n

\u793a\u4f8b 3:

\n\n
\n\u8f93\u5165: boxes = [1,2,3], warehouse = [1,2,3,4]\n\u8f93\u51fa: 3\n
\n\n

\u793a\u4f8b 4:

\n\n
\n\u8f93\u5165: boxes = [4,5,6], warehouse = [3,3,3,3,3]\n\u8f93\u51fa: 0\n
\n\n

\u00a0

\n\n

\u63d0\u793a:

\n\n
    \n\t
  • n == warehouse.length
  • \n\t
  • 1 <= boxes.length, warehouse.length <= 105
  • \n\t
  • 1 <= boxes[i], warehouse[i] <= 109
  • \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxBoxesInWarehouse(vector& boxes, vector& warehouse) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxBoxesInWarehouse(int[] boxes, int[] warehouse) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxBoxesInWarehouse(self, boxes, warehouse):\n \"\"\"\n :type boxes: List[int]\n :type warehouse: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxBoxesInWarehouse(self, boxes: List[int], warehouse: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxBoxesInWarehouse(int* boxes, int boxesSize, int* warehouse, int warehouseSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxBoxesInWarehouse(int[] boxes, int[] warehouse) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} boxes\n * @param {number[]} warehouse\n * @return {number}\n */\nvar maxBoxesInWarehouse = function(boxes, warehouse) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} boxes\n# @param {Integer[]} warehouse\n# @return {Integer}\ndef max_boxes_in_warehouse(boxes, warehouse)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxBoxesInWarehouse(_ boxes: [Int], _ warehouse: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxBoxesInWarehouse(boxes []int, warehouse []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxBoxesInWarehouse(boxes: Array[Int], warehouse: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxBoxesInWarehouse(boxes: IntArray, warehouse: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_boxes_in_warehouse(boxes: Vec, warehouse: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $boxes\n * @param Integer[] $warehouse\n * @return Integer\n */\n function maxBoxesInWarehouse($boxes, $warehouse) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxBoxesInWarehouse(boxes: number[], warehouse: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-boxes-in-warehouse boxes warehouse)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1580](https://leetcode-cn.com/problems/put-boxes-into-the-warehouse-ii)", "[\u628a\u7bb1\u5b50\u653e\u8fdb\u4ed3\u5e93\u91cc II](/solution/1500-1599/1580.Put%20Boxes%20Into%20the%20Warehouse%20II/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1580](https://leetcode.com/problems/put-boxes-into-the-warehouse-ii)", "[Put Boxes Into the Warehouse II](/solution/1500-1599/1580.Put%20Boxes%20Into%20the%20Warehouse%20II/README_EN.md)", "`Greedy`", "Medium", "\ud83d\udd12"]}, {"question_id": "1718", "frontend_question_id": "1571", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/warehouse-manager", "url_en": "https://leetcode.com/problems/warehouse-manager", "relative_path_cn": "/solution/1500-1599/1571.Warehouse%20Manager/README.md", "relative_path_en": "/solution/1500-1599/1571.Warehouse%20Manager/README_EN.md", "title_cn": "\u4ed3\u5e93\u7ecf\u7406", "title_en": "Warehouse Manager", "question_title_slug": "warehouse-manager", "content_en": "

Table: Warehouse

\n\n
\n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| name         | varchar |\n| product_id   | int     |\n| units        | int     |\n+--------------+---------+\n(name, product_id) is the primary key for this table.\nEach row of this table contains the information of the products in each warehouse.\n
\n\n

 

\n\n

Table: Products

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| product_id    | int     |\n| product_name  | varchar |\n| Width         | int     |\n| Length        | int     |\n| Height        | int     |\n+---------------+---------+\nproduct_id is the primary key for this table.\nEach row of this table contains the information about the product dimensions (Width, Lenght and Height) in feets of each product.\n
\n\n

 

\n\n

Write an SQL query to report, How much cubic feet of volume does the inventory occupy in each warehouse.

\n\n
    \n\t
  • warehouse_name
  • \n\t
  • volume
  • \n
\n\n

Return the result table in any order.

\n\n

The query result format is in the following example.

\n\n

 

\n\n
\nWarehouse table:\n+------------+--------------+-------------+\n| name       | product_id   | units       |\n+------------+--------------+-------------+\n| LCHouse1   | 1            | 1           |\n| LCHouse1   | 2            | 10          |\n| LCHouse1   | 3            | 5           |\n| LCHouse2   | 1            | 2           |\n| LCHouse2   | 2            | 2           |\n| LCHouse3   | 4            | 1           |\n+------------+--------------+-------------+\n\nProducts table:\n+------------+--------------+------------+----------+-----------+\n| product_id | product_name | Width      | Length   | Height    |\n+------------+--------------+------------+----------+-----------+\n| 1          | LC-TV        | 5          | 50       | 40        |\n| 2          | LC-KeyChain  | 5          | 5        | 5         |\n| 3          | LC-Phone     | 2          | 10       | 10        |\n| 4          | LC-T-Shirt   | 4          | 10       | 20        |\n+------------+--------------+------------+----------+-----------+\n\nResult table:\n+----------------+------------+\n| warehouse_name | volume     | \n+----------------+------------+\n| LCHouse1       | 12250      | \n| LCHouse2       | 20250      |\n| LCHouse3       | 800        |\n+----------------+------------+\nVolume of product_id = 1 (LC-TV), 5x50x40 = 10000\nVolume of product_id = 2 (LC-KeyChain), 5x5x5 = 125 \nVolume of product_id = 3 (LC-Phone), 2x10x10 = 200\nVolume of product_id = 4 (LC-T-Shirt), 4x10x20 = 800\nLCHouse1: 1 unit of LC-TV + 10 units of LC-KeyChain + 5 units of LC-Phone.\n          Total volume: 1*10000 + 10*125  + 5*200 = 12250 cubic feet\nLCHouse2: 2 units of LC-TV + 2 units of LC-KeyChain.\n          Total volume: 2*10000 + 2*125 = 20250 cubic feet\nLCHouse3: 1 unit of LC-T-Shirt.\n          Total volume: 1*800 = 800 cubic feet.\n
\n", "content_cn": "

\u8868:\u00a0Warehouse

\n\n
\n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| name         | varchar |\n| product_id   | int     |\n| units        | int     |\n+--------------+---------+\n(name, product_id) \u662f\u8be5\u8868\u4e3b\u952e.\n\u8be5\u8868\u7684\u884c\u5305\u542b\u4e86\u6bcf\u4e2a\u4ed3\u5e93\u7684\u6240\u6709\u5546\u54c1\u4fe1\u606f.\n
\n\n

\u00a0

\n\n

\u8868: Products

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| product_id    | int     |\n| product_name  | varchar |\n| Width         | int     |\n| Length        | int     |\n| Height        | int     |\n+---------------+---------+\nproduct_id \u662f\u8be5\u8868\u4e3b\u952e.\n\u8be5\u8868\u7684\u884c\u5305\u542b\u4e86\u6bcf\u4ef6\u5546\u54c1\u4ee5\u82f1\u5c3a\u4e3a\u5355\u4f4d\u7684\u5c3a\u5bf8(\u5bbd\u5ea6, \u957f\u5ea6\u548c\u9ad8\u5ea6)\u4fe1\u606f.\n
\n\n

\u00a0

\n\n

\u5199\u4e00\u4e2a SQL\u00a0\u67e5\u8be2\u6765\u62a5\u544a,\u00a0\u6bcf\u4e2a\u4ed3\u5e93\u7684\u5b58\u8d27\u91cf\u662f\u591a\u5c11\u7acb\u65b9\u82f1\u5c3a.

\n\n
    \n\t
  • \u4ed3\u5e93\u540d
  • \n\t
  • \u5b58\u8d27\u91cf
  • \n
\n\n

\u8fd4\u56de\u7ed3\u679c\u6ca1\u6709\u987a\u5e8f\u8981\u6c42.

\n\n

\u67e5\u8be2\u7ed3\u679c\u5982\u4e0b\u4f8b\u6240\u793a.

\n\n

\u00a0

\n\n
\nWarehouse \u8868:\n+------------+--------------+-------------+\n| name       | product_id   | units       |\n+------------+--------------+-------------+\n| LCHouse1   | 1            | 1           |\n| LCHouse1   | 2            | 10          |\n| LCHouse1   | 3            | 5           |\n| LCHouse2   | 1            | 2           |\n| LCHouse2   | 2            | 2           |\n| LCHouse3   | 4            | 1           |\n+------------+--------------+-------------+\n\nProducts \u8868:\n+------------+--------------+------------+----------+-----------+\n| product_id | product_name | Width      | Length   | Height    |\n+------------+--------------+------------+----------+-----------+\n| 1          | LC-TV        | 5          | 50       | 40        |\n| 2          | LC-KeyChain  | 5          | 5        | 5         |\n| 3          | LC-Phone     | 2          | 10       | 10        |\n| 4          | LC-T-Shirt   | 4          | 10       | 20        |\n+------------+--------------+------------+----------+-----------+\n\nResult \u8868:\n+----------------+------------+\n| WAREHOUSE_NAME | VOLUME     | \n+----------------+------------+\n| LCHouse1       | 12250      | \n| LCHouse2       | 20250      |\n| LCHouse3       | 800        |\n+----------------+------------+\nId\u4e3a1\u7684\u5546\u54c1(LC-TV)\u7684\u5b58\u8d27\u91cf\u4e3a 5x50x40 = 10000\nId\u4e3a2\u7684\u5546\u54c1(LC-KeyChain)\u7684\u5b58\u8d27\u91cf\u4e3a 5x5x5 = 125 \nId\u4e3a3\u7684\u5546\u54c1(LC-Phone)\u7684\u5b58\u8d27\u91cf\u4e3a 2x10x10 = 200\nId\u4e3a4\u7684\u5546\u54c1(LC-T-Shirt)\u7684\u5b58\u8d27\u91cf\u4e3a 4x10x20 = 800\n\u4ed3\u5e93LCHouse1: 1\u4e2a\u5355\u4f4d\u7684LC-TV + 10\u4e2a\u5355\u4f4d\u7684LC-KeyChain + 5\u4e2a\u5355\u4f4d\u7684LC-Phone.\n\u00a0         \u603b\u5b58\u8d27\u91cf\u4e3a: 1*10000 + 10*125  + 5*200 = 12250 \u7acb\u65b9\u82f1\u5c3a\n\u4ed3\u5e93LCHouse2: 2\u4e2a\u5355\u4f4d\u7684LC-TV + 2\u4e2a\u5355\u4f4d\u7684LC-KeyChain.\n\u00a0         \u603b\u5b58\u8d27\u91cf\u4e3a: 2*10000 + 2*125 = 20250 \u7acb\u65b9\u82f1\u5c3a\n\u4ed3\u5e93LCHouse3: 1\u4e2a\u5355\u4f4d\u7684LC-T-Shirt.\n          \u603b\u5b58\u8d27\u91cf\u4e3a: 1*800 = 800 \u7acb\u65b9\u82f1\u5c3a.\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1571](https://leetcode-cn.com/problems/warehouse-manager)", "[\u4ed3\u5e93\u7ecf\u7406](/solution/1500-1599/1571.Warehouse%20Manager/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1571](https://leetcode.com/problems/warehouse-manager)", "[Warehouse Manager](/solution/1500-1599/1571.Warehouse%20Manager/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1717", "frontend_question_id": "1595", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-cost-to-connect-two-groups-of-points", "url_en": "https://leetcode.com/problems/minimum-cost-to-connect-two-groups-of-points", "relative_path_cn": "/solution/1500-1599/1595.Minimum%20Cost%20to%20Connect%20Two%20Groups%20of%20Points/README.md", "relative_path_en": "/solution/1500-1599/1595.Minimum%20Cost%20to%20Connect%20Two%20Groups%20of%20Points/README_EN.md", "title_cn": "\u8fde\u901a\u4e24\u7ec4\u70b9\u7684\u6700\u5c0f\u6210\u672c", "title_en": "Minimum Cost to Connect Two Groups of Points", "question_title_slug": "minimum-cost-to-connect-two-groups-of-points", "content_en": "

You are given two groups of points where the first group has size1 points, the second group has size2 points, and size1 >= size2.

\n\n

The cost of the connection between any two points are given in an size1 x size2 matrix where cost[i][j] is the cost of connecting point i of the first group and point j of the second group. The groups are connected if each point in both groups is connected to one or more points in the opposite group. In other words, each point in the first group must be connected to at least one point in the second group, and each point in the second group must be connected to at least one point in the first group.

\n\n

Return the minimum cost it takes to connect the two groups.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: cost = [[15, 96], [36, 2]]\nOutput: 17\nExplanation: The optimal way of connecting the groups is:\n1--A\n2--B\nThis results in a total cost of 17.\n
\n\n

Example 2:

\n\"\"\n
\nInput: cost = [[1, 3, 5], [4, 1, 1], [1, 5, 3]]\nOutput: 4\nExplanation: The optimal way of connecting the groups is:\n1--A\n2--B\n2--C\n3--A\nThis results in a total cost of 4.\nNote that there are multiple points connected to point 2 in the first group and point A in the second group. This does not matter as there is no limit to the number of points that can be connected. We only care about the minimum total cost.\n
\n\n

Example 3:

\n\n
\nInput: cost = [[2, 5, 1], [3, 4, 7], [8, 1, 2], [6, 2, 4], [3, 8, 8]]\nOutput: 10\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • size1 == cost.length
  • \n\t
  • size2 == cost[i].length
  • \n\t
  • 1 <= size1, size2 <= 12
  • \n\t
  • size1 >= size2
  • \n\t
  • 0 <= cost[i][j] <= 100
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e24\u7ec4\u70b9\uff0c\u5176\u4e2d\u7b2c\u4e00\u7ec4\u4e2d\u6709 size1 \u4e2a\u70b9\uff0c\u7b2c\u4e8c\u7ec4\u4e2d\u6709 size2 \u4e2a\u70b9\uff0c\u4e14 size1 >= size2 \u3002

\n\n

\u4efb\u610f\u4e24\u70b9\u95f4\u7684\u8fde\u63a5\u6210\u672c cost \u7531\u5927\u5c0f\u4e3a size1 x size2 \u77e9\u9635\u7ed9\u51fa\uff0c\u5176\u4e2d cost[i][j] \u662f\u7b2c\u4e00\u7ec4\u4e2d\u7684\u70b9 i \u548c\u7b2c\u4e8c\u7ec4\u4e2d\u7684\u70b9 j \u7684\u8fde\u63a5\u6210\u672c\u3002\u5982\u679c\u4e24\u4e2a\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u70b9\u90fd\u4e0e\u53e6\u4e00\u7ec4\u4e2d\u7684\u4e00\u4e2a\u6216\u591a\u4e2a\u70b9\u8fde\u63a5\uff0c\u5219\u79f0\u8fd9\u4e24\u7ec4\u70b9\u662f\u8fde\u901a\u7684\u3002\u6362\u8a00\u4e4b\uff0c\u7b2c\u4e00\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u70b9\u5fc5\u987b\u81f3\u5c11\u4e0e\u7b2c\u4e8c\u7ec4\u4e2d\u7684\u4e00\u4e2a\u70b9\u8fde\u63a5\uff0c\u4e14\u7b2c\u4e8c\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u70b9\u5fc5\u987b\u81f3\u5c11\u4e0e\u7b2c\u4e00\u7ec4\u4e2d\u7684\u4e00\u4e2a\u70b9\u8fde\u63a5\u3002

\n\n

\u8fd4\u56de\u8fde\u901a\u4e24\u7ec4\u70b9\u6240\u9700\u7684\u6700\u5c0f\u6210\u672c\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1acost = [[15, 96], [36, 2]]\n\u8f93\u51fa\uff1a17\n\u89e3\u91ca\uff1a\u8fde\u901a\u4e24\u7ec4\u70b9\u7684\u6700\u4f73\u65b9\u6cd5\u662f\uff1a\n1--A\n2--B\n\u603b\u6210\u672c\u4e3a 17 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1acost = [[1, 3, 5], [4, 1, 1], [1, 5, 3]]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u8fde\u901a\u4e24\u7ec4\u70b9\u7684\u6700\u4f73\u65b9\u6cd5\u662f\uff1a\n1--A\n2--B\n2--C\n3--A\n\u6700\u5c0f\u6210\u672c\u4e3a 4 \u3002\n\u8bf7\u6ce8\u610f\uff0c\u867d\u7136\u6709\u591a\u4e2a\u70b9\u8fde\u63a5\u5230\u7b2c\u4e00\u7ec4\u4e2d\u7684\u70b9 2 \u548c\u7b2c\u4e8c\u7ec4\u4e2d\u7684\u70b9 A \uff0c\u4f46\u7531\u4e8e\u9898\u76ee\u5e76\u4e0d\u9650\u5236\u8fde\u63a5\u70b9\u7684\u6570\u76ee\uff0c\u6240\u4ee5\u53ea\u9700\u8981\u5173\u5fc3\u6700\u4f4e\u603b\u6210\u672c\u3002
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1acost = [[2, 5, 1], [3, 4, 7], [8, 1, 2], [6, 2, 4], [3, 8, 8]]\n\u8f93\u51fa\uff1a10\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • size1 == cost.length
  • \n\t
  • size2 == cost[i].length
  • \n\t
  • 1 <= size1, size2 <= 12
  • \n\t
  • size1 >= size2
  • \n\t
  • 0 <= cost[i][j] <= 100
  • \n
\n", "tags_en": ["Graph", "Dynamic Programming"], "tags_cn": ["\u56fe", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int connectTwoGroups(vector>& cost) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int connectTwoGroups(List> cost) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def connectTwoGroups(self, cost):\n \"\"\"\n :type cost: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def connectTwoGroups(self, cost: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint connectTwoGroups(int** cost, int costSize, int* costColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ConnectTwoGroups(IList> cost) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} cost\n * @return {number}\n */\nvar connectTwoGroups = function(cost) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} cost\n# @return {Integer}\ndef connect_two_groups(cost)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func connectTwoGroups(_ cost: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func connectTwoGroups(cost [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def connectTwoGroups(cost: List[List[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun connectTwoGroups(cost: List>): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn connect_two_groups(cost: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $cost\n * @return Integer\n */\n function connectTwoGroups($cost) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function connectTwoGroups(cost: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (connect-two-groups cost)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1595](https://leetcode-cn.com/problems/minimum-cost-to-connect-two-groups-of-points)", "[\u8fde\u901a\u4e24\u7ec4\u70b9\u7684\u6700\u5c0f\u6210\u672c](/solution/1500-1599/1595.Minimum%20Cost%20to%20Connect%20Two%20Groups%20of%20Points/README.md)", "`\u56fe`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1595](https://leetcode.com/problems/minimum-cost-to-connect-two-groups-of-points)", "[Minimum Cost to Connect Two Groups of Points](/solution/1500-1599/1595.Minimum%20Cost%20to%20Connect%20Two%20Groups%20of%20Points/README_EN.md)", "`Graph`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "1716", "frontend_question_id": "1594", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-non-negative-product-in-a-matrix", "url_en": "https://leetcode.com/problems/maximum-non-negative-product-in-a-matrix", "relative_path_cn": "/solution/1500-1599/1594.Maximum%20Non%20Negative%20Product%20in%20a%20Matrix/README.md", "relative_path_en": "/solution/1500-1599/1594.Maximum%20Non%20Negative%20Product%20in%20a%20Matrix/README_EN.md", "title_cn": "\u77e9\u9635\u7684\u6700\u5927\u975e\u8d1f\u79ef", "title_en": "Maximum Non Negative Product in a Matrix", "question_title_slug": "maximum-non-negative-product-in-a-matrix", "content_en": "

You are given a rows x cols matrix grid. Initially, you are located at the top-left corner (0, 0), and in each step, you can only move right or down in the matrix.

\n\n

Among all possible paths starting from the top-left corner (0, 0) and ending in the bottom-right corner (rows - 1, cols - 1), find the path with the maximum non-negative product. The product of a path is the product of all integers in the grid cells visited along the path.

\n\n

Return the maximum non-negative product modulo 109 + 7If the maximum product is negative return -1.

\n\n

Notice that the modulo is performed after getting the maximum product.

\n\n

 

\n

Example 1:

\n\n
\nInput: grid = [[-1,-2,-3],\n               [-2,-3,-3],\n               [-3,-3,-2]]\nOutput: -1\nExplanation: It's not possible to get non-negative product in the path from (0, 0) to (2, 2), so return -1.\n
\n\n

Example 2:

\n\n
\nInput: grid = [[1,-2,1],\n               [1,-2,1],\n               [3,-4,1]]\nOutput: 8\nExplanation: Maximum non-negative product is in bold (1 * 1 * -2 * -4 * 1 = 8).\n
\n\n

Example 3:

\n\n
\nInput: grid = [[1, 3],\n               [0,-4]]\nOutput: 0\nExplanation: Maximum non-negative product is in bold (1 * 0 * -4 = 0).\n
\n\n

Example 4:

\n\n
\nInput: grid = [[ 1, 4,4,0],\n               [-2, 0,0,1],\n               [ 1,-1,1,1]]\nOutput: 2\nExplanation: Maximum non-negative product is in bold (1 * -2 * 1 * -1 * 1 * 1 = 2).\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= rows, cols <= 15
  • \n\t
  • -4 <= grid[i][j] <= 4
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5927\u5c0f\u4e3a rows x cols \u7684\u77e9\u9635 grid \u3002\u6700\u521d\uff0c\u4f60\u4f4d\u4e8e\u5de6\u4e0a\u89d2 (0, 0) \uff0c\u6bcf\u4e00\u6b65\uff0c\u4f60\u53ef\u4ee5\u5728\u77e9\u9635\u4e2d \u5411\u53f3 \u6216 \u5411\u4e0b \u79fb\u52a8\u3002

\n\n

\u5728\u4ece\u5de6\u4e0a\u89d2 (0, 0) \u5f00\u59cb\u5230\u53f3\u4e0b\u89d2 (rows - 1, cols - 1) \u7ed3\u675f\u7684\u6240\u6709\u8def\u5f84\u4e2d\uff0c\u627e\u51fa\u5177\u6709 \u6700\u5927\u975e\u8d1f\u79ef \u7684\u8def\u5f84\u3002\u8def\u5f84\u7684\u79ef\u662f\u6cbf\u8def\u5f84\u8bbf\u95ee\u7684\u5355\u5143\u683c\u4e2d\u6240\u6709\u6574\u6570\u7684\u4e58\u79ef\u3002

\n\n

\u8fd4\u56de \u6700\u5927\u975e\u8d1f\u79ef \u5bf9 109 + 7 \u53d6\u4f59 \u7684\u7ed3\u679c\u3002\u5982\u679c\u6700\u5927\u79ef\u4e3a\u8d1f\u6570\uff0c\u5219\u8fd4\u56de -1 \u3002

\n\n

\u6ce8\u610f\uff0c\u53d6\u4f59\u662f\u5728\u5f97\u5230\u6700\u5927\u79ef\u4e4b\u540e\u6267\u884c\u7684\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1agrid = [[-1,-2,-3],\n             [-2,-3,-3],\n             [-3,-3,-2]]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u4ece (0, 0) \u5230 (2, 2) \u7684\u8def\u5f84\u4e2d\u65e0\u6cd5\u5f97\u5230\u975e\u8d1f\u79ef\uff0c\u6240\u4ee5\u8fd4\u56de -1\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1agrid = [[1,-2,1],\n             [1,-2,1],\n             [3,-4,1]]\n\u8f93\u51fa\uff1a8\n\u89e3\u91ca\uff1a\u6700\u5927\u975e\u8d1f\u79ef\u5bf9\u5e94\u7684\u8def\u5f84\u5df2\u7ecf\u7528\u7c97\u4f53\u6807\u51fa (1 * 1 * -2 * -4 * 1 = 8)\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1agrid = [[1, 3],\n             [0,-4]]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6700\u5927\u975e\u8d1f\u79ef\u5bf9\u5e94\u7684\u8def\u5f84\u5df2\u7ecf\u7528\u7c97\u4f53\u6807\u51fa (1 * 0 * -4 = 0)\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1agrid = [[ 1, 4,4,0],\n             [-2, 0,0,1],\n             [ 1,-1,1,1]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6700\u5927\u975e\u8d1f\u79ef\u5bf9\u5e94\u7684\u8def\u5f84\u5df2\u7ecf\u7528\u7c97\u4f53\u6807\u51fa (1 * -2 * 1 * -1 * 1 * 1 = 2)\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= rows, cols <= 15
  • \n\t
  • -4 <= grid[i][j] <= 4
  • \n
\n", "tags_en": ["Greedy", "Dynamic Programming"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxProductPath(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxProductPath(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxProductPath(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxProductPath(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxProductPath(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxProductPath(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar maxProductPath = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef max_product_path(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxProductPath(_ grid: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxProductPath(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxProductPath(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxProductPath(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_product_path(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function maxProductPath($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxProductPath(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-product-path grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1594](https://leetcode-cn.com/problems/maximum-non-negative-product-in-a-matrix)", "[\u77e9\u9635\u7684\u6700\u5927\u975e\u8d1f\u79ef](/solution/1500-1599/1594.Maximum%20Non%20Negative%20Product%20in%20a%20Matrix/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1594](https://leetcode.com/problems/maximum-non-negative-product-in-a-matrix)", "[Maximum Non Negative Product in a Matrix](/solution/1500-1599/1594.Maximum%20Non%20Negative%20Product%20in%20a%20Matrix/README_EN.md)", "`Greedy`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "1715", "frontend_question_id": "1593", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/split-a-string-into-the-max-number-of-unique-substrings", "url_en": "https://leetcode.com/problems/split-a-string-into-the-max-number-of-unique-substrings", "relative_path_cn": "/solution/1500-1599/1593.Split%20a%20String%20Into%20the%20Max%20Number%20of%20Unique%20Substrings/README.md", "relative_path_en": "/solution/1500-1599/1593.Split%20a%20String%20Into%20the%20Max%20Number%20of%20Unique%20Substrings/README_EN.md", "title_cn": "\u62c6\u5206\u5b57\u7b26\u4e32\u4f7f\u552f\u4e00\u5b50\u5b57\u7b26\u4e32\u7684\u6570\u76ee\u6700\u5927", "title_en": "Split a String Into the Max Number of Unique Substrings", "question_title_slug": "split-a-string-into-the-max-number-of-unique-substrings", "content_en": "

Given a string s, return the maximum number of unique substrings that the given string can be split into.

\n\n

You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.

\n\n

A substring is a contiguous sequence of characters within a string.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "ababccc"\nOutput: 5\nExplanation: One way to split maximally is ['a', 'b', 'ab', 'c', 'cc']. Splitting like ['a', 'b', 'a', 'b', 'c', 'cc'] is not valid as you have 'a' and 'b' multiple times.\n
\n\n

Example 2:

\n\n
\nInput: s = "aba"\nOutput: 2\nExplanation: One way to split maximally is ['a', 'ba'].\n
\n\n

Example 3:

\n\n
\nInput: s = "aa"\nOutput: 1\nExplanation: It is impossible to split the string any further.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • \n\t

    1 <= s.length <= 16

    \n\t
  • \n\t
  • \n\t

    s contains only lower case English letters.

    \n\t
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \uff0c\u8bf7\u4f60\u62c6\u5206\u8be5\u5b57\u7b26\u4e32\uff0c\u5e76\u8fd4\u56de\u62c6\u5206\u540e\u552f\u4e00\u5b50\u5b57\u7b26\u4e32\u7684\u6700\u5927\u6570\u76ee\u3002

\n\n

\u5b57\u7b26\u4e32 s \u62c6\u5206\u540e\u53ef\u4ee5\u5f97\u5230\u82e5\u5e72 \u975e\u7a7a\u5b50\u5b57\u7b26\u4e32 \uff0c\u8fd9\u4e9b\u5b50\u5b57\u7b26\u4e32\u8fde\u63a5\u540e\u5e94\u5f53\u80fd\u591f\u8fd8\u539f\u4e3a\u539f\u5b57\u7b26\u4e32\u3002\u4f46\u662f\u62c6\u5206\u51fa\u6765\u7684\u6bcf\u4e2a\u5b50\u5b57\u7b26\u4e32\u90fd\u5fc5\u987b\u662f \u552f\u4e00\u7684 \u3002

\n\n

\u6ce8\u610f\uff1a\u5b50\u5b57\u7b26\u4e32 \u662f\u5b57\u7b26\u4e32\u4e2d\u7684\u4e00\u4e2a\u8fde\u7eed\u5b57\u7b26\u5e8f\u5217\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1as = "ababccc"\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u4e00\u79cd\u6700\u5927\u62c6\u5206\u65b9\u6cd5\u4e3a ['a', 'b', 'ab', 'c', 'cc'] \u3002\u50cf ['a', 'b', 'a', 'b', 'c', 'cc'] \u8fd9\u6837\u62c6\u5206\u4e0d\u6ee1\u8db3\u9898\u76ee\u8981\u6c42\uff0c\u56e0\u4e3a\u5176\u4e2d\u7684 'a' \u548c 'b' \u90fd\u51fa\u73b0\u4e86\u4e0d\u6b62\u4e00\u6b21\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1as = "aba"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u4e00\u79cd\u6700\u5927\u62c6\u5206\u65b9\u6cd5\u4e3a ['a', 'ba'] \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1as = "aa"\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u65e0\u6cd5\u8fdb\u4e00\u6b65\u62c6\u5206\u5b57\u7b26\u4e32\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \n\t

    1 <= s.length <= 16

    \n\t
  • \n\t
  • \n\t

    s \u4ec5\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd

    \n\t
  • \n
\n", "tags_en": ["Backtracking"], "tags_cn": ["\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxUniqueSplit(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxUniqueSplit(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxUniqueSplit(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxUniqueSplit(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxUniqueSplit(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxUniqueSplit(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar maxUniqueSplit = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef max_unique_split(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxUniqueSplit(_ s: String) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxUniqueSplit(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxUniqueSplit(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxUniqueSplit(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_unique_split(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function maxUniqueSplit($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxUniqueSplit(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-unique-split s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1593](https://leetcode-cn.com/problems/split-a-string-into-the-max-number-of-unique-substrings)", "[\u62c6\u5206\u5b57\u7b26\u4e32\u4f7f\u552f\u4e00\u5b50\u5b57\u7b26\u4e32\u7684\u6570\u76ee\u6700\u5927](/solution/1500-1599/1593.Split%20a%20String%20Into%20the%20Max%20Number%20of%20Unique%20Substrings/README.md)", "`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1593](https://leetcode.com/problems/split-a-string-into-the-max-number-of-unique-substrings)", "[Split a String Into the Max Number of Unique Substrings](/solution/1500-1599/1593.Split%20a%20String%20Into%20the%20Max%20Number%20of%20Unique%20Substrings/README_EN.md)", "`Backtracking`", "Medium", ""]}, {"question_id": "1714", "frontend_question_id": "1592", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/rearrange-spaces-between-words", "url_en": "https://leetcode.com/problems/rearrange-spaces-between-words", "relative_path_cn": "/solution/1500-1599/1592.Rearrange%20Spaces%20Between%20Words/README.md", "relative_path_en": "/solution/1500-1599/1592.Rearrange%20Spaces%20Between%20Words/README_EN.md", "title_cn": "\u91cd\u65b0\u6392\u5217\u5355\u8bcd\u95f4\u7684\u7a7a\u683c", "title_en": "Rearrange Spaces Between Words", "question_title_slug": "rearrange-spaces-between-words", "content_en": "

You are given a string text of words that are placed among some number of spaces. Each word consists of one or more lowercase English letters and are separated by at least one space. It's guaranteed that text contains at least one word.

\n\n

Rearrange the spaces so that there is an equal number of spaces between every pair of adjacent words and that number is maximized. If you cannot redistribute all the spaces equally, place the extra spaces at the end, meaning the returned string should be the same length as text.

\n\n

Return the string after rearranging the spaces.

\n\n

 

\n

Example 1:

\n\n
\nInput: text = "  this   is  a sentence "\nOutput: "this   is   a   sentence"\nExplanation: There are a total of 9 spaces and 4 words. We can evenly divide the 9 spaces between the words: 9 / (4-1) = 3 spaces.\n
\n\n

Example 2:

\n\n
\nInput: text = " practice   makes   perfect"\nOutput: "practice   makes   perfect "\nExplanation: There are a total of 7 spaces and 3 words. 7 / (3-1) = 3 spaces plus 1 extra space. We place this extra space at the end of the string.\n
\n\n

Example 3:

\n\n
\nInput: text = "hello   world"\nOutput: "hello   world"\n
\n\n

Example 4:

\n\n
\nInput: text = "  walks  udp package   into  bar a"\nOutput: "walks  udp  package  into  bar  a "\n
\n\n

Example 5:

\n\n
\nInput: text = "a"\nOutput: "a"\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= text.length <= 100
  • \n\t
  • text consists of lowercase English letters and ' '.
  • \n\t
  • text contains at least one word.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 text \uff0c\u8be5\u5b57\u7b26\u4e32\u7531\u82e5\u5e72\u88ab\u7a7a\u683c\u5305\u56f4\u7684\u5355\u8bcd\u7ec4\u6210\u3002\u6bcf\u4e2a\u5355\u8bcd\u7531\u4e00\u4e2a\u6216\u8005\u591a\u4e2a\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\uff0c\u5e76\u4e14\u4e24\u4e2a\u5355\u8bcd\u4e4b\u95f4\u81f3\u5c11\u5b58\u5728\u4e00\u4e2a\u7a7a\u683c\u3002\u9898\u76ee\u6d4b\u8bd5\u7528\u4f8b\u4fdd\u8bc1 text \u81f3\u5c11\u5305\u542b\u4e00\u4e2a\u5355\u8bcd \u3002

\n\n

\u8bf7\u4f60\u91cd\u65b0\u6392\u5217\u7a7a\u683c\uff0c\u4f7f\u6bcf\u5bf9\u76f8\u90bb\u5355\u8bcd\u4e4b\u95f4\u7684\u7a7a\u683c\u6570\u76ee\u90fd \u76f8\u7b49 \uff0c\u5e76\u5c3d\u53ef\u80fd \u6700\u5927\u5316 \u8be5\u6570\u76ee\u3002\u5982\u679c\u4e0d\u80fd\u91cd\u65b0\u5e73\u5747\u5206\u914d\u6240\u6709\u7a7a\u683c\uff0c\u8bf7 \u5c06\u591a\u4f59\u7684\u7a7a\u683c\u653e\u7f6e\u5728\u5b57\u7b26\u4e32\u672b\u5c3e \uff0c\u8fd9\u4e5f\u610f\u5473\u7740\u8fd4\u56de\u7684\u5b57\u7b26\u4e32\u5e94\u5f53\u4e0e\u539f text \u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u76f8\u7b49\u3002

\n\n

\u8fd4\u56de \u91cd\u65b0\u6392\u5217\u7a7a\u683c\u540e\u7684\u5b57\u7b26\u4e32 \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1atext = "  this   is  a sentence "\n\u8f93\u51fa\uff1a"this   is   a   sentence"\n\u89e3\u91ca\uff1a\u603b\u5171\u6709 9 \u4e2a\u7a7a\u683c\u548c 4 \u4e2a\u5355\u8bcd\u3002\u53ef\u4ee5\u5c06 9 \u4e2a\u7a7a\u683c\u5e73\u5747\u5206\u914d\u5230\u76f8\u90bb\u5355\u8bcd\u4e4b\u95f4\uff0c\u76f8\u90bb\u5355\u8bcd\u95f4\u7a7a\u683c\u6570\u4e3a\uff1a9 / (4-1) = 3 \u4e2a\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1atext = " practice   makes   perfect"\n\u8f93\u51fa\uff1a"practice   makes   perfect "\n\u89e3\u91ca\uff1a\u603b\u5171\u6709 7 \u4e2a\u7a7a\u683c\u548c 3 \u4e2a\u5355\u8bcd\u30027 / (3-1) = 3 \u4e2a\u7a7a\u683c\u52a0\u4e0a 1 \u4e2a\u591a\u4f59\u7684\u7a7a\u683c\u3002\u591a\u4f59\u7684\u7a7a\u683c\u9700\u8981\u653e\u5728\u5b57\u7b26\u4e32\u7684\u672b\u5c3e\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1atext = "hello   world"\n\u8f93\u51fa\uff1a"hello   world"\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1atext = "  walks  udp package   into  bar a"\n\u8f93\u51fa\uff1a"walks  udp  package  into  bar  a "\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1atext = "a"\n\u8f93\u51fa\uff1a"a"\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= text.length <= 100
  • \n\t
  • text \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u548c ' ' \u7ec4\u6210
  • \n\t
  • text \u4e2d\u81f3\u5c11\u5305\u542b\u4e00\u4e2a\u5355\u8bcd
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string reorderSpaces(string text) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String reorderSpaces(String text) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def reorderSpaces(self, text):\n \"\"\"\n :type text: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def reorderSpaces(self, text: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * reorderSpaces(char * text){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ReorderSpaces(string text) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} text\n * @return {string}\n */\nvar reorderSpaces = function(text) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} text\n# @return {String}\ndef reorder_spaces(text)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func reorderSpaces(_ text: String) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func reorderSpaces(text string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def reorderSpaces(text: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun reorderSpaces(text: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn reorder_spaces(text: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $text\n * @return String\n */\n function reorderSpaces($text) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function reorderSpaces(text: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (reorder-spaces text)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1592](https://leetcode-cn.com/problems/rearrange-spaces-between-words)", "[\u91cd\u65b0\u6392\u5217\u5355\u8bcd\u95f4\u7684\u7a7a\u683c](/solution/1500-1599/1592.Rearrange%20Spaces%20Between%20Words/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1592](https://leetcode.com/problems/rearrange-spaces-between-words)", "[Rearrange Spaces Between Words](/solution/1500-1599/1592.Rearrange%20Spaces%20Between%20Words/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1713", "frontend_question_id": "1570", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/dot-product-of-two-sparse-vectors", "url_en": "https://leetcode.com/problems/dot-product-of-two-sparse-vectors", "relative_path_cn": "/solution/1500-1599/1570.Dot%20Product%20of%20Two%20Sparse%20Vectors/README.md", "relative_path_en": "/solution/1500-1599/1570.Dot%20Product%20of%20Two%20Sparse%20Vectors/README_EN.md", "title_cn": "\u4e24\u4e2a\u7a00\u758f\u5411\u91cf\u7684\u70b9\u79ef", "title_en": "Dot Product of Two Sparse Vectors", "question_title_slug": "dot-product-of-two-sparse-vectors", "content_en": "

Given two sparse vectors, compute their dot product.

\n\n

Implement class SparseVector:

\n\n
    \n\t
  • SparseVector(nums) Initializes the object with the vector nums
  • \n\t
  • dotProduct(vec) Compute the dot product between the instance of SparseVector and vec
  • \n
\n\n

A sparse vector is a vector that has mostly zero values, you should store the sparse vector efficiently and compute the dot product between two SparseVector.

\n\n

Follow up: What if only one of the vectors is sparse?

\n\n

 

\n

Example 1:

\n\n
\nInput: nums1 = [1,0,0,2,3], nums2 = [0,3,0,4,0]\nOutput: 8\nExplanation: v1 = SparseVector(nums1) , v2 = SparseVector(nums2)\nv1.dotProduct(v2) = 1*0 + 0*3 + 0*0 + 2*4 + 3*0 = 8\n
\n\n

Example 2:

\n\n
\nInput: nums1 = [0,1,0,0,0], nums2 = [0,0,0,0,2]\nOutput: 0\nExplanation: v1 = SparseVector(nums1) , v2 = SparseVector(nums2)\nv1.dotProduct(v2) = 0*0 + 1*0 + 0*0 + 0*0 + 0*2 = 0\n
\n\n

Example 3:

\n\n
\nInput: nums1 = [0,1,0,0,2,0,0], nums2 = [1,0,0,0,3,0,4]\nOutput: 6\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == nums1.length == nums2.length
  • \n\t
  • 1 <= n <= 10^5
  • \n\t
  • 0 <= nums1[i], nums2[i] <= 100
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e24\u4e2a\u7a00\u758f\u5411\u91cf\uff0c\u8ba1\u7b97\u5b83\u4eec\u7684\u70b9\u79ef\uff08\u6570\u91cf\u79ef\uff09\u3002

\n\n

\u5b9e\u73b0\u7c7b\u00a0SparseVector\uff1a

\n\n
    \n\t
  • SparseVector(nums)\u00a0\u4ee5\u5411\u91cf\u00a0nums\u00a0\u521d\u59cb\u5316\u5bf9\u8c61\u3002
  • \n\t
  • dotProduct(vec)\u00a0\u8ba1\u7b97\u6b64\u5411\u91cf\u4e0e\u00a0vec\u00a0\u7684\u70b9\u79ef\u3002
  • \n
\n\n

\u7a00\u758f\u5411\u91cf \u662f\u6307\u7edd\u5927\u591a\u6570\u5206\u91cf\u4e3a 0 \u7684\u5411\u91cf\u3002\u4f60\u9700\u8981 \u9ad8\u6548 \u5730\u5b58\u50a8\u8fd9\u4e2a\u5411\u91cf\uff0c\u5e76\u8ba1\u7b97\u4e24\u4e2a\u7a00\u758f\u5411\u91cf\u7684\u70b9\u79ef\u3002

\n\n

\u8fdb\u9636\uff1a\u5f53\u5176\u4e2d\u53ea\u6709\u4e00\u4e2a\u5411\u91cf\u662f\u7a00\u758f\u5411\u91cf\u65f6\uff0c\u4f60\u8be5\u5982\u4f55\u89e3\u51b3\u6b64\u95ee\u9898\uff1f

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1anums1 = [1,0,0,2,3], nums2 = [0,3,0,4,0]\n\u8f93\u51fa\uff1a8\n\u89e3\u91ca\uff1av1 = SparseVector(nums1) , v2 = SparseVector(nums2)\nv1.dotProduct(v2) = 1*0 + 0*3 + 0*0 + 2*4 + 3*0 = 8\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1anums1 = [0,1,0,0,0], nums2 = [0,0,0,0,2]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1av1 = SparseVector(nums1) , v2 = SparseVector(nums2)\nv1.dotProduct(v2) = 0*0 + 1*0 + 0*0 + 0*0 + 0*2 = 0\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1anums1 = [0,1,0,0,2,0,0], nums2 = [1,0,0,0,3,0,4]\n\u8f93\u51fa\uff1a6\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • n == nums1.length == nums2.length
  • \n\t
  • 1 <= n <= 10^5
  • \n\t
  • 0 <= nums1[i], nums2[i]\u00a0<= 100
  • \n
\n", "tags_en": ["Array", "Hash Table", "Two Pointers"], "tags_cn": ["\u6570\u7ec4", "\u54c8\u5e0c\u8868", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class SparseVector {\npublic:\n \n SparseVector(vector &nums) {\n \n }\n \n // Return the dotProduct of two sparse vectors\n int dotProduct(SparseVector& vec) {\n \n }\n};\n\n// Your SparseVector object will be instantiated and called as such:\n// SparseVector v1(nums1);\n// SparseVector v2(nums2);\n// int ans = v1.dotProduct(v2);", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class SparseVector {\n \n SparseVector(int[] nums) {\n \n }\n \n\t// Return the dotProduct of two sparse vectors\n public int dotProduct(SparseVector vec) {\n \n }\n}\n\n// Your SparseVector object will be instantiated and called as such:\n// SparseVector v1 = new SparseVector(nums1);\n// SparseVector v2 = new SparseVector(nums2);\n// int ans = v1.dotProduct(v2);", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class SparseVector:\n def __init__(self, nums):\n \"\"\"\n :type nums: List[int]\n \"\"\"\n \n\n # Return the dotProduct of two sparse vectors\n def dotProduct(self, vec):\n \"\"\"\n :type vec: 'SparseVector'\n :rtype: int\n \"\"\"\n \n\n# Your SparseVector object will be instantiated and called as such:\n# v1 = SparseVector(nums1)\n# v2 = SparseVector(nums2)\n# ans = v1.dotProduct(v2)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class SparseVector:\n def __init__(self, nums: List[int]):\n \n\n # Return the dotProduct of two sparse vectors\n def dotProduct(self, vec: 'SparseVector') -> int:\n \n\n# Your SparseVector object will be instantiated and called as such:\n# v1 = SparseVector(nums1)\n# v2 = SparseVector(nums2)\n# ans = v1.dotProduct(v2)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} SparseVector;\n\n\nSparseVector* sparseVectorCreate(int* nums, int numsSize) {\n \n}\n\n// Return the dotProduct of two sparse vectors\nint sparseVectordotProduct(SparseVector* obj, SparseVector* vec) {\n \n}\n\n/**\n * Your SparseVector struct will be instantiated and called as such:\n * SparseVector* v1 = sparseVectorCreate(nums1, nums1Size);\n * SparseVector* v2 = sparseVectorCreate(nums2, nums2Size);\n * int ans = sparseVectordotProduct(v1, v2);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class SparseVector {\n \n SparseVector(int[] nums) {\n \n }\n \n // Return the dotProduct of two sparse vectors\n public int DotProduct(SparseVector vec) {\n \n }\n}\n\n// Your SparseVector object will be instantiated and called as such:\n// SparseVector v1 = new SparseVector(nums1);\n// SparseVector v2 = new SparseVector(nums2);\n// int ans = v1.DotProduct(v2);", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {SparseVector}\n */\nvar SparseVector = function(nums) {\n \n};\n\n// Return the dotProduct of two sparse vectors\n/**\n * @param {SparseVector} vec\n * @return {number}\n */\nSparseVector.prototype.dotProduct = function(vec) {\n \n};\n\n// Your SparseVector object will be instantiated and called as such:\n// let v1 = new SparseVector(nums1);\n// let v2 = new SparseVector(nums2);\n// let ans = v1.dotProduct(v2);", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class SparseVector\n\n=begin\n :type nums: Integer[]\n=end\n def initialize(nums)\n \n end\n\n# Return the dotProduct of two sparse vectors\n=begin\n :type vec: SparseVector\n :rtype: Integer\n=end\n def dotProduct(vec)\n \n end\nend\n\n# Your SparseVector object will be instantiated and called as such:\n# v1 = SparseVector.new(nums1)\n# v2 = SparseVector.new(nums2)\n# ans = v1.dotProduct(v2)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass SparseVector {\n \n init(_ nums: [Int]) {\n \n }\n\n // Return the dotProduct of two sparse vectors\n func dotProduct(_ vec: SparseVector) -> Int {\n \n }\n}\n\n/**\n * Your SparseVector object will be instantiated and called as such:\n * let v1 = SparseVector(nums1)\n * let v2 = SparseVector(nums2)\n * let ans = v1.dotProduct(v2)\n*/", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type SparseVector struct {\n \n}\n\nfunc Constructor(nums []int) SparseVector {\n \n}\n\n// Return the dotProduct of two sparse vectors\nfunc (this *SparseVector) dotProduct(vec SparseVector) int {\n \n}\n\n/**\n * Your SparseVector object will be instantiated and called as such:\n * v1 := Constructor(nums1);\n * v2 := Constructor(nums2);\n * ans := v1.dotProduct(v2);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class SparseVector(nums: Array[Int]) {\n // Return the dotProduct of two sparse vectors\n def dotProduct(vec: SparseVector): Int = {\n \n }\n}\n\n/**\n * Your SparseVector object will be instantiated and called as such:\n * var v1 = new SparseVector(nums1)\n * var v2 = new SparseVector(nums2)\n * val ans = v1.dotProduct(v2)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class SparseVector(nums: IntArray) {\n // Return the dotProduct of two sparse vectors\n fun dotProduct(vec: SparseVector): Int {\n \n }\n}\n\n/**\n * Your SparseVector object will be instantiated and called as such:\n * var v1 = SparseVector(nums1)\n * var v2 = SparseVector(nums2)\n * val ans = v1.dotProduct(v2)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct SparseVector {\n\t\n}\n\n/** \n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl SparseVector {\n fn new(nums: Vec) -> Self {\n \n }\n\t\n // Return the dotProduct of two sparse vectors\n fn dot_product(&self, vec: SparseVector) -> i32 {\n \n }\n}\n\n/**\n * Your SparseVector object will be instantiated and called as such:\n * let v1 = SparseVector::new(nums1);\n * let v2 = SparseVector::new(nums2);\n * let ans = v1.dot_product(v2);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class SparseVector {\n /**\n * @param Integer[] $nums\n */\n function __construct($nums) {\n \n }\n \n // Return the dotProduct of two sparse vectors\n /**\n * @param SparseVector $vec\n * @return Integer\n */\n function dotProduct($vec) {\n \n }\n}\n\n/**\n * Your SparseVector object will be instantiated and called as such:\n * $v1 = new SparseVector($nums1);\n * $v2 = new SparseVector($nums2);\n * $ans = $v1->dotProduct($v2);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class SparseVector {\n constructor(nums: number[]) {\n\t\t\n }\n\n\t// Return the dotProduct of two sparse vectors\n dotProduct(vec: SparseVector): number {\n\t\t\n }\n}\n\n/**\n * Your SparseVector object will be instantiated and called as such:\n * var v1 = new SparseVector(nums1)\n * var v2 = new SparseVector(nums1)\n * var ans = v1.dotProduct(v2)\n */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1570](https://leetcode-cn.com/problems/dot-product-of-two-sparse-vectors)", "[\u4e24\u4e2a\u7a00\u758f\u5411\u91cf\u7684\u70b9\u79ef](/solution/1500-1599/1570.Dot%20Product%20of%20Two%20Sparse%20Vectors/README.md)", "`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1570](https://leetcode.com/problems/dot-product-of-two-sparse-vectors)", "[Dot Product of Two Sparse Vectors](/solution/1500-1599/1570.Dot%20Product%20of%20Two%20Sparse%20Vectors/README_EN.md)", "`Array`,`Hash Table`,`Two Pointers`", "Medium", "\ud83d\udd12"]}, {"question_id": "1712", "frontend_question_id": "1565", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/unique-orders-and-customers-per-month", "url_en": "https://leetcode.com/problems/unique-orders-and-customers-per-month", "relative_path_cn": "/solution/1500-1599/1565.Unique%20Orders%20and%20Customers%20Per%20Month/README.md", "relative_path_en": "/solution/1500-1599/1565.Unique%20Orders%20and%20Customers%20Per%20Month/README_EN.md", "title_cn": "\u6309\u6708\u7edf\u8ba1\u8ba2\u5355\u6570\u4e0e\u987e\u5ba2\u6570", "title_en": "Unique Orders and Customers Per Month", "question_title_slug": "unique-orders-and-customers-per-month", "content_en": "

Table: Orders

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| order_id      | int     |\n| order_date    | date    |\n| customer_id   | int     |\n| invoice       | int     |\n+---------------+---------+\norder_id is the primary key for this table.\nThis table contains information about the orders made by customer_id.\n
\n\n

 

\n\n

Write an SQL query to find the number of unique orders and the number of unique customers with invoices > $20 for each different month.

\n\n

Return the result table sorted in any order.

\n\n

The query result format is in the following example:

\n\n
\nOrders\n+----------+------------+-------------+------------+\n| order_id | order_date | customer_id | invoice    |\n+----------+------------+-------------+------------+\n| 1        | 2020-09-15 | 1           | 30         |\n| 2        | 2020-09-17 | 2           | 90         |\n| 3        | 2020-10-06 | 3           | 20         |\n| 4        | 2020-10-20 | 3           | 21         |\n| 5        | 2020-11-10 | 1           | 10         |\n| 6        | 2020-11-21 | 2           | 15         |\n| 7        | 2020-12-01 | 4           | 55         |\n| 8        | 2020-12-03 | 4           | 77         |\n| 9        | 2021-01-07 | 3           | 31         |\n| 10       | 2021-01-15 | 2           | 20         |\n+----------+------------+-------------+------------+\n\nResult table:\n+---------+-------------+----------------+\n| month   | order_count | customer_count |\n+---------+-------------+----------------+\n| 2020-09 | 2           | 2              |\n| 2020-10 | 1           | 1              |\n| 2020-12 | 2           | 1              |\n| 2021-01 | 1           | 1              |\n+---------+-------------+----------------+\nIn September 2020 we have two orders from 2 different customers with invoices > $20.\nIn October 2020 we have two orders from 1 customer, and only one of the two orders has invoice > $20.\nIn November 2020 we have two orders from 2 different customers but invoices < $20, so we don't include that month.\nIn December 2020 we have two orders from 1 customer both with invoices > $20.\nIn January 2021 we have two orders from 2 different customers, but only one of them with invoice > $20.\n
\n", "content_cn": "

\u8868\uff1aOrders

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| order_id      | int     |\n| order_date    | date    |\n| customer_id   | int     |\n| invoice       | int     |\n+---------------+---------+\norder_id \u662f Orders \u8868\u7684\u4e3b\u952e\u3002\n\u8fd9\u5f20\u8868\u5305\u542b\u987e\u5ba2(customer_id)\u6240\u4e0b\u8ba2\u5355\u7684\u4fe1\u606f\u3002\n
\n\n

\u5199\u4e00\u4e2a\u67e5\u8be2\u8bed\u53e5\u6765 \u6309\u6708 \u7edf\u8ba1 \u91d1\u989d\u5927\u4e8e $20 \u7684\u552f\u4e00 \u8ba2\u5355\u6570 \u548c\u552f\u4e00 \u987e\u5ba2\u6570 \u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u65e0\u6392\u5e8f\u8981\u6c42\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u9762\u4f8b\u5b50\u6240\u793a\uff1a

\n\n
\nOrders\n+----------+------------+-------------+------------+\n| order_id | order_date | customer_id | invoice    |\n+----------+------------+-------------+------------+\n| 1        | 2020-09-15 | 1           | 30         |\n| 2        | 2020-09-17 | 2           | 90         |\n| 3        | 2020-10-06 | 3           | 20         |\n| 4        | 2020-10-20 | 3           | 21         |\n| 5        | 2020-11-10 | 1           | 10         |\n| 6        | 2020-11-21 | 2           | 15         |\n| 7        | 2020-12-01 | 4           | 55         |\n| 8        | 2020-12-03 | 4           | 77         |\n| 9        | 2021-01-07 | 3           | 31         |\n| 10       | 2021-01-15 | 2           | 20         |\n+----------+------------+-------------+------------+\n\nResult \u8868\uff1a\n+---------+-------------+----------------+\n| month   | order_count | customer_count |\n+---------+-------------+----------------+\n| 2020-09 | 2           | 2              |\n| 2020-10 | 1           | 1              |\n| 2020-12 | 2           | 1              |\n| 2021-01 | 1           | 1              |\n+---------+-------------+----------------+\n\u5728 2020 \u5e74 09 \u6708\uff0c\u6709 2 \u4efd\u6765\u81ea 2 \u4f4d\u4e0d\u540c\u987e\u5ba2\u7684\u91d1\u989d\u5927\u4e8e $20 \u7684\u8ba2\u5355\u3002\n\u5728 2020 \u5e74 10 \u6708\uff0c\u6709 2 \u4efd\u6765\u81ea 1 \u4f4d\u987e\u5ba2\u7684\u8ba2\u5355\uff0c\u5e76\u4e14\u53ea\u6709\u5176\u4e2d\u7684 1 \u4efd\u8ba2\u5355\u91d1\u989d\u5927\u4e8e $20 \u3002\n\u5728 2020 \u5e74 11 \u6708\uff0c\u6709 2 \u4efd\u6765\u81ea 2 \u4f4d\u4e0d\u540c\u987e\u5ba2\u7684\u8ba2\u5355\uff0c\u4f46\u7531\u4e8e\u91d1\u989d\u90fd\u5c0f\u4e8e $20 \uff0c\u6240\u4ee5\u6211\u4eec\u7684\u67e5\u8be2\u7ed3\u679c\u4e2d\u4e0d\u5305\u542b\u8fd9\u4e2a\u6708\u7684\u6570\u636e\u3002\n\u5728 2020 \u5e74 12 \u6708\uff0c\u6709 2 \u4efd\u6765\u81ea 1 \u4f4d\u987e\u5ba2\u7684\u8ba2\u5355\uff0c\u4e14 2 \u4efd\u8ba2\u5355\u91d1\u989d\u90fd\u5927\u4e8e $20 \u3002\n\u5728 2021 \u5e74 01 \u6708\uff0c\u6709 2 \u4efd\u6765\u81ea 2 \u4f4d\u4e0d\u540c\u987e\u5ba2\u7684\u8ba2\u5355\uff0c\u4f46\u53ea\u6709\u5176\u4e2d\u4e00\u4efd\u8ba2\u5355\u91d1\u989d\u5927\u4e8e $20 \u3002\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1565](https://leetcode-cn.com/problems/unique-orders-and-customers-per-month)", "[\u6309\u6708\u7edf\u8ba1\u8ba2\u5355\u6570\u4e0e\u987e\u5ba2\u6570](/solution/1500-1599/1565.Unique%20Orders%20and%20Customers%20Per%20Month/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1565](https://leetcode.com/problems/unique-orders-and-customers-per-month)", "[Unique Orders and Customers Per Month](/solution/1500-1599/1565.Unique%20Orders%20and%20Customers%20Per%20Month/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1711", "frontend_question_id": "1605", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-valid-matrix-given-row-and-column-sums", "url_en": "https://leetcode.com/problems/find-valid-matrix-given-row-and-column-sums", "relative_path_cn": "/solution/1600-1699/1605.Find%20Valid%20Matrix%20Given%20Row%20and%20Column%20Sums/README.md", "relative_path_en": "/solution/1600-1699/1605.Find%20Valid%20Matrix%20Given%20Row%20and%20Column%20Sums/README_EN.md", "title_cn": "\u7ed9\u5b9a\u884c\u548c\u5217\u7684\u548c\u6c42\u53ef\u884c\u77e9\u9635", "title_en": "Find Valid Matrix Given Row and Column Sums", "question_title_slug": "find-valid-matrix-given-row-and-column-sums", "content_en": "

You are given two arrays rowSum and colSum of non-negative integers where rowSum[i] is the sum of the elements in the ith row and colSum[j] is the sum of the elements of the jth column of a 2D matrix. In other words, you do not know the elements of the matrix, but you do know the sums of each row and column.

\n\n

Find any matrix of non-negative integers of size rowSum.length x colSum.length that satisfies the rowSum and colSum requirements.

\n\n

Return a 2D array representing any matrix that fulfills the requirements. It's guaranteed that at least one matrix that fulfills the requirements exists.

\n\n

 

\n

Example 1:

\n\n
\nInput: rowSum = [3,8], colSum = [4,7]\nOutput: [[3,0],\n         [1,7]]\nExplanation:\n0th row: 3 + 0 = 3 == rowSum[0]\n1st row: 1 + 7 = 8 == rowSum[1]\n0th column: 3 + 1 = 4 == colSum[0]\n1st column: 0 + 7 = 7 == colSum[1]\nThe row and column sums match, and all matrix elements are non-negative.\nAnother possible matrix is: [[1,2],\n                             [3,5]]\n
\n\n

Example 2:

\n\n
\nInput: rowSum = [5,7,10], colSum = [8,6,8]\nOutput: [[0,5,0],\n         [6,1,0],\n         [2,0,8]]\n
\n\n

Example 3:

\n\n
\nInput: rowSum = [14,9], colSum = [6,9,8]\nOutput: [[0,9,5],\n         [6,0,3]]\n
\n\n

Example 4:

\n\n
\nInput: rowSum = [1,0], colSum = [1]\nOutput: [[1],\n         [0]]\n
\n\n

Example 5:

\n\n
\nInput: rowSum = [0], colSum = [0]\nOutput: [[0]]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= rowSum.length, colSum.length <= 500
  • \n\t
  • 0 <= rowSum[i], colSum[i] <= 108
  • \n\t
  • sum(rows) == sum(columns)
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e24\u4e2a\u975e\u8d1f\u6574\u6570\u6570\u7ec4\u00a0rowSum \u548c\u00a0colSum\u00a0\uff0c\u5176\u4e2d\u00a0rowSum[i]\u00a0\u662f\u4e8c\u7ef4\u77e9\u9635\u4e2d\u7b2c i\u00a0\u884c\u5143\u7d20\u7684\u548c\uff0c colSum[j]\u00a0\u662f\u7b2c j\u00a0\u5217\u5143\u7d20\u7684\u548c\u3002\u6362\u8a00\u4e4b\u4f60\u4e0d\u77e5\u9053\u77e9\u9635\u91cc\u7684\u6bcf\u4e2a\u5143\u7d20\uff0c\u4f46\u662f\u4f60\u77e5\u9053\u6bcf\u4e00\u884c\u548c\u6bcf\u4e00\u5217\u7684\u548c\u3002

\n\n

\u8bf7\u627e\u5230\u5927\u5c0f\u4e3a\u00a0rowSum.length x colSum.length\u00a0\u7684\u4efb\u610f \u975e\u8d1f\u6574\u6570\u00a0\u77e9\u9635\uff0c\u4e14\u8be5\u77e9\u9635\u6ee1\u8db3\u00a0rowSum \u548c\u00a0colSum\u00a0\u7684\u8981\u6c42\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u4efb\u610f\u4e00\u4e2a\u6ee1\u8db3\u9898\u76ee\u8981\u6c42\u7684\u4e8c\u7ef4\u77e9\u9635\uff0c\u9898\u76ee\u4fdd\u8bc1\u5b58\u5728 \u81f3\u5c11\u4e00\u4e2a\u00a0\u53ef\u884c\u77e9\u9635\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1arowSum = [3,8], colSum = [4,7]\n\u8f93\u51fa\uff1a[[3,0],\n      [1,7]]\n\u89e3\u91ca\uff1a\n\u7b2c 0 \u884c\uff1a3 + 0 = 3 == rowSum[0]\n\u7b2c 1 \u884c\uff1a1 + 7 = 8 == rowSum[1]\n\u7b2c 0 \u5217\uff1a3 + 1 = 4 == colSum[0]\n\u7b2c 1 \u5217\uff1a0 + 7 = 7 == colSum[1]\n\u884c\u548c\u5217\u7684\u548c\u90fd\u6ee1\u8db3\u9898\u76ee\u8981\u6c42\uff0c\u4e14\u6240\u6709\u77e9\u9635\u5143\u7d20\u90fd\u662f\u975e\u8d1f\u7684\u3002\n\u53e6\u4e00\u4e2a\u53ef\u884c\u7684\u77e9\u9635\u4e3a\uff1a[[1,2],\n                  [3,5]]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1arowSum = [5,7,10], colSum = [8,6,8]\n\u8f93\u51fa\uff1a[[0,5,0],\n      [6,1,0],\n      [2,0,8]]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1arowSum = [14,9], colSum = [6,9,8]\n\u8f93\u51fa\uff1a[[0,9,5],\n      [6,0,3]]\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1arowSum = [1,0], colSum = [1]\n\u8f93\u51fa\uff1a[[1],\n      [0]]\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\n\u8f93\u5165\uff1arowSum = [0], colSum = [0]\n\u8f93\u51fa\uff1a[[0]]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= rowSum.length, colSum.length <= 500
  • \n\t
  • 0 <= rowSum[i], colSum[i] <= 108
  • \n\t
  • sum(rows) == sum(columns)
  • \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> restoreMatrix(vector& rowSum, vector& colSum) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[][] restoreMatrix(int[] rowSum, int[] colSum) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def restoreMatrix(self, rowSum, colSum):\n \"\"\"\n :type rowSum: List[int]\n :type colSum: List[int]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def restoreMatrix(self, rowSum: List[int], colSum: List[int]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** restoreMatrix(int* rowSum, int rowSumSize, int* colSum, int colSumSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[][] RestoreMatrix(int[] rowSum, int[] colSum) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} rowSum\n * @param {number[]} colSum\n * @return {number[][]}\n */\nvar restoreMatrix = function(rowSum, colSum) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} row_sum\n# @param {Integer[]} col_sum\n# @return {Integer[][]}\ndef restore_matrix(row_sum, col_sum)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func restoreMatrix(_ rowSum: [Int], _ colSum: [Int]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func restoreMatrix(rowSum []int, colSum []int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def restoreMatrix(rowSum: Array[Int], colSum: Array[Int]): Array[Array[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun restoreMatrix(rowSum: IntArray, colSum: IntArray): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn restore_matrix(row_sum: Vec, col_sum: Vec) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $rowSum\n * @param Integer[] $colSum\n * @return Integer[][]\n */\n function restoreMatrix($rowSum, $colSum) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function restoreMatrix(rowSum: number[], colSum: number[]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (restore-matrix rowSum colSum)\n (-> (listof exact-integer?) (listof exact-integer?) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1605](https://leetcode-cn.com/problems/find-valid-matrix-given-row-and-column-sums)", "[\u7ed9\u5b9a\u884c\u548c\u5217\u7684\u548c\u6c42\u53ef\u884c\u77e9\u9635](/solution/1600-1699/1605.Find%20Valid%20Matrix%20Given%20Row%20and%20Column%20Sums/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1605](https://leetcode.com/problems/find-valid-matrix-given-row-and-column-sums)", "[Find Valid Matrix Given Row and Column Sums](/solution/1600-1699/1605.Find%20Valid%20Matrix%20Given%20Row%20and%20Column%20Sums/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1710", "frontend_question_id": "1606", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-servers-that-handled-most-number-of-requests", "url_en": "https://leetcode.com/problems/find-servers-that-handled-most-number-of-requests", "relative_path_cn": "/solution/1600-1699/1606.Find%20Servers%20That%20Handled%20Most%20Number%20of%20Requests/README.md", "relative_path_en": "/solution/1600-1699/1606.Find%20Servers%20That%20Handled%20Most%20Number%20of%20Requests/README_EN.md", "title_cn": "\u627e\u5230\u5904\u7406\u6700\u591a\u8bf7\u6c42\u7684\u670d\u52a1\u5668", "title_en": "Find Servers That Handled Most Number of Requests", "question_title_slug": "find-servers-that-handled-most-number-of-requests", "content_en": "

You have k servers numbered from 0 to k-1 that are being used to handle multiple requests simultaneously. Each server has infinite computational capacity but cannot handle more than one request at a time. The requests are assigned to servers according to a specific algorithm:

\n\n
    \n\t
  • The ith (0-indexed) request arrives.
  • \n\t
  • If all servers are busy, the request is dropped (not handled at all).
  • \n\t
  • If the (i % k)th server is available, assign the request to that server.
  • \n\t
  • Otherwise, assign the request to the next available server (wrapping around the list of servers and starting from 0 if necessary). For example, if the ith server is busy, try to assign the request to the (i+1)th server, then the (i+2)th server, and so on.
  • \n
\n\n

You are given a strictly increasing array arrival of positive integers, where arrival[i] represents the arrival time of the ith request, and another array load, where load[i] represents the load of the ith request (the time it takes to complete). Your goal is to find the busiest server(s). A server is considered busiest if it handled the most number of requests successfully among all the servers.

\n\n

Return a list containing the IDs (0-indexed) of the busiest server(s). You may return the IDs in any order.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: k = 3, arrival = [1,2,3,4,5], load = [5,2,3,3,3] \nOutput: [1] \nExplanation:\nAll of the servers start out available.\nThe first 3 requests are handled by the first 3 servers in order.\nRequest 3 comes in. Server 0 is busy, so it's assigned to the next available server, which is 1.\nRequest 4 comes in. It cannot be handled since all servers are busy, so it is dropped.\nServers 0 and 2 handled one request each, while server 1 handled two requests. Hence server 1 is the busiest server.\n
\n\n

Example 2:

\n\n
\nInput: k = 3, arrival = [1,2,3,4], load = [1,2,1,2]\nOutput: [0]\nExplanation:\nThe first 3 requests are handled by first 3 servers.\nRequest 3 comes in. It is handled by server 0 since the server is available.\nServer 0 handled two requests, while servers 1 and 2 handled one request each. Hence server 0 is the busiest server.\n
\n\n

Example 3:

\n\n
\nInput: k = 3, arrival = [1,2,3], load = [10,12,11]\nOutput: [0,1,2]\nExplanation: Each server handles a single request, so they are all considered the busiest.\n
\n\n

Example 4:

\n\n
\nInput: k = 3, arrival = [1,2,3,4,8,9,10], load = [5,2,10,3,1,2,2]\nOutput: [1]\n
\n\n

Example 5:

\n\n
\nInput: k = 1, arrival = [1], load = [1]\nOutput: [0]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= k <= 105
  • \n\t
  • 1 <= arrival.length, load.length <= 105
  • \n\t
  • arrival.length == load.length
  • \n\t
  • 1 <= arrival[i], load[i] <= 109
  • \n\t
  • arrival is strictly increasing.
  • \n
\n", "content_cn": "

\u4f60\u6709 k\u00a0\u4e2a\u670d\u52a1\u5668\uff0c\u7f16\u53f7\u4e3a 0\u00a0\u5230 k-1\u00a0\uff0c\u5b83\u4eec\u53ef\u4ee5\u540c\u65f6\u5904\u7406\u591a\u4e2a\u8bf7\u6c42\u7ec4\u3002\u6bcf\u4e2a\u670d\u52a1\u5668\u6709\u65e0\u7a77\u7684\u8ba1\u7b97\u80fd\u529b\u4f46\u662f \u4e0d\u80fd\u540c\u65f6\u5904\u7406\u8d85\u8fc7\u4e00\u4e2a\u8bf7\u6c42\u00a0\u3002\u8bf7\u6c42\u5206\u914d\u5230\u670d\u52a1\u5668\u7684\u89c4\u5219\u5982\u4e0b\uff1a

\n\n
    \n\t
  • \u7b2c\u00a0i\u00a0\uff08\u5e8f\u53f7\u4ece 0 \u5f00\u59cb\uff09\u4e2a\u8bf7\u6c42\u5230\u8fbe\u3002
  • \n\t
  • \u5982\u679c\u6240\u6709\u670d\u52a1\u5668\u90fd\u5df2\u88ab\u5360\u636e\uff0c\u90a3\u4e48\u8be5\u8bf7\u6c42\u88ab\u820d\u5f03\uff08\u5b8c\u5168\u4e0d\u5904\u7406\uff09\u3002
  • \n\t
  • \u5982\u679c\u7b2c\u00a0(i % k)\u00a0\u4e2a\u670d\u52a1\u5668\u7a7a\u95f2\uff0c\u90a3\u4e48\u5bf9\u5e94\u670d\u52a1\u5668\u4f1a\u5904\u7406\u8be5\u8bf7\u6c42\u3002
  • \n\t
  • \u5426\u5219\uff0c\u5c06\u8bf7\u6c42\u5b89\u6392\u7ed9\u4e0b\u4e00\u4e2a\u7a7a\u95f2\u7684\u670d\u52a1\u5668\uff08\u670d\u52a1\u5668\u6784\u6210\u4e00\u4e2a\u73af\uff0c\u5fc5\u8981\u7684\u8bdd\u53ef\u80fd\u4ece\u7b2c 0 \u4e2a\u670d\u52a1\u5668\u5f00\u59cb\u7ee7\u7eed\u627e\u4e0b\u4e00\u4e2a\u7a7a\u95f2\u7684\u670d\u52a1\u5668\uff09\u3002\u6bd4\u65b9\u8bf4\uff0c\u5982\u679c\u7b2c i\u00a0\u4e2a\u670d\u52a1\u5668\u5728\u5fd9\uff0c\u90a3\u4e48\u4f1a\u67e5\u770b\u7b2c (i+1)\u00a0\u4e2a\u670d\u52a1\u5668\uff0c\u7b2c (i+2)\u00a0\u4e2a\u670d\u52a1\u5668\u7b49\u7b49\u3002
  • \n
\n\n

\u7ed9\u4f60\u4e00\u4e2a \u4e25\u683c\u9012\u589e\u00a0\u7684\u6b63\u6574\u6570\u6570\u7ec4\u00a0arrival\u00a0\uff0c\u8868\u793a\u7b2c\u00a0i\u00a0\u4e2a\u4efb\u52a1\u7684\u5230\u8fbe\u65f6\u95f4\uff0c\u548c\u53e6\u4e00\u4e2a\u6570\u7ec4\u00a0load\u00a0\uff0c\u5176\u4e2d\u00a0load[i]\u00a0\u8868\u793a\u7b2c\u00a0i\u00a0\u4e2a\u8bf7\u6c42\u7684\u5de5\u4f5c\u91cf\uff08\u4e5f\u5c31\u662f\u670d\u52a1\u5668\u5b8c\u6210\u5b83\u6240\u9700\u8981\u7684\u65f6\u95f4\uff09\u3002\u4f60\u7684\u4efb\u52a1\u662f\u627e\u5230 \u6700\u7e41\u5fd9\u7684\u670d\u52a1\u5668\u00a0\u3002\u6700\u7e41\u5fd9\u5b9a\u4e49\u4e3a\u4e00\u4e2a\u670d\u52a1\u5668\u5904\u7406\u7684\u8bf7\u6c42\u6570\u662f\u6240\u6709\u670d\u52a1\u5668\u91cc\u6700\u591a\u7684\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u5305\u542b\u6240\u6709\u00a0\u6700\u7e41\u5fd9\u670d\u52a1\u5668\u00a0\u5e8f\u53f7\u7684\u5217\u8868\uff0c\u4f60\u53ef\u4ee5\u4ee5\u4efb\u610f\u987a\u5e8f\u8fd4\u56de\u8fd9\u4e2a\u5217\u8868\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1ak = 3, arrival = [1,2,3,4,5], load = [5,2,3,3,3] \n\u8f93\u51fa\uff1a[1] \n\u89e3\u91ca\uff1a\n\u6240\u6709\u670d\u52a1\u5668\u4e00\u5f00\u59cb\u90fd\u662f\u7a7a\u95f2\u7684\u3002\n\u524d 3 \u4e2a\u8bf7\u6c42\u5206\u522b\u7531\u524d 3 \u53f0\u670d\u52a1\u5668\u4f9d\u6b21\u5904\u7406\u3002\n\u8bf7\u6c42 3 \u8fdb\u6765\u7684\u65f6\u5019\uff0c\u670d\u52a1\u5668 0 \u88ab\u5360\u636e\uff0c\u6240\u4ee5\u5b83\u5457\u5b89\u6392\u5230\u4e0b\u4e00\u53f0\u7a7a\u95f2\u7684\u670d\u52a1\u5668\uff0c\u4e5f\u5c31\u662f\u670d\u52a1\u5668 1 \u3002\n\u8bf7\u6c42 4 \u8fdb\u6765\u7684\u65f6\u5019\uff0c\u7531\u4e8e\u6240\u6709\u670d\u52a1\u5668\u90fd\u88ab\u5360\u636e\uff0c\u8be5\u8bf7\u6c42\u88ab\u820d\u5f03\u3002\n\u670d\u52a1\u5668 0 \u548c 2 \u5206\u522b\u90fd\u5904\u7406\u4e86\u4e00\u4e2a\u8bf7\u6c42\uff0c\u670d\u52a1\u5668 1 \u5904\u7406\u4e86\u4e24\u4e2a\u8bf7\u6c42\u3002\u6240\u4ee5\u670d\u52a1\u5668 1 \u662f\u6700\u5fd9\u7684\u670d\u52a1\u5668\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1ak = 3, arrival = [1,2,3,4], load = [1,2,1,2]\n\u8f93\u51fa\uff1a[0]\n\u89e3\u91ca\uff1a\n\u524d 3 \u4e2a\u8bf7\u6c42\u5206\u522b\u88ab\u524d 3 \u4e2a\u670d\u52a1\u5668\u5904\u7406\u3002\n\u8bf7\u6c42 3 \u8fdb\u6765\uff0c\u7531\u4e8e\u670d\u52a1\u5668 0 \u7a7a\u95f2\uff0c\u5b83\u88ab\u670d\u52a1\u5668 0 \u5904\u7406\u3002\n\u670d\u52a1\u5668 0 \u5904\u7406\u4e86\u4e24\u4e2a\u8bf7\u6c42\uff0c\u670d\u52a1\u5668 1 \u548c 2 \u5206\u522b\u5904\u7406\u4e86\u4e00\u4e2a\u8bf7\u6c42\u3002\u6240\u4ee5\u670d\u52a1\u5668 0 \u662f\u6700\u5fd9\u7684\u670d\u52a1\u5668\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1ak = 3, arrival = [1,2,3], load = [10,12,11]\n\u8f93\u51fa\uff1a[0,1,2]\n\u89e3\u91ca\uff1a\u6bcf\u4e2a\u670d\u52a1\u5668\u5206\u522b\u5904\u7406\u4e86\u4e00\u4e2a\u8bf7\u6c42\uff0c\u6240\u4ee5\u5b83\u4eec\u90fd\u662f\u6700\u5fd9\u7684\u670d\u52a1\u5668\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1ak = 3, arrival = [1,2,3,4,8,9,10], load = [5,2,10,3,1,2,2]\n\u8f93\u51fa\uff1a[1]\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\n\u8f93\u5165\uff1ak = 1, arrival = [1], load = [1]\n\u8f93\u51fa\uff1a[0]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= k <= 105
  • \n\t
  • 1 <= arrival.length, load.length <= 105
  • \n\t
  • arrival.length == load.length
  • \n\t
  • 1 <= arrival[i], load[i] <= 109
  • \n\t
  • arrival\u00a0\u4fdd\u8bc1 \u4e25\u683c\u9012\u589e\u00a0\u3002
  • \n
\n", "tags_en": ["Ordered Map"], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector busiestServers(int k, vector& arrival, vector& load) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List busiestServers(int k, int[] arrival, int[] load) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def busiestServers(self, k, arrival, load):\n \"\"\"\n :type k: int\n :type arrival: List[int]\n :type load: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def busiestServers(self, k: int, arrival: List[int], load: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* busiestServers(int k, int* arrival, int arrivalSize, int* load, int loadSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList BusiestServers(int k, int[] arrival, int[] load) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} k\n * @param {number[]} arrival\n * @param {number[]} load\n * @return {number[]}\n */\nvar busiestServers = function(k, arrival, load) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} k\n# @param {Integer[]} arrival\n# @param {Integer[]} load\n# @return {Integer[]}\ndef busiest_servers(k, arrival, load)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func busiestServers(_ k: Int, _ arrival: [Int], _ load: [Int]) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func busiestServers(k int, arrival []int, load []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def busiestServers(k: Int, arrival: Array[Int], load: Array[Int]): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun busiestServers(k: Int, arrival: IntArray, load: IntArray): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn busiest_servers(k: i32, arrival: Vec, load: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $k\n * @param Integer[] $arrival\n * @param Integer[] $load\n * @return Integer[]\n */\n function busiestServers($k, $arrival, $load) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function busiestServers(k: number, arrival: number[], load: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (busiest-servers k arrival load)\n (-> exact-integer? (listof exact-integer?) (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1606](https://leetcode-cn.com/problems/find-servers-that-handled-most-number-of-requests)", "[\u627e\u5230\u5904\u7406\u6700\u591a\u8bf7\u6c42\u7684\u670d\u52a1\u5668](/solution/1600-1699/1606.Find%20Servers%20That%20Handled%20Most%20Number%20of%20Requests/README.md)", "", "\u56f0\u96be", ""], "md_table_row_en": ["[1606](https://leetcode.com/problems/find-servers-that-handled-most-number-of-requests)", "[Find Servers That Handled Most Number of Requests](/solution/1600-1699/1606.Find%20Servers%20That%20Handled%20Most%20Number%20of%20Requests/README_EN.md)", "`Ordered Map`", "Hard", ""]}, {"question_id": "1709", "frontend_question_id": "1604", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/alert-using-same-key-card-three-or-more-times-in-a-one-hour-period", "url_en": "https://leetcode.com/problems/alert-using-same-key-card-three-or-more-times-in-a-one-hour-period", "relative_path_cn": "/solution/1600-1699/1604.Alert%20Using%20Same%20Key-Card%20Three%20or%20More%20Times%20in%20a%20One%20Hour%20Period/README.md", "relative_path_en": "/solution/1600-1699/1604.Alert%20Using%20Same%20Key-Card%20Three%20or%20More%20Times%20in%20a%20One%20Hour%20Period/README_EN.md", "title_cn": "\u8b66\u544a\u4e00\u5c0f\u65f6\u5185\u4f7f\u7528\u76f8\u540c\u5458\u5de5\u5361\u5927\u4e8e\u7b49\u4e8e\u4e09\u6b21\u7684\u4eba", "title_en": "Alert Using Same Key-Card Three or More Times in a One Hour Period", "question_title_slug": "alert-using-same-key-card-three-or-more-times-in-a-one-hour-period", "content_en": "

LeetCode company workers use key-cards to unlock office doors. Each time a worker uses their key-card, the security system saves the worker's name and the time when it was used. The system emits an alert if any worker uses the key-card three or more times in a one-hour period.

\n\n

You are given a list of strings keyName and keyTime where [keyName[i], keyTime[i]] corresponds to a person's name and the time when their key-card was used in a single day.

\n\n

Access times are given in the 24-hour time format "HH:MM", such as "23:51" and "09:49".

\n\n

Return a list of unique worker names who received an alert for frequent keycard use. Sort the names in ascending order alphabetically.

\n\n

Notice that "10:00" - "11:00" is considered to be within a one-hour period, while "22:51" - "23:52" is not considered to be within a one-hour period.

\n\n

 

\n

Example 1:

\n\n
\nInput: keyName = ["daniel","daniel","daniel","luis","luis","luis","luis"], keyTime = ["10:00","10:40","11:00","09:00","11:00","13:00","15:00"]\nOutput: ["daniel"]\nExplanation: "daniel" used the keycard 3 times in a one-hour period ("10:00","10:40", "11:00").\n
\n\n

Example 2:

\n\n
\nInput: keyName = ["alice","alice","alice","bob","bob","bob","bob"], keyTime = ["12:01","12:00","18:00","21:00","21:20","21:30","23:00"]\nOutput: ["bob"]\nExplanation: "bob" used the keycard 3 times in a one-hour period ("21:00","21:20", "21:30").\n
\n\n

Example 3:

\n\n
\nInput: keyName = ["john","john","john"], keyTime = ["23:58","23:59","00:01"]\nOutput: []\n
\n\n

Example 4:

\n\n
\nInput: keyName = ["leslie","leslie","leslie","clare","clare","clare","clare"], keyTime = ["13:00","13:20","14:00","18:00","18:51","19:30","19:49"]\nOutput: ["clare","leslie"]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= keyName.length, keyTime.length <= 105
  • \n\t
  • keyName.length == keyTime.length
  • \n\t
  • keyTime[i] is in the format "HH:MM".
  • \n\t
  • [keyName[i], keyTime[i]] is unique.
  • \n\t
  • 1 <= keyName[i].length <= 10
  • \n\t
  • keyName[i] contains only lowercase English letters.
  • \n
\n", "content_cn": "

\u529b\u6263\u516c\u53f8\u7684\u5458\u5de5\u90fd\u4f7f\u7528\u5458\u5de5\u5361\u6765\u5f00\u529e\u516c\u5ba4\u7684\u95e8\u3002\u6bcf\u5f53\u4e00\u4e2a\u5458\u5de5\u4f7f\u7528\u4e00\u6b21\u4ed6\u7684\u5458\u5de5\u5361\uff0c\u5b89\u4fdd\u7cfb\u7edf\u4f1a\u8bb0\u5f55\u4e0b\u5458\u5de5\u7684\u540d\u5b57\u548c\u4f7f\u7528\u65f6\u95f4\u3002\u5982\u679c\u4e00\u4e2a\u5458\u5de5\u5728\u4e00\u5c0f\u65f6\u65f6\u95f4\u5185\u4f7f\u7528\u5458\u5de5\u5361\u7684\u6b21\u6570\u5927\u4e8e\u7b49\u4e8e\u4e09\u6b21\uff0c\u8fd9\u4e2a\u7cfb\u7edf\u4f1a\u81ea\u52a8\u53d1\u5e03\u4e00\u4e2a \u8b66\u544a\u00a0\u3002

\n\n

\u7ed9\u4f60\u5b57\u7b26\u4e32\u6570\u7ec4\u00a0keyName\u00a0\u548c\u00a0keyTime \uff0c\u5176\u4e2d\u00a0[keyName[i], keyTime[i]]\u00a0\u5bf9\u5e94\u4e00\u4e2a\u4eba\u7684\u540d\u5b57\u548c\u4ed6\u5728\u00a0\u67d0\u4e00\u5929 \u5185\u4f7f\u7528\u5458\u5de5\u5361\u7684\u65f6\u95f4\u3002

\n\n

\u4f7f\u7528\u65f6\u95f4\u7684\u683c\u5f0f\u662f 24\u5c0f\u65f6\u5236\u00a0\uff0c\u5f62\u5982\u00a0\"HH:MM\"\u00a0\uff0c\u6bd4\u65b9\u8bf4\u00a0\"23:51\" \u548c\u00a0\"09:49\"\u00a0\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u53bb\u91cd\u540e\u7684\u6536\u5230\u7cfb\u7edf\u8b66\u544a\u7684\u5458\u5de5\u540d\u5b57\uff0c\u5c06\u5b83\u4eec\u6309 \u5b57\u5178\u5e8f\u5347\u5e8f\u00a0\u6392\u5e8f\u540e\u8fd4\u56de\u3002

\n\n

\u8bf7\u6ce8\u610f\u00a0\"10:00\" - \"11:00\"\u00a0\u89c6\u4e3a\u4e00\u4e2a\u5c0f\u65f6\u65f6\u95f4\u8303\u56f4\u5185\uff0c\u800c\u00a0\"23:51\" - \"00:10\"\u00a0\u4e0d\u88ab\u89c6\u4e3a\u4e00\u5c0f\u65f6\u5185\uff0c\u56e0\u4e3a\u7cfb\u7edf\u8bb0\u5f55\u7684\u662f\u67d0\u4e00\u5929\u5185\u7684\u4f7f\u7528\u60c5\u51b5\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1akeyName = [\"daniel\",\"daniel\",\"daniel\",\"luis\",\"luis\",\"luis\",\"luis\"], keyTime = [\"10:00\",\"10:40\",\"11:00\",\"09:00\",\"11:00\",\"13:00\",\"15:00\"]\n\u8f93\u51fa\uff1a[\"daniel\"]\n\u89e3\u91ca\uff1a\"daniel\" \u5728\u4e00\u5c0f\u65f6\u5185\u4f7f\u7528\u4e86 3 \u6b21\u5458\u5de5\u5361\uff08\"10:00\"\uff0c\"10:40\"\uff0c\"11:00\"\uff09\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1akeyName = [\"alice\",\"alice\",\"alice\",\"bob\",\"bob\",\"bob\",\"bob\"], keyTime = [\"12:01\",\"12:00\",\"18:00\",\"21:00\",\"21:20\",\"21:30\",\"23:00\"]\n\u8f93\u51fa\uff1a[\"bob\"]\n\u89e3\u91ca\uff1a\"bob\" \u5728\u4e00\u5c0f\u65f6\u5185\u4f7f\u7528\u4e86 3 \u6b21\u5458\u5de5\u5361\uff08\"21:00\"\uff0c\"21:20\"\uff0c\"21:30\"\uff09\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1akeyName = [\"john\",\"john\",\"john\"], keyTime = [\"23:58\",\"23:59\",\"00:01\"]\n\u8f93\u51fa\uff1a[]\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1akeyName = [\"leslie\",\"leslie\",\"leslie\",\"clare\",\"clare\",\"clare\",\"clare\"], keyTime = [\"13:00\",\"13:20\",\"14:00\",\"18:00\",\"18:51\",\"19:30\",\"19:49\"]\n\u8f93\u51fa\uff1a[\"clare\",\"leslie\"]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= keyName.length, keyTime.length <= 105
  • \n\t
  • keyName.length == keyTime.length
  • \n\t
  • keyTime \u683c\u5f0f\u4e3a\u00a0\"HH:MM\"\u00a0\u3002
  • \n\t
  • \u4fdd\u8bc1\u00a0[keyName[i], keyTime[i]]\u00a0\u5f62\u6210\u7684\u4e8c\u5143\u5bf9\u00a0\u4e92\u4e0d\u76f8\u540c\u00a0\u3002
  • \n\t
  • 1 <= keyName[i].length <= 10
  • \n\t
  • keyName[i]\u00a0\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
  • \n
\n", "tags_en": ["String", "Ordered Map"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector alertNames(vector& keyName, vector& keyTime) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List alertNames(String[] keyName, String[] keyTime) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def alertNames(self, keyName, keyTime):\n \"\"\"\n :type keyName: List[str]\n :type keyTime: List[str]\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def alertNames(self, keyName: List[str], keyTime: List[str]) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** alertNames(char ** keyName, int keyNameSize, char ** keyTime, int keyTimeSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList AlertNames(string[] keyName, string[] keyTime) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} keyName\n * @param {string[]} keyTime\n * @return {string[]}\n */\nvar alertNames = function(keyName, keyTime) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} key_name\n# @param {String[]} key_time\n# @return {String[]}\ndef alert_names(key_name, key_time)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func alertNames(_ keyName: [String], _ keyTime: [String]) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func alertNames(keyName []string, keyTime []string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def alertNames(keyName: Array[String], keyTime: Array[String]): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun alertNames(keyName: Array, keyTime: Array): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn alert_names(key_name: Vec, key_time: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $keyName\n * @param String[] $keyTime\n * @return String[]\n */\n function alertNames($keyName, $keyTime) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function alertNames(keyName: string[], keyTime: string[]): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (alert-names keyName keyTime)\n (-> (listof string?) (listof string?) (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1604](https://leetcode-cn.com/problems/alert-using-same-key-card-three-or-more-times-in-a-one-hour-period)", "[\u8b66\u544a\u4e00\u5c0f\u65f6\u5185\u4f7f\u7528\u76f8\u540c\u5458\u5de5\u5361\u5927\u4e8e\u7b49\u4e8e\u4e09\u6b21\u7684\u4eba](/solution/1600-1699/1604.Alert%20Using%20Same%20Key-Card%20Three%20or%20More%20Times%20in%20a%20One%20Hour%20Period/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1604](https://leetcode.com/problems/alert-using-same-key-card-three-or-more-times-in-a-one-hour-period)", "[Alert Using Same Key-Card Three or More Times in a One Hour Period](/solution/1600-1699/1604.Alert%20Using%20Same%20Key-Card%20Three%20or%20More%20Times%20in%20a%20One%20Hour%20Period/README_EN.md)", "`String`,`Ordered Map`", "Medium", ""]}, {"question_id": "1708", "frontend_question_id": "1603", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/design-parking-system", "url_en": "https://leetcode.com/problems/design-parking-system", "relative_path_cn": "/solution/1600-1699/1603.Design%20Parking%20System/README.md", "relative_path_en": "/solution/1600-1699/1603.Design%20Parking%20System/README_EN.md", "title_cn": "\u8bbe\u8ba1\u505c\u8f66\u7cfb\u7edf", "title_en": "Design Parking System", "question_title_slug": "design-parking-system", "content_en": "

Design a parking system for a parking lot. The parking lot has three kinds of parking spaces: big, medium, and small, with a fixed number of slots for each size.

\n\n

Implement the ParkingSystem class:

\n\n
    \n\t
  • ParkingSystem(int big, int medium, int small) Initializes object of the ParkingSystem class. The number of slots for each parking space are given as part of the constructor.
  • \n\t
  • bool addCar(int carType) Checks whether there is a parking space of carType for the car that wants to get into the parking lot. carType can be of three kinds: big, medium, or small, which are represented by 1, 2, and 3 respectively. A car can only park in a parking space of its carType. If there is no space available, return false, else park the car in that size space and return true.
  • \n
\n\n

 

\n

Example 1:

\n\n
\nInput\n["ParkingSystem", "addCar", "addCar", "addCar", "addCar"]\n[[1, 1, 0], [1], [2], [3], [1]]\nOutput\n[null, true, true, false, false]\n\nExplanation\nParkingSystem parkingSystem = new ParkingSystem(1, 1, 0);\nparkingSystem.addCar(1); // return true because there is 1 available slot for a big car\nparkingSystem.addCar(2); // return true because there is 1 available slot for a medium car\nparkingSystem.addCar(3); // return false because there is no available slot for a small car\nparkingSystem.addCar(1); // return false because there is no available slot for a big car. It is already occupied.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 0 <= big, medium, small <= 1000
  • \n\t
  • carType is 1, 2, or 3
  • \n\t
  • At most 1000 calls will be made to addCar
  • \n
\n", "content_cn": "

\u8bf7\u4f60\u7ed9\u4e00\u4e2a\u505c\u8f66\u573a\u8bbe\u8ba1\u4e00\u4e2a\u505c\u8f66\u7cfb\u7edf\u3002\u505c\u8f66\u573a\u603b\u5171\u6709\u4e09\u79cd\u4e0d\u540c\u5927\u5c0f\u7684\u8f66\u4f4d\uff1a\u5927\uff0c\u4e2d\u548c\u5c0f\uff0c\u6bcf\u79cd\u5c3a\u5bf8\u5206\u522b\u6709\u56fa\u5b9a\u6570\u76ee\u7684\u8f66\u4f4d\u3002

\n\n

\u8bf7\u4f60\u5b9e\u73b0\u00a0ParkingSystem\u00a0\u7c7b\uff1a

\n\n
    \n\t
  • ParkingSystem(int big, int medium, int small)\u00a0\u521d\u59cb\u5316\u00a0ParkingSystem\u00a0\u7c7b\uff0c\u4e09\u4e2a\u53c2\u6570\u5206\u522b\u5bf9\u5e94\u6bcf\u79cd\u505c\u8f66\u4f4d\u7684\u6570\u76ee\u3002
  • \n\t
  • bool addCar(int carType)\u00a0\u68c0\u67e5\u662f\u5426\u6709\u00a0carType\u00a0\u5bf9\u5e94\u7684\u505c\u8f66\u4f4d\u3002\u00a0carType\u00a0\u6709\u4e09\u79cd\u7c7b\u578b\uff1a\u5927\uff0c\u4e2d\uff0c\u5c0f\uff0c\u5206\u522b\u7528\u6570\u5b57\u00a01\uff0c\u00a02\u00a0\u548c\u00a03\u00a0\u8868\u793a\u3002\u4e00\u8f86\u8f66\u53ea\u80fd\u505c\u5728\u00a0\u00a0carType\u00a0\u5bf9\u5e94\u5c3a\u5bf8\u7684\u505c\u8f66\u4f4d\u4e2d\u3002\u5982\u679c\u6ca1\u6709\u7a7a\u8f66\u4f4d\uff0c\u8bf7\u8fd4\u56de\u00a0false\u00a0\uff0c\u5426\u5219\u5c06\u8be5\u8f66\u505c\u5165\u8f66\u4f4d\u5e76\u8fd4\u56de\u00a0true\u00a0\u3002
  • \n
\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1a\n[\"ParkingSystem\", \"addCar\", \"addCar\", \"addCar\", \"addCar\"]\n[[1, 1, 0], [1], [2], [3], [1]]\n\u8f93\u51fa\uff1a\n[null, true, true, false, false]\n\n\u89e3\u91ca\uff1a\nParkingSystem parkingSystem = new ParkingSystem(1, 1, 0);\nparkingSystem.addCar(1); // \u8fd4\u56de true \uff0c\u56e0\u4e3a\u6709 1 \u4e2a\u7a7a\u7684\u5927\u8f66\u4f4d\nparkingSystem.addCar(2); // \u8fd4\u56de true \uff0c\u56e0\u4e3a\u6709 1 \u4e2a\u7a7a\u7684\u4e2d\u8f66\u4f4d\nparkingSystem.addCar(3); // \u8fd4\u56de false \uff0c\u56e0\u4e3a\u6ca1\u6709\u7a7a\u7684\u5c0f\u8f66\u4f4d\nparkingSystem.addCar(1); // \u8fd4\u56de false \uff0c\u56e0\u4e3a\u6ca1\u6709\u7a7a\u7684\u5927\u8f66\u4f4d\uff0c\u552f\u4e00\u4e00\u4e2a\u5927\u8f66\u4f4d\u5df2\u7ecf\u88ab\u5360\u636e\u4e86\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 0 <= big, medium, small <= 1000
  • \n\t
  • carType\u00a0\u53d6\u503c\u4e3a\u00a01\uff0c\u00a02\u00a0\u6216\u00a03
  • \n\t
  • \u6700\u591a\u4f1a\u8c03\u7528\u00a0addCar\u00a0\u51fd\u6570\u00a01000\u00a0\u6b21
  • \n
\n", "tags_en": ["Design"], "tags_cn": ["\u8bbe\u8ba1"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class ParkingSystem {\npublic:\n ParkingSystem(int big, int medium, int small) {\n\n }\n \n bool addCar(int carType) {\n\n }\n};\n\n/**\n * Your ParkingSystem object will be instantiated and called as such:\n * ParkingSystem* obj = new ParkingSystem(big, medium, small);\n * bool param_1 = obj->addCar(carType);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class ParkingSystem {\n\n public ParkingSystem(int big, int medium, int small) {\n\n }\n \n public boolean addCar(int carType) {\n\n }\n}\n\n/**\n * Your ParkingSystem object will be instantiated and called as such:\n * ParkingSystem obj = new ParkingSystem(big, medium, small);\n * boolean param_1 = obj.addCar(carType);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class ParkingSystem(object):\n\n def __init__(self, big, medium, small):\n \"\"\"\n :type big: int\n :type medium: int\n :type small: int\n \"\"\"\n\n\n def addCar(self, carType):\n \"\"\"\n :type carType: int\n :rtype: bool\n \"\"\"\n\n\n\n# Your ParkingSystem object will be instantiated and called as such:\n# obj = ParkingSystem(big, medium, small)\n# param_1 = obj.addCar(carType)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class ParkingSystem:\n\n def __init__(self, big: int, medium: int, small: int):\n\n\n def addCar(self, carType: int) -> bool:\n\n\n\n# Your ParkingSystem object will be instantiated and called as such:\n# obj = ParkingSystem(big, medium, small)\n# param_1 = obj.addCar(carType)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} ParkingSystem;\n\n\nParkingSystem* parkingSystemCreate(int big, int medium, int small) {\n\n}\n\nbool parkingSystemAddCar(ParkingSystem* obj, int carType) {\n\n}\n\nvoid parkingSystemFree(ParkingSystem* obj) {\n\n}\n\n/**\n * Your ParkingSystem struct will be instantiated and called as such:\n * ParkingSystem* obj = parkingSystemCreate(big, medium, small);\n * bool param_1 = parkingSystemAddCar(obj, carType);\n \n * parkingSystemFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class ParkingSystem {\n\n public ParkingSystem(int big, int medium, int small) {\n\n }\n \n public bool AddCar(int carType) {\n\n }\n}\n\n/**\n * Your ParkingSystem object will be instantiated and called as such:\n * ParkingSystem obj = new ParkingSystem(big, medium, small);\n * bool param_1 = obj.AddCar(carType);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} big\n * @param {number} medium\n * @param {number} small\n */\nvar ParkingSystem = function(big, medium, small) {\n\n};\n\n/** \n * @param {number} carType\n * @return {boolean}\n */\nParkingSystem.prototype.addCar = function(carType) {\n\n};\n\n/**\n * Your ParkingSystem object will be instantiated and called as such:\n * var obj = new ParkingSystem(big, medium, small)\n * var param_1 = obj.addCar(carType)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class ParkingSystem\n\n=begin\n :type big: Integer\n :type medium: Integer\n :type small: Integer\n=end\n def initialize(big, medium, small)\n\n end\n\n\n=begin\n :type car_type: Integer\n :rtype: Boolean\n=end\n def add_car(car_type)\n\n end\n\n\nend\n\n# Your ParkingSystem object will be instantiated and called as such:\n# obj = ParkingSystem.new(big, medium, small)\n# param_1 = obj.add_car(car_type)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass ParkingSystem {\n\n init(_ big: Int, _ medium: Int, _ small: Int) {\n \n }\n \n func addCar(_ carType: Int) -> Bool {\n \n }\n}\n\n/**\n * Your ParkingSystem object will be instantiated and called as such:\n * let obj = ParkingSystem(big, medium, small)\n * let ret_1: Bool = obj.addCar(carType)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type ParkingSystem struct {\n\n}\n\n\nfunc Constructor(big int, medium int, small int) ParkingSystem {\n\n}\n\n\nfunc (this *ParkingSystem) AddCar(carType int) bool {\n\n}\n\n\n/**\n * Your ParkingSystem object will be instantiated and called as such:\n * obj := Constructor(big, medium, small);\n * param_1 := obj.AddCar(carType);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class ParkingSystem(_big: Int, _medium: Int, _small: Int) {\n\n def addCar(carType: Int): Boolean = {\n\n }\n\n}\n\n/**\n * Your ParkingSystem object will be instantiated and called as such:\n * var obj = new ParkingSystem(big, medium, small)\n * var param_1 = obj.addCar(carType)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class ParkingSystem(big: Int, medium: Int, small: Int) {\n\n fun addCar(carType: Int): Boolean {\n\n }\n\n}\n\n/**\n * Your ParkingSystem object will be instantiated and called as such:\n * var obj = ParkingSystem(big, medium, small)\n * var param_1 = obj.addCar(carType)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct ParkingSystem {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl ParkingSystem {\n\n fn new(big: i32, medium: i32, small: i32) -> Self {\n\n }\n \n fn add_car(&self, car_type: i32) -> bool {\n\n }\n}\n\n/**\n * Your ParkingSystem object will be instantiated and called as such:\n * let obj = ParkingSystem::new(big, medium, small);\n * let ret_1: bool = obj.add_car(carType);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class ParkingSystem {\n /**\n * @param Integer $big\n * @param Integer $medium\n * @param Integer $small\n */\n function __construct($big, $medium, $small) {\n\n }\n\n /**\n * @param Integer $carType\n * @return Boolean\n */\n function addCar($carType) {\n\n }\n}\n\n/**\n * Your ParkingSystem object will be instantiated and called as such:\n * $obj = ParkingSystem($big, $medium, $small);\n * $ret_1 = $obj->addCar($carType);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class ParkingSystem {\n constructor(big: number, medium: number, small: number) {\n\n }\n\n addCar(carType: number): boolean {\n\n }\n}\n\n/**\n * Your ParkingSystem object will be instantiated and called as such:\n * var obj = new ParkingSystem(big, medium, small)\n * var param_1 = obj.addCar(carType)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define parking-system%\n (class object%\n (super-new)\n\n ; big : exact-integer?\n\n ; medium : exact-integer?\n\n ; small : exact-integer?\n (init-field\n big\n medium\n small)\n \n ; add-car : exact-integer? -> boolean?\n (define/public (add-car carType)\n\n )))\n\n;; Your parking-system% object will be instantiated and called as such:\n;; (define obj (new parking-system% [big big] [medium medium] [small small]))\n;; (define param_1 (send obj add-car car-type))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1603](https://leetcode-cn.com/problems/design-parking-system)", "[\u8bbe\u8ba1\u505c\u8f66\u7cfb\u7edf](/solution/1600-1699/1603.Design%20Parking%20System/README.md)", "`\u8bbe\u8ba1`", "\u7b80\u5355", ""], "md_table_row_en": ["[1603](https://leetcode.com/problems/design-parking-system)", "[Design Parking System](/solution/1600-1699/1603.Design%20Parking%20System/README_EN.md)", "`Design`", "Easy", ""]}, {"question_id": "1707", "frontend_question_id": "1585", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/check-if-string-is-transformable-with-substring-sort-operations", "url_en": "https://leetcode.com/problems/check-if-string-is-transformable-with-substring-sort-operations", "relative_path_cn": "/solution/1500-1599/1585.Check%20If%20String%20Is%20Transformable%20With%20Substring%20Sort%20Operations/README.md", "relative_path_en": "/solution/1500-1599/1585.Check%20If%20String%20Is%20Transformable%20With%20Substring%20Sort%20Operations/README_EN.md", "title_cn": "\u68c0\u67e5\u5b57\u7b26\u4e32\u662f\u5426\u53ef\u4ee5\u901a\u8fc7\u6392\u5e8f\u5b50\u5b57\u7b26\u4e32\u5f97\u5230\u53e6\u4e00\u4e2a\u5b57\u7b26\u4e32", "title_en": "Check If String Is Transformable With Substring Sort Operations", "question_title_slug": "check-if-string-is-transformable-with-substring-sort-operations", "content_en": "

Given two strings s and t, you want to transform string s into string t using the following operation any number of times:

\n\n
    \n\t
  • Choose a non-empty substring in s and sort it in-place so the characters are in ascending order.
  • \n
\n\n

For example, applying the operation on the underlined substring in "14234" results in "12344".

\n\n

Return true if it is possible to transform string s into string t. Otherwise, return false.

\n\n

A substring is a contiguous sequence of characters within a string.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "84532", t = "34852"\nOutput: true\nExplanation: You can transform s into t using the following sort operations:\n"84532" (from index 2 to 3) -> "84352"\n"84352" (from index 0 to 2) -> "34852"\n
\n\n

Example 2:

\n\n
\nInput: s = "34521", t = "23415"\nOutput: true\nExplanation: You can transform s into t using the following sort operations:\n"34521" -> "23451"\n"23451" -> "23415"\n
\n\n

Example 3:

\n\n
\nInput: s = "12345", t = "12435"\nOutput: false\n
\n\n

Example 4:

\n\n
\nInput: s = "1", t = "2"\nOutput: false\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • s.length == t.length
  • \n\t
  • 1 <= s.length <= 105
  • \n\t
  • s and t only contain digits from '0' to '9'.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e24\u4e2a\u5b57\u7b26\u4e32 s \u548c t \uff0c\u8bf7\u4f60\u901a\u8fc7\u82e5\u5e72\u6b21\u4ee5\u4e0b\u64cd\u4f5c\u5c06\u5b57\u7b26\u4e32 s \u8f6c\u5316\u6210\u5b57\u7b26\u4e32 t \uff1a

\n\n
    \n\t
  • \u9009\u62e9 s \u4e2d\u4e00\u4e2a \u975e\u7a7a \u5b50\u5b57\u7b26\u4e32\u5e76\u5c06\u5b83\u5305\u542b\u7684\u5b57\u7b26\u5c31\u5730 \u5347\u5e8f \u6392\u5e8f\u3002
  • \n
\n\n

\u6bd4\u65b9\u8bf4\uff0c\u5bf9\u4e0b\u5212\u7ebf\u6240\u793a\u7684\u5b50\u5b57\u7b26\u4e32\u8fdb\u884c\u64cd\u4f5c\u53ef\u4ee5\u7531 "14234" \u5f97\u5230 "12344" \u3002

\n\n

\u5982\u679c\u53ef\u4ee5\u5c06\u5b57\u7b26\u4e32 s \u53d8\u6210 t \uff0c\u8fd4\u56de true \u3002\u5426\u5219\uff0c\u8fd4\u56de false \u3002

\n\n

\u4e00\u4e2a \u5b50\u5b57\u7b26\u4e32 \u5b9a\u4e49\u4e3a\u4e00\u4e2a\u5b57\u7b26\u4e32\u4e2d\u8fde\u7eed\u7684\u82e5\u5e72\u5b57\u7b26\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1as = "84532", t = "34852"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u6309\u4ee5\u4e0b\u64cd\u4f5c\u5c06 s \u8f6c\u53d8\u4e3a t \uff1a\n"84532" \uff08\u4ece\u4e0b\u6807 2 \u5230\u4e0b\u6807 3\uff09-> "84352"\n"84352" \uff08\u4ece\u4e0b\u6807 0 \u5230\u4e0b\u6807 2\uff09 -> "34852"\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1as = "34521", t = "23415"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u6309\u4ee5\u4e0b\u64cd\u4f5c\u5c06 s \u8f6c\u53d8\u4e3a t \uff1a\n"34521" -> "23451"\n"23451" -> "23415"\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1as = "12345", t = "12435"\n\u8f93\u51fa\uff1afalse\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1as = "1", t = "2"\n\u8f93\u51fa\uff1afalse\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • s.length == t.length
  • \n\t
  • 1 <= s.length <= 105
  • \n\t
  • s \u548c t \u90fd\u53ea\u5305\u542b\u6570\u5b57\u5b57\u7b26\uff0c\u5373 '0' \u5230 '9' \u3002
  • \n
\n", "tags_en": ["Greedy", "String"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isTransformable(string s, string t) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isTransformable(String s, String t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isTransformable(self, s, t):\n \"\"\"\n :type s: str\n :type t: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isTransformable(self, s: str, t: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isTransformable(char * s, char * t){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsTransformable(string s, string t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string} t\n * @return {boolean}\n */\nvar isTransformable = function(s, t) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String} t\n# @return {Boolean}\ndef is_transformable(s, t)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isTransformable(_ s: String, _ t: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isTransformable(s string, t string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isTransformable(s: String, t: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isTransformable(s: String, t: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_transformable(s: String, t: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String $t\n * @return Boolean\n */\n function isTransformable($s, $t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isTransformable(s: string, t: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-transformable s t)\n (-> string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1585](https://leetcode-cn.com/problems/check-if-string-is-transformable-with-substring-sort-operations)", "[\u68c0\u67e5\u5b57\u7b26\u4e32\u662f\u5426\u53ef\u4ee5\u901a\u8fc7\u6392\u5e8f\u5b50\u5b57\u7b26\u4e32\u5f97\u5230\u53e6\u4e00\u4e2a\u5b57\u7b26\u4e32](/solution/1500-1599/1585.Check%20If%20String%20Is%20Transformable%20With%20Substring%20Sort%20Operations/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u5b57\u7b26\u4e32`", "\u56f0\u96be", ""], "md_table_row_en": ["[1585](https://leetcode.com/problems/check-if-string-is-transformable-with-substring-sort-operations)", "[Check If String Is Transformable With Substring Sort Operations](/solution/1500-1599/1585.Check%20If%20String%20Is%20Transformable%20With%20Substring%20Sort%20Operations/README_EN.md)", "`Greedy`,`String`", "Hard", ""]}, {"question_id": "1706", "frontend_question_id": "1584", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/min-cost-to-connect-all-points", "url_en": "https://leetcode.com/problems/min-cost-to-connect-all-points", "relative_path_cn": "/solution/1500-1599/1584.Min%20Cost%20to%20Connect%20All%20Points/README.md", "relative_path_en": "/solution/1500-1599/1584.Min%20Cost%20to%20Connect%20All%20Points/README_EN.md", "title_cn": "\u8fde\u63a5\u6240\u6709\u70b9\u7684\u6700\u5c0f\u8d39\u7528", "title_en": "Min Cost to Connect All Points", "question_title_slug": "min-cost-to-connect-all-points", "content_en": "

You are given an array points representing integer coordinates of some points on a 2D-plane, where points[i] = [xi, yi].

\n\n

The cost of connecting two points [xi, yi] and [xj, yj] is the manhattan distance between them: |xi - xj| + |yi - yj|, where |val| denotes the absolute value of val.

\n\n

Return the minimum cost to make all points connected. All points are connected if there is exactly one simple path between any two points.

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: points = [[0,0],[2,2],[3,10],[5,2],[7,0]]\nOutput: 20\nExplanation:\n\"\"\nWe can connect the points as shown above to get the minimum cost of 20.\nNotice that there is a unique path between every pair of points.\n
\n\n

Example 2:

\n\n
\nInput: points = [[3,12],[-2,5],[-4,1]]\nOutput: 18\n
\n\n

Example 3:

\n\n
\nInput: points = [[0,0],[1,1],[1,0],[-1,1]]\nOutput: 4\n
\n\n

Example 4:

\n\n
\nInput: points = [[-1000000,-1000000],[1000000,1000000]]\nOutput: 4000000\n
\n\n

Example 5:

\n\n
\nInput: points = [[0,0]]\nOutput: 0\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= points.length <= 1000
  • \n\t
  • -106 <= xi, yi <= 106
  • \n\t
  • All pairs (xi, yi) are distinct.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2apoints \u6570\u7ec4\uff0c\u8868\u793a 2D \u5e73\u9762\u4e0a\u7684\u4e00\u4e9b\u70b9\uff0c\u5176\u4e2d points[i] = [xi, yi] \u3002

\n\n

\u8fde\u63a5\u70b9 [xi, yi] \u548c\u70b9 [xj, yj] \u7684\u8d39\u7528\u4e3a\u5b83\u4eec\u4e4b\u95f4\u7684 \u66fc\u54c8\u987f\u8ddd\u79bb \uff1a|xi - xj| + |yi - yj| \uff0c\u5176\u4e2d |val| \u8868\u793a val \u7684\u7edd\u5bf9\u503c\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u5c06\u6240\u6709\u70b9\u8fde\u63a5\u7684\u6700\u5c0f\u603b\u8d39\u7528\u3002\u53ea\u6709\u4efb\u610f\u4e24\u70b9\u4e4b\u95f4 \u6709\u4e14\u4ec5\u6709 \u4e00\u6761\u7b80\u5355\u8def\u5f84\u65f6\uff0c\u624d\u8ba4\u4e3a\u6240\u6709\u70b9\u90fd\u5df2\u8fde\u63a5\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1apoints = [[0,0],[2,2],[3,10],[5,2],[7,0]]\n\u8f93\u51fa\uff1a20\n\u89e3\u91ca\uff1a\n\"\"\n\u6211\u4eec\u53ef\u4ee5\u6309\u7167\u4e0a\u56fe\u6240\u793a\u8fde\u63a5\u6240\u6709\u70b9\u5f97\u5230\u6700\u5c0f\u603b\u8d39\u7528\uff0c\u603b\u8d39\u7528\u4e3a 20 \u3002\n\u6ce8\u610f\u5230\u4efb\u610f\u4e24\u4e2a\u70b9\u4e4b\u95f4\u53ea\u6709\u552f\u4e00\u4e00\u6761\u8def\u5f84\u4e92\u76f8\u5230\u8fbe\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1apoints = [[3,12],[-2,5],[-4,1]]\n\u8f93\u51fa\uff1a18\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1apoints = [[0,0],[1,1],[1,0],[-1,1]]\n\u8f93\u51fa\uff1a4\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1apoints = [[-1000000,-1000000],[1000000,1000000]]\n\u8f93\u51fa\uff1a4000000\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\n\u8f93\u5165\uff1apoints = [[0,0]]\n\u8f93\u51fa\uff1a0\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= points.length <= 1000
  • \n\t
  • -106 <= xi, yi <= 106
  • \n\t
  • \u6240\u6709\u70b9 (xi, yi) \u4e24\u4e24\u4e0d\u540c\u3002
  • \n
\n", "tags_en": ["Union Find"], "tags_cn": ["\u5e76\u67e5\u96c6"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minCostConnectPoints(vector>& points) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minCostConnectPoints(int[][] points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minCostConnectPoints(self, points):\n \"\"\"\n :type points: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minCostConnectPoints(self, points: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minCostConnectPoints(int** points, int pointsSize, int* pointsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinCostConnectPoints(int[][] points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} points\n * @return {number}\n */\nvar minCostConnectPoints = function(points) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} points\n# @return {Integer}\ndef min_cost_connect_points(points)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minCostConnectPoints(_ points: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minCostConnectPoints(points [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minCostConnectPoints(points: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minCostConnectPoints(points: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_cost_connect_points(points: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $points\n * @return Integer\n */\n function minCostConnectPoints($points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minCostConnectPoints(points: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-cost-connect-points points)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1584](https://leetcode-cn.com/problems/min-cost-to-connect-all-points)", "[\u8fde\u63a5\u6240\u6709\u70b9\u7684\u6700\u5c0f\u8d39\u7528](/solution/1500-1599/1584.Min%20Cost%20to%20Connect%20All%20Points/README.md)", "`\u5e76\u67e5\u96c6`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1584](https://leetcode.com/problems/min-cost-to-connect-all-points)", "[Min Cost to Connect All Points](/solution/1500-1599/1584.Min%20Cost%20to%20Connect%20All%20Points/README_EN.md)", "`Union Find`", "Medium", ""]}, {"question_id": "1705", "frontend_question_id": "1583", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-unhappy-friends", "url_en": "https://leetcode.com/problems/count-unhappy-friends", "relative_path_cn": "/solution/1500-1599/1583.Count%20Unhappy%20Friends/README.md", "relative_path_en": "/solution/1500-1599/1583.Count%20Unhappy%20Friends/README_EN.md", "title_cn": "\u7edf\u8ba1\u4e0d\u5f00\u5fc3\u7684\u670b\u53cb", "title_en": "Count Unhappy Friends", "question_title_slug": "count-unhappy-friends", "content_en": "

You are given a list of preferences for n friends, where n is always even.

\n\n

For each person ipreferences[i] contains a list of friends sorted in the order of preference. In other words, a friend earlier in the list is more preferred than a friend later in the list. Friends in each list are denoted by integers from 0 to n-1.

\n\n

All the friends are divided into pairs. The pairings are given in a list pairs, where pairs[i] = [xi, yi] denotes xi is paired with yi and yi is paired with xi.

\n\n

However, this pairing may cause some of the friends to be unhappy. A friend x is unhappy if x is paired with y and there exists a friend u who is paired with v but:

\n\n
    \n\t
  • x prefers u over y, and
  • \n\t
  • u prefers x over v.
  • \n
\n\n

Return the number of unhappy friends.

\n\n

 

\n

Example 1:

\n\n
\nInput: n = 4, preferences = [[1, 2, 3], [3, 2, 0], [3, 1, 0], [1, 2, 0]], pairs = [[0, 1], [2, 3]]\nOutput: 2\nExplanation:\nFriend 1 is unhappy because:\n- 1 is paired with 0 but prefers 3 over 0, and\n- 3 prefers 1 over 2.\nFriend 3 is unhappy because:\n- 3 is paired with 2 but prefers 1 over 2, and\n- 1 prefers 3 over 0.\nFriends 0 and 2 are happy.\n
\n\n

Example 2:

\n\n
\nInput: n = 2, preferences = [[1], [0]], pairs = [[1, 0]]\nOutput: 0\nExplanation: Both friends 0 and 1 are happy.\n
\n\n

Example 3:

\n\n
\nInput: n = 4, preferences = [[1, 3, 2], [2, 3, 0], [1, 3, 0], [0, 2, 1]], pairs = [[1, 3], [0, 2]]\nOutput: 4\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= n <= 500
  • \n\t
  • n is even.
  • \n\t
  • preferences.length == n
  • \n\t
  • preferences[i].length == n - 1
  • \n\t
  • 0 <= preferences[i][j] <= n - 1
  • \n\t
  • preferences[i] does not contain i.
  • \n\t
  • All values in preferences[i] are unique.
  • \n\t
  • pairs.length == n/2
  • \n\t
  • pairs[i].length == 2
  • \n\t
  • xi != yi
  • \n\t
  • 0 <= xi, yi <= n - 1
  • \n\t
  • Each person is contained in exactly one pair.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4efd n \u4f4d\u670b\u53cb\u7684\u4eb2\u8fd1\u7a0b\u5ea6\u5217\u8868\uff0c\u5176\u4e2d n \u603b\u662f \u5076\u6570 \u3002

\n\n

\u5bf9\u6bcf\u4f4d\u670b\u53cb i\uff0cpreferences[i] \u5305\u542b\u4e00\u4efd \u6309\u4eb2\u8fd1\u7a0b\u5ea6\u4ece\u9ad8\u5230\u4f4e\u6392\u5217 \u7684\u670b\u53cb\u5217\u8868\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u6392\u5728\u5217\u8868\u524d\u9762\u7684\u670b\u53cb\u4e0e i \u7684\u4eb2\u8fd1\u7a0b\u5ea6\u6bd4\u6392\u5728\u5217\u8868\u540e\u9762\u7684\u670b\u53cb\u66f4\u9ad8\u3002\u6bcf\u4e2a\u5217\u8868\u4e2d\u7684\u670b\u53cb\u5747\u4ee5 0 \u5230 n-1 \u4e4b\u95f4\u7684\u6574\u6570\u8868\u793a\u3002

\n\n

\u6240\u6709\u7684\u670b\u53cb\u88ab\u5206\u6210\u51e0\u5bf9\uff0c\u914d\u5bf9\u60c5\u51b5\u4ee5\u5217\u8868 pairs \u7ed9\u51fa\uff0c\u5176\u4e2d pairs[i] = [xi, yi] \u8868\u793a xi \u4e0e yi \u914d\u5bf9\uff0c\u4e14 yi \u4e0e xi \u914d\u5bf9\u3002

\n\n

\u4f46\u662f\uff0c\u8fd9\u6837\u7684\u914d\u5bf9\u60c5\u51b5\u53ef\u80fd\u4f1a\u662f\u5176\u4e2d\u90e8\u5206\u670b\u53cb\u611f\u5230\u4e0d\u5f00\u5fc3\u3002\u5728 x \u4e0e y \u914d\u5bf9\u4e14 u \u4e0e v \u914d\u5bf9\u7684\u60c5\u51b5\u4e0b\uff0c\u5982\u679c\u540c\u65f6\u6ee1\u8db3\u4e0b\u8ff0\u4e24\u4e2a\u6761\u4ef6\uff0cx \u5c31\u4f1a\u4e0d\u5f00\u5fc3\uff1a

\n\n
    \n\t
  • x \u4e0e u \u7684\u4eb2\u8fd1\u7a0b\u5ea6\u80dc\u8fc7 x \u4e0e y\uff0c\u4e14
  • \n\t
  • u \u4e0e x \u7684\u4eb2\u8fd1\u7a0b\u5ea6\u80dc\u8fc7 u \u4e0e v
  • \n
\n\n

\u8fd4\u56de \u4e0d\u5f00\u5fc3\u7684\u670b\u53cb\u7684\u6570\u76ee \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1an = 4, preferences = [[1, 2, 3], [3, 2, 0], [3, 1, 0], [1, 2, 0]], pairs = [[0, 1], [2, 3]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n\u670b\u53cb 1 \u4e0d\u5f00\u5fc3\uff0c\u56e0\u4e3a\uff1a\n- 1 \u4e0e 0 \u914d\u5bf9\uff0c\u4f46 1 \u4e0e 3 \u7684\u4eb2\u8fd1\u7a0b\u5ea6\u6bd4 1 \u4e0e 0 \u9ad8\uff0c\u4e14\n- 3 \u4e0e 1 \u7684\u4eb2\u8fd1\u7a0b\u5ea6\u6bd4 3 \u4e0e 2 \u9ad8\u3002\n\u670b\u53cb 3 \u4e0d\u5f00\u5fc3\uff0c\u56e0\u4e3a\uff1a\n- 3 \u4e0e 2 \u914d\u5bf9\uff0c\u4f46 3 \u4e0e 1 \u7684\u4eb2\u8fd1\u7a0b\u5ea6\u6bd4 3 \u4e0e 2 \u9ad8\uff0c\u4e14\n- 1 \u4e0e 3 \u7684\u4eb2\u8fd1\u7a0b\u5ea6\u6bd4 1 \u4e0e 0 \u9ad8\u3002\n\u670b\u53cb 0 \u548c 2 \u90fd\u662f\u5f00\u5fc3\u7684\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1an = 2, preferences = [[1], [0]], pairs = [[1, 0]]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u670b\u53cb 0 \u548c 1 \u90fd\u5f00\u5fc3\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1an = 4, preferences = [[1, 3, 2], [2, 3, 0], [1, 3, 0], [0, 2, 1]], pairs = [[1, 3], [0, 2]]\n\u8f93\u51fa\uff1a4\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= n <= 500
  • \n\t
  • n \u662f\u5076\u6570
  • \n\t
  • preferences.length == n
  • \n\t
  • preferences[i].length == n - 1
  • \n\t
  • 0 <= preferences[i][j] <= n - 1
  • \n\t
  • preferences[i] \u4e0d\u5305\u542b i
  • \n\t
  • preferences[i] \u4e2d\u7684\u6240\u6709\u503c\u90fd\u662f\u72ec\u4e00\u65e0\u4e8c\u7684
  • \n\t
  • pairs.length == n/2
  • \n\t
  • pairs[i].length == 2
  • \n\t
  • xi != yi
  • \n\t
  • 0 <= xi, yi <= n - 1
  • \n\t
  • \u6bcf\u4f4d\u670b\u53cb\u90fd \u6070\u597d \u88ab\u5305\u542b\u5728\u4e00\u5bf9\u4e2d
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int unhappyFriends(int n, vector>& preferences, vector>& pairs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int unhappyFriends(int n, int[][] preferences, int[][] pairs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def unhappyFriends(self, n, preferences, pairs):\n \"\"\"\n :type n: int\n :type preferences: List[List[int]]\n :type pairs: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def unhappyFriends(self, n: int, preferences: List[List[int]], pairs: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint unhappyFriends(int n, int** preferences, int preferencesSize, int* preferencesColSize, int** pairs, int pairsSize, int* pairsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int UnhappyFriends(int n, int[][] preferences, int[][] pairs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} preferences\n * @param {number[][]} pairs\n * @return {number}\n */\nvar unhappyFriends = function(n, preferences, pairs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} preferences\n# @param {Integer[][]} pairs\n# @return {Integer}\ndef unhappy_friends(n, preferences, pairs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func unhappyFriends(_ n: Int, _ preferences: [[Int]], _ pairs: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func unhappyFriends(n int, preferences [][]int, pairs [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def unhappyFriends(n: Int, preferences: Array[Array[Int]], pairs: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun unhappyFriends(n: Int, preferences: Array, pairs: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn unhappy_friends(n: i32, preferences: Vec>, pairs: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $preferences\n * @param Integer[][] $pairs\n * @return Integer\n */\n function unhappyFriends($n, $preferences, $pairs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function unhappyFriends(n: number, preferences: number[][], pairs: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (unhappy-friends n preferences pairs)\n (-> exact-integer? (listof (listof exact-integer?)) (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1583](https://leetcode-cn.com/problems/count-unhappy-friends)", "[\u7edf\u8ba1\u4e0d\u5f00\u5fc3\u7684\u670b\u53cb](/solution/1500-1599/1583.Count%20Unhappy%20Friends/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1583](https://leetcode.com/problems/count-unhappy-friends)", "[Count Unhappy Friends](/solution/1500-1599/1583.Count%20Unhappy%20Friends/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "1704", "frontend_question_id": "1582", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/special-positions-in-a-binary-matrix", "url_en": "https://leetcode.com/problems/special-positions-in-a-binary-matrix", "relative_path_cn": "/solution/1500-1599/1582.Special%20Positions%20in%20a%20Binary%20Matrix/README.md", "relative_path_en": "/solution/1500-1599/1582.Special%20Positions%20in%20a%20Binary%20Matrix/README_EN.md", "title_cn": "\u4e8c\u8fdb\u5236\u77e9\u9635\u4e2d\u7684\u7279\u6b8a\u4f4d\u7f6e", "title_en": "Special Positions in a Binary Matrix", "question_title_slug": "special-positions-in-a-binary-matrix", "content_en": "

Given a rows x cols matrix mat, where mat[i][j] is either 0 or 1, return the number of special positions in mat.

\n\n

A position (i,j) is called special if mat[i][j] == 1 and all other elements in row i and column j are 0 (rows and columns are 0-indexed).

\n\n

 

\n

Example 1:

\n\n
\nInput: mat = [[1,0,0],\n              [0,0,1],\n              [1,0,0]]\nOutput: 1\nExplanation: (1,2) is a special position because mat[1][2] == 1 and all other elements in row 1 and column 2 are 0.\n
\n\n

Example 2:

\n\n
\nInput: mat = [[1,0,0],\n              [0,1,0],\n              [0,0,1]]\nOutput: 3\nExplanation: (0,0), (1,1) and (2,2) are special positions. \n
\n\n

Example 3:

\n\n
\nInput: mat = [[0,0,0,1],\n              [1,0,0,0],\n              [0,1,1,0],\n              [0,0,0,0]]\nOutput: 2\n
\n\n

Example 4:

\n\n
\nInput: mat = [[0,0,0,0,0],\n              [1,0,0,0,0],\n              [0,1,0,0,0],\n              [0,0,1,0,0],\n              [0,0,0,1,1]]\nOutput: 3\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • rows == mat.length
  • \n\t
  • cols == mat[i].length
  • \n\t
  • 1 <= rows, cols <= 100
  • \n\t
  • mat[i][j] is 0 or 1.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5927\u5c0f\u4e3a rows x cols \u7684\u77e9\u9635 mat\uff0c\u5176\u4e2d mat[i][j] \u662f 0 \u6216 1\uff0c\u8bf7\u8fd4\u56de \u77e9\u9635 mat \u4e2d\u7279\u6b8a\u4f4d\u7f6e\u7684\u6570\u76ee \u3002

\n\n

\u7279\u6b8a\u4f4d\u7f6e \u5b9a\u4e49\uff1a\u5982\u679c mat[i][j] == 1 \u5e76\u4e14\u7b2c i \u884c\u548c\u7b2c j \u5217\u4e2d\u7684\u6240\u6709\u5176\u4ed6\u5143\u7d20\u5747\u4e3a 0\uff08\u884c\u548c\u5217\u7684\u4e0b\u6807\u5747 \u4ece 0 \u5f00\u59cb \uff09\uff0c\u5219\u4f4d\u7f6e (i, j) \u88ab\u79f0\u4e3a\u7279\u6b8a\u4f4d\u7f6e\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1amat = [[1,0,0],\n            [0,0,1],\n            [1,0,0]]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a(1,2) \u662f\u4e00\u4e2a\u7279\u6b8a\u4f4d\u7f6e\uff0c\u56e0\u4e3a mat[1][2] == 1 \u4e14\u6240\u5904\u7684\u884c\u548c\u5217\u4e0a\u6240\u6709\u5176\u4ed6\u5143\u7d20\u90fd\u662f 0\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1amat = [[1,0,0],\n            [0,1,0],\n            [0,0,1]]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a(0,0), (1,1) \u548c (2,2) \u90fd\u662f\u7279\u6b8a\u4f4d\u7f6e\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1amat = [[0,0,0,1],\n            [1,0,0,0],\n            [0,1,1,0],\n            [0,0,0,0]]\n\u8f93\u51fa\uff1a2\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1amat = [[0,0,0,0,0],\n            [1,0,0,0,0],\n            [0,1,0,0,0],\n            [0,0,1,0,0],\n            [0,0,0,1,1]]\n\u8f93\u51fa\uff1a3\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • rows == mat.length
  • \n\t
  • cols == mat[i].length
  • \n\t
  • 1 <= rows, cols <= 100
  • \n\t
  • mat[i][j] \u662f 0 \u6216 1
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numSpecial(vector>& mat) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numSpecial(int[][] mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numSpecial(self, mat):\n \"\"\"\n :type mat: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numSpecial(self, mat: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numSpecial(int** mat, int matSize, int* matColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumSpecial(int[][] mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} mat\n * @return {number}\n */\nvar numSpecial = function(mat) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} mat\n# @return {Integer}\ndef num_special(mat)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numSpecial(_ mat: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numSpecial(mat [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numSpecial(mat: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numSpecial(mat: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_special(mat: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $mat\n * @return Integer\n */\n function numSpecial($mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numSpecial(mat: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-special mat)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1582](https://leetcode-cn.com/problems/special-positions-in-a-binary-matrix)", "[\u4e8c\u8fdb\u5236\u77e9\u9635\u4e2d\u7684\u7279\u6b8a\u4f4d\u7f6e](/solution/1500-1599/1582.Special%20Positions%20in%20a%20Binary%20Matrix/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1582](https://leetcode.com/problems/special-positions-in-a-binary-matrix)", "[Special Positions in a Binary Matrix](/solution/1500-1599/1582.Special%20Positions%20in%20a%20Binary%20Matrix/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1703", "frontend_question_id": "1564", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/put-boxes-into-the-warehouse-i", "url_en": "https://leetcode.com/problems/put-boxes-into-the-warehouse-i", "relative_path_cn": "/solution/1500-1599/1564.Put%20Boxes%20Into%20the%20Warehouse%20I/README.md", "relative_path_en": "/solution/1500-1599/1564.Put%20Boxes%20Into%20the%20Warehouse%20I/README_EN.md", "title_cn": "\u628a\u7bb1\u5b50\u653e\u8fdb\u4ed3\u5e93\u91cc I", "title_en": "Put Boxes Into the Warehouse I", "question_title_slug": "put-boxes-into-the-warehouse-i", "content_en": "

You are given two arrays of positive integers, boxes and warehouse, representing the heights of some boxes of unit width and the heights of n rooms in a warehouse respectively. The warehouse's rooms are labelled from 0 to n - 1 from left to right where warehouse[i] (0-indexed) is the height of the ith room.

\n\n

Boxes are put into the warehouse by the following rules:

\n\n
    \n\t
  • Boxes cannot be stacked.
  • \n\t
  • You can rearrange the insertion order of the boxes.
  • \n\t
  • Boxes can only be pushed into the warehouse from left to right only.
  • \n\t
  • If the height of some room in the warehouse is less than the height of a box, then that box and all other boxes behind it will be stopped before that room.
  • \n
\n\n

Return the maximum number of boxes you can put into the warehouse.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: boxes = [4,3,4,1], warehouse = [5,3,3,4,1]\nOutput: 3\nExplanation: \n\"\"\nWe can first put the box of height 1 in room 4. Then we can put the box of height 3 in either of the 3 rooms 1, 2, or 3. Lastly, we can put one box of height 4 in room 0.\nThere is no way we can fit all 4 boxes in the warehouse.
\n\n

Example 2:

\n\"\"\n
\nInput: boxes = [1,2,2,3,4], warehouse = [3,4,1,2]\nOutput: 3\nExplanation: \n\"\"\nNotice that it's not possible to put the box of height 4 into the warehouse since it cannot pass the first room of height 3.\nAlso, for the last two rooms, 2 and 3, only boxes of height 1 can fit.\nWe can fit 3 boxes maximum as shown above. The yellow box can also be put in room 2 instead.\nSwapping the orange and green boxes is also valid, or swapping one of them with the red box.
\n\n

Example 3:

\n\n
\nInput: boxes = [1,2,3], warehouse = [1,2,3,4]\nOutput: 1\nExplanation: Since the first room in the warehouse is of height 1, we can only put boxes of height 1.\n
\n\n

Example 4:

\n\n
\nInput: boxes = [4,5,6], warehouse = [3,3,3,3,3]\nOutput: 0\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == warehouse.length
  • \n\t
  • 1 <= boxes.length, warehouse.length <= 10^5
  • \n\t
  • 1 <= boxes[i], warehouse[i] <= 10^9
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e24\u4e2a\u6b63\u6574\u6570\u6570\u7ec4\u00a0boxes\u00a0\u548c\u00a0warehouse\u00a0\uff0c\u5206\u522b\u5305\u542b\u5355\u4f4d\u5bbd\u5ea6\u7684\u7bb1\u5b50\u7684\u9ad8\u5ea6\uff0c\u4ee5\u53ca\u4ed3\u5e93\u4e2d n \u4e2a\u623f\u95f4\u5404\u81ea\u7684\u9ad8\u5ea6\u3002\u4ed3\u5e93\u7684\u623f\u95f4\u5206\u522b\u4ece\u00a00\u00a0\u5230\u00a0n - 1\u00a0\u81ea\u5de6\u5411\u53f3\u7f16\u53f7\uff0c\u00a0warehouse[i]\u00a0\uff08\u7d22\u5f15\u4ece 0 \u5f00\u59cb\uff09\u662f\u7b2c\u00a0i\u00a0\u4e2a\u623f\u95f4\u7684\u9ad8\u5ea6\u3002

\n\n

\u7bb1\u5b50\u653e\u8fdb\u4ed3\u5e93\u65f6\u9075\u5faa\u4e0b\u5217\u89c4\u5219\uff1a

\n\n
    \n\t
  • \u7bb1\u5b50\u4e0d\u53ef\u53e0\u653e\u3002
  • \n\t
  • \u4f60\u53ef\u4ee5\u91cd\u65b0\u8c03\u6574\u7bb1\u5b50\u7684\u987a\u5e8f\u3002
  • \n\t
  • \u7bb1\u5b50\u53ea\u80fd\u4ece\u5de6\u5411\u53f3\u63a8\u8fdb\u4ed3\u5e93\u4e2d\u3002
  • \n\t
  • \u5982\u679c\u4ed3\u5e93\u4e2d\u67d0\u623f\u95f4\u7684\u9ad8\u5ea6\u5c0f\u4e8e\u67d0\u7bb1\u5b50\u7684\u9ad8\u5ea6\uff0c\u5219\u8fd9\u4e2a\u7bb1\u5b50\u548c\u4e4b\u540e\u7684\u7bb1\u5b50\u90fd\u4f1a\u505c\u5728\u8fd9\u4e2a\u623f\u95f4\u7684\u524d\u9762\u3002
  • \n
\n\n

\u4f60\u6700\u591a\u53ef\u4ee5\u5728\u4ed3\u5e93\u4e2d\u653e\u8fdb\u591a\u5c11\u4e2a\u7bb1\u5b50\uff1f

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1aboxes = [4,3,4,1], warehouse = [5,3,3,4,1]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\n\"\"\n\u6211\u4eec\u53ef\u4ee5\u5148\u628a\u9ad8\u5ea6\u4e3a 1 \u7684\u7bb1\u5b50\u653e\u5165 4 \u53f7\u623f\u95f4\uff0c\u7136\u540e\u518d\u628a\u9ad8\u5ea6\u4e3a 3 \u7684\u7bb1\u5b50\u653e\u5165 1 \u53f7\u3001 2 \u53f7\u6216 3 \u53f7\u623f\u95f4\uff0c\u6700\u540e\u518d\u628a\u9ad8\u5ea6\u4e3a 4 \u7684\u7bb1\u5b50\u653e\u5165 0 \u53f7\u623f\u95f4\u3002\n\u6211\u4eec\u4e0d\u53ef\u80fd\u628a\u6240\u6709 4 \u4e2a\u7bb1\u5b50\u5168\u90e8\u653e\u8fdb\u4ed3\u5e93\u91cc\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1aboxes = [1,2,2,3,4], warehouse = [3,4,1,2]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\n\"\"\n\u6211\u4eec\u6ce8\u610f\u5230\uff0c\u4e0d\u53ef\u80fd\u628a\u9ad8\u5ea6\u4e3a 4 \u7684\u7bb1\u5b50\u653e\u5165\u4ed3\u5e93\u4e2d\uff0c\u56e0\u4e3a\u5b83\u4e0d\u80fd\u901a\u8fc7\u9ad8\u5ea6\u4e3a 3 \u7684\u623f\u95f4\u3002\n\u800c\u4e14\uff0c\u5bf9\u4e8e\u6700\u540e\u4e24\u4e2a\u623f\u95f4 2 \u53f7\u548c 3 \u53f7\u6765\u8bf4\uff0c\u53ea\u6709\u9ad8\u5ea6\u4e3a 1 \u7684\u7bb1\u5b50\u53ef\u4ee5\u653e\u8fdb\u53bb\u3002\n\u6211\u4eec\u6700\u591a\u53ef\u4ee5\u653e\u8fdb 3 \u4e2a\u7bb1\u5b50\uff0c\u5982\u4e0a\u56fe\u6240\u793a\u3002\u9ec4\u8272\u7684\u7bb1\u5b50\u4e5f\u53ef\u4ee5\u653e\u5165 2 \u53f7\u623f\u95f4\u3002\n\u4ea4\u6362\u6a59\u8272\u548c\u7eff\u8272\u7bb1\u5b50\u7684\u4f4d\u7f6e\uff0c\u6216\u662f\u5c06\u8fd9\u4e24\u4e2a\u7bb1\u5b50\u4e0e\u7ea2\u8272\u7bb1\u5b50\u4ea4\u6362\u4f4d\u7f6e\uff0c\u4e5f\u662f\u53ef\u4ee5\u7684\u3002
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1aboxes = [1,2,3], warehouse = [1,2,3,4]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u7531\u4e8e\u7b2c\u4e00\u4e2a\u623f\u95f4\u7684\u9ad8\u5ea6\u4e3a 1\uff0c\u6211\u4eec\u53ea\u80fd\u653e\u8fdb\u9ad8\u5ea6\u4e3a 1 \u7684\u7bb1\u5b50\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1aboxes = [4,5,6], warehouse = [3,3,3,3,3]\n\u8f93\u51fa\uff1a0\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • n == warehouse.length
  • \n\t
  • 1 <= boxes.length, warehouse.length <= 10^5
  • \n\t
  • 1 <= boxes[i], warehouse[i] <= 10^9
  • \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxBoxesInWarehouse(vector& boxes, vector& warehouse) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxBoxesInWarehouse(int[] boxes, int[] warehouse) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxBoxesInWarehouse(self, boxes, warehouse):\n \"\"\"\n :type boxes: List[int]\n :type warehouse: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxBoxesInWarehouse(self, boxes: List[int], warehouse: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxBoxesInWarehouse(int* boxes, int boxesSize, int* warehouse, int warehouseSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxBoxesInWarehouse(int[] boxes, int[] warehouse) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} boxes\n * @param {number[]} warehouse\n * @return {number}\n */\nvar maxBoxesInWarehouse = function(boxes, warehouse) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} boxes\n# @param {Integer[]} warehouse\n# @return {Integer}\ndef max_boxes_in_warehouse(boxes, warehouse)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxBoxesInWarehouse(_ boxes: [Int], _ warehouse: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxBoxesInWarehouse(boxes []int, warehouse []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxBoxesInWarehouse(boxes: Array[Int], warehouse: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxBoxesInWarehouse(boxes: IntArray, warehouse: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_boxes_in_warehouse(boxes: Vec, warehouse: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $boxes\n * @param Integer[] $warehouse\n * @return Integer\n */\n function maxBoxesInWarehouse($boxes, $warehouse) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxBoxesInWarehouse(boxes: number[], warehouse: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-boxes-in-warehouse boxes warehouse)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1564](https://leetcode-cn.com/problems/put-boxes-into-the-warehouse-i)", "[\u628a\u7bb1\u5b50\u653e\u8fdb\u4ed3\u5e93\u91cc I](/solution/1500-1599/1564.Put%20Boxes%20Into%20the%20Warehouse%20I/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1564](https://leetcode.com/problems/put-boxes-into-the-warehouse-i)", "[Put Boxes Into the Warehouse I](/solution/1500-1599/1564.Put%20Boxes%20Into%20the%20Warehouse%20I/README_EN.md)", "`Greedy`", "Medium", "\ud83d\udd12"]}, {"question_id": "1702", "frontend_question_id": "1555", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/bank-account-summary", "url_en": "https://leetcode.com/problems/bank-account-summary", "relative_path_cn": "/solution/1500-1599/1555.Bank%20Account%20Summary/README.md", "relative_path_en": "/solution/1500-1599/1555.Bank%20Account%20Summary/README_EN.md", "title_cn": "\u94f6\u884c\u8d26\u6237\u6982\u8981", "title_en": "Bank Account Summary", "question_title_slug": "bank-account-summary", "content_en": "

Table: Users

\n\n
\n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| user_id      | int     |\n| user_name    | varchar |\n| credit       | int     |\n+--------------+---------+\nuser_id is the primary key for this table.\nEach row of this table contains the current credit information for each user.\n
\n\n

 

\n\n

Table: Transactions

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| trans_id      | int     |\n| paid_by       | int     |\n| paid_to       | int     |\n| amount        | int     |\n| transacted_on | date    |\n+---------------+---------+\ntrans_id is the primary key for this table.\nEach row of this table contains the information about the transaction in the bank.\nUser with id (paid_by) transfer money to user with id (paid_to).\n
\n\n

 

\n\n

Leetcode Bank (LCB) helps its coders in making virtual payments. Our bank records all transactions in the table Transaction, we want to find out the current balance of all users and check wheter they have breached their credit limit (If their current credit is less than 0).

\n\n

Write an SQL query to report.

\n\n
    \n\t
  • user_id
  • \n\t
  • user_name
  • \n\t
  • credit, current balance after performing transactions.  
  • \n\t
  • credit_limit_breached, check credit_limit ("Yes" or "No")
  • \n
\n\n

Return the result table in any order.

\n\n

The query result format is in the following example.

\n\n

 

\n\n
\nUsers table:\n+------------+--------------+-------------+\n| user_id    | user_name    | credit      |\n+------------+--------------+-------------+\n| 1          | Moustafa     | 100         |\n| 2          | Jonathan     | 200         |\n| 3          | Winston      | 10000       |\n| 4          | Luis         | 800         | \n+------------+--------------+-------------+\n\nTransactions table:\n+------------+------------+------------+----------+---------------+\n| trans_id   | paid_by    | paid_to    | amount   | transacted_on |\n+------------+------------+------------+----------+---------------+\n| 1          | 1          | 3          | 400      | 2020-08-01    |\n| 2          | 3          | 2          | 500      | 2020-08-02    |\n| 3          | 2          | 1          | 200      | 2020-08-03    |\n+------------+------------+------------+----------+---------------+\n\nResult table:\n+------------+------------+------------+-----------------------+\n| user_id    | user_name  | credit     | credit_limit_breached |\n+------------+------------+------------+-----------------------+\n| 1          | Moustafa   | -100       | Yes                   | \n| 2          | Jonathan   | 500        | No                    |\n| 3          | Winston    | 9900       | No                    |\n| 4          | Luis       | 800        | No                    |\n+------------+------------+------------+-----------------------+\nMoustafa paid $400 on "2020-08-01" and received $200 on "2020-08-03", credit (100 -400 +200) = -$100\nJonathan received $500 on "2020-08-02" and paid $200 on "2020-08-08", credit (200 +500 -200) = $500\nWinston received $400 on "2020-08-01" and paid $500 on "2020-08-03", credit (10000 +400 -500) = $9990\nLuis didn't received any transfer, credit = $800
\n", "content_cn": "

\u7528\u6237\u8868\uff1a\u00a0Users

\n\n
\n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| user_id      | int     |\n| user_name    | varchar |\n| credit       | int     |\n+--------------+---------+\nuser_id \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\u3002\n\u8868\u4e2d\u7684\u6bcf\u4e00\u5217\u5305\u542b\u6bcf\u4e00\u4e2a\u7528\u6237\u5f53\u524d\u7684\u989d\u5ea6\u4fe1\u606f\u3002
\n\n

\u00a0

\n\n

\u4ea4\u6613\u8868\uff1aTransactions

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| trans_id      | int     |\n| paid_by       | int     |\n| paid_to       | int     |\n| amount        | int     |\n| transacted_on | date    |\n+---------------+---------+\ntrans_id \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\u3002\n\u8868\u4e2d\u7684\u6bcf\u4e00\u5217\u5305\u542b\u94f6\u884c\u7684\u4ea4\u6613\u4fe1\u606f\u3002\nID \u4e3a paid_by \u7684\u7528\u6237\u7ed9 ID \u4e3a paid_to \u7684\u7528\u6237\u8f6c\u8d26\u3002\n
\n\n

\u00a0

\n\n

\u529b\u6263\u94f6\u884c (LCB) \u5e2e\u52a9\u7a0b\u5e8f\u5458\u4eec\u5b8c\u6210\u865a\u62df\u652f\u4ed8\u3002\u6211\u4eec\u7684\u94f6\u884c\u5728\u8868\u00a0Transaction\u00a0\u4e2d\u8bb0\u5f55\u6bcf\u6761\u4ea4\u6613\u4fe1\u606f\uff0c\u6211\u4eec\u8981\u67e5\u8be2\u6bcf\u4e2a\u7528\u6237\u7684\u5f53\u524d\u4f59\u989d\uff0c\u5e76\u68c0\u67e5\u4ed6\u4eec\u662f\u5426\u5df2\u900f\u652f\uff08\u5f53\u524d\u989d\u5ea6\u5c0f\u4e8e 0\uff09\u3002

\n\n

\u5199\u4e00\u6761 SQL \u8bed\u53e5\uff0c\u67e5\u8be2\uff1a

\n\n
    \n\t
  • user_id\u00a0\u7528\u6237 ID
  • \n\t
  • user_name\u00a0\u7528\u6237\u540d
  • \n\t
  • credit\u00a0\u5b8c\u6210\u4ea4\u6613\u540e\u7684\u4f59\u989d
  • \n\t
  • credit_limit_breached\u00a0\u68c0\u67e5\u662f\u5426\u900f\u652f \uff08\"Yes\" \u6216\u00a0\"No\"\uff09
  • \n
\n\n

\u4ee5\u4efb\u610f\u987a\u5e8f\u8fd4\u56de\u7ed3\u679c\u8868\u3002

\n\n

\u00a0

\n\n

\u67e5\u8be2\u683c\u5f0f\u89c1\u5982\u4e0b\u793a\u4f8b\uff1a

\n\n
\nUsers \u8868\uff1a\n+------------+--------------+-------------+\n| user_id    | user_name    | credit      |\n+------------+--------------+-------------+\n| 1          | Moustafa     | 100         |\n| 2          | Jonathan     | 200         |\n| 3          | Winston      | 10000       |\n| 4          | Luis         | 800         | \n+------------+--------------+-------------+\n\nTransactions \u8868\uff1a\n+------------+------------+------------+----------+---------------+\n| trans_id   | paid_by    | paid_to    | amount   | transacted_on |\n+------------+------------+------------+----------+---------------+\n| 1          | 1          | 3          | 400      | 2020-08-01    |\n| 2          | 3          | 2          | 500      | 2020-08-02    |\n| 3          | 2          | 1          | 200      | 2020-08-03    |\n+------------+------------+------------+----------+---------------+\n\n\u7ed3\u679c\u8868\uff1a\n+------------+------------+------------+-----------------------+\n| user_id    | user_name  | credit     | credit_limit_breached |\n+------------+------------+------------+-----------------------+\n| 1          | Moustafa   | -100       | Yes                   | \n| 2          | Jonathan   | 500        | No                    |\n| 3          | Winston    | 9900       | No                    |\n| 4          | Luis       | 800        | No                    |\n+------------+------------+------------+-----------------------+\nMoustafa \u5728 \"2020-08-01\" \u652f\u4ed8\u4e86 $400 \u5e76\u5728 \"2020-08-03\" \u6536\u5230\u4e86 $200 \uff0c\u5f53\u524d\u989d\u5ea6 (100 -400 +200) = -$100\nJonathan \u5728 \"2020-08-02\" \u6536\u5230\u4e86 $500 \u5e76\u5728 \"2020-08-08\" \u652f\u4ed8\u4e86 $200 \uff0c\u5f53\u524d\u989d\u5ea6 (200 +500 -200) = $500\nWinston \u5728 \"2020-08-01\" \u6536\u5230\u4e86 $400 \u5e76\u5728 \"2020-08-03\" \u652f\u4ed8\u4e86 $500 \uff0c\u5f53\u524d\u989d\u5ea6 (10000 +400 -500) = $9900\nLuis \u672a\u6536\u5230\u4efb\u4f55\u8f6c\u8d26\u4fe1\u606f\uff0c\u989d\u5ea6 = $800
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1555](https://leetcode-cn.com/problems/bank-account-summary)", "[\u94f6\u884c\u8d26\u6237\u6982\u8981](/solution/1500-1599/1555.Bank%20Account%20Summary/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1555](https://leetcode.com/problems/bank-account-summary)", "[Bank Account Summary](/solution/1500-1599/1555.Bank%20Account%20Summary/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1701", "frontend_question_id": "1579", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/remove-max-number-of-edges-to-keep-graph-fully-traversable", "url_en": "https://leetcode.com/problems/remove-max-number-of-edges-to-keep-graph-fully-traversable", "relative_path_cn": "/solution/1500-1599/1579.Remove%20Max%20Number%20of%20Edges%20to%20Keep%20Graph%20Fully%20Traversable/README.md", "relative_path_en": "/solution/1500-1599/1579.Remove%20Max%20Number%20of%20Edges%20to%20Keep%20Graph%20Fully%20Traversable/README_EN.md", "title_cn": "\u4fdd\u8bc1\u56fe\u53ef\u5b8c\u5168\u904d\u5386", "title_en": "Remove Max Number of Edges to Keep Graph Fully Traversable", "question_title_slug": "remove-max-number-of-edges-to-keep-graph-fully-traversable", "content_en": "

Alice and Bob have an undirected graph of n nodes and 3 types of edges:

\n\n
    \n\t
  • Type 1: Can be traversed by Alice only.
  • \n\t
  • Type 2: Can be traversed by Bob only.
  • \n\t
  • Type 3: Can by traversed by both Alice and Bob.
  • \n
\n\n

Given an array edges where edges[i] = [typei, ui, vi] represents a bidirectional edge of type typei between nodes ui and vi, find the maximum number of edges you can remove so that after removing the edges, the graph can still be fully traversed by both Alice and Bob. The graph is fully traversed by Alice and Bob if starting from any node, they can reach all other nodes.

\n\n

Return the maximum number of edges you can remove, or return -1 if it's impossible for the graph to be fully traversed by Alice and Bob.

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: n = 4, edges = [[3,1,2],[3,2,3],[1,1,3],[1,2,4],[1,1,2],[2,3,4]]\nOutput: 2\nExplanation: If we remove the 2 edges [1,1,2] and [1,1,3]. The graph will still be fully traversable by Alice and Bob. Removing any additional edge will not make it so. So the maximum number of edges we can remove is 2.\n
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: n = 4, edges = [[3,1,2],[3,2,3],[1,1,4],[2,1,4]]\nOutput: 0\nExplanation: Notice that removing any edge will not make the graph fully traversable by Alice and Bob.\n
\n\n

Example 3:

\n\n

\"\"

\n\n
\nInput: n = 4, edges = [[3,2,3],[1,1,2],[2,3,4]]\nOutput: -1\nExplanation: In the current graph, Alice cannot reach node 4 from the other nodes. Likewise, Bob cannot reach 1. Therefore it's impossible to make the graph fully traversable.
\n\n

 

\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 10^5
  • \n\t
  • 1 <= edges.length <= min(10^5, 3 * n * (n-1) / 2)
  • \n\t
  • edges[i].length == 3
  • \n\t
  • 1 <= edges[i][0] <= 3
  • \n\t
  • 1 <= edges[i][1] < edges[i][2] <= n
  • \n\t
  • All tuples (typei, ui, vi) are distinct.
  • \n
\n", "content_cn": "

Alice \u548c Bob \u5171\u6709\u4e00\u4e2a\u65e0\u5411\u56fe\uff0c\u5176\u4e2d\u5305\u542b n \u4e2a\u8282\u70b9\u548c 3  \u79cd\u7c7b\u578b\u7684\u8fb9\uff1a

\n\n
    \n\t
  • \u7c7b\u578b 1\uff1a\u53ea\u80fd\u7531 Alice \u904d\u5386\u3002
  • \n\t
  • \u7c7b\u578b 2\uff1a\u53ea\u80fd\u7531 Bob \u904d\u5386\u3002
  • \n\t
  • \u7c7b\u578b 3\uff1aAlice \u548c Bob \u90fd\u53ef\u4ee5\u904d\u5386\u3002
  • \n
\n\n

\u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 edges \uff0c\u5176\u4e2d edges[i] = [typei, ui, vi] \u8868\u793a\u8282\u70b9 ui \u548c vi \u4e4b\u95f4\u5b58\u5728\u7c7b\u578b\u4e3a typei \u7684\u53cc\u5411\u8fb9\u3002\u8bf7\u4f60\u5728\u4fdd\u8bc1\u56fe\u4ecd\u80fd\u591f\u88ab Alice\u548c Bob \u5b8c\u5168\u904d\u5386\u7684\u524d\u63d0\u4e0b\uff0c\u627e\u51fa\u53ef\u4ee5\u5220\u9664\u7684\u6700\u5927\u8fb9\u6570\u3002\u5982\u679c\u4ece\u4efb\u4f55\u8282\u70b9\u5f00\u59cb\uff0cAlice \u548c Bob \u90fd\u53ef\u4ee5\u5230\u8fbe\u6240\u6709\u5176\u4ed6\u8282\u70b9\uff0c\u5219\u8ba4\u4e3a\u56fe\u662f\u53ef\u4ee5\u5b8c\u5168\u904d\u5386\u7684\u3002

\n\n

\u8fd4\u56de\u53ef\u4ee5\u5220\u9664\u7684\u6700\u5927\u8fb9\u6570\uff0c\u5982\u679c Alice \u548c Bob \u65e0\u6cd5\u5b8c\u5168\u904d\u5386\u56fe\uff0c\u5219\u8fd4\u56de -1 \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1an = 4, edges = [[3,1,2],[3,2,3],[1,1,3],[1,2,4],[1,1,2],[2,3,4]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5982\u679c\u5220\u9664 [1,1,2] \u548c [1,1,3] \u8fd9\u4e24\u6761\u8fb9\uff0cAlice \u548c Bob \u4ecd\u7136\u53ef\u4ee5\u5b8c\u5168\u904d\u5386\u8fd9\u4e2a\u56fe\u3002\u518d\u5220\u9664\u4efb\u4f55\u5176\u4ed6\u7684\u8fb9\u90fd\u65e0\u6cd5\u4fdd\u8bc1\u56fe\u53ef\u4ee5\u5b8c\u5168\u904d\u5386\u3002\u6240\u4ee5\u53ef\u4ee5\u5220\u9664\u7684\u6700\u5927\u8fb9\u6570\u662f 2 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1an = 4, edges = [[3,1,2],[3,2,3],[1,1,4],[2,1,4]]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6ce8\u610f\uff0c\u5220\u9664\u4efb\u4f55\u4e00\u6761\u8fb9\u90fd\u4f1a\u4f7f Alice \u548c Bob \u65e0\u6cd5\u5b8c\u5168\u904d\u5386\u8fd9\u4e2a\u56fe\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1an = 4, edges = [[3,2,3],[1,1,2],[2,3,4]]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u5728\u5f53\u524d\u56fe\u4e2d\uff0cAlice \u65e0\u6cd5\u4ece\u5176\u4ed6\u8282\u70b9\u5230\u8fbe\u8282\u70b9 4 \u3002\u7c7b\u4f3c\u5730\uff0cBob \u4e5f\u4e0d\u80fd\u8fbe\u5230\u8282\u70b9 1 \u3002\u56e0\u6b64\uff0c\u56fe\u65e0\u6cd5\u5b8c\u5168\u904d\u5386\u3002
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 10^5
  • \n\t
  • 1 <= edges.length <= min(10^5, 3 * n * (n-1) / 2)
  • \n\t
  • edges[i].length == 3
  • \n\t
  • 1 <= edges[i][0] <= 3
  • \n\t
  • 1 <= edges[i][1] < edges[i][2] <= n
  • \n\t
  • \u6240\u6709\u5143\u7ec4 (typei, ui, vi) \u4e92\u4e0d\u76f8\u540c
  • \n
\n", "tags_en": ["Union Find"], "tags_cn": ["\u5e76\u67e5\u96c6"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxNumEdgesToRemove(int n, vector>& edges) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxNumEdgesToRemove(int n, int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxNumEdgesToRemove(self, n, edges):\n \"\"\"\n :type n: int\n :type edges: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxNumEdgesToRemove(self, n: int, edges: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxNumEdgesToRemove(int n, int** edges, int edgesSize, int* edgesColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxNumEdgesToRemove(int n, int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} edges\n * @return {number}\n */\nvar maxNumEdgesToRemove = function(n, edges) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} edges\n# @return {Integer}\ndef max_num_edges_to_remove(n, edges)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxNumEdgesToRemove(_ n: Int, _ edges: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxNumEdgesToRemove(n int, edges [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxNumEdgesToRemove(n: Int, edges: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxNumEdgesToRemove(n: Int, edges: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_num_edges_to_remove(n: i32, edges: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $edges\n * @return Integer\n */\n function maxNumEdgesToRemove($n, $edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxNumEdgesToRemove(n: number, edges: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-num-edges-to-remove n edges)\n (-> exact-integer? (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1579](https://leetcode-cn.com/problems/remove-max-number-of-edges-to-keep-graph-fully-traversable)", "[\u4fdd\u8bc1\u56fe\u53ef\u5b8c\u5168\u904d\u5386](/solution/1500-1599/1579.Remove%20Max%20Number%20of%20Edges%20to%20Keep%20Graph%20Fully%20Traversable/README.md)", "`\u5e76\u67e5\u96c6`", "\u56f0\u96be", ""], "md_table_row_en": ["[1579](https://leetcode.com/problems/remove-max-number-of-edges-to-keep-graph-fully-traversable)", "[Remove Max Number of Edges to Keep Graph Fully Traversable](/solution/1500-1599/1579.Remove%20Max%20Number%20of%20Edges%20to%20Keep%20Graph%20Fully%20Traversable/README_EN.md)", "`Union Find`", "Hard", ""]}, {"question_id": "1700", "frontend_question_id": "1578", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-deletion-cost-to-avoid-repeating-letters", "url_en": "https://leetcode.com/problems/minimum-deletion-cost-to-avoid-repeating-letters", "relative_path_cn": "/solution/1500-1599/1578.Minimum%20Deletion%20Cost%20to%20Avoid%20Repeating%20Letters/README.md", "relative_path_en": "/solution/1500-1599/1578.Minimum%20Deletion%20Cost%20to%20Avoid%20Repeating%20Letters/README_EN.md", "title_cn": "\u907f\u514d\u91cd\u590d\u5b57\u6bcd\u7684\u6700\u5c0f\u5220\u9664\u6210\u672c", "title_en": "Minimum Deletion Cost to Avoid Repeating Letters", "question_title_slug": "minimum-deletion-cost-to-avoid-repeating-letters", "content_en": "

Given a string s and an array of integers cost where cost[i] is the cost of deleting the ith character in s.

\n\n

Return the minimum cost of deletions such that there are no two identical letters next to each other.

\n\n

Notice that you will delete the chosen characters at the same time, in other words, after deleting a character, the costs of deleting other characters will not change.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "abaac", cost = [1,2,3,4,5]\nOutput: 3\nExplanation: Delete the letter "a" with cost 3 to get "abac" (String without two identical letters next to each other).\n
\n\n

Example 2:

\n\n
\nInput: s = "abc", cost = [1,2,3]\nOutput: 0\nExplanation: You don't need to delete any character because there are no identical letters next to each other.\n
\n\n

Example 3:

\n\n
\nInput: s = "aabaa", cost = [1,2,3,4,1]\nOutput: 2\nExplanation: Delete the first and the last character, getting the string ("aba").\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • s.length == cost.length
  • \n\t
  • 1 <= s.length, cost.length <= 10^5
  • \n\t
  • 1 <= cost[i] <= 10^4
  • \n\t
  • s contains only lowercase English letters.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \u548c\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 cost \uff0c\u5176\u4e2d cost[i] \u662f\u4ece s \u4e2d\u5220\u9664\u5b57\u7b26 i \u7684\u4ee3\u4ef7\u3002

\n\n

\u8fd4\u56de\u4f7f\u5b57\u7b26\u4e32\u4efb\u610f\u76f8\u90bb\u4e24\u4e2a\u5b57\u6bcd\u4e0d\u76f8\u540c\u7684\u6700\u5c0f\u5220\u9664\u6210\u672c\u3002

\n\n

\u8bf7\u6ce8\u610f\uff0c\u5220\u9664\u4e00\u4e2a\u5b57\u7b26\u540e\uff0c\u5220\u9664\u5176\u4ed6\u5b57\u7b26\u7684\u6210\u672c\u4e0d\u4f1a\u6539\u53d8\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1as = "abaac", cost = [1,2,3,4,5]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u5220\u9664\u5b57\u6bcd "a" \u7684\u6210\u672c\u4e3a 3\uff0c\u7136\u540e\u5f97\u5230 "abac"\uff08\u5b57\u7b26\u4e32\u4e2d\u76f8\u90bb\u4e24\u4e2a\u5b57\u6bcd\u4e0d\u76f8\u540c\uff09\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1as = "abc", cost = [1,2,3]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u65e0\u9700\u5220\u9664\u4efb\u4f55\u5b57\u6bcd\uff0c\u56e0\u4e3a\u5b57\u7b26\u4e32\u4e2d\u4e0d\u5b58\u5728\u76f8\u90bb\u4e24\u4e2a\u5b57\u6bcd\u76f8\u540c\u7684\u60c5\u51b5\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1as = "aabaa", cost = [1,2,3,4,1]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5220\u9664\u7b2c\u4e00\u4e2a\u548c\u6700\u540e\u4e00\u4e2a\u5b57\u6bcd\uff0c\u5f97\u5230\u5b57\u7b26\u4e32 ("aba") \u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • s.length == cost.length
  • \n\t
  • 1 <= s.length, cost.length <= 10^5
  • \n\t
  • 1 <= cost[i] <= 10^4
  • \n\t
  • s \u4e2d\u53ea\u542b\u6709\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd
  • \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minCost(string s, vector& cost) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minCost(String s, int[] cost) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minCost(self, s, cost):\n \"\"\"\n :type s: str\n :type cost: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minCost(self, s: str, cost: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minCost(char * s, int* cost, int costSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinCost(string s, int[] cost) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number[]} cost\n * @return {number}\n */\nvar minCost = function(s, cost) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer[]} cost\n# @return {Integer}\ndef min_cost(s, cost)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minCost(_ s: String, _ cost: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minCost(s string, cost []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minCost(s: String, cost: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minCost(s: String, cost: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_cost(s: String, cost: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer[] $cost\n * @return Integer\n */\n function minCost($s, $cost) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minCost(s: string, cost: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-cost s cost)\n (-> string? (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1578](https://leetcode-cn.com/problems/minimum-deletion-cost-to-avoid-repeating-letters)", "[\u907f\u514d\u91cd\u590d\u5b57\u6bcd\u7684\u6700\u5c0f\u5220\u9664\u6210\u672c](/solution/1500-1599/1578.Minimum%20Deletion%20Cost%20to%20Avoid%20Repeating%20Letters/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1578](https://leetcode.com/problems/minimum-deletion-cost-to-avoid-repeating-letters)", "[Minimum Deletion Cost to Avoid Repeating Letters](/solution/1500-1599/1578.Minimum%20Deletion%20Cost%20to%20Avoid%20Repeating%20Letters/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1699", "frontend_question_id": "1577", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers", "url_en": "https://leetcode.com/problems/number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers", "relative_path_cn": "/solution/1500-1599/1577.Number%20of%20Ways%20Where%20Square%20of%20Number%20Is%20Equal%20to%20Product%20of%20Two%20Numbers/README.md", "relative_path_en": "/solution/1500-1599/1577.Number%20of%20Ways%20Where%20Square%20of%20Number%20Is%20Equal%20to%20Product%20of%20Two%20Numbers/README_EN.md", "title_cn": "\u6570\u7684\u5e73\u65b9\u7b49\u4e8e\u4e24\u6570\u4e58\u79ef\u7684\u65b9\u6cd5\u6570", "title_en": "Number of Ways Where Square of Number Is Equal to Product of Two Numbers", "question_title_slug": "number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers", "content_en": "

Given two arrays of integers nums1 and nums2, return the number of triplets formed (type 1 and type 2) under the following rules:

\n\n
    \n\t
  • Type 1: Triplet (i, j, k) if nums1[i]2 == nums2[j] * nums2[k] where 0 <= i < nums1.length and 0 <= j < k < nums2.length.
  • \n\t
  • Type 2: Triplet (i, j, k) if nums2[i]2 == nums1[j] * nums1[k] where 0 <= i < nums2.length and 0 <= j < k < nums1.length.
  • \n
\n\n

 

\n

Example 1:

\n\n
\nInput: nums1 = [7,4], nums2 = [5,2,8,9]\nOutput: 1\nExplanation: Type 1: (1,1,2), nums1[1]^2 = nums2[1] * nums2[2]. (4^2 = 2 * 8). \n
\n\n

Example 2:

\n\n
\nInput: nums1 = [1,1], nums2 = [1,1,1]\nOutput: 9\nExplanation: All Triplets are valid, because 1^2 = 1 * 1.\nType 1: (0,0,1), (0,0,2), (0,1,2), (1,0,1), (1,0,2), (1,1,2).  nums1[i]^2 = nums2[j] * nums2[k].\nType 2: (0,0,1), (1,0,1), (2,0,1). nums2[i]^2 = nums1[j] * nums1[k].\n
\n\n

Example 3:

\n\n
\nInput: nums1 = [7,7,8,3], nums2 = [1,2,9,7]\nOutput: 2\nExplanation: There are 2 valid triplets.\nType 1: (3,0,2).  nums1[3]^2 = nums2[0] * nums2[2].\nType 2: (3,0,1).  nums2[3]^2 = nums1[0] * nums1[1].\n
\n\n

Example 4:

\n\n
\nInput: nums1 = [4,7,9,11,23], nums2 = [3,5,1024,12,18]\nOutput: 0\nExplanation: There are no valid triplets.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums1.length, nums2.length <= 1000
  • \n\t
  • 1 <= nums1[i], nums2[i] <= 10^5
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e24\u4e2a\u6574\u6570\u6570\u7ec4 nums1 \u548c nums2 \uff0c\u8bf7\u4f60\u8fd4\u56de\u6839\u636e\u4ee5\u4e0b\u89c4\u5219\u5f62\u6210\u7684\u4e09\u5143\u7ec4\u7684\u6570\u76ee\uff08\u7c7b\u578b 1 \u548c\u7c7b\u578b 2 \uff09\uff1a

\n\n
    \n\t
  • \u7c7b\u578b 1\uff1a\u4e09\u5143\u7ec4 (i, j, k) \uff0c\u5982\u679c nums1[i]2 == nums2[j] * nums2[k] \u5176\u4e2d 0 <= i < nums1.length \u4e14 0 <= j < k < nums2.length
  • \n\t
  • \u7c7b\u578b 2\uff1a\u4e09\u5143\u7ec4 (i, j, k) \uff0c\u5982\u679c nums2[i]2 == nums1[j] * nums1[k] \u5176\u4e2d 0 <= i < nums2.length \u4e14 0 <= j < k < nums1.length
  • \n
\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anums1 = [7,4], nums2 = [5,2,8,9]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u7c7b\u578b 1\uff1a(1,1,2), nums1[1]^2 = nums2[1] * nums2[2] (4^2 = 2 * 8)
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anums1 = [1,1], nums2 = [1,1,1]\n\u8f93\u51fa\uff1a9\n\u89e3\u91ca\uff1a\u6240\u6709\u4e09\u5143\u7ec4\u90fd\u7b26\u5408\u9898\u76ee\u8981\u6c42\uff0c\u56e0\u4e3a 1^2 = 1 * 1\n\u7c7b\u578b 1\uff1a(0,0,1), (0,0,2), (0,1,2), (1,0,1), (1,0,2), (1,1,2), nums1[i]^2 = nums2[j] * nums2[k]\n\u7c7b\u578b 2\uff1a(0,0,1), (1,0,1), (2,0,1), nums2[i]^2 = nums1[j] * nums1[k]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1anums1 = [7,7,8,3], nums2 = [1,2,9,7]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6709\u4e24\u4e2a\u7b26\u5408\u9898\u76ee\u8981\u6c42\u7684\u4e09\u5143\u7ec4\n\u7c7b\u578b 1\uff1a(3,0,2), nums1[3]^2 = nums2[0] * nums2[2]\n\u7c7b\u578b 2\uff1a(3,0,1), nums2[3]^2 = nums1[0] * nums1[1]\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1anums1 = [4,7,9,11,23], nums2 = [3,5,1024,12,18]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u4e0d\u5b58\u5728\u7b26\u5408\u9898\u76ee\u8981\u6c42\u7684\u4e09\u5143\u7ec4\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums1.length, nums2.length <= 1000
  • \n\t
  • 1 <= nums1[i], nums2[i] <= 10^5
  • \n
\n", "tags_en": ["Hash Table", "Math"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numTriplets(vector& nums1, vector& nums2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numTriplets(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numTriplets(self, nums1, nums2):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numTriplets(self, nums1: List[int], nums2: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numTriplets(int* nums1, int nums1Size, int* nums2, int nums2Size){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumTriplets(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums1\n * @param {number[]} nums2\n * @return {number}\n */\nvar numTriplets = function(nums1, nums2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums1\n# @param {Integer[]} nums2\n# @return {Integer}\ndef num_triplets(nums1, nums2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numTriplets(_ nums1: [Int], _ nums2: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numTriplets(nums1 []int, nums2 []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numTriplets(nums1: Array[Int], nums2: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numTriplets(nums1: IntArray, nums2: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_triplets(nums1: Vec, nums2: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums1\n * @param Integer[] $nums2\n * @return Integer\n */\n function numTriplets($nums1, $nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numTriplets(nums1: number[], nums2: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-triplets nums1 nums2)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1577](https://leetcode-cn.com/problems/number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers)", "[\u6570\u7684\u5e73\u65b9\u7b49\u4e8e\u4e24\u6570\u4e58\u79ef\u7684\u65b9\u6cd5\u6570](/solution/1500-1599/1577.Number%20of%20Ways%20Where%20Square%20of%20Number%20Is%20Equal%20to%20Product%20of%20Two%20Numbers/README.md)", "`\u54c8\u5e0c\u8868`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1577](https://leetcode.com/problems/number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers)", "[Number of Ways Where Square of Number Is Equal to Product of Two Numbers](/solution/1500-1599/1577.Number%20of%20Ways%20Where%20Square%20of%20Number%20Is%20Equal%20to%20Product%20of%20Two%20Numbers/README_EN.md)", "`Hash Table`,`Math`", "Medium", ""]}, {"question_id": "1698", "frontend_question_id": "1576", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/replace-all-s-to-avoid-consecutive-repeating-characters", "url_en": "https://leetcode.com/problems/replace-all-s-to-avoid-consecutive-repeating-characters", "relative_path_cn": "/solution/1500-1599/1576.Replace%20All%20%27s%20to%20Avoid%20Consecutive%20Repeating%20Characters/README.md", "relative_path_en": "/solution/1500-1599/1576.Replace%20All%20%27s%20to%20Avoid%20Consecutive%20Repeating%20Characters/README_EN.md", "title_cn": "\u66ff\u6362\u6240\u6709\u7684\u95ee\u53f7", "title_en": "Replace All 's to Avoid Consecutive Repeating Characters", "question_title_slug": "replace-all-s-to-avoid-consecutive-repeating-characters", "content_en": "

Given a string s containing only lower case English letters and the '?' character, convert all the '?' characters into lower case letters such that the final string does not contain any consecutive repeating characters. You cannot modify the non '?' characters.

\n\n

It is guaranteed that there are no consecutive repeating characters in the given string except for '?'.

\n\n

Return the final string after all the conversions (possibly zero) have been made. If there is more than one solution, return any of them. It can be shown that an answer is always possible with the given constraints.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "?zs"\nOutput: "azs"\nExplanation: There are 25 solutions for this problem. From "azs" to "yzs", all are valid. Only "z" is an invalid modification as the string will consist of consecutive repeating characters in "zzs".
\n\n

Example 2:

\n\n
\nInput: s = "ubv?w"\nOutput: "ubvaw"\nExplanation: There are 24 solutions for this problem. Only "v" and "w" are invalid modifications as the strings will consist of consecutive repeating characters in "ubvvw" and "ubvww".\n
\n\n

Example 3:

\n\n
\nInput: s = "j?qg??b"\nOutput: "jaqgacb"\n
\n\n

Example 4:

\n\n
\nInput: s = "??yw?ipkj?"\nOutput: "acywaipkja"\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 100
  • \n\t
  • s contains only lower case English letters and '?'.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u4ec5\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u548c '?' \u5b57\u7b26\u7684\u5b57\u7b26\u4e32 s\uff0c\u8bf7\u4f60\u5c06\u6240\u6709\u7684 '?' \u8f6c\u6362\u4e3a\u82e5\u5e72\u5c0f\u5199\u5b57\u6bcd\uff0c\u4f7f\u6700\u7ec8\u7684\u5b57\u7b26\u4e32\u4e0d\u5305\u542b\u4efb\u4f55 \u8fde\u7eed\u91cd\u590d \u7684\u5b57\u7b26\u3002

\n\n

\u6ce8\u610f\uff1a\u4f60 \u4e0d\u80fd \u4fee\u6539\u975e '?' \u5b57\u7b26\u3002

\n\n

\u9898\u76ee\u6d4b\u8bd5\u7528\u4f8b\u4fdd\u8bc1 \u9664 '?' \u5b57\u7b26 \u4e4b\u5916\uff0c\u4e0d\u5b58\u5728\u8fde\u7eed\u91cd\u590d\u7684\u5b57\u7b26\u3002

\n\n

\u5728\u5b8c\u6210\u6240\u6709\u8f6c\u6362\uff08\u53ef\u80fd\u65e0\u9700\u8f6c\u6362\uff09\u540e\u8fd4\u56de\u6700\u7ec8\u7684\u5b57\u7b26\u4e32\u3002\u5982\u679c\u6709\u591a\u4e2a\u89e3\u51b3\u65b9\u6848\uff0c\u8bf7\u8fd4\u56de\u5176\u4e2d\u4efb\u4f55\u4e00\u4e2a\u3002\u53ef\u4ee5\u8bc1\u660e\uff0c\u5728\u7ed9\u5b9a\u7684\u7ea6\u675f\u6761\u4ef6\u4e0b\uff0c\u7b54\u6848\u603b\u662f\u5b58\u5728\u7684\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1as = "?zs"\n\u8f93\u51fa\uff1a"azs"\n\u89e3\u91ca\uff1a\u8be5\u793a\u4f8b\u5171\u6709 25 \u79cd\u89e3\u51b3\u65b9\u6848\uff0c\u4ece "azs" \u5230 "yzs" \u90fd\u662f\u7b26\u5408\u9898\u76ee\u8981\u6c42\u7684\u3002\u53ea\u6709 "z" \u662f\u65e0\u6548\u7684\u4fee\u6539\uff0c\u56e0\u4e3a\u5b57\u7b26\u4e32 "zzs" \u4e2d\u6709\u8fde\u7eed\u91cd\u590d\u7684\u4e24\u4e2a 'z' \u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1as = "ubv?w"\n\u8f93\u51fa\uff1a"ubvaw"\n\u89e3\u91ca\uff1a\u8be5\u793a\u4f8b\u5171\u6709 24 \u79cd\u89e3\u51b3\u65b9\u6848\uff0c\u53ea\u6709\u66ff\u6362\u6210 "v" \u548c "w" \u4e0d\u7b26\u5408\u9898\u76ee\u8981\u6c42\u3002\u56e0\u4e3a "ubvvw" \u548c "ubvww" \u90fd\u5305\u542b\u8fde\u7eed\u91cd\u590d\u7684\u5b57\u7b26\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1as = "j?qg??b"\n\u8f93\u51fa\uff1a"jaqgacb"\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1as = "??yw?ipkj?"\n\u8f93\u51fa\uff1a"acywaipkja"\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \n\t

    1 <= s.length <= 100

    \n\t
  • \n\t
  • \n\t

    s \u4ec5\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u548c '?' \u5b57\u7b26

    \n\t
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string modifyString(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String modifyString(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def modifyString(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def modifyString(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * modifyString(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ModifyString(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar modifyString = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef modify_string(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func modifyString(_ s: String) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func modifyString(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def modifyString(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun modifyString(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn modify_string(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function modifyString($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function modifyString(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (modify-string s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1576](https://leetcode-cn.com/problems/replace-all-s-to-avoid-consecutive-repeating-characters)", "[\u66ff\u6362\u6240\u6709\u7684\u95ee\u53f7](/solution/1500-1599/1576.Replace%20All%20%27s%20to%20Avoid%20Consecutive%20Repeating%20Characters/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1576](https://leetcode.com/problems/replace-all-s-to-avoid-consecutive-repeating-characters)", "[Replace All 's to Avoid Consecutive Repeating Characters](/solution/1500-1599/1576.Replace%20All%20%27s%20to%20Avoid%20Consecutive%20Repeating%20Characters/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1697", "frontend_question_id": "1554", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/strings-differ-by-one-character", "url_en": "https://leetcode.com/problems/strings-differ-by-one-character", "relative_path_cn": "/solution/1500-1599/1554.Strings%20Differ%20by%20One%20Character/README.md", "relative_path_en": "/solution/1500-1599/1554.Strings%20Differ%20by%20One%20Character/README_EN.md", "title_cn": "\u53ea\u6709\u4e00\u4e2a\u4e0d\u540c\u5b57\u7b26\u7684\u5b57\u7b26\u4e32", "title_en": "Strings Differ by One Character", "question_title_slug": "strings-differ-by-one-character", "content_en": "

Given a list of strings dict where all the strings are of the same length.

\n\n

Return True if there are 2 strings that only differ by 1 character in the same index, otherwise return False.

\n\n

Follow up: Could you solve this problem in O(n*m) where n is the length of dict and m is the length of each string.

\n\n

 

\n

Example 1:

\n\n
\nInput: dict = ["abcd","acbd", "aacd"]\nOutput: true\nExplanation: Strings "abcd" and "aacd" differ only by one character in the index 1.\n
\n\n

Example 2:

\n\n
\nInput: dict = ["ab","cd","yz"]\nOutput: false\n
\n\n

Example 3:

\n\n
\nInput: dict = ["abcd","cccc","abyd","abab"]\nOutput: true\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • Number of characters in dict <= 10^5
  • \n\t
  • dict[i].length == dict[j].length
  • \n\t
  • dict[i] should be unique.
  • \n\t
  • dict[i] contains only lowercase English letters.
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\u5217\u8868 dict \uff0c\u5176\u4e2d\u6240\u6709\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u90fd\u76f8\u540c\u3002

\n\n

\u5f53\u5b58\u5728\u4e24\u4e2a\u5b57\u7b26\u4e32\u5728\u76f8\u540c\u7d22\u5f15\u5904\u53ea\u6709\u4e00\u4e2a\u5b57\u7b26\u4e0d\u540c\u65f6\uff0c\u8fd4\u56de True \uff0c\u5426\u5219\u8fd4\u56de False \u3002

\n\n

\u8fdb\u9636\uff1a\u4f60\u53ef\u4ee5\u4ee5 O(n*m) \u7684\u590d\u6742\u5ea6\u89e3\u51b3\u95ee\u9898\u5417\uff1f\u5176\u4e2d n \u662f\u5217\u8868 dict \u7684\u957f\u5ea6\uff0cm \u662f\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1adict = ["abcd","acbd", "aacd"]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u5b57\u7b26\u4e32 "abcd" \u548c "aacd" \u53ea\u5728\u7d22\u5f15 1 \u5904\u6709\u4e00\u4e2a\u4e0d\u540c\u7684\u5b57\u7b26\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1adict = ["ab","cd","yz"]\n\u8f93\u51fa\uff1afalse\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1adict = ["abcd","cccc","abyd","abab"]\n\u8f93\u51fa\uff1atrue\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • dict \u4e2d\u7684\u5b57\u7b26\u6570\u5c0f\u4e8e\u6216\u7b49\u4e8e 10^5 \u3002
  • \n\t
  • dict[i].length == dict[j].length
  • \n\t
  • dict[i] \u662f\u4e92\u4e0d\u76f8\u540c\u7684\u3002
  • \n\t
  • dict[i] \u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
  • \n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool differByOne(vector& dict) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean differByOne(String[] dict) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def differByOne(self, dict):\n \"\"\"\n :type dict: List[str]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def differByOne(self, dict: List[str]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool differByOne(char ** dict, int dictSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool DifferByOne(string[] dict) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} dict\n * @return {boolean}\n */\nvar differByOne = function(dict) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} dict\n# @return {Boolean}\ndef differ_by_one(dict)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func differByOne(_ dict: [String]) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func differByOne(dict []string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def differByOne(dict: Array[String]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun differByOne(dict: Array): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn differ_by_one(dict: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $dict\n * @return Boolean\n */\n function differByOne($dict) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function differByOne(dict: string[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (differ-by-one dict)\n (-> (listof string?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1554](https://leetcode-cn.com/problems/strings-differ-by-one-character)", "[\u53ea\u6709\u4e00\u4e2a\u4e0d\u540c\u5b57\u7b26\u7684\u5b57\u7b26\u4e32](/solution/1500-1599/1554.Strings%20Differ%20by%20One%20Character/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1554](https://leetcode.com/problems/strings-differ-by-one-character)", "[Strings Differ by One Character](/solution/1500-1599/1554.Strings%20Differ%20by%20One%20Character/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1696", "frontend_question_id": "1591", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/strange-printer-ii", "url_en": "https://leetcode.com/problems/strange-printer-ii", "relative_path_cn": "/solution/1500-1599/1591.Strange%20Printer%20II/README.md", "relative_path_en": "/solution/1500-1599/1591.Strange%20Printer%20II/README_EN.md", "title_cn": "\u5947\u602a\u7684\u6253\u5370\u673a II", "title_en": "Strange Printer II", "question_title_slug": "strange-printer-ii", "content_en": "

There is a strange printer with the following two special requirements:

\n\n
    \n\t
  • On each turn, the printer will print a solid rectangular pattern of a single color on the grid. This will cover up the existing colors in the rectangle.
  • \n\t
  • Once the printer has used a color for the above operation, the same color cannot be used again.
  • \n
\n\n

You are given a m x n matrix targetGrid, where targetGrid[row][col] is the color in the position (row, col) of the grid.

\n\n

Return true if it is possible to print the matrix targetGrid, otherwise, return false.

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: targetGrid = [[1,1,1,1],[1,2,2,1],[1,2,2,1],[1,1,1,1]]\nOutput: true\n
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: targetGrid = [[1,1,1,1],[1,1,3,3],[1,1,3,4],[5,5,1,4]]\nOutput: true\n
\n\n

Example 3:

\n\n
\nInput: targetGrid = [[1,2,1],[2,1,2],[1,2,1]]\nOutput: false\nExplanation: It is impossible to form targetGrid because it is not allowed to print the same color in different turns.
\n\n

Example 4:

\n\n
\nInput: targetGrid = [[1,1,1],[3,1,3]]\nOutput: false\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • m == targetGrid.length
  • \n\t
  • n == targetGrid[i].length
  • \n\t
  • 1 <= m, n <= 60
  • \n\t
  • 1 <= targetGrid[row][col] <= 60
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5947\u602a\u7684\u6253\u5370\u673a\uff0c\u5b83\u6709\u5982\u4e0b\u4e24\u4e2a\u7279\u6b8a\u7684\u6253\u5370\u89c4\u5219\uff1a

\n\n
    \n\t
  • \u6bcf\u4e00\u6b21\u64cd\u4f5c\u65f6\uff0c\u6253\u5370\u673a\u4f1a\u7528\u540c\u4e00\u79cd\u989c\u8272\u6253\u5370\u4e00\u4e2a\u77e9\u5f62\u7684\u5f62\u72b6\uff0c\u6bcf\u6b21\u6253\u5370\u4f1a\u8986\u76d6\u77e9\u5f62\u5bf9\u5e94\u683c\u5b50\u91cc\u539f\u672c\u7684\u989c\u8272\u3002
  • \n\t
  • \u4e00\u65e6\u77e9\u5f62\u6839\u636e\u4e0a\u9762\u7684\u89c4\u5219\u4f7f\u7528\u4e86\u4e00\u79cd\u989c\u8272\uff0c\u90a3\u4e48 \u76f8\u540c\u7684\u989c\u8272\u4e0d\u80fd\u518d\u88ab\u4f7f\u7528 \u3002
  • \n
\n\n

\u7ed9\u4f60\u4e00\u4e2a\u521d\u59cb\u6ca1\u6709\u989c\u8272\u7684 m x n \u7684\u77e9\u5f62 targetGrid \uff0c\u5176\u4e2d targetGrid[row][col] \u662f\u4f4d\u7f6e (row, col) \u7684\u989c\u8272\u3002

\n\n

\u5982\u679c\u4f60\u80fd\u6309\u7167\u4e0a\u8ff0\u89c4\u5219\u6253\u5370\u51fa\u77e9\u5f62 targetGrid \uff0c\u8bf7\u4f60\u8fd4\u56de true \uff0c\u5426\u5219\u8fd4\u56de false \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1atargetGrid = [[1,1,1,1],[1,2,2,1],[1,2,2,1],[1,1,1,1]]\n\u8f93\u51fa\uff1atrue\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1atargetGrid = [[1,1,1,1],[1,1,3,3],[1,1,3,4],[5,5,1,4]]\n\u8f93\u51fa\uff1atrue\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1atargetGrid = [[1,2,1],[2,1,2],[1,2,1]]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u6ca1\u6709\u529e\u6cd5\u5f97\u5230 targetGrid \uff0c\u56e0\u4e3a\u6bcf\u4e00\u8f6e\u64cd\u4f5c\u4f7f\u7528\u7684\u989c\u8272\u4e92\u4e0d\u76f8\u540c\u3002
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1atargetGrid = [[1,1,1],[3,1,3]]\n\u8f93\u51fa\uff1afalse\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • m == targetGrid.length
  • \n\t
  • n == targetGrid[i].length
  • \n\t
  • 1 <= m, n <= 60
  • \n\t
  • 1 <= targetGrid[row][col] <= 60
  • \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isPrintable(vector>& targetGrid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isPrintable(int[][] targetGrid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isPrintable(self, targetGrid):\n \"\"\"\n :type targetGrid: List[List[int]]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isPrintable(self, targetGrid: List[List[int]]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isPrintable(int** targetGrid, int targetGridSize, int* targetGridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsPrintable(int[][] targetGrid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} targetGrid\n * @return {boolean}\n */\nvar isPrintable = function(targetGrid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} target_grid\n# @return {Boolean}\ndef is_printable(target_grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isPrintable(_ targetGrid: [[Int]]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isPrintable(targetGrid [][]int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isPrintable(targetGrid: Array[Array[Int]]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isPrintable(targetGrid: Array): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_printable(target_grid: Vec>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $targetGrid\n * @return Boolean\n */\n function isPrintable($targetGrid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isPrintable(targetGrid: number[][]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-printable targetGrid)\n (-> (listof (listof exact-integer?)) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1591](https://leetcode-cn.com/problems/strange-printer-ii)", "[\u5947\u602a\u7684\u6253\u5370\u673a II](/solution/1500-1599/1591.Strange%20Printer%20II/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[1591](https://leetcode.com/problems/strange-printer-ii)", "[Strange Printer II](/solution/1500-1599/1591.Strange%20Printer%20II/README_EN.md)", "`Greedy`", "Hard", ""]}, {"question_id": "1695", "frontend_question_id": "1589", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-sum-obtained-of-any-permutation", "url_en": "https://leetcode.com/problems/maximum-sum-obtained-of-any-permutation", "relative_path_cn": "/solution/1500-1599/1589.Maximum%20Sum%20Obtained%20of%20Any%20Permutation/README.md", "relative_path_en": "/solution/1500-1599/1589.Maximum%20Sum%20Obtained%20of%20Any%20Permutation/README_EN.md", "title_cn": "\u6240\u6709\u6392\u5217\u4e2d\u7684\u6700\u5927\u548c", "title_en": "Maximum Sum Obtained of Any Permutation", "question_title_slug": "maximum-sum-obtained-of-any-permutation", "content_en": "

We have an array of integers, nums, and an array of requests where requests[i] = [starti, endi]. The ith request asks for the sum of nums[starti] + nums[starti + 1] + ... + nums[endi - 1] + nums[endi]. Both starti and endi are 0-indexed.

\n\n

Return the maximum total sum of all requests among all permutations of nums.

\n\n

Since the answer may be too large, return it modulo 109 + 7.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [1,2,3,4,5], requests = [[1,3],[0,1]]\nOutput: 19\nExplanation: One permutation of nums is [2,1,3,4,5] with the following result: \nrequests[0] -> nums[1] + nums[2] + nums[3] = 1 + 3 + 4 = 8\nrequests[1] -> nums[0] + nums[1] = 2 + 1 = 3\nTotal sum: 8 + 3 = 11.\nA permutation with a higher total sum is [3,5,4,2,1] with the following result:\nrequests[0] -> nums[1] + nums[2] + nums[3] = 5 + 4 + 2 = 11\nrequests[1] -> nums[0] + nums[1] = 3 + 5  = 8\nTotal sum: 11 + 8 = 19, which is the best that you can do.\n
\n\n

Example 2:

\n\n
\nInput: nums = [1,2,3,4,5,6], requests = [[0,1]]\nOutput: 11\nExplanation: A permutation with the max total sum is [6,5,4,3,2,1] with request sums [11].
\n\n

Example 3:

\n\n
\nInput: nums = [1,2,3,4,5,10], requests = [[0,2],[1,3],[1,1]]\nOutput: 47\nExplanation: A permutation with the max total sum is [4,10,5,3,2,1] with request sums [19,18,10].
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == nums.length
  • \n\t
  • 1 <= n <= 105
  • \n\t
  • 0 <= nums[i] <= 105
  • \n\t
  • 1 <= requests.length <= 105
  • \n\t
  • requests[i].length == 2
  • \n\t
  • 0 <= starti <= endi < n
  • \n
\n", "content_cn": "

\u6709\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \uff0c\u548c\u4e00\u4e2a\u67e5\u8be2\u6570\u7ec4 requests \uff0c\u5176\u4e2d requests[i] = [starti, endi] \u3002\u7b2c i \u4e2a\u67e5\u8be2\u6c42 nums[starti] + nums[starti + 1] + ... + nums[endi - 1] + nums[endi] \u7684\u7ed3\u679c \uff0cstarti \u548c endi \u6570\u7ec4\u7d22\u5f15\u90fd\u662f \u4ece 0 \u5f00\u59cb \u7684\u3002

\n\n

\u4f60\u53ef\u4ee5\u4efb\u610f\u6392\u5217 nums \u4e2d\u7684\u6570\u5b57\uff0c\u8bf7\u4f60\u8fd4\u56de\u6240\u6709\u67e5\u8be2\u7ed3\u679c\u4e4b\u548c\u7684\u6700\u5927\u503c\u3002

\n\n

\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u4f1a\u5f88\u5927\uff0c\u8bf7\u4f60\u5c06\u5b83\u5bf9 109 + 7 \u53d6\u4f59 \u540e\u8fd4\u56de\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,2,3,4,5], requests = [[1,3],[0,1]]\n\u8f93\u51fa\uff1a19\n\u89e3\u91ca\uff1a\u4e00\u4e2a\u53ef\u884c\u7684 nums \u6392\u5217\u4e3a [2,1,3,4,5]\uff0c\u5e76\u6709\u5982\u4e0b\u7ed3\u679c\uff1a\nrequests[0] -> nums[1] + nums[2] + nums[3] = 1 + 3 + 4 = 8\nrequests[1] -> nums[0] + nums[1] = 2 + 1 = 3\n\u603b\u548c\u4e3a\uff1a8 + 3 = 11\u3002\n\u4e00\u4e2a\u603b\u548c\u66f4\u5927\u7684\u6392\u5217\u4e3a [3,5,4,2,1]\uff0c\u5e76\u6709\u5982\u4e0b\u7ed3\u679c\uff1a\nrequests[0] -> nums[1] + nums[2] + nums[3] = 5 + 4 + 2 = 11\nrequests[1] -> nums[0] + nums[1] = 3 + 5  = 8\n\u603b\u548c\u4e3a\uff1a 11 + 8 = 19\uff0c\u8fd9\u4e2a\u65b9\u6848\u662f\u6240\u6709\u6392\u5217\u4e2d\u67e5\u8be2\u4e4b\u548c\u6700\u5927\u7684\u7ed3\u679c\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,2,3,4,5,6], requests = [[0,1]]\n\u8f93\u51fa\uff1a11\n\u89e3\u91ca\uff1a\u4e00\u4e2a\u603b\u548c\u6700\u5927\u7684\u6392\u5217\u4e3a [6,5,4,3,2,1] \uff0c\u67e5\u8be2\u548c\u4e3a [11]\u3002
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,2,3,4,5,10], requests = [[0,2],[1,3],[1,1]]\n\u8f93\u51fa\uff1a47\n\u89e3\u91ca\uff1a\u4e00\u4e2a\u548c\u6700\u5927\u7684\u6392\u5217\u4e3a [4,10,5,3,2,1] \uff0c\u67e5\u8be2\u7ed3\u679c\u5206\u522b\u4e3a [19,18,10]\u3002
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • n == nums.length
  • \n\t
  • 1 <= n <= 105
  • \n\t
  • 0 <= nums[i] <= 105
  • \n\t
  • 1 <= requests.length <= 105
  • \n\t
  • requests[i].length == 2
  • \n\t
  • 0 <= starti <= endi < n
  • \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxSumRangeQuery(vector& nums, vector>& requests) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxSumRangeQuery(int[] nums, int[][] requests) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxSumRangeQuery(self, nums, requests):\n \"\"\"\n :type nums: List[int]\n :type requests: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxSumRangeQuery(self, nums: List[int], requests: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxSumRangeQuery(int* nums, int numsSize, int** requests, int requestsSize, int* requestsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxSumRangeQuery(int[] nums, int[][] requests) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number[][]} requests\n * @return {number}\n */\nvar maxSumRangeQuery = function(nums, requests) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer[][]} requests\n# @return {Integer}\ndef max_sum_range_query(nums, requests)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxSumRangeQuery(_ nums: [Int], _ requests: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxSumRangeQuery(nums []int, requests [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxSumRangeQuery(nums: Array[Int], requests: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxSumRangeQuery(nums: IntArray, requests: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_sum_range_query(nums: Vec, requests: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer[][] $requests\n * @return Integer\n */\n function maxSumRangeQuery($nums, $requests) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxSumRangeQuery(nums: number[], requests: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-sum-range-query nums requests)\n (-> (listof exact-integer?) (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1589](https://leetcode-cn.com/problems/maximum-sum-obtained-of-any-permutation)", "[\u6240\u6709\u6392\u5217\u4e2d\u7684\u6700\u5927\u548c](/solution/1500-1599/1589.Maximum%20Sum%20Obtained%20of%20Any%20Permutation/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1589](https://leetcode.com/problems/maximum-sum-obtained-of-any-permutation)", "[Maximum Sum Obtained of Any Permutation](/solution/1500-1599/1589.Maximum%20Sum%20Obtained%20of%20Any%20Permutation/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1694", "frontend_question_id": "1590", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/make-sum-divisible-by-p", "url_en": "https://leetcode.com/problems/make-sum-divisible-by-p", "relative_path_cn": "/solution/1500-1599/1590.Make%20Sum%20Divisible%20by%20P/README.md", "relative_path_en": "/solution/1500-1599/1590.Make%20Sum%20Divisible%20by%20P/README_EN.md", "title_cn": "\u4f7f\u6570\u7ec4\u548c\u80fd\u88ab P \u6574\u9664", "title_en": "Make Sum Divisible by P", "question_title_slug": "make-sum-divisible-by-p", "content_en": "

Given an array of positive integers nums, remove the smallest subarray (possibly empty) such that the sum of the remaining elements is divisible by p. It is not allowed to remove the whole array.

\n\n

Return the length of the smallest subarray that you need to remove, or -1 if it's impossible.

\n\n

A subarray is defined as a contiguous block of elements in the array.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [3,1,4,2], p = 6\nOutput: 1\nExplanation: The sum of the elements in nums is 10, which is not divisible by 6. We can remove the subarray [4], and the sum of the remaining elements is 6, which is divisible by 6.\n
\n\n

Example 2:

\n\n
\nInput: nums = [6,3,5,2], p = 9\nOutput: 2\nExplanation: We cannot remove a single element to get a sum divisible by 9. The best way is to remove the subarray [5,2], leaving us with [6,3] with sum 9.\n
\n\n

Example 3:

\n\n
\nInput: nums = [1,2,3], p = 3\nOutput: 0\nExplanation: Here the sum is 6. which is already divisible by 3. Thus we do not need to remove anything.\n
\n\n

Example 4:

\n\n
\nInput: nums = [1,2,3], p = 7\nOutput: -1\nExplanation: There is no way to remove a subarray in order to get a sum divisible by 7.\n
\n\n

Example 5:

\n\n
\nInput: nums = [1000000000,1000000000,1000000000], p = 3\nOutput: 0\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 105
  • \n\t
  • 1 <= nums[i] <= 109
  • \n\t
  • 1 <= p <= 109
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6b63\u6574\u6570\u6570\u7ec4 nums\uff0c\u8bf7\u4f60\u79fb\u9664 \u6700\u77ed \u5b50\u6570\u7ec4\uff08\u53ef\u4ee5\u4e3a \u7a7a\uff09\uff0c\u4f7f\u5f97\u5269\u4f59\u5143\u7d20\u7684 \u548c \u80fd\u88ab p \u6574\u9664\u3002 \u4e0d\u5141\u8bb8 \u5c06\u6574\u4e2a\u6570\u7ec4\u90fd\u79fb\u9664\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u4f60\u9700\u8981\u79fb\u9664\u7684\u6700\u77ed\u5b50\u6570\u7ec4\u7684\u957f\u5ea6\uff0c\u5982\u679c\u65e0\u6cd5\u6ee1\u8db3\u9898\u76ee\u8981\u6c42\uff0c\u8fd4\u56de -1 \u3002

\n\n

\u5b50\u6570\u7ec4 \u5b9a\u4e49\u4e3a\u539f\u6570\u7ec4\u4e2d\u8fde\u7eed\u7684\u4e00\u7ec4\u5143\u7d20\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anums = [3,1,4,2], p = 6\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1anums \u4e2d\u5143\u7d20\u548c\u4e3a 10\uff0c\u4e0d\u80fd\u88ab p \u6574\u9664\u3002\u6211\u4eec\u53ef\u4ee5\u79fb\u9664\u5b50\u6570\u7ec4 [4] \uff0c\u5269\u4f59\u5143\u7d20\u7684\u548c\u4e3a 6 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anums = [6,3,5,2], p = 9\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6211\u4eec\u65e0\u6cd5\u79fb\u9664\u4efb\u4f55\u4e00\u4e2a\u5143\u7d20\u4f7f\u5f97\u548c\u88ab 9 \u6574\u9664\uff0c\u6700\u4f18\u65b9\u6848\u662f\u79fb\u9664\u5b50\u6570\u7ec4 [5,2] \uff0c\u5269\u4f59\u5143\u7d20\u4e3a [6,3]\uff0c\u548c\u4e3a 9 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,2,3], p = 3\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u548c\u6070\u597d\u4e3a 6 \uff0c\u5df2\u7ecf\u80fd\u88ab 3 \u6574\u9664\u4e86\u3002\u6240\u4ee5\u6211\u4eec\u4e0d\u9700\u8981\u79fb\u9664\u4efb\u4f55\u5143\u7d20\u3002\n
\n\n

\u793a\u4f8b  4\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,2,3], p = 7\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u6ca1\u6709\u4efb\u4f55\u65b9\u6848\u4f7f\u5f97\u79fb\u9664\u5b50\u6570\u7ec4\u540e\u5269\u4f59\u5143\u7d20\u7684\u548c\u88ab 7 \u6574\u9664\u3002\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1anums = [1000000000,1000000000,1000000000], p = 3\n\u8f93\u51fa\uff1a0\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 105
  • \n\t
  • 1 <= nums[i] <= 109
  • \n\t
  • 1 <= p <= 109
  • \n
\n", "tags_en": ["Array", "Hash Table", "Math", "Binary Search"], "tags_cn": ["\u6570\u7ec4", "\u54c8\u5e0c\u8868", "\u6570\u5b66", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minSubarray(vector& nums, int p) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minSubarray(int[] nums, int p) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minSubarray(self, nums, p):\n \"\"\"\n :type nums: List[int]\n :type p: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minSubarray(self, nums: List[int], p: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minSubarray(int* nums, int numsSize, int p){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinSubarray(int[] nums, int p) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} p\n * @return {number}\n */\nvar minSubarray = function(nums, p) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} p\n# @return {Integer}\ndef min_subarray(nums, p)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minSubarray(_ nums: [Int], _ p: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minSubarray(nums []int, p int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minSubarray(nums: Array[Int], p: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minSubarray(nums: IntArray, p: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_subarray(nums: Vec, p: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $p\n * @return Integer\n */\n function minSubarray($nums, $p) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minSubarray(nums: number[], p: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-subarray nums p)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1590](https://leetcode-cn.com/problems/make-sum-divisible-by-p)", "[\u4f7f\u6570\u7ec4\u548c\u80fd\u88ab P \u6574\u9664](/solution/1500-1599/1590.Make%20Sum%20Divisible%20by%20P/README.md)", "`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`,`\u6570\u5b66`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1590](https://leetcode.com/problems/make-sum-divisible-by-p)", "[Make Sum Divisible by P](/solution/1500-1599/1590.Make%20Sum%20Divisible%20by%20P/README_EN.md)", "`Array`,`Hash Table`,`Math`,`Binary Search`", "Medium", ""]}, {"question_id": "1693", "frontend_question_id": "1588", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sum-of-all-odd-length-subarrays", "url_en": "https://leetcode.com/problems/sum-of-all-odd-length-subarrays", "relative_path_cn": "/solution/1500-1599/1588.Sum%20of%20All%20Odd%20Length%20Subarrays/README.md", "relative_path_en": "/solution/1500-1599/1588.Sum%20of%20All%20Odd%20Length%20Subarrays/README_EN.md", "title_cn": "\u6240\u6709\u5947\u6570\u957f\u5ea6\u5b50\u6570\u7ec4\u7684\u548c", "title_en": "Sum of All Odd Length Subarrays", "question_title_slug": "sum-of-all-odd-length-subarrays", "content_en": "

Given an array of positive integers arr, calculate the sum of all possible odd-length subarrays.

\n\n

A subarray is a contiguous subsequence of the array.

\n\n

Return the sum of all odd-length subarrays of arr.

\n\n

 

\n

Example 1:

\n\n
\nInput: arr = [1,4,2,5,3]\nOutput: 58\nExplanation: The odd-length subarrays of arr and their sums are:\n[1] = 1\n[4] = 4\n[2] = 2\n[5] = 5\n[3] = 3\n[1,4,2] = 7\n[4,2,5] = 11\n[2,5,3] = 10\n[1,4,2,5,3] = 15\nIf we add all these together we get 1 + 4 + 2 + 5 + 3 + 7 + 11 + 10 + 15 = 58
\n\n

Example 2:

\n\n
\nInput: arr = [1,2]\nOutput: 3\nExplanation: There are only 2 subarrays of odd length, [1] and [2]. Their sum is 3.
\n\n

Example 3:

\n\n
\nInput: arr = [10,11,12]\nOutput: 66\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= arr.length <= 100
  • \n\t
  • 1 <= arr[i] <= 1000
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6b63\u6574\u6570\u6570\u7ec4 arr \uff0c\u8bf7\u4f60\u8ba1\u7b97\u6240\u6709\u53ef\u80fd\u7684\u5947\u6570\u957f\u5ea6\u5b50\u6570\u7ec4\u7684\u548c\u3002

\n\n

\u5b50\u6570\u7ec4 \u5b9a\u4e49\u4e3a\u539f\u6570\u7ec4\u4e2d\u7684\u4e00\u4e2a\u8fde\u7eed\u5b50\u5e8f\u5217\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de arr \u4e2d \u6240\u6709\u5947\u6570\u957f\u5ea6\u5b50\u6570\u7ec4\u7684\u548c \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aarr = [1,4,2,5,3]\n\u8f93\u51fa\uff1a58\n\u89e3\u91ca\uff1a\u6240\u6709\u5947\u6570\u957f\u5ea6\u5b50\u6570\u7ec4\u548c\u5b83\u4eec\u7684\u548c\u4e3a\uff1a\n[1] = 1\n[4] = 4\n[2] = 2\n[5] = 5\n[3] = 3\n[1,4,2] = 7\n[4,2,5] = 11\n[2,5,3] = 10\n[1,4,2,5,3] = 15\n\u6211\u4eec\u5c06\u6240\u6709\u503c\u6c42\u548c\u5f97\u5230 1 + 4 + 2 + 5 + 3 + 7 + 11 + 10 + 15 = 58
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aarr = [1,2]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u603b\u5171\u53ea\u6709 2 \u4e2a\u957f\u5ea6\u4e3a\u5947\u6570\u7684\u5b50\u6570\u7ec4\uff0c[1] \u548c [2]\u3002\u5b83\u4eec\u7684\u548c\u4e3a 3 \u3002
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aarr = [10,11,12]\n\u8f93\u51fa\uff1a66\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= arr.length <= 100
  • \n\t
  • 1 <= arr[i] <= 1000
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int sumOddLengthSubarrays(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int sumOddLengthSubarrays(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def sumOddLengthSubarrays(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def sumOddLengthSubarrays(self, arr: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint sumOddLengthSubarrays(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SumOddLengthSubarrays(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar sumOddLengthSubarrays = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef sum_odd_length_subarrays(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func sumOddLengthSubarrays(_ arr: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func sumOddLengthSubarrays(arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def sumOddLengthSubarrays(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun sumOddLengthSubarrays(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sum_odd_length_subarrays(arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function sumOddLengthSubarrays($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function sumOddLengthSubarrays(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (sum-odd-length-subarrays arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1588](https://leetcode-cn.com/problems/sum-of-all-odd-length-subarrays)", "[\u6240\u6709\u5947\u6570\u957f\u5ea6\u5b50\u6570\u7ec4\u7684\u548c](/solution/1500-1599/1588.Sum%20of%20All%20Odd%20Length%20Subarrays/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1588](https://leetcode.com/problems/sum-of-all-odd-length-subarrays)", "[Sum of All Odd Length Subarrays](/solution/1500-1599/1588.Sum%20of%20All%20Odd%20Length%20Subarrays/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1692", "frontend_question_id": "1569", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-ways-to-reorder-array-to-get-same-bst", "url_en": "https://leetcode.com/problems/number-of-ways-to-reorder-array-to-get-same-bst", "relative_path_cn": "/solution/1500-1599/1569.Number%20of%20Ways%20to%20Reorder%20Array%20to%20Get%20Same%20BST/README.md", "relative_path_en": "/solution/1500-1599/1569.Number%20of%20Ways%20to%20Reorder%20Array%20to%20Get%20Same%20BST/README_EN.md", "title_cn": "\u5c06\u5b50\u6570\u7ec4\u91cd\u65b0\u6392\u5e8f\u5f97\u5230\u540c\u4e00\u4e2a\u4e8c\u53c9\u67e5\u627e\u6811\u7684\u65b9\u6848\u6570", "title_en": "Number of Ways to Reorder Array to Get Same BST", "question_title_slug": "number-of-ways-to-reorder-array-to-get-same-bst", "content_en": "

Given an array nums that represents a permutation of integers from 1 to n. We are going to construct a binary search tree (BST) by inserting the elements of nums in order into an initially empty BST. Find the number of different ways to reorder nums so that the constructed BST is identical to that formed from the original array nums.

\n\n

For example, given nums = [2,1,3], we will have 2 as the root, 1 as a left child, and 3 as a right child. The array [2,3,1] also yields the same BST but [3,2,1] yields a different BST.

\n\n

Return the number of ways to reorder nums such that the BST formed is identical to the original BST formed from nums.

\n\n

Since the answer may be very large, return it modulo 10^9 + 7.

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: nums = [2,1,3]\nOutput: 1\nExplanation: We can reorder nums to be [2,3,1] which will yield the same BST. There are no other ways to reorder nums which will yield the same BST.\n
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: nums = [3,4,5,1,2]\nOutput: 5\nExplanation: The following 5 arrays will yield the same BST: \n[3,1,2,4,5]\n[3,1,4,2,5]\n[3,1,4,5,2]\n[3,4,1,2,5]\n[3,4,1,5,2]\n
\n\n

Example 3:

\n\n

\"\"

\n\n
\nInput: nums = [1,2,3]\nOutput: 0\nExplanation: There are no other orderings of nums that will yield the same BST.\n
\n\n

Example 4:

\n\n

\"\"

\n\n
\nInput: nums = [3,1,2,5,4,6]\nOutput: 19\n
\n\n

Example 5:

\n\n
\nInput: nums = [9,4,2,1,3,6,5,7,8,14,11,10,12,13,16,15,17,18]\nOutput: 216212978\nExplanation: The number of ways to reorder nums to get the same BST is 3216212999. Taking this number modulo 10^9 + 7 gives 216212978.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 1000
  • \n\t
  • 1 <= nums[i] <= nums.length
  • \n\t
  • All integers in nums are distinct.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 nums \u8868\u793a 1 \u5230 n \u7684\u4e00\u4e2a\u6392\u5217\u3002\u6211\u4eec\u6309\u7167\u5143\u7d20\u5728 nums \u4e2d\u7684\u987a\u5e8f\u4f9d\u6b21\u63d2\u5165\u4e00\u4e2a\u521d\u59cb\u4e3a\u7a7a\u7684\u4e8c\u53c9\u67e5\u627e\u6811\uff08BST\uff09\u3002\u8bf7\u4f60\u7edf\u8ba1\u5c06 nums \u91cd\u65b0\u6392\u5e8f\u540e\uff0c\u7edf\u8ba1\u6ee1\u8db3\u5982\u4e0b\u6761\u4ef6\u7684\u65b9\u6848\u6570\uff1a\u91cd\u6392\u540e\u5f97\u5230\u7684\u4e8c\u53c9\u67e5\u627e\u6811\u4e0e nums \u539f\u672c\u6570\u5b57\u987a\u5e8f\u5f97\u5230\u7684\u4e8c\u53c9\u67e5\u627e\u6811\u76f8\u540c\u3002

\n\n

\u6bd4\u65b9\u8bf4\uff0c\u7ed9\u4f60 nums = [2,1,3]\uff0c\u6211\u4eec\u5f97\u5230\u4e00\u68f5 2 \u4e3a\u6839\uff0c1 \u4e3a\u5de6\u5b69\u5b50\uff0c3 \u4e3a\u53f3\u5b69\u5b50\u7684\u6811\u3002\u6570\u7ec4 [2,3,1] \u4e5f\u80fd\u5f97\u5230\u76f8\u540c\u7684 BST\uff0c\u4f46 [3,2,1] \u4f1a\u5f97\u5230\u4e00\u68f5\u4e0d\u540c\u7684 BST \u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u91cd\u6392 nums \u540e\uff0c\u4e0e\u539f\u6570\u7ec4 nums \u5f97\u5230\u76f8\u540c\u4e8c\u53c9\u67e5\u627e\u6811\u7684\u65b9\u6848\u6570\u3002

\n\n

\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u4f1a\u5f88\u5927\uff0c\u8bf7\u5c06\u7ed3\u679c\u5bf9 10^9 + 7 \u53d6\u4f59\u6570\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1anums = [2,1,3]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u6211\u4eec\u5c06 nums \u91cd\u6392\uff0c [2,3,1] \u80fd\u5f97\u5230\u76f8\u540c\u7684 BST \u3002\u6ca1\u6709\u5176\u4ed6\u5f97\u5230\u76f8\u540c BST \u7684\u65b9\u6848\u4e86\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1anums = [3,4,5,1,2]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u4e0b\u9762 5 \u4e2a\u6570\u7ec4\u4f1a\u5f97\u5230\u76f8\u540c\u7684 BST\uff1a\n[3,1,2,4,5]\n[3,1,4,2,5]\n[3,1,4,5,2]\n[3,4,1,2,5]\n[3,4,1,5,2]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1anums = [1,2,3]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6ca1\u6709\u522b\u7684\u6392\u5217\u987a\u5e8f\u80fd\u5f97\u5230\u76f8\u540c\u7684 BST \u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1anums = [3,1,2,5,4,6]\n\u8f93\u51fa\uff1a19\n
\n\n

\u793a\u4f8b  5\uff1a

\n\n
\u8f93\u5165\uff1anums = [9,4,2,1,3,6,5,7,8,14,11,10,12,13,16,15,17,18]\n\u8f93\u51fa\uff1a216212978\n\u89e3\u91ca\uff1a\u5f97\u5230\u76f8\u540c BST \u7684\u65b9\u6848\u6570\u662f 3216212999\u3002\u5c06\u5b83\u5bf9 10^9 + 7 \u53d6\u4f59\u540e\u5f97\u5230 216212978\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 1000
  • \n\t
  • 1 <= nums[i] <= nums.length
  • \n\t
  • nums \u4e2d\u6240\u6709\u6570 \u4e92\u4e0d\u76f8\u540c \u3002
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numOfWays(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numOfWays(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numOfWays(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numOfWays(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numOfWays(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumOfWays(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar numOfWays = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef num_of_ways(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numOfWays(_ nums: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numOfWays(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numOfWays(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numOfWays(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_of_ways(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function numOfWays($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numOfWays(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-of-ways nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1569](https://leetcode-cn.com/problems/number-of-ways-to-reorder-array-to-get-same-bst)", "[\u5c06\u5b50\u6570\u7ec4\u91cd\u65b0\u6392\u5e8f\u5f97\u5230\u540c\u4e00\u4e2a\u4e8c\u53c9\u67e5\u627e\u6811\u7684\u65b9\u6848\u6570](/solution/1500-1599/1569.Number%20of%20Ways%20to%20Reorder%20Array%20to%20Get%20Same%20BST/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1569](https://leetcode.com/problems/number-of-ways-to-reorder-array-to-get-same-bst)", "[Number of Ways to Reorder Array to Get Same BST](/solution/1500-1599/1569.Number%20of%20Ways%20to%20Reorder%20Array%20to%20Get%20Same%20BST/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1691", "frontend_question_id": "1568", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-number-of-days-to-disconnect-island", "url_en": "https://leetcode.com/problems/minimum-number-of-days-to-disconnect-island", "relative_path_cn": "/solution/1500-1599/1568.Minimum%20Number%20of%20Days%20to%20Disconnect%20Island/README.md", "relative_path_en": "/solution/1500-1599/1568.Minimum%20Number%20of%20Days%20to%20Disconnect%20Island/README_EN.md", "title_cn": "\u4f7f\u9646\u5730\u5206\u79bb\u7684\u6700\u5c11\u5929\u6570", "title_en": "Minimum Number of Days to Disconnect Island", "question_title_slug": "minimum-number-of-days-to-disconnect-island", "content_en": "

Given a 2D grid consisting of 1s (land) and 0s (water).  An island is a maximal 4-directionally (horizontal or vertical) connected group of 1s.

\n\n

The grid is said to be connected if we have exactly one island, otherwise is said disconnected.

\n\n

In one day, we are allowed to change any single land cell (1) into a water cell (0).

\n\n

Return the minimum number of days to disconnect the grid.

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: grid = [[0,1,1,0],[0,1,1,0],[0,0,0,0]]\nOutput: 2\nExplanation: We need at least 2 days to get a disconnected grid.\nChange land grid[1][1] and grid[0][2] to water and get 2 disconnected island.\n
\n\n

Example 2:

\n\n
\nInput: grid = [[1,1]]\nOutput: 2\nExplanation: Grid of full water is also disconnected ([[1,1]] -> [[0,0]]), 0 islands.\n
\n\n

Example 3:

\n\n
\nInput: grid = [[1,0,1,0]]\nOutput: 0\n
\n\n

Example 4:

\n\n
\nInput: grid = [[1,1,0,1,1],\n               [1,1,1,1,1],\n               [1,1,0,1,1],\n               [1,1,0,1,1]]\nOutput: 1\n
\n\n

Example 5:

\n\n
\nInput: grid = [[1,1,0,1,1],\n               [1,1,1,1,1],\n               [1,1,0,1,1],\n               [1,1,1,1,1]]\nOutput: 2\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= grid.length, grid[i].length <= 30
  • \n\t
  • grid[i][j] is 0 or 1.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u7531\u82e5\u5e72 0 \u548c 1 \u7ec4\u6210\u7684\u4e8c\u7ef4\u7f51\u683c grid \uff0c\u5176\u4e2d 0 \u8868\u793a\u6c34\uff0c\u800c 1 \u8868\u793a\u9646\u5730\u3002\u5c9b\u5c7f\u7531\u6c34\u5e73\u65b9\u5411\u6216\u7ad6\u76f4\u65b9\u5411\u4e0a\u76f8\u90bb\u7684 1 \uff08\u9646\u5730\uff09\u8fde\u63a5\u5f62\u6210\u3002

\n\n

\u5982\u679c \u6070\u597d\u53ea\u6709\u4e00\u5ea7\u5c9b\u5c7f \uff0c\u5219\u8ba4\u4e3a\u9646\u5730\u662f \u8fde\u901a\u7684 \uff1b\u5426\u5219\uff0c\u9646\u5730\u5c31\u662f \u5206\u79bb\u7684 \u3002

\n\n

\u4e00\u5929\u5185\uff0c\u53ef\u4ee5\u5c06\u4efb\u4f55\u5355\u4e2a\u9646\u5730\u5355\u5143\uff081\uff09\u66f4\u6539\u4e3a\u6c34\u5355\u5143\uff080\uff09\u3002

\n\n

\u8fd4\u56de\u4f7f\u9646\u5730\u5206\u79bb\u7684\u6700\u5c11\u5929\u6570\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1agrid = [[0,1,1,0],[0,1,1,0],[0,0,0,0]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u81f3\u5c11\u9700\u8981 2 \u5929\u624d\u80fd\u5f97\u5230\u5206\u79bb\u7684\u9646\u5730\u3002\n\u5c06\u9646\u5730 grid[1][1] \u548c grid[0][2] \u66f4\u6539\u4e3a\u6c34\uff0c\u5f97\u5230\u4e24\u4e2a\u5206\u79bb\u7684\u5c9b\u5c7f\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1agrid = [[1,1]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5982\u679c\u7f51\u683c\u4e2d\u90fd\u662f\u6c34\uff0c\u4e5f\u8ba4\u4e3a\u662f\u5206\u79bb\u7684 ([[1,1]] -> [[0,0]])\uff0c0 \u5c9b\u5c7f\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1agrid = [[1,0,1,0]]\n\u8f93\u51fa\uff1a0\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1agrid = [[1,1,0,1,1],\n             [1,1,1,1,1],\n             [1,1,0,1,1],\n             [1,1,0,1,1]]\n\u8f93\u51fa\uff1a1\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1agrid = [[1,1,0,1,1],\n             [1,1,1,1,1],\n             [1,1,0,1,1],\n             [1,1,1,1,1]]\n\u8f93\u51fa\uff1a2\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= grid.length, grid[i].length <= 30
  • \n\t
  • grid[i][j] \u4e3a 0 \u6216 1
  • \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minDays(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minDays(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minDays(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minDays(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minDays(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinDays(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar minDays = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef min_days(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minDays(_ grid: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minDays(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minDays(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minDays(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_days(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function minDays($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minDays(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-days grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1568](https://leetcode-cn.com/problems/minimum-number-of-days-to-disconnect-island)", "[\u4f7f\u9646\u5730\u5206\u79bb\u7684\u6700\u5c11\u5929\u6570](/solution/1500-1599/1568.Minimum%20Number%20of%20Days%20to%20Disconnect%20Island/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[1568](https://leetcode.com/problems/minimum-number-of-days-to-disconnect-island)", "[Minimum Number of Days to Disconnect Island](/solution/1500-1599/1568.Minimum%20Number%20of%20Days%20to%20Disconnect%20Island/README_EN.md)", "`Greedy`", "Hard", ""]}, {"question_id": "1690", "frontend_question_id": "1567", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-length-of-subarray-with-positive-product", "url_en": "https://leetcode.com/problems/maximum-length-of-subarray-with-positive-product", "relative_path_cn": "/solution/1500-1599/1567.Maximum%20Length%20of%20Subarray%20With%20Positive%20Product/README.md", "relative_path_en": "/solution/1500-1599/1567.Maximum%20Length%20of%20Subarray%20With%20Positive%20Product/README_EN.md", "title_cn": "\u4e58\u79ef\u4e3a\u6b63\u6570\u7684\u6700\u957f\u5b50\u6570\u7ec4\u957f\u5ea6", "title_en": "Maximum Length of Subarray With Positive Product", "question_title_slug": "maximum-length-of-subarray-with-positive-product", "content_en": "

Given an array of integers nums, find the maximum length of a subarray where the product of all its elements is positive.

\n\n

A subarray of an array is a consecutive sequence of zero or more values taken out of that array.

\n\n

Return the maximum length of a subarray with positive product.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [1,-2,-3,4]\nOutput: 4\nExplanation: The array nums already has a positive product of 24.\n
\n\n

Example 2:

\n\n
\nInput: nums = [0,1,-2,-3,-4]\nOutput: 3\nExplanation: The longest subarray with positive product is [1,-2,-3] which has a product of 6.\nNotice that we cannot include 0 in the subarray since that'll make the product 0 which is not positive.
\n\n

Example 3:

\n\n
\nInput: nums = [-1,-2,-3,0,1]\nOutput: 2\nExplanation: The longest subarray with positive product is [-1,-2] or [-2,-3].\n
\n\n

Example 4:

\n\n
\nInput: nums = [-1,2]\nOutput: 1\n
\n\n

Example 5:

\n\n
\nInput: nums = [1,2,3,5,-6,4,0,10]\nOutput: 4\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 10^5
  • \n\t
  • -10^9 <= nums[i] <= 10^9
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \uff0c\u8bf7\u4f60\u6c42\u51fa\u4e58\u79ef\u4e3a\u6b63\u6570\u7684\u6700\u957f\u5b50\u6570\u7ec4\u7684\u957f\u5ea6\u3002

\n\n

\u4e00\u4e2a\u6570\u7ec4\u7684\u5b50\u6570\u7ec4\u662f\u7531\u539f\u6570\u7ec4\u4e2d\u96f6\u4e2a\u6216\u8005\u66f4\u591a\u4e2a\u8fde\u7eed\u6570\u5b57\u7ec4\u6210\u7684\u6570\u7ec4\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u4e58\u79ef\u4e3a\u6b63\u6570\u7684\u6700\u957f\u5b50\u6570\u7ec4\u957f\u5ea6\u3002

\n\n

 

\n\n

\u793a\u4f8b  1\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,-2,-3,4]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u6570\u7ec4\u672c\u8eab\u4e58\u79ef\u5c31\u662f\u6b63\u6570\uff0c\u503c\u4e3a 24 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anums = [0,1,-2,-3,-4]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6700\u957f\u4e58\u79ef\u4e3a\u6b63\u6570\u7684\u5b50\u6570\u7ec4\u4e3a [1,-2,-3] \uff0c\u4e58\u79ef\u4e3a 6 \u3002\n\u6ce8\u610f\uff0c\u6211\u4eec\u4e0d\u80fd\u628a 0 \u4e5f\u5305\u62ec\u5230\u5b50\u6570\u7ec4\u4e2d\uff0c\u56e0\u4e3a\u8fd9\u6837\u4e58\u79ef\u4e3a 0 \uff0c\u4e0d\u662f\u6b63\u6570\u3002
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1anums = [-1,-2,-3,0,1]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u4e58\u79ef\u4e3a\u6b63\u6570\u7684\u6700\u957f\u5b50\u6570\u7ec4\u662f [-1,-2] \u6216\u8005 [-2,-3] \u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1anums = [-1,2]\n\u8f93\u51fa\uff1a1\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,2,3,5,-6,4,0,10]\n\u8f93\u51fa\uff1a4\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 10^5
  • \n\t
  • -10^9 <= nums[i] <= 10^9
  • \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int getMaxLen(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int getMaxLen(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getMaxLen(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getMaxLen(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint getMaxLen(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int GetMaxLen(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar getMaxLen = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef get_max_len(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getMaxLen(_ nums: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getMaxLen(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getMaxLen(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getMaxLen(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_max_len(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function getMaxLen($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getMaxLen(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-max-len nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1567](https://leetcode-cn.com/problems/maximum-length-of-subarray-with-positive-product)", "[\u4e58\u79ef\u4e3a\u6b63\u6570\u7684\u6700\u957f\u5b50\u6570\u7ec4\u957f\u5ea6](/solution/1500-1599/1567.Maximum%20Length%20of%20Subarray%20With%20Positive%20Product/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1567](https://leetcode.com/problems/maximum-length-of-subarray-with-positive-product)", "[Maximum Length of Subarray With Positive Product](/solution/1500-1599/1567.Maximum%20Length%20of%20Subarray%20With%20Positive%20Product/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1689", "frontend_question_id": "1566", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/detect-pattern-of-length-m-repeated-k-or-more-times", "url_en": "https://leetcode.com/problems/detect-pattern-of-length-m-repeated-k-or-more-times", "relative_path_cn": "/solution/1500-1599/1566.Detect%20Pattern%20of%20Length%20M%20Repeated%20K%20or%20More%20Times/README.md", "relative_path_en": "/solution/1500-1599/1566.Detect%20Pattern%20of%20Length%20M%20Repeated%20K%20or%20More%20Times/README_EN.md", "title_cn": "\u91cd\u590d\u81f3\u5c11 K \u6b21\u4e14\u957f\u5ea6\u4e3a M \u7684\u6a21\u5f0f", "title_en": "Detect Pattern of Length M Repeated K or More Times", "question_title_slug": "detect-pattern-of-length-m-repeated-k-or-more-times", "content_en": "

Given an array of positive integers arr,  find a pattern of length m that is repeated k or more times.

\n\n

A pattern is a subarray (consecutive sub-sequence) that consists of one or more values, repeated multiple times consecutively without overlapping. A pattern is defined by its length and the number of repetitions.

\n\n

Return true if there exists a pattern of length m that is repeated k or more times, otherwise return false.

\n\n

 

\n

Example 1:

\n\n
\nInput: arr = [1,2,4,4,4,4], m = 1, k = 3\nOutput: true\nExplanation: The pattern (4) of length 1 is repeated 4 consecutive times. Notice that pattern can be repeated k or more times but not less.\n
\n\n

Example 2:

\n\n
\nInput: arr = [1,2,1,2,1,1,1,3], m = 2, k = 2\nOutput: true\nExplanation: The pattern (1,2) of length 2 is repeated 2 consecutive times. Another valid pattern (2,1) is also repeated 2 times.\n
\n\n

Example 3:

\n\n
\nInput: arr = [1,2,1,2,1,3], m = 2, k = 3\nOutput: false\nExplanation: The pattern (1,2) is of length 2 but is repeated only 2 times. There is no pattern of length 2 that is repeated 3 or more times.\n
\n\n

Example 4:

\n\n
\nInput: arr = [1,2,3,1,2], m = 2, k = 2\nOutput: false\nExplanation: Notice that the pattern (1,2) exists twice but not consecutively, so it doesn't count.\n
\n\n

Example 5:

\n\n
\nInput: arr = [2,2,2,2], m = 2, k = 3\nOutput: false\nExplanation: The only pattern of length 2 is (2,2) however it's repeated only twice. Notice that we do not count overlapping repetitions.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= arr.length <= 100
  • \n\t
  • 1 <= arr[i] <= 100
  • \n\t
  • 1 <= m <= 100
  • \n\t
  • 2 <= k <= 100
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6b63\u6574\u6570\u6570\u7ec4 arr\uff0c\u8bf7\u4f60\u627e\u51fa\u4e00\u4e2a\u957f\u5ea6\u4e3a m \u4e14\u5728\u6570\u7ec4\u4e2d\u81f3\u5c11\u91cd\u590d k \u6b21\u7684\u6a21\u5f0f\u3002

\n\n

\u6a21\u5f0f \u662f\u7531\u4e00\u4e2a\u6216\u591a\u4e2a\u503c\u7ec4\u6210\u7684\u5b50\u6570\u7ec4\uff08\u8fde\u7eed\u7684\u5b50\u5e8f\u5217\uff09\uff0c\u8fde\u7eed \u91cd\u590d\u591a\u6b21\u4f46 \u4e0d\u91cd\u53e0 \u3002 \u6a21\u5f0f\u7531\u5176\u957f\u5ea6\u548c\u91cd\u590d\u6b21\u6570\u5b9a\u4e49\u3002

\n\n

\u5982\u679c\u6570\u7ec4\u4e2d\u5b58\u5728\u81f3\u5c11\u91cd\u590d k \u6b21\u4e14\u957f\u5ea6\u4e3a m \u7684\u6a21\u5f0f\uff0c\u5219\u8fd4\u56de true \uff0c\u5426\u5219\u8fd4\u56de  false \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aarr = [1,2,4,4,4,4], m = 1, k = 3\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u6a21\u5f0f (4) \u7684\u957f\u5ea6\u4e3a 1 \uff0c\u4e14\u8fde\u7eed\u91cd\u590d 4 \u6b21\u3002\u6ce8\u610f\uff0c\u6a21\u5f0f\u53ef\u4ee5\u91cd\u590d k \u6b21\u6216\u66f4\u591a\u6b21\uff0c\u4f46\u4e0d\u80fd\u5c11\u4e8e k \u6b21\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aarr = [1,2,1,2,1,1,1,3], m = 2, k = 2\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u6a21\u5f0f (1,2) \u957f\u5ea6\u4e3a 2 \uff0c\u4e14\u8fde\u7eed\u91cd\u590d 2 \u6b21\u3002\u53e6\u4e00\u4e2a\u7b26\u5408\u9898\u610f\u7684\u6a21\u5f0f\u662f (2,1) \uff0c\u540c\u6837\u91cd\u590d 2 \u6b21\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aarr = [1,2,1,2,1,3], m = 2, k = 3\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u6a21\u5f0f (1,2) \u957f\u5ea6\u4e3a 2 \uff0c\u4f46\u662f\u53ea\u8fde\u7eed\u91cd\u590d 2 \u6b21\u3002\u4e0d\u5b58\u5728\u957f\u5ea6\u4e3a 2 \u4e14\u81f3\u5c11\u91cd\u590d 3 \u6b21\u7684\u6a21\u5f0f\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1aarr = [1,2,3,1,2], m = 2, k = 2\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u6a21\u5f0f (1,2) \u51fa\u73b0 2 \u6b21\u4f46\u5e76\u4e0d\u8fde\u7eed\uff0c\u6240\u4ee5\u4e0d\u80fd\u7b97\u4f5c\u8fde\u7eed\u91cd\u590d 2 \u6b21\u3002\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1aarr = [2,2,2,2], m = 2, k = 3\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u957f\u5ea6\u4e3a 2 \u7684\u6a21\u5f0f\u53ea\u6709 (2,2) \uff0c\u4f46\u662f\u53ea\u8fde\u7eed\u91cd\u590d 2 \u6b21\u3002\u6ce8\u610f\uff0c\u4e0d\u80fd\u8ba1\u7b97\u91cd\u53e0\u7684\u91cd\u590d\u6b21\u6570\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= arr.length <= 100
  • \n\t
  • 1 <= arr[i] <= 100
  • \n\t
  • 1 <= m <= 100
  • \n\t
  • 2 <= k <= 100
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool containsPattern(vector& arr, int m, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean containsPattern(int[] arr, int m, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def containsPattern(self, arr, m, k):\n \"\"\"\n :type arr: List[int]\n :type m: int\n :type k: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def containsPattern(self, arr: List[int], m: int, k: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool containsPattern(int* arr, int arrSize, int m, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool ContainsPattern(int[] arr, int m, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @param {number} m\n * @param {number} k\n * @return {boolean}\n */\nvar containsPattern = function(arr, m, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @param {Integer} m\n# @param {Integer} k\n# @return {Boolean}\ndef contains_pattern(arr, m, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func containsPattern(_ arr: [Int], _ m: Int, _ k: Int) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func containsPattern(arr []int, m int, k int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def containsPattern(arr: Array[Int], m: Int, k: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun containsPattern(arr: IntArray, m: Int, k: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn contains_pattern(arr: Vec, m: i32, k: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @param Integer $m\n * @param Integer $k\n * @return Boolean\n */\n function containsPattern($arr, $m, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function containsPattern(arr: number[], m: number, k: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (contains-pattern arr m k)\n (-> (listof exact-integer?) exact-integer? exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1566](https://leetcode-cn.com/problems/detect-pattern-of-length-m-repeated-k-or-more-times)", "[\u91cd\u590d\u81f3\u5c11 K \u6b21\u4e14\u957f\u5ea6\u4e3a M \u7684\u6a21\u5f0f](/solution/1500-1599/1566.Detect%20Pattern%20of%20Length%20M%20Repeated%20K%20or%20More%20Times/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1566](https://leetcode.com/problems/detect-pattern-of-length-m-repeated-k-or-more-times)", "[Detect Pattern of Length M Repeated K or More Times](/solution/1500-1599/1566.Detect%20Pattern%20of%20Length%20M%20Repeated%20K%20or%20More%20Times/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1688", "frontend_question_id": "1549", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/the-most-recent-orders-for-each-product", "url_en": "https://leetcode.com/problems/the-most-recent-orders-for-each-product", "relative_path_cn": "/solution/1500-1599/1549.The%20Most%20Recent%20Orders%20for%20Each%20Product/README.md", "relative_path_en": "/solution/1500-1599/1549.The%20Most%20Recent%20Orders%20for%20Each%20Product/README_EN.md", "title_cn": "\u6bcf\u4ef6\u5546\u54c1\u7684\u6700\u65b0\u8ba2\u5355", "title_en": "The Most Recent Orders for Each Product", "question_title_slug": "the-most-recent-orders-for-each-product", "content_en": "

Table: Customers

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| customer_id   | int     |\n| name          | varchar |\n+---------------+---------+\ncustomer_id is the primary key for this table.\nThis table contains information about the customers.\n
\n\n

 

\n\n

Table: Orders

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| order_id      | int     |\n| order_date    | date    |\n| customer_id   | int     |\n| product_id    | int     |\n+---------------+---------+\norder_id is the primary key for this table.\nThis table contains information about the orders made by customer_id.\nThere will be no product ordered by the same user more than once in one day.
\n\n

 

\n\n

Table: Products

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| product_id    | int     |\n| product_name  | varchar |\n| price         | int     |\n+---------------+---------+\nproduct_id is the primary key for this table.\nThis table contains information about the Products.\n
\n\n

 

\n\n

Write an SQL query to find the most recent order(s) of each product.

\n\n

Return the result table sorted by product_name in ascending order and in case of a tie by the product_id in ascending order. If there still a tie, order them by the order_id in ascending order.

\n\n

The query result format is in the following example:

\n\n
\nCustomers\n+-------------+-----------+\n| customer_id | name      |\n+-------------+-----------+\n| 1           | Winston   |\n| 2           | Jonathan  |\n| 3           | Annabelle |\n| 4           | Marwan    |\n| 5           | Khaled    |\n+-------------+-----------+\n\nOrders\n+----------+------------+-------------+------------+\n| order_id | order_date | customer_id | product_id |\n+----------+------------+-------------+------------+\n| 1        | 2020-07-31 | 1           | 1          |\n| 2        | 2020-07-30 | 2           | 2          |\n| 3        | 2020-08-29 | 3           | 3          |\n| 4        | 2020-07-29 | 4           | 1          |\n| 5        | 2020-06-10 | 1           | 2          |\n| 6        | 2020-08-01 | 2           | 1          |\n| 7        | 2020-08-01 | 3           | 1          |\n| 8        | 2020-08-03 | 1           | 2          |\n| 9        | 2020-08-07 | 2           | 3          |\n| 10       | 2020-07-15 | 1           | 2          |\n+----------+------------+-------------+------------+\n\nProducts\n+------------+--------------+-------+\n| product_id | product_name | price |\n+------------+--------------+-------+\n| 1          | keyboard     | 120   |\n| 2          | mouse        | 80    |\n| 3          | screen       | 600   |\n| 4          | hard disk    | 450   |\n+------------+--------------+-------+\n\nResult table:\n+--------------+------------+----------+------------+\n| product_name | product_id | order_id | order_date |\n+--------------+------------+----------+------------+\n| keyboard     | 1          | 6        | 2020-08-01 |\n| keyboard     | 1          | 7        | 2020-08-01 |\n| mouse        | 2          | 8        | 2020-08-03 |\n| screen       | 3          | 3        | 2020-08-29 |\n+--------------+------------+----------+------------+\nkeyboard's most recent order is in 2020-08-01, it was ordered two times this day.\nmouse's most recent order is in 2020-08-03, it was ordered only once this day.\nscreen's most recent order is in 2020-08-29, it was ordered only once this day.\nThe hard disk was never ordered and we don't include it in the result table.\n
\n", "content_cn": "

\u8868: Customers

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| customer_id   | int     |\n| name          | varchar |\n+---------------+---------+\ncustomer_id \u662f\u8be5\u8868\u4e3b\u952e.\n\u8be5\u8868\u5305\u542b\u6d88\u8d39\u8005\u7684\u4fe1\u606f.\n
\n\n

 

\n\n

\u8868: Orders

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| order_id      | int     |\n| order_date    | date    |\n| customer_id   | int     |\n| product_id    | int     |\n+---------------+---------+\norder_id \u662f\u8be5\u8868\u4e3b\u952e.\n\u8be5\u8868\u5305\u542b\u6d88\u8d39\u8005customer_id\u4ea7\u751f\u7684\u8ba2\u5355.\n\u4e0d\u4f1a\u6709\u5546\u54c1\u88ab\u76f8\u540c\u7684\u7528\u6237\u5728\u4e00\u5929\u5185\u4e0b\u5355\u8d85\u8fc7\u4e00\u6b21.
\n\n

 

\n\n

\u8868: Products

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| product_id    | int     |\n| product_name  | varchar |\n| price         | int     |\n+---------------+---------+\nproduct_id \u662f\u8be5\u8868\u4e3b\u952e.\n\u8be5\u8868\u5305\u542b\u6240\u6709\u5546\u54c1\u7684\u4fe1\u606f.\n
\n\n

 

\n\n

\u5199\u4e00\u4e2aSQL \u8bed\u53e5, \u627e\u5230\u6bcf\u4ef6\u5546\u54c1\u7684\u6700\u65b0\u8ba2\u5355(\u53ef\u80fd\u6709\u591a\u4e2a).

\n\n

\u8fd4\u56de\u7684\u7ed3\u679c\u4ee5 product_name \u5347\u5e8f\u6392\u5217, \u5982\u679c\u6709\u6392\u5e8f\u76f8\u540c, \u518d\u4ee5 product_id \u5347\u5e8f\u6392\u5217. \u5982\u679c\u8fd8\u6709\u6392\u5e8f\u76f8\u540c, \u518d\u4ee5 order_id \u5347\u5e8f\u6392\u5217.

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a:

\n\n
\nCustomers\n+-------------+-----------+\n| customer_id | name      |\n+-------------+-----------+\n| 1           | Winston   |\n| 2           | Jonathan  |\n| 3           | Annabelle |\n| 4           | Marwan    |\n| 5           | Khaled    |\n+-------------+-----------+\n\nOrders\n+----------+------------+-------------+------------+\n| order_id | order_date | customer_id | product_id |\n+----------+------------+-------------+------------+\n| 1        | 2020-07-31 | 1           | 1          |\n| 2        | 2020-07-30 | 2           | 2          |\n| 3        | 2020-08-29 | 3           | 3          |\n| 4        | 2020-07-29 | 4           | 1          |\n| 5        | 2020-06-10 | 1           | 2          |\n| 6        | 2020-08-01 | 2           | 1          |\n| 7        | 2020-08-01 | 3           | 1          |\n| 8        | 2020-08-03 | 1           | 2          |\n| 9        | 2020-08-07 | 2           | 3          |\n| 10       | 2020-07-15 | 1           | 2          |\n+----------+------------+-------------+------------+\n\nProducts\n+------------+--------------+-------+\n| product_id | product_name | price |\n+------------+--------------+-------+\n| 1          | keyboard     | 120   |\n| 2          | mouse        | 80    |\n| 3          | screen       | 600   |\n| 4          | hard disk    | 450   |\n+------------+--------------+-------+\n\nResult\n+--------------+------------+----------+------------+\n| product_name | product_id | order_id | order_date |\n+--------------+------------+----------+------------+\n| keyboard     | 1          | 6        | 2020-08-01 |\n| keyboard     | 1          | 7        | 2020-08-01 |\n| mouse        | 2          | 8        | 2020-08-03 |\n| screen       | 3          | 3        | 2020-08-29 |\n+--------------+------------+----------+------------+\nkeyboard \u7684\u6700\u65b0\u8ba2\u5355\u57282020-08-01, \u5728\u8fd9\u5929\u6709\u4e24\u6b21\u4e0b\u5355.\nmouse \u7684\u6700\u65b0\u8ba2\u5355\u57282020-08-03, \u5728\u8fd9\u5929\u53ea\u6709\u4e00\u6b21\u4e0b\u5355.\nscreen \u7684\u6700\u65b0\u8ba2\u5355\u57282020-08-29, \u5728\u8fd9\u5929\u53ea\u6709\u4e00\u6b21\u4e0b\u5355.\nhard disk \u6ca1\u6709\u88ab\u4e0b\u5355, \u6211\u4eec\u4e0d\u628a\u5b83\u5305\u542b\u5728\u7ed3\u679c\u8868\u4e2d.\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1549](https://leetcode-cn.com/problems/the-most-recent-orders-for-each-product)", "[\u6bcf\u4ef6\u5546\u54c1\u7684\u6700\u65b0\u8ba2\u5355](/solution/1500-1599/1549.The%20Most%20Recent%20Orders%20for%20Each%20Product/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1549](https://leetcode.com/problems/the-most-recent-orders-for-each-product)", "[The Most Recent Orders for Each Product](/solution/1500-1599/1549.The%20Most%20Recent%20Orders%20for%20Each%20Product/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1687", "frontend_question_id": "1548", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/the-most-similar-path-in-a-graph", "url_en": "https://leetcode.com/problems/the-most-similar-path-in-a-graph", "relative_path_cn": "/solution/1500-1599/1548.The%20Most%20Similar%20Path%20in%20a%20Graph/README.md", "relative_path_en": "/solution/1500-1599/1548.The%20Most%20Similar%20Path%20in%20a%20Graph/README_EN.md", "title_cn": "\u56fe\u4e2d\u6700\u76f8\u4f3c\u7684\u8def\u5f84", "title_en": "The Most Similar Path in a Graph", "question_title_slug": "the-most-similar-path-in-a-graph", "content_en": "

We have n cities and m bi-directional roads where roads[i] = [ai, bi] connects city ai with city bi. Each city has a name consisting of exactly 3 upper-case English letters given in the string array names. Starting at any city x, you can reach any city y where y != x (i.e. the cities and the roads are forming an undirected connected graph).

\n\n

You will be given a string array targetPath. You should find a path in the graph of the same length and with the minimum edit distance to targetPath.

\n\n

You need to return the order of the nodes in the path with the minimum edit distance, The path should be of the same length of targetPath and should be valid (i.e. there should be a direct road between ans[i] and ans[i + 1]). If there are multiple answers return any one of them.

\n\n

The edit distance is defined as follows:

\n\n

\"\"

\n\n

Follow-up: If each node can be visited only once in the path, What should you change in your solution?

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: n = 5, roads = [[0,2],[0,3],[1,2],[1,3],[1,4],[2,4]], names = ["ATL","PEK","LAX","DXB","HND"], targetPath = ["ATL","DXB","HND","LAX"]\nOutput: [0,2,4,2]\nExplanation: [0,2,4,2], [0,3,0,2] and [0,3,1,2] are accepted answers.\n[0,2,4,2] is equivalent to ["ATL","LAX","HND","LAX"] which has edit distance = 1 with targetPath.\n[0,3,0,2] is equivalent to ["ATL","DXB","ATL","LAX"] which has edit distance = 1 with targetPath.\n[0,3,1,2] is equivalent to ["ATL","DXB","PEK","LAX"] which has edit distance = 1 with targetPath.\n
\n\n

Example 2:

\n\"\"\n
\nInput: n = 4, roads = [[1,0],[2,0],[3,0],[2,1],[3,1],[3,2]], names = ["ATL","PEK","LAX","DXB"], targetPath = ["ABC","DEF","GHI","JKL","MNO","PQR","STU","VWX"]\nOutput: [0,1,0,1,0,1,0,1]\nExplanation: Any path in this graph has edit distance = 8 with targetPath.\n
\n\n

Example 3:

\n\n

\"\"

\n\n
\nInput: n = 6, roads = [[0,1],[1,2],[2,3],[3,4],[4,5]], names = ["ATL","PEK","LAX","ATL","DXB","HND"], targetPath = ["ATL","DXB","HND","DXB","ATL","LAX","PEK"]\nOutput: [3,4,5,4,3,2,1]\nExplanation: [3,4,5,4,3,2,1] is the only path with edit distance = 0 with targetPath.\nIt's equivalent to ["ATL","DXB","HND","DXB","ATL","LAX","PEK"]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= n <= 100
  • \n\t
  • m == roads.length
  • \n\t
  • n - 1 <= m <= (n * (n - 1) / 2)
  • \n\t
  • 0 <= ai, bi <= n - 1
  • \n\t
  • ai != bi 
  • \n\t
  • The graph is guaranteed to be connected and each pair of nodes may have at most one direct road.
  • \n\t
  • names.length == n
  • \n\t
  • names[i].length == 3
  • \n\t
  • names[i] consists of upper-case English letters.
  • \n\t
  • There can be two cities with the same name.
  • \n\t
  • 1 <= targetPath.length <= 100
  • \n\t
  • targetPath[i].length == 3
  • \n\t
  • targetPath[i] consists of upper-case English letters.
  • \n
\n", "content_cn": "

\u6211\u4eec\u6709\u00a0n\u00a0\u5ea7\u57ce\u5e02\u548c\u00a0m\u00a0\u6761\u53cc\u5411\u9053\u8def\u00a0roads\u00a0\uff0c\u5176\u4e2d\u00a0roads[i] = [ai, bi]\u00a0\u8fde\u63a5\u57ce\u5e02\u00a0ai\u00a0\u548c\u57ce\u5e02\u00a0bi\u3002\u6bcf\u4e2a\u57ce\u5e02\u6709\u4e00\u4e2a\u6b63\u597d 3 \u4e2a\u5927\u5199\u5b57\u6bcd\u7684\u540d\u5b57\uff0c\u5728\u6570\u7ec4\u00a0names\u4e2d\u7ed9\u51fa\u3002\u4ece\u4efb\u610f\u57ce\u5e02\u00a0x\u00a0\u51fa\u53d1\uff0c\u4f60\u53ef\u4ee5\u5230\u8fbe\u4efb\u610f\u57ce\u5e02\u00a0y \uff0c\u5176\u4e2d\u00a0y != x\u00a0\uff08\u5373\uff1a\u57ce\u5e02\u548c\u9053\u8def\u5f62\u6210\u4e00\u5f20\u65e0\u5411\u8fde\u901a\u56fe\uff09\u3002

\n\n

\u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4\u00a0targetPath\uff0c\u4f60\u9700\u8981\u627e\u51fa\u56fe\u4e2d\u4e0e\u00a0targetPath\u00a0\u7684 \u957f\u5ea6\u76f8\u540c \u4e14 \u7f16\u8f91\u8ddd\u79bb\u6700\u5c0f \u7684\u8def\u5f84\u3002

\n\n

\u4f60\u9700\u8981\u8fd4\u56de \u7f16\u8f91\u8ddd\u79bb\u6700\u5c0f\u7684\u8def\u5f84\u4e2d\u8282\u70b9\u7684\u987a\u5e8f \u3002\u8be5\u8def\u5f84\u5e94\u5f53\u4e0e\u00a0targetPath\u00a0\u7684\u957f\u5ea6\u76f8\u7b49\uff0c\u4e14\u8def\u5f84\u9700\u6709\u6548\uff08\u5373\uff1a\u00a0ans[i]\u00a0\u548c\u00a0ans[i + 1]\u00a0\u95f4\u5e94\u5b58\u5728\u76f4\u63a5\u8fde\u901a\u7684\u9053\u8def\uff09\u3002\u5982\u679c\u6709\u591a\u4e2a\u7b54\u6848\uff0c\u8fd4\u56de\u4efb\u610f\u4e00\u4e2a\u3002

\n\n

\u7f16\u8f91\u8ddd\u79bb \u7684\u5b9a\u4e49\u5982\u4e0b\uff1a

\n\n
\ndefine editDistance(targetPath, myPath) {\n    dis := 0\n    a := targetPath.length\n    b := myPath.length\n    if a != b {\n        return 1000000000\n    }\n    for (i := 0; i < a; i += 1) {\n        if targetPath[i] != myPath[i] {\n            dis += 1\n        }\n    }\n    return dis\n}\n
\n\n

\u00a0

\n\n

\u8fdb\u9636\uff1a\u5982\u679c\u8def\u5f84\u4e2d\u6bcf\u4e2a\u8282\u70b9\u53ea\u53ef\u8bbf\u95ee\u4e00\u6b21\uff0c\u4f60\u8be5\u5982\u4f55\u4fee\u6539\u4f60\u7684\u7b54\u6848\uff1f

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1an = 5, roads = [[0,2],[0,3],[1,2],[1,3],[1,4],[2,4]], names = [\"ATL\",\"PEK\",\"LAX\",\"DXB\",\"HND\"], targetPath = [\"ATL\",\"DXB\",\"HND\",\"LAX\"]\n\u8f93\u51fa\uff1a[0,2,4,2]\n\u89e3\u91ca\uff1a[0,2,4,2], [0,3,0,2] \u548c [0,3,1,2] \u90fd\u662f\u6b63\u786e\u7b54\u6848\u3002\n[0,2,4,2] \u7b49\u4ef7\u4e8e [\"ATL\",\"LAX\",\"HND\",\"LAX\"] \uff0c\u4e0e targetPath \u7684\u7f16\u8f91\u8ddd\u79bb = 1\u3002\n[0,3,0,2] \u7b49\u4ef7\u4e8e [\"ATL\",\"DXB\",\"ATL\",\"LAX\"] \uff0c\u4e0e targetPath \u7684\u7f16\u8f91\u8ddd\u79bb = 1\u3002\n[0,3,1,2] \u7b49\u4ef7\u4e8e [\"ATL\",\"DXB\",\"PEK\",\"LAX\"] \uff0c\u4e0e targetPath \u7684\u7f16\u8f91\u8ddd\u79bb = 1\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1an = 4, roads = [[1,0],[2,0],[3,0],[2,1],[3,1],[3,2]], names = [\"ATL\",\"PEK\",\"LAX\",\"DXB\"], targetPath = [\"ABC\",\"DEF\",\"GHI\",\"JKL\",\"MNO\",\"PQR\",\"STU\",\"VWX\"]\n\u8f93\u51fa\uff1a[0,1,0,1,0,1,0,1]\n\u89e3\u91ca\uff1a\u4efb\u610f\u8def\u5f84\u4e0e targetPath \u7684\u7f16\u8f91\u8ddd\u79bb\u90fd\u7b49\u4e8e 8\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1an = 6, roads = [[0,1],[1,2],[2,3],[3,4],[4,5]], names = [\"ATL\",\"PEK\",\"LAX\",\"ATL\",\"DXB\",\"HND\"], targetPath = [\"ATL\",\"DXB\",\"HND\",\"DXB\",\"ATL\",\"LAX\",\"PEK\"]\n\u8f93\u51fa\uff1a[3,4,5,4,3,2,1]\n\u89e3\u91ca\uff1a[3,4,5,4,3,2,1] \u662f\u552f\u4e00\u4e0e targetPath \u7684\u7f16\u8f91\u8ddd\u79bb = 0 \u7684\u8def\u5f84\u3002\n\u8be5\u8def\u5f84\u7b49\u4ef7\u4e8e [\"ATL\",\"DXB\",\"HND\",\"DXB\",\"ATL\",\"LAX\",\"PEK\"]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= n <= 100
  • \n\t
  • m == roads.length
  • \n\t
  • n - 1 <= m <= (n * (n - 1) / 2)
  • \n\t
  • 0 <= ai, bi <= n - 1
  • \n\t
  • ai != bi\u00a0
  • \n\t
  • \u7ed9\u5b9a\u7684\u56fe\u4fdd\u8bc1\u662f\u8fde\u901a\u7684\uff0c\u4efb\u610f\u4e24\u4e2a\u8282\u70b9\u81f3\u591a\u6709\u4e00\u4e2a\u76f4\u63a5\u8fde\u901a\u7684\u9053\u8def\u3002
  • \n\t
  • names.length == n
  • \n\t
  • names[i].length == 3
  • \n\t
  • names[i]\u00a0\u5305\u542b\u5927\u5199\u82f1\u6587\u5b57\u6bcd\u3002
  • \n\t
  • \u53ef\u80fd\u6709\u4e24\u4e2a\u540d\u79f0\u76f8\u540c\u7684\u57ce\u5e02\u3002
  • \n\t
  • 1 <= targetPath.length <= 100
  • \n\t
  • targetPath[i].length == 3
  • \n\t
  • targetPath[i] \u7531\u5927\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\u3002
  • \n
\n", "tags_en": ["Graph", "Dynamic Programming"], "tags_cn": ["\u56fe", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector mostSimilar(int n, vector>& roads, vector& names, vector& targetPath) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List mostSimilar(int n, int[][] roads, String[] names, String[] targetPath) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def mostSimilar(self, n, roads, names, targetPath):\n \"\"\"\n :type n: int\n :type roads: List[List[int]]\n :type names: List[str]\n :type targetPath: List[str]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def mostSimilar(self, n: int, roads: List[List[int]], names: List[str], targetPath: List[str]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* mostSimilar(int n, int** roads, int roadsSize, int* roadsColSize, char ** names, int namesSize, char ** targetPath, int targetPathSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList MostSimilar(int n, int[][] roads, string[] names, string[] targetPath) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} roads\n * @param {string[]} names\n * @param {string[]} targetPath\n * @return {number[]}\n */\nvar mostSimilar = function(n, roads, names, targetPath) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} roads\n# @param {String[]} names\n# @param {String[]} target_path\n# @return {Integer[]}\ndef most_similar(n, roads, names, target_path)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func mostSimilar(_ n: Int, _ roads: [[Int]], _ names: [String], _ targetPath: [String]) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func mostSimilar(n int, roads [][]int, names []string, targetPath []string) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def mostSimilar(n: Int, roads: Array[Array[Int]], names: Array[String], targetPath: Array[String]): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun mostSimilar(n: Int, roads: Array, names: Array, targetPath: Array): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn most_similar(n: i32, roads: Vec>, names: Vec, target_path: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $roads\n * @param String[] $names\n * @param String[] $targetPath\n * @return Integer[]\n */\n function mostSimilar($n, $roads, $names, $targetPath) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function mostSimilar(n: number, roads: number[][], names: string[], targetPath: string[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (most-similar n roads names targetPath)\n (-> exact-integer? (listof (listof exact-integer?)) (listof string?) (listof string?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1548](https://leetcode-cn.com/problems/the-most-similar-path-in-a-graph)", "[\u56fe\u4e2d\u6700\u76f8\u4f3c\u7684\u8def\u5f84](/solution/1500-1599/1548.The%20Most%20Similar%20Path%20in%20a%20Graph/README.md)", "`\u56fe`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1548](https://leetcode.com/problems/the-most-similar-path-in-a-graph)", "[The Most Similar Path in a Graph](/solution/1500-1599/1548.The%20Most%20Similar%20Path%20in%20a%20Graph/README_EN.md)", "`Graph`,`Dynamic Programming`", "Hard", "\ud83d\udd12"]}, {"question_id": "1686", "frontend_question_id": "1543", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/fix-product-name-format", "url_en": "https://leetcode.com/problems/fix-product-name-format", "relative_path_cn": "/solution/1500-1599/1543.Fix%20Product%20Name%20Format/README.md", "relative_path_en": "/solution/1500-1599/1543.Fix%20Product%20Name%20Format/README_EN.md", "title_cn": "\u4ea7\u54c1\u540d\u79f0\u683c\u5f0f\u4fee\u590d", "title_en": "Fix Product Name Format", "question_title_slug": "fix-product-name-format", "content_en": "

Table: Sales

\n\n
\n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| sale_id      | int     |\n| product_name | varchar |\n| sale_date    | date    |\n+--------------+---------+\nsale_id is the primary key for this table.\nEach row of this table contains the product name and the date it was sold.\n
\n\n

 

\n\n

Since table Sales was filled manually in the year 2000, product_name may contain leading and/or trailing white spaces, also they are case-insensitive.

\n\n

Write an SQL query to report

\n\n
    \n\t
  • product_name in lowercase without leading or trailing white spaces.
  • \n\t
  • sale_date in the format ('YYYY-MM').
  • \n\t
  • total the number of times the product was sold in this month.
  • \n
\n\n

Return the result table ordered by product_name in ascending order. In case of a tie, order it by sale_date in ascending order.

\n\n

The query result format is in the following example.

\n\n

 

\n\n
\nSales\n+---------+--------------+------------+\n| sale_id | product_name | sale_date  |\n+---------+--------------+------------+\n| 1       | LCPHONE      | 2000-01-16 |\n| 2       | LCPhone      | 2000-01-17 |\n| 3       | LcPhOnE      | 2000-02-18 |\n| 4       | LCKeyCHAiN   | 2000-02-19 |\n| 5       | LCKeyChain   | 2000-02-28 |\n| 6       | Matryoshka   | 2000-03-31 |\n+---------+--------------+------------+\n\nResult table:\n+--------------+-----------+-------+\n| product_name | sale_date | total |\n+--------------+-----------+-------+\n| lckeychain   | 2000-02   | 2     |\n| lcphone      | 2000-01   | 2     |\n| lcphone      | 2000-02   | 1     |\n| matryoshka   | 2000-03   | 1     |\n+--------------+-----------+-------+\nIn January, 2 LcPhones were sold, please note that the product names are not case sensitive and may contain spaces.\nIn Februery, 2 LCKeychains and 1 LCPhone were sold.\nIn March, 1 matryoshka was sold.\n
\n", "content_cn": "

\u8868\uff1aSales

\n\n
\n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| sale_id      | int     |\n| product_name | varchar |\n| sale_date    | date    |\n+--------------+---------+\nsale_id \u662f\u8be5\u8868\u4e3b\u952e\n\u8be5\u8868\u7684\u6bcf\u4e00\u884c\u5305\u542b\u4e86\u4ea7\u54c1\u7684\u540d\u79f0\u53ca\u5176\u9500\u552e\u65e5\u671f\n
\n\n

\u56e0\u4e3a\u5728 2000 \u5e74\u8be5\u8868\u662f\u624b\u5de5\u586b\u5199\u7684\uff0cproduct_name\u00a0\u53ef\u80fd\u5305\u542b\u524d\u540e\u7a7a\u683c\uff0c\u800c\u4e14\u5305\u542b\u5927\u5c0f\u5199\u3002

\n\n

\u5199\u4e00\u4e2a SQL \u8bed\u53e5\u62a5\u544a\u6bcf\u4e2a\u6708\u7684\u9500\u552e\u60c5\u51b5\uff1a

\n\n
    \n\t
  • product_name\u00a0\u662f\u5c0f\u5199\u5b57\u6bcd\u4e14\u4e0d\u5305\u542b\u524d\u540e\u7a7a\u683c
  • \n\t
  • sale_date\u00a0\u683c\u5f0f\u4e3a\u00a0('YYYY-MM')\u00a0
  • \n\t
  • total\u00a0\u662f\u4ea7\u54c1\u5728\u672c\u6708\u9500\u552e\u7684\u6b21\u6570
  • \n
\n\n

\u8fd4\u56de\u7ed3\u679c\u4ee5\u00a0product_name\u00a0\u5347\u5e8f \u6392\u5217\uff0c\u5982\u679c\u6709\u6392\u540d\u76f8\u540c\uff0c\u518d\u4ee5\u00a0sale_date \u5347\u5e8f \u6392\u5217\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u6240\u793a\uff1a

\n\n
\nSales \u8868\uff1a\n+------------+------------------+--------------+\n| sale_id    | product_name     | sale_date    |\n+------------+------------------+--------------+\n| 1          |      LCPHONE     | 2000-01-16   |\n| 2    \u00a0     |    LCPhone       | 2000-01-17   |\n| 3    \u00a0     |     LcPhOnE     \u00a0| 2000-02-18   |\n| 4 \u00a0        |      LCKeyCHAiN  | 2000-02-19   |\n| 5 \u00a0        |   LCKeyChain     | 2000-02-28   |\n| 6        \u00a0 | Matryoshka     \u00a0 | 2000-03-31   | \n+------------+------------------+--------------+\n\nResult \u8868\uff1a\n+--------------+--------------+----------+\n| product_name | sale_date    | total    |\n+--------------+--------------+----------+\n| lcphone   \u00a0  | 2000-01     \u00a0| 2       \u00a0|\n| lckeychain   | 2000-02  \u00a0   | 2       \u00a0| \n| lcphone      | 2000-02    \u00a0 | 1       \u00a0| \n| matryoshka   | 2000-03 \u00a0    | 1       \u00a0| \n+--------------+--------------+----------+\n\n1 \u6708\u4efd\uff0c\u5356\u4e86 2 \u4e2a LcPhones\uff0c\u8bf7\u6ce8\u610f\u4ea7\u54c1\u540d\u79f0\u662f\u5c0f\u5199\u7684\uff0c\u4e2d\u95f4\u53ef\u80fd\u5305\u542b\u7a7a\u683c\n2 \u6708\u4efd\uff0c\u5356\u4e86 2 \u4e2a LCKeychains \u548c 1 \u4e2a LCPhone\n3 \u6708\u4efd\uff0c\u5356\u4e86 1 \u4e2a matryoshka\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1543](https://leetcode-cn.com/problems/fix-product-name-format)", "[\u4ea7\u54c1\u540d\u79f0\u683c\u5f0f\u4fee\u590d](/solution/1500-1599/1543.Fix%20Product%20Name%20Format/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1543](https://leetcode.com/problems/fix-product-name-format)", "[Fix Product Name Format](/solution/1500-1599/1543.Fix%20Product%20Name%20Format/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1685", "frontend_question_id": "1563", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/stone-game-v", "url_en": "https://leetcode.com/problems/stone-game-v", "relative_path_cn": "/solution/1500-1599/1563.Stone%20Game%20V/README.md", "relative_path_en": "/solution/1500-1599/1563.Stone%20Game%20V/README_EN.md", "title_cn": "\u77f3\u5b50\u6e38\u620f V", "title_en": "Stone Game V", "question_title_slug": "stone-game-v", "content_en": "

There are several stones arranged in a row, and each stone has an associated value which is an integer given in the array stoneValue.

\n\n

In each round of the game, Alice divides the row into two non-empty rows (i.e. left row and right row), then Bob calculates the value of each row which is the sum of the values of all the stones in this row. Bob throws away the row which has the maximum value, and Alice's score increases by the value of the remaining row. If the value of the two rows are equal, Bob lets Alice decide which row will be thrown away. The next round starts with the remaining row.

\n\n

The game ends when there is only one stone remaining. Alice's is initially zero.

\n\n

Return the maximum score that Alice can obtain.

\n\n

 

\n

Example 1:

\n\n
\nInput: stoneValue = [6,2,3,4,5,5]\nOutput: 18\nExplanation: In the first round, Alice divides the row to [6,2,3], [4,5,5]. The left row has the value 11 and the right row has value 14. Bob throws away the right row and Alice's score is now 11.\nIn the second round Alice divides the row to [6], [2,3]. This time Bob throws away the left row and Alice's score becomes 16 (11 + 5).\nThe last round Alice has only one choice to divide the row which is [2], [3]. Bob throws away the right row and Alice's score is now 18 (16 + 2). The game ends because only one stone is remaining in the row.\n
\n\n

Example 2:

\n\n
\nInput: stoneValue = [7,7,7,7,7,7,7]\nOutput: 28\n
\n\n

Example 3:

\n\n
\nInput: stoneValue = [4]\nOutput: 0\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= stoneValue.length <= 500
  • \n\t
  • 1 <= stoneValue[i] <= 10^6
  • \n
\n", "content_cn": "

\u51e0\u5757\u77f3\u5b50 \u6392\u6210\u4e00\u884c \uff0c\u6bcf\u5757\u77f3\u5b50\u90fd\u6709\u4e00\u4e2a\u5173\u8054\u503c\uff0c\u5173\u8054\u503c\u4e3a\u6574\u6570\uff0c\u7531\u6570\u7ec4 stoneValue \u7ed9\u51fa\u3002

\n\n

\u6e38\u620f\u4e2d\u7684\u6bcf\u4e00\u8f6e\uff1aAlice \u4f1a\u5c06\u8fd9\u884c\u77f3\u5b50\u5206\u6210\u4e24\u4e2a \u975e\u7a7a\u884c\uff08\u5373\uff0c\u5de6\u4fa7\u884c\u548c\u53f3\u4fa7\u884c\uff09\uff1bBob \u8d1f\u8d23\u8ba1\u7b97\u6bcf\u4e00\u884c\u7684\u503c\uff0c\u5373\u6b64\u884c\u4e2d\u6240\u6709\u77f3\u5b50\u7684\u503c\u7684\u603b\u548c\u3002Bob \u4f1a\u4e22\u5f03\u503c\u6700\u5927\u7684\u884c\uff0cAlice \u7684\u5f97\u5206\u4e3a\u5269\u4e0b\u90a3\u884c\u7684\u503c\uff08\u6bcf\u8f6e\u7d2f\u52a0\uff09\u3002\u5982\u679c\u4e24\u884c\u7684\u503c\u76f8\u7b49\uff0cBob \u8ba9 Alice \u51b3\u5b9a\u4e22\u5f03\u54ea\u4e00\u884c\u3002\u4e0b\u4e00\u8f6e\u4ece\u5269\u4e0b\u7684\u90a3\u4e00\u884c\u5f00\u59cb\u3002

\n\n

\u53ea \u5269\u4e0b\u4e00\u5757\u77f3\u5b50 \u65f6\uff0c\u6e38\u620f\u7ed3\u675f\u3002Alice \u7684\u5206\u6570\u6700\u521d\u4e3a 0 \u3002

\n\n

\u8fd4\u56de Alice \u80fd\u591f\u83b7\u5f97\u7684\u6700\u5927\u5206\u6570 \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1astoneValue = [6,2,3,4,5,5]\n\u8f93\u51fa\uff1a18\n\u89e3\u91ca\uff1a\u5728\u7b2c\u4e00\u8f6e\u4e2d\uff0cAlice \u5c06\u884c\u5212\u5206\u4e3a [6\uff0c2\uff0c3]\uff0c[4\uff0c5\uff0c5] \u3002\u5de6\u884c\u7684\u503c\u662f 11 \uff0c\u53f3\u884c\u7684\u503c\u662f 14 \u3002Bob \u4e22\u5f03\u4e86\u53f3\u884c\uff0cAlice \u7684\u5206\u6570\u73b0\u5728\u662f 11 \u3002\n\u5728\u7b2c\u4e8c\u8f6e\u4e2d\uff0cAlice \u5c06\u884c\u5206\u6210 [6]\uff0c[2\uff0c3] \u3002\u8fd9\u4e00\u6b21 Bob \u6254\u6389\u4e86\u5de6\u884c\uff0cAlice \u7684\u5206\u6570\u53d8\u6210\u4e86 16\uff0811 + 5\uff09\u3002\n\u6700\u540e\u4e00\u8f6e Alice \u53ea\u80fd\u5c06\u884c\u5206\u6210 [2]\uff0c[3] \u3002Bob \u6254\u6389\u53f3\u884c\uff0cAlice \u7684\u5206\u6570\u73b0\u5728\u662f 18\uff0816 + 2\uff09\u3002\u6e38\u620f\u7ed3\u675f\uff0c\u56e0\u4e3a\u8fd9\u884c\u53ea\u5269\u4e0b\u4e00\u5757\u77f3\u5934\u4e86\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1astoneValue = [7,7,7,7,7,7,7]\n\u8f93\u51fa\uff1a28\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1astoneValue = [4]\n\u8f93\u51fa\uff1a0\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= stoneValue.length <= 500
  • \n\t
  • 1 <= stoneValue[i] <= 10^6
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int stoneGameV(vector& stoneValue) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int stoneGameV(int[] stoneValue) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def stoneGameV(self, stoneValue):\n \"\"\"\n :type stoneValue: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def stoneGameV(self, stoneValue: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint stoneGameV(int* stoneValue, int stoneValueSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int StoneGameV(int[] stoneValue) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} stoneValue\n * @return {number}\n */\nvar stoneGameV = function(stoneValue) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} stone_value\n# @return {Integer}\ndef stone_game_v(stone_value)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func stoneGameV(_ stoneValue: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func stoneGameV(stoneValue []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def stoneGameV(stoneValue: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun stoneGameV(stoneValue: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn stone_game_v(stone_value: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $stoneValue\n * @return Integer\n */\n function stoneGameV($stoneValue) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function stoneGameV(stoneValue: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (stone-game-v stoneValue)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1563](https://leetcode-cn.com/problems/stone-game-v)", "[\u77f3\u5b50\u6e38\u620f V](/solution/1500-1599/1563.Stone%20Game%20V/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1563](https://leetcode.com/problems/stone-game-v)", "[Stone Game V](/solution/1500-1599/1563.Stone%20Game%20V/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1684", "frontend_question_id": "1562", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-latest-group-of-size-m", "url_en": "https://leetcode.com/problems/find-latest-group-of-size-m", "relative_path_cn": "/solution/1500-1599/1562.Find%20Latest%20Group%20of%20Size%20M/README.md", "relative_path_en": "/solution/1500-1599/1562.Find%20Latest%20Group%20of%20Size%20M/README_EN.md", "title_cn": "\u67e5\u627e\u5927\u5c0f\u4e3a M \u7684\u6700\u65b0\u5206\u7ec4", "title_en": "Find Latest Group of Size M", "question_title_slug": "find-latest-group-of-size-m", "content_en": "

Given an array arr that represents a permutation of numbers from 1 to n. You have a binary string of size n that initially has all its bits set to zero.

\n\n

At each step i (assuming both the binary string and arr are 1-indexed) from 1 to n, the bit at position arr[i] is set to 1. You are given an integer m and you need to find the latest step at which there exists a group of ones of length m. A group of ones is a contiguous substring of 1s such that it cannot be extended in either direction.

\n\n

Return the latest step at which there exists a group of ones of length exactly m. If no such group exists, return -1.

\n\n

 

\n

Example 1:

\n\n
\nInput: arr = [3,5,1,2,4], m = 1\nOutput: 4\nExplanation:\nStep 1: "00100", groups: ["1"]\nStep 2: "00101", groups: ["1", "1"]\nStep 3: "10101", groups: ["1", "1", "1"]\nStep 4: "11101", groups: ["111", "1"]\nStep 5: "11111", groups: ["11111"]\nThe latest step at which there exists a group of size 1 is step 4.
\n\n

Example 2:

\n\n
\nInput: arr = [3,1,5,4,2], m = 2\nOutput: -1\nExplanation:\nStep 1: "00100", groups: ["1"]\nStep 2: "10100", groups: ["1", "1"]\nStep 3: "10101", groups: ["1", "1", "1"]\nStep 4: "10111", groups: ["1", "111"]\nStep 5: "11111", groups: ["11111"]\nNo group of size 2 exists during any step.\n
\n\n

Example 3:

\n\n
\nInput: arr = [1], m = 1\nOutput: 1\n
\n\n

Example 4:

\n\n
\nInput: arr = [2,1], m = 2\nOutput: 2\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == arr.length
  • \n\t
  • 1 <= n <= 10^5
  • \n\t
  • 1 <= arr[i] <= n
  • \n\t
  • All integers in arr are distinct.
  • \n\t
  • 1 <= m <= arr.length
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 arr \uff0c\u8be5\u6570\u7ec4\u8868\u793a\u4e00\u4e2a\u4ece 1 \u5230 n \u7684\u6570\u5b57\u6392\u5217\u3002\u6709\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32\uff0c\u8be5\u5b57\u7b26\u4e32\u4e0a\u7684\u6240\u6709\u4f4d\u6700\u521d\u90fd\u8bbe\u7f6e\u4e3a 0 \u3002

\n\n

\u5728\u4ece 1 \u5230 n \u7684\u6bcf\u4e2a\u6b65\u9aa4 i \u4e2d\uff08\u5047\u8bbe\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32\u548c arr \u90fd\u662f\u4ece 1 \u5f00\u59cb\u7d22\u5f15\u7684\u60c5\u51b5\u4e0b\uff09\uff0c\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32\u4e0a\u4f4d\u4e8e\u4f4d\u7f6e arr[i] \u7684\u4f4d\u5c06\u4f1a\u8bbe\u4e3a 1 \u3002

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 m \uff0c\u8bf7\u4f60\u627e\u51fa\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32\u4e0a\u5b58\u5728\u957f\u5ea6\u4e3a m \u7684\u4e00\u7ec4 1 \u7684\u6700\u540e\u6b65\u9aa4\u3002\u4e00\u7ec4 1 \u662f\u4e00\u4e2a\u8fde\u7eed\u7684\u3001\u7531 1 \u7ec4\u6210\u7684\u5b50\u4e32\uff0c\u4e14\u5de6\u53f3\u4e24\u8fb9\u4e0d\u518d\u6709\u53ef\u4ee5\u5ef6\u4f38\u7684 1 \u3002

\n\n

\u8fd4\u56de\u5b58\u5728\u957f\u5ea6 \u6070\u597d \u4e3a m \u7684 \u4e00\u7ec4 1  \u7684\u6700\u540e\u6b65\u9aa4\u3002\u5982\u679c\u4e0d\u5b58\u5728\u8fd9\u6837\u7684\u6b65\u9aa4\uff0c\u8bf7\u8fd4\u56de -1 \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aarr = [3,5,1,2,4], m = 1\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\n\u6b65\u9aa4 1\uff1a"00100"\uff0c\u7531 1 \u6784\u6210\u7684\u7ec4\uff1a["1"]\n\u6b65\u9aa4 2\uff1a"00101"\uff0c\u7531 1 \u6784\u6210\u7684\u7ec4\uff1a["1", "1"]\n\u6b65\u9aa4 3\uff1a"10101"\uff0c\u7531 1 \u6784\u6210\u7684\u7ec4\uff1a["1", "1", "1"]\n\u6b65\u9aa4 4\uff1a"11101"\uff0c\u7531 1 \u6784\u6210\u7684\u7ec4\uff1a["111", "1"]\n\u6b65\u9aa4 5\uff1a"11111"\uff0c\u7531 1 \u6784\u6210\u7684\u7ec4\uff1a["11111"]\n\u5b58\u5728\u957f\u5ea6\u4e3a 1 \u7684\u4e00\u7ec4 1 \u7684\u6700\u540e\u6b65\u9aa4\u662f\u6b65\u9aa4 4 \u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aarr = [3,1,5,4,2], m = 2\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\n\u6b65\u9aa4 1\uff1a"00100"\uff0c\u7531 1 \u6784\u6210\u7684\u7ec4\uff1a["1"]\n\u6b65\u9aa4 2\uff1a"10100"\uff0c\u7531 1 \u6784\u6210\u7684\u7ec4\uff1a["1", "1"]\n\u6b65\u9aa4 3\uff1a"10101"\uff0c\u7531 1 \u6784\u6210\u7684\u7ec4\uff1a["1", "1", "1"]\n\u6b65\u9aa4 4\uff1a"10111"\uff0c\u7531 1 \u6784\u6210\u7684\u7ec4\uff1a["1", "111"]\n\u6b65\u9aa4 5\uff1a"11111"\uff0c\u7531 1 \u6784\u6210\u7684\u7ec4\uff1a["11111"]\n\u4e0d\u7ba1\u662f\u54ea\u4e00\u6b65\u9aa4\u90fd\u65e0\u6cd5\u5f62\u6210\u957f\u5ea6\u4e3a 2 \u7684\u4e00\u7ec4 1 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aarr = [1], m = 1\n\u8f93\u51fa\uff1a1\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1aarr = [2,1], m = 2\n\u8f93\u51fa\uff1a2\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • n == arr.length
  • \n\t
  • 1 <= n <= 10^5
  • \n\t
  • 1 <= arr[i] <= n
  • \n\t
  • arr \u4e2d\u7684\u6240\u6709\u6574\u6570 \u4e92\u4e0d\u76f8\u540c
  • \n\t
  • 1 <= m <= arr.length
  • \n
\n", "tags_en": ["Binary Search"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findLatestStep(vector& arr, int m) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findLatestStep(int[] arr, int m) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findLatestStep(self, arr, m):\n \"\"\"\n :type arr: List[int]\n :type m: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findLatestStep(self, arr: List[int], m: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findLatestStep(int* arr, int arrSize, int m){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindLatestStep(int[] arr, int m) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @param {number} m\n * @return {number}\n */\nvar findLatestStep = function(arr, m) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @param {Integer} m\n# @return {Integer}\ndef find_latest_step(arr, m)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findLatestStep(_ arr: [Int], _ m: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findLatestStep(arr []int, m int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findLatestStep(arr: Array[Int], m: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findLatestStep(arr: IntArray, m: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_latest_step(arr: Vec, m: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @param Integer $m\n * @return Integer\n */\n function findLatestStep($arr, $m) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findLatestStep(arr: number[], m: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-latest-step arr m)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1562](https://leetcode-cn.com/problems/find-latest-group-of-size-m)", "[\u67e5\u627e\u5927\u5c0f\u4e3a M \u7684\u6700\u65b0\u5206\u7ec4](/solution/1500-1599/1562.Find%20Latest%20Group%20of%20Size%20M/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1562](https://leetcode.com/problems/find-latest-group-of-size-m)", "[Find Latest Group of Size M](/solution/1500-1599/1562.Find%20Latest%20Group%20of%20Size%20M/README_EN.md)", "`Binary Search`", "Medium", ""]}, {"question_id": "1683", "frontend_question_id": "1561", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-number-of-coins-you-can-get", "url_en": "https://leetcode.com/problems/maximum-number-of-coins-you-can-get", "relative_path_cn": "/solution/1500-1599/1561.Maximum%20Number%20of%20Coins%20You%20Can%20Get/README.md", "relative_path_en": "/solution/1500-1599/1561.Maximum%20Number%20of%20Coins%20You%20Can%20Get/README_EN.md", "title_cn": "\u4f60\u53ef\u4ee5\u83b7\u5f97\u7684\u6700\u5927\u786c\u5e01\u6570\u76ee", "title_en": "Maximum Number of Coins You Can Get", "question_title_slug": "maximum-number-of-coins-you-can-get", "content_en": "

There are 3n piles of coins of varying size, you and your friends will take piles of coins as follows:

\n\n
    \n\t
  • In each step, you will choose any 3 piles of coins (not necessarily consecutive).
  • \n\t
  • Of your choice, Alice will pick the pile with the maximum number of coins.
  • \n\t
  • You will pick the next pile with maximum number of coins.
  • \n\t
  • Your friend Bob will pick the last pile.
  • \n\t
  • Repeat until there are no more piles of coins.
  • \n
\n\n

Given an array of integers piles where piles[i] is the number of coins in the ith pile.

\n\n

Return the maximum number of coins which you can have.

\n\n

 

\n

Example 1:

\n\n
\nInput: piles = [2,4,1,2,7,8]\nOutput: 9\nExplanation: Choose the triplet (2, 7, 8), Alice Pick the pile with 8 coins, you the pile with 7 coins and Bob the last one.\nChoose the triplet (1, 2, 4), Alice Pick the pile with 4 coins, you the pile with 2 coins and Bob the last one.\nThe maximum number of coins which you can have are: 7 + 2 = 9.\nOn the other hand if we choose this arrangement (1, 2, 8), (2, 4, 7) you only get 2 + 4 = 6 coins which is not optimal.\n
\n\n

Example 2:

\n\n
\nInput: piles = [2,4,5]\nOutput: 4\n
\n\n

Example 3:

\n\n
\nInput: piles = [9,8,7,6,5,1,2,3,4]\nOutput: 18\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 3 <= piles.length <= 10^5
  • \n\t
  • piles.length % 3 == 0
  • \n\t
  • 1 <= piles[i] <= 10^4
  • \n
\n", "content_cn": "

\u6709 3n \u5806\u6570\u76ee\u4e0d\u4e00\u7684\u786c\u5e01\uff0c\u4f60\u548c\u4f60\u7684\u670b\u53cb\u4eec\u6253\u7b97\u6309\u4ee5\u4e0b\u65b9\u5f0f\u5206\u786c\u5e01\uff1a

\n\n
    \n\t
  • \u6bcf\u4e00\u8f6e\u4e2d\uff0c\u4f60\u5c06\u4f1a\u9009\u51fa \u4efb\u610f 3 \u5806\u786c\u5e01\uff08\u4e0d\u4e00\u5b9a\u8fde\u7eed\uff09\u3002
  • \n\t
  • Alice \u5c06\u4f1a\u53d6\u8d70\u786c\u5e01\u6570\u91cf\u6700\u591a\u7684\u90a3\u4e00\u5806\u3002
  • \n\t
  • \u4f60\u5c06\u4f1a\u53d6\u8d70\u786c\u5e01\u6570\u91cf\u7b2c\u4e8c\u591a\u7684\u90a3\u4e00\u5806\u3002
  • \n\t
  • Bob \u5c06\u4f1a\u53d6\u8d70\u6700\u540e\u4e00\u5806\u3002
  • \n\t
  • \u91cd\u590d\u8fd9\u4e2a\u8fc7\u7a0b\uff0c\u76f4\u5230\u6ca1\u6709\u66f4\u591a\u786c\u5e01\u3002
  • \n
\n\n

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 piles \uff0c\u5176\u4e2d piles[i] \u662f\u7b2c i \u5806\u4e2d\u786c\u5e01\u7684\u6570\u76ee\u3002

\n\n

\u8fd4\u56de\u4f60\u53ef\u4ee5\u83b7\u5f97\u7684\u6700\u5927\u786c\u5e01\u6570\u76ee\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1apiles = [2,4,1,2,7,8]\n\u8f93\u51fa\uff1a9\n\u89e3\u91ca\uff1a\u9009\u51fa (2, 7, 8) \uff0cAlice \u53d6\u8d70 8 \u679a\u786c\u5e01\u7684\u90a3\u5806\uff0c\u4f60\u53d6\u8d70 7 \u679a\u786c\u5e01\u7684\u90a3\u5806\uff0cBob \u53d6\u8d70\u6700\u540e\u4e00\u5806\u3002\n\u9009\u51fa (1, 2, 4) , Alice \u53d6\u8d70 4 \u679a\u786c\u5e01\u7684\u90a3\u5806\uff0c\u4f60\u53d6\u8d70 2 \u679a\u786c\u5e01\u7684\u90a3\u5806\uff0cBob \u53d6\u8d70\u6700\u540e\u4e00\u5806\u3002\n\u4f60\u53ef\u4ee5\u83b7\u5f97\u7684\u6700\u5927\u786c\u5e01\u6570\u76ee\uff1a7 + 2 = 9.\n\u8003\u8651\u53e6\u5916\u4e00\u79cd\u60c5\u51b5\uff0c\u5982\u679c\u9009\u51fa\u7684\u662f (1, 2, 8) \u548c (2, 4, 7) \uff0c\u4f60\u5c31\u53ea\u80fd\u5f97\u5230 2 + 4 = 6 \u679a\u786c\u5e01\uff0c\u8fd9\u4e0d\u662f\u6700\u4f18\u89e3\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1apiles = [2,4,5]\n\u8f93\u51fa\uff1a4\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1apiles = [9,8,7,6,5,1,2,3,4]\n\u8f93\u51fa\uff1a18\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 3 <= piles.length <= 10^5
  • \n\t
  • piles.length % 3 == 0
  • \n\t
  • 1 <= piles[i] <= 10^4
  • \n
\n", "tags_en": ["Sort"], "tags_cn": ["\u6392\u5e8f"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxCoins(vector& piles) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxCoins(int[] piles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxCoins(self, piles):\n \"\"\"\n :type piles: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxCoins(self, piles: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxCoins(int* piles, int pilesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxCoins(int[] piles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} piles\n * @return {number}\n */\nvar maxCoins = function(piles) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} piles\n# @return {Integer}\ndef max_coins(piles)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxCoins(_ piles: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxCoins(piles []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxCoins(piles: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxCoins(piles: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_coins(piles: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $piles\n * @return Integer\n */\n function maxCoins($piles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxCoins(piles: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-coins piles)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1561](https://leetcode-cn.com/problems/maximum-number-of-coins-you-can-get)", "[\u4f60\u53ef\u4ee5\u83b7\u5f97\u7684\u6700\u5927\u786c\u5e01\u6570\u76ee](/solution/1500-1599/1561.Maximum%20Number%20of%20Coins%20You%20Can%20Get/README.md)", "`\u6392\u5e8f`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1561](https://leetcode.com/problems/maximum-number-of-coins-you-can-get)", "[Maximum Number of Coins You Can Get](/solution/1500-1599/1561.Maximum%20Number%20of%20Coins%20You%20Can%20Get/README_EN.md)", "`Sort`", "Medium", ""]}, {"question_id": "1682", "frontend_question_id": "1560", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/most-visited-sector-in-a-circular-track", "url_en": "https://leetcode.com/problems/most-visited-sector-in-a-circular-track", "relative_path_cn": "/solution/1500-1599/1560.Most%20Visited%20Sector%20in%20%20a%20Circular%20Track/README.md", "relative_path_en": "/solution/1500-1599/1560.Most%20Visited%20Sector%20in%20%20a%20Circular%20Track/README_EN.md", "title_cn": "\u5706\u5f62\u8d5b\u9053\u4e0a\u7ecf\u8fc7\u6b21\u6570\u6700\u591a\u7684\u6247\u533a", "title_en": "Most Visited Sector in a Circular Track", "question_title_slug": "most-visited-sector-in-a-circular-track", "content_en": "

Given an integer n and an integer array rounds. We have a circular track which consists of n sectors labeled from 1 to n. A marathon will be held on this track, the marathon consists of m rounds. The ith round starts at sector rounds[i - 1] and ends at sector rounds[i]. For example, round 1 starts at sector rounds[0] and ends at sector rounds[1]

\n\n

Return an array of the most visited sectors sorted in ascending order.

\n\n

Notice that you circulate the track in ascending order of sector numbers in the counter-clockwise direction (See the first example).

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: n = 4, rounds = [1,3,1,2]\nOutput: [1,2]\nExplanation: The marathon starts at sector 1. The order of the visited sectors is as follows:\n1 --> 2 --> 3 (end of round 1) --> 4 --> 1 (end of round 2) --> 2 (end of round 3 and the marathon)\nWe can see that both sectors 1 and 2 are visited twice and they are the most visited sectors. Sectors 3 and 4 are visited only once.
\n\n

Example 2:

\n\n
\nInput: n = 2, rounds = [2,1,2,1,2,1,2,1,2]\nOutput: [2]\n
\n\n

Example 3:

\n\n
\nInput: n = 7, rounds = [1,3,5,7]\nOutput: [1,2,3,4,5,6,7]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= n <= 100
  • \n\t
  • 1 <= m <= 100
  • \n\t
  • rounds.length == m + 1
  • \n\t
  • 1 <= rounds[i] <= n
  • \n\t
  • rounds[i] != rounds[i + 1] for 0 <= i < m
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n \u548c\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 rounds \u3002\u6709\u4e00\u6761\u5706\u5f62\u8d5b\u9053\u7531 n \u4e2a\u6247\u533a\u7ec4\u6210\uff0c\u6247\u533a\u7f16\u53f7\u4ece 1 \u5230 n \u3002\u73b0\u5c06\u5728\u8fd9\u6761\u8d5b\u9053\u4e0a\u4e3e\u529e\u4e00\u573a\u9a6c\u62c9\u677e\u6bd4\u8d5b\uff0c\u8be5\u9a6c\u62c9\u677e\u5168\u7a0b\u7531 m \u4e2a\u9636\u6bb5\u7ec4\u6210\u3002\u5176\u4e2d\uff0c\u7b2c i \u4e2a\u9636\u6bb5\u5c06\u4f1a\u4ece\u6247\u533a rounds[i - 1] \u5f00\u59cb\uff0c\u5230\u6247\u533a rounds[i] \u7ed3\u675f\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u7b2c 1 \u9636\u6bb5\u4ece rounds[0] \u5f00\u59cb\uff0c\u5230 rounds[1] \u7ed3\u675f\u3002

\n\n

\u8bf7\u4f60\u4ee5\u6570\u7ec4\u5f62\u5f0f\u8fd4\u56de\u7ecf\u8fc7\u6b21\u6570\u6700\u591a\u7684\u90a3\u51e0\u4e2a\u6247\u533a\uff0c\u6309\u6247\u533a\u7f16\u53f7 \u5347\u5e8f \u6392\u5217\u3002

\n\n

\u6ce8\u610f\uff0c\u8d5b\u9053\u6309\u6247\u533a\u7f16\u53f7\u5347\u5e8f\u9006\u65f6\u9488\u5f62\u6210\u4e00\u4e2a\u5706\uff08\u8bf7\u53c2\u89c1\u7b2c\u4e00\u4e2a\u793a\u4f8b\uff09\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1an = 4, rounds = [1,3,1,2]\n\u8f93\u51fa\uff1a[1,2]\n\u89e3\u91ca\uff1a\u672c\u573a\u9a6c\u62c9\u677e\u6bd4\u8d5b\u4ece\u6247\u533a 1 \u5f00\u59cb\u3002\u7ecf\u8fc7\u5404\u4e2a\u6247\u533a\u7684\u6b21\u5e8f\u5982\u4e0b\u6240\u793a\uff1a\n1 --> 2 --> 3\uff08\u9636\u6bb5 1 \u7ed3\u675f\uff09--> 4 --> 1\uff08\u9636\u6bb5 2 \u7ed3\u675f\uff09--> 2\uff08\u9636\u6bb5 3 \u7ed3\u675f\uff0c\u5373\u672c\u573a\u9a6c\u62c9\u677e\u7ed3\u675f\uff09\n\u5176\u4e2d\uff0c\u6247\u533a 1 \u548c 2 \u90fd\u7ecf\u8fc7\u4e86\u4e24\u6b21\uff0c\u5b83\u4eec\u662f\u7ecf\u8fc7\u6b21\u6570\u6700\u591a\u7684\u4e24\u4e2a\u6247\u533a\u3002\u6247\u533a 3 \u548c 4 \u90fd\u53ea\u7ecf\u8fc7\u4e86\u4e00\u6b21\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1an = 2, rounds = [2,1,2,1,2,1,2,1,2]\n\u8f93\u51fa\uff1a[2]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1an = 7, rounds = [1,3,5,7]\n\u8f93\u51fa\uff1a[1,2,3,4,5,6,7]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= n <= 100
  • \n\t
  • 1 <= m <= 100
  • \n\t
  • rounds.length == m + 1
  • \n\t
  • 1 <= rounds[i] <= n
  • \n\t
  • rounds[i] != rounds[i + 1] \uff0c\u5176\u4e2d 0 <= i < m
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector mostVisited(int n, vector& rounds) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List mostVisited(int n, int[] rounds) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def mostVisited(self, n, rounds):\n \"\"\"\n :type n: int\n :type rounds: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def mostVisited(self, n: int, rounds: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* mostVisited(int n, int* rounds, int roundsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList MostVisited(int n, int[] rounds) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[]} rounds\n * @return {number[]}\n */\nvar mostVisited = function(n, rounds) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[]} rounds\n# @return {Integer[]}\ndef most_visited(n, rounds)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func mostVisited(_ n: Int, _ rounds: [Int]) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func mostVisited(n int, rounds []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def mostVisited(n: Int, rounds: Array[Int]): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun mostVisited(n: Int, rounds: IntArray): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn most_visited(n: i32, rounds: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[] $rounds\n * @return Integer[]\n */\n function mostVisited($n, $rounds) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function mostVisited(n: number, rounds: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (most-visited n rounds)\n (-> exact-integer? (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1560](https://leetcode-cn.com/problems/most-visited-sector-in-a-circular-track)", "[\u5706\u5f62\u8d5b\u9053\u4e0a\u7ecf\u8fc7\u6b21\u6570\u6700\u591a\u7684\u6247\u533a](/solution/1500-1599/1560.Most%20Visited%20Sector%20in%20%20a%20Circular%20Track/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1560](https://leetcode.com/problems/most-visited-sector-in-a-circular-track)", "[Most Visited Sector in a Circular Track](/solution/1500-1599/1560.Most%20Visited%20Sector%20in%20%20a%20Circular%20Track/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1681", "frontend_question_id": "1538", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/guess-the-majority-in-a-hidden-array", "url_en": "https://leetcode.com/problems/guess-the-majority-in-a-hidden-array", "relative_path_cn": "/solution/1500-1599/1538.Guess%20the%20Majority%20in%20a%20Hidden%20Array/README.md", "relative_path_en": "/solution/1500-1599/1538.Guess%20the%20Majority%20in%20a%20Hidden%20Array/README_EN.md", "title_cn": "\u627e\u51fa\u9690\u85cf\u6570\u7ec4\u4e2d\u51fa\u73b0\u6b21\u6570\u6700\u591a\u7684\u5143\u7d20", "title_en": "Guess the Majority in a Hidden Array", "question_title_slug": "guess-the-majority-in-a-hidden-array", "content_en": "

We have an integer array nums, where all the integers in nums are 0 or 1. You will not be given direct access to the array, instead, you will have an API ArrayReader which have the following functions:

\n\n
    \n\t
  • int query(int a, int b, int c, int d): where 0 <= a < b < c < d < ArrayReader.length(). The function returns the distribution of the value of the 4 elements and returns:\n\n\t
      \n\t\t
    • 4 : if the values of the 4 elements are the same (0 or 1).
    • \n\t\t
    • 2 : if three elements have a value equal to 0 and one element has value equal to 1 or vice versa.
    • \n\t\t
    • : if two element have a value equal to 0 and two elements have a value equal to 1.
    • \n\t
    \n\t
  • \n\t
  • int length(): Returns the size of the array.
  • \n
\n\n

You are allowed to call query() 2 * n times at most where n is equal to ArrayReader.length().

\n\n

Return any index of the most frequent value in nums, in case of tie, return -1.

\n\n

Follow up: What is the minimum number of calls needed to find the majority element?

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [0,0,1,0,1,1,1,1]\nOutput: 5\nExplanation: The following calls to the API\nreader.length() // returns 8 because there are 8 elements in the hidden array.\nreader.query(0,1,2,3) // returns 2 this is a query that compares the elements nums[0], nums[1], nums[2], nums[3]\n// Three elements have a value equal to 0 and one element has value equal to 1 or viceversa.\nreader.query(4,5,6,7) // returns 4 because nums[4], nums[5], nums[6], nums[7] have the same value.\nwe can infer that the most frequent value is found in the last 4 elements.\nIndex 2, 4, 6, 7 is also a correct answer.\n
\n\n

Example 2:

\n\n
\nInput: nums = [0,0,1,1,0]\nOutput: 0\n
\n\n

Example 3:

\n\n
\nInput: nums = [1,0,1,0,1,0,1,0]\nOutput: -1\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 5 <= nums.length <= 10^5
  • \n\t
  • 0 <= nums[i] <= 1
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums\uff0c\u4e14 nums \u4e2d\u7684\u6240\u6709\u6574\u6570\u90fd\u4e3a 0 \u6216 1\u3002\u4f60\u4e0d\u80fd\u76f4\u63a5\u8bbf\u95ee\u8fd9\u4e2a\u6570\u7ec4\uff0c\u4f60\u9700\u8981\u4f7f\u7528 API ArrayReader \uff0c\u8be5 API \u542b\u6709\u4e0b\u5217\u6210\u5458\u51fd\u6570\uff1a

\n\n
    \n\t
  • int query(int a, int b, int c, int d)\uff1a\u5176\u4e2d 0 <= a < b < c < d < ArrayReader.length() \u3002\u6b64\u51fd\u6570\u67e5\u8be2\u4ee5\u8fd9\u56db\u4e2a\u53c2\u6570\u4e3a\u4e0b\u6807\u7684\u5143\u7d20\u5e76\u8fd4\u56de\uff1a\n\n\t
      \n\t\t
    • 4 : \u5f53\u8fd9\u56db\u4e2a\u5143\u7d20\u76f8\u540c\uff080 \u6216 1\uff09\u65f6\u3002
    • \n\t\t
    • 2 : \u5f53\u5176\u4e2d\u4e09\u4e2a\u5143\u7d20\u7684\u503c\u7b49\u4e8e 0 \u4e14\u4e00\u4e2a\u5143\u7d20\u7b49\u4e8e 1 \u65f6\uff0c\u6216\u5f53\u5176\u4e2d\u4e09\u4e2a\u5143\u7d20\u7684\u503c\u7b49\u4e8e 1 \u4e14\u4e00\u4e2a\u5143\u7d20\u7b49\u4e8e 0 \u65f6\u3002
    • \n\t\t
    • : \u5f53\u5176\u4e2d\u4e24\u4e2a\u5143\u7d20\u7b49\u4e8e 0 \u4e14\u4e24\u4e2a\u5143\u7d20\u7b49\u4e8e 1 \u65f6\u3002
    • \n\t
    \n\t
  • \n\t
  • int length()\uff1a\u8fd4\u56de\u6570\u7ec4\u7684\u957f\u5ea6\u3002
  • \n
\n\n

\u4f60\u53ef\u4ee5\u8c03\u7528 query() \u6700\u591a 2 * n \u6b21\uff0c\u5176\u4e2d n \u7b49\u4e8e ArrayReader.length()\u3002

\n\n

\u8fd4\u56de nums \u4e2d\u51fa\u73b0\u6b21\u6570\u6700\u591a\u7684\u503c\u7684\u4efb\u610f\u7d22\u5f15\uff0c\u82e5\u6240\u6709\u7684\u503c\u51fa\u73b0\u6b21\u6570\u5747\u76f8\u540c\uff0c\u8fd4\u56de -1\u3002

\n\n

\u8fdb\u9636\uff1a\u8981\u627e\u5230\u51fa\u73b0\u6b21\u6570\u6700\u591a\u7684\u5143\u7d20\uff0c\u9700\u8981\u81f3\u5c11\u8c03\u7528 query() \u591a\u5c11\u6b21\uff1f

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165: nums = [0,0,1,0,1,1,1,1]\n\u8f93\u51fa: 5\n\u89e3\u91ca: API \u7684\u8c03\u7528\u60c5\u51b5\u5982\u4e0b\uff1a\nreader.length() // \u8fd4\u56de 8\uff0c\u56e0\u4e3a\u9690\u85cf\u6570\u7ec4\u4e2d\u6709 8 \u4e2a\u5143\u7d20\u3002\nreader.query(0,1,2,3) // \u8fd4\u56de 2\uff0c\u67e5\u8be2\u5143\u7d20 nums[0], nums[1], nums[2], nums[3] \u95f4\u7684\u6bd4\u8f83\u3002\n// \u4e09\u4e2a\u5143\u7d20\u7b49\u4e8e 0 \u4e14\u4e00\u4e2a\u5143\u7d20\u7b49\u4e8e 1 \u6216\u51fa\u73b0\u76f8\u53cd\u60c5\u51b5\u3002\nreader.query(4,5,6,7) // \u8fd4\u56de 4\uff0c\u56e0\u4e3a nums[4], nums[5], nums[6], nums[7] \u6709\u76f8\u540c\u503c\u3002\n\u6211\u4eec\u53ef\u4ee5\u63a8\u65ad\uff0c\u6700\u5e38\u51fa\u73b0\u7684\u503c\u5728\u6700\u540e 4 \u4e2a\u5143\u7d20\u4e2d\u3002\n\u7d22\u5f15 2, 4, 6, 7 \u4e5f\u662f\u6b63\u786e\u7b54\u6848\u3002\n
\n\n

\u793a\u4f8b 2:

\n\n
\u8f93\u5165: nums = [0,0,1,1,0]\n\u8f93\u51fa: 0\n
\n\n

\u793a\u4f8b 3:

\n\n
\u8f93\u5165: nums = [1,0,1,0,1,0,1,0]\n\u8f93\u51fa: -1\n
\n\n

 

\n\n

\u63d0\u793a:

\n\n
    \n\t
  • 5 <= nums.length <= 10^5
  • \n\t
  • 0 <= nums[i] <= 1
  • \n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * // This is the ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * class ArrayReader {\n * public:\n * // Compares 4 different elements in the array\n * // return 4 if the values of the 4 elements are the same (0 or 1).\n * // return 2 if three\u00a0elements have a value\u00a0equal to 0\u00a0and one\u00a0element has value equal to 1\u00a0or vice versa.\n * // return 0 :\u00a0if two element have a value equal to 0 and two elements have a value equal to 1.\n * int query(int a, int b, int c, int d);\n *\n * // Returns the length of the array\n * int length();\n * };\n */\n\nclass Solution {\npublic:\n int guessMajority(ArrayReader &reader) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * // This is the ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * interface ArrayReader {\n * public:\n * // Compares 4 different elements in the array\n * // return 4 if the values of the 4 elements are the same (0 or 1).\n * // return 2 if three\u00a0elements have a value\u00a0equal to 0\u00a0and one\u00a0element has value equal to 1\u00a0or vice versa.\n * // return 0 :\u00a0if two element have a value equal to 0 and two elements have a value equal to 1.\n * public int query(int a, int b, int c, int d);\n *\n * // Returns the length of the array\n * public int length();\n * };\n */\n\nclass Solution {\n public int guessMajority(ArrayReader reader) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# \"\"\"\n# This is the ArrayReader's API interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class ArrayReader(object):\n#\t # Compares 4 different elements in the array\n#\t # return 4 if the values of the 4 elements are the same (0 or 1).\n#\t # return 2 if three\u00a0elements have a value\u00a0equal to 0\u00a0and one\u00a0element has value equal to 1\u00a0or vice versa.\n#\t # return 0 :\u00a0if two element have a value equal to 0 and two elements have a value equal to 1.\n# def query(self, a, b, c, d):\n# \"\"\"\n# :type a, b, c, d: int\n# :rtype int\n# \"\"\"\n#\n#\t # Returns the length of the array\n# def length(self):\n# \"\"\"\n# :rtype int\n# \n\nclass Solution(object):\n def guessMajority(self, reader):\n \"\"\"\n :type reader: ArrayReader\n :rtype: integer\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# \"\"\"\n# This is the ArrayReader's API interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class ArrayReader(object):\n#\t # Compares 4 different elements in the array\n#\t # return 4 if the values of the 4 elements are the same (0 or 1).\n#\t # return 2 if three\u00a0elements have a value\u00a0equal to 0\u00a0and one\u00a0element has value equal to 1\u00a0or vice versa.\n#\t # return 0 :\u00a0if two element have a value equal to 0 and two elements have a value equal to 1.\n# def query(self, a: int, b: int, c: int, d: int) -> int:\n#\n#\t # Returns the length of the array\n# def length(self) -> int:\n#\n\nclass Solution:\n def guessMajority(self, reader: 'ArrayReader') -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * *********************************************************************\n * // This is the ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * *********************************************************************\n *\n * // Compares 4 different elements in the array\n * // return 4 if the values of the 4 elements are the same (0 or 1).\n * // return 2 if three\u00a0elements have a value\u00a0equal to 0\u00a0and one\u00a0element has value equal to 1\u00a0or vice versa.\n * // return 0 :\u00a0if two element have a value equal to 0 and two elements have a value equal to 1.\n * int query(ArrayReader *, int a, int b, int c, int d);\n *\n * // Returns the length of the array\n * int length(ArrayReader *);\n */\n\nint guessMajority(ArrayReader* reader) {\n\t\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * // This is the ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * class ArrayReader {\n * public:\n * // Compares 4 different elements in the array\n * // return 4 if the values of the 4 elements are the same (0 or 1).\n * // return 2 if three\u00a0elements have a value\u00a0equal to 0\u00a0and one\u00a0element has value equal to 1\u00a0or vice versa.\n * // return 0 :\u00a0if two element have a value equal to 0 and two elements have a value equal to 1.\n * public int Query(int a, int b, int c, int d) {}\n *\n * // Returns the length of the array\n * public int Length() {}\n * };\n */\n\nclass Solution {\n public int GuessMajority(ArrayReader reader) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // This is the ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * function ArrayReader() {\n * // Compares 4 different elements in the array\n * // return 4 if the values of the 4 elements are the same (0 or 1).\n * // return 2 if three\u00a0elements have a value\u00a0equal to 0\u00a0and one\u00a0element has value equal to 1\u00a0or vice versa.\n * // return 0 :\u00a0if two element have a value equal to 0 and two elements have a value equal to 1.\n * @param {number} a, b, c, d\n * @return {number}\n * this.query = function(a, b, c, d) {\n * ...\n * }; \n *\n * // Returns the length of the array\n * @return {number}\n * this.length = function() {\n * ...\n * };\n * };\n */\n\n/**\n * @param {ArrayReader} reader\n * @return {number}\n */\nvar guessMajority = function(reader) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# This is ArrayReader's API interface.\n# You should not implement it, or speculate about its implementation\n# class ArrayReader\n#\t # Compares 4 different elements in the array\n#\t # return 4 if the values of the 4 elements are the same (0 or 1).\n#\t # return 2 if three\u00a0elements have a value\u00a0equal to 0\u00a0and one\u00a0element has value equal to 1\u00a0or vice versa.\n#\t # return 0 :\u00a0if two element have a value equal to 0 and two elements have a value equal to 1.\n# def query(a, b, c, d):\n# \n# end\n#\n#\t # Returns the length of the array\n# def length()\n#\t\t\n#\t end\n# end\n\n# @param {ArrayReader} reader\n# @return {int}\ndef guess_majority(reader)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * // This is ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * interface ArrayReader {\n * // Compares 4 different elements in the array\n * // return 4 if the values of the 4 elements are the same (0 or 1).\n * // return 2 if three\u00a0elements have a value\u00a0equal to 0\u00a0and one\u00a0element has value equal to 1\u00a0or vice versa.\n * // return 0 :\u00a0if two element have a value equal to 0 and two elements have a value equal to 1.\n * public func query(_ a: Int, _ b: Int, _ c: Int, _ d: Int) -> Int {}\n *\n * // Returns the length of the array\n * public func length() -> Int {}\n * }\n */\n\nclass Solution {\n func guessMajority(_ reader: ArrayReader) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * // This is the ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * type ArrayReader struct {\n * }\n * // Compares 4 different elements in the array\n * // return 4 if the values of the 4 elements are the same (0 or 1).\n * // return 2 if three\u00a0elements have a value\u00a0equal to 0\u00a0and one\u00a0element has value equal to 1\u00a0or vice versa.\n * // return 0 :\u00a0if two element have a value equal to 0 and two elements have a value equal to 1.\n * func (this *ArrayReader) query(a, b, c, d int) int {}\n * \n * // Returns the length of the array\n * func (this *ArrayReader) length() int {}\n */\n\nfunc guessMajority(reader *ArrayReader) int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * // This is ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * interface ArrayReader {\n * // Compares 4 different elements in the array\n * // return 4 if the values of the 4 elements are the same (0 or 1).\n * // return 2 if three\u00a0elements have a value\u00a0equal to 0\u00a0and one\u00a0element has value equal to 1\u00a0or vice versa.\n * // return 0 :\u00a0if two element have a value equal to 0 and two elements have a value equal to 1.\n * def query(a: Int, b: Int, c: Int, d: Int): Int {}\n *\n * // Returns the length of the array\n * def length(): Int {}\n * }\n */\n\nobject Solution {\n def guessMajority(reader: ArrayReader): Int = {\n \n\t}\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * // This is ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * interface ArrayReader {\n * // Compares 4 different elements in the array\n * // return 4 if the values of the 4 elements are the same (0 or 1).\n * // return 2 if three\u00a0elements have a value\u00a0equal to 0\u00a0and one\u00a0element has value equal to 1\u00a0or vice versa.\n * // return 0 :\u00a0if two element have a value equal to 0 and two elements have a value equal to 1.\n * fun query(a: Int, b: Int, c: Int, d: Int): Int {}\n *\n * // Returns the length of the array\n * fun length(): Int {}\n * }\n */\n\nclass Solution {\n fun guessMajority(reader: ArrayReader): Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "/**\n * // This is the ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * struct ArrayReader;\n * impl ArrayReader {\n * // Compares 4 different elements in the array\n * // return 4 if the values of the 4 elements are the same (0 or 1).\n * // return 2 if three elements have a value equal to 0 and one element has value equal to 1 or vice versa.\n * // return 0 : if two element have a value equal to 0 and two elements have a value equal to 1.\n * pub fn query(a: i32, b: i32, c: i32, d: i32) -> i32 {}\n *\n * // Returns the length of the array\n * pub fn length() -> i32 {}\n * };\n */\n\nimpl Solution {\n pub fn get_majority(reader: &ArrayReader) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * // This is ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * interface ArrayReader {\n * // Compares 4 different elements in the array\n * // return 4 if the values of the 4 elements are the same (0 or 1).\n * // return 2 if three\u00a0elements have a value\u00a0equal to 0\u00a0and one\u00a0element has value equal to 1\u00a0or vice versa.\n * // return 0 :\u00a0if two element have a value equal to 0 and two elements have a value equal to 1.\n * function query($a, $b, $c, $d) {}\n *\n * // Returns the length of the array\n * function length() {}\n * }\n */\n\nclass Solution {\n /**\n * @param ArrayReader $reader\n * @return Integer\n */\n function guessMajority($reader) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * // This is the ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * class ArrayReader {\n * // Compares 4 different elements in the array\n * // return 4 if the values of the 4 elements are the same (0 or 1).\n * // return 2 if three\u00a0elements have a value\u00a0equal to 0\u00a0and one\u00a0element has value equal to 1\u00a0or vice versa.\n * // return 0 :\u00a0if two element have a value equal to 0 and two elements have a value equal to 1.\n * query(a: number, b: number, c: number, d: number): number { };\n *\n * // Returns the length of the array\n * length(): number { };\n * };\n */\n\nfunction guessMajority(reader: ArrayReader): number {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1538](https://leetcode-cn.com/problems/guess-the-majority-in-a-hidden-array)", "[\u627e\u51fa\u9690\u85cf\u6570\u7ec4\u4e2d\u51fa\u73b0\u6b21\u6570\u6700\u591a\u7684\u5143\u7d20](/solution/1500-1599/1538.Guess%20the%20Majority%20in%20a%20Hidden%20Array/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1538](https://leetcode.com/problems/guess-the-majority-in-a-hidden-array)", "[Guess the Majority in a Hidden Array](/solution/1500-1599/1538.Guess%20the%20Majority%20in%20a%20Hidden%20Array/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1680", "frontend_question_id": "1575", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-all-possible-routes", "url_en": "https://leetcode.com/problems/count-all-possible-routes", "relative_path_cn": "/solution/1500-1599/1575.Count%20All%20Possible%20Routes/README.md", "relative_path_en": "/solution/1500-1599/1575.Count%20All%20Possible%20Routes/README_EN.md", "title_cn": "\u7edf\u8ba1\u6240\u6709\u53ef\u884c\u8def\u5f84", "title_en": "Count All Possible Routes", "question_title_slug": "count-all-possible-routes", "content_en": "

You are given an array of distinct positive integers locations where locations[i] represents the position of city i. You are also given integers startfinish and fuel representing the starting city, ending city, and the initial amount of fuel you have, respectively.

\n\n

At each step, if you are at city i, you can pick any city j such that j != i and 0 <= j < locations.length and move to city j. Moving from city i to city j reduces the amount of fuel you have by |locations[i] - locations[j]|. Please notice that |x| denotes the absolute value of x.

\n\n

Notice that fuel cannot become negative at any point in time, and that you are allowed to visit any city more than once (including start and finish).

\n\n

Return the count of all possible routes from start to finish.

\n\n

Since the answer may be too large, return it modulo 10^9 + 7.

\n\n

 

\n

Example 1:

\n\n
\nInput: locations = [2,3,6,8,4], start = 1, finish = 3, fuel = 5\nOutput: 4\nExplanation: The following are all possible routes, each uses 5 units of fuel:\n1 -> 3\n1 -> 2 -> 3\n1 -> 4 -> 3\n1 -> 4 -> 2 -> 3\n
\n\n

Example 2:

\n\n
\nInput: locations = [4,3,1], start = 1, finish = 0, fuel = 6\nOutput: 5\nExplanation: The following are all possible routes:\n1 -> 0, used fuel = 1\n1 -> 2 -> 0, used fuel = 5\n1 -> 2 -> 1 -> 0, used fuel = 5\n1 -> 0 -> 1 -> 0, used fuel = 3\n1 -> 0 -> 1 -> 0 -> 1 -> 0, used fuel = 5\n
\n\n

Example 3:

\n\n
\nInput: locations = [5,2,1], start = 0, finish = 2, fuel = 3\nOutput: 0\nExplanation: It's impossible to get from 0 to 2 using only 3 units of fuel since the shortest route needs 4 units of fuel.
\n\n

Example 4:

\n\n
\nInput: locations = [2,1,5], start = 0, finish = 0, fuel = 3\nOutput: 2\nExplanation: There are two possible routes, 0 and 0 -> 1 -> 0.
\n\n

Example 5:

\n\n
\nInput: locations = [1,2,3], start = 0, finish = 2, fuel = 40\nOutput: 615088286\nExplanation: The total number of possible routes is 2615088300. Taking this number modulo 10^9 + 7 gives us 615088286.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= locations.length <= 100
  • \n\t
  • 1 <= locations[i] <= 10^9
  • \n\t
  • All integers in locations are distinct.
  • \n\t
  • 0 <= start, finish < locations.length
  • \n\t
  • 1 <= fuel <= 200
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a \u4e92\u4e0d\u76f8\u540c \u7684\u6574\u6570\u6570\u7ec4\uff0c\u5176\u4e2d locations[i] \u8868\u793a\u7b2c i \u4e2a\u57ce\u5e02\u7684\u4f4d\u7f6e\u3002\u540c\u65f6\u7ed9\u4f60 start\uff0cfinish \u548c fuel \u5206\u522b\u8868\u793a\u51fa\u53d1\u57ce\u5e02\u3001\u76ee\u7684\u5730\u57ce\u5e02\u548c\u4f60\u521d\u59cb\u62e5\u6709\u7684\u6c7d\u6cb9\u603b\u91cf

\n\n

\u6bcf\u4e00\u6b65\u4e2d\uff0c\u5982\u679c\u4f60\u5728\u57ce\u5e02 i \uff0c\u4f60\u53ef\u4ee5\u9009\u62e9\u4efb\u610f\u4e00\u4e2a\u57ce\u5e02 j \uff0c\u6ee1\u8db3  j != i \u4e14 0 <= j < locations.length \uff0c\u5e76\u79fb\u52a8\u5230\u57ce\u5e02 j \u3002\u4ece\u57ce\u5e02 i \u79fb\u52a8\u5230 j \u6d88\u8017\u7684\u6c7d\u6cb9\u91cf\u4e3a |locations[i] - locations[j]|\uff0c|x| \u8868\u793a x \u7684\u7edd\u5bf9\u503c\u3002

\n\n

\u8bf7\u6ce8\u610f\uff0c fuel \u4efb\u4f55\u65f6\u523b\u90fd \u4e0d\u80fd \u4e3a\u8d1f\uff0c\u4e14\u4f60 \u53ef\u4ee5 \u7ecf\u8fc7\u4efb\u610f\u57ce\u5e02\u8d85\u8fc7\u4e00\u6b21\uff08\u5305\u62ec start \u548c finish \uff09\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u4ece start \u5230 finish \u6240\u6709\u53ef\u80fd\u8def\u5f84\u7684\u6570\u76ee\u3002

\n\n

\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u5f88\u5927\uff0c \u8bf7\u5c06\u5b83\u5bf9 10^9 + 7 \u53d6\u4f59\u540e\u8fd4\u56de\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1alocations = [2,3,6,8,4], start = 1, finish = 3, fuel = 5\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u4ee5\u4e0b\u4e3a\u6240\u6709\u53ef\u80fd\u8def\u5f84\uff0c\u6bcf\u4e00\u6761\u90fd\u7528\u4e86 5 \u5355\u4f4d\u7684\u6c7d\u6cb9\uff1a\n1 -> 3\n1 -> 2 -> 3\n1 -> 4 -> 3\n1 -> 4 -> 2 -> 3\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1alocations = [4,3,1], start = 1, finish = 0, fuel = 6\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u4ee5\u4e0b\u4e3a\u6240\u6709\u53ef\u80fd\u7684\u8def\u5f84\uff1a\n1 -> 0\uff0c\u4f7f\u7528\u6c7d\u6cb9\u91cf\u4e3a fuel = 1\n1 -> 2 -> 0\uff0c\u4f7f\u7528\u6c7d\u6cb9\u91cf\u4e3a fuel = 5\n1 -> 2 -> 1 -> 0\uff0c\u4f7f\u7528\u6c7d\u6cb9\u91cf\u4e3a fuel = 5\n1 -> 0 -> 1 -> 0\uff0c\u4f7f\u7528\u6c7d\u6cb9\u91cf\u4e3a fuel = 3\n1 -> 0 -> 1 -> 0 -> 1 -> 0\uff0c\u4f7f\u7528\u6c7d\u6cb9\u91cf\u4e3a fuel = 5\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1alocations = [5,2,1], start = 0, finish = 2, fuel = 3\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6ca1\u6709\u529e\u6cd5\u53ea\u7528 3 \u5355\u4f4d\u7684\u6c7d\u6cb9\u4ece 0 \u5230\u8fbe 2 \u3002\u56e0\u4e3a\u6700\u77ed\u8def\u5f84\u9700\u8981 4 \u5355\u4f4d\u7684\u6c7d\u6cb9\u3002
\n\n

\u793a\u4f8b 4 \uff1a

\n\n
\n\u8f93\u5165\uff1alocations = [2,1,5], start = 0, finish = 0, fuel = 3\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u603b\u5171\u6709\u4e24\u6761\u53ef\u884c\u8def\u5f84\uff0c0 \u548c 0 -> 1 -> 0 \u3002
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\n\u8f93\u5165\uff1alocations = [1,2,3], start = 0, finish = 2, fuel = 40\n\u8f93\u51fa\uff1a615088286\n\u89e3\u91ca\uff1a\u8def\u5f84\u603b\u6570\u4e3a 2615088300 \u3002\u5c06\u7ed3\u679c\u5bf9 10^9 + 7 \u53d6\u4f59\uff0c\u5f97\u5230 615088286 \u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= locations.length <= 100
  • \n\t
  • 1 <= locations[i] <= 10^9
  • \n\t
  • \u6240\u6709 locations \u4e2d\u7684\u6574\u6570 \u4e92\u4e0d\u76f8\u540c \u3002
  • \n\t
  • 0 <= start, finish < locations.length
  • \n\t
  • 1 <= fuel <= 200
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countRoutes(vector& locations, int start, int finish, int fuel) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countRoutes(int[] locations, int start, int finish, int fuel) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countRoutes(self, locations, start, finish, fuel):\n \"\"\"\n :type locations: List[int]\n :type start: int\n :type finish: int\n :type fuel: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countRoutes(self, locations: List[int], start: int, finish: int, fuel: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countRoutes(int* locations, int locationsSize, int start, int finish, int fuel){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountRoutes(int[] locations, int start, int finish, int fuel) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} locations\n * @param {number} start\n * @param {number} finish\n * @param {number} fuel\n * @return {number}\n */\nvar countRoutes = function(locations, start, finish, fuel) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} locations\n# @param {Integer} start\n# @param {Integer} finish\n# @param {Integer} fuel\n# @return {Integer}\ndef count_routes(locations, start, finish, fuel)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countRoutes(_ locations: [Int], _ start: Int, _ finish: Int, _ fuel: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countRoutes(locations []int, start int, finish int, fuel int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countRoutes(locations: Array[Int], start: Int, finish: Int, fuel: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countRoutes(locations: IntArray, start: Int, finish: Int, fuel: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_routes(locations: Vec, start: i32, finish: i32, fuel: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $locations\n * @param Integer $start\n * @param Integer $finish\n * @param Integer $fuel\n * @return Integer\n */\n function countRoutes($locations, $start, $finish, $fuel) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countRoutes(locations: number[], start: number, finish: number, fuel: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-routes locations start finish fuel)\n (-> (listof exact-integer?) exact-integer? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1575](https://leetcode-cn.com/problems/count-all-possible-routes)", "[\u7edf\u8ba1\u6240\u6709\u53ef\u884c\u8def\u5f84](/solution/1500-1599/1575.Count%20All%20Possible%20Routes/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1575](https://leetcode.com/problems/count-all-possible-routes)", "[Count All Possible Routes](/solution/1500-1599/1575.Count%20All%20Possible%20Routes/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1679", "frontend_question_id": "1574", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/shortest-subarray-to-be-removed-to-make-array-sorted", "url_en": "https://leetcode.com/problems/shortest-subarray-to-be-removed-to-make-array-sorted", "relative_path_cn": "/solution/1500-1599/1574.Shortest%20Subarray%20to%20be%20Removed%20to%20Make%20Array%20Sorted/README.md", "relative_path_en": "/solution/1500-1599/1574.Shortest%20Subarray%20to%20be%20Removed%20to%20Make%20Array%20Sorted/README_EN.md", "title_cn": "\u5220\u9664\u6700\u77ed\u7684\u5b50\u6570\u7ec4\u4f7f\u5269\u4f59\u6570\u7ec4\u6709\u5e8f", "title_en": "Shortest Subarray to be Removed to Make Array Sorted", "question_title_slug": "shortest-subarray-to-be-removed-to-make-array-sorted", "content_en": "

Given an integer array arr, remove a subarray (can be empty) from arr such that the remaining elements in arr are non-decreasing.

\n\n

A subarray is a contiguous subsequence of the array.

\n\n

Return the length of the shortest subarray to remove.

\n\n

 

\n

Example 1:

\n\n
\nInput: arr = [1,2,3,10,4,2,3,5]\nOutput: 3\nExplanation: The shortest subarray we can remove is [10,4,2] of length 3. The remaining elements after that will be [1,2,3,3,5] which are sorted.\nAnother correct solution is to remove the subarray [3,10,4].
\n\n

Example 2:

\n\n
\nInput: arr = [5,4,3,2,1]\nOutput: 4\nExplanation: Since the array is strictly decreasing, we can only keep a single element. Therefore we need to remove a subarray of length 4, either [5,4,3,2] or [4,3,2,1].\n
\n\n

Example 3:

\n\n
\nInput: arr = [1,2,3]\nOutput: 0\nExplanation: The array is already non-decreasing. We do not need to remove any elements.\n
\n\n

Example 4:

\n\n
\nInput: arr = [1]\nOutput: 0\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= arr.length <= 10^5
  • \n\t
  • 0 <= arr[i] <= 10^9
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr \uff0c\u8bf7\u4f60\u5220\u9664\u4e00\u4e2a\u5b50\u6570\u7ec4\uff08\u53ef\u4ee5\u4e3a\u7a7a\uff09\uff0c\u4f7f\u5f97 arr \u4e2d\u5269\u4e0b\u7684\u5143\u7d20\u662f \u975e\u9012\u51cf \u7684\u3002

\n\n

\u4e00\u4e2a\u5b50\u6570\u7ec4\u6307\u7684\u662f\u539f\u6570\u7ec4\u4e2d\u8fde\u7eed\u7684\u4e00\u4e2a\u5b50\u5e8f\u5217\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u6ee1\u8db3\u9898\u76ee\u8981\u6c42\u7684\u6700\u77ed\u5b50\u6570\u7ec4\u7684\u957f\u5ea6\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [1,2,3,10,4,2,3,5]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6211\u4eec\u9700\u8981\u5220\u9664\u7684\u6700\u77ed\u5b50\u6570\u7ec4\u662f [10,4,2] \uff0c\u957f\u5ea6\u4e3a 3 \u3002\u5269\u4f59\u5143\u7d20\u5f62\u6210\u975e\u9012\u51cf\u6570\u7ec4 [1,2,3,3,5] \u3002\n\u53e6\u4e00\u4e2a\u6b63\u786e\u7684\u89e3\u4e3a\u5220\u9664\u5b50\u6570\u7ec4 [3,10,4] \u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [5,4,3,2,1]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u7531\u4e8e\u6570\u7ec4\u662f\u4e25\u683c\u9012\u51cf\u7684\uff0c\u6211\u4eec\u53ea\u80fd\u4fdd\u7559\u4e00\u4e2a\u5143\u7d20\u3002\u6240\u4ee5\u6211\u4eec\u9700\u8981\u5220\u9664\u957f\u5ea6\u4e3a 4 \u7684\u5b50\u6570\u7ec4\uff0c\u8981\u4e48\u5220\u9664 [5,4,3,2]\uff0c\u8981\u4e48\u5220\u9664 [4,3,2,1]\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [1,2,3]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6570\u7ec4\u5df2\u7ecf\u662f\u975e\u9012\u51cf\u7684\u4e86\uff0c\u6211\u4eec\u4e0d\u9700\u8981\u5220\u9664\u4efb\u4f55\u5143\u7d20\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [1]\n\u8f93\u51fa\uff1a0\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= arr.length <= 10^5
  • \n\t
  • 0 <= arr[i] <= 10^9
  • \n
\n", "tags_en": ["Array", "Binary Search"], "tags_cn": ["\u6570\u7ec4", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findLengthOfShortestSubarray(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findLengthOfShortestSubarray(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findLengthOfShortestSubarray(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findLengthOfShortestSubarray(self, arr: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findLengthOfShortestSubarray(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindLengthOfShortestSubarray(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar findLengthOfShortestSubarray = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef find_length_of_shortest_subarray(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findLengthOfShortestSubarray(_ arr: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findLengthOfShortestSubarray(arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findLengthOfShortestSubarray(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findLengthOfShortestSubarray(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_length_of_shortest_subarray(arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function findLengthOfShortestSubarray($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findLengthOfShortestSubarray(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-length-of-shortest-subarray arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1574](https://leetcode-cn.com/problems/shortest-subarray-to-be-removed-to-make-array-sorted)", "[\u5220\u9664\u6700\u77ed\u7684\u5b50\u6570\u7ec4\u4f7f\u5269\u4f59\u6570\u7ec4\u6709\u5e8f](/solution/1500-1599/1574.Shortest%20Subarray%20to%20be%20Removed%20to%20Make%20Array%20Sorted/README.md)", "`\u6570\u7ec4`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1574](https://leetcode.com/problems/shortest-subarray-to-be-removed-to-make-array-sorted)", "[Shortest Subarray to be Removed to Make Array Sorted](/solution/1500-1599/1574.Shortest%20Subarray%20to%20be%20Removed%20to%20Make%20Array%20Sorted/README_EN.md)", "`Array`,`Binary Search`", "Medium", ""]}, {"question_id": "1678", "frontend_question_id": "1573", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-ways-to-split-a-string", "url_en": "https://leetcode.com/problems/number-of-ways-to-split-a-string", "relative_path_cn": "/solution/1500-1599/1573.Number%20of%20Ways%20to%20Split%20a%20String/README.md", "relative_path_en": "/solution/1500-1599/1573.Number%20of%20Ways%20to%20Split%20a%20String/README_EN.md", "title_cn": "\u5206\u5272\u5b57\u7b26\u4e32\u7684\u65b9\u6848\u6570", "title_en": "Number of Ways to Split a String", "question_title_slug": "number-of-ways-to-split-a-string", "content_en": "

Given a binary string s (a string consisting only of '0's and '1's), we can split s into 3 non-empty strings s1, s2, s3 (s1+ s2+ s3 = s).

\n\n

Return the number of ways s can be split such that the number of characters '1' is the same in s1, s2, and s3.

\n\n

Since the answer may be too large, return it modulo 10^9 + 7.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "10101"\nOutput: 4\nExplanation: There are four ways to split s in 3 parts where each part contain the same number of letters '1'.\n"1|010|1"\n"1|01|01"\n"10|10|1"\n"10|1|01"\n
\n\n

Example 2:

\n\n
\nInput: s = "1001"\nOutput: 0\n
\n\n

Example 3:

\n\n
\nInput: s = "0000"\nOutput: 3\nExplanation: There are three ways to split s in 3 parts.\n"0|0|00"\n"0|00|0"\n"00|0|0"\n
\n\n

Example 4:

\n\n
\nInput: s = "100100010100110"\nOutput: 12\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 3 <= s.length <= 10^5
  • \n\t
  • s[i] is '0' or '1'.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u4e8c\u8fdb\u5236\u4e32 s  \uff08\u4e00\u4e2a\u53ea\u5305\u542b 0 \u548c 1 \u7684\u5b57\u7b26\u4e32\uff09\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06 s \u5206\u5272\u6210 3 \u4e2a \u975e\u7a7a \u5b57\u7b26\u4e32 s1, s2, s3 \uff08s1 + s2 + s3 = s\uff09\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u5206\u5272 s \u7684\u65b9\u6848\u6570\uff0c\u6ee1\u8db3 s1\uff0cs2 \u548c s3 \u4e2d\u5b57\u7b26 '1' \u7684\u6570\u76ee\u76f8\u540c\u3002

\n\n

\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u5f88\u5927\uff0c\u8bf7\u5c06\u5b83\u5bf9 10^9 + 7 \u53d6\u4f59\u540e\u8fd4\u56de\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1as = "10101"\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u603b\u5171\u6709 4 \u79cd\u65b9\u6cd5\u5c06 s \u5206\u5272\u6210\u542b\u6709 '1' \u6570\u76ee\u76f8\u540c\u7684\u4e09\u4e2a\u5b50\u5b57\u7b26\u4e32\u3002\n"1|010|1"\n"1|01|01"\n"10|10|1"\n"10|1|01"\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1as = "1001"\n\u8f93\u51fa\uff1a0\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1as = "0000"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u603b\u5171\u6709 3 \u79cd\u5206\u5272 s \u7684\u65b9\u6cd5\u3002\n"0|0|00"\n"0|00|0"\n"00|0|0"\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1as = "100100010100110"\n\u8f93\u51fa\uff1a12\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • s[i] == '0' \u6216\u8005 s[i] == '1'
  • \n\t
  • 3 <= s.length <= 10^5
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numWays(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numWays(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numWays(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numWays(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numWays(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumWays(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar numWays = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef num_ways(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numWays(_ s: String) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numWays(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numWays(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numWays(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_ways(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function numWays($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numWays(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-ways s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1573](https://leetcode-cn.com/problems/number-of-ways-to-split-a-string)", "[\u5206\u5272\u5b57\u7b26\u4e32\u7684\u65b9\u6848\u6570](/solution/1500-1599/1573.Number%20of%20Ways%20to%20Split%20a%20String/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1573](https://leetcode.com/problems/number-of-ways-to-split-a-string)", "[Number of Ways to Split a String](/solution/1500-1599/1573.Number%20of%20Ways%20to%20Split%20a%20String/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "1677", "frontend_question_id": "1572", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/matrix-diagonal-sum", "url_en": "https://leetcode.com/problems/matrix-diagonal-sum", "relative_path_cn": "/solution/1500-1599/1572.Matrix%20Diagonal%20Sum/README.md", "relative_path_en": "/solution/1500-1599/1572.Matrix%20Diagonal%20Sum/README_EN.md", "title_cn": "\u77e9\u9635\u5bf9\u89d2\u7ebf\u5143\u7d20\u7684\u548c", "title_en": "Matrix Diagonal Sum", "question_title_slug": "matrix-diagonal-sum", "content_en": "

Given a square matrix mat, return the sum of the matrix diagonals.

\n\n

Only include the sum of all the elements on the primary diagonal and all the elements on the secondary diagonal that are not part of the primary diagonal.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: mat = [[1,2,3],\n              [4,5,6],\n              [7,8,9]]\nOutput: 25\nExplanation: Diagonals sum: 1 + 5 + 9 + 3 + 7 = 25\nNotice that element mat[1][1] = 5 is counted only once.\n
\n\n

Example 2:

\n\n
\nInput: mat = [[1,1,1,1],\n              [1,1,1,1],\n              [1,1,1,1],\n              [1,1,1,1]]\nOutput: 8\n
\n\n

Example 3:

\n\n
\nInput: mat = [[5]]\nOutput: 5\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == mat.length == mat[i].length
  • \n\t
  • 1 <= n <= 100
  • \n\t
  • 1 <= mat[i][j] <= 100
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6b63\u65b9\u5f62\u77e9\u9635 mat\uff0c\u8bf7\u4f60\u8fd4\u56de\u77e9\u9635\u5bf9\u89d2\u7ebf\u5143\u7d20\u7684\u548c\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u5728\u77e9\u9635\u4e3b\u5bf9\u89d2\u7ebf\u4e0a\u7684\u5143\u7d20\u548c\u526f\u5bf9\u89d2\u7ebf\u4e0a\u4e14\u4e0d\u5728\u4e3b\u5bf9\u89d2\u7ebf\u4e0a\u5143\u7d20\u7684\u548c\u3002

\n\n

 

\n\n

\u793a\u4f8b  1\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1amat = [[1,2,3],\n            [4,5,6],\n            [7,8,9]]\n\u8f93\u51fa\uff1a25\n\u89e3\u91ca\uff1a\u5bf9\u89d2\u7ebf\u7684\u548c\u4e3a\uff1a1 + 5 + 9 + 3 + 7 = 25\n\u8bf7\u6ce8\u610f\uff0c\u5143\u7d20 mat[1][1] = 5 \u53ea\u4f1a\u88ab\u8ba1\u7b97\u4e00\u6b21\u3002\n
\n\n

\u793a\u4f8b  2\uff1a

\n\n
\n\u8f93\u5165\uff1amat = [[1,1,1,1],\n            [1,1,1,1],\n            [1,1,1,1],\n            [1,1,1,1]]\n\u8f93\u51fa\uff1a8\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1amat = [[5]]\n\u8f93\u51fa\uff1a5\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • n == mat.length == mat[i].length
  • \n\t
  • 1 <= n <= 100
  • \n\t
  • 1 <= mat[i][j] <= 100
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int diagonalSum(vector>& mat) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int diagonalSum(int[][] mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def diagonalSum(self, mat):\n \"\"\"\n :type mat: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def diagonalSum(self, mat: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint diagonalSum(int** mat, int matSize, int* matColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int DiagonalSum(int[][] mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} mat\n * @return {number}\n */\nvar diagonalSum = function(mat) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} mat\n# @return {Integer}\ndef diagonal_sum(mat)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func diagonalSum(_ mat: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func diagonalSum(mat [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def diagonalSum(mat: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun diagonalSum(mat: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn diagonal_sum(mat: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $mat\n * @return Integer\n */\n function diagonalSum($mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function diagonalSum(mat: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (diagonal-sum mat)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1572](https://leetcode-cn.com/problems/matrix-diagonal-sum)", "[\u77e9\u9635\u5bf9\u89d2\u7ebf\u5143\u7d20\u7684\u548c](/solution/1500-1599/1572.Matrix%20Diagonal%20Sum/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1572](https://leetcode.com/problems/matrix-diagonal-sum)", "[Matrix Diagonal Sum](/solution/1500-1599/1572.Matrix%20Diagonal%20Sum/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1676", "frontend_question_id": "1553", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-number-of-days-to-eat-n-oranges", "url_en": "https://leetcode.com/problems/minimum-number-of-days-to-eat-n-oranges", "relative_path_cn": "/solution/1500-1599/1553.Minimum%20Number%20of%20Days%20to%20Eat%20N%20Oranges/README.md", "relative_path_en": "/solution/1500-1599/1553.Minimum%20Number%20of%20Days%20to%20Eat%20N%20Oranges/README_EN.md", "title_cn": "\u5403\u6389 N \u4e2a\u6a58\u5b50\u7684\u6700\u5c11\u5929\u6570", "title_en": "Minimum Number of Days to Eat N Oranges", "question_title_slug": "minimum-number-of-days-to-eat-n-oranges", "content_en": "

There are n oranges in the kitchen and you decided to eat some of these oranges every day as follows:

\r\n\r\n
    \r\n\t
  • Eat one orange.
  • \r\n\t
  • If the number of remaining oranges (n) is divisible by 2 then you can eat  n/2 oranges.
  • \r\n\t
  • If the number of remaining oranges (n) is divisible by 3 then you can eat  2*(n/3) oranges.
  • \r\n
\r\n\r\n

You can only choose one of the actions per day.

\r\n\r\n

Return the minimum number of days to eat n oranges.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: n = 10\r\nOutput: 4\r\nExplanation: You have 10 oranges.\r\nDay 1: Eat 1 orange,  10 - 1 = 9.  \r\nDay 2: Eat 6 oranges, 9 - 2*(9/3) = 9 - 6 = 3. (Since 9 is divisible by 3)\r\nDay 3: Eat 2 oranges, 3 - 2*(3/3) = 3 - 2 = 1. \r\nDay 4: Eat the last orange  1 - 1  = 0.\r\nYou need at least 4 days to eat the 10 oranges.\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: n = 6\r\nOutput: 3\r\nExplanation: You have 6 oranges.\r\nDay 1: Eat 3 oranges, 6 - 6/2 = 6 - 3 = 3. (Since 6 is divisible by 2).\r\nDay 2: Eat 2 oranges, 3 - 2*(3/3) = 3 - 2 = 1. (Since 3 is divisible by 3)\r\nDay 3: Eat the last orange  1 - 1  = 0.\r\nYou need at least 3 days to eat the 6 oranges.\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: n = 1\r\nOutput: 1\r\n
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: n = 56\r\nOutput: 6\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= n <= 2*10^9
  • \r\n
", "content_cn": "

\u53a8\u623f\u91cc\u603b\u5171\u6709 n \u4e2a\u6a58\u5b50\uff0c\u4f60\u51b3\u5b9a\u6bcf\u4e00\u5929\u9009\u62e9\u5982\u4e0b\u65b9\u5f0f\u4e4b\u4e00\u5403\u8fd9\u4e9b\u6a58\u5b50\uff1a

\n\n
    \n\t
  • \u5403\u6389\u4e00\u4e2a\u6a58\u5b50\u3002
  • \n\t
  • \u5982\u679c\u5269\u4f59\u6a58\u5b50\u6570 n \u80fd\u88ab 2 \u6574\u9664\uff0c\u90a3\u4e48\u4f60\u53ef\u4ee5\u5403\u6389 n/2 \u4e2a\u6a58\u5b50\u3002
  • \n\t
  • \u5982\u679c\u5269\u4f59\u6a58\u5b50\u6570 n \u80fd\u88ab 3 \u6574\u9664\uff0c\u90a3\u4e48\u4f60\u53ef\u4ee5\u5403\u6389 2*(n/3) \u4e2a\u6a58\u5b50\u3002
  • \n
\n\n

\u6bcf\u5929\u4f60\u53ea\u80fd\u4ece\u4ee5\u4e0a 3 \u79cd\u65b9\u6848\u4e2d\u9009\u62e9\u4e00\u79cd\u65b9\u6848\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u5403\u6389\u6240\u6709 n \u4e2a\u6a58\u5b50\u7684\u6700\u5c11\u5929\u6570\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1an = 10\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u4f60\u603b\u5171\u6709 10 \u4e2a\u6a58\u5b50\u3002\n\u7b2c 1 \u5929\uff1a\u5403 1 \u4e2a\u6a58\u5b50\uff0c\u5269\u4f59\u6a58\u5b50\u6570 10 - 1 = 9\u3002\n\u7b2c 2 \u5929\uff1a\u5403 6 \u4e2a\u6a58\u5b50\uff0c\u5269\u4f59\u6a58\u5b50\u6570 9 - 2*(9/3) = 9 - 6 = 3\u3002\uff089 \u53ef\u4ee5\u88ab 3 \u6574\u9664\uff09\n\u7b2c 3 \u5929\uff1a\u5403 2 \u4e2a\u6a58\u5b50\uff0c\u5269\u4f59\u6a58\u5b50\u6570 3 - 2*(3/3) = 3 - 2 = 1\u3002\n\u7b2c 4 \u5929\uff1a\u5403\u6389\u6700\u540e 1 \u4e2a\u6a58\u5b50\uff0c\u5269\u4f59\u6a58\u5b50\u6570 1 - 1 = 0\u3002\n\u4f60\u9700\u8981\u81f3\u5c11 4 \u5929\u5403\u6389 10 \u4e2a\u6a58\u5b50\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1an = 6\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u4f60\u603b\u5171\u6709 6 \u4e2a\u6a58\u5b50\u3002\n\u7b2c 1 \u5929\uff1a\u5403 3 \u4e2a\u6a58\u5b50\uff0c\u5269\u4f59\u6a58\u5b50\u6570 6 - 6/2 = 6 - 3 = 3\u3002\uff086 \u53ef\u4ee5\u88ab 2 \u6574\u9664\uff09\n\u7b2c 2 \u5929\uff1a\u5403 2 \u4e2a\u6a58\u5b50\uff0c\u5269\u4f59\u6a58\u5b50\u6570 3 - 2*(3/3) = 3 - 2 = 1\u3002\uff083 \u53ef\u4ee5\u88ab 3 \u6574\u9664\uff09\n\u7b2c 3 \u5929\uff1a\u5403\u6389\u5269\u4f59 1 \u4e2a\u6a58\u5b50\uff0c\u5269\u4f59\u6a58\u5b50\u6570 1 - 1 = 0\u3002\n\u4f60\u81f3\u5c11\u9700\u8981 3 \u5929\u5403\u6389 6 \u4e2a\u6a58\u5b50\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1a1\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1an = 56\n\u8f93\u51fa\uff1a6\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 2*10^9
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minDays(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minDays(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minDays(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minDays(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minDays(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinDays(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar minDays = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef min_days(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minDays(_ n: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minDays(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minDays(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minDays(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_days(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function minDays($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minDays(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-days n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1553](https://leetcode-cn.com/problems/minimum-number-of-days-to-eat-n-oranges)", "[\u5403\u6389 N \u4e2a\u6a58\u5b50\u7684\u6700\u5c11\u5929\u6570](/solution/1500-1599/1553.Minimum%20Number%20of%20Days%20to%20Eat%20N%20Oranges/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1553](https://leetcode.com/problems/minimum-number-of-days-to-eat-n-oranges)", "[Minimum Number of Days to Eat N Oranges](/solution/1500-1599/1553.Minimum%20Number%20of%20Days%20to%20Eat%20N%20Oranges/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1675", "frontend_question_id": "1552", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/magnetic-force-between-two-balls", "url_en": "https://leetcode.com/problems/magnetic-force-between-two-balls", "relative_path_cn": "/solution/1500-1599/1552.Magnetic%20Force%20Between%20Two%20Balls/README.md", "relative_path_en": "/solution/1500-1599/1552.Magnetic%20Force%20Between%20Two%20Balls/README_EN.md", "title_cn": "\u4e24\u7403\u4e4b\u95f4\u7684\u78c1\u529b", "title_en": "Magnetic Force Between Two Balls", "question_title_slug": "magnetic-force-between-two-balls", "content_en": "

In universe Earth C-137, Rick discovered a special form of magnetic force between two balls if they are put in his new invented basket. Rick has n empty baskets, the ith basket is at position[i], Morty has m balls and needs to distribute the balls into the baskets such that the minimum magnetic force between any two balls is maximum.

\n\n

Rick stated that magnetic force between two different balls at positions x and y is |x - y|.

\n\n

Given the integer array position and the integer m. Return the required force.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: position = [1,2,3,4,7], m = 3\nOutput: 3\nExplanation: Distributing the 3 balls into baskets 1, 4 and 7 will make the magnetic force between ball pairs [3, 3, 6]. The minimum magnetic force is 3. We cannot achieve a larger minimum magnetic force than 3.\n
\n\n

Example 2:

\n\n
\nInput: position = [5,4,3,2,1,1000000000], m = 2\nOutput: 999999999\nExplanation: We can use baskets 1 and 1000000000.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == position.length
  • \n\t
  • 2 <= n <= 10^5
  • \n\t
  • 1 <= position[i] <= 10^9
  • \n\t
  • All integers in position are distinct.
  • \n\t
  • 2 <= m <= position.length
  • \n
\n", "content_cn": "

\u5728\u4ee3\u53f7\u4e3a C-137 \u7684\u5730\u7403\u4e0a\uff0cRick \u53d1\u73b0\u5982\u679c\u4ed6\u5c06\u4e24\u4e2a\u7403\u653e\u5728\u4ed6\u65b0\u53d1\u660e\u7684\u7bee\u5b50\u91cc\uff0c\u5b83\u4eec\u4e4b\u95f4\u4f1a\u5f62\u6210\u7279\u6b8a\u5f62\u5f0f\u7684\u78c1\u529b\u3002Rick \u6709 n \u4e2a\u7a7a\u7684\u7bee\u5b50\uff0c\u7b2c i \u4e2a\u7bee\u5b50\u7684\u4f4d\u7f6e\u5728 position[i] \uff0cMorty \u60f3\u628a m \u4e2a\u7403\u653e\u5230\u8fd9\u4e9b\u7bee\u5b50\u91cc\uff0c\u4f7f\u5f97\u4efb\u610f\u4e24\u7403\u95f4 \u6700\u5c0f\u78c1\u529b \u6700\u5927\u3002

\n\n

\u5df2\u77e5\u4e24\u4e2a\u7403\u5982\u679c\u5206\u522b\u4f4d\u4e8e x \u548c y \uff0c\u90a3\u4e48\u5b83\u4eec\u4e4b\u95f4\u7684\u78c1\u529b\u4e3a |x - y| \u3002

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 position \u548c\u4e00\u4e2a\u6574\u6570 m \uff0c\u8bf7\u4f60\u8fd4\u56de\u6700\u5927\u5316\u7684\u6700\u5c0f\u78c1\u529b\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1aposition = [1,2,3,4,7], m = 3\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u5c06 3 \u4e2a\u7403\u5206\u522b\u653e\u5165\u4f4d\u4e8e 1\uff0c4 \u548c 7 \u7684\u4e09\u4e2a\u7bee\u5b50\uff0c\u4e24\u7403\u95f4\u7684\u78c1\u529b\u5206\u522b\u4e3a [3, 3, 6]\u3002\u6700\u5c0f\u78c1\u529b\u4e3a 3 \u3002\u6211\u4eec\u6ca1\u529e\u6cd5\u8ba9\u6700\u5c0f\u78c1\u529b\u5927\u4e8e 3 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aposition = [5,4,3,2,1,1000000000], m = 2\n\u8f93\u51fa\uff1a999999999\n\u89e3\u91ca\uff1a\u6211\u4eec\u4f7f\u7528\u4f4d\u4e8e 1 \u548c 1000000000 \u7684\u7bee\u5b50\u65f6\u6700\u5c0f\u78c1\u529b\u6700\u5927\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • n == position.length
  • \n\t
  • 2 <= n <= 10^5
  • \n\t
  • 1 <= position[i] <= 10^9
  • \n\t
  • \u6240\u6709 position \u4e2d\u7684\u6574\u6570 \u4e92\u4e0d\u76f8\u540c \u3002
  • \n\t
  • 2 <= m <= position.length
  • \n
\n", "tags_en": ["Array", "Binary Search"], "tags_cn": ["\u6570\u7ec4", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxDistance(vector& position, int m) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxDistance(int[] position, int m) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxDistance(self, position, m):\n \"\"\"\n :type position: List[int]\n :type m: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxDistance(self, position: List[int], m: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxDistance(int* position, int positionSize, int m){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxDistance(int[] position, int m) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} position\n * @param {number} m\n * @return {number}\n */\nvar maxDistance = function(position, m) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} position\n# @param {Integer} m\n# @return {Integer}\ndef max_distance(position, m)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxDistance(_ position: [Int], _ m: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxDistance(position []int, m int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxDistance(position: Array[Int], m: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxDistance(position: IntArray, m: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_distance(position: Vec, m: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $position\n * @param Integer $m\n * @return Integer\n */\n function maxDistance($position, $m) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxDistance(position: number[], m: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-distance position m)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1552](https://leetcode-cn.com/problems/magnetic-force-between-two-balls)", "[\u4e24\u7403\u4e4b\u95f4\u7684\u78c1\u529b](/solution/1500-1599/1552.Magnetic%20Force%20Between%20Two%20Balls/README.md)", "`\u6570\u7ec4`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1552](https://leetcode.com/problems/magnetic-force-between-two-balls)", "[Magnetic Force Between Two Balls](/solution/1500-1599/1552.Magnetic%20Force%20Between%20Two%20Balls/README_EN.md)", "`Array`,`Binary Search`", "Medium", ""]}, {"question_id": "1674", "frontend_question_id": "1551", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-operations-to-make-array-equal", "url_en": "https://leetcode.com/problems/minimum-operations-to-make-array-equal", "relative_path_cn": "/solution/1500-1599/1551.Minimum%20Operations%20to%20Make%20Array%20Equal/README.md", "relative_path_en": "/solution/1500-1599/1551.Minimum%20Operations%20to%20Make%20Array%20Equal/README_EN.md", "title_cn": "\u4f7f\u6570\u7ec4\u4e2d\u6240\u6709\u5143\u7d20\u76f8\u7b49\u7684\u6700\u5c0f\u64cd\u4f5c\u6570", "title_en": "Minimum Operations to Make Array Equal", "question_title_slug": "minimum-operations-to-make-array-equal", "content_en": "

You have an array arr of length n where arr[i] = (2 * i) + 1 for all valid values of i (i.e. 0 <= i < n).

\r\n\r\n

In one operation, you can select two indices x and y where 0 <= x, y < n and subtract 1 from arr[x] and add 1 to arr[y] (i.e. perform arr[x] -=1 and arr[y] += 1). The goal is to make all the elements of the array equal. It is guaranteed that all the elements of the array can be made equal using some operations.

\r\n\r\n

Given an integer n, the length of the array. Return the minimum number of operations needed to make all the elements of arr equal.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: n = 3\r\nOutput: 2\r\nExplanation: arr = [1, 3, 5]\r\nFirst operation choose x = 2 and y = 0, this leads arr to be [2, 3, 4]\r\nIn the second operation choose x = 2 and y = 0 again, thus arr = [3, 3, 3].\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: n = 6\r\nOutput: 9\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= n <= 10^4
  • \r\n
", "content_cn": "

\u5b58\u5728\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u6570\u7ec4 arr \uff0c\u5176\u4e2d arr[i] = (2 * i) + 1 \uff08 0 <= i < n \uff09\u3002

\n\n

\u4e00\u6b21\u64cd\u4f5c\u4e2d\uff0c\u4f60\u53ef\u4ee5\u9009\u51fa\u4e24\u4e2a\u4e0b\u6807\uff0c\u8bb0\u4f5c x \u548c y \uff08 0 <= x, y < n \uff09\u5e76\u4f7f arr[x] \u51cf\u53bb 1 \u3001arr[y] \u52a0\u4e0a 1 \uff08\u5373 arr[x] -=1 \u4e14 arr[y] += 1 \uff09\u3002\u6700\u7ec8\u7684\u76ee\u6807\u662f\u4f7f\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u90fd \u76f8\u7b49 \u3002\u9898\u76ee\u6d4b\u8bd5\u7528\u4f8b\u5c06\u4f1a \u4fdd\u8bc1 \uff1a\u5728\u6267\u884c\u82e5\u5e72\u6b65\u64cd\u4f5c\u540e\uff0c\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u6700\u7ec8\u53ef\u4ee5\u5168\u90e8\u76f8\u7b49\u3002

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n\uff0c\u5373\u6570\u7ec4\u7684\u957f\u5ea6\u3002\u8bf7\u4f60\u8fd4\u56de\u4f7f\u6570\u7ec4 arr \u4e2d\u6240\u6709\u5143\u7d20\u76f8\u7b49\u6240\u9700\u7684 \u6700\u5c0f\u64cd\u4f5c\u6570 \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1an = 3\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1aarr = [1, 3, 5]\n\u7b2c\u4e00\u6b21\u64cd\u4f5c\u9009\u51fa x = 2 \u548c y = 0\uff0c\u4f7f\u6570\u7ec4\u53d8\u4e3a [2, 3, 4]\n\u7b2c\u4e8c\u6b21\u64cd\u4f5c\u7ee7\u7eed\u9009\u51fa x = 2 \u548c y = 0\uff0c\u6570\u7ec4\u5c06\u4f1a\u53d8\u6210 [3, 3, 3]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1an = 6\n\u8f93\u51fa\uff1a9\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 10^4
  • \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minOperations(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minOperations(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minOperations(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minOperations(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minOperations(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinOperations(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar minOperations = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef min_operations(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minOperations(_ n: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minOperations(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minOperations(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minOperations(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_operations(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function minOperations($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minOperations(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-operations n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1551](https://leetcode-cn.com/problems/minimum-operations-to-make-array-equal)", "[\u4f7f\u6570\u7ec4\u4e2d\u6240\u6709\u5143\u7d20\u76f8\u7b49\u7684\u6700\u5c0f\u64cd\u4f5c\u6570](/solution/1500-1599/1551.Minimum%20Operations%20to%20Make%20Array%20Equal/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1551](https://leetcode.com/problems/minimum-operations-to-make-array-equal)", "[Minimum Operations to Make Array Equal](/solution/1500-1599/1551.Minimum%20Operations%20to%20Make%20Array%20Equal/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "1672", "frontend_question_id": "1533", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/find-the-index-of-the-large-integer", "url_en": "https://leetcode.com/problems/find-the-index-of-the-large-integer", "relative_path_cn": "/solution/1500-1599/1533.Find%20the%20Index%20of%20the%20Large%20Integer/README.md", "relative_path_en": "/solution/1500-1599/1533.Find%20the%20Index%20of%20the%20Large%20Integer/README_EN.md", "title_cn": "\u627e\u5230\u6700\u5927\u6574\u6570\u7684\u7d22\u5f15", "title_en": "Find the Index of the Large Integer", "question_title_slug": "find-the-index-of-the-large-integer", "content_en": "

We have an integer array arr, where all the integers in arr are equal except for one integer which is larger than the rest of the integers. You will not be given direct access to the array, instead, you will have an API ArrayReader which have the following functions:

\n\n
    \n\t
  • int compareSub(int l, int r, int x, int y): where 0 <= l, r, x, y < ArrayReader.length(), l <= r and x <= y. The function compares the sum of sub-array arr[l..r] with the sum of the sub-array arr[x..y] and returns:\n\n\t
      \n\t\t
    • 1 if arr[l]+arr[l+1]+...+arr[r] > arr[x]+arr[x+1]+...+arr[y].
    • \n\t\t
    • 0 if arr[l]+arr[l+1]+...+arr[r] == arr[x]+arr[x+1]+...+arr[y].
    • \n\t\t
    • -1 if arr[l]+arr[l+1]+...+arr[r] < arr[x]+arr[x+1]+...+arr[y].
    • \n\t
    \n\t
  • \n\t
  • int length(): Returns the size of the array.
  • \n
\n\n

You are allowed to call compareSub() 20 times at most. You can assume both functions work in O(1) time.

\n\n

Return the index of the array arr which has the largest integer.

\n\n

Follow-up:

\n\n
    \n\t
  • What if there are two numbers in arr that are bigger than all other numbers?
  • \n\t
  • What if there is one number that is bigger than other numbers and one number that is smaller than other numbers?
  • \n
\n\n

 

\n

Example 1:

\n\n
\nInput: arr = [7,7,7,7,10,7,7,7]\nOutput: 4\nExplanation: The following calls to the API\nreader.compareSub(0, 0, 1, 1) // returns 0 this is a query comparing the sub-array (0, 0) with the sub array (1, 1), (i.e. compares arr[0] with arr[1]).\nThus we know that arr[0] and arr[1] doesn't contain the largest element.\nreader.compareSub(2, 2, 3, 3) // returns 0, we can exclude arr[2] and arr[3].\nreader.compareSub(4, 4, 5, 5) // returns 1, thus for sure arr[4] is the largest element in the array.\nNotice that we made only 3 calls, so the answer is valid.\n
\n\n

Example 2:

\n\n
\nInput: nums = [6,6,12]\nOutput: 2\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= arr.length <= 5 * 10^5
  • \n\t
  • 1 <= arr[i] <= 100
  • \n\t
  • All elements of arr are equal except for one element which is larger than all other elements.
  • \n
\n", "content_cn": "

\u6211\u4eec\u6709\u8fd9\u6837\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr \uff0c\u9664\u4e86\u4e00\u4e2a\u6700\u5927\u7684\u6574\u6570\u5916\uff0c\u5176\u4ed6\u6240\u6709\u6574\u6570\u90fd\u76f8\u7b49\u3002\u4f60\u4e0d\u80fd\u76f4\u63a5\u8bbf\u95ee\u8be5\u6570\u7ec4\uff0c\u4f60\u9700\u8981\u901a\u8fc7 API ArrayReader \u6765\u95f4\u63a5\u8bbf\u95ee\uff0c\u8fd9\u4e2a API \u6709\u4ee5\u4e0b\u6210\u5458\u51fd\u6570\uff1a

\n\n
    \n\t
  • int compareSub(int l, int r, int x, int y)\uff1a\u5176\u4e2d 0 <= l, r, x, y < ArrayReader.length()\uff0c l <= r \u4e14 x <= y\u3002\u8fd9\u4e2a\u51fd\u6570\u6bd4\u8f83\u5b50\u6570\u7ec4 arr[l..r] \u4e0e\u5b50\u6570\u7ec4 arr[x..y] \u7684\u548c\u3002\u8be5\u51fd\u6570\u8fd4\u56de\uff1a\n\n\t
      \n\t\t
    • 1 \u82e5 arr[l]+arr[l+1]+...+arr[r] > arr[x]+arr[x+1]+...+arr[y] \u3002
    • \n\t\t
    • 0 \u82e5 arr[l]+arr[l+1]+...+arr[r] == arr[x]+arr[x+1]+...+arr[y] \u3002
    • \n\t\t
    • -1 \u82e5 arr[l]+arr[l+1]+...+arr[r] < arr[x]+arr[x+1]+...+arr[y] \u3002
    • \n\t
    \n\t
  • \n\t
  • int length()\uff1a\u8fd4\u56de\u6570\u7ec4\u7684\u957f\u5ea6\u3002
  • \n
\n\n

\u4f60\u6700\u591a\u53ef\u4ee5\u8c03\u7528\u51fd\u6570 compareSub() 20 \u6b21\u3002\u4f60\u53ef\u4ee5\u8ba4\u4e3a\u8fd9\u4e24\u4e2a\u51fd\u6570\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u90fd\u4e3a O(1) \u3002

\n\n

\u8fd4\u56de arr \u4e2d\u6700\u5927\u6574\u6570\u7684\u7d22\u5f15\u3002

\n\n

\u8fdb\u9636

\n\n
    \n\t
  • \u5982\u679c arr \u4e2d\u6709\u4e24\u4e2a\u6574\u6570\u6bd4\u5176\u4ed6\u6570\u5927\u5462\uff1f
  • \n\t
  • \u5982\u679c\u6709\u4e00\u4e2a\u6570\u6bd4\u5176\u4ed6\u6570\u5927\uff0c\u53e6\u4e00\u4e2a\u6570\u6bd4\u5176\u4ed6\u6570\u5c0f\u5462\uff1f
  • \n
\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165: arr = [7,7,7,7,10,7,7,7]\n\u8f93\u51fa: 4\n\u89e3\u91ca: API \u7684\u8c03\u7528\u5982\u4e0b\uff1a\nreader.compareSub(0, 0, 1, 1) // \u8fd4\u56de 0\u3002\u6bd4\u8f83\u5b50\u6570\u7ec4 (0, 0) \u4e0e\u5b50\u6570\u7ec4 (1, 1) \uff08\u5373\u6bd4\u8f83 arr[0] \u548c arr[1]\uff09\u3002\n\u56e0\u6b64\u6211\u4eec\u77e5\u9053 arr[0] \u548c arr[1] \u4e0d\u5305\u542b\u6700\u5927\u5143\u7d20\u3002\nreader.compareSub(2, 2, 3, 3) // \u8fd4\u56de 0\u3002\u6211\u4eec\u53ef\u4ee5\u6392\u9664 arr[2] \u548c arr[3]\u3002\nreader.compareSub(4, 4, 5, 5) // \u8fd4\u56de 1\u3002\u56e0\u6b64\uff0c\u53ef\u4ee5\u786e\u5b9a arr[4] \u662f\u6570\u7ec4\u4e2d\u6700\u5927\u7684\u5143\u7d20\u3002\n\u6ce8\u610f\uff0c\u6211\u4eec\u53ea\u8c03\u7528\u4e86 3 \u6b21 compareSub\uff0c\u6240\u4ee5\u8fd9\u4e2a\u7b54\u6848\u662f\u6709\u6548\u7684\u3002\n
\n\n

\u793a\u4f8b 2:

\n\n
\u8f93\u5165: nums = [6,6,12]\n\u8f93\u51fa: 2\n
\n\n

 

\n\n

\u63d0\u793a:

\n\n
    \n\t
  • 2 <= arr.length <= 5 * 10^5
  • \n\t
  • 1 <= arr[i] <= 100
  • \n\t
  • arr \u4e2d\u9664\u4e00\u4e2a\u6700\u5927\u5143\u7d20\u5916\uff0c\u5176\u4f59\u6240\u6709\u5143\u7d20\u90fd\u76f8\u7b49\u3002
  • \n
\n", "tags_en": ["Binary Search"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * // This is the ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * class ArrayReader {\n * public:\n * // Compares the sum of arr[l..r] with the sum of arr[x..y] \n * // return 1 if sum(arr[l..r]) > sum(arr[x..y])\n * // return 0 if sum(arr[l..r]) == sum(arr[x..y])\n * // return -1 if sum(arr[l..r]) < sum(arr[x..y])\n * int compareSub(int l, int r, int x, int y);\n *\n * // Returns the length of the array\n * int length();\n * };\n */\n\nclass Solution {\npublic:\n int getIndex(ArrayReader &reader) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * // This is ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * interface ArrayReader {\n * // Compares the sum of arr[l..r] with the sum of arr[x..y] \n * // return 1 if sum(arr[l..r]) > sum(arr[x..y])\n * // return 0 if sum(arr[l..r]) == sum(arr[x..y])\n * // return -1 if sum(arr[l..r]) < sum(arr[x..y])\n * public int compareSub(int l, int r, int x, int y) {}\n *\n * // Returns the length of the array\n * public int length() {}\n * }\n */\n\nclass Solution {\n public int getIndex(ArrayReader reader) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# \"\"\"\n# This is ArrayReader's API interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class ArrayReader(object):\n#\t # Compares the sum of arr[l..r] with the sum of arr[x..y]\n#\t # return 1 if sum(arr[l..r]) > sum(arr[x..y])\n#\t # return 0 if sum(arr[l..r]) == sum(arr[x..y])\n#\t # return -1 if sum(arr[l..r]) < sum(arr[x..y])\n# def compareSub(self, l, r, x, y):\n# \"\"\"\n# :type l, r, x, y: int\n# :rtype int\n# \"\"\"\n#\n#\t # Returns the length of the array\n# def length(self):\n# \"\"\"\n# :rtype int\n# \"\"\"\n\nclass Solution(object):\n def getIndex(self, reader):\n \"\"\"\n :type reader: ArrayReader\n :rtype: integer\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# \"\"\"\n# This is ArrayReader's API interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class ArrayReader(object):\n#\t # Compares the sum of arr[l..r] with the sum of arr[x..y]\n#\t # return 1 if sum(arr[l..r]) > sum(arr[x..y])\n#\t # return 0 if sum(arr[l..r]) == sum(arr[x..y])\n#\t # return -1 if sum(arr[l..r]) < sum(arr[x..y])\n# def compareSub(self, l: int, r: int, x: int, y: int) -> int:\n#\n#\t # Returns the length of the array\n# def length(self) -> int:\n#\n\n\nclass Solution:\n def getIndex(self, reader: 'ArrayReader') -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * *********************************************************************\n * // This is the ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * *********************************************************************\n *\n * // Compares the sum of arr[l..r] with the sum of arr[x..y] \n * // return 1 if sum(arr[l..r]) > sum(arr[x..y])\n * // return 0 if sum(arr[l..r]) == sum(arr[x..y])\n * // return -1 if sum(arr[l..r]) < sum(arr[x..y])\n * int compareSub(ArrayReader *, int l, int r, int x, int y);\n *\n * // Returns the length of the array\n * int length(ArrayReader *);\n */\n\nint getIndex(ArrayReader* reader) {\n\t\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * // This is ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * class ArrayReader {\n * // Compares the sum of arr[l..r] with the sum of arr[x..y] \n * // return 1 if sum(arr[l..r]) > sum(arr[x..y])\n * // return 0 if sum(arr[l..r]) == sum(arr[x..y])\n * // return -1 if sum(arr[l..r]) < sum(arr[x..y])\n * public int CompareSub(int l, int r, int x, int y) {}\n *\n * // Returns the length of the array\n * public int Length() {}\n * }\n */\n\nclass Solution {\n public int GetIndex(ArrayReader reader) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // This is the ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * function ArrayReader() {\n * // Compares the sum of arr[l..r] with the sum of arr[x..y] \n * // return 1 if sum(arr[l..r]) > sum(arr[x..y])\n * // return 0 if sum(arr[l..r]) == sum(arr[x..y])\n * // return -1 if sum(arr[l..r]) < sum(arr[x..y])\n * @param {number} l, r, x, y\n * @return {number}\n * this.compareSub = function(l, r, x, y) {\n * ...\n * };\n *\n * // Returns the length of the array\n * @return {number}\n * this.length = function() {\n * ...\n * };\n * };\n */\n\n/**\n * @param {ArrayReader} reader\n * @return {number}\n */\nvar getIndex = function(reader) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# This is ArrayReader's API interface.\n# You should not implement it, or speculate about its implementation\n# class ArrayReader\n#\t # Compares the sum of arr[l..r] with the sum of arr[x..y]\n#\t # return 1 if sum(arr[l..r]) > sum(arr[x..y])\n#\t # return 0 if sum(arr[l..r]) == sum(arr[x..y])\n#\t # return -1 if sum(arr[l..r]) < sum(arr[x..y])\n# def compare_sub(l, r, x, y):\n# \n# end\n#\n#\t # Returns the length of the array\n# def length()\n#\t\t\n#\t end\n# end\n\n# @param {ArrayReader} reader\n# @return {int}\ndef get_index(reader)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * // This is ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * interface ArrayReader {\n * // Compares the sum of arr[l..r] with the sum of arr[x..y] \n * // return 1 if sum(arr[l..r]) > sum(arr[x..y])\n * // return 0 if sum(arr[l..r]) == sum(arr[x..y])\n * // return -1 if sum(arr[l..r]) < sum(arr[x..y])\n * public func compareSub(_ l: Int, _ r: Int, _ x: Int, _ y: Int) -> Int {}\n *\n * // Returns the length of the array\n * public func length() -> Int {}\n * }\n */\n\nclass Solution {\n func getIndex(_ reader: ArrayReader) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * // This is the ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * type ArrayReader struct {\n * }\n * // Compares the sum of arr[l..r] with the sum of arr[x..y] \n * // return 1 if sum(arr[l..r]) > sum(arr[x..y])\n * // return 0 if sum(arr[l..r]) == sum(arr[x..y])\n * // return -1 if sum(arr[l..r]) < sum(arr[x..y])\n * func (this *ArrayReader) compareSub(l, r, x, y int) int {}\n * \n * // Returns the length of the array\n * func (this *ArrayReader) length() int {}\n */\n\nfunc getIndex(reader *ArrayReader) int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * // This is ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * interface ArrayReader {\n * // Compares the sum of arr[l..r] with the sum of arr[x..y] \n * // return 1 if sum(arr[l..r]) > sum(arr[x..y])\n * // return 0 if sum(arr[l..r]) == sum(arr[x..y])\n * // return -1 if sum(arr[l..r]) < sum(arr[x..y])\n * def compareSub(l: Int, r: Int, x: Int, y: Int): Int {}\n *\n * // Returns the length of the array\n * def length(): Int {}\n * }\n */\n\nobject Solution {\n def getIndex(reader: ArrayReader): Int = {\n \n\t}\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * // This is ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * interface ArrayReader {\n * // Compares the sum of arr[l..r] with the sum of arr[x..y] \n * // return 1 if sum(arr[l..r]) > sum(arr[x..y])\n * // return 0 if sum(arr[l..r]) == sum(arr[x..y])\n * // return -1 if sum(arr[l..r]) < sum(arr[x..y])\n * fun compareSub(l: Int, r: Int, x: Int, y: Int): Int {}\n *\n * // Returns the length of the array\n * fun length(): Int {}\n * }\n */\n\nclass Solution {\n fun getIndex(reader: ArrayReader): Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "/**\n * // This is the ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * struct ArrayReader;\n * impl Array Reader {\n * pub fn compareSub(l: i32, r: i32, x: i32, y: i32) -> i32 {}\n * // Compares the sum of arr[l..r] with the sum of arr[x..y] \n * // return 1 if sum(arr[l..r]) > sum(arr[x..y])\n * // return 0 if sum(arr[l..r]) == sum(arr[x..y])\n * // return -1 if sum(arr[l..r]) < sum(arr[x..y])\n * // Returns the length of the array\n * }\n */\n\nimpl Solution {\n pub fn get_index(reader: &ArrayReader) -> i32 {\n\t\t\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * // This is ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * interface ArrayReader {\n * // Compares the sum of arr[l..r] with the sum of arr[x..y] \n * // return 1 if sum(arr[l..r]) > sum(arr[x..y])\n * // return 0 if sum(arr[l..r]) == sum(arr[x..y])\n * // return -1 if sum(arr[l..r]) < sum(arr[x..y])\n * function compareSub($l, $r, $x, $y) {}\n *\n * // Returns the length of the array\n * function length() {}\n * }\n */\n\nclass Solution {\n /**\n * @param ArrayReader $reader\n * @return Integer\n */\n function getIndex($reader) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * // This is the ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * class ArrayReader {\n * // Compares the sum of arr[l..r] with the sum of arr[x..y] \n * // return 1 if sum(arr[l..r]) > sum(arr[x..y])\n * // return 0 if sum(arr[l..r]) == sum(arr[x..y])\n * // return -1 if sum(arr[l..r]) < sum(arr[x..y])\n * compareSub(l: number, r: number, x: number, y: number): number { };\n *\n * // Returns the length of the array\n * length(): number { };\n * };\n */\n\nfunction getIndex(reader: ArrayReader): number {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1533](https://leetcode-cn.com/problems/find-the-index-of-the-large-integer)", "[\u627e\u5230\u6700\u5927\u6574\u6570\u7684\u7d22\u5f15](/solution/1500-1599/1533.Find%20the%20Index%20of%20the%20Large%20Integer/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1533](https://leetcode.com/problems/find-the-index-of-the-large-integer)", "[Find the Index of the Large Integer](/solution/1500-1599/1533.Find%20the%20Index%20of%20the%20Large%20Integer/README_EN.md)", "`Binary Search`", "Medium", "\ud83d\udd12"]}, {"question_id": "1671", "frontend_question_id": "1532", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/the-most-recent-three-orders", "url_en": "https://leetcode.com/problems/the-most-recent-three-orders", "relative_path_cn": "/solution/1500-1599/1532.The%20Most%20Recent%20Three%20Orders/README.md", "relative_path_en": "/solution/1500-1599/1532.The%20Most%20Recent%20Three%20Orders/README_EN.md", "title_cn": "\u6700\u8fd1\u7684\u4e09\u7b14\u8ba2\u5355", "title_en": "The Most Recent Three Orders", "question_title_slug": "the-most-recent-three-orders", "content_en": "

Table: Customers

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| customer_id   | int     |\n| name          | varchar |\n+---------------+---------+\ncustomer_id is the primary key for this table.\nThis table contains information about customers.\n
\n\n

 

\n\n

Table: Orders

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| order_id      | int     |\n| order_date    | date    |\n| customer_id   | int     |\n| cost          | int     |\n+---------------+---------+\norder_id is the primary key for this table.\nThis table contains information about the orders made by customer_id.\nEach customer has one order per day.\n
\n\n

 

\n\n

Write an SQL query to find the most recent 3 orders of each user. If a user ordered less than 3 orders return all of their orders.

\n\n

Return the result table sorted by customer_name in ascending order and in case of a tie by the customer_id in ascending order. If there still a tie, order them by the order_date in descending order.

\n\n

The query result format is in the following example:

\n\n
\nCustomers\n+-------------+-----------+\n| customer_id | name      |\n+-------------+-----------+\n| 1           | Winston   |\n| 2           | Jonathan  |\n| 3           | Annabelle |\n| 4           | Marwan    |\n| 5           | Khaled    |\n+-------------+-----------+\n\nOrders\n+----------+------------+-------------+------+\n| order_id | order_date | customer_id | cost |\n+----------+------------+-------------+------+\n| 1        | 2020-07-31 | 1           | 30   |\n| 2        | 2020-07-30 | 2           | 40   |\n| 3        | 2020-07-31 | 3           | 70   |\n| 4        | 2020-07-29 | 4           | 100  |\n| 5        | 2020-06-10 | 1           | 1010 |\n| 6        | 2020-08-01 | 2           | 102  |\n| 7        | 2020-08-01 | 3           | 111  |\n| 8        | 2020-08-03 | 1           | 99   |\n| 9        | 2020-08-07 | 2           | 32   |\n| 10       | 2020-07-15 | 1           | 2    |\n+----------+------------+-------------+------+\n\nResult table:\n+---------------+-------------+----------+------------+\n| customer_name | customer_id | order_id | order_date |\n+---------------+-------------+----------+------------+\n| Annabelle     | 3           | 7        | 2020-08-01 |\n| Annabelle     | 3           | 3        | 2020-07-31 |\n| Jonathan      | 2           | 9        | 2020-08-07 |\n| Jonathan      | 2           | 6        | 2020-08-01 |\n| Jonathan      | 2           | 2        | 2020-07-30 |\n| Marwan        | 4           | 4        | 2020-07-29 |\n| Winston       | 1           | 8        | 2020-08-03 |\n| Winston       | 1           | 1        | 2020-07-31 |\n| Winston       | 1           | 10       | 2020-07-15 |\n+---------------+-------------+----------+------------+\nWinston has 4 orders, we discard the order of "2020-06-10" because it is the oldest order.\nAnnabelle has only 2 orders, we return them.\nJonathan has exactly 3 orders.\nMarwan ordered only one time.\nWe sort the result table by customer_name in ascending order, by customer_id in ascending order and by order_date in descending order in case of a tie.\n
\n\n

Follow-up:
\nCan you write a general solution for the most recent n orders?

\n", "content_cn": "

\u8868\uff1aCustomers

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| customer_id   | int     |\n| name          | varchar |\n+---------------+---------+\ncustomer_id \u662f\u8be5\u8868\u4e3b\u952e\n\u8be5\u8868\u5305\u542b\u6d88\u8d39\u8005\u7684\u4fe1\u606f\n
\n\n

\u00a0

\n\n

\u8868\uff1aOrders

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| order_id      | int     |\n| order_date    | date    |\n| customer_id   | int     |\n| cost          | int     |\n+---------------+---------+\norder_id \u662f\u8be5\u8868\u4e3b\u952e\n\u8be5\u8868\u5305\u542bid\u4e3acustomer_id\u7684\u6d88\u8d39\u8005\u7684\u8ba2\u5355\u4fe1\u606f\n\u6bcf\u4e00\u4e2a\u6d88\u8d39\u8005 \u6bcf\u5929\u4e00\u7b14\u8ba2\u5355\n
\n\n

\u00a0

\n\n

\u5199\u4e00\u4e2a SQL \u8bed\u53e5\uff0c\u627e\u5230\u6bcf\u4e2a\u7528\u6237\u7684\u6700\u8fd1\u4e09\u7b14\u8ba2\u5355\u3002\u5982\u679c\u7528\u6237\u7684\u8ba2\u5355\u5c11\u4e8e 3 \u7b14\uff0c\u5219\u8fd4\u56de\u4ed6\u7684\u5168\u90e8\u8ba2\u5355\u3002

\n\n

\u8fd4\u56de\u7684\u7ed3\u679c\u6309\u7167 customer_name\u00a0\u5347\u5e8f\u6392\u5217\u3002\u5982\u679c\u6392\u540d\u6709\u76f8\u540c\uff0c\u5219\u7ee7\u7eed\u6309\u7167 customer_id \u5347\u5e8f\u6392\u5217\u3002\u5982\u679c\u6392\u540d\u8fd8\u6709\u76f8\u540c\uff0c\u5219\u7ee7\u7eed\u6309\u7167 order_date \u964d\u5e8f\u6392\u5217\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a\uff1a

\n\n
\nCustomers\n+-------------+-----------+\n| customer_id | name      |\n+-------------+-----------+\n| 1           | Winston   |\n| 2           | Jonathan  |\n| 3           | Annabelle |\n| 4           | Marwan    |\n| 5           | Khaled    |\n+-------------+-----------+\n\nOrders\n+----------+------------+-------------+------+\n| order_id | order_date | customer_id | cost |\n+----------+------------+-------------+------+\n| 1        | 2020-07-31 | 1           | 30   |\n| 2        | 2020-07-30 | 2           | 40   |\n| 3        | 2020-07-31 | 3           | 70   |\n| 4        | 2020-07-29 | 4           | 100  |\n| 5        | 2020-06-10 | 1           | 1010 |\n| 6        | 2020-08-01 | 2           | 102  |\n| 7        | 2020-08-01 | 3           | 111  |\n| 8        | 2020-08-03 | 1           | 99   |\n| 9        | 2020-08-07 | 2           | 32   |\n| 10       | 2020-07-15 | 1           | 2    |\n+----------+------------+-------------+------+\n\nResult table\uff1a\n+---------------+-------------+----------+------------+\n| customer_name | customer_id | order_id | order_date |\n+---------------+-------------+----------+------------+\n| Annabelle     | 3           | 7        | 2020-08-01 |\n| Annabelle     | 3           | 3        | 2020-07-31 |\n| Jonathan      | 2           | 9        | 2020-08-07 |\n| Jonathan      | 2           | 6        | 2020-08-01 |\n| Jonathan      | 2           | 2        | 2020-07-30 |\n| Marwan        | 4           | 4        | 2020-07-29 |\n| Winston       | 1           | 8        | 2020-08-03 |\n| Winston       | 1           | 1        | 2020-07-31 |\n| Winston       | 1           | 10       | 2020-07-15 |\n+---------------+-------------+----------+------------+\nWinston \u6709 4 \u7b14\u8ba2\u5355, \u6392\u9664\u4e86 \"2020-06-10\" \u7684\u8ba2\u5355, \u56e0\u4e3a\u5b83\u662f\u6700\u8001\u7684\u8ba2\u5355\u3002\nAnnabelle \u53ea\u6709 2 \u7b14\u8ba2\u5355, \u5168\u90e8\u8fd4\u56de\u3002\nJonathan \u6070\u597d\u6709 3 \u7b14\u8ba2\u5355\u3002\nMarwan \u53ea\u6709 1 \u7b14\u8ba2\u5355\u3002\n\u7ed3\u679c\u8868\u6211\u4eec\u6309\u7167 customer_name \u5347\u5e8f\u6392\u5217\uff0ccustomer_id \u5347\u5e8f\u6392\u5217\uff0corder_date \u964d\u5e8f\u6392\u5217\u3002\n
\n\n

\u00a0

\n\n

\u8fdb\u9636\uff1a

\n\n
    \n\t
  • \u4f60\u80fd\u5199\u51fa\u6765\u6700\u8fd1\u00a0n\u00a0\u7b14\u8ba2\u5355\u7684\u901a\u7528\u89e3\u51b3\u65b9\u6848\u5417?
  • \n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1532](https://leetcode-cn.com/problems/the-most-recent-three-orders)", "[\u6700\u8fd1\u7684\u4e09\u7b14\u8ba2\u5355](/solution/1500-1599/1532.The%20Most%20Recent%20Three%20Orders/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1532](https://leetcode.com/problems/the-most-recent-three-orders)", "[The Most Recent Three Orders](/solution/1500-1599/1532.The%20Most%20Recent%20Three%20Orders/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1670", "frontend_question_id": "1527", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/patients-with-a-condition", "url_en": "https://leetcode.com/problems/patients-with-a-condition", "relative_path_cn": "/solution/1500-1599/1527.Patients%20With%20a%20Condition/README.md", "relative_path_en": "/solution/1500-1599/1527.Patients%20With%20a%20Condition/README_EN.md", "title_cn": "\u60a3\u67d0\u79cd\u75be\u75c5\u7684\u60a3\u8005", "title_en": "Patients With a Condition", "question_title_slug": "patients-with-a-condition", "content_en": "

Table: Patients

\n\n
\n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| patient_id   | int     |\n| patient_name | varchar |\n| conditions   | varchar |\n+--------------+---------+\npatient_id is the primary key for this table.\n'conditions' contains 0 or more code separated by spaces. \nThis table contains information of the patients in the hospital.\n
\n\n

 

\n\n

Write an SQL query to report the patient_id, patient_name all conditions of patients who have Type I Diabetes. Type I Diabetes always starts with DIAB1 prefix

\n\n

Return the result table in any order.

\n\n

The query result format is in the following example.

\n\n

 

\n\n
\nPatients\n+------------+--------------+--------------+\n| patient_id | patient_name | conditions   |\n+------------+--------------+--------------+\n| 1          | Daniel       | YFEV COUGH   |\n| 2          | Alice        |              |\n| 3          | Bob          | DIAB100 MYOP |\n| 4          | George       | ACNE DIAB100 |\n| 5          | Alain        | DIAB201      |\n+------------+--------------+--------------+\n\nResult table:\n+------------+--------------+--------------+\n| patient_id | patient_name | conditions   |\n+------------+--------------+--------------+\n| 3          | Bob          | DIAB100 MYOP |\n| 4          | George       | ACNE DIAB100 | \n+------------+--------------+--------------+\nBob and George both have a condition that starts with DIAB1.\n
\n", "content_cn": "

\u60a3\u8005\u4fe1\u606f\u8868\uff1a Patients

\n\n
+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| patient_id   | int     |\n| patient_name | varchar |\n| conditions   | varchar |\n+--------------+---------+\npatient_id \uff08\u60a3\u8005 ID\uff09\u662f\u8be5\u8868\u7684\u4e3b\u952e\u3002\n'conditions' \uff08\u75be\u75c5\uff09\u5305\u542b 0 \u4e2a\u6216\u4ee5\u4e0a\u7684\u75be\u75c5\u4ee3\u7801\uff0c\u4ee5\u7a7a\u683c\u5206\u9694\u3002\n\u8fd9\u4e2a\u8868\u5305\u542b\u533b\u9662\u4e2d\u60a3\u8005\u7684\u4fe1\u606f\u3002
\n\n

 

\n\n

\u5199\u4e00\u6761 SQL \u8bed\u53e5\uff0c\u67e5\u8be2\u60a3\u6709 I \u7c7b\u7cd6\u5c3f\u75c5\u7684\u60a3\u8005 ID \uff08patient_id\uff09\u3001\u60a3\u8005\u59d3\u540d\uff08patient_name\uff09\u4ee5\u53ca\u5176\u60a3\u6709\u7684\u6240\u6709\u75be\u75c5\u4ee3\u7801\uff08conditions\uff09\u3002I \u7c7b\u7cd6\u5c3f\u75c5\u7684\u4ee3\u7801\u603b\u662f\u5305\u542b\u524d\u7f00 DIAB1 \u3002

\n\n

\u6309\u4efb\u610f\u987a\u5e8f\u8fd4\u56de\u7ed3\u679c\u8868\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u793a\u4f8b\u6240\u793a\uff1a

\n\n

 

\n\n
Patients\n+------------+--------------+--------------+\n| patient_id | patient_name | conditions   |\n+------------+--------------+--------------+\n| 1          | Daniel       | YFEV COUGH   |\n| 2          | Alice        |              |\n| 3          | Bob          | DIAB100 MYOP |\n| 4          | George       | ACNE DIAB100 |\n| 5          | Alain        | DIAB201      |\n+------------+--------------+--------------+\n\n\u7ed3\u679c\u8868\uff1a\n+------------+--------------+--------------+\n| patient_id | patient_name | conditions   |\n+------------+--------------+--------------+\n| 3          | Bob          | DIAB100 MYOP |\n| 4          | George       | ACNE DIAB100 | \n+------------+--------------+--------------+\nBob \u548c George \u90fd\u60a3\u6709\u4ee3\u7801\u4ee5 DIAB1 \u5f00\u5934\u7684\u75be\u75c5\u3002\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1527](https://leetcode-cn.com/problems/patients-with-a-condition)", "[\u60a3\u67d0\u79cd\u75be\u75c5\u7684\u60a3\u8005](/solution/1500-1599/1527.Patients%20With%20a%20Condition/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1527](https://leetcode.com/problems/patients-with-a-condition)", "[Patients With a Condition](/solution/1500-1599/1527.Patients%20With%20a%20Condition/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1669", "frontend_question_id": "1547", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-cost-to-cut-a-stick", "url_en": "https://leetcode.com/problems/minimum-cost-to-cut-a-stick", "relative_path_cn": "/solution/1500-1599/1547.Minimum%20Cost%20to%20Cut%20a%20Stick/README.md", "relative_path_en": "/solution/1500-1599/1547.Minimum%20Cost%20to%20Cut%20a%20Stick/README_EN.md", "title_cn": "\u5207\u68cd\u5b50\u7684\u6700\u5c0f\u6210\u672c", "title_en": "Minimum Cost to Cut a Stick", "question_title_slug": "minimum-cost-to-cut-a-stick", "content_en": "

Given a wooden stick of length n units. The stick is labelled from 0 to n. For example, a stick of length 6 is labelled as follows:

\r\n\"\"\r\n

Given an integer array cuts where cuts[i] denotes a position you should perform a cut at.

\r\n\r\n

You should perform the cuts in order, you can change the order of the cuts as you wish.

\r\n\r\n

The cost of one cut is the length of the stick to be cut, the total cost is the sum of costs of all cuts. When you cut a stick, it will be split into two smaller sticks (i.e. the sum of their lengths is the length of the stick before the cut). Please refer to the first example for a better explanation.

\r\n\r\n

Return the minimum total cost of the cuts.

\r\n\r\n

 

\r\n

Example 1:

\r\n\"\"\r\n
\r\nInput: n = 7, cuts = [1,3,4,5]\r\nOutput: 16\r\nExplanation: Using cuts order = [1, 3, 4, 5] as in the input leads to the following scenario:\r\n\"\"\r\nThe first cut is done to a rod of length 7 so the cost is 7. The second cut is done to a rod of length 6 (i.e. the second part of the first cut), the third is done to a rod of length 4 and the last cut is to a rod of length 3. The total cost is 7 + 6 + 4 + 3 = 20.\r\nRearranging the cuts to be [3, 5, 1, 4] for example will lead to a scenario with total cost = 16 (as shown in the example photo 7 + 4 + 3 + 2 = 16).
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: n = 9, cuts = [5,6,1,4,2]\r\nOutput: 22\r\nExplanation: If you try the given cuts ordering the cost will be 25.\r\nThere are much ordering with total cost <= 25, for example, the order [4, 6, 5, 2, 1] has total cost = 22 which is the minimum possible.\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 2 <= n <= 10^6
  • \r\n\t
  • 1 <= cuts.length <= min(n - 1, 100)
  • \r\n\t
  • 1 <= cuts[i] <= n - 1
  • \r\n\t
  • All the integers in cuts array are distinct.
  • \r\n
", "content_cn": "

\u6709\u4e00\u6839\u957f\u5ea6\u4e3a n \u4e2a\u5355\u4f4d\u7684\u6728\u68cd\uff0c\u68cd\u4e0a\u4ece 0 \u5230 n \u6807\u8bb0\u4e86\u82e5\u5e72\u4f4d\u7f6e\u3002\u4f8b\u5982\uff0c\u957f\u5ea6\u4e3a 6 \u7684\u68cd\u5b50\u53ef\u4ee5\u6807\u8bb0\u5982\u4e0b\uff1a

\n\n

\"\"

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 cuts \uff0c\u5176\u4e2d cuts[i] \u8868\u793a\u4f60\u9700\u8981\u5c06\u68cd\u5b50\u5207\u5f00\u7684\u4f4d\u7f6e\u3002

\n\n

\u4f60\u53ef\u4ee5\u6309\u987a\u5e8f\u5b8c\u6210\u5207\u5272\uff0c\u4e5f\u53ef\u4ee5\u6839\u636e\u9700\u8981\u66f4\u6539\u5207\u5272\u7684\u987a\u5e8f\u3002

\n\n

\u6bcf\u6b21\u5207\u5272\u7684\u6210\u672c\u90fd\u662f\u5f53\u524d\u8981\u5207\u5272\u7684\u68cd\u5b50\u7684\u957f\u5ea6\uff0c\u5207\u68cd\u5b50\u7684\u603b\u6210\u672c\u662f\u5386\u6b21\u5207\u5272\u6210\u672c\u7684\u603b\u548c\u3002\u5bf9\u68cd\u5b50\u8fdb\u884c\u5207\u5272\u5c06\u4f1a\u628a\u4e00\u6839\u6728\u68cd\u5206\u6210\u4e24\u6839\u8f83\u5c0f\u7684\u6728\u68cd\uff08\u8fd9\u4e24\u6839\u6728\u68cd\u7684\u957f\u5ea6\u548c\u5c31\u662f\u5207\u5272\u524d\u6728\u68cd\u7684\u957f\u5ea6\uff09\u3002\u8bf7\u53c2\u9605\u7b2c\u4e00\u4e2a\u793a\u4f8b\u4ee5\u83b7\u5f97\u66f4\u76f4\u89c2\u7684\u89e3\u91ca\u3002

\n\n

\u8fd4\u56de\u5207\u68cd\u5b50\u7684 \u6700\u5c0f\u603b\u6210\u672c \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1an = 7, cuts = [1,3,4,5]\n\u8f93\u51fa\uff1a16\n\u89e3\u91ca\uff1a\u6309 [1, 3, 4, 5] \u7684\u987a\u5e8f\u5207\u5272\u7684\u60c5\u51b5\u5982\u4e0b\u6240\u793a\uff1a\n\"\"\n\u7b2c\u4e00\u6b21\u5207\u5272\u957f\u5ea6\u4e3a 7 \u7684\u68cd\u5b50\uff0c\u6210\u672c\u4e3a 7 \u3002\u7b2c\u4e8c\u6b21\u5207\u5272\u957f\u5ea6\u4e3a 6 \u7684\u68cd\u5b50\uff08\u5373\u7b2c\u4e00\u6b21\u5207\u5272\u5f97\u5230\u7684\u7b2c\u4e8c\u6839\u68cd\u5b50\uff09\uff0c\u7b2c\u4e09\u6b21\u5207\u5272\u4e3a\u957f\u5ea6 4 \u7684\u68cd\u5b50\uff0c\u6700\u540e\u5207\u5272\u957f\u5ea6\u4e3a 3 \u7684\u68cd\u5b50\u3002\u603b\u6210\u672c\u4e3a 7 + 6 + 4 + 3 = 20 \u3002\n\u800c\u5c06\u5207\u5272\u987a\u5e8f\u91cd\u65b0\u6392\u5217\u4e3a [3, 5, 1, 4] \u540e\uff0c\u603b\u6210\u672c = 16\uff08\u5982\u793a\u4f8b\u56fe\u4e2d 7 + 4 + 3 + 2 = 16\uff09\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1an = 9, cuts = [5,6,1,4,2]\n\u8f93\u51fa\uff1a22\n\u89e3\u91ca\uff1a\u5982\u679c\u6309\u7ed9\u5b9a\u7684\u987a\u5e8f\u5207\u5272\uff0c\u5219\u603b\u6210\u672c\u4e3a 25 \u3002\u603b\u6210\u672c <= 25 \u7684\u5207\u5272\u987a\u5e8f\u5f88\u591a\uff0c\u4f8b\u5982\uff0c[4, 6, 5, 2, 1] \u7684\u603b\u6210\u672c = 22\uff0c\u662f\u6240\u6709\u53ef\u80fd\u65b9\u6848\u4e2d\u6210\u672c\u6700\u5c0f\u7684\u3002
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= n <= 10^6
  • \n\t
  • 1 <= cuts.length <= min(n - 1, 100)
  • \n\t
  • 1 <= cuts[i] <= n - 1
  • \n\t
  • cuts \u6570\u7ec4\u4e2d\u7684\u6240\u6709\u6574\u6570\u90fd \u4e92\u4e0d\u76f8\u540c
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minCost(int n, vector& cuts) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minCost(int n, int[] cuts) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minCost(self, n, cuts):\n \"\"\"\n :type n: int\n :type cuts: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minCost(self, n: int, cuts: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minCost(int n, int* cuts, int cutsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinCost(int n, int[] cuts) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[]} cuts\n * @return {number}\n */\nvar minCost = function(n, cuts) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[]} cuts\n# @return {Integer}\ndef min_cost(n, cuts)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minCost(_ n: Int, _ cuts: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minCost(n int, cuts []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minCost(n: Int, cuts: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minCost(n: Int, cuts: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_cost(n: i32, cuts: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[] $cuts\n * @return Integer\n */\n function minCost($n, $cuts) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minCost(n: number, cuts: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-cost n cuts)\n (-> exact-integer? (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1547](https://leetcode-cn.com/problems/minimum-cost-to-cut-a-stick)", "[\u5207\u68cd\u5b50\u7684\u6700\u5c0f\u6210\u672c](/solution/1500-1599/1547.Minimum%20Cost%20to%20Cut%20a%20Stick/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1547](https://leetcode.com/problems/minimum-cost-to-cut-a-stick)", "[Minimum Cost to Cut a Stick](/solution/1500-1599/1547.Minimum%20Cost%20to%20Cut%20a%20Stick/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1668", "frontend_question_id": "1542", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-longest-awesome-substring", "url_en": "https://leetcode.com/problems/find-longest-awesome-substring", "relative_path_cn": "/solution/1500-1599/1542.Find%20Longest%20Awesome%20Substring/README.md", "relative_path_en": "/solution/1500-1599/1542.Find%20Longest%20Awesome%20Substring/README_EN.md", "title_cn": "\u627e\u51fa\u6700\u957f\u7684\u8d85\u8d5e\u5b50\u5b57\u7b26\u4e32", "title_en": "Find Longest Awesome Substring", "question_title_slug": "find-longest-awesome-substring", "content_en": "

Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.

\n\n

Return the length of the maximum length awesome substring of s.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "3242415"\nOutput: 5\nExplanation: "24241" is the longest awesome substring, we can form the palindrome "24142" with some swaps.\n
\n\n

Example 2:

\n\n
\nInput: s = "12345678"\nOutput: 1\n
\n\n

Example 3:

\n\n
\nInput: s = "213123"\nOutput: 6\nExplanation: "213123" is the longest awesome substring, we can form the palindrome "231132" with some swaps.\n
\n\n

Example 4:

\n\n
\nInput: s = "00"\nOutput: 2\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 10^5
  • \n\t
  • s consists only of digits.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \u3002\u8bf7\u8fd4\u56de s \u4e2d\u6700\u957f\u7684 \u8d85\u8d5e\u5b50\u5b57\u7b26\u4e32 \u7684\u957f\u5ea6\u3002

\n\n

\u300c\u8d85\u8d5e\u5b50\u5b57\u7b26\u4e32\u300d\u9700\u6ee1\u8db3\u6ee1\u8db3\u4e0b\u8ff0\u4e24\u4e2a\u6761\u4ef6\uff1a

\n\n
    \n\t
  • \u8be5\u5b57\u7b26\u4e32\u662f s \u7684\u4e00\u4e2a\u975e\u7a7a\u5b50\u5b57\u7b26\u4e32
  • \n\t
  • \u8fdb\u884c\u4efb\u610f\u6b21\u6570\u7684\u5b57\u7b26\u4ea4\u6362\u540e\uff0c\u8be5\u5b57\u7b26\u4e32\u53ef\u4ee5\u53d8\u6210\u4e00\u4e2a\u56de\u6587\u5b57\u7b26\u4e32
  • \n
\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1as = "3242415"\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a"24241" \u662f\u6700\u957f\u7684\u8d85\u8d5e\u5b50\u5b57\u7b26\u4e32\uff0c\u4ea4\u6362\u5176\u4e2d\u7684\u5b57\u7b26\u540e\uff0c\u53ef\u4ee5\u5f97\u5230\u56de\u6587 "24142"\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1as = "12345678"\n\u8f93\u51fa\uff1a1\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1as = "213123"\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a"213123" \u662f\u6700\u957f\u7684\u8d85\u8d5e\u5b50\u5b57\u7b26\u4e32\uff0c\u4ea4\u6362\u5176\u4e2d\u7684\u5b57\u7b26\u540e\uff0c\u53ef\u4ee5\u5f97\u5230\u56de\u6587 "231132"\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1as = "00"\n\u8f93\u51fa\uff1a2\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length <= 10^5
  • \n\t
  • s \u4ec5\u7531\u6570\u5b57\u7ec4\u6210
  • \n
\n", "tags_en": ["Bit Manipulation", "String"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int longestAwesome(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int longestAwesome(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestAwesome(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestAwesome(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint longestAwesome(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LongestAwesome(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar longestAwesome = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef longest_awesome(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestAwesome(_ s: String) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestAwesome(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestAwesome(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestAwesome(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_awesome(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function longestAwesome($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestAwesome(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-awesome s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1542](https://leetcode-cn.com/problems/find-longest-awesome-substring)", "[\u627e\u51fa\u6700\u957f\u7684\u8d85\u8d5e\u5b50\u5b57\u7b26\u4e32](/solution/1500-1599/1542.Find%20Longest%20Awesome%20Substring/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u5b57\u7b26\u4e32`", "\u56f0\u96be", ""], "md_table_row_en": ["[1542](https://leetcode.com/problems/find-longest-awesome-substring)", "[Find Longest Awesome Substring](/solution/1500-1599/1542.Find%20Longest%20Awesome%20Substring/README_EN.md)", "`Bit Manipulation`,`String`", "Hard", ""]}, {"question_id": "1667", "frontend_question_id": "1545", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-kth-bit-in-nth-binary-string", "url_en": "https://leetcode.com/problems/find-kth-bit-in-nth-binary-string", "relative_path_cn": "/solution/1500-1599/1545.Find%20Kth%20Bit%20in%20Nth%20Binary%20String/README.md", "relative_path_en": "/solution/1500-1599/1545.Find%20Kth%20Bit%20in%20Nth%20Binary%20String/README_EN.md", "title_cn": "\u627e\u51fa\u7b2c N \u4e2a\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32\u4e2d\u7684\u7b2c K \u4f4d", "title_en": "Find Kth Bit in Nth Binary String", "question_title_slug": "find-kth-bit-in-nth-binary-string", "content_en": "

Given two positive integers n and k, the binary string  Sn is formed as follows:

\r\n\r\n
    \r\n\t
  • S1 = "0"
  • \r\n\t
  • Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1
  • \r\n
\r\n\r\n

Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0).

\r\n\r\n

For example, the first 4 strings in the above sequence are:

\r\n\r\n
    \r\n\t
  • S= "0"
  • \r\n\t
  • S= "011"
  • \r\n\t
  • S= "0111001"
  • \r\n\t
  • S4 = "011100110110001"
  • \r\n
\r\n\r\n

Return the kth bit in Sn. It is guaranteed that k is valid for the given n.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: n = 3, k = 1\r\nOutput: "0"\r\nExplanation: S3 is "0111001". The first bit is "0".\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: n = 4, k = 11\r\nOutput: "1"\r\nExplanation: S4 is "011100110110001". The 11th bit is "1".\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: n = 1, k = 1\r\nOutput: "0"\r\n
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: n = 2, k = 3\r\nOutput: "1"\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= n <= 20
  • \r\n\t
  • 1 <= k <= 2n - 1
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e24\u4e2a\u6b63\u6574\u6570 n \u548c k\uff0c\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32\u00a0 Sn \u7684\u5f62\u6210\u89c4\u5219\u5982\u4e0b\uff1a

\n\n
    \n\t
  • S1\u00a0= \"0\"
  • \n\t
  • \u5f53 i > 1 \u65f6\uff0cSi\u00a0=\u00a0Si-1\u00a0+ \"1\" + reverse(invert(Si-1))
  • \n
\n\n

\u5176\u4e2d + \u8868\u793a\u4e32\u8054\u64cd\u4f5c\uff0creverse(x) \u8fd4\u56de\u53cd\u8f6c x \u540e\u5f97\u5230\u7684\u5b57\u7b26\u4e32\uff0c\u800c invert(x) \u5219\u4f1a\u7ffb\u8f6c x \u4e2d\u7684\u6bcf\u4e00\u4f4d\uff080 \u53d8\u4e3a 1\uff0c\u800c 1 \u53d8\u4e3a 0\uff09\u3002

\n\n

\u4f8b\u5982\uff0c\u7b26\u5408\u4e0a\u8ff0\u63cf\u8ff0\u7684\u5e8f\u5217\u7684\u524d 4 \u4e2a\u5b57\u7b26\u4e32\u4f9d\u6b21\u662f\uff1a

\n\n
    \n\t
  • S1\u00a0= \"0\"
  • \n\t
  • S2\u00a0= \"011\"
  • \n\t
  • S3\u00a0= \"0111001\"
  • \n\t
  • S4 = \"011100110110001\"
  • \n
\n\n

\u8bf7\u4f60\u8fd4\u56de\u00a0 Sn \u7684 \u7b2c k \u4f4d\u5b57\u7b26 \uff0c\u9898\u76ee\u6570\u636e\u4fdd\u8bc1 k \u4e00\u5b9a\u5728 Sn \u957f\u5ea6\u8303\u56f4\u4ee5\u5185\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1an = 3, k = 1\n\u8f93\u51fa\uff1a\"0\"\n\u89e3\u91ca\uff1aS3 \u4e3a \"0111001\"\uff0c\u5176\u7b2c 1 \u4f4d\u4e3a \"0\" \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1an = 4, k = 11\n\u8f93\u51fa\uff1a\"1\"\n\u89e3\u91ca\uff1aS4 \u4e3a \"011100110110001\"\uff0c\u5176\u7b2c 11 \u4f4d\u4e3a \"1\" \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1an = 1, k = 1\n\u8f93\u51fa\uff1a\"0\"\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1an = 2, k = 3\n\u8f93\u51fa\uff1a\"1\"\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 20
  • \n\t
  • 1 <= k <= 2n - 1
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n char findKthBit(int n, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public char findKthBit(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findKthBit(self, n, k):\n \"\"\"\n :type n: int\n :type k: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findKthBit(self, n: int, k: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar findKthBit(int n, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public char FindKthBit(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} k\n * @return {character}\n */\nvar findKthBit = function(n, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} k\n# @return {Character}\ndef find_kth_bit(n, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findKthBit(_ n: Int, _ k: Int) -> Character {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findKthBit(n int, k int) byte {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findKthBit(n: Int, k: Int): Char = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findKthBit(n: Int, k: Int): Char {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_kth_bit(n: i32, k: i32) -> char {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $k\n * @return String\n */\n function findKthBit($n, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findKthBit(n: number, k: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-kth-bit n k)\n (-> exact-integer? exact-integer? char?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1545](https://leetcode-cn.com/problems/find-kth-bit-in-nth-binary-string)", "[\u627e\u51fa\u7b2c N \u4e2a\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32\u4e2d\u7684\u7b2c K \u4f4d](/solution/1500-1599/1545.Find%20Kth%20Bit%20in%20Nth%20Binary%20String/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1545](https://leetcode.com/problems/find-kth-bit-in-nth-binary-string)", "[Find Kth Bit in Nth Binary String](/solution/1500-1599/1545.Find%20Kth%20Bit%20in%20Nth%20Binary%20String/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "1666", "frontend_question_id": "1544", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/make-the-string-great", "url_en": "https://leetcode.com/problems/make-the-string-great", "relative_path_cn": "/solution/1500-1599/1544.Make%20The%20String%20Great/README.md", "relative_path_en": "/solution/1500-1599/1544.Make%20The%20String%20Great/README_EN.md", "title_cn": "\u6574\u7406\u5b57\u7b26\u4e32", "title_en": "Make The String Great", "question_title_slug": "make-the-string-great", "content_en": "

Given a string s of lower and upper case English letters.

\r\n\r\n

A good string is a string which doesn't have two adjacent characters s[i] and s[i + 1] where:

\r\n\r\n
    \r\n\t
  • 0 <= i <= s.length - 2
  • \r\n\t
  • s[i] is a lower-case letter and s[i + 1] is the same letter but in upper-case or vice-versa.
  • \r\n
\r\n\r\n

To make the string good, you can choose two adjacent characters that make the string bad and remove them. You can keep doing this until the string becomes good.

\r\n\r\n

Return the string after making it good. The answer is guaranteed to be unique under the given constraints.

\r\n\r\n

Notice that an empty string is also good.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: s = "leEeetcode"\r\nOutput: "leetcode"\r\nExplanation: In the first step, either you choose i = 1 or i = 2, both will result "leEeetcode" to be reduced to "leetcode".\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: s = "abBAcC"\r\nOutput: ""\r\nExplanation: We have many possible scenarios, and all lead to the same answer. For example:\r\n"abBAcC" --> "aAcC" --> "cC" --> ""\r\n"abBAcC" --> "abBA" --> "aA" --> ""\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: s = "s"\r\nOutput: "s"\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= s.length <= 100
  • \r\n\t
  • s contains only lower and upper case English letters.
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u7531\u5927\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\u7684\u5b57\u7b26\u4e32 s \u3002

\n\n

\u4e00\u4e2a\u6574\u7406\u597d\u7684\u5b57\u7b26\u4e32\u4e2d\uff0c\u4e24\u4e2a\u76f8\u90bb\u5b57\u7b26 s[i] \u548c s[i+1]\uff0c\u5176\u4e2d 0<= i <= s.length-2 \uff0c\u8981\u6ee1\u8db3\u5982\u4e0b\u6761\u4ef6:

\n\n
    \n\t
  • \u82e5 s[i] \u662f\u5c0f\u5199\u5b57\u7b26\uff0c\u5219 s[i+1] \u4e0d\u53ef\u4ee5\u662f\u76f8\u540c\u7684\u5927\u5199\u5b57\u7b26\u3002
  • \n\t
  • \u82e5 s[i] \u662f\u5927\u5199\u5b57\u7b26\uff0c\u5219 s[i+1] \u4e0d\u53ef\u4ee5\u662f\u76f8\u540c\u7684\u5c0f\u5199\u5b57\u7b26\u3002
  • \n
\n\n

\u8bf7\u4f60\u5c06\u5b57\u7b26\u4e32\u6574\u7406\u597d\uff0c\u6bcf\u6b21\u4f60\u90fd\u53ef\u4ee5\u4ece\u5b57\u7b26\u4e32\u4e2d\u9009\u51fa\u6ee1\u8db3\u4e0a\u8ff0\u6761\u4ef6\u7684 \u4e24\u4e2a\u76f8\u90bb \u5b57\u7b26\u5e76\u5220\u9664\uff0c\u76f4\u5230\u5b57\u7b26\u4e32\u6574\u7406\u597d\u4e3a\u6b62\u3002

\n\n

\u8bf7\u8fd4\u56de\u6574\u7406\u597d\u7684 \u5b57\u7b26\u4e32 \u3002\u9898\u76ee\u4fdd\u8bc1\u5728\u7ed9\u51fa\u7684\u7ea6\u675f\u6761\u4ef6\u4e0b\uff0c\u6d4b\u8bd5\u6837\u4f8b\u5bf9\u5e94\u7684\u7b54\u6848\u662f\u552f\u4e00\u7684\u3002

\n\n

\u6ce8\u610f\uff1a\u7a7a\u5b57\u7b26\u4e32\u4e5f\u5c5e\u4e8e\u6574\u7406\u597d\u7684\u5b57\u7b26\u4e32\uff0c\u5c3d\u7ba1\u5176\u4e2d\u6ca1\u6709\u4efb\u4f55\u5b57\u7b26\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"leEeetcode\"\n\u8f93\u51fa\uff1a\"leetcode\"\n\u89e3\u91ca\uff1a\u65e0\u8bba\u4f60\u7b2c\u4e00\u6b21\u9009\u7684\u662f i = 1 \u8fd8\u662f i = 2\uff0c\u90fd\u4f1a\u4f7f \"leEeetcode\" \u7f29\u51cf\u4e3a \"leetcode\" \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"abBAcC\"\n\u8f93\u51fa\uff1a\"\"\n\u89e3\u91ca\uff1a\u5b58\u5728\u591a\u79cd\u4e0d\u540c\u60c5\u51b5\uff0c\u4f46\u6240\u6709\u7684\u60c5\u51b5\u90fd\u4f1a\u5bfc\u81f4\u76f8\u540c\u7684\u7ed3\u679c\u3002\u4f8b\u5982\uff1a\n\"abBAcC\" --> \"aAcC\" --> \"cC\" --> \"\"\n\"abBAcC\" --> \"abBA\" --> \"aA\" --> \"\"\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"s\"\n\u8f93\u51fa\uff1a\"s\"\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length <= 100
  • \n\t
  • s \u53ea\u5305\u542b\u5c0f\u5199\u548c\u5927\u5199\u82f1\u6587\u5b57\u6bcd
  • \n
\n", "tags_en": ["Stack", "String"], "tags_cn": ["\u6808", "\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string makeGood(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String makeGood(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def makeGood(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def makeGood(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * makeGood(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string MakeGood(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar makeGood = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef make_good(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func makeGood(_ s: String) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func makeGood(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def makeGood(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun makeGood(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn make_good(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function makeGood($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function makeGood(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (make-good s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1544](https://leetcode-cn.com/problems/make-the-string-great)", "[\u6574\u7406\u5b57\u7b26\u4e32](/solution/1500-1599/1544.Make%20The%20String%20Great/README.md)", "`\u6808`,`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1544](https://leetcode.com/problems/make-the-string-great)", "[Make The String Great](/solution/1500-1599/1544.Make%20The%20String%20Great/README_EN.md)", "`Stack`,`String`", "Easy", ""]}, {"question_id": "1665", "frontend_question_id": "1522", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/diameter-of-n-ary-tree", "url_en": "https://leetcode.com/problems/diameter-of-n-ary-tree", "relative_path_cn": "/solution/1500-1599/1522.Diameter%20of%20N-Ary%20Tree/README.md", "relative_path_en": "/solution/1500-1599/1522.Diameter%20of%20N-Ary%20Tree/README_EN.md", "title_cn": "N \u53c9\u6811\u7684\u76f4\u5f84", "title_en": "Diameter of N-Ary Tree", "question_title_slug": "diameter-of-n-ary-tree", "content_en": "

Given a root of an N-ary tree, you need to compute the length of the diameter of the tree.

\n\n

The diameter of an N-ary tree is the length of the longest path between any two nodes in the tree. This path may or may not pass through the root.

\n\n

(Nary-Tree input serialization is represented in their level order traversal, each group of children is separated by the null value.)

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: root = [1,null,3,2,4,null,5,6]\nOutput: 3\nExplanation: Diameter is shown in red color.
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: root = [1,null,2,null,3,4,null,5,null,6]\nOutput: 4\n
\n\n

Example 3:

\n\n

\"\"

\n\n
\nInput: root = [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]\nOutput: 7\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The depth of the n-ary tree is less than or equal to 1000.
  • \n\t
  • The total number of nodes is between [1, 104].
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u68f5 N \u53c9\u6811\u7684\u6839\u8282\u70b9 root \uff0c\u8ba1\u7b97\u8fd9\u68f5\u6811\u7684\u76f4\u5f84\u957f\u5ea6\u3002

\n\n

N \u53c9\u6811\u7684\u76f4\u5f84\u6307\u7684\u662f\u6811\u4e2d\u4efb\u610f\u4e24\u4e2a\u8282\u70b9\u95f4\u8def\u5f84\u4e2d \u6700\u957f \u8def\u5f84\u7684\u957f\u5ea6\u3002\u8fd9\u6761\u8def\u5f84\u53ef\u80fd\u7ecf\u8fc7\u6839\u8282\u70b9\uff0c\u4e5f\u53ef\u80fd\u4e0d\u7ecf\u8fc7\u6839\u8282\u70b9\u3002

\n\n

\uff08N \u53c9\u6811\u7684\u8f93\u5165\u5e8f\u5217\u4ee5\u5c42\u5e8f\u904d\u5386\u7684\u5f62\u5f0f\u7ed9\u51fa\uff0c\u6bcf\u7ec4\u5b50\u8282\u70b9\u7528 null \u5206\u9694\uff09

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1aroot = [1,null,3,2,4,null,5,6]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u76f4\u5f84\u5982\u56fe\u4e2d\u7ea2\u7ebf\u6240\u793a\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1aroot = [1,null,2,null,3,4,null,5,null,6]\n\u8f93\u51fa\uff1a4\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165: root = [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]\n\u8f93\u51fa: 7\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • N \u53c9\u6811\u7684\u6df1\u5ea6\u5c0f\u4e8e\u6216\u7b49\u4e8e 1000 \u3002
  • \n\t
  • \u8282\u70b9\u7684\u603b\u4e2a\u6570\u5728 [0, 10^4] \u95f4\u3002
  • \n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n vector children;\n\n Node() {}\n\n Node(int _val) {\n val = _val;\n }\n\n Node(int _val, vector _children) {\n val = _val;\n children = _children;\n }\n};\n*/\n\nclass Solution {\npublic:\n int diameter(Node* root) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/*\n// Definition for a Node.\nclass Node {\n public int val;\n public List children;\n\n \n public Node() {\n children = new ArrayList();\n }\n \n public Node(int _val) {\n val = _val;\n children = new ArrayList();\n }\n \n public Node(int _val,ArrayList _children) {\n val = _val;\n children = _children;\n }\n};\n*/\n\nclass Solution {\n public int diameter(Node root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "\"\"\"\n# Definition for a Node.\nclass Node(object):\n def __init__(self, val=None, children=None):\n self.val = val\n self.children = children if children is not None else []\n\"\"\"\n\nclass Solution(object):\n def diameter(self, root):\n \"\"\"\n :type root: 'Node'\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "\"\"\"\n# Definition for a Node.\nclass Node:\n def __init__(self, val=None, children=None):\n self.val = val\n self.children = children if children is not None else []\n\"\"\"\n\nclass Solution:\n def diameter(self, root: 'Node') -> int:\n \"\"\"\n :type root: 'Node'\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a Node.\n * struct Node {\n * int val;\n * int numChildren;\n * struct Node** children;\n * };\n */\n\nint* diameter(struct Node* root) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/*\n// Definition for a Node.\npublic class Node {\n public int val;\n public IList children;\n \n public Node() {\n val = 0;\n children = new List();\n }\n\n public Node(int _val) {\n val = _val;\n children = new List();\n }\n \n public Node(int _val, List _children) {\n val = _val;\n children = _children;\n }\n}\n*/\n\npublic class Solution {\n public int Diameter(Node root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // Definition for a Node.\n * function Node(val, children) {\n * this.val = val === undefined ? 0 : val;\n * this.children = children === undefined ? [] : children;\n * };\n */\n\n/**\n * @param {Node} root\n * @return {number}\n */\nvar diameter = function(root) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a Node.\n# class Node\n# attr_accessor :val, :children\n# def initialize(val=0, children=[])\n# @val = val\n# @children = children\n# end\n# end\n\n# @param {Node} root\n# @return {Integer}\ndef diameter(root)\n\t\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a Node.\n * public class Node {\n * public var val: Int\n * public var children: [Node]\n * public init(_ val: Int) {\n * self.val = val\n * self.children = []\n * }\n * }\n */\n\nclass Solution {\n func diameter(_ root: Node?) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a Node.\n * type Node struct {\n * Val int\n * Children []*Node\n * }\n */\n\nfunc diameter(root *Node) int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a Node.\n * class Node(var _value: Int) {\n * var value: Int = _value\n * var children: List[Node] = List()\n * }\n */\n\nobject Solution {\n def diameter(root: Node): Int = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a Node.\n * class Node(var `val`: Int) {\n * var children: List = listOf()\n * }\n */\n\nclass Solution {\n fun diameter(root: Node?): Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a Node.\n * class Node {\n * public $val = null;\n * public $children = null;\n * function __construct($val = 0) {\n * $this->val = $val;\n * $this->children = array();\n * }\n * }\n */\n\nclass Solution {\n /**\n * @param Node $root\n * @return Integer\n */\n function diameter($root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for Node.\n * class Node {\n * val: number\n * children: Node[]\n * constructor(val?: number, children?: Node[]) {\n * this.val = (val===undefined ? 0 : val)\n * this.children = (children===undefined ? [] : children)\n * }\n * }\n */\n\nfunction diameter(root: Node): number {\n \n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1522](https://leetcode-cn.com/problems/diameter-of-n-ary-tree)", "[N \u53c9\u6811\u7684\u76f4\u5f84](/solution/1500-1599/1522.Diameter%20of%20N-Ary%20Tree/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1522](https://leetcode.com/problems/diameter-of-n-ary-tree)", "[Diameter of N-Ary Tree](/solution/1500-1599/1522.Diameter%20of%20N-Ary%20Tree/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1664", "frontend_question_id": "1517", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/find-users-with-valid-e-mails", "url_en": "https://leetcode.com/problems/find-users-with-valid-e-mails", "relative_path_cn": "/solution/1500-1599/1517.Find%20Users%20With%20Valid%20E-Mails/README.md", "relative_path_en": "/solution/1500-1599/1517.Find%20Users%20With%20Valid%20E-Mails/README_EN.md", "title_cn": "\u67e5\u627e\u62e5\u6709\u6709\u6548\u90ae\u7bb1\u7684\u7528\u6237", "title_en": "Find Users With Valid E-Mails", "question_title_slug": "find-users-with-valid-e-mails", "content_en": "

Table: Users

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| user_id       | int     |\n| name          | varchar |\n| mail          | varchar |\n+---------------+---------+\nuser_id is the primary key for this table.\nThis table contains information of the users signed up in a website. Some e-mails are invalid.\n
\n\n

 

\n\n

Write an SQL query to find the users who have valid emails.

\n\n

A valid e-mail has a prefix name and a domain where: 

\n\n
    \n\t
  • The prefix name is a string that may contain letters (upper or lower case), digits, underscore '_', period '.' and/or dash '-'. The prefix name must start with a letter.
  • \n\t
  • The domain is '@leetcode.com'.
  • \n
\n\n

Return the result table in any order.

\n\n

The query result format is in the following example.

\n\n

 

\n\n
\nUsers\n+---------+-----------+-------------------------+\n| user_id | name      | mail                    |\n+---------+-----------+-------------------------+\n| 1       | Winston   | winston@leetcode.com    |\n| 2       | Jonathan  | jonathanisgreat         |\n| 3       | Annabelle | bella-@leetcode.com     |\n| 4       | Sally     | sally.come@leetcode.com |\n| 5       | Marwan    | quarz#2020@leetcode.com |\n| 6       | David     | david69@gmail.com       |\n| 7       | Shapiro   | .shapo@leetcode.com     |\n+---------+-----------+-------------------------+\n\nResult table:\n+---------+-----------+-------------------------+\n| user_id | name      | mail                    |\n+---------+-----------+-------------------------+\n| 1       | Winston   | winston@leetcode.com    |\n| 3       | Annabelle | bella-@leetcode.com     |\n| 4       | Sally     | sally.come@leetcode.com |\n+---------+-----------+-------------------------+\nThe mail of user 2 doesn't have a domain.\nThe mail of user 5 has # sign which is not allowed.\nThe mail of user 6 doesn't have leetcode domain.\nThe mail of user 7 starts with a period.\n
\n", "content_cn": "

\u7528\u6237\u8868\uff1a Users

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| user_id       | int     |\n| name          | varchar |\n| mail          | varchar | \n+---------------+---------+\nuser_id \uff08\u7528\u6237 ID\uff09\u662f\u8be5\u8868\u7684\u4e3b\u952e\u3002\n\u8fd9\u4e2a\u8868\u5305\u542b\u7528\u6237\u5728\u67d0\u7f51\u7ad9\u4e0a\u6ce8\u518c\u7684\u4fe1\u606f\u3002\u6709\u4e9b\u90ae\u7bb1\u662f\u65e0\u6548\u7684\u3002
\n\n

 

\n\n

\u5199\u4e00\u6761 SQL \u8bed\u53e5\uff0c\u67e5\u8be2\u62e5\u6709\u6709\u6548\u90ae\u7bb1\u7684\u7528\u6237\u3002

\n\n

\u6709\u6548\u7684\u90ae\u7bb1\u5305\u542b\u7b26\u5408\u4e0b\u5217\u6761\u4ef6\u7684\u524d\u7f00\u540d\u548c\u57df\u540d\uff1a

\n\n
    \n\t
  • \u524d\u7f00\u540d\u662f\u5305\u542b\u5b57\u6bcd\uff08\u5927\u5199\u6216\u5c0f\u5199\uff09\u3001\u6570\u5b57\u3001\u4e0b\u5212\u7ebf '_'\u3001\u53e5\u70b9 '.' \u548c/\u6216\u6a2a\u6760 '-' \u7684\u5b57\u7b26\u4e32\u3002\u524d\u7f00\u540d\u5fc5\u987b\u4ee5\u5b57\u6bcd\u5f00\u5934\u3002
  • \n\t
  • \u57df\u540d\u662f '@leetcode.com' \u3002
  • \n
\n\n

\u6309\u4efb\u610f\u987a\u5e8f\u8fd4\u56de\u7ed3\u679c\u8868\u3002

\n\n

 

\n\n

\u67e5\u8be2\u683c\u5f0f\u5982\u4e0b\u6240\u793a\uff1a

\n\n
\nUsers\n+---------+-----------+-------------------------+\n| user_id | name      | mail                    |\n+---------+-----------+-------------------------+\n| 1       | Winston   | winston@leetcode.com    |\n| 2       | Jonathan  | jonathanisgreat         |\n| 3       | Annabelle | bella-@leetcode.com     |\n| 4       | Sally     | sally.come@leetcode.com |\n| 5       | Marwan    | quarz#2020@leetcode.com |\n| 6       | David     | david69@gmail.com       |\n| 7       | Shapiro   | .shapo@leetcode.com     |\n+---------+-----------+-------------------------+\n\n\u7ed3\u679c\u8868\uff1a\n+---------+-----------+-------------------------+\n| user_id | name      | mail                    |\n+---------+-----------+-------------------------+\n| 1       | Winston   | winston@leetcode.com    |\n| 3       | Annabelle | bella-@leetcode.com     |\n| 4       | Sally     | sally.come@leetcode.com |\n+---------+-----------+-------------------------+\n2 \u53f7\u7528\u6237\u7684\u90ae\u7bb1\u6ca1\u6709\u57df\u540d\u3002\n5 \u53f7\u7528\u6237\u7684\u90ae\u7bb1\u5305\u542b\u975e\u6cd5\u5b57\u7b26 #\u3002\n6 \u53f7\u7528\u6237\u7684\u90ae\u7bb1\u7684\u57df\u540d\u4e0d\u662f leetcode\u3002\n7 \u53f7\u7528\u6237\u7684\u90ae\u7bb1\u4ee5\u53e5\u70b9\uff08.\uff09\u5f00\u5934\u3002\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1517](https://leetcode-cn.com/problems/find-users-with-valid-e-mails)", "[\u67e5\u627e\u62e5\u6709\u6709\u6548\u90ae\u7bb1\u7684\u7528\u6237](/solution/1500-1599/1517.Find%20Users%20With%20Valid%20E-Mails/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1517](https://leetcode.com/problems/find-users-with-valid-e-mails)", "[Find Users With Valid E-Mails](/solution/1500-1599/1517.Find%20Users%20With%20Valid%20E-Mails/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1663", "frontend_question_id": "1559", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/detect-cycles-in-2d-grid", "url_en": "https://leetcode.com/problems/detect-cycles-in-2d-grid", "relative_path_cn": "/solution/1500-1599/1559.Detect%20Cycles%20in%202D%20Grid/README.md", "relative_path_en": "/solution/1500-1599/1559.Detect%20Cycles%20in%202D%20Grid/README_EN.md", "title_cn": "\u4e8c\u7ef4\u7f51\u683c\u56fe\u4e2d\u63a2\u6d4b\u73af", "title_en": "Detect Cycles in 2D Grid", "question_title_slug": "detect-cycles-in-2d-grid", "content_en": "

Given a 2D array of characters grid of size m x n, you need to find if there exists any cycle consisting of the same value in grid.

\n\n

A cycle is a path of length 4 or more in the grid that starts and ends at the same cell. From a given cell, you can move to one of the cells adjacent to it - in one of the four directions (up, down, left, or right), if it has the same value of the current cell.

\n\n

Also, you cannot move to the cell that you visited in your last move. For example, the cycle (1, 1) -> (1, 2) -> (1, 1) is invalid because from (1, 2) we visited (1, 1) which was the last visited cell.

\n\n

Return true if any cycle of the same value exists in grid, otherwise, return false.

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: grid = [["a","a","a","a"],["a","b","b","a"],["a","b","b","a"],["a","a","a","a"]]\nOutput: true\nExplanation: There are two valid cycles shown in different colors in the image below:\n\"\"\n
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: grid = [["c","c","c","a"],["c","d","c","c"],["c","c","e","c"],["f","c","c","c"]]\nOutput: true\nExplanation: There is only one valid cycle highlighted in the image below:\n\"\"\n
\n\n

Example 3:

\n\n

\"\"

\n\n
\nInput: grid = [["a","b","b"],["b","z","b"],["b","b","a"]]\nOutput: false\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • m == grid.length
  • \n\t
  • n == grid[i].length
  • \n\t
  • 1 <= m <= 500
  • \n\t
  • 1 <= n <= 500
  • \n\t
  • grid consists only of lowercase English letters.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u4e8c\u7ef4\u5b57\u7b26\u7f51\u683c\u6570\u7ec4 grid \uff0c\u5927\u5c0f\u4e3a m x n \uff0c\u4f60\u9700\u8981\u68c0\u67e5 grid \u4e2d\u662f\u5426\u5b58\u5728 \u76f8\u540c\u503c \u5f62\u6210\u7684\u73af\u3002

\n\n

\u4e00\u4e2a\u73af\u662f\u4e00\u6761\u5f00\u59cb\u548c\u7ed3\u675f\u4e8e\u540c\u4e00\u4e2a\u683c\u5b50\u7684\u957f\u5ea6 \u5927\u4e8e\u7b49\u4e8e 4 \u7684\u8def\u5f84\u3002\u5bf9\u4e8e\u4e00\u4e2a\u7ed9\u5b9a\u7684\u683c\u5b50\uff0c\u4f60\u53ef\u4ee5\u79fb\u52a8\u5230\u5b83\u4e0a\u3001\u4e0b\u3001\u5de6\u3001\u53f3\u56db\u4e2a\u65b9\u5411\u76f8\u90bb\u7684\u683c\u5b50\u4e4b\u4e00\uff0c\u53ef\u4ee5\u79fb\u52a8\u7684\u524d\u63d0\u662f\u8fd9\u4e24\u4e2a\u683c\u5b50\u6709 \u76f8\u540c\u7684\u503c \u3002

\n\n

\u540c\u65f6\uff0c\u4f60\u4e5f\u4e0d\u80fd\u56de\u5230\u4e0a\u4e00\u6b21\u79fb\u52a8\u65f6\u6240\u5728\u7684\u683c\u5b50\u3002\u6bd4\u65b9\u8bf4\uff0c\u73af  (1, 1) -> (1, 2) -> (1, 1) \u662f\u4e0d\u5408\u6cd5\u7684\uff0c\u56e0\u4e3a\u4ece (1, 2) \u79fb\u52a8\u5230 (1, 1) \u56de\u5230\u4e86\u4e0a\u4e00\u6b21\u79fb\u52a8\u65f6\u7684\u683c\u5b50\u3002

\n\n

\u5982\u679c grid \u4e2d\u6709\u76f8\u540c\u503c\u5f62\u6210\u7684\u73af\uff0c\u8bf7\u4f60\u8fd4\u56de true \uff0c\u5426\u5219\u8fd4\u56de false \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1agrid = [["a","a","a","a"],["a","b","b","a"],["a","b","b","a"],["a","a","a","a"]]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u5982\u4e0b\u56fe\u6240\u793a\uff0c\u6709 2 \u4e2a\u7528\u4e0d\u540c\u989c\u8272\u6807\u51fa\u6765\u7684\u73af\uff1a\n\"\"\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1agrid = [["c","c","c","a"],["c","d","c","c"],["c","c","e","c"],["f","c","c","c"]]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u5982\u4e0b\u56fe\u6240\u793a\uff0c\u53ea\u6709\u9ad8\u4eae\u6240\u793a\u7684\u4e00\u4e2a\u5408\u6cd5\u73af\uff1a\n\"\"\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1agrid = [["a","b","b"],["b","z","b"],["b","b","a"]]\n\u8f93\u51fa\uff1afalse\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • m == grid.length
  • \n\t
  • n == grid[i].length
  • \n\t
  • 1 <= m <= 500
  • \n\t
  • 1 <= n <= 500
  • \n\t
  • grid \u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
  • \n
\n", "tags_en": ["Depth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool containsCycle(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean containsCycle(char[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def containsCycle(self, grid):\n \"\"\"\n :type grid: List[List[str]]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def containsCycle(self, grid: List[List[str]]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool containsCycle(char** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool ContainsCycle(char[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {character[][]} grid\n * @return {boolean}\n */\nvar containsCycle = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Character[][]} grid\n# @return {Boolean}\ndef contains_cycle(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func containsCycle(_ grid: [[Character]]) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func containsCycle(grid [][]byte) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def containsCycle(grid: Array[Array[Char]]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun containsCycle(grid: Array): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn contains_cycle(grid: Vec>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $grid\n * @return Boolean\n */\n function containsCycle($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function containsCycle(grid: string[][]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (contains-cycle grid)\n (-> (listof (listof char?)) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1559](https://leetcode-cn.com/problems/detect-cycles-in-2d-grid)", "[\u4e8c\u7ef4\u7f51\u683c\u56fe\u4e2d\u63a2\u6d4b\u73af](/solution/1500-1599/1559.Detect%20Cycles%20in%202D%20Grid/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[1559](https://leetcode.com/problems/detect-cycles-in-2d-grid)", "[Detect Cycles in 2D Grid](/solution/1500-1599/1559.Detect%20Cycles%20in%202D%20Grid/README_EN.md)", "`Depth-first Search`", "Hard", ""]}, {"question_id": "1662", "frontend_question_id": "1558", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-numbers-of-function-calls-to-make-target-array", "url_en": "https://leetcode.com/problems/minimum-numbers-of-function-calls-to-make-target-array", "relative_path_cn": "/solution/1500-1599/1558.Minimum%20Numbers%20of%20Function%20Calls%20to%20Make%20Target%20Array/README.md", "relative_path_en": "/solution/1500-1599/1558.Minimum%20Numbers%20of%20Function%20Calls%20to%20Make%20Target%20Array/README_EN.md", "title_cn": "\u5f97\u5230\u76ee\u6807\u6570\u7ec4\u7684\u6700\u5c11\u51fd\u6570\u8c03\u7528\u6b21\u6570", "title_en": "Minimum Numbers of Function Calls to Make Target Array", "question_title_slug": "minimum-numbers-of-function-calls-to-make-target-array", "content_en": "

\"\"

\n\n

Your task is to form an integer array nums from an initial array of zeros arr that is the same size as nums.

\n\n

Return the minimum number of function calls to make nums from arr.

\n\n

The answer is guaranteed to fit in a 32-bit signed integer.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [1,5]\nOutput: 5\nExplanation: Increment by 1 (second element): [0, 0] to get [0, 1] (1 operation).\nDouble all the elements: [0, 1] -> [0, 2] -> [0, 4] (2 operations).\nIncrement by 1 (both elements)  [0, 4] -> [1, 4] -> [1, 5] (2 operations).\nTotal of operations: 1 + 2 + 2 = 5.\n
\n\n

Example 2:

\n\n
\nInput: nums = [2,2]\nOutput: 3\nExplanation: Increment by 1 (both elements) [0, 0] -> [0, 1] -> [1, 1] (2 operations).\nDouble all the elements: [1, 1] -> [2, 2] (1 operation).\nTotal of operations: 2 + 1 = 3.\n
\n\n

Example 3:

\n\n
\nInput: nums = [4,2,5]\nOutput: 6\nExplanation: (initial)[0,0,0] -> [1,0,0] -> [1,0,1] -> [2,0,2] -> [2,1,2] -> [4,2,4] -> [4,2,5](nums).\n
\n\n

Example 4:

\n\n
\nInput: nums = [3,2,2,4]\nOutput: 7\n
\n\n

Example 5:

\n\n
\nInput: nums = [2,4,8,16]\nOutput: 8\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 10^5
  • \n\t
  • 0 <= nums[i] <= 10^9
  • \n
\n", "content_cn": "

\"\"

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u4e0e nums \u5927\u5c0f\u76f8\u540c\u4e14\u521d\u59cb\u503c\u5168\u4e3a 0 \u7684\u6570\u7ec4 arr \uff0c\u8bf7\u4f60\u8c03\u7528\u4ee5\u4e0a\u51fd\u6570\u5f97\u5230\u6574\u6570\u6570\u7ec4 nums \u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u5c06 arr \u53d8\u6210 nums \u7684\u6700\u5c11\u51fd\u6570\u8c03\u7528\u6b21\u6570\u3002

\n\n

\u7b54\u6848\u4fdd\u8bc1\u5728 32 \u4f4d\u6709\u7b26\u53f7\u6574\u6570\u4ee5\u5185\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [1,5]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u7ed9\u7b2c\u4e8c\u4e2a\u6570\u52a0 1 \uff1a[0, 0] \u53d8\u6210 [0, 1] \uff081 \u6b21\u64cd\u4f5c\uff09\u3002\n\u5c06\u6240\u6709\u6570\u5b57\u4e58\u4ee5 2 \uff1a[0, 1] -> [0, 2] -> [0, 4] \uff082 \u6b21\u64cd\u4f5c\uff09\u3002\n\u7ed9\u4e24\u4e2a\u6570\u5b57\u90fd\u52a0 1 \uff1a[0, 4] -> [1, 4] -> [1, 5] \uff082 \u6b21\u64cd\u4f5c\uff09\u3002\n\u603b\u64cd\u4f5c\u6b21\u6570\u4e3a\uff1a1 + 2 + 2 = 5 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [2,2]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u7ed9\u4e24\u4e2a\u6570\u5b57\u90fd\u52a0 1 \uff1a[0, 0] -> [0, 1] -> [1, 1] \uff082 \u6b21\u64cd\u4f5c\uff09\u3002\n\u5c06\u6240\u6709\u6570\u5b57\u4e58\u4ee5 2 \uff1a [1, 1] -> [2, 2] \uff081 \u6b21\u64cd\u4f5c\uff09\u3002\n\u603b\u64cd\u4f5c\u6b21\u6570\u4e3a\uff1a 2 + 1 = 3 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [4,2,5]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\uff08\u521d\u59cb\uff09[0,0,0] -> [1,0,0] -> [1,0,1] -> [2,0,2] -> [2,1,2] -> [4,2,4] -> [4,2,5] \uff08nums \u6570\u7ec4\uff09\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [3,2,2,4]\n\u8f93\u51fa\uff1a7\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [2,4,8,16]\n\u8f93\u51fa\uff1a8\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 10^5
  • \n\t
  • 0 <= nums[i] <= 10^9
  • \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minOperations(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minOperations(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minOperations(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minOperations(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minOperations(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinOperations(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar minOperations = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef min_operations(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minOperations(_ nums: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minOperations(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minOperations(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minOperations(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_operations(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function minOperations($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minOperations(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-operations nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1558](https://leetcode-cn.com/problems/minimum-numbers-of-function-calls-to-make-target-array)", "[\u5f97\u5230\u76ee\u6807\u6570\u7ec4\u7684\u6700\u5c11\u51fd\u6570\u8c03\u7528\u6b21\u6570](/solution/1500-1599/1558.Minimum%20Numbers%20of%20Function%20Calls%20to%20Make%20Target%20Array/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1558](https://leetcode.com/problems/minimum-numbers-of-function-calls-to-make-target-array)", "[Minimum Numbers of Function Calls to Make Target Array](/solution/1500-1599/1558.Minimum%20Numbers%20of%20Function%20Calls%20to%20Make%20Target%20Array/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1661", "frontend_question_id": "1557", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-number-of-vertices-to-reach-all-nodes", "url_en": "https://leetcode.com/problems/minimum-number-of-vertices-to-reach-all-nodes", "relative_path_cn": "/solution/1500-1599/1557.Minimum%20Number%20of%20Vertices%20to%20Reach%20All%20Nodes/README.md", "relative_path_en": "/solution/1500-1599/1557.Minimum%20Number%20of%20Vertices%20to%20Reach%20All%20Nodes/README_EN.md", "title_cn": "\u53ef\u4ee5\u5230\u8fbe\u6240\u6709\u70b9\u7684\u6700\u5c11\u70b9\u6570\u76ee", "title_en": "Minimum Number of Vertices to Reach All Nodes", "question_title_slug": "minimum-number-of-vertices-to-reach-all-nodes", "content_en": "

Given a directed acyclic graph, with n vertices numbered from 0 to n-1, and an array edges where edges[i] = [fromi, toi] represents a directed edge from node fromi to node toi.

\r\n\r\n

Find the smallest set of vertices from which all nodes in the graph are reachable. It's guaranteed that a unique solution exists.

\r\n\r\n

Notice that you can return the vertices in any order.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n

\"\"

\r\n\r\n
\r\nInput: n = 6, edges = [[0,1],[0,2],[2,5],[3,4],[4,2]]\r\nOutput: [0,3]\r\nExplanation: It's not possible to reach all the nodes from a single vertex. From 0 we can reach [0,1,2,5]. From 3 we can reach [3,4,2,5]. So we output [0,3].
\r\n\r\n

Example 2:

\r\n\r\n

\"\"

\r\n\r\n
\r\nInput: n = 5, edges = [[0,1],[2,1],[3,1],[1,4],[2,4]]\r\nOutput: [0,2,3]\r\nExplanation: Notice that vertices 0, 3 and 2 are not reachable from any other node, so we must include them. Also any of these vertices can reach nodes 1 and 4.\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 2 <= n <= 10^5
  • \r\n\t
  • 1 <= edges.length <= min(10^5, n * (n - 1) / 2)
  • \r\n\t
  • edges[i].length == 2
  • \r\n\t
  • 0 <= fromi, toi < n
  • \r\n\t
  • All pairs (fromi, toi) are distinct.
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a \u6709\u5411\u65e0\u73af\u56fe \uff0c n \u4e2a\u8282\u70b9\u7f16\u53f7\u4e3a 0 \u5230 n-1 \uff0c\u4ee5\u53ca\u4e00\u4e2a\u8fb9\u6570\u7ec4 edges \uff0c\u5176\u4e2d edges[i] = [fromi, toi] \u8868\u793a\u4e00\u6761\u4ece\u70b9  fromi \u5230\u70b9 toi \u7684\u6709\u5411\u8fb9\u3002

\n\n

\u627e\u5230\u6700\u5c0f\u7684\u70b9\u96c6\u4f7f\u5f97\u4ece\u8fd9\u4e9b\u70b9\u51fa\u53d1\u80fd\u5230\u8fbe\u56fe\u4e2d\u6240\u6709\u70b9\u3002\u9898\u76ee\u4fdd\u8bc1\u89e3\u5b58\u5728\u4e14\u552f\u4e00\u3002

\n\n

\u4f60\u53ef\u4ee5\u4ee5\u4efb\u610f\u987a\u5e8f\u8fd4\u56de\u8fd9\u4e9b\u8282\u70b9\u7f16\u53f7\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1an = 6, edges = [[0,1],[0,2],[2,5],[3,4],[4,2]]\n\u8f93\u51fa\uff1a[0,3]\n\u89e3\u91ca\uff1a\u4ece\u5355\u4e2a\u8282\u70b9\u51fa\u53d1\u65e0\u6cd5\u5230\u8fbe\u6240\u6709\u8282\u70b9\u3002\u4ece 0 \u51fa\u53d1\u6211\u4eec\u53ef\u4ee5\u5230\u8fbe [0,1,2,5] \u3002\u4ece 3 \u51fa\u53d1\u6211\u4eec\u53ef\u4ee5\u5230\u8fbe [3,4,2,5] \u3002\u6240\u4ee5\u6211\u4eec\u8f93\u51fa [0,3] \u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1an = 5, edges = [[0,1],[2,1],[3,1],[1,4],[2,4]]\n\u8f93\u51fa\uff1a[0,2,3]\n\u89e3\u91ca\uff1a\u6ce8\u610f\u5230\u8282\u70b9 0\uff0c3 \u548c 2 \u65e0\u6cd5\u4ece\u5176\u4ed6\u8282\u70b9\u5230\u8fbe\uff0c\u6240\u4ee5\u6211\u4eec\u5fc5\u987b\u5c06\u5b83\u4eec\u5305\u542b\u5728\u7ed3\u679c\u70b9\u96c6\u4e2d\uff0c\u8fd9\u4e9b\u70b9\u90fd\u80fd\u5230\u8fbe\u8282\u70b9 1 \u548c 4 \u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= n <= 10^5
  • \n\t
  • 1 <= edges.length <= min(10^5, n * (n - 1) / 2)
  • \n\t
  • edges[i].length == 2
  • \n\t
  • 0 <= fromi, toi < n
  • \n\t
  • \u6240\u6709\u70b9\u5bf9 (fromi, toi) \u4e92\u4e0d\u76f8\u540c\u3002
  • \n
\n", "tags_en": ["Graph"], "tags_cn": ["\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findSmallestSetOfVertices(int n, vector>& edges) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List findSmallestSetOfVertices(int n, List> edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findSmallestSetOfVertices(self, n, edges):\n \"\"\"\n :type n: int\n :type edges: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findSmallestSetOfVertices(self, n: int, edges: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* findSmallestSetOfVertices(int n, int** edges, int edgesSize, int* edgesColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList FindSmallestSetOfVertices(int n, IList> edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} edges\n * @return {number[]}\n */\nvar findSmallestSetOfVertices = function(n, edges) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} edges\n# @return {Integer[]}\ndef find_smallest_set_of_vertices(n, edges)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findSmallestSetOfVertices(_ n: Int, _ edges: [[Int]]) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findSmallestSetOfVertices(n int, edges [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findSmallestSetOfVertices(n: Int, edges: List[List[Int]]): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findSmallestSetOfVertices(n: Int, edges: List>): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_smallest_set_of_vertices(n: i32, edges: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $edges\n * @return Integer[]\n */\n function findSmallestSetOfVertices($n, $edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findSmallestSetOfVertices(n: number, edges: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-smallest-set-of-vertices n edges)\n (-> exact-integer? (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1557](https://leetcode-cn.com/problems/minimum-number-of-vertices-to-reach-all-nodes)", "[\u53ef\u4ee5\u5230\u8fbe\u6240\u6709\u70b9\u7684\u6700\u5c11\u70b9\u6570\u76ee](/solution/1500-1599/1557.Minimum%20Number%20of%20Vertices%20to%20Reach%20All%20Nodes/README.md)", "`\u56fe`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1557](https://leetcode.com/problems/minimum-number-of-vertices-to-reach-all-nodes)", "[Minimum Number of Vertices to Reach All Nodes](/solution/1500-1599/1557.Minimum%20Number%20of%20Vertices%20to%20Reach%20All%20Nodes/README_EN.md)", "`Graph`", "Medium", ""]}, {"question_id": "1660", "frontend_question_id": "1556", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/thousand-separator", "url_en": "https://leetcode.com/problems/thousand-separator", "relative_path_cn": "/solution/1500-1599/1556.Thousand%20Separator/README.md", "relative_path_en": "/solution/1500-1599/1556.Thousand%20Separator/README_EN.md", "title_cn": "\u5343\u4f4d\u5206\u9694\u6570", "title_en": "Thousand Separator", "question_title_slug": "thousand-separator", "content_en": "

Given an integer n, add a dot (".") as the thousands separator and return it in string format.

\n\n

 

\n

Example 1:

\n\n
\nInput: n = 987\nOutput: "987"\n
\n\n

Example 2:

\n\n
\nInput: n = 1234\nOutput: "1.234"\n
\n\n

Example 3:

\n\n
\nInput: n = 123456789\nOutput: "123.456.789"\n
\n\n

Example 4:

\n\n
\nInput: n = 0\nOutput: "0"\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 0 <= n < 2^31
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n\uff0c\u8bf7\u4f60\u6bcf\u9694\u4e09\u4f4d\u6dfb\u52a0\u70b9\uff08\u5373 "." \u7b26\u53f7\uff09\u4f5c\u4e3a\u5343\u4f4d\u5206\u9694\u7b26\uff0c\u5e76\u5c06\u7ed3\u679c\u4ee5\u5b57\u7b26\u4e32\u683c\u5f0f\u8fd4\u56de\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1an = 987\n\u8f93\u51fa\uff1a"987"\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1an = 1234\n\u8f93\u51fa\uff1a"1.234"\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1an = 123456789\n\u8f93\u51fa\uff1a"123.456.789"\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1an = 0\n\u8f93\u51fa\uff1a"0"\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 0 <= n < 2^31
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string thousandSeparator(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String thousandSeparator(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def thousandSeparator(self, n):\n \"\"\"\n :type n: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def thousandSeparator(self, n: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * thousandSeparator(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ThousandSeparator(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {string}\n */\nvar thousandSeparator = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {String}\ndef thousand_separator(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func thousandSeparator(_ n: Int) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func thousandSeparator(n int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def thousandSeparator(n: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun thousandSeparator(n: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn thousand_separator(n: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return String\n */\n function thousandSeparator($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function thousandSeparator(n: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (thousand-separator n)\n (-> exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1556](https://leetcode-cn.com/problems/thousand-separator)", "[\u5343\u4f4d\u5206\u9694\u6570](/solution/1500-1599/1556.Thousand%20Separator/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1556](https://leetcode.com/problems/thousand-separator)", "[Thousand Separator](/solution/1500-1599/1556.Thousand%20Separator/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1659", "frontend_question_id": "1537", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/get-the-maximum-score", "url_en": "https://leetcode.com/problems/get-the-maximum-score", "relative_path_cn": "/solution/1500-1599/1537.Get%20the%20Maximum%20Score/README.md", "relative_path_en": "/solution/1500-1599/1537.Get%20the%20Maximum%20Score/README_EN.md", "title_cn": "\u6700\u5927\u5f97\u5206", "title_en": "Get the Maximum Score", "question_title_slug": "get-the-maximum-score", "content_en": "

You are given two sorted arrays of distinct integers nums1 and nums2.

\n\n

A valid path is defined as follows:

\n\n
    \n\t
  • Choose array nums1 or nums2 to traverse (from index-0).
  • \n\t
  • Traverse the current array from left to right.
  • \n\t
  • If you are reading any value that is present in nums1 and nums2 you are allowed to change your path to the other array. (Only one repeated value is considered in the valid path).
  • \n
\n\n

Score is defined as the sum of uniques values in a valid path.

\n\n

Return the maximum score you can obtain of all possible valid paths.

\n\n

Since the answer may be too large, return it modulo 10^9 + 7.

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: nums1 = [2,4,5,8,10], nums2 = [4,6,8,9]\nOutput: 30\nExplanation: Valid paths:\n[2,4,5,8,10], [2,4,5,8,9], [2,4,6,8,9], [2,4,6,8,10],  (starting from nums1)\n[4,6,8,9], [4,5,8,10], [4,5,8,9], [4,6,8,10]    (starting from nums2)\nThe maximum is obtained with the path in green [2,4,6,8,10].\n
\n\n

Example 2:

\n\n
\nInput: nums1 = [1,3,5,7,9], nums2 = [3,5,100]\nOutput: 109\nExplanation: Maximum sum is obtained with the path [1,3,5,100].\n
\n\n

Example 3:

\n\n
\nInput: nums1 = [1,2,3,4,5], nums2 = [6,7,8,9,10]\nOutput: 40\nExplanation: There are no common elements between nums1 and nums2.\nMaximum sum is obtained with the path [6,7,8,9,10].\n
\n\n

Example 4:

\n\n
\nInput: nums1 = [1,4,5,8,9,11,19], nums2 = [2,3,4,11,12]\nOutput: 61\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums1.length <= 10^5
  • \n\t
  • 1 <= nums2.length <= 10^5
  • \n\t
  • 1 <= nums1[i], nums2[i] <= 10^7
  • \n\t
  • nums1 and nums2 are strictly increasing.
  • \n
\n", "content_cn": "

\u4f60\u6709\u4e24\u4e2a \u6709\u5e8f \u4e14\u6570\u7ec4\u5185\u5143\u7d20\u4e92\u4e0d\u76f8\u540c\u7684\u6570\u7ec4 nums1 \u548c nums2 \u3002

\n\n

\u4e00\u6761 \u5408\u6cd5\u8def\u5f84 \u5b9a\u4e49\u5982\u4e0b\uff1a

\n\n
    \n\t
  • \u9009\u62e9\u6570\u7ec4 nums1 \u6216\u8005 nums2 \u5f00\u59cb\u904d\u5386\uff08\u4ece\u4e0b\u6807 0 \u5904\u5f00\u59cb\uff09\u3002
  • \n\t
  • \u4ece\u5de6\u5230\u53f3\u904d\u5386\u5f53\u524d\u6570\u7ec4\u3002
  • \n\t
  • \u5982\u679c\u4f60\u9047\u5230\u4e86 nums1 \u548c nums2 \u4e2d\u90fd\u5b58\u5728\u7684\u503c\uff0c\u90a3\u4e48\u4f60\u53ef\u4ee5\u5207\u6362\u8def\u5f84\u5230\u53e6\u4e00\u4e2a\u6570\u7ec4\u5bf9\u5e94\u6570\u5b57\u5904\u7ee7\u7eed\u904d\u5386\uff08\u4f46\u5728\u5408\u6cd5\u8def\u5f84\u4e2d\u91cd\u590d\u6570\u5b57\u53ea\u4f1a\u88ab\u7edf\u8ba1\u4e00\u6b21\uff09\u3002
  • \n
\n\n

\u5f97\u5206\u5b9a\u4e49\u4e3a\u5408\u6cd5\u8def\u5f84\u4e2d\u4e0d\u540c\u6570\u5b57\u7684\u548c\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u6240\u6709\u53ef\u80fd\u5408\u6cd5\u8def\u5f84\u4e2d\u7684\u6700\u5927\u5f97\u5206\u3002

\n\n

\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u5f88\u5927\uff0c\u8bf7\u4f60\u5c06\u5b83\u5bf9 10^9 + 7 \u53d6\u4f59\u540e\u8fd4\u56de\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1anums1 = [2,4,5,8,10], nums2 = [4,6,8,9]\n\u8f93\u51fa\uff1a30\n\u89e3\u91ca\uff1a\u5408\u6cd5\u8def\u5f84\u5305\u62ec\uff1a\n[2,4,5,8,10], [2,4,5,8,9], [2,4,6,8,9], [2,4,6,8,10],\uff08\u4ece nums1 \u5f00\u59cb\u904d\u5386\uff09\n[4,6,8,9], [4,5,8,10], [4,5,8,9], [4,6,8,10]  \uff08\u4ece nums2 \u5f00\u59cb\u904d\u5386\uff09\n\u6700\u5927\u5f97\u5206\u4e3a\u4e0a\u56fe\u4e2d\u7684\u7eff\u8272\u8def\u5f84 [2,4,6,8,10] \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anums1 = [1,3,5,7,9], nums2 = [3,5,100]\n\u8f93\u51fa\uff1a109\n\u89e3\u91ca\uff1a\u6700\u5927\u5f97\u5206\u7531\u8def\u5f84 [1,3,5,100] \u5f97\u5230\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1anums1 = [1,2,3,4,5], nums2 = [6,7,8,9,10]\n\u8f93\u51fa\uff1a40\n\u89e3\u91ca\uff1anums1 \u548c nums2 \u4e4b\u95f4\u65e0\u76f8\u540c\u6570\u5b57\u3002\n\u6700\u5927\u5f97\u5206\u7531\u8def\u5f84 [6,7,8,9,10] \u5f97\u5230\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1anums1 = [1,4,5,8,9,11,19], nums2 = [2,3,4,11,12]\n\u8f93\u51fa\uff1a61\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums1.length <= 10^5
  • \n\t
  • 1 <= nums2.length <= 10^5
  • \n\t
  • 1 <= nums1[i], nums2[i] <= 10^7
  • \n\t
  • nums1 \u548c nums2 \u90fd\u662f\u4e25\u683c\u9012\u589e\u7684\u6570\u7ec4\u3002
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxSum(vector& nums1, vector& nums2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxSum(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxSum(self, nums1, nums2):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxSum(self, nums1: List[int], nums2: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxSum(int* nums1, int nums1Size, int* nums2, int nums2Size){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxSum(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums1\n * @param {number[]} nums2\n * @return {number}\n */\nvar maxSum = function(nums1, nums2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums1\n# @param {Integer[]} nums2\n# @return {Integer}\ndef max_sum(nums1, nums2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxSum(_ nums1: [Int], _ nums2: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxSum(nums1 []int, nums2 []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxSum(nums1: Array[Int], nums2: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxSum(nums1: IntArray, nums2: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_sum(nums1: Vec, nums2: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums1\n * @param Integer[] $nums2\n * @return Integer\n */\n function maxSum($nums1, $nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxSum(nums1: number[], nums2: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-sum nums1 nums2)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1537](https://leetcode-cn.com/problems/get-the-maximum-score)", "[\u6700\u5927\u5f97\u5206](/solution/1500-1599/1537.Get%20the%20Maximum%20Score/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1537](https://leetcode.com/problems/get-the-maximum-score)", "[Get the Maximum Score](/solution/1500-1599/1537.Get%20the%20Maximum%20Score/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1658", "frontend_question_id": "1536", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-swaps-to-arrange-a-binary-grid", "url_en": "https://leetcode.com/problems/minimum-swaps-to-arrange-a-binary-grid", "relative_path_cn": "/solution/1500-1599/1536.Minimum%20Swaps%20to%20Arrange%20a%20Binary%20Grid/README.md", "relative_path_en": "/solution/1500-1599/1536.Minimum%20Swaps%20to%20Arrange%20a%20Binary%20Grid/README_EN.md", "title_cn": "\u6392\u5e03\u4e8c\u8fdb\u5236\u7f51\u683c\u7684\u6700\u5c11\u4ea4\u6362\u6b21\u6570", "title_en": "Minimum Swaps to Arrange a Binary Grid", "question_title_slug": "minimum-swaps-to-arrange-a-binary-grid", "content_en": "

Given an n x n binary grid, in one step you can choose two adjacent rows of the grid and swap them.

\n\n

A grid is said to be valid if all the cells above the main diagonal are zeros.

\n\n

Return the minimum number of steps needed to make the grid valid, or -1 if the grid cannot be valid.

\n\n

The main diagonal of a grid is the diagonal that starts at cell (1, 1) and ends at cell (n, n).

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: grid = [[0,0,1],[1,1,0],[1,0,0]]\nOutput: 3\n
\n\n

Example 2:

\n\"\"\n
\nInput: grid = [[0,1,1,0],[0,1,1,0],[0,1,1,0],[0,1,1,0]]\nOutput: -1\nExplanation: All rows are similar, swaps have no effect on the grid.\n
\n\n

Example 3:

\n\"\"\n
\nInput: grid = [[1,0,0],[1,1,0],[1,1,1]]\nOutput: 0\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == grid.length
  • \n\t
  • n == grid[i].length
  • \n\t
  • 1 <= n <= 200
  • \n\t
  • grid[i][j] is 0 or 1
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a n x n \u7684\u4e8c\u8fdb\u5236\u7f51\u683c grid\uff0c\u6bcf\u4e00\u6b21\u64cd\u4f5c\u4e2d\uff0c\u4f60\u53ef\u4ee5\u9009\u62e9\u7f51\u683c\u7684 \u76f8\u90bb\u4e24\u884c \u8fdb\u884c\u4ea4\u6362\u3002

\n\n

\u4e00\u4e2a\u7b26\u5408\u8981\u6c42\u7684\u7f51\u683c\u9700\u8981\u6ee1\u8db3\u4e3b\u5bf9\u89d2\u7ebf\u4ee5\u4e0a\u7684\u683c\u5b50\u5168\u90e8\u90fd\u662f 0 \u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u4f7f\u7f51\u683c\u6ee1\u8db3\u8981\u6c42\u7684\u6700\u5c11\u64cd\u4f5c\u6b21\u6570\uff0c\u5982\u679c\u65e0\u6cd5\u4f7f\u7f51\u683c\u7b26\u5408\u8981\u6c42\uff0c\u8bf7\u4f60\u8fd4\u56de -1 \u3002

\n\n

\u4e3b\u5bf9\u89d2\u7ebf\u6307\u7684\u662f\u4ece (1, 1) \u5230 (n, n) \u7684\u8fd9\u4e9b\u683c\u5b50\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1agrid = [[0,0,1],[1,1,0],[1,0,0]]\n\u8f93\u51fa\uff1a3\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1agrid = [[0,1,1,0],[0,1,1,0],[0,1,1,0],[0,1,1,0]]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u6240\u6709\u884c\u90fd\u662f\u4e00\u6837\u7684\uff0c\u4ea4\u6362\u76f8\u90bb\u884c\u65e0\u6cd5\u4f7f\u7f51\u683c\u7b26\u5408\u8981\u6c42\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1agrid = [[1,0,0],[1,1,0],[1,1,1]]\n\u8f93\u51fa\uff1a0\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • n == grid.length
  • \n\t
  • n == grid[i].length
  • \n\t
  • 1 <= n <= 200
  • \n\t
  • grid[i][j] \u8981\u4e48\u662f 0 \u8981\u4e48\u662f 1 \u3002
  • \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minSwaps(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minSwaps(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minSwaps(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minSwaps(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minSwaps(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinSwaps(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar minSwaps = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef min_swaps(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minSwaps(_ grid: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minSwaps(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minSwaps(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minSwaps(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_swaps(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function minSwaps($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minSwaps(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-swaps grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1536](https://leetcode-cn.com/problems/minimum-swaps-to-arrange-a-binary-grid)", "[\u6392\u5e03\u4e8c\u8fdb\u5236\u7f51\u683c\u7684\u6700\u5c11\u4ea4\u6362\u6b21\u6570](/solution/1500-1599/1536.Minimum%20Swaps%20to%20Arrange%20a%20Binary%20Grid/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1536](https://leetcode.com/problems/minimum-swaps-to-arrange-a-binary-grid)", "[Minimum Swaps to Arrange a Binary Grid](/solution/1500-1599/1536.Minimum%20Swaps%20to%20Arrange%20a%20Binary%20Grid/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1657", "frontend_question_id": "1535", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-the-winner-of-an-array-game", "url_en": "https://leetcode.com/problems/find-the-winner-of-an-array-game", "relative_path_cn": "/solution/1500-1599/1535.Find%20the%20Winner%20of%20an%20Array%20Game/README.md", "relative_path_en": "/solution/1500-1599/1535.Find%20the%20Winner%20of%20an%20Array%20Game/README_EN.md", "title_cn": "\u627e\u51fa\u6570\u7ec4\u6e38\u620f\u7684\u8d62\u5bb6", "title_en": "Find the Winner of an Array Game", "question_title_slug": "find-the-winner-of-an-array-game", "content_en": "

Given an integer array arr of distinct integers and an integer k.

\r\n\r\n

A game will be played between the first two elements of the array (i.e. arr[0] and arr[1]). In each round of the game, we compare arr[0] with arr[1], the larger integer wins and remains at position 0 and the smaller integer moves to the end of the array. The game ends when an integer wins k consecutive rounds.

\r\n\r\n

Return the integer which will win the game.

\r\n\r\n

It is guaranteed that there will be a winner of the game.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: arr = [2,1,3,5,4,6,7], k = 2\r\nOutput: 5\r\nExplanation: Let's see the rounds of the game:\r\nRound |       arr       | winner | win_count\r\n  1   | [2,1,3,5,4,6,7] | 2      | 1\r\n  2   | [2,3,5,4,6,7,1] | 3      | 1\r\n  3   | [3,5,4,6,7,1,2] | 5      | 1\r\n  4   | [5,4,6,7,1,2,3] | 5      | 2\r\nSo we can see that 4 rounds will be played and 5 is the winner because it wins 2 consecutive games.\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: arr = [3,2,1], k = 10\r\nOutput: 3\r\nExplanation: 3 will win the first 10 rounds consecutively.\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: arr = [1,9,8,2,3,7,6,4,5], k = 7\r\nOutput: 9\r\n
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: arr = [1,11,22,33,44,55,66,77,88,99], k = 1000000000\r\nOutput: 99\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 2 <= arr.length <= 10^5
  • \r\n\t
  • 1 <= arr[i] <= 10^6
  • \r\n\t
  • arr contains distinct integers.
  • \r\n\t
  • 1 <= k <= 10^9
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u7531 \u4e0d\u540c \u6574\u6570\u7ec4\u6210\u7684\u6574\u6570\u6570\u7ec4 arr \u548c\u4e00\u4e2a\u6574\u6570 k \u3002

\n\n

\u6bcf\u56de\u5408\u6e38\u620f\u90fd\u5728\u6570\u7ec4\u7684\u524d\u4e24\u4e2a\u5143\u7d20\uff08\u5373 arr[0] \u548c arr[1] \uff09\u4e4b\u95f4\u8fdb\u884c\u3002\u6bd4\u8f83 arr[0] \u4e0e arr[1] \u7684\u5927\u5c0f\uff0c\u8f83\u5927\u7684\u6574\u6570\u5c06\u4f1a\u53d6\u5f97\u8fd9\u4e00\u56de\u5408\u7684\u80dc\u5229\u5e76\u4fdd\u7559\u5728\u4f4d\u7f6e 0 \uff0c\u8f83\u5c0f\u7684\u6574\u6570\u79fb\u81f3\u6570\u7ec4\u7684\u672b\u5c3e\u3002\u5f53\u4e00\u4e2a\u6574\u6570\u8d62\u5f97 k \u4e2a\u8fde\u7eed\u56de\u5408\u65f6\uff0c\u6e38\u620f\u7ed3\u675f\uff0c\u8be5\u6574\u6570\u5c31\u662f\u6bd4\u8d5b\u7684 \u8d62\u5bb6 \u3002

\n\n

\u8fd4\u56de\u8d62\u5f97\u6bd4\u8d5b\u7684\u6574\u6570\u3002

\n\n

\u9898\u76ee\u6570\u636e \u4fdd\u8bc1 \u6e38\u620f\u5b58\u5728\u8d62\u5bb6\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aarr = [2,1,3,5,4,6,7], k = 2\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u4e00\u8d77\u770b\u4e00\u4e0b\u672c\u573a\u6e38\u620f\u6bcf\u56de\u5408\u7684\u60c5\u51b5\uff1a\n\"\"\n\u56e0\u6b64\u5c06\u8fdb\u884c 4 \u56de\u5408\u6bd4\u8d5b\uff0c\u5176\u4e2d 5 \u662f\u8d62\u5bb6\uff0c\u56e0\u4e3a\u5b83\u8fde\u80dc 2 \u56de\u5408\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aarr = [3,2,1], k = 10\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a3 \u5c06\u4f1a\u5728\u524d 10 \u4e2a\u56de\u5408\u4e2d\u8fde\u7eed\u83b7\u80dc\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aarr = [1,9,8,2,3,7,6,4,5], k = 7\n\u8f93\u51fa\uff1a9\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1aarr = [1,11,22,33,44,55,66,77,88,99], k = 1000000000\n\u8f93\u51fa\uff1a99\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= arr.length <= 10^5
  • \n\t
  • 1 <= arr[i] <= 10^6
  • \n\t
  • arr \u6240\u542b\u7684\u6574\u6570 \u5404\u4e0d\u76f8\u540c \u3002
  • \n\t
  • 1 <= k <= 10^9
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int getWinner(vector& arr, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int getWinner(int[] arr, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getWinner(self, arr, k):\n \"\"\"\n :type arr: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getWinner(self, arr: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint getWinner(int* arr, int arrSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int GetWinner(int[] arr, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @param {number} k\n * @return {number}\n */\nvar getWinner = function(arr, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @param {Integer} k\n# @return {Integer}\ndef get_winner(arr, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getWinner(_ arr: [Int], _ k: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getWinner(arr []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getWinner(arr: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getWinner(arr: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_winner(arr: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @param Integer $k\n * @return Integer\n */\n function getWinner($arr, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getWinner(arr: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-winner arr k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1535](https://leetcode-cn.com/problems/find-the-winner-of-an-array-game)", "[\u627e\u51fa\u6570\u7ec4\u6e38\u620f\u7684\u8d62\u5bb6](/solution/1500-1599/1535.Find%20the%20Winner%20of%20an%20Array%20Game/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1535](https://leetcode.com/problems/find-the-winner-of-an-array-game)", "[Find the Winner of an Array Game](/solution/1500-1599/1535.Find%20the%20Winner%20of%20an%20Array%20Game/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "1656", "frontend_question_id": "1534", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-good-triplets", "url_en": "https://leetcode.com/problems/count-good-triplets", "relative_path_cn": "/solution/1500-1599/1534.Count%20Good%20Triplets/README.md", "relative_path_en": "/solution/1500-1599/1534.Count%20Good%20Triplets/README_EN.md", "title_cn": "\u7edf\u8ba1\u597d\u4e09\u5143\u7ec4", "title_en": "Count Good Triplets", "question_title_slug": "count-good-triplets", "content_en": "

Given an array of integers arr, and three integers ab and c. You need to find the number of good triplets.

\r\n\r\n

A triplet (arr[i], arr[j], arr[k]) is good if the following conditions are true:

\r\n\r\n
    \r\n\t
  • 0 <= i < j < k < arr.length
  • \r\n\t
  • |arr[i] - arr[j]| <= a
  • \r\n\t
  • |arr[j] - arr[k]| <= b
  • \r\n\t
  • |arr[i] - arr[k]| <= c
  • \r\n
\r\n\r\n

Where |x| denotes the absolute value of x.

\r\n\r\n

Return the number of good triplets.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: arr = [3,0,1,1,9,7], a = 7, b = 2, c = 3\r\nOutput: 4\r\nExplanation: There are 4 good triplets: [(3,0,1), (3,0,1), (3,1,1), (0,1,1)].\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: arr = [1,1,2,2,3], a = 0, b = 0, c = 1\r\nOutput: 0\r\nExplanation: No triplet satisfies all conditions.\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 3 <= arr.length <= 100
  • \r\n\t
  • 0 <= arr[i] <= 1000
  • \r\n\t
  • 0 <= a, b, c <= 1000
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr \uff0c\u4ee5\u53ca a\u3001b \u3001c \u4e09\u4e2a\u6574\u6570\u3002\u8bf7\u4f60\u7edf\u8ba1\u5176\u4e2d\u597d\u4e09\u5143\u7ec4\u7684\u6570\u91cf\u3002

\n\n

\u5982\u679c\u4e09\u5143\u7ec4 (arr[i], arr[j], arr[k]) \u6ee1\u8db3\u4e0b\u5217\u5168\u90e8\u6761\u4ef6\uff0c\u5219\u8ba4\u4e3a\u5b83\u662f\u4e00\u4e2a \u597d\u4e09\u5143\u7ec4 \u3002

\n\n
    \n\t
  • 0 <= i < j < k < arr.length
  • \n\t
  • |arr[i] - arr[j]| <= a
  • \n\t
  • |arr[j] - arr[k]| <= b
  • \n\t
  • |arr[i] - arr[k]| <= c
  • \n
\n\n

\u5176\u4e2d |x| \u8868\u793a x \u7684\u7edd\u5bf9\u503c\u3002

\n\n

\u8fd4\u56de \u597d\u4e09\u5143\u7ec4\u7684\u6570\u91cf \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aarr = [3,0,1,1,9,7], a = 7, b = 2, c = 3\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u4e00\u5171\u6709 4 \u4e2a\u597d\u4e09\u5143\u7ec4\uff1a[(3,0,1), (3,0,1), (3,1,1), (0,1,1)] \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aarr = [1,1,2,2,3], a = 0, b = 0, c = 1\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u4e0d\u5b58\u5728\u6ee1\u8db3\u6240\u6709\u6761\u4ef6\u7684\u4e09\u5143\u7ec4\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 3 <= arr.length <= 100
  • \n\t
  • 0 <= arr[i] <= 1000
  • \n\t
  • 0 <= a, b, c <= 1000
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countGoodTriplets(vector& arr, int a, int b, int c) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countGoodTriplets(int[] arr, int a, int b, int c) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countGoodTriplets(self, arr, a, b, c):\n \"\"\"\n :type arr: List[int]\n :type a: int\n :type b: int\n :type c: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countGoodTriplets(self, arr: List[int], a: int, b: int, c: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countGoodTriplets(int* arr, int arrSize, int a, int b, int c){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountGoodTriplets(int[] arr, int a, int b, int c) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @param {number} a\n * @param {number} b\n * @param {number} c\n * @return {number}\n */\nvar countGoodTriplets = function(arr, a, b, c) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @param {Integer} a\n# @param {Integer} b\n# @param {Integer} c\n# @return {Integer}\ndef count_good_triplets(arr, a, b, c)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countGoodTriplets(_ arr: [Int], _ a: Int, _ b: Int, _ c: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countGoodTriplets(arr []int, a int, b int, c int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countGoodTriplets(arr: Array[Int], a: Int, b: Int, c: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countGoodTriplets(arr: IntArray, a: Int, b: Int, c: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_good_triplets(arr: Vec, a: i32, b: i32, c: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @param Integer $a\n * @param Integer $b\n * @param Integer $c\n * @return Integer\n */\n function countGoodTriplets($arr, $a, $b, $c) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countGoodTriplets(arr: number[], a: number, b: number, c: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-good-triplets arr a b c)\n (-> (listof exact-integer?) exact-integer? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1534](https://leetcode-cn.com/problems/count-good-triplets)", "[\u7edf\u8ba1\u597d\u4e09\u5143\u7ec4](/solution/1500-1599/1534.Count%20Good%20Triplets/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1534](https://leetcode.com/problems/count-good-triplets)", "[Count Good Triplets](/solution/1500-1599/1534.Count%20Good%20Triplets/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1655", "frontend_question_id": "1516", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/move-sub-tree-of-n-ary-tree", "url_en": "https://leetcode.com/problems/move-sub-tree-of-n-ary-tree", "relative_path_cn": "/solution/1500-1599/1516.Move%20Sub-Tree%20of%20N-Ary%20Tree/README.md", "relative_path_en": "/solution/1500-1599/1516.Move%20Sub-Tree%20of%20N-Ary%20Tree/README_EN.md", "title_cn": "\u79fb\u52a8 N \u53c9\u6811\u7684\u5b50\u6811", "title_en": "Move Sub-Tree of N-Ary Tree", "question_title_slug": "move-sub-tree-of-n-ary-tree", "content_en": "

Given the root of an N-ary tree of unique values, and two nodes of the tree p and q.

\n\n

You should move the subtree of the node p to become a direct child of node q. If p is already a direct child of q, don't change anything. Node p must be the last child in the children list of node q.

\n\n

Return the root of the tree after adjusting it.

\n\n

 

\n\n

There are 3 cases for nodes p and q:

\n\n
    \n\t
  1. Node q is in the sub-tree of node p.
  2. \n\t
  3. Node p is in the sub-tree of node q.
  4. \n\t
  5. Neither node p is in the sub-tree of node q nor node q is in the sub-tree of node p.
  6. \n
\n\n

In cases 2 and 3, you just need to move p (with its sub-tree) to be a child of q, but in case 1 the tree may be disconnected, thus you need to reconnect the tree again. Please read the examples carefully before solving this problem.

\n\n

 

\n\n

Nary-Tree input serialization is represented in their level order traversal, each group of children is separated by the null value (See examples).

\n\n

\"\"

\n\n

For example, the above tree is serialized as [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14].

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: root = [1,null,2,3,null,4,5,null,6,null,7,8], p = 4, q = 1\nOutput: [1,null,2,3,4,null,5,null,6,null,7,8]\nExplanation: This example follows the second case as node p is in the sub-tree of node q. We move node p with its sub-tree to be a direct child of node q.\nNotice that node 4 is the last child of node 1.
\n\n

Example 2:

\n\"\"\n
\nInput: root = [1,null,2,3,null,4,5,null,6,null,7,8], p = 7, q = 4\nOutput: [1,null,2,3,null,4,5,null,6,null,7,8]\nExplanation: Node 7 is already a direct child of node 4. We don't change anything.\n
\n\n

Example 3:

\n\"\"\n
\nInput: root = [1,null,2,3,null,4,5,null,6,null,7,8], p = 3, q = 8\nOutput: [1,null,2,null,4,5,null,7,8,null,null,null,3,null,6]\nExplanation: This example follows case 3 because node p is not in the sub-tree of node q and vice-versa. We can move node 3 with its sub-tree and make it as node 8's child.\n
\n\n

Example 4:

\n\"\"\n
\nInput: root = [1,null,2,3,null,4,5,null,6,null,7,8], p = 2, q = 7\nOutput: [1,null,7,3,null,2,null,6,null,4,5,null,null,8]\nExplanation: Node q is in the sub-tree of node p, so this is case 1.\nThe first step, we move node p (with all of its sub-tree except for node q) and add it as a child to node q.\nThen we will see that the tree is disconnected, you need to reconnect node q to replace node p as shown.\n
\n\n

Example 5:

\n\"\"\n
\nInput: root = [1,null,2,3,null,4,5,null,6,null,7,8], p = 1, q = 2\nOutput: [2,null,4,5,1,null,7,8,null,null,3,null,null,null,6]\nExplanation: Node q is in the sub-tree of node p, so this is case 1.\nThe first step, we move node p (with all of its sub-tree except for node q) and add it as a child to node q.\nAs node p was the root of the tree, node q replaces it and becomes the root of the tree.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The total number of nodes is between [2, 1000].
  • \n\t
  • Each node has a unique value.
  • \n\t
  • p != null
  • \n\t
  • q != null
  • \n\t
  • p and q are two different nodes (i.e. p != q).
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u68f5\u6ca1\u6709\u91cd\u590d\u503c\u7684 N \u53c9\u6811\u7684\u6839\u8282\u70b9 root \uff0c\u4ee5\u53ca\u5176\u4e2d\u7684\u4e24\u4e2a\u8282\u70b9 p \u548c q\u3002

\n\n

\u79fb\u52a8\u8282\u70b9 p \u53ca\u5176\u5b50\u6811\uff0c\u4f7f\u8282\u70b9 p \u6210\u4e3a\u8282\u70b9 q \u7684\u76f4\u63a5\u5b50\u8282\u70b9\u3002\u5982\u679c p \u5df2\u7ecf\u662f q \u7684\u76f4\u63a5\u5b50\u8282\u70b9\uff0c\u5219\u8bf7\u52ff\u6539\u52a8\u4efb\u4f55\u8282\u70b9\u3002\u8282\u70b9 p \u5fc5\u987b\u662f\u8282\u70b9 q \u7684\u5b50\u8282\u70b9\u5217\u8868\u7684\u6700\u540e\u4e00\u9879\u3002

\n\n

\u8fd4\u56de\u6539\u52a8\u540e\u7684\u6811\u7684\u6839\u8282\u70b9\u3002

\n\n

 

\n\n

\u8282\u70b9 p \u548c q \u53ef\u80fd\u662f\u4e0b\u5217\u4e09\u79cd\u60c5\u51b5\u4e4b\u4e00\uff1a

\n\n
    \n\t
  1. \u8282\u70b9 q \u5728\u8282\u70b9 p \u7684\u5b50\u6811\u4e2d\u3002
  2. \n\t
  3. \u8282\u70b9 p \u5728\u8282\u70b9 q \u7684\u5b50\u6811\u4e2d\u3002
  4. \n\t
  5. \u8282\u70b9 p \u4e0d\u5728\u8282\u70b9 q \u7684\u5b50\u6811\u4e2d\uff0c\u4e14\u8282\u70b9 q \u4e5f\u4e0d\u5728\u8282\u70b9 p \u7684\u5b50\u6811\u4e2d\u3002
  6. \n
\n\n

\u5728\u7b2c 2 \u79cd\u548c\u7b2c 3 \u79cd\u60c5\u51b5\u4e2d\uff0c\u4f60\u53ea\u9700\u8981\u79fb\u52a8 p \uff08\u53ca\u5176\u5b50\u6811\uff09\uff0c\u4f7f p \u6210\u4e3a q \u7684\u5b50\u8282\u70b9\u3002\u4f46\u662f\u5728\u7b2c 1 \u79cd\u60c5\u51b5\u4e2d\uff0c\u6811\u7684\u8282\u70b9\u53ef\u80fd\u4f1a\u65ad\u8fde\uff0c\u56e0\u6b64\u4f60\u8fd8\u9700\u8981\u91cd\u65b0\u8fde\u63a5\u8fd9\u4e9b\u8282\u70b9\u3002\u8bf7\u5728\u89e3\u9898\u524d\u4ed4\u7ec6\u9605\u8bfb\u793a\u4f8b\u3002

\n\n

 

\n\n

N \u53c9\u6811\u7684\u8f93\u5165\u5e8f\u5217\u4ee5\u5c42\u5e8f\u904d\u5386\u7684\u5f62\u5f0f\u7ed9\u51fa\uff0c\u6bcf\u7ec4\u5b50\u8282\u70b9\u7528 null \u5206\u9694\uff08\u89c1\u793a\u4f8b\uff09\u3002

\n\n

\"\"

\n\n

\u4f8b\u5982\uff0c\u4e0a\u9762\u7684\u6811\u4f1a\u88ab\u5e8f\u5217\u5316\u4e3a [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]\u3002

\n\n

 

\n\n

\u793a\u4f8b 1:

\n\n

\"\"

\n\n
\u8f93\u5165: root = [1,null,2,3,null,4,5,null,6,null,7,8], p = 4, q = 1\n\u8f93\u51fa: [1,null,2,3,4,null,5,null,6,null,7,8]\n\u89e3\u91ca: \u8be5\u793a\u4f8b\u5c5e\u4e8e\u7b2c\u4e8c\u79cd\u60c5\u51b5\uff0c\u8282\u70b9 p \u5728\u8282\u70b9 q \u7684\u5b50\u6811\u4e2d\u3002\u6211\u4eec\u53ef\u4ee5\u79fb\u52a8\u8282\u70b9 p \u53ca\u5176\u5b50\u6811\uff0c\u4f7f p \u6210\u4e3a\u8282\u70b9 q \u7684\u76f4\u63a5\u5b50\u8282\u70b9\u3002\n\u6ce8\u610f\uff0c\u8282\u70b9 4 \u662f\u8282\u70b9 1 \u7684\u6700\u540e\u4e00\u4e2a\u5b50\u8282\u70b9\u3002
\n\n

\u793a\u4f8b 2:

\n\n

\"\"

\n\n
\u8f93\u5165: root = [1,null,2,3,null,4,5,null,6,null,7,8], p = 7, q = 4\n\u8f93\u51fa: [1,null,2,3,null,4,5,null,6,null,7,8]\n\u89e3\u91ca: \u8282\u70b9 7 \u5df2\u7ecf\u662f\u8282\u70b9 4 \u7684\u76f4\u63a5\u5b50\u8282\u70b9\uff0c\u56e0\u6b64\u6211\u4eec\u4e0d\u6539\u52a8\u4efb\u4f55\u8282\u70b9\u3002\n
\n\n

\u793a\u4f8b 3:

\n\n

\"\"

\n\n
\u8f93\u5165: root = [1,null,2,3,null,4,5,null,6,null,7,8], p = 3, q = 8\n\u8f93\u51fa: [1,null,2,null,4,5,null,7,8,null,null,null,3,null,6]\n\u89e3\u91ca: \u8be5\u793a\u4f8b\u5c5e\u4e8e\u7b2c\u4e09\u79cd\u60c5\u51b5\uff0c\u8282\u70b9 p \u4e0d\u5728\u8282\u70b9 q \u7684\u5b50\u6811\u4e2d\uff0c\u53cd\u4e4b\u4ea6\u7136\u3002\u6211\u4eec\u53ef\u4ee5\u79fb\u52a8\u8282\u70b9 3 \u53ca\u5176\u5b50\u6811\uff0c\u4f7f\u4e4b\u6210\u4e3a\u8282\u70b9 8 \u7684\u5b50\u8282\u70b9\u3002\n
\n\n

\u793a\u4f8b 4:

\n\n

\"\"

\n\n
\u8f93\u5165: root = [1,null,2,3,null,4,5,null,6,null,7,8], p = 2, q = 7\n\u8f93\u51fa: [1,null,7,3,null,2,null,6,null,4,5,null,null,8]\n\u89e3\u91ca: \u8282\u70b9 q \u5728\u8282\u70b9 p \u7684\u5b50\u6811\u4e2d\uff0c\u56e0\u6b64\u8be5\u793a\u4f8b\u5c5e\u4e8e\u7b2c\u4e00\u79cd\u60c5\u51b5\u3002\n\u7b2c\u4e00\u6b65\uff0c\u6211\u4eec\u79fb\u52a8\u8282\u70b9 p \uff08\u53ca\u5176\u6240\u6709\u5b50\u6811\uff0c\u9664\u8282\u70b9 q \u7684\u5b50\u6811\u5916\uff09\uff0c\u5e76\u5c06\u5176\u52a0\u5165\u8282\u70b9 q \u7684\u5b50\u8282\u70b9\u5217\u8868\u4e2d\u3002\n\u7136\u540e\u6211\u4eec\u53d1\u73b0\u6811\u5df2\u65ad\u8fde\uff0c\u4f60\u9700\u8981\u91cd\u65b0\u8fde\u63a5\u8282\u70b9 q \u6765\u4ee3\u66ff\u8282\u70b9 p\uff0c\u5982\u56fe\u6240\u793a\u3002\n
\n\n

\u793a\u4f8b 5:

\n\n

\"\"

\n\n
\u8f93\u5165: root = [1,null,2,3,null,4,5,null,6,null,7,8], p = 1, q = 2\n\u8f93\u51fa: [2,null,4,5,1,null,7,8,null,null,3,null,null,null,6]\n\u89e3\u91ca: \u8282\u70b9 q \u5728\u8282\u70b9 p \u7684\u5b50\u6811\u4e2d\uff0c\u56e0\u6b64\u8be5\u793a\u4f8b\u5c5e\u4e8e\u7b2c\u4e00\u79cd\u60c5\u51b5\u3002\n\u7b2c\u4e00\u6b65\uff0c\u6211\u4eec\u79fb\u52a8\u8282\u70b9 p \uff08\u53ca\u5176\u6240\u6709\u5b50\u6811\uff0c\u9664\u8282\u70b9 q \u7684\u5b50\u6811\u5916\uff09\uff0c\u5e76\u5c06\u5176\u52a0\u5165\u8282\u70b9 q \u7684\u5b50\u8282\u70b9\u5217\u8868\u4e2d\u3002\n\u56e0\u4e3a\u8282\u70b9 p \u662f\u539f\u6811\u7684\u6839\u8282\u70b9\uff0c\u56e0\u6b64\u8282\u70b9 q \u4ee3\u66ff\u4e4b\u6210\u4e3a\u65b0\u6811\u7684\u6839\u8282\u70b9\u3002
\n\n

 

\n\n

\u63d0\u793a:

\n\n
    \n\t
  • \u8282\u70b9\u7684\u603b\u6570\u5728 [2, 1000] \u95f4\u3002
  • \n\t
  • \u6bcf\u4e2a\u8282\u70b9\u90fd\u6709\u552f\u4e00\u7684\u503c\u3002
  • \n\t
  • p != null
  • \n\t
  • q != null
  • \n\t
  • p \u548c q \u662f\u4e24\u4e2a\u4e0d\u540c\u7684\u8282\u70b9\uff08\u5373 p != q \uff09\u3002
  • \n
\n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n vector children;\n\n Node() {}\n\n Node(int _val) {\n val = _val;\n }\n\n Node(int _val, vector _children) {\n val = _val;\n children = _children;\n }\n};\n*/\n\nclass Solution {\npublic:\n Node* moveSubTree(Node* root, Node* p, Node* q) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/*\n// Definition for a Node.\nclass Node {\n public int val;\n public List children;\n\n \n public Node() {\n children = new ArrayList();\n }\n \n public Node(int _val) {\n val = _val;\n children = new ArrayList();\n }\n \n public Node(int _val,ArrayList _children) {\n val = _val;\n children = _children;\n }\n};\n*/\n\nclass Solution {\n public Node moveSubTree(Node root, Node p, Node q) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "\"\"\"\n# Definition for a Node.\nclass Node(object):\n def __init__(self, val=None, children=None):\n self.val = val\n self.children = children if children is not None else []\n\"\"\"\n\nclass Solution(object):\n def moveSubTree(self, root, p, q):\n \"\"\"\n :type root: Node\n :type p: Node\n :type q: Node\n :rtype: Node\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "\"\"\"\n# Definition for a Node.\nclass Node:\n def __init__(self, val=None, children=None):\n self.val = val\n self.children = children if children is not None else []\n\"\"\"\n\nclass Solution:\n def moveSubTree(self, root: 'Node', p: 'Node', q: 'Node') -> 'Node':\n ", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/*\n// Definition for a Node.\npublic class Node {\n public int val;\n public IList children;\n \n public Node() {\n val = 0;\n children = new List();\n }\n\n public Node(int _val) {\n val = _val;\n children = new List();\n }\n \n public Node(int _val, List _children) {\n val = _val;\n children = _children;\n }\n}\n*/\n\npublic class Solution {\n public Node MoveSubTree(Node root, Node p, Node q) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // Definition for a Node.\n * function Node(val, children) {\n * this.val = val === undefined ? 0 : val;\n * this.children = children === undefined ? [] : children;\n * };\n */\n\n/**\n * @param {Node} root\n * @param {Node} p\n * @param {Node} q\n * @return {Node}\n */\nvar moveSubTree = function(root, p, q) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a Node.\n# class Node\n# attr_accessor :val, :children\n# def initialize(val=0, children=[])\n# @val = val\n# @children = children\n# end\n# end\n\n# @param {TreeNode} root\n# @param {TreeNode} p\n# @param {TreeNode} q\n# @return {Integer}\ndef move_sub_tree(root, p, q)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a Node.\n * public class Node {\n * public var val: Int\n * public var children: [Node]\n * public init(_ val: Int) {\n * self.val = val\n * self.children = []\n * }\n * }\n */\n\nclass Solution {\n func moveSubTree(_ root: Node?, _ p: Node?, _ q: Node?) -> Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a Node.\n * type Node struct {\n * Val int\n * Children []*Node\n * }\n */\n\nfunc moveSubTree(root *Node, p *Node, q *Node) *Node {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a Node.\n * class Node(var _value: Int) {\n * var value: Int = _value\n * var children: List[Node] = List()\n * }\n */\n\nobject Solution {\n def moveSubTree(root: Node, p: Node, q: Node): Node = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a Node.\n * class Node(var `val`: Int) {\n * var children: List = listOf()\n * }\n */\n\nclass Solution {\n fun moveSubTree(root: Node?, p: Node?, q: Node?): Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a Node.\n * class Node {\n * public $val = null;\n * public $children = null;\n * function __construct($val = 0) {\n * $this->val = $val;\n * $this->children = array();\n * }\n * }\n */\n\nclass Solution {\n\n /**\n * @param Node $root\n * @param Node $p\n * @param Node $q\n * @return Node\n */\n function moveSubTree($root, $p, $q) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for Node.\n * class Node {\n * val: number\n * children: Node[]\n * constructor(val?: number, children?: Node[]) {\n * this.val = (val===undefined ? 0 : val)\n * this.children = (children===undefined ? [] : children)\n * }\n * }\n */\n\nfunction moveSubTree(root: Node | null, p: Node | null, q: Node | null): Node | null {\n\t\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1516](https://leetcode-cn.com/problems/move-sub-tree-of-n-ary-tree)", "[\u79fb\u52a8 N \u53c9\u6811\u7684\u5b50\u6811](/solution/1500-1599/1516.Move%20Sub-Tree%20of%20N-Ary%20Tree/README.md)", "`\u6811`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1516](https://leetcode.com/problems/move-sub-tree-of-n-ary-tree)", "[Move Sub-Tree of N-Ary Tree](/solution/1500-1599/1516.Move%20Sub-Tree%20of%20N-Ary%20Tree/README_EN.md)", "`Tree`", "Hard", "\ud83d\udd12"]}, {"question_id": "1654", "frontend_question_id": "1511", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/customer-order-frequency", "url_en": "https://leetcode.com/problems/customer-order-frequency", "relative_path_cn": "/solution/1500-1599/1511.Customer%20Order%20Frequency/README.md", "relative_path_en": "/solution/1500-1599/1511.Customer%20Order%20Frequency/README_EN.md", "title_cn": "\u6d88\u8d39\u8005\u4e0b\u5355\u9891\u7387", "title_en": "Customer Order Frequency", "question_title_slug": "customer-order-frequency", "content_en": "

Table: Customers

\r\n\r\n
\r\n+---------------+---------+\r\n| Column Name   | Type    |\r\n+---------------+---------+\r\n| customer_id   | int     |\r\n| name          | varchar |\r\n| country       | varchar |\r\n+---------------+---------+\r\ncustomer_id is the primary key for this table.\r\nThis table contains information of the customers in the company.\r\n
\r\n\r\n

 

\r\n\r\n

Table: Product

\r\n\r\n
\r\n+---------------+---------+\r\n| Column Name   | Type    |\r\n+---------------+---------+\r\n| product_id    | int     |\r\n| description   | varchar |\r\n| price         | int     |\r\n+---------------+---------+\r\nproduct_id is the primary key for this table.\r\nThis table contains information of the products in the company.\r\nprice is the product cost.
\r\n\r\n

 

\r\n\r\n

Table: Orders

\r\n\r\n
\r\n+---------------+---------+\r\n| Column Name   | Type    |\r\n+---------------+---------+\r\n| order_id      | int     |\r\n| customer_id   | int     |\r\n| product_id    | int     |\r\n| order_date    | date    |\r\n| quantity      | int     |\r\n+---------------+---------+\r\norder_id is the primary key for this table.\r\nThis table contains information on customer orders.\r\ncustomer_id is the id of the customer who bought "quantity" products with id "product_id".\r\nOrder_date is the date in format ('YYYY-MM-DD') when the order was shipped.
\r\n\r\n

 

\r\n\r\n

Write an SQL query to report the customer_id and customer_name of customers who have spent at least $100 in each month of June and July 2020.

\r\n\r\n

Return the result table in any order.

\r\n\r\n

The query result format is in the following example.

\r\n\r\n

 

\r\n\r\n
\r\nCustomers\r\n+--------------+-----------+-------------+\r\n| customer_id  | name      | country     |\r\n+--------------+-----------+-------------+\r\n| 1            | Winston   | USA         |\r\n| 2            | Jonathan  | Peru        |\r\n| 3            | Moustafa  | Egypt       |\r\n+--------------+-----------+-------------+\r\n\r\nProduct\r\n+--------------+-------------+-------------+\r\n| product_id   | description | price       |\r\n+--------------+-------------+-------------+\r\n| 10           | LC Phone    | 300         |\r\n| 20           | LC T-Shirt  | 10          |\r\n| 30           | LC Book     | 45          |\r\n| 40           | LC Keychain | 2           |\r\n+--------------+-------------+-------------+\r\n\r\nOrders\r\n+--------------+-------------+-------------+-------------+-----------+\r\n| order_id     | customer_id | product_id  | order_date  | quantity  |\r\n+--------------+-------------+-------------+-------------+-----------+\r\n| 1            | 1           | 10          | 2020-06-10  | 1         |\r\n| 2            | 1           | 20          | 2020-07-01  | 1         |\r\n| 3            | 1           | 30          | 2020-07-08  | 2         |\r\n| 4            | 2           | 10          | 2020-06-15  | 2         |\r\n| 5            | 2           | 40          | 2020-07-01  | 10        |\r\n| 6            | 3           | 20          | 2020-06-24  | 2         |\r\n| 7            | 3           | 30          | 2020-06-25  | 2         |\r\n| 9            | 3           | 30          | 2020-05-08  | 3         |\r\n+--------------+-------------+-------------+-------------+-----------+\r\n\r\nResult table:\r\n+--------------+------------+\r\n| customer_id  | name       |  \r\n+--------------+------------+\r\n| 1            | Winston    |\r\n+--------------+------------+ \r\nWinston spent $300 (300 * 1) in June and $100 ( 10 * 1 + 45 * 2) in July 2020.\r\nJonathan spent $600 (300 * 2) in June and $20 ( 2 * 10) in July 2020.\r\nMoustafa spent $110 (10 * 2 + 45 * 2) in June and $0 in July 2020.\r\n
", "content_cn": "

\u8868: Customers

\n\n
+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| customer_id   | int     |\n| name          | varchar |\n| country       | varchar |\n+---------------+---------+\ncustomer_id \u662f\u8be5\u8868\u4e3b\u952e.\n\u8be5\u8868\u5305\u542b\u516c\u53f8\u6d88\u8d39\u8005\u7684\u4fe1\u606f.\n
\n\n

 

\n\n

\u8868: Product

\n\n
+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| product_id    | int     |\n| description   | varchar |\n| price         | int     |\n+---------------+---------+\nproduct_id \u662f\u8be5\u8868\u4e3b\u952e.\n\u8be5\u8868\u5305\u542b\u516c\u53f8\u4ea7\u54c1\u7684\u4fe1\u606f.\nprice \u662f\u672c\u4ea7\u54c1\u7684\u82b1\u9500.
\n\n

 

\n\n

\u8868: Orders

\n\n
+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| order_id      | int     |\n| customer_id   | int     |\n| product_id    | int     |\n| order_date    | date    |\n| quantity      | int     |\n+---------------+---------+\norder_id \u662f\u8be5\u8868\u4e3b\u952e.\n\u8be5\u8868\u5305\u542b\u6d88\u8d39\u8005\u4e0b\u5355\u7684\u4fe1\u606f.\ncustomer_id \u662f\u4e70\u4e86\u6570\u91cf\u4e3a"quantity", id\u4e3a"product_id"\u4ea7\u54c1\u7684\u6d88\u8d39\u8005\u7684 id.\nOrder_date \u662f\u8ba2\u5355\u53d1\u8d27\u7684\u65e5\u671f, \u683c\u5f0f\u4e3a('YYYY-MM-DD').
\n\n

 

\n\n

\u5199\u4e00\u4e2a SQL \u8bed\u53e5,  \u62a5\u544a\u6d88\u8d39\u8005\u7684 id \u548c\u540d\u5b57, \u5176\u4e2d\u6d88\u8d39\u8005\u5728 2020 \u5e74 6 \u6708\u548c 7 \u6708, \u6bcf\u6708\u81f3\u5c11\u82b1\u8d39\u4e86$100.

\n\n

\u7ed3\u679c\u8868\u65e0\u987a\u5e8f\u8981\u6c42.

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a.

\n\n

 

\n\n
Customers\n+--------------+-----------+-------------+\n| customer_id  | name      | country     |\n+--------------+-----------+-------------+\n| 1            | Winston   | USA         |\n| 2            | Jonathan  | Peru        |\n| 3            | Moustafa  | Egypt       |\n+--------------+-----------+-------------+\n\nProduct\n+--------------+-------------+-------------+\n| product_id   | description | price       |\n+--------------+-------------+-------------+\n| 10           | LC Phone    | 300         |\n| 20           | LC T-Shirt  | 10          |\n| 30           | LC Book     | 45          |\n| 40           | LC Keychain | 2           |\n+--------------+-------------+-------------+\n\nOrders\n+--------------+-------------+-------------+-------------+-----------+\n| order_id     | customer_id | product_id  | order_date  | quantity  |\n+--------------+-------------+-------------+-------------+-----------+\n| 1            | 1           | 10          | 2020-06-10  | 1         |\n| 2            | 1           | 20          | 2020-07-01  | 1         |\n| 3            | 1           | 30          | 2020-07-08  | 2         |\n| 4            | 2           | 10          | 2020-06-15  | 2         |\n| 5            | 2           | 40          | 2020-07-01  | 10        |\n| 6            | 3           | 20          | 2020-06-24  | 2         |\n| 7            | 3           | 30          | 2020-06-25  | 2         |\n| 9            | 3           | 30          | 2020-05-08  | 3         |\n+--------------+-------------+-------------+-------------+-----------+\n\nResult \u8868:\n+--------------+------------+\n| customer_id  | name       |  \n+--------------+------------+\n| 1            | Winston    |\n+--------------+------------+ \nWinston \u57282020\u5e746\u6708\u82b1\u8d39\u4e86$300(300 * 1), \u57287\u6708\u82b1\u8d39\u4e86$100(10 * 1 + 45 * 2).\nJonathan \u57282020\u5e746\u6708\u82b1\u8d39\u4e86$600(300 * 2), \u57287\u6708\u82b1\u8d39\u4e86$20(2 * 10).\nMoustafa \u57282020\u5e746\u6708\u82b1\u8d39\u4e86$110 (10 * 2 + 45 * 2), \u57287\u6708\u82b1\u8d39\u4e86$0.\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1511](https://leetcode-cn.com/problems/customer-order-frequency)", "[\u6d88\u8d39\u8005\u4e0b\u5355\u9891\u7387](/solution/1500-1599/1511.Customer%20Order%20Frequency/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1511](https://leetcode.com/problems/customer-order-frequency)", "[Customer Order Frequency](/solution/1500-1599/1511.Customer%20Order%20Frequency/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1653", "frontend_question_id": "1530", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-good-leaf-nodes-pairs", "url_en": "https://leetcode.com/problems/number-of-good-leaf-nodes-pairs", "relative_path_cn": "/solution/1500-1599/1530.Number%20of%20Good%20Leaf%20Nodes%20Pairs/README.md", "relative_path_en": "/solution/1500-1599/1530.Number%20of%20Good%20Leaf%20Nodes%20Pairs/README_EN.md", "title_cn": "\u597d\u53f6\u5b50\u8282\u70b9\u5bf9\u7684\u6570\u91cf", "title_en": "Number of Good Leaf Nodes Pairs", "question_title_slug": "number-of-good-leaf-nodes-pairs", "content_en": "

Given the root of a binary tree and an integer distance. A pair of two different leaf nodes of a binary tree is said to be good if the length of the shortest path between them is less than or equal to distance.

\r\n\r\n

Return the number of good leaf node pairs in the tree.

\r\n\r\n

 

\r\n

Example 1:

\r\n\"\"\r\n
\r\nInput: root = [1,2,3,null,4], distance = 3\r\nOutput: 1\r\nExplanation: The leaf nodes of the tree are 3 and 4 and the length of the shortest path between them is 3. This is the only good pair.\r\n
\r\n\r\n

Example 2:

\r\n\"\"\r\n
\r\nInput: root = [1,2,3,4,5,6,7], distance = 3\r\nOutput: 2\r\nExplanation: The good pairs are [4,5] and [6,7] with shortest path = 2. The pair [4,6] is not good because the length of ther shortest path between them is 4.\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: root = [7,1,4,6,null,5,3,null,null,null,null,null,2], distance = 3\r\nOutput: 1\r\nExplanation: The only good pair is [2,5].\r\n
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: root = [100], distance = 1\r\nOutput: 0\r\n
\r\n\r\n

Example 5:

\r\n\r\n
\r\nInput: root = [1,1,1], distance = 2\r\nOutput: 1\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • The number of nodes in the tree is in the range [1, 2^10].
  • \r\n\t
  • Each node's value is between [1, 100].
  • \r\n\t
  • 1 <= distance <= 10
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9 root \u548c\u4e00\u4e2a\u6574\u6570 distance \u3002

\n\n

\u5982\u679c\u4e8c\u53c9\u6811\u4e2d\u4e24\u4e2a \u53f6 \u8282\u70b9\u4e4b\u95f4\u7684 \u6700\u77ed\u8def\u5f84\u957f\u5ea6 \u5c0f\u4e8e\u6216\u8005\u7b49\u4e8e distance \uff0c\u90a3\u5b83\u4eec\u5c31\u53ef\u4ee5\u6784\u6210\u4e00\u7ec4 \u597d\u53f6\u5b50\u8282\u70b9\u5bf9 \u3002

\n\n

\u8fd4\u56de\u6811\u4e2d \u597d\u53f6\u5b50\u8282\u70b9\u5bf9\u7684\u6570\u91cf \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

 

\n\n

\"\"

\n\n
\u8f93\u5165\uff1aroot = [1,2,3,null,4], distance = 3\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u6811\u7684\u53f6\u8282\u70b9\u662f 3 \u548c 4 \uff0c\u5b83\u4eec\u4e4b\u95f4\u7684\u6700\u77ed\u8def\u5f84\u7684\u957f\u5ea6\u662f 3 \u3002\u8fd9\u662f\u552f\u4e00\u7684\u597d\u53f6\u5b50\u8282\u70b9\u5bf9\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1aroot = [1,2,3,4,5,6,7], distance = 3\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u597d\u53f6\u5b50\u8282\u70b9\u5bf9\u4e3a [4,5] \u548c [6,7] \uff0c\u6700\u77ed\u8def\u5f84\u957f\u5ea6\u90fd\u662f 2 \u3002\u4f46\u662f\u53f6\u5b50\u8282\u70b9\u5bf9 [4,6] \u4e0d\u6ee1\u8db3\u8981\u6c42\uff0c\u56e0\u4e3a\u5b83\u4eec\u4e4b\u95f4\u7684\u6700\u77ed\u8def\u5f84\u957f\u5ea6\u4e3a 4 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aroot = [7,1,4,6,null,5,3,null,null,null,null,null,2], distance = 3\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u552f\u4e00\u7684\u597d\u53f6\u5b50\u8282\u70b9\u5bf9\u662f [2,5] \u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1aroot = [100], distance = 1\n\u8f93\u51fa\uff1a0\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1aroot = [1,1,1], distance = 2\n\u8f93\u51fa\uff1a1\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • tree \u7684\u8282\u70b9\u6570\u5728 [1, 2^10] \u8303\u56f4\u5185\u3002
  • \n\t
  • \u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u90fd\u5728 [1, 100] \u4e4b\u95f4\u3002
  • \n\t
  • 1 <= distance <= 10
  • \n
\n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int countPairs(TreeNode* root, int distance) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int countPairs(TreeNode root, int distance) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def countPairs(self, root, distance):\n \"\"\"\n :type root: TreeNode\n :type distance: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def countPairs(self, root: TreeNode, distance: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint countPairs(struct TreeNode* root, int distance){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int CountPairs(TreeNode root, int distance) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number} distance\n * @return {number}\n */\nvar countPairs = function(root, distance) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @param {Integer} distance\n# @return {Integer}\ndef count_pairs(root, distance)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func countPairs(_ root: TreeNode?, _ distance: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc countPairs(root *TreeNode, distance int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def countPairs(root: TreeNode, distance: Int): Int = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun countPairs(root: TreeNode?, distance: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn count_pairs(root: Option>>, distance: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param Integer $distance\n * @return Integer\n */\n function countPairs($root, $distance) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction countPairs(root: TreeNode | null, distance: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (count-pairs root distance)\n (-> (or/c tree-node? #f) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1530](https://leetcode-cn.com/problems/number-of-good-leaf-nodes-pairs)", "[\u597d\u53f6\u5b50\u8282\u70b9\u5bf9\u7684\u6570\u91cf](/solution/1500-1599/1530.Number%20of%20Good%20Leaf%20Nodes%20Pairs/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1530](https://leetcode.com/problems/number-of-good-leaf-nodes-pairs)", "[Number of Good Leaf Nodes Pairs](/solution/1500-1599/1530.Number%20of%20Good%20Leaf%20Nodes%20Pairs/README_EN.md)", "`Tree`,`Depth-first Search`", "Medium", ""]}, {"question_id": "1652", "frontend_question_id": "1529", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/bulb-switcher-iv", "url_en": "https://leetcode.com/problems/bulb-switcher-iv", "relative_path_cn": "/solution/1500-1599/1529.Bulb%20Switcher%20IV/README.md", "relative_path_en": "/solution/1500-1599/1529.Bulb%20Switcher%20IV/README_EN.md", "title_cn": "\u706f\u6ce1\u5f00\u5173 IV", "title_en": "Bulb Switcher IV", "question_title_slug": "bulb-switcher-iv", "content_en": "

There is a room with n bulbs, numbered from 0 to n - 1, arranged in a row from left to right. Initially, all the bulbs are turned off.

\n\n

Your task is to obtain the configuration represented by target where target[i] is '1' if the ith bulb is turned on and is '0' if it is turned off.

\n\n

You have a switch to flip the state of the bulb, a flip operation is defined as follows:

\n\n
    \n\t
  • Choose any bulb (index i) of your current configuration.
  • \n\t
  • Flip each bulb from index i to index n - 1.
  • \n
\n\n

When any bulb is flipped it means that if it is '0' it changes to '1' and if it is '1' it changes to '0'.

\n\n

Return the minimum number of flips required to form target.

\n\n

 

\n

Example 1:

\n\n
\nInput: target = "10111"\nOutput: 3\nExplanation: Initial configuration "00000".\nflip from the third bulb:  "00000" -> "00111"\nflip from the first bulb:  "00111" -> "11000"\nflip from the second bulb:  "11000" -> "10111"\nWe need at least 3 flip operations to form target.
\n\n

Example 2:

\n\n
\nInput: target = "101"\nOutput: 3\nExplanation: "000" -> "111" -> "100" -> "101".\n
\n\n

Example 3:

\n\n
\nInput: target = "00000"\nOutput: 0\n
\n\n

Example 4:

\n\n
\nInput: target = "001011101"\nOutput: 5\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= target.length <= 105
  • \n\t
  • target[i] is either '0' or '1'.
  • \n
\n", "content_cn": "

\u623f\u95f4\u4e2d\u6709 n \u4e2a\u706f\u6ce1\uff0c\u7f16\u53f7\u4ece 0 \u5230 n-1 \uff0c\u81ea\u5de6\u5411\u53f3\u6392\u6210\u4e00\u884c\u3002\u6700\u5f00\u59cb\u7684\u65f6\u5019\uff0c\u6240\u6709\u7684\u706f\u6ce1\u90fd\u662f \u5173 \u7740\u7684\u3002

\n\n

\u8bf7\u4f60\u8bbe\u6cd5\u4f7f\u5f97\u706f\u6ce1\u7684\u5f00\u5173\u72b6\u6001\u548c target \u63cf\u8ff0\u7684\u72b6\u6001\u4e00\u81f4\uff0c\u5176\u4e2d target[i] \u7b49\u4e8e 1 \u7b2c i \u4e2a\u706f\u6ce1\u662f\u5f00\u7740\u7684\uff0c\u7b49\u4e8e 0 \u610f\u5473\u7740\u7b2c i \u4e2a\u706f\u662f\u5173\u7740\u7684\u3002

\n\n

\u6709\u4e00\u4e2a\u5f00\u5173\u53ef\u4ee5\u7528\u4e8e\u7ffb\u8f6c\u706f\u6ce1\u7684\u72b6\u6001\uff0c\u7ffb\u8f6c\u64cd\u4f5c\u5b9a\u4e49\u5982\u4e0b\uff1a

\n\n
    \n\t
  • \u9009\u62e9\u5f53\u524d\u914d\u7f6e\u4e0b\u7684\u4efb\u610f\u4e00\u4e2a\u706f\u6ce1\uff08\u4e0b\u6807\u4e3a i \uff09
  • \n\t
  • \u7ffb\u8f6c\u4e0b\u6807\u4ece i \u5230 n-1 \u7684\u6bcf\u4e2a\u706f\u6ce1
  • \n
\n\n

\u7ffb\u8f6c\u65f6\uff0c\u5982\u679c\u706f\u6ce1\u7684\u72b6\u6001\u4e3a 0 \u5c31\u53d8\u4e3a 1\uff0c\u4e3a 1 \u5c31\u53d8\u4e3a 0 \u3002

\n\n

\u8fd4\u56de\u8fbe\u6210 target \u63cf\u8ff0\u7684\u72b6\u6001\u6240\u9700\u7684 \u6700\u5c11 \u7ffb\u8f6c\u6b21\u6570\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1atarget = "10111"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u521d\u59cb\u914d\u7f6e "00000".\n\u4ece\u7b2c 3 \u4e2a\u706f\u6ce1\uff08\u4e0b\u6807\u4e3a 2\uff09\u5f00\u59cb\u7ffb\u8f6c "00000" -> "00111"\n\u4ece\u7b2c 1 \u4e2a\u706f\u6ce1\uff08\u4e0b\u6807\u4e3a 0\uff09\u5f00\u59cb\u7ffb\u8f6c "00111" -> "11000"\n\u4ece\u7b2c 2 \u4e2a\u706f\u6ce1\uff08\u4e0b\u6807\u4e3a 1\uff09\u5f00\u59cb\u7ffb\u8f6c "11000" -> "10111"\n\u81f3\u5c11\u9700\u8981\u7ffb\u8f6c 3 \u6b21\u624d\u80fd\u8fbe\u6210 target \u63cf\u8ff0\u7684\u72b6\u6001
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1atarget = "101"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a"000" -> "111" -> "100" -> "101".\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1atarget = "00000"\n\u8f93\u51fa\uff1a0\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1atarget = "001011101"\n\u8f93\u51fa\uff1a5\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= target.length <= 10^5
  • \n\t
  • target[i] == '0' \u6216\u8005 target[i] == '1'
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minFlips(string target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minFlips(String target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minFlips(self, target):\n \"\"\"\n :type target: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minFlips(self, target: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minFlips(char * target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinFlips(string target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} target\n * @return {number}\n */\nvar minFlips = function(target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} target\n# @return {Integer}\ndef min_flips(target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minFlips(_ target: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minFlips(target string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minFlips(target: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minFlips(target: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_flips(target: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $target\n * @return Integer\n */\n function minFlips($target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minFlips(target: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-flips target)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1529](https://leetcode-cn.com/problems/bulb-switcher-iv)", "[\u706f\u6ce1\u5f00\u5173 IV](/solution/1500-1599/1529.Bulb%20Switcher%20IV/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1529](https://leetcode.com/problems/bulb-switcher-iv)", "[Bulb Switcher IV](/solution/1500-1599/1529.Bulb%20Switcher%20IV/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "1651", "frontend_question_id": "1528", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/shuffle-string", "url_en": "https://leetcode.com/problems/shuffle-string", "relative_path_cn": "/solution/1500-1599/1528.Shuffle%20String/README.md", "relative_path_en": "/solution/1500-1599/1528.Shuffle%20String/README_EN.md", "title_cn": "\u91cd\u65b0\u6392\u5217\u5b57\u7b26\u4e32", "title_en": "Shuffle String", "question_title_slug": "shuffle-string", "content_en": "

Given a string s and an integer array indices of the same length.

\r\n\r\n

The string s will be shuffled such that the character at the ith position moves to indices[i] in the shuffled string.

\r\n\r\n

Return the shuffled string.

\r\n\r\n

 

\r\n

Example 1:

\r\n\"\"\r\n
\r\nInput: s = "codeleet", indices = [4,5,6,7,0,2,1,3]\r\nOutput: "leetcode"\r\nExplanation: As shown, "codeleet" becomes "leetcode" after shuffling.\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: s = "abc", indices = [0,1,2]\r\nOutput: "abc"\r\nExplanation: After shuffling, each character remains in its position.\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: s = "aiohn", indices = [3,1,4,2,0]\r\nOutput: "nihao"\r\n
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: s = "aaiougrt", indices = [4,0,2,6,7,3,1,5]\r\nOutput: "arigatou"\r\n
\r\n\r\n

Example 5:

\r\n\r\n
\r\nInput: s = "art", indices = [1,0,2]\r\nOutput: "rat"\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • s.length == indices.length == n
  • \r\n\t
  • 1 <= n <= 100
  • \r\n\t
  • s contains only lower-case English letters.
  • \r\n\t
  • 0 <= indices[i] < n
  • \r\n\t
  • All values of indices are unique (i.e. indices is a permutation of the integers from 0 to n - 1).
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \u548c\u4e00\u4e2a \u957f\u5ea6\u76f8\u540c \u7684\u6574\u6570\u6570\u7ec4 indices \u3002

\n\n

\u8bf7\u4f60\u91cd\u65b0\u6392\u5217\u5b57\u7b26\u4e32 s \uff0c\u5176\u4e2d\u7b2c i \u4e2a\u5b57\u7b26\u9700\u8981\u79fb\u52a8\u5230 indices[i] \u6307\u793a\u7684\u4f4d\u7f6e\u3002

\n\n

\u8fd4\u56de\u91cd\u65b0\u6392\u5217\u540e\u7684\u5b57\u7b26\u4e32\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1as = "codeleet", indices = [4,5,6,7,0,2,1,3]\n\u8f93\u51fa\uff1a"leetcode"\n\u89e3\u91ca\uff1a\u5982\u56fe\u6240\u793a\uff0c"codeleet" \u91cd\u65b0\u6392\u5217\u540e\u53d8\u4e3a "leetcode" \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1as = "abc", indices = [0,1,2]\n\u8f93\u51fa\uff1a"abc"\n\u89e3\u91ca\uff1a\u91cd\u65b0\u6392\u5217\u540e\uff0c\u6bcf\u4e2a\u5b57\u7b26\u90fd\u8fd8\u7559\u5728\u539f\u6765\u7684\u4f4d\u7f6e\u4e0a\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1as = "aiohn", indices = [3,1,4,2,0]\n\u8f93\u51fa\uff1a"nihao"\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1as = "aaiougrt", indices = [4,0,2,6,7,3,1,5]\n\u8f93\u51fa\uff1a"arigatou"\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1as = "art", indices = [1,0,2]\n\u8f93\u51fa\uff1a"rat"\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • s.length == indices.length == n
  • \n\t
  • 1 <= n <= 100
  • \n\t
  • s \u4ec5\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
  • \n\t
  • 0 <= indices[i] < n
  • \n\t
  • indices \u7684\u6240\u6709\u7684\u503c\u90fd\u662f\u552f\u4e00\u7684\uff08\u4e5f\u5c31\u662f\u8bf4\uff0cindices \u662f\u6574\u6570 0 \u5230 n - 1 \u5f62\u6210\u7684\u4e00\u7ec4\u6392\u5217\uff09\u3002
  • \n
\n", "tags_en": ["Sort"], "tags_cn": ["\u6392\u5e8f"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string restoreString(string s, vector& indices) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String restoreString(String s, int[] indices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def restoreString(self, s, indices):\n \"\"\"\n :type s: str\n :type indices: List[int]\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def restoreString(self, s: str, indices: List[int]) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * restoreString(char * s, int* indices, int indicesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string RestoreString(string s, int[] indices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number[]} indices\n * @return {string}\n */\nvar restoreString = function(s, indices) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer[]} indices\n# @return {String}\ndef restore_string(s, indices)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func restoreString(_ s: String, _ indices: [Int]) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func restoreString(s string, indices []int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def restoreString(s: String, indices: Array[Int]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun restoreString(s: String, indices: IntArray): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn restore_string(s: String, indices: Vec) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer[] $indices\n * @return String\n */\n function restoreString($s, $indices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function restoreString(s: string, indices: number[]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (restore-string s indices)\n (-> string? (listof exact-integer?) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1528](https://leetcode-cn.com/problems/shuffle-string)", "[\u91cd\u65b0\u6392\u5217\u5b57\u7b26\u4e32](/solution/1500-1599/1528.Shuffle%20String/README.md)", "`\u6392\u5e8f`", "\u7b80\u5355", ""], "md_table_row_en": ["[1528](https://leetcode.com/problems/shuffle-string)", "[Shuffle String](/solution/1500-1599/1528.Shuffle%20String/README_EN.md)", "`Sort`", "Easy", ""]}, {"question_id": "1650", "frontend_question_id": "1506", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/find-root-of-n-ary-tree", "url_en": "https://leetcode.com/problems/find-root-of-n-ary-tree", "relative_path_cn": "/solution/1500-1599/1506.Find%20Root%20of%20N-Ary%20Tree/README.md", "relative_path_en": "/solution/1500-1599/1506.Find%20Root%20of%20N-Ary%20Tree/README_EN.md", "title_cn": "\u627e\u5230 N \u53c9\u6811\u7684\u6839\u8282\u70b9", "title_en": "Find Root of N-Ary Tree", "question_title_slug": "find-root-of-n-ary-tree", "content_en": "

You are given all the nodes of an N-ary tree as an array of Node objects, where each node has a unique value.

\n\n

Return the root of the N-ary tree.

\n\n

Custom testing:

\n\n

An N-ary tree can be serialized as represented in its level order traversal where each group of children is separated by the null value (see examples).

\n\n

\"\"

\n\n

For example, the above tree is serialized as [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14].

\n\n

The testing will be done in the following way:

\n\n
    \n\t
  1. The input data should be provided as a serialization of the tree.
  2. \n\t
  3. The driver code will construct the tree from the serialized input data and put each Node object into an array in an arbitrary order.
  4. \n\t
  5. The driver code will pass the array to findRoot, and your function should find and return the root Node object in the array.
  6. \n\t
  7. The driver code will take the returned Node object and serialize it. If the serialized value and the input data are the same, the test passes.
  8. \n
\n\n

 

\n

Example 1:

\n\n

\n\n
\nInput: tree = [1,null,3,2,4,null,5,6]\nOutput: [1,null,3,2,4,null,5,6]\nExplanation: The tree from the input data is shown above.\nThe driver code creates the tree and gives findRoot the Node objects in an arbitrary order.\nFor example, the passed array could be [Node(5),Node(4),Node(3),Node(6),Node(2),Node(1)] or [Node(2),Node(6),Node(1),Node(3),Node(5),Node(4)].\nThe findRoot function should return the root Node(1), and the driver code will serialize it and compare with the input data.\nThe input data and serialized Node(1) are the same, so the test passes.\n
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: tree = [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]\nOutput: [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The total number of nodes is between [1, 5 * 104].
  • \n\t
  • Each node has a unique value.
  • \n
\n\n

 

\n

Follow up:

\n\n
    \n\t
  • Could you solve this problem in constant space complexity with a linear time algorithm?
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u68f5\u00a0N \u53c9\u6811\u00a0\u7684\u6240\u6709\u8282\u70b9\u5728\u4e00\u4e2a\u6570\u7ec4\u00a0\u00a0Node[] tree\u00a0\u4e2d\uff0c\u6811\u4e2d\u6bcf\u4e2a\u8282\u70b9\u90fd\u6709 \u552f\u4e00\u7684\u503c \u3002

\n\n

\u627e\u5230\u5e76\u8fd4\u56de N \u53c9\u6811\u7684 \u6839\u8282\u70b9 \u3002

\n\n

\u00a0

\n\n

\u81ea\u5b9a\u4e49\u6d4b\u8bd5\uff1a

\n\n

N \u53c9\u6811\u7684\u8f93\u5165\u5e8f\u5217\u4e3a\u5176\u5c42\u5e8f\u904d\u5386\u5e8f\u5217\uff0c\u6bcf\u7ec4\u5b50\u8282\u70b9\u7528 null \u5206\u9694\uff08\u89c1\u793a\u4f8b\uff09\u3002

\n\n

\"\"

\n\n

\u4e0a\u56fe\u4e2d\u7684 N \u53c9\u6811\u7684\u5e8f\u5217\u5316\u63cf\u8ff0\u4e3a [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14] \u3002

\n\n

\u6d4b\u8bd5\u5c06\u4ee5\u4e0b\u5217\u65b9\u5f0f\u8fdb\u884c\uff1a

\n\n
    \n\t
  • \u8f93\u5165\u6570\u636e\u7684\u5f62\u5f0f\u4e3a\u6811\u7684\u5e8f\u5217\u5316\u63cf\u8ff0\u3002
  • \n\t
  • \u9a71\u52a8\u7a0b\u5e8f\u4ee3\u7801\u5c06\u6839\u636e\u5e8f\u5217\u5316\u7684\u8f93\u5165\u6570\u636e\u6784\u9020\u6811\uff0c\u5e76\u4ee5\u4efb\u610f\u987a\u5e8f\u5c06\u6bcf\u4e2a Node \u5bf9\u8c61\u653e\u5165\u4e00\u4e2a\u6570\u7ec4\u4e2d\u3002
  • \n\t
  • \u9a71\u52a8\u7a0b\u5e8f\u4ee3\u7801\u5c06\u628a\u6570\u7ec4\u4f20\u9012\u7ed9 findRoot \uff0c\u4f60\u6240\u7f16\u5199\u7684\u51fd\u6570\u5e94\u8be5\u5728\u6570\u7ec4\u4e2d\u67e5\u627e\u5e76\u8fd4\u56de\u6839 Node \u5bf9\u8c61\u3002
  • \n\t
  • \u9a71\u52a8\u7a0b\u5e8f\u4ee3\u7801\u5c06\u63a5\u53d7\u8fd4\u56de\u7684 Node \u5bf9\u8c61\u5e76\u5bf9\u5176\u8fdb\u884c\u5e8f\u5217\u5316\u3002\u5982\u679c\u5e8f\u5217\u5316\u7684\u7ed3\u679c\u548c\u8f93\u5165\u6570\u636e \u76f8\u540c \uff0c\u5219\u6d4b\u8bd5 \u901a\u8fc7 \u3002
  • \n
\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\n\n
\n\u8f93\u5165\uff1atree = [1,null,3,2,4,null,5,6]\n\u8f93\u51fa\uff1a[1,null,3,2,4,null,5,6]\n\u89e3\u91ca\uff1a\u6765\u81ea\u8f93\u5165\u6570\u636e\u7684\u6811\u5982\u4e0a\u6240\u793a\u3002\n\u9a71\u52a8\u7a0b\u5e8f\u4ee3\u7801\u521b\u5efa\u6811\uff0c\u5e76\u4ee5\u4efb\u610f\u987a\u5e8f\u5411 findRoot \u63d0\u4f9b Node \u5bf9\u8c61\u3002\n\u4f8b\u5982\uff0c\u4f20\u9012\u7684\u6570\u7ec4\u53ef\u4ee5\u662f [Node(5),Node(4),Node(3),Node(6),Node(2),Node(1)] \u6216 [Node(2),Node(6),Node(1),Node(3),Node(5),Node(4)] \u3002\nfindRoot \u51fd\u6570\u5e94\u8be5\u8fd4\u56de\u6839 Node(1) \uff0c\u9a71\u52a8\u7a0b\u5e8f\u4ee3\u7801\u5c06\u5e8f\u5217\u5316\u5b83\u5e76\u4e0e\u8f93\u5165\u6570\u636e\u8fdb\u884c\u6bd4\u8f83\u3002\n\u8f93\u5165\u6570\u636e\u548c\u5e8f\u5217\u5316\u7684 Node(1) \u76f8\u540c\uff0c\u56e0\u6b64\u6d4b\u8bd5\u901a\u8fc7\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1atree = [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]\n\u8f93\u51fa\uff1a[1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u8282\u70b9\u7684\u603b\u4e2a\u6570\u5728\u00a0[1,\u00a05*10^4]\u00a0\u4e4b\u95f4\u3002
  • \n\t
  • \u6bcf\u4e2a\u8282\u70b9\u90fd\u6709\u552f\u4e00\u7684\u503c\u3002
  • \n
\n\n

\u00a0

\n\n

\u8fdb\u9636\uff1a

\n\n
    \n\t
  • \u4f60\u53ef\u4ee5\u4f7f\u7528 O(1) \u989d\u5916\u5185\u5b58\u7a7a\u95f4\u4e14 O(n) \u65f6\u95f4\u590d\u6742\u5ea6\u7684\u7b97\u6cd5\u6765\u627e\u5230\u8be5\u6811\u7684\u6839\u8282\u70b9\u5417\uff1f
  • \n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n vector children;\n\n Node() {}\n\n Node(int _val) {\n val = _val;\n }\n\n Node(int _val, vector _children) {\n val = _val;\n children = _children;\n }\n};\n*/\n\nclass Solution {\npublic:\n Node* findRoot(vector tree) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/*\n// Definition for a Node.\nclass Node {\n public int val;\n public List children;\n\n \n public Node() {\n children = new ArrayList();\n }\n \n public Node(int _val) {\n val = _val;\n children = new ArrayList();\n }\n \n public Node(int _val,ArrayList _children) {\n val = _val;\n children = _children;\n }\n};\n*/\n\nclass Solution {\n public Node findRoot(List tree) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "\"\"\"\n# Definition for a Node.\nclass Node(object):\n def __init__(self, val=None, children=None):\n self.val = val\n self.children = children if children is not None else []\n\"\"\"\n\nclass Solution(object):\n def findRoot(self, tree):\n \"\"\"\n :type tree: List['Node']\n :rtype: 'Node'\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "\"\"\"\n# Definition for a Node.\nclass Node:\n def __init__(self, val=None, children=None):\n self.val = val\n self.children = children if children is not None else []\n\"\"\"\n\nclass Solution:\n def findRoot(self, tree: List['Node']) -> 'Node':\n ", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/*\n// Definition for a Node.\npublic class Node {\n public int val;\n public IList children;\n \n public Node() {\n val = 0;\n children = new List();\n }\n\n public Node(int _val) {\n val = _val;\n children = new List();\n }\n \n public Node(int _val, List _children) {\n val = _val;\n children = _children;\n }\n}\n*/\n\npublic class Solution {\n public Node FindRoot(List tree) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // Definition for a Node.\n * function Node(val, children) {\n * this.val = val === undefined ? 0 : val;\n * this.children = children === undefined ? [] : children;\n * };\n */\n\n/**\n * @param {Node[]} tree\n * @return {Node}\n */\nvar findRoot = function(tree) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a Node.\n# class Node\n# attr_accessor :val, :children\n# def initialize(val=0, children=[])\n# @val = val\n# @children = children\n# end\n# end\n\n# @param {Node[]} tree\n# @return {Node}\ndef find_root(tree)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a Node.\n * public class Node {\n * public var val: Int\n * public var children: [Node]\n * public init(_ val: Int) {\n * self.val = val\n * self.children = []\n * }\n * }\n */\n\nclass Solution {\n func findRoot(_ tree: [Node]) -> Node? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a Node.\n * type Node struct {\n * Val int\n * Children []*Node\n * }\n */\n\nfunc findRoot(tree []*Node) *Node {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a Node.\n * class Node(var _value: Int) {\n * var value: Int = _value\n * var children: List[Node] = List()\n * }\n */\n\nobject Solution {\n def findRoot(tree: List[Node]): Node = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a Node.\n * class Node(var `val`: Int) {\n * var children: List = listOf()\n * }\n */\n\nclass Solution {\n fun findRoot(tree: List): Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a Node.\n * class Node {\n * public $val = null;\n * public $children = null;\n * function __construct($val = 0) {\n * $this->val = $val;\n * $this->children = array();\n * }\n * }\n */\n\nclass Solution {\n /**\n * @param Node[] $tree\n * @return Node\n */\n function findRoot($tree) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for Node.\n * class Node {\n * val: number\n * children: Node[]\n * constructor(val?: number, children?: Node[]) {\n * this.val = (val===undefined ? 0 : val)\n * this.children = (children===undefined ? [] : children)\n * }\n * }\n */\n\nfunction findRoot(tree: Node[]): Node | null {\n \n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1506](https://leetcode-cn.com/problems/find-root-of-n-ary-tree)", "[\u627e\u5230 N \u53c9\u6811\u7684\u6839\u8282\u70b9](/solution/1500-1599/1506.Find%20Root%20of%20N-Ary%20Tree/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1506](https://leetcode.com/problems/find-root-of-n-ary-tree)", "[Find Root of N-Ary Tree](/solution/1500-1599/1506.Find%20Root%20of%20N-Ary%20Tree/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1649", "frontend_question_id": "1546", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-number-of-non-overlapping-subarrays-with-sum-equals-target", "url_en": "https://leetcode.com/problems/maximum-number-of-non-overlapping-subarrays-with-sum-equals-target", "relative_path_cn": "/solution/1500-1599/1546.Maximum%20Number%20of%20Non-Overlapping%20Subarrays%20With%20Sum%20Equals%20Target/README.md", "relative_path_en": "/solution/1500-1599/1546.Maximum%20Number%20of%20Non-Overlapping%20Subarrays%20With%20Sum%20Equals%20Target/README_EN.md", "title_cn": "\u548c\u4e3a\u76ee\u6807\u503c\u4e14\u4e0d\u91cd\u53e0\u7684\u975e\u7a7a\u5b50\u6570\u7ec4\u7684\u6700\u5927\u6570\u76ee", "title_en": "Maximum Number of Non-Overlapping Subarrays With Sum Equals Target", "question_title_slug": "maximum-number-of-non-overlapping-subarrays-with-sum-equals-target", "content_en": "

Given an array nums and an integer target.

\n\n

Return the maximum number of non-empty non-overlapping subarrays such that the sum of values in each subarray is equal to target.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [1,1,1,1,1], target = 2\nOutput: 2\nExplanation: There are 2 non-overlapping subarrays [1,1,1,1,1] with sum equals to target(2).\n
\n\n

Example 2:

\n\n
\nInput: nums = [-1,3,5,1,4,2,-9], target = 6\nOutput: 2\nExplanation: There are 3 subarrays with sum equal to 6.\n([5,1], [4,2], [3,5,1,4,2,-9]) but only the first 2 are non-overlapping.
\n\n

Example 3:

\n\n
\nInput: nums = [-2,6,6,3,5,4,1,2,8], target = 10\nOutput: 3\n
\n\n

Example 4:

\n\n
\nInput: nums = [0,0,0], target = 0\nOutput: 3\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 10^5
  • \n\t
  • -10^4 <= nums[i] <= 10^4
  • \n\t
  • 0 <= target <= 10^6
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 nums \u548c\u4e00\u4e2a\u6574\u6570 target \u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de \u975e\u7a7a\u4e0d\u91cd\u53e0 \u5b50\u6570\u7ec4\u7684\u6700\u5927\u6570\u76ee\uff0c\u4e14\u6bcf\u4e2a\u5b50\u6570\u7ec4\u4e2d\u6570\u5b57\u548c\u90fd\u4e3a target \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,1,1,1,1], target = 2\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u603b\u5171\u6709 2 \u4e2a\u4e0d\u91cd\u53e0\u5b50\u6570\u7ec4\uff08\u52a0\u7c97\u6570\u5b57\u8868\u793a\uff09 [1,1,1,1,1] \uff0c\u5b83\u4eec\u7684\u548c\u4e3a\u76ee\u6807\u503c 2 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anums = [-1,3,5,1,4,2,-9], target = 6\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u603b\u5171\u6709 3 \u4e2a\u5b50\u6570\u7ec4\u548c\u4e3a 6 \u3002\n([5,1], [4,2], [3,5,1,4,2,-9]) \u4f46\u53ea\u6709\u524d 2 \u4e2a\u662f\u4e0d\u91cd\u53e0\u7684\u3002
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1anums = [-2,6,6,3,5,4,1,2,8], target = 10\n\u8f93\u51fa\uff1a3\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1anums = [0,0,0], target = 0\n\u8f93\u51fa\uff1a3\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 10^5
  • \n\t
  • -10^4 <= nums[i] <= 10^4
  • \n\t
  • 0 <= target <= 10^6
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxNonOverlapping(vector& nums, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxNonOverlapping(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxNonOverlapping(self, nums, target):\n \"\"\"\n :type nums: List[int]\n :type target: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxNonOverlapping(self, nums: List[int], target: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxNonOverlapping(int* nums, int numsSize, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxNonOverlapping(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} target\n * @return {number}\n */\nvar maxNonOverlapping = function(nums, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} target\n# @return {Integer}\ndef max_non_overlapping(nums, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxNonOverlapping(_ nums: [Int], _ target: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxNonOverlapping(nums []int, target int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxNonOverlapping(nums: Array[Int], target: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxNonOverlapping(nums: IntArray, target: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_non_overlapping(nums: Vec, target: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $target\n * @return Integer\n */\n function maxNonOverlapping($nums, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxNonOverlapping(nums: number[], target: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-non-overlapping nums target)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1546](https://leetcode-cn.com/problems/maximum-number-of-non-overlapping-subarrays-with-sum-equals-target)", "[\u548c\u4e3a\u76ee\u6807\u503c\u4e14\u4e0d\u91cd\u53e0\u7684\u975e\u7a7a\u5b50\u6570\u7ec4\u7684\u6700\u5927\u6570\u76ee](/solution/1500-1599/1546.Maximum%20Number%20of%20Non-Overlapping%20Subarrays%20With%20Sum%20Equals%20Target/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1546](https://leetcode.com/problems/maximum-number-of-non-overlapping-subarrays-with-sum-equals-target)", "[Maximum Number of Non-Overlapping Subarrays With Sum Equals Target](/solution/1500-1599/1546.Maximum%20Number%20of%20Non-Overlapping%20Subarrays%20With%20Sum%20Equals%20Target/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "1648", "frontend_question_id": "1541", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-insertions-to-balance-a-parentheses-string", "url_en": "https://leetcode.com/problems/minimum-insertions-to-balance-a-parentheses-string", "relative_path_cn": "/solution/1500-1599/1541.Minimum%20Insertions%20to%20Balance%20a%20Parentheses%20String/README.md", "relative_path_en": "/solution/1500-1599/1541.Minimum%20Insertions%20to%20Balance%20a%20Parentheses%20String/README_EN.md", "title_cn": "\u5e73\u8861\u62ec\u53f7\u5b57\u7b26\u4e32\u7684\u6700\u5c11\u63d2\u5165\u6b21\u6570", "title_en": "Minimum Insertions to Balance a Parentheses String", "question_title_slug": "minimum-insertions-to-balance-a-parentheses-string", "content_en": "

Given a parentheses string s containing only the characters '(' and ')'. A parentheses string is balanced if:

\n\n
    \n\t
  • Any left parenthesis '(' must have a corresponding two consecutive right parenthesis '))'.
  • \n\t
  • Left parenthesis '(' must go before the corresponding two consecutive right parenthesis '))'.
  • \n
\n\n

In other words, we treat '(' as openning parenthesis and '))' as closing parenthesis.

\n\n

For example, "())", "())(())))" and "(())())))" are balanced, ")()", "()))" and "(()))" are not balanced.

\n\n

You can insert the characters '(' and ')' at any position of the string to balance it if needed.

\n\n

Return the minimum number of insertions needed to make s balanced.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "(()))"\nOutput: 1\nExplanation: The second '(' has two matching '))', but the first '(' has only ')' matching. We need to to add one more ')' at the end of the string to be "(())))" which is balanced.\n
\n\n

Example 2:

\n\n
\nInput: s = "())"\nOutput: 0\nExplanation: The string is already balanced.\n
\n\n

Example 3:

\n\n
\nInput: s = "))())("\nOutput: 3\nExplanation: Add '(' to match the first '))', Add '))' to match the last '('.\n
\n\n

Example 4:

\n\n
\nInput: s = "(((((("\nOutput: 12\nExplanation: Add 12 ')' to balance the string.\n
\n\n

Example 5:

\n\n
\nInput: s = ")))))))"\nOutput: 5\nExplanation: Add 4 '(' at the beginning of the string and one ')' at the end. The string becomes "(((())))))))".\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 10^5
  • \n\t
  • s consists of '(' and ')' only.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u62ec\u53f7\u5b57\u7b26\u4e32 s \uff0c\u5b83\u53ea\u5305\u542b\u5b57\u7b26 '(' \u548c ')' \u3002\u4e00\u4e2a\u62ec\u53f7\u5b57\u7b26\u4e32\u88ab\u79f0\u4e3a\u5e73\u8861\u7684\u5f53\u5b83\u6ee1\u8db3\uff1a

\n\n
    \n\t
  • \u4efb\u4f55\u5de6\u62ec\u53f7 '(' \u5fc5\u987b\u5bf9\u5e94\u4e24\u4e2a\u8fde\u7eed\u7684\u53f3\u62ec\u53f7 '))' \u3002
  • \n\t
  • \u5de6\u62ec\u53f7 '(' \u5fc5\u987b\u5728\u5bf9\u5e94\u7684\u8fde\u7eed\u4e24\u4e2a\u53f3\u62ec\u53f7 '))' \u4e4b\u524d\u3002
  • \n
\n\n

\u6bd4\u65b9\u8bf4 "())"\uff0c "())(())))" \u548c "(())())))" \u90fd\u662f\u5e73\u8861\u7684\uff0c ")()"\uff0c "()))" \u548c "(()))" \u90fd\u662f\u4e0d\u5e73\u8861\u7684\u3002

\n\n

\u4f60\u53ef\u4ee5\u5728\u4efb\u610f\u4f4d\u7f6e\u63d2\u5165\u5b57\u7b26 '(' \u548c ')' \u4f7f\u5b57\u7b26\u4e32\u5e73\u8861\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u8ba9 s \u5e73\u8861\u7684\u6700\u5c11\u63d2\u5165\u6b21\u6570\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1as = "(()))"\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u7b2c\u4e8c\u4e2a\u5de6\u62ec\u53f7\u6709\u4e0e\u4e4b\u5339\u914d\u7684\u4e24\u4e2a\u53f3\u62ec\u53f7\uff0c\u4f46\u662f\u7b2c\u4e00\u4e2a\u5de6\u62ec\u53f7\u53ea\u6709\u4e00\u4e2a\u53f3\u62ec\u53f7\u3002\u6211\u4eec\u9700\u8981\u5728\u5b57\u7b26\u4e32\u7ed3\u5c3e\u989d\u5916\u589e\u52a0\u4e00\u4e2a ')' \u4f7f\u5b57\u7b26\u4e32\u53d8\u6210\u5e73\u8861\u5b57\u7b26\u4e32 "(())))" \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1as = "())"\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u5b57\u7b26\u4e32\u5df2\u7ecf\u5e73\u8861\u4e86\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1as = "))())("\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6dfb\u52a0 '(' \u53bb\u5339\u914d\u6700\u5f00\u5934\u7684 '))' \uff0c\u7136\u540e\u6dfb\u52a0 '))' \u53bb\u5339\u914d\u6700\u540e\u4e00\u4e2a '(' \u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1as = "(((((("\n\u8f93\u51fa\uff1a12\n\u89e3\u91ca\uff1a\u6dfb\u52a0 12 \u4e2a ')' \u5f97\u5230\u5e73\u8861\u5b57\u7b26\u4e32\u3002\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1as = ")))))))"\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u5728\u5b57\u7b26\u4e32\u5f00\u5934\u6dfb\u52a0 4 \u4e2a '(' \u5e76\u5728\u7ed3\u5c3e\u6dfb\u52a0 1 \u4e2a ')' \uff0c\u5b57\u7b26\u4e32\u53d8\u6210\u5e73\u8861\u5b57\u7b26\u4e32 "(((())))))))" \u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length <= 10^5
  • \n\t
  • s \u53ea\u5305\u542b '(' \u548c ')' \u3002
  • \n
\n", "tags_en": ["Stack", "String"], "tags_cn": ["\u6808", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minInsertions(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minInsertions(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minInsertions(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minInsertions(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minInsertions(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinInsertions(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar minInsertions = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef min_insertions(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minInsertions(_ s: String) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minInsertions(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minInsertions(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minInsertions(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_insertions(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function minInsertions($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minInsertions(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-insertions s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1541](https://leetcode-cn.com/problems/minimum-insertions-to-balance-a-parentheses-string)", "[\u5e73\u8861\u62ec\u53f7\u5b57\u7b26\u4e32\u7684\u6700\u5c11\u63d2\u5165\u6b21\u6570](/solution/1500-1599/1541.Minimum%20Insertions%20to%20Balance%20a%20Parentheses%20String/README.md)", "`\u6808`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1541](https://leetcode.com/problems/minimum-insertions-to-balance-a-parentheses-string)", "[Minimum Insertions to Balance a Parentheses String](/solution/1500-1599/1541.Minimum%20Insertions%20to%20Balance%20a%20Parentheses%20String/README_EN.md)", "`Stack`,`String`", "Medium", ""]}, {"question_id": "1647", "frontend_question_id": "1540", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/can-convert-string-in-k-moves", "url_en": "https://leetcode.com/problems/can-convert-string-in-k-moves", "relative_path_cn": "/solution/1500-1599/1540.Can%20Convert%20String%20in%20K%20Moves/README.md", "relative_path_en": "/solution/1500-1599/1540.Can%20Convert%20String%20in%20K%20Moves/README_EN.md", "title_cn": "K \u6b21\u64cd\u4f5c\u8f6c\u53d8\u5b57\u7b26\u4e32", "title_en": "Can Convert String in K Moves", "question_title_slug": "can-convert-string-in-k-moves", "content_en": "

Given two strings s and t, your goal is to convert s into t in k moves or less.

\n\n

During the ith (1 <= i <= kmove you can:

\n\n
    \n\t
  • Choose any index j (1-indexed) from s, such that 1 <= j <= s.length and j has not been chosen in any previous move, and shift the character at that index i times.
  • \n\t
  • Do nothing.
  • \n
\n\n

Shifting a character means replacing it by the next letter in the alphabet (wrapping around so that 'z' becomes 'a'). Shifting a character by i means applying the shift operations i times.

\n\n

Remember that any index j can be picked at most once.

\n\n

Return true if it's possible to convert s into t in no more than k moves, otherwise return false.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "input", t = "ouput", k = 9\nOutput: true\nExplanation: In the 6th move, we shift 'i' 6 times to get 'o'. And in the 7th move we shift 'n' to get 'u'.\n
\n\n

Example 2:

\n\n
\nInput: s = "abc", t = "bcd", k = 10\nOutput: false\nExplanation: We need to shift each character in s one time to convert it into t. We can shift 'a' to 'b' during the 1st move. However, there is no way to shift the other characters in the remaining moves to obtain t from s.\n
\n\n

Example 3:

\n\n
\nInput: s = "aab", t = "bbb", k = 27\nOutput: true\nExplanation: In the 1st move, we shift the first 'a' 1 time to get 'b'. In the 27th move, we shift the second 'a' 27 times to get 'b'.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length, t.length <= 10^5
  • \n\t
  • 0 <= k <= 10^9
  • \n\t
  • s, t contain only lowercase English letters.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e24\u4e2a\u5b57\u7b26\u4e32 s \u548c t \uff0c\u4f60\u7684\u76ee\u6807\u662f\u5728 k \u6b21\u64cd\u4f5c\u4ee5\u5185\u628a\u5b57\u7b26\u4e32 s \u8f6c\u53d8\u6210 t \u3002

\n\n

\u5728\u7b2c i \u6b21\u64cd\u4f5c\u65f6\uff081 <= i <= k\uff09\uff0c\u4f60\u53ef\u4ee5\u9009\u62e9\u8fdb\u884c\u5982\u4e0b\u64cd\u4f5c\uff1a

\n\n
    \n\t
  • \u9009\u62e9\u5b57\u7b26\u4e32 s \u4e2d\u6ee1\u8db3 1 <= j <= s.length \u4e14\u4e4b\u524d\u672a\u88ab\u9009\u8fc7\u7684\u4efb\u610f\u4e0b\u6807 j \uff08\u4e0b\u6807\u4ece 1 \u5f00\u59cb\uff09\uff0c\u5e76\u5c06\u6b64\u4f4d\u7f6e\u7684\u5b57\u7b26\u5207\u6362 i \u6b21\u3002
  • \n\t
  • \u4e0d\u8fdb\u884c\u4efb\u4f55\u64cd\u4f5c\u3002
  • \n
\n\n

\u5207\u6362 1 \u6b21\u5b57\u7b26\u7684\u610f\u601d\u662f\u7528\u5b57\u6bcd\u8868\u4e2d\u8be5\u5b57\u6bcd\u7684\u4e0b\u4e00\u4e2a\u5b57\u6bcd\u66ff\u6362\u5b83\uff08\u5b57\u6bcd\u8868\u73af\u72b6\u63a5\u8d77\u6765\uff0c\u6240\u4ee5 'z' \u5207\u6362\u540e\u4f1a\u53d8\u6210 'a'\uff09\u3002

\n\n

\u8bf7\u8bb0\u4f4f\u4efb\u610f\u4e00\u4e2a\u4e0b\u6807 j \u6700\u591a\u53ea\u80fd\u88ab\u64cd\u4f5c 1 \u6b21\u3002

\n\n

\u5982\u679c\u5728\u4e0d\u8d85\u8fc7 k \u6b21\u64cd\u4f5c\u5185\u53ef\u4ee5\u628a\u5b57\u7b26\u4e32 s \u8f6c\u53d8\u6210 t \uff0c\u90a3\u4e48\u8bf7\u4f60\u8fd4\u56de true \uff0c\u5426\u5219\u8bf7\u4f60\u8fd4\u56de false \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1as = "input", t = "ouput", k = 9\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u7b2c 6 \u6b21\u64cd\u4f5c\u65f6\uff0c\u6211\u4eec\u5c06 'i' \u5207\u6362 6 \u6b21\u5f97\u5230 'o' \u3002\u7b2c 7 \u6b21\u64cd\u4f5c\u65f6\uff0c\u6211\u4eec\u5c06 'n' \u5207\u6362 7 \u6b21\u5f97\u5230 'u' \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1as = "abc", t = "bcd", k = 10\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u6211\u4eec\u9700\u8981\u5c06\u6bcf\u4e2a\u5b57\u7b26\u5207\u6362 1 \u6b21\u624d\u80fd\u5f97\u5230 t \u3002\u6211\u4eec\u53ef\u4ee5\u5728\u7b2c 1 \u6b21\u64cd\u4f5c\u65f6\u5c06 'a' \u5207\u6362\u6210 'b' \uff0c\u4f46\u53e6\u5916 2 \u4e2a\u5b57\u6bcd\u5728\u5269\u4f59\u64cd\u4f5c\u4e2d\u65e0\u6cd5\u518d\u8f6c\u53d8\u4e3a t \u4e2d\u5bf9\u5e94\u5b57\u6bcd\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1as = "aab", t = "bbb", k = 27\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u7b2c 1 \u6b21\u64cd\u4f5c\u65f6\uff0c\u6211\u4eec\u5c06\u7b2c\u4e00\u4e2a 'a' \u5207\u6362 1 \u6b21\u5f97\u5230 'b' \u3002\u5728\u7b2c 27 \u6b21\u64cd\u4f5c\u65f6\uff0c\u6211\u4eec\u5c06\u7b2c\u4e8c\u4e2a\u5b57\u6bcd 'a' \u5207\u6362 27 \u6b21\u5f97\u5230 'b' \u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length, t.length <= 10^5
  • \n\t
  • 0 <= k <= 10^9
  • \n\t
  • s \u548c t \u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
  • \n
\n", "tags_en": ["Greedy", "String"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canConvertString(string s, string t, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canConvertString(String s, String t, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canConvertString(self, s, t, k):\n \"\"\"\n :type s: str\n :type t: str\n :type k: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canConvertString(self, s: str, t: str, k: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canConvertString(char * s, char * t, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanConvertString(string s, string t, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string} t\n * @param {number} k\n * @return {boolean}\n */\nvar canConvertString = function(s, t, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String} t\n# @param {Integer} k\n# @return {Boolean}\ndef can_convert_string(s, t, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canConvertString(_ s: String, _ t: String, _ k: Int) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canConvertString(s string, t string, k int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canConvertString(s: String, t: String, k: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canConvertString(s: String, t: String, k: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_convert_string(s: String, t: String, k: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String $t\n * @param Integer $k\n * @return Boolean\n */\n function canConvertString($s, $t, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canConvertString(s: string, t: string, k: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-convert-string s t k)\n (-> string? string? exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1540](https://leetcode-cn.com/problems/can-convert-string-in-k-moves)", "[K \u6b21\u64cd\u4f5c\u8f6c\u53d8\u5b57\u7b26\u4e32](/solution/1500-1599/1540.Can%20Convert%20String%20in%20K%20Moves/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1540](https://leetcode.com/problems/can-convert-string-in-k-moves)", "[Can Convert String in K Moves](/solution/1500-1599/1540.Can%20Convert%20String%20in%20K%20Moves/README_EN.md)", "`Greedy`,`String`", "Medium", ""]}, {"question_id": "1646", "frontend_question_id": "1539", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/kth-missing-positive-number", "url_en": "https://leetcode.com/problems/kth-missing-positive-number", "relative_path_cn": "/solution/1500-1599/1539.Kth%20Missing%20Positive%20Number/README.md", "relative_path_en": "/solution/1500-1599/1539.Kth%20Missing%20Positive%20Number/README_EN.md", "title_cn": "\u7b2c k \u4e2a\u7f3a\u5931\u7684\u6b63\u6574\u6570", "title_en": "Kth Missing Positive Number", "question_title_slug": "kth-missing-positive-number", "content_en": "

Given an array arr of positive integers sorted in a strictly increasing order, and an integer k.

\n\n

Find the kth positive integer that is missing from this array.

\n\n

 

\n

Example 1:

\n\n
\nInput: arr = [2,3,4,7,11], k = 5\nOutput: 9\nExplanation: The missing positive integers are [1,5,6,8,9,10,12,13,...]. The 5th missing positive integer is 9.\n
\n\n

Example 2:

\n\n
\nInput: arr = [1,2,3,4], k = 2\nOutput: 6\nExplanation: The missing positive integers are [5,6,7,...]. The 2nd missing positive integer is 6.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= arr.length <= 1000
  • \n\t
  • 1 <= arr[i] <= 1000
  • \n\t
  • 1 <= k <= 1000
  • \n\t
  • arr[i] < arr[j] for 1 <= i < j <= arr.length
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a \u4e25\u683c\u5347\u5e8f\u6392\u5217 \u7684\u6b63\u6574\u6570\u6570\u7ec4 arr \u548c\u4e00\u4e2a\u6574\u6570 k \u3002

\n\n

\u8bf7\u4f60\u627e\u5230\u8fd9\u4e2a\u6570\u7ec4\u91cc\u7b2c k \u4e2a\u7f3a\u5931\u7684\u6b63\u6574\u6570\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aarr = [2,3,4,7,11], k = 5\n\u8f93\u51fa\uff1a9\n\u89e3\u91ca\uff1a\u7f3a\u5931\u7684\u6b63\u6574\u6570\u5305\u62ec [1,5,6,8,9,10,12,13,...] \u3002\u7b2c 5 \u4e2a\u7f3a\u5931\u7684\u6b63\u6574\u6570\u4e3a 9 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aarr = [1,2,3,4], k = 2\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u7f3a\u5931\u7684\u6b63\u6574\u6570\u5305\u62ec [5,6,7,...] \u3002\u7b2c 2 \u4e2a\u7f3a\u5931\u7684\u6b63\u6574\u6570\u4e3a 6 \u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= arr.length <= 1000
  • \n\t
  • 1 <= arr[i] <= 1000
  • \n\t
  • 1 <= k <= 1000
  • \n\t
  • \u5bf9\u4e8e\u6240\u6709 1 <= i < j <= arr.length \u7684 i \u548c j \u6ee1\u8db3 arr[i] < arr[j] 
  • \n
\n", "tags_en": ["Array", "Hash Table"], "tags_cn": ["\u6570\u7ec4", "\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findKthPositive(vector& arr, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findKthPositive(int[] arr, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findKthPositive(self, arr, k):\n \"\"\"\n :type arr: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findKthPositive(self, arr: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findKthPositive(int* arr, int arrSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindKthPositive(int[] arr, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @param {number} k\n * @return {number}\n */\nvar findKthPositive = function(arr, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @param {Integer} k\n# @return {Integer}\ndef find_kth_positive(arr, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findKthPositive(_ arr: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findKthPositive(arr []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findKthPositive(arr: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findKthPositive(arr: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_kth_positive(arr: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @param Integer $k\n * @return Integer\n */\n function findKthPositive($arr, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findKthPositive(arr: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-kth-positive arr k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1539](https://leetcode-cn.com/problems/kth-missing-positive-number)", "[\u7b2c k \u4e2a\u7f3a\u5931\u7684\u6b63\u6574\u6570](/solution/1500-1599/1539.Kth%20Missing%20Positive%20Number/README.md)", "`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[1539](https://leetcode.com/problems/kth-missing-positive-number)", "[Kth Missing Positive Number](/solution/1500-1599/1539.Kth%20Missing%20Positive%20Number/README_EN.md)", "`Array`,`Hash Table`", "Easy", ""]}, {"question_id": "1645", "frontend_question_id": "1521", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-a-value-of-a-mysterious-function-closest-to-target", "url_en": "https://leetcode.com/problems/find-a-value-of-a-mysterious-function-closest-to-target", "relative_path_cn": "/solution/1500-1599/1521.Find%20a%20Value%20of%20a%20Mysterious%20Function%20Closest%20to%20Target/README.md", "relative_path_en": "/solution/1500-1599/1521.Find%20a%20Value%20of%20a%20Mysterious%20Function%20Closest%20to%20Target/README_EN.md", "title_cn": "\u627e\u5230\u6700\u63a5\u8fd1\u76ee\u6807\u503c\u7684\u51fd\u6570\u503c", "title_en": "Find a Value of a Mysterious Function Closest to Target", "question_title_slug": "find-a-value-of-a-mysterious-function-closest-to-target", "content_en": "

\"\"

\n\n

Winston was given the above mysterious function func. He has an integer array arr and an integer target and he wants to find the values l and r that make the value |func(arr, l, r) - target| minimum possible.

\n\n

Return the minimum possible value of |func(arr, l, r) - target|.

\n\n

Notice that func should be called with the values l and r where 0 <= l, r < arr.length.

\n\n

 

\n

Example 1:

\n\n
\nInput: arr = [9,12,3,7,15], target = 5\nOutput: 2\nExplanation: Calling func with all the pairs of [l,r] = [[0,0],[1,1],[2,2],[3,3],[4,4],[0,1],[1,2],[2,3],[3,4],[0,2],[1,3],[2,4],[0,3],[1,4],[0,4]], Winston got the following results [9,12,3,7,15,8,0,3,7,0,0,3,0,0,0]. The value closest to 5 is 7 and 3, thus the minimum difference is 2.\n
\n\n

Example 2:

\n\n
\nInput: arr = [1000000,1000000,1000000], target = 1\nOutput: 999999\nExplanation: Winston called the func with all possible values of [l,r] and he always got 1000000, thus the min difference is 999999.\n
\n\n

Example 3:

\n\n
\nInput: arr = [1,2,4,8,16], target = 0\nOutput: 0\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= arr.length <= 105
  • \n\t
  • 1 <= arr[i] <= 106
  • \n\t
  • 0 <= target <= 107
  • \n
\n", "content_cn": "

\"\"

\n\n

Winston \u6784\u9020\u4e86\u4e00\u4e2a\u5982\u4e0a\u6240\u793a\u7684\u51fd\u6570 func \u3002\u4ed6\u6709\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr \u548c\u4e00\u4e2a\u6574\u6570 target \uff0c\u4ed6\u60f3\u627e\u5230\u8ba9 |func(arr, l, r) - target| \u6700\u5c0f\u7684 l \u548c r \u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de |func(arr, l, r) - target| \u7684\u6700\u5c0f\u503c\u3002

\n\n

\u8bf7\u6ce8\u610f\uff0c func \u7684\u8f93\u5165\u53c2\u6570 l \u548c r \u9700\u8981\u6ee1\u8db3 0 <= l, r < arr.length \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aarr = [9,12,3,7,15], target = 5\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6240\u6709\u53ef\u80fd\u7684 [l,r] \u6570\u5bf9\u5305\u62ec [[0,0],[1,1],[2,2],[3,3],[4,4],[0,1],[1,2],[2,3],[3,4],[0,2],[1,3],[2,4],[0,3],[1,4],[0,4]]\uff0c Winston \u5f97\u5230\u7684\u76f8\u5e94\u7ed3\u679c\u4e3a [9,12,3,7,15,8,0,3,7,0,0,3,0,0,0] \u3002\u6700\u63a5\u8fd1 5 \u7684\u503c\u662f 7 \u548c 3\uff0c\u6240\u4ee5\u6700\u5c0f\u5dee\u503c\u4e3a 2 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aarr = [1000000,1000000,1000000], target = 1\n\u8f93\u51fa\uff1a999999\n\u89e3\u91ca\uff1aWinston \u8f93\u5165\u51fd\u6570\u7684\u6240\u6709\u53ef\u80fd [l,r] \u6570\u5bf9\u5f97\u5230\u7684\u51fd\u6570\u503c\u90fd\u4e3a 1000000 \uff0c\u6240\u4ee5\u6700\u5c0f\u5dee\u503c\u4e3a 999999 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aarr = [1,2,4,8,16], target = 0\n\u8f93\u51fa\uff1a0\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= arr.length <= 10^5
  • \n\t
  • 1 <= arr[i] <= 10^6
  • \n\t
  • 0 <= target <= 10^7
  • \n
\n", "tags_en": ["Bit Manipulation", "Segment Tree", "Binary Search"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u7ebf\u6bb5\u6811", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int closestToTarget(vector& arr, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int closestToTarget(int[] arr, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def closestToTarget(self, arr, target):\n \"\"\"\n :type arr: List[int]\n :type target: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def closestToTarget(self, arr: List[int], target: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint closestToTarget(int* arr, int arrSize, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ClosestToTarget(int[] arr, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @param {number} target\n * @return {number}\n */\nvar closestToTarget = function(arr, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @param {Integer} target\n# @return {Integer}\ndef closest_to_target(arr, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func closestToTarget(_ arr: [Int], _ target: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func closestToTarget(arr []int, target int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def closestToTarget(arr: Array[Int], target: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun closestToTarget(arr: IntArray, target: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn closest_to_target(arr: Vec, target: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @param Integer $target\n * @return Integer\n */\n function closestToTarget($arr, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function closestToTarget(arr: number[], target: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (closest-to-target arr target)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1521](https://leetcode-cn.com/problems/find-a-value-of-a-mysterious-function-closest-to-target)", "[\u627e\u5230\u6700\u63a5\u8fd1\u76ee\u6807\u503c\u7684\u51fd\u6570\u503c](/solution/1500-1599/1521.Find%20a%20Value%20of%20a%20Mysterious%20Function%20Closest%20to%20Target/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u7ebf\u6bb5\u6811`,`\u4e8c\u5206\u67e5\u627e`", "\u56f0\u96be", ""], "md_table_row_en": ["[1521](https://leetcode.com/problems/find-a-value-of-a-mysterious-function-closest-to-target)", "[Find a Value of a Mysterious Function Closest to Target](/solution/1500-1599/1521.Find%20a%20Value%20of%20a%20Mysterious%20Function%20Closest%20to%20Target/README_EN.md)", "`Bit Manipulation`,`Segment Tree`,`Binary Search`", "Hard", ""]}, {"question_id": "1644", "frontend_question_id": "1520", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-number-of-non-overlapping-substrings", "url_en": "https://leetcode.com/problems/maximum-number-of-non-overlapping-substrings", "relative_path_cn": "/solution/1500-1599/1520.Maximum%20Number%20of%20Non-Overlapping%20Substrings/README.md", "relative_path_en": "/solution/1500-1599/1520.Maximum%20Number%20of%20Non-Overlapping%20Substrings/README_EN.md", "title_cn": "\u6700\u591a\u7684\u4e0d\u91cd\u53e0\u5b50\u5b57\u7b26\u4e32", "title_en": "Maximum Number of Non-Overlapping Substrings", "question_title_slug": "maximum-number-of-non-overlapping-substrings", "content_en": "

Given a string s of lowercase letters, you need to find the maximum number of non-empty substrings of s that meet the following conditions:

\n\n
    \n\t
  1. The substrings do not overlap, that is for any two substrings s[i..j] and s[k..l], either j < k or i > l is true.
  2. \n\t
  3. A substring that contains a certain character c must also contain all occurrences of c.
  4. \n
\n\n

Find the maximum number of substrings that meet the above conditions. If there are multiple solutions with the same number of substrings, return the one with minimum total length. It can be shown that there exists a unique solution of minimum total length.

\n\n

Notice that you can return the substrings in any order.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "adefaddaccc"\nOutput: ["e","f","ccc"]\nExplanation: The following are all the possible substrings that meet the conditions:\n[\n  "adefaddaccc"\n  "adefadda",\n  "ef",\n  "e",\n  "f",\n  "ccc",\n]\nIf we choose the first string, we cannot choose anything else and we'd get only 1. If we choose "adefadda", we are left with "ccc" which is the only one that doesn't overlap, thus obtaining 2 substrings. Notice also, that it's not optimal to choose "ef" since it can be split into two. Therefore, the optimal way is to choose ["e","f","ccc"] which gives us 3 substrings. No other solution of the same number of substrings exist.\n
\n\n

Example 2:

\n\n
\nInput: s = "abbaccd"\nOutput: ["d","bb","cc"]\nExplanation: Notice that while the set of substrings ["d","abba","cc"] also has length 3, it's considered incorrect since it has larger total length.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 10^5
  • \n\t
  • s contains only lowercase English letters.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd\u7684\u5b57\u7b26\u4e32 s \uff0c\u4f60\u9700\u8981\u627e\u5230 s \u4e2d\u6700\u591a\u6570\u76ee\u7684\u975e\u7a7a\u5b50\u5b57\u7b26\u4e32\uff0c\u6ee1\u8db3\u5982\u4e0b\u6761\u4ef6\uff1a

\n\n
    \n\t
  1. \u8fd9\u4e9b\u5b57\u7b26\u4e32\u4e4b\u95f4\u4e92\u4e0d\u91cd\u53e0\uff0c\u4e5f\u5c31\u662f\u8bf4\u5bf9\u4e8e\u4efb\u610f\u4e24\u4e2a\u5b50\u5b57\u7b26\u4e32 s[i..j] \u548c s[k..l] \uff0c\u8981\u4e48 j < k \u8981\u4e48 i > l \u3002
  2. \n\t
  3. \u5982\u679c\u4e00\u4e2a\u5b50\u5b57\u7b26\u4e32\u5305\u542b\u5b57\u7b26 char \uff0c\u90a3\u4e48 s \u4e2d\u6240\u6709 char \u5b57\u7b26\u90fd\u5e94\u8be5\u5728\u8fd9\u4e2a\u5b50\u5b57\u7b26\u4e32\u4e2d\u3002
  4. \n
\n\n

\u8bf7\u4f60\u627e\u5230\u6ee1\u8db3\u4e0a\u8ff0\u6761\u4ef6\u7684\u6700\u591a\u5b50\u5b57\u7b26\u4e32\u6570\u76ee\u3002\u5982\u679c\u6709\u591a\u4e2a\u89e3\u6cd5\u6709\u76f8\u540c\u7684\u5b50\u5b57\u7b26\u4e32\u6570\u76ee\uff0c\u8bf7\u8fd4\u56de\u8fd9\u4e9b\u5b50\u5b57\u7b26\u4e32\u603b\u957f\u5ea6\u6700\u5c0f\u7684\u4e00\u4e2a\u89e3\u3002\u53ef\u4ee5\u8bc1\u660e\u6700\u5c0f\u603b\u957f\u5ea6\u89e3\u662f\u552f\u4e00\u7684\u3002

\n\n

\u8bf7\u6ce8\u610f\uff0c\u4f60\u53ef\u4ee5\u4ee5 \u4efb\u610f \u987a\u5e8f\u8fd4\u56de\u6700\u4f18\u89e3\u7684\u5b50\u5b57\u7b26\u4e32\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1as = "adefaddaccc"\n\u8f93\u51fa\uff1a["e","f","ccc"]\n\u89e3\u91ca\uff1a\u4e0b\u9762\u4e3a\u6240\u6709\u6ee1\u8db3\u7b2c\u4e8c\u4e2a\u6761\u4ef6\u7684\u5b50\u5b57\u7b26\u4e32\uff1a\n[\n  "adefaddaccc"\n  "adefadda",\n  "ef",\n  "e",\n  "f",\n  "ccc",\n]\n\u5982\u679c\u6211\u4eec\u9009\u62e9\u7b2c\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u90a3\u4e48\u6211\u4eec\u65e0\u6cd5\u518d\u9009\u62e9\u5176\u4ed6\u4efb\u4f55\u5b57\u7b26\u4e32\uff0c\u6240\u4ee5\u7b54\u6848\u4e3a 1 \u3002\u5982\u679c\u6211\u4eec\u9009\u62e9 "adefadda" \uff0c\u5269\u4e0b\u5b50\u5b57\u7b26\u4e32\u4e2d\u6211\u4eec\u53ea\u53ef\u4ee5\u9009\u62e9 "ccc" \uff0c\u5b83\u662f\u552f\u4e00\u4e0d\u91cd\u53e0\u7684\u5b50\u5b57\u7b26\u4e32\uff0c\u6240\u4ee5\u7b54\u6848\u4e3a 2 \u3002\u540c\u65f6\u6211\u4eec\u53ef\u4ee5\u53d1\u73b0\uff0c\u9009\u62e9 "ef" \u4e0d\u662f\u6700\u4f18\u7684\uff0c\u56e0\u4e3a\u5b83\u53ef\u4ee5\u88ab\u62c6\u5206\u6210 2 \u4e2a\u5b50\u5b57\u7b26\u4e32\u3002\u6240\u4ee5\u6700\u4f18\u89e3\u662f\u9009\u62e9 ["e","f","ccc"] \uff0c\u7b54\u6848\u4e3a 3 \u3002\u4e0d\u5b58\u5728\u522b\u7684\u76f8\u540c\u6570\u76ee\u5b50\u5b57\u7b26\u4e32\u89e3\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1as = "abbaccd"\n\u8f93\u51fa\uff1a["d","bb","cc"]\n\u89e3\u91ca\uff1a\u6ce8\u610f\u5230\u89e3 ["d","abba","cc"] \u7b54\u6848\u4e5f\u4e3a 3 \uff0c\u4f46\u5b83\u4e0d\u662f\u6700\u4f18\u89e3\uff0c\u56e0\u4e3a\u5b83\u7684\u603b\u957f\u5ea6\u66f4\u957f\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length <= 10^5
  • \n\t
  • s \u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
  • \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector maxNumOfSubstrings(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List maxNumOfSubstrings(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxNumOfSubstrings(self, s):\n \"\"\"\n :type s: str\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxNumOfSubstrings(self, s: str) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** maxNumOfSubstrings(char * s, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList MaxNumOfSubstrings(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string[]}\n */\nvar maxNumOfSubstrings = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String[]}\ndef max_num_of_substrings(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxNumOfSubstrings(_ s: String) -> [String] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxNumOfSubstrings(s string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxNumOfSubstrings(s: String): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxNumOfSubstrings(s: String): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_num_of_substrings(s: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String[]\n */\n function maxNumOfSubstrings($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxNumOfSubstrings(s: string): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-num-of-substrings s)\n (-> string? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1520](https://leetcode-cn.com/problems/maximum-number-of-non-overlapping-substrings)", "[\u6700\u591a\u7684\u4e0d\u91cd\u53e0\u5b50\u5b57\u7b26\u4e32](/solution/1500-1599/1520.Maximum%20Number%20of%20Non-Overlapping%20Substrings/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[1520](https://leetcode.com/problems/maximum-number-of-non-overlapping-substrings)", "[Maximum Number of Non-Overlapping Substrings](/solution/1500-1599/1520.Maximum%20Number%20of%20Non-Overlapping%20Substrings/README_EN.md)", "`Greedy`", "Hard", ""]}, {"question_id": "1643", "frontend_question_id": "1519", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-nodes-in-the-sub-tree-with-the-same-label", "url_en": "https://leetcode.com/problems/number-of-nodes-in-the-sub-tree-with-the-same-label", "relative_path_cn": "/solution/1500-1599/1519.Number%20of%20Nodes%20in%20the%20Sub-Tree%20With%20the%20Same%20Label/README.md", "relative_path_en": "/solution/1500-1599/1519.Number%20of%20Nodes%20in%20the%20Sub-Tree%20With%20the%20Same%20Label/README_EN.md", "title_cn": "\u5b50\u6811\u4e2d\u6807\u7b7e\u76f8\u540c\u7684\u8282\u70b9\u6570", "title_en": "Number of Nodes in the Sub-Tree With the Same Label", "question_title_slug": "number-of-nodes-in-the-sub-tree-with-the-same-label", "content_en": "

Given a tree (i.e. a connected, undirected graph that has no cycles) consisting of n nodes numbered from 0 to n - 1 and exactly n - 1 edges. The root of the tree is the node 0, and each node of the tree has a label which is a lower-case character given in the string labels (i.e. The node with the number i has the label labels[i]).

\r\n\r\n

The edges array is given on the form edges[i] = [ai, bi], which means there is an edge between nodes ai and bi in the tree.

\r\n\r\n

Return an array of size n where ans[i] is the number of nodes in the subtree of the ith node which have the same label as node i.

\r\n\r\n

A subtree of a tree T is the tree consisting of a node in T and all of its descendant nodes.

\r\n\r\n

 

\r\n

Example 1:

\r\n\"\"\r\n
\r\nInput: n = 7, edges = [[0,1],[0,2],[1,4],[1,5],[2,3],[2,6]], labels = "abaedcd"\r\nOutput: [2,1,1,1,1,1,1]\r\nExplanation: Node 0 has label 'a' and its sub-tree has node 2 with label 'a' as well, thus the answer is 2. Notice that any node is part of its sub-tree.\r\nNode 1 has a label 'b'. The sub-tree of node 1 contains nodes 1,4 and 5, as nodes 4 and 5 have different labels than node 1, the answer is just 1 (the node itself).\r\n
\r\n\r\n

Example 2:

\r\n\"\"\r\n
\r\nInput: n = 4, edges = [[0,1],[1,2],[0,3]], labels = "bbbb"\r\nOutput: [4,2,1,1]\r\nExplanation: The sub-tree of node 2 contains only node 2, so the answer is 1.\r\nThe sub-tree of node 3 contains only node 3, so the answer is 1.\r\nThe sub-tree of node 1 contains nodes 1 and 2, both have label 'b', thus the answer is 2.\r\nThe sub-tree of node 0 contains nodes 0, 1, 2 and 3, all with label 'b', thus the answer is 4.\r\n
\r\n\r\n

Example 3:

\r\n\"\"\r\n
\r\nInput: n = 5, edges = [[0,1],[0,2],[1,3],[0,4]], labels = "aabab"\r\nOutput: [3,2,1,1,1]\r\n
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: n = 6, edges = [[0,1],[0,2],[1,3],[3,4],[4,5]], labels = "cbabaa"\r\nOutput: [1,2,1,1,2,1]\r\n
\r\n\r\n

Example 5:

\r\n\r\n
\r\nInput: n = 7, edges = [[0,1],[1,2],[2,3],[3,4],[4,5],[5,6]], labels = "aaabaaa"\r\nOutput: [6,5,4,1,3,2,1]\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= n <= 10^5
  • \r\n\t
  • edges.length == n - 1
  • \r\n\t
  • edges[i].length == 2
  • \r\n\t
  • 0 <= ai, bi < n
  • \r\n\t
  • ai != bi
  • \r\n\t
  • labels.length == n
  • \r\n\t
  • labels is consisting of only of lower-case English letters.
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u68f5\u6811\uff08\u5373\uff0c\u4e00\u4e2a\u8fde\u901a\u7684\u65e0\u73af\u65e0\u5411\u56fe\uff09\uff0c\u8fd9\u68f5\u6811\u7531\u7f16\u53f7\u4ece 0  \u5230 n - 1 \u7684 n \u4e2a\u8282\u70b9\u7ec4\u6210\uff0c\u4e14\u6070\u597d\u6709 n - 1 \u6761 edges \u3002\u6811\u7684\u6839\u8282\u70b9\u4e3a\u8282\u70b9 0 \uff0c\u6811\u4e0a\u7684\u6bcf\u4e00\u4e2a\u8282\u70b9\u90fd\u6709\u4e00\u4e2a\u6807\u7b7e\uff0c\u4e5f\u5c31\u662f\u5b57\u7b26\u4e32 labels \u4e2d\u7684\u4e00\u4e2a\u5c0f\u5199\u5b57\u7b26\uff08\u7f16\u53f7\u4e3a i \u7684 \u8282\u70b9\u7684\u6807\u7b7e\u5c31\u662f labels[i] \uff09

\n\n

\u8fb9\u6570\u7ec4 edges \u4ee5 edges[i] = [ai, bi] \u7684\u5f62\u5f0f\u7ed9\u51fa\uff0c\u8be5\u683c\u5f0f\u8868\u793a\u8282\u70b9 ai \u548c bi \u4e4b\u95f4\u5b58\u5728\u4e00\u6761\u8fb9\u3002

\n\n

\u8fd4\u56de\u4e00\u4e2a\u5927\u5c0f\u4e3a n \u7684\u6570\u7ec4\uff0c\u5176\u4e2d ans[i] \u8868\u793a\u7b2c i \u4e2a\u8282\u70b9\u7684\u5b50\u6811\u4e2d\u4e0e\u8282\u70b9 i \u6807\u7b7e\u76f8\u540c\u7684\u8282\u70b9\u6570\u3002

\n\n

\u6811 T \u4e2d\u7684\u5b50\u6811\u662f\u7531 T \u4e2d\u7684\u67d0\u4e2a\u8282\u70b9\u53ca\u5176\u6240\u6709\u540e\u4ee3\u8282\u70b9\u7ec4\u6210\u7684\u6811\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1an = 7, edges = [[0,1],[0,2],[1,4],[1,5],[2,3],[2,6]], labels = "abaedcd"\n\u8f93\u51fa\uff1a[2,1,1,1,1,1,1]\n\u89e3\u91ca\uff1a\u8282\u70b9 0 \u7684\u6807\u7b7e\u4e3a 'a' \uff0c\u4ee5 'a' \u4e3a\u6839\u8282\u70b9\u7684\u5b50\u6811\u4e2d\uff0c\u8282\u70b9 2 \u7684\u6807\u7b7e\u4e5f\u662f 'a' \uff0c\u56e0\u6b64\u7b54\u6848\u4e3a 2 \u3002\u6ce8\u610f\u6811\u4e2d\u7684\u6bcf\u4e2a\u8282\u70b9\u90fd\u662f\u8fd9\u68f5\u5b50\u6811\u7684\u4e00\u90e8\u5206\u3002\n\u8282\u70b9 1 \u7684\u6807\u7b7e\u4e3a 'b' \uff0c\u8282\u70b9 1 \u7684\u5b50\u6811\u5305\u542b\u8282\u70b9 1\u30014 \u548c 5\uff0c\u4f46\u662f\u8282\u70b9 4\u30015 \u7684\u6807\u7b7e\u4e0e\u8282\u70b9 1 \u4e0d\u540c\uff0c\u6545\u800c\u7b54\u6848\u4e3a 1\uff08\u5373\uff0c\u8be5\u8282\u70b9\u672c\u8eab\uff09\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1an = 4, edges = [[0,1],[1,2],[0,3]], labels = "bbbb"\n\u8f93\u51fa\uff1a[4,2,1,1]\n\u89e3\u91ca\uff1a\u8282\u70b9 2 \u7684\u5b50\u6811\u4e2d\u53ea\u6709\u8282\u70b9 2 \uff0c\u6240\u4ee5\u7b54\u6848\u4e3a 1 \u3002\n\u8282\u70b9 3 \u7684\u5b50\u6811\u4e2d\u53ea\u6709\u8282\u70b9 3 \uff0c\u6240\u4ee5\u7b54\u6848\u4e3a 1 \u3002\n\u8282\u70b9 1 \u7684\u5b50\u6811\u4e2d\u5305\u542b\u8282\u70b9 1 \u548c 2 \uff0c\u6807\u7b7e\u90fd\u662f 'b' \uff0c\u56e0\u6b64\u7b54\u6848\u4e3a 2 \u3002\n\u8282\u70b9 0 \u7684\u5b50\u6811\u4e2d\u5305\u542b\u8282\u70b9 0\u30011\u30012 \u548c 3\uff0c\u6807\u7b7e\u90fd\u662f 'b'\uff0c\u56e0\u6b64\u7b54\u6848\u4e3a 4 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1an = 5, edges = [[0,1],[0,2],[1,3],[0,4]], labels = "aabab"\n\u8f93\u51fa\uff1a[3,2,1,1,1]\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1an = 6, edges = [[0,1],[0,2],[1,3],[3,4],[4,5]], labels = "cbabaa"\n\u8f93\u51fa\uff1a[1,2,1,1,2,1]\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1an = 7, edges = [[0,1],[1,2],[2,3],[3,4],[4,5],[5,6]], labels = "aaabaaa"\n\u8f93\u51fa\uff1a[6,5,4,1,3,2,1]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 10^5
  • \n\t
  • edges.length == n - 1
  • \n\t
  • edges[i].length == 2
  • \n\t
  • 0 <= ai, bi < n
  • \n\t
  • ai != bi
  • \n\t
  • labels.length == n
  • \n\t
  • labels \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
  • \n
\n", "tags_en": ["Depth-first Search", "Breadth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector countSubTrees(int n, vector>& edges, string labels) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] countSubTrees(int n, int[][] edges, String labels) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countSubTrees(self, n, edges, labels):\n \"\"\"\n :type n: int\n :type edges: List[List[int]]\n :type labels: str\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countSubTrees(self, n: int, edges: List[List[int]], labels: str) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* countSubTrees(int n, int** edges, int edgesSize, int* edgesColSize, char * labels, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] CountSubTrees(int n, int[][] edges, string labels) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} edges\n * @param {string} labels\n * @return {number[]}\n */\nvar countSubTrees = function(n, edges, labels) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} edges\n# @param {String} labels\n# @return {Integer[]}\ndef count_sub_trees(n, edges, labels)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countSubTrees(_ n: Int, _ edges: [[Int]], _ labels: String) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countSubTrees(n int, edges [][]int, labels string) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countSubTrees(n: Int, edges: Array[Array[Int]], labels: String): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countSubTrees(n: Int, edges: Array, labels: String): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_sub_trees(n: i32, edges: Vec>, labels: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $edges\n * @param String $labels\n * @return Integer[]\n */\n function countSubTrees($n, $edges, $labels) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countSubTrees(n: number, edges: number[][], labels: string): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-sub-trees n edges labels)\n (-> exact-integer? (listof (listof exact-integer?)) string? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1519](https://leetcode-cn.com/problems/number-of-nodes-in-the-sub-tree-with-the-same-label)", "[\u5b50\u6811\u4e2d\u6807\u7b7e\u76f8\u540c\u7684\u8282\u70b9\u6570](/solution/1500-1599/1519.Number%20of%20Nodes%20in%20the%20Sub-Tree%20With%20the%20Same%20Label/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1519](https://leetcode.com/problems/number-of-nodes-in-the-sub-tree-with-the-same-label)", "[Number of Nodes in the Sub-Tree With the Same Label](/solution/1500-1599/1519.Number%20of%20Nodes%20in%20the%20Sub-Tree%20With%20the%20Same%20Label/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`", "Medium", ""]}, {"question_id": "1642", "frontend_question_id": "1518", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/water-bottles", "url_en": "https://leetcode.com/problems/water-bottles", "relative_path_cn": "/solution/1500-1599/1518.Water%20Bottles/README.md", "relative_path_en": "/solution/1500-1599/1518.Water%20Bottles/README_EN.md", "title_cn": "\u6362\u9152\u95ee\u9898", "title_en": "Water Bottles", "question_title_slug": "water-bottles", "content_en": "

Given numBottles full water bottles, you can exchange numExchange empty water bottles for one full water bottle.

\r\n\r\n

The operation of drinking a full water bottle turns it into an empty bottle.

\r\n\r\n

Return the maximum number of water bottles you can drink.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n

\"\"

\r\n\r\n
\r\nInput: numBottles = 9, numExchange = 3\r\nOutput: 13\r\nExplanation: You can exchange 3 empty bottles to get 1 full water bottle.\r\nNumber of water bottles you can drink: 9 + 3 + 1 = 13.\r\n
\r\n\r\n

Example 2:

\r\n\r\n

\"\"

\r\n\r\n
\r\nInput: numBottles = 15, numExchange = 4\r\nOutput: 19\r\nExplanation: You can exchange 4 empty bottles to get 1 full water bottle. \r\nNumber of water bottles you can drink: 15 + 3 + 1 = 19.\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: numBottles = 5, numExchange = 5\r\nOutput: 6\r\n
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: numBottles = 2, numExchange = 3\r\nOutput: 2\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= numBottles <= 100
  • \r\n\t
  • 2 <= numExchange <= 100
  • \r\n
", "content_cn": "

\u5c0f\u533a\u4fbf\u5229\u5e97\u6b63\u5728\u4fc3\u9500\uff0c\u7528 numExchange \u4e2a\u7a7a\u9152\u74f6\u53ef\u4ee5\u5151\u6362\u4e00\u74f6\u65b0\u9152\u3002\u4f60\u8d2d\u5165\u4e86 numBottles \u74f6\u9152\u3002

\n\n

\u5982\u679c\u559d\u6389\u4e86\u9152\u74f6\u4e2d\u7684\u9152\uff0c\u90a3\u4e48\u9152\u74f6\u5c31\u4f1a\u53d8\u6210\u7a7a\u7684\u3002

\n\n

\u8bf7\u4f60\u8ba1\u7b97 \u6700\u591a \u80fd\u559d\u5230\u591a\u5c11\u74f6\u9152\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1anumBottles = 9, numExchange = 3\n\u8f93\u51fa\uff1a13\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u7528 3 \u4e2a\u7a7a\u9152\u74f6\u5151\u6362 1 \u74f6\u9152\u3002\n\u6240\u4ee5\u6700\u591a\u80fd\u559d\u5230 9 + 3 + 1 = 13 \u74f6\u9152\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1anumBottles = 15, numExchange = 4\n\u8f93\u51fa\uff1a19\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u7528 4 \u4e2a\u7a7a\u9152\u74f6\u5151\u6362 1 \u74f6\u9152\u3002\n\u6240\u4ee5\u6700\u591a\u80fd\u559d\u5230 15 + 3 + 1 = 19 \u74f6\u9152\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1anumBottles = 5, numExchange = 5\n\u8f93\u51fa\uff1a6\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1anumBottles = 2, numExchange = 3\n\u8f93\u51fa\uff1a2\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= numBottles <= 100
  • \n\t
  • 2 <= numExchange <= 100
  • \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numWaterBottles(int numBottles, int numExchange) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numWaterBottles(int numBottles, int numExchange) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numWaterBottles(self, numBottles, numExchange):\n \"\"\"\n :type numBottles: int\n :type numExchange: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numWaterBottles(self, numBottles: int, numExchange: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numWaterBottles(int numBottles, int numExchange){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumWaterBottles(int numBottles, int numExchange) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} numBottles\n * @param {number} numExchange\n * @return {number}\n */\nvar numWaterBottles = function(numBottles, numExchange) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} num_bottles\n# @param {Integer} num_exchange\n# @return {Integer}\ndef num_water_bottles(num_bottles, num_exchange)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numWaterBottles(_ numBottles: Int, _ numExchange: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numWaterBottles(numBottles int, numExchange int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numWaterBottles(numBottles: Int, numExchange: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numWaterBottles(numBottles: Int, numExchange: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_water_bottles(num_bottles: i32, num_exchange: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $numBottles\n * @param Integer $numExchange\n * @return Integer\n */\n function numWaterBottles($numBottles, $numExchange) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numWaterBottles(numBottles: number, numExchange: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-water-bottles numBottles numExchange)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1518](https://leetcode-cn.com/problems/water-bottles)", "[\u6362\u9152\u95ee\u9898](/solution/1500-1599/1518.Water%20Bottles/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u7b80\u5355", ""], "md_table_row_en": ["[1518](https://leetcode.com/problems/water-bottles)", "[Water Bottles](/solution/1500-1599/1518.Water%20Bottles/README_EN.md)", "`Greedy`", "Easy", ""]}, {"question_id": "1641", "frontend_question_id": "1501", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/countries-you-can-safely-invest-in", "url_en": "https://leetcode.com/problems/countries-you-can-safely-invest-in", "relative_path_cn": "/solution/1500-1599/1501.Countries%20You%20Can%20Safely%20Invest%20In/README.md", "relative_path_en": "/solution/1500-1599/1501.Countries%20You%20Can%20Safely%20Invest%20In/README_EN.md", "title_cn": "\u53ef\u4ee5\u653e\u5fc3\u6295\u8d44\u7684\u56fd\u5bb6", "title_en": "Countries You Can Safely Invest In", "question_title_slug": "countries-you-can-safely-invest-in", "content_en": "

Table Person:

\n\n
\n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| id             | int     |\n| name           | varchar |\n| phone_number   | varchar |\n+----------------+---------+\nid is the primary key for this table.\nEach row of this table contains the name of a person and their phone number.\nPhone number will be in the form 'xxx-yyyyyyy' where xxx is the country code (3 characters) and yyyyyyy is the phone number (7 characters) where x and y are digits. Both can contain leading zeros.\n
\n\n

 

\n\n

Table Country:

\n\n
\n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| name           | varchar |\n| country_code   | varchar |\n+----------------+---------+\ncountry_code is the primary key for this table.\nEach row of this table contains the country name and its code. country_code will be in the form 'xxx' where x is digits.\n
\n\n

 

\n\n

Table Calls:

\n\n
\n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| caller_id   | int  |\n| callee_id   | int  |\n| duration    | int  |\n+-------------+------+\nThere is no primary key for this table, it may contain duplicates.\nEach row of this table contains the caller id, callee id and the duration of the call in minutes. caller_id != callee_id\n
\n\n

 

\n\n

A telecommunications company wants to invest in new countries. The company intends to invest in the countries where the average call duration of the calls in this country is strictly greater than the global average call duration.

\n\n

Write an SQL query to find the countries where this company can invest.

\n\n

Return the result table in any order.

\n\n

The query result format is in the following example:

\n\n

 

\n\n
\nPerson table:\n+----+----------+--------------+\n| id | name     | phone_number |\n+----+----------+--------------+\n| 3  | Jonathan | 051-1234567  |\n| 12 | Elvis    | 051-7654321  |\n| 1  | Moncef   | 212-1234567  |\n| 2  | Maroua   | 212-6523651  |\n| 7  | Meir     | 972-1234567  |\n| 9  | Rachel   | 972-0011100  |\n+----+----------+--------------+\n\nCountry table:\n+----------+--------------+\n| name     | country_code |\n+----------+--------------+\n| Peru     | 051          |\n| Israel   | 972          |\n| Morocco  | 212          |\n| Germany  | 049          |\n| Ethiopia | 251          |\n+----------+--------------+\n\nCalls table:\n+-----------+-----------+----------+\n| caller_id | callee_id | duration |\n+-----------+-----------+----------+\n| 1         | 9         | 33       |\n| 2         | 9         | 4        |\n| 1         | 2         | 59       |\n| 3         | 12        | 102      |\n| 3         | 12        | 330      |\n| 12        | 3         | 5        |\n| 7         | 9         | 13       |\n| 7         | 1         | 3        |\n| 9         | 7         | 1        |\n| 1         | 7         | 7        |\n+-----------+-----------+----------+\n\nResult table:\n+----------+\n| country  |\n+----------+\n| Peru     |\n+----------+\nThe average call duration for Peru is (102 + 102 + 330 + 330 + 5 + 5) / 6 = 145.666667\nThe average call duration for Israel is (33 + 4 + 13 + 13 + 3 + 1 + 1 + 7) / 8 = 9.37500\nThe average call duration for Morocco is (33 + 4 + 59 + 59 + 3 + 7) / 6 = 27.5000 \nGlobal call duration average = (2 * (33 + 4 + 59 + 102 + 330 + 5 + 13 + 3 + 1 + 7)) / 20 = 55.70000\nSince Peru is the only country where average call duration is greater than the global average, it's the only recommended country.\n
\n", "content_cn": "

\u8868\u00a0Person:

\n\n
\n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| id             | int     |\n| name           | varchar |\n| phone_number   | varchar |\n+----------------+---------+\nid \u662f\u8be5\u8868\u4e3b\u952e.\n\u8be5\u8868\u6bcf\u4e00\u884c\u5305\u542b\u4e00\u4e2a\u4eba\u7684\u540d\u5b57\u548c\u7535\u8bdd\u53f7\u7801.\n\u7535\u8bdd\u53f7\u7801\u7684\u683c\u5f0f\u662f:'xxx-yyyyyyy', \u5176\u4e2dxxx\u662f\u56fd\u5bb6\u7801(3\u4e2a\u5b57\u7b26), yyyyyyy\u662f\u7535\u8bdd\u53f7\u7801(7\u4e2a\u5b57\u7b26), x\u548cy\u90fd\u8868\u793a\u6570\u5b57. \u540c\u65f6, \u56fd\u5bb6\u7801\u548c\u7535\u8bdd\u53f7\u7801\u90fd\u53ef\u4ee5\u5305\u542b\u524d\u5bfc0.\n
\n\n

\u8868\u00a0Country:

\n\n
\n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| name           | varchar |\n| country_code   | varchar |\n+----------------+---------+\ncountry_code\u662f\u8be5\u8868\u4e3b\u952e.\n\u8be5\u8868\u6bcf\u4e00\u884c\u5305\u542b\u56fd\u5bb6\u540d\u548c\u56fd\u5bb6\u7801. country_code\u7684\u683c\u5f0f\u662f'xxx', x\u662f\u6570\u5b57.\n
\n\n

\u00a0

\n\n

\u8868\u00a0Calls:

\n\n
\n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| caller_id   | int  |\n| callee_id   | int  |\n| duration    | int  |\n+-------------+------+\n\u8be5\u8868\u65e0\u4e3b\u952e, \u53ef\u80fd\u5305\u542b\u91cd\u590d\u884c.\n\u6bcf\u4e00\u884c\u5305\u542b\u547c\u53eb\u65b9id, \u88ab\u547c\u53eb\u65b9id\u548c\u4ee5\u5206\u949f\u4e3a\u5355\u4f4d\u7684\u901a\u8bdd\u65f6\u957f. caller_id != callee_id\n
\n\n

\u4e00\u5bb6\u7535\u4fe1\u516c\u53f8\u60f3\u8981\u6295\u8d44\u65b0\u7684\u56fd\u5bb6. \u8be5\u516c\u53f8\u60f3\u8981\u6295\u8d44\u7684\u56fd\u5bb6\u662f:\u00a0 \u8be5\u56fd\u7684\u5e73\u5747\u901a\u8bdd\u65f6\u957f\u8981\u4e25\u683c\u5730\u5927\u4e8e\u5168\u7403\u5e73\u5747\u901a\u8bdd\u65f6\u957f.

\n\n

\u5199\u4e00\u6bb5 SQL,\u00a0\u00a0\u627e\u5230\u6240\u6709\u8be5\u516c\u53f8\u53ef\u4ee5\u6295\u8d44\u7684\u56fd\u5bb6.

\n\n

\u8fd4\u56de\u7684\u7ed3\u679c\u8868\u6ca1\u6709\u987a\u5e8f\u8981\u6c42.

\n\n

\u67e5\u8be2\u7684\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a.

\n\n
\nPerson \u8868:\n+----+----------+--------------+\n| id | name     | phone_number |\n+----+----------+--------------+\n| 3  | Jonathan | 051-1234567  |\n| 12 | Elvis    | 051-7654321  |\n| 1  | Moncef   | 212-1234567  |\n| 2  | Maroua   | 212-6523651  |\n| 7  | Meir     | 972-1234567  |\n| 9  | Rachel   | 972-0011100  |\n+----+----------+--------------+\n\nCountry \u8868:\n+----------+--------------+\n| name     | country_code |\n+----------+--------------+\n| Peru     | 051          |\n| Israel   | 972          |\n| Morocco  | 212          |\n| Germany  | 049          |\n| Ethiopia | 251          |\n+----------+--------------+\n\nCalls \u8868:\n+-----------+-----------+----------+\n| caller_id | callee_id | duration |\n+-----------+-----------+----------+\n| 1         | 9         | 33       |\n| 2         | 9         | 4        |\n| 1         | 2         | 59       |\n| 3         | 12        | 102      |\n| 3         | 12        | 330      |\n| 12        | 3         | 5        |\n| 7         | 9         | 13       |\n| 7         | 1         | 3        |\n| 9         | 7         | 1        |\n| 1         | 7         | 7        |\n+-----------+-----------+----------+\n\nResult \u8868:\n+----------+\n| country  |\n+----------+\n| Peru     |\n+----------+\n\u56fd\u5bb6Peru\u7684\u5e73\u5747\u901a\u8bdd\u65f6\u957f\u662f (102 + 102 + 330 + 330 + 5 + 5) / 6 = 145.666667\n\u56fd\u5bb6Israel\u7684\u5e73\u5747\u901a\u8bdd\u65f6\u957f\u662f (33 + 4 + 13 + 13 + 3 + 1 + 1 + 7) / 8 = 9.37500\n\u56fd\u5bb6Morocco\u7684\u5e73\u5747\u901a\u8bdd\u65f6\u957f\u662f (33 + 4 + 59 + 59 + 3 + 7) / 6 = 27.5000 \n\u5168\u7403\u5e73\u5747\u901a\u8bdd\u65f6\u957f = (2 * (33 + 4 + 59 + 102 + 330 + 5 + 13 + 3 + 1 + 7)) / 20 = 55.70000\n\u6240\u4ee5, Peru\u662f\u552f\u4e00\u7684\u5e73\u5747\u901a\u8bdd\u65f6\u957f\u5927\u4e8e\u5168\u7403\u5e73\u5747\u901a\u8bdd\u65f6\u957f\u7684\u56fd\u5bb6, \u4e5f\u662f\u552f\u4e00\u7684\u63a8\u8350\u6295\u8d44\u7684\u56fd\u5bb6.\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1501](https://leetcode-cn.com/problems/countries-you-can-safely-invest-in)", "[\u53ef\u4ee5\u653e\u5fc3\u6295\u8d44\u7684\u56fd\u5bb6](/solution/1500-1599/1501.Countries%20You%20Can%20Safely%20Invest%20In/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1501](https://leetcode.com/problems/countries-you-can-safely-invest-in)", "[Countries You Can Safely Invest In](/solution/1500-1599/1501.Countries%20You%20Can%20Safely%20Invest%20In/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1640", "frontend_question_id": "1500", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/design-a-file-sharing-system", "url_en": "https://leetcode.com/problems/design-a-file-sharing-system", "relative_path_cn": "/solution/1500-1599/1500.Design%20a%20File%20Sharing%20System/README.md", "relative_path_en": "/solution/1500-1599/1500.Design%20a%20File%20Sharing%20System/README_EN.md", "title_cn": "\u8bbe\u8ba1\u6587\u4ef6\u5206\u4eab\u7cfb\u7edf", "title_en": "Design a File Sharing System", "question_title_slug": "design-a-file-sharing-system", "content_en": "

We will use a file-sharing system to share a very large file which consists of m small chunks with IDs from 1 to m.

\n\n

When users join the system, the system should assign a unique ID to them. The unique ID should be used once for each user, but when a user leaves the system, the ID can be reused again.

\n\n

Users can request a certain chunk of the file, the system should return a list of IDs of all the users who own this chunk. If the user receive a non-empty list of IDs, they receive the requested chunk successfully.

\n\n


\nImplement the FileSharing class:

\n\n
    \n\t
  • FileSharing(int m) Initializes the object with a file of m chunks.
  • \n\t
  • int join(int[] ownedChunks): A new user joined the system owning some chunks of the file, the system should assign an id to the user which is the smallest positive integer not taken by any other user. Return the assigned id.
  • \n\t
  • void leave(int userID): The user with userID will leave the system, you cannot take file chunks from them anymore.
  • \n\t
  • int[] request(int userID, int chunkID): The user userID requested the file chunk with chunkID. Return a list of the IDs of all users that own this chunk sorted in ascending order.
  • \n
\n\n

 

\n\n

Follow-ups:

\n\n
    \n\t
  • What happens if the system identifies the user by their IP address instead of their unique ID and users disconnect and connect from the system with the same IP?
  • \n\t
  • If the users in the system join and leave the system frequently without requesting any chunks, will your solution still be efficient?
  • \n\t
  • If all each user join the system one time, request all files and then leave, will your solution still be efficient?
  • \n\t
  • If the system will be used to share n files where the ith file consists of m[i], what are the changes you have to do?
  • \n
\n\n

 

\n

Example:

\n\n
\nInput:\n["FileSharing","join","join","join","request","request","leave","request","leave","join"]\n[[4],[[1,2]],[[2,3]],[[4]],[1,3],[2,2],[1],[2,1],[2],[[]]]\nOutput:\n[null,1,2,3,[2],[1,2],null,[],null,1]\nExplanation:\nFileSharing fileSharing = new FileSharing(4); // We use the system to share a file of 4 chunks.\n\nfileSharing.join([1, 2]);    // A user who has chunks [1,2] joined the system, assign id = 1 to them and return 1.\n\nfileSharing.join([2, 3]);    // A user who has chunks [2,3] joined the system, assign id = 2 to them and return 2.\n\nfileSharing.join([4]);       // A user who has chunk [4] joined the system, assign id = 3 to them and return 3.\n\nfileSharing.request(1, 3);   // The user with id = 1 requested the third file chunk, as only the user with id = 2 has the file, return [2] . Notice that user 1 now has chunks [1,2,3].\n\nfileSharing.request(2, 2);   // The user with id = 2 requested the second file chunk, users with ids [1,2] have this chunk, thus we return [1,2].\n\nfileSharing.leave(1);        // The user with id = 1 left the system, all the file chunks with them are no longer available for other users.\n\nfileSharing.request(2, 1);   // The user with id = 2 requested the first file chunk, no one in the system has this chunk, we return empty list [].\n\nfileSharing.leave(2);        // The user with id = 2 left the system.\n\nfileSharing.join([]);        // A user who doesn't have any chunks joined the system, assign id = 1 to them and return 1. Notice that ids 1 and 2 are free and we can reuse them.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= m <= 10^5
  • \n\t
  • 0 <= ownedChunks.length <= min(100, m)
  • \n\t
  • 1 <= ownedChunks[i] <= m
  • \n\t
  • Values of ownedChunks are unique.
  • \n\t
  • 1 <= chunkID <= m
  • \n\t
  • userID is guaranteed to be a user in the system if you assign the IDs correctly
  • \n\t
  • At most 10^4 calls will be made to joinleave and request.
  • \n\t
  • Each call to leave will have a matching call for join.
  • \n
\n", "content_cn": "

\u6211\u4eec\u9700\u8981\u4f7f\u7528\u4e00\u5957\u6587\u4ef6\u5206\u4eab\u7cfb\u7edf\u6765\u5206\u4eab\u4e00\u4e2a\u975e\u5e38\u5927\u7684\u6587\u4ef6\uff0c\u8be5\u6587\u4ef6\u7531 m \u4e2a\u4ece 1 \u5230 m \u7f16\u53f7\u7684\u6587\u4ef6\u5757\u7ec4\u6210\u3002

\n\n

\u5f53\u7528\u6237\u52a0\u5165\u7cfb\u7edf\u65f6\uff0c\u7cfb\u7edf\u5e94\u4e3a\u5176\u6ce8\u518c\u4e00\u4e2a\u72ec\u6709\u7684 ID\u3002\u8fd9\u4e2a\u72ec\u6709\u7684 ID \u5e94\u5f53\u88ab\u76f8\u5e94\u7684\u7528\u6237\u4f7f\u7528\u4e00\u6b21\uff0c\u4f46\u662f\u5f53\u7528\u6237\u79bb\u5f00\u7cfb\u7edf\u65f6\uff0c\u5176 ID \u5e94\u53ef\u4ee5\u88ab\uff08\u540e\u7eed\u65b0\u6ce8\u518c\u7684\u7528\u6237\uff09\u518d\u6b21\u4f7f\u7528\u3002

\n\n

\u7528\u6237\u53ef\u4ee5\u8bf7\u6c42\u6587\u4ef6\u4e2d\u7684\u67d0\u4e2a\u6307\u5b9a\u7684\u6587\u4ef6\u5757\uff0c\u7cfb\u7edf\u5e94\u5f53\u8fd4\u56de\u62e5\u6709\u8fd9\u4e2a\u6587\u4ef6\u5757\u7684\u6240\u6709\u7528\u6237\u7684 ID\u3002\u5982\u679c\u7528\u6237\u6536\u5230 ID \u7684\u975e\u7a7a\u5217\u8868\uff0c\u5c31\u8868\u793a\u6210\u529f\u63a5\u6536\u5230\u8bf7\u6c42\u7684\u6587\u4ef6\u5757\u3002

\n\n


\n\u5b9e\u73b0 FileSharing \u7c7b\uff1a

\n\n
    \n\t
  • FileSharing(int m) \u521d\u59cb\u5316\u8be5\u5bf9\u8c61\uff0c\u6587\u4ef6\u6709 m \u4e2a\u6587\u4ef6\u5757\u3002
  • \n\t
  • int join(int[] ownedChunks)\uff1a\u4e00\u4e2a\u65b0\u7528\u6237\u52a0\u5165\u7cfb\u7edf\uff0c\u5e76\u62e5\u6709\u6587\u4ef6\u7684\u4e00\u4e9b\u6587\u4ef6\u5757\u3002\u7cfb\u7edf\u5e94\u5f53\u4e3a\u8be5\u7528\u6237\u6ce8\u518c\u4e00\u4e2a ID\uff0c\u8be5 ID \u5e94\u662f\u672a\u88ab\u5176\u4ed6\u7528\u6237\u5360\u7528\u7684\u6700\u5c0f\u6b63\u6574\u6570\u3002\u8fd4\u56de\u6ce8\u518c\u7684 ID\u3002
  • \n\t
  • void leave(int userID)\uff1aID \u4e3a userID \u7684\u7528\u6237\u5c06\u79bb\u5f00\u7cfb\u7edf\uff0c\u4f60\u4e0d\u80fd\u518d\u4ece\u8be5\u7528\u6237\u63d0\u53d6\u6587\u4ef6\u5757\u4e86\u3002
  • \n\t
  • int[] request(int userID, int chunkID)\uff1aID \u4e3a userID \u7684\u7528\u6237\u8bf7\u6c42\u7f16\u53f7\u4e3a chunkID \u7684\u6587\u4ef6\u5757\u3002\u8fd4\u56de\u62e5\u6709\u8fd9\u4e2a\u6587\u4ef6\u5757\u7684\u6240\u6709\u7528\u6237\u7684 ID \u6240\u6784\u6210\u7684\u5217\u8868\u6216\u6570\u7ec4\uff0c\u6309\u5347\u5e8f\u6392\u5217\u3002
  • \n
\n\n

 

\n\n

\u8fdb\u9636\uff1a

\n\n
    \n\t
  • \u5f53\u7cfb\u7edf\u4ee5\u7528\u6237\u7684 IP \u5730\u5740\u800c\u4e0d\u662f\u72ec\u6709 ID \u6765\u8bc6\u522b\u7528\u6237\uff0c\u4e14\u7528\u6237\u65ad\u5f00\u8fde\u63a5\u540e\u4ee5\u76f8\u540c IP \u91cd\u65b0\u8fde\u63a5\u7cfb\u7edf\u65f6\uff0c\u4f1a\u53d1\u751f\u4ec0\u4e48\uff1f
  • \n\t
  • \u5f53\u7528\u6237\u9891\u7e41\u52a0\u5165\u5e76\u9000\u51fa\u7cfb\u7edf\uff0c\u4e14\u8be5\u7528\u6237\u4e0d\u8bf7\u6c42\u4efb\u4f55\u6587\u4ef6\u5757\u65f6\uff0c\u4f60\u7684\u89e3\u51b3\u65b9\u6848\u4ecd\u7136\u4fdd\u6301\u9ad8\u6548\u5417\uff1f
  • \n\t
  • \u5f53\u6240\u6709\u7528\u6237\u540c\u65f6\u52a0\u5165\u7cfb\u7edf\uff0c\u8bf7\u6c42\u6240\u6709\u6587\u4ef6\u5e76\u79bb\u5f00\u65f6\uff0c\u4f60\u7684\u89e3\u51b3\u65b9\u6848\u4ecd\u7136\u4fdd\u6301\u9ad8\u6548\u5417\uff1f
  • \n\t
  • \u5982\u679c\u7cfb\u7edf\u7528\u4e8e\u5206\u4eab n \u4e2a\u6587\u4ef6\uff0c\u5176\u4e2d\u7b2c  i \u4e2a\u6587\u4ef6\u7531 m[i] \u7ec4\u6210\uff0c\u4f60\u9700\u8981\u5982\u4f55\u4fee\u6539\uff1f
  • \n
\n\n

 

\n\n

\u793a\u4f8b:

\n\n
\u8f93\u5165:\n["FileSharing","join","join","join","request","request","leave","request","leave","join"]\n[[4],[[1,2]],[[2,3]],[[4]],[1,3],[2,2],[1],[2,1],[2],[[]]]\n\u8f93\u51fa:\n[null,1,2,3,[2],[1,2],null,[],null,1]\n\u89e3\u91ca:\nFileSharing fileSharing = new FileSharing(4); // \u6211\u4eec\u7528\u8be5\u7cfb\u7edf\u5206\u4eab\u7531 4 \u4e2a\u6587\u4ef6\u5757\u7ec4\u6210\u7684\u6587\u4ef6\u3002\n\nfileSharing.join([1, 2]);    // \u4e00\u4e2a\u62e5\u6709\u6587\u4ef6\u5757 [1,2] \u7684\u7528\u6237\u52a0\u5165\u7cfb\u7edf\uff0c\u4e3a\u5176\u6ce8\u518c id = 1 \u5e76\u8fd4\u56de 1\u3002\n\nfileSharing.join([2, 3]);    // \u4e00\u4e2a\u62e5\u6709\u6587\u4ef6\u5757 [2,3] \u7684\u7528\u6237\u52a0\u5165\u7cfb\u7edf\uff0c\u4e3a\u5176\u6ce8\u518c id = 2 \u5e76\u8fd4\u56de 2\u3002\n\nfileSharing.join([4]);       // \u4e00\u4e2a\u62e5\u6709\u6587\u4ef6\u5757 [4] \u7684\u7528\u6237\u52a0\u5165\u7cfb\u7edf\uff0c\u4e3a\u5176\u6ce8\u518c id = 3 \u5e76\u8fd4\u56de 3\u3002\n\nfileSharing.request(1, 3);   // id = 1 \u7684\u7528\u6237\u8bf7\u6c42\u7b2c 3 \u4e2a\u6587\u4ef6\u5757\uff0c\u53ea\u6709 id = 2 \u7684\u7528\u6237\u62e5\u6709\u6587\u4ef6\u5757\uff0c\u8fd4\u56de [2] \u3002\u6ce8\u610f\uff0c\u73b0\u5728\u7528\u6237 1 \u73b0\u62e5\u6709\u6587\u4ef6\u5757 [1,2,3]\u3002\n\nfileSharing.request(2, 2);   // id = 2 \u7684\u7528\u6237\u8bf7\u6c42\u7b2c 2 \u4e2a\u6587\u4ef6\u5757\uff0cid \u4e3a [1,2] \u7684\u7528\u6237\u62e5\u6709\u8be5\u6587\u4ef6\u5757\uff0c\u6240\u4ee5\u6211\u4eec\u8fd4\u56de [1,2] \u3002\n\nfileSharing.leave(1);        // id = 1 \u7684\u7528\u6237\u79bb\u5f00\u7cfb\u7edf\uff0c\u5176\u6240\u62e5\u6709\u7684\u6240\u6709\u6587\u4ef6\u5757\u4e0d\u518d\u5bf9\u5176\u4ed6\u7528\u6237\u53ef\u7528\u3002\n\nfileSharing.request(2, 1);   // id = 2 \u7684\u7528\u6237\u8bf7\u6c42\u7b2c 1 \u4e2a\u6587\u4ef6\u5757\uff0c\u7cfb\u7edf\u4e2d\u6ca1\u6709\u7528\u6237\u62e5\u6709\u8be5\u6587\u4ef6\u5757\uff0c\u6240\u4ee5\u6211\u4eec\u8fd4\u56de\u7a7a\u5217\u8868 [] \u3002\n\nfileSharing.leave(2);        // id = 2 \u7684\u7528\u6237\u79bb\u5f00\u7cfb\u7edf\u3002\n\nfileSharing.join([]);        // \u4e00\u4e2a\u4e0d\u62e5\u6709\u4efb\u4f55\u6587\u4ef6\u5757\u7684\u7528\u6237\u52a0\u5165\u7cfb\u7edf\uff0c\u4e3a\u5176\u6ce8\u518c id = 1 \u5e76\u8fd4\u56de 1 \u3002\u6ce8\u610f\uff0cid 1 \u548c 2 \u7a7a\u95f2\uff0c\u53ef\u4ee5\u91cd\u65b0\u4f7f\u7528\u3002\n
\n\n

 

\n\n

\u63d0\u793a:

\n\n
    \n\t
  • 1 <= m <= 10^5
  • \n\t
  • 0 <= ownedChunks.length <= min(100, m)
  • \n\t
  • 1 <= ownedChunks[i] <= m
  • \n\t
  • ownedChunks \u7684\u503c\u662f\u4e92\u4e0d\u76f8\u540c\u7684\u3002
  • \n\t
  • 1 <= chunkID <= m
  • \n\t
  • \u5f53\u4f60\u6b63\u786e\u5730\u6ce8\u518c\u7528\u6237 ID \u65f6\uff0c\u9898\u76ee\u4fdd\u8bc1 userID \u662f\u7cfb\u7edf\u4e2d\u7684\u4e00\u4e2a\u5df2\u6ce8\u518c\u7528\u6237\u3002
  • \n\t
  • join\u3001 leave \u548c request \u6700\u591a\u88ab\u8c03\u7528 10^4 \u6b21\u3002
  • \n\t
  • \u6bcf\u6b21\u5bf9 leave \u7684\u8c03\u7528\u90fd\u6709\u5bf9\u5e94\u7684\u5bf9 join \u7684\u8c03\u7528\u3002
  • \n
\n", "tags_en": ["Design", "Array"], "tags_cn": ["\u8bbe\u8ba1", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class FileSharing {\npublic:\n FileSharing(int m) {\n\n }\n \n int join(vector ownedChunks) {\n\n }\n \n void leave(int userID) {\n\n }\n \n vector request(int userID, int chunkID) {\n\n }\n};\n\n/**\n * Your FileSharing object will be instantiated and called as such:\n * FileSharing* obj = new FileSharing(m);\n * int param_1 = obj->join(ownedChunks);\n * obj->leave(userID);\n * vector param_3 = obj->request(userID,chunkID);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class FileSharing {\n\n public FileSharing(int m) {\n\n }\n \n public int join(List ownedChunks) {\n\n }\n \n public void leave(int userID) {\n\n }\n \n public List request(int userID, int chunkID) {\n\n }\n}\n\n/**\n * Your FileSharing object will be instantiated and called as such:\n * FileSharing obj = new FileSharing(m);\n * int param_1 = obj.join(ownedChunks);\n * obj.leave(userID);\n * List param_3 = obj.request(userID,chunkID);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class FileSharing(object):\n\n def __init__(self, m):\n \"\"\"\n :type m: int\n \"\"\"\n\n\n def join(self, ownedChunks):\n \"\"\"\n :type ownedChunks: List[int]\n :rtype: int\n \"\"\"\n\n\n def leave(self, userID):\n \"\"\"\n :type userID: int\n :rtype: None\n \"\"\"\n\n\n def request(self, userID, chunkID):\n \"\"\"\n :type userID: int\n :type chunkID: int\n :rtype: List[int]\n \"\"\"\n\n\n\n# Your FileSharing object will be instantiated and called as such:\n# obj = FileSharing(m)\n# param_1 = obj.join(ownedChunks)\n# obj.leave(userID)\n# param_3 = obj.request(userID,chunkID)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class FileSharing:\n\n def __init__(self, m: int):\n\n\n def join(self, ownedChunks: List[int]) -> int:\n\n\n def leave(self, userID: int) -> None:\n\n\n def request(self, userID: int, chunkID: int) -> List[int]:\n\n\n\n# Your FileSharing object will be instantiated and called as such:\n# obj = FileSharing(m)\n# param_1 = obj.join(ownedChunks)\n# obj.leave(userID)\n# param_3 = obj.request(userID,chunkID)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} FileSharing;\n\n\nFileSharing* fileSharingCreate(int m) {\n\n}\n\nint fileSharingJoin(FileSharing* obj, int* ownedChunks, int ownedChunksSize) {\n\n}\n\nvoid fileSharingLeave(FileSharing* obj, int userID) {\n\n}\n\nint* fileSharingRequest(FileSharing* obj, int userID, int chunkID, int* retSize) {\n\n}\n\nvoid fileSharingFree(FileSharing* obj) {\n\n}\n\n/**\n * Your FileSharing struct will be instantiated and called as such:\n * FileSharing* obj = fileSharingCreate(m);\n * int param_1 = fileSharingJoin(obj, ownedChunks, ownedChunksSize);\n \n * fileSharingLeave(obj, userID);\n \n * int* param_3 = fileSharingRequest(obj, userID, chunkID, retSize);\n \n * fileSharingFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class FileSharing {\n\n public FileSharing(int m) {\n\n }\n \n public int Join(IList ownedChunks) {\n\n }\n \n public void Leave(int userID) {\n\n }\n \n public IList Request(int userID, int chunkID) {\n\n }\n}\n\n/**\n * Your FileSharing object will be instantiated and called as such:\n * FileSharing obj = new FileSharing(m);\n * int param_1 = obj.Join(ownedChunks);\n * obj.Leave(userID);\n * IList param_3 = obj.Request(userID,chunkID);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} m\n */\nvar FileSharing = function(m) {\n\n};\n\n/** \n * @param {number[]} ownedChunks\n * @return {number}\n */\nFileSharing.prototype.join = function(ownedChunks) {\n\n};\n\n/** \n * @param {number} userID\n * @return {void}\n */\nFileSharing.prototype.leave = function(userID) {\n\n};\n\n/** \n * @param {number} userID \n * @param {number} chunkID\n * @return {number[]}\n */\nFileSharing.prototype.request = function(userID, chunkID) {\n\n};\n\n/**\n * Your FileSharing object will be instantiated and called as such:\n * var obj = new FileSharing(m)\n * var param_1 = obj.join(ownedChunks)\n * obj.leave(userID)\n * var param_3 = obj.request(userID,chunkID)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class FileSharing\n\n=begin\n :type m: Integer\n=end\n def initialize(m)\n\n end\n\n\n=begin\n :type owned_chunks: Integer[]\n :rtype: Integer\n=end\n def join(owned_chunks)\n\n end\n\n\n=begin\n :type user_id: Integer\n :rtype: Void\n=end\n def leave(user_id)\n\n end\n\n\n=begin\n :type user_id: Integer\n :type chunk_id: Integer\n :rtype: Integer[]\n=end\n def request(user_id, chunk_id)\n\n end\n\n\nend\n\n# Your FileSharing object will be instantiated and called as such:\n# obj = FileSharing.new(m)\n# param_1 = obj.join(owned_chunks)\n# obj.leave(user_id)\n# param_3 = obj.request(user_id, chunk_id)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass FileSharing {\n\n init(_ m: Int) {\n\n }\n \n func join(_ ownedChunks: [Int]) -> Int {\n\n }\n \n func leave(_ userID: Int) {\n\n }\n \n func request(_ userID: Int, _ chunkID: Int) -> [Int] {\n\n }\n}\n\n/**\n * Your FileSharing object will be instantiated and called as such:\n * let obj = FileSharing(m)\n * let ret_1: Int = obj.join(ownedChunks)\n * obj.leave(userID)\n * let ret_3: [Int] = obj.request(userID, chunkID)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type FileSharing struct {\n\n}\n\n\nfunc Constructor(m int) FileSharing {\n\n}\n\n\nfunc (this *FileSharing) Join(ownedChunks []int) int {\n\n}\n\n\nfunc (this *FileSharing) Leave(userID int) {\n\n}\n\n\nfunc (this *FileSharing) Request(userID int, chunkID int) []int {\n\n}\n\n\n/**\n * Your FileSharing object will be instantiated and called as such:\n * obj := Constructor(m);\n * param_1 := obj.Join(ownedChunks);\n * obj.Leave(userID);\n * param_3 := obj.Request(userID,chunkID);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class FileSharing(_m: Int) {\n\n def join(ownedChunks: List[Int]): Int = {\n\n }\n\n def leave(userID: Int) {\n\n }\n\n def request(userID: Int, chunkID: Int): List[Int] = {\n\n }\n\n}\n\n/**\n * Your FileSharing object will be instantiated and called as such:\n * var obj = new FileSharing(m)\n * var param_1 = obj.join(ownedChunks)\n * obj.leave(userID)\n * var param_3 = obj.request(userID,chunkID)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class FileSharing(m: Int) {\n\n fun join(ownedChunks: List): Int {\n\n }\n\n fun leave(userID: Int) {\n\n }\n\n fun request(userID: Int, chunkID: Int): List {\n\n }\n\n}\n\n/**\n * Your FileSharing object will be instantiated and called as such:\n * var obj = FileSharing(m)\n * var param_1 = obj.join(ownedChunks)\n * obj.leave(userID)\n * var param_3 = obj.request(userID,chunkID)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct FileSharing {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl FileSharing {\n\n fn new(m: i32) -> Self {\n\n }\n \n fn join(&self, owned_chunks: Vec) -> i32 {\n\n }\n \n fn leave(&self, user_id: i32) {\n\n }\n \n fn request(&self, user_id: i32, chunk_id: i32) -> Vec {\n\n }\n}\n\n/**\n * Your FileSharing object will be instantiated and called as such:\n * let obj = FileSharing::new(m);\n * let ret_1: i32 = obj.join(ownedChunks);\n * obj.leave(userID);\n * let ret_3: Vec = obj.request(userID, chunkID);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class FileSharing {\n /**\n * @param Integer $m\n */\n function __construct($m) {\n\n }\n\n /**\n * @param Integer[] $ownedChunks\n * @return Integer\n */\n function join($ownedChunks) {\n\n }\n\n /**\n * @param Integer $userID\n * @return NULL\n */\n function leave($userID) {\n\n }\n\n /**\n * @param Integer $userID\n * @param Integer $chunkID\n * @return Integer[]\n */\n function request($userID, $chunkID) {\n\n }\n}\n\n/**\n * Your FileSharing object will be instantiated and called as such:\n * $obj = FileSharing($m);\n * $ret_1 = $obj->join($ownedChunks);\n * $obj->leave($userID);\n * $ret_3 = $obj->request($userID, $chunkID);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class FileSharing {\n constructor(m: number) {\n\n }\n\n join(ownedChunks: number[]): number {\n\n }\n\n leave(userID: number): void {\n\n }\n\n request(userID: number, chunkID: number): number[] {\n\n }\n}\n\n/**\n * Your FileSharing object will be instantiated and called as such:\n * var obj = new FileSharing(m)\n * var param_1 = obj.join(ownedChunks)\n * obj.leave(userID)\n * var param_3 = obj.request(userID,chunkID)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define file-sharing%\n (class object%\n (super-new)\n\n ; m : exact-integer?\n (init-field\n m)\n \n ; join : (listof exact-integer?) -> exact-integer?\n (define/public (join ownedChunks)\n\n )\n ; leave : exact-integer? -> void?\n (define/public (leave userID)\n\n )\n ; request : exact-integer? exact-integer? -> (listof exact-integer?)\n (define/public (request userID chunkID)\n\n )))\n\n;; Your file-sharing% object will be instantiated and called as such:\n;; (define obj (new file-sharing% [m m]))\n;; (define param_1 (send obj join owned-chunks))\n;; (send obj leave user-id)\n;; (define param_3 (send obj request user-id chunk-id))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1500](https://leetcode-cn.com/problems/design-a-file-sharing-system)", "[\u8bbe\u8ba1\u6587\u4ef6\u5206\u4eab\u7cfb\u7edf](/solution/1500-1599/1500.Design%20a%20File%20Sharing%20System/README.md)", "`\u8bbe\u8ba1`,`\u6570\u7ec4`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1500](https://leetcode.com/problems/design-a-file-sharing-system)", "[Design a File Sharing System](/solution/1500-1599/1500.Design%20a%20File%20Sharing%20System/README_EN.md)", "`Design`,`Array`", "Medium", "\ud83d\udd12"]}, {"question_id": "1639", "frontend_question_id": "1495", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/friendly-movies-streamed-last-month", "url_en": "https://leetcode.com/problems/friendly-movies-streamed-last-month", "relative_path_cn": "/solution/1400-1499/1495.Friendly%20Movies%20Streamed%20Last%20Month/README.md", "relative_path_en": "/solution/1400-1499/1495.Friendly%20Movies%20Streamed%20Last%20Month/README_EN.md", "title_cn": "\u4e0a\u6708\u64ad\u653e\u7684\u513f\u7ae5\u9002\u5b9c\u7535\u5f71", "title_en": "Friendly Movies Streamed Last Month", "question_title_slug": "friendly-movies-streamed-last-month", "content_en": "

Table: TVProgram

\r\n\r\n
\r\n+---------------+---------+\r\n| Column Name   | Type    |\r\n+---------------+---------+\r\n| program_date  | date    |\r\n| content_id    | int     |\r\n| channel       | varchar |\r\n+---------------+---------+\r\n(program_date, content_id) is the primary key for this table.\r\nThis table contains information of the programs on the TV.\r\ncontent_id is the id of the program in some channel on the TV.
\r\n\r\n

 

\r\n\r\n

Table: Content

\r\n\r\n
\r\n+------------------+---------+\r\n| Column Name      | Type    |\r\n+------------------+---------+\r\n| content_id       | varchar |\r\n| title            | varchar |\r\n| Kids_content     | enum    |\r\n| content_type     | varchar |\r\n+------------------+---------+\r\ncontent_id is the primary key for this table.\r\nKids_content is an enum that takes one of the values ('Y', 'N') where: \r\n'Y' means is content for kids otherwise 'N' is not content for kids.\r\ncontent_type is the category of the content as movies, series, etc.\r\n
\r\n\r\n

 

\r\n\r\n

Write an SQL query to report the distinct titles of the kid-friendly movies streamed in June 2020.

\r\n\r\n

Return the result table in any order.

\r\n\r\n

The query result format is in the following example.

\r\n\r\n

 

\r\n\r\n
\r\nTVProgram table:\r\n+--------------------+--------------+-------------+\r\n| program_date       | content_id   | channel     |\r\n+--------------------+--------------+-------------+\r\n| 2020-06-10 08:00   | 1            | LC-Channel  |\r\n| 2020-05-11 12:00   | 2            | LC-Channel  |\r\n| 2020-05-12 12:00   | 3            | LC-Channel  |\r\n| 2020-05-13 14:00   | 4            | Disney Ch   |\r\n| 2020-06-18 14:00   | 4            | Disney Ch   |\r\n| 2020-07-15 16:00   | 5            | Disney Ch   |\r\n+--------------------+--------------+-------------+\r\n\r\nContent table:\r\n+------------+----------------+---------------+---------------+\r\n| content_id | title          | Kids_content  | content_type  |\r\n+------------+----------------+---------------+---------------+\r\n| 1          | Leetcode Movie | N             | Movies        |\r\n| 2          | Alg. for Kids  | Y             | Series        |\r\n| 3          | Database Sols  | N             | Series        |\r\n| 4          | Aladdin        | Y             | Movies        |\r\n| 5          | Cinderella     | Y             | Movies        |\r\n+------------+----------------+---------------+---------------+\r\n\r\nResult table:\r\n+--------------+\r\n| title        |\r\n+--------------+\r\n| Aladdin      |\r\n+--------------+\r\n"Leetcode Movie" is not a content for kids.\r\n"Alg. for Kids" is not a movie.\r\n"Database Sols" is not a movie\r\n"Alladin" is a movie, content for kids and was streamed in June 2020.\r\n"Cinderella" was not streamed in June 2020.\r\n
", "content_cn": "

\u8868: TVProgram

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| program_date  | date    |\n| content_id    | int     |\n| channel       | varchar |\n+---------------+---------+\n(program_date, content_id) \u662f\u8be5\u8868\u4e3b\u952e.\n\u8be5\u8868\u5305\u542b\u7535\u89c6\u4e0a\u7684\u8282\u76ee\u4fe1\u606f.\ncontent_id \u662f\u7535\u89c6\u4e00\u4e9b\u9891\u9053\u4e0a\u7684\u8282\u76ee\u7684 id.
\n\n

 

\n\n

\u8868: Content

\n\n
\n+------------------+---------+\n| Column Name      | Type    |\n+------------------+---------+\n| content_id       | varchar |\n| title            | varchar |\n| Kids_content     | enum    |\n| content_type     | varchar |\n+------------------+---------+\ncontent_id \u662f\u8be5\u8868\u4e3b\u952e.\nKids_content \u662f\u679a\u4e3e\u7c7b\u578b, \u53d6\u503c\u4e3a('Y', 'N'), \u5176\u4e2d: \n'Y' \u8868\u793a\u513f\u7ae5\u9002\u5b9c\u5185\u5bb9, \u800c'N'\u8868\u793a\u513f\u7ae5\u4e0d\u5b9c\u5185\u5bb9.\ncontent_type \u8868\u793a\u5185\u5bb9\u7684\u7c7b\u578b, \u6bd4\u5982\u7535\u5f71, \u7535\u89c6\u5267\u7b49.\n
\n\n

 

\n\n

\u5199\u4e00\u4e2a SQL \u8bed\u53e5,  \u62a5\u544a\u5728 2020 \u5e74 6 \u6708\u4efd\u64ad\u653e\u7684\u513f\u7ae5\u9002\u5b9c\u7535\u5f71\u7684\u53bb\u91cd\u7535\u5f71\u540d.

\n\n

\u8fd4\u56de\u7684\u7ed3\u679c\u8868\u5355\u6ca1\u6709\u987a\u5e8f\u8981\u6c42.

\n\n

\u67e5\u8be2\u7ed3\u679c\u7684\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a.

\n\n

 

\n\n
\nTVProgram \u8868:\n+--------------------+--------------+-------------+\n| program_date       | content_id   | channel     |\n+--------------------+--------------+-------------+\n| 2020-06-10 08:00   | 1            | LC-Channel  |\n| 2020-05-11 12:00   | 2            | LC-Channel  |\n| 2020-05-12 12:00   | 3            | LC-Channel  |\n| 2020-05-13 14:00   | 4            | Disney Ch   |\n| 2020-06-18 14:00   | 4            | Disney Ch   |\n| 2020-07-15 16:00   | 5            | Disney Ch   |\n+--------------------+--------------+-------------+\n\nContent \u8868:\n+------------+----------------+---------------+---------------+\n| content_id | title          | Kids_content  | content_type  |\n+------------+----------------+---------------+---------------+\n| 1          | Leetcode Movie | N             | Movies        |\n| 2          | Alg. for Kids  | Y             | Series        |\n| 3          | Database Sols  | N             | Series        |\n| 4          | Aladdin        | Y             | Movies        |\n| 5          | Cinderella     | Y             | Movies        |\n+------------+----------------+---------------+---------------+\n\nResult \u8868:\n+--------------+\n| title        |\n+--------------+\n| Aladdin      |\n+--------------+\n"Leetcode Movie" \u662f\u513f\u7ae5\u4e0d\u5b9c\u7684\u7535\u5f71.\n"Alg. for Kids" \u4e0d\u662f\u7535\u5f71.\n"Database Sols" \u4e0d\u662f\u7535\u5f71\n"Alladin" \u662f\u7535\u5f71, \u513f\u7ae5\u9002\u5b9c, \u5e76\u4e14\u5728 2020 \u5e74 6 \u6708\u4efd\u64ad\u653e.\n"Cinderella" \u4e0d\u5728 2020 \u5e74 6 \u6708\u4efd\u64ad\u653e.\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1495](https://leetcode-cn.com/problems/friendly-movies-streamed-last-month)", "[\u4e0a\u6708\u64ad\u653e\u7684\u513f\u7ae5\u9002\u5b9c\u7535\u5f71](/solution/1400-1499/1495.Friendly%20Movies%20Streamed%20Last%20Month/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1495](https://leetcode.com/problems/friendly-movies-streamed-last-month)", "[Friendly Movies Streamed Last Month](/solution/1400-1499/1495.Friendly%20Movies%20Streamed%20Last%20Month/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1638", "frontend_question_id": "1515", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/best-position-for-a-service-centre", "url_en": "https://leetcode.com/problems/best-position-for-a-service-centre", "relative_path_cn": "/solution/1500-1599/1515.Best%20Position%20for%20a%20Service%20Centre/README.md", "relative_path_en": "/solution/1500-1599/1515.Best%20Position%20for%20a%20Service%20Centre/README_EN.md", "title_cn": "\u670d\u52a1\u4e2d\u5fc3\u7684\u6700\u4f73\u4f4d\u7f6e", "title_en": "Best Position for a Service Centre", "question_title_slug": "best-position-for-a-service-centre", "content_en": "

A delivery company wants to build a new service centre in a new city. The company knows the positions of all the customers in this city on a 2D-Map and wants to build the new centre in a position such that the sum of the euclidean distances to all customers is minimum.

\n\n

Given an array positions where positions[i] = [xi, yi] is the position of the ith customer on the map, return the minimum sum of the euclidean distances to all customers.

\n\n

In other words, you need to choose the position of the service centre [xcentre, ycentre] such that the following formula is minimized:

\n\"\"\n

Answers within 10^-5 of the actual value will be accepted.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: positions = [[0,1],[1,0],[1,2],[2,1]]\nOutput: 4.00000\nExplanation: As shown, you can see that choosing [xcentre, ycentre] = [1, 1] will make the distance to each customer = 1, the sum of all distances is 4 which is the minimum possible we can achieve.\n
\n\n

Example 2:

\n\"\"\n
\nInput: positions = [[1,1],[3,3]]\nOutput: 2.82843\nExplanation: The minimum possible sum of distances = sqrt(2) + sqrt(2) = 2.82843\n
\n\n

Example 3:

\n\n
\nInput: positions = [[1,1]]\nOutput: 0.00000\n
\n\n

Example 4:

\n\n
\nInput: positions = [[1,1],[0,0],[2,0]]\nOutput: 2.73205\nExplanation: At the first glance, you may think that locating the centre at [1, 0] will achieve the minimum sum, but locating it at [1, 0] will make the sum of distances = 3.\nTry to locate the centre at [1.0, 0.5773502711] you will see that the sum of distances is 2.73205.\nBe careful with the precision!\n
\n\n

Example 5:

\n\n
\nInput: positions = [[0,1],[3,2],[4,5],[7,6],[8,9],[11,1],[2,12]]\nOutput: 32.94036\nExplanation: You can use [4.3460852395, 4.9813795505] as the position of the centre.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= positions.length <= 50
  • \n\t
  • positions[i].length == 2
  • \n\t
  • 0 <= positions[i][0], positions[i][1] <= 100
  • \n
\n", "content_cn": "

\u4e00\u5bb6\u5feb\u9012\u516c\u53f8\u5e0c\u671b\u5728\u65b0\u57ce\u5e02\u5efa\u7acb\u65b0\u7684\u670d\u52a1\u4e2d\u5fc3\u3002\u516c\u53f8\u7edf\u8ba1\u4e86\u8be5\u57ce\u5e02\u6240\u6709\u5ba2\u6237\u5728\u4e8c\u7ef4\u5730\u56fe\u4e0a\u7684\u5750\u6807\uff0c\u5e76\u5e0c\u671b\u80fd\u591f\u4ee5\u6b64\u4e3a\u4f9d\u636e\u4e3a\u65b0\u7684\u670d\u52a1\u4e2d\u5fc3\u9009\u5740\uff1a\u4f7f\u670d\u52a1\u4e2d\u5fc3 \u5230\u6240\u6709\u5ba2\u6237\u7684\u6b27\u51e0\u91cc\u5f97\u8ddd\u79bb\u7684\u603b\u548c\u6700\u5c0f \u3002

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 positions \uff0c\u5176\u4e2d positions[i] = [xi, yi] \u8868\u793a\u7b2c i \u4e2a\u5ba2\u6237\u5728\u4e8c\u7ef4\u5730\u56fe\u4e0a\u7684\u4f4d\u7f6e\uff0c\u8fd4\u56de\u5230\u6240\u6709\u5ba2\u6237\u7684 \u6b27\u51e0\u91cc\u5f97\u8ddd\u79bb\u7684\u6700\u5c0f\u603b\u548c \u3002

\n\n

\u6362\u53e5\u8bdd\u8bf4\uff0c\u8bf7\u4f60\u4e3a\u670d\u52a1\u4e2d\u5fc3\u9009\u5740\uff0c\u8be5\u4f4d\u7f6e\u7684\u5750\u6807 [xcentre, ycentre] \u9700\u8981\u4f7f\u4e0b\u9762\u7684\u516c\u5f0f\u53d6\u5230\u6700\u5c0f\u503c\uff1a

\n\n

\"\"

\n\n

\u4e0e\u771f\u5b9e\u503c\u8bef\u5dee\u5728 10^-5 \u4e4b\u5185\u7684\u7b54\u6848\u5c06\u88ab\u89c6\u4f5c\u6b63\u786e\u7b54\u6848\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1apositions = [[0,1],[1,0],[1,2],[2,1]]\n\u8f93\u51fa\uff1a4.00000\n\u89e3\u91ca\uff1a\u5982\u56fe\u6240\u793a\uff0c\u4f60\u53ef\u4ee5\u9009 [xcentre, ycentre] = [1, 1] \u4f5c\u4e3a\u65b0\u4e2d\u5fc3\u7684\u4f4d\u7f6e\uff0c\u8fd9\u6837\u4e00\u6765\u5230\u6bcf\u4e2a\u5ba2\u6237\u7684\u8ddd\u79bb\u5c31\u90fd\u662f 1\uff0c\u6240\u6709\u8ddd\u79bb\u4e4b\u548c\u4e3a 4 \uff0c\u8fd9\u4e5f\u662f\u53ef\u4ee5\u627e\u5230\u7684\u6700\u5c0f\u503c\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1apositions = [[1,1],[3,3]]\n\u8f93\u51fa\uff1a2.82843\n\u89e3\u91ca\uff1a\u6b27\u51e0\u91cc\u5f97\u8ddd\u79bb\u53ef\u80fd\u7684\u6700\u5c0f\u603b\u548c\u4e3a sqrt(2) + sqrt(2) = 2.82843\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1apositions = [[1,1]]\n\u8f93\u51fa\uff1a0.00000\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1apositions = [[1,1],[0,0],[2,0]]\n\u8f93\u51fa\uff1a2.73205\n\u89e3\u91ca\uff1a\u4e4d\u4e00\u770b\uff0c\u4f60\u53ef\u80fd\u4f1a\u5c06\u4e2d\u5fc3\u5b9a\u5728 [1, 0] \u5e76\u671f\u5f85\u80fd\u591f\u5f97\u5230\u6700\u5c0f\u603b\u548c\uff0c\u4f46\u662f\u5982\u679c\u9009\u5740\u5728 [1, 0] \u8ddd\u79bb\u603b\u548c\u4e3a 3\n\u5982\u679c\u5c06\u4f4d\u7f6e\u9009\u5728 [1.0, 0.5773502711] \uff0c\u8ddd\u79bb\u603b\u548c\u5c06\u4f1a\u53d8\u4e3a 2.73205\n\u5f53\u5fc3\u7cbe\u5ea6\u95ee\u9898\uff01\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1apositions = [[0,1],[3,2],[4,5],[7,6],[8,9],[11,1],[2,12]]\n\u8f93\u51fa\uff1a32.94036\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u7528 [4.3460852395, 4.9813795505] \u4f5c\u4e3a\u65b0\u4e2d\u5fc3\u7684\u4f4d\u7f6e\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= positions.length <= 50
  • \n\t
  • positions[i].length == 2
  • \n\t
  • 0 <= positions[i][0], positions[i][1] <= 100
  • \n
\n", "tags_en": ["Geometry"], "tags_cn": ["\u51e0\u4f55"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n double getMinDistSum(vector>& positions) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double getMinDistSum(int[][] positions) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getMinDistSum(self, positions):\n \"\"\"\n :type positions: List[List[int]]\n :rtype: float\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getMinDistSum(self, positions: List[List[int]]) -> float:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\ndouble getMinDistSum(int** positions, int positionsSize, int* positionsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double GetMinDistSum(int[][] positions) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} positions\n * @return {number}\n */\nvar getMinDistSum = function(positions) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} positions\n# @return {Float}\ndef get_min_dist_sum(positions)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getMinDistSum(_ positions: [[Int]]) -> Double {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getMinDistSum(positions [][]int) float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getMinDistSum(positions: Array[Array[Int]]): Double = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getMinDistSum(positions: Array): Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_min_dist_sum(positions: Vec>) -> f64 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $positions\n * @return Float\n */\n function getMinDistSum($positions) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getMinDistSum(positions: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-min-dist-sum positions)\n (-> (listof (listof exact-integer?)) flonum?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1515](https://leetcode-cn.com/problems/best-position-for-a-service-centre)", "[\u670d\u52a1\u4e2d\u5fc3\u7684\u6700\u4f73\u4f4d\u7f6e](/solution/1500-1599/1515.Best%20Position%20for%20a%20Service%20Centre/README.md)", "`\u51e0\u4f55`", "\u56f0\u96be", ""], "md_table_row_en": ["[1515](https://leetcode.com/problems/best-position-for-a-service-centre)", "[Best Position for a Service Centre](/solution/1500-1599/1515.Best%20Position%20for%20a%20Service%20Centre/README_EN.md)", "`Geometry`", "Hard", ""]}, {"question_id": "1637", "frontend_question_id": "1531", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/string-compression-ii", "url_en": "https://leetcode.com/problems/string-compression-ii", "relative_path_cn": "/solution/1500-1599/1531.String%20Compression%20II/README.md", "relative_path_en": "/solution/1500-1599/1531.String%20Compression%20II/README_EN.md", "title_cn": "\u538b\u7f29\u5b57\u7b26\u4e32 II", "title_en": "String Compression II", "question_title_slug": "string-compression-ii", "content_en": "

Run-length encoding is a string compression method that works by replacing consecutive identical characters (repeated 2 or more times) with the concatenation of the character and the number marking the count of the characters (length of the run). For example, to compress the string "aabccc" we replace "aa" by "a2" and replace "ccc" by "c3". Thus the compressed string becomes "a2bc3".

\n\n

Notice that in this problem, we are not adding '1' after single characters.

\n\n

Given a string s and an integer k. You need to delete at most k characters from s such that the run-length encoded version of s has minimum length.

\n\n

Find the minimum length of the run-length encoded version of s after deleting at most k characters.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "aaabcccd", k = 2\nOutput: 4\nExplanation: Compressing s without deleting anything will give us "a3bc3d" of length 6. Deleting any of the characters 'a' or 'c' would at most decrease the length of the compressed string to 5, for instance delete 2 'a' then we will have s = "abcccd" which compressed is abc3d. Therefore, the optimal way is to delete 'b' and 'd', then the compressed version of s will be "a3c3" of length 4.
\n\n

Example 2:

\n\n
\nInput: s = "aabbaa", k = 2\nOutput: 2\nExplanation: If we delete both 'b' characters, the resulting compressed string would be "a4" of length 2.\n
\n\n

Example 3:

\n\n
\nInput: s = "aaaaaaaaaaa", k = 0\nOutput: 3\nExplanation: Since k is zero, we cannot delete anything. The compressed string is "a11" of length 3.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 100
  • \n\t
  • 0 <= k <= s.length
  • \n\t
  • s contains only lowercase English letters.
  • \n
\n", "content_cn": "

\u884c\u7a0b\u957f\u5ea6\u7f16\u7801 \u662f\u4e00\u79cd\u5e38\u7528\u7684\u5b57\u7b26\u4e32\u538b\u7f29\u65b9\u6cd5\uff0c\u5b83\u5c06\u8fde\u7eed\u7684\u76f8\u540c\u5b57\u7b26\uff08\u91cd\u590d 2 \u6b21\u6216\u66f4\u591a\u6b21\uff09\u66ff\u6362\u4e3a\u5b57\u7b26\u548c\u8868\u793a\u5b57\u7b26\u8ba1\u6570\u7684\u6570\u5b57\uff08\u884c\u7a0b\u957f\u5ea6\uff09\u3002\u4f8b\u5982\uff0c\u7528\u6b64\u65b9\u6cd5\u538b\u7f29\u5b57\u7b26\u4e32 "aabccc" \uff0c\u5c06 "aa" \u66ff\u6362\u4e3a "a2" \uff0c"ccc" \u66ff\u6362\u4e3a` "c3" \u3002\u56e0\u6b64\u538b\u7f29\u540e\u7684\u5b57\u7b26\u4e32\u53d8\u4e3a "a2bc3" \u3002

\n\n

\u6ce8\u610f\uff0c\u672c\u95ee\u9898\u4e2d\uff0c\u538b\u7f29\u65f6\u6ca1\u6709\u5728\u5355\u4e2a\u5b57\u7b26\u540e\u9644\u52a0\u8ba1\u6570 '1' \u3002

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \u548c\u4e00\u4e2a\u6574\u6570 k \u3002\u4f60\u9700\u8981\u4ece\u5b57\u7b26\u4e32 s \u4e2d\u5220\u9664\u6700\u591a k \u4e2a\u5b57\u7b26\uff0c\u4ee5\u4f7f s \u7684\u884c\u7a0b\u957f\u5ea6\u7f16\u7801\u957f\u5ea6\u6700\u5c0f\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u5220\u9664\u6700\u591a k \u4e2a\u5b57\u7b26\u540e\uff0cs \u884c\u7a0b\u957f\u5ea6\u7f16\u7801\u7684\u6700\u5c0f\u957f\u5ea6 \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1as = "aaabcccd", k = 2\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u5728\u4e0d\u5220\u9664\u4efb\u4f55\u5185\u5bb9\u7684\u60c5\u51b5\u4e0b\uff0c\u538b\u7f29\u540e\u7684\u5b57\u7b26\u4e32\u662f "a3bc3d" \uff0c\u957f\u5ea6\u4e3a 6 \u3002\u6700\u4f18\u7684\u65b9\u6848\u662f\u5220\u9664 'b' \u548c 'd'\uff0c\u8fd9\u6837\u4e00\u6765\uff0c\u538b\u7f29\u540e\u7684\u5b57\u7b26\u4e32\u4e3a "a3c3" \uff0c\u957f\u5ea6\u662f 4 \u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1as = "aabbaa", k = 2\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5982\u679c\u5220\u53bb\u4e24\u4e2a 'b' \u5b57\u7b26\uff0c\u90a3\u4e48\u538b\u7f29\u540e\u7684\u5b57\u7b26\u4e32\u662f\u957f\u5ea6\u4e3a 2 \u7684 "a4" \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1as = "aaaaaaaaaaa", k = 0\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u7531\u4e8e k \u7b49\u4e8e 0 \uff0c\u4e0d\u80fd\u5220\u53bb\u4efb\u4f55\u5b57\u7b26\u3002\u538b\u7f29\u540e\u7684\u5b57\u7b26\u4e32\u662f "a11" \uff0c\u957f\u5ea6\u4e3a 3 \u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length <= 100
  • \n\t
  • 0 <= k <= s.length
  • \n\t
  • s \u4ec5\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd
  • \n
\n", "tags_en": ["String", "Dynamic Programming"], "tags_cn": ["\u5b57\u7b26\u4e32", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int getLengthOfOptimalCompression(string s, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int getLengthOfOptimalCompression(String s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getLengthOfOptimalCompression(self, s, k):\n \"\"\"\n :type s: str\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getLengthOfOptimalCompression(self, s: str, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint getLengthOfOptimalCompression(char * s, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int GetLengthOfOptimalCompression(string s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number} k\n * @return {number}\n */\nvar getLengthOfOptimalCompression = function(s, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer} k\n# @return {Integer}\ndef get_length_of_optimal_compression(s, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getLengthOfOptimalCompression(_ s: String, _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getLengthOfOptimalCompression(s string, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getLengthOfOptimalCompression(s: String, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getLengthOfOptimalCompression(s: String, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_length_of_optimal_compression(s: String, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer $k\n * @return Integer\n */\n function getLengthOfOptimalCompression($s, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getLengthOfOptimalCompression(s: string, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-length-of-optimal-compression s k)\n (-> string? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1531](https://leetcode-cn.com/problems/string-compression-ii)", "[\u538b\u7f29\u5b57\u7b26\u4e32 II](/solution/1500-1599/1531.String%20Compression%20II/README.md)", "`\u5b57\u7b26\u4e32`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1531](https://leetcode.com/problems/string-compression-ii)", "[String Compression II](/solution/1500-1599/1531.String%20Compression%20II/README_EN.md)", "`String`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "1636", "frontend_question_id": "1513", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-substrings-with-only-1s", "url_en": "https://leetcode.com/problems/number-of-substrings-with-only-1s", "relative_path_cn": "/solution/1500-1599/1513.Number%20of%20Substrings%20With%20Only%201s/README.md", "relative_path_en": "/solution/1500-1599/1513.Number%20of%20Substrings%20With%20Only%201s/README_EN.md", "title_cn": "\u4ec5\u542b 1 \u7684\u5b50\u4e32\u6570", "title_en": "Number of Substrings With Only 1s", "question_title_slug": "number-of-substrings-with-only-1s", "content_en": "

Given a binary string s (a string consisting only of '0' and '1's).

\r\n\r\n

Return the number of substrings with all characters 1's.

\r\n\r\n

Since the answer may be too large, return it modulo 10^9 + 7.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: s = "0110111"\r\nOutput: 9\r\nExplanation: There are 9 substring in total with only 1's characters.\r\n"1" -> 5 times.\r\n"11" -> 3 times.\r\n"111" -> 1 time.
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: s = "101"\r\nOutput: 2\r\nExplanation: Substring "1" is shown 2 times in s.\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: s = "111111"\r\nOutput: 21\r\nExplanation: Each substring contains only 1's characters.\r\n
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: s = "000"\r\nOutput: 0\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • s[i] == '0' or s[i] == '1'
  • \r\n\t
  • 1 <= s.length <= 10^5
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32 s\uff08\u4ec5\u7531 '0' \u548c '1' \u7ec4\u6210\u7684\u5b57\u7b26\u4e32\uff09\u3002

\n\n

\u8fd4\u56de\u6240\u6709\u5b57\u7b26\u90fd\u4e3a 1 \u7684\u5b50\u5b57\u7b26\u4e32\u7684\u6570\u76ee\u3002

\n\n

\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u5f88\u5927\uff0c\u8bf7\u4f60\u5c06\u5b83\u5bf9 10^9 + 7 \u53d6\u6a21\u540e\u8fd4\u56de\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1as = "0110111"\n\u8f93\u51fa\uff1a9\n\u89e3\u91ca\uff1a\u5171\u6709 9 \u4e2a\u5b50\u5b57\u7b26\u4e32\u4ec5\u7531 '1' \u7ec4\u6210\n"1" -> 5 \u6b21\n"11" -> 3 \u6b21\n"111" -> 1 \u6b21
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1as = "101"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5b50\u5b57\u7b26\u4e32 "1" \u5728 s \u4e2d\u5171\u51fa\u73b0 2 \u6b21\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1as = "111111"\n\u8f93\u51fa\uff1a21\n\u89e3\u91ca\uff1a\u6bcf\u4e2a\u5b50\u5b57\u7b26\u4e32\u90fd\u4ec5\u7531 '1' \u7ec4\u6210\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1as = "000"\n\u8f93\u51fa\uff1a0\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • s[i] == '0' \u6216 s[i] == '1'
  • \n\t
  • 1 <= s.length <= 10^5
  • \n
\n", "tags_en": ["Math", "String"], "tags_cn": ["\u6570\u5b66", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numSub(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numSub(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numSub(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numSub(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numSub(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumSub(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar numSub = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef num_sub(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numSub(_ s: String) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numSub(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numSub(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numSub(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_sub(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function numSub($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numSub(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-sub s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1513](https://leetcode-cn.com/problems/number-of-substrings-with-only-1s)", "[\u4ec5\u542b 1 \u7684\u5b50\u4e32\u6570](/solution/1500-1599/1513.Number%20of%20Substrings%20With%20Only%201s/README.md)", "`\u6570\u5b66`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1513](https://leetcode.com/problems/number-of-substrings-with-only-1s)", "[Number of Substrings With Only 1s](/solution/1500-1599/1513.Number%20of%20Substrings%20With%20Only%201s/README_EN.md)", "`Math`,`String`", "Medium", ""]}, {"question_id": "1635", "frontend_question_id": "1512", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-good-pairs", "url_en": "https://leetcode.com/problems/number-of-good-pairs", "relative_path_cn": "/solution/1500-1599/1512.Number%20of%20Good%20Pairs/README.md", "relative_path_en": "/solution/1500-1599/1512.Number%20of%20Good%20Pairs/README_EN.md", "title_cn": "\u597d\u6570\u5bf9\u7684\u6570\u76ee", "title_en": "Number of Good Pairs", "question_title_slug": "number-of-good-pairs", "content_en": "

Given an array of integers nums.

\r\n\r\n

A pair (i,j) is called good if nums[i] == nums[j] and i < j.

\r\n\r\n

Return the number of good pairs.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: nums = [1,2,3,1,1,3]\r\nOutput: 4\r\nExplanation: There are 4 good pairs (0,3), (0,4), (3,4), (2,5) 0-indexed.\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: nums = [1,1,1,1]\r\nOutput: 6\r\nExplanation: Each pair in the array are good.\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: nums = [1,2,3]\r\nOutput: 0\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= nums.length <= 100
  • \r\n\t
  • 1 <= nums[i] <= 100
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \u3002

\n\n

\u5982\u679c\u4e00\u7ec4\u6570\u5b57 (i,j) \u6ee1\u8db3 nums[i] == nums[j] \u4e14 i < j \uff0c\u5c31\u53ef\u4ee5\u8ba4\u4e3a\u8fd9\u662f\u4e00\u7ec4 \u597d\u6570\u5bf9 \u3002

\n\n

\u8fd4\u56de\u597d\u6570\u5bf9\u7684\u6570\u76ee\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,2,3,1,1,3]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u6709 4 \u7ec4\u597d\u6570\u5bf9\uff0c\u5206\u522b\u662f (0,3), (0,4), (3,4), (2,5) \uff0c\u4e0b\u6807\u4ece 0 \u5f00\u59cb\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,1,1,1]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u6570\u7ec4\u4e2d\u7684\u6bcf\u7ec4\u6570\u5b57\u90fd\u662f\u597d\u6570\u5bf9
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,2,3]\n\u8f93\u51fa\uff1a0\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 100
  • \n\t
  • 1 <= nums[i] <= 100
  • \n
\n", "tags_en": ["Array", "Hash Table", "Math"], "tags_cn": ["\u6570\u7ec4", "\u54c8\u5e0c\u8868", "\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numIdenticalPairs(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numIdenticalPairs(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numIdenticalPairs(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numIdenticalPairs(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numIdenticalPairs(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumIdenticalPairs(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar numIdenticalPairs = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef num_identical_pairs(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numIdenticalPairs(_ nums: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numIdenticalPairs(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numIdenticalPairs(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numIdenticalPairs(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_identical_pairs(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function numIdenticalPairs($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numIdenticalPairs(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-identical-pairs nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1512](https://leetcode-cn.com/problems/number-of-good-pairs)", "[\u597d\u6570\u5bf9\u7684\u6570\u76ee](/solution/1500-1599/1512.Number%20of%20Good%20Pairs/README.md)", "`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`,`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[1512](https://leetcode.com/problems/number-of-good-pairs)", "[Number of Good Pairs](/solution/1500-1599/1512.Number%20of%20Good%20Pairs/README_EN.md)", "`Array`,`Hash Table`,`Math`", "Easy", ""]}, {"question_id": "1634", "frontend_question_id": "1490", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/clone-n-ary-tree", "url_en": "https://leetcode.com/problems/clone-n-ary-tree", "relative_path_cn": "/solution/1400-1499/1490.Clone%20N-ary%20Tree/README.md", "relative_path_en": "/solution/1400-1499/1490.Clone%20N-ary%20Tree/README_EN.md", "title_cn": "\u514b\u9686 N \u53c9\u6811", "title_en": "Clone N-ary Tree", "question_title_slug": "clone-n-ary-tree", "content_en": "

Given a root of an N-ary tree, return a deep copy (clone) of the tree.

\n\n

Each node in the n-ary tree contains a val (int) and a list (List[Node]) of its children.

\n\n
\nclass Node {\n    public int val;\n    public List<Node> children;\n}\n
\n\n

Nary-Tree input serialization is represented in their level order traversal, each group of children is separated by the null value (See examples).

\n\n

 

\n

Example 1:

\n\n

\n\n
\nInput: root = [1,null,3,2,4,null,5,6]\nOutput: [1,null,3,2,4,null,5,6]\n
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: root = [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]\nOutput: [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The depth of the n-ary tree is less than or equal to 1000.
  • \n\t
  • The total number of nodes is between [0, 104].
  • \n
\n\n

 

\nFollow up: Can your solution work for the graph problem?", "content_cn": "

\u7ed9\u5b9a\u4e00\u68f5 N \u53c9\u6811\u7684\u6839\u8282\u70b9 root \uff0c\u8fd4\u56de\u8be5\u6811\u7684\u6df1\u62f7\u8d1d\uff08\u514b\u9686\uff09\u3002

\n\n

N \u53c9\u6811\u7684\u6bcf\u4e2a\u8282\u70b9\u90fd\u5305\u542b\u4e00\u4e2a\u503c\uff08 int \uff09\u548c\u5b50\u8282\u70b9\u7684\u5217\u8868\uff08 List[Node] \uff09\u3002

\n\n
\nclass Node {\n    public int val;\n    public List<Node> children;\n}\n
\n\n

N \u53c9\u6811\u7684\u8f93\u5165\u5e8f\u5217\u7528\u5c42\u5e8f\u904d\u5386\u8868\u793a\uff0c\u6bcf\u7ec4\u5b50\u8282\u70b9\u7528 null \u5206\u9694\uff08\u89c1\u793a\u4f8b\uff09\u3002

\n\n

\u8fdb\u9636\uff1a\u4f60\u7684\u7b54\u6848\u53ef\u4ee5\u9002\u7528\u4e8e\u514b\u9686\u56fe\u95ee\u9898\u5417\uff1f

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\n\n
\n\u8f93\u5165\uff1aroot = [1,null,3,2,4,null,5,6]\n\u8f93\u51fa\uff1a[1,null,3,2,4,null,5,6]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1aroot = [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]\n\u8f93\u51fa\uff1a[1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u7ed9\u5b9a\u7684 N \u53c9\u6811\u7684\u6df1\u5ea6\u5c0f\u4e8e\u6216\u7b49\u4e8e 1000\u3002
  • \n\t
  • \u8282\u70b9\u7684\u603b\u4e2a\u6570\u5728 [0, 10^4] \u4e4b\u95f4
  • \n
\n", "tags_en": ["Tree", "Depth-first Search", "Breadth-first Search", "Hash Table"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n vector children;\n\n Node() {}\n\n Node(int _val) {\n val = _val;\n }\n\n Node(int _val, vector _children) {\n val = _val;\n children = _children;\n }\n};\n*/\n\nclass Solution {\npublic:\n Node* cloneTree(Node* root) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/*\n// Definition for a Node.\nclass Node {\n public int val;\n public List children;\n\n \n public Node() {\n children = new ArrayList();\n }\n \n public Node(int _val) {\n val = _val;\n children = new ArrayList();\n }\n \n public Node(int _val,ArrayList _children) {\n val = _val;\n children = _children;\n }\n};\n*/\n\nclass Solution {\n public Node cloneTree(Node root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "\"\"\"\n# Definition for a Node.\nclass Node(object):\n def __init__(self, val=None, children=None):\n self.val = val\n self.children = children if children is not None else []\n\"\"\"\n\nclass Solution(object):\n def cloneTree(self, root):\n \"\"\"\n :type root: Node\n :rtype: Node\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "\"\"\"\n# Definition for a Node.\nclass Node:\n def __init__(self, val=None, children=None):\n self.val = val\n self.children = children if children is not None else []\n\"\"\"\n\nclass Solution:\n def cloneTree(self, root: 'Node') -> 'Node':", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/*\n// Definition for a Node.\npublic class Node {\n public int val;\n public IList children;\n \n public Node() {\n val = 0;\n children = new List();\n }\n\n public Node(int _val) {\n val = _val;\n children = new List();\n }\n \n public Node(int _val, List _children) {\n val = _val;\n children = _children;\n }\n}\n*/\n\n\npublic class Solution {\n public Node CloneTree(Node root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // Definition for a Node.\n * function Node(val, children) {\n * this.val = val === undefined ? 0 : val;\n * this.children = children === undefined ? [] : children;\n * };\n */\n\n/**\n * @param {Node|null} node\n * @return {Node|null}\n */\nvar cloneTree = function(root) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a Node.\n# class Node\n# attr_accessor :val, :children\n# def initialize(val=0, children=[])\n# @val = val\n# @children = children\n# end\n# end\n\n# @param {Node} root\n# @return {Node}\ndef clone_tree(root)\n\t\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a Node.\n * public class Node {\n * public var val: Int\n * public var children: [Node]\n * public init(_ val: Int) {\n * self.val = val\n * self.children = []\n * }\n * }\n */\n\nclass Solution {\n func cloneTree(_ root: Node?) -> Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a Node.\n * type Node struct {\n * Val int\n * Children []*Node\n * }\n */\n\nfunc cloneTree(root *Node) *Node {\n\t\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a Node.\n * class Node(var _value: Int) {\n * var value: Int = _value\n * var children: List[Node] = List()\n * }\n */\n\nobject Solution {\n def cloneTree(root: Node): Node = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a Node.\n * class Node(var `val`: Int) {\n * var children: List = listOf()\n * }\n */\n\nclass Solution {\n fun cloneTree(root: Node?): Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a Node.\n * class Node {\n * public $val = null;\n * public $children = null;\n * function __construct($val = 0) {\n * $this->val = $val;\n * $this->children = array();\n * }\n * }\n */\n\nclass Solution {\n /**\n * @param Node $root\n * @return Node\n */\n function cloneTree($root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for Node.\n * class Node {\n * val: number\n * children: Node[]\n * constructor(val?: number, children?: Node[]) {\n * this.val = (val===undefined ? 0 : val)\n * this.children = (children===undefined ? [] : children)\n * }\n * }\n */\n\nfunction cloneTree(root: Node | null): Node | null {\n \n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1490](https://leetcode-cn.com/problems/clone-n-ary-tree)", "[\u514b\u9686 N \u53c9\u6811](/solution/1400-1499/1490.Clone%20N-ary%20Tree/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1490](https://leetcode.com/problems/clone-n-ary-tree)", "[Clone N-ary Tree](/solution/1400-1499/1490.Clone%20N-ary%20Tree/README_EN.md)", "`Tree`,`Depth-first Search`,`Breadth-first Search`,`Hash Table`", "Medium", "\ud83d\udd12"]}, {"question_id": "1633", "frontend_question_id": "1526", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-number-of-increments-on-subarrays-to-form-a-target-array", "url_en": "https://leetcode.com/problems/minimum-number-of-increments-on-subarrays-to-form-a-target-array", "relative_path_cn": "/solution/1500-1599/1526.Minimum%20Number%20of%20Increments%20on%20Subarrays%20to%20Form%20a%20Target%20Array/README.md", "relative_path_en": "/solution/1500-1599/1526.Minimum%20Number%20of%20Increments%20on%20Subarrays%20to%20Form%20a%20Target%20Array/README_EN.md", "title_cn": "\u5f62\u6210\u76ee\u6807\u6570\u7ec4\u7684\u5b50\u6570\u7ec4\u6700\u5c11\u589e\u52a0\u6b21\u6570", "title_en": "Minimum Number of Increments on Subarrays to Form a Target Array", "question_title_slug": "minimum-number-of-increments-on-subarrays-to-form-a-target-array", "content_en": "

Given an array of positive integers target and an array initial of same size with all zeros.

\n\n

Return the minimum number of operations to form a target array from initial if you are allowed to do the following operation:

\n\n
    \n\t
  • Choose any subarray from initial and increment each value by one.
  • \n
\nThe answer is guaranteed to fit within the range of a 32-bit signed integer.\n

 

\n

Example 1:

\n\n
\nInput: target = [1,2,3,2,1]\nOutput: 3\nExplanation: We need at least 3 operations to form the target array from the initial array.\n[0,0,0,0,0] increment 1 from index 0 to 4 (inclusive).\n[1,1,1,1,1] increment 1 from index 1 to 3 (inclusive).\n[1,2,2,2,1] increment 1 at index 2.\n[1,2,3,2,1] target array is formed.\n
\n\n

Example 2:

\n\n
\nInput: target = [3,1,1,2]\nOutput: 4\nExplanation: (initial)[0,0,0,0] -> [1,1,1,1] -> [1,1,1,2] -> [2,1,1,2] -> [3,1,1,2] (target).\n
\n\n

Example 3:

\n\n
\nInput: target = [3,1,5,4,2]\nOutput: 7\nExplanation: (initial)[0,0,0,0,0] -> [1,1,1,1,1] -> [2,1,1,1,1] -> [3,1,1,1,1] \n                                  -> [3,1,2,2,2] -> [3,1,3,3,2] -> [3,1,4,4,2] -> [3,1,5,4,2] (target).\n
\n\n

Example 4:

\n\n
\nInput: target = [1,1,1,1]\nOutput: 1\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= target.length <= 10^5
  • \n\t
  • 1 <= target[i] <= 10^5
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 target \u548c\u4e00\u4e2a\u6570\u7ec4 initial \uff0cinitial \u6570\u7ec4\u4e0e target  \u6570\u7ec4\u6709\u540c\u6837\u7684\u7ef4\u5ea6\uff0c\u4e14\u4e00\u5f00\u59cb\u5168\u90e8\u4e3a 0 \u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u4ece initial \u5f97\u5230  target \u7684\u6700\u5c11\u64cd\u4f5c\u6b21\u6570\uff0c\u6bcf\u6b21\u64cd\u4f5c\u9700\u9075\u5faa\u4ee5\u4e0b\u89c4\u5219\uff1a

\n\n
    \n\t
  • \u5728 initial \u4e2d\u9009\u62e9 \u4efb\u610f \u5b50\u6570\u7ec4\uff0c\u5e76\u5c06\u5b50\u6570\u7ec4\u4e2d\u6bcf\u4e2a\u5143\u7d20\u589e\u52a0 1 \u3002
  • \n
\n\n

\u7b54\u6848\u4fdd\u8bc1\u5728 32 \u4f4d\u6709\u7b26\u53f7\u6574\u6570\u4ee5\u5185\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1atarget = [1,2,3,2,1]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6211\u4eec\u9700\u8981\u81f3\u5c11 3 \u6b21\u64cd\u4f5c\u4ece intial \u6570\u7ec4\u5f97\u5230 target \u6570\u7ec4\u3002\n[0,0,0,0,0] \u5c06\u4e0b\u6807\u4e3a 0 \u5230 4 \u7684\u5143\u7d20\uff08\u5305\u542b\u4e8c\u8005\uff09\u52a0 1 \u3002\n[1,1,1,1,1] \u5c06\u4e0b\u6807\u4e3a 1 \u5230 3 \u7684\u5143\u7d20\uff08\u5305\u542b\u4e8c\u8005\uff09\u52a0 1 \u3002\n[1,2,2,2,1] \u5c06\u4e0b\u8868\u4e3a 2 \u7684\u5143\u7d20\u589e\u52a0 1 \u3002\n[1,2,3,2,1] \u5f97\u5230\u4e86\u76ee\u6807\u6570\u7ec4\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1atarget = [3,1,1,2]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a(initial)[0,0,0,0] -> [1,1,1,1] -> [1,1,1,2] -> [2,1,1,2] -> [3,1,1,2] (target) \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1atarget = [3,1,5,4,2]\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a(initial)[0,0,0,0,0] -> [1,1,1,1,1] -> [2,1,1,1,1] -> [3,1,1,1,1] \n                                  -> [3,1,2,2,2] -> [3,1,3,3,2] -> [3,1,4,4,2] -> [3,1,5,4,2] (target)\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1atarget = [1,1,1,1]\n\u8f93\u51fa\uff1a1\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= target.length <= 10^5
  • \n\t
  • 1 <= target[i] <= 10^5
  • \n
\n", "tags_en": ["Segment Tree"], "tags_cn": ["\u7ebf\u6bb5\u6811"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minNumberOperations(vector& target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minNumberOperations(int[] target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minNumberOperations(self, target):\n \"\"\"\n :type target: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minNumberOperations(self, target: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minNumberOperations(int* target, int targetSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinNumberOperations(int[] target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} target\n * @return {number}\n */\nvar minNumberOperations = function(target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} target\n# @return {Integer}\ndef min_number_operations(target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minNumberOperations(_ target: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minNumberOperations(target []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minNumberOperations(target: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minNumberOperations(target: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_number_operations(target: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $target\n * @return Integer\n */\n function minNumberOperations($target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minNumberOperations(target: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-number-operations target)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1526](https://leetcode-cn.com/problems/minimum-number-of-increments-on-subarrays-to-form-a-target-array)", "[\u5f62\u6210\u76ee\u6807\u6570\u7ec4\u7684\u5b50\u6570\u7ec4\u6700\u5c11\u589e\u52a0\u6b21\u6570](/solution/1500-1599/1526.Minimum%20Number%20of%20Increments%20on%20Subarrays%20to%20Form%20a%20Target%20Array/README.md)", "`\u7ebf\u6bb5\u6811`", "\u56f0\u96be", ""], "md_table_row_en": ["[1526](https://leetcode.com/problems/minimum-number-of-increments-on-subarrays-to-form-a-target-array)", "[Minimum Number of Increments on Subarrays to Form a Target Array](/solution/1500-1599/1526.Minimum%20Number%20of%20Increments%20on%20Subarrays%20to%20Form%20a%20Target%20Array/README_EN.md)", "`Segment Tree`", "Hard", ""]}, {"question_id": "1632", "frontend_question_id": "1525", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-good-ways-to-split-a-string", "url_en": "https://leetcode.com/problems/number-of-good-ways-to-split-a-string", "relative_path_cn": "/solution/1500-1599/1525.Number%20of%20Good%20Ways%20to%20Split%20a%20String/README.md", "relative_path_en": "/solution/1500-1599/1525.Number%20of%20Good%20Ways%20to%20Split%20a%20String/README_EN.md", "title_cn": "\u5b57\u7b26\u4e32\u7684\u597d\u5206\u5272\u6570\u76ee", "title_en": "Number of Good Ways to Split a String", "question_title_slug": "number-of-good-ways-to-split-a-string", "content_en": "

You are given a string s, a split is called good if you can split s into 2 non-empty strings p and q where its concatenation is equal to s and the number of distinct letters in p and q are the same.

\r\n\r\n

Return the number of good splits you can make in s.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: s = "aacaba"\r\nOutput: 2\r\nExplanation: There are 5 ways to split "aacaba" and 2 of them are good. \r\n("a", "acaba") Left string and right string contains 1 and 3 different letters respectively.\r\n("aa", "caba") Left string and right string contains 1 and 3 different letters respectively.\r\n("aac", "aba") Left string and right string contains 2 and 2 different letters respectively (good split).\r\n("aaca", "ba") Left string and right string contains 2 and 2 different letters respectively (good split).\r\n("aacab", "a") Left string and right string contains 3 and 1 different letters respectively.\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: s = "abcd"\r\nOutput: 1\r\nExplanation: Split the string as follows ("ab", "cd").\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: s = "aaaaa"\r\nOutput: 4\r\nExplanation: All possible splits are good.
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: s = "acbadbaada"\r\nOutput: 2\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • s contains only lowercase English letters.
  • \r\n\t
  • 1 <= s.length <= 10^5
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \uff0c\u4e00\u4e2a\u5206\u5272\u88ab\u79f0\u4e3a \u300c\u597d\u5206\u5272\u300d \u5f53\u5b83\u6ee1\u8db3\uff1a\u5c06 s \u5206\u5272\u6210 2 \u4e2a\u5b57\u7b26\u4e32 p \u548c q \uff0c\u5b83\u4eec\u8fde\u63a5\u8d77\u6765\u7b49\u4e8e s \u4e14 p \u548c q \u4e2d\u4e0d\u540c\u5b57\u7b26\u7684\u6570\u76ee\u76f8\u540c\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de s \u4e2d\u597d\u5206\u5272\u7684\u6570\u76ee\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1as = "aacaba"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u603b\u5171\u6709 5 \u79cd\u5206\u5272\u5b57\u7b26\u4e32 "aacaba" \u7684\u65b9\u6cd5\uff0c\u5176\u4e2d 2 \u79cd\u662f\u597d\u5206\u5272\u3002\n("a", "acaba") \u5de6\u8fb9\u5b57\u7b26\u4e32\u548c\u53f3\u8fb9\u5b57\u7b26\u4e32\u5206\u522b\u5305\u542b 1 \u4e2a\u548c 3 \u4e2a\u4e0d\u540c\u7684\u5b57\u7b26\u3002\n("aa", "caba") \u5de6\u8fb9\u5b57\u7b26\u4e32\u548c\u53f3\u8fb9\u5b57\u7b26\u4e32\u5206\u522b\u5305\u542b 1 \u4e2a\u548c 3 \u4e2a\u4e0d\u540c\u7684\u5b57\u7b26\u3002\n("aac", "aba") \u5de6\u8fb9\u5b57\u7b26\u4e32\u548c\u53f3\u8fb9\u5b57\u7b26\u4e32\u5206\u522b\u5305\u542b 2 \u4e2a\u548c 2 \u4e2a\u4e0d\u540c\u7684\u5b57\u7b26\u3002\u8fd9\u662f\u4e00\u4e2a\u597d\u5206\u5272\u3002\n("aaca", "ba") \u5de6\u8fb9\u5b57\u7b26\u4e32\u548c\u53f3\u8fb9\u5b57\u7b26\u4e32\u5206\u522b\u5305\u542b 2 \u4e2a\u548c 2 \u4e2a\u4e0d\u540c\u7684\u5b57\u7b26\u3002\u8fd9\u662f\u4e00\u4e2a\u597d\u5206\u5272\u3002\n("aacab", "a") \u5de6\u8fb9\u5b57\u7b26\u4e32\u548c\u53f3\u8fb9\u5b57\u7b26\u4e32\u5206\u522b\u5305\u542b 3 \u4e2a\u548c 1 \u4e2a\u4e0d\u540c\u7684\u5b57\u7b26\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1as = "abcd"\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u597d\u5206\u5272\u4e3a\u5c06\u5b57\u7b26\u4e32\u5206\u5272\u6210 ("ab", "cd") \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1as = "aaaaa"\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u6240\u6709\u5206\u5272\u90fd\u662f\u597d\u5206\u5272\u3002
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1as = "acbadbaada"\n\u8f93\u51fa\uff1a2\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • s \u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
  • \n\t
  • 1 <= s.length <= 10^5
  • \n
\n", "tags_en": ["Bit Manipulation", "String"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numSplits(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numSplits(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numSplits(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numSplits(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numSplits(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumSplits(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar numSplits = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef num_splits(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numSplits(_ s: String) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numSplits(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numSplits(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numSplits(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_splits(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function numSplits($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numSplits(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-splits s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1525](https://leetcode-cn.com/problems/number-of-good-ways-to-split-a-string)", "[\u5b57\u7b26\u4e32\u7684\u597d\u5206\u5272\u6570\u76ee](/solution/1500-1599/1525.Number%20of%20Good%20Ways%20to%20Split%20a%20String/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1525](https://leetcode.com/problems/number-of-good-ways-to-split-a-string)", "[Number of Good Ways to Split a String](/solution/1500-1599/1525.Number%20of%20Good%20Ways%20to%20Split%20a%20String/README_EN.md)", "`Bit Manipulation`,`String`", "Medium", ""]}, {"question_id": "1631", "frontend_question_id": "1524", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-sub-arrays-with-odd-sum", "url_en": "https://leetcode.com/problems/number-of-sub-arrays-with-odd-sum", "relative_path_cn": "/solution/1500-1599/1524.Number%20of%20Sub-arrays%20With%20Odd%20Sum/README.md", "relative_path_en": "/solution/1500-1599/1524.Number%20of%20Sub-arrays%20With%20Odd%20Sum/README_EN.md", "title_cn": "\u548c\u4e3a\u5947\u6570\u7684\u5b50\u6570\u7ec4\u6570\u76ee", "title_en": "Number of Sub-arrays With Odd Sum", "question_title_slug": "number-of-sub-arrays-with-odd-sum", "content_en": "

Given an array of integers arr. Return the number of sub-arrays with odd sum.

\r\n\r\n

As the answer may grow large, the answer must be computed modulo 10^9 + 7.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: arr = [1,3,5]\r\nOutput: 4\r\nExplanation: All sub-arrays are [[1],[1,3],[1,3,5],[3],[3,5],[5]]\r\nAll sub-arrays sum are [1,4,9,3,8,5].\r\nOdd sums are [1,9,3,5] so the answer is 4.\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: arr = [2,4,6]\r\nOutput: 0\r\nExplanation: All sub-arrays are [[2],[2,4],[2,4,6],[4],[4,6],[6]]\r\nAll sub-arrays sum are [2,6,12,4,10,6].\r\nAll sub-arrays have even sum and the answer is 0.\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: arr = [1,2,3,4,5,6,7]\r\nOutput: 16\r\n
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: arr = [100,100,99,99]\r\nOutput: 4\r\n
\r\n\r\n

Example 5:

\r\n\r\n
\r\nInput: arr = [7]\r\nOutput: 1\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= arr.length <= 10^5
  • \r\n\t
  • 1 <= arr[i] <= 100
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr \u3002\u8bf7\u4f60\u8fd4\u56de\u548c\u4e3a \u5947\u6570 \u7684\u5b50\u6570\u7ec4\u6570\u76ee\u3002

\n\n

\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u4f1a\u5f88\u5927\uff0c\u8bf7\u4f60\u5c06\u7ed3\u679c\u5bf9 10^9 + 7 \u53d6\u4f59\u540e\u8fd4\u56de\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aarr = [1,3,5]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u6240\u6709\u7684\u5b50\u6570\u7ec4\u4e3a [[1],[1,3],[1,3,5],[3],[3,5],[5]] \u3002\n\u6240\u6709\u5b50\u6570\u7ec4\u7684\u548c\u4e3a [1,4,9,3,8,5].\n\u5947\u6570\u548c\u5305\u62ec [1,9,3,5] \uff0c\u6240\u4ee5\u7b54\u6848\u4e3a 4 \u3002\n
\n\n

\u793a\u4f8b 2 \uff1a

\n\n
\u8f93\u5165\uff1aarr = [2,4,6]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6240\u6709\u5b50\u6570\u7ec4\u4e3a [[2],[2,4],[2,4,6],[4],[4,6],[6]] \u3002\n\u6240\u6709\u5b50\u6570\u7ec4\u548c\u4e3a [2,6,12,4,10,6] \u3002\n\u6240\u6709\u5b50\u6570\u7ec4\u548c\u90fd\u662f\u5076\u6570\uff0c\u6240\u4ee5\u7b54\u6848\u4e3a 0 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aarr = [1,2,3,4,5,6,7]\n\u8f93\u51fa\uff1a16\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1aarr = [100,100,99,99]\n\u8f93\u51fa\uff1a4\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1aarr = [7]\n\u8f93\u51fa\uff1a1\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= arr.length <= 10^5
  • \n\t
  • 1 <= arr[i] <= 100
  • \n
\n", "tags_en": ["Array", "Math"], "tags_cn": ["\u6570\u7ec4", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numOfSubarrays(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numOfSubarrays(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numOfSubarrays(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numOfSubarrays(self, arr: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numOfSubarrays(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumOfSubarrays(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar numOfSubarrays = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef num_of_subarrays(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numOfSubarrays(_ arr: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numOfSubarrays(arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numOfSubarrays(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numOfSubarrays(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_of_subarrays(arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function numOfSubarrays($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numOfSubarrays(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-of-subarrays arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1524](https://leetcode-cn.com/problems/number-of-sub-arrays-with-odd-sum)", "[\u548c\u4e3a\u5947\u6570\u7684\u5b50\u6570\u7ec4\u6570\u76ee](/solution/1500-1599/1524.Number%20of%20Sub-arrays%20With%20Odd%20Sum/README.md)", "`\u6570\u7ec4`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1524](https://leetcode.com/problems/number-of-sub-arrays-with-odd-sum)", "[Number of Sub-arrays With Odd Sum](/solution/1500-1599/1524.Number%20of%20Sub-arrays%20With%20Odd%20Sum/README_EN.md)", "`Array`,`Math`", "Medium", ""]}, {"question_id": "1630", "frontend_question_id": "1523", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-odd-numbers-in-an-interval-range", "url_en": "https://leetcode.com/problems/count-odd-numbers-in-an-interval-range", "relative_path_cn": "/solution/1500-1599/1523.Count%20Odd%20Numbers%20in%20an%20Interval%20Range/README.md", "relative_path_en": "/solution/1500-1599/1523.Count%20Odd%20Numbers%20in%20an%20Interval%20Range/README_EN.md", "title_cn": "\u5728\u533a\u95f4\u8303\u56f4\u5185\u7edf\u8ba1\u5947\u6570\u6570\u76ee", "title_en": "Count Odd Numbers in an Interval Range", "question_title_slug": "count-odd-numbers-in-an-interval-range", "content_en": "

Given two non-negative integers low and high. Return the count of odd numbers between low and high (inclusive).

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: low = 3, high = 7\r\nOutput: 3\r\nExplanation: The odd numbers between 3 and 7 are [3,5,7].
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: low = 8, high = 10\r\nOutput: 1\r\nExplanation: The odd numbers between 8 and 10 are [9].
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 0 <= low <= high <= 10^9
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e24\u4e2a\u975e\u8d1f\u6574\u6570 low \u548c high \u3002\u8bf7\u4f60\u8fd4\u56de low \u548c high \u4e4b\u95f4\uff08\u5305\u62ec\u4e8c\u8005\uff09\u5947\u6570\u7684\u6570\u76ee\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1alow = 3, high = 7\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a3 \u5230 7 \u4e4b\u95f4\u5947\u6570\u6570\u5b57\u4e3a [3,5,7] \u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1alow = 8, high = 10\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a8 \u5230 10 \u4e4b\u95f4\u5947\u6570\u6570\u5b57\u4e3a [9] \u3002
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 0 <= low <= high <= 10^9
  • \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countOdds(int low, int high) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countOdds(int low, int high) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countOdds(self, low, high):\n \"\"\"\n :type low: int\n :type high: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countOdds(self, low: int, high: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countOdds(int low, int high){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountOdds(int low, int high) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} low\n * @param {number} high\n * @return {number}\n */\nvar countOdds = function(low, high) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} low\n# @param {Integer} high\n# @return {Integer}\ndef count_odds(low, high)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countOdds(_ low: Int, _ high: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countOdds(low int, high int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countOdds(low: Int, high: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countOdds(low: Int, high: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_odds(low: i32, high: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $low\n * @param Integer $high\n * @return Integer\n */\n function countOdds($low, $high) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countOdds(low: number, high: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-odds low high)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1523](https://leetcode-cn.com/problems/count-odd-numbers-in-an-interval-range)", "[\u5728\u533a\u95f4\u8303\u56f4\u5185\u7edf\u8ba1\u5947\u6570\u6570\u76ee](/solution/1500-1599/1523.Count%20Odd%20Numbers%20in%20an%20Interval%20Range/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[1523](https://leetcode.com/problems/count-odd-numbers-in-an-interval-range)", "[Count Odd Numbers in an Interval Range](/solution/1500-1599/1523.Count%20Odd%20Numbers%20in%20an%20Interval%20Range/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "1629", "frontend_question_id": "1505", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-possible-integer-after-at-most-k-adjacent-swaps-on-digits", "url_en": "https://leetcode.com/problems/minimum-possible-integer-after-at-most-k-adjacent-swaps-on-digits", "relative_path_cn": "/solution/1500-1599/1505.Minimum%20Possible%20Integer%20After%20at%20Most%20K%20Adjacent%20Swaps%20On%20Digits/README.md", "relative_path_en": "/solution/1500-1599/1505.Minimum%20Possible%20Integer%20After%20at%20Most%20K%20Adjacent%20Swaps%20On%20Digits/README_EN.md", "title_cn": "\u6700\u591a K \u6b21\u4ea4\u6362\u76f8\u90bb\u6570\u4f4d\u540e\u5f97\u5230\u7684\u6700\u5c0f\u6574\u6570", "title_en": "Minimum Possible Integer After at Most K Adjacent Swaps On Digits", "question_title_slug": "minimum-possible-integer-after-at-most-k-adjacent-swaps-on-digits", "content_en": "

Given a string num representing the digits of a very large integer and an integer k.

\n\n

You are allowed to swap any two adjacent digits of the integer at most k times.

\n\n

Return the minimum integer you can obtain also as a string.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: num = "4321", k = 4\nOutput: "1342"\nExplanation: The steps to obtain the minimum integer from 4321 with 4 adjacent swaps are shown.\n
\n\n

Example 2:

\n\n
\nInput: num = "100", k = 1\nOutput: "010"\nExplanation: It's ok for the output to have leading zeros, but the input is guaranteed not to have any leading zeros.\n
\n\n

Example 3:

\n\n
\nInput: num = "36789", k = 1000\nOutput: "36789"\nExplanation: We can keep the number without any swaps.\n
\n\n

Example 4:

\n\n
\nInput: num = "22", k = 22\nOutput: "22"\n
\n\n

Example 5:

\n\n
\nInput: num = "9438957234785635408", k = 23\nOutput: "0345989723478563548"\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= num.length <= 30000
  • \n\t
  • num contains digits only and doesn't have leading zeros.
  • \n\t
  • 1 <= k <= 10^9
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 num \u548c\u4e00\u4e2a\u6574\u6570 k \u3002\u5176\u4e2d\uff0cnum \u8868\u793a\u4e00\u4e2a\u5f88\u5927\u7684\u6574\u6570\uff0c\u5b57\u7b26\u4e32\u4e2d\u7684\u6bcf\u4e2a\u5b57\u7b26\u4f9d\u6b21\u5bf9\u5e94\u6574\u6570\u4e0a\u7684\u5404\u4e2a \u6570\u4f4d \u3002

\n\n

\u4f60\u53ef\u4ee5\u4ea4\u6362\u8fd9\u4e2a\u6574\u6570\u76f8\u90bb\u6570\u4f4d\u7684\u6570\u5b57 \u6700\u591a k \u6b21\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u4f60\u80fd\u5f97\u5230\u7684\u6700\u5c0f\u6574\u6570\uff0c\u5e76\u4ee5\u5b57\u7b26\u4e32\u5f62\u5f0f\u8fd4\u56de\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1anum = "4321", k = 4\n\u8f93\u51fa\uff1a"1342"\n\u89e3\u91ca\uff1a4321 \u901a\u8fc7 4 \u6b21\u4ea4\u6362\u76f8\u90bb\u6570\u4f4d\u5f97\u5230\u6700\u5c0f\u6574\u6570\u7684\u6b65\u9aa4\u5982\u4e0a\u56fe\u6240\u793a\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1anum = "100", k = 1\n\u8f93\u51fa\uff1a"010"\n\u89e3\u91ca\uff1a\u8f93\u51fa\u53ef\u4ee5\u5305\u542b\u524d\u5bfc 0 \uff0c\u4f46\u8f93\u5165\u4fdd\u8bc1\u4e0d\u4f1a\u6709\u524d\u5bfc 0 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1anum = "36789", k = 1000\n\u8f93\u51fa\uff1a"36789"\n\u89e3\u91ca\uff1a\u4e0d\u9700\u8981\u505a\u4efb\u4f55\u4ea4\u6362\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1anum = "22", k = 22\n\u8f93\u51fa\uff1a"22"\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\n\u8f93\u5165\uff1anum = "9438957234785635408", k = 23\n\u8f93\u51fa\uff1a"0345989723478563548"\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= num.length <= 30000
  • \n\t
  • num \u53ea\u5305\u542b \u6570\u5b57 \u4e14\u4e0d\u542b\u6709 \u524d\u5bfc 0 \u3002
  • \n\t
  • 1 <= k <= 10^9
  • \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string minInteger(string num, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String minInteger(String num, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minInteger(self, num, k):\n \"\"\"\n :type num: str\n :type k: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minInteger(self, num: str, k: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * minInteger(char * num, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string MinInteger(string num, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} num\n * @param {number} k\n * @return {string}\n */\nvar minInteger = function(num, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} num\n# @param {Integer} k\n# @return {String}\ndef min_integer(num, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minInteger(_ num: String, _ k: Int) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minInteger(num string, k int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minInteger(num: String, k: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minInteger(num: String, k: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_integer(num: String, k: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $num\n * @param Integer $k\n * @return String\n */\n function minInteger($num, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minInteger(num: string, k: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-integer num k)\n (-> string? exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1505](https://leetcode-cn.com/problems/minimum-possible-integer-after-at-most-k-adjacent-swaps-on-digits)", "[\u6700\u591a K \u6b21\u4ea4\u6362\u76f8\u90bb\u6570\u4f4d\u540e\u5f97\u5230\u7684\u6700\u5c0f\u6574\u6570](/solution/1500-1599/1505.Minimum%20Possible%20Integer%20After%20at%20Most%20K%20Adjacent%20Swaps%20On%20Digits/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[1505](https://leetcode.com/problems/minimum-possible-integer-after-at-most-k-adjacent-swaps-on-digits)", "[Minimum Possible Integer After at Most K Adjacent Swaps On Digits](/solution/1500-1599/1505.Minimum%20Possible%20Integer%20After%20at%20Most%20K%20Adjacent%20Swaps%20On%20Digits/README_EN.md)", "`Greedy`", "Hard", ""]}, {"question_id": "1628", "frontend_question_id": "1504", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-submatrices-with-all-ones", "url_en": "https://leetcode.com/problems/count-submatrices-with-all-ones", "relative_path_cn": "/solution/1500-1599/1504.Count%20Submatrices%20With%20All%20Ones/README.md", "relative_path_en": "/solution/1500-1599/1504.Count%20Submatrices%20With%20All%20Ones/README_EN.md", "title_cn": "\u7edf\u8ba1\u5168 1 \u5b50\u77e9\u5f62", "title_en": "Count Submatrices With All Ones", "question_title_slug": "count-submatrices-with-all-ones", "content_en": "

Given a rows * columns matrix mat of ones and zeros, return how many submatrices have all ones.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: mat = [[1,0,1],\r\n              [1,1,0],\r\n              [1,1,0]]\r\nOutput: 13\r\nExplanation:\r\nThere are 6 rectangles of side 1x1.\r\nThere are 2 rectangles of side 1x2.\r\nThere are 3 rectangles of side 2x1.\r\nThere is 1 rectangle of side 2x2. \r\nThere is 1 rectangle of side 3x1.\r\nTotal number of rectangles = 6 + 2 + 3 + 1 + 1 = 13.\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: mat = [[0,1,1,0],\r\n              [0,1,1,1],\r\n              [1,1,1,0]]\r\nOutput: 24\r\nExplanation:\r\nThere are 8 rectangles of side 1x1.\r\nThere are 5 rectangles of side 1x2.\r\nThere are 2 rectangles of side 1x3. \r\nThere are 4 rectangles of side 2x1.\r\nThere are 2 rectangles of side 2x2. \r\nThere are 2 rectangles of side 3x1. \r\nThere is 1 rectangle of side 3x2. \r\nTotal number of rectangles = 8 + 5 + 2 + 4 + 2 + 2 + 1 = 24.\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: mat = [[1,1,1,1,1,1]]\r\nOutput: 21\r\n
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: mat = [[1,0,1],[0,1,0],[1,0,1]]\r\nOutput: 5\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= rows <= 150
  • \r\n\t
  • 1 <= columns <= 150
  • \r\n\t
  • 0 <= mat[i][j] <= 1
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u53ea\u5305\u542b 0 \u548c 1 \u7684 rows * columns \u77e9\u9635 mat \uff0c\u8bf7\u4f60\u8fd4\u56de\u6709\u591a\u5c11\u4e2a \u5b50\u77e9\u5f62 \u7684\u5143\u7d20\u5168\u90e8\u90fd\u662f 1 \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1amat = [[1,0,1],\n            [1,1,0],\n            [1,1,0]]\n\u8f93\u51fa\uff1a13\n\u89e3\u91ca\uff1a\n\u6709 6 \u4e2a 1x1 \u7684\u77e9\u5f62\u3002\n\u6709 2 \u4e2a 1x2 \u7684\u77e9\u5f62\u3002\n\u6709 3 \u4e2a 2x1 \u7684\u77e9\u5f62\u3002\n\u6709 1 \u4e2a 2x2 \u7684\u77e9\u5f62\u3002\n\u6709 1 \u4e2a 3x1 \u7684\u77e9\u5f62\u3002\n\u77e9\u5f62\u6570\u76ee\u603b\u5171 = 6 + 2 + 3 + 1 + 1 = 13 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1amat = [[0,1,1,0],\n            [0,1,1,1],\n            [1,1,1,0]]\n\u8f93\u51fa\uff1a24\n\u89e3\u91ca\uff1a\n\u6709 8 \u4e2a 1x1 \u7684\u5b50\u77e9\u5f62\u3002\n\u6709 5 \u4e2a 1x2 \u7684\u5b50\u77e9\u5f62\u3002\n\u6709 2 \u4e2a 1x3 \u7684\u5b50\u77e9\u5f62\u3002\n\u6709 4 \u4e2a 2x1 \u7684\u5b50\u77e9\u5f62\u3002\n\u6709 2 \u4e2a 2x2 \u7684\u5b50\u77e9\u5f62\u3002\n\u6709 2 \u4e2a 3x1 \u7684\u5b50\u77e9\u5f62\u3002\n\u6709 1 \u4e2a 3x2 \u7684\u5b50\u77e9\u5f62\u3002\n\u77e9\u5f62\u6570\u76ee\u603b\u5171 = 8 + 5 + 2 + 4 + 2 + 2 + 1 = 24 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1amat = [[1,1,1,1,1,1]]\n\u8f93\u51fa\uff1a21\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1amat = [[1,0,1],[0,1,0],[1,0,1]]\n\u8f93\u51fa\uff1a5\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= rows <= 150
  • \n\t
  • 1 <= columns <= 150
  • \n\t
  • 0 <= mat[i][j] <= 1
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numSubmat(vector>& mat) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numSubmat(int[][] mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numSubmat(self, mat):\n \"\"\"\n :type mat: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numSubmat(self, mat: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numSubmat(int** mat, int matSize, int* matColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumSubmat(int[][] mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} mat\n * @return {number}\n */\nvar numSubmat = function(mat) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} mat\n# @return {Integer}\ndef num_submat(mat)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numSubmat(_ mat: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numSubmat(mat [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numSubmat(mat: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numSubmat(mat: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_submat(mat: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $mat\n * @return Integer\n */\n function numSubmat($mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numSubmat(mat: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-submat mat)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1504](https://leetcode-cn.com/problems/count-submatrices-with-all-ones)", "[\u7edf\u8ba1\u5168 1 \u5b50\u77e9\u5f62](/solution/1500-1599/1504.Count%20Submatrices%20With%20All%20Ones/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1504](https://leetcode.com/problems/count-submatrices-with-all-ones)", "[Count Submatrices With All Ones](/solution/1500-1599/1504.Count%20Submatrices%20With%20All%20Ones/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "1627", "frontend_question_id": "1503", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/last-moment-before-all-ants-fall-out-of-a-plank", "url_en": "https://leetcode.com/problems/last-moment-before-all-ants-fall-out-of-a-plank", "relative_path_cn": "/solution/1500-1599/1503.Last%20Moment%20Before%20All%20Ants%20Fall%20Out%20of%20a%20Plank/README.md", "relative_path_en": "/solution/1500-1599/1503.Last%20Moment%20Before%20All%20Ants%20Fall%20Out%20of%20a%20Plank/README_EN.md", "title_cn": "\u6240\u6709\u8682\u8681\u6389\u4e0b\u6765\u524d\u7684\u6700\u540e\u4e00\u523b", "title_en": "Last Moment Before All Ants Fall Out of a Plank", "question_title_slug": "last-moment-before-all-ants-fall-out-of-a-plank", "content_en": "

We have a wooden plank of the length n units. Some ants are walking on the plank, each ant moves with speed 1 unit per second. Some of the ants move to the left, the other move to the right.

\r\n\r\n

When two ants moving in two different directions meet at some point, they change their directions and continue moving again. Assume changing directions doesn't take any additional time.

\r\n\r\n

When an ant reaches one end of the plank at a time t, it falls out of the plank imediately.

\r\n\r\n

Given an integer n and two integer arrays left and right, the positions of the ants moving to the left and the right. Return the moment when the last ant(s) fall out of the plank.

\r\n\r\n

 

\r\n

Example 1:

\r\n\"\"\r\n
\r\nInput: n = 4, left = [4,3], right = [0,1]\r\nOutput: 4\r\nExplanation: In the image above:\r\n-The ant at index 0 is named A and going to the right.\r\n-The ant at index 1 is named B and going to the right.\r\n-The ant at index 3 is named C and going to the left.\r\n-The ant at index 4 is named D and going to the left.\r\nNote that the last moment when an ant was on the plank is t = 4 second, after that it falls imediately out of the plank. (i.e. We can say that at t = 4.0000000001, there is no ants on the plank).\r\n
\r\n\r\n

Example 2:

\r\n\"\"\r\n
\r\nInput: n = 7, left = [], right = [0,1,2,3,4,5,6,7]\r\nOutput: 7\r\nExplanation: All ants are going to the right, the ant at index 0 needs 7 seconds to fall.\r\n
\r\n\r\n

Example 3:

\r\n\"\"\r\n
\r\nInput: n = 7, left = [0,1,2,3,4,5,6,7], right = []\r\nOutput: 7\r\nExplanation: All ants are going to the left, the ant at index 7 needs 7 seconds to fall.\r\n
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: n = 9, left = [5], right = [4]\r\nOutput: 5\r\nExplanation: At t = 1 second, both ants will be at the same intial position but with different direction.\r\n
\r\n\r\n

Example 5:

\r\n\r\n
\r\nInput: n = 6, left = [6], right = [0]\r\nOutput: 6\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= n <= 10^4
  • \r\n\t
  • 0 <= left.length <= n + 1
  • \r\n\t
  • 0 <= left[i] <= n
  • \r\n\t
  • 0 <= right.length <= n + 1
  • \r\n\t
  • 0 <= right[i] <= n
  • \r\n\t
  • 1 <= left.length + right.length <= n + 1
  • \r\n\t
  • All values of left and right are unique, and each value can appear only in one of the two arrays.
  • \r\n
", "content_cn": "

\u6709\u4e00\u5757\u6728\u677f\uff0c\u957f\u5ea6\u4e3a n \u4e2a \u5355\u4f4d \u3002\u4e00\u4e9b\u8682\u8681\u5728\u6728\u677f\u4e0a\u79fb\u52a8\uff0c\u6bcf\u53ea\u8682\u8681\u90fd\u4ee5 \u6bcf\u79d2\u4e00\u4e2a\u5355\u4f4d \u7684\u901f\u5ea6\u79fb\u52a8\u3002\u5176\u4e2d\uff0c\u4e00\u90e8\u5206\u8682\u8681\u5411 \u5de6 \u79fb\u52a8\uff0c\u5176\u4ed6\u8682\u8681\u5411 \u53f3 \u79fb\u52a8\u3002

\n\n

\u5f53\u4e24\u53ea\u5411 \u4e0d\u540c \u65b9\u5411\u79fb\u52a8\u7684\u8682\u8681\u5728\u67d0\u4e2a\u70b9\u76f8\u9047\u65f6\uff0c\u5b83\u4eec\u4f1a\u540c\u65f6\u6539\u53d8\u79fb\u52a8\u65b9\u5411\u5e76\u7ee7\u7eed\u79fb\u52a8\u3002\u5047\u8bbe\u66f4\u6539\u65b9\u5411\u4e0d\u4f1a\u82b1\u8d39\u4efb\u4f55\u989d\u5916\u65f6\u95f4\u3002

\n\n

\u800c\u5f53\u8682\u8681\u5728\u67d0\u4e00\u65f6\u523b t \u5230\u8fbe\u6728\u677f\u7684\u4e00\u7aef\u65f6\uff0c\u5b83\u7acb\u5373\u4ece\u6728\u677f\u4e0a\u6389\u4e0b\u6765\u3002

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n \u548c\u4e24\u4e2a\u6574\u6570\u6570\u7ec4 left \u4ee5\u53ca right \u3002\u4e24\u4e2a\u6570\u7ec4\u5206\u522b\u6807\u8bc6\u5411\u5de6\u6216\u8005\u5411\u53f3\u79fb\u52a8\u7684\u8682\u8681\u5728 t = 0 \u65f6\u7684\u4f4d\u7f6e\u3002\u8bf7\u4f60\u8fd4\u56de\u6700\u540e\u4e00\u53ea\u8682\u8681\u4ece\u6728\u677f\u4e0a\u6389\u4e0b\u6765\u7684\u65f6\u523b\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

 

\n\n

\"\"

\n\n
\u8f93\u5165\uff1an = 4, left = [4,3], right = [0,1]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u5982\u4e0a\u56fe\u6240\u793a\uff1a\n-\u4e0b\u6807 0 \u5904\u7684\u8682\u8681\u547d\u540d\u4e3a A \u5e76\u5411\u53f3\u79fb\u52a8\u3002\n-\u4e0b\u6807 1 \u5904\u7684\u8682\u8681\u547d\u540d\u4e3a B \u5e76\u5411\u53f3\u79fb\u52a8\u3002\n-\u4e0b\u6807 3 \u5904\u7684\u8682\u8681\u547d\u540d\u4e3a C \u5e76\u5411\u5de6\u79fb\u52a8\u3002\n-\u4e0b\u6807 4 \u5904\u7684\u8682\u8681\u547d\u540d\u4e3a D \u5e76\u5411\u5de6\u79fb\u52a8\u3002\n\u8bf7\u6ce8\u610f\uff0c\u8682\u8681\u5728\u6728\u677f\u4e0a\u7684\u6700\u540e\u65f6\u523b\u662f t = 4 \u79d2\uff0c\u4e4b\u540e\u8682\u8681\u7acb\u5373\u4ece\u6728\u677f\u4e0a\u6389\u4e0b\u6765\u3002\uff08\u4e5f\u5c31\u662f\u8bf4\u5728 t = 4.0000000001 \u65f6\uff0c\u6728\u677f\u4e0a\u6ca1\u6709\u8682\u8681\uff09\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1an = 7, left = [], right = [0,1,2,3,4,5,6,7]\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\u6240\u6709\u8682\u8681\u90fd\u5411\u53f3\u79fb\u52a8\uff0c\u4e0b\u6807\u4e3a 0 \u7684\u8682\u8681\u9700\u8981 7 \u79d2\u624d\u80fd\u4ece\u6728\u677f\u4e0a\u6389\u843d\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1an = 7, left = [0,1,2,3,4,5,6,7], right = []\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\u6240\u6709\u8682\u8681\u90fd\u5411\u5de6\u79fb\u52a8\uff0c\u4e0b\u6807\u4e3a 7 \u7684\u8682\u8681\u9700\u8981 7 \u79d2\u624d\u80fd\u4ece\u6728\u677f\u4e0a\u6389\u843d\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1an = 9, left = [5], right = [4]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1at = 1 \u79d2\u65f6\uff0c\u4e24\u53ea\u8682\u8681\u5c06\u56de\u5230\u521d\u59cb\u4f4d\u7f6e\uff0c\u4f46\u79fb\u52a8\u65b9\u5411\u4e0e\u4e4b\u524d\u76f8\u53cd\u3002\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1an = 6, left = [6], right = [0]\n\u8f93\u51fa\uff1a6\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 10^4
  • \n\t
  • 0 <= left.length <= n + 1
  • \n\t
  • 0 <= left[i] <= n
  • \n\t
  • 0 <= right.length <= n + 1
  • \n\t
  • 0 <= right[i] <= n
  • \n\t
  • 1 <= left.length + right.length <= n + 1
  • \n\t
  • left \u548c right \u4e2d\u7684\u6240\u6709\u503c\u90fd\u662f\u552f\u4e00\u7684\uff0c\u5e76\u4e14\u6bcf\u4e2a\u503c \u53ea\u80fd\u51fa\u73b0\u5728\u4e8c\u8005\u4e4b\u4e00 \u4e2d\u3002
  • \n
\n", "tags_en": ["Brainteaser", "Array"], "tags_cn": ["\u8111\u7b4b\u6025\u8f6c\u5f2f", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int getLastMoment(int n, vector& left, vector& right) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int getLastMoment(int n, int[] left, int[] right) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getLastMoment(self, n, left, right):\n \"\"\"\n :type n: int\n :type left: List[int]\n :type right: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getLastMoment(self, n: int, left: List[int], right: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint getLastMoment(int n, int* left, int leftSize, int* right, int rightSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int GetLastMoment(int n, int[] left, int[] right) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[]} left\n * @param {number[]} right\n * @return {number}\n */\nvar getLastMoment = function(n, left, right) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[]} left\n# @param {Integer[]} right\n# @return {Integer}\ndef get_last_moment(n, left, right)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getLastMoment(_ n: Int, _ left: [Int], _ right: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getLastMoment(n int, left []int, right []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getLastMoment(n: Int, left: Array[Int], right: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getLastMoment(n: Int, left: IntArray, right: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_last_moment(n: i32, left: Vec, right: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[] $left\n * @param Integer[] $right\n * @return Integer\n */\n function getLastMoment($n, $left, $right) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getLastMoment(n: number, left: number[], right: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-last-moment n left right)\n (-> exact-integer? (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1503](https://leetcode-cn.com/problems/last-moment-before-all-ants-fall-out-of-a-plank)", "[\u6240\u6709\u8682\u8681\u6389\u4e0b\u6765\u524d\u7684\u6700\u540e\u4e00\u523b](/solution/1500-1599/1503.Last%20Moment%20Before%20All%20Ants%20Fall%20Out%20of%20a%20Plank/README.md)", "`\u8111\u7b4b\u6025\u8f6c\u5f2f`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1503](https://leetcode.com/problems/last-moment-before-all-ants-fall-out-of-a-plank)", "[Last Moment Before All Ants Fall Out of a Plank](/solution/1500-1599/1503.Last%20Moment%20Before%20All%20Ants%20Fall%20Out%20of%20a%20Plank/README_EN.md)", "`Brainteaser`,`Array`", "Medium", ""]}, {"question_id": "1626", "frontend_question_id": "1502", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/can-make-arithmetic-progression-from-sequence", "url_en": "https://leetcode.com/problems/can-make-arithmetic-progression-from-sequence", "relative_path_cn": "/solution/1500-1599/1502.Can%20Make%20Arithmetic%20Progression%20From%20Sequence/README.md", "relative_path_en": "/solution/1500-1599/1502.Can%20Make%20Arithmetic%20Progression%20From%20Sequence/README_EN.md", "title_cn": "\u5224\u65ad\u80fd\u5426\u5f62\u6210\u7b49\u5dee\u6570\u5217", "title_en": "Can Make Arithmetic Progression From Sequence", "question_title_slug": "can-make-arithmetic-progression-from-sequence", "content_en": "

A sequence of numbers is called an arithmetic progression if the difference between any two consecutive elements is the same.

\n\n

Given an array of numbers arr, return true if the array can be rearranged to form an arithmetic progression. Otherwise, return false.

\n\n

 

\n

Example 1:

\n\n
\nInput: arr = [3,5,1]\nOutput: true\nExplanation: We can reorder the elements as [1,3,5] or [5,3,1] with differences 2 and -2 respectively, between each consecutive elements.\n
\n\n

Example 2:

\n\n
\nInput: arr = [1,2,4]\nOutput: false\nExplanation: There is no way to reorder the elements to obtain an arithmetic progression.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= arr.length <= 1000
  • \n\t
  • -106 <= arr[i] <= 106
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6570\u5b57\u6570\u7ec4 arr \u3002

\n\n

\u5982\u679c\u4e00\u4e2a\u6570\u5217\u4e2d\uff0c\u4efb\u610f\u76f8\u90bb\u4e24\u9879\u7684\u5dee\u603b\u7b49\u4e8e\u540c\u4e00\u4e2a\u5e38\u6570\uff0c\u90a3\u4e48\u8fd9\u4e2a\u6570\u5217\u5c31\u79f0\u4e3a \u7b49\u5dee\u6570\u5217 \u3002

\n\n

\u5982\u679c\u53ef\u4ee5\u91cd\u65b0\u6392\u5217\u6570\u7ec4\u5f62\u6210\u7b49\u5dee\u6570\u5217\uff0c\u8bf7\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aarr = [3,5,1]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u5bf9\u6570\u7ec4\u91cd\u65b0\u6392\u5e8f\u5f97\u5230 [1,3,5] \u6216\u8005 [5,3,1] \uff0c\u4efb\u610f\u76f8\u90bb\u4e24\u9879\u7684\u5dee\u5206\u522b\u4e3a 2 \u6216 -2 \uff0c\u53ef\u4ee5\u5f62\u6210\u7b49\u5dee\u6570\u5217\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aarr = [1,2,4]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u65e0\u6cd5\u901a\u8fc7\u91cd\u65b0\u6392\u5e8f\u5f97\u5230\u7b49\u5dee\u6570\u5217\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= arr.length <= 1000
  • \n\t
  • -10^6 <= arr[i] <= 10^6
  • \n
\n", "tags_en": ["Sort", "Array"], "tags_cn": ["\u6392\u5e8f", "\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canMakeArithmeticProgression(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canMakeArithmeticProgression(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canMakeArithmeticProgression(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canMakeArithmeticProgression(self, arr: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canMakeArithmeticProgression(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanMakeArithmeticProgression(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {boolean}\n */\nvar canMakeArithmeticProgression = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Boolean}\ndef can_make_arithmetic_progression(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canMakeArithmeticProgression(_ arr: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canMakeArithmeticProgression(arr []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canMakeArithmeticProgression(arr: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canMakeArithmeticProgression(arr: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_make_arithmetic_progression(arr: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Boolean\n */\n function canMakeArithmeticProgression($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canMakeArithmeticProgression(arr: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-make-arithmetic-progression arr)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1502](https://leetcode-cn.com/problems/can-make-arithmetic-progression-from-sequence)", "[\u5224\u65ad\u80fd\u5426\u5f62\u6210\u7b49\u5dee\u6570\u5217](/solution/1500-1599/1502.Can%20Make%20Arithmetic%20Progression%20From%20Sequence/README.md)", "`\u6392\u5e8f`,`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1502](https://leetcode.com/problems/can-make-arithmetic-progression-from-sequence)", "[Can Make Arithmetic Progression From Sequence](/solution/1500-1599/1502.Can%20Make%20Arithmetic%20Progression%20From%20Sequence/README_EN.md)", "`Sort`,`Array`", "Easy", ""]}, {"question_id": "1625", "frontend_question_id": "1484", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/group-sold-products-by-the-date", "url_en": "https://leetcode.com/problems/group-sold-products-by-the-date", "relative_path_cn": "/solution/1400-1499/1484.Group%20Sold%20Products%20By%20The%20Date/README.md", "relative_path_en": "/solution/1400-1499/1484.Group%20Sold%20Products%20By%20The%20Date/README_EN.md", "title_cn": "\u6309\u65e5\u671f\u5206\u7ec4\u9500\u552e\u4ea7\u54c1", "title_en": "Group Sold Products By The Date", "question_title_slug": "group-sold-products-by-the-date", "content_en": "

Table Activities:

\r\n\r\n
\r\n+-------------+---------+\r\n| Column Name | Type    |\r\n+-------------+---------+\r\n| sell_date   | date    |\r\n| product     | varchar |\r\n+-------------+---------+\r\nThere is no primary key for this table, it may contains duplicates.\r\nEach row of this table contains the product name and the date it was sold in a market.
\r\n\r\n

 

\r\n\r\n

Write an SQL query to find for each date, the number of distinct products sold and their names.

\r\n\r\n

The sold-products names for each date should be sorted lexicographically. 

\r\n\r\n

Return the result table ordered by sell_date.

\r\n\r\n

The query result format is in the following example.

\r\n\r\n
\r\nActivities table:\r\n+------------+-------------+\r\n| sell_date  | product     |\r\n+------------+-------------+\r\n| 2020-05-30 | Headphone   |\r\n| 2020-06-01 | Pencil      |\r\n| 2020-06-02 | Mask        |\r\n| 2020-05-30 | Basketball  |\r\n| 2020-06-01 | Bible       |\r\n| 2020-06-02 | Mask        |\r\n| 2020-05-30 | T-Shirt     |\r\n+------------+-------------+\r\n\r\nResult table:\r\n+------------+----------+------------------------------+\r\n| sell_date  | num_sold | products                     |\r\n+------------+----------+------------------------------+\r\n| 2020-05-30 | 3        | Basketball,Headphone,T-shirt |\r\n| 2020-06-01 | 2        | Bible,Pencil                 |\r\n| 2020-06-02 | 1        | Mask                         |\r\n+------------+----------+------------------------------+\r\nFor 2020-05-30, Sold items were (Headphone, Basketball, T-shirt), we sort them lexicographically and separate them by comma.\r\nFor 2020-06-01, Sold items were (Pencil, Bible), we sort them lexicographically and separate them by comma.\r\nFor 2020-06-02, Sold item is (Masks), we just return it.\r\n\r\n
", "content_cn": "

\u8868 Activities\uff1a

\n\n
+-------------+---------+\n| \u5217\u540d         | \u7c7b\u578b    |\n+-------------+---------+\n| sell_date   | date    |\n| product     | varchar |\n+-------------+---------+\n\u6b64\u8868\u6ca1\u6709\u4e3b\u952e\uff0c\u5b83\u53ef\u80fd\u5305\u542b\u91cd\u590d\u9879\u3002\n\u6b64\u8868\u7684\u6bcf\u4e00\u884c\u90fd\u5305\u542b\u4ea7\u54c1\u540d\u79f0\u548c\u5728\u5e02\u573a\u4e0a\u9500\u552e\u7684\u65e5\u671f\u3002\n
\n\n

 

\n\n

\u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\u6765\u67e5\u627e\u6bcf\u4e2a\u65e5\u671f\u3001\u9500\u552e\u7684\u4e0d\u540c\u4ea7\u54c1\u7684\u6570\u91cf\u53ca\u5176\u540d\u79f0\u3002
\n\u6bcf\u4e2a\u65e5\u671f\u7684\u9500\u552e\u4ea7\u54c1\u540d\u79f0\u5e94\u6309\u8bcd\u5178\u5e8f\u6392\u5217\u3002
\n\u8fd4\u56de\u6309 sell_date \u6392\u5e8f\u7684\u7ed3\u679c\u8868\u3002

\n\n


\n\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a\u3002

\n\n
Activities \u8868\uff1a\n+------------+-------------+\n| sell_date  | product     |\n+------------+-------------+\n| 2020-05-30 | Headphone   |\n| 2020-06-01 | Pencil      |\n| 2020-06-02 | Mask        |\n| 2020-05-30 | Basketball  |\n| 2020-06-01 | Bible       |\n| 2020-06-02 | Mask        |\n| 2020-05-30 | T-Shirt     |\n+------------+-------------+\n\nResult \u8868\uff1a\n+------------+----------+------------------------------+\n| sell_date  | num_sold | products                     |\n+------------+----------+------------------------------+\n| 2020-05-30 | 3        | Basketball,Headphone,T-shirt |\n| 2020-06-01 | 2        | Bible,Pencil                 |\n| 2020-06-02 | 1        | Mask                         |\n+------------+----------+------------------------------+\n\u5bf9\u4e8e2020-05-30\uff0c\u51fa\u552e\u7684\u7269\u54c1\u662f (Headphone, Basketball, T-shirt)\uff0c\u6309\u8bcd\u5178\u5e8f\u6392\u5217\uff0c\u5e76\u7528\u9017\u53f7 ',' \u5206\u9694\u3002\n\u5bf9\u4e8e2020-06-01\uff0c\u51fa\u552e\u7684\u7269\u54c1\u662f (Pencil, Bible)\uff0c\u6309\u8bcd\u5178\u5e8f\u6392\u5217\uff0c\u5e76\u7528\u9017\u53f7\u5206\u9694\u3002\n\u5bf9\u4e8e2020-06-02\uff0c\u51fa\u552e\u7684\u7269\u54c1\u662f (Mask)\uff0c\u53ea\u9700\u8fd4\u56de\u8be5\u7269\u54c1\u540d\u3002\n
\n\n

 

\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1484](https://leetcode-cn.com/problems/group-sold-products-by-the-date)", "[\u6309\u65e5\u671f\u5206\u7ec4\u9500\u552e\u4ea7\u54c1](/solution/1400-1499/1484.Group%20Sold%20Products%20By%20The%20Date/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1484](https://leetcode.com/problems/group-sold-products-by-the-date)", "[Group Sold Products By The Date](/solution/1400-1499/1484.Group%20Sold%20Products%20By%20The%20Date/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1624", "frontend_question_id": "1485", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/clone-binary-tree-with-random-pointer", "url_en": "https://leetcode.com/problems/clone-binary-tree-with-random-pointer", "relative_path_cn": "/solution/1400-1499/1485.Clone%20Binary%20Tree%20With%20Random%20Pointer/README.md", "relative_path_en": "/solution/1400-1499/1485.Clone%20Binary%20Tree%20With%20Random%20Pointer/README_EN.md", "title_cn": "\u514b\u9686\u542b\u968f\u673a\u6307\u9488\u7684\u4e8c\u53c9\u6811", "title_en": "Clone Binary Tree With Random Pointer", "question_title_slug": "clone-binary-tree-with-random-pointer", "content_en": "

A binary tree is given such that each node contains an additional random pointer which could point to any node in the tree or null.

\n\n

Return a deep copy of the tree.

\n\n

The tree is represented in the same input/output way as normal binary trees where each node is represented as a pair of [val, random_index] where:

\n\n
    \n\t
  • val: an integer representing Node.val
  • \n\t
  • random_index: the index of the node (in the input) where the random pointer points to, or null if it does not point to any node.
  • \n
\n\n

You will be given the tree in class Node and you should return the cloned tree in class NodeCopy.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: root = [[1,null],null,[4,3],[7,0]]\nOutput: [[1,null],null,[4,3],[7,0]]\nExplanation: The original binary tree is [1,null,4,7].\nThe random pointer of node one is null, so it is represented as [1, null].\nThe random pointer of node 4 is node 7, so it is represented as [4, 3] where 3 is the index of node 7 in the tree array.\nThe random pointer of node 7 is node 1, so it is represented as [7, 0] where 0 is the index of node 1 in the tree array\n
\n\n

Example 2:

\n\"\"\n
\nInput: root = [[1,4],null,[1,0],null,[1,5],[1,5]]\nOutput: [[1,4],null,[1,0],null,[1,5],[1,5]]\nExplanation: The random pointer of a node can be the node itself.\n
\n\n

Example 3:

\n\"\"\n
\nInput: root = [[1,6],[2,5],[3,4],[4,3],[5,2],[6,1],[7,0]]\nOutput: [[1,6],[2,5],[3,4],[4,3],[5,2],[6,1],[7,0]]\n
\n\n

Example 4:

\n\n
\nInput: root = []\nOutput: []\n
\n\n

Example 5:

\n\n
\nInput: root = [[1,null],null,[2,null],null,[1,null]]\nOutput: [[1,null],null,[2,null],null,[1,null]]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The number of nodes in the tree is in the range [0, 1000].
  • \n\t
  • Each node's value is between [1, 10^6].
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u4e8c\u53c9\u6811\uff0c\u6811\u4e2d\u6bcf\u4e2a\u8282\u70b9\u90fd\u542b\u6709\u4e00\u4e2a\u9644\u52a0\u7684\u968f\u673a\u6307\u9488\uff0c\u8be5\u6307\u9488\u53ef\u4ee5\u6307\u5411\u6811\u4e2d\u7684\u4efb\u4f55\u8282\u70b9\u6216\u8005\u6307\u5411\u7a7a\uff08null\uff09\u3002

\n\n

\u8bf7\u8fd4\u56de\u8be5\u6811\u7684 \u6df1\u62f7\u8d1d \u3002

\n\n

\u8be5\u6811\u7684\u8f93\u5165/\u8f93\u51fa\u5f62\u5f0f\u4e0e\u666e\u901a\u4e8c\u53c9\u6811\u76f8\u540c\uff0c\u6bcf\u4e2a\u8282\u70b9\u90fd\u7528 [val, random_index] \u8868\u793a\uff1a

\n\n
    \n\t
  • val\uff1a\u8868\u793a Node.val \u7684\u6574\u6570
  • \n\t
  • random_index\uff1a\u968f\u673a\u6307\u9488\u6307\u5411\u7684\u8282\u70b9\uff08\u5728\u8f93\u5165\u7684\u6811\u6570\u7ec4\u4e2d\uff09\u7684\u4e0b\u6807\uff1b\u5982\u679c\u672a\u6307\u5411\u4efb\u4f55\u8282\u70b9\uff0c\u5219\u4e3a null \u3002
  • \n
\n\n

\u8be5\u6811\u4ee5 Node \u7c7b\u7684\u5f62\u5f0f\u7ed9\u51fa\uff0c\u800c\u4f60\u9700\u8981\u4ee5 NodeCopy \u7c7b\u7684\u5f62\u5f0f\u8fd4\u56de\u514b\u9686\u5f97\u5230\u7684\u6811\u3002NodeCopy \u7c7b\u548cNode \u7c7b\u5b9a\u4e49\u4e00\u81f4\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1aroot = [[1,null],null,[4,3],[7,0]]\n\u8f93\u51fa\uff1a[[1,null],null,[4,3],[7,0]]\n\u89e3\u91ca\uff1a\u521d\u59cb\u4e8c\u53c9\u6811\u4e3a [1,null,4,7] \u3002\n\u8282\u70b9 1 \u7684\u968f\u673a\u6307\u9488\u6307\u5411 null\uff0c\u6240\u4ee5\u8868\u793a\u4e3a [1, null] \u3002\n\u8282\u70b9 4 \u7684\u968f\u673a\u6307\u9488\u6307\u5411 7\uff0c\u6240\u4ee5\u8868\u793a\u4e3a [4, 3] \u5176\u4e2d 3 \u662f\u6811\u6570\u7ec4\u4e2d\u8282\u70b9 7 \u5bf9\u5e94\u7684\u4e0b\u6807\u3002\n\u8282\u70b9 7 \u7684\u968f\u673a\u6307\u9488\u6307\u5411 1\uff0c\u6240\u4ee5\u8868\u793a\u4e3a [7, 0] \u5176\u4e2d 0 \u662f\u6811\u6570\u7ec4\u4e2d\u8282\u70b9 1 \u5bf9\u5e94\u7684\u4e0b\u6807\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1aroot = [[1,4],null,[1,0],null,[1,5],[1,5]]\n\u8f93\u51fa\uff1a[[1,4],null,[1,0],null,[1,5],[1,5]]\n\u89e3\u91ca\uff1a\u8282\u70b9\u7684\u968f\u673a\u6307\u9488\u53ef\u4ee5\u6307\u5411\u5b83\u81ea\u8eab\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1aroot = [[1,6],[2,5],[3,4],[4,3],[5,2],[6,1],[7,0]]\n\u8f93\u51fa\uff1a[[1,6],[2,5],[3,4],[4,3],[5,2],[6,1],[7,0]]\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1aroot = []\n\u8f93\u51fa\uff1a[]\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1aroot = [[1,null],null,[2,null],null,[1,null]]\n\u8f93\u51fa\uff1a[[1,null],null,[2,null],null,[1,null]]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • tree \u4e2d\u8282\u70b9\u6570\u76ee\u8303\u56f4\u662f [0, 1000]
  • \n\t
  • \u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u7684\u8303\u56f4\u662f [1, 10^6]
  • \n
\n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for a binary tree node.\n * struct Node {\n * int val;\n * Node *left;\n * Node *right;\n * Node *random;\n * Node() : val(0), left(nullptr), right(nullptr), random(nullptr) {}\n * Node(int x) : val(x), left(nullptr), right(nullptr), random(nullptr) {}\n * Node(int x, Node *left, Node *right, Node *random) : val(x), left(left), right(right), random(random) {}\n * };\n */\nclass Solution {\npublic:\n NodeCopy* copyRandomBinaryTree(Node* root) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class Node {\n * int val;\n * Node left;\n * Node right;\n * Node random;\n * Node() {}\n * Node(int val) { this.val = val; }\n * Node(int val, Node left, Node right, Node random) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * this.random = random;\n * }\n * }\n */\nclass Solution {\n public NodeCopy copyRandomBinaryTree(Node root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class Node(object):\n# def __init__(self, val=0, left=None, right=None, random=None):\n# self.val = val\n# self.left = left\n# self.right = right\n# self.random = random\nclass Solution(object):\n def copyRandomBinaryTree(self, root):\n \"\"\"\n :type root: Node\n :rtype: NodeCopy\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class Node:\n# def __init__(self, val=0, left=None, right=None, random=None):\n# self.val = val\n# self.left = left\n# self.right = right\n# self.random = random\nclass Solution:\n def copyRandomBinaryTree(self, root: 'Node') -> 'NodeCopy':\n ", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class Node {\n * public int val;\n * public Node left;\n * public Node right;\n * public Node random;\n * public Node(int val=0, Node left=null, Node right=null, Node random=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * this.random = random;\n * }\n * }\n */\npublic class Solution {\n public TreeNode CopyRandomBinaryTree(TreeNode root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // Definition for a Node.\n * function Node(val, left, right, random) {\n * this.val = val === undefined ? null : val;\n * this.left = left === undefined ? null : left;\n * this.right = right === undefined ? null : right;\n * this.random = next === undefined ? null : random;\n * };\n */\n\n/**\n * @param {Node} root\n * @return {NodeCopy}\n */\nvar copyRandomBinaryTree = function(root) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class Node\n# attr_accessor :val, :left, :right, :random\n# def initialize(val = 0, left = nil, right = nil, random = nil)\n# @val = val\n# @left = left\n# @right = right\n# @random = random\n# end\n# end\n# @param {Node} root\n# @return {NodeCopy}\ndef copy_random_binary_tree(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a Node.\n * public class Node {\n * public var val: Int\n * public var left: Node?\n * public var right: Node?\n *\t public var random: Node?\n * public init(_ val: Int) {\n * self.val = val\n * self.left = nil\n * self.right = nil\n * self.random = nil\n * }\n * }\n */\n\nclass Solution {\n func copyRandomBinaryTree(_ root: Node?) -> NodeCopy? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a Node.\n * type Node struct {\n * Val int\n * Left *Node\n * Right *Node\n * Random *Node\n * }\n */\n\nfunc copyRandomBinaryTree(root *Node) *NodeCopy {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a Node.\n * class Node(var _value: Int) {\n * var value: Int = _value\n * var left: Node = null\n * var right: Node = null\n * var random: Node = null\n * }\n */\n\nobject Solution {\n def copyRandomBinaryTree(root: Node): NodeCopy = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a Node.\n * class Node(var `val`: Int) {\n * var left: Node? = null\n * var right: Node? = null\n * var random: Node? = null\n * }\n */\n\nclass Solution {\n fun copyRandomBinaryTree(root: Node?): NodeCopy? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a Node.\n * class Node {\n * function __construct($val = 0) {\n * $this->val = $val;\n * $this->left = null;\n * $this->right = null;\n * $this->random = null;\n * }\n * }\n */\n\nclass Solution {\n /**\n * @param Node $root\n * @return NodeCopy\n */\n public function copyRandomBinaryTree($root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class Node {\n * val: number\n * left: Node | null\n * right: Node | null\n * random: Node | null\n * constructor(val?: number, left?: Node | null, right?: Node | null, random?: Node | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * this.random = (random===undefined ? null : random)\n * }\n * }\n */\n\nfunction copyRandomBinaryTree(root: Node | null): NodeCopy {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1485](https://leetcode-cn.com/problems/clone-binary-tree-with-random-pointer)", "[\u514b\u9686\u542b\u968f\u673a\u6307\u9488\u7684\u4e8c\u53c9\u6811](/solution/1400-1499/1485.Clone%20Binary%20Tree%20With%20Random%20Pointer/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1485](https://leetcode.com/problems/clone-binary-tree-with-random-pointer)", "[Clone Binary Tree With Random Pointer](/solution/1400-1499/1485.Clone%20Binary%20Tree%20With%20Random%20Pointer/README_EN.md)", "`Tree`,`Depth-first Search`", "Medium", "\ud83d\udd12"]}, {"question_id": "1623", "frontend_question_id": "1479", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/sales-by-day-of-the-week", "url_en": "https://leetcode.com/problems/sales-by-day-of-the-week", "relative_path_cn": "/solution/1400-1499/1479.Sales%20by%20Day%20of%20the%20Week/README.md", "relative_path_en": "/solution/1400-1499/1479.Sales%20by%20Day%20of%20the%20Week/README_EN.md", "title_cn": "\u5468\u5185\u6bcf\u5929\u7684\u9500\u552e\u60c5\u51b5", "title_en": "Sales by Day of the Week", "question_title_slug": "sales-by-day-of-the-week", "content_en": "

Table: Orders

\r\n\r\n
\r\n+---------------+---------+\r\n| Column Name   | Type    |\r\n+---------------+---------+\r\n| order_id      | int     |\r\n| customer_id   | int     |\r\n| order_date    | date    | \r\n| item_id       | varchar |\r\n| quantity      | int     |\r\n+---------------+---------+\r\n(ordered_id, item_id) is the primary key for this table.\r\nThis table contains information of the orders placed.\r\norder_date is the date when item_id was ordered by the customer with id customer_id.\r\n
\r\n\r\n

 

\r\n\r\n

Table: Items

\r\n\r\n
\r\n+---------------------+---------+\r\n| Column Name         | Type    |\r\n+---------------------+---------+\r\n| item_id             | varchar |\r\n| item_name           | varchar |\r\n| item_category       | varchar |\r\n+---------------------+---------+\r\nitem_id is the primary key for this table.\r\nitem_name is the name of the item.\r\nitem_category is the category of the item.\r\n
\r\n\r\n

 

\r\n\r\n

You are the business owner and would like to obtain a sales report for category items and day of the week.

\r\n\r\n

Write an SQL query to report how many units in each category have been ordered on each day of the week.

\r\n\r\n

Return the result table ordered by category.

\r\n\r\n

The query result format is in the following example:

\r\n\r\n

 

\r\n\r\n
\r\nOrders table:\r\n+------------+--------------+-------------+--------------+-------------+\r\n| order_id   | customer_id  | order_date  | item_id      | quantity    |\r\n+------------+--------------+-------------+--------------+-------------+\r\n| 1          | 1            | 2020-06-01  | 1            | 10          |\r\n| 2          | 1            | 2020-06-08  | 2            | 10          |\r\n| 3          | 2            | 2020-06-02  | 1            | 5           |\r\n| 4          | 3            | 2020-06-03  | 3            | 5           |\r\n| 5          | 4            | 2020-06-04  | 4            | 1           |\r\n| 6          | 4            | 2020-06-05  | 5            | 5           |\r\n| 7          | 5            | 2020-06-05  | 1            | 10          |\r\n| 8          | 5            | 2020-06-14  | 4            | 5           |\r\n| 9          | 5            | 2020-06-21  | 3            | 5           |\r\n+------------+--------------+-------------+--------------+-------------+\r\n\r\nItems table:\r\n+------------+----------------+---------------+\r\n| item_id    | item_name      | item_category |\r\n+------------+----------------+---------------+\r\n| 1          | LC Alg. Book   | Book          |\r\n| 2          | LC DB. Book    | Book          |\r\n| 3          | LC SmarthPhone | Phone         |\r\n| 4          | LC Phone 2020  | Phone         |\r\n| 5          | LC SmartGlass  | Glasses       |\r\n| 6          | LC T-Shirt XL  | T-Shirt       |\r\n+------------+----------------+---------------+\r\n\r\nResult table:\r\n+------------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+\r\n| Category   | Monday    | Tuesday   | Wednesday | Thursday  | Friday    | Saturday  | Sunday    |\r\n+------------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+\r\n| Book       | 20        | 5         | 0         | 0         | 10        | 0         | 0         |\r\n| Glasses    | 0         | 0         | 0         | 0         | 5         | 0         | 0         |\r\n| Phone      | 0         | 0         | 5         | 1         | 0         | 0         | 10        |\r\n| T-Shirt    | 0         | 0         | 0         | 0         | 0         | 0         | 0         |\r\n+------------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+\r\nOn Monday (2020-06-01, 2020-06-08) were sold a total of 20 units (10 + 10) in the category Book (ids: 1, 2).\r\nOn Tuesday (2020-06-02) were sold a total of 5 units  in the category Book (ids: 1, 2).\r\nOn Wednesday (2020-06-03) were sold a total of 5 units in the category Phone (ids: 3, 4).\r\nOn Thursday (2020-06-04) were sold a total of 1 unit in the category Phone (ids: 3, 4).\r\nOn Friday (2020-06-05) were sold 10 units in the category Book (ids: 1, 2) and 5 units in Glasses (ids: 5).\r\nOn Saturday there are no items sold.\r\nOn Sunday (2020-06-14, 2020-06-21) were sold a total of 10 units (5 +5) in the category Phone (ids: 3, 4).\r\nThere are no sales of T-Shirt.\r\n
", "content_cn": "

\u8868\uff1aOrders

\n\n
+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| order_id      | int     |\n| customer_id   | int     |\n| order_date    | date    | \n| item_id       | varchar |\n| quantity      | int     |\n+---------------+---------+\n(order_id, item_id) \u662f\u8be5\u8868\u4e3b\u952e\n\u8be5\u8868\u5305\u542b\u4e86\u8ba2\u5355\u4fe1\u606f\norder_date \u662fid\u4e3a item_id \u7684\u5546\u54c1\u88abid\u4e3a customer_id \u7684\u6d88\u8d39\u8005\u8ba2\u8d2d\u7684\u65e5\u671f.
\n\n

\u8868\uff1aItems

\n\n
+---------------------+---------+\n| Column Name         | Type    |\n+---------------------+---------+\n| item_id             | varchar |\n| item_name           | varchar |\n| item_category       | varchar |\n+---------------------+---------+\nitem_id \u662f\u8be5\u8868\u4e3b\u952e\nitem_name \u662f\u5546\u54c1\u7684\u540d\u5b57\nitem_category \u662f\u5546\u54c1\u7684\u7c7b\u522b\n
\n\n

 

\n\n

\u4f60\u662f\u4f01\u4e1a\u4e3b\uff0c\u60f3\u8981\u83b7\u5f97\u5206\u7c7b\u5546\u54c1\u548c\u5468\u5185\u6bcf\u5929\u7684\u9500\u552e\u62a5\u544a\u3002

\n\n

\u5199\u4e00\u4e2aSQL\u8bed\u53e5\uff0c\u62a5\u544a \u5468\u5185\u6bcf\u5929 \u6bcf\u4e2a\u5546\u54c1\u7c7b\u522b\u4e0b\u8ba2\u8d2d\u4e86\u591a\u5c11\u5355\u4f4d\u3002

\n\n

\u8fd4\u56de\u7ed3\u679c\u8868\u5355 \u6309\u5546\u54c1\u7c7b\u522b\u6392\u5e8f \u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a\uff1a

\n\n

 

\n\n
Orders \u8868\uff1a\n+------------+--------------+-------------+--------------+-------------+\n| order_id   | customer_id  | order_date  | item_id      | quantity    |\n+------------+--------------+-------------+--------------+-------------+\n| 1          | 1            | 2020-06-01  | 1            | 10          |\n| 2          | 1            | 2020-06-08  | 2            | 10          |\n| 3          | 2            | 2020-06-02  | 1            | 5           |\n| 4          | 3            | 2020-06-03  | 3            | 5           |\n| 5          | 4            | 2020-06-04  | 4            | 1           |\n| 6          | 4            | 2020-06-05  | 5            | 5           |\n| 7          | 5            | 2020-06-05  | 1            | 10          |\n| 8          | 5            | 2020-06-14  | 4            | 5           |\n| 9          | 5            | 2020-06-21  | 3            | 5           |\n+------------+--------------+-------------+--------------+-------------+\n\nItems \u8868\uff1a\n+------------+----------------+---------------+\n| item_id    | item_name      | item_category |\n+------------+----------------+---------------+\n| 1          | LC Alg. Book   | Book          |\n| 2          | LC DB. Book    | Book          |\n| 3          | LC SmarthPhone | Phone         |\n| 4          | LC Phone 2020  | Phone         |\n| 5          | LC SmartGlass  | Glasses       |\n| 6          | LC T-Shirt XL  | T-Shirt       |\n+------------+----------------+---------------+\n\nResult \u8868\uff1a\n+------------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+\n| Category   | Monday    | Tuesday   | Wednesday | Thursday  | Friday    | Saturday  | Sunday    |\n+------------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+\n| Book       | 20        | 5         | 0         | 0         | 10        | 0         | 0         |\n| Glasses    | 0         | 0         | 0         | 0         | 5         | 0         | 0         |\n| Phone      | 0         | 0         | 5         | 1         | 0         | 0         | 10        |\n| T-Shirt    | 0         | 0         | 0         | 0         | 0         | 0         | 0         |\n+------------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+\n\u5728\u5468\u4e00(2020-06-01, 2020-06-08)\uff0cBook\u5206\u7c7b(ids: 1, 2)\u4e0b\uff0c\u603b\u5171\u9500\u552e\u4e8620\u4e2a\u5355\u4f4d(10 + 10)\n\u5728\u5468\u4e8c(2020-06-02)\uff0cBook\u5206\u7c7b(ids: 1, 2)\u4e0b\uff0c\u603b\u5171\u9500\u552e\u4e865\u4e2a\u5355\u4f4d\n\u5728\u5468\u4e09(2020-06-03)\uff0cPhone\u5206\u7c7b(ids: 3, 4)\u4e0b\uff0c\u603b\u5171\u9500\u552e\u4e865\u4e2a\u5355\u4f4d\n\u5728\u5468\u56db(2020-06-04)\uff0cPhone\u5206\u7c7b(ids: 3, 4)\u4e0b\uff0c\u603b\u5171\u9500\u552e\u4e861\u4e2a\u5355\u4f4d\n\u5728\u5468\u4e94(2020-06-05)\uff0cBook\u5206\u7c7b(ids: 1, 2)\u4e0b\uff0c\u603b\u5171\u9500\u552e\u4e8610\u4e2a\u5355\u4f4d\uff0cGlasses\u5206\u7c7b(ids: 5)\u4e0b\uff0c\u603b\u5171\u9500\u552e\u4e865\u4e2a\u5355\u4f4d\n\u5728\u5468\u516d, \u6ca1\u6709\u5546\u54c1\u9500\u552e\n\u5728\u5468\u5929(2020-06-14, 2020-06-21)\uff0cPhone\u5206\u7c7b(ids: 3, 4)\u4e0b\uff0c\u603b\u5171\u9500\u552e\u4e8610\u4e2a\u5355\u4f4d(5 + 5)\n\u6ca1\u6709\u9500\u552e T-Shirt \u7c7b\u522b\u7684\u5546\u54c1\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1479](https://leetcode-cn.com/problems/sales-by-day-of-the-week)", "[\u5468\u5185\u6bcf\u5929\u7684\u9500\u552e\u60c5\u51b5](/solution/1400-1499/1479.Sales%20by%20Day%20of%20the%20Week/README.md)", "", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1479](https://leetcode.com/problems/sales-by-day-of-the-week)", "[Sales by Day of the Week](/solution/1400-1499/1479.Sales%20by%20Day%20of%20the%20Week/README_EN.md)", "", "Hard", "\ud83d\udd12"]}, {"question_id": "1622", "frontend_question_id": "1499", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/max-value-of-equation", "url_en": "https://leetcode.com/problems/max-value-of-equation", "relative_path_cn": "/solution/1400-1499/1499.Max%20Value%20of%20Equation/README.md", "relative_path_en": "/solution/1400-1499/1499.Max%20Value%20of%20Equation/README_EN.md", "title_cn": "\u6ee1\u8db3\u4e0d\u7b49\u5f0f\u7684\u6700\u5927\u503c", "title_en": "Max Value of Equation", "question_title_slug": "max-value-of-equation", "content_en": "

You are given an array points containing the coordinates of points on a 2D plane, sorted by the x-values, where points[i] = [xi, yi] such that xi < xj for all 1 <= i < j <= points.length. You are also given an integer k.

\n\n

Return the maximum value of the equation yi + yj + |xi - xj| where |xi - xj| <= k and 1 <= i < j <= points.length.

\n\n

It is guaranteed that there exists at least one pair of points that satisfy the constraint |xi - xj| <= k.

\n\n

 

\n

Example 1:

\n\n
\nInput: points = [[1,3],[2,0],[5,10],[6,-10]], k = 1\nOutput: 4\nExplanation: The first two points satisfy the condition |xi - xj| <= 1 and if we calculate the equation we get 3 + 0 + |1 - 2| = 4. Third and fourth points also satisfy the condition and give a value of 10 + -10 + |5 - 6| = 1.\nNo other pairs satisfy the condition, so we return the max of 4 and 1.\n
\n\n

Example 2:

\n\n
\nInput: points = [[0,0],[3,0],[9,2]], k = 3\nOutput: 3\nExplanation: Only the first two points have an absolute difference of 3 or less in the x-values, and give the value of 0 + 0 + |0 - 3| = 3.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= points.length <= 105
  • \n\t
  • points[i].length == 2
  • \n\t
  • -108 <= xi, yi <= 108
  • \n\t
  • 0 <= k <= 2 * 108
  • \n\t
  • xi < xj for all 1 <= i < j <= points.length
  • \n\t
  • xi form a strictly increasing sequence.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 points \u548c\u4e00\u4e2a\u6574\u6570 k \u3002\u6570\u7ec4\u4e2d\u6bcf\u4e2a\u5143\u7d20\u90fd\u8868\u793a\u4e8c\u7ef4\u5e73\u9762\u4e0a\u7684\u70b9\u7684\u5750\u6807\uff0c\u5e76\u6309\u7167\u6a2a\u5750\u6807 x \u7684\u503c\u4ece\u5c0f\u5230\u5927\u6392\u5e8f\u3002\u4e5f\u5c31\u662f\u8bf4 points[i] = [xi, yi] \uff0c\u5e76\u4e14\u5728 1 <= i < j <= points.length \u7684\u524d\u63d0\u4e0b\uff0c xi < xj \u603b\u6210\u7acb\u3002

\n\n

\u8bf7\u4f60\u627e\u51fa yi + yj + |xi - xj| \u7684 \u6700\u5927\u503c\uff0c\u5176\u4e2d |xi - xj| <= k \u4e14 1 <= i < j <= points.length\u3002

\n\n

\u9898\u76ee\u6d4b\u8bd5\u6570\u636e\u4fdd\u8bc1\u81f3\u5c11\u5b58\u5728\u4e00\u5bf9\u80fd\u591f\u6ee1\u8db3 |xi - xj| <= k \u7684\u70b9\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1apoints = [[1,3],[2,0],[5,10],[6,-10]], k = 1\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u524d\u4e24\u4e2a\u70b9\u6ee1\u8db3 |xi - xj| <= 1 \uff0c\u4ee3\u5165\u65b9\u7a0b\u8ba1\u7b97\uff0c\u5219\u5f97\u5230\u503c 3 + 0 + |1 - 2| = 4 \u3002\u7b2c\u4e09\u4e2a\u548c\u7b2c\u56db\u4e2a\u70b9\u4e5f\u6ee1\u8db3\u6761\u4ef6\uff0c\u5f97\u5230\u503c 10 + -10 + |5 - 6| = 1 \u3002\n\u6ca1\u6709\u5176\u4ed6\u6ee1\u8db3\u6761\u4ef6\u7684\u70b9\uff0c\u6240\u4ee5\u8fd4\u56de 4 \u548c 1 \u4e2d\u6700\u5927\u7684\u90a3\u4e2a\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1apoints = [[0,0],[3,0],[9,2]], k = 3\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u53ea\u6709\u524d\u4e24\u4e2a\u70b9\u6ee1\u8db3 |xi - xj| <= 3 \uff0c\u4ee3\u5165\u65b9\u7a0b\u540e\u5f97\u5230\u503c 0 + 0 + |0 - 3| = 3 \u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= points.length <= 10^5
  • \n\t
  • points[i].length == 2
  • \n\t
  • -10^8 <= points[i][0], points[i][1] <= 10^8
  • \n\t
  • 0 <= k <= 2 * 10^8
  • \n\t
  • \u5bf9\u4e8e\u6240\u6709\u76841 <= i < j <= points.length \uff0cpoints[i][0] < points[j][0] \u90fd\u6210\u7acb\u3002\u4e5f\u5c31\u662f\u8bf4\uff0cxi \u662f\u4e25\u683c\u9012\u589e\u7684\u3002
  • \n
\n", "tags_en": ["Array", "Sliding Window"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findMaxValueOfEquation(vector>& points, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findMaxValueOfEquation(int[][] points, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findMaxValueOfEquation(self, points, k):\n \"\"\"\n :type points: List[List[int]]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findMaxValueOfEquation(self, points: List[List[int]], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findMaxValueOfEquation(int** points, int pointsSize, int* pointsColSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindMaxValueOfEquation(int[][] points, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} points\n * @param {number} k\n * @return {number}\n */\nvar findMaxValueOfEquation = function(points, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} points\n# @param {Integer} k\n# @return {Integer}\ndef find_max_value_of_equation(points, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findMaxValueOfEquation(_ points: [[Int]], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findMaxValueOfEquation(points [][]int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findMaxValueOfEquation(points: Array[Array[Int]], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findMaxValueOfEquation(points: Array, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_max_value_of_equation(points: Vec>, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $points\n * @param Integer $k\n * @return Integer\n */\n function findMaxValueOfEquation($points, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findMaxValueOfEquation(points: number[][], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-max-value-of-equation points k)\n (-> (listof (listof exact-integer?)) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1499](https://leetcode-cn.com/problems/max-value-of-equation)", "[\u6ee1\u8db3\u4e0d\u7b49\u5f0f\u7684\u6700\u5927\u503c](/solution/1400-1499/1499.Max%20Value%20of%20Equation/README.md)", "`\u6570\u7ec4`", "\u56f0\u96be", ""], "md_table_row_en": ["[1499](https://leetcode.com/problems/max-value-of-equation)", "[Max Value of Equation](/solution/1400-1499/1499.Max%20Value%20of%20Equation/README_EN.md)", "`Array`,`Sliding Window`", "Hard", ""]}, {"question_id": "1621", "frontend_question_id": "1498", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-subsequences-that-satisfy-the-given-sum-condition", "url_en": "https://leetcode.com/problems/number-of-subsequences-that-satisfy-the-given-sum-condition", "relative_path_cn": "/solution/1400-1499/1498.Number%20of%20Subsequences%20That%20Satisfy%20the%20Given%20Sum%20Condition/README.md", "relative_path_en": "/solution/1400-1499/1498.Number%20of%20Subsequences%20That%20Satisfy%20the%20Given%20Sum%20Condition/README_EN.md", "title_cn": "\u6ee1\u8db3\u6761\u4ef6\u7684\u5b50\u5e8f\u5217\u6570\u76ee", "title_en": "Number of Subsequences That Satisfy the Given Sum Condition", "question_title_slug": "number-of-subsequences-that-satisfy-the-given-sum-condition", "content_en": "

Given an array of integers nums and an integer target.

\n\n

Return the number of non-empty subsequences of nums such that the sum of the minimum and maximum element on it is less or equal to target. Since the answer may be too large, return it modulo 109 + 7.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [3,5,6,7], target = 9\nOutput: 4\nExplanation: There are 4 subsequences that satisfy the condition.\n[3] -> Min value + max value <= target (3 + 3 <= 9)\n[3,5] -> (3 + 5 <= 9)\n[3,5,6] -> (3 + 6 <= 9)\n[3,6] -> (3 + 6 <= 9)\n
\n\n

Example 2:

\n\n
\nInput: nums = [3,3,6,8], target = 10\nOutput: 6\nExplanation: There are 6 subsequences that satisfy the condition. (nums can have repeated numbers).\n[3] , [3] , [3,3], [3,6] , [3,6] , [3,3,6]
\n\n

Example 3:

\n\n
\nInput: nums = [2,3,3,4,6,7], target = 12\nOutput: 61\nExplanation: There are 63 non-empty subsequences, two of them don't satisfy the condition ([6,7], [7]).\nNumber of valid subsequences (63 - 2 = 61).\n
\n\n

Example 4:

\n\n
\nInput: nums = [5,2,4,1,7,6,8], target = 16\nOutput: 127\nExplanation: All non-empty subset satisfy the condition (2^7 - 1) = 127
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 105
  • \n\t
  • 1 <= nums[i] <= 106
  • \n\t
  • 1 <= target <= 106
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \u548c\u4e00\u4e2a\u6574\u6570 target \u3002

\n\n

\u8bf7\u4f60\u7edf\u8ba1\u5e76\u8fd4\u56de nums \u4e2d\u80fd\u6ee1\u8db3\u5176\u6700\u5c0f\u5143\u7d20\u4e0e\u6700\u5927\u5143\u7d20\u7684 \u548c \u5c0f\u4e8e\u6216\u7b49\u4e8e target \u7684 \u975e\u7a7a \u5b50\u5e8f\u5217\u7684\u6570\u76ee\u3002

\n\n

\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u5f88\u5927\uff0c\u8bf7\u5c06\u7ed3\u679c\u5bf9 10^9 + 7 \u53d6\u4f59\u540e\u8fd4\u56de\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anums = [3,5,6,7], target = 9\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u6709 4 \u4e2a\u5b50\u5e8f\u5217\u6ee1\u8db3\u8be5\u6761\u4ef6\u3002\n[3] -> \u6700\u5c0f\u5143\u7d20 + \u6700\u5927\u5143\u7d20 <= target (3 + 3 <= 9)\n[3,5] -> (3 + 5 <= 9)\n[3,5,6] -> (3 + 6 <= 9)\n[3,6] -> (3 + 6 <= 9)\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anums = [3,3,6,8], target = 10\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u6709 6 \u4e2a\u5b50\u5e8f\u5217\u6ee1\u8db3\u8be5\u6761\u4ef6\u3002\uff08nums \u4e2d\u53ef\u4ee5\u6709\u91cd\u590d\u6570\u5b57\uff09\n[3] , [3] , [3,3], [3,6] , [3,6] , [3,3,6]
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1anums = [2,3,3,4,6,7], target = 12\n\u8f93\u51fa\uff1a61\n\u89e3\u91ca\uff1a\u5171\u6709 63 \u4e2a\u975e\u7a7a\u5b50\u5e8f\u5217\uff0c\u5176\u4e2d 2 \u4e2a\u4e0d\u6ee1\u8db3\u6761\u4ef6\uff08[6,7], [7]\uff09\n\u6709\u6548\u5e8f\u5217\u603b\u6570\u4e3a\uff0863 - 2 = 61\uff09\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1anums = [5,2,4,1,7,6,8], target = 16\n\u8f93\u51fa\uff1a127\n\u89e3\u91ca\uff1a\u6240\u6709\u975e\u7a7a\u5b50\u5e8f\u5217\u90fd\u6ee1\u8db3\u6761\u4ef6 (2^7 - 1) = 127
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 10^5
  • \n\t
  • 1 <= nums[i] <= 10^6
  • \n\t
  • 1 <= target <= 10^6
  • \n
\n", "tags_en": ["Sort", "Sliding Window"], "tags_cn": ["\u6392\u5e8f"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numSubseq(vector& nums, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numSubseq(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numSubseq(self, nums, target):\n \"\"\"\n :type nums: List[int]\n :type target: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numSubseq(self, nums: List[int], target: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numSubseq(int* nums, int numsSize, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumSubseq(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} target\n * @return {number}\n */\nvar numSubseq = function(nums, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} target\n# @return {Integer}\ndef num_subseq(nums, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numSubseq(_ nums: [Int], _ target: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numSubseq(nums []int, target int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numSubseq(nums: Array[Int], target: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numSubseq(nums: IntArray, target: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_subseq(nums: Vec, target: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $target\n * @return Integer\n */\n function numSubseq($nums, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numSubseq(nums: number[], target: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-subseq nums target)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1498](https://leetcode-cn.com/problems/number-of-subsequences-that-satisfy-the-given-sum-condition)", "[\u6ee1\u8db3\u6761\u4ef6\u7684\u5b50\u5e8f\u5217\u6570\u76ee](/solution/1400-1499/1498.Number%20of%20Subsequences%20That%20Satisfy%20the%20Given%20Sum%20Condition/README.md)", "`\u6392\u5e8f`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1498](https://leetcode.com/problems/number-of-subsequences-that-satisfy-the-given-sum-condition)", "[Number of Subsequences That Satisfy the Given Sum Condition](/solution/1400-1499/1498.Number%20of%20Subsequences%20That%20Satisfy%20the%20Given%20Sum%20Condition/README_EN.md)", "`Sort`,`Sliding Window`", "Medium", ""]}, {"question_id": "1620", "frontend_question_id": "1497", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/check-if-array-pairs-are-divisible-by-k", "url_en": "https://leetcode.com/problems/check-if-array-pairs-are-divisible-by-k", "relative_path_cn": "/solution/1400-1499/1497.Check%20If%20Array%20Pairs%20Are%20Divisible%20by%20k/README.md", "relative_path_en": "/solution/1400-1499/1497.Check%20If%20Array%20Pairs%20Are%20Divisible%20by%20k/README_EN.md", "title_cn": "\u68c0\u67e5\u6570\u7ec4\u5bf9\u662f\u5426\u53ef\u4ee5\u88ab k \u6574\u9664", "title_en": "Check If Array Pairs Are Divisible by k", "question_title_slug": "check-if-array-pairs-are-divisible-by-k", "content_en": "

Given an array of integers arr of even length n and an integer k.

\n\n

We want to divide the array into exactly n / 2 pairs such that the sum of each pair is divisible by k.

\n\n

Return True If you can find a way to do that or False otherwise.

\n\n

 

\n

Example 1:

\n\n
\nInput: arr = [1,2,3,4,5,10,6,7,8,9], k = 5\nOutput: true\nExplanation: Pairs are (1,9),(2,8),(3,7),(4,6) and (5,10).\n
\n\n

Example 2:

\n\n
\nInput: arr = [1,2,3,4,5,6], k = 7\nOutput: true\nExplanation: Pairs are (1,6),(2,5) and(3,4).\n
\n\n

Example 3:

\n\n
\nInput: arr = [1,2,3,4,5,6], k = 10\nOutput: false\nExplanation: You can try all possible pairs to see that there is no way to divide arr into 3 pairs each with sum divisible by 10.\n
\n\n

Example 4:

\n\n
\nInput: arr = [-10,10], k = 2\nOutput: true\n
\n\n

Example 5:

\n\n
\nInput: arr = [-1,1,-2,2,-3,3,-4,4], k = 3\nOutput: true\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • arr.length == n
  • \n\t
  • 1 <= n <= 105
  • \n\t
  • n is even.
  • \n\t
  • -109 <= arr[i] <= 109
  • \n\t
  • 1 <= k <= 105
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr \u548c\u4e00\u4e2a\u6574\u6570 k \uff0c\u5176\u4e2d\u6570\u7ec4\u957f\u5ea6\u662f\u5076\u6570\uff0c\u503c\u4e3a n \u3002

\n\n

\u73b0\u5728\u9700\u8981\u628a\u6570\u7ec4\u6070\u597d\u5206\u6210 n / 2 \u5bf9\uff0c\u4ee5\u4f7f\u6bcf\u5bf9\u6570\u5b57\u7684\u548c\u90fd\u80fd\u591f\u88ab k \u6574\u9664\u3002

\n\n

\u5982\u679c\u5b58\u5728\u8fd9\u6837\u7684\u5206\u6cd5\uff0c\u8bf7\u8fd4\u56de True \uff1b\u5426\u5219\uff0c\u8fd4\u56de False \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aarr = [1,2,3,4,5,10,6,7,8,9], k = 5\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u5212\u5206\u540e\u7684\u6570\u5b57\u5bf9\u4e3a (1,9),(2,8),(3,7),(4,6) \u4ee5\u53ca (5,10) \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aarr = [1,2,3,4,5,6], k = 7\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u5212\u5206\u540e\u7684\u6570\u5b57\u5bf9\u4e3a (1,6),(2,5) \u4ee5\u53ca (3,4) \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aarr = [1,2,3,4,5,6], k = 10\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u65e0\u6cd5\u5728\u5c06\u6570\u7ec4\u4e2d\u7684\u6570\u5b57\u5206\u4e3a\u4e09\u5bf9\u7684\u540c\u65f6\u6ee1\u8db3\u6bcf\u5bf9\u6570\u5b57\u548c\u80fd\u591f\u88ab 10 \u6574\u9664\u7684\u6761\u4ef6\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1aarr = [-10,10], k = 2\n\u8f93\u51fa\uff1atrue\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1aarr = [-1,1,-2,2,-3,3,-4,4], k = 3\n\u8f93\u51fa\uff1atrue\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • arr.length == n
  • \n\t
  • 1 <= n <= 10^5
  • \n\t
  • n \u4e3a\u5076\u6570
  • \n\t
  • -10^9 <= arr[i] <= 10^9
  • \n\t
  • 1 <= k <= 10^5
  • \n
\n", "tags_en": ["Greedy", "Array", "Math"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u7ec4", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canArrange(vector& arr, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canArrange(int[] arr, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canArrange(self, arr, k):\n \"\"\"\n :type arr: List[int]\n :type k: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canArrange(self, arr: List[int], k: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canArrange(int* arr, int arrSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanArrange(int[] arr, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @param {number} k\n * @return {boolean}\n */\nvar canArrange = function(arr, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @param {Integer} k\n# @return {Boolean}\ndef can_arrange(arr, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canArrange(_ arr: [Int], _ k: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canArrange(arr []int, k int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canArrange(arr: Array[Int], k: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canArrange(arr: IntArray, k: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_arrange(arr: Vec, k: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @param Integer $k\n * @return Boolean\n */\n function canArrange($arr, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canArrange(arr: number[], k: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-arrange arr k)\n (-> (listof exact-integer?) exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1497](https://leetcode-cn.com/problems/check-if-array-pairs-are-divisible-by-k)", "[\u68c0\u67e5\u6570\u7ec4\u5bf9\u662f\u5426\u53ef\u4ee5\u88ab k \u6574\u9664](/solution/1400-1499/1497.Check%20If%20Array%20Pairs%20Are%20Divisible%20by%20k/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u7ec4`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1497](https://leetcode.com/problems/check-if-array-pairs-are-divisible-by-k)", "[Check If Array Pairs Are Divisible by k](/solution/1400-1499/1497.Check%20If%20Array%20Pairs%20Are%20Divisible%20by%20k/README_EN.md)", "`Greedy`,`Array`,`Math`", "Medium", ""]}, {"question_id": "1619", "frontend_question_id": "1496", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/path-crossing", "url_en": "https://leetcode.com/problems/path-crossing", "relative_path_cn": "/solution/1400-1499/1496.Path%20Crossing/README.md", "relative_path_en": "/solution/1400-1499/1496.Path%20Crossing/README_EN.md", "title_cn": "\u5224\u65ad\u8def\u5f84\u662f\u5426\u76f8\u4ea4", "title_en": "Path Crossing", "question_title_slug": "path-crossing", "content_en": "

Given a string path, where path[i] = 'N', 'S', 'E' or 'W', each representing moving one unit north, south, east, or west, respectively. You start at the origin (0, 0) on a 2D plane and walk on the path specified by path.

\n\n

Return true if the path crosses itself at any point, that is, if at any time you are on a location you have previously visited. Return false otherwise.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: path = "NES"\nOutput: false \nExplanation: Notice that the path doesn't cross any point more than once.\n
\n\n

Example 2:

\n\"\"\n
\nInput: path = "NESWW"\nOutput: true\nExplanation: Notice that the path visits the origin twice.
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= path.length <= 104
  • \n\t
  • path[i] is either 'N', 'S', 'E', or 'W'.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 path\uff0c\u5176\u4e2d path[i] \u7684\u503c\u53ef\u4ee5\u662f 'N'\u3001'S'\u3001'E' \u6216\u8005 'W'\uff0c\u5206\u522b\u8868\u793a\u5411\u5317\u3001\u5411\u5357\u3001\u5411\u4e1c\u3001\u5411\u897f\u79fb\u52a8\u4e00\u4e2a\u5355\u4f4d\u3002

\n\n

\u673a\u5668\u4eba\u4ece\u4e8c\u7ef4\u5e73\u9762\u4e0a\u7684\u539f\u70b9 (0, 0) \u5904\u5f00\u59cb\u51fa\u53d1\uff0c\u6309 path \u6240\u6307\u793a\u7684\u8def\u5f84\u884c\u8d70\u3002

\n\n

\u5982\u679c\u8def\u5f84\u5728\u4efb\u4f55\u4f4d\u7f6e\u4e0a\u51fa\u73b0\u76f8\u4ea4\u7684\u60c5\u51b5\uff0c\u4e5f\u5c31\u662f\u8d70\u5230\u4e4b\u524d\u5df2\u7ecf\u8d70\u8fc7\u7684\u4f4d\u7f6e\uff0c\u8bf7\u8fd4\u56de True \uff1b\u5426\u5219\uff0c\u8fd4\u56de False \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1apath = "NES"\n\u8f93\u51fa\uff1afalse \n\u89e3\u91ca\uff1a\u8be5\u8def\u5f84\u6ca1\u6709\u5728\u4efb\u4f55\u4f4d\u7f6e\u76f8\u4ea4\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1apath = "NESWW"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u8be5\u8def\u5f84\u7ecf\u8fc7\u539f\u70b9\u4e24\u6b21\u3002
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= path.length <= 10^4
  • \n\t
  • path \u4ec5\u7531 {'N', 'S', 'E', 'W} \u4e2d\u7684\u5b57\u7b26\u7ec4\u6210
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isPathCrossing(string path) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isPathCrossing(String path) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isPathCrossing(self, path):\n \"\"\"\n :type path: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isPathCrossing(self, path: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isPathCrossing(char * path){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsPathCrossing(string path) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} path\n * @return {boolean}\n */\nvar isPathCrossing = function(path) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} path\n# @return {Boolean}\ndef is_path_crossing(path)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isPathCrossing(_ path: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isPathCrossing(path string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isPathCrossing(path: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isPathCrossing(path: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_path_crossing(path: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $path\n * @return Boolean\n */\n function isPathCrossing($path) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isPathCrossing(path: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-path-crossing path)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1496](https://leetcode-cn.com/problems/path-crossing)", "[\u5224\u65ad\u8def\u5f84\u662f\u5426\u76f8\u4ea4](/solution/1400-1499/1496.Path%20Crossing/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1496](https://leetcode.com/problems/path-crossing)", "[Path Crossing](/solution/1400-1499/1496.Path%20Crossing/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1618", "frontend_question_id": "1474", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/delete-n-nodes-after-m-nodes-of-a-linked-list", "url_en": "https://leetcode.com/problems/delete-n-nodes-after-m-nodes-of-a-linked-list", "relative_path_cn": "/solution/1400-1499/1474.Delete%20N%20Nodes%20After%20M%20Nodes%20of%20a%20Linked%20List/README.md", "relative_path_en": "/solution/1400-1499/1474.Delete%20N%20Nodes%20After%20M%20Nodes%20of%20a%20Linked%20List/README_EN.md", "title_cn": "\u5220\u9664\u94fe\u8868 M \u4e2a\u8282\u70b9\u4e4b\u540e\u7684 N \u4e2a\u8282\u70b9", "title_en": "Delete N Nodes After M Nodes of a Linked List", "question_title_slug": "delete-n-nodes-after-m-nodes-of-a-linked-list", "content_en": "

Given the head of a linked list and two integers m and n. Traverse the linked list and remove some nodes in the following way:

\r\n\r\n
    \r\n\t
  • Start with the head as the current node.
  • \r\n\t
  • Keep the first m nodes starting with the current node.
  • \r\n\t
  • Remove the next n nodes
  • \r\n\t
  • Keep repeating steps 2 and 3 until you reach the end of the list.
  • \r\n
\r\n\r\n

Return the head of the modified list after removing the mentioned nodes.

\r\n\r\n

Follow up question: How can you solve this problem by modifying the list in-place?

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n

\"\"

\r\n\r\n
\r\nInput: head = [1,2,3,4,5,6,7,8,9,10,11,12,13], m = 2, n = 3\r\nOutput: [1,2,6,7,11,12]\r\nExplanation: Keep the first (m = 2) nodes starting from the head of the linked List  (1 ->2) show in black nodes.\r\nDelete the next (n = 3) nodes (3 -> 4 -> 5) show in read nodes.\r\nContinue with the same procedure until reaching the tail of the Linked List.\r\nHead of linked list after removing nodes is returned.
\r\n\r\n

Example 2:

\r\n\r\n

\"\"

\r\n\r\n
\r\nInput: head = [1,2,3,4,5,6,7,8,9,10,11], m = 1, n = 3\r\nOutput: [1,5,9]\r\nExplanation: Head of linked list after removing nodes is returned.
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: head = [1,2,3,4,5,6,7,8,9,10,11], m = 3, n = 1\r\nOutput: [1,2,3,5,6,7,9,10,11]\r\n
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: head = [9,3,7,7,9,10,8,2], m = 1, n = 2\r\nOutput: [9,7,8]\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • The given linked list will contain between 1 and 10^4 nodes.
  • \r\n\t
  • The value of each node in the linked list will be in the range [1, 10^6].
  • \r\n\t
  • 1 <= m,n <= 1000
  • \r\n
", "content_cn": "

\u7ed9\u5b9a\u94fe\u8868\u00a0head\u00a0\u548c\u4e24\u4e2a\u6574\u6570\u00a0m\u00a0\u548c\u00a0n. \u904d\u5386\u8be5\u94fe\u8868\u5e76\u6309\u7167\u5982\u4e0b\u65b9\u5f0f\u5220\u9664\u8282\u70b9:

\n\n
    \n\t
  • \u5f00\u59cb\u65f6\u4ee5\u5934\u8282\u70b9\u4f5c\u4e3a\u5f53\u524d\u8282\u70b9.
  • \n\t
  • \u4fdd\u7559\u4ee5\u5f53\u524d\u8282\u70b9\u5f00\u59cb\u7684\u524d\u00a0m\u00a0\u4e2a\u8282\u70b9.
  • \n\t
  • \u5220\u9664\u63a5\u4e0b\u6765\u7684\u00a0n\u00a0\u4e2a\u8282\u70b9.
  • \n\t
  • \u91cd\u590d\u6b65\u9aa4 2 \u548c 3,\u00a0\u76f4\u5230\u5230\u8fbe\u94fe\u8868\u7ed3\u5c3e.
  • \n
\n\n

\u5728\u5220\u9664\u4e86\u6307\u5b9a\u7ed3\u70b9\u4e4b\u540e,\u00a0\u8fd4\u56de\u4fee\u6539\u8fc7\u540e\u7684\u94fe\u8868\u7684\u5934\u8282\u70b9.

\n\n

\u8fdb\u9636\u95ee\u9898: \u4f60\u80fd\u901a\u8fc7\u5c31\u5730\u4fee\u6539\u94fe\u8868\u7684\u65b9\u5f0f\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u5417?

\n\n

\u00a0

\n\n

\u793a\u4f8b 1:

\n\n

\"\"

\n\n
\n\u8f93\u5165: head = [1,2,3,4,5,6,7,8,9,10,11,12,13], m = 2, n = 3\n\u8f93\u51fa: [1,2,6,7,11,12]\n\u89e3\u6790: \u4fdd\u7559\u524d(m = 2)\u4e2a\u7ed3\u70b9,  \u4e5f\u5c31\u662f\u4ee5\u9ed1\u8272\u8282\u70b9\u8868\u793a\u7684\u4ece\u94fe\u8868\u5934\u7ed3\u70b9\u5f00\u59cb\u7684\u7ed3\u70b9(1 ->2).\n\u5220\u9664\u63a5\u4e0b\u6765\u7684(n = 3)\u4e2a\u7ed3\u70b9(3 -> 4 -> 5), \u5728\u56fe\u4e2d\u4ee5\u7ea2\u8272\u7ed3\u70b9\u8868\u793a.\n\u7ee7\u7eed\u76f8\u540c\u7684\u64cd\u4f5c, \u76f4\u5230\u94fe\u8868\u7684\u672b\u5c3e.\n\u8fd4\u56de\u5220\u9664\u7ed3\u70b9\u4e4b\u540e\u7684\u94fe\u8868\u7684\u5934\u7ed3\u70b9.
\n\n

\u793a\u4f8b 2:

\n\n

\"\"

\n\n
\n\u8f93\u5165: head = [1,2,3,4,5,6,7,8,9,10,11], m = 1, n = 3\n\u8f93\u51fa: [1,5,9]\n\u89e3\u6790: \u8fd4\u56de\u5220\u9664\u7ed3\u70b9\u4e4b\u540e\u7684\u94fe\u8868\u7684\u5934\u7ed3\u70b9.
\n\n

\u793a\u4f8b 3:

\n\n
\n\u8f93\u5165: head = [1,2,3,4,5,6,7,8,9,10,11], m = 3, n = 1\n\u8f93\u51fa: [1,2,3,5,6,7,9,10,11]\n
\n\n

\u793a\u4f8b\u00a04:

\n\n
\n\u8f93\u5165: head = [9,3,7,7,9,10,8,2], m = 1, n = 2\n\u8f93\u51fa: [9,7,8]\n
\n\n

\u00a0

\n\n

\u63d0\u793a:

\n\n
    \n\t
  • \u00a01 <=\u00a0\u94fe\u8868\u7ed3\u70b9\u6570 <= 10^4
  • \n\t
  • [1 <= \u94fe\u8868\u7684\u6bcf\u4e00\u4e2a\u7ed3\u70b9\u503c <=10^6]
  • \n\t
  • 1 <= m,n <=\u00a01000
  • \n
\n", "tags_en": ["Linked List"], "tags_cn": ["\u94fe\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n ListNode* deleteNodes(ListNode* head, int m, int n) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public ListNode deleteNodes(ListNode head, int m, int n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def deleteNodes(self, head, m, n):\n \"\"\"\n :type head: ListNode\n :type m: int\n :type n: int\n :rtype: ListNode\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def deleteNodes(self, head: ListNode, m: int, n: int) -> ListNode:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nstruct ListNode* deleteNodes(struct ListNode* head, int m, int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public ListNode DeleteNodes(ListNode head, int m, int n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} head\n * @param {number} m\n * @param {number} n\n * @return {ListNode}\n */\nvar deleteNodes = function(head, m, n) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode} head\n# @param {Integer} m\n# @param {Integer} n\n# @return {ListNode}\ndef delete_nodes(head, m, n)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func deleteNodes(_ head: ListNode?, _ m: Int, _ n: Int) -> ListNode? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc deleteNodes(head *ListNode, m int, n int) *ListNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def deleteNodes(head: ListNode, m: Int, n: Int): ListNode = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun deleteNodes(head: ListNode?, m: Int, n: Int): ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn delete_nodes(head: Option>, m: i32, n: i32) -> Option> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @param Integer $m\n * @param Integer $n\n * @return ListNode\n */\n function deleteNodes($head, $m, $n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction deleteNodes(head: ListNode | null, m: number, n: number): ListNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (delete-nodes head m n)\n (-> (or/c list-node? #f) exact-integer? exact-integer? (or/c list-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1474](https://leetcode-cn.com/problems/delete-n-nodes-after-m-nodes-of-a-linked-list)", "[\u5220\u9664\u94fe\u8868 M \u4e2a\u8282\u70b9\u4e4b\u540e\u7684 N \u4e2a\u8282\u70b9](/solution/1400-1499/1474.Delete%20N%20Nodes%20After%20M%20Nodes%20of%20a%20Linked%20List/README.md)", "`\u94fe\u8868`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1474](https://leetcode.com/problems/delete-n-nodes-after-m-nodes-of-a-linked-list)", "[Delete N Nodes After M Nodes of a Linked List](/solution/1400-1499/1474.Delete%20N%20Nodes%20After%20M%20Nodes%20of%20a%20Linked%20List/README_EN.md)", "`Linked List`", "Easy", "\ud83d\udd12"]}, {"question_id": "1617", "frontend_question_id": "1510", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/stone-game-iv", "url_en": "https://leetcode.com/problems/stone-game-iv", "relative_path_cn": "/solution/1500-1599/1510.Stone%20Game%20IV/README.md", "relative_path_en": "/solution/1500-1599/1510.Stone%20Game%20IV/README_EN.md", "title_cn": "\u77f3\u5b50\u6e38\u620f IV", "title_en": "Stone Game IV", "question_title_slug": "stone-game-iv", "content_en": "

Alice and Bob take turns playing a game, with Alice starting first.

\n\n

Initially, there are n stones in a pile.  On each player's turn, that player makes a move consisting of removing any non-zero square number of stones in the pile.

\n\n

Also, if a player cannot make a move, he/she loses the game.

\n\n

Given a positive integer n. Return True if and only if Alice wins the game otherwise return False, assuming both players play optimally.

\n\n

 

\n

Example 1:

\n\n
\nInput: n = 1\nOutput: true\nExplanation: Alice can remove 1 stone winning the game because Bob doesn't have any moves.
\n\n

Example 2:

\n\n
\nInput: n = 2\nOutput: false\nExplanation: Alice can only remove 1 stone, after that Bob removes the last one winning the game (2 -> 1 -> 0).
\n\n

Example 3:

\n\n
\nInput: n = 4\nOutput: true\nExplanation: n is already a perfect square, Alice can win with one move, removing 4 stones (4 -> 0).\n
\n\n

Example 4:

\n\n
\nInput: n = 7\nOutput: false\nExplanation: Alice can't win the game if Bob plays optimally.\nIf Alice starts removing 4 stones, Bob will remove 1 stone then Alice should remove only 1 stone and finally Bob removes the last one (7 -> 3 -> 2 -> 1 -> 0). \nIf Alice starts removing 1 stone, Bob will remove 4 stones then Alice only can remove 1 stone and finally Bob removes the last one (7 -> 6 -> 2 -> 1 -> 0).
\n\n

Example 5:

\n\n
\nInput: n = 17\nOutput: false\nExplanation: Alice can't win the game if Bob plays optimally.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 10^5
  • \n
\n", "content_cn": "

Alice \u548c Bob \u4e24\u4e2a\u4eba\u8f6e\u6d41\u73a9\u4e00\u4e2a\u6e38\u620f\uff0cAlice \u5148\u624b\u3002

\n\n

\u4e00\u5f00\u59cb\uff0c\u6709 n \u4e2a\u77f3\u5b50\u5806\u5728\u4e00\u8d77\u3002\u6bcf\u4e2a\u4eba\u8f6e\u6d41\u64cd\u4f5c\uff0c\u6b63\u5728\u64cd\u4f5c\u7684\u73a9\u5bb6\u53ef\u4ee5\u4ece\u77f3\u5b50\u5806\u91cc\u62ff\u8d70 \u4efb\u610f \u975e\u96f6 \u5e73\u65b9\u6570 \u4e2a\u77f3\u5b50\u3002

\n\n

\u5982\u679c\u77f3\u5b50\u5806\u91cc\u6ca1\u6709\u77f3\u5b50\u4e86\uff0c\u5219\u65e0\u6cd5\u64cd\u4f5c\u7684\u73a9\u5bb6\u8f93\u6389\u6e38\u620f\u3002

\n\n

\u7ed9\u4f60\u6b63\u6574\u6570 n \uff0c\u4e14\u5df2\u77e5\u4e24\u4e2a\u4eba\u90fd\u91c7\u53d6\u6700\u4f18\u7b56\u7565\u3002\u5982\u679c Alice \u4f1a\u8d62\u5f97\u6bd4\u8d5b\uff0c\u90a3\u4e48\u8fd4\u56de True \uff0c\u5426\u5219\u8fd4\u56de False \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1aAlice \u62ff\u8d70 1 \u4e2a\u77f3\u5b50\u5e76\u8d62\u5f97\u80dc\u5229\uff0c\u56e0\u4e3a Bob \u65e0\u6cd5\u8fdb\u884c\u4efb\u4f55\u64cd\u4f5c\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1an = 2\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1aAlice \u53ea\u80fd\u62ff\u8d70 1 \u4e2a\u77f3\u5b50\uff0c\u7136\u540e Bob \u62ff\u8d70\u6700\u540e\u4e00\u4e2a\u77f3\u5b50\u5e76\u8d62\u5f97\u80dc\u5229\uff082 -> 1 -> 0\uff09\u3002
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1an = 4\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1an \u5df2\u7ecf\u662f\u4e00\u4e2a\u5e73\u65b9\u6570\uff0cAlice \u53ef\u4ee5\u4e00\u6b21\u5168\u62ff\u6389 4 \u4e2a\u77f3\u5b50\u5e76\u8d62\u5f97\u80dc\u5229\uff084 -> 0\uff09\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1an = 7\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u5f53 Bob \u91c7\u53d6\u6700\u4f18\u7b56\u7565\u65f6\uff0cAlice \u65e0\u6cd5\u8d62\u5f97\u6bd4\u8d5b\u3002\n\u5982\u679c Alice \u4e00\u5f00\u59cb\u62ff\u8d70 4 \u4e2a\u77f3\u5b50\uff0c Bob \u4f1a\u62ff\u8d70 1 \u4e2a\u77f3\u5b50\uff0c\u7136\u540e Alice \u53ea\u80fd\u62ff\u8d70 1 \u4e2a\u77f3\u5b50\uff0cBob \u62ff\u8d70\u6700\u540e\u4e00\u4e2a\u77f3\u5b50\u5e76\u8d62\u5f97\u80dc\u5229\uff087 -> 3 -> 2 -> 1 -> 0\uff09\u3002\n\u5982\u679c Alice \u4e00\u5f00\u59cb\u62ff\u8d70 1 \u4e2a\u77f3\u5b50\uff0c Bob \u4f1a\u62ff\u8d70 4 \u4e2a\u77f3\u5b50\uff0c\u7136\u540e Alice \u53ea\u80fd\u62ff\u8d70 1 \u4e2a\u77f3\u5b50\uff0cBob \u62ff\u8d70\u6700\u540e\u4e00\u4e2a\u77f3\u5b50\u5e76\u8d62\u5f97\u80dc\u5229\uff087 -> 6 -> 2 -> 1 -> 0\uff09\u3002
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\n\u8f93\u5165\uff1an = 17\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u5982\u679c Bob \u91c7\u53d6\u6700\u4f18\u7b56\u7565\uff0cAlice \u65e0\u6cd5\u8d62\u5f97\u80dc\u5229\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 10^5
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool winnerSquareGame(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean winnerSquareGame(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def winnerSquareGame(self, n):\n \"\"\"\n :type n: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def winnerSquareGame(self, n: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool winnerSquareGame(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool WinnerSquareGame(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {boolean}\n */\nvar winnerSquareGame = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Boolean}\ndef winner_square_game(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func winnerSquareGame(_ n: Int) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func winnerSquareGame(n int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def winnerSquareGame(n: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun winnerSquareGame(n: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn winner_square_game(n: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Boolean\n */\n function winnerSquareGame($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function winnerSquareGame(n: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (winner-square-game n)\n (-> exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1510](https://leetcode-cn.com/problems/stone-game-iv)", "[\u77f3\u5b50\u6e38\u620f IV](/solution/1500-1599/1510.Stone%20Game%20IV/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1510](https://leetcode.com/problems/stone-game-iv)", "[Stone Game IV](/solution/1500-1599/1510.Stone%20Game%20IV/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1616", "frontend_question_id": "1509", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-difference-between-largest-and-smallest-value-in-three-moves", "url_en": "https://leetcode.com/problems/minimum-difference-between-largest-and-smallest-value-in-three-moves", "relative_path_cn": "/solution/1500-1599/1509.Minimum%20Difference%20Between%20Largest%20and%20Smallest%20Value%20in%20Three%20Moves/README.md", "relative_path_en": "/solution/1500-1599/1509.Minimum%20Difference%20Between%20Largest%20and%20Smallest%20Value%20in%20Three%20Moves/README_EN.md", "title_cn": "\u4e09\u6b21\u64cd\u4f5c\u540e\u6700\u5927\u503c\u4e0e\u6700\u5c0f\u503c\u7684\u6700\u5c0f\u5dee", "title_en": "Minimum Difference Between Largest and Smallest Value in Three Moves", "question_title_slug": "minimum-difference-between-largest-and-smallest-value-in-three-moves", "content_en": "

Given an array nums, you are allowed to choose one element of nums and change it by any value in one move.

\r\n\r\n

Return the minimum difference between the largest and smallest value of nums after perfoming at most 3 moves.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: nums = [5,3,2,4]\r\nOutput: 0\r\nExplanation: Change the array [5,3,2,4] to [2,2,2,2].\r\nThe difference between the maximum and minimum is 2-2 = 0.
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: nums = [1,5,0,10,14]\r\nOutput: 1\r\nExplanation: Change the array [1,5,0,10,14] to [1,1,0,1,1]. \r\nThe difference between the maximum and minimum is 1-0 = 1.\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: nums = [6,6,0,1,1,4,6]\r\nOutput: 2\r\n
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: nums = [1,5,6,14,15]\r\nOutput: 1\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= nums.length <= 10^5
  • \r\n\t
  • -10^9 <= nums[i] <= 10^9
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 nums \uff0c\u6bcf\u6b21\u64cd\u4f5c\u4f60\u53ef\u4ee5\u9009\u62e9 nums \u4e2d\u7684\u4efb\u610f\u4e00\u4e2a\u5143\u7d20\u5e76\u5c06\u5b83\u6539\u6210\u4efb\u610f\u503c\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u4e09\u6b21\u64cd\u4f5c\u540e\uff0c nums \u4e2d\u6700\u5927\u503c\u4e0e\u6700\u5c0f\u503c\u7684\u5dee\u7684\u6700\u5c0f\u503c\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anums = [5,3,2,4]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u5c06\u6570\u7ec4 [5,3,2,4] \u53d8\u6210 [2,2,2,2].\n\u6700\u5927\u503c\u4e0e\u6700\u5c0f\u503c\u7684\u5dee\u4e3a 2-2 = 0 \u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,5,0,10,14]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u5c06\u6570\u7ec4 [1,5,0,10,14] \u53d8\u6210 [1,1,0,1,1] \u3002\n\u6700\u5927\u503c\u4e0e\u6700\u5c0f\u503c\u7684\u5dee\u4e3a 1-0 = 1 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1anums = [6,6,0,1,1,4,6]\n\u8f93\u51fa\uff1a2\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,5,6,14,15]\n\u8f93\u51fa\uff1a1\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 10^5
  • \n\t
  • -10^9 <= nums[i] <= 10^9
  • \n
\n", "tags_en": ["Sort", "Array"], "tags_cn": ["\u6392\u5e8f", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minDifference(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minDifference(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minDifference(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minDifference(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minDifference(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinDifference(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar minDifference = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef min_difference(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minDifference(_ nums: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minDifference(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minDifference(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minDifference(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_difference(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function minDifference($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minDifference(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-difference nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1509](https://leetcode-cn.com/problems/minimum-difference-between-largest-and-smallest-value-in-three-moves)", "[\u4e09\u6b21\u64cd\u4f5c\u540e\u6700\u5927\u503c\u4e0e\u6700\u5c0f\u503c\u7684\u6700\u5c0f\u5dee](/solution/1500-1599/1509.Minimum%20Difference%20Between%20Largest%20and%20Smallest%20Value%20in%20Three%20Moves/README.md)", "`\u6392\u5e8f`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1509](https://leetcode.com/problems/minimum-difference-between-largest-and-smallest-value-in-three-moves)", "[Minimum Difference Between Largest and Smallest Value in Three Moves](/solution/1500-1599/1509.Minimum%20Difference%20Between%20Largest%20and%20Smallest%20Value%20in%20Three%20Moves/README_EN.md)", "`Sort`,`Array`", "Medium", ""]}, {"question_id": "1615", "frontend_question_id": "1508", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/range-sum-of-sorted-subarray-sums", "url_en": "https://leetcode.com/problems/range-sum-of-sorted-subarray-sums", "relative_path_cn": "/solution/1500-1599/1508.Range%20Sum%20of%20Sorted%20Subarray%20Sums/README.md", "relative_path_en": "/solution/1500-1599/1508.Range%20Sum%20of%20Sorted%20Subarray%20Sums/README_EN.md", "title_cn": "\u5b50\u6570\u7ec4\u548c\u6392\u5e8f\u540e\u7684\u533a\u95f4\u548c", "title_en": "Range Sum of Sorted Subarray Sums", "question_title_slug": "range-sum-of-sorted-subarray-sums", "content_en": "

Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers.

\n\n

Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the new array. Since the answer can be a huge number return it modulo 10^9 + 7.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [1,2,3,4], n = 4, left = 1, right = 5\nOutput: 13 \nExplanation: All subarray sums are 1, 3, 6, 10, 2, 5, 9, 3, 7, 4. After sorting them in non-decreasing order we have the new array [1, 2, 3, 3, 4, 5, 6, 7, 9, 10]. The sum of the numbers from index le = 1 to ri = 5 is 1 + 2 + 3 + 3 + 4 = 13. \n
\n\n

Example 2:

\n\n
\nInput: nums = [1,2,3,4], n = 4, left = 3, right = 4\nOutput: 6\nExplanation: The given array is the same as example 1. We have the new array [1, 2, 3, 3, 4, 5, 6, 7, 9, 10]. The sum of the numbers from index le = 3 to ri = 4 is 3 + 3 = 6.\n
\n\n

Example 3:

\n\n
\nInput: nums = [1,2,3,4], n = 4, left = 1, right = 10\nOutput: 50\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 10^3
  • \n\t
  • nums.length == n
  • \n\t
  • 1 <= nums[i] <= 100
  • \n\t
  • 1 <= left <= right <= n * (n + 1) / 2
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 nums \uff0c\u5b83\u5305\u542b n \u4e2a\u6b63\u6574\u6570\u3002\u4f60\u9700\u8981\u8ba1\u7b97\u6240\u6709\u975e\u7a7a\u8fde\u7eed\u5b50\u6570\u7ec4\u7684\u548c\uff0c\u5e76\u5c06\u5b83\u4eec\u6309\u5347\u5e8f\u6392\u5e8f\uff0c\u5f97\u5230\u4e00\u4e2a\u65b0\u7684\u5305\u542b n * (n + 1) / 2 \u4e2a\u6570\u5b57\u7684\u6570\u7ec4\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u5728\u65b0\u6570\u7ec4\u4e2d\u4e0b\u6807\u4e3a left \u5230 right \uff08\u4e0b\u6807\u4ece 1 \u5f00\u59cb\uff09\u7684\u6240\u6709\u6570\u5b57\u548c\uff08\u5305\u62ec\u5de6\u53f3\u7aef\u70b9\uff09\u3002\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u5f88\u5927\uff0c\u8bf7\u4f60\u5c06\u5b83\u5bf9 10^9 + 7 \u53d6\u6a21\u540e\u8fd4\u56de\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [1,2,3,4], n = 4, left = 1, right = 5\n\u8f93\u51fa\uff1a13 \n\u89e3\u91ca\uff1a\u6240\u6709\u7684\u5b50\u6570\u7ec4\u548c\u4e3a 1, 3, 6, 10, 2, 5, 9, 3, 7, 4 \u3002\u5c06\u5b83\u4eec\u5347\u5e8f\u6392\u5e8f\u540e\uff0c\u6211\u4eec\u5f97\u5230\u65b0\u7684\u6570\u7ec4 [1, 2, 3, 3, 4, 5, 6, 7, 9, 10] \u3002\u4e0b\u6807\u4ece le = 1 \u5230 ri = 5 \u7684\u548c\u4e3a 1 + 2 + 3 + 3 + 4 = 13 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [1,2,3,4], n = 4, left = 3, right = 4\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u7ed9\u5b9a\u6570\u7ec4\u4e0e\u793a\u4f8b 1 \u4e00\u6837\uff0c\u6240\u4ee5\u65b0\u6570\u7ec4\u4e3a [1, 2, 3, 3, 4, 5, 6, 7, 9, 10] \u3002\u4e0b\u6807\u4ece le = 3 \u5230 ri = 4 \u7684\u548c\u4e3a 3 + 3 = 6 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [1,2,3,4], n = 4, left = 1, right = 10\n\u8f93\u51fa\uff1a50\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 10^3
  • \n\t
  • nums.length == n
  • \n\t
  • 1 <= nums[i] <= 100
  • \n\t
  • 1 <= left <= right <= n * (n + 1) / 2
  • \n
\n", "tags_en": ["Sort", "Array"], "tags_cn": ["\u6392\u5e8f", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int rangeSum(vector& nums, int n, int left, int right) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int rangeSum(int[] nums, int n, int left, int right) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def rangeSum(self, nums, n, left, right):\n \"\"\"\n :type nums: List[int]\n :type n: int\n :type left: int\n :type right: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint rangeSum(int* nums, int numsSize, int n, int left, int right){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int RangeSum(int[] nums, int n, int left, int right) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} n\n * @param {number} left\n * @param {number} right\n * @return {number}\n */\nvar rangeSum = function(nums, n, left, right) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} n\n# @param {Integer} left\n# @param {Integer} right\n# @return {Integer}\ndef range_sum(nums, n, left, right)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func rangeSum(_ nums: [Int], _ n: Int, _ left: Int, _ right: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func rangeSum(nums []int, n int, left int, right int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def rangeSum(nums: Array[Int], n: Int, left: Int, right: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun rangeSum(nums: IntArray, n: Int, left: Int, right: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn range_sum(nums: Vec, n: i32, left: i32, right: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $n\n * @param Integer $left\n * @param Integer $right\n * @return Integer\n */\n function rangeSum($nums, $n, $left, $right) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function rangeSum(nums: number[], n: number, left: number, right: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (range-sum nums n left right)\n (-> (listof exact-integer?) exact-integer? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1508](https://leetcode-cn.com/problems/range-sum-of-sorted-subarray-sums)", "[\u5b50\u6570\u7ec4\u548c\u6392\u5e8f\u540e\u7684\u533a\u95f4\u548c](/solution/1500-1599/1508.Range%20Sum%20of%20Sorted%20Subarray%20Sums/README.md)", "`\u6392\u5e8f`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1508](https://leetcode.com/problems/range-sum-of-sorted-subarray-sums)", "[Range Sum of Sorted Subarray Sums](/solution/1500-1599/1508.Range%20Sum%20of%20Sorted%20Subarray%20Sums/README_EN.md)", "`Sort`,`Array`", "Medium", ""]}, {"question_id": "1613", "frontend_question_id": "1489", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree", "url_en": "https://leetcode.com/problems/find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree", "relative_path_cn": "/solution/1400-1499/1489.Find%20Critical%20and%20Pseudo-Critical%20Edges%20in%20Minimum%20Spanning%20Tree/README.md", "relative_path_en": "/solution/1400-1499/1489.Find%20Critical%20and%20Pseudo-Critical%20Edges%20in%20Minimum%20Spanning%20Tree/README_EN.md", "title_cn": "\u627e\u5230\u6700\u5c0f\u751f\u6210\u6811\u91cc\u7684\u5173\u952e\u8fb9\u548c\u4f2a\u5173\u952e\u8fb9", "title_en": "Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree", "question_title_slug": "find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree", "content_en": "

Given a weighted undirected connected graph with n vertices numbered from 0 to n - 1, and an array edges where edges[i] = [ai, bi, weighti] represents a bidirectional and weighted edge between nodes ai and bi. A minimum spanning tree (MST) is a subset of the graph's edges that connects all vertices without cycles and with the minimum possible total edge weight.

\n\n

Find all the critical and pseudo-critical edges in the given graph's minimum spanning tree (MST). An MST edge whose deletion from the graph would cause the MST weight to increase is called a critical edge. On the other hand, a pseudo-critical edge is that which can appear in some MSTs but not all.

\n\n

Note that you can return the indices of the edges in any order.

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: n = 5, edges = [[0,1,1],[1,2,1],[2,3,2],[0,3,2],[0,4,3],[3,4,3],[1,4,6]]\nOutput: [[0,1],[2,3,4,5]]\nExplanation: The figure above describes the graph.\nThe following figure shows all the possible MSTs:\n\"\"\nNotice that the two edges 0 and 1 appear in all MSTs, therefore they are critical edges, so we return them in the first list of the output.\nThe edges 2, 3, 4, and 5 are only part of some MSTs, therefore they are considered pseudo-critical edges. We add them to the second list of the output.\n
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: n = 4, edges = [[0,1,1],[1,2,1],[2,3,1],[0,3,1]]\nOutput: [[],[0,1,2,3]]\nExplanation: We can observe that since all 4 edges have equal weight, choosing any 3 edges from the given 4 will yield an MST. Therefore all 4 edges are pseudo-critical.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= n <= 100
  • \n\t
  • 1 <= edges.length <= min(200, n * (n - 1) / 2)
  • \n\t
  • edges[i].length == 3
  • \n\t
  • 0 <= ai < bi < n
  • \n\t
  • 1 <= weighti <= 1000
  • \n\t
  • All pairs (ai, bi) are distinct.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a n \u4e2a\u70b9\u7684\u5e26\u6743\u65e0\u5411\u8fde\u901a\u56fe\uff0c\u8282\u70b9\u7f16\u53f7\u4e3a 0 \u5230 n-1 \uff0c\u540c\u65f6\u8fd8\u6709\u4e00\u4e2a\u6570\u7ec4 edges \uff0c\u5176\u4e2d edges[i] = [fromi, toi, weighti] \u8868\u793a\u5728 fromi \u548c toi \u8282\u70b9\u4e4b\u95f4\u6709\u4e00\u6761\u5e26\u6743\u65e0\u5411\u8fb9\u3002\u6700\u5c0f\u751f\u6210\u6811 (MST) \u662f\u7ed9\u5b9a\u56fe\u4e2d\u8fb9\u7684\u4e00\u4e2a\u5b50\u96c6\uff0c\u5b83\u8fde\u63a5\u4e86\u6240\u6709\u8282\u70b9\u4e14\u6ca1\u6709\u73af\uff0c\u800c\u4e14\u8fd9\u4e9b\u8fb9\u7684\u6743\u503c\u548c\u6700\u5c0f\u3002

\n\n

\u8bf7\u4f60\u627e\u5230\u7ed9\u5b9a\u56fe\u4e2d\u6700\u5c0f\u751f\u6210\u6811\u7684\u6240\u6709\u5173\u952e\u8fb9\u548c\u4f2a\u5173\u952e\u8fb9\u3002\u5982\u679c\u4ece\u56fe\u4e2d\u5220\u53bb\u67d0\u6761\u8fb9\uff0c\u4f1a\u5bfc\u81f4\u6700\u5c0f\u751f\u6210\u6811\u7684\u6743\u503c\u548c\u589e\u52a0\uff0c\u90a3\u4e48\u6211\u4eec\u5c31\u8bf4\u5b83\u662f\u4e00\u6761\u5173\u952e\u8fb9\u3002\u4f2a\u5173\u952e\u8fb9\u5219\u662f\u53ef\u80fd\u4f1a\u51fa\u73b0\u5728\u67d0\u4e9b\u6700\u5c0f\u751f\u6210\u6811\u4e2d\u4f46\u4e0d\u4f1a\u51fa\u73b0\u5728\u6240\u6709\u6700\u5c0f\u751f\u6210\u6811\u4e2d\u7684\u8fb9\u3002

\n\n

\u8bf7\u6ce8\u610f\uff0c\u4f60\u53ef\u4ee5\u5206\u522b\u4ee5\u4efb\u610f\u987a\u5e8f\u8fd4\u56de\u5173\u952e\u8fb9\u7684\u4e0b\u6807\u548c\u4f2a\u5173\u952e\u8fb9\u7684\u4e0b\u6807\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1an = 5, edges = [[0,1,1],[1,2,1],[2,3,2],[0,3,2],[0,4,3],[3,4,3],[1,4,6]]\n\u8f93\u51fa\uff1a[[0,1],[2,3,4,5]]\n\u89e3\u91ca\uff1a\u4e0a\u56fe\u63cf\u8ff0\u4e86\u7ed9\u5b9a\u56fe\u3002\n\u4e0b\u56fe\u662f\u6240\u6709\u7684\u6700\u5c0f\u751f\u6210\u6811\u3002\n\"\"\n\u6ce8\u610f\u5230\u7b2c 0 \u6761\u8fb9\u548c\u7b2c 1 \u6761\u8fb9\u51fa\u73b0\u5728\u4e86\u6240\u6709\u6700\u5c0f\u751f\u6210\u6811\u4e2d\uff0c\u6240\u4ee5\u5b83\u4eec\u662f\u5173\u952e\u8fb9\uff0c\u6211\u4eec\u5c06\u8fd9\u4e24\u4e2a\u4e0b\u6807\u4f5c\u4e3a\u8f93\u51fa\u7684\u7b2c\u4e00\u4e2a\u5217\u8868\u3002\n\u8fb9 2\uff0c3\uff0c4 \u548c 5 \u662f\u6240\u6709 MST \u7684\u5269\u4f59\u8fb9\uff0c\u6240\u4ee5\u5b83\u4eec\u662f\u4f2a\u5173\u952e\u8fb9\u3002\u6211\u4eec\u5c06\u5b83\u4eec\u4f5c\u4e3a\u8f93\u51fa\u7684\u7b2c\u4e8c\u4e2a\u5217\u8868\u3002\n
\n\n

\u793a\u4f8b 2 \uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1an = 4, edges = [[0,1,1],[1,2,1],[2,3,1],[0,3,1]]\n\u8f93\u51fa\uff1a[[],[0,1,2,3]]\n\u89e3\u91ca\uff1a\u53ef\u4ee5\u89c2\u5bdf\u5230 4 \u6761\u8fb9\u90fd\u6709\u76f8\u540c\u7684\u6743\u503c\uff0c\u4efb\u9009\u5b83\u4eec\u4e2d\u7684 3 \u6761\u53ef\u4ee5\u5f62\u6210\u4e00\u68f5 MST \u3002\u6240\u4ee5 4 \u6761\u8fb9\u90fd\u662f\u4f2a\u5173\u952e\u8fb9\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= n <= 100
  • \n\t
  • 1 <= edges.length <= min(200, n * (n - 1) / 2)
  • \n\t
  • edges[i].length == 3
  • \n\t
  • 0 <= fromi < toi < n
  • \n\t
  • 1 <= weighti <= 1000
  • \n\t
  • \u6240\u6709 (fromi, toi) \u6570\u5bf9\u90fd\u662f\u4e92\u4e0d\u76f8\u540c\u7684\u3002
  • \n
\n", "tags_en": ["Depth-first Search", "Union Find"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e76\u67e5\u96c6"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> findCriticalAndPseudoCriticalEdges(int n, vector>& edges) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> findCriticalAndPseudoCriticalEdges(int n, int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findCriticalAndPseudoCriticalEdges(self, n, edges):\n \"\"\"\n :type n: int\n :type edges: List[List[int]]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findCriticalAndPseudoCriticalEdges(self, n: int, edges: List[List[int]]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** findCriticalAndPseudoCriticalEdges(int n, int** edges, int edgesSize, int* edgesColSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> FindCriticalAndPseudoCriticalEdges(int n, int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} edges\n * @return {number[][]}\n */\nvar findCriticalAndPseudoCriticalEdges = function(n, edges) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} edges\n# @return {Integer[][]}\ndef find_critical_and_pseudo_critical_edges(n, edges)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findCriticalAndPseudoCriticalEdges(_ n: Int, _ edges: [[Int]]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findCriticalAndPseudoCriticalEdges(n int, edges [][]int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findCriticalAndPseudoCriticalEdges(n: Int, edges: Array[Array[Int]]): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findCriticalAndPseudoCriticalEdges(n: Int, edges: Array): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_critical_and_pseudo_critical_edges(n: i32, edges: Vec>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $edges\n * @return Integer[][]\n */\n function findCriticalAndPseudoCriticalEdges($n, $edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findCriticalAndPseudoCriticalEdges(n: number, edges: number[][]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-critical-and-pseudo-critical-edges n edges)\n (-> exact-integer? (listof (listof exact-integer?)) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1489](https://leetcode-cn.com/problems/find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree)", "[\u627e\u5230\u6700\u5c0f\u751f\u6210\u6811\u91cc\u7684\u5173\u952e\u8fb9\u548c\u4f2a\u5173\u952e\u8fb9](/solution/1400-1499/1489.Find%20Critical%20and%20Pseudo-Critical%20Edges%20in%20Minimum%20Spanning%20Tree/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e76\u67e5\u96c6`", "\u56f0\u96be", ""], "md_table_row_en": ["[1489](https://leetcode.com/problems/find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree)", "[Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree](/solution/1400-1499/1489.Find%20Critical%20and%20Pseudo-Critical%20Edges%20in%20Minimum%20Spanning%20Tree/README_EN.md)", "`Depth-first Search`,`Union Find`", "Hard", ""]}, {"question_id": "1612", "frontend_question_id": "1488", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/avoid-flood-in-the-city", "url_en": "https://leetcode.com/problems/avoid-flood-in-the-city", "relative_path_cn": "/solution/1400-1499/1488.Avoid%20Flood%20in%20The%20City/README.md", "relative_path_en": "/solution/1400-1499/1488.Avoid%20Flood%20in%20The%20City/README_EN.md", "title_cn": "\u907f\u514d\u6d2a\u6c34\u6cdb\u6ee5", "title_en": "Avoid Flood in The City", "question_title_slug": "avoid-flood-in-the-city", "content_en": "

Your country has an infinite number of lakes. Initially, all the lakes are empty, but when it rains over the nth lake, the nth lake becomes full of water. If it rains over a lake which is full of water, there will be a flood. Your goal is to avoid the flood in any lake.

\n\n

Given an integer array rains where:

\n\n
    \n\t
  • rains[i] > 0 means there will be rains over the rains[i] lake.
  • \n\t
  • rains[i] == 0 means there are no rains this day and you can choose one lake this day and dry it.
  • \n
\n\n

Return an array ans where:

\n\n
    \n\t
  • ans.length == rains.length
  • \n\t
  • ans[i] == -1 if rains[i] > 0.
  • \n\t
  • ans[i] is the lake you choose to dry in the ith day if rains[i] == 0.
  • \n
\n\n

If there are multiple valid answers return any of them. If it is impossible to avoid flood return an empty array.

\n\n

Notice that if you chose to dry a full lake, it becomes empty, but if you chose to dry an empty lake, nothing changes. (see example 4)

\n\n

 

\n

Example 1:

\n\n
\nInput: rains = [1,2,3,4]\nOutput: [-1,-1,-1,-1]\nExplanation: After the first day full lakes are [1]\nAfter the second day full lakes are [1,2]\nAfter the third day full lakes are [1,2,3]\nAfter the fourth day full lakes are [1,2,3,4]\nThere's no day to dry any lake and there is no flood in any lake.\n
\n\n

Example 2:

\n\n
\nInput: rains = [1,2,0,0,2,1]\nOutput: [-1,-1,2,1,-1,-1]\nExplanation: After the first day full lakes are [1]\nAfter the second day full lakes are [1,2]\nAfter the third day, we dry lake 2. Full lakes are [1]\nAfter the fourth day, we dry lake 1. There is no full lakes.\nAfter the fifth day, full lakes are [2].\nAfter the sixth day, full lakes are [1,2].\nIt is easy that this scenario is flood-free. [-1,-1,1,2,-1,-1] is another acceptable scenario.\n
\n\n

Example 3:

\n\n
\nInput: rains = [1,2,0,1,2]\nOutput: []\nExplanation: After the second day, full lakes are  [1,2]. We have to dry one lake in the third day.\nAfter that, it will rain over lakes [1,2]. It's easy to prove that no matter which lake you choose to dry in the 3rd day, the other one will flood.\n
\n\n

Example 4:

\n\n
\nInput: rains = [69,0,0,0,69]\nOutput: [-1,69,1,1,-1]\nExplanation: Any solution on one of the forms [-1,69,x,y,-1], [-1,x,69,y,-1] or [-1,x,y,69,-1] is acceptable where 1 <= x,y <= 10^9\n
\n\n

Example 5:

\n\n
\nInput: rains = [10,20,20]\nOutput: []\nExplanation: It will rain over lake 20 two consecutive days. There is no chance to dry any lake.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= rains.length <= 105
  • \n\t
  • 0 <= rains[i] <= 109
  • \n
\n", "content_cn": "

\u4f60\u7684\u56fd\u5bb6\u6709\u65e0\u6570\u4e2a\u6e56\u6cca\uff0c\u6240\u6709\u6e56\u6cca\u4e00\u5f00\u59cb\u90fd\u662f\u7a7a\u7684\u3002\u5f53\u7b2c n \u4e2a\u6e56\u6cca\u4e0b\u96e8\u7684\u65f6\u5019\uff0c\u5982\u679c\u7b2c n \u4e2a\u6e56\u6cca\u662f\u7a7a\u7684\uff0c\u90a3\u4e48\u5b83\u5c31\u4f1a\u88c5\u6ee1\u6c34\uff0c\u5426\u5219\u8fd9\u4e2a\u6e56\u6cca\u4f1a\u53d1\u751f\u6d2a\u6c34\u3002\u4f60\u7684\u76ee\u6807\u662f\u907f\u514d\u4efb\u610f\u4e00\u4e2a\u6e56\u6cca\u53d1\u751f\u6d2a\u6c34\u3002

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 rains \uff0c\u5176\u4e2d\uff1a

\n\n
    \n\t
  • rains[i] > 0 \u8868\u793a\u7b2c i \u5929\u65f6\uff0c\u7b2c rains[i] \u4e2a\u6e56\u6cca\u4f1a\u4e0b\u96e8\u3002
  • \n\t
  • rains[i] == 0 \u8868\u793a\u7b2c i \u5929\u6ca1\u6709\u6e56\u6cca\u4f1a\u4e0b\u96e8\uff0c\u4f60\u53ef\u4ee5\u9009\u62e9 \u4e00\u4e2a \u6e56\u6cca\u5e76 \u62bd\u5e72 \u8fd9\u4e2a\u6e56\u6cca\u7684\u6c34\u3002
  • \n
\n\n

\u8bf7\u8fd4\u56de\u4e00\u4e2a\u6570\u7ec4 ans \uff0c\u6ee1\u8db3\uff1a

\n\n
    \n\t
  • ans.length == rains.length
  • \n\t
  • \u5982\u679c rains[i] > 0 \uff0c\u90a3\u4e48ans[i] == -1 \u3002
  • \n\t
  • \u5982\u679c rains[i] == 0 \uff0cans[i] \u662f\u4f60\u7b2c i \u5929\u9009\u62e9\u62bd\u5e72\u7684\u6e56\u6cca\u3002
  • \n
\n\n

\u5982\u679c\u6709\u591a\u79cd\u53ef\u884c\u89e3\uff0c\u8bf7\u8fd4\u56de\u5b83\u4eec\u4e2d\u7684 \u4efb\u610f\u4e00\u4e2a \u3002\u5982\u679c\u6ca1\u529e\u6cd5\u963b\u6b62\u6d2a\u6c34\uff0c\u8bf7\u8fd4\u56de\u4e00\u4e2a \u7a7a\u7684\u6570\u7ec4 \u3002

\n\n

\u8bf7\u6ce8\u610f\uff0c\u5982\u679c\u4f60\u9009\u62e9\u62bd\u5e72\u4e00\u4e2a\u88c5\u6ee1\u6c34\u7684\u6e56\u6cca\uff0c\u5b83\u4f1a\u53d8\u6210\u4e00\u4e2a\u7a7a\u7684\u6e56\u6cca\u3002\u4f46\u5982\u679c\u4f60\u9009\u62e9\u62bd\u5e72\u4e00\u4e2a\u7a7a\u7684\u6e56\u6cca\uff0c\u90a3\u4e48\u5c06\u65e0\u4e8b\u53d1\u751f\uff08\u8be6\u60c5\u8bf7\u770b\u793a\u4f8b 4\uff09\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1arains = [1,2,3,4]\n\u8f93\u51fa\uff1a[-1,-1,-1,-1]\n\u89e3\u91ca\uff1a\u7b2c\u4e00\u5929\u540e\uff0c\u88c5\u6ee1\u6c34\u7684\u6e56\u6cca\u5305\u62ec [1]\n\u7b2c\u4e8c\u5929\u540e\uff0c\u88c5\u6ee1\u6c34\u7684\u6e56\u6cca\u5305\u62ec [1,2]\n\u7b2c\u4e09\u5929\u540e\uff0c\u88c5\u6ee1\u6c34\u7684\u6e56\u6cca\u5305\u62ec [1,2,3]\n\u7b2c\u56db\u5929\u540e\uff0c\u88c5\u6ee1\u6c34\u7684\u6e56\u6cca\u5305\u62ec [1,2,3,4]\n\u6ca1\u6709\u54ea\u4e00\u5929\u4f60\u53ef\u4ee5\u62bd\u5e72\u4efb\u4f55\u6e56\u6cca\u7684\u6c34\uff0c\u4e5f\u6ca1\u6709\u6e56\u6cca\u4f1a\u53d1\u751f\u6d2a\u6c34\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1arains = [1,2,0,0,2,1]\n\u8f93\u51fa\uff1a[-1,-1,2,1,-1,-1]\n\u89e3\u91ca\uff1a\u7b2c\u4e00\u5929\u540e\uff0c\u88c5\u6ee1\u6c34\u7684\u6e56\u6cca\u5305\u62ec [1]\n\u7b2c\u4e8c\u5929\u540e\uff0c\u88c5\u6ee1\u6c34\u7684\u6e56\u6cca\u5305\u62ec [1,2]\n\u7b2c\u4e09\u5929\u540e\uff0c\u6211\u4eec\u62bd\u5e72\u6e56\u6cca 2 \u3002\u6240\u4ee5\u5269\u4e0b\u88c5\u6ee1\u6c34\u7684\u6e56\u6cca\u5305\u62ec [1]\n\u7b2c\u56db\u5929\u540e\uff0c\u6211\u4eec\u62bd\u5e72\u6e56\u6cca 1 \u3002\u6240\u4ee5\u6682\u65f6\u6ca1\u6709\u88c5\u6ee1\u6c34\u7684\u6e56\u6cca\u4e86\u3002\n\u7b2c\u4e94\u5929\u540e\uff0c\u88c5\u6ee1\u6c34\u7684\u6e56\u6cca\u5305\u62ec [2]\u3002\n\u7b2c\u516d\u5929\u540e\uff0c\u88c5\u6ee1\u6c34\u7684\u6e56\u6cca\u5305\u62ec [1,2]\u3002\n\u53ef\u4ee5\u770b\u51fa\uff0c\u8fd9\u4e2a\u65b9\u6848\u4e0b\u4e0d\u4f1a\u6709\u6d2a\u6c34\u53d1\u751f\u3002\u540c\u65f6\uff0c [-1,-1,1,2,-1,-1] \u4e5f\u662f\u53e6\u4e00\u4e2a\u53ef\u884c\u7684\u6ca1\u6709\u6d2a\u6c34\u7684\u65b9\u6848\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1arains = [1,2,0,1,2]\n\u8f93\u51fa\uff1a[]\n\u89e3\u91ca\uff1a\u7b2c\u4e8c\u5929\u540e\uff0c\u88c5\u6ee1\u6c34\u7684\u6e56\u6cca\u5305\u62ec [1,2]\u3002\u6211\u4eec\u53ef\u4ee5\u5728\u7b2c\u4e09\u5929\u62bd\u5e72\u4e00\u4e2a\u6e56\u6cca\u7684\u6c34\u3002\n\u4f46\u7b2c\u4e09\u5929\u540e\uff0c\u6e56\u6cca 1 \u548c 2 \u90fd\u4f1a\u518d\u6b21\u4e0b\u96e8\uff0c\u6240\u4ee5\u4e0d\u7ba1\u6211\u4eec\u7b2c\u4e09\u5929\u62bd\u5e72\u54ea\u4e2a\u6e56\u6cca\u7684\u6c34\uff0c\u53e6\u4e00\u4e2a\u6e56\u6cca\u90fd\u4f1a\u53d1\u751f\u6d2a\u6c34\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1arains = [69,0,0,0,69]\n\u8f93\u51fa\uff1a[-1,69,1,1,-1]\n\u89e3\u91ca\uff1a\u4efb\u4f55\u5f62\u5982 [-1,69,x,y,-1], [-1,x,69,y,-1] \u6216\u8005 [-1,x,y,69,-1] \u90fd\u662f\u53ef\u884c\u7684\u89e3\uff0c\u5176\u4e2d 1 <= x,y <= 10^9\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1arains = [10,20,20]\n\u8f93\u51fa\uff1a[]\n\u89e3\u91ca\uff1a\u7531\u4e8e\u6e56\u6cca 20 \u4f1a\u8fde\u7eed\u4e0b 2 \u5929\u7684\u96e8\uff0c\u6240\u4ee5\u6ca1\u6709\u6ca1\u6709\u529e\u6cd5\u963b\u6b62\u6d2a\u6c34\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= rains.length <= 10^5
  • \n\t
  • 0 <= rains[i] <= 10^9
  • \n
\n", "tags_en": ["Array", "Hash Table"], "tags_cn": ["\u6570\u7ec4", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector avoidFlood(vector& rains) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] avoidFlood(int[] rains) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def avoidFlood(self, rains):\n \"\"\"\n :type rains: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def avoidFlood(self, rains: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* avoidFlood(int* rains, int rainsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] AvoidFlood(int[] rains) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} rains\n * @return {number[]}\n */\nvar avoidFlood = function(rains) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} rains\n# @return {Integer[]}\ndef avoid_flood(rains)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func avoidFlood(_ rains: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func avoidFlood(rains []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def avoidFlood(rains: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun avoidFlood(rains: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn avoid_flood(rains: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $rains\n * @return Integer[]\n */\n function avoidFlood($rains) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function avoidFlood(rains: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (avoid-flood rains)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1488](https://leetcode-cn.com/problems/avoid-flood-in-the-city)", "[\u907f\u514d\u6d2a\u6c34\u6cdb\u6ee5](/solution/1400-1499/1488.Avoid%20Flood%20in%20The%20City/README.md)", "`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1488](https://leetcode.com/problems/avoid-flood-in-the-city)", "[Avoid Flood in The City](/solution/1400-1499/1488.Avoid%20Flood%20in%20The%20City/README_EN.md)", "`Array`,`Hash Table`", "Medium", ""]}, {"question_id": "1611", "frontend_question_id": "1487", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/making-file-names-unique", "url_en": "https://leetcode.com/problems/making-file-names-unique", "relative_path_cn": "/solution/1400-1499/1487.Making%20File%20Names%20Unique/README.md", "relative_path_en": "/solution/1400-1499/1487.Making%20File%20Names%20Unique/README_EN.md", "title_cn": "\u4fdd\u8bc1\u6587\u4ef6\u540d\u552f\u4e00", "title_en": "Making File Names Unique", "question_title_slug": "making-file-names-unique", "content_en": "

Given an array of strings names of size n. You will create n folders in your file system such that, at the ith minute, you will create a folder with the name names[i].

\r\n\r\n

Since two files cannot have the same name, if you enter a folder name which is previously used, the system will have a suffix addition to its name in the form of (k), where, k is the smallest positive integer such that the obtained name remains unique.

\r\n\r\n

Return an array of strings of length n where ans[i] is the actual name the system will assign to the ith folder when you create it.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: names = ["pes","fifa","gta","pes(2019)"]\r\nOutput: ["pes","fifa","gta","pes(2019)"]\r\nExplanation: Let's see how the file system creates folder names:\r\n"pes" --> not assigned before, remains "pes"\r\n"fifa" --> not assigned before, remains "fifa"\r\n"gta" --> not assigned before, remains "gta"\r\n"pes(2019)" --> not assigned before, remains "pes(2019)"\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: names = ["gta","gta(1)","gta","avalon"]\r\nOutput: ["gta","gta(1)","gta(2)","avalon"]\r\nExplanation: Let's see how the file system creates folder names:\r\n"gta" --> not assigned before, remains "gta"\r\n"gta(1)" --> not assigned before, remains "gta(1)"\r\n"gta" --> the name is reserved, system adds (k), since "gta(1)" is also reserved, systems put k = 2. it becomes "gta(2)"\r\n"avalon" --> not assigned before, remains "avalon"\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: names = ["onepiece","onepiece(1)","onepiece(2)","onepiece(3)","onepiece"]\r\nOutput: ["onepiece","onepiece(1)","onepiece(2)","onepiece(3)","onepiece(4)"]\r\nExplanation: When the last folder is created, the smallest positive valid k is 4, and it becomes "onepiece(4)".\r\n
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: names = ["wano","wano","wano","wano"]\r\nOutput: ["wano","wano(1)","wano(2)","wano(3)"]\r\nExplanation: Just increase the value of k each time you create folder "wano".\r\n
\r\n\r\n

Example 5:

\r\n\r\n
\r\nInput: names = ["kaido","kaido(1)","kaido","kaido(1)"]\r\nOutput: ["kaido","kaido(1)","kaido(2)","kaido(1)(1)"]\r\nExplanation: Please note that system adds the suffix (k) to current name even it contained the same suffix before.\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= names.length <= 5 * 10^4
  • \r\n\t
  • 1 <= names[i].length <= 20
  • \r\n\t
  • names[i] consists of lower case English letters, digits and/or round brackets.
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u5b57\u7b26\u4e32\u6570\u7ec4 names \u3002\u4f60\u5c06\u4f1a\u5728\u6587\u4ef6\u7cfb\u7edf\u4e2d\u521b\u5efa n \u4e2a\u6587\u4ef6\u5939\uff1a\u5728\u7b2c i \u5206\u949f\uff0c\u65b0\u5efa\u540d\u4e3a names[i] \u7684\u6587\u4ef6\u5939\u3002

\n\n

\u7531\u4e8e\u4e24\u4e2a\u6587\u4ef6 \u4e0d\u80fd \u5171\u4eab\u76f8\u540c\u7684\u6587\u4ef6\u540d\uff0c\u56e0\u6b64\u5982\u679c\u65b0\u5efa\u6587\u4ef6\u5939\u4f7f\u7528\u7684\u6587\u4ef6\u540d\u5df2\u7ecf\u88ab\u5360\u7528\uff0c\u7cfb\u7edf\u4f1a\u4ee5 (k) \u7684\u5f62\u5f0f\u4e3a\u65b0\u6587\u4ef6\u5939\u7684\u6587\u4ef6\u540d\u6dfb\u52a0\u540e\u7f00\uff0c\u5176\u4e2d k \u662f\u80fd\u4fdd\u8bc1\u6587\u4ef6\u540d\u552f\u4e00\u7684 \u6700\u5c0f\u6b63\u6574\u6570 \u3002

\n\n

\u8fd4\u56de\u957f\u5ea6\u4e3a n \u7684\u5b57\u7b26\u4e32\u6570\u7ec4\uff0c\u5176\u4e2d ans[i] \u662f\u521b\u5efa\u7b2c i \u4e2a\u6587\u4ef6\u5939\u65f6\u7cfb\u7edf\u5206\u914d\u7ed9\u8be5\u6587\u4ef6\u5939\u7684\u5b9e\u9645\u540d\u79f0\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anames = ["pes","fifa","gta","pes(2019)"]\n\u8f93\u51fa\uff1a["pes","fifa","gta","pes(2019)"]\n\u89e3\u91ca\uff1a\u6587\u4ef6\u7cfb\u7edf\u5c06\u4f1a\u8fd9\u6837\u521b\u5efa\u6587\u4ef6\u540d\uff1a\n"pes" --> \u4e4b\u524d\u672a\u5206\u914d\uff0c\u4ecd\u4e3a "pes"\n"fifa" --> \u4e4b\u524d\u672a\u5206\u914d\uff0c\u4ecd\u4e3a "fifa"\n"gta" --> \u4e4b\u524d\u672a\u5206\u914d\uff0c\u4ecd\u4e3a "gta"\n"pes(2019)" --> \u4e4b\u524d\u672a\u5206\u914d\uff0c\u4ecd\u4e3a "pes(2019)"\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anames = ["gta","gta(1)","gta","avalon"]\n\u8f93\u51fa\uff1a["gta","gta(1)","gta(2)","avalon"]\n\u89e3\u91ca\uff1a\u6587\u4ef6\u7cfb\u7edf\u5c06\u4f1a\u8fd9\u6837\u521b\u5efa\u6587\u4ef6\u540d\uff1a\n"gta" --> \u4e4b\u524d\u672a\u5206\u914d\uff0c\u4ecd\u4e3a "gta"\n"gta(1)" --> \u4e4b\u524d\u672a\u5206\u914d\uff0c\u4ecd\u4e3a "gta(1)"\n"gta" --> \u6587\u4ef6\u540d\u88ab\u5360\u7528\uff0c\u7cfb\u7edf\u4e3a\u8be5\u540d\u79f0\u6dfb\u52a0\u540e\u7f00 (k)\uff0c\u7531\u4e8e "gta(1)" \u4e5f\u88ab\u5360\u7528\uff0c\u6240\u4ee5 k = 2 \u3002\u5b9e\u9645\u521b\u5efa\u7684\u6587\u4ef6\u540d\u4e3a "gta(2)" \u3002\n"avalon" --> \u4e4b\u524d\u672a\u5206\u914d\uff0c\u4ecd\u4e3a "avalon"\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1anames = ["onepiece","onepiece(1)","onepiece(2)","onepiece(3)","onepiece"]\n\u8f93\u51fa\uff1a["onepiece","onepiece(1)","onepiece(2)","onepiece(3)","onepiece(4)"]\n\u89e3\u91ca\uff1a\u5f53\u521b\u5efa\u6700\u540e\u4e00\u4e2a\u6587\u4ef6\u5939\u65f6\uff0c\u6700\u5c0f\u7684\u6b63\u6709\u6548 k \u4e3a 4 \uff0c\u6587\u4ef6\u540d\u53d8\u4e3a "onepiece(4)"\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1anames = ["wano","wano","wano","wano"]\n\u8f93\u51fa\uff1a["wano","wano(1)","wano(2)","wano(3)"]\n\u89e3\u91ca\uff1a\u6bcf\u6b21\u521b\u5efa\u6587\u4ef6\u5939 "wano" \u65f6\uff0c\u53ea\u9700\u589e\u52a0\u540e\u7f00\u4e2d k \u7684\u503c\u5373\u53ef\u3002
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1anames = ["kaido","kaido(1)","kaido","kaido(1)"]\n\u8f93\u51fa\uff1a["kaido","kaido(1)","kaido(2)","kaido(1)(1)"]\n\u89e3\u91ca\uff1a\u6ce8\u610f\uff0c\u5982\u679c\u542b\u540e\u7f00\u6587\u4ef6\u540d\u88ab\u5360\u7528\uff0c\u90a3\u4e48\u7cfb\u7edf\u4e5f\u4f1a\u6309\u89c4\u5219\u5728\u540d\u79f0\u540e\u6dfb\u52a0\u65b0\u7684\u540e\u7f00 (k) \u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= names.length <= 5 * 10^4
  • \n\t
  • 1 <= names[i].length <= 20
  • \n\t
  • names[i] \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3001\u6570\u5b57\u548c/\u6216\u5706\u62ec\u53f7\u7ec4\u6210\u3002
  • \n
\n", "tags_en": ["Hash Table", "String"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector getFolderNames(vector& names) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String[] getFolderNames(String[] names) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getFolderNames(self, names):\n \"\"\"\n :type names: List[str]\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getFolderNames(self, names: List[str]) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** getFolderNames(char ** names, int namesSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string[] GetFolderNames(string[] names) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} names\n * @return {string[]}\n */\nvar getFolderNames = function(names) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} names\n# @return {String[]}\ndef get_folder_names(names)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getFolderNames(_ names: [String]) -> [String] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getFolderNames(names []string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getFolderNames(names: Array[String]): Array[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getFolderNames(names: Array): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_folder_names(names: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $names\n * @return String[]\n */\n function getFolderNames($names) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getFolderNames(names: string[]): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-folder-names names)\n (-> (listof string?) (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1487](https://leetcode-cn.com/problems/making-file-names-unique)", "[\u4fdd\u8bc1\u6587\u4ef6\u540d\u552f\u4e00](/solution/1400-1499/1487.Making%20File%20Names%20Unique/README.md)", "`\u54c8\u5e0c\u8868`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1487](https://leetcode.com/problems/making-file-names-unique)", "[Making File Names Unique](/solution/1400-1499/1487.Making%20File%20Names%20Unique/README_EN.md)", "`Hash Table`,`String`", "Medium", ""]}, {"question_id": "1610", "frontend_question_id": "1486", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/xor-operation-in-an-array", "url_en": "https://leetcode.com/problems/xor-operation-in-an-array", "relative_path_cn": "/solution/1400-1499/1486.XOR%20Operation%20in%20an%20Array/README.md", "relative_path_en": "/solution/1400-1499/1486.XOR%20Operation%20in%20an%20Array/README_EN.md", "title_cn": "\u6570\u7ec4\u5f02\u6216\u64cd\u4f5c", "title_en": "XOR Operation in an Array", "question_title_slug": "xor-operation-in-an-array", "content_en": "

Given an integer n and an integer start.

\r\n\r\n

Define an array nums where nums[i] = start + 2*i (0-indexed) and n == nums.length.

\r\n\r\n

Return the bitwise XOR of all elements of nums.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: n = 5, start = 0\r\nOutput: 8\r\nExplanation: Array nums is equal to [0, 2, 4, 6, 8] where (0 ^ 2 ^ 4 ^ 6 ^ 8) = 8.\r\nWhere "^" corresponds to bitwise XOR operator.\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: n = 4, start = 3\r\nOutput: 8\r\nExplanation: Array nums is equal to [3, 5, 7, 9] where (3 ^ 5 ^ 7 ^ 9) = 8.
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: n = 1, start = 7\r\nOutput: 7\r\n
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: n = 10, start = 5\r\nOutput: 2\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= n <= 1000
  • \r\n\t
  • 0 <= start <= 1000
  • \r\n\t
  • n == nums.length
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e24\u4e2a\u6574\u6570\uff0cn \u548c start \u3002

\n\n

\u6570\u7ec4 nums \u5b9a\u4e49\u4e3a\uff1anums[i] = start + 2*i\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\u4e14 n == nums.length \u3002

\n\n

\u8bf7\u8fd4\u56de nums \u4e2d\u6240\u6709\u5143\u7d20\u6309\u4f4d\u5f02\u6216\uff08XOR\uff09\u540e\u5f97\u5230\u7684\u7ed3\u679c\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1an = 5, start = 0\n\u8f93\u51fa\uff1a8\n\u89e3\u91ca\uff1a\u6570\u7ec4 nums \u4e3a [0, 2, 4, 6, 8]\uff0c\u5176\u4e2d (0 ^ 2 ^ 4 ^ 6 ^ 8) = 8 \u3002\n     "^" \u4e3a\u6309\u4f4d\u5f02\u6216 XOR \u8fd0\u7b97\u7b26\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1an = 4, start = 3\n\u8f93\u51fa\uff1a8\n\u89e3\u91ca\uff1a\u6570\u7ec4 nums \u4e3a [3, 5, 7, 9]\uff0c\u5176\u4e2d (3 ^ 5 ^ 7 ^ 9) = 8.
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1an = 1, start = 7\n\u8f93\u51fa\uff1a7\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1an = 10, start = 5\n\u8f93\u51fa\uff1a2\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 1000
  • \n\t
  • 0 <= start <= 1000
  • \n\t
  • n == nums.length
  • \n
\n", "tags_en": ["Bit Manipulation", "Array"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int xorOperation(int n, int start) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int xorOperation(int n, int start) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def xorOperation(self, n, start):\n \"\"\"\n :type n: int\n :type start: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def xorOperation(self, n: int, start: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint xorOperation(int n, int start){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int XorOperation(int n, int start) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} start\n * @return {number}\n */\nvar xorOperation = function(n, start) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} start\n# @return {Integer}\ndef xor_operation(n, start)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func xorOperation(_ n: Int, _ start: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func xorOperation(n int, start int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def xorOperation(n: Int, start: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun xorOperation(n: Int, start: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn xor_operation(n: i32, start: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $start\n * @return Integer\n */\n function xorOperation($n, $start) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function xorOperation(n: number, start: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (xor-operation n start)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1486](https://leetcode-cn.com/problems/xor-operation-in-an-array)", "[\u6570\u7ec4\u5f02\u6216\u64cd\u4f5c](/solution/1400-1499/1486.XOR%20Operation%20in%20an%20Array/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1486](https://leetcode.com/problems/xor-operation-in-an-array)", "[XOR Operation in an Array](/solution/1400-1499/1486.XOR%20Operation%20in%20an%20Array/README_EN.md)", "`Bit Manipulation`,`Array`", "Easy", ""]}, {"question_id": "1609", "frontend_question_id": "1469", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/find-all-the-lonely-nodes", "url_en": "https://leetcode.com/problems/find-all-the-lonely-nodes", "relative_path_cn": "/solution/1400-1499/1469.Find%20All%20The%20Lonely%20Nodes/README.md", "relative_path_en": "/solution/1400-1499/1469.Find%20All%20The%20Lonely%20Nodes/README_EN.md", "title_cn": "\u5bfb\u627e\u6240\u6709\u7684\u72ec\u751f\u8282\u70b9", "title_en": "Find All The Lonely Nodes", "question_title_slug": "find-all-the-lonely-nodes", "content_en": "

In a binary tree, a lonely node is a node that is the only child of its parent node. The root of the tree is not lonely because it does not have a parent node.

\n\n

Given the root of a binary tree, return an array containing the values of all lonely nodes in the tree. Return the list in any order.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: root = [1,2,3,null,4]\nOutput: [4]\nExplanation: Light blue node is the only lonely node.\nNode 1 is the root and is not lonely.\nNodes 2 and 3 have the same parent and are not lonely.\n
\n\n

Example 2:

\n\"\"\n
\nInput: root = [7,1,4,6,null,5,3,null,null,null,null,null,2]\nOutput: [6,2]\nExplanation: Light blue nodes are lonely nodes.\nPlease remember that order doesn't matter, [2,6] is also an acceptable answer.\n
\n\n

Example 3:

\n\"\" \n\n
\n\nInput: root = [11,99,88,77,null,null,66,55,null,null,44,33,null,null,22]\nOutput: [77,55,33,66,44,22]\nExplanation: Nodes 99 and 88 share the same parent. Node 11 is the root.\nAll other nodes are lonely.\n
\n\n

Example 4:

\n\n
\nInput: root = [197]\nOutput: []\n
\n\n

Example 5:

\n\n
\nInput: root = [31,null,78,null,28]\nOutput: [78,28]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The number of nodes in the tree is in the range [1, 1000].
  • \n\t
  • Each node's value is between [1, 10^6].
  • \n
\n", "content_cn": "

\u4e8c\u53c9\u6811\u4e2d\uff0c\u5982\u679c\u4e00\u4e2a\u8282\u70b9\u662f\u5176\u7236\u8282\u70b9\u7684\u552f\u4e00\u5b50\u8282\u70b9\uff0c\u5219\u79f0\u8fd9\u6837\u7684\u8282\u70b9\u4e3a “\u72ec\u751f\u8282\u70b9” \u3002\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9\u4e0d\u4f1a\u662f\u72ec\u751f\u8282\u70b9\uff0c\u56e0\u4e3a\u5b83\u6ca1\u6709\u7236\u8282\u70b9\u3002

\n\n

\u7ed9\u5b9a\u4e00\u68f5\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9 root \uff0c\u8fd4\u56de\u6811\u4e2d \u6240\u6709\u7684\u72ec\u751f\u8282\u70b9\u7684\u503c\u6240\u6784\u6210\u7684\u6570\u7ec4 \u3002\u6570\u7ec4\u7684\u987a\u5e8f \u4e0d\u9650 \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1aroot = [1,2,3,null,4]\n\u8f93\u51fa\uff1a[4]\n\u89e3\u91ca\uff1a\u6d45\u84dd\u8272\u7684\u8282\u70b9\u662f\u552f\u4e00\u7684\u72ec\u751f\u8282\u70b9\u3002\n\u8282\u70b9 1 \u662f\u6839\u8282\u70b9\uff0c\u4e0d\u662f\u72ec\u751f\u7684\u3002\n\u8282\u70b9 2 \u548c 3 \u6709\u5171\u540c\u7684\u7236\u8282\u70b9\uff0c\u6240\u4ee5\u5b83\u4eec\u90fd\u4e0d\u662f\u72ec\u751f\u7684\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1aroot = [7,1,4,6,null,5,3,null,null,null,null,null,2]\n\u8f93\u51fa\uff1a[6,2]\n\u8f93\u51fa\uff1a\u6d45\u84dd\u8272\u7684\u8282\u70b9\u662f\u72ec\u751f\u8282\u70b9\u3002\n\u8bf7\u8c28\u8bb0\uff0c\u987a\u5e8f\u662f\u4e0d\u9650\u7684\u3002 [2,6] \u4e5f\u662f\u4e00\u79cd\u53ef\u63a5\u53d7\u7684\u7b54\u6848\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1aroot = [11,99,88,77,null,null,66,55,null,null,44,33,null,null,22]\n\u8f93\u51fa\uff1a[77,55,33,66,44,22]\n\u89e3\u91ca\uff1a\u8282\u70b9 99 \u548c 88 \u6709\u5171\u540c\u7684\u7236\u8282\u70b9\uff0c\u8282\u70b9 11 \u662f\u6839\u8282\u70b9\u3002\n\u5176\u4ed6\u6240\u6709\u8282\u70b9\u90fd\u662f\u72ec\u751f\u8282\u70b9\u3002
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1aroot = [197]\n\u8f93\u51fa\uff1a[]\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\n\u8f93\u5165\uff1aroot = [31,null,78,null,28]\n\u8f93\u51fa\uff1a[78,28]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  •  tree \u4e2d\u8282\u70b9\u4e2a\u6570\u7684\u53d6\u503c\u8303\u56f4\u662f [1, 1000]\u3002
  • \n\t
  • \u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u7684\u53d6\u503c\u8303\u56f4\u662f [1, 10^6]\u3002
  • \n
\n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector getLonelyNodes(TreeNode* root) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public List getLonelyNodes(TreeNode root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def getLonelyNodes(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: List[int]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def getLonelyNodes(self, root: TreeNode) -> List[int]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* getLonelyNodes(struct TreeNode* root, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public IList GetLonelyNodes(TreeNode root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number[]}\n */\nvar getLonelyNodes = function(root) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer[]}\ndef get_lonely_nodes(root)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func getLonelyNodes(_ root: TreeNode?) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc getLonelyNodes(root *TreeNode) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def getLonelyNodes(root: TreeNode): List[Int] = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun getLonelyNodes(root: TreeNode?): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn get_lonely_nodes(root: Option>>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer[]\n */\n function getLonelyNodes($root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction getLonelyNodes(root: TreeNode | null): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (get-lonely-nodes root)\n (-> (or/c tree-node? #f) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1469](https://leetcode-cn.com/problems/find-all-the-lonely-nodes)", "[\u5bfb\u627e\u6240\u6709\u7684\u72ec\u751f\u8282\u70b9](/solution/1400-1499/1469.Find%20All%20The%20Lonely%20Nodes/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1469](https://leetcode.com/problems/find-all-the-lonely-nodes)", "[Find All The Lonely Nodes](/solution/1400-1499/1469.Find%20All%20The%20Lonely%20Nodes/README_EN.md)", "`Tree`,`Depth-first Search`", "Easy", "\ud83d\udd12"]}, {"question_id": "1608", "frontend_question_id": "1468", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/calculate-salaries", "url_en": "https://leetcode.com/problems/calculate-salaries", "relative_path_cn": "/solution/1400-1499/1468.Calculate%20Salaries/README.md", "relative_path_en": "/solution/1400-1499/1468.Calculate%20Salaries/README_EN.md", "title_cn": "\u8ba1\u7b97\u7a0e\u540e\u5de5\u8d44", "title_en": "Calculate Salaries", "question_title_slug": "calculate-salaries", "content_en": "

Table Salaries:

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| company_id    | int     |\n| employee_id   | int     |\n| employee_name | varchar |\n| salary        | int     |\n+---------------+---------+\n(company_id, employee_id) is the primary key for this table.\nThis table contains the company id, the id, the name and the salary for an employee.\n
\n\n

 

\n\n

Write an SQL query to find the salaries of the employees after applying taxes.

\n\n

The tax rate is calculated for each company based on the following criteria:

\n\n
    \n\t
  • 0% If the max salary of any employee in the company is less than 1000$.
  • \n\t
  • 24% If the max salary of any employee in the company is in the range [1000, 10000] inclusive.
  • \n\t
  • 49% If the max salary of any employee in the company is greater than 10000$.
  • \n
\n\n

Return the result table in any order. Round the salary to the nearest integer.

\n\n

The query result format is in the following example:

\n\n
\nSalaries table:\n+------------+-------------+---------------+--------+\n| company_id | employee_id | employee_name | salary |\n+------------+-------------+---------------+--------+\n| 1          | 1           | Tony          | 2000   |\n| 1          | 2           | Pronub        | 21300  |\n| 1          | 3           | Tyrrox        | 10800  |\n| 2          | 1           | Pam           | 300    |\n| 2          | 7           | Bassem        | 450    |\n| 2          | 9           | Hermione      | 700    |\n| 3          | 7           | Bocaben       | 100    |\n| 3          | 2           | Ognjen        | 2200   |\n| 3          | 13          | Nyancat       | 3300   |\n| 3          | 15          | Morninngcat   | 7777   |\n+------------+-------------+---------------+--------+\n\nResult table:\n+------------+-------------+---------------+--------+\n| company_id | employee_id | employee_name | salary |\n+------------+-------------+---------------+--------+\n| 1          | 1           | Tony          | 1020   |\n| 1          | 2           | Pronub        | 10863  |\n| 1          | 3           | Tyrrox        | 5508   |\n| 2          | 1           | Pam           | 300    |\n| 2          | 7           | Bassem        | 450    |\n| 2          | 9           | Hermione      | 700    |\n| 3          | 7           | Bocaben       | 76     |\n| 3          | 2           | Ognjen        | 1672   |\n| 3          | 13          | Nyancat       | 2508   |\n| 3          | 15          | Morninngcat   | 5911   |\n+------------+-------------+---------------+--------+\nFor company 1, Max salary is 21300. Employees in company 1 have taxes = 49%\nFor company 2, Max salary is 700. Employees in company 2 have taxes = 0%\nFor company 3, Max salary is 7777. Employees in company 3 have taxes = 24%\nThe salary after taxes = salary - (taxes percentage / 100) * salary\nFor example, Salary for Morninngcat (3, 15) after taxes = 7777 - 7777 * (24 / 100) = 7777 - 1866.48 = 5910.52, which is rounded to 5911.\n
\n", "content_cn": "

Salaries \u8868\uff1a

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| company_id    | int     |\n| employee_id   | int     |\n| employee_name | varchar |\n| salary        | int     |\n+---------------+---------+\n(company_id, employee_id) \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\n\u8fd9\u4e2a\u8868\u5305\u62ec\u5458\u5de5\u7684company id, id, name \u548c salary \n
\n\n

\u00a0

\n\n

\u5199\u4e00\u6761\u67e5\u8be2 SQL \u6765\u67e5\u627e\u6bcf\u4e2a\u5458\u5de5\u7684\u7a0e\u540e\u5de5\u8d44

\n\n

\u6bcf\u4e2a\u516c\u53f8\u7684\u7a0e\u7387\u8ba1\u7b97\u4f9d\u7167\u4ee5\u4e0b\u89c4\u5219

\n\n
    \n\t
  • \u5982\u679c\u8fd9\u4e2a\u516c\u53f8\u5458\u5de5\u6700\u9ad8\u5de5\u8d44\u4e0d\u5230 1000 \uff0c\u7a0e\u7387\u4e3a 0%
  • \n\t
  • \u5982\u679c\u8fd9\u4e2a\u516c\u53f8\u5458\u5de5\u6700\u9ad8\u5de5\u8d44\u5728 1000 \u5230 10000 \u4e4b\u95f4\uff0c\u7a0e\u7387\u4e3a 24%
  • \n\t
  • \u5982\u679c\u8fd9\u4e2a\u516c\u53f8\u5458\u5de5\u6700\u9ad8\u5de5\u8d44\u5927\u4e8e 10000 \uff0c\u7a0e\u7387\u4e3a 49%
  • \n
\n\n

\u6309\u4efb\u610f\u987a\u5e8f\u8fd4\u56de\u7ed3\u679c\uff0c\u7a0e\u540e\u5de5\u8d44\u7ed3\u679c\u53d6\u6574

\n\n

\u00a0

\n\n

\u7ed3\u679c\u8868\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a\uff1a

\n\n
\nSalaries \u8868\uff1a\n+------------+-------------+---------------+--------+\n| company_id | employee_id | employee_name | salary |\n+------------+-------------+---------------+--------+\n| 1          | 1           | Tony          | 2000   |\n| 1          | 2           | Pronub        | 21300  |\n| 1          | 3           | Tyrrox        | 10800  |\n| 2          | 1           | Pam           | 300    |\n| 2          | 7           | Bassem        | 450    |\n| 2          | 9           | Hermione      | 700    |\n| 3          | 7           | Bocaben       | 100    |\n| 3          | 2           | Ognjen        | 2200   |\n| 3          | 13          | Nyancat       | 3300   |\n| 3          | 15          | Morninngcat   | 7777   |\n+------------+-------------+---------------+--------+\n\nResult \u8868\uff1a\n+------------+-------------+---------------+--------+\n| company_id | employee_id | employee_name | salary |\n+------------+-------------+---------------+--------+\n| 1          | 1           | Tony          | 1020   |\n| 1          | 2           | Pronub        | 10863  |\n| 1          | 3           | Tyrrox        | 5508   |\n| 2          | 1           | Pam           | 300    |\n| 2          | 7           | Bassem        | 450    |\n| 2          | 9           | Hermione      | 700    |\n| 3          | 7           | Bocaben       | 76     |\n| 3          | 2           | Ognjen        | 1672   |\n| 3          | 13          | Nyancat       | 2508   |\n| 3          | 15          | Morninngcat   | 5911   |\n+------------+-------------+---------------+--------+\n\u5bf9\u4e8e\u516c\u53f8 1 \uff0c\u6700\u9ad8\u5de5\u8d44\u662f 21300 \uff0c\u5176\u6bcf\u4e2a\u5458\u5de5\u7684\u7a0e\u7387\u4e3a 49%\n\u5bf9\u4e8e\u516c\u53f8 2 \uff0c\u6700\u9ad8\u5de5\u8d44\u662f 700 \uff0c\u5176\u6bcf\u4e2a\u5458\u5de5\u7a0e\u7387\u4e3a 0%\n\u5bf9\u4e8e\u516c\u53f8 3 \uff0c\u6700\u9ad8\u5de5\u8d44\u662f 7777 \uff0c\u5176\u6bcf\u4e2a\u5458\u5de5\u7a0e\u7387\u662f 24%\n\u7a0e\u540e\u5de5\u8d44\u8ba1\u7b97 = \u5de5\u8d44 - ( \u7a0e\u7387 / 100\uff09*\u5de5\u8d44\n\u5bf9\u4e8e\u4e0a\u8ff0\u6848\u4f8b\uff0cMorninngcat \u7684\u7a0e\u540e\u5de5\u8d44 = 7777 - 7777 * ( 24 / 100) = 7777 - 1866.48 = 5910.52 \uff0c\u53d6\u6574\u4e3a 5911\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1468](https://leetcode-cn.com/problems/calculate-salaries)", "[\u8ba1\u7b97\u7a0e\u540e\u5de5\u8d44](/solution/1400-1499/1468.Calculate%20Salaries/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1468](https://leetcode.com/problems/calculate-salaries)", "[Calculate Salaries](/solution/1400-1499/1468.Calculate%20Salaries/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1607", "frontend_question_id": "1459", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/rectangles-area", "url_en": "https://leetcode.com/problems/rectangles-area", "relative_path_cn": "/solution/1400-1499/1459.Rectangles%20Area/README.md", "relative_path_en": "/solution/1400-1499/1459.Rectangles%20Area/README_EN.md", "title_cn": "\u77e9\u5f62\u9762\u79ef", "title_en": "Rectangles Area", "question_title_slug": "rectangles-area", "content_en": "

Table: Points

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| x_value       | int     |\n| y_value       | int     |\n+---------------+---------+\nid is the primary key for this table.\nEach point is represented as a 2D coordinate (x_value, y_value).
\n\n

 

\n\n

Write an SQL query to report all possible axis-aligned rectangles with non-zero area that can be formed by any two points in the Points table.

\n\n

Each row in the result should contain three columns (p1, p2, area) where:

\n\n
    \n\t
  • p1 and p2 are the id's of the two points that determine the opposite corners of a rectangle.
  • \n\t
  • area is the area of the rectangle and must be non-zero.
  • \n
\n\n

Report the query in descending order by area first, then in ascending order by p1's id if there is a tie, then in ascending order by p2's id if there is another tie.

\n\n

The query result format is in the following table:

\n\n

 

\n\n
\nPoints table:\n+----------+-------------+-------------+\n| id       | x_value     | y_value     |\n+----------+-------------+-------------+\n| 1        | 2           | 7           |\n| 2        | 4           | 8           |\n| 3        | 2           | 10          |\n+----------+-------------+-------------+\n\nResult table:\n+----------+-------------+-------------+\n| p1       | p2          | area        |\n+----------+-------------+-------------+\n| 2        | 3           | 4           |\n| 1        | 2           | 2           |\n+----------+-------------+-------------+\n\n\"\"\nThe rectangle formed by p1 = 2 and p2 = 3 has an area equal to |4-2| * |8-10| = 4.\nThe rectangle formed by p1 = 1 and p2 = 2 has an area equal to |2-4| * |7-8| = 2.\nNote that the rectangle formed by p1 = 1 and p2 = 3 is invalid because the area is 0.\n
\n", "content_cn": "

\u8868: Points

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| x_value       | int     |\n| y_value       | int     |\n+---------------+---------+\nid \u662f\u8be5\u8868\u4e3b\u952e\n\u6bcf\u4e2a\u70b9\u90fd\u7528\u4e8c\u7ef4\u5750\u6807 (x_value, y_value) \u8868\u793a
\n\n

\u00a0

\n\n

\u5199\u4e00\u4e2a SQL \u8bed\u53e5\uff0c\u62a5\u544a\u7531\u8868\u4e2d\u4efb\u610f\u4e24\u70b9\u53ef\u4ee5\u5f62\u6210\u7684\u6240\u6709 \u8fb9\u4e0e\u5750\u6807\u8f74\u5e73\u884c \u4e14 \u9762\u79ef\u4e0d\u4e3a\u96f6 \u7684\u77e9\u5f62\u3002

\n\n

\u7ed3\u679c\u8868\u4e2d\u7684\u6bcf\u4e00\u884c\u5305\u542b\u4e09\u5217 (p1, p2, area)\u00a0\u5982\u4e0b:

\n\n
    \n\t
  • p1\u00a0\u548c\u00a0p2\u00a0\u662f\u77e9\u5f62\u4e24\u4e2a\u5bf9\u89d2\u7684 id
  • \n\t
  • \u77e9\u5f62\u7684\u9762\u79ef\u7531\u5217\u00a0area\u00a0\u8868\u793a
  • \n
\n\n

\u8bf7\u6309\u7167\u9762\u79ef\u00a0area \u5927\u5c0f\u964d\u5e8f\u6392\u5217\uff1b\u5982\u679c\u9762\u79ef\u76f8\u540c\u7684\u8bdd, \u5219\u6309\u7167\u00a0p1\u00a0\u5347\u5e8f\u6392\u5e8f\uff1b\u82e5\u4ecd\u76f8\u540c\uff0c\u5219\u6309 p2 \u5347\u5e8f\u6392\u5217\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u5982\u4e0b\u4f8b\u6240\u793a\uff1a

\n\n
\nPoints \u8868:\n+----------+-------------+-------------+\n| id       | x_value     | y_value     |\n+----------+-------------+-------------+\n| 1        | 2           | 7           |\n| 2        | 4           | 8           |\n| 3        | 2           | 10          |\n+----------+-------------+-------------+\n\nResult \u8868:\n+----------+-------------+-------------+\n| p1       | p2          | area        |\n+----------+-------------+-------------+\n| 2        | 3           | 4           |\n| 1        | 2           | 2           |\n+----------+-------------+-------------+\n\n\"\"\n\np1 = 2 \u4e14 p2 = 3 \u65f6, \u9762\u79ef\u7b49\u4e8e |4-2| * |8-10| = 4\np1 = 1 \u4e14 p2 = 2 \u65f6, \u9762\u79ef\u7b49\u4e8e ||2-4| * |7-8| = 2 \np1 = 1 \u4e14 p2 = 3 \u65f6, \u662f\u4e0d\u53ef\u80fd\u4e3a\u77e9\u5f62\u7684, \u9762\u79ef\u7b49\u4e8e 0\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1459](https://leetcode-cn.com/problems/rectangles-area)", "[\u77e9\u5f62\u9762\u79ef](/solution/1400-1499/1459.Rectangles%20Area/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1459](https://leetcode.com/problems/rectangles-area)", "[Rectangles Area](/solution/1400-1499/1459.Rectangles%20Area/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1605", "frontend_question_id": "1482", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-number-of-days-to-make-m-bouquets", "url_en": "https://leetcode.com/problems/minimum-number-of-days-to-make-m-bouquets", "relative_path_cn": "/solution/1400-1499/1482.Minimum%20Number%20of%20Days%20to%20Make%20m%20Bouquets/README.md", "relative_path_en": "/solution/1400-1499/1482.Minimum%20Number%20of%20Days%20to%20Make%20m%20Bouquets/README_EN.md", "title_cn": "\u5236\u4f5c m \u675f\u82b1\u6240\u9700\u7684\u6700\u5c11\u5929\u6570", "title_en": "Minimum Number of Days to Make m Bouquets", "question_title_slug": "minimum-number-of-days-to-make-m-bouquets", "content_en": "

Given an integer array bloomDay, an integer m and an integer k.

\r\n\r\n

We need to make m bouquets. To make a bouquet, you need to use k adjacent flowers from the garden.

\r\n\r\n

The garden consists of n flowers, the ith flower will bloom in the bloomDay[i] and then can be used in exactly one bouquet.

\r\n\r\n

Return the minimum number of days you need to wait to be able to make m bouquets from the garden. If it is impossible to make m bouquets return -1.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: bloomDay = [1,10,3,10,2], m = 3, k = 1\r\nOutput: 3\r\nExplanation: Let's see what happened in the first three days. x means flower bloomed and _ means flower didn't bloom in the garden.\r\nWe need 3 bouquets each should contain 1 flower.\r\nAfter day 1: [x, _, _, _, _]   // we can only make one bouquet.\r\nAfter day 2: [x, _, _, _, x]   // we can only make two bouquets.\r\nAfter day 3: [x, _, x, _, x]   // we can make 3 bouquets. The answer is 3.\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: bloomDay = [1,10,3,10,2], m = 3, k = 2\r\nOutput: -1\r\nExplanation: We need 3 bouquets each has 2 flowers, that means we need 6 flowers. We only have 5 flowers so it is impossible to get the needed bouquets and we return -1.\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: bloomDay = [7,7,7,7,12,7,7], m = 2, k = 3\r\nOutput: 12\r\nExplanation: We need 2 bouquets each should have 3 flowers.\r\nHere's the garden after the 7 and 12 days:\r\nAfter day 7: [x, x, x, x, _, x, x]\r\nWe can make one bouquet of the first three flowers that bloomed. We cannot make another bouquet from the last three flowers that bloomed because they are not adjacent.\r\nAfter day 12: [x, x, x, x, x, x, x]\r\nIt is obvious that we can make two bouquets in different ways.\r\n
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: bloomDay = [1000000000,1000000000], m = 1, k = 1\r\nOutput: 1000000000\r\nExplanation: You need to wait 1000000000 days to have a flower ready for a bouquet.\r\n
\r\n\r\n

Example 5:

\r\n\r\n
\r\nInput: bloomDay = [1,10,2,9,3,8,4,7,5,6], m = 4, k = 2\r\nOutput: 9\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • bloomDay.length == n
  • \r\n\t
  • 1 <= n <= 10^5
  • \r\n\t
  • 1 <= bloomDay[i] <= 10^9
  • \r\n\t
  • 1 <= m <= 10^6
  • \r\n\t
  • 1 <= k <= n
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 bloomDay\uff0c\u4ee5\u53ca\u4e24\u4e2a\u6574\u6570 m \u548c k \u3002

\n\n

\u73b0\u9700\u8981\u5236\u4f5c m \u675f\u82b1\u3002\u5236\u4f5c\u82b1\u675f\u65f6\uff0c\u9700\u8981\u4f7f\u7528\u82b1\u56ed\u4e2d \u76f8\u90bb\u7684 k \u6735\u82b1 \u3002

\n\n

\u82b1\u56ed\u4e2d\u6709 n \u6735\u82b1\uff0c\u7b2c i \u6735\u82b1\u4f1a\u5728 bloomDay[i] \u65f6\u76db\u5f00\uff0c\u6070\u597d \u53ef\u4ee5\u7528\u4e8e \u4e00\u675f \u82b1\u4e2d\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u4ece\u82b1\u56ed\u4e2d\u6458 m \u675f\u82b1\u9700\u8981\u7b49\u5f85\u7684\u6700\u5c11\u7684\u5929\u6570\u3002\u5982\u679c\u4e0d\u80fd\u6458\u5230 m \u675f\u82b1\u5219\u8fd4\u56de -1 \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1abloomDay = [1,10,3,10,2], m = 3, k = 1\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u8ba9\u6211\u4eec\u4e00\u8d77\u89c2\u5bdf\u8fd9\u4e09\u5929\u7684\u82b1\u5f00\u8fc7\u7a0b\uff0cx \u8868\u793a\u82b1\u5f00\uff0c\u800c _ \u8868\u793a\u82b1\u8fd8\u672a\u5f00\u3002\n\u73b0\u5728\u9700\u8981\u5236\u4f5c 3 \u675f\u82b1\uff0c\u6bcf\u675f\u53ea\u9700\u8981 1 \u6735\u3002\n1 \u5929\u540e\uff1a[x, _, _, _, _]   // \u53ea\u80fd\u5236\u4f5c 1 \u675f\u82b1\n2 \u5929\u540e\uff1a[x, _, _, _, x]   // \u53ea\u80fd\u5236\u4f5c 2 \u675f\u82b1\n3 \u5929\u540e\uff1a[x, _, x, _, x]   // \u53ef\u4ee5\u5236\u4f5c 3 \u675f\u82b1\uff0c\u7b54\u6848\u4e3a 3\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1abloomDay = [1,10,3,10,2], m = 3, k = 2\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u8981\u5236\u4f5c 3 \u675f\u82b1\uff0c\u6bcf\u675f\u9700\u8981 2 \u6735\u82b1\uff0c\u4e5f\u5c31\u662f\u4e00\u5171\u9700\u8981 6 \u6735\u82b1\u3002\u800c\u82b1\u56ed\u4e2d\u53ea\u6709 5 \u6735\u82b1\uff0c\u65e0\u6cd5\u6ee1\u8db3\u5236\u4f5c\u8981\u6c42\uff0c\u8fd4\u56de -1 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1abloomDay = [7,7,7,7,12,7,7], m = 2, k = 3\n\u8f93\u51fa\uff1a12\n\u89e3\u91ca\uff1a\u8981\u5236\u4f5c 2 \u675f\u82b1\uff0c\u6bcf\u675f\u9700\u8981 3 \u6735\u3002\n\u82b1\u56ed\u5728 7 \u5929\u540e\u548c 12 \u5929\u540e\u7684\u60c5\u51b5\u5982\u4e0b\uff1a\n7 \u5929\u540e\uff1a[x, x, x, x, _, x, x]\n\u53ef\u4ee5\u7528\u524d 3 \u6735\u76db\u5f00\u7684\u82b1\u5236\u4f5c\u7b2c\u4e00\u675f\u82b1\u3002\u4f46\u4e0d\u80fd\u4f7f\u7528\u540e 3 \u6735\u76db\u5f00\u7684\u82b1\uff0c\u56e0\u4e3a\u5b83\u4eec\u4e0d\u76f8\u90bb\u3002\n12 \u5929\u540e\uff1a[x, x, x, x, x, x, x]\n\u663e\u7136\uff0c\u6211\u4eec\u53ef\u4ee5\u7528\u4e0d\u540c\u7684\u65b9\u5f0f\u5236\u4f5c\u4e24\u675f\u82b1\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1abloomDay = [1000000000,1000000000], m = 1, k = 1\n\u8f93\u51fa\uff1a1000000000\n\u89e3\u91ca\uff1a\u9700\u8981\u7b49 1000000000 \u5929\u624d\u80fd\u91c7\u5230\u82b1\u6765\u5236\u4f5c\u82b1\u675f\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1abloomDay = [1,10,2,9,3,8,4,7,5,6], m = 4, k = 2\n\u8f93\u51fa\uff1a9\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • bloomDay.length == n
  • \n\t
  • 1 <= n <= 10^5
  • \n\t
  • 1 <= bloomDay[i] <= 10^9
  • \n\t
  • 1 <= m <= 10^6
  • \n\t
  • 1 <= k <= n
  • \n
\n", "tags_en": ["Array", "Binary Search"], "tags_cn": ["\u6570\u7ec4", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minDays(vector& bloomDay, int m, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minDays(int[] bloomDay, int m, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minDays(self, bloomDay, m, k):\n \"\"\"\n :type bloomDay: List[int]\n :type m: int\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minDays(self, bloomDay: List[int], m: int, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minDays(int* bloomDay, int bloomDaySize, int m, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinDays(int[] bloomDay, int m, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} bloomDay\n * @param {number} m\n * @param {number} k\n * @return {number}\n */\nvar minDays = function(bloomDay, m, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} bloom_day\n# @param {Integer} m\n# @param {Integer} k\n# @return {Integer}\ndef min_days(bloom_day, m, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minDays(_ bloomDay: [Int], _ m: Int, _ k: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minDays(bloomDay []int, m int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minDays(bloomDay: Array[Int], m: Int, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minDays(bloomDay: IntArray, m: Int, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_days(bloom_day: Vec, m: i32, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $bloomDay\n * @param Integer $m\n * @param Integer $k\n * @return Integer\n */\n function minDays($bloomDay, $m, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minDays(bloomDay: number[], m: number, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-days bloomDay m k)\n (-> (listof exact-integer?) exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1482](https://leetcode-cn.com/problems/minimum-number-of-days-to-make-m-bouquets)", "[\u5236\u4f5c m \u675f\u82b1\u6240\u9700\u7684\u6700\u5c11\u5929\u6570](/solution/1400-1499/1482.Minimum%20Number%20of%20Days%20to%20Make%20m%20Bouquets/README.md)", "`\u6570\u7ec4`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1482](https://leetcode.com/problems/minimum-number-of-days-to-make-m-bouquets)", "[Minimum Number of Days to Make m Bouquets](/solution/1400-1499/1482.Minimum%20Number%20of%20Days%20to%20Make%20m%20Bouquets/README_EN.md)", "`Array`,`Binary Search`", "Medium", ""]}, {"question_id": "1604", "frontend_question_id": "1481", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/least-number-of-unique-integers-after-k-removals", "url_en": "https://leetcode.com/problems/least-number-of-unique-integers-after-k-removals", "relative_path_cn": "/solution/1400-1499/1481.Least%20Number%20of%20Unique%20Integers%20after%20K%20Removals/README.md", "relative_path_en": "/solution/1400-1499/1481.Least%20Number%20of%20Unique%20Integers%20after%20K%20Removals/README_EN.md", "title_cn": "\u4e0d\u540c\u6574\u6570\u7684\u6700\u5c11\u6570\u76ee", "title_en": "Least Number of Unique Integers after K Removals", "question_title_slug": "least-number-of-unique-integers-after-k-removals", "content_en": "

Given an array of integers arr and an integer k. Find the least number of unique integers after removing exactly k elements.

\r\n\r\n
    \r\n
\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: arr = [5,5,4], k = 1\r\nOutput: 1\r\nExplanation: Remove the single 4, only 5 is left.\r\n
\r\nExample 2:\r\n\r\n
\r\nInput: arr = [4,3,1,1,3,3,2], k = 3\r\nOutput: 2\r\nExplanation: Remove 4, 2 and either one of the two 1s or three 3s. 1 and 3 will be left.
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= arr.length <= 10^5
  • \r\n\t
  • 1 <= arr[i] <= 10^9
  • \r\n\t
  • 0 <= k <= arr.length
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr \u548c\u4e00\u4e2a\u6574\u6570 k \u3002\u73b0\u9700\u8981\u4ece\u6570\u7ec4\u4e2d\u6070\u597d\u79fb\u9664 k \u4e2a\u5143\u7d20\uff0c\u8bf7\u627e\u51fa\u79fb\u9664\u540e\u6570\u7ec4\u4e2d\u4e0d\u540c\u6574\u6570\u7684\u6700\u5c11\u6570\u76ee\u3002

\n\n
    \n
\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aarr = [5,5,4], k = 1\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u79fb\u9664 1 \u4e2a 4 \uff0c\u6570\u7ec4\u4e2d\u53ea\u5269\u4e0b 5 \u4e00\u79cd\u6574\u6570\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aarr = [4,3,1,1,3,3,2], k = 3\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5148\u79fb\u9664 4\u30012 \uff0c\u7136\u540e\u518d\u79fb\u9664\u4e24\u4e2a 1 \u4e2d\u7684\u4efb\u610f 1 \u4e2a\u6216\u8005\u4e09\u4e2a 3 \u4e2d\u7684\u4efb\u610f 1 \u4e2a\uff0c\u6700\u540e\u5269\u4e0b 1 \u548c 3 \u4e24\u79cd\u6574\u6570\u3002
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= arr.length <= 10^5
  • \n\t
  • 1 <= arr[i] <= 10^9
  • \n\t
  • 0 <= k <= arr.length
  • \n
\n", "tags_en": ["Sort", "Array"], "tags_cn": ["\u6392\u5e8f", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findLeastNumOfUniqueInts(vector& arr, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findLeastNumOfUniqueInts(int[] arr, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findLeastNumOfUniqueInts(self, arr, k):\n \"\"\"\n :type arr: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findLeastNumOfUniqueInts(self, arr: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findLeastNumOfUniqueInts(int* arr, int arrSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindLeastNumOfUniqueInts(int[] arr, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @param {number} k\n * @return {number}\n */\nvar findLeastNumOfUniqueInts = function(arr, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @param {Integer} k\n# @return {Integer}\ndef find_least_num_of_unique_ints(arr, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findLeastNumOfUniqueInts(_ arr: [Int], _ k: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findLeastNumOfUniqueInts(arr []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findLeastNumOfUniqueInts(arr: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findLeastNumOfUniqueInts(arr: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_least_num_of_unique_ints(arr: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @param Integer $k\n * @return Integer\n */\n function findLeastNumOfUniqueInts($arr, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findLeastNumOfUniqueInts(arr: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-least-num-of-unique-ints arr k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1481](https://leetcode-cn.com/problems/least-number-of-unique-integers-after-k-removals)", "[\u4e0d\u540c\u6574\u6570\u7684\u6700\u5c11\u6570\u76ee](/solution/1400-1499/1481.Least%20Number%20of%20Unique%20Integers%20after%20K%20Removals/README.md)", "`\u6392\u5e8f`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1481](https://leetcode.com/problems/least-number-of-unique-integers-after-k-removals)", "[Least Number of Unique Integers after K Removals](/solution/1400-1499/1481.Least%20Number%20of%20Unique%20Integers%20after%20K%20Removals/README_EN.md)", "`Sort`,`Array`", "Medium", ""]}, {"question_id": "1603", "frontend_question_id": "1480", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/running-sum-of-1d-array", "url_en": "https://leetcode.com/problems/running-sum-of-1d-array", "relative_path_cn": "/solution/1400-1499/1480.Running%20Sum%20of%201d%20Array/README.md", "relative_path_en": "/solution/1400-1499/1480.Running%20Sum%20of%201d%20Array/README_EN.md", "title_cn": "\u4e00\u7ef4\u6570\u7ec4\u7684\u52a8\u6001\u548c", "title_en": "Running Sum of 1d Array", "question_title_slug": "running-sum-of-1d-array", "content_en": "

Given an array nums. We define a running sum of an array as runningSum[i] = sum(nums[0]…nums[i]).

\r\n\r\n

Return the running sum of nums.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: nums = [1,2,3,4]\r\nOutput: [1,3,6,10]\r\nExplanation: Running sum is obtained as follows: [1, 1+2, 1+2+3, 1+2+3+4].
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: nums = [1,1,1,1,1]\r\nOutput: [1,2,3,4,5]\r\nExplanation: Running sum is obtained as follows: [1, 1+1, 1+1+1, 1+1+1+1, 1+1+1+1+1].
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: nums = [3,1,2,10,1]\r\nOutput: [3,4,6,16,17]\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= nums.length <= 1000
  • \r\n\t
  • -10^6 <= nums[i] <= 10^6
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 nums \u3002\u6570\u7ec4\u300c\u52a8\u6001\u548c\u300d\u7684\u8ba1\u7b97\u516c\u5f0f\u4e3a\uff1arunningSum[i] = sum(nums[0]…nums[i]) \u3002

\n\n

\u8bf7\u8fd4\u56de nums \u7684\u52a8\u6001\u548c\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,2,3,4]\n\u8f93\u51fa\uff1a[1,3,6,10]\n\u89e3\u91ca\uff1a\u52a8\u6001\u548c\u8ba1\u7b97\u8fc7\u7a0b\u4e3a [1, 1+2, 1+2+3, 1+2+3+4] \u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,1,1,1,1]\n\u8f93\u51fa\uff1a[1,2,3,4,5]\n\u89e3\u91ca\uff1a\u52a8\u6001\u548c\u8ba1\u7b97\u8fc7\u7a0b\u4e3a [1, 1+1, 1+1+1, 1+1+1+1, 1+1+1+1+1] \u3002
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1anums = [3,1,2,10,1]\n\u8f93\u51fa\uff1a[3,4,6,16,17]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 1000
  • \n\t
  • -10^6 <= nums[i] <= 10^6
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector runningSum(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] runningSum(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def runningSum(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def runningSum(self, nums: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* runningSum(int* nums, int numsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] RunningSum(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar runningSum = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer[]}\ndef running_sum(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func runningSum(_ nums: [Int]) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func runningSum(nums []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def runningSum(nums: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun runningSum(nums: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn running_sum(nums: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer[]\n */\n function runningSum($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function runningSum(nums: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (running-sum nums)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1480](https://leetcode-cn.com/problems/running-sum-of-1d-array)", "[\u4e00\u7ef4\u6570\u7ec4\u7684\u52a8\u6001\u548c](/solution/1400-1499/1480.Running%20Sum%20of%201d%20Array/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1480](https://leetcode.com/problems/running-sum-of-1d-array)", "[Running Sum of 1d Array](/solution/1400-1499/1480.Running%20Sum%20of%201d%20Array/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1587", "frontend_question_id": "1494", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/parallel-courses-ii", "url_en": "https://leetcode.com/problems/parallel-courses-ii", "relative_path_cn": "/solution/1400-1499/1494.Parallel%20Courses%20II/README.md", "relative_path_en": "/solution/1400-1499/1494.Parallel%20Courses%20II/README_EN.md", "title_cn": "\u5e76\u884c\u8bfe\u7a0b II", "title_en": "Parallel Courses II", "question_title_slug": "parallel-courses-ii", "content_en": "

You are given an integer n, which indicates that there are n courses labeled from 1 to n. You are also given an array relations where relations[i] = [prevCoursei, nextCoursei], representing a prerequisite relationship between course prevCoursei and course nextCoursei: course prevCoursei has to be taken before course nextCoursei. Also, you are given the integer k.

\n\n

In one semester, you can take at most k courses as long as you have taken all the prerequisites in the previous semester for the courses you are taking.

\n\n

Return the minimum number of semesters needed to take all courses. The testcases will be generated such that it is possible to take every course.

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: n = 4, dependencies = [[2,1],[3,1],[1,4]], k = 2\nOutput: 3 \nExplanation: The figure above represents the given graph.\nIn the first semester, you can take courses 2 and 3.\nIn the second semester, you can take course 1.\nIn the third semester, you can take course 4.\n
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: n = 5, dependencies = [[2,1],[3,1],[4,1],[1,5]], k = 2\nOutput: 4 \nExplanation: The figure above represents the given graph.\nIn the first semester, you can take courses 2 and 3 only since you cannot take more than two per semester.\nIn the second semester, you can take course 4.\nIn the third semester, you can take course 1.\nIn the fourth semester, you can take course 5.\n
\n\n

Example 3:

\n\n
\nInput: n = 11, dependencies = [], k = 2\nOutput: 6\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 15
  • \n\t
  • 1 <= k <= n
  • \n\t
  • 0 <= relations.length <= n * (n-1) / 2
  • \n\t
  • relations[i].length == 2
  • \n\t
  • 1 <= prevCoursei, nextCoursei <= n
  • \n\t
  • prevCoursei != nextCoursei
  • \n\t
  • All the pairs [prevCoursei, nextCoursei] are unique.
  • \n\t
  • The given graph is a directed acyclic graph.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n \u8868\u793a\u67d0\u6240\u5927\u5b66\u91cc\u8bfe\u7a0b\u7684\u6570\u76ee\uff0c\u7f16\u53f7\u4e3a 1 \u5230 n \uff0c\u6570\u7ec4 dependencies \u4e2d\uff0c dependencies[i] = [xi, yi]  \u8868\u793a\u4e00\u4e2a\u5148\u4fee\u8bfe\u7684\u5173\u7cfb\uff0c\u4e5f\u5c31\u662f\u8bfe\u7a0b xi \u5fc5\u987b\u5728\u8bfe\u7a0b yi \u4e4b\u524d\u4e0a\u3002\u540c\u65f6\u4f60\u8fd8\u6709\u4e00\u4e2a\u6574\u6570 k \u3002

\n\n

\u5728\u4e00\u4e2a\u5b66\u671f\u4e2d\uff0c\u4f60 \u6700\u591a \u53ef\u4ee5\u540c\u65f6\u4e0a k \u95e8\u8bfe\uff0c\u524d\u63d0\u662f\u8fd9\u4e9b\u8bfe\u7684\u5148\u4fee\u8bfe\u5728\u4e4b\u524d\u7684\u5b66\u671f\u91cc\u5df2\u7ecf\u4e0a\u8fc7\u4e86\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u4e0a\u5b8c\u6240\u6709\u8bfe\u6700\u5c11\u9700\u8981\u591a\u5c11\u4e2a\u5b66\u671f\u3002\u9898\u76ee\u4fdd\u8bc1\u4e00\u5b9a\u5b58\u5728\u4e00\u79cd\u4e0a\u5b8c\u6240\u6709\u8bfe\u7684\u65b9\u5f0f\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1an = 4, dependencies = [[2,1],[3,1],[1,4]], k = 2\n\u8f93\u51fa\uff1a3 \n\u89e3\u91ca\uff1a\u4e0a\u56fe\u5c55\u793a\u4e86\u9898\u76ee\u8f93\u5165\u7684\u56fe\u3002\u5728\u7b2c\u4e00\u4e2a\u5b66\u671f\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4e0a\u8bfe\u7a0b 2 \u548c\u8bfe\u7a0b 3 \u3002\u7136\u540e\u7b2c\u4e8c\u4e2a\u5b66\u671f\u4e0a\u8bfe\u7a0b 1 \uff0c\u7b2c\u4e09\u4e2a\u5b66\u671f\u4e0a\u8bfe\u7a0b 4 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1an = 5, dependencies = [[2,1],[3,1],[4,1],[1,5]], k = 2\n\u8f93\u51fa\uff1a4 \n\u89e3\u91ca\uff1a\u4e0a\u56fe\u5c55\u793a\u4e86\u9898\u76ee\u8f93\u5165\u7684\u56fe\u3002\u4e00\u4e2a\u6700\u4f18\u65b9\u6848\u662f\uff1a\u7b2c\u4e00\u5b66\u671f\u4e0a\u8bfe\u7a0b 2 \u548c 3\uff0c\u7b2c\u4e8c\u5b66\u671f\u4e0a\u8bfe\u7a0b 4 \uff0c\u7b2c\u4e09\u5b66\u671f\u4e0a\u8bfe\u7a0b 1 \uff0c\u7b2c\u56db\u5b66\u671f\u4e0a\u8bfe\u7a0b 5 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1an = 11, dependencies = [], k = 2\n\u8f93\u51fa\uff1a6\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 15
  • \n\t
  • 1 <= k <= n
  • \n\t
  • 0 <= dependencies.length <= n * (n-1) / 2
  • \n\t
  • dependencies[i].length == 2
  • \n\t
  • 1 <= xi, yi <= n
  • \n\t
  • xi != yi
  • \n\t
  • \u6240\u6709\u5148\u4fee\u5173\u7cfb\u90fd\u662f\u4e0d\u540c\u7684\uff0c\u4e5f\u5c31\u662f\u8bf4 dependencies[i] != dependencies[j] \u3002
  • \n\t
  • \u9898\u76ee\u8f93\u5165\u7684\u56fe\u662f\u4e2a\u6709\u5411\u65e0\u73af\u56fe\u3002
  • \n
\n", "tags_en": ["Graph"], "tags_cn": ["\u56fe"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minNumberOfSemesters(int n, vector>& relations, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minNumberOfSemesters(int n, int[][] relations, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minNumberOfSemesters(self, n, relations, k):\n \"\"\"\n :type n: int\n :type relations: List[List[int]]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minNumberOfSemesters(self, n: int, relations: List[List[int]], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minNumberOfSemesters(int n, int** relations, int relationsSize, int* relationsColSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinNumberOfSemesters(int n, int[][] relations, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} relations\n * @param {number} k\n * @return {number}\n */\nvar minNumberOfSemesters = function(n, relations, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} relations\n# @param {Integer} k\n# @return {Integer}\ndef min_number_of_semesters(n, relations, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minNumberOfSemesters(_ n: Int, _ relations: [[Int]], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minNumberOfSemesters(n int, relations [][]int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minNumberOfSemesters(n: Int, relations: Array[Array[Int]], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minNumberOfSemesters(n: Int, relations: Array, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_number_of_semesters(n: i32, relations: Vec>, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $relations\n * @param Integer $k\n * @return Integer\n */\n function minNumberOfSemesters($n, $relations, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minNumberOfSemesters(n: number, relations: number[][], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-number-of-semesters n relations k)\n (-> exact-integer? (listof (listof exact-integer?)) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1494](https://leetcode-cn.com/problems/parallel-courses-ii)", "[\u5e76\u884c\u8bfe\u7a0b II](/solution/1400-1499/1494.Parallel%20Courses%20II/README.md)", "`\u56fe`", "\u56f0\u96be", ""], "md_table_row_en": ["[1494](https://leetcode.com/problems/parallel-courses-ii)", "[Parallel Courses II](/solution/1400-1499/1494.Parallel%20Courses%20II/README_EN.md)", "`Graph`", "Hard", ""]}, {"question_id": "1586", "frontend_question_id": "1493", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-subarray-of-1s-after-deleting-one-element", "url_en": "https://leetcode.com/problems/longest-subarray-of-1s-after-deleting-one-element", "relative_path_cn": "/solution/1400-1499/1493.Longest%20Subarray%20of%201%27s%20After%20Deleting%20One%20Element/README.md", "relative_path_en": "/solution/1400-1499/1493.Longest%20Subarray%20of%201%27s%20After%20Deleting%20One%20Element/README_EN.md", "title_cn": "\u5220\u6389\u4e00\u4e2a\u5143\u7d20\u4ee5\u540e\u5168\u4e3a 1 \u7684\u6700\u957f\u5b50\u6570\u7ec4", "title_en": "Longest Subarray of 1's After Deleting One Element", "question_title_slug": "longest-subarray-of-1s-after-deleting-one-element", "content_en": "

Given a binary array nums, you should delete one element from it.

\n\n

Return the size of the longest non-empty subarray containing only 1's in the resulting array.

\n\n

Return 0 if there is no such subarray.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [1,1,0,1]\nOutput: 3\nExplanation: After deleting the number in position 2, [1,1,1] contains 3 numbers with value of 1's.
\n\n

Example 2:

\n\n
\nInput: nums = [0,1,1,1,0,1,1,0,1]\nOutput: 5\nExplanation: After deleting the number in position 4, [0,1,1,1,1,1,0,1] longest subarray with value of 1's is [1,1,1,1,1].
\n\n

Example 3:

\n\n
\nInput: nums = [1,1,1]\nOutput: 2\nExplanation: You must delete one element.
\n\n

Example 4:

\n\n
\nInput: nums = [1,1,0,0,1,1,1,0,1]\nOutput: 4\n
\n\n

Example 5:

\n\n
\nInput: nums = [0,0,0]\nOutput: 0\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 10^5
  • \n\t
  • nums[i] is either 0 or 1.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u4e8c\u8fdb\u5236\u6570\u7ec4 nums \uff0c\u4f60\u9700\u8981\u4ece\u4e2d\u5220\u6389\u4e00\u4e2a\u5143\u7d20\u3002

\n\n

\u8bf7\u4f60\u5728\u5220\u6389\u5143\u7d20\u7684\u7ed3\u679c\u6570\u7ec4\u4e2d\uff0c\u8fd4\u56de\u6700\u957f\u7684\u4e14\u53ea\u5305\u542b 1 \u7684\u975e\u7a7a\u5b50\u6570\u7ec4\u7684\u957f\u5ea6\u3002

\n\n

\u5982\u679c\u4e0d\u5b58\u5728\u8fd9\u6837\u7684\u5b50\u6570\u7ec4\uff0c\u8bf7\u8fd4\u56de 0 \u3002

\n\n

 

\n\n

\u63d0\u793a 1\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,1,0,1]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u5220\u6389\u4f4d\u7f6e 2 \u7684\u6570\u540e\uff0c[1,1,1] \u5305\u542b 3 \u4e2a 1 \u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anums = [0,1,1,1,0,1,1,0,1]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u5220\u6389\u4f4d\u7f6e 4 \u7684\u6570\u5b57\u540e\uff0c[0,1,1,1,1,1,0,1] \u7684\u6700\u957f\u5168 1 \u5b50\u6570\u7ec4\u4e3a [1,1,1,1,1] \u3002
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,1,1]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u4f60\u5fc5\u987b\u8981\u5220\u9664\u4e00\u4e2a\u5143\u7d20\u3002
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,1,0,0,1,1,1,0,1]\n\u8f93\u51fa\uff1a4\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1anums = [0,0,0]\n\u8f93\u51fa\uff1a0\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 10^5
  • \n\t
  • nums[i] \u8981\u4e48\u662f 0 \u8981\u4e48\u662f 1 \u3002
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int longestSubarray(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int longestSubarray(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestSubarray(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestSubarray(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint longestSubarray(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LongestSubarray(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar longestSubarray = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef longest_subarray(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestSubarray(_ nums: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestSubarray(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestSubarray(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestSubarray(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_subarray(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function longestSubarray($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestSubarray(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-subarray nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1493](https://leetcode-cn.com/problems/longest-subarray-of-1s-after-deleting-one-element)", "[\u5220\u6389\u4e00\u4e2a\u5143\u7d20\u4ee5\u540e\u5168\u4e3a 1 \u7684\u6700\u957f\u5b50\u6570\u7ec4](/solution/1400-1499/1493.Longest%20Subarray%20of%201%27s%20After%20Deleting%20One%20Element/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1493](https://leetcode.com/problems/longest-subarray-of-1s-after-deleting-one-element)", "[Longest Subarray of 1's After Deleting One Element](/solution/1400-1499/1493.Longest%20Subarray%20of%201%27s%20After%20Deleting%20One%20Element/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "1585", "frontend_question_id": "1492", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/the-kth-factor-of-n", "url_en": "https://leetcode.com/problems/the-kth-factor-of-n", "relative_path_cn": "/solution/1400-1499/1492.The%20kth%20Factor%20of%20n/README.md", "relative_path_en": "/solution/1400-1499/1492.The%20kth%20Factor%20of%20n/README_EN.md", "title_cn": "n \u7684\u7b2c k \u4e2a\u56e0\u5b50", "title_en": "The kth Factor of n", "question_title_slug": "the-kth-factor-of-n", "content_en": "

Given two positive integers n and k.

\r\n\r\n

A factor of an integer n is defined as an integer i where n % i == 0.

\r\n\r\n

Consider a list of all factors of n sorted in ascending order, return the kth factor in this list or return -1 if n has less than k factors.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: n = 12, k = 3\r\nOutput: 3\r\nExplanation: Factors list is [1, 2, 3, 4, 6, 12], the 3rd factor is 3.\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: n = 7, k = 2\r\nOutput: 7\r\nExplanation: Factors list is [1, 7], the 2nd factor is 7.\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: n = 4, k = 4\r\nOutput: -1\r\nExplanation: Factors list is [1, 2, 4], there is only 3 factors. We should return -1.\r\n
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: n = 1, k = 1\r\nOutput: 1\r\nExplanation: Factors list is [1], the 1st factor is 1.\r\n
\r\n\r\n

Example 5:

\r\n\r\n
\r\nInput: n = 1000, k = 3\r\nOutput: 4\r\nExplanation: Factors list is [1, 2, 4, 5, 8, 10, 20, 25, 40, 50, 100, 125, 200, 250, 500, 1000].\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= k <= n <= 1000
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e24\u4e2a\u6b63\u6574\u6570 n \u548c k \u3002

\n\n

\u5982\u679c\u6b63\u6574\u6570 i \u6ee1\u8db3 n % i == 0 \uff0c\u90a3\u4e48\u6211\u4eec\u5c31\u8bf4\u6b63\u6574\u6570 i \u662f\u6574\u6570 n \u7684\u56e0\u5b50\u3002

\n\n

\u8003\u8651\u6574\u6570 n \u7684\u6240\u6709\u56e0\u5b50\uff0c\u5c06\u5b83\u4eec \u5347\u5e8f\u6392\u5217 \u3002\u8bf7\u4f60\u8fd4\u56de\u7b2c k \u4e2a\u56e0\u5b50\u3002\u5982\u679c n \u7684\u56e0\u5b50\u6570\u5c11\u4e8e k \uff0c\u8bf7\u4f60\u8fd4\u56de -1 \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1an = 12, k = 3\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u56e0\u5b50\u5217\u8868\u5305\u62ec [1, 2, 3, 4, 6, 12]\uff0c\u7b2c 3 \u4e2a\u56e0\u5b50\u662f 3 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1an = 7, k = 2\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\u56e0\u5b50\u5217\u8868\u5305\u62ec [1, 7] \uff0c\u7b2c 2 \u4e2a\u56e0\u5b50\u662f 7 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1an = 4, k = 4\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u56e0\u5b50\u5217\u8868\u5305\u62ec [1, 2, 4] \uff0c\u53ea\u6709 3 \u4e2a\u56e0\u5b50\uff0c\u6240\u4ee5\u6211\u4eec\u5e94\u8be5\u8fd4\u56de -1 \u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1an = 1, k = 1\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u56e0\u5b50\u5217\u8868\u5305\u62ec [1] \uff0c\u7b2c 1 \u4e2a\u56e0\u5b50\u4e3a 1 \u3002\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1an = 1000, k = 3\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u56e0\u5b50\u5217\u8868\u5305\u62ec [1, 2, 4, 5, 8, 10, 20, 25, 40, 50, 100, 125, 200, 250, 500, 1000] \u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= k <= n <= 1000
  • \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int kthFactor(int n, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int kthFactor(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def kthFactor(self, n, k):\n \"\"\"\n :type n: int\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def kthFactor(self, n: int, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint kthFactor(int n, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int KthFactor(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} k\n * @return {number}\n */\nvar kthFactor = function(n, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} k\n# @return {Integer}\ndef kth_factor(n, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func kthFactor(_ n: Int, _ k: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func kthFactor(n int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def kthFactor(n: Int, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun kthFactor(n: Int, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn kth_factor(n: i32, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $k\n * @return Integer\n */\n function kthFactor($n, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function kthFactor(n: number, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (kth-factor n k)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1492](https://leetcode-cn.com/problems/the-kth-factor-of-n)", "[n \u7684\u7b2c k \u4e2a\u56e0\u5b50](/solution/1400-1499/1492.The%20kth%20Factor%20of%20n/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1492](https://leetcode.com/problems/the-kth-factor-of-n)", "[The kth Factor of n](/solution/1400-1499/1492.The%20kth%20Factor%20of%20n/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "1584", "frontend_question_id": "1491", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/average-salary-excluding-the-minimum-and-maximum-salary", "url_en": "https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary", "relative_path_cn": "/solution/1400-1499/1491.Average%20Salary%20Excluding%20the%20Minimum%20and%20Maximum%20Salary/README.md", "relative_path_en": "/solution/1400-1499/1491.Average%20Salary%20Excluding%20the%20Minimum%20and%20Maximum%20Salary/README_EN.md", "title_cn": "\u53bb\u6389\u6700\u4f4e\u5de5\u8d44\u548c\u6700\u9ad8\u5de5\u8d44\u540e\u7684\u5de5\u8d44\u5e73\u5747\u503c", "title_en": "Average Salary Excluding the Minimum and Maximum Salary", "question_title_slug": "average-salary-excluding-the-minimum-and-maximum-salary", "content_en": "

Given an array of unique integers salary where salary[i] is the salary of the employee i.

\r\n\r\n

Return the average salary of employees excluding the minimum and maximum salary.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: salary = [4000,3000,1000,2000]\r\nOutput: 2500.00000\r\nExplanation: Minimum salary and maximum salary are 1000 and 4000 respectively.\r\nAverage salary excluding minimum and maximum salary is (2000+3000)/2= 2500\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: salary = [1000,2000,3000]\r\nOutput: 2000.00000\r\nExplanation: Minimum salary and maximum salary are 1000 and 3000 respectively.\r\nAverage salary excluding minimum and maximum salary is (2000)/1= 2000\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: salary = [6000,5000,4000,3000,2000,1000]\r\nOutput: 3500.00000\r\n
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: salary = [8000,9000,2000,3000,6000,1000]\r\nOutput: 4750.00000\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 3 <= salary.length <= 100
  • \r\n\t
  • 10^3 <= salary[i] <= 10^6
  • \r\n\t
  • salary[i] is unique.
  • \r\n\t
  • Answers within 10^-5 of the actual value will be accepted as correct.
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 salary \uff0c\u6570\u7ec4\u91cc\u6bcf\u4e2a\u6570\u90fd\u662f \u552f\u4e00 \u7684\uff0c\u5176\u4e2d salary[i] \u662f\u7b2c i \u4e2a\u5458\u5de5\u7684\u5de5\u8d44\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u53bb\u6389\u6700\u4f4e\u5de5\u8d44\u548c\u6700\u9ad8\u5de5\u8d44\u4ee5\u540e\uff0c\u5269\u4e0b\u5458\u5de5\u5de5\u8d44\u7684\u5e73\u5747\u503c\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1asalary = [4000,3000,1000,2000]\n\u8f93\u51fa\uff1a2500.00000\n\u89e3\u91ca\uff1a\u6700\u4f4e\u5de5\u8d44\u548c\u6700\u9ad8\u5de5\u8d44\u5206\u522b\u662f 1000 \u548c 4000 \u3002\n\u53bb\u6389\u6700\u4f4e\u5de5\u8d44\u548c\u6700\u9ad8\u5de5\u8d44\u4ee5\u540e\u7684\u5e73\u5747\u5de5\u8d44\u662f (2000+3000)/2= 2500\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1asalary = [1000,2000,3000]\n\u8f93\u51fa\uff1a2000.00000\n\u89e3\u91ca\uff1a\u6700\u4f4e\u5de5\u8d44\u548c\u6700\u9ad8\u5de5\u8d44\u5206\u522b\u662f 1000 \u548c 3000 \u3002\n\u53bb\u6389\u6700\u4f4e\u5de5\u8d44\u548c\u6700\u9ad8\u5de5\u8d44\u4ee5\u540e\u7684\u5e73\u5747\u5de5\u8d44\u662f (2000)/1= 2000\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1asalary = [6000,5000,4000,3000,2000,1000]\n\u8f93\u51fa\uff1a3500.00000\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1asalary = [8000,9000,2000,3000,6000,1000]\n\u8f93\u51fa\uff1a4750.00000\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 3 <= salary.length <= 100
  • \n\t
  • 10^3 <= salary[i] <= 10^6
  • \n\t
  • salary[i] \u662f\u552f\u4e00\u7684\u3002
  • \n\t
  • \u4e0e\u771f\u5b9e\u503c\u8bef\u5dee\u5728 10^-5 \u4ee5\u5185\u7684\u7ed3\u679c\u90fd\u5c06\u89c6\u4e3a\u6b63\u786e\u7b54\u6848\u3002
  • \n
\n", "tags_en": ["Sort", "Array"], "tags_cn": ["\u6392\u5e8f", "\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n double average(vector& salary) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double average(int[] salary) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def average(self, salary):\n \"\"\"\n :type salary: List[int]\n :rtype: float\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def average(self, salary: List[int]) -> float:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\ndouble average(int* salary, int salarySize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double Average(int[] salary) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} salary\n * @return {number}\n */\nvar average = function(salary) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} salary\n# @return {Float}\ndef average(salary)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func average(_ salary: [Int]) -> Double {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func average(salary []int) float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def average(salary: Array[Int]): Double = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun average(salary: IntArray): Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn average(salary: Vec) -> f64 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $salary\n * @return Float\n */\n function average($salary) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function average(salary: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (average salary)\n (-> (listof exact-integer?) flonum?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1491](https://leetcode-cn.com/problems/average-salary-excluding-the-minimum-and-maximum-salary)", "[\u53bb\u6389\u6700\u4f4e\u5de5\u8d44\u548c\u6700\u9ad8\u5de5\u8d44\u540e\u7684\u5de5\u8d44\u5e73\u5747\u503c](/solution/1400-1499/1491.Average%20Salary%20Excluding%20the%20Minimum%20and%20Maximum%20Salary/README.md)", "`\u6392\u5e8f`,`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1491](https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary)", "[Average Salary Excluding the Minimum and Maximum Salary](/solution/1400-1499/1491.Average%20Salary%20Excluding%20the%20Minimum%20and%20Maximum%20Salary/README_EN.md)", "`Sort`,`Array`", "Easy", ""]}, {"question_id": "1583", "frontend_question_id": "1473", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/paint-house-iii", "url_en": "https://leetcode.com/problems/paint-house-iii", "relative_path_cn": "/solution/1400-1499/1473.Paint%20House%20III/README.md", "relative_path_en": "/solution/1400-1499/1473.Paint%20House%20III/README_EN.md", "title_cn": "\u7c89\u5237\u623f\u5b50 III", "title_en": "Paint House III", "question_title_slug": "paint-house-iii", "content_en": "

There is a row of m houses in a small city, each house must be painted with one of the n colors (labeled from 1 to n), some houses that have been painted last summer should not be painted again.

\n\n

A neighborhood is a maximal group of continuous houses that are painted with the same color.

\n\n
    \n\t
  • For example: houses = [1,2,2,3,3,2,1,1] contains 5 neighborhoods [{1}, {2,2}, {3,3}, {2}, {1,1}].
  • \n
\n\n

Given an array houses, an m x n matrix cost and an integer target where:

\n\n
    \n\t
  • houses[i]: is the color of the house i, and 0 if the house is not painted yet.
  • \n\t
  • cost[i][j]: is the cost of paint the house i with the color j + 1.
  • \n
\n\n

Return the minimum cost of painting all the remaining houses in such a way that there are exactly target neighborhoods. If it is not possible, return -1.

\n\n

 

\n

Example 1:

\n\n
\nInput: houses = [0,0,0,0,0], cost = [[1,10],[10,1],[10,1],[1,10],[5,1]], m = 5, n = 2, target = 3\nOutput: 9\nExplanation: Paint houses of this way [1,2,2,1,1]\nThis array contains target = 3 neighborhoods, [{1}, {2,2}, {1,1}].\nCost of paint all houses (1 + 1 + 1 + 1 + 5) = 9.\n
\n\n

Example 2:

\n\n
\nInput: houses = [0,2,1,2,0], cost = [[1,10],[10,1],[10,1],[1,10],[5,1]], m = 5, n = 2, target = 3\nOutput: 11\nExplanation: Some houses are already painted, Paint the houses of this way [2,2,1,2,2]\nThis array contains target = 3 neighborhoods, [{2,2}, {1}, {2,2}]. \nCost of paint the first and last house (10 + 1) = 11.\n
\n\n

Example 3:

\n\n
\nInput: houses = [0,0,0,0,0], cost = [[1,10],[10,1],[1,10],[10,1],[1,10]], m = 5, n = 2, target = 5\nOutput: 5\n
\n\n

Example 4:

\n\n
\nInput: houses = [3,1,2,3], cost = [[1,1,1],[1,1,1],[1,1,1],[1,1,1]], m = 4, n = 3, target = 3\nOutput: -1\nExplanation: Houses are already painted with a total of 4 neighborhoods [{3},{1},{2},{3}] different of target = 3.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • m == houses.length == cost.length
  • \n\t
  • n == cost[i].length
  • \n\t
  • 1 <= m <= 100
  • \n\t
  • 1 <= n <= 20
  • \n\t
  • 1 <= target <= m
  • \n\t
  • 0 <= houses[i] <= n
  • \n\t
  • 1 <= cost[i][j] <= 10^4
  • \n
\n", "content_cn": "

\u5728\u4e00\u4e2a\u5c0f\u57ce\u5e02\u91cc\uff0c\u6709\u00a0m\u00a0\u4e2a\u623f\u5b50\u6392\u6210\u4e00\u6392\uff0c\u4f60\u9700\u8981\u7ed9\u6bcf\u4e2a\u623f\u5b50\u6d82\u4e0a n\u00a0\u79cd\u989c\u8272\u4e4b\u4e00\uff08\u989c\u8272\u7f16\u53f7\u4e3a 1 \u5230 n\u00a0\uff09\u3002\u6709\u7684\u623f\u5b50\u53bb\u5e74\u590f\u5929\u5df2\u7ecf\u6d82\u8fc7\u989c\u8272\u4e86\uff0c\u6240\u4ee5\u8fd9\u4e9b\u623f\u5b50\u4e0d\u53ef\u4ee5\u88ab\u91cd\u65b0\u6d82\u8272\u3002

\n\n

\u6211\u4eec\u5c06\u8fde\u7eed\u76f8\u540c\u989c\u8272\u5c3d\u53ef\u80fd\u591a\u7684\u623f\u5b50\u79f0\u4e3a\u4e00\u4e2a\u8857\u533a\u3002\uff08\u6bd4\u65b9\u8bf4 houses = [1,2,2,3,3,2,1,1] \uff0c\u5b83\u5305\u542b 5 \u4e2a\u8857\u533a\u00a0 [{1}, {2,2}, {3,3}, {2}, {1,1}] \u3002\uff09

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4\u00a0houses\u00a0\uff0c\u4e00\u4e2a\u00a0m * n\u00a0\u7684\u77e9\u9635\u00a0cost\u00a0\u548c\u4e00\u4e2a\u6574\u6570\u00a0target\u00a0\uff0c\u5176\u4e2d\uff1a

\n\n
    \n\t
  • houses[i]\uff1a\u662f\u7b2c\u00a0i\u00a0\u4e2a\u623f\u5b50\u7684\u989c\u8272\uff0c0\u00a0\u8868\u793a\u8fd9\u4e2a\u623f\u5b50\u8fd8\u6ca1\u6709\u88ab\u6d82\u8272\u3002
  • \n\t
  • cost[i][j]\uff1a\u662f\u5c06\u7b2c\u00a0i\u00a0\u4e2a\u623f\u5b50\u6d82\u6210\u989c\u8272\u00a0j+1\u00a0\u7684\u82b1\u8d39\u3002
  • \n
\n\n

\u8bf7\u4f60\u8fd4\u56de\u623f\u5b50\u6d82\u8272\u65b9\u6848\u7684\u6700\u5c0f\u603b\u82b1\u8d39\uff0c\u4f7f\u5f97\u6bcf\u4e2a\u623f\u5b50\u90fd\u88ab\u6d82\u8272\u540e\uff0c\u6070\u597d\u7ec4\u6210\u00a0target\u00a0\u4e2a\u8857\u533a\u3002\u5982\u679c\u6ca1\u6709\u53ef\u7528\u7684\u6d82\u8272\u65b9\u6848\uff0c\u8bf7\u8fd4\u56de\u00a0-1\u00a0\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1ahouses = [0,0,0,0,0], cost = [[1,10],[10,1],[10,1],[1,10],[5,1]], m = 5, n = 2, target = 3\n\u8f93\u51fa\uff1a9\n\u89e3\u91ca\uff1a\u623f\u5b50\u6d82\u8272\u65b9\u6848\u4e3a [1,2,2,1,1]\n\u6b64\u65b9\u6848\u5305\u542b target = 3 \u4e2a\u8857\u533a\uff0c\u5206\u522b\u662f [{1}, {2,2}, {1,1}]\u3002\n\u6d82\u8272\u7684\u603b\u82b1\u8d39\u4e3a (1 + 1 + 1 + 1 + 5) = 9\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1ahouses = [0,2,1,2,0], cost = [[1,10],[10,1],[10,1],[1,10],[5,1]], m = 5, n = 2, target = 3\n\u8f93\u51fa\uff1a11\n\u89e3\u91ca\uff1a\u6709\u7684\u623f\u5b50\u5df2\u7ecf\u88ab\u6d82\u8272\u4e86\uff0c\u5728\u6b64\u57fa\u7840\u4e0a\u6d82\u8272\u65b9\u6848\u4e3a [2,2,1,2,2]\n\u6b64\u65b9\u6848\u5305\u542b target = 3 \u4e2a\u8857\u533a\uff0c\u5206\u522b\u662f [{2,2}, {1}, {2,2}]\u3002\n\u7ed9\u7b2c\u4e00\u4e2a\u548c\u6700\u540e\u4e00\u4e2a\u623f\u5b50\u6d82\u8272\u7684\u82b1\u8d39\u4e3a (10 + 1) = 11\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1ahouses = [0,0,0,0,0], cost = [[1,10],[10,1],[1,10],[10,1],[1,10]], m = 5, n = 2, target = 5\n\u8f93\u51fa\uff1a5\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1ahouses = [3,1,2,3], cost = [[1,1,1],[1,1,1],[1,1,1],[1,1,1]], m = 4, n = 3, target = 3\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u623f\u5b50\u5df2\u7ecf\u88ab\u6d82\u8272\u5e76\u7ec4\u6210\u4e86 4 \u4e2a\u8857\u533a\uff0c\u5206\u522b\u662f [{3},{1},{2},{3}] \uff0c\u65e0\u6cd5\u5f62\u6210 target = 3 \u4e2a\u8857\u533a\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • m == houses.length == cost.length
  • \n\t
  • n == cost[i].length
  • \n\t
  • 1 <= m <= 100
  • \n\t
  • 1 <= n <= 20
  • \n\t
  • 1 <= target\u00a0<= m
  • \n\t
  • 0 <= houses[i]\u00a0<= n
  • \n\t
  • 1 <= cost[i][j] <= 10^4
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minCost(vector& houses, vector>& cost, int m, int n, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minCost(int[] houses, int[][] cost, int m, int n, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minCost(self, houses, cost, m, n, target):\n \"\"\"\n :type houses: List[int]\n :type cost: List[List[int]]\n :type m: int\n :type n: int\n :type target: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minCost(self, houses: List[int], cost: List[List[int]], m: int, n: int, target: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minCost(int* houses, int housesSize, int** cost, int costSize, int* costColSize, int m, int n, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinCost(int[] houses, int[][] cost, int m, int n, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} houses\n * @param {number[][]} cost\n * @param {number} m\n * @param {number} n\n * @param {number} target\n * @return {number}\n */\nvar minCost = function(houses, cost, m, n, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} houses\n# @param {Integer[][]} cost\n# @param {Integer} m\n# @param {Integer} n\n# @param {Integer} target\n# @return {Integer}\ndef min_cost(houses, cost, m, n, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minCost(_ houses: [Int], _ cost: [[Int]], _ m: Int, _ n: Int, _ target: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minCost(houses []int, cost [][]int, m int, n int, target int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minCost(houses: Array[Int], cost: Array[Array[Int]], m: Int, n: Int, target: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minCost(houses: IntArray, cost: Array, m: Int, n: Int, target: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_cost(houses: Vec, cost: Vec>, m: i32, n: i32, target: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $houses\n * @param Integer[][] $cost\n * @param Integer $m\n * @param Integer $n\n * @param Integer $target\n * @return Integer\n */\n function minCost($houses, $cost, $m, $n, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minCost(houses: number[], cost: number[][], m: number, n: number, target: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-cost houses cost m n target)\n (-> (listof exact-integer?) (listof (listof exact-integer?)) exact-integer? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1473](https://leetcode-cn.com/problems/paint-house-iii)", "[\u7c89\u5237\u623f\u5b50 III](/solution/1400-1499/1473.Paint%20House%20III/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1473](https://leetcode.com/problems/paint-house-iii)", "[Paint House III](/solution/1400-1499/1473.Paint%20House%20III/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1582", "frontend_question_id": "1472", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/design-browser-history", "url_en": "https://leetcode.com/problems/design-browser-history", "relative_path_cn": "/solution/1400-1499/1472.Design%20Browser%20History/README.md", "relative_path_en": "/solution/1400-1499/1472.Design%20Browser%20History/README_EN.md", "title_cn": "\u8bbe\u8ba1\u6d4f\u89c8\u5668\u5386\u53f2\u8bb0\u5f55", "title_en": "Design Browser History", "question_title_slug": "design-browser-history", "content_en": "

You have a browser of one tab where you start on the homepage and you can visit another url, get back in the history number of steps or move forward in the history number of steps.

\n\n

Implement the BrowserHistory class:

\n\n
    \n\t
  • BrowserHistory(string homepage) Initializes the object with the homepage of the browser.
  • \n\t
  • void visit(string url) Visits url from the current page. It clears up all the forward history.
  • \n\t
  • string back(int steps) Move steps back in history. If you can only return x steps in the history and steps > x, you will return only x steps. Return the current url after moving back in history at most steps.
  • \n\t
  • string forward(int steps) Move steps forward in history. If you can only forward x steps in the history and steps > x, you will forward only x steps. Return the current url after forwarding in history at most steps.
  • \n
\n\n

 

\n

Example:

\n\n
\nInput:\n["BrowserHistory","visit","visit","visit","back","back","forward","visit","forward","back","back"]\n[["leetcode.com"],["google.com"],["facebook.com"],["youtube.com"],[1],[1],[1],["linkedin.com"],[2],[2],[7]]\nOutput:\n[null,null,null,null,"facebook.com","google.com","facebook.com",null,"linkedin.com","google.com","leetcode.com"]\n\nExplanation:\nBrowserHistory browserHistory = new BrowserHistory("leetcode.com");\nbrowserHistory.visit("google.com");       // You are in "leetcode.com". Visit "google.com"\nbrowserHistory.visit("facebook.com");     // You are in "google.com". Visit "facebook.com"\nbrowserHistory.visit("youtube.com");      // You are in "facebook.com". Visit "youtube.com"\nbrowserHistory.back(1);                   // You are in "youtube.com", move back to "facebook.com" return "facebook.com"\nbrowserHistory.back(1);                   // You are in "facebook.com", move back to "google.com" return "google.com"\nbrowserHistory.forward(1);                // You are in "google.com", move forward to "facebook.com" return "facebook.com"\nbrowserHistory.visit("linkedin.com");     // You are in "facebook.com". Visit "linkedin.com"\nbrowserHistory.forward(2);                // You are in "linkedin.com", you cannot move forward any steps.\nbrowserHistory.back(2);                   // You are in "linkedin.com", move back two steps to "facebook.com" then to "google.com". return "google.com"\nbrowserHistory.back(7);                   // You are in "google.com", you can move back only one step to "leetcode.com". return "leetcode.com"\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= homepage.length <= 20
  • \n\t
  • 1 <= url.length <= 20
  • \n\t
  • 1 <= steps <= 100
  • \n\t
  • homepage and url consist of  '.' or lower case English letters.
  • \n\t
  • At most 5000 calls will be made to visit, back, and forward.
  • \n
\n", "content_cn": "

\u4f60\u6709\u4e00\u4e2a\u53ea\u652f\u6301\u5355\u4e2a\u6807\u7b7e\u9875\u7684 \u6d4f\u89c8\u5668 \uff0c\u6700\u5f00\u59cb\u4f60\u6d4f\u89c8\u7684\u7f51\u9875\u662f homepage \uff0c\u4f60\u53ef\u4ee5\u8bbf\u95ee\u5176\u4ed6\u7684\u7f51\u7ad9 url \uff0c\u4e5f\u53ef\u4ee5\u5728\u6d4f\u89c8\u5386\u53f2\u4e2d\u540e\u9000 steps \u6b65\u6216\u524d\u8fdb steps \u6b65\u3002

\n\n

\u8bf7\u4f60\u5b9e\u73b0 BrowserHistory \u7c7b\uff1a

\n\n
    \n\t
  • BrowserHistory(string homepage) \uff0c\u7528 homepage \u521d\u59cb\u5316\u6d4f\u89c8\u5668\u7c7b\u3002
  • \n\t
  • void visit(string url) \u4ece\u5f53\u524d\u9875\u8df3\u8f6c\u8bbf\u95ee url \u5bf9\u5e94\u7684\u9875\u9762  \u3002\u6267\u884c\u6b64\u64cd\u4f5c\u4f1a\u628a\u6d4f\u89c8\u5386\u53f2\u524d\u8fdb\u7684\u8bb0\u5f55\u5168\u90e8\u5220\u9664\u3002
  • \n\t
  • string back(int steps) \u5728\u6d4f\u89c8\u5386\u53f2\u4e2d\u540e\u9000 steps \u6b65\u3002\u5982\u679c\u4f60\u53ea\u80fd\u5728\u6d4f\u89c8\u5386\u53f2\u4e2d\u540e\u9000\u81f3\u591a x \u6b65\u4e14 steps > x \uff0c\u90a3\u4e48\u4f60\u53ea\u540e\u9000 x \u6b65\u3002\u8bf7\u8fd4\u56de\u540e\u9000 \u81f3\u591a steps \u6b65\u4ee5\u540e\u7684 url \u3002
  • \n\t
  • string forward(int steps) \u5728\u6d4f\u89c8\u5386\u53f2\u4e2d\u524d\u8fdb steps \u6b65\u3002\u5982\u679c\u4f60\u53ea\u80fd\u5728\u6d4f\u89c8\u5386\u53f2\u4e2d\u524d\u8fdb\u81f3\u591a x \u6b65\u4e14 steps > x \uff0c\u90a3\u4e48\u4f60\u53ea\u524d\u8fdb x \u6b65\u3002\u8bf7\u8fd4\u56de\u524d\u8fdb \u81f3\u591a steps\u6b65\u4ee5\u540e\u7684 url \u3002
  • \n
\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1a\n["BrowserHistory","visit","visit","visit","back","back","forward","visit","forward","back","back"]\n[["leetcode.com"],["google.com"],["facebook.com"],["youtube.com"],[1],[1],[1],["linkedin.com"],[2],[2],[7]]\n\u8f93\u51fa\uff1a\n[null,null,null,null,"facebook.com","google.com","facebook.com",null,"linkedin.com","google.com","leetcode.com"]\n\n\u89e3\u91ca\uff1a\nBrowserHistory browserHistory = new BrowserHistory("leetcode.com");\nbrowserHistory.visit("google.com");       // \u4f60\u539f\u672c\u5728\u6d4f\u89c8 "leetcode.com" \u3002\u8bbf\u95ee "google.com"\nbrowserHistory.visit("facebook.com");     // \u4f60\u539f\u672c\u5728\u6d4f\u89c8 "google.com" \u3002\u8bbf\u95ee "facebook.com"\nbrowserHistory.visit("youtube.com");      // \u4f60\u539f\u672c\u5728\u6d4f\u89c8 "facebook.com" \u3002\u8bbf\u95ee "youtube.com"\nbrowserHistory.back(1);                   // \u4f60\u539f\u672c\u5728\u6d4f\u89c8 "youtube.com" \uff0c\u540e\u9000\u5230 "facebook.com" \u5e76\u8fd4\u56de "facebook.com"\nbrowserHistory.back(1);                   // \u4f60\u539f\u672c\u5728\u6d4f\u89c8 "facebook.com" \uff0c\u540e\u9000\u5230 "google.com" \u5e76\u8fd4\u56de "google.com"\nbrowserHistory.forward(1);                // \u4f60\u539f\u672c\u5728\u6d4f\u89c8 "google.com" \uff0c\u524d\u8fdb\u5230 "facebook.com" \u5e76\u8fd4\u56de "facebook.com"\nbrowserHistory.visit("linkedin.com");     // \u4f60\u539f\u672c\u5728\u6d4f\u89c8 "facebook.com" \u3002 \u8bbf\u95ee "linkedin.com"\nbrowserHistory.forward(2);                // \u4f60\u539f\u672c\u5728\u6d4f\u89c8 "linkedin.com" \uff0c\u4f60\u65e0\u6cd5\u524d\u8fdb\u4efb\u4f55\u6b65\u6570\u3002\nbrowserHistory.back(2);                   // \u4f60\u539f\u672c\u5728\u6d4f\u89c8 "linkedin.com" \uff0c\u540e\u9000\u4e24\u6b65\u4f9d\u6b21\u5148\u5230 "facebook.com" \uff0c\u7136\u540e\u5230 "google.com" \uff0c\u5e76\u8fd4\u56de "google.com"\nbrowserHistory.back(7);                   // \u4f60\u539f\u672c\u5728\u6d4f\u89c8 "google.com"\uff0c \u4f60\u53ea\u80fd\u540e\u9000\u4e00\u6b65\u5230 "leetcode.com" \uff0c\u5e76\u8fd4\u56de "leetcode.com"\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= homepage.length <= 20
  • \n\t
  • 1 <= url.length <= 20
  • \n\t
  • 1 <= steps <= 100
  • \n\t
  • homepage \u548c url \u90fd\u53ea\u5305\u542b '.' \u6216\u8005\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
  • \n\t
  • \u6700\u591a\u8c03\u7528 5000 \u6b21 visit\uff0c back \u548c forward \u51fd\u6570\u3002
  • \n
\n", "tags_en": ["Design"], "tags_cn": ["\u8bbe\u8ba1"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class BrowserHistory {\npublic:\n BrowserHistory(string homepage) {\n\n }\n \n void visit(string url) {\n\n }\n \n string back(int steps) {\n\n }\n \n string forward(int steps) {\n\n }\n};\n\n/**\n * Your BrowserHistory object will be instantiated and called as such:\n * BrowserHistory* obj = new BrowserHistory(homepage);\n * obj->visit(url);\n * string param_2 = obj->back(steps);\n * string param_3 = obj->forward(steps);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class BrowserHistory {\n\n public BrowserHistory(String homepage) {\n\n }\n \n public void visit(String url) {\n\n }\n \n public String back(int steps) {\n\n }\n \n public String forward(int steps) {\n\n }\n}\n\n/**\n * Your BrowserHistory object will be instantiated and called as such:\n * BrowserHistory obj = new BrowserHistory(homepage);\n * obj.visit(url);\n * String param_2 = obj.back(steps);\n * String param_3 = obj.forward(steps);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class BrowserHistory(object):\n\n def __init__(self, homepage):\n \"\"\"\n :type homepage: str\n \"\"\"\n\n\n def visit(self, url):\n \"\"\"\n :type url: str\n :rtype: None\n \"\"\"\n\n\n def back(self, steps):\n \"\"\"\n :type steps: int\n :rtype: str\n \"\"\"\n\n\n def forward(self, steps):\n \"\"\"\n :type steps: int\n :rtype: str\n \"\"\"\n\n\n\n# Your BrowserHistory object will be instantiated and called as such:\n# obj = BrowserHistory(homepage)\n# obj.visit(url)\n# param_2 = obj.back(steps)\n# param_3 = obj.forward(steps)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class BrowserHistory:\n\n def __init__(self, homepage: str):\n\n\n def visit(self, url: str) -> None:\n\n\n def back(self, steps: int) -> str:\n\n\n def forward(self, steps: int) -> str:\n\n\n\n# Your BrowserHistory object will be instantiated and called as such:\n# obj = BrowserHistory(homepage)\n# obj.visit(url)\n# param_2 = obj.back(steps)\n# param_3 = obj.forward(steps)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} BrowserHistory;\n\n\nBrowserHistory* browserHistoryCreate(char * homepage) {\n \n}\n\nvoid browserHistoryVisit(BrowserHistory* obj, char * url) {\n \n}\n\nchar * browserHistoryBack(BrowserHistory* obj, int steps) {\n \n}\n\nchar * browserHistoryForward(BrowserHistory* obj, int steps) {\n \n}\n\nvoid browserHistoryFree(BrowserHistory* obj) {\n \n}\n\n/**\n * Your BrowserHistory struct will be instantiated and called as such:\n * BrowserHistory* obj = browserHistoryCreate(homepage);\n * browserHistoryVisit(obj, url);\n \n * char * param_2 = browserHistoryBack(obj, steps);\n \n * char * param_3 = browserHistoryForward(obj, steps);\n \n * browserHistoryFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class BrowserHistory {\n\n public BrowserHistory(string homepage) {\n\n }\n \n public void Visit(string url) {\n\n }\n \n public string Back(int steps) {\n\n }\n \n public string Forward(int steps) {\n\n }\n}\n\n/**\n * Your BrowserHistory object will be instantiated and called as such:\n * BrowserHistory obj = new BrowserHistory(homepage);\n * obj.Visit(url);\n * string param_2 = obj.Back(steps);\n * string param_3 = obj.Forward(steps);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} homepage\n */\nvar BrowserHistory = function(homepage) {\n\n};\n\n/** \n * @param {string} url\n * @return {void}\n */\nBrowserHistory.prototype.visit = function(url) {\n\n};\n\n/** \n * @param {number} steps\n * @return {string}\n */\nBrowserHistory.prototype.back = function(steps) {\n\n};\n\n/** \n * @param {number} steps\n * @return {string}\n */\nBrowserHistory.prototype.forward = function(steps) {\n\n};\n\n/**\n * Your BrowserHistory object will be instantiated and called as such:\n * var obj = new BrowserHistory(homepage)\n * obj.visit(url)\n * var param_2 = obj.back(steps)\n * var param_3 = obj.forward(steps)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class BrowserHistory\n\n=begin\n :type homepage: String\n=end\n def initialize(homepage)\n\n end\n\n\n=begin\n :type url: String\n :rtype: Void\n=end\n def visit(url)\n\n end\n\n\n=begin\n :type steps: Integer\n :rtype: String\n=end\n def back(steps)\n\n end\n\n\n=begin\n :type steps: Integer\n :rtype: String\n=end\n def forward(steps)\n\n end\n\n\nend\n\n# Your BrowserHistory object will be instantiated and called as such:\n# obj = BrowserHistory.new(homepage)\n# obj.visit(url)\n# param_2 = obj.back(steps)\n# param_3 = obj.forward(steps)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass BrowserHistory {\n\n init(_ homepage: String) {\n \n }\n \n func visit(_ url: String) {\n \n }\n \n func back(_ steps: Int) -> String {\n \n }\n \n func forward(_ steps: Int) -> String {\n \n }\n}\n\n/**\n * Your BrowserHistory object will be instantiated and called as such:\n * let obj = BrowserHistory(homepage)\n * obj.visit(url)\n * let ret_2: String = obj.back(steps)\n * let ret_3: String = obj.forward(steps)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type BrowserHistory struct {\n\n}\n\n\nfunc Constructor(homepage string) BrowserHistory {\n\n}\n\n\nfunc (this *BrowserHistory) Visit(url string) {\n\n}\n\n\nfunc (this *BrowserHistory) Back(steps int) string {\n\n}\n\n\nfunc (this *BrowserHistory) Forward(steps int) string {\n\n}\n\n\n/**\n * Your BrowserHistory object will be instantiated and called as such:\n * obj := Constructor(homepage);\n * obj.Visit(url);\n * param_2 := obj.Back(steps);\n * param_3 := obj.Forward(steps);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class BrowserHistory(_homepage: String) {\n\n def visit(url: String) {\n\n }\n\n def back(steps: Int): String = {\n\n }\n\n def forward(steps: Int): String = {\n\n }\n\n}\n\n/**\n * Your BrowserHistory object will be instantiated and called as such:\n * var obj = new BrowserHistory(homepage)\n * obj.visit(url)\n * var param_2 = obj.back(steps)\n * var param_3 = obj.forward(steps)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class BrowserHistory(homepage: String) {\n\n fun visit(url: String) {\n\n }\n\n fun back(steps: Int): String {\n\n }\n\n fun forward(steps: Int): String {\n\n }\n\n}\n\n/**\n * Your BrowserHistory object will be instantiated and called as such:\n * var obj = BrowserHistory(homepage)\n * obj.visit(url)\n * var param_2 = obj.back(steps)\n * var param_3 = obj.forward(steps)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct BrowserHistory {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl BrowserHistory {\n\n fn new(homepage: String) -> Self {\n\n }\n \n fn visit(&self, url: String) {\n\n }\n \n fn back(&self, steps: i32) -> String {\n\n }\n \n fn forward(&self, steps: i32) -> String {\n\n }\n}\n\n/**\n * Your BrowserHistory object will be instantiated and called as such:\n * let obj = BrowserHistory::new(homepage);\n * obj.visit(url);\n * let ret_2: String = obj.back(steps);\n * let ret_3: String = obj.forward(steps);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class BrowserHistory {\n /**\n * @param String $homepage\n */\n function __construct($homepage) {\n \n }\n \n /**\n * @param String $url\n * @return NULL\n */\n function visit($url) {\n \n }\n \n /**\n * @param Integer $steps\n * @return String\n */\n function back($steps) {\n \n }\n \n /**\n * @param Integer $steps\n * @return String\n */\n function forward($steps) {\n \n }\n}\n\n/**\n * Your BrowserHistory object will be instantiated and called as such:\n * $obj = BrowserHistory($homepage);\n * $obj->visit($url);\n * $ret_2 = $obj->back($steps);\n * $ret_3 = $obj->forward($steps);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class BrowserHistory {\n constructor(homepage: string) {\n\n }\n\n visit(url: string): void {\n\n }\n\n back(steps: number): string {\n\n }\n\n forward(steps: number): string {\n\n }\n}\n\n/**\n * Your BrowserHistory object will be instantiated and called as such:\n * var obj = new BrowserHistory(homepage)\n * obj.visit(url)\n * var param_2 = obj.back(steps)\n * var param_3 = obj.forward(steps)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define browser-history%\n (class object%\n (super-new)\n\n ; homepage : string?\n (init-field\n homepage)\n \n ; visit : string? -> void?\n (define/public (visit url)\n\n )\n ; back : exact-integer? -> string?\n (define/public (back steps)\n\n )\n ; forward : exact-integer? -> string?\n (define/public (forward steps)\n\n )))\n\n;; Your browser-history% object will be instantiated and called as such:\n;; (define obj (new browser-history% [homepage homepage]))\n;; (send obj visit url)\n;; (define param_2 (send obj back steps))\n;; (define param_3 (send obj forward steps))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1472](https://leetcode-cn.com/problems/design-browser-history)", "[\u8bbe\u8ba1\u6d4f\u89c8\u5668\u5386\u53f2\u8bb0\u5f55](/solution/1400-1499/1472.Design%20Browser%20History/README.md)", "`\u8bbe\u8ba1`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1472](https://leetcode.com/problems/design-browser-history)", "[Design Browser History](/solution/1400-1499/1472.Design%20Browser%20History/README_EN.md)", "`Design`", "Medium", ""]}, {"question_id": "1581", "frontend_question_id": "1471", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/the-k-strongest-values-in-an-array", "url_en": "https://leetcode.com/problems/the-k-strongest-values-in-an-array", "relative_path_cn": "/solution/1400-1499/1471.The%20k%20Strongest%20Values%20in%20an%20Array/README.md", "relative_path_en": "/solution/1400-1499/1471.The%20k%20Strongest%20Values%20in%20an%20Array/README_EN.md", "title_cn": "\u6570\u7ec4\u4e2d\u7684 k \u4e2a\u6700\u5f3a\u503c", "title_en": "The k Strongest Values in an Array", "question_title_slug": "the-k-strongest-values-in-an-array", "content_en": "

Given an array of integers arr and an integer k.

\r\n\r\n

A value arr[i] is said to be stronger than a value arr[j] if |arr[i] - m| > |arr[j] - m| where m is the median of the array.
\r\nIf |arr[i] - m| == |arr[j] - m|, then arr[i] is said to be stronger than arr[j] if arr[i] > arr[j].

\r\n\r\n

Return a list of the strongest k values in the array. return the answer in any arbitrary order.

\r\n\r\n

Median is the middle value in an ordered integer list. More formally, if the length of the list is n, the median is the element in position ((n - 1) / 2) in the sorted list (0-indexed).

\r\n\r\n
    \r\n\t
  • For arr = [6, -3, 7, 2, 11]n = 5 and the median is obtained by sorting the array arr = [-3, 2, 6, 7, 11] and the median is arr[m] where m = ((5 - 1) / 2) = 2. The median is 6.
  • \r\n\t
  • For arr = [-7, 22, 17, 3]n = 4 and the median is obtained by sorting the array arr = [-7, 3, 17, 22] and the median is arr[m] where m = ((4 - 1) / 2) = 1. The median is 3.
  • \r\n
\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: arr = [1,2,3,4,5], k = 2\r\nOutput: [5,1]\r\nExplanation: Median is 3, the elements of the array sorted by the strongest are [5,1,4,2,3]. The strongest 2 elements are [5, 1]. [1, 5] is also accepted answer.\r\nPlease note that although |5 - 3| == |1 - 3| but 5 is stronger than 1 because 5 > 1.\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: arr = [1,1,3,5,5], k = 2\r\nOutput: [5,5]\r\nExplanation: Median is 3, the elements of the array sorted by the strongest are [5,5,1,1,3]. The strongest 2 elements are [5, 5].\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: arr = [6,7,11,7,6,8], k = 5\r\nOutput: [11,8,6,6,7]\r\nExplanation: Median is 7, the elements of the array sorted by the strongest are [11,8,6,6,7,7].\r\nAny permutation of [11,8,6,6,7] is accepted.\r\n
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: arr = [6,-3,7,2,11], k = 3\r\nOutput: [-3,11,2]\r\n
\r\n\r\n

Example 5:

\r\n\r\n
\r\nInput: arr = [-7,22,17,3], k = 2\r\nOutput: [22,17]\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= arr.length <= 10^5
  • \r\n\t
  • -10^5 <= arr[i] <= 10^5
  • \r\n\t
  • 1 <= k <= arr.length
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr \u548c\u4e00\u4e2a\u6574\u6570 k \u3002

\n\n

\u8bbe m \u4e3a\u6570\u7ec4\u7684\u4e2d\u4f4d\u6570\uff0c\u53ea\u8981\u6ee1\u8db3\u4e0b\u8ff0\u4e24\u4e2a\u524d\u63d0\u4e4b\u4e00\uff0c\u5c31\u53ef\u4ee5\u5224\u5b9a arr[i] \u7684\u503c\u6bd4 arr[j] \u7684\u503c\u66f4\u5f3a\uff1a

\n\n
    \n\t
  •  |arr[i] - m| > |arr[j] - m|
  • \n\t
  •  |arr[i] - m| == |arr[j] - m|\uff0c\u4e14 arr[i] > arr[j]
  • \n
\n\n

\u8bf7\u8fd4\u56de\u7531\u6570\u7ec4\u4e2d\u6700\u5f3a\u7684 k \u4e2a\u503c\u7ec4\u6210\u7684\u5217\u8868\u3002\u7b54\u6848\u53ef\u4ee5\u4ee5 \u4efb\u610f\u987a\u5e8f \u8fd4\u56de\u3002

\n\n

\u4e2d\u4f4d\u6570 \u662f\u4e00\u4e2a\u6709\u5e8f\u6574\u6570\u5217\u8868\u4e2d\u5904\u4e8e\u4e2d\u95f4\u4f4d\u7f6e\u7684\u503c\u3002\u5f62\u5f0f\u4e0a\uff0c\u5982\u679c\u5217\u8868\u7684\u957f\u5ea6\u4e3a n \uff0c\u90a3\u4e48\u4e2d\u4f4d\u6570\u5c31\u662f\u8be5\u6709\u5e8f\u5217\u8868\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\u4e2d\u4f4d\u4e8e ((n - 1) / 2) \u7684\u5143\u7d20\u3002

\n\n
    \n\t
  • \u4f8b\u5982 arr = [6, -3, 7, 2, 11]\uff0cn = 5\uff1a\u6570\u7ec4\u6392\u5e8f\u540e\u5f97\u5230 arr = [-3, 2, 6, 7, 11] \uff0c\u6570\u7ec4\u7684\u4e2d\u95f4\u4f4d\u7f6e\u4e3a m = ((5 - 1) / 2) = 2 \uff0c\u4e2d\u4f4d\u6570 arr[m] \u7684\u503c\u4e3a 6 \u3002
  • \n\t
  • \u4f8b\u5982 arr = [-7, 22, 17, 3]\uff0cn = 4\uff1a\u6570\u7ec4\u6392\u5e8f\u540e\u5f97\u5230 arr = [-7, 3, 17, 22] \uff0c\u6570\u7ec4\u7684\u4e2d\u95f4\u4f4d\u7f6e\u4e3a m = ((4 - 1) / 2) = 1 \uff0c\u4e2d\u4f4d\u6570 arr[m] \u7684\u503c\u4e3a 3 \u3002
  • \n
\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aarr = [1,2,3,4,5], k = 2\n\u8f93\u51fa\uff1a[5,1]\n\u89e3\u91ca\uff1a\u4e2d\u4f4d\u6570\u4e3a 3\uff0c\u6309\u4ece\u5f3a\u5230\u5f31\u987a\u5e8f\u6392\u5e8f\u540e\uff0c\u6570\u7ec4\u53d8\u4e3a [5,1,4,2,3]\u3002\u6700\u5f3a\u7684\u4e24\u4e2a\u5143\u7d20\u662f [5, 1]\u3002[1, 5] \u4e5f\u662f\u6b63\u786e\u7b54\u6848\u3002\n\u6ce8\u610f\uff0c\u5c3d\u7ba1 |5 - 3| == |1 - 3| \uff0c\u4f46\u662f 5 \u6bd4 1 \u66f4\u5f3a\uff0c\u56e0\u4e3a 5 > 1 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aarr = [1,1,3,5,5], k = 2\n\u8f93\u51fa\uff1a[5,5]\n\u89e3\u91ca\uff1a\u4e2d\u4f4d\u6570\u4e3a 3, \u6309\u4ece\u5f3a\u5230\u5f31\u987a\u5e8f\u6392\u5e8f\u540e\uff0c\u6570\u7ec4\u53d8\u4e3a [5,5,1,1,3]\u3002\u6700\u5f3a\u7684\u4e24\u4e2a\u5143\u7d20\u662f [5, 5]\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aarr = [6,7,11,7,6,8], k = 5\n\u8f93\u51fa\uff1a[11,8,6,6,7]\n\u89e3\u91ca\uff1a\u4e2d\u4f4d\u6570\u4e3a 7, \u6309\u4ece\u5f3a\u5230\u5f31\u987a\u5e8f\u6392\u5e8f\u540e\uff0c\u6570\u7ec4\u53d8\u4e3a [11,8,6,6,7,7]\u3002\n[11,8,6,6,7] \u7684\u4efb\u4f55\u6392\u5217\u90fd\u662f\u6b63\u786e\u7b54\u6848\u3002
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1aarr = [6,-3,7,2,11], k = 3\n\u8f93\u51fa\uff1a[-3,11,2]\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1aarr = [-7,22,17,3], k = 2\n\u8f93\u51fa\uff1a[22,17]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= arr.length <= 10^5
  • \n\t
  • -10^5 <= arr[i] <= 10^5
  • \n\t
  • 1 <= k <= arr.length
  • \n
\n", "tags_en": ["Sort", "Array"], "tags_cn": ["\u6392\u5e8f", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector getStrongest(vector& arr, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] getStrongest(int[] arr, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getStrongest(self, arr, k):\n \"\"\"\n :type arr: List[int]\n :type k: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getStrongest(self, arr: List[int], k: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* getStrongest(int* arr, int arrSize, int k, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] GetStrongest(int[] arr, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @param {number} k\n * @return {number[]}\n */\nvar getStrongest = function(arr, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @param {Integer} k\n# @return {Integer[]}\ndef get_strongest(arr, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getStrongest(_ arr: [Int], _ k: Int) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getStrongest(arr []int, k int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getStrongest(arr: Array[Int], k: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getStrongest(arr: IntArray, k: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_strongest(arr: Vec, k: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @param Integer $k\n * @return Integer[]\n */\n function getStrongest($arr, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getStrongest(arr: number[], k: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-strongest arr k)\n (-> (listof exact-integer?) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1471](https://leetcode-cn.com/problems/the-k-strongest-values-in-an-array)", "[\u6570\u7ec4\u4e2d\u7684 k \u4e2a\u6700\u5f3a\u503c](/solution/1400-1499/1471.The%20k%20Strongest%20Values%20in%20an%20Array/README.md)", "`\u6392\u5e8f`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1471](https://leetcode.com/problems/the-k-strongest-values-in-an-array)", "[The k Strongest Values in an Array](/solution/1400-1499/1471.The%20k%20Strongest%20Values%20in%20an%20Array/README_EN.md)", "`Sort`,`Array`", "Medium", ""]}, {"question_id": "1580", "frontend_question_id": "1470", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/shuffle-the-array", "url_en": "https://leetcode.com/problems/shuffle-the-array", "relative_path_cn": "/solution/1400-1499/1470.Shuffle%20the%20Array/README.md", "relative_path_en": "/solution/1400-1499/1470.Shuffle%20the%20Array/README_EN.md", "title_cn": "\u91cd\u65b0\u6392\u5217\u6570\u7ec4", "title_en": "Shuffle the Array", "question_title_slug": "shuffle-the-array", "content_en": "

Given the array nums consisting of 2n elements in the form [x1,x2,...,xn,y1,y2,...,yn].

\r\n\r\n

Return the array in the form [x1,y1,x2,y2,...,xn,yn].

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: nums = [2,5,1,3,4,7], n = 3\r\nOutput: [2,3,5,4,1,7] \r\nExplanation: Since x1=2, x2=5, x3=1, y1=3, y2=4, y3=7 then the answer is [2,3,5,4,1,7].\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: nums = [1,2,3,4,4,3,2,1], n = 4\r\nOutput: [1,4,2,3,3,2,4,1]\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: nums = [1,1,2,2], n = 2\r\nOutput: [1,2,1,2]\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= n <= 500
  • \r\n\t
  • nums.length == 2n
  • \r\n\t
  • 1 <= nums[i] <= 10^3
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 nums \uff0c\u6570\u7ec4\u4e2d\u6709 2n \u4e2a\u5143\u7d20\uff0c\u6309 [x1,x2,...,xn,y1,y2,...,yn] \u7684\u683c\u5f0f\u6392\u5217\u3002

\n\n

\u8bf7\u4f60\u5c06\u6570\u7ec4\u6309 [x1,y1,x2,y2,...,xn,yn] \u683c\u5f0f\u91cd\u65b0\u6392\u5217\uff0c\u8fd4\u56de\u91cd\u6392\u540e\u7684\u6570\u7ec4\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anums = [2,5,1,3,4,7], n = 3\n\u8f93\u51fa\uff1a[2,3,5,4,1,7] \n\u89e3\u91ca\uff1a\u7531\u4e8e x1=2, x2=5, x3=1, y1=3, y2=4, y3=7 \uff0c\u6240\u4ee5\u7b54\u6848\u4e3a [2,3,5,4,1,7]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,2,3,4,4,3,2,1], n = 4\n\u8f93\u51fa\uff1a[1,4,2,3,3,2,4,1]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,1,2,2], n = 2\n\u8f93\u51fa\uff1a[1,2,1,2]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 500
  • \n\t
  • nums.length == 2n
  • \n\t
  • 1 <= nums[i] <= 10^3
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector shuffle(vector& nums, int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] shuffle(int[] nums, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def shuffle(self, nums, n):\n \"\"\"\n :type nums: List[int]\n :type n: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def shuffle(self, nums: List[int], n: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* shuffle(int* nums, int numsSize, int n, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] Shuffle(int[] nums, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} n\n * @return {number[]}\n */\nvar shuffle = function(nums, n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} n\n# @return {Integer[]}\ndef shuffle(nums, n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func shuffle(_ nums: [Int], _ n: Int) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func shuffle(nums []int, n int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def shuffle(nums: Array[Int], n: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun shuffle(nums: IntArray, n: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn shuffle(nums: Vec, n: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $n\n * @return Integer[]\n */\n function shuffle($nums, $n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function shuffle(nums: number[], n: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (shuffle nums n)\n (-> (listof exact-integer?) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1470](https://leetcode-cn.com/problems/shuffle-the-array)", "[\u91cd\u65b0\u6392\u5217\u6570\u7ec4](/solution/1400-1499/1470.Shuffle%20the%20Array/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1470](https://leetcode.com/problems/shuffle-the-array)", "[Shuffle the Array](/solution/1400-1499/1470.Shuffle%20the%20Array/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1579", "frontend_question_id": "1454", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/active-users", "url_en": "https://leetcode.com/problems/active-users", "relative_path_cn": "/solution/1400-1499/1454.Active%20Users/README.md", "relative_path_en": "/solution/1400-1499/1454.Active%20Users/README_EN.md", "title_cn": "\u6d3b\u8dc3\u7528\u6237", "title_en": "Active Users", "question_title_slug": "active-users", "content_en": "

Table Accounts:

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| name          | varchar |\n+---------------+---------+\nthe id is the primary key for this table.\nThis table contains the account id and the user name of each account.\n
\n\n

 

\n\n

Table Logins:

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| login_date    | date    |\n+---------------+---------+\nThere is no primary key for this table, it may contain duplicates.\nThis table contains the account id of the user who logged in and the login date. A user may log in multiple times in the day.\n
\n\n

 

\n\n

Write an SQL query to find the id and the name of active users.

\n\n

Active users are those who logged in to their accounts for 5 or more consecutive days.

\n\n

Return the result table ordered by the id.

\n\n

The query result format is in the following example:

\n\n
\nAccounts table:\n+----+----------+\n| id | name     |\n+----+----------+\n| 1  | Winston  |\n| 7  | Jonathan |\n+----+----------+\n\nLogins table:\n+----+------------+\n| id | login_date |\n+----+------------+\n| 7  | 2020-05-30 |\n| 1  | 2020-05-30 |\n| 7  | 2020-05-31 |\n| 7  | 2020-06-01 |\n| 7  | 2020-06-02 |\n| 7  | 2020-06-02 |\n| 7  | 2020-06-03 |\n| 1  | 2020-06-07 |\n| 7  | 2020-06-10 |\n+----+------------+\n\nResult table:\n+----+----------+\n| id | name     |\n+----+----------+\n| 7  | Jonathan |\n+----+----------+\nUser Winston with id = 1 logged in 2 times only in 2 different days, so, Winston is not an active user.\nUser Jonathan with id = 7 logged in 7 times in 6 different days, five of them were consecutive days, so, Jonathan is an active user.\n
\n\n

Follow up question:
\nCan you write a general solution if the active users are those who logged in to their accounts for n or more consecutive days?

\n", "content_cn": "

\u8868 Accounts:

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| name          | varchar |\n+---------------+---------+\nid \u662f\u8be5\u8868\u4e3b\u952e.\n\u8be5\u8868\u5305\u542b\u8d26\u6237 id \u548c\u8d26\u6237\u7684\u7528\u6237\u540d.\n
\n\n

\u00a0

\n\n

\u8868 Logins:

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| login_date    | date    |\n+---------------+---------+\n\u8be5\u8868\u65e0\u4e3b\u952e, \u53ef\u80fd\u5305\u542b\u91cd\u590d\u9879.\n\u8be5\u8868\u5305\u542b\u767b\u5f55\u7528\u6237\u7684\u8d26\u6237 id \u548c\u767b\u5f55\u65e5\u671f. \u7528\u6237\u4e5f\u8bb8\u4e00\u5929\u5185\u767b\u5f55\u591a\u6b21.\n
\n\n

\u00a0

\n\n

\u5199\u4e00\u4e2a SQL \u67e5\u8be2,\u00a0 \u627e\u5230\u6d3b\u8dc3\u7528\u6237\u7684 id \u548c name.

\n\n

\u6d3b\u8dc3\u7528\u6237\u662f\u6307\u90a3\u4e9b\u81f3\u5c11\u8fde\u7eed\u00a05 \u5929\u767b\u5f55\u8d26\u6237\u7684\u7528\u6237.

\n\n

\u8fd4\u56de\u7684\u7ed3\u679c\u8868\u6309\u7167 id \u6392\u5e8f.

\n\n

\u7ed3\u679c\u8868\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a:

\n\n
\nAccounts \u8868:\n+----+----------+\n| id | name     |\n+----+----------+\n| 1  | Winston  |\n| 7  | Jonathan |\n+----+----------+\n\nLogins \u8868:\n+----+------------+\n| id | login_date |\n+----+------------+\n| 7  | 2020-05-30 |\n| 1  | 2020-05-30 |\n| 7  | 2020-05-31 |\n| 7  | 2020-06-01 |\n| 7  | 2020-06-02 |\n| 7  | 2020-06-02 |\n| 7  | 2020-06-03 |\n| 1  | 2020-06-07 |\n| 7  | 2020-06-10 |\n+----+------------+\n\nResult \u8868:\n+----+----------+\n| id | name     |\n+----+----------+\n| 7  | Jonathan |\n+----+----------+\nid = 1 \u7684\u7528\u6237 Winston \u4ec5\u4ec5\u5728\u4e0d\u540c\u7684 2 \u5929\u5185\u767b\u5f55\u4e86 2 \u6b21, \u6240\u4ee5, Winston \u4e0d\u662f\u6d3b\u8dc3\u7528\u6237.\nid = 7 \u7684\u7528\u6237 Jonathon \u5728\u4e0d\u540c\u7684 6 \u5929\u5185\u767b\u5f55\u4e86 7 \u6b21, , 6 \u5929\u4e2d\u6709 5 \u5929\u662f\u8fde\u7eed\u7684, \u6240\u4ee5, Jonathan \u662f\u6d3b\u8dc3\u7528\u6237.\n
\n\n

\u00a0

\n\n

\u8fdb\u9636\u95ee\u9898:
\n\u5982\u679c\u6d3b\u8dc3\u7528\u6237\u662f\u90a3\u4e9b\u81f3\u5c11\u8fde\u7eed\u00a0n\u00a0\u5929\u767b\u5f55\u8d26\u6237\u7684\u7528\u6237,\u00a0\u4f60\u80fd\u5426\u5199\u51fa\u901a\u7528\u7684\u89e3\u51b3\u65b9\u6848?

\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1454](https://leetcode-cn.com/problems/active-users)", "[\u6d3b\u8dc3\u7528\u6237](/solution/1400-1499/1454.Active%20Users/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1454](https://leetcode.com/problems/active-users)", "[Active Users](/solution/1400-1499/1454.Active%20Users/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1578", "frontend_question_id": "1445", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/apples-oranges", "url_en": "https://leetcode.com/problems/apples-oranges", "relative_path_cn": "/solution/1400-1499/1445.Apples%20%26%20Oranges/README.md", "relative_path_en": "/solution/1400-1499/1445.Apples%20%26%20Oranges/README_EN.md", "title_cn": "\u82f9\u679c\u548c\u6854\u5b50", "title_en": "Apples & Oranges", "question_title_slug": "apples-oranges", "content_en": "

Table: Sales

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| sale_date     | date    |\n| fruit         | enum    | \n| sold_num      | int     | \n+---------------+---------+\n(sale_date,fruit) is the primary key for this table.\nThis table contains the sales of "apples" and "oranges" sold each day.\n
\n\n

 

\n\n

Write an SQL query to report the difference between number of apples and oranges sold each day.

\n\n

Return the result table ordered by sale_date in format ('YYYY-MM-DD').

\n\n

The query result format is in the following example:

\n\n

 

\n\n
\nSales table:\n+------------+------------+-------------+\n| sale_date  | fruit      | sold_num    |\n+------------+------------+-------------+\n| 2020-05-01 | apples     | 10          |\n| 2020-05-01 | oranges    | 8           |\n| 2020-05-02 | apples     | 15          |\n| 2020-05-02 | oranges    | 15          |\n| 2020-05-03 | apples     | 20          |\n| 2020-05-03 | oranges    | 0           |\n| 2020-05-04 | apples     | 15          |\n| 2020-05-04 | oranges    | 16          |\n+------------+------------+-------------+\n\nResult table:\n+------------+--------------+\n| sale_date  | diff         |\n+------------+--------------+\n| 2020-05-01 | 2            |\n| 2020-05-02 | 0            |\n| 2020-05-03 | 20           |\n| 2020-05-04 | -1           |\n+------------+--------------+\n\nDay 2020-05-01, 10 apples and 8 oranges were sold (Difference  10 - 8 = 2).\nDay 2020-05-02, 15 apples and 15 oranges were sold (Difference 15 - 15 = 0).\nDay 2020-05-03, 20 apples and 0 oranges were sold (Difference 20 - 0 = 20).\nDay 2020-05-04, 15 apples and 16 oranges were sold (Difference 15 - 16 = -1).\n
\n", "content_cn": "

\u8868: Sales

\n\n
+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| sale_date     | date    |\n| fruit         | enum    | \n| sold_num      | int     | \n+---------------+---------+\n(sale_date,fruit) \u662f\u8be5\u8868\u4e3b\u952e.\n\u8be5\u8868\u5305\u542b\u4e86\u6bcf\u4e00\u5929\u4e2d"\u82f9\u679c" \u548c "\u6854\u5b50"\u7684\u9500\u552e\u60c5\u51b5.\n
\n\n

 

\n\n

\u5199\u4e00\u4e2a SQL \u67e5\u8be2, \u62a5\u544a\u6bcf\u4e00\u5929 \u82f9\u679c \u548c \u6854\u5b50 \u9500\u552e\u7684\u6570\u76ee\u7684\u5dee\u5f02.

\n\n

\u8fd4\u56de\u7684\u7ed3\u679c\u8868, \u6309\u7167\u683c\u5f0f\u4e3a ('YYYY-MM-DD') \u7684 sale_date \u6392\u5e8f.

\n\n

\u67e5\u8be2\u7ed3\u679c\u8868\u5982\u4e0b\u4f8b\u6240\u793a:

\n\n

 

\n\n
Sales \u8868:\n+------------+------------+-------------+\n| sale_date  | fruit      | sold_num    |\n+------------+------------+-------------+\n| 2020-05-01 | apples     | 10          |\n| 2020-05-01 | oranges    | 8           |\n| 2020-05-02 | apples     | 15          |\n| 2020-05-02 | oranges    | 15          |\n| 2020-05-03 | apples     | 20          |\n| 2020-05-03 | oranges    | 0           |\n| 2020-05-04 | apples     | 15          |\n| 2020-05-04 | oranges    | 16          |\n+------------+------------+-------------+\n\nResult \u8868:\n+------------+--------------+\n| sale_date  | diff         |\n+------------+--------------+\n| 2020-05-01 | 2            |\n| 2020-05-02 | 0            |\n| 2020-05-03 | 20           |\n| 2020-05-04 | -1           |\n+------------+--------------+\n\n\u5728 2020-05-01, \u5356\u4e86 10 \u4e2a\u82f9\u679c \u548c 8 \u4e2a\u6854\u5b50 (\u5dee\u5f02\u4e3a 10 - 8 = 2).\n\u5728 2020-05-02, \u5356\u4e86 15 \u4e2a\u82f9\u679c \u548c 15 \u4e2a\u6854\u5b50 (\u5dee\u5f02\u4e3a 15 - 15 = 0).\n\u5728 2020-05-03, \u5356\u4e86 20 \u4e2a\u82f9\u679c \u548c 0 \u4e2a\u6854\u5b50 (\u5dee\u5f02\u4e3a 20 - 0 = 20).\n\u5728 2020-05-04, \u5356\u4e86 15 \u4e2a\u82f9\u679c \u548c 16 \u4e2a\u6854\u5b50 (\u5dee\u5f02\u4e3a 15 - 16 = -1).\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1445](https://leetcode-cn.com/problems/apples-oranges)", "[\u82f9\u679c\u548c\u6854\u5b50](/solution/1400-1499/1445.Apples%20%26%20Oranges/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1445](https://leetcode.com/problems/apples-oranges)", "[Apples & Oranges](/solution/1400-1499/1445.Apples%20%26%20Oranges/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1577", "frontend_question_id": "1467", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/probability-of-a-two-boxes-having-the-same-number-of-distinct-balls", "url_en": "https://leetcode.com/problems/probability-of-a-two-boxes-having-the-same-number-of-distinct-balls", "relative_path_cn": "/solution/1400-1499/1467.Probability%20of%20a%20Two%20Boxes%20Having%20The%20Same%20Number%20of%20Distinct%20Balls/README.md", "relative_path_en": "/solution/1400-1499/1467.Probability%20of%20a%20Two%20Boxes%20Having%20The%20Same%20Number%20of%20Distinct%20Balls/README_EN.md", "title_cn": "\u4e24\u4e2a\u76d2\u5b50\u4e2d\u7403\u7684\u989c\u8272\u6570\u76f8\u540c\u7684\u6982\u7387", "title_en": "Probability of a Two Boxes Having The Same Number of Distinct Balls", "question_title_slug": "probability-of-a-two-boxes-having-the-same-number-of-distinct-balls", "content_en": "

Given 2n balls of k distinct colors. You will be given an integer array balls of size k where balls[i] is the number of balls of color i

\n\n

All the balls will be shuffled uniformly at random, then we will distribute the first n balls to the first box and the remaining n balls to the other box (Please read the explanation of the second example carefully).

\n\n

Please note that the two boxes are considered different. For example, if we have two balls of colors a and b, and two boxes [] and (), then the distribution [a] (b) is considered different than the distribution [b] (a) (Please read the explanation of the first example carefully).

\n\n

We want to calculate the probability that the two boxes have the same number of distinct balls.

\n\n

 

\n

Example 1:

\n\n
\nInput: balls = [1,1]\nOutput: 1.00000\nExplanation: Only 2 ways to divide the balls equally:\n- A ball of color 1 to box 1 and a ball of color 2 to box 2\n- A ball of color 2 to box 1 and a ball of color 1 to box 2\nIn both ways, the number of distinct colors in each box is equal. The probability is 2/2 = 1\n
\n\n

Example 2:

\n\n
\nInput: balls = [2,1,1]\nOutput: 0.66667\nExplanation: We have the set of balls [1, 1, 2, 3]\nThis set of balls will be shuffled randomly and we may have one of the 12 distinct shuffles with equale probability (i.e. 1/12):\n[1,1 / 2,3], [1,1 / 3,2], [1,2 / 1,3], [1,2 / 3,1], [1,3 / 1,2], [1,3 / 2,1], [2,1 / 1,3], [2,1 / 3,1], [2,3 / 1,1], [3,1 / 1,2], [3,1 / 2,1], [3,2 / 1,1]\nAfter that we add the first two balls to the first box and the second two balls to the second box.\nWe can see that 8 of these 12 possible random distributions have the same number of distinct colors of balls in each box.\nProbability is 8/12 = 0.66667\n
\n\n

Example 3:

\n\n
\nInput: balls = [1,2,1,2]\nOutput: 0.60000\nExplanation: The set of balls is [1, 2, 2, 3, 4, 4]. It is hard to display all the 180 possible random shuffles of this set but it is easy to check that 108 of them will have the same number of distinct colors in each box.\nProbability = 108 / 180 = 0.6\n
\n\n

Example 4:

\n\n
\nInput: balls = [3,2,1]\nOutput: 0.30000\nExplanation: The set of balls is [1, 1, 1, 2, 2, 3]. It is hard to display all the 60 possible random shuffles of this set but it is easy to check that 18 of them will have the same number of distinct colors in each box.\nProbability = 18 / 60 = 0.3\n
\n\n

Example 5:

\n\n
\nInput: balls = [6,6,6,6,6,6]\nOutput: 0.90327\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= balls.length <= 8
  • \n\t
  • 1 <= balls[i] <= 6
  • \n\t
  • sum(balls) is even.
  • \n\t
  • Answers within 10^-5 of the actual value will be accepted as correct.
  • \n
\n", "content_cn": "

\u684c\u9762\u4e0a\u6709 2n \u4e2a\u989c\u8272\u4e0d\u5b8c\u5168\u76f8\u540c\u7684\u7403\uff0c\u7403\u4e0a\u7684\u989c\u8272\u5171\u6709 k \u79cd\u3002\u7ed9\u4f60\u4e00\u4e2a\u5927\u5c0f\u4e3a k \u7684\u6574\u6570\u6570\u7ec4 balls \uff0c\u5176\u4e2d balls[i] \u662f\u989c\u8272\u4e3a i \u7684\u7403\u7684\u6570\u91cf\u3002

\n\n

\u6240\u6709\u7684\u7403\u90fd\u5df2\u7ecf \u968f\u673a\u6253\u4e71\u987a\u5e8f \uff0c\u524d n \u4e2a\u7403\u653e\u5165\u7b2c\u4e00\u4e2a\u76d2\u5b50\uff0c\u540e n \u4e2a\u7403\u653e\u5165\u53e6\u4e00\u4e2a\u76d2\u5b50\uff08\u8bf7\u8ba4\u771f\u9605\u8bfb\u793a\u4f8b 2 \u7684\u89e3\u91ca\u90e8\u5206\uff09\u3002

\n\n

\u6ce8\u610f\uff1a\u8fd9\u4e24\u4e2a\u76d2\u5b50\u662f\u4e0d\u540c\u7684\u3002\u4f8b\u5982\uff0c\u4e24\u4e2a\u7403\u989c\u8272\u5206\u522b\u4e3a a \u548c b\uff0c\u76d2\u5b50\u5206\u522b\u4e3a [] \u548c ()\uff0c\u90a3\u4e48 [a] (b) \u548c [b] (a) \u8fd9\u4e24\u79cd\u5206\u914d\u65b9\u5f0f\u662f\u4e0d\u540c\u7684\uff08\u8bf7\u8ba4\u771f\u9605\u8bfb\u793a\u4f8b 1 \u7684\u89e3\u91ca\u90e8\u5206\uff09\u3002

\n\n

\u8bf7\u8ba1\u7b97\u300c\u4e24\u4e2a\u76d2\u5b50\u4e2d\u7403\u7684\u989c\u8272\u6570\u76f8\u540c\u300d\u7684\u60c5\u51b5\u7684\u6982\u7387\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aballs = [1,1]\n\u8f93\u51fa\uff1a1.00000\n\u89e3\u91ca\uff1a\u7403\u5e73\u5747\u5206\u914d\u7684\u65b9\u5f0f\u53ea\u6709\u4e24\u79cd\uff1a\n- \u989c\u8272\u4e3a 1 \u7684\u7403\u653e\u5165\u7b2c\u4e00\u4e2a\u76d2\u5b50\uff0c\u989c\u8272\u4e3a 2 \u7684\u7403\u653e\u5165\u7b2c\u4e8c\u4e2a\u76d2\u5b50\n- \u989c\u8272\u4e3a 2 \u7684\u7403\u653e\u5165\u7b2c\u4e00\u4e2a\u76d2\u5b50\uff0c\u989c\u8272\u4e3a 1 \u7684\u7403\u653e\u5165\u7b2c\u4e8c\u4e2a\u76d2\u5b50\n\u8fd9\u4e24\u79cd\u5206\u914d\uff0c\u4e24\u4e2a\u76d2\u5b50\u4e2d\u7403\u7684\u989c\u8272\u6570\u90fd\u76f8\u540c\u3002\u6240\u4ee5\u6982\u7387\u4e3a 2/2 = 1 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aballs = [2,1,1]\n\u8f93\u51fa\uff1a0.66667\n\u89e3\u91ca\uff1a\u7403\u7684\u5217\u8868\u4e3a [1, 1, 2, 3]\n\u968f\u673a\u6253\u4e71\uff0c\u5f97\u5230 12 \u79cd\u7b49\u6982\u7387\u7684\u4e0d\u540c\u6253\u4e71\u65b9\u6848\uff0c\u6bcf\u79cd\u65b9\u6848\u6982\u7387\u4e3a 1/12 \uff1a\n[1,1 / 2,3], [1,1 / 3,2], [1,2 / 1,3], [1,2 / 3,1], [1,3 / 1,2], [1,3 / 2,1], [2,1 / 1,3], [2,1 / 3,1], [2,3 / 1,1], [3,1 / 1,2], [3,1 / 2,1], [3,2 / 1,1]\n\u7136\u540e\uff0c\u6211\u4eec\u5c06\u524d\u4e24\u4e2a\u7403\u653e\u5165\u7b2c\u4e00\u4e2a\u76d2\u5b50\uff0c\u540e\u4e24\u4e2a\u7403\u653e\u5165\u7b2c\u4e8c\u4e2a\u76d2\u5b50\u3002\n\u8fd9 12 \u79cd\u53ef\u80fd\u7684\u968f\u673a\u6253\u4e71\u65b9\u5f0f\u4e2d\u7684 8 \u79cd\u6ee1\u8db3\u300c\u4e24\u4e2a\u76d2\u5b50\u4e2d\u7403\u7684\u989c\u8272\u6570\u76f8\u540c\u300d\u3002\n\u6982\u7387 = 8/12 = 0.66667\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aballs = [1,2,1,2]\n\u8f93\u51fa\uff1a0.60000\n\u89e3\u91ca\uff1a\u7403\u7684\u5217\u8868\u4e3a [1, 2, 2, 3, 4, 4]\u3002\u8981\u60f3\u663e\u793a\u6240\u6709 180 \u79cd\u968f\u673a\u6253\u4e71\u65b9\u6848\u662f\u5f88\u96be\u7684\uff0c\u4f46\u53ea\u68c0\u67e5\u300c\u4e24\u4e2a\u76d2\u5b50\u4e2d\u7403\u7684\u989c\u8272\u6570\u76f8\u540c\u300d\u7684 108 \u79cd\u60c5\u51b5\u662f\u6bd4\u8f83\u5bb9\u6613\u7684\u3002\n\u6982\u7387 = 108 / 180 = 0.6 \u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1aballs = [3,2,1]\n\u8f93\u51fa\uff1a0.30000\n\u89e3\u91ca\uff1a\u7403\u7684\u5217\u8868\u4e3a [1, 1, 1, 2, 2, 3]\u3002\u8981\u60f3\u663e\u793a\u6240\u6709 60 \u79cd\u968f\u673a\u6253\u4e71\u65b9\u6848\u662f\u5f88\u96be\u7684\uff0c\u4f46\u53ea\u68c0\u67e5\u300c\u4e24\u4e2a\u76d2\u5b50\u4e2d\u7403\u7684\u989c\u8272\u6570\u76f8\u540c\u300d\u7684 18 \u79cd\u60c5\u51b5\u662f\u6bd4\u8f83\u5bb9\u6613\u7684\u3002\n\u6982\u7387 = 18 / 60 = 0.3 \u3002\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1aballs = [6,6,6,6,6,6]\n\u8f93\u51fa\uff1a0.90327\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= balls.length <= 8
  • \n\t
  • 1 <= balls[i] <= 6
  • \n\t
  • sum(balls) \u662f\u5076\u6570
  • \n\t
  • \u7b54\u6848\u4e0e\u771f\u5b9e\u503c\u8bef\u5dee\u5728 10^-5 \u4ee5\u5185\uff0c\u5219\u88ab\u89c6\u4e3a\u6b63\u786e\u7b54\u6848
  • \n
\n", "tags_en": ["Math", "Backtracking"], "tags_cn": ["\u6570\u5b66", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n double getProbability(vector& balls) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double getProbability(int[] balls) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getProbability(self, balls):\n \"\"\"\n :type balls: List[int]\n :rtype: float\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getProbability(self, balls: List[int]) -> float:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\ndouble getProbability(int* balls, int ballsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double GetProbability(int[] balls) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} balls\n * @return {number}\n */\nvar getProbability = function(balls) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} balls\n# @return {Float}\ndef get_probability(balls)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getProbability(_ balls: [Int]) -> Double {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getProbability(balls []int) float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getProbability(balls: Array[Int]): Double = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getProbability(balls: IntArray): Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_probability(balls: Vec) -> f64 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $balls\n * @return Float\n */\n function getProbability($balls) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getProbability(balls: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-probability balls)\n (-> (listof exact-integer?) flonum?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1467](https://leetcode-cn.com/problems/probability-of-a-two-boxes-having-the-same-number-of-distinct-balls)", "[\u4e24\u4e2a\u76d2\u5b50\u4e2d\u7403\u7684\u989c\u8272\u6570\u76f8\u540c\u7684\u6982\u7387](/solution/1400-1499/1467.Probability%20of%20a%20Two%20Boxes%20Having%20The%20Same%20Number%20of%20Distinct%20Balls/README.md)", "`\u6570\u5b66`,`\u56de\u6eaf\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[1467](https://leetcode.com/problems/probability-of-a-two-boxes-having-the-same-number-of-distinct-balls)", "[Probability of a Two Boxes Having The Same Number of Distinct Balls](/solution/1400-1499/1467.Probability%20of%20a%20Two%20Boxes%20Having%20The%20Same%20Number%20of%20Distinct%20Balls/README_EN.md)", "`Math`,`Backtracking`", "Hard", ""]}, {"question_id": "1576", "frontend_question_id": "1466", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reorder-routes-to-make-all-paths-lead-to-the-city-zero", "url_en": "https://leetcode.com/problems/reorder-routes-to-make-all-paths-lead-to-the-city-zero", "relative_path_cn": "/solution/1400-1499/1466.Reorder%20Routes%20to%20Make%20All%20Paths%20Lead%20to%20the%20City%20Zero/README.md", "relative_path_en": "/solution/1400-1499/1466.Reorder%20Routes%20to%20Make%20All%20Paths%20Lead%20to%20the%20City%20Zero/README_EN.md", "title_cn": "\u91cd\u65b0\u89c4\u5212\u8def\u7ebf", "title_en": "Reorder Routes to Make All Paths Lead to the City Zero", "question_title_slug": "reorder-routes-to-make-all-paths-lead-to-the-city-zero", "content_en": "

There are n cities numbered from 0 to n - 1 and n - 1 roads such that there is only one way to travel between two different cities (this network form a tree). Last year, The ministry of transport decided to orient the roads in one direction because they are too narrow.

\n\n

Roads are represented by connections where connections[i] = [ai, bi] represents a road from city ai to city bi.

\n\n

This year, there will be a big event in the capital (city 0), and many people want to travel to this city.

\n\n

Your task consists of reorienting some roads such that each city can visit the city 0. Return the minimum number of edges changed.

\n\n

It's guaranteed that each city can reach city 0 after reorder.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: n = 6, connections = [[0,1],[1,3],[2,3],[4,0],[4,5]]\nOutput: 3\nExplanation: Change the direction of edges show in red such that each node can reach the node 0 (capital).\n
\n\n

Example 2:

\n\"\"\n
\nInput: n = 5, connections = [[1,0],[1,2],[3,2],[3,4]]\nOutput: 2\nExplanation: Change the direction of edges show in red such that each node can reach the node 0 (capital).\n
\n\n

Example 3:

\n\n
\nInput: n = 3, connections = [[1,0],[2,0]]\nOutput: 0\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= n <= 5 * 104
  • \n\t
  • connections.length == n - 1
  • \n\t
  • connections[i].length == 2
  • \n\t
  • 0 <= ai, bi <= n - 1
  • \n\t
  • ai != bi
  • \n
\n", "content_cn": "

n \u5ea7\u57ce\u5e02\uff0c\u4ece 0 \u5230 n-1 \u7f16\u53f7\uff0c\u5176\u95f4\u5171\u6709 n-1 \u6761\u8def\u7ebf\u3002\u56e0\u6b64\uff0c\u8981\u60f3\u5728\u4e24\u5ea7\u4e0d\u540c\u57ce\u5e02\u4e4b\u95f4\u65c5\u884c\u53ea\u6709\u552f\u4e00\u4e00\u6761\u8def\u7ebf\u53ef\u4f9b\u9009\u62e9\uff08\u8def\u7ebf\u7f51\u5f62\u6210\u4e00\u9897\u6811\uff09\u3002\u53bb\u5e74\uff0c\u4ea4\u901a\u8fd0\u8f93\u90e8\u51b3\u5b9a\u91cd\u65b0\u89c4\u5212\u8def\u7ebf\uff0c\u4ee5\u6539\u53d8\u4ea4\u901a\u62e5\u5835\u7684\u72b6\u51b5\u3002

\n\n

\u8def\u7ebf\u7528 connections \u8868\u793a\uff0c\u5176\u4e2d connections[i] = [a, b] \u8868\u793a\u4ece\u57ce\u5e02 a \u5230 b \u7684\u4e00\u6761\u6709\u5411\u8def\u7ebf\u3002

\n\n

\u4eca\u5e74\uff0c\u57ce\u5e02 0 \u5c06\u4f1a\u4e3e\u529e\u4e00\u573a\u5927\u578b\u6bd4\u8d5b\uff0c\u5f88\u591a\u6e38\u5ba2\u90fd\u60f3\u524d\u5f80\u57ce\u5e02 0 \u3002

\n\n

\u8bf7\u4f60\u5e2e\u52a9\u91cd\u65b0\u89c4\u5212\u8def\u7ebf\u65b9\u5411\uff0c\u4f7f\u6bcf\u4e2a\u57ce\u5e02\u90fd\u53ef\u4ee5\u8bbf\u95ee\u57ce\u5e02 0 \u3002\u8fd4\u56de\u9700\u8981\u53d8\u66f4\u65b9\u5411\u7684\u6700\u5c0f\u8def\u7ebf\u6570\u3002

\n\n

\u9898\u76ee\u6570\u636e \u4fdd\u8bc1 \u6bcf\u4e2a\u57ce\u5e02\u5728\u91cd\u65b0\u89c4\u5212\u8def\u7ebf\u65b9\u5411\u540e\u90fd\u80fd\u5230\u8fbe\u57ce\u5e02 0 \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1an = 6, connections = [[0,1],[1,3],[2,3],[4,0],[4,5]]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u66f4\u6539\u4ee5\u7ea2\u8272\u663e\u793a\u7684\u8def\u7ebf\u7684\u65b9\u5411\uff0c\u4f7f\u6bcf\u4e2a\u57ce\u5e02\u90fd\u53ef\u4ee5\u5230\u8fbe\u57ce\u5e02 0 \u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1an = 5, connections = [[1,0],[1,2],[3,2],[3,4]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u66f4\u6539\u4ee5\u7ea2\u8272\u663e\u793a\u7684\u8def\u7ebf\u7684\u65b9\u5411\uff0c\u4f7f\u6bcf\u4e2a\u57ce\u5e02\u90fd\u53ef\u4ee5\u5230\u8fbe\u57ce\u5e02 0 \u3002
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1an = 3, connections = [[1,0],[2,0]]\n\u8f93\u51fa\uff1a0\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= n <= 5 * 10^4
  • \n\t
  • connections.length == n-1
  • \n\t
  • connections[i].length == 2
  • \n\t
  • 0 <= connections[i][0], connections[i][1] <= n-1
  • \n\t
  • connections[i][0] != connections[i][1]
  • \n
\n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minReorder(int n, vector>& connections) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minReorder(int n, int[][] connections) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minReorder(self, n, connections):\n \"\"\"\n :type n: int\n :type connections: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minReorder(self, n: int, connections: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minReorder(int n, int** connections, int connectionsSize, int* connectionsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinReorder(int n, int[][] connections) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} connections\n * @return {number}\n */\nvar minReorder = function(n, connections) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} connections\n# @return {Integer}\ndef min_reorder(n, connections)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minReorder(_ n: Int, _ connections: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minReorder(n int, connections [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minReorder(n: Int, connections: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minReorder(n: Int, connections: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_reorder(n: i32, connections: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $connections\n * @return Integer\n */\n function minReorder($n, $connections) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minReorder(n: number, connections: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-reorder n connections)\n (-> exact-integer? (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1466](https://leetcode-cn.com/problems/reorder-routes-to-make-all-paths-lead-to-the-city-zero)", "[\u91cd\u65b0\u89c4\u5212\u8def\u7ebf](/solution/1400-1499/1466.Reorder%20Routes%20to%20Make%20All%20Paths%20Lead%20to%20the%20City%20Zero/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1466](https://leetcode.com/problems/reorder-routes-to-make-all-paths-lead-to-the-city-zero)", "[Reorder Routes to Make All Paths Lead to the City Zero](/solution/1400-1499/1466.Reorder%20Routes%20to%20Make%20All%20Paths%20Lead%20to%20the%20City%20Zero/README_EN.md)", "`Tree`,`Depth-first Search`", "Medium", ""]}, {"question_id": "1575", "frontend_question_id": "1465", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts", "url_en": "https://leetcode.com/problems/maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts", "relative_path_cn": "/solution/1400-1499/1465.Maximum%20Area%20of%20a%20Piece%20of%20Cake%20After%20Horizontal%20and%20Vertical%20Cuts/README.md", "relative_path_en": "/solution/1400-1499/1465.Maximum%20Area%20of%20a%20Piece%20of%20Cake%20After%20Horizontal%20and%20Vertical%20Cuts/README_EN.md", "title_cn": "\u5207\u5272\u540e\u9762\u79ef\u6700\u5927\u7684\u86cb\u7cd5", "title_en": "Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts", "question_title_slug": "maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts", "content_en": "

Given a rectangular cake with height h and width w, and two arrays of integers horizontalCuts and verticalCuts where horizontalCuts[i] is the distance from the top of the rectangular cake to the ith horizontal cut and similarly, verticalCuts[j] is the distance from the left of the rectangular cake to the jth vertical cut.

\n\n

Return the maximum area of a piece of cake after you cut at each horizontal and vertical position provided in the arrays horizontalCuts and verticalCutsSince the answer can be a huge number, return this modulo 10^9 + 7.

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: h = 5, w = 4, horizontalCuts = [1,2,4], verticalCuts = [1,3]\nOutput: 4 \nExplanation: The figure above represents the given rectangular cake. Red lines are the horizontal and vertical cuts. After you cut the cake, the green piece of cake has the maximum area.\n
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: h = 5, w = 4, horizontalCuts = [3,1], verticalCuts = [1]\nOutput: 6\nExplanation: The figure above represents the given rectangular cake. Red lines are the horizontal and vertical cuts. After you cut the cake, the green and yellow pieces of cake have the maximum area.\n
\n\n

Example 3:

\n\n
\nInput: h = 5, w = 4, horizontalCuts = [3], verticalCuts = [3]\nOutput: 9\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= h, w <= 10^9
  • \n\t
  • 1 <= horizontalCuts.length < min(h, 10^5)
  • \n\t
  • 1 <= verticalCuts.length < min(w, 10^5)
  • \n\t
  • 1 <= horizontalCuts[i] < h
  • \n\t
  • 1 <= verticalCuts[i] < w
  • \n\t
  • It is guaranteed that all elements in horizontalCuts are distinct.
  • \n\t
  • It is guaranteed that all elements in verticalCuts are distinct.
  • \n
\n", "content_cn": "

\u77e9\u5f62\u86cb\u7cd5\u7684\u9ad8\u5ea6\u4e3a h \u4e14\u5bbd\u5ea6\u4e3a w\uff0c\u7ed9\u4f60\u4e24\u4e2a\u6574\u6570\u6570\u7ec4 horizontalCuts \u548c verticalCuts\uff0c\u5176\u4e2d horizontalCuts[i] \u662f\u4ece\u77e9\u5f62\u86cb\u7cd5\u9876\u90e8\u5230\u7b2c  i \u4e2a\u6c34\u5e73\u5207\u53e3\u7684\u8ddd\u79bb\uff0c\u7c7b\u4f3c\u5730\uff0c verticalCuts[j] \u662f\u4ece\u77e9\u5f62\u86cb\u7cd5\u7684\u5de6\u4fa7\u5230\u7b2c j \u4e2a\u7ad6\u76f4\u5207\u53e3\u7684\u8ddd\u79bb\u3002

\n\n

\u8bf7\u4f60\u6309\u6570\u7ec4 horizontalCuts \u548c verticalCuts \u4e2d\u63d0\u4f9b\u7684\u6c34\u5e73\u548c\u7ad6\u76f4\u4f4d\u7f6e\u5207\u5272\u540e\uff0c\u8bf7\u4f60\u627e\u51fa \u9762\u79ef\u6700\u5927 \u7684\u90a3\u4efd\u86cb\u7cd5\uff0c\u5e76\u8fd4\u56de\u5176 \u9762\u79ef \u3002\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u662f\u4e00\u4e2a\u5f88\u5927\u7684\u6570\u5b57\uff0c\u56e0\u6b64\u9700\u8981\u5c06\u7ed3\u679c\u5bf9 10^9 + 7 \u53d6\u4f59\u540e\u8fd4\u56de\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1ah = 5, w = 4, horizontalCuts = [1,2,4], verticalCuts = [1,3]\n\u8f93\u51fa\uff1a4 \n\u89e3\u91ca\uff1a\u4e0a\u56fe\u6240\u793a\u7684\u77e9\u9635\u86cb\u7cd5\u4e2d\uff0c\u7ea2\u8272\u7ebf\u8868\u793a\u6c34\u5e73\u548c\u7ad6\u76f4\u65b9\u5411\u4e0a\u7684\u5207\u53e3\u3002\u5207\u5272\u86cb\u7cd5\u540e\uff0c\u7eff\u8272\u7684\u90a3\u4efd\u86cb\u7cd5\u9762\u79ef\u6700\u5927\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1ah = 5, w = 4, horizontalCuts = [3,1], verticalCuts = [1]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u4e0a\u56fe\u6240\u793a\u7684\u77e9\u9635\u86cb\u7cd5\u4e2d\uff0c\u7ea2\u8272\u7ebf\u8868\u793a\u6c34\u5e73\u548c\u7ad6\u76f4\u65b9\u5411\u4e0a\u7684\u5207\u53e3\u3002\u5207\u5272\u86cb\u7cd5\u540e\uff0c\u7eff\u8272\u548c\u9ec4\u8272\u7684\u4e24\u4efd\u86cb\u7cd5\u9762\u79ef\u6700\u5927\u3002
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1ah = 5, w = 4, horizontalCuts = [3], verticalCuts = [3]\n\u8f93\u51fa\uff1a9\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= h, w <= 10^9
  • \n\t
  • 1 <= horizontalCuts.length < min(h, 10^5)
  • \n\t
  • 1 <= verticalCuts.length < min(w, 10^5)
  • \n\t
  • 1 <= horizontalCuts[i] < h
  • \n\t
  • 1 <= verticalCuts[i] < w
  • \n\t
  • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1 horizontalCuts \u4e2d\u7684\u6240\u6709\u5143\u7d20\u5404\u4e0d\u76f8\u540c
  • \n\t
  • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1 verticalCuts \u4e2d\u7684\u6240\u6709\u5143\u7d20\u5404\u4e0d\u76f8\u540c
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxArea(int h, int w, vector& horizontalCuts, vector& verticalCuts) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxArea(int h, int w, int[] horizontalCuts, int[] verticalCuts) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxArea(self, h, w, horizontalCuts, verticalCuts):\n \"\"\"\n :type h: int\n :type w: int\n :type horizontalCuts: List[int]\n :type verticalCuts: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxArea(self, h: int, w: int, horizontalCuts: List[int], verticalCuts: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxArea(int h, int w, int* horizontalCuts, int horizontalCutsSize, int* verticalCuts, int verticalCutsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxArea(int h, int w, int[] horizontalCuts, int[] verticalCuts) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} h\n * @param {number} w\n * @param {number[]} horizontalCuts\n * @param {number[]} verticalCuts\n * @return {number}\n */\nvar maxArea = function(h, w, horizontalCuts, verticalCuts) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} h\n# @param {Integer} w\n# @param {Integer[]} horizontal_cuts\n# @param {Integer[]} vertical_cuts\n# @return {Integer}\ndef max_area(h, w, horizontal_cuts, vertical_cuts)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxArea(_ h: Int, _ w: Int, _ horizontalCuts: [Int], _ verticalCuts: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxArea(h int, w int, horizontalCuts []int, verticalCuts []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxArea(h: Int, w: Int, horizontalCuts: Array[Int], verticalCuts: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxArea(h: Int, w: Int, horizontalCuts: IntArray, verticalCuts: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_area(h: i32, w: i32, horizontal_cuts: Vec, vertical_cuts: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $h\n * @param Integer $w\n * @param Integer[] $horizontalCuts\n * @param Integer[] $verticalCuts\n * @return Integer\n */\n function maxArea($h, $w, $horizontalCuts, $verticalCuts) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxArea(h: number, w: number, horizontalCuts: number[], verticalCuts: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-area h w horizontalCuts verticalCuts)\n (-> exact-integer? exact-integer? (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1465](https://leetcode-cn.com/problems/maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts)", "[\u5207\u5272\u540e\u9762\u79ef\u6700\u5927\u7684\u86cb\u7cd5](/solution/1400-1499/1465.Maximum%20Area%20of%20a%20Piece%20of%20Cake%20After%20Horizontal%20and%20Vertical%20Cuts/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1465](https://leetcode.com/problems/maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts)", "[Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts](/solution/1400-1499/1465.Maximum%20Area%20of%20a%20Piece%20of%20Cake%20After%20Horizontal%20and%20Vertical%20Cuts/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "1574", "frontend_question_id": "1464", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-product-of-two-elements-in-an-array", "url_en": "https://leetcode.com/problems/maximum-product-of-two-elements-in-an-array", "relative_path_cn": "/solution/1400-1499/1464.Maximum%20Product%20of%20Two%20Elements%20in%20an%20Array/README.md", "relative_path_en": "/solution/1400-1499/1464.Maximum%20Product%20of%20Two%20Elements%20in%20an%20Array/README_EN.md", "title_cn": "\u6570\u7ec4\u4e2d\u4e24\u5143\u7d20\u7684\u6700\u5927\u4e58\u79ef", "title_en": "Maximum Product of Two Elements in an Array", "question_title_slug": "maximum-product-of-two-elements-in-an-array", "content_en": "Given the array of integers nums, you will choose two different indices i and j of that array. Return the maximum value of (nums[i]-1)*(nums[j]-1).\n

 

\n

Example 1:

\n\n
\nInput: nums = [3,4,5,2]\nOutput: 12 \nExplanation: If you choose the indices i=1 and j=2 (indexed from 0), you will get the maximum value, that is, (nums[1]-1)*(nums[2]-1) = (4-1)*(5-1) = 3*4 = 12. \n
\n\n

Example 2:

\n\n
\nInput: nums = [1,5,4,5]\nOutput: 16\nExplanation: Choosing the indices i=1 and j=3 (indexed from 0), you will get the maximum value of (5-1)*(5-1) = 16.\n
\n\n

Example 3:

\n\n
\nInput: nums = [3,7]\nOutput: 12\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= nums.length <= 500
  • \n\t
  • 1 <= nums[i] <= 10^3
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums\uff0c\u8bf7\u4f60\u9009\u62e9\u6570\u7ec4\u7684\u4e24\u4e2a\u4e0d\u540c\u4e0b\u6807 i \u548c j\uff0c\u4f7f (nums[i]-1)*(nums[j]-1) \u53d6\u5f97\u6700\u5927\u503c\u3002

\n\n

\u8bf7\u4f60\u8ba1\u7b97\u5e76\u8fd4\u56de\u8be5\u5f0f\u7684\u6700\u5927\u503c\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anums = [3,4,5,2]\n\u8f93\u51fa\uff1a12 \n\u89e3\u91ca\uff1a\u5982\u679c\u9009\u62e9\u4e0b\u6807 i=1 \u548c j=2\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\uff0c\u5219\u53ef\u4ee5\u83b7\u5f97\u6700\u5927\u503c\uff0c(nums[1]-1)*(nums[2]-1) = (4-1)*(5-1) = 3*4 = 12 \u3002 \n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,5,4,5]\n\u8f93\u51fa\uff1a16\n\u89e3\u91ca\uff1a\u9009\u62e9\u4e0b\u6807 i=1 \u548c j=3\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\uff0c\u5219\u53ef\u4ee5\u83b7\u5f97\u6700\u5927\u503c (5-1)*(5-1) = 16 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1anums = [3,7]\n\u8f93\u51fa\uff1a12\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= nums.length <= 500
  • \n\t
  • 1 <= nums[i] <= 10^3
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxProduct(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxProduct(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxProduct(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxProduct(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxProduct(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxProduct(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar maxProduct = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef max_product(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxProduct(_ nums: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxProduct(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxProduct(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxProduct(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_product(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function maxProduct($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxProduct(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-product nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1464](https://leetcode-cn.com/problems/maximum-product-of-two-elements-in-an-array)", "[\u6570\u7ec4\u4e2d\u4e24\u5143\u7d20\u7684\u6700\u5927\u4e58\u79ef](/solution/1400-1499/1464.Maximum%20Product%20of%20Two%20Elements%20in%20an%20Array/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1464](https://leetcode.com/problems/maximum-product-of-two-elements-in-an-array)", "[Maximum Product of Two Elements in an Array](/solution/1400-1499/1464.Maximum%20Product%20of%20Two%20Elements%20in%20an%20Array/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1573", "frontend_question_id": "1477", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-two-non-overlapping-sub-arrays-each-with-target-sum", "url_en": "https://leetcode.com/problems/find-two-non-overlapping-sub-arrays-each-with-target-sum", "relative_path_cn": "/solution/1400-1499/1477.Find%20Two%20Non-overlapping%20Sub-arrays%20Each%20With%20Target%20Sum/README.md", "relative_path_en": "/solution/1400-1499/1477.Find%20Two%20Non-overlapping%20Sub-arrays%20Each%20With%20Target%20Sum/README_EN.md", "title_cn": "\u627e\u4e24\u4e2a\u548c\u4e3a\u76ee\u6807\u503c\u4e14\u4e0d\u91cd\u53e0\u7684\u5b50\u6570\u7ec4", "title_en": "Find Two Non-overlapping Sub-arrays Each With Target Sum", "question_title_slug": "find-two-non-overlapping-sub-arrays-each-with-target-sum", "content_en": "

Given an array of integers arr and an integer target.

\n\n

You have to find two non-overlapping sub-arrays of arr each with a sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.

\n\n

Return the minimum sum of the lengths of the two required sub-arrays, or return -1 if you cannot find such two sub-arrays.

\n\n

 

\n

Example 1:

\n\n
\nInput: arr = [3,2,2,4,3], target = 3\nOutput: 2\nExplanation: Only two sub-arrays have sum = 3 ([3] and [3]). The sum of their lengths is 2.\n
\n\n

Example 2:

\n\n
\nInput: arr = [7,3,4,7], target = 7\nOutput: 2\nExplanation: Although we have three non-overlapping sub-arrays of sum = 7 ([7], [3,4] and [7]), but we will choose the first and third sub-arrays as the sum of their lengths is 2.\n
\n\n

Example 3:

\n\n
\nInput: arr = [4,3,2,6,2,3,4], target = 6\nOutput: -1\nExplanation: We have only one sub-array of sum = 6.\n
\n\n

Example 4:

\n\n
\nInput: arr = [5,5,4,4,5], target = 3\nOutput: -1\nExplanation: We cannot find a sub-array of sum = 3.\n
\n\n

Example 5:

\n\n
\nInput: arr = [3,1,1,1,5,1,2,1], target = 3\nOutput: 3\nExplanation: Note that sub-arrays [1,2] and [2,1] cannot be an answer because they overlap.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= arr.length <= 105
  • \n\t
  • 1 <= arr[i] <= 1000
  • \n\t
  • 1 <= target <= 108
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr \u548c\u4e00\u4e2a\u6574\u6570\u503c target \u3002

\n\n

\u8bf7\u4f60\u5728 arr \u4e2d\u627e \u4e24\u4e2a\u4e92\u4e0d\u91cd\u53e0\u7684\u5b50\u6570\u7ec4 \u4e14\u5b83\u4eec\u7684\u548c\u90fd\u7b49\u4e8e target \u3002\u53ef\u80fd\u4f1a\u6709\u591a\u79cd\u65b9\u6848\uff0c\u8bf7\u4f60\u8fd4\u56de\u6ee1\u8db3\u8981\u6c42\u7684\u4e24\u4e2a\u5b50\u6570\u7ec4\u957f\u5ea6\u548c\u7684 \u6700\u5c0f\u503c \u3002

\n\n

\u8bf7\u8fd4\u56de\u6ee1\u8db3\u8981\u6c42\u7684\u6700\u5c0f\u957f\u5ea6\u548c\uff0c\u5982\u679c\u65e0\u6cd5\u627e\u5230\u8fd9\u6837\u7684\u4e24\u4e2a\u5b50\u6570\u7ec4\uff0c\u8bf7\u8fd4\u56de -1 \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aarr = [3,2,2,4,3], target = 3\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u53ea\u6709\u4e24\u4e2a\u5b50\u6570\u7ec4\u548c\u4e3a 3 \uff08[3] \u548c [3]\uff09\u3002\u5b83\u4eec\u7684\u957f\u5ea6\u548c\u4e3a 2 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aarr = [7,3,4,7], target = 7\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5c3d\u7ba1\u6211\u4eec\u6709 3 \u4e2a\u4e92\u4e0d\u91cd\u53e0\u7684\u5b50\u6570\u7ec4\u548c\u4e3a 7 \uff08[7], [3,4] \u548c [7]\uff09\uff0c\u4f46\u6211\u4eec\u4f1a\u9009\u62e9\u7b2c\u4e00\u4e2a\u548c\u7b2c\u4e09\u4e2a\u5b50\u6570\u7ec4\uff0c\u56e0\u4e3a\u5b83\u4eec\u7684\u957f\u5ea6\u548c 2 \u662f\u6700\u5c0f\u503c\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aarr = [4,3,2,6,2,3,4], target = 6\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u6211\u4eec\u53ea\u6709\u4e00\u4e2a\u548c\u4e3a 6 \u7684\u5b50\u6570\u7ec4\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1aarr = [5,5,4,4,5], target = 3\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u6211\u4eec\u65e0\u6cd5\u627e\u5230\u548c\u4e3a 3 \u7684\u5b50\u6570\u7ec4\u3002\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1aarr = [3,1,1,1,5,1,2,1], target = 3\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6ce8\u610f\u5b50\u6570\u7ec4 [1,2] \u548c [2,1] \u4e0d\u80fd\u6210\u4e3a\u4e00\u4e2a\u65b9\u6848\u56e0\u4e3a\u5b83\u4eec\u91cd\u53e0\u4e86\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= arr.length <= 10^5
  • \n\t
  • 1 <= arr[i] <= 1000
  • \n\t
  • 1 <= target <= 10^8
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minSumOfLengths(vector& arr, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minSumOfLengths(int[] arr, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minSumOfLengths(self, arr, target):\n \"\"\"\n :type arr: List[int]\n :type target: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minSumOfLengths(self, arr: List[int], target: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minSumOfLengths(int* arr, int arrSize, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinSumOfLengths(int[] arr, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @param {number} target\n * @return {number}\n */\nvar minSumOfLengths = function(arr, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @param {Integer} target\n# @return {Integer}\ndef min_sum_of_lengths(arr, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minSumOfLengths(_ arr: [Int], _ target: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minSumOfLengths(arr []int, target int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minSumOfLengths(arr: Array[Int], target: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minSumOfLengths(arr: IntArray, target: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_sum_of_lengths(arr: Vec, target: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @param Integer $target\n * @return Integer\n */\n function minSumOfLengths($arr, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minSumOfLengths(arr: number[], target: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-sum-of-lengths arr target)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1477](https://leetcode-cn.com/problems/find-two-non-overlapping-sub-arrays-each-with-target-sum)", "[\u627e\u4e24\u4e2a\u548c\u4e3a\u76ee\u6807\u503c\u4e14\u4e0d\u91cd\u53e0\u7684\u5b50\u6570\u7ec4](/solution/1400-1499/1477.Find%20Two%20Non-overlapping%20Sub-arrays%20Each%20With%20Target%20Sum/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1477](https://leetcode.com/problems/find-two-non-overlapping-sub-arrays-each-with-target-sum)", "[Find Two Non-overlapping Sub-arrays Each With Target Sum](/solution/1400-1499/1477.Find%20Two%20Non-overlapping%20Sub-arrays%20Each%20With%20Target%20Sum/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "1572", "frontend_question_id": "1476", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/subrectangle-queries", "url_en": "https://leetcode.com/problems/subrectangle-queries", "relative_path_cn": "/solution/1400-1499/1476.Subrectangle%20Queries/README.md", "relative_path_en": "/solution/1400-1499/1476.Subrectangle%20Queries/README_EN.md", "title_cn": "\u5b50\u77e9\u5f62\u67e5\u8be2", "title_en": "Subrectangle Queries", "question_title_slug": "subrectangle-queries", "content_en": "

Implement the class SubrectangleQueries which receives a rows x cols rectangle as a matrix of integers in the constructor and supports two methods:

\n\n

1. updateSubrectangle(int row1, int col1, int row2, int col2, int newValue)

\n\n
    \n\t
  • Updates all values with newValue in the subrectangle whose upper left coordinate is (row1,col1) and bottom right coordinate is (row2,col2).
  • \n
\n\n

2. getValue(int row, int col)

\n\n
    \n\t
  • Returns the current value of the coordinate (row,col) from the rectangle.
  • \n
\n\n

 

\n

Example 1:

\n\n
\nInput\n["SubrectangleQueries","getValue","updateSubrectangle","getValue","getValue","updateSubrectangle","getValue","getValue"]\n[[[[1,2,1],[4,3,4],[3,2,1],[1,1,1]]],[0,2],[0,0,3,2,5],[0,2],[3,1],[3,0,3,2,10],[3,1],[0,2]]\nOutput\n[null,1,null,5,5,null,10,5]\nExplanation\nSubrectangleQueries subrectangleQueries = new SubrectangleQueries([[1,2,1],[4,3,4],[3,2,1],[1,1,1]]);  \n// The initial rectangle (4x3) looks like:\n// 1 2 1\n// 4 3 4\n// 3 2 1\n// 1 1 1\nsubrectangleQueries.getValue(0, 2); // return 1\nsubrectangleQueries.updateSubrectangle(0, 0, 3, 2, 5);\n// After this update the rectangle looks like:\n// 5 5 5\n// 5 5 5\n// 5 5 5\n// 5 5 5 \nsubrectangleQueries.getValue(0, 2); // return 5\nsubrectangleQueries.getValue(3, 1); // return 5\nsubrectangleQueries.updateSubrectangle(3, 0, 3, 2, 10);\n// After this update the rectangle looks like:\n// 5   5   5\n// 5   5   5\n// 5   5   5\n// 10  10  10 \nsubrectangleQueries.getValue(3, 1); // return 10\nsubrectangleQueries.getValue(0, 2); // return 5\n
\n\n

Example 2:

\n\n
\nInput\n["SubrectangleQueries","getValue","updateSubrectangle","getValue","getValue","updateSubrectangle","getValue"]\n[[[[1,1,1],[2,2,2],[3,3,3]]],[0,0],[0,0,2,2,100],[0,0],[2,2],[1,1,2,2,20],[2,2]]\nOutput\n[null,1,null,100,100,null,20]\nExplanation\nSubrectangleQueries subrectangleQueries = new SubrectangleQueries([[1,1,1],[2,2,2],[3,3,3]]);\nsubrectangleQueries.getValue(0, 0); // return 1\nsubrectangleQueries.updateSubrectangle(0, 0, 2, 2, 100);\nsubrectangleQueries.getValue(0, 0); // return 100\nsubrectangleQueries.getValue(2, 2); // return 100\nsubrectangleQueries.updateSubrectangle(1, 1, 2, 2, 20);\nsubrectangleQueries.getValue(2, 2); // return 20\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • There will be at most 500 operations considering both methods: updateSubrectangle and getValue.
  • \n\t
  • 1 <= rows, cols <= 100
  • \n\t
  • rows == rectangle.length
  • \n\t
  • cols == rectangle[i].length
  • \n\t
  • 0 <= row1 <= row2 < rows
  • \n\t
  • 0 <= col1 <= col2 < cols
  • \n\t
  • 1 <= newValue, rectangle[i][j] <= 10^9
  • \n\t
  • 0 <= row < rows
  • \n\t
  • 0 <= col < cols
  • \n
\n", "content_cn": "

\u8bf7\u4f60\u5b9e\u73b0\u4e00\u4e2a\u7c7b SubrectangleQueries \uff0c\u5b83\u7684\u6784\u9020\u51fd\u6570\u7684\u53c2\u6570\u662f\u4e00\u4e2a rows x cols \u7684\u77e9\u5f62\uff08\u8fd9\u91cc\u7528\u6574\u6570\u77e9\u9635\u8868\u793a\uff09\uff0c\u5e76\u652f\u6301\u4ee5\u4e0b\u4e24\u79cd\u64cd\u4f5c\uff1a

\n\n

1. updateSubrectangle(int row1, int col1, int row2, int col2, int newValue)

\n\n
    \n\t
  • \u7528 newValue \u66f4\u65b0\u4ee5 (row1,col1) \u4e3a\u5de6\u4e0a\u89d2\u4e14\u4ee5 (row2,col2) \u4e3a\u53f3\u4e0b\u89d2\u7684\u5b50\u77e9\u5f62\u3002
  • \n
\n\n

2. getValue(int row, int col)

\n\n
    \n\t
  • \u8fd4\u56de\u77e9\u5f62\u4e2d\u5750\u6807 (row,col) \u7684\u5f53\u524d\u503c\u3002
  • \n
\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a\n["SubrectangleQueries","getValue","updateSubrectangle","getValue","getValue","updateSubrectangle","getValue","getValue"]\n[[[[1,2,1],[4,3,4],[3,2,1],[1,1,1]]],[0,2],[0,0,3,2,5],[0,2],[3,1],[3,0,3,2,10],[3,1],[0,2]]\n\u8f93\u51fa\uff1a\n[null,1,null,5,5,null,10,5]\n\u89e3\u91ca\uff1a\nSubrectangleQueries subrectangleQueries = new SubrectangleQueries([[1,2,1],[4,3,4],[3,2,1],[1,1,1]]);  \n// \u521d\u59cb\u7684 (4x3) \u77e9\u5f62\u5982\u4e0b\uff1a\n// 1 2 1\n// 4 3 4\n// 3 2 1\n// 1 1 1\nsubrectangleQueries.getValue(0, 2); // \u8fd4\u56de 1\nsubrectangleQueries.updateSubrectangle(0, 0, 3, 2, 5);\n// \u6b64\u6b21\u66f4\u65b0\u540e\u77e9\u5f62\u53d8\u4e3a\uff1a\n// 5 5 5\n// 5 5 5\n// 5 5 5\n// 5 5 5 \nsubrectangleQueries.getValue(0, 2); // \u8fd4\u56de 5\nsubrectangleQueries.getValue(3, 1); // \u8fd4\u56de 5\nsubrectangleQueries.updateSubrectangle(3, 0, 3, 2, 10);\n// \u6b64\u6b21\u66f4\u65b0\u540e\u77e9\u5f62\u53d8\u4e3a\uff1a\n// 5   5   5\n// 5   5   5\n// 5   5   5\n// 10  10  10 \nsubrectangleQueries.getValue(3, 1); // \u8fd4\u56de 10\nsubrectangleQueries.getValue(0, 2); // \u8fd4\u56de 5\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a\n["SubrectangleQueries","getValue","updateSubrectangle","getValue","getValue","updateSubrectangle","getValue"]\n[[[[1,1,1],[2,2,2],[3,3,3]]],[0,0],[0,0,2,2,100],[0,0],[2,2],[1,1,2,2,20],[2,2]]\n\u8f93\u51fa\uff1a\n[null,1,null,100,100,null,20]\n\u89e3\u91ca\uff1a\nSubrectangleQueries subrectangleQueries = new SubrectangleQueries([[1,1,1],[2,2,2],[3,3,3]]);\nsubrectangleQueries.getValue(0, 0); // \u8fd4\u56de 1\nsubrectangleQueries.updateSubrectangle(0, 0, 2, 2, 100);\nsubrectangleQueries.getValue(0, 0); // \u8fd4\u56de 100\nsubrectangleQueries.getValue(2, 2); // \u8fd4\u56de 100\nsubrectangleQueries.updateSubrectangle(1, 1, 2, 2, 20);\nsubrectangleQueries.getValue(2, 2); // \u8fd4\u56de 20\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u6700\u591a\u6709 500 \u6b21updateSubrectangle \u548c getValue \u64cd\u4f5c\u3002
  • \n\t
  • 1 <= rows, cols <= 100
  • \n\t
  • rows == rectangle.length
  • \n\t
  • cols == rectangle[i].length
  • \n\t
  • 0 <= row1 <= row2 < rows
  • \n\t
  • 0 <= col1 <= col2 < cols
  • \n\t
  • 1 <= newValue, rectangle[i][j] <= 10^9
  • \n\t
  • 0 <= row < rows
  • \n\t
  • 0 <= col < cols
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class SubrectangleQueries {\npublic:\n SubrectangleQueries(vector>& rectangle) {\n\n }\n \n void updateSubrectangle(int row1, int col1, int row2, int col2, int newValue) {\n\n }\n \n int getValue(int row, int col) {\n\n }\n};\n\n/**\n * Your SubrectangleQueries object will be instantiated and called as such:\n * SubrectangleQueries* obj = new SubrectangleQueries(rectangle);\n * obj->updateSubrectangle(row1,col1,row2,col2,newValue);\n * int param_2 = obj->getValue(row,col);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class SubrectangleQueries {\n\n public SubrectangleQueries(int[][] rectangle) {\n\n }\n \n public void updateSubrectangle(int row1, int col1, int row2, int col2, int newValue) {\n\n }\n \n public int getValue(int row, int col) {\n\n }\n}\n\n/**\n * Your SubrectangleQueries object will be instantiated and called as such:\n * SubrectangleQueries obj = new SubrectangleQueries(rectangle);\n * obj.updateSubrectangle(row1,col1,row2,col2,newValue);\n * int param_2 = obj.getValue(row,col);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class SubrectangleQueries(object):\n\n def __init__(self, rectangle):\n \"\"\"\n :type rectangle: List[List[int]]\n \"\"\"\n\n\n def updateSubrectangle(self, row1, col1, row2, col2, newValue):\n \"\"\"\n :type row1: int\n :type col1: int\n :type row2: int\n :type col2: int\n :type newValue: int\n :rtype: None\n \"\"\"\n\n\n def getValue(self, row, col):\n \"\"\"\n :type row: int\n :type col: int\n :rtype: int\n \"\"\"\n\n\n\n# Your SubrectangleQueries object will be instantiated and called as such:\n# obj = SubrectangleQueries(rectangle)\n# obj.updateSubrectangle(row1,col1,row2,col2,newValue)\n# param_2 = obj.getValue(row,col)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class SubrectangleQueries:\n\n def __init__(self, rectangle: List[List[int]]):\n\n\n def updateSubrectangle(self, row1: int, col1: int, row2: int, col2: int, newValue: int) -> None:\n\n\n def getValue(self, row: int, col: int) -> int:\n\n\n\n# Your SubrectangleQueries object will be instantiated and called as such:\n# obj = SubrectangleQueries(rectangle)\n# obj.updateSubrectangle(row1,col1,row2,col2,newValue)\n# param_2 = obj.getValue(row,col)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} SubrectangleQueries;\n\n\nSubrectangleQueries* subrectangleQueriesCreate(int** rectangle, int rectangleSize, int* rectangleColSize) {\n\n}\n\nvoid subrectangleQueriesUpdateSubrectangle(SubrectangleQueries* obj, int row1, int col1, int row2, int col2, int newValue) {\n\n}\n\nint subrectangleQueriesGetValue(SubrectangleQueries* obj, int row, int col) {\n\n}\n\nvoid subrectangleQueriesFree(SubrectangleQueries* obj) {\n\n}\n\n/**\n * Your SubrectangleQueries struct will be instantiated and called as such:\n * SubrectangleQueries* obj = subrectangleQueriesCreate(rectangle, rectangleSize, rectangleColSize);\n * subrectangleQueriesUpdateSubrectangle(obj, row1, col1, row2, col2, newValue);\n \n * int param_2 = subrectangleQueriesGetValue(obj, row, col);\n \n * subrectangleQueriesFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class SubrectangleQueries {\n\n public SubrectangleQueries(int[][] rectangle) {\n\n }\n \n public void UpdateSubrectangle(int row1, int col1, int row2, int col2, int newValue) {\n\n }\n \n public int GetValue(int row, int col) {\n\n }\n}\n\n/**\n * Your SubrectangleQueries object will be instantiated and called as such:\n * SubrectangleQueries obj = new SubrectangleQueries(rectangle);\n * obj.UpdateSubrectangle(row1,col1,row2,col2,newValue);\n * int param_2 = obj.GetValue(row,col);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} rectangle\n */\nvar SubrectangleQueries = function(rectangle) {\n\n};\n\n/** \n * @param {number} row1 \n * @param {number} col1 \n * @param {number} row2 \n * @param {number} col2 \n * @param {number} newValue\n * @return {void}\n */\nSubrectangleQueries.prototype.updateSubrectangle = function(row1, col1, row2, col2, newValue) {\n\n};\n\n/** \n * @param {number} row \n * @param {number} col\n * @return {number}\n */\nSubrectangleQueries.prototype.getValue = function(row, col) {\n\n};\n\n/**\n * Your SubrectangleQueries object will be instantiated and called as such:\n * var obj = new SubrectangleQueries(rectangle)\n * obj.updateSubrectangle(row1,col1,row2,col2,newValue)\n * var param_2 = obj.getValue(row,col)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class SubrectangleQueries\n\n=begin\n :type rectangle: Integer[][]\n=end\n def initialize(rectangle)\n\n end\n\n\n=begin\n :type row1: Integer\n :type col1: Integer\n :type row2: Integer\n :type col2: Integer\n :type new_value: Integer\n :rtype: Void\n=end\n def update_subrectangle(row1, col1, row2, col2, new_value)\n\n end\n\n\n=begin\n :type row: Integer\n :type col: Integer\n :rtype: Integer\n=end\n def get_value(row, col)\n\n end\n\n\nend\n\n# Your SubrectangleQueries object will be instantiated and called as such:\n# obj = SubrectangleQueries.new(rectangle)\n# obj.update_subrectangle(row1, col1, row2, col2, new_value)\n# param_2 = obj.get_value(row, col)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass SubrectangleQueries {\n\n init(_ rectangle: [[Int]]) {\n\n }\n \n func updateSubrectangle(_ row1: Int, _ col1: Int, _ row2: Int, _ col2: Int, _ newValue: Int) {\n\n }\n \n func getValue(_ row: Int, _ col: Int) -> Int {\n\n }\n}\n\n/**\n * Your SubrectangleQueries object will be instantiated and called as such:\n * let obj = SubrectangleQueries(rectangle)\n * obj.updateSubrectangle(row1, col1, row2, col2, newValue)\n * let ret_2: Int = obj.getValue(row, col)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type SubrectangleQueries struct {\n\n}\n\n\nfunc Constructor(rectangle [][]int) SubrectangleQueries {\n\n}\n\n\nfunc (this *SubrectangleQueries) UpdateSubrectangle(row1 int, col1 int, row2 int, col2 int, newValue int) {\n\n}\n\n\nfunc (this *SubrectangleQueries) GetValue(row int, col int) int {\n\n}\n\n\n/**\n * Your SubrectangleQueries object will be instantiated and called as such:\n * obj := Constructor(rectangle);\n * obj.UpdateSubrectangle(row1,col1,row2,col2,newValue);\n * param_2 := obj.GetValue(row,col);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class SubrectangleQueries(_rectangle: Array[Array[Int]]) {\n\n def updateSubrectangle(row1: Int, col1: Int, row2: Int, col2: Int, newValue: Int) {\n\n }\n\n def getValue(row: Int, col: Int): Int = {\n\n }\n\n}\n\n/**\n * Your SubrectangleQueries object will be instantiated and called as such:\n * var obj = new SubrectangleQueries(rectangle)\n * obj.updateSubrectangle(row1,col1,row2,col2,newValue)\n * var param_2 = obj.getValue(row,col)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class SubrectangleQueries(rectangle: Array) {\n\n fun updateSubrectangle(row1: Int, col1: Int, row2: Int, col2: Int, newValue: Int) {\n\n }\n\n fun getValue(row: Int, col: Int): Int {\n\n }\n\n}\n\n/**\n * Your SubrectangleQueries object will be instantiated and called as such:\n * var obj = SubrectangleQueries(rectangle)\n * obj.updateSubrectangle(row1,col1,row2,col2,newValue)\n * var param_2 = obj.getValue(row,col)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct SubrectangleQueries {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl SubrectangleQueries {\n\n fn new(rectangle: Vec>) -> Self {\n\n }\n \n fn update_subrectangle(&self, row1: i32, col1: i32, row2: i32, col2: i32, new_value: i32) {\n\n }\n \n fn get_value(&self, row: i32, col: i32) -> i32 {\n\n }\n}\n\n/**\n * Your SubrectangleQueries object will be instantiated and called as such:\n * let obj = SubrectangleQueries::new(rectangle);\n * obj.update_subrectangle(row1, col1, row2, col2, newValue);\n * let ret_2: i32 = obj.get_value(row, col);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class SubrectangleQueries {\n /**\n * @param Integer[][] $rectangle\n */\n function __construct($rectangle) {\n\n }\n\n /**\n * @param Integer $row1\n * @param Integer $col1\n * @param Integer $row2\n * @param Integer $col2\n * @param Integer $newValue\n * @return NULL\n */\n function updateSubrectangle($row1, $col1, $row2, $col2, $newValue) {\n\n }\n\n /**\n * @param Integer $row\n * @param Integer $col\n * @return Integer\n */\n function getValue($row, $col) {\n\n }\n}\n\n/**\n * Your SubrectangleQueries object will be instantiated and called as such:\n * $obj = SubrectangleQueries($rectangle);\n * $obj->updateSubrectangle($row1, $col1, $row2, $col2, $newValue);\n * $ret_2 = $obj->getValue($row, $col);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class SubrectangleQueries {\n constructor(rectangle: number[][]) {\n\n }\n\n updateSubrectangle(row1: number, col1: number, row2: number, col2: number, newValue: number): void {\n\n }\n\n getValue(row: number, col: number): number {\n\n }\n}\n\n/**\n * Your SubrectangleQueries object will be instantiated and called as such:\n * var obj = new SubrectangleQueries(rectangle)\n * obj.updateSubrectangle(row1,col1,row2,col2,newValue)\n * var param_2 = obj.getValue(row,col)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define subrectangle-queries%\n (class object%\n (super-new)\n\n ; rectangle : (listof (listof exact-integer?))\n (init-field\n rectangle)\n \n ; update-subrectangle : exact-integer? exact-integer? exact-integer? exact-integer? exact-integer? -> void?\n (define/public (update-subrectangle row1 col1 row2 col2 newValue)\n\n )\n ; get-value : exact-integer? exact-integer? -> exact-integer?\n (define/public (get-value row col)\n\n )))\n\n;; Your subrectangle-queries% object will be instantiated and called as such:\n;; (define obj (new subrectangle-queries% [rectangle rectangle]))\n;; (send obj update-subrectangle row1 col1 row2 col2 new-value)\n;; (define param_2 (send obj get-value row col))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1476](https://leetcode-cn.com/problems/subrectangle-queries)", "[\u5b50\u77e9\u5f62\u67e5\u8be2](/solution/1400-1499/1476.Subrectangle%20Queries/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1476](https://leetcode.com/problems/subrectangle-queries)", "[Subrectangle Queries](/solution/1400-1499/1476.Subrectangle%20Queries/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "1571", "frontend_question_id": "1478", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/allocate-mailboxes", "url_en": "https://leetcode.com/problems/allocate-mailboxes", "relative_path_cn": "/solution/1400-1499/1478.Allocate%20Mailboxes/README.md", "relative_path_en": "/solution/1400-1499/1478.Allocate%20Mailboxes/README_EN.md", "title_cn": "\u5b89\u6392\u90ae\u7b52", "title_en": "Allocate Mailboxes", "question_title_slug": "allocate-mailboxes", "content_en": "

Given the array houses and an integer k. where houses[i] is the location of the ith house along a street, your task is to allocate k mailboxes in the street.

\r\n\r\n

Return the minimum total distance between each house and its nearest mailbox.

\r\n\r\n

The answer is guaranteed to fit in a 32-bit signed integer.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n

\"\"

\r\n\r\n
\r\nInput: houses = [1,4,8,10,20], k = 3\r\nOutput: 5\r\nExplanation: Allocate mailboxes in position 3, 9 and 20.\r\nMinimum total distance from each houses to nearest mailboxes is |3-1| + |4-3| + |9-8| + |10-9| + |20-20| = 5 \r\n
\r\n\r\n

Example 2:

\r\n\r\n

\"\"

\r\n\r\n
\r\nInput: houses = [2,3,5,12,18], k = 2\r\nOutput: 9\r\nExplanation: Allocate mailboxes in position 3 and 14.\r\nMinimum total distance from each houses to nearest mailboxes is |2-3| + |3-3| + |5-3| + |12-14| + |18-14| = 9.\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: houses = [7,4,6,1], k = 1\r\nOutput: 8\r\n
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: houses = [3,6,14,10], k = 4\r\nOutput: 0\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • n == houses.length
  • \r\n\t
  • 1 <= n <= 100
  • \r\n\t
  • 1 <= houses[i] <= 10^4
  • \r\n\t
  • 1 <= k <= n
  • \r\n\t
  • Array houses contain unique integers.
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u623f\u5c4b\u6570\u7ec4houses \u548c\u4e00\u4e2a\u6574\u6570 k \uff0c\u5176\u4e2d houses[i] \u662f\u7b2c i \u680b\u623f\u5b50\u5728\u4e00\u6761\u8857\u4e0a\u7684\u4f4d\u7f6e\uff0c\u73b0\u9700\u8981\u5728\u8fd9\u6761\u8857\u4e0a\u5b89\u6392 k \u4e2a\u90ae\u7b52\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u6bcf\u680b\u623f\u5b50\u4e0e\u79bb\u5b83\u6700\u8fd1\u7684\u90ae\u7b52\u4e4b\u95f4\u7684\u8ddd\u79bb\u7684 \u6700\u5c0f \u603b\u548c\u3002

\n\n

\u7b54\u6848\u4fdd\u8bc1\u5728 32 \u4f4d\u6709\u7b26\u53f7\u6574\u6570\u8303\u56f4\u4ee5\u5185\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1ahouses = [1,4,8,10,20], k = 3\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u5c06\u90ae\u7b52\u5206\u522b\u5b89\u653e\u5728\u4f4d\u7f6e 3\uff0c 9 \u548c 20 \u5904\u3002\n\u6bcf\u4e2a\u623f\u5b50\u5230\u6700\u8fd1\u90ae\u7b52\u7684\u8ddd\u79bb\u548c\u4e3a |3-1| + |4-3| + |9-8| + |10-9| + |20-20| = 5 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1ahouses = [2,3,5,12,18], k = 2\n\u8f93\u51fa\uff1a9\n\u89e3\u91ca\uff1a\u5c06\u90ae\u7b52\u5206\u522b\u5b89\u653e\u5728\u4f4d\u7f6e 3 \u548c 14 \u5904\u3002\n\u6bcf\u4e2a\u623f\u5b50\u5230\u6700\u8fd1\u90ae\u7b52\u8ddd\u79bb\u548c\u4e3a |2-3| + |3-3| + |5-3| + |12-14| + |18-14| = 9 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1ahouses = [7,4,6,1], k = 1\n\u8f93\u51fa\uff1a8\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1ahouses = [3,6,14,10], k = 4\n\u8f93\u51fa\uff1a0\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • n == houses.length
  • \n\t
  • 1 <= n <= 100
  • \n\t
  • 1 <= houses[i] <= 10^4
  • \n\t
  • 1 <= k <= n
  • \n\t
  • \u6570\u7ec4 houses \u4e2d\u7684\u6574\u6570\u4e92\u4e0d\u76f8\u540c\u3002
  • \n
\n", "tags_en": ["Math", "Dynamic Programming"], "tags_cn": ["\u6570\u5b66", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minDistance(vector& houses, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minDistance(int[] houses, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minDistance(self, houses, k):\n \"\"\"\n :type houses: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minDistance(self, houses: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minDistance(int* houses, int housesSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinDistance(int[] houses, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} houses\n * @param {number} k\n * @return {number}\n */\nvar minDistance = function(houses, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} houses\n# @param {Integer} k\n# @return {Integer}\ndef min_distance(houses, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minDistance(_ houses: [Int], _ k: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minDistance(houses []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minDistance(houses: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minDistance(houses: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_distance(houses: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $houses\n * @param Integer $k\n * @return Integer\n */\n function minDistance($houses, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minDistance(houses: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-distance houses k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1478](https://leetcode-cn.com/problems/allocate-mailboxes)", "[\u5b89\u6392\u90ae\u7b52](/solution/1400-1499/1478.Allocate%20Mailboxes/README.md)", "`\u6570\u5b66`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1478](https://leetcode.com/problems/allocate-mailboxes)", "[Allocate Mailboxes](/solution/1400-1499/1478.Allocate%20Mailboxes/README_EN.md)", "`Math`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "1570", "frontend_question_id": "1475", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/final-prices-with-a-special-discount-in-a-shop", "url_en": "https://leetcode.com/problems/final-prices-with-a-special-discount-in-a-shop", "relative_path_cn": "/solution/1400-1499/1475.Final%20Prices%20With%20a%20Special%20Discount%20in%20a%20Shop/README.md", "relative_path_en": "/solution/1400-1499/1475.Final%20Prices%20With%20a%20Special%20Discount%20in%20a%20Shop/README_EN.md", "title_cn": "\u5546\u54c1\u6298\u6263\u540e\u7684\u6700\u7ec8\u4ef7\u683c", "title_en": "Final Prices With a Special Discount in a Shop", "question_title_slug": "final-prices-with-a-special-discount-in-a-shop", "content_en": "

Given the array prices where prices[i] is the price of the ith item in a shop. There is a special discount for items in the shop, if you buy the ith item, then you will receive a discount equivalent to prices[j] where j is the minimum index such that j > i and prices[j] <= prices[i], otherwise, you will not receive any discount at all.

\n\n

Return an array where the ith element is the final price you will pay for the ith item of the shop considering the special discount.

\n\n

 

\n

Example 1:

\n\n
\nInput: prices = [8,4,6,2,3]\nOutput: [4,2,4,2,3]\nExplanation: \nFor item 0 with price[0]=8 you will receive a discount equivalent to prices[1]=4, therefore, the final price you will pay is 8 - 4 = 4. \nFor item 1 with price[1]=4 you will receive a discount equivalent to prices[3]=2, therefore, the final price you will pay is 4 - 2 = 2. \nFor item 2 with price[2]=6 you will receive a discount equivalent to prices[3]=2, therefore, the final price you will pay is 6 - 2 = 4. \nFor items 3 and 4 you will not receive any discount at all.\n
\n\n

Example 2:

\n\n
\nInput: prices = [1,2,3,4,5]\nOutput: [1,2,3,4,5]\nExplanation: In this case, for all items, you will not receive any discount at all.\n
\n\n

Example 3:

\n\n
\nInput: prices = [10,1,1,6]\nOutput: [9,0,1,6]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= prices.length <= 500
  • \n\t
  • 1 <= prices[i] <= 10^3
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 prices \uff0c\u5176\u4e2d prices[i] \u662f\u5546\u5e97\u91cc\u7b2c i \u4ef6\u5546\u54c1\u7684\u4ef7\u683c\u3002

\n\n

\u5546\u5e97\u91cc\u6b63\u5728\u8fdb\u884c\u4fc3\u9500\u6d3b\u52a8\uff0c\u5982\u679c\u4f60\u8981\u4e70\u7b2c i \u4ef6\u5546\u54c1\uff0c\u90a3\u4e48\u4f60\u53ef\u4ee5\u5f97\u5230\u4e0e prices[j] \u76f8\u7b49\u7684\u6298\u6263\uff0c\u5176\u4e2d j \u662f\u6ee1\u8db3 j > i \u4e14 prices[j] <= prices[i] \u7684 \u6700\u5c0f\u4e0b\u6807 \uff0c\u5982\u679c\u6ca1\u6709\u6ee1\u8db3\u6761\u4ef6\u7684 j \uff0c\u4f60\u5c06\u6ca1\u6709\u4efb\u4f55\u6298\u6263\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u4e00\u4e2a\u6570\u7ec4\uff0c\u6570\u7ec4\u4e2d\u7b2c i \u4e2a\u5143\u7d20\u662f\u6298\u6263\u540e\u4f60\u8d2d\u4e70\u5546\u54c1 i \u6700\u7ec8\u9700\u8981\u652f\u4ed8\u7684\u4ef7\u683c\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aprices = [8,4,6,2,3]\n\u8f93\u51fa\uff1a[4,2,4,2,3]\n\u89e3\u91ca\uff1a\n\u5546\u54c1 0 \u7684\u4ef7\u683c\u4e3a price[0]=8 \uff0c\u4f60\u5c06\u5f97\u5230 prices[1]=4 \u7684\u6298\u6263\uff0c\u6240\u4ee5\u6700\u7ec8\u4ef7\u683c\u4e3a 8 - 4 = 4 \u3002\n\u5546\u54c1 1 \u7684\u4ef7\u683c\u4e3a price[1]=4 \uff0c\u4f60\u5c06\u5f97\u5230 prices[3]=2 \u7684\u6298\u6263\uff0c\u6240\u4ee5\u6700\u7ec8\u4ef7\u683c\u4e3a 4 - 2 = 2 \u3002\n\u5546\u54c1 2 \u7684\u4ef7\u683c\u4e3a price[2]=6 \uff0c\u4f60\u5c06\u5f97\u5230 prices[3]=2 \u7684\u6298\u6263\uff0c\u6240\u4ee5\u6700\u7ec8\u4ef7\u683c\u4e3a 6 - 2 = 4 \u3002\n\u5546\u54c1 3 \u548c 4 \u90fd\u6ca1\u6709\u6298\u6263\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aprices = [1,2,3,4,5]\n\u8f93\u51fa\uff1a[1,2,3,4,5]\n\u89e3\u91ca\uff1a\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6240\u6709\u5546\u54c1\u90fd\u6ca1\u6709\u6298\u6263\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aprices = [10,1,1,6]\n\u8f93\u51fa\uff1a[9,0,1,6]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= prices.length <= 500
  • \n\t
  • 1 <= prices[i] <= 10^3
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector finalPrices(vector& prices) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] finalPrices(int[] prices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def finalPrices(self, prices):\n \"\"\"\n :type prices: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def finalPrices(self, prices: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* finalPrices(int* prices, int pricesSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] FinalPrices(int[] prices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} prices\n * @return {number[]}\n */\nvar finalPrices = function(prices) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} prices\n# @return {Integer[]}\ndef final_prices(prices)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func finalPrices(_ prices: [Int]) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func finalPrices(prices []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def finalPrices(prices: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun finalPrices(prices: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn final_prices(prices: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $prices\n * @return Integer[]\n */\n function finalPrices($prices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function finalPrices(prices: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (final-prices prices)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1475](https://leetcode-cn.com/problems/final-prices-with-a-special-discount-in-a-shop)", "[\u5546\u54c1\u6298\u6263\u540e\u7684\u6700\u7ec8\u4ef7\u683c](/solution/1400-1499/1475.Final%20Prices%20With%20a%20Special%20Discount%20in%20a%20Shop/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1475](https://leetcode.com/problems/final-prices-with-a-special-discount-in-a-shop)", "[Final Prices With a Special Discount in a Shop](/solution/1400-1499/1475.Final%20Prices%20With%20a%20Special%20Discount%20in%20a%20Shop/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1569", "frontend_question_id": "1458", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/max-dot-product-of-two-subsequences", "url_en": "https://leetcode.com/problems/max-dot-product-of-two-subsequences", "relative_path_cn": "/solution/1400-1499/1458.Max%20Dot%20Product%20of%20Two%20Subsequences/README.md", "relative_path_en": "/solution/1400-1499/1458.Max%20Dot%20Product%20of%20Two%20Subsequences/README_EN.md", "title_cn": "\u4e24\u4e2a\u5b50\u5e8f\u5217\u7684\u6700\u5927\u70b9\u79ef", "title_en": "Max Dot Product of Two Subsequences", "question_title_slug": "max-dot-product-of-two-subsequences", "content_en": "

Given two arrays nums1 and nums2.

\n\n

Return the maximum dot product between non-empty subsequences of nums1 and nums2 with the same length.

\n\n

A subsequence of a array is a new array which is formed from the original array by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (ie, [2,3,5] is a subsequence of [1,2,3,4,5] while [1,5,3] is not).

\n\n

 

\n

Example 1:

\n\n
\nInput: nums1 = [2,1,-2,5], nums2 = [3,0,-6]\nOutput: 18\nExplanation: Take subsequence [2,-2] from nums1 and subsequence [3,-6] from nums2.\nTheir dot product is (2*3 + (-2)*(-6)) = 18.
\n\n

Example 2:

\n\n
\nInput: nums1 = [3,-2], nums2 = [2,-6,7]\nOutput: 21\nExplanation: Take subsequence [3] from nums1 and subsequence [7] from nums2.\nTheir dot product is (3*7) = 21.
\n\n

Example 3:

\n\n
\nInput: nums1 = [-1,-1], nums2 = [1,1]\nOutput: -1\nExplanation: Take subsequence [-1] from nums1 and subsequence [1] from nums2.\nTheir dot product is -1.
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums1.length, nums2.length <= 500
  • \n\t
  • -1000 <= nums1[i], nums2[i] <= 1000
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e24\u4e2a\u6570\u7ec4 nums1 \u548c nums2 \u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de nums1 \u548c nums2 \u4e2d\u4e24\u4e2a\u957f\u5ea6\u76f8\u540c\u7684 \u975e\u7a7a \u5b50\u5e8f\u5217\u7684\u6700\u5927\u70b9\u79ef\u3002

\n\n

\u6570\u7ec4\u7684\u975e\u7a7a\u5b50\u5e8f\u5217\u662f\u901a\u8fc7\u5220\u9664\u539f\u6570\u7ec4\u4e2d\u67d0\u4e9b\u5143\u7d20\uff08\u53ef\u80fd\u4e00\u4e2a\u4e5f\u4e0d\u5220\u9664\uff09\u540e\u5269\u4f59\u6570\u5b57\u7ec4\u6210\u7684\u5e8f\u5217\uff0c\u4f46\u4e0d\u80fd\u6539\u53d8\u6570\u5b57\u95f4\u76f8\u5bf9\u987a\u5e8f\u3002\u6bd4\u65b9\u8bf4\uff0c[2,3,5] \u662f [1,2,3,4,5] \u7684\u4e00\u4e2a\u5b50\u5e8f\u5217\u800c [1,5,3] \u4e0d\u662f\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1anums1 = [2,1,-2,5], nums2 = [3,0,-6]\n\u8f93\u51fa\uff1a18\n\u89e3\u91ca\uff1a\u4ece nums1 \u4e2d\u5f97\u5230\u5b50\u5e8f\u5217 [2,-2] \uff0c\u4ece nums2 \u4e2d\u5f97\u5230\u5b50\u5e8f\u5217 [3,-6] \u3002\n\u5b83\u4eec\u7684\u70b9\u79ef\u4e3a (2*3 + (-2)*(-6)) = 18 \u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1anums1 = [3,-2], nums2 = [2,-6,7]\n\u8f93\u51fa\uff1a21\n\u89e3\u91ca\uff1a\u4ece nums1 \u4e2d\u5f97\u5230\u5b50\u5e8f\u5217 [3] \uff0c\u4ece nums2 \u4e2d\u5f97\u5230\u5b50\u5e8f\u5217 [7] \u3002\n\u5b83\u4eec\u7684\u70b9\u79ef\u4e3a (3*7) = 21 \u3002
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1anums1 = [-1,-1], nums2 = [1,1]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u4ece nums1 \u4e2d\u5f97\u5230\u5b50\u5e8f\u5217 [-1] \uff0c\u4ece nums2 \u4e2d\u5f97\u5230\u5b50\u5e8f\u5217 [1] \u3002\n\u5b83\u4eec\u7684\u70b9\u79ef\u4e3a -1 \u3002
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums1.length, nums2.length <= 500
  • \n\t
  • -1000 <= nums1[i], nums2[i] <= 100
  • \n
\n\n

 

\n\n

\u70b9\u79ef\uff1a

\n\n
\n\u5b9a\u4e49 a = [a1a2,…, an] \u548c b = [b1b2,…, bn] \u7684\u70b9\u79ef\u4e3a\uff1a\n\n\"\\mathbf{a}\\cdot\n\n\u8fd9\u91cc\u7684 Σ \u6307\u793a\u603b\u548c\u7b26\u53f7\u3002\n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxDotProduct(vector& nums1, vector& nums2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxDotProduct(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxDotProduct(self, nums1, nums2):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxDotProduct(self, nums1: List[int], nums2: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxDotProduct(int* nums1, int nums1Size, int* nums2, int nums2Size){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxDotProduct(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums1\n * @param {number[]} nums2\n * @return {number}\n */\nvar maxDotProduct = function(nums1, nums2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums1\n# @param {Integer[]} nums2\n# @return {Integer}\ndef max_dot_product(nums1, nums2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxDotProduct(_ nums1: [Int], _ nums2: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxDotProduct(nums1 []int, nums2 []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxDotProduct(nums1: Array[Int], nums2: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxDotProduct(nums1: IntArray, nums2: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_dot_product(nums1: Vec, nums2: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums1\n * @param Integer[] $nums2\n * @return Integer\n */\n function maxDotProduct($nums1, $nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxDotProduct(nums1: number[], nums2: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-dot-product nums1 nums2)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1458](https://leetcode-cn.com/problems/max-dot-product-of-two-subsequences)", "[\u4e24\u4e2a\u5b50\u5e8f\u5217\u7684\u6700\u5927\u70b9\u79ef](/solution/1400-1499/1458.Max%20Dot%20Product%20of%20Two%20Subsequences/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1458](https://leetcode.com/problems/max-dot-product-of-two-subsequences)", "[Max Dot Product of Two Subsequences](/solution/1400-1499/1458.Max%20Dot%20Product%20of%20Two%20Subsequences/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1568", "frontend_question_id": "1457", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/pseudo-palindromic-paths-in-a-binary-tree", "url_en": "https://leetcode.com/problems/pseudo-palindromic-paths-in-a-binary-tree", "relative_path_cn": "/solution/1400-1499/1457.Pseudo-Palindromic%20Paths%20in%20a%20Binary%20Tree/README.md", "relative_path_en": "/solution/1400-1499/1457.Pseudo-Palindromic%20Paths%20in%20a%20Binary%20Tree/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u4e2d\u7684\u4f2a\u56de\u6587\u8def\u5f84", "title_en": "Pseudo-Palindromic Paths in a Binary Tree", "question_title_slug": "pseudo-palindromic-paths-in-a-binary-tree", "content_en": "

Given a binary tree where node values are digits from 1 to 9. A path in the binary tree is said to be pseudo-palindromic if at least one permutation of the node values in the path is a palindrome.

\n\n

Return the number of pseudo-palindromic paths going from the root node to leaf nodes.

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: root = [2,3,1,3,1,null,1]\nOutput: 2 \nExplanation: The figure above represents the given binary tree. There are three paths going from the root node to leaf nodes: the red path [2,3,3], the green path [2,1,1], and the path [2,3,1]. Among these paths only red path and green path are pseudo-palindromic paths since the red path [2,3,3] can be rearranged in [3,2,3] (palindrome) and the green path [2,1,1] can be rearranged in [1,2,1] (palindrome).\n
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: root = [2,1,1,1,3,null,null,null,null,null,1]\nOutput: 1 \nExplanation: The figure above represents the given binary tree. There are three paths going from the root node to leaf nodes: the green path [2,1,1], the path [2,1,3,1], and the path [2,1]. Among these paths only the green path is pseudo-palindromic since [2,1,1] can be rearranged in [1,2,1] (palindrome).\n
\n\n

Example 3:

\n\n
\nInput: root = [9]\nOutput: 1\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The number of nodes in the tree is in the range [1, 105].
  • \n\t
  • 1 <= Node.val <= 9
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u68f5\u4e8c\u53c9\u6811\uff0c\u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u4e3a 1 \u5230 9 \u3002\u6211\u4eec\u79f0\u4e8c\u53c9\u6811\u4e2d\u7684\u4e00\u6761\u8def\u5f84\u662f \u300c\u4f2a\u56de\u6587\u300d\u7684\uff0c\u5f53\u5b83\u6ee1\u8db3\uff1a\u8def\u5f84\u7ecf\u8fc7\u7684\u6240\u6709\u8282\u70b9\u503c\u7684\u6392\u5217\u4e2d\uff0c\u5b58\u5728\u4e00\u4e2a\u56de\u6587\u5e8f\u5217\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u4ece\u6839\u5230\u53f6\u5b50\u8282\u70b9\u7684\u6240\u6709\u8def\u5f84\u4e2d \u4f2a\u56de\u6587 \u8def\u5f84\u7684\u6570\u76ee\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1aroot = [2,3,1,3,1,null,1]\n\u8f93\u51fa\uff1a2 \n\u89e3\u91ca\uff1a\u4e0a\u56fe\u4e3a\u7ed9\u5b9a\u7684\u4e8c\u53c9\u6811\u3002\u603b\u5171\u6709 3 \u6761\u4ece\u6839\u5230\u53f6\u5b50\u7684\u8def\u5f84\uff1a\u7ea2\u8272\u8def\u5f84 [2,3,3] \uff0c\u7eff\u8272\u8def\u5f84 [2,1,1] \u548c\u8def\u5f84 [2,3,1] \u3002\n     \u5728\u8fd9\u4e9b\u8def\u5f84\u4e2d\uff0c\u53ea\u6709\u7ea2\u8272\u548c\u7eff\u8272\u7684\u8def\u5f84\u662f\u4f2a\u56de\u6587\u8def\u5f84\uff0c\u56e0\u4e3a\u7ea2\u8272\u8def\u5f84 [2,3,3] \u5b58\u5728\u56de\u6587\u6392\u5217 [3,2,3] \uff0c\u7eff\u8272\u8def\u5f84 [2,1,1] \u5b58\u5728\u56de\u6587\u6392\u5217 [1,2,1] \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1aroot = [2,1,1,1,3,null,null,null,null,null,1]\n\u8f93\u51fa\uff1a1 \n\u89e3\u91ca\uff1a\u4e0a\u56fe\u4e3a\u7ed9\u5b9a\u4e8c\u53c9\u6811\u3002\u603b\u5171\u6709 3 \u6761\u4ece\u6839\u5230\u53f6\u5b50\u7684\u8def\u5f84\uff1a\u7eff\u8272\u8def\u5f84 [2,1,1] \uff0c\u8def\u5f84 [2,1,3,1] \u548c\u8def\u5f84 [2,1] \u3002\n     \u8fd9\u4e9b\u8def\u5f84\u4e2d\u53ea\u6709\u7eff\u8272\u8def\u5f84\u662f\u4f2a\u56de\u6587\u8def\u5f84\uff0c\u56e0\u4e3a [2,1,1] \u5b58\u5728\u56de\u6587\u6392\u5217 [1,2,1] \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aroot = [9]\n\u8f93\u51fa\uff1a1\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u7ed9\u5b9a\u4e8c\u53c9\u6811\u7684\u8282\u70b9\u6570\u76ee\u5728 1 \u5230 10^5 \u4e4b\u95f4\u3002
  • \n\t
  • \u8282\u70b9\u503c\u5728 1 \u5230 9 \u4e4b\u95f4\u3002
  • \n
\n", "tags_en": ["Bit Manipulation", "Tree", "Depth-first Search"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int pseudoPalindromicPaths (TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int pseudoPalindromicPaths (TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def pseudoPalindromicPaths (self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def pseudoPalindromicPaths (self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint pseudoPalindromicPaths (struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int PseudoPalindromicPaths (TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar pseudoPalindromicPaths = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef pseudo_palindromic_paths (root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func pseudoPalindromicPaths (_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc pseudoPalindromicPaths (root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def pseudoPalindromicPaths (root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun pseudoPalindromicPaths (root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn pseudo_palindromic_paths (root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function pseudoPalindromicPaths ($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction pseudoPalindromicPaths (root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (pseudo-palindromic-paths root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1457](https://leetcode-cn.com/problems/pseudo-palindromic-paths-in-a-binary-tree)", "[\u4e8c\u53c9\u6811\u4e2d\u7684\u4f2a\u56de\u6587\u8def\u5f84](/solution/1400-1499/1457.Pseudo-Palindromic%20Paths%20in%20a%20Binary%20Tree/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1457](https://leetcode.com/problems/pseudo-palindromic-paths-in-a-binary-tree)", "[Pseudo-Palindromic Paths in a Binary Tree](/solution/1400-1499/1457.Pseudo-Palindromic%20Paths%20in%20a%20Binary%20Tree/README_EN.md)", "`Bit Manipulation`,`Tree`,`Depth-first Search`", "Medium", ""]}, {"question_id": "1567", "frontend_question_id": "1456", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-number-of-vowels-in-a-substring-of-given-length", "url_en": "https://leetcode.com/problems/maximum-number-of-vowels-in-a-substring-of-given-length", "relative_path_cn": "/solution/1400-1499/1456.Maximum%20Number%20of%20Vowels%20in%20a%20Substring%20of%20Given%20Length/README.md", "relative_path_en": "/solution/1400-1499/1456.Maximum%20Number%20of%20Vowels%20in%20a%20Substring%20of%20Given%20Length/README_EN.md", "title_cn": "\u5b9a\u957f\u5b50\u4e32\u4e2d\u5143\u97f3\u7684\u6700\u5927\u6570\u76ee", "title_en": "Maximum Number of Vowels in a Substring of Given Length", "question_title_slug": "maximum-number-of-vowels-in-a-substring-of-given-length", "content_en": "

Given a string s and an integer k.

\r\n\r\n

Return the maximum number of vowel letters in any substring of s with length k.

\r\n\r\n

Vowel letters in English are (a, e, i, o, u).

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: s = "abciiidef", k = 3\r\nOutput: 3\r\nExplanation: The substring "iii" contains 3 vowel letters.\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: s = "aeiou", k = 2\r\nOutput: 2\r\nExplanation: Any substring of length 2 contains 2 vowels.\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: s = "leetcode", k = 3\r\nOutput: 2\r\nExplanation: "lee", "eet" and "ode" contain 2 vowels.\r\n
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: s = "rhythms", k = 4\r\nOutput: 0\r\nExplanation: We can see that s doesn't have any vowel letters.\r\n
\r\n\r\n

Example 5:

\r\n\r\n
\r\nInput: s = "tryhard", k = 4\r\nOutput: 1\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= s.length <= 10^5
  • \r\n\t
  • s consists of lowercase English letters.
  • \r\n\t
  • 1 <= k <= s.length
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u5b57\u7b26\u4e32 s \u548c\u6574\u6570 k \u3002

\n\n

\u8bf7\u8fd4\u56de\u5b57\u7b26\u4e32 s \u4e2d\u957f\u5ea6\u4e3a k \u7684\u5355\u4e2a\u5b50\u5b57\u7b26\u4e32\u4e2d\u53ef\u80fd\u5305\u542b\u7684\u6700\u5927\u5143\u97f3\u5b57\u6bcd\u6570\u3002

\n\n

\u82f1\u6587\u4e2d\u7684 \u5143\u97f3\u5b57\u6bcd \u4e3a\uff08a, e, i, o, u\uff09\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1as = "abciiidef", k = 3\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u5b50\u5b57\u7b26\u4e32 "iii" \u5305\u542b 3 \u4e2a\u5143\u97f3\u5b57\u6bcd\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1as = "aeiou", k = 2\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u4efb\u610f\u957f\u5ea6\u4e3a 2 \u7684\u5b50\u5b57\u7b26\u4e32\u90fd\u5305\u542b 2 \u4e2a\u5143\u97f3\u5b57\u6bcd\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1as = "leetcode", k = 3\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a"lee"\u3001"eet" \u548c "ode" \u90fd\u5305\u542b 2 \u4e2a\u5143\u97f3\u5b57\u6bcd\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1as = "rhythms", k = 4\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u5b57\u7b26\u4e32 s \u4e2d\u4e0d\u542b\u4efb\u4f55\u5143\u97f3\u5b57\u6bcd\u3002\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1as = "tryhard", k = 4\n\u8f93\u51fa\uff1a1\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length <= 10^5
  • \n\t
  • s \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
  • \n\t
  • 1 <= k <= s.length
  • \n
\n", "tags_en": ["String", "Sliding Window"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxVowels(string s, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxVowels(String s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxVowels(self, s, k):\n \"\"\"\n :type s: str\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxVowels(self, s: str, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxVowels(char * s, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxVowels(string s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number} k\n * @return {number}\n */\nvar maxVowels = function(s, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer} k\n# @return {Integer}\ndef max_vowels(s, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxVowels(_ s: String, _ k: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxVowels(s string, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxVowels(s: String, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxVowels(s: String, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_vowels(s: String, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer $k\n * @return Integer\n */\n function maxVowels($s, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxVowels(s: string, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-vowels s k)\n (-> string? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1456](https://leetcode-cn.com/problems/maximum-number-of-vowels-in-a-substring-of-given-length)", "[\u5b9a\u957f\u5b50\u4e32\u4e2d\u5143\u97f3\u7684\u6700\u5927\u6570\u76ee](/solution/1400-1499/1456.Maximum%20Number%20of%20Vowels%20in%20a%20Substring%20of%20Given%20Length/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1456](https://leetcode.com/problems/maximum-number-of-vowels-in-a-substring-of-given-length)", "[Maximum Number of Vowels in a Substring of Given Length](/solution/1400-1499/1456.Maximum%20Number%20of%20Vowels%20in%20a%20Substring%20of%20Given%20Length/README_EN.md)", "`String`,`Sliding Window`", "Medium", ""]}, {"question_id": "1566", "frontend_question_id": "1455", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence", "url_en": "https://leetcode.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence", "relative_path_cn": "/solution/1400-1499/1455.Check%20If%20a%20Word%20Occurs%20As%20a%20Prefix%20of%20Any%20Word%20in%20a%20Sentence/README.md", "relative_path_en": "/solution/1400-1499/1455.Check%20If%20a%20Word%20Occurs%20As%20a%20Prefix%20of%20Any%20Word%20in%20a%20Sentence/README_EN.md", "title_cn": "\u68c0\u67e5\u5355\u8bcd\u662f\u5426\u4e3a\u53e5\u4e2d\u5176\u4ed6\u5355\u8bcd\u7684\u524d\u7f00", "title_en": "Check If a Word Occurs As a Prefix of Any Word in a Sentence", "question_title_slug": "check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence", "content_en": "

Given a sentence that consists of some words separated by a single space, and a searchWord.

\n\n

You have to check if searchWord is a prefix of any word in sentence.

\n\n

Return the index of the word in sentence where searchWord is a prefix of this word (1-indexed).

\n\n

If searchWord is a prefix of more than one word, return the index of the first word (minimum index). If there is no such word return -1.

\n\n

A prefix of a string S is any leading contiguous substring of S.

\n\n

 

\n

Example 1:

\n\n
\nInput: sentence = "i love eating burger", searchWord = "burg"\nOutput: 4\nExplanation: "burg" is prefix of "burger" which is the 4th word in the sentence.\n
\n\n

Example 2:

\n\n
\nInput: sentence = "this problem is an easy problem", searchWord = "pro"\nOutput: 2\nExplanation: "pro" is prefix of "problem" which is the 2nd and the 6th word in the sentence, but we return 2 as it's the minimal index.\n
\n\n

Example 3:

\n\n
\nInput: sentence = "i am tired", searchWord = "you"\nOutput: -1\nExplanation: "you" is not a prefix of any word in the sentence.\n
\n\n

Example 4:

\n\n
\nInput: sentence = "i use triple pillow", searchWord = "pill"\nOutput: 4\n
\n\n

Example 5:

\n\n
\nInput: sentence = "hello from the other side", searchWord = "they"\nOutput: -1\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= sentence.length <= 100
  • \n\t
  • 1 <= searchWord.length <= 10
  • \n\t
  • sentence consists of lowercase English letters and spaces.
  • \n\t
  • searchWord consists of lowercase English letters.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 sentence \u4f5c\u4e3a\u53e5\u5b50\u5e76\u6307\u5b9a\u68c0\u7d22\u8bcd\u4e3a searchWord \uff0c\u5176\u4e2d\u53e5\u5b50\u7531\u82e5\u5e72\u7528 \u5355\u4e2a\u7a7a\u683c \u5206\u9694\u7684\u5355\u8bcd\u7ec4\u6210\u3002

\n\n

\u8bf7\u4f60\u68c0\u67e5\u68c0\u7d22\u8bcd searchWord \u662f\u5426\u4e3a\u53e5\u5b50 sentence \u4e2d\u4efb\u610f\u5355\u8bcd\u7684\u524d\u7f00\u3002

\n\n
    \n\t
  • \u5982\u679c\u00a0searchWord \u662f\u67d0\u4e00\u4e2a\u5355\u8bcd\u7684\u524d\u7f00\uff0c\u5219\u8fd4\u56de\u53e5\u5b50\u00a0sentence \u4e2d\u8be5\u5355\u8bcd\u6240\u5bf9\u5e94\u7684\u4e0b\u6807\uff08\u4e0b\u6807\u4ece 1 \u5f00\u59cb\uff09\u3002
  • \n\t
  • \u5982\u679c searchWord \u662f\u591a\u4e2a\u5355\u8bcd\u7684\u524d\u7f00\uff0c\u5219\u8fd4\u56de\u5339\u914d\u7684\u7b2c\u4e00\u4e2a\u5355\u8bcd\u7684\u4e0b\u6807\uff08\u6700\u5c0f\u4e0b\u6807\uff09\u3002
  • \n\t
  • \u5982\u679c searchWord \u4e0d\u662f\u4efb\u4f55\u5355\u8bcd\u7684\u524d\u7f00\uff0c\u5219\u8fd4\u56de -1 \u3002
  • \n
\n\n

\u5b57\u7b26\u4e32 S \u7684 \u524d\u7f00 \u662f S \u7684\u4efb\u4f55\u524d\u5bfc\u8fde\u7eed\u5b50\u5b57\u7b26\u4e32\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1asentence = \"i love eating burger\", searchWord = \"burg\"\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\"burg\" \u662f \"burger\" \u7684\u524d\u7f00\uff0c\u800c \"burger\" \u662f\u53e5\u5b50\u4e2d\u7b2c 4 \u4e2a\u5355\u8bcd\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1asentence = \"this problem is an easy problem\", searchWord = \"pro\"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\"pro\" \u662f \"problem\" \u7684\u524d\u7f00\uff0c\u800c \"problem\" \u662f\u53e5\u5b50\u4e2d\u7b2c 2 \u4e2a\u4e5f\u662f\u7b2c 6 \u4e2a\u5355\u8bcd\uff0c\u4f46\u662f\u5e94\u8be5\u8fd4\u56de\u6700\u5c0f\u4e0b\u6807 2 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1asentence = \"i am tired\", searchWord = \"you\"\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\"you\" \u4e0d\u662f\u53e5\u5b50\u4e2d\u4efb\u4f55\u5355\u8bcd\u7684\u524d\u7f00\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1asentence = \"i use triple pillow\", searchWord = \"pill\"\n\u8f93\u51fa\uff1a4\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\n\u8f93\u5165\uff1asentence = \"hello from the other side\", searchWord = \"they\"\n\u8f93\u51fa\uff1a-1\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= sentence.length <= 100
  • \n\t
  • 1 <= searchWord.length <= 10
  • \n\t
  • sentence \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u548c\u7a7a\u683c\u7ec4\u6210\u3002
  • \n\t
  • searchWord \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\u3002
  • \n\t
  • \u524d\u7f00\u5c31\u662f\u7d27\u5bc6\u9644\u7740\u4e8e\u8bcd\u6839\u7684\u8bed\u7d20\uff0c\u4e2d\u95f4\u4e0d\u80fd\u63d2\u5165\u5176\u5b83\u6210\u5206\uff0c\u5e76\u4e14\u5b83\u7684\u4f4d\u7f6e\u662f\u56fa\u5b9a\u7684\u2014\u2014-\u4f4d\u4e8e\u8bcd\u6839\u4e4b\u524d\u3002\uff08\u5f15\u7528\u81ea \u524d\u7f00_\u767e\u5ea6\u767e\u79d1 \uff09
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int isPrefixOfWord(string sentence, string searchWord) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int isPrefixOfWord(String sentence, String searchWord) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isPrefixOfWord(self, sentence, searchWord):\n \"\"\"\n :type sentence: str\n :type searchWord: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isPrefixOfWord(self, sentence: str, searchWord: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint isPrefixOfWord(char * sentence, char * searchWord){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int IsPrefixOfWord(string sentence, string searchWord) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} sentence\n * @param {string} searchWord\n * @return {number}\n */\nvar isPrefixOfWord = function(sentence, searchWord) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} sentence\n# @param {String} search_word\n# @return {Integer}\ndef is_prefix_of_word(sentence, search_word)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isPrefixOfWord(_ sentence: String, _ searchWord: String) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isPrefixOfWord(sentence string, searchWord string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isPrefixOfWord(sentence: String, searchWord: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isPrefixOfWord(sentence: String, searchWord: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_prefix_of_word(sentence: String, search_word: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $sentence\n * @param String $searchWord\n * @return Integer\n */\n function isPrefixOfWord($sentence, $searchWord) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isPrefixOfWord(sentence: string, searchWord: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-prefix-of-word sentence searchWord)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1455](https://leetcode-cn.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence)", "[\u68c0\u67e5\u5355\u8bcd\u662f\u5426\u4e3a\u53e5\u4e2d\u5176\u4ed6\u5355\u8bcd\u7684\u524d\u7f00](/solution/1400-1499/1455.Check%20If%20a%20Word%20Occurs%20As%20a%20Prefix%20of%20Any%20Word%20in%20a%20Sentence/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1455](https://leetcode.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence)", "[Check If a Word Occurs As a Prefix of Any Word in a Sentence](/solution/1400-1499/1455.Check%20If%20a%20Word%20Occurs%20As%20a%20Prefix%20of%20Any%20Word%20in%20a%20Sentence/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1565", "frontend_question_id": "1440", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/evaluate-boolean-expression", "url_en": "https://leetcode.com/problems/evaluate-boolean-expression", "relative_path_cn": "/solution/1400-1499/1440.Evaluate%20Boolean%20Expression/README.md", "relative_path_en": "/solution/1400-1499/1440.Evaluate%20Boolean%20Expression/README_EN.md", "title_cn": "\u8ba1\u7b97\u5e03\u5c14\u8868\u8fbe\u5f0f\u7684\u503c", "title_en": "Evaluate Boolean Expression", "question_title_slug": "evaluate-boolean-expression", "content_en": "

Table Variables:

\r\n\r\n
\r\n+---------------+---------+\r\n| Column Name   | Type    |\r\n+---------------+---------+\r\n| name          | varchar |\r\n| value         | int     |\r\n+---------------+---------+\r\nname is the primary key for this table.\r\nThis table contains the stored variables and their values.\r\n
\r\n\r\n

 

\r\n\r\n

Table Expressions:

\r\n\r\n
\r\n+---------------+---------+\r\n| Column Name   | Type    |\r\n+---------------+---------+\r\n| left_operand  | varchar |\r\n| operator      | enum    |\r\n| right_operand | varchar |\r\n+---------------+---------+\r\n(left_operand, operator, right_operand) is the primary key for this table.\r\nThis table contains a boolean expression that should be evaluated.\r\noperator is an enum that takes one of the values ('<', '>', '=')\r\nThe values of left_operand and right_operand are guaranteed to be in the Variables table.\r\n
\r\n\r\n

 

\r\n\r\n

Write an SQL query to evaluate the boolean expressions in Expressions table.

\r\n\r\n

Return the result table in any order.

\r\n\r\n

The query result format is in the following example.

\r\n\r\n
\r\nVariables table:\r\n+------+-------+\r\n| name | value |\r\n+------+-------+\r\n| x    | 66    |\r\n| y    | 77    |\r\n+------+-------+\r\n\r\nExpressions table:\r\n+--------------+----------+---------------+\r\n| left_operand | operator | right_operand |\r\n+--------------+----------+---------------+\r\n| x            | >        | y             |\r\n| x            | <        | y             |\r\n| x            | =        | y             |\r\n| y            | >        | x             |\r\n| y            | <        | x             |\r\n| x            | =        | x             |\r\n+--------------+----------+---------------+\r\n\r\nResult table:\r\n+--------------+----------+---------------+-------+\r\n| left_operand | operator | right_operand | value |\r\n+--------------+----------+---------------+-------+\r\n| x            | >        | y             | false |\r\n| x            | <        | y             | true  |\r\n| x            | =        | y             | false |\r\n| y            | >        | x             | true  |\r\n| y            | <        | x             | false |\r\n| x            | =        | x             | true  |\r\n+--------------+----------+---------------+-------+\r\nAs shown, you need find the value of each boolean exprssion in the table using the variables table.\r\n
", "content_cn": "

\u8868 Variables:

\n\n
+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| name          | varchar |\n| value         | int     |\n+---------------+---------+\nname \u662f\u8be5\u8868\u4e3b\u952e.\n\u8be5\u8868\u5305\u542b\u4e86\u5b58\u50a8\u7684\u53d8\u91cf\u53ca\u5176\u5bf9\u5e94\u7684\u503c.\n
\n\n

 

\n\n

\u8868 Expressions:

\n\n
+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| left_operand  | varchar |\n| operator      | enum    |\n| right_operand | varchar |\n+---------------+---------+\n(left_operand, operator, right_operand) \u662f\u8be5\u8868\u4e3b\u952e.\n\u8be5\u8868\u5305\u542b\u4e86\u9700\u8981\u8ba1\u7b97\u7684\u5e03\u5c14\u8868\u8fbe\u5f0f.\noperator \u662f\u679a\u4e3e\u7c7b\u578b, \u53d6\u503c\u4e8e('<', '>', '=')\nleft_operand \u548c right_operand \u7684\u503c\u4fdd\u8bc1\u5b58\u5728\u4e8e Variables \u8868\u5355\u4e2d.\n
\n\n

 

\n\n

\u5199\u4e00\u4e2a SQL \u67e5\u8be2,  \u4ee5\u8ba1\u7b97\u8868 Expressions \u4e2d\u7684\u5e03\u5c14\u8868\u8fbe\u5f0f.

\n\n

\u8fd4\u56de\u7684\u7ed3\u679c\u8868\u6ca1\u6709\u987a\u5e8f\u8981\u6c42.

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a.

\n\n
Variables \u8868:\n+------+-------+\n| name | value |\n+------+-------+\n| x    | 66    |\n| y    | 77    |\n+------+-------+\n\nExpressions \u8868:\n+--------------+----------+---------------+\n| left_operand | operator | right_operand |\n+--------------+----------+---------------+\n| x            | >        | y             |\n| x            | <        | y             |\n| x            | =        | y             |\n| y            | >        | x             |\n| y            | <        | x             |\n| x            | =        | x             |\n+--------------+----------+---------------+\n\nResult \u8868:\n+--------------+----------+---------------+-------+\n| left_operand | operator | right_operand | value |\n+--------------+----------+---------------+-------+\n| x            | >        | y             | false |\n| x            | <        | y             | true  |\n| x            | =        | y             | false |\n| y            | >        | x             | true  |\n| y            | <        | x             | false |\n| x            | =        | x             | true  |\n+--------------+----------+---------------+-------+\n\u5982\u4e0a\u6240\u793a, \u4f60\u9700\u8981\u901a\u8fc7\u4f7f\u7528 Variables \u8868\u6765\u627e\u5230 Expressions \u8868\u4e2d\u7684\u6bcf\u4e00\u4e2a\u5e03\u5c14\u8868\u8fbe\u5f0f\u7684\u503c.\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1440](https://leetcode-cn.com/problems/evaluate-boolean-expression)", "[\u8ba1\u7b97\u5e03\u5c14\u8868\u8fbe\u5f0f\u7684\u503c](/solution/1400-1499/1440.Evaluate%20Boolean%20Expression/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1440](https://leetcode.com/problems/evaluate-boolean-expression)", "[Evaluate Boolean Expression](/solution/1400-1499/1440.Evaluate%20Boolean%20Expression/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1564", "frontend_question_id": "1435", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/create-a-session-bar-chart", "url_en": "https://leetcode.com/problems/create-a-session-bar-chart", "relative_path_cn": "/solution/1400-1499/1435.Create%20a%20Session%20Bar%20Chart/README.md", "relative_path_en": "/solution/1400-1499/1435.Create%20a%20Session%20Bar%20Chart/README_EN.md", "title_cn": "\u5236\u4f5c\u4f1a\u8bdd\u67f1\u72b6\u56fe", "title_en": "Create a Session Bar Chart", "question_title_slug": "create-a-session-bar-chart", "content_en": "

Table: Sessions

\n\n
\n+---------------------+---------+\n| Column Name         | Type    |\n+---------------------+---------+\n| session_id          | int     |\n| duration            | int     |\n+---------------------+---------+\nsession_id is the primary key for this table.\nduration is the time in seconds that a user has visited the application.\n
\n\n

 

\n\n

You want to know how long a user visits your application. You decided to create bins of "[0-5>", "[5-10>", "[10-15>" and "15 minutes or more" and count the number of sessions on it.

\n\n

Write an SQL query to report the (bin, total) in any order.

\n\n

The query result format is in the following example.

\n\n
\nSessions table:\n+-------------+---------------+\n| session_id  | duration      |\n+-------------+---------------+\n| 1           | 30            |\n| 2           | 199           |\n| 3           | 299           |\n| 4           | 580           |\n| 5           | 1000          |\n+-------------+---------------+\n\nResult table:\n+--------------+--------------+\n| bin          | total        |\n+--------------+--------------+\n| [0-5>        | 3            |\n| [5-10>       | 1            |\n| [10-15>      | 0            |\n| 15 or more   | 1            |\n+--------------+--------------+\n\nFor session_id 1, 2 and 3 have a duration greater or equal than 0 minutes and less than 5 minutes.\nFor session_id 4 has a duration greater or equal than 5 minutes and less than 10 minutes.\nThere are no session with a duration greater or equial than 10 minutes and less than 15 minutes.\nFor session_id 5 has a duration greater or equal than 15 minutes.\n
\n", "content_cn": "

\u8868\uff1aSessions

\n\n
+---------------------+---------+\n| Column Name         | Type    |\n+---------------------+---------+\n| session_id          | int     |\n| duration            | int     |\n+---------------------+---------+\nsession_id \u662f\u8be5\u8868\u4e3b\u952e\nduration \u662f\u7528\u6237\u8bbf\u95ee\u5e94\u7528\u7684\u65f6\u95f4, \u4ee5\u79d2\u4e3a\u5355\u4f4d\n
\n\n

 

\n\n

\u4f60\u60f3\u77e5\u9053\u7528\u6237\u5728\u4f60\u7684 app \u4e0a\u7684\u8bbf\u95ee\u65f6\u957f\u60c5\u51b5\u3002\u56e0\u6b64\u51b3\u5b9a\u7edf\u8ba1\u8bbf\u95ee\u65f6\u957f\u533a\u95f4\u5206\u522b\u4e3a "[0-5>", "[5-10>", "[10-15>" \u548c "15 or more" \uff08\u5355\u4f4d\uff1a\u5206\u949f\uff09\u7684\u4f1a\u8bdd\u6570\u91cf\uff0c\u5e76\u4ee5\u6b64\u7ed8\u5236\u67f1\u72b6\u56fe\u3002

\n\n

\u5199\u4e00\u4e2aSQL\u67e5\u8be2\u6765\u62a5\u544a\uff08\u8bbf\u95ee\u65f6\u957f\u533a\u95f4\uff0c\u4f1a\u8bdd\u603b\u6570\uff09\u3002\u7ed3\u679c\u53ef\u7528\u4efb\u4f55\u987a\u5e8f\u5448\u73b0\u3002

\n\n

 

\n\n

\u4e0b\u65b9\u4e3a\u67e5\u8be2\u7684\u8f93\u51fa\u683c\u5f0f\uff1a

\n\n
Sessions \u8868\uff1a\n+-------------+---------------+\n| session_id  | duration      |\n+-------------+---------------+\n| 1           | 30            |\n| 2           | 199           |\n| 3           | 299           |\n| 4           | 580           |\n| 5           | 1000          |\n+-------------+---------------+\n\nResult \u8868\uff1a\n+--------------+--------------+\n| bin          | total        |\n+--------------+--------------+\n| [0-5>        | 3            |\n| [5-10>       | 1            |\n| [10-15>      | 0            |\n| 15 or more   | 1            |\n+--------------+--------------+\n\n\u5bf9\u4e8e session_id 1\uff0c2 \u548c 3 \uff0c\u5b83\u4eec\u7684\u8bbf\u95ee\u65f6\u95f4\u5927\u4e8e\u7b49\u4e8e 0 \u5206\u949f\u4e14\u5c0f\u4e8e 5 \u5206\u949f\u3002\n\u5bf9\u4e8e session_id 4\uff0c\u5b83\u7684\u8bbf\u95ee\u65f6\u95f4\u5927\u4e8e\u7b49\u4e8e 5 \u5206\u949f\u4e14\u5c0f\u4e8e 10 \u5206\u949f\u3002\n\u6ca1\u6709\u4f1a\u8bdd\u7684\u8bbf\u95ee\u65f6\u95f4\u5927\u4e8e\u7b49\u4e8e 10 \u5206\u949f\u4e14\u5c0f\u4e8e 15 \u5206\u949f\u3002\n\u5bf9\u4e8e session_id 5, \u5b83\u7684\u8bbf\u95ee\u65f6\u95f4\u5927\u4e8e\u7b49\u4e8e 15 \u5206\u949f\u3002\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1435](https://leetcode-cn.com/problems/create-a-session-bar-chart)", "[\u5236\u4f5c\u4f1a\u8bdd\u67f1\u72b6\u56fe](/solution/1400-1499/1435.Create%20a%20Session%20Bar%20Chart/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1435](https://leetcode.com/problems/create-a-session-bar-chart)", "[Create a Session Bar Chart](/solution/1400-1499/1435.Create%20a%20Session%20Bar%20Chart/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1563", "frontend_question_id": "1453", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-number-of-darts-inside-of-a-circular-dartboard", "url_en": "https://leetcode.com/problems/maximum-number-of-darts-inside-of-a-circular-dartboard", "relative_path_cn": "/solution/1400-1499/1453.Maximum%20Number%20of%20Darts%20Inside%20of%20a%20Circular%20Dartboard/README.md", "relative_path_en": "/solution/1400-1499/1453.Maximum%20Number%20of%20Darts%20Inside%20of%20a%20Circular%20Dartboard/README_EN.md", "title_cn": "\u5706\u5f62\u9776\u5185\u7684\u6700\u5927\u98de\u9556\u6570\u91cf", "title_en": "Maximum Number of Darts Inside of a Circular Dartboard", "question_title_slug": "maximum-number-of-darts-inside-of-a-circular-dartboard", "content_en": "

You have a very large square wall and a circular dartboard placed on the wall. You have been challenged to throw darts into the board blindfolded. Darts thrown at the wall are represented as an array of points on a 2D plane. 

\r\n\r\n

Return the maximum number of points that are within or lie on any circular dartboard of radius r.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n

\"\"

\r\n\r\n
\r\nInput: points = [[-2,0],[2,0],[0,2],[0,-2]], r = 2\r\nOutput: 4\r\nExplanation: Circle dartboard with center in (0,0) and radius = 2 contain all points.\r\n
\r\n\r\n

Example 2:

\r\n\r\n

\"\"

\r\n\r\n
\r\nInput: points = [[-3,0],[3,0],[2,6],[5,4],[0,9],[7,8]], r = 5\r\nOutput: 5\r\nExplanation: Circle dartboard with center in (0,4) and radius = 5 contain all points except the point (7,8).\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: points = [[-2,0],[2,0],[0,2],[0,-2]], r = 1\r\nOutput: 1\r\n
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: points = [[1,2],[3,5],[1,-1],[2,3],[4,1],[1,3]], r = 2\r\nOutput: 4\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= points.length <= 100
  • \r\n\t
  • points[i].length == 2
  • \r\n\t
  • -10^4 <= points[i][0], points[i][1] <= 10^4
  • \r\n\t
  • 1 <= r <= 5000
  • \r\n
", "content_cn": "

\u5899\u58c1\u4e0a\u6302\u7740\u4e00\u4e2a\u5706\u5f62\u7684\u98de\u9556\u9776\u3002\u73b0\u5728\u8bf7\u4f60\u8499\u7740\u773c\u775b\u5411\u9776\u4e0a\u6295\u63b7\u98de\u9556\u3002

\n\n

\u6295\u63b7\u5230\u5899\u4e0a\u7684\u98de\u9556\u7528\u4e8c\u7ef4\u5e73\u9762\u4e0a\u7684\u70b9\u5750\u6807\u6570\u7ec4\u8868\u793a\u3002\u98de\u9556\u9776\u7684\u534a\u5f84\u4e3a r \u3002

\n\n

\u8bf7\u8fd4\u56de\u80fd\u591f\u843d\u5728 \u4efb\u610f \u534a\u5f84\u4e3a r \u7684\u5706\u5f62\u9776\u5185\u6216\u9776\u4e0a\u7684\u6700\u5927\u98de\u9556\u6570\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1apoints = [[-2,0],[2,0],[0,2],[0,-2]], r = 2\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u5982\u679c\u5706\u5f62\u7684\u98de\u9556\u9776\u7684\u5706\u5fc3\u4e3a (0,0) \uff0c\u534a\u5f84\u4e3a 2 \uff0c\u6240\u6709\u7684\u98de\u9556\u90fd\u843d\u5728\u9776\u4e0a\uff0c\u6b64\u65f6\u843d\u5728\u9776\u4e0a\u7684\u98de\u9556\u6570\u6700\u5927\uff0c\u503c\u4e3a 4 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1apoints = [[-3,0],[3,0],[2,6],[5,4],[0,9],[7,8]], r = 5\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u5982\u679c\u5706\u5f62\u7684\u98de\u9556\u9776\u7684\u5706\u5fc3\u4e3a (0,4) \uff0c\u534a\u5f84\u4e3a 5 \uff0c\u5219\u9664\u4e86 (7,8) \u4e4b\u5916\u7684\u98de\u9556\u90fd\u843d\u5728\u9776\u4e0a\uff0c\u6b64\u65f6\u843d\u5728\u9776\u4e0a\u7684\u98de\u9556\u6570\u6700\u5927\uff0c\u503c\u4e3a 5 \u3002
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1apoints = [[-2,0],[2,0],[0,2],[0,-2]], r = 1\n\u8f93\u51fa\uff1a1\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1apoints = [[1,2],[3,5],[1,-1],[2,3],[4,1],[1,3]], r = 2\n\u8f93\u51fa\uff1a4\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= points.length <= 100
  • \n\t
  • points[i].length == 2
  • \n\t
  • -10^4 <= points[i][0], points[i][1] <= 10^4
  • \n\t
  • 1 <= r <= 5000
  • \n
\n", "tags_en": ["Geometry"], "tags_cn": ["\u51e0\u4f55"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numPoints(vector>& points, int r) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numPoints(int[][] points, int r) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numPoints(self, points, r):\n \"\"\"\n :type points: List[List[int]]\n :type r: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numPoints(self, points: List[List[int]], r: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numPoints(int** points, int pointsSize, int* pointsColSize, int r){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumPoints(int[][] points, int r) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} points\n * @param {number} r\n * @return {number}\n */\nvar numPoints = function(points, r) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} points\n# @param {Integer} r\n# @return {Integer}\ndef num_points(points, r)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numPoints(_ points: [[Int]], _ r: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numPoints(points [][]int, r int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numPoints(points: Array[Array[Int]], r: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numPoints(points: Array, r: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_points(points: Vec>, r: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $points\n * @param Integer $r\n * @return Integer\n */\n function numPoints($points, $r) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numPoints(points: number[][], r: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-points points r)\n (-> (listof (listof exact-integer?)) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1453](https://leetcode-cn.com/problems/maximum-number-of-darts-inside-of-a-circular-dartboard)", "[\u5706\u5f62\u9776\u5185\u7684\u6700\u5927\u98de\u9556\u6570\u91cf](/solution/1400-1499/1453.Maximum%20Number%20of%20Darts%20Inside%20of%20a%20Circular%20Dartboard/README.md)", "`\u51e0\u4f55`", "\u56f0\u96be", ""], "md_table_row_en": ["[1453](https://leetcode.com/problems/maximum-number-of-darts-inside-of-a-circular-dartboard)", "[Maximum Number of Darts Inside of a Circular Dartboard](/solution/1400-1499/1453.Maximum%20Number%20of%20Darts%20Inside%20of%20a%20Circular%20Dartboard/README_EN.md)", "`Geometry`", "Hard", ""]}, {"question_id": "1562", "frontend_question_id": "1452", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/people-whose-list-of-favorite-companies-is-not-a-subset-of-another-list", "url_en": "https://leetcode.com/problems/people-whose-list-of-favorite-companies-is-not-a-subset-of-another-list", "relative_path_cn": "/solution/1400-1499/1452.People%20Whose%20List%20of%20Favorite%20Companies%20Is%20Not%20a%20Subset%20of%20Another%20List/README.md", "relative_path_en": "/solution/1400-1499/1452.People%20Whose%20List%20of%20Favorite%20Companies%20Is%20Not%20a%20Subset%20of%20Another%20List/README_EN.md", "title_cn": "\u6536\u85cf\u6e05\u5355", "title_en": "People Whose List of Favorite Companies Is Not a Subset of Another List", "question_title_slug": "people-whose-list-of-favorite-companies-is-not-a-subset-of-another-list", "content_en": "

Given the array favoriteCompanies where favoriteCompanies[i] is the list of favorites companies for the ith person (indexed from 0).

\n\n

Return the indices of people whose list of favorite companies is not a subset of any other list of favorites companies. You must return the indices in increasing order.

\n\n

 

\n

Example 1:

\n\n
\nInput: favoriteCompanies = [["leetcode","google","facebook"],["google","microsoft"],["google","facebook"],["google"],["amazon"]]\nOutput: [0,1,4] \nExplanation: \nPerson with index=2 has favoriteCompanies[2]=["google","facebook"] which is a subset of favoriteCompanies[0]=["leetcode","google","facebook"] corresponding to the person with index 0. \nPerson with index=3 has favoriteCompanies[3]=["google"] which is a subset of favoriteCompanies[0]=["leetcode","google","facebook"] and favoriteCompanies[1]=["google","microsoft"]. \nOther lists of favorite companies are not a subset of another list, therefore, the answer is [0,1,4].\n
\n\n

Example 2:

\n\n
\nInput: favoriteCompanies = [["leetcode","google","facebook"],["leetcode","amazon"],["facebook","google"]]\nOutput: [0,1] \nExplanation: In this case favoriteCompanies[2]=["facebook","google"] is a subset of favoriteCompanies[0]=["leetcode","google","facebook"], therefore, the answer is [0,1].\n
\n\n

Example 3:

\n\n
\nInput: favoriteCompanies = [["leetcode"],["google"],["facebook"],["amazon"]]\nOutput: [0,1,2,3]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= favoriteCompanies.length <= 100
  • \n\t
  • 1 <= favoriteCompanies[i].length <= 500
  • \n\t
  • 1 <= favoriteCompanies[i][j].length <= 20
  • \n\t
  • All strings in favoriteCompanies[i] are distinct.
  • \n\t
  • All lists of favorite companies are distinct, that is, If we sort alphabetically each list then favoriteCompanies[i] != favoriteCompanies[j].
  • \n\t
  • All strings consist of lowercase English letters only.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 favoriteCompanies \uff0c\u5176\u4e2d favoriteCompanies[i] \u662f\u7b2c i \u540d\u7528\u6237\u6536\u85cf\u7684\u516c\u53f8\u6e05\u5355\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\u3002

\n\n

\u8bf7\u627e\u51fa\u4e0d\u662f\u5176\u4ed6\u4efb\u4f55\u4eba\u6536\u85cf\u7684\u516c\u53f8\u6e05\u5355\u7684\u5b50\u96c6\u7684\u6536\u85cf\u6e05\u5355\uff0c\u5e76\u8fd4\u56de\u8be5\u6e05\u5355\u4e0b\u6807\u3002\u4e0b\u6807\u9700\u8981\u6309\u5347\u5e8f\u6392\u5217\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1afavoriteCompanies = [["leetcode","google","facebook"],["google","microsoft"],["google","facebook"],["google"],["amazon"]]\n\u8f93\u51fa\uff1a[0,1,4] \n\u89e3\u91ca\uff1a\nfavoriteCompanies[2]=["google","facebook"] \u662f favoriteCompanies[0]=["leetcode","google","facebook"] \u7684\u5b50\u96c6\u3002\nfavoriteCompanies[3]=["google"] \u662f favoriteCompanies[0]=["leetcode","google","facebook"] \u548c favoriteCompanies[1]=["google","microsoft"] \u7684\u5b50\u96c6\u3002\n\u5176\u4f59\u7684\u6536\u85cf\u6e05\u5355\u5747\u4e0d\u662f\u5176\u4ed6\u4efb\u4f55\u4eba\u6536\u85cf\u7684\u516c\u53f8\u6e05\u5355\u7684\u5b50\u96c6\uff0c\u56e0\u6b64\uff0c\u7b54\u6848\u4e3a [0,1,4] \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1afavoriteCompanies = [["leetcode","google","facebook"],["leetcode","amazon"],["facebook","google"]]\n\u8f93\u51fa\uff1a[0,1] \n\u89e3\u91ca\uff1afavoriteCompanies[2]=["facebook","google"] \u662f favoriteCompanies[0]=["leetcode","google","facebook"] \u7684\u5b50\u96c6\uff0c\u56e0\u6b64\uff0c\u7b54\u6848\u4e3a [0,1] \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1afavoriteCompanies = [["leetcode"],["google"],["facebook"],["amazon"]]\n\u8f93\u51fa\uff1a[0,1,2,3]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= favoriteCompanies.length <= 100
  • \n\t
  • 1 <= favoriteCompanies[i].length <= 500
  • \n\t
  • 1 <= favoriteCompanies[i][j].length <= 20
  • \n\t
  • favoriteCompanies[i] \u4e2d\u7684\u6240\u6709\u5b57\u7b26\u4e32 \u5404\u4e0d\u76f8\u540c \u3002
  • \n\t
  • \u7528\u6237\u6536\u85cf\u7684\u516c\u53f8\u6e05\u5355\u4e5f \u5404\u4e0d\u76f8\u540c \uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u5373\u4fbf\u6211\u4eec\u6309\u5b57\u6bcd\u987a\u5e8f\u6392\u5e8f\u6bcf\u4e2a\u6e05\u5355\uff0c favoriteCompanies[i] != favoriteCompanies[j] \u4ecd\u7136\u6210\u7acb\u3002
  • \n\t
  • \u6240\u6709\u5b57\u7b26\u4e32\u4ec5\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
  • \n
\n", "tags_en": ["Sort", "String"], "tags_cn": ["\u6392\u5e8f", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector peopleIndexes(vector>& favoriteCompanies) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List peopleIndexes(List> favoriteCompanies) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def peopleIndexes(self, favoriteCompanies):\n \"\"\"\n :type favoriteCompanies: List[List[str]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def peopleIndexes(self, favoriteCompanies: List[List[str]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* peopleIndexes(char *** favoriteCompanies, int favoriteCompaniesSize, int* favoriteCompaniesColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList PeopleIndexes(IList> favoriteCompanies) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[][]} favoriteCompanies\n * @return {number[]}\n */\nvar peopleIndexes = function(favoriteCompanies) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[][]} favorite_companies\n# @return {Integer[]}\ndef people_indexes(favorite_companies)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func peopleIndexes(_ favoriteCompanies: [[String]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func peopleIndexes(favoriteCompanies [][]string) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def peopleIndexes(favoriteCompanies: List[List[String]]): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun peopleIndexes(favoriteCompanies: List>): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn people_indexes(favorite_companies: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $favoriteCompanies\n * @return Integer[]\n */\n function peopleIndexes($favoriteCompanies) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function peopleIndexes(favoriteCompanies: string[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (people-indexes favoriteCompanies)\n (-> (listof (listof string?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1452](https://leetcode-cn.com/problems/people-whose-list-of-favorite-companies-is-not-a-subset-of-another-list)", "[\u6536\u85cf\u6e05\u5355](/solution/1400-1499/1452.People%20Whose%20List%20of%20Favorite%20Companies%20Is%20Not%20a%20Subset%20of%20Another%20List/README.md)", "`\u6392\u5e8f`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1452](https://leetcode.com/problems/people-whose-list-of-favorite-companies-is-not-a-subset-of-another-list)", "[People Whose List of Favorite Companies Is Not a Subset of Another List](/solution/1400-1499/1452.People%20Whose%20List%20of%20Favorite%20Companies%20Is%20Not%20a%20Subset%20of%20Another%20List/README_EN.md)", "`Sort`,`String`", "Medium", ""]}, {"question_id": "1561", "frontend_question_id": "1451", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/rearrange-words-in-a-sentence", "url_en": "https://leetcode.com/problems/rearrange-words-in-a-sentence", "relative_path_cn": "/solution/1400-1499/1451.Rearrange%20Words%20in%20a%20Sentence/README.md", "relative_path_en": "/solution/1400-1499/1451.Rearrange%20Words%20in%20a%20Sentence/README_EN.md", "title_cn": "\u91cd\u65b0\u6392\u5217\u53e5\u5b50\u4e2d\u7684\u5355\u8bcd", "title_en": "Rearrange Words in a Sentence", "question_title_slug": "rearrange-words-in-a-sentence", "content_en": "

Given a sentence text (A sentence is a string of space-separated words) in the following format:

\n\n
    \n\t
  • First letter is in upper case.
  • \n\t
  • Each word in text are separated by a single space.
  • \n
\n\n

Your task is to rearrange the words in text such that all words are rearranged in an increasing order of their lengths. If two words have the same length, arrange them in their original order.

\n\n

Return the new text following the format shown above.

\n\n

 

\n

Example 1:

\n\n
\nInput: text = "Leetcode is cool"\nOutput: "Is cool leetcode"\nExplanation: There are 3 words, "Leetcode" of length 8, "is" of length 2 and "cool" of length 4.\nOutput is ordered by length and the new first word starts with capital letter.\n
\n\n

Example 2:

\n\n
\nInput: text = "Keep calm and code on"\nOutput: "On and keep calm code"\nExplanation: Output is ordered as follows:\n"On" 2 letters.\n"and" 3 letters.\n"keep" 4 letters in case of tie order by position in original text.\n"calm" 4 letters.\n"code" 4 letters.\n
\n\n

Example 3:

\n\n
\nInput: text = "To be or not to be"\nOutput: "To be or to be not"\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • text begins with a capital letter and then contains lowercase letters and single space between words.
  • \n\t
  • 1 <= text.length <= 10^5
  • \n
\n", "content_cn": "

\u300c\u53e5\u5b50\u300d\u662f\u4e00\u4e2a\u7528\u7a7a\u683c\u5206\u9694\u5355\u8bcd\u7684\u5b57\u7b26\u4e32\u3002\u7ed9\u4f60\u4e00\u4e2a\u6ee1\u8db3\u4e0b\u8ff0\u683c\u5f0f\u7684\u53e5\u5b50 text :

\n\n
    \n\t
  • \u53e5\u5b50\u7684\u9996\u5b57\u6bcd\u5927\u5199
  • \n\t
  • text \u4e2d\u7684\u6bcf\u4e2a\u5355\u8bcd\u90fd\u7528\u5355\u4e2a\u7a7a\u683c\u5206\u9694\u3002
  • \n
\n\n

\u8bf7\u4f60\u91cd\u65b0\u6392\u5217 text \u4e2d\u7684\u5355\u8bcd\uff0c\u4f7f\u6240\u6709\u5355\u8bcd\u6309\u5176\u957f\u5ea6\u7684\u5347\u5e8f\u6392\u5217\u3002\u5982\u679c\u4e24\u4e2a\u5355\u8bcd\u7684\u957f\u5ea6\u76f8\u540c\uff0c\u5219\u4fdd\u7559\u5176\u5728\u539f\u53e5\u5b50\u4e2d\u7684\u76f8\u5bf9\u987a\u5e8f\u3002

\n\n

\u8bf7\u540c\u6837\u6309\u4e0a\u8ff0\u683c\u5f0f\u8fd4\u56de\u65b0\u7684\u53e5\u5b50\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1atext = "Leetcode is cool"\n\u8f93\u51fa\uff1a"Is cool leetcode"\n\u89e3\u91ca\uff1a\u53e5\u5b50\u4e2d\u5171\u6709 3 \u4e2a\u5355\u8bcd\uff0c\u957f\u5ea6\u4e3a 8 \u7684 "Leetcode" \uff0c\u957f\u5ea6\u4e3a 2 \u7684 "is" \u4ee5\u53ca\u957f\u5ea6\u4e3a 4 \u7684 "cool" \u3002\n\u8f93\u51fa\u9700\u8981\u6309\u5355\u8bcd\u7684\u957f\u5ea6\u5347\u5e8f\u6392\u5217\uff0c\u65b0\u53e5\u5b50\u4e2d\u7684\u7b2c\u4e00\u4e2a\u5355\u8bcd\u9996\u5b57\u6bcd\u9700\u8981\u5927\u5199\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1atext = "Keep calm and code on"\n\u8f93\u51fa\uff1a"On and keep calm code"\n\u89e3\u91ca\uff1a\u8f93\u51fa\u7684\u6392\u5e8f\u60c5\u51b5\u5982\u4e0b\uff1a\n"On" 2 \u4e2a\u5b57\u6bcd\u3002\n"and" 3 \u4e2a\u5b57\u6bcd\u3002\n"keep" 4 \u4e2a\u5b57\u6bcd\uff0c\u56e0\u4e3a\u5b58\u5728\u957f\u5ea6\u76f8\u540c\u7684\u5176\u4ed6\u5355\u8bcd\uff0c\u6240\u4ee5\u5b83\u4eec\u4e4b\u95f4\u9700\u8981\u4fdd\u7559\u5728\u539f\u53e5\u5b50\u4e2d\u7684\u76f8\u5bf9\u987a\u5e8f\u3002\n"calm" 4 \u4e2a\u5b57\u6bcd\u3002\n"code" 4 \u4e2a\u5b57\u6bcd\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1atext = "To be or not to be"\n\u8f93\u51fa\uff1a"To be or to be not"\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • text \u4ee5\u5927\u5199\u5b57\u6bcd\u5f00\u5934\uff0c\u7136\u540e\u5305\u542b\u82e5\u5e72\u5c0f\u5199\u5b57\u6bcd\u4ee5\u53ca\u5355\u8bcd\u95f4\u7684\u5355\u4e2a\u7a7a\u683c\u3002
  • \n\t
  • 1 <= text.length <= 10^5
  • \n
\n", "tags_en": ["Sort", "String"], "tags_cn": ["\u6392\u5e8f", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string arrangeWords(string text) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String arrangeWords(String text) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def arrangeWords(self, text):\n \"\"\"\n :type text: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def arrangeWords(self, text: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * arrangeWords(char * text){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ArrangeWords(string text) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} text\n * @return {string}\n */\nvar arrangeWords = function(text) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} text\n# @return {String}\ndef arrange_words(text)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func arrangeWords(_ text: String) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func arrangeWords(text string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def arrangeWords(text: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun arrangeWords(text: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn arrange_words(text: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $text\n * @return String\n */\n function arrangeWords($text) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function arrangeWords(text: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (arrange-words text)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1451](https://leetcode-cn.com/problems/rearrange-words-in-a-sentence)", "[\u91cd\u65b0\u6392\u5217\u53e5\u5b50\u4e2d\u7684\u5355\u8bcd](/solution/1400-1499/1451.Rearrange%20Words%20in%20a%20Sentence/README.md)", "`\u6392\u5e8f`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1451](https://leetcode.com/problems/rearrange-words-in-a-sentence)", "[Rearrange Words in a Sentence](/solution/1400-1499/1451.Rearrange%20Words%20in%20a%20Sentence/README_EN.md)", "`Sort`,`String`", "Medium", ""]}, {"question_id": "1560", "frontend_question_id": "1450", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-students-doing-homework-at-a-given-time", "url_en": "https://leetcode.com/problems/number-of-students-doing-homework-at-a-given-time", "relative_path_cn": "/solution/1400-1499/1450.Number%20of%20Students%20Doing%20Homework%20at%20a%20Given%20Time/README.md", "relative_path_en": "/solution/1400-1499/1450.Number%20of%20Students%20Doing%20Homework%20at%20a%20Given%20Time/README_EN.md", "title_cn": "\u5728\u65e2\u5b9a\u65f6\u95f4\u505a\u4f5c\u4e1a\u7684\u5b66\u751f\u4eba\u6570", "title_en": "Number of Students Doing Homework at a Given Time", "question_title_slug": "number-of-students-doing-homework-at-a-given-time", "content_en": "

Given two integer arrays startTime and endTime and given an integer queryTime.

\n\n

The ith student started doing their homework at the time startTime[i] and finished it at time endTime[i].

\n\n

Return the number of students doing their homework at time queryTime. More formally, return the number of students where queryTime lays in the interval [startTime[i], endTime[i]] inclusive.

\n\n

 

\n

Example 1:

\n\n
\nInput: startTime = [1,2,3], endTime = [3,2,7], queryTime = 4\nOutput: 1\nExplanation: We have 3 students where:\nThe first student started doing homework at time 1 and finished at time 3 and wasn't doing anything at time 4.\nThe second student started doing homework at time 2 and finished at time 2 and also wasn't doing anything at time 4.\nThe third student started doing homework at time 3 and finished at time 7 and was the only student doing homework at time 4.\n
\n\n

Example 2:

\n\n
\nInput: startTime = [4], endTime = [4], queryTime = 4\nOutput: 1\nExplanation: The only student was doing their homework at the queryTime.\n
\n\n

Example 3:

\n\n
\nInput: startTime = [4], endTime = [4], queryTime = 5\nOutput: 0\n
\n\n

Example 4:

\n\n
\nInput: startTime = [1,1,1,1], endTime = [1,3,2,4], queryTime = 7\nOutput: 0\n
\n\n

Example 5:

\n\n
\nInput: startTime = [9,8,7,6,5,4,3,2,1], endTime = [10,10,10,10,10,10,10,10,10], queryTime = 5\nOutput: 5\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • startTime.length == endTime.length
  • \n\t
  • 1 <= startTime.length <= 100
  • \n\t
  • 1 <= startTime[i] <= endTime[i] <= 1000
  • \n\t
  • 1 <= queryTime <= 1000
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e24\u4e2a\u6574\u6570\u6570\u7ec4 startTime\uff08\u5f00\u59cb\u65f6\u95f4\uff09\u548c endTime\uff08\u7ed3\u675f\u65f6\u95f4\uff09\uff0c\u5e76\u6307\u5b9a\u4e00\u4e2a\u6574\u6570 queryTime \u4f5c\u4e3a\u67e5\u8be2\u65f6\u95f4\u3002

\n\n

\u5df2\u77e5\uff0c\u7b2c i \u540d\u5b66\u751f\u5728 startTime[i] \u65f6\u5f00\u59cb\u5199\u4f5c\u4e1a\u5e76\u4e8e endTime[i] \u65f6\u5b8c\u6210\u4f5c\u4e1a\u3002

\n\n

\u8bf7\u8fd4\u56de\u5728\u67e5\u8be2\u65f6\u95f4 queryTime \u65f6\u6b63\u5728\u505a\u4f5c\u4e1a\u7684\u5b66\u751f\u4eba\u6570\u3002\u5f62\u5f0f\u4e0a\uff0c\u8fd4\u56de\u80fd\u591f\u4f7f queryTime \u5904\u4e8e\u533a\u95f4 [startTime[i], endTime[i]]\uff08\u542b\uff09\u7684\u5b66\u751f\u4eba\u6570\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1astartTime = [1,2,3], endTime = [3,2,7], queryTime = 4\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u4e00\u5171\u6709 3 \u540d\u5b66\u751f\u3002\n\u7b2c\u4e00\u540d\u5b66\u751f\u5728\u65f6\u95f4 1 \u5f00\u59cb\u5199\u4f5c\u4e1a\uff0c\u5e76\u4e8e\u65f6\u95f4 3 \u5b8c\u6210\u4f5c\u4e1a\uff0c\u5728\u65f6\u95f4 4 \u6ca1\u6709\u5904\u4e8e\u505a\u4f5c\u4e1a\u7684\u72b6\u6001\u3002\n\u7b2c\u4e8c\u540d\u5b66\u751f\u5728\u65f6\u95f4 2 \u5f00\u59cb\u5199\u4f5c\u4e1a\uff0c\u5e76\u4e8e\u65f6\u95f4 2 \u5b8c\u6210\u4f5c\u4e1a\uff0c\u5728\u65f6\u95f4 4 \u6ca1\u6709\u5904\u4e8e\u505a\u4f5c\u4e1a\u7684\u72b6\u6001\u3002\n\u7b2c\u4e09\u540d\u5b66\u751f\u5728\u65f6\u95f4 3 \u5f00\u59cb\u5199\u4f5c\u4e1a\uff0c\u9884\u8ba1\u4e8e\u65f6\u95f4 7 \u5b8c\u6210\u4f5c\u4e1a\uff0c\u8fd9\u662f\u662f\u552f\u4e00\u4e00\u540d\u5728\u65f6\u95f4 4 \u65f6\u6b63\u5728\u505a\u4f5c\u4e1a\u7684\u5b66\u751f\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1astartTime = [4], endTime = [4], queryTime = 4\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u5728\u67e5\u8be2\u65f6\u95f4\u53ea\u6709\u4e00\u540d\u5b66\u751f\u5728\u505a\u4f5c\u4e1a\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1astartTime = [4], endTime = [4], queryTime = 5\n\u8f93\u51fa\uff1a0\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1astartTime = [1,1,1,1], endTime = [1,3,2,4], queryTime = 7\n\u8f93\u51fa\uff1a0\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1astartTime = [9,8,7,6,5,4,3,2,1], endTime = [10,10,10,10,10,10,10,10,10], queryTime = 5\n\u8f93\u51fa\uff1a5\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • startTime.length == endTime.length
  • \n\t
  • 1 <= startTime.length <= 100
  • \n\t
  • 1 <= startTime[i] <= endTime[i] <= 1000
  • \n\t
  • 1 <= queryTime <= 1000
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int busyStudent(vector& startTime, vector& endTime, int queryTime) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int busyStudent(int[] startTime, int[] endTime, int queryTime) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def busyStudent(self, startTime, endTime, queryTime):\n \"\"\"\n :type startTime: List[int]\n :type endTime: List[int]\n :type queryTime: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint busyStudent(int* startTime, int startTimeSize, int* endTime, int endTimeSize, int queryTime){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int BusyStudent(int[] startTime, int[] endTime, int queryTime) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} startTime\n * @param {number[]} endTime\n * @param {number} queryTime\n * @return {number}\n */\nvar busyStudent = function(startTime, endTime, queryTime) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} start_time\n# @param {Integer[]} end_time\n# @param {Integer} query_time\n# @return {Integer}\ndef busy_student(start_time, end_time, query_time)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func busyStudent(_ startTime: [Int], _ endTime: [Int], _ queryTime: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func busyStudent(startTime []int, endTime []int, queryTime int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def busyStudent(startTime: Array[Int], endTime: Array[Int], queryTime: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun busyStudent(startTime: IntArray, endTime: IntArray, queryTime: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn busy_student(start_time: Vec, end_time: Vec, query_time: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $startTime\n * @param Integer[] $endTime\n * @param Integer $queryTime\n * @return Integer\n */\n function busyStudent($startTime, $endTime, $queryTime) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function busyStudent(startTime: number[], endTime: number[], queryTime: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (busy-student startTime endTime queryTime)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1450](https://leetcode-cn.com/problems/number-of-students-doing-homework-at-a-given-time)", "[\u5728\u65e2\u5b9a\u65f6\u95f4\u505a\u4f5c\u4e1a\u7684\u5b66\u751f\u4eba\u6570](/solution/1400-1499/1450.Number%20of%20Students%20Doing%20Homework%20at%20a%20Given%20Time/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1450](https://leetcode.com/problems/number-of-students-doing-homework-at-a-given-time)", "[Number of Students Doing Homework at a Given Time](/solution/1400-1499/1450.Number%20of%20Students%20Doing%20Homework%20at%20a%20Given%20Time/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1559", "frontend_question_id": "1463", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/cherry-pickup-ii", "url_en": "https://leetcode.com/problems/cherry-pickup-ii", "relative_path_cn": "/solution/1400-1499/1463.Cherry%20Pickup%20II/README.md", "relative_path_en": "/solution/1400-1499/1463.Cherry%20Pickup%20II/README_EN.md", "title_cn": "\u6458\u6a31\u6843 II", "title_en": "Cherry Pickup II", "question_title_slug": "cherry-pickup-ii", "content_en": "

Given a rows x cols matrix grid representing a field of cherries. Each cell in grid represents the number of cherries that you can collect.

\n\n

You have two robots that can collect cherries for you, Robot #1 is located at the top-left corner (0,0) , and Robot #2 is located at the top-right corner (0, cols-1) of the grid.

\n\n

Return the maximum number of cherries collection using both robots  by following the rules below:

\n\n
    \n\t
  • From a cell (i,j), robots can move to cell (i+1, j-1) , (i+1, j) or (i+1, j+1).
  • \n\t
  • When any robot is passing through a cell, It picks it up all cherries, and the cell becomes an empty cell (0).
  • \n\t
  • When both robots stay on the same cell, only one of them takes the cherries.
  • \n\t
  • Both robots cannot move outside of the grid at any moment.
  • \n\t
  • Both robots should reach the bottom row in the grid.
  • \n
\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: grid = [[3,1,1],[2,5,1],[1,5,5],[2,1,1]]\nOutput: 24\nExplanation: Path of robot #1 and #2 are described in color green and blue respectively.\nCherries taken by Robot #1, (3 + 2 + 5 + 2) = 12.\nCherries taken by Robot #2, (1 + 5 + 5 + 1) = 12.\nTotal of cherries: 12 + 12 = 24.\n
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: grid = [[1,0,0,0,0,0,1],[2,0,0,0,0,3,0],[2,0,9,0,0,0,0],[0,3,0,5,4,0,0],[1,0,2,3,0,0,6]]\nOutput: 28\nExplanation: Path of robot #1 and #2 are described in color green and blue respectively.\nCherries taken by Robot #1, (1 + 9 + 5 + 2) = 17.\nCherries taken by Robot #2, (1 + 3 + 4 + 3) = 11.\nTotal of cherries: 17 + 11 = 28.\n
\n\n

Example 3:

\n\n
\nInput: grid = [[1,0,0,3],[0,0,0,3],[0,0,3,3],[9,0,3,3]]\nOutput: 22\n
\n\n

Example 4:

\n\n
\nInput: grid = [[1,1],[1,1]]\nOutput: 4\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • rows == grid.length
  • \n\t
  • cols == grid[i].length
  • \n\t
  • 2 <= rows, cols <= 70
  • \n\t
  • 0 <= grid[i][j] <= 100 
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a rows x cols \u7684\u77e9\u9635 grid \u6765\u8868\u793a\u4e00\u5757\u6a31\u6843\u5730\u3002 grid \u4e2d\u6bcf\u4e2a\u683c\u5b50\u7684\u6570\u5b57\u8868\u793a\u4f60\u80fd\u83b7\u5f97\u7684\u6a31\u6843\u6570\u76ee\u3002

\n\n

\u4f60\u6709\u4e24\u4e2a\u673a\u5668\u4eba\u5e2e\u4f60\u6536\u96c6\u6a31\u6843\uff0c\u673a\u5668\u4eba 1 \u4ece\u5de6\u4e0a\u89d2\u683c\u5b50 (0,0) \u51fa\u53d1\uff0c\u673a\u5668\u4eba 2 \u4ece\u53f3\u4e0a\u89d2\u683c\u5b50 (0, cols-1) \u51fa\u53d1\u3002

\n\n

\u8bf7\u4f60\u6309\u7167\u5982\u4e0b\u89c4\u5219\uff0c\u8fd4\u56de\u4e24\u4e2a\u673a\u5668\u4eba\u80fd\u6536\u96c6\u7684\u6700\u591a\u6a31\u6843\u6570\u76ee\uff1a

\n\n
    \n\t
  • \u4ece\u683c\u5b50 (i,j) \u51fa\u53d1\uff0c\u673a\u5668\u4eba\u53ef\u4ee5\u79fb\u52a8\u5230\u683c\u5b50 (i+1, j-1)\uff0c(i+1, j) \u6216\u8005 (i+1, j+1) \u3002
  • \n\t
  • \u5f53\u4e00\u4e2a\u673a\u5668\u4eba\u7ecf\u8fc7\u67d0\u4e2a\u683c\u5b50\u65f6\uff0c\u5b83\u4f1a\u628a\u8be5\u683c\u5b50\u5185\u6240\u6709\u7684\u6a31\u6843\u90fd\u6458\u8d70\uff0c\u7136\u540e\u8fd9\u4e2a\u4f4d\u7f6e\u4f1a\u53d8\u6210\u7a7a\u683c\u5b50\uff0c\u5373\u6ca1\u6709\u6a31\u6843\u7684\u683c\u5b50\u3002
  • \n\t
  • \u5f53\u4e24\u4e2a\u673a\u5668\u4eba\u540c\u65f6\u5230\u8fbe\u540c\u4e00\u4e2a\u683c\u5b50\u65f6\uff0c\u5b83\u4eec\u4e2d\u53ea\u6709\u4e00\u4e2a\u53ef\u4ee5\u6458\u5230\u6a31\u6843\u3002
  • \n\t
  • \u4e24\u4e2a\u673a\u5668\u4eba\u5728\u4efb\u610f\u65f6\u523b\u90fd\u4e0d\u80fd\u79fb\u52a8\u5230 grid \u5916\u9762\u3002
  • \n\t
  • \u4e24\u4e2a\u673a\u5668\u4eba\u6700\u540e\u90fd\u8981\u5230\u8fbe grid \u6700\u5e95\u4e0b\u4e00\u884c\u3002
  • \n
\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1agrid = [[3,1,1],[2,5,1],[1,5,5],[2,1,1]]\n\u8f93\u51fa\uff1a24\n\u89e3\u91ca\uff1a\u673a\u5668\u4eba 1 \u548c\u673a\u5668\u4eba 2 \u7684\u8def\u5f84\u5728\u4e0a\u56fe\u4e2d\u5206\u522b\u7528\u7eff\u8272\u548c\u84dd\u8272\u8868\u793a\u3002\n\u673a\u5668\u4eba 1 \u6458\u7684\u6a31\u6843\u6570\u76ee\u4e3a (3 + 2 + 5 + 2) = 12 \u3002\n\u673a\u5668\u4eba 2 \u6458\u7684\u6a31\u6843\u6570\u76ee\u4e3a (1 + 5 + 5 + 1) = 12 \u3002\n\u6a31\u6843\u603b\u6570\u4e3a\uff1a 12 + 12 = 24 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1agrid = [[1,0,0,0,0,0,1],[2,0,0,0,0,3,0],[2,0,9,0,0,0,0],[0,3,0,5,4,0,0],[1,0,2,3,0,0,6]]\n\u8f93\u51fa\uff1a28\n\u89e3\u91ca\uff1a\u673a\u5668\u4eba 1 \u548c\u673a\u5668\u4eba 2 \u7684\u8def\u5f84\u5728\u4e0a\u56fe\u4e2d\u5206\u522b\u7528\u7eff\u8272\u548c\u84dd\u8272\u8868\u793a\u3002\n\u673a\u5668\u4eba 1 \u6458\u7684\u6a31\u6843\u6570\u76ee\u4e3a (1 + 9 + 5 + 2) = 17 \u3002\n\u673a\u5668\u4eba 2 \u6458\u7684\u6a31\u6843\u6570\u76ee\u4e3a (1 + 3 + 4 + 3) = 11 \u3002\n\u6a31\u6843\u603b\u6570\u4e3a\uff1a 17 + 11 = 28 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1agrid = [[1,0,0,3],[0,0,0,3],[0,0,3,3],[9,0,3,3]]\n\u8f93\u51fa\uff1a22\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1agrid = [[1,1],[1,1]]\n\u8f93\u51fa\uff1a4\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • rows == grid.length
  • \n\t
  • cols == grid[i].length
  • \n\t
  • 2 <= rows, cols <= 70
  • \n\t
  • 0 <= grid[i][j] <= 100 
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int cherryPickup(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int cherryPickup(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def cherryPickup(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def cherryPickup(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint cherryPickup(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CherryPickup(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar cherryPickup = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef cherry_pickup(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func cherryPickup(_ grid: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func cherryPickup(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def cherryPickup(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun cherryPickup(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn cherry_pickup(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function cherryPickup($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function cherryPickup(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (cherry-pickup grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1463](https://leetcode-cn.com/problems/cherry-pickup-ii)", "[\u6458\u6a31\u6843 II](/solution/1400-1499/1463.Cherry%20Pickup%20II/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1463](https://leetcode.com/problems/cherry-pickup-ii)", "[Cherry Pickup II](/solution/1400-1499/1463.Cherry%20Pickup%20II/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1558", "frontend_question_id": "1462", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/course-schedule-iv", "url_en": "https://leetcode.com/problems/course-schedule-iv", "relative_path_cn": "/solution/1400-1499/1462.Course%20Schedule%20IV/README.md", "relative_path_en": "/solution/1400-1499/1462.Course%20Schedule%20IV/README_EN.md", "title_cn": "\u8bfe\u7a0b\u8868 IV", "title_en": "Course Schedule IV", "question_title_slug": "course-schedule-iv", "content_en": "

There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i] = [ai, bi] indicates that you must take course bi first if you want to take course ai.

\n\n
    \n\t
  • For example, the pair [0, 1], indicates that to take course 0 you have to first take course 1.
  • \n
\n\n

You are also given an array queries where queries[j] = [uj, vj]. For the jth query, you should answer whether the course uj is a prerequisite of the course vj or not. Note that if course a is a prerequisite of course b and course b is a prerequisite of course c, then, course a is a prerequisite of course c.

\n\n

Return a boolean array answer, where answer[j] is the answer of the jth query.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: numCourses = 2, prerequisites = [[1,0]], queries = [[0,1],[1,0]]\nOutput: [false,true]\nExplanation: course 0 is not a prerequisite of course 1 but the opposite is true.\n
\n\n

Example 2:

\n\n
\nInput: numCourses = 2, prerequisites = [], queries = [[1,0],[0,1]]\nOutput: [false,false]\nExplanation: There are no prerequisites and each course is independent.\n
\n\n

Example 3:

\n\"\"\n
\nInput: numCourses = 3, prerequisites = [[1,2],[1,0],[2,0]], queries = [[1,0],[1,2]]\nOutput: [true,true]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= numCourses <= 100
  • \n\t
  • 0 <= prerequisite.length <= (numCourses * (numCourses - 1) / 2)
  • \n\t
  • 0 <= ai, bi < n
  • \n\t
  • ai != bi
  • \n\t
  • All the pairs [ai, bi] are unique.
  • \n\t
  • The prerequisites graph has no cycles.
  • \n\t
  • 1 <= queries.length <= 104
  • \n\t
  • 0 <= ui, vi < n
  • \n\t
  • ui != vi
  • \n
\n", "content_cn": "

\u4f60\u603b\u5171\u9700\u8981\u4e0a n \u95e8\u8bfe\uff0c\u8bfe\u7a0b\u7f16\u53f7\u4f9d\u6b21\u4e3a 0 \u5230 n-1 \u3002

\n\n

\u6709\u7684\u8bfe\u4f1a\u6709\u76f4\u63a5\u7684\u5148\u4fee\u8bfe\u7a0b\uff0c\u6bd4\u5982\u5982\u679c\u60f3\u4e0a\u8bfe\u7a0b 0 \uff0c\u4f60\u5fc5\u987b\u5148\u4e0a\u8bfe\u7a0b 1 \uff0c\u90a3\u4e48\u4f1a\u4ee5 [1,0] \u6570\u5bf9\u7684\u5f62\u5f0f\u7ed9\u51fa\u5148\u4fee\u8bfe\u7a0b\u6570\u5bf9\u3002

\n\n

\u7ed9\u4f60\u8bfe\u7a0b\u603b\u6570 n \u548c\u4e00\u4e2a\u76f4\u63a5\u5148\u4fee\u8bfe\u7a0b\u6570\u5bf9\u5217\u8868 prerequisite \u548c\u4e00\u4e2a\u67e5\u8be2\u5bf9\u5217\u8868 queries \u3002

\n\n

\u5bf9\u4e8e\u6bcf\u4e2a\u67e5\u8be2\u5bf9 queries[i] \uff0c\u8bf7\u5224\u65ad queries[i][0] \u662f\u5426\u662f queries[i][1] \u7684\u5148\u4fee\u8bfe\u7a0b\u3002

\n\n

\u8bf7\u8fd4\u56de\u4e00\u4e2a\u5e03\u5c14\u503c\u5217\u8868\uff0c\u5217\u8868\u4e2d\u6bcf\u4e2a\u5143\u7d20\u4f9d\u6b21\u5206\u522b\u5bf9\u5e94 queries \u6bcf\u4e2a\u67e5\u8be2\u5bf9\u7684\u5224\u65ad\u7ed3\u679c\u3002

\n\n

\u6ce8\u610f\uff1a\u5982\u679c\u8bfe\u7a0b a \u662f\u8bfe\u7a0b b \u7684\u5148\u4fee\u8bfe\u7a0b\u4e14\u8bfe\u7a0b b \u662f\u8bfe\u7a0b c \u7684\u5148\u4fee\u8bfe\u7a0b\uff0c\u90a3\u4e48\u8bfe\u7a0b a \u4e5f\u662f\u8bfe\u7a0b c \u7684\u5148\u4fee\u8bfe\u7a0b\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1an = 2, prerequisites = [[1,0]], queries = [[0,1],[1,0]]\n\u8f93\u51fa\uff1a[false,true]\n\u89e3\u91ca\uff1a\u8bfe\u7a0b 0 \u4e0d\u662f\u8bfe\u7a0b 1 \u7684\u5148\u4fee\u8bfe\u7a0b\uff0c\u4f46\u8bfe\u7a0b 1 \u662f\u8bfe\u7a0b 0 \u7684\u5148\u4fee\u8bfe\u7a0b\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1an = 2, prerequisites = [], queries = [[1,0],[0,1]]\n\u8f93\u51fa\uff1a[false,false]\n\u89e3\u91ca\uff1a\u6ca1\u6709\u5148\u4fee\u8bfe\u7a0b\u5bf9\uff0c\u6240\u4ee5\u6bcf\u95e8\u8bfe\u7a0b\u4e4b\u95f4\u662f\u72ec\u7acb\u7684\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1an = 3, prerequisites = [[1,2],[1,0],[2,0]], queries = [[1,0],[1,2]]\n\u8f93\u51fa\uff1a[true,true]\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1an = 3, prerequisites = [[1,0],[2,0]], queries = [[0,1],[2,0]]\n\u8f93\u51fa\uff1a[false,true]\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1an = 5, prerequisites = [[0,1],[1,2],[2,3],[3,4]], queries = [[0,4],[4,0],[1,3],[3,0]]\n\u8f93\u51fa\uff1a[true,false,true,false]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= n <= 100
  • \n\t
  • 0 <= prerequisite.length <= (n * (n - 1) / 2)
  • \n\t
  • 0 <= prerequisite[i][0], prerequisite[i][1] < n
  • \n\t
  • prerequisite[i][0] != prerequisite[i][1]
  • \n\t
  • \u5148\u4fee\u8bfe\u7a0b\u56fe\u4e2d\u6ca1\u6709\u73af\u3002
  • \n\t
  • \u5148\u4fee\u8bfe\u7a0b\u56fe\u4e2d\u6ca1\u6709\u91cd\u590d\u7684\u8fb9\u3002
  • \n\t
  • 1 <= queries.length <= 10^4
  • \n\t
  • queries[i][0] != queries[i][1]
  • \n
\n", "tags_en": ["Graph"], "tags_cn": ["\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector checkIfPrerequisite(int numCourses, vector>& prerequisites, vector>& queries) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List checkIfPrerequisite(int numCourses, int[][] prerequisites, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def checkIfPrerequisite(self, numCourses, prerequisites, queries):\n \"\"\"\n :type numCourses: int\n :type prerequisites: List[List[int]]\n :type queries: List[List[int]]\n :rtype: List[bool]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def checkIfPrerequisite(self, numCourses: int, prerequisites: List[List[int]], queries: List[List[int]]) -> List[bool]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nbool* checkIfPrerequisite(int numCourses, int** prerequisites, int prerequisitesSize, int* prerequisitesColSize, int** queries, int queriesSize, int* queriesColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList CheckIfPrerequisite(int numCourses, int[][] prerequisites, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} numCourses\n * @param {number[][]} prerequisites\n * @param {number[][]} queries\n * @return {boolean[]}\n */\nvar checkIfPrerequisite = function(numCourses, prerequisites, queries) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} num_courses\n# @param {Integer[][]} prerequisites\n# @param {Integer[][]} queries\n# @return {Boolean[]}\ndef check_if_prerequisite(num_courses, prerequisites, queries)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func checkIfPrerequisite(_ numCourses: Int, _ prerequisites: [[Int]], _ queries: [[Int]]) -> [Bool] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func checkIfPrerequisite(numCourses int, prerequisites [][]int, queries [][]int) []bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def checkIfPrerequisite(numCourses: Int, prerequisites: Array[Array[Int]], queries: Array[Array[Int]]): List[Boolean] = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun checkIfPrerequisite(numCourses: Int, prerequisites: Array, queries: Array): List {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn check_if_prerequisite(num_courses: i32, prerequisites: Vec>, queries: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $numCourses\n * @param Integer[][] $prerequisites\n * @param Integer[][] $queries\n * @return Boolean[]\n */\n function checkIfPrerequisite($numCourses, $prerequisites, $queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function checkIfPrerequisite(numCourses: number, prerequisites: number[][], queries: number[][]): boolean[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (check-if-prerequisite numCourses prerequisites queries)\n (-> exact-integer? (listof (listof exact-integer?)) (listof (listof exact-integer?)) (listof boolean?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1462](https://leetcode-cn.com/problems/course-schedule-iv)", "[\u8bfe\u7a0b\u8868 IV](/solution/1400-1499/1462.Course%20Schedule%20IV/README.md)", "`\u56fe`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1462](https://leetcode.com/problems/course-schedule-iv)", "[Course Schedule IV](/solution/1400-1499/1462.Course%20Schedule%20IV/README_EN.md)", "`Graph`", "Medium", ""]}, {"question_id": "1557", "frontend_question_id": "1461", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/check-if-a-string-contains-all-binary-codes-of-size-k", "url_en": "https://leetcode.com/problems/check-if-a-string-contains-all-binary-codes-of-size-k", "relative_path_cn": "/solution/1400-1499/1461.Check%20If%20a%20String%20Contains%20All%20Binary%20Codes%20of%20Size%20K/README.md", "relative_path_en": "/solution/1400-1499/1461.Check%20If%20a%20String%20Contains%20All%20Binary%20Codes%20of%20Size%20K/README_EN.md", "title_cn": "\u68c0\u67e5\u4e00\u4e2a\u5b57\u7b26\u4e32\u662f\u5426\u5305\u542b\u6240\u6709\u957f\u5ea6\u4e3a K \u7684\u4e8c\u8fdb\u5236\u5b50\u4e32", "title_en": "Check If a String Contains All Binary Codes of Size K", "question_title_slug": "check-if-a-string-contains-all-binary-codes-of-size-k", "content_en": "

Given a binary string s and an integer k.

\n\n

Return true if every binary code of length k is a substring of s. Otherwise, return false.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "00110110", k = 2\nOutput: true\nExplanation: The binary codes of length 2 are "00", "01", "10" and "11". They can be all found as substrings at indicies 0, 1, 3 and 2 respectively.\n
\n\n

Example 2:

\n\n
\nInput: s = "00110", k = 2\nOutput: true\n
\n\n

Example 3:

\n\n
\nInput: s = "0110", k = 1\nOutput: true\nExplanation: The binary codes of length 1 are "0" and "1", it is clear that both exist as a substring. \n
\n\n

Example 4:

\n\n
\nInput: s = "0110", k = 2\nOutput: false\nExplanation: The binary code "00" is of length 2 and doesn't exist in the array.\n
\n\n

Example 5:

\n\n
\nInput: s = "0000000001011100", k = 4\nOutput: false\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 5 * 105
  • \n\t
  • s[i] is either '0' or '1'.
  • \n\t
  • 1 <= k <= 20
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32\u00a0s\u00a0\u548c\u4e00\u4e2a\u6574\u6570\u00a0k\u00a0\u3002

\n\n

\u5982\u679c\u6240\u6709\u957f\u5ea6\u4e3a k\u00a0\u7684\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32\u90fd\u662f s\u00a0\u7684\u5b50\u4e32\uff0c\u8bf7\u8fd4\u56de true \uff0c\u5426\u5219\u8bf7\u8fd4\u56de false \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"00110110\", k = 2\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u957f\u5ea6\u4e3a 2 \u7684\u4e8c\u8fdb\u5236\u4e32\u5305\u62ec \"00\"\uff0c\"01\"\uff0c\"10\" \u548c \"11\"\u3002\u5b83\u4eec\u5206\u522b\u662f s \u4e2d\u4e0b\u6807\u4e3a 0\uff0c1\uff0c3\uff0c2 \u5f00\u59cb\u7684\u957f\u5ea6\u4e3a 2 \u7684\u5b50\u4e32\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"00110\", k = 2\n\u8f93\u51fa\uff1atrue\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"0110\", k = 1\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u957f\u5ea6\u4e3a 1 \u7684\u4e8c\u8fdb\u5236\u4e32\u5305\u62ec \"0\" \u548c \"1\"\uff0c\u663e\u7136\u5b83\u4eec\u90fd\u662f s \u7684\u5b50\u4e32\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"0110\", k = 2\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u957f\u5ea6\u4e3a 2 \u7684\u4e8c\u8fdb\u5236\u4e32 \"00\" \u6ca1\u6709\u51fa\u73b0\u5728 s \u4e2d\u3002\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"0000000001011100\", k = 4\n\u8f93\u51fa\uff1afalse\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length <= 5 * 105
  • \n\t
  • s[i] \u4e0d\u662f'0' \u5c31\u662f '1'
  • \n\t
  • 1 <= k <= 20
  • \n
\n", "tags_en": ["Bit Manipulation", "String"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean hasAllCodes(String s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def hasAllCodes(self, s, k):\n \"\"\"\n :type s: str\n :type k: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def hasAllCodes(self, s: str, k: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool hasAllCodes(char * s, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool HasAllCodes(string s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number} k\n * @return {boolean}\n */\nvar hasAllCodes = function(s, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer} k\n# @return {Boolean}\ndef has_all_codes(s, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func hasAllCodes(_ s: String, _ k: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func hasAllCodes(s string, k int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def hasAllCodes(s: String, k: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun hasAllCodes(s: String, k: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn has_all_codes(s: String, k: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer $k\n * @return Boolean\n */\n function hasAllCodes($s, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function hasAllCodes(s: string, k: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (has-all-codes s k)\n (-> string? exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1461](https://leetcode-cn.com/problems/check-if-a-string-contains-all-binary-codes-of-size-k)", "[\u68c0\u67e5\u4e00\u4e2a\u5b57\u7b26\u4e32\u662f\u5426\u5305\u542b\u6240\u6709\u957f\u5ea6\u4e3a K \u7684\u4e8c\u8fdb\u5236\u5b50\u4e32](/solution/1400-1499/1461.Check%20If%20a%20String%20Contains%20All%20Binary%20Codes%20of%20Size%20K/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1461](https://leetcode.com/problems/check-if-a-string-contains-all-binary-codes-of-size-k)", "[Check If a String Contains All Binary Codes of Size K](/solution/1400-1499/1461.Check%20If%20a%20String%20Contains%20All%20Binary%20Codes%20of%20Size%20K/README_EN.md)", "`Bit Manipulation`,`String`", "Medium", ""]}, {"question_id": "1556", "frontend_question_id": "1460", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/make-two-arrays-equal-by-reversing-sub-arrays", "url_en": "https://leetcode.com/problems/make-two-arrays-equal-by-reversing-sub-arrays", "relative_path_cn": "/solution/1400-1499/1460.Make%20Two%20Arrays%20Equal%20by%20Reversing%20Sub-arrays/README.md", "relative_path_en": "/solution/1400-1499/1460.Make%20Two%20Arrays%20Equal%20by%20Reversing%20Sub-arrays/README_EN.md", "title_cn": "\u901a\u8fc7\u7ffb\u8f6c\u5b50\u6570\u7ec4\u4f7f\u4e24\u4e2a\u6570\u7ec4\u76f8\u7b49", "title_en": "Make Two Arrays Equal by Reversing Sub-arrays", "question_title_slug": "make-two-arrays-equal-by-reversing-sub-arrays", "content_en": "

Given two integer arrays of equal length target and arr.

\n\n

In one step, you can select any non-empty sub-array of arr and reverse it. You are allowed to make any number of steps.

\n\n

Return True if you can make arr equal to target, or False otherwise.

\n\n

 

\n

Example 1:

\n\n
\nInput: target = [1,2,3,4], arr = [2,4,1,3]\nOutput: true\nExplanation: You can follow the next steps to convert arr to target:\n1- Reverse sub-array [2,4,1], arr becomes [1,4,2,3]\n2- Reverse sub-array [4,2], arr becomes [1,2,4,3]\n3- Reverse sub-array [4,3], arr becomes [1,2,3,4]\nThere are multiple ways to convert arr to target, this is not the only way to do so.\n
\n\n

Example 2:

\n\n
\nInput: target = [7], arr = [7]\nOutput: true\nExplanation: arr is equal to target without any reverses.\n
\n\n

Example 3:

\n\n
\nInput: target = [1,12], arr = [12,1]\nOutput: true\n
\n\n

Example 4:

\n\n
\nInput: target = [3,7,9], arr = [3,7,11]\nOutput: false\nExplanation: arr doesn't have value 9 and it can never be converted to target.\n
\n\n

Example 5:

\n\n
\nInput: target = [1,1,1,1,1], arr = [1,1,1,1,1]\nOutput: true\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • target.length == arr.length
  • \n\t
  • 1 <= target.length <= 1000
  • \n\t
  • 1 <= target[i] <= 1000
  • \n\t
  • 1 <= arr[i] <= 1000
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e24\u4e2a\u957f\u5ea6\u76f8\u540c\u7684\u6574\u6570\u6570\u7ec4 target \u548c arr \u3002

\n\n

\u6bcf\u4e00\u6b65\u4e2d\uff0c\u4f60\u53ef\u4ee5\u9009\u62e9 arr \u7684\u4efb\u610f \u975e\u7a7a\u5b50\u6570\u7ec4 \u5e76\u5c06\u5b83\u7ffb\u8f6c\u3002\u4f60\u53ef\u4ee5\u6267\u884c\u6b64\u8fc7\u7a0b\u4efb\u610f\u6b21\u3002

\n\n

\u5982\u679c\u4f60\u80fd\u8ba9 arr \u53d8\u5f97\u4e0e target \u76f8\u540c\uff0c\u8fd4\u56de True\uff1b\u5426\u5219\uff0c\u8fd4\u56de False \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1atarget = [1,2,3,4], arr = [2,4,1,3]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u6309\u7167\u5982\u4e0b\u6b65\u9aa4\u4f7f arr \u53d8\u6210 target\uff1a\n1- \u7ffb\u8f6c\u5b50\u6570\u7ec4 [2,4,1] \uff0carr \u53d8\u6210 [1,4,2,3]\n2- \u7ffb\u8f6c\u5b50\u6570\u7ec4 [4,2] \uff0carr \u53d8\u6210 [1,2,4,3]\n3- \u7ffb\u8f6c\u5b50\u6570\u7ec4 [4,3] \uff0carr \u53d8\u6210 [1,2,3,4]\n\u4e0a\u8ff0\u65b9\u6cd5\u5e76\u4e0d\u662f\u552f\u4e00\u7684\uff0c\u8fd8\u5b58\u5728\u591a\u79cd\u5c06 arr \u53d8\u6210 target \u7684\u65b9\u6cd5\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1atarget = [7], arr = [7]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1aarr \u4e0d\u9700\u8981\u505a\u4efb\u4f55\u7ffb\u8f6c\u5df2\u7ecf\u4e0e target \u76f8\u7b49\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1atarget = [1,12], arr = [12,1]\n\u8f93\u51fa\uff1atrue\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1atarget = [3,7,9], arr = [3,7,11]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1aarr \u6ca1\u6709\u6570\u5b57 9 \uff0c\u6240\u4ee5\u65e0\u8bba\u5982\u4f55\u4e5f\u65e0\u6cd5\u53d8\u6210 target \u3002\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1atarget = [1,1,1,1,1], arr = [1,1,1,1,1]\n\u8f93\u51fa\uff1atrue\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • target.length == arr.length
  • \n\t
  • 1 <= target.length <= 1000
  • \n\t
  • 1 <= target[i] <= 1000
  • \n\t
  • 1 <= arr[i] <= 1000
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canBeEqual(vector& target, vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canBeEqual(int[] target, int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canBeEqual(self, target, arr):\n \"\"\"\n :type target: List[int]\n :type arr: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canBeEqual(self, target: List[int], arr: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canBeEqual(int* target, int targetSize, int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanBeEqual(int[] target, int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} target\n * @param {number[]} arr\n * @return {boolean}\n */\nvar canBeEqual = function(target, arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} target\n# @param {Integer[]} arr\n# @return {Boolean}\ndef can_be_equal(target, arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canBeEqual(_ target: [Int], _ arr: [Int]) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canBeEqual(target []int, arr []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canBeEqual(target: Array[Int], arr: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canBeEqual(target: IntArray, arr: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_be_equal(target: Vec, arr: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $target\n * @param Integer[] $arr\n * @return Boolean\n */\n function canBeEqual($target, $arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canBeEqual(target: number[], arr: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-be-equal target arr)\n (-> (listof exact-integer?) (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1460](https://leetcode-cn.com/problems/make-two-arrays-equal-by-reversing-sub-arrays)", "[\u901a\u8fc7\u7ffb\u8f6c\u5b50\u6570\u7ec4\u4f7f\u4e24\u4e2a\u6570\u7ec4\u76f8\u7b49](/solution/1400-1499/1460.Make%20Two%20Arrays%20Equal%20by%20Reversing%20Sub-arrays/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1460](https://leetcode.com/problems/make-two-arrays-equal-by-reversing-sub-arrays)", "[Make Two Arrays Equal by Reversing Sub-arrays](/solution/1400-1499/1460.Make%20Two%20Arrays%20Equal%20by%20Reversing%20Sub-arrays/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1555", "frontend_question_id": "1444", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-ways-of-cutting-a-pizza", "url_en": "https://leetcode.com/problems/number-of-ways-of-cutting-a-pizza", "relative_path_cn": "/solution/1400-1499/1444.Number%20of%20Ways%20of%20Cutting%20a%20Pizza/README.md", "relative_path_en": "/solution/1400-1499/1444.Number%20of%20Ways%20of%20Cutting%20a%20Pizza/README_EN.md", "title_cn": "\u5207\u62ab\u8428\u7684\u65b9\u6848\u6570", "title_en": "Number of Ways of Cutting a Pizza", "question_title_slug": "number-of-ways-of-cutting-a-pizza", "content_en": "

Given a rectangular pizza represented as a rows x cols matrix containing the following characters: 'A' (an apple) and '.' (empty cell) and given the integer k. You have to cut the pizza into k pieces using k-1 cuts. 

\r\n\r\n

For each cut you choose the direction: vertical or horizontal, then you choose a cut position at the cell boundary and cut the pizza into two pieces. If you cut the pizza vertically, give the left part of the pizza to a person. If you cut the pizza horizontally, give the upper part of the pizza to a person. Give the last piece of pizza to the last person.

\r\n\r\n

Return the number of ways of cutting the pizza such that each piece contains at least one apple. Since the answer can be a huge number, return this modulo 10^9 + 7.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n

\"\"

\r\n\r\n
\r\nInput: pizza = ["A..","AAA","..."], k = 3\r\nOutput: 3 \r\nExplanation: The figure above shows the three ways to cut the pizza. Note that pieces must contain at least one apple.\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: pizza = ["A..","AA.","..."], k = 3\r\nOutput: 1\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: pizza = ["A..","A..","..."], k = 1\r\nOutput: 1\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= rows, cols <= 50
  • \r\n\t
  • rows == pizza.length
  • \r\n\t
  • cols == pizza[i].length
  • \r\n\t
  • 1 <= k <= 10
  • \r\n\t
  • pizza consists of characters 'A' and '.' only.
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a rows x cols \u5927\u5c0f\u7684\u77e9\u5f62\u62ab\u8428\u548c\u4e00\u4e2a\u6574\u6570 k \uff0c\u77e9\u5f62\u5305\u542b\u4e24\u79cd\u5b57\u7b26\uff1a 'A' \uff08\u8868\u793a\u82f9\u679c\uff09\u548c '.' \uff08\u8868\u793a\u7a7a\u767d\u683c\u5b50\uff09\u3002\u4f60\u9700\u8981\u5207\u62ab\u8428 k-1 \u6b21\uff0c\u5f97\u5230 k \u5757\u62ab\u8428\u5e76\u9001\u7ed9\u522b\u4eba\u3002

\n\n

\u5207\u62ab\u8428\u7684\u6bcf\u4e00\u5200\uff0c\u5148\u8981\u9009\u62e9\u662f\u5411\u5782\u76f4\u8fd8\u662f\u6c34\u5e73\u65b9\u5411\u5207\uff0c\u518d\u5728\u77e9\u5f62\u7684\u8fb9\u754c\u4e0a\u9009\u4e00\u4e2a\u5207\u7684\u4f4d\u7f6e\uff0c\u5c06\u62ab\u8428\u4e00\u5206\u4e3a\u4e8c\u3002\u5982\u679c\u5782\u76f4\u5730\u5207\u62ab\u8428\uff0c\u90a3\u4e48\u9700\u8981\u628a\u5de6\u8fb9\u7684\u90e8\u5206\u9001\u7ed9\u4e00\u4e2a\u4eba\uff0c\u5982\u679c\u6c34\u5e73\u5730\u5207\uff0c\u90a3\u4e48\u9700\u8981\u628a\u4e0a\u9762\u7684\u90e8\u5206\u9001\u7ed9\u4e00\u4e2a\u4eba\u3002\u5728\u5207\u5b8c\u6700\u540e\u4e00\u5200\u540e\uff0c\u9700\u8981\u628a\u5269\u4e0b\u6765\u7684\u4e00\u5757\u9001\u7ed9\u6700\u540e\u4e00\u4e2a\u4eba\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u786e\u4fdd\u6bcf\u4e00\u5757\u62ab\u8428\u5305\u542b \u81f3\u5c11 \u4e00\u4e2a\u82f9\u679c\u7684\u5207\u62ab\u8428\u65b9\u6848\u6570\u3002\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u662f\u4e2a\u5f88\u5927\u7684\u6570\u5b57\uff0c\u8bf7\u4f60\u8fd4\u56de\u5b83\u5bf9 10^9 + 7 \u53d6\u4f59\u7684\u7ed3\u679c\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1apizza = ["A..","AAA","..."], k = 3\n\u8f93\u51fa\uff1a3 \n\u89e3\u91ca\uff1a\u4e0a\u56fe\u5c55\u793a\u4e86\u4e09\u79cd\u5207\u62ab\u8428\u7684\u65b9\u6848\u3002\u6ce8\u610f\u6bcf\u4e00\u5757\u62ab\u8428\u90fd\u81f3\u5c11\u5305\u542b\u4e00\u4e2a\u82f9\u679c\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1apizza = ["A..","AA.","..."], k = 3\n\u8f93\u51fa\uff1a1\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1apizza = ["A..","A..","..."], k = 1\n\u8f93\u51fa\uff1a1\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= rows, cols <= 50
  • \n\t
  • rows == pizza.length
  • \n\t
  • cols == pizza[i].length
  • \n\t
  • 1 <= k <= 10
  • \n\t
  • pizza \u53ea\u5305\u542b\u5b57\u7b26 'A' \u548c '.' \u3002
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int ways(vector& pizza, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int ways(String[] pizza, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def ways(self, pizza, k):\n \"\"\"\n :type pizza: List[str]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def ways(self, pizza: List[str], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint ways(char ** pizza, int pizzaSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int Ways(string[] pizza, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} pizza\n * @param {number} k\n * @return {number}\n */\nvar ways = function(pizza, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} pizza\n# @param {Integer} k\n# @return {Integer}\ndef ways(pizza, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func ways(_ pizza: [String], _ k: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func ways(pizza []string, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def ways(pizza: Array[String], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun ways(pizza: Array, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn ways(pizza: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $pizza\n * @param Integer $k\n * @return Integer\n */\n function ways($pizza, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function ways(pizza: string[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (ways pizza k)\n (-> (listof string?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1444](https://leetcode-cn.com/problems/number-of-ways-of-cutting-a-pizza)", "[\u5207\u62ab\u8428\u7684\u65b9\u6848\u6570](/solution/1400-1499/1444.Number%20of%20Ways%20of%20Cutting%20a%20Pizza/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1444](https://leetcode.com/problems/number-of-ways-of-cutting-a-pizza)", "[Number of Ways of Cutting a Pizza](/solution/1400-1499/1444.Number%20of%20Ways%20of%20Cutting%20a%20Pizza/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1554", "frontend_question_id": "1443", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-time-to-collect-all-apples-in-a-tree", "url_en": "https://leetcode.com/problems/minimum-time-to-collect-all-apples-in-a-tree", "relative_path_cn": "/solution/1400-1499/1443.Minimum%20Time%20to%20Collect%20All%20Apples%20in%20a%20Tree/README.md", "relative_path_en": "/solution/1400-1499/1443.Minimum%20Time%20to%20Collect%20All%20Apples%20in%20a%20Tree/README_EN.md", "title_cn": "\u6536\u96c6\u6811\u4e0a\u6240\u6709\u82f9\u679c\u7684\u6700\u5c11\u65f6\u95f4", "title_en": "Minimum Time to Collect All Apples in a Tree", "question_title_slug": "minimum-time-to-collect-all-apples-in-a-tree", "content_en": "

Given an undirected tree consisting of n vertices numbered from 0 to n-1, which has some apples in their vertices. You spend 1 second to walk over one edge of the tree. Return the minimum time in seconds you have to spend to collect all apples in the tree, starting at vertex 0 and coming back to this vertex.

\n\n

The edges of the undirected tree are given in the array edges, where edges[i] = [ai, bi] means that exists an edge connecting the vertices ai and bi. Additionally, there is a boolean array hasApple, where hasApple[i] = true means that vertex i has an apple; otherwise, it does not have any apple.

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: n = 7, edges = [[0,1],[0,2],[1,4],[1,5],[2,3],[2,6]], hasApple = [false,false,true,false,true,true,false]\nOutput: 8 \nExplanation: The figure above represents the given tree where red vertices have an apple. One optimal path to collect all apples is shown by the green arrows.  \n
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: n = 7, edges = [[0,1],[0,2],[1,4],[1,5],[2,3],[2,6]], hasApple = [false,false,true,false,false,true,false]\nOutput: 6\nExplanation: The figure above represents the given tree where red vertices have an apple. One optimal path to collect all apples is shown by the green arrows.  \n
\n\n

Example 3:

\n\n
\nInput: n = 7, edges = [[0,1],[0,2],[1,4],[1,5],[2,3],[2,6]], hasApple = [false,false,false,false,false,false,false]\nOutput: 0\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 10^5
  • \n\t
  • edges.length == n - 1
  • \n\t
  • edges[i].length == 2
  • \n\t
  • 0 <= ai < bi <= n - 1
  • \n\t
  • fromi < toi
  • \n\t
  • hasApple.length == n
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u68f5\u6709 n \u4e2a\u8282\u70b9\u7684\u65e0\u5411\u6811\uff0c\u8282\u70b9\u7f16\u53f7\u4e3a 0 \u5230 n-1 \uff0c\u5b83\u4eec\u4e2d\u6709\u4e00\u4e9b\u8282\u70b9\u6709\u82f9\u679c\u3002\u901a\u8fc7\u6811\u4e0a\u7684\u4e00\u6761\u8fb9\uff0c\u9700\u8981\u82b1\u8d39 1 \u79d2\u949f\u3002\u4f60\u4ece \u8282\u70b9 0 \u51fa\u53d1\uff0c\u8bf7\u4f60\u8fd4\u56de\u6700\u5c11\u9700\u8981\u591a\u5c11\u79d2\uff0c\u53ef\u4ee5\u6536\u96c6\u5230\u6240\u6709\u82f9\u679c\uff0c\u5e76\u56de\u5230\u8282\u70b9 0 \u3002

\n\n

\u65e0\u5411\u6811\u7684\u8fb9\u7531 edges \u7ed9\u51fa\uff0c\u5176\u4e2d edges[i] = [fromi, toi] \uff0c\u8868\u793a\u6709\u4e00\u6761\u8fb9\u8fde\u63a5 from \u548c toi \u3002\u9664\u6b64\u4ee5\u5916\uff0c\u8fd8\u6709\u4e00\u4e2a\u5e03\u5c14\u6570\u7ec4 hasApple \uff0c\u5176\u4e2d hasApple[i] = true \u4ee3\u8868\u8282\u70b9 i \u6709\u4e00\u4e2a\u82f9\u679c\uff0c\u5426\u5219\uff0c\u8282\u70b9 i \u6ca1\u6709\u82f9\u679c\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1an = 7, edges = [[0,1],[0,2],[1,4],[1,5],[2,3],[2,6]], hasApple = [false,false,true,false,true,true,false]\n\u8f93\u51fa\uff1a8 \n\u89e3\u91ca\uff1a\u4e0a\u56fe\u5c55\u793a\u4e86\u7ed9\u5b9a\u7684\u6811\uff0c\u5176\u4e2d\u7ea2\u8272\u8282\u70b9\u8868\u793a\u6709\u82f9\u679c\u3002\u4e00\u4e2a\u80fd\u6536\u96c6\u5230\u6240\u6709\u82f9\u679c\u7684\u6700\u4f18\u65b9\u6848\u7531\u7eff\u8272\u7bad\u5934\u8868\u793a\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1an = 7, edges = [[0,1],[0,2],[1,4],[1,5],[2,3],[2,6]], hasApple = [false,false,true,false,false,true,false]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u4e0a\u56fe\u5c55\u793a\u4e86\u7ed9\u5b9a\u7684\u6811\uff0c\u5176\u4e2d\u7ea2\u8272\u8282\u70b9\u8868\u793a\u6709\u82f9\u679c\u3002\u4e00\u4e2a\u80fd\u6536\u96c6\u5230\u6240\u6709\u82f9\u679c\u7684\u6700\u4f18\u65b9\u6848\u7531\u7eff\u8272\u7bad\u5934\u8868\u793a\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1an = 7, edges = [[0,1],[0,2],[1,4],[1,5],[2,3],[2,6]], hasApple = [false,false,false,false,false,false,false]\n\u8f93\u51fa\uff1a0\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 10^5
  • \n\t
  • edges.length == n-1
  • \n\t
  • edges[i].length == 2
  • \n\t
  • 0 <= fromi, toi <= n-1
  • \n\t
  • fromi < toi
  • \n\t
  • hasApple.length == n
  • \n
\n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minTime(int n, vector>& edges, vector& hasApple) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minTime(int n, int[][] edges, List hasApple) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minTime(self, n, edges, hasApple):\n \"\"\"\n :type n: int\n :type edges: List[List[int]]\n :type hasApple: List[bool]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minTime(self, n: int, edges: List[List[int]], hasApple: List[bool]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minTime(int n, int** edges, int edgesSize, int* edgesColSize, bool* hasApple, int hasAppleSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinTime(int n, int[][] edges, IList hasApple) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} edges\n * @param {boolean[]} hasApple\n * @return {number}\n */\nvar minTime = function(n, edges, hasApple) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} edges\n# @param {Boolean[]} has_apple\n# @return {Integer}\ndef min_time(n, edges, has_apple)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minTime(_ n: Int, _ edges: [[Int]], _ hasApple: [Bool]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minTime(n int, edges [][]int, hasApple []bool) int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minTime(n: Int, edges: Array[Array[Int]], hasApple: List[Boolean]): Int = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minTime(n: Int, edges: Array, hasApple: List): Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_time(n: i32, edges: Vec>, has_apple: Vec) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $edges\n * @param Boolean[] $hasApple\n * @return Integer\n */\n function minTime($n, $edges, $hasApple) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minTime(n: number, edges: number[][], hasApple: boolean[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-time n edges hasApple)\n (-> exact-integer? (listof (listof exact-integer?)) (listof boolean?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1443](https://leetcode-cn.com/problems/minimum-time-to-collect-all-apples-in-a-tree)", "[\u6536\u96c6\u6811\u4e0a\u6240\u6709\u82f9\u679c\u7684\u6700\u5c11\u65f6\u95f4](/solution/1400-1499/1443.Minimum%20Time%20to%20Collect%20All%20Apples%20in%20a%20Tree/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1443](https://leetcode.com/problems/minimum-time-to-collect-all-apples-in-a-tree)", "[Minimum Time to Collect All Apples in a Tree](/solution/1400-1499/1443.Minimum%20Time%20to%20Collect%20All%20Apples%20in%20a%20Tree/README_EN.md)", "`Tree`,`Depth-first Search`", "Medium", ""]}, {"question_id": "1553", "frontend_question_id": "1442", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-triplets-that-can-form-two-arrays-of-equal-xor", "url_en": "https://leetcode.com/problems/count-triplets-that-can-form-two-arrays-of-equal-xor", "relative_path_cn": "/solution/1400-1499/1442.Count%20Triplets%20That%20Can%20Form%20Two%20Arrays%20of%20Equal%20XOR/README.md", "relative_path_en": "/solution/1400-1499/1442.Count%20Triplets%20That%20Can%20Form%20Two%20Arrays%20of%20Equal%20XOR/README_EN.md", "title_cn": "\u5f62\u6210\u4e24\u4e2a\u5f02\u6216\u76f8\u7b49\u6570\u7ec4\u7684\u4e09\u5143\u7ec4\u6570\u76ee", "title_en": "Count Triplets That Can Form Two Arrays of Equal XOR", "question_title_slug": "count-triplets-that-can-form-two-arrays-of-equal-xor", "content_en": "

Given an array of integers arr.

\r\n\r\n

We want to select three indices i, j and k where (0 <= i < j <= k < arr.length).

\r\n\r\n

Let's define a and b as follows:

\r\n\r\n
    \r\n\t
  • a = arr[i] ^ arr[i + 1] ^ ... ^ arr[j - 1]
  • \r\n\t
  • b = arr[j] ^ arr[j + 1] ^ ... ^ arr[k]
  • \r\n
\r\n\r\n

Note that ^ denotes the bitwise-xor operation.

\r\n\r\n

Return the number of triplets (i, j and k) Where a == b.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: arr = [2,3,1,6,7]\r\nOutput: 4\r\nExplanation: The triplets are (0,1,2), (0,2,2), (2,3,4) and (2,4,4)\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: arr = [1,1,1,1,1]\r\nOutput: 10\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: arr = [2,3]\r\nOutput: 0\r\n
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: arr = [1,3,5,7,9]\r\nOutput: 3\r\n
\r\n\r\n

Example 5:

\r\n\r\n
\r\nInput: arr = [7,11,12,9,5,2,7,17,22]\r\nOutput: 8\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= arr.length <= 300
  • \r\n\t
  • 1 <= arr[i] <= 10^8
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr \u3002

\n\n

\u73b0\u9700\u8981\u4ece\u6570\u7ec4\u4e2d\u53d6\u4e09\u4e2a\u4e0b\u6807 i\u3001j \u548c k \uff0c\u5176\u4e2d (0 <= i < j <= k < arr.length) \u3002

\n\n

a \u548c b \u5b9a\u4e49\u5982\u4e0b\uff1a

\n\n
    \n\t
  • a = arr[i] ^ arr[i + 1] ^ ... ^ arr[j - 1]
  • \n\t
  • b = arr[j] ^ arr[j + 1] ^ ... ^ arr[k]
  • \n
\n\n

\u6ce8\u610f\uff1a^ \u8868\u793a \u6309\u4f4d\u5f02\u6216 \u64cd\u4f5c\u3002

\n\n

\u8bf7\u8fd4\u56de\u80fd\u591f\u4ee4 a == b \u6210\u7acb\u7684\u4e09\u5143\u7ec4 (i, j , k) \u7684\u6570\u76ee\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aarr = [2,3,1,6,7]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u6ee1\u8db3\u9898\u610f\u7684\u4e09\u5143\u7ec4\u5206\u522b\u662f (0,1,2), (0,2,2), (2,3,4) \u4ee5\u53ca (2,4,4)\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aarr = [1,1,1,1,1]\n\u8f93\u51fa\uff1a10\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aarr = [2,3]\n\u8f93\u51fa\uff1a0\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1aarr = [1,3,5,7,9]\n\u8f93\u51fa\uff1a3\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1aarr = [7,11,12,9,5,2,7,17,22]\n\u8f93\u51fa\uff1a8\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= arr.length <= 300
  • \n\t
  • 1 <= arr[i] <= 10^8
  • \n
\n", "tags_en": ["Bit Manipulation", "Array", "Math"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u6570\u7ec4", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countTriplets(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countTriplets(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countTriplets(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countTriplets(self, arr: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countTriplets(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountTriplets(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar countTriplets = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef count_triplets(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countTriplets(_ arr: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countTriplets(arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countTriplets(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countTriplets(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_triplets(arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function countTriplets($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countTriplets(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-triplets arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1442](https://leetcode-cn.com/problems/count-triplets-that-can-form-two-arrays-of-equal-xor)", "[\u5f62\u6210\u4e24\u4e2a\u5f02\u6216\u76f8\u7b49\u6570\u7ec4\u7684\u4e09\u5143\u7ec4\u6570\u76ee](/solution/1400-1499/1442.Count%20Triplets%20That%20Can%20Form%20Two%20Arrays%20of%20Equal%20XOR/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u6570\u7ec4`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1442](https://leetcode.com/problems/count-triplets-that-can-form-two-arrays-of-equal-xor)", "[Count Triplets That Can Form Two Arrays of Equal XOR](/solution/1400-1499/1442.Count%20Triplets%20That%20Can%20Form%20Two%20Arrays%20of%20Equal%20XOR/README_EN.md)", "`Bit Manipulation`,`Array`,`Math`", "Medium", ""]}, {"question_id": "1552", "frontend_question_id": "1441", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/build-an-array-with-stack-operations", "url_en": "https://leetcode.com/problems/build-an-array-with-stack-operations", "relative_path_cn": "/solution/1400-1499/1441.Build%20an%20Array%20With%20Stack%20Operations/README.md", "relative_path_en": "/solution/1400-1499/1441.Build%20an%20Array%20With%20Stack%20Operations/README_EN.md", "title_cn": "\u7528\u6808\u64cd\u4f5c\u6784\u5efa\u6570\u7ec4", "title_en": "Build an Array With Stack Operations", "question_title_slug": "build-an-array-with-stack-operations", "content_en": "

Given an array target and an integer n. In each iteration, you will read a number from  list = {1,2,3..., n}.

\n\n

Build the target array using the following operations:

\n\n
    \n\t
  • Push: Read a new element from the beginning list, and push it in the array.
  • \n\t
  • Pop: delete the last element of the array.
  • \n\t
  • If the target array is already built, stop reading more elements.
  • \n
\n\n

Return the operations to build the target array. You are guaranteed that the answer is unique.

\n\n

 

\n

Example 1:

\n\n
\nInput: target = [1,3], n = 3\nOutput: ["Push","Push","Pop","Push"]\nExplanation: \nRead number 1 and automatically push in the array -> [1]\nRead number 2 and automatically push in the array then Pop it -> [1]\nRead number 3 and automatically push in the array -> [1,3]\n
\n\n

Example 2:

\n\n
\nInput: target = [1,2,3], n = 3\nOutput: ["Push","Push","Push"]\n
\n\n

Example 3:

\n\n
\nInput: target = [1,2], n = 4\nOutput: ["Push","Push"]\nExplanation: You only need to read the first 2 numbers and stop.\n
\n\n

Example 4:

\n\n
\nInput: target = [2,3,4], n = 4\nOutput: ["Push","Pop","Push","Push","Push"]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= target.length <= 100
  • \n\t
  • 1 <= target[i] <= n
  • \n\t
  • 1 <= n <= 100
  • \n\t
  • target is strictly increasing.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u76ee\u6807\u6570\u7ec4 target \u548c\u4e00\u4e2a\u6574\u6570 n\u3002\u6bcf\u6b21\u8fed\u4ee3\uff0c\u9700\u8981\u4ece\u00a0 list = {1,2,3..., n} \u4e2d\u4f9d\u5e8f\u8bfb\u53d6\u4e00\u4e2a\u6570\u5b57\u3002

\n\n

\u8bf7\u4f7f\u7528\u4e0b\u8ff0\u64cd\u4f5c\u6765\u6784\u5efa\u76ee\u6807\u6570\u7ec4 target \uff1a

\n\n
    \n\t
  • Push\uff1a\u4ece list \u4e2d\u8bfb\u53d6\u4e00\u4e2a\u65b0\u5143\u7d20\uff0c \u5e76\u5c06\u5176\u63a8\u5165\u6570\u7ec4\u4e2d\u3002
  • \n\t
  • Pop\uff1a\u5220\u9664\u6570\u7ec4\u4e2d\u7684\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u3002
  • \n\t
  • \u5982\u679c\u76ee\u6807\u6570\u7ec4\u6784\u5efa\u5b8c\u6210\uff0c\u5c31\u505c\u6b62\u8bfb\u53d6\u66f4\u591a\u5143\u7d20\u3002
  • \n
\n\n

\u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u76ee\u6807\u6570\u7ec4\u4e25\u683c\u9012\u589e\uff0c\u5e76\u4e14\u53ea\u5305\u542b 1 \u5230 n \u4e4b\u95f4\u7684\u6570\u5b57\u3002

\n\n

\u8bf7\u8fd4\u56de\u6784\u5efa\u76ee\u6807\u6570\u7ec4\u6240\u7528\u7684\u64cd\u4f5c\u5e8f\u5217\u3002

\n\n

\u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u7b54\u6848\u662f\u552f\u4e00\u7684\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1atarget = [1,3], n = 3\n\u8f93\u51fa\uff1a[\"Push\",\"Push\",\"Pop\",\"Push\"]\n\u89e3\u91ca\uff1a \n\u8bfb\u53d6 1 \u5e76\u81ea\u52a8\u63a8\u5165\u6570\u7ec4 -> [1]\n\u8bfb\u53d6 2 \u5e76\u81ea\u52a8\u63a8\u5165\u6570\u7ec4\uff0c\u7136\u540e\u5220\u9664\u5b83 -> [1]\n\u8bfb\u53d6 3 \u5e76\u81ea\u52a8\u63a8\u5165\u6570\u7ec4 -> [1,3]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1atarget = [1,2,3], n = 3\n\u8f93\u51fa\uff1a[\"Push\",\"Push\",\"Push\"]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1atarget = [1,2], n = 4\n\u8f93\u51fa\uff1a[\"Push\",\"Push\"]\n\u89e3\u91ca\uff1a\u53ea\u9700\u8981\u8bfb\u53d6\u524d 2 \u4e2a\u6570\u5b57\u5c31\u53ef\u4ee5\u505c\u6b62\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1atarget = [2,3,4], n = 4\n\u8f93\u51fa\uff1a[\"Push\",\"Pop\",\"Push\",\"Push\",\"Push\"]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= target.length <= 100
  • \n\t
  • 1 <= target[i]\u00a0<= 100
  • \n\t
  • 1 <= n <= 100
  • \n\t
  • target \u662f\u4e25\u683c\u9012\u589e\u7684
  • \n
\n", "tags_en": ["Stack"], "tags_cn": ["\u6808"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector buildArray(vector& target, int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List buildArray(int[] target, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def buildArray(self, target, n):\n \"\"\"\n :type target: List[int]\n :type n: int\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def buildArray(self, target: List[int], n: int) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** buildArray(int* target, int targetSize, int n, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList BuildArray(int[] target, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} target\n * @param {number} n\n * @return {string[]}\n */\nvar buildArray = function(target, n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} target\n# @param {Integer} n\n# @return {String[]}\ndef build_array(target, n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func buildArray(_ target: [Int], _ n: Int) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func buildArray(target []int, n int) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def buildArray(target: Array[Int], n: Int): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun buildArray(target: IntArray, n: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn build_array(target: Vec, n: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $target\n * @param Integer $n\n * @return String[]\n */\n function buildArray($target, $n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function buildArray(target: number[], n: number): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (build-array target n)\n (-> (listof exact-integer?) exact-integer? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1441](https://leetcode-cn.com/problems/build-an-array-with-stack-operations)", "[\u7528\u6808\u64cd\u4f5c\u6784\u5efa\u6570\u7ec4](/solution/1400-1499/1441.Build%20an%20Array%20With%20Stack%20Operations/README.md)", "`\u6808`", "\u7b80\u5355", ""], "md_table_row_en": ["[1441](https://leetcode.com/problems/build-an-array-with-stack-operations)", "[Build an Array With Stack Operations](/solution/1400-1499/1441.Build%20an%20Array%20With%20Stack%20Operations/README_EN.md)", "`Stack`", "Easy", ""]}, {"question_id": "1551", "frontend_question_id": "1421", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/npv-queries", "url_en": "https://leetcode.com/problems/npv-queries", "relative_path_cn": "/solution/1400-1499/1421.NPV%20Queries/README.md", "relative_path_en": "/solution/1400-1499/1421.NPV%20Queries/README_EN.md", "title_cn": "\u51c0\u73b0\u503c\u67e5\u8be2", "title_en": "NPV Queries", "question_title_slug": "npv-queries", "content_en": "

Table: NPV

\r\n\r\n
\r\n+---------------+---------+\r\n| Column Name   | Type    |\r\n+---------------+---------+\r\n| id            | int     |\r\n| year          | int     |\r\n| npv           | int     |\r\n+---------------+---------+\r\n(id, year) is the primary key of this table.\r\nThe table has information about the id and the year of each inventory and the corresponding net present value.\r\n
\r\n\r\n

 

\r\n\r\n

Table: Queries

\r\n\r\n
\r\n+---------------+---------+\r\n| Column Name   | Type    |\r\n+---------------+---------+\r\n| id            | int     |\r\n| year          | int     |\r\n+---------------+---------+\r\n(id, year) is the primary key of this table.\r\nThe table has information about the id and the year of each inventory query.\r\n
\r\n\r\n

 

\r\n\r\n

Write an SQL query to find the npv of all each query of queries table.

\r\n\r\n

Return the result table in any order.

\r\n\r\n

The query result format is in the following example:

\r\n\r\n
\r\nNPV table:\r\n+------+--------+--------+\r\n| id   | year   | npv    |\r\n+------+--------+--------+\r\n| 1    | 2018   | 100    |\r\n| 7    | 2020   | 30     |\r\n| 13   | 2019   | 40     |\r\n| 1    | 2019   | 113    |\r\n| 2    | 2008   | 121    |\r\n| 3    | 2009   | 12     |\r\n| 11   | 2020   | 99     |\r\n| 7    | 2019   | 0      |\r\n+------+--------+--------+\r\n\r\nQueries table:\r\n+------+--------+\r\n| id   | year   |\r\n+------+--------+\r\n| 1    | 2019   |\r\n| 2    | 2008   |\r\n| 3    | 2009   |\r\n| 7    | 2018   |\r\n| 7    | 2019   |\r\n| 7    | 2020   |\r\n| 13   | 2019   |\r\n+------+--------+\r\n\r\nResult table:\r\n+------+--------+--------+\r\n| id   | year   | npv    |\r\n+------+--------+--------+\r\n| 1    | 2019   | 113    |\r\n| 2    | 2008   | 121    |\r\n| 3    | 2009   | 12     |\r\n| 7    | 2018   | 0      |\r\n| 7    | 2019   | 0      |\r\n| 7    | 2020   | 30     |\r\n| 13   | 2019   | 40     |\r\n+------+--------+--------+\r\n\r\nThe npv value of (7, 2018) is not present in the NPV table, we consider it 0.\r\nThe npv values of all other queries can be found in the NPV table.\r\n
", "content_cn": "

\u8868: NPV

\n\n
+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| year          | int     |\n| npv           | int     |\n+---------------+---------+\n(id, year) \u662f\u8be5\u8868\u4e3b\u952e.\n\u8be5\u8868\u6709\u6bcf\u4e00\u7b14\u5b58\u8d27\u7684\u5e74\u4efd, id \u548c\u5bf9\u5e94\u51c0\u73b0\u503c\u7684\u4fe1\u606f.\n
\n\n

 

\n\n

\u8868: Queries

\n\n
+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| year          | int     |\n+---------------+---------+\n(id, year) \u662f\u8be5\u8868\u4e3b\u952e.\n\u8be5\u8868\u6709\u6bcf\u4e00\u6b21\u67e5\u8be2\u6240\u5bf9\u5e94\u5b58\u8d27\u7684 id \u548c\u5e74\u4efd\u7684\u4fe1\u606f.\n
\n\n

 

\n\n

\u5199\u4e00\u4e2a SQL, \u627e\u5230 Queries \u8868\u4e2d\u6bcf\u4e00\u6b21\u67e5\u8be2\u7684\u51c0\u73b0\u503c.

\n\n

\u7ed3\u679c\u8868\u6ca1\u6709\u987a\u5e8f\u8981\u6c42.

\n\n

\u67e5\u8be2\u7ed3\u679c\u7684\u683c\u5f0f\u5982\u4e0b\u6240\u793a:

\n\n
NPV \u8868:\n+------+--------+--------+\n| id   | year   | npv    |\n+------+--------+--------+\n| 1    | 2018   | 100    |\n| 7    | 2020   | 30     |\n| 13   | 2019   | 40     |\n| 1    | 2019   | 113    |\n| 2    | 2008   | 121    |\n| 3    | 2009   | 12     |\n| 11   | 2020   | 99     |\n| 7    | 2019   | 0      |\n+------+--------+--------+\n\nQueries \u8868:\n+------+--------+\n| id   | year   |\n+------+--------+\n| 1    | 2019   |\n| 2    | 2008   |\n| 3    | 2009   |\n| 7    | 2018   |\n| 7    | 2019   |\n| 7    | 2020   |\n| 13   | 2019   |\n+------+--------+\n\n\u7ed3\u679c\u8868:\n+------+--------+--------+\n| id   | year   | npv    |\n+------+--------+--------+\n| 1    | 2019   | 113    |\n| 2    | 2008   | 121    |\n| 3    | 2009   | 12     |\n| 7    | 2018   | 0      |\n| 7    | 2019   | 0      |\n| 7    | 2020   | 30     |\n| 13   | 2019   | 40     |\n+------+--------+--------+\n\n(7, 2018)\u7684\u51c0\u73b0\u503c\u4e0d\u5728 NPV \u8868\u4e2d, \u6211\u4eec\u628a\u5b83\u770b\u4f5c\u662f 0.\n\u6240\u6709\u5176\u5b83\u67e5\u8be2\u7684\u51c0\u73b0\u503c\u90fd\u80fd\u5728 NPV \u8868\u4e2d\u627e\u5230.\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1421](https://leetcode-cn.com/problems/npv-queries)", "[\u51c0\u73b0\u503c\u67e5\u8be2](/solution/1400-1499/1421.NPV%20Queries/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1421](https://leetcode.com/problems/npv-queries)", "[NPV Queries](/solution/1400-1499/1421.NPV%20Queries/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1550", "frontend_question_id": "1439", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-the-kth-smallest-sum-of-a-matrix-with-sorted-rows", "url_en": "https://leetcode.com/problems/find-the-kth-smallest-sum-of-a-matrix-with-sorted-rows", "relative_path_cn": "/solution/1400-1499/1439.Find%20the%20Kth%20Smallest%20Sum%20of%20a%20Matrix%20With%20Sorted%20Rows/README.md", "relative_path_en": "/solution/1400-1499/1439.Find%20the%20Kth%20Smallest%20Sum%20of%20a%20Matrix%20With%20Sorted%20Rows/README_EN.md", "title_cn": "\u6709\u5e8f\u77e9\u9635\u4e2d\u7684\u7b2c k \u4e2a\u6700\u5c0f\u6570\u7ec4\u548c", "title_en": "Find the Kth Smallest Sum of a Matrix With Sorted Rows", "question_title_slug": "find-the-kth-smallest-sum-of-a-matrix-with-sorted-rows", "content_en": "

You are given an m * n matrix, mat, and an integer k, which has its rows sorted in non-decreasing order.

\n\n

You are allowed to choose exactly 1 element from each row to form an array. Return the Kth smallest array sum among all possible arrays.

\n\n

 

\n

Example 1:

\n\n
\nInput: mat = [[1,3,11],[2,4,6]], k = 5\nOutput: 7\nExplanation: Choosing one element from each row, the first k smallest sum are:\n[1,2], [1,4], [3,2], [3,4], [1,6]. Where the 5th sum is 7.  
\n\n

Example 2:

\n\n
\nInput: mat = [[1,3,11],[2,4,6]], k = 9\nOutput: 17\n
\n\n

Example 3:

\n\n
\nInput: mat = [[1,10,10],[1,4,5],[2,3,6]], k = 7\nOutput: 9\nExplanation: Choosing one element from each row, the first k smallest sum are:\n[1,1,2], [1,1,3], [1,4,2], [1,4,3], [1,1,6], [1,5,2], [1,5,3]. Where the 7th sum is 9.  \n
\n\n

Example 4:

\n\n
\nInput: mat = [[1,1,10],[2,2,9]], k = 7\nOutput: 12\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • m == mat.length
  • \n\t
  • n == mat.length[i]
  • \n\t
  • 1 <= m, n <= 40
  • \n\t
  • 1 <= k <= min(200, n ^ m)
  • \n\t
  • 1 <= mat[i][j] <= 5000
  • \n\t
  • mat[i] is a non decreasing array.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a m * n \u7684\u77e9\u9635 mat\uff0c\u4ee5\u53ca\u4e00\u4e2a\u6574\u6570 k \uff0c\u77e9\u9635\u4e2d\u7684\u6bcf\u4e00\u884c\u90fd\u4ee5\u975e\u9012\u51cf\u7684\u987a\u5e8f\u6392\u5217\u3002

\n\n

\u4f60\u53ef\u4ee5\u4ece\u6bcf\u4e00\u884c\u4e2d\u9009\u51fa 1 \u4e2a\u5143\u7d20\u5f62\u6210\u4e00\u4e2a\u6570\u7ec4\u3002\u8fd4\u56de\u6240\u6709\u53ef\u80fd\u6570\u7ec4\u4e2d\u7684\u7b2c k \u4e2a \u6700\u5c0f \u6570\u7ec4\u548c\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1amat = [[1,3,11],[2,4,6]], k = 5\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\u4ece\u6bcf\u4e00\u884c\u4e2d\u9009\u51fa\u4e00\u4e2a\u5143\u7d20\uff0c\u524d k \u4e2a\u548c\u6700\u5c0f\u7684\u6570\u7ec4\u5206\u522b\u662f\uff1a\n[1,2], [1,4], [3,2], [3,4], [1,6]\u3002\u5176\u4e2d\u7b2c 5 \u4e2a\u7684\u548c\u662f 7 \u3002  
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1amat = [[1,3,11],[2,4,6]], k = 9\n\u8f93\u51fa\uff1a17\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1amat = [[1,10,10],[1,4,5],[2,3,6]], k = 7\n\u8f93\u51fa\uff1a9\n\u89e3\u91ca\uff1a\u4ece\u6bcf\u4e00\u884c\u4e2d\u9009\u51fa\u4e00\u4e2a\u5143\u7d20\uff0c\u524d k \u4e2a\u548c\u6700\u5c0f\u7684\u6570\u7ec4\u5206\u522b\u662f\uff1a\n[1,1,2], [1,1,3], [1,4,2], [1,4,3], [1,1,6], [1,5,2], [1,5,3]\u3002\u5176\u4e2d\u7b2c 7 \u4e2a\u7684\u548c\u662f 9 \u3002 \n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1amat = [[1,1,10],[2,2,9]], k = 7\n\u8f93\u51fa\uff1a12\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • m == mat.length
  • \n\t
  • n == mat.length[i]
  • \n\t
  • 1 <= m, n <= 40
  • \n\t
  • 1 <= k <= min(200, n ^ m)
  • \n\t
  • 1 <= mat[i][j] <= 5000
  • \n\t
  • mat[i] \u662f\u4e00\u4e2a\u975e\u9012\u51cf\u6570\u7ec4
  • \n
\n", "tags_en": ["Heap"], "tags_cn": ["\u5806"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int kthSmallest(vector>& mat, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int kthSmallest(int[][] mat, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def kthSmallest(self, mat, k):\n \"\"\"\n :type mat: List[List[int]]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def kthSmallest(self, mat: List[List[int]], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint kthSmallest(int** mat, int matSize, int* matColSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int KthSmallest(int[][] mat, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} mat\n * @param {number} k\n * @return {number}\n */\nvar kthSmallest = function(mat, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} mat\n# @param {Integer} k\n# @return {Integer}\ndef kth_smallest(mat, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func kthSmallest(_ mat: [[Int]], _ k: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func kthSmallest(mat [][]int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def kthSmallest(mat: Array[Array[Int]], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun kthSmallest(mat: Array, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn kth_smallest(mat: Vec>, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $mat\n * @param Integer $k\n * @return Integer\n */\n function kthSmallest($mat, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function kthSmallest(mat: number[][], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (kth-smallest mat k)\n (-> (listof (listof exact-integer?)) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1439](https://leetcode-cn.com/problems/find-the-kth-smallest-sum-of-a-matrix-with-sorted-rows)", "[\u6709\u5e8f\u77e9\u9635\u4e2d\u7684\u7b2c k \u4e2a\u6700\u5c0f\u6570\u7ec4\u548c](/solution/1400-1499/1439.Find%20the%20Kth%20Smallest%20Sum%20of%20a%20Matrix%20With%20Sorted%20Rows/README.md)", "`\u5806`", "\u56f0\u96be", ""], "md_table_row_en": ["[1439](https://leetcode.com/problems/find-the-kth-smallest-sum-of-a-matrix-with-sorted-rows)", "[Find the Kth Smallest Sum of a Matrix With Sorted Rows](/solution/1400-1499/1439.Find%20the%20Kth%20Smallest%20Sum%20of%20a%20Matrix%20With%20Sorted%20Rows/README_EN.md)", "`Heap`", "Hard", ""]}, {"question_id": "1549", "frontend_question_id": "1438", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit", "url_en": "https://leetcode.com/problems/longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit", "relative_path_cn": "/solution/1400-1499/1438.Longest%20Continuous%20Subarray%20With%20Absolute%20Diff%20Less%20Than%20or%20Equal%20to%20Limit/README.md", "relative_path_en": "/solution/1400-1499/1438.Longest%20Continuous%20Subarray%20With%20Absolute%20Diff%20Less%20Than%20or%20Equal%20to%20Limit/README_EN.md", "title_cn": "\u7edd\u5bf9\u5dee\u4e0d\u8d85\u8fc7\u9650\u5236\u7684\u6700\u957f\u8fde\u7eed\u5b50\u6570\u7ec4", "title_en": "Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit", "question_title_slug": "longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit", "content_en": "

Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [8,2,4,7], limit = 4\nOutput: 2 \nExplanation: All subarrays are: \n[8] with maximum absolute diff |8-8| = 0 <= 4.\n[8,2] with maximum absolute diff |8-2| = 6 > 4. \n[8,2,4] with maximum absolute diff |8-2| = 6 > 4.\n[8,2,4,7] with maximum absolute diff |8-2| = 6 > 4.\n[2] with maximum absolute diff |2-2| = 0 <= 4.\n[2,4] with maximum absolute diff |2-4| = 2 <= 4.\n[2,4,7] with maximum absolute diff |2-7| = 5 > 4.\n[4] with maximum absolute diff |4-4| = 0 <= 4.\n[4,7] with maximum absolute diff |4-7| = 3 <= 4.\n[7] with maximum absolute diff |7-7| = 0 <= 4. \nTherefore, the size of the longest subarray is 2.\n
\n\n

Example 2:

\n\n
\nInput: nums = [10,1,2,4,7,2], limit = 5\nOutput: 4 \nExplanation: The subarray [2,4,7,2] is the longest since the maximum absolute diff is |2-7| = 5 <= 5.\n
\n\n

Example 3:

\n\n
\nInput: nums = [4,2,2,2,4,4,2,2], limit = 0\nOutput: 3\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 105
  • \n\t
  • 1 <= nums[i] <= 109
  • \n\t
  • 0 <= limit <= 109
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \uff0c\u548c\u4e00\u4e2a\u8868\u793a\u9650\u5236\u7684\u6574\u6570 limit\uff0c\u8bf7\u4f60\u8fd4\u56de\u6700\u957f\u8fde\u7eed\u5b50\u6570\u7ec4\u7684\u957f\u5ea6\uff0c\u8be5\u5b50\u6570\u7ec4\u4e2d\u7684\u4efb\u610f\u4e24\u4e2a\u5143\u7d20\u4e4b\u95f4\u7684\u7edd\u5bf9\u5dee\u5fc5\u987b\u5c0f\u4e8e\u6216\u8005\u7b49\u4e8e limit \u3002

\n\n

\u5982\u679c\u4e0d\u5b58\u5728\u6ee1\u8db3\u6761\u4ef6\u7684\u5b50\u6570\u7ec4\uff0c\u5219\u8fd4\u56de 0 \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anums = [8,2,4,7], limit = 4\n\u8f93\u51fa\uff1a2 \n\u89e3\u91ca\uff1a\u6240\u6709\u5b50\u6570\u7ec4\u5982\u4e0b\uff1a\n[8] \u6700\u5927\u7edd\u5bf9\u5dee |8-8| = 0 <= 4.\n[8,2] \u6700\u5927\u7edd\u5bf9\u5dee |8-2| = 6 > 4. \n[8,2,4] \u6700\u5927\u7edd\u5bf9\u5dee |8-2| = 6 > 4.\n[8,2,4,7] \u6700\u5927\u7edd\u5bf9\u5dee |8-2| = 6 > 4.\n[2] \u6700\u5927\u7edd\u5bf9\u5dee |2-2| = 0 <= 4.\n[2,4] \u6700\u5927\u7edd\u5bf9\u5dee |2-4| = 2 <= 4.\n[2,4,7] \u6700\u5927\u7edd\u5bf9\u5dee |2-7| = 5 > 4.\n[4] \u6700\u5927\u7edd\u5bf9\u5dee |4-4| = 0 <= 4.\n[4,7] \u6700\u5927\u7edd\u5bf9\u5dee |4-7| = 3 <= 4.\n[7] \u6700\u5927\u7edd\u5bf9\u5dee |7-7| = 0 <= 4. \n\u56e0\u6b64\uff0c\u6ee1\u8db3\u9898\u610f\u7684\u6700\u957f\u5b50\u6570\u7ec4\u7684\u957f\u5ea6\u4e3a 2 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anums = [10,1,2,4,7,2], limit = 5\n\u8f93\u51fa\uff1a4 \n\u89e3\u91ca\uff1a\u6ee1\u8db3\u9898\u610f\u7684\u6700\u957f\u5b50\u6570\u7ec4\u662f [2,4,7,2]\uff0c\u5176\u6700\u5927\u7edd\u5bf9\u5dee |2-7| = 5 <= 5 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1anums = [4,2,2,2,4,4,2,2], limit = 0\n\u8f93\u51fa\uff1a3\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 10^5
  • \n\t
  • 1 <= nums[i] <= 10^9
  • \n\t
  • 0 <= limit <= 10^9
  • \n
\n", "tags_en": ["Array", "Sliding Window"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int longestSubarray(vector& nums, int limit) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int longestSubarray(int[] nums, int limit) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestSubarray(self, nums, limit):\n \"\"\"\n :type nums: List[int]\n :type limit: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestSubarray(self, nums: List[int], limit: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint longestSubarray(int* nums, int numsSize, int limit){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LongestSubarray(int[] nums, int limit) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} limit\n * @return {number}\n */\nvar longestSubarray = function(nums, limit) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} limit\n# @return {Integer}\ndef longest_subarray(nums, limit)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestSubarray(_ nums: [Int], _ limit: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestSubarray(nums []int, limit int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestSubarray(nums: Array[Int], limit: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestSubarray(nums: IntArray, limit: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_subarray(nums: Vec, limit: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $limit\n * @return Integer\n */\n function longestSubarray($nums, $limit) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestSubarray(nums: number[], limit: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-subarray nums limit)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1438](https://leetcode-cn.com/problems/longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit)", "[\u7edd\u5bf9\u5dee\u4e0d\u8d85\u8fc7\u9650\u5236\u7684\u6700\u957f\u8fde\u7eed\u5b50\u6570\u7ec4](/solution/1400-1499/1438.Longest%20Continuous%20Subarray%20With%20Absolute%20Diff%20Less%20Than%20or%20Equal%20to%20Limit/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1438](https://leetcode.com/problems/longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit)", "[Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit](/solution/1400-1499/1438.Longest%20Continuous%20Subarray%20With%20Absolute%20Diff%20Less%20Than%20or%20Equal%20to%20Limit/README_EN.md)", "`Array`,`Sliding Window`", "Medium", ""]}, {"question_id": "1548", "frontend_question_id": "1437", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/check-if-all-1s-are-at-least-length-k-places-away", "url_en": "https://leetcode.com/problems/check-if-all-1s-are-at-least-length-k-places-away", "relative_path_cn": "/solution/1400-1499/1437.Check%20If%20All%201%27s%20Are%20at%20Least%20Length%20K%20Places%20Away/README.md", "relative_path_en": "/solution/1400-1499/1437.Check%20If%20All%201%27s%20Are%20at%20Least%20Length%20K%20Places%20Away/README_EN.md", "title_cn": "\u662f\u5426\u6240\u6709 1 \u90fd\u81f3\u5c11\u76f8\u9694 k \u4e2a\u5143\u7d20", "title_en": "Check If All 1's Are at Least Length K Places Away", "question_title_slug": "check-if-all-1s-are-at-least-length-k-places-away", "content_en": "

Given an array nums of 0s and 1s and an integer k, return True if all 1's are at least k places away from each other, otherwise return False.

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: nums = [1,0,0,0,1,0,0,1], k = 2\nOutput: true\nExplanation: Each of the 1s are at least 2 places away from each other.\n
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: nums = [1,0,0,1,0,1], k = 2\nOutput: false\nExplanation: The second 1 and third 1 are only one apart from each other.
\n\n

Example 3:

\n\n
\nInput: nums = [1,1,1,1,1], k = 0\nOutput: true\n
\n\n

Example 4:

\n\n
\nInput: nums = [0,1,0,1], k = 1\nOutput: true\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 105
  • \n\t
  • 0 <= k <= nums.length
  • \n\t
  • nums[i] is 0 or 1
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u7531\u82e5\u5e72 0 \u548c 1 \u7ec4\u6210\u7684\u6570\u7ec4 nums \u4ee5\u53ca\u6574\u6570 k\u3002\u5982\u679c\u6240\u6709 1 \u90fd\u81f3\u5c11\u76f8\u9694 k \u4e2a\u5143\u7d20\uff0c\u5219\u8fd4\u56de True \uff1b\u5426\u5219\uff0c\u8fd4\u56de False \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1anums = [1,0,0,0,1,0,0,1], k = 2\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u6bcf\u4e2a 1 \u90fd\u81f3\u5c11\u76f8\u9694 2 \u4e2a\u5143\u7d20\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1anums = [1,0,0,1,0,1], k = 2\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u7b2c\u4e8c\u4e2a 1 \u548c\u7b2c\u4e09\u4e2a 1 \u4e4b\u95f4\u53ea\u9694\u4e86 1 \u4e2a\u5143\u7d20\u3002
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,1,1,1,1], k = 0\n\u8f93\u51fa\uff1atrue\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1anums = [0,1,0,1], k = 1\n\u8f93\u51fa\uff1atrue\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 10^5
  • \n\t
  • 0 <= k <= nums.length
  • \n\t
  • nums[i] \u7684\u503c\u4e3a 0 \u6216 1
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool kLengthApart(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean kLengthApart(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def kLengthApart(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def kLengthApart(self, nums: List[int], k: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool kLengthApart(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool KLengthApart(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {boolean}\n */\nvar kLengthApart = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Boolean}\ndef k_length_apart(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func kLengthApart(_ nums: [Int], _ k: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func kLengthApart(nums []int, k int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def kLengthApart(nums: Array[Int], k: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun kLengthApart(nums: IntArray, k: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn k_length_apart(nums: Vec, k: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Boolean\n */\n function kLengthApart($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function kLengthApart(nums: number[], k: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (k-length-apart nums k)\n (-> (listof exact-integer?) exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1437](https://leetcode-cn.com/problems/check-if-all-1s-are-at-least-length-k-places-away)", "[\u662f\u5426\u6240\u6709 1 \u90fd\u81f3\u5c11\u76f8\u9694 k \u4e2a\u5143\u7d20](/solution/1400-1499/1437.Check%20If%20All%201%27s%20Are%20at%20Least%20Length%20K%20Places%20Away/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1437](https://leetcode.com/problems/check-if-all-1s-are-at-least-length-k-places-away)", "[Check If All 1's Are at Least Length K Places Away](/solution/1400-1499/1437.Check%20If%20All%201%27s%20Are%20at%20Least%20Length%20K%20Places%20Away/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1547", "frontend_question_id": "1436", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/destination-city", "url_en": "https://leetcode.com/problems/destination-city", "relative_path_cn": "/solution/1400-1499/1436.Destination%20City/README.md", "relative_path_en": "/solution/1400-1499/1436.Destination%20City/README_EN.md", "title_cn": "\u65c5\u884c\u7ec8\u70b9\u7ad9", "title_en": "Destination City", "question_title_slug": "destination-city", "content_en": "

You are given the array paths, where paths[i] = [cityAi, cityBi] means there exists a direct path going from cityAi to cityBi. Return the destination city, that is, the city without any path outgoing to another city.

\n\n

It is guaranteed that the graph of paths forms a line without any loop, therefore, there will be exactly one destination city.

\n\n

 

\n

Example 1:

\n\n
\nInput: paths = [["London","New York"],["New York","Lima"],["Lima","Sao Paulo"]]\nOutput: "Sao Paulo" \nExplanation: Starting at "London" city you will reach "Sao Paulo" city which is the destination city. Your trip consist of: "London" -> "New York" -> "Lima" -> "Sao Paulo".\n
\n\n

Example 2:

\n\n
\nInput: paths = [["B","C"],["D","B"],["C","A"]]\nOutput: "A"\nExplanation: All possible trips are: \n"D" -> "B" -> "C" -> "A". \n"B" -> "C" -> "A". \n"C" -> "A". \n"A". \nClearly the destination city is "A".\n
\n\n

Example 3:

\n\n
\nInput: paths = [["A","Z"]]\nOutput: "Z"\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= paths.length <= 100
  • \n\t
  • paths[i].length == 2
  • \n\t
  • 1 <= cityAi.length, cityBi.length <= 10
  • \n\t
  • cityAi != cityBi
  • \n\t
  • All strings consist of lowercase and uppercase English letters and the space character.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4efd\u65c5\u6e38\u7ebf\u8def\u56fe\uff0c\u8be5\u7ebf\u8def\u56fe\u4e2d\u7684\u65c5\u884c\u7ebf\u8def\u7528\u6570\u7ec4 paths \u8868\u793a\uff0c\u5176\u4e2d paths[i] = [cityAi, cityBi] \u8868\u793a\u8be5\u7ebf\u8def\u5c06\u4f1a\u4ece cityAi \u76f4\u63a5\u524d\u5f80 cityBi \u3002\u8bf7\u4f60\u627e\u51fa\u8fd9\u6b21\u65c5\u884c\u7684\u7ec8\u70b9\u7ad9\uff0c\u5373\u6ca1\u6709\u4efb\u4f55\u53ef\u4ee5\u901a\u5f80\u5176\u4ed6\u57ce\u5e02\u7684\u7ebf\u8def\u7684\u57ce\u5e02\u3002

\n\n

\u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u7ebf\u8def\u56fe\u4f1a\u5f62\u6210\u4e00\u6761\u4e0d\u5b58\u5728\u5faa\u73af\u7684\u7ebf\u8def\uff0c\u56e0\u6b64\u53ea\u4f1a\u6709\u4e00\u4e2a\u65c5\u884c\u7ec8\u70b9\u7ad9\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1apaths = [["London","New York"],["New York","Lima"],["Lima","Sao Paulo"]]\n\u8f93\u51fa\uff1a"Sao Paulo" \n\u89e3\u91ca\uff1a\u4ece "London" \u51fa\u53d1\uff0c\u6700\u540e\u62b5\u8fbe\u7ec8\u70b9\u7ad9 "Sao Paulo" \u3002\u672c\u6b21\u65c5\u884c\u7684\u8def\u7ebf\u662f "London" -> "New York" -> "Lima" -> "Sao Paulo" \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1apaths = [["B","C"],["D","B"],["C","A"]]\n\u8f93\u51fa\uff1a"A"\n\u89e3\u91ca\uff1a\u6240\u6709\u53ef\u80fd\u7684\u7ebf\u8def\u662f\uff1a\n"D" -> "B" -> "C" -> "A". \n"B" -> "C" -> "A". \n"C" -> "A". \n"A". \n\u663e\u7136\uff0c\u65c5\u884c\u7ec8\u70b9\u7ad9\u662f "A" \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1apaths = [["A","Z"]]\n\u8f93\u51fa\uff1a"Z"\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= paths.length <= 100
  • \n\t
  • paths[i].length == 2
  • \n\t
  • 1 <= cityAi.length, cityBi.length <= 10
  • \n\t
  • cityA!= cityBi
  • \n\t
  • \u6240\u6709\u5b57\u7b26\u4e32\u5747\u7531\u5927\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u548c\u7a7a\u683c\u5b57\u7b26\u7ec4\u6210\u3002
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string destCity(vector>& paths) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String destCity(List> paths) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def destCity(self, paths):\n \"\"\"\n :type paths: List[List[str]]\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def destCity(self, paths: List[List[str]]) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * destCity(char *** paths, int pathsSize, int* pathsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string DestCity(IList> paths) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[][]} paths\n * @return {string}\n */\nvar destCity = function(paths) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[][]} paths\n# @return {String}\ndef dest_city(paths)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func destCity(_ paths: [[String]]) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func destCity(paths [][]string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def destCity(paths: List[List[String]]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun destCity(paths: List>): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn dest_city(paths: Vec>) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $paths\n * @return String\n */\n function destCity($paths) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function destCity(paths: string[][]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (dest-city paths)\n (-> (listof (listof string?)) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1436](https://leetcode-cn.com/problems/destination-city)", "[\u65c5\u884c\u7ec8\u70b9\u7ad9](/solution/1400-1499/1436.Destination%20City/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1436](https://leetcode.com/problems/destination-city)", "[Destination City](/solution/1400-1499/1436.Destination%20City/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1546", "frontend_question_id": "1412", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/find-the-quiet-students-in-all-exams", "url_en": "https://leetcode.com/problems/find-the-quiet-students-in-all-exams", "relative_path_cn": "/solution/1400-1499/1412.Find%20the%20Quiet%20Students%20in%20All%20Exams/README.md", "relative_path_en": "/solution/1400-1499/1412.Find%20the%20Quiet%20Students%20in%20All%20Exams/README_EN.md", "title_cn": "\u67e5\u627e\u6210\u7ee9\u5904\u4e8e\u4e2d\u6e38\u7684\u5b66\u751f", "title_en": "Find the Quiet Students in All Exams", "question_title_slug": "find-the-quiet-students-in-all-exams", "content_en": "

Table: Student

\n\n
\n+---------------------+---------+\n| Column Name         | Type    |\n+---------------------+---------+\n| student_id          | int     |\n| student_name        | varchar |\n+---------------------+---------+\nstudent_id is the primary key for this table.\nstudent_name is the name of the student.
\n\n

 

\n\n

Table: Exam

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| exam_id       | int     |\n| student_id    | int     |\n| score         | int     |\n+---------------+---------+\n(exam_id, student_id) is the primary key for this table.\nStudent with student_id got score points in exam with id exam_id.\n
\n\n

 

\n\n

A "quite" student is the one who took at least one exam and didn't score neither the high score nor the low score.

\n\n

Write an SQL query to report the students (student_id, student_name) being "quiet" in ALL exams.

\n\n

Don't return the student who has never taken any exam. Return the result table ordered by student_id.

\n\n

The query result format is in the following example.

\n\n

 

\n\n
\nStudent table:\n+-------------+---------------+\n| student_id  | student_name  |\n+-------------+---------------+\n| 1           | Daniel        |\n| 2           | Jade          |\n| 3           | Stella        |\n| 4           | Jonathan      |\n| 5           | Will          |\n+-------------+---------------+\n\nExam table:\n+------------+--------------+-----------+\n| exam_id    | student_id   | score     |\n+------------+--------------+-----------+\n| 10         |     1        |    70     |\n| 10         |     2        |    80     |\n| 10         |     3        |    90     |\n| 20         |     1        |    80     |\n| 30         |     1        |    70     |\n| 30         |     3        |    80     |\n| 30         |     4        |    90     |\n| 40         |     1        |    60     |\n| 40         |     2        |    70     |\n| 40         |     4        |    80     |\n+------------+--------------+-----------+\n\nResult table:\n+-------------+---------------+\n| student_id  | student_name  |\n+-------------+---------------+\n| 2           | Jade          |\n+-------------+---------------+\n\nFor exam 1: Student 1 and 3 hold the lowest and high score respectively.\nFor exam 2: Student 1 hold both highest and lowest score.\nFor exam 3 and 4: Studnet 1 and 4 hold the lowest and high score respectively.\nStudent 2 and 5 have never got the highest or lowest in any of the exam.\nSince student 5 is not taking any exam, he is excluded from the result.\nSo, we only return the information of Student 2.
\n", "content_cn": "

\u8868: Student

\n\n
\n+---------------------+---------+\n| Column Name         | Type    |\n+---------------------+---------+\n| student_id          | int     |\n| student_name        | varchar |\n+---------------------+---------+\nstudent_id \u662f\u8be5\u8868\u4e3b\u952e.\nstudent_name \u5b66\u751f\u540d\u5b57.
\n\n

\u00a0

\n\n

\u8868: Exam

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| exam_id       | int     |\n| student_id    | int     |\n| score         | int     |\n+---------------+---------+\n(exam_id, student_id) \u662f\u8be5\u8868\u4e3b\u952e.\n\u5b66\u751f student_id \u5728\u6d4b\u9a8c exam_id \u4e2d\u5f97\u5206\u4e3a score.\n
\n\n

\u00a0

\n\n

\u6210\u7ee9\u5904\u4e8e\u4e2d\u6e38\u7684\u5b66\u751f\u662f\u6307\u81f3\u5c11\u53c2\u52a0\u4e86\u4e00\u6b21\u6d4b\u9a8c,\u00a0\u4e14\u5f97\u5206\u65e2\u4e0d\u662f\u6700\u9ad8\u5206\u4e5f\u4e0d\u662f\u6700\u4f4e\u5206\u7684\u5b66\u751f\u3002

\n\n

\u5199\u4e00\u4e2a SQL \u8bed\u53e5\uff0c\u627e\u51fa\u5728 \u6240\u6709 \u6d4b\u9a8c\u4e2d\u90fd\u5904\u4e8e\u4e2d\u6e38\u7684\u5b66\u751f (student_id, student_name)\u3002

\n\n

\u4e0d\u8981\u8fd4\u56de\u4ece\u6765\u6ca1\u6709\u53c2\u52a0\u8fc7\u6d4b\u9a8c\u7684\u5b66\u751f\u3002\u8fd4\u56de\u7ed3\u679c\u8868\u6309\u7167\u00a0student_id\u00a0\u6392\u5e8f\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u3002

\n\n

\u00a0

\n\n
\nStudent \u8868\uff1a\n+-------------+---------------+\n| student_id  | student_name  |\n+-------------+---------------+\n| 1           | Daniel        |\n| 2           | Jade          |\n| 3           | Stella        |\n| 4           | Jonathan      |\n| 5           | Will          |\n+-------------+---------------+\n\nExam \u8868\uff1a\n+------------+--------------+-----------+\n| exam_id    | student_id   | score     |\n+------------+--------------+-----------+\n| 10         |     1        |    70     |\n| 10         |     2        |    80     |\n| 10         |     3        |    90     |\n| 20         |     1        |    80     |\n| 30         |     1        |    70     |\n| 30         |     3        |    80     |\n| 30         |     4        |    90     |\n| 40         |     1        |    60     |\n| 40         |     2        |    70     |\n| 40         |     4        |    80     |\n+------------+--------------+-----------+\n\nResult \u8868\uff1a\n+-------------+---------------+\n| student_id  | student_name  |\n+-------------+---------------+\n| 2           | Jade          |\n+-------------+---------------+\n\n\u5bf9\u4e8e\u6d4b\u9a8c 1: \u5b66\u751f 1 \u548c 3 \u5206\u522b\u83b7\u5f97\u4e86\u6700\u4f4e\u5206\u548c\u6700\u9ad8\u5206\u3002\n\u5bf9\u4e8e\u6d4b\u9a8c 2: \u5b66\u751f 1 \u65e2\u83b7\u5f97\u4e86\u6700\u9ad8\u5206, \u4e5f\u83b7\u5f97\u4e86\u6700\u4f4e\u5206\u3002\n\u5bf9\u4e8e\u6d4b\u9a8c 3 \u548c 4: \u5b66\u751f 1 \u548c 4 \u5206\u522b\u83b7\u5f97\u4e86\u6700\u4f4e\u5206\u548c\u6700\u9ad8\u5206\u3002\n\u5b66\u751f 2 \u548c 5 \u6ca1\u6709\u5728\u4efb\u4e00\u573a\u6d4b\u9a8c\u4e2d\u83b7\u5f97\u4e86\u6700\u9ad8\u5206\u6216\u8005\u6700\u4f4e\u5206\u3002\n\u56e0\u4e3a\u5b66\u751f 5 \u4ece\u6765\u6ca1\u6709\u53c2\u52a0\u8fc7\u4efb\u4f55\u6d4b\u9a8c, \u6240\u4ee5\u4ed6\u88ab\u6392\u9664\u4e8e\u7ed3\u679c\u8868\u3002\n\u7531\u6b64, \u6211\u4eec\u4ec5\u4ec5\u8fd4\u56de\u5b66\u751f 2 \u7684\u4fe1\u606f\u3002
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1412](https://leetcode-cn.com/problems/find-the-quiet-students-in-all-exams)", "[\u67e5\u627e\u6210\u7ee9\u5904\u4e8e\u4e2d\u6e38\u7684\u5b66\u751f](/solution/1400-1499/1412.Find%20the%20Quiet%20Students%20in%20All%20Exams/README.md)", "", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1412](https://leetcode.com/problems/find-the-quiet-students-in-all-exams)", "[Find the Quiet Students in All Exams](/solution/1400-1499/1412.Find%20the%20Quiet%20Students%20in%20All%20Exams/README_EN.md)", "", "Hard", "\ud83d\udd12"]}, {"question_id": "1545", "frontend_question_id": "1449", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/form-largest-integer-with-digits-that-add-up-to-target", "url_en": "https://leetcode.com/problems/form-largest-integer-with-digits-that-add-up-to-target", "relative_path_cn": "/solution/1400-1499/1449.Form%20Largest%20Integer%20With%20Digits%20That%20Add%20up%20to%20Target/README.md", "relative_path_en": "/solution/1400-1499/1449.Form%20Largest%20Integer%20With%20Digits%20That%20Add%20up%20to%20Target/README_EN.md", "title_cn": "\u6570\u4f4d\u6210\u672c\u548c\u4e3a\u76ee\u6807\u503c\u7684\u6700\u5927\u6570\u5b57", "title_en": "Form Largest Integer With Digits That Add up to Target", "question_title_slug": "form-largest-integer-with-digits-that-add-up-to-target", "content_en": "

Given an array of integers cost and an integer target. Return the maximum integer you can paint under the following rules:

\n\n
    \n\t
  • The cost of painting a digit (i+1) is given by cost[i] (0 indexed).
  • \n\t
  • The total cost used must be equal to target.
  • \n\t
  • Integer does not have digits 0.
  • \n
\n\n

Since the answer may be too large, return it as string.

\n\n

If there is no way to paint any integer given the condition, return "0".

\n\n

 

\n

Example 1:

\n\n
\nInput: cost = [4,3,2,5,6,7,2,5,5], target = 9\nOutput: "7772"\nExplanation:  The cost to paint the digit '7' is 2, and the digit '2' is 3. Then cost("7772") = 2*3+ 3*1 = 9. You could also paint "977", but "7772" is the largest number.\nDigit    cost\n  1  ->   4\n  2  ->   3\n  3  ->   2\n  4  ->   5\n  5  ->   6\n  6  ->   7\n  7  ->   2\n  8  ->   5\n  9  ->   5\n
\n\n

Example 2:

\n\n
\nInput: cost = [7,6,5,5,5,6,8,7,8], target = 12\nOutput: "85"\nExplanation: The cost to paint the digit '8' is 7, and the digit '5' is 5. Then cost("85") = 7 + 5 = 12.\n
\n\n

Example 3:

\n\n
\nInput: cost = [2,4,6,2,4,6,4,4,4], target = 5\nOutput: "0"\nExplanation: It's not possible to paint any integer with total cost equal to target.\n
\n\n

Example 4:

\n\n
\nInput: cost = [6,10,15,40,40,40,40,40,40], target = 47\nOutput: "32211"\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • cost.length == 9
  • \n\t
  • 1 <= cost[i] <= 5000
  • \n\t
  • 1 <= target <= 5000
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0cost\u00a0\u548c\u4e00\u4e2a\u6574\u6570\u00a0target\u00a0\u3002\u8bf7\u4f60\u8fd4\u56de\u6ee1\u8db3\u5982\u4e0b\u89c4\u5219\u53ef\u4ee5\u5f97\u5230\u7684\u00a0\u6700\u5927\u00a0\u6574\u6570\uff1a

\n\n
    \n\t
  • \u7ed9\u5f53\u524d\u7ed3\u679c\u6dfb\u52a0\u4e00\u4e2a\u6570\u4f4d\uff08i + 1\uff09\u7684\u6210\u672c\u4e3a\u00a0cost[i]\u00a0\uff08cost\u00a0\u6570\u7ec4\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\u3002
  • \n\t
  • \u603b\u6210\u672c\u5fc5\u987b\u6070\u597d\u7b49\u4e8e\u00a0target\u00a0\u3002
  • \n\t
  • \u6dfb\u52a0\u7684\u6570\u4f4d\u4e2d\u6ca1\u6709\u6570\u5b57 0 \u3002
  • \n
\n\n

\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u4f1a\u5f88\u5927\uff0c\u8bf7\u4f60\u4ee5\u5b57\u7b26\u4e32\u5f62\u5f0f\u8fd4\u56de\u3002

\n\n

\u5982\u679c\u6309\u7167\u4e0a\u8ff0\u8981\u6c42\u65e0\u6cd5\u5f97\u5230\u4efb\u4f55\u6574\u6570\uff0c\u8bf7\u4f60\u8fd4\u56de \"0\" \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1acost = [4,3,2,5,6,7,2,5,5], target = 9\n\u8f93\u51fa\uff1a\"7772\"\n\u89e3\u91ca\uff1a\u6dfb\u52a0\u6570\u4f4d '7' \u7684\u6210\u672c\u4e3a 2 \uff0c\u6dfb\u52a0\u6570\u4f4d '2' \u7684\u6210\u672c\u4e3a 3 \u3002\u6240\u4ee5 \"7772\" \u7684\u4ee3\u4ef7\u4e3a 2*3+ 3*1 = 9 \u3002 \"977\" \u4e5f\u662f\u6ee1\u8db3\u8981\u6c42\u7684\u6570\u5b57\uff0c\u4f46 \"7772\" \u662f\u8f83\u5927\u7684\u6570\u5b57\u3002\n \u6570\u5b57     \u6210\u672c\n  1  ->   4\n  2  ->   3\n  3  ->   2\n  4  ->   5\n  5  ->   6\n  6  ->   7\n  7  ->   2\n  8  ->   5\n  9  ->   5\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1acost = [7,6,5,5,5,6,8,7,8], target = 12\n\u8f93\u51fa\uff1a\"85\"\n\u89e3\u91ca\uff1a\u6dfb\u52a0\u6570\u4f4d '8' \u7684\u6210\u672c\u662f 7 \uff0c\u6dfb\u52a0\u6570\u4f4d '5' \u7684\u6210\u672c\u662f 5 \u3002\"85\" \u7684\u6210\u672c\u4e3a 7 + 5 = 12 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1acost = [2,4,6,2,4,6,4,4,4], target = 5\n\u8f93\u51fa\uff1a\"0\"\n\u89e3\u91ca\uff1a\u603b\u6210\u672c\u662f target \u7684\u6761\u4ef6\u4e0b\uff0c\u65e0\u6cd5\u751f\u6210\u4efb\u4f55\u6574\u6570\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1acost = [6,10,15,40,40,40,40,40,40], target = 47\n\u8f93\u51fa\uff1a\"32211\"\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • cost.length == 9
  • \n\t
  • 1 <= cost[i] <= 5000
  • \n\t
  • 1 <= target <= 5000
  • \n
\n", "tags_en": ["String", "Dynamic Programming"], "tags_cn": ["\u5b57\u7b26\u4e32", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string largestNumber(vector& cost, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String largestNumber(int[] cost, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def largestNumber(self, cost, target):\n \"\"\"\n :type cost: List[int]\n :type target: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def largestNumber(self, cost: List[int], target: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * largestNumber(int* cost, int costSize, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string LargestNumber(int[] cost, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} cost\n * @param {number} target\n * @return {string}\n */\nvar largestNumber = function(cost, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} cost\n# @param {Integer} target\n# @return {String}\ndef largest_number(cost, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func largestNumber(_ cost: [Int], _ target: Int) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func largestNumber(cost []int, target int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def largestNumber(cost: Array[Int], target: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun largestNumber(cost: IntArray, target: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn largest_number(cost: Vec, target: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $cost\n * @param Integer $target\n * @return String\n */\n function largestNumber($cost, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function largestNumber(cost: number[], target: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (largest-number cost target)\n (-> (listof exact-integer?) exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1449](https://leetcode-cn.com/problems/form-largest-integer-with-digits-that-add-up-to-target)", "[\u6570\u4f4d\u6210\u672c\u548c\u4e3a\u76ee\u6807\u503c\u7684\u6700\u5927\u6570\u5b57](/solution/1400-1499/1449.Form%20Largest%20Integer%20With%20Digits%20That%20Add%20up%20to%20Target/README.md)", "`\u5b57\u7b26\u4e32`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1449](https://leetcode.com/problems/form-largest-integer-with-digits-that-add-up-to-target)", "[Form Largest Integer With Digits That Add up to Target](/solution/1400-1499/1449.Form%20Largest%20Integer%20With%20Digits%20That%20Add%20up%20to%20Target/README_EN.md)", "`String`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "1544", "frontend_question_id": "1448", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-good-nodes-in-binary-tree", "url_en": "https://leetcode.com/problems/count-good-nodes-in-binary-tree", "relative_path_cn": "/solution/1400-1499/1448.Count%20Good%20Nodes%20in%20Binary%20Tree/README.md", "relative_path_en": "/solution/1400-1499/1448.Count%20Good%20Nodes%20in%20Binary%20Tree/README_EN.md", "title_cn": "\u7edf\u8ba1\u4e8c\u53c9\u6811\u4e2d\u597d\u8282\u70b9\u7684\u6570\u76ee", "title_en": "Count Good Nodes in Binary Tree", "question_title_slug": "count-good-nodes-in-binary-tree", "content_en": "

Given a binary tree root, a node X in the tree is named good if in the path from root to X there are no nodes with a value greater than X.

\r\n\r\n

Return the number of good nodes in the binary tree.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n

\"\"

\r\n\r\n
\r\nInput: root = [3,1,4,3,null,1,5]\r\nOutput: 4\r\nExplanation: Nodes in blue are good.\r\nRoot Node (3) is always a good node.\r\nNode 4 -> (3,4) is the maximum value in the path starting from the root.\r\nNode 5 -> (3,4,5) is the maximum value in the path\r\nNode 3 -> (3,1,3) is the maximum value in the path.
\r\n\r\n

Example 2:

\r\n\r\n

\"\"

\r\n\r\n
\r\nInput: root = [3,3,null,4,2]\r\nOutput: 3\r\nExplanation: Node 2 -> (3, 3, 2) is not good, because "3" is higher than it.
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: root = [1]\r\nOutput: 1\r\nExplanation: Root is considered as good.
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • The number of nodes in the binary tree is in the range [1, 10^5].
  • \r\n\t
  • Each node's value is between [-10^4, 10^4].
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u68f5\u6839\u4e3a root \u7684\u4e8c\u53c9\u6811\uff0c\u8bf7\u4f60\u8fd4\u56de\u4e8c\u53c9\u6811\u4e2d\u597d\u8282\u70b9\u7684\u6570\u76ee\u3002

\n\n

\u300c\u597d\u8282\u70b9\u300dX \u5b9a\u4e49\u4e3a\uff1a\u4ece\u6839\u5230\u8be5\u8282\u70b9 X \u6240\u7ecf\u8fc7\u7684\u8282\u70b9\u4e2d\uff0c\u6ca1\u6709\u4efb\u4f55\u8282\u70b9\u7684\u503c\u5927\u4e8e X \u7684\u503c\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1aroot = [3,1,4,3,null,1,5]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u56fe\u4e2d\u84dd\u8272\u8282\u70b9\u4e3a\u597d\u8282\u70b9\u3002\n\u6839\u8282\u70b9 (3) \u6c38\u8fdc\u662f\u4e2a\u597d\u8282\u70b9\u3002\n\u8282\u70b9 4 -> (3,4) \u662f\u8def\u5f84\u4e2d\u7684\u6700\u5927\u503c\u3002\n\u8282\u70b9 5 -> (3,4,5) \u662f\u8def\u5f84\u4e2d\u7684\u6700\u5927\u503c\u3002\n\u8282\u70b9 3 -> (3,1,3) \u662f\u8def\u5f84\u4e2d\u7684\u6700\u5927\u503c\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1aroot = [3,3,null,4,2]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u8282\u70b9 2 -> (3, 3, 2) \u4e0d\u662f\u597d\u8282\u70b9\uff0c\u56e0\u4e3a "3" \u6bd4\u5b83\u5927\u3002
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aroot = [1]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u6839\u8282\u70b9\u662f\u597d\u8282\u70b9\u3002
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u4e8c\u53c9\u6811\u4e2d\u8282\u70b9\u6570\u76ee\u8303\u56f4\u662f [1, 10^5] \u3002
  • \n\t
  • \u6bcf\u4e2a\u8282\u70b9\u6743\u503c\u7684\u8303\u56f4\u662f [-10^4, 10^4] \u3002
  • \n
\n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int goodNodes(TreeNode* root) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int goodNodes(TreeNode root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def goodNodes(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def goodNodes(self, root: TreeNode) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint goodNodes(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int GoodNodes(TreeNode root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar goodNodes = function(root) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef good_nodes(root)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func goodNodes(_ root: TreeNode?) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc goodNodes(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def goodNodes(root: TreeNode): Int = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun goodNodes(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn good_nodes(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function goodNodes($root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction goodNodes(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (good-nodes root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1448](https://leetcode-cn.com/problems/count-good-nodes-in-binary-tree)", "[\u7edf\u8ba1\u4e8c\u53c9\u6811\u4e2d\u597d\u8282\u70b9\u7684\u6570\u76ee](/solution/1400-1499/1448.Count%20Good%20Nodes%20in%20Binary%20Tree/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1448](https://leetcode.com/problems/count-good-nodes-in-binary-tree)", "[Count Good Nodes in Binary Tree](/solution/1400-1499/1448.Count%20Good%20Nodes%20in%20Binary%20Tree/README_EN.md)", "`Tree`,`Depth-first Search`", "Medium", ""]}, {"question_id": "1543", "frontend_question_id": "1447", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/simplified-fractions", "url_en": "https://leetcode.com/problems/simplified-fractions", "relative_path_cn": "/solution/1400-1499/1447.Simplified%20Fractions/README.md", "relative_path_en": "/solution/1400-1499/1447.Simplified%20Fractions/README_EN.md", "title_cn": "\u6700\u7b80\u5206\u6570", "title_en": "Simplified Fractions", "question_title_slug": "simplified-fractions", "content_en": "

Given an integer n, return a list of all simplified fractions between 0 and 1 (exclusive) such that the denominator is less-than-or-equal-to n. The fractions can be in any order.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: n = 2\r\nOutput: ["1/2"]\r\nExplanation: "1/2" is the only unique fraction with a denominator less-than-or-equal-to 2.
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: n = 3\r\nOutput: ["1/2","1/3","2/3"]\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: n = 4\r\nOutput: ["1/2","1/3","1/4","2/3","3/4"]\r\nExplanation: "2/4" is not a simplified fraction because it can be simplified to "1/2".
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: n = 1\r\nOutput: []\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= n <= 100
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n \uff0c\u8bf7\u4f60\u8fd4\u56de\u6240\u6709 0 \u5230 1 \u4e4b\u95f4\uff08\u4e0d\u5305\u62ec 0 \u548c 1\uff09\u6ee1\u8db3\u5206\u6bcd\u5c0f\u4e8e\u7b49\u4e8e  n \u7684 \u6700\u7b80 \u5206\u6570 \u3002\u5206\u6570\u53ef\u4ee5\u4ee5 \u4efb\u610f \u987a\u5e8f\u8fd4\u56de\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1an = 2\n\u8f93\u51fa\uff1a["1/2"]\n\u89e3\u91ca\uff1a"1/2" \u662f\u552f\u4e00\u4e00\u4e2a\u5206\u6bcd\u5c0f\u4e8e\u7b49\u4e8e 2 \u7684\u6700\u7b80\u5206\u6570\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1an = 3\n\u8f93\u51fa\uff1a["1/2","1/3","2/3"]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1an = 4\n\u8f93\u51fa\uff1a["1/2","1/3","1/4","2/3","3/4"]\n\u89e3\u91ca\uff1a"2/4" \u4e0d\u662f\u6700\u7b80\u5206\u6570\uff0c\u56e0\u4e3a\u5b83\u53ef\u4ee5\u5316\u7b80\u4e3a "1/2" \u3002
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1a[]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 100
  • \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector simplifiedFractions(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List simplifiedFractions(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def simplifiedFractions(self, n):\n \"\"\"\n :type n: int\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def simplifiedFractions(self, n: int) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** simplifiedFractions(int n, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList SimplifiedFractions(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {string[]}\n */\nvar simplifiedFractions = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {String[]}\ndef simplified_fractions(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func simplifiedFractions(_ n: Int) -> [String] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func simplifiedFractions(n int) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def simplifiedFractions(n: Int): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun simplifiedFractions(n: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn simplified_fractions(n: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return String[]\n */\n function simplifiedFractions($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function simplifiedFractions(n: number): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (simplified-fractions n)\n (-> exact-integer? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1447](https://leetcode-cn.com/problems/simplified-fractions)", "[\u6700\u7b80\u5206\u6570](/solution/1400-1499/1447.Simplified%20Fractions/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1447](https://leetcode.com/problems/simplified-fractions)", "[Simplified Fractions](/solution/1400-1499/1447.Simplified%20Fractions/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "1542", "frontend_question_id": "1446", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/consecutive-characters", "url_en": "https://leetcode.com/problems/consecutive-characters", "relative_path_cn": "/solution/1400-1499/1446.Consecutive%20Characters/README.md", "relative_path_en": "/solution/1400-1499/1446.Consecutive%20Characters/README_EN.md", "title_cn": "\u8fde\u7eed\u5b57\u7b26", "title_en": "Consecutive Characters", "question_title_slug": "consecutive-characters", "content_en": "

Given a string s, the power of the string is the maximum length of a non-empty substring that contains only one unique character.

\r\n\r\n

Return the power of the string.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: s = "leetcode"\r\nOutput: 2\r\nExplanation: The substring "ee" is of length 2 with the character 'e' only.\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: s = "abbcccddddeeeeedcba"\r\nOutput: 5\r\nExplanation: The substring "eeeee" is of length 5 with the character 'e' only.\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: s = "triplepillooooow"\r\nOutput: 5\r\n
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: s = "hooraaaaaaaaaaay"\r\nOutput: 11\r\n
\r\n\r\n

Example 5:

\r\n\r\n
\r\nInput: s = "tourist"\r\nOutput: 1\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= s.length <= 500
  • \r\n\t
  • s contains only lowercase English letters.
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \uff0c\u5b57\u7b26\u4e32\u7684\u300c\u80fd\u91cf\u300d\u5b9a\u4e49\u4e3a\uff1a\u53ea\u5305\u542b\u4e00\u79cd\u5b57\u7b26\u7684\u6700\u957f\u975e\u7a7a\u5b50\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u5b57\u7b26\u4e32\u7684\u80fd\u91cf\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1as = "leetcode"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5b50\u5b57\u7b26\u4e32 "ee" \u957f\u5ea6\u4e3a 2 \uff0c\u53ea\u5305\u542b\u5b57\u7b26 'e' \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1as = "abbcccddddeeeeedcba"\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u5b50\u5b57\u7b26\u4e32 "eeeee" \u957f\u5ea6\u4e3a 5 \uff0c\u53ea\u5305\u542b\u5b57\u7b26 'e' \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1as = "triplepillooooow"\n\u8f93\u51fa\uff1a5\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1as = "hooraaaaaaaaaaay"\n\u8f93\u51fa\uff1a11\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1as = "tourist"\n\u8f93\u51fa\uff1a1\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length <= 500
  • \n\t
  • s \u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxPower(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxPower(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxPower(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxPower(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxPower(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxPower(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar maxPower = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef max_power(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxPower(_ s: String) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxPower(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxPower(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxPower(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_power(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function maxPower($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxPower(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-power s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1446](https://leetcode-cn.com/problems/consecutive-characters)", "[\u8fde\u7eed\u5b57\u7b26](/solution/1400-1499/1446.Consecutive%20Characters/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1446](https://leetcode.com/problems/consecutive-characters)", "[Consecutive Characters](/solution/1400-1499/1446.Consecutive%20Characters/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1541", "frontend_question_id": "1407", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/top-travellers", "url_en": "https://leetcode.com/problems/top-travellers", "relative_path_cn": "/solution/1400-1499/1407.Top%20Travellers/README.md", "relative_path_en": "/solution/1400-1499/1407.Top%20Travellers/README_EN.md", "title_cn": "\u6392\u540d\u9760\u524d\u7684\u65c5\u884c\u8005", "title_en": "Top Travellers", "question_title_slug": "top-travellers", "content_en": "

Table: Users

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| name          | varchar |\n+---------------+---------+\nid is the primary key for this table.\nname is the name of the user.\n
\n\n

 

\n\n

Table: Rides

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| user_id       | int     |\n| distance      | int     |\n+---------------+---------+\nid is the primary key for this table.\nuser_id is the id of the user who travelled the distance "distance".\n
\n\n

 

\n\n

Write an SQL query to report the distance travelled by each user.

\n\n

Return the result table ordered by travelled_distance in descending order, if two or more users travelled the same distance, order them by their name in ascending order.

\n\n

The query result format is in the following example.

\n\n

 

\n\n
\nUsers table:\n+------+-----------+\n| id   | name      |\n+------+-----------+\n| 1    | Alice     |\n| 2    | Bob       |\n| 3    | Alex      |\n| 4    | Donald    |\n| 7    | Lee       |\n| 13   | Jonathan  |\n| 19   | Elvis     |\n+------+-----------+\n\nRides table:\n+------+----------+----------+\n| id   | user_id  | distance |\n+------+----------+----------+\n| 1    | 1        | 120      |\n| 2    | 2        | 317      |\n| 3    | 3        | 222      |\n| 4    | 7        | 100      |\n| 5    | 13       | 312      |\n| 6    | 19       | 50       |\n| 7    | 7        | 120      |\n| 8    | 19       | 400      |\n| 9    | 7        | 230      |\n+------+----------+----------+\n\nResult table:\n+----------+--------------------+\n| name     | travelled_distance |\n+----------+--------------------+\n| Elvis    | 450                |\n| Lee      | 450                |\n| Bob      | 317                |\n| Jonathan | 312                |\n| Alex     | 222                |\n| Alice    | 120                |\n| Donald   | 0                  |\n+----------+--------------------+\nElvis and Lee travelled 450 miles, Elvis is the top traveller as his name is alphabetically smaller than Lee.\nBob, Jonathan, Alex and Alice have only one ride and we just order them by the total distances of the ride.\nDonald didn't have any rides, the distance travelled by him is 0.\n
\n", "content_cn": "

\u8868\uff1aUsers

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| name          | varchar |\n+---------------+---------+\nid \u662f\u8be5\u8868\u5355\u4e3b\u952e\u3002\nname \u662f\u7528\u6237\u540d\u5b57\u3002
\n\n

\u00a0

\n\n

\u8868\uff1aRides

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| user_id       | int     |\n| distance      | int     |\n+---------------+---------+\nid \u662f\u8be5\u8868\u5355\u4e3b\u952e\u3002\nuser_id \u662f\u672c\u6b21\u884c\u7a0b\u7684\u7528\u6237\u7684 id, \u800c\u8be5\u7528\u6237\u6b64\u6b21\u884c\u7a0b\u8ddd\u79bb\u4e3a distance \u3002\n
\n\n

\u00a0

\n\n

\u5199\u4e00\u6bb5 SQL ,\u00a0\u62a5\u544a\u6bcf\u4e2a\u7528\u6237\u7684\u65c5\u884c\u8ddd\u79bb\u3002

\n\n

\u8fd4\u56de\u7684\u7ed3\u679c\u8868\u5355\uff0c\u4ee5\u00a0travelled_distance\u00a0\u964d\u5e8f\u6392\u5217 \uff0c\u5982\u679c\u6709\u4e24\u4e2a\u6216\u8005\u66f4\u591a\u7684\u7528\u6237\u65c5\u884c\u4e86\u76f8\u540c\u7684\u8ddd\u79bb,\u00a0\u90a3\u4e48\u518d\u4ee5\u00a0name\u00a0\u5347\u5e8f\u6392\u5217 \u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a\u3002

\n\n
\nUsers \u8868\uff1a\n+------+-----------+\n| id   | name      |\n+------+-----------+\n| 1    | Alice     |\n| 2    | Bob       |\n| 3    | Alex      |\n| 4    | Donald    |\n| 7    | Lee       |\n| 13   | Jonathan  |\n| 19   | Elvis     |\n+------+-----------+\n\nRides \u8868\uff1a\n+------+----------+----------+\n| id   | user_id  | distance |\n+------+----------+----------+\n| 1    | 1        | 120      |\n| 2    | 2        | 317      |\n| 3    | 3        | 222      |\n| 4    | 7        | 100      |\n| 5    | 13       | 312      |\n| 6    | 19       | 50       |\n| 7    | 7        | 120      |\n| 8    | 19       | 400      |\n| 9    | 7        | 230      |\n+------+----------+----------+\n\nResult \u8868\uff1a\n+----------+--------------------+\n| name     | travelled_distance |\n+----------+--------------------+\n| Elvis    | 450                |\n| Lee      | 450                |\n| Bob      | 317                |\n| Jonathan | 312                |\n| Alex     | 222                |\n| Alice    | 120                |\n| Donald   | 0                  |\n+----------+--------------------+\nElvis \u548c Lee \u65c5\u884c\u4e86 450 \u82f1\u91cc\uff0cElvis \u662f\u6392\u540d\u9760\u524d\u7684\u65c5\u884c\u8005\uff0c\u56e0\u4e3a\u4ed6\u7684\u540d\u5b57\u5728\u5b57\u6bcd\u8868\u4e0a\u7684\u6392\u5e8f\u6bd4 Lee \u66f4\u5c0f\u3002\nBob, Jonathan, Alex \u548c Alice \u53ea\u6709\u4e00\u6b21\u884c\u7a0b\uff0c\u6211\u4eec\u53ea\u6309\u6b64\u6b21\u884c\u7a0b\u7684\u5168\u90e8\u8ddd\u79bb\u5bf9\u4ed6\u4eec\u6392\u5e8f\u3002\nDonald \u6ca1\u6709\u4efb\u4f55\u884c\u7a0b, \u4ed6\u7684\u65c5\u884c\u8ddd\u79bb\u4e3a 0\u3002\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1407](https://leetcode-cn.com/problems/top-travellers)", "[\u6392\u540d\u9760\u524d\u7684\u65c5\u884c\u8005](/solution/1400-1499/1407.Top%20Travellers/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1407](https://leetcode.com/problems/top-travellers)", "[Top Travellers](/solution/1400-1499/1407.Top%20Travellers/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1539", "frontend_question_id": "1424", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/diagonal-traverse-ii", "url_en": "https://leetcode.com/problems/diagonal-traverse-ii", "relative_path_cn": "/solution/1400-1499/1424.Diagonal%20Traverse%20II/README.md", "relative_path_en": "/solution/1400-1499/1424.Diagonal%20Traverse%20II/README_EN.md", "title_cn": "\u5bf9\u89d2\u7ebf\u904d\u5386 II", "title_en": "Diagonal Traverse II", "question_title_slug": "diagonal-traverse-ii", "content_en": "Given a list of lists of integers, nums, return all elements of nums in diagonal order as shown in the below images.\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: nums = [[1,2,3],[4,5,6],[7,8,9]]\nOutput: [1,4,2,7,5,3,8,6,9]\n
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: nums = [[1,2,3,4,5],[6,7],[8],[9,10,11],[12,13,14,15,16]]\nOutput: [1,6,2,8,7,3,9,4,12,10,5,13,11,14,15,16]\n
\n\n

Example 3:

\n\n
\nInput: nums = [[1,2,3],[4],[5,6,7],[8],[9,10,11]]\nOutput: [1,4,2,5,3,8,6,9,7,10,11]\n
\n\n

Example 4:

\n\n
\nInput: nums = [[1,2,3,4,5,6]]\nOutput: [1,2,3,4,5,6]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 10^5
  • \n\t
  • 1 <= nums[i].length <= 10^5
  • \n\t
  • 1 <= nums[i][j] <= 10^9
  • \n\t
  • There at most 10^5 elements in nums.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5217\u8868 nums \uff0c\u91cc\u9762\u6bcf\u4e00\u4e2a\u5143\u7d20\u90fd\u662f\u4e00\u4e2a\u6574\u6570\u5217\u8868\u3002\u8bf7\u4f60\u4f9d\u7167\u4e0b\u9762\u5404\u56fe\u7684\u89c4\u5219\uff0c\u6309\u987a\u5e8f\u8fd4\u56de nums \u4e2d\u5bf9\u89d2\u7ebf\u4e0a\u7684\u6574\u6570\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1anums = [[1,2,3],[4,5,6],[7,8,9]]\n\u8f93\u51fa\uff1a[1,4,2,7,5,3,8,6,9]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1anums = [[1,2,3,4,5],[6,7],[8],[9,10,11],[12,13,14,15,16]]\n\u8f93\u51fa\uff1a[1,6,2,8,7,3,9,4,12,10,5,13,11,14,15,16]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1anums = [[1,2,3],[4],[5,6,7],[8],[9,10,11]]\n\u8f93\u51fa\uff1a[1,4,2,5,3,8,6,9,7,10,11]\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1anums = [[1,2,3,4,5,6]]\n\u8f93\u51fa\uff1a[1,2,3,4,5,6]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 10^5
  • \n\t
  • 1 <= nums[i].length <= 10^5
  • \n\t
  • 1 <= nums[i][j] <= 10^9
  • \n\t
  • nums \u4e2d\u6700\u591a\u6709 10^5 \u4e2a\u6570\u5b57\u3002
  • \n
\n", "tags_en": ["Sort", "Array"], "tags_cn": ["\u6392\u5e8f", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findDiagonalOrder(vector>& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] findDiagonalOrder(List> nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findDiagonalOrder(self, nums):\n \"\"\"\n :type nums: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findDiagonalOrder(self, nums: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* findDiagonalOrder(int** nums, int numsSize, int* numsColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] FindDiagonalOrder(IList> nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} nums\n * @return {number[]}\n */\nvar findDiagonalOrder = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} nums\n# @return {Integer[]}\ndef find_diagonal_order(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findDiagonalOrder(_ nums: [[Int]]) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findDiagonalOrder(nums [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findDiagonalOrder(nums: List[List[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findDiagonalOrder(nums: List>): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_diagonal_order(nums: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $nums\n * @return Integer[]\n */\n function findDiagonalOrder($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findDiagonalOrder(nums: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-diagonal-order nums)\n (-> (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1424](https://leetcode-cn.com/problems/diagonal-traverse-ii)", "[\u5bf9\u89d2\u7ebf\u904d\u5386 II](/solution/1400-1499/1424.Diagonal%20Traverse%20II/README.md)", "`\u6392\u5e8f`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1424](https://leetcode.com/problems/diagonal-traverse-ii)", "[Diagonal Traverse II](/solution/1400-1499/1424.Diagonal%20Traverse%20II/README_EN.md)", "`Sort`,`Array`", "Medium", ""]}, {"question_id": "1538", "frontend_question_id": "1423", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-points-you-can-obtain-from-cards", "url_en": "https://leetcode.com/problems/maximum-points-you-can-obtain-from-cards", "relative_path_cn": "/solution/1400-1499/1423.Maximum%20Points%20You%20Can%20Obtain%20from%20Cards/README.md", "relative_path_en": "/solution/1400-1499/1423.Maximum%20Points%20You%20Can%20Obtain%20from%20Cards/README_EN.md", "title_cn": "\u53ef\u83b7\u5f97\u7684\u6700\u5927\u70b9\u6570", "title_en": "Maximum Points You Can Obtain from Cards", "question_title_slug": "maximum-points-you-can-obtain-from-cards", "content_en": "

There are several cards arranged in a row, and each card has an associated number of points. The points are given in the integer array cardPoints.

\n\n

In one step, you can take one card from the beginning or from the end of the row. You have to take exactly k cards.

\n\n

Your score is the sum of the points of the cards you have taken.

\n\n

Given the integer array cardPoints and the integer k, return the maximum score you can obtain.

\n\n

 

\n

Example 1:

\n\n
\nInput: cardPoints = [1,2,3,4,5,6,1], k = 3\nOutput: 12\nExplanation: After the first step, your score will always be 1. However, choosing the rightmost card first will maximize your total score. The optimal strategy is to take the three cards on the right, giving a final score of 1 + 6 + 5 = 12.\n
\n\n

Example 2:

\n\n
\nInput: cardPoints = [2,2,2], k = 2\nOutput: 4\nExplanation: Regardless of which two cards you take, your score will always be 4.\n
\n\n

Example 3:

\n\n
\nInput: cardPoints = [9,7,7,9,7,7,9], k = 7\nOutput: 55\nExplanation: You have to take all the cards. Your score is the sum of points of all cards.\n
\n\n

Example 4:

\n\n
\nInput: cardPoints = [1,1000,1], k = 1\nOutput: 1\nExplanation: You cannot take the card in the middle. Your best score is 1. \n
\n\n

Example 5:

\n\n
\nInput: cardPoints = [1,79,80,1,1,1,200,1], k = 3\nOutput: 202\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= cardPoints.length <= 105
  • \n\t
  • 1 <= cardPoints[i] <= 104
  • \n\t
  • 1 <= k <= cardPoints.length
  • \n
\n", "content_cn": "

\u51e0\u5f20\u5361\u724c \u6392\u6210\u4e00\u884c\uff0c\u6bcf\u5f20\u5361\u724c\u90fd\u6709\u4e00\u4e2a\u5bf9\u5e94\u7684\u70b9\u6570\u3002\u70b9\u6570\u7531\u6574\u6570\u6570\u7ec4 cardPoints \u7ed9\u51fa\u3002

\n\n

\u6bcf\u6b21\u884c\u52a8\uff0c\u4f60\u53ef\u4ee5\u4ece\u884c\u7684\u5f00\u5934\u6216\u8005\u672b\u5c3e\u62ff\u4e00\u5f20\u5361\u724c\uff0c\u6700\u7ec8\u4f60\u5fc5\u987b\u6b63\u597d\u62ff k \u5f20\u5361\u724c\u3002

\n\n

\u4f60\u7684\u70b9\u6570\u5c31\u662f\u4f60\u62ff\u5230\u624b\u4e2d\u7684\u6240\u6709\u5361\u724c\u7684\u70b9\u6570\u4e4b\u548c\u3002

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 cardPoints \u548c\u6574\u6570 k\uff0c\u8bf7\u4f60\u8fd4\u56de\u53ef\u4ee5\u83b7\u5f97\u7684\u6700\u5927\u70b9\u6570\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1acardPoints = [1,2,3,4,5,6,1], k = 3\n\u8f93\u51fa\uff1a12\n\u89e3\u91ca\uff1a\u7b2c\u4e00\u6b21\u884c\u52a8\uff0c\u4e0d\u7ba1\u62ff\u54ea\u5f20\u724c\uff0c\u4f60\u7684\u70b9\u6570\u603b\u662f 1 \u3002\u4f46\u662f\uff0c\u5148\u62ff\u6700\u53f3\u8fb9\u7684\u5361\u724c\u5c06\u4f1a\u6700\u5927\u5316\u4f60\u7684\u53ef\u83b7\u5f97\u70b9\u6570\u3002\u6700\u4f18\u7b56\u7565\u662f\u62ff\u53f3\u8fb9\u7684\u4e09\u5f20\u724c\uff0c\u6700\u7ec8\u70b9\u6570\u4e3a 1 + 6 + 5 = 12 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1acardPoints = [2,2,2], k = 2\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u65e0\u8bba\u4f60\u62ff\u8d77\u54ea\u4e24\u5f20\u5361\u724c\uff0c\u53ef\u83b7\u5f97\u7684\u70b9\u6570\u603b\u662f 4 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1acardPoints = [9,7,7,9,7,7,9], k = 7\n\u8f93\u51fa\uff1a55\n\u89e3\u91ca\uff1a\u4f60\u5fc5\u987b\u62ff\u8d77\u6240\u6709\u5361\u724c\uff0c\u53ef\u4ee5\u83b7\u5f97\u7684\u70b9\u6570\u4e3a\u6240\u6709\u5361\u724c\u7684\u70b9\u6570\u4e4b\u548c\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1acardPoints = [1,1000,1], k = 1\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u4f60\u65e0\u6cd5\u62ff\u5230\u4e2d\u95f4\u90a3\u5f20\u5361\u724c\uff0c\u6240\u4ee5\u53ef\u4ee5\u83b7\u5f97\u7684\u6700\u5927\u70b9\u6570\u4e3a 1 \u3002 \n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1acardPoints = [1,79,80,1,1,1,200,1], k = 3\n\u8f93\u51fa\uff1a202\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= cardPoints.length <= 10^5
  • \n\t
  • 1 <= cardPoints[i] <= 10^4
  • \n\t
  • 1 <= k <= cardPoints.length
  • \n
\n", "tags_en": ["Array", "Dynamic Programming", "Sliding Window"], "tags_cn": ["\u6570\u7ec4", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxScore(vector& cardPoints, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxScore(int[] cardPoints, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxScore(self, cardPoints, k):\n \"\"\"\n :type cardPoints: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxScore(self, cardPoints: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxScore(int* cardPoints, int cardPointsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxScore(int[] cardPoints, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} cardPoints\n * @param {number} k\n * @return {number}\n */\nvar maxScore = function(cardPoints, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} card_points\n# @param {Integer} k\n# @return {Integer}\ndef max_score(card_points, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxScore(_ cardPoints: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxScore(cardPoints []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxScore(cardPoints: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxScore(cardPoints: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_score(card_points: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $cardPoints\n * @param Integer $k\n * @return Integer\n */\n function maxScore($cardPoints, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxScore(cardPoints: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-score cardPoints k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1423](https://leetcode-cn.com/problems/maximum-points-you-can-obtain-from-cards)", "[\u53ef\u83b7\u5f97\u7684\u6700\u5927\u70b9\u6570](/solution/1400-1499/1423.Maximum%20Points%20You%20Can%20Obtain%20from%20Cards/README.md)", "`\u6570\u7ec4`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1423](https://leetcode.com/problems/maximum-points-you-can-obtain-from-cards)", "[Maximum Points You Can Obtain from Cards](/solution/1400-1499/1423.Maximum%20Points%20You%20Can%20Obtain%20from%20Cards/README_EN.md)", "`Array`,`Dynamic Programming`,`Sliding Window`", "Medium", ""]}, {"question_id": "1537", "frontend_question_id": "1422", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-score-after-splitting-a-string", "url_en": "https://leetcode.com/problems/maximum-score-after-splitting-a-string", "relative_path_cn": "/solution/1400-1499/1422.Maximum%20Score%20After%20Splitting%20a%20String/README.md", "relative_path_en": "/solution/1400-1499/1422.Maximum%20Score%20After%20Splitting%20a%20String/README_EN.md", "title_cn": "\u5206\u5272\u5b57\u7b26\u4e32\u7684\u6700\u5927\u5f97\u5206", "title_en": "Maximum Score After Splitting a String", "question_title_slug": "maximum-score-after-splitting-a-string", "content_en": "

Given a string s of zeros and ones, return the maximum score after splitting the string into two non-empty substrings (i.e. left substring and right substring).

\n\n

The score after splitting a string is the number of zeros in the left substring plus the number of ones in the right substring.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "011101"\nOutput: 5 \nExplanation: \nAll possible ways of splitting s into two non-empty substrings are:\nleft = "0" and right = "11101", score = 1 + 4 = 5 \nleft = "01" and right = "1101", score = 1 + 3 = 4 \nleft = "011" and right = "101", score = 1 + 2 = 3 \nleft = "0111" and right = "01", score = 1 + 1 = 2 \nleft = "01110" and right = "1", score = 2 + 1 = 3\n
\n\n

Example 2:

\n\n
\nInput: s = "00111"\nOutput: 5\nExplanation: When left = "00" and right = "111", we get the maximum score = 2 + 3 = 5\n
\n\n

Example 3:

\n\n
\nInput: s = "1111"\nOutput: 3\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= s.length <= 500
  • \n\t
  • The string s consists of characters '0' and '1' only.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u7531\u82e5\u5e72 0 \u548c 1 \u7ec4\u6210\u7684\u5b57\u7b26\u4e32 s \uff0c\u8bf7\u4f60\u8ba1\u7b97\u5e76\u8fd4\u56de\u5c06\u8be5\u5b57\u7b26\u4e32\u5206\u5272\u6210\u4e24\u4e2a \u975e\u7a7a \u5b50\u5b57\u7b26\u4e32\uff08\u5373 \u5de6 \u5b50\u5b57\u7b26\u4e32\u548c \u53f3 \u5b50\u5b57\u7b26\u4e32\uff09\u6240\u80fd\u83b7\u5f97\u7684\u6700\u5927\u5f97\u5206\u3002

\n\n

\u300c\u5206\u5272\u5b57\u7b26\u4e32\u7684\u5f97\u5206\u300d\u4e3a \u5de6 \u5b50\u5b57\u7b26\u4e32\u4e2d 0 \u7684\u6570\u91cf\u52a0\u4e0a \u53f3 \u5b50\u5b57\u7b26\u4e32\u4e2d 1 \u7684\u6570\u91cf\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1as = "011101"\n\u8f93\u51fa\uff1a5 \n\u89e3\u91ca\uff1a\n\u5c06\u5b57\u7b26\u4e32 s \u5212\u5206\u4e3a\u4e24\u4e2a\u975e\u7a7a\u5b50\u5b57\u7b26\u4e32\u7684\u53ef\u884c\u65b9\u6848\u6709\uff1a\n\u5de6\u5b50\u5b57\u7b26\u4e32 = "0" \u4e14 \u53f3\u5b50\u5b57\u7b26\u4e32 = "11101"\uff0c\u5f97\u5206 = 1 + 4 = 5 \n\u5de6\u5b50\u5b57\u7b26\u4e32 = "01" \u4e14 \u53f3\u5b50\u5b57\u7b26\u4e32 = "1101"\uff0c\u5f97\u5206 = 1 + 3 = 4 \n\u5de6\u5b50\u5b57\u7b26\u4e32 = "011" \u4e14 \u53f3\u5b50\u5b57\u7b26\u4e32 = "101"\uff0c\u5f97\u5206 = 1 + 2 = 3 \n\u5de6\u5b50\u5b57\u7b26\u4e32 = "0111" \u4e14 \u53f3\u5b50\u5b57\u7b26\u4e32 = "01"\uff0c\u5f97\u5206 = 1 + 1 = 2 \n\u5de6\u5b50\u5b57\u7b26\u4e32 = "01110" \u4e14 \u53f3\u5b50\u5b57\u7b26\u4e32 = "1"\uff0c\u5f97\u5206 = 2 + 1 = 3\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1as = "00111"\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u5f53 \u5de6\u5b50\u5b57\u7b26\u4e32 = "00" \u4e14 \u53f3\u5b50\u5b57\u7b26\u4e32 = "111" \u65f6\uff0c\u6211\u4eec\u5f97\u5230\u6700\u5927\u5f97\u5206 = 2 + 3 = 5\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1as = "1111"\n\u8f93\u51fa\uff1a3\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= s.length <= 500
  • \n\t
  • \u5b57\u7b26\u4e32 s \u4ec5\u7531\u5b57\u7b26 '0' \u548c '1' \u7ec4\u6210\u3002
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxScore(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxScore(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxScore(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxScore(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxScore(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxScore(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar maxScore = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef max_score(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxScore(_ s: String) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxScore(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxScore(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxScore(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_score(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function maxScore($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxScore(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-score s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1422](https://leetcode-cn.com/problems/maximum-score-after-splitting-a-string)", "[\u5206\u5272\u5b57\u7b26\u4e32\u7684\u6700\u5927\u5f97\u5206](/solution/1400-1499/1422.Maximum%20Score%20After%20Splitting%20a%20String/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1422](https://leetcode.com/problems/maximum-score-after-splitting-a-string)", "[Maximum Score After Splitting a String](/solution/1400-1499/1422.Maximum%20Score%20After%20Splitting%20a%20String/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1536", "frontend_question_id": "1398", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/customers-who-bought-products-a-and-b-but-not-c", "url_en": "https://leetcode.com/problems/customers-who-bought-products-a-and-b-but-not-c", "relative_path_cn": "/solution/1300-1399/1398.Customers%20Who%20Bought%20Products%20A%20and%20B%20but%20Not%20C/README.md", "relative_path_en": "/solution/1300-1399/1398.Customers%20Who%20Bought%20Products%20A%20and%20B%20but%20Not%20C/README_EN.md", "title_cn": "\u8d2d\u4e70\u4e86\u4ea7\u54c1 A \u548c\u4ea7\u54c1 B \u5374\u6ca1\u6709\u8d2d\u4e70\u4ea7\u54c1 C \u7684\u987e\u5ba2", "title_en": "Customers Who Bought Products A and B but Not C", "question_title_slug": "customers-who-bought-products-a-and-b-but-not-c", "content_en": "

Table: Customers

\n\n
\n+---------------------+---------+\n| Column Name         | Type    |\n+---------------------+---------+\n| customer_id         | int     |\n| customer_name       | varchar |\n+---------------------+---------+\ncustomer_id is the primary key for this table.\ncustomer_name is the name of the customer.
\n\n

 

\n\n

Table: Orders

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| order_id      | int     |\n| customer_id   | int     |\n| product_name  | varchar |\n+---------------+---------+\norder_id is the primary key for this table.\ncustomer_id is the id of the customer who bought the product "product_name".\n
\n\n

 

\n\n

Write an SQL query to report the customer_id and customer_name of customers who bought products "A", "B" but did not buy the product "C" since we want to recommend them buy this product.

\n\n

Return the result table ordered by customer_id.

\n\n

The query result format is in the following example.

\n\n

 

\n\n
\nCustomers table:\n+-------------+---------------+\n| customer_id | customer_name |\n+-------------+---------------+\n| 1           | Daniel        |\n| 2           | Diana         |\n| 3           | Elizabeth     |\n| 4           | Jhon          |\n+-------------+---------------+\n\nOrders table:\n+------------+--------------+---------------+\n| order_id   | customer_id  | product_name  |\n+------------+--------------+---------------+\n| 10         |     1        |     A         |\n| 20         |     1        |     B         |\n| 30         |     1        |     D         |\n| 40         |     1        |     C         |\n| 50         |     2        |     A         |\n| 60         |     3        |     A         |\n| 70         |     3        |     B         |\n| 80         |     3        |     D         |\n| 90         |     4        |     C         |\n+------------+--------------+---------------+\n\nResult table:\n+-------------+---------------+\n| customer_id | customer_name |\n+-------------+---------------+\n| 3           | Elizabeth     |\n+-------------+---------------+\nOnly the customer_id with id 3 bought the product A and B but not the product C.
\n", "content_cn": "

 Customers \u8868\uff1a

\n\n
\n+---------------------+---------+\n| Column Name         | Type    |\n+---------------------+---------+\n| customer_id         | int     |\n| customer_name       | varchar |\n+---------------------+---------+\ncustomer_id \u662f\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\u3002\ncustomer_name \u662f\u987e\u5ba2\u7684\u540d\u79f0\u3002
\n\n

 

\n\n

Orders \u8868\uff1a

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| order_id      | int     |\n| customer_id   | int     |\n| product_name  | varchar |\n+---------------+---------+\norder_id \u662f\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\u3002\ncustomer_id \u662f\u8d2d\u4e70\u4e86\u540d\u4e3a "product_name" \u4ea7\u54c1\u987e\u5ba2\u7684id\u3002\n
\n\n

 

\n\n

\u8bf7\u4f60\u8bbe\u8ba1 SQL \u67e5\u8be2\u6765\u62a5\u544a\u8d2d\u4e70\u4e86\u4ea7\u54c1 A \u548c\u4ea7\u54c1 B \u5374\u6ca1\u6709\u8d2d\u4e70\u4ea7\u54c1 C \u7684\u987e\u5ba2\u7684 ID \u548c\u59d3\u540d\uff08 customer_id \u548c customer_name \uff09\uff0c\u6211\u4eec\u5c06\u57fa\u4e8e\u6b64\u7ed3\u679c\u4e3a\u4ed6\u4eec\u63a8\u8350\u4ea7\u54c1 C \u3002
\n\u60a8\u8fd4\u56de\u7684\u67e5\u8be2\u7ed3\u679c\u9700\u8981\u6309\u7167 customer_id \u6392\u5e8f\u3002

\n\n

 

\n\n

\u67e5\u8be2\u7ed3\u679c\u5982\u4e0b\u4f8b\u6240\u793a\u3002

\n\n
\nCustomers table:\n+-------------+---------------+\n| customer_id | customer_name |\n+-------------+---------------+\n| 1           | Daniel        |\n| 2           | Diana         |\n| 3           | Elizabeth     |\n| 4           | Jhon          |\n+-------------+---------------+\n\nOrders table:\n+------------+--------------+---------------+\n| order_id   | customer_id  | product_name  |\n+------------+--------------+---------------+\n| 10         |     1        |     A         |\n| 20         |     1        |     B         |\n| 30         |     1        |     D         |\n| 40         |     1        |     C         |\n| 50         |     2        |     A         |\n| 60         |     3        |     A         |\n| 70         |     3        |     B         |\n| 80         |     3        |     D         |\n| 90         |     4        |     C         |\n+------------+--------------+---------------+\n\nResult table:\n+-------------+---------------+\n| customer_id | customer_name |\n+-------------+---------------+\n| 3           | Elizabeth     |\n+-------------+---------------+\n\u53ea\u6709 customer_id \u4e3a 3 \u7684\u987e\u5ba2\u8d2d\u4e70\u4e86\u4ea7\u54c1 A \u548c\u4ea7\u54c1 B \uff0c\u5374\u6ca1\u6709\u8d2d\u4e70\u4ea7\u54c1 C \u3002
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1398](https://leetcode-cn.com/problems/customers-who-bought-products-a-and-b-but-not-c)", "[\u8d2d\u4e70\u4e86\u4ea7\u54c1 A \u548c\u4ea7\u54c1 B \u5374\u6ca1\u6709\u8d2d\u4e70\u4ea7\u54c1 C \u7684\u987e\u5ba2](/solution/1300-1399/1398.Customers%20Who%20Bought%20Products%20A%20and%20B%20but%20Not%20C/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1398](https://leetcode.com/problems/customers-who-bought-products-a-and-b-but-not-c)", "[Customers Who Bought Products A and B but Not C](/solution/1300-1399/1398.Customers%20Who%20Bought%20Products%20A%20and%20B%20but%20Not%20C/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1535", "frontend_question_id": "1420", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/build-array-where-you-can-find-the-maximum-exactly-k-comparisons", "url_en": "https://leetcode.com/problems/build-array-where-you-can-find-the-maximum-exactly-k-comparisons", "relative_path_cn": "/solution/1400-1499/1420.Build%20Array%20Where%20You%20Can%20Find%20The%20Maximum%20Exactly%20K%20Comparisons/README.md", "relative_path_en": "/solution/1400-1499/1420.Build%20Array%20Where%20You%20Can%20Find%20The%20Maximum%20Exactly%20K%20Comparisons/README_EN.md", "title_cn": "\u751f\u6210\u6570\u7ec4", "title_en": "Build Array Where You Can Find The Maximum Exactly K Comparisons", "question_title_slug": "build-array-where-you-can-find-the-maximum-exactly-k-comparisons", "content_en": "

Given three integers n, m and k. Consider the following algorithm to find the maximum element of an array of positive integers:

\r\n\"\"\r\n

You should build the array arr which has the following properties:

\r\n\r\n
    \r\n\t
  • arr has exactly n integers.
  • \r\n\t
  • 1 <= arr[i] <= m where (0 <= i < n).
  • \r\n\t
  • After applying the mentioned algorithm to arr, the value search_cost is equal to k.
  • \r\n
\r\n\r\n

Return the number of ways to build the array arr under the mentioned conditions. As the answer may grow large, the answer must be computed modulo 10^9 + 7.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: n = 2, m = 3, k = 1\r\nOutput: 6\r\nExplanation: The possible arrays are [1, 1], [2, 1], [2, 2], [3, 1], [3, 2] [3, 3]\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: n = 5, m = 2, k = 3\r\nOutput: 0\r\nExplanation: There are no possible arrays that satisify the mentioned conditions.\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: n = 9, m = 1, k = 1\r\nOutput: 1\r\nExplanation: The only possible array is [1, 1, 1, 1, 1, 1, 1, 1, 1]\r\n
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: n = 50, m = 100, k = 25\r\nOutput: 34549172\r\nExplanation: Don't forget to compute the answer modulo 1000000007\r\n
\r\n\r\n

Example 5:

\r\n\r\n
\r\nInput: n = 37, m = 17, k = 7\r\nOutput: 418930126\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= n <= 50
  • \r\n\t
  • 1 <= m <= 100
  • \r\n\t
  • 0 <= k <= n
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e09\u4e2a\u6574\u6570 n\u3001m \u548c k \u3002\u4e0b\u56fe\u63cf\u8ff0\u7684\u7b97\u6cd5\u7528\u4e8e\u627e\u51fa\u6b63\u6574\u6570\u6570\u7ec4\u4e2d\u6700\u5927\u7684\u5143\u7d20\u3002

\n\n

\"\"

\n\n

\u8bf7\u4f60\u751f\u6210\u4e00\u4e2a\u5177\u6709\u4e0b\u8ff0\u5c5e\u6027\u7684\u6570\u7ec4 arr \uff1a

\n\n
    \n\t
  • arr \u4e2d\u6709 n \u4e2a\u6574\u6570\u3002
  • \n\t
  • 1 <= arr[i] <= m \u5176\u4e2d (0 <= i < n) \u3002
  • \n\t
  • \u5c06\u4e0a\u9762\u63d0\u5230\u7684\u7b97\u6cd5\u5e94\u7528\u4e8e arr \uff0csearch_cost \u7684\u503c\u7b49\u4e8e k \u3002
  • \n
\n\n

\u8fd4\u56de\u4e0a\u8ff0\u6761\u4ef6\u4e0b\u751f\u6210\u6570\u7ec4 arr \u7684 \u65b9\u6cd5\u6570 \uff0c\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u4f1a\u5f88\u5927\uff0c\u6240\u4ee5 \u5fc5\u987b \u5bf9 10^9 + 7 \u53d6\u4f59\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1an = 2, m = 3, k = 1\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u53ef\u80fd\u7684\u6570\u7ec4\u5206\u522b\u4e3a [1, 1], [2, 1], [2, 2], [3, 1], [3, 2] [3, 3]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1an = 5, m = 2, k = 3\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6ca1\u6709\u6570\u7ec4\u53ef\u4ee5\u6ee1\u8db3\u4e0a\u8ff0\u6761\u4ef6\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1an = 9, m = 1, k = 1\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u53ef\u80fd\u7684\u6570\u7ec4\u53ea\u6709 [1, 1, 1, 1, 1, 1, 1, 1, 1]\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1an = 50, m = 100, k = 25\n\u8f93\u51fa\uff1a34549172\n\u89e3\u91ca\uff1a\u4e0d\u8981\u5fd8\u4e86\u5bf9 1000000007 \u53d6\u4f59\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1an = 37, m = 17, k = 7\n\u8f93\u51fa\uff1a418930126\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 50
  • \n\t
  • 1 <= m <= 100
  • \n\t
  • 0 <= k <= n
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numOfArrays(int n, int m, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numOfArrays(int n, int m, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numOfArrays(self, n, m, k):\n \"\"\"\n :type n: int\n :type m: int\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numOfArrays(self, n: int, m: int, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numOfArrays(int n, int m, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumOfArrays(int n, int m, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} m\n * @param {number} k\n * @return {number}\n */\nvar numOfArrays = function(n, m, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} m\n# @param {Integer} k\n# @return {Integer}\ndef num_of_arrays(n, m, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numOfArrays(_ n: Int, _ m: Int, _ k: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numOfArrays(n int, m int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numOfArrays(n: Int, m: Int, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numOfArrays(n: Int, m: Int, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_of_arrays(n: i32, m: i32, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $m\n * @param Integer $k\n * @return Integer\n */\n function numOfArrays($n, $m, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numOfArrays(n: number, m: number, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-of-arrays n m k)\n (-> exact-integer? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1420](https://leetcode-cn.com/problems/build-array-where-you-can-find-the-maximum-exactly-k-comparisons)", "[\u751f\u6210\u6570\u7ec4](/solution/1400-1499/1420.Build%20Array%20Where%20You%20Can%20Find%20The%20Maximum%20Exactly%20K%20Comparisons/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1420](https://leetcode.com/problems/build-array-where-you-can-find-the-maximum-exactly-k-comparisons)", "[Build Array Where You Can Find The Maximum Exactly K Comparisons](/solution/1400-1499/1420.Build%20Array%20Where%20You%20Can%20Find%20The%20Maximum%20Exactly%20K%20Comparisons/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1534", "frontend_question_id": "1419", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-number-of-frogs-croaking", "url_en": "https://leetcode.com/problems/minimum-number-of-frogs-croaking", "relative_path_cn": "/solution/1400-1499/1419.Minimum%20Number%20of%20Frogs%20Croaking/README.md", "relative_path_en": "/solution/1400-1499/1419.Minimum%20Number%20of%20Frogs%20Croaking/README_EN.md", "title_cn": "\u6570\u9752\u86d9", "title_en": "Minimum Number of Frogs Croaking", "question_title_slug": "minimum-number-of-frogs-croaking", "content_en": "

Given the string croakOfFrogs, which represents a combination of the string "croak" from different frogs, that is, multiple frogs can croak at the same time, so multiple “croak” are mixed. Return the minimum number of different frogs to finish all the croak in the given string.

\n\n

A valid "croak" means a frog is printing 5 letters ‘c’, ’r’, ’o’, ’a’, ’k’ sequentially. The frogs have to print all five letters to finish a croak. If the given string is not a combination of valid "croak" return -1.

\n\n

 

\n

Example 1:

\n\n
\nInput: croakOfFrogs = "croakcroak"\nOutput: 1 \nExplanation: One frog yelling "croak" twice.\n
\n\n

Example 2:

\n\n
\nInput: croakOfFrogs = "crcoakroak"\nOutput: 2 \nExplanation: The minimum number of frogs is two. \nThe first frog could yell "crcoakroak".\nThe second frog could yell later "crcoakroak".\n
\n\n

Example 3:

\n\n
\nInput: croakOfFrogs = "croakcrook"\nOutput: -1\nExplanation: The given string is an invalid combination of "croak" from different frogs.\n
\n\n

Example 4:

\n\n
\nInput: croakOfFrogs = "croakcroa"\nOutput: -1\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= croakOfFrogs.length <= 10^5
  • \n\t
  • All characters in the string are: 'c', 'r', 'o', 'a' or 'k'.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 croakOfFrogs\uff0c\u5b83\u8868\u793a\u4e0d\u540c\u9752\u86d9\u53d1\u51fa\u7684\u86d9\u9e23\u58f0\uff08\u5b57\u7b26\u4e32 "croak" \uff09\u7684\u7ec4\u5408\u3002\u7531\u4e8e\u540c\u4e00\u65f6\u95f4\u53ef\u4ee5\u6709\u591a\u53ea\u9752\u86d9\u5471\u5471\u4f5c\u54cd\uff0c\u6240\u4ee5 croakOfFrogs \u4e2d\u4f1a\u6df7\u5408\u591a\u4e2a “croak” \u3002\u8bf7\u4f60\u8fd4\u56de\u6a21\u62df\u5b57\u7b26\u4e32\u4e2d\u6240\u6709\u86d9\u9e23\u6240\u9700\u4e0d\u540c\u9752\u86d9\u7684\u6700\u5c11\u6570\u76ee\u3002

\n\n

\u6ce8\u610f\uff1a\u8981\u60f3\u53d1\u51fa\u86d9\u9e23 "croak"\uff0c\u9752\u86d9\u5fc5\u987b \u4f9d\u5e8f \u8f93\u51fa ‘c’, ’r’, ’o’, ’a’, ’k’ \u8fd9 5 \u4e2a\u5b57\u6bcd\u3002\u5982\u679c\u6ca1\u6709\u8f93\u51fa\u5168\u90e8\u4e94\u4e2a\u5b57\u6bcd\uff0c\u90a3\u4e48\u5b83\u5c31\u4e0d\u4f1a\u53d1\u51fa\u58f0\u97f3\u3002

\n\n

\u5982\u679c\u5b57\u7b26\u4e32 croakOfFrogs \u4e0d\u662f\u7531\u82e5\u5e72\u6709\u6548\u7684 "croak" \u5b57\u7b26\u6df7\u5408\u800c\u6210\uff0c\u8bf7\u8fd4\u56de -1 \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1acroakOfFrogs = "croakcroak"\n\u8f93\u51fa\uff1a1 \n\u89e3\u91ca\uff1a\u4e00\u53ea\u9752\u86d9 “\u5471\u5471” \u4e24\u6b21\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1acroakOfFrogs = "crcoakroak"\n\u8f93\u51fa\uff1a2 \n\u89e3\u91ca\uff1a\u6700\u5c11\u9700\u8981\u4e24\u53ea\u9752\u86d9\uff0c“\u5471\u5471” \u58f0\u7528\u9ed1\u4f53\u6807\u6ce8\n\u7b2c\u4e00\u53ea\u9752\u86d9 "crcoakroak"\n\u7b2c\u4e8c\u53ea\u9752\u86d9 "crcoakroak"\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1acroakOfFrogs = "croakcrook"\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u7ed9\u51fa\u7684\u5b57\u7b26\u4e32\u4e0d\u662f "croak" \u7684\u6709\u6548\u7ec4\u5408\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1acroakOfFrogs = "croakcroa"\n\u8f93\u51fa\uff1a-1\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= croakOfFrogs.length <= 10^5
  • \n\t
  • \u5b57\u7b26\u4e32\u4e2d\u7684\u5b57\u7b26\u53ea\u6709 'c', 'r', 'o', 'a' \u6216\u8005 'k'
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minNumberOfFrogs(string croakOfFrogs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minNumberOfFrogs(String croakOfFrogs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minNumberOfFrogs(self, croakOfFrogs):\n \"\"\"\n :type croakOfFrogs: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minNumberOfFrogs(self, croakOfFrogs: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minNumberOfFrogs(char * croakOfFrogs){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinNumberOfFrogs(string croakOfFrogs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} croakOfFrogs\n * @return {number}\n */\nvar minNumberOfFrogs = function(croakOfFrogs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} croak_of_frogs\n# @return {Integer}\ndef min_number_of_frogs(croak_of_frogs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minNumberOfFrogs(_ croakOfFrogs: String) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minNumberOfFrogs(croakOfFrogs string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minNumberOfFrogs(croakOfFrogs: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minNumberOfFrogs(croakOfFrogs: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_number_of_frogs(croak_of_frogs: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $croakOfFrogs\n * @return Integer\n */\n function minNumberOfFrogs($croakOfFrogs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minNumberOfFrogs(croakOfFrogs: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-number-of-frogs croakOfFrogs)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1419](https://leetcode-cn.com/problems/minimum-number-of-frogs-croaking)", "[\u6570\u9752\u86d9](/solution/1400-1499/1419.Minimum%20Number%20of%20Frogs%20Croaking/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1419](https://leetcode.com/problems/minimum-number-of-frogs-croaking)", "[Minimum Number of Frogs Croaking](/solution/1400-1499/1419.Minimum%20Number%20of%20Frogs%20Croaking/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "1533", "frontend_question_id": "1418", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/display-table-of-food-orders-in-a-restaurant", "url_en": "https://leetcode.com/problems/display-table-of-food-orders-in-a-restaurant", "relative_path_cn": "/solution/1400-1499/1418.Display%20Table%20of%20Food%20Orders%20in%20a%20Restaurant/README.md", "relative_path_en": "/solution/1400-1499/1418.Display%20Table%20of%20Food%20Orders%20in%20a%20Restaurant/README_EN.md", "title_cn": "\u70b9\u83dc\u5c55\u793a\u8868", "title_en": "Display Table of Food Orders in a Restaurant", "question_title_slug": "display-table-of-food-orders-in-a-restaurant", "content_en": "

Given the array orders, which represents the orders that customers have done in a restaurant. More specifically orders[i]=[customerNamei,tableNumberi,foodItemi] where customerNamei is the name of the customer, tableNumberi is the table customer sit at, and foodItemi is the item customer orders.

\r\n\r\n

Return the restaurant's “display table. The “display table” is a table whose row entries denote how many of each food item each table ordered. The first column is the table number and the remaining columns correspond to each food item in alphabetical order. The first row should be a header whose first column is “Table”, followed by the names of the food items. Note that the customer names are not part of the table. Additionally, the rows should be sorted in numerically increasing order.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: orders = [["David","3","Ceviche"],["Corina","10","Beef Burrito"],["David","3","Fried Chicken"],["Carla","5","Water"],["Carla","5","Ceviche"],["Rous","3","Ceviche"]]\r\nOutput: [["Table","Beef Burrito","Ceviche","Fried Chicken","Water"],["3","0","2","1","0"],["5","0","1","0","1"],["10","1","0","0","0"]] \r\nExplanation:\r\nThe displaying table looks like:\r\nTable,Beef Burrito,Ceviche,Fried Chicken,Water\r\n3    ,0           ,2      ,1            ,0\r\n5    ,0           ,1      ,0            ,1\r\n10   ,1           ,0      ,0            ,0\r\nFor the table 3: David orders "Ceviche" and "Fried Chicken", and Rous orders "Ceviche".\r\nFor the table 5: Carla orders "Water" and "Ceviche".\r\nFor the table 10: Corina orders "Beef Burrito". \r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: orders = [["James","12","Fried Chicken"],["Ratesh","12","Fried Chicken"],["Amadeus","12","Fried Chicken"],["Adam","1","Canadian Waffles"],["Brianna","1","Canadian Waffles"]]\r\nOutput: [["Table","Canadian Waffles","Fried Chicken"],["1","2","0"],["12","0","3"]] \r\nExplanation: \r\nFor the table 1: Adam and Brianna order "Canadian Waffles".\r\nFor the table 12: James, Ratesh and Amadeus order "Fried Chicken".\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: orders = [["Laura","2","Bean Burrito"],["Jhon","2","Beef Burrito"],["Melissa","2","Soda"]]\r\nOutput: [["Table","Bean Burrito","Beef Burrito","Soda"],["2","1","1","1"]]\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= orders.length <= 5 * 10^4
  • \r\n\t
  • orders[i].length == 3
  • \r\n\t
  • 1 <= customerNamei.length, foodItemi.length <= 20
  • \r\n\t
  • customerNamei and foodItemi consist of lowercase and uppercase English letters and the space character.
  • \r\n\t
  • tableNumberi is a valid integer between 1 and 500.
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 orders\uff0c\u8868\u793a\u5ba2\u6237\u5728\u9910\u5385\u4e2d\u5b8c\u6210\u7684\u8ba2\u5355\uff0c\u786e\u5207\u5730\u8bf4\uff0c orders[i]=[customerNamei,tableNumberi,foodItemi] \uff0c\u5176\u4e2d customerNamei \u662f\u5ba2\u6237\u7684\u59d3\u540d\uff0ctableNumberi \u662f\u5ba2\u6237\u6240\u5728\u9910\u684c\u7684\u684c\u53f7\uff0c\u800c foodItemi \u662f\u5ba2\u6237\u70b9\u7684\u9910\u54c1\u540d\u79f0\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u8be5\u9910\u5385\u7684 \u70b9\u83dc\u5c55\u793a\u8868 \u3002\u5728\u8fd9\u5f20\u8868\u4e2d\uff0c\u8868\u4e2d\u7b2c\u4e00\u884c\u4e3a\u6807\u9898\uff0c\u5176\u7b2c\u4e00\u5217\u4e3a\u9910\u684c\u684c\u53f7 “Table” \uff0c\u540e\u9762\u6bcf\u4e00\u5217\u90fd\u662f\u6309\u5b57\u6bcd\u987a\u5e8f\u6392\u5217\u7684\u9910\u54c1\u540d\u79f0\u3002\u63a5\u4e0b\u6765\u6bcf\u4e00\u884c\u4e2d\u7684\u9879\u5219\u8868\u793a\u6bcf\u5f20\u9910\u684c\u8ba2\u8d2d\u7684\u76f8\u5e94\u9910\u54c1\u6570\u91cf\uff0c\u7b2c\u4e00\u5217\u5e94\u5f53\u586b\u5bf9\u5e94\u7684\u684c\u53f7\uff0c\u540e\u9762\u4f9d\u6b21\u586b\u5199\u4e0b\u5355\u7684\u9910\u54c1\u6570\u91cf\u3002

\n\n

\u6ce8\u610f\uff1a\u5ba2\u6237\u59d3\u540d\u4e0d\u662f\u70b9\u83dc\u5c55\u793a\u8868\u7684\u4e00\u90e8\u5206\u3002\u6b64\u5916\uff0c\u8868\u4e2d\u7684\u6570\u636e\u884c\u5e94\u8be5\u6309\u9910\u684c\u684c\u53f7\u5347\u5e8f\u6392\u5217\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aorders = [["David","3","Ceviche"],["Corina","10","Beef Burrito"],["David","3","Fried Chicken"],["Carla","5","Water"],["Carla","5","Ceviche"],["Rous","3","Ceviche"]]\n\u8f93\u51fa\uff1a[["Table","Beef Burrito","Ceviche","Fried Chicken","Water"],["3","0","2","1","0"],["5","0","1","0","1"],["10","1","0","0","0"]] \n\u89e3\u91ca\uff1a\n\u70b9\u83dc\u5c55\u793a\u8868\u5982\u4e0b\u6240\u793a\uff1a\nTable,Beef Burrito,Ceviche,Fried Chicken,Water\n3    ,0           ,2      ,1            ,0\n5    ,0           ,1      ,0            ,1\n10   ,1           ,0      ,0            ,0\n\u5bf9\u4e8e\u9910\u684c 3\uff1aDavid \u70b9\u4e86 "Ceviche" \u548c "Fried Chicken"\uff0c\u800c Rous \u70b9\u4e86 "Ceviche"\n\u800c\u9910\u684c 5\uff1aCarla \u70b9\u4e86 "Water" \u548c "Ceviche"\n\u9910\u684c 10\uff1aCorina \u70b9\u4e86 "Beef Burrito" \n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aorders = [["James","12","Fried Chicken"],["Ratesh","12","Fried Chicken"],["Amadeus","12","Fried Chicken"],["Adam","1","Canadian Waffles"],["Brianna","1","Canadian Waffles"]]\n\u8f93\u51fa\uff1a[["Table","Canadian Waffles","Fried Chicken"],["1","2","0"],["12","0","3"]] \n\u89e3\u91ca\uff1a\n\u5bf9\u4e8e\u9910\u684c 1\uff1aAdam \u548c Brianna \u90fd\u70b9\u4e86 "Canadian Waffles"\n\u800c\u9910\u684c 12\uff1aJames, Ratesh \u548c Amadeus \u90fd\u70b9\u4e86 "Fried Chicken"\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aorders = [["Laura","2","Bean Burrito"],["Jhon","2","Beef Burrito"],["Melissa","2","Soda"]]\n\u8f93\u51fa\uff1a[["Table","Bean Burrito","Beef Burrito","Soda"],["2","1","1","1"]]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= orders.length <= 5 * 10^4
  • \n\t
  • orders[i].length == 3
  • \n\t
  • 1 <= customerNamei.length, foodItemi.length <= 20
  • \n\t
  • customerNamei \u548c foodItemi \u7531\u5927\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u53ca\u7a7a\u683c\u5b57\u7b26 ' ' \u7ec4\u6210\u3002
  • \n\t
  • tableNumberi \u662f 1 \u5230 500 \u8303\u56f4\u5185\u7684\u6574\u6570\u3002
  • \n
\n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> displayTable(vector>& orders) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> displayTable(List> orders) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def displayTable(self, orders):\n \"\"\"\n :type orders: List[List[str]]\n :rtype: List[List[str]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def displayTable(self, orders: List[List[str]]) -> List[List[str]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nchar *** displayTable(char *** orders, int ordersSize, int* ordersColSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> DisplayTable(IList> orders) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[][]} orders\n * @return {string[][]}\n */\nvar displayTable = function(orders) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[][]} orders\n# @return {String[][]}\ndef display_table(orders)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func displayTable(_ orders: [[String]]) -> [[String]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func displayTable(orders [][]string) [][]string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def displayTable(orders: List[List[String]]): List[List[String]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun displayTable(orders: List>): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn display_table(orders: Vec>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $orders\n * @return String[][]\n */\n function displayTable($orders) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function displayTable(orders: string[][]): string[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (display-table orders)\n (-> (listof (listof string?)) (listof (listof string?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1418](https://leetcode-cn.com/problems/display-table-of-food-orders-in-a-restaurant)", "[\u70b9\u83dc\u5c55\u793a\u8868](/solution/1400-1499/1418.Display%20Table%20of%20Food%20Orders%20in%20a%20Restaurant/README.md)", "`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1418](https://leetcode.com/problems/display-table-of-food-orders-in-a-restaurant)", "[Display Table of Food Orders in a Restaurant](/solution/1400-1499/1418.Display%20Table%20of%20Food%20Orders%20in%20a%20Restaurant/README_EN.md)", "`Hash Table`", "Medium", ""]}, {"question_id": "1532", "frontend_question_id": "1417", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reformat-the-string", "url_en": "https://leetcode.com/problems/reformat-the-string", "relative_path_cn": "/solution/1400-1499/1417.Reformat%20The%20String/README.md", "relative_path_en": "/solution/1400-1499/1417.Reformat%20The%20String/README_EN.md", "title_cn": "\u91cd\u65b0\u683c\u5f0f\u5316\u5b57\u7b26\u4e32", "title_en": "Reformat The String", "question_title_slug": "reformat-the-string", "content_en": "

Given alphanumeric string s. (Alphanumeric string is a string consisting of lowercase English letters and digits).

\n\n

You have to find a permutation of the string where no letter is followed by another letter and no digit is followed by another digit. That is, no two adjacent characters have the same type.

\n\n

Return the reformatted string or return an empty string if it is impossible to reformat the string.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "a0b1c2"\nOutput: "0a1b2c"\nExplanation: No two adjacent characters have the same type in "0a1b2c". "a0b1c2", "0a1b2c", "0c2a1b" are also valid permutations.\n
\n\n

Example 2:

\n\n
\nInput: s = "leetcode"\nOutput: ""\nExplanation: "leetcode" has only characters so we cannot separate them by digits.\n
\n\n

Example 3:

\n\n
\nInput: s = "1229857369"\nOutput: ""\nExplanation: "1229857369" has only digits so we cannot separate them by characters.\n
\n\n

Example 4:

\n\n
\nInput: s = "covid2019"\nOutput: "c2o0v1i9d"\n
\n\n

Example 5:

\n\n
\nInput: s = "ab123"\nOutput: "1a2b3"\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 500
  • \n\t
  • s consists of only lowercase English letters and/or digits.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6df7\u5408\u4e86\u6570\u5b57\u548c\u5b57\u6bcd\u7684\u5b57\u7b26\u4e32 s\uff0c\u5176\u4e2d\u7684\u5b57\u6bcd\u5747\u4e3a\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002

\n\n

\u8bf7\u4f60\u5c06\u8be5\u5b57\u7b26\u4e32\u91cd\u65b0\u683c\u5f0f\u5316\uff0c\u4f7f\u5f97\u4efb\u610f\u4e24\u4e2a\u76f8\u90bb\u5b57\u7b26\u7684\u7c7b\u578b\u90fd\u4e0d\u540c\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u5b57\u6bcd\u540e\u9762\u5e94\u8be5\u8ddf\u7740\u6570\u5b57\uff0c\u800c\u6570\u5b57\u540e\u9762\u5e94\u8be5\u8ddf\u7740\u5b57\u6bcd\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de \u91cd\u65b0\u683c\u5f0f\u5316\u540e \u7684\u5b57\u7b26\u4e32\uff1b\u5982\u679c\u65e0\u6cd5\u6309\u8981\u6c42\u91cd\u65b0\u683c\u5f0f\u5316\uff0c\u5219\u8fd4\u56de\u4e00\u4e2a \u7a7a\u5b57\u7b26\u4e32 \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1as = "a0b1c2"\n\u8f93\u51fa\uff1a"0a1b2c"\n\u89e3\u91ca\uff1a"0a1b2c" \u4e2d\u4efb\u610f\u4e24\u4e2a\u76f8\u90bb\u5b57\u7b26\u7684\u7c7b\u578b\u90fd\u4e0d\u540c\u3002 "a0b1c2", "0a1b2c", "0c2a1b" \u4e5f\u662f\u6ee1\u8db3\u9898\u76ee\u8981\u6c42\u7684\u7b54\u6848\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1as = "leetcode"\n\u8f93\u51fa\uff1a""\n\u89e3\u91ca\uff1a"leetcode" \u4e2d\u53ea\u6709\u5b57\u6bcd\uff0c\u6240\u4ee5\u65e0\u6cd5\u6ee1\u8db3\u91cd\u65b0\u683c\u5f0f\u5316\u7684\u6761\u4ef6\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1as = "1229857369"\n\u8f93\u51fa\uff1a""\n\u89e3\u91ca\uff1a"1229857369" \u4e2d\u53ea\u6709\u6570\u5b57\uff0c\u6240\u4ee5\u65e0\u6cd5\u6ee1\u8db3\u91cd\u65b0\u683c\u5f0f\u5316\u7684\u6761\u4ef6\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1as = "covid2019"\n\u8f93\u51fa\uff1a"c2o0v1i9d"\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1as = "ab123"\n\u8f93\u51fa\uff1a"1a2b3"\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length <= 500
  • \n\t
  • s \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u548c/\u6216\u6570\u5b57\u7ec4\u6210\u3002
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string reformat(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String reformat(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def reformat(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def reformat(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * reformat(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string Reformat(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar reformat = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef reformat(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func reformat(_ s: String) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func reformat(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def reformat(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun reformat(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn reformat(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function reformat($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function reformat(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (reformat s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1417](https://leetcode-cn.com/problems/reformat-the-string)", "[\u91cd\u65b0\u683c\u5f0f\u5316\u5b57\u7b26\u4e32](/solution/1400-1499/1417.Reformat%20The%20String/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1417](https://leetcode.com/problems/reformat-the-string)", "[Reformat The String](/solution/1400-1499/1417.Reformat%20The%20String/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1531", "frontend_question_id": "1434", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-ways-to-wear-different-hats-to-each-other", "url_en": "https://leetcode.com/problems/number-of-ways-to-wear-different-hats-to-each-other", "relative_path_cn": "/solution/1400-1499/1434.Number%20of%20Ways%20to%20Wear%20Different%20Hats%20to%20Each%20Other/README.md", "relative_path_en": "/solution/1400-1499/1434.Number%20of%20Ways%20to%20Wear%20Different%20Hats%20to%20Each%20Other/README_EN.md", "title_cn": "\u6bcf\u4e2a\u4eba\u6234\u4e0d\u540c\u5e3d\u5b50\u7684\u65b9\u6848\u6570", "title_en": "Number of Ways to Wear Different Hats to Each Other", "question_title_slug": "number-of-ways-to-wear-different-hats-to-each-other", "content_en": "

There are n people and 40 types of hats labeled from 1 to 40.

\r\n\r\n

Given a list of list of integers hats, where hats[i] is a list of all hats preferred by the i-th person.

\r\n\r\n

Return the number of ways that the n people wear different hats to each other.

\r\n\r\n

Since the answer may be too large, return it modulo 10^9 + 7.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: hats = [[3,4],[4,5],[5]]\r\nOutput: 1\r\nExplanation: There is only one way to choose hats given the conditions. \r\nFirst person choose hat 3, Second person choose hat 4 and last one hat 5.
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: hats = [[3,5,1],[3,5]]\r\nOutput: 4\r\nExplanation: There are 4 ways to choose hats\r\n(3,5), (5,3), (1,3) and (1,5)\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: hats = [[1,2,3,4],[1,2,3,4],[1,2,3,4],[1,2,3,4]]\r\nOutput: 24\r\nExplanation: Each person can choose hats labeled from 1 to 4.\r\nNumber of Permutations of (1,2,3,4) = 24.\r\n
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: hats = [[1,2,3],[2,3,5,6],[1,3,7,9],[1,8,9],[2,5,7]]\r\nOutput: 111\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • n == hats.length
  • \r\n\t
  • 1 <= n <= 10
  • \r\n\t
  • 1 <= hats[i].length <= 40
  • \r\n\t
  • 1 <= hats[i][j] <= 40
  • \r\n\t
  • hats[i] contains a list of unique integers.
  • \r\n
", "content_cn": "

\u603b\u5171\u6709 n \u4e2a\u4eba\u548c 40 \u79cd\u4e0d\u540c\u7684\u5e3d\u5b50\uff0c\u5e3d\u5b50\u7f16\u53f7\u4ece 1 \u5230 40 \u3002

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u5217\u8868\u7684\u5217\u8868 hats \uff0c\u5176\u4e2d hats[i] \u662f\u7b2c i \u4e2a\u4eba\u6240\u6709\u559c\u6b22\u5e3d\u5b50\u7684\u5217\u8868\u3002

\n\n

\u8bf7\u4f60\u7ed9\u6bcf\u4e2a\u4eba\u5b89\u6392\u4e00\u9876\u4ed6\u559c\u6b22\u7684\u5e3d\u5b50\uff0c\u786e\u4fdd\u6bcf\u4e2a\u4eba\u6234\u7684\u5e3d\u5b50\u8ddf\u522b\u4eba\u90fd\u4e0d\u4e00\u6837\uff0c\u5e76\u8fd4\u56de\u65b9\u6848\u6570\u3002

\n\n

\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u5f88\u5927\uff0c\u8bf7\u8fd4\u56de\u5b83\u5bf9 10^9 + 7 \u53d6\u4f59\u540e\u7684\u7ed3\u679c\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1ahats = [[3,4],[4,5],[5]]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u7ed9\u5b9a\u6761\u4ef6\u4e0b\u53ea\u6709\u4e00\u79cd\u65b9\u6cd5\u9009\u62e9\u5e3d\u5b50\u3002\n\u7b2c\u4e00\u4e2a\u4eba\u9009\u62e9\u5e3d\u5b50 3\uff0c\u7b2c\u4e8c\u4e2a\u4eba\u9009\u62e9\u5e3d\u5b50 4\uff0c\u6700\u540e\u4e00\u4e2a\u4eba\u9009\u62e9\u5e3d\u5b50 5\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1ahats = [[3,5,1],[3,5]]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u603b\u5171\u6709 4 \u79cd\u5b89\u6392\u5e3d\u5b50\u7684\u65b9\u6cd5\uff1a\n(3,5)\uff0c(5,3)\uff0c(1,3) \u548c (1,5)\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1ahats = [[1,2,3,4],[1,2,3,4],[1,2,3,4],[1,2,3,4]]\n\u8f93\u51fa\uff1a24\n\u89e3\u91ca\uff1a\u6bcf\u4e2a\u4eba\u90fd\u53ef\u4ee5\u4ece\u7f16\u53f7\u4e3a 1 \u5230 4 \u7684\u5e3d\u5b50\u4e2d\u9009\u3002\n(1,2,3,4) 4 \u4e2a\u5e3d\u5b50\u7684\u6392\u5217\u65b9\u6848\u6570\u4e3a 24 \u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1ahats = [[1,2,3],[2,3,5,6],[1,3,7,9],[1,8,9],[2,5,7]]\n\u8f93\u51fa\uff1a111\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • n == hats.length
  • \n\t
  • 1 <= n <= 10
  • \n\t
  • 1 <= hats[i].length <= 40
  • \n\t
  • 1 <= hats[i][j] <= 40
  • \n\t
  • hats[i] \u5305\u542b\u4e00\u4e2a\u6570\u5b57\u4e92\u4e0d\u76f8\u540c\u7684\u6574\u6570\u5217\u8868\u3002
  • \n
\n", "tags_en": ["Bit Manipulation", "Dynamic Programming"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numberWays(vector>& hats) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numberWays(List> hats) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numberWays(self, hats):\n \"\"\"\n :type hats: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numberWays(self, hats: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numberWays(int** hats, int hatsSize, int* hatsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumberWays(IList> hats) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} hats\n * @return {number}\n */\nvar numberWays = function(hats) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} hats\n# @return {Integer}\ndef number_ways(hats)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numberWays(_ hats: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numberWays(hats [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numberWays(hats: List[List[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numberWays(hats: List>): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn number_ways(hats: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $hats\n * @return Integer\n */\n function numberWays($hats) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numberWays(hats: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (number-ways hats)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1434](https://leetcode-cn.com/problems/number-of-ways-to-wear-different-hats-to-each-other)", "[\u6bcf\u4e2a\u4eba\u6234\u4e0d\u540c\u5e3d\u5b50\u7684\u65b9\u6848\u6570](/solution/1400-1499/1434.Number%20of%20Ways%20to%20Wear%20Different%20Hats%20to%20Each%20Other/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1434](https://leetcode.com/problems/number-of-ways-to-wear-different-hats-to-each-other)", "[Number of Ways to Wear Different Hats to Each Other](/solution/1400-1499/1434.Number%20of%20Ways%20to%20Wear%20Different%20Hats%20to%20Each%20Other/README_EN.md)", "`Bit Manipulation`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "1530", "frontend_question_id": "1433", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/check-if-a-string-can-break-another-string", "url_en": "https://leetcode.com/problems/check-if-a-string-can-break-another-string", "relative_path_cn": "/solution/1400-1499/1433.Check%20If%20a%20String%20Can%20Break%20Another%20String/README.md", "relative_path_en": "/solution/1400-1499/1433.Check%20If%20a%20String%20Can%20Break%20Another%20String/README_EN.md", "title_cn": "\u68c0\u67e5\u4e00\u4e2a\u5b57\u7b26\u4e32\u662f\u5426\u53ef\u4ee5\u6253\u7834\u53e6\u4e00\u4e2a\u5b57\u7b26\u4e32", "title_en": "Check If a String Can Break Another String", "question_title_slug": "check-if-a-string-can-break-another-string", "content_en": "

Given two strings: s1 and s2 with the same size, check if some permutation of string s1 can break some permutation of string s2 or vice-versa. In other words s2 can break s1 or vice-versa.

\n\n

A string x can break string y (both of size n) if x[i] >= y[i] (in alphabetical order) for all i between 0 and n-1.

\n\n

 

\n

Example 1:

\n\n
\nInput: s1 = "abc", s2 = "xya"\nOutput: true\nExplanation: "ayx" is a permutation of s2="xya" which can break to string "abc" which is a permutation of s1="abc".\n
\n\n

Example 2:

\n\n
\nInput: s1 = "abe", s2 = "acd"\nOutput: false \nExplanation: All permutations for s1="abe" are: "abe", "aeb", "bae", "bea", "eab" and "eba" and all permutation for s2="acd" are: "acd", "adc", "cad", "cda", "dac" and "dca". However, there is not any permutation from s1 which can break some permutation from s2 and vice-versa.\n
\n\n

Example 3:

\n\n
\nInput: s1 = "leetcodee", s2 = "interview"\nOutput: true\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • s1.length == n
  • \n\t
  • s2.length == n
  • \n\t
  • 1 <= n <= 10^5
  • \n\t
  • All strings consist of lowercase English letters.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e24\u4e2a\u5b57\u7b26\u4e32 s1 \u548c s2 \uff0c\u5b83\u4eec\u957f\u5ea6\u76f8\u7b49\uff0c\u8bf7\u4f60\u68c0\u67e5\u662f\u5426\u5b58\u5728\u4e00\u4e2a s1  \u7684\u6392\u5217\u53ef\u4ee5\u6253\u7834 s2 \u7684\u4e00\u4e2a\u6392\u5217\uff0c\u6216\u8005\u662f\u5426\u5b58\u5728\u4e00\u4e2a s2 \u7684\u6392\u5217\u53ef\u4ee5\u6253\u7834 s1 \u7684\u4e00\u4e2a\u6392\u5217\u3002

\n\n

\u5b57\u7b26\u4e32 x \u53ef\u4ee5\u6253\u7834\u5b57\u7b26\u4e32 y \uff08\u4e24\u8005\u957f\u5ea6\u90fd\u4e3a n \uff09\u9700\u6ee1\u8db3\u5bf9\u4e8e\u6240\u6709 i\uff08\u5728 0 \u5230 n - 1 \u4e4b\u95f4\uff09\u90fd\u6709 x[i] >= y[i]\uff08\u5b57\u5178\u5e8f\u610f\u4e49\u4e0b\u7684\u987a\u5e8f\uff09\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1as1 = "abc", s2 = "xya"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a"ayx" \u662f s2="xya" \u7684\u4e00\u4e2a\u6392\u5217\uff0c"abc" \u662f\u5b57\u7b26\u4e32 s1="abc" \u7684\u4e00\u4e2a\u6392\u5217\uff0c\u4e14 "ayx" \u53ef\u4ee5\u6253\u7834 "abc" \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1as1 = "abe", s2 = "acd"\n\u8f93\u51fa\uff1afalse \n\u89e3\u91ca\uff1as1="abe" \u7684\u6240\u6709\u6392\u5217\u5305\u62ec\uff1a"abe"\uff0c"aeb"\uff0c"bae"\uff0c"bea"\uff0c"eab" \u548c "eba" \uff0cs2="acd" \u7684\u6240\u6709\u6392\u5217\u5305\u62ec\uff1a"acd"\uff0c"adc"\uff0c"cad"\uff0c"cda"\uff0c"dac" \u548c "dca"\u3002\u7136\u800c\u6ca1\u6709\u4efb\u4f55 s1 \u7684\u6392\u5217\u53ef\u4ee5\u6253\u7834 s2 \u7684\u6392\u5217\u3002\u4e5f\u6ca1\u6709 s2 \u7684\u6392\u5217\u80fd\u6253\u7834 s1 \u7684\u6392\u5217\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1as1 = "leetcodee", s2 = "interview"\n\u8f93\u51fa\uff1atrue\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • s1.length == n
  • \n\t
  • s2.length == n
  • \n\t
  • 1 <= n <= 10^5
  • \n\t
  • \u6240\u6709\u5b57\u7b26\u4e32\u90fd\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
  • \n
\n", "tags_en": ["Greedy", "String"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool checkIfCanBreak(string s1, string s2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean checkIfCanBreak(String s1, String s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def checkIfCanBreak(self, s1, s2):\n \"\"\"\n :type s1: str\n :type s2: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def checkIfCanBreak(self, s1: str, s2: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool checkIfCanBreak(char * s1, char * s2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CheckIfCanBreak(string s1, string s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s1\n * @param {string} s2\n * @return {boolean}\n */\nvar checkIfCanBreak = function(s1, s2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s1\n# @param {String} s2\n# @return {Boolean}\ndef check_if_can_break(s1, s2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func checkIfCanBreak(_ s1: String, _ s2: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func checkIfCanBreak(s1 string, s2 string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def checkIfCanBreak(s1: String, s2: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun checkIfCanBreak(s1: String, s2: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn check_if_can_break(s1: String, s2: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s1\n * @param String $s2\n * @return Boolean\n */\n function checkIfCanBreak($s1, $s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function checkIfCanBreak(s1: string, s2: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (check-if-can-break s1 s2)\n (-> string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1433](https://leetcode-cn.com/problems/check-if-a-string-can-break-another-string)", "[\u68c0\u67e5\u4e00\u4e2a\u5b57\u7b26\u4e32\u662f\u5426\u53ef\u4ee5\u6253\u7834\u53e6\u4e00\u4e2a\u5b57\u7b26\u4e32](/solution/1400-1499/1433.Check%20If%20a%20String%20Can%20Break%20Another%20String/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1433](https://leetcode.com/problems/check-if-a-string-can-break-another-string)", "[Check If a String Can Break Another String](/solution/1400-1499/1433.Check%20If%20a%20String%20Can%20Break%20Another%20String/README_EN.md)", "`Greedy`,`String`", "Medium", ""]}, {"question_id": "1529", "frontend_question_id": "1432", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/max-difference-you-can-get-from-changing-an-integer", "url_en": "https://leetcode.com/problems/max-difference-you-can-get-from-changing-an-integer", "relative_path_cn": "/solution/1400-1499/1432.Max%20Difference%20You%20Can%20Get%20From%20Changing%20an%20Integer/README.md", "relative_path_en": "/solution/1400-1499/1432.Max%20Difference%20You%20Can%20Get%20From%20Changing%20an%20Integer/README_EN.md", "title_cn": "\u6539\u53d8\u4e00\u4e2a\u6574\u6570\u80fd\u5f97\u5230\u7684\u6700\u5927\u5dee\u503c", "title_en": "Max Difference You Can Get From Changing an Integer", "question_title_slug": "max-difference-you-can-get-from-changing-an-integer", "content_en": "

You are given an integer num. You will apply the following steps exactly two times:

\n\n
    \n\t
  • Pick a digit x (0 <= x <= 9).
  • \n\t
  • Pick another digit y (0 <= y <= 9). The digit y can be equal to x.
  • \n\t
  • Replace all the occurrences of x in the decimal representation of num by y.
  • \n\t
  • The new integer cannot have any leading zeros, also the new integer cannot be 0.
  • \n
\n\n

Let a and b be the results of applying the operations to num the first and second times, respectively.

\n\n

Return the max difference between a and b.

\n\n

 

\n

Example 1:

\n\n
\nInput: num = 555\nOutput: 888\nExplanation: The first time pick x = 5 and y = 9 and store the new integer in a.\nThe second time pick x = 5 and y = 1 and store the new integer in b.\nWe have now a = 999 and b = 111 and max difference = 888\n
\n\n

Example 2:

\n\n
\nInput: num = 9\nOutput: 8\nExplanation: The first time pick x = 9 and y = 9 and store the new integer in a.\nThe second time pick x = 9 and y = 1 and store the new integer in b.\nWe have now a = 9 and b = 1 and max difference = 8\n
\n\n

Example 3:

\n\n
\nInput: num = 123456\nOutput: 820000\n
\n\n

Example 4:

\n\n
\nInput: num = 10000\nOutput: 80000\n
\n\n

Example 5:

\n\n
\nInput: num = 9288\nOutput: 8700\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= num <= 10^8
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 num \u3002\u4f60\u53ef\u4ee5\u5bf9\u5b83\u8fdb\u884c\u5982\u4e0b\u6b65\u9aa4\u6070\u597d \u4e24\u6b21 \uff1a

\n\n
    \n\t
  • \u9009\u62e9\u4e00\u4e2a\u6570\u5b57 x (0 <= x <= 9).
  • \n\t
  • \u9009\u62e9\u53e6\u4e00\u4e2a\u6570\u5b57 y (0 <= y <= 9) \u3002\u6570\u5b57 y \u53ef\u4ee5\u7b49\u4e8e x \u3002
  • \n\t
  • \u5c06 num \u4e2d\u6240\u6709\u51fa\u73b0 x \u7684\u6570\u4f4d\u90fd\u7528 y \u66ff\u6362\u3002
  • \n\t
  • \u5f97\u5230\u7684\u65b0\u7684\u6574\u6570 \u4e0d\u80fd \u6709\u524d\u5bfc 0 \uff0c\u5f97\u5230\u7684\u65b0\u6574\u6570\u4e5f \u4e0d\u80fd \u662f 0 \u3002
  • \n
\n\n

\u4ee4\u4e24\u6b21\u5bf9 num \u7684\u64cd\u4f5c\u5f97\u5230\u7684\u7ed3\u679c\u5206\u522b\u4e3a a \u548c b \u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de a \u548c b \u7684 \u6700\u5927\u5dee\u503c \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anum = 555\n\u8f93\u51fa\uff1a888\n\u89e3\u91ca\uff1a\u7b2c\u4e00\u6b21\u9009\u62e9 x = 5 \u4e14 y = 9 \uff0c\u5e76\u628a\u5f97\u5230\u7684\u65b0\u6570\u5b57\u4fdd\u5b58\u5728 a \u4e2d\u3002\n\u7b2c\u4e8c\u6b21\u9009\u62e9 x = 5 \u4e14 y = 1 \uff0c\u5e76\u628a\u5f97\u5230\u7684\u65b0\u6570\u5b57\u4fdd\u5b58\u5728 b \u4e2d\u3002\n\u73b0\u5728\uff0c\u6211\u4eec\u6709 a = 999 \u548c b = 111 \uff0c\u6700\u5927\u5dee\u503c\u4e3a 888\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anum = 9\n\u8f93\u51fa\uff1a8\n\u89e3\u91ca\uff1a\u7b2c\u4e00\u6b21\u9009\u62e9 x = 9 \u4e14 y = 9 \uff0c\u5e76\u628a\u5f97\u5230\u7684\u65b0\u6570\u5b57\u4fdd\u5b58\u5728 a \u4e2d\u3002\n\u7b2c\u4e8c\u6b21\u9009\u62e9 x = 9 \u4e14 y = 1 \uff0c\u5e76\u628a\u5f97\u5230\u7684\u65b0\u6570\u5b57\u4fdd\u5b58\u5728 b \u4e2d\u3002\n\u73b0\u5728\uff0c\u6211\u4eec\u6709 a = 9 \u548c b = 1 \uff0c\u6700\u5927\u5dee\u503c\u4e3a 8\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1anum = 123456\n\u8f93\u51fa\uff1a820000\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1anum = 10000\n\u8f93\u51fa\uff1a80000\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1anum = 9288\n\u8f93\u51fa\uff1a8700\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= num <= 10^8
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxDiff(int num) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxDiff(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxDiff(self, num):\n \"\"\"\n :type num: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxDiff(self, num: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxDiff(int num){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxDiff(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} num\n * @return {number}\n */\nvar maxDiff = function(num) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} num\n# @return {Integer}\ndef max_diff(num)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxDiff(_ num: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxDiff(num int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxDiff(num: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxDiff(num: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_diff(num: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $num\n * @return Integer\n */\n function maxDiff($num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxDiff(num: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-diff num)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1432](https://leetcode-cn.com/problems/max-difference-you-can-get-from-changing-an-integer)", "[\u6539\u53d8\u4e00\u4e2a\u6574\u6570\u80fd\u5f97\u5230\u7684\u6700\u5927\u5dee\u503c](/solution/1400-1499/1432.Max%20Difference%20You%20Can%20Get%20From%20Changing%20an%20Integer/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1432](https://leetcode.com/problems/max-difference-you-can-get-from-changing-an-integer)", "[Max Difference You Can Get From Changing an Integer](/solution/1400-1499/1432.Max%20Difference%20You%20Can%20Get%20From%20Changing%20an%20Integer/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "1528", "frontend_question_id": "1431", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/kids-with-the-greatest-number-of-candies", "url_en": "https://leetcode.com/problems/kids-with-the-greatest-number-of-candies", "relative_path_cn": "/solution/1400-1499/1431.Kids%20With%20the%20Greatest%20Number%20of%20Candies/README.md", "relative_path_en": "/solution/1400-1499/1431.Kids%20With%20the%20Greatest%20Number%20of%20Candies/README_EN.md", "title_cn": "\u62e5\u6709\u6700\u591a\u7cd6\u679c\u7684\u5b69\u5b50", "title_en": "Kids With the Greatest Number of Candies", "question_title_slug": "kids-with-the-greatest-number-of-candies", "content_en": "

Given the array candies and the integer extraCandies, where candies[i] represents the number of candies that the ith kid has.

\n\n

For each kid check if there is a way to distribute extraCandies among the kids such that he or she can have the greatest number of candies among them. Notice that multiple kids can have the greatest number of candies.

\n\n

 

\n

Example 1:

\n\n
\nInput: candies = [2,3,5,1,3], extraCandies = 3\nOutput: [true,true,true,false,true] \nExplanation: \nKid 1 has 2 candies and if he or she receives all extra candies (3) will have 5 candies --- the greatest number of candies among the kids. \nKid 2 has 3 candies and if he or she receives at least 2 extra candies will have the greatest number of candies among the kids. \nKid 3 has 5 candies and this is already the greatest number of candies among the kids. \nKid 4 has 1 candy and even if he or she receives all extra candies will only have 4 candies. \nKid 5 has 3 candies and if he or she receives at least 2 extra candies will have the greatest number of candies among the kids. \n
\n\n

Example 2:

\n\n
\nInput: candies = [4,2,1,1,2], extraCandies = 1\nOutput: [true,false,false,false,false] \nExplanation: There is only 1 extra candy, therefore only kid 1 will have the greatest number of candies among the kids regardless of who takes the extra candy.\n
\n\n

Example 3:

\n\n
\nInput: candies = [12,1,12], extraCandies = 10\nOutput: [true,false,true]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= candies.length <= 100
  • \n\t
  • 1 <= candies[i] <= 100
  • \n\t
  • 1 <= extraCandies <= 50
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 candies \u548c\u4e00\u4e2a\u6574\u6570 extraCandies \uff0c\u5176\u4e2d candies[i] \u4ee3\u8868\u7b2c i \u4e2a\u5b69\u5b50\u62e5\u6709\u7684\u7cd6\u679c\u6570\u76ee\u3002

\n\n

\u5bf9\u6bcf\u4e00\u4e2a\u5b69\u5b50\uff0c\u68c0\u67e5\u662f\u5426\u5b58\u5728\u4e00\u79cd\u65b9\u6848\uff0c\u5c06\u989d\u5916\u7684 extraCandies \u4e2a\u7cd6\u679c\u5206\u914d\u7ed9\u5b69\u5b50\u4eec\u4e4b\u540e\uff0c\u6b64\u5b69\u5b50\u6709 \u6700\u591a \u7684\u7cd6\u679c\u3002\u6ce8\u610f\uff0c\u5141\u8bb8\u6709\u591a\u4e2a\u5b69\u5b50\u540c\u65f6\u62e5\u6709 \u6700\u591a \u7684\u7cd6\u679c\u6570\u76ee\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1acandies = [2,3,5,1,3], extraCandies = 3\n\u8f93\u51fa\uff1a[true,true,true,false,true] \n\u89e3\u91ca\uff1a\n\u5b69\u5b50 1 \u6709 2 \u4e2a\u7cd6\u679c\uff0c\u5982\u679c\u4ed6\u5f97\u5230\u6240\u6709\u989d\u5916\u7684\u7cd6\u679c\uff083\u4e2a\uff09\uff0c\u90a3\u4e48\u4ed6\u603b\u5171\u6709 5 \u4e2a\u7cd6\u679c\uff0c\u4ed6\u5c06\u6210\u4e3a\u62e5\u6709\u6700\u591a\u7cd6\u679c\u7684\u5b69\u5b50\u3002\n\u5b69\u5b50 2 \u6709 3 \u4e2a\u7cd6\u679c\uff0c\u5982\u679c\u4ed6\u5f97\u5230\u81f3\u5c11 2 \u4e2a\u989d\u5916\u7cd6\u679c\uff0c\u90a3\u4e48\u4ed6\u5c06\u6210\u4e3a\u62e5\u6709\u6700\u591a\u7cd6\u679c\u7684\u5b69\u5b50\u3002\n\u5b69\u5b50 3 \u6709 5 \u4e2a\u7cd6\u679c\uff0c\u4ed6\u5df2\u7ecf\u662f\u62e5\u6709\u6700\u591a\u7cd6\u679c\u7684\u5b69\u5b50\u3002\n\u5b69\u5b50 4 \u6709 1 \u4e2a\u7cd6\u679c\uff0c\u5373\u4f7f\u4ed6\u5f97\u5230\u6240\u6709\u989d\u5916\u7684\u7cd6\u679c\uff0c\u4ed6\u4e5f\u53ea\u6709 4 \u4e2a\u7cd6\u679c\uff0c\u65e0\u6cd5\u6210\u4e3a\u62e5\u6709\u7cd6\u679c\u6700\u591a\u7684\u5b69\u5b50\u3002\n\u5b69\u5b50 5 \u6709 3 \u4e2a\u7cd6\u679c\uff0c\u5982\u679c\u4ed6\u5f97\u5230\u81f3\u5c11 2 \u4e2a\u989d\u5916\u7cd6\u679c\uff0c\u90a3\u4e48\u4ed6\u5c06\u6210\u4e3a\u62e5\u6709\u6700\u591a\u7cd6\u679c\u7684\u5b69\u5b50\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1acandies = [4,2,1,1,2], extraCandies = 1\n\u8f93\u51fa\uff1a[true,false,false,false,false] \n\u89e3\u91ca\uff1a\u53ea\u6709 1 \u4e2a\u989d\u5916\u7cd6\u679c\uff0c\u6240\u4ee5\u4e0d\u7ba1\u989d\u5916\u7cd6\u679c\u7ed9\u8c01\uff0c\u53ea\u6709\u5b69\u5b50 1 \u53ef\u4ee5\u6210\u4e3a\u62e5\u6709\u7cd6\u679c\u6700\u591a\u7684\u5b69\u5b50\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1acandies = [12,1,12], extraCandies = 10\n\u8f93\u51fa\uff1a[true,false,true]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= candies.length <= 100
  • \n\t
  • 1 <= candies[i] <= 100
  • \n\t
  • 1 <= extraCandies <= 50
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector kidsWithCandies(vector& candies, int extraCandies) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List kidsWithCandies(int[] candies, int extraCandies) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def kidsWithCandies(self, candies, extraCandies):\n \"\"\"\n :type candies: List[int]\n :type extraCandies: int\n :rtype: List[bool]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def kidsWithCandies(self, candies: List[int], extraCandies: int) -> List[bool]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nbool* kidsWithCandies(int* candies, int candiesSize, int extraCandies, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList KidsWithCandies(int[] candies, int extraCandies) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} candies\n * @param {number} extraCandies\n * @return {boolean[]}\n */\nvar kidsWithCandies = function(candies, extraCandies) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} candies\n# @param {Integer} extra_candies\n# @return {Boolean[]}\ndef kids_with_candies(candies, extra_candies)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func kidsWithCandies(_ candies: [Int], _ extraCandies: Int) -> [Bool] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func kidsWithCandies(candies []int, extraCandies int) []bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def kidsWithCandies(candies: Array[Int], extraCandies: Int): List[Boolean] = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun kidsWithCandies(candies: IntArray, extraCandies: Int): List {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn kids_with_candies(candies: Vec, extra_candies: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $candies\n * @param Integer $extraCandies\n * @return Boolean[]\n */\n function kidsWithCandies($candies, $extraCandies) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function kidsWithCandies(candies: number[], extraCandies: number): boolean[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (kids-with-candies candies extraCandies)\n (-> (listof exact-integer?) exact-integer? (listof boolean?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1431](https://leetcode-cn.com/problems/kids-with-the-greatest-number-of-candies)", "[\u62e5\u6709\u6700\u591a\u7cd6\u679c\u7684\u5b69\u5b50](/solution/1400-1499/1431.Kids%20With%20the%20Greatest%20Number%20of%20Candies/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1431](https://leetcode.com/problems/kids-with-the-greatest-number-of-candies)", "[Kids With the Greatest Number of Candies](/solution/1400-1499/1431.Kids%20With%20the%20Greatest%20Number%20of%20Candies/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1527", "frontend_question_id": "1411", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-ways-to-paint-n-3-grid", "url_en": "https://leetcode.com/problems/number-of-ways-to-paint-n-3-grid", "relative_path_cn": "/solution/1400-1499/1411.Number%20of%20Ways%20to%20Paint%20N%20%C3%97%203%20Grid/README.md", "relative_path_en": "/solution/1400-1499/1411.Number%20of%20Ways%20to%20Paint%20N%20%C3%97%203%20Grid/README_EN.md", "title_cn": "\u7ed9 N x 3 \u7f51\u683c\u56fe\u6d82\u8272\u7684\u65b9\u6848\u6570", "title_en": "Number of Ways to Paint N \u00d7 3 Grid", "question_title_slug": "number-of-ways-to-paint-n-3-grid", "content_en": "

You have a grid of size n x 3 and you want to paint each cell of the grid with exactly one of the three colors: Red, Yellow, or Green while making sure that no two adjacent cells have the same color (i.e., no two cells that share vertical or horizontal sides have the same color).

\n\n

Given n the number of rows of the grid, return the number of ways you can paint this grid. As the answer may grow large, the answer must be computed modulo 109 + 7.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: n = 1\nOutput: 12\nExplanation: There are 12 possible way to paint the grid as shown.\n
\n\n

Example 2:

\n\n
\nInput: n = 2\nOutput: 54\n
\n\n

Example 3:

\n\n
\nInput: n = 3\nOutput: 246\n
\n\n

Example 4:

\n\n
\nInput: n = 7\nOutput: 106494\n
\n\n

Example 5:

\n\n
\nInput: n = 5000\nOutput: 30228214\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == grid.length
  • \n\t
  • grid[i].length == 3
  • \n\t
  • 1 <= n <= 5000
  • \n
\n", "content_cn": "

\u4f60\u6709\u4e00\u4e2a n x 3 \u7684\u7f51\u683c\u56fe grid \uff0c\u4f60\u9700\u8981\u7528 \u7ea2\uff0c\u9ec4\uff0c\u7eff \u4e09\u79cd\u989c\u8272\u4e4b\u4e00\u7ed9\u6bcf\u4e00\u4e2a\u683c\u5b50\u4e0a\u8272\uff0c\u4e14\u786e\u4fdd\u76f8\u90bb\u683c\u5b50\u989c\u8272\u4e0d\u540c\uff08\u4e5f\u5c31\u662f\u6709\u76f8\u540c\u6c34\u5e73\u8fb9\u6216\u8005\u5782\u76f4\u8fb9\u7684\u683c\u5b50\u989c\u8272\u4e0d\u540c\uff09\u3002

\n\n

\u7ed9\u4f60\u7f51\u683c\u56fe\u7684\u884c\u6570 n \u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u7ed9 grid \u6d82\u8272\u7684\u65b9\u6848\u6570\u3002\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u4f1a\u975e\u5e38\u5927\uff0c\u8bf7\u4f60\u8fd4\u56de\u7b54\u6848\u5bf9 10^9 + 7 \u53d6\u4f59\u7684\u7ed3\u679c\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1a12\n\u89e3\u91ca\uff1a\u603b\u5171\u6709 12 \u79cd\u53ef\u884c\u7684\u65b9\u6cd5\uff1a\n\"\"\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1an = 2\n\u8f93\u51fa\uff1a54\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1an = 3\n\u8f93\u51fa\uff1a246\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1an = 7\n\u8f93\u51fa\uff1a106494\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1an = 5000\n\u8f93\u51fa\uff1a30228214\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • n == grid.length
  • \n\t
  • grid[i].length == 3
  • \n\t
  • 1 <= n <= 5000
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numOfWays(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numOfWays(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numOfWays(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numOfWays(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numOfWays(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumOfWays(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar numOfWays = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef num_of_ways(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numOfWays(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numOfWays(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numOfWays(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numOfWays(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_of_ways(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function numOfWays($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numOfWays(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-of-ways n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1411](https://leetcode-cn.com/problems/number-of-ways-to-paint-n-3-grid)", "[\u7ed9 N x 3 \u7f51\u683c\u56fe\u6d82\u8272\u7684\u65b9\u6848\u6570](/solution/1400-1499/1411.Number%20of%20Ways%20to%20Paint%20N%20%C3%97%203%20Grid/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1411](https://leetcode.com/problems/number-of-ways-to-paint-n-3-grid)", "[Number of Ways to Paint N \u00d7 3 Grid](/solution/1400-1499/1411.Number%20of%20Ways%20to%20Paint%20N%20%C3%97%203%20Grid/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1526", "frontend_question_id": "1410", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/html-entity-parser", "url_en": "https://leetcode.com/problems/html-entity-parser", "relative_path_cn": "/solution/1400-1499/1410.HTML%20Entity%20Parser/README.md", "relative_path_en": "/solution/1400-1499/1410.HTML%20Entity%20Parser/README_EN.md", "title_cn": "HTML \u5b9e\u4f53\u89e3\u6790\u5668", "title_en": "HTML Entity Parser", "question_title_slug": "html-entity-parser", "content_en": "

HTML entity parser is the parser that takes HTML code as input and replace all the entities of the special characters by the characters itself.

\n\n

The special characters and their entities for HTML are:

\n\n
    \n\t
  • Quotation Mark: the entity is &quot; and symbol character is ".
  • \n\t
  • Single Quote Mark: the entity is &apos; and symbol character is '.
  • \n\t
  • Ampersand: the entity is &amp; and symbol character is &.
  • \n\t
  • Greater Than Sign: the entity is &gt; and symbol character is >.
  • \n\t
  • Less Than Sign: the entity is &lt; and symbol character is <.
  • \n\t
  • Slash: the entity is &frasl; and symbol character is /.
  • \n
\n\n

Given the input text string to the HTML parser, you have to implement the entity parser.

\n\n

Return the text after replacing the entities by the special characters.

\n\n

 

\n

Example 1:

\n\n
\nInput: text = "&amp; is an HTML entity but &ambassador; is not."\nOutput: "& is an HTML entity but &ambassador; is not."\nExplanation: The parser will replace the &amp; entity by &\n
\n\n

Example 2:

\n\n
\nInput: text = "and I quote: &quot;...&quot;"\nOutput: "and I quote: \\"...\\""\n
\n\n

Example 3:

\n\n
\nInput: text = "Stay home! Practice on Leetcode :)"\nOutput: "Stay home! Practice on Leetcode :)"\n
\n\n

Example 4:

\n\n
\nInput: text = "x &gt; y &amp;&amp; x &lt; y is always false"\nOutput: "x > y && x < y is always false"\n
\n\n

Example 5:

\n\n
\nInput: text = "leetcode.com&frasl;problemset&frasl;all"\nOutput: "leetcode.com/problemset/all"\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= text.length <= 10^5
  • \n\t
  • The string may contain any possible characters out of all the 256 ASCII characters.
  • \n
\n", "content_cn": "

\u300cHTML \u5b9e\u4f53\u89e3\u6790\u5668\u300d \u662f\u4e00\u79cd\u7279\u6b8a\u7684\u89e3\u6790\u5668\uff0c\u5b83\u5c06 HTML \u4ee3\u7801\u4f5c\u4e3a\u8f93\u5165\uff0c\u5e76\u7528\u5b57\u7b26\u672c\u8eab\u66ff\u6362\u6389\u6240\u6709\u8fd9\u4e9b\u7279\u6b8a\u7684\u5b57\u7b26\u5b9e\u4f53\u3002

\n\n

HTML \u91cc\u8fd9\u4e9b\u7279\u6b8a\u5b57\u7b26\u548c\u5b83\u4eec\u5bf9\u5e94\u7684\u5b57\u7b26\u5b9e\u4f53\u5305\u62ec\uff1a

\n\n
    \n\t
  • \u53cc\u5f15\u53f7\uff1a\u5b57\u7b26\u5b9e\u4f53\u4e3a &quot; \uff0c\u5bf9\u5e94\u7684\u5b57\u7b26\u662f " \u3002
  • \n\t
  • \u5355\u5f15\u53f7\uff1a\u5b57\u7b26\u5b9e\u4f53\u4e3a &apos; \uff0c\u5bf9\u5e94\u7684\u5b57\u7b26\u662f ' \u3002
  • \n\t
  • \u4e0e\u7b26\u53f7\uff1a\u5b57\u7b26\u5b9e\u4f53\u4e3a &amp; \uff0c\u5bf9\u5e94\u5bf9\u7684\u5b57\u7b26\u662f & \u3002
  • \n\t
  • \u5927\u4e8e\u53f7\uff1a\u5b57\u7b26\u5b9e\u4f53\u4e3a &gt; \uff0c\u5bf9\u5e94\u7684\u5b57\u7b26\u662f > \u3002
  • \n\t
  • \u5c0f\u4e8e\u53f7\uff1a\u5b57\u7b26\u5b9e\u4f53\u4e3a &lt; \uff0c\u5bf9\u5e94\u7684\u5b57\u7b26\u662f < \u3002
  • \n\t
  • \u659c\u7ebf\u53f7\uff1a\u5b57\u7b26\u5b9e\u4f53\u4e3a &frasl; \uff0c\u5bf9\u5e94\u7684\u5b57\u7b26\u662f / \u3002
  • \n
\n\n

\u7ed9\u4f60\u8f93\u5165\u5b57\u7b26\u4e32 text \uff0c\u8bf7\u4f60\u5b9e\u73b0\u4e00\u4e2a HTML \u5b9e\u4f53\u89e3\u6790\u5668\uff0c\u8fd4\u56de\u89e3\u6790\u5668\u89e3\u6790\u540e\u7684\u7ed3\u679c\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1atext = "&amp; is an HTML entity but &ambassador; is not."\n\u8f93\u51fa\uff1a"& is an HTML entity but &ambassador; is not."\n\u89e3\u91ca\uff1a\u89e3\u6790\u5668\u628a\u5b57\u7b26\u5b9e\u4f53 &amp; \u7528 & \u66ff\u6362\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1atext = "and I quote: &quot;...&quot;"\n\u8f93\u51fa\uff1a"and I quote: \\"...\\""\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1atext = "Stay home! Practice on Leetcode :)"\n\u8f93\u51fa\uff1a"Stay home! Practice on Leetcode :)"\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1atext = "x &gt; y &amp;&amp; x &lt; y is always false"\n\u8f93\u51fa\uff1a"x > y && x < y is always false"\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\n\u8f93\u5165\uff1atext = "leetcode.com&frasl;problemset&frasl;all"\n\u8f93\u51fa\uff1a"leetcode.com/problemset/all"\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= text.length <= 10^5
  • \n\t
  • \u5b57\u7b26\u4e32\u53ef\u80fd\u5305\u542b 256 \u4e2aASCII \u5b57\u7b26\u4e2d\u7684\u4efb\u610f\u5b57\u7b26\u3002
  • \n
\n", "tags_en": ["Stack", "String"], "tags_cn": ["\u6808", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string entityParser(string text) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String entityParser(String text) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def entityParser(self, text):\n \"\"\"\n :type text: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def entityParser(self, text: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * entityParser(char * text){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string EntityParser(string text) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} text\n * @return {string}\n */\nvar entityParser = function(text) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} text\n# @return {String}\ndef entity_parser(text)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func entityParser(_ text: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func entityParser(text string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def entityParser(text: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun entityParser(text: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn entity_parser(text: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $text\n * @return String\n */\n function entityParser($text) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function entityParser(text: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (entity-parser text)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1410](https://leetcode-cn.com/problems/html-entity-parser)", "[HTML \u5b9e\u4f53\u89e3\u6790\u5668](/solution/1400-1499/1410.HTML%20Entity%20Parser/README.md)", "`\u6808`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1410](https://leetcode.com/problems/html-entity-parser)", "[HTML Entity Parser](/solution/1400-1499/1410.HTML%20Entity%20Parser/README_EN.md)", "`Stack`,`String`", "Medium", ""]}, {"question_id": "1525", "frontend_question_id": "1409", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/queries-on-a-permutation-with-key", "url_en": "https://leetcode.com/problems/queries-on-a-permutation-with-key", "relative_path_cn": "/solution/1400-1499/1409.Queries%20on%20a%20Permutation%20With%20Key/README.md", "relative_path_en": "/solution/1400-1499/1409.Queries%20on%20a%20Permutation%20With%20Key/README_EN.md", "title_cn": "\u67e5\u8be2\u5e26\u952e\u7684\u6392\u5217", "title_en": "Queries on a Permutation With Key", "question_title_slug": "queries-on-a-permutation-with-key", "content_en": "

Given the array queries of positive integers between 1 and m, you have to process all queries[i] (from i=0 to i=queries.length-1) according to the following rules:

\r\n\r\n
    \r\n\t
  • In the beginning, you have the permutation P=[1,2,3,...,m].
  • \r\n\t
  • For the current i, find the position of queries[i] in the permutation P (indexing from 0) and then move this at the beginning of the permutation P. Notice that the position of queries[i] in P is the result for queries[i].
  • \r\n
\r\n\r\n

Return an array containing the result for the given queries.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: queries = [3,1,2,1], m = 5\r\nOutput: [2,1,2,1] \r\nExplanation: The queries are processed as follow: \r\nFor i=0: queries[i]=3, P=[1,2,3,4,5], position of 3 in P is 2, then we move 3 to the beginning of P resulting in P=[3,1,2,4,5]. \r\nFor i=1: queries[i]=1, P=[3,1,2,4,5], position of 1 in P is 1, then we move 1 to the beginning of P resulting in P=[1,3,2,4,5]. \r\nFor i=2: queries[i]=2, P=[1,3,2,4,5], position of 2 in P is 2, then we move 2 to the beginning of P resulting in P=[2,1,3,4,5]. \r\nFor i=3: queries[i]=1, P=[2,1,3,4,5], position of 1 in P is 1, then we move 1 to the beginning of P resulting in P=[1,2,3,4,5]. \r\nTherefore, the array containing the result is [2,1,2,1].  \r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: queries = [4,1,2,2], m = 4\r\nOutput: [3,1,2,0]\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: queries = [7,5,5,8,3], m = 8\r\nOutput: [6,5,0,7,5]\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= m <= 10^3
  • \r\n\t
  • 1 <= queries.length <= m
  • \r\n\t
  • 1 <= queries[i] <= m
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5f85\u67e5\u6570\u7ec4 queries \uff0c\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u4e3a 1 \u5230 m \u4e4b\u95f4\u7684\u6b63\u6574\u6570\u3002 \u8bf7\u4f60\u6839\u636e\u4ee5\u4e0b\u89c4\u5219\u5904\u7406\u6240\u6709\u5f85\u67e5\u9879 queries[i]\uff08\u4ece i=0 \u5230 i=queries.length-1\uff09\uff1a

\n\n
    \n\t
  • \u4e00\u5f00\u59cb\uff0c\u6392\u5217 P=[1,2,3,...,m]\u3002
  • \n\t
  • \u5bf9\u4e8e\u5f53\u524d\u7684 i \uff0c\u8bf7\u4f60\u627e\u51fa\u5f85\u67e5\u9879 queries[i] \u5728\u6392\u5217 P \u4e2d\u7684\u4f4d\u7f6e\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\uff0c\u7136\u540e\u5c06\u5176\u4ece\u539f\u4f4d\u7f6e\u79fb\u52a8\u5230\u6392\u5217 P \u7684\u8d77\u59cb\u4f4d\u7f6e\uff08\u5373\u4e0b\u6807\u4e3a 0 \u5904\uff09\u3002\u6ce8\u610f\uff0c queries[i] \u5728 P \u4e2d\u7684\u4f4d\u7f6e\u5c31\u662f queries[i] \u7684\u67e5\u8be2\u7ed3\u679c\u3002
  • \n
\n\n

\u8bf7\u4f60\u4ee5\u6570\u7ec4\u5f62\u5f0f\u8fd4\u56de\u5f85\u67e5\u6570\u7ec4  queries \u7684\u67e5\u8be2\u7ed3\u679c\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aqueries = [3,1,2,1], m = 5\n\u8f93\u51fa\uff1a[2,1,2,1] \n\u89e3\u91ca\uff1a\u5f85\u67e5\u6570\u7ec4 queries \u5904\u7406\u5982\u4e0b\uff1a\n\u5bf9\u4e8e i=0: queries[i]=3, P=[1,2,3,4,5], 3 \u5728 P \u4e2d\u7684\u4f4d\u7f6e\u662f 2\uff0c\u63a5\u7740\u6211\u4eec\u628a 3 \u79fb\u52a8\u5230 P \u7684\u8d77\u59cb\u4f4d\u7f6e\uff0c\u5f97\u5230 P=[3,1,2,4,5] \u3002\n\u5bf9\u4e8e i=1: queries[i]=1, P=[3,1,2,4,5], 1 \u5728 P \u4e2d\u7684\u4f4d\u7f6e\u662f 1\uff0c\u63a5\u7740\u6211\u4eec\u628a 1 \u79fb\u52a8\u5230 P \u7684\u8d77\u59cb\u4f4d\u7f6e\uff0c\u5f97\u5230 P=[1,3,2,4,5] \u3002 \n\u5bf9\u4e8e i=2: queries[i]=2, P=[1,3,2,4,5], 2 \u5728 P \u4e2d\u7684\u4f4d\u7f6e\u662f 2\uff0c\u63a5\u7740\u6211\u4eec\u628a 2 \u79fb\u52a8\u5230 P \u7684\u8d77\u59cb\u4f4d\u7f6e\uff0c\u5f97\u5230 P=[2,1,3,4,5] \u3002\n\u5bf9\u4e8e i=3: queries[i]=1, P=[2,1,3,4,5], 1 \u5728 P \u4e2d\u7684\u4f4d\u7f6e\u662f 1\uff0c\u63a5\u7740\u6211\u4eec\u628a 1 \u79fb\u52a8\u5230 P \u7684\u8d77\u59cb\u4f4d\u7f6e\uff0c\u5f97\u5230 P=[1,2,3,4,5] \u3002 \n\u56e0\u6b64\uff0c\u8fd4\u56de\u7684\u7ed3\u679c\u6570\u7ec4\u4e3a [2,1,2,1] \u3002  \n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aqueries = [4,1,2,2], m = 4\n\u8f93\u51fa\uff1a[3,1,2,0]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aqueries = [7,5,5,8,3], m = 8\n\u8f93\u51fa\uff1a[6,5,0,7,5]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= m <= 10^3
  • \n\t
  • 1 <= queries.length <= m
  • \n\t
  • 1 <= queries[i] <= m
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector processQueries(vector& queries, int m) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] processQueries(int[] queries, int m) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def processQueries(self, queries, m):\n \"\"\"\n :type queries: List[int]\n :type m: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def processQueries(self, queries: List[int], m: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* processQueries(int* queries, int queriesSize, int m, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] ProcessQueries(int[] queries, int m) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} queries\n * @param {number} m\n * @return {number[]}\n */\nvar processQueries = function(queries, m) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} queries\n# @param {Integer} m\n# @return {Integer[]}\ndef process_queries(queries, m)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func processQueries(_ queries: [Int], _ m: Int) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func processQueries(queries []int, m int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def processQueries(queries: Array[Int], m: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun processQueries(queries: IntArray, m: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn process_queries(queries: Vec, m: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $queries\n * @param Integer $m\n * @return Integer[]\n */\n function processQueries($queries, $m) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function processQueries(queries: number[], m: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (process-queries queries m)\n (-> (listof exact-integer?) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1409](https://leetcode-cn.com/problems/queries-on-a-permutation-with-key)", "[\u67e5\u8be2\u5e26\u952e\u7684\u6392\u5217](/solution/1400-1499/1409.Queries%20on%20a%20Permutation%20With%20Key/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1409](https://leetcode.com/problems/queries-on-a-permutation-with-key)", "[Queries on a Permutation With Key](/solution/1400-1499/1409.Queries%20on%20a%20Permutation%20With%20Key/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "1524", "frontend_question_id": "1408", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/string-matching-in-an-array", "url_en": "https://leetcode.com/problems/string-matching-in-an-array", "relative_path_cn": "/solution/1400-1499/1408.String%20Matching%20in%20an%20Array/README.md", "relative_path_en": "/solution/1400-1499/1408.String%20Matching%20in%20an%20Array/README_EN.md", "title_cn": "\u6570\u7ec4\u4e2d\u7684\u5b57\u7b26\u4e32\u5339\u914d", "title_en": "String Matching in an Array", "question_title_slug": "string-matching-in-an-array", "content_en": "

Given an array of string words. Return all strings in words which is substring of another word in any order. 

\r\n\r\n

String words[i] is substring of words[j], if can be obtained removing some characters to left and/or right side of words[j].

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: words = ["mass","as","hero","superhero"]\r\nOutput: ["as","hero"]\r\nExplanation: "as" is substring of "mass" and "hero" is substring of "superhero".\r\n["hero","as"] is also a valid answer.\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: words = ["leetcode","et","code"]\r\nOutput: ["et","code"]\r\nExplanation: "et", "code" are substring of "leetcode".\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: words = ["blue","green","bu"]\r\nOutput: []\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= words.length <= 100
  • \r\n\t
  • 1 <= words[i].length <= 30
  • \r\n\t
  • words[i] contains only lowercase English letters.
  • \r\n\t
  • It's guaranteed that words[i] will be unique.
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4 words \uff0c\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u5b57\u7b26\u4e32\u90fd\u53ef\u4ee5\u770b\u4f5c\u662f\u4e00\u4e2a\u5355\u8bcd\u3002\u8bf7\u4f60\u6309 \u4efb\u610f \u987a\u5e8f\u8fd4\u56de words \u4e2d\u662f\u5176\u4ed6\u5355\u8bcd\u7684\u5b50\u5b57\u7b26\u4e32\u7684\u6240\u6709\u5355\u8bcd\u3002

\n\n

\u5982\u679c\u4f60\u53ef\u4ee5\u5220\u9664 words[j] \u6700\u5de6\u4fa7\u548c/\u6216\u6700\u53f3\u4fa7\u7684\u82e5\u5e72\u5b57\u7b26\u5f97\u5230 word[i] \uff0c\u90a3\u4e48\u5b57\u7b26\u4e32 words[i] \u5c31\u662f words[j] \u7684\u4e00\u4e2a\u5b50\u5b57\u7b26\u4e32\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1awords = ["mass","as","hero","superhero"]\n\u8f93\u51fa\uff1a["as","hero"]\n\u89e3\u91ca\uff1a"as" \u662f "mass" \u7684\u5b50\u5b57\u7b26\u4e32\uff0c"hero" \u662f "superhero" \u7684\u5b50\u5b57\u7b26\u4e32\u3002\n["hero","as"] \u4e5f\u662f\u6709\u6548\u7684\u7b54\u6848\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1awords = ["leetcode","et","code"]\n\u8f93\u51fa\uff1a["et","code"]\n\u89e3\u91ca\uff1a"et" \u548c "code" \u90fd\u662f "leetcode" \u7684\u5b50\u5b57\u7b26\u4e32\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1awords = ["blue","green","bu"]\n\u8f93\u51fa\uff1a[]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= words.length <= 100
  • \n\t
  • 1 <= words[i].length <= 30
  • \n\t
  • words[i] \u4ec5\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
  • \n\t
  • \u9898\u76ee\u6570\u636e \u4fdd\u8bc1 \u6bcf\u4e2a words[i] \u90fd\u662f\u72ec\u4e00\u65e0\u4e8c\u7684\u3002
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector stringMatching(vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List stringMatching(String[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def stringMatching(self, words):\n \"\"\"\n :type words: List[str]\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def stringMatching(self, words: List[str]) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** stringMatching(char ** words, int wordsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList StringMatching(string[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @return {string[]}\n */\nvar stringMatching = function(words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @return {String[]}\ndef string_matching(words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func stringMatching(_ words: [String]) -> [String] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func stringMatching(words []string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def stringMatching(words: Array[String]): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun stringMatching(words: Array): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn string_matching(words: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @return String[]\n */\n function stringMatching($words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function stringMatching(words: string[]): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (string-matching words)\n (-> (listof string?) (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1408](https://leetcode-cn.com/problems/string-matching-in-an-array)", "[\u6570\u7ec4\u4e2d\u7684\u5b57\u7b26\u4e32\u5339\u914d](/solution/1400-1499/1408.String%20Matching%20in%20an%20Array/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1408](https://leetcode.com/problems/string-matching-in-an-array)", "[String Matching in an Array](/solution/1400-1499/1408.String%20Matching%20in%20an%20Array/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1523", "frontend_question_id": "1393", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/capital-gainloss", "url_en": "https://leetcode.com/problems/capital-gainloss", "relative_path_cn": "/solution/1300-1399/1393.Capital%20GainLoss/README.md", "relative_path_en": "/solution/1300-1399/1393.Capital%20GainLoss/README_EN.md", "title_cn": "\u80a1\u7968\u7684\u8d44\u672c\u635f\u76ca", "title_en": "Capital GainLoss", "question_title_slug": "capital-gainloss", "content_en": "

Table: Stocks

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| stock_name    | varchar |\n| operation     | enum    |\n| operation_day | int     |\n| price         | int     |\n+---------------+---------+\n(stock_name, operation_day) is the primary key for this table.\nThe operation column is an ENUM of type ('Sell', 'Buy')\nEach row of this table indicates that the stock which has stock_name had an operation on the day operation_day with the price.\nIt is guaranteed that each 'Sell' operation for a stock has a corresponding 'Buy' operation in a previous day.\n
\n\n

 

\n\n

Write an SQL query to report the Capital gain/loss for each stock.

\n\n

The capital gain/loss of a stock is total gain or loss after buying and selling the stock one or many times.

\n\n

Return the result table in any order.

\n\n

The query result format is in the following example:

\n\n

 

\n\n
\nStocks table:\n+---------------+-----------+---------------+--------+\n| stock_name    | operation | operation_day | price  |\n+---------------+-----------+---------------+--------+\n| Leetcode      | Buy       | 1             | 1000   |\n| Corona Masks  | Buy       | 2             | 10     |\n| Leetcode      | Sell      | 5             | 9000   |\n| Handbags      | Buy       | 17            | 30000  |\n| Corona Masks  | Sell      | 3             | 1010   |\n| Corona Masks  | Buy       | 4             | 1000   |\n| Corona Masks  | Sell      | 5             | 500    |\n| Corona Masks  | Buy       | 6             | 1000   |\n| Handbags      | Sell      | 29            | 7000   |\n| Corona Masks  | Sell      | 10            | 10000  |\n+---------------+-----------+---------------+--------+\n\nResult table:\n+---------------+-------------------+\n| stock_name    | capital_gain_loss |\n+---------------+-------------------+\n| Corona Masks  | 9500              |\n| Leetcode      | 8000              |\n| Handbags      | -23000            |\n+---------------+-------------------+\nLeetcode stock was bought at day 1 for 1000$ and was sold at day 5 for 9000$. Capital gain = 9000 - 1000 = 8000$.\nHandbags stock was bought at day 17 for 30000$ and was sold at day 29 for 7000$. Capital loss = 7000 - 30000 = -23000$.\nCorona Masks stock was bought at day 1 for 10$ and was sold at day 3 for 1010$. It was bought again at day 4 for 1000$ and was sold at day 5 for 500$. At last, it was bought at day 6 for 1000$ and was sold at day 10 for 10000$. Capital gain/loss is the sum of capital gains/losses for each ('Buy' --> 'Sell') operation = (1010 - 10) + (500 - 1000) + (10000 - 1000) = 1000 - 500 + 9000 = 9500$.\n\n
\n", "content_cn": "

Stocks \u8868\uff1a

\n\n
+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| stock_name    | varchar |\n| operation     | enum    |\n| operation_day | int     |\n| price         | int     |\n+---------------+---------+\n(stock_name, day) \u662f\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\noperation \u5217\u4f7f\u7528\u7684\u662f\u4e00\u79cd\u679a\u4e3e\u7c7b\u578b\uff0c\u5305\u62ec\uff1a('Sell','Buy')\n\u6b64\u8868\u7684\u6bcf\u4e00\u884c\u4ee3\u8868\u4e86\u540d\u4e3a stock_name \u7684\u67d0\u652f\u80a1\u7968\u5728 operation_day \u8fd9\u4e00\u5929\u7684\u64cd\u4f5c\u4ef7\u683c\u3002\n\u4fdd\u8bc1\u80a1\u7968\u7684\u6bcf\u6b21'Sell'\u64cd\u4f5c\u524d\uff0c\u90fd\u6709\u76f8\u5e94\u7684'Buy'\u64cd\u4f5c\u3002\n
\n\n

 

\n\n

\u7f16\u5199\u4e00\u4e2aSQL\u67e5\u8be2\u6765\u62a5\u544a\u6bcf\u652f\u80a1\u7968\u7684\u8d44\u672c\u635f\u76ca\u3002

\n\n

\u80a1\u7968\u7684\u8d44\u672c\u635f\u76ca\u662f\u4e00\u6b21\u6216\u591a\u6b21\u4e70\u5356\u80a1\u7968\u540e\u7684\u5168\u90e8\u6536\u76ca\u6216\u635f\u5931\u3002

\n\n

\u4ee5\u4efb\u610f\u987a\u5e8f\u8fd4\u56de\u7ed3\u679c\u5373\u53ef\u3002

\n\n

SQL\u67e5\u8be2\u7ed3\u679c\u7684\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a\uff1a

\n\n
Stocks \u8868:\n+---------------+-----------+---------------+--------+\n| stock_name    | operation | operation_day | price  |\n+---------------+-----------+---------------+--------+\n| Leetcode      | Buy       | 1             | 1000   |\n| Corona Masks  | Buy       | 2             | 10     |\n| Leetcode      | Sell      | 5             | 9000   |\n| Handbags      | Buy       | 17            | 30000  |\n| Corona Masks  | Sell      | 3             | 1010   |\n| Corona Masks  | Buy       | 4             | 1000   |\n| Corona Masks  | Sell      | 5             | 500    |\n| Corona Masks  | Buy       | 6             | 1000   |\n| Handbags      | Sell      | 29            | 7000   |\n| Corona Masks  | Sell      | 10            | 10000  |\n+---------------+-----------+---------------+--------+\n\nResult \u8868:\n+---------------+-------------------+\n| stock_name    | capital_gain_loss |\n+---------------+-------------------+\n| Corona Masks  | 9500              |\n| Leetcode      | 8000              |\n| Handbags      | -23000            |\n+---------------+-------------------+\nLeetcode \u80a1\u7968\u5728\u7b2c\u4e00\u5929\u4ee51000\u7f8e\u5143\u7684\u4ef7\u683c\u4e70\u5165\uff0c\u5728\u7b2c\u4e94\u5929\u4ee59000\u7f8e\u5143\u7684\u4ef7\u683c\u5356\u51fa\u3002\u8d44\u672c\u6536\u76ca=9000-1000=8000\u7f8e\u5143\u3002\nHandbags \u80a1\u7968\u5728\u7b2c17\u5929\u4ee530000\u7f8e\u5143\u7684\u4ef7\u683c\u4e70\u5165\uff0c\u5728\u7b2c29\u5929\u4ee57000\u7f8e\u5143\u7684\u4ef7\u683c\u5356\u51fa\u3002\u8d44\u672c\u635f\u5931=7000-30000=-23000\u7f8e\u5143\u3002\nCorona Masks \u80a1\u7968\u5728\u7b2c1\u5929\u4ee510\u7f8e\u5143\u7684\u4ef7\u683c\u4e70\u5165\uff0c\u5728\u7b2c3\u5929\u4ee51010\u7f8e\u5143\u7684\u4ef7\u683c\u5356\u51fa\u3002\u5728\u7b2c4\u5929\u4ee51000\u7f8e\u5143\u7684\u4ef7\u683c\u518d\u6b21\u8d2d\u4e70\uff0c\u5728\u7b2c5\u5929\u4ee5500\u7f8e\u5143\u7684\u4ef7\u683c\u51fa\u552e\u3002\u6700\u540e\uff0c\u5b83\u5728\u7b2c6\u5929\u4ee51000\u7f8e\u5143\u7684\u4ef7\u683c\u88ab\u4e70\u8d70\uff0c\u5728\u7b2c10\u5929\u4ee510000\u7f8e\u5143\u7684\u4ef7\u683c\u88ab\u5356\u6389\u3002\u8d44\u672c\u635f\u76ca\u662f\u6bcf\u6b21\uff08’Buy'->'Sell'\uff09\u64cd\u4f5c\u8d44\u672c\u6536\u76ca\u6216\u635f\u5931\u7684\u548c=\uff081010-10\uff09+\uff08500-1000\uff09+\uff0810000-1000\uff09=1000-500+9000=9500\u7f8e\u5143\u3002\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1393](https://leetcode-cn.com/problems/capital-gainloss)", "[\u80a1\u7968\u7684\u8d44\u672c\u635f\u76ca](/solution/1300-1399/1393.Capital%20GainLoss/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1393](https://leetcode.com/problems/capital-gainloss)", "[Capital GainLoss](/solution/1300-1399/1393.Capital%20GainLoss/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1522", "frontend_question_id": "1406", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/stone-game-iii", "url_en": "https://leetcode.com/problems/stone-game-iii", "relative_path_cn": "/solution/1400-1499/1406.Stone%20Game%20III/README.md", "relative_path_en": "/solution/1400-1499/1406.Stone%20Game%20III/README_EN.md", "title_cn": "\u77f3\u5b50\u6e38\u620f III", "title_en": "Stone Game III", "question_title_slug": "stone-game-iii", "content_en": "

Alice and Bob continue their games with piles of stones. There are several stones arranged in a row, and each stone has an associated value which is an integer given in the array stoneValue.

\r\n\r\n

Alice and Bob take turns, with Alice starting first. On each player's turn, that player can take 1, 2 or 3 stones from the first remaining stones in the row.

\r\n\r\n

The score of each player is the sum of values of the stones taken. The score of each player is 0 initially.

\r\n\r\n

The objective of the game is to end with the highest score, and the winner is the player with the highest score and there could be a tie. The game continues until all the stones have been taken.

\r\n\r\n

Assume Alice and Bob play optimally.

\r\n\r\n

Return "Alice" if Alice will win, "Bob" if Bob will win or "Tie" if they end the game with the same score.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: values = [1,2,3,7]\r\nOutput: "Bob"\r\nExplanation: Alice will always lose. Her best move will be to take three piles and the score become 6. Now the score of Bob is 7 and Bob wins.\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: values = [1,2,3,-9]\r\nOutput: "Alice"\r\nExplanation: Alice must choose all the three piles at the first move to win and leave Bob with negative score.\r\nIf Alice chooses one pile her score will be 1 and the next move Bob's score becomes 5. The next move Alice will take the pile with value = -9 and lose.\r\nIf Alice chooses two piles her score will be 3 and the next move Bob's score becomes 3. The next move Alice will take the pile with value = -9 and also lose.\r\nRemember that both play optimally so here Alice will choose the scenario that makes her win.\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: values = [1,2,3,6]\r\nOutput: "Tie"\r\nExplanation: Alice cannot win this game. She can end the game in a draw if she decided to choose all the first three piles, otherwise she will lose.\r\n
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: values = [1,2,3,-1,-2,-3,7]\r\nOutput: "Alice"\r\n
\r\n\r\n

Example 5:

\r\n\r\n
\r\nInput: values = [-1,-2,-3]\r\nOutput: "Tie"\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= values.length <= 50000
  • \r\n\t
  • -1000 <= values[i] <= 1000
  • \r\n
", "content_cn": "

Alice \u548c Bob \u7528\u51e0\u5806\u77f3\u5b50\u5728\u505a\u6e38\u620f\u3002\u51e0\u5806\u77f3\u5b50\u6392\u6210\u4e00\u884c\uff0c\u6bcf\u5806\u77f3\u5b50\u90fd\u5bf9\u5e94\u4e00\u4e2a\u5f97\u5206\uff0c\u7531\u6570\u7ec4 stoneValue \u7ed9\u51fa\u3002

\n\n

Alice \u548c Bob \u8f6e\u6d41\u53d6\u77f3\u5b50\uff0cAlice \u603b\u662f\u5148\u5f00\u59cb\u3002\u5728\u6bcf\u4e2a\u73a9\u5bb6\u7684\u56de\u5408\u4e2d\uff0c\u8be5\u73a9\u5bb6\u53ef\u4ee5\u62ff\u8d70\u5269\u4e0b\u77f3\u5b50\u4e2d\u7684\u7684\u524d 1\u30012 \u6216 3 \u5806\u77f3\u5b50 \u3002\u6bd4\u8d5b\u4e00\u76f4\u6301\u7eed\u5230\u6240\u6709\u77f3\u5934\u90fd\u88ab\u62ff\u8d70\u3002

\n\n

\u6bcf\u4e2a\u73a9\u5bb6\u7684\u6700\u7ec8\u5f97\u5206\u4e3a\u4ed6\u6240\u62ff\u5230\u7684\u6bcf\u5806\u77f3\u5b50\u7684\u5bf9\u5e94\u5f97\u5206\u4e4b\u548c\u3002\u6bcf\u4e2a\u73a9\u5bb6\u7684\u521d\u59cb\u5206\u6570\u90fd\u662f 0 \u3002\u6bd4\u8d5b\u7684\u76ee\u6807\u662f\u51b3\u51fa\u6700\u9ad8\u5206\uff0c\u5f97\u5206\u6700\u9ad8\u7684\u9009\u624b\u5c06\u4f1a\u8d62\u5f97\u6bd4\u8d5b\uff0c\u6bd4\u8d5b\u4e5f\u53ef\u80fd\u4f1a\u51fa\u73b0\u5e73\u5c40\u3002

\n\n

\u5047\u8bbe Alice \u548c Bob \u90fd\u91c7\u53d6 \u6700\u4f18\u7b56\u7565 \u3002\u5982\u679c Alice \u8d62\u4e86\u5c31\u8fd4\u56de "Alice" \uff0cBob \u8d62\u4e86\u5c31\u8fd4\u56de "Bob"\uff0c\u5e73\u5c40\uff08\u5206\u6570\u76f8\u540c\uff09\u8fd4\u56de "Tie" \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1avalues = [1,2,3,7]\n\u8f93\u51fa\uff1a"Bob"\n\u89e3\u91ca\uff1aAlice \u603b\u662f\u4f1a\u8f93\uff0c\u5979\u7684\u6700\u4f73\u9009\u62e9\u662f\u62ff\u8d70\u524d\u4e09\u5806\uff0c\u5f97\u5206\u53d8\u6210 6 \u3002\u4f46\u662f Bob \u7684\u5f97\u5206\u4e3a 7\uff0cBob \u83b7\u80dc\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1avalues = [1,2,3,-9]\n\u8f93\u51fa\uff1a"Alice"\n\u89e3\u91ca\uff1aAlice \u8981\u60f3\u83b7\u80dc\u5c31\u5fc5\u987b\u5728\u7b2c\u4e00\u4e2a\u56de\u5408\u62ff\u8d70\u524d\u4e09\u5806\u77f3\u5b50\uff0c\u7ed9 Bob \u7559\u4e0b\u8d1f\u5206\u3002\n\u5982\u679c Alice \u53ea\u62ff\u8d70\u7b2c\u4e00\u5806\uff0c\u90a3\u4e48\u5979\u7684\u5f97\u5206\u4e3a 1\uff0c\u63a5\u4e0b\u6765 Bob \u62ff\u8d70\u7b2c\u4e8c\u3001\u4e09\u5806\uff0c\u5f97\u5206\u4e3a 5 \u3002\u4e4b\u540e Alice \u53ea\u80fd\u62ff\u5230\u5206\u6570 -9 \u7684\u77f3\u5b50\u5806\uff0c\u8f93\u6389\u6bd4\u8d5b\u3002\n\u5982\u679c Alice \u62ff\u8d70\u524d\u4e24\u5806\uff0c\u90a3\u4e48\u5979\u7684\u5f97\u5206\u4e3a 3\uff0c\u63a5\u4e0b\u6765 Bob \u62ff\u8d70\u7b2c\u4e09\u5806\uff0c\u5f97\u5206\u4e3a 3 \u3002\u4e4b\u540e Alice \u53ea\u80fd\u62ff\u5230\u5206\u6570 -9 \u7684\u77f3\u5b50\u5806\uff0c\u540c\u6837\u4f1a\u8f93\u6389\u6bd4\u8d5b\u3002\n\u6ce8\u610f\uff0c\u4ed6\u4eec\u90fd\u5e94\u8be5\u91c7\u53d6 \u6700\u4f18\u7b56\u7565 \uff0c\u6240\u4ee5\u5728\u8fd9\u91cc Alice \u5c06\u9009\u62e9\u80fd\u591f\u4f7f\u5979\u83b7\u80dc\u7684\u65b9\u6848\u3002
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1avalues = [1,2,3,6]\n\u8f93\u51fa\uff1a"Tie"\n\u89e3\u91ca\uff1aAlice \u65e0\u6cd5\u8d62\u5f97\u6bd4\u8d5b\u3002\u5982\u679c\u5979\u51b3\u5b9a\u9009\u62e9\u524d\u4e09\u5806\uff0c\u5979\u53ef\u4ee5\u4ee5\u5e73\u5c40\u7ed3\u675f\u6bd4\u8d5b\uff0c\u5426\u5219\u5979\u5c31\u4f1a\u8f93\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1avalues = [1,2,3,-1,-2,-3,7]\n\u8f93\u51fa\uff1a"Alice"\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1avalues = [-1,-2,-3]\n\u8f93\u51fa\uff1a"Tie"\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= values.length <= 50000
  • \n\t
  • -1000 <= values[i] <= 1000
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string stoneGameIII(vector& stoneValue) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String stoneGameIII(int[] stoneValue) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def stoneGameIII(self, stoneValue):\n \"\"\"\n :type stoneValue: List[int]\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def stoneGameIII(self, stoneValue: List[int]) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * stoneGameIII(int* stoneValue, int stoneValueSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string StoneGameIII(int[] stoneValue) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} stoneValue\n * @return {string}\n */\nvar stoneGameIII = function(stoneValue) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} stone_value\n# @return {String}\ndef stone_game_iii(stone_value)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func stoneGameIII(_ stoneValue: [Int]) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func stoneGameIII(stoneValue []int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def stoneGameIII(stoneValue: Array[Int]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun stoneGameIII(stoneValue: IntArray): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn stone_game_iii(stone_value: Vec) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $stoneValue\n * @return String\n */\n function stoneGameIII($stoneValue) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function stoneGameIII(stoneValue: number[]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (stone-game-iii stoneValue)\n (-> (listof exact-integer?) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1406](https://leetcode-cn.com/problems/stone-game-iii)", "[\u77f3\u5b50\u6e38\u620f III](/solution/1400-1499/1406.Stone%20Game%20III/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1406](https://leetcode.com/problems/stone-game-iii)", "[Stone Game III](/solution/1400-1499/1406.Stone%20Game%20III/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1520", "frontend_question_id": "1404", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-steps-to-reduce-a-number-in-binary-representation-to-one", "url_en": "https://leetcode.com/problems/number-of-steps-to-reduce-a-number-in-binary-representation-to-one", "relative_path_cn": "/solution/1400-1499/1404.Number%20of%20Steps%20to%20Reduce%20a%20Number%20in%20Binary%20Representation%20to%20One/README.md", "relative_path_en": "/solution/1400-1499/1404.Number%20of%20Steps%20to%20Reduce%20a%20Number%20in%20Binary%20Representation%20to%20One/README_EN.md", "title_cn": "\u5c06\u4e8c\u8fdb\u5236\u8868\u793a\u51cf\u5230 1 \u7684\u6b65\u9aa4\u6570", "title_en": "Number of Steps to Reduce a Number in Binary Representation to One", "question_title_slug": "number-of-steps-to-reduce-a-number-in-binary-representation-to-one", "content_en": "

Given a number s in their binary representation. Return the number of steps to reduce it to 1 under the following rules:

\n\n
    \n\t
  • \n\t

    If the current number is even, you have to divide it by 2.

    \n\t
  • \n\t
  • \n\t

    If the current number is odd, you have to add 1 to it.

    \n\t
  • \n
\n\n

It's guaranteed that you can always reach to one for all testcases.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "1101"\nOutput: 6\nExplanation: "1101" corressponds to number 13 in their decimal representation.\nStep 1) 13 is odd, add 1 and obtain 14. \nStep 2) 14 is even, divide by 2 and obtain 7.\nStep 3) 7 is odd, add 1 and obtain 8.\nStep 4) 8 is even, divide by 2 and obtain 4.  \nStep 5) 4 is even, divide by 2 and obtain 2. \nStep 6) 2 is even, divide by 2 and obtain 1.  \n
\n\n

Example 2:

\n\n
\nInput: s = "10"\nOutput: 1\nExplanation: "10" corressponds to number 2 in their decimal representation.\nStep 1) 2 is even, divide by 2 and obtain 1.  \n
\n\n

Example 3:

\n\n
\nInput: s = "1"\nOutput: 0\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 500
  • \n\t
  • s consists of characters '0' or '1'
  • \n\t
  • s[0] == '1'
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u4ee5\u4e8c\u8fdb\u5236\u5f62\u5f0f\u8868\u793a\u7684\u6570\u5b57 s \u3002\u8bf7\u4f60\u8fd4\u56de\u6309\u4e0b\u8ff0\u89c4\u5219\u5c06\u5176\u51cf\u5c11\u5230 1 \u6240\u9700\u8981\u7684\u6b65\u9aa4\u6570\uff1a

\n\n
    \n\t
  • \n\t

    \u5982\u679c\u5f53\u524d\u6570\u5b57\u4e3a\u5076\u6570\uff0c\u5219\u5c06\u5176\u9664\u4ee5 2 \u3002

    \n\t
  • \n\t
  • \n\t

    \u5982\u679c\u5f53\u524d\u6570\u5b57\u4e3a\u5947\u6570\uff0c\u5219\u5c06\u5176\u52a0\u4e0a 1 \u3002

    \n\t
  • \n
\n\n

\u9898\u76ee\u4fdd\u8bc1\u4f60\u603b\u662f\u53ef\u4ee5\u6309\u4e0a\u8ff0\u89c4\u5219\u5c06\u6d4b\u8bd5\u7528\u4f8b\u53d8\u4e3a 1 \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1as = "1101"\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a"1101" \u8868\u793a\u5341\u8fdb\u5236\u6570 13 \u3002\nStep 1) 13 \u662f\u5947\u6570\uff0c\u52a0 1 \u5f97\u5230 14 \nStep 2) 14 \u662f\u5076\u6570\uff0c\u9664 2 \u5f97\u5230 7\nStep 3) 7  \u662f\u5947\u6570\uff0c\u52a0 1 \u5f97\u5230 8\nStep 4) 8  \u662f\u5076\u6570\uff0c\u9664 2 \u5f97\u5230 4  \nStep 5) 4  \u662f\u5076\u6570\uff0c\u9664 2 \u5f97\u5230 2 \nStep 6) 2  \u662f\u5076\u6570\uff0c\u9664 2 \u5f97\u5230 1  \n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1as = "10"\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a"10" \u8868\u793a\u5341\u8fdb\u5236\u6570 2 \u3002\nStep 1) 2 \u662f\u5076\u6570\uff0c\u9664 2 \u5f97\u5230 1 \n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1as = "1"\n\u8f93\u51fa\uff1a0\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length <= 500
  • \n\t
  • s \u7531\u5b57\u7b26 '0' \u6216 '1' \u7ec4\u6210\u3002
  • \n\t
  • s[0] == '1'
  • \n
\n", "tags_en": ["Bit Manipulation", "String"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numSteps(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numSteps(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numSteps(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numSteps(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numSteps(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumSteps(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar numSteps = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef num_steps(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numSteps(_ s: String) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numSteps(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numSteps(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numSteps(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_steps(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function numSteps($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numSteps(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-steps s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1404](https://leetcode-cn.com/problems/number-of-steps-to-reduce-a-number-in-binary-representation-to-one)", "[\u5c06\u4e8c\u8fdb\u5236\u8868\u793a\u51cf\u5230 1 \u7684\u6b65\u9aa4\u6570](/solution/1400-1499/1404.Number%20of%20Steps%20to%20Reduce%20a%20Number%20in%20Binary%20Representation%20to%20One/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1404](https://leetcode.com/problems/number-of-steps-to-reduce-a-number-in-binary-representation-to-one)", "[Number of Steps to Reduce a Number in Binary Representation to One](/solution/1400-1499/1404.Number%20of%20Steps%20to%20Reduce%20a%20Number%20in%20Binary%20Representation%20to%20One/README_EN.md)", "`Bit Manipulation`,`String`", "Medium", ""]}, {"question_id": "1519", "frontend_question_id": "1403", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-subsequence-in-non-increasing-order", "url_en": "https://leetcode.com/problems/minimum-subsequence-in-non-increasing-order", "relative_path_cn": "/solution/1400-1499/1403.Minimum%20Subsequence%20in%20Non-Increasing%20Order/README.md", "relative_path_en": "/solution/1400-1499/1403.Minimum%20Subsequence%20in%20Non-Increasing%20Order/README_EN.md", "title_cn": "\u975e\u9012\u589e\u987a\u5e8f\u7684\u6700\u5c0f\u5b50\u5e8f\u5217", "title_en": "Minimum Subsequence in Non-Increasing Order", "question_title_slug": "minimum-subsequence-in-non-increasing-order", "content_en": "

Given the array nums, obtain a subsequence of the array whose sum of elements is strictly greater than the sum of the non included elements in such subsequence. 

\r\n\r\n

If there are multiple solutions, return the subsequence with minimum size and if there still exist multiple solutions, return the subsequence with the maximum total sum of all its elements. A subsequence of an array can be obtained by erasing some (possibly zero) elements from the array. 

\r\n\r\n

Note that the solution with the given constraints is guaranteed to be unique. Also return the answer sorted in non-increasing order.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: nums = [4,3,10,9,8]\r\nOutput: [10,9] \r\nExplanation: The subsequences [10,9] and [10,8] are minimal such that the sum of their elements is strictly greater than the sum of elements not included, however, the subsequence [10,9] has the maximum total sum of its elements. \r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: nums = [4,4,7,6,7]\r\nOutput: [7,7,6] \r\nExplanation: The subsequence [7,7] has the sum of its elements equal to 14 which is not strictly greater than the sum of elements not included (14 = 4 + 4 + 6). Therefore, the subsequence [7,6,7] is the minimal satisfying the conditions. Note the subsequence has to returned in non-decreasing order.  \r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: nums = [6]\r\nOutput: [6]\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= nums.length <= 500
  • \r\n\t
  • 1 <= nums[i] <= 100
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 nums\uff0c\u8bf7\u4f60\u4ece\u4e2d\u62bd\u53d6\u4e00\u4e2a\u5b50\u5e8f\u5217\uff0c\u6ee1\u8db3\u8be5\u5b50\u5e8f\u5217\u7684\u5143\u7d20\u4e4b\u548c \u4e25\u683c \u5927\u4e8e\u672a\u5305\u542b\u5728\u8be5\u5b50\u5e8f\u5217\u4e2d\u7684\u5404\u5143\u7d20\u4e4b\u548c\u3002

\n\n

\u5982\u679c\u5b58\u5728\u591a\u4e2a\u89e3\u51b3\u65b9\u6848\uff0c\u53ea\u9700\u8fd4\u56de \u957f\u5ea6\u6700\u5c0f \u7684\u5b50\u5e8f\u5217\u3002\u5982\u679c\u4ecd\u7136\u6709\u591a\u4e2a\u89e3\u51b3\u65b9\u6848\uff0c\u5219\u8fd4\u56de \u5143\u7d20\u4e4b\u548c\u6700\u5927 \u7684\u5b50\u5e8f\u5217\u3002

\n\n

\u4e0e\u5b50\u6570\u7ec4\u4e0d\u540c\u7684\u5730\u65b9\u5728\u4e8e\uff0c\u300c\u6570\u7ec4\u7684\u5b50\u5e8f\u5217\u300d\u4e0d\u5f3a\u8c03\u5143\u7d20\u5728\u539f\u6570\u7ec4\u4e2d\u7684\u8fde\u7eed\u6027\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u5b83\u53ef\u4ee5\u901a\u8fc7\u4ece\u6570\u7ec4\u4e2d\u5206\u79bb\u4e00\u4e9b\uff08\u4e5f\u53ef\u80fd\u4e0d\u5206\u79bb\uff09\u5143\u7d20\u5f97\u5230\u3002

\n\n

\u6ce8\u610f\uff0c\u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u6ee1\u8db3\u6240\u6709\u7ea6\u675f\u6761\u4ef6\u7684\u89e3\u51b3\u65b9\u6848\u662f \u552f\u4e00 \u7684\u3002\u540c\u65f6\uff0c\u8fd4\u56de\u7684\u7b54\u6848\u5e94\u5f53\u6309 \u975e\u9012\u589e\u987a\u5e8f \u6392\u5217\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anums = [4,3,10,9,8]\n\u8f93\u51fa\uff1a[10,9] \n\u89e3\u91ca\uff1a\u5b50\u5e8f\u5217 [10,9] \u548c [10,8] \u662f\u6700\u5c0f\u7684\u3001\u6ee1\u8db3\u5143\u7d20\u4e4b\u548c\u5927\u4e8e\u5176\u4ed6\u5404\u5143\u7d20\u4e4b\u548c\u7684\u5b50\u5e8f\u5217\u3002\u4f46\u662f [10,9] \u7684\u5143\u7d20\u4e4b\u548c\u6700\u5927\u3002 \n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anums = [4,4,7,6,7]\n\u8f93\u51fa\uff1a[7,7,6] \n\u89e3\u91ca\uff1a\u5b50\u5e8f\u5217 [7,7] \u7684\u548c\u4e3a 14 \uff0c\u4e0d\u4e25\u683c\u5927\u4e8e\u5269\u4e0b\u7684\u5176\u4ed6\u5143\u7d20\u4e4b\u548c\uff0814 = 4 + 4 + 6\uff09\u3002\u56e0\u6b64\uff0c[7,6,7] \u662f\u6ee1\u8db3\u9898\u610f\u7684\u6700\u5c0f\u5b50\u5e8f\u5217\u3002\u6ce8\u610f\uff0c\u5143\u7d20\u6309\u975e\u9012\u589e\u987a\u5e8f\u8fd4\u56de\u3002  \n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1anums = [6]\n\u8f93\u51fa\uff1a[6]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 500
  • \n\t
  • 1 <= nums[i] <= 100
  • \n
\n", "tags_en": ["Greedy", "Sort"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6392\u5e8f"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector minSubsequence(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List minSubsequence(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minSubsequence(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minSubsequence(self, nums: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* minSubsequence(int* nums, int numsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList MinSubsequence(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar minSubsequence = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer[]}\ndef min_subsequence(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minSubsequence(_ nums: [Int]) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minSubsequence(nums []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minSubsequence(nums: Array[Int]): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minSubsequence(nums: IntArray): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_subsequence(nums: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer[]\n */\n function minSubsequence($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minSubsequence(nums: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-subsequence nums)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1403](https://leetcode-cn.com/problems/minimum-subsequence-in-non-increasing-order)", "[\u975e\u9012\u589e\u987a\u5e8f\u7684\u6700\u5c0f\u5b50\u5e8f\u5217](/solution/1400-1499/1403.Minimum%20Subsequence%20in%20Non-Increasing%20Order/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6392\u5e8f`", "\u7b80\u5355", ""], "md_table_row_en": ["[1403](https://leetcode.com/problems/minimum-subsequence-in-non-increasing-order)", "[Minimum Subsequence in Non-Increasing Order](/solution/1400-1499/1403.Minimum%20Subsequence%20in%20Non-Increasing%20Order/README_EN.md)", "`Greedy`,`Sort`", "Easy", ""]}, {"question_id": "1518", "frontend_question_id": "1384", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/total-sales-amount-by-year", "url_en": "https://leetcode.com/problems/total-sales-amount-by-year", "relative_path_cn": "/solution/1300-1399/1384.Total%20Sales%20Amount%20by%20Year/README.md", "relative_path_en": "/solution/1300-1399/1384.Total%20Sales%20Amount%20by%20Year/README_EN.md", "title_cn": "\u6309\u5e74\u5ea6\u5217\u51fa\u9500\u552e\u603b\u989d", "title_en": "Total Sales Amount by Year", "question_title_slug": "total-sales-amount-by-year", "content_en": "

Table: Product

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| product_id    | int     |\n| product_name  | varchar |\n+---------------+---------+\nproduct_id is the primary key for this table.\nproduct_name is the name of the product.\n
\n\n

 

\n\n

Table: Sales

\n\n
\n+---------------------+---------+\n| Column Name         | Type    |\n+---------------------+---------+\n| product_id          | int     |\n| period_start        | date    |\n| period_end          | date    |\n| average_daily_sales | int     |\n+---------------------+---------+\nproduct_id is the primary key for this table. \nperiod_start and period_end indicates the start and end date for sales period, both dates are inclusive.\nThe average_daily_sales column holds the average daily sales amount of the items for the period.\n\n
\n\n

Write an SQL query to report the Total sales amount of each item for each year, with corresponding product name, product_id, product_name and report_year.

\n\n

Dates of the sales years are between 2018 to 2020. Return the result table ordered by product_id and report_year.

\n\n

The query result format is in the following example:

\n\n
\nProduct table:\n+------------+--------------+\n| product_id | product_name |\n+------------+--------------+\n| 1          | LC Phone     |\n| 2          | LC T-Shirt   |\n| 3          | LC Keychain  |\n+------------+--------------+\n\nSales table:\n+------------+--------------+-------------+---------------------+\n| product_id | period_start | period_end  | average_daily_sales |\n+------------+--------------+-------------+---------------------+\n| 1          | 2019-01-25   | 2019-02-28  | 100                 |\n| 2          | 2018-12-01   | 2020-01-01  | 10                  |\n| 3          | 2019-12-01   | 2020-01-31  | 1                   |\n+------------+--------------+-------------+---------------------+\n\nResult table:\n+------------+--------------+-------------+--------------+\n| product_id | product_name | report_year | total_amount |\n+------------+--------------+-------------+--------------+\n| 1          | LC Phone     |    2019     | 3500         |\n| 2          | LC T-Shirt   |    2018     | 310          |\n| 2          | LC T-Shirt   |    2019     | 3650         |\n| 2          | LC T-Shirt   |    2020     | 10           |\n| 3          | LC Keychain  |    2019     | 31           |\n| 3          | LC Keychain  |    2020     | 31           |\n+------------+--------------+-------------+--------------+\nLC Phone was sold for the period of 2019-01-25 to 2019-02-28, and there are 35 days for this period. Total amount 35*100 = 3500. \nLC T-shirt was sold for the period of 2018-12-01 to 2020-01-01, and there are 31, 365, 1 days for years 2018, 2019 and 2020 respectively.\nLC Keychain was sold for the period of 2019-12-01 to 2020-01-31, and there are 31, 31 days for years 2019 and 2020 respectively.\n
\n", "content_cn": "

\u00a0Product\u00a0\u8868\uff1a

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| product_id    | int     |\n| product_name  | varchar |\n+---------------+---------+\nproduct_id \u662f\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\u3002\nproduct_name \u662f\u4ea7\u54c1\u7684\u540d\u79f0\u3002\n
\n\n

\u00a0

\n\n

Sales\u00a0\u8868\uff1a

\n\n
\n+---------------------+---------+\n| Column Name         | Type    |\n+---------------------+---------+\n| product_id          | int     |\n| period_start        | date    |\n| period_end          | date    |\n| average_daily_sales | int     |\n+---------------------+---------+\nproduct_id \u662f\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\u3002\nperiod_start\u00a0\u548c period_end\u00a0\u662f\u8be5\u4ea7\u54c1\u9500\u552e\u671f\u7684\u8d77\u59cb\u65e5\u671f\u548c\u7ed3\u675f\u65e5\u671f\uff0c\u4e14\u8fd9\u4e24\u4e2a\u65e5\u671f\u5305\u542b\u5728\u9500\u552e\u671f\u5185\u3002\naverage_daily_sales \u5217\u5b58\u50a8\u9500\u552e\u671f\u5185\u8be5\u4ea7\u54c1\u7684\u65e5\u5e73\u5747\u9500\u552e\u989d\u3002\n
\n\n

\u00a0

\n\n

\u7f16\u5199\u4e00\u6bb5 SQL \u67e5\u8be2\u6bcf\u4e2a\u4ea7\u54c1\u6bcf\u5e74\u7684\u603b\u9500\u552e\u989d\uff0c\u5e76\u5305\u542b product_id, product_name \u4ee5\u53ca report_year \u7b49\u4fe1\u606f\u3002

\n\n

\u9500\u552e\u5e74\u4efd\u7684\u65e5\u671f\u4ecb\u4e8e 2018 \u5e74\u5230 2020 \u5e74\u4e4b\u95f4\u3002\u4f60\u8fd4\u56de\u7684\u7ed3\u679c\u9700\u8981\u6309\u00a0product_id \u548c report_year \u6392\u5e8f\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a\uff1a

\n\n
\nProduct table:\n+------------+--------------+\n| product_id | product_name |\n+------------+--------------+\n| 1          | LC Phone     |\n| 2          | LC T-Shirt   |\n| 3          | LC Keychain  |\n+------------+--------------+\n\nSales table:\n+------------+--------------+-------------+---------------------+\n| product_id | period_start | period_end  | average_daily_sales |\n+------------+--------------+-------------+---------------------+\n| 1          | 2019-01-25   | 2019-02-28  | 100                 |\n| 2          | 2018-12-01   | 2020-01-01  | 10                  |\n| 3          | 2019-12-01   | 2020-01-31  | 1                   |\n+------------+--------------+-------------+---------------------+\n\nResult table:\n+------------+--------------+-------------+--------------+\n| product_id | product_name | report_year | total_amount |\n+------------+--------------+-------------+--------------+\n| 1          | LC Phone     |    2019     | 3500         |\n| 2          | LC T-Shirt   |    2018     | 310          |\n| 2          | LC T-Shirt   |    2019     | 3650         |\n| 2          | LC T-Shirt   |    2020     | 10           |\n| 3          | LC Keychain  |    2019     | 31           |\n| 3          | LC Keychain  |    2020     | 31           |\n+------------+--------------+-------------+--------------+\nLC Phone \u5728 2019-01-25 \u81f3 2019-02-28 \u671f\u95f4\u9500\u552e\uff0c\u8be5\u4ea7\u54c1\u9500\u552e\u65f6\u95f4\u603b\u8ba135\u5929\u3002\u9500\u552e\u603b\u989d 35*100 = 3500\u3002\nLC T-shirt \u5728 2018-12-01\u00a0\u81f3 2020-01-01 \u671f\u95f4\u9500\u552e\uff0c\u8be5\u4ea7\u54c1\u57282018\u5e74\u30012019\u5e74\u30012020\u5e74\u7684\u9500\u552e\u65f6\u95f4\u5206\u522b\u662f31\u5929\u3001365\u5929\u30011\u5929\uff0c2018\u5e74\u30012019\u5e74\u30012020\u5e74\u7684\u9500\u552e\u603b\u989d\u5206\u522b\u662f31*10=310\u3001365*10=3650\u30011*10=10\u3002\nLC Keychain \u5728 2019-12-01\u00a0\u81f3 2020-01-31 \u671f\u95f4\u9500\u552e\uff0c\u8be5\u4ea7\u54c1\u57282019\u5e74\u30012020\u5e74\u7684\u9500\u552e\u65f6\u95f4\u5206\u522b\u662f\uff1a31\u5929\u300131\u5929\uff0c2019\u5e74\u30012020\u5e74\u7684\u9500\u552e\u603b\u989d\u5206\u522b\u662f31*1=31\u300131*1=31\u3002\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1384](https://leetcode-cn.com/problems/total-sales-amount-by-year)", "[\u6309\u5e74\u5ea6\u5217\u51fa\u9500\u552e\u603b\u989d](/solution/1300-1399/1384.Total%20Sales%20Amount%20by%20Year/README.md)", "", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1384](https://leetcode.com/problems/total-sales-amount-by-year)", "[Total Sales Amount by Year](/solution/1300-1399/1384.Total%20Sales%20Amount%20by%20Year/README_EN.md)", "", "Hard", "\ud83d\udd12"]}, {"question_id": "1517", "frontend_question_id": "1416", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/restore-the-array", "url_en": "https://leetcode.com/problems/restore-the-array", "relative_path_cn": "/solution/1400-1499/1416.Restore%20The%20Array/README.md", "relative_path_en": "/solution/1400-1499/1416.Restore%20The%20Array/README_EN.md", "title_cn": "\u6062\u590d\u6570\u7ec4", "title_en": "Restore The Array", "question_title_slug": "restore-the-array", "content_en": "

A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits and all we know is that all integers in the array were in the range [1, k] and there are no leading zeros in the array.

\r\n\r\n

Given the string s and the integer k. There can be multiple ways to restore the array.

\r\n\r\n

Return the number of possible array that can be printed as a string s using the mentioned program.

\r\n\r\n

The number of ways could be very large so return it modulo 10^9 + 7

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: s = "1000", k = 10000\r\nOutput: 1\r\nExplanation: The only possible array is [1000]\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: s = "1000", k = 10\r\nOutput: 0\r\nExplanation: There cannot be an array that was printed this way and has all integer >= 1 and <= 10.\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: s = "1317", k = 2000\r\nOutput: 8\r\nExplanation: Possible arrays are [1317],[131,7],[13,17],[1,317],[13,1,7],[1,31,7],[1,3,17],[1,3,1,7]\r\n
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: s = "2020", k = 30\r\nOutput: 1\r\nExplanation: The only possible array is [20,20]. [2020] is invalid because 2020 > 30. [2,020] is ivalid because 020 contains leading zeros.\r\n
\r\n\r\n

Example 5:

\r\n\r\n
\r\nInput: s = "1234567890", k = 90\r\nOutput: 34\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= s.length <= 10^5.
  • \r\n\t
  • s consists of only digits and doesn't contain leading zeros.
  • \r\n\t
  • 1 <= k <= 10^9.
  • \r\n
", "content_cn": "

\u67d0\u4e2a\u7a0b\u5e8f\u672c\u6765\u5e94\u8be5\u8f93\u51fa\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u3002\u4f46\u662f\u8fd9\u4e2a\u7a0b\u5e8f\u5fd8\u8bb0\u8f93\u51fa\u7a7a\u683c\u4e86\u4ee5\u81f4\u8f93\u51fa\u4e86\u4e00\u4e2a\u6570\u5b57\u5b57\u7b26\u4e32\uff0c\u6211\u4eec\u6240\u77e5\u9053\u7684\u4fe1\u606f\u53ea\u6709\uff1a\u6570\u7ec4\u4e2d\u6240\u6709\u6574\u6570\u90fd\u5728 [1, k] \u4e4b\u95f4\uff0c\u4e14\u6570\u7ec4\u4e2d\u7684\u6570\u5b57\u90fd\u6ca1\u6709\u524d\u5bfc 0 \u3002

\n\n

\u7ed9\u4f60\u5b57\u7b26\u4e32 s \u548c\u6574\u6570 k \u3002\u53ef\u80fd\u4f1a\u6709\u591a\u79cd\u4e0d\u540c\u7684\u6570\u7ec4\u6062\u590d\u7ed3\u679c\u3002

\n\n

\u6309\u7167\u4e0a\u8ff0\u7a0b\u5e8f\uff0c\u8bf7\u4f60\u8fd4\u56de\u6240\u6709\u53ef\u80fd\u8f93\u51fa\u5b57\u7b26\u4e32 s \u7684\u6570\u7ec4\u65b9\u6848\u6570\u3002

\n\n

\u7531\u4e8e\u6570\u7ec4\u65b9\u6848\u6570\u53ef\u80fd\u4f1a\u5f88\u5927\uff0c\u8bf7\u4f60\u8fd4\u56de\u5b83\u5bf9 10^9 + 7 \u53d6\u4f59 \u540e\u7684\u7ed3\u679c\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1as = "1000", k = 10000\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u552f\u4e00\u4e00\u79cd\u53ef\u80fd\u7684\u6570\u7ec4\u65b9\u6848\u662f [1000]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1as = "1000", k = 10\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u4e0d\u5b58\u5728\u4efb\u4f55\u6570\u7ec4\u65b9\u6848\u6ee1\u8db3\u6240\u6709\u6574\u6570\u90fd >= 1 \u4e14 <= 10 \u540c\u65f6\u8f93\u51fa\u7ed3\u679c\u4e3a s \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1as = "1317", k = 2000\n\u8f93\u51fa\uff1a8\n\u89e3\u91ca\uff1a\u53ef\u884c\u7684\u6570\u7ec4\u65b9\u6848\u4e3a [1317]\uff0c[131,7]\uff0c[13,17]\uff0c[1,317]\uff0c[13,1,7]\uff0c[1,31,7]\uff0c[1,3,17]\uff0c[1,3,1,7]\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1as = "2020", k = 30\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u552f\u4e00\u53ef\u80fd\u7684\u6570\u7ec4\u65b9\u6848\u662f [20,20] \u3002 [2020] \u4e0d\u662f\u53ef\u884c\u7684\u6570\u7ec4\u65b9\u6848\uff0c\u539f\u56e0\u662f 2020 > 30 \u3002 [2,020] \u4e5f\u4e0d\u662f\u53ef\u884c\u7684\u6570\u7ec4\u65b9\u6848\uff0c\u56e0\u4e3a 020 \u542b\u6709\u524d\u5bfc 0 \u3002\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1as = "1234567890", k = 90\n\u8f93\u51fa\uff1a34\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length <= 10^5.
  • \n\t
  • s \u53ea\u5305\u542b\u6570\u5b57\u4e14\u4e0d\u5305\u542b\u524d\u5bfc 0 \u3002
  • \n\t
  • 1 <= k <= 10^9.
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numberOfArrays(string s, int k) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numberOfArrays(String s, int k) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numberOfArrays(self, s, k):\n \"\"\"\n :type s: str\n :type k: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numberOfArrays(self, s: str, k: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numberOfArrays(char * s, int k){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumberOfArrays(string s, int k) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number} k\n * @return {number}\n */\nvar numberOfArrays = function(s, k) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer} k\n# @return {Integer}\ndef number_of_arrays(s, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numberOfArrays(_ s: String, _ k: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numberOfArrays(s string, k int) int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numberOfArrays(s: String, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numberOfArrays(s: String, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn number_of_arrays(s: String, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer $k\n * @return Integer\n */\n function numberOfArrays($s, $k) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numberOfArrays(s: string, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (number-of-arrays s k)\n (-> string? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1416](https://leetcode-cn.com/problems/restore-the-array)", "[\u6062\u590d\u6570\u7ec4](/solution/1400-1499/1416.Restore%20The%20Array/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1416](https://leetcode.com/problems/restore-the-array)", "[Restore The Array](/solution/1400-1499/1416.Restore%20The%20Array/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1516", "frontend_question_id": "1415", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/the-k-th-lexicographical-string-of-all-happy-strings-of-length-n", "url_en": "https://leetcode.com/problems/the-k-th-lexicographical-string-of-all-happy-strings-of-length-n", "relative_path_cn": "/solution/1400-1499/1415.The%20k-th%20Lexicographical%20String%20of%20All%20Happy%20Strings%20of%20Length%20n/README.md", "relative_path_en": "/solution/1400-1499/1415.The%20k-th%20Lexicographical%20String%20of%20All%20Happy%20Strings%20of%20Length%20n/README_EN.md", "title_cn": "\u957f\u5ea6\u4e3a n \u7684\u5f00\u5fc3\u5b57\u7b26\u4e32\u4e2d\u5b57\u5178\u5e8f\u7b2c k \u5c0f\u7684\u5b57\u7b26\u4e32", "title_en": "The k-th Lexicographical String of All Happy Strings of Length n", "question_title_slug": "the-k-th-lexicographical-string-of-all-happy-strings-of-length-n", "content_en": "

A happy string is a string that:

\r\n\r\n
    \r\n\t
  • consists only of letters of the set ['a', 'b', 'c'].
  • \r\n\t
  • s[i] != s[i + 1] for all values of i from 1 to s.length - 1 (string is 1-indexed).
  • \r\n
\r\n\r\n

For example, strings "abc", "ac", "b" and "abcbabcbcb" are all happy strings and strings "aa", "baa" and "ababbc" are not happy strings.

\r\n\r\n

Given two integers n and k, consider a list of all happy strings of length n sorted in lexicographical order.

\r\n\r\n

Return the kth string of this list or return an empty string if there are less than k happy strings of length n.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: n = 1, k = 3\r\nOutput: "c"\r\nExplanation: The list ["a", "b", "c"] contains all happy strings of length 1. The third string is "c".\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: n = 1, k = 4\r\nOutput: ""\r\nExplanation: There are only 3 happy strings of length 1.\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: n = 3, k = 9\r\nOutput: "cab"\r\nExplanation: There are 12 different happy string of length 3 ["aba", "abc", "aca", "acb", "bab", "bac", "bca", "bcb", "cab", "cac", "cba", "cbc"]. You will find the 9th string = "cab"\r\n
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: n = 2, k = 7\r\nOutput: ""\r\n
\r\n\r\n

Example 5:

\r\n\r\n
\r\nInput: n = 10, k = 100\r\nOutput: "abacbabacb"\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= n <= 10
  • \r\n\t
  • 1 <= k <= 100
  • \r\n
\r\n\r\n
 
", "content_cn": "

\u4e00\u4e2a \u300c\u5f00\u5fc3\u5b57\u7b26\u4e32\u300d\u5b9a\u4e49\u4e3a\uff1a

\n\n
    \n\t
  • \u4ec5\u5305\u542b\u5c0f\u5199\u5b57\u6bcd ['a', 'b', 'c'].
  • \n\t
  • \u5bf9\u6240\u6709\u5728 1 \u5230 s.length - 1 \u4e4b\u95f4\u7684 i \uff0c\u6ee1\u8db3 s[i] != s[i + 1] \uff08\u5b57\u7b26\u4e32\u7684\u4e0b\u6807\u4ece 1 \u5f00\u59cb\uff09\u3002
  • \n
\n\n

\u6bd4\u65b9\u8bf4\uff0c\u5b57\u7b26\u4e32 "abc"\uff0c"ac"\uff0c"b" \u548c "abcbabcbcb" \u90fd\u662f\u5f00\u5fc3\u5b57\u7b26\u4e32\uff0c\u4f46\u662f "aa"\uff0c"baa" \u548c "ababbc" \u90fd\u4e0d\u662f\u5f00\u5fc3\u5b57\u7b26\u4e32\u3002

\n\n

\u7ed9\u4f60\u4e24\u4e2a\u6574\u6570 n \u548c k \uff0c\u4f60\u9700\u8981\u5c06\u957f\u5ea6\u4e3a n \u7684\u6240\u6709\u5f00\u5fc3\u5b57\u7b26\u4e32\u6309\u5b57\u5178\u5e8f\u6392\u5e8f\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u6392\u5e8f\u540e\u7684\u7b2c k \u4e2a\u5f00\u5fc3\u5b57\u7b26\u4e32\uff0c\u5982\u679c\u957f\u5ea6\u4e3a n \u7684\u5f00\u5fc3\u5b57\u7b26\u4e32\u5c11\u4e8e k \u4e2a\uff0c\u90a3\u4e48\u8bf7\u4f60\u8fd4\u56de \u7a7a\u5b57\u7b26\u4e32 \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1an = 1, k = 3\n\u8f93\u51fa\uff1a"c"\n\u89e3\u91ca\uff1a\u5217\u8868 ["a", "b", "c"] \u5305\u542b\u4e86\u6240\u6709\u957f\u5ea6\u4e3a 1 \u7684\u5f00\u5fc3\u5b57\u7b26\u4e32\u3002\u6309\u7167\u5b57\u5178\u5e8f\u6392\u5e8f\u540e\u7b2c\u4e09\u4e2a\u5b57\u7b26\u4e32\u4e3a "c" \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1an = 1, k = 4\n\u8f93\u51fa\uff1a""\n\u89e3\u91ca\uff1a\u957f\u5ea6\u4e3a 1 \u7684\u5f00\u5fc3\u5b57\u7b26\u4e32\u53ea\u6709 3 \u4e2a\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1an = 3, k = 9\n\u8f93\u51fa\uff1a"cab"\n\u89e3\u91ca\uff1a\u957f\u5ea6\u4e3a 3 \u7684\u5f00\u5fc3\u5b57\u7b26\u4e32\u603b\u5171\u6709 12 \u4e2a ["aba", "abc", "aca", "acb", "bab", "bac", "bca", "bcb", "cab", "cac", "cba", "cbc"] \u3002\u7b2c 9 \u4e2a\u5b57\u7b26\u4e32\u4e3a "cab"\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1an = 2, k = 7\n\u8f93\u51fa\uff1a""\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1an = 10, k = 100\n\u8f93\u51fa\uff1a"abacbabacb"\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 10
  • \n\t
  • 1 <= k <= 100
  • \n
\n\n

 

\n", "tags_en": ["Backtracking"], "tags_cn": ["\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string getHappyString(int n, int k) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String getHappyString(int n, int k) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getHappyString(self, n, k):\n \"\"\"\n :type n: int\n :type k: int\n :rtype: str\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getHappyString(self, n: int, k: int) -> str:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * getHappyString(int n, int k){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string GetHappyString(int n, int k) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} k\n * @return {string}\n */\nvar getHappyString = function(n, k) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} k\n# @return {String}\ndef get_happy_string(n, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getHappyString(_ n: Int, _ k: Int) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getHappyString(n int, k int) string {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getHappyString(n: Int, k: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getHappyString(n: Int, k: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_happy_string(n: i32, k: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $k\n * @return String\n */\n function getHappyString($n, $k) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getHappyString(n: number, k: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-happy-string n k)\n (-> exact-integer? exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1415](https://leetcode-cn.com/problems/the-k-th-lexicographical-string-of-all-happy-strings-of-length-n)", "[\u957f\u5ea6\u4e3a n \u7684\u5f00\u5fc3\u5b57\u7b26\u4e32\u4e2d\u5b57\u5178\u5e8f\u7b2c k \u5c0f\u7684\u5b57\u7b26\u4e32](/solution/1400-1499/1415.The%20k-th%20Lexicographical%20String%20of%20All%20Happy%20Strings%20of%20Length%20n/README.md)", "`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1415](https://leetcode.com/problems/the-k-th-lexicographical-string-of-all-happy-strings-of-length-n)", "[The k-th Lexicographical String of All Happy Strings of Length n](/solution/1400-1499/1415.The%20k-th%20Lexicographical%20String%20of%20All%20Happy%20Strings%20of%20Length%20n/README_EN.md)", "`Backtracking`", "Medium", ""]}, {"question_id": "1515", "frontend_question_id": "1414", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-the-minimum-number-of-fibonacci-numbers-whose-sum-is-k", "url_en": "https://leetcode.com/problems/find-the-minimum-number-of-fibonacci-numbers-whose-sum-is-k", "relative_path_cn": "/solution/1400-1499/1414.Find%20the%20Minimum%20Number%20of%20Fibonacci%20Numbers%20Whose%20Sum%20Is%20K/README.md", "relative_path_en": "/solution/1400-1499/1414.Find%20the%20Minimum%20Number%20of%20Fibonacci%20Numbers%20Whose%20Sum%20Is%20K/README_EN.md", "title_cn": "\u548c\u4e3a K \u7684\u6700\u5c11\u6590\u6ce2\u90a3\u5951\u6570\u5b57\u6570\u76ee", "title_en": "Find the Minimum Number of Fibonacci Numbers Whose Sum Is K", "question_title_slug": "find-the-minimum-number-of-fibonacci-numbers-whose-sum-is-k", "content_en": "

Given an integer k, return the minimum number of Fibonacci numbers whose sum is equal to k. The same Fibonacci number can be used multiple times.

\n\n

The Fibonacci numbers are defined as:

\n\n
    \n\t
  • F1 = 1
  • \n\t
  • F2 = 1
  • \n\t
  • Fn = Fn-1 + Fn-2 for n > 2.
  • \n
\nIt is guaranteed that for the given constraints we can always find such Fibonacci numbers that sum up to k.\n

 

\n

Example 1:

\n\n
\nInput: k = 7\nOutput: 2 \nExplanation: The Fibonacci numbers are: 1, 1, 2, 3, 5, 8, 13, ... \nFor k = 7 we can use 2 + 5 = 7.
\n\n

Example 2:

\n\n
\nInput: k = 10\nOutput: 2 \nExplanation: For k = 10 we can use 2 + 8 = 10.\n
\n\n

Example 3:

\n\n
\nInput: k = 19\nOutput: 3 \nExplanation: For k = 19 we can use 1 + 5 + 13 = 19.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= k <= 10^9
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u6570\u5b57 k \uff0c\u8bf7\u4f60\u8fd4\u56de\u548c\u4e3a k \u7684\u6590\u6ce2\u90a3\u5951\u6570\u5b57\u7684\u6700\u5c11\u6570\u76ee\uff0c\u5176\u4e2d\uff0c\u6bcf\u4e2a\u6590\u6ce2\u90a3\u5951\u6570\u5b57\u90fd\u53ef\u4ee5\u88ab\u4f7f\u7528\u591a\u6b21\u3002

\n\n

\u6590\u6ce2\u90a3\u5951\u6570\u5b57\u5b9a\u4e49\u4e3a\uff1a

\n\n
    \n\t
  • F1 = 1
  • \n\t
  • F2 = 1
  • \n\t
  • Fn = Fn-1 + Fn-2 \uff0c \u5176\u4e2d n > 2 \u3002
  • \n
\n\n

\u6570\u636e\u4fdd\u8bc1\u5bf9\u4e8e\u7ed9\u5b9a\u7684 k \uff0c\u4e00\u5b9a\u80fd\u627e\u5230\u53ef\u884c\u89e3\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1ak = 7\n\u8f93\u51fa\uff1a2 \n\u89e3\u91ca\uff1a\u6590\u6ce2\u90a3\u5951\u6570\u5b57\u4e3a\uff1a1\uff0c1\uff0c2\uff0c3\uff0c5\uff0c8\uff0c13\uff0c……\n\u5bf9\u4e8e k = 7 \uff0c\u6211\u4eec\u53ef\u4ee5\u5f97\u5230 2 + 5 = 7 \u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1ak = 10\n\u8f93\u51fa\uff1a2 \n\u89e3\u91ca\uff1a\u5bf9\u4e8e k = 10 \uff0c\u6211\u4eec\u53ef\u4ee5\u5f97\u5230 2 + 8 = 10 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1ak = 19\n\u8f93\u51fa\uff1a3 \n\u89e3\u91ca\uff1a\u5bf9\u4e8e k = 19 \uff0c\u6211\u4eec\u53ef\u4ee5\u5f97\u5230 1 + 5 + 13 = 19 \u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= k <= 10^9
  • \n
\n", "tags_en": ["Greedy", "Array"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findMinFibonacciNumbers(int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findMinFibonacciNumbers(int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findMinFibonacciNumbers(self, k):\n \"\"\"\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findMinFibonacciNumbers(self, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findMinFibonacciNumbers(int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindMinFibonacciNumbers(int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} k\n * @return {number}\n */\nvar findMinFibonacciNumbers = function(k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} k\n# @return {Integer}\ndef find_min_fibonacci_numbers(k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findMinFibonacciNumbers(_ k: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findMinFibonacciNumbers(k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findMinFibonacciNumbers(k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findMinFibonacciNumbers(k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_min_fibonacci_numbers(k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $k\n * @return Integer\n */\n function findMinFibonacciNumbers($k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findMinFibonacciNumbers(k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-min-fibonacci-numbers k)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1414](https://leetcode-cn.com/problems/find-the-minimum-number-of-fibonacci-numbers-whose-sum-is-k)", "[\u548c\u4e3a K \u7684\u6700\u5c11\u6590\u6ce2\u90a3\u5951\u6570\u5b57\u6570\u76ee](/solution/1400-1499/1414.Find%20the%20Minimum%20Number%20of%20Fibonacci%20Numbers%20Whose%20Sum%20Is%20K/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1414](https://leetcode.com/problems/find-the-minimum-number-of-fibonacci-numbers-whose-sum-is-k)", "[Find the Minimum Number of Fibonacci Numbers Whose Sum Is K](/solution/1400-1499/1414.Find%20the%20Minimum%20Number%20of%20Fibonacci%20Numbers%20Whose%20Sum%20Is%20K/README_EN.md)", "`Greedy`,`Array`", "Medium", ""]}, {"question_id": "1514", "frontend_question_id": "1413", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-value-to-get-positive-step-by-step-sum", "url_en": "https://leetcode.com/problems/minimum-value-to-get-positive-step-by-step-sum", "relative_path_cn": "/solution/1400-1499/1413.Minimum%20Value%20to%20Get%20Positive%20Step%20by%20Step%20Sum/README.md", "relative_path_en": "/solution/1400-1499/1413.Minimum%20Value%20to%20Get%20Positive%20Step%20by%20Step%20Sum/README_EN.md", "title_cn": "\u9010\u6b65\u6c42\u548c\u5f97\u5230\u6b63\u6570\u7684\u6700\u5c0f\u503c", "title_en": "Minimum Value to Get Positive Step by Step Sum", "question_title_slug": "minimum-value-to-get-positive-step-by-step-sum", "content_en": "

Given an array of integers nums, you start with an initial positive value startValue.

\r\n\r\n

In each iteration, you calculate the step by step sum of startValue plus elements in nums (from left to right).

\r\n\r\n

Return the minimum positive value of startValue such that the step by step sum is never less than 1.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: nums = [-3,2,-3,4,2]\r\nOutput: 5\r\nExplanation: If you choose startValue = 4, in the third iteration your step by step sum is less than 1.\r\n                step by step sum\r\n                startValue = 4 | startValue = 5 | nums\r\n                  (4 -3 ) = 1  | (5 -3 ) = 2    |  -3\r\n                  (1 +2 ) = 3  | (2 +2 ) = 4    |   2\r\n                  (3 -3 ) = 0  | (4 -3 ) = 1    |  -3\r\n                  (0 +4 ) = 4  | (1 +4 ) = 5    |   4\r\n                  (4 +2 ) = 6  | (5 +2 ) = 7    |   2\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: nums = [1,2]\r\nOutput: 1\r\nExplanation: Minimum start value should be positive. \r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: nums = [1,-2,-3]\r\nOutput: 5\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= nums.length <= 100
  • \r\n\t
  • -100 <= nums[i] <= 100
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \u3002\u4f60\u53ef\u4ee5\u9009\u5b9a\u4efb\u610f\u7684 \u6b63\u6570 startValue \u4f5c\u4e3a\u521d\u59cb\u503c\u3002

\n\n

\u4f60\u9700\u8981\u4ece\u5de6\u5230\u53f3\u904d\u5386 nums \u6570\u7ec4\uff0c\u5e76\u5c06 startValue \u4f9d\u6b21\u7d2f\u52a0\u4e0a nums \u6570\u7ec4\u4e2d\u7684\u503c\u3002

\n\n

\u8bf7\u4f60\u5728\u786e\u4fdd\u7d2f\u52a0\u548c\u59cb\u7ec8\u5927\u4e8e\u7b49\u4e8e 1 \u7684\u524d\u63d0\u4e0b\uff0c\u9009\u51fa\u4e00\u4e2a\u6700\u5c0f\u7684 \u6b63\u6570 \u4f5c\u4e3a startValue \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [-3,2,-3,4,2]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u5982\u679c\u4f60\u9009\u62e9 startValue = 4\uff0c\u5728\u7b2c\u4e09\u6b21\u7d2f\u52a0\u65f6\uff0c\u548c\u5c0f\u4e8e 1 \u3002\n                \u7d2f\u52a0\u6c42\u548c\n                startValue = 4 | startValue = 5 | nums\n                  (4 -3 ) = 1  | (5 -3 ) = 2    |  -3\n                  (1 +2 ) = 3  | (2 +2 ) = 4    |   2\n                  (3 -3 ) = 0  | (4 -3 ) = 1    |  -3\n                  (0 +4 ) = 4  | (1 +4 ) = 5    |   4\n                  (4 +2 ) = 6  | (5 +2 ) = 7    |   2\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [1,2]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u6700\u5c0f\u7684 startValue \u9700\u8981\u662f\u6b63\u6570\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [1,-2,-3]\n\u8f93\u51fa\uff1a5\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 100
  • \n\t
  • -100 <= nums[i] <= 100
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minStartValue(vector& nums) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minStartValue(int[] nums) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minStartValue(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minStartValue(self, nums: List[int]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minStartValue(int* nums, int numsSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinStartValue(int[] nums) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar minStartValue = function(nums) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef min_start_value(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minStartValue(_ nums: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minStartValue(nums []int) int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minStartValue(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minStartValue(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_start_value(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function minStartValue($nums) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minStartValue(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-start-value nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1413](https://leetcode-cn.com/problems/minimum-value-to-get-positive-step-by-step-sum)", "[\u9010\u6b65\u6c42\u548c\u5f97\u5230\u6b63\u6570\u7684\u6700\u5c0f\u503c](/solution/1400-1499/1413.Minimum%20Value%20to%20Get%20Positive%20Step%20by%20Step%20Sum/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1413](https://leetcode.com/problems/minimum-value-to-get-positive-step-by-step-sum)", "[Minimum Value to Get Positive Step by Step Sum](/solution/1400-1499/1413.Minimum%20Value%20to%20Get%20Positive%20Step%20by%20Step%20Sum/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1513", "frontend_question_id": "1397", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-all-good-strings", "url_en": "https://leetcode.com/problems/find-all-good-strings", "relative_path_cn": "/solution/1300-1399/1397.Find%20All%20Good%20Strings/README.md", "relative_path_en": "/solution/1300-1399/1397.Find%20All%20Good%20Strings/README_EN.md", "title_cn": "\u627e\u5230\u6240\u6709\u597d\u5b57\u7b26\u4e32", "title_en": "Find All Good Strings", "question_title_slug": "find-all-good-strings", "content_en": "

Given the strings s1 and s2 of size n and the string evil, return the number of good strings.

\n\n

A good string has size n, it is alphabetically greater than or equal to s1, it is alphabetically smaller than or equal to s2, and it does not contain the string evil as a substring. Since the answer can be a huge number, return this modulo 109 + 7.

\n\n

 

\n

Example 1:

\n\n
\nInput: n = 2, s1 = "aa", s2 = "da", evil = "b"\nOutput: 51 \nExplanation: There are 25 good strings starting with 'a': "aa","ac","ad",...,"az". Then there are 25 good strings starting with 'c': "ca","cc","cd",...,"cz" and finally there is one good string starting with 'd': "da". \n
\n\n

Example 2:

\n\n
\nInput: n = 8, s1 = "leetcode", s2 = "leetgoes", evil = "leet"\nOutput: 0 \nExplanation: All strings greater than or equal to s1 and smaller than or equal to s2 start with the prefix "leet", therefore, there is not any good string.\n
\n\n

Example 3:

\n\n
\nInput: n = 2, s1 = "gx", s2 = "gz", evil = "x"\nOutput: 2\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • s1.length == n
  • \n\t
  • s2.length == n
  • \n\t
  • s1 <= s2
  • \n\t
  • 1 <= n <= 500
  • \n\t
  • 1 <= evil.length <= 50
  • \n\t
  • All strings consist of lowercase English letters.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e24\u4e2a\u957f\u5ea6\u4e3a n \u7684\u5b57\u7b26\u4e32 s1 \u548c s2 \uff0c\u4ee5\u53ca\u4e00\u4e2a\u5b57\u7b26\u4e32 evil \u3002\u8bf7\u4f60\u8fd4\u56de \u597d\u5b57\u7b26\u4e32 \u7684\u6570\u76ee\u3002

\n\n

\u597d\u5b57\u7b26\u4e32 \u7684\u5b9a\u4e49\u4e3a\uff1a\u5b83\u7684\u957f\u5ea6\u4e3a n \uff0c\u5b57\u5178\u5e8f\u5927\u4e8e\u7b49\u4e8e s1 \uff0c\u5b57\u5178\u5e8f\u5c0f\u4e8e\u7b49\u4e8e s2 \uff0c\u4e14\u4e0d\u5305\u542b evil \u4e3a\u5b50\u5b57\u7b26\u4e32\u3002

\n\n

\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u5f88\u5927\uff0c\u8bf7\u4f60\u8fd4\u56de\u7b54\u6848\u5bf9 10^9 + 7 \u53d6\u4f59\u7684\u7ed3\u679c\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1an = 2, s1 = "aa", s2 = "da", evil = "b"\n\u8f93\u51fa\uff1a51 \n\u89e3\u91ca\uff1a\u603b\u5171\u6709 25 \u4e2a\u4ee5 'a' \u5f00\u5934\u7684\u597d\u5b57\u7b26\u4e32\uff1a"aa"\uff0c"ac"\uff0c"ad"\uff0c...\uff0c"az"\u3002\u8fd8\u6709 25 \u4e2a\u4ee5 'c' \u5f00\u5934\u7684\u597d\u5b57\u7b26\u4e32\uff1a"ca"\uff0c"cc"\uff0c"cd"\uff0c...\uff0c"cz"\u3002\u6700\u540e\uff0c\u8fd8\u6709\u4e00\u4e2a\u4ee5 'd' \u5f00\u5934\u7684\u597d\u5b57\u7b26\u4e32\uff1a"da"\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1an = 8, s1 = "leetcode", s2 = "leetgoes", evil = "leet"\n\u8f93\u51fa\uff1a0 \n\u89e3\u91ca\uff1a\u6240\u6709\u5b57\u5178\u5e8f\u5927\u4e8e\u7b49\u4e8e s1 \u4e14\u5c0f\u4e8e\u7b49\u4e8e s2 \u7684\u5b57\u7b26\u4e32\u90fd\u4ee5 evil \u5b57\u7b26\u4e32 "leet" \u5f00\u5934\u3002\u6240\u4ee5\u6ca1\u6709\u597d\u5b57\u7b26\u4e32\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1an = 2, s1 = "gx", s2 = "gz", evil = "x"\n\u8f93\u51fa\uff1a2\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • s1.length == n
  • \n\t
  • s2.length == n
  • \n\t
  • s1 <= s2
  • \n\t
  • 1 <= n <= 500
  • \n\t
  • 1 <= evil.length <= 50
  • \n\t
  • \u6240\u6709\u5b57\u7b26\u4e32\u90fd\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findGoodStrings(int n, string s1, string s2, string evil) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findGoodStrings(int n, String s1, String s2, String evil) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findGoodStrings(self, n, s1, s2, evil):\n \"\"\"\n :type n: int\n :type s1: str\n :type s2: str\n :type evil: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findGoodStrings(self, n: int, s1: str, s2: str, evil: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findGoodStrings(int n, char * s1, char * s2, char * evil){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindGoodStrings(int n, string s1, string s2, string evil) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {string} s1\n * @param {string} s2\n * @param {string} evil\n * @return {number}\n */\nvar findGoodStrings = function(n, s1, s2, evil) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {String} s1\n# @param {String} s2\n# @param {String} evil\n# @return {Integer}\ndef find_good_strings(n, s1, s2, evil)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findGoodStrings(_ n: Int, _ s1: String, _ s2: String, _ evil: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findGoodStrings(n int, s1 string, s2 string, evil string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findGoodStrings(n: Int, s1: String, s2: String, evil: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findGoodStrings(n: Int, s1: String, s2: String, evil: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_good_strings(n: i32, s1: String, s2: String, evil: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param String $s1\n * @param String $s2\n * @param String $evil\n * @return Integer\n */\n function findGoodStrings($n, $s1, $s2, $evil) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findGoodStrings(n: number, s1: string, s2: string, evil: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-good-strings n s1 s2 evil)\n (-> exact-integer? string? string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1397](https://leetcode-cn.com/problems/find-all-good-strings)", "[\u627e\u5230\u6240\u6709\u597d\u5b57\u7b26\u4e32](/solution/1300-1399/1397.Find%20All%20Good%20Strings/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1397](https://leetcode.com/problems/find-all-good-strings)", "[Find All Good Strings](/solution/1300-1399/1397.Find%20All%20Good%20Strings/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1512", "frontend_question_id": "1396", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/design-underground-system", "url_en": "https://leetcode.com/problems/design-underground-system", "relative_path_cn": "/solution/1300-1399/1396.Design%20Underground%20System/README.md", "relative_path_en": "/solution/1300-1399/1396.Design%20Underground%20System/README_EN.md", "title_cn": "\u8bbe\u8ba1\u5730\u94c1\u7cfb\u7edf", "title_en": "Design Underground System", "question_title_slug": "design-underground-system", "content_en": "

An underground railway system is keeping track of customer travel times between different stations. They are using this data to calculate the average time it takes to travel from one station to another.

\n\n

Implement the UndergroundSystem class:

\n\n
    \n\t
  • void checkIn(int id, string stationName, int t)\n\n\t
      \n\t\t
    • A customer with a card ID equal to id, checks in at the station stationName at time t.
    • \n\t\t
    • A customer can only be checked into one place at a time.
    • \n\t
    \n\t
  • \n\t
  • void checkOut(int id, string stationName, int t)\n\t
      \n\t\t
    • A customer with a card ID equal to id, checks out from the station stationName at time t.
    • \n\t
    \n\t
  • \n\t
  • double getAverageTime(string startStation, string endStation)\n\t
      \n\t\t
    • Returns the average time it takes to travel from startStation to endStation.
    • \n\t\t
    • The average time is computed from all the previous traveling times from startStation to endStation that happened directly, meaning a check in at startStation followed by a check out from endStation.
    • \n\t\t
    • The time it takes to travel from startStation to endStation may be different from the time it takes to travel from endStation to startStation.
    • \n\t\t
    • There will be at least one customer that has traveled from startStation to endStation before getAverageTime is called.
    • \n\t
    \n\t
  • \n
\n\n

You may assume all calls to the checkIn and checkOut methods are consistent. If a customer checks in at time t1 then checks out at time t2, then t1 < t2. All events happen in chronological order.

\n\n

 

\n

Example 1:

\n\n
\nInput\n["UndergroundSystem","checkIn","checkIn","checkIn","checkOut","checkOut","checkOut","getAverageTime","getAverageTime","checkIn","getAverageTime","checkOut","getAverageTime"]\n[[],[45,"Leyton",3],[32,"Paradise",8],[27,"Leyton",10],[45,"Waterloo",15],[27,"Waterloo",20],[32,"Cambridge",22],["Paradise","Cambridge"],["Leyton","Waterloo"],[10,"Leyton",24],["Leyton","Waterloo"],[10,"Waterloo",38],["Leyton","Waterloo"]]\n\nOutput\n[null,null,null,null,null,null,null,14.00000,11.00000,null,11.00000,null,12.00000]\n\nExplanation\nUndergroundSystem undergroundSystem = new UndergroundSystem();\nundergroundSystem.checkIn(45, "Leyton", 3);\nundergroundSystem.checkIn(32, "Paradise", 8);\nundergroundSystem.checkIn(27, "Leyton", 10);\nundergroundSystem.checkOut(45, "Waterloo", 15);  // Customer 45 "Leyton" -> "Waterloo" in 15-3 = 12\nundergroundSystem.checkOut(27, "Waterloo", 20);  // Customer 27 "Leyton" -> "Waterloo" in 20-10 = 10\nundergroundSystem.checkOut(32, "Cambridge", 22); // Customer 32 "Paradise" -> "Cambridge" in 22-8 = 14\nundergroundSystem.getAverageTime("Paradise", "Cambridge"); // return 14.00000. One trip "Paradise" -> "Cambridge", (14) / 1 = 14\nundergroundSystem.getAverageTime("Leyton", "Waterloo");    // return 11.00000. Two trips "Leyton" -> "Waterloo", (10 + 12) / 2 = 11\nundergroundSystem.checkIn(10, "Leyton", 24);\nundergroundSystem.getAverageTime("Leyton", "Waterloo");    // return 11.00000\nundergroundSystem.checkOut(10, "Waterloo", 38);  // Customer 10 "Leyton" -> "Waterloo" in 38-24 = 14\nundergroundSystem.getAverageTime("Leyton", "Waterloo");    // return 12.00000. Three trips "Leyton" -> "Waterloo", (10 + 12 + 14) / 3 = 12\n
\n\n

Example 2:

\n\n
\nInput\n["UndergroundSystem","checkIn","checkOut","getAverageTime","checkIn","checkOut","getAverageTime","checkIn","checkOut","getAverageTime"]\n[[],[10,"Leyton",3],[10,"Paradise",8],["Leyton","Paradise"],[5,"Leyton",10],[5,"Paradise",16],["Leyton","Paradise"],[2,"Leyton",21],[2,"Paradise",30],["Leyton","Paradise"]]\n\nOutput\n[null,null,null,5.00000,null,null,5.50000,null,null,6.66667]\n\nExplanation\nUndergroundSystem undergroundSystem = new UndergroundSystem();\nundergroundSystem.checkIn(10, "Leyton", 3);\nundergroundSystem.checkOut(10, "Paradise", 8); // Customer 10 "Leyton" -> "Paradise" in 8-3 = 5\nundergroundSystem.getAverageTime("Leyton", "Paradise"); // return 5.00000, (5) / 1 = 5\nundergroundSystem.checkIn(5, "Leyton", 10);\nundergroundSystem.checkOut(5, "Paradise", 16); // Customer 5 "Leyton" -> "Paradise" in 16-10 = 6\nundergroundSystem.getAverageTime("Leyton", "Paradise"); // return 5.50000, (5 + 6) / 2 = 5.5\nundergroundSystem.checkIn(2, "Leyton", 21);\nundergroundSystem.checkOut(2, "Paradise", 30); // Customer 2 "Leyton" -> "Paradise" in 30-21 = 9\nundergroundSystem.getAverageTime("Leyton", "Paradise"); // return 6.66667, (5 + 6 + 9) / 3 = 6.66667\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= id, t <= 106
  • \n\t
  • 1 <= stationName.length, startStation.length, endStation.length <= 10
  • \n\t
  • All strings consist of uppercase and lowercase English letters and digits.
  • \n\t
  • There will be at most 2 * 104 calls in total to checkIn, checkOut, and getAverageTime.
  • \n\t
  • Answers within 10-5 of the actual value will be accepted.
  • \n
\n", "content_cn": "

\u8bf7\u4f60\u5b9e\u73b0\u4e00\u4e2a\u7c7b UndergroundSystem \uff0c\u5b83\u652f\u6301\u4ee5\u4e0b 3 \u79cd\u65b9\u6cd5\uff1a

\n\n

1. checkIn(int id, string stationName, int t)

\n\n
    \n\t
  • \u7f16\u53f7\u4e3a id \u7684\u4e58\u5ba2\u5728 t \u65f6\u523b\u8fdb\u5165\u5730\u94c1\u7ad9 stationName \u3002
  • \n\t
  • \u4e00\u4e2a\u4e58\u5ba2\u5728\u540c\u4e00\u65f6\u95f4\u53ea\u80fd\u5728\u4e00\u4e2a\u5730\u94c1\u7ad9\u8fdb\u5165\u6216\u8005\u79bb\u5f00\u3002
  • \n
\n\n

2. checkOut(int id, string stationName, int t)

\n\n
    \n\t
  • \u7f16\u53f7\u4e3a id \u7684\u4e58\u5ba2\u5728 t \u65f6\u523b\u79bb\u5f00\u5730\u94c1\u7ad9 stationName \u3002
  • \n
\n\n

3. getAverageTime(string startStation, string endStation) 

\n\n
    \n\t
  • \u8fd4\u56de\u4ece\u5730\u94c1\u7ad9 startStation \u5230\u5730\u94c1\u7ad9 endStation \u7684\u5e73\u5747\u82b1\u8d39\u65f6\u95f4\u3002
  • \n\t
  • \u5e73\u5747\u65f6\u95f4\u8ba1\u7b97\u7684\u884c\u7a0b\u5305\u62ec\u5f53\u524d\u4e3a\u6b62\u6240\u6709\u4ece startStation \u76f4\u63a5\u5230\u8fbe endStation \u7684\u884c\u7a0b\u3002
  • \n\t
  • \u8c03\u7528 getAverageTime \u65f6\uff0c\u8be2\u95ee\u7684\u8def\u7ebf\u81f3\u5c11\u5305\u542b\u4e00\u8d9f\u884c\u7a0b\u3002
  • \n
\n\n

\u4f60\u53ef\u4ee5\u5047\u8bbe\u6240\u6709\u5bf9 checkIn \u548c checkOut \u7684\u8c03\u7528\u90fd\u662f\u7b26\u5408\u903b\u8f91\u7684\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u5982\u679c\u4e00\u4e2a\u987e\u5ba2\u5728 t1 \u65f6\u523b\u5230\u8fbe\u67d0\u4e2a\u5730\u94c1\u7ad9\uff0c\u90a3\u4e48\u4ed6\u79bb\u5f00\u7684\u65f6\u95f4 t2 \u4e00\u5b9a\u6ee1\u8db3 t2 > t1 \u3002\u6240\u6709\u7684\u4e8b\u4ef6\u90fd\u6309\u65f6\u95f4\u987a\u5e8f\u7ed9\u51fa\u3002

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1a\n["UndergroundSystem","checkIn","checkIn","checkIn","checkOut","checkOut","checkOut","getAverageTime","getAverageTime","checkIn","getAverageTime","checkOut","getAverageTime"]\n[[],[45,"Leyton",3],[32,"Paradise",8],[27,"Leyton",10],[45,"Waterloo",15],[27,"Waterloo",20],[32,"Cambridge",22],["Paradise","Cambridge"],["Leyton","Waterloo"],[10,"Leyton",24],["Leyton","Waterloo"],[10,"Waterloo",38],["Leyton","Waterloo"]]\n\n\u8f93\u51fa\uff1a\n[null,null,null,null,null,null,null,14.0,11.0,null,11.0,null,12.0]\n\n\u89e3\u91ca\uff1a\nUndergroundSystem undergroundSystem = new UndergroundSystem();\nundergroundSystem.checkIn(45, "Leyton", 3);\nundergroundSystem.checkIn(32, "Paradise", 8);\nundergroundSystem.checkIn(27, "Leyton", 10);\nundergroundSystem.checkOut(45, "Waterloo", 15);\nundergroundSystem.checkOut(27, "Waterloo", 20);\nundergroundSystem.checkOut(32, "Cambridge", 22);\nundergroundSystem.getAverageTime("Paradise", "Cambridge");       // \u8fd4\u56de 14.0\u3002\u4ece "Paradise"\uff08\u65f6\u523b 8\uff09\u5230 "Cambridge"(\u65f6\u523b 22)\u7684\u884c\u7a0b\u53ea\u6709\u4e00\u8d9f\nundergroundSystem.getAverageTime("Leyton", "Waterloo");          // \u8fd4\u56de 11.0\u3002\u603b\u5171\u6709 2 \u8eba\u4ece "Leyton" \u5230 "Waterloo" \u7684\u884c\u7a0b\uff0c\u7f16\u53f7\u4e3a id=45 \u7684\u4e58\u5ba2\u51fa\u53d1\u4e8e time=3 \u5230\u8fbe\u4e8e time=15\uff0c\u7f16\u53f7\u4e3a id=27 \u7684\u4e58\u5ba2\u4e8e time=10 \u51fa\u53d1\u4e8e time=20 \u5230\u8fbe\u3002\u6240\u4ee5\u5e73\u5747\u65f6\u95f4\u4e3a ( (15-3) + (20-10) ) / 2 = 11.0\nundergroundSystem.checkIn(10, "Leyton", 24);\nundergroundSystem.getAverageTime("Leyton", "Waterloo");          // \u8fd4\u56de 11.0\nundergroundSystem.checkOut(10, "Waterloo", 38);\nundergroundSystem.getAverageTime("Leyton", "Waterloo");          // \u8fd4\u56de 12.0
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u603b\u5171\u6700\u591a\u6709 20000 \u6b21\u64cd\u4f5c\u3002
  • \n\t
  • 1 <= id, t <= 10^6
  • \n\t
  • \u6240\u6709\u7684\u5b57\u7b26\u4e32\u5305\u542b\u5927\u5199\u5b57\u6bcd\uff0c\u5c0f\u5199\u5b57\u6bcd\u548c\u6570\u5b57\u3002
  • \n\t
  • 1 <= stationName.length <= 10
  • \n\t
  • \u4e0e\u6807\u51c6\u7b54\u6848\u8bef\u5dee\u5728 10^-5 \u4ee5\u5185\u7684\u7ed3\u679c\u90fd\u89c6\u4e3a\u6b63\u786e\u7ed3\u679c\u3002
  • \n
\n", "tags_en": ["Design"], "tags_cn": ["\u8bbe\u8ba1"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class UndergroundSystem {\npublic:\n UndergroundSystem() {\n\n }\n \n void checkIn(int id, string stationName, int t) {\n\n }\n \n void checkOut(int id, string stationName, int t) {\n\n }\n \n double getAverageTime(string startStation, string endStation) {\n\n }\n};\n\n/**\n * Your UndergroundSystem object will be instantiated and called as such:\n * UndergroundSystem* obj = new UndergroundSystem();\n * obj->checkIn(id,stationName,t);\n * obj->checkOut(id,stationName,t);\n * double param_3 = obj->getAverageTime(startStation,endStation);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class UndergroundSystem {\n\n public UndergroundSystem() {\n\n }\n \n public void checkIn(int id, String stationName, int t) {\n\n }\n \n public void checkOut(int id, String stationName, int t) {\n\n }\n \n public double getAverageTime(String startStation, String endStation) {\n\n }\n}\n\n/**\n * Your UndergroundSystem object will be instantiated and called as such:\n * UndergroundSystem obj = new UndergroundSystem();\n * obj.checkIn(id,stationName,t);\n * obj.checkOut(id,stationName,t);\n * double param_3 = obj.getAverageTime(startStation,endStation);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class UndergroundSystem(object):\n\n def __init__(self):\n\n\n def checkIn(self, id, stationName, t):\n \"\"\"\n :type id: int\n :type stationName: str\n :type t: int\n :rtype: None\n \"\"\"\n\n\n def checkOut(self, id, stationName, t):\n \"\"\"\n :type id: int\n :type stationName: str\n :type t: int\n :rtype: None\n \"\"\"\n\n\n def getAverageTime(self, startStation, endStation):\n \"\"\"\n :type startStation: str\n :type endStation: str\n :rtype: float\n \"\"\"\n\n\n\n# Your UndergroundSystem object will be instantiated and called as such:\n# obj = UndergroundSystem()\n# obj.checkIn(id,stationName,t)\n# obj.checkOut(id,stationName,t)\n# param_3 = obj.getAverageTime(startStation,endStation)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class UndergroundSystem:\n\n def __init__(self):\n\n\n def checkIn(self, id: int, stationName: str, t: int) -> None:\n\n\n def checkOut(self, id: int, stationName: str, t: int) -> None:\n\n\n def getAverageTime(self, startStation: str, endStation: str) -> float:\n\n\n\n# Your UndergroundSystem object will be instantiated and called as such:\n# obj = UndergroundSystem()\n# obj.checkIn(id,stationName,t)\n# obj.checkOut(id,stationName,t)\n# param_3 = obj.getAverageTime(startStation,endStation)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} UndergroundSystem;\n\n\nUndergroundSystem* undergroundSystemCreate() {\n \n}\n\nvoid undergroundSystemCheckIn(UndergroundSystem* obj, int id, char * stationName, int t) {\n \n}\n\nvoid undergroundSystemCheckOut(UndergroundSystem* obj, int id, char * stationName, int t) {\n \n}\n\ndouble undergroundSystemGetAverageTime(UndergroundSystem* obj, char * startStation, char * endStation) {\n \n}\n\nvoid undergroundSystemFree(UndergroundSystem* obj) {\n \n}\n\n/**\n * Your UndergroundSystem struct will be instantiated and called as such:\n * UndergroundSystem* obj = undergroundSystemCreate();\n * undergroundSystemCheckIn(obj, id, stationName, t);\n \n * undergroundSystemCheckOut(obj, id, stationName, t);\n \n * double param_3 = undergroundSystemGetAverageTime(obj, startStation, endStation);\n \n * undergroundSystemFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class UndergroundSystem {\n\n public UndergroundSystem() {\n\n }\n \n public void CheckIn(int id, string stationName, int t) {\n\n }\n \n public void CheckOut(int id, string stationName, int t) {\n\n }\n \n public double GetAverageTime(string startStation, string endStation) {\n\n }\n}\n\n/**\n * Your UndergroundSystem object will be instantiated and called as such:\n * UndergroundSystem obj = new UndergroundSystem();\n * obj.CheckIn(id,stationName,t);\n * obj.CheckOut(id,stationName,t);\n * double param_3 = obj.GetAverageTime(startStation,endStation);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "\nvar UndergroundSystem = function() {\n\n};\n\n/** \n * @param {number} id \n * @param {string} stationName \n * @param {number} t\n * @return {void}\n */\nUndergroundSystem.prototype.checkIn = function(id, stationName, t) {\n\n};\n\n/** \n * @param {number} id \n * @param {string} stationName \n * @param {number} t\n * @return {void}\n */\nUndergroundSystem.prototype.checkOut = function(id, stationName, t) {\n\n};\n\n/** \n * @param {string} startStation \n * @param {string} endStation\n * @return {number}\n */\nUndergroundSystem.prototype.getAverageTime = function(startStation, endStation) {\n\n};\n\n/**\n * Your UndergroundSystem object will be instantiated and called as such:\n * var obj = new UndergroundSystem()\n * obj.checkIn(id,stationName,t)\n * obj.checkOut(id,stationName,t)\n * var param_3 = obj.getAverageTime(startStation,endStation)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class UndergroundSystem\n def initialize()\n\n end\n\n\n=begin\n :type id: Integer\n :type station_name: String\n :type t: Integer\n :rtype: Void\n=end\n def check_in(id, station_name, t)\n\n end\n\n\n=begin\n :type id: Integer\n :type station_name: String\n :type t: Integer\n :rtype: Void\n=end\n def check_out(id, station_name, t)\n\n end\n\n\n=begin\n :type start_station: String\n :type end_station: String\n :rtype: Float\n=end\n def get_average_time(start_station, end_station)\n\n end\n\n\nend\n\n# Your UndergroundSystem object will be instantiated and called as such:\n# obj = UndergroundSystem.new()\n# obj.check_in(id, station_name, t)\n# obj.check_out(id, station_name, t)\n# param_3 = obj.get_average_time(start_station, end_station)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass UndergroundSystem {\n\n init() {\n\n }\n \n func checkIn(_ id: Int, _ stationName: String, _ t: Int) {\n\n }\n \n func checkOut(_ id: Int, _ stationName: String, _ t: Int) {\n\n }\n \n func getAverageTime(_ startStation: String, _ endStation: String) -> Double {\n\n }\n}\n\n/**\n * Your UndergroundSystem object will be instantiated and called as such:\n * let obj = UndergroundSystem()\n * obj.checkIn(id, stationName, t)\n * obj.checkOut(id, stationName, t)\n * let ret_3: Double = obj.getAverageTime(startStation, endStation)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type UndergroundSystem struct {\n\n}\n\n\nfunc Constructor() UndergroundSystem {\n\n}\n\n\nfunc (this *UndergroundSystem) CheckIn(id int, stationName string, t int) {\n\n}\n\n\nfunc (this *UndergroundSystem) CheckOut(id int, stationName string, t int) {\n\n}\n\n\nfunc (this *UndergroundSystem) GetAverageTime(startStation string, endStation string) float64 {\n\n}\n\n\n/**\n * Your UndergroundSystem object will be instantiated and called as such:\n * obj := Constructor();\n * obj.CheckIn(id,stationName,t);\n * obj.CheckOut(id,stationName,t);\n * param_3 := obj.GetAverageTime(startStation,endStation);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class UndergroundSystem() {\n\n def checkIn(id: Int, stationName: String, t: Int) {\n\n }\n\n def checkOut(id: Int, stationName: String, t: Int) {\n\n }\n\n def getAverageTime(startStation: String, endStation: String): Double = {\n\n }\n\n}\n\n/**\n * Your UndergroundSystem object will be instantiated and called as such:\n * var obj = new UndergroundSystem()\n * obj.checkIn(id,stationName,t)\n * obj.checkOut(id,stationName,t)\n * var param_3 = obj.getAverageTime(startStation,endStation)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class UndergroundSystem() {\n\n fun checkIn(id: Int, stationName: String, t: Int) {\n\n }\n\n fun checkOut(id: Int, stationName: String, t: Int) {\n\n }\n\n fun getAverageTime(startStation: String, endStation: String): Double {\n\n }\n\n}\n\n/**\n * Your UndergroundSystem object will be instantiated and called as such:\n * var obj = UndergroundSystem()\n * obj.checkIn(id,stationName,t)\n * obj.checkOut(id,stationName,t)\n * var param_3 = obj.getAverageTime(startStation,endStation)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct UndergroundSystem {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl UndergroundSystem {\n\n fn new() -> Self {\n\n }\n \n fn check_in(&self, id: i32, station_name: String, t: i32) {\n\n }\n \n fn check_out(&self, id: i32, station_name: String, t: i32) {\n\n }\n \n fn get_average_time(&self, start_station: String, end_station: String) -> f64 {\n\n }\n}\n\n/**\n * Your UndergroundSystem object will be instantiated and called as such:\n * let obj = UndergroundSystem::new();\n * obj.check_in(id, stationName, t);\n * obj.check_out(id, stationName, t);\n * let ret_3: f64 = obj.get_average_time(startStation, endStation);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class UndergroundSystem {\n /**\n */\n function __construct() {\n\n }\n\n /**\n * @param Integer $id\n * @param String $stationName\n * @param Integer $t\n * @return NULL\n */\n function checkIn($id, $stationName, $t) {\n\n }\n\n /**\n * @param Integer $id\n * @param String $stationName\n * @param Integer $t\n * @return NULL\n */\n function checkOut($id, $stationName, $t) {\n\n }\n\n /**\n * @param String $startStation\n * @param String $endStation\n * @return Float\n */\n function getAverageTime($startStation, $endStation) {\n\n }\n}\n\n/**\n * Your UndergroundSystem object will be instantiated and called as such:\n * $obj = UndergroundSystem();\n * $obj->checkIn($id, $stationName, $t);\n * $obj->checkOut($id, $stationName, $t);\n * $ret_3 = $obj->getAverageTime($startStation, $endStation);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class UndergroundSystem {\n constructor() {\n\n }\n\n checkIn(id: number, stationName: string, t: number): void {\n\n }\n\n checkOut(id: number, stationName: string, t: number): void {\n\n }\n\n getAverageTime(startStation: string, endStation: string): number {\n\n }\n}\n\n/**\n * Your UndergroundSystem object will be instantiated and called as such:\n * var obj = new UndergroundSystem()\n * obj.checkIn(id,stationName,t)\n * obj.checkOut(id,stationName,t)\n * var param_3 = obj.getAverageTime(startStation,endStation)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define underground-system%\n (class object%\n (super-new)\n (init-field)\n \n ; check-in : exact-integer? string? exact-integer? -> void?\n (define/public (check-in id stationName t)\n\n )\n ; check-out : exact-integer? string? exact-integer? -> void?\n (define/public (check-out id stationName t)\n\n )\n ; get-average-time : string? string? -> flonum?\n (define/public (get-average-time startStation endStation)\n\n )))\n\n;; Your underground-system% object will be instantiated and called as such:\n;; (define obj (new underground-system%))\n;; (send obj check-in id station-name t)\n;; (send obj check-out id station-name t)\n;; (define param_3 (send obj get-average-time start-station end-station))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1396](https://leetcode-cn.com/problems/design-underground-system)", "[\u8bbe\u8ba1\u5730\u94c1\u7cfb\u7edf](/solution/1300-1399/1396.Design%20Underground%20System/README.md)", "`\u8bbe\u8ba1`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1396](https://leetcode.com/problems/design-underground-system)", "[Design Underground System](/solution/1300-1399/1396.Design%20Underground%20System/README_EN.md)", "`Design`", "Medium", ""]}, {"question_id": "1511", "frontend_question_id": "1395", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-number-of-teams", "url_en": "https://leetcode.com/problems/count-number-of-teams", "relative_path_cn": "/solution/1300-1399/1395.Count%20Number%20of%20Teams/README.md", "relative_path_en": "/solution/1300-1399/1395.Count%20Number%20of%20Teams/README_EN.md", "title_cn": "\u7edf\u8ba1\u4f5c\u6218\u5355\u4f4d\u6570", "title_en": "Count Number of Teams", "question_title_slug": "count-number-of-teams", "content_en": "

There are n soldiers standing in a line. Each soldier is assigned a unique rating value.

\n\n

You have to form a team of 3 soldiers amongst them under the following rules:

\n\n
    \n\t
  • Choose 3 soldiers with index (i, j, k) with rating (rating[i], rating[j], rating[k]).
  • \n\t
  • A team is valid if: (rating[i] < rating[j] < rating[k]) or (rating[i] > rating[j] > rating[k]) where (0 <= i < j < k < n).
  • \n
\n\n

Return the number of teams you can form given the conditions. (soldiers can be part of multiple teams).

\n\n

 

\n

Example 1:

\n\n
\nInput: rating = [2,5,3,4,1]\nOutput: 3\nExplanation: We can form three teams given the conditions. (2,3,4), (5,4,1), (5,3,1). \n
\n\n

Example 2:

\n\n
\nInput: rating = [2,1,3]\nOutput: 0\nExplanation: We can't form any team given the conditions.\n
\n\n

Example 3:

\n\n
\nInput: rating = [1,2,3,4]\nOutput: 4\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == rating.length
  • \n\t
  • 3 <= n <= 1000
  • \n\t
  • 1 <= rating[i] <= 105
  • \n\t
  • All the integers in rating are unique.
  • \n
\n", "content_cn": "

\u00a0n \u540d\u58eb\u5175\u7ad9\u6210\u4e00\u6392\u3002\u6bcf\u4e2a\u58eb\u5175\u90fd\u6709\u4e00\u4e2a \u72ec\u4e00\u65e0\u4e8c \u7684\u8bc4\u5206 rating \u3002

\n\n

\u6bcf 3 \u4e2a\u58eb\u5175\u53ef\u4ee5\u7ec4\u6210\u4e00\u4e2a\u4f5c\u6218\u5355\u4f4d\uff0c\u5206\u7ec4\u89c4\u5219\u5982\u4e0b\uff1a

\n\n
    \n\t
  • \u4ece\u961f\u4f0d\u4e2d\u9009\u51fa\u4e0b\u6807\u5206\u522b\u4e3a i\u3001j\u3001k \u7684 3 \u540d\u58eb\u5175\uff0c\u4ed6\u4eec\u7684\u8bc4\u5206\u5206\u522b\u4e3a rating[i]\u3001rating[j]\u3001rating[k]
  • \n\t
  • \u4f5c\u6218\u5355\u4f4d\u9700\u6ee1\u8db3\uff1a rating[i] < rating[j] < rating[k] \u6216\u8005 rating[i] > rating[j] > rating[k] \uff0c\u5176\u4e2d\u00a0 0\u00a0<= i <\u00a0j <\u00a0k <\u00a0n
  • \n
\n\n

\u8bf7\u4f60\u8fd4\u56de\u6309\u4e0a\u8ff0\u6761\u4ef6\u53ef\u4ee5\u7ec4\u5efa\u7684\u4f5c\u6218\u5355\u4f4d\u6570\u91cf\u3002\u6bcf\u4e2a\u58eb\u5175\u90fd\u53ef\u4ee5\u662f\u591a\u4e2a\u4f5c\u6218\u5355\u4f4d\u7684\u4e00\u90e8\u5206\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1arating = [2,5,3,4,1]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6211\u4eec\u53ef\u4ee5\u7ec4\u5efa\u4e09\u4e2a\u4f5c\u6218\u5355\u4f4d (2,3,4)\u3001(5,4,1)\u3001(5,3,1) \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1arating = [2,1,3]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6839\u636e\u9898\u76ee\u6761\u4ef6\uff0c\u6211\u4eec\u65e0\u6cd5\u7ec4\u5efa\u4f5c\u6218\u5355\u4f4d\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1arating = [1,2,3,4]\n\u8f93\u51fa\uff1a4\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • n == rating.length
  • \n\t
  • 3 <= n <= 1000
  • \n\t
  • 1 <= rating[i] <= 10^5
  • \n\t
  • rating\u00a0\u4e2d\u7684\u5143\u7d20\u90fd\u662f\u552f\u4e00\u7684
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numTeams(vector& rating) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numTeams(int[] rating) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numTeams(self, rating):\n \"\"\"\n :type rating: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numTeams(self, rating: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numTeams(int* rating, int ratingSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumTeams(int[] rating) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} rating\n * @return {number}\n */\nvar numTeams = function(rating) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} rating\n# @return {Integer}\ndef num_teams(rating)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numTeams(_ rating: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numTeams(rating []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numTeams(rating: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numTeams(rating: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_teams(rating: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $rating\n * @return Integer\n */\n function numTeams($rating) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numTeams(rating: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-teams rating)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1395](https://leetcode-cn.com/problems/count-number-of-teams)", "[\u7edf\u8ba1\u4f5c\u6218\u5355\u4f4d\u6570](/solution/1300-1399/1395.Count%20Number%20of%20Teams/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1395](https://leetcode.com/problems/count-number-of-teams)", "[Count Number of Teams](/solution/1300-1399/1395.Count%20Number%20of%20Teams/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "1510", "frontend_question_id": "1394", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-lucky-integer-in-an-array", "url_en": "https://leetcode.com/problems/find-lucky-integer-in-an-array", "relative_path_cn": "/solution/1300-1399/1394.Find%20Lucky%20Integer%20in%20an%20Array/README.md", "relative_path_en": "/solution/1300-1399/1394.Find%20Lucky%20Integer%20in%20an%20Array/README_EN.md", "title_cn": "\u627e\u51fa\u6570\u7ec4\u4e2d\u7684\u5e78\u8fd0\u6570", "title_en": "Find Lucky Integer in an Array", "question_title_slug": "find-lucky-integer-in-an-array", "content_en": "

Given an array of integers arr, a lucky integer is an integer which has a frequency in the array equal to its value.

\r\n\r\n

Return a lucky integer in the array. If there are multiple lucky integers return the largest of them. If there is no lucky integer return -1.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: arr = [2,2,3,4]\r\nOutput: 2\r\nExplanation: The only lucky number in the array is 2 because frequency[2] == 2.\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: arr = [1,2,2,3,3,3]\r\nOutput: 3\r\nExplanation: 1, 2 and 3 are all lucky numbers, return the largest of them.\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: arr = [2,2,2,3,3]\r\nOutput: -1\r\nExplanation: There are no lucky numbers in the array.\r\n
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: arr = [5]\r\nOutput: -1\r\n
\r\n\r\n

Example 5:

\r\n\r\n
\r\nInput: arr = [7,7,7,7,7,7,7]\r\nOutput: 7\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= arr.length <= 500
  • \r\n\t
  • 1 <= arr[i] <= 500
  • \r\n
", "content_cn": "

\u5728\u6574\u6570\u6570\u7ec4\u4e2d\uff0c\u5982\u679c\u4e00\u4e2a\u6574\u6570\u7684\u51fa\u73b0\u9891\u6b21\u548c\u5b83\u7684\u6570\u503c\u5927\u5c0f\u76f8\u7b49\uff0c\u6211\u4eec\u5c31\u79f0\u8fd9\u4e2a\u6574\u6570\u4e3a\u300c\u5e78\u8fd0\u6570\u300d\u3002

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr\uff0c\u8bf7\u4f60\u4ece\u4e2d\u627e\u51fa\u5e76\u8fd4\u56de\u4e00\u4e2a\u5e78\u8fd0\u6570\u3002

\n\n
    \n\t
  • \u5982\u679c\u6570\u7ec4\u4e2d\u5b58\u5728\u591a\u4e2a\u5e78\u8fd0\u6570\uff0c\u53ea\u9700\u8fd4\u56de \u6700\u5927 \u7684\u90a3\u4e2a\u3002
  • \n\t
  • \u5982\u679c\u6570\u7ec4\u4e2d\u4e0d\u542b\u5e78\u8fd0\u6570\uff0c\u5219\u8fd4\u56de -1 \u3002
  • \n
\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aarr = [2,2,3,4]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6570\u7ec4\u4e2d\u552f\u4e00\u7684\u5e78\u8fd0\u6570\u662f 2 \uff0c\u56e0\u4e3a\u6570\u503c 2 \u7684\u51fa\u73b0\u9891\u6b21\u4e5f\u662f 2 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aarr = [1,2,2,3,3,3]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a1\u30012 \u4ee5\u53ca 3 \u90fd\u662f\u5e78\u8fd0\u6570\uff0c\u53ea\u9700\u8981\u8fd4\u56de\u5176\u4e2d\u6700\u5927\u7684 3 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aarr = [2,2,2,3,3]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u6570\u7ec4\u4e2d\u4e0d\u5b58\u5728\u5e78\u8fd0\u6570\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1aarr = [5]\n\u8f93\u51fa\uff1a-1\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1aarr = [7,7,7,7,7,7,7]\n\u8f93\u51fa\uff1a7\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= arr.length <= 500
  • \n\t
  • 1 <= arr[i] <= 500
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findLucky(vector& arr) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findLucky(int[] arr) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findLucky(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findLucky(self, arr: List[int]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findLucky(int* arr, int arrSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindLucky(int[] arr) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar findLucky = function(arr) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef find_lucky(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findLucky(_ arr: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findLucky(arr []int) int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findLucky(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findLucky(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_lucky(arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function findLucky($arr) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findLucky(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-lucky arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1394](https://leetcode-cn.com/problems/find-lucky-integer-in-an-array)", "[\u627e\u51fa\u6570\u7ec4\u4e2d\u7684\u5e78\u8fd0\u6570](/solution/1300-1399/1394.Find%20Lucky%20Integer%20in%20an%20Array/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1394](https://leetcode.com/problems/find-lucky-integer-in-an-array)", "[Find Lucky Integer in an Array](/solution/1300-1399/1394.Find%20Lucky%20Integer%20in%20an%20Array/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1509", "frontend_question_id": "1378", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/replace-employee-id-with-the-unique-identifier", "url_en": "https://leetcode.com/problems/replace-employee-id-with-the-unique-identifier", "relative_path_cn": "/solution/1300-1399/1378.Replace%20Employee%20ID%20With%20The%20Unique%20Identifier/README.md", "relative_path_en": "/solution/1300-1399/1378.Replace%20Employee%20ID%20With%20The%20Unique%20Identifier/README_EN.md", "title_cn": "\u4f7f\u7528\u552f\u4e00\u6807\u8bc6\u7801\u66ff\u6362\u5458\u5de5ID", "title_en": "Replace Employee ID With The Unique Identifier", "question_title_slug": "replace-employee-id-with-the-unique-identifier", "content_en": "

Table: Employees

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| name          | varchar |\n+---------------+---------+\nid is the primary key for this table.\nEach row of this table contains the id and the name of an employee in a company.\n
\n\n

 

\n\n

Table: EmployeeUNI

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| unique_id     | int     |\n+---------------+---------+\n(id, unique_id) is the primary key for this table.\nEach row of this table contains the id and the corresponding unique id of an employee in the company.\n
\n\n

 

\n\n

Write an SQL query to show the unique ID of each user, If a user doesn't have a unique ID replace just show null.

\n\n

Return the result table in any order.

\n\n

The query result format is in the following example:

\n\n
\nEmployees table:\n+----+----------+\n| id | name     |\n+----+----------+\n| 1  | Alice    |\n| 7  | Bob      |\n| 11 | Meir     |\n| 90 | Winston  |\n| 3  | Jonathan |\n+----+----------+\n\nEmployeeUNI table:\n+----+-----------+\n| id | unique_id |\n+----+-----------+\n| 3  | 1         |\n| 11 | 2         |\n| 90 | 3         |\n+----+-----------+\n\nResult table:\n+-----------+----------+\n| unique_id | name     |\n+-----------+----------+\n| null      | Alice    |\n| null      | Bob      |\n| 2         | Meir     |\n| 3         | Winston  |\n| 1         | Jonathan |\n+-----------+----------+\n\nAlice and Bob don't have a unique ID, We will show null instead.\nThe unique ID of Meir is 2.\nThe unique ID of Winston is 3.\nThe unique ID of Jonathan is 1.\n
\n", "content_cn": "

Employees \u8868\uff1a

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| name          | varchar |\n+---------------+---------+\nid \u662f\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\u3002\n\u8fd9\u5f20\u8868\u7684\u6bcf\u4e00\u884c\u5206\u522b\u4ee3\u8868\u4e86\u67d0\u516c\u53f8\u5176\u4e2d\u4e00\u4f4d\u5458\u5de5\u7684\u540d\u5b57\u548c ID \u3002\n
\n\n

 

\n\n

EmployeeUNI \u8868\uff1a

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| unique_id     | int     |\n+---------------+---------+\n(id, unique_id) \u662f\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\u3002\n\u8fd9\u5f20\u8868\u7684\u6bcf\u4e00\u884c\u5305\u542b\u4e86\u8be5\u516c\u53f8\u67d0\u4f4d\u5458\u5de5\u7684 ID \u548c\u4ed6\u7684\u552f\u4e00\u6807\u8bc6\u7801\uff08unique ID\uff09\u3002\n
\n\n

 

\n\n

\u5199\u4e00\u6bb5SQL\u67e5\u8be2\u6765\u5c55\u793a\u6bcf\u4f4d\u7528\u6237\u7684 \u552f\u4e00\u6807\u8bc6\u7801\uff08unique ID \uff09\uff1b\u5982\u679c\u67d0\u4f4d\u5458\u5de5\u6ca1\u6709\u552f\u4e00\u6807\u8bc6\u7801\uff0c\u4f7f\u7528 null \u586b\u5145\u5373\u53ef\u3002

\n\n

\u4f60\u53ef\u4ee5\u4ee5 \u4efb\u610f \u987a\u5e8f\u8fd4\u56de\u7ed3\u679c\u8868\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u7684\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a\uff1a

\n\n
\nEmployees table:\n+----+----------+\n| id | name     |\n+----+----------+\n| 1  | Alice    |\n| 7  | Bob      |\n| 11 | Meir     |\n| 90 | Winston  |\n| 3  | Jonathan |\n+----+----------+\n\nEmployeeUNI table:\n+----+-----------+\n| id | unique_id |\n+----+-----------+\n| 3  | 1         |\n| 11 | 2         |\n| 90 | 3         |\n+----+-----------+\n\nEmployeeUNI table:\n+-----------+----------+\n| unique_id | name     |\n+-----------+----------+\n| null      | Alice    |\n| null      | Bob      |\n| 2         | Meir     |\n| 3         | Winston  |\n| 1         | Jonathan |\n+-----------+----------+\n\nAlice and Bob \u6ca1\u6709\u552f\u4e00\u6807\u8bc6\u7801, \u56e0\u6b64\u6211\u4eec\u4f7f\u7528 null \u66ff\u4ee3\u3002\nMeir \u7684\u552f\u4e00\u6807\u8bc6\u7801\u662f 2 \u3002\nWinston \u7684\u552f\u4e00\u6807\u8bc6\u7801\u662f 3 \u3002\nJonathan \u552f\u4e00\u6807\u8bc6\u7801\u662f 1 \u3002\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1378](https://leetcode-cn.com/problems/replace-employee-id-with-the-unique-identifier)", "[\u4f7f\u7528\u552f\u4e00\u6807\u8bc6\u7801\u66ff\u6362\u5458\u5de5ID](/solution/1300-1399/1378.Replace%20Employee%20ID%20With%20The%20Unique%20Identifier/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1378](https://leetcode.com/problems/replace-employee-id-with-the-unique-identifier)", "[Replace Employee ID With The Unique Identifier](/solution/1300-1399/1378.Replace%20Employee%20ID%20With%20The%20Unique%20Identifier/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1508", "frontend_question_id": "1392", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-happy-prefix", "url_en": "https://leetcode.com/problems/longest-happy-prefix", "relative_path_cn": "/solution/1300-1399/1392.Longest%20Happy%20Prefix/README.md", "relative_path_en": "/solution/1300-1399/1392.Longest%20Happy%20Prefix/README_EN.md", "title_cn": "\u6700\u957f\u5feb\u4e50\u524d\u7f00", "title_en": "Longest Happy Prefix", "question_title_slug": "longest-happy-prefix", "content_en": "

A string is called a happy prefix if is a non-empty prefix which is also a suffix (excluding itself).

\n\n

Given a string s, return the longest happy prefix of s. Return an empty string "" if no such prefix exists.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "level"\nOutput: "l"\nExplanation: s contains 4 prefix excluding itself ("l", "le", "lev", "leve"), and suffix ("l", "el", "vel", "evel"). The largest prefix which is also suffix is given by "l".\n
\n\n

Example 2:

\n\n
\nInput: s = "ababab"\nOutput: "abab"\nExplanation: "abab" is the largest prefix which is also suffix. They can overlap in the original string.\n
\n\n

Example 3:

\n\n
\nInput: s = "leetcodeleet"\nOutput: "leet"\n
\n\n

Example 4:

\n\n
\nInput: s = "a"\nOutput: ""\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 105
  • \n\t
  • s contains only lowercase English letters.
  • \n
\n", "content_cn": "

\u300c\u5feb\u4e50\u524d\u7f00\u300d\u662f\u5728\u539f\u5b57\u7b26\u4e32\u4e2d\u65e2\u662f \u975e\u7a7a \u524d\u7f00\u4e5f\u662f\u540e\u7f00\uff08\u4e0d\u5305\u62ec\u539f\u5b57\u7b26\u4e32\u81ea\u8eab\uff09\u7684\u5b57\u7b26\u4e32\u3002

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s\uff0c\u8bf7\u4f60\u8fd4\u56de\u5b83\u7684 \u6700\u957f\u5feb\u4e50\u524d\u7f00\u3002

\n\n

\u5982\u679c\u4e0d\u5b58\u5728\u6ee1\u8db3\u9898\u610f\u7684\u524d\u7f00\uff0c\u5219\u8fd4\u56de\u4e00\u4e2a\u7a7a\u5b57\u7b26\u4e32\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1as = "level"\n\u8f93\u51fa\uff1a"l"\n\u89e3\u91ca\uff1a\u4e0d\u5305\u62ec s \u81ea\u5df1\uff0c\u4e00\u5171\u6709 4 \u4e2a\u524d\u7f00\uff08"l", "le", "lev", "leve"\uff09\u548c 4 \u4e2a\u540e\u7f00\uff08"l", "el", "vel", "evel"\uff09\u3002\u6700\u957f\u7684\u65e2\u662f\u524d\u7f00\u4e5f\u662f\u540e\u7f00\u7684\u5b57\u7b26\u4e32\u662f "l" \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1as = "ababab"\n\u8f93\u51fa\uff1a"abab"\n\u89e3\u91ca\uff1a"abab" \u662f\u6700\u957f\u7684\u65e2\u662f\u524d\u7f00\u4e5f\u662f\u540e\u7f00\u7684\u5b57\u7b26\u4e32\u3002\u9898\u76ee\u5141\u8bb8\u524d\u540e\u7f00\u5728\u539f\u5b57\u7b26\u4e32\u4e2d\u91cd\u53e0\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1as = "leetcodeleet"\n\u8f93\u51fa\uff1a"leet"\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1as = "a"\n\u8f93\u51fa\uff1a""\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length <= 10^5
  • \n\t
  • s \u53ea\u542b\u6709\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string longestPrefix(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String longestPrefix(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestPrefix(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestPrefix(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * longestPrefix(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string LongestPrefix(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar longestPrefix = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef longest_prefix(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestPrefix(_ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestPrefix(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestPrefix(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestPrefix(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_prefix(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function longestPrefix($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestPrefix(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-prefix s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1392](https://leetcode-cn.com/problems/longest-happy-prefix)", "[\u6700\u957f\u5feb\u4e50\u524d\u7f00](/solution/1300-1399/1392.Longest%20Happy%20Prefix/README.md)", "`\u5b57\u7b26\u4e32`", "\u56f0\u96be", ""], "md_table_row_en": ["[1392](https://leetcode.com/problems/longest-happy-prefix)", "[Longest Happy Prefix](/solution/1300-1399/1392.Longest%20Happy%20Prefix/README_EN.md)", "`String`", "Hard", ""]}, {"question_id": "1507", "frontend_question_id": "1391", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/check-if-there-is-a-valid-path-in-a-grid", "url_en": "https://leetcode.com/problems/check-if-there-is-a-valid-path-in-a-grid", "relative_path_cn": "/solution/1300-1399/1391.Check%20if%20There%20is%20a%20Valid%20Path%20in%20a%20Grid/README.md", "relative_path_en": "/solution/1300-1399/1391.Check%20if%20There%20is%20a%20Valid%20Path%20in%20a%20Grid/README_EN.md", "title_cn": "\u68c0\u67e5\u7f51\u683c\u4e2d\u662f\u5426\u5b58\u5728\u6709\u6548\u8def\u5f84", "title_en": "Check if There is a Valid Path in a Grid", "question_title_slug": "check-if-there-is-a-valid-path-in-a-grid", "content_en": "Given a m x n grid. Each cell of the grid represents a street. The street of grid[i][j] can be:\n
    \n\t
  • 1 which means a street connecting the left cell and the right cell.
  • \n\t
  • 2 which means a street connecting the upper cell and the lower cell.
  • \n\t
  • 3 which means a street connecting the left cell and the lower cell.
  • \n\t
  • 4 which means a street connecting the right cell and the lower cell.
  • \n\t
  • 5 which means a street connecting the left cell and the upper cell.
  • \n\t
  • 6 which means a street connecting the right cell and the upper cell.
  • \n
\n\n

\"\"

\n\n

You will initially start at the street of the upper-left cell (0,0). A valid path in the grid is a path which starts from the upper left cell (0,0) and ends at the bottom-right cell (m - 1, n - 1). The path should only follow the streets.

\n\n

Notice that you are not allowed to change any street.

\n\n

Return true if there is a valid path in the grid or false otherwise.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: grid = [[2,4,3],[6,5,2]]\nOutput: true\nExplanation: As shown you can start at cell (0, 0) and visit all the cells of the grid to reach (m - 1, n - 1).\n
\n\n

Example 2:

\n\"\"\n
\nInput: grid = [[1,2,1],[1,2,1]]\nOutput: false\nExplanation: As shown you the street at cell (0, 0) is not connected with any street of any other cell and you will get stuck at cell (0, 0)\n
\n\n

Example 3:

\n\n
\nInput: grid = [[1,1,2]]\nOutput: false\nExplanation: You will get stuck at cell (0, 1) and you cannot reach cell (0, 2).\n
\n\n

Example 4:

\n\n
\nInput: grid = [[1,1,1,1,1,1,3]]\nOutput: true\n
\n\n

Example 5:

\n\n
\nInput: grid = [[2],[2],[2],[2],[2],[2],[6]]\nOutput: true\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • m == grid.length
  • \n\t
  • n == grid[i].length
  • \n\t
  • 1 <= m, n <= 300
  • \n\t
  • 1 <= grid[i][j] <= 6
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a m x n \u7684\u7f51\u683c grid\u3002\u7f51\u683c\u91cc\u7684\u6bcf\u4e2a\u5355\u5143\u90fd\u4ee3\u8868\u4e00\u6761\u8857\u9053\u3002grid[i][j] \u7684\u8857\u9053\u53ef\u4ee5\u662f\uff1a

\n\n
    \n\t
  • 1 \u8868\u793a\u8fde\u63a5\u5de6\u5355\u5143\u683c\u548c\u53f3\u5355\u5143\u683c\u7684\u8857\u9053\u3002
  • \n\t
  • 2 \u8868\u793a\u8fde\u63a5\u4e0a\u5355\u5143\u683c\u548c\u4e0b\u5355\u5143\u683c\u7684\u8857\u9053\u3002
  • \n\t
  • 3 \u8868\u793a\u8fde\u63a5\u5de6\u5355\u5143\u683c\u548c\u4e0b\u5355\u5143\u683c\u7684\u8857\u9053\u3002
  • \n\t
  • 4 \u8868\u793a\u8fde\u63a5\u53f3\u5355\u5143\u683c\u548c\u4e0b\u5355\u5143\u683c\u7684\u8857\u9053\u3002
  • \n\t
  • 5 \u8868\u793a\u8fde\u63a5\u5de6\u5355\u5143\u683c\u548c\u4e0a\u5355\u5143\u683c\u7684\u8857\u9053\u3002
  • \n\t
  • 6 \u8868\u793a\u8fde\u63a5\u53f3\u5355\u5143\u683c\u548c\u4e0a\u5355\u5143\u683c\u7684\u8857\u9053\u3002
  • \n
\n\n

\"\"

\n\n

\u4f60\u6700\u5f00\u59cb\u4ece\u5de6\u4e0a\u89d2\u7684\u5355\u5143\u683c (0,0) \u5f00\u59cb\u51fa\u53d1\uff0c\u7f51\u683c\u4e2d\u7684\u300c\u6709\u6548\u8def\u5f84\u300d\u662f\u6307\u4ece\u5de6\u4e0a\u65b9\u7684\u5355\u5143\u683c (0,0) \u5f00\u59cb\u3001\u4e00\u76f4\u5230\u53f3\u4e0b\u65b9\u7684 (m-1,n-1) \u7ed3\u675f\u7684\u8def\u5f84\u3002\u8be5\u8def\u5f84\u5fc5\u987b\u53ea\u6cbf\u7740\u8857\u9053\u8d70\u3002

\n\n

\u6ce8\u610f\uff1a\u4f60 \u4e0d\u80fd \u53d8\u66f4\u8857\u9053\u3002

\n\n

\u5982\u679c\u7f51\u683c\u4e2d\u5b58\u5728\u6709\u6548\u7684\u8def\u5f84\uff0c\u5219\u8fd4\u56de true\uff0c\u5426\u5219\u8fd4\u56de false \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1agrid = [[2,4,3],[6,5,2]]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u5982\u56fe\u6240\u793a\uff0c\u4f60\u53ef\u4ee5\u4ece (0, 0) \u5f00\u59cb\uff0c\u8bbf\u95ee\u7f51\u683c\u4e2d\u7684\u6240\u6709\u5355\u5143\u683c\u5e76\u5230\u8fbe (m - 1, n - 1) \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1agrid = [[1,2,1],[1,2,1]]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u5982\u56fe\u6240\u793a\uff0c\u5355\u5143\u683c (0, 0) \u4e0a\u7684\u8857\u9053\u6ca1\u6709\u4e0e\u4efb\u4f55\u5176\u4ed6\u5355\u5143\u683c\u4e0a\u7684\u8857\u9053\u76f8\u8fde\uff0c\u4f60\u53ea\u4f1a\u505c\u5728 (0, 0) \u5904\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1agrid = [[1,1,2]]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u4f60\u4f1a\u505c\u5728 (0, 1)\uff0c\u800c\u4e14\u65e0\u6cd5\u5230\u8fbe (0, 2) \u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1agrid = [[1,1,1,1,1,1,3]]\n\u8f93\u51fa\uff1atrue\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1agrid = [[2],[2],[2],[2],[2],[2],[6]]\n\u8f93\u51fa\uff1atrue\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • m == grid.length
  • \n\t
  • n == grid[i].length
  • \n\t
  • 1 <= m, n <= 300
  • \n\t
  • 1 <= grid[i][j] <= 6
  • \n
\n", "tags_en": ["Depth-first Search", "Breadth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool hasValidPath(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean hasValidPath(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def hasValidPath(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def hasValidPath(self, grid: List[List[int]]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool hasValidPath(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool HasValidPath(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {boolean}\n */\nvar hasValidPath = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Boolean}\ndef has_valid_path(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func hasValidPath(_ grid: [[Int]]) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func hasValidPath(grid [][]int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def hasValidPath(grid: Array[Array[Int]]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun hasValidPath(grid: Array): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn has_valid_path(grid: Vec>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Boolean\n */\n function hasValidPath($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function hasValidPath(grid: number[][]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (has-valid-path grid)\n (-> (listof (listof exact-integer?)) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1391](https://leetcode-cn.com/problems/check-if-there-is-a-valid-path-in-a-grid)", "[\u68c0\u67e5\u7f51\u683c\u4e2d\u662f\u5426\u5b58\u5728\u6709\u6548\u8def\u5f84](/solution/1300-1399/1391.Check%20if%20There%20is%20a%20Valid%20Path%20in%20a%20Grid/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1391](https://leetcode.com/problems/check-if-there-is-a-valid-path-in-a-grid)", "[Check if There is a Valid Path in a Grid](/solution/1300-1399/1391.Check%20if%20There%20is%20a%20Valid%20Path%20in%20a%20Grid/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`", "Medium", ""]}, {"question_id": "1505", "frontend_question_id": "1389", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/create-target-array-in-the-given-order", "url_en": "https://leetcode.com/problems/create-target-array-in-the-given-order", "relative_path_cn": "/solution/1300-1399/1389.Create%20Target%20Array%20in%20the%20Given%20Order/README.md", "relative_path_en": "/solution/1300-1399/1389.Create%20Target%20Array%20in%20the%20Given%20Order/README_EN.md", "title_cn": "\u6309\u65e2\u5b9a\u987a\u5e8f\u521b\u5efa\u76ee\u6807\u6570\u7ec4", "title_en": "Create Target Array in the Given Order", "question_title_slug": "create-target-array-in-the-given-order", "content_en": "

Given two arrays of integers nums and index. Your task is to create target array under the following rules:

\n\n
    \n\t
  • Initially target array is empty.
  • \n\t
  • From left to right read nums[i] and index[i], insert at index index[i] the value nums[i] in target array.
  • \n\t
  • Repeat the previous step until there are no elements to read in nums and index.
  • \n
\n\n

Return the target array.

\n\n

It is guaranteed that the insertion operations will be valid.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [0,1,2,3,4], index = [0,1,2,2,1]\nOutput: [0,4,1,3,2]\nExplanation:\nnums       index     target\n0            0        [0]\n1            1        [0,1]\n2            2        [0,1,2]\n3            2        [0,1,3,2]\n4            1        [0,4,1,3,2]\n
\n\n

Example 2:

\n\n
\nInput: nums = [1,2,3,4,0], index = [0,1,2,3,0]\nOutput: [0,1,2,3,4]\nExplanation:\nnums       index     target\n1            0        [1]\n2            1        [1,2]\n3            2        [1,2,3]\n4            3        [1,2,3,4]\n0            0        [0,1,2,3,4]\n
\n\n

Example 3:

\n\n
\nInput: nums = [1], index = [0]\nOutput: [1]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length, index.length <= 100
  • \n\t
  • nums.length == index.length
  • \n\t
  • 0 <= nums[i] <= 100
  • \n\t
  • 0 <= index[i] <= i
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e24\u4e2a\u6574\u6570\u6570\u7ec4 nums \u548c index\u3002\u4f60\u9700\u8981\u6309\u7167\u4ee5\u4e0b\u89c4\u5219\u521b\u5efa\u76ee\u6807\u6570\u7ec4\uff1a

\n\n
    \n\t
  • \u76ee\u6807\u6570\u7ec4 target \u6700\u521d\u4e3a\u7a7a\u3002
  • \n\t
  • \u6309\u4ece\u5de6\u5230\u53f3\u7684\u987a\u5e8f\u4f9d\u6b21\u8bfb\u53d6 nums[i] \u548c index[i]\uff0c\u5728 target \u6570\u7ec4\u4e2d\u7684\u4e0b\u6807 index[i] \u5904\u63d2\u5165\u503c nums[i] \u3002
  • \n\t
  • \u91cd\u590d\u4e0a\u4e00\u6b65\uff0c\u76f4\u5230\u5728 nums \u548c index \u4e2d\u90fd\u6ca1\u6709\u8981\u8bfb\u53d6\u7684\u5143\u7d20\u3002
  • \n
\n\n

\u8bf7\u4f60\u8fd4\u56de\u76ee\u6807\u6570\u7ec4\u3002

\n\n

\u9898\u76ee\u4fdd\u8bc1\u6570\u5b57\u63d2\u5165\u4f4d\u7f6e\u603b\u662f\u5b58\u5728\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anums = [0,1,2,3,4], index = [0,1,2,2,1]\n\u8f93\u51fa\uff1a[0,4,1,3,2]\n\u89e3\u91ca\uff1a\nnums       index     target\n0            0        [0]\n1            1        [0,1]\n2            2        [0,1,2]\n3            2        [0,1,3,2]\n4            1        [0,4,1,3,2]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,2,3,4,0], index = [0,1,2,3,0]\n\u8f93\u51fa\uff1a[0,1,2,3,4]\n\u89e3\u91ca\uff1a\nnums       index     target\n1            0        [1]\n2            1        [1,2]\n3            2        [1,2,3]\n4            3        [1,2,3,4]\n0            0        [0,1,2,3,4]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1anums = [1], index = [0]\n\u8f93\u51fa\uff1a[1]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length, index.length <= 100
  • \n\t
  • nums.length == index.length
  • \n\t
  • 0 <= nums[i] <= 100
  • \n\t
  • 0 <= index[i] <= i
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector createTargetArray(vector& nums, vector& index) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] createTargetArray(int[] nums, int[] index) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def createTargetArray(self, nums, index):\n \"\"\"\n :type nums: List[int]\n :type index: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* createTargetArray(int* nums, int numsSize, int* index, int indexSize, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] CreateTargetArray(int[] nums, int[] index) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number[]} index\n * @return {number[]}\n */\nvar createTargetArray = function(nums, index) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer[]} index\n# @return {Integer[]}\ndef create_target_array(nums, index)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func createTargetArray(_ nums: [Int], _ index: [Int]) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func createTargetArray(nums []int, index []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def createTargetArray(nums: Array[Int], index: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun createTargetArray(nums: IntArray, index: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn create_target_array(nums: Vec, index: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer[] $index\n * @return Integer[]\n */\n function createTargetArray($nums, $index) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function createTargetArray(nums: number[], index: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (create-target-array nums index)\n (-> (listof exact-integer?) (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1389](https://leetcode-cn.com/problems/create-target-array-in-the-given-order)", "[\u6309\u65e2\u5b9a\u987a\u5e8f\u521b\u5efa\u76ee\u6807\u6570\u7ec4](/solution/1300-1399/1389.Create%20Target%20Array%20in%20the%20Given%20Order/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1389](https://leetcode.com/problems/create-target-array-in-the-given-order)", "[Create Target Array in the Given Order](/solution/1300-1399/1389.Create%20Target%20Array%20in%20the%20Given%20Order/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1504", "frontend_question_id": "1369", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/get-the-second-most-recent-activity", "url_en": "https://leetcode.com/problems/get-the-second-most-recent-activity", "relative_path_cn": "/solution/1300-1399/1369.Get%20the%20Second%20Most%20Recent%20Activity/README.md", "relative_path_en": "/solution/1300-1399/1369.Get%20the%20Second%20Most%20Recent%20Activity/README_EN.md", "title_cn": "\u83b7\u53d6\u6700\u8fd1\u7b2c\u4e8c\u6b21\u7684\u6d3b\u52a8", "title_en": "Get the Second Most Recent Activity", "question_title_slug": "get-the-second-most-recent-activity", "content_en": "

Table: UserActivity

\r\n\r\n
\r\n+---------------+---------+\r\n| Column Name   | Type    |\r\n+---------------+---------+\r\n| username      | varchar |\r\n| activity      | varchar |\r\n| startDate     | Date    |\r\n| endDate       | Date    |\r\n+---------------+---------+\r\nThis table does not contain primary key.\r\nThis table contain information about the activity performed of each user in a period of time.\r\nA person with username performed a activity from startDate to endDate.\r\n\r\n
\r\n\r\n

Write an SQL query to show the second most recent activity of each user.

\r\n\r\n

If the user only has one activity, return that one. 

\r\n\r\n

A user can't perform more than one activity at the same time. Return the result table in any order.

\r\n\r\n

The query result format is in the following example:

\r\n\r\n
\r\nUserActivity table:\r\n+------------+--------------+-------------+-------------+\r\n| username   | activity     | startDate   | endDate     |\r\n+------------+--------------+-------------+-------------+\r\n| Alice      | Travel       | 2020-02-12  | 2020-02-20  |\r\n| Alice      | Dancing      | 2020-02-21  | 2020-02-23  |\r\n| Alice      | Travel       | 2020-02-24  | 2020-02-28  |\r\n| Bob        | Travel       | 2020-02-11  | 2020-02-18  |\r\n+------------+--------------+-------------+-------------+\r\n\r\nResult table:\r\n+------------+--------------+-------------+-------------+\r\n| username   | activity     | startDate   | endDate     |\r\n+------------+--------------+-------------+-------------+\r\n| Alice      | Dancing      | 2020-02-21  | 2020-02-23  |\r\n| Bob        | Travel       | 2020-02-11  | 2020-02-18  |\r\n+------------+--------------+-------------+-------------+\r\n\r\nThe most recent activity of Alice is Travel from 2020-02-24 to 2020-02-28, before that she was dancing from 2020-02-21 to 2020-02-23.\r\nBob only has one record, we just take that one.\r\n
", "content_cn": "

\u8868: UserActivity

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| username      | varchar |\n| activity      | varchar |\n| startDate     | Date    |\n| endDate       | Date    |\n+---------------+---------+\n\u8be5\u8868\u4e0d\u5305\u542b\u4e3b\u952e\n\u8be5\u8868\u5305\u542b\u6bcf\u4e2a\u7528\u6237\u5728\u4e00\u6bb5\u65f6\u95f4\u5185\u8fdb\u884c\u7684\u6d3b\u52a8\u7684\u4fe1\u606f\n\u540d\u4e3a username \u7684\u7528\u6237\u5728 startDate \u5230 endDate \u65e5\u5185\u6709\u4e00\u6b21\u6d3b\u52a8\n
\n\n

\u00a0

\n\n

\u5199\u4e00\u6761SQL\u67e5\u8be2\u5c55\u793a\u6bcf\u4e00\u4f4d\u7528\u6237 \u6700\u8fd1\u7b2c\u4e8c\u6b21 \u7684\u6d3b\u52a8

\n\n

\u5982\u679c\u7528\u6237\u4ec5\u6709\u4e00\u6b21\u6d3b\u52a8\uff0c\u8fd4\u56de\u8be5\u6d3b\u52a8

\n\n

\u4e00\u4e2a\u7528\u6237\u4e0d\u80fd\u540c\u65f6\u8fdb\u884c\u8d85\u8fc7\u4e00\u9879\u6d3b\u52a8\uff0c\u4ee5 \u4efb\u610f \u987a\u5e8f\u8fd4\u56de\u7ed3\u679c

\n\n

\u4e0b\u9762\u662f\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u7684\u4f8b\u5b50\uff1a

\n\n
\nUserActivity \u8868:\n+------------+--------------+-------------+-------------+\n| username   | activity     | startDate   | endDate     |\n+------------+--------------+-------------+-------------+\n| Alice      | Travel       | 2020-02-12  | 2020-02-20  |\n| Alice      | Dancing      | 2020-02-21  | 2020-02-23  |\n| Alice      | Travel       | 2020-02-24  | 2020-02-28  |\n| Bob        | Travel       | 2020-02-11  | 2020-02-18  |\n+------------+--------------+-------------+-------------+\n\nResult \u8868:\n+------------+--------------+-------------+-------------+\n| username   | activity     | startDate   | endDate     |\n+------------+--------------+-------------+-------------+\n| Alice      | Dancing      | 2020-02-21  | 2020-02-23  |\n| Bob        | Travel       | 2020-02-11  | 2020-02-18  |\n+------------+--------------+-------------+-------------+\n\nAlice \u6700\u8fd1\u4e00\u6b21\u7684\u6d3b\u52a8\u662f\u4ece 2020-02-24 \u5230 2020-02-28 \u7684\u65c5\u884c, \u5728\u6b64\u4e4b\u524d\u7684 2020-02-21 \u5230 2020-02-23 \u5979\u8fdb\u884c\u4e86\u821e\u8e48\nBob \u53ea\u6709\u4e00\u6761\u8bb0\u5f55\uff0c\u6211\u4eec\u5c31\u53d6\u8fd9\u6761\u8bb0\u5f55\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1369](https://leetcode-cn.com/problems/get-the-second-most-recent-activity)", "[\u83b7\u53d6\u6700\u8fd1\u7b2c\u4e8c\u6b21\u7684\u6d3b\u52a8](/solution/1300-1399/1369.Get%20the%20Second%20Most%20Recent%20Activity/README.md)", "", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1369](https://leetcode.com/problems/get-the-second-most-recent-activity)", "[Get the Second Most Recent Activity](/solution/1300-1399/1369.Get%20the%20Second%20Most%20Recent%20Activity/README_EN.md)", "", "Hard", "\ud83d\udd12"]}, {"question_id": "1503", "frontend_question_id": "1402", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reducing-dishes", "url_en": "https://leetcode.com/problems/reducing-dishes", "relative_path_cn": "/solution/1400-1499/1402.Reducing%20Dishes/README.md", "relative_path_en": "/solution/1400-1499/1402.Reducing%20Dishes/README_EN.md", "title_cn": "\u505a\u83dc\u987a\u5e8f", "title_en": "Reducing Dishes", "question_title_slug": "reducing-dishes", "content_en": "

A chef has collected data on the satisfaction level of his n dishes. Chef can cook any dish in 1 unit of time.

\r\n\r\n

Like-time coefficient of a dish is defined as the time taken to cook that dish including previous dishes multiplied by its satisfaction level  i.e.  time[i]*satisfaction[i]

\r\n\r\n

Return the maximum sum of Like-time coefficient that the chef can obtain after dishes preparation.

\r\n\r\n

Dishes can be prepared in any order and the chef can discard some dishes to get this maximum value.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: satisfaction = [-1,-8,0,5,-9]\r\nOutput: 14\r\nExplanation: After Removing the second and last dish, the maximum total Like-time coefficient will be equal to (-1*1 + 0*2 + 5*3 = 14). Each dish is prepared in one unit of time.
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: satisfaction = [4,3,2]\r\nOutput: 20\r\nExplanation: Dishes can be prepared in any order, (2*1 + 3*2 + 4*3 = 20)\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: satisfaction = [-1,-4,-5]\r\nOutput: 0\r\nExplanation: People don't like the dishes. No dish is prepared.\r\n
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: satisfaction = [-2,5,-1,0,3,-3]\r\nOutput: 35\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • n == satisfaction.length
  • \r\n\t
  • 1 <= n <= 500
  • \r\n\t
  • -10^3 <= satisfaction[i] <= 10^3
  • \r\n
", "content_cn": "

\u4e00\u4e2a\u53a8\u5e08\u6536\u96c6\u4e86\u4ed6 n \u9053\u83dc\u7684\u6ee1\u610f\u7a0b\u5ea6 satisfaction \uff0c\u8fd9\u4e2a\u53a8\u5e08\u505a\u51fa\u6bcf\u9053\u83dc\u7684\u65f6\u95f4\u90fd\u662f 1 \u5355\u4f4d\u65f6\u95f4\u3002

\n\n

\u4e00\u9053\u83dc\u7684 \u300c\u559c\u7231\u65f6\u95f4\u300d\u7cfb\u6570\u5b9a\u4e49\u4e3a\u70f9\u996a\u8fd9\u9053\u83dc\u4ee5\u53ca\u4e4b\u524d\u6bcf\u9053\u83dc\u6240\u82b1\u8d39\u7684\u65f6\u95f4\u4e58\u4ee5\u8fd9\u9053\u83dc\u7684\u6ee1\u610f\u7a0b\u5ea6\uff0c\u4e5f\u5c31\u662f time[i]*satisfaction[i] \u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u505a\u5b8c\u6240\u6709\u83dc \u300c\u559c\u7231\u65f6\u95f4\u300d\u603b\u548c\u7684\u6700\u5927\u503c\u4e3a\u591a\u5c11\u3002

\n\n

\u4f60\u53ef\u4ee5\u6309 \u4efb\u610f \u987a\u5e8f\u5b89\u6392\u505a\u83dc\u7684\u987a\u5e8f\uff0c\u4f60\u4e5f\u53ef\u4ee5\u9009\u62e9\u653e\u5f03\u505a\u67d0\u4e9b\u83dc\u6765\u83b7\u5f97\u66f4\u5927\u7684\u603b\u548c\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1asatisfaction = [-1,-8,0,5,-9]\n\u8f93\u51fa\uff1a14\n\u89e3\u91ca\uff1a\u53bb\u6389\u7b2c\u4e8c\u9053\u548c\u6700\u540e\u4e00\u9053\u83dc\uff0c\u6700\u5927\u7684\u559c\u7231\u65f6\u95f4\u7cfb\u6570\u548c\u4e3a (-1*1 + 0*2 + 5*3 = 14) \u3002\u6bcf\u9053\u83dc\u90fd\u9700\u8981\u82b1\u8d39 1 \u5355\u4f4d\u65f6\u95f4\u5b8c\u6210\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1asatisfaction = [4,3,2]\n\u8f93\u51fa\uff1a20\n\u89e3\u91ca\uff1a\u6309\u7167\u539f\u6765\u987a\u5e8f\u76f8\u53cd\u7684\u65f6\u95f4\u505a\u83dc (2*1 + 3*2 + 4*3 = 20)\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1asatisfaction = [-1,-4,-5]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u5927\u5bb6\u90fd\u4e0d\u559c\u6b22\u8fd9\u4e9b\u83dc\uff0c\u6240\u4ee5\u4e0d\u505a\u4efb\u4f55\u83dc\u53ef\u4ee5\u83b7\u5f97\u6700\u5927\u7684\u559c\u7231\u65f6\u95f4\u7cfb\u6570\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1asatisfaction = [-2,5,-1,0,3,-3]\n\u8f93\u51fa\uff1a35\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • n == satisfaction.length
  • \n\t
  • 1 <= n <= 500
  • \n\t
  • -10^3 <= satisfaction[i] <= 10^3
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxSatisfaction(vector& satisfaction) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxSatisfaction(int[] satisfaction) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxSatisfaction(self, satisfaction):\n \"\"\"\n :type satisfaction: List[int]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxSatisfaction(self, satisfaction: List[int]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxSatisfaction(int* satisfaction, int satisfactionSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxSatisfaction(int[] satisfaction) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} satisfaction\n * @return {number}\n */\nvar maxSatisfaction = function(satisfaction) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} satisfaction\n# @return {Integer}\ndef max_satisfaction(satisfaction)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxSatisfaction(_ satisfaction: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxSatisfaction(satisfaction []int) int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxSatisfaction(satisfaction: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxSatisfaction(satisfaction: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_satisfaction(satisfaction: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $satisfaction\n * @return Integer\n */\n function maxSatisfaction($satisfaction) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxSatisfaction(satisfaction: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-satisfaction satisfaction)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1402](https://leetcode-cn.com/problems/reducing-dishes)", "[\u505a\u83dc\u987a\u5e8f](/solution/1400-1499/1402.Reducing%20Dishes/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1402](https://leetcode.com/problems/reducing-dishes)", "[Reducing Dishes](/solution/1400-1499/1402.Reducing%20Dishes/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1502", "frontend_question_id": "1400", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/construct-k-palindrome-strings", "url_en": "https://leetcode.com/problems/construct-k-palindrome-strings", "relative_path_cn": "/solution/1400-1499/1400.Construct%20K%20Palindrome%20Strings/README.md", "relative_path_en": "/solution/1400-1499/1400.Construct%20K%20Palindrome%20Strings/README_EN.md", "title_cn": "\u6784\u9020 K \u4e2a\u56de\u6587\u5b57\u7b26\u4e32", "title_en": "Construct K Palindrome Strings", "question_title_slug": "construct-k-palindrome-strings", "content_en": "

Given a string s and an integer k. You should construct k non-empty palindrome strings using all the characters in s.

\r\n\r\n

Return True if you can use all the characters in s to construct k palindrome strings or False otherwise.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: s = "annabelle", k = 2\r\nOutput: true\r\nExplanation: You can construct two palindromes using all characters in s.\r\nSome possible constructions "anna" + "elble", "anbna" + "elle", "anellena" + "b"\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: s = "leetcode", k = 3\r\nOutput: false\r\nExplanation: It is impossible to construct 3 palindromes using all the characters of s.\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: s = "true", k = 4\r\nOutput: true\r\nExplanation: The only possible solution is to put each character in a separate string.\r\n
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: s = "yzyzyzyzyzyzyzy", k = 2\r\nOutput: true\r\nExplanation: Simply you can put all z's in one string and all y's in the other string. Both strings will be palindrome.\r\n
\r\n\r\n

Example 5:

\r\n\r\n
\r\nInput: s = "cr", k = 7\r\nOutput: false\r\nExplanation: We don't have enough characters in s to construct 7 palindromes.\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= s.length <= 10^5
  • \r\n\t
  • All characters in s are lower-case English letters.
  • \r\n\t
  • 1 <= k <= 10^5
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \u548c\u4e00\u4e2a\u6574\u6570 k \u3002\u8bf7\u4f60\u7528 s \u5b57\u7b26\u4e32\u4e2d \u6240\u6709\u5b57\u7b26 \u6784\u9020 k \u4e2a\u975e\u7a7a \u56de\u6587\u4e32 \u3002

\n\n

\u5982\u679c\u4f60\u53ef\u4ee5\u7528 s \u4e2d\u6240\u6709\u5b57\u7b26\u6784\u9020 k \u4e2a\u56de\u6587\u5b57\u7b26\u4e32\uff0c\u90a3\u4e48\u8bf7\u4f60\u8fd4\u56de True \uff0c\u5426\u5219\u8fd4\u56de False \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1as = "annabelle", k = 2\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u53ef\u4ee5\u7528 s \u4e2d\u6240\u6709\u5b57\u7b26\u6784\u9020 2 \u4e2a\u56de\u6587\u5b57\u7b26\u4e32\u3002\n\u4e00\u4e9b\u53ef\u884c\u7684\u6784\u9020\u65b9\u6848\u5305\u62ec\uff1a"anna" + "elble"\uff0c"anbna" + "elle"\uff0c"anellena" + "b"\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1as = "leetcode", k = 3\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u65e0\u6cd5\u7528 s \u4e2d\u6240\u6709\u5b57\u7b26\u6784\u9020 3 \u4e2a\u56de\u6587\u4e32\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1as = "true", k = 4\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u552f\u4e00\u53ef\u884c\u7684\u65b9\u6848\u662f\u8ba9 s \u4e2d\u6bcf\u4e2a\u5b57\u7b26\u5355\u72ec\u6784\u6210\u4e00\u4e2a\u5b57\u7b26\u4e32\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1as = "yzyzyzyzyzyzyzy", k = 2\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u4f60\u53ea\u9700\u8981\u5c06\u6240\u6709\u7684 z \u653e\u5728\u4e00\u4e2a\u5b57\u7b26\u4e32\u4e2d\uff0c\u6240\u6709\u7684 y \u653e\u5728\u53e6\u4e00\u4e2a\u5b57\u7b26\u4e32\u4e2d\u3002\u90a3\u4e48\u4e24\u4e2a\u5b57\u7b26\u4e32\u90fd\u662f\u56de\u6587\u4e32\u3002\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\n\u8f93\u5165\uff1as = "cr", k = 7\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u6211\u4eec\u6ca1\u6709\u8db3\u591f\u7684\u5b57\u7b26\u53bb\u6784\u9020 7 \u4e2a\u56de\u6587\u4e32\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length <= 10^5
  • \n\t
  • s \u4e2d\u6240\u6709\u5b57\u7b26\u90fd\u662f\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
  • \n\t
  • 1 <= k <= 10^5
  • \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canConstruct(string s, int k) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canConstruct(String s, int k) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canConstruct(self, s, k):\n \"\"\"\n :type s: str\n :type k: int\n :rtype: bool\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canConstruct(self, s: str, k: int) -> bool:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canConstruct(char * s, int k){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanConstruct(string s, int k) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number} k\n * @return {boolean}\n */\nvar canConstruct = function(s, k) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer} k\n# @return {Boolean}\ndef can_construct(s, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canConstruct(_ s: String, _ k: Int) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canConstruct(s string, k int) bool {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canConstruct(s: String, k: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canConstruct(s: String, k: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_construct(s: String, k: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer $k\n * @return Boolean\n */\n function canConstruct($s, $k) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canConstruct(s: string, k: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-construct s k)\n (-> string? exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1400](https://leetcode-cn.com/problems/construct-k-palindrome-strings)", "[\u6784\u9020 K \u4e2a\u56de\u6587\u5b57\u7b26\u4e32](/solution/1400-1499/1400.Construct%20K%20Palindrome%20Strings/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1400](https://leetcode.com/problems/construct-k-palindrome-strings)", "[Construct K Palindrome Strings](/solution/1400-1499/1400.Construct%20K%20Palindrome%20Strings/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1501", "frontend_question_id": "1401", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/circle-and-rectangle-overlapping", "url_en": "https://leetcode.com/problems/circle-and-rectangle-overlapping", "relative_path_cn": "/solution/1400-1499/1401.Circle%20and%20Rectangle%20Overlapping/README.md", "relative_path_en": "/solution/1400-1499/1401.Circle%20and%20Rectangle%20Overlapping/README_EN.md", "title_cn": "\u5706\u548c\u77e9\u5f62\u662f\u5426\u6709\u91cd\u53e0", "title_en": "Circle and Rectangle Overlapping", "question_title_slug": "circle-and-rectangle-overlapping", "content_en": "

Given a circle represented as (radius, x_center, y_center) and an axis-aligned rectangle represented as (x1, y1, x2, y2), where (x1, y1) are the coordinates of the bottom-left corner, and (x2, y2) are the coordinates of the top-right corner of the rectangle.

\n\n

Return True if the circle and rectangle are overlapped otherwise return False.

\n\n

In other words, check if there are any point (xi, yi) such that belongs to the circle and the rectangle at the same time.

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: radius = 1, x_center = 0, y_center = 0, x1 = 1, y1 = -1, x2 = 3, y2 = 1\nOutput: true\nExplanation: Circle and rectangle share the point (1,0) \n
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: radius = 1, x_center = 0, y_center = 0, x1 = -1, y1 = 0, x2 = 0, y2 = 1\nOutput: true\n
\n\n

Example 3:

\n\n

\"\"

\n\n
\nInput: radius = 1, x_center = 1, y_center = 1, x1 = -3, y1 = -3, x2 = 3, y2 = 3\nOutput: true\n
\n\n

Example 4:

\n\n
\nInput: radius = 1, x_center = 1, y_center = 1, x1 = 1, y1 = -3, x2 = 2, y2 = -1\nOutput: false\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= radius <= 2000
  • \n\t
  • -10^4 <= x_center, y_center, x1, y1, x2, y2 <= 10^4
  • \n\t
  • x1 < x2
  • \n\t
  • y1 < y2
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u4ee5 (radius, x_center, y_center) \u8868\u793a\u7684\u5706\u548c\u4e00\u4e2a\u4e0e\u5750\u6807\u8f74\u5e73\u884c\u7684\u77e9\u5f62 (x1, y1, x2, y2)\uff0c\u5176\u4e2d (x1, y1) \u662f\u77e9\u5f62\u5de6\u4e0b\u89d2\u7684\u5750\u6807\uff0c(x2, y2) \u662f\u53f3\u4e0a\u89d2\u7684\u5750\u6807\u3002

\n\n

\u5982\u679c\u5706\u548c\u77e9\u5f62\u6709\u91cd\u53e0\u7684\u90e8\u5206\uff0c\u8bf7\u4f60\u8fd4\u56de True \uff0c\u5426\u5219\u8fd4\u56de False \u3002

\n\n

\u6362\u53e5\u8bdd\u8bf4\uff0c\u8bf7\u4f60\u68c0\u6d4b\u662f\u5426 \u5b58\u5728 \u70b9 (xi, yi) \uff0c\u5b83\u65e2\u5728\u5706\u4e0a\u4e5f\u5728\u77e9\u5f62\u4e0a\uff08\u4e24\u8005\u90fd\u5305\u62ec\u70b9\u843d\u5728\u8fb9\u754c\u4e0a\u7684\u60c5\u51b5\uff09\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1aradius = 1, x_center = 0, y_center = 0, x1 = 1, y1 = -1, x2 = 3, y2 = 1\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u5706\u548c\u77e9\u5f62\u6709\u516c\u5171\u70b9 (1,0) \n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1aradius = 1, x_center = 0, y_center = 0, x1 = -1, y1 = 0, x2 = 0, y2 = 1\n\u8f93\u51fa\uff1atrue\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1aradius = 1, x_center = 1, y_center = 1, x1 = -3, y1 = -3, x2 = 3, y2 = 3\n\u8f93\u51fa\uff1atrue\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1aradius = 1, x_center = 1, y_center = 1, x1 = 1, y1 = -3, x2 = 2, y2 = -1\n\u8f93\u51fa\uff1afalse\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= radius <= 2000
  • \n\t
  • -10^4 <= x_center, y_center, x1, y1, x2, y2 <= 10^4
  • \n\t
  • x1 < x2
  • \n\t
  • y1 < y2
  • \n
\n", "tags_en": ["Geometry"], "tags_cn": ["\u51e0\u4f55"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool checkOverlap(int radius, int x_center, int y_center, int x1, int y1, int x2, int y2) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean checkOverlap(int radius, int x_center, int y_center, int x1, int y1, int x2, int y2) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def checkOverlap(self, radius, x_center, y_center, x1, y1, x2, y2):\n \"\"\"\n :type radius: int\n :type x_center: int\n :type y_center: int\n :type x1: int\n :type y1: int\n :type x2: int\n :type y2: int\n :rtype: bool\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def checkOverlap(self, radius: int, x_center: int, y_center: int, x1: int, y1: int, x2: int, y2: int) -> bool:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool checkOverlap(int radius, int x_center, int y_center, int x1, int y1, int x2, int y2){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CheckOverlap(int radius, int x_center, int y_center, int x1, int y1, int x2, int y2) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} radius\n * @param {number} x_center\n * @param {number} y_center\n * @param {number} x1\n * @param {number} y1\n * @param {number} x2\n * @param {number} y2\n * @return {boolean}\n */\nvar checkOverlap = function(radius, x_center, y_center, x1, y1, x2, y2) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} radius\n# @param {Integer} x_center\n# @param {Integer} y_center\n# @param {Integer} x1\n# @param {Integer} y1\n# @param {Integer} x2\n# @param {Integer} y2\n# @return {Boolean}\ndef check_overlap(radius, x_center, y_center, x1, y1, x2, y2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func checkOverlap(_ radius: Int, _ x_center: Int, _ y_center: Int, _ x1: Int, _ y1: Int, _ x2: Int, _ y2: Int) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func checkOverlap(radius int, x_center int, y_center int, x1 int, y1 int, x2 int, y2 int) bool {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def checkOverlap(radius: Int, x_center: Int, y_center: Int, x1: Int, y1: Int, x2: Int, y2: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun checkOverlap(radius: Int, x_center: Int, y_center: Int, x1: Int, y1: Int, x2: Int, y2: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn check_overlap(radius: i32, x_center: i32, y_center: i32, x1: i32, y1: i32, x2: i32, y2: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $radius\n * @param Integer $x_center\n * @param Integer $y_center\n * @param Integer $x1\n * @param Integer $y1\n * @param Integer $x2\n * @param Integer $y2\n * @return Boolean\n */\n function checkOverlap($radius, $x_center, $y_center, $x1, $y1, $x2, $y2) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function checkOverlap(radius: number, x_center: number, y_center: number, x1: number, y1: number, x2: number, y2: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (check-overlap radius x_center y_center x1 y1 x2 y2)\n (-> exact-integer? exact-integer? exact-integer? exact-integer? exact-integer? exact-integer? exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1401](https://leetcode-cn.com/problems/circle-and-rectangle-overlapping)", "[\u5706\u548c\u77e9\u5f62\u662f\u5426\u6709\u91cd\u53e0](/solution/1400-1499/1401.Circle%20and%20Rectangle%20Overlapping/README.md)", "`\u51e0\u4f55`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1401](https://leetcode.com/problems/circle-and-rectangle-overlapping)", "[Circle and Rectangle Overlapping](/solution/1400-1499/1401.Circle%20and%20Rectangle%20Overlapping/README_EN.md)", "`Geometry`", "Medium", ""]}, {"question_id": "1500", "frontend_question_id": "1399", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-largest-group", "url_en": "https://leetcode.com/problems/count-largest-group", "relative_path_cn": "/solution/1300-1399/1399.Count%20Largest%20Group/README.md", "relative_path_en": "/solution/1300-1399/1399.Count%20Largest%20Group/README_EN.md", "title_cn": "\u7edf\u8ba1\u6700\u5927\u7ec4\u7684\u6570\u76ee", "title_en": "Count Largest Group", "question_title_slug": "count-largest-group", "content_en": "

Given an integer n. Each number from 1 to n is grouped according to the sum of its digits. 

\n\n

Return how many groups have the largest size.

\n\n

 

\n

Example 1:

\n\n
\nInput: n = 13\nOutput: 4\nExplanation: There are 9 groups in total, they are grouped according sum of its digits of numbers from 1 to 13:\n[1,10], [2,11], [3,12], [4,13], [5], [6], [7], [8], [9]. There are 4 groups with largest size.\n
\n\n

Example 2:

\n\n
\nInput: n = 2\nOutput: 2\nExplanation: There are 2 groups [1], [2] of size 1.\n
\n\n

Example 3:

\n\n
\nInput: n = 15\nOutput: 6\n
\n\n

Example 4:

\n\n
\nInput: n = 24\nOutput: 5\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 10^4
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n \u3002\u8bf7\u4f60\u5148\u6c42\u51fa\u4ece 1 \u5230 n \u7684\u6bcf\u4e2a\u6574\u6570 10 \u8fdb\u5236\u8868\u793a\u4e0b\u7684\u6570\u4f4d\u548c\uff08\u6bcf\u4e00\u4f4d\u4e0a\u7684\u6570\u5b57\u76f8\u52a0\uff09\uff0c\u7136\u540e\u628a\u6570\u4f4d\u548c\u76f8\u7b49\u7684\u6570\u5b57\u653e\u5230\u540c\u4e00\u4e2a\u7ec4\u4e2d\u3002

\n\n

\u8bf7\u4f60\u7edf\u8ba1\u6bcf\u4e2a\u7ec4\u4e2d\u7684\u6570\u5b57\u6570\u76ee\uff0c\u5e76\u8fd4\u56de\u6570\u5b57\u6570\u76ee\u5e76\u5217\u6700\u591a\u7684\u7ec4\u6709\u591a\u5c11\u4e2a\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1an = 13\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u603b\u5171\u6709 9 \u4e2a\u7ec4\uff0c\u5c06 1 \u5230 13 \u6309\u6570\u4f4d\u6c42\u548c\u540e\u8fd9\u4e9b\u7ec4\u5206\u522b\u662f\uff1a\n[1,10]\uff0c[2,11]\uff0c[3,12]\uff0c[4,13]\uff0c[5]\uff0c[6]\uff0c[7]\uff0c[8]\uff0c[9]\u3002\u603b\u5171\u6709 4 \u4e2a\u7ec4\u62e5\u6709\u7684\u6570\u5b57\u5e76\u5217\u6700\u591a\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1an = 2\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u603b\u5171\u6709 2 \u4e2a\u5927\u5c0f\u4e3a 1 \u7684\u7ec4 [1]\uff0c[2]\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1an = 15\n\u8f93\u51fa\uff1a6\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1an = 24\n\u8f93\u51fa\uff1a5\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 10^4
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countLargestGroup(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countLargestGroup(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countLargestGroup(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countLargestGroup(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countLargestGroup(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountLargestGroup(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar countLargestGroup = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef count_largest_group(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countLargestGroup(_ n: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countLargestGroup(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countLargestGroup(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countLargestGroup(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_largest_group(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function countLargestGroup($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countLargestGroup(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-largest-group n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1399](https://leetcode-cn.com/problems/count-largest-group)", "[\u7edf\u8ba1\u6700\u5927\u7ec4\u7684\u6570\u76ee](/solution/1300-1399/1399.Count%20Largest%20Group/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1399](https://leetcode.com/problems/count-largest-group)", "[Count Largest Group](/solution/1300-1399/1399.Count%20Largest%20Group/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1499", "frontend_question_id": "1383", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-performance-of-a-team", "url_en": "https://leetcode.com/problems/maximum-performance-of-a-team", "relative_path_cn": "/solution/1300-1399/1383.Maximum%20Performance%20of%20a%20Team/README.md", "relative_path_en": "/solution/1300-1399/1383.Maximum%20Performance%20of%20a%20Team/README_EN.md", "title_cn": "\u6700\u5927\u7684\u56e2\u961f\u8868\u73b0\u503c", "title_en": "Maximum Performance of a Team", "question_title_slug": "maximum-performance-of-a-team", "content_en": "

You are given two integers n and k and two integer arrays speed and efficiency both of length n. There are n engineers numbered from 1 to n. speed[i] and efficiency[i] represent the speed and efficiency of the ith engineer respectively.

\n\n

Choose at most k different engineers out of the n engineers to form a team with the maximum performance.

\n\n

The performance of a team is the sum of their engineers' speeds multiplied by the minimum efficiency among their engineers.

\n\n

Return the maximum performance of this team. Since the answer can be a huge number, return it modulo 109 + 7.

\n\n

 

\n

Example 1:

\n\n
\nInput: n = 6, speed = [2,10,3,1,5,8], efficiency = [5,4,3,9,7,2], k = 2\nOutput: 60\nExplanation: \nWe have the maximum performance of the team by selecting engineer 2 (with speed=10 and efficiency=4) and engineer 5 (with speed=5 and efficiency=7). That is, performance = (10 + 5) * min(4, 7) = 60.\n
\n\n

Example 2:

\n\n
\nInput: n = 6, speed = [2,10,3,1,5,8], efficiency = [5,4,3,9,7,2], k = 3\nOutput: 68\nExplanation:\nThis is the same example as the first but k = 3. We can select engineer 1, engineer 2 and engineer 5 to get the maximum performance of the team. That is, performance = (2 + 10 + 5) * min(5, 4, 7) = 68.\n
\n\n

Example 3:

\n\n
\nInput: n = 6, speed = [2,10,3,1,5,8], efficiency = [5,4,3,9,7,2], k = 4\nOutput: 72\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= <= k <= n <= 105
  • \n\t
  • speed.length == n
  • \n\t
  • efficiency.length == n
  • \n\t
  • 1 <= speed[i] <= 105
  • \n\t
  • 1 <= efficiency[i] <= 108
  • \n
\n", "content_cn": "

\u516c\u53f8\u6709\u7f16\u53f7\u4e3a 1 \u5230 n \u7684 n \u4e2a\u5de5\u7a0b\u5e08\uff0c\u7ed9\u4f60\u4e24\u4e2a\u6570\u7ec4 speed \u548c efficiency \uff0c\u5176\u4e2d speed[i] \u548c efficiency[i] \u5206\u522b\u4ee3\u8868\u7b2c i \u4f4d\u5de5\u7a0b\u5e08\u7684\u901f\u5ea6\u548c\u6548\u7387\u3002\u8bf7\u4f60\u8fd4\u56de\u7531\u6700\u591a k \u4e2a\u5de5\u7a0b\u5e08\u7ec4\u6210\u7684 \u200b\u200b\u200b\u200b\u200b\u200b\u6700\u5927\u56e2\u961f\u8868\u73b0\u503c \uff0c\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u5f88\u5927\uff0c\u8bf7\u4f60\u8fd4\u56de\u7ed3\u679c\u5bf9 10^9 + 7 \u53d6\u4f59\u540e\u7684\u7ed3\u679c\u3002

\n\n

\u56e2\u961f\u8868\u73b0\u503c \u7684\u5b9a\u4e49\u4e3a\uff1a\u4e00\u4e2a\u56e2\u961f\u4e2d\u300c\u6240\u6709\u5de5\u7a0b\u5e08\u901f\u5ea6\u7684\u548c\u300d\u4e58\u4ee5\u4ed6\u4eec\u300c\u6548\u7387\u503c\u4e2d\u7684\u6700\u5c0f\u503c\u300d\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1an = 6, speed = [2,10,3,1,5,8], efficiency = [5,4,3,9,7,2], k = 2\n\u8f93\u51fa\uff1a60\n\u89e3\u91ca\uff1a\n\u6211\u4eec\u9009\u62e9\u5de5\u7a0b\u5e08 2\uff08speed=10 \u4e14 efficiency=4\uff09\u548c\u5de5\u7a0b\u5e08 5\uff08speed=5 \u4e14 efficiency=7\uff09\u3002\u4ed6\u4eec\u7684\u56e2\u961f\u8868\u73b0\u503c\u4e3a performance = (10 + 5) * min(4, 7) = 60 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1an = 6, speed = [2,10,3,1,5,8], efficiency = [5,4,3,9,7,2], k = 3\n\u8f93\u51fa\uff1a68\n\u89e3\u91ca\uff1a\n\u6b64\u793a\u4f8b\u4e0e\u7b2c\u4e00\u4e2a\u793a\u4f8b\u76f8\u540c\uff0c\u9664\u4e86 k = 3 \u3002\u6211\u4eec\u53ef\u4ee5\u9009\u62e9\u5de5\u7a0b\u5e08 1 \uff0c\u5de5\u7a0b\u5e08 2 \u548c\u5de5\u7a0b\u5e08 5 \u5f97\u5230\u6700\u5927\u7684\u56e2\u961f\u8868\u73b0\u503c\u3002\u8868\u73b0\u503c\u4e3a performance = (2 + 10 + 5) * min(5, 4, 7) = 68 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1an = 6, speed = [2,10,3,1,5,8], efficiency = [5,4,3,9,7,2], k = 4\n\u8f93\u51fa\uff1a72\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 10^5
  • \n\t
  • speed.length == n
  • \n\t
  • efficiency.length == n
  • \n\t
  • 1 <= speed[i] <= 10^5
  • \n\t
  • 1 <= efficiency[i] <= 10^8
  • \n\t
  • 1 <= k <= n
  • \n
\n", "tags_en": ["Greedy", "Sort"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6392\u5e8f"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxPerformance(int n, vector& speed, vector& efficiency, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxPerformance(int n, int[] speed, int[] efficiency, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxPerformance(self, n, speed, efficiency, k):\n \"\"\"\n :type n: int\n :type speed: List[int]\n :type efficiency: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxPerformance(self, n: int, speed: List[int], efficiency: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxPerformance(int n, int* speed, int speedSize, int* efficiency, int efficiencySize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxPerformance(int n, int[] speed, int[] efficiency, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[]} speed\n * @param {number[]} efficiency\n * @param {number} k\n * @return {number}\n */\nvar maxPerformance = function(n, speed, efficiency, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[]} speed\n# @param {Integer[]} efficiency\n# @param {Integer} k\n# @return {Integer}\ndef max_performance(n, speed, efficiency, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxPerformance(_ n: Int, _ speed: [Int], _ efficiency: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxPerformance(n int, speed []int, efficiency []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxPerformance(n: Int, speed: Array[Int], efficiency: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxPerformance(n: Int, speed: IntArray, efficiency: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_performance(n: i32, speed: Vec, efficiency: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[] $speed\n * @param Integer[] $efficiency\n * @param Integer $k\n * @return Integer\n */\n function maxPerformance($n, $speed, $efficiency, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxPerformance(n: number, speed: number[], efficiency: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-performance n speed efficiency k)\n (-> exact-integer? (listof exact-integer?) (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1383](https://leetcode-cn.com/problems/maximum-performance-of-a-team)", "[\u6700\u5927\u7684\u56e2\u961f\u8868\u73b0\u503c](/solution/1300-1399/1383.Maximum%20Performance%20of%20a%20Team/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6392\u5e8f`", "\u56f0\u96be", ""], "md_table_row_en": ["[1383](https://leetcode.com/problems/maximum-performance-of-a-team)", "[Maximum Performance of a Team](/solution/1300-1399/1383.Maximum%20Performance%20of%20a%20Team/README_EN.md)", "`Greedy`,`Sort`", "Hard", ""]}, {"question_id": "1498", "frontend_question_id": "1379", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree", "url_en": "https://leetcode.com/problems/find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree", "relative_path_cn": "/solution/1300-1399/1379.Find%20a%20Corresponding%20Node%20of%20a%20Binary%20Tree%20in%20a%20Clone%20of%20That%20Tree/README.md", "relative_path_en": "/solution/1300-1399/1379.Find%20a%20Corresponding%20Node%20of%20a%20Binary%20Tree%20in%20a%20Clone%20of%20That%20Tree/README_EN.md", "title_cn": "\u627e\u51fa\u514b\u9686\u4e8c\u53c9\u6811\u4e2d\u7684\u76f8\u540c\u8282\u70b9", "title_en": "Find a Corresponding Node of a Binary Tree in a Clone of That Tree", "question_title_slug": "find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree", "content_en": "

Given two binary trees original and cloned and given a reference to a node target in the original tree.

\r\n\r\n

The cloned tree is a copy of the original tree.

\r\n\r\n

Return a reference to the same node in the cloned tree.

\r\n\r\n

Note that you are not allowed to change any of the two trees or the target node and the answer must be a reference to a node in the cloned tree.

\r\n\r\n

Follow up: Solve the problem if repeated values on the tree are allowed.

\r\n\r\n

 

\r\n

Example 1:

\r\n\"\"\r\n
\r\nInput: tree = [7,4,3,null,null,6,19], target = 3\r\nOutput: 3\r\nExplanation: In all examples the original and cloned trees are shown. The target node is a green node from the original tree. The answer is the yellow node from the cloned tree.\r\n
\r\n\r\n

Example 2:

\r\n\"\"\r\n
\r\nInput: tree = [7], target =  7\r\nOutput: 7\r\n
\r\n\r\n

Example 3:

\r\n\"\"\r\n
\r\nInput: tree = [8,null,6,null,5,null,4,null,3,null,2,null,1], target = 4\r\nOutput: 4\r\n
\r\n\r\n

Example 4:

\r\n\"\"\r\n
\r\nInput: tree = [1,2,3,4,5,6,7,8,9,10], target = 5\r\nOutput: 5\r\n
\r\n\r\n

Example 5:

\r\n\"\"\r\n
\r\nInput: tree = [1,2,null,3], target = 2\r\nOutput: 2\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • The number of nodes in the tree is in the range [1, 10^4].
  • \r\n\t
  • The values of the nodes of the tree are unique.
  • \r\n\t
  • target node is a node from the original tree and is not null.
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e24\u68f5\u4e8c\u53c9\u6811\uff0c\u539f\u59cb\u6811 original \u548c\u514b\u9686\u6811 cloned\uff0c\u4ee5\u53ca\u4e00\u4e2a\u4f4d\u4e8e\u539f\u59cb\u6811 original \u4e2d\u7684\u76ee\u6807\u8282\u70b9 target\u3002

\n\n

\u5176\u4e2d\uff0c\u514b\u9686\u6811 cloned \u662f\u539f\u59cb\u6811 original \u7684\u4e00\u4e2a \u526f\u672c \u3002

\n\n

\u8bf7\u627e\u51fa\u5728\u6811 cloned \u4e2d\uff0c\u4e0e target \u76f8\u540c \u7684\u8282\u70b9\uff0c\u5e76\u8fd4\u56de\u5bf9\u8be5\u8282\u70b9\u7684\u5f15\u7528\uff08\u5728 C/C++ \u7b49\u6709\u6307\u9488\u7684\u8bed\u8a00\u4e2d\u8fd4\u56de \u8282\u70b9\u6307\u9488\uff0c\u5176\u4ed6\u8bed\u8a00\u8fd4\u56de\u8282\u70b9\u672c\u8eab\uff09\u3002

\n\n

 

\n\n

\u6ce8\u610f\uff1a

\n\n
    \n\t
  1. \u4f60 \u4e0d\u80fd \u5bf9\u4e24\u68f5\u4e8c\u53c9\u6811\uff0c\u4ee5\u53ca target \u8282\u70b9\u8fdb\u884c\u66f4\u6539\u3002
  2. \n\t
  3. \u53ea\u80fd \u8fd4\u56de\u5bf9\u514b\u9686\u6811 cloned \u4e2d\u5df2\u6709\u7684\u8282\u70b9\u7684\u5f15\u7528\u3002
  4. \n
\n\n
    \n
\n\n

\u8fdb\u9636\uff1a\u5982\u679c\u6811\u4e2d\u5141\u8bb8\u51fa\u73b0\u503c\u76f8\u540c\u7684\u8282\u70b9\uff0c\u4f60\u5c06\u5982\u4f55\u89e3\u7b54\uff1f

\n\n

 

\n\n
    \n
\n\n

\u793a\u4f8b 1:

\n\n

\"\"

\n\n
\u8f93\u5165: tree = [7,4,3,null,null,6,19], target = 3\n\u8f93\u51fa: 3\n\u89e3\u91ca: \u4e0a\u56fe\u753b\u51fa\u4e86\u6811 original \u548c cloned\u3002target \u8282\u70b9\u5728\u6811 original \u4e2d\uff0c\u7528\u7eff\u8272\u6807\u8bb0\u3002\u7b54\u6848\u662f\u6811 cloned \u4e2d\u7684\u9ec4\u989c\u8272\u7684\u8282\u70b9\uff08\u5176\u4ed6\u793a\u4f8b\u7c7b\u4f3c\uff09\u3002
\n\n

\u793a\u4f8b 2:

\n\n

\"\"

\n\n
\u8f93\u5165: tree = [7], target =  7\n\u8f93\u51fa: 7\n
\n\n

\u793a\u4f8b 3:

\n\n

\"\"

\n\n
\u8f93\u5165: tree = [8,null,6,null,5,null,4,null,3,null,2,null,1], target = 4\n\u8f93\u51fa: 4\n
\n\n

\u793a\u4f8b 4:

\n\n

\"\"

\n\n
\u8f93\u5165: tree = [1,2,3,4,5,6,7,8,9,10], target = 5\n\u8f93\u51fa: 5\n
\n\n

\u793a\u4f8b 5:

\n\n

\"\"

\n\n
\u8f93\u5165: tree = [1,2,null,3], target = 2\n\u8f93\u51fa: 2
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u6811\u4e2d\u8282\u70b9\u7684\u6570\u91cf\u8303\u56f4\u4e3a [1, 10^4] \u3002
  • \n\t
  • \u540c\u4e00\u68f5\u6811\u4e2d\uff0c\u6ca1\u6709\u503c\u76f8\u540c\u7684\u8282\u70b9\u3002
  • \n\t
  • target \u8282\u70b9\u662f\u6811 original \u4e2d\u7684\u4e00\u4e2a\u8282\u70b9\uff0c\u5e76\u4e14\u4e0d\u4f1a\u662f null \u3002
  • \n
\n", "tags_en": ["Tree", "Depth-first Search", "Breadth-first Search", "Recursion"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u9012\u5f52"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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\nclass Solution {\npublic:\n TreeNode* getTargetCopy(TreeNode* original, TreeNode* cloned, TreeNode* target) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode(int x) { val = x; }\n * }\n */\n\nclass Solution {\n public final TreeNode getTargetCopy(final TreeNode original, final TreeNode cloned, final TreeNode target) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution(object):\n def getTargetCopy(self, original, cloned, target):\n \"\"\"\n :type original: TreeNode\n :type cloned: TreeNode\n :type target: TreeNode\n :rtype: TreeNode\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution:\n def getTargetCopy(self, original: TreeNode, cloned: TreeNode, target: TreeNode) -> TreeNode:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int x) { val = x; }\n * }\n */\n\npublic class Solution {\n public TreeNode GetTargetCopy(TreeNode original, TreeNode cloned, TreeNode target) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val) {\n * this.val = val;\n * this.left = this.right = null;\n * }\n */\n/**\n * @param {TreeNode} original\n * @param {TreeNode} cloned\n * @param {TreeNode} target\n * @return {TreeNode}\n */\n\nvar getTargetCopy = function(original, cloned, target) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction getTargetCopy(original: TreeNode | null, cloned: TreeNode | null, target: TreeNode | null): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1379](https://leetcode-cn.com/problems/find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree)", "[\u627e\u51fa\u514b\u9686\u4e8c\u53c9\u6811\u4e2d\u7684\u76f8\u540c\u8282\u70b9](/solution/1300-1399/1379.Find%20a%20Corresponding%20Node%20of%20a%20Binary%20Tree%20in%20a%20Clone%20of%20That%20Tree/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u9012\u5f52`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1379](https://leetcode.com/problems/find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree)", "[Find a Corresponding Node of a Binary Tree in a Clone of That Tree](/solution/1300-1399/1379.Find%20a%20Corresponding%20Node%20of%20a%20Binary%20Tree%20in%20a%20Clone%20of%20That%20Tree/README_EN.md)", "`Tree`,`Depth-first Search`,`Breadth-first Search`,`Recursion`", "Medium", ""]}, {"question_id": "1497", "frontend_question_id": "1381", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/design-a-stack-with-increment-operation", "url_en": "https://leetcode.com/problems/design-a-stack-with-increment-operation", "relative_path_cn": "/solution/1300-1399/1381.Design%20a%20Stack%20With%20Increment%20Operation/README.md", "relative_path_en": "/solution/1300-1399/1381.Design%20a%20Stack%20With%20Increment%20Operation/README_EN.md", "title_cn": "\u8bbe\u8ba1\u4e00\u4e2a\u652f\u6301\u589e\u91cf\u64cd\u4f5c\u7684\u6808", "title_en": "Design a Stack With Increment Operation", "question_title_slug": "design-a-stack-with-increment-operation", "content_en": "

Design a stack which supports the following operations.

\n\n

Implement the CustomStack class:

\n\n
    \n\t
  • CustomStack(int maxSize) Initializes the object with maxSize which is the maximum number of elements in the stack or do nothing if the stack reached the maxSize.
  • \n\t
  • void push(int x) Adds x to the top of the stack if the stack hasn't reached the maxSize.
  • \n\t
  • int pop() Pops and returns the top of stack or -1 if the stack is empty.
  • \n\t
  • void inc(int k, int val) Increments the bottom k elements of the stack by val. If there are less than k elements in the stack, just increment all the elements in the stack.
  • \n
\n\n

 

\n

Example 1:

\n\n
\nInput\n["CustomStack","push","push","pop","push","push","push","increment","increment","pop","pop","pop","pop"]\n[[3],[1],[2],[],[2],[3],[4],[5,100],[2,100],[],[],[],[]]\nOutput\n[null,null,null,2,null,null,null,null,null,103,202,201,-1]\nExplanation\nCustomStack customStack = new CustomStack(3); // Stack is Empty []\ncustomStack.push(1);                          // stack becomes [1]\ncustomStack.push(2);                          // stack becomes [1, 2]\ncustomStack.pop();                            // return 2 --> Return top of the stack 2, stack becomes [1]\ncustomStack.push(2);                          // stack becomes [1, 2]\ncustomStack.push(3);                          // stack becomes [1, 2, 3]\ncustomStack.push(4);                          // stack still [1, 2, 3], Don't add another elements as size is 4\ncustomStack.increment(5, 100);                // stack becomes [101, 102, 103]\ncustomStack.increment(2, 100);                // stack becomes [201, 202, 103]\ncustomStack.pop();                            // return 103 --> Return top of the stack 103, stack becomes [201, 202]\ncustomStack.pop();                            // return 202 --> Return top of the stack 102, stack becomes [201]\ncustomStack.pop();                            // return 201 --> Return top of the stack 101, stack becomes []\ncustomStack.pop();                            // return -1 --> Stack is empty return -1.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= maxSize <= 1000
  • \n\t
  • 1 <= x <= 1000
  • \n\t
  • 1 <= k <= 1000
  • \n\t
  • 0 <= val <= 100
  • \n\t
  • At most 1000 calls will be made to each method of increment, push and pop each separately.
  • \n
\n", "content_cn": "

\u8bf7\u4f60\u8bbe\u8ba1\u4e00\u4e2a\u652f\u6301\u4e0b\u8ff0\u64cd\u4f5c\u7684\u6808\u3002

\n\n

\u5b9e\u73b0\u81ea\u5b9a\u4e49\u6808\u7c7b CustomStack \uff1a

\n\n
    \n\t
  • CustomStack(int maxSize)\uff1a\u7528 maxSize \u521d\u59cb\u5316\u5bf9\u8c61\uff0cmaxSize \u662f\u6808\u4e2d\u6700\u591a\u80fd\u5bb9\u7eb3\u7684\u5143\u7d20\u6570\u91cf\uff0c\u6808\u5728\u589e\u957f\u5230 maxSize \u4e4b\u540e\u5219\u4e0d\u652f\u6301 push \u64cd\u4f5c\u3002
  • \n\t
  • void push(int x)\uff1a\u5982\u679c\u6808\u8fd8\u672a\u589e\u957f\u5230 maxSize \uff0c\u5c31\u5c06 x \u6dfb\u52a0\u5230\u6808\u9876\u3002
  • \n\t
  • int pop()\uff1a\u5f39\u51fa\u6808\u9876\u5143\u7d20\uff0c\u5e76\u8fd4\u56de\u6808\u9876\u7684\u503c\uff0c\u6216\u6808\u4e3a\u7a7a\u65f6\u8fd4\u56de -1 \u3002
  • \n\t
  • void inc(int k, int val)\uff1a\u6808\u5e95\u7684 k \u4e2a\u5143\u7d20\u7684\u503c\u90fd\u589e\u52a0 val \u3002\u5982\u679c\u6808\u4e2d\u5143\u7d20\u603b\u6570\u5c0f\u4e8e k \uff0c\u5219\u6808\u4e2d\u7684\u6240\u6709\u5143\u7d20\u90fd\u589e\u52a0 val \u3002
  • \n
\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1a\n["CustomStack","push","push","pop","push","push","push","increment","increment","pop","pop","pop","pop"]\n[[3],[1],[2],[],[2],[3],[4],[5,100],[2,100],[],[],[],[]]\n\u8f93\u51fa\uff1a\n[null,null,null,2,null,null,null,null,null,103,202,201,-1]\n\u89e3\u91ca\uff1a\nCustomStack customStack = new CustomStack(3); // \u6808\u662f\u7a7a\u7684 []\ncustomStack.push(1);                          // \u6808\u53d8\u4e3a [1]\ncustomStack.push(2);                          // \u6808\u53d8\u4e3a [1, 2]\ncustomStack.pop();                            // \u8fd4\u56de 2 --> \u8fd4\u56de\u6808\u9876\u503c 2\uff0c\u6808\u53d8\u4e3a [1]\ncustomStack.push(2);                          // \u6808\u53d8\u4e3a [1, 2]\ncustomStack.push(3);                          // \u6808\u53d8\u4e3a [1, 2, 3]\ncustomStack.push(4);                          // \u6808\u4ecd\u7136\u662f [1, 2, 3]\uff0c\u4e0d\u80fd\u6dfb\u52a0\u5176\u4ed6\u5143\u7d20\u4f7f\u6808\u5927\u5c0f\u53d8\u4e3a 4\ncustomStack.increment(5, 100);                // \u6808\u53d8\u4e3a [101, 102, 103]\ncustomStack.increment(2, 100);                // \u6808\u53d8\u4e3a [201, 202, 103]\ncustomStack.pop();                            // \u8fd4\u56de 103 --> \u8fd4\u56de\u6808\u9876\u503c 103\uff0c\u6808\u53d8\u4e3a [201, 202]\ncustomStack.pop();                            // \u8fd4\u56de 202 --> \u8fd4\u56de\u6808\u9876\u503c 202\uff0c\u6808\u53d8\u4e3a [201]\ncustomStack.pop();                            // \u8fd4\u56de 201 --> \u8fd4\u56de\u6808\u9876\u503c 201\uff0c\u6808\u53d8\u4e3a []\ncustomStack.pop();                            // \u8fd4\u56de -1 --> \u6808\u4e3a\u7a7a\uff0c\u8fd4\u56de -1\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= maxSize <= 1000
  • \n\t
  • 1 <= x <= 1000
  • \n\t
  • 1 <= k <= 1000
  • \n\t
  • 0 <= val <= 100
  • \n\t
  • \u6bcf\u79cd\u65b9\u6cd5 increment\uff0cpush \u4ee5\u53ca pop \u5206\u522b\u6700\u591a\u8c03\u7528 1000 \u6b21
  • \n
\n", "tags_en": ["Stack", "Design"], "tags_cn": ["\u6808", "\u8bbe\u8ba1"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class CustomStack {\npublic:\n CustomStack(int maxSize) {\n\n }\n \n void push(int x) {\n\n }\n \n int pop() {\n\n }\n \n void increment(int k, int val) {\n\n }\n};\n\n/**\n * Your CustomStack object will be instantiated and called as such:\n * CustomStack* obj = new CustomStack(maxSize);\n * obj->push(x);\n * int param_2 = obj->pop();\n * obj->increment(k,val);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class CustomStack {\n\n public CustomStack(int maxSize) {\n\n }\n \n public void push(int x) {\n\n }\n \n public int pop() {\n\n }\n \n public void increment(int k, int val) {\n\n }\n}\n\n/**\n * Your CustomStack object will be instantiated and called as such:\n * CustomStack obj = new CustomStack(maxSize);\n * obj.push(x);\n * int param_2 = obj.pop();\n * obj.increment(k,val);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class CustomStack(object):\n\n def __init__(self, maxSize):\n \"\"\"\n :type maxSize: int\n \"\"\"\n\n\n def push(self, x):\n \"\"\"\n :type x: int\n :rtype: None\n \"\"\"\n\n\n def pop(self):\n \"\"\"\n :rtype: int\n \"\"\"\n\n\n def increment(self, k, val):\n \"\"\"\n :type k: int\n :type val: int\n :rtype: None\n \"\"\"\n\n\n\n# Your CustomStack object will be instantiated and called as such:\n# obj = CustomStack(maxSize)\n# obj.push(x)\n# param_2 = obj.pop()\n# obj.increment(k,val)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class CustomStack:\n\n def __init__(self, maxSize: int):\n\n\n def push(self, x: int) -> None:\n\n\n def pop(self) -> int:\n\n\n def increment(self, k: int, val: int) -> None:\n\n\n\n# Your CustomStack object will be instantiated and called as such:\n# obj = CustomStack(maxSize)\n# obj.push(x)\n# param_2 = obj.pop()\n# obj.increment(k,val)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} CustomStack;\n\n\nCustomStack* customStackCreate(int maxSize) {\n\n}\n\nvoid customStackPush(CustomStack* obj, int x) {\n\n}\n\nint customStackPop(CustomStack* obj) {\n\n}\n\nvoid customStackIncrement(CustomStack* obj, int k, int val) {\n\n}\n\nvoid customStackFree(CustomStack* obj) {\n\n}\n\n/**\n * Your CustomStack struct will be instantiated and called as such:\n * CustomStack* obj = customStackCreate(maxSize);\n * customStackPush(obj, x);\n \n * int param_2 = customStackPop(obj);\n \n * customStackIncrement(obj, k, val);\n \n * customStackFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class CustomStack {\n\n public CustomStack(int maxSize) {\n\n }\n \n public void Push(int x) {\n\n }\n \n public int Pop() {\n\n }\n \n public void Increment(int k, int val) {\n\n }\n}\n\n/**\n * Your CustomStack object will be instantiated and called as such:\n * CustomStack obj = new CustomStack(maxSize);\n * obj.Push(x);\n * int param_2 = obj.Pop();\n * obj.Increment(k,val);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} maxSize\n */\nvar CustomStack = function(maxSize) {\n\n};\n\n/** \n * @param {number} x\n * @return {void}\n */\nCustomStack.prototype.push = function(x) {\n\n};\n\n/**\n * @return {number}\n */\nCustomStack.prototype.pop = function() {\n\n};\n\n/** \n * @param {number} k \n * @param {number} val\n * @return {void}\n */\nCustomStack.prototype.increment = function(k, val) {\n\n};\n\n/**\n * Your CustomStack object will be instantiated and called as such:\n * var obj = new CustomStack(maxSize)\n * obj.push(x)\n * var param_2 = obj.pop()\n * obj.increment(k,val)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class CustomStack\n\n=begin\n :type max_size: Integer\n=end\n def initialize(max_size)\n\n end\n\n\n=begin\n :type x: Integer\n :rtype: Void\n=end\n def push(x)\n\n end\n\n\n=begin\n :rtype: Integer\n=end\n def pop()\n\n end\n\n\n=begin\n :type k: Integer\n :type val: Integer\n :rtype: Void\n=end\n def increment(k, val)\n\n end\n\n\nend\n\n# Your CustomStack object will be instantiated and called as such:\n# obj = CustomStack.new(max_size)\n# obj.push(x)\n# param_2 = obj.pop()\n# obj.increment(k, val)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass CustomStack {\n\n init(_ maxSize: Int) {\n\n }\n \n func push(_ x: Int) {\n\n }\n \n func pop() -> Int {\n\n }\n \n func increment(_ k: Int, _ val: Int) {\n\n }\n}\n\n/**\n * Your CustomStack object will be instantiated and called as such:\n * let obj = CustomStack(maxSize)\n * obj.push(x)\n * let ret_2: Int = obj.pop()\n * obj.increment(k, val)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type CustomStack struct {\n\n}\n\n\nfunc Constructor(maxSize int) CustomStack {\n\n}\n\n\nfunc (this *CustomStack) Push(x int) {\n\n}\n\n\nfunc (this *CustomStack) Pop() int {\n\n}\n\n\nfunc (this *CustomStack) Increment(k int, val int) {\n\n}\n\n\n/**\n * Your CustomStack object will be instantiated and called as such:\n * obj := Constructor(maxSize);\n * obj.Push(x);\n * param_2 := obj.Pop();\n * obj.Increment(k,val);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class CustomStack(_maxSize: Int) {\n\n def push(x: Int) {\n\n }\n\n def pop(): Int = {\n\n }\n\n def increment(k: Int, `val`: Int) {\n\n }\n\n}\n\n/**\n * Your CustomStack object will be instantiated and called as such:\n * var obj = new CustomStack(maxSize)\n * obj.push(x)\n * var param_2 = obj.pop()\n * obj.increment(k,`val`)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class CustomStack(maxSize: Int) {\n\n fun push(x: Int) {\n\n }\n\n fun pop(): Int {\n\n }\n\n fun increment(k: Int, `val`: Int) {\n\n }\n\n}\n\n/**\n * Your CustomStack object will be instantiated and called as such:\n * var obj = CustomStack(maxSize)\n * obj.push(x)\n * var param_2 = obj.pop()\n * obj.increment(k,`val`)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct CustomStack {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl CustomStack {\n\n fn new(maxSize: i32) -> Self {\n\n }\n \n fn push(&self, x: i32) {\n\n }\n \n fn pop(&self) -> i32 {\n\n }\n \n fn increment(&self, k: i32, val: i32) {\n\n }\n}\n\n/**\n * Your CustomStack object will be instantiated and called as such:\n * let obj = CustomStack::new(maxSize);\n * obj.push(x);\n * let ret_2: i32 = obj.pop();\n * obj.increment(k, val);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class CustomStack {\n /**\n * @param Integer $maxSize\n */\n function __construct($maxSize) {\n\n }\n\n /**\n * @param Integer $x\n * @return NULL\n */\n function push($x) {\n\n }\n\n /**\n * @return Integer\n */\n function pop() {\n\n }\n\n /**\n * @param Integer $k\n * @param Integer $val\n * @return NULL\n */\n function increment($k, $val) {\n\n }\n}\n\n/**\n * Your CustomStack object will be instantiated and called as such:\n * $obj = CustomStack($maxSize);\n * $obj->push($x);\n * $ret_2 = $obj->pop();\n * $obj->increment($k, $val);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class CustomStack {\n constructor(maxSize: number) {\n\n }\n\n push(x: number): void {\n\n }\n\n pop(): number {\n\n }\n\n increment(k: number, val: number): void {\n\n }\n}\n\n/**\n * Your CustomStack object will be instantiated and called as such:\n * var obj = new CustomStack(maxSize)\n * obj.push(x)\n * var param_2 = obj.pop()\n * obj.increment(k,val)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define custom-stack%\n (class object%\n (super-new)\n\n ; max-size : exact-integer?\n (init-field\n max-size)\n \n ; push : exact-integer? -> void?\n (define/public (push x)\n\n )\n ; pop : -> exact-integer?\n (define/public (pop)\n\n )\n ; increment : exact-integer? exact-integer? -> void?\n (define/public (increment k val)\n\n )))\n\n;; Your custom-stack% object will be instantiated and called as such:\n;; (define obj (new custom-stack% [maxSize maxSize]))\n;; (send obj push x)\n;; (define param_2 (send obj pop))\n;; (send obj increment k val)", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1381](https://leetcode-cn.com/problems/design-a-stack-with-increment-operation)", "[\u8bbe\u8ba1\u4e00\u4e2a\u652f\u6301\u589e\u91cf\u64cd\u4f5c\u7684\u6808](/solution/1300-1399/1381.Design%20a%20Stack%20With%20Increment%20Operation/README.md)", "`\u6808`,`\u8bbe\u8ba1`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1381](https://leetcode.com/problems/design-a-stack-with-increment-operation)", "[Design a Stack With Increment Operation](/solution/1300-1399/1381.Design%20a%20Stack%20With%20Increment%20Operation/README_EN.md)", "`Stack`,`Design`", "Medium", ""]}, {"question_id": "1496", "frontend_question_id": "1380", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/lucky-numbers-in-a-matrix", "url_en": "https://leetcode.com/problems/lucky-numbers-in-a-matrix", "relative_path_cn": "/solution/1300-1399/1380.Lucky%20Numbers%20in%20a%20Matrix/README.md", "relative_path_en": "/solution/1300-1399/1380.Lucky%20Numbers%20in%20a%20Matrix/README_EN.md", "title_cn": "\u77e9\u9635\u4e2d\u7684\u5e78\u8fd0\u6570", "title_en": "Lucky Numbers in a Matrix", "question_title_slug": "lucky-numbers-in-a-matrix", "content_en": "

Given a m * n matrix of distinct numbers, return all lucky numbers in the matrix in any order.

\n\n

A lucky number is an element of the matrix such that it is the minimum element in its row and maximum in its column.

\n\n

 

\n

Example 1:

\n\n
\nInput: matrix = [[3,7,8],[9,11,13],[15,16,17]]\nOutput: [15]\nExplanation: 15 is the only lucky number since it is the minimum in its row and the maximum in its column\n
\n\n

Example 2:

\n\n
\nInput: matrix = [[1,10,4,2],[9,3,8,7],[15,16,17,12]]\nOutput: [12]\nExplanation: 12 is the only lucky number since it is the minimum in its row and the maximum in its column.\n
\n\n

Example 3:

\n\n
\nInput: matrix = [[7,8],[1,2]]\nOutput: [7]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • m == mat.length
  • \n\t
  • n == mat[i].length
  • \n\t
  • 1 <= n, m <= 50
  • \n\t
  • 1 <= matrix[i][j] <= 10^5.
  • \n\t
  • All elements in the matrix are distinct.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a m * n \u7684\u77e9\u9635\uff0c\u77e9\u9635\u4e2d\u7684\u6570\u5b57 \u5404\u4e0d\u76f8\u540c \u3002\u8bf7\u4f60\u6309 \u4efb\u610f \u987a\u5e8f\u8fd4\u56de\u77e9\u9635\u4e2d\u7684\u6240\u6709\u5e78\u8fd0\u6570\u3002

\n\n

\u5e78\u8fd0\u6570\u662f\u6307\u77e9\u9635\u4e2d\u6ee1\u8db3\u540c\u65f6\u4e0b\u5217\u4e24\u4e2a\u6761\u4ef6\u7684\u5143\u7d20\uff1a

\n\n
    \n\t
  • \u5728\u540c\u4e00\u884c\u7684\u6240\u6709\u5143\u7d20\u4e2d\u6700\u5c0f
  • \n\t
  • \u5728\u540c\u4e00\u5217\u7684\u6240\u6709\u5143\u7d20\u4e2d\u6700\u5927
  • \n
\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1amatrix = [[3,7,8],[9,11,13],[15,16,17]]\n\u8f93\u51fa\uff1a[15]\n\u89e3\u91ca\uff1a15 \u662f\u552f\u4e00\u7684\u5e78\u8fd0\u6570\uff0c\u56e0\u4e3a\u5b83\u662f\u5176\u6240\u5728\u884c\u4e2d\u7684\u6700\u5c0f\u503c\uff0c\u4e5f\u662f\u6240\u5728\u5217\u4e2d\u7684\u6700\u5927\u503c\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1amatrix = [[1,10,4,2],[9,3,8,7],[15,16,17,12]]\n\u8f93\u51fa\uff1a[12]\n\u89e3\u91ca\uff1a12 \u662f\u552f\u4e00\u7684\u5e78\u8fd0\u6570\uff0c\u56e0\u4e3a\u5b83\u662f\u5176\u6240\u5728\u884c\u4e2d\u7684\u6700\u5c0f\u503c\uff0c\u4e5f\u662f\u6240\u5728\u5217\u4e2d\u7684\u6700\u5927\u503c\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1amatrix = [[7,8],[1,2]]\n\u8f93\u51fa\uff1a[7]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • m == mat.length
  • \n\t
  • n == mat[i].length
  • \n\t
  • 1 <= n, m <= 50
  • \n\t
  • 1 <= matrix[i][j] <= 10^5
  • \n\t
  • \u77e9\u9635\u4e2d\u7684\u6240\u6709\u5143\u7d20\u90fd\u662f\u4e0d\u540c\u7684
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector luckyNumbers (vector>& matrix) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List luckyNumbers (int[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def luckyNumbers (self, matrix):\n \"\"\"\n :type matrix: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def luckyNumbers (self, matrix: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* luckyNumbers (int** matrix, int matrixSize, int* matrixColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList LuckyNumbers (int[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} matrix\n * @return {number[]}\n */\nvar luckyNumbers = function(matrix) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} matrix\n# @return {Integer[]}\ndef lucky_numbers (matrix)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func luckyNumbers (_ matrix: [[Int]]) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func luckyNumbers (matrix [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def luckyNumbers (matrix: Array[Array[Int]]): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun luckyNumbers (matrix: Array): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn lucky_numbers (matrix: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $matrix\n * @return Integer[]\n */\n function luckyNumbers ($matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function luckyNumbers (matrix: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (lucky-numbers matrix)\n (-> (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1380](https://leetcode-cn.com/problems/lucky-numbers-in-a-matrix)", "[\u77e9\u9635\u4e2d\u7684\u5e78\u8fd0\u6570](/solution/1300-1399/1380.Lucky%20Numbers%20in%20a%20Matrix/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1380](https://leetcode.com/problems/lucky-numbers-in-a-matrix)", "[Lucky Numbers in a Matrix](/solution/1300-1399/1380.Lucky%20Numbers%20in%20a%20Matrix/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1495", "frontend_question_id": "1364", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/number-of-trusted-contacts-of-a-customer", "url_en": "https://leetcode.com/problems/number-of-trusted-contacts-of-a-customer", "relative_path_cn": "/solution/1300-1399/1364.Number%20of%20Trusted%20Contacts%20of%20a%20Customer/README.md", "relative_path_en": "/solution/1300-1399/1364.Number%20of%20Trusted%20Contacts%20of%20a%20Customer/README_EN.md", "title_cn": "\u987e\u5ba2\u7684\u53ef\u4fe1\u8054\u7cfb\u4eba\u6570\u91cf", "title_en": "Number of Trusted Contacts of a Customer", "question_title_slug": "number-of-trusted-contacts-of-a-customer", "content_en": "

Table: Customers

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| customer_id   | int     |\n| customer_name | varchar |\n| email         | varchar |\n+---------------+---------+\ncustomer_id is the primary key for this table.\nEach row of this table contains the name and the email of a customer of an online shop.\n
\n\n

 

\n\n

Table: Contacts

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| user_id       | id      |\n| contact_name  | varchar |\n| contact_email | varchar |\n+---------------+---------+\n(user_id, contact_email) is the primary key for this table.\nEach row of this table contains the name and email of one contact of customer with user_id.\nThis table contains information about people each customer trust. The contact may or may not exist in the Customers table.\n\n
\n\n

 

\n\n

Table: Invoices

\n\n
\n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| invoice_id   | int     |\n| price        | int     |\n| user_id      | int     |\n+--------------+---------+\ninvoice_id is the primary key for this table.\nEach row of this table indicates that user_id has an invoice with invoice_id and a price.\n
\n\n

 

\n\n

Write an SQL query to find the following for each invoice_id:

\n\n
    \n\t
  • customer_name: The name of the customer the invoice is related to.
  • \n\t
  • price: The price of the invoice.
  • \n\t
  • contacts_cnt: The number of contacts related to the customer.
  • \n\t
  • trusted_contacts_cnt: The number of contacts related to the customer and at the same time they are customers to the shop. (i.e His/Her email exists in the Customers table.)
  • \n
\n\n

Order the result table by invoice_id.

\n\n

The query result format is in the following example:

\n\n
\nCustomers table:\n+-------------+---------------+--------------------+\n| customer_id | customer_name | email              |\n+-------------+---------------+--------------------+\n| 1           | Alice         | alice@leetcode.com |\n| 2           | Bob           | bob@leetcode.com   |\n| 13          | John          | john@leetcode.com  |\n| 6           | Alex          | alex@leetcode.com  |\n+-------------+---------------+--------------------+\nContacts table:\n+-------------+--------------+--------------------+\n| user_id     | contact_name | contact_email      |\n+-------------+--------------+--------------------+\n| 1           | Bob          | bob@leetcode.com   |\n| 1           | John         | john@leetcode.com  |\n| 1           | Jal          | jal@leetcode.com   |\n| 2           | Omar         | omar@leetcode.com  |\n| 2           | Meir         | meir@leetcode.com  |\n| 6           | Alice        | alice@leetcode.com |\n+-------------+--------------+--------------------+\nInvoices table:\n+------------+-------+---------+\n| invoice_id | price | user_id |\n+------------+-------+---------+\n| 77         | 100   | 1       |\n| 88         | 200   | 1       |\n| 99         | 300   | 2       |\n| 66         | 400   | 2       |\n| 55         | 500   | 13      |\n| 44         | 60    | 6       |\n+------------+-------+---------+\nResult table:\n+------------+---------------+-------+--------------+----------------------+\n| invoice_id | customer_name | price | contacts_cnt | trusted_contacts_cnt |\n+------------+---------------+-------+--------------+----------------------+\n| 44         | Alex          | 60    | 1            | 1                    |\n| 55         | John          | 500   | 0            | 0                    |\n| 66         | Bob           | 400   | 2            | 0                    |\n| 77         | Alice         | 100   | 3            | 2                    |\n| 88         | Alice         | 200   | 3            | 2                    |\n| 99         | Bob           | 300   | 2            | 0                    |\n+------------+---------------+-------+--------------+----------------------+\nAlice has three contacts, two of them are trusted contacts (Bob and John).\nBob has two contacts, none of them is a trusted contact.\nAlex has one contact and it is a trusted contact (Alice).\nJohn doesn't have any contacts.\n
\n", "content_cn": "

\u987e\u5ba2\u8868\uff1aCustomers

\n\n
+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| customer_id   | int     |\n| customer_name | varchar |\n| email         | varchar |\n+---------------+---------+\ncustomer_id \u662f\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\u3002\n\u6b64\u8868\u7684\u6bcf\u4e00\u884c\u5305\u542b\u4e86\u67d0\u5728\u7ebf\u5546\u5e97\u987e\u5ba2\u7684\u59d3\u540d\u548c\u7535\u5b50\u90ae\u4ef6\u3002\n
\n\n

 

\n\n

\u8054\u7cfb\u65b9\u5f0f\u8868\uff1aContacts

\n\n
+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| user_id       | id      |\n| contact_name  | varchar |\n| contact_email | varchar |\n+---------------+---------+\n(user_id, contact_email) \u662f\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\u3002\n\u6b64\u8868\u7684\u6bcf\u4e00\u884c\u8868\u793a\u7f16\u53f7\u4e3a user_id \u7684\u987e\u5ba2\u7684\u67d0\u4f4d\u8054\u7cfb\u4eba\u7684\u59d3\u540d\u548c\u7535\u5b50\u90ae\u4ef6\u3002\n\u6b64\u8868\u5305\u542b\u6bcf\u4f4d\u987e\u5ba2\u7684\u8054\u7cfb\u4eba\u4fe1\u606f\uff0c\u4f46\u987e\u5ba2\u7684\u8054\u7cfb\u4eba\u4e0d\u4e00\u5b9a\u5b58\u5728\u4e8e\u987e\u5ba2\u8868\u4e2d\u3002\n
\n\n

 

\n\n

\u53d1\u7968\u8868\uff1aInvoices

\n\n
+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| invoice_id   | int     |\n| price        | int     |\n| user_id      | int     |\n+--------------+---------+\ninvoice_id \u662f\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\u3002\n\u6b64\u8868\u7684\u6bcf\u4e00\u884c\u5206\u522b\u8868\u793a\u7f16\u53f7\u4e3a user_id \u7684\u987e\u5ba2\u62e5\u6709\u6709\u4e00\u5f20\u7f16\u53f7\u4e3a invoice_id\u3001\u4ef7\u683c\u4e3a price \u7684\u53d1\u7968\u3002\n
\n\n

 

\n\n

\u4e3a\u6bcf\u5f20\u53d1\u7968 invoice_id \u7f16\u5199\u4e00\u4e2aSQL\u67e5\u8be2\u4ee5\u67e5\u627e\u4ee5\u4e0b\u5185\u5bb9\uff1a

\n\n
    \n\t
  • customer_name\uff1a\u4e0e\u53d1\u7968\u76f8\u5173\u7684\u987e\u5ba2\u540d\u79f0\u3002
  • \n\t
  • price\uff1a\u53d1\u7968\u7684\u4ef7\u683c\u3002
  • \n\t
  • contacts_cnt\uff1a\u8be5\u987e\u5ba2\u7684\u8054\u7cfb\u4eba\u6570\u91cf\u3002
  • \n\t
  • trusted_contacts_cnt\uff1a\u53ef\u4fe1\u8054\u7cfb\u4eba\u7684\u6570\u91cf\uff1a\u65e2\u662f\u8be5\u987e\u5ba2\u7684\u8054\u7cfb\u4eba\u53c8\u662f\u5546\u5e97\u987e\u5ba2\u7684\u8054\u7cfb\u4eba\u6570\u91cf\uff08\u5373\uff1a\u53ef\u4fe1\u8054\u7cfb\u4eba\u7684\u7535\u5b50\u90ae\u4ef6\u5b58\u5728\u4e8e\u5ba2\u6237\u8868\u4e2d\uff09\u3002
  • \n
\n\n

\u5c06\u67e5\u8be2\u7684\u7ed3\u679c\u6309\u7167 invoice_id \u6392\u5e8f\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u7684\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a\uff1a

\n\n
Customers table:\n+-------------+---------------+--------------------+\n| customer_id | customer_name | email              |\n+-------------+---------------+--------------------+\n| 1           | Alice         | alice@leetcode.com |\n| 2           | Bob           | bob@leetcode.com   |\n| 13          | John          | john@leetcode.com  |\n| 6           | Alex          | alex@leetcode.com  |\n+-------------+---------------+--------------------+\nContacts table:\n+-------------+--------------+--------------------+\n| user_id     | contact_name | contact_email      |\n+-------------+--------------+--------------------+\n| 1           | Bob          | bob@leetcode.com   |\n| 1           | John         | john@leetcode.com  |\n| 1           | Jal          | jal@leetcode.com   |\n| 2           | Omar         | omar@leetcode.com  |\n| 2           | Meir         | meir@leetcode.com  |\n| 6           | Alice        | alice@leetcode.com |\n+-------------+--------------+--------------------+\nInvoices table:\n+------------+-------+---------+\n| invoice_id | price | user_id |\n+------------+-------+---------+\n| 77         | 100   | 1       |\n| 88         | 200   | 1       |\n| 99         | 300   | 2       |\n| 66         | 400   | 2       |\n| 55         | 500   | 13      |\n| 44         | 60    | 6       |\n+------------+-------+---------+\nResult table:\n+------------+---------------+-------+--------------+----------------------+\n| invoice_id | customer_name | price | contacts_cnt | trusted_contacts_cnt |\n+------------+---------------+-------+--------------+----------------------+\n| 44         | Alex          | 60    | 1            | 1                    |\n| 55         | John          | 500   | 0            | 0                    |\n| 66         | Bob           | 400   | 2            | 0                    |\n| 77         | Alice         | 100   | 3            | 2                    |\n| 88         | Alice         | 200   | 3            | 2                    |\n| 99         | Bob           | 300   | 2            | 0                    |\n+------------+---------------+-------+--------------+----------------------+\nAlice \u6709\u4e09\u4f4d\u8054\u7cfb\u4eba\uff0c\u5176\u4e2d\u4e24\u4f4d(Bob \u548c John)\u662f\u53ef\u4fe1\u8054\u7cfb\u4eba\u3002\nBob \u6709\u4e24\u4f4d\u8054\u7cfb\u4eba, \u4ed6\u4eec\u4e2d\u7684\u4efb\u4f55\u4e00\u4f4d\u90fd\u4e0d\u662f\u53ef\u4fe1\u8054\u7cfb\u4eba\u3002\nAlex \u53ea\u6709\u4e00\u4f4d\u8054\u7cfb\u4eba(Alice)\uff0c\u5e76\u662f\u4e00\u4f4d\u53ef\u4fe1\u8054\u7cfb\u4eba\u3002\nJohn \u6ca1\u6709\u4efb\u4f55\u8054\u7cfb\u4eba\u3002\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1364](https://leetcode-cn.com/problems/number-of-trusted-contacts-of-a-customer)", "[\u987e\u5ba2\u7684\u53ef\u4fe1\u8054\u7cfb\u4eba\u6570\u91cf](/solution/1300-1399/1364.Number%20of%20Trusted%20Contacts%20of%20a%20Customer/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1364](https://leetcode.com/problems/number-of-trusted-contacts-of-a-customer)", "[Number of Trusted Contacts of a Customer](/solution/1300-1399/1364.Number%20of%20Trusted%20Contacts%20of%20a%20Customer/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1494", "frontend_question_id": "1355", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/activity-participants", "url_en": "https://leetcode.com/problems/activity-participants", "relative_path_cn": "/solution/1300-1399/1355.Activity%20Participants/README.md", "relative_path_en": "/solution/1300-1399/1355.Activity%20Participants/README_EN.md", "title_cn": "\u6d3b\u52a8\u53c2\u4e0e\u8005", "title_en": "Activity Participants", "question_title_slug": "activity-participants", "content_en": "

Table: Friends

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| name          | varchar |\n| activity      | varchar |\n+---------------+---------+\nid is the id of the friend and primary key for this table.\nname is the name of the friend.\nactivity is the name of the activity which the friend takes part in.\n
\n\n

Table: Activities

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| name          | varchar |\n+---------------+---------+\nid is the primary key for this table.\nname is the name of the activity.\n
\n\n

 

\n\n

Write an SQL query to find the names of all the activities with neither maximum, nor minimum number of participants.

\n\n

Return the result table in any order. Each activity in table Activities is performed by any person in the table Friends.

\n\n

The query result format is in the following example:

\n\n
\nFriends table:\n+------+--------------+---------------+\n| id   | name         | activity      |\n+------+--------------+---------------+\n| 1    | Jonathan D.  | Eating        |\n| 2    | Jade W.      | Singing       |\n| 3    | Victor J.    | Singing       |\n| 4    | Elvis Q.     | Eating        |\n| 5    | Daniel A.    | Eating        |\n| 6    | Bob B.       | Horse Riding  |\n+------+--------------+---------------+\n\nActivities table:\n+------+--------------+\n| id   | name         |\n+------+--------------+\n| 1    | Eating       |\n| 2    | Singing      |\n| 3    | Horse Riding |\n+------+--------------+\n\nResult table:\n+--------------+\n| activity     |\n+--------------+\n| Singing      |\n+--------------+\n\nEating activity is performed by 3 friends, maximum number of participants, (Jonathan D. , Elvis Q. and Daniel A.)\nHorse Riding activity is performed by 1 friend, minimum number of participants, (Bob B.)\nSinging is performed by 2 friends (Victor J. and Jade W.)\n
\n", "content_cn": "

\u8868: Friends

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| name          | varchar |\n| activity      | varchar |\n+---------------+---------+\nid \u662f\u670b\u53cb\u7684 id \u548c\u8be5\u8868\u7684\u4e3b\u952e\nname \u662f\u670b\u53cb\u7684\u540d\u5b57\nactivity \u662f\u670b\u53cb\u53c2\u52a0\u7684\u6d3b\u52a8\u7684\u540d\u5b57\n
\n\n

\u8868: Activities

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| name          | varchar |\n+---------------+---------+\nid \u662f\u8be5\u8868\u7684\u4e3b\u952e\nname \u662f\u6d3b\u52a8\u7684\u540d\u5b57\n
\n\n

\u00a0

\n\n

\u5199\u4e00\u6761 SQL \u67e5\u8be2\u90a3\u4e9b\u65e2\u6ca1\u6709\u6700\u591a\uff0c\u4e5f\u6ca1\u6709\u6700\u5c11\u53c2\u4e0e\u8005\u7684\u6d3b\u52a8\u7684\u540d\u5b57

\n\n

\u53ef\u4ee5\u4ee5\u4efb\u4f55\u987a\u5e8f\u8fd4\u56de\u7ed3\u679c\uff0cActivities \u8868\u7684\u6bcf\u9879\u6d3b\u52a8\u7684\u53c2\u4e0e\u8005\u90fd\u6765\u81ea Friends \u8868

\n\n

\u6ce8\u610f\uff1a\u540d\u79f0\u76f8\u540c id \u4e0d\u540c\u7684\u53c2\u4e0e\u8005\u7b97\u4f5c\u4e24\u4e2a\u4eba

\n\n

\u4e0b\u9762\u662f\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u7684\u4f8b\u5b50\uff1a

\n\n
\nFriends \u8868:\n+------+--------------+---------------+\n| id   | name         | activity      |\n+------+--------------+---------------+\n| 1    | Jonathan D.  | Eating        |\n| 2    | Jade W.      | Singing       |\n| 3    | Victor J.    | Singing       |\n| 4    | Elvis Q.     | Eating        |\n| 5    | Daniel A.    | Eating        |\n| 6    | Bob B.       | Horse Riding  |\n+------+--------------+---------------+\n\nActivities \u8868:\n+------+--------------+\n| id   | name         |\n+------+--------------+\n| 1    | Eating       |\n| 2    | Singing      |\n| 3    | Horse Riding |\n+------+--------------+\n\nResult \u8868:\n+--------------+\n| activity     |\n+--------------+\n| Singing      |\n+--------------+\n\nEating \u6d3b\u52a8\u6709\u4e09\u4e2a\u4eba\u53c2\u52a0, \u662f\u6700\u591a\u4eba\u53c2\u52a0\u7684\u6d3b\u52a8 (Jonathan D. , Elvis Q. and Daniel A.)\nHorse Riding \u6d3b\u52a8\u6709\u4e00\u4e2a\u4eba\u53c2\u52a0, \u662f\u6700\u5c11\u4eba\u53c2\u52a0\u7684\u6d3b\u52a8 (Bob B.)\nSinging \u6d3b\u52a8\u6709\u4e24\u4e2a\u4eba\u53c2\u52a0 (Victor J. and Jade W.)\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1355](https://leetcode-cn.com/problems/activity-participants)", "[\u6d3b\u52a8\u53c2\u4e0e\u8005](/solution/1300-1399/1355.Activity%20Participants/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1355](https://leetcode.com/problems/activity-participants)", "[Activity Participants](/solution/1300-1399/1355.Activity%20Participants/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1493", "frontend_question_id": "1377", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/frog-position-after-t-seconds", "url_en": "https://leetcode.com/problems/frog-position-after-t-seconds", "relative_path_cn": "/solution/1300-1399/1377.Frog%20Position%20After%20T%20Seconds/README.md", "relative_path_en": "/solution/1300-1399/1377.Frog%20Position%20After%20T%20Seconds/README_EN.md", "title_cn": "T \u79d2\u540e\u9752\u86d9\u7684\u4f4d\u7f6e", "title_en": "Frog Position After T Seconds", "question_title_slug": "frog-position-after-t-seconds", "content_en": "

Given an undirected tree consisting of n vertices numbered from 1 to n. A frog starts jumping from vertex 1. In one second, the frog jumps from its current vertex to another unvisited vertex if they are directly connected. The frog can not jump back to a visited vertex. In case the frog can jump to several vertices, it jumps randomly to one of them with the same probability. Otherwise, when the frog can not jump to any unvisited vertex, it jumps forever on the same vertex.

\n\n

The edges of the undirected tree are given in the array edges, where edges[i] = [ai, bi] means that exists an edge connecting the vertices ai and bi.

\n\n

Return the probability that after t seconds the frog is on the vertex target.

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: n = 7, edges = [[1,2],[1,3],[1,7],[2,4],[2,6],[3,5]], t = 2, target = 4\nOutput: 0.16666666666666666 \nExplanation: The figure above shows the given graph. The frog starts at vertex 1, jumping with 1/3 probability to the vertex 2 after second 1 and then jumping with 1/2 probability to vertex 4 after second 2. Thus the probability for the frog is on the vertex 4 after 2 seconds is 1/3 * 1/2 = 1/6 = 0.16666666666666666. \n
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: n = 7, edges = [[1,2],[1,3],[1,7],[2,4],[2,6],[3,5]], t = 1, target = 7\nOutput: 0.3333333333333333\nExplanation: The figure above shows the given graph. The frog starts at vertex 1, jumping with 1/3 = 0.3333333333333333 probability to the vertex 7 after second 1. \n
\n\n

Example 3:

\n\n
\nInput: n = 7, edges = [[1,2],[1,3],[1,7],[2,4],[2,6],[3,5]], t = 20, target = 6\nOutput: 0.16666666666666666\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 100
  • \n\t
  • edges.length == n - 1
  • \n\t
  • edges[i].length == 2
  • \n\t
  • 1 <= ai, bi <= n
  • \n\t
  • 1 <= t <= 50
  • \n\t
  • 1 <= target <= n
  • \n\t
  • Answers within 10-5 of the actual value will be accepted as correct.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u68f5\u7531 n \u4e2a\u9876\u70b9\u7ec4\u6210\u7684\u65e0\u5411\u6811\uff0c\u9876\u70b9\u7f16\u53f7\u4ece 1 \u5230 n\u3002\u9752\u86d9\u4ece \u9876\u70b9 1 \u5f00\u59cb\u8d77\u8df3\u3002\u89c4\u5219\u5982\u4e0b\uff1a

\n\n
    \n\t
  • \u5728\u4e00\u79d2\u5185\uff0c\u9752\u86d9\u4ece\u5b83\u6240\u5728\u7684\u5f53\u524d\u9876\u70b9\u8df3\u5230\u53e6\u4e00\u4e2a \u672a\u8bbf\u95ee \u8fc7\u7684\u9876\u70b9\uff08\u5982\u679c\u5b83\u4eec\u76f4\u63a5\u76f8\u8fde\uff09\u3002
  • \n\t
  • \u9752\u86d9\u65e0\u6cd5\u8df3\u56de\u5df2\u7ecf\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\u3002
  • \n\t
  • \u5982\u679c\u9752\u86d9\u53ef\u4ee5\u8df3\u5230\u591a\u4e2a\u4e0d\u540c\u9876\u70b9\uff0c\u90a3\u4e48\u5b83\u8df3\u5230\u5176\u4e2d\u4efb\u610f\u4e00\u4e2a\u9876\u70b9\u4e0a\u7684\u673a\u7387\u90fd\u76f8\u540c\u3002
  • \n\t
  • \u5982\u679c\u9752\u86d9\u4e0d\u80fd\u8df3\u5230\u4efb\u4f55\u672a\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\u4e0a\uff0c\u90a3\u4e48\u5b83\u6bcf\u6b21\u8df3\u8dc3\u90fd\u4f1a\u505c\u7559\u5728\u539f\u5730\u3002
  • \n
\n\n

\u65e0\u5411\u6811\u7684\u8fb9\u7528\u6570\u7ec4 edges \u63cf\u8ff0\uff0c\u5176\u4e2d edges[i] = [fromi, toi] \u610f\u5473\u7740\u5b58\u5728\u4e00\u6761\u76f4\u63a5\u8fde\u901a fromi \u548c toi \u4e24\u4e2a\u9876\u70b9\u7684\u8fb9\u3002

\n\n

\u8fd4\u56de\u9752\u86d9\u5728 t \u79d2\u540e\u4f4d\u4e8e\u76ee\u6807\u9876\u70b9 target \u4e0a\u7684\u6982\u7387\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1an = 7, edges = [[1,2],[1,3],[1,7],[2,4],[2,6],[3,5]], t = 2, target = 4\n\u8f93\u51fa\uff1a0.16666666666666666 \n\u89e3\u91ca\uff1a\u4e0a\u56fe\u663e\u793a\u4e86\u9752\u86d9\u7684\u8df3\u8dc3\u8def\u5f84\u3002\u9752\u86d9\u4ece\u9876\u70b9 1 \u8d77\u8df3\uff0c\u7b2c 1 \u79d2 \u6709 1/3 \u7684\u6982\u7387\u8df3\u5230\u9876\u70b9 2 \uff0c\u7136\u540e\u7b2c 2 \u79d2 \u6709 1/2 \u7684\u6982\u7387\u8df3\u5230\u9876\u70b9 4\uff0c\u56e0\u6b64\u9752\u86d9\u5728 2 \u79d2\u540e\u4f4d\u4e8e\u9876\u70b9 4 \u7684\u6982\u7387\u662f 1/3 * 1/2 = 1/6 = 0.16666666666666666 \u3002 \n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1an = 7, edges = [[1,2],[1,3],[1,7],[2,4],[2,6],[3,5]], t = 1, target = 7\n\u8f93\u51fa\uff1a0.3333333333333333\n\u89e3\u91ca\uff1a\u4e0a\u56fe\u663e\u793a\u4e86\u9752\u86d9\u7684\u8df3\u8dc3\u8def\u5f84\u3002\u9752\u86d9\u4ece\u9876\u70b9 1 \u8d77\u8df3\uff0c\u6709 1/3 = 0.3333333333333333 \u7684\u6982\u7387\u80fd\u591f 1 \u79d2 \u540e\u8df3\u5230\u9876\u70b9 7 \u3002 \n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1an = 7, edges = [[1,2],[1,3],[1,7],[2,4],[2,6],[3,5]], t = 20, target = 6\n\u8f93\u51fa\uff1a0.16666666666666666\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 100
  • \n\t
  • edges.length == n-1
  • \n\t
  • edges[i].length == 2
  • \n\t
  • 1 <= edges[i][0], edges[i][1] <= n
  • \n\t
  • 1 <= t <= 50
  • \n\t
  • 1 <= target <= n
  • \n\t
  • \u4e0e\u51c6\u786e\u503c\u8bef\u5dee\u5728 10^-5 \u4e4b\u5185\u7684\u7ed3\u679c\u5c06\u88ab\u5224\u5b9a\u4e3a\u6b63\u786e\u3002
  • \n
\n", "tags_en": ["Depth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n double frogPosition(int n, vector>& edges, int t, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double frogPosition(int n, int[][] edges, int t, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def frogPosition(self, n, edges, t, target):\n \"\"\"\n :type n: int\n :type edges: List[List[int]]\n :type t: int\n :type target: int\n :rtype: float\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def frogPosition(self, n: int, edges: List[List[int]], t: int, target: int) -> float:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\ndouble frogPosition(int n, int** edges, int edgesSize, int* edgesColSize, int t, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double FrogPosition(int n, int[][] edges, int t, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} edges\n * @param {number} t\n * @param {number} target\n * @return {number}\n */\nvar frogPosition = function(n, edges, t, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} edges\n# @param {Integer} t\n# @param {Integer} target\n# @return {Float}\ndef frog_position(n, edges, t, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func frogPosition(_ n: Int, _ edges: [[Int]], _ t: Int, _ target: Int) -> Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func frogPosition(n int, edges [][]int, t int, target int) float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def frogPosition(n: Int, edges: Array[Array[Int]], t: Int, target: Int): Double = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun frogPosition(n: Int, edges: Array, t: Int, target: Int): Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn frog_position(n: i32, edges: Vec>, t: i32, target: i32) -> f64 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $edges\n * @param Integer $t\n * @param Integer $target\n * @return Float\n */\n function frogPosition($n, $edges, $t, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function frogPosition(n: number, edges: number[][], t: number, target: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (frog-position n edges t target)\n (-> exact-integer? (listof (listof exact-integer?)) exact-integer? exact-integer? flonum?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1377](https://leetcode-cn.com/problems/frog-position-after-t-seconds)", "[T \u79d2\u540e\u9752\u86d9\u7684\u4f4d\u7f6e](/solution/1300-1399/1377.Frog%20Position%20After%20T%20Seconds/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[1377](https://leetcode.com/problems/frog-position-after-t-seconds)", "[Frog Position After T Seconds](/solution/1300-1399/1377.Frog%20Position%20After%20T%20Seconds/README_EN.md)", "`Depth-first Search`", "Hard", ""]}, {"question_id": "1492", "frontend_question_id": "1376", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/time-needed-to-inform-all-employees", "url_en": "https://leetcode.com/problems/time-needed-to-inform-all-employees", "relative_path_cn": "/solution/1300-1399/1376.Time%20Needed%20to%20Inform%20All%20Employees/README.md", "relative_path_en": "/solution/1300-1399/1376.Time%20Needed%20to%20Inform%20All%20Employees/README_EN.md", "title_cn": "\u901a\u77e5\u6240\u6709\u5458\u5de5\u6240\u9700\u7684\u65f6\u95f4", "title_en": "Time Needed to Inform All Employees", "question_title_slug": "time-needed-to-inform-all-employees", "content_en": "

A company has n employees with a unique ID for each employee from 0 to n - 1. The head of the company is the one with headID.

\n\n

Each employee has one direct manager given in the manager array where manager[i] is the direct manager of the i-th employee, manager[headID] = -1. Also, it is guaranteed that the subordination relationships have a tree structure.

\n\n

The head of the company wants to inform all the company employees of an urgent piece of news. He will inform his direct subordinates, and they will inform their subordinates, and so on until all employees know about the urgent news.

\n\n

The i-th employee needs informTime[i] minutes to inform all of his direct subordinates (i.e., After informTime[i] minutes, all his direct subordinates can start spreading the news).

\n\n

Return the number of minutes needed to inform all the employees about the urgent news.

\n\n

 

\n

Example 1:

\n\n
\nInput: n = 1, headID = 0, manager = [-1], informTime = [0]\nOutput: 0\nExplanation: The head of the company is the only employee in the company.\n
\n\n

Example 2:

\n\"\"\n
\nInput: n = 6, headID = 2, manager = [2,2,-1,2,2,2], informTime = [0,0,1,0,0,0]\nOutput: 1\nExplanation: The head of the company with id = 2 is the direct manager of all the employees in the company and needs 1 minute to inform them all.\nThe tree structure of the employees in the company is shown.\n
\n\n

Example 3:

\n\"\"\n
\nInput: n = 7, headID = 6, manager = [1,2,3,4,5,6,-1], informTime = [0,6,5,4,3,2,1]\nOutput: 21\nExplanation: The head has id = 6. He will inform employee with id = 5 in 1 minute.\nThe employee with id = 5 will inform the employee with id = 4 in 2 minutes.\nThe employee with id = 4 will inform the employee with id = 3 in 3 minutes.\nThe employee with id = 3 will inform the employee with id = 2 in 4 minutes.\nThe employee with id = 2 will inform the employee with id = 1 in 5 minutes.\nThe employee with id = 1 will inform the employee with id = 0 in 6 minutes.\nNeeded time = 1 + 2 + 3 + 4 + 5 + 6 = 21.\n
\n\n

Example 4:

\n\n
\nInput: n = 15, headID = 0, manager = [-1,0,0,1,1,2,2,3,3,4,4,5,5,6,6], informTime = [1,1,1,1,1,1,1,0,0,0,0,0,0,0,0]\nOutput: 3\nExplanation: The first minute the head will inform employees 1 and 2.\nThe second minute they will inform employees 3, 4, 5 and 6.\nThe third minute they will inform the rest of employees.\n
\n\n

Example 5:

\n\n
\nInput: n = 4, headID = 2, manager = [3,3,-1,2], informTime = [0,0,162,914]\nOutput: 1076\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 105
  • \n\t
  • 0 <= headID < n
  • \n\t
  • manager.length == n
  • \n\t
  • 0 <= manager[i] < n
  • \n\t
  • manager[headID] == -1
  • \n\t
  • informTime.length == n
  • \n\t
  • 0 <= informTime[i] <= 1000
  • \n\t
  • informTime[i] == 0 if employee i has no subordinates.
  • \n\t
  • It is guaranteed that all the employees can be informed.
  • \n
\n", "content_cn": "

\u516c\u53f8\u91cc\u6709 n \u540d\u5458\u5de5\uff0c\u6bcf\u4e2a\u5458\u5de5\u7684 ID \u90fd\u662f\u72ec\u4e00\u65e0\u4e8c\u7684\uff0c\u7f16\u53f7\u4ece 0 \u5230 n - 1\u3002\u516c\u53f8\u7684\u603b\u8d1f\u8d23\u4eba\u901a\u8fc7 headID \u8fdb\u884c\u6807\u8bc6\u3002

\n\n

\u5728 manager \u6570\u7ec4\u4e2d\uff0c\u6bcf\u4e2a\u5458\u5de5\u90fd\u6709\u4e00\u4e2a\u76f4\u5c5e\u8d1f\u8d23\u4eba\uff0c\u5176\u4e2d manager[i] \u662f\u7b2c i \u540d\u5458\u5de5\u7684\u76f4\u5c5e\u8d1f\u8d23\u4eba\u3002\u5bf9\u4e8e\u603b\u8d1f\u8d23\u4eba\uff0cmanager[headID] = -1\u3002\u9898\u76ee\u4fdd\u8bc1\u4ece\u5c5e\u5173\u7cfb\u53ef\u4ee5\u7528\u6811\u7ed3\u6784\u663e\u793a\u3002

\n\n

\u516c\u53f8\u603b\u8d1f\u8d23\u4eba\u60f3\u8981\u5411\u516c\u53f8\u6240\u6709\u5458\u5de5\u901a\u544a\u4e00\u6761\u7d27\u6025\u6d88\u606f\u3002\u4ed6\u5c06\u4f1a\u9996\u5148\u901a\u77e5\u4ed6\u7684\u76f4\u5c5e\u4e0b\u5c5e\u4eec\uff0c\u7136\u540e\u7531\u8fd9\u4e9b\u4e0b\u5c5e\u901a\u77e5\u4ed6\u4eec\u7684\u4e0b\u5c5e\uff0c\u76f4\u5230\u6240\u6709\u7684\u5458\u5de5\u90fd\u5f97\u77e5\u8fd9\u6761\u7d27\u6025\u6d88\u606f\u3002

\n\n

\u7b2c i \u540d\u5458\u5de5\u9700\u8981 informTime[i] \u5206\u949f\u6765\u901a\u77e5\u5b83\u7684\u6240\u6709\u76f4\u5c5e\u4e0b\u5c5e\uff08\u4e5f\u5c31\u662f\u8bf4\u5728 informTime[i] \u5206\u949f\u540e\uff0c\u4ed6\u7684\u6240\u6709\u76f4\u5c5e\u4e0b\u5c5e\u90fd\u53ef\u4ee5\u5f00\u59cb\u4f20\u64ad\u8fd9\u4e00\u6d88\u606f\uff09\u3002

\n\n

\u8fd4\u56de\u901a\u77e5\u6240\u6709\u5458\u5de5\u8fd9\u4e00\u7d27\u6025\u6d88\u606f\u6240\u9700\u8981\u7684 \u5206\u949f\u6570 \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1an = 1, headID = 0, manager = [-1], informTime = [0]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u516c\u53f8\u603b\u8d1f\u8d23\u4eba\u662f\u8be5\u516c\u53f8\u7684\u552f\u4e00\u4e00\u540d\u5458\u5de5\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1an = 6, headID = 2, manager = [2,2,-1,2,2,2], informTime = [0,0,1,0,0,0]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1aid = 2 \u7684\u5458\u5de5\u662f\u516c\u53f8\u7684\u603b\u8d1f\u8d23\u4eba\uff0c\u4e5f\u662f\u5176\u4ed6\u6240\u6709\u5458\u5de5\u7684\u76f4\u5c5e\u8d1f\u8d23\u4eba\uff0c\u4ed6\u9700\u8981 1 \u5206\u949f\u6765\u901a\u77e5\u6240\u6709\u5458\u5de5\u3002\n\u4e0a\u56fe\u663e\u793a\u4e86\u516c\u53f8\u5458\u5de5\u7684\u6811\u7ed3\u6784\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1an = 7, headID = 6, manager = [1,2,3,4,5,6,-1], informTime = [0,6,5,4,3,2,1]\n\u8f93\u51fa\uff1a21\n\u89e3\u91ca\uff1a\u603b\u8d1f\u8d23\u4eba id = 6\u3002\u4ed6\u5c06\u5728 1 \u5206\u949f\u5185\u901a\u77e5 id = 5 \u7684\u5458\u5de5\u3002\nid = 5 \u7684\u5458\u5de5\u5c06\u5728 2 \u5206\u949f\u5185\u901a\u77e5 id = 4 \u7684\u5458\u5de5\u3002\nid = 4 \u7684\u5458\u5de5\u5c06\u5728 3 \u5206\u949f\u5185\u901a\u77e5 id = 3 \u7684\u5458\u5de5\u3002\nid = 3 \u7684\u5458\u5de5\u5c06\u5728 4 \u5206\u949f\u5185\u901a\u77e5 id = 2 \u7684\u5458\u5de5\u3002\nid = 2 \u7684\u5458\u5de5\u5c06\u5728 5 \u5206\u949f\u5185\u901a\u77e5 id = 1 \u7684\u5458\u5de5\u3002\nid = 1 \u7684\u5458\u5de5\u5c06\u5728 6 \u5206\u949f\u5185\u901a\u77e5 id = 0 \u7684\u5458\u5de5\u3002\n\u6240\u9700\u65f6\u95f4 = 1 + 2 + 3 + 4 + 5 + 6 = 21 \u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1an = 15, headID = 0, manager = [-1,0,0,1,1,2,2,3,3,4,4,5,5,6,6], informTime = [1,1,1,1,1,1,1,0,0,0,0,0,0,0,0]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u7b2c\u4e00\u5206\u949f\u603b\u8d1f\u8d23\u4eba\u901a\u77e5\u5458\u5de5 1 \u548c 2 \u3002\n\u7b2c\u4e8c\u5206\u949f\u4ed6\u4eec\u5c06\u4f1a\u901a\u77e5\u5458\u5de5 3, 4, 5 \u548c 6 \u3002\n\u7b2c\u4e09\u5206\u949f\u4ed6\u4eec\u5c06\u4f1a\u901a\u77e5\u5269\u4e0b\u7684\u5458\u5de5\u3002\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1an = 4, headID = 2, manager = [3,3,-1,2], informTime = [0,0,162,914]\n\u8f93\u51fa\uff1a1076\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 10^5
  • \n\t
  • 0 <= headID < n
  • \n\t
  • manager.length == n
  • \n\t
  • 0 <= manager[i] < n
  • \n\t
  • manager[headID] == -1
  • \n\t
  • informTime.length == n
  • \n\t
  • 0 <= informTime[i] <= 1000
  • \n\t
  • \u5982\u679c\u5458\u5de5 i \u6ca1\u6709\u4e0b\u5c5e\uff0cinformTime[i] == 0 \u3002
  • \n\t
  • \u9898\u76ee \u4fdd\u8bc1 \u6240\u6709\u5458\u5de5\u90fd\u53ef\u4ee5\u6536\u5230\u901a\u77e5\u3002
  • \n
\n", "tags_en": ["Depth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numOfMinutes(int n, int headID, vector& manager, vector& informTime) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numOfMinutes(int n, int headID, int[] manager, int[] informTime) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numOfMinutes(self, n, headID, manager, informTime):\n \"\"\"\n :type n: int\n :type headID: int\n :type manager: List[int]\n :type informTime: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numOfMinutes(self, n: int, headID: int, manager: List[int], informTime: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numOfMinutes(int n, int headID, int* manager, int managerSize, int* informTime, int informTimeSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumOfMinutes(int n, int headID, int[] manager, int[] informTime) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} headID\n * @param {number[]} manager\n * @param {number[]} informTime\n * @return {number}\n */\nvar numOfMinutes = function(n, headID, manager, informTime) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} head_id\n# @param {Integer[]} manager\n# @param {Integer[]} inform_time\n# @return {Integer}\ndef num_of_minutes(n, head_id, manager, inform_time)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numOfMinutes(_ n: Int, _ headID: Int, _ manager: [Int], _ informTime: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numOfMinutes(n int, headID int, manager []int, informTime []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numOfMinutes(n: Int, headID: Int, manager: Array[Int], informTime: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numOfMinutes(n: Int, headID: Int, manager: IntArray, informTime: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_of_minutes(n: i32, head_id: i32, manager: Vec, inform_time: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $headID\n * @param Integer[] $manager\n * @param Integer[] $informTime\n * @return Integer\n */\n function numOfMinutes($n, $headID, $manager, $informTime) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numOfMinutes(n: number, headID: number, manager: number[], informTime: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-of-minutes n headID manager informTime)\n (-> exact-integer? exact-integer? (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1376](https://leetcode-cn.com/problems/time-needed-to-inform-all-employees)", "[\u901a\u77e5\u6240\u6709\u5458\u5de5\u6240\u9700\u7684\u65f6\u95f4](/solution/1300-1399/1376.Time%20Needed%20to%20Inform%20All%20Employees/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1376](https://leetcode.com/problems/time-needed-to-inform-all-employees)", "[Time Needed to Inform All Employees](/solution/1300-1399/1376.Time%20Needed%20to%20Inform%20All%20Employees/README_EN.md)", "`Depth-first Search`", "Medium", ""]}, {"question_id": "1491", "frontend_question_id": "1375", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/bulb-switcher-iii", "url_en": "https://leetcode.com/problems/bulb-switcher-iii", "relative_path_cn": "/solution/1300-1399/1375.Bulb%20Switcher%20III/README.md", "relative_path_en": "/solution/1300-1399/1375.Bulb%20Switcher%20III/README_EN.md", "title_cn": "\u706f\u6ce1\u5f00\u5173 III", "title_en": "Bulb Switcher III", "question_title_slug": "bulb-switcher-iii", "content_en": "

There is a room with n bulbs, numbered from 1 to n, arranged in a row from left to right. Initially, all the bulbs are turned off.

\n\n

At moment k (for k from 0 to n - 1), we turn on the light[k] bulb. A bulb change color to blue only if it is on and all the previous bulbs (to the left) are turned on too.

\n\n

Return the number of moments in which all turned on bulbs are blue.

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: light = [2,1,3,5,4]\nOutput: 3\nExplanation: All bulbs turned on, are blue at the moment 1, 2 and 4.\n
\n\n

Example 2:

\n\n
\nInput: light = [3,2,4,1,5]\nOutput: 2\nExplanation: All bulbs turned on, are blue at the moment 3, and 4 (index-0).\n
\n\n

Example 3:

\n\n
\nInput: light = [4,1,2,3]\nOutput: 1\nExplanation: All bulbs turned on, are blue at the moment 3 (index-0).\nBulb 4th changes to blue at the moment 3.\n
\n\n

Example 4:

\n\n
\nInput: light = [2,1,4,3,6,5]\nOutput: 3\n
\n\n

Example 5:

\n\n
\nInput: light = [1,2,3,4,5,6]\nOutput: 6\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == light.length
  • \n\t
  • 1 <= n <= 5 * 10^4
  • \n\t
  • light is a permutation of  [1, 2, ..., n]
  • \n
\n", "content_cn": "

\u623f\u95f4\u4e2d\u6709 n \u679a\u706f\u6ce1\uff0c\u7f16\u53f7\u4ece 1 \u5230 n\uff0c\u81ea\u5de6\u5411\u53f3\u6392\u6210\u4e00\u6392\u3002\u6700\u521d\uff0c\u6240\u6709\u7684\u706f\u90fd\u662f\u5173\u7740\u7684\u3002

\n\n

\u5728 k  \u65f6\u523b\uff08 k \u7684\u53d6\u503c\u8303\u56f4\u662f 0 \u5230 n - 1\uff09\uff0c\u6211\u4eec\u6253\u5f00 light[k] \u8fd9\u4e2a\u706f\u3002

\n\n

\u706f\u7684\u989c\u8272\u8981\u60f3 \u53d8\u6210\u84dd\u8272 \u5c31\u5fc5\u987b\u540c\u65f6\u6ee1\u8db3\u4e0b\u9762\u4e24\u4e2a\u6761\u4ef6\uff1a

\n\n
    \n\t
  • \u706f\u5904\u4e8e\u6253\u5f00\u72b6\u6001\u3002
  • \n\t
  • \u6392\u5728\u5b83\u4e4b\u524d\uff08\u5de6\u4fa7\uff09\u7684\u6240\u6709\u706f\u4e5f\u90fd\u5904\u4e8e\u6253\u5f00\u72b6\u6001\u3002
  • \n
\n\n

\u8bf7\u8fd4\u56de\u80fd\u591f\u8ba9 \u6240\u6709\u5f00\u7740\u7684 \u706f\u90fd \u53d8\u6210\u84dd\u8272 \u7684\u65f6\u523b \u6570\u76ee \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1alight = [2,1,3,5,4]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6240\u6709\u5f00\u7740\u7684\u706f\u90fd\u53d8\u84dd\u7684\u65f6\u523b\u5206\u522b\u662f 1\uff0c2 \u548c 4 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1alight = [3,2,4,1,5]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6240\u6709\u5f00\u7740\u7684\u706f\u90fd\u53d8\u84dd\u7684\u65f6\u523b\u5206\u522b\u662f 3 \u548c 4\uff08index-0\uff09\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1alight = [4,1,2,3]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u6240\u6709\u5f00\u7740\u7684\u706f\u90fd\u53d8\u84dd\u7684\u65f6\u523b\u662f 3\uff08index-0\uff09\u3002\n\u7b2c 4 \u4e2a\u706f\u5728\u65f6\u523b 3 \u53d8\u84dd\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1alight = [2,1,4,3,6,5]\n\u8f93\u51fa\uff1a3\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1alight = [1,2,3,4,5,6]\n\u8f93\u51fa\uff1a6\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • n == light.length
  • \n\t
  • 1 <= n <= 5 * 10^4
  • \n\t
  • light \u662f [1, 2, ..., n] \u7684\u4e00\u4e2a\u6392\u5217\u3002
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numTimesAllBlue(vector& light) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numTimesAllBlue(int[] light) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numTimesAllBlue(self, light):\n \"\"\"\n :type light: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numTimesAllBlue(self, light: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numTimesAllBlue(int* light, int lightSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumTimesAllBlue(int[] light) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} light\n * @return {number}\n */\nvar numTimesAllBlue = function(light) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} light\n# @return {Integer}\ndef num_times_all_blue(light)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numTimesAllBlue(_ light: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numTimesAllBlue(light []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numTimesAllBlue(light: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numTimesAllBlue(light: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_times_all_blue(light: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $light\n * @return Integer\n */\n function numTimesAllBlue($light) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numTimesAllBlue(light: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-times-all-blue light)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1375](https://leetcode-cn.com/problems/bulb-switcher-iii)", "[\u706f\u6ce1\u5f00\u5173 III](/solution/1300-1399/1375.Bulb%20Switcher%20III/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1375](https://leetcode.com/problems/bulb-switcher-iii)", "[Bulb Switcher III](/solution/1300-1399/1375.Bulb%20Switcher%20III/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "1490", "frontend_question_id": "1374", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/generate-a-string-with-characters-that-have-odd-counts", "url_en": "https://leetcode.com/problems/generate-a-string-with-characters-that-have-odd-counts", "relative_path_cn": "/solution/1300-1399/1374.Generate%20a%20String%20With%20Characters%20That%20Have%20Odd%20Counts/README.md", "relative_path_en": "/solution/1300-1399/1374.Generate%20a%20String%20With%20Characters%20That%20Have%20Odd%20Counts/README_EN.md", "title_cn": "\u751f\u6210\u6bcf\u79cd\u5b57\u7b26\u90fd\u662f\u5947\u6570\u4e2a\u7684\u5b57\u7b26\u4e32", "title_en": "Generate a String With Characters That Have Odd Counts", "question_title_slug": "generate-a-string-with-characters-that-have-odd-counts", "content_en": "

Given an integer n, return a string with n characters such that each character in such string occurs an odd number of times.

\n\n

The returned string must contain only lowercase English letters. If there are multiples valid strings, return any of them.  

\n\n

 

\n

Example 1:

\n\n
\nInput: n = 4\nOutput: "pppz"\nExplanation: "pppz" is a valid string since the character 'p' occurs three times and the character 'z' occurs once. Note that there are many other valid strings such as "ohhh" and "love".\n
\n\n

Example 2:

\n\n
\nInput: n = 2\nOutput: "xy"\nExplanation: "xy" is a valid string since the characters 'x' and 'y' occur once. Note that there are many other valid strings such as "ag" and "ur".\n
\n\n

Example 3:

\n\n
\nInput: n = 7\nOutput: "holasss"\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 500
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n\uff0c\u8bf7\u4f60\u8fd4\u56de\u4e00\u4e2a\u542b n \u4e2a\u5b57\u7b26\u7684\u5b57\u7b26\u4e32\uff0c\u5176\u4e2d\u6bcf\u79cd\u5b57\u7b26\u5728\u8be5\u5b57\u7b26\u4e32\u4e2d\u90fd\u6070\u597d\u51fa\u73b0 \u5947\u6570\u6b21 \u3002

\n\n

\u8fd4\u56de\u7684\u5b57\u7b26\u4e32\u5fc5\u987b\u53ea\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002\u5982\u679c\u5b58\u5728\u591a\u4e2a\u6ee1\u8db3\u9898\u76ee\u8981\u6c42\u7684\u5b57\u7b26\u4e32\uff0c\u5219\u8fd4\u56de\u5176\u4e2d\u4efb\u610f\u4e00\u4e2a\u5373\u53ef\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1an = 4\n\u8f93\u51fa\uff1a"pppz"\n\u89e3\u91ca\uff1a"pppz" \u662f\u4e00\u4e2a\u6ee1\u8db3\u9898\u76ee\u8981\u6c42\u7684\u5b57\u7b26\u4e32\uff0c\u56e0\u4e3a 'p' \u51fa\u73b0 3 \u6b21\uff0c\u4e14 'z' \u51fa\u73b0 1 \u6b21\u3002\u5f53\u7136\uff0c\u8fd8\u6709\u5f88\u591a\u5176\u4ed6\u5b57\u7b26\u4e32\u4e5f\u6ee1\u8db3\u9898\u76ee\u8981\u6c42\uff0c\u6bd4\u5982\uff1a"ohhh" \u548c "love"\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1an = 2\n\u8f93\u51fa\uff1a"xy"\n\u89e3\u91ca\uff1a"xy" \u662f\u4e00\u4e2a\u6ee1\u8db3\u9898\u76ee\u8981\u6c42\u7684\u5b57\u7b26\u4e32\uff0c\u56e0\u4e3a 'x' \u548c 'y' \u5404\u51fa\u73b0 1 \u6b21\u3002\u5f53\u7136\uff0c\u8fd8\u6709\u5f88\u591a\u5176\u4ed6\u5b57\u7b26\u4e32\u4e5f\u6ee1\u8db3\u9898\u76ee\u8981\u6c42\uff0c\u6bd4\u5982\uff1a"ag" \u548c "ur"\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1an = 7\n\u8f93\u51fa\uff1a"holasss"\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 500
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string generateTheString(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String generateTheString(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def generateTheString(self, n):\n \"\"\"\n :type n: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def generateTheString(self, n: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * generateTheString(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string GenerateTheString(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {string}\n */\nvar generateTheString = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {String}\ndef generate_the_string(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func generateTheString(_ n: Int) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func generateTheString(n int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def generateTheString(n: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun generateTheString(n: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn generate_the_string(n: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return String\n */\n function generateTheString($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function generateTheString(n: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (generate-the-string n)\n (-> exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1374](https://leetcode-cn.com/problems/generate-a-string-with-characters-that-have-odd-counts)", "[\u751f\u6210\u6bcf\u79cd\u5b57\u7b26\u90fd\u662f\u5947\u6570\u4e2a\u7684\u5b57\u7b26\u4e32](/solution/1300-1399/1374.Generate%20a%20String%20With%20Characters%20That%20Have%20Odd%20Counts/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1374](https://leetcode.com/problems/generate-a-string-with-characters-that-have-odd-counts)", "[Generate a String With Characters That Have Odd Counts](/solution/1300-1399/1374.Generate%20a%20String%20With%20Characters%20That%20Have%20Odd%20Counts/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1489", "frontend_question_id": "1388", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/pizza-with-3n-slices", "url_en": "https://leetcode.com/problems/pizza-with-3n-slices", "relative_path_cn": "/solution/1300-1399/1388.Pizza%20With%203n%20Slices/README.md", "relative_path_en": "/solution/1300-1399/1388.Pizza%20With%203n%20Slices/README_EN.md", "title_cn": "3n \u5757\u62ab\u8428", "title_en": "Pizza With 3n Slices", "question_title_slug": "pizza-with-3n-slices", "content_en": "

There is a pizza with 3n slices of varying size, you and your friends will take slices of pizza as follows:

\n\n
    \n\t
  • You will pick any pizza slice.
  • \n\t
  • Your friend Alice will pick next slice in anti clockwise direction of your pick. 
  • \n\t
  • Your friend Bob will pick next slice in clockwise direction of your pick.
  • \n\t
  • Repeat until there are no more slices of pizzas.
  • \n
\n\n

Sizes of Pizza slices is represented by circular array slices in clockwise direction.

\n\n

Return the maximum possible sum of slice sizes which you can have.

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: slices = [1,2,3,4,5,6]\nOutput: 10\nExplanation: Pick pizza slice of size 4, Alice and Bob will pick slices with size 3 and 5 respectively. Then Pick slices with size 6, finally Alice and Bob will pick slice of size 2 and 1 respectively. Total = 4 + 6.\n
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: slices = [8,9,8,6,1,1]\nOutput: 16\nOutput: Pick pizza slice of size 8 in each turn. If you pick slice with size 9 your partners will pick slices of size 8.\n
\n\n

Example 3:

\n\n
\nInput: slices = [4,1,2,5,8,3,1,9,7]\nOutput: 21\n
\n\n

Example 4:

\n\n
\nInput: slices = [3,1,2]\nOutput: 3\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= slices.length <= 500
  • \n\t
  • slices.length % 3 == 0
  • \n\t
  • 1 <= slices[i] <= 1000
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u62ab\u8428\uff0c\u5b83\u7531 3n \u5757\u4e0d\u540c\u5927\u5c0f\u7684\u90e8\u5206\u7ec4\u6210\uff0c\u73b0\u5728\u4f60\u548c\u4f60\u7684\u670b\u53cb\u4eec\u9700\u8981\u6309\u7167\u5982\u4e0b\u89c4\u5219\u6765\u5206\u62ab\u8428\uff1a

\n\n
    \n\t
  • \u4f60\u6311\u9009 \u4efb\u610f \u4e00\u5757\u62ab\u8428\u3002
  • \n\t
  • Alice \u5c06\u4f1a\u6311\u9009\u4f60\u6240\u9009\u62e9\u7684\u62ab\u8428\u9006\u65f6\u9488\u65b9\u5411\u7684\u4e0b\u4e00\u5757\u62ab\u8428\u3002
  • \n\t
  • Bob \u5c06\u4f1a\u6311\u9009\u4f60\u6240\u9009\u62e9\u7684\u62ab\u8428\u987a\u65f6\u9488\u65b9\u5411\u7684\u4e0b\u4e00\u5757\u62ab\u8428\u3002
  • \n\t
  • \u91cd\u590d\u4e0a\u8ff0\u8fc7\u7a0b\u76f4\u5230\u6ca1\u6709\u62ab\u8428\u5269\u4e0b\u3002
  • \n
\n\n

\u6bcf\u4e00\u5757\u62ab\u8428\u7684\u5927\u5c0f\u6309\u987a\u65f6\u9488\u65b9\u5411\u7531\u5faa\u73af\u6570\u7ec4 slices \u8868\u793a\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u4f60\u53ef\u4ee5\u83b7\u5f97\u7684\u62ab\u8428\u5927\u5c0f\u603b\u548c\u7684\u6700\u5927\u503c\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1aslices = [1,2,3,4,5,6]\n\u8f93\u51fa\uff1a10\n\u89e3\u91ca\uff1a\u9009\u62e9\u5927\u5c0f\u4e3a 4 \u7684\u62ab\u8428\uff0cAlice \u548c Bob \u5206\u522b\u6311\u9009\u5927\u5c0f\u4e3a 3 \u548c 5 \u7684\u62ab\u8428\u3002\u7136\u540e\u4f60\u9009\u62e9\u5927\u5c0f\u4e3a 6 \u7684\u62ab\u8428\uff0cAlice \u548c Bob \u5206\u522b\u6311\u9009\u5927\u5c0f\u4e3a 2 \u548c 1 \u7684\u62ab\u8428\u3002\u4f60\u83b7\u5f97\u7684\u62ab\u8428\u603b\u5927\u5c0f\u4e3a 4 + 6 = 10 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1aslices = [8,9,8,6,1,1]\n\u8f93\u51fa\uff1a16\n\u89e3\u91ca\uff1a\u4e24\u8f6e\u90fd\u9009\u5927\u5c0f\u4e3a 8 \u7684\u62ab\u8428\u3002\u5982\u679c\u4f60\u9009\u62e9\u5927\u5c0f\u4e3a 9 \u7684\u62ab\u8428\uff0c\u4f60\u7684\u670b\u53cb\u4eec\u5c31\u4f1a\u9009\u62e9\u5927\u5c0f\u4e3a 8 \u7684\u62ab\u8428\uff0c\u8fd9\u79cd\u60c5\u51b5\u4e0b\u4f60\u7684\u603b\u548c\u4e0d\u662f\u6700\u5927\u7684\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aslices = [4,1,2,5,8,3,1,9,7]\n\u8f93\u51fa\uff1a21\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1aslices = [3,1,2]\n\u8f93\u51fa\uff1a3\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= slices.length <= 500
  • \n\t
  • slices.length % 3 == 0
  • \n\t
  • 1 <= slices[i] <= 1000
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxSizeSlices(vector& slices) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxSizeSlices(int[] slices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxSizeSlices(self, slices):\n \"\"\"\n :type slices: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxSizeSlices(self, slices: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxSizeSlices(int* slices, int slicesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxSizeSlices(int[] slices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} slices\n * @return {number}\n */\nvar maxSizeSlices = function(slices) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} slices\n# @return {Integer}\ndef max_size_slices(slices)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxSizeSlices(_ slices: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxSizeSlices(slices []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxSizeSlices(slices: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxSizeSlices(slices: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_size_slices(slices: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $slices\n * @return Integer\n */\n function maxSizeSlices($slices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxSizeSlices(slices: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-size-slices slices)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1388](https://leetcode-cn.com/problems/pizza-with-3n-slices)", "[3n \u5757\u62ab\u8428](/solution/1300-1399/1388.Pizza%20With%203n%20Slices/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1388](https://leetcode.com/problems/pizza-with-3n-slices)", "[Pizza With 3n Slices](/solution/1300-1399/1388.Pizza%20With%203n%20Slices/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1488", "frontend_question_id": "1387", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sort-integers-by-the-power-value", "url_en": "https://leetcode.com/problems/sort-integers-by-the-power-value", "relative_path_cn": "/solution/1300-1399/1387.Sort%20Integers%20by%20The%20Power%20Value/README.md", "relative_path_en": "/solution/1300-1399/1387.Sort%20Integers%20by%20The%20Power%20Value/README_EN.md", "title_cn": "\u5c06\u6574\u6570\u6309\u6743\u91cd\u6392\u5e8f", "title_en": "Sort Integers by The Power Value", "question_title_slug": "sort-integers-by-the-power-value", "content_en": "

The power of an integer x is defined as the number of steps needed to transform x into 1 using the following steps:

\r\n\r\n
    \r\n\t
  • if x is even then x = x / 2
  • \r\n\t
  • if x is odd then x = 3 * x + 1
  • \r\n
\r\n\r\n

For example, the power of x = 3 is 7 because 3 needs 7 steps to become 1 (3 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1).

\r\n\r\n

Given three integers lo, hi and k. The task is to sort all integers in the interval [lo, hi] by the power value in ascending order, if two or more integers have the same power value sort them by ascending order.

\r\n\r\n

Return the k-th integer in the range [lo, hi] sorted by the power value.

\r\n\r\n

Notice that for any integer x (lo <= x <= hi) it is guaranteed that x will transform into 1 using these steps and that the power of x is will fit in 32 bit signed integer.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: lo = 12, hi = 15, k = 2\r\nOutput: 13\r\nExplanation: The power of 12 is 9 (12 --> 6 --> 3 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1)\r\nThe power of 13 is 9\r\nThe power of 14 is 17\r\nThe power of 15 is 17\r\nThe interval sorted by the power value [12,13,14,15]. For k = 2 answer is the second element which is 13.\r\nNotice that 12 and 13 have the same power value and we sorted them in ascending order. Same for 14 and 15.\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: lo = 1, hi = 1, k = 1\r\nOutput: 1\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: lo = 7, hi = 11, k = 4\r\nOutput: 7\r\nExplanation: The power array corresponding to the interval [7, 8, 9, 10, 11] is [16, 3, 19, 6, 14].\r\nThe interval sorted by power is [8, 10, 11, 7, 9].\r\nThe fourth number in the sorted array is 7.\r\n
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: lo = 10, hi = 20, k = 5\r\nOutput: 13\r\n
\r\n\r\n

Example 5:

\r\n\r\n
\r\nInput: lo = 1, hi = 1000, k = 777\r\nOutput: 570\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= lo <= hi <= 1000
  • \r\n\t
  • 1 <= k <= hi - lo + 1
  • \r\n
", "content_cn": "

\u6211\u4eec\u5c06\u6574\u6570 x \u7684 \u6743\u91cd \u5b9a\u4e49\u4e3a\u6309\u7167\u4e0b\u8ff0\u89c4\u5219\u5c06 x \u53d8\u6210 1 \u6240\u9700\u8981\u7684\u6b65\u6570\uff1a

\n\n
    \n\t
  • \u5982\u679c x \u662f\u5076\u6570\uff0c\u90a3\u4e48 x = x / 2
  • \n\t
  • \u5982\u679c x \u662f\u5947\u6570\uff0c\u90a3\u4e48 x = 3 * x + 1
  • \n
\n\n

\u6bd4\u65b9\u8bf4\uff0cx=3 \u7684\u6743\u91cd\u4e3a 7 \u3002\u56e0\u4e3a 3 \u9700\u8981 7 \u6b65\u53d8\u6210 1 \uff083 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1\uff09\u3002

\n\n

\u7ed9\u4f60\u4e09\u4e2a\u6574\u6570 lo\uff0c hi \u548c k \u3002\u4f60\u7684\u4efb\u52a1\u662f\u5c06\u533a\u95f4 [lo, hi] \u4e4b\u95f4\u7684\u6574\u6570\u6309\u7167\u5b83\u4eec\u7684\u6743\u91cd \u5347\u5e8f\u6392\u5e8f \uff0c\u5982\u679c\u5927\u4e8e\u7b49\u4e8e 2 \u4e2a\u6574\u6570\u6709 \u76f8\u540c \u7684\u6743\u91cd\uff0c\u90a3\u4e48\u6309\u7167\u6570\u5b57\u81ea\u8eab\u7684\u6570\u503c \u5347\u5e8f\u6392\u5e8f \u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u533a\u95f4 [lo, hi] \u4e4b\u95f4\u7684\u6574\u6570\u6309\u6743\u91cd\u6392\u5e8f\u540e\u7684\u7b2c k \u4e2a\u6570\u3002

\n\n

\u6ce8\u610f\uff0c\u9898\u76ee\u4fdd\u8bc1\u5bf9\u4e8e\u4efb\u610f\u6574\u6570 x \uff08lo <= x <= hi\uff09 \uff0c\u5b83\u53d8\u6210 1 \u6240\u9700\u8981\u7684\u6b65\u6570\u662f\u4e00\u4e2a 32 \u4f4d\u6709\u7b26\u53f7\u6574\u6570\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1alo = 12, hi = 15, k = 2\n\u8f93\u51fa\uff1a13\n\u89e3\u91ca\uff1a12 \u7684\u6743\u91cd\u4e3a 9\uff0812 --> 6 --> 3 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1\uff09\n13 \u7684\u6743\u91cd\u4e3a 9\n14 \u7684\u6743\u91cd\u4e3a 17\n15 \u7684\u6743\u91cd\u4e3a 17\n\u533a\u95f4\u5185\u7684\u6570\u6309\u6743\u91cd\u6392\u5e8f\u4ee5\u540e\u7684\u7ed3\u679c\u4e3a [12,13,14,15] \u3002\u5bf9\u4e8e k = 2 \uff0c\u7b54\u6848\u662f\u7b2c\u4e8c\u4e2a\u6574\u6570\u4e5f\u5c31\u662f 13 \u3002\n\u6ce8\u610f\uff0c12 \u548c 13 \u6709\u76f8\u540c\u7684\u6743\u91cd\uff0c\u6240\u4ee5\u6211\u4eec\u6309\u7167\u5b83\u4eec\u672c\u8eab\u5347\u5e8f\u6392\u5e8f\u300214 \u548c 15 \u540c\u7406\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1alo = 1, hi = 1, k = 1\n\u8f93\u51fa\uff1a1\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1alo = 7, hi = 11, k = 4\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\u533a\u95f4\u5185\u6574\u6570 [7, 8, 9, 10, 11] \u5bf9\u5e94\u7684\u6743\u91cd\u4e3a [16, 3, 19, 6, 14] \u3002\n\u6309\u6743\u91cd\u6392\u5e8f\u540e\u5f97\u5230\u7684\u7ed3\u679c\u4e3a [8, 10, 11, 7, 9] \u3002\n\u6392\u5e8f\u540e\u6570\u7ec4\u4e2d\u7b2c 4 \u4e2a\u6570\u5b57\u4e3a 7 \u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1alo = 10, hi = 20, k = 5\n\u8f93\u51fa\uff1a13\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1alo = 1, hi = 1000, k = 777\n\u8f93\u51fa\uff1a570\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= lo <= hi <= 1000
  • \n\t
  • 1 <= k <= hi - lo + 1
  • \n
\n", "tags_en": ["Sort", "Graph"], "tags_cn": ["\u6392\u5e8f", "\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int getKth(int lo, int hi, int k) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int getKth(int lo, int hi, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getKth(self, lo, hi, k):\n \"\"\"\n :type lo: int\n :type hi: int\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getKth(self, lo: int, hi: int, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint getKth(int lo, int hi, int k){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int GetKth(int lo, int hi, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} lo\n * @param {number} hi\n * @param {number} k\n * @return {number}\n */\nvar getKth = function(lo, hi, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} lo\n# @param {Integer} hi\n# @param {Integer} k\n# @return {Integer}\ndef get_kth(lo, hi, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getKth(_ lo: Int, _ hi: Int, _ k: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getKth(lo int, hi int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getKth(lo: Int, hi: Int, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getKth(lo: Int, hi: Int, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_kth(lo: i32, hi: i32, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $lo\n * @param Integer $hi\n * @param Integer $k\n * @return Integer\n */\n function getKth($lo, $hi, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getKth(lo: number, hi: number, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-kth lo hi k)\n (-> exact-integer? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1387](https://leetcode-cn.com/problems/sort-integers-by-the-power-value)", "[\u5c06\u6574\u6570\u6309\u6743\u91cd\u6392\u5e8f](/solution/1300-1399/1387.Sort%20Integers%20by%20The%20Power%20Value/README.md)", "`\u6392\u5e8f`,`\u56fe`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1387](https://leetcode.com/problems/sort-integers-by-the-power-value)", "[Sort Integers by The Power Value](/solution/1300-1399/1387.Sort%20Integers%20by%20The%20Power%20Value/README_EN.md)", "`Sort`,`Graph`", "Medium", ""]}, {"question_id": "1487", "frontend_question_id": "1386", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/cinema-seat-allocation", "url_en": "https://leetcode.com/problems/cinema-seat-allocation", "relative_path_cn": "/solution/1300-1399/1386.Cinema%20Seat%20Allocation/README.md", "relative_path_en": "/solution/1300-1399/1386.Cinema%20Seat%20Allocation/README_EN.md", "title_cn": "\u5b89\u6392\u7535\u5f71\u9662\u5ea7\u4f4d", "title_en": "Cinema Seat Allocation", "question_title_slug": "cinema-seat-allocation", "content_en": "

\"\"

\n\n

A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.

\n\n

Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already reserved.

\n\n

Return the maximum number of four-person groups you can assign on the cinema seats. A four-person group occupies four adjacent seats in one single row. Seats across an aisle (such as [3,3] and [3,4]) are not considered to be adjacent, but there is an exceptional case on which an aisle split a four-person group, in that case, the aisle split a four-person group in the middle, which means to have two people on each side.

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: n = 3, reservedSeats = [[1,2],[1,3],[1,8],[2,6],[3,1],[3,10]]\nOutput: 4\nExplanation: The figure above shows the optimal allocation for four groups, where seats mark with blue are already reserved and contiguous seats mark with orange are for one group.\n
\n\n

Example 2:

\n\n
\nInput: n = 2, reservedSeats = [[2,1],[1,8],[2,6]]\nOutput: 2\n
\n\n

Example 3:

\n\n
\nInput: n = 4, reservedSeats = [[4,3],[1,4],[4,6],[1,7]]\nOutput: 4\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 10^9
  • \n\t
  • 1 <= reservedSeats.length <= min(10*n, 10^4)
  • \n\t
  • reservedSeats[i].length == 2
  • \n\t
  • 1 <= reservedSeats[i][0] <= n
  • \n\t
  • 1 <= reservedSeats[i][1] <= 10
  • \n\t
  • All reservedSeats[i] are distinct.
  • \n
\n", "content_cn": "

\"\"

\n\n

\u5982\u4e0a\u56fe\u6240\u793a\uff0c\u7535\u5f71\u9662\u7684\u89c2\u5f71\u5385\u4e2d\u6709 n \u884c\u5ea7\u4f4d\uff0c\u884c\u7f16\u53f7\u4ece 1 \u5230 n \uff0c\u4e14\u6bcf\u4e00\u884c\u5185\u603b\u5171\u6709 10 \u4e2a\u5ea7\u4f4d\uff0c\u5217\u7f16\u53f7\u4ece 1 \u5230 10 \u3002

\n\n

\u7ed9\u4f60\u6570\u7ec4 reservedSeats \uff0c\u5305\u542b\u6240\u6709\u5df2\u7ecf\u88ab\u9884\u7ea6\u4e86\u7684\u5ea7\u4f4d\u3002\u6bd4\u5982\u8bf4\uff0cresearvedSeats[i]=[3,8] \uff0c\u5b83\u8868\u793a\u7b2c 3 \u884c\u7b2c 8 \u4e2a\u5ea7\u4f4d\u88ab\u9884\u7ea6\u4e86\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de \u6700\u591a\u80fd\u5b89\u6392\u591a\u5c11\u4e2a 4 \u4eba\u5bb6\u5ead \u30024 \u4eba\u5bb6\u5ead\u8981\u5360\u636e \u540c\u4e00\u884c\u5185\u8fde\u7eed \u7684 4 \u4e2a\u5ea7\u4f4d\u3002\u9694\u7740\u8fc7\u9053\u7684\u5ea7\u4f4d\uff08\u6bd4\u65b9\u8bf4 [3,3] \u548c [3,4]\uff09\u4e0d\u662f\u8fde\u7eed\u7684\u5ea7\u4f4d\uff0c\u4f46\u662f\u5982\u679c\u4f60\u53ef\u4ee5\u5c06 4 \u4eba\u5bb6\u5ead\u62c6\u6210\u8fc7\u9053\u4e24\u8fb9\u5404\u5750 2 \u4eba\uff0c\u8fd9\u6837\u5b50\u662f\u5141\u8bb8\u7684\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1an = 3, reservedSeats = [[1,2],[1,3],[1,8],[2,6],[3,1],[3,10]]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u4e0a\u56fe\u6240\u793a\u662f\u6700\u4f18\u7684\u5b89\u6392\u65b9\u6848\uff0c\u603b\u5171\u53ef\u4ee5\u5b89\u6392 4 \u4e2a\u5bb6\u5ead\u3002\u84dd\u8272\u7684\u53c9\u8868\u793a\u88ab\u9884\u7ea6\u7684\u5ea7\u4f4d\uff0c\u6a59\u8272\u7684\u8fde\u7eed\u5ea7\u4f4d\u8868\u793a\u4e00\u4e2a 4 \u4eba\u5bb6\u5ead\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1an = 2, reservedSeats = [[2,1],[1,8],[2,6]]\n\u8f93\u51fa\uff1a2\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1an = 4, reservedSeats = [[4,3],[1,4],[4,6],[1,7]]\n\u8f93\u51fa\uff1a4\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 10^9
  • \n\t
  • 1 <= reservedSeats.length <= min(10*n, 10^4)
  • \n\t
  • reservedSeats[i].length == 2
  • \n\t
  • 1 <= reservedSeats[i][0] <= n
  • \n\t
  • 1 <= reservedSeats[i][1] <= 10
  • \n\t
  • \u6240\u6709 reservedSeats[i] \u90fd\u662f\u4e92\u4e0d\u76f8\u540c\u7684\u3002
  • \n
\n", "tags_en": ["Greedy", "Array"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxNumberOfFamilies(int n, vector>& reservedSeats) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxNumberOfFamilies(int n, int[][] reservedSeats) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxNumberOfFamilies(self, n, reservedSeats):\n \"\"\"\n :type n: int\n :type reservedSeats: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxNumberOfFamilies(int n, int** reservedSeats, int reservedSeatsSize, int* reservedSeatsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxNumberOfFamilies(int n, int[][] reservedSeats) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} reservedSeats\n * @return {number}\n */\nvar maxNumberOfFamilies = function(n, reservedSeats) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} reserved_seats\n# @return {Integer}\ndef max_number_of_families(n, reserved_seats)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxNumberOfFamilies(_ n: Int, _ reservedSeats: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxNumberOfFamilies(n int, reservedSeats [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxNumberOfFamilies(n: Int, reservedSeats: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxNumberOfFamilies(n: Int, reservedSeats: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_number_of_families(n: i32, reserved_seats: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $reservedSeats\n * @return Integer\n */\n function maxNumberOfFamilies($n, $reservedSeats) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxNumberOfFamilies(n: number, reservedSeats: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-number-of-families n reservedSeats)\n (-> exact-integer? (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1386](https://leetcode-cn.com/problems/cinema-seat-allocation)", "[\u5b89\u6392\u7535\u5f71\u9662\u5ea7\u4f4d](/solution/1300-1399/1386.Cinema%20Seat%20Allocation/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1386](https://leetcode.com/problems/cinema-seat-allocation)", "[Cinema Seat Allocation](/solution/1300-1399/1386.Cinema%20Seat%20Allocation/README_EN.md)", "`Greedy`,`Array`", "Medium", ""]}, {"question_id": "1486", "frontend_question_id": "1385", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-the-distance-value-between-two-arrays", "url_en": "https://leetcode.com/problems/find-the-distance-value-between-two-arrays", "relative_path_cn": "/solution/1300-1399/1385.Find%20the%20Distance%20Value%20Between%20Two%20Arrays/README.md", "relative_path_en": "/solution/1300-1399/1385.Find%20the%20Distance%20Value%20Between%20Two%20Arrays/README_EN.md", "title_cn": "\u4e24\u4e2a\u6570\u7ec4\u95f4\u7684\u8ddd\u79bb\u503c", "title_en": "Find the Distance Value Between Two Arrays", "question_title_slug": "find-the-distance-value-between-two-arrays", "content_en": "

Given two integer arrays arr1 and arr2, and the integer d, return the distance value between the two arrays.

\n\n

The distance value is defined as the number of elements arr1[i] such that there is not any element arr2[j] where |arr1[i]-arr2[j]| <= d.

\n\n

 

\n

Example 1:

\n\n
\nInput: arr1 = [4,5,8], arr2 = [10,9,1,8], d = 2\nOutput: 2\nExplanation: \nFor arr1[0]=4 we have: \n|4-10|=6 > d=2 \n|4-9|=5 > d=2 \n|4-1|=3 > d=2 \n|4-8|=4 > d=2 \nFor arr1[1]=5 we have: \n|5-10|=5 > d=2 \n|5-9|=4 > d=2 \n|5-1|=4 > d=2 \n|5-8|=3 > d=2\nFor arr1[2]=8 we have:\n|8-10|=2 <= d=2\n|8-9|=1 <= d=2\n|8-1|=7 > d=2\n|8-8|=0 <= d=2\n
\n\n

Example 2:

\n\n
\nInput: arr1 = [1,4,2,3], arr2 = [-4,-3,6,10,20,30], d = 3\nOutput: 2\n
\n\n

Example 3:

\n\n
\nInput: arr1 = [2,1,100,3], arr2 = [-5,-2,10,-3,7], d = 6\nOutput: 1\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= arr1.length, arr2.length <= 500
  • \n\t
  • -10^3 <= arr1[i], arr2[j] <= 10^3
  • \n\t
  • 0 <= d <= 100
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e24\u4e2a\u6574\u6570\u6570\u7ec4 arr1 \uff0c arr2 \u548c\u4e00\u4e2a\u6574\u6570 d \uff0c\u8bf7\u4f60\u8fd4\u56de\u4e24\u4e2a\u6570\u7ec4\u4e4b\u95f4\u7684 \u8ddd\u79bb\u503c \u3002

\n\n

\u300c\u8ddd\u79bb\u503c\u300d \u5b9a\u4e49\u4e3a\u7b26\u5408\u6b64\u8ddd\u79bb\u8981\u6c42\u7684\u5143\u7d20\u6570\u76ee\uff1a\u5bf9\u4e8e\u5143\u7d20 arr1[i] \uff0c\u4e0d\u5b58\u5728\u4efb\u4f55\u5143\u7d20 arr2[j] \u6ee1\u8db3 |arr1[i]-arr2[j]| <= d \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aarr1 = [4,5,8], arr2 = [10,9,1,8], d = 2\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n\u5bf9\u4e8e arr1[0]=4 \u6211\u4eec\u6709\uff1a\n|4-10|=6 > d=2 \n|4-9|=5 > d=2 \n|4-1|=3 > d=2 \n|4-8|=4 > d=2 \n\u6240\u4ee5 arr1[0]=4 \u7b26\u5408\u8ddd\u79bb\u8981\u6c42\n\n\u5bf9\u4e8e arr1[1]=5 \u6211\u4eec\u6709\uff1a\n|5-10|=5 > d=2 \n|5-9|=4 > d=2 \n|5-1|=4 > d=2 \n|5-8|=3 > d=2\n\u6240\u4ee5 arr1[1]=5 \u4e5f\u7b26\u5408\u8ddd\u79bb\u8981\u6c42\n\n\u5bf9\u4e8e arr1[2]=8 \u6211\u4eec\u6709\uff1a\n|8-10|=2 <= d=2\n|8-9|=1 <= d=2\n|8-1|=7 > d=2\n|8-8|=0 <= d=2\n\u5b58\u5728\u8ddd\u79bb\u5c0f\u4e8e\u7b49\u4e8e 2 \u7684\u60c5\u51b5\uff0c\u4e0d\u7b26\u5408\u8ddd\u79bb\u8981\u6c42 \n\n\u6545\u800c\u53ea\u6709 arr1[0]=4 \u548c arr1[1]=5 \u4e24\u4e2a\u7b26\u5408\u8ddd\u79bb\u8981\u6c42\uff0c\u8ddd\u79bb\u503c\u4e3a 2
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aarr1 = [1,4,2,3], arr2 = [-4,-3,6,10,20,30], d = 3\n\u8f93\u51fa\uff1a2\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aarr1 = [2,1,100,3], arr2 = [-5,-2,10,-3,7], d = 6\n\u8f93\u51fa\uff1a1\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= arr1.length, arr2.length <= 500
  • \n\t
  • -10^3 <= arr1[i], arr2[j] <= 10^3
  • \n\t
  • 0 <= d <= 100
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findTheDistanceValue(vector& arr1, vector& arr2, int d) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findTheDistanceValue(int[] arr1, int[] arr2, int d) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findTheDistanceValue(self, arr1, arr2, d):\n \"\"\"\n :type arr1: List[int]\n :type arr2: List[int]\n :type d: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findTheDistanceValue(self, arr1: List[int], arr2: List[int], d: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findTheDistanceValue(int* arr1, int arr1Size, int* arr2, int arr2Size, int d){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindTheDistanceValue(int[] arr1, int[] arr2, int d) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr1\n * @param {number[]} arr2\n * @param {number} d\n * @return {number}\n */\nvar findTheDistanceValue = function(arr1, arr2, d) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr1\n# @param {Integer[]} arr2\n# @param {Integer} d\n# @return {Integer}\ndef find_the_distance_value(arr1, arr2, d)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findTheDistanceValue(_ arr1: [Int], _ arr2: [Int], _ d: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findTheDistanceValue(arr1 []int, arr2 []int, d int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findTheDistanceValue(arr1: Array[Int], arr2: Array[Int], d: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findTheDistanceValue(arr1: IntArray, arr2: IntArray, d: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_the_distance_value(arr1: Vec, arr2: Vec, d: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr1\n * @param Integer[] $arr2\n * @param Integer $d\n * @return Integer\n */\n function findTheDistanceValue($arr1, $arr2, $d) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findTheDistanceValue(arr1: number[], arr2: number[], d: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-the-distance-value arr1 arr2 d)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1385](https://leetcode-cn.com/problems/find-the-distance-value-between-two-arrays)", "[\u4e24\u4e2a\u6570\u7ec4\u95f4\u7684\u8ddd\u79bb\u503c](/solution/1300-1399/1385.Find%20the%20Distance%20Value%20Between%20Two%20Arrays/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1385](https://leetcode.com/problems/find-the-distance-value-between-two-arrays)", "[Find the Distance Value Between Two Arrays](/solution/1300-1399/1385.Find%20the%20Distance%20Value%20Between%20Two%20Arrays/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1485", "frontend_question_id": "1368", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-cost-to-make-at-least-one-valid-path-in-a-grid", "url_en": "https://leetcode.com/problems/minimum-cost-to-make-at-least-one-valid-path-in-a-grid", "relative_path_cn": "/solution/1300-1399/1368.Minimum%20Cost%20to%20Make%20at%20Least%20One%20Valid%20Path%20in%20a%20Grid/README.md", "relative_path_en": "/solution/1300-1399/1368.Minimum%20Cost%20to%20Make%20at%20Least%20One%20Valid%20Path%20in%20a%20Grid/README_EN.md", "title_cn": "\u4f7f\u7f51\u683c\u56fe\u81f3\u5c11\u6709\u4e00\u6761\u6709\u6548\u8def\u5f84\u7684\u6700\u5c0f\u4ee3\u4ef7", "title_en": "Minimum Cost to Make at Least One Valid Path in a Grid", "question_title_slug": "minimum-cost-to-make-at-least-one-valid-path-in-a-grid", "content_en": "Given a m x n grid. Each cell of the grid has a sign pointing to the next cell you should visit if you are currently in this cell. The sign of grid[i][j] can be:\n
    \n\t
  • 1 which means go to the cell to the right. (i.e go from grid[i][j] to grid[i][j + 1])
  • \n\t
  • 2 which means go to the cell to the left. (i.e go from grid[i][j] to grid[i][j - 1])
  • \n\t
  • 3 which means go to the lower cell. (i.e go from grid[i][j] to grid[i + 1][j])
  • \n\t
  • 4 which means go to the upper cell. (i.e go from grid[i][j] to grid[i - 1][j])
  • \n
\n\n

Notice that there could be some invalid signs on the cells of the grid which points outside the grid.

\n\n

You will initially start at the upper left cell (0,0). A valid path in the grid is a path which starts from the upper left cell (0,0) and ends at the bottom-right cell (m - 1, n - 1) following the signs on the grid. The valid path doesn't have to be the shortest.

\n\n

You can modify the sign on a cell with cost = 1. You can modify the sign on a cell one time only.

\n\n

Return the minimum cost to make the grid have at least one valid path.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: grid = [[1,1,1,1],[2,2,2,2],[1,1,1,1],[2,2,2,2]]\nOutput: 3\nExplanation: You will start at point (0, 0).\nThe path to (3, 3) is as follows. (0, 0) --> (0, 1) --> (0, 2) --> (0, 3) change the arrow to down with cost = 1 --> (1, 3) --> (1, 2) --> (1, 1) --> (1, 0) change the arrow to down with cost = 1 --> (2, 0) --> (2, 1) --> (2, 2) --> (2, 3) change the arrow to down with cost = 1 --> (3, 3)\nThe total cost = 3.\n
\n\n

Example 2:

\n\"\"\n
\nInput: grid = [[1,1,3],[3,2,2],[1,1,4]]\nOutput: 0\nExplanation: You can follow the path from (0, 0) to (2, 2).\n
\n\n

Example 3:

\n\"\"\n
\nInput: grid = [[1,2],[4,3]]\nOutput: 1\n
\n\n

Example 4:

\n\n
\nInput: grid = [[2,2,2],[2,2,2]]\nOutput: 3\n
\n\n

Example 5:

\n\n
\nInput: grid = [[4]]\nOutput: 0\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • m == grid.length
  • \n\t
  • n == grid[i].length
  • \n\t
  • 1 <= m, n <= 100
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a m x n \u7684\u7f51\u683c\u56fe grid \u3002 grid \u4e2d\u6bcf\u4e2a\u683c\u5b50\u90fd\u6709\u4e00\u4e2a\u6570\u5b57\uff0c\u5bf9\u5e94\u7740\u4ece\u8be5\u683c\u5b50\u51fa\u53d1\u4e0b\u4e00\u6b65\u8d70\u7684\u65b9\u5411\u3002 grid[i][j] \u4e2d\u7684\u6570\u5b57\u53ef\u80fd\u4e3a\u4ee5\u4e0b\u51e0\u79cd\u60c5\u51b5\uff1a

\n\n
    \n\t
  • 1 \uff0c\u4e0b\u4e00\u6b65\u5f80\u53f3\u8d70\uff0c\u4e5f\u5c31\u662f\u4f60\u4f1a\u4ece grid[i][j] \u8d70\u5230 grid[i][j + 1]
  • \n\t
  • 2 \uff0c\u4e0b\u4e00\u6b65\u5f80\u5de6\u8d70\uff0c\u4e5f\u5c31\u662f\u4f60\u4f1a\u4ece grid[i][j] \u8d70\u5230 grid[i][j - 1]
  • \n\t
  • 3 \uff0c\u4e0b\u4e00\u6b65\u5f80\u4e0b\u8d70\uff0c\u4e5f\u5c31\u662f\u4f60\u4f1a\u4ece grid[i][j] \u8d70\u5230 grid[i + 1][j]
  • \n\t
  • 4 \uff0c\u4e0b\u4e00\u6b65\u5f80\u4e0a\u8d70\uff0c\u4e5f\u5c31\u662f\u4f60\u4f1a\u4ece grid[i][j] \u8d70\u5230 grid[i - 1][j]
  • \n
\n\n

\u6ce8\u610f\u7f51\u683c\u56fe\u4e2d\u53ef\u80fd\u4f1a\u6709 \u65e0\u6548\u6570\u5b57 \uff0c\u56e0\u4e3a\u5b83\u4eec\u53ef\u80fd\u6307\u5411 grid \u4ee5\u5916\u7684\u533a\u57df\u3002

\n\n

\u4e00\u5f00\u59cb\uff0c\u4f60\u4f1a\u4ece\u6700\u5de6\u4e0a\u89d2\u7684\u683c\u5b50 (0,0) \u51fa\u53d1\u3002\u6211\u4eec\u5b9a\u4e49\u4e00\u6761 \u6709\u6548\u8def\u5f84 \u4e3a\u4ece\u683c\u5b50 (0,0) \u51fa\u53d1\uff0c\u6bcf\u4e00\u6b65\u90fd\u987a\u7740\u6570\u5b57\u5bf9\u5e94\u65b9\u5411\u8d70\uff0c\u6700\u7ec8\u5728\u6700\u53f3\u4e0b\u89d2\u7684\u683c\u5b50 (m - 1, n - 1) \u7ed3\u675f\u7684\u8def\u5f84\u3002\u6709\u6548\u8def\u5f84 \u4e0d\u9700\u8981\u662f\u6700\u77ed\u8def\u5f84 \u3002

\n\n

\u4f60\u53ef\u4ee5\u82b1\u8d39 cost = 1 \u7684\u4ee3\u4ef7\u4fee\u6539\u4e00\u4e2a\u683c\u5b50\u4e2d\u7684\u6570\u5b57\uff0c\u4f46\u6bcf\u4e2a\u683c\u5b50\u4e2d\u7684\u6570\u5b57 \u53ea\u80fd\u4fee\u6539\u4e00\u6b21 \u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u8ba9\u7f51\u683c\u56fe\u81f3\u5c11\u6709\u4e00\u6761\u6709\u6548\u8def\u5f84\u7684\u6700\u5c0f\u4ee3\u4ef7\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1agrid = [[1,1,1,1],[2,2,2,2],[1,1,1,1],[2,2,2,2]]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u4f60\u5c06\u4ece\u70b9 (0, 0) \u51fa\u53d1\u3002\n\u5230\u8fbe (3, 3) \u7684\u8def\u5f84\u4e3a\uff1a (0, 0) --> (0, 1) --> (0, 2) --> (0, 3) \u82b1\u8d39\u4ee3\u4ef7 cost = 1 \u4f7f\u65b9\u5411\u5411\u4e0b --> (1, 3) --> (1, 2) --> (1, 1) --> (1, 0) \u82b1\u8d39\u4ee3\u4ef7 cost = 1 \u4f7f\u65b9\u5411\u5411\u4e0b --> (2, 0) --> (2, 1) --> (2, 2) --> (2, 3) \u82b1\u8d39\u4ee3\u4ef7 cost = 1 \u4f7f\u65b9\u5411\u5411\u4e0b --> (3, 3)\n\u603b\u82b1\u8d39\u4e3a cost = 3.\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1agrid = [[1,1,3],[3,2,2],[1,1,4]]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u4e0d\u4fee\u6539\u4efb\u4f55\u6570\u5b57\u4f60\u5c31\u53ef\u4ee5\u4ece (0, 0) \u5230\u8fbe (2, 2) \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1agrid = [[1,2],[4,3]]\n\u8f93\u51fa\uff1a1\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1agrid = [[2,2,2],[2,2,2]]\n\u8f93\u51fa\uff1a3\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1agrid = [[4]]\n\u8f93\u51fa\uff1a0\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • m == grid.length
  • \n\t
  • n == grid[i].length
  • \n\t
  • 1 <= m, n <= 100
  • \n
\n", "tags_en": ["Breadth-first Search"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minCost(vector>& grid) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minCost(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minCost(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minCost(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minCost(int** grid, int gridSize, int* gridColSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinCost(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar minCost = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef min_cost(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minCost(_ grid: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minCost(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minCost(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minCost(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_cost(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function minCost($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minCost(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-cost grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1368](https://leetcode-cn.com/problems/minimum-cost-to-make-at-least-one-valid-path-in-a-grid)", "[\u4f7f\u7f51\u683c\u56fe\u81f3\u5c11\u6709\u4e00\u6761\u6709\u6548\u8def\u5f84\u7684\u6700\u5c0f\u4ee3\u4ef7](/solution/1300-1399/1368.Minimum%20Cost%20to%20Make%20at%20Least%20One%20Valid%20Path%20in%20a%20Grid/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[1368](https://leetcode.com/problems/minimum-cost-to-make-at-least-one-valid-path-in-a-grid)", "[Minimum Cost to Make at Least One Valid Path in a Grid](/solution/1300-1399/1368.Minimum%20Cost%20to%20Make%20at%20Least%20One%20Valid%20Path%20in%20a%20Grid/README_EN.md)", "`Breadth-first Search`", "Hard", ""]}, {"question_id": "1484", "frontend_question_id": "1367", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/linked-list-in-binary-tree", "url_en": "https://leetcode.com/problems/linked-list-in-binary-tree", "relative_path_cn": "/solution/1300-1399/1367.Linked%20List%20in%20Binary%20Tree/README.md", "relative_path_en": "/solution/1300-1399/1367.Linked%20List%20in%20Binary%20Tree/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u4e2d\u7684\u5217\u8868", "title_en": "Linked List in Binary Tree", "question_title_slug": "linked-list-in-binary-tree", "content_en": "

Given a binary tree root and a linked list with head as the first node. 

\n\n

Return True if all the elements in the linked list starting from the head correspond to some downward path connected in the binary tree otherwise return False.

\n\n

In this context downward path means a path that starts at some node and goes downwards.

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: head = [4,2,8], root = [1,4,4,null,2,2,null,1,null,6,8,null,null,null,null,1,3]\nOutput: true\nExplanation: Nodes in blue form a subpath in the binary Tree.  \n
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: head = [1,4,2,6], root = [1,4,4,null,2,2,null,1,null,6,8,null,null,null,null,1,3]\nOutput: true\n
\n\n

Example 3:

\n\n
\nInput: head = [1,4,2,6,8], root = [1,4,4,null,2,2,null,1,null,6,8,null,null,null,null,1,3]\nOutput: false\nExplanation: There is no path in the binary tree that contains all the elements of the linked list from head.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The number of nodes in the tree will be in the range [1, 2500].
  • \n\t
  • The number of nodes in the list will be in the range [1, 100].
  • \n\t
  • 1 <= Node.val <= 100 for each node in the linked list and binary tree.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u68f5\u4ee5 root \u4e3a\u6839\u7684\u4e8c\u53c9\u6811\u548c\u4e00\u4e2a head \u4e3a\u7b2c\u4e00\u4e2a\u8282\u70b9\u7684\u94fe\u8868\u3002

\n\n

\u5982\u679c\u5728\u4e8c\u53c9\u6811\u4e2d\uff0c\u5b58\u5728\u4e00\u6761\u4e00\u76f4\u5411\u4e0b\u7684\u8def\u5f84\uff0c\u4e14\u6bcf\u4e2a\u70b9\u7684\u6570\u503c\u6070\u597d\u4e00\u4e00\u5bf9\u5e94\u4ee5 head \u4e3a\u9996\u7684\u94fe\u8868\u4e2d\u6bcf\u4e2a\u8282\u70b9\u7684\u503c\uff0c\u90a3\u4e48\u8bf7\u4f60\u8fd4\u56de True \uff0c\u5426\u5219\u8fd4\u56de False \u3002

\n\n

\u4e00\u76f4\u5411\u4e0b\u7684\u8def\u5f84\u7684\u610f\u601d\u662f\uff1a\u4ece\u6811\u4e2d\u67d0\u4e2a\u8282\u70b9\u5f00\u59cb\uff0c\u4e00\u76f4\u8fde\u7eed\u5411\u4e0b\u7684\u8def\u5f84\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1ahead = [4,2,8], root = [1,4,4,null,2,2,null,1,null,6,8,null,null,null,null,1,3]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u6811\u4e2d\u84dd\u8272\u7684\u8282\u70b9\u6784\u6210\u4e86\u4e0e\u94fe\u8868\u5bf9\u5e94\u7684\u5b50\u8def\u5f84\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1ahead = [1,4,2,6], root = [1,4,4,null,2,2,null,1,null,6,8,null,null,null,null,1,3]\n\u8f93\u51fa\uff1atrue\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1ahead = [1,4,2,6,8], root = [1,4,4,null,2,2,null,1,null,6,8,null,null,null,null,1,3]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u4e8c\u53c9\u6811\u4e2d\u4e0d\u5b58\u5728\u4e00\u4e00\u5bf9\u5e94\u94fe\u8868\u7684\u8def\u5f84\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u4e8c\u53c9\u6811\u548c\u94fe\u8868\u4e2d\u7684\u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u90fd\u6ee1\u8db3 1 <= node.val <= 100 \u3002
  • \n\t
  • \u94fe\u8868\u5305\u542b\u7684\u8282\u70b9\u6570\u76ee\u5728 1 \u5230 100 \u4e4b\u95f4\u3002
  • \n\t
  • \u4e8c\u53c9\u6811\u5305\u542b\u7684\u8282\u70b9\u6570\u76ee\u5728 1 \u5230 2500 \u4e4b\u95f4\u3002
  • \n
\n", "tags_en": ["Tree", "Linked List", "Dynamic Programming"], "tags_cn": ["\u6811", "\u94fe\u8868", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n bool isSubPath(ListNode* head, TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public boolean isSubPath(ListNode head, TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\n# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def isSubPath(self, head, root):\n \"\"\"\n :type head: ListNode\n :type root: TreeNode\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\n# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def isSubPath(self, head: ListNode, root: TreeNode) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nbool isSubPath(struct ListNode* head, struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public bool IsSubPath(ListNode head, TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {ListNode} head\n * @param {TreeNode} root\n * @return {boolean}\n */\nvar isSubPath = function(head, root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {ListNode} head\n# @param {TreeNode} root\n# @return {Boolean}\ndef is_sub_path(head, root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func isSubPath(_ head: ListNode?, _ root: TreeNode?) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\n/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc isSubPath(head *ListNode, root *TreeNode) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\n/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def isSubPath(head: ListNode, root: TreeNode): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\n/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun isSubPath(head: ListNode?, root: TreeNode?): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\n// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn is_sub_path(head: Option>, root: Option>>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\n/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @param TreeNode $root\n * @return Boolean\n */\n function isSubPath($head, $root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\n/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction isSubPath(head: ListNode | null, root: TreeNode | null): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (is-sub-path head root)\n (-> (or/c list-node? #f) (or/c tree-node? #f) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1367](https://leetcode-cn.com/problems/linked-list-in-binary-tree)", "[\u4e8c\u53c9\u6811\u4e2d\u7684\u5217\u8868](/solution/1300-1399/1367.Linked%20List%20in%20Binary%20Tree/README.md)", "`\u6811`,`\u94fe\u8868`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1367](https://leetcode.com/problems/linked-list-in-binary-tree)", "[Linked List in Binary Tree](/solution/1300-1399/1367.Linked%20List%20in%20Binary%20Tree/README_EN.md)", "`Tree`,`Linked List`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "1483", "frontend_question_id": "1366", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/rank-teams-by-votes", "url_en": "https://leetcode.com/problems/rank-teams-by-votes", "relative_path_cn": "/solution/1300-1399/1366.Rank%20Teams%20by%20Votes/README.md", "relative_path_en": "/solution/1300-1399/1366.Rank%20Teams%20by%20Votes/README_EN.md", "title_cn": "\u901a\u8fc7\u6295\u7968\u5bf9\u56e2\u961f\u6392\u540d", "title_en": "Rank Teams by Votes", "question_title_slug": "rank-teams-by-votes", "content_en": "

In a special ranking system, each voter gives a rank from highest to lowest to all teams participated in the competition.

\n\n

The ordering of teams is decided by who received the most position-one votes. If two or more teams tie in the first position, we consider the second position to resolve the conflict, if they tie again, we continue this process until the ties are resolved. If two or more teams are still tied after considering all positions, we rank them alphabetically based on their team letter.

\n\n

Given an array of strings votes which is the votes of all voters in the ranking systems. Sort all teams according to the ranking system described above.

\n\n

Return a string of all teams sorted by the ranking system.

\n\n

 

\n

Example 1:

\n\n
\nInput: votes = ["ABC","ACB","ABC","ACB","ACB"]\nOutput: "ACB"\nExplanation: Team A was ranked first place by 5 voters. No other team was voted as first place so team A is the first team.\nTeam B was ranked second by 2 voters and was ranked third by 3 voters.\nTeam C was ranked second by 3 voters and was ranked third by 2 voters.\nAs most of the voters ranked C second, team C is the second team and team B is the third.\n
\n\n

Example 2:

\n\n
\nInput: votes = ["WXYZ","XYZW"]\nOutput: "XWYZ"\nExplanation: X is the winner due to tie-breaking rule. X has same votes as W for the first position but X has one vote as second position while W doesn't have any votes as second position. \n
\n\n

Example 3:

\n\n
\nInput: votes = ["ZMNAGUEDSJYLBOPHRQICWFXTVK"]\nOutput: "ZMNAGUEDSJYLBOPHRQICWFXTVK"\nExplanation: Only one voter so his votes are used for the ranking.\n
\n\n

Example 4:

\n\n
\nInput: votes = ["BCA","CAB","CBA","ABC","ACB","BAC"]\nOutput: "ABC"\nExplanation: \nTeam A was ranked first by 2 voters, second by 2 voters and third by 2 voters.\nTeam B was ranked first by 2 voters, second by 2 voters and third by 2 voters.\nTeam C was ranked first by 2 voters, second by 2 voters and third by 2 voters.\nThere is a tie and we rank teams ascending by their IDs.\n
\n\n

Example 5:

\n\n
\nInput: votes = ["M","M","M","M"]\nOutput: "M"\nExplanation: Only team M in the competition so it has the first rank.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= votes.length <= 1000
  • \n\t
  • 1 <= votes[i].length <= 26
  • \n\t
  • votes[i].length == votes[j].length for 0 <= i, j < votes.length.
  • \n\t
  • votes[i][j] is an English upper-case letter.
  • \n\t
  • All characters of votes[i] are unique.
  • \n\t
  • All the characters that occur in votes[0] also occur in votes[j] where 1 <= j < votes.length.
  • \n
\n", "content_cn": "

\u73b0\u5728\u6709\u4e00\u4e2a\u7279\u6b8a\u7684\u6392\u540d\u7cfb\u7edf\uff0c\u4f9d\u636e\u53c2\u8d5b\u56e2\u961f\u5728\u6295\u7968\u4eba\u5fc3\u4e2d\u7684\u6b21\u5e8f\u8fdb\u884c\u6392\u540d\uff0c\u6bcf\u4e2a\u6295\u7968\u8005\u90fd\u9700\u8981\u6309\u4ece\u9ad8\u5230\u4f4e\u7684\u987a\u5e8f\u5bf9\u53c2\u4e0e\u6392\u540d\u7684\u6240\u6709\u56e2\u961f\u8fdb\u884c\u6392\u4f4d\u3002

\n\n

\u6392\u540d\u89c4\u5219\u5982\u4e0b\uff1a

\n\n
    \n\t
  • \u53c2\u8d5b\u56e2\u961f\u7684\u6392\u540d\u6b21\u5e8f\u4f9d\u7167\u5176\u6240\u83b7\u300c\u6392\u4f4d\u7b2c\u4e00\u300d\u7684\u7968\u7684\u591a\u5c11\u51b3\u5b9a\u3002\u5982\u679c\u5b58\u5728\u591a\u4e2a\u56e2\u961f\u5e76\u5217\u7684\u60c5\u51b5\uff0c\u5c06\u7ee7\u7eed\u8003\u8651\u5176\u300c\u6392\u4f4d\u7b2c\u4e8c\u300d\u7684\u7968\u7684\u6570\u91cf\u3002\u4ee5\u6b64\u7c7b\u63a8\uff0c\u76f4\u5230\u4e0d\u518d\u5b58\u5728\u5e76\u5217\u7684\u60c5\u51b5\u3002
  • \n\t
  • \u5982\u679c\u5728\u8003\u8651\u5b8c\u6240\u6709\u6295\u7968\u60c5\u51b5\u540e\u4ecd\u7136\u51fa\u73b0\u5e76\u5217\u73b0\u8c61\uff0c\u5219\u6839\u636e\u56e2\u961f\u5b57\u6bcd\u7684\u5b57\u6bcd\u987a\u5e8f\u8fdb\u884c\u6392\u540d\u3002
  • \n
\n\n

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4 votes \u4ee3\u8868\u5168\u4f53\u6295\u7968\u8005\u7ed9\u51fa\u7684\u6392\u4f4d\u60c5\u51b5\uff0c\u8bf7\u4f60\u6839\u636e\u4e0a\u8ff0\u6392\u540d\u89c4\u5219\u5bf9\u6240\u6709\u53c2\u8d5b\u56e2\u961f\u8fdb\u884c\u6392\u540d\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u80fd\u8868\u793a\u6309\u6392\u540d\u7cfb\u7edf \u6392\u5e8f\u540e \u7684\u6240\u6709\u56e2\u961f\u6392\u540d\u7684\u5b57\u7b26\u4e32\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1avotes = ["ABC","ACB","ABC","ACB","ACB"]\n\u8f93\u51fa\uff1a"ACB"\n\u89e3\u91ca\uff1aA \u961f\u83b7\u5f97\u4e94\u7968\u300c\u6392\u4f4d\u7b2c\u4e00\u300d\uff0c\u6ca1\u6709\u5176\u4ed6\u961f\u83b7\u5f97\u300c\u6392\u4f4d\u7b2c\u4e00\u300d\uff0c\u6240\u4ee5 A \u961f\u6392\u540d\u7b2c\u4e00\u3002\nB \u961f\u83b7\u5f97\u4e24\u7968\u300c\u6392\u4f4d\u7b2c\u4e8c\u300d\uff0c\u4e09\u7968\u300c\u6392\u4f4d\u7b2c\u4e09\u300d\u3002\nC \u961f\u83b7\u5f97\u4e09\u7968\u300c\u6392\u4f4d\u7b2c\u4e8c\u300d\uff0c\u4e24\u7968\u300c\u6392\u4f4d\u7b2c\u4e09\u300d\u3002\n\u7531\u4e8e C \u961f\u300c\u6392\u4f4d\u7b2c\u4e8c\u300d\u7684\u7968\u6570\u8f83\u591a\uff0c\u6240\u4ee5 C \u961f\u6392\u7b2c\u4e8c\uff0cB \u961f\u6392\u7b2c\u4e09\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1avotes = ["WXYZ","XYZW"]\n\u8f93\u51fa\uff1a"XWYZ"\n\u89e3\u91ca\uff1aX \u961f\u5728\u5e76\u5217\u50f5\u5c40\u6253\u7834\u540e\u6210\u4e3a\u6392\u540d\u7b2c\u4e00\u7684\u56e2\u961f\u3002X \u961f\u548c W \u961f\u7684\u300c\u6392\u4f4d\u7b2c\u4e00\u300d\u7968\u6570\u4e00\u6837\uff0c\u4f46\u662f X \u961f\u6709\u4e00\u7968\u300c\u6392\u4f4d\u7b2c\u4e8c\u300d\uff0c\u800c W \u6ca1\u6709\u83b7\u5f97\u300c\u6392\u4f4d\u7b2c\u4e8c\u300d\u3002 \n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1avotes = ["ZMNAGUEDSJYLBOPHRQICWFXTVK"]\n\u8f93\u51fa\uff1a"ZMNAGUEDSJYLBOPHRQICWFXTVK"\n\u89e3\u91ca\uff1a\u53ea\u6709\u4e00\u4e2a\u6295\u7968\u8005\uff0c\u6240\u4ee5\u6392\u540d\u5b8c\u5168\u6309\u7167\u4ed6\u7684\u610f\u613f\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1avotes = ["BCA","CAB","CBA","ABC","ACB","BAC"]\n\u8f93\u51fa\uff1a"ABC"\n\u89e3\u91ca\uff1a \nA \u961f\u83b7\u5f97\u4e24\u7968\u300c\u6392\u4f4d\u7b2c\u4e00\u300d\uff0c\u4e24\u7968\u300c\u6392\u4f4d\u7b2c\u4e8c\u300d\uff0c\u4e24\u7968\u300c\u6392\u4f4d\u7b2c\u4e09\u300d\u3002\nB \u961f\u83b7\u5f97\u4e24\u7968\u300c\u6392\u4f4d\u7b2c\u4e00\u300d\uff0c\u4e24\u7968\u300c\u6392\u4f4d\u7b2c\u4e8c\u300d\uff0c\u4e24\u7968\u300c\u6392\u4f4d\u7b2c\u4e09\u300d\u3002\nC \u961f\u83b7\u5f97\u4e24\u7968\u300c\u6392\u4f4d\u7b2c\u4e00\u300d\uff0c\u4e24\u7968\u300c\u6392\u4f4d\u7b2c\u4e8c\u300d\uff0c\u4e24\u7968\u300c\u6392\u4f4d\u7b2c\u4e09\u300d\u3002\n\u5b8c\u5168\u5e76\u5217\uff0c\u6240\u4ee5\u6211\u4eec\u9700\u8981\u6309\u7167\u5b57\u6bcd\u5347\u5e8f\u6392\u540d\u3002\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1avotes = ["M","M","M","M"]\n\u8f93\u51fa\uff1a"M"\n\u89e3\u91ca\uff1a\u53ea\u6709 M \u961f\u53c2\u8d5b\uff0c\u6240\u4ee5\u5b83\u6392\u540d\u7b2c\u4e00\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= votes.length <= 1000
  • \n\t
  • 1 <= votes[i].length <= 26
  • \n\t
  • votes[i].length == votes[j].length for 0 <= i, j < votes.length
  • \n\t
  • votes[i][j] \u662f\u82f1\u6587 \u5927\u5199 \u5b57\u6bcd
  • \n\t
  • votes[i] \u4e2d\u7684\u6240\u6709\u5b57\u6bcd\u90fd\u662f\u552f\u4e00\u7684
  • \n\t
  • votes[0] \u4e2d\u51fa\u73b0\u7684\u6240\u6709\u5b57\u6bcd \u540c\u6837\u4e5f \u51fa\u73b0\u5728 votes[j] \u4e2d\uff0c\u5176\u4e2d 1 <= j < votes.length
  • \n
\n", "tags_en": ["Sort", "Array"], "tags_cn": ["\u6392\u5e8f", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string rankTeams(vector& votes) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String rankTeams(String[] votes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def rankTeams(self, votes):\n \"\"\"\n :type votes: List[str]\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def rankTeams(self, votes: List[str]) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * rankTeams(char ** votes, int votesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string RankTeams(string[] votes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} votes\n * @return {string}\n */\nvar rankTeams = function(votes) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} votes\n# @return {String}\ndef rank_teams(votes)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func rankTeams(_ votes: [String]) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func rankTeams(votes []string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def rankTeams(votes: Array[String]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun rankTeams(votes: Array): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn rank_teams(votes: Vec) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $votes\n * @return String\n */\n function rankTeams($votes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function rankTeams(votes: string[]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (rank-teams votes)\n (-> (listof string?) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1366](https://leetcode-cn.com/problems/rank-teams-by-votes)", "[\u901a\u8fc7\u6295\u7968\u5bf9\u56e2\u961f\u6392\u540d](/solution/1300-1399/1366.Rank%20Teams%20by%20Votes/README.md)", "`\u6392\u5e8f`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1366](https://leetcode.com/problems/rank-teams-by-votes)", "[Rank Teams by Votes](/solution/1300-1399/1366.Rank%20Teams%20by%20Votes/README_EN.md)", "`Sort`,`Array`", "Medium", ""]}, {"question_id": "1482", "frontend_question_id": "1365", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/how-many-numbers-are-smaller-than-the-current-number", "url_en": "https://leetcode.com/problems/how-many-numbers-are-smaller-than-the-current-number", "relative_path_cn": "/solution/1300-1399/1365.How%20Many%20Numbers%20Are%20Smaller%20Than%20the%20Current%20Number/README.md", "relative_path_en": "/solution/1300-1399/1365.How%20Many%20Numbers%20Are%20Smaller%20Than%20the%20Current%20Number/README_EN.md", "title_cn": "\u6709\u591a\u5c11\u5c0f\u4e8e\u5f53\u524d\u6570\u5b57\u7684\u6570\u5b57", "title_en": "How Many Numbers Are Smaller Than the Current Number", "question_title_slug": "how-many-numbers-are-smaller-than-the-current-number", "content_en": "

Given the array nums, for each nums[i] find out how many numbers in the array are smaller than it. That is, for each nums[i] you have to count the number of valid j's such that j != i and nums[j] < nums[i].

\n\n

Return the answer in an array.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [8,1,2,2,3]\nOutput: [4,0,1,1,3]\nExplanation: \nFor nums[0]=8 there exist four smaller numbers than it (1, 2, 2 and 3). \nFor nums[1]=1 does not exist any smaller number than it.\nFor nums[2]=2 there exist one smaller number than it (1). \nFor nums[3]=2 there exist one smaller number than it (1). \nFor nums[4]=3 there exist three smaller numbers than it (1, 2 and 2).\n
\n\n

Example 2:

\n\n
\nInput: nums = [6,5,4,8]\nOutput: [2,1,0,3]\n
\n\n

Example 3:

\n\n
\nInput: nums = [7,7,7,7]\nOutput: [0,0,0,0]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= nums.length <= 500
  • \n\t
  • 0 <= nums[i] <= 100
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 nums\uff0c\u5bf9\u4e8e\u5176\u4e2d\u6bcf\u4e2a\u5143\u7d20 nums[i]\uff0c\u8bf7\u4f60\u7edf\u8ba1\u6570\u7ec4\u4e2d\u6bd4\u5b83\u5c0f\u7684\u6240\u6709\u6570\u5b57\u7684\u6570\u76ee\u3002

\n\n

\u6362\u800c\u8a00\u4e4b\uff0c\u5bf9\u4e8e\u6bcf\u4e2a nums[i] \u4f60\u5fc5\u987b\u8ba1\u7b97\u51fa\u6709\u6548\u7684 j \u7684\u6570\u91cf\uff0c\u5176\u4e2d j \u6ee1\u8db3 j != i \u4e14 nums[j] < nums[i] \u3002

\n\n

\u4ee5\u6570\u7ec4\u5f62\u5f0f\u8fd4\u56de\u7b54\u6848\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anums = [8,1,2,2,3]\n\u8f93\u51fa\uff1a[4,0,1,1,3]\n\u89e3\u91ca\uff1a \n\u5bf9\u4e8e nums[0]=8 \u5b58\u5728\u56db\u4e2a\u6bd4\u5b83\u5c0f\u7684\u6570\u5b57\uff1a\uff081\uff0c2\uff0c2 \u548c 3\uff09\u3002 \n\u5bf9\u4e8e nums[1]=1 \u4e0d\u5b58\u5728\u6bd4\u5b83\u5c0f\u7684\u6570\u5b57\u3002\n\u5bf9\u4e8e nums[2]=2 \u5b58\u5728\u4e00\u4e2a\u6bd4\u5b83\u5c0f\u7684\u6570\u5b57\uff1a\uff081\uff09\u3002 \n\u5bf9\u4e8e nums[3]=2 \u5b58\u5728\u4e00\u4e2a\u6bd4\u5b83\u5c0f\u7684\u6570\u5b57\uff1a\uff081\uff09\u3002 \n\u5bf9\u4e8e nums[4]=3 \u5b58\u5728\u4e09\u4e2a\u6bd4\u5b83\u5c0f\u7684\u6570\u5b57\uff1a\uff081\uff0c2 \u548c 2\uff09\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anums = [6,5,4,8]\n\u8f93\u51fa\uff1a[2,1,0,3]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1anums = [7,7,7,7]\n\u8f93\u51fa\uff1a[0,0,0,0]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= nums.length <= 500
  • \n\t
  • 0 <= nums[i] <= 100
  • \n
\n", "tags_en": ["Array", "Hash Table"], "tags_cn": ["\u6570\u7ec4", "\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector smallerNumbersThanCurrent(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] smallerNumbersThanCurrent(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def smallerNumbersThanCurrent(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def smallerNumbersThanCurrent(self, nums: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* smallerNumbersThanCurrent(int* nums, int numsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] SmallerNumbersThanCurrent(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar smallerNumbersThanCurrent = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer[]}\ndef smaller_numbers_than_current(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func smallerNumbersThanCurrent(_ nums: [Int]) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func smallerNumbersThanCurrent(nums []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def smallerNumbersThanCurrent(nums: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun smallerNumbersThanCurrent(nums: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn smaller_numbers_than_current(nums: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer[]\n */\n function smallerNumbersThanCurrent($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function smallerNumbersThanCurrent(nums: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (smaller-numbers-than-current nums)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1365](https://leetcode-cn.com/problems/how-many-numbers-are-smaller-than-the-current-number)", "[\u6709\u591a\u5c11\u5c0f\u4e8e\u5f53\u524d\u6570\u5b57\u7684\u6570\u5b57](/solution/1300-1399/1365.How%20Many%20Numbers%20Are%20Smaller%20Than%20the%20Current%20Number/README.md)", "`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[1365](https://leetcode.com/problems/how-many-numbers-are-smaller-than-the-current-number)", "[How Many Numbers Are Smaller Than the Current Number](/solution/1300-1399/1365.How%20Many%20Numbers%20Are%20Smaller%20Than%20the%20Current%20Number/README_EN.md)", "`Array`,`Hash Table`", "Easy", ""]}, {"question_id": "1481", "frontend_question_id": "1350", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/students-with-invalid-departments", "url_en": "https://leetcode.com/problems/students-with-invalid-departments", "relative_path_cn": "/solution/1300-1399/1350.Students%20With%20Invalid%20Departments/README.md", "relative_path_en": "/solution/1300-1399/1350.Students%20With%20Invalid%20Departments/README_EN.md", "title_cn": "\u9662\u7cfb\u65e0\u6548\u7684\u5b66\u751f", "title_en": "Students With Invalid Departments", "question_title_slug": "students-with-invalid-departments", "content_en": "

Table: Departments

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| name          | varchar |\n+---------------+---------+\nid is the primary key of this table.\nThe table has information about the id of each department of a university.\n
\n\n

 

\n\n

Table: Students

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| name          | varchar |\n| department_id | int     |\n+---------------+---------+\nid is the primary key of this table.\nThe table has information about the id of each student at a university and the id of the department he/she studies at.\n
\n\n

 

\n\n

Write an SQL query to find the id and the name of all students who are enrolled in departments that no longer exists.

\n\n

Return the result table in any order.

\n\n

The query result format is in the following example:

\n\n
\nDepartments table:\n+------+--------------------------+\n| id   | name                     |\n+------+--------------------------+\n| 1    | Electrical Engineering   |\n| 7    | Computer Engineering     |\n| 13   | Bussiness Administration |\n+------+--------------------------+\n\nStudents table:\n+------+----------+---------------+\n| id   | name     | department_id |\n+------+----------+---------------+\n| 23   | Alice    | 1             |\n| 1    | Bob      | 7             |\n| 5    | Jennifer | 13            |\n| 2    | John     | 14            |\n| 4    | Jasmine  | 77            |\n| 3    | Steve    | 74            |\n| 6    | Luis     | 1             |\n| 8    | Jonathan | 7             |\n| 7    | Daiana   | 33            |\n| 11   | Madelynn | 1             |\n+------+----------+---------------+\n\nResult table:\n+------+----------+\n| id   | name     |\n+------+----------+\n| 2    | John     |\n| 7    | Daiana   |\n| 4    | Jasmine  |\n| 3    | Steve    |\n+------+----------+\n\nJohn, Daiana, Steve and Jasmine are enrolled in departments 14, 33, 74 and 77 respectively. department 14, 33, 74 and 77 doesn't exist in the Departments table.\n
\n", "content_cn": "

\u9662\u7cfb\u8868: Departments

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| name          | varchar |\n+---------------+---------+\nid \u662f\u8be5\u8868\u7684\u4e3b\u952e\n\u8be5\u8868\u5305\u542b\u4e00\u6240\u5927\u5b66\u6bcf\u4e2a\u9662\u7cfb\u7684 id \u4fe1\u606f\n
\n\n

 

\n\n

\u5b66\u751f\u8868: Students

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| name          | varchar |\n| department_id | int     |\n+---------------+---------+\nid \u662f\u8be5\u8868\u7684\u4e3b\u952e\n\u8be5\u8868\u5305\u542b\u4e00\u6240\u5927\u5b66\u6bcf\u4e2a\u5b66\u751f\u7684 id \u548c\u4ed6/\u5979\u5c31\u8bfb\u7684\u9662\u7cfb\u4fe1\u606f\n
\n\n

 

\n\n

\u5199\u4e00\u6761 SQL \u8bed\u53e5\u4ee5\u67e5\u8be2\u90a3\u4e9b\u6240\u5728\u9662\u7cfb\u4e0d\u5b58\u5728\u7684\u5b66\u751f\u7684 id \u548c\u59d3\u540d

\n\n

\u53ef\u4ee5\u4ee5\u4efb\u4f55\u987a\u5e8f\u8fd4\u56de\u7ed3\u679c

\n\n

\u4e0b\u9762\u662f\u8fd4\u56de\u7ed3\u679c\u683c\u5f0f\u7684\u4f8b\u5b50

\n\n
\nDepartments \u8868:\n+------+--------------------------+\n| id   | name                     |\n+------+--------------------------+\n| 1    | Electrical Engineering   |\n| 7    | Computer Engineering     |\n| 13   | Bussiness Administration |\n+------+--------------------------+\n\nStudents \u8868:\n+------+----------+---------------+\n| id   | name     | department_id |\n+------+----------+---------------+\n| 23   | Alice    | 1             |\n| 1    | Bob      | 7             |\n| 5    | Jennifer | 13            |\n| 2    | John     | 14            |\n| 4    | Jasmine  | 77            |\n| 3    | Steve    | 74            |\n| 6    | Luis     | 1             |\n| 8    | Jonathan | 7             |\n| 7    | Daiana   | 33            |\n| 11   | Madelynn | 1             |\n+------+----------+---------------+\n\n\u7ed3\u679c\u8868:\n+------+----------+\n| id   | name     |\n+------+----------+\n| 2    | John     |\n| 7    | Daiana   |\n| 4    | Jasmine  |\n| 3    | Steve    |\n+------+----------+\n\nJohn, Daiana, Steve \u548c Jasmine \u6240\u5728\u7684\u9662\u7cfb\u5206\u522b\u662f 14, 33, 74 \u548c 77\uff0c \u5176\u4e2d 14, 33, 74 \u548c 77 \u5e76\u4e0d\u5b58\u5728\u4e8e\u9662\u7cfb\u8868\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1350](https://leetcode-cn.com/problems/students-with-invalid-departments)", "[\u9662\u7cfb\u65e0\u6548\u7684\u5b66\u751f](/solution/1300-1399/1350.Students%20With%20Invalid%20Departments/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1350](https://leetcode.com/problems/students-with-invalid-departments)", "[Students With Invalid Departments](/solution/1300-1399/1350.Students%20With%20Invalid%20Departments/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1480", "frontend_question_id": "1341", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/movie-rating", "url_en": "https://leetcode.com/problems/movie-rating", "relative_path_cn": "/solution/1300-1399/1341.Movie%20Rating/README.md", "relative_path_en": "/solution/1300-1399/1341.Movie%20Rating/README_EN.md", "title_cn": "\u7535\u5f71\u8bc4\u5206", "title_en": "Movie Rating", "question_title_slug": "movie-rating", "content_en": "

Table: Movies

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| movie_id      | int     |\n| title         | varchar |\n+---------------+---------+\nmovie_id is the primary key for this table.\ntitle is the name of the movie.\n
\n\n

Table: Users

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| user_id       | int     |\n| name          | varchar |\n+---------------+---------+\nuser_id is the primary key for this table.\n
\n\n

Table: Movie_Rating

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| movie_id      | int     |\n| user_id       | int     |\n| rating        | int     |\n| created_at    | date    |\n+---------------+---------+\n(movie_id, user_id) is the primary key for this table.\nThis table contains the rating of a movie by a user in their review.\ncreated_at is the user's review date. \n
\n\n

 

\n\n

Write the following SQL query:

\n\n
    \n\t
  • Find the name of the user who has rated the greatest number of movies.\n\t

    In case of a tie, return lexicographically smaller user name.

    \n\t
  • \n\t
  • Find the movie name with the highest average rating in February 2020.\n\t

    In case of a tie, return lexicographically smaller movie name.

    \n\t
  • \n
\n\n

The query is returned in 2 rows, the query result format is in the following example:

\n\n
\nMovies table:\n+-------------+--------------+\n| movie_id    |  title       |\n+-------------+--------------+\n| 1           | Avengers     |\n| 2           | Frozen 2     |\n| 3           | Joker        |\n+-------------+--------------+\n\nUsers table:\n+-------------+--------------+\n| user_id     |  name        |\n+-------------+--------------+\n| 1           | Daniel       |\n| 2           | Monica       |\n| 3           | Maria        |\n| 4           | James        |\n+-------------+--------------+\n\nMovie_Rating table:\n+-------------+--------------+--------------+-------------+\n| movie_id    | user_id      | rating       | created_at  |\n+-------------+--------------+--------------+-------------+\n| 1           | 1            | 3            | 2020-01-12  |\n| 1           | 2            | 4            | 2020-02-11  |\n| 1           | 3            | 2            | 2020-02-12  |\n| 1           | 4            | 1            | 2020-01-01  |\n| 2           | 1            | 5            | 2020-02-17  | \n| 2           | 2            | 2            | 2020-02-01  | \n| 2           | 3            | 2            | 2020-03-01  |\n| 3           | 1            | 3            | 2020-02-22  | \n| 3           | 2            | 4            | 2020-02-25  | \n+-------------+--------------+--------------+-------------+\n\nResult table:\n+--------------+\n| results      |\n+--------------+\n| Daniel       |\n| Frozen 2     |\n+--------------+\n\nDaniel and Monica have rated 3 movies ("Avengers", "Frozen 2" and "Joker") but Daniel is smaller lexicographically.\nFrozen 2 and Joker have a rating average of 3.5 in February but Frozen 2 is smaller lexicographically.\n
\n", "content_cn": "

\u8868\uff1aMovies

\n\n
+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| movie_id      | int     |\n| title         | varchar |\n+---------------+---------+\nmovie_id \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\u3002\ntitle \u662f\u7535\u5f71\u7684\u540d\u5b57\u3002\n
\n\n

\u8868\uff1aUsers

\n\n
+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| user_id       | int     |\n| name          | varchar |\n+---------------+---------+\nuser_id \u662f\u8868\u7684\u4e3b\u952e\u3002\n
\n\n

\u8868\uff1aMovie_Rating

\n\n
+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| movie_id      | int     |\n| user_id       | int     |\n| rating        | int     |\n| created_at    | date    |\n+---------------+---------+\n(movie_id, user_id) \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\u3002\n\u8fd9\u4e2a\u8868\u5305\u542b\u7528\u6237\u5728\u5176\u8bc4\u8bba\u4e2d\u5bf9\u7535\u5f71\u7684\u8bc4\u5206 rating \u3002\ncreated_at \u662f\u7528\u6237\u7684\u70b9\u8bc4\u65e5\u671f\u3002 \n
\n\n

 

\n\n

\u8bf7\u4f60\u7f16\u5199\u4e00\u7ec4 SQL \u67e5\u8be2\uff1a

\n\n
    \n\t
  • \u67e5\u627e\u8bc4\u8bba\u7535\u5f71\u6570\u91cf\u6700\u591a\u7684\u7528\u6237\u540d\u3002\n\t

    \u5982\u679c\u51fa\u73b0\u5e73\u5c40\uff0c\u8fd4\u56de\u5b57\u5178\u5e8f\u8f83\u5c0f\u7684\u7528\u6237\u540d\u3002

    \n\t
  • \n\t
  • \u67e5\u627e\u5728 2020 \u5e74 2 \u6708 \u5e73\u5747\u8bc4\u5206\u6700\u9ad8 \u7684\u7535\u5f71\u540d\u79f0\u3002\n\t

    \u5982\u679c\u51fa\u73b0\u5e73\u5c40\uff0c\u8fd4\u56de\u5b57\u5178\u5e8f\u8f83\u5c0f\u7684\u7535\u5f71\u540d\u79f0\u3002

    \n\t
  • \n
\n\n

\u67e5\u8be2\u5206\u4e24\u884c\u8fd4\u56de\uff0c\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a\uff1a

\n\n
Movies \u8868\uff1a\n+-------------+--------------+\n| movie_id    |  title       |\n+-------------+--------------+\n| 1           | Avengers     |\n| 2           | Frozen 2     |\n| 3           | Joker        |\n+-------------+--------------+\n\nUsers \u8868\uff1a\n+-------------+--------------+\n| user_id     |  name        |\n+-------------+--------------+\n| 1           | Daniel       |\n| 2           | Monica       |\n| 3           | Maria        |\n| 4           | James        |\n+-------------+--------------+\n\nMovie_Rating \u8868\uff1a\n+-------------+--------------+--------------+-------------+\n| movie_id    | user_id      | rating       | created_at  |\n+-------------+--------------+--------------+-------------+\n| 1           | 1            | 3            | 2020-01-12  |\n| 1           | 2            | 4            | 2020-02-11  |\n| 1           | 3            | 2            | 2020-02-12  |\n| 1           | 4            | 1            | 2020-01-01  |\n| 2           | 1            | 5            | 2020-02-17  | \n| 2           | 2            | 2            | 2020-02-01  | \n| 2           | 3            | 2            | 2020-03-01  |\n| 3           | 1            | 3            | 2020-02-22  | \n| 3           | 2            | 4            | 2020-02-25  | \n+-------------+--------------+--------------+-------------+\n\nResult \u8868\uff1a\n+--------------+\n| results      |\n+--------------+\n| Daniel       |\n| Frozen 2     |\n+--------------+\n\nDaniel \u548c Monica \u90fd\u70b9\u8bc4\u4e86 3 \u90e8\u7535\u5f71\uff08"Avengers", "Frozen 2" \u548c "Joker"\uff09 \u4f46\u662f Daniel \u5b57\u5178\u5e8f\u6bd4\u8f83\u5c0f\u3002\nFrozen 2 \u548c Joker \u5728 2 \u6708\u7684\u8bc4\u5206\u90fd\u662f 3.5\uff0c\u4f46\u662f Frozen 2 \u7684\u5b57\u5178\u5e8f\u6bd4\u8f83\u5c0f\u3002\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1341](https://leetcode-cn.com/problems/movie-rating)", "[\u7535\u5f71\u8bc4\u5206](/solution/1300-1399/1341.Movie%20Rating/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1341](https://leetcode.com/problems/movie-rating)", "[Movie Rating](/solution/1300-1399/1341.Movie%20Rating/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1479", "frontend_question_id": "1354", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/construct-target-array-with-multiple-sums", "url_en": "https://leetcode.com/problems/construct-target-array-with-multiple-sums", "relative_path_cn": "/solution/1300-1399/1354.Construct%20Target%20Array%20With%20Multiple%20Sums/README.md", "relative_path_en": "/solution/1300-1399/1354.Construct%20Target%20Array%20With%20Multiple%20Sums/README_EN.md", "title_cn": "\u591a\u6b21\u6c42\u548c\u6784\u9020\u76ee\u6807\u6570\u7ec4", "title_en": "Construct Target Array With Multiple Sums", "question_title_slug": "construct-target-array-with-multiple-sums", "content_en": "

You are given an array target of n integers. From a starting array arr consisting of n 1's, you may perform the following procedure :

\n\n
    \n\t
  • let x be the sum of all elements currently in your array.
  • \n\t
  • choose index i, such that 0 <= i < n and set the value of arr at index i to x.
  • \n\t
  • You may repeat this procedure as many times as needed.
  • \n
\n\n

Return true if it is possible to construct the target array from arr, otherwise, return false.

\n\n

 

\n

Example 1:

\n\n
\nInput: target = [9,3,5]\nOutput: true\nExplanation: Start with arr = [1, 1, 1] \n[1, 1, 1], sum = 3 choose index 1\n[1, 3, 1], sum = 5 choose index 2\n[1, 3, 5], sum = 9 choose index 0\n[9, 3, 5] Done\n
\n\n

Example 2:

\n\n
\nInput: target = [1,1,1,2]\nOutput: false\nExplanation: Impossible to create target array from [1,1,1,1].\n
\n\n

Example 3:

\n\n
\nInput: target = [8,5]\nOutput: true\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == target.length
  • \n\t
  • 1 <= n <= 5 * 104
  • \n\t
  • 1 <= target[i] <= 109
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 target \u3002\u4e00\u5f00\u59cb\uff0c\u4f60\u6709\u4e00\u4e2a\u6570\u7ec4 A \uff0c\u5b83\u7684\u6240\u6709\u5143\u7d20\u5747\u4e3a 1 \uff0c\u4f60\u53ef\u4ee5\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\uff1a

\n\n
    \n\t
  • \u4ee4 x \u4e3a\u4f60\u6570\u7ec4\u91cc\u6240\u6709\u5143\u7d20\u7684\u548c
  • \n\t
  • \u9009\u62e9\u6ee1\u8db3 0 <= i < target.size \u7684\u4efb\u610f\u4e0b\u6807 i \uff0c\u5e76\u8ba9 A \u6570\u7ec4\u91cc\u4e0b\u6807\u4e3a i \u5904\u7684\u503c\u4e3a x \u3002
  • \n\t
  • \u4f60\u53ef\u4ee5\u91cd\u590d\u8be5\u8fc7\u7a0b\u4efb\u610f\u6b21
  • \n
\n\n

\u5982\u679c\u80fd\u4ece A \u5f00\u59cb\u6784\u9020\u51fa\u76ee\u6807\u6570\u7ec4 target \uff0c\u8bf7\u4f60\u8fd4\u56de True \uff0c\u5426\u5219\u8fd4\u56de False \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1atarget = [9,3,5]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u4ece [1, 1, 1] \u5f00\u59cb\n[1, 1, 1], \u548c\u4e3a 3 \uff0c\u9009\u62e9\u4e0b\u6807 1\n[1, 3, 1], \u548c\u4e3a 5\uff0c \u9009\u62e9\u4e0b\u6807 2\n[1, 3, 5], \u548c\u4e3a 9\uff0c \u9009\u62e9\u4e0b\u6807 0\n[9, 3, 5] \u5b8c\u6210\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1atarget = [1,1,1,2]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u4e0d\u53ef\u80fd\u4ece [1,1,1,1] \u51fa\u53d1\u6784\u9020\u76ee\u6807\u6570\u7ec4\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1atarget = [8,5]\n\u8f93\u51fa\uff1atrue\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • N == target.length
  • \n\t
  • 1 <= target.length <= 5 * 10^4
  • \n\t
  • 1 <= target[i] <= 10^9
  • \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isPossible(vector& target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isPossible(int[] target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isPossible(self, target):\n \"\"\"\n :type target: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isPossible(self, target: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isPossible(int* target, int targetSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsPossible(int[] target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} target\n * @return {boolean}\n */\nvar isPossible = function(target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} target\n# @return {Boolean}\ndef is_possible(target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isPossible(_ target: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isPossible(target []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isPossible(target: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isPossible(target: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_possible(target: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $target\n * @return Boolean\n */\n function isPossible($target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isPossible(target: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-possible target)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1354](https://leetcode-cn.com/problems/construct-target-array-with-multiple-sums)", "[\u591a\u6b21\u6c42\u548c\u6784\u9020\u76ee\u6807\u6570\u7ec4](/solution/1300-1399/1354.Construct%20Target%20Array%20With%20Multiple%20Sums/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[1354](https://leetcode.com/problems/construct-target-array-with-multiple-sums)", "[Construct Target Array With Multiple Sums](/solution/1300-1399/1354.Construct%20Target%20Array%20With%20Multiple%20Sums/README_EN.md)", "`Greedy`", "Hard", ""]}, {"question_id": "1478", "frontend_question_id": "1353", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-number-of-events-that-can-be-attended", "url_en": "https://leetcode.com/problems/maximum-number-of-events-that-can-be-attended", "relative_path_cn": "/solution/1300-1399/1353.Maximum%20Number%20of%20Events%20That%20Can%20Be%20Attended/README.md", "relative_path_en": "/solution/1300-1399/1353.Maximum%20Number%20of%20Events%20That%20Can%20Be%20Attended/README_EN.md", "title_cn": "\u6700\u591a\u53ef\u4ee5\u53c2\u52a0\u7684\u4f1a\u8bae\u6570\u76ee", "title_en": "Maximum Number of Events That Can Be Attended", "question_title_slug": "maximum-number-of-events-that-can-be-attended", "content_en": "

Given an array of events where events[i] = [startDayi, endDayi]. Every event i starts at startDayi and ends at endDayi.

\n\n

You can attend an event i at any day d where startTimei <= d <= endTimei. Notice that you can only attend one event at any time d.

\n\n

Return the maximum number of events you can attend.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: events = [[1,2],[2,3],[3,4]]\nOutput: 3\nExplanation: You can attend all the three events.\nOne way to attend them all is as shown.\nAttend the first event on day 1.\nAttend the second event on day 2.\nAttend the third event on day 3.\n
\n\n

Example 2:

\n\n
\nInput: events= [[1,2],[2,3],[3,4],[1,2]]\nOutput: 4\n
\n\n

Example 3:

\n\n
\nInput: events = [[1,4],[4,4],[2,2],[3,4],[1,1]]\nOutput: 4\n
\n\n

Example 4:

\n\n
\nInput: events = [[1,100000]]\nOutput: 1\n
\n\n

Example 5:

\n\n
\nInput: events = [[1,1],[1,2],[1,3],[1,4],[1,5],[1,6],[1,7]]\nOutput: 7\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= events.length <= 105
  • \n\t
  • events[i].length == 2
  • \n\t
  • 1 <= startDayi <= endDayi <= 105
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 events\uff0c\u5176\u4e2d events[i] = [startDayi, endDayi] \uff0c\u8868\u793a\u4f1a\u8bae i \u5f00\u59cb\u4e8e startDayi \uff0c\u7ed3\u675f\u4e8e endDayi \u3002

\n\n

\u4f60\u53ef\u4ee5\u5728\u6ee1\u8db3 startDayi <= d <= endDayi \u4e2d\u7684\u4efb\u610f\u4e00\u5929 d \u53c2\u52a0\u4f1a\u8bae i \u3002\u6ce8\u610f\uff0c\u4e00\u5929\u53ea\u80fd\u53c2\u52a0\u4e00\u4e2a\u4f1a\u8bae\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u4f60\u53ef\u4ee5\u53c2\u52a0\u7684 \u6700\u5927 \u4f1a\u8bae\u6570\u76ee\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1aevents = [[1,2],[2,3],[3,4]]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u53c2\u52a0\u6240\u6709\u7684\u4e09\u4e2a\u4f1a\u8bae\u3002\n\u5b89\u6392\u4f1a\u8bae\u7684\u4e00\u79cd\u65b9\u6848\u5982\u4e0a\u56fe\u3002\n\u7b2c 1 \u5929\u53c2\u52a0\u7b2c\u4e00\u4e2a\u4f1a\u8bae\u3002\n\u7b2c 2 \u5929\u53c2\u52a0\u7b2c\u4e8c\u4e2a\u4f1a\u8bae\u3002\n\u7b2c 3 \u5929\u53c2\u52a0\u7b2c\u4e09\u4e2a\u4f1a\u8bae\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aevents= [[1,2],[2,3],[3,4],[1,2]]\n\u8f93\u51fa\uff1a4\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aevents = [[1,4],[4,4],[2,2],[3,4],[1,1]]\n\u8f93\u51fa\uff1a4\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1aevents = [[1,100000]]\n\u8f93\u51fa\uff1a1\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1aevents = [[1,1],[1,2],[1,3],[1,4],[1,5],[1,6],[1,7]]\n\u8f93\u51fa\uff1a7\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= events.length <= 10^5
  • \n\t
  • events[i].length == 2
  • \n\t
  • 1 <= events[i][0] <= events[i][1] <= 10^5
  • \n
\n", "tags_en": ["Greedy", "Sort", "Segment Tree"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6392\u5e8f", "\u7ebf\u6bb5\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxEvents(vector>& events) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxEvents(int[][] events) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxEvents(self, events):\n \"\"\"\n :type events: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxEvents(self, events: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxEvents(int** events, int eventsSize, int* eventsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxEvents(int[][] events) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} events\n * @return {number}\n */\nvar maxEvents = function(events) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} events\n# @return {Integer}\ndef max_events(events)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxEvents(_ events: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxEvents(events [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxEvents(events: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxEvents(events: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_events(events: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $events\n * @return Integer\n */\n function maxEvents($events) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxEvents(events: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-events events)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1353](https://leetcode-cn.com/problems/maximum-number-of-events-that-can-be-attended)", "[\u6700\u591a\u53ef\u4ee5\u53c2\u52a0\u7684\u4f1a\u8bae\u6570\u76ee](/solution/1300-1399/1353.Maximum%20Number%20of%20Events%20That%20Can%20Be%20Attended/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6392\u5e8f`,`\u7ebf\u6bb5\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1353](https://leetcode.com/problems/maximum-number-of-events-that-can-be-attended)", "[Maximum Number of Events That Can Be Attended](/solution/1300-1399/1353.Maximum%20Number%20of%20Events%20That%20Can%20Be%20Attended/README_EN.md)", "`Greedy`,`Sort`,`Segment Tree`", "Medium", ""]}, {"question_id": "1477", "frontend_question_id": "1352", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/product-of-the-last-k-numbers", "url_en": "https://leetcode.com/problems/product-of-the-last-k-numbers", "relative_path_cn": "/solution/1300-1399/1352.Product%20of%20the%20Last%20K%20Numbers/README.md", "relative_path_en": "/solution/1300-1399/1352.Product%20of%20the%20Last%20K%20Numbers/README_EN.md", "title_cn": "\u6700\u540e K \u4e2a\u6570\u7684\u4e58\u79ef", "title_en": "Product of the Last K Numbers", "question_title_slug": "product-of-the-last-k-numbers", "content_en": "

Implement the class ProductOfNumbers that supports two methods:

\n\n

1. add(int num)

\n\n
    \n\t
  • Adds the number num to the back of the current list of numbers.
  • \n
\n\n

2. getProduct(int k)

\n\n
    \n\t
  • Returns the product of the last k numbers in the current list.
  • \n\t
  • You can assume that always the current list has at least k numbers.
  • \n
\n\n

At any time, the product of any contiguous sequence of numbers will fit into a single 32-bit integer without overflowing.

\n\n

 

\n

Example:

\n\n
\nInput\n["ProductOfNumbers","add","add","add","add","add","getProduct","getProduct","getProduct","add","getProduct"]\n[[],[3],[0],[2],[5],[4],[2],[3],[4],[8],[2]]\n\nOutput\n[null,null,null,null,null,null,20,40,0,null,32]\n\nExplanation\nProductOfNumbers productOfNumbers = new ProductOfNumbers();\nproductOfNumbers.add(3);        // [3]\nproductOfNumbers.add(0);        // [3,0]\nproductOfNumbers.add(2);        // [3,0,2]\nproductOfNumbers.add(5);        // [3,0,2,5]\nproductOfNumbers.add(4);        // [3,0,2,5,4]\nproductOfNumbers.getProduct(2); // return 20. The product of the last 2 numbers is 5 * 4 = 20\nproductOfNumbers.getProduct(3); // return 40. The product of the last 3 numbers is 2 * 5 * 4 = 40\nproductOfNumbers.getProduct(4); // return 0. The product of the last 4 numbers is 0 * 2 * 5 * 4 = 0\nproductOfNumbers.add(8);        // [3,0,2,5,4,8]\nproductOfNumbers.getProduct(2); // return 32. The product of the last 2 numbers is 4 * 8 = 32 \n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • There will be at most 40000 operations considering both add and getProduct.
  • \n\t
  • 0 <= num <= 100
  • \n\t
  • 1 <= k <= 40000
  • \n
\n", "content_cn": "

\u8bf7\u4f60\u5b9e\u73b0\u4e00\u4e2a\u300c\u6570\u5b57\u4e58\u79ef\u7c7b\u300dProductOfNumbers\uff0c\u8981\u6c42\u652f\u6301\u4e0b\u8ff0\u4e24\u79cd\u65b9\u6cd5\uff1a

\n\n

1. add(int num)

\n\n
    \n\t
  • \u5c06\u6570\u5b57 num \u6dfb\u52a0\u5230\u5f53\u524d\u6570\u5b57\u5217\u8868\u7684\u6700\u540e\u9762\u3002
  • \n
\n\n

2. getProduct(int k)

\n\n
    \n\t
  • \u8fd4\u56de\u5f53\u524d\u6570\u5b57\u5217\u8868\u4e2d\uff0c\u6700\u540e k \u4e2a\u6570\u5b57\u7684\u4e58\u79ef\u3002
  • \n\t
  • \u4f60\u53ef\u4ee5\u5047\u8bbe\u5f53\u524d\u5217\u8868\u4e2d\u59cb\u7ec8 \u81f3\u5c11 \u5305\u542b k \u4e2a\u6570\u5b57\u3002
  • \n
\n\n

\u9898\u76ee\u6570\u636e\u4fdd\u8bc1\uff1a\u4efb\u4f55\u65f6\u5019\uff0c\u4efb\u4e00\u8fde\u7eed\u6570\u5b57\u5e8f\u5217\u7684\u4e58\u79ef\u90fd\u5728 32-bit \u6574\u6570\u8303\u56f4\u5185\uff0c\u4e0d\u4f1a\u6ea2\u51fa\u3002

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1a\n["ProductOfNumbers","add","add","add","add","add","getProduct","getProduct","getProduct","add","getProduct"]\n[[],[3],[0],[2],[5],[4],[2],[3],[4],[8],[2]]\n\n\u8f93\u51fa\uff1a\n[null,null,null,null,null,null,20,40,0,null,32]\n\n\u89e3\u91ca\uff1a\nProductOfNumbers productOfNumbers = new ProductOfNumbers();\nproductOfNumbers.add(3);        // [3]\nproductOfNumbers.add(0);        // [3,0]\nproductOfNumbers.add(2);        // [3,0,2]\nproductOfNumbers.add(5);        // [3,0,2,5]\nproductOfNumbers.add(4);        // [3,0,2,5,4]\nproductOfNumbers.getProduct(2); // \u8fd4\u56de 20 \u3002\u6700\u540e 2 \u4e2a\u6570\u5b57\u7684\u4e58\u79ef\u662f 5 * 4 = 20\nproductOfNumbers.getProduct(3); // \u8fd4\u56de 40 \u3002\u6700\u540e 3 \u4e2a\u6570\u5b57\u7684\u4e58\u79ef\u662f 2 * 5 * 4 = 40\nproductOfNumbers.getProduct(4); // \u8fd4\u56de  0 \u3002\u6700\u540e 4 \u4e2a\u6570\u5b57\u7684\u4e58\u79ef\u662f 0 * 2 * 5 * 4 = 0\nproductOfNumbers.add(8);        // [3,0,2,5,4,8]\nproductOfNumbers.getProduct(2); // \u8fd4\u56de 32 \u3002\u6700\u540e 2 \u4e2a\u6570\u5b57\u7684\u4e58\u79ef\u662f 4 * 8 = 32 \n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • add \u548c getProduct \u4e24\u79cd\u64cd\u4f5c\u52a0\u8d77\u6765\u603b\u5171\u4e0d\u4f1a\u8d85\u8fc7 40000 \u6b21\u3002
  • \n\t
  • 0 <= num <= 100
  • \n\t
  • 1 <= k <= 40000
  • \n
\n", "tags_en": ["Design", "Array"], "tags_cn": ["\u8bbe\u8ba1", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class ProductOfNumbers {\npublic:\n ProductOfNumbers() {\n\n }\n \n void add(int num) {\n\n }\n \n int getProduct(int k) {\n\n }\n};\n\n/**\n * Your ProductOfNumbers object will be instantiated and called as such:\n * ProductOfNumbers* obj = new ProductOfNumbers();\n * obj->add(num);\n * int param_2 = obj->getProduct(k);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class ProductOfNumbers {\n\n public ProductOfNumbers() {\n\n }\n \n public void add(int num) {\n\n }\n \n public int getProduct(int k) {\n\n }\n}\n\n/**\n * Your ProductOfNumbers object will be instantiated and called as such:\n * ProductOfNumbers obj = new ProductOfNumbers();\n * obj.add(num);\n * int param_2 = obj.getProduct(k);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class ProductOfNumbers(object):\n\n def __init__(self):\n\n\n def add(self, num):\n \"\"\"\n :type num: int\n :rtype: None\n \"\"\"\n\n\n def getProduct(self, k):\n \"\"\"\n :type k: int\n :rtype: int\n \"\"\"\n\n\n\n# Your ProductOfNumbers object will be instantiated and called as such:\n# obj = ProductOfNumbers()\n# obj.add(num)\n# param_2 = obj.getProduct(k)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class ProductOfNumbers:\n\n def __init__(self):\n\n\n def add(self, num: int) -> None:\n\n\n def getProduct(self, k: int) -> int:\n\n\n\n# Your ProductOfNumbers object will be instantiated and called as such:\n# obj = ProductOfNumbers()\n# obj.add(num)\n# param_2 = obj.getProduct(k)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} ProductOfNumbers;\n\n\nProductOfNumbers* productOfNumbersCreate() {\n\n}\n\nvoid productOfNumbersAdd(ProductOfNumbers* obj, int num) {\n\n}\n\nint productOfNumbersGetProduct(ProductOfNumbers* obj, int k) {\n\n}\n\nvoid productOfNumbersFree(ProductOfNumbers* obj) {\n\n}\n\n/**\n * Your ProductOfNumbers struct will be instantiated and called as such:\n * ProductOfNumbers* obj = productOfNumbersCreate();\n * productOfNumbersAdd(obj, num);\n \n * int param_2 = productOfNumbersGetProduct(obj, k);\n \n * productOfNumbersFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class ProductOfNumbers {\n\n public ProductOfNumbers() {\n\n }\n \n public void Add(int num) {\n\n }\n \n public int GetProduct(int k) {\n\n }\n}\n\n/**\n * Your ProductOfNumbers object will be instantiated and called as such:\n * ProductOfNumbers obj = new ProductOfNumbers();\n * obj.Add(num);\n * int param_2 = obj.GetProduct(k);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "\nvar ProductOfNumbers = function() {\n\n};\n\n/** \n * @param {number} num\n * @return {void}\n */\nProductOfNumbers.prototype.add = function(num) {\n\n};\n\n/** \n * @param {number} k\n * @return {number}\n */\nProductOfNumbers.prototype.getProduct = function(k) {\n\n};\n\n/**\n * Your ProductOfNumbers object will be instantiated and called as such:\n * var obj = new ProductOfNumbers()\n * obj.add(num)\n * var param_2 = obj.getProduct(k)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class ProductOfNumbers\n def initialize()\n\n end\n\n\n=begin\n :type num: Integer\n :rtype: Void\n=end\n def add(num)\n\n end\n\n\n=begin\n :type k: Integer\n :rtype: Integer\n=end\n def get_product(k)\n\n end\n\n\nend\n\n# Your ProductOfNumbers object will be instantiated and called as such:\n# obj = ProductOfNumbers.new()\n# obj.add(num)\n# param_2 = obj.get_product(k)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass ProductOfNumbers {\n\n init() {\n \n }\n \n func add(_ num: Int) {\n \n }\n \n func getProduct(_ k: Int) -> Int {\n \n }\n}\n\n/**\n * Your ProductOfNumbers object will be instantiated and called as such:\n * let obj = ProductOfNumbers()\n * obj.add(num)\n * let ret_2: Int = obj.getProduct(k)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type ProductOfNumbers struct {\n\n}\n\n\nfunc Constructor() ProductOfNumbers {\n\n}\n\n\nfunc (this *ProductOfNumbers) Add(num int) {\n\n}\n\n\nfunc (this *ProductOfNumbers) GetProduct(k int) int {\n\n}\n\n\n/**\n * Your ProductOfNumbers object will be instantiated and called as such:\n * obj := Constructor();\n * obj.Add(num);\n * param_2 := obj.GetProduct(k);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class ProductOfNumbers() {\n\n def add(num: Int) {\n\n }\n\n def getProduct(k: Int): Int = {\n\n }\n\n}\n\n/**\n * Your ProductOfNumbers object will be instantiated and called as such:\n * var obj = new ProductOfNumbers()\n * obj.add(num)\n * var param_2 = obj.getProduct(k)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class ProductOfNumbers() {\n\n fun add(num: Int) {\n\n }\n\n fun getProduct(k: Int): Int {\n\n }\n\n}\n\n/**\n * Your ProductOfNumbers object will be instantiated and called as such:\n * var obj = ProductOfNumbers()\n * obj.add(num)\n * var param_2 = obj.getProduct(k)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct ProductOfNumbers {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl ProductOfNumbers {\n\n fn new() -> Self {\n\n }\n \n fn add(&self, num: i32) {\n\n }\n \n fn get_product(&self, k: i32) -> i32 {\n\n }\n}\n\n/**\n * Your ProductOfNumbers object will be instantiated and called as such:\n * let obj = ProductOfNumbers::new();\n * obj.add(num);\n * let ret_2: i32 = obj.get_product(k);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class ProductOfNumbers {\n /**\n */\n function __construct() {\n\n }\n\n /**\n * @param Integer $num\n * @return NULL\n */\n function add($num) {\n\n }\n\n /**\n * @param Integer $k\n * @return Integer\n */\n function getProduct($k) {\n\n }\n}\n\n/**\n * Your ProductOfNumbers object will be instantiated and called as such:\n * $obj = ProductOfNumbers();\n * $obj->add($num);\n * $ret_2 = $obj->getProduct($k);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class ProductOfNumbers {\n constructor() {\n\n }\n\n add(num: number): void {\n\n }\n\n getProduct(k: number): number {\n\n }\n}\n\n/**\n * Your ProductOfNumbers object will be instantiated and called as such:\n * var obj = new ProductOfNumbers()\n * obj.add(num)\n * var param_2 = obj.getProduct(k)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define product-of-numbers%\n (class object%\n (super-new)\n (init-field)\n \n ; add : exact-integer? -> void?\n (define/public (add num)\n\n )\n ; get-product : exact-integer? -> exact-integer?\n (define/public (get-product k)\n\n )))\n\n;; Your product-of-numbers% object will be instantiated and called as such:\n;; (define obj (new product-of-numbers%))\n;; (send obj add num)\n;; (define param_2 (send obj get-product k))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1352](https://leetcode-cn.com/problems/product-of-the-last-k-numbers)", "[\u6700\u540e K \u4e2a\u6570\u7684\u4e58\u79ef](/solution/1300-1399/1352.Product%20of%20the%20Last%20K%20Numbers/README.md)", "`\u8bbe\u8ba1`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1352](https://leetcode.com/problems/product-of-the-last-k-numbers)", "[Product of the Last K Numbers](/solution/1300-1399/1352.Product%20of%20the%20Last%20K%20Numbers/README_EN.md)", "`Design`,`Array`", "Medium", ""]}, {"question_id": "1476", "frontend_question_id": "1351", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-negative-numbers-in-a-sorted-matrix", "url_en": "https://leetcode.com/problems/count-negative-numbers-in-a-sorted-matrix", "relative_path_cn": "/solution/1300-1399/1351.Count%20Negative%20Numbers%20in%20a%20Sorted%20Matrix/README.md", "relative_path_en": "/solution/1300-1399/1351.Count%20Negative%20Numbers%20in%20a%20Sorted%20Matrix/README_EN.md", "title_cn": "\u7edf\u8ba1\u6709\u5e8f\u77e9\u9635\u4e2d\u7684\u8d1f\u6570", "title_en": "Count Negative Numbers in a Sorted Matrix", "question_title_slug": "count-negative-numbers-in-a-sorted-matrix", "content_en": "

Given a m x n matrix grid which is sorted in non-increasing order both row-wise and column-wise, return the number of negative numbers in grid.

\n\n

 

\n

Example 1:

\n\n
\nInput: grid = [[4,3,2,-1],[3,2,1,-1],[1,1,-1,-2],[-1,-1,-2,-3]]\nOutput: 8\nExplanation: There are 8 negatives number in the matrix.\n
\n\n

Example 2:

\n\n
\nInput: grid = [[3,2],[1,0]]\nOutput: 0\n
\n\n

Example 3:

\n\n
\nInput: grid = [[1,-1],[-1,-1]]\nOutput: 3\n
\n\n

Example 4:

\n\n
\nInput: grid = [[-1]]\nOutput: 1\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • m == grid.length
  • \n\t
  • n == grid[i].length
  • \n\t
  • 1 <= m, n <= 100
  • \n\t
  • -100 <= grid[i][j] <= 100
  • \n
\n\n

 

\nFollow up: Could you find an O(n + m) solution?", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u00a0m\u00a0* n\u00a0\u7684\u77e9\u9635\u00a0grid\uff0c\u77e9\u9635\u4e2d\u7684\u5143\u7d20\u65e0\u8bba\u662f\u6309\u884c\u8fd8\u662f\u6309\u5217\uff0c\u90fd\u4ee5\u975e\u9012\u589e\u987a\u5e8f\u6392\u5217\u3002\u00a0

\n\n

\u8bf7\u4f60\u7edf\u8ba1\u5e76\u8fd4\u56de\u00a0grid\u00a0\u4e2d \u8d1f\u6570 \u7684\u6570\u76ee\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1agrid = [[4,3,2,-1],[3,2,1,-1],[1,1,-1,-2],[-1,-1,-2,-3]]\n\u8f93\u51fa\uff1a8\n\u89e3\u91ca\uff1a\u77e9\u9635\u4e2d\u5171\u6709 8 \u4e2a\u8d1f\u6570\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1agrid = [[3,2],[1,0]]\n\u8f93\u51fa\uff1a0\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1agrid = [[1,-1],[-1,-1]]\n\u8f93\u51fa\uff1a3\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1agrid = [[-1]]\n\u8f93\u51fa\uff1a1\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • m == grid.length
  • \n\t
  • n == grid[i].length
  • \n\t
  • 1 <= m, n <= 100
  • \n\t
  • -100 <= grid[i][j] <= 100
  • \n
\n\n

\u00a0

\n\n

\u8fdb\u9636\uff1a\u4f60\u53ef\u4ee5\u8bbe\u8ba1\u4e00\u4e2a\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n + m) \u7684\u89e3\u51b3\u65b9\u6848\u5417\uff1f

\n\n

\u00a0

\n", "tags_en": ["Array", "Binary Search"], "tags_cn": ["\u6570\u7ec4", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countNegatives(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countNegatives(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countNegatives(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countNegatives(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countNegatives(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountNegatives(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar countNegatives = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef count_negatives(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countNegatives(_ grid: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countNegatives(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countNegatives(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countNegatives(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_negatives(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function countNegatives($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countNegatives(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-negatives grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1351](https://leetcode-cn.com/problems/count-negative-numbers-in-a-sorted-matrix)", "[\u7edf\u8ba1\u6709\u5e8f\u77e9\u9635\u4e2d\u7684\u8d1f\u6570](/solution/1300-1399/1351.Count%20Negative%20Numbers%20in%20a%20Sorted%20Matrix/README.md)", "`\u6570\u7ec4`,`\u4e8c\u5206\u67e5\u627e`", "\u7b80\u5355", ""], "md_table_row_en": ["[1351](https://leetcode.com/problems/count-negative-numbers-in-a-sorted-matrix)", "[Count Negative Numbers in a Sorted Matrix](/solution/1300-1399/1351.Count%20Negative%20Numbers%20in%20a%20Sorted%20Matrix/README_EN.md)", "`Array`,`Binary Search`", "Easy", ""]}, {"question_id": "1475", "frontend_question_id": "1373", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-sum-bst-in-binary-tree", "url_en": "https://leetcode.com/problems/maximum-sum-bst-in-binary-tree", "relative_path_cn": "/solution/1300-1399/1373.Maximum%20Sum%20BST%20in%20Binary%20Tree/README.md", "relative_path_en": "/solution/1300-1399/1373.Maximum%20Sum%20BST%20in%20Binary%20Tree/README_EN.md", "title_cn": "\u4e8c\u53c9\u641c\u7d22\u5b50\u6811\u7684\u6700\u5927\u952e\u503c\u548c", "title_en": "Maximum Sum BST in Binary Tree", "question_title_slug": "maximum-sum-bst-in-binary-tree", "content_en": "

Given a binary tree root, the task is to return the maximum sum of all keys of any sub-tree which is also a Binary Search Tree (BST).

\n\n

Assume a BST is defined as follows:

\n\n
    \n\t
  • The left subtree of a node contains only nodes with keys less than the node's key.
  • \n\t
  • The right subtree of a node contains only nodes with keys greater than the node's key.
  • \n\t
  • Both the left and right subtrees must also be binary search trees.
  • \n
\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: root = [1,4,3,2,4,2,5,null,null,null,null,null,null,4,6]\nOutput: 20\nExplanation: Maximum sum in a valid Binary search tree is obtained in root node with key equal to 3.\n
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: root = [4,3,null,1,2]\nOutput: 2\nExplanation: Maximum sum in a valid Binary search tree is obtained in a single root node with key equal to 2.\n
\n\n

Example 3:

\n\n
\nInput: root = [-4,-2,-5]\nOutput: 0\nExplanation: All values are negatives. Return an empty BST.\n
\n\n

Example 4:

\n\n
\nInput: root = [2,1,3]\nOutput: 6\n
\n\n

Example 5:

\n\n
\nInput: root = [5,4,8,3,null,6,3]\nOutput: 7\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The given binary tree will have between 1 and 40000 nodes.
  • \n\t
  • Each node's value is between [-4 * 10^4 , 4 * 10^4].
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u68f5\u4ee5\u00a0root\u00a0\u4e3a\u6839\u7684\u00a0\u4e8c\u53c9\u6811\u00a0\uff0c\u8bf7\u4f60\u8fd4\u56de \u4efb\u610f\u00a0\u4e8c\u53c9\u641c\u7d22\u5b50\u6811\u7684\u6700\u5927\u952e\u503c\u548c\u3002

\n\n

\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u5b9a\u4e49\u5982\u4e0b\uff1a

\n\n
    \n\t
  • \u4efb\u610f\u8282\u70b9\u7684\u5de6\u5b50\u6811\u4e2d\u7684\u952e\u503c\u90fd\u00a0\u5c0f\u4e8e\u00a0\u6b64\u8282\u70b9\u7684\u952e\u503c\u3002
  • \n\t
  • \u4efb\u610f\u8282\u70b9\u7684\u53f3\u5b50\u6811\u4e2d\u7684\u952e\u503c\u90fd \u5927\u4e8e\u00a0\u6b64\u8282\u70b9\u7684\u952e\u503c\u3002
  • \n\t
  • \u4efb\u610f\u8282\u70b9\u7684\u5de6\u5b50\u6811\u548c\u53f3\u5b50\u6811\u90fd\u662f\u4e8c\u53c9\u641c\u7d22\u6811\u3002
  • \n
\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1aroot = [1,4,3,2,4,2,5,null,null,null,null,null,null,4,6]\n\u8f93\u51fa\uff1a20\n\u89e3\u91ca\uff1a\u952e\u503c\u4e3a 3 \u7684\u5b50\u6811\u662f\u548c\u6700\u5927\u7684\u4e8c\u53c9\u641c\u7d22\u6811\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1aroot = [4,3,null,1,2]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u952e\u503c\u4e3a 2 \u7684\u5355\u8282\u70b9\u5b50\u6811\u662f\u548c\u6700\u5927\u7684\u4e8c\u53c9\u641c\u7d22\u6811\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1aroot = [-4,-2,-5]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6240\u6709\u8282\u70b9\u952e\u503c\u90fd\u4e3a\u8d1f\u6570\uff0c\u548c\u6700\u5927\u7684\u4e8c\u53c9\u641c\u7d22\u6811\u4e3a\u7a7a\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1aroot = [2,1,3]\n\u8f93\u51fa\uff1a6\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\n\u8f93\u5165\uff1aroot = [5,4,8,3,null,6,3]\n\u8f93\u51fa\uff1a7\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u6bcf\u68f5\u6811\u6709 1 \u5230 40000\u00a0\u4e2a\u8282\u70b9\u3002
  • \n\t
  • \u6bcf\u4e2a\u8282\u70b9\u7684\u952e\u503c\u5728\u00a0[-4 * 10^4\u00a0, 4 * 10^4] \u4e4b\u95f4\u3002
  • \n
\n", "tags_en": ["Binary Search Tree", "Dynamic Programming"], "tags_cn": ["\u4e8c\u53c9\u641c\u7d22\u6811", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int maxSumBST(TreeNode* root) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int maxSumBST(TreeNode root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def maxSumBST(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def maxSumBST(self, root: TreeNode) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint maxSumBST(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int MaxSumBST(TreeNode root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar maxSumBST = function(root) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef max_sum_bst(root)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func maxSumBST(_ root: TreeNode?) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc maxSumBST(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def maxSumBST(root: TreeNode): Int = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun maxSumBST(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn max_sum_bst(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function maxSumBST($root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction maxSumBST(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (max-sum-bst root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1373](https://leetcode-cn.com/problems/maximum-sum-bst-in-binary-tree)", "[\u4e8c\u53c9\u641c\u7d22\u5b50\u6811\u7684\u6700\u5927\u952e\u503c\u548c](/solution/1300-1399/1373.Maximum%20Sum%20BST%20in%20Binary%20Tree/README.md)", "`\u4e8c\u53c9\u641c\u7d22\u6811`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1373](https://leetcode.com/problems/maximum-sum-bst-in-binary-tree)", "[Maximum Sum BST in Binary Tree](/solution/1300-1399/1373.Maximum%20Sum%20BST%20in%20Binary%20Tree/README_EN.md)", "`Binary Search Tree`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "1474", "frontend_question_id": "1372", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-zigzag-path-in-a-binary-tree", "url_en": "https://leetcode.com/problems/longest-zigzag-path-in-a-binary-tree", "relative_path_cn": "/solution/1300-1399/1372.Longest%20ZigZag%20Path%20in%20a%20Binary%20Tree/README.md", "relative_path_en": "/solution/1300-1399/1372.Longest%20ZigZag%20Path%20in%20a%20Binary%20Tree/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u4e2d\u7684\u6700\u957f\u4ea4\u9519\u8def\u5f84", "title_en": "Longest ZigZag Path in a Binary Tree", "question_title_slug": "longest-zigzag-path-in-a-binary-tree", "content_en": "

You are given the root of a binary tree.

\n\n

A ZigZag path for a binary tree is defined as follow:

\n\n
    \n\t
  • Choose any node in the binary tree and a direction (right or left).
  • \n\t
  • If the current direction is right, move to the right child of the current node; otherwise, move to the left child.
  • \n\t
  • Change the direction from right to left or from left to right.
  • \n\t
  • Repeat the second and third steps until you can't move in the tree.
  • \n
\n\n

Zigzag length is defined as the number of nodes visited - 1. (A single node has a length of 0).

\n\n

Return the longest ZigZag path contained in that tree.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: root = [1,null,1,1,1,null,null,1,1,null,1,null,null,null,1,null,1]\nOutput: 3\nExplanation: Longest ZigZag path in blue nodes (right -> left -> right).\n
\n\n

Example 2:

\n\"\"\n
\nInput: root = [1,1,1,null,1,null,null,1,1,null,1]\nOutput: 4\nExplanation: Longest ZigZag path in blue nodes (left -> right -> left -> right).\n
\n\n

Example 3:

\n\n
\nInput: root = [1]\nOutput: 0\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The number of nodes in the tree is in the range [1, 5 * 104].
  • \n\t
  • 1 <= Node.val <= 100
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u68f5\u4ee5 root \u4e3a\u6839\u7684\u4e8c\u53c9\u6811\uff0c\u4e8c\u53c9\u6811\u4e2d\u7684\u4ea4\u9519\u8def\u5f84\u5b9a\u4e49\u5982\u4e0b\uff1a

\n\n
    \n\t
  • \u9009\u62e9\u4e8c\u53c9\u6811\u4e2d \u4efb\u610f \u8282\u70b9\u548c\u4e00\u4e2a\u65b9\u5411\uff08\u5de6\u6216\u8005\u53f3\uff09\u3002
  • \n\t
  • \u5982\u679c\u524d\u8fdb\u65b9\u5411\u4e3a\u53f3\uff0c\u90a3\u4e48\u79fb\u52a8\u5230\u5f53\u524d\u8282\u70b9\u7684\u7684\u53f3\u5b50\u8282\u70b9\uff0c\u5426\u5219\u79fb\u52a8\u5230\u5b83\u7684\u5de6\u5b50\u8282\u70b9\u3002
  • \n\t
  • \u6539\u53d8\u524d\u8fdb\u65b9\u5411\uff1a\u5de6\u53d8\u53f3\u6216\u8005\u53f3\u53d8\u5de6\u3002
  • \n\t
  • \u91cd\u590d\u7b2c\u4e8c\u6b65\u548c\u7b2c\u4e09\u6b65\uff0c\u76f4\u5230\u4f60\u5728\u6811\u4e2d\u65e0\u6cd5\u7ee7\u7eed\u79fb\u52a8\u3002
  • \n
\n\n

\u4ea4\u9519\u8def\u5f84\u7684\u957f\u5ea6\u5b9a\u4e49\u4e3a\uff1a\u8bbf\u95ee\u8fc7\u7684\u8282\u70b9\u6570\u76ee - 1\uff08\u5355\u4e2a\u8282\u70b9\u7684\u8def\u5f84\u957f\u5ea6\u4e3a 0 \uff09\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u7ed9\u5b9a\u6811\u4e2d\u6700\u957f \u4ea4\u9519\u8def\u5f84 \u7684\u957f\u5ea6\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1aroot = [1,null,1,1,1,null,null,1,1,null,1,null,null,null,1,null,1]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u84dd\u8272\u8282\u70b9\u4e3a\u6811\u4e2d\u6700\u957f\u4ea4\u9519\u8def\u5f84\uff08\u53f3 -> \u5de6 -> \u53f3\uff09\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1aroot = [1,1,1,null,1,null,null,1,1,null,1]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u84dd\u8272\u8282\u70b9\u4e3a\u6811\u4e2d\u6700\u957f\u4ea4\u9519\u8def\u5f84\uff08\u5de6 -> \u53f3 -> \u5de6 -> \u53f3\uff09\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aroot = [1]\n\u8f93\u51fa\uff1a0\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u6bcf\u68f5\u6811\u6700\u591a\u6709 50000 \u4e2a\u8282\u70b9\u3002
  • \n\t
  • \u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u5728 [1, 100] \u4e4b\u95f4\u3002
  • \n
\n", "tags_en": ["Tree", "Dynamic Programming"], "tags_cn": ["\u6811", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int longestZigZag(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int longestZigZag(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def longestZigZag(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def longestZigZag(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint longestZigZag(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int LongestZigZag(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar longestZigZag = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef longest_zig_zag(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func longestZigZag(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc longestZigZag(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def longestZigZag(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun longestZigZag(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn longest_zig_zag(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function longestZigZag($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction longestZigZag(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (longest-zig-zag root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1372](https://leetcode-cn.com/problems/longest-zigzag-path-in-a-binary-tree)", "[\u4e8c\u53c9\u6811\u4e2d\u7684\u6700\u957f\u4ea4\u9519\u8def\u5f84](/solution/1300-1399/1372.Longest%20ZigZag%20Path%20in%20a%20Binary%20Tree/README.md)", "`\u6811`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1372](https://leetcode.com/problems/longest-zigzag-path-in-a-binary-tree)", "[Longest ZigZag Path in a Binary Tree](/solution/1300-1399/1372.Longest%20ZigZag%20Path%20in%20a%20Binary%20Tree/README_EN.md)", "`Tree`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "1473", "frontend_question_id": "1371", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-the-longest-substring-containing-vowels-in-even-counts", "url_en": "https://leetcode.com/problems/find-the-longest-substring-containing-vowels-in-even-counts", "relative_path_cn": "/solution/1300-1399/1371.Find%20the%20Longest%20Substring%20Containing%20Vowels%20in%20Even%20Counts/README.md", "relative_path_en": "/solution/1300-1399/1371.Find%20the%20Longest%20Substring%20Containing%20Vowels%20in%20Even%20Counts/README_EN.md", "title_cn": "\u6bcf\u4e2a\u5143\u97f3\u5305\u542b\u5076\u6570\u6b21\u7684\u6700\u957f\u5b50\u5b57\u7b26\u4e32", "title_en": "Find the Longest Substring Containing Vowels in Even Counts", "question_title_slug": "find-the-longest-substring-containing-vowels-in-even-counts", "content_en": "

Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "eleetminicoworoep"\nOutput: 13\nExplanation: The longest substring is "leetminicowor" which contains two each of the vowels: e, i and o and zero of the vowels: a and u.\n
\n\n

Example 2:

\n\n
\nInput: s = "leetcodeisgreat"\nOutput: 5\nExplanation: The longest substring is "leetc" which contains two e's.\n
\n\n

Example 3:

\n\n
\nInput: s = "bcbcbc"\nOutput: 6\nExplanation: In this case, the given string "bcbcbc" is the longest because all vowels: a, e, i, o and u appear zero times.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 5 x 10^5
  • \n\t
  • s contains only lowercase English letters.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \uff0c\u8bf7\u4f60\u8fd4\u56de\u6ee1\u8db3\u4ee5\u4e0b\u6761\u4ef6\u7684\u6700\u957f\u5b50\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\uff1a\u6bcf\u4e2a\u5143\u97f3\u5b57\u6bcd\uff0c\u5373 'a'\uff0c'e'\uff0c'i'\uff0c'o'\uff0c'u' \uff0c\u5728\u5b50\u5b57\u7b26\u4e32\u4e2d\u90fd\u6070\u597d\u51fa\u73b0\u4e86\u5076\u6570\u6b21\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1as = "eleetminicoworoep"\n\u8f93\u51fa\uff1a13\n\u89e3\u91ca\uff1a\u6700\u957f\u5b50\u5b57\u7b26\u4e32\u662f "leetminicowor" \uff0c\u5b83\u5305\u542b e\uff0ci\uff0co \u5404 2 \u4e2a\uff0c\u4ee5\u53ca 0 \u4e2a a\uff0cu \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1as = "leetcodeisgreat"\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u6700\u957f\u5b50\u5b57\u7b26\u4e32\u662f "leetc" \uff0c\u5176\u4e2d\u5305\u542b 2 \u4e2a e \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1as = "bcbcbc"\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u5b57\u7b26\u4e32 "bcbcbc" \u672c\u8eab\u5c31\u662f\u6700\u957f\u7684\uff0c\u56e0\u4e3a\u6240\u6709\u7684\u5143\u97f3 a\uff0ce\uff0ci\uff0co\uff0cu \u90fd\u51fa\u73b0\u4e86 0 \u6b21\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length <= 5 x 10^5
  • \n\t
  • s \u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findTheLongestSubstring(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findTheLongestSubstring(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findTheLongestSubstring(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findTheLongestSubstring(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findTheLongestSubstring(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindTheLongestSubstring(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar findTheLongestSubstring = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef find_the_longest_substring(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findTheLongestSubstring(_ s: String) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findTheLongestSubstring(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findTheLongestSubstring(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findTheLongestSubstring(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_the_longest_substring(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function findTheLongestSubstring($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findTheLongestSubstring(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-the-longest-substring s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1371](https://leetcode-cn.com/problems/find-the-longest-substring-containing-vowels-in-even-counts)", "[\u6bcf\u4e2a\u5143\u97f3\u5305\u542b\u5076\u6570\u6b21\u7684\u6700\u957f\u5b50\u5b57\u7b26\u4e32](/solution/1300-1399/1371.Find%20the%20Longest%20Substring%20Containing%20Vowels%20in%20Even%20Counts/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1371](https://leetcode.com/problems/find-the-longest-substring-containing-vowels-in-even-counts)", "[Find the Longest Substring Containing Vowels in Even Counts](/solution/1300-1399/1371.Find%20the%20Longest%20Substring%20Containing%20Vowels%20in%20Even%20Counts/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "1472", "frontend_question_id": "1370", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/increasing-decreasing-string", "url_en": "https://leetcode.com/problems/increasing-decreasing-string", "relative_path_cn": "/solution/1300-1399/1370.Increasing%20Decreasing%20String/README.md", "relative_path_en": "/solution/1300-1399/1370.Increasing%20Decreasing%20String/README_EN.md", "title_cn": "\u4e0a\u5347\u4e0b\u964d\u5b57\u7b26\u4e32", "title_en": "Increasing Decreasing String", "question_title_slug": "increasing-decreasing-string", "content_en": "

Given a string s. You should re-order the string using the following algorithm:

\n\n
    \n\t
  1. Pick the smallest character from s and append it to the result.
  2. \n\t
  3. Pick the smallest character from s which is greater than the last appended character to the result and append it.
  4. \n\t
  5. Repeat step 2 until you cannot pick more characters.
  6. \n\t
  7. Pick the largest character from s and append it to the result.
  8. \n\t
  9. Pick the largest character from s which is smaller than the last appended character to the result and append it.
  10. \n\t
  11. Repeat step 5 until you cannot pick more characters.
  12. \n\t
  13. Repeat the steps from 1 to 6 until you pick all characters from s.
  14. \n
\n\n

In each step, If the smallest or the largest character appears more than once you can choose any occurrence and append it to the result.

\n\n

Return the result string after sorting s with this algorithm.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "aaaabbbbcccc"\nOutput: "abccbaabccba"\nExplanation: After steps 1, 2 and 3 of the first iteration, result = "abc"\nAfter steps 4, 5 and 6 of the first iteration, result = "abccba"\nFirst iteration is done. Now s = "aabbcc" and we go back to step 1\nAfter steps 1, 2 and 3 of the second iteration, result = "abccbaabc"\nAfter steps 4, 5 and 6 of the second iteration, result = "abccbaabccba"\n
\n\n

Example 2:

\n\n
\nInput: s = "rat"\nOutput: "art"\nExplanation: The word "rat" becomes "art" after re-ordering it with the mentioned algorithm.\n
\n\n

Example 3:

\n\n
\nInput: s = "leetcode"\nOutput: "cdelotee"\n
\n\n

Example 4:

\n\n
\nInput: s = "ggggggg"\nOutput: "ggggggg"\n
\n\n

Example 5:

\n\n
\nInput: s = "spo"\nOutput: "ops"\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 500
  • \n\t
  • s contains only lower-case English letters.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \uff0c\u8bf7\u4f60\u6839\u636e\u4e0b\u9762\u7684\u7b97\u6cd5\u91cd\u65b0\u6784\u9020\u5b57\u7b26\u4e32\uff1a

\n\n
    \n\t
  1. \u4ece s \u4e2d\u9009\u51fa \u6700\u5c0f \u7684\u5b57\u7b26\uff0c\u5c06\u5b83 \u63a5\u5728 \u7ed3\u679c\u5b57\u7b26\u4e32\u7684\u540e\u9762\u3002
  2. \n\t
  3. \u4ece s \u5269\u4f59\u5b57\u7b26\u4e2d\u9009\u51fa \u6700\u5c0f \u7684\u5b57\u7b26\uff0c\u4e14\u8be5\u5b57\u7b26\u6bd4\u4e0a\u4e00\u4e2a\u6dfb\u52a0\u7684\u5b57\u7b26\u5927\uff0c\u5c06\u5b83 \u63a5\u5728 \u7ed3\u679c\u5b57\u7b26\u4e32\u540e\u9762\u3002
  4. \n\t
  5. \u91cd\u590d\u6b65\u9aa4 2 \uff0c\u76f4\u5230\u4f60\u6ca1\u6cd5\u4ece s \u4e2d\u9009\u62e9\u5b57\u7b26\u3002
  6. \n\t
  7. \u4ece s \u4e2d\u9009\u51fa \u6700\u5927 \u7684\u5b57\u7b26\uff0c\u5c06\u5b83 \u63a5\u5728 \u7ed3\u679c\u5b57\u7b26\u4e32\u7684\u540e\u9762\u3002
  8. \n\t
  9. \u4ece s \u5269\u4f59\u5b57\u7b26\u4e2d\u9009\u51fa \u6700\u5927 \u7684\u5b57\u7b26\uff0c\u4e14\u8be5\u5b57\u7b26\u6bd4\u4e0a\u4e00\u4e2a\u6dfb\u52a0\u7684\u5b57\u7b26\u5c0f\uff0c\u5c06\u5b83 \u63a5\u5728 \u7ed3\u679c\u5b57\u7b26\u4e32\u540e\u9762\u3002
  10. \n\t
  11. \u91cd\u590d\u6b65\u9aa4 5 \uff0c\u76f4\u5230\u4f60\u6ca1\u6cd5\u4ece s \u4e2d\u9009\u62e9\u5b57\u7b26\u3002
  12. \n\t
  13. \u91cd\u590d\u6b65\u9aa4 1 \u5230 6 \uff0c\u76f4\u5230 s \u4e2d\u6240\u6709\u5b57\u7b26\u90fd\u5df2\u7ecf\u88ab\u9009\u8fc7\u3002
  14. \n
\n\n

\u5728\u4efb\u4f55\u4e00\u6b65\u4e2d\uff0c\u5982\u679c\u6700\u5c0f\u6216\u8005\u6700\u5927\u5b57\u7b26\u4e0d\u6b62\u4e00\u4e2a \uff0c\u4f60\u53ef\u4ee5\u9009\u62e9\u5176\u4e2d\u4efb\u610f\u4e00\u4e2a\uff0c\u5e76\u5c06\u5176\u6dfb\u52a0\u5230\u7ed3\u679c\u5b57\u7b26\u4e32\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u5c06 s \u4e2d\u5b57\u7b26\u91cd\u65b0\u6392\u5e8f\u540e\u7684 \u7ed3\u679c\u5b57\u7b26\u4e32 \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1as = "aaaabbbbcccc"\n\u8f93\u51fa\uff1a"abccbaabccba"\n\u89e3\u91ca\uff1a\u7b2c\u4e00\u8f6e\u7684\u6b65\u9aa4 1\uff0c2\uff0c3 \u540e\uff0c\u7ed3\u679c\u5b57\u7b26\u4e32\u4e3a result = "abc"\n\u7b2c\u4e00\u8f6e\u7684\u6b65\u9aa4 4\uff0c5\uff0c6 \u540e\uff0c\u7ed3\u679c\u5b57\u7b26\u4e32\u4e3a result = "abccba"\n\u7b2c\u4e00\u8f6e\u7ed3\u675f\uff0c\u73b0\u5728 s = "aabbcc" \uff0c\u6211\u4eec\u518d\u6b21\u56de\u5230\u6b65\u9aa4 1\n\u7b2c\u4e8c\u8f6e\u7684\u6b65\u9aa4 1\uff0c2\uff0c3 \u540e\uff0c\u7ed3\u679c\u5b57\u7b26\u4e32\u4e3a result = "abccbaabc"\n\u7b2c\u4e8c\u8f6e\u7684\u6b65\u9aa4 4\uff0c5\uff0c6 \u540e\uff0c\u7ed3\u679c\u5b57\u7b26\u4e32\u4e3a result = "abccbaabccba"\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1as = "rat"\n\u8f93\u51fa\uff1a"art"\n\u89e3\u91ca\uff1a\u5355\u8bcd "rat" \u5728\u4e0a\u8ff0\u7b97\u6cd5\u91cd\u6392\u5e8f\u4ee5\u540e\u53d8\u6210 "art"\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1as = "leetcode"\n\u8f93\u51fa\uff1a"cdelotee"\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1as = "ggggggg"\n\u8f93\u51fa\uff1a"ggggggg"\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1as = "spo"\n\u8f93\u51fa\uff1a"ops"\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length <= 500
  • \n\t
  • s \u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
  • \n
\n", "tags_en": ["Sort", "String"], "tags_cn": ["\u6392\u5e8f", "\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string sortString(string s) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String sortString(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def sortString(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def sortString(self, s: str) -> str:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * sortString(char * s){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string SortString(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar sortString = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef sort_string(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func sortString(_ s: String) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func sortString(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def sortString(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun sortString(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sort_string(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function sortString($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function sortString(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (sort-string s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1370](https://leetcode-cn.com/problems/increasing-decreasing-string)", "[\u4e0a\u5347\u4e0b\u964d\u5b57\u7b26\u4e32](/solution/1300-1399/1370.Increasing%20Decreasing%20String/README.md)", "`\u6392\u5e8f`,`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1370](https://leetcode.com/problems/increasing-decreasing-string)", "[Increasing Decreasing String](/solution/1300-1399/1370.Increasing%20Decreasing%20String/README_EN.md)", "`Sort`,`String`", "Easy", ""]}, {"question_id": "1471", "frontend_question_id": "1349", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-students-taking-exam", "url_en": "https://leetcode.com/problems/maximum-students-taking-exam", "relative_path_cn": "/solution/1300-1399/1349.Maximum%20Students%20Taking%20Exam/README.md", "relative_path_en": "/solution/1300-1399/1349.Maximum%20Students%20Taking%20Exam/README_EN.md", "title_cn": "\u53c2\u52a0\u8003\u8bd5\u7684\u6700\u5927\u5b66\u751f\u6570", "title_en": "Maximum Students Taking Exam", "question_title_slug": "maximum-students-taking-exam", "content_en": "

Given a m * n matrix seats  that represent seats distributions in a classroom. If a seat is broken, it is denoted by '#' character otherwise it is denoted by a '.' character.

\n\n

Students can see the answers of those sitting next to the left, right, upper left and upper right, but he cannot see the answers of the student sitting directly in front or behind him. Return the maximum number of students that can take the exam together without any cheating being possible..

\n\n

Students must be placed in seats in good condition.

\n\n

 

\n

Example 1:

\n\n
\nInput: seats = [["#",".","#","#",".","#"],\n                [".","#","#","#","#","."],\n                ["#",".","#","#",".","#"]]\nOutput: 4\nExplanation: Teacher can place 4 students in available seats so they don't cheat on the exam. \n
\n\n

Example 2:

\n\n
\nInput: seats = [[".","#"],\n                ["#","#"],\n                ["#","."],\n                ["#","#"],\n                [".","#"]]\nOutput: 3\nExplanation: Place all students in available seats. \n\n
\n\n

Example 3:

\n\n
\nInput: seats = [["#",".",".",".","#"],\n                [".","#",".","#","."],\n                [".",".","#",".","."],\n                [".","#",".","#","."],\n                ["#",".",".",".","#"]]\nOutput: 10\nExplanation: Place students in available seats in column 1, 3 and 5.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • seats contains only characters '.' and'#'.
  • \n\t
  • m == seats.length
  • \n\t
  • n == seats[i].length
  • \n\t
  • 1 <= m <= 8
  • \n\t
  • 1 <= n <= 8
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a m * n \u7684\u77e9\u9635 seats \u8868\u793a\u6559\u5ba4\u4e2d\u7684\u5ea7\u4f4d\u5206\u5e03\u3002\u5982\u679c\u5ea7\u4f4d\u662f\u574f\u7684\uff08\u4e0d\u53ef\u7528\uff09\uff0c\u5c31\u7528 '#' \u8868\u793a\uff1b\u5426\u5219\uff0c\u7528 '.' \u8868\u793a\u3002

\n\n

\u5b66\u751f\u53ef\u4ee5\u770b\u5230\u5de6\u4fa7\u3001\u53f3\u4fa7\u3001\u5de6\u4e0a\u3001\u53f3\u4e0a\u8fd9\u56db\u4e2a\u65b9\u5411\u4e0a\u7d27\u90bb\u4ed6\u7684\u5b66\u751f\u7684\u7b54\u5377\uff0c\u4f46\u662f\u770b\u4e0d\u5230\u76f4\u63a5\u5750\u5728\u4ed6\u524d\u9762\u6216\u8005\u540e\u9762\u7684\u5b66\u751f\u7684\u7b54\u5377\u3002\u8bf7\u4f60\u8ba1\u7b97\u5e76\u8fd4\u56de\u8be5\u8003\u573a\u53ef\u4ee5\u5bb9\u7eb3\u7684\u4e00\u8d77\u53c2\u52a0\u8003\u8bd5\u4e14\u65e0\u6cd5\u4f5c\u5f0a\u7684\u6700\u5927\u5b66\u751f\u4eba\u6570\u3002

\n\n

\u5b66\u751f\u5fc5\u987b\u5750\u5728\u72b6\u51b5\u826f\u597d\u7684\u5ea7\u4f4d\u4e0a\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\n\n
\u8f93\u5165\uff1aseats = [["#",".","#","#",".","#"],\n              [".","#","#","#","#","."],\n              ["#",".","#","#",".","#"]]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u6559\u5e08\u53ef\u4ee5\u8ba9 4 \u4e2a\u5b66\u751f\u5750\u5728\u53ef\u7528\u7684\u5ea7\u4f4d\u4e0a\uff0c\u8fd9\u6837\u4ed6\u4eec\u5c31\u65e0\u6cd5\u5728\u8003\u8bd5\u4e2d\u4f5c\u5f0a\u3002 \n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aseats = [[".","#"],\n              ["#","#"],\n              ["#","."],\n              ["#","#"],\n              [".","#"]]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u8ba9\u6240\u6709\u5b66\u751f\u5750\u5728\u53ef\u7528\u7684\u5ea7\u4f4d\u4e0a\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aseats = [["#",".",".",".","#"],\n              [".","#",".","#","."],\n              [".",".","#",".","."],\n              [".","#",".","#","."],\n              ["#",".",".",".","#"]]\n\u8f93\u51fa\uff1a10\n\u89e3\u91ca\uff1a\u8ba9\u5b66\u751f\u5750\u5728\u7b2c 1\u30013 \u548c 5 \u5217\u7684\u53ef\u7528\u5ea7\u4f4d\u4e0a\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • seats \u53ea\u5305\u542b\u5b57\u7b26 '.' \u548c'#'
  • \n\t
  • m == seats.length
  • \n\t
  • n == seats[i].length
  • \n\t
  • 1 <= m <= 8
  • \n\t
  • 1 <= n <= 8
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxStudents(vector>& seats) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxStudents(char[][] seats) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxStudents(self, seats):\n \"\"\"\n :type seats: List[List[str]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxStudents(self, seats: List[List[str]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxStudents(char** seats, int seatsSize, int* seatsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxStudents(char[][] seats) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {character[][]} seats\n * @return {number}\n */\nvar maxStudents = function(seats) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Character[][]} seats\n# @return {Integer}\ndef max_students(seats)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxStudents(_ seats: [[Character]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxStudents(seats [][]byte) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxStudents(seats: Array[Array[Char]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxStudents(seats: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_students(seats: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $seats\n * @return Integer\n */\n function maxStudents($seats) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxStudents(seats: string[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-students seats)\n (-> (listof (listof char?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1349](https://leetcode-cn.com/problems/maximum-students-taking-exam)", "[\u53c2\u52a0\u8003\u8bd5\u7684\u6700\u5927\u5b66\u751f\u6570](/solution/1300-1399/1349.Maximum%20Students%20Taking%20Exam/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1349](https://leetcode.com/problems/maximum-students-taking-exam)", "[Maximum Students Taking Exam](/solution/1300-1399/1349.Maximum%20Students%20Taking%20Exam/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1470", "frontend_question_id": "1348", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/tweet-counts-per-frequency", "url_en": "https://leetcode.com/problems/tweet-counts-per-frequency", "relative_path_cn": "/solution/1300-1399/1348.Tweet%20Counts%20Per%20Frequency/README.md", "relative_path_en": "/solution/1300-1399/1348.Tweet%20Counts%20Per%20Frequency/README_EN.md", "title_cn": "\u63a8\u6587\u8ba1\u6570", "title_en": "Tweet Counts Per Frequency", "question_title_slug": "tweet-counts-per-frequency", "content_en": "

A social media company is trying to monitor activity on their site by analyzing the number of tweets that occur in select periods of time. These periods can be partitioned into smaller time chunks based on a certain frequency (every minute, hour, or day).

\n\n

For example, the period [10, 10000] (in seconds) would be partitioned into the following time chunks with these frequencies:

\n\n
    \n\t
  • Every minute (60-second chunks): [10,69], [70,129], [130,189], ..., [9970,10000]
  • \n\t
  • Every hour (3600-second chunks): [10,3609], [3610,7209], [7210,10000]
  • \n\t
  • Every day (86400-second chunks): [10,10000]
  • \n
\n\n

Notice that the last chunk may be shorter than the specified frequency's chunk size and will always end with the end time of the period (10000 in the above example).

\n\n

Design and implement an API to help the company with their analysis.

\n\n

Implement the TweetCounts class:

\n\n
    \n\t
  • TweetCounts() Initializes the TweetCounts object.
  • \n\t
  • void recordTweet(String tweetName, int time) Stores the tweetName at the recorded time (in seconds).
  • \n\t
  • List<Integer> getTweetCountsPerFrequency(String freq, String tweetName, int startTime, int endTime) Returns a list of integers representing the number of tweets with tweetName in each time chunk for the given period of time [startTime, endTime] (in seconds) and frequency freq.\n\t
      \n\t\t
    • freq is one of "minute", "hour", or "day" representing a frequency of every minute, hour, or day respectively.
    • \n\t
    \n\t
  • \n
\n\n

 

\n

Example:

\n\n
\nInput\n["TweetCounts","recordTweet","recordTweet","recordTweet","getTweetCountsPerFrequency","getTweetCountsPerFrequency","recordTweet","getTweetCountsPerFrequency"]\n[[],["tweet3",0],["tweet3",60],["tweet3",10],["minute","tweet3",0,59],["minute","tweet3",0,60],["tweet3",120],["hour","tweet3",0,210]]\n\nOutput\n[null,null,null,null,[2],[2,1],null,[4]]\n\nExplanation\nTweetCounts tweetCounts = new TweetCounts();\ntweetCounts.recordTweet("tweet3", 0);                              // New tweet "tweet3" at time 0\ntweetCounts.recordTweet("tweet3", 60);                             // New tweet "tweet3" at time 60\ntweetCounts.recordTweet("tweet3", 10);                             // New tweet "tweet3" at time 10\ntweetCounts.getTweetCountsPerFrequency("minute", "tweet3", 0, 59); // return [2]; chunk [0,59] had 2 tweets\ntweetCounts.getTweetCountsPerFrequency("minute", "tweet3", 0, 60); // return [2,1]; chunk [0,59] had 2 tweets, chunk [60,60] had 1 tweet\ntweetCounts.recordTweet("tweet3", 120);                            // New tweet "tweet3" at time 120\ntweetCounts.getTweetCountsPerFrequency("hour", "tweet3", 0, 210);  // return [4]; chunk [0,210] had 4 tweets\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 0 <= time, startTime, endTime <= 109
  • \n\t
  • 0 <= endTime - startTime <= 104
  • \n\t
  • There will be at most 104 calls in total to recordTweet and getTweetCountsPerFrequency.
  • \n
\n", "content_cn": "

\u8bf7\u4f60\u5b9e\u73b0\u4e00\u4e2a\u80fd\u591f\u652f\u6301\u4ee5\u4e0b\u4e24\u79cd\u65b9\u6cd5\u7684\u63a8\u6587\u8ba1\u6570\u7c7b TweetCounts\uff1a

\n\n

1. recordTweet(string tweetName, int time)

\n\n
    \n\t
  • \u8bb0\u5f55\u63a8\u6587\u53d1\u5e03\u60c5\u51b5\uff1a\u7528\u6237 tweetName \u5728 time\uff08\u4ee5 \u79d2 \u4e3a\u5355\u4f4d\uff09\u65f6\u523b\u53d1\u5e03\u4e86\u4e00\u6761\u63a8\u6587\u3002
  • \n
\n\n

2. getTweetCountsPerFrequency(string freq, string tweetName, int startTime, int endTime)

\n\n
    \n\t
  • \u8fd4\u56de\u4ece\u5f00\u59cb\u65f6\u95f4 startTime\uff08\u4ee5 \u79d2 \u4e3a\u5355\u4f4d\uff09\u5230\u7ed3\u675f\u65f6\u95f4 endTime\uff08\u4ee5 \u79d2 \u4e3a\u5355\u4f4d\uff09\u5185\uff0c\u6bcf \u5206 minute\uff0c\u65f6 hour \u6216\u8005 \u65e5 day \uff08\u53d6\u51b3\u4e8e freq\uff09\u5185\u6307\u5b9a\u7528\u6237 tweetName \u53d1\u5e03\u7684\u63a8\u6587\u603b\u6570\u3002
  • \n\t
  • freq \u7684\u503c\u59cb\u7ec8\u4e3a \u5206 minute\uff0c\u65f6 hour \u6216\u8005 \u65e5 day \u4e4b\u4e00\uff0c\u8868\u793a\u83b7\u53d6\u6307\u5b9a\u7528\u6237 tweetName \u53d1\u5e03\u63a8\u6587\u6b21\u6570\u7684\u65f6\u95f4\u95f4\u9694\u3002
  • \n\t
  • \u7b2c\u4e00\u4e2a\u65f6\u95f4\u95f4\u9694\u59cb\u7ec8\u4ece startTime \u5f00\u59cb\uff0c\u56e0\u6b64\u65f6\u95f4\u95f4\u9694\u4e3a [startTime, startTime + delta*1>,  [startTime + delta*1, startTime + delta*2>, [startTime + delta*2, startTime + delta*3>, ... , [startTime + delta*i, min(startTime + delta*(i+1), endTime + 1)>\uff0c\u5176\u4e2d i \u548c delta\uff08\u53d6\u51b3\u4e8e freq\uff09\u90fd\u662f\u975e\u8d1f\u6574\u6570\u3002
  • \n
\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1a\n["TweetCounts","recordTweet","recordTweet","recordTweet","getTweetCountsPerFrequency","getTweetCountsPerFrequency","recordTweet","getTweetCountsPerFrequency"]\n[[],["tweet3",0],["tweet3",60],["tweet3",10],["minute","tweet3",0,59],["minute","tweet3",0,60],["tweet3",120],["hour","tweet3",0,210]]\n\n\u8f93\u51fa\uff1a\n[null,null,null,null,[2],[2,1],null,[4]]\n\n\u89e3\u91ca\uff1a\nTweetCounts tweetCounts = new TweetCounts();\ntweetCounts.recordTweet("tweet3", 0);\ntweetCounts.recordTweet("tweet3", 60);\ntweetCounts.recordTweet("tweet3", 10);                             // "tweet3" \u53d1\u5e03\u63a8\u6587\u7684\u65f6\u95f4\u5206\u522b\u662f 0, 10 \u548c 60 \u3002\ntweetCounts.getTweetCountsPerFrequency("minute", "tweet3", 0, 59); // \u8fd4\u56de [2]\u3002\u7edf\u8ba1\u9891\u7387\u662f\u6bcf\u5206\u949f\uff0860 \u79d2\uff09\uff0c\u56e0\u6b64\u53ea\u6709\u4e00\u4e2a\u6709\u6548\u65f6\u95f4\u95f4\u9694 [0,60> - > 2 \u6761\u63a8\u6587\u3002\ntweetCounts.getTweetCountsPerFrequency("minute", "tweet3", 0, 60); // \u8fd4\u56de [2,1]\u3002\u7edf\u8ba1\u9891\u7387\u662f\u6bcf\u5206\u949f\uff0860 \u79d2\uff09\uff0c\u56e0\u6b64\u6709\u4e24\u4e2a\u6709\u6548\u65f6\u95f4\u95f4\u9694 1) [0,60> - > 2 \u6761\u63a8\u6587\uff0c\u548c 2) [60,61> - > 1 \u6761\u63a8\u6587\u3002 \ntweetCounts.recordTweet("tweet3", 120);                            // "tweet3" \u53d1\u5e03\u63a8\u6587\u7684\u65f6\u95f4\u5206\u522b\u662f 0, 10, 60 \u548c 120 \u3002\ntweetCounts.getTweetCountsPerFrequency("hour", "tweet3", 0, 210);  // \u8fd4\u56de [4]\u3002\u7edf\u8ba1\u9891\u7387\u662f\u6bcf\u5c0f\u65f6\uff083600 \u79d2\uff09\uff0c\u56e0\u6b64\u53ea\u6709\u4e00\u4e2a\u6709\u6548\u65f6\u95f4\u95f4\u9694 [0,211> - > 4 \u6761\u63a8\u6587\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u540c\u65f6\u8003\u8651 recordTweet \u548c getTweetCountsPerFrequency\uff0c\u6700\u591a\u6709 10000 \u6b21\u64cd\u4f5c\u3002
  • \n\t
  • 0 <= time, startTime, endTime <= 10^9
  • \n\t
  • 0 <= endTime - startTime <= 10^4
  • \n
\n", "tags_en": ["Design"], "tags_cn": ["\u8bbe\u8ba1"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class TweetCounts {\npublic:\n TweetCounts() {\n\n }\n \n void recordTweet(string tweetName, int time) {\n\n }\n \n vector getTweetCountsPerFrequency(string freq, string tweetName, int startTime, int endTime) {\n\n }\n};\n\n/**\n * Your TweetCounts object will be instantiated and called as such:\n * TweetCounts* obj = new TweetCounts();\n * obj->recordTweet(tweetName,time);\n * vector param_2 = obj->getTweetCountsPerFrequency(freq,tweetName,startTime,endTime);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class TweetCounts {\n\n public TweetCounts() {\n\n }\n \n public void recordTweet(String tweetName, int time) {\n\n }\n \n public List getTweetCountsPerFrequency(String freq, String tweetName, int startTime, int endTime) {\n\n }\n}\n\n/**\n * Your TweetCounts object will be instantiated and called as such:\n * TweetCounts obj = new TweetCounts();\n * obj.recordTweet(tweetName,time);\n * List param_2 = obj.getTweetCountsPerFrequency(freq,tweetName,startTime,endTime);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class TweetCounts(object):\n\n def __init__(self):\n\n\n def recordTweet(self, tweetName, time):\n \"\"\"\n :type tweetName: str\n :type time: int\n :rtype: None\n \"\"\"\n\n\n def getTweetCountsPerFrequency(self, freq, tweetName, startTime, endTime):\n \"\"\"\n :type freq: str\n :type tweetName: str\n :type startTime: int\n :type endTime: int\n :rtype: List[int]\n \"\"\"\n\n\n\n# Your TweetCounts object will be instantiated and called as such:\n# obj = TweetCounts()\n# obj.recordTweet(tweetName,time)\n# param_2 = obj.getTweetCountsPerFrequency(freq,tweetName,startTime,endTime)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class TweetCounts:\n\n def __init__(self):\n\n\n def recordTweet(self, tweetName: str, time: int) -> None:\n\n\n def getTweetCountsPerFrequency(self, freq: str, tweetName: str, startTime: int, endTime: int) -> List[int]:\n\n\n\n# Your TweetCounts object will be instantiated and called as such:\n# obj = TweetCounts()\n# obj.recordTweet(tweetName,time)\n# param_2 = obj.getTweetCountsPerFrequency(freq,tweetName,startTime,endTime)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} TweetCounts;\n\n\nTweetCounts* tweetCountsCreate() {\n \n}\n\nvoid tweetCountsRecordTweet(TweetCounts* obj, char * tweetName, int time) {\n \n}\n\nint* tweetCountsGetTweetCountsPerFrequency(TweetCounts* obj, char * freq, char * tweetName, int startTime, int endTime, int* retSize) {\n \n}\n\nvoid tweetCountsFree(TweetCounts* obj) {\n \n}\n\n/**\n * Your TweetCounts struct will be instantiated and called as such:\n * TweetCounts* obj = tweetCountsCreate();\n * tweetCountsRecordTweet(obj, tweetName, time);\n \n * int* param_2 = tweetCountsGetTweetCountsPerFrequency(obj, freq, tweetName, startTime, endTime, retSize);\n \n * tweetCountsFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class TweetCounts {\n\n public TweetCounts() {\n\n }\n \n public void RecordTweet(string tweetName, int time) {\n\n }\n \n public IList GetTweetCountsPerFrequency(string freq, string tweetName, int startTime, int endTime) {\n\n }\n}\n\n/**\n * Your TweetCounts object will be instantiated and called as such:\n * TweetCounts obj = new TweetCounts();\n * obj.RecordTweet(tweetName,time);\n * IList param_2 = obj.GetTweetCountsPerFrequency(freq,tweetName,startTime,endTime);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "\nvar TweetCounts = function() {\n\n};\n\n/** \n * @param {string} tweetName \n * @param {number} time\n * @return {void}\n */\nTweetCounts.prototype.recordTweet = function(tweetName, time) {\n\n};\n\n/** \n * @param {string} freq \n * @param {string} tweetName \n * @param {number} startTime \n * @param {number} endTime\n * @return {number[]}\n */\nTweetCounts.prototype.getTweetCountsPerFrequency = function(freq, tweetName, startTime, endTime) {\n\n};\n\n/**\n * Your TweetCounts object will be instantiated and called as such:\n * var obj = new TweetCounts()\n * obj.recordTweet(tweetName,time)\n * var param_2 = obj.getTweetCountsPerFrequency(freq,tweetName,startTime,endTime)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class TweetCounts\n def initialize()\n\n end\n\n\n=begin\n :type tweet_name: String\n :type time: Integer\n :rtype: Void\n=end\n def record_tweet(tweet_name, time)\n\n end\n\n\n=begin\n :type freq: String\n :type tweet_name: String\n :type start_time: Integer\n :type end_time: Integer\n :rtype: Integer[]\n=end\n def get_tweet_counts_per_frequency(freq, tweet_name, start_time, end_time)\n\n end\n\n\nend\n\n# Your TweetCounts object will be instantiated and called as such:\n# obj = TweetCounts.new()\n# obj.record_tweet(tweet_name, time)\n# param_2 = obj.get_tweet_counts_per_frequency(freq, tweet_name, start_time, end_time)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass TweetCounts {\n\n init() {\n\n }\n \n func recordTweet(_ tweetName: String, _ time: Int) {\n\n }\n \n func getTweetCountsPerFrequency(_ freq: String, _ tweetName: String, _ startTime: Int, _ endTime: Int) -> [Int] {\n\n }\n}\n\n/**\n * Your TweetCounts object will be instantiated and called as such:\n * let obj = TweetCounts()\n * obj.recordTweet(tweetName, time)\n * let ret_2: [Int] = obj.getTweetCountsPerFrequency(freq, tweetName, startTime, endTime)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type TweetCounts struct {\n\n}\n\n\nfunc Constructor() TweetCounts {\n\n}\n\n\nfunc (this *TweetCounts) RecordTweet(tweetName string, time int) {\n\n}\n\n\nfunc (this *TweetCounts) GetTweetCountsPerFrequency(freq string, tweetName string, startTime int, endTime int) []int {\n\n}\n\n\n/**\n * Your TweetCounts object will be instantiated and called as such:\n * obj := Constructor();\n * obj.RecordTweet(tweetName,time);\n * param_2 := obj.GetTweetCountsPerFrequency(freq,tweetName,startTime,endTime);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class TweetCounts() {\n\n def recordTweet(tweetName: String, time: Int) {\n\n }\n\n def getTweetCountsPerFrequency(freq: String, tweetName: String, startTime: Int, endTime: Int): List[Int] = {\n\n }\n\n}\n\n/**\n * Your TweetCounts object will be instantiated and called as such:\n * var obj = new TweetCounts()\n * obj.recordTweet(tweetName,time)\n * var param_2 = obj.getTweetCountsPerFrequency(freq,tweetName,startTime,endTime)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class TweetCounts() {\n\n fun recordTweet(tweetName: String, time: Int) {\n\n }\n\n fun getTweetCountsPerFrequency(freq: String, tweetName: String, startTime: Int, endTime: Int): List {\n\n }\n\n}\n\n/**\n * Your TweetCounts object will be instantiated and called as such:\n * var obj = TweetCounts()\n * obj.recordTweet(tweetName,time)\n * var param_2 = obj.getTweetCountsPerFrequency(freq,tweetName,startTime,endTime)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct TweetCounts {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl TweetCounts {\n\n fn new() -> Self {\n\n }\n \n fn record_tweet(&self, tweet_name: String, time: i32) {\n\n }\n \n fn get_tweet_counts_per_frequency(&self, freq: String, tweet_name: String, start_time: i32, end_time: i32) -> Vec {\n\n }\n}\n\n/**\n * Your TweetCounts object will be instantiated and called as such:\n * let obj = TweetCounts::new();\n * obj.record_tweet(tweetName, time);\n * let ret_2: Vec = obj.get_tweet_counts_per_frequency(freq, tweetName, startTime, endTime);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class TweetCounts {\n /**\n */\n function __construct() {\n\n }\n\n /**\n * @param String $tweetName\n * @param Integer $time\n * @return NULL\n */\n function recordTweet($tweetName, $time) {\n\n }\n\n /**\n * @param String $freq\n * @param String $tweetName\n * @param Integer $startTime\n * @param Integer $endTime\n * @return Integer[]\n */\n function getTweetCountsPerFrequency($freq, $tweetName, $startTime, $endTime) {\n\n }\n}\n\n/**\n * Your TweetCounts object will be instantiated and called as such:\n * $obj = TweetCounts();\n * $obj->recordTweet($tweetName, $time);\n * $ret_2 = $obj->getTweetCountsPerFrequency($freq, $tweetName, $startTime, $endTime);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class TweetCounts {\n constructor() {\n\n }\n\n recordTweet(tweetName: string, time: number): void {\n\n }\n\n getTweetCountsPerFrequency(freq: string, tweetName: string, startTime: number, endTime: number): number[] {\n\n }\n}\n\n/**\n * Your TweetCounts object will be instantiated and called as such:\n * var obj = new TweetCounts()\n * obj.recordTweet(tweetName,time)\n * var param_2 = obj.getTweetCountsPerFrequency(freq,tweetName,startTime,endTime)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define tweet-counts%\n (class object%\n (super-new)\n (init-field)\n \n ; record-tweet : string? exact-integer? -> void?\n (define/public (record-tweet tweetName time)\n\n )\n ; get-tweet-counts-per-frequency : string? string? exact-integer? exact-integer? -> (listof exact-integer?)\n (define/public (get-tweet-counts-per-frequency freq tweetName startTime endTime)\n\n )))\n\n;; Your tweet-counts% object will be instantiated and called as such:\n;; (define obj (new tweet-counts%))\n;; (send obj record-tweet tweet-name time)\n;; (define param_2 (send obj get-tweet-counts-per-frequency freq tweet-name start-time end-time))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1348](https://leetcode-cn.com/problems/tweet-counts-per-frequency)", "[\u63a8\u6587\u8ba1\u6570](/solution/1300-1399/1348.Tweet%20Counts%20Per%20Frequency/README.md)", "`\u8bbe\u8ba1`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1348](https://leetcode.com/problems/tweet-counts-per-frequency)", "[Tweet Counts Per Frequency](/solution/1300-1399/1348.Tweet%20Counts%20Per%20Frequency/README_EN.md)", "`Design`", "Medium", ""]}, {"question_id": "1469", "frontend_question_id": "1347", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-number-of-steps-to-make-two-strings-anagram", "url_en": "https://leetcode.com/problems/minimum-number-of-steps-to-make-two-strings-anagram", "relative_path_cn": "/solution/1300-1399/1347.Minimum%20Number%20of%20Steps%20to%20Make%20Two%20Strings%20Anagram/README.md", "relative_path_en": "/solution/1300-1399/1347.Minimum%20Number%20of%20Steps%20to%20Make%20Two%20Strings%20Anagram/README_EN.md", "title_cn": "\u5236\u9020\u5b57\u6bcd\u5f02\u4f4d\u8bcd\u7684\u6700\u5c0f\u6b65\u9aa4\u6570", "title_en": "Minimum Number of Steps to Make Two Strings Anagram", "question_title_slug": "minimum-number-of-steps-to-make-two-strings-anagram", "content_en": "

Given two equal-size strings s and t. In one step you can choose any character of t and replace it with another character.

\n\n

Return the minimum number of steps to make t an anagram of s.

\n\n

An Anagram of a string is a string that contains the same characters with a different (or the same) ordering.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "bab", t = "aba"\nOutput: 1\nExplanation: Replace the first 'a' in t with b, t = "bba" which is anagram of s.\n
\n\n

Example 2:

\n\n
\nInput: s = "leetcode", t = "practice"\nOutput: 5\nExplanation: Replace 'p', 'r', 'a', 'i' and 'c' from t with proper characters to make t anagram of s.\n
\n\n

Example 3:

\n\n
\nInput: s = "anagram", t = "mangaar"\nOutput: 0\nExplanation: "anagram" and "mangaar" are anagrams. \n
\n\n

Example 4:

\n\n
\nInput: s = "xxyyzz", t = "xxyyzz"\nOutput: 0\n
\n\n

Example 5:

\n\n
\nInput: s = "friend", t = "family"\nOutput: 4\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 50000
  • \n\t
  • s.length == t.length
  • \n\t
  • s and t contain lower-case English letters only.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e24\u4e2a\u957f\u5ea6\u76f8\u7b49\u7684\u5b57\u7b26\u4e32 s \u548c t\u3002\u6bcf\u4e00\u4e2a\u6b65\u9aa4\u4e2d\uff0c\u4f60\u53ef\u4ee5\u9009\u62e9\u5c06 t \u4e2d\u7684 \u4efb\u4e00\u5b57\u7b26 \u66ff\u6362\u4e3a \u53e6\u4e00\u4e2a\u5b57\u7b26\u3002

\n\n

\u8fd4\u56de\u4f7f t \u6210\u4e3a s \u7684\u5b57\u6bcd\u5f02\u4f4d\u8bcd\u7684\u6700\u5c0f\u6b65\u9aa4\u6570\u3002

\n\n

\u5b57\u6bcd\u5f02\u4f4d\u8bcd \u6307\u5b57\u6bcd\u76f8\u540c\uff0c\u4f46\u6392\u5217\u4e0d\u540c\uff08\u4e5f\u53ef\u80fd\u76f8\u540c\uff09\u7684\u5b57\u7b26\u4e32\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u51fa\uff1as = "bab", t = "aba"\n\u8f93\u51fa\uff1a1\n\u63d0\u793a\uff1a\u7528 'b' \u66ff\u6362 t \u4e2d\u7684\u7b2c\u4e00\u4e2a 'a'\uff0ct = "bba" \u662f s \u7684\u4e00\u4e2a\u5b57\u6bcd\u5f02\u4f4d\u8bcd\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u51fa\uff1as = "leetcode", t = "practice"\n\u8f93\u51fa\uff1a5\n\u63d0\u793a\uff1a\u7528\u5408\u9002\u7684\u5b57\u7b26\u66ff\u6362 t \u4e2d\u7684 'p', 'r', 'a', 'i' \u548c 'c'\uff0c\u4f7f t \u53d8\u6210 s \u7684\u5b57\u6bcd\u5f02\u4f4d\u8bcd\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u51fa\uff1as = "anagram", t = "mangaar"\n\u8f93\u51fa\uff1a0\n\u63d0\u793a\uff1a"anagram" \u548c "mangaar" \u672c\u8eab\u5c31\u662f\u4e00\u7ec4\u5b57\u6bcd\u5f02\u4f4d\u8bcd\u3002 \n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u51fa\uff1as = "xxyyzz", t = "xxyyzz"\n\u8f93\u51fa\uff1a0\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u51fa\uff1as = "friend", t = "family"\n\u8f93\u51fa\uff1a4\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length <= 50000
  • \n\t
  • s.length == t.length
  • \n\t
  • s \u548c t \u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minSteps(string s, string t) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minSteps(String s, String t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minSteps(self, s, t):\n \"\"\"\n :type s: str\n :type t: str\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minSteps(self, s: str, t: str) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minSteps(char * s, char * t){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinSteps(string s, string t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string} t\n * @return {number}\n */\nvar minSteps = function(s, t) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String} t\n# @return {Integer}\ndef min_steps(s, t)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minSteps(_ s: String, _ t: String) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minSteps(s string, t string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minSteps(s: String, t: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minSteps(s: String, t: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_steps(s: String, t: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String $t\n * @return Integer\n */\n function minSteps($s, $t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minSteps(s: string, t: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-steps s t)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1347](https://leetcode-cn.com/problems/minimum-number-of-steps-to-make-two-strings-anagram)", "[\u5236\u9020\u5b57\u6bcd\u5f02\u4f4d\u8bcd\u7684\u6700\u5c0f\u6b65\u9aa4\u6570](/solution/1300-1399/1347.Minimum%20Number%20of%20Steps%20to%20Make%20Two%20Strings%20Anagram/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1347](https://leetcode.com/problems/minimum-number-of-steps-to-make-two-strings-anagram)", "[Minimum Number of Steps to Make Two Strings Anagram](/solution/1300-1399/1347.Minimum%20Number%20of%20Steps%20to%20Make%20Two%20Strings%20Anagram/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "1468", "frontend_question_id": "1346", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/check-if-n-and-its-double-exist", "url_en": "https://leetcode.com/problems/check-if-n-and-its-double-exist", "relative_path_cn": "/solution/1300-1399/1346.Check%20If%20N%20and%20Its%20Double%20Exist/README.md", "relative_path_en": "/solution/1300-1399/1346.Check%20If%20N%20and%20Its%20Double%20Exist/README_EN.md", "title_cn": "\u68c0\u67e5\u6574\u6570\u53ca\u5176\u4e24\u500d\u6570\u662f\u5426\u5b58\u5728", "title_en": "Check If N and Its Double Exist", "question_title_slug": "check-if-n-and-its-double-exist", "content_en": "

Given an array arr of integers, check if there exists two integers N and M such that N is the double of M ( i.e. N = 2 * M).

\n\n

More formally check if there exists two indices i and j such that :

\n\n
    \n\t
  • i != j
  • \n\t
  • 0 <= i, j < arr.length
  • \n\t
  • arr[i] == 2 * arr[j]
  • \n
\n\n

 

\n

Example 1:

\n\n
\nInput: arr = [10,2,5,3]\nOutput: true\nExplanation: N = 10 is the double of M = 5,that is, 10 = 2 * 5.\n
\n\n

Example 2:

\n\n
\nInput: arr = [7,1,14,11]\nOutput: true\nExplanation: N = 14 is the double of M = 7,that is, 14 = 2 * 7.\n
\n\n

Example 3:

\n\n
\nInput: arr = [3,1,7,11]\nOutput: false\nExplanation: In this case does not exist N and M, such that N = 2 * M.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= arr.length <= 500
  • \n\t
  • -10^3 <= arr[i] <= 10^3
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr\uff0c\u8bf7\u4f60\u68c0\u67e5\u662f\u5426\u5b58\u5728\u4e24\u4e2a\u6574\u6570 N \u548c M\uff0c\u6ee1\u8db3 N \u662f M \u7684\u4e24\u500d\uff08\u5373\uff0cN = 2 * M\uff09\u3002

\n\n

\u66f4\u6b63\u5f0f\u5730\uff0c\u68c0\u67e5\u662f\u5426\u5b58\u5728\u4e24\u4e2a\u4e0b\u6807 i \u548c j \u6ee1\u8db3\uff1a

\n\n
    \n\t
  • i != j
  • \n\t
  • 0 <= i, j < arr.length
  • \n\t
  • arr[i] == 2 * arr[j]
  • \n
\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aarr = [10,2,5,3]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1aN = 10 \u662f M = 5 \u7684\u4e24\u500d\uff0c\u5373 10 = 2 * 5 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aarr = [7,1,14,11]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1aN = 14 \u662f M = 7 \u7684\u4e24\u500d\uff0c\u5373 14 = 2 * 7 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aarr = [3,1,7,11]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u5728\u8be5\u60c5\u51b5\u4e0b\u4e0d\u5b58\u5728 N \u548c M \u6ee1\u8db3 N = 2 * M \u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= arr.length <= 500
  • \n\t
  • -10^3 <= arr[i] <= 10^3
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool checkIfExist(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean checkIfExist(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def checkIfExist(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def checkIfExist(self, arr: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool checkIfExist(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CheckIfExist(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {boolean}\n */\nvar checkIfExist = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Boolean}\ndef check_if_exist(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func checkIfExist(_ arr: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func checkIfExist(arr []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def checkIfExist(arr: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun checkIfExist(arr: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn check_if_exist(arr: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Boolean\n */\n function checkIfExist($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function checkIfExist(arr: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (check-if-exist arr)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1346](https://leetcode-cn.com/problems/check-if-n-and-its-double-exist)", "[\u68c0\u67e5\u6574\u6570\u53ca\u5176\u4e24\u500d\u6570\u662f\u5426\u5b58\u5728](/solution/1300-1399/1346.Check%20If%20N%20and%20Its%20Double%20Exist/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1346](https://leetcode.com/problems/check-if-n-and-its-double-exist)", "[Check If N and Its Double Exist](/solution/1300-1399/1346.Check%20If%20N%20and%20Its%20Double%20Exist/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1467", "frontend_question_id": "1336", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/number-of-transactions-per-visit", "url_en": "https://leetcode.com/problems/number-of-transactions-per-visit", "relative_path_cn": "/solution/1300-1399/1336.Number%20of%20Transactions%20per%20Visit/README.md", "relative_path_en": "/solution/1300-1399/1336.Number%20of%20Transactions%20per%20Visit/README_EN.md", "title_cn": "\u6bcf\u6b21\u8bbf\u95ee\u7684\u4ea4\u6613\u6b21\u6570", "title_en": "Number of Transactions per Visit", "question_title_slug": "number-of-transactions-per-visit", "content_en": "

Table: Visits

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| user_id       | int     |\n| visit_date    | date    |\n+---------------+---------+\n(user_id, visit_date) is the primary key for this table.\nEach row of this table indicates that user_id has visited the bank in visit_date.\n
\n\n

 

\n\n

Table: Transactions

\n\n
\n+------------------+---------+\n| Column Name      | Type    |\n+------------------+---------+\n| user_id          | int     |\n| transaction_date | date    |\n| amount           | int     |\n+------------------+---------+\nThere is no primary key for this table, it may contain duplicates.\nEach row of this table indicates that user_id has done a transaction of amount in transaction_date.\nIt is guaranteed that the user has visited the bank in the transaction_date.(i.e The Visits table contains (user_id, transaction_date) in one row)\n
\n\n

 

\n\n

A bank wants to draw a chart of the number of transactions bank visitors did in one visit to the bank and the corresponding number of visitors who have done this number of transaction in one visit.

\n\n

Write an SQL query to find how many users visited the bank and didn't do any transactions, how many visited the bank and did one transaction and so on.

\n\n

The result table will contain two columns:

\n\n
    \n\t
  • transactions_count which is the number of transactions done in one visit.
  • \n\t
  • visits_count which is the corresponding number of users who did transactions_count in one visit to the bank.
  • \n
\n\n

transactions_count should take all values from 0 to max(transactions_count) done by one or more users.

\n\n

Order the result table by transactions_count.

\n\n

The query result format is in the following example:

\n\n
\nVisits table:\n+---------+------------+\n| user_id | visit_date |\n+---------+------------+\n| 1       | 2020-01-01 |\n| 2       | 2020-01-02 |\n| 12      | 2020-01-01 |\n| 19      | 2020-01-03 |\n| 1       | 2020-01-02 |\n| 2       | 2020-01-03 |\n| 1       | 2020-01-04 |\n| 7       | 2020-01-11 |\n| 9       | 2020-01-25 |\n| 8       | 2020-01-28 |\n+---------+------------+\nTransactions table:\n+---------+------------------+--------+\n| user_id | transaction_date | amount |\n+---------+------------------+--------+\n| 1       | 2020-01-02       | 120    |\n| 2       | 2020-01-03       | 22     |\n| 7       | 2020-01-11       | 232    |\n| 1       | 2020-01-04       | 7      |\n| 9       | 2020-01-25       | 33     |\n| 9       | 2020-01-25       | 66     |\n| 8       | 2020-01-28       | 1      |\n| 9       | 2020-01-25       | 99     |\n+---------+------------------+--------+\nResult table:\n+--------------------+--------------+\n| transactions_count | visits_count |\n+--------------------+--------------+\n| 0                  | 4            |\n| 1                  | 5            |\n| 2                  | 0            |\n| 3                  | 1            |\n+--------------------+--------------+\n* For transactions_count = 0, The visits (1, "2020-01-01"), (2, "2020-01-02"), (12, "2020-01-01") and (19, "2020-01-03") did no transactions so visits_count = 4.\n* For transactions_count = 1, The visits (2, "2020-01-03"), (7, "2020-01-11"), (8, "2020-01-28"), (1, "2020-01-02") and (1, "2020-01-04") did one transaction so visits_count = 5.\n* For transactions_count = 2, No customers visited the bank and did two transactions so visits_count = 0.\n* For transactions_count = 3, The visit (9, "2020-01-25") did three transactions so visits_count = 1.\n* For transactions_count >= 4, No customers visited the bank and did more than three transactions so we will stop at transactions_count = 3\n\nThe chart drawn for this example is as follows:\n\"\"\n
\n", "content_cn": "

\u8868: Visits

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| user_id       | int     |\n| visit_date    | date    |\n+---------------+---------+\n(user_id, visit_date) \u662f\u8be5\u8868\u7684\u4e3b\u952e\n\u8be5\u8868\u7684\u6bcf\u884c\u8868\u793a user_id \u5728 visit_date \u8bbf\u95ee\u4e86\u94f6\u884c\n
\n\n

 

\n\n

\u8868: Transactions

\n\n
\n+------------------+---------+\n| Column Name      | Type    |\n+------------------+---------+\n| user_id          | int     |\n| transaction_date | date    |\n| amount           | int     |\n+------------------+---------+\n\u8be5\u8868\u6ca1\u6709\u4e3b\u952e\uff0c\u6240\u4ee5\u53ef\u80fd\u6709\u91cd\u590d\u884c\n\u8be5\u8868\u7684\u6bcf\u4e00\u884c\u8868\u793a user_id \u5728 transaction_date \u5b8c\u6210\u4e86\u4e00\u7b14 amount \u6570\u989d\u7684\u4ea4\u6613\n\u53ef\u4ee5\u4fdd\u8bc1\u7528\u6237 (user) \u5728 transaction_date \u8bbf\u95ee\u4e86\u94f6\u884c (\u4e5f\u5c31\u662f\u8bf4 Visits \u8868\u5305\u542b (user_id, transaction_date) \u884c)\n
\n\n

 

\n\n

\u94f6\u884c\u60f3\u8981\u5f97\u5230\u94f6\u884c\u5ba2\u6237\u5728\u4e00\u6b21\u8bbf\u95ee\u65f6\u7684\u4ea4\u6613\u6b21\u6570\u548c\u76f8\u5e94\u7684\u5728\u4e00\u6b21\u8bbf\u95ee\u65f6\u8be5\u4ea4\u6613\u6b21\u6570\u7684\u5ba2\u6237\u6570\u91cf\u7684\u56fe\u8868

\n\n

\u5199\u4e00\u6761 SQL \u67e5\u8be2\u591a\u5c11\u5ba2\u6237\u8bbf\u95ee\u4e86\u94f6\u884c\u4f46\u6ca1\u6709\u8fdb\u884c\u4efb\u4f55\u4ea4\u6613\uff0c\u591a\u5c11\u5ba2\u6237\u8bbf\u95ee\u4e86\u94f6\u884c\u8fdb\u884c\u4e86\u4e00\u6b21\u4ea4\u6613\u7b49\u7b49

\n\n

\u7ed3\u679c\u5305\u542b\u4e24\u5217\uff1a

\n\n
    \n\t
  • transactions_count\uff1a \u5ba2\u6237\u5728\u4e00\u6b21\u8bbf\u95ee\u4e2d\u7684\u4ea4\u6613\u6b21\u6570
  • \n\t
  • visits_count\uff1a \u5728 transactions_count \u4ea4\u6613\u6b21\u6570\u4e0b\u76f8\u5e94\u7684\u4e00\u6b21\u8bbf\u95ee\u65f6\u7684\u5ba2\u6237\u6570\u91cf
  • \n
\n\n

transactions_count \u7684\u503c\u4ece 0 \u5230\u6240\u6709\u7528\u6237\u4e00\u6b21\u8bbf\u95ee\u4e2d\u7684 max(transactions_count) 

\n\n

\u6309 transactions_count \u6392\u5e8f

\n\n

\u4e0b\u9762\u662f\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u7684\u4f8b\u5b50\uff1a

\n\n
\nVisits \u8868:\n+---------+------------+\n| user_id | visit_date |\n+---------+------------+\n| 1       | 2020-01-01 |\n| 2       | 2020-01-02 |\n| 12      | 2020-01-01 |\n| 19      | 2020-01-03 |\n| 1       | 2020-01-02 |\n| 2       | 2020-01-03 |\n| 1       | 2020-01-04 |\n| 7       | 2020-01-11 |\n| 9       | 2020-01-25 |\n| 8       | 2020-01-28 |\n+---------+------------+\nTransactions \u8868:\n+---------+------------------+--------+\n| user_id | transaction_date | amount |\n+---------+------------------+--------+\n| 1       | 2020-01-02       | 120    |\n| 2       | 2020-01-03       | 22     |\n| 7       | 2020-01-11       | 232    |\n| 1       | 2020-01-04       | 7      |\n| 9       | 2020-01-25       | 33     |\n| 9       | 2020-01-25       | 66     |\n| 8       | 2020-01-28       | 1      |\n| 9       | 2020-01-25       | 99     |\n+---------+------------------+--------+\n\u7ed3\u679c\u8868:\n+--------------------+--------------+\n| transactions_count | visits_count |\n+--------------------+--------------+\n| 0                  | 4            |\n| 1                  | 5            |\n| 2                  | 0            |\n| 3                  | 1            |\n+--------------------+--------------+\n* \u5bf9\u4e8e transactions_count = 0, visits \u4e2d (1, "2020-01-01"), (2, "2020-01-02"), (12, "2020-01-01") \u548c (19, "2020-01-03") \u6ca1\u6709\u8fdb\u884c\u4ea4\u6613\uff0c\u6240\u4ee5 visits_count = 4 \u3002\n* \u5bf9\u4e8e transactions_count = 1, visits \u4e2d (2, "2020-01-03"), (7, "2020-01-11"), (8, "2020-01-28"), (1, "2020-01-02") \u548c (1, "2020-01-04") \u8fdb\u884c\u4e86\u4e00\u6b21\u4ea4\u6613\uff0c\u6240\u4ee5 visits_count = 5 \u3002\n* \u5bf9\u4e8e transactions_count = 2, \u6ca1\u6709\u5ba2\u6237\u8bbf\u95ee\u94f6\u884c\u8fdb\u884c\u4e86\u4e24\u6b21\u4ea4\u6613\uff0c\u6240\u4ee5 visits_count = 0 \u3002\n* \u5bf9\u4e8e transactions_count = 3, visits \u4e2d (9, "2020-01-25") \u8fdb\u884c\u4e86\u4e09\u6b21\u4ea4\u6613\uff0c\u6240\u4ee5 visits_count = 1 \u3002\n* \u5bf9\u4e8e transactions_count >= 4, \u6ca1\u6709\u5ba2\u6237\u8bbf\u95ee\u94f6\u884c\u8fdb\u884c\u4e86\u8d85\u8fc73\u6b21\u4ea4\u6613\uff0c\u6240\u4ee5\u6211\u4eec\u505c\u6b62\u5728 transactions_count = 3 \u3002\n\n\u5982\u4e0b\u662f\u8fd9\u4e2a\u4f8b\u5b50\u7684\u56fe\u8868\uff1a\n\"\"\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1336](https://leetcode-cn.com/problems/number-of-transactions-per-visit)", "[\u6bcf\u6b21\u8bbf\u95ee\u7684\u4ea4\u6613\u6b21\u6570](/solution/1300-1399/1336.Number%20of%20Transactions%20per%20Visit/README.md)", "", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1336](https://leetcode.com/problems/number-of-transactions-per-visit)", "[Number of Transactions per Visit](/solution/1300-1399/1336.Number%20of%20Transactions%20per%20Visit/README_EN.md)", "", "Hard", "\ud83d\udd12"]}, {"question_id": "1466", "frontend_question_id": "1340", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/jump-game-v", "url_en": "https://leetcode.com/problems/jump-game-v", "relative_path_cn": "/solution/1300-1399/1340.Jump%20Game%20V/README.md", "relative_path_en": "/solution/1300-1399/1340.Jump%20Game%20V/README_EN.md", "title_cn": "\u8df3\u8dc3\u6e38\u620f V", "title_en": "Jump Game V", "question_title_slug": "jump-game-v", "content_en": "

Given an array of integers arr and an integer d. In one step you can jump from index i to index:

\r\n\r\n
    \r\n\t
  • i + x where: i + x < arr.length and 0 < x <= d.
  • \r\n\t
  • i - x where: i - x >= 0 and 0 < x <= d.
  • \r\n
\r\n\r\n

In addition, you can only jump from index i to index j if arr[i] > arr[j] and arr[i] > arr[k] for all indices k between i and j (More formally min(i, j) < k < max(i, j)).

\r\n\r\n

You can choose any index of the array and start jumping. Return the maximum number of indices you can visit.

\r\n\r\n

Notice that you can not jump outside of the array at any time.

\r\n\r\n

 

\r\n

Example 1:

\r\n\"\"\r\n
\r\nInput: arr = [6,4,14,6,8,13,9,7,10,6,12], d = 2\r\nOutput: 4\r\nExplanation: You can start at index 10. You can jump 10 --> 8 --> 6 --> 7 as shown.\r\nNote that if you start at index 6 you can only jump to index 7. You cannot jump to index 5 because 13 > 9. You cannot jump to index 4 because index 5 is between index 4 and 6 and 13 > 9.\r\nSimilarly You cannot jump from index 3 to index 2 or index 1.\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: arr = [3,3,3,3,3], d = 3\r\nOutput: 1\r\nExplanation: You can start at any index. You always cannot jump to any index.\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: arr = [7,6,5,4,3,2,1], d = 1\r\nOutput: 7\r\nExplanation: Start at index 0. You can visit all the indicies. \r\n
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: arr = [7,1,7,1,7,1], d = 2\r\nOutput: 2\r\n
\r\n\r\n

Example 5:

\r\n\r\n
\r\nInput: arr = [66], d = 1\r\nOutput: 1\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= arr.length <= 1000
  • \r\n\t
  • 1 <= arr[i] <= 10^5
  • \r\n\t
  • 1 <= d <= arr.length
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr \u548c\u4e00\u4e2a\u6574\u6570 d \u3002\u6bcf\u4e00\u6b65\u4f60\u53ef\u4ee5\u4ece\u4e0b\u6807 i \u8df3\u5230\uff1a

\n\n
    \n\t
  • i + x \uff0c\u5176\u4e2d i + x < arr.length \u4e14 0 < x <= d \u3002
  • \n\t
  • i - x \uff0c\u5176\u4e2d i - x >= 0 \u4e14 0 < x <= d \u3002
  • \n
\n\n

\u9664\u6b64\u4ee5\u5916\uff0c\u4f60\u4ece\u4e0b\u6807 i \u8df3\u5230\u4e0b\u6807 j \u9700\u8981\u6ee1\u8db3\uff1aarr[i] > arr[j] \u4e14 arr[i] > arr[k] \uff0c\u5176\u4e2d\u4e0b\u6807 k \u662f\u6240\u6709 i \u5230 j \u4e4b\u95f4\u7684\u6570\u5b57\uff08\u66f4\u6b63\u5f0f\u7684\uff0cmin(i, j) < k < max(i, j)\uff09\u3002

\n\n

\u4f60\u53ef\u4ee5\u9009\u62e9\u6570\u7ec4\u7684\u4efb\u610f\u4e0b\u6807\u5f00\u59cb\u8df3\u8dc3\u3002\u8bf7\u4f60\u8fd4\u56de\u4f60 \u6700\u591a \u53ef\u4ee5\u8bbf\u95ee\u591a\u5c11\u4e2a\u4e0b\u6807\u3002

\n\n

\u8bf7\u6ce8\u610f\uff0c\u4efb\u4f55\u65f6\u523b\u4f60\u90fd\u4e0d\u80fd\u8df3\u5230\u6570\u7ec4\u7684\u5916\u9762\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1aarr = [6,4,14,6,8,13,9,7,10,6,12], d = 2\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u4ece\u4e0b\u6807 10 \u51fa\u53d1\uff0c\u7136\u540e\u5982\u4e0a\u56fe\u4f9d\u6b21\u7ecf\u8fc7 10 --> 8 --> 6 --> 7 \u3002\n\u6ce8\u610f\uff0c\u5982\u679c\u4f60\u4ece\u4e0b\u6807 6 \u5f00\u59cb\uff0c\u4f60\u53ea\u80fd\u8df3\u5230\u4e0b\u6807 7 \u5904\u3002\u4f60\u4e0d\u80fd\u8df3\u5230\u4e0b\u6807 5 \u5904\u56e0\u4e3a 13 > 9 \u3002\u4f60\u4e5f\u4e0d\u80fd\u8df3\u5230\u4e0b\u6807 4 \u5904\uff0c\u56e0\u4e3a\u4e0b\u6807 5 \u5728\u4e0b\u6807 4 \u548c 6 \u4e4b\u95f4\u4e14 13 > 9 \u3002\n\u7c7b\u4f3c\u7684\uff0c\u4f60\u4e0d\u80fd\u4ece\u4e0b\u6807 3 \u5904\u8df3\u5230\u4e0b\u6807 2 \u6216\u8005\u4e0b\u6807 1 \u5904\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aarr = [3,3,3,3,3], d = 3\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u4ece\u4efb\u610f\u4e0b\u6807\u5904\u5f00\u59cb\u4e14\u4f60\u6c38\u8fdc\u65e0\u6cd5\u8df3\u5230\u4efb\u4f55\u5176\u4ed6\u5750\u6807\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aarr = [7,6,5,4,3,2,1], d = 1\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\u4ece\u4e0b\u6807 0 \u5904\u5f00\u59cb\uff0c\u4f60\u53ef\u4ee5\u6309\u7167\u6570\u503c\u4ece\u5927\u5230\u5c0f\uff0c\u8bbf\u95ee\u6240\u6709\u7684\u4e0b\u6807\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1aarr = [7,1,7,1,7,1], d = 2\n\u8f93\u51fa\uff1a2\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1aarr = [66], d = 1\n\u8f93\u51fa\uff1a1\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= arr.length <= 1000
  • \n\t
  • 1 <= arr[i] <= 10^5
  • \n\t
  • 1 <= d <= arr.length
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxJumps(vector& arr, int d) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxJumps(int[] arr, int d) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxJumps(self, arr, d):\n \"\"\"\n :type arr: List[int]\n :type d: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxJumps(self, arr: List[int], d: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxJumps(int* arr, int arrSize, int d){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxJumps(int[] arr, int d) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @param {number} d\n * @return {number}\n */\nvar maxJumps = function(arr, d) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @param {Integer} d\n# @return {Integer}\ndef max_jumps(arr, d)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxJumps(_ arr: [Int], _ d: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxJumps(arr []int, d int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxJumps(arr: Array[Int], d: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxJumps(arr: IntArray, d: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_jumps(arr: Vec, d: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @param Integer $d\n * @return Integer\n */\n function maxJumps($arr, $d) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxJumps(arr: number[], d: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-jumps arr d)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1340](https://leetcode-cn.com/problems/jump-game-v)", "[\u8df3\u8dc3\u6e38\u620f V](/solution/1300-1399/1340.Jump%20Game%20V/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1340](https://leetcode.com/problems/jump-game-v)", "[Jump Game V](/solution/1300-1399/1340.Jump%20Game%20V/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1465", "frontend_question_id": "1339", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-product-of-splitted-binary-tree", "url_en": "https://leetcode.com/problems/maximum-product-of-splitted-binary-tree", "relative_path_cn": "/solution/1300-1399/1339.Maximum%20Product%20of%20Splitted%20Binary%20Tree/README.md", "relative_path_en": "/solution/1300-1399/1339.Maximum%20Product%20of%20Splitted%20Binary%20Tree/README_EN.md", "title_cn": "\u5206\u88c2\u4e8c\u53c9\u6811\u7684\u6700\u5927\u4e58\u79ef", "title_en": "Maximum Product of Splitted Binary Tree", "question_title_slug": "maximum-product-of-splitted-binary-tree", "content_en": "

Given a binary tree root. Split the binary tree into two subtrees by removing 1 edge such that the product of the sums of the subtrees are maximized.

\r\n\r\n

Since the answer may be too large, return it modulo 10^9 + 7.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n

\"\"

\r\n\r\n
\r\nInput: root = [1,2,3,4,5,6]\r\nOutput: 110\r\nExplanation: Remove the red edge and get 2 binary trees with sum 11 and 10. Their product is 110 (11*10)\r\n
\r\n\r\n

Example 2:

\r\n\r\n

\"\"

\r\n\r\n
\r\nInput: root = [1,null,2,3,4,null,null,5,6]\r\nOutput: 90\r\nExplanation:  Remove the red edge and get 2 binary trees with sum 15 and 6.Their product is 90 (15*6)\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: root = [2,3,9,10,7,8,6,5,4,11,1]\r\nOutput: 1025\r\n
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: root = [1,1]\r\nOutput: 1\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • Each tree has at most 50000 nodes and at least 2 nodes.
  • \r\n\t
  • Each node's value is between [1, 10000].
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u68f5\u4e8c\u53c9\u6811\uff0c\u5b83\u7684\u6839\u4e3a root \u3002\u8bf7\u4f60\u5220\u9664 1 \u6761\u8fb9\uff0c\u4f7f\u4e8c\u53c9\u6811\u5206\u88c2\u6210\u4e24\u68f5\u5b50\u6811\uff0c\u4e14\u5b83\u4eec\u5b50\u6811\u548c\u7684\u4e58\u79ef\u5c3d\u53ef\u80fd\u5927\u3002

\n\n

\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u4f1a\u5f88\u5927\uff0c\u8bf7\u4f60\u5c06\u7ed3\u679c\u5bf9 10^9 + 7 \u53d6\u6a21\u540e\u518d\u8fd4\u56de\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1aroot = [1,2,3,4,5,6]\n\u8f93\u51fa\uff1a110\n\u89e3\u91ca\uff1a\u5220\u9664\u7ea2\u8272\u7684\u8fb9\uff0c\u5f97\u5230 2 \u68f5\u5b50\u6811\uff0c\u548c\u5206\u522b\u4e3a 11 \u548c 10 \u3002\u5b83\u4eec\u7684\u4e58\u79ef\u662f 110 \uff0811*10\uff09\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1aroot = [1,null,2,3,4,null,null,5,6]\n\u8f93\u51fa\uff1a90\n\u89e3\u91ca\uff1a\u79fb\u9664\u7ea2\u8272\u7684\u8fb9\uff0c\u5f97\u5230 2 \u68f5\u5b50\u6811\uff0c\u548c\u5206\u522b\u662f 15 \u548c 6 \u3002\u5b83\u4eec\u7684\u4e58\u79ef\u4e3a 90 \uff0815*6\uff09\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aroot = [2,3,9,10,7,8,6,5,4,11,1]\n\u8f93\u51fa\uff1a1025\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1aroot = [1,1]\n\u8f93\u51fa\uff1a1\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u6bcf\u68f5\u6811\u6700\u591a\u6709 50000 \u4e2a\u8282\u70b9\uff0c\u4e14\u81f3\u5c11\u6709 2 \u4e2a\u8282\u70b9\u3002
  • \n\t
  • \u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u5728 [1, 10000] \u4e4b\u95f4\u3002
  • \n
\n", "tags_en": ["Tree", "Dynamic Programming"], "tags_cn": ["\u6811", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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 */\nclass Solution {\npublic:\n int maxProduct(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode(int x) { val = x; }\n * }\n */\nclass Solution {\n public int maxProduct(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution(object):\n def maxProduct(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution:\n def maxProduct(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint maxProduct(struct TreeNode* root){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int x) { val = x; }\n * }\n */\npublic class Solution {\n public int MaxProduct(TreeNode root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val) {\n * this.val = val;\n * this.left = this.right = null;\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar maxProduct = function(root) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val)\n# @val = val\n# @left, @right = nil, nil\n# end\n# end\n\n# @param {TreeNode} root\n# @return {Integer}\ndef max_product(root)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.left = nil\n * self.right = nil\n * }\n * }\n */\nclass Solution {\n func maxProduct(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc maxProduct(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(var _value: Int) {\n * var value: Int = _value\n * var left: TreeNode = null\n * var right: TreeNode = null\n * }\n */\nobject Solution {\n def maxProduct(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun maxProduct(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n// \n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn max_product(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($value) { $this->val = $value; }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function maxProduct($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction maxProduct(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (max-product root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1339](https://leetcode-cn.com/problems/maximum-product-of-splitted-binary-tree)", "[\u5206\u88c2\u4e8c\u53c9\u6811\u7684\u6700\u5927\u4e58\u79ef](/solution/1300-1399/1339.Maximum%20Product%20of%20Splitted%20Binary%20Tree/README.md)", "`\u6811`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1339](https://leetcode.com/problems/maximum-product-of-splitted-binary-tree)", "[Maximum Product of Splitted Binary Tree](/solution/1300-1399/1339.Maximum%20Product%20of%20Splitted%20Binary%20Tree/README_EN.md)", "`Tree`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "1464", "frontend_question_id": "1338", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reduce-array-size-to-the-half", "url_en": "https://leetcode.com/problems/reduce-array-size-to-the-half", "relative_path_cn": "/solution/1300-1399/1338.Reduce%20Array%20Size%20to%20The%20Half/README.md", "relative_path_en": "/solution/1300-1399/1338.Reduce%20Array%20Size%20to%20The%20Half/README_EN.md", "title_cn": "\u6570\u7ec4\u5927\u5c0f\u51cf\u534a", "title_en": "Reduce Array Size to The Half", "question_title_slug": "reduce-array-size-to-the-half", "content_en": "

Given an array arr.  You can choose a set of integers and remove all the occurrences of these integers in the array.

\r\n\r\n

Return the minimum size of the set so that at least half of the integers of the array are removed.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: arr = [3,3,3,3,5,5,5,2,2,7]\r\nOutput: 2\r\nExplanation: Choosing {3,7} will make the new array [5,5,5,2,2] which has size 5 (i.e equal to half of the size of the old array).\r\nPossible sets of size 2 are {3,5},{3,2},{5,2}.\r\nChoosing set {2,7} is not possible as it will make the new array [3,3,3,3,5,5,5] which has size greater than half of the size of the old array.\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: arr = [7,7,7,7,7,7]\r\nOutput: 1\r\nExplanation: The only possible set you can choose is {7}. This will make the new array empty.\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: arr = [1,9]\r\nOutput: 1\r\n
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: arr = [1000,1000,3,7]\r\nOutput: 1\r\n
\r\n\r\n

Example 5:

\r\n\r\n
\r\nInput: arr = [1,2,3,4,5,6,7,8,9,10]\r\nOutput: 5\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= arr.length <= 10^5
  • \r\n\t
  • arr.length is even.
  • \r\n\t
  • 1 <= arr[i] <= 10^5
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr\u3002\u4f60\u53ef\u4ee5\u4ece\u4e2d\u9009\u51fa\u4e00\u4e2a\u6574\u6570\u96c6\u5408\uff0c\u5e76\u5220\u9664\u8fd9\u4e9b\u6574\u6570\u5728\u6570\u7ec4\u4e2d\u7684\u6bcf\u6b21\u51fa\u73b0\u3002

\n\n

\u8fd4\u56de \u81f3\u5c11 \u80fd\u5220\u9664\u6570\u7ec4\u4e2d\u7684\u4e00\u534a\u6574\u6570\u7684\u6574\u6570\u96c6\u5408\u7684\u6700\u5c0f\u5927\u5c0f\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aarr = [3,3,3,3,5,5,5,2,2,7]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u9009\u62e9 {3,7} \u4f7f\u5f97\u7ed3\u679c\u6570\u7ec4\u4e3a [5,5,5,2,2]\u3001\u957f\u5ea6\u4e3a 5\uff08\u539f\u6570\u7ec4\u957f\u5ea6\u7684\u4e00\u534a\uff09\u3002\n\u5927\u5c0f\u4e3a 2 \u7684\u53ef\u884c\u96c6\u5408\u6709 {3,5},{3,2},{5,2}\u3002\n\u9009\u62e9 {2,7} \u662f\u4e0d\u53ef\u884c\u7684\uff0c\u5b83\u7684\u7ed3\u679c\u6570\u7ec4\u4e3a [3,3,3,3,5,5,5]\uff0c\u65b0\u6570\u7ec4\u957f\u5ea6\u5927\u4e8e\u539f\u6570\u7ec4\u7684\u4e8c\u5206\u4e4b\u4e00\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aarr = [7,7,7,7,7,7]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u6211\u4eec\u53ea\u80fd\u9009\u62e9\u96c6\u5408 {7}\uff0c\u7ed3\u679c\u6570\u7ec4\u4e3a\u7a7a\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aarr = [1,9]\n\u8f93\u51fa\uff1a1\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1aarr = [1000,1000,3,7]\n\u8f93\u51fa\uff1a1\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1aarr = [1,2,3,4,5,6,7,8,9,10]\n\u8f93\u51fa\uff1a5\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= arr.length <= 10^5
  • \n\t
  • arr.length \u4e3a\u5076\u6570
  • \n\t
  • 1 <= arr[i] <= 10^5
  • \n
\n", "tags_en": ["Greedy", "Array"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minSetSize(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minSetSize(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minSetSize(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minSetSize(self, arr: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minSetSize(int* arr, int arrSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinSetSize(int[] arr) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar minSetSize = function(arr) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef min_set_size(arr)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minSetSize(_ arr: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minSetSize(arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minSetSize(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minSetSize(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_set_size(arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function minSetSize($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minSetSize(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-set-size arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1338](https://leetcode-cn.com/problems/reduce-array-size-to-the-half)", "[\u6570\u7ec4\u5927\u5c0f\u51cf\u534a](/solution/1300-1399/1338.Reduce%20Array%20Size%20to%20The%20Half/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1338](https://leetcode.com/problems/reduce-array-size-to-the-half)", "[Reduce Array Size to The Half](/solution/1300-1399/1338.Reduce%20Array%20Size%20to%20The%20Half/README_EN.md)", "`Greedy`,`Array`", "Medium", ""]}, {"question_id": "1463", "frontend_question_id": "1337", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/the-k-weakest-rows-in-a-matrix", "url_en": "https://leetcode.com/problems/the-k-weakest-rows-in-a-matrix", "relative_path_cn": "/solution/1300-1399/1337.The%20K%20Weakest%20Rows%20in%20a%20Matrix/README.md", "relative_path_en": "/solution/1300-1399/1337.The%20K%20Weakest%20Rows%20in%20a%20Matrix/README_EN.md", "title_cn": "\u77e9\u9635\u4e2d\u6218\u6597\u529b\u6700\u5f31\u7684 K \u884c", "title_en": "The K Weakest Rows in a Matrix", "question_title_slug": "the-k-weakest-rows-in-a-matrix", "content_en": "

You are given an m x n binary matrix mat of 1's (representing soldiers) and 0's (representing civilians). The soldiers are positioned in front of the civilians. That is, all the 1's will appear to the left of all the 0's in each row.

\n\n

A row i is weaker than a row j if one of the following is true:

\n\n
    \n\t
  • The number of soldiers in row i is less than the number of soldiers in row j.
  • \n\t
  • Both rows have the same number of soldiers and i < j.
  • \n
\n\n

Return the indices of the k weakest rows in the matrix ordered from weakest to strongest.

\n\n

 

\n

Example 1:

\n\n
\nInput: mat = \n[[1,1,0,0,0],\n [1,1,1,1,0],\n [1,0,0,0,0],\n [1,1,0,0,0],\n [1,1,1,1,1]], \nk = 3\nOutput: [2,0,3]\nExplanation: \nThe number of soldiers in each row is: \n- Row 0: 2 \n- Row 1: 4 \n- Row 2: 1 \n- Row 3: 2 \n- Row 4: 5 \nThe rows ordered from weakest to strongest are [2,0,3,1,4].\n
\n\n

Example 2:

\n\n
\nInput: mat = \n[[1,0,0,0],\n [1,1,1,1],\n [1,0,0,0],\n [1,0,0,0]], \nk = 2\nOutput: [0,2]\nExplanation: \nThe number of soldiers in each row is: \n- Row 0: 1 \n- Row 1: 4 \n- Row 2: 1 \n- Row 3: 1 \nThe rows ordered from weakest to strongest are [0,2,3,1].\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • m == mat.length
  • \n\t
  • n == mat[i].length
  • \n\t
  • 2 <= n, m <= 100
  • \n\t
  • 1 <= k <= m
  • \n\t
  • matrix[i][j] is either 0 or 1.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5927\u5c0f\u4e3a\u00a0m\u00a0* n\u00a0\u7684\u77e9\u9635\u00a0mat\uff0c\u77e9\u9635\u7531\u82e5\u5e72\u519b\u4eba\u548c\u5e73\u6c11\u7ec4\u6210\uff0c\u5206\u522b\u7528 1 \u548c 0 \u8868\u793a\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u77e9\u9635\u4e2d\u6218\u6597\u529b\u6700\u5f31\u7684\u00a0k\u00a0\u884c\u7684\u7d22\u5f15\uff0c\u6309\u4ece\u6700\u5f31\u5230\u6700\u5f3a\u6392\u5e8f\u3002

\n\n

\u5982\u679c\u7b2c\u00a0i\u00a0\u884c\u7684\u519b\u4eba\u6570\u91cf\u5c11\u4e8e\u7b2c\u00a0j\u00a0\u884c\uff0c\u6216\u8005\u4e24\u884c\u519b\u4eba\u6570\u91cf\u76f8\u540c\u4f46 i \u5c0f\u4e8e j\uff0c\u90a3\u4e48\u6211\u4eec\u8ba4\u4e3a\u7b2c i \u884c\u7684\u6218\u6597\u529b\u6bd4\u7b2c j \u884c\u5f31\u3002

\n\n

\u519b\u4eba \u603b\u662f \u6392\u5728\u4e00\u884c\u4e2d\u7684\u9760\u524d\u4f4d\u7f6e\uff0c\u4e5f\u5c31\u662f\u8bf4 1 \u603b\u662f\u51fa\u73b0\u5728 0 \u4e4b\u524d\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1amat = \n[[1,1,0,0,0],\n [1,1,1,1,0],\n [1,0,0,0,0],\n [1,1,0,0,0],\n [1,1,1,1,1]], \nk = 3\n\u8f93\u51fa\uff1a[2,0,3]\n\u89e3\u91ca\uff1a\n\u6bcf\u884c\u4e2d\u7684\u519b\u4eba\u6570\u76ee\uff1a\n\u884c 0 -> 2 \n\u884c 1 -> 4 \n\u884c 2 -> 1 \n\u884c 3 -> 2 \n\u884c 4 -> 5 \n\u4ece\u6700\u5f31\u5230\u6700\u5f3a\u5bf9\u8fd9\u4e9b\u884c\u6392\u5e8f\u540e\u5f97\u5230 [2,0,3,1,4]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1amat = \n[[1,0,0,0],\n\u00a0[1,1,1,1],\n\u00a0[1,0,0,0],\n\u00a0[1,0,0,0]], \nk = 2\n\u8f93\u51fa\uff1a[0,2]\n\u89e3\u91ca\uff1a \n\u6bcf\u884c\u4e2d\u7684\u519b\u4eba\u6570\u76ee\uff1a\n\u884c 0 -> 1 \n\u884c 1 -> 4 \n\u884c 2 -> 1 \n\u884c 3 -> 1 \n\u4ece\u6700\u5f31\u5230\u6700\u5f3a\u5bf9\u8fd9\u4e9b\u884c\u6392\u5e8f\u540e\u5f97\u5230 [0,2,3,1]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • m == mat.length
  • \n\t
  • n == mat[i].length
  • \n\t
  • 2 <= n, m <= 100
  • \n\t
  • 1 <= k <= m
  • \n\t
  • matrix[i][j] \u4e0d\u662f 0 \u5c31\u662f 1
  • \n
\n", "tags_en": ["Array", "Binary Search"], "tags_cn": ["\u6570\u7ec4", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector kWeakestRows(vector>& mat, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] kWeakestRows(int[][] mat, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def kWeakestRows(self, mat, k):\n \"\"\"\n :type mat: List[List[int]]\n :type k: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def kWeakestRows(self, mat: List[List[int]], k: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* kWeakestRows(int** mat, int matSize, int* matColSize, int k, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] KWeakestRows(int[][] mat, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} mat\n * @param {number} k\n * @return {number[]}\n */\nvar kWeakestRows = function(mat, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} mat\n# @param {Integer} k\n# @return {Integer[]}\ndef k_weakest_rows(mat, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func kWeakestRows(_ mat: [[Int]], _ k: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func kWeakestRows(mat [][]int, k int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def kWeakestRows(mat: Array[Array[Int]], k: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun kWeakestRows(mat: Array, k: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn k_weakest_rows(mat: Vec>, k: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $mat\n * @param Integer $k\n * @return Integer[]\n */\n function kWeakestRows($mat, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function kWeakestRows(mat: number[][], k: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (k-weakest-rows mat k)\n (-> (listof (listof exact-integer?)) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1337](https://leetcode-cn.com/problems/the-k-weakest-rows-in-a-matrix)", "[\u77e9\u9635\u4e2d\u6218\u6597\u529b\u6700\u5f31\u7684 K \u884c](/solution/1300-1399/1337.The%20K%20Weakest%20Rows%20in%20a%20Matrix/README.md)", "`\u6570\u7ec4`,`\u4e8c\u5206\u67e5\u627e`", "\u7b80\u5355", ""], "md_table_row_en": ["[1337](https://leetcode.com/problems/the-k-weakest-rows-in-a-matrix)", "[The K Weakest Rows in a Matrix](/solution/1300-1399/1337.The%20K%20Weakest%20Rows%20in%20a%20Matrix/README_EN.md)", "`Array`,`Binary Search`", "Easy", ""]}, {"question_id": "1462", "frontend_question_id": "1327", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/list-the-products-ordered-in-a-period", "url_en": "https://leetcode.com/problems/list-the-products-ordered-in-a-period", "relative_path_cn": "/solution/1300-1399/1327.List%20the%20Products%20Ordered%20in%20a%20Period/README.md", "relative_path_en": "/solution/1300-1399/1327.List%20the%20Products%20Ordered%20in%20a%20Period/README_EN.md", "title_cn": "\u5217\u51fa\u6307\u5b9a\u65f6\u95f4\u6bb5\u5185\u6240\u6709\u7684\u4e0b\u5355\u4ea7\u54c1", "title_en": "List the Products Ordered in a Period", "question_title_slug": "list-the-products-ordered-in-a-period", "content_en": "

Table: Products

\n\n
\n+------------------+---------+\n| Column Name      | Type    |\n+------------------+---------+\n| product_id       | int     |\n| product_name     | varchar |\n| product_category | varchar |\n+------------------+---------+\nproduct_id is the primary key for this table.\nThis table contains data about the company's products.\n
\n\n

Table: Orders

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| product_id    | int     |\n| order_date    | date    |\n| unit          | int     |\n+---------------+---------+\nThere is no primary key for this table. It may have duplicate rows.\nproduct_id is a foreign key to Products table.\nunit is the number of products ordered in order_date.\n
\n\n

 

\n\n

Write an SQL query to get the names of products with greater than or equal to 100 units ordered in February 2020 and their amount.

\n\n

Return result table in any order.

\n\n

The query result format is in the following example:

\n\n

 

\n\n
\nProducts table:\n+-------------+-----------------------+------------------+\n| product_id  | product_name          | product_category |\n+-------------+-----------------------+------------------+\n| 1           | Leetcode Solutions    | Book             |\n| 2           | Jewels of Stringology | Book             |\n| 3           | HP                    | Laptop           |\n| 4           | Lenovo                | Laptop           |\n| 5           | Leetcode Kit          | T-shirt          |\n+-------------+-----------------------+------------------+\n\nOrders table:\n+--------------+--------------+----------+\n| product_id   | order_date   | unit     |\n+--------------+--------------+----------+\n| 1            | 2020-02-05   | 60       |\n| 1            | 2020-02-10   | 70       |\n| 2            | 2020-01-18   | 30       |\n| 2            | 2020-02-11   | 80       |\n| 3            | 2020-02-17   | 2        |\n| 3            | 2020-02-24   | 3        |\n| 4            | 2020-03-01   | 20       |\n| 4            | 2020-03-04   | 30       |\n| 4            | 2020-03-04   | 60       |\n| 5            | 2020-02-25   | 50       |\n| 5            | 2020-02-27   | 50       |\n| 5            | 2020-03-01   | 50       |\n+--------------+--------------+----------+\n\nResult table:\n+--------------------+---------+\n| product_name       | unit    |\n+--------------------+---------+\n| Leetcode Solutions | 130     |\n| Leetcode Kit       | 100     |\n+--------------------+---------+\n\nProducts with product_id = 1 is ordered in February a total of (60 + 70) = 130.\nProducts with product_id = 2 is ordered in February a total of 80.\nProducts with product_id = 3 is ordered in February a total of (2 + 3) = 5.\nProducts with product_id = 4 was not ordered in February 2020.\nProducts with product_id = 5 is ordered in February a total of (50 + 50) = 100.\n
\n", "content_cn": "

\u8868: Products

\n\n
+------------------+---------+\n| Column Name      | Type    |\n+------------------+---------+\n| product_id       | int     |\n| product_name     | varchar |\n| product_category | varchar |\n+------------------+---------+\nproduct_id \u662f\u8be5\u8868\u4e3b\u952e\u3002\n\u8be5\u8868\u5305\u542b\u8be5\u516c\u53f8\u4ea7\u54c1\u7684\u6570\u636e\u3002\n
\n\n

\u8868: Orders

\n\n
+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| product_id    | int     |\n| order_date    | date    |\n| unit          | int     |\n+---------------+---------+\n\u8be5\u8868\u65e0\u4e3b\u952e\uff0c\u53ef\u80fd\u5305\u542b\u91cd\u590d\u884c\u3002\nproduct_id \u662f\u8868\u5355 Products \u7684\u5916\u952e\u3002\nunit \u662f\u5728\u65e5\u671f order_date \u5185\u4e0b\u5355\u4ea7\u54c1\u7684\u6570\u76ee\u3002\n
\n\n

 

\n\n

\u5199\u4e00\u4e2a SQL \u8bed\u53e5\uff0c\u8981\u6c42\u83b7\u53d6\u5728 2020 \u5e74 2 \u6708\u4efd\u4e0b\u5355\u7684\u6570\u91cf\u4e0d\u5c11\u4e8e 100 \u7684\u4ea7\u54c1\u7684\u540d\u5b57\u548c\u6570\u76ee\u3002

\n\n

\u8fd4\u56de\u7ed3\u679c\u8868\u5355\u7684\u987a\u5e8f\u65e0\u8981\u6c42\u3002

\n\n

 

\n\n

\u67e5\u8be2\u7ed3\u679c\u7684\u683c\u5f0f\u5982\u4e0b\uff1a

\n\n
Products \u8868:\n+-------------+-----------------------+------------------+\n| product_id  | product_name          | product_category |\n+-------------+-----------------------+------------------+\n| 1           | Leetcode Solutions    | Book             |\n| 2           | Jewels of Stringology | Book             |\n| 3           | HP                    | Laptop           |\n| 4           | Lenovo                | Laptop           |\n| 5           | Leetcode Kit          | T-shirt          |\n+-------------+-----------------------+------------------+\n\nOrders \u8868:\n+--------------+--------------+----------+\n| product_id   | order_date   | unit     |\n+--------------+--------------+----------+\n| 1            | 2020-02-05   | 60       |\n| 1            | 2020-02-10   | 70       |\n| 2            | 2020-01-18   | 30       |\n| 2            | 2020-02-11   | 80       |\n| 3            | 2020-02-17   | 2        |\n| 3            | 2020-02-24   | 3        |\n| 4            | 2020-03-01   | 20       |\n| 4            | 2020-03-04   | 30       |\n| 4            | 2020-03-04   | 60       |\n| 5            | 2020-02-25   | 50       |\n| 5            | 2020-02-27   | 50       |\n| 5            | 2020-03-01   | 50       |\n+--------------+--------------+----------+\n\nResult \u8868:\n+--------------------+---------+\n| product_name       | unit    |\n+--------------------+---------+\n| Leetcode Solutions | 130     |\n| Leetcode Kit       | 100     |\n+--------------------+---------+\n\n2020 \u5e74 2 \u6708\u4efd\u4e0b\u5355 product_id = 1 \u7684\u4ea7\u54c1\u7684\u6570\u76ee\u603b\u548c\u4e3a (60 + 70) = 130 \u3002\n2020 \u5e74 2 \u6708\u4efd\u4e0b\u5355 product_id = 2 \u7684\u4ea7\u54c1\u7684\u6570\u76ee\u603b\u548c\u4e3a 80 \u3002\n2020 \u5e74 2 \u6708\u4efd\u4e0b\u5355 product_id = 3 \u7684\u4ea7\u54c1\u7684\u6570\u76ee\u603b\u548c\u4e3a (2 + 3) = 5 \u3002\n2020 \u5e74 2 \u6708\u4efd product_id = 4 \u7684\u4ea7\u54c1\u5e76\u6ca1\u6709\u4e0b\u5355\u3002\n2020 \u5e74 2 \u6708\u4efd\u4e0b\u5355 product_id = 5 \u7684\u4ea7\u54c1\u7684\u6570\u76ee\u603b\u548c\u4e3a (50 + 50) = 100 \u3002\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1327](https://leetcode-cn.com/problems/list-the-products-ordered-in-a-period)", "[\u5217\u51fa\u6307\u5b9a\u65f6\u95f4\u6bb5\u5185\u6240\u6709\u7684\u4e0b\u5355\u4ea7\u54c1](/solution/1300-1399/1327.List%20the%20Products%20Ordered%20in%20a%20Period/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1327](https://leetcode.com/problems/list-the-products-ordered-in-a-period)", "[List the Products Ordered in a Period](/solution/1300-1399/1327.List%20the%20Products%20Ordered%20in%20a%20Period/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1461", "frontend_question_id": "1359", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-all-valid-pickup-and-delivery-options", "url_en": "https://leetcode.com/problems/count-all-valid-pickup-and-delivery-options", "relative_path_cn": "/solution/1300-1399/1359.Count%20All%20Valid%20Pickup%20and%20Delivery%20Options/README.md", "relative_path_en": "/solution/1300-1399/1359.Count%20All%20Valid%20Pickup%20and%20Delivery%20Options/README_EN.md", "title_cn": "\u6709\u6548\u7684\u5feb\u9012\u5e8f\u5217\u6570\u76ee", "title_en": "Count All Valid Pickup and Delivery Options", "question_title_slug": "count-all-valid-pickup-and-delivery-options", "content_en": "

Given n orders, each order consist in pickup and delivery services. 

\n\n

Count all valid pickup/delivery possible sequences such that delivery(i) is always after of pickup(i). 

\n\n

Since the answer may be too large, return it modulo 10^9 + 7.

\n\n

 

\n

Example 1:

\n\n
\nInput: n = 1\nOutput: 1\nExplanation: Unique order (P1, D1), Delivery 1 always is after of Pickup 1.\n
\n\n

Example 2:

\n\n
\nInput: n = 2\nOutput: 6\nExplanation: All possible orders: \n(P1,P2,D1,D2), (P1,P2,D2,D1), (P1,D1,P2,D2), (P2,P1,D1,D2), (P2,P1,D2,D1) and (P2,D2,P1,D1).\nThis is an invalid order (P1,D2,P2,D1) because Pickup 2 is after of Delivery 2.\n
\n\n

Example 3:

\n\n
\nInput: n = 3\nOutput: 90\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 500
  • \n
\n", "content_cn": "

\u7ed9\u4f60 n \u7b14\u8ba2\u5355\uff0c\u6bcf\u7b14\u8ba2\u5355\u90fd\u9700\u8981\u5feb\u9012\u670d\u52a1\u3002

\n\n

\u8bf7\u4f60\u7edf\u8ba1\u6240\u6709\u6709\u6548\u7684 \u6536\u4ef6/\u914d\u9001 \u5e8f\u5217\u7684\u6570\u76ee\uff0c\u786e\u4fdd\u7b2c i \u4e2a\u7269\u54c1\u7684\u914d\u9001\u670d\u52a1 delivery(i) \u603b\u662f\u5728\u5176\u6536\u4ef6\u670d\u52a1 pickup(i) \u4e4b\u540e\u3002

\n\n

\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u5f88\u5927\uff0c\u8bf7\u8fd4\u56de\u7b54\u6848\u5bf9 10^9 + 7 \u53d6\u4f59\u7684\u7ed3\u679c\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u53ea\u6709\u4e00\u79cd\u5e8f\u5217 (P1, D1)\uff0c\u7269\u54c1 1 \u7684\u914d\u9001\u670d\u52a1\uff08D1\uff09\u5728\u7269\u54c1 1 \u7684\u6536\u4ef6\u670d\u52a1\uff08P1\uff09\u540e\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1an = 2\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u6240\u6709\u53ef\u80fd\u7684\u5e8f\u5217\u5305\u62ec\uff1a\n(P1,P2,D1,D2)\uff0c(P1,P2,D2,D1)\uff0c(P1,D1,P2,D2)\uff0c(P2,P1,D1,D2)\uff0c(P2,P1,D2,D1) \u548c (P2,D2,P1,D1)\u3002\n(P1,D2,P2,D1) \u662f\u4e00\u4e2a\u65e0\u6548\u7684\u5e8f\u5217\uff0c\u56e0\u4e3a\u7269\u54c1 2 \u7684\u6536\u4ef6\u670d\u52a1\uff08P2\uff09\u4e0d\u5e94\u5728\u7269\u54c1 2 \u7684\u914d\u9001\u670d\u52a1\uff08D2\uff09\u4e4b\u540e\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1an = 3\n\u8f93\u51fa\uff1a90\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 500
  • \n
\n", "tags_en": ["Math", "Dynamic Programming"], "tags_cn": ["\u6570\u5b66", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countOrders(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countOrders(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countOrders(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countOrders(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countOrders(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountOrders(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar countOrders = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef count_orders(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countOrders(_ n: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countOrders(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countOrders(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countOrders(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_orders(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function countOrders($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countOrders(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-orders n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1359](https://leetcode-cn.com/problems/count-all-valid-pickup-and-delivery-options)", "[\u6709\u6548\u7684\u5feb\u9012\u5e8f\u5217\u6570\u76ee](/solution/1300-1399/1359.Count%20All%20Valid%20Pickup%20and%20Delivery%20Options/README.md)", "`\u6570\u5b66`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1359](https://leetcode.com/problems/count-all-valid-pickup-and-delivery-options)", "[Count All Valid Pickup and Delivery Options](/solution/1300-1399/1359.Count%20All%20Valid%20Pickup%20and%20Delivery%20Options/README_EN.md)", "`Math`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "1460", "frontend_question_id": "1358", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-substrings-containing-all-three-characters", "url_en": "https://leetcode.com/problems/number-of-substrings-containing-all-three-characters", "relative_path_cn": "/solution/1300-1399/1358.Number%20of%20Substrings%20Containing%20All%20Three%20Characters/README.md", "relative_path_en": "/solution/1300-1399/1358.Number%20of%20Substrings%20Containing%20All%20Three%20Characters/README_EN.md", "title_cn": "\u5305\u542b\u6240\u6709\u4e09\u79cd\u5b57\u7b26\u7684\u5b50\u5b57\u7b26\u4e32\u6570\u76ee", "title_en": "Number of Substrings Containing All Three Characters", "question_title_slug": "number-of-substrings-containing-all-three-characters", "content_en": "

Given a string s consisting only of characters a, b and c.

\n\n

Return the number of substrings containing at least one occurrence of all these characters a, b and c.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "abcabc"\nOutput: 10\nExplanation: The substrings containing at least one occurrence of the characters ab and c are "abc", "abca", "abcab", "abcabc", "bca", "bcab", "bcabc", "cab", "cabc" and "abc" (again). \n
\n\n

Example 2:

\n\n
\nInput: s = "aaacb"\nOutput: 3\nExplanation: The substrings containing at least one occurrence of the characters ab and c are "aaacb", "aacb" and "acb". \n
\n\n

Example 3:

\n\n
\nInput: s = "abc"\nOutput: 1\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 3 <= s.length <= 5 x 10^4
  • \n\t
  • s only consists of a, b or characters.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \uff0c\u5b83\u53ea\u5305\u542b\u4e09\u79cd\u5b57\u7b26 a, b \u548c c \u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de a\uff0cb \u548c c \u90fd \u81f3\u5c11 \u51fa\u73b0\u8fc7\u4e00\u6b21\u7684\u5b50\u5b57\u7b26\u4e32\u6570\u76ee\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1as = "abcabc"\n\u8f93\u51fa\uff1a10\n\u89e3\u91ca\uff1a\u5305\u542b a\uff0cb \u548c c \u5404\u81f3\u5c11\u4e00\u6b21\u7684\u5b50\u5b57\u7b26\u4e32\u4e3a "abc", "abca", "abcab", "abcabc", "bca", "bcab", "bcabc", "cab", "cabc" \u548c "abc" (\u76f8\u540c\u5b57\u7b26\u4e32\u7b97\u591a\u6b21)\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1as = "aaacb"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u5305\u542b a\uff0cb \u548c c \u5404\u81f3\u5c11\u4e00\u6b21\u7684\u5b50\u5b57\u7b26\u4e32\u4e3a "aaacb", "aacb" \u548c "acb" \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1as = "abc"\n\u8f93\u51fa\uff1a1\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 3 <= s.length <= 5 x 10^4
  • \n\t
  • s \u53ea\u5305\u542b\u5b57\u7b26 a\uff0cb \u548c c \u3002
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numberOfSubstrings(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numberOfSubstrings(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numberOfSubstrings(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numberOfSubstrings(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numberOfSubstrings(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumberOfSubstrings(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar numberOfSubstrings = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef number_of_substrings(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numberOfSubstrings(_ s: String) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numberOfSubstrings(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numberOfSubstrings(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numberOfSubstrings(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn number_of_substrings(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function numberOfSubstrings($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numberOfSubstrings(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (number-of-substrings s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1358](https://leetcode-cn.com/problems/number-of-substrings-containing-all-three-characters)", "[\u5305\u542b\u6240\u6709\u4e09\u79cd\u5b57\u7b26\u7684\u5b50\u5b57\u7b26\u4e32\u6570\u76ee](/solution/1300-1399/1358.Number%20of%20Substrings%20Containing%20All%20Three%20Characters/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1358](https://leetcode.com/problems/number-of-substrings-containing-all-three-characters)", "[Number of Substrings Containing All Three Characters](/solution/1300-1399/1358.Number%20of%20Substrings%20Containing%20All%20Three%20Characters/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "1459", "frontend_question_id": "1357", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/apply-discount-every-n-orders", "url_en": "https://leetcode.com/problems/apply-discount-every-n-orders", "relative_path_cn": "/solution/1300-1399/1357.Apply%20Discount%20Every%20n%20Orders/README.md", "relative_path_en": "/solution/1300-1399/1357.Apply%20Discount%20Every%20n%20Orders/README_EN.md", "title_cn": "\u6bcf\u9694 n \u4e2a\u987e\u5ba2\u6253\u6298", "title_en": "Apply Discount Every n Orders", "question_title_slug": "apply-discount-every-n-orders", "content_en": "

There is a sale in a supermarket, there will be a discount every n customer.
\nThere are some products in the supermarket where the id of the i-th product is products[i] and the price per unit of this product is prices[i].
\nThe system will count the number of customers and when the n-th customer arrive he/she will have a discount on the bill. (i.e if the cost is x the new cost is x - (discount * x) / 100). Then the system will start counting customers again.
\nThe customer orders a certain amount of each product where product[i] is the id of the i-th product the customer ordered and amount[i] is the number of units the customer ordered of that product.

\n\n

Implement the Cashier class:

\n\n
    \n\t
  • Cashier(int n, int discount, int[] products, int[] prices) Initializes the object with n, the discount, the products and their prices.
  • \n\t
  • double getBill(int[] product, int[] amount) returns the value of the bill and apply the discount if needed. Answers within 10^-5 of the actual value will be accepted as correct.
  • \n
\n\n

 

\n

Example 1:

\n\n
\nInput\n["Cashier","getBill","getBill","getBill","getBill","getBill","getBill","getBill"]\n[[3,50,[1,2,3,4,5,6,7],[100,200,300,400,300,200,100]],[[1,2],[1,2]],[[3,7],[10,10]],[[1,2,3,4,5,6,7],[1,1,1,1,1,1,1]],[[4],[10]],[[7,3],[10,10]],[[7,5,3,1,6,4,2],[10,10,10,9,9,9,7]],[[2,3,5],[5,3,2]]]\nOutput\n[null,500.0,4000.0,800.0,4000.0,4000.0,7350.0,2500.0]\nExplanation\nCashier cashier = new Cashier(3,50,[1,2,3,4,5,6,7],[100,200,300,400,300,200,100]);\ncashier.getBill([1,2],[1,2]);                        // return 500.0, bill = 1 * 100 + 2 * 200 = 500.\ncashier.getBill([3,7],[10,10]);                      // return 4000.0\ncashier.getBill([1,2,3,4,5,6,7],[1,1,1,1,1,1,1]);    // return 800.0, The bill was 1600.0 but as this is the third customer, he has a discount of 50% which means his bill is only 1600 - 1600 * (50 / 100) = 800.\ncashier.getBill([4],[10]);                           // return 4000.0\ncashier.getBill([7,3],[10,10]);                      // return 4000.0\ncashier.getBill([7,5,3,1,6,4,2],[10,10,10,9,9,9,7]); // return 7350.0, Bill was 14700.0 but as the system counted three more customers, he will have a 50% discount and the bill becomes 7350.0\ncashier.getBill([2,3,5],[5,3,2]);                    // return 2500.0\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 10^4
  • \n\t
  • 0 <= discount <= 100
  • \n\t
  • 1 <= products.length <= 200
  • \n\t
  • 1 <= products[i] <= 200
  • \n\t
  • There are not repeated elements in the array products.
  • \n\t
  • prices.length == products.length
  • \n\t
  • 1 <= prices[i] <= 1000
  • \n\t
  • 1 <= product.length <= products.length
  • \n\t
  • product[i] exists in products.
  • \n\t
  • amount.length == product.length
  • \n\t
  • 1 <= amount[i] <= 1000
  • \n\t
  • At most 1000 calls will be made to getBill.
  • \n\t
  • Answers within 10^-5 of the actual value will be accepted as correct.
  • \n
\n", "content_cn": "

\u8d85\u5e02\u91cc\u6b63\u5728\u4e3e\u884c\u6253\u6298\u6d3b\u52a8\uff0c\u6bcf\u9694 n \u4e2a\u987e\u5ba2\u4f1a\u5f97\u5230 discount \u7684\u6298\u6263\u3002

\n\n

\u8d85\u5e02\u91cc\u6709\u4e00\u4e9b\u5546\u54c1\uff0c\u7b2c i \u79cd\u5546\u54c1\u4e3a products[i] \u4e14\u6bcf\u4ef6\u5355\u54c1\u7684\u4ef7\u683c\u4e3a prices[i] \u3002

\n\n

\u7ed3\u8d26\u7cfb\u7edf\u4f1a\u7edf\u8ba1\u987e\u5ba2\u7684\u6570\u76ee\uff0c\u6bcf\u9694 n \u4e2a\u987e\u5ba2\u7ed3\u8d26\u65f6\uff0c\u8be5\u987e\u5ba2\u7684\u8d26\u5355\u90fd\u4f1a\u6253\u6298\uff0c\u6298\u6263\u4e3a discount \uff08\u4e5f\u5c31\u662f\u5982\u679c\u539f\u672c\u8d26\u5355\u4e3a x \uff0c\u90a3\u4e48\u5b9e\u9645\u91d1\u989d\u4f1a\u53d8\u6210 x - (discount * x) / 100 \uff09\uff0c\u7136\u540e\u7cfb\u7edf\u4f1a\u91cd\u65b0\u5f00\u59cb\u8ba1\u6570\u3002

\n\n

\u987e\u5ba2\u4f1a\u8d2d\u4e70\u4e00\u4e9b\u5546\u54c1\uff0c product[i] \u662f\u987e\u5ba2\u8d2d\u4e70\u7684\u7b2c i \u79cd\u5546\u54c1\uff0c amount[i] \u662f\u5bf9\u5e94\u7684\u8d2d\u4e70\u8be5\u79cd\u5546\u54c1\u7684\u6570\u76ee\u3002

\n\n

\u8bf7\u4f60\u5b9e\u73b0 Cashier \u7c7b\uff1a

\n\n
    \n\t
  • Cashier(int n, int discount, int[] products, int[] prices) \u521d\u59cb\u5316\u5b9e\u4f8b\u5bf9\u8c61\uff0c\u53c2\u6570\u5206\u522b\u4e3a\u6253\u6298\u9891\u7387 n \uff0c\u6298\u6263\u5927\u5c0f discount \uff0c\u8d85\u5e02\u91cc\u7684\u5546\u54c1\u5217\u8868 products \u548c\u5b83\u4eec\u7684\u4ef7\u683c prices \u3002
  • \n\t
  • double getBill(int[] product, int[] amount) \u8fd4\u56de\u8d26\u5355\u7684\u5b9e\u9645\u91d1\u989d\uff08\u5982\u679c\u6709\u6253\u6298\uff0c\u8bf7\u8fd4\u56de\u6253\u6298\u540e\u7684\u7ed3\u679c\uff09\u3002\u8fd4\u56de\u7ed3\u679c\u4e0e\u6807\u51c6\u7b54\u6848\u8bef\u5dee\u5728 10^-5 \u4ee5\u5185\u90fd\u89c6\u4e3a\u6b63\u786e\u7ed3\u679c\u3002
  • \n
\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\n["Cashier","getBill","getBill","getBill","getBill","getBill","getBill","getBill"]\n[[3,50,[1,2,3,4,5,6,7],[100,200,300,400,300,200,100]],[[1,2],[1,2]],[[3,7],[10,10]],[[1,2,3,4,5,6,7],[1,1,1,1,1,1,1]],[[4],[10]],[[7,3],[10,10]],[[7,5,3,1,6,4,2],[10,10,10,9,9,9,7]],[[2,3,5],[5,3,2]]]\n\u8f93\u51fa\n[null,500.0,4000.0,800.0,4000.0,4000.0,7350.0,2500.0]\n\u89e3\u91ca\nCashier cashier = new Cashier(3,50,[1,2,3,4,5,6,7],[100,200,300,400,300,200,100]);\ncashier.getBill([1,2],[1,2]);                        // \u8fd4\u56de 500.0, \u8d26\u5355\u91d1\u989d\u4e3a = 1 * 100 + 2 * 200 = 500.\ncashier.getBill([3,7],[10,10]);                      // \u8fd4\u56de 4000.0\ncashier.getBill([1,2,3,4,5,6,7],[1,1,1,1,1,1,1]);    // \u8fd4\u56de 800.0 \uff0c\u8d26\u5355\u539f\u672c\u4e3a 1600.0 \uff0c\u4f46\u7531\u4e8e\u8be5\u987e\u5ba2\u662f\u7b2c\u4e09\u4f4d\u987e\u5ba2\uff0c\u4ed6\u5c06\u5f97\u5230 50% \u7684\u6298\u6263\uff0c\u6240\u4ee5\u5b9e\u9645\u91d1\u989d\u4e3a 1600 - 1600 * (50 / 100) = 800 \u3002\ncashier.getBill([4],[10]);                           // \u8fd4\u56de 4000.0\ncashier.getBill([7,3],[10,10]);                      // \u8fd4\u56de 4000.0\ncashier.getBill([7,5,3,1,6,4,2],[10,10,10,9,9,9,7]); // \u8fd4\u56de 7350.0 \uff0c\u8d26\u5355\u539f\u672c\u4e3a 14700.0 \uff0c\u4f46\u7531\u4e8e\u7cfb\u7edf\u8ba1\u6570\u518d\u6b21\u8fbe\u5230\u4e09\uff0c\u8be5\u987e\u5ba2\u5c06\u5f97\u5230 50% \u7684\u6298\u6263\uff0c\u5b9e\u9645\u91d1\u989d\u4e3a 7350.0 \u3002\ncashier.getBill([2,3,5],[5,3,2]);                    // \u8fd4\u56de 2500.0\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 10^4
  • \n\t
  • 0 <= discount <= 100
  • \n\t
  • 1 <= products.length <= 200
  • \n\t
  • 1 <= products[i] <= 200
  • \n\t
  • products \u5217\u8868\u4e2d \u4e0d\u4f1a \u6709\u91cd\u590d\u7684\u5143\u7d20\u3002
  • \n\t
  • prices.length == products.length
  • \n\t
  • 1 <= prices[i] <= 1000
  • \n\t
  • 1 <= product.length <= products.length
  • \n\t
  • product[i] \u5728 products \u51fa\u73b0\u8fc7\u3002
  • \n\t
  • amount.length == product.length
  • \n\t
  • 1 <= amount[i] <= 1000
  • \n\t
  • \u6700\u591a\u6709 1000 \u6b21\u5bf9 getBill \u51fd\u6570\u7684\u8c03\u7528\u3002
  • \n\t
  • \u8fd4\u56de\u7ed3\u679c\u4e0e\u6807\u51c6\u7b54\u6848\u8bef\u5dee\u5728 10^-5 \u4ee5\u5185\u90fd\u89c6\u4e3a\u6b63\u786e\u7ed3\u679c\u3002
  • \n
\n", "tags_en": ["Design"], "tags_cn": ["\u8bbe\u8ba1"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Cashier {\npublic:\n Cashier(int n, int discount, vector& products, vector& prices) {\n\n }\n \n double getBill(vector product, vector amount) {\n\n }\n};\n\n/**\n * Your Cashier object will be instantiated and called as such:\n * Cashier* obj = new Cashier(n, discount, products, prices);\n * double param_1 = obj->getBill(product,amount);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Cashier {\n\n public Cashier(int n, int discount, int[] products, int[] prices) {\n\n }\n \n public double getBill(int[] product, int[] amount) {\n\n }\n}\n\n/**\n * Your Cashier object will be instantiated and called as such:\n * Cashier obj = new Cashier(n, discount, products, prices);\n * double param_1 = obj.getBill(product,amount);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Cashier(object):\n\n def __init__(self, n, discount, products, prices):\n \"\"\"\n :type n: int\n :type discount: int\n :type products: List[int]\n :type prices: List[int]\n \"\"\"\n\n\n def getBill(self, product, amount):\n \"\"\"\n :type product: List[int]\n :type amount: List[int]\n :rtype: float\n \"\"\"\n\n\n\n# Your Cashier object will be instantiated and called as such:\n# obj = Cashier(n, discount, products, prices)\n# param_1 = obj.getBill(product,amount)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Cashier:\n\n def __init__(self, n: int, discount: int, products: List[int], prices: List[int]):\n\n\n def getBill(self, product: List[int], amount: List[int]) -> float:\n\n\n\n# Your Cashier object will be instantiated and called as such:\n# obj = Cashier(n, discount, products, prices)\n# param_1 = obj.getBill(product,amount)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} Cashier;\n\n\nCashier* cashierCreate(int n, int discount, int* products, int productsSize, int* prices, int pricesSize) {\n\n}\n\ndouble cashierGetBill(Cashier* obj, int* product, int productSize, int* amount, int amountSize) {\n\n}\n\nvoid cashierFree(Cashier* obj) {\n\n}\n\n/**\n * Your Cashier struct will be instantiated and called as such:\n * Cashier* obj = cashierCreate(n, discount, products, productsSize, prices, pricesSize);\n * double param_1 = cashierGetBill(obj, product, productSize, amount, amountSize);\n \n * cashierFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Cashier {\n\n public Cashier(int n, int discount, int[] products, int[] prices) {\n\n }\n \n public double GetBill(int[] product, int[] amount) {\n\n }\n}\n\n/**\n * Your Cashier object will be instantiated and called as such:\n * Cashier obj = new Cashier(n, discount, products, prices);\n * double param_1 = obj.GetBill(product,amount);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} discount\n * @param {number[]} products\n * @param {number[]} prices\n */\nvar Cashier = function(n, discount, products, prices) {\n\n};\n\n/** \n * @param {number[]} product \n * @param {number[]} amount\n * @return {number}\n */\nCashier.prototype.getBill = function(product, amount) {\n\n};\n\n/**\n * Your Cashier object will be instantiated and called as such:\n * var obj = new Cashier(n, discount, products, prices)\n * var param_1 = obj.getBill(product,amount)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class Cashier\n\n=begin\n :type n: Integer\n :type discount: Integer\n :type products: Integer[]\n :type prices: Integer[]\n=end\n def initialize(n, discount, products, prices)\n\n end\n\n\n=begin\n :type product: Integer[]\n :type amount: Integer[]\n :rtype: Float\n=end\n def get_bill(product, amount)\n\n end\n\n\nend\n\n# Your Cashier object will be instantiated and called as such:\n# obj = Cashier.new(n, discount, products, prices)\n# param_1 = obj.get_bill(product, amount)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass Cashier {\n\n init(_ n: Int, _ discount: Int, _ products: [Int], _ prices: [Int]) {\n\n }\n \n func getBill(_ product: [Int], _ amount: [Int]) -> Double {\n\n }\n}\n\n/**\n * Your Cashier object will be instantiated and called as such:\n * let obj = Cashier(n, discount, products, prices)\n * let ret_1: Double = obj.getBill(product, amount)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type Cashier struct {\n\n}\n\n\nfunc Constructor(n int, discount int, products []int, prices []int) Cashier {\n\n}\n\n\nfunc (this *Cashier) GetBill(product []int, amount []int) float64 {\n\n}\n\n\n/**\n * Your Cashier object will be instantiated and called as such:\n * obj := Constructor(n, discount, products, prices);\n * param_1 := obj.GetBill(product,amount);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class Cashier(_n: Int, _discount: Int, _products: Array[Int], _prices: Array[Int]) {\n\n def getBill(product: Array[Int], amount: Array[Int]): Double = {\n\n }\n\n}\n\n/**\n * Your Cashier object will be instantiated and called as such:\n * var obj = new Cashier(n, discount, products, prices)\n * var param_1 = obj.getBill(product,amount)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Cashier(n: Int, discount: Int, products: IntArray, prices: IntArray) {\n\n fun getBill(product: IntArray, amount: IntArray): Double {\n\n }\n\n}\n\n/**\n * Your Cashier object will be instantiated and called as such:\n * var obj = Cashier(n, discount, products, prices)\n * var param_1 = obj.getBill(product,amount)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct Cashier {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl Cashier {\n\n fn new(n: i32, discount: i32, products: Vec, prices: Vec) -> Self {\n\n }\n \n fn get_bill(&self, product: Vec, amount: Vec) -> f64 {\n\n }\n}\n\n/**\n * Your Cashier object will be instantiated and called as such:\n * let obj = Cashier::new(n, discount, products, prices);\n * let ret_1: f64 = obj.get_bill(product, amount);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Cashier {\n /**\n * @param Integer $n\n * @param Integer $discount\n * @param Integer[] $products\n * @param Integer[] $prices\n */\n function __construct($n, $discount, $products, $prices) {\n\n }\n\n /**\n * @param Integer[] $product\n * @param Integer[] $amount\n * @return Float\n */\n function getBill($product, $amount) {\n\n }\n}\n\n/**\n * Your Cashier object will be instantiated and called as such:\n * $obj = Cashier($n, $discount, $products, $prices);\n * $ret_1 = $obj->getBill($product, $amount);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class Cashier {\n constructor(n: number, discount: number, products: number[], prices: number[]) {\n\n }\n\n getBill(product: number[], amount: number[]): number {\n\n }\n}\n\n/**\n * Your Cashier object will be instantiated and called as such:\n * var obj = new Cashier(n, discount, products, prices)\n * var param_1 = obj.getBill(product,amount)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define cashier%\n (class object%\n (super-new)\n\n ; n : exact-integer?\n\n ; discount : exact-integer?\n\n ; products : (listof exact-integer?)\n\n ; prices : (listof exact-integer?)\n (init-field\n n\n discount\n products\n prices)\n \n ; get-bill : (listof exact-integer?) (listof exact-integer?) -> flonum?\n (define/public (get-bill product amount)\n\n )))\n\n;; Your cashier% object will be instantiated and called as such:\n;; (define obj (new cashier% [n n] [discount discount] [products products] [prices prices]))\n;; (define param_1 (send obj get-bill product amount))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1357](https://leetcode-cn.com/problems/apply-discount-every-n-orders)", "[\u6bcf\u9694 n \u4e2a\u987e\u5ba2\u6253\u6298](/solution/1300-1399/1357.Apply%20Discount%20Every%20n%20Orders/README.md)", "`\u8bbe\u8ba1`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1357](https://leetcode.com/problems/apply-discount-every-n-orders)", "[Apply Discount Every n Orders](/solution/1300-1399/1357.Apply%20Discount%20Every%20n%20Orders/README_EN.md)", "`Design`", "Medium", ""]}, {"question_id": "1458", "frontend_question_id": "1356", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sort-integers-by-the-number-of-1-bits", "url_en": "https://leetcode.com/problems/sort-integers-by-the-number-of-1-bits", "relative_path_cn": "/solution/1300-1399/1356.Sort%20Integers%20by%20The%20Number%20of%201%20Bits/README.md", "relative_path_en": "/solution/1300-1399/1356.Sort%20Integers%20by%20The%20Number%20of%201%20Bits/README_EN.md", "title_cn": "\u6839\u636e\u6570\u5b57\u4e8c\u8fdb\u5236\u4e0b 1 \u7684\u6570\u76ee\u6392\u5e8f", "title_en": "Sort Integers by The Number of 1 Bits", "question_title_slug": "sort-integers-by-the-number-of-1-bits", "content_en": "

Given an integer array arr. You have to sort the integers in the array in ascending order by the number of 1's in their binary representation and in case of two or more integers have the same number of 1's you have to sort them in ascending order.

\n\n

Return the sorted array.

\n\n

 

\n

Example 1:

\n\n
\nInput: arr = [0,1,2,3,4,5,6,7,8]\nOutput: [0,1,2,4,8,3,5,6,7]\nExplantion: [0] is the only integer with 0 bits.\n[1,2,4,8] all have 1 bit.\n[3,5,6] have 2 bits.\n[7] has 3 bits.\nThe sorted array by bits is [0,1,2,4,8,3,5,6,7]\n
\n\n

Example 2:

\n\n
\nInput: arr = [1024,512,256,128,64,32,16,8,4,2,1]\nOutput: [1,2,4,8,16,32,64,128,256,512,1024]\nExplantion: All integers have 1 bit in the binary representation, you should just sort them in ascending order.\n
\n\n

Example 3:

\n\n
\nInput: arr = [10000,10000]\nOutput: [10000,10000]\n
\n\n

Example 4:

\n\n
\nInput: arr = [2,3,5,7,11,13,17,19]\nOutput: [2,3,5,17,7,11,13,19]\n
\n\n

Example 5:

\n\n
\nInput: arr = [10,100,1000,10000]\nOutput: [10,100,10000,1000]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= arr.length <= 500
  • \n\t
  • 0 <= arr[i] <= 10^4
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr \u3002\u8bf7\u4f60\u5c06\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u6309\u7167\u5176\u4e8c\u8fdb\u5236\u8868\u793a\u4e2d\u6570\u5b57 1 \u7684\u6570\u76ee\u5347\u5e8f\u6392\u5e8f\u3002

\n\n

\u5982\u679c\u5b58\u5728\u591a\u4e2a\u6570\u5b57\u4e8c\u8fdb\u5236\u4e2d 1 \u7684\u6570\u76ee\u76f8\u540c\uff0c\u5219\u5fc5\u987b\u5c06\u5b83\u4eec\u6309\u7167\u6570\u503c\u5927\u5c0f\u5347\u5e8f\u6392\u5217\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u6392\u5e8f\u540e\u7684\u6570\u7ec4\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aarr = [0,1,2,3,4,5,6,7,8]\n\u8f93\u51fa\uff1a[0,1,2,4,8,3,5,6,7]\n\u89e3\u91ca\uff1a[0] \u662f\u552f\u4e00\u4e00\u4e2a\u6709 0 \u4e2a 1 \u7684\u6570\u3002\n[1,2,4,8] \u90fd\u6709 1 \u4e2a 1 \u3002\n[3,5,6] \u6709 2 \u4e2a 1 \u3002\n[7] \u6709 3 \u4e2a 1 \u3002\n\u6309\u7167 1 \u7684\u4e2a\u6570\u6392\u5e8f\u5f97\u5230\u7684\u7ed3\u679c\u6570\u7ec4\u4e3a [0,1,2,4,8,3,5,6,7]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aarr = [1024,512,256,128,64,32,16,8,4,2,1]\n\u8f93\u51fa\uff1a[1,2,4,8,16,32,64,128,256,512,1024]\n\u89e3\u91ca\uff1a\u6570\u7ec4\u4e2d\u6240\u6709\u6574\u6570\u4e8c\u8fdb\u5236\u4e0b\u90fd\u53ea\u6709 1 \u4e2a 1 \uff0c\u6240\u4ee5\u4f60\u9700\u8981\u6309\u7167\u6570\u503c\u5927\u5c0f\u5c06\u5b83\u4eec\u6392\u5e8f\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aarr = [10000,10000]\n\u8f93\u51fa\uff1a[10000,10000]\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1aarr = [2,3,5,7,11,13,17,19]\n\u8f93\u51fa\uff1a[2,3,5,17,7,11,13,19]\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1aarr = [10,100,1000,10000]\n\u8f93\u51fa\uff1a[10,100,10000,1000]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= arr.length <= 500
  • \n\t
  • 0 <= arr[i] <= 10^4
  • \n
\n", "tags_en": ["Sort", "Bit Manipulation"], "tags_cn": ["\u6392\u5e8f", "\u4f4d\u8fd0\u7b97"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector sortByBits(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] sortByBits(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def sortByBits(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def sortByBits(self, arr: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* sortByBits(int* arr, int arrSize, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] SortByBits(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number[]}\n */\nvar sortByBits = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer[]}\ndef sort_by_bits(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func sortByBits(_ arr: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func sortByBits(arr []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def sortByBits(arr: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun sortByBits(arr: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sort_by_bits(arr: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer[]\n */\n function sortByBits($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function sortByBits(arr: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (sort-by-bits arr)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1356](https://leetcode-cn.com/problems/sort-integers-by-the-number-of-1-bits)", "[\u6839\u636e\u6570\u5b57\u4e8c\u8fdb\u5236\u4e0b 1 \u7684\u6570\u76ee\u6392\u5e8f](/solution/1300-1399/1356.Sort%20Integers%20by%20The%20Number%20of%201%20Bits/README.md)", "`\u6392\u5e8f`,`\u4f4d\u8fd0\u7b97`", "\u7b80\u5355", ""], "md_table_row_en": ["[1356](https://leetcode.com/problems/sort-integers-by-the-number-of-1-bits)", "[Sort Integers by The Number of 1 Bits](/solution/1300-1399/1356.Sort%20Integers%20by%20The%20Number%20of%201%20Bits/README_EN.md)", "`Sort`,`Bit Manipulation`", "Easy", ""]}, {"question_id": "1457", "frontend_question_id": "1335", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-difficulty-of-a-job-schedule", "url_en": "https://leetcode.com/problems/minimum-difficulty-of-a-job-schedule", "relative_path_cn": "/solution/1300-1399/1335.Minimum%20Difficulty%20of%20a%20Job%20Schedule/README.md", "relative_path_en": "/solution/1300-1399/1335.Minimum%20Difficulty%20of%20a%20Job%20Schedule/README_EN.md", "title_cn": "\u5de5\u4f5c\u8ba1\u5212\u7684\u6700\u4f4e\u96be\u5ea6", "title_en": "Minimum Difficulty of a Job Schedule", "question_title_slug": "minimum-difficulty-of-a-job-schedule", "content_en": "

You want to schedule a list of jobs in d days. Jobs are dependent (i.e To work on the i-th job, you have to finish all the jobs j where 0 <= j < i).

\r\n\r\n

You have to finish at least one task every day. The difficulty of a job schedule is the sum of difficulties of each day of the d days. The difficulty of a day is the maximum difficulty of a job done in that day.

\r\n\r\n

Given an array of integers jobDifficulty and an integer d. The difficulty of the i-th job is jobDifficulty[i].

\r\n\r\n

Return the minimum difficulty of a job schedule. If you cannot find a schedule for the jobs return -1.

\r\n\r\n

 

\r\n

Example 1:

\r\n\"\"\r\n
\r\nInput: jobDifficulty = [6,5,4,3,2,1], d = 2\r\nOutput: 7\r\nExplanation: First day you can finish the first 5 jobs, total difficulty = 6.\r\nSecond day you can finish the last job, total difficulty = 1.\r\nThe difficulty of the schedule = 6 + 1 = 7 \r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: jobDifficulty = [9,9,9], d = 4\r\nOutput: -1\r\nExplanation: If you finish a job per day you will still have a free day. you cannot find a schedule for the given jobs.\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: jobDifficulty = [1,1,1], d = 3\r\nOutput: 3\r\nExplanation: The schedule is one job per day. total difficulty will be 3.\r\n
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: jobDifficulty = [7,1,7,1,7,1], d = 3\r\nOutput: 15\r\n
\r\n\r\n

Example 5:

\r\n\r\n
\r\nInput: jobDifficulty = [11,111,22,222,33,333,44,444], d = 6\r\nOutput: 843\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= jobDifficulty.length <= 300
  • \r\n\t
  • 0 <= jobDifficulty[i] <= 1000
  • \r\n\t
  • 1 <= d <= 10
  • \r\n
", "content_cn": "

\u4f60\u9700\u8981\u5236\u5b9a\u4e00\u4efd d \u5929\u7684\u5de5\u4f5c\u8ba1\u5212\u8868\u3002\u5de5\u4f5c\u4e4b\u95f4\u5b58\u5728\u4f9d\u8d56\uff0c\u8981\u60f3\u6267\u884c\u7b2c i \u9879\u5de5\u4f5c\uff0c\u4f60\u5fc5\u987b\u5b8c\u6210\u5168\u90e8 j \u9879\u5de5\u4f5c\uff08 0 <= j < i\uff09\u3002

\n\n

\u4f60\u6bcf\u5929 \u81f3\u5c11 \u9700\u8981\u5b8c\u6210\u4e00\u9879\u4efb\u52a1\u3002\u5de5\u4f5c\u8ba1\u5212\u7684\u603b\u96be\u5ea6\u662f\u8fd9 d \u5929\u6bcf\u4e00\u5929\u7684\u96be\u5ea6\u4e4b\u548c\uff0c\u800c\u4e00\u5929\u7684\u5de5\u4f5c\u96be\u5ea6\u662f\u5f53\u5929\u5e94\u8be5\u5b8c\u6210\u5de5\u4f5c\u7684\u6700\u5927\u96be\u5ea6\u3002

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 jobDifficulty \u548c\u4e00\u4e2a\u6574\u6570 d\uff0c\u5206\u522b\u4ee3\u8868\u5de5\u4f5c\u96be\u5ea6\u548c\u9700\u8981\u8ba1\u5212\u7684\u5929\u6570\u3002\u7b2c i \u9879\u5de5\u4f5c\u7684\u96be\u5ea6\u662f jobDifficulty[i]\u3002

\n\n

\u8fd4\u56de\u6574\u4e2a\u5de5\u4f5c\u8ba1\u5212\u7684 \u6700\u5c0f\u96be\u5ea6 \u3002\u5982\u679c\u65e0\u6cd5\u5236\u5b9a\u5de5\u4f5c\u8ba1\u5212\uff0c\u5219\u8fd4\u56de -1 \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1ajobDifficulty = [6,5,4,3,2,1], d = 2\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\u7b2c\u4e00\u5929\uff0c\u60a8\u53ef\u4ee5\u5b8c\u6210\u524d 5 \u9879\u5de5\u4f5c\uff0c\u603b\u96be\u5ea6 = 6.\n\u7b2c\u4e8c\u5929\uff0c\u60a8\u53ef\u4ee5\u5b8c\u6210\u6700\u540e\u4e00\u9879\u5de5\u4f5c\uff0c\u603b\u96be\u5ea6 = 1.\n\u8ba1\u5212\u8868\u7684\u96be\u5ea6 = 6 + 1 = 7 \n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1ajobDifficulty = [9,9,9], d = 4\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u5c31\u7b97\u4f60\u6bcf\u5929\u5b8c\u6210\u4e00\u9879\u5de5\u4f5c\uff0c\u4ecd\u7136\u6709\u4e00\u5929\u662f\u7a7a\u95f2\u7684\uff0c\u4f60\u65e0\u6cd5\u5236\u5b9a\u4e00\u4efd\u80fd\u591f\u6ee1\u8db3\u65e2\u5b9a\u5de5\u4f5c\u65f6\u95f4\u7684\u8ba1\u5212\u8868\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1ajobDifficulty = [1,1,1], d = 3\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u5de5\u4f5c\u8ba1\u5212\u4e3a\u6bcf\u5929\u4e00\u9879\u5de5\u4f5c\uff0c\u603b\u96be\u5ea6\u4e3a 3 \u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1ajobDifficulty = [7,1,7,1,7,1], d = 3\n\u8f93\u51fa\uff1a15\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1ajobDifficulty = [11,111,22,222,33,333,44,444], d = 6\n\u8f93\u51fa\uff1a843\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= jobDifficulty.length <= 300
  • \n\t
  • 0 <= jobDifficulty[i] <= 1000
  • \n\t
  • 1 <= d <= 10
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minDifficulty(vector& jobDifficulty, int d) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minDifficulty(int[] jobDifficulty, int d) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minDifficulty(self, jobDifficulty, d):\n \"\"\"\n :type jobDifficulty: List[int]\n :type d: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minDifficulty(self, jobDifficulty: List[int], d: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minDifficulty(int* jobDifficulty, int jobDifficultySize, int d){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinDifficulty(int[] jobDifficulty, int d) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} jobDifficulty\n * @param {number} d\n * @return {number}\n */\nvar minDifficulty = function(jobDifficulty, d) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} job_difficulty\n# @param {Integer} d\n# @return {Integer}\ndef min_difficulty(job_difficulty, d)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minDifficulty(_ jobDifficulty: [Int], _ d: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minDifficulty(jobDifficulty []int, d int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minDifficulty(jobDifficulty: Array[Int], d: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minDifficulty(jobDifficulty: IntArray, d: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_difficulty(job_difficulty: Vec, d: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $jobDifficulty\n * @param Integer $d\n * @return Integer\n */\n function minDifficulty($jobDifficulty, $d) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minDifficulty(jobDifficulty: number[], d: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-difficulty jobDifficulty d)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1335](https://leetcode-cn.com/problems/minimum-difficulty-of-a-job-schedule)", "[\u5de5\u4f5c\u8ba1\u5212\u7684\u6700\u4f4e\u96be\u5ea6](/solution/1300-1399/1335.Minimum%20Difficulty%20of%20a%20Job%20Schedule/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1335](https://leetcode.com/problems/minimum-difficulty-of-a-job-schedule)", "[Minimum Difficulty of a Job Schedule](/solution/1300-1399/1335.Minimum%20Difficulty%20of%20a%20Job%20Schedule/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1456", "frontend_question_id": "1334", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance", "url_en": "https://leetcode.com/problems/find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance", "relative_path_cn": "/solution/1300-1399/1334.Find%20the%20City%20With%20the%20Smallest%20Number%20of%20Neighbors%20at%20a%20Threshold%20Distance/README.md", "relative_path_en": "/solution/1300-1399/1334.Find%20the%20City%20With%20the%20Smallest%20Number%20of%20Neighbors%20at%20a%20Threshold%20Distance/README_EN.md", "title_cn": "\u9608\u503c\u8ddd\u79bb\u5185\u90bb\u5c45\u6700\u5c11\u7684\u57ce\u5e02", "title_en": "Find the City With the Smallest Number of Neighbors at a Threshold Distance", "question_title_slug": "find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance", "content_en": "

There are n cities numbered from 0 to n-1. Given the array edges where edges[i] = [fromi, toi, weighti] represents a bidirectional and weighted edge between cities fromi and toi, and given the integer distanceThreshold.

\n\n

Return the city with the smallest number of cities that are reachable through some path and whose distance is at most distanceThreshold, If there are multiple such cities, return the city with the greatest number.

\n\n

Notice that the distance of a path connecting cities i and j is equal to the sum of the edges' weights along that path.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: n = 4, edges = [[0,1,3],[1,2,1],[1,3,4],[2,3,1]], distanceThreshold = 4\nOutput: 3\nExplanation: The figure above describes the graph. \nThe neighboring cities at a distanceThreshold = 4 for each city are:\nCity 0 -> [City 1, City 2] \nCity 1 -> [City 0, City 2, City 3] \nCity 2 -> [City 0, City 1, City 3] \nCity 3 -> [City 1, City 2] \nCities 0 and 3 have 2 neighboring cities at a distanceThreshold = 4, but we have to return city 3 since it has the greatest number.\n
\n\n

Example 2:

\n\"\"\n
\nInput: n = 5, edges = [[0,1,2],[0,4,8],[1,2,3],[1,4,2],[2,3,1],[3,4,1]], distanceThreshold = 2\nOutput: 0\nExplanation: The figure above describes the graph. \nThe neighboring cities at a distanceThreshold = 2 for each city are:\nCity 0 -> [City 1] \nCity 1 -> [City 0, City 4] \nCity 2 -> [City 3, City 4] \nCity 3 -> [City 2, City 4]\nCity 4 -> [City 1, City 2, City 3] \nThe city 0 has 1 neighboring city at a distanceThreshold = 2.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= n <= 100
  • \n\t
  • 1 <= edges.length <= n * (n - 1) / 2
  • \n\t
  • edges[i].length == 3
  • \n\t
  • 0 <= fromi < toi < n
  • \n\t
  • 1 <= weighti, distanceThreshold <= 10^4
  • \n\t
  • All pairs (fromi, toi) are distinct.
  • \n
\n", "content_cn": "

\u6709 n\u00a0\u4e2a\u57ce\u5e02\uff0c\u6309\u4ece 0 \u5230 n-1\u00a0\u7f16\u53f7\u3002\u7ed9\u4f60\u4e00\u4e2a\u8fb9\u6570\u7ec4\u00a0edges\uff0c\u5176\u4e2d edges[i] = [fromi, toi, weighti]\u00a0\u4ee3\u8868\u00a0fromi\u00a0\u548c\u00a0toi\u00a0\u4e24\u4e2a\u57ce\u5e02\u4e4b\u95f4\u7684\u53cc\u5411\u52a0\u6743\u8fb9\uff0c\u8ddd\u79bb\u9608\u503c\u662f\u4e00\u4e2a\u6574\u6570\u00a0distanceThreshold\u3002

\n\n

\u8fd4\u56de\u80fd\u901a\u8fc7\u67d0\u4e9b\u8def\u5f84\u5230\u8fbe\u5176\u4ed6\u57ce\u5e02\u6570\u76ee\u6700\u5c11\u3001\u4e14\u8def\u5f84\u8ddd\u79bb \u6700\u5927 \u4e3a\u00a0distanceThreshold\u00a0\u7684\u57ce\u5e02\u3002\u5982\u679c\u6709\u591a\u4e2a\u8fd9\u6837\u7684\u57ce\u5e02\uff0c\u5219\u8fd4\u56de\u7f16\u53f7\u6700\u5927\u7684\u57ce\u5e02\u3002

\n\n

\u6ce8\u610f\uff0c\u8fde\u63a5\u57ce\u5e02 i \u548c j \u7684\u8def\u5f84\u7684\u8ddd\u79bb\u7b49\u4e8e\u6cbf\u8be5\u8def\u5f84\u7684\u6240\u6709\u8fb9\u7684\u6743\u91cd\u4e4b\u548c\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1an = 4, edges = [[0,1,3],[1,2,1],[1,3,4],[2,3,1]], distanceThreshold = 4\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u57ce\u5e02\u5206\u5e03\u56fe\u5982\u4e0a\u3002\n\u6bcf\u4e2a\u57ce\u5e02\u9608\u503c\u8ddd\u79bb distanceThreshold = 4 \u5185\u7684\u90bb\u5c45\u57ce\u5e02\u5206\u522b\u662f\uff1a\n\u57ce\u5e02 0 -> [\u57ce\u5e02 1, \u57ce\u5e02 2]\u00a0\n\u57ce\u5e02 1 -> [\u57ce\u5e02 0, \u57ce\u5e02 2, \u57ce\u5e02 3]\u00a0\n\u57ce\u5e02 2 -> [\u57ce\u5e02 0, \u57ce\u5e02 1, \u57ce\u5e02 3]\u00a0\n\u57ce\u5e02 3 -> [\u57ce\u5e02 1, \u57ce\u5e02 2]\u00a0\n\u57ce\u5e02 0 \u548c 3 \u5728\u9608\u503c\u8ddd\u79bb 4 \u4ee5\u5185\u90fd\u6709 2 \u4e2a\u90bb\u5c45\u57ce\u5e02\uff0c\u4f46\u662f\u6211\u4eec\u5fc5\u987b\u8fd4\u56de\u57ce\u5e02 3\uff0c\u56e0\u4e3a\u5b83\u7684\u7f16\u53f7\u6700\u5927\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1an = 5, edges = [[0,1,2],[0,4,8],[1,2,3],[1,4,2],[2,3,1],[3,4,1]], distanceThreshold = 2\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u57ce\u5e02\u5206\u5e03\u56fe\u5982\u4e0a\u3002\u00a0\n\u6bcf\u4e2a\u57ce\u5e02\u9608\u503c\u8ddd\u79bb distanceThreshold = 2 \u5185\u7684\u90bb\u5c45\u57ce\u5e02\u5206\u522b\u662f\uff1a\n\u57ce\u5e02 0 -> [\u57ce\u5e02 1]\u00a0\n\u57ce\u5e02 1 -> [\u57ce\u5e02 0, \u57ce\u5e02 4]\u00a0\n\u57ce\u5e02 2 -> [\u57ce\u5e02 3, \u57ce\u5e02 4]\u00a0\n\u57ce\u5e02 3 -> [\u57ce\u5e02 2, \u57ce\u5e02 4]\n\u57ce\u5e02 4 -> [\u57ce\u5e02 1, \u57ce\u5e02 2, \u57ce\u5e02 3]\u00a0\n\u57ce\u5e02 0 \u5728\u9608\u503c\u8ddd\u79bb 2 \u4ee5\u5185\u53ea\u6709 1 \u4e2a\u90bb\u5c45\u57ce\u5e02\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= n <= 100
  • \n\t
  • 1 <= edges.length <= n * (n - 1) / 2
  • \n\t
  • edges[i].length == 3
  • \n\t
  • 0 <= fromi < toi < n
  • \n\t
  • 1 <= weighti,\u00a0distanceThreshold <= 10^4
  • \n\t
  • \u6240\u6709 (fromi, toi)\u00a0\u90fd\u662f\u4e0d\u540c\u7684\u3002
  • \n
\n", "tags_en": ["Graph"], "tags_cn": ["\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findTheCity(int n, vector>& edges, int distanceThreshold) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findTheCity(int n, int[][] edges, int distanceThreshold) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findTheCity(self, n, edges, distanceThreshold):\n \"\"\"\n :type n: int\n :type edges: List[List[int]]\n :type distanceThreshold: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findTheCity(self, n: int, edges: List[List[int]], distanceThreshold: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findTheCity(int n, int** edges, int edgesSize, int* edgesColSize, int distanceThreshold){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindTheCity(int n, int[][] edges, int distanceThreshold) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} edges\n * @param {number} distanceThreshold\n * @return {number}\n */\nvar findTheCity = function(n, edges, distanceThreshold) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} edges\n# @param {Integer} distance_threshold\n# @return {Integer}\ndef find_the_city(n, edges, distance_threshold)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findTheCity(_ n: Int, _ edges: [[Int]], _ distanceThreshold: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findTheCity(n int, edges [][]int, distanceThreshold int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findTheCity(n: Int, edges: Array[Array[Int]], distanceThreshold: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findTheCity(n: Int, edges: Array, distanceThreshold: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_the_city(n: i32, edges: Vec>, distance_threshold: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $edges\n * @param Integer $distanceThreshold\n * @return Integer\n */\n function findTheCity($n, $edges, $distanceThreshold) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findTheCity(n: number, edges: number[][], distanceThreshold: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-the-city n edges distanceThreshold)\n (-> exact-integer? (listof (listof exact-integer?)) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1334](https://leetcode-cn.com/problems/find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance)", "[\u9608\u503c\u8ddd\u79bb\u5185\u90bb\u5c45\u6700\u5c11\u7684\u57ce\u5e02](/solution/1300-1399/1334.Find%20the%20City%20With%20the%20Smallest%20Number%20of%20Neighbors%20at%20a%20Threshold%20Distance/README.md)", "`\u56fe`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1334](https://leetcode.com/problems/find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance)", "[Find the City With the Smallest Number of Neighbors at a Threshold Distance](/solution/1300-1399/1334.Find%20the%20City%20With%20the%20Smallest%20Number%20of%20Neighbors%20at%20a%20Threshold%20Distance/README_EN.md)", "`Graph`", "Medium", ""]}, {"question_id": "1455", "frontend_question_id": "1333", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/filter-restaurants-by-vegan-friendly-price-and-distance", "url_en": "https://leetcode.com/problems/filter-restaurants-by-vegan-friendly-price-and-distance", "relative_path_cn": "/solution/1300-1399/1333.Filter%20Restaurants%20by%20Vegan-Friendly%2C%20Price%20and%20Distance/README.md", "relative_path_en": "/solution/1300-1399/1333.Filter%20Restaurants%20by%20Vegan-Friendly%2C%20Price%20and%20Distance/README_EN.md", "title_cn": "\u9910\u5385\u8fc7\u6ee4\u5668", "title_en": "Filter Restaurants by Vegan-Friendly, Price and Distance", "question_title_slug": "filter-restaurants-by-vegan-friendly-price-and-distance", "content_en": "

Given the array restaurants where  restaurants[i] = [idi, ratingi, veganFriendlyi, pricei, distancei]. You have to filter the restaurants using three filters.

\n\n

The veganFriendly filter will be either true (meaning you should only include restaurants with veganFriendlyi set to true) or false (meaning you can include any restaurant). In addition, you have the filters maxPrice and maxDistance which are the maximum value for price and distance of restaurants you should consider respectively.

\n\n

Return the array of restaurant IDs after filtering, ordered by rating from highest to lowest. For restaurants with the same rating, order them by id from highest to lowest. For simplicity veganFriendlyi and veganFriendly take value 1 when it is true, and 0 when it is false.

\n\n

 

\n

Example 1:

\n\n
\nInput: restaurants = [[1,4,1,40,10],[2,8,0,50,5],[3,8,1,30,4],[4,10,0,10,3],[5,1,1,15,1]], veganFriendly = 1, maxPrice = 50, maxDistance = 10\nOutput: [3,1,5] \nExplanation: \nThe restaurants are:\nRestaurant 1 [id=1, rating=4, veganFriendly=1, price=40, distance=10]\nRestaurant 2 [id=2, rating=8, veganFriendly=0, price=50, distance=5]\nRestaurant 3 [id=3, rating=8, veganFriendly=1, price=30, distance=4]\nRestaurant 4 [id=4, rating=10, veganFriendly=0, price=10, distance=3]\nRestaurant 5 [id=5, rating=1, veganFriendly=1, price=15, distance=1] \nAfter filter restaurants with veganFriendly = 1, maxPrice = 50 and maxDistance = 10 we have restaurant 3, restaurant 1 and restaurant 5 (ordered by rating from highest to lowest). \n
\n\n

Example 2:

\n\n
\nInput: restaurants = [[1,4,1,40,10],[2,8,0,50,5],[3,8,1,30,4],[4,10,0,10,3],[5,1,1,15,1]], veganFriendly = 0, maxPrice = 50, maxDistance = 10\nOutput: [4,3,2,1,5]\nExplanation: The restaurants are the same as in example 1, but in this case the filter veganFriendly = 0, therefore all restaurants are considered.\n
\n\n

Example 3:

\n\n
\nInput: restaurants = [[1,4,1,40,10],[2,8,0,50,5],[3,8,1,30,4],[4,10,0,10,3],[5,1,1,15,1]], veganFriendly = 0, maxPrice = 30, maxDistance = 3\nOutput: [4,5]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= restaurants.length <= 10^4
  • \n\t
  • restaurants[i].length == 5
  • \n\t
  • 1 <= idi, ratingi, pricei, distancei <= 10^5
  • \n\t
  • 1 <= maxPrice, maxDistance <= 10^5
  • \n\t
  • veganFriendlyi and veganFriendly are 0 or 1.
  • \n\t
  • All idi are distinct.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u9910\u9986\u4fe1\u606f\u6570\u7ec4 restaurants\uff0c\u5176\u4e2d  restaurants[i] = [idi, ratingi, veganFriendlyi, pricei, distancei]\u3002\u4f60\u5fc5\u987b\u4f7f\u7528\u4ee5\u4e0b\u4e09\u4e2a\u8fc7\u6ee4\u5668\u6765\u8fc7\u6ee4\u8fd9\u4e9b\u9910\u9986\u4fe1\u606f\u3002

\n\n

\u5176\u4e2d\u7d20\u98df\u8005\u53cb\u597d\u8fc7\u6ee4\u5668 veganFriendly \u7684\u503c\u53ef\u4ee5\u4e3a true \u6216\u8005 false\uff0c\u5982\u679c\u4e3a true \u5c31\u610f\u5473\u7740\u4f60\u5e94\u8be5\u53ea\u5305\u62ec veganFriendlyi \u4e3a true \u7684\u9910\u9986\uff0c\u4e3a false \u5219\u610f\u5473\u7740\u53ef\u4ee5\u5305\u62ec\u4efb\u4f55\u9910\u9986\u3002\u6b64\u5916\uff0c\u6211\u4eec\u8fd8\u6709\u6700\u5927\u4ef7\u683c maxPrice \u548c\u6700\u5927\u8ddd\u79bb maxDistance \u4e24\u4e2a\u8fc7\u6ee4\u5668\uff0c\u5b83\u4eec\u5206\u522b\u8003\u8651\u9910\u5385\u7684\u4ef7\u683c\u56e0\u7d20\u548c\u8ddd\u79bb\u56e0\u7d20\u7684\u6700\u5927\u503c\u3002

\n\n

\u8fc7\u6ee4\u540e\u8fd4\u56de\u9910\u9986\u7684 id\uff0c\u6309\u7167 rating \u4ece\u9ad8\u5230\u4f4e\u6392\u5e8f\u3002\u5982\u679c rating \u76f8\u540c\uff0c\u90a3\u4e48\u6309 id \u4ece\u9ad8\u5230\u4f4e\u6392\u5e8f\u3002\u7b80\u5355\u8d77\u89c1\uff0c veganFriendlyi \u548c veganFriendly \u4e3a true \u65f6\u53d6\u503c\u4e3a 1\uff0c\u4e3a false \u65f6\uff0c\u53d6\u503c\u4e3a 0 \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1arestaurants = [[1,4,1,40,10],[2,8,0,50,5],[3,8,1,30,4],[4,10,0,10,3],[5,1,1,15,1]], veganFriendly = 1, maxPrice = 50, maxDistance = 10\n\u8f93\u51fa\uff1a[3,1,5] \n\u89e3\u91ca\uff1a \n\u8fd9\u4e9b\u9910\u9986\u4e3a\uff1a\n\u9910\u9986 1 [id=1, rating=4, veganFriendly=1, price=40, distance=10]\n\u9910\u9986 2 [id=2, rating=8, veganFriendly=0, price=50, distance=5]\n\u9910\u9986 3 [id=3, rating=8, veganFriendly=1, price=30, distance=4]\n\u9910\u9986 4 [id=4, rating=10, veganFriendly=0, price=10, distance=3]\n\u9910\u9986 5 [id=5, rating=1, veganFriendly=1, price=15, distance=1] \n\u5728\u6309\u7167 veganFriendly = 1, maxPrice = 50 \u548c maxDistance = 10 \u8fdb\u884c\u8fc7\u6ee4\u540e\uff0c\u6211\u4eec\u5f97\u5230\u4e86\u9910\u9986 3, \u9910\u9986 1 \u548c \u9910\u9986 5\uff08\u6309\u8bc4\u5206\u4ece\u9ad8\u5230\u4f4e\u6392\u5e8f\uff09\u3002 \n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1arestaurants = [[1,4,1,40,10],[2,8,0,50,5],[3,8,1,30,4],[4,10,0,10,3],[5,1,1,15,1]], veganFriendly = 0, maxPrice = 50, maxDistance = 10\n\u8f93\u51fa\uff1a[4,3,2,1,5]\n\u89e3\u91ca\uff1a\u9910\u9986\u4e0e\u793a\u4f8b 1 \u76f8\u540c\uff0c\u4f46\u5728 veganFriendly = 0 \u7684\u8fc7\u6ee4\u6761\u4ef6\u4e0b\uff0c\u5e94\u8be5\u8003\u8651\u6240\u6709\u9910\u9986\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1arestaurants = [[1,4,1,40,10],[2,8,0,50,5],[3,8,1,30,4],[4,10,0,10,3],[5,1,1,15,1]], veganFriendly = 0, maxPrice = 30, maxDistance = 3\n\u8f93\u51fa\uff1a[4,5]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= restaurants.length <= 10^4
  • \n\t
  • restaurants[i].length == 5
  • \n\t
  • 1 <= idi, ratingi, pricei, distancei <= 10^5
  • \n\t
  • 1 <= maxPrice, maxDistance <= 10^5
  • \n\t
  • veganFriendlyi \u548c veganFriendly \u7684\u503c\u4e3a 0 \u6216 1 \u3002
  • \n\t
  • \u6240\u6709 idi \u5404\u4e0d\u76f8\u540c\u3002
  • \n
\n", "tags_en": ["Sort", "Array"], "tags_cn": ["\u6392\u5e8f", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector filterRestaurants(vector>& restaurants, int veganFriendly, int maxPrice, int maxDistance) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List filterRestaurants(int[][] restaurants, int veganFriendly, int maxPrice, int maxDistance) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def filterRestaurants(self, restaurants, veganFriendly, maxPrice, maxDistance):\n \"\"\"\n :type restaurants: List[List[int]]\n :type veganFriendly: int\n :type maxPrice: int\n :type maxDistance: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def filterRestaurants(self, restaurants: List[List[int]], veganFriendly: int, maxPrice: int, maxDistance: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* filterRestaurants(int** restaurants, int restaurantsSize, int* restaurantsColSize, int veganFriendly, int maxPrice, int maxDistance, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList FilterRestaurants(int[][] restaurants, int veganFriendly, int maxPrice, int maxDistance) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} restaurants\n * @param {number} veganFriendly\n * @param {number} maxPrice\n * @param {number} maxDistance\n * @return {number[]}\n */\nvar filterRestaurants = function(restaurants, veganFriendly, maxPrice, maxDistance) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} restaurants\n# @param {Integer} vegan_friendly\n# @param {Integer} max_price\n# @param {Integer} max_distance\n# @return {Integer[]}\ndef filter_restaurants(restaurants, vegan_friendly, max_price, max_distance)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func filterRestaurants(_ restaurants: [[Int]], _ veganFriendly: Int, _ maxPrice: Int, _ maxDistance: Int) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func filterRestaurants(restaurants [][]int, veganFriendly int, maxPrice int, maxDistance int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def filterRestaurants(restaurants: Array[Array[Int]], veganFriendly: Int, maxPrice: Int, maxDistance: Int): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun filterRestaurants(restaurants: Array, veganFriendly: Int, maxPrice: Int, maxDistance: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn filter_restaurants(restaurants: Vec>, vegan_friendly: i32, max_price: i32, max_distance: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $restaurants\n * @param Integer $veganFriendly\n * @param Integer $maxPrice\n * @param Integer $maxDistance\n * @return Integer[]\n */\n function filterRestaurants($restaurants, $veganFriendly, $maxPrice, $maxDistance) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function filterRestaurants(restaurants: number[][], veganFriendly: number, maxPrice: number, maxDistance: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (filter-restaurants restaurants veganFriendly maxPrice maxDistance)\n (-> (listof (listof exact-integer?)) exact-integer? exact-integer? exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1333](https://leetcode-cn.com/problems/filter-restaurants-by-vegan-friendly-price-and-distance)", "[\u9910\u5385\u8fc7\u6ee4\u5668](/solution/1300-1399/1333.Filter%20Restaurants%20by%20Vegan-Friendly%2C%20Price%20and%20Distance/README.md)", "`\u6392\u5e8f`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1333](https://leetcode.com/problems/filter-restaurants-by-vegan-friendly-price-and-distance)", "[Filter Restaurants by Vegan-Friendly, Price and Distance](/solution/1300-1399/1333.Filter%20Restaurants%20by%20Vegan-Friendly%2C%20Price%20and%20Distance/README_EN.md)", "`Sort`,`Array`", "Medium", ""]}, {"question_id": "1454", "frontend_question_id": "1332", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/remove-palindromic-subsequences", "url_en": "https://leetcode.com/problems/remove-palindromic-subsequences", "relative_path_cn": "/solution/1300-1399/1332.Remove%20Palindromic%20Subsequences/README.md", "relative_path_en": "/solution/1300-1399/1332.Remove%20Palindromic%20Subsequences/README_EN.md", "title_cn": "\u5220\u9664\u56de\u6587\u5b50\u5e8f\u5217", "title_en": "Remove Palindromic Subsequences", "question_title_slug": "remove-palindromic-subsequences", "content_en": "

You are given a string s consisting only of letters 'a' and 'b'. In a single step you can remove one palindromic subsequence from s.

\n\n

Return the minimum number of steps to make the given string empty.

\n\n

A string is a subsequence of a given string if it is generated by deleting some characters of a given string without changing its order. Note that a subsequence does not necessarily need to be contiguous.

\n\n

A string is called palindrome if is one that reads the same backward as well as forward.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "ababa"\nOutput: 1\nExplanation: s is already a palindrome, so its entirety can be removed in a single step.\n
\n\n

Example 2:

\n\n
\nInput: s = "abb"\nOutput: 2\nExplanation: "abb" -> "bb" -> "". \nRemove palindromic subsequence "a" then "bb".\n
\n\n

Example 3:

\n\n
\nInput: s = "baabb"\nOutput: 2\nExplanation: "baabb" -> "b" -> "". \nRemove palindromic subsequence "baab" then "b".\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 1000
  • \n\t
  • s[i] is either 'a' or 'b'.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s\uff0c\u5b83\u4ec5\u7531\u5b57\u6bcd 'a' \u548c 'b' \u7ec4\u6210\u3002\u6bcf\u4e00\u6b21\u5220\u9664\u64cd\u4f5c\u90fd\u53ef\u4ee5\u4ece s \u4e2d\u5220\u9664\u4e00\u4e2a\u56de\u6587 \u5b50\u5e8f\u5217\u3002

\n\n

\u8fd4\u56de\u5220\u9664\u7ed9\u5b9a\u5b57\u7b26\u4e32\u4e2d\u6240\u6709\u5b57\u7b26\uff08\u5b57\u7b26\u4e32\u4e3a\u7a7a\uff09\u7684\u6700\u5c0f\u5220\u9664\u6b21\u6570\u3002

\n\n

\u300c\u5b50\u5e8f\u5217\u300d\u5b9a\u4e49\uff1a\u5982\u679c\u4e00\u4e2a\u5b57\u7b26\u4e32\u53ef\u4ee5\u901a\u8fc7\u5220\u9664\u539f\u5b57\u7b26\u4e32\u67d0\u4e9b\u5b57\u7b26\u800c\u4e0d\u6539\u53d8\u539f\u5b57\u7b26\u987a\u5e8f\u5f97\u5230\uff0c\u90a3\u4e48\u8fd9\u4e2a\u5b57\u7b26\u4e32\u5c31\u662f\u539f\u5b57\u7b26\u4e32\u7684\u4e00\u4e2a\u5b50\u5e8f\u5217\u3002

\n\n

\u300c\u56de\u6587\u300d\u5b9a\u4e49\uff1a\u5982\u679c\u4e00\u4e2a\u5b57\u7b26\u4e32\u5411\u540e\u548c\u5411\u524d\u8bfb\u662f\u4e00\u81f4\u7684\uff0c\u90a3\u4e48\u8fd9\u4e2a\u5b57\u7b26\u4e32\u5c31\u662f\u4e00\u4e2a\u56de\u6587\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1as = "ababa"\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u5b57\u7b26\u4e32\u672c\u8eab\u5c31\u662f\u56de\u6587\u5e8f\u5217\uff0c\u53ea\u9700\u8981\u5220\u9664\u4e00\u6b21\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1as = "abb"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a"abb" -> "bb" -> "". \n\u5148\u5220\u9664\u56de\u6587\u5b50\u5e8f\u5217 "a"\uff0c\u7136\u540e\u518d\u5220\u9664 "bb"\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1as = "baabb"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a"baabb" -> "b" -> "". \n\u5148\u5220\u9664\u56de\u6587\u5b50\u5e8f\u5217 "baab"\uff0c\u7136\u540e\u518d\u5220\u9664 "b"\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1as = ""\n\u8f93\u51fa\uff1a0\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 0 <= s.length <= 1000
  • \n\t
  • s \u4ec5\u5305\u542b\u5b57\u6bcd 'a'  \u548c 'b'
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int removePalindromeSub(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int removePalindromeSub(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def removePalindromeSub(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def removePalindromeSub(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint removePalindromeSub(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int RemovePalindromeSub(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar removePalindromeSub = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef remove_palindrome_sub(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func removePalindromeSub(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func removePalindromeSub(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def removePalindromeSub(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun removePalindromeSub(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn remove_palindrome_sub(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function removePalindromeSub($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function removePalindromeSub(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (remove-palindrome-sub s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1332](https://leetcode-cn.com/problems/remove-palindromic-subsequences)", "[\u5220\u9664\u56de\u6587\u5b50\u5e8f\u5217](/solution/1300-1399/1332.Remove%20Palindromic%20Subsequences/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1332](https://leetcode.com/problems/remove-palindromic-subsequences)", "[Remove Palindromic Subsequences](/solution/1300-1399/1332.Remove%20Palindromic%20Subsequences/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1453", "frontend_question_id": "1322", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/ads-performance", "url_en": "https://leetcode.com/problems/ads-performance", "relative_path_cn": "/solution/1300-1399/1322.Ads%20Performance/README.md", "relative_path_en": "/solution/1300-1399/1322.Ads%20Performance/README_EN.md", "title_cn": "\u5e7f\u544a\u6548\u679c", "title_en": "Ads Performance", "question_title_slug": "ads-performance", "content_en": "

Table: Ads

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| ad_id         | int     |\n| user_id       | int     |\n| action        | enum    |\n+---------------+---------+\n(ad_id, user_id) is the primary key for this table.\nEach row of this table contains the ID of an Ad, the ID of a user and the action taken by this user regarding this Ad.\nThe action column is an ENUM type of ('Clicked', 'Viewed', 'Ignored').\n
\n\n

 

\n\n

A company is running Ads and wants to calculate the performance of each Ad.

\n\n

Performance of the Ad is measured using Click-Through Rate (CTR) where:

\n\n

\"\"

\n\n

Write an SQL query to find the ctr of each Ad.

\n\n

Round ctr to 2 decimal points. Order the result table by ctr in descending order and by ad_id in ascending order in case of a tie.

\n\n

The query result format is in the following example:

\n\n
\nAds table:\n+-------+---------+---------+\n| ad_id | user_id | action  |\n+-------+---------+---------+\n| 1     | 1       | Clicked |\n| 2     | 2       | Clicked |\n| 3     | 3       | Viewed  |\n| 5     | 5       | Ignored |\n| 1     | 7       | Ignored |\n| 2     | 7       | Viewed  |\n| 3     | 5       | Clicked |\n| 1     | 4       | Viewed  |\n| 2     | 11      | Viewed  |\n| 1     | 2       | Clicked |\n+-------+---------+---------+\nResult table:\n+-------+-------+\n| ad_id | ctr   |\n+-------+-------+\n| 1     | 66.67 |\n| 3     | 50.00 |\n| 2     | 33.33 |\n| 5     | 0.00  |\n+-------+-------+\nfor ad_id = 1, ctr = (2/(2+1)) * 100 = 66.67\nfor ad_id = 2, ctr = (1/(1+2)) * 100 = 33.33\nfor ad_id = 3, ctr = (1/(1+1)) * 100 = 50.00\nfor ad_id = 5, ctr = 0.00, Note that ad_id = 5 has no clicks or views.\nNote that we don't care about Ignored Ads.\nResult table is ordered by the ctr. in case of a tie we order them by ad_id\n
\n", "content_cn": "

\u8868: Ads

\n\n
+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| ad_id         | int     |\n| user_id       | int     |\n| action        | enum    |\n+---------------+---------+\n(ad_id, user_id) \u662f\u8be5\u8868\u7684\u4e3b\u952e\n\u8be5\u8868\u7684\u6bcf\u4e00\u884c\u5305\u542b\u4e00\u6761\u5e7f\u544a\u7684 ID(ad_id)\uff0c\u7528\u6237\u7684 ID(user_id) \u548c\u7528\u6237\u5bf9\u5e7f\u544a\u91c7\u53d6\u7684\u884c\u4e3a (action)\naction \u5217\u662f\u4e00\u4e2a\u679a\u4e3e\u7c7b\u578b ('Clicked', 'Viewed', 'Ignored') \u3002\n
\n\n

 

\n\n

\u4e00\u5bb6\u516c\u53f8\u6b63\u5728\u8fd0\u8425\u8fd9\u4e9b\u5e7f\u544a\u5e76\u60f3\u8ba1\u7b97\u6bcf\u6761\u5e7f\u544a\u7684\u6548\u679c\u3002

\n\n

\u5e7f\u544a\u6548\u679c\u7528\u70b9\u51fb\u901a\u8fc7\u7387\uff08Click-Through Rate\uff1aCTR\uff09\u6765\u8861\u91cf\uff0c\u516c\u5f0f\u5982\u4e0b:

\n\n

\"\"

\n\n

\u5199\u4e00\u6761SQL\u8bed\u53e5\u6765\u67e5\u8be2\u6bcf\u4e00\u6761\u5e7f\u544a\u7684 ctr \uff0c

\n\n

 ctr \u8981\u4fdd\u7559\u4e24\u4f4d\u5c0f\u6570\u3002\u7ed3\u679c\u9700\u8981\u6309 ctr \u964d\u5e8f\u3001\u6309 ad_id \u5347\u5e8f \u8fdb\u884c\u6392\u5e8f\u3002

\n\n

 

\n\n

\u67e5\u8be2\u7ed3\u679c\u793a\u4f8b\u5982\u4e0b\uff1a

\n\n
Ads \u8868:\n+-------+---------+---------+\n| ad_id | user_id | action  |\n+-------+---------+---------+\n| 1     | 1       | Clicked |\n| 2     | 2       | Clicked |\n| 3     | 3       | Viewed  |\n| 5     | 5       | Ignored |\n| 1     | 7       | Ignored |\n| 2     | 7       | Viewed  |\n| 3     | 5       | Clicked |\n| 1     | 4       | Viewed  |\n| 2     | 11      | Viewed  |\n| 1     | 2       | Clicked |\n+-------+---------+---------+\n\u7ed3\u679c\u8868:\n+-------+-------+\n| ad_id | ctr   |\n+-------+-------+\n| 1     | 66.67 |\n| 3     | 50.00 |\n| 2     | 33.33 |\n| 5     | 0.00  |\n+-------+-------+\n\u5bf9\u4e8e ad_id = 1, ctr = (2/(2+1)) * 100 = 66.67\n\u5bf9\u4e8e ad_id = 2, ctr = (1/(1+2)) * 100 = 33.33\n\u5bf9\u4e8e ad_id = 3, ctr = (1/(1+1)) * 100 = 50.00\n\u5bf9\u4e8e ad_id = 5, ctr = 0.00, \u6ce8\u610f ad_id = 5 \u6ca1\u6709\u88ab\u70b9\u51fb (Clicked) \u6216\u67e5\u770b (Viewed) \u8fc7\n\u6ce8\u610f\u6211\u4eec\u4e0d\u5173\u5fc3 action \u4e3a Ingnored \u7684\u5e7f\u544a\n\u7ed3\u679c\u6309 ctr\uff08\u964d\u5e8f\uff09\uff0cad_id\uff08\u5347\u5e8f\uff09\u6392\u5e8f\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1322](https://leetcode-cn.com/problems/ads-performance)", "[\u5e7f\u544a\u6548\u679c](/solution/1300-1399/1322.Ads%20Performance/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1322](https://leetcode.com/problems/ads-performance)", "[Ads Performance](/solution/1300-1399/1322.Ads%20Performance/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1452", "frontend_question_id": "1321", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/restaurant-growth", "url_en": "https://leetcode.com/problems/restaurant-growth", "relative_path_cn": "/solution/1300-1399/1321.Restaurant%20Growth/README.md", "relative_path_en": "/solution/1300-1399/1321.Restaurant%20Growth/README_EN.md", "title_cn": "\u9910\u9986\u8425\u4e1a\u989d\u53d8\u5316\u589e\u957f", "title_en": "Restaurant Growth", "question_title_slug": "restaurant-growth", "content_en": "

Table: Customer

\r\n\r\n
\r\n+---------------+---------+\r\n| Column Name   | Type    |\r\n+---------------+---------+\r\n| customer_id   | int     |\r\n| name          | varchar |\r\n| visited_on    | date    |\r\n| amount        | int     |\r\n+---------------+---------+\r\n(customer_id, visited_on) is the primary key for this table.\r\nThis table contains data about customer transactions in a restaurant.\r\nvisited_on is the date on which the customer with ID (customer_id) have visited the restaurant.\r\namount is the total paid by a customer.\r\n
\r\n\r\n

 

\r\n\r\n

You are the restaurant owner and you want to analyze a possible expansion (there will be at least one customer every day).

\r\n\r\n

Write an SQL query to compute moving average of how much customer paid in a 7 days window (current day + 6 days before) .

\r\n\r\n

The query result format is in the following example:

\r\n\r\n

Return result table ordered by visited_on.

\r\n\r\n

average_amount should be rounded to 2 decimal places, all dates are in the format ('YYYY-MM-DD').

\r\n\r\n

 

\r\n\r\n
\r\nCustomer table:\r\n+-------------+--------------+--------------+-------------+\r\n| customer_id | name         | visited_on   | amount      |\r\n+-------------+--------------+--------------+-------------+\r\n| 1           | Jhon         | 2019-01-01   | 100         |\r\n| 2           | Daniel       | 2019-01-02   | 110         |\r\n| 3           | Jade         | 2019-01-03   | 120         |\r\n| 4           | Khaled       | 2019-01-04   | 130         |\r\n| 5           | Winston      | 2019-01-05   | 110         | \r\n| 6           | Elvis        | 2019-01-06   | 140         | \r\n| 7           | Anna         | 2019-01-07   | 150         |\r\n| 8           | Maria        | 2019-01-08   | 80          |\r\n| 9           | Jaze         | 2019-01-09   | 110         | \r\n| 1           | Jhon         | 2019-01-10   | 130         | \r\n| 3           | Jade         | 2019-01-10   | 150         | \r\n+-------------+--------------+--------------+-------------+\r\n\r\nResult table:\r\n+--------------+--------------+----------------+\r\n| visited_on   | amount       | average_amount |\r\n+--------------+--------------+----------------+\r\n| 2019-01-07   | 860          | 122.86         |\r\n| 2019-01-08   | 840          | 120            |\r\n| 2019-01-09   | 840          | 120            |\r\n| 2019-01-10   | 1000         | 142.86         |\r\n+--------------+--------------+----------------+\r\n\r\n1st moving average from 2019-01-01 to 2019-01-07 has an average_amount of (100 + 110 + 120 + 130 + 110 + 140 + 150)/7 = 122.86\r\n2nd moving average from 2019-01-02 to 2019-01-08 has an average_amount of (110 + 120 + 130 + 110 + 140 + 150 + 80)/7 = 120\r\n3rd moving average from 2019-01-03 to 2019-01-09 has an average_amount of (120 + 130 + 110 + 140 + 150 + 80 + 110)/7 = 120\r\n4th moving average from 2019-01-04 to 2019-01-10 has an average_amount of (130 + 110 + 140 + 150 + 80 + 110 + 130 + 150)/7 = 142.86\r\n
", "content_cn": "

\u8868: Customer

\n\n
+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| customer_id   | int     |\n| name          | varchar |\n| visited_on    | date    |\n| amount        | int     |\n+---------------+---------+\n(customer_id, visited_on) \u662f\u8be5\u8868\u7684\u4e3b\u952e\n\u8be5\u8868\u5305\u542b\u4e00\u5bb6\u9910\u9986\u7684\u987e\u5ba2\u4ea4\u6613\u6570\u636e\nvisited_on \u8868\u793a (customer_id) \u7684\u987e\u5ba2\u5728 visited_on \u90a3\u5929\u8bbf\u95ee\u4e86\u9910\u9986\namount \u662f\u4e00\u4e2a\u987e\u5ba2\u67d0\u4e00\u5929\u7684\u6d88\u8d39\u603b\u989d\n
\n\n

 

\n\n

\u4f60\u662f\u9910\u9986\u7684\u8001\u677f\uff0c\u73b0\u5728\u4f60\u60f3\u5206\u6790\u4e00\u4e0b\u53ef\u80fd\u7684\u8425\u4e1a\u989d\u53d8\u5316\u589e\u957f\uff08\u6bcf\u5929\u81f3\u5c11\u6709\u4e00\u4f4d\u987e\u5ba2\uff09

\n\n

\u5199\u4e00\u6761 SQL \u67e5\u8be2\u8ba1\u7b97\u4ee5 7 \u5929\uff08\u67d0\u65e5\u671f + \u8be5\u65e5\u671f\u524d\u7684 6 \u5929\uff09\u4e3a\u4e00\u4e2a\u65f6\u95f4\u6bb5\u7684\u987e\u5ba2\u6d88\u8d39\u5e73\u5747\u503c

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u7684\u4f8b\u5b50\u5982\u4e0b\uff1a

\n\n
    \n\t
  • \u67e5\u8be2\u7ed3\u679c\u6309 visited_on \u6392\u5e8f
  • \n\t
  • average_amount \u8981 \u4fdd\u7559\u4e24\u4f4d\u5c0f\u6570\uff0c\u65e5\u671f\u6570\u636e\u7684\u683c\u5f0f\u4e3a ('YYYY-MM-DD')
  • \n
\n\n

 

\n\n
Customer \u8868:\n+-------------+--------------+--------------+-------------+\n| customer_id | name         | visited_on   | amount      |\n+-------------+--------------+--------------+-------------+\n| 1           | Jhon         | 2019-01-01   | 100         |\n| 2           | Daniel       | 2019-01-02   | 110         |\n| 3           | Jade         | 2019-01-03   | 120         |\n| 4           | Khaled       | 2019-01-04   | 130         |\n| 5           | Winston      | 2019-01-05   | 110         | \n| 6           | Elvis        | 2019-01-06   | 140         | \n| 7           | Anna         | 2019-01-07   | 150         |\n| 8           | Maria        | 2019-01-08   | 80          |\n| 9           | Jaze         | 2019-01-09   | 110         | \n| 1           | Jhon         | 2019-01-10   | 130         | \n| 3           | Jade         | 2019-01-10   | 150         | \n+-------------+--------------+--------------+-------------+\n\n\u7ed3\u679c\u8868:\n+--------------+--------------+----------------+\n| visited_on   | amount       | average_amount |\n+--------------+--------------+----------------+\n| 2019-01-07   | 860          | 122.86         |\n| 2019-01-08   | 840          | 120            |\n| 2019-01-09   | 840          | 120            |\n| 2019-01-10   | 1000         | 142.86         |\n+--------------+--------------+----------------+\n\n\u7b2c\u4e00\u4e2a\u4e03\u5929\u6d88\u8d39\u5e73\u5747\u503c\u4ece 2019-01-01 \u5230 2019-01-07 \u662f (100 + 110 + 120 + 130 + 110 + 140 + 150)/7 = 122.86\n\u7b2c\u4e8c\u4e2a\u4e03\u5929\u6d88\u8d39\u5e73\u5747\u503c\u4ece 2019-01-02 \u5230 2019-01-08 \u662f (110 + 120 + 130 + 110 + 140 + 150 + 80)/7 = 120\n\u7b2c\u4e09\u4e2a\u4e03\u5929\u6d88\u8d39\u5e73\u5747\u503c\u4ece 2019-01-03 \u5230 2019-01-09 \u662f (120 + 130 + 110 + 140 + 150 + 80 + 110)/7 = 120\n\u7b2c\u56db\u4e2a\u4e03\u5929\u6d88\u8d39\u5e73\u5747\u503c\u4ece 2019-01-04 \u5230 2019-01-10 \u662f (130 + 110 + 140 + 150 + 80 + 110 + 130 + 150)/7 = 142.86
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1321](https://leetcode-cn.com/problems/restaurant-growth)", "[\u9910\u9986\u8425\u4e1a\u989d\u53d8\u5316\u589e\u957f](/solution/1300-1399/1321.Restaurant%20Growth/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1321](https://leetcode.com/problems/restaurant-growth)", "[Restaurant Growth](/solution/1300-1399/1321.Restaurant%20Growth/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1451", "frontend_question_id": "1326", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-number-of-taps-to-open-to-water-a-garden", "url_en": "https://leetcode.com/problems/minimum-number-of-taps-to-open-to-water-a-garden", "relative_path_cn": "/solution/1300-1399/1326.Minimum%20Number%20of%20Taps%20to%20Open%20to%20Water%20a%20Garden/README.md", "relative_path_en": "/solution/1300-1399/1326.Minimum%20Number%20of%20Taps%20to%20Open%20to%20Water%20a%20Garden/README_EN.md", "title_cn": "\u704c\u6e89\u82b1\u56ed\u7684\u6700\u5c11\u6c34\u9f99\u5934\u6570\u76ee", "title_en": "Minimum Number of Taps to Open to Water a Garden", "question_title_slug": "minimum-number-of-taps-to-open-to-water-a-garden", "content_en": "

There is a one-dimensional garden on the x-axis. The garden starts at the point 0 and ends at the point n. (i.e The length of the garden is n).

\n\n

There are n + 1 taps located at points [0, 1, ..., n] in the garden.

\n\n

Given an integer n and an integer array ranges of length n + 1 where ranges[i] (0-indexed) means the i-th tap can water the area [i - ranges[i], i + ranges[i]] if it was open.

\n\n

Return the minimum number of taps that should be open to water the whole garden, If the garden cannot be watered return -1.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: n = 5, ranges = [3,4,1,1,0,0]\nOutput: 1\nExplanation: The tap at point 0 can cover the interval [-3,3]\nThe tap at point 1 can cover the interval [-3,5]\nThe tap at point 2 can cover the interval [1,3]\nThe tap at point 3 can cover the interval [2,4]\nThe tap at point 4 can cover the interval [4,4]\nThe tap at point 5 can cover the interval [5,5]\nOpening Only the second tap will water the whole garden [0,5]\n
\n\n

Example 2:

\n\n
\nInput: n = 3, ranges = [0,0,0,0]\nOutput: -1\nExplanation: Even if you activate all the four taps you cannot water the whole garden.\n
\n\n

Example 3:

\n\n
\nInput: n = 7, ranges = [1,2,1,0,2,1,0,1]\nOutput: 3\n
\n\n

Example 4:

\n\n
\nInput: n = 8, ranges = [4,0,0,0,0,0,0,0,4]\nOutput: 2\n
\n\n

Example 5:

\n\n
\nInput: n = 8, ranges = [4,0,0,0,4,0,0,0,4]\nOutput: 1\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 10^4
  • \n\t
  • ranges.length == n + 1
  • \n\t
  • 0 <= ranges[i] <= 100
  • \n
\n", "content_cn": "

\u5728 x \u8f74\u4e0a\u6709\u4e00\u4e2a\u4e00\u7ef4\u7684\u82b1\u56ed\u3002\u82b1\u56ed\u957f\u5ea6\u4e3a n\uff0c\u4ece\u70b9 0 \u5f00\u59cb\uff0c\u5230\u70b9 n \u7ed3\u675f\u3002

\n\n

\u82b1\u56ed\u91cc\u603b\u5171\u6709 n + 1 \u4e2a\u6c34\u9f99\u5934\uff0c\u5206\u522b\u4f4d\u4e8e [0, 1, ..., n] \u3002

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n \u548c\u4e00\u4e2a\u957f\u5ea6\u4e3a n + 1 \u7684\u6574\u6570\u6570\u7ec4 ranges \uff0c\u5176\u4e2d ranges[i] \uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\u8868\u793a\uff1a\u5982\u679c\u6253\u5f00\u70b9 i \u5904\u7684\u6c34\u9f99\u5934\uff0c\u53ef\u4ee5\u704c\u6e89\u7684\u533a\u57df\u4e3a [i -  ranges[i], i + ranges[i]] \u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u53ef\u4ee5\u704c\u6e89\u6574\u4e2a\u82b1\u56ed\u7684 \u6700\u5c11\u6c34\u9f99\u5934\u6570\u76ee \u3002\u5982\u679c\u82b1\u56ed\u59cb\u7ec8\u5b58\u5728\u65e0\u6cd5\u704c\u6e89\u5230\u7684\u5730\u65b9\uff0c\u8bf7\u4f60\u8fd4\u56de -1 \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1an = 5, ranges = [3,4,1,1,0,0]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\n\u70b9 0 \u5904\u7684\u6c34\u9f99\u5934\u53ef\u4ee5\u704c\u6e89\u533a\u95f4 [-3,3]\n\u70b9 1 \u5904\u7684\u6c34\u9f99\u5934\u53ef\u4ee5\u704c\u6e89\u533a\u95f4 [-3,5]\n\u70b9 2 \u5904\u7684\u6c34\u9f99\u5934\u53ef\u4ee5\u704c\u6e89\u533a\u95f4 [1,3]\n\u70b9 3 \u5904\u7684\u6c34\u9f99\u5934\u53ef\u4ee5\u704c\u6e89\u533a\u95f4 [2,4]\n\u70b9 4 \u5904\u7684\u6c34\u9f99\u5934\u53ef\u4ee5\u704c\u6e89\u533a\u95f4 [4,4]\n\u70b9 5 \u5904\u7684\u6c34\u9f99\u5934\u53ef\u4ee5\u704c\u6e89\u533a\u95f4 [5,5]\n\u53ea\u9700\u8981\u6253\u5f00\u70b9 1 \u5904\u7684\u6c34\u9f99\u5934\u5373\u53ef\u704c\u6e89\u6574\u4e2a\u82b1\u56ed [0,5] \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1an = 3, ranges = [0,0,0,0]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u5373\u4f7f\u6253\u5f00\u6240\u6709\u6c34\u9f99\u5934\uff0c\u4f60\u4e5f\u65e0\u6cd5\u704c\u6e89\u6574\u4e2a\u82b1\u56ed\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1an = 7, ranges = [1,2,1,0,2,1,0,1]\n\u8f93\u51fa\uff1a3\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1an = 8, ranges = [4,0,0,0,0,0,0,0,4]\n\u8f93\u51fa\uff1a2\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1an = 8, ranges = [4,0,0,0,4,0,0,0,4]\n\u8f93\u51fa\uff1a1\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 10^4
  • \n\t
  • ranges.length == n + 1
  • \n\t
  • 0 <= ranges[i] <= 100
  • \n
\n", "tags_en": ["Greedy", "Dynamic Programming"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minTaps(int n, vector& ranges) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minTaps(int n, int[] ranges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minTaps(self, n, ranges):\n \"\"\"\n :type n: int\n :type ranges: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minTaps(self, n: int, ranges: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minTaps(int n, int* ranges, int rangesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinTaps(int n, int[] ranges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[]} ranges\n * @return {number}\n */\nvar minTaps = function(n, ranges) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[]} ranges\n# @return {Integer}\ndef min_taps(n, ranges)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minTaps(_ n: Int, _ ranges: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minTaps(n int, ranges []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minTaps(n: Int, ranges: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minTaps(n: Int, ranges: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_taps(n: i32, ranges: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[] $ranges\n * @return Integer\n */\n function minTaps($n, $ranges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minTaps(n: number, ranges: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-taps n ranges)\n (-> exact-integer? (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1326](https://leetcode-cn.com/problems/minimum-number-of-taps-to-open-to-water-a-garden)", "[\u704c\u6e89\u82b1\u56ed\u7684\u6700\u5c11\u6c34\u9f99\u5934\u6570\u76ee](/solution/1300-1399/1326.Minimum%20Number%20of%20Taps%20to%20Open%20to%20Water%20a%20Garden/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1326](https://leetcode.com/problems/minimum-number-of-taps-to-open-to-water-a-garden)", "[Minimum Number of Taps to Open to Water a Garden](/solution/1300-1399/1326.Minimum%20Number%20of%20Taps%20to%20Open%20to%20Water%20a%20Garden/README_EN.md)", "`Greedy`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "1450", "frontend_question_id": "1325", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/delete-leaves-with-a-given-value", "url_en": "https://leetcode.com/problems/delete-leaves-with-a-given-value", "relative_path_cn": "/solution/1300-1399/1325.Delete%20Leaves%20With%20a%20Given%20Value/README.md", "relative_path_en": "/solution/1300-1399/1325.Delete%20Leaves%20With%20a%20Given%20Value/README_EN.md", "title_cn": "\u5220\u9664\u7ed9\u5b9a\u503c\u7684\u53f6\u5b50\u8282\u70b9", "title_en": "Delete Leaves With a Given Value", "question_title_slug": "delete-leaves-with-a-given-value", "content_en": "

Given a binary tree root and an integer target, delete all the leaf nodes with value target.

\n\n

Note that once you delete a leaf node with value targetif it's parent node becomes a leaf node and has the value target, it should also be deleted (you need to continue doing that until you can't).

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: root = [1,2,3,2,null,2,4], target = 2\nOutput: [1,null,3,null,4]\nExplanation: Leaf nodes in green with value (target = 2) are removed (Picture in left). \nAfter removing, new nodes become leaf nodes with value (target = 2) (Picture in center).\n
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: root = [1,3,3,3,2], target = 3\nOutput: [1,3,null,null,2]\n
\n\n

Example 3:

\n\n

\"\"

\n\n
\nInput: root = [1,2,null,2,null,2], target = 2\nOutput: [1]\nExplanation: Leaf nodes in green with value (target = 2) are removed at each step.\n
\n\n

Example 4:

\n\n
\nInput: root = [1,1,1], target = 1\nOutput: []\n
\n\n

Example 5:

\n\n
\nInput: root = [1,2,3], target = 1\nOutput: [1,2,3]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= target <= 1000
  • \n\t
  • The given binary tree will have between 1 and 3000 nodes.
  • \n\t
  • Each node's value is between [1, 1000].
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u68f5\u4ee5 root \u4e3a\u6839\u7684\u4e8c\u53c9\u6811\u548c\u4e00\u4e2a\u6574\u6570 target \uff0c\u8bf7\u4f60\u5220\u9664\u6240\u6709\u503c\u4e3a target \u7684 \u53f6\u5b50\u8282\u70b9 \u3002

\n\n

\u6ce8\u610f\uff0c\u4e00\u65e6\u5220\u9664\u503c\u4e3a target \u7684\u53f6\u5b50\u8282\u70b9\uff0c\u5b83\u7684\u7236\u8282\u70b9\u5c31\u53ef\u80fd\u53d8\u6210\u53f6\u5b50\u8282\u70b9\uff1b\u5982\u679c\u65b0\u53f6\u5b50\u8282\u70b9\u7684\u503c\u6070\u597d\u4e5f\u662f target \uff0c\u90a3\u4e48\u8fd9\u4e2a\u8282\u70b9\u4e5f\u5e94\u8be5\u88ab\u5220\u9664\u3002

\n\n

\u4e5f\u5c31\u662f\u8bf4\uff0c\u4f60\u9700\u8981\u91cd\u590d\u6b64\u8fc7\u7a0b\u76f4\u5230\u4e0d\u80fd\u7ee7\u7eed\u5220\u9664\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1aroot = [1,2,3,2,null,2,4], target = 2\n\u8f93\u51fa\uff1a[1,null,3,null,4]\n\u89e3\u91ca\uff1a\n\u4e0a\u9762\u5de6\u8fb9\u7684\u56fe\u4e2d\uff0c\u7eff\u8272\u8282\u70b9\u4e3a\u53f6\u5b50\u8282\u70b9\uff0c\u4e14\u5b83\u4eec\u7684\u503c\u4e0e target \u76f8\u540c\uff08\u540c\u4e3a 2 \uff09\uff0c\u5b83\u4eec\u4f1a\u88ab\u5220\u9664\uff0c\u5f97\u5230\u4e2d\u95f4\u7684\u56fe\u3002\n\u6709\u4e00\u4e2a\u65b0\u7684\u8282\u70b9\u53d8\u6210\u4e86\u53f6\u5b50\u8282\u70b9\u4e14\u5b83\u7684\u503c\u4e0e target \u76f8\u540c\uff0c\u6240\u4ee5\u5c06\u518d\u6b21\u8fdb\u884c\u5220\u9664\uff0c\u4ece\u800c\u5f97\u5230\u6700\u53f3\u8fb9\u7684\u56fe\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1aroot = [1,3,3,3,2], target = 3\n\u8f93\u51fa\uff1a[1,3,null,null,2]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1aroot = [1,2,null,2,null,2], target = 2\n\u8f93\u51fa\uff1a[1]\n\u89e3\u91ca\uff1a\u6bcf\u4e00\u6b65\u90fd\u5220\u9664\u4e00\u4e2a\u7eff\u8272\u7684\u53f6\u5b50\u8282\u70b9\uff08\u503c\u4e3a 2\uff09\u3002
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1aroot = [1,1,1], target = 1\n\u8f93\u51fa\uff1a[]\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1aroot = [1,2,3], target = 1\n\u8f93\u51fa\uff1a[1,2,3]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= target <= 1000
  • \n\t
  • \u6bcf\u4e00\u68f5\u6811\u6700\u591a\u6709 3000 \u4e2a\u8282\u70b9\u3002
  • \n\t
  • \u6bcf\u4e00\u4e2a\u8282\u70b9\u503c\u7684\u8303\u56f4\u662f [1, 1000] \u3002
  • \n
\n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* removeLeafNodes(TreeNode* root, int target) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode removeLeafNodes(TreeNode root, int target) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def removeLeafNodes(self, root, target):\n \"\"\"\n :type root: TreeNode\n :type target: int\n :rtype: TreeNode\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def removeLeafNodes(self, root: TreeNode, target: int) -> TreeNode:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* removeLeafNodes(struct TreeNode* root, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode RemoveLeafNodes(TreeNode root, int target) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number} target\n * @return {TreeNode}\n */\nvar removeLeafNodes = function(root, target) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @param {Integer} target\n# @return {TreeNode}\ndef remove_leaf_nodes(root, target)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func removeLeafNodes(_ root: TreeNode?, _ target: Int) -> TreeNode? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc removeLeafNodes(root *TreeNode, target int) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def removeLeafNodes(root: TreeNode, target: Int): TreeNode = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun removeLeafNodes(root: TreeNode?, target: Int): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn remove_leaf_nodes(root: Option>>, target: i32) -> Option>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param Integer $target\n * @return TreeNode\n */\n function removeLeafNodes($root, $target) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction removeLeafNodes(root: TreeNode | null, target: number): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (remove-leaf-nodes root target)\n (-> (or/c tree-node? #f) exact-integer? (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1325](https://leetcode-cn.com/problems/delete-leaves-with-a-given-value)", "[\u5220\u9664\u7ed9\u5b9a\u503c\u7684\u53f6\u5b50\u8282\u70b9](/solution/1300-1399/1325.Delete%20Leaves%20With%20a%20Given%20Value/README.md)", "`\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1325](https://leetcode.com/problems/delete-leaves-with-a-given-value)", "[Delete Leaves With a Given Value](/solution/1300-1399/1325.Delete%20Leaves%20With%20a%20Given%20Value/README_EN.md)", "`Tree`", "Medium", ""]}, {"question_id": "1449", "frontend_question_id": "1324", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/print-words-vertically", "url_en": "https://leetcode.com/problems/print-words-vertically", "relative_path_cn": "/solution/1300-1399/1324.Print%20Words%20Vertically/README.md", "relative_path_en": "/solution/1300-1399/1324.Print%20Words%20Vertically/README_EN.md", "title_cn": "\u7ad6\u76f4\u6253\u5370\u5355\u8bcd", "title_en": "Print Words Vertically", "question_title_slug": "print-words-vertically", "content_en": "

Given a string s. Return all the words vertically in the same order in which they appear in s.
\r\nWords are returned as a list of strings, complete with spaces when is necessary. (Trailing spaces are not allowed).
\r\nEach word would be put on only one column and that in one column there will be only one word.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: s = "HOW ARE YOU"\r\nOutput: ["HAY","ORO","WEU"]\r\nExplanation: Each word is printed vertically. \r\n "HAY"\r\n "ORO"\r\n "WEU"\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: s = "TO BE OR NOT TO BE"\r\nOutput: ["TBONTB","OEROOE","   T"]\r\nExplanation: Trailing spaces is not allowed. \r\n"TBONTB"\r\n"OEROOE"\r\n"   T"\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: s = "CONTEST IS COMING"\r\nOutput: ["CIC","OSO","N M","T I","E N","S G","T"]\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= s.length <= 200
  • \r\n\t
  • s contains only upper case English letters.
  • \r\n\t
  • It's guaranteed that there is only one space between 2 words.
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s\u3002\u8bf7\u4f60\u6309\u7167\u5355\u8bcd\u5728 s \u4e2d\u7684\u51fa\u73b0\u987a\u5e8f\u5c06\u5b83\u4eec\u5168\u90e8\u7ad6\u76f4\u8fd4\u56de\u3002
\n\u5355\u8bcd\u5e94\u8be5\u4ee5\u5b57\u7b26\u4e32\u5217\u8868\u7684\u5f62\u5f0f\u8fd4\u56de\uff0c\u5fc5\u8981\u65f6\u7528\u7a7a\u683c\u8865\u4f4d\uff0c\u4f46\u8f93\u51fa\u5c3e\u90e8\u7684\u7a7a\u683c\u9700\u8981\u5220\u9664\uff08\u4e0d\u5141\u8bb8\u5c3e\u968f\u7a7a\u683c\uff09\u3002
\n\u6bcf\u4e2a\u5355\u8bcd\u53ea\u80fd\u653e\u5728\u4e00\u5217\u4e0a\uff0c\u6bcf\u4e00\u5217\u4e2d\u4e5f\u53ea\u80fd\u6709\u4e00\u4e2a\u5355\u8bcd\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1as = "HOW ARE YOU"\n\u8f93\u51fa\uff1a["HAY","ORO","WEU"]\n\u89e3\u91ca\uff1a\u6bcf\u4e2a\u5355\u8bcd\u90fd\u5e94\u8be5\u7ad6\u76f4\u6253\u5370\u3002 \n "HAY"\n "ORO"\n "WEU"\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1as = "TO BE OR NOT TO BE"\n\u8f93\u51fa\uff1a["TBONTB","OEROOE","   T"]\n\u89e3\u91ca\uff1a\u9898\u76ee\u5141\u8bb8\u4f7f\u7528\u7a7a\u683c\u8865\u4f4d\uff0c\u4f46\u4e0d\u5141\u8bb8\u8f93\u51fa\u672b\u5c3e\u51fa\u73b0\u7a7a\u683c\u3002\n"TBONTB"\n"OEROOE"\n"   T"\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1as = "CONTEST IS COMING"\n\u8f93\u51fa\uff1a["CIC","OSO","N M","T I","E N","S G","T"]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length <= 200
  • \n\t
  • s \u4ec5\u542b\u5927\u5199\u82f1\u6587\u5b57\u6bcd\u3002
  • \n\t
  • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u4e24\u4e2a\u5355\u8bcd\u4e4b\u95f4\u53ea\u6709\u4e00\u4e2a\u7a7a\u683c\u3002
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector printVertically(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List printVertically(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def printVertically(self, s):\n \"\"\"\n :type s: str\n :rtype: List[str]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def printVertically(self, s: str) -> List[str]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** printVertically(char * s, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList PrintVertically(string s) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string[]}\n */\nvar printVertically = function(s) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String[]}\ndef print_vertically(s)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func printVertically(_ s: String) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func printVertically(s string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def printVertically(s: String): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun printVertically(s: String): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn print_vertically(s: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String[]\n */\n function printVertically($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function printVertically(s: string): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (print-vertically s)\n (-> string? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1324](https://leetcode-cn.com/problems/print-words-vertically)", "[\u7ad6\u76f4\u6253\u5370\u5355\u8bcd](/solution/1300-1399/1324.Print%20Words%20Vertically/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1324](https://leetcode.com/problems/print-words-vertically)", "[Print Words Vertically](/solution/1300-1399/1324.Print%20Words%20Vertically/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "1448", "frontend_question_id": "1323", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-69-number", "url_en": "https://leetcode.com/problems/maximum-69-number", "relative_path_cn": "/solution/1300-1399/1323.Maximum%2069%20Number/README.md", "relative_path_en": "/solution/1300-1399/1323.Maximum%2069%20Number/README_EN.md", "title_cn": "6 \u548c 9 \u7ec4\u6210\u7684\u6700\u5927\u6570\u5b57", "title_en": "Maximum 69 Number", "question_title_slug": "maximum-69-number", "content_en": "

Given a positive integer num consisting only of digits 6 and 9.

\r\n\r\n

Return the maximum number you can get by changing at most one digit (6 becomes 9, and 9 becomes 6).

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: num = 9669\r\nOutput: 9969\r\nExplanation: \r\nChanging the first digit results in 6669.\r\nChanging the second digit results in 9969.\r\nChanging the third digit results in 9699.\r\nChanging the fourth digit results in 9666. \r\nThe maximum number is 9969.\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: num = 9996\r\nOutput: 9999\r\nExplanation: Changing the last digit 6 to 9 results in the maximum number.
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: num = 9999\r\nOutput: 9999\r\nExplanation: It is better not to apply any change.
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= num <= 10^4
  • \r\n\t
  • num's digits are 6 or 9.
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u4ec5\u7531\u6570\u5b57 6 \u548c 9 \u7ec4\u6210\u7684\u6b63\u6574\u6570 num\u3002

\n\n

\u4f60\u6700\u591a\u53ea\u80fd\u7ffb\u8f6c\u4e00\u4f4d\u6570\u5b57\uff0c\u5c06 6 \u53d8\u6210 9\uff0c\u6216\u8005\u628a 9 \u53d8\u6210 6 \u3002

\n\n

\u8bf7\u8fd4\u56de\u4f60\u53ef\u4ee5\u5f97\u5230\u7684\u6700\u5927\u6570\u5b57\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anum = 9669\n\u8f93\u51fa\uff1a9969\n\u89e3\u91ca\uff1a\n\u6539\u53d8\u7b2c\u4e00\u4f4d\u6570\u5b57\u53ef\u4ee5\u5f97\u5230 6669 \u3002\n\u6539\u53d8\u7b2c\u4e8c\u4f4d\u6570\u5b57\u53ef\u4ee5\u5f97\u5230 9969 \u3002\n\u6539\u53d8\u7b2c\u4e09\u4f4d\u6570\u5b57\u53ef\u4ee5\u5f97\u5230 9699 \u3002\n\u6539\u53d8\u7b2c\u56db\u4f4d\u6570\u5b57\u53ef\u4ee5\u5f97\u5230 9666 \u3002\n\u5176\u4e2d\u6700\u5927\u7684\u6570\u5b57\u662f 9969 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anum = 9996\n\u8f93\u51fa\uff1a9999\n\u89e3\u91ca\uff1a\u5c06\u6700\u540e\u4e00\u4f4d\u4ece 6 \u53d8\u5230 9\uff0c\u5176\u7ed3\u679c 9999 \u662f\u6700\u5927\u7684\u6570\u3002
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1anum = 9999\n\u8f93\u51fa\uff1a9999\n\u89e3\u91ca\uff1a\u65e0\u9700\u6539\u53d8\u5c31\u5df2\u7ecf\u662f\u6700\u5927\u7684\u6570\u5b57\u4e86\u3002
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= num <= 10^4
  • \n\t
  • num \u6bcf\u4e00\u4f4d\u4e0a\u7684\u6570\u5b57\u90fd\u662f 6 \u6216\u8005 9 \u3002
  • \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maximum69Number (int num) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maximum69Number (int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximum69Number (self, num):\n \"\"\"\n :type num: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximum69Number (self, num: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maximum69Number (int num){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int Maximum69Number (int num) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} num\n * @return {number}\n */\nvar maximum69Number = function(num) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} num\n# @return {Integer}\ndef maximum69_number (num)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximum69Number (_ num: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximum69Number (num int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximum69Number (num: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximum69Number (num: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximum69_number (num: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $num\n * @return Integer\n */\n function maximum69Number ($num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximum69Number (num: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximum69-number num)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1323](https://leetcode-cn.com/problems/maximum-69-number)", "[6 \u548c 9 \u7ec4\u6210\u7684\u6700\u5927\u6570\u5b57](/solution/1300-1399/1323.Maximum%2069%20Number/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[1323](https://leetcode.com/problems/maximum-69-number)", "[Maximum 69 Number](/solution/1300-1399/1323.Maximum%2069%20Number/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "1447", "frontend_question_id": "1345", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/jump-game-iv", "url_en": "https://leetcode.com/problems/jump-game-iv", "relative_path_cn": "/solution/1300-1399/1345.Jump%20Game%20IV/README.md", "relative_path_en": "/solution/1300-1399/1345.Jump%20Game%20IV/README_EN.md", "title_cn": "\u8df3\u8dc3\u6e38\u620f IV", "title_en": "Jump Game IV", "question_title_slug": "jump-game-iv", "content_en": "

Given an array of integers arr, you are initially positioned at the first index of the array.

\n\n

In one step you can jump from index i to index:

\n\n
    \n\t
  • i + 1 where: i + 1 < arr.length.
  • \n\t
  • i - 1 where: i - 1 >= 0.
  • \n\t
  • j where: arr[i] == arr[j] and i != j.
  • \n
\n\n

Return the minimum number of steps to reach the last index of the array.

\n\n

Notice that you can not jump outside of the array at any time.

\n\n

 

\n

Example 1:

\n\n
\nInput: arr = [100,-23,-23,404,100,23,23,23,3,404]\nOutput: 3\nExplanation: You need three jumps from index 0 --> 4 --> 3 --> 9. Note that index 9 is the last index of the array.\n
\n\n

Example 2:

\n\n
\nInput: arr = [7]\nOutput: 0\nExplanation: Start index is the last index. You don't need to jump.\n
\n\n

Example 3:

\n\n
\nInput: arr = [7,6,9,6,9,6,9,7]\nOutput: 1\nExplanation: You can jump directly from index 0 to index 7 which is last index of the array.\n
\n\n

Example 4:

\n\n
\nInput: arr = [6,1,9]\nOutput: 2\n
\n\n

Example 5:

\n\n
\nInput: arr = [11,22,7,7,7,7,7,7,7,22,13]\nOutput: 3\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= arr.length <= 5 * 104
  • \n\t
  • -108 <= arr[i] <= 108
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr \uff0c\u4f60\u4e00\u5f00\u59cb\u5728\u6570\u7ec4\u7684\u7b2c\u4e00\u4e2a\u5143\u7d20\u5904\uff08\u4e0b\u6807\u4e3a 0\uff09\u3002

\n\n

\u6bcf\u4e00\u6b65\uff0c\u4f60\u53ef\u4ee5\u4ece\u4e0b\u6807 i \u8df3\u5230\u4e0b\u6807\uff1a

\n\n
    \n\t
  • i + 1 \u6ee1\u8db3\uff1ai + 1 < arr.length
  • \n\t
  • i - 1 \u6ee1\u8db3\uff1ai - 1 >= 0
  • \n\t
  • j \u6ee1\u8db3\uff1aarr[i] == arr[j] \u4e14 i != j
  • \n
\n\n

\u8bf7\u4f60\u8fd4\u56de\u5230\u8fbe\u6570\u7ec4\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u7684\u4e0b\u6807\u5904\u6240\u9700\u7684 \u6700\u5c11\u64cd\u4f5c\u6b21\u6570 \u3002

\n\n

\u6ce8\u610f\uff1a\u4efb\u4f55\u65f6\u5019\u4f60\u90fd\u4e0d\u80fd\u8df3\u5230\u6570\u7ec4\u5916\u9762\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aarr = [100,-23,-23,404,100,23,23,23,3,404]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u90a3\u4f60\u9700\u8981\u8df3\u8dc3 3 \u6b21\uff0c\u4e0b\u6807\u4f9d\u6b21\u4e3a 0 --> 4 --> 3 --> 9 \u3002\u4e0b\u6807 9 \u4e3a\u6570\u7ec4\u7684\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u7684\u4e0b\u6807\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aarr = [7]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u4e00\u5f00\u59cb\u5c31\u5728\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u5904\uff0c\u6240\u4ee5\u4f60\u4e0d\u9700\u8981\u8df3\u8dc3\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aarr = [7,6,9,6,9,6,9,7]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u76f4\u63a5\u4ece\u4e0b\u6807 0 \u5904\u8df3\u5230\u4e0b\u6807 7 \u5904\uff0c\u4e5f\u5c31\u662f\u6570\u7ec4\u7684\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u5904\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1aarr = [6,1,9]\n\u8f93\u51fa\uff1a2\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1aarr = [11,22,7,7,7,7,7,7,7,22,13]\n\u8f93\u51fa\uff1a3\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= arr.length <= 5 * 10^4
  • \n\t
  • -10^8 <= arr[i] <= 10^8
  • \n
\n", "tags_en": ["Breadth-first Search"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minJumps(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minJumps(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minJumps(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minJumps(self, arr: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minJumps(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinJumps(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar minJumps = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef min_jumps(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minJumps(_ arr: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minJumps(arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minJumps(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minJumps(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_jumps(arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function minJumps($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minJumps(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-jumps arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1345](https://leetcode-cn.com/problems/jump-game-iv)", "[\u8df3\u8dc3\u6e38\u620f IV](/solution/1300-1399/1345.Jump%20Game%20IV/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[1345](https://leetcode.com/problems/jump-game-iv)", "[Jump Game IV](/solution/1300-1399/1345.Jump%20Game%20IV/README_EN.md)", "`Breadth-first Search`", "Hard", ""]}, {"question_id": "1446", "frontend_question_id": "1344", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/angle-between-hands-of-a-clock", "url_en": "https://leetcode.com/problems/angle-between-hands-of-a-clock", "relative_path_cn": "/solution/1300-1399/1344.Angle%20Between%20Hands%20of%20a%20Clock/README.md", "relative_path_en": "/solution/1300-1399/1344.Angle%20Between%20Hands%20of%20a%20Clock/README_EN.md", "title_cn": "\u65f6\u949f\u6307\u9488\u7684\u5939\u89d2", "title_en": "Angle Between Hands of a Clock", "question_title_slug": "angle-between-hands-of-a-clock", "content_en": "

Given two numbers, hour and minutes. Return the smaller angle (in degrees) formed between the hour and the minute hand.

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: hour = 12, minutes = 30\nOutput: 165\n
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: hour = 3, minutes = 30\nOutput: 75\n
\n\n

Example 3:

\n\n

\"\"

\n\n
\nInput: hour = 3, minutes = 15\nOutput: 7.5\n
\n\n

Example 4:

\n\n
\nInput: hour = 4, minutes = 50\nOutput: 155\n
\n\n

Example 5:

\n\n
\nInput: hour = 12, minutes = 0\nOutput: 0\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= hour <= 12
  • \n\t
  • 0 <= minutes <= 59
  • \n\t
  • Answers within 10^-5 of the actual value will be accepted as correct.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e24\u4e2a\u6570 hour \u548c minutes \u3002\u8bf7\u4f60\u8fd4\u56de\u5728\u65f6\u949f\u4e0a\uff0c\u7531\u7ed9\u5b9a\u65f6\u95f4\u7684\u65f6\u9488\u548c\u5206\u9488\u7ec4\u6210\u7684\u8f83\u5c0f\u89d2\u7684\u89d2\u5ea6\uff0860 \u5355\u4f4d\u5236\uff09\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1ahour = 12, minutes = 30\n\u8f93\u51fa\uff1a165\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1ahour = 3, minutes = 30\n\u8f93\u51fa\uff1b75\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1ahour = 3, minutes = 15\n\u8f93\u51fa\uff1a7.5\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1ahour = 4, minutes = 50\n\u8f93\u51fa\uff1a155\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1ahour = 12, minutes = 0\n\u8f93\u51fa\uff1a0\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= hour <= 12
  • \n\t
  • 0 <= minutes <= 59
  • \n\t
  • \u4e0e\u6807\u51c6\u7b54\u6848\u8bef\u5dee\u5728 10^-5 \u4ee5\u5185\u7684\u7ed3\u679c\u90fd\u88ab\u89c6\u4e3a\u6b63\u786e\u7ed3\u679c\u3002
  • \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n double angleClock(int hour, int minutes) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double angleClock(int hour, int minutes) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def angleClock(self, hour, minutes):\n \"\"\"\n :type hour: int\n :type minutes: int\n :rtype: float\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def angleClock(self, hour: int, minutes: int) -> float:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\ndouble angleClock(int hour, int minutes){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double AngleClock(int hour, int minutes) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} hour\n * @param {number} minutes\n * @return {number}\n */\nvar angleClock = function(hour, minutes) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} hour\n# @param {Integer} minutes\n# @return {Float}\ndef angle_clock(hour, minutes)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func angleClock(_ hour: Int, _ minutes: Int) -> Double {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func angleClock(hour int, minutes int) float64 {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def angleClock(hour: Int, minutes: Int): Double = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun angleClock(hour: Int, minutes: Int): Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn angle_clock(hour: i32, minutes: i32) -> f64 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $hour\n * @param Integer $minutes\n * @return Float\n */\n function angleClock($hour, $minutes) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function angleClock(hour: number, minutes: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (angle-clock hour minutes)\n (-> exact-integer? exact-integer? flonum?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1344](https://leetcode-cn.com/problems/angle-between-hands-of-a-clock)", "[\u65f6\u949f\u6307\u9488\u7684\u5939\u89d2](/solution/1300-1399/1344.Angle%20Between%20Hands%20of%20a%20Clock/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1344](https://leetcode.com/problems/angle-between-hands-of-a-clock)", "[Angle Between Hands of a Clock](/solution/1300-1399/1344.Angle%20Between%20Hands%20of%20a%20Clock/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "1445", "frontend_question_id": "1343", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-sub-arrays-of-size-k-and-average-greater-than-or-equal-to-threshold", "url_en": "https://leetcode.com/problems/number-of-sub-arrays-of-size-k-and-average-greater-than-or-equal-to-threshold", "relative_path_cn": "/solution/1300-1399/1343.Number%20of%20Sub-arrays%20of%20Size%20K%20and%20Average%20Greater%20than%20or%20Equal%20to%20Threshold/README.md", "relative_path_en": "/solution/1300-1399/1343.Number%20of%20Sub-arrays%20of%20Size%20K%20and%20Average%20Greater%20than%20or%20Equal%20to%20Threshold/README_EN.md", "title_cn": "\u5927\u5c0f\u4e3a K \u4e14\u5e73\u5747\u503c\u5927\u4e8e\u7b49\u4e8e\u9608\u503c\u7684\u5b50\u6570\u7ec4\u6570\u76ee", "title_en": "Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold", "question_title_slug": "number-of-sub-arrays-of-size-k-and-average-greater-than-or-equal-to-threshold", "content_en": "

Given an array of integers arr and two integers k and threshold.

\n\n

Return the number of sub-arrays of size k and average greater than or equal to threshold.

\n\n

 

\n

Example 1:

\n\n
\nInput: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4\nOutput: 3\nExplanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively. All other sub-arrays of size 3 have averages less than 4 (the threshold).\n
\n\n

Example 2:

\n\n
\nInput: arr = [1,1,1,1,1], k = 1, threshold = 0\nOutput: 5\n
\n\n

Example 3:

\n\n
\nInput: arr = [11,13,17,23,29,31,7,5,2,3], k = 3, threshold = 5\nOutput: 6\nExplanation: The first 6 sub-arrays of size 3 have averages greater than 5. Note that averages are not integers.\n
\n\n

Example 4:

\n\n
\nInput: arr = [7,7,7,7,7,7,7], k = 7, threshold = 7\nOutput: 1\n
\n\n

Example 5:

\n\n
\nInput: arr = [4,4,4,4], k = 4, threshold = 1\nOutput: 1\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= arr.length <= 10^5
  • \n\t
  • 1 <= arr[i] <= 10^4
  • \n\t
  • 1 <= k <= arr.length
  • \n\t
  • 0 <= threshold <= 10^4
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr \u548c\u4e24\u4e2a\u6574\u6570 k \u548c threshold \u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u957f\u5ea6\u4e3a k \u4e14\u5e73\u5747\u503c\u5927\u4e8e\u7b49\u4e8e threshold \u7684\u5b50\u6570\u7ec4\u6570\u76ee\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aarr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u5b50\u6570\u7ec4 [2,5,5],[5,5,5] \u548c [5,5,8] \u7684\u5e73\u5747\u503c\u5206\u522b\u4e3a 4\uff0c5 \u548c 6 \u3002\u5176\u4ed6\u957f\u5ea6\u4e3a 3 \u7684\u5b50\u6570\u7ec4\u7684\u5e73\u5747\u503c\u90fd\u5c0f\u4e8e 4 \uff08threshold \u7684\u503c)\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aarr = [1,1,1,1,1], k = 1, threshold = 0\n\u8f93\u51fa\uff1a5\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aarr = [11,13,17,23,29,31,7,5,2,3], k = 3, threshold = 5\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u524d 6 \u4e2a\u957f\u5ea6\u4e3a 3 \u7684\u5b50\u6570\u7ec4\u5e73\u5747\u503c\u90fd\u5927\u4e8e 5 \u3002\u6ce8\u610f\u5e73\u5747\u503c\u4e0d\u662f\u6574\u6570\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1aarr = [7,7,7,7,7,7,7], k = 7, threshold = 7\n\u8f93\u51fa\uff1a1\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1aarr = [4,4,4,4], k = 4, threshold = 1\n\u8f93\u51fa\uff1a1\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= arr.length <= 10^5
  • \n\t
  • 1 <= arr[i] <= 10^4
  • \n\t
  • 1 <= k <= arr.length
  • \n\t
  • 0 <= threshold <= 10^4
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numOfSubarrays(vector& arr, int k, int threshold) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numOfSubarrays(int[] arr, int k, int threshold) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numOfSubarrays(self, arr, k, threshold):\n \"\"\"\n :type arr: List[int]\n :type k: int\n :type threshold: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numOfSubarrays(self, arr: List[int], k: int, threshold: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numOfSubarrays(int* arr, int arrSize, int k, int threshold){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumOfSubarrays(int[] arr, int k, int threshold) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @param {number} k\n * @param {number} threshold\n * @return {number}\n */\nvar numOfSubarrays = function(arr, k, threshold) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @param {Integer} k\n# @param {Integer} threshold\n# @return {Integer}\ndef num_of_subarrays(arr, k, threshold)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numOfSubarrays(_ arr: [Int], _ k: Int, _ threshold: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numOfSubarrays(arr []int, k int, threshold int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numOfSubarrays(arr: Array[Int], k: Int, threshold: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numOfSubarrays(arr: IntArray, k: Int, threshold: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_of_subarrays(arr: Vec, k: i32, threshold: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @param Integer $k\n * @param Integer $threshold\n * @return Integer\n */\n function numOfSubarrays($arr, $k, $threshold) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numOfSubarrays(arr: number[], k: number, threshold: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-of-subarrays arr k threshold)\n (-> (listof exact-integer?) exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1343](https://leetcode-cn.com/problems/number-of-sub-arrays-of-size-k-and-average-greater-than-or-equal-to-threshold)", "[\u5927\u5c0f\u4e3a K \u4e14\u5e73\u5747\u503c\u5927\u4e8e\u7b49\u4e8e\u9608\u503c\u7684\u5b50\u6570\u7ec4\u6570\u76ee](/solution/1300-1399/1343.Number%20of%20Sub-arrays%20of%20Size%20K%20and%20Average%20Greater%20than%20or%20Equal%20to%20Threshold/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1343](https://leetcode.com/problems/number-of-sub-arrays-of-size-k-and-average-greater-than-or-equal-to-threshold)", "[Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold](/solution/1300-1399/1343.Number%20of%20Sub-arrays%20of%20Size%20K%20and%20Average%20Greater%20than%20or%20Equal%20to%20Threshold/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "1444", "frontend_question_id": "1342", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-steps-to-reduce-a-number-to-zero", "url_en": "https://leetcode.com/problems/number-of-steps-to-reduce-a-number-to-zero", "relative_path_cn": "/solution/1300-1399/1342.Number%20of%20Steps%20to%20Reduce%20a%20Number%20to%20Zero/README.md", "relative_path_en": "/solution/1300-1399/1342.Number%20of%20Steps%20to%20Reduce%20a%20Number%20to%20Zero/README_EN.md", "title_cn": "\u5c06\u6570\u5b57\u53d8\u6210 0 \u7684\u64cd\u4f5c\u6b21\u6570", "title_en": "Number of Steps to Reduce a Number to Zero", "question_title_slug": "number-of-steps-to-reduce-a-number-to-zero", "content_en": "

Given a non-negative integer num, return the number of steps to reduce it to zero. If the current number is even, you have to divide it by 2, otherwise, you have to subtract 1 from it.

\n\n

 

\n

Example 1:

\n\n
\nInput: num = 14\nOutput: 6\nExplanation: \nStep 1) 14 is even; divide by 2 and obtain 7. \nStep 2) 7 is odd; subtract 1 and obtain 6.\nStep 3) 6 is even; divide by 2 and obtain 3. \nStep 4) 3 is odd; subtract 1 and obtain 2. \nStep 5) 2 is even; divide by 2 and obtain 1. \nStep 6) 1 is odd; subtract 1 and obtain 0.\n
\n\n

Example 2:

\n\n
\nInput: num = 8\nOutput: 4\nExplanation: \nStep 1) 8 is even; divide by 2 and obtain 4. \nStep 2) 4 is even; divide by 2 and obtain 2. \nStep 3) 2 is even; divide by 2 and obtain 1. \nStep 4) 1 is odd; subtract 1 and obtain 0.\n
\n\n

Example 3:

\n\n
\nInput: num = 123\nOutput: 12\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 0 <= num <= 10^6
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u975e\u8d1f\u6574\u6570 num \uff0c\u8bf7\u4f60\u8fd4\u56de\u5c06\u5b83\u53d8\u6210 0 \u6240\u9700\u8981\u7684\u6b65\u6570\u3002 \u5982\u679c\u5f53\u524d\u6570\u5b57\u662f\u5076\u6570\uff0c\u4f60\u9700\u8981\u628a\u5b83\u9664\u4ee5 2 \uff1b\u5426\u5219\uff0c\u51cf\u53bb 1 \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anum = 14\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\n\u6b65\u9aa4 1) 14 \u662f\u5076\u6570\uff0c\u9664\u4ee5 2 \u5f97\u5230 7 \u3002\n\u6b65\u9aa4 2\uff09 7 \u662f\u5947\u6570\uff0c\u51cf 1 \u5f97\u5230 6 \u3002\n\u6b65\u9aa4 3\uff09 6 \u662f\u5076\u6570\uff0c\u9664\u4ee5 2 \u5f97\u5230 3 \u3002\n\u6b65\u9aa4 4\uff09 3 \u662f\u5947\u6570\uff0c\u51cf 1 \u5f97\u5230 2 \u3002\n\u6b65\u9aa4 5\uff09 2 \u662f\u5076\u6570\uff0c\u9664\u4ee5 2 \u5f97\u5230 1 \u3002\n\u6b65\u9aa4 6\uff09 1 \u662f\u5947\u6570\uff0c\u51cf 1 \u5f97\u5230 0 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anum = 8\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\n\u6b65\u9aa4 1\uff09 8 \u662f\u5076\u6570\uff0c\u9664\u4ee5 2 \u5f97\u5230 4 \u3002\n\u6b65\u9aa4 2\uff09 4 \u662f\u5076\u6570\uff0c\u9664\u4ee5 2 \u5f97\u5230 2 \u3002\n\u6b65\u9aa4 3\uff09 2 \u662f\u5076\u6570\uff0c\u9664\u4ee5 2 \u5f97\u5230 1 \u3002\n\u6b65\u9aa4 4\uff09 1 \u662f\u5947\u6570\uff0c\u51cf 1 \u5f97\u5230 0 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1anum = 123\n\u8f93\u51fa\uff1a12\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 0 <= num <= 10^6
  • \n
\n", "tags_en": ["Bit Manipulation"], "tags_cn": ["\u4f4d\u8fd0\u7b97"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numberOfSteps(int num) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numberOfSteps(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numberOfSteps(self, num):\n \"\"\"\n :type num: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numberOfSteps(self, num: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numberOfSteps(int num){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumberOfSteps(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} num\n * @return {number}\n */\nvar numberOfSteps = function(num) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} num\n# @return {Integer}\ndef number_of_steps(num)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numberOfSteps(_ num: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numberOfSteps(num int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numberOfSteps(num: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numberOfSteps(num: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn number_of_steps(num: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $num\n * @return Integer\n */\n function numberOfSteps($num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numberOfSteps(num: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (number-of-steps num)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1342](https://leetcode-cn.com/problems/number-of-steps-to-reduce-a-number-to-zero)", "[\u5c06\u6570\u5b57\u53d8\u6210 0 \u7684\u64cd\u4f5c\u6b21\u6570](/solution/1300-1399/1342.Number%20of%20Steps%20to%20Reduce%20a%20Number%20to%20Zero/README.md)", "`\u4f4d\u8fd0\u7b97`", "\u7b80\u5355", ""], "md_table_row_en": ["[1342](https://leetcode.com/problems/number-of-steps-to-reduce-a-number-to-zero)", "[Number of Steps to Reduce a Number to Zero](/solution/1300-1399/1342.Number%20of%20Steps%20to%20Reduce%20a%20Number%20to%20Zero/README_EN.md)", "`Bit Manipulation`", "Easy", ""]}, {"question_id": "1443", "frontend_question_id": "1320", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-distance-to-type-a-word-using-two-fingers", "url_en": "https://leetcode.com/problems/minimum-distance-to-type-a-word-using-two-fingers", "relative_path_cn": "/solution/1300-1399/1320.Minimum%20Distance%20to%20Type%20a%20Word%20Using%20Two%20Fingers/README.md", "relative_path_en": "/solution/1300-1399/1320.Minimum%20Distance%20to%20Type%20a%20Word%20Using%20Two%20Fingers/README_EN.md", "title_cn": "\u4e8c\u6307\u8f93\u5165\u7684\u7684\u6700\u5c0f\u8ddd\u79bb", "title_en": "Minimum Distance to Type a Word Using Two Fingers", "question_title_slug": "minimum-distance-to-type-a-word-using-two-fingers", "content_en": "

\"\"

\r\n\r\n

You have a keyboard layout as shown above in the XY plane, where each English uppercase letter is located at some coordinate, for example, the letter A is located at coordinate (0,0), the letter B is located at coordinate (0,1), the letter P is located at coordinate (2,3) and the letter Z is located at coordinate (4,1).

\r\n\r\n

Given the string word, return the minimum total distance to type such string using only two fingers. The distance between coordinates (x1,y1) and (x2,y2) is |x1 - x2| + |y1 - y2|

\r\n\r\n

Note that the initial positions of your two fingers are considered free so don't count towards your total distance, also your two fingers do not have to start at the first letter or the first two letters.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: word = "CAKE"\r\nOutput: 3\r\nExplanation: \r\nUsing two fingers, one optimal way to type "CAKE" is: \r\nFinger 1 on letter 'C' -> cost = 0 \r\nFinger 1 on letter 'A' -> cost = Distance from letter 'C' to letter 'A' = 2 \r\nFinger 2 on letter 'K' -> cost = 0 \r\nFinger 2 on letter 'E' -> cost = Distance from letter 'K' to letter 'E' = 1 \r\nTotal distance = 3\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: word = "HAPPY"\r\nOutput: 6\r\nExplanation: \r\nUsing two fingers, one optimal way to type "HAPPY" is:\r\nFinger 1 on letter 'H' -> cost = 0\r\nFinger 1 on letter 'A' -> cost = Distance from letter 'H' to letter 'A' = 2\r\nFinger 2 on letter 'P' -> cost = 0\r\nFinger 2 on letter 'P' -> cost = Distance from letter 'P' to letter 'P' = 0\r\nFinger 1 on letter 'Y' -> cost = Distance from letter 'A' to letter 'Y' = 4\r\nTotal distance = 6\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: word = "NEW"\r\nOutput: 3\r\n
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: word = "YEAR"\r\nOutput: 7\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 2 <= word.length <= 300
  • \r\n\t
  • Each word[i] is an English uppercase letter.
  • \r\n
", "content_cn": "

\"\"

\n\n

\u4e8c\u6307\u8f93\u5165\u6cd5\u5b9a\u5236\u952e\u76d8\u5728 XY \u5e73\u9762\u4e0a\u7684\u5e03\u5c40\u5982\u4e0a\u56fe\u6240\u793a\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5927\u5199\u82f1\u6587\u5b57\u6bcd\u90fd\u4f4d\u4e8e\u67d0\u4e2a\u5750\u6807\u5904\uff0c\u4f8b\u5982\u5b57\u6bcd A \u4f4d\u4e8e\u5750\u6807 (0,0)\uff0c\u5b57\u6bcd B \u4f4d\u4e8e\u5750\u6807 (0,1)\uff0c\u5b57\u6bcd P \u4f4d\u4e8e\u5750\u6807 (2,3) \u4e14\u5b57\u6bcd Z \u4f4d\u4e8e\u5750\u6807 (4,1)\u3002

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u5f85\u8f93\u5165\u5b57\u7b26\u4e32 word\uff0c\u8bf7\u4f60\u8ba1\u7b97\u5e76\u8fd4\u56de\u5728\u4ec5\u4f7f\u7528\u4e24\u6839\u624b\u6307\u7684\u60c5\u51b5\u4e0b\uff0c\u952e\u5165\u8be5\u5b57\u7b26\u4e32\u9700\u8981\u7684\u6700\u5c0f\u79fb\u52a8\u603b\u8ddd\u79bb\u3002\u5750\u6807 (x1,y1) \u548c (x2,y2) \u4e4b\u95f4\u7684\u8ddd\u79bb\u662f |x1 - x2| + |y1 - y2|\u3002 

\n\n

\u6ce8\u610f\uff0c\u4e24\u6839\u624b\u6307\u7684\u8d77\u59cb\u4f4d\u7f6e\u662f\u96f6\u4ee3\u4ef7\u7684\uff0c\u4e0d\u8ba1\u5165\u79fb\u52a8\u603b\u8ddd\u79bb\u3002\u4f60\u7684\u4e24\u6839\u624b\u6307\u7684\u8d77\u59cb\u4f4d\u7f6e\u4e5f\u4e0d\u5fc5\u4ece\u9996\u5b57\u6bcd\u6216\u8005\u524d\u4e24\u4e2a\u5b57\u6bcd\u5f00\u59cb\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aword = "CAKE"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a \n\u4f7f\u7528\u4e24\u6839\u624b\u6307\u8f93\u5165 "CAKE" \u7684\u6700\u4f73\u65b9\u6848\u4e4b\u4e00\u662f\uff1a \n\u624b\u6307 1 \u5728\u5b57\u6bcd 'C' \u4e0a -> \u79fb\u52a8\u8ddd\u79bb = 0 \n\u624b\u6307 1 \u5728\u5b57\u6bcd 'A' \u4e0a -> \u79fb\u52a8\u8ddd\u79bb = \u4ece\u5b57\u6bcd 'C' \u5230\u5b57\u6bcd 'A' \u7684\u8ddd\u79bb = 2 \n\u624b\u6307 2 \u5728\u5b57\u6bcd 'K' \u4e0a -> \u79fb\u52a8\u8ddd\u79bb = 0 \n\u624b\u6307 2 \u5728\u5b57\u6bcd 'E' \u4e0a -> \u79fb\u52a8\u8ddd\u79bb = \u4ece\u5b57\u6bcd 'K' \u5230\u5b57\u6bcd 'E' \u7684\u8ddd\u79bb  = 1 \n\u603b\u8ddd\u79bb = 3\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aword = "HAPPY"\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a \n\u4f7f\u7528\u4e24\u6839\u624b\u6307\u8f93\u5165 "HAPPY" \u7684\u6700\u4f73\u65b9\u6848\u4e4b\u4e00\u662f\uff1a\n\u624b\u6307 1 \u5728\u5b57\u6bcd 'H' \u4e0a -> \u79fb\u52a8\u8ddd\u79bb = 0\n\u624b\u6307 1 \u5728\u5b57\u6bcd 'A' \u4e0a -> \u79fb\u52a8\u8ddd\u79bb = \u4ece\u5b57\u6bcd 'H' \u5230\u5b57\u6bcd 'A' \u7684\u8ddd\u79bb = 2\n\u624b\u6307 2 \u5728\u5b57\u6bcd 'P' \u4e0a -> \u79fb\u52a8\u8ddd\u79bb = 0\n\u624b\u6307 2 \u5728\u5b57\u6bcd 'P' \u4e0a -> \u79fb\u52a8\u8ddd\u79bb = \u4ece\u5b57\u6bcd 'P' \u5230\u5b57\u6bcd 'P' \u7684\u8ddd\u79bb = 0\n\u624b\u6307 1 \u5728\u5b57\u6bcd 'Y' \u4e0a -> \u79fb\u52a8\u8ddd\u79bb = \u4ece\u5b57\u6bcd 'A' \u5230\u5b57\u6bcd 'Y' \u7684\u8ddd\u79bb = 4\n\u603b\u8ddd\u79bb = 6\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aword = "NEW"\n\u8f93\u51fa\uff1a3\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1aword = "YEAR"\n\u8f93\u51fa\uff1a7\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= word.length <= 300
  • \n\t
  • \u6bcf\u4e2a word[i] \u90fd\u662f\u4e00\u4e2a\u5927\u5199\u82f1\u6587\u5b57\u6bcd\u3002
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minimumDistance(string word) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minimumDistance(String word) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimumDistance(self, word):\n \"\"\"\n :type word: str\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimumDistance(self, word: str) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minimumDistance(char * word){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinimumDistance(string word) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} word\n * @return {number}\n */\nvar minimumDistance = function(word) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} word\n# @return {Integer}\ndef minimum_distance(word)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimumDistance(_ word: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimumDistance(word string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimumDistance(word: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimumDistance(word: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimum_distance(word: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $word\n * @return Integer\n */\n function minimumDistance($word) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimumDistance(word: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimum-distance word)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1320](https://leetcode-cn.com/problems/minimum-distance-to-type-a-word-using-two-fingers)", "[\u4e8c\u6307\u8f93\u5165\u7684\u7684\u6700\u5c0f\u8ddd\u79bb](/solution/1300-1399/1320.Minimum%20Distance%20to%20Type%20a%20Word%20Using%20Two%20Fingers/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1320](https://leetcode.com/problems/minimum-distance-to-type-a-word-using-two-fingers)", "[Minimum Distance to Type a Word Using Two Fingers](/solution/1300-1399/1320.Minimum%20Distance%20to%20Type%20a%20Word%20Using%20Two%20Fingers/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1442", "frontend_question_id": "1319", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-operations-to-make-network-connected", "url_en": "https://leetcode.com/problems/number-of-operations-to-make-network-connected", "relative_path_cn": "/solution/1300-1399/1319.Number%20of%20Operations%20to%20Make%20Network%20Connected/README.md", "relative_path_en": "/solution/1300-1399/1319.Number%20of%20Operations%20to%20Make%20Network%20Connected/README_EN.md", "title_cn": "\u8fde\u901a\u7f51\u7edc\u7684\u64cd\u4f5c\u6b21\u6570", "title_en": "Number of Operations to Make Network Connected", "question_title_slug": "number-of-operations-to-make-network-connected", "content_en": "

There are n computers numbered from 0 to n-1 connected by ethernet cables connections forming a network where connections[i] = [a, b] represents a connection between computers a and b. Any computer can reach any other computer directly or indirectly through the network.

\n\n

Given an initial computer network connections. You can extract certain cables between two directly connected computers, and place them between any pair of disconnected computers to make them directly connected. Return the minimum number of times you need to do this in order to make all the computers connected. If it's not possible, return -1. 

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: n = 4, connections = [[0,1],[0,2],[1,2]]\nOutput: 1\nExplanation: Remove cable between computer 1 and 2 and place between computers 1 and 3.\n
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: n = 6, connections = [[0,1],[0,2],[0,3],[1,2],[1,3]]\nOutput: 2\n
\n\n

Example 3:

\n\n
\nInput: n = 6, connections = [[0,1],[0,2],[0,3],[1,2]]\nOutput: -1\nExplanation: There are not enough cables.\n
\n\n

Example 4:

\n\n
\nInput: n = 5, connections = [[0,1],[0,2],[3,4],[2,3]]\nOutput: 0\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 10^5
  • \n\t
  • 1 <= connections.length <= min(n*(n-1)/2, 10^5)
  • \n\t
  • connections[i].length == 2
  • \n\t
  • 0 <= connections[i][0], connections[i][1] < n
  • \n\t
  • connections[i][0] != connections[i][1]
  • \n\t
  • There are no repeated connections.
  • \n\t
  • No two computers are connected by more than one cable.
  • \n
\n", "content_cn": "

\u7528\u4ee5\u592a\u7f51\u7ebf\u7f06\u5c06 n \u53f0\u8ba1\u7b97\u673a\u8fde\u63a5\u6210\u4e00\u4e2a\u7f51\u7edc\uff0c\u8ba1\u7b97\u673a\u7684\u7f16\u53f7\u4ece 0 \u5230 n-1\u3002\u7ebf\u7f06\u7528 connections \u8868\u793a\uff0c\u5176\u4e2d connections[i] = [a, b] \u8fde\u63a5\u4e86\u8ba1\u7b97\u673a a \u548c b\u3002

\n\n

\u7f51\u7edc\u4e2d\u7684\u4efb\u4f55\u4e00\u53f0\u8ba1\u7b97\u673a\u90fd\u53ef\u4ee5\u901a\u8fc7\u7f51\u7edc\u76f4\u63a5\u6216\u8005\u95f4\u63a5\u8bbf\u95ee\u540c\u4e00\u4e2a\u7f51\u7edc\u4e2d\u5176\u4ed6\u4efb\u610f\u4e00\u53f0\u8ba1\u7b97\u673a\u3002

\n\n

\u7ed9\u4f60\u8fd9\u4e2a\u8ba1\u7b97\u673a\u7f51\u7edc\u7684\u521d\u59cb\u5e03\u7ebf connections\uff0c\u4f60\u53ef\u4ee5\u62d4\u5f00\u4efb\u610f\u4e24\u53f0\u76f4\u8fde\u8ba1\u7b97\u673a\u4e4b\u95f4\u7684\u7ebf\u7f06\uff0c\u5e76\u7528\u5b83\u8fde\u63a5\u4e00\u5bf9\u672a\u76f4\u8fde\u7684\u8ba1\u7b97\u673a\u3002\u8bf7\u4f60\u8ba1\u7b97\u5e76\u8fd4\u56de\u4f7f\u6240\u6709\u8ba1\u7b97\u673a\u90fd\u8fde\u901a\u6240\u9700\u7684\u6700\u5c11\u64cd\u4f5c\u6b21\u6570\u3002\u5982\u679c\u4e0d\u53ef\u80fd\uff0c\u5219\u8fd4\u56de -1 \u3002 

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1an = 4, connections = [[0,1],[0,2],[1,2]]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u62d4\u4e0b\u8ba1\u7b97\u673a 1 \u548c 2 \u4e4b\u95f4\u7684\u7ebf\u7f06\uff0c\u5e76\u5c06\u5b83\u63d2\u5230\u8ba1\u7b97\u673a 1 \u548c 3 \u4e0a\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1an = 6, connections = [[0,1],[0,2],[0,3],[1,2],[1,3]]\n\u8f93\u51fa\uff1a2\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1an = 6, connections = [[0,1],[0,2],[0,3],[1,2]]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u7ebf\u7f06\u6570\u91cf\u4e0d\u8db3\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1an = 5, connections = [[0,1],[0,2],[3,4],[2,3]]\n\u8f93\u51fa\uff1a0\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 10^5
  • \n\t
  • 1 <= connections.length <= min(n*(n-1)/2, 10^5)
  • \n\t
  • connections[i].length == 2
  • \n\t
  • 0 <= connections[i][0], connections[i][1] < n
  • \n\t
  • connections[i][0] != connections[i][1]
  • \n\t
  • \u6ca1\u6709\u91cd\u590d\u7684\u8fde\u63a5\u3002
  • \n\t
  • \u4e24\u53f0\u8ba1\u7b97\u673a\u4e0d\u4f1a\u901a\u8fc7\u591a\u6761\u7ebf\u7f06\u8fde\u63a5\u3002
  • \n
\n", "tags_en": ["Depth-first Search", "Breadth-first Search", "Union Find"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e76\u67e5\u96c6"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int makeConnected(int n, vector>& connections) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int makeConnected(int n, int[][] connections) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def makeConnected(self, n, connections):\n \"\"\"\n :type n: int\n :type connections: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def makeConnected(self, n: int, connections: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint makeConnected(int n, int** connections, int connectionsSize, int* connectionsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MakeConnected(int n, int[][] connections) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} connections\n * @return {number}\n */\nvar makeConnected = function(n, connections) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} connections\n# @return {Integer}\ndef make_connected(n, connections)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func makeConnected(_ n: Int, _ connections: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func makeConnected(n int, connections [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def makeConnected(n: Int, connections: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun makeConnected(n: Int, connections: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn make_connected(n: i32, connections: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $connections\n * @return Integer\n */\n function makeConnected($n, $connections) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function makeConnected(n: number, connections: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (make-connected n connections)\n (-> exact-integer? (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1319](https://leetcode-cn.com/problems/number-of-operations-to-make-network-connected)", "[\u8fde\u901a\u7f51\u7edc\u7684\u64cd\u4f5c\u6b21\u6570](/solution/1300-1399/1319.Number%20of%20Operations%20to%20Make%20Network%20Connected/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e76\u67e5\u96c6`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1319](https://leetcode.com/problems/number-of-operations-to-make-network-connected)", "[Number of Operations to Make Network Connected](/solution/1300-1399/1319.Number%20of%20Operations%20to%20Make%20Network%20Connected/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`,`Union Find`", "Medium", ""]}, {"question_id": "1441", "frontend_question_id": "1318", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-flips-to-make-a-or-b-equal-to-c", "url_en": "https://leetcode.com/problems/minimum-flips-to-make-a-or-b-equal-to-c", "relative_path_cn": "/solution/1300-1399/1318.Minimum%20Flips%20to%20Make%20a%20OR%20b%20Equal%20to%20c/README.md", "relative_path_en": "/solution/1300-1399/1318.Minimum%20Flips%20to%20Make%20a%20OR%20b%20Equal%20to%20c/README_EN.md", "title_cn": "\u6216\u8fd0\u7b97\u7684\u6700\u5c0f\u7ffb\u8f6c\u6b21\u6570", "title_en": "Minimum Flips to Make a OR b Equal to c", "question_title_slug": "minimum-flips-to-make-a-or-b-equal-to-c", "content_en": "

Given 3 positives numbers a, b and c. Return the minimum flips required in some bits of a and b to make ( a OR b == c ). (bitwise OR operation).
\r\nFlip operation consists of change any single bit 1 to 0 or change the bit 0 to 1 in their binary representation.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n

\"\"

\r\n\r\n
\r\nInput: a = 2, b = 6, c = 5\r\nOutput: 3\r\nExplanation: After flips a = 1 , b = 4 , c = 5 such that (a OR b == c)
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: a = 4, b = 2, c = 7\r\nOutput: 1\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: a = 1, b = 2, c = 3\r\nOutput: 0\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= a <= 10^9
  • \r\n\t
  • 1 <= b <= 10^9
  • \r\n\t
  • 1 <= c <= 10^9
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e09\u4e2a\u6b63\u6574\u6570 a\u3001b \u548c c\u3002

\n\n

\u4f60\u53ef\u4ee5\u5bf9 a \u548c b \u7684\u4e8c\u8fdb\u5236\u8868\u793a\u8fdb\u884c\u4f4d\u7ffb\u8f6c\u64cd\u4f5c\uff0c\u8fd4\u56de\u80fd\u591f\u4f7f\u6309\u4f4d\u6216\u8fd0\u7b97   a OR b == c  \u6210\u7acb\u7684\u6700\u5c0f\u7ffb\u8f6c\u6b21\u6570\u3002

\n\n

\u300c\u4f4d\u7ffb\u8f6c\u64cd\u4f5c\u300d\u662f\u6307\u5c06\u4e00\u4e2a\u6570\u7684\u4e8c\u8fdb\u5236\u8868\u793a\u4efb\u4f55\u5355\u4e2a\u4f4d\u4e0a\u7684 1 \u53d8\u6210 0 \u6216\u8005 0 \u53d8\u6210 1 \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1aa = 2, b = 6, c = 5\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u7ffb\u8f6c\u540e a = 1 , b = 4 , c = 5 \u4f7f\u5f97 a OR b == c
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aa = 4, b = 2, c = 7\n\u8f93\u51fa\uff1a1\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aa = 1, b = 2, c = 3\n\u8f93\u51fa\uff1a0\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= a <= 10^9
  • \n\t
  • 1 <= b <= 10^9
  • \n\t
  • 1 <= c <= 10^9
  • \n
\n", "tags_en": ["Bit Manipulation"], "tags_cn": ["\u4f4d\u8fd0\u7b97"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minFlips(int a, int b, int c) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minFlips(int a, int b, int c) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minFlips(self, a, b, c):\n \"\"\"\n :type a: int\n :type b: int\n :type c: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minFlips(self, a: int, b: int, c: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minFlips(int a, int b, int c){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinFlips(int a, int b, int c) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} a\n * @param {number} b\n * @param {number} c\n * @return {number}\n */\nvar minFlips = function(a, b, c) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} a\n# @param {Integer} b\n# @param {Integer} c\n# @return {Integer}\ndef min_flips(a, b, c)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minFlips(_ a: Int, _ b: Int, _ c: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minFlips(a int, b int, c int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minFlips(a: Int, b: Int, c: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minFlips(a: Int, b: Int, c: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_flips(a: i32, b: i32, c: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $a\n * @param Integer $b\n * @param Integer $c\n * @return Integer\n */\n function minFlips($a, $b, $c) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minFlips(a: number, b: number, c: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-flips a b c)\n (-> exact-integer? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1318](https://leetcode-cn.com/problems/minimum-flips-to-make-a-or-b-equal-to-c)", "[\u6216\u8fd0\u7b97\u7684\u6700\u5c0f\u7ffb\u8f6c\u6b21\u6570](/solution/1300-1399/1318.Minimum%20Flips%20to%20Make%20a%20OR%20b%20Equal%20to%20c/README.md)", "`\u4f4d\u8fd0\u7b97`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1318](https://leetcode.com/problems/minimum-flips-to-make-a-or-b-equal-to-c)", "[Minimum Flips to Make a OR b Equal to c](/solution/1300-1399/1318.Minimum%20Flips%20to%20Make%20a%20OR%20b%20Equal%20to%20c/README_EN.md)", "`Bit Manipulation`", "Medium", ""]}, {"question_id": "1440", "frontend_question_id": "1317", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers", "url_en": "https://leetcode.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers", "relative_path_cn": "/solution/1300-1399/1317.Convert%20Integer%20to%20the%20Sum%20of%20Two%20No-Zero%20Integers/README.md", "relative_path_en": "/solution/1300-1399/1317.Convert%20Integer%20to%20the%20Sum%20of%20Two%20No-Zero%20Integers/README_EN.md", "title_cn": "\u5c06\u6574\u6570\u8f6c\u6362\u4e3a\u4e24\u4e2a\u65e0\u96f6\u6574\u6570\u7684\u548c", "title_en": "Convert Integer to the Sum of Two No-Zero Integers", "question_title_slug": "convert-integer-to-the-sum-of-two-no-zero-integers", "content_en": "

Given an integer n. No-Zero integer is a positive integer which doesn't contain any 0 in its decimal representation.

\r\n\r\n

Return a list of two integers [A, B] where:

\r\n\r\n
    \r\n\t
  • A and B are No-Zero integers.
  • \r\n\t
  • A + B = n
  • \r\n
\r\n\r\n

It's guarateed that there is at least one valid solution. If there are many valid solutions you can return any of them.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: n = 2\r\nOutput: [1,1]\r\nExplanation: A = 1, B = 1. A + B = n and both A and B don't contain any 0 in their decimal representation.\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: n = 11\r\nOutput: [2,9]\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: n = 10000\r\nOutput: [1,9999]\r\n
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: n = 69\r\nOutput: [1,68]\r\n
\r\n\r\n

Example 5:

\r\n\r\n
\r\nInput: n = 1010\r\nOutput: [11,999]\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 2 <= n <= 10^4
  • \r\n
", "content_cn": "

\u300c\u65e0\u96f6\u6574\u6570\u300d\u662f\u5341\u8fdb\u5236\u8868\u793a\u4e2d \u4e0d\u542b\u4efb\u4f55 0 \u7684\u6b63\u6574\u6570\u3002

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n\uff0c\u8bf7\u4f60\u8fd4\u56de\u4e00\u4e2a \u7531\u4e24\u4e2a\u6574\u6570\u7ec4\u6210\u7684\u5217\u8868 [A, B]\uff0c\u6ee1\u8db3\uff1a

\n\n
    \n\t
  • A \u548c B \u90fd\u662f\u65e0\u96f6\u6574\u6570
  • \n\t
  • A + B = n
  • \n
\n\n

\u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u81f3\u5c11\u6709\u4e00\u4e2a\u6709\u6548\u7684\u89e3\u51b3\u65b9\u6848\u3002

\n\n

\u5982\u679c\u5b58\u5728\u591a\u4e2a\u6709\u6548\u89e3\u51b3\u65b9\u6848\uff0c\u4f60\u53ef\u4ee5\u8fd4\u56de\u5176\u4e2d\u4efb\u610f\u4e00\u4e2a\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1an = 2\n\u8f93\u51fa\uff1a[1,1]\n\u89e3\u91ca\uff1aA = 1, B = 1. A + B = n \u5e76\u4e14 A \u548c B \u7684\u5341\u8fdb\u5236\u8868\u793a\u5f62\u5f0f\u90fd\u4e0d\u5305\u542b\u4efb\u4f55 0 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1an = 11\n\u8f93\u51fa\uff1a[2,9]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1an = 10000\n\u8f93\u51fa\uff1a[1,9999]\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1an = 69\n\u8f93\u51fa\uff1a[1,68]\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1an = 1010\n\u8f93\u51fa\uff1a[11,999]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= n <= 10^4
  • \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector getNoZeroIntegers(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] getNoZeroIntegers(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getNoZeroIntegers(self, n):\n \"\"\"\n :type n: int\n :rtype: List[int]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getNoZeroIntegers(self, n: int) -> List[int]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* getNoZeroIntegers(int n, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] GetNoZeroIntegers(int n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number[]}\n */\nvar getNoZeroIntegers = function(n) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer[]}\ndef get_no_zero_integers(n)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getNoZeroIntegers(_ n: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getNoZeroIntegers(n int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getNoZeroIntegers(n: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getNoZeroIntegers(n: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_no_zero_integers(n: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer[]\n */\n function getNoZeroIntegers($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getNoZeroIntegers(n: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-no-zero-integers n)\n (-> exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1317](https://leetcode-cn.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers)", "[\u5c06\u6574\u6570\u8f6c\u6362\u4e3a\u4e24\u4e2a\u65e0\u96f6\u6574\u6570\u7684\u548c](/solution/1300-1399/1317.Convert%20Integer%20to%20the%20Sum%20of%20Two%20No-Zero%20Integers/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[1317](https://leetcode.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers)", "[Convert Integer to the Sum of Two No-Zero Integers](/solution/1300-1399/1317.Convert%20Integer%20to%20the%20Sum%20of%20Two%20No-Zero%20Integers/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "1439", "frontend_question_id": "1308", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/running-total-for-different-genders", "url_en": "https://leetcode.com/problems/running-total-for-different-genders", "relative_path_cn": "/solution/1300-1399/1308.Running%20Total%20for%20Different%20Genders/README.md", "relative_path_en": "/solution/1300-1399/1308.Running%20Total%20for%20Different%20Genders/README_EN.md", "title_cn": "\u4e0d\u540c\u6027\u522b\u6bcf\u65e5\u5206\u6570\u603b\u8ba1", "title_en": "Running Total for Different Genders", "question_title_slug": "running-total-for-different-genders", "content_en": "

Table: Scores

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| player_name   | varchar |\n| gender        | varchar |\n| day           | date    |\n| score_points  | int     |\n+---------------+---------+\n(gender, day) is the primary key for this table.\nA competition is held between females team and males team.\nEach row of this table indicates that a player_name and with gender has scored score_point in someday.\nGender is 'F' if the player is in females team and 'M' if the player is in males team.\n
\n\n

 

\n\n

Write an SQL query to find the total score for each gender at each day.

\n\n

Order the result table by gender and day

\n\n

The query result format is in the following example:

\n\n
\nScores table:\n+-------------+--------+------------+--------------+\n| player_name | gender | day        | score_points |\n+-------------+--------+------------+--------------+\n| Aron        | F      | 2020-01-01 | 17           |\n| Alice       | F      | 2020-01-07 | 23           |\n| Bajrang     | M      | 2020-01-07 | 7            |\n| Khali       | M      | 2019-12-25 | 11           |\n| Slaman      | M      | 2019-12-30 | 13           |\n| Joe         | M      | 2019-12-31 | 3            |\n| Jose        | M      | 2019-12-18 | 2            |\n| Priya       | F      | 2019-12-31 | 23           |\n| Priyanka    | F      | 2019-12-30 | 17           |\n+-------------+--------+------------+--------------+\nResult table:\n+--------+------------+-------+\n| gender | day        | total |\n+--------+------------+-------+\n| F      | 2019-12-30 | 17    |\n| F      | 2019-12-31 | 40    |\n| F      | 2020-01-01 | 57    |\n| F      | 2020-01-07 | 80    |\n| M      | 2019-12-18 | 2     |\n| M      | 2019-12-25 | 13    |\n| M      | 2019-12-30 | 26    |\n| M      | 2019-12-31 | 29    |\n| M      | 2020-01-07 | 36    |\n+--------+------------+-------+\nFor females team:\nFirst day is 2019-12-30, Priyanka scored 17 points and the total score for the team is 17.\nSecond day is 2019-12-31, Priya scored 23 points and the total score for the team is 40.\nThird day is 2020-01-01, Aron scored 17 points and the total score for the team is 57.\nFourth day is 2020-01-07, Alice scored 23 points and the total score for the team is 80.\nFor males team:\nFirst day is 2019-12-18, Jose scored 2 points and the total score for the team is 2.\nSecond day is 2019-12-25, Khali scored 11 points and the total score for the team is 13.\nThird day is 2019-12-30, Slaman scored 13 points and the total score for the team is 26.\nFourth day is 2019-12-31, Joe scored 3 points and the total score for the team is 29.\nFifth day is 2020-01-07, Bajrang scored 7 points and the total score for the team is 36.\n
\n", "content_cn": "

\u8868: Scores

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| player_name   | varchar |\n| gender        | varchar |\n| day           | date    |\n| score_points  | int     |\n+---------------+---------+\n(gender, day)\u662f\u8be5\u8868\u7684\u4e3b\u952e\n\u4e00\u573a\u6bd4\u8d5b\u662f\u5728\u5973\u961f\u548c\u7537\u961f\u4e4b\u95f4\u4e3e\u884c\u7684\n\u8be5\u8868\u7684\u6bcf\u4e00\u884c\u8868\u793a\u4e00\u4e2a\u540d\u53eb (player_name) \u6027\u522b\u4e3a (gender) \u7684\u53c2\u8d5b\u8005\u5728\u67d0\u4e00\u5929\u83b7\u5f97\u4e86 (score_points) \u7684\u5206\u6570\n\u5982\u679c\u53c2\u8d5b\u8005\u662f\u5973\u6027\uff0c\u90a3\u4e48 gender \u5217\u4e3a 'F'\uff0c\u5982\u679c\u53c2\u8d5b\u8005\u662f\u7537\u6027\uff0c\u90a3\u4e48 gender \u5217\u4e3a 'M'\n
\n\n

 

\n\n

\u5199\u4e00\u6761SQL\u8bed\u53e5\u67e5\u8be2\u6bcf\u79cd\u6027\u522b\u5728\u6bcf\u4e00\u5929\u7684\u603b\u5206\uff0c\u5e76\u6309\u6027\u522b\u548c\u65e5\u671f\u5bf9\u67e5\u8be2\u7ed3\u679c\u6392\u5e8f

\n\n

\u4e0b\u9762\u662f\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u7684\u4f8b\u5b50\uff1a

\n\n
\nScores\u8868:\n+-------------+--------+------------+--------------+\n| player_name | gender | day        | score_points |\n+-------------+--------+------------+--------------+\n| Aron        | F      | 2020-01-01 | 17           |\n| Alice       | F      | 2020-01-07 | 23           |\n| Bajrang     | M      | 2020-01-07 | 7            |\n| Khali       | M      | 2019-12-25 | 11           |\n| Slaman      | M      | 2019-12-30 | 13           |\n| Joe         | M      | 2019-12-31 | 3            |\n| Jose        | M      | 2019-12-18 | 2            |\n| Priya       | F      | 2019-12-31 | 23           |\n| Priyanka    | F      | 2019-12-30 | 17           |\n+-------------+--------+------------+--------------+\n\u7ed3\u679c\u8868:\n+--------+------------+-------+\n| gender | day        | total |\n+--------+------------+-------+\n| F      | 2019-12-30 | 17    |\n| F      | 2019-12-31 | 40    |\n| F      | 2020-01-01 | 57    |\n| F      | 2020-01-07 | 80    |\n| M      | 2019-12-18 | 2     |\n| M      | 2019-12-25 | 13    |\n| M      | 2019-12-30 | 26    |\n| M      | 2019-12-31 | 29    |\n| M      | 2020-01-07 | 36    |\n+--------+------------+-------+\n\u5973\u6027\u961f\u4f0d:\n\u7b2c\u4e00\u5929\u662f 2019-12-30\uff0cPriyanka \u83b7\u5f97 17 \u5206\uff0c\u961f\u4f0d\u7684\u603b\u5206\u662f 17 \u5206\n\u7b2c\u4e8c\u5929\u662f 2019-12-31, Priya \u83b7\u5f97 23 \u5206\uff0c\u961f\u4f0d\u7684\u603b\u5206\u662f 40 \u5206\n\u7b2c\u4e09\u5929\u662f 2020-01-01, Aron \u83b7\u5f97 17 \u5206\uff0c\u961f\u4f0d\u7684\u603b\u5206\u662f 57 \u5206\n\u7b2c\u56db\u5929\u662f 2020-01-07, Alice \u83b7\u5f97 23 \u5206\uff0c\u961f\u4f0d\u7684\u603b\u5206\u662f 80 \u5206\n\u7537\u6027\u961f\u4f0d\uff1a\n\u7b2c\u4e00\u5929\u662f 2019-12-18, Jose \u83b7\u5f97 2 \u5206\uff0c\u961f\u4f0d\u7684\u603b\u5206\u662f 2 \u5206\n\u7b2c\u4e8c\u5929\u662f 2019-12-25, Khali \u83b7\u5f97 11 \u5206\uff0c\u961f\u4f0d\u7684\u603b\u5206\u662f 13 \u5206\n\u7b2c\u4e09\u5929\u662f 2019-12-30, Slaman \u83b7\u5f97 13 \u5206\uff0c\u961f\u4f0d\u7684\u603b\u5206\u662f 26 \u5206\n\u7b2c\u56db\u5929\u662f 2019-12-31, Joe \u83b7\u5f97 3 \u5206\uff0c\u961f\u4f0d\u7684\u603b\u5206\u662f 29 \u5206\n\u7b2c\u4e94\u5929\u662f 2020-01-07, Bajrang \u83b7\u5f97 7 \u5206\uff0c\u961f\u4f0d\u7684\u603b\u5206\u662f 36 \u5206\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1308](https://leetcode-cn.com/problems/running-total-for-different-genders)", "[\u4e0d\u540c\u6027\u522b\u6bcf\u65e5\u5206\u6570\u603b\u8ba1](/solution/1300-1399/1308.Running%20Total%20for%20Different%20Genders/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1308](https://leetcode.com/problems/running-total-for-different-genders)", "[Running Total for Different Genders](/solution/1300-1399/1308.Running%20Total%20for%20Different%20Genders/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1438", "frontend_question_id": "1303", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/find-the-team-size", "url_en": "https://leetcode.com/problems/find-the-team-size", "relative_path_cn": "/solution/1300-1399/1303.Find%20the%20Team%20Size/README.md", "relative_path_en": "/solution/1300-1399/1303.Find%20the%20Team%20Size/README_EN.md", "title_cn": "\u6c42\u56e2\u961f\u4eba\u6570", "title_en": "Find the Team Size", "question_title_slug": "find-the-team-size", "content_en": "

Table: Employee

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| employee_id   | int     |\n| team_id       | int     |\n+---------------+---------+\nemployee_id is the primary key for this table.\nEach row of this table contains the ID of each employee and their respective team.\n
\n\n

Write an SQL query to find the team size of each of the employees.

\n\n

Return result table in any order.

\n\n

The query result format is in the following example:

\n\n
\nEmployee Table:\n+-------------+------------+\n| employee_id | team_id    |\n+-------------+------------+\n|     1       |     8      |\n|     2       |     8      |\n|     3       |     8      |\n|     4       |     7      |\n|     5       |     9      |\n|     6       |     9      |\n+-------------+------------+\nResult table:\n+-------------+------------+\n| employee_id | team_size  |\n+-------------+------------+\n|     1       |     3      |\n|     2       |     3      |\n|     3       |     3      |\n|     4       |     1      |\n|     5       |     2      |\n|     6       |     2      |\n+-------------+------------+\nEmployees with Id 1,2,3 are part of a team with team_id = 8.\nEmployees with Id 4 is part of a team with team_id = 7.\nEmployees with Id 5,6 are part of a team with team_id = 9.\n\n
\n", "content_cn": "

\u5458\u5de5\u8868\uff1aEmployee

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| employee_id   | int     |\n| team_id       | int     |\n+---------------+---------+\nemployee_id \u5b57\u6bb5\u662f\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\uff0c\u8868\u4e2d\u7684\u6bcf\u4e00\u884c\u90fd\u5305\u542b\u6bcf\u4e2a\u5458\u5de5\u7684 ID \u548c\u4ed6\u4eec\u6240\u5c5e\u7684\u56e2\u961f\u3002\n
\n\n

\u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\uff0c\u4ee5\u6c42\u5f97\u6bcf\u4e2a\u5458\u5de5\u6240\u5728\u56e2\u961f\u7684\u603b\u4eba\u6570\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u4e2d\u7684\u987a\u5e8f\u65e0\u7279\u5b9a\u8981\u6c42\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u793a\u4f8b\u5982\u4e0b\uff1a

\n\n
\nEmployee Table:\n+-------------+------------+\n| employee_id | team_id    |\n+-------------+------------+\n|     1       |     8      |\n|     2       |     8      |\n|     3       |     8      |\n|     4       |     7      |\n|     5       |     9      |\n|     6       |     9      |\n+-------------+------------+\nResult table:\n+-------------+------------+\n| employee_id | team_size  |\n+-------------+------------+\n|     1       |     3      |\n|     2       |     3      |\n|     3       |     3      |\n|     4       |     1      |\n|     5       |     2      |\n|     6       |     2      |\n+-------------+------------+\nID \u4e3a 1\u30012\u30013 \u7684\u5458\u5de5\u662f team_id \u4e3a 8 \u7684\u56e2\u961f\u7684\u6210\u5458\uff0c\nID \u4e3a 4 \u7684\u5458\u5de5\u662f team_id \u4e3a 7 \u7684\u56e2\u961f\u7684\u6210\u5458\uff0c\nID \u4e3a 5\u30016 \u7684\u5458\u5de5\u662f team_id \u4e3a 9 \u7684\u56e2\u961f\u7684\u6210\u5458\u3002\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1303](https://leetcode-cn.com/problems/find-the-team-size)", "[\u6c42\u56e2\u961f\u4eba\u6570](/solution/1300-1399/1303.Find%20the%20Team%20Size/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1303](https://leetcode.com/problems/find-the-team-size)", "[Find the Team Size](/solution/1300-1399/1303.Find%20the%20Team%20Size/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1437", "frontend_question_id": "1312", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-insertion-steps-to-make-a-string-palindrome", "url_en": "https://leetcode.com/problems/minimum-insertion-steps-to-make-a-string-palindrome", "relative_path_cn": "/solution/1300-1399/1312.Minimum%20Insertion%20Steps%20to%20Make%20a%20String%20Palindrome/README.md", "relative_path_en": "/solution/1300-1399/1312.Minimum%20Insertion%20Steps%20to%20Make%20a%20String%20Palindrome/README_EN.md", "title_cn": "\u8ba9\u5b57\u7b26\u4e32\u6210\u4e3a\u56de\u6587\u4e32\u7684\u6700\u5c11\u63d2\u5165\u6b21\u6570", "title_en": "Minimum Insertion Steps to Make a String Palindrome", "question_title_slug": "minimum-insertion-steps-to-make-a-string-palindrome", "content_en": "

Given a string s. In one step you can insert any character at any index of the string.

\n\n

Return the minimum number of steps to make s palindrome.

\n\n

Palindrome String is one that reads the same backward as well as forward.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "zzazz"\nOutput: 0\nExplanation: The string "zzazz" is already palindrome we don't need any insertions.\n
\n\n

Example 2:

\n\n
\nInput: s = "mbadm"\nOutput: 2\nExplanation: String can be "mbdadbm" or "mdbabdm".\n
\n\n

Example 3:

\n\n
\nInput: s = "leetcode"\nOutput: 5\nExplanation: Inserting 5 characters the string becomes "leetcodocteel".\n
\n\n

Example 4:

\n\n
\nInput: s = "g"\nOutput: 0\n
\n\n

Example 5:

\n\n
\nInput: s = "no"\nOutput: 1\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 500
  • \n\t
  • All characters of s are lower case English letters.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \uff0c\u6bcf\u4e00\u6b21\u64cd\u4f5c\u4f60\u90fd\u53ef\u4ee5\u5728\u5b57\u7b26\u4e32\u7684\u4efb\u610f\u4f4d\u7f6e\u63d2\u5165\u4efb\u610f\u5b57\u7b26\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u8ba9 s \u6210\u4e3a\u56de\u6587\u4e32\u7684 \u6700\u5c11\u64cd\u4f5c\u6b21\u6570 \u3002

\n\n

\u300c\u56de\u6587\u4e32\u300d\u662f\u6b63\u8bfb\u548c\u53cd\u8bfb\u90fd\u76f8\u540c\u7684\u5b57\u7b26\u4e32\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1as = "zzazz"\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u5b57\u7b26\u4e32 "zzazz" \u5df2\u7ecf\u662f\u56de\u6587\u4e32\u4e86\uff0c\u6240\u4ee5\u4e0d\u9700\u8981\u505a\u4efb\u4f55\u63d2\u5165\u64cd\u4f5c\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1as = "mbadm"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5b57\u7b26\u4e32\u53ef\u53d8\u4e3a "mbdadbm" \u6216\u8005 "mdbabdm" \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1as = "leetcode"\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u63d2\u5165 5 \u4e2a\u5b57\u7b26\u540e\u5b57\u7b26\u4e32\u53d8\u4e3a "leetcodocteel" \u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1as = "g"\n\u8f93\u51fa\uff1a0\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\n\u8f93\u5165\uff1as = "no"\n\u8f93\u51fa\uff1a1\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length <= 500
  • \n\t
  • s \u4e2d\u6240\u6709\u5b57\u7b26\u90fd\u662f\u5c0f\u5199\u5b57\u6bcd\u3002
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minInsertions(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minInsertions(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minInsertions(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minInsertions(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minInsertions(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinInsertions(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar minInsertions = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef min_insertions(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minInsertions(_ s: String) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minInsertions(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minInsertions(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minInsertions(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_insertions(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function minInsertions($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minInsertions(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-insertions s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1312](https://leetcode-cn.com/problems/minimum-insertion-steps-to-make-a-string-palindrome)", "[\u8ba9\u5b57\u7b26\u4e32\u6210\u4e3a\u56de\u6587\u4e32\u7684\u6700\u5c11\u63d2\u5165\u6b21\u6570](/solution/1300-1399/1312.Minimum%20Insertion%20Steps%20to%20Make%20a%20String%20Palindrome/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1312](https://leetcode.com/problems/minimum-insertion-steps-to-make-a-string-palindrome)", "[Minimum Insertion Steps to Make a String Palindrome](/solution/1300-1399/1312.Minimum%20Insertion%20Steps%20to%20Make%20a%20String%20Palindrome/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1436", "frontend_question_id": "1311", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/get-watched-videos-by-your-friends", "url_en": "https://leetcode.com/problems/get-watched-videos-by-your-friends", "relative_path_cn": "/solution/1300-1399/1311.Get%20Watched%20Videos%20by%20Your%20Friends/README.md", "relative_path_en": "/solution/1300-1399/1311.Get%20Watched%20Videos%20by%20Your%20Friends/README_EN.md", "title_cn": "\u83b7\u53d6\u4f60\u597d\u53cb\u5df2\u89c2\u770b\u7684\u89c6\u9891", "title_en": "Get Watched Videos by Your Friends", "question_title_slug": "get-watched-videos-by-your-friends", "content_en": "

There are n people, each person has a unique id between 0 and n-1. Given the arrays watchedVideos and friends, where watchedVideos[i] and friends[i] contain the list of watched videos and the list of friends respectively for the person with id = i.

\n\n

Level 1 of videos are all watched videos by your friends, level 2 of videos are all watched videos by the friends of your friends and so on. In general, the level k of videos are all watched videos by people with the shortest path exactly equal to k with you. Given your id and the level of videos, return the list of videos ordered by their frequencies (increasing). For videos with the same frequency order them alphabetically from least to greatest. 

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: watchedVideos = [["A","B"],["C"],["B","C"],["D"]], friends = [[1,2],[0,3],[0,3],[1,2]], id = 0, level = 1\nOutput: ["B","C"] \nExplanation: \nYou have id = 0 (green color in the figure) and your friends are (yellow color in the figure):\nPerson with id = 1 -> watchedVideos = ["C"] \nPerson with id = 2 -> watchedVideos = ["B","C"] \nThe frequencies of watchedVideos by your friends are: \nB -> 1 \nC -> 2\n
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: watchedVideos = [["A","B"],["C"],["B","C"],["D"]], friends = [[1,2],[0,3],[0,3],[1,2]], id = 0, level = 2\nOutput: ["D"]\nExplanation: \nYou have id = 0 (green color in the figure) and the only friend of your friends is the person with id = 3 (yellow color in the figure).\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == watchedVideos.length == friends.length
  • \n\t
  • 2 <= n <= 100
  • \n\t
  • 1 <= watchedVideos[i].length <= 100
  • \n\t
  • 1 <= watchedVideos[i][j].length <= 8
  • \n\t
  • 0 <= friends[i].length < n
  • \n\t
  • 0 <= friends[i][j] < n
  • \n\t
  • 0 <= id < n
  • \n\t
  • 1 <= level < n
  • \n\t
  • if friends[i] contains j, then friends[j] contains i
  • \n
\n", "content_cn": "

\u6709 n \u4e2a\u4eba\uff0c\u6bcf\u4e2a\u4eba\u90fd\u6709\u4e00\u4e2a  0 \u5230 n-1 \u7684\u552f\u4e00 id \u3002

\n\n

\u7ed9\u4f60\u6570\u7ec4 watchedVideos  \u548c friends \uff0c\u5176\u4e2d watchedVideos[i]  \u548c friends[i] \u5206\u522b\u8868\u793a id = i \u7684\u4eba\u89c2\u770b\u8fc7\u7684\u89c6\u9891\u5217\u8868\u548c\u4ed6\u7684\u597d\u53cb\u5217\u8868\u3002

\n\n

Level 1 \u7684\u89c6\u9891\u5305\u542b\u6240\u6709\u4f60\u597d\u53cb\u89c2\u770b\u8fc7\u7684\u89c6\u9891\uff0clevel 2 \u7684\u89c6\u9891\u5305\u542b\u6240\u6709\u4f60\u597d\u53cb\u7684\u597d\u53cb\u89c2\u770b\u8fc7\u7684\u89c6\u9891\uff0c\u4ee5\u6b64\u7c7b\u63a8\u3002\u4e00\u822c\u7684\uff0cLevel \u4e3a k \u7684\u89c6\u9891\u5305\u542b\u6240\u6709\u4ece\u4f60\u51fa\u53d1\uff0c\u6700\u77ed\u8ddd\u79bb\u4e3a k \u7684\u597d\u53cb\u89c2\u770b\u8fc7\u7684\u89c6\u9891\u3002

\n\n

\u7ed9\u5b9a\u4f60\u7684 id  \u548c\u4e00\u4e2a level \u503c\uff0c\u8bf7\u4f60\u627e\u51fa\u6240\u6709\u6307\u5b9a level \u7684\u89c6\u9891\uff0c\u5e76\u5c06\u5b83\u4eec\u6309\u89c2\u770b\u9891\u7387\u5347\u5e8f\u8fd4\u56de\u3002\u5982\u679c\u6709\u9891\u7387\u76f8\u540c\u7684\u89c6\u9891\uff0c\u8bf7\u5c06\u5b83\u4eec\u6309\u5b57\u6bcd\u987a\u5e8f\u4ece\u5c0f\u5230\u5927\u6392\u5217\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1awatchedVideos = [["A","B"],["C"],["B","C"],["D"]], friends = [[1,2],[0,3],[0,3],[1,2]], id = 0, level = 1\n\u8f93\u51fa\uff1a["B","C"] \n\u89e3\u91ca\uff1a\n\u4f60\u7684 id \u4e3a 0\uff08\u7eff\u8272\uff09\uff0c\u4f60\u7684\u670b\u53cb\u5305\u62ec\uff08\u9ec4\u8272\uff09\uff1a\nid \u4e3a 1 -> watchedVideos = ["C"] \nid \u4e3a 2 -> watchedVideos = ["B","C"] \n\u4f60\u670b\u53cb\u89c2\u770b\u8fc7\u89c6\u9891\u7684\u9891\u7387\u4e3a\uff1a\nB -> 1 \nC -> 2\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1awatchedVideos = [["A","B"],["C"],["B","C"],["D"]], friends = [[1,2],[0,3],[0,3],[1,2]], id = 0, level = 2\n\u8f93\u51fa\uff1a["D"]\n\u89e3\u91ca\uff1a\n\u4f60\u7684 id \u4e3a 0\uff08\u7eff\u8272\uff09\uff0c\u4f60\u670b\u53cb\u7684\u670b\u53cb\u53ea\u6709\u4e00\u4e2a\u4eba\uff0c\u4ed6\u7684 id \u4e3a 3\uff08\u9ec4\u8272\uff09\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • n == watchedVideos.length == friends.length
  • \n\t
  • 2 <= n <= 100
  • \n\t
  • 1 <= watchedVideos[i].length <= 100
  • \n\t
  • 1 <= watchedVideos[i][j].length <= 8
  • \n\t
  • 0 <= friends[i].length < n
  • \n\t
  • 0 <= friends[i][j] < n
  • \n\t
  • 0 <= id < n
  • \n\t
  • 1 <= level < n
  • \n\t
  • \u5982\u679c friends[i] \u5305\u542b j \uff0c\u90a3\u4e48 friends[j] \u5305\u542b i
  • \n
\n", "tags_en": ["Breadth-first Search", "Hash Table", "String"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u54c8\u5e0c\u8868", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector watchedVideosByFriends(vector>& watchedVideos, vector>& friends, int id, int level) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List watchedVideosByFriends(List> watchedVideos, int[][] friends, int id, int level) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def watchedVideosByFriends(self, watchedVideos, friends, id, level):\n \"\"\"\n :type watchedVideos: List[List[str]]\n :type friends: List[List[int]]\n :type id: int\n :type level: int\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def watchedVideosByFriends(self, watchedVideos: List[List[str]], friends: List[List[int]], id: int, level: int) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** watchedVideosByFriends(char *** watchedVideos, int watchedVideosSize, int* watchedVideosColSize, int** friends, int friendsSize, int* friendsColSize, int id, int level, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList WatchedVideosByFriends(IList> watchedVideos, int[][] friends, int id, int level) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[][]} watchedVideos\n * @param {number[][]} friends\n * @param {number} id\n * @param {number} level\n * @return {string[]}\n */\nvar watchedVideosByFriends = function(watchedVideos, friends, id, level) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[][]} watched_videos\n# @param {Integer[][]} friends\n# @param {Integer} id\n# @param {Integer} level\n# @return {String[]}\ndef watched_videos_by_friends(watched_videos, friends, id, level)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func watchedVideosByFriends(_ watchedVideos: [[String]], _ friends: [[Int]], _ id: Int, _ level: Int) -> [String] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func watchedVideosByFriends(watchedVideos [][]string, friends [][]int, id int, level int) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def watchedVideosByFriends(watchedVideos: List[List[String]], friends: Array[Array[Int]], id: Int, level: Int): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun watchedVideosByFriends(watchedVideos: List>, friends: Array, id: Int, level: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn watched_videos_by_friends(watched_videos: Vec>, friends: Vec>, id: i32, level: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $watchedVideos\n * @param Integer[][] $friends\n * @param Integer $id\n * @param Integer $level\n * @return String[]\n */\n function watchedVideosByFriends($watchedVideos, $friends, $id, $level) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function watchedVideosByFriends(watchedVideos: string[][], friends: number[][], id: number, level: number): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (watched-videos-by-friends watchedVideos friends id level)\n (-> (listof (listof string?)) (listof (listof exact-integer?)) exact-integer? exact-integer? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1311](https://leetcode-cn.com/problems/get-watched-videos-by-your-friends)", "[\u83b7\u53d6\u4f60\u597d\u53cb\u5df2\u89c2\u770b\u7684\u89c6\u9891](/solution/1300-1399/1311.Get%20Watched%20Videos%20by%20Your%20Friends/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u54c8\u5e0c\u8868`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1311](https://leetcode.com/problems/get-watched-videos-by-your-friends)", "[Get Watched Videos by Your Friends](/solution/1300-1399/1311.Get%20Watched%20Videos%20by%20Your%20Friends/README_EN.md)", "`Breadth-first Search`,`Hash Table`,`String`", "Medium", ""]}, {"question_id": "1435", "frontend_question_id": "1310", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/xor-queries-of-a-subarray", "url_en": "https://leetcode.com/problems/xor-queries-of-a-subarray", "relative_path_cn": "/solution/1300-1399/1310.XOR%20Queries%20of%20a%20Subarray/README.md", "relative_path_en": "/solution/1300-1399/1310.XOR%20Queries%20of%20a%20Subarray/README_EN.md", "title_cn": "\u5b50\u6570\u7ec4\u5f02\u6216\u67e5\u8be2", "title_en": "XOR Queries of a Subarray", "question_title_slug": "xor-queries-of-a-subarray", "content_en": "Given the array arr of positive integers and the array queries where queries[i] = [Li, Ri], for each query i compute the XOR of elements from Li to Ri (that is, arr[Li] xor arr[Li+1] xor ... xor arr[Ri] ). Return an array containing the result for the given queries.\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: arr = [1,3,4,8], queries = [[0,1],[1,2],[0,3],[3,3]]\r\nOutput: [2,7,14,8] \r\nExplanation: \r\nThe binary representation of the elements in the array are:\r\n1 = 0001 \r\n3 = 0011 \r\n4 = 0100 \r\n8 = 1000 \r\nThe XOR values for queries are:\r\n[0,1] = 1 xor 3 = 2 \r\n[1,2] = 3 xor 4 = 7 \r\n[0,3] = 1 xor 3 xor 4 xor 8 = 14 \r\n[3,3] = 8\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: arr = [4,8,2,10], queries = [[2,3],[1,3],[0,0],[0,3]]\r\nOutput: [8,0,4,4]\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= arr.length <= 3 * 10^4
  • \r\n\t
  • 1 <= arr[i] <= 10^9
  • \r\n\t
  • 1 <= queries.length <= 3 * 10^4
  • \r\n\t
  • queries[i].length == 2
  • \r\n\t
  • 0 <= queries[i][0] <= queries[i][1] < arr.length
  • \r\n
", "content_cn": "

\u6709\u4e00\u4e2a\u6b63\u6574\u6570\u6570\u7ec4\u00a0arr\uff0c\u73b0\u7ed9\u4f60\u4e00\u4e2a\u5bf9\u5e94\u7684\u67e5\u8be2\u6570\u7ec4\u00a0queries\uff0c\u5176\u4e2d\u00a0queries[i] = [Li,\u00a0Ri]\u3002

\n\n

\u5bf9\u4e8e\u6bcf\u4e2a\u67e5\u8be2\u00a0i\uff0c\u8bf7\u4f60\u8ba1\u7b97\u4ece\u00a0Li\u00a0\u5230\u00a0Ri\u00a0\u7684\u00a0XOR\u00a0\u503c\uff08\u5373\u00a0arr[Li] xor arr[Li+1] xor ... xor arr[Ri]\uff09\u4f5c\u4e3a\u672c\u6b21\u67e5\u8be2\u7684\u7ed3\u679c\u3002

\n\n

\u5e76\u8fd4\u56de\u4e00\u4e2a\u5305\u542b\u7ed9\u5b9a\u67e5\u8be2\u00a0queries\u00a0\u6240\u6709\u7ed3\u679c\u7684\u6570\u7ec4\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [1,3,4,8], queries = [[0,1],[1,2],[0,3],[3,3]]\n\u8f93\u51fa\uff1a[2,7,14,8] \n\u89e3\u91ca\uff1a\n\u6570\u7ec4\u4e2d\u5143\u7d20\u7684\u4e8c\u8fdb\u5236\u8868\u793a\u5f62\u5f0f\u662f\uff1a\n1 = 0001 \n3 = 0011 \n4 = 0100 \n8 = 1000 \n\u67e5\u8be2\u7684 XOR \u503c\u4e3a\uff1a\n[0,1] = 1 xor 3 = 2 \n[1,2] = 3 xor 4 = 7 \n[0,3] = 1 xor 3 xor 4 xor 8 = 14 \n[3,3] = 8\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [4,8,2,10], queries = [[2,3],[1,3],[0,0],[0,3]]\n\u8f93\u51fa\uff1a[8,0,4,4]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= arr.length <= 3 *\u00a010^4
  • \n\t
  • 1 <= arr[i] <= 10^9
  • \n\t
  • 1 <= queries.length <= 3 * 10^4
  • \n\t
  • queries[i].length == 2
  • \n\t
  • 0 <= queries[i][0] <= queries[i][1] < arr.length
  • \n
\n", "tags_en": ["Bit Manipulation"], "tags_cn": ["\u4f4d\u8fd0\u7b97"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector xorQueries(vector& arr, vector>& queries) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] xorQueries(int[] arr, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def xorQueries(self, arr, queries):\n \"\"\"\n :type arr: List[int]\n :type queries: List[List[int]]\n :rtype: List[int]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* xorQueries(int* arr, int arrSize, int** queries, int queriesSize, int* queriesColSize, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] XorQueries(int[] arr, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @param {number[][]} queries\n * @return {number[]}\n */\nvar xorQueries = function(arr, queries) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @param {Integer[][]} queries\n# @return {Integer[]}\ndef xor_queries(arr, queries)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func xorQueries(_ arr: [Int], _ queries: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func xorQueries(arr []int, queries [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def xorQueries(arr: Array[Int], queries: Array[Array[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun xorQueries(arr: IntArray, queries: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn xor_queries(arr: Vec, queries: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @param Integer[][] $queries\n * @return Integer[]\n */\n function xorQueries($arr, $queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function xorQueries(arr: number[], queries: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (xor-queries arr queries)\n (-> (listof exact-integer?) (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1310](https://leetcode-cn.com/problems/xor-queries-of-a-subarray)", "[\u5b50\u6570\u7ec4\u5f02\u6216\u67e5\u8be2](/solution/1300-1399/1310.XOR%20Queries%20of%20a%20Subarray/README.md)", "`\u4f4d\u8fd0\u7b97`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1310](https://leetcode.com/problems/xor-queries-of-a-subarray)", "[XOR Queries of a Subarray](/solution/1300-1399/1310.XOR%20Queries%20of%20a%20Subarray/README_EN.md)", "`Bit Manipulation`", "Medium", ""]}, {"question_id": "1434", "frontend_question_id": "1309", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/decrypt-string-from-alphabet-to-integer-mapping", "url_en": "https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping", "relative_path_cn": "/solution/1300-1399/1309.Decrypt%20String%20from%20Alphabet%20to%20Integer%20Mapping/README.md", "relative_path_en": "/solution/1300-1399/1309.Decrypt%20String%20from%20Alphabet%20to%20Integer%20Mapping/README_EN.md", "title_cn": "\u89e3\u7801\u5b57\u6bcd\u5230\u6574\u6570\u6620\u5c04", "title_en": "Decrypt String from Alphabet to Integer Mapping", "question_title_slug": "decrypt-string-from-alphabet-to-integer-mapping", "content_en": "

Given a string s formed by digits ('0' - '9') and '#' . We want to map s to English lowercase characters as follows:

\n\n
    \n\t
  • Characters ('a' to 'i') are represented by ('1' to '9') respectively.
  • \n\t
  • Characters ('j' to 'z') are represented by ('10#' to '26#') respectively. 
  • \n
\n\n

Return the string formed after mapping.

\n\n

It's guaranteed that a unique mapping will always exist.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "10#11#12"\nOutput: "jkab"\nExplanation: "j" -> "10#" , "k" -> "11#" , "a" -> "1" , "b" -> "2".\n
\n\n

Example 2:

\n\n
\nInput: s = "1326#"\nOutput: "acz"\n
\n\n

Example 3:

\n\n
\nInput: s = "25#"\nOutput: "y"\n
\n\n

Example 4:

\n\n
\nInput: s = "12345678910#11#12#13#14#15#16#17#18#19#20#21#22#23#24#25#26#"\nOutput: "abcdefghijklmnopqrstuvwxyz"\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 1000
  • \n\t
  • s[i] only contains digits letters ('0'-'9') and '#' letter.
  • \n\t
  • s will be valid string such that mapping is always possible.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s\uff0c\u5b83\u7531\u6570\u5b57\uff08'0' - '9'\uff09\u548c '#' \u7ec4\u6210\u3002\u6211\u4eec\u5e0c\u671b\u6309\u4e0b\u8ff0\u89c4\u5219\u5c06 s \u6620\u5c04\u4e3a\u4e00\u4e9b\u5c0f\u5199\u82f1\u6587\u5b57\u7b26\uff1a

\n\n
    \n\t
  • \u5b57\u7b26\uff08'a' - 'i'\uff09\u5206\u522b\u7528\uff08'1''9'\uff09\u8868\u793a\u3002
  • \n\t
  • \u5b57\u7b26\uff08'j' - 'z'\uff09\u5206\u522b\u7528\uff08'10#' - '26#'\uff09\u8868\u793a\u3002 
  • \n
\n\n

\u8fd4\u56de\u6620\u5c04\u4e4b\u540e\u5f62\u6210\u7684\u65b0\u5b57\u7b26\u4e32\u3002

\n\n

\u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u6620\u5c04\u59cb\u7ec8\u552f\u4e00\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1as = "10#11#12"\n\u8f93\u51fa\uff1a"jkab"\n\u89e3\u91ca\uff1a"j" -> "10#" , "k" -> "11#" , "a" -> "1" , "b" -> "2".\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1as = "1326#"\n\u8f93\u51fa\uff1a"acz"\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1as = "25#"\n\u8f93\u51fa\uff1a"y"\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1as = "12345678910#11#12#13#14#15#16#17#18#19#20#21#22#23#24#25#26#"\n\u8f93\u51fa\uff1a"abcdefghijklmnopqrstuvwxyz"\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length <= 1000
  • \n\t
  • s[i] \u53ea\u5305\u542b\u6570\u5b57\uff08'0'-'9'\uff09\u548c '#' \u5b57\u7b26\u3002
  • \n\t
  • s \u662f\u6620\u5c04\u59cb\u7ec8\u5b58\u5728\u7684\u6709\u6548\u5b57\u7b26\u4e32\u3002
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string freqAlphabets(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String freqAlphabets(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def freqAlphabets(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def freqAlphabets(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * freqAlphabets(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string FreqAlphabets(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar freqAlphabets = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef freq_alphabets(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func freqAlphabets(_ s: String) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func freqAlphabets(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def freqAlphabets(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun freqAlphabets(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn freq_alphabets(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function freqAlphabets($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function freqAlphabets(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (freq-alphabets s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1309](https://leetcode-cn.com/problems/decrypt-string-from-alphabet-to-integer-mapping)", "[\u89e3\u7801\u5b57\u6bcd\u5230\u6574\u6570\u6620\u5c04](/solution/1300-1399/1309.Decrypt%20String%20from%20Alphabet%20to%20Integer%20Mapping/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1309](https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping)", "[Decrypt String from Alphabet to Integer Mapping](/solution/1300-1399/1309.Decrypt%20String%20from%20Alphabet%20to%20Integer%20Mapping/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1432", "frontend_question_id": "1430", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/check-if-a-string-is-a-valid-sequence-from-root-to-leaves-path-in-a-binary-tree", "url_en": "https://leetcode.com/problems/check-if-a-string-is-a-valid-sequence-from-root-to-leaves-path-in-a-binary-tree", "relative_path_cn": "/solution/1400-1499/1430.Check%20If%20a%20String%20Is%20a%20Valid%20Sequence%20from%20Root%20to%20Leaves%20Path%20in%20a%20Binary%20Tree/README.md", "relative_path_en": "/solution/1400-1499/1430.Check%20If%20a%20String%20Is%20a%20Valid%20Sequence%20from%20Root%20to%20Leaves%20Path%20in%20a%20Binary%20Tree/README_EN.md", "title_cn": "\u5224\u65ad\u7ed9\u5b9a\u7684\u5e8f\u5217\u662f\u5426\u662f\u4e8c\u53c9\u6811\u4ece\u6839\u5230\u53f6\u7684\u8def\u5f84", "title_en": "Check If a String Is a Valid Sequence from Root to Leaves Path in a Binary Tree", "question_title_slug": "check-if-a-string-is-a-valid-sequence-from-root-to-leaves-path-in-a-binary-tree", "content_en": "

Given a binary tree where each path going from the root to any leaf form a valid sequence, check if a given string is a valid sequence in such binary tree. 

\n\n

We get the given string from the concatenation of an array of integers arr and the concatenation of all values of the nodes along a path results in a sequence in the given binary tree.

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: root = [0,1,0,0,1,0,null,null,1,0,0], arr = [0,1,0,1]\nOutput: true\nExplanation: \nThe path 0 -> 1 -> 0 -> 1 is a valid sequence (green color in the figure). \nOther valid sequences are: \n0 -> 1 -> 1 -> 0 \n0 -> 0 -> 0\n
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: root = [0,1,0,0,1,0,null,null,1,0,0], arr = [0,0,1]\nOutput: false \nExplanation: The path 0 -> 0 -> 1 does not exist, therefore it is not even a sequence.\n
\n\n

Example 3:

\n\n

\"\"

\n\n
\nInput: root = [0,1,0,0,1,0,null,null,1,0,0], arr = [0,1,1]\nOutput: false\nExplanation: The path 0 -> 1 -> 1 is a sequence, but it is not a valid sequence.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= arr.length <= 5000
  • \n\t
  • 0 <= arr[i] <= 9
  • \n\t
  • Each node's value is between [0 - 9].
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811\uff0c\u6211\u4eec\u79f0\u4ece\u6839\u8282\u70b9\u5230\u4efb\u610f\u53f6\u8282\u70b9\u7684\u4efb\u610f\u8def\u5f84\u4e2d\u7684\u8282\u70b9\u503c\u6240\u6784\u6210\u7684\u5e8f\u5217\u4e3a\u8be5\u4e8c\u53c9\u6811\u7684\u4e00\u4e2a “\u6709\u6548\u5e8f\u5217” \u3002\u68c0\u67e5\u4e00\u4e2a\u7ed9\u5b9a\u7684\u5e8f\u5217\u662f\u5426\u662f\u7ed9\u5b9a\u4e8c\u53c9\u6811\u7684\u4e00\u4e2a “\u6709\u6548\u5e8f\u5217” \u3002

\n\n

\u6211\u4eec\u4ee5\u6574\u6570\u6570\u7ec4 arr \u7684\u5f62\u5f0f\u7ed9\u51fa\u8fd9\u4e2a\u5e8f\u5217\u3002\u4ece\u6839\u8282\u70b9\u5230\u4efb\u610f\u53f6\u8282\u70b9\u7684\u4efb\u610f\u8def\u5f84\u4e2d\u7684\u8282\u70b9\u503c\u6240\u6784\u6210\u7684\u5e8f\u5217\u90fd\u662f\u8fd9\u4e2a\u4e8c\u53c9\u6811\u7684 “\u6709\u6548\u5e8f\u5217” \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1aroot = [0,1,0,0,1,0,null,null,1,0,0], arr = [0,1,0,1]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\n\u8def\u5f84 0 -> 1 -> 0 -> 1 \u662f\u4e00\u4e2a“\u6709\u6548\u5e8f\u5217”\uff08\u56fe\u4e2d\u7684\u7eff\u8272\u8282\u70b9\uff09\u3002\n\u5176\u4ed6\u7684“\u6709\u6548\u5e8f\u5217”\u662f\uff1a\n0 -> 1 -> 1 -> 0 \n0 -> 0 -> 0\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1aroot = [0,1,0,0,1,0,null,null,1,0,0], arr = [0,0,1]\n\u8f93\u51fa\uff1afalse \n\u89e3\u91ca\uff1a\u8def\u5f84 0 -> 0 -> 1 \u4e0d\u5b58\u5728\uff0c\u6240\u4ee5\u8fd9\u4e0d\u662f\u4e00\u4e2a“\u5e8f\u5217”\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1aroot = [0,1,0,0,1,0,null,null,1,0,0], arr = [0,1,1]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u8def\u5f84 0 -> 1 -> 1 \u662f\u4e00\u4e2a\u5e8f\u5217\uff0c\u4f46\u4e0d\u662f\u4e00\u4e2a“\u6709\u6548\u5e8f\u5217”\uff08\u8bd1\u8005\u6ce8\uff1a\u56e0\u4e3a\u5e8f\u5217\u7684\u7ec8\u70b9\u4e0d\u662f\u53f6\u8282\u70b9\uff09\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= arr.length <= 5000
  • \n\t
  • 0 <= arr[i] <= 9
  • \n\t
  • \u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u7684\u53d6\u503c\u8303\u56f4\u662f [0 - 9]
  • \n
\n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n bool isValidSequence(TreeNode* root, vector& arr) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public boolean isValidSequence(TreeNode root, int[] arr) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def isValidSequence(self, root, arr):\n \"\"\"\n :type root: TreeNode\n :type arr: List[int]\n :rtype: bool\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def isValidSequence(self, root: TreeNode, arr: List[int]) -> bool:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nbool isValidSequence(struct TreeNode* root, int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public bool IsValidSequence(TreeNode root, int[] arr) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number[]} arr\n * @return {boolean}\n */\nvar isValidSequence = function(root, arr) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @param {Integer[]} arr\n# @return {Boolean}\ndef is_valid_sequence(root, arr)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func isValidSequence(_ root: TreeNode?, _ arr: [Int]) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc isValidSequence(root *TreeNode, arr []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def isValidSequence(root: TreeNode, arr: Array[Int]): Boolean = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun isValidSequence(root: TreeNode?, arr: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn is_valid_sequence(root: Option>>, arr: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param Integer[] $arr\n * @return Boolean\n */\n function isValidSequence($root, $arr) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction isValidSequence(root: TreeNode | null, arr: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (is-valid-sequence root arr)\n (-> (or/c tree-node? #f) (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1430](https://leetcode-cn.com/problems/check-if-a-string-is-a-valid-sequence-from-root-to-leaves-path-in-a-binary-tree)", "[\u5224\u65ad\u7ed9\u5b9a\u7684\u5e8f\u5217\u662f\u5426\u662f\u4e8c\u53c9\u6811\u4ece\u6839\u5230\u53f6\u7684\u8def\u5f84](/solution/1400-1499/1430.Check%20If%20a%20String%20Is%20a%20Valid%20Sequence%20from%20Root%20to%20Leaves%20Path%20in%20a%20Binary%20Tree/README.md)", "`\u6811`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1430](https://leetcode.com/problems/check-if-a-string-is-a-valid-sequence-from-root-to-leaves-path-in-a-binary-tree)", "[Check If a String Is a Valid Sequence from Root to Leaves Path in a Binary Tree](/solution/1400-1499/1430.Check%20If%20a%20String%20Is%20a%20Valid%20Sequence%20from%20Root%20to%20Leaves%20Path%20in%20a%20Binary%20Tree/README_EN.md)", "`Tree`", "Medium", "\ud83d\udd12"]}, {"question_id": "1429", "frontend_question_id": "1307", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/verbal-arithmetic-puzzle", "url_en": "https://leetcode.com/problems/verbal-arithmetic-puzzle", "relative_path_cn": "/solution/1300-1399/1307.Verbal%20Arithmetic%20Puzzle/README.md", "relative_path_en": "/solution/1300-1399/1307.Verbal%20Arithmetic%20Puzzle/README_EN.md", "title_cn": "\u53e3\u7b97\u96be\u9898", "title_en": "Verbal Arithmetic Puzzle", "question_title_slug": "verbal-arithmetic-puzzle", "content_en": "

Given an equation, represented by words on left side and the result on right side.

\n\n

You need to check if the equation is solvable under the following rules:

\n\n
    \n\t
  • Each character is decoded as one digit (0 - 9).
  • \n\t
  • Every pair of different characters they must map to different digits.
  • \n\t
  • Each words[i] and result are decoded as one number without leading zeros.
  • \n\t
  • Sum of numbers on left side (words) will equal to the number on right side (result). 
  • \n
\n\n

Return True if the equation is solvable otherwise return False.

\n\n

 

\n

Example 1:

\n\n
\nInput: words = ["SEND","MORE"], result = "MONEY"\nOutput: true\nExplanation: Map 'S'-> 9, 'E'->5, 'N'->6, 'D'->7, 'M'->1, 'O'->0, 'R'->8, 'Y'->'2'\nSuch that: "SEND" + "MORE" = "MONEY" ,  9567 + 1085 = 10652
\n\n

Example 2:

\n\n
\nInput: words = ["SIX","SEVEN","SEVEN"], result = "TWENTY"\nOutput: true\nExplanation: Map 'S'-> 6, 'I'->5, 'X'->0, 'E'->8, 'V'->7, 'N'->2, 'T'->1, 'W'->'3', 'Y'->4\nSuch that: "SIX" + "SEVEN" + "SEVEN" = "TWENTY" ,  650 + 68782 + 68782 = 138214
\n\n

Example 3:

\n\n
\nInput: words = ["THIS","IS","TOO"], result = "FUNNY"\nOutput: true\n
\n\n

Example 4:

\n\n
\nInput: words = ["LEET","CODE"], result = "POINT"\nOutput: false\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= words.length <= 5
  • \n\t
  • 1 <= words[i].length, result.length <= 7
  • \n\t
  • words[i], result contain only uppercase English letters.
  • \n\t
  • The number of different characters used in the expression is at most 10.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u65b9\u7a0b\uff0c\u5de6\u8fb9\u7528 words \u8868\u793a\uff0c\u53f3\u8fb9\u7528 result \u8868\u793a\u3002

\n\n

\u4f60\u9700\u8981\u6839\u636e\u4ee5\u4e0b\u89c4\u5219\u68c0\u67e5\u65b9\u7a0b\u662f\u5426\u53ef\u89e3\uff1a

\n\n
    \n\t
  • \u6bcf\u4e2a\u5b57\u7b26\u90fd\u4f1a\u88ab\u89e3\u7801\u6210\u4e00\u4f4d\u6570\u5b57\uff080 - 9\uff09\u3002
  • \n\t
  • \u6bcf\u5bf9\u4e0d\u540c\u7684\u5b57\u7b26\u5fc5\u987b\u6620\u5c04\u5230\u4e0d\u540c\u7684\u6570\u5b57\u3002
  • \n\t
  • \u6bcf\u4e2a words[i] \u548c result \u90fd\u4f1a\u88ab\u89e3\u7801\u6210\u4e00\u4e2a\u6ca1\u6709\u524d\u5bfc\u96f6\u7684\u6570\u5b57\u3002
  • \n\t
  • \u5de6\u4fa7\u6570\u5b57\u4e4b\u548c\uff08words\uff09\u7b49\u4e8e\u53f3\u4fa7\u6570\u5b57\uff08result\uff09\u3002 
  • \n
\n\n

\u5982\u679c\u65b9\u7a0b\u53ef\u89e3\uff0c\u8fd4\u56de True\uff0c\u5426\u5219\u8fd4\u56de False\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1awords = ["SEND","MORE"], result = "MONEY"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u6620\u5c04 'S'-> 9, 'E'->5, 'N'->6, 'D'->7, 'M'->1, 'O'->0, 'R'->8, 'Y'->'2'\n\u6240\u4ee5 "SEND" + "MORE" = "MONEY" ,  9567 + 1085 = 10652
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1awords = ["SIX","SEVEN","SEVEN"], result = "TWENTY"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u6620\u5c04 'S'-> 6, 'I'->5, 'X'->0, 'E'->8, 'V'->7, 'N'->2, 'T'->1, 'W'->'3', 'Y'->4\n\u6240\u4ee5 "SIX" + "SEVEN" + "SEVEN" = "TWENTY" ,  650 + 68782 + 68782 = 138214
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1awords = ["THIS","IS","TOO"], result = "FUNNY"\n\u8f93\u51fa\uff1atrue\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1awords = ["LEET","CODE"], result = "POINT"\n\u8f93\u51fa\uff1afalse\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= words.length <= 5
  • \n\t
  • 1 <= words[i].length, results.length <= 7
  • \n\t
  • words[i], result \u53ea\u542b\u6709\u5927\u5199\u82f1\u6587\u5b57\u6bcd
  • \n\t
  • \u8868\u8fbe\u5f0f\u4e2d\u4f7f\u7528\u7684\u4e0d\u540c\u5b57\u7b26\u6570\u6700\u5927\u4e3a 10
  • \n
\n", "tags_en": ["Math", "Backtracking"], "tags_cn": ["\u6570\u5b66", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isSolvable(vector& words, string result) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isSolvable(String[] words, String result) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isSolvable(self, words, result):\n \"\"\"\n :type words: List[str]\n :type result: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isSolvable(self, words: List[str], result: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isSolvable(char ** words, int wordsSize, char * result){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsSolvable(string[] words, string result) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @param {string} result\n * @return {boolean}\n */\nvar isSolvable = function(words, result) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @param {String} result\n# @return {Boolean}\ndef is_solvable(words, result)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isSolvable(_ words: [String], _ result: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isSolvable(words []string, result string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isSolvable(words: Array[String], result: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isSolvable(words: Array, result: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_solvable(words: Vec, result: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @param String $result\n * @return Boolean\n */\n function isSolvable($words, $result) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isSolvable(words: string[], result: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-solvable words result)\n (-> (listof string?) string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1307](https://leetcode-cn.com/problems/verbal-arithmetic-puzzle)", "[\u53e3\u7b97\u96be\u9898](/solution/1300-1399/1307.Verbal%20Arithmetic%20Puzzle/README.md)", "`\u6570\u5b66`,`\u56de\u6eaf\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[1307](https://leetcode.com/problems/verbal-arithmetic-puzzle)", "[Verbal Arithmetic Puzzle](/solution/1300-1399/1307.Verbal%20Arithmetic%20Puzzle/README_EN.md)", "`Math`,`Backtracking`", "Hard", ""]}, {"question_id": "1428", "frontend_question_id": "1306", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/jump-game-iii", "url_en": "https://leetcode.com/problems/jump-game-iii", "relative_path_cn": "/solution/1300-1399/1306.Jump%20Game%20III/README.md", "relative_path_en": "/solution/1300-1399/1306.Jump%20Game%20III/README_EN.md", "title_cn": "\u8df3\u8dc3\u6e38\u620f III", "title_en": "Jump Game III", "question_title_slug": "jump-game-iii", "content_en": "

Given an array of non-negative integers arr, you are initially positioned at start index of the array. When you are at index i, you can jump to i + arr[i] or i - arr[i], check if you can reach to any index with value 0.

\n\n

Notice that you can not jump outside of the array at any time.

\n\n

 

\n

Example 1:

\n\n
\nInput: arr = [4,2,3,0,3,1,2], start = 5\nOutput: true\nExplanation: \nAll possible ways to reach at index 3 with value 0 are: \nindex 5 -> index 4 -> index 1 -> index 3 \nindex 5 -> index 6 -> index 4 -> index 1 -> index 3 \n
\n\n

Example 2:

\n\n
\nInput: arr = [4,2,3,0,3,1,2], start = 0\nOutput: true \nExplanation: \nOne possible way to reach at index 3 with value 0 is: \nindex 0 -> index 4 -> index 1 -> index 3\n
\n\n

Example 3:

\n\n
\nInput: arr = [3,0,2,1,2], start = 2\nOutput: false\nExplanation: There is no way to reach at index 1 with value 0.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= arr.length <= 5 * 104
  • \n\t
  • 0 <= arr[i] < arr.length
  • \n\t
  • 0 <= start < arr.length
  • \n
\n", "content_cn": "

\u8fd9\u91cc\u6709\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\u6570\u7ec4 arr\uff0c\u4f60\u6700\u5f00\u59cb\u4f4d\u4e8e\u8be5\u6570\u7ec4\u7684\u8d77\u59cb\u4e0b\u6807 start \u5904\u3002\u5f53\u4f60\u4f4d\u4e8e\u4e0b\u6807 i \u5904\u65f6\uff0c\u4f60\u53ef\u4ee5\u8df3\u5230 i + arr[i] \u6216\u8005 i - arr[i]\u3002

\n\n

\u8bf7\u4f60\u5224\u65ad\u81ea\u5df1\u662f\u5426\u80fd\u591f\u8df3\u5230\u5bf9\u5e94\u5143\u7d20\u503c\u4e3a 0 \u7684 \u4efb\u4e00 \u4e0b\u6807\u5904\u3002

\n\n

\u6ce8\u610f\uff0c\u4e0d\u7ba1\u662f\u4ec0\u4e48\u60c5\u51b5\u4e0b\uff0c\u4f60\u90fd\u65e0\u6cd5\u8df3\u5230\u6570\u7ec4\u4e4b\u5916\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aarr = [4,2,3,0,3,1,2], start = 5\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\n\u5230\u8fbe\u503c\u4e3a 0 \u7684\u4e0b\u6807 3 \u6709\u4ee5\u4e0b\u53ef\u80fd\u65b9\u6848\uff1a \n\u4e0b\u6807 5 -> \u4e0b\u6807 4 -> \u4e0b\u6807 1 -> \u4e0b\u6807 3 \n\u4e0b\u6807 5 -> \u4e0b\u6807 6 -> \u4e0b\u6807 4 -> \u4e0b\u6807 1 -> \u4e0b\u6807 3 \n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aarr = [4,2,3,0,3,1,2], start = 0\n\u8f93\u51fa\uff1atrue \n\u89e3\u91ca\uff1a\n\u5230\u8fbe\u503c\u4e3a 0 \u7684\u4e0b\u6807 3 \u6709\u4ee5\u4e0b\u53ef\u80fd\u65b9\u6848\uff1a \n\u4e0b\u6807 0 -> \u4e0b\u6807 4 -> \u4e0b\u6807 1 -> \u4e0b\u6807 3\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aarr = [3,0,2,1,2], start = 2\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u65e0\u6cd5\u5230\u8fbe\u503c\u4e3a 0 \u7684\u4e0b\u6807 1 \u5904\u3002 \n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= arr.length <= 5 * 10^4
  • \n\t
  • 0 <= arr[i] < arr.length
  • \n\t
  • 0 <= start < arr.length
  • \n
\n", "tags_en": ["Depth-first Search", "Breadth-first Search", "Recursion"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u9012\u5f52"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canReach(vector& arr, int start) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canReach(int[] arr, int start) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canReach(self, arr, start):\n \"\"\"\n :type arr: List[int]\n :type start: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canReach(self, arr: List[int], start: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canReach(int* arr, int arrSize, int start){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanReach(int[] arr, int start) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @param {number} start\n * @return {boolean}\n */\nvar canReach = function(arr, start) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @param {Integer} start\n# @return {Boolean}\ndef can_reach(arr, start)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canReach(_ arr: [Int], _ start: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canReach(arr []int, start int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canReach(arr: Array[Int], start: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canReach(arr: IntArray, start: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_reach(arr: Vec, start: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @param Integer $start\n * @return Boolean\n */\n function canReach($arr, $start) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canReach(arr: number[], start: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-reach arr start)\n (-> (listof exact-integer?) exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1306](https://leetcode-cn.com/problems/jump-game-iii)", "[\u8df3\u8dc3\u6e38\u620f III](/solution/1300-1399/1306.Jump%20Game%20III/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u9012\u5f52`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1306](https://leetcode.com/problems/jump-game-iii)", "[Jump Game III](/solution/1300-1399/1306.Jump%20Game%20III/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`,`Recursion`", "Medium", ""]}, {"question_id": "1427", "frontend_question_id": "1305", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/all-elements-in-two-binary-search-trees", "url_en": "https://leetcode.com/problems/all-elements-in-two-binary-search-trees", "relative_path_cn": "/solution/1300-1399/1305.All%20Elements%20in%20Two%20Binary%20Search%20Trees/README.md", "relative_path_en": "/solution/1300-1399/1305.All%20Elements%20in%20Two%20Binary%20Search%20Trees/README_EN.md", "title_cn": "\u4e24\u68f5\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u7684\u6240\u6709\u5143\u7d20", "title_en": "All Elements in Two Binary Search Trees", "question_title_slug": "all-elements-in-two-binary-search-trees", "content_en": "

Given two binary search trees root1 and root2.

\n\n

Return a list containing all the integers from both trees sorted in ascending order.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: root1 = [2,1,4], root2 = [1,0,3]\nOutput: [0,1,1,2,3,4]\n
\n\n

Example 2:

\n\n
\nInput: root1 = [0,-10,10], root2 = [5,1,7,0,2]\nOutput: [-10,0,0,1,2,5,7,10]\n
\n\n

Example 3:

\n\n
\nInput: root1 = [], root2 = [5,1,7,0,2]\nOutput: [0,1,2,5,7]\n
\n\n

Example 4:

\n\n
\nInput: root1 = [0,-10,10], root2 = []\nOutput: [-10,0,10]\n
\n\n

Example 5:

\n\"\"\n
\nInput: root1 = [1,null,8], root2 = [8,1]\nOutput: [1,1,8,8]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • Each tree has at most 5000 nodes.
  • \n\t
  • Each node's value is between [-10^5, 10^5].
  • \n
\n", "content_cn": "

\u7ed9\u4f60 root1 \u548c root2 \u8fd9\u4e24\u68f5\u4e8c\u53c9\u641c\u7d22\u6811\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u4e00\u4e2a\u5217\u8868\uff0c\u5176\u4e2d\u5305\u542b \u4e24\u68f5\u6811 \u4e2d\u7684\u6240\u6709\u6574\u6570\u5e76\u6309 \u5347\u5e8f \u6392\u5e8f\u3002.

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1aroot1 = [2,1,4], root2 = [1,0,3]\n\u8f93\u51fa\uff1a[0,1,1,2,3,4]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aroot1 = [0,-10,10], root2 = [5,1,7,0,2]\n\u8f93\u51fa\uff1a[-10,0,0,1,2,5,7,10]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aroot1 = [], root2 = [5,1,7,0,2]\n\u8f93\u51fa\uff1a[0,1,2,5,7]\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1aroot1 = [0,-10,10], root2 = []\n\u8f93\u51fa\uff1a[-10,0,10]\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1aroot1 = [1,null,8], root2 = [8,1]\n\u8f93\u51fa\uff1a[1,1,8,8]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u6bcf\u68f5\u6811\u6700\u591a\u6709 5000 \u4e2a\u8282\u70b9\u3002
  • \n\t
  • \u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u5728 [-10^5, 10^5] \u4e4b\u95f4\u3002
  • \n
\n", "tags_en": ["Sort", "Tree"], "tags_cn": ["\u6392\u5e8f", "\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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 */\nclass Solution {\npublic:\n vector getAllElements(TreeNode* root1, TreeNode* root2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode(int x) { val = x; }\n * }\n */\nclass Solution {\n public List getAllElements(TreeNode root1, TreeNode root2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution(object):\n def getAllElements(self, root1, root2):\n \"\"\"\n :type root1: TreeNode\n :type root2: TreeNode\n :rtype: List[int]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution:\n def getAllElements(self, root1: TreeNode, root2: TreeNode) -> List[int]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* getAllElements(struct TreeNode* root1, struct TreeNode* root2, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int x) { val = x; }\n * }\n */\npublic class Solution {\n public IList GetAllElements(TreeNode root1, TreeNode root2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val) {\n * this.val = val;\n * this.left = this.right = null;\n * }\n */\n/**\n * @param {TreeNode} root1\n * @param {TreeNode} root2\n * @return {number[]}\n */\nvar getAllElements = function(root1, root2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val)\n# @val = val\n# @left, @right = nil, nil\n# end\n# end\n\n# @param {TreeNode} root1\n# @param {TreeNode} root2\n# @return {Integer[]}\ndef get_all_elements(root1, root2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.left = nil\n * self.right = nil\n * }\n * }\n */\nclass Solution {\n func getAllElements(_ root1: TreeNode?, _ root2: TreeNode?) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc getAllElements(root1 *TreeNode, root2 *TreeNode) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(var _value: Int) {\n * var value: Int = _value\n * var left: TreeNode = null\n * var right: TreeNode = null\n * }\n */\nobject Solution {\n def getAllElements(root1: TreeNode, root2: TreeNode): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun getAllElements(root1: TreeNode?, root2: TreeNode?): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n// \n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn get_all_elements(root1: Option>>, root2: Option>>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($value) { $this->val = $value; }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root1\n * @param TreeNode $root2\n * @return Integer[]\n */\n function getAllElements($root1, $root2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction getAllElements(root1: TreeNode | null, root2: TreeNode | null): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (get-all-elements root1 root2)\n (-> (or/c tree-node? #f) (or/c tree-node? #f) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1305](https://leetcode-cn.com/problems/all-elements-in-two-binary-search-trees)", "[\u4e24\u68f5\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u7684\u6240\u6709\u5143\u7d20](/solution/1300-1399/1305.All%20Elements%20in%20Two%20Binary%20Search%20Trees/README.md)", "`\u6392\u5e8f`,`\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1305](https://leetcode.com/problems/all-elements-in-two-binary-search-trees)", "[All Elements in Two Binary Search Trees](/solution/1300-1399/1305.All%20Elements%20in%20Two%20Binary%20Search%20Trees/README_EN.md)", "`Sort`,`Tree`", "Medium", ""]}, {"question_id": "1426", "frontend_question_id": "1304", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-n-unique-integers-sum-up-to-zero", "url_en": "https://leetcode.com/problems/find-n-unique-integers-sum-up-to-zero", "relative_path_cn": "/solution/1300-1399/1304.Find%20N%20Unique%20Integers%20Sum%20up%20to%20Zero/README.md", "relative_path_en": "/solution/1300-1399/1304.Find%20N%20Unique%20Integers%20Sum%20up%20to%20Zero/README_EN.md", "title_cn": "\u548c\u4e3a\u96f6\u7684N\u4e2a\u552f\u4e00\u6574\u6570", "title_en": "Find N Unique Integers Sum up to Zero", "question_title_slug": "find-n-unique-integers-sum-up-to-zero", "content_en": "

Given an integer n, return any array containing n unique integers such that they add up to 0.

\n\n

 

\n

Example 1:

\n\n
\nInput: n = 5\nOutput: [-7,-1,1,3,4]\nExplanation: These arrays also are accepted [-5,-1,1,2,3] , [-3,-1,2,-2,4].\n
\n\n

Example 2:

\n\n
\nInput: n = 3\nOutput: [-1,0,1]\n
\n\n

Example 3:

\n\n
\nInput: n = 1\nOutput: [0]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 1000
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n\uff0c\u8bf7\u4f60\u8fd4\u56de \u4efb\u610f \u4e00\u4e2a\u7531 n \u4e2a \u5404\u4e0d\u76f8\u540c \u7684\u6574\u6570\u7ec4\u6210\u7684\u6570\u7ec4\uff0c\u5e76\u4e14\u8fd9 n \u4e2a\u6570\u76f8\u52a0\u548c\u4e3a 0 \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1an = 5\n\u8f93\u51fa\uff1a[-7,-1,1,3,4]\n\u89e3\u91ca\uff1a\u8fd9\u4e9b\u6570\u7ec4\u4e5f\u662f\u6b63\u786e\u7684 [-5,-1,1,2,3]\uff0c[-3,-1,2,-2,4]\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1an = 3\n\u8f93\u51fa\uff1a[-1,0,1]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1a[0]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 1000
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector sumZero(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] sumZero(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def sumZero(self, n):\n \"\"\"\n :type n: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def sumZero(self, n: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* sumZero(int n, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] SumZero(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number[]}\n */\nvar sumZero = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer[]}\ndef sum_zero(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func sumZero(_ n: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func sumZero(n int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def sumZero(n: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun sumZero(n: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sum_zero(n: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer[]\n */\n function sumZero($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function sumZero(n: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (sum-zero n)\n (-> exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1304](https://leetcode-cn.com/problems/find-n-unique-integers-sum-up-to-zero)", "[\u548c\u4e3a\u96f6\u7684N\u4e2a\u552f\u4e00\u6574\u6570](/solution/1300-1399/1304.Find%20N%20Unique%20Integers%20Sum%20up%20to%20Zero/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1304](https://leetcode.com/problems/find-n-unique-integers-sum-up-to-zero)", "[Find N Unique Integers Sum up to Zero](/solution/1300-1399/1304.Find%20N%20Unique%20Integers%20Sum%20up%20to%20Zero/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1425", "frontend_question_id": "1294", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/weather-type-in-each-country", "url_en": "https://leetcode.com/problems/weather-type-in-each-country", "relative_path_cn": "/solution/1200-1299/1294.Weather%20Type%20in%20Each%20Country/README.md", "relative_path_en": "/solution/1200-1299/1294.Weather%20Type%20in%20Each%20Country/README_EN.md", "title_cn": "\u4e0d\u540c\u56fd\u5bb6\u7684\u5929\u6c14\u7c7b\u578b", "title_en": "Weather Type in Each Country", "question_title_slug": "weather-type-in-each-country", "content_en": "

Table: Countries

\r\n\r\n
\r\n+---------------+---------+\r\n| Column Name   | Type    |\r\n+---------------+---------+\r\n| country_id    | int     |\r\n| country_name  | varchar |\r\n+---------------+---------+\r\ncountry_id is the primary key for this table.\r\nEach row of this table contains the ID and the name of one country.\r\n
\r\n\r\n

 

\r\n\r\n

Table: Weather

\r\n\r\n
\r\n+---------------+---------+\r\n| Column Name   | Type    |\r\n+---------------+---------+\r\n| country_id    | int     |\r\n| weather_state | varchar |\r\n| day           | date    |\r\n+---------------+---------+\r\n(country_id, day) is the primary key for this table.\r\nEach row of this table indicates the weather state in a country for one day.\r\n
\r\n\r\n

 

\r\n\r\n

Write an SQL query to find the type of weather in each country for November 2019.

\r\n\r\n

The type of weather is Cold if the average weather_state is less than or equal 15, Hot if the average weather_state is greater than or equal 25 and Warm otherwise.

\r\n\r\n

Return result table in any order.

\r\n\r\n

The query result format is in the following example:

\r\n\r\n
\r\nCountries table:\r\n+------------+--------------+\r\n| country_id | country_name |\r\n+------------+--------------+\r\n| 2          | USA          |\r\n| 3          | Australia    |\r\n| 7          | Peru         |\r\n| 5          | China        |\r\n| 8          | Morocco      |\r\n| 9          | Spain        |\r\n+------------+--------------+\r\nWeather table:\r\n+------------+---------------+------------+\r\n| country_id | weather_state | day        |\r\n+------------+---------------+------------+\r\n| 2          | 15            | 2019-11-01 |\r\n| 2          | 12            | 2019-10-28 |\r\n| 2          | 12            | 2019-10-27 |\r\n| 3          | -2            | 2019-11-10 |\r\n| 3          | 0             | 2019-11-11 |\r\n| 3          | 3             | 2019-11-12 |\r\n| 5          | 16            | 2019-11-07 |\r\n| 5          | 18            | 2019-11-09 |\r\n| 5          | 21            | 2019-11-23 |\r\n| 7          | 25            | 2019-11-28 |\r\n| 7          | 22            | 2019-12-01 |\r\n| 7          | 20            | 2019-12-02 |\r\n| 8          | 25            | 2019-11-05 |\r\n| 8          | 27            | 2019-11-15 |\r\n| 8          | 31            | 2019-11-25 |\r\n| 9          | 7             | 2019-10-23 |\r\n| 9          | 3             | 2019-12-23 |\r\n+------------+---------------+------------+\r\nResult table:\r\n+--------------+--------------+\r\n| country_name | weather_type |\r\n+--------------+--------------+\r\n| USA          | Cold         |\r\n| Austraila    | Cold         |\r\n| Peru         | Hot          |\r\n| China        | Warm         |\r\n| Morocco      | Hot          |\r\n+--------------+--------------+\r\nAverage weather_state in USA in November is (15) / 1 = 15 so weather type is Cold.\r\nAverage weather_state in Austraila in November is (-2 + 0 + 3) / 3 = 0.333 so weather type is Cold.\r\nAverage weather_state in Peru in November is (25) / 1 = 25 so weather type is Hot.\r\nAverage weather_state in China in November is (16 + 18 + 21) / 3 = 18.333 so weather type is Warm.\r\nAverage weather_state in Morocco in November is (25 + 27 + 31) / 3 = 27.667 so weather type is Hot.\r\nWe know nothing about average weather_state in Spain in November so we don't include it in the result table. \r\n
", "content_cn": "

\u56fd\u5bb6\u8868\uff1aCountries

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| country_id    | int     |\n| country_name  | varchar |\n+---------------+---------+\ncountry_id \u662f\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\u3002\n\u8be5\u8868\u7684\u6bcf\u884c\u6709 country_id \u548c country_name \u4e24\u5217\u3002\n
\n\n

 

\n\n

\u5929\u6c14\u8868\uff1aWeather

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| country_id    | int     |\n| weather_state | varchar |\n| day           | date    |\n+---------------+---------+\n(country_id, day) \u662f\u8be5\u8868\u7684\u590d\u5408\u4e3b\u952e\u3002\n\u8be5\u8868\u7684\u6bcf\u4e00\u884c\u8bb0\u5f55\u4e86\u67d0\u4e2a\u56fd\u5bb6\u67d0\u4e00\u5929\u7684\u5929\u6c14\u60c5\u51b5\u3002\n
\n\n

 

\n\n

\u5199\u4e00\u6bb5 SQL \u6765\u627e\u5230\u8868\u4e2d\u6bcf\u4e2a\u56fd\u5bb6\u5728 2019 \u5e74 11 \u6708\u7684\u5929\u6c14\u7c7b\u578b\u3002

\n\n

\u5929\u6c14\u7c7b\u578b\u7684\u5b9a\u4e49\u5982\u4e0b\uff1a\u5f53 weather_state \u7684\u5e73\u5747\u503c\u5c0f\u4e8e\u6216\u7b49\u4e8e15\u8fd4\u56de Cold\uff0c\u5f53 weather_state \u7684\u5e73\u5747\u503c\u5927\u4e8e\u6216\u7b49\u4e8e 25 \u8fd4\u56de Hot\uff0c\u5426\u5219\u8fd4\u56de Warm\u3002

\n\n

\u4f60\u53ef\u4ee5\u4ee5\u4efb\u610f\u987a\u5e8f\u8fd4\u56de\u4f60\u7684\u67e5\u8be2\u7ed3\u679c\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u6240\u793a\uff1a

\n\n
\nCountries table:\n+------------+--------------+\n| country_id | country_name |\n+------------+--------------+\n| 2          | USA          |\n| 3          | Australia    |\n| 7          | Peru         |\n| 5          | China        |\n| 8          | Morocco      |\n| 9          | Spain        |\n+------------+--------------+\nWeather table:\n+------------+---------------+------------+\n| country_id | weather_state | day        |\n+------------+---------------+------------+\n| 2          | 15            | 2019-11-01 |\n| 2          | 12            | 2019-10-28 |\n| 2          | 12            | 2019-10-27 |\n| 3          | -2            | 2019-11-10 |\n| 3          | 0             | 2019-11-11 |\n| 3          | 3             | 2019-11-12 |\n| 5          | 16            | 2019-11-07 |\n| 5          | 18            | 2019-11-09 |\n| 5          | 21            | 2019-11-23 |\n| 7          | 25            | 2019-11-28 |\n| 7          | 22            | 2019-12-01 |\n| 7          | 20            | 2019-12-02 |\n| 8          | 25            | 2019-11-05 |\n| 8          | 27            | 2019-11-15 |\n| 8          | 31            | 2019-11-25 |\n| 9          | 7             | 2019-10-23 |\n| 9          | 3             | 2019-12-23 |\n+------------+---------------+------------+\nResult table:\n+--------------+--------------+\n| country_name | weather_type |\n+--------------+--------------+\n| USA          | Cold         |\n| Austraila    | Cold         |\n| Peru         | Hot          |\n| China        | Warm         |\n| Morocco      | Hot          |\n+--------------+--------------+\nUSA 11 \u6708\u7684\u5e73\u5747 weather_state \u4e3a (15) / 1 = 15 \u6240\u4ee5\u5929\u6c14\u7c7b\u578b\u4e3a Cold\u3002\nAustralia 11 \u6708\u7684\u5e73\u5747 weather_state \u4e3a (-2 + 0 + 3) / 3 = 0.333 \u6240\u4ee5\u5929\u6c14\u7c7b\u578b\u4e3a Cold\u3002\nPeru 11 \u6708\u7684\u5e73\u5747 weather_state \u4e3a (25) / 1 = 25 \u6240\u4ee5\u5929\u6c14\u7c7b\u578b\u4e3a Hot\u3002\nChina 11 \u6708\u7684\u5e73\u5747 weather_state \u4e3a (16 + 18 + 21) / 3 = 18.333 \u6240\u4ee5\u5929\u6c14\u7c7b\u578b\u4e3a Warm\u3002\nMorocco 11 \u6708\u7684\u5e73\u5747 weather_state \u4e3a (25 + 27 + 31) / 3 = 27.667 \u6240\u4ee5\u5929\u6c14\u7c7b\u578b\u4e3a Hot\u3002\n\u6211\u4eec\u5e76\u4e0d\u77e5\u9053 Spain \u5728 11 \u6708\u7684 weather_state \u60c5\u51b5\u6240\u4ee5\u65e0\u9700\u5c06\u4ed6\u5305\u542b\u5728\u7ed3\u679c\u4e2d\u3002\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1294](https://leetcode-cn.com/problems/weather-type-in-each-country)", "[\u4e0d\u540c\u56fd\u5bb6\u7684\u5929\u6c14\u7c7b\u578b](/solution/1200-1299/1294.Weather%20Type%20in%20Each%20Country/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1294](https://leetcode.com/problems/weather-type-in-each-country)", "[Weather Type in Each Country](/solution/1200-1299/1294.Weather%20Type%20in%20Each%20Country/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1424", "frontend_question_id": "1298", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-candies-you-can-get-from-boxes", "url_en": "https://leetcode.com/problems/maximum-candies-you-can-get-from-boxes", "relative_path_cn": "/solution/1200-1299/1298.Maximum%20Candies%20You%20Can%20Get%20from%20Boxes/README.md", "relative_path_en": "/solution/1200-1299/1298.Maximum%20Candies%20You%20Can%20Get%20from%20Boxes/README_EN.md", "title_cn": "\u4f60\u80fd\u4ece\u76d2\u5b50\u91cc\u83b7\u5f97\u7684\u6700\u5927\u7cd6\u679c\u6570", "title_en": "Maximum Candies You Can Get from Boxes", "question_title_slug": "maximum-candies-you-can-get-from-boxes", "content_en": "

Given n boxes, each box is given in the format [status, candies, keys, containedBoxes] where:

\r\n\r\n
    \r\n\t
  • status[i]: an integer which is 1 if box[i] is open and 0 if box[i] is closed.
  • \r\n\t
  • candies[i]: an integer representing the number of candies in box[i].
  • \r\n\t
  • keys[i]: an array contains the indices of the boxes you can open with the key in box[i].
  • \r\n\t
  • containedBoxes[i]: an array contains the indices of the boxes found in box[i].
  • \r\n
\r\n\r\n

You will start with some boxes given in initialBoxes array. You can take all the candies in any open box and you can use the keys in it to open new boxes and you also can use the boxes you find in it.

\r\n\r\n

Return the maximum number of candies you can get following the rules above.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: status = [1,0,1,0], candies = [7,5,4,100], keys = [[],[],[1],[]], containedBoxes = [[1,2],[3],[],[]], initialBoxes = [0]\r\nOutput: 16\r\nExplanation: You will be initially given box 0. You will find 7 candies in it and boxes 1 and 2. Box 1 is closed and you don't have a key for it so you will open box 2. You will find 4 candies and a key to box 1 in box 2.\r\nIn box 1, you will find 5 candies and box 3 but you will not find a key to box 3 so box 3 will remain closed.\r\nTotal number of candies collected = 7 + 4 + 5 = 16 candy.\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: status = [1,0,0,0,0,0], candies = [1,1,1,1,1,1], keys = [[1,2,3,4,5],[],[],[],[],[]], containedBoxes = [[1,2,3,4,5],[],[],[],[],[]], initialBoxes = [0]\r\nOutput: 6\r\nExplanation: You have initially box 0. Opening it you can find boxes 1,2,3,4 and 5 and their keys. The total number of candies will be 6.\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: status = [1,1,1], candies = [100,1,100], keys = [[],[0,2],[]], containedBoxes = [[],[],[]], initialBoxes = [1]\r\nOutput: 1\r\n
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: status = [1], candies = [100], keys = [[]], containedBoxes = [[]], initialBoxes = []\r\nOutput: 0\r\n
\r\n\r\n

Example 5:

\r\n\r\n
\r\nInput: status = [1,1,1], candies = [2,3,2], keys = [[],[],[]], containedBoxes = [[],[],[]], initialBoxes = [2,1,0]\r\nOutput: 7\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= status.length <= 1000
  • \r\n\t
  • status.length == candies.length == keys.length == containedBoxes.length == n
  • \r\n\t
  • status[i] is 0 or 1.
  • \r\n\t
  • 1 <= candies[i] <= 1000
  • \r\n\t
  • 0 <= keys[i].length <= status.length
  • \r\n\t
  • 0 <= keys[i][j] < status.length
  • \r\n\t
  • All values in keys[i] are unique.
  • \r\n\t
  • 0 <= containedBoxes[i].length <= status.length
  • \r\n\t
  • 0 <= containedBoxes[i][j] < status.length
  • \r\n\t
  • All values in containedBoxes[i] are unique.
  • \r\n\t
  • Each box is contained in one box at most.
  • \r\n\t
  • 0 <= initialBoxes.length <= status.length
  • \r\n\t
  • 0 <= initialBoxes[i] < status.length
  • \r\n
", "content_cn": "

\u7ed9\u4f60 n \u4e2a\u76d2\u5b50\uff0c\u6bcf\u4e2a\u76d2\u5b50\u7684\u683c\u5f0f\u4e3a [status, candies, keys, containedBoxes] \uff0c\u5176\u4e2d\uff1a

\n\n
    \n\t
  • \u72b6\u6001\u5b57 status[i]\uff1a\u6574\u6570\uff0c\u5982\u679c box[i] \u662f\u5f00\u7684\uff0c\u90a3\u4e48\u662f \uff0c\u5426\u5219\u662f \u3002
  • \n\t
  • \u7cd6\u679c\u6570 candies[i]: \u6574\u6570\uff0c\u8868\u793a box[i] \u4e2d\u7cd6\u679c\u7684\u6570\u76ee\u3002
  • \n\t
  • \u94a5\u5319 keys[i]\uff1a\u6570\u7ec4\uff0c\u8868\u793a\u4f60\u6253\u5f00 box[i] \u540e\uff0c\u53ef\u4ee5\u5f97\u5230\u4e00\u4e9b\u76d2\u5b50\u7684\u94a5\u5319\uff0c\u6bcf\u4e2a\u5143\u7d20\u5206\u522b\u4e3a\u8be5\u94a5\u5319\u5bf9\u5e94\u76d2\u5b50\u7684\u4e0b\u6807\u3002
  • \n\t
  • \u5185\u542b\u7684\u76d2\u5b50 containedBoxes[i]\uff1a\u6574\u6570\uff0c\u8868\u793a\u653e\u5728 box[i] \u91cc\u7684\u76d2\u5b50\u6240\u5bf9\u5e94\u7684\u4e0b\u6807\u3002
  • \n
\n\n

\u7ed9\u4f60\u4e00\u4e2a initialBoxes \u6570\u7ec4\uff0c\u8868\u793a\u4f60\u73b0\u5728\u5f97\u5230\u7684\u76d2\u5b50\uff0c\u4f60\u53ef\u4ee5\u83b7\u5f97\u91cc\u9762\u7684\u7cd6\u679c\uff0c\u4e5f\u53ef\u4ee5\u7528\u76d2\u5b50\u91cc\u7684\u94a5\u5319\u6253\u5f00\u65b0\u7684\u76d2\u5b50\uff0c\u8fd8\u53ef\u4ee5\u7ee7\u7eed\u63a2\u7d22\u4ece\u8fd9\u4e2a\u76d2\u5b50\u91cc\u627e\u5230\u7684\u5176\u4ed6\u76d2\u5b50\u3002

\n\n

\u8bf7\u4f60\u6309\u7167\u4e0a\u8ff0\u89c4\u5219\uff0c\u8fd4\u56de\u53ef\u4ee5\u83b7\u5f97\u7cd6\u679c\u7684 \u6700\u5927\u6570\u76ee \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1astatus = [1,0,1,0], candies = [7,5,4,100], keys = [[],[],[1],[]], containedBoxes = [[1,2],[3],[],[]], initialBoxes = [0]\n\u8f93\u51fa\uff1a16\n\u89e3\u91ca\uff1a\n\u4e00\u5f00\u59cb\u4f60\u6709\u76d2\u5b50 0 \u3002\u4f60\u5c06\u83b7\u5f97\u5b83\u91cc\u9762\u7684 7 \u4e2a\u7cd6\u679c\u548c\u76d2\u5b50 1 \u548c 2\u3002\n\u76d2\u5b50 1 \u76ee\u524d\u72b6\u6001\u662f\u5173\u95ed\u7684\uff0c\u800c\u4e14\u4f60\u8fd8\u6ca1\u6709\u5bf9\u5e94\u5b83\u7684\u94a5\u5319\u3002\u6240\u4ee5\u4f60\u5c06\u4f1a\u6253\u5f00\u76d2\u5b50 2 \uff0c\u5e76\u5f97\u5230\u91cc\u9762\u7684 4 \u4e2a\u7cd6\u679c\u548c\u76d2\u5b50 1 \u7684\u94a5\u5319\u3002\n\u5728\u76d2\u5b50 1 \u4e2d\uff0c\u4f60\u4f1a\u83b7\u5f97 5 \u4e2a\u7cd6\u679c\u548c\u76d2\u5b50 3 \uff0c\u4f46\u662f\u4f60\u6ca1\u6cd5\u83b7\u5f97\u76d2\u5b50 3 \u7684\u94a5\u5319\u6240\u4ee5\u76d2\u5b50 3 \u4f1a\u4fdd\u6301\u5173\u95ed\u72b6\u6001\u3002\n\u4f60\u603b\u5171\u53ef\u4ee5\u83b7\u5f97\u7684\u7cd6\u679c\u6570\u76ee = 7 + 4 + 5 = 16 \u4e2a\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1astatus = [1,0,0,0,0,0], candies = [1,1,1,1,1,1], keys = [[1,2,3,4,5],[],[],[],[],[]], containedBoxes = [[1,2,3,4,5],[],[],[],[],[]], initialBoxes = [0]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\n\u4f60\u4e00\u5f00\u59cb\u62e5\u6709\u76d2\u5b50 0 \u3002\u6253\u5f00\u5b83\u4f60\u53ef\u4ee5\u627e\u5230\u76d2\u5b50 1,2,3,4,5 \u548c\u5b83\u4eec\u5bf9\u5e94\u7684\u94a5\u5319\u3002\n\u6253\u5f00\u8fd9\u4e9b\u76d2\u5b50\uff0c\u4f60\u5c06\u83b7\u5f97\u6240\u6709\u76d2\u5b50\u7684\u7cd6\u679c\uff0c\u6240\u4ee5\u603b\u7cd6\u679c\u6570\u4e3a 6 \u4e2a\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1astatus = [1,1,1], candies = [100,1,100], keys = [[],[0,2],[]], containedBoxes = [[],[],[]], initialBoxes = [1]\n\u8f93\u51fa\uff1a1\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1astatus = [1], candies = [100], keys = [[]], containedBoxes = [[]], initialBoxes = []\n\u8f93\u51fa\uff1a0\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1astatus = [1,1,1], candies = [2,3,2], keys = [[],[],[]], containedBoxes = [[],[],[]], initialBoxes = [2,1,0]\n\u8f93\u51fa\uff1a7\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= status.length <= 1000
  • \n\t
  • status.length == candies.length == keys.length == containedBoxes.length == n
  • \n\t
  • status[i] \u8981\u4e48\u662f 0 \u8981\u4e48\u662f 1 \u3002
  • \n\t
  • 1 <= candies[i] <= 1000
  • \n\t
  • 0 <= keys[i].length <= status.length
  • \n\t
  • 0 <= keys[i][j] < status.length
  • \n\t
  • keys[i] \u4e2d\u7684\u503c\u90fd\u662f\u4e92\u4e0d\u76f8\u540c\u7684\u3002
  • \n\t
  • 0 <= containedBoxes[i].length <= status.length
  • \n\t
  • 0 <= containedBoxes[i][j] < status.length
  • \n\t
  • containedBoxes[i] \u4e2d\u7684\u503c\u90fd\u662f\u4e92\u4e0d\u76f8\u540c\u7684\u3002
  • \n\t
  • \u6bcf\u4e2a\u76d2\u5b50\u6700\u591a\u88ab\u4e00\u4e2a\u76d2\u5b50\u5305\u542b\u3002
  • \n\t
  • 0 <= initialBoxes.length <= status.length
  • \n\t
  • 0 <= initialBoxes[i] < status.length
  • \n
\n", "tags_en": ["Breadth-first Search"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxCandies(vector& status, vector& candies, vector>& keys, vector>& containedBoxes, vector& initialBoxes) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxCandies(int[] status, int[] candies, int[][] keys, int[][] containedBoxes, int[] initialBoxes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxCandies(self, status, candies, keys, containedBoxes, initialBoxes):\n \"\"\"\n :type status: List[int]\n :type candies: List[int]\n :type keys: List[List[int]]\n :type containedBoxes: List[List[int]]\n :type initialBoxes: List[int]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxCandies(self, status: List[int], candies: List[int], keys: List[List[int]], containedBoxes: List[List[int]], initialBoxes: List[int]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxCandies(int* status, int statusSize, int* candies, int candiesSize, int** keys, int keysSize, int* keysColSize, int** containedBoxes, int containedBoxesSize, int* containedBoxesColSize, int* initialBoxes, int initialBoxesSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxCandies(int[] status, int[] candies, int[][] keys, int[][] containedBoxes, int[] initialBoxes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} status\n * @param {number[]} candies\n * @param {number[][]} keys\n * @param {number[][]} containedBoxes\n * @param {number[]} initialBoxes\n * @return {number}\n */\nvar maxCandies = function(status, candies, keys, containedBoxes, initialBoxes) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} status\n# @param {Integer[]} candies\n# @param {Integer[][]} keys\n# @param {Integer[][]} contained_boxes\n# @param {Integer[]} initial_boxes\n# @return {Integer}\ndef max_candies(status, candies, keys, contained_boxes, initial_boxes)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxCandies(_ status: [Int], _ candies: [Int], _ keys: [[Int]], _ containedBoxes: [[Int]], _ initialBoxes: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxCandies(status []int, candies []int, keys [][]int, containedBoxes [][]int, initialBoxes []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxCandies(status: Array[Int], candies: Array[Int], keys: Array[Array[Int]], containedBoxes: Array[Array[Int]], initialBoxes: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxCandies(status: IntArray, candies: IntArray, keys: Array, containedBoxes: Array, initialBoxes: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_candies(status: Vec, candies: Vec, keys: Vec>, contained_boxes: Vec>, initial_boxes: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $status\n * @param Integer[] $candies\n * @param Integer[][] $keys\n * @param Integer[][] $containedBoxes\n * @param Integer[] $initialBoxes\n * @return Integer\n */\n function maxCandies($status, $candies, $keys, $containedBoxes, $initialBoxes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxCandies(status: number[], candies: number[], keys: number[][], containedBoxes: number[][], initialBoxes: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-candies status candies keys containedBoxes initialBoxes)\n (-> (listof exact-integer?) (listof exact-integer?) (listof (listof exact-integer?)) (listof (listof exact-integer?)) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1298](https://leetcode-cn.com/problems/maximum-candies-you-can-get-from-boxes)", "[\u4f60\u80fd\u4ece\u76d2\u5b50\u91cc\u83b7\u5f97\u7684\u6700\u5927\u7cd6\u679c\u6570](/solution/1200-1299/1298.Maximum%20Candies%20You%20Can%20Get%20from%20Boxes/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[1298](https://leetcode.com/problems/maximum-candies-you-can-get-from-boxes)", "[Maximum Candies You Can Get from Boxes](/solution/1200-1299/1298.Maximum%20Candies%20You%20Can%20Get%20from%20Boxes/README_EN.md)", "`Breadth-first Search`", "Hard", ""]}, {"question_id": "1423", "frontend_question_id": "1297", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-number-of-occurrences-of-a-substring", "url_en": "https://leetcode.com/problems/maximum-number-of-occurrences-of-a-substring", "relative_path_cn": "/solution/1200-1299/1297.Maximum%20Number%20of%20Occurrences%20of%20a%20Substring/README.md", "relative_path_en": "/solution/1200-1299/1297.Maximum%20Number%20of%20Occurrences%20of%20a%20Substring/README_EN.md", "title_cn": "\u5b50\u4e32\u7684\u6700\u5927\u51fa\u73b0\u6b21\u6570", "title_en": "Maximum Number of Occurrences of a Substring", "question_title_slug": "maximum-number-of-occurrences-of-a-substring", "content_en": "

Given a string s, return the maximum number of ocurrences of any substring under the following rules:

\r\n\r\n
    \r\n\t
  • The number of unique characters in the substring must be less than or equal to maxLetters.
  • \r\n\t
  • The substring size must be between minSize and maxSize inclusive.
  • \r\n
\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4\r\nOutput: 2\r\nExplanation: Substring "aab" has 2 ocurrences in the original string.\r\nIt satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize).\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3\r\nOutput: 2\r\nExplanation: Substring "aaa" occur 2 times in the string. It can overlap.\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3\r\nOutput: 3\r\n
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3\r\nOutput: 0\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= s.length <= 10^5
  • \r\n\t
  • 1 <= maxLetters <= 26
  • \r\n\t
  • 1 <= minSize <= maxSize <= min(26, s.length)
  • \r\n\t
  • s only contains lowercase English letters.
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \uff0c\u8bf7\u4f60\u8fd4\u56de\u6ee1\u8db3\u4ee5\u4e0b\u6761\u4ef6\u4e14\u51fa\u73b0\u6b21\u6570\u6700\u5927\u7684 \u4efb\u610f \u5b50\u4e32\u7684\u51fa\u73b0\u6b21\u6570\uff1a

\n\n
    \n\t
  • \u5b50\u4e32\u4e2d\u4e0d\u540c\u5b57\u6bcd\u7684\u6570\u76ee\u5fc5\u987b\u5c0f\u4e8e\u7b49\u4e8e maxLetters \u3002
  • \n\t
  • \u5b50\u4e32\u7684\u957f\u5ea6\u5fc5\u987b\u5927\u4e8e\u7b49\u4e8e minSize \u4e14\u5c0f\u4e8e\u7b49\u4e8e maxSize \u3002
  • \n
\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1as = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5b50\u4e32 "aab" \u5728\u539f\u5b57\u7b26\u4e32\u4e2d\u51fa\u73b0\u4e86 2 \u6b21\u3002\n\u5b83\u6ee1\u8db3\u6240\u6709\u7684\u8981\u6c42\uff1a2 \u4e2a\u4e0d\u540c\u7684\u5b57\u6bcd\uff0c\u957f\u5ea6\u4e3a 3 \uff08\u5728 minSize \u548c maxSize \u8303\u56f4\u5185\uff09\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1as = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5b50\u4e32 "aaa" \u5728\u539f\u5b57\u7b26\u4e32\u4e2d\u51fa\u73b0\u4e86 2 \u6b21\uff0c\u4e14\u5b83\u4eec\u6709\u91cd\u53e0\u90e8\u5206\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1as = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3\n\u8f93\u51fa\uff1a3\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1as = "abcde", maxLetters = 2, minSize = 3, maxSize = 3\n\u8f93\u51fa\uff1a0\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length <= 10^5
  • \n\t
  • 1 <= maxLetters <= 26
  • \n\t
  • 1 <= minSize <= maxSize <= min(26, s.length)
  • \n\t
  • s \u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
  • \n
\n", "tags_en": ["Bit Manipulation", "String"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxFreq(string s, int maxLetters, int minSize, int maxSize) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxFreq(String s, int maxLetters, int minSize, int maxSize) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxFreq(self, s, maxLetters, minSize, maxSize):\n \"\"\"\n :type s: str\n :type maxLetters: int\n :type minSize: int\n :type maxSize: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxFreq(char * s, int maxLetters, int minSize, int maxSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxFreq(string s, int maxLetters, int minSize, int maxSize) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number} maxLetters\n * @param {number} minSize\n * @param {number} maxSize\n * @return {number}\n */\nvar maxFreq = function(s, maxLetters, minSize, maxSize) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer} max_letters\n# @param {Integer} min_size\n# @param {Integer} max_size\n# @return {Integer}\ndef max_freq(s, max_letters, min_size, max_size)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxFreq(_ s: String, _ maxLetters: Int, _ minSize: Int, _ maxSize: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxFreq(s string, maxLetters int, minSize int, maxSize int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxFreq(s: String, maxLetters: Int, minSize: Int, maxSize: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxFreq(s: String, maxLetters: Int, minSize: Int, maxSize: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_freq(s: String, max_letters: i32, min_size: i32, max_size: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer $maxLetters\n * @param Integer $minSize\n * @param Integer $maxSize\n * @return Integer\n */\n function maxFreq($s, $maxLetters, $minSize, $maxSize) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxFreq(s: string, maxLetters: number, minSize: number, maxSize: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-freq s maxLetters minSize maxSize)\n (-> string? exact-integer? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1297](https://leetcode-cn.com/problems/maximum-number-of-occurrences-of-a-substring)", "[\u5b50\u4e32\u7684\u6700\u5927\u51fa\u73b0\u6b21\u6570](/solution/1200-1299/1297.Maximum%20Number%20of%20Occurrences%20of%20a%20Substring/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1297](https://leetcode.com/problems/maximum-number-of-occurrences-of-a-substring)", "[Maximum Number of Occurrences of a Substring](/solution/1200-1299/1297.Maximum%20Number%20of%20Occurrences%20of%20a%20Substring/README_EN.md)", "`Bit Manipulation`,`String`", "Medium", ""]}, {"question_id": "1422", "frontend_question_id": "1296", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/divide-array-in-sets-of-k-consecutive-numbers", "url_en": "https://leetcode.com/problems/divide-array-in-sets-of-k-consecutive-numbers", "relative_path_cn": "/solution/1200-1299/1296.Divide%20Array%20in%20Sets%20of%20K%20Consecutive%20Numbers/README.md", "relative_path_en": "/solution/1200-1299/1296.Divide%20Array%20in%20Sets%20of%20K%20Consecutive%20Numbers/README_EN.md", "title_cn": "\u5212\u5206\u6570\u7ec4\u4e3a\u8fde\u7eed\u6570\u5b57\u7684\u96c6\u5408", "title_en": "Divide Array in Sets of K Consecutive Numbers", "question_title_slug": "divide-array-in-sets-of-k-consecutive-numbers", "content_en": "

Given an array of integers nums and a positive integer k, find whether it's possible to divide this array into sets of k consecutive numbers
\nReturn True if it is possible. Otherwise, return False.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [1,2,3,3,4,4,5,6], k = 4\nOutput: true\nExplanation: Array can be divided into [1,2,3,4] and [3,4,5,6].\n
\n\n

Example 2:

\n\n
\nInput: nums = [3,2,1,2,3,4,3,4,5,9,10,11], k = 3\nOutput: true\nExplanation: Array can be divided into [1,2,3] , [2,3,4] , [3,4,5] and [9,10,11].\n
\n\n

Example 3:

\n\n
\nInput: nums = [3,3,2,2,1,1], k = 3\nOutput: true\n
\n\n

Example 4:

\n\n
\nInput: nums = [1,2,3,4], k = 3\nOutput: false\nExplanation: Each array should be divided in subarrays of size 3.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= k <= nums.length <= 105
  • \n\t
  • 1 <= nums[i] <= 109
  • \n
\n\n

 

\nNote: This question is the same as 846: https://leetcode.com/problems/hand-of-straights/", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0nums\u00a0\u548c\u4e00\u4e2a\u6b63\u6574\u6570\u00a0k\uff0c\u8bf7\u4f60\u5224\u65ad\u662f\u5426\u53ef\u4ee5\u628a\u8fd9\u4e2a\u6570\u7ec4\u5212\u5206\u6210\u4e00\u4e9b\u7531\u00a0k\u00a0\u4e2a\u8fde\u7eed\u6570\u5b57\u7ec4\u6210\u7684\u96c6\u5408\u3002
\n\u5982\u679c\u53ef\u4ee5\uff0c\u8bf7\u8fd4\u56de\u00a0True\uff1b\u5426\u5219\uff0c\u8fd4\u56de\u00a0False\u3002

\n\n

\u00a0

\n\n

\u6ce8\u610f\uff1a\u6b64\u9898\u76ee\u4e0e 846 \u91cd\u590d\uff1ahttps://leetcode-cn.com/problems/hand-of-straights/

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [1,2,3,3,4,4,5,6], k = 4\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u6570\u7ec4\u53ef\u4ee5\u5206\u6210 [1,2,3,4] \u548c [3,4,5,6]\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [3,2,1,2,3,4,3,4,5,9,10,11], k = 3\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u6570\u7ec4\u53ef\u4ee5\u5206\u6210 [1,2,3] , [2,3,4] , [3,4,5] \u548c [9,10,11]\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [3,3,2,2,1,1], k = 3\n\u8f93\u51fa\uff1atrue\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [1,2,3,4], k = 3\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u6570\u7ec4\u4e0d\u80fd\u5206\u6210\u51e0\u4e2a\u5927\u5c0f\u4e3a 3 \u7684\u5b50\u6570\u7ec4\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 10^5
  • \n\t
  • 1 <= nums[i] <= 10^9
  • \n\t
  • 1 <= k <= nums.length
  • \n
\n", "tags_en": ["Greedy", "Array"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isPossibleDivide(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isPossibleDivide(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isPossibleDivide(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isPossibleDivide(self, nums: List[int], k: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isPossibleDivide(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsPossibleDivide(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {boolean}\n */\nvar isPossibleDivide = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Boolean}\ndef is_possible_divide(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isPossibleDivide(_ nums: [Int], _ k: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isPossibleDivide(nums []int, k int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isPossibleDivide(nums: Array[Int], k: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isPossibleDivide(nums: IntArray, k: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_possible_divide(nums: Vec, k: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Boolean\n */\n function isPossibleDivide($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isPossibleDivide(nums: number[], k: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-possible-divide nums k)\n (-> (listof exact-integer?) exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1296](https://leetcode-cn.com/problems/divide-array-in-sets-of-k-consecutive-numbers)", "[\u5212\u5206\u6570\u7ec4\u4e3a\u8fde\u7eed\u6570\u5b57\u7684\u96c6\u5408](/solution/1200-1299/1296.Divide%20Array%20in%20Sets%20of%20K%20Consecutive%20Numbers/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1296](https://leetcode.com/problems/divide-array-in-sets-of-k-consecutive-numbers)", "[Divide Array in Sets of K Consecutive Numbers](/solution/1200-1299/1296.Divide%20Array%20in%20Sets%20of%20K%20Consecutive%20Numbers/README_EN.md)", "`Greedy`,`Array`", "Medium", ""]}, {"question_id": "1421", "frontend_question_id": "1295", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-numbers-with-even-number-of-digits", "url_en": "https://leetcode.com/problems/find-numbers-with-even-number-of-digits", "relative_path_cn": "/solution/1200-1299/1295.Find%20Numbers%20with%20Even%20Number%20of%20Digits/README.md", "relative_path_en": "/solution/1200-1299/1295.Find%20Numbers%20with%20Even%20Number%20of%20Digits/README_EN.md", "title_cn": "\u7edf\u8ba1\u4f4d\u6570\u4e3a\u5076\u6570\u7684\u6570\u5b57", "title_en": "Find Numbers with Even Number of Digits", "question_title_slug": "find-numbers-with-even-number-of-digits", "content_en": "Given an array nums of integers, return how many of them contain an even number of digits.\n

 

\n

Example 1:

\n\n
\nInput: nums = [12,345,2,6,7896]\nOutput: 2\nExplanation: \n12 contains 2 digits (even number of digits). \n345 contains 3 digits (odd number of digits). \n2 contains 1 digit (odd number of digits). \n6 contains 1 digit (odd number of digits). \n7896 contains 4 digits (even number of digits). \nTherefore only 12 and 7896 contain an even number of digits.\n
\n\n

Example 2:

\n\n
\nInput: nums = [555,901,482,1771]\nOutput: 1 \nExplanation: \nOnly 1771 contains an even number of digits.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 500
  • \n\t
  • 1 <= nums[i] <= 10^5
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums\uff0c\u8bf7\u4f60\u8fd4\u56de\u5176\u4e2d\u4f4d\u6570\u4e3a \u5076\u6570 \u7684\u6570\u5b57\u7684\u4e2a\u6570\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anums = [12,345,2,6,7896]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n12 \u662f 2 \u4f4d\u6570\u5b57\uff08\u4f4d\u6570\u4e3a\u5076\u6570\uff09 \n345 \u662f 3 \u4f4d\u6570\u5b57\uff08\u4f4d\u6570\u4e3a\u5947\u6570\uff09  \n2 \u662f 1 \u4f4d\u6570\u5b57\uff08\u4f4d\u6570\u4e3a\u5947\u6570\uff09 \n6 \u662f 1 \u4f4d\u6570\u5b57 \u4f4d\u6570\u4e3a\u5947\u6570\uff09 \n7896 \u662f 4 \u4f4d\u6570\u5b57\uff08\u4f4d\u6570\u4e3a\u5076\u6570\uff09  \n\u56e0\u6b64\u53ea\u6709 12 \u548c 7896 \u662f\u4f4d\u6570\u4e3a\u5076\u6570\u7684\u6570\u5b57\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anums = [555,901,482,1771]\n\u8f93\u51fa\uff1a1 \n\u89e3\u91ca\uff1a \n\u53ea\u6709 1771 \u662f\u4f4d\u6570\u4e3a\u5076\u6570\u7684\u6570\u5b57\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 500
  • \n\t
  • 1 <= nums[i] <= 10^5
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findNumbers(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findNumbers(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findNumbers(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findNumbers(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findNumbers(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindNumbers(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar findNumbers = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef find_numbers(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findNumbers(_ nums: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findNumbers(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findNumbers(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findNumbers(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_numbers(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function findNumbers($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findNumbers(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-numbers nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1295](https://leetcode-cn.com/problems/find-numbers-with-even-number-of-digits)", "[\u7edf\u8ba1\u4f4d\u6570\u4e3a\u5076\u6570\u7684\u6570\u5b57](/solution/1200-1299/1295.Find%20Numbers%20with%20Even%20Number%20of%20Digits/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1295](https://leetcode.com/problems/find-numbers-with-even-number-of-digits)", "[Find Numbers with Even Number of Digits](/solution/1200-1299/1295.Find%20Numbers%20with%20Even%20Number%20of%20Digits/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1420", "frontend_question_id": "1285", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/find-the-start-and-end-number-of-continuous-ranges", "url_en": "https://leetcode.com/problems/find-the-start-and-end-number-of-continuous-ranges", "relative_path_cn": "/solution/1200-1299/1285.Find%20the%20Start%20and%20End%20Number%20of%20Continuous%20Ranges/README.md", "relative_path_en": "/solution/1200-1299/1285.Find%20the%20Start%20and%20End%20Number%20of%20Continuous%20Ranges/README_EN.md", "title_cn": "\u627e\u5230\u8fde\u7eed\u533a\u95f4\u7684\u5f00\u59cb\u548c\u7ed3\u675f\u6570\u5b57", "title_en": "Find the Start and End Number of Continuous Ranges", "question_title_slug": "find-the-start-and-end-number-of-continuous-ranges", "content_en": "

Table: Logs

\r\n\r\n
\r\n+---------------+---------+\r\n| Column Name   | Type    |\r\n+---------------+---------+\r\n| log_id        | int     |\r\n+---------------+---------+\r\nid is the primary key for this table.\r\nEach row of this table contains the ID in a log Table.\r\n\r\n
\r\n\r\n

Since some IDs have been removed from Logs. Write an SQL query to find the start and end number of continuous ranges in table Logs.

\r\n\r\n

Order the result table by start_id.

\r\n\r\n

The query result format is in the following example:

\r\n\r\n
\r\nLogs table:\r\n+------------+\r\n| log_id     |\r\n+------------+\r\n| 1          |\r\n| 2          |\r\n| 3          |\r\n| 7          |\r\n| 8          |\r\n| 10         |\r\n+------------+\r\n\r\nResult table:\r\n+------------+--------------+\r\n| start_id   | end_id       |\r\n+------------+--------------+\r\n| 1          | 3            |\r\n| 7          | 8            |\r\n| 10         | 10           |\r\n+------------+--------------+\r\nThe result table should contain all ranges in table Logs.\r\nFrom 1 to 3 is contained in the table.\r\nFrom 4 to 6 is missing in the table\r\nFrom 7 to 8 is contained in the table.\r\nNumber 9 is missing in the table.\r\nNumber 10 is contained in the table.\r\n
", "content_cn": "

\u8868\uff1aLogs

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| log_id        | int     |\n+---------------+---------+\nid \u662f\u4e0a\u8868\u7684\u4e3b\u952e\u3002\n\u4e0a\u8868\u7684\u6bcf\u4e00\u884c\u5305\u542b\u65e5\u5fd7\u8868\u4e2d\u7684\u4e00\u4e2a ID\u3002\n
\n\n

 

\n\n

\u540e\u6765\u4e00\u4e9b ID \u4ece Logs \u8868\u4e2d\u5220\u9664\u3002\u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\u5f97\u5230 Logs \u8868\u4e2d\u7684\u8fde\u7eed\u533a\u95f4\u7684\u5f00\u59cb\u6570\u5b57\u548c\u7ed3\u675f\u6570\u5b57\u3002

\n\n

\u5c06\u67e5\u8be2\u8868\u6309\u7167 start_id \u6392\u5e8f\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u9762\u7684\u4f8b\u5b50\uff1a

\n\n
\nLogs \u8868\uff1a\n+------------+\n| log_id     |\n+------------+\n| 1          |\n| 2          |\n| 3          |\n| 7          |\n| 8          |\n| 10         |\n+------------+\n\n\u7ed3\u679c\u8868\uff1a\n+------------+--------------+\n| start_id   | end_id       |\n+------------+--------------+\n| 1          | 3            |\n| 7          | 8            |\n| 10         | 10           |\n+------------+--------------+\n\u7ed3\u679c\u8868\u5e94\u5305\u542b Logs \u8868\u4e2d\u7684\u6240\u6709\u533a\u95f4\u3002\n\u4ece 1 \u5230 3 \u5728\u8868\u4e2d\u3002\n\u4ece 4 \u5230 6 \u4e0d\u5728\u8868\u4e2d\u3002\n\u4ece 7 \u5230 8 \u5728\u8868\u4e2d\u3002\n9 \u4e0d\u5728\u8868\u4e2d\u3002\n10 \u5728\u8868\u4e2d\u3002\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1285](https://leetcode-cn.com/problems/find-the-start-and-end-number-of-continuous-ranges)", "[\u627e\u5230\u8fde\u7eed\u533a\u95f4\u7684\u5f00\u59cb\u548c\u7ed3\u675f\u6570\u5b57](/solution/1200-1299/1285.Find%20the%20Start%20and%20End%20Number%20of%20Continuous%20Ranges/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1285](https://leetcode.com/problems/find-the-start-and-end-number-of-continuous-ranges)", "[Find the Start and End Number of Continuous Ranges](/solution/1200-1299/1285.Find%20the%20Start%20and%20End%20Number%20of%20Continuous%20Ranges/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1415", "frontend_question_id": "1280", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/students-and-examinations", "url_en": "https://leetcode.com/problems/students-and-examinations", "relative_path_cn": "/solution/1200-1299/1280.Students%20and%20Examinations/README.md", "relative_path_en": "/solution/1200-1299/1280.Students%20and%20Examinations/README_EN.md", "title_cn": "\u5b66\u751f\u4eec\u53c2\u52a0\u5404\u79d1\u6d4b\u8bd5\u7684\u6b21\u6570", "title_en": "Students and Examinations", "question_title_slug": "students-and-examinations", "content_en": "

Table: Students

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| student_id    | int     |\n| student_name  | varchar |\n+---------------+---------+\nstudent_id is the primary key for this table.\nEach row of this table contains the ID and the name of one student in the school.\n
\n\n

 

\n\n

Table: Subjects

\n\n
\n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| subject_name | varchar |\n+--------------+---------+\nsubject_name is the primary key for this table.\nEach row of this table contains the name of one subject in the school.\n
\n\n

 

\n\n

Table: Examinations

\n\n
\n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| student_id   | int     |\n| subject_name | varchar |\n+--------------+---------+\nThere is no primary key for this table. It may contain duplicates.\nEach student from the Students table takes every course from Subjects table.\nEach row of this table indicates that a student with ID student_id attended the exam of subject_name.\n
\n\n

 

\n\n

Write an SQL query to find the number of times each student attended each exam.

\n\n

Order the result table by student_id and subject_name.

\n\n

The query result format is in the following example:

\n\n
\nStudents table:\n+------------+--------------+\n| student_id | student_name |\n+------------+--------------+\n| 1          | Alice        |\n| 2          | Bob          |\n| 13         | John         |\n| 6          | Alex         |\n+------------+--------------+\nSubjects table:\n+--------------+\n| subject_name |\n+--------------+\n| Math         |\n| Physics      |\n| Programming  |\n+--------------+\nExaminations table:\n+------------+--------------+\n| student_id | subject_name |\n+------------+--------------+\n| 1          | Math         |\n| 1          | Physics      |\n| 1          | Programming  |\n| 2          | Programming  |\n| 1          | Physics      |\n| 1          | Math         |\n| 13         | Math         |\n| 13         | Programming  |\n| 13         | Physics      |\n| 2          | Math         |\n| 1          | Math         |\n+------------+--------------+\nResult table:\n+------------+--------------+--------------+----------------+\n| student_id | student_name | subject_name | attended_exams |\n+------------+--------------+--------------+----------------+\n| 1          | Alice        | Math         | 3              |\n| 1          | Alice        | Physics      | 2              |\n| 1          | Alice        | Programming  | 1              |\n| 2          | Bob          | Math         | 1              |\n| 2          | Bob          | Physics      | 0              |\n| 2          | Bob          | Programming  | 1              |\n| 6          | Alex         | Math         | 0              |\n| 6          | Alex         | Physics      | 0              |\n| 6          | Alex         | Programming  | 0              |\n| 13         | John         | Math         | 1              |\n| 13         | John         | Physics      | 1              |\n| 13         | John         | Programming  | 1              |\n+------------+--------------+--------------+----------------+\nThe result table should contain all students and all subjects.\nAlice attended Math exam 3 times, Physics exam 2 times and Programming exam 1 time.\nBob attended Math exam 1 time, Programming exam 1 time and didn't attend the Physics exam.\nAlex didn't attend any exam.\nJohn attended Math exam 1 time, Physics exam 1 time and Programming exam 1 time.\n
\n", "content_cn": "

\u5b66\u751f\u8868: Students

\n\n
+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| student_id    | int     |\n| student_name  | varchar |\n+---------------+---------+\n\u4e3b\u952e\u4e3a student_id\uff08\u5b66\u751fID\uff09\uff0c\u8be5\u8868\u5185\u7684\u6bcf\u4e00\u884c\u90fd\u8bb0\u5f55\u6709\u5b66\u6821\u4e00\u540d\u5b66\u751f\u7684\u4fe1\u606f\u3002\n
\n\n

 

\n\n

\u79d1\u76ee\u8868: Subjects

\n\n
+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| subject_name | varchar |\n+--------------+---------+\n\u4e3b\u952e\u4e3a subject_name\uff08\u79d1\u76ee\u540d\u79f0\uff09\uff0c\u6bcf\u4e00\u884c\u8bb0\u5f55\u5b66\u6821\u7684\u4e00\u95e8\u79d1\u76ee\u540d\u79f0\u3002\n
\n\n

 

\n\n

\u8003\u8bd5\u8868: Examinations

\n\n
+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| student_id   | int     |\n| subject_name | varchar |\n+--------------+---------+\n\u8fd9\u5f20\u8868\u538b\u6839\u6ca1\u6709\u4e3b\u952e\uff0c\u53ef\u80fd\u4f1a\u6709\u91cd\u590d\u884c\u3002\n\u5b66\u751f\u8868\u91cc\u7684\u4e00\u4e2a\u5b66\u751f\u4fee\u8bfb\u79d1\u76ee\u8868\u91cc\u7684\u6bcf\u4e00\u95e8\u79d1\u76ee\uff0c\u800c\u8fd9\u5f20\u8003\u8bd5\u8868\u7684\u6bcf\u4e00\u884c\u8bb0\u5f55\u5c31\u8868\u793a\u5b66\u751f\u8868\u91cc\u7684\u67d0\u4e2a\u5b66\u751f\u53c2\u52a0\u4e86\u4e00\u6b21\u79d1\u76ee\u8868\u91cc\u67d0\u95e8\u79d1\u76ee\u7684\u6d4b\u8bd5\u3002\n
\n\n

 

\n\n

\u8981\u6c42\u5199\u4e00\u6bb5 SQL \u8bed\u53e5\uff0c\u67e5\u8be2\u51fa\u6bcf\u4e2a\u5b66\u751f\u53c2\u52a0\u6bcf\u4e00\u95e8\u79d1\u76ee\u6d4b\u8bd5\u7684\u6b21\u6570\uff0c\u7ed3\u679c\u6309 student_id \u548c subject_name \u6392\u5e8f\u3002

\n\n

\u67e5\u8be2\u7ed3\u6784\u683c\u5f0f\u5982\u4e0b\u6240\u793a\uff1a

\n\n
Students table:\n+------------+--------------+\n| student_id | student_name |\n+------------+--------------+\n| 1          | Alice        |\n| 2          | Bob          |\n| 13         | John         |\n| 6          | Alex         |\n+------------+--------------+\nSubjects table:\n+--------------+\n| subject_name |\n+--------------+\n| Math         |\n| Physics      |\n| Programming  |\n+--------------+\nExaminations table:\n+------------+--------------+\n| student_id | subject_name |\n+------------+--------------+\n| 1          | Math         |\n| 1          | Physics      |\n| 1          | Programming  |\n| 2          | Programming  |\n| 1          | Physics      |\n| 1          | Math         |\n| 13         | Math         |\n| 13         | Programming  |\n| 13         | Physics      |\n| 2          | Math         |\n| 1          | Math         |\n+------------+--------------+\nResult table:\n+------------+--------------+--------------+----------------+\n| student_id | student_name | subject_name | attended_exams |\n+------------+--------------+--------------+----------------+\n| 1          | Alice        | Math         | 3              |\n| 1          | Alice        | Physics      | 2              |\n| 1          | Alice        | Programming  | 1              |\n| 2          | Bob          | Math         | 1              |\n| 2          | Bob          | Physics      | 0              |\n| 2          | Bob          | Programming  | 1              |\n| 6          | Alex         | Math         | 0              |\n| 6          | Alex         | Physics      | 0              |\n| 6          | Alex         | Programming  | 0              |\n| 13         | John         | Math         | 1              |\n| 13         | John         | Physics      | 1              |\n| 13         | John         | Programming  | 1              |\n+------------+--------------+--------------+----------------+\n\u7ed3\u679c\u8868\u9700\u5305\u542b\u6240\u6709\u5b66\u751f\u548c\u6240\u6709\u79d1\u76ee\uff08\u5373\u4fbf\u6d4b\u8bd5\u6b21\u6570\u4e3a0\uff09\uff1a\nAlice \u53c2\u52a0\u4e86 3 \u6b21\u6570\u5b66\u6d4b\u8bd5, 2 \u6b21\u7269\u7406\u6d4b\u8bd5\uff0c\u4ee5\u53ca 1 \u6b21\u7f16\u7a0b\u6d4b\u8bd5\uff1b\nBob \u53c2\u52a0\u4e86 1 \u6b21\u6570\u5b66\u6d4b\u8bd5, 1 \u6b21\u7f16\u7a0b\u6d4b\u8bd5\uff0c\u6ca1\u6709\u53c2\u52a0\u7269\u7406\u6d4b\u8bd5\uff1b\nAlex \u5565\u6d4b\u8bd5\u90fd\u6ca1\u53c2\u52a0\uff1b\nJohn  \u53c2\u52a0\u4e86\u6570\u5b66\u3001\u7269\u7406\u3001\u7f16\u7a0b\u6d4b\u8bd5\u5404 1 \u6b21\u3002\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1280](https://leetcode-cn.com/problems/students-and-examinations)", "[\u5b66\u751f\u4eec\u53c2\u52a0\u5404\u79d1\u6d4b\u8bd5\u7684\u6b21\u6570](/solution/1200-1299/1280.Students%20and%20Examinations/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1280](https://leetcode.com/problems/students-and-examinations)", "[Students and Examinations](/solution/1200-1299/1280.Students%20and%20Examinations/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1414", "frontend_question_id": "1293", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/shortest-path-in-a-grid-with-obstacles-elimination", "url_en": "https://leetcode.com/problems/shortest-path-in-a-grid-with-obstacles-elimination", "relative_path_cn": "/solution/1200-1299/1293.Shortest%20Path%20in%20a%20Grid%20with%20Obstacles%20Elimination/README.md", "relative_path_en": "/solution/1200-1299/1293.Shortest%20Path%20in%20a%20Grid%20with%20Obstacles%20Elimination/README_EN.md", "title_cn": "\u7f51\u683c\u4e2d\u7684\u6700\u77ed\u8def\u5f84", "title_en": "Shortest Path in a Grid with Obstacles Elimination", "question_title_slug": "shortest-path-in-a-grid-with-obstacles-elimination", "content_en": "

Given a m * n grid, where each cell is either 0 (empty) or 1 (obstacle). In one step, you can move up, down, left or right from and to an empty cell.

\n\n

Return the minimum number of steps to walk from the upper left corner (0, 0) to the lower right corner (m-1, n-1) given that you can eliminate at most k obstacles. If it is not possible to find such walk return -1.

\n\n

 

\n

Example 1:

\n\n
\nInput: \ngrid = \n[[0,0,0],\n [1,1,0],\n [0,0,0],\n [0,1,1],\n [0,0,0]], \nk = 1\nOutput: 6\nExplanation: \nThe shortest path without eliminating any obstacle is 10. \nThe shortest path with one obstacle elimination at position (3,2) is 6. Such path is (0,0) -> (0,1) -> (0,2) -> (1,2) -> (2,2) -> (3,2) -> (4,2).\n
\n\n

 

\n\n

Example 2:

\n\n
\nInput: \ngrid = \n[[0,1,1],\n [1,1,1],\n [1,0,0]], \nk = 1\nOutput: -1\nExplanation: \nWe need to eliminate at least two obstacles to find such a walk.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • grid.length == m
  • \n\t
  • grid[0].length == n
  • \n\t
  • 1 <= m, n <= 40
  • \n\t
  • 1 <= k <= m*n
  • \n\t
  • grid[i][j] == 0 or 1
  • \n\t
  • grid[0][0] == grid[m-1][n-1] == 0
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a m * n \u7684\u7f51\u683c\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5355\u5143\u683c\u4e0d\u662f 0\uff08\u7a7a\uff09\u5c31\u662f 1\uff08\u969c\u788d\u7269\uff09\u3002\u6bcf\u4e00\u6b65\uff0c\u60a8\u90fd\u53ef\u4ee5\u5728\u7a7a\u767d\u5355\u5143\u683c\u4e2d\u4e0a\u3001\u4e0b\u3001\u5de6\u3001\u53f3\u79fb\u52a8\u3002

\n\n

\u5982\u679c\u60a8 \u6700\u591a \u53ef\u4ee5\u6d88\u9664 k \u4e2a\u969c\u788d\u7269\uff0c\u8bf7\u627e\u51fa\u4ece\u5de6\u4e0a\u89d2 (0, 0) \u5230\u53f3\u4e0b\u89d2 (m-1, n-1) \u7684\u6700\u77ed\u8def\u5f84\uff0c\u5e76\u8fd4\u56de\u901a\u8fc7\u8be5\u8def\u5f84\u6240\u9700\u7684\u6b65\u6570\u3002\u5982\u679c\u627e\u4e0d\u5230\u8fd9\u6837\u7684\u8def\u5f84\uff0c\u5219\u8fd4\u56de -1\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a \ngrid = \n[[0,0,0],\n [1,1,0],\n [0,0,0],\n [0,1,1],\n [0,0,0]], \nk = 1\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\n\u4e0d\u6d88\u9664\u4efb\u4f55\u969c\u788d\u7684\u6700\u77ed\u8def\u5f84\u662f 10\u3002\n\u6d88\u9664\u4f4d\u7f6e (3,2) \u5904\u7684\u969c\u788d\u540e\uff0c\u6700\u77ed\u8def\u5f84\u662f 6 \u3002\u8be5\u8def\u5f84\u662f (0,0) -> (0,1) -> (0,2) -> (1,2) -> (2,2) -> (3,2) -> (4,2).\n
\n\n

 

\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a\ngrid = \n[[0,1,1],\n [1,1,1],\n [1,0,0]], \nk = 1\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\n\u6211\u4eec\u81f3\u5c11\u9700\u8981\u6d88\u9664\u4e24\u4e2a\u969c\u788d\u624d\u80fd\u627e\u5230\u8fd9\u6837\u7684\u8def\u5f84\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • grid.length == m
  • \n\t
  • grid[0].length == n
  • \n\t
  • 1 <= m, n <= 40
  • \n\t
  • 1 <= k <= m*n
  • \n\t
  • grid[i][j] == 0 or 1
  • \n\t
  • grid[0][0] == grid[m-1][n-1] == 0
  • \n
\n", "tags_en": ["Breadth-first Search"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int shortestPath(vector>& grid, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int shortestPath(int[][] grid, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def shortestPath(self, grid, k):\n \"\"\"\n :type grid: List[List[int]]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def shortestPath(self, grid: List[List[int]], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint shortestPath(int** grid, int gridSize, int* gridColSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ShortestPath(int[][] grid, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @param {number} k\n * @return {number}\n */\nvar shortestPath = function(grid, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @param {Integer} k\n# @return {Integer}\ndef shortest_path(grid, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func shortestPath(_ grid: [[Int]], _ k: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func shortestPath(grid [][]int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def shortestPath(grid: Array[Array[Int]], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun shortestPath(grid: Array, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn shortest_path(grid: Vec>, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @param Integer $k\n * @return Integer\n */\n function shortestPath($grid, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function shortestPath(grid: number[][], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (shortest-path grid k)\n (-> (listof (listof exact-integer?)) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1293](https://leetcode-cn.com/problems/shortest-path-in-a-grid-with-obstacles-elimination)", "[\u7f51\u683c\u4e2d\u7684\u6700\u77ed\u8def\u5f84](/solution/1200-1299/1293.Shortest%20Path%20in%20a%20Grid%20with%20Obstacles%20Elimination/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[1293](https://leetcode.com/problems/shortest-path-in-a-grid-with-obstacles-elimination)", "[Shortest Path in a Grid with Obstacles Elimination](/solution/1200-1299/1293.Shortest%20Path%20in%20a%20Grid%20with%20Obstacles%20Elimination/README_EN.md)", "`Breadth-first Search`", "Hard", ""]}, {"question_id": "1413", "frontend_question_id": "1292", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-side-length-of-a-square-with-sum-less-than-or-equal-to-threshold", "url_en": "https://leetcode.com/problems/maximum-side-length-of-a-square-with-sum-less-than-or-equal-to-threshold", "relative_path_cn": "/solution/1200-1299/1292.Maximum%20Side%20Length%20of%20a%20Square%20with%20Sum%20Less%20than%20or%20Equal%20to%20Threshold/README.md", "relative_path_en": "/solution/1200-1299/1292.Maximum%20Side%20Length%20of%20a%20Square%20with%20Sum%20Less%20than%20or%20Equal%20to%20Threshold/README_EN.md", "title_cn": "\u5143\u7d20\u548c\u5c0f\u4e8e\u7b49\u4e8e\u9608\u503c\u7684\u6b63\u65b9\u5f62\u7684\u6700\u5927\u8fb9\u957f", "title_en": "Maximum Side Length of a Square with Sum Less than or Equal to Threshold", "question_title_slug": "maximum-side-length-of-a-square-with-sum-less-than-or-equal-to-threshold", "content_en": "

Given a m x n matrix mat and an integer threshold. Return the maximum side-length of a square with a sum less than or equal to threshold or return 0 if there is no such square.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: mat = [[1,1,3,2,4,3,2],[1,1,3,2,4,3,2],[1,1,3,2,4,3,2]], threshold = 4\nOutput: 2\nExplanation: The maximum side length of square with sum less than 4 is 2 as shown.\n
\n\n

Example 2:

\n\n
\nInput: mat = [[2,2,2,2,2],[2,2,2,2,2],[2,2,2,2,2],[2,2,2,2,2],[2,2,2,2,2]], threshold = 1\nOutput: 0\n
\n\n

Example 3:

\n\n
\nInput: mat = [[1,1,1,1],[1,0,0,0],[1,0,0,0],[1,0,0,0]], threshold = 6\nOutput: 3\n
\n\n

Example 4:

\n\n
\nInput: mat = [[18,70],[61,1],[25,85],[14,40],[11,96],[97,96],[63,45]], threshold = 40184\nOutput: 2\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= m, n <= 300
  • \n\t
  • m == mat.length
  • \n\t
  • n == mat[i].length
  • \n\t
  • 0 <= mat[i][j] <= 10000
  • \n\t
  • 0 <= threshold <= 10^5
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5927\u5c0f\u4e3a\u00a0m x n\u00a0\u7684\u77e9\u9635\u00a0mat\u00a0\u548c\u4e00\u4e2a\u6574\u6570\u9608\u503c\u00a0threshold\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u5143\u7d20\u603b\u548c\u5c0f\u4e8e\u6216\u7b49\u4e8e\u9608\u503c\u7684\u6b63\u65b9\u5f62\u533a\u57df\u7684\u6700\u5927\u8fb9\u957f\uff1b\u5982\u679c\u6ca1\u6709\u8fd9\u6837\u7684\u6b63\u65b9\u5f62\u533a\u57df\uff0c\u5219\u8fd4\u56de 0\u00a0\u3002
\n\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1amat = [[1,1,3,2,4,3,2],[1,1,3,2,4,3,2],[1,1,3,2,4,3,2]], threshold = 4\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u603b\u548c\u5c0f\u4e8e\u6216\u7b49\u4e8e 4 \u7684\u6b63\u65b9\u5f62\u7684\u6700\u5927\u8fb9\u957f\u4e3a 2\uff0c\u5982\u56fe\u6240\u793a\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1amat = [[2,2,2,2,2],[2,2,2,2,2],[2,2,2,2,2],[2,2,2,2,2],[2,2,2,2,2]], threshold = 1\n\u8f93\u51fa\uff1a0\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1amat = [[1,1,1,1],[1,0,0,0],[1,0,0,0],[1,0,0,0]], threshold = 6\n\u8f93\u51fa\uff1a3\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1amat = [[18,70],[61,1],[25,85],[14,40],[11,96],[97,96],[63,45]], threshold = 40184\n\u8f93\u51fa\uff1a2\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= m, n <= 300
  • \n\t
  • m == mat.length
  • \n\t
  • n == mat[i].length
  • \n\t
  • 0 <= mat[i][j] <= 10000
  • \n\t
  • 0 <= threshold\u00a0<= 10^5
  • \n
\n", "tags_en": ["Array", "Binary Search"], "tags_cn": ["\u6570\u7ec4", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxSideLength(vector>& mat, int threshold) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxSideLength(int[][] mat, int threshold) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxSideLength(self, mat, threshold):\n \"\"\"\n :type mat: List[List[int]]\n :type threshold: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxSideLength(self, mat: List[List[int]], threshold: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxSideLength(int** mat, int matSize, int* matColSize, int threshold){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxSideLength(int[][] mat, int threshold) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} mat\n * @param {number} threshold\n * @return {number}\n */\nvar maxSideLength = function(mat, threshold) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} mat\n# @param {Integer} threshold\n# @return {Integer}\ndef max_side_length(mat, threshold)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxSideLength(_ mat: [[Int]], _ threshold: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxSideLength(mat [][]int, threshold int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxSideLength(mat: Array[Array[Int]], threshold: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxSideLength(mat: Array, threshold: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_side_length(mat: Vec>, threshold: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $mat\n * @param Integer $threshold\n * @return Integer\n */\n function maxSideLength($mat, $threshold) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxSideLength(mat: number[][], threshold: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-side-length mat threshold)\n (-> (listof (listof exact-integer?)) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1292](https://leetcode-cn.com/problems/maximum-side-length-of-a-square-with-sum-less-than-or-equal-to-threshold)", "[\u5143\u7d20\u548c\u5c0f\u4e8e\u7b49\u4e8e\u9608\u503c\u7684\u6b63\u65b9\u5f62\u7684\u6700\u5927\u8fb9\u957f](/solution/1200-1299/1292.Maximum%20Side%20Length%20of%20a%20Square%20with%20Sum%20Less%20than%20or%20Equal%20to%20Threshold/README.md)", "`\u6570\u7ec4`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1292](https://leetcode.com/problems/maximum-side-length-of-a-square-with-sum-less-than-or-equal-to-threshold)", "[Maximum Side Length of a Square with Sum Less than or Equal to Threshold](/solution/1200-1299/1292.Maximum%20Side%20Length%20of%20a%20Square%20with%20Sum%20Less%20than%20or%20Equal%20to%20Threshold/README_EN.md)", "`Array`,`Binary Search`", "Medium", ""]}, {"question_id": "1411", "frontend_question_id": "1290", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/convert-binary-number-in-a-linked-list-to-integer", "url_en": "https://leetcode.com/problems/convert-binary-number-in-a-linked-list-to-integer", "relative_path_cn": "/solution/1200-1299/1290.Convert%20Binary%20Number%20in%20a%20Linked%20List%20to%20Integer/README.md", "relative_path_en": "/solution/1200-1299/1290.Convert%20Binary%20Number%20in%20a%20Linked%20List%20to%20Integer/README_EN.md", "title_cn": "\u4e8c\u8fdb\u5236\u94fe\u8868\u8f6c\u6574\u6570", "title_en": "Convert Binary Number in a Linked List to Integer", "question_title_slug": "convert-binary-number-in-a-linked-list-to-integer", "content_en": "

Given head which is a reference node to a singly-linked list. The value of each node in the linked list is either 0 or 1. The linked list holds the binary representation of a number.

\r\n\r\n

Return the decimal value of the number in the linked list.

\r\n\r\n

 

\r\n

Example 1:

\r\n\"\"\r\n
\r\nInput: head = [1,0,1]\r\nOutput: 5\r\nExplanation: (101) in base 2 = (5) in base 10\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: head = [0]\r\nOutput: 0\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: head = [1]\r\nOutput: 1\r\n
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: head = [1,0,0,1,0,0,1,1,1,0,0,0,0,0,0]\r\nOutput: 18880\r\n
\r\n\r\n

Example 5:

\r\n\r\n
\r\nInput: head = [0,0]\r\nOutput: 0\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • The Linked List is not empty.
  • \r\n\t
  • Number of nodes will not exceed 30.
  • \r\n\t
  • Each node's value is either 0 or 1.
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5355\u94fe\u8868\u7684\u5f15\u7528\u7ed3\u70b9 head\u3002\u94fe\u8868\u4e2d\u6bcf\u4e2a\u7ed3\u70b9\u7684\u503c\u4e0d\u662f 0 \u5c31\u662f 1\u3002\u5df2\u77e5\u6b64\u94fe\u8868\u662f\u4e00\u4e2a\u6574\u6570\u6570\u5b57\u7684\u4e8c\u8fdb\u5236\u8868\u793a\u5f62\u5f0f\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u8be5\u94fe\u8868\u6240\u8868\u793a\u6570\u5b57\u7684 \u5341\u8fdb\u5236\u503c \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1ahead = [1,0,1]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u4e8c\u8fdb\u5236\u6570 (101) \u8f6c\u5316\u4e3a\u5341\u8fdb\u5236\u6570 (5)\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1ahead = [0]\n\u8f93\u51fa\uff1a0\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1ahead = [1]\n\u8f93\u51fa\uff1a1\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1ahead = [1,0,0,1,0,0,1,1,1,0,0,0,0,0,0]\n\u8f93\u51fa\uff1a18880\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1ahead = [0,0]\n\u8f93\u51fa\uff1a0\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u94fe\u8868\u4e0d\u4e3a\u7a7a\u3002
  • \n\t
  • \u94fe\u8868\u7684\u7ed3\u70b9\u603b\u6570\u4e0d\u8d85\u8fc7 30\u3002
  • \n\t
  • \u6bcf\u4e2a\u7ed3\u70b9\u7684\u503c\u4e0d\u662f 0 \u5c31\u662f 1\u3002
  • \n
\n", "tags_en": ["Bit Manipulation", "Linked List"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u94fe\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\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 int getDecimalValue(ListNode* head) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode(int x) { val = x; }\n * }\n */\nclass Solution {\n public int getDecimalValue(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.next = None\n\nclass Solution(object):\n def getDecimalValue(self, head):\n \"\"\"\n :type head: ListNode\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, x):\n# self.val = x\n# self.next = None\n\nclass Solution:\n def getDecimalValue(self, head: ListNode) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nint getDecimalValue(struct ListNode* head){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int x) { val = x; }\n * }\n */\npublic class Solution {\n public int GetDecimalValue(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val) {\n * this.val = val;\n * this.next = null;\n * }\n */\n/**\n * @param {ListNode} head\n * @return {number}\n */\nvar getDecimalValue = function(head) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val)\n# @val = val\n# @next = nil\n# end\n# end\n\n# @param {ListNode} head\n# @return {Integer}\ndef get_decimal_value(head)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.next = nil\n * }\n * }\n */\nclass Solution {\n func getDecimalValue(_ head: ListNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc getDecimalValue(head *ListNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(var _x: Int = 0) {\n * var next: ListNode = null\n * var x: Int = _x\n * }\n */\nobject Solution {\n def getDecimalValue(head: ListNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun getDecimalValue(head: ListNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n// \n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn get_decimal_value(head: Option>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val) { $this->val = $val; }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @return Integer\n */\n function getDecimalValue($head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction getDecimalValue(head: ListNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (get-decimal-value head)\n (-> (or/c list-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1290](https://leetcode-cn.com/problems/convert-binary-number-in-a-linked-list-to-integer)", "[\u4e8c\u8fdb\u5236\u94fe\u8868\u8f6c\u6574\u6570](/solution/1200-1299/1290.Convert%20Binary%20Number%20in%20a%20Linked%20List%20to%20Integer/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u94fe\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[1290](https://leetcode.com/problems/convert-binary-number-in-a-linked-list-to-integer)", "[Convert Binary Number in a Linked List to Integer](/solution/1200-1299/1290.Convert%20Binary%20Number%20in%20a%20Linked%20List%20to%20Integer/README_EN.md)", "`Bit Manipulation`,`Linked List`", "Easy", ""]}, {"question_id": "1410", "frontend_question_id": "1279", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/traffic-light-controlled-intersection", "url_en": "https://leetcode.com/problems/traffic-light-controlled-intersection", "relative_path_cn": "/solution/1200-1299/1279.Traffic%20Light%20Controlled%20Intersection/README.md", "relative_path_en": "/solution/1200-1299/1279.Traffic%20Light%20Controlled%20Intersection/README_EN.md", "title_cn": "\u7ea2\u7eff\u706f\u8def\u53e3", "title_en": "Traffic Light Controlled Intersection", "question_title_slug": "traffic-light-controlled-intersection", "content_en": "

There is an intersection of two roads. First road is road A where cars travel from North to South in direction 1 and from South to North in direction 2. Second road is road B where cars travel from West to East in direction 3 and from East to West in direction 4.

\n\n

\"\"

\n\n

There is a traffic light located on each road before the intersection. A traffic light can either be green or red.

\n\n
    \n\t
  1. Green means cars can cross the intersection in both directions of the road.
  2. \n\t
  3. Red means cars in both directions cannot cross the intersection and must wait until the light turns green.
  4. \n
\n\n

The traffic lights cannot be green on both roads at the same time. That means when the light is green on road A, it is red on road B and when the light is green on road B, it is red on road A.

\n\n

Initially, the traffic light is green on road A and red on road B. When the light is green on one road, all cars can cross the intersection in both directions until the light becomes green on the other road. No two cars traveling on different roads should cross at the same time.

\n\n

Design a deadlock-free traffic light controlled system at this intersection.

\n\n

Implement the function void carArrived(carId, roadId, direction, turnGreen, crossCar) where:

\n\n
    \n\t
  • carId is the id of the car that arrived.
  • \n\t
  • roadId is the id of the road that the car travels on.
  • \n\t
  • direction is the direction of the car.
  • \n\t
  • turnGreen is a function you can call to turn the traffic light to green on the current road.
  • \n\t
  • crossCar is a function you can call to let the current car cross the intersection.
  • \n
\n\n

Your answer is considered correct if it avoids cars deadlock in the intersection. Turning the light green on a road when it was already green is considered a wrong answer.

\n\n

 

\n

Example 1:

\n\n
\nInput: cars = [1,3,5,2,4], directions = [2,1,2,4,3], arrivalTimes = [10,20,30,40,50]\nOutput: [\n"Car 1 Has Passed Road A In Direction 2",    // Traffic light on road A is green, car 1 can cross the intersection.\n"Car 3 Has Passed Road A In Direction 1",    // Car 3 crosses the intersection as the light is still green.\n"Car 5 Has Passed Road A In Direction 2",    // Car 5 crosses the intersection as the light is still green.\n"Traffic Light On Road B Is Green",          // Car 2 requests green light for road B.\n"Car 2 Has Passed Road B In Direction 4",    // Car 2 crosses as the light is green on road B now.\n"Car 4 Has Passed Road B In Direction 3"     // Car 4 crosses the intersection as the light is still green.\n]\n
\n\n

Example 2:

\n\n
\nInput: cars = [1,2,3,4,5], directions = [2,4,3,3,1], arrivalTimes = [10,20,30,40,40]\nOutput: [\n"Car 1 Has Passed Road A In Direction 2",    // Traffic light on road A is green, car 1 can cross the intersection.\n"Traffic Light On Road B Is Green",          // Car 2 requests green light for road B.\n"Car 2 Has Passed Road B In Direction 4",    // Car 2 crosses as the light is green on road B now.\n"Car 3 Has Passed Road B In Direction 3",    // Car 3 crosses as the light is green on road B now.\n"Traffic Light On Road A Is Green",          // Car 5 requests green light for road A.\n"Car 5 Has Passed Road A In Direction 1",    // Car 5 crosses as the light is green on road A now.\n"Traffic Light On Road B Is Green",          // Car 4 requests green light for road B. Car 4 blocked until car 5 crosses and then traffic light is green on road B.\n"Car 4 Has Passed Road B In Direction 3"     // Car 4 crosses as the light is green on road B now.\n]\nExplanation: This is a dead-lock free scenario. Note that the scenario when car 4 crosses before turning light into green on road A and allowing car 5 to pass is also correct and Accepted scenario.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= cars.length <= 20
  • \n\t
  • cars.length = directions.length
  • \n\t
  • cars.length = arrivalTimes.length
  • \n\t
  • All values of cars are unique
  • \n\t
  • 1 <= directions[i] <= 4
  • \n\t
  • arrivalTimes is non-decreasing
  • \n
\n", "content_cn": "

\u8fd9\u662f\u4e24\u6761\u8def\u7684\u4ea4\u53c9\u8def\u53e3\u3002\u7b2c\u4e00\u6761\u8def\u662f A \u8def\uff0c\u8f66\u8f86\u53ef\u6cbf 1 \u53f7\u65b9\u5411\u7531\u5317\u5411\u5357\u884c\u9a76\uff0c\u4e5f\u53ef\u6cbf 2 \u53f7\u65b9\u5411\u7531\u5357\u5411\u5317\u884c\u9a76\u3002\u7b2c\u4e8c\u6761\u8def\u662f B \u8def\uff0c\u8f66\u8f86\u53ef\u6cbf 3 \u53f7\u65b9\u5411\u7531\u897f\u5411\u4e1c\u884c\u9a76\uff0c\u4e5f\u53ef\u6cbf 4 \u53f7\u65b9\u5411\u7531\u4e1c\u5411\u897f\u884c\u9a76\u3002

\n\n

\"\"

\n\n

\u6bcf\u6761\u8def\u5728\u8def\u53e3\u524d\u90fd\u6709\u4e00\u4e2a\u7ea2\u7eff\u706f\u3002\u7ea2\u7eff\u706f\u53ef\u4ee5\u4eae\u8d77\u7ea2\u706f\u6216\u7eff\u706f\u3002

\n\n
    \n\t
  1. \u7eff\u706f\u8868\u793a\u4e24\u4e2a\u65b9\u5411\u7684\u8f66\u8f86\u90fd\u53ef\u901a\u8fc7\u8def\u53e3\u3002
  2. \n\t
  3. \u7ea2\u706f\u8868\u793a\u4e24\u4e2a\u65b9\u5411\u7684\u8f66\u8f86\u90fd\u4e0d\u53ef\u4ee5\u901a\u8fc7\u8def\u53e3\uff0c\u5fc5\u987b\u7b49\u5f85\u7eff\u706f\u4eae\u8d77\u3002
  4. \n
\n\n

\u4e24\u6761\u8def\u4e0a\u7684\u7ea2\u7eff\u706f\u4e0d\u53ef\u4ee5\u540c\u65f6\u4e3a\u7eff\u706f\u3002\u8fd9\u610f\u5473\u7740\uff0c\u5f53 A \u8def\u4e0a\u7684\u7eff\u706f\u4eae\u8d77\u65f6\uff0cB \u8def\u4e0a\u7684\u7ea2\u706f\u4f1a\u4eae\u8d77\uff1b\u5f53 B \u8def\u4e0a\u7684\u7eff\u706f\u4eae\u8d77\u65f6\uff0cA \u8def\u4e0a\u7684\u7ea2\u706f\u4f1a\u4eae\u8d77.

\n\n

\u5f00\u59cb\u65f6\uff0cA \u8def\u4e0a\u7684\u7eff\u706f\u4eae\u8d77\uff0cB \u8def\u4e0a\u7684\u7ea2\u706f\u4eae\u8d77\u3002\u5f53\u4e00\u6761\u8def\u4e0a\u7684\u7eff\u706f\u4eae\u8d77\u65f6\uff0c\u6240\u6709\u8f66\u8f86\u90fd\u53ef\u4ee5\u4ece\u4efb\u610f\u4e24\u4e2a\u65b9\u5411\u901a\u8fc7\u8def\u53e3\uff0c\u76f4\u5230\u53e6\u4e00\u6761\u8def\u4e0a\u7684\u7eff\u706f\u4eae\u8d77\u3002\u4e0d\u540c\u8def\u4e0a\u7684\u8f66\u8f86\u4e0d\u53ef\u4ee5\u540c\u65f6\u901a\u8fc7\u8def\u53e3\u3002

\n\n

\u7ed9\u8fd9\u4e2a\u8def\u53e3\u8bbe\u8ba1\u4e00\u4e2a\u6ca1\u6709\u6b7b\u9501\u7684\u7ea2\u7eff\u706f\u63a7\u5236\u7cfb\u7edf\u3002

\n\n

\u5b9e\u73b0\u51fd\u6570 void carArrived(carId, roadId, direction, turnGreen, crossCar) :

\n\n
    \n\t
  • carId \u4e3a\u5230\u8fbe\u8f66\u8f86\u7684\u7f16\u53f7\u3002
  • \n\t
  • roadId \u4e3a\u8f66\u8f86\u6240\u5728\u9053\u8def\u7684\u7f16\u53f7\u3002
  • \n\t
  • direction \u4e3a\u8f66\u8f86\u7684\u884c\u8fdb\u65b9\u5411\u3002
  • \n\t
  • turnGreen \u662f\u4e00\u4e2a\u51fd\u6570\uff0c\u8c03\u7528\u6b64\u51fd\u6570\u4f1a\u4f7f\u5f53\u524d\u9053\u8def\u4e0a\u7684\u7eff\u706f\u4eae\u8d77\u3002
  • \n\t
  • crossCar \u662f\u4e00\u4e2a\u51fd\u6570\uff0c\u8c03\u7528\u6b64\u51fd\u6570\u4f1a\u5141\u8bb8\u8f66\u8f86\u901a\u8fc7\u8def\u53e3\u3002
  • \n
\n\n

\u5f53\u4f60\u7684\u7b54\u6848\u907f\u514d\u4e86\u8f66\u8f86\u5728\u8def\u53e3\u51fa\u73b0\u6b7b\u9501\uff0c\u6b64\u7b54\u6848\u4f1a\u88ab\u8ba4\u5b9a\u4e3a\u6b63\u786e\u7684\u3002\u5f53\u8def\u53e3\u5df2\u7ecf\u4eae\u8d77\u7eff\u706f\u65f6\u4ecd\u6253\u5f00\u7eff\u706f\uff0c\u6b64\u7b54\u6848\u4f1a\u88ab\u8ba4\u5b9a\u4e3a\u9519\u8bef\u7684\u3002

\n\n

 

\n\n

\u793a\u4f8b 1:

\n\n
\n\u8f93\u5165: cars = [1,3,5,2,4], directions = [2,1,2,4,3], arrivalTimes = [10,20,30,40,50]\n\u8f93\u51fa: [\n"Car 1 Has Passed Road A In Direction 2",    // A \u8def\u4e0a\u7684\u7ea2\u7eff\u706f\u4e3a\u7eff\u8272\uff0c1 \u53f7\u8f66\u53ef\u901a\u8fc7\u8def\u53e3\u3002\n"Car 3 Has Passed Road A In Direction 1",    // \u7ea2\u7eff\u706f\u4ecd\u4e3a\u7eff\u8272\uff0c3 \u53f7\u8f66\u901a\u8fc7\u8def\u53e3\u3002\n"Car 5 Has Passed Road A In Direction 2",    // \u7ea2\u7eff\u706f\u4ecd\u4e3a\u7eff\u8272\uff0c5 \u53f7\u8f66\u901a\u8fc7\u8def\u53e3\u3002\n"Traffic Light On Road B Is Green",          // 2 \u53f7\u8f66\u5728 B \u8def\u8bf7\u6c42\u7eff\u706f\u3002\n"Car 2 Has Passed Road B In Direction 4",    // B \u8def\u4e0a\u7684\u7eff\u706f\u73b0\u5df2\u4eae\u8d77\uff0c2 \u53f7\u8f66\u901a\u8fc7\u8def\u53e3\u3002\n"Car 4 Has Passed Road B In Direction 3"     // \u7ea2\u7eff\u706f\u4ecd\u4e3a\u7eff\u8272\uff0c4 \u53f7\u8f66\u901a\u8fc7\u8def\u53e3\u3002\n]\n
\n\n

\u793a\u4f8b 2:

\n\n
\n\u8f93\u5165: cars = [1,2,3,4,5], directions = [2,4,3,3,1], arrivalTimes = [10,20,30,40,40]\n\u8f93\u51fa: [\n"Car 1 Has Passed Road A In Direction 2",    // A \u8def\u4e0a\u7684\u7ea2\u7eff\u706f\u4e3a\u7eff\u8272\uff0c1 \u53f7\u8f66\u53ef\u901a\u8fc7\u8def\u53e3\u3002\n"Traffic Light On Road B Is Green",          // 2 \u53f7\u8f66\u5728 B \u8def\u8bf7\u6c42\u7eff\u706f\u3002\n"Car 2 Has Passed Road B In Direction 4",    // B \u8def\u4e0a\u7684\u7eff\u706f\u73b0\u5df2\u4eae\u8d77\uff0c2 \u53f7\u8f66\u901a\u8fc7\u8def\u53e3\u3002\n"Car 3 Has Passed Road B In Direction 3",    // B \u8def\u4e0a\u7684\u7eff\u706f\u73b0\u5df2\u4eae\u8d77\uff0c3 \u53f7\u8f66\u901a\u8fc7\u8def\u53e3\u3002\n"Traffic Light On Road A Is Green",          // 5 \u53f7\u8f66\u5728 A \u8def\u8bf7\u6c42\u7eff\u706f\u3002\n"Car 5 Has Passed Road A In Direction 1",    // A \u8def\u4e0a\u7684\u7eff\u706f\u73b0\u5df2\u4eae\u8d77\uff0c5 \u53f7\u8f66\u901a\u8fc7\u8def\u53e3\u3002\n"Traffic Light On Road B Is Green",          // 4 \u53f7\u8f66\u5728 B \u8def\u8bf7\u6c42\u7eff\u706f\u30024 \u53f7\u8f66\u5728\u8def\u53e3\u7b49\u706f\uff0c\u76f4\u5230 5 \u53f7\u8f66\u901a\u8fc7\u8def\u53e3\uff0cB \u8def\u7684\u7eff\u706f\u4eae\u8d77\u3002\n"Car 4 Has Passed Road B In Direction 3"     // B \u8def\u4e0a\u7684\u7eff\u706f\u73b0\u5df2\u4eae\u8d77\uff0c4 \u53f7\u8f66\u901a\u8fc7\u8def\u53e3\u3002\n]\n\u89e3\u91ca: \u8fd9\u662f\u4e00\u4e2a\u65e0\u6b7b\u9501\u7684\u65b9\u6848\u3002\u6ce8\u610f\uff0c\u5728 A \u8def\u4e0a\u7684\u7eff\u706f\u4eae\u8d77\u30015 \u53f7\u8f66\u901a\u8fc7\u524d\u8ba9 4 \u53f7\u8f66\u901a\u8fc7\uff0c\u4e5f\u662f\u4e00\u4e2a\u6b63\u786e\u4e14\u53ef\u88ab\u63a5\u53d7\u7684\u65b9\u6848\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= cars.length <= 20
  • \n\t
  • cars.length = directions.length
  • \n\t
  • cars.length = arrivalTimes.length
  • \n\t
  • cars \u4e2d\u7684\u6240\u6709\u503c\u90fd\u662f\u552f\u4e00\u7684\u3002
  • \n\t
  • 1 <= directions[i] <= 4
  • \n\t
  • arrivalTimes \u662f\u975e\u9012\u51cf\u7684\u3002
  • \n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class TrafficLight {\npublic:\n TrafficLight() {\n \n }\n\n void carArrived(\n int carId, // ID of the car\n int roadId, // ID of the road the car travels on. Can be 1 (road A) or 2 (road B)\n int direction, // Direction of the car\n function turnGreen, // Use turnGreen() to turn light to green on current road\n function crossCar // Use crossCar() to make car cross the intersection\n ) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class TrafficLight {\n\n public TrafficLight() {\n \n }\n \n public void carArrived(\n int carId, // ID of the car\n int roadId, // ID of the road the car travels on. Can be 1 (road A) or 2 (road B)\n int direction, // Direction of the car\n Runnable turnGreen, // Use turnGreen.run() to turn light to green on current road\n Runnable crossCar // Use crossCar.run() to make car cross the intersection \n ) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class TrafficLight(object):\n \n def __init__(self):\n pass\n\n def carArrived(self, carId, roadId, direction, turnGreen, crossCar):\n \"\"\"\n :type roadId: int --> // ID of the car\n :type carId: int --> // ID of the road the car travels on. Can be 1 (road A) or 2 (road B)\n :type direction: int --> // Direction of the car\n :type turnGreen: method --> // Use turnGreen() to turn light to green on current road\n :type crossCar: method --> // Use crossCar() to make car cross the intersection\n :rtype: void\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class TrafficLight:\n def __init__(self):\n pass\n\n def carArrived(\n self,\n carId: int, # ID of the car\n roadId: int, # ID of the road the car travels on. Can be 1 (road A) or 2 (road B)\n direction: int, # Direction of the car\n turnGreen: 'Callable[[], None]', # Use turnGreen() to turn light to green on current road\n crossCar: 'Callable[[], None]' # Use crossCar() to make car cross the intersection\n ) -> None:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class TrafficLight {\n \n public TrafficLight() {\n \n }\n \n public void CarArrived(\n int carId, // ID of the car\n int roadId, // ID of the road the car travels on. Can be 1 (road A) or 2 (road B)\n int direction, // Direction of the car\n Action turnGreen, // Use turnGreen() to turn light to green on current road\n Action crossCar // Use crossCar() to make car cross the intersection\n ) {\n \n }\n}", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1279](https://leetcode-cn.com/problems/traffic-light-controlled-intersection)", "[\u7ea2\u7eff\u706f\u8def\u53e3](/solution/1200-1299/1279.Traffic%20Light%20Controlled%20Intersection/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1279](https://leetcode.com/problems/traffic-light-controlled-intersection)", "[Traffic Light Controlled Intersection](/solution/1200-1299/1279.Traffic%20Light%20Controlled%20Intersection/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1409", "frontend_question_id": "1284", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-number-of-flips-to-convert-binary-matrix-to-zero-matrix", "url_en": "https://leetcode.com/problems/minimum-number-of-flips-to-convert-binary-matrix-to-zero-matrix", "relative_path_cn": "/solution/1200-1299/1284.Minimum%20Number%20of%20Flips%20to%20Convert%20Binary%20Matrix%20to%20Zero%20Matrix/README.md", "relative_path_en": "/solution/1200-1299/1284.Minimum%20Number%20of%20Flips%20to%20Convert%20Binary%20Matrix%20to%20Zero%20Matrix/README_EN.md", "title_cn": "\u8f6c\u5316\u4e3a\u5168\u96f6\u77e9\u9635\u7684\u6700\u5c11\u53cd\u8f6c\u6b21\u6570", "title_en": "Minimum Number of Flips to Convert Binary Matrix to Zero Matrix", "question_title_slug": "minimum-number-of-flips-to-convert-binary-matrix-to-zero-matrix", "content_en": "

Given a m x n binary matrix mat. In one step, you can choose one cell and flip it and all the four neighbors of it if they exist (Flip is changing 1 to 0 and 0 to 1). A pair of cells are called neighbors if they share one edge.

\n\n

Return the minimum number of steps required to convert mat to a zero matrix or -1 if you cannot.

\n\n

A binary matrix is a matrix with all cells equal to 0 or 1 only.

\n\n

A zero matrix is a matrix with all cells equal to 0.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: mat = [[0,0],[0,1]]\nOutput: 3\nExplanation: One possible solution is to flip (1, 0) then (0, 1) and finally (1, 1) as shown.\n
\n\n

Example 2:

\n\n
\nInput: mat = [[0]]\nOutput: 0\nExplanation: Given matrix is a zero matrix. We don't need to change it.\n
\n\n

Example 3:

\n\n
\nInput: mat = [[1,1,1],[1,0,1],[0,0,0]]\nOutput: 6\n
\n\n

Example 4:

\n\n
\nInput: mat = [[1,0,0],[1,0,0]]\nOutput: -1\nExplanation: Given matrix can't be a zero matrix\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • m == mat.length
  • \n\t
  • n == mat[i].length
  • \n\t
  • 1 <= m, n <= 3
  • \n\t
  • mat[i][j] is either 0 or 1.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a m x n \u7684\u4e8c\u8fdb\u5236\u77e9\u9635 mat\u3002

\n\n

\u6bcf\u4e00\u6b65\uff0c\u4f60\u53ef\u4ee5\u9009\u62e9\u4e00\u4e2a\u5355\u5143\u683c\u5e76\u5c06\u5b83\u53cd\u8f6c\uff08\u53cd\u8f6c\u8868\u793a 0 \u53d8 1 \uff0c1 \u53d8 0 \uff09\u3002\u5982\u679c\u5b58\u5728\u548c\u5b83\u76f8\u90bb\u7684\u5355\u5143\u683c\uff0c\u90a3\u4e48\u8fd9\u4e9b\u76f8\u90bb\u7684\u5355\u5143\u683c\u4e5f\u4f1a\u88ab\u53cd\u8f6c\u3002\uff08\u6ce8\uff1a\u76f8\u90bb\u7684\u4e24\u4e2a\u5355\u5143\u683c\u5171\u4eab\u540c\u4e00\u6761\u8fb9\u3002\uff09

\n\n

\u8bf7\u4f60\u8fd4\u56de\u5c06\u77e9\u9635 mat \u8f6c\u5316\u4e3a\u5168\u96f6\u77e9\u9635\u7684\u6700\u5c11\u53cd\u8f6c\u6b21\u6570\uff0c\u5982\u679c\u65e0\u6cd5\u8f6c\u5316\u4e3a\u5168\u96f6\u77e9\u9635\uff0c\u8bf7\u8fd4\u56de -1 \u3002

\n\n

\u4e8c\u8fdb\u5236\u77e9\u9635\u7684\u6bcf\u4e00\u4e2a\u683c\u5b50\u8981\u4e48\u662f 0 \u8981\u4e48\u662f 1 \u3002

\n\n

\u5168\u96f6\u77e9\u9635\u662f\u6240\u6709\u683c\u5b50\u90fd\u4e3a 0 \u7684\u77e9\u9635\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1amat = [[0,0],[0,1]]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u4e00\u4e2a\u53ef\u80fd\u7684\u89e3\u662f\u53cd\u8f6c (1, 0)\uff0c\u7136\u540e (0, 1) \uff0c\u6700\u540e\u662f (1, 1) \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1amat = [[0]]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u7ed9\u51fa\u7684\u77e9\u9635\u662f\u5168\u96f6\u77e9\u9635\uff0c\u6240\u4ee5\u4f60\u4e0d\u9700\u8981\u6539\u53d8\u5b83\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1amat = [[1,1,1],[1,0,1],[0,0,0]]\n\u8f93\u51fa\uff1a6\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1amat = [[1,0,0],[1,0,0]]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u8be5\u77e9\u9635\u65e0\u6cd5\u8f6c\u53d8\u6210\u5168\u96f6\u77e9\u9635\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • m == mat.length
  • \n\t
  • n == mat[0].length
  • \n\t
  • 1 <= m <= 3
  • \n\t
  • 1 <= n <= 3
  • \n\t
  • mat[i][j] \u662f 0 \u6216 1 \u3002
  • \n
\n", "tags_en": ["Breadth-first Search"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minFlips(vector>& mat) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minFlips(int[][] mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minFlips(self, mat):\n \"\"\"\n :type mat: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minFlips(self, mat: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minFlips(int** mat, int matSize, int* matColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinFlips(int[][] mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} mat\n * @return {number}\n */\nvar minFlips = function(mat) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} mat\n# @return {Integer}\ndef min_flips(mat)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minFlips(_ mat: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minFlips(mat [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minFlips(mat: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minFlips(mat: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_flips(mat: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $mat\n * @return Integer\n */\n function minFlips($mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minFlips(mat: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-flips mat)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1284](https://leetcode-cn.com/problems/minimum-number-of-flips-to-convert-binary-matrix-to-zero-matrix)", "[\u8f6c\u5316\u4e3a\u5168\u96f6\u77e9\u9635\u7684\u6700\u5c11\u53cd\u8f6c\u6b21\u6570](/solution/1200-1299/1284.Minimum%20Number%20of%20Flips%20to%20Convert%20Binary%20Matrix%20to%20Zero%20Matrix/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[1284](https://leetcode.com/problems/minimum-number-of-flips-to-convert-binary-matrix-to-zero-matrix)", "[Minimum Number of Flips to Convert Binary Matrix to Zero Matrix](/solution/1200-1299/1284.Minimum%20Number%20of%20Flips%20to%20Convert%20Binary%20Matrix%20to%20Zero%20Matrix/README_EN.md)", "`Breadth-first Search`", "Hard", ""]}, {"question_id": "1408", "frontend_question_id": "1283", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-the-smallest-divisor-given-a-threshold", "url_en": "https://leetcode.com/problems/find-the-smallest-divisor-given-a-threshold", "relative_path_cn": "/solution/1200-1299/1283.Find%20the%20Smallest%20Divisor%20Given%20a%20Threshold/README.md", "relative_path_en": "/solution/1200-1299/1283.Find%20the%20Smallest%20Divisor%20Given%20a%20Threshold/README_EN.md", "title_cn": "\u4f7f\u7ed3\u679c\u4e0d\u8d85\u8fc7\u9608\u503c\u7684\u6700\u5c0f\u9664\u6570", "title_en": "Find the Smallest Divisor Given a Threshold", "question_title_slug": "find-the-smallest-divisor-given-a-threshold", "content_en": "

Given an array of integers nums and an integer threshold, we will choose a positive integer divisor, divide all the array by it, and sum the division's result. Find the smallest divisor such that the result mentioned above is less than or equal to threshold.

\n\n

Each result of the division is rounded to the nearest integer greater than or equal to that element. (For example: 7/3 = 3 and 10/2 = 5).

\n\n

It is guaranteed that there will be an answer.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [1,2,5,9], threshold = 6\nOutput: 5\nExplanation: We can get a sum to 17 (1+2+5+9) if the divisor is 1. \nIf the divisor is 4 we can get a sum of 7 (1+1+2+3) and if the divisor is 5 the sum will be 5 (1+1+1+2). \n
\n\n

Example 2:

\n\n
\nInput: nums = [44,22,33,11,1], threshold = 5\nOutput: 44\n
\n\n

Example 3:

\n\n
\nInput: nums = [21212,10101,12121], threshold = 1000000\nOutput: 1\n
\n\n

Example 4:

\n\n
\nInput: nums = [2,3,5,7,11], threshold = 11\nOutput: 3\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 5 * 104
  • \n\t
  • 1 <= nums[i] <= 106
  • \n\t
  • nums.length <= threshold <= 106
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \u548c\u4e00\u4e2a\u6b63\u6574\u6570 threshold  \uff0c\u4f60\u9700\u8981\u9009\u62e9\u4e00\u4e2a\u6b63\u6574\u6570\u4f5c\u4e3a\u9664\u6570\uff0c\u7136\u540e\u5c06\u6570\u7ec4\u91cc\u6bcf\u4e2a\u6570\u90fd\u9664\u4ee5\u5b83\uff0c\u5e76\u5bf9\u9664\u6cd5\u7ed3\u679c\u6c42\u548c\u3002

\n\n

\u8bf7\u4f60\u627e\u51fa\u80fd\u591f\u4f7f\u4e0a\u8ff0\u7ed3\u679c\u5c0f\u4e8e\u7b49\u4e8e\u9608\u503c threshold \u7684\u9664\u6570\u4e2d \u6700\u5c0f \u7684\u90a3\u4e2a\u3002

\n\n

\u6bcf\u4e2a\u6570\u9664\u4ee5\u9664\u6570\u540e\u90fd\u5411\u4e0a\u53d6\u6574\uff0c\u6bd4\u65b9\u8bf4 7/3 = 3 \uff0c 10/2 = 5 \u3002

\n\n

\u9898\u76ee\u4fdd\u8bc1\u4e00\u5b9a\u6709\u89e3\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [1,2,5,9], threshold = 6\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u5982\u679c\u9664\u6570\u4e3a 1 \uff0c\u6211\u4eec\u53ef\u4ee5\u5f97\u5230\u548c\u4e3a 17 \uff081+2+5+9\uff09\u3002\n\u5982\u679c\u9664\u6570\u4e3a 4 \uff0c\u6211\u4eec\u53ef\u4ee5\u5f97\u5230\u548c\u4e3a 7 (1+1+2+3) \u3002\u5982\u679c\u9664\u6570\u4e3a 5 \uff0c\u548c\u4e3a 5 (1+1+1+2)\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [2,3,5,7,11], threshold = 11\n\u8f93\u51fa\uff1a3\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [19], threshold = 5\n\u8f93\u51fa\uff1a4\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 5 * 10^4
  • \n\t
  • 1 <= nums[i] <= 10^6
  • \n\t
  • nums.length <= threshold <= 10^6
  • \n
\n", "tags_en": ["Binary Search"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int smallestDivisor(vector& nums, int threshold) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int smallestDivisor(int[] nums, int threshold) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def smallestDivisor(self, nums, threshold):\n \"\"\"\n :type nums: List[int]\n :type threshold: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def smallestDivisor(self, nums: List[int], threshold: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint smallestDivisor(int* nums, int numsSize, int threshold){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SmallestDivisor(int[] nums, int threshold) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} threshold\n * @return {number}\n */\nvar smallestDivisor = function(nums, threshold) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} threshold\n# @return {Integer}\ndef smallest_divisor(nums, threshold)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func smallestDivisor(_ nums: [Int], _ threshold: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func smallestDivisor(nums []int, threshold int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def smallestDivisor(nums: Array[Int], threshold: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun smallestDivisor(nums: IntArray, threshold: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn smallest_divisor(nums: Vec, threshold: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $threshold\n * @return Integer\n */\n function smallestDivisor($nums, $threshold) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function smallestDivisor(nums: number[], threshold: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (smallest-divisor nums threshold)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1283](https://leetcode-cn.com/problems/find-the-smallest-divisor-given-a-threshold)", "[\u4f7f\u7ed3\u679c\u4e0d\u8d85\u8fc7\u9608\u503c\u7684\u6700\u5c0f\u9664\u6570](/solution/1200-1299/1283.Find%20the%20Smallest%20Divisor%20Given%20a%20Threshold/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1283](https://leetcode.com/problems/find-the-smallest-divisor-given-a-threshold)", "[Find the Smallest Divisor Given a Threshold](/solution/1200-1299/1283.Find%20the%20Smallest%20Divisor%20Given%20a%20Threshold/README_EN.md)", "`Binary Search`", "Medium", ""]}, {"question_id": "1407", "frontend_question_id": "1282", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/group-the-people-given-the-group-size-they-belong-to", "url_en": "https://leetcode.com/problems/group-the-people-given-the-group-size-they-belong-to", "relative_path_cn": "/solution/1200-1299/1282.Group%20the%20People%20Given%20the%20Group%20Size%20They%20Belong%20To/README.md", "relative_path_en": "/solution/1200-1299/1282.Group%20the%20People%20Given%20the%20Group%20Size%20They%20Belong%20To/README_EN.md", "title_cn": "\u7528\u6237\u5206\u7ec4", "title_en": "Group the People Given the Group Size They Belong To", "question_title_slug": "group-the-people-given-the-group-size-they-belong-to", "content_en": "

There are n people that are split into some unknown number of groups. Each person is labeled with a unique ID from 0 to n - 1.

\n\n

You are given an integer array groupSizes, where groupSizes[i] is the size of the group that person i is in. For example, if groupSizes[1] = 3, then person 1 must be in a group of size 3.

\n\n

Return a list of groups such that each person i is in a group of size groupSizes[i].

\n\n

Each person should appear in exactly one group, and every person must be in a group. If there are multiple answers, return any of them. It is guaranteed that there will be at least one valid solution for the given input.

\n\n

 

\n

Example 1:

\n\n
\nInput: groupSizes = [3,3,3,3,3,1,3]\nOutput: [[5],[0,1,2],[3,4,6]]\nExplanation: \nThe first group is [5]. The size is 1, and groupSizes[5] = 1.\nThe second group is [0,1,2]. The size is 3, and groupSizes[0] = groupSizes[1] = groupSizes[2] = 3.\nThe third group is [3,4,6]. The size is 3, and groupSizes[3] = groupSizes[4] = groupSizes[6] = 3.\nOther possible solutions are [[2,1,6],[5],[0,4,3]] and [[5],[0,6,2],[4,3,1]].\n
\n\n

Example 2:

\n\n
\nInput: groupSizes = [2,1,3,3,3,2]\nOutput: [[1],[0,5],[2,3,4]]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • groupSizes.length == n
  • \n\t
  • 1 <= n <= 500
  • \n\t
  • 1 <= groupSizes[i] <= n
  • \n
\n", "content_cn": "

\u6709 n \u4f4d\u7528\u6237\u53c2\u52a0\u6d3b\u52a8\uff0c\u4ed6\u4eec\u7684 ID \u4ece 0 \u5230 n - 1\uff0c\u6bcf\u4f4d\u7528\u6237\u90fd \u6070\u597d \u5c5e\u4e8e\u67d0\u4e00\u7528\u6237\u7ec4\u3002\u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u6570\u7ec4 groupSizes\uff0c\u5176\u4e2d\u5305\u542b\u6bcf\u4f4d\u7528\u6237\u6240\u5904\u7684\u7528\u6237\u7ec4\u7684\u5927\u5c0f\uff0c\u8bf7\u4f60\u8fd4\u56de\u7528\u6237\u5206\u7ec4\u60c5\u51b5\uff08\u5b58\u5728\u7684\u7528\u6237\u7ec4\u4ee5\u53ca\u6bcf\u4e2a\u7ec4\u4e2d\u7528\u6237\u7684 ID\uff09\u3002

\n\n

\u4f60\u53ef\u4ee5\u4efb\u4f55\u987a\u5e8f\u8fd4\u56de\u89e3\u51b3\u65b9\u6848\uff0cID \u7684\u987a\u5e8f\u4e5f\u4e0d\u53d7\u9650\u5236\u3002\u6b64\u5916\uff0c\u9898\u76ee\u7ed9\u51fa\u7684\u6570\u636e\u4fdd\u8bc1\u81f3\u5c11\u5b58\u5728\u4e00\u79cd\u89e3\u51b3\u65b9\u6848\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1agroupSizes = [3,3,3,3,3,1,3]\n\u8f93\u51fa\uff1a[[5],[0,1,2],[3,4,6]]\n\u89e3\u91ca\uff1a \n\u5176\u4ed6\u53ef\u80fd\u7684\u89e3\u51b3\u65b9\u6848\u6709 [[2,1,6],[5],[0,4,3]] \u548c [[5],[0,6,2],[4,3,1]]\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1agroupSizes = [2,1,3,3,3,2]\n\u8f93\u51fa\uff1a[[1],[0,5],[2,3,4]]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • groupSizes.length == n
  • \n\t
  • 1 <= n <= 500
  • \n\t
  • 1 <= groupSizes[i] <= n
  • \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> groupThePeople(vector& groupSizes) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> groupThePeople(int[] groupSizes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def groupThePeople(self, groupSizes):\n \"\"\"\n :type groupSizes: List[int]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def groupThePeople(self, groupSizes: List[int]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** groupThePeople(int* groupSizes, int groupSizesSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> GroupThePeople(int[] groupSizes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} groupSizes\n * @return {number[][]}\n */\nvar groupThePeople = function(groupSizes) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} group_sizes\n# @return {Integer[][]}\ndef group_the_people(group_sizes)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func groupThePeople(_ groupSizes: [Int]) -> [[Int]] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func groupThePeople(groupSizes []int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def groupThePeople(groupSizes: Array[Int]): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun groupThePeople(groupSizes: IntArray): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn group_the_people(group_sizes: Vec) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $groupSizes\n * @return Integer[][]\n */\n function groupThePeople($groupSizes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function groupThePeople(groupSizes: number[]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (group-the-people groupSizes)\n (-> (listof exact-integer?) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1282](https://leetcode-cn.com/problems/group-the-people-given-the-group-size-they-belong-to)", "[\u7528\u6237\u5206\u7ec4](/solution/1200-1299/1282.Group%20the%20People%20Given%20the%20Group%20Size%20They%20Belong%20To/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1282](https://leetcode.com/problems/group-the-people-given-the-group-size-they-belong-to)", "[Group the People Given the Group Size They Belong To](/solution/1200-1299/1282.Group%20the%20People%20Given%20the%20Group%20Size%20They%20Belong%20To/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1406", "frontend_question_id": "1281", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer", "url_en": "https://leetcode.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer", "relative_path_cn": "/solution/1200-1299/1281.Subtract%20the%20Product%20and%20Sum%20of%20Digits%20of%20an%20Integer/README.md", "relative_path_en": "/solution/1200-1299/1281.Subtract%20the%20Product%20and%20Sum%20of%20Digits%20of%20an%20Integer/README_EN.md", "title_cn": "\u6574\u6570\u7684\u5404\u4f4d\u79ef\u548c\u4e4b\u5dee", "title_en": "Subtract the Product and Sum of Digits of an Integer", "question_title_slug": "subtract-the-product-and-sum-of-digits-of-an-integer", "content_en": "Given an integer number n, return the difference between the product of its digits and the sum of its digits.\n

 

\n

Example 1:

\n\n
\nInput: n = 234\nOutput: 15 \nExplanation: \nProduct of digits = 2 * 3 * 4 = 24 \nSum of digits = 2 + 3 + 4 = 9 \nResult = 24 - 9 = 15\n
\n\n

Example 2:

\n\n
\nInput: n = 4421\nOutput: 21\nExplanation: \nProduct of digits = 4 * 4 * 2 * 1 = 32 \nSum of digits = 4 + 4 + 2 + 1 = 11 \nResult = 32 - 11 = 21\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 10^5
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n\uff0c\u8bf7\u4f60\u5e2e\u5fd9\u8ba1\u7b97\u5e76\u8fd4\u56de\u8be5\u6574\u6570\u300c\u5404\u4f4d\u6570\u5b57\u4e4b\u79ef\u300d\u4e0e\u300c\u5404\u4f4d\u6570\u5b57\u4e4b\u548c\u300d\u7684\u5dee\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1an = 234\n\u8f93\u51fa\uff1a15 \n\u89e3\u91ca\uff1a\n\u5404\u4f4d\u6570\u4e4b\u79ef = 2 * 3 * 4 = 24 \n\u5404\u4f4d\u6570\u4e4b\u548c = 2 + 3 + 4 = 9 \n\u7ed3\u679c = 24 - 9 = 15\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1an = 4421\n\u8f93\u51fa\uff1a21\n\u89e3\u91ca\uff1a \n\u5404\u4f4d\u6570\u4e4b\u79ef = 4 * 4 * 2 * 1 = 32 \n\u5404\u4f4d\u6570\u4e4b\u548c = 4 + 4 + 2 + 1 = 11 \n\u7ed3\u679c = 32 - 11 = 21\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 10^5
  • \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int subtractProductAndSum(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int subtractProductAndSum(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def subtractProductAndSum(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def subtractProductAndSum(self, n: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint subtractProductAndSum(int n){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SubtractProductAndSum(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar subtractProductAndSum = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef subtract_product_and_sum(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func subtractProductAndSum(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func subtractProductAndSum(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def subtractProductAndSum(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun subtractProductAndSum(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn subtract_product_and_sum(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function subtractProductAndSum($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function subtractProductAndSum(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (subtract-product-and-sum n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1281](https://leetcode-cn.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer)", "[\u6574\u6570\u7684\u5404\u4f4d\u79ef\u548c\u4e4b\u5dee](/solution/1200-1299/1281.Subtract%20the%20Product%20and%20Sum%20of%20Digits%20of%20an%20Integer/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[1281](https://leetcode.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer)", "[Subtract the Product and Sum of Digits of an Integer](/solution/1200-1299/1281.Subtract%20the%20Product%20and%20Sum%20of%20Digits%20of%20an%20Integer/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "1405", "frontend_question_id": "1270", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/all-people-report-to-the-given-manager", "url_en": "https://leetcode.com/problems/all-people-report-to-the-given-manager", "relative_path_cn": "/solution/1200-1299/1270.All%20People%20Report%20to%20the%20Given%20Manager/README.md", "relative_path_en": "/solution/1200-1299/1270.All%20People%20Report%20to%20the%20Given%20Manager/README_EN.md", "title_cn": "\u5411\u516c\u53f8CEO\u6c47\u62a5\u5de5\u4f5c\u7684\u6240\u6709\u4eba", "title_en": "All People Report to the Given Manager", "question_title_slug": "all-people-report-to-the-given-manager", "content_en": "

Table: Employees

\r\n\r\n
\r\n+---------------+---------+\r\n| Column Name   | Type    |\r\n+---------------+---------+\r\n| employee_id   | int     |\r\n| employee_name | varchar |\r\n| manager_id    | int     |\r\n+---------------+---------+\r\nemployee_id is the primary key for this table.\r\nEach row of this table indicates that the employee with ID employee_id and name employee_name reports his work to his/her direct manager with manager_id\r\nThe head of the company is the employee with employee_id = 1.\r\n
\r\n\r\n

 

\r\n\r\n

Write an SQL query to find employee_id of all employees that directly or indirectly report their work to the head of the company.

\r\n\r\n

The indirect relation between managers will not exceed 3 managers as the company is small.

\r\n\r\n

Return result table in any order without duplicates.

\r\n\r\n

The query result format is in the following example:

\r\n\r\n
\r\nEmployees table:\r\n+-------------+---------------+------------+\r\n| employee_id | employee_name | manager_id |\r\n+-------------+---------------+------------+\r\n| 1           | Boss          | 1          |\r\n| 3           | Alice         | 3          |\r\n| 2           | Bob           | 1          |\r\n| 4           | Daniel        | 2          |\r\n| 7           | Luis          | 4          |\r\n| 8           | Jhon          | 3          |\r\n| 9           | Angela        | 8          |\r\n| 77          | Robert        | 1          |\r\n+-------------+---------------+------------+\r\n\r\nResult table:\r\n+-------------+\r\n| employee_id |\r\n+-------------+\r\n| 2           |\r\n| 77          |\r\n| 4           |\r\n| 7           |\r\n+-------------+\r\n\r\nThe head of the company is the employee with employee_id 1.\r\nThe employees with employee_id 2 and 77 report their work directly to the head of the company.\r\nThe employee with employee_id 4 report his work indirectly to the head of the company 4 --> 2 --> 1. \r\nThe employee with employee_id 7 report his work indirectly to the head of the company 7 --> 4 --> 2 --> 1.\r\nThe employees with employee_id 3, 8 and 9 don't report their work to head of company directly or indirectly. \r\n
", "content_cn": "

\u5458\u5de5\u8868\uff1aEmployees

\n\n
+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| employee_id   | int     |\n| employee_name | varchar |\n| manager_id    | int     |\n+---------------+---------+\nemployee_id \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\u3002\n\u8fd9\u4e2a\u8868\u4e2d\u6bcf\u4e00\u884c\u4e2d\uff0cemployee_id \u8868\u793a\u804c\u5de5\u7684 ID\uff0cemployee_name \u8868\u793a\u804c\u5de5\u7684\u540d\u5b57\uff0cmanager_id \u8868\u793a\u8be5\u804c\u5de5\u6c47\u62a5\u5de5\u4f5c\u7684\u76f4\u7ebf\u7ecf\u7406\u3002\n\u8fd9\u4e2a\u516c\u53f8 CEO \u662f employee_id = 1 \u7684\u4eba\u3002\n
\n\n

 

\n\n

\u7528 SQL \u67e5\u8be2\u51fa\u6240\u6709\u76f4\u63a5\u6216\u95f4\u63a5\u5411\u516c\u53f8 CEO \u6c47\u62a5\u5de5\u4f5c\u7684\u804c\u5de5\u7684 employee_id \u3002

\n\n

\u7531\u4e8e\u516c\u53f8\u89c4\u6a21\u8f83\u5c0f\uff0c\u7ecf\u7406\u4e4b\u95f4\u7684\u95f4\u63a5\u5173\u7cfb\u4e0d\u8d85\u8fc7 3 \u4e2a\u7ecf\u7406\u3002

\n\n

\u53ef\u4ee5\u4ee5\u4efb\u4f55\u987a\u5e8f\u8fd4\u56de\u7684\u7ed3\u679c\uff0c\u4e0d\u9700\u8981\u53bb\u91cd\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u793a\u4f8b\u5982\u4e0b\uff1a

\n\n
Employees table:\n+-------------+---------------+------------+\n| employee_id | employee_name | manager_id |\n+-------------+---------------+------------+\n| 1           | Boss          | 1          |\n| 3           | Alice         | 3          |\n| 2           | Bob           | 1          |\n| 4           | Daniel        | 2          |\n| 7           | Luis          | 4          |\n| 8           | Jhon          | 3          |\n| 9           | Angela        | 8          |\n| 77          | Robert        | 1          |\n+-------------+---------------+------------+\n\nResult table:\n+-------------+\n| employee_id |\n+-------------+\n| 2           |\n| 77          |\n| 4           |\n| 7           |\n+-------------+\n\n\u516c\u53f8 CEO \u7684 employee_id \u662f 1.\nemployee_id \u662f 2 \u548c 77 \u7684\u804c\u5458\u76f4\u63a5\u6c47\u62a5\u7ed9\u516c\u53f8 CEO\u3002\nemployee_id \u662f 4 \u7684\u804c\u5458\u95f4\u63a5\u6c47\u62a5\u7ed9\u516c\u53f8 CEO 4 --> 2 --> 1 \u3002\nemployee_id \u662f 7 \u7684\u804c\u5458\u95f4\u63a5\u6c47\u62a5\u7ed9\u516c\u53f8 CEO 7 --> 4 --> 2 --> 1 \u3002\nemployee_id \u662f 3, 8 \uff0c9 \u7684\u804c\u5458\u4e0d\u4f1a\u76f4\u63a5\u6216\u95f4\u63a5\u7684\u6c47\u62a5\u7ed9\u516c\u53f8 CEO\u3002 \n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1270](https://leetcode-cn.com/problems/all-people-report-to-the-given-manager)", "[\u5411\u516c\u53f8CEO\u6c47\u62a5\u5de5\u4f5c\u7684\u6240\u6709\u4eba](/solution/1200-1299/1270.All%20People%20Report%20to%20the%20Given%20Manager/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1270](https://leetcode.com/problems/all-people-report-to-the-given-manager)", "[All People Report to the Given Manager](/solution/1200-1299/1270.All%20People%20Report%20to%20the%20Given%20Manager/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1404", "frontend_question_id": "1265", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/print-immutable-linked-list-in-reverse", "url_en": "https://leetcode.com/problems/print-immutable-linked-list-in-reverse", "relative_path_cn": "/solution/1200-1299/1265.Print%20Immutable%20Linked%20List%20in%20Reverse/README.md", "relative_path_en": "/solution/1200-1299/1265.Print%20Immutable%20Linked%20List%20in%20Reverse/README_EN.md", "title_cn": "\u9006\u5e8f\u6253\u5370\u4e0d\u53ef\u53d8\u94fe\u8868", "title_en": "Print Immutable Linked List in Reverse", "question_title_slug": "print-immutable-linked-list-in-reverse", "content_en": "

You are given an immutable linked list, print out all values of each node in reverse with the help of the following interface:

\n\n
    \n\t
  • ImmutableListNode: An interface of immutable linked list, you are given the head of the list.
  • \n
\n\n

You need to use the following functions to access the linked list (you can't access the ImmutableListNode directly):

\n\n
    \n\t
  • ImmutableListNode.printValue(): Print value of the current node.
  • \n\t
  • ImmutableListNode.getNext(): Return the next node.
  • \n
\n\n

The input is only given to initialize the linked list internally. You must solve this problem without modifying the linked list. In other words, you must operate the linked list using only the mentioned APIs.

\n\n

 

\n

Example 1:

\n\n
\nInput: head = [1,2,3,4]\nOutput: [4,3,2,1]\n
\n\n

Example 2:

\n\n
\nInput: head = [0,-4,-1,3,-5]\nOutput: [-5,3,-1,-4,0]\n
\n\n

Example 3:

\n\n
\nInput: head = [-2,0,6,4,4,-6]\nOutput: [-6,4,4,6,0,-2]\n
\n\n
    \n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The length of the linked list is between [1, 1000].
  • \n\t
  • The value of each node in the linked list is between [-1000, 1000].
  • \n
\n\n

 

\n\n

Follow up:

\n\n

Could you solve this problem in:

\n\n
    \n\t
  • Constant space complexity?
  • \n\t
  • Linear time complexity and less than linear space complexity?
  • \n
\n", "content_cn": "

\u7ed9\u60a8\u4e00\u4e2a\u4e0d\u53ef\u53d8\u7684\u94fe\u8868\uff0c\u4f7f\u7528\u4e0b\u5217\u63a5\u53e3\u9006\u5e8f\u6253\u5370\u6bcf\u4e2a\u8282\u70b9\u7684\u503c\uff1a

\n\n
    \n\t
  • ImmutableListNode: \u63cf\u8ff0\u4e0d\u53ef\u53d8\u94fe\u8868\u7684\u63a5\u53e3\uff0c\u94fe\u8868\u7684\u5934\u8282\u70b9\u5df2\u7ed9\u51fa\u3002
  • \n
\n\n

\u60a8\u9700\u8981\u4f7f\u7528\u4ee5\u4e0b\u51fd\u6570\u6765\u8bbf\u95ee\u6b64\u94fe\u8868\uff08\u60a8 \u4e0d\u80fd \u76f4\u63a5\u8bbf\u95ee ImmutableListNode\uff09\uff1a

\n\n
    \n\t
  • ImmutableListNode.printValue()\uff1a\u6253\u5370\u5f53\u524d\u8282\u70b9\u7684\u503c\u3002
  • \n\t
  • ImmutableListNode.getNext()\uff1a\u8fd4\u56de\u4e0b\u4e00\u4e2a\u8282\u70b9\u3002
  • \n
\n\n

\u8f93\u5165\u53ea\u7528\u6765\u5185\u90e8\u521d\u59cb\u5316\u94fe\u8868\u3002\u60a8\u4e0d\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539\u94fe\u8868\u89e3\u51b3\u95ee\u9898\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u60a8\u53ea\u80fd\u901a\u8fc7\u4e0a\u8ff0 API \u6765\u64cd\u4f5c\u94fe\u8868\u3002

\n\n

 

\n\n

\u8fdb\u9636\uff1a

\n\n

\u60a8\u662f\u5426\u53ef\u4ee5\uff1a

\n\n
    \n\t
  • \u4f7f\u7528\u5e38\u6570\u7ea7\u7a7a\u95f4\u590d\u6742\u5ea6\u89e3\u51b3\u95ee\u9898\uff1f
  • \n\t
  • \u4f7f\u7528\u7ebf\u6027\u7ea7\u65f6\u95f4\u590d\u6742\u5ea6\u548c\u4f4e\u4e8e\u7ebf\u6027\u7ea7\u7a7a\u95f4\u590d\u6742\u5ea6\u89e3\u51b3\u95ee\u9898\uff1f
  • \n
\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1ahead = [1,2,3,4]\n\u8f93\u51fa\uff1a[4,3,2,1]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1ahead = [0,-4,-1,3,-5]\n\u8f93\u51fa\uff1a[-5,3,-1,-4,0]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1ahead = [-2,0,6,4,4,-6]\n\u8f93\u51fa\uff1a[-6,4,4,6,0,-2]\n
\n\n
    \n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u94fe\u8868\u7684\u957f\u5ea6\u5728 [1, 1000] \u4e4b\u95f4\u3002
  • \n\t
  • \u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u5728 [-1000, 1000] \u4e4b\u95f4\u3002
  • \n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * // This is the ImmutableListNode's API interface.\n * // You should not implement it, or speculate about its implementation.\n * class ImmutableListNode {\n * public:\n * void printValue(); // print the value of the node.\n * ImmutableListNode* getNext(); // return the next node.\n * };\n */\n\nclass Solution {\npublic:\n void printLinkedListInReverse(ImmutableListNode* head) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * // This is the ImmutableListNode's API interface.\n * // You should not implement it, or speculate about its implementation.\n * interface ImmutableListNode {\n * public void printValue(); // print the value of this node.\n * public ImmutableListNode getNext(); // return the next node.\n * };\n */\n\nclass Solution {\n public void printLinkedListInReverse(ImmutableListNode head) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# \"\"\"\n# This is the ImmutableListNode's API interface.\n# You should not implement it, or speculate about its implementation.\n# \"\"\"\n# class ImmutableListNode(object):\n# def printValue(self): # print the value of this node.\n# . \"\"\"\n# :rtype None\n# \"\"\"\n#\n# def getNext(self): # return the next node.\n# . \"\"\"\n# :rtype ImmutableListNode\n# \"\"\"\n\nclass Solution(object):\n def printLinkedListInReverse(self, head):\n \"\"\"\n :type head: ImmutableListNode\n :rtype: None\n \"\"\"\n\t\t", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# \"\"\"\n# This is the ImmutableListNode's API interface.\n# You should not implement it, or speculate about its implementation.\n# \"\"\"\n# class ImmutableListNode:\n# def printValue(self) -> None: # print the value of this node.\n# def getNext(self) -> 'ImmutableListNode': # return the next node.\n\nclass Solution:\n def printLinkedListInReverse(self, head: 'ImmutableListNode') -> None:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for ImmutableListNode.\n * struct ImmutableListNode {\n * struct ImmutableListNode* (*getNext)(struct ImmutableListNode*); // return the next node.\n * void (*printValue)(struct ImmutableListNode*); // print the value of the node.\n * };\n */\n\nvoid printLinkedListInReverse(struct ImmutableListNode* head) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * // This is the ImmutableListNode's API interface.\n * // You should not implement it, or speculate about its implementation.\n * class ImmutableListNode {\n * public void PrintValue(); // print the value of this node.\n * public ImmutableListNode GetNext(); // return the next node.\n * }\n */\n\npublic class Solution {\n public void PrintLinkedListInReverse(ImmutableListNode head) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // This is the ImmutableListNode's API interface.\n * // You should not implement it, or speculate about its implementation.\n * function ImmutableListNode() {\n * @ return {void}\n * this.printValue = function() { // print the value of this node.\n * ...\n * }; \n *\n * @return {ImmutableListNode}\n * this.getNext = function() { // return the next node.\n * ...\n * };\n * };\n */\n\n/**\n * @param {ImmutableListNode} head\n * @return {void}\n */\nvar printLinkedListInReverse = function(head) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# This is the ImmutableListNode's API interface.\n# You should not implement it, or speculate about its implementation.\n#\n# class ImmutableListNode\n# def printValue()\n# . print the value of this node.\n# def end\n# \"\"\"\n#\n# def getNext()\n# . return the next node.\n# end\n# end\n\ndef printLinkedListInReverse(head)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for ImmutableListNode.\n * public class ImmutableListNode {\n * public func printValue() {}\n * public func getNext() -> ImmutableListNode? {}\n * }\n */\n\nclass Solution {\n func printLinkedListInReverse(_ head: ImmutableListNode?) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/* Below is the interface for ImmutableListNode, which is already defined for you.\n *\n * type ImmutableListNode struct {\n * \n * }\n *\n * func (this *ImmutableListNode) getNext() ImmutableListNode {\n *\t\t// return the next node.\n * }\n *\n * func (this *ImmutableListNode) printValue() {\n *\t\t// print the value of this node.\n * }\n */\n\nfunc printLinkedListInReverse(head ImmutableListNode) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * // This is the ImmutableListNode's API interface.\n * // You should not implement it, or speculate about its implementation.\n * class ImmutableListNode{\n * def printValue(): Unit = {} // print the value of this node.\n * def getNext(): ImmutableListNode = {} // return the next node.\n * };\n */\n\nobject Solution {\n def printLinkedListInReverse(head: ImmutableListNode): Unit = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * // This is the ImmutableListNode's API interface.\n * // You should not implement it, or speculate about its implementation.\n * class ImmutableListNode {\n * fun getNext(): ImmutableListNode? {} // return the next node.\n * fun printValue() {} // print the value of this node.\n * };\n */\n\nclass Solution {\n\tfun printLinkedListInReverse(head:ImmutableListNode?) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * // This is the ImmutableListNode's API interface.\n * // You should not implement it, or speculate about its implementation.\n * class ImmutableListNode {\n * public function printValue() {} // print the value of this node.\n * public function getNext() {} // return the next node.\n * };\n */\n\nclass Solution {\n /**\n * @param ImmutableListNode $head\n * @return void\n */\n function printLinkedListInReverse($head) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * // This is the ImmutableListNode's API interface.\n * // You should not implement it, or speculate about its implementation\n * class ImmutableListNode {\n * printValue() {}\n *\n * getNext(): ImmutableListNode {}\n * }\n */\n\nfunction printLinkedListInReverse(head: ImmutableListNode) {\n\t\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1265](https://leetcode-cn.com/problems/print-immutable-linked-list-in-reverse)", "[\u9006\u5e8f\u6253\u5370\u4e0d\u53ef\u53d8\u94fe\u8868](/solution/1200-1299/1265.Print%20Immutable%20Linked%20List%20in%20Reverse/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1265](https://leetcode.com/problems/print-immutable-linked-list-in-reverse)", "[Print Immutable Linked List in Reverse](/solution/1200-1299/1265.Print%20Immutable%20Linked%20List%20in%20Reverse/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1403", "frontend_question_id": "1278", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/palindrome-partitioning-iii", "url_en": "https://leetcode.com/problems/palindrome-partitioning-iii", "relative_path_cn": "/solution/1200-1299/1278.Palindrome%20Partitioning%20III/README.md", "relative_path_en": "/solution/1200-1299/1278.Palindrome%20Partitioning%20III/README_EN.md", "title_cn": "\u5206\u5272\u56de\u6587\u4e32 III", "title_en": "Palindrome Partitioning III", "question_title_slug": "palindrome-partitioning-iii", "content_en": "

You are given a string s containing lowercase letters and an integer k. You need to :

\r\n\r\n
    \r\n\t
  • First, change some characters of s to other lowercase English letters.
  • \r\n\t
  • Then divide s into k non-empty disjoint substrings such that each substring is palindrome.
  • \r\n
\r\n\r\n

Return the minimal number of characters that you need to change to divide the string.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: s = "abc", k = 2\r\nOutput: 1\r\nExplanation: You can split the string into "ab" and "c", and change 1 character in "ab" to make it palindrome.\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: s = "aabbc", k = 3\r\nOutput: 0\r\nExplanation: You can split the string into "aa", "bb" and "c", all of them are palindrome.
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: s = "leetcode", k = 8\r\nOutput: 0\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= k <= s.length <= 100.
  • \r\n\t
  • s only contains lowercase English letters.
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210\u7684\u5b57\u7b26\u4e32 s\uff0c\u548c\u4e00\u4e2a\u6574\u6570 k\u3002

\n\n

\u8bf7\u4f60\u6309\u4e0b\u9762\u7684\u8981\u6c42\u5206\u5272\u5b57\u7b26\u4e32\uff1a

\n\n
    \n\t
  • \u9996\u5148\uff0c\u4f60\u53ef\u4ee5\u5c06 s \u4e2d\u7684\u90e8\u5206\u5b57\u7b26\u4fee\u6539\u4e3a\u5176\u4ed6\u7684\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
  • \n\t
  • \u63a5\u7740\uff0c\u4f60\u9700\u8981\u628a s \u5206\u5272\u6210 k \u4e2a\u975e\u7a7a\u4e14\u4e0d\u76f8\u4ea4\u7684\u5b50\u4e32\uff0c\u5e76\u4e14\u6bcf\u4e2a\u5b50\u4e32\u90fd\u662f\u56de\u6587\u4e32\u3002
  • \n
\n\n

\u8bf7\u8fd4\u56de\u4ee5\u8fd9\u79cd\u65b9\u5f0f\u5206\u5272\u5b57\u7b26\u4e32\u6240\u9700\u4fee\u6539\u7684\u6700\u5c11\u5b57\u7b26\u6570\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1as = "abc", k = 2\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u628a\u5b57\u7b26\u4e32\u5206\u5272\u6210 "ab" \u548c "c"\uff0c\u5e76\u4fee\u6539 "ab" \u4e2d\u7684 1 \u4e2a\u5b57\u7b26\uff0c\u5c06\u5b83\u53d8\u6210\u56de\u6587\u4e32\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1as = "aabbc", k = 3\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u628a\u5b57\u7b26\u4e32\u5206\u5272\u6210 "aa"\u3001"bb" \u548c "c"\uff0c\u5b83\u4eec\u90fd\u662f\u56de\u6587\u4e32\u3002
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1as = "leetcode", k = 8\n\u8f93\u51fa\uff1a0\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= k <= s.length <= 100
  • \n\t
  • s \u4e2d\u53ea\u542b\u6709\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int palindromePartition(string s, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int palindromePartition(String s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def palindromePartition(self, s, k):\n \"\"\"\n :type s: str\n :type k: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def palindromePartition(self, s: str, k: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint palindromePartition(char * s, int k){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int PalindromePartition(string s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number} k\n * @return {number}\n */\nvar palindromePartition = function(s, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer} k\n# @return {Integer}\ndef palindrome_partition(s, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func palindromePartition(_ s: String, _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func palindromePartition(s string, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def palindromePartition(s: String, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun palindromePartition(s: String, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn palindrome_partition(s: String, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer $k\n * @return Integer\n */\n function palindromePartition($s, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function palindromePartition(s: string, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (palindrome-partition s k)\n (-> string? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1278](https://leetcode-cn.com/problems/palindrome-partitioning-iii)", "[\u5206\u5272\u56de\u6587\u4e32 III](/solution/1200-1299/1278.Palindrome%20Partitioning%20III/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1278](https://leetcode.com/problems/palindrome-partitioning-iii)", "[Palindrome Partitioning III](/solution/1200-1299/1278.Palindrome%20Partitioning%20III/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1402", "frontend_question_id": "1277", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-square-submatrices-with-all-ones", "url_en": "https://leetcode.com/problems/count-square-submatrices-with-all-ones", "relative_path_cn": "/solution/1200-1299/1277.Count%20Square%20Submatrices%20with%20All%20Ones/README.md", "relative_path_en": "/solution/1200-1299/1277.Count%20Square%20Submatrices%20with%20All%20Ones/README_EN.md", "title_cn": "\u7edf\u8ba1\u5168\u4e3a 1 \u7684\u6b63\u65b9\u5f62\u5b50\u77e9\u9635", "title_en": "Count Square Submatrices with All Ones", "question_title_slug": "count-square-submatrices-with-all-ones", "content_en": "

Given a m * n matrix of ones and zeros, return how many square submatrices have all ones.

\n\n

 

\n

Example 1:

\n\n
\nInput: matrix =\n[\n  [0,1,1,1],\n  [1,1,1,1],\n  [0,1,1,1]\n]\nOutput: 15\nExplanation: \nThere are 10 squares of side 1.\nThere are 4 squares of side 2.\nThere is  1 square of side 3.\nTotal number of squares = 10 + 4 + 1 = 15.\n
\n\n

Example 2:

\n\n
\nInput: matrix = \n[\n  [1,0,1],\n  [1,1,0],\n  [1,1,0]\n]\nOutput: 7\nExplanation: \nThere are 6 squares of side 1.  \nThere is 1 square of side 2. \nTotal number of squares = 6 + 1 = 7.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= arr.length <= 300
  • \n\t
  • 1 <= arr[0].length <= 300
  • \n\t
  • 0 <= arr[i][j] <= 1
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a m * n \u7684\u77e9\u9635\uff0c\u77e9\u9635\u4e2d\u7684\u5143\u7d20\u4e0d\u662f 0 \u5c31\u662f 1\uff0c\u8bf7\u4f60\u7edf\u8ba1\u5e76\u8fd4\u56de\u5176\u4e2d\u5b8c\u5168\u7531 1 \u7ec4\u6210\u7684 \u6b63\u65b9\u5f62 \u5b50\u77e9\u9635\u7684\u4e2a\u6570\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1amatrix =\n[\n  [0,1,1,1],\n  [1,1,1,1],\n  [0,1,1,1]\n]\n\u8f93\u51fa\uff1a15\n\u89e3\u91ca\uff1a \n\u8fb9\u957f\u4e3a 1 \u7684\u6b63\u65b9\u5f62\u6709 10 \u4e2a\u3002\n\u8fb9\u957f\u4e3a 2 \u7684\u6b63\u65b9\u5f62\u6709 4 \u4e2a\u3002\n\u8fb9\u957f\u4e3a 3 \u7684\u6b63\u65b9\u5f62\u6709 1 \u4e2a\u3002\n\u6b63\u65b9\u5f62\u7684\u603b\u6570 = 10 + 4 + 1 = 15.\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1amatrix = \n[\n  [1,0,1],\n  [1,1,0],\n  [1,1,0]\n]\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\n\u8fb9\u957f\u4e3a 1 \u7684\u6b63\u65b9\u5f62\u6709 6 \u4e2a\u3002 \n\u8fb9\u957f\u4e3a 2 \u7684\u6b63\u65b9\u5f62\u6709 1 \u4e2a\u3002\n\u6b63\u65b9\u5f62\u7684\u603b\u6570 = 6 + 1 = 7.\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= arr.length <= 300
  • \n\t
  • 1 <= arr[0].length <= 300
  • \n\t
  • 0 <= arr[i][j] <= 1
  • \n
\n", "tags_en": ["Array", "Dynamic Programming"], "tags_cn": ["\u6570\u7ec4", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countSquares(vector>& matrix) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countSquares(int[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countSquares(self, matrix):\n \"\"\"\n :type matrix: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countSquares(self, matrix: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countSquares(int** matrix, int matrixSize, int* matrixColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountSquares(int[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} matrix\n * @return {number}\n */\nvar countSquares = function(matrix) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} matrix\n# @return {Integer}\ndef count_squares(matrix)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countSquares(_ matrix: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countSquares(matrix [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countSquares(matrix: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countSquares(matrix: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_squares(matrix: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $matrix\n * @return Integer\n */\n function countSquares($matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countSquares(matrix: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-squares matrix)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1277](https://leetcode-cn.com/problems/count-square-submatrices-with-all-ones)", "[\u7edf\u8ba1\u5168\u4e3a 1 \u7684\u6b63\u65b9\u5f62\u5b50\u77e9\u9635](/solution/1200-1299/1277.Count%20Square%20Submatrices%20with%20All%20Ones/README.md)", "`\u6570\u7ec4`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1277](https://leetcode.com/problems/count-square-submatrices-with-all-ones)", "[Count Square Submatrices with All Ones](/solution/1200-1299/1277.Count%20Square%20Submatrices%20with%20All%20Ones/README_EN.md)", "`Array`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "1401", "frontend_question_id": "1276", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-burgers-with-no-waste-of-ingredients", "url_en": "https://leetcode.com/problems/number-of-burgers-with-no-waste-of-ingredients", "relative_path_cn": "/solution/1200-1299/1276.Number%20of%20Burgers%20with%20No%20Waste%20of%20Ingredients/README.md", "relative_path_en": "/solution/1200-1299/1276.Number%20of%20Burgers%20with%20No%20Waste%20of%20Ingredients/README_EN.md", "title_cn": "\u4e0d\u6d6a\u8d39\u539f\u6599\u7684\u6c49\u5821\u5236\u4f5c\u65b9\u6848", "title_en": "Number of Burgers with No Waste of Ingredients", "question_title_slug": "number-of-burgers-with-no-waste-of-ingredients", "content_en": "

Given two integers tomatoSlices and cheeseSlices. The ingredients of different burgers are as follows:

\r\n\r\n
    \r\n\t
  • Jumbo Burger: 4 tomato slices and 1 cheese slice.
  • \r\n\t
  • Small Burger: 2 Tomato slices and 1 cheese slice.
  • \r\n
\r\n\r\n

Return [total_jumbo, total_small] so that the number of remaining tomatoSlices equal to 0 and the number of remaining cheeseSlices equal to 0. If it is not possible to make the remaining tomatoSlices and cheeseSlices equal to 0 return [].

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: tomatoSlices = 16, cheeseSlices = 7\r\nOutput: [1,6]\r\nExplantion: To make one jumbo burger and 6 small burgers we need 4*1 + 2*6 = 16 tomato and 1 + 6 = 7 cheese. There will be no remaining ingredients.\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: tomatoSlices = 17, cheeseSlices = 4\r\nOutput: []\r\nExplantion: There will be no way to use all ingredients to make small and jumbo burgers.\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: tomatoSlices = 4, cheeseSlices = 17\r\nOutput: []\r\nExplantion: Making 1 jumbo burger there will be 16 cheese remaining and making 2 small burgers there will be 15 cheese remaining.\r\n
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: tomatoSlices = 0, cheeseSlices = 0\r\nOutput: [0,0]\r\n
\r\n\r\n

Example 5:

\r\n\r\n
\r\nInput: tomatoSlices = 2, cheeseSlices = 1\r\nOutput: [0,1]\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 0 <= tomatoSlices <= 10^7
  • \r\n\t
  • 0 <= cheeseSlices <= 10^7
  • \r\n
", "content_cn": "

\u5723\u8bde\u6d3b\u52a8\u9884\u70ed\u5f00\u59cb\u5566\uff0c\u6c49\u5821\u5e97\u63a8\u51fa\u4e86\u5168\u65b0\u7684\u6c49\u5821\u5957\u9910\u3002\u4e3a\u4e86\u907f\u514d\u6d6a\u8d39\u539f\u6599\uff0c\u8bf7\u4f60\u5e2e\u4ed6\u4eec\u5236\u5b9a\u5408\u9002\u7684\u5236\u4f5c\u8ba1\u5212\u3002

\n\n

\u7ed9\u4f60\u4e24\u4e2a\u6574\u6570 tomatoSlices \u548c cheeseSlices\uff0c\u5206\u522b\u8868\u793a\u756a\u8304\u7247\u548c\u5976\u916a\u7247\u7684\u6570\u76ee\u3002\u4e0d\u540c\u6c49\u5821\u7684\u539f\u6599\u642d\u914d\u5982\u4e0b\uff1a

\n\n
    \n\t
  • \u5de8\u65e0\u9738\u6c49\u5821\uff1a4 \u7247\u756a\u8304\u548c 1 \u7247\u5976\u916a
  • \n\t
  • \u5c0f\u7687\u5821\uff1a2 \u7247\u756a\u8304\u548c 1 \u7247\u5976\u916a
  • \n
\n\n

\u8bf7\u4f60\u4ee5 [total_jumbo, total_small]\uff08[\u5de8\u65e0\u9738\u6c49\u5821\u603b\u6570\uff0c\u5c0f\u7687\u5821\u603b\u6570]\uff09\u7684\u683c\u5f0f\u8fd4\u56de\u6070\u5f53\u7684\u5236\u4f5c\u65b9\u6848\uff0c\u4f7f\u5f97\u5269\u4e0b\u7684\u756a\u8304\u7247 tomatoSlices \u548c\u5976\u916a\u7247 cheeseSlices \u7684\u6570\u91cf\u90fd\u662f 0\u3002

\n\n

\u5982\u679c\u65e0\u6cd5\u4f7f\u5269\u4e0b\u7684\u756a\u8304\u7247 tomatoSlices \u548c\u5976\u916a\u7247 cheeseSlices \u7684\u6570\u91cf\u4e3a 0\uff0c\u5c31\u8bf7\u8fd4\u56de []\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1atomatoSlices = 16, cheeseSlices = 7\n\u8f93\u51fa\uff1a[1,6]\n\u89e3\u91ca\uff1a\u5236\u4f5c 1 \u4e2a\u5de8\u65e0\u9738\u6c49\u5821\u548c 6 \u4e2a\u5c0f\u7687\u5821\u9700\u8981 4*1 + 2*6 = 16 \u7247\u756a\u8304\u548c 1 + 6 = 7 \u7247\u5976\u916a\u3002\u4e0d\u4f1a\u5269\u4e0b\u539f\u6599\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1atomatoSlices = 17, cheeseSlices = 4\n\u8f93\u51fa\uff1a[]\n\u89e3\u91ca\uff1a\u53ea\u5236\u4f5c\u5c0f\u7687\u5821\u548c\u5de8\u65e0\u9738\u6c49\u5821\u65e0\u6cd5\u7528\u5149\u5168\u90e8\u539f\u6599\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1atomatoSlices = 4, cheeseSlices = 17\n\u8f93\u51fa\uff1a[]\n\u89e3\u91ca\uff1a\u5236\u4f5c 1 \u4e2a\u5de8\u65e0\u9738\u6c49\u5821\u4f1a\u5269\u4e0b 16 \u7247\u5976\u916a\uff0c\u5236\u4f5c 2 \u4e2a\u5c0f\u7687\u5821\u4f1a\u5269\u4e0b 15 \u7247\u5976\u916a\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1atomatoSlices = 0, cheeseSlices = 0\n\u8f93\u51fa\uff1a[0,0]\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1atomatoSlices = 2, cheeseSlices = 1\n\u8f93\u51fa\uff1a[0,1]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 0 <= tomatoSlices <= 10^7
  • \n\t
  • 0 <= cheeseSlices <= 10^7
  • \n
\n", "tags_en": ["Greedy", "Math"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector numOfBurgers(int tomatoSlices, int cheeseSlices) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List numOfBurgers(int tomatoSlices, int cheeseSlices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numOfBurgers(self, tomatoSlices, cheeseSlices):\n \"\"\"\n :type tomatoSlices: int\n :type cheeseSlices: int\n :rtype: List[int]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* numOfBurgers(int tomatoSlices, int cheeseSlices, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList NumOfBurgers(int tomatoSlices, int cheeseSlices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} tomatoSlices\n * @param {number} cheeseSlices\n * @return {number[]}\n */\nvar numOfBurgers = function(tomatoSlices, cheeseSlices) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} tomato_slices\n# @param {Integer} cheese_slices\n# @return {Integer[]}\ndef num_of_burgers(tomato_slices, cheese_slices)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numOfBurgers(_ tomatoSlices: Int, _ cheeseSlices: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numOfBurgers(tomatoSlices int, cheeseSlices int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numOfBurgers(tomatoSlices: Int, cheeseSlices: Int): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numOfBurgers(tomatoSlices: Int, cheeseSlices: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_of_burgers(tomato_slices: i32, cheese_slices: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $tomatoSlices\n * @param Integer $cheeseSlices\n * @return Integer[]\n */\n function numOfBurgers($tomatoSlices, $cheeseSlices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numOfBurgers(tomatoSlices: number, cheeseSlices: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-of-burgers tomatoSlices cheeseSlices)\n (-> exact-integer? exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1276](https://leetcode-cn.com/problems/number-of-burgers-with-no-waste-of-ingredients)", "[\u4e0d\u6d6a\u8d39\u539f\u6599\u7684\u6c49\u5821\u5236\u4f5c\u65b9\u6848](/solution/1200-1299/1276.Number%20of%20Burgers%20with%20No%20Waste%20of%20Ingredients/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1276](https://leetcode.com/problems/number-of-burgers-with-no-waste-of-ingredients)", "[Number of Burgers with No Waste of Ingredients](/solution/1200-1299/1276.Number%20of%20Burgers%20with%20No%20Waste%20of%20Ingredients/README_EN.md)", "`Greedy`,`Math`", "Medium", ""]}, {"question_id": "1400", "frontend_question_id": "1275", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-winner-on-a-tic-tac-toe-game", "url_en": "https://leetcode.com/problems/find-winner-on-a-tic-tac-toe-game", "relative_path_cn": "/solution/1200-1299/1275.Find%20Winner%20on%20a%20Tic%20Tac%20Toe%20Game/README.md", "relative_path_en": "/solution/1200-1299/1275.Find%20Winner%20on%20a%20Tic%20Tac%20Toe%20Game/README_EN.md", "title_cn": "\u627e\u51fa\u4e95\u5b57\u68cb\u7684\u83b7\u80dc\u8005", "title_en": "Find Winner on a Tic Tac Toe Game", "question_title_slug": "find-winner-on-a-tic-tac-toe-game", "content_en": "

Tic-tac-toe is played by two players A and B on a 3 x 3 grid.

\r\n\r\n

Here are the rules of Tic-Tac-Toe:

\r\n\r\n
    \r\n\t
  • Players take turns placing characters into empty squares (" ").
  • \r\n\t
  • The first player A always places "X" characters, while the second player B always places "O" characters.
  • \r\n\t
  • "X" and "O" characters are always placed into empty squares, never on filled ones.
  • \r\n\t
  • The game ends when there are 3 of the same (non-empty) character filling any row, column, or diagonal.
  • \r\n\t
  • The game also ends if all squares are non-empty.
  • \r\n\t
  • No more moves can be played if the game is over.
  • \r\n
\r\n\r\n

Given an array moves where each element is another array of size 2 corresponding to the row and column of the grid where they mark their respective character in the order in which A and B play.

\r\n\r\n

Return the winner of the game if it exists (A or B), in case the game ends in a draw return "Draw", if there are still movements to play return "Pending".

\r\n\r\n

You can assume that moves is valid (It follows the rules of Tic-Tac-Toe), the grid is initially empty and A will play first.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: moves = [[0,0],[2,0],[1,1],[2,1],[2,2]]\r\nOutput: "A"\r\nExplanation: "A" wins, he always plays first.\r\n"X  "    "X  "    "X  "    "X  "    "X  "\r\n"   " -> "   " -> " X " -> " X " -> " X "\r\n"   "    "O  "    "O  "    "OO "    "OOX"\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: moves = [[0,0],[1,1],[0,1],[0,2],[1,0],[2,0]]\r\nOutput: "B"\r\nExplanation: "B" wins.\r\n"X  "    "X  "    "XX "    "XXO"    "XXO"    "XXO"\r\n"   " -> " O " -> " O " -> " O " -> "XO " -> "XO " \r\n"   "    "   "    "   "    "   "    "   "    "O  "\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: moves = [[0,0],[1,1],[2,0],[1,0],[1,2],[2,1],[0,1],[0,2],[2,2]]\r\nOutput: "Draw"\r\nExplanation: The game ends in a draw since there are no moves to make.\r\n"XXO"\r\n"OOX"\r\n"XOX"\r\n
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: moves = [[0,0],[1,1]]\r\nOutput: "Pending"\r\nExplanation: The game has not finished yet.\r\n"X  "\r\n" O "\r\n"   "\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= moves.length <= 9
  • \r\n\t
  • moves[i].length == 2
  • \r\n\t
  • 0 <= moves[i][j] <= 2
  • \r\n\t
  • There are no repeated elements on moves.
  • \r\n\t
  • moves follow the rules of tic tac toe.
  • \r\n
", "content_cn": "

A \u548c B \u5728\u4e00\u4e2a 3 x 3 \u7684\u7f51\u683c\u4e0a\u73a9\u4e95\u5b57\u68cb\u3002

\n\n

\u4e95\u5b57\u68cb\u6e38\u620f\u7684\u89c4\u5219\u5982\u4e0b\uff1a

\n\n
    \n\t
  • \u73a9\u5bb6\u8f6e\u6d41\u5c06\u68cb\u5b50\u653e\u5728\u7a7a\u65b9\u683c (" ") \u4e0a\u3002
  • \n\t
  • \u7b2c\u4e00\u4e2a\u73a9\u5bb6 A \u603b\u662f\u7528 "X" \u4f5c\u4e3a\u68cb\u5b50\uff0c\u800c\u7b2c\u4e8c\u4e2a\u73a9\u5bb6 B \u603b\u662f\u7528 "O" \u4f5c\u4e3a\u68cb\u5b50\u3002
  • \n\t
  • "X" \u548c "O" \u53ea\u80fd\u653e\u5728\u7a7a\u65b9\u683c\u4e2d\uff0c\u800c\u4e0d\u80fd\u653e\u5728\u5df2\u7ecf\u88ab\u5360\u7528\u7684\u65b9\u683c\u4e0a\u3002
  • \n\t
  • \u53ea\u8981\u6709 3 \u4e2a\u76f8\u540c\u7684\uff08\u975e\u7a7a\uff09\u68cb\u5b50\u6392\u6210\u4e00\u6761\u76f4\u7ebf\uff08\u884c\u3001\u5217\u3001\u5bf9\u89d2\u7ebf\uff09\u65f6\uff0c\u6e38\u620f\u7ed3\u675f\u3002
  • \n\t
  • \u5982\u679c\u6240\u6709\u65b9\u5757\u90fd\u653e\u6ee1\u68cb\u5b50\uff08\u4e0d\u4e3a\u7a7a\uff09\uff0c\u6e38\u620f\u4e5f\u4f1a\u7ed3\u675f\u3002
  • \n\t
  • \u6e38\u620f\u7ed3\u675f\u540e\uff0c\u68cb\u5b50\u65e0\u6cd5\u518d\u8fdb\u884c\u4efb\u4f55\u79fb\u52a8\u3002
  • \n
\n\n

\u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 moves\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5143\u7d20\u662f\u5927\u5c0f\u4e3a 2 \u7684\u53e6\u4e00\u4e2a\u6570\u7ec4\uff08\u5143\u7d20\u5206\u522b\u5bf9\u5e94\u7f51\u683c\u7684\u884c\u548c\u5217\uff09\uff0c\u5b83\u6309\u7167 A \u548c B \u7684\u884c\u52a8\u987a\u5e8f\uff08\u5148 A \u540e B\uff09\u8bb0\u5f55\u4e86\u4e24\u4eba\u5404\u81ea\u7684\u68cb\u5b50\u4f4d\u7f6e\u3002

\n\n

\u5982\u679c\u6e38\u620f\u5b58\u5728\u83b7\u80dc\u8005\uff08A \u6216 B\uff09\uff0c\u5c31\u8fd4\u56de\u8be5\u6e38\u620f\u7684\u83b7\u80dc\u8005\uff1b\u5982\u679c\u6e38\u620f\u4ee5\u5e73\u5c40\u7ed3\u675f\uff0c\u5219\u8fd4\u56de "Draw"\uff1b\u5982\u679c\u4ecd\u4f1a\u6709\u884c\u52a8\uff08\u6e38\u620f\u672a\u7ed3\u675f\uff09\uff0c\u5219\u8fd4\u56de "Pending"\u3002

\n\n

\u4f60\u53ef\u4ee5\u5047\u8bbe moves \u90fd \u6709\u6548\uff08\u9075\u5faa\u4e95\u5b57\u68cb\u89c4\u5219\uff09\uff0c\u7f51\u683c\u6700\u521d\u662f\u7a7a\u7684\uff0cA \u5c06\u5148\u884c\u52a8\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1amoves = [[0,0],[2,0],[1,1],[2,1],[2,2]]\n\u8f93\u51fa\uff1a"A"\n\u89e3\u91ca\uff1a"A" \u83b7\u80dc\uff0c\u4ed6\u603b\u662f\u5148\u8d70\u3002\n"X  "    "X  "    "X  "    "X  "    "X  "\n"   " -> "   " -> " X " -> " X " -> " X "\n"   "    "O  "    "O  "    "OO "    "OOX"\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1amoves = [[0,0],[1,1],[0,1],[0,2],[1,0],[2,0]]\n\u8f93\u51fa\uff1a"B"\n\u89e3\u91ca\uff1a"B" \u83b7\u80dc\u3002\n"X  "    "X  "    "XX "    "XXO"    "XXO"    "XXO"\n"   " -> " O " -> " O " -> " O " -> "XO " -> "XO " \n"   "    "   "    "   "    "   "    "   "    "O  "\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1amoves = [[0,0],[1,1],[2,0],[1,0],[1,2],[2,1],[0,1],[0,2],[2,2]]\n\u8f93\u51fa\uff1a"Draw"\n\u8f93\u51fa\uff1a\u7531\u4e8e\u6ca1\u6709\u529e\u6cd5\u518d\u884c\u52a8\uff0c\u6e38\u620f\u4ee5\u5e73\u5c40\u7ed3\u675f\u3002\n"XXO"\n"OOX"\n"XOX"\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1amoves = [[0,0],[1,1]]\n\u8f93\u51fa\uff1a"Pending"\n\u89e3\u91ca\uff1a\u6e38\u620f\u8fd8\u6ca1\u6709\u7ed3\u675f\u3002\n"X  "\n" O "\n"   "\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= moves.length <= 9
  • \n\t
  • moves[i].length == 2
  • \n\t
  • 0 <= moves[i][j] <= 2
  • \n\t
  • moves \u91cc\u6ca1\u6709\u91cd\u590d\u7684\u5143\u7d20\u3002
  • \n\t
  • moves \u9075\u5faa\u4e95\u5b57\u68cb\u7684\u89c4\u5219\u3002
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string tictactoe(vector>& moves) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String tictactoe(int[][] moves) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def tictactoe(self, moves):\n \"\"\"\n :type moves: List[List[int]]\n :rtype: str\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def tictactoe(self, moves: List[List[int]]) -> str:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * tictactoe(int** moves, int movesSize, int* movesColSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string Tictactoe(int[][] moves) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} moves\n * @return {string}\n */\nvar tictactoe = function(moves) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} moves\n# @return {String}\ndef tictactoe(moves)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func tictactoe(_ moves: [[Int]]) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func tictactoe(moves [][]int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def tictactoe(moves: Array[Array[Int]]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun tictactoe(moves: Array): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn tictactoe(moves: Vec>) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $moves\n * @return String\n */\n function tictactoe($moves) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function tictactoe(moves: number[][]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (tictactoe moves)\n (-> (listof (listof exact-integer?)) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1275](https://leetcode-cn.com/problems/find-winner-on-a-tic-tac-toe-game)", "[\u627e\u51fa\u4e95\u5b57\u68cb\u7684\u83b7\u80dc\u8005](/solution/1200-1299/1275.Find%20Winner%20on%20a%20Tic%20Tac%20Toe%20Game/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1275](https://leetcode.com/problems/find-winner-on-a-tic-tac-toe-game)", "[Find Winner on a Tic Tac Toe Game](/solution/1200-1299/1275.Find%20Winner%20on%20a%20Tic%20Tac%20Toe%20Game/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1399", "frontend_question_id": "1264", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/page-recommendations", "url_en": "https://leetcode.com/problems/page-recommendations", "relative_path_cn": "/solution/1200-1299/1264.Page%20Recommendations/README.md", "relative_path_en": "/solution/1200-1299/1264.Page%20Recommendations/README_EN.md", "title_cn": "\u9875\u9762\u63a8\u8350", "title_en": "Page Recommendations", "question_title_slug": "page-recommendations", "content_en": "

Table: Friendship

\r\n\r\n
\r\n+---------------+---------+\r\n| Column Name   | Type    |\r\n+---------------+---------+\r\n| user1_id      | int     |\r\n| user2_id      | int     |\r\n+---------------+---------+\r\n(user1_id, user2_id) is the primary key for this table.\r\nEach row of this table indicates that there is a friendship relation between user1_id and user2_id.\r\n
\r\n\r\n

 

\r\n\r\n

Table: Likes

\r\n\r\n
\r\n+-------------+---------+\r\n| Column Name | Type    |\r\n+-------------+---------+\r\n| user_id     | int     |\r\n| page_id     | int     |\r\n+-------------+---------+\r\n(user_id, page_id) is the primary key for this table.\r\nEach row of this table indicates that user_id likes page_id.\r\n
\r\n\r\n

 

\r\n\r\n

Write an SQL query to recommend pages to the user with user_id = 1 using the pages that your friends liked. It should not recommend pages you already liked.

\r\n\r\n

Return result table in any order without duplicates.

\r\n\r\n

The query result format is in the following example:

\r\n\r\n
\r\nFriendship table:\r\n+----------+----------+\r\n| user1_id | user2_id |\r\n+----------+----------+\r\n| 1        | 2        |\r\n| 1        | 3        |\r\n| 1        | 4        |\r\n| 2        | 3        |\r\n| 2        | 4        |\r\n| 2        | 5        |\r\n| 6        | 1        |\r\n+----------+----------+\r\n \r\nLikes table:\r\n+---------+---------+\r\n| user_id | page_id |\r\n+---------+---------+\r\n| 1       | 88      |\r\n| 2       | 23      |\r\n| 3       | 24      |\r\n| 4       | 56      |\r\n| 5       | 11      |\r\n| 6       | 33      |\r\n| 2       | 77      |\r\n| 3       | 77      |\r\n| 6       | 88      |\r\n+---------+---------+\r\n\r\nResult table:\r\n+------------------+\r\n| recommended_page |\r\n+------------------+\r\n| 23               |\r\n| 24               |\r\n| 56               |\r\n| 33               |\r\n| 77               |\r\n+------------------+\r\nUser one is friend with users 2, 3, 4 and 6.\r\nSuggested pages are 23 from user 2, 24 from user 3, 56 from user 3 and 33 from user 6.\r\nPage 77 is suggested from both user 2 and user 3.\r\nPage 88 is not suggested because user 1 already likes it.\r\n
", "content_cn": "

\u670b\u53cb\u5173\u7cfb\u5217\u8868\uff1a Friendship

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| user1_id      | int     |\n| user2_id      | int     |\n+---------------+---------+\n\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\u662f (user1_id, user2_id)\u3002\n\u8fd9\u5f20\u8868\u7684\u6bcf\u4e00\u884c\u4ee3\u8868\u7740 user1_id \u548c user2_id \u4e4b\u95f4\u5b58\u5728\u7740\u670b\u53cb\u5173\u7cfb\u3002\n
\n\n

 

\n\n

\u559c\u6b22\u5217\u8868\uff1a Likes

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| user_id     | int     |\n| page_id     | int     |\n+-------------+---------+\n\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\u662f (user_id, page_id)\u3002\n\u8fd9\u5f20\u8868\u7684\u6bcf\u4e00\u884c\u4ee3\u8868\u7740 user_id \u559c\u6b22 page_id\u3002\n
\n\n

 

\n\n

\u5199\u4e00\u6bb5 SQL  \u5411user_id = 1 \u7684\u7528\u6237\uff0c\u63a8\u8350\u5176\u670b\u53cb\u4eec\u559c\u6b22\u7684\u9875\u9762\u3002\u4e0d\u8981\u63a8\u8350\u8be5\u7528\u6237\u5df2\u7ecf\u559c\u6b22\u7684\u9875\u9762\u3002

\n\n

\u4f60\u8fd4\u56de\u7684\u7ed3\u679c\u4e2d\u4e0d\u5e94\u5f53\u5305\u542b\u91cd\u590d\u9879\u3002

\n\n

\u8fd4\u56de\u7ed3\u679c\u7684\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a\uff1a

\n\n
\nFriendship table:\n+----------+----------+\n| user1_id | user2_id |\n+----------+----------+\n| 1        | 2        |\n| 1        | 3        |\n| 1        | 4        |\n| 2        | 3        |\n| 2        | 4        |\n| 2        | 5        |\n| 6        | 1        |\n+----------+----------+\n \nLikes table:\n+---------+---------+\n| user_id | page_id |\n+---------+---------+\n| 1       | 88      |\n| 2       | 23      |\n| 3       | 24      |\n| 4       | 56      |\n| 5       | 11      |\n| 6       | 33      |\n| 2       | 77      |\n| 3       | 77      |\n| 6       | 88      |\n+---------+---------+\n\nResult table:\n+------------------+\n| recommended_page |\n+------------------+\n| 23               |\n| 24               |\n| 56               |\n| 33               |\n| 77               |\n+------------------+\n\u7528\u62371 \u540c \u7528\u62372, 3, 4, 6 \u662f\u670b\u53cb\u5173\u7cfb\u3002\n\u63a8\u8350\u9875\u9762\u4e3a\uff1a \u9875\u976223 \u6765\u81ea\u4e8e \u7528\u62372, \u9875\u976224 \u6765\u81ea\u4e8e \u7528\u62373, \u9875\u976256 \u6765\u81ea\u4e8e \u7528\u62373 \u4ee5\u53ca \u9875\u976233 \u6765\u81ea\u4e8e \u7528\u62376\u3002\n\u9875\u976277 \u540c\u65f6\u88ab \u7528\u62372 \u548c \u7528\u62373 \u63a8\u8350\u3002\n\u9875\u976288 \u6ca1\u6709\u88ab\u63a8\u8350\uff0c\u56e0\u4e3a \u7528\u62371 \u5df2\u7ecf\u559c\u6b22\u4e86\u5b83\u3002\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1264](https://leetcode-cn.com/problems/page-recommendations)", "[\u9875\u9762\u63a8\u8350](/solution/1200-1299/1264.Page%20Recommendations/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1264](https://leetcode.com/problems/page-recommendations)", "[Page Recommendations](/solution/1200-1299/1264.Page%20Recommendations/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1398", "frontend_question_id": "1269", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-ways-to-stay-in-the-same-place-after-some-steps", "url_en": "https://leetcode.com/problems/number-of-ways-to-stay-in-the-same-place-after-some-steps", "relative_path_cn": "/solution/1200-1299/1269.Number%20of%20Ways%20to%20Stay%20in%20the%20Same%20Place%20After%20Some%20Steps/README.md", "relative_path_en": "/solution/1200-1299/1269.Number%20of%20Ways%20to%20Stay%20in%20the%20Same%20Place%20After%20Some%20Steps/README_EN.md", "title_cn": "\u505c\u5728\u539f\u5730\u7684\u65b9\u6848\u6570", "title_en": "Number of Ways to Stay in the Same Place After Some Steps", "question_title_slug": "number-of-ways-to-stay-in-the-same-place-after-some-steps", "content_en": "

You have a pointer at index 0 in an array of size arrLen. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).

\n\n

Given two integers steps and arrLen, return the number of ways such that your pointer still at index 0 after exactly steps steps. Since the answer may be too large, return it modulo 109 + 7.

\n\n

 

\n

Example 1:

\n\n
\nInput: steps = 3, arrLen = 2\nOutput: 4\nExplanation: There are 4 differents ways to stay at index 0 after 3 steps.\nRight, Left, Stay\nStay, Right, Left\nRight, Stay, Left\nStay, Stay, Stay\n
\n\n

Example 2:

\n\n
\nInput: steps = 2, arrLen = 4\nOutput: 2\nExplanation: There are 2 differents ways to stay at index 0 after 2 steps\nRight, Left\nStay, Stay\n
\n\n

Example 3:

\n\n
\nInput: steps = 4, arrLen = 2\nOutput: 8\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= steps <= 500
  • \n\t
  • 1 <= arrLen <= 106
  • \n
\n", "content_cn": "

\u6709\u4e00\u4e2a\u957f\u5ea6\u4e3a\u00a0arrLen\u00a0\u7684\u6570\u7ec4\uff0c\u5f00\u59cb\u6709\u4e00\u4e2a\u6307\u9488\u5728\u7d22\u5f15\u00a00 \u5904\u3002

\n\n

\u6bcf\u4e00\u6b65\u64cd\u4f5c\u4e2d\uff0c\u4f60\u53ef\u4ee5\u5c06\u6307\u9488\u5411\u5de6\u6216\u5411\u53f3\u79fb\u52a8 1 \u6b65\uff0c\u6216\u8005\u505c\u5728\u539f\u5730\uff08\u6307\u9488\u4e0d\u80fd\u88ab\u79fb\u52a8\u5230\u6570\u7ec4\u8303\u56f4\u5916\uff09\u3002

\n\n

\u7ed9\u4f60\u4e24\u4e2a\u6574\u6570\u00a0steps \u548c\u00a0arrLen \uff0c\u8bf7\u4f60\u8ba1\u7b97\u5e76\u8fd4\u56de\uff1a\u5728\u6070\u597d\u6267\u884c\u00a0steps\u00a0\u6b21\u64cd\u4f5c\u4ee5\u540e\uff0c\u6307\u9488\u4ecd\u7136\u6307\u5411\u7d22\u5f15\u00a00 \u5904\u7684\u65b9\u6848\u6570\u3002

\n\n

\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u4f1a\u5f88\u5927\uff0c\u8bf7\u8fd4\u56de\u65b9\u6848\u6570 \u6a21\u00a010^9 + 7 \u540e\u7684\u7ed3\u679c\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1asteps = 3, arrLen = 2\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a3 \u6b65\u540e\uff0c\u603b\u5171\u6709 4 \u79cd\u4e0d\u540c\u7684\u65b9\u6cd5\u53ef\u4ee5\u505c\u5728\u7d22\u5f15 0 \u5904\u3002\n\u5411\u53f3\uff0c\u5411\u5de6\uff0c\u4e0d\u52a8\n\u4e0d\u52a8\uff0c\u5411\u53f3\uff0c\u5411\u5de6\n\u5411\u53f3\uff0c\u4e0d\u52a8\uff0c\u5411\u5de6\n\u4e0d\u52a8\uff0c\u4e0d\u52a8\uff0c\u4e0d\u52a8\n
\n\n

\u793a\u4f8b\u00a0 2\uff1a

\n\n
\n\u8f93\u5165\uff1asteps = 2, arrLen = 4\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a2 \u6b65\u540e\uff0c\u603b\u5171\u6709 2 \u79cd\u4e0d\u540c\u7684\u65b9\u6cd5\u53ef\u4ee5\u505c\u5728\u7d22\u5f15 0 \u5904\u3002\n\u5411\u53f3\uff0c\u5411\u5de6\n\u4e0d\u52a8\uff0c\u4e0d\u52a8\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1asteps = 4, arrLen = 2\n\u8f93\u51fa\uff1a8\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= steps <= 500
  • \n\t
  • 1 <= arrLen <= 106
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numWays(int steps, int arrLen) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numWays(int steps, int arrLen) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numWays(self, steps, arrLen):\n \"\"\"\n :type steps: int\n :type arrLen: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numWays(self, steps: int, arrLen: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numWays(int steps, int arrLen){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumWays(int steps, int arrLen) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} steps\n * @param {number} arrLen\n * @return {number}\n */\nvar numWays = function(steps, arrLen) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} steps\n# @param {Integer} arr_len\n# @return {Integer}\ndef num_ways(steps, arr_len)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numWays(_ steps: Int, _ arrLen: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numWays(steps int, arrLen int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numWays(steps: Int, arrLen: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numWays(steps: Int, arrLen: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_ways(steps: i32, arr_len: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $steps\n * @param Integer $arrLen\n * @return Integer\n */\n function numWays($steps, $arrLen) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numWays(steps: number, arrLen: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-ways steps arrLen)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1269](https://leetcode-cn.com/problems/number-of-ways-to-stay-in-the-same-place-after-some-steps)", "[\u505c\u5728\u539f\u5730\u7684\u65b9\u6848\u6570](/solution/1200-1299/1269.Number%20of%20Ways%20to%20Stay%20in%20the%20Same%20Place%20After%20Some%20Steps/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1269](https://leetcode.com/problems/number-of-ways-to-stay-in-the-same-place-after-some-steps)", "[Number of Ways to Stay in the Same Place After Some Steps](/solution/1200-1299/1269.Number%20of%20Ways%20to%20Stay%20in%20the%20Same%20Place%20After%20Some%20Steps/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1397", "frontend_question_id": "1268", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/search-suggestions-system", "url_en": "https://leetcode.com/problems/search-suggestions-system", "relative_path_cn": "/solution/1200-1299/1268.Search%20Suggestions%20System/README.md", "relative_path_en": "/solution/1200-1299/1268.Search%20Suggestions%20System/README_EN.md", "title_cn": "\u641c\u7d22\u63a8\u8350\u7cfb\u7edf", "title_en": "Search Suggestions System", "question_title_slug": "search-suggestions-system", "content_en": "

Given an array of strings products and a string searchWord. We want to design a system that suggests at most three product names from products after each character of searchWord is typed. Suggested products should have common prefix with the searchWord. If there are more than three products with a common prefix return the three lexicographically minimums products.

\n\n

Return list of lists of the suggested products after each character of searchWord is typed. 

\n\n

 

\n

Example 1:

\n\n
\nInput: products = ["mobile","mouse","moneypot","monitor","mousepad"], searchWord = "mouse"\nOutput: [\n["mobile","moneypot","monitor"],\n["mobile","moneypot","monitor"],\n["mouse","mousepad"],\n["mouse","mousepad"],\n["mouse","mousepad"]\n]\nExplanation: products sorted lexicographically = ["mobile","moneypot","monitor","mouse","mousepad"]\nAfter typing m and mo all products match and we show user ["mobile","moneypot","monitor"]\nAfter typing mou, mous and mouse the system suggests ["mouse","mousepad"]\n
\n\n

Example 2:

\n\n
\nInput: products = ["havana"], searchWord = "havana"\nOutput: [["havana"],["havana"],["havana"],["havana"],["havana"],["havana"]]\n
\n\n

Example 3:

\n\n
\nInput: products = ["bags","baggage","banner","box","cloths"], searchWord = "bags"\nOutput: [["baggage","bags","banner"],["baggage","bags","banner"],["baggage","bags"],["bags"]]\n
\n\n

Example 4:

\n\n
\nInput: products = ["havana"], searchWord = "tatiana"\nOutput: [[],[],[],[],[],[],[]]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= products.length <= 1000
  • \n\t
  • There are no repeated elements in products.
  • \n\t
  • 1 <= Σ products[i].length <= 2 * 10^4
  • \n\t
  • All characters of products[i] are lower-case English letters.
  • \n\t
  • 1 <= searchWord.length <= 1000
  • \n\t
  • All characters of searchWord are lower-case English letters.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u4ea7\u54c1\u6570\u7ec4 products \u548c\u4e00\u4e2a\u5b57\u7b26\u4e32 searchWord \uff0cproducts  \u6570\u7ec4\u4e2d\u6bcf\u4e2a\u4ea7\u54c1\u90fd\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\u3002

\n\n

\u8bf7\u4f60\u8bbe\u8ba1\u4e00\u4e2a\u63a8\u8350\u7cfb\u7edf\uff0c\u5728\u4f9d\u6b21\u8f93\u5165\u5355\u8bcd searchWord \u7684\u6bcf\u4e00\u4e2a\u5b57\u6bcd\u540e\uff0c\u63a8\u8350 products \u6570\u7ec4\u4e2d\u524d\u7f00\u4e0e searchWord \u76f8\u540c\u7684\u6700\u591a\u4e09\u4e2a\u4ea7\u54c1\u3002\u5982\u679c\u524d\u7f00\u76f8\u540c\u7684\u53ef\u63a8\u8350\u4ea7\u54c1\u8d85\u8fc7\u4e09\u4e2a\uff0c\u8bf7\u6309\u5b57\u5178\u5e8f\u8fd4\u56de\u6700\u5c0f\u7684\u4e09\u4e2a\u3002

\n\n

\u8bf7\u4f60\u4ee5\u4e8c\u7ef4\u5217\u8868\u7684\u5f62\u5f0f\uff0c\u8fd4\u56de\u5728\u8f93\u5165 searchWord \u6bcf\u4e2a\u5b57\u6bcd\u540e\u76f8\u5e94\u7684\u63a8\u8350\u4ea7\u54c1\u7684\u5217\u8868\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aproducts = ["mobile","mouse","moneypot","monitor","mousepad"], searchWord = "mouse"\n\u8f93\u51fa\uff1a[\n["mobile","moneypot","monitor"],\n["mobile","moneypot","monitor"],\n["mouse","mousepad"],\n["mouse","mousepad"],\n["mouse","mousepad"]\n]\n\u89e3\u91ca\uff1a\u6309\u5b57\u5178\u5e8f\u6392\u5e8f\u540e\u7684\u4ea7\u54c1\u5217\u8868\u662f ["mobile","moneypot","monitor","mouse","mousepad"]\n\u8f93\u5165 m \u548c mo\uff0c\u7531\u4e8e\u6240\u6709\u4ea7\u54c1\u7684\u524d\u7f00\u90fd\u76f8\u540c\uff0c\u6240\u4ee5\u7cfb\u7edf\u8fd4\u56de\u5b57\u5178\u5e8f\u6700\u5c0f\u7684\u4e09\u4e2a\u4ea7\u54c1 ["mobile","moneypot","monitor"]\n\u8f93\u5165 mou\uff0c mous \u548c mouse \u540e\u7cfb\u7edf\u90fd\u8fd4\u56de ["mouse","mousepad"]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aproducts = ["havana"], searchWord = "havana"\n\u8f93\u51fa\uff1a[["havana"],["havana"],["havana"],["havana"],["havana"],["havana"]]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aproducts = ["bags","baggage","banner","box","cloths"], searchWord = "bags"\n\u8f93\u51fa\uff1a[["baggage","bags","banner"],["baggage","bags","banner"],["baggage","bags"],["bags"]]\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1aproducts = ["havana"], searchWord = "tatiana"\n\u8f93\u51fa\uff1a[[],[],[],[],[],[],[]]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= products.length <= 1000
  • \n\t
  • 1 <= Σ products[i].length <= 2 * 10^4
  • \n\t
  • products[i] \u4e2d\u6240\u6709\u7684\u5b57\u7b26\u90fd\u662f\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
  • \n\t
  • 1 <= searchWord.length <= 1000
  • \n\t
  • searchWord \u4e2d\u6240\u6709\u5b57\u7b26\u90fd\u662f\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> suggestedProducts(vector& products, string searchWord) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> suggestedProducts(String[] products, String searchWord) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def suggestedProducts(self, products, searchWord):\n \"\"\"\n :type products: List[str]\n :type searchWord: str\n :rtype: List[List[str]]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def suggestedProducts(self, products: List[str], searchWord: str) -> List[List[str]]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nchar *** suggestedProducts(char ** products, int productsSize, char * searchWord, int* returnSize, int** returnColumnSizes){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> SuggestedProducts(string[] products, string searchWord) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} products\n * @param {string} searchWord\n * @return {string[][]}\n */\nvar suggestedProducts = function(products, searchWord) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} products\n# @param {String} search_word\n# @return {String[][]}\ndef suggested_products(products, search_word)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func suggestedProducts(_ products: [String], _ searchWord: String) -> [[String]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func suggestedProducts(products []string, searchWord string) [][]string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def suggestedProducts(products: Array[String], searchWord: String): List[List[String]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun suggestedProducts(products: Array, searchWord: String): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn suggested_products(products: Vec, search_word: String) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $products\n * @param String $searchWord\n * @return String[][]\n */\n function suggestedProducts($products, $searchWord) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function suggestedProducts(products: string[], searchWord: string): string[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (suggested-products products searchWord)\n (-> (listof string?) string? (listof (listof string?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1268](https://leetcode-cn.com/problems/search-suggestions-system)", "[\u641c\u7d22\u63a8\u8350\u7cfb\u7edf](/solution/1200-1299/1268.Search%20Suggestions%20System/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1268](https://leetcode.com/problems/search-suggestions-system)", "[Search Suggestions System](/solution/1200-1299/1268.Search%20Suggestions%20System/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "1396", "frontend_question_id": "1267", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-servers-that-communicate", "url_en": "https://leetcode.com/problems/count-servers-that-communicate", "relative_path_cn": "/solution/1200-1299/1267.Count%20Servers%20that%20Communicate/README.md", "relative_path_en": "/solution/1200-1299/1267.Count%20Servers%20that%20Communicate/README_EN.md", "title_cn": "\u7edf\u8ba1\u53c2\u4e0e\u901a\u4fe1\u7684\u670d\u52a1\u5668", "title_en": "Count Servers that Communicate", "question_title_slug": "count-servers-that-communicate", "content_en": "

You are given a map of a server center, represented as a m * n integer matrix grid, where 1 means that on that cell there is a server and 0 means that it is no server. Two servers are said to communicate if they are on the same row or on the same column.
\n
\nReturn the number of servers that communicate with any other server.

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: grid = [[1,0],[0,1]]\nOutput: 0\nExplanation: No servers can communicate with others.
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: grid = [[1,0],[1,1]]\nOutput: 3\nExplanation: All three servers can communicate with at least one other server.\n
\n\n

Example 3:

\n\n

\"\"

\n\n
\nInput: grid = [[1,1,0,0],[0,0,1,0],[0,0,1,0],[0,0,0,1]]\nOutput: 4\nExplanation: The two servers in the first row can communicate with each other. The two servers in the third column can communicate with each other. The server at right bottom corner can't communicate with any other server.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • m == grid.length
  • \n\t
  • n == grid[i].length
  • \n\t
  • 1 <= m <= 250
  • \n\t
  • 1 <= n <= 250
  • \n\t
  • grid[i][j] == 0 or 1
  • \n
\n", "content_cn": "

\u8fd9\u91cc\u6709\u4e00\u5e45\u670d\u52a1\u5668\u5206\u5e03\u56fe\uff0c\u670d\u52a1\u5668\u7684\u4f4d\u7f6e\u6807\u8bc6\u5728 m * n \u7684\u6574\u6570\u77e9\u9635\u7f51\u683c grid \u4e2d\uff0c1 \u8868\u793a\u5355\u5143\u683c\u4e0a\u6709\u670d\u52a1\u5668\uff0c0 \u8868\u793a\u6ca1\u6709\u3002

\n\n

\u5982\u679c\u4e24\u53f0\u670d\u52a1\u5668\u4f4d\u4e8e\u540c\u4e00\u884c\u6216\u8005\u540c\u4e00\u5217\uff0c\u6211\u4eec\u5c31\u8ba4\u4e3a\u5b83\u4eec\u4e4b\u95f4\u53ef\u4ee5\u8fdb\u884c\u901a\u4fe1\u3002

\n\n

\u8bf7\u4f60\u7edf\u8ba1\u5e76\u8fd4\u56de\u80fd\u591f\u4e0e\u81f3\u5c11\u4e00\u53f0\u5176\u4ed6\u670d\u52a1\u5668\u8fdb\u884c\u901a\u4fe1\u7684\u670d\u52a1\u5668\u7684\u6570\u91cf\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1agrid = [[1,0],[0,1]]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6ca1\u6709\u4e00\u53f0\u670d\u52a1\u5668\u80fd\u4e0e\u5176\u4ed6\u670d\u52a1\u5668\u8fdb\u884c\u901a\u4fe1\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1agrid = [[1,0],[1,1]]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6240\u6709\u8fd9\u4e9b\u670d\u52a1\u5668\u90fd\u81f3\u5c11\u53ef\u4ee5\u4e0e\u4e00\u53f0\u522b\u7684\u670d\u52a1\u5668\u8fdb\u884c\u901a\u4fe1\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1agrid = [[1,1,0,0],[0,0,1,0],[0,0,1,0],[0,0,0,1]]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u7b2c\u4e00\u884c\u7684\u4e24\u53f0\u670d\u52a1\u5668\u4e92\u76f8\u901a\u4fe1\uff0c\u7b2c\u4e09\u5217\u7684\u4e24\u53f0\u670d\u52a1\u5668\u4e92\u76f8\u901a\u4fe1\uff0c\u4f46\u53f3\u4e0b\u89d2\u7684\u670d\u52a1\u5668\u65e0\u6cd5\u4e0e\u5176\u4ed6\u670d\u52a1\u5668\u901a\u4fe1\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • m == grid.length
  • \n\t
  • n == grid[i].length
  • \n\t
  • 1 <= m <= 250
  • \n\t
  • 1 <= n <= 250
  • \n\t
  • grid[i][j] == 0 or 1
  • \n
\n", "tags_en": ["Graph", "Array"], "tags_cn": ["\u56fe", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countServers(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countServers(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countServers(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countServers(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countServers(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountServers(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar countServers = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef count_servers(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countServers(_ grid: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countServers(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countServers(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countServers(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_servers(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function countServers($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countServers(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-servers grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1267](https://leetcode-cn.com/problems/count-servers-that-communicate)", "[\u7edf\u8ba1\u53c2\u4e0e\u901a\u4fe1\u7684\u670d\u52a1\u5668](/solution/1200-1299/1267.Count%20Servers%20that%20Communicate/README.md)", "`\u56fe`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1267](https://leetcode.com/problems/count-servers-that-communicate)", "[Count Servers that Communicate](/solution/1200-1299/1267.Count%20Servers%20that%20Communicate/README_EN.md)", "`Graph`,`Array`", "Medium", ""]}, {"question_id": "1395", "frontend_question_id": "1266", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-time-visiting-all-points", "url_en": "https://leetcode.com/problems/minimum-time-visiting-all-points", "relative_path_cn": "/solution/1200-1299/1266.Minimum%20Time%20Visiting%20All%20Points/README.md", "relative_path_en": "/solution/1200-1299/1266.Minimum%20Time%20Visiting%20All%20Points/README_EN.md", "title_cn": "\u8bbf\u95ee\u6240\u6709\u70b9\u7684\u6700\u5c0f\u65f6\u95f4", "title_en": "Minimum Time Visiting All Points", "question_title_slug": "minimum-time-visiting-all-points", "content_en": "

On a 2D plane, there are n points with integer coordinates points[i] = [xi, yi]. Return the minimum time in seconds to visit all the points in the order given by points.

\n\n

You can move according to these rules:

\n\n
    \n\t
  • In 1 second, you can either:\n\n\t
      \n\t\t
    • move vertically by one unit,
    • \n\t\t
    • move horizontally by one unit, or
    • \n\t\t
    • move diagonally sqrt(2) units (in other words, move one unit vertically then one unit horizontally in 1 second).
    • \n\t
    \n\t
  • \n\t
  • You have to visit the points in the same order as they appear in the array.
  • \n\t
  • You are allowed to pass through points that appear later in the order, but these do not count as visits.
  • \n
\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: points = [[1,1],[3,4],[-1,0]]\nOutput: 7\nExplanation: One optimal path is [1,1] -> [2,2] -> [3,3] -> [3,4] -> [2,3] -> [1,2] -> [0,1] -> [-1,0]   \nTime from [1,1] to [3,4] = 3 seconds \nTime from [3,4] to [-1,0] = 4 seconds\nTotal time = 7 seconds
\n\n

Example 2:

\n\n
\nInput: points = [[3,2],[-2,2]]\nOutput: 5\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • points.length == n
  • \n\t
  • 1 <= n <= 100
  • \n\t
  • points[i].length == 2
  • \n\t
  • -1000 <= points[i][0], points[i][1] <= 1000
  • \n
\n", "content_cn": "

\u5e73\u9762\u4e0a\u6709\u00a0n\u00a0\u4e2a\u70b9\uff0c\u70b9\u7684\u4f4d\u7f6e\u7528\u6574\u6570\u5750\u6807\u8868\u793a points[i] = [xi, yi] \u3002\u8bf7\u4f60\u8ba1\u7b97\u8bbf\u95ee\u6240\u6709\u8fd9\u4e9b\u70b9\u9700\u8981\u7684 \u6700\u5c0f\u65f6\u95f4\uff08\u4ee5\u79d2\u4e3a\u5355\u4f4d\uff09\u3002

\n\n

\u4f60\u9700\u8981\u6309\u7167\u4e0b\u9762\u7684\u89c4\u5219\u5728\u5e73\u9762\u4e0a\u79fb\u52a8\uff1a

\n\n
    \n\t
  • \u6bcf\u4e00\u79d2\u5185\uff0c\u4f60\u53ef\u4ee5\uff1a\n\t
      \n\t\t
    • \u6cbf\u6c34\u5e73\u65b9\u5411\u79fb\u52a8\u4e00\u4e2a\u5355\u4f4d\u957f\u5ea6\uff0c\u6216\u8005
    • \n\t\t
    • \u6cbf\u7ad6\u76f4\u65b9\u5411\u79fb\u52a8\u4e00\u4e2a\u5355\u4f4d\u957f\u5ea6\uff0c\u6216\u8005
    • \n\t\t
    • \u8de8\u8fc7\u5bf9\u89d2\u7ebf\u79fb\u52a8 sqrt(2) \u4e2a\u5355\u4f4d\u957f\u5ea6\uff08\u53ef\u4ee5\u770b\u4f5c\u5728\u4e00\u79d2\u5185\u5411\u6c34\u5e73\u548c\u7ad6\u76f4\u65b9\u5411\u5404\u79fb\u52a8\u4e00\u4e2a\u5355\u4f4d\u957f\u5ea6\uff09\u3002
    • \n\t
    \n\t
  • \n\t
  • \u5fc5\u987b\u6309\u7167\u6570\u7ec4\u4e2d\u51fa\u73b0\u7684\u987a\u5e8f\u6765\u8bbf\u95ee\u8fd9\u4e9b\u70b9\u3002
  • \n\t
  • \u5728\u8bbf\u95ee\u67d0\u4e2a\u70b9\u65f6\uff0c\u53ef\u4ee5\u7ecf\u8fc7\u8be5\u70b9\u540e\u9762\u51fa\u73b0\u7684\u70b9\uff0c\u4f46\u7ecf\u8fc7\u7684\u90a3\u4e9b\u70b9\u4e0d\u7b97\u4f5c\u6709\u6548\u8bbf\u95ee\u3002
  • \n
\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1apoints = [[1,1],[3,4],[-1,0]]\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\u4e00\u6761\u6700\u4f73\u7684\u8bbf\u95ee\u8def\u5f84\u662f\uff1a [1,1] -> [2,2] -> [3,3] -> [3,4] -> [2,3] -> [1,2] -> [0,1] -> [-1,0]   \n\u4ece [1,1] \u5230 [3,4] \u9700\u8981 3 \u79d2 \n\u4ece [3,4] \u5230 [-1,0] \u9700\u8981 4 \u79d2\n\u4e00\u5171\u9700\u8981 7 \u79d2
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1apoints = [[3,2],[-2,2]]\n\u8f93\u51fa\uff1a5\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • points.length == n
  • \n\t
  • 1 <= n\u00a0<= 100
  • \n\t
  • points[i].length == 2
  • \n\t
  • -1000\u00a0<= points[i][0], points[i][1]\u00a0<= 1000
  • \n
\n", "tags_en": ["Geometry", "Array"], "tags_cn": ["\u51e0\u4f55", "\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minTimeToVisitAllPoints(vector>& points) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minTimeToVisitAllPoints(int[][] points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minTimeToVisitAllPoints(self, points):\n \"\"\"\n :type points: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minTimeToVisitAllPoints(self, points: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minTimeToVisitAllPoints(int** points, int pointsSize, int* pointsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinTimeToVisitAllPoints(int[][] points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} points\n * @return {number}\n */\nvar minTimeToVisitAllPoints = function(points) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} points\n# @return {Integer}\ndef min_time_to_visit_all_points(points)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minTimeToVisitAllPoints(_ points: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minTimeToVisitAllPoints(points [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minTimeToVisitAllPoints(points: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minTimeToVisitAllPoints(points: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_time_to_visit_all_points(points: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $points\n * @return Integer\n */\n function minTimeToVisitAllPoints($points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minTimeToVisitAllPoints(points: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-time-to-visit-all-points points)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1266](https://leetcode-cn.com/problems/minimum-time-visiting-all-points)", "[\u8bbf\u95ee\u6240\u6709\u70b9\u7684\u6700\u5c0f\u65f6\u95f4](/solution/1200-1299/1266.Minimum%20Time%20Visiting%20All%20Points/README.md)", "`\u51e0\u4f55`,`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1266](https://leetcode.com/problems/minimum-time-visiting-all-points)", "[Minimum Time Visiting All Points](/solution/1200-1299/1266.Minimum%20Time%20Visiting%20All%20Points/README_EN.md)", "`Geometry`,`Array`", "Easy", ""]}, {"question_id": "1391", "frontend_question_id": "1426", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/counting-elements", "url_en": "https://leetcode.com/problems/counting-elements", "relative_path_cn": "/solution/1400-1499/1426.Counting%20Elements/README.md", "relative_path_en": "/solution/1400-1499/1426.Counting%20Elements/README_EN.md", "title_cn": "\u6570\u5143\u7d20", "title_en": "Counting Elements", "question_title_slug": "counting-elements", "content_en": "

Given an integer array arr, count how many elements x there are, such that x + 1 is also in arr. If there are duplicates in arr, count them separately.

\n\n

 

\n

Example 1:

\n\n
\nInput: arr = [1,2,3]\nOutput: 2\nExplanation: 1 and 2 are counted cause 2 and 3 are in arr.
\n\n

Example 2:

\n\n
\nInput: arr = [1,1,3,3,5,5,7,7]\nOutput: 0\nExplanation: No numbers are counted, cause there's no 2, 4, 6, or 8 in arr.\n
\n\n

Example 3:

\n\n
\nInput: arr = [1,3,2,3,5,0]\nOutput: 3\nExplanation: 0, 1 and 2 are counted cause 1, 2 and 3 are in arr.\n
\n\n

Example 4:

\n\n
\nInput: arr = [1,1,2,2]\nOutput: 2\nExplanation: Two 1s are counted cause 2 is in arr.\n
\n\n

Example 5:

\n\n
\nInput: arr = [1,1,2]\nOutput: 2\nExplanation: Both 1s are counted because 2 is in the array.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= arr.length <= 1000
  • \n\t
  • 0 <= arr[i] <= 1000
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr\uff0c \u5bf9\u4e8e\u5143\u7d20 x \uff0c\u53ea\u6709\u5f53 x + 1 \u4e5f\u5728\u6570\u7ec4 arr \u91cc\u65f6\uff0c\u624d\u80fd\u8bb0\u4e3a 1 \u4e2a\u6570\u3002

\n\n

\u5982\u679c\u6570\u7ec4 arr \u91cc\u6709\u91cd\u590d\u7684\u6570\uff0c\u6bcf\u4e2a\u91cd\u590d\u7684\u6570\u5355\u72ec\u8ba1\u7b97\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aarr = [1,2,3]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a1 \u548c 2 \u88ab\u8ba1\u7b97\u6b21\u6570\u56e0\u4e3a 2 \u548c 3 \u5728\u6570\u7ec4 arr \u91cc\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aarr = [1,1,3,3,5,5,7,7]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6240\u6709\u7684\u6570\u90fd\u4e0d\u7b97, \u56e0\u4e3a\u6570\u7ec4\u91cc\u6ca1\u6709 2\u30014\u30016\u30018\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aarr = [1,3,2,3,5,0]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a0\u30011\u30012 \u88ab\u8ba1\u7b97\u4e86\u56e0\u4e3a 1\u30012\u30013 \u5728\u6570\u7ec4\u91cc\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1aarr = [1,1,2,2]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u4e24\u4e2a 1 \u88ab\u8ba1\u7b97\u4e86\u56e0\u4e3a\u6709 2 \u5728\u6570\u7ec4\u91cc\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= arr.length <= 1000
  • \n\t
  • 0 <= arr[i] <= 1000
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countElements(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countElements(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countElements(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countElements(self, arr: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countElements(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountElements(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar countElements = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef count_elements(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countElements(_ arr: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countElements(arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countElements(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countElements(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_elements(arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function countElements($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countElements(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-elements arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1426](https://leetcode-cn.com/problems/counting-elements)", "[\u6570\u5143\u7d20](/solution/1400-1499/1426.Counting%20Elements/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1426](https://leetcode.com/problems/counting-elements)", "[Counting Elements](/solution/1400-1499/1426.Counting%20Elements/README_EN.md)", "`Array`", "Easy", "\ud83d\udd12"]}, {"question_id": "1390", "frontend_question_id": "1251", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/average-selling-price", "url_en": "https://leetcode.com/problems/average-selling-price", "relative_path_cn": "/solution/1200-1299/1251.Average%20Selling%20Price/README.md", "relative_path_en": "/solution/1200-1299/1251.Average%20Selling%20Price/README_EN.md", "title_cn": "\u5e73\u5747\u552e\u4ef7", "title_en": "Average Selling Price", "question_title_slug": "average-selling-price", "content_en": "

Table: Prices

\r\n\r\n
\r\n+---------------+---------+\r\n| Column Name   | Type    |\r\n+---------------+---------+\r\n| product_id    | int     |\r\n| start_date    | date    |\r\n| end_date      | date    |\r\n| price         | int     |\r\n+---------------+---------+\r\n(product_id, start_date, end_date) is the primary key for this table.\r\nEach row of this table indicates the price of the product_id in the period from start_date to end_date.\r\nFor each product_id there will be no two overlapping periods. That means there will be no two intersecting periods for the same product_id.\r\n
\r\n\r\n

 

\r\n\r\n

Table: UnitsSold

\r\n\r\n
\r\n+---------------+---------+\r\n| Column Name   | Type    |\r\n+---------------+---------+\r\n| product_id    | int     |\r\n| purchase_date | date    |\r\n| units         | int     |\r\n+---------------+---------+\r\nThere is no primary key for this table, it may contain duplicates.\r\nEach row of this table indicates the date, units and product_id of each product sold. \r\n
\r\n\r\n

 

\r\n\r\n

Write an SQL query to find the average selling price for each product.

\r\n\r\n

average_price should be rounded to 2 decimal places.

\r\n\r\n

The query result format is in the following example:

\r\n\r\n
\r\nPrices table:\r\n+------------+------------+------------+--------+\r\n| product_id | start_date | end_date   | price  |\r\n+------------+------------+------------+--------+\r\n| 1          | 2019-02-17 | 2019-02-28 | 5      |\r\n| 1          | 2019-03-01 | 2019-03-22 | 20     |\r\n| 2          | 2019-02-01 | 2019-02-20 | 15     |\r\n| 2          | 2019-02-21 | 2019-03-31 | 30     |\r\n+------------+------------+------------+--------+\r\n \r\nUnitsSold table:\r\n+------------+---------------+-------+\r\n| product_id | purchase_date | units |\r\n+------------+---------------+-------+\r\n| 1          | 2019-02-25    | 100   |\r\n| 1          | 2019-03-01    | 15    |\r\n| 2          | 2019-02-10    | 200   |\r\n| 2          | 2019-03-22    | 30    |\r\n+------------+---------------+-------+\r\n\r\nResult table:\r\n+------------+---------------+\r\n| product_id | average_price |\r\n+------------+---------------+\r\n| 1          | 6.96          |\r\n| 2          | 16.96         |\r\n+------------+---------------+\r\nAverage selling price = Total Price of Product / Number of products sold.\r\nAverage selling price for product 1 = ((100 * 5) + (15 * 20)) / 115 = 6.96\r\nAverage selling price for product 2 = ((200 * 15) + (30 * 30)) / 230 = 16.96\r\n
", "content_cn": "

Table: Prices

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| product_id    | int     |\n| start_date    | date    |\n| end_date      | date    |\n| price         | int     |\n+---------------+---------+\n(product_id\uff0cstart_date\uff0cend_date) \u662f Prices \u8868\u7684\u4e3b\u952e\u3002\nPrices \u8868\u7684\u6bcf\u4e00\u884c\u8868\u793a\u7684\u662f\u67d0\u4e2a\u4ea7\u54c1\u5728\u4e00\u6bb5\u65f6\u671f\u5185\u7684\u4ef7\u683c\u3002\n\u6bcf\u4e2a\u4ea7\u54c1\u7684\u5bf9\u5e94\u65f6\u95f4\u6bb5\u662f\u4e0d\u4f1a\u91cd\u53e0\u7684\uff0c\u8fd9\u4e5f\u610f\u5473\u7740\u540c\u4e00\u4e2a\u4ea7\u54c1\u7684\u4ef7\u683c\u65f6\u6bb5\u4e0d\u4f1a\u51fa\u73b0\u4ea4\u53c9\u3002
\n\n

 

\n\n

Table: UnitsSold

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| product_id    | int     |\n| purchase_date | date    |\n| units         | int     |\n+---------------+---------+\nUnitsSold \u8868\u6ca1\u6709\u4e3b\u952e\uff0c\u5b83\u53ef\u80fd\u5305\u542b\u91cd\u590d\u9879\u3002\nUnitsSold \u8868\u7684\u6bcf\u4e00\u884c\u8868\u793a\u7684\u662f\u6bcf\u79cd\u4ea7\u54c1\u7684\u51fa\u552e\u65e5\u671f\uff0c\u5355\u4f4d\u548c\u4ea7\u54c1 id\u3002
\n\n

 

\n\n

\u7f16\u5199SQL\u67e5\u8be2\u4ee5\u67e5\u627e\u6bcf\u79cd\u4ea7\u54c1\u7684\u5e73\u5747\u552e\u4ef7\u3002
\naverage_price \u5e94\u8be5\u56db\u820d\u4e94\u5165\u5230\u5c0f\u6570\u70b9\u540e\u4e24\u4f4d\u3002
\n\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a\uff1a

\n\n
\nPrices table:\n+------------+------------+------------+--------+\n| product_id | start_date | end_date   | price  |\n+------------+------------+------------+--------+\n| 1          | 2019-02-17 | 2019-02-28 | 5      |\n| 1          | 2019-03-01 | 2019-03-22 | 20     |\n| 2          | 2019-02-01 | 2019-02-20 | 15     |\n| 2          | 2019-02-21 | 2019-03-31 | 30     |\n+------------+------------+------------+--------+\n \nUnitsSold table:\n+------------+---------------+-------+\n| product_id | purchase_date | units |\n+------------+---------------+-------+\n| 1          | 2019-02-25    | 100   |\n| 1          | 2019-03-01    | 15    |\n| 2          | 2019-02-10    | 200   |\n| 2          | 2019-03-22    | 30    |\n+------------+---------------+-------+\n\nResult table:\n+------------+---------------+\n| product_id | average_price |\n+------------+---------------+\n| 1          | 6.96          |\n| 2          | 16.96         |\n+------------+---------------+\n\u5e73\u5747\u552e\u4ef7 = \u4ea7\u54c1\u603b\u4ef7 / \u9500\u552e\u7684\u4ea7\u54c1\u6570\u91cf\u3002\n\u4ea7\u54c1 1 \u7684\u5e73\u5747\u552e\u4ef7 = ((100 * 5)+(15 * 20) )/ 115 = 6.96\n\u4ea7\u54c1 2 \u7684\u5e73\u5747\u552e\u4ef7 = ((200 * 15)+(30 * 30) )/ 230 = 16.96
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1251](https://leetcode-cn.com/problems/average-selling-price)", "[\u5e73\u5747\u552e\u4ef7](/solution/1200-1299/1251.Average%20Selling%20Price/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1251](https://leetcode.com/problems/average-selling-price)", "[Average Selling Price](/solution/1200-1299/1251.Average%20Selling%20Price/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1389", "frontend_question_id": "1263", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-moves-to-move-a-box-to-their-target-location", "url_en": "https://leetcode.com/problems/minimum-moves-to-move-a-box-to-their-target-location", "relative_path_cn": "/solution/1200-1299/1263.Minimum%20Moves%20to%20Move%20a%20Box%20to%20Their%20Target%20Location/README.md", "relative_path_en": "/solution/1200-1299/1263.Minimum%20Moves%20to%20Move%20a%20Box%20to%20Their%20Target%20Location/README_EN.md", "title_cn": "\u63a8\u7bb1\u5b50", "title_en": "Minimum Moves to Move a Box to Their Target Location", "question_title_slug": "minimum-moves-to-move-a-box-to-their-target-location", "content_en": "

Storekeeper is a game in which the player pushes boxes around in a warehouse trying to get them to target locations.

\n\n

The game is represented by a grid of size m x n, where each element is a wall, floor, or a box.

\n\n

Your task is move the box 'B' to the target position 'T' under the following rules:

\n\n
    \n\t
  • Player is represented by character 'S' and can move up, down, left, right in the grid if it is a floor (empy cell).
  • \n\t
  • Floor is represented by character '.' that means free cell to walk.
  • \n\t
  • Wall is represented by character '#' that means obstacle  (impossible to walk there). 
  • \n\t
  • There is only one box 'B' and one target cell 'T' in the grid.
  • \n\t
  • The box can be moved to an adjacent free cell by standing next to the box and then moving in the direction of the box. This is a push.
  • \n\t
  • The player cannot walk through the box.
  • \n
\n\n

Return the minimum number of pushes to move the box to the target. If there is no way to reach the target, return -1.

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: grid = [["#","#","#","#","#","#"],\n               ["#","T","#","#","#","#"],\n               ["#",".",".","B",".","#"],\n               ["#",".","#","#",".","#"],\n               ["#",".",".",".","S","#"],\n               ["#","#","#","#","#","#"]]\nOutput: 3\nExplanation: We return only the number of times the box is pushed.
\n\n

Example 2:

\n\n
\nInput: grid = [["#","#","#","#","#","#"],\n               ["#","T","#","#","#","#"],\n               ["#",".",".","B",".","#"],\n               ["#","#","#","#",".","#"],\n               ["#",".",".",".","S","#"],\n               ["#","#","#","#","#","#"]]\nOutput: -1\n
\n\n

Example 3:

\n\n
\nInput: grid = [["#","#","#","#","#","#"],\n               ["#","T",".",".","#","#"],\n               ["#",".","#","B",".","#"],\n               ["#",".",".",".",".","#"],\n               ["#",".",".",".","S","#"],\n               ["#","#","#","#","#","#"]]\nOutput: 5\nExplanation:  push the box down, left, left, up and up.\n
\n\n

Example 4:

\n\n
\nInput: grid = [["#","#","#","#","#","#","#"],\n               ["#","S","#",".","B","T","#"],\n               ["#","#","#","#","#","#","#"]]\nOutput: -1\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • m == grid.length
  • \n\t
  • n == grid[i].length
  • \n\t
  • 1 <= m <= 20
  • \n\t
  • 1 <= n <= 20
  • \n\t
  • grid contains only characters '.', '#''S' , 'T', or 'B'.
  • \n\t
  • There is only one character 'S', 'B' and 'T' in the grid.
  • \n
\n", "content_cn": "

\u300c\u63a8\u7bb1\u5b50\u300d\u662f\u4e00\u6b3e\u98ce\u9761\u5168\u7403\u7684\u76ca\u667a\u5c0f\u6e38\u620f\uff0c\u73a9\u5bb6\u9700\u8981\u5c06\u7bb1\u5b50\u63a8\u5230\u4ed3\u5e93\u4e2d\u7684\u76ee\u6807\u4f4d\u7f6e\u3002

\n\n

\u6e38\u620f\u5730\u56fe\u7528\u5927\u5c0f\u4e3a n * m \u7684\u7f51\u683c grid \u8868\u793a\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5143\u7d20\u53ef\u4ee5\u662f\u5899\u3001\u5730\u677f\u6216\u8005\u662f\u7bb1\u5b50\u3002

\n\n

\u73b0\u5728\u4f60\u5c06\u4f5c\u4e3a\u73a9\u5bb6\u53c2\u4e0e\u6e38\u620f\uff0c\u6309\u89c4\u5219\u5c06\u7bb1\u5b50 'B' \u79fb\u52a8\u5230\u76ee\u6807\u4f4d\u7f6e 'T' \uff1a

\n\n
    \n\t
  • \u73a9\u5bb6\u7528\u5b57\u7b26 'S' \u8868\u793a\uff0c\u53ea\u8981\u4ed6\u5728\u5730\u677f\u4e0a\uff0c\u5c31\u53ef\u4ee5\u5728\u7f51\u683c\u4e2d\u5411\u4e0a\u3001\u4e0b\u3001\u5de6\u3001\u53f3\u56db\u4e2a\u65b9\u5411\u79fb\u52a8\u3002
  • \n\t
  • \u5730\u677f\u7528\u5b57\u7b26 '.' \u8868\u793a\uff0c\u610f\u5473\u7740\u53ef\u4ee5\u81ea\u7531\u884c\u8d70\u3002
  • \n\t
  • \u5899\u7528\u5b57\u7b26 '#' \u8868\u793a\uff0c\u610f\u5473\u7740\u969c\u788d\u7269\uff0c\u4e0d\u80fd\u901a\u884c\u3002 
  • \n\t
  • \u7bb1\u5b50\u4ec5\u6709\u4e00\u4e2a\uff0c\u7528\u5b57\u7b26 'B' \u8868\u793a\u3002\u76f8\u5e94\u5730\uff0c\u7f51\u683c\u4e0a\u6709\u4e00\u4e2a\u76ee\u6807\u4f4d\u7f6e 'T'\u3002
  • \n\t
  • \u73a9\u5bb6\u9700\u8981\u7ad9\u5728\u7bb1\u5b50\u65c1\u8fb9\uff0c\u7136\u540e\u6cbf\u7740\u7bb1\u5b50\u7684\u65b9\u5411\u8fdb\u884c\u79fb\u52a8\uff0c\u6b64\u65f6\u7bb1\u5b50\u4f1a\u88ab\u79fb\u52a8\u5230\u76f8\u90bb\u7684\u5730\u677f\u5355\u5143\u683c\u3002\u8bb0\u4f5c\u4e00\u6b21\u300c\u63a8\u52a8\u300d\u3002
  • \n\t
  • \u73a9\u5bb6\u65e0\u6cd5\u8d8a\u8fc7\u7bb1\u5b50\u3002
  • \n
\n\n

\u8fd4\u56de\u5c06\u7bb1\u5b50\u63a8\u5230\u76ee\u6807\u4f4d\u7f6e\u7684\u6700\u5c0f \u63a8\u52a8 \u6b21\u6570\uff0c\u5982\u679c\u65e0\u6cd5\u505a\u5230\uff0c\u8bf7\u8fd4\u56de -1\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1agrid = [["#","#","#","#","#","#"],\n             ["#","T","#","#","#","#"],\n             ["#",".",".","B",".","#"],\n             ["#",".","#","#",".","#"],\n             ["#",".",".",".","S","#"],\n             ["#","#","#","#","#","#"]]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6211\u4eec\u53ea\u9700\u8981\u8fd4\u56de\u63a8\u7bb1\u5b50\u7684\u6b21\u6570\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1agrid = [["#","#","#","#","#","#"],\n             ["#","T","#","#","#","#"],\n             ["#",".",".","B",".","#"],\n             ["#","#","#","#",".","#"],\n             ["#",".",".",".","S","#"],\n             ["#","#","#","#","#","#"]]\n\u8f93\u51fa\uff1a-1\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1agrid = [["#","#","#","#","#","#"],\n             ["#","T",".",".","#","#"],\n             ["#",".","#","B",".","#"],\n             ["#",".",".",".",".","#"],\n             ["#",".",".",".","S","#"],\n             ["#","#","#","#","#","#"]]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u5411\u4e0b\u3001\u5411\u5de6\u3001\u5411\u5de6\u3001\u5411\u4e0a\u518d\u5411\u4e0a\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1agrid = [["#","#","#","#","#","#","#"],\n             ["#","S","#",".","B","T","#"],\n             ["#","#","#","#","#","#","#"]]\n\u8f93\u51fa\uff1a-1\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= grid.length <= 20
  • \n\t
  • 1 <= grid[i].length <= 20
  • \n\t
  • grid \u4ec5\u5305\u542b\u5b57\u7b26 '.', '#''S' , 'T', \u4ee5\u53ca 'B'\u3002
  • \n\t
  • grid \u4e2d 'S', 'B' \u548c 'T' \u5404\u53ea\u80fd\u51fa\u73b0\u4e00\u4e2a\u3002
  • \n
\n", "tags_en": ["Breadth-first Search"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minPushBox(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minPushBox(char[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minPushBox(self, grid):\n \"\"\"\n :type grid: List[List[str]]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minPushBox(self, grid: List[List[str]]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minPushBox(char** grid, int gridSize, int* gridColSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinPushBox(char[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {character[][]} grid\n * @return {number}\n */\nvar minPushBox = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Character[][]} grid\n# @return {Integer}\ndef min_push_box(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minPushBox(_ grid: [[Character]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minPushBox(grid [][]byte) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minPushBox(grid: Array[Array[Char]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minPushBox(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_push_box(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $grid\n * @return Integer\n */\n function minPushBox($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minPushBox(grid: string[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-push-box grid)\n (-> (listof (listof char?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1263](https://leetcode-cn.com/problems/minimum-moves-to-move-a-box-to-their-target-location)", "[\u63a8\u7bb1\u5b50](/solution/1200-1299/1263.Minimum%20Moves%20to%20Move%20a%20Box%20to%20Their%20Target%20Location/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[1263](https://leetcode.com/problems/minimum-moves-to-move-a-box-to-their-target-location)", "[Minimum Moves to Move a Box to Their Target Location](/solution/1200-1299/1263.Minimum%20Moves%20to%20Move%20a%20Box%20to%20Their%20Target%20Location/README_EN.md)", "`Breadth-first Search`", "Hard", ""]}, {"question_id": "1388", "frontend_question_id": "1262", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/greatest-sum-divisible-by-three", "url_en": "https://leetcode.com/problems/greatest-sum-divisible-by-three", "relative_path_cn": "/solution/1200-1299/1262.Greatest%20Sum%20Divisible%20by%20Three/README.md", "relative_path_en": "/solution/1200-1299/1262.Greatest%20Sum%20Divisible%20by%20Three/README_EN.md", "title_cn": "\u53ef\u88ab\u4e09\u6574\u9664\u7684\u6700\u5927\u548c", "title_en": "Greatest Sum Divisible by Three", "question_title_slug": "greatest-sum-divisible-by-three", "content_en": "

Given an array nums of integers, we need to find the maximum possible sum of elements of the array such that it is divisible by three.

\n\n
    \n
\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [3,6,5,1,8]\nOutput: 18\nExplanation: Pick numbers 3, 6, 1 and 8 their sum is 18 (maximum sum divisible by 3).
\n\n

Example 2:

\n\n
\nInput: nums = [4]\nOutput: 0\nExplanation: Since 4 is not divisible by 3, do not pick any number.\n
\n\n

Example 3:

\n\n
\nInput: nums = [1,2,3,4,4]\nOutput: 12\nExplanation: Pick numbers 1, 3, 4 and 4 their sum is 12 (maximum sum divisible by 3).\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 4 * 10^4
  • \n\t
  • 1 <= nums[i] <= 10^4
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums\uff0c\u8bf7\u4f60\u627e\u51fa\u5e76\u8fd4\u56de\u80fd\u88ab\u4e09\u6574\u9664\u7684\u5143\u7d20\u6700\u5927\u548c\u3002

\n\n
    \n
\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anums = [3,6,5,1,8]\n\u8f93\u51fa\uff1a18\n\u89e3\u91ca\uff1a\u9009\u51fa\u6570\u5b57 3, 6, 1 \u548c 8\uff0c\u5b83\u4eec\u7684\u548c\u662f 18\uff08\u53ef\u88ab 3 \u6574\u9664\u7684\u6700\u5927\u548c\uff09\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anums = [4]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a4 \u4e0d\u80fd\u88ab 3 \u6574\u9664\uff0c\u6240\u4ee5\u65e0\u6cd5\u9009\u51fa\u6570\u5b57\uff0c\u8fd4\u56de 0\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,2,3,4,4]\n\u8f93\u51fa\uff1a12\n\u89e3\u91ca\uff1a\u9009\u51fa\u6570\u5b57 1, 3, 4 \u4ee5\u53ca 4\uff0c\u5b83\u4eec\u7684\u548c\u662f 12\uff08\u53ef\u88ab 3 \u6574\u9664\u7684\u6700\u5927\u548c\uff09\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 4 * 10^4
  • \n\t
  • 1 <= nums[i] <= 10^4
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxSumDivThree(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxSumDivThree(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxSumDivThree(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxSumDivThree(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxSumDivThree(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxSumDivThree(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar maxSumDivThree = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef max_sum_div_three(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxSumDivThree(_ nums: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxSumDivThree(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxSumDivThree(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxSumDivThree(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_sum_div_three(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function maxSumDivThree($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxSumDivThree(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-sum-div-three nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1262](https://leetcode-cn.com/problems/greatest-sum-divisible-by-three)", "[\u53ef\u88ab\u4e09\u6574\u9664\u7684\u6700\u5927\u548c](/solution/1200-1299/1262.Greatest%20Sum%20Divisible%20by%20Three/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1262](https://leetcode.com/problems/greatest-sum-divisible-by-three)", "[Greatest Sum Divisible by Three](/solution/1200-1299/1262.Greatest%20Sum%20Divisible%20by%20Three/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "1387", "frontend_question_id": "1261", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-elements-in-a-contaminated-binary-tree", "url_en": "https://leetcode.com/problems/find-elements-in-a-contaminated-binary-tree", "relative_path_cn": "/solution/1200-1299/1261.Find%20Elements%20in%20a%20Contaminated%20Binary%20Tree/README.md", "relative_path_en": "/solution/1200-1299/1261.Find%20Elements%20in%20a%20Contaminated%20Binary%20Tree/README_EN.md", "title_cn": "\u5728\u53d7\u6c61\u67d3\u7684\u4e8c\u53c9\u6811\u4e2d\u67e5\u627e\u5143\u7d20", "title_en": "Find Elements in a Contaminated Binary Tree", "question_title_slug": "find-elements-in-a-contaminated-binary-tree", "content_en": "

Given a binary tree with the following rules:

\n\n
    \n\t
  1. root.val == 0
  2. \n\t
  3. If treeNode.val == x and treeNode.left != null, then treeNode.left.val == 2 * x + 1
  4. \n\t
  5. If treeNode.val == x and treeNode.right != null, then treeNode.right.val == 2 * x + 2
  6. \n
\n\n

Now the binary tree is contaminated, which means all treeNode.val have been changed to -1.

\n\n

You need to first recover the binary tree and then implement the FindElements class:

\n\n
    \n\t
  • FindElements(TreeNode* root) Initializes the object with a contamined binary tree, you need to recover it first.
  • \n\t
  • bool find(int target) Return if the target value exists in the recovered binary tree.
  • \n
\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput\n["FindElements","find","find"]\n[[[-1,null,-1]],[1],[2]]\nOutput\n[null,false,true]\nExplanation\nFindElements findElements = new FindElements([-1,null,-1]); \nfindElements.find(1); // return False \nfindElements.find(2); // return True 
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput\n["FindElements","find","find","find"]\n[[[-1,-1,-1,-1,-1]],[1],[3],[5]]\nOutput\n[null,true,true,false]\nExplanation\nFindElements findElements = new FindElements([-1,-1,-1,-1,-1]);\nfindElements.find(1); // return True\nfindElements.find(3); // return True\nfindElements.find(5); // return False
\n\n

Example 3:

\n\n

\"\"

\n\n
\nInput\n["FindElements","find","find","find","find"]\n[[[-1,null,-1,-1,null,-1]],[2],[3],[4],[5]]\nOutput\n[null,true,false,false,true]\nExplanation\nFindElements findElements = new FindElements([-1,null,-1,-1,null,-1]);\nfindElements.find(2); // return True\nfindElements.find(3); // return False\nfindElements.find(4); // return False\nfindElements.find(5); // return True\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • TreeNode.val == -1
  • \n\t
  • The height of the binary tree is less than or equal to 20
  • \n\t
  • The total number of nodes is between [1, 10^4]
  • \n\t
  • Total calls of find() is between [1, 10^4]
  • \n\t
  • 0 <= target <= 10^6
  • \n
\n", "content_cn": "

\u7ed9\u51fa\u4e00\u4e2a\u6ee1\u8db3\u4e0b\u8ff0\u89c4\u5219\u7684\u4e8c\u53c9\u6811\uff1a

\n\n
    \n\t
  1. root.val == 0
  2. \n\t
  3. \u5982\u679c treeNode.val == x \u4e14 treeNode.left != null\uff0c\u90a3\u4e48 treeNode.left.val == 2 * x + 1
  4. \n\t
  5. \u5982\u679c treeNode.val == x \u4e14 treeNode.right != null\uff0c\u90a3\u4e48 treeNode.right.val == 2 * x + 2
  6. \n
\n\n

\u73b0\u5728\u8fd9\u4e2a\u4e8c\u53c9\u6811\u53d7\u5230\u300c\u6c61\u67d3\u300d\uff0c\u6240\u6709\u7684 treeNode.val \u90fd\u53d8\u6210\u4e86 -1\u3002

\n\n

\u8bf7\u4f60\u5148\u8fd8\u539f\u4e8c\u53c9\u6811\uff0c\u7136\u540e\u5b9e\u73b0 FindElements \u7c7b\uff1a

\n\n
    \n\t
  • FindElements(TreeNode* root) \u7528\u53d7\u6c61\u67d3\u7684\u4e8c\u53c9\u6811\u521d\u59cb\u5316\u5bf9\u8c61\uff0c\u4f60\u9700\u8981\u5148\u628a\u5b83\u8fd8\u539f\u3002
  • \n\t
  • bool find(int target) \u5224\u65ad\u76ee\u6807\u503c target \u662f\u5426\u5b58\u5728\u4e8e\u8fd8\u539f\u540e\u7684\u4e8c\u53c9\u6811\u4e2d\u5e76\u8fd4\u56de\u7ed3\u679c\u3002
  • \n
\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1a\n["FindElements","find","find"]\n[[[-1,null,-1]],[1],[2]]\n\u8f93\u51fa\uff1a\n[null,false,true]\n\u89e3\u91ca\uff1a\nFindElements findElements = new FindElements([-1,null,-1]); \nfindElements.find(1); // return False \nfindElements.find(2); // return True 
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1a\n["FindElements","find","find","find"]\n[[[-1,-1,-1,-1,-1]],[1],[3],[5]]\n\u8f93\u51fa\uff1a\n[null,true,true,false]\n\u89e3\u91ca\uff1a\nFindElements findElements = new FindElements([-1,-1,-1,-1,-1]);\nfindElements.find(1); // return True\nfindElements.find(3); // return True\nfindElements.find(5); // return False
\n\n

\u793a\u4f8b 3\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1a\n["FindElements","find","find","find","find"]\n[[[-1,null,-1,-1,null,-1]],[2],[3],[4],[5]]\n\u8f93\u51fa\uff1a\n[null,true,false,false,true]\n\u89e3\u91ca\uff1a\nFindElements findElements = new FindElements([-1,null,-1,-1,null,-1]);\nfindElements.find(2); // return True\nfindElements.find(3); // return False\nfindElements.find(4); // return False\nfindElements.find(5); // return True\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • TreeNode.val == -1
  • \n\t
  • \u4e8c\u53c9\u6811\u7684\u9ad8\u5ea6\u4e0d\u8d85\u8fc7 20
  • \n\t
  • \u8282\u70b9\u7684\u603b\u6570\u5728 [1, 10^4] \u4e4b\u95f4
  • \n\t
  • \u8c03\u7528 find() \u7684\u603b\u6b21\u6570\u5728 [1, 10^4] \u4e4b\u95f4
  • \n\t
  • 0 <= target <= 10^6
  • \n
\n", "tags_en": ["Tree", "Hash Table"], "tags_cn": ["\u6811", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass FindElements {\npublic:\n FindElements(TreeNode* root) {\n\n }\n \n bool find(int target) {\n\n }\n};\n\n/**\n * Your FindElements object will be instantiated and called as such:\n * FindElements* obj = new FindElements(root);\n * bool param_1 = obj->find(target);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass FindElements {\n\n public FindElements(TreeNode root) {\n\n }\n \n public boolean find(int target) {\n\n }\n}\n\n/**\n * Your FindElements object will be instantiated and called as such:\n * FindElements obj = new FindElements(root);\n * boolean param_1 = obj.find(target);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass FindElements(object):\n\n def __init__(self, root):\n \"\"\"\n :type root: TreeNode\n \"\"\"\n\n\n def find(self, target):\n \"\"\"\n :type target: int\n :rtype: bool\n \"\"\"\n\n\n\n# Your FindElements object will be instantiated and called as such:\n# obj = FindElements(root)\n# param_1 = obj.find(target)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass FindElements:\n\n def __init__(self, root: TreeNode):\n\n\n def find(self, target: int) -> bool:\n\n\n\n# Your FindElements object will be instantiated and called as such:\n# obj = FindElements(root)\n# param_1 = obj.find(target)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n\ntypedef struct {\n\n} FindElements;\n\n\nFindElements* findElementsCreate(struct TreeNode* root) {\n\n}\n\nbool findElementsFind(FindElements* obj, int target) {\n\n}\n\nvoid findElementsFree(FindElements* obj) {\n\n}\n\n/**\n * Your FindElements struct will be instantiated and called as such:\n * FindElements* obj = findElementsCreate(root);\n * bool param_1 = findElementsFind(obj, target);\n \n * findElementsFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class FindElements {\n\n public FindElements(TreeNode root) {\n\n }\n \n public bool Find(int target) {\n\n }\n}\n\n/**\n * Your FindElements object will be instantiated and called as such:\n * FindElements obj = new FindElements(root);\n * bool param_1 = obj.Find(target);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n */\nvar FindElements = function(root) {\n\n};\n\n/** \n * @param {number} target\n * @return {boolean}\n */\nFindElements.prototype.find = function(target) {\n\n};\n\n/**\n * Your FindElements object will be instantiated and called as such:\n * var obj = new FindElements(root)\n * var param_1 = obj.find(target)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\nclass FindElements\n\n=begin\n :type root: TreeNode\n=end\n def initialize(root)\n\n end\n\n\n=begin\n :type target: Integer\n :rtype: Boolean\n=end\n def find(target)\n\n end\n\n\nend\n\n# Your FindElements object will be instantiated and called as such:\n# obj = FindElements.new(root)\n# param_1 = obj.find(target)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\n\nclass FindElements {\n\n init(_ root: TreeNode?) {\n\n }\n \n func find(_ target: Int) -> Bool {\n\n }\n}\n\n/**\n * Your FindElements object will be instantiated and called as such:\n * let obj = FindElements(root)\n * let ret_1: Bool = obj.find(target)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\ntype FindElements struct {\n\n}\n\n\nfunc Constructor(root *TreeNode) FindElements {\n\n}\n\n\nfunc (this *FindElements) Find(target int) bool {\n\n}\n\n\n/**\n * Your FindElements object will be instantiated and called as such:\n * obj := Constructor(root);\n * param_1 := obj.Find(target);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nclass FindElements(_root: TreeNode) {\n\n def find(target: Int): Boolean = {\n\n }\n\n}\n\n/**\n * Your FindElements object will be instantiated and called as such:\n * var obj = new FindElements(root)\n * var param_1 = obj.find(target)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass FindElements(root: TreeNode?) {\n\n fun find(target: Int): Boolean {\n\n }\n\n}\n\n/**\n * Your FindElements object will be instantiated and called as such:\n * var obj = FindElements(root)\n * var param_1 = obj.find(target)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nstruct FindElements {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl FindElements {\n\n fn new(root: Option>>) -> Self {\n\n }\n \n fn find(&self, target: i32) -> bool {\n\n }\n}\n\n/**\n * Your FindElements object will be instantiated and called as such:\n * let obj = FindElements::new(root);\n * let ret_1: bool = obj.find(target);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass FindElements {\n /**\n * @param TreeNode $root\n */\n function __construct($root) {\n\n }\n\n /**\n * @param Integer $target\n * @return Boolean\n */\n function find($target) {\n\n }\n}\n\n/**\n * Your FindElements object will be instantiated and called as such:\n * $obj = FindElements($root);\n * $ret_1 = $obj->find($target);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nclass FindElements {\n constructor(root: TreeNode | null) {\n\n }\n\n find(target: number): boolean {\n\n }\n}\n\n/**\n * Your FindElements object will be instantiated and called as such:\n * var obj = new FindElements(root)\n * var param_1 = obj.find(target)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define find-elements%\n (class object%\n (super-new)\n\n ; root : (or/c tree-node? #f)\n (init-field\n root)\n \n ; find : exact-integer? -> boolean?\n (define/public (find target)\n\n )))\n\n;; Your find-elements% object will be instantiated and called as such:\n;; (define obj (new find-elements% [root root]))\n;; (define param_1 (send obj find target))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1261](https://leetcode-cn.com/problems/find-elements-in-a-contaminated-binary-tree)", "[\u5728\u53d7\u6c61\u67d3\u7684\u4e8c\u53c9\u6811\u4e2d\u67e5\u627e\u5143\u7d20](/solution/1200-1299/1261.Find%20Elements%20in%20a%20Contaminated%20Binary%20Tree/README.md)", "`\u6811`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1261](https://leetcode.com/problems/find-elements-in-a-contaminated-binary-tree)", "[Find Elements in a Contaminated Binary Tree](/solution/1200-1299/1261.Find%20Elements%20in%20a%20Contaminated%20Binary%20Tree/README_EN.md)", "`Tree`,`Hash Table`", "Medium", ""]}, {"question_id": "1386", "frontend_question_id": "1260", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/shift-2d-grid", "url_en": "https://leetcode.com/problems/shift-2d-grid", "relative_path_cn": "/solution/1200-1299/1260.Shift%202D%20Grid/README.md", "relative_path_en": "/solution/1200-1299/1260.Shift%202D%20Grid/README_EN.md", "title_cn": "\u4e8c\u7ef4\u7f51\u683c\u8fc1\u79fb", "title_en": "Shift 2D Grid", "question_title_slug": "shift-2d-grid", "content_en": "

Given a 2D grid of size m x n and an integer k. You need to shift the grid k times.

\n\n

In one shift operation:

\n\n
    \n\t
  • Element at grid[i][j] moves to grid[i][j + 1].
  • \n\t
  • Element at grid[i][n - 1] moves to grid[i + 1][0].
  • \n\t
  • Element at grid[m - 1][n - 1] moves to grid[0][0].
  • \n
\n\n

Return the 2D grid after applying shift operation k times.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: grid = [[1,2,3],[4,5,6],[7,8,9]], k = 1\nOutput: [[9,1,2],[3,4,5],[6,7,8]]\n
\n\n

Example 2:

\n\"\"\n
\nInput: grid = [[3,8,1,9],[19,7,2,5],[4,6,11,10],[12,0,21,13]], k = 4\nOutput: [[12,0,21,13],[3,8,1,9],[19,7,2,5],[4,6,11,10]]\n
\n\n

Example 3:

\n\n
\nInput: grid = [[1,2,3],[4,5,6],[7,8,9]], k = 9\nOutput: [[1,2,3],[4,5,6],[7,8,9]]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • m == grid.length
  • \n\t
  • n == grid[i].length
  • \n\t
  • 1 <= m <= 50
  • \n\t
  • 1 <= n <= 50
  • \n\t
  • -1000 <= grid[i][j] <= 1000
  • \n\t
  • 0 <= k <= 100
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a m \u884c n\u00a0\u5217\u7684\u4e8c\u7ef4\u7f51\u683c\u00a0grid\u00a0\u548c\u4e00\u4e2a\u6574\u6570\u00a0k\u3002\u4f60\u9700\u8981\u5c06\u00a0grid\u00a0\u8fc1\u79fb\u00a0k\u00a0\u6b21\u3002

\n\n

\u6bcf\u6b21\u300c\u8fc1\u79fb\u300d\u64cd\u4f5c\u5c06\u4f1a\u5f15\u53d1\u4e0b\u8ff0\u6d3b\u52a8\uff1a

\n\n
    \n\t
  • \u4f4d\u4e8e grid[i][j]\u00a0\u7684\u5143\u7d20\u5c06\u4f1a\u79fb\u52a8\u5230\u00a0grid[i][j + 1]\u3002
  • \n\t
  • \u4f4d\u4e8e\u00a0grid[i][n\u00a0- 1] \u7684\u5143\u7d20\u5c06\u4f1a\u79fb\u52a8\u5230\u00a0grid[i + 1][0]\u3002
  • \n\t
  • \u4f4d\u4e8e grid[m\u00a0- 1][n - 1]\u00a0\u7684\u5143\u7d20\u5c06\u4f1a\u79fb\u52a8\u5230\u00a0grid[0][0]\u3002
  • \n
\n\n

\u8bf7\u4f60\u8fd4\u56de\u00a0k \u6b21\u8fc1\u79fb\u64cd\u4f5c\u540e\u6700\u7ec8\u5f97\u5230\u7684 \u4e8c\u7ef4\u7f51\u683c\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1agrid = [[1,2,3],[4,5,6],[7,8,9]], k = 1\n\u8f93\u51fa\uff1a[[9,1,2],[3,4,5],[6,7,8]]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1agrid = [[3,8,1,9],[19,7,2,5],[4,6,11,10],[12,0,21,13]], k = 4\n\u8f93\u51fa\uff1a[[12,0,21,13],[3,8,1,9],[19,7,2,5],[4,6,11,10]]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1agrid = [[1,2,3],[4,5,6],[7,8,9]], k = 9\n\u8f93\u51fa\uff1a[[1,2,3],[4,5,6],[7,8,9]]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • m ==\u00a0grid.length
  • \n\t
  • n ==\u00a0grid[i].length
  • \n\t
  • 1 <= m <= 50
  • \n\t
  • 1 <= n <= 50
  • \n\t
  • -1000 <= grid[i][j] <= 1000
  • \n\t
  • 0 <= k <= 100
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> shiftGrid(vector>& grid, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> shiftGrid(int[][] grid, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def shiftGrid(self, grid, k):\n \"\"\"\n :type grid: List[List[int]]\n :type k: int\n :rtype: List[List[int]]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def shiftGrid(self, grid: List[List[int]], k: int) -> List[List[int]]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** shiftGrid(int** grid, int gridSize, int* gridColSize, int k, int* returnSize, int** returnColumnSizes){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> ShiftGrid(int[][] grid, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @param {number} k\n * @return {number[][]}\n */\nvar shiftGrid = function(grid, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @param {Integer} k\n# @return {Integer[][]}\ndef shift_grid(grid, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func shiftGrid(_ grid: [[Int]], _ k: Int) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func shiftGrid(grid [][]int, k int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def shiftGrid(grid: Array[Array[Int]], k: Int): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun shiftGrid(grid: Array, k: Int): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn shift_grid(grid: Vec>, k: i32) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @param Integer $k\n * @return Integer[][]\n */\n function shiftGrid($grid, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function shiftGrid(grid: number[][], k: number): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (shift-grid grid k)\n (-> (listof (listof exact-integer?)) exact-integer? (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1260](https://leetcode-cn.com/problems/shift-2d-grid)", "[\u4e8c\u7ef4\u7f51\u683c\u8fc1\u79fb](/solution/1200-1299/1260.Shift%202D%20Grid/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1260](https://leetcode.com/problems/shift-2d-grid)", "[Shift 2D Grid](/solution/1200-1299/1260.Shift%202D%20Grid/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1384", "frontend_question_id": "1618", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/maximum-font-to-fit-a-sentence-in-a-screen", "url_en": "https://leetcode.com/problems/maximum-font-to-fit-a-sentence-in-a-screen", "relative_path_cn": "/solution/1600-1699/1618.Maximum%20Font%20to%20Fit%20a%20Sentence%20in%20a%20Screen/README.md", "relative_path_en": "/solution/1600-1699/1618.Maximum%20Font%20to%20Fit%20a%20Sentence%20in%20a%20Screen/README_EN.md", "title_cn": "\u627e\u51fa\u9002\u5e94\u5c4f\u5e55\u7684\u6700\u5927\u5b57\u53f7", "title_en": "Maximum Font to Fit a Sentence in a Screen", "question_title_slug": "maximum-font-to-fit-a-sentence-in-a-screen", "content_en": "

You are given a string text. We want to display text on a screen of width w and height h. You can choose any font size from array fonts, which contains the available font sizes in ascending order.

\r\n\r\n

You can use the FontInfo interface to get the width and height of any character at any available font size.

\r\n\r\n

The FontInfo interface is defined as such:

\r\n\r\n
\r\ninterface FontInfo {\r\n  // Returns the width of character ch on the screen using font size fontSize.\r\n  // O(1) per call\r\n  public int getWidth(int fontSize, char ch);\r\n\r\n  // Returns the height of any character on the screen using font size fontSize.\r\n  // O(1) per call\r\n  public int getHeight(int fontSize);\r\n}
\r\n\r\n

The calculated width of text for some fontSize is the sum of every getWidth(fontSize, text[i]) call for each 0 <= i < text.length (0-indexed). The calculated height of text for some fontSize is getHeight(fontSize). Note that text is displayed on a single line.

\r\n\r\n

It is guaranteed that FontInfo will return the same value if you call getHeight or getWidth with the same parameters.

\r\n\r\n

It is also guaranteed that for any font size fontSize and any character ch:

\r\n\r\n
    \r\n\t
  • getHeight(fontSize) <= getHeight(fontSize+1)
  • \r\n\t
  • getWidth(fontSize, ch) <= getWidth(fontSize+1, ch)
  • \r\n
\r\n\r\n

Return the maximum font size you can use to display text on the screen. If text cannot fit on the display with any font size, return -1.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: text = "helloworld", w = 80, h = 20, fonts = [6,8,10,12,14,16,18,24,36]\r\nOutput: 6\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: text = "leetcode", w = 1000, h = 50, fonts = [1,2,4]\r\nOutput: 4\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: text = "easyquestion", w = 100, h = 100, fonts = [10,15,20,25]\r\nOutput: -1\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= text.length <= 50000
  • \r\n\t
  • text contains only lowercase English letters.
  • \r\n\t
  • 1 <= w <= 107
  • \r\n\t
  • 1 <= h <= 104
  • \r\n\t
  • 1 <= fonts.length <= 105
  • \r\n\t
  • 1 <= fonts[i] <= 105
  • \r\n\t
  • fonts is sorted in ascending order and does not contain duplicates.
  • \r\n
", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\u00a0text\u3002\u5e76\u80fd\u591f\u5728 \u5bbd\u4e3a w \u9ad8\u4e3a h \u7684\u5c4f\u5e55\u4e0a\u663e\u793a\u8be5\u6587\u672c\u3002

\n\n

\u5b57\u4f53\u6570\u7ec4\u4e2d\u5305\u542b\u6309\u5347\u5e8f\u6392\u5217\u7684\u53ef\u7528\u5b57\u53f7\uff0c\u60a8\u53ef\u4ee5\u4ece\u8be5\u6570\u7ec4\u4e2d\u9009\u62e9\u4efb\u4f55\u5b57\u4f53\u5927\u5c0f\u3002

\n\n

\u60a8\u53ef\u4ee5\u4f7f\u7528FontInfo\u63a5\u53e3\u6765\u83b7\u53d6\u4efb\u4f55\u53ef\u7528\u5b57\u4f53\u5927\u5c0f\u7684\u4efb\u4f55\u5b57\u7b26\u7684\u5bbd\u5ea6\u548c\u9ad8\u5ea6\u3002

\n\n

FontInfo\u63a5\u53e3\u5b9a\u4e49\u5982\u4e0b\uff1a

\n\n
interface FontInfo {\n  // \u8fd4\u56de fontSize \u5927\u5c0f\u7684\u5b57\u7b26 ch \u5728\u5c4f\u5e55\u4e0a\u7684\u5bbd\u5ea6\u3002\n  // \u6bcf\u8c03\u7528\u8be5\u51fd\u6570\u590d\u6742\u5ea6\u4e3a O(1)\n  public int getWidth(int fontSize, char ch);\n\n  // \u8fd4\u56de fontSize \u5927\u5c0f\u7684\u4efb\u610f\u5b57\u7b26\u5728\u5c4f\u5e55\u4e0a\u7684\u9ad8\u5ea6\u3002\n  // \u6bcf\u8c03\u7528\u8be5\u51fd\u6570\u590d\u6742\u5ea6\u4e3a O(1)\n  public int getHeight(int fontSize);\n}
\n\n

\u4e00\u4e32\u5b57\u7b26\u7684\u6587\u672c\u5bbd\u5ea6\u5e94\u8be5\u662f\u6bcf\u4e00\u4e2a\u5b57\u7b26\u5728\u5bf9\u5e94\u5b57\u53f7(fontSize)\u4e0b\u8fd4\u56de\u7684\u5bbd\u5ea6getHeight(fontSize)\u7684\u603b\u548c\u3002

\n\n

\u8bf7\u6ce8\u610f\uff1a\u6587\u672c\u6700\u591a\u53ea\u80fd\u6392\u653e\u4e00\u6392

\n\n

\u5982\u679c\u4f7f\u7528\u76f8\u540c\u7684\u53c2\u6570\u8c03\u7528 getHeight\u00a0\u6216\u00a0getWidth \uff0c\u5219\u53ef\u4ee5\u4fdd\u8bc1 FontInfo \u5c06\u8fd4\u56de\u76f8\u540c\u7684\u503c\u3002

\n\n

\u540c\u65f6\uff0c\u5bf9\u4e8e\u4efb\u4f55\u5b57\u4f53\u5927\u5c0f\u7684\u00a0fontSize \u548c\u4efb\u4f55\u5b57\u7b26 ch \uff1a

\n\n
    \n\t
  • getHeight(fontSize) <= getHeight(fontSize+1)
  • \n\t
  • getWidth(fontSize, ch) <= getWidth(fontSize+1, ch)
  • \n
\n\n

\u8fd4\u56de\u53ef\u7528\u4e8e\u5728\u5c4f\u5e55\u4e0a\u663e\u793a\u6587\u672c\u7684\u6700\u5927\u5b57\u4f53\u5927\u5c0f\u3002\u5982\u679c\u6587\u672c\u4e0d\u80fd\u4ee5\u4efb\u4f55\u5b57\u4f53\u5927\u5c0f\u663e\u793a\uff0c\u5219\u8fd4\u56de-1\u3002

\n\n

\u793a\u4f8b 1:

\n\n
\u8f93\u5165: text = \"helloworld\", w = 80, h = 20, fonts = [6,8,10,12,14,16,18,24,36]\n\u8f93\u51fa: 6\n
\n\n

Example 2:

\n\n
\u8f93\u5165: text = \"leetcode\", w = 1000, h = 50, fonts = [1,2,4]\n\u8f93\u51fa: 4\n
\n\n

Example 3:

\n\n
\u8f93\u5165: text = \"easyquestion\", w = 100, h = 100, fonts = [10,15,20,25]\n\u8f93\u51fa: -1\n
\n\n

\u00a0

\n\n

\u6ce8\u610f:

\n\n
    \n\t
  • 1 <= text.length <= 50000
  • \n\t
  • text \u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd
  • \n\t
  • 1 <= w <= 107
  • \n\t
  • 1 <= h <= 104
  • \n\t
  • 1 <= fonts.length <= 105
  • \n\t
  • 1 <= fonts[i] <= 105
  • \n\t
  • fonts\u00a0\u5df2\u7ecf\u6309\u5347\u5e8f\u6392\u5e8f\uff0c\u4e14\u4e0d\u5305\u542b\u91cd\u590d\u9879\u3002
  • \n
\n", "tags_en": ["String", "Binary Search"], "tags_cn": ["\u5b57\u7b26\u4e32", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * // This is the FontInfo's API interface.\n * // You should not implement it, or speculate about its implementation\n * class FontInfo {\n * public:\n * // Return the width of char ch when fontSize is used.\n * int getWidth(int fontSize, char ch);\n * \n * // Return Height of any char when fontSize is used.\n * int getHeight(int fontSize)\n * };\n */\nclass Solution {\npublic:\n int maxFont(string text, int w, int h, vector& fonts, FontInfo fontInfo) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * // This is the FontInfo's API interface.\n * // You should not implement it, or speculate about its implementation\n * interface FontInfo {\n * // Return the width of char ch when fontSize is used.\n * public int getWidth(int fontSize, char ch) {}\n * // Return Height of any char when fontSize is used.\n * public int getHeight(int fontSize)\n * }\n */\nclass Solution {\n public int maxFont(String text, int w, int h, int[] fonts, FontInfo fontInfo) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# \"\"\"\n# This is FontInfo's API interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class FontInfo(object):\n# Return the width of char ch when fontSize is used.\n# def getWidth(self, fontSize, ch):\n# \"\"\"\n# :type fontSize: int\n# :type ch: char\n# :rtype int\n# \"\"\"\n# \n# def getHeight(self, fontSize):\n# \"\"\"\n# :type fontSize: int\n# :rtype int\n# \"\"\"\nclass Solution(object):\n def maxFont(self, text, w, h, fonts, fontInfo):\n \"\"\"\n :type text: str\n :type w: int\n :type h: int\n :type fonts: List[int]\n :type fontInfo: FontInfo\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# \"\"\"\n# This is FontInfo's API interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class FontInfo(object):\n# Return the width of char ch when fontSize is used.\n# def getWidth(self, fontSize, ch):\n# \"\"\"\n# :type fontSize: int\n# :type ch: char\n# :rtype int\n# \"\"\"\n# \n# def getHeight(self, fontSize):\n# \"\"\"\n# :type fontSize: int\n# :rtype int\n# \"\"\"\nclass Solution:\n def maxFont(self, text: str, w: int, h: int, fonts: List[int], fontInfo : 'FontInfo') -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * // This is the FontInfo's API interface.\n * // You should not implement it, or speculate about its implementation\n * interface FontInfo {\n * // Return the width of char ch when fontSize is used.\n * public int GetWidth(int fontSize, char ch) {}\n * // Return Height of any char when fontSize is used.\n * public int GetHeight(int fontSize)\n * }\n */\npublic class Solution {\n public int MaxFont(string text, int w, int h, int[] fonts, FontInfo fontInfo) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // This is the FontInfo's API interface.\n * // You should not implement it, or speculate about its implementation\n * function FontInfo() {\n *\n *\t\t@param {number} fontSize\n *\t\t@param {char} ch\n * \t@return {number}\n * \tthis.getWidth = function(fontSize, ch) {\n * \t...\n * \t};\n *\n *\t\t@param {number} fontSize\n * \t@return {number}\n * \tthis.getHeight = function(fontSize) {\n * \t...\n * \t};\n * };\n */\n/**\n * @param {string} text\n * @param {number} w\n * @param {number} h\n * @param {number[]} fonts\n * @param {FontInfo} fontInfo\n * @return {number}\n */\nvar maxFont = function(text, w, h, fonts, fontInfo) {\n \n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1618](https://leetcode-cn.com/problems/maximum-font-to-fit-a-sentence-in-a-screen)", "[\u627e\u51fa\u9002\u5e94\u5c4f\u5e55\u7684\u6700\u5927\u5b57\u53f7](/solution/1600-1699/1618.Maximum%20Font%20to%20Fit%20a%20Sentence%20in%20a%20Screen/README.md)", "`\u5b57\u7b26\u4e32`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1618](https://leetcode.com/problems/maximum-font-to-fit-a-sentence-in-a-screen)", "[Maximum Font to Fit a Sentence in a Screen](/solution/1600-1699/1618.Maximum%20Font%20to%20Fit%20a%20Sentence%20in%20a%20Screen/README_EN.md)", "`String`,`Binary Search`", "Medium", "\ud83d\udd12"]}, {"question_id": "1381", "frontend_question_id": "1255", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-score-words-formed-by-letters", "url_en": "https://leetcode.com/problems/maximum-score-words-formed-by-letters", "relative_path_cn": "/solution/1200-1299/1255.Maximum%20Score%20Words%20Formed%20by%20Letters/README.md", "relative_path_en": "/solution/1200-1299/1255.Maximum%20Score%20Words%20Formed%20by%20Letters/README_EN.md", "title_cn": "\u5f97\u5206\u6700\u9ad8\u7684\u5355\u8bcd\u96c6\u5408", "title_en": "Maximum Score Words Formed by Letters", "question_title_slug": "maximum-score-words-formed-by-letters", "content_en": "

Given a list of words, list of  single letters (might be repeating) and score of every character.

\n\n

Return the maximum score of any valid set of words formed by using the given letters (words[i] cannot be used two or more times).

\n\n

It is not necessary to use all characters in letters and each letter can only be used once. Score of letters 'a', 'b', 'c', ... ,'z' is given by score[0], score[1], ... , score[25] respectively.

\n\n

 

\n

Example 1:

\n\n
\nInput: words = ["dog","cat","dad","good"], letters = ["a","a","c","d","d","d","g","o","o"], score = [1,0,9,5,0,0,3,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0]\nOutput: 23\nExplanation:\nScore  a=1, c=9, d=5, g=3, o=2\nGiven letters, we can form the words "dad" (5+1+5) and "good" (3+2+2+5) with a score of 23.\nWords "dad" and "dog" only get a score of 21.
\n\n

Example 2:

\n\n
\nInput: words = ["xxxz","ax","bx","cx"], letters = ["z","a","b","c","x","x","x"], score = [4,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,0,10]\nOutput: 27\nExplanation:\nScore  a=4, b=4, c=4, x=5, z=10\nGiven letters, we can form the words "ax" (4+5), "bx" (4+5) and "cx" (4+5) with a score of 27.\nWord "xxxz" only get a score of 25.
\n\n

Example 3:

\n\n
\nInput: words = ["leetcode"], letters = ["l","e","t","c","o","d"], score = [0,0,1,1,1,0,0,0,0,0,0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0]\nOutput: 0\nExplanation:\nLetter "e" can only be used once.
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= words.length <= 14
  • \n\t
  • 1 <= words[i].length <= 15
  • \n\t
  • 1 <= letters.length <= 100
  • \n\t
  • letters[i].length == 1
  • \n\t
  • score.length == 26
  • \n\t
  • 0 <= score[i] <= 10
  • \n\t
  • words[i], letters[i] contains only lower case English letters.
  • \n
\n", "content_cn": "

\u4f60\u5c06\u4f1a\u5f97\u5230\u4e00\u4efd\u5355\u8bcd\u8868 words\uff0c\u4e00\u4e2a\u5b57\u6bcd\u8868 letters \uff08\u53ef\u80fd\u4f1a\u6709\u91cd\u590d\u5b57\u6bcd\uff09\uff0c\u4ee5\u53ca\u6bcf\u4e2a\u5b57\u6bcd\u5bf9\u5e94\u7684\u5f97\u5206\u60c5\u51b5\u8868 score\u3002

\n\n

\u8bf7\u4f60\u5e2e\u5fd9\u8ba1\u7b97\u73a9\u5bb6\u5728\u5355\u8bcd\u62fc\u5199\u6e38\u620f\u4e2d\u6240\u80fd\u83b7\u5f97\u7684\u300c\u6700\u9ad8\u5f97\u5206\u300d\uff1a\u80fd\u591f\u7531 letters \u91cc\u7684\u5b57\u6bcd\u62fc\u5199\u51fa\u7684 \u4efb\u610f \u5c5e\u4e8e words \u5355\u8bcd\u5b50\u96c6\u4e2d\uff0c\u5206\u6570\u6700\u9ad8\u7684\u5355\u8bcd\u96c6\u5408\u7684\u5f97\u5206\u3002

\n\n

\u5355\u8bcd\u62fc\u5199\u6e38\u620f\u7684\u89c4\u5219\u6982\u8ff0\u5982\u4e0b\uff1a

\n\n
    \n\t
  • \u73a9\u5bb6\u9700\u8981\u7528\u5b57\u6bcd\u8868 letters \u91cc\u7684\u5b57\u6bcd\u6765\u62fc\u5199\u5355\u8bcd\u8868 words \u4e2d\u7684\u5355\u8bcd\u3002
  • \n\t
  • \u53ef\u4ee5\u53ea\u4f7f\u7528\u5b57\u6bcd\u8868 letters \u4e2d\u7684\u90e8\u5206\u5b57\u6bcd\uff0c\u4f46\u662f\u6bcf\u4e2a\u5b57\u6bcd\u6700\u591a\u88ab\u4f7f\u7528\u4e00\u6b21\u3002
  • \n\t
  • \u5355\u8bcd\u8868 words \u4e2d\u6bcf\u4e2a\u5355\u8bcd\u53ea\u80fd\u8ba1\u5206\uff08\u4f7f\u7528\uff09\u4e00\u6b21\u3002
  • \n\t
  • \u6839\u636e\u5b57\u6bcd\u5f97\u5206\u60c5\u51b5\u8868score\uff0c\u5b57\u6bcd 'a''b''c', ... , 'z' \u5bf9\u5e94\u7684\u5f97\u5206\u5206\u522b\u4e3a score[0], score[1], ..., score[25]\u3002
  • \n\t
  • \u672c\u573a\u6e38\u620f\u7684\u300c\u5f97\u5206\u300d\u662f\u6307\uff1a\u73a9\u5bb6\u6240\u62fc\u5199\u51fa\u7684\u5355\u8bcd\u96c6\u5408\u91cc\u5305\u542b\u7684\u6240\u6709\u5b57\u6bcd\u7684\u5f97\u5206\u4e4b\u548c\u3002
  • \n
\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1awords = ["dog","cat","dad","good"], letters = ["a","a","c","d","d","d","g","o","o"], score = [1,0,9,5,0,0,3,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0]\n\u8f93\u51fa\uff1a23\n\u89e3\u91ca\uff1a\n\u5b57\u6bcd\u5f97\u5206\u4e3a  a=1, c=9, d=5, g=3, o=2\n\u4f7f\u7528\u7ed9\u5b9a\u7684\u5b57\u6bcd\u8868 letters\uff0c\u6211\u4eec\u53ef\u4ee5\u62fc\u5199\u5355\u8bcd "dad" (5+1+5)\u548c "good" (3+2+2+5)\uff0c\u5f97\u5206\u4e3a 23 \u3002\n\u800c\u5355\u8bcd "dad" \u548c "dog" \u53ea\u80fd\u5f97\u5230 21 \u5206\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1awords = ["xxxz","ax","bx","cx"], letters = ["z","a","b","c","x","x","x"], score = [4,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,0,10]\n\u8f93\u51fa\uff1a27\n\u89e3\u91ca\uff1a\n\u5b57\u6bcd\u5f97\u5206\u4e3a  a=4, b=4, c=4, x=5, z=10\n\u4f7f\u7528\u7ed9\u5b9a\u7684\u5b57\u6bcd\u8868 letters\uff0c\u6211\u4eec\u53ef\u4ee5\u7ec4\u6210\u5355\u8bcd "ax" (4+5)\uff0c "bx" (4+5) \u548c "cx" (4+5) \uff0c\u603b\u5f97\u5206\u4e3a 27 \u3002\n\u5355\u8bcd "xxxz" \u7684\u5f97\u5206\u4ec5\u4e3a 25 \u3002
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1awords = ["leetcode"], letters = ["l","e","t","c","o","d"], score = [0,0,1,1,1,0,0,0,0,0,0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\n\u5b57\u6bcd "e" \u5728\u5b57\u6bcd\u8868 letters \u4e2d\u53ea\u51fa\u73b0\u4e86\u4e00\u6b21\uff0c\u6240\u4ee5\u65e0\u6cd5\u7ec4\u6210\u5355\u8bcd\u8868 words \u4e2d\u7684\u5355\u8bcd\u3002
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= words.length <= 14
  • \n\t
  • 1 <= words[i].length <= 15
  • \n\t
  • 1 <= letters.length <= 100
  • \n\t
  • letters[i].length == 1
  • \n\t
  • score.length == 26
  • \n\t
  • 0 <= score[i] <= 10
  • \n\t
  • words[i] \u548c letters[i] \u53ea\u5305\u542b\u5c0f\u5199\u7684\u82f1\u6587\u5b57\u6bcd\u3002
  • \n
\n", "tags_en": ["Bit Manipulation"], "tags_cn": ["\u4f4d\u8fd0\u7b97"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxScoreWords(vector& words, vector& letters, vector& score) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxScoreWords(String[] words, char[] letters, int[] score) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxScoreWords(self, words, letters, score):\n \"\"\"\n :type words: List[str]\n :type letters: List[str]\n :type score: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxScoreWords(self, words: List[str], letters: List[str], score: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxScoreWords(char ** words, int wordsSize, char* letters, int lettersSize, int* score, int scoreSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxScoreWords(string[] words, char[] letters, int[] score) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @param {character[]} letters\n * @param {number[]} score\n * @return {number}\n */\nvar maxScoreWords = function(words, letters, score) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @param {Character[]} letters\n# @param {Integer[]} score\n# @return {Integer}\ndef max_score_words(words, letters, score)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxScoreWords(_ words: [String], _ letters: [Character], _ score: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxScoreWords(words []string, letters []byte, score []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxScoreWords(words: Array[String], letters: Array[Char], score: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxScoreWords(words: Array, letters: CharArray, score: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_score_words(words: Vec, letters: Vec, score: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @param String[] $letters\n * @param Integer[] $score\n * @return Integer\n */\n function maxScoreWords($words, $letters, $score) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxScoreWords(words: string[], letters: string[], score: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-score-words words letters score)\n (-> (listof string?) (listof char?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1255](https://leetcode-cn.com/problems/maximum-score-words-formed-by-letters)", "[\u5f97\u5206\u6700\u9ad8\u7684\u5355\u8bcd\u96c6\u5408](/solution/1200-1299/1255.Maximum%20Score%20Words%20Formed%20by%20Letters/README.md)", "`\u4f4d\u8fd0\u7b97`", "\u56f0\u96be", ""], "md_table_row_en": ["[1255](https://leetcode.com/problems/maximum-score-words-formed-by-letters)", "[Maximum Score Words Formed by Letters](/solution/1200-1299/1255.Maximum%20Score%20Words%20Formed%20by%20Letters/README_EN.md)", "`Bit Manipulation`", "Hard", ""]}, {"question_id": "1380", "frontend_question_id": "1254", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-closed-islands", "url_en": "https://leetcode.com/problems/number-of-closed-islands", "relative_path_cn": "/solution/1200-1299/1254.Number%20of%20Closed%20Islands/README.md", "relative_path_en": "/solution/1200-1299/1254.Number%20of%20Closed%20Islands/README_EN.md", "title_cn": "\u7edf\u8ba1\u5c01\u95ed\u5c9b\u5c7f\u7684\u6570\u76ee", "title_en": "Number of Closed Islands", "question_title_slug": "number-of-closed-islands", "content_en": "

Given a 2D grid consists of 0s (land) and 1s (water).  An island is a maximal 4-directionally connected group of 0s and a closed island is an island totally (all left, top, right, bottom) surrounded by 1s.

\n\n

Return the number of closed islands.

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: grid = [[1,1,1,1,1,1,1,0],[1,0,0,0,0,1,1,0],[1,0,1,0,1,1,1,0],[1,0,0,0,0,1,0,1],[1,1,1,1,1,1,1,0]]\nOutput: 2\nExplanation: \nIslands in gray are closed because they are completely surrounded by water (group of 1s).
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: grid = [[0,0,1,0,0],[0,1,0,1,0],[0,1,1,1,0]]\nOutput: 1\n
\n\n

Example 3:

\n\n
\nInput: grid = [[1,1,1,1,1,1,1],\n               [1,0,0,0,0,0,1],\n               [1,0,1,1,1,0,1],\n               [1,0,1,0,1,0,1],\n               [1,0,1,1,1,0,1],\n               [1,0,0,0,0,0,1],\n               [1,1,1,1,1,1,1]]\nOutput: 2\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= grid.length, grid[0].length <= 100
  • \n\t
  • 0 <= grid[i][j] <=1
  • \n
\n", "content_cn": "

\u6709\u4e00\u4e2a\u4e8c\u7ef4\u77e9\u9635 grid \uff0c\u6bcf\u4e2a\u4f4d\u7f6e\u8981\u4e48\u662f\u9646\u5730\uff08\u8bb0\u53f7\u4e3a 0 \uff09\u8981\u4e48\u662f\u6c34\u57df\uff08\u8bb0\u53f7\u4e3a 1 \uff09\u3002

\n\n

\u6211\u4eec\u4ece\u4e00\u5757\u9646\u5730\u51fa\u53d1\uff0c\u6bcf\u6b21\u53ef\u4ee5\u5f80\u4e0a\u4e0b\u5de6\u53f3 4 \u4e2a\u65b9\u5411\u76f8\u90bb\u533a\u57df\u8d70\uff0c\u80fd\u8d70\u5230\u7684\u6240\u6709\u9646\u5730\u533a\u57df\uff0c\u6211\u4eec\u5c06\u5176\u79f0\u4e3a\u4e00\u5ea7\u300c\u5c9b\u5c7f\u300d\u3002

\n\n

\u5982\u679c\u4e00\u5ea7\u5c9b\u5c7f \u5b8c\u5168 \u7531\u6c34\u57df\u5305\u56f4\uff0c\u5373\u9646\u5730\u8fb9\u7f18\u4e0a\u4e0b\u5de6\u53f3\u6240\u6709\u76f8\u90bb\u533a\u57df\u90fd\u662f\u6c34\u57df\uff0c\u90a3\u4e48\u6211\u4eec\u5c06\u5176\u79f0\u4e3a \u300c\u5c01\u95ed\u5c9b\u5c7f\u300d\u3002

\n\n

\u8bf7\u8fd4\u56de\u5c01\u95ed\u5c9b\u5c7f\u7684\u6570\u76ee\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\n\n
\u8f93\u5165\uff1agrid = [[1,1,1,1,1,1,1,0],[1,0,0,0,0,1,1,0],[1,0,1,0,1,1,1,0],[1,0,0,0,0,1,0,1],[1,1,1,1,1,1,1,0]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n\u7070\u8272\u533a\u57df\u7684\u5c9b\u5c7f\u662f\u5c01\u95ed\u5c9b\u5c7f\uff0c\u56e0\u4e3a\u8fd9\u5ea7\u5c9b\u5c7f\u5b8c\u5168\u88ab\u6c34\u57df\u5305\u56f4\uff08\u5373\u88ab 1 \u533a\u57df\u5305\u56f4\uff09\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\n\n
\u8f93\u5165\uff1agrid = [[0,0,1,0,0],[0,1,0,1,0],[0,1,1,1,0]]\n\u8f93\u51fa\uff1a1\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1agrid = [[1,1,1,1,1,1,1],\n             [1,0,0,0,0,0,1],\n             [1,0,1,1,1,0,1],\n             [1,0,1,0,1,0,1],\n             [1,0,1,1,1,0,1],\n             [1,0,0,0,0,0,1],\n             [1,1,1,1,1,1,1]]\n\u8f93\u51fa\uff1a2\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= grid.length, grid[0].length <= 100
  • \n\t
  • 0 <= grid[i][j] <=1
  • \n
\n", "tags_en": ["Depth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int closedIsland(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int closedIsland(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def closedIsland(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def closedIsland(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint closedIsland(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ClosedIsland(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar closedIsland = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef closed_island(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func closedIsland(_ grid: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func closedIsland(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def closedIsland(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun closedIsland(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn closed_island(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function closedIsland($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function closedIsland(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (closed-island grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1254](https://leetcode-cn.com/problems/number-of-closed-islands)", "[\u7edf\u8ba1\u5c01\u95ed\u5c9b\u5c7f\u7684\u6570\u76ee](/solution/1200-1299/1254.Number%20of%20Closed%20Islands/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1254](https://leetcode.com/problems/number-of-closed-islands)", "[Number of Closed Islands](/solution/1200-1299/1254.Number%20of%20Closed%20Islands/README_EN.md)", "`Depth-first Search`", "Medium", ""]}, {"question_id": "1379", "frontend_question_id": "1253", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reconstruct-a-2-row-binary-matrix", "url_en": "https://leetcode.com/problems/reconstruct-a-2-row-binary-matrix", "relative_path_cn": "/solution/1200-1299/1253.Reconstruct%20a%202-Row%20Binary%20Matrix/README.md", "relative_path_en": "/solution/1200-1299/1253.Reconstruct%20a%202-Row%20Binary%20Matrix/README_EN.md", "title_cn": "\u91cd\u6784 2 \u884c\u4e8c\u8fdb\u5236\u77e9\u9635", "title_en": "Reconstruct a 2-Row Binary Matrix", "question_title_slug": "reconstruct-a-2-row-binary-matrix", "content_en": "

Given the following details of a matrix with n columns and 2 rows :

\n\n
    \n\t
  • The matrix is a binary matrix, which means each element in the matrix can be 0 or 1.
  • \n\t
  • The sum of elements of the 0-th(upper) row is given as upper.
  • \n\t
  • The sum of elements of the 1-st(lower) row is given as lower.
  • \n\t
  • The sum of elements in the i-th column(0-indexed) is colsum[i], where colsum is given as an integer array with length n.
  • \n
\n\n

Your task is to reconstruct the matrix with upper, lower and colsum.

\n\n

Return it as a 2-D integer array.

\n\n

If there are more than one valid solution, any of them will be accepted.

\n\n

If no valid solution exists, return an empty 2-D array.

\n\n

 

\n

Example 1:

\n\n
\nInput: upper = 2, lower = 1, colsum = [1,1,1]\nOutput: [[1,1,0],[0,0,1]]\nExplanation: [[1,0,1],[0,1,0]], and [[0,1,1],[1,0,0]] are also correct answers.\n
\n\n

Example 2:

\n\n
\nInput: upper = 2, lower = 3, colsum = [2,2,1,1]\nOutput: []\n
\n\n

Example 3:

\n\n
\nInput: upper = 5, lower = 5, colsum = [2,1,2,0,1,0,1,2,0,1]\nOutput: [[1,1,1,0,1,0,0,1,0,0],[1,0,1,0,0,0,1,1,0,1]]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= colsum.length <= 10^5
  • \n\t
  • 0 <= upper, lower <= colsum.length
  • \n\t
  • 0 <= colsum[i] <= 2
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a 2 \u884c n \u5217\u7684\u4e8c\u8fdb\u5236\u6570\u7ec4\uff1a

\n\n
    \n\t
  • \u77e9\u9635\u662f\u4e00\u4e2a\u4e8c\u8fdb\u5236\u77e9\u9635\uff0c\u8fd9\u610f\u5473\u7740\u77e9\u9635\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u4e0d\u662f 0 \u5c31\u662f 1\u3002
  • \n\t
  • \u7b2c 0 \u884c\u7684\u5143\u7d20\u4e4b\u548c\u4e3a upper\u3002
  • \n\t
  • \u7b2c 1 \u884c\u7684\u5143\u7d20\u4e4b\u548c\u4e3a lower\u3002
  • \n\t
  • \u7b2c i \u5217\uff08\u4ece 0 \u5f00\u59cb\u7f16\u53f7\uff09\u7684\u5143\u7d20\u4e4b\u548c\u4e3a colsum[i]\uff0ccolsum \u662f\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u6574\u6570\u6570\u7ec4\u3002
  • \n
\n\n

\u4f60\u9700\u8981\u5229\u7528 upper\uff0clower \u548c colsum \u6765\u91cd\u6784\u8fd9\u4e2a\u77e9\u9635\uff0c\u5e76\u4ee5\u4e8c\u7ef4\u6574\u6570\u6570\u7ec4\u7684\u5f62\u5f0f\u8fd4\u56de\u5b83\u3002

\n\n

\u5982\u679c\u6709\u591a\u4e2a\u4e0d\u540c\u7684\u7b54\u6848\uff0c\u90a3\u4e48\u4efb\u610f\u4e00\u4e2a\u90fd\u53ef\u4ee5\u901a\u8fc7\u672c\u9898\u3002

\n\n

\u5982\u679c\u4e0d\u5b58\u5728\u7b26\u5408\u8981\u6c42\u7684\u7b54\u6848\uff0c\u5c31\u8bf7\u8fd4\u56de\u4e00\u4e2a\u7a7a\u7684\u4e8c\u7ef4\u6570\u7ec4\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aupper = 2, lower = 1, colsum = [1,1,1]\n\u8f93\u51fa\uff1a[[1,1,0],[0,0,1]]\n\u89e3\u91ca\uff1a[[1,0,1],[0,1,0]] \u548c [[0,1,1],[1,0,0]] \u4e5f\u662f\u6b63\u786e\u7b54\u6848\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aupper = 2, lower = 3, colsum = [2,2,1,1]\n\u8f93\u51fa\uff1a[]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aupper = 5, lower = 5, colsum = [2,1,2,0,1,0,1,2,0,1]\n\u8f93\u51fa\uff1a[[1,1,1,0,1,0,0,1,0,0],[1,0,1,0,0,0,1,1,0,1]]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= colsum.length <= 10^5
  • \n\t
  • 0 <= upper, lower <= colsum.length
  • \n\t
  • 0 <= colsum[i] <= 2
  • \n
\n", "tags_en": ["Greedy", "Math"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> reconstructMatrix(int upper, int lower, vector& colsum) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> reconstructMatrix(int upper, int lower, int[] colsum) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def reconstructMatrix(self, upper, lower, colsum):\n \"\"\"\n :type upper: int\n :type lower: int\n :type colsum: List[int]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def reconstructMatrix(self, upper: int, lower: int, colsum: List[int]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** reconstructMatrix(int upper, int lower, int* colsum, int colsumSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> ReconstructMatrix(int upper, int lower, int[] colsum) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} upper\n * @param {number} lower\n * @param {number[]} colsum\n * @return {number[][]}\n */\nvar reconstructMatrix = function(upper, lower, colsum) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} upper\n# @param {Integer} lower\n# @param {Integer[]} colsum\n# @return {Integer[][]}\ndef reconstruct_matrix(upper, lower, colsum)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func reconstructMatrix(_ upper: Int, _ lower: Int, _ colsum: [Int]) -> [[Int]] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func reconstructMatrix(upper int, lower int, colsum []int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def reconstructMatrix(upper: Int, lower: Int, colsum: Array[Int]): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun reconstructMatrix(upper: Int, lower: Int, colsum: IntArray): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn reconstruct_matrix(upper: i32, lower: i32, colsum: Vec) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $upper\n * @param Integer $lower\n * @param Integer[] $colsum\n * @return Integer[][]\n */\n function reconstructMatrix($upper, $lower, $colsum) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function reconstructMatrix(upper: number, lower: number, colsum: number[]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (reconstruct-matrix upper lower colsum)\n (-> exact-integer? exact-integer? (listof exact-integer?) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1253](https://leetcode-cn.com/problems/reconstruct-a-2-row-binary-matrix)", "[\u91cd\u6784 2 \u884c\u4e8c\u8fdb\u5236\u77e9\u9635](/solution/1200-1299/1253.Reconstruct%20a%202-Row%20Binary%20Matrix/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1253](https://leetcode.com/problems/reconstruct-a-2-row-binary-matrix)", "[Reconstruct a 2-Row Binary Matrix](/solution/1200-1299/1253.Reconstruct%20a%202-Row%20Binary%20Matrix/README_EN.md)", "`Greedy`,`Math`", "Medium", ""]}, {"question_id": "1378", "frontend_question_id": "1252", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/cells-with-odd-values-in-a-matrix", "url_en": "https://leetcode.com/problems/cells-with-odd-values-in-a-matrix", "relative_path_cn": "/solution/1200-1299/1252.Cells%20with%20Odd%20Values%20in%20a%20Matrix/README.md", "relative_path_en": "/solution/1200-1299/1252.Cells%20with%20Odd%20Values%20in%20a%20Matrix/README_EN.md", "title_cn": "\u5947\u6570\u503c\u5355\u5143\u683c\u7684\u6570\u76ee", "title_en": "Cells with Odd Values in a Matrix", "question_title_slug": "cells-with-odd-values-in-a-matrix", "content_en": "

There is an m x n matrix that is initialized to all 0's. There is also a 2D array indices where each indices[i] = [ri, ci] represents a 0-indexed location to perform some increment operations on the matrix.

\n\n

For each location indices[i], do both of the following:

\n\n
    \n\t
  1. Increment all the cells on row ri.
  2. \n\t
  3. Increment all the cells on column ci.
  4. \n
\n\n

Given m, n, and indices, return the number of odd-valued cells in the matrix after applying the increment to all locations in indices.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: m = 2, n = 3, indices = [[0,1],[1,1]]\nOutput: 6\nExplanation: Initial matrix = [[0,0,0],[0,0,0]].\nAfter applying first increment it becomes [[1,2,1],[0,1,0]].\nThe final matrix is [[1,3,1],[1,3,1]], which contains 6 odd numbers.\n
\n\n

Example 2:

\n\"\"\n
\nInput: m = 2, n = 2, indices = [[1,1],[0,0]]\nOutput: 0\nExplanation: Final matrix = [[2,2],[2,2]]. There are no odd numbers in the final matrix.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= m, n <= 50
  • \n\t
  • 1 <= indices.length <= 100
  • \n\t
  • 0 <= ri < m
  • \n\t
  • 0 <= ci < n
  • \n
\n\n

 

\n

Follow up: Could you solve this in O(n + m + indices.length) time with only O(n + m) extra space?

\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a m x n \u7684\u77e9\u9635\uff0c\u6700\u5f00\u59cb\u7684\u65f6\u5019\uff0c\u6bcf\u4e2a\u5355\u5143\u683c\u4e2d\u7684\u503c\u90fd\u662f 0\u3002

\n\n

\u53e6\u6709\u4e00\u4e2a\u4e8c\u7ef4\u7d22\u5f15\u6570\u7ec4\u00a0indices\uff0cindices[i] = [ri, ci] \u6307\u5411\u77e9\u9635\u4e2d\u7684\u67d0\u4e2a\u4f4d\u7f6e\uff0c\u5176\u4e2d ri \u548c ci \u5206\u522b\u8868\u793a\u6307\u5b9a\u7684\u884c\u548c\u5217\uff08\u4ece 0 \u5f00\u59cb\u7f16\u53f7\uff09\u3002

\n\n

\u5bf9 indices[i] \u6240\u6307\u5411\u7684\u6bcf\u4e2a\u4f4d\u7f6e\uff0c\u5e94\u540c\u65f6\u6267\u884c\u4e0b\u8ff0\u589e\u91cf\u64cd\u4f5c\uff1a

\n\n
    \n\t
  1. ri \u884c\u4e0a\u7684\u6240\u6709\u5355\u5143\u683c\uff0c\u52a0 1 \u3002
  2. \n\t
  3. ci \u5217\u4e0a\u7684\u6240\u6709\u5355\u5143\u683c\uff0c\u52a0 1 \u3002
  4. \n
\n\n

\u7ed9\u4f60 m\u3001n \u548c indices \u3002\u8bf7\u4f60\u5728\u6267\u884c\u5b8c\u6240\u6709\u00a0indices\u00a0\u6307\u5b9a\u7684\u589e\u91cf\u64cd\u4f5c\u540e\uff0c\u8fd4\u56de\u77e9\u9635\u4e2d \u5947\u6570\u503c\u5355\u5143\u683c \u7684\u6570\u76ee\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1am = 2, n = 3, indices = [[0,1],[1,1]]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u6700\u5f00\u59cb\u7684\u77e9\u9635\u662f [[0,0,0],[0,0,0]]\u3002\n\u7b2c\u4e00\u6b21\u589e\u91cf\u64cd\u4f5c\u540e\u5f97\u5230 [[1,2,1],[0,1,0]]\u3002\n\u6700\u540e\u7684\u77e9\u9635\u662f [[1,3,1],[1,3,1]]\uff0c\u91cc\u9762\u6709 6 \u4e2a\u5947\u6570\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1am = 2, n = 2, indices = [[1,1],[0,0]]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6700\u540e\u7684\u77e9\u9635\u662f [[2,2],[2,2]]\uff0c\u91cc\u9762\u6ca1\u6709\u5947\u6570\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= m, n <= 50
  • \n\t
  • 1 <= indices.length <= 100
  • \n\t
  • 0 <= ri < m
  • \n\t
  • 0 <= ci < n
  • \n
\n\n

\u00a0

\n\n

\u8fdb\u9636\uff1a\u4f60\u53ef\u4ee5\u8bbe\u8ba1\u4e00\u4e2a\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n + m + indices.length) \u4e14\u4ec5\u7528 O(n + m) \u989d\u5916\u7a7a\u95f4\u7684\u7b97\u6cd5\u6765\u89e3\u51b3\u6b64\u95ee\u9898\u5417\uff1f

\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int oddCells(int m, int n, vector>& indices) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int oddCells(int m, int n, int[][] indices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def oddCells(self, m, n, indices):\n \"\"\"\n :type m: int\n :type n: int\n :type indices: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint oddCells(int m, int n, int** indices, int indicesSize, int* indicesColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int OddCells(int m, int n, int[][] indices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} m\n * @param {number} n\n * @param {number[][]} indices\n * @return {number}\n */\nvar oddCells = function(m, n, indices) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} m\n# @param {Integer} n\n# @param {Integer[][]} indices\n# @return {Integer}\ndef odd_cells(m, n, indices)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func oddCells(_ m: Int, _ n: Int, _ indices: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func oddCells(m int, n int, indices [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def oddCells(m: Int, n: Int, indices: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun oddCells(m: Int, n: Int, indices: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn odd_cells(m: i32, n: i32, indices: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $m\n * @param Integer $n\n * @param Integer[][] $indices\n * @return Integer\n */\n function oddCells($m, $n, $indices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function oddCells(m: number, n: number, indices: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (odd-cells m n indices)\n (-> exact-integer? exact-integer? (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1252](https://leetcode-cn.com/problems/cells-with-odd-values-in-a-matrix)", "[\u5947\u6570\u503c\u5355\u5143\u683c\u7684\u6570\u76ee](/solution/1200-1299/1252.Cells%20with%20Odd%20Values%20in%20a%20Matrix/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1252](https://leetcode.com/problems/cells-with-odd-values-in-a-matrix)", "[Cells with Odd Values in a Matrix](/solution/1200-1299/1252.Cells%20with%20Odd%20Values%20in%20a%20Matrix/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1377", "frontend_question_id": "1241", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/number-of-comments-per-post", "url_en": "https://leetcode.com/problems/number-of-comments-per-post", "relative_path_cn": "/solution/1200-1299/1241.Number%20of%20Comments%20per%20Post/README.md", "relative_path_en": "/solution/1200-1299/1241.Number%20of%20Comments%20per%20Post/README_EN.md", "title_cn": "\u6bcf\u4e2a\u5e16\u5b50\u7684\u8bc4\u8bba\u6570", "title_en": "Number of Comments per Post", "question_title_slug": "number-of-comments-per-post", "content_en": "

Table: Submissions

\n\n
\n+---------------+----------+\n| Column Name   | Type     |\n+---------------+----------+\n| sub_id        | int      |\n| parent_id     | int      |\n+---------------+----------+\nThere is no primary key for this table, it may have duplicate rows.\nEach row can be a post or comment on the post.\nparent_id is null for posts.\nparent_id for comments is sub_id for another post in the table.\n
\n\n

 

\n\n

Write an SQL query to find number of comments per each post.

\n\n

Result table should contain post_id and its corresponding number_of_comments, and must be sorted by post_id in ascending order.

\n\n

Submissions may contain duplicate comments. You should count the number of unique comments per post.

\n\n

Submissions may contain duplicate posts. You should treat them as one post.

\n\n

The query result format is in the following example:

\n\n
\nSubmissions table:\n+---------+------------+\n| sub_id  | parent_id  |\n+---------+------------+\n| 1       | Null       |\n| 2       | Null       |\n| 1       | Null       |\n| 12      | Null       |\n| 3       | 1          |\n| 5       | 2          |\n| 3       | 1          |\n| 4       | 1          |\n| 9       | 1          |\n| 10      | 2          |\n| 6       | 7          |\n+---------+------------+\n\nResult table:\n+---------+--------------------+\n| post_id | number_of_comments |\n+---------+--------------------+\n| 1       | 3                  |\n| 2       | 2                  |\n| 12      | 0                  |\n+---------+--------------------+\n\nThe post with id 1 has three comments in the table with id 3, 4 and 9. The comment with id 3 is repeated in the table, we counted it only once.\nThe post with id 2 has two comments in the table with id 5 and 10.\nThe post with id 12 has no comments in the table.\nThe comment with id 6 is a comment on a deleted post with id 7 so we ignored it.\n
\n", "content_cn": "

\u8868 Submissions \u7ed3\u6784\u5982\u4e0b\uff1a

\n\n
\n+---------------+----------+\n| \u5217\u540d           | \u7c7b\u578b     |\n+---------------+----------+\n| sub_id        | int      |\n| parent_id     | int      |\n+---------------+----------+\n\u4e0a\u8868\u6ca1\u6709\u4e3b\u952e, \u6240\u4ee5\u53ef\u80fd\u4f1a\u51fa\u73b0\u91cd\u590d\u7684\u884c\u3002\n\u6bcf\u884c\u53ef\u4ee5\u662f\u4e00\u4e2a\u5e16\u5b50\u6216\u5bf9\u8be5\u5e16\u5b50\u7684\u8bc4\u8bba\u3002\n\u5982\u679c\u662f\u5e16\u5b50\u7684\u8bdd\uff0cparent_id \u5c31\u662f null\u3002\n\u5bf9\u4e8e\u8bc4\u8bba\u6765\u8bf4\uff0cparent_id \u5c31\u662f\u8868\u4e2d\u5bf9\u5e94\u5e16\u5b50\u7684 sub_id\u3002\n
\n\n

 

\n\n

\u7f16\u5199 SQL \u8bed\u53e5\u4ee5\u67e5\u627e\u6bcf\u4e2a\u5e16\u5b50\u7684\u8bc4\u8bba\u6570\u3002

\n\n

\u7ed3\u679c\u8868\u5e94\u5305\u542b\u5e16\u5b50\u7684 post_id \u548c\u5bf9\u5e94\u7684\u8bc4\u8bba\u6570 number_of_comments \u5e76\u4e14\u6309 post_id \u5347\u5e8f\u6392\u5217\u3002

\n\n

Submissions \u53ef\u80fd\u5305\u542b\u91cd\u590d\u7684\u8bc4\u8bba\u3002\u60a8\u5e94\u8be5\u8ba1\u7b97\u6bcf\u4e2a\u5e16\u5b50\u7684\u552f\u4e00\u8bc4\u8bba\u6570\u3002

\n\n

Submissions \u53ef\u80fd\u5305\u542b\u91cd\u590d\u7684\u5e16\u5b50\u3002\u60a8\u5e94\u8be5\u5c06\u5b83\u4eec\u89c6\u4e3a\u4e00\u4e2a\u5e16\u5b50\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a\uff1a

\n\n
\nSubmissions table:\n+---------+------------+\n| sub_id  | parent_id  |\n+---------+------------+\n| 1       | Null       |\n| 2       | Null       |\n| 1       | Null       |\n| 12      | Null       |\n| 3       | 1          |\n| 5       | 2          |\n| 3       | 1          |\n| 4       | 1          |\n| 9       | 1          |\n| 10      | 2          |\n| 6       | 7          |\n+---------+------------+\n\n\u7ed3\u679c\u8868\uff1a\n+---------+--------------------+\n| post_id | number_of_comments |\n+---------+--------------------+\n| 1       | 3                  |\n| 2       | 2                  |\n| 12      | 0                  |\n+---------+--------------------+\n\n\u8868\u4e2d ID \u4e3a 1 \u7684\u5e16\u5b50\u6709 ID \u4e3a 3\u30014 \u548c 9 \u7684\u4e09\u4e2a\u8bc4\u8bba\u3002\u8868\u4e2d ID \u4e3a 3 \u7684\u8bc4\u8bba\u91cd\u590d\u51fa\u73b0\u4e86\uff0c\u6240\u4ee5\u6211\u4eec\u53ea\u5bf9\u5b83\u8fdb\u884c\u4e86\u4e00\u6b21\u8ba1\u6570\u3002\n\u8868\u4e2d ID \u4e3a 2 \u7684\u5e16\u5b50\u6709 ID \u4e3a 5 \u548c 10 \u7684\u4e24\u4e2a\u8bc4\u8bba\u3002\nID \u4e3a 12 \u7684\u5e16\u5b50\u5728\u8868\u4e2d\u6ca1\u6709\u8bc4\u8bba\u3002\n\u8868\u4e2d ID \u4e3a 6 \u7684\u8bc4\u8bba\u662f\u5bf9 ID \u4e3a 7 \u7684\u5df2\u5220\u9664\u5e16\u5b50\u7684\u8bc4\u8bba\uff0c\u56e0\u6b64\u6211\u4eec\u5c06\u5176\u5ffd\u7565\u3002\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1241](https://leetcode-cn.com/problems/number-of-comments-per-post)", "[\u6bcf\u4e2a\u5e16\u5b50\u7684\u8bc4\u8bba\u6570](/solution/1200-1299/1241.Number%20of%20Comments%20per%20Post/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1241](https://leetcode.com/problems/number-of-comments-per-post)", "[Number of Comments per Post](/solution/1200-1299/1241.Number%20of%20Comments%20per%20Post/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1374", "frontend_question_id": "1428", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/leftmost-column-with-at-least-a-one", "url_en": "https://leetcode.com/problems/leftmost-column-with-at-least-a-one", "relative_path_cn": "/solution/1400-1499/1428.Leftmost%20Column%20with%20at%20Least%20a%20One/README.md", "relative_path_en": "/solution/1400-1499/1428.Leftmost%20Column%20with%20at%20Least%20a%20One/README_EN.md", "title_cn": "\u81f3\u5c11\u6709\u4e00\u4e2a 1 \u7684\u6700\u5de6\u7aef\u5217", "title_en": "Leftmost Column with at Least a One", "question_title_slug": "leftmost-column-with-at-least-a-one", "content_en": "

(This problem is an interactive problem.)

\n\n

A row-sorted binary matrix means that all elements are 0 or 1 and each row of the matrix is sorted in non-decreasing order.

\n\n

Given a row-sorted binary matrix binaryMatrix, return the index (0-indexed) of the leftmost column with a 1 in it. If such an index does not exist, return -1.

\n\n

You can't access the Binary Matrix directly. You may only access the matrix using a BinaryMatrix interface:

\n\n
    \n\t
  • BinaryMatrix.get(row, col) returns the element of the matrix at index (row, col) (0-indexed).
  • \n\t
  • BinaryMatrix.dimensions() returns the dimensions of the matrix as a list of 2 elements [rows, cols], which means the matrix is rows x cols.
  • \n
\n\n

Submissions making more than 1000 calls to BinaryMatrix.get will be judged Wrong Answer. Also, any solutions that attempt to circumvent the judge will result in disqualification.

\n\n

For custom testing purposes, the input will be the entire binary matrix mat. You will not have access to the binary matrix directly.

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: mat = [[0,0],[1,1]]\nOutput: 0\n
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: mat = [[0,0],[0,1]]\nOutput: 1\n
\n\n

Example 3:

\n\n

\"\"

\n\n
\nInput: mat = [[0,0],[0,0]]\nOutput: -1
\n\n

Example 4:

\n\n

\"\"

\n\n
\nInput: mat = [[0,0,0,1],[0,0,1,1],[0,1,1,1]]\nOutput: 1\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • rows == mat.length
  • \n\t
  • cols == mat[i].length
  • \n\t
  • 1 <= rows, cols <= 100
  • \n\t
  • mat[i][j] is either 0 or 1.
  • \n\t
  • mat[i] is sorted in non-decreasing order.
  • \n
\n", "content_cn": "

\uff08\u8fd9\u662f\u4e00\u4e2a\u4ea4\u4e92\u9898\uff09

\n\n

\u6211\u4eec\u79f0\u53ea\u5305\u542b\u5143\u7d20 0 \u6216 1 \u7684\u77e9\u9635\u4e3a\u4e8c\u8fdb\u5236\u77e9\u9635\u3002\u77e9\u9635\u4e2d\u6bcf\u4e2a\u5355\u72ec\u7684\u884c\u90fd\u6309\u975e\u9012\u51cf\u987a\u5e8f\u6392\u5e8f\u3002

\n\n

\u7ed9\u5b9a\u4e00\u4e2a\u8fd9\u6837\u7684\u4e8c\u8fdb\u5236\u77e9\u9635\uff0c\u8fd4\u56de\u81f3\u5c11\u5305\u542b\u4e00\u4e2a 1 \u7684\u6700\u5de6\u7aef\u5217\u7684\u7d22\u5f15\uff08\u4ece 0 \u5f00\u59cb\uff09\u3002\u5982\u679c\u8fd9\u6837\u7684\u5217\u4e0d\u5b58\u5728\uff0c\u8fd4\u56de -1\u3002

\n\n

\u60a8\u4e0d\u80fd\u76f4\u63a5\u8bbf\u95ee\u8be5\u4e8c\u8fdb\u5236\u77e9\u9635\u3002\u4f60\u53ea\u53ef\u4ee5\u901a\u8fc7 BinaryMatrix \u63a5\u53e3\u6765\u8bbf\u95ee\u3002

\n\n
    \n\t
  • BinaryMatrix.get(row, col) \u8fd4\u56de\u4f4d\u4e8e\u7d22\u5f15 (row, col) \uff08\u4ece 0 \u5f00\u59cb\uff09\u7684\u5143\u7d20\u3002
  • \n\t
  • BinaryMatrix.dimensions() \u8fd4\u56de\u542b\u6709 2 \u4e2a\u5143\u7d20\u7684\u5217\u8868 [rows, cols]\uff0c\u8868\u793a\u8fd9\u662f\u4e00\u4e2a rows * cols\u7684\u77e9\u9635\u3002
  • \n
\n\n

\u5982\u679c\u63d0\u4ea4\u7684\u7b54\u6848\u8c03\u7528 BinaryMatrix.get \u8d85\u8fc7 1000 \u6b21\uff0c\u5219\u8be5\u7b54\u6848\u4f1a\u88ab\u5224\u5b9a\u4e3a\u9519\u8bef\u7b54\u6848\u3002\u63d0\u4ea4\u4efb\u4f55\u8bd5\u56fe\u89c4\u907f\u5224\u5b9a\u673a\u5236\u7684\u7b54\u6848\u5c06\u4f1a\u88ab\u53d6\u6d88\u8d44\u683c\u3002

\n\n

\u4e0b\u5217\u793a\u4f8b\u4e2d\uff0c mat \u4e3a\u7ed9\u5b9a\u7684\u4e8c\u8fdb\u5236\u77e9\u9635\u3002\u60a8\u4e0d\u80fd\u76f4\u63a5\u8bbf\u95ee\u8be5\u77e9\u9635\u3002

\n\n

 

\n\n

\u793a\u4f8b 1:

\n\n

\"\"

\n\n
\n\u8f93\u5165: mat = [[0,0],[1,1]]\n\u8f93\u51fa: 0\n
\n\n

\u793a\u4f8b 2:

\n\n

\"\"

\n\n
\n\u8f93\u5165: mat = [[0,0],[0,1]]\n\u8f93\u51fa: 1\n
\n\n

\u793a\u4f8b 3:

\n\n

\"\"

\n\n
\n\u8f93\u5165: mat = [[0,0],[0,0]]\n\u8f93\u51fa: -1
\n\n

\u793a\u4f8b 4:

\n\n

\"\"

\n\n
\n\u8f93\u5165: mat = [[0,0,0,1],[0,0,1,1],[0,1,1,1]]\n\u8f93\u51fa: 1\n
\n\n

 

\n\n

\u63d0\u793a:

\n\n
    \n\t
  • rows == mat.length
  • \n\t
  • cols == mat[i].length
  • \n\t
  • 1 <= rows, cols <= 100
  • \n\t
  • mat[i][j] \u53ea\u4f1a\u662f 0 \u6216 1\u3002
  • \n\t
  • mat[i] \u5df2\u6309\u975e\u9012\u51cf\u987a\u5e8f\u6392\u5e8f\u3002
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * // This is the BinaryMatrix's API interface.\n * // You should not implement it, or speculate about its implementation\n * class BinaryMatrix {\n * public:\n * int get(int row, int col);\n * vector dimensions();\n * };\n */\n\nclass Solution {\npublic:\n int leftMostColumnWithOne(BinaryMatrix &binaryMatrix) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * // This is the BinaryMatrix's API interface.\n * // You should not implement it, or speculate about its implementation\n * interface BinaryMatrix {\n * public int get(int row, int col) {}\n * public List dimensions {}\n * };\n */\n\nclass Solution {\n public int leftMostColumnWithOne(BinaryMatrix binaryMatrix) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# \"\"\"\n# This is BinaryMatrix's API interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class BinaryMatrix(object):\n# def get(self, row, col):\n# \"\"\"\n# :type row : int, col : int\n# :rtype int\n# \"\"\"\n#\n# def dimensions:\n# \"\"\"\n# :rtype list[]\n# \"\"\"\n\nclass Solution(object):\n def leftMostColumnWithOne(self, binaryMatrix):\n \"\"\"\n :type binaryMatrix: BinaryMatrix\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# \"\"\"\n# This is BinaryMatrix's API interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class BinaryMatrix(object):\n# def get(self, row: int, col: int) -> int:\n# def dimensions(self) -> list[]:\n\nclass Solution:\n def leftMostColumnWithOne(self, binaryMatrix: 'BinaryMatrix') -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * // This is the BinaryMatrix's API interface.\n * // You should not implement it, or speculate about its implementation\n * struct BinaryMatrix {\n * int (*get)(struct BinaryMatrix*, int, int);\n * int* (*dimensions)(struct BinaryMatrix*);\n * };\n */\n\nint leftMostColumnWithOne(struct BinaryMatrix* matrix) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * // This is BinaryMatrix's API interface.\n * // You should not implement it, or speculate about its implementation\n * class BinaryMatrix {\n * public int Get(int row, int col) {}\n * public IList Dimensions() {}\n * }\n */\n\nclass Solution {\n public int LeftMostColumnWithOne(BinaryMatrix binaryMatrix) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // This is the BinaryMatrix's API interface.\n * // You should not implement it, or speculate about its implementation\n * function BinaryMatrix() {\n * @param {integer} row, col\n * @return {integer}\n * this.get = function(row, col) {\n * ...\n * };\n *\n * @return {[integer, integer]}\n * this.dimensions = function() {\n * ...\n * };\n * };\n */\n\n/**\n * @param {BinaryMatrix} binaryMatrix\n * @return {number}\n */\nvar leftMostColumnWithOne = function(binaryMatrix) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# \"\"\"\n# This is BinaryMatrix's API interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n# class BinaryMatrix\n# \tdef get(row, col)\n# \t\t@return {Integer}\n# \tend\n#\n# \tdef dimensions()\n# \t\t@return {List[Integer]}\n# \tend\n# end\n\n# @param {BinaryMatrix} binaryMatrix\n# @return {Integer}\ndef leftMostColumnWithOne(binaryMatrix)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * // This is the BinaryMatrix's API interface.\n * // You should not implement it, or speculate about its implementation\n * public class BinaryMatrix {\n * public func get(_ row: Int, _ col: Int) -> Int {}\n * public func dimensions() -> [Int] {}\n * };\n */\n\nclass Solution {\n func leftMostColumnWithOne(_ binaryMatrix: BinaryMatrix) -> Int {\n\t\t\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * // This is the BinaryMatrix's API interface.\n * // You should not implement it, or speculate about its implementation\n * type BinaryMatrix struct {\n * Get func(int, int) int\n * Dimensions func() []int\n * }\n */\n\nfunc leftMostColumnWithOne(binaryMatrix BinaryMatrix) int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * // This is the BinaryMatrix's API interface.\n * // You should not implement it, or speculate about its implementation\n * class BinaryMatrix {\n * def get(row: Int, col: Int): Int = {}\n * def dimensions(): Array[Int] = {}\n * }\n */\n\nobject Solution {\n def leftMostColumnWithOne(binaryMatrix: BinaryMatrix): Int = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * // This is the BinaryMatrix's API interface.\n * // You should not implement it, or speculate about its implementation\n * class BinaryMatrix {\n * fun get(row:Int, col:Int):Int {}\n * fun dimensions():List {}\n * }\n */\n\nclass Solution {\n fun leftMostColumnWithOne(binaryMatrix:BinaryMatrix):Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "/**\n * // This is the BinaryMatrix's API interface.\n * // You should not implement it, or speculate about its implementation\n * struct BinaryMatrix;\n * impl BinaryMatrix {\n * fn get(row: i32, col: i32) -> i32;\n * fn dimensions() -> Vec;\n * };\n */\n\nimpl Solution {\n pub fn left_most_column_with_one(binaryMatrix: &BinaryMatrix) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * // This is the BinaryMatrix's API interface.\n * // You should not implement it, or speculate about its implementation\n * class BinaryMatrix {\n * public function get($row, $col) {} @return Integer\n * public function dimensions() {} @return Integer[]\n * }\n */\n\nclass Solution {\n /**\n * @param BinaryMatrix $binaryMatrix\n * @return Integer\n */\n public function leftMostColumnWithOne($binaryMatrix) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * // This is the BinaryMatrix's API interface.\n * // You should not implement it, or speculate about its implementation\n * class BinaryMatrix {\n * get(row: number, col: number): number {}\n *\n * dimensions(): number[] {}\n * }\n */\n\nfunction leftMostColumnWithOne(binaryMatrix: BinaryMatrix) {\n\t\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1428](https://leetcode-cn.com/problems/leftmost-column-with-at-least-a-one)", "[\u81f3\u5c11\u6709\u4e00\u4e2a 1 \u7684\u6700\u5de6\u7aef\u5217](/solution/1400-1499/1428.Leftmost%20Column%20with%20at%20Least%20a%20One/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1428](https://leetcode.com/problems/leftmost-column-with-at-least-a-one)", "[Leftmost Column with at Least a One](/solution/1400-1499/1428.Leftmost%20Column%20with%20at%20Least%20a%20One/README_EN.md)", "`Array`", "Medium", "\ud83d\udd12"]}, {"question_id": "1372", "frontend_question_id": "1250", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/check-if-it-is-a-good-array", "url_en": "https://leetcode.com/problems/check-if-it-is-a-good-array", "relative_path_cn": "/solution/1200-1299/1250.Check%20If%20It%20Is%20a%20Good%20Array/README.md", "relative_path_en": "/solution/1200-1299/1250.Check%20If%20It%20Is%20a%20Good%20Array/README_EN.md", "title_cn": "\u68c0\u67e5\u300c\u597d\u6570\u7ec4\u300d", "title_en": "Check If It Is a Good Array", "question_title_slug": "check-if-it-is-a-good-array", "content_en": "

Given an array nums of positive integers. Your task is to select some subset of nums, multiply each element by an integer and add all these numbers. The array is said to be good if you can obtain a sum of 1 from the array by any possible subset and multiplicand.

\n\n

Return True if the array is good otherwise return False.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [12,5,7,23]\nOutput: true\nExplanation: Pick numbers 5 and 7.\n5*3 + 7*(-2) = 1\n
\n\n

Example 2:

\n\n
\nInput: nums = [29,6,10]\nOutput: true\nExplanation: Pick numbers 29, 6 and 10.\n29*1 + 6*(-3) + 10*(-1) = 1\n
\n\n

Example 3:

\n\n
\nInput: nums = [3,6]\nOutput: false\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 10^5
  • \n\t
  • 1 <= nums[i] <= 10^9
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6b63\u6574\u6570\u6570\u7ec4 nums\uff0c\u4f60\u9700\u8981\u4ece\u4e2d\u4efb\u9009\u4e00\u4e9b\u5b50\u96c6\uff0c\u7136\u540e\u5c06\u5b50\u96c6\u4e2d\u6bcf\u4e00\u4e2a\u6570\u4e58\u4ee5\u4e00\u4e2a \u4efb\u610f\u6574\u6570\uff0c\u5e76\u6c42\u51fa\u4ed6\u4eec\u7684\u548c\u3002

\n\n

\u5047\u5982\u8be5\u548c\u7ed3\u679c\u4e3a 1\uff0c\u90a3\u4e48\u539f\u6570\u7ec4\u5c31\u662f\u4e00\u4e2a\u300c\u597d\u6570\u7ec4\u300d\uff0c\u5219\u8fd4\u56de True\uff1b\u5426\u5219\u8bf7\u8fd4\u56de False\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anums = [12,5,7,23]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u6311\u9009\u6570\u5b57 5 \u548c 7\u3002\n5*3 + 7*(-2) = 1\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anums = [29,6,10]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u6311\u9009\u6570\u5b57 29, 6 \u548c 10\u3002\n29*1 + 6*(-3) + 10*(-1) = 1\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1anums = [3,6]\n\u8f93\u51fa\uff1afalse\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 10^5
  • \n\t
  • 1 <= nums[i] <= 10^9
  • \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isGoodArray(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isGoodArray(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isGoodArray(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: bool\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isGoodArray(self, nums: List[int]) -> bool:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isGoodArray(int* nums, int numsSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsGoodArray(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {boolean}\n */\nvar isGoodArray = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Boolean}\ndef is_good_array(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isGoodArray(_ nums: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isGoodArray(nums []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isGoodArray(nums: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isGoodArray(nums: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_good_array(nums: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Boolean\n */\n function isGoodArray($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isGoodArray(nums: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-good-array nums)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1250](https://leetcode-cn.com/problems/check-if-it-is-a-good-array)", "[\u68c0\u67e5\u300c\u597d\u6570\u7ec4\u300d](/solution/1200-1299/1250.Check%20If%20It%20Is%20a%20Good%20Array/README.md)", "`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[1250](https://leetcode.com/problems/check-if-it-is-a-good-array)", "[Check If It Is a Good Array](/solution/1200-1299/1250.Check%20If%20It%20Is%20a%20Good%20Array/README_EN.md)", "`Math`", "Hard", ""]}, {"question_id": "1371", "frontend_question_id": "1249", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-remove-to-make-valid-parentheses", "url_en": "https://leetcode.com/problems/minimum-remove-to-make-valid-parentheses", "relative_path_cn": "/solution/1200-1299/1249.Minimum%20Remove%20to%20Make%20Valid%20Parentheses/README.md", "relative_path_en": "/solution/1200-1299/1249.Minimum%20Remove%20to%20Make%20Valid%20Parentheses/README_EN.md", "title_cn": "\u79fb\u9664\u65e0\u6548\u7684\u62ec\u53f7", "title_en": "Minimum Remove to Make Valid Parentheses", "question_title_slug": "minimum-remove-to-make-valid-parentheses", "content_en": "

Given a string s of '(' , ')' and lowercase English characters. 

\r\n\r\n

Your task is to remove the minimum number of parentheses ( '(' or ')', in any positions ) so that the resulting parentheses string is valid and return any valid string.

\r\n\r\n

Formally, a parentheses string is valid if and only if:

\r\n\r\n
    \r\n\t
  • It is the empty string, contains only lowercase characters, or
  • \r\n\t
  • It can be written as AB (A concatenated with B), where A and B are valid strings, or
  • \r\n\t
  • It can be written as (A), where A is a valid string.
  • \r\n
\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: s = "lee(t(c)o)de)"\r\nOutput: "lee(t(c)o)de"\r\nExplanation: "lee(t(co)de)" , "lee(t(c)ode)" would also be accepted.\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: s = "a)b(c)d"\r\nOutput: "ab(c)d"\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: s = "))(("\r\nOutput: ""\r\nExplanation: An empty string is also valid.\r\n
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: s = "(a(b(c)d)"\r\nOutput: "a(b(c)d)"\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= s.length <= 10^5
  • \r\n\t
  • s[i] is one of  '(' , ')' and lowercase English letters.
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u7531 '('\u3001')' \u548c\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210\u7684\u5b57\u7b26\u4e32 s\u3002

\n\n

\u4f60\u9700\u8981\u4ece\u5b57\u7b26\u4e32\u4e2d\u5220\u9664\u6700\u5c11\u6570\u76ee\u7684 '(' \u6216\u8005 ')' \uff08\u53ef\u4ee5\u5220\u9664\u4efb\u610f\u4f4d\u7f6e\u7684\u62ec\u53f7)\uff0c\u4f7f\u5f97\u5269\u4e0b\u7684\u300c\u62ec\u53f7\u5b57\u7b26\u4e32\u300d\u6709\u6548\u3002

\n\n

\u8bf7\u8fd4\u56de\u4efb\u610f\u4e00\u4e2a\u5408\u6cd5\u5b57\u7b26\u4e32\u3002

\n\n

\u6709\u6548\u300c\u62ec\u53f7\u5b57\u7b26\u4e32\u300d\u5e94\u5f53\u7b26\u5408\u4ee5\u4e0b \u4efb\u610f\u4e00\u6761 \u8981\u6c42\uff1a

\n\n
    \n\t
  • \u7a7a\u5b57\u7b26\u4e32\u6216\u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd\u7684\u5b57\u7b26\u4e32
  • \n\t
  • \u53ef\u4ee5\u88ab\u5199\u4f5c AB\uff08A \u8fde\u63a5 B\uff09\u7684\u5b57\u7b26\u4e32\uff0c\u5176\u4e2d A \u548c B \u90fd\u662f\u6709\u6548\u300c\u62ec\u53f7\u5b57\u7b26\u4e32\u300d
  • \n\t
  • \u53ef\u4ee5\u88ab\u5199\u4f5c (A) \u7684\u5b57\u7b26\u4e32\uff0c\u5176\u4e2d A \u662f\u4e00\u4e2a\u6709\u6548\u7684\u300c\u62ec\u53f7\u5b57\u7b26\u4e32\u300d
  • \n
\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1as = "lee(t(c)o)de)"\n\u8f93\u51fa\uff1a"lee(t(c)o)de"\n\u89e3\u91ca\uff1a"lee(t(co)de)" , "lee(t(c)ode)" \u4e5f\u662f\u4e00\u4e2a\u53ef\u884c\u7b54\u6848\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1as = "a)b(c)d"\n\u8f93\u51fa\uff1a"ab(c)d"\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1as = "))(("\n\u8f93\u51fa\uff1a""\n\u89e3\u91ca\uff1a\u7a7a\u5b57\u7b26\u4e32\u4e5f\u662f\u6709\u6548\u7684\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1as = "(a(b(c)d)"\n\u8f93\u51fa\uff1a"a(b(c)d)"\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length <= 10^5
  • \n\t
  • s[i] \u53ef\u80fd\u662f '('\u3001')' \u6216\u82f1\u6587\u5c0f\u5199\u5b57\u6bcd
  • \n
\n", "tags_en": ["Stack", "String"], "tags_cn": ["\u6808", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string minRemoveToMakeValid(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String minRemoveToMakeValid(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minRemoveToMakeValid(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minRemoveToMakeValid(self, s: str) -> str:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * minRemoveToMakeValid(char * s){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string MinRemoveToMakeValid(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar minRemoveToMakeValid = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef min_remove_to_make_valid(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minRemoveToMakeValid(_ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minRemoveToMakeValid(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minRemoveToMakeValid(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minRemoveToMakeValid(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_remove_to_make_valid(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function minRemoveToMakeValid($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minRemoveToMakeValid(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-remove-to-make-valid s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1249](https://leetcode-cn.com/problems/minimum-remove-to-make-valid-parentheses)", "[\u79fb\u9664\u65e0\u6548\u7684\u62ec\u53f7](/solution/1200-1299/1249.Minimum%20Remove%20to%20Make%20Valid%20Parentheses/README.md)", "`\u6808`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1249](https://leetcode.com/problems/minimum-remove-to-make-valid-parentheses)", "[Minimum Remove to Make Valid Parentheses](/solution/1200-1299/1249.Minimum%20Remove%20to%20Make%20Valid%20Parentheses/README_EN.md)", "`Stack`,`String`", "Medium", ""]}, {"question_id": "1370", "frontend_question_id": "1248", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-number-of-nice-subarrays", "url_en": "https://leetcode.com/problems/count-number-of-nice-subarrays", "relative_path_cn": "/solution/1200-1299/1248.Count%20Number%20of%20Nice%20Subarrays/README.md", "relative_path_en": "/solution/1200-1299/1248.Count%20Number%20of%20Nice%20Subarrays/README_EN.md", "title_cn": "\u7edf\u8ba1\u300c\u4f18\u7f8e\u5b50\u6570\u7ec4\u300d", "title_en": "Count Number of Nice Subarrays", "question_title_slug": "count-number-of-nice-subarrays", "content_en": "

Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it.

\n\n

Return the number of nice sub-arrays.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [1,1,2,1,1], k = 3\nOutput: 2\nExplanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1].\n
\n\n

Example 2:

\n\n
\nInput: nums = [2,4,6], k = 1\nOutput: 0\nExplanation: There is no odd numbers in the array.\n
\n\n

Example 3:

\n\n
\nInput: nums = [2,2,2,1,2,2,1,2,2,2], k = 2\nOutput: 16\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 50000
  • \n\t
  • 1 <= nums[i] <= 10^5
  • \n\t
  • 1 <= k <= nums.length
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \u548c\u4e00\u4e2a\u6574\u6570 k\u3002

\n\n

\u5982\u679c\u67d0\u4e2a \u8fde\u7eed \u5b50\u6570\u7ec4\u4e2d\u6070\u597d\u6709 k \u4e2a\u5947\u6570\u6570\u5b57\uff0c\u6211\u4eec\u5c31\u8ba4\u4e3a\u8fd9\u4e2a\u5b50\u6570\u7ec4\u662f\u300c\u4f18\u7f8e\u5b50\u6570\u7ec4\u300d\u3002

\n\n

\u8bf7\u8fd4\u56de\u8fd9\u4e2a\u6570\u7ec4\u4e2d\u300c\u4f18\u7f8e\u5b50\u6570\u7ec4\u300d\u7684\u6570\u76ee\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,1,2,1,1], k = 3\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5305\u542b 3 \u4e2a\u5947\u6570\u7684\u5b50\u6570\u7ec4\u662f [1,1,2,1] \u548c [1,2,1,1] \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anums = [2,4,6], k = 1\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6570\u5217\u4e2d\u4e0d\u5305\u542b\u4efb\u4f55\u5947\u6570\uff0c\u6240\u4ee5\u4e0d\u5b58\u5728\u4f18\u7f8e\u5b50\u6570\u7ec4\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1anums = [2,2,2,1,2,2,1,2,2,2], k = 2\n\u8f93\u51fa\uff1a16\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 50000
  • \n\t
  • 1 <= nums[i] <= 10^5
  • \n\t
  • 1 <= k <= nums.length
  • \n
\n", "tags_en": ["Two Pointers"], "tags_cn": ["\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numberOfSubarrays(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numberOfSubarrays(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numberOfSubarrays(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numberOfSubarrays(self, nums: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numberOfSubarrays(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumberOfSubarrays(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar numberOfSubarrays = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef number_of_subarrays(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numberOfSubarrays(_ nums: [Int], _ k: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numberOfSubarrays(nums []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numberOfSubarrays(nums: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numberOfSubarrays(nums: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn number_of_subarrays(nums: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer\n */\n function numberOfSubarrays($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numberOfSubarrays(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (number-of-subarrays nums k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1248](https://leetcode-cn.com/problems/count-number-of-nice-subarrays)", "[\u7edf\u8ba1\u300c\u4f18\u7f8e\u5b50\u6570\u7ec4\u300d](/solution/1200-1299/1248.Count%20Number%20of%20Nice%20Subarrays/README.md)", "`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1248](https://leetcode.com/problems/count-number-of-nice-subarrays)", "[Count Number of Nice Subarrays](/solution/1200-1299/1248.Count%20Number%20of%20Nice%20Subarrays/README_EN.md)", "`Two Pointers`", "Medium", ""]}, {"question_id": "1369", "frontend_question_id": "1247", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-swaps-to-make-strings-equal", "url_en": "https://leetcode.com/problems/minimum-swaps-to-make-strings-equal", "relative_path_cn": "/solution/1200-1299/1247.Minimum%20Swaps%20to%20Make%20Strings%20Equal/README.md", "relative_path_en": "/solution/1200-1299/1247.Minimum%20Swaps%20to%20Make%20Strings%20Equal/README_EN.md", "title_cn": "\u4ea4\u6362\u5b57\u7b26\u4f7f\u5f97\u5b57\u7b26\u4e32\u76f8\u540c", "title_en": "Minimum Swaps to Make Strings Equal", "question_title_slug": "minimum-swaps-to-make-strings-equal", "content_en": "

You are given two strings s1 and s2 of equal length consisting of letters "x" and "y" only. Your task is to make these two strings equal to each other. You can swap any two characters that belong to different strings, which means: swap s1[i] and s2[j].

\r\n\r\n

Return the minimum number of swaps required to make s1 and s2 equal, or return -1 if it is impossible to do so.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: s1 = "xx", s2 = "yy"\r\nOutput: 1\r\nExplanation: \r\nSwap s1[0] and s2[1], s1 = "yx", s2 = "yx".
\r\n\r\n

Example 2: 

\r\n\r\n
\r\nInput: s1 = "xy", s2 = "yx"\r\nOutput: 2\r\nExplanation: \r\nSwap s1[0] and s2[0], s1 = "yy", s2 = "xx".\r\nSwap s1[0] and s2[1], s1 = "xy", s2 = "xy".\r\nNote that you can't swap s1[0] and s1[1] to make s1 equal to "yx", cause we can only swap chars in different strings.
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: s1 = "xx", s2 = "xy"\r\nOutput: -1\r\n
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: s1 = "xxyyxyxyxx", s2 = "xyyxyxxxyx"\r\nOutput: 4\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= s1.length, s2.length <= 1000
  • \r\n\t
  • s1, s2 only contain 'x' or 'y'.
  • \r\n
", "content_cn": "

\u6709\u4e24\u4e2a\u957f\u5ea6\u76f8\u540c\u7684\u5b57\u7b26\u4e32 s1 \u548c s2\uff0c\u4e14\u5b83\u4eec\u5176\u4e2d \u53ea\u542b\u6709 \u5b57\u7b26 "x" \u548c "y"\uff0c\u4f60\u9700\u8981\u901a\u8fc7\u300c\u4ea4\u6362\u5b57\u7b26\u300d\u7684\u65b9\u5f0f\u4f7f\u8fd9\u4e24\u4e2a\u5b57\u7b26\u4e32\u76f8\u540c\u3002

\n\n

\u6bcf\u6b21\u300c\u4ea4\u6362\u5b57\u7b26\u300d\u7684\u65f6\u5019\uff0c\u4f60\u90fd\u53ef\u4ee5\u5728\u4e24\u4e2a\u5b57\u7b26\u4e32\u4e2d\u5404\u9009\u4e00\u4e2a\u5b57\u7b26\u8fdb\u884c\u4ea4\u6362\u3002

\n\n

\u4ea4\u6362\u53ea\u80fd\u53d1\u751f\u5728\u4e24\u4e2a\u4e0d\u540c\u7684\u5b57\u7b26\u4e32\u4e4b\u95f4\uff0c\u7edd\u5bf9\u4e0d\u80fd\u53d1\u751f\u5728\u540c\u4e00\u4e2a\u5b57\u7b26\u4e32\u5185\u90e8\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u6211\u4eec\u53ef\u4ee5\u4ea4\u6362 s1[i] \u548c s2[j]\uff0c\u4f46\u4e0d\u80fd\u4ea4\u6362 s1[i] \u548c s1[j]\u3002

\n\n

\u6700\u540e\uff0c\u8bf7\u4f60\u8fd4\u56de\u4f7f s1 \u548c s2 \u76f8\u540c\u7684\u6700\u5c0f\u4ea4\u6362\u6b21\u6570\uff0c\u5982\u679c\u6ca1\u6709\u65b9\u6cd5\u80fd\u591f\u4f7f\u5f97\u8fd9\u4e24\u4e2a\u5b57\u7b26\u4e32\u76f8\u540c\uff0c\u5219\u8fd4\u56de -1 \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1as1 = "xx", s2 = "yy"\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\n\u4ea4\u6362 s1[0] \u548c s2[1]\uff0c\u5f97\u5230 s1 = "yx"\uff0cs2 = "yx"\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1as1 = "xy", s2 = "yx"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n\u4ea4\u6362 s1[0] \u548c s2[0]\uff0c\u5f97\u5230 s1 = "yy"\uff0cs2 = "xx" \u3002\n\u4ea4\u6362 s1[0] \u548c s2[1]\uff0c\u5f97\u5230 s1 = "xy"\uff0cs2 = "xy" \u3002\n\u6ce8\u610f\uff0c\u4f60\u4e0d\u80fd\u4ea4\u6362 s1[0] \u548c s1[1] \u4f7f\u5f97 s1 \u53d8\u6210 "yx"\uff0c\u56e0\u4e3a\u6211\u4eec\u53ea\u80fd\u4ea4\u6362\u5c5e\u4e8e\u4e24\u4e2a\u4e0d\u540c\u5b57\u7b26\u4e32\u7684\u5b57\u7b26\u3002
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1as1 = "xx", s2 = "xy"\n\u8f93\u51fa\uff1a-1\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1as1 = "xxyyxyxyxx", s2 = "xyyxyxxxyx"\n\u8f93\u51fa\uff1a4\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s1.length, s2.length <= 1000
  • \n\t
  • s1, s2 \u53ea\u5305\u542b 'x' \u6216 'y'\u3002
  • \n
\n", "tags_en": ["Greedy", "String"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minimumSwap(string s1, string s2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minimumSwap(String s1, String s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimumSwap(self, s1, s2):\n \"\"\"\n :type s1: str\n :type s2: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimumSwap(self, s1: str, s2: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "int minimumSwap(char * s1, char * s2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinimumSwap(string s1, string s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s1\n * @param {string} s2\n * @return {number}\n */\nvar minimumSwap = function(s1, s2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s1\n# @param {String} s2\n# @return {Integer}\ndef minimum_swap(s1, s2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimumSwap(_ s1: String, _ s2: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimumSwap(s1 string, s2 string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimumSwap(s1: String, s2: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimumSwap(s1: String, s2: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimum_swap(s1: String, s2: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s1\n * @param String $s2\n * @return Integer\n */\n function minimumSwap($s1, $s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimumSwap(s1: string, s2: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimum-swap s1 s2)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1247](https://leetcode-cn.com/problems/minimum-swaps-to-make-strings-equal)", "[\u4ea4\u6362\u5b57\u7b26\u4f7f\u5f97\u5b57\u7b26\u4e32\u76f8\u540c](/solution/1200-1299/1247.Minimum%20Swaps%20to%20Make%20Strings%20Equal/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1247](https://leetcode.com/problems/minimum-swaps-to-make-strings-equal)", "[Minimum Swaps to Make Strings Equal](/solution/1200-1299/1247.Minimum%20Swaps%20to%20Make%20Strings%20Equal/README_EN.md)", "`Greedy`,`String`", "Medium", ""]}, {"question_id": "1368", "frontend_question_id": "1242", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/web-crawler-multithreaded", "url_en": "https://leetcode.com/problems/web-crawler-multithreaded", "relative_path_cn": "/solution/1200-1299/1242.Web%20Crawler%20Multithreaded/README.md", "relative_path_en": "/solution/1200-1299/1242.Web%20Crawler%20Multithreaded/README_EN.md", "title_cn": "\u591a\u7ebf\u7a0b\u7f51\u9875\u722c\u866b", "title_en": "Web Crawler Multithreaded", "question_title_slug": "web-crawler-multithreaded", "content_en": "

Given a url startUrl and an interface HtmlParser, implement a Multi-threaded web crawler to crawl all links that are under the same hostname as startUrl

\n\n

Return all urls obtained by your web crawler in any order.

\n\n

Your crawler should:

\n\n
    \n\t
  • Start from the page: startUrl
  • \n\t
  • Call HtmlParser.getUrls(url) to get all urls from a webpage of given url.
  • \n\t
  • Do not crawl the same link twice.
  • \n\t
  • Explore only the links that are under the same hostname as startUrl.
  • \n
\n\n

\"\"

\n\n

As shown in the example url above, the hostname is example.org. For simplicity sake, you may assume all urls use http protocol without any port specified. For example, the urls http://leetcode.com/problems and http://leetcode.com/contest are under the same hostname, while urls http://example.org/test and http://example.com/abc are not under the same hostname.

\n\n

The HtmlParser interface is defined as such: 

\n\n
\ninterface HtmlParser {\n  // Return a list of all urls from a webpage of given url.\n  // This is a blocking call, that means it will do HTTP request and return when this request is finished.\n  public List<String> getUrls(String url);\n}
\n\n

Note that getUrls(String url) simulates performing a HTTP request. You can treat it as a blocking function call which waits for a HTTP request to finish. It is guaranteed that getUrls(String url) will return the urls within 15ms.  Single-threaded solutions will exceed the time limit so, can your multi-threaded web crawler do better?

\n\n

Below are two examples explaining the functionality of the problem, for custom testing purposes you'll have three variables urlsedges and startUrl. Notice that you will only have access to startUrl in your code, while urls and edges are not directly accessible to you in code.

\n\n

 

\n\n

Follow up:

\n\n
    \n\t
  1. Assume we have 10,000 nodes and 1 billion URLs to crawl. We will deploy the same software onto each node. The software can know about all the nodes. We have to minimize communication between machines and make sure each node does equal amount of work. How would your web crawler design change?
  2. \n\t
  3. What if one node fails or does not work?
  4. \n\t
  5. How do you know when the crawler is done?
  6. \n
\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput:\nurls = [\n  "http://news.yahoo.com",\n  "http://news.yahoo.com/news",\n  "http://news.yahoo.com/news/topics/",\n  "http://news.google.com",\n  "http://news.yahoo.com/us"\n]\nedges = [[2,0],[2,1],[3,2],[3,1],[0,4]]\nstartUrl = "http://news.yahoo.com/news/topics/"\nOutput: [\n  "http://news.yahoo.com",\n  "http://news.yahoo.com/news",\n  "http://news.yahoo.com/news/topics/",\n  "http://news.yahoo.com/us"\n]\n
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: \nurls = [\n  "http://news.yahoo.com",\n  "http://news.yahoo.com/news",\n  "http://news.yahoo.com/news/topics/",\n  "http://news.google.com"\n]\nedges = [[0,2],[2,1],[3,2],[3,1],[3,0]]\nstartUrl = "http://news.google.com"\nOutput: ["http://news.google.com"]\nExplanation: The startUrl links to all other pages that do not share the same hostname.
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= urls.length <= 1000
  • \n\t
  • 1 <= urls[i].length <= 300
  • \n\t
  • startUrl is one of the urls.
  • \n\t
  • Hostname label must be from 1 to 63 characters long, including the dots, may contain only the ASCII letters from 'a' to 'z', digits from '0' to '9' and the hyphen-minus character ('-').
  • \n\t
  • The hostname may not start or end with the hyphen-minus character ('-'). 
  • \n\t
  • See:  https://en.wikipedia.org/wiki/Hostname#Restrictions_on_valid_hostnames
  • \n\t
  • You may assume there're no duplicates in url library.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u521d\u59cb\u5730\u5740 startUrl \u548c\u4e00\u4e2a HTML \u89e3\u6790\u5668\u63a5\u53e3 HtmlParser\uff0c\u8bf7\u4f60\u5b9e\u73b0\u4e00\u4e2a \u591a\u7ebf\u7a0b\u7684\u7f51\u9875\u722c\u866b\uff0c\u7528\u4e8e\u83b7\u53d6\u4e0e startUrl \u6709 \u76f8\u540c\u4e3b\u673a\u540d \u7684\u6240\u6709\u94fe\u63a5\u3002 

\n\n

\u4ee5 \u4efb\u610f \u987a\u5e8f\u8fd4\u56de\u722c\u866b\u83b7\u53d6\u7684\u8def\u5f84\u3002

\n\n

\u722c\u866b\u5e94\u8be5\u9075\u5faa\uff1a

\n\n
    \n\t
  • \u4ece startUrl \u5f00\u59cb
  • \n\t
  • \u8c03\u7528 HtmlParser.getUrls(url) \u4ece\u6307\u5b9a\u7f51\u9875\u8def\u5f84\u83b7\u5f97\u7684\u6240\u6709\u8def\u5f84\u3002
  • \n\t
  • \u4e0d\u8981\u6293\u53d6\u76f8\u540c\u7684\u94fe\u63a5\u4e24\u6b21\u3002
  • \n\t
  • \u4ec5\u6d4f\u89c8\u4e0e startUrl \u76f8\u540c\u4e3b\u673a\u540d \u7684\u94fe\u63a5\u3002
  • \n
\n\n

\"\"\"\"

\n\n

\u5982\u4e0a\u56fe\u6240\u793a\uff0c\u4e3b\u673a\u540d\u662f example.org \u3002\u7b80\u5355\u8d77\u89c1\uff0c\u4f60\u53ef\u4ee5\u5047\u8bbe\u6240\u6709\u94fe\u63a5\u90fd\u91c7\u7528 http \u534f\u8bae\uff0c\u5e76\u4e14\u6ca1\u6709\u6307\u5b9a \u7aef\u53e3\u53f7\u3002\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u94fe\u63a5 http://leetcode.com/problems \u548c\u94fe\u63a5 http://leetcode.com/contest \u5c5e\u4e8e\u540c\u4e00\u4e2a \u4e3b\u673a\u540d\uff0c \u800c http://example.org/test \u4e0e http://example.com/abc \u5e76\u4e0d\u5c5e\u4e8e\u540c\u4e00\u4e2a \u4e3b\u673a\u540d\u3002

\n\n

HtmlParser \u7684\u63a5\u53e3\u5b9a\u4e49\u5982\u4e0b\uff1a

\n\n
\ninterface HtmlParser {\n  // Return a list of all urls from a webpage of given url.\n  // This is a blocking call, that means it will do HTTP request and return when this request is finished.\n  public List<String> getUrls(String url);\n}
\n\n

\u6ce8\u610f\u4e00\u70b9\uff0cgetUrls(String url) \u6a21\u62df\u6267\u884c\u4e00\u4e2aHTTP\u7684\u8bf7\u6c42\u3002 \u4f60\u53ef\u4ee5\u5c06\u5b83\u5f53\u505a\u4e00\u4e2a\u963b\u585e\u5f0f\u7684\u65b9\u6cd5\uff0c\u76f4\u5230\u8bf7\u6c42\u7ed3\u675f\u3002 getUrls(String url) \u4fdd\u8bc1\u4f1a\u5728 15ms \u5185\u8fd4\u56de\u6240\u6709\u7684\u8def\u5f84\u3002 \u5355\u7ebf\u7a0b\u7684\u65b9\u6848\u4f1a\u8d85\u8fc7\u65f6\u95f4\u9650\u5236\uff0c\u4f60\u80fd\u7528\u591a\u7ebf\u7a0b\u65b9\u6848\u505a\u7684\u66f4\u597d\u5417\uff1f

\n\n

\u5bf9\u4e8e\u95ee\u9898\u6240\u9700\u7684\u529f\u80fd\uff0c\u4e0b\u9762\u63d0\u4f9b\u4e86\u4e24\u4e2a\u4f8b\u5b50\u3002\u4e3a\u4e86\u65b9\u4fbf\u81ea\u5b9a\u4e49\u6d4b\u8bd5\uff0c\u4f60\u53ef\u4ee5\u58f0\u660e\u4e09\u4e2a\u53d8\u91cf urls\uff0cedges \u548c startUrl\u3002\u4f46\u8981\u6ce8\u610f\u4f60\u53ea\u80fd\u5728\u4ee3\u7801\u4e2d\u8bbf\u95ee startUrl\uff0c\u5e76\u4e0d\u80fd\u76f4\u63a5\u8bbf\u95ee urls \u548c edges\u3002

\n\n

 

\n\n

\u62d3\u5c55\u95ee\u9898\uff1a

\n\n
    \n\t
  1. \u5047\u8bbe\u6211\u4eec\u8981\u8981\u6293\u53d6 10000 \u4e2a\u8282\u70b9\u548c 10 \u4ebf\u4e2a\u8def\u5f84\u3002\u5e76\u4e14\u5728\u6bcf\u4e2a\u8282\u70b9\u90e8\u7f72\u76f8\u540c\u7684\u7684\u8f6f\u4ef6\u3002\u8f6f\u4ef6\u53ef\u4ee5\u53d1\u73b0\u6240\u6709\u7684\u8282\u70b9\u3002\u6211\u4eec\u5fc5\u987b\u5c3d\u53ef\u80fd\u51cf\u5c11\u673a\u5668\u4e4b\u95f4\u7684\u901a\u8baf\uff0c\u5e76\u786e\u4fdd\u6bcf\u4e2a\u8282\u70b9\u8d1f\u8f7d\u5747\u8861\u3002\u4f60\u5c06\u5982\u4f55\u8bbe\u8ba1\u8fd9\u4e2a\u7f51\u9875\u722c\u866b\uff1f
  2. \n\t
  3. \u5982\u679c\u6709\u4e00\u4e2a\u8282\u70b9\u53d1\u751f\u6545\u969c\u4e0d\u5de5\u4f5c\u8be5\u600e\u4e48\u529e\uff1f
  4. \n\t
  5. \u5982\u4f55\u786e\u8ba4\u722c\u866b\u4efb\u52a1\u5df2\u7ecf\u5b8c\u6210\uff1f
  6. \n
\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"\"\"

\n\n
\n\u8f93\u5165\uff1a\nurls = [\n  "http://news.yahoo.com",\n  "http://news.yahoo.com/news",\n  "http://news.yahoo.com/news/topics/",\n  "http://news.google.com",\n  "http://news.yahoo.com/us"\n]\nedges = [[2,0],[2,1],[3,2],[3,1],[0,4]]\nstartUrl = "http://news.yahoo.com/news/topics/"\n\u8f93\u51fa\uff1a[\n  "http://news.yahoo.com",\n  "http://news.yahoo.com/news",\n  "http://news.yahoo.com/news/topics/",\n  "http://news.yahoo.com/us"\n]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"\"\"

\n\n
\n\u8f93\u5165\uff1a\nurls = [\n  "http://news.yahoo.com",\n  "http://news.yahoo.com/news",\n  "http://news.yahoo.com/news/topics/",\n  "http://news.google.com"\n]\nedges = [[0,2],[2,1],[3,2],[3,1],[3,0]]\nstartUrl = "http://news.google.com"\n\u8f93\u51fa\uff1a["http://news.google.com"]\n\u89e3\u91ca\uff1astartUrl \u94fe\u63a5\u4e0e\u5176\u4ed6\u9875\u9762\u4e0d\u5171\u4eab\u4e00\u4e2a\u4e3b\u673a\u540d\u3002
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= urls.length <= 1000
  • \n\t
  • 1 <= urls[i].length <= 300
  • \n\t
  • startUrl \u662f urls \u4e2d\u7684\u4e00\u4e2a\u3002
  • \n\t
  • \u4e3b\u673a\u540d\u7684\u957f\u5ea6\u5fc5\u987b\u4e3a 1 \u5230 63 \u4e2a\u5b57\u7b26\uff08\u5305\u62ec\u70b9 . \u5728\u5185\uff09\uff0c\u53ea\u80fd\u5305\u542b\u4ece “a” \u5230 “z” \u7684 ASCII \u5b57\u6bcd\u548c “0” \u5230 “9” \u7684\u6570\u5b57\uff0c\u4ee5\u53ca\u4e2d\u5212\u7ebf “-”\u3002
  • \n\t
  • \u4e3b\u673a\u540d\u5f00\u5934\u548c\u7ed3\u5c3e\u4e0d\u80fd\u662f\u4e2d\u5212\u7ebf “-”\u3002
  • \n\t
  • \u53c2\u8003\u8d44\u6599\uff1ahttps://en.wikipedia.org/wiki/Hostname#Restrictions_on_valid_hostnames
  • \n\t
  • \u4f60\u53ef\u4ee5\u5047\u8bbe\u8def\u5f84\u90fd\u662f\u4e0d\u91cd\u590d\u7684\u3002
  • \n
\n", "tags_en": ["Depth-first Search", "Breadth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * // This is the HtmlParser's API interface.\n * // You should not implement it, or speculate about its implementation\n * class HtmlParser {\n * public:\n * vector getUrls(string url);\n * };\n */\nclass Solution {\npublic:\n vector crawl(string startUrl, HtmlParser htmlParser) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * // This is the HtmlParser's API interface.\n * // You should not implement it, or speculate about its implementation\n * interface HtmlParser {\n * public List getUrls(String url) {}\n * }\n */\nclass Solution {\n public List crawl(String startUrl, HtmlParser htmlParser) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# \"\"\"\n# This is HtmlParser's API interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class HtmlParser(object):\n# def getUrls(self, url):\n# \"\"\"\n# :type url: str\n# :rtype List[str]\n# \"\"\"\n\nclass Solution(object):\n def crawl(self, startUrl, htmlParser):\n \"\"\"\n :type startUrl: str\n :type htmlParser: HtmlParser\n :rtype: List[str]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# \"\"\"\n# This is HtmlParser's API interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class HtmlParser(object):\n# def getUrls(self, url):\n# \"\"\"\n# :type url: str\n# :rtype List[str]\n# \"\"\"\n\nclass Solution:\n def crawl(self, startUrl: str, htmlParser: 'HtmlParser') -> List[str]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * // This is the HtmlParser's API interface.\n * // You should not implement it, or speculate about its implementation\n * class HtmlParser {\n * public List GetUrls(String url) {}\n * }\n */\nclass Solution {\n public IList Crawl(string startUrl, HtmlParser htmlParser) {\n \n }\n}", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1242](https://leetcode-cn.com/problems/web-crawler-multithreaded)", "[\u591a\u7ebf\u7a0b\u7f51\u9875\u722c\u866b](/solution/1200-1299/1242.Web%20Crawler%20Multithreaded/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1242](https://leetcode.com/problems/web-crawler-multithreaded)", "[Web Crawler Multithreaded](/solution/1200-1299/1242.Web%20Crawler%20Multithreaded/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`", "Medium", "\ud83d\udd12"]}, {"question_id": "1367", "frontend_question_id": "1691", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-height-by-stacking-cuboids", "url_en": "https://leetcode.com/problems/maximum-height-by-stacking-cuboids", "relative_path_cn": "/solution/1600-1699/1691.Maximum%20Height%20by%20Stacking%20Cuboids/README.md", "relative_path_en": "/solution/1600-1699/1691.Maximum%20Height%20by%20Stacking%20Cuboids/README_EN.md", "title_cn": "\u5806\u53e0\u957f\u65b9\u4f53\u7684\u6700\u5927\u9ad8\u5ea6", "title_en": "Maximum Height by Stacking Cuboids", "question_title_slug": "maximum-height-by-stacking-cuboids", "content_en": "

Given n cuboids where the dimensions of the ith cuboid is cuboids[i] = [widthi, lengthi, heighti] (0-indexed). Choose a subset of cuboids and place them on each other.

\n\n

You can place cuboid i on cuboid j if widthi <= widthj and lengthi <= lengthj and heighti <= heightj. You can rearrange any cuboid's dimensions by rotating it to put it on another cuboid.

\n\n

Return the maximum height of the stacked cuboids.

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: cuboids = [[50,45,20],[95,37,53],[45,23,12]]\nOutput: 190\nExplanation:\nCuboid 1 is placed on the bottom with the 53x37 side facing down with height 95.\nCuboid 0 is placed next with the 45x20 side facing down with height 50.\nCuboid 2 is placed next with the 23x12 side facing down with height 45.\nThe total height is 95 + 50 + 45 = 190.\n
\n\n

Example 2:

\n\n
\nInput: cuboids = [[38,25,45],[76,35,3]]\nOutput: 76\nExplanation:\nYou can't place any of the cuboids on the other.\nWe choose cuboid 1 and rotate it so that the 35x3 side is facing down and its height is 76.\n
\n\n

Example 3:

\n\n
\nInput: cuboids = [[7,11,17],[7,17,11],[11,7,17],[11,17,7],[17,7,11],[17,11,7]]\nOutput: 102\nExplanation:\nAfter rearranging the cuboids, you can see that all cuboids have the same dimension.\nYou can place the 11x7 side down on all cuboids so their heights are 17.\nThe maximum height of stacked cuboids is 6 * 17 = 102.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == cuboids.length
  • \n\t
  • 1 <= n <= 100
  • \n\t
  • 1 <= widthi, lengthi, heighti <= 100
  • \n
\n", "content_cn": "

\u7ed9\u4f60 n \u4e2a\u957f\u65b9\u4f53 cuboids \uff0c\u5176\u4e2d\u7b2c i \u4e2a\u957f\u65b9\u4f53\u7684\u957f\u5bbd\u9ad8\u8868\u793a\u4e3a cuboids[i] = [widthi, lengthi, heighti]\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\u3002\u8bf7\u4f60\u4ece cuboids \u9009\u51fa\u4e00\u4e2a \u5b50\u96c6 \uff0c\u5e76\u5c06\u5b83\u4eec\u5806\u53e0\u8d77\u6765\u3002

\n\n

\u5982\u679c widthi <= widthj \u4e14 lengthi <= lengthj \u4e14 heighti <= heightj \uff0c\u4f60\u5c31\u53ef\u4ee5\u5c06\u957f\u65b9\u4f53 i \u5806\u53e0\u5728\u957f\u65b9\u4f53 j \u4e0a\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u65cb\u8f6c\u628a\u957f\u65b9\u4f53\u7684\u957f\u5bbd\u9ad8\u91cd\u65b0\u6392\u5217\uff0c\u4ee5\u5c06\u5b83\u653e\u5728\u53e6\u4e00\u4e2a\u957f\u65b9\u4f53\u4e0a\u3002

\n\n

\u8fd4\u56de \u5806\u53e0\u957f\u65b9\u4f53\u00a0cuboids \u53ef\u4ee5\u5f97\u5230\u7684 \u6700\u5927\u9ad8\u5ea6 \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1acuboids = [[50,45,20],[95,37,53],[45,23,12]]\n\u8f93\u51fa\uff1a190\n\u89e3\u91ca\uff1a\n\u7b2c 1 \u4e2a\u957f\u65b9\u4f53\u653e\u5728\u5e95\u90e8\uff0c53x37 \u7684\u4e00\u9762\u671d\u4e0b\uff0c\u9ad8\u5ea6\u4e3a 95 \u3002\n\u7b2c 0 \u4e2a\u957f\u65b9\u4f53\u653e\u5728\u4e2d\u95f4\uff0c45x20 \u7684\u4e00\u9762\u671d\u4e0b\uff0c\u9ad8\u5ea6\u4e3a 50 \u3002\n\u7b2c 2 \u4e2a\u957f\u65b9\u4f53\u653e\u5728\u4e0a\u9762\uff0c23x12 \u7684\u4e00\u9762\u671d\u4e0b\uff0c\u9ad8\u5ea6\u4e3a 45 \u3002\n\u603b\u9ad8\u5ea6\u662f 95 + 50 + 45 = 190 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1acuboids = [[38,25,45],[76,35,3]]\n\u8f93\u51fa\uff1a76\n\u89e3\u91ca\uff1a\n\u65e0\u6cd5\u5c06\u4efb\u4f55\u957f\u65b9\u4f53\u653e\u5728\u53e6\u4e00\u4e2a\u4e0a\u9762\u3002\n\u9009\u62e9\u7b2c 1 \u4e2a\u957f\u65b9\u4f53\u7136\u540e\u65cb\u8f6c\u5b83\uff0c\u4f7f 35x3 \u7684\u4e00\u9762\u671d\u4e0b\uff0c\u5176\u9ad8\u5ea6\u4e3a 76 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1acuboids = [[7,11,17],[7,17,11],[11,7,17],[11,17,7],[17,7,11],[17,11,7]]\n\u8f93\u51fa\uff1a102\n\u89e3\u91ca\uff1a\n\u91cd\u65b0\u6392\u5217\u957f\u65b9\u4f53\u540e\uff0c\u53ef\u4ee5\u770b\u5230\u6240\u6709\u957f\u65b9\u4f53\u7684\u5c3a\u5bf8\u90fd\u76f8\u540c\u3002\n\u4f60\u53ef\u4ee5\u628a 11x7 \u7684\u4e00\u9762\u671d\u4e0b\uff0c\u8fd9\u6837\u5b83\u4eec\u7684\u9ad8\u5ea6\u5c31\u662f 17 \u3002\n\u5806\u53e0\u957f\u65b9\u4f53\u7684\u6700\u5927\u9ad8\u5ea6\u4e3a 6 * 17 = 102 \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • n == cuboids.length
  • \n\t
  • 1 <= n <= 100
  • \n\t
  • 1 <= widthi, lengthi, heighti <= 100
  • \n
\n", "tags_en": ["Sort", "Dynamic Programming"], "tags_cn": ["\u6392\u5e8f", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxHeight(vector>& cuboids) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxHeight(int[][] cuboids) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxHeight(self, cuboids):\n \"\"\"\n :type cuboids: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxHeight(self, cuboids: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxHeight(int** cuboids, int cuboidsSize, int* cuboidsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxHeight(int[][] cuboids) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} cuboids\n * @return {number}\n */\nvar maxHeight = function(cuboids) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} cuboids\n# @return {Integer}\ndef max_height(cuboids)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxHeight(_ cuboids: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxHeight(cuboids [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxHeight(cuboids: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxHeight(cuboids: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_height(cuboids: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $cuboids\n * @return Integer\n */\n function maxHeight($cuboids) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxHeight(cuboids: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-height cuboids)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1691](https://leetcode-cn.com/problems/maximum-height-by-stacking-cuboids)", "[\u5806\u53e0\u957f\u65b9\u4f53\u7684\u6700\u5927\u9ad8\u5ea6](/solution/1600-1699/1691.Maximum%20Height%20by%20Stacking%20Cuboids/README.md)", "`\u6392\u5e8f`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1691](https://leetcode.com/problems/maximum-height-by-stacking-cuboids)", "[Maximum Height by Stacking Cuboids](/solution/1600-1699/1691.Maximum%20Height%20by%20Stacking%20Cuboids/README_EN.md)", "`Sort`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "1366", "frontend_question_id": "1429", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/first-unique-number", "url_en": "https://leetcode.com/problems/first-unique-number", "relative_path_cn": "/solution/1400-1499/1429.First%20Unique%20Number/README.md", "relative_path_en": "/solution/1400-1499/1429.First%20Unique%20Number/README_EN.md", "title_cn": "\u7b2c\u4e00\u4e2a\u552f\u4e00\u6570\u5b57", "title_en": "First Unique Number", "question_title_slug": "first-unique-number", "content_en": "

You have a queue of integers, you need to retrieve the first unique integer in the queue.

\n\n

Implement the FirstUnique class:

\n\n
    \n\t
  • FirstUnique(int[] nums) Initializes the object with the numbers in the queue.
  • \n\t
  • int showFirstUnique() returns the value of the first unique integer of the queue, and returns -1 if there is no such integer.
  • \n\t
  • void add(int value) insert value to the queue.
  • \n
\n\n

 

\n

Example 1:

\n\n
\nInput: \n["FirstUnique","showFirstUnique","add","showFirstUnique","add","showFirstUnique","add","showFirstUnique"]\n[[[2,3,5]],[],[5],[],[2],[],[3],[]]\nOutput: \n[null,2,null,2,null,3,null,-1]\nExplanation: \nFirstUnique firstUnique = new FirstUnique([2,3,5]);\nfirstUnique.showFirstUnique(); // return 2\nfirstUnique.add(5);            // the queue is now [2,3,5,5]\nfirstUnique.showFirstUnique(); // return 2\nfirstUnique.add(2);            // the queue is now [2,3,5,5,2]\nfirstUnique.showFirstUnique(); // return 3\nfirstUnique.add(3);            // the queue is now [2,3,5,5,2,3]\nfirstUnique.showFirstUnique(); // return -1\n
\n\n

Example 2:

\n\n
\nInput: \n["FirstUnique","showFirstUnique","add","add","add","add","add","showFirstUnique"]\n[[[7,7,7,7,7,7]],[],[7],[3],[3],[7],[17],[]]\nOutput: \n[null,-1,null,null,null,null,null,17]\nExplanation: \nFirstUnique firstUnique = new FirstUnique([7,7,7,7,7,7]);\nfirstUnique.showFirstUnique(); // return -1\nfirstUnique.add(7);            // the queue is now [7,7,7,7,7,7,7]\nfirstUnique.add(3);            // the queue is now [7,7,7,7,7,7,7,3]\nfirstUnique.add(3);            // the queue is now [7,7,7,7,7,7,7,3,3]\nfirstUnique.add(7);            // the queue is now [7,7,7,7,7,7,7,3,3,7]\nfirstUnique.add(17);           // the queue is now [7,7,7,7,7,7,7,3,3,7,17]\nfirstUnique.showFirstUnique(); // return 17\n
\n\n

Example 3:

\n\n
\nInput: \n["FirstUnique","showFirstUnique","add","showFirstUnique"]\n[[[809]],[],[809],[]]\nOutput: \n[null,809,null,-1]\nExplanation: \nFirstUnique firstUnique = new FirstUnique([809]);\nfirstUnique.showFirstUnique(); // return 809\nfirstUnique.add(809);          // the queue is now [809,809]\nfirstUnique.showFirstUnique(); // return -1\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 10^5
  • \n\t
  • 1 <= nums[i] <= 10^8
  • \n\t
  • 1 <= value <= 10^8
  • \n\t
  • At most 50000 calls will be made to showFirstUnique and add.
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u7cfb\u5217\u6574\u6570\uff0c\u63d2\u5165\u4e00\u4e2a\u961f\u5217\u4e2d\uff0c\u627e\u51fa\u961f\u5217\u4e2d\u7b2c\u4e00\u4e2a\u552f\u4e00\u6574\u6570\u3002

\n\n

\u5b9e\u73b0\u00a0FirstUnique\u00a0\u7c7b\uff1a

\n\n
    \n\t
  • FirstUnique(int[] nums) \u7528\u6570\u7ec4\u91cc\u7684\u6570\u5b57\u521d\u59cb\u5316\u961f\u5217\u3002
  • \n\t
  • int showFirstUnique()\u00a0\u8fd4\u56de\u961f\u5217\u4e2d\u7684 \u7b2c\u4e00\u4e2a\u552f\u4e00 \u6574\u6570\u7684\u503c\u3002\u5982\u679c\u6ca1\u6709\u552f\u4e00\u6574\u6570\uff0c\u8fd4\u56de -1\u3002\uff08\u8bd1\u8005\u6ce8\uff1a\u6b64\u65b9\u6cd5\u4e0d\u79fb\u9664\u961f\u5217\u4e2d\u7684\u4efb\u4f55\u5143\u7d20\uff09
  • \n\t
  • void add(int value)\u00a0\u5c06 value \u63d2\u5165\u961f\u5217\u4e2d\u3002
  • \n
\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1a\n[\"FirstUnique\",\"showFirstUnique\",\"add\",\"showFirstUnique\",\"add\",\"showFirstUnique\",\"add\",\"showFirstUnique\"]\n[[[2,3,5]],[],[5],[],[2],[],[3],[]]\n\u8f93\u51fa\uff1a\n[null,2,null,2,null,3,null,-1]\n\u89e3\u91ca\uff1a\nFirstUnique firstUnique = new FirstUnique([2,3,5]);\nfirstUnique.showFirstUnique(); // \u8fd4\u56de 2\nfirstUnique.add(5);            // \u6b64\u65f6\u961f\u5217\u4e3a [2,3,5,5]\nfirstUnique.showFirstUnique(); // \u8fd4\u56de 2\nfirstUnique.add(2);\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 // \u6b64\u65f6\u961f\u5217\u4e3a [2,3,5,5,2]\nfirstUnique.showFirstUnique(); // \u8fd4\u56de 3\nfirstUnique.add(3);\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 // \u6b64\u65f6\u961f\u5217\u4e3a [2,3,5,5,2,3]\nfirstUnique.showFirstUnique(); // \u8fd4\u56de -1\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1a\n[\"FirstUnique\",\"showFirstUnique\",\"add\",\"add\",\"add\",\"add\",\"add\",\"showFirstUnique\"]\n[[[7,7,7,7,7,7]],[],[7],[3],[3],[7],[17],[]]\n\u8f93\u51fa\uff1a\n[null,-1,null,null,null,null,null,17]\n\u89e3\u91ca\uff1a\nFirstUnique firstUnique = new FirstUnique([7,7,7,7,7,7]);\nfirstUnique.showFirstUnique(); // \u8fd4\u56de -1\nfirstUnique.add(7);            // \u6b64\u65f6\u961f\u5217\u4e3a [7,7,7,7,7,7,7]\nfirstUnique.add(3);\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 // \u6b64\u65f6\u961f\u5217\u4e3a [7,7,7,7,7,7,7,3]\nfirstUnique.add(3);\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 // \u6b64\u65f6\u961f\u5217\u4e3a [7,7,7,7,7,7,7,3,3]\nfirstUnique.add(7);\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 // \u6b64\u65f6\u961f\u5217\u4e3a [7,7,7,7,7,7,7,3,3,7]\nfirstUnique.add(17);\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0// \u6b64\u65f6\u961f\u5217\u4e3a [7,7,7,7,7,7,7,3,3,7,17]\nfirstUnique.showFirstUnique(); // \u8fd4\u56de 17\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1a\n[\"FirstUnique\",\"showFirstUnique\",\"add\",\"showFirstUnique\"]\n[[[809]],[],[809],[]]\n\u8f93\u51fa\uff1a\n[null,809,null,-1]\n\u89e3\u91ca\uff1a\nFirstUnique firstUnique = new FirstUnique([809]);\nfirstUnique.showFirstUnique(); // \u8fd4\u56de 809\nfirstUnique.add(809);          // \u6b64\u65f6\u961f\u5217\u4e3a [809,809]\nfirstUnique.showFirstUnique(); // \u8fd4\u56de -1\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 10^5
  • \n\t
  • 1 <= nums[i] <= 10^8
  • \n\t
  • 1 <= value <= 10^8
  • \n\t
  • \u6700\u591a\u8c03\u7528 5000 \u6b21\u00a0showFirstUnique\u00a0\u548c\u00a0add \u3002
  • \n
\n", "tags_en": ["Design", "Hash Table"], "tags_cn": ["\u8bbe\u8ba1", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class FirstUnique {\npublic:\n FirstUnique(vector& nums) {\n\n }\n \n int showFirstUnique() {\n\n }\n \n void add(int value) {\n\n }\n};\n\n/**\n * Your FirstUnique object will be instantiated and called as such:\n * FirstUnique* obj = new FirstUnique(nums);\n * int param_1 = obj->showFirstUnique();\n * obj->add(value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class FirstUnique {\n\n public FirstUnique(int[] nums) {\n\n }\n \n public int showFirstUnique() {\n\n }\n \n public void add(int value) {\n\n }\n}\n\n/**\n * Your FirstUnique object will be instantiated and called as such:\n * FirstUnique obj = new FirstUnique(nums);\n * int param_1 = obj.showFirstUnique();\n * obj.add(value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class FirstUnique(object):\n\n def __init__(self, nums):\n \"\"\"\n :type nums: List[int]\n \"\"\"\n\n\n def showFirstUnique(self):\n \"\"\"\n :rtype: int\n \"\"\"\n\n\n def add(self, value):\n \"\"\"\n :type value: int\n :rtype: None\n \"\"\"\n\n\n\n# Your FirstUnique object will be instantiated and called as such:\n# obj = FirstUnique(nums)\n# param_1 = obj.showFirstUnique()\n# obj.add(value)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class FirstUnique:\n\n def __init__(self, nums: List[int]):\n\n\n def showFirstUnique(self) -> int:\n\n\n def add(self, value: int) -> None:\n\n\n\n# Your FirstUnique object will be instantiated and called as such:\n# obj = FirstUnique(nums)\n# param_1 = obj.showFirstUnique()\n# obj.add(value)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} FirstUnique;\n\n\nFirstUnique* firstUniqueCreate(int* nums, int numsSize) {\n\n}\n\nint firstUniqueShowFirstUnique(FirstUnique* obj) {\n\n}\n\nvoid firstUniqueAdd(FirstUnique* obj, int value) {\n\n}\n\nvoid firstUniqueFree(FirstUnique* obj) {\n\n}\n\n/**\n * Your FirstUnique struct will be instantiated and called as such:\n * FirstUnique* obj = firstUniqueCreate(nums, numsSize);\n * int param_1 = firstUniqueShowFirstUnique(obj);\n \n * firstUniqueAdd(obj, value);\n \n * firstUniqueFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class FirstUnique {\n\n public FirstUnique(int[] nums) {\n\n }\n \n public int ShowFirstUnique() {\n\n }\n \n public void Add(int value) {\n\n }\n}\n\n/**\n * Your FirstUnique object will be instantiated and called as such:\n * FirstUnique obj = new FirstUnique(nums);\n * int param_1 = obj.ShowFirstUnique();\n * obj.Add(value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n */\nvar FirstUnique = function(nums) {\n\n};\n\n/**\n * @return {number}\n */\nFirstUnique.prototype.showFirstUnique = function() {\n\n};\n\n/** \n * @param {number} value\n * @return {void}\n */\nFirstUnique.prototype.add = function(value) {\n\n};\n\n/**\n * Your FirstUnique object will be instantiated and called as such:\n * var obj = new FirstUnique(nums)\n * var param_1 = obj.showFirstUnique()\n * obj.add(value)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class FirstUnique\n\n=begin\n :type nums: Integer[]\n=end\n def initialize(nums)\n\n end\n\n\n=begin\n :rtype: Integer\n=end\n def show_first_unique()\n\n end\n\n\n=begin\n :type value: Integer\n :rtype: Void\n=end\n def add(value)\n\n end\n\n\nend\n\n# Your FirstUnique object will be instantiated and called as such:\n# obj = FirstUnique.new(nums)\n# param_1 = obj.show_first_unique()\n# obj.add(value)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass FirstUnique {\n\n init(_ nums: [Int]) {\n\n }\n \n func showFirstUnique() -> Int {\n\n }\n \n func add(_ value: Int) {\n\n }\n}\n\n/**\n * Your FirstUnique object will be instantiated and called as such:\n * let obj = FirstUnique(nums)\n * let ret_1: Int = obj.showFirstUnique()\n * obj.add(value)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type FirstUnique struct {\n\n}\n\n\nfunc Constructor(nums []int) FirstUnique {\n\n}\n\n\nfunc (this *FirstUnique) ShowFirstUnique() int {\n\n}\n\n\nfunc (this *FirstUnique) Add(value int) {\n\n}\n\n\n/**\n * Your FirstUnique object will be instantiated and called as such:\n * obj := Constructor(nums);\n * param_1 := obj.ShowFirstUnique();\n * obj.Add(value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class FirstUnique(_nums: Array[Int]) {\n\n def showFirstUnique(): Int = {\n\n }\n\n def add(value: Int) {\n\n }\n\n}\n\n/**\n * Your FirstUnique object will be instantiated and called as such:\n * var obj = new FirstUnique(nums)\n * var param_1 = obj.showFirstUnique()\n * obj.add(value)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class FirstUnique(nums: IntArray) {\n\n fun showFirstUnique(): Int {\n\n }\n\n fun add(value: Int) {\n\n }\n\n}\n\n/**\n * Your FirstUnique object will be instantiated and called as such:\n * var obj = FirstUnique(nums)\n * var param_1 = obj.showFirstUnique()\n * obj.add(value)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct FirstUnique {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl FirstUnique {\n\n fn new(nums: Vec) -> Self {\n\n }\n \n fn show_first_unique(&self) -> i32 {\n\n }\n \n fn add(&self, value: i32) {\n\n }\n}\n\n/**\n * Your FirstUnique object will be instantiated and called as such:\n * let obj = FirstUnique::new(nums);\n * let ret_1: i32 = obj.show_first_unique();\n * obj.add(value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class FirstUnique {\n /**\n * @param Integer[] $nums\n */\n function __construct($nums) {\n\n }\n\n /**\n * @return Integer\n */\n function showFirstUnique() {\n\n }\n\n /**\n * @param Integer $value\n * @return NULL\n */\n function add($value) {\n\n }\n}\n\n/**\n * Your FirstUnique object will be instantiated and called as such:\n * $obj = FirstUnique($nums);\n * $ret_1 = $obj->showFirstUnique();\n * $obj->add($value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class FirstUnique {\n constructor(nums: number[]) {\n\n }\n\n showFirstUnique(): number {\n\n }\n\n add(value: number): void {\n\n }\n}\n\n/**\n * Your FirstUnique object will be instantiated and called as such:\n * var obj = new FirstUnique(nums)\n * var param_1 = obj.showFirstUnique()\n * obj.add(value)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define first-unique%\n (class object%\n (super-new)\n\n ; nums : (listof exact-integer?)\n (init-field\n nums)\n \n ; show-first-unique : -> exact-integer?\n (define/public (show-first-unique)\n\n )\n ; add : exact-integer? -> void?\n (define/public (add value)\n\n )))\n\n;; Your first-unique% object will be instantiated and called as such:\n;; (define obj (new first-unique% [nums nums]))\n;; (define param_1 (send obj show-first-unique))\n;; (send obj add value)", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1429](https://leetcode-cn.com/problems/first-unique-number)", "[\u7b2c\u4e00\u4e2a\u552f\u4e00\u6570\u5b57](/solution/1400-1499/1429.First%20Unique%20Number/README.md)", "`\u8bbe\u8ba1`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1429](https://leetcode.com/problems/first-unique-number)", "[First Unique Number](/solution/1400-1499/1429.First%20Unique%20Number/README_EN.md)", "`Design`,`Hash Table`", "Medium", "\ud83d\udd12"]}, {"question_id": "1364", "frontend_question_id": "1726", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/tuple-with-same-product", "url_en": "https://leetcode.com/problems/tuple-with-same-product", "relative_path_cn": "/solution/1700-1799/1726.Tuple%20with%20Same%20Product/README.md", "relative_path_en": "/solution/1700-1799/1726.Tuple%20with%20Same%20Product/README_EN.md", "title_cn": "\u540c\u79ef\u5143\u7ec4", "title_en": "Tuple with Same Product", "question_title_slug": "tuple-with-same-product", "content_en": "

Given an array nums of distinct positive integers, return the number of tuples (a, b, c, d) such that a * b = c * d where a, b, c, and d are elements of nums, and a != b != c != d.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: nums = [2,3,4,6]\r\nOutput: 8\r\nExplanation: There are 8 valid tuples:\r\n(2,6,3,4) , (2,6,4,3) , (6,2,3,4) , (6,2,4,3)\r\n(3,4,2,6) , (4,3,2,6) , (3,4,6,2) , (4,3,6,2)\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: nums = [1,2,4,5,10]\r\nOutput: 16\r\nExplanation: There are 16 valids tuples:\r\n(1,10,2,5) , (1,10,5,2) , (10,1,2,5) , (10,1,5,2)\r\n(2,5,1,10) , (2,5,10,1) , (5,2,1,10) , (5,2,10,1)\r\n(2,10,4,5) , (2,10,5,4) , (10,2,4,5) , (10,2,4,5)\r\n(4,5,2,10) , (4,5,10,2) , (5,4,2,10) , (5,4,10,2)\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: nums = [2,3,4,6,8,12]\r\nOutput: 40\r\n
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: nums = [2,3,5,7]\r\nOutput: 0\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= nums.length <= 1000
  • \r\n\t
  • 1 <= nums[i] <= 104
  • \r\n\t
  • All elements in nums are distinct.
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u7531 \u4e0d\u540c \u6b63\u6574\u6570\u7ec4\u6210\u7684\u6570\u7ec4 nums \uff0c\u8bf7\u4f60\u8fd4\u56de\u6ee1\u8db3\u00a0a * b = c * d \u7684\u5143\u7ec4 (a, b, c, d) \u7684\u6570\u91cf\u3002\u5176\u4e2d a\u3001b\u3001c \u548c d \u90fd\u662f nums \u4e2d\u7684\u5143\u7d20\uff0c\u4e14 a != b != c != d \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [2,3,4,6]\n\u8f93\u51fa\uff1a8\n\u89e3\u91ca\uff1a\u5b58\u5728 8 \u4e2a\u6ee1\u8db3\u9898\u610f\u7684\u5143\u7ec4\uff1a\n(2,6,3,4) , (2,6,4,3) , (6,2,3,4) , (6,2,4,3)\n(3,4,2,6) , (4,3,2,6) , (3,4,6,2) , (4,3,6,2)\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [1,2,4,5,10]\n\u8f93\u51fa\uff1a16\n\u89e3\u91ca\uff1a\u5b58\u5728 16 \u4e2a\u6ee1\u8db3\u9898\u610f\u7684\u5143\u7ec4\uff1a\n(1,10,2,5) , (1,10,5,2) , (10,1,2,5) , (10,1,5,2)\n(2,5,1,10) , (2,5,10,1) , (5,2,1,10) , (5,2,10,1)\n(2,10,4,5) , (2,10,5,4) , (10,2,4,5) , (10,2,4,5)\n(4,5,2,10) , (4,5,10,2) , (5,4,2,10) , (5,4,10,2)\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [2,3,4,6,8,12]\n\u8f93\u51fa\uff1a40\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [2,3,5,7]\n\u8f93\u51fa\uff1a0\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 1000
  • \n\t
  • 1 <= nums[i] <= 104
  • \n\t
  • nums \u4e2d\u7684\u6240\u6709\u5143\u7d20 \u4e92\u4e0d\u76f8\u540c
  • \n
\n", "tags_en": ["Array", "Hash Table"], "tags_cn": ["\u6570\u7ec4", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int tupleSameProduct(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int tupleSameProduct(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def tupleSameProduct(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def tupleSameProduct(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint tupleSameProduct(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int TupleSameProduct(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar tupleSameProduct = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef tuple_same_product(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func tupleSameProduct(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func tupleSameProduct(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def tupleSameProduct(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun tupleSameProduct(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn tuple_same_product(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function tupleSameProduct($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function tupleSameProduct(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (tuple-same-product nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1726](https://leetcode-cn.com/problems/tuple-with-same-product)", "[\u540c\u79ef\u5143\u7ec4](/solution/1700-1799/1726.Tuple%20with%20Same%20Product/README.md)", "`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1726](https://leetcode.com/problems/tuple-with-same-product)", "[Tuple with Same Product](/solution/1700-1799/1726.Tuple%20with%20Same%20Product/README_EN.md)", "`Array`,`Hash Table`", "Medium", ""]}, {"question_id": "1362", "frontend_question_id": "1227", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/airplane-seat-assignment-probability", "url_en": "https://leetcode.com/problems/airplane-seat-assignment-probability", "relative_path_cn": "/solution/1200-1299/1227.Airplane%20Seat%20Assignment%20Probability/README.md", "relative_path_en": "/solution/1200-1299/1227.Airplane%20Seat%20Assignment%20Probability/README_EN.md", "title_cn": "\u98de\u673a\u5ea7\u4f4d\u5206\u914d\u6982\u7387", "title_en": "Airplane Seat Assignment Probability", "question_title_slug": "airplane-seat-assignment-probability", "content_en": "

n passengers board an airplane with exactly n seats. The first passenger has lost the ticket and picks a seat randomly. But after that, the rest of passengers will:

\r\n\r\n
    \r\n\t
  • Take their own seat if it is still available, 
  • \r\n\t
  • Pick other seats randomly when they find their seat occupied 
  • \r\n
\r\n\r\n

What is the probability that the n-th person can get his own seat?

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: n = 1\r\nOutput: 1.00000\r\nExplanation: The first person can only get the first seat.
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: n = 2\r\nOutput: 0.50000\r\nExplanation: The second person has a probability of 0.5 to get the second seat (when first person gets the first seat).\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= n <= 10^5
  • \r\n
", "content_cn": "

\u6709 n \u4f4d\u4e58\u5ba2\u5373\u5c06\u767b\u673a\uff0c\u98de\u673a\u6b63\u597d\u6709 n \u4e2a\u5ea7\u4f4d\u3002\u7b2c\u4e00\u4f4d\u4e58\u5ba2\u7684\u7968\u4e22\u4e86\uff0c\u4ed6\u968f\u4fbf\u9009\u4e86\u4e00\u4e2a\u5ea7\u4f4d\u5750\u4e0b\u3002

\n\n

\u5269\u4e0b\u7684\u4e58\u5ba2\u5c06\u4f1a\uff1a

\n\n
    \n\t
  • \n\t

    \u5982\u679c\u4ed6\u4eec\u81ea\u5df1\u7684\u5ea7\u4f4d\u8fd8\u7a7a\u7740\uff0c\u5c31\u5750\u5230\u81ea\u5df1\u7684\u5ea7\u4f4d\u4e0a\uff0c

    \n\t
  • \n\t
  • \u5f53\u4ed6\u4eec\u81ea\u5df1\u7684\u5ea7\u4f4d\u88ab\u5360\u7528\u65f6\uff0c\u968f\u673a\u9009\u62e9\u5176\u4ed6\u5ea7\u4f4d
  • \n
\n\n

\u7b2c n \u4f4d\u4e58\u5ba2\u5750\u5728\u81ea\u5df1\u7684\u5ea7\u4f4d\u4e0a\u7684\u6982\u7387\u662f\u591a\u5c11\uff1f

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1a1.00000\n\u89e3\u91ca\uff1a\u7b2c\u4e00\u4e2a\u4eba\u53ea\u4f1a\u5750\u5728\u81ea\u5df1\u7684\u4f4d\u7f6e\u4e0a\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165: n = 2\n\u8f93\u51fa: 0.50000\n\u89e3\u91ca\uff1a\u5728\u7b2c\u4e00\u4e2a\u4eba\u9009\u597d\u5ea7\u4f4d\u5750\u4e0b\u540e\uff0c\u7b2c\u4e8c\u4e2a\u4eba\u5750\u5728\u81ea\u5df1\u7684\u5ea7\u4f4d\u4e0a\u7684\u6982\u7387\u662f 0.5\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 10^5
  • \n
\n", "tags_en": ["Brainteaser", "Math", "Dynamic Programming"], "tags_cn": ["\u8111\u7b4b\u6025\u8f6c\u5f2f", "\u6570\u5b66", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n double nthPersonGetsNthSeat(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double nthPersonGetsNthSeat(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def nthPersonGetsNthSeat(self, n):\n \"\"\"\n :type n: int\n :rtype: float\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def nthPersonGetsNthSeat(self, n: int) -> float:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\ndouble nthPersonGetsNthSeat(int n){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double NthPersonGetsNthSeat(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar nthPersonGetsNthSeat = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Float}\ndef nth_person_gets_nth_seat(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func nthPersonGetsNthSeat(_ n: Int) -> Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func nthPersonGetsNthSeat(n int) float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def nthPersonGetsNthSeat(n: Int): Double = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun nthPersonGetsNthSeat(n: Int): Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn nth_person_gets_nth_seat(n: i32) -> f64 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Float\n */\n function nthPersonGetsNthSeat($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function nthPersonGetsNthSeat(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (nth-person-gets-nth-seat n)\n (-> exact-integer? flonum?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1227](https://leetcode-cn.com/problems/airplane-seat-assignment-probability)", "[\u98de\u673a\u5ea7\u4f4d\u5206\u914d\u6982\u7387](/solution/1200-1299/1227.Airplane%20Seat%20Assignment%20Probability/README.md)", "`\u8111\u7b4b\u6025\u8f6c\u5f2f`,`\u6570\u5b66`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1227](https://leetcode.com/problems/airplane-seat-assignment-probability)", "[Airplane Seat Assignment Probability](/solution/1200-1299/1227.Airplane%20Seat%20Assignment%20Probability/README_EN.md)", "`Brainteaser`,`Math`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "1361", "frontend_question_id": "1240", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/tiling-a-rectangle-with-the-fewest-squares", "url_en": "https://leetcode.com/problems/tiling-a-rectangle-with-the-fewest-squares", "relative_path_cn": "/solution/1200-1299/1240.Tiling%20a%20Rectangle%20with%20the%20Fewest%20Squares/README.md", "relative_path_en": "/solution/1200-1299/1240.Tiling%20a%20Rectangle%20with%20the%20Fewest%20Squares/README_EN.md", "title_cn": "\u94fa\u74f7\u7816", "title_en": "Tiling a Rectangle with the Fewest Squares", "question_title_slug": "tiling-a-rectangle-with-the-fewest-squares", "content_en": "

Given a rectangle of size n x m, find the minimum number of integer-sided squares that tile the rectangle.

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: n = 2, m = 3\nOutput: 3\nExplanation: 3 squares are necessary to cover the rectangle.\n2 (squares of 1x1)\n1 (square of 2x2)
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: n = 5, m = 8\nOutput: 5\n
\n\n

Example 3:

\n\n

\"\"

\n\n
\nInput: n = 11, m = 13\nOutput: 6\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 13
  • \n\t
  • 1 <= m <= 13
  • \n
\n", "content_cn": "

\u4f60\u662f\u4e00\u4f4d\u65bd\u5de5\u961f\u7684\u5de5\u957f\uff0c\u6839\u636e\u8bbe\u8ba1\u5e08\u7684\u8981\u6c42\u51c6\u5907\u4e3a\u4e00\u5957\u8bbe\u8ba1\u98ce\u683c\u72ec\u7279\u7684\u623f\u5b50\u8fdb\u884c\u5ba4\u5185\u88c5\u4fee\u3002

\n\n

\u623f\u5b50\u7684\u5ba2\u5385\u5927\u5c0f\u4e3a n x m\uff0c\u4e3a\u4fdd\u6301\u6781\u7b80\u7684\u98ce\u683c\uff0c\u9700\u8981\u4f7f\u7528\u5c3d\u53ef\u80fd\u5c11\u7684 \u6b63\u65b9\u5f62 \u74f7\u7816\u6765\u94fa\u76d6\u5730\u9762\u3002

\n\n

\u5047\u8bbe\u6b63\u65b9\u5f62\u74f7\u7816\u7684\u89c4\u683c\u4e0d\u9650\uff0c\u8fb9\u957f\u90fd\u662f\u6574\u6570\u3002

\n\n

\u8bf7\u4f60\u5e2e\u8bbe\u8ba1\u5e08\u8ba1\u7b97\u4e00\u4e0b\uff0c\u6700\u5c11\u9700\u8981\u7528\u5230\u591a\u5c11\u5757\u65b9\u5f62\u74f7\u7816\uff1f

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1an = 2, m = 3\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a3 \u5757\u5730\u7816\u5c31\u53ef\u4ee5\u94fa\u6ee1\u5367\u5ba4\u3002\n     2 \u5757 1x1 \u5730\u7816\n     1 \u5757 2x2 \u5730\u7816
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1an = 5, m = 8\n\u8f93\u51fa\uff1a5\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1an = 11, m = 13\n\u8f93\u51fa\uff1a6\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 13
  • \n\t
  • 1 <= m <= 13
  • \n
\n", "tags_en": ["Dynamic Programming", "Backtracking"], "tags_cn": ["\u52a8\u6001\u89c4\u5212", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int tilingRectangle(int n, int m) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int tilingRectangle(int n, int m) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def tilingRectangle(self, n, m):\n \"\"\"\n :type n: int\n :type m: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def tilingRectangle(self, n: int, m: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint tilingRectangle(int n, int m){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int TilingRectangle(int n, int m) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} m\n * @return {number}\n */\nvar tilingRectangle = function(n, m) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} m\n# @return {Integer}\ndef tiling_rectangle(n, m)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func tilingRectangle(_ n: Int, _ m: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func tilingRectangle(n int, m int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def tilingRectangle(n: Int, m: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun tilingRectangle(n: Int, m: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn tiling_rectangle(n: i32, m: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $m\n * @return Integer\n */\n function tilingRectangle($n, $m) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function tilingRectangle(n: number, m: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (tiling-rectangle n m)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1240](https://leetcode-cn.com/problems/tiling-a-rectangle-with-the-fewest-squares)", "[\u94fa\u74f7\u7816](/solution/1200-1299/1240.Tiling%20a%20Rectangle%20with%20the%20Fewest%20Squares/README.md)", "`\u52a8\u6001\u89c4\u5212`,`\u56de\u6eaf\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[1240](https://leetcode.com/problems/tiling-a-rectangle-with-the-fewest-squares)", "[Tiling a Rectangle with the Fewest Squares](/solution/1200-1299/1240.Tiling%20a%20Rectangle%20with%20the%20Fewest%20Squares/README_EN.md)", "`Dynamic Programming`,`Backtracking`", "Hard", ""]}, {"question_id": "1360", "frontend_question_id": "1239", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-length-of-a-concatenated-string-with-unique-characters", "url_en": "https://leetcode.com/problems/maximum-length-of-a-concatenated-string-with-unique-characters", "relative_path_cn": "/solution/1200-1299/1239.Maximum%20Length%20of%20a%20Concatenated%20String%20with%20Unique%20Characters/README.md", "relative_path_en": "/solution/1200-1299/1239.Maximum%20Length%20of%20a%20Concatenated%20String%20with%20Unique%20Characters/README_EN.md", "title_cn": "\u4e32\u8054\u5b57\u7b26\u4e32\u7684\u6700\u5927\u957f\u5ea6", "title_en": "Maximum Length of a Concatenated String with Unique Characters", "question_title_slug": "maximum-length-of-a-concatenated-string-with-unique-characters", "content_en": "

Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.

\n\n

Return the maximum possible length of s.

\n\n

 

\n

Example 1:

\n\n
\nInput: arr = ["un","iq","ue"]\nOutput: 4\nExplanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".\nMaximum length is 4.\n
\n\n

Example 2:

\n\n
\nInput: arr = ["cha","r","act","ers"]\nOutput: 6\nExplanation: Possible solutions are "chaers" and "acters".\n
\n\n

Example 3:

\n\n
\nInput: arr = ["abcdefghijklmnopqrstuvwxyz"]\nOutput: 26\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= arr.length <= 16
  • \n\t
  • 1 <= arr[i].length <= 26
  • \n\t
  • arr[i] contains only lower case English letters.
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4 arr\uff0c\u5b57\u7b26\u4e32 s \u662f\u5c06 arr \u67d0\u4e00\u5b50\u5e8f\u5217\u5b57\u7b26\u4e32\u8fde\u63a5\u6240\u5f97\u7684\u5b57\u7b26\u4e32\uff0c\u5982\u679c s \u4e2d\u7684\u6bcf\u4e00\u4e2a\u5b57\u7b26\u90fd\u53ea\u51fa\u73b0\u8fc7\u4e00\u6b21\uff0c\u90a3\u4e48\u5b83\u5c31\u662f\u4e00\u4e2a\u53ef\u884c\u89e3\u3002

\n\n

\u8bf7\u8fd4\u56de\u6240\u6709\u53ef\u884c\u89e3 s \u4e2d\u6700\u957f\u957f\u5ea6\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aarr = ["un","iq","ue"]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u6240\u6709\u53ef\u80fd\u7684\u4e32\u8054\u7ec4\u5408\u662f "","un","iq","ue","uniq" \u548c "ique"\uff0c\u6700\u5927\u957f\u5ea6\u4e3a 4\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aarr = ["cha","r","act","ers"]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u53ef\u80fd\u7684\u89e3\u7b54\u6709 "chaers" \u548c "acters"\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aarr = ["abcdefghijklmnopqrstuvwxyz"]\n\u8f93\u51fa\uff1a26\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= arr.length <= 16
  • \n\t
  • 1 <= arr[i].length <= 26
  • \n\t
  • arr[i] \u4e2d\u53ea\u542b\u6709\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd
  • \n
\n", "tags_en": ["Bit Manipulation", "Backtracking"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxLength(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxLength(List arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxLength(self, arr):\n \"\"\"\n :type arr: List[str]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxLength(self, arr: List[str]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxLength(char ** arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxLength(IList arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} arr\n * @return {number}\n */\nvar maxLength = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} arr\n# @return {Integer}\ndef max_length(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxLength(_ arr: [String]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxLength(arr []string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxLength(arr: List[String]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxLength(arr: List): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_length(arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $arr\n * @return Integer\n */\n function maxLength($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxLength(arr: string[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-length arr)\n (-> (listof string?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1239](https://leetcode-cn.com/problems/maximum-length-of-a-concatenated-string-with-unique-characters)", "[\u4e32\u8054\u5b57\u7b26\u4e32\u7684\u6700\u5927\u957f\u5ea6](/solution/1200-1299/1239.Maximum%20Length%20of%20a%20Concatenated%20String%20with%20Unique%20Characters/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1239](https://leetcode.com/problems/maximum-length-of-a-concatenated-string-with-unique-characters)", "[Maximum Length of a Concatenated String with Unique Characters](/solution/1200-1299/1239.Maximum%20Length%20of%20a%20Concatenated%20String%20with%20Unique%20Characters/README_EN.md)", "`Bit Manipulation`,`Backtracking`", "Medium", ""]}, {"question_id": "1359", "frontend_question_id": "1238", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/circular-permutation-in-binary-representation", "url_en": "https://leetcode.com/problems/circular-permutation-in-binary-representation", "relative_path_cn": "/solution/1200-1299/1238.Circular%20Permutation%20in%20Binary%20Representation/README.md", "relative_path_en": "/solution/1200-1299/1238.Circular%20Permutation%20in%20Binary%20Representation/README_EN.md", "title_cn": "\u5faa\u73af\u7801\u6392\u5217", "title_en": "Circular Permutation in Binary Representation", "question_title_slug": "circular-permutation-in-binary-representation", "content_en": "

Given 2 integers n and start. Your task is return any permutation p of (0,1,2.....,2^n -1) such that :

\r\n\r\n
    \r\n\t
  • p[0] = start
  • \r\n\t
  • p[i] and p[i+1] differ by only one bit in their binary representation.
  • \r\n\t
  • p[0] and p[2^n -1] must also differ by only one bit in their binary representation.
  • \r\n
\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: n = 2, start = 3\r\nOutput: [3,2,0,1]\r\nExplanation: The binary representation of the permutation is (11,10,00,01). \r\nAll the adjacent element differ by one bit. Another valid permutation is [3,1,0,2]\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: n = 3, start = 2\r\nOutput: [2,6,7,5,4,0,1,3]\r\nExplanation: The binary representation of the permutation is (010,110,111,101,100,000,001,011).\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= n <= 16
  • \r\n\t
  • 0 <= start < 2 ^ n
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e24\u4e2a\u6574\u6570 n \u548c start\u3002\u4f60\u7684\u4efb\u52a1\u662f\u8fd4\u56de\u4efb\u610f (0,1,2,,...,2^n-1) \u7684\u6392\u5217 p\uff0c\u5e76\u4e14\u6ee1\u8db3\uff1a

\n\n
    \n\t
  • p[0] = start
  • \n\t
  • p[i] \u548c p[i+1] \u7684\u4e8c\u8fdb\u5236\u8868\u793a\u5f62\u5f0f\u53ea\u6709\u4e00\u4f4d\u4e0d\u540c
  • \n\t
  • p[0] \u548c p[2^n -1] \u7684\u4e8c\u8fdb\u5236\u8868\u793a\u5f62\u5f0f\u4e5f\u53ea\u6709\u4e00\u4f4d\u4e0d\u540c
  • \n
\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1an = 2, start = 3\n\u8f93\u51fa\uff1a[3,2,0,1]\n\u89e3\u91ca\uff1a\u8fd9\u4e2a\u6392\u5217\u7684\u4e8c\u8fdb\u5236\u8868\u793a\u662f (11,10,00,01)\n     \u6240\u6709\u7684\u76f8\u90bb\u5143\u7d20\u90fd\u6709\u4e00\u4f4d\u662f\u4e0d\u540c\u7684\uff0c\u53e6\u4e00\u4e2a\u6709\u6548\u7684\u6392\u5217\u662f [3,1,0,2]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u51fa\uff1an = 3, start = 2\n\u8f93\u51fa\uff1a[2,6,7,5,4,0,1,3]\n\u89e3\u91ca\uff1a\u8fd9\u4e2a\u6392\u5217\u7684\u4e8c\u8fdb\u5236\u8868\u793a\u662f (010,110,111,101,100,000,001,011)\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 16
  • \n\t
  • 0 <= start < 2^n
  • \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector circularPermutation(int n, int start) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List circularPermutation(int n, int start) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def circularPermutation(self, n, start):\n \"\"\"\n :type n: int\n :type start: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def circularPermutation(self, n: int, start: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* circularPermutation(int n, int start, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList CircularPermutation(int n, int start) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} start\n * @return {number[]}\n */\nvar circularPermutation = function(n, start) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} start\n# @return {Integer[]}\ndef circular_permutation(n, start)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func circularPermutation(_ n: Int, _ start: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func circularPermutation(n int, start int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def circularPermutation(n: Int, start: Int): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun circularPermutation(n: Int, start: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn circular_permutation(n: i32, start: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $start\n * @return Integer[]\n */\n function circularPermutation($n, $start) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function circularPermutation(n: number, start: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (circular-permutation n start)\n (-> exact-integer? exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1238](https://leetcode-cn.com/problems/circular-permutation-in-binary-representation)", "[\u5faa\u73af\u7801\u6392\u5217](/solution/1200-1299/1238.Circular%20Permutation%20in%20Binary%20Representation/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1238](https://leetcode.com/problems/circular-permutation-in-binary-representation)", "[Circular Permutation in Binary Representation](/solution/1200-1299/1238.Circular%20Permutation%20in%20Binary%20Representation/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "1358", "frontend_question_id": "1237", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-positive-integer-solution-for-a-given-equation", "url_en": "https://leetcode.com/problems/find-positive-integer-solution-for-a-given-equation", "relative_path_cn": "/solution/1200-1299/1237.Find%20Positive%20Integer%20Solution%20for%20a%20Given%20Equation/README.md", "relative_path_en": "/solution/1200-1299/1237.Find%20Positive%20Integer%20Solution%20for%20a%20Given%20Equation/README_EN.md", "title_cn": "\u627e\u51fa\u7ed9\u5b9a\u65b9\u7a0b\u7684\u6b63\u6574\u6570\u89e3", "title_en": "Find Positive Integer Solution for a Given Equation", "question_title_slug": "find-positive-integer-solution-for-a-given-equation", "content_en": "

Given a callable function f(x, y) with a hidden formula and a value z, reverse engineer the formula and return all positive integer pairs x and y where f(x,y) == z. You may return the pairs in any order.

\n\n

While the exact formula is hidden, the function is monotonically increasing, i.e.:

\n\n
    \n\t
  • f(x, y) < f(x + 1, y)
  • \n\t
  • f(x, y) < f(x, y + 1)
  • \n
\n\n

The function interface is defined like this:

\n\n
\ninterface CustomFunction {\npublic:\n  // Returns some positive integer f(x, y) for two positive integers x and y based on a formula.\n  int f(int x, int y);\n};\n
\n\n

We will judge your solution as follows:

\n\n
    \n\t
  • The judge has a list of 9 hidden implementations of CustomFunction, along with a way to generate an answer key of all valid pairs for a specific z.
  • \n\t
  • The judge will receive two inputs: a function_id (to determine which implementation to test your code with), and the target z.
  • \n\t
  • The judge will call your findSolution and compare your results with the answer key.
  • \n\t
  • If your results match the answer key, your solution will be Accepted.
  • \n
\n\n

 

\n

Example 1:

\n\n
\nInput: function_id = 1, z = 5\nOutput: [[1,4],[2,3],[3,2],[4,1]]\nExplanation: The hidden formula for function_id = 1 is f(x, y) = x + y.\nThe following positive integer values of x and y make f(x, y) equal to 5:\nx=1, y=4 -> f(1, 4) = 1 + 4 = 5.\nx=2, y=3 -> f(2, 3) = 2 + 3 = 5.\nx=3, y=2 -> f(3, 2) = 3 + 2 = 5.\nx=4, y=1 -> f(4, 1) = 4 + 1 = 5.\n
\n\n

Example 2:

\n\n
\nInput: function_id = 2, z = 5\nOutput: [[1,5],[5,1]]\nExplanation: The hidden formula for function_id = 2 is f(x, y) = x * y.\nThe following positive integer values of x and y make f(x, y) equal to 5:\nx=1, y=5 -> f(1, 5) = 1 * 5 = 5.\nx=5, y=1 -> f(5, 1) = 5 * 1 = 5.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= function_id <= 9
  • \n\t
  • 1 <= z <= 100
  • \n\t
  • It is guaranteed that the solutions of f(x, y) == z will be in the range 1 <= x, y <= 1000.
  • \n\t
  • It is also guaranteed that f(x, y) will fit in 32 bit signed integer if 1 <= x, y <= 1000.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u51fd\u6570\u00a0\u00a0f(x, y)\u00a0\u548c\u4e00\u4e2a\u76ee\u6807\u7ed3\u679c\u00a0z\uff0c\u51fd\u6570\u516c\u5f0f\u672a\u77e5\uff0c\u8bf7\u4f60\u8ba1\u7b97\u65b9\u7a0b\u00a0f(x,y) == z\u00a0\u6240\u6709\u53ef\u80fd\u7684\u6b63\u6574\u6570 \u6570\u5bf9\u00a0x \u548c y\u3002\u6ee1\u8db3\u6761\u4ef6\u7684\u7ed3\u679c\u6570\u5bf9\u53ef\u4ee5\u6309\u4efb\u610f\u987a\u5e8f\u8fd4\u56de\u3002

\n\n

\u5c3d\u7ba1\u51fd\u6570\u7684\u5177\u4f53\u5f0f\u5b50\u672a\u77e5\uff0c\u4f46\u5b83\u662f\u5355\u8c03\u9012\u589e\u51fd\u6570\uff0c\u4e5f\u5c31\u662f\u8bf4\uff1a

\n\n
    \n\t
  • f(x, y) < f(x + 1, y)
  • \n\t
  • f(x, y) < f(x, y + 1)
  • \n
\n\n

\u51fd\u6570\u63a5\u53e3\u5b9a\u4e49\u5982\u4e0b\uff1a

\n\n
\ninterface CustomFunction {\npublic:\n  // Returns some positive integer f(x, y) for two positive integers x and y based on a formula.\n  int f(int x, int y);\n};
\n\n

\u4f60\u7684\u89e3\u51b3\u65b9\u6848\u5c06\u6309\u5982\u4e0b\u89c4\u5219\u8fdb\u884c\u8bc4\u5224\uff1a

\n\n
    \n\t
  • \u5224\u9898\u7a0b\u5e8f\u6709\u4e00\u4e2a\u7531 CustomFunction \u7684 9 \u79cd\u5b9e\u73b0\u7ec4\u6210\u7684\u5217\u8868\uff0c\u4ee5\u53ca\u4e00\u79cd\u4e3a\u7279\u5b9a\u7684 z \u751f\u6210\u6240\u6709\u6709\u6548\u6570\u5bf9\u7684\u7b54\u6848\u7684\u65b9\u6cd5\u3002
  • \n\t
  • \u5224\u9898\u7a0b\u5e8f\u63a5\u53d7\u4e24\u4e2a\u8f93\u5165\uff1afunction_id\uff08\u51b3\u5b9a\u4f7f\u7528\u54ea\u79cd\u5b9e\u73b0\u6d4b\u8bd5\u4f60\u7684\u4ee3\u7801\uff09\u4ee5\u53ca\u76ee\u6807\u7ed3\u679c z \u3002
  • \n\t
  • \u5224\u9898\u7a0b\u5e8f\u5c06\u4f1a\u8c03\u7528\u4f60\u5b9e\u73b0\u7684 findSolution \u5e76\u5c06\u4f60\u7684\u7ed3\u679c\u4e0e\u7b54\u6848\u8fdb\u884c\u6bd4\u8f83\u3002
  • \n\t
  • \u5982\u679c\u4f60\u7684\u7ed3\u679c\u4e0e\u7b54\u6848\u76f8\u7b26\uff0c\u90a3\u4e48\u89e3\u51b3\u65b9\u6848\u5c06\u88ab\u89c6\u4f5c\u6b63\u786e\u7b54\u6848\uff0c\u5373 Accepted \u3002
  • \n
\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1afunction_id = 1, z = 5\n\u8f93\u51fa\uff1a[[1,4],[2,3],[3,2],[4,1]]\n\u89e3\u91ca\uff1afunction_id = 1 \u6697\u542b\u7684\u51fd\u6570\u5f0f\u5b50\u4e3a f(x, y) = x + y\n\u4ee5\u4e0b x \u548c y \u6ee1\u8db3 f(x, y) \u7b49\u4e8e 5\uff1a\nx=1, y=4 -> f(1, 4) = 1 + 4 = 5\nx=2, y=3 -> f(2, 3) = 2 + 3 = 5\nx=3, y=2 -> f(3, 2) = 3 + 2 = 5\nx=4, y=1 -> f(4, 1) = 4 + 1 = 5\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1afunction_id = 2, z = 5\n\u8f93\u51fa\uff1a[[1,5],[5,1]]\n\u89e3\u91ca\uff1afunction_id = 2 \u6697\u542b\u7684\u51fd\u6570\u5f0f\u5b50\u4e3a f(x, y) = x * y\n\u4ee5\u4e0b x \u548c y \u6ee1\u8db3 f(x, y) \u7b49\u4e8e 5\uff1a\nx=1, y=5 -> f(1, 5) = 1 * 5 = 5\nx=5, y=1 -> f(5, 1) = 5 * 1 = 5
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= function_id <= 9
  • \n\t
  • 1 <= z <= 100
  • \n\t
  • \u9898\u76ee\u4fdd\u8bc1\u00a0f(x, y) == z\u00a0\u7684\u89e3\u5904\u4e8e\u00a01 <= x, y <= 1000\u00a0\u7684\u8303\u56f4\u5185\u3002
  • \n\t
  • \u5728 1 <= x, y <= 1000\u00a0\u7684\u524d\u63d0\u4e0b\uff0c\u9898\u76ee\u4fdd\u8bc1\u00a0f(x, y)\u00a0\u662f\u4e00\u4e2a\u00a032 \u4f4d\u6709\u7b26\u53f7\u6574\u6570\u3002
  • \n
\n", "tags_en": ["Math", "Binary Search"], "tags_cn": ["\u6570\u5b66", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n * // This is the custom function interface.\n * // You should not implement it, or speculate about its implementation\n * class CustomFunction {\n * public:\n * // Returns f(x, y) for any given positive integers x and y.\n * // Note that f(x, y) is increasing with respect to both x and y.\n * // i.e. f(x, y) < f(x + 1, y), f(x, y) < f(x, y + 1)\n * int f(int x, int y);\n * };\n */\n\nclass Solution {\npublic:\n vector> findSolution(CustomFunction& customfunction, int z) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/*\n * // This is the custom function interface.\n * // You should not implement it, or speculate about its implementation\n * class CustomFunction {\n * // Returns f(x, y) for any given positive integers x and y.\n * // Note that f(x, y) is increasing with respect to both x and y.\n * // i.e. f(x, y) < f(x + 1, y), f(x, y) < f(x, y + 1)\n * public int f(int x, int y);\n * };\n */\n\nclass Solution {\n public List> findSolution(CustomFunction customfunction, int z) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "\"\"\"\n This is the custom function interface.\n You should not implement it, or speculate about its implementation\n class CustomFunction:\n # Returns f(x, y) for any given positive integers x and y.\n # Note that f(x, y) is increasing with respect to both x and y.\n # i.e. f(x, y) < f(x + 1, y), f(x, y) < f(x, y + 1)\n def f(self, x, y):\n\"\"\"\n\nclass Solution(object):\n def findSolution(self, customfunction, z):\n \"\"\"\n :type num: int\n :type z: int\n :rtype: List[List[int]]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "\"\"\"\n This is the custom function interface.\n You should not implement it, or speculate about its implementation\n class CustomFunction:\n # Returns f(x, y) for any given positive integers x and y.\n # Note that f(x, y) is increasing with respect to both x and y.\n # i.e. f(x, y) < f(x + 1, y), f(x, y) < f(x, y + 1)\n def f(self, x, y):\n \n\"\"\"\n\nclass Solution:\n def findSolution(self, customfunction: 'CustomFunction', z: int) -> List[List[int]]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/*\n * // This is the definition for customFunction API.\n * // You should not implement it, or speculate about its implementation\n *\n * // Returns f(x, y) for any given positive integers x and y.\n * // Note that f(x, y) is increasing with respect to both x and y.\n * // i.e. f(x, y) < f(x + 1, y), f(x, y) < f(x, y + 1)\n */\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** findSolution(int (*customFunction)(int, int), int z, int* returnSize, int** returnColumnSizes) {\n\t\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/*\n * // This is the custom function interface.\n * // You should not implement it, or speculate about its implementation\n * public class CustomFunction {\n * // Returns f(x, y) for any given positive integers x and y.\n * // Note that f(x, y) is increasing with respect to both x and y.\n * // i.e. f(x, y) < f(x + 1, y), f(x, y) < f(x, y + 1)\n * public int f(int x, int y);\n * };\n */\n\npublic class Solution {\n public IList> FindSolution(CustomFunction customfunction, int z) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // This is the CustomFunction's API interface.\n * // You should not implement it, or speculate about its implementation\n * function CustomFunction() {\n * @param {integer, integer} x, y\n * @return {integer}\n * this.f = function(x, y) {\n * ...\n * };\n * };\n */\n\n/**\n * @param {CustomFunction} customfunction\n * @param {integer} z\n * @return {integer[][]}\n */\nvar findSolution = function(customfunction, z) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# \tThis is the custom function interface.\n#\tYou should not implement it, or speculate about its implementation\n#\tclass CustomFunction:\n#\t\tdef f(self, x, y):\n# \t\t\tReturns f(x, y) for any given positive integers x and y.\n# \t\t\tNote that f(x, y) is increasing with respect to both x and y.\n# \t\t\ti.e. f(x, y) < f(x + 1, y), f(x, y) < f(x, y + 1)\n# \t\tend\n# \tend\n# \n\n# @param {CustomFunction} customfunction\n# @param {Integer} z\n# @return {List[List[Integer]]}\ndef findSolution(customfunction, z)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/*\n * // This is the custom function interface.\n * // You should not implement it, or speculate about its implementation\n * class CustomFunction {\n * // Returns f(x, y) for any given positive integers x and y.\n * // Note that f(x, y) is increasing with respect to both x and y.\n * // i.e. f(x, y) < f(x + 1, y), f(x, y) < f(x, y + 1)\n * func f(_ x: Int, _ y: Int) -> Int {}\n * }\n */\n\nclass Solution {\n func findSolution(_ customfunction: CustomFunction, _ z: Int) -> [[Int]] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/** \n * This is the declaration of customFunction API.\n * @param x int\n * @param x int\n * @return \t Returns f(x, y) for any given positive integers x and y.\n *\t\t\t Note that f(x, y) is increasing with respect to both x and y.\n * i.e. f(x, y) < f(x + 1, y), f(x, y) < f(x, y + 1)\n */\n\nfunc findSolution(customFunction func(int, int) int, z int) [][]int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/*\n * // This is the custom function interface.\n * // You should not implement it, or speculate about its implementation\n * class CustomFunction {\n * // Returns f(x, y) for any given positive integers x and y.\n * // Note that f(x, y) is increasing with respect to both x and y.\n * // i.e. f(x, y) < f(x + 1, y), f(x, y) < f(x, y + 1)\n * def f(x: Int, y: Int): Int = {}\n * };\n */\n\nobject Solution {\n def findSolution(customfunction: CustomFunction, z: Int): List[List[Int]] = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/*\n * // This is the custom function interface.\n * // You should not implement it, or speculate about its implementation\n * class CustomFunction {\n * // Returns f(x, y) for any given positive integers x and y.\n * // Note that f(x, y) is increasing with respect to both x and y.\n * // i.e. f(x, y) < f(x + 1, y), f(x, y) < f(x, y + 1)\n * fun f(x:Int, y:Int):Int {}\n * };\n */\n\nclass Solution {\n\tfun findSolution(customfunction:CustomFunction, z:Int):List> {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "/*\n * // This is the custom function interface.\n * // You should not implement it, or speculate about its implementation\n * struct CustomFunction;\n * impl CustomFunction {\n * pub fn f(x:i32,y:i32)->i32{}\n * }\n */\n\nimpl Solution {\n pub fn find_solution(customfunction: &CustomFunction, z: i32) -> Vec> {\n\t\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/*\n * // This is the custom function interface.\n * // You should not implement it, or speculate about its implementation\n * class CustomFunction {\n * // Returns f(x, y) for any given positive integers x and y.\n * // Note that f(x, y) is increasing with respect to both x and y.\n * // i.e. f(x, y) < f(x + 1, y), f(x, y) < f(x, y + 1)\n * public function f($x, $y){}\n * };\n */\n\nclass Solution {\n /**\n * @param CustomFunction $customfunction\n * @param Integer $z\n * @return Integer[][]\n */\n function findSolution($customfunction, $n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * // This is the CustomFunction's API interface.\n * // You should not implement it, or speculate about its implementation\n * class CustomFunction {\n * f(x: number, y: number): number {}\n * }\n */\n\nfunction findSolution(customfunction: CustomFunction, z: number): number[][] {\n\t\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1237](https://leetcode-cn.com/problems/find-positive-integer-solution-for-a-given-equation)", "[\u627e\u51fa\u7ed9\u5b9a\u65b9\u7a0b\u7684\u6b63\u6574\u6570\u89e3](/solution/1200-1299/1237.Find%20Positive%20Integer%20Solution%20for%20a%20Given%20Equation/README.md)", "`\u6570\u5b66`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1237](https://leetcode.com/problems/find-positive-integer-solution-for-a-given-equation)", "[Find Positive Integer Solution for a Given Equation](/solution/1200-1299/1237.Find%20Positive%20Integer%20Solution%20for%20a%20Given%20Equation/README_EN.md)", "`Math`,`Binary Search`", "Medium", ""]}, {"question_id": "1357", "frontend_question_id": "1225", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/report-contiguous-dates", "url_en": "https://leetcode.com/problems/report-contiguous-dates", "relative_path_cn": "/solution/1200-1299/1225.Report%20Contiguous%20Dates/README.md", "relative_path_en": "/solution/1200-1299/1225.Report%20Contiguous%20Dates/README_EN.md", "title_cn": "\u62a5\u544a\u7cfb\u7edf\u72b6\u6001\u7684\u8fde\u7eed\u65e5\u671f", "title_en": "Report Contiguous Dates", "question_title_slug": "report-contiguous-dates", "content_en": "

Table: Failed

\n\n
\n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| fail_date    | date    |\n+--------------+---------+\nPrimary key for this table is fail_date.\nFailed table contains the days of failed tasks.\n
\n\n

Table: Succeeded

\n\n
\n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| success_date | date    |\n+--------------+---------+\nPrimary key for this table is success_date.\nSucceeded table contains the days of succeeded tasks.\n
\n\n

 

\n\n

A system is running one task every day. Every task is independent of the previous tasks. The tasks can fail or succeed.

\n\n

Write an SQL query to generate a report of period_state for each continuous interval of days in the period from 2019-01-01 to 2019-12-31.

\n\n

period_state is 'failed' if tasks in this interval failed or 'succeeded' if tasks in this interval succeeded. Interval of days are retrieved as start_date and end_date.

\n\n

Order result by start_date.

\n\n

The query result format is in the following example:

\n\n
\nFailed table:\n+-------------------+\n| fail_date         |\n+-------------------+\n| 2018-12-28        |\n| 2018-12-29        |\n| 2019-01-04        |\n| 2019-01-05        |\n+-------------------+\n\nSucceeded table:\n+-------------------+\n| success_date      |\n+-------------------+\n| 2018-12-30        |\n| 2018-12-31        |\n| 2019-01-01        |\n| 2019-01-02        |\n| 2019-01-03        |\n| 2019-01-06        |\n+-------------------+\n\n\nResult table:\n+--------------+--------------+--------------+\n| period_state | start_date   | end_date     |\n+--------------+--------------+--------------+\n| succeeded    | 2019-01-01   | 2019-01-03   |\n| failed       | 2019-01-04   | 2019-01-05   |\n| succeeded    | 2019-01-06   | 2019-01-06   |\n+--------------+--------------+--------------+\n\nThe report ignored the system state in 2018 as we care about the system in the period 2019-01-01 to 2019-12-31.\nFrom 2019-01-01 to 2019-01-03 all tasks succeeded and the system state was "succeeded".\nFrom 2019-01-04 to 2019-01-05 all tasks failed and system state was "failed".\nFrom 2019-01-06 to 2019-01-06 all tasks succeeded and system state was "succeeded".\n
\n", "content_cn": "

Table: Failed

\n\n
+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| fail_date    | date    |\n+--------------+---------+\n\u8be5\u8868\u4e3b\u952e\u4e3a fail_date\u3002\n\u8be5\u8868\u5305\u542b\u5931\u8d25\u4efb\u52a1\u7684\u5929\u6570.\n
\n\n

Table: Succeeded

\n\n
+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| success_date | date    |\n+--------------+---------+\n\u8be5\u8868\u4e3b\u952e\u4e3a success_date\u3002\n\u8be5\u8868\u5305\u542b\u6210\u529f\u4efb\u52a1\u7684\u5929\u6570.\n
\n\n

 

\n\n

\u7cfb\u7edf \u6bcf\u5929 \u8fd0\u884c\u4e00\u4e2a\u4efb\u52a1\u3002\u6bcf\u4e2a\u4efb\u52a1\u90fd\u72ec\u7acb\u4e8e\u5148\u524d\u7684\u4efb\u52a1\u3002\u4efb\u52a1\u7684\u72b6\u6001\u53ef\u4ee5\u662f\u5931\u8d25\u6216\u662f\u6210\u529f\u3002

\n\n

\u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2 2019-01-01 \u5230 2019-12-31 \u671f\u95f4\u4efb\u52a1\u8fde\u7eed\u540c\u72b6\u6001 period_state \u7684\u8d77\u6b62\u65e5\u671f\uff08start_date \u548c end_date\uff09\u3002\u5373\u5982\u679c\u4efb\u52a1\u5931\u8d25\u4e86\uff0c\u5c31\u662f\u5931\u8d25\u72b6\u6001\u7684\u8d77\u6b62\u65e5\u671f\uff0c\u5982\u679c\u4efb\u52a1\u6210\u529f\u4e86\uff0c\u5c31\u662f\u6210\u529f\u72b6\u6001\u7684\u8d77\u6b62\u65e5\u671f\u3002

\n\n

\u6700\u540e\u7ed3\u679c\u6309\u7167\u8d77\u59cb\u65e5\u671f start_date \u6392\u5e8f

\n\n

\u67e5\u8be2\u7ed3\u679c\u6837\u4f8b\u5982\u4e0b\u6240\u793a:

\n\n
Failed table:\n+-------------------+\n| fail_date         |\n+-------------------+\n| 2018-12-28        |\n| 2018-12-29        |\n| 2019-01-04        |\n| 2019-01-05        |\n+-------------------+\n\nSucceeded table:\n+-------------------+\n| success_date      |\n+-------------------+\n| 2018-12-30        |\n| 2018-12-31        |\n| 2019-01-01        |\n| 2019-01-02        |\n| 2019-01-03        |\n| 2019-01-06        |\n+-------------------+\n\n\nResult table:\n+--------------+--------------+--------------+\n| period_state | start_date   | end_date     |\n+--------------+--------------+--------------+\n| succeeded    | 2019-01-01   | 2019-01-03   |\n| failed       | 2019-01-04   | 2019-01-05   |\n| succeeded    | 2019-01-06   | 2019-01-06   |\n+--------------+--------------+--------------+\n\n\u7ed3\u679c\u5ffd\u7565\u4e86 2018 \u5e74\u7684\u8bb0\u5f55\uff0c\u56e0\u4e3a\u6211\u4eec\u53ea\u5173\u5fc3\u4ece 2019-01-01 \u5230 2019-12-31 \u7684\u8bb0\u5f55\n\u4ece 2019-01-01 \u5230 2019-01-03 \u6240\u6709\u4efb\u52a1\u6210\u529f\uff0c\u7cfb\u7edf\u72b6\u6001\u4e3a "succeeded"\u3002\n\u4ece 2019-01-04 \u5230 2019-01-05 \u6240\u6709\u4efb\u52a1\u5931\u8d25\uff0c\u7cfb\u7edf\u72b6\u6001\u4e3a "failed"\u3002\n\u4ece 2019-01-06 \u5230 2019-01-06 \u6240\u6709\u4efb\u52a1\u6210\u529f\uff0c\u7cfb\u7edf\u72b6\u6001\u4e3a "succeeded"\u3002\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1225](https://leetcode-cn.com/problems/report-contiguous-dates)", "[\u62a5\u544a\u7cfb\u7edf\u72b6\u6001\u7684\u8fde\u7eed\u65e5\u671f](/solution/1200-1299/1225.Report%20Contiguous%20Dates/README.md)", "", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1225](https://leetcode.com/problems/report-contiguous-dates)", "[Report Contiguous Dates](/solution/1200-1299/1225.Report%20Contiguous%20Dates/README_EN.md)", "", "Hard", "\ud83d\udd12"]}, {"question_id": "1352", "frontend_question_id": "1235", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-profit-in-job-scheduling", "url_en": "https://leetcode.com/problems/maximum-profit-in-job-scheduling", "relative_path_cn": "/solution/1200-1299/1235.Maximum%20Profit%20in%20Job%20Scheduling/README.md", "relative_path_en": "/solution/1200-1299/1235.Maximum%20Profit%20in%20Job%20Scheduling/README_EN.md", "title_cn": "\u89c4\u5212\u517c\u804c\u5de5\u4f5c", "title_en": "Maximum Profit in Job Scheduling", "question_title_slug": "maximum-profit-in-job-scheduling", "content_en": "

We have n jobs, where every job is scheduled to be done from startTime[i] to endTime[i], obtaining a profit of profit[i].

\n\n

You're given the startTime, endTime and profit arrays, return the maximum profit you can take such that there are no two jobs in the subset with overlapping time range.

\n\n

If you choose a job that ends at time X you will be able to start another job that starts at time X.

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: startTime = [1,2,3,3], endTime = [3,4,5,6], profit = [50,10,40,70]\nOutput: 120\nExplanation: The subset chosen is the first and fourth job. \nTime range [1-3]+[3-6] , we get profit of 120 = 50 + 70.\n
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: startTime = [1,2,3,4,6], endTime = [3,5,10,6,9], profit = [20,20,100,70,60]\nOutput: 150\nExplanation: The subset chosen is the first, fourth and fifth job. \nProfit obtained 150 = 20 + 70 + 60.\n
\n\n

Example 3:

\n\n

\"\"

\n\n
\nInput: startTime = [1,1,1], endTime = [2,3,4], profit = [5,6,4]\nOutput: 6\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= startTime.length == endTime.length == profit.length <= 5 * 104
  • \n\t
  • 1 <= startTime[i] < endTime[i] <= 109
  • \n\t
  • 1 <= profit[i] <= 104
  • \n
\n", "content_cn": "

\u4f60\u6253\u7b97\u5229\u7528\u7a7a\u95f2\u65f6\u95f4\u6765\u505a\u517c\u804c\u5de5\u4f5c\u8d5a\u4e9b\u96f6\u82b1\u94b1\u3002

\n\n

\u8fd9\u91cc\u6709 n \u4efd\u517c\u804c\u5de5\u4f5c\uff0c\u6bcf\u4efd\u5de5\u4f5c\u9884\u8ba1\u4ece startTime[i] \u5f00\u59cb\u5230 endTime[i] \u7ed3\u675f\uff0c\u62a5\u916c\u4e3a profit[i]\u3002

\n\n

\u7ed9\u4f60\u4e00\u4efd\u517c\u804c\u5de5\u4f5c\u8868\uff0c\u5305\u542b\u5f00\u59cb\u65f6\u95f4 startTime\uff0c\u7ed3\u675f\u65f6\u95f4 endTime \u548c\u9884\u8ba1\u62a5\u916c profit \u4e09\u4e2a\u6570\u7ec4\uff0c\u8bf7\u4f60\u8ba1\u7b97\u5e76\u8fd4\u56de\u53ef\u4ee5\u83b7\u5f97\u7684\u6700\u5927\u62a5\u916c\u3002

\n\n

\u6ce8\u610f\uff0c\u65f6\u95f4\u4e0a\u51fa\u73b0\u91cd\u53e0\u7684 2 \u4efd\u5de5\u4f5c\u4e0d\u80fd\u540c\u65f6\u8fdb\u884c\u3002

\n\n

\u5982\u679c\u4f60\u9009\u62e9\u7684\u5de5\u4f5c\u5728\u65f6\u95f4 X \u7ed3\u675f\uff0c\u90a3\u4e48\u4f60\u53ef\u4ee5\u7acb\u523b\u8fdb\u884c\u5728\u65f6\u95f4 X \u5f00\u59cb\u7684\u4e0b\u4e00\u4efd\u5de5\u4f5c\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1astartTime = [1,2,3,3], endTime = [3,4,5,6], profit = [50,10,40,70]\n\u8f93\u51fa\uff1a120\n\u89e3\u91ca\uff1a\n\u6211\u4eec\u9009\u51fa\u7b2c 1 \u4efd\u548c\u7b2c 4 \u4efd\u5de5\u4f5c\uff0c \n\u65f6\u95f4\u8303\u56f4\u662f [1-3]+[3-6]\uff0c\u5171\u83b7\u5f97\u62a5\u916c 120 = 50 + 70\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1astartTime = [1,2,3,4,6], endTime = [3,5,10,6,9], profit = [20,20,100,70,60]\n\u8f93\u51fa\uff1a150\n\u89e3\u91ca\uff1a\n\u6211\u4eec\u9009\u62e9\u7b2c 1\uff0c4\uff0c5 \u4efd\u5de5\u4f5c\u3002 \n\u5171\u83b7\u5f97\u62a5\u916c 150 = 20 + 70 + 60\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1astartTime = [1,1,1], endTime = [2,3,4], profit = [5,6,4]\n\u8f93\u51fa\uff1a6\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= startTime.length == endTime.length == profit.length <= 5 * 10^4
  • \n\t
  • 1 <= startTime[i] < endTime[i] <= 10^9
  • \n\t
  • 1 <= profit[i] <= 10^4
  • \n
\n", "tags_en": ["Sort", "Binary Search", "Dynamic Programming"], "tags_cn": ["\u6392\u5e8f", "\u4e8c\u5206\u67e5\u627e", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int jobScheduling(vector& startTime, vector& endTime, vector& profit) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int jobScheduling(int[] startTime, int[] endTime, int[] profit) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def jobScheduling(self, startTime, endTime, profit):\n \"\"\"\n :type startTime: List[int]\n :type endTime: List[int]\n :type profit: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def jobScheduling(self, startTime: List[int], endTime: List[int], profit: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint jobScheduling(int* startTime, int startTimeSize, int* endTime, int endTimeSize, int* profit, int profitSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int JobScheduling(int[] startTime, int[] endTime, int[] profit) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} startTime\n * @param {number[]} endTime\n * @param {number[]} profit\n * @return {number}\n */\nvar jobScheduling = function(startTime, endTime, profit) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} start_time\n# @param {Integer[]} end_time\n# @param {Integer[]} profit\n# @return {Integer}\ndef job_scheduling(start_time, end_time, profit)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func jobScheduling(_ startTime: [Int], _ endTime: [Int], _ profit: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func jobScheduling(startTime []int, endTime []int, profit []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def jobScheduling(startTime: Array[Int], endTime: Array[Int], profit: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun jobScheduling(startTime: IntArray, endTime: IntArray, profit: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn job_scheduling(start_time: Vec, end_time: Vec, profit: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $startTime\n * @param Integer[] $endTime\n * @param Integer[] $profit\n * @return Integer\n */\n function jobScheduling($startTime, $endTime, $profit) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function jobScheduling(startTime: number[], endTime: number[], profit: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (job-scheduling startTime endTime profit)\n (-> (listof exact-integer?) (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1235](https://leetcode-cn.com/problems/maximum-profit-in-job-scheduling)", "[\u89c4\u5212\u517c\u804c\u5de5\u4f5c](/solution/1200-1299/1235.Maximum%20Profit%20in%20Job%20Scheduling/README.md)", "`\u6392\u5e8f`,`\u4e8c\u5206\u67e5\u627e`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1235](https://leetcode.com/problems/maximum-profit-in-job-scheduling)", "[Maximum Profit in Job Scheduling](/solution/1200-1299/1235.Maximum%20Profit%20in%20Job%20Scheduling/README_EN.md)", "`Sort`,`Binary Search`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "1351", "frontend_question_id": "1234", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/replace-the-substring-for-balanced-string", "url_en": "https://leetcode.com/problems/replace-the-substring-for-balanced-string", "relative_path_cn": "/solution/1200-1299/1234.Replace%20the%20Substring%20for%20Balanced%20String/README.md", "relative_path_en": "/solution/1200-1299/1234.Replace%20the%20Substring%20for%20Balanced%20String/README_EN.md", "title_cn": "\u66ff\u6362\u5b50\u4e32\u5f97\u5230\u5e73\u8861\u5b57\u7b26\u4e32", "title_en": "Replace the Substring for Balanced String", "question_title_slug": "replace-the-substring-for-balanced-string", "content_en": "

You are given a string containing only 4 kinds of characters 'Q', 'W', 'E' and 'R'.

\n\n

A string is said to be balanced if each of its characters appears n/4 times where n is the length of the string.

\n\n

Return the minimum length of the substring that can be replaced with any other string of the same length to make the original string s balanced.

\n\n

Return 0 if the string is already balanced.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "QWER"\nOutput: 0\nExplanation: s is already balanced.
\n\n

Example 2:

\n\n
\nInput: s = "QQWE"\nOutput: 1\nExplanation: We need to replace a 'Q' to 'R', so that "RQWE" (or "QRWE") is balanced.\n
\n\n

Example 3:

\n\n
\nInput: s = "QQQW"\nOutput: 2\nExplanation: We can replace the first "QQ" to "ER". \n
\n\n

Example 4:

\n\n
\nInput: s = "QQQQ"\nOutput: 3\nExplanation: We can replace the last 3 'Q' to make s = "QWER".\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 10^5
  • \n\t
  • s.length is a multiple of 4
  • \n\t
  • contains only 'Q', 'W', 'E' and 'R'.
  • \n
\n", "content_cn": "

\u6709\u4e00\u4e2a\u53ea\u542b\u6709 'Q', 'W', 'E', 'R' \u56db\u79cd\u5b57\u7b26\uff0c\u4e14\u957f\u5ea6\u4e3a n \u7684\u5b57\u7b26\u4e32\u3002

\n\n

\u5047\u5982\u5728\u8be5\u5b57\u7b26\u4e32\u4e2d\uff0c\u8fd9\u56db\u4e2a\u5b57\u7b26\u90fd\u6070\u597d\u51fa\u73b0 n/4 \u6b21\uff0c\u90a3\u4e48\u5b83\u5c31\u662f\u4e00\u4e2a\u300c\u5e73\u8861\u5b57\u7b26\u4e32\u300d\u3002

\n\n

 

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u8fd9\u6837\u7684\u5b57\u7b26\u4e32 s\uff0c\u8bf7\u901a\u8fc7\u300c\u66ff\u6362\u4e00\u4e2a\u5b50\u4e32\u300d\u7684\u65b9\u5f0f\uff0c\u4f7f\u539f\u5b57\u7b26\u4e32 s \u53d8\u6210\u4e00\u4e2a\u300c\u5e73\u8861\u5b57\u7b26\u4e32\u300d\u3002

\n\n

\u4f60\u53ef\u4ee5\u7528\u548c\u300c\u5f85\u66ff\u6362\u5b50\u4e32\u300d\u957f\u5ea6\u76f8\u540c\u7684 \u4efb\u4f55 \u5176\u4ed6\u5b57\u7b26\u4e32\u6765\u5b8c\u6210\u66ff\u6362\u3002

\n\n

\u8bf7\u8fd4\u56de\u5f85\u66ff\u6362\u5b50\u4e32\u7684\u6700\u5c0f\u53ef\u80fd\u957f\u5ea6\u3002

\n\n

\u5982\u679c\u539f\u5b57\u7b26\u4e32\u81ea\u8eab\u5c31\u662f\u4e00\u4e2a\u5e73\u8861\u5b57\u7b26\u4e32\uff0c\u5219\u8fd4\u56de 0\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1as = "QWER"\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1as \u5df2\u7ecf\u662f\u5e73\u8861\u7684\u4e86\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1as = "QQWE"\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u6211\u4eec\u9700\u8981\u628a\u4e00\u4e2a 'Q' \u66ff\u6362\u6210 'R'\uff0c\u8fd9\u6837\u5f97\u5230\u7684 "RQWE" (\u6216 "QRWE") \u662f\u5e73\u8861\u7684\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1as = "QQQW"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6211\u4eec\u53ef\u4ee5\u628a\u524d\u9762\u7684 "QQ" \u66ff\u6362\u6210 "ER"\u3002 \n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1as = "QQQQ"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6211\u4eec\u53ef\u4ee5\u66ff\u6362\u540e 3 \u4e2a 'Q'\uff0c\u4f7f s = "QWER"\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length <= 10^5
  • \n\t
  • s.length \u662f 4 \u7684\u500d\u6570
  • \n\t
  • s \u4e2d\u53ea\u542b\u6709 'Q', 'W', 'E''R' \u56db\u79cd\u5b57\u7b26
  • \n
\n", "tags_en": ["Two Pointers", "String"], "tags_cn": ["\u53cc\u6307\u9488", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int balancedString(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int balancedString(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def balancedString(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def balancedString(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint balancedString(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int BalancedString(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar balancedString = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef balanced_string(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func balancedString(_ s: String) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func balancedString(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def balancedString(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun balancedString(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn balanced_string(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function balancedString($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function balancedString(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (balanced-string s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1234](https://leetcode-cn.com/problems/replace-the-substring-for-balanced-string)", "[\u66ff\u6362\u5b50\u4e32\u5f97\u5230\u5e73\u8861\u5b57\u7b26\u4e32](/solution/1200-1299/1234.Replace%20the%20Substring%20for%20Balanced%20String/README.md)", "`\u53cc\u6307\u9488`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1234](https://leetcode.com/problems/replace-the-substring-for-balanced-string)", "[Replace the Substring for Balanced String](/solution/1200-1299/1234.Replace%20the%20Substring%20for%20Balanced%20String/README_EN.md)", "`Two Pointers`,`String`", "Medium", ""]}, {"question_id": "1350", "frontend_question_id": "1233", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/remove-sub-folders-from-the-filesystem", "url_en": "https://leetcode.com/problems/remove-sub-folders-from-the-filesystem", "relative_path_cn": "/solution/1200-1299/1233.Remove%20Sub-Folders%20from%20the%20Filesystem/README.md", "relative_path_en": "/solution/1200-1299/1233.Remove%20Sub-Folders%20from%20the%20Filesystem/README_EN.md", "title_cn": "\u5220\u9664\u5b50\u6587\u4ef6\u5939", "title_en": "Remove Sub-Folders from the Filesystem", "question_title_slug": "remove-sub-folders-from-the-filesystem", "content_en": "

Given a list of folders, remove all sub-folders in those folders and return in any order the folders after removing.

\n\n

If a folder[i] is located within another folder[j], it is called a sub-folder of it.

\n\n

The format of a path is one or more concatenated strings of the form: / followed by one or more lowercase English letters. For example, /leetcode and /leetcode/problems are valid paths while an empty string and / are not.

\n\n

 

\n

Example 1:

\n\n
\nInput: folder = ["/a","/a/b","/c/d","/c/d/e","/c/f"]\nOutput: ["/a","/c/d","/c/f"]\nExplanation: Folders "/a/b/" is a subfolder of "/a" and "/c/d/e" is inside of folder "/c/d" in our filesystem.\n
\n\n

Example 2:

\n\n
\nInput: folder = ["/a","/a/b/c","/a/b/d"]\nOutput: ["/a"]\nExplanation: Folders "/a/b/c" and "/a/b/d/" will be removed because they are subfolders of "/a".\n
\n\n

Example 3:

\n\n
\nInput: folder = ["/a/b/c","/a/b/ca","/a/b/d"]\nOutput: ["/a/b/c","/a/b/ca","/a/b/d"]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= folder.length <= 4 * 10^4
  • \n\t
  • 2 <= folder[i].length <= 100
  • \n\t
  • folder[i] contains only lowercase letters and '/'
  • \n\t
  • folder[i] always starts with character '/'
  • \n\t
  • Each folder name is unique.
  • \n
\n", "content_cn": "

\u4f60\u662f\u4e00\u4f4d\u7cfb\u7edf\u7ba1\u7406\u5458\uff0c\u624b\u91cc\u6709\u4e00\u4efd\u6587\u4ef6\u5939\u5217\u8868 folder\uff0c\u4f60\u7684\u4efb\u52a1\u662f\u8981\u5220\u9664\u8be5\u5217\u8868\u4e2d\u7684\u6240\u6709 \u5b50\u6587\u4ef6\u5939\uff0c\u5e76\u4ee5 \u4efb\u610f\u987a\u5e8f \u8fd4\u56de\u5269\u4e0b\u7684\u6587\u4ef6\u5939\u3002

\n\n

\u6211\u4eec\u8fd9\u6837\u5b9a\u4e49\u300c\u5b50\u6587\u4ef6\u5939\u300d\uff1a

\n\n
    \n\t
  • \u5982\u679c\u6587\u4ef6\u5939 folder[i] \u4f4d\u4e8e\u53e6\u4e00\u4e2a\u6587\u4ef6\u5939 folder[j] \u4e0b\uff0c\u90a3\u4e48 folder[i] \u5c31\u662f folder[j] \u7684\u5b50\u6587\u4ef6\u5939\u3002
  • \n
\n\n

\u6587\u4ef6\u5939\u7684\u300c\u8def\u5f84\u300d\u662f\u7531\u4e00\u4e2a\u6216\u591a\u4e2a\u6309\u4ee5\u4e0b\u683c\u5f0f\u4e32\u8054\u5f62\u6210\u7684\u5b57\u7b26\u4e32\uff1a

\n\n
    \n\t
  • / \u540e\u8ddf\u4e00\u4e2a\u6216\u8005\u591a\u4e2a\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
  • \n
\n\n

\u4f8b\u5982\uff0c/leetcode \u548c /leetcode/problems \u90fd\u662f\u6709\u6548\u7684\u8def\u5f84\uff0c\u800c\u7a7a\u5b57\u7b26\u4e32\u548c / \u4e0d\u662f\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1afolder = ["/a","/a/b","/c/d","/c/d/e","/c/f"]\n\u8f93\u51fa\uff1a["/a","/c/d","/c/f"]\n\u89e3\u91ca\uff1a"/a/b/" \u662f "/a" \u7684\u5b50\u6587\u4ef6\u5939\uff0c\u800c "/c/d/e" \u662f "/c/d" \u7684\u5b50\u6587\u4ef6\u5939\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1afolder = ["/a","/a/b/c","/a/b/d"]\n\u8f93\u51fa\uff1a["/a"]\n\u89e3\u91ca\uff1a\u6587\u4ef6\u5939 "/a/b/c" \u548c "/a/b/d/" \u90fd\u4f1a\u88ab\u5220\u9664\uff0c\u56e0\u4e3a\u5b83\u4eec\u90fd\u662f "/a" \u7684\u5b50\u6587\u4ef6\u5939\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1afolder = ["/a/b/c","/a/b/d","/a/b/ca"]\n\u8f93\u51fa\uff1a["/a/b/c","/a/b/ca","/a/b/d"]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= folder.length <= 4 * 10^4
  • \n\t
  • 2 <= folder[i].length <= 100
  • \n\t
  • folder[i] \u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd\u548c /
  • \n\t
  • folder[i] \u603b\u662f\u4ee5\u5b57\u7b26 / \u8d77\u59cb
  • \n\t
  • \u6bcf\u4e2a\u6587\u4ef6\u5939\u540d\u90fd\u662f\u552f\u4e00\u7684
  • \n
\n", "tags_en": ["Array", "String"], "tags_cn": ["\u6570\u7ec4", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector removeSubfolders(vector& folder) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List removeSubfolders(String[] folder) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def removeSubfolders(self, folder):\n \"\"\"\n :type folder: List[str]\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def removeSubfolders(self, folder: List[str]) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** removeSubfolders(char ** folder, int folderSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList RemoveSubfolders(string[] folder) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} folder\n * @return {string[]}\n */\nvar removeSubfolders = function(folder) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} folder\n# @return {String[]}\ndef remove_subfolders(folder)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func removeSubfolders(_ folder: [String]) -> [String] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func removeSubfolders(folder []string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def removeSubfolders(folder: Array[String]): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun removeSubfolders(folder: Array): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn remove_subfolders(folder: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $folder\n * @return String[]\n */\n function removeSubfolders($folder) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function removeSubfolders(folder: string[]): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (remove-subfolders folder)\n (-> (listof string?) (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1233](https://leetcode-cn.com/problems/remove-sub-folders-from-the-filesystem)", "[\u5220\u9664\u5b50\u6587\u4ef6\u5939](/solution/1200-1299/1233.Remove%20Sub-Folders%20from%20the%20Filesystem/README.md)", "`\u6570\u7ec4`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1233](https://leetcode.com/problems/remove-sub-folders-from-the-filesystem)", "[Remove Sub-Folders from the Filesystem](/solution/1200-1299/1233.Remove%20Sub-Folders%20from%20the%20Filesystem/README_EN.md)", "`Array`,`String`", "Medium", ""]}, {"question_id": "1349", "frontend_question_id": "1232", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/check-if-it-is-a-straight-line", "url_en": "https://leetcode.com/problems/check-if-it-is-a-straight-line", "relative_path_cn": "/solution/1200-1299/1232.Check%20If%20It%20Is%20a%20Straight%20Line/README.md", "relative_path_en": "/solution/1200-1299/1232.Check%20If%20It%20Is%20a%20Straight%20Line/README_EN.md", "title_cn": "\u7f00\u70b9\u6210\u7ebf", "title_en": "Check If It Is a Straight Line", "question_title_slug": "check-if-it-is-a-straight-line", "content_en": "

You are given an array coordinates, coordinates[i] = [x, y], where [x, y] represents the coordinate of a point. Check if these points make a straight line in the XY plane.

\r\n\r\n

 

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n

\"\"

\r\n\r\n
\r\nInput: coordinates = [[1,2],[2,3],[3,4],[4,5],[5,6],[6,7]]\r\nOutput: true\r\n
\r\n\r\n

Example 2:

\r\n\r\n

\"\"

\r\n\r\n
\r\nInput: coordinates = [[1,1],[2,2],[3,4],[4,5],[5,6],[7,7]]\r\nOutput: false\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 2 <= coordinates.length <= 1000
  • \r\n\t
  • coordinates[i].length == 2
  • \r\n\t
  • -10^4 <= coordinates[i][0], coordinates[i][1] <= 10^4
  • \r\n\t
  • coordinates contains no duplicate point.
  • \r\n
", "content_cn": "

\u5728\u4e00\u4e2a XY \u5750\u6807\u7cfb\u4e2d\u6709\u4e00\u4e9b\u70b9\uff0c\u6211\u4eec\u7528\u6570\u7ec4 coordinates \u6765\u5206\u522b\u8bb0\u5f55\u5b83\u4eec\u7684\u5750\u6807\uff0c\u5176\u4e2d coordinates[i] = [x, y] \u8868\u793a\u6a2a\u5750\u6807\u4e3a x\u3001\u7eb5\u5750\u6807\u4e3a y \u7684\u70b9\u3002

\n\n

\u8bf7\u4f60\u6765\u5224\u65ad\uff0c\u8fd9\u4e9b\u70b9\u662f\u5426\u5728\u8be5\u5750\u6807\u7cfb\u4e2d\u5c5e\u4e8e\u540c\u4e00\u6761\u76f4\u7ebf\u4e0a\uff0c\u662f\u5219\u8fd4\u56de true\uff0c\u5426\u5219\u8bf7\u8fd4\u56de false\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1acoordinates = [[1,2],[2,3],[3,4],[4,5],[5,6],[6,7]]\n\u8f93\u51fa\uff1atrue\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1acoordinates = [[1,1],[2,2],[3,4],[4,5],[5,6],[7,7]]\n\u8f93\u51fa\uff1afalse\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= coordinates.length <= 1000
  • \n\t
  • coordinates[i].length == 2
  • \n\t
  • -10^4 <= coordinates[i][0], coordinates[i][1] <= 10^4
  • \n\t
  • coordinates \u4e2d\u4e0d\u542b\u91cd\u590d\u7684\u70b9
  • \n
\n", "tags_en": ["Geometry", "Array", "Math"], "tags_cn": ["\u51e0\u4f55", "\u6570\u7ec4", "\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool checkStraightLine(vector>& coordinates) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean checkStraightLine(int[][] coordinates) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def checkStraightLine(self, coordinates):\n \"\"\"\n :type coordinates: List[List[int]]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def checkStraightLine(self, coordinates: List[List[int]]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "bool checkStraightLine(int** coordinates, int coordinatesSize, int* coordinatesColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CheckStraightLine(int[][] coordinates) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} coordinates\n * @return {boolean}\n */\nvar checkStraightLine = function(coordinates) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} coordinates\n# @return {Boolean}\ndef check_straight_line(coordinates)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func checkStraightLine(_ coordinates: [[Int]]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func checkStraightLine(coordinates [][]int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def checkStraightLine(coordinates: Array[Array[Int]]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun checkStraightLine(coordinates: Array): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn check_straight_line(coordinates: Vec>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $coordinates\n * @return Boolean\n */\n function checkStraightLine($coordinates) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function checkStraightLine(coordinates: number[][]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (check-straight-line coordinates)\n (-> (listof (listof exact-integer?)) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1232](https://leetcode-cn.com/problems/check-if-it-is-a-straight-line)", "[\u7f00\u70b9\u6210\u7ebf](/solution/1200-1299/1232.Check%20If%20It%20Is%20a%20Straight%20Line/README.md)", "`\u51e0\u4f55`,`\u6570\u7ec4`,`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[1232](https://leetcode.com/problems/check-if-it-is-a-straight-line)", "[Check If It Is a Straight Line](/solution/1200-1299/1232.Check%20If%20It%20Is%20a%20Straight%20Line/README_EN.md)", "`Geometry`,`Array`,`Math`", "Easy", ""]}, {"question_id": "1345", "frontend_question_id": "1427", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/perform-string-shifts", "url_en": "https://leetcode.com/problems/perform-string-shifts", "relative_path_cn": "/solution/1400-1499/1427.Perform%20String%20Shifts/README.md", "relative_path_en": "/solution/1400-1499/1427.Perform%20String%20Shifts/README_EN.md", "title_cn": "\u5b57\u7b26\u4e32\u7684\u5de6\u53f3\u79fb", "title_en": "Perform String Shifts", "question_title_slug": "perform-string-shifts", "content_en": "

You are given a string s containing lowercase English letters, and a matrix shift, where shift[i] = [directioni, amounti]:

\n\n
    \n\t
  • directioni can be 0 (for left shift) or 1 (for right shift).
  • \n\t
  • amounti is the amount by which string s is to be shifted.
  • \n\t
  • A left shift by 1 means remove the first character of s and append it to the end.
  • \n\t
  • Similarly, a right shift by 1 means remove the last character of s and add it to the beginning.
  • \n
\n\n

Return the final string after all operations.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "abc", shift = [[0,1],[1,2]]\nOutput: "cab"\nExplanation: \n[0,1] means shift to left by 1. "abc" -> "bca"\n[1,2] means shift to right by 2. "bca" -> "cab"
\n\n

Example 2:

\n\n
\nInput: s = "abcdefg", shift = [[1,1],[1,1],[0,2],[1,3]]\nOutput: "efgabcd"\nExplanation:  \n[1,1] means shift to right by 1. "abcdefg" -> "gabcdef"\n[1,1] means shift to right by 1. "gabcdef" -> "fgabcde"\n[0,2] means shift to left by 2. "fgabcde" -> "abcdefg"\n[1,3] means shift to right by 3. "abcdefg" -> "efgabcd"
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 100
  • \n\t
  • s only contains lower case English letters.
  • \n\t
  • 1 <= shift.length <= 100
  • \n\t
  • shift[i].length == 2
  • \n\t
  • directioni is either 0 or 1.
  • \n\t
  • 0 <= amounti <= 100
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7684\u5b57\u7b26\u4e32 s \u4ee5\u53ca\u4e00\u4e2a\u77e9\u9635 shift\uff0c\u5176\u4e2d shift[i] = [direction, amount]\uff1a

\n\n
    \n\t
  • direction \u53ef\u4ee5\u4e3a 0 \uff08\u8868\u793a\u5de6\u79fb\uff09\u6216 1 \uff08\u8868\u793a\u53f3\u79fb\uff09\u3002
  • \n\t
  • amount \u8868\u793a s \u5de6\u53f3\u79fb\u7684\u4f4d\u6570\u3002
  • \n\t
  • \u5de6\u79fb 1 \u4f4d\u8868\u793a\u79fb\u9664 s \u7684\u7b2c\u4e00\u4e2a\u5b57\u7b26\uff0c\u5e76\u5c06\u8be5\u5b57\u7b26\u63d2\u5165\u5230 s \u7684\u7ed3\u5c3e\u3002
  • \n\t
  • \u7c7b\u4f3c\u5730\uff0c\u53f3\u79fb 1 \u4f4d\u8868\u793a\u79fb\u9664 s \u7684\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\uff0c\u5e76\u5c06\u8be5\u5b57\u7b26\u63d2\u5165\u5230 s \u7684\u5f00\u5934\u3002
  • \n
\n\n

\u5bf9\u8fd9\u4e2a\u5b57\u7b26\u4e32\u8fdb\u884c\u6240\u6709\u64cd\u4f5c\u540e\uff0c\u8fd4\u56de\u6700\u7ec8\u7ed3\u679c\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1as = "abc", shift = [[0,1],[1,2]]\n\u8f93\u51fa\uff1a"cab"\n\u89e3\u91ca\uff1a\n[0,1] \u8868\u793a\u5de6\u79fb 1 \u4f4d\u3002 "abc" -> "bca"\n[1,2] \u8868\u793a\u53f3\u79fb 2 \u4f4d\u3002 "bca" -> "cab"
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1as = "abcdefg", shift = [[1,1],[1,1],[0,2],[1,3]]\n\u8f93\u51fa\uff1a"efgabcd"\n\u89e3\u91ca\uff1a \n[1,1] \u8868\u793a\u53f3\u79fb 1 \u4f4d\u3002 "abcdefg" -> "gabcdef"\n[1,1] \u8868\u793a\u53f3\u79fb 1 \u4f4d\u3002 "gabcdef" -> "fgabcde"\n[0,2] \u8868\u793a\u5de6\u79fb 2 \u4f4d\u3002 "fgabcde" -> "abcdefg"\n[1,3] \u8868\u793a\u53f3\u79fb 3 \u4f4d\u3002 "abcdefg" -> "efgabcd"
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length <= 100
  • \n\t
  • s \u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd
  • \n\t
  • 1 <= shift.length <= 100
  • \n\t
  • shift[i].length == 2
  • \n\t
  • 0 <= shift[i][0] <= 1
  • \n\t
  • 0 <= shift[i][1] <= 100
  • \n
\n", "tags_en": ["Array", "Math"], "tags_cn": ["\u6570\u7ec4", "\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string stringShift(string s, vector>& shift) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String stringShift(String s, int[][] shift) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def stringShift(self, s, shift):\n \"\"\"\n :type s: str\n :type shift: List[List[int]]\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def stringShift(self, s: str, shift: List[List[int]]) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * stringShift(char * s, int** shift, int shiftSize, int* shiftColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string StringShift(string s, int[][] shift) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number[][]} shift\n * @return {string}\n */\nvar stringShift = function(s, shift) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer[][]} shift\n# @return {String}\ndef string_shift(s, shift)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func stringShift(_ s: String, _ shift: [[Int]]) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func stringShift(s string, shift [][]int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def stringShift(s: String, shift: Array[Array[Int]]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun stringShift(s: String, shift: Array): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn string_shift(s: String, shift: Vec>) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer[][] $shift\n * @return String\n */\n function stringShift($s, $shift) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function stringShift(s: string, shift: number[][]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (string-shift s shift)\n (-> string? (listof (listof exact-integer?)) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1427](https://leetcode-cn.com/problems/perform-string-shifts)", "[\u5b57\u7b26\u4e32\u7684\u5de6\u53f3\u79fb](/solution/1400-1499/1427.Perform%20String%20Shifts/README.md)", "`\u6570\u7ec4`,`\u6570\u5b66`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1427](https://leetcode.com/problems/perform-string-shifts)", "[Perform String Shifts](/solution/1400-1499/1427.Perform%20String%20Shifts/README_EN.md)", "`Array`,`Math`", "Easy", "\ud83d\udd12"]}, {"question_id": "1344", "frontend_question_id": "1224", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-equal-frequency", "url_en": "https://leetcode.com/problems/maximum-equal-frequency", "relative_path_cn": "/solution/1200-1299/1224.Maximum%20Equal%20Frequency/README.md", "relative_path_en": "/solution/1200-1299/1224.Maximum%20Equal%20Frequency/README_EN.md", "title_cn": "\u6700\u5927\u76f8\u7b49\u9891\u7387", "title_en": "Maximum Equal Frequency", "question_title_slug": "maximum-equal-frequency", "content_en": "

Given an array nums of positive integers, return the longest possible length of an array prefix of nums, such that it is possible to remove exactly one element from this prefix so that every number that has appeared in it will have the same number of occurrences.

\n\n

If after removing one element there are no remaining elements, it's still considered that every appeared number has the same number of ocurrences (0).

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [2,2,1,1,5,3,3,5]\nOutput: 7\nExplanation: For the subarray [2,2,1,1,5,3,3] of length 7, if we remove nums[4]=5, we will get [2,2,1,1,3,3], so that each number will appear exactly twice.\n
\n\n

Example 2:

\n\n
\nInput: nums = [1,1,1,2,2,2,3,3,3,4,4,4,5]\nOutput: 13\n
\n\n

Example 3:

\n\n
\nInput: nums = [1,1,1,2,2,2]\nOutput: 5\n
\n\n

Example 4:

\n\n
\nInput: nums = [10,2,8,9,3,8,1,5,2,3,7,6]\nOutput: 8\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= nums.length <= 10^5
  • \n\t
  • 1 <= nums[i] <= 10^5
  • \n
\n", "content_cn": "

\u7ed9\u51fa\u4e00\u4e2a\u6b63\u6574\u6570\u6570\u7ec4 nums\uff0c\u8bf7\u4f60\u5e2e\u5fd9\u4ece\u8be5\u6570\u7ec4\u4e2d\u627e\u51fa\u80fd\u6ee1\u8db3\u4e0b\u9762\u8981\u6c42\u7684 \u6700\u957f \u524d\u7f00\uff0c\u5e76\u8fd4\u56de\u5176\u957f\u5ea6\uff1a

\n\n
    \n\t
  • \u4ece\u524d\u7f00\u4e2d \u5220\u9664\u4e00\u4e2a \u5143\u7d20\u540e\uff0c\u4f7f\u5f97\u6240\u5269\u4e0b\u7684\u6bcf\u4e2a\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\u76f8\u540c\u3002
  • \n
\n\n

\u5982\u679c\u5220\u9664\u8fd9\u4e2a\u5143\u7d20\u540e\u6ca1\u6709\u5269\u4f59\u5143\u7d20\u5b58\u5728\uff0c\u4ecd\u53ef\u8ba4\u4e3a\u6bcf\u4e2a\u6570\u5b57\u90fd\u5177\u6709\u76f8\u540c\u7684\u51fa\u73b0\u6b21\u6570\uff08\u4e5f\u5c31\u662f 0 \u6b21\uff09\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anums = [2,2,1,1,5,3,3,5]\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\u5bf9\u4e8e\u957f\u5ea6\u4e3a 7 \u7684\u5b50\u6570\u7ec4 [2,2,1,1,5,3,3]\uff0c\u5982\u679c\u6211\u4eec\u4ece\u4e2d\u5220\u53bb nums[4]=5\uff0c\u5c31\u53ef\u4ee5\u5f97\u5230 [2,2,1,1,3,3]\uff0c\u91cc\u9762\u6bcf\u4e2a\u6570\u5b57\u90fd\u51fa\u73b0\u4e86\u4e24\u6b21\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,1,1,2,2,2,3,3,3,4,4,4,5]\n\u8f93\u51fa\uff1a13\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,1,1,2,2,2]\n\u8f93\u51fa\uff1a5\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1anums = [10,2,8,9,3,8,1,5,2,3,7,6]\n\u8f93\u51fa\uff1a8\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= nums.length <= 10^5
  • \n\t
  • 1 <= nums[i] <= 10^5
  • \n
\n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxEqualFreq(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxEqualFreq(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxEqualFreq(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxEqualFreq(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxEqualFreq(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxEqualFreq(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar maxEqualFreq = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef max_equal_freq(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxEqualFreq(_ nums: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxEqualFreq(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxEqualFreq(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxEqualFreq(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_equal_freq(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function maxEqualFreq($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxEqualFreq(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-equal-freq nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1224](https://leetcode-cn.com/problems/maximum-equal-frequency)", "[\u6700\u5927\u76f8\u7b49\u9891\u7387](/solution/1200-1299/1224.Maximum%20Equal%20Frequency/README.md)", "`\u54c8\u5e0c\u8868`", "\u56f0\u96be", ""], "md_table_row_en": ["[1224](https://leetcode.com/problems/maximum-equal-frequency)", "[Maximum Equal Frequency](/solution/1200-1299/1224.Maximum%20Equal%20Frequency/README_EN.md)", "`Hash Table`", "Hard", ""]}, {"question_id": "1343", "frontend_question_id": "1223", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/dice-roll-simulation", "url_en": "https://leetcode.com/problems/dice-roll-simulation", "relative_path_cn": "/solution/1200-1299/1223.Dice%20Roll%20Simulation/README.md", "relative_path_en": "/solution/1200-1299/1223.Dice%20Roll%20Simulation/README_EN.md", "title_cn": "\u63b7\u9ab0\u5b50\u6a21\u62df", "title_en": "Dice Roll Simulation", "question_title_slug": "dice-roll-simulation", "content_en": "

A die simulator generates a random number from 1 to 6 for each roll. You introduced a constraint to the generator such that it cannot roll the number i more than rollMax[i] (1-indexed) consecutive times. 

\n\n

Given an array of integers rollMax and an integer n, return the number of distinct sequences that can be obtained with exact n rolls.

\n\n

Two sequences are considered different if at least one element differs from each other. Since the answer may be too large, return it modulo 10^9 + 7.

\n\n

 

\n

Example 1:

\n\n
\nInput: n = 2, rollMax = [1,1,2,2,2,3]\nOutput: 34\nExplanation: There will be 2 rolls of die, if there are no constraints on the die, there are 6 * 6 = 36 possible combinations. In this case, looking at rollMax array, the numbers 1 and 2 appear at most once consecutively, therefore sequences (1,1) and (2,2) cannot occur, so the final answer is 36-2 = 34.\n
\n\n

Example 2:

\n\n
\nInput: n = 2, rollMax = [1,1,1,1,1,1]\nOutput: 30\n
\n\n

Example 3:

\n\n
\nInput: n = 3, rollMax = [1,1,1,2,2,3]\nOutput: 181\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 5000
  • \n\t
  • rollMax.length == 6
  • \n\t
  • 1 <= rollMax[i] <= 15
  • \n
\n", "content_cn": "

\u6709\u4e00\u4e2a\u9ab0\u5b50\u6a21\u62df\u5668\u4f1a\u6bcf\u6b21\u6295\u63b7\u7684\u65f6\u5019\u751f\u6210\u4e00\u4e2a 1 \u5230 6 \u7684\u968f\u673a\u6570\u3002

\n\n

\u4e0d\u8fc7\u6211\u4eec\u5728\u4f7f\u7528\u5b83\u65f6\u6709\u4e2a\u7ea6\u675f\uff0c\u5c31\u662f\u4f7f\u5f97\u6295\u63b7\u9ab0\u5b50\u65f6\uff0c\u8fde\u7eed \u63b7\u51fa\u6570\u5b57 i \u7684\u6b21\u6570\u4e0d\u80fd\u8d85\u8fc7 rollMax[i]\uff08i \u4ece 1 \u5f00\u59cb\u7f16\u53f7\uff09\u3002

\n\n

\u73b0\u5728\uff0c\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 rollMax \u548c\u4e00\u4e2a\u6574\u6570 n\uff0c\u8bf7\u4f60\u6765\u8ba1\u7b97\u63b7 n \u6b21\u9ab0\u5b50\u53ef\u5f97\u5230\u7684\u4e0d\u540c\u70b9\u6570\u5e8f\u5217\u7684\u6570\u91cf\u3002

\n\n

\u5047\u5982\u4e24\u4e2a\u5e8f\u5217\u4e2d\u81f3\u5c11\u5b58\u5728\u4e00\u4e2a\u5143\u7d20\u4e0d\u540c\uff0c\u5c31\u8ba4\u4e3a\u8fd9\u4e24\u4e2a\u5e8f\u5217\u662f\u4e0d\u540c\u7684\u3002\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u5f88\u5927\uff0c\u6240\u4ee5\u8bf7\u8fd4\u56de \u6a21 10^9 + 7 \u4e4b\u540e\u7684\u7ed3\u679c\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1an = 2, rollMax = [1,1,2,2,2,3]\n\u8f93\u51fa\uff1a34\n\u89e3\u91ca\uff1a\u6211\u4eec\u63b7 2 \u6b21\u9ab0\u5b50\uff0c\u5982\u679c\u6ca1\u6709\u7ea6\u675f\u7684\u8bdd\uff0c\u5171\u6709 6 * 6 = 36 \u79cd\u53ef\u80fd\u7684\u7ec4\u5408\u3002\u4f46\u662f\u6839\u636e rollMax \u6570\u7ec4\uff0c\u6570\u5b57 1 \u548c 2 \u6700\u591a\u8fde\u7eed\u51fa\u73b0\u4e00\u6b21\uff0c\u6240\u4ee5\u4e0d\u4f1a\u51fa\u73b0\u5e8f\u5217 (1,1) \u548c (2,2)\u3002\u56e0\u6b64\uff0c\u6700\u7ec8\u7b54\u6848\u662f 36-2 = 34\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1an = 2, rollMax = [1,1,1,1,1,1]\n\u8f93\u51fa\uff1a30\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1an = 3, rollMax = [1,1,1,2,2,3]\n\u8f93\u51fa\uff1a181\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 5000
  • \n\t
  • rollMax.length == 6
  • \n\t
  • 1 <= rollMax[i] <= 15
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int dieSimulator(int n, vector& rollMax) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int dieSimulator(int n, int[] rollMax) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def dieSimulator(self, n, rollMax):\n \"\"\"\n :type n: int\n :type rollMax: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def dieSimulator(self, n: int, rollMax: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint dieSimulator(int n, int* rollMax, int rollMaxSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int DieSimulator(int n, int[] rollMax) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[]} rollMax\n * @return {number}\n */\nvar dieSimulator = function(n, rollMax) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[]} roll_max\n# @return {Integer}\ndef die_simulator(n, roll_max)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func dieSimulator(_ n: Int, _ rollMax: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func dieSimulator(n int, rollMax []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def dieSimulator(n: Int, rollMax: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun dieSimulator(n: Int, rollMax: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn die_simulator(n: i32, roll_max: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[] $rollMax\n * @return Integer\n */\n function dieSimulator($n, $rollMax) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function dieSimulator(n: number, rollMax: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (die-simulator n rollMax)\n (-> exact-integer? (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1223](https://leetcode-cn.com/problems/dice-roll-simulation)", "[\u63b7\u9ab0\u5b50\u6a21\u62df](/solution/1200-1299/1223.Dice%20Roll%20Simulation/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1223](https://leetcode.com/problems/dice-roll-simulation)", "[Dice Roll Simulation](/solution/1200-1299/1223.Dice%20Roll%20Simulation/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "1342", "frontend_question_id": "1222", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/queens-that-can-attack-the-king", "url_en": "https://leetcode.com/problems/queens-that-can-attack-the-king", "relative_path_cn": "/solution/1200-1299/1222.Queens%20That%20Can%20Attack%20the%20King/README.md", "relative_path_en": "/solution/1200-1299/1222.Queens%20That%20Can%20Attack%20the%20King/README_EN.md", "title_cn": "\u53ef\u4ee5\u653b\u51fb\u56fd\u738b\u7684\u7687\u540e", "title_en": "Queens That Can Attack the King", "question_title_slug": "queens-that-can-attack-the-king", "content_en": "

On an 8x8 chessboard, there can be multiple Black Queens and one White King.

\r\n\r\n

Given an array of integer coordinates queens that represents the positions of the Black Queens, and a pair of coordinates king that represent the position of the White King, return the coordinates of all the queens (in any order) that can attack the King.

\n

 

\n

Example 1:

\r\n\r\n

\"\"

\r\n\r\n
\r\nInput: queens = [[0,1],[1,0],[4,0],[0,4],[3,3],[2,4]], king = [0,0]\r\nOutput: [[0,1],[1,0],[3,3]]\r\nExplanation:  \r\nThe queen at [0,1] can attack the king cause they're in the same row. \r\nThe queen at [1,0] can attack the king cause they're in the same column. \r\nThe queen at [3,3] can attack the king cause they're in the same diagnal. \r\nThe queen at [0,4] can't attack the king cause it's blocked by the queen at [0,1]. \r\nThe queen at [4,0] can't attack the king cause it's blocked by the queen at [1,0]. \r\nThe queen at [2,4] can't attack the king cause it's not in the same row/column/diagnal as the king.\r\n
\r\n\r\n

Example 2:

\r\n\r\n

\"\"

\r\n\r\n
\r\nInput: queens = [[0,0],[1,1],[2,2],[3,4],[3,5],[4,4],[4,5]], king = [3,3]\r\nOutput: [[2,2],[3,4],[4,4]]\r\n
\r\n\r\n

Example 3:

\r\n\r\n

\"\"

\r\n\r\n
\r\nInput: queens = [[5,6],[7,7],[2,1],[0,7],[1,6],[5,1],[3,7],[0,3],[4,0],[1,2],[6,3],[5,0],[0,4],[2,2],[1,1],[6,4],[5,4],[0,0],[2,6],[4,5],[5,2],[1,4],[7,5],[2,3],[0,5],[4,2],[1,0],[2,7],[0,1],[4,6],[6,1],[0,6],[4,3],[1,7]], king = [3,4]\r\nOutput: [[2,3],[1,4],[1,6],[3,7],[4,3],[5,4],[4,5]]\r\n
\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= queens.length <= 63
  • \n\t
  • queens[i].length == 2
  • \n\t
  • 0 <= queens[i][j] < 8
  • \n\t
  • king.length == 2
  • \n\t
  • 0 <= king[0], king[1] < 8
  • \n\t
  • At most one piece is allowed in a cell.
  • \n
\n", "content_cn": "

\u5728\u4e00\u4e2a\u00a08x8\u00a0\u7684\u68cb\u76d8\u4e0a\uff0c\u653e\u7f6e\u7740\u82e5\u5e72\u300c\u9ed1\u7687\u540e\u300d\u548c\u4e00\u4e2a\u300c\u767d\u56fd\u738b\u300d\u3002

\n\n

\u300c\u9ed1\u7687\u540e\u300d\u5728\u68cb\u76d8\u4e0a\u7684\u4f4d\u7f6e\u5206\u5e03\u7528\u6574\u6570\u5750\u6807\u6570\u7ec4\u00a0queens\u00a0\u8868\u793a\uff0c\u300c\u767d\u56fd\u738b\u300d\u7684\u5750\u6807\u7528\u6570\u7ec4 king \u8868\u793a\u3002

\n\n

\u300c\u9ed1\u7687\u540e\u300d\u7684\u884c\u68cb\u89c4\u5b9a\u662f\uff1a\u6a2a\u3001\u76f4\u3001\u659c\u90fd\u53ef\u4ee5\u8d70\uff0c\u6b65\u6570\u4e0d\u53d7\u9650\u5236\uff0c\u4f46\u662f\uff0c\u4e0d\u80fd\u8d8a\u5b50\u884c\u68cb\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u53ef\u4ee5\u76f4\u63a5\u653b\u51fb\u5230\u300c\u767d\u56fd\u738b\u300d\u7684\u6240\u6709\u300c\u9ed1\u7687\u540e\u300d\u7684\u5750\u6807\uff08\u4efb\u610f\u987a\u5e8f\uff09\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1aqueens = [[0,1],[1,0],[4,0],[0,4],[3,3],[2,4]], king = [0,0]\n\u8f93\u51fa\uff1a[[0,1],[1,0],[3,3]]\n\u89e3\u91ca\uff1a \n[0,1] \u7684\u7687\u540e\u53ef\u4ee5\u653b\u51fb\u5230\u56fd\u738b\uff0c\u56e0\u4e3a\u4ed6\u4eec\u5728\u540c\u4e00\u884c\u4e0a\u3002 \n[1,0] \u7684\u7687\u540e\u53ef\u4ee5\u653b\u51fb\u5230\u56fd\u738b\uff0c\u56e0\u4e3a\u4ed6\u4eec\u5728\u540c\u4e00\u5217\u4e0a\u3002 \n[3,3] \u7684\u7687\u540e\u53ef\u4ee5\u653b\u51fb\u5230\u56fd\u738b\uff0c\u56e0\u4e3a\u4ed6\u4eec\u5728\u540c\u4e00\u6761\u5bf9\u89d2\u7ebf\u4e0a\u3002 \n[0,4] \u7684\u7687\u540e\u65e0\u6cd5\u653b\u51fb\u5230\u56fd\u738b\uff0c\u56e0\u4e3a\u5979\u88ab\u4f4d\u4e8e [0,1] \u7684\u7687\u540e\u6321\u4f4f\u4e86\u3002 \n[4,0] \u7684\u7687\u540e\u65e0\u6cd5\u653b\u51fb\u5230\u56fd\u738b\uff0c\u56e0\u4e3a\u5979\u88ab\u4f4d\u4e8e [1,0] \u7684\u7687\u540e\u6321\u4f4f\u4e86\u3002 \n[2,4] \u7684\u7687\u540e\u65e0\u6cd5\u653b\u51fb\u5230\u56fd\u738b\uff0c\u56e0\u4e3a\u5979\u548c\u56fd\u738b\u4e0d\u5728\u540c\u4e00\u884c/\u5217/\u5bf9\u89d2\u7ebf\u4e0a\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1aqueens = [[0,0],[1,1],[2,2],[3,4],[3,5],[4,4],[4,5]], king = [3,3]\n\u8f93\u51fa\uff1a[[2,2],[3,4],[4,4]]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1aqueens = [[5,6],[7,7],[2,1],[0,7],[1,6],[5,1],[3,7],[0,3],[4,0],[1,2],[6,3],[5,0],[0,4],[2,2],[1,1],[6,4],[5,4],[0,0],[2,6],[4,5],[5,2],[1,4],[7,5],[2,3],[0,5],[4,2],[1,0],[2,7],[0,1],[4,6],[6,1],[0,6],[4,3],[1,7]], king = [3,4]\n\u8f93\u51fa\uff1a[[2,3],[1,4],[1,6],[3,7],[4,3],[5,4],[4,5]]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= queens.length\u00a0<= 63
  • \n\t
  • queens[i].length == 2
  • \n\t
  • 0 <= queens[i][j] <\u00a08
  • \n\t
  • king.length == 2
  • \n\t
  • 0 <= king[0], king[1] < 8
  • \n\t
  • \u4e00\u4e2a\u68cb\u76d8\u683c\u4e0a\u6700\u591a\u53ea\u80fd\u653e\u7f6e\u4e00\u679a\u68cb\u5b50\u3002
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> queensAttacktheKing(vector>& queens, vector& king) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> queensAttacktheKing(int[][] queens, int[] king) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def queensAttacktheKing(self, queens, king):\n \"\"\"\n :type queens: List[List[int]]\n :type king: List[int]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def queensAttacktheKing(self, queens: List[List[int]], king: List[int]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** queensAttacktheKing(int** queens, int queensSize, int* queensColSize, int* king, int kingSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> QueensAttacktheKing(int[][] queens, int[] king) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} queens\n * @param {number[]} king\n * @return {number[][]}\n */\nvar queensAttacktheKing = function(queens, king) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} queens\n# @param {Integer[]} king\n# @return {Integer[][]}\ndef queens_attackthe_king(queens, king)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func queensAttacktheKing(_ queens: [[Int]], _ king: [Int]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func queensAttacktheKing(queens [][]int, king []int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def queensAttacktheKing(queens: Array[Array[Int]], king: Array[Int]): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun queensAttacktheKing(queens: Array, king: IntArray): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn queens_attackthe_king(queens: Vec>, king: Vec) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $queens\n * @param Integer[] $king\n * @return Integer[][]\n */\n function queensAttacktheKing($queens, $king) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function queensAttacktheKing(queens: number[][], king: number[]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (queens-attackthe-king queens king)\n (-> (listof (listof exact-integer?)) (listof exact-integer?) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1222](https://leetcode-cn.com/problems/queens-that-can-attack-the-king)", "[\u53ef\u4ee5\u653b\u51fb\u56fd\u738b\u7684\u7687\u540e](/solution/1200-1299/1222.Queens%20That%20Can%20Attack%20the%20King/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1222](https://leetcode.com/problems/queens-that-can-attack-the-king)", "[Queens That Can Attack the King](/solution/1200-1299/1222.Queens%20That%20Can%20Attack%20the%20King/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "1341", "frontend_question_id": "1221", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/split-a-string-in-balanced-strings", "url_en": "https://leetcode.com/problems/split-a-string-in-balanced-strings", "relative_path_cn": "/solution/1200-1299/1221.Split%20a%20String%20in%20Balanced%20Strings/README.md", "relative_path_en": "/solution/1200-1299/1221.Split%20a%20String%20in%20Balanced%20Strings/README_EN.md", "title_cn": "\u5206\u5272\u5e73\u8861\u5b57\u7b26\u4e32", "title_en": "Split a String in Balanced Strings", "question_title_slug": "split-a-string-in-balanced-strings", "content_en": "

Balanced strings are those that have an equal quantity of 'L' and 'R' characters.

\n\n

Given a balanced string s, split it in the maximum amount of balanced strings.

\n\n

Return the maximum amount of split balanced strings.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "RLRRLLRLRL"\nOutput: 4\nExplanation: s can be split into "RL", "RRLL", "RL", "RL", each substring contains same number of 'L' and 'R'.\n
\n\n

Example 2:

\n\n
\nInput: s = "RLLLLRRRLR"\nOutput: 3\nExplanation: s can be split into "RL", "LLLRRR", "LR", each substring contains same number of 'L' and 'R'.\n
\n\n

Example 3:

\n\n
\nInput: s = "LLLLRRRR"\nOutput: 1\nExplanation: s can be split into "LLLLRRRR".\n
\n\n

Example 4:

\n\n
\nInput: s = "RLRRRLLRLL"\nOutput: 2\nExplanation: s can be split into "RL", "RRRLLRLL", since each substring contains an equal number of 'L' and 'R'\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 1000
  • \n\t
  • s[i] is either 'L' or 'R'.
  • \n\t
  • s is a balanced string.
  • \n
\n", "content_cn": "

\u5728\u4e00\u4e2a \u5e73\u8861\u5b57\u7b26\u4e32 \u4e2d\uff0c'L' \u548c 'R' \u5b57\u7b26\u7684\u6570\u91cf\u662f\u76f8\u540c\u7684\u3002

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u5e73\u8861\u5b57\u7b26\u4e32\u00a0s\uff0c\u8bf7\u4f60\u5c06\u5b83\u5206\u5272\u6210\u5c3d\u53ef\u80fd\u591a\u7684\u5e73\u8861\u5b57\u7b26\u4e32\u3002

\n\n

\u6ce8\u610f\uff1a\u5206\u5272\u5f97\u5230\u7684\u6bcf\u4e2a\u5b57\u7b26\u4e32\u90fd\u5fc5\u987b\u662f\u5e73\u8861\u5b57\u7b26\u4e32\u3002

\n\n

\u8fd4\u56de\u53ef\u4ee5\u901a\u8fc7\u5206\u5272\u5f97\u5230\u7684\u5e73\u8861\u5b57\u7b26\u4e32\u7684 \u6700\u5927\u6570\u91cf \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"RLRRLLRLRL\"\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1as \u53ef\u4ee5\u5206\u5272\u4e3a \"RL\"\u3001\"RRLL\"\u3001\"RL\"\u3001\"RL\" \uff0c\u6bcf\u4e2a\u5b50\u5b57\u7b26\u4e32\u4e2d\u90fd\u5305\u542b\u76f8\u540c\u6570\u91cf\u7684 'L' \u548c 'R' \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"RLLLLRRRLR\"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1as \u53ef\u4ee5\u5206\u5272\u4e3a \"RL\"\u3001\"LLLRRR\"\u3001\"LR\" \uff0c\u6bcf\u4e2a\u5b50\u5b57\u7b26\u4e32\u4e2d\u90fd\u5305\u542b\u76f8\u540c\u6570\u91cf\u7684 'L' \u548c 'R' \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"LLLLRRRR\"\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1as \u53ea\u80fd\u4fdd\u6301\u539f\u6837 \"LLLLRRRR\".\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"RLRRRLLRLL\"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1as \u53ef\u4ee5\u5206\u5272\u4e3a \"RL\"\u3001\"RRRLLRLL\" \uff0c\u6bcf\u4e2a\u5b50\u5b57\u7b26\u4e32\u4e2d\u90fd\u5305\u542b\u76f8\u540c\u6570\u91cf\u7684 'L' \u548c 'R' \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length <= 1000
  • \n\t
  • s[i] = 'L' \u6216 'R'
  • \n\t
  • s \u662f\u4e00\u4e2a \u5e73\u8861 \u5b57\u7b26\u4e32
  • \n
\n", "tags_en": ["Greedy", "String"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int balancedStringSplit(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int balancedStringSplit(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def balancedStringSplit(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def balancedStringSplit(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint balancedStringSplit(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int BalancedStringSplit(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar balancedStringSplit = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef balanced_string_split(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func balancedStringSplit(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func balancedStringSplit(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def balancedStringSplit(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun balancedStringSplit(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn balanced_string_split(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function balancedStringSplit($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function balancedStringSplit(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (balanced-string-split s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1221](https://leetcode-cn.com/problems/split-a-string-in-balanced-strings)", "[\u5206\u5272\u5e73\u8861\u5b57\u7b26\u4e32](/solution/1200-1299/1221.Split%20a%20String%20in%20Balanced%20Strings/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1221](https://leetcode.com/problems/split-a-string-in-balanced-strings)", "[Split a String in Balanced Strings](/solution/1200-1299/1221.Split%20a%20String%20in%20Balanced%20Strings/README_EN.md)", "`Greedy`,`String`", "Easy", ""]}, {"question_id": "1340", "frontend_question_id": "1226", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/the-dining-philosophers", "url_en": "https://leetcode.com/problems/the-dining-philosophers", "relative_path_cn": "/solution/1200-1299/1226.The%20Dining%20Philosophers/README.md", "relative_path_en": "/solution/1200-1299/1226.The%20Dining%20Philosophers/README_EN.md", "title_cn": "\u54f2\u5b66\u5bb6\u8fdb\u9910", "title_en": "The Dining Philosophers", "question_title_slug": "the-dining-philosophers", "content_en": "

Five silent philosophers sit at a round table with bowls of spaghetti. Forks are placed between each pair of adjacent philosophers.

\n\n

Each philosopher must alternately think and eat. However, a philosopher can only eat spaghetti when they have both left and right forks. Each fork can be held by only one philosopher and so a philosopher can use the fork only if it is not being used by another philosopher. After an individual philosopher finishes eating, they need to put down both forks so that the forks become available to others. A philosopher can take the fork on their right or the one on their left as they become available, but cannot start eating before getting both forks.

\n\n

Eating is not limited by the remaining amounts of spaghetti or stomach space; an infinite supply and an infinite demand are assumed.

\n\n

Design a discipline of behaviour (a concurrent algorithm) such that no philosopher will starve; i.e., each can forever continue to alternate between eating and thinking, assuming that no philosopher can know when others may want to eat or think.

\n\n

\"\"

\n\n

The problem statement and the image above are taken from wikipedia.org

\n\n

 

\n\n

The philosophers' ids are numbered from 0 to 4 in a clockwise order. Implement the function void wantsToEat(philosopher, pickLeftFork, pickRightFork, eat, putLeftFork, putRightFork) where:

\n\n
    \n\t
  • philosopher is the id of the philosopher who wants to eat.
  • \n\t
  • pickLeftFork and pickRightFork are functions you can call to pick the corresponding forks of that philosopher.
  • \n\t
  • eat is a function you can call to let the philosopher eat once he has picked both forks.
  • \n\t
  • putLeftFork and putRightFork are functions you can call to put down the corresponding forks of that philosopher.
  • \n\t
  • The philosophers are assumed to be thinking as long as they are not asking to eat (the function is not being called with their number).
  • \n
\n\n

Five threads, each representing a philosopher, will simultaneously use one object of your class to simulate the process. The function may be called for the same philosopher more than once, even before the last call ends.

\n\n

 

\n

Example 1:

\n\n
\nInput: n = 1\nOutput: [[4,2,1],[4,1,1],[0,1,1],[2,2,1],[2,1,1],[2,0,3],[2,1,2],[2,2,2],[4,0,3],[4,1,2],[0,2,1],[4,2,2],[3,2,1],[3,1,1],[0,0,3],[0,1,2],[0,2,2],[1,2,1],[1,1,1],[3,0,3],[3,1,2],[3,2,2],[1,0,3],[1,1,2],[1,2,2]]\nExplanation:\nn is the number of times each philosopher will call the function.\nThe output array describes the calls you made to the functions controlling the forks and the eat function, its format is:\noutput[i] = [a, b, c] (three integers)\n- a is the id of a philosopher.\n- b specifies the fork: {1 : left, 2 : right}.\n- c specifies the operation: {1 : pick, 2 : put, 3 : eat}.
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 60
  • \n
\n", "content_cn": "

5 \u4e2a\u6c89\u9ed8\u5be1\u8a00\u7684\u54f2\u5b66\u5bb6\u56f4\u5750\u5728\u5706\u684c\u524d\uff0c\u6bcf\u4eba\u9762\u524d\u4e00\u76d8\u610f\u9762\u3002\u53c9\u5b50\u653e\u5728\u54f2\u5b66\u5bb6\u4e4b\u95f4\u7684\u684c\u9762\u4e0a\u3002\uff085 \u4e2a\u54f2\u5b66\u5bb6\uff0c5 \u6839\u53c9\u5b50\uff09

\n\n

\u6240\u6709\u7684\u54f2\u5b66\u5bb6\u90fd\u53ea\u4f1a\u5728\u601d\u8003\u548c\u8fdb\u9910\u4e24\u79cd\u884c\u4e3a\u95f4\u4ea4\u66ff\u3002\u54f2\u5b66\u5bb6\u53ea\u6709\u540c\u65f6\u62ff\u5230\u5de6\u8fb9\u548c\u53f3\u8fb9\u7684\u53c9\u5b50\u624d\u80fd\u5403\u5230\u9762\uff0c\u800c\u540c\u4e00\u6839\u53c9\u5b50\u5728\u540c\u4e00\u65f6\u95f4\u53ea\u80fd\u88ab\u4e00\u4e2a\u54f2\u5b66\u5bb6\u4f7f\u7528\u3002\u6bcf\u4e2a\u54f2\u5b66\u5bb6\u5403\u5b8c\u9762\u540e\u90fd\u9700\u8981\u628a\u53c9\u5b50\u653e\u56de\u684c\u9762\u4ee5\u4f9b\u5176\u4ed6\u54f2\u5b66\u5bb6\u5403\u9762\u3002\u53ea\u8981\u6761\u4ef6\u5141\u8bb8\uff0c\u54f2\u5b66\u5bb6\u53ef\u4ee5\u62ff\u8d77\u5de6\u8fb9\u6216\u8005\u53f3\u8fb9\u7684\u53c9\u5b50\uff0c\u4f46\u5728\u6ca1\u6709\u540c\u65f6\u62ff\u5230\u5de6\u53f3\u53c9\u5b50\u65f6\u4e0d\u80fd\u8fdb\u98df\u3002

\n\n

\u5047\u8bbe\u9762\u7684\u6570\u91cf\u6ca1\u6709\u9650\u5236\uff0c\u54f2\u5b66\u5bb6\u4e5f\u80fd\u968f\u4fbf\u5403\uff0c\u4e0d\u9700\u8981\u8003\u8651\u5403\u4e0d\u5403\u5f97\u4e0b\u3002

\n\n

\u8bbe\u8ba1\u4e00\u4e2a\u8fdb\u9910\u89c4\u5219\uff08\u5e76\u884c\u7b97\u6cd5\uff09\u4f7f\u5f97\u6bcf\u4e2a\u54f2\u5b66\u5bb6\u90fd\u4e0d\u4f1a\u6328\u997f\uff1b\u4e5f\u5c31\u662f\u8bf4\uff0c\u5728\u6ca1\u6709\u4eba\u77e5\u9053\u522b\u4eba\u4ec0\u4e48\u65f6\u5019\u60f3\u5403\u4e1c\u897f\u6216\u601d\u8003\u7684\u60c5\u51b5\u4e0b\uff0c\u6bcf\u4e2a\u54f2\u5b66\u5bb6\u90fd\u53ef\u4ee5\u5728\u5403\u996d\u548c\u601d\u8003\u4e4b\u95f4\u4e00\u76f4\u4ea4\u66ff\u4e0b\u53bb\u3002

\n\n

\"\"

\n\n

\u95ee\u9898\u63cf\u8ff0\u548c\u56fe\u7247\u6765\u81ea\u7ef4\u57fa\u767e\u79d1 wikipedia.org

\n\n

 

\n\n

\u54f2\u5b66\u5bb6\u4ece 0 \u5230 4 \u6309 \u987a\u65f6\u9488 \u7f16\u53f7\u3002\u8bf7\u5b9e\u73b0\u51fd\u6570 void wantsToEat(philosopher, pickLeftFork, pickRightFork, eat, putLeftFork, putRightFork)\uff1a

\n\n
    \n\t
  • philosopher \u54f2\u5b66\u5bb6\u7684\u7f16\u53f7\u3002
  • \n\t
  • pickLeftFork \u548c pickRightFork \u8868\u793a\u62ff\u8d77\u5de6\u8fb9\u6216\u53f3\u8fb9\u7684\u53c9\u5b50\u3002
  • \n\t
  • eat \u8868\u793a\u5403\u9762\u3002
  • \n\t
  • putLeftFork \u548c putRightFork \u8868\u793a\u653e\u4e0b\u5de6\u8fb9\u6216\u53f3\u8fb9\u7684\u53c9\u5b50\u3002
  • \n\t
  • \u7531\u4e8e\u54f2\u5b66\u5bb6\u4e0d\u662f\u5728\u5403\u9762\u5c31\u662f\u5728\u60f3\u7740\u5565\u65f6\u5019\u5403\u9762\uff0c\u6240\u4ee5\u601d\u8003\u8fd9\u4e2a\u65b9\u6cd5\u6ca1\u6709\u5bf9\u5e94\u7684\u56de\u8c03\u3002
  • \n
\n\n

\u7ed9\u4f60 5 \u4e2a\u7ebf\u7a0b\uff0c\u6bcf\u4e2a\u90fd\u4ee3\u8868\u4e00\u4e2a\u54f2\u5b66\u5bb6\uff0c\u8bf7\u4f60\u4f7f\u7528\u7c7b\u7684\u540c\u4e00\u4e2a\u5bf9\u8c61\u6765\u6a21\u62df\u8fd9\u4e2a\u8fc7\u7a0b\u3002\u5728\u6700\u540e\u4e00\u6b21\u8c03\u7528\u7ed3\u675f\u4e4b\u524d\uff0c\u53ef\u80fd\u4f1a\u4e3a\u540c\u4e00\u4e2a\u54f2\u5b66\u5bb6\u591a\u6b21\u8c03\u7528\u8be5\u51fd\u6570\u3002

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1a[[4,2,1],[4,1,1],[0,1,1],[2,2,1],[2,1,1],[2,0,3],[2,1,2],[2,2,2],[4,0,3],[4,1,2],[0,2,1],[4,2,2],[3,2,1],[3,1,1],[0,0,3],[0,1,2],[0,2,2],[1,2,1],[1,1,1],[3,0,3],[3,1,2],[3,2,2],[1,0,3],[1,1,2],[1,2,2]]\n\u89e3\u91ca:\nn \u8868\u793a\u6bcf\u4e2a\u54f2\u5b66\u5bb6\u9700\u8981\u8fdb\u9910\u7684\u6b21\u6570\u3002\n\u8f93\u51fa\u6570\u7ec4\u63cf\u8ff0\u4e86\u53c9\u5b50\u7684\u63a7\u5236\u548c\u8fdb\u9910\u7684\u8c03\u7528\uff0c\u5b83\u7684\u683c\u5f0f\u5982\u4e0b\uff1a\noutput[i] = [a, b, c] (3\u4e2a\u6574\u6570)\n- a \u54f2\u5b66\u5bb6\u7f16\u53f7\u3002\n- b \u6307\u5b9a\u53c9\u5b50\uff1a{1 : \u5de6\u8fb9, 2 : \u53f3\u8fb9}.\n- c \u6307\u5b9a\u884c\u4e3a\uff1a{1 : \u62ff\u8d77, 2 : \u653e\u4e0b, 3 : \u5403\u9762}\u3002\n\u5982 [4,2,1] \u8868\u793a 4 \u53f7\u54f2\u5b66\u5bb6\u62ff\u8d77\u4e86\u53f3\u8fb9\u7684\u53c9\u5b50\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 60
  • \n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class DiningPhilosophers {\npublic:\n DiningPhilosophers() {\n \n }\n\n void wantsToEat(int philosopher,\n function pickLeftFork,\n function pickRightFork,\n function eat,\n function putLeftFork,\n function putRightFork) {\n\t\t\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class DiningPhilosophers {\n\n public DiningPhilosophers() {\n \n }\n\n // call the run() method of any runnable to execute its code\n public void wantsToEat(int philosopher,\n Runnable pickLeftFork,\n Runnable pickRightFork,\n Runnable eat,\n Runnable putLeftFork,\n Runnable putRightFork) throws InterruptedException {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class DiningPhilosophers(object):\n\n # call the functions directly to execute, for example, eat()\n def wantsToEat(self, philosopher, pickLeftFork, pickRightFork, eat, putLeftFork, putRightFork):\n \"\"\"\n :type philosopher: int\n :type pickLeftFork: method\n :type pickRightFork: method\n :type eat: method\n :type putLeftFork: method\n :type putRightFork: method\n :rtype: void\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class DiningPhilosophers:\n\n # call the functions directly to execute, for example, eat()\n def wantsToEat(self,\n philosopher: int,\n pickLeftFork: 'Callable[[], None]',\n pickRightFork: 'Callable[[], None]',\n eat: 'Callable[[], None]',\n putLeftFork: 'Callable[[], None]',\n putRightFork: 'Callable[[], None]') -> None:\n ", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1226](https://leetcode-cn.com/problems/the-dining-philosophers)", "[\u54f2\u5b66\u5bb6\u8fdb\u9910](/solution/1200-1299/1226.The%20Dining%20Philosophers/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1226](https://leetcode.com/problems/the-dining-philosophers)", "[The Dining Philosophers](/solution/1200-1299/1226.The%20Dining%20Philosophers/README_EN.md)", "", "Medium", ""]}, {"question_id": "1339", "frontend_question_id": "1212", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/team-scores-in-football-tournament", "url_en": "https://leetcode.com/problems/team-scores-in-football-tournament", "relative_path_cn": "/solution/1200-1299/1212.Team%20Scores%20in%20Football%20Tournament/README.md", "relative_path_en": "/solution/1200-1299/1212.Team%20Scores%20in%20Football%20Tournament/README_EN.md", "title_cn": "\u67e5\u8be2\u7403\u961f\u79ef\u5206", "title_en": "Team Scores in Football Tournament", "question_title_slug": "team-scores-in-football-tournament", "content_en": "

Table: Teams

\n\n
\n+---------------+----------+\n| Column Name   | Type     |\n+---------------+----------+\n| team_id       | int      |\n| team_name     | varchar  |\n+---------------+----------+\nteam_id is the primary key of this table.\nEach row of this table represents a single football team.\n
\n\n

Table: Matches

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| match_id      | int     |\n| host_team     | int     |\n| guest_team    | int     | \n| host_goals    | int     |\n| guest_goals   | int     |\n+---------------+---------+\nmatch_id is the primary key of this table.\nEach row is a record of a finished match between two different teams. \nTeams host_team and guest_team are represented by their IDs in the teams table (team_id) and they scored host_goals and guest_goals goals respectively.\n
\n\n

 

\nYou would like to compute the scores of all teams after all matches. Points are awarded as follows:\n\n
    \n\t
  • A team receives three points if they win a match (Score strictly more goals than the opponent team).
  • \n\t
  • A team receives one point if they draw a match (Same number of goals as the opponent team).
  • \n\t
  • A team receives no points if they lose a match (Score less goals than the opponent team).
  • \n
\n\n

Write an SQL query that selects the team_id, team_name and num_points of each team in the tournament after all described matches. Result table should be ordered by num_points (decreasing order). In case of a tie, order the records by team_id (increasing order).

\n\n

The query result format is in the following example:

\n\n
\nTeams table:\n+-----------+--------------+\n| team_id   | team_name    |\n+-----------+--------------+\n| 10        | Leetcode FC  |\n| 20        | NewYork FC   |\n| 30        | Atlanta FC   |\n| 40        | Chicago FC   |\n| 50        | Toronto FC   |\n+-----------+--------------+\n\nMatches table:\n+------------+--------------+---------------+-------------+--------------+\n| match_id   | host_team    | guest_team    | host_goals  | guest_goals  |\n+------------+--------------+---------------+-------------+--------------+\n| 1          | 10           | 20            | 3           | 0            |\n| 2          | 30           | 10            | 2           | 2            |\n| 3          | 10           | 50            | 5           | 1            |\n| 4          | 20           | 30            | 1           | 0            |\n| 5          | 50           | 30            | 1           | 0            |\n+------------+--------------+---------------+-------------+--------------+\n\nResult table:\n+------------+--------------+---------------+\n| team_id    | team_name    | num_points    |\n+------------+--------------+---------------+\n| 10         | Leetcode FC  | 7             |\n| 20         | NewYork FC   | 3             |\n| 50         | Toronto FC   | 3             |\n| 30         | Atlanta FC   | 1             |\n| 40         | Chicago FC   | 0             |\n+------------+--------------+---------------+\n
\n", "content_cn": "

Table: Teams

\n\n
\n+---------------+----------+\n| Column Name   | Type     |\n+---------------+----------+\n| team_id       | int      |\n| team_name     | varchar  |\n+---------------+----------+\n\u6b64\u8868\u7684\u4e3b\u952e\u662f team_id\uff0c\u8868\u4e2d\u7684\u6bcf\u4e00\u884c\u90fd\u4ee3\u8868\u4e00\u652f\u72ec\u7acb\u8db3\u7403\u961f\u3002\n
\n\n

Table: Matches

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| match_id      | int     |\n| host_team     | int     |\n| guest_team    | int     | \n| host_goals    | int     |\n| guest_goals   | int     |\n+---------------+---------+\n\u6b64\u8868\u7684\u4e3b\u952e\u662f match_id\uff0c\u8868\u4e2d\u7684\u6bcf\u4e00\u884c\u90fd\u4ee3\u8868\u4e00\u573a\u5df2\u7ed3\u675f\u7684\u6bd4\u8d5b\uff0c\u6bd4\u8d5b\u7684\u4e3b\u5ba2\u961f\u5206\u522b\u7531\u5b83\u4eec\u81ea\u5df1\u7684 id \u8868\u793a\uff0c\u4ed6\u4eec\u7684\u8fdb\u7403\u7531 host_goals \u548c guest_goals \u5206\u522b\u8868\u793a\u3002\n
\n\n

 

\n\n

\u79ef\u5206\u89c4\u5219\u5982\u4e0b\uff1a

\n\n
    \n\t
  • \u8d62\u4e00\u573a\u5f97\u4e09\u5206\uff1b
  • \n\t
  • \u5e73\u4e00\u573a\u5f97\u4e00\u5206\uff1b
  • \n\t
  • \u8f93\u4e00\u573a\u4e0d\u5f97\u5206\u3002
  • \n
\n\n

\u5199\u51fa\u4e00\u6761SQL\u8bed\u53e5\u4ee5\u67e5\u8be2\u6bcf\u4e2a\u961f\u7684 team_id\uff0cteam_name \u548c num_points\u3002\u7ed3\u679c\u6839\u636e num_points \u964d\u5e8f\u6392\u5e8f\uff0c\u5982\u679c\u6709\u4e24\u961f\u79ef\u5206\u76f8\u540c\uff0c\u90a3\u4e48\u8fd9\u4e24\u961f\u6309 team_id  \u5347\u5e8f\u6392\u5e8f\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\uff1a

\n\n
\nTeams table:\n+-----------+--------------+\n| team_id   | team_name    |\n+-----------+--------------+\n| 10        | Leetcode FC  |\n| 20        | NewYork FC   |\n| 30        | Atlanta FC   |\n| 40        | Chicago FC   |\n| 50        | Toronto FC   |\n+-----------+--------------+\n\nMatches table:\n+------------+--------------+---------------+-------------+--------------+\n| match_id   | host_team    | guest_team    | host_goals  | guest_goals  |\n+------------+--------------+---------------+-------------+--------------+\n| 1          | 10           | 20            | 3           | 0            |\n| 2          | 30           | 10            | 2           | 2            |\n| 3          | 10           | 50            | 5           | 1            |\n| 4          | 20           | 30            | 1           | 0            |\n| 5          | 50           | 30            | 1           | 0            |\n+------------+--------------+---------------+-------------+--------------+\n\nResult table:\n+------------+--------------+---------------+\n| team_id    | team_name    | num_points    |\n+------------+--------------+---------------+\n| 10         | Leetcode FC  | 7             |\n| 20         | NewYork FC   | 3             |\n| 50         | Toronto FC   | 3             |\n| 30         | Atlanta FC   | 1             |\n| 40         | Chicago FC   | 0             |\n+------------+--------------+---------------+\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1212](https://leetcode-cn.com/problems/team-scores-in-football-tournament)", "[\u67e5\u8be2\u7403\u961f\u79ef\u5206](/solution/1200-1299/1212.Team%20Scores%20in%20Football%20Tournament/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1212](https://leetcode.com/problems/team-scores-in-football-tournament)", "[Team Scores in Football Tournament](/solution/1200-1299/1212.Team%20Scores%20in%20Football%20Tournament/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1338", "frontend_question_id": "1211", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/queries-quality-and-percentage", "url_en": "https://leetcode.com/problems/queries-quality-and-percentage", "relative_path_cn": "/solution/1200-1299/1211.Queries%20Quality%20and%20Percentage/README.md", "relative_path_en": "/solution/1200-1299/1211.Queries%20Quality%20and%20Percentage/README_EN.md", "title_cn": "\u67e5\u8be2\u7ed3\u679c\u7684\u8d28\u91cf\u548c\u5360\u6bd4", "title_en": "Queries Quality and Percentage", "question_title_slug": "queries-quality-and-percentage", "content_en": "

Table: Queries

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| query_name  | varchar |\n| result      | varchar |\n| position    | int     |\n| rating      | int     |\n+-------------+---------+\nThere is no primary key for this table, it may have duplicate rows.\nThis table contains information collected from some queries on a database.\nThe position column has a value from 1 to 500.\nThe rating column has a value from 1 to 5. Query with rating less than 3 is a poor query.\n
\n\n

 

\n\n

We define query quality as:

\n\n
\n

The average of the ratio between query rating and its position.

\n
\n\n

We also define poor query percentage as:

\n\n
\n

The percentage of all queries with rating less than 3.

\n
\n\n

Write an SQL query to find each query_name, the quality and poor_query_percentage.

\n\n

Both quality and poor_query_percentage should be rounded to 2 decimal places.

\n\n

The query result format is in the following example:

\n\n
\nQueries table:\n+------------+-------------------+----------+--------+\n| query_name | result            | position | rating |\n+------------+-------------------+----------+--------+\n| Dog        | Golden Retriever  | 1        | 5      |\n| Dog        | German Shepherd   | 2        | 5      |\n| Dog        | Mule              | 200      | 1      |\n| Cat        | Shirazi           | 5        | 2      |\n| Cat        | Siamese           | 3        | 3      |\n| Cat        | Sphynx            | 7        | 4      |\n+------------+-------------------+----------+--------+\n\nResult table:\n+------------+---------+-----------------------+\n| query_name | quality | poor_query_percentage |\n+------------+---------+-----------------------+\n| Dog        | 2.50    | 33.33                 |\n| Cat        | 0.66    | 33.33                 |\n+------------+---------+-----------------------+\n\nDog queries quality is ((5 / 1) + (5 / 2) + (1 / 200)) / 3 = 2.50\nDog queries poor_ query_percentage is (1 / 3) * 100 = 33.33\n\nCat queries quality equals ((2 / 5) + (3 / 3) + (4 / 7)) / 3 = 0.66\nCat queries poor_ query_percentage is (1 / 3) * 100 = 33.33\n
\n", "content_cn": "

\u67e5\u8be2\u8868 Queries\uff1a 

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| query_name  | varchar |\n| result      | varchar |\n| position    | int     |\n| rating      | int     |\n+-------------+---------+\n\u6b64\u8868\u6ca1\u6709\u4e3b\u952e\uff0c\u5e76\u53ef\u80fd\u6709\u91cd\u590d\u7684\u884c\u3002\n\u6b64\u8868\u5305\u542b\u4e86\u4e00\u4e9b\u4ece\u6570\u636e\u5e93\u4e2d\u6536\u96c6\u7684\u67e5\u8be2\u4fe1\u606f\u3002\n“\u4f4d\u7f6e”\uff08position\uff09\u5217\u7684\u503c\u4e3a 1 \u5230 500 \u3002\n“\u8bc4\u5206”\uff08rating\uff09\u5217\u7684\u503c\u4e3a 1 \u5230 5 \u3002\u8bc4\u5206\u5c0f\u4e8e 3 \u7684\u67e5\u8be2\u88ab\u5b9a\u4e49\u4e3a\u8d28\u91cf\u5f88\u5dee\u7684\u67e5\u8be2\u3002\n
\n\n

 

\n\n

\u5c06\u67e5\u8be2\u7ed3\u679c\u7684\u8d28\u91cf quality \u5b9a\u4e49\u4e3a\uff1a

\n\n
\n

\u5404\u67e5\u8be2\u7ed3\u679c\u7684\u8bc4\u5206\u4e0e\u5176\u4f4d\u7f6e\u4e4b\u95f4\u6bd4\u7387\u7684\u5e73\u5747\u503c\u3002

\n
\n\n

\u5c06\u52a3\u8d28\u67e5\u8be2\u767e\u5206\u6bd4 poor_query_percentage \u4e3a\uff1a

\n\n
\n

\u8bc4\u5206\u5c0f\u4e8e 3 \u7684\u67e5\u8be2\u7ed3\u679c\u5360\u5168\u90e8\u67e5\u8be2\u7ed3\u679c\u7684\u767e\u5206\u6bd4\u3002

\n
\n\n

\u7f16\u5199\u4e00\u7ec4 SQL \u6765\u67e5\u627e\u6bcf\u6b21\u67e5\u8be2\u7684\u540d\u79f0(query_name)\u3001\u8d28\u91cf(quality) \u548c \u52a3\u8d28\u67e5\u8be2\u767e\u5206\u6bd4(poor_query_percentage)\u3002

\n\n

\u8d28\u91cf(quality) \u548c\u52a3\u8d28\u67e5\u8be2\u767e\u5206\u6bd4(poor_query_percentage) \u90fd\u5e94\u56db\u820d\u4e94\u5165\u5230\u5c0f\u6570\u70b9\u540e\u4e24\u4f4d\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u6240\u793a\uff1a

\n\n
\nQueries table:\n+------------+-------------------+----------+--------+\n| query_name | result            | position | rating |\n+------------+-------------------+----------+--------+\n| Dog        | Golden Retriever  | 1        | 5      |\n| Dog        | German Shepherd   | 2        | 5      |\n| Dog        | Mule              | 200      | 1      |\n| Cat        | Shirazi           | 5        | 2      |\n| Cat        | Siamese           | 3        | 3      |\n| Cat        | Sphynx            | 7        | 4      |\n+------------+-------------------+----------+--------+\n\nResult table:\n+------------+---------+-----------------------+\n| query_name | quality | poor_query_percentage |\n+------------+---------+-----------------------+\n| Dog        | 2.50    | 33.33                 |\n| Cat        | 0.66    | 33.33                 |\n+------------+---------+-----------------------+\n\nDog \u67e5\u8be2\u7ed3\u679c\u7684\u8d28\u91cf\u4e3a ((5 / 1) + (5 / 2) + (1 / 200)) / 3 = 2.50\nDog \u67e5\u8be2\u7ed3\u679c\u7684\u52a3\u8d28\u67e5\u8be2\u767e\u5206\u6bd4\u4e3a (1 / 3) * 100 = 33.33\n\nCat \u67e5\u8be2\u7ed3\u679c\u7684\u8d28\u91cf\u4e3a ((2 / 5) + (3 / 3) + (4 / 7)) / 3 = 0.66\nCat \u67e5\u8be2\u7ed3\u679c\u7684\u52a3\u8d28\u67e5\u8be2\u767e\u5206\u6bd4\u4e3a (1 / 3) * 100 = 33.33\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1211](https://leetcode-cn.com/problems/queries-quality-and-percentage)", "[\u67e5\u8be2\u7ed3\u679c\u7684\u8d28\u91cf\u548c\u5360\u6bd4](/solution/1200-1299/1211.Queries%20Quality%20and%20Percentage/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1211](https://leetcode.com/problems/queries-quality-and-percentage)", "[Queries Quality and Percentage](/solution/1200-1299/1211.Queries%20Quality%20and%20Percentage/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1337", "frontend_question_id": "1206", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/design-skiplist", "url_en": "https://leetcode.com/problems/design-skiplist", "relative_path_cn": "/solution/1200-1299/1206.Design%20Skiplist/README.md", "relative_path_en": "/solution/1200-1299/1206.Design%20Skiplist/README_EN.md", "title_cn": "\u8bbe\u8ba1\u8df3\u8868", "title_en": "Design Skiplist", "question_title_slug": "design-skiplist", "content_en": "

Design a Skiplist without using any built-in libraries.

\r\n\r\n

A Skiplist is a data structure that takes O(log(n)) time to add, erase and search. Comparing with treap and red-black tree which has the same function and performance, the code length of Skiplist can be comparatively short and the idea behind Skiplists are just simple linked lists.

\r\n\r\n

For example: we have a Skiplist containing [30,40,50,60,70,90] and we want to add 80 and 45 into it. The Skiplist works this way:

\r\n\r\n

\"\"
\r\nArtyom Kalinin [CC BY-SA 3.0], via Wikimedia Commons

\r\n\r\n

You can see there are many layers in the Skiplist. Each layer is a sorted linked list. With the help of the top layers, add , erase and search can be faster than O(n). It can be proven that the average time complexity for each operation is O(log(n)) and space complexity is O(n).

\r\n\r\n

To be specific, your design should include these functions:

\r\n\r\n
    \r\n\t
  • bool search(int target) : Return whether the target exists in the Skiplist or not.
  • \r\n\t
  • void add(int num): Insert a value into the SkipList. 
  • \r\n\t
  • bool erase(int num): Remove a value in the Skiplist. If num does not exist in the Skiplist, do nothing and return false. If there exists multiple num values, removing any one of them is fine.
  • \r\n
\r\n\r\n

See more about Skiplist : https://en.wikipedia.org/wiki/Skip_list

\r\n\r\n

Note that duplicates may exist in the Skiplist, your code needs to handle this situation.

\r\n\r\n

 

\r\n\r\n

Example:

\r\n\r\n
\r\nSkiplist skiplist = new Skiplist();\r\n\r\nskiplist.add(1);\r\nskiplist.add(2);\r\nskiplist.add(3);\r\nskiplist.search(0);   // return false.\r\nskiplist.add(4);\r\nskiplist.search(1);   // return true.\r\nskiplist.erase(0);    // return false, 0 is not in skiplist.\r\nskiplist.erase(1);    // return true.\r\nskiplist.search(1);   // return false, 1 has already been erased.
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 0 <= num, target <= 20000
  • \r\n\t
  • At most 50000 calls will be made to search, add, and erase.
  • \r\n
", "content_cn": "

\u4e0d\u4f7f\u7528\u4efb\u4f55\u5e93\u51fd\u6570\uff0c\u8bbe\u8ba1\u4e00\u4e2a\u8df3\u8868\u3002

\n\n

\u8df3\u8868\u662f\u5728 O(log(n)) \u65f6\u95f4\u5185\u5b8c\u6210\u589e\u52a0\u3001\u5220\u9664\u3001\u641c\u7d22\u64cd\u4f5c\u7684\u6570\u636e\u7ed3\u6784\u3002\u8df3\u8868\u76f8\u6bd4\u4e8e\u6811\u5806\u4e0e\u7ea2\u9ed1\u6811\uff0c\u5176\u529f\u80fd\u4e0e\u6027\u80fd\u76f8\u5f53\uff0c\u5e76\u4e14\u8df3\u8868\u7684\u4ee3\u7801\u957f\u5ea6\u76f8\u8f83\u4e0b\u66f4\u77ed\uff0c\u5176\u8bbe\u8ba1\u601d\u60f3\u4e0e\u94fe\u8868\u76f8\u4f3c\u3002

\n\n

\u4f8b\u5982\uff0c\u4e00\u4e2a\u8df3\u8868\u5305\u542b [30, 40, 50, 60, 70, 90]\uff0c\u7136\u540e\u589e\u52a0 80\u300145 \u5230\u8df3\u8868\u4e2d\uff0c\u4ee5\u4e0b\u56fe\u7684\u65b9\u5f0f\u64cd\u4f5c\uff1a

\n\n

\"\"
\nArtyom Kalinin [CC BY-SA 3.0], via Wikimedia Commons

\n\n

\u8df3\u8868\u4e2d\u6709\u5f88\u591a\u5c42\uff0c\u6bcf\u4e00\u5c42\u662f\u4e00\u4e2a\u77ed\u7684\u94fe\u8868\u3002\u5728\u7b2c\u4e00\u5c42\u7684\u4f5c\u7528\u4e0b\uff0c\u589e\u52a0\u3001\u5220\u9664\u548c\u641c\u7d22\u64cd\u4f5c\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e0d\u8d85\u8fc7 O(n)\u3002\u8df3\u8868\u7684\u6bcf\u4e00\u4e2a\u64cd\u4f5c\u7684\u5e73\u5747\u65f6\u95f4\u590d\u6742\u5ea6\u662f O(log(n))\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u662f O(n)\u3002

\n\n

\u5728\u672c\u9898\u4e2d\uff0c\u4f60\u7684\u8bbe\u8ba1\u5e94\u8be5\u8981\u5305\u542b\u8fd9\u4e9b\u51fd\u6570\uff1a

\n\n
    \n\t
  • bool search(int target) : \u8fd4\u56detarget\u662f\u5426\u5b58\u5728\u4e8e\u8df3\u8868\u4e2d\u3002
  • \n\t
  • void add(int num): \u63d2\u5165\u4e00\u4e2a\u5143\u7d20\u5230\u8df3\u8868\u3002
  • \n\t
  • bool erase(int num): \u5728\u8df3\u8868\u4e2d\u5220\u9664\u4e00\u4e2a\u503c\uff0c\u5982\u679c num \u4e0d\u5b58\u5728\uff0c\u76f4\u63a5\u8fd4\u56defalse. \u5982\u679c\u5b58\u5728\u591a\u4e2a num \uff0c\u5220\u9664\u5176\u4e2d\u4efb\u610f\u4e00\u4e2a\u5373\u53ef\u3002
  • \n
\n\n

\u4e86\u89e3\u66f4\u591a : https://en.wikipedia.org/wiki/Skip_list

\n\n

\u6ce8\u610f\uff0c\u8df3\u8868\u4e2d\u53ef\u80fd\u5b58\u5728\u591a\u4e2a\u76f8\u540c\u7684\u503c\uff0c\u4f60\u7684\u4ee3\u7801\u9700\u8981\u5904\u7406\u8fd9\u79cd\u60c5\u51b5\u3002

\n\n

\u6837\u4f8b:

\n\n
Skiplist skiplist = new Skiplist();\n\nskiplist.add(1);\nskiplist.add(2);\nskiplist.add(3);\nskiplist.search(0);   // \u8fd4\u56de false\nskiplist.add(4);\nskiplist.search(1);   // \u8fd4\u56de true\nskiplist.erase(0);    // \u8fd4\u56de false\uff0c0 \u4e0d\u5728\u8df3\u8868\u4e2d\nskiplist.erase(1);    // \u8fd4\u56de true\nskiplist.search(1);   // \u8fd4\u56de false\uff0c1 \u5df2\u88ab\u64e6\u9664\n
\n\n

\u7ea6\u675f\u6761\u4ef6:

\n\n
    \n\t
  • 0 <= num, target <= 20000
  • \n\t
  • \u6700\u591a\u8c03\u7528 50000 \u6b21 search, add, \u4ee5\u53ca erase\u64cd\u4f5c\u3002
  • \n
\n", "tags_en": ["Design"], "tags_cn": ["\u8bbe\u8ba1"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Skiplist {\npublic:\n Skiplist() {\n\n }\n \n bool search(int target) {\n\n }\n \n void add(int num) {\n\n }\n \n bool erase(int num) {\n\n }\n};\n\n/**\n * Your Skiplist object will be instantiated and called as such:\n * Skiplist* obj = new Skiplist();\n * bool param_1 = obj->search(target);\n * obj->add(num);\n * bool param_3 = obj->erase(num);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Skiplist {\n\n public Skiplist() {\n\n }\n \n public boolean search(int target) {\n\n }\n \n public void add(int num) {\n\n }\n \n public boolean erase(int num) {\n\n }\n}\n\n/**\n * Your Skiplist object will be instantiated and called as such:\n * Skiplist obj = new Skiplist();\n * boolean param_1 = obj.search(target);\n * obj.add(num);\n * boolean param_3 = obj.erase(num);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Skiplist(object):\n\n def __init__(self):\n \n\n def search(self, target):\n \"\"\"\n :type target: int\n :rtype: bool\n \"\"\"\n \n\n def add(self, num):\n \"\"\"\n :type num: int\n :rtype: None\n \"\"\"\n \n\n def erase(self, num):\n \"\"\"\n :type num: int\n :rtype: bool\n \"\"\"\n \n\n\n# Your Skiplist object will be instantiated and called as such:\n# obj = Skiplist()\n# param_1 = obj.search(target)\n# obj.add(num)\n# param_3 = obj.erase(num)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Skiplist:\n\n def __init__(self):\n \n\n def search(self, target: int) -> bool:\n \n\n def add(self, num: int) -> None:\n \n\n def erase(self, num: int) -> bool:\n \n\n\n# Your Skiplist object will be instantiated and called as such:\n# obj = Skiplist()\n# param_1 = obj.search(target)\n# obj.add(num)\n# param_3 = obj.erase(num)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} Skiplist;\n\n\nSkiplist* skiplistCreate() {\n \n}\n\nbool skiplistSearch(Skiplist* obj, int target) {\n \n}\n\nvoid skiplistAdd(Skiplist* obj, int num) {\n \n}\n\nbool skiplistErase(Skiplist* obj, int num) {\n \n}\n\nvoid skiplistFree(Skiplist* obj) {\n \n}\n\n/**\n * Your Skiplist struct will be instantiated and called as such:\n * Skiplist* obj = skiplistCreate();\n * bool param_1 = skiplistSearch(obj, target);\n \n * skiplistAdd(obj, num);\n \n * bool param_3 = skiplistErase(obj, num);\n \n * skiplistFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Skiplist {\n\n public Skiplist() {\n\n }\n \n public bool Search(int target) {\n\n }\n \n public void Add(int num) {\n\n }\n \n public bool Erase(int num) {\n\n }\n}\n\n/**\n * Your Skiplist object will be instantiated and called as such:\n * Skiplist obj = new Skiplist();\n * bool param_1 = obj.Search(target);\n * obj.Add(num);\n * bool param_3 = obj.Erase(num);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "\nvar Skiplist = function() {\n\n};\n\n/** \n * @param {number} target\n * @return {boolean}\n */\nSkiplist.prototype.search = function(target) {\n\n};\n\n/** \n * @param {number} num\n * @return {void}\n */\nSkiplist.prototype.add = function(num) {\n\n};\n\n/** \n * @param {number} num\n * @return {boolean}\n */\nSkiplist.prototype.erase = function(num) {\n\n};\n\n/**\n * Your Skiplist object will be instantiated and called as such:\n * var obj = new Skiplist()\n * var param_1 = obj.search(target)\n * obj.add(num)\n * var param_3 = obj.erase(num)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class Skiplist\n def initialize()\n\n end\n\n\n=begin\n :type target: Integer\n :rtype: Boolean\n=end\n def search(target)\n\n end\n\n\n=begin\n :type num: Integer\n :rtype: Void\n=end\n def add(num)\n\n end\n\n\n=begin\n :type num: Integer\n :rtype: Boolean\n=end\n def erase(num)\n\n end\n\n\nend\n\n# Your Skiplist object will be instantiated and called as such:\n# obj = Skiplist.new()\n# param_1 = obj.search(target)\n# obj.add(num)\n# param_3 = obj.erase(num)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass Skiplist {\n\n init() {\n\n }\n \n func search(_ target: Int) -> Bool {\n\n }\n \n func add(_ num: Int) {\n\n }\n \n func erase(_ num: Int) -> Bool {\n\n }\n}\n\n/**\n * Your Skiplist object will be instantiated and called as such:\n * let obj = Skiplist()\n * let ret_1: Bool = obj.search(target)\n * obj.add(num)\n * let ret_3: Bool = obj.erase(num)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type Skiplist struct {\n\n}\n\n\nfunc Constructor() Skiplist {\n\n}\n\n\nfunc (this *Skiplist) Search(target int) bool {\n\n}\n\n\nfunc (this *Skiplist) Add(num int) {\n\n}\n\n\nfunc (this *Skiplist) Erase(num int) bool {\n\n}\n\n\n/**\n * Your Skiplist object will be instantiated and called as such:\n * obj := Constructor();\n * param_1 := obj.Search(target);\n * obj.Add(num);\n * param_3 := obj.Erase(num);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class Skiplist() {\n\n def search(target: Int): Boolean = {\n\n }\n\n def add(num: Int) {\n\n }\n\n def erase(num: Int): Boolean = {\n\n }\n\n}\n\n/**\n * Your Skiplist object will be instantiated and called as such:\n * var obj = new Skiplist()\n * var param_1 = obj.search(target)\n * obj.add(num)\n * var param_3 = obj.erase(num)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Skiplist() {\n\n fun search(target: Int): Boolean {\n\n }\n\n fun add(num: Int) {\n\n }\n\n fun erase(num: Int): Boolean {\n\n }\n\n}\n\n/**\n * Your Skiplist object will be instantiated and called as such:\n * var obj = Skiplist()\n * var param_1 = obj.search(target)\n * obj.add(num)\n * var param_3 = obj.erase(num)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct Skiplist {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl Skiplist {\n\n fn new() -> Self {\n\n }\n \n fn search(&self, target: i32) -> bool {\n\n }\n \n fn add(&self, num: i32) {\n\n }\n \n fn erase(&self, num: i32) -> bool {\n\n }\n}\n\n/**\n * Your Skiplist object will be instantiated and called as such:\n * let obj = Skiplist::new();\n * let ret_1: bool = obj.search(target);\n * obj.add(num);\n * let ret_3: bool = obj.erase(num);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Skiplist {\n /**\n */\n function __construct() {\n\n }\n\n /**\n * @param Integer $target\n * @return Boolean\n */\n function search($target) {\n\n }\n\n /**\n * @param Integer $num\n * @return NULL\n */\n function add($num) {\n\n }\n\n /**\n * @param Integer $num\n * @return Boolean\n */\n function erase($num) {\n\n }\n}\n\n/**\n * Your Skiplist object will be instantiated and called as such:\n * $obj = Skiplist();\n * $ret_1 = $obj->search($target);\n * $obj->add($num);\n * $ret_3 = $obj->erase($num);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class Skiplist {\n constructor() {\n\n }\n\n search(target: number): boolean {\n\n }\n\n add(num: number): void {\n\n }\n\n erase(num: number): boolean {\n\n }\n}\n\n/**\n * Your Skiplist object will be instantiated and called as such:\n * var obj = new Skiplist()\n * var param_1 = obj.search(target)\n * obj.add(num)\n * var param_3 = obj.erase(num)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define skiplist%\n (class object%\n (super-new)\n (init-field)\n \n ; search : exact-integer? -> boolean?\n (define/public (search target)\n\n )\n ; add : exact-integer? -> void?\n (define/public (add num)\n\n )\n ; erase : exact-integer? -> boolean?\n (define/public (erase num)\n\n )))\n\n;; Your skiplist% object will be instantiated and called as such:\n;; (define obj (new skiplist%))\n;; (define param_1 (send obj search target))\n;; (send obj add num)\n;; (define param_3 (send obj erase num))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1206](https://leetcode-cn.com/problems/design-skiplist)", "[\u8bbe\u8ba1\u8df3\u8868](/solution/1200-1299/1206.Design%20Skiplist/README.md)", "`\u8bbe\u8ba1`", "\u56f0\u96be", ""], "md_table_row_en": ["[1206](https://leetcode.com/problems/design-skiplist)", "[Design Skiplist](/solution/1200-1299/1206.Design%20Skiplist/README_EN.md)", "`Design`", "Hard", ""]}, {"question_id": "1332", "frontend_question_id": "1220", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-vowels-permutation", "url_en": "https://leetcode.com/problems/count-vowels-permutation", "relative_path_cn": "/solution/1200-1299/1220.Count%20Vowels%20Permutation/README.md", "relative_path_en": "/solution/1200-1299/1220.Count%20Vowels%20Permutation/README_EN.md", "title_cn": "\u7edf\u8ba1\u5143\u97f3\u5b57\u6bcd\u5e8f\u5217\u7684\u6570\u76ee", "title_en": "Count Vowels Permutation", "question_title_slug": "count-vowels-permutation", "content_en": "

Given an integer n, your task is to count how many strings of length n can be formed under the following rules:

\n\n
    \n\t
  • Each character is a lower case vowel ('a', 'e', 'i', 'o', 'u')
  • \n\t
  • Each vowel 'a' may only be followed by an 'e'.
  • \n\t
  • Each vowel 'e' may only be followed by an 'a' or an 'i'.
  • \n\t
  • Each vowel 'i' may not be followed by another 'i'.
  • \n\t
  • Each vowel 'o' may only be followed by an 'i' or a 'u'.
  • \n\t
  • Each vowel 'u' may only be followed by an 'a'.
  • \n
\n\n

Since the answer may be too large, return it modulo 10^9 + 7.

\n\n

 

\n

Example 1:

\n\n
\nInput: n = 1\nOutput: 5\nExplanation: All possible strings are: "a", "e", "i" , "o" and "u".\n
\n\n

Example 2:

\n\n
\nInput: n = 2\nOutput: 10\nExplanation: All possible strings are: "ae", "ea", "ei", "ia", "ie", "io", "iu", "oi", "ou" and "ua".\n
\n\n

Example 3: 

\n\n
\nInput: n = 5\nOutput: 68
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 2 * 10^4
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n\uff0c\u8bf7\u4f60\u5e2e\u5fd9\u7edf\u8ba1\u4e00\u4e0b\u6211\u4eec\u53ef\u4ee5\u6309\u4e0b\u8ff0\u89c4\u5219\u5f62\u6210\u591a\u5c11\u4e2a\u957f\u5ea6\u4e3a n \u7684\u5b57\u7b26\u4e32\uff1a

\n\n
    \n\t
  • \u5b57\u7b26\u4e32\u4e2d\u7684\u6bcf\u4e2a\u5b57\u7b26\u90fd\u5e94\u5f53\u662f\u5c0f\u5199\u5143\u97f3\u5b57\u6bcd\uff08'a', 'e', 'i', 'o', 'u'\uff09
  • \n\t
  • \u6bcf\u4e2a\u5143\u97f3 'a' \u540e\u9762\u90fd\u53ea\u80fd\u8ddf\u7740 'e'
  • \n\t
  • \u6bcf\u4e2a\u5143\u97f3 'e' \u540e\u9762\u53ea\u80fd\u8ddf\u7740 'a' \u6216\u8005\u662f 'i'
  • \n\t
  • \u6bcf\u4e2a\u5143\u97f3 'i' \u540e\u9762 \u4e0d\u80fd \u518d\u8ddf\u7740\u53e6\u4e00\u4e2a 'i'
  • \n\t
  • \u6bcf\u4e2a\u5143\u97f3 'o' \u540e\u9762\u53ea\u80fd\u8ddf\u7740 'i' \u6216\u8005\u662f 'u'
  • \n\t
  • \u6bcf\u4e2a\u5143\u97f3 'u' \u540e\u9762\u53ea\u80fd\u8ddf\u7740 'a'
  • \n
\n\n

\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u4f1a\u5f88\u5927\uff0c\u6240\u4ee5\u8bf7\u4f60\u8fd4\u56de \u6a21 10^9 + 7 \u4e4b\u540e\u7684\u7ed3\u679c\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u6240\u6709\u53ef\u80fd\u7684\u5b57\u7b26\u4e32\u5206\u522b\u662f\uff1a"a", "e", "i" , "o" \u548c "u"\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1an = 2\n\u8f93\u51fa\uff1a10\n\u89e3\u91ca\uff1a\u6240\u6709\u53ef\u80fd\u7684\u5b57\u7b26\u4e32\u5206\u522b\u662f\uff1a"ae", "ea", "ei", "ia", "ie", "io", "iu", "oi", "ou" \u548c "ua"\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1an = 5\n\u8f93\u51fa\uff1a68
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 2 * 10^4
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countVowelPermutation(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countVowelPermutation(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countVowelPermutation(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countVowelPermutation(self, n: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countVowelPermutation(int n){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountVowelPermutation(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar countVowelPermutation = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef count_vowel_permutation(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countVowelPermutation(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countVowelPermutation(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countVowelPermutation(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countVowelPermutation(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_vowel_permutation(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function countVowelPermutation($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countVowelPermutation(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-vowel-permutation n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1220](https://leetcode-cn.com/problems/count-vowels-permutation)", "[\u7edf\u8ba1\u5143\u97f3\u5b57\u6bcd\u5e8f\u5217\u7684\u6570\u76ee](/solution/1200-1299/1220.Count%20Vowels%20Permutation/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1220](https://leetcode.com/problems/count-vowels-permutation)", "[Count Vowels Permutation](/solution/1200-1299/1220.Count%20Vowels%20Permutation/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1331", "frontend_question_id": "1219", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/path-with-maximum-gold", "url_en": "https://leetcode.com/problems/path-with-maximum-gold", "relative_path_cn": "/solution/1200-1299/1219.Path%20with%20Maximum%20Gold/README.md", "relative_path_en": "/solution/1200-1299/1219.Path%20with%20Maximum%20Gold/README_EN.md", "title_cn": "\u9ec4\u91d1\u77ff\u5de5", "title_en": "Path with Maximum Gold", "question_title_slug": "path-with-maximum-gold", "content_en": "

In a gold mine grid of size m x n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.

\n\n

Return the maximum amount of gold you can collect under the conditions:

\n\n
    \n\t
  • Every time you are located in a cell you will collect all the gold in that cell.
  • \n\t
  • From your position, you can walk one step to the left, right, up, or down.
  • \n\t
  • You can't visit the same cell more than once.
  • \n\t
  • Never visit a cell with 0 gold.
  • \n\t
  • You can start and stop collecting gold from any position in the grid that has some gold.
  • \n
\n\n

 

\n

Example 1:

\n\n
\nInput: grid = [[0,6,0],[5,8,7],[0,9,0]]\nOutput: 24\nExplanation:\n[[0,6,0],\n [5,8,7],\n [0,9,0]]\nPath to get the maximum gold, 9 -> 8 -> 7.\n
\n\n

Example 2:

\n\n
\nInput: grid = [[1,0,7],[2,0,6],[3,4,5],[0,3,0],[9,0,20]]\nOutput: 28\nExplanation:\n[[1,0,7],\n [2,0,6],\n [3,4,5],\n [0,3,0],\n [9,0,20]]\nPath to get the maximum gold, 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • m == grid.length
  • \n\t
  • n == grid[i].length
  • \n\t
  • 1 <= m, n <= 15
  • \n\t
  • 0 <= grid[i][j] <= 100
  • \n\t
  • There are at most 25 cells containing gold.
  • \n
\n", "content_cn": "

\u4f60\u8981\u5f00\u53d1\u4e00\u5ea7\u91d1\u77ff\uff0c\u5730\u8d28\u52d8\u6d4b\u5b66\u5bb6\u5df2\u7ecf\u63a2\u660e\u4e86\u8fd9\u5ea7\u91d1\u77ff\u4e2d\u7684\u8d44\u6e90\u5206\u5e03\uff0c\u5e76\u7528\u5927\u5c0f\u4e3a m * n \u7684\u7f51\u683c grid \u8fdb\u884c\u4e86\u6807\u6ce8\u3002\u6bcf\u4e2a\u5355\u5143\u683c\u4e2d\u7684\u6574\u6570\u5c31\u8868\u793a\u8fd9\u4e00\u5355\u5143\u683c\u4e2d\u7684\u9ec4\u91d1\u6570\u91cf\uff1b\u5982\u679c\u8be5\u5355\u5143\u683c\u662f\u7a7a\u7684\uff0c\u90a3\u4e48\u5c31\u662f 0\u3002

\n\n

\u4e3a\u4e86\u4f7f\u6536\u76ca\u6700\u5927\u5316\uff0c\u77ff\u5de5\u9700\u8981\u6309\u4ee5\u4e0b\u89c4\u5219\u6765\u5f00\u91c7\u9ec4\u91d1\uff1a

\n\n
    \n\t
  • \u6bcf\u5f53\u77ff\u5de5\u8fdb\u5165\u4e00\u4e2a\u5355\u5143\uff0c\u5c31\u4f1a\u6536\u96c6\u8be5\u5355\u5143\u683c\u4e2d\u7684\u6240\u6709\u9ec4\u91d1\u3002
  • \n\t
  • \u77ff\u5de5\u6bcf\u6b21\u53ef\u4ee5\u4ece\u5f53\u524d\u4f4d\u7f6e\u5411\u4e0a\u4e0b\u5de6\u53f3\u56db\u4e2a\u65b9\u5411\u8d70\u3002
  • \n\t
  • \u6bcf\u4e2a\u5355\u5143\u683c\u53ea\u80fd\u88ab\u5f00\u91c7\uff08\u8fdb\u5165\uff09\u4e00\u6b21\u3002
  • \n\t
  • \u4e0d\u5f97\u5f00\u91c7\uff08\u8fdb\u5165\uff09\u9ec4\u91d1\u6570\u76ee\u4e3a 0 \u7684\u5355\u5143\u683c\u3002
  • \n\t
  • \u77ff\u5de5\u53ef\u4ee5\u4ece\u7f51\u683c\u4e2d \u4efb\u610f\u4e00\u4e2a \u6709\u9ec4\u91d1\u7684\u5355\u5143\u683c\u51fa\u53d1\u6216\u8005\u662f\u505c\u6b62\u3002
  • \n
\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1agrid = [[0,6,0],[5,8,7],[0,9,0]]\n\u8f93\u51fa\uff1a24\n\u89e3\u91ca\uff1a\n[[0,6,0],\n [5,8,7],\n [0,9,0]]\n\u4e00\u79cd\u6536\u96c6\u6700\u591a\u9ec4\u91d1\u7684\u8def\u7ebf\u662f\uff1a9 -> 8 -> 7\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1agrid = [[1,0,7],[2,0,6],[3,4,5],[0,3,0],[9,0,20]]\n\u8f93\u51fa\uff1a28\n\u89e3\u91ca\uff1a\n[[1,0,7],\n [2,0,6],\n [3,4,5],\n [0,3,0],\n [9,0,20]]\n\u4e00\u79cd\u6536\u96c6\u6700\u591a\u9ec4\u91d1\u7684\u8def\u7ebf\u662f\uff1a1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= grid.length, grid[i].length <= 15
  • \n\t
  • 0 <= grid[i][j] <= 100
  • \n\t
  • \u6700\u591a 25 \u4e2a\u5355\u5143\u683c\u4e2d\u6709\u9ec4\u91d1\u3002
  • \n
\n", "tags_en": ["Backtracking"], "tags_cn": ["\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int getMaximumGold(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int getMaximumGold(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getMaximumGold(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getMaximumGold(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint getMaximumGold(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int GetMaximumGold(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar getMaximumGold = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef get_maximum_gold(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getMaximumGold(_ grid: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getMaximumGold(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getMaximumGold(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getMaximumGold(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_maximum_gold(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function getMaximumGold($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getMaximumGold(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-maximum-gold grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1219](https://leetcode-cn.com/problems/path-with-maximum-gold)", "[\u9ec4\u91d1\u77ff\u5de5](/solution/1200-1299/1219.Path%20with%20Maximum%20Gold/README.md)", "`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1219](https://leetcode.com/problems/path-with-maximum-gold)", "[Path with Maximum Gold](/solution/1200-1299/1219.Path%20with%20Maximum%20Gold/README_EN.md)", "`Backtracking`", "Medium", ""]}, {"question_id": "1330", "frontend_question_id": "1218", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-arithmetic-subsequence-of-given-difference", "url_en": "https://leetcode.com/problems/longest-arithmetic-subsequence-of-given-difference", "relative_path_cn": "/solution/1200-1299/1218.Longest%20Arithmetic%20Subsequence%20of%20Given%20Difference/README.md", "relative_path_en": "/solution/1200-1299/1218.Longest%20Arithmetic%20Subsequence%20of%20Given%20Difference/README_EN.md", "title_cn": "\u6700\u957f\u5b9a\u5dee\u5b50\u5e8f\u5217", "title_en": "Longest Arithmetic Subsequence of Given Difference", "question_title_slug": "longest-arithmetic-subsequence-of-given-difference", "content_en": "

Given an integer array arr and an integer difference, return the length of the longest subsequence in arr which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals difference.

\r\n\r\n

A subsequence is a sequence that can be derived from arr by deleting some or no elements without changing the order of the remaining elements.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: arr = [1,2,3,4], difference = 1\r\nOutput: 4\r\nExplanation: The longest arithmetic subsequence is [1,2,3,4].
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: arr = [1,3,5,7], difference = 1\r\nOutput: 1\r\nExplanation: The longest arithmetic subsequence is any single element.\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: arr = [1,5,7,8,5,3,4,2,1], difference = -2\r\nOutput: 4\r\nExplanation: The longest arithmetic subsequence is [7,5,3,1].\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= arr.length <= 105
  • \r\n\t
  • -104 <= arr[i], difference <= 104
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0arr\u00a0\u548c\u4e00\u4e2a\u6574\u6570\u00a0difference\uff0c\u8bf7\u4f60\u627e\u51fa\u5e76\u8fd4\u56de arr\u00a0\u4e2d\u6700\u957f\u7b49\u5dee\u5b50\u5e8f\u5217\u7684\u957f\u5ea6\uff0c\u8be5\u5b50\u5e8f\u5217\u4e2d\u76f8\u90bb\u5143\u7d20\u4e4b\u95f4\u7684\u5dee\u7b49\u4e8e difference \u3002

\n\n

\u5b50\u5e8f\u5217 \u662f\u6307\u5728\u4e0d\u6539\u53d8\u5176\u4f59\u5143\u7d20\u987a\u5e8f\u7684\u60c5\u51b5\u4e0b\uff0c\u901a\u8fc7\u5220\u9664\u4e00\u4e9b\u5143\u7d20\u6216\u4e0d\u5220\u9664\u4efb\u4f55\u5143\u7d20\u800c\u4ece arr \u6d3e\u751f\u51fa\u6765\u7684\u5e8f\u5217\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [1,2,3,4], difference = 1\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u6700\u957f\u7684\u7b49\u5dee\u5b50\u5e8f\u5217\u662f [1,2,3,4]\u3002
\n\n

\u793a\u4f8b\u00a02\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [1,3,5,7], difference = 1\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u6700\u957f\u7684\u7b49\u5dee\u5b50\u5e8f\u5217\u662f\u4efb\u610f\u5355\u4e2a\u5143\u7d20\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [1,5,7,8,5,3,4,2,1], difference = -2\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u6700\u957f\u7684\u7b49\u5dee\u5b50\u5e8f\u5217\u662f [7,5,3,1]\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= arr.length <= 105
  • \n\t
  • -104 <= arr[i], difference <= 104
  • \n
\n", "tags_en": ["Hash Table", "Math", "Dynamic Programming"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u6570\u5b66", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int longestSubsequence(vector& arr, int difference) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int longestSubsequence(int[] arr, int difference) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestSubsequence(self, arr, difference):\n \"\"\"\n :type arr: List[int]\n :type difference: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestSubsequence(self, arr: List[int], difference: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint longestSubsequence(int* arr, int arrSize, int difference){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LongestSubsequence(int[] arr, int difference) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @param {number} difference\n * @return {number}\n */\nvar longestSubsequence = function(arr, difference) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @param {Integer} difference\n# @return {Integer}\ndef longest_subsequence(arr, difference)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestSubsequence(_ arr: [Int], _ difference: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestSubsequence(arr []int, difference int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestSubsequence(arr: Array[Int], difference: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestSubsequence(arr: IntArray, difference: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_subsequence(arr: Vec, difference: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @param Integer $difference\n * @return Integer\n */\n function longestSubsequence($arr, $difference) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestSubsequence(arr: number[], difference: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-subsequence arr difference)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1218](https://leetcode-cn.com/problems/longest-arithmetic-subsequence-of-given-difference)", "[\u6700\u957f\u5b9a\u5dee\u5b50\u5e8f\u5217](/solution/1200-1299/1218.Longest%20Arithmetic%20Subsequence%20of%20Given%20Difference/README.md)", "`\u54c8\u5e0c\u8868`,`\u6570\u5b66`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1218](https://leetcode.com/problems/longest-arithmetic-subsequence-of-given-difference)", "[Longest Arithmetic Subsequence of Given Difference](/solution/1200-1299/1218.Longest%20Arithmetic%20Subsequence%20of%20Given%20Difference/README_EN.md)", "`Hash Table`,`Math`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "1329", "frontend_question_id": "1217", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-cost-to-move-chips-to-the-same-position", "url_en": "https://leetcode.com/problems/minimum-cost-to-move-chips-to-the-same-position", "relative_path_cn": "/solution/1200-1299/1217.Minimum%20Cost%20to%20Move%20Chips%20to%20The%20Same%20Position/README.md", "relative_path_en": "/solution/1200-1299/1217.Minimum%20Cost%20to%20Move%20Chips%20to%20The%20Same%20Position/README_EN.md", "title_cn": "\u73a9\u7b79\u7801", "title_en": "Minimum Cost to Move Chips to The Same Position", "question_title_slug": "minimum-cost-to-move-chips-to-the-same-position", "content_en": "

We have n chips, where the position of the ith chip is position[i].

\n\n

We need to move all the chips to the same position. In one step, we can change the position of the ith chip from position[i] to:

\n\n
    \n\t
  • position[i] + 2 or position[i] - 2 with cost = 0.
  • \n\t
  • position[i] + 1 or position[i] - 1 with cost = 1.
  • \n
\n\n

Return the minimum cost needed to move all the chips to the same position.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: position = [1,2,3]\nOutput: 1\nExplanation: First step: Move the chip at position 3 to position 1 with cost = 0.\nSecond step: Move the chip at position 2 to position 1 with cost = 1.\nTotal cost is 1.\n
\n\n

Example 2:

\n\"\"\n
\nInput: position = [2,2,2,3,3]\nOutput: 2\nExplanation: We can move the two chips at position  3 to position 2. Each move has cost = 1. The total cost = 2.\n
\n\n

Example 3:

\n\n
\nInput: position = [1,1000000000]\nOutput: 1\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= position.length <= 100
  • \n\t
  • 1 <= position[i] <= 10^9
  • \n
\n", "content_cn": "

\u6570\u8f74\u4e0a\u653e\u7f6e\u4e86\u4e00\u4e9b\u7b79\u7801\uff0c\u6bcf\u4e2a\u7b79\u7801\u7684\u4f4d\u7f6e\u5b58\u5728\u6570\u7ec4 chips \u5f53\u4e2d\u3002

\n\n

\u4f60\u53ef\u4ee5\u5bf9 \u4efb\u4f55\u7b79\u7801 \u6267\u884c\u4e0b\u9762\u4e24\u79cd\u64cd\u4f5c\u4e4b\u4e00\uff08\u4e0d\u9650\u64cd\u4f5c\u6b21\u6570\uff0c0 \u6b21\u4e5f\u53ef\u4ee5\uff09\uff1a

\n\n
    \n\t
  • \u5c06\u7b2c i \u4e2a\u7b79\u7801\u5411\u5de6\u6216\u8005\u53f3\u79fb\u52a8 2 \u4e2a\u5355\u4f4d\uff0c\u4ee3\u4ef7\u4e3a 0\u3002
  • \n\t
  • \u5c06\u7b2c i \u4e2a\u7b79\u7801\u5411\u5de6\u6216\u8005\u53f3\u79fb\u52a8 1 \u4e2a\u5355\u4f4d\uff0c\u4ee3\u4ef7\u4e3a 1\u3002
  • \n
\n\n

\u6700\u5f00\u59cb\u7684\u65f6\u5019\uff0c\u540c\u4e00\u4f4d\u7f6e\u4e0a\u4e5f\u53ef\u80fd\u653e\u7740\u4e24\u4e2a\u6216\u8005\u66f4\u591a\u7684\u7b79\u7801\u3002

\n\n

\u8fd4\u56de\u5c06\u6240\u6709\u7b79\u7801\u79fb\u52a8\u5230\u540c\u4e00\u4f4d\u7f6e\uff08\u4efb\u610f\u4f4d\u7f6e\uff09\u4e0a\u6240\u9700\u8981\u7684\u6700\u5c0f\u4ee3\u4ef7\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1achips = [1,2,3]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u7b2c\u4e8c\u4e2a\u7b79\u7801\u79fb\u52a8\u5230\u4f4d\u7f6e\u4e09\u7684\u4ee3\u4ef7\u662f 1\uff0c\u7b2c\u4e00\u4e2a\u7b79\u7801\u79fb\u52a8\u5230\u4f4d\u7f6e\u4e09\u7684\u4ee3\u4ef7\u662f 0\uff0c\u603b\u4ee3\u4ef7\u4e3a 1\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1achips = [2,2,2,3,3]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u7b2c\u56db\u548c\u7b2c\u4e94\u4e2a\u7b79\u7801\u79fb\u52a8\u5230\u4f4d\u7f6e\u4e8c\u7684\u4ee3\u4ef7\u90fd\u662f 1\uff0c\u6240\u4ee5\u6700\u5c0f\u603b\u4ee3\u4ef7\u4e3a 2\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= chips.length <= 100
  • \n\t
  • 1 <= chips[i] <= 10^9
  • \n
\n", "tags_en": ["Greedy", "Array", "Math"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u7ec4", "\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minCostToMoveChips(vector& position) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minCostToMoveChips(int[] position) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minCostToMoveChips(self, position):\n \"\"\"\n :type position: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minCostToMoveChips(self, position: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minCostToMoveChips(int* position, int positionSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinCostToMoveChips(int[] position) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} position\n * @return {number}\n */\nvar minCostToMoveChips = function(position) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} position\n# @return {Integer}\ndef min_cost_to_move_chips(position)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minCostToMoveChips(_ position: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minCostToMoveChips(position []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minCostToMoveChips(position: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minCostToMoveChips(position: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_cost_to_move_chips(position: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $position\n * @return Integer\n */\n function minCostToMoveChips($position) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minCostToMoveChips(position: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-cost-to-move-chips position)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1217](https://leetcode-cn.com/problems/minimum-cost-to-move-chips-to-the-same-position)", "[\u73a9\u7b79\u7801](/solution/1200-1299/1217.Minimum%20Cost%20to%20Move%20Chips%20to%20The%20Same%20Position/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u7ec4`,`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[1217](https://leetcode.com/problems/minimum-cost-to-move-chips-to-the-same-position)", "[Minimum Cost to Move Chips to The Same Position](/solution/1200-1299/1217.Minimum%20Cost%20to%20Move%20Chips%20to%20The%20Same%20Position/README_EN.md)", "`Greedy`,`Array`,`Math`", "Easy", ""]}, {"question_id": "1328", "frontend_question_id": "1205", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/monthly-transactions-ii", "url_en": "https://leetcode.com/problems/monthly-transactions-ii", "relative_path_cn": "/solution/1200-1299/1205.Monthly%20Transactions%20II/README.md", "relative_path_en": "/solution/1200-1299/1205.Monthly%20Transactions%20II/README_EN.md", "title_cn": "\u6bcf\u6708\u4ea4\u6613II", "title_en": "Monthly Transactions II", "question_title_slug": "monthly-transactions-ii", "content_en": "

Table: Transactions

\n\n
\n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| id             | int     |\n| country        | varchar |\n| state          | enum    |\n| amount         | int     |\n| trans_date     | date    |\n+----------------+---------+\nid is the primary key of this table.\nThe table has information about incoming transactions.\nThe state column is an enum of type ["approved", "declined"].\n
\n\n

Table: Chargebacks

\n\n
\n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| trans_id       | int     |\n| trans_date     | date    |\n+----------------+---------+\nChargebacks contains basic information regarding incoming chargebacks from some transactions placed in Transactions table.\ntrans_id is a foreign key to the id column of Transactions table.\nEach chargeback corresponds to a transaction made previously even if they were not approved.
\n\n

 

\n\n

Write an SQL query to find for each month and country: the number of approved transactions and their total amount, the number of chargebacks, and their total amount.

\n\n

Note: In your query, given the month and country, ignore rows with all zeros.

\n\n

The query result format is in the following example:

\n\n

 

\n\n
\nTransactions table:\n+-----+---------+----------+--------+------------+\n| id  | country | state    | amount | trans_date |\n+-----+---------+----------+--------+------------+\n| 101 | US      | approved | 1000   | 2019-05-18 |\n| 102 | US      | declined | 2000   | 2019-05-19 |\n| 103 | US      | approved | 3000   | 2019-06-10 |\n| 104 | US      | declined | 4000   | 2019-06-13 |\n| 105 | US      | approved | 5000   | 2019-06-15 |\n+-----+---------+----------+--------+------------+\n\nChargebacks table:\n+----------+------------+\n| trans_id | trans_date |\n+----------+------------+\n| 102      | 2019-05-29 |\n| 101      | 2019-06-30 |\n| 105      | 2019-09-18 |\n+----------+------------+\n\nResult table:\n+---------+---------+----------------+-----------------+------------------+-------------------+\n| month   | country | approved_count | approved_amount | chargeback_count | chargeback_amount |\n+---------+---------+----------------+-----------------+------------------+-------------------+\n| 2019-05 | US      | 1              | 1000            | 1                | 2000              |\n| 2019-06 | US      | 2              | 8000            | 1                | 1000              |\n| 2019-09 | US      | 0              | 0               | 1                | 5000              |\n+---------+---------+----------------+-----------------+------------------+-------------------+\n\n
\n", "content_cn": "

Transactions \u8bb0\u5f55\u8868

\n\n
+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| id             | int     |\n| country        | varchar |\n| state          | enum    |\n| amount         | int     |\n| trans_date     | date    |\n+----------------+---------+\nid \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\u3002\n\u8be5\u8868\u5305\u542b\u6709\u5173\u4f20\u5165\u4e8b\u52a1\u7684\u4fe1\u606f\u3002\n\u72b6\u6001\u5217\u662f\u7c7b\u578b\u4e3a [approved\uff08\u5df2\u6279\u51c6\uff09\u3001declined\uff08\u5df2\u62d2\u7edd\uff09] \u7684\u679a\u4e3e\u3002
\n\n

 

\n\n

Chargebacks \u8868

\n\n
+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| trans_id       | int     |\n| charge_date    | date    |\n+----------------+---------+\n\u9000\u5355\u5305\u542b\u6709\u5173\u653e\u7f6e\u5728\u4e8b\u52a1\u8868\u4e2d\u7684\u67d0\u4e9b\u4e8b\u52a1\u7684\u4f20\u5165\u9000\u5355\u7684\u57fa\u672c\u4fe1\u606f\u3002\ntrans_id \u662f transactions \u8868\u7684 id \u5217\u7684\u5916\u952e\u3002\n\u6bcf\u9879\u9000\u5355\u90fd\u5bf9\u5e94\u4e8e\u4e4b\u524d\u8fdb\u884c\u7684\u4ea4\u6613\uff0c\u5373\u4f7f\u672a\u7ecf\u6279\u51c6\u3002
\n\n

 

\n\n

\u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\uff0c\u4ee5\u67e5\u627e\u6bcf\u4e2a\u6708\u548c\u6bcf\u4e2a\u56fd\u5bb6/\u5730\u533a\u7684\u5df2\u6279\u51c6\u4ea4\u6613\u7684\u6570\u91cf\u53ca\u5176\u603b\u91d1\u989d\u3001\u9000\u5355\u7684\u6570\u91cf\u53ca\u5176\u603b\u91d1\u989d\u3002

\n\n

\u6ce8\u610f\uff1a\u5728\u60a8\u7684\u67e5\u8be2\u4e2d\uff0c\u7ed9\u5b9a\u6708\u4efd\u548c\u56fd\u5bb6\uff0c\u5ffd\u7565\u6240\u6709\u4e3a\u96f6\u7684\u884c\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u6240\u793a\uff1a

\n\n
Transactions \u8868\uff1a\n+------+---------+----------+--------+------------+\n| id   | country | state    | amount | trans_date |\n+------+---------+----------+--------+------------+\n| 101  | US      | approved | 1000   | 2019-05-18 |\n| 102  | US      | declined | 2000   | 2019-05-19 |\n| 103  | US      | approved | 3000   | 2019-06-10 |\n| 104  | US      | declined | 4000   | 2019-06-13 |\n| 105  | US      | approved | 5000   | 2019-06-15 |\n+------+---------+----------+--------+------------+\n\nChargebacks \u8868\uff1a\n+------------+------------+\n| trans_id   | trans_date |\n+------------+------------+\n| 102        | 2019-05-29 |\n| 101        | 2019-06-30 |\n| 105        | 2019-09-18 |\n+------------+------------+\n\nResult \u8868\uff1a\n+----------+---------+----------------+-----------------+-------------------+--------------------+\n| month    | country | approved_count | approved_amount | chargeback_count  | chargeback_amount  |\n+----------+---------+----------------+-----------------+-------------------+--------------------+\n| 2019-05  | US      | 1              | 1000            | 1                 | 2000               |\n| 2019-06  | US      | 2              | 8000            | 1                 | 1000               |\n| 2019-09  | US      | 0              | 0               | 1                 | 5000               |\n+----------+---------+----------------+-----------------+-------------------+--------------------+\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1205](https://leetcode-cn.com/problems/monthly-transactions-ii)", "[\u6bcf\u6708\u4ea4\u6613II](/solution/1200-1299/1205.Monthly%20Transactions%20II/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1205](https://leetcode.com/problems/monthly-transactions-ii)", "[Monthly Transactions II](/solution/1200-1299/1205.Monthly%20Transactions%20II/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1327", "frontend_question_id": "1204", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/last-person-to-fit-in-the-elevator", "url_en": "https://leetcode.com/problems/last-person-to-fit-in-the-elevator", "relative_path_cn": "/solution/1200-1299/1204.Last%20Person%20to%20Fit%20in%20the%20Elevator/README.md", "relative_path_en": "/solution/1200-1299/1204.Last%20Person%20to%20Fit%20in%20the%20Elevator/README_EN.md", "title_cn": "\u6700\u540e\u4e00\u4e2a\u80fd\u8fdb\u5165\u7535\u68af\u7684\u4eba", "title_en": "Last Person to Fit in the Elevator", "question_title_slug": "last-person-to-fit-in-the-elevator", "content_en": "

Table: Queue

\r\n\r\n
\r\n+-------------+---------+\r\n| Column Name | Type    |\r\n+-------------+---------+\r\n| person_id   | int     |\r\n| person_name | varchar |\r\n| weight      | int     |\r\n| turn        | int     |\r\n+-------------+---------+\r\nperson_id is the primary key column for this table.\r\nThis table has the information about all people waiting for an elevator.\r\nThe person_id and turn columns will contain all numbers from 1 to n, where n is the number of rows in the table.\r\n
\r\n\r\n

 

\r\n\r\n

The maximum weight the elevator can hold is 1000.

\r\n\r\n

Write an SQL query to find the person_name of the last person who will fit in the elevator without exceeding the weight limit. It is guaranteed that the person who is first in the queue can fit in the elevator.

\r\n\r\n

The query result format is in the following example:

\r\n\r\n
\r\nQueue table\r\n+-----------+-------------------+--------+------+\r\n| person_id | person_name       | weight | turn |\r\n+-----------+-------------------+--------+------+\r\n| 5         | George Washington | 250    | 1    |\r\n| 3         | John Adams        | 350    | 2    |\r\n| 6         | Thomas Jefferson  | 400    | 3    |\r\n| 2         | Will Johnliams    | 200    | 4    |\r\n| 4         | Thomas Jefferson  | 175    | 5    |\r\n| 1         | James Elephant    | 500    | 6    |\r\n+-----------+-------------------+--------+------+\r\n\r\nResult table\r\n+-------------------+\r\n| person_name       |\r\n+-------------------+\r\n| Thomas Jefferson  |\r\n+-------------------+\r\n\r\nQueue table is ordered by turn in the example for simplicity.\r\nIn the example George Washington(id 5), John Adams(id 3) and Thomas Jefferson(id 6) will enter the elevator as their weight sum is 250 + 350 + 400 = 1000.\r\nThomas Jefferson(id 6) is the last person to fit in the elevator because he has the last turn in these three people.\r\n
\r\n", "content_cn": "

\u8868: Queue

\n\n
+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| person_id   | int     |\n| person_name | varchar |\n| weight      | int     |\n| turn        | int     |\n+-------------+---------+\nperson_id \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\u3002\n\u8be5\u8868\u5c55\u793a\u4e86\u6240\u6709\u7b49\u5f85\u7535\u68af\u7684\u4eba\u7684\u4fe1\u606f\u3002\n\u8868\u4e2d person_id \u548c turn \u5217\u5c06\u5305\u542b\u4ece 1 \u5230 n \u7684\u6240\u6709\u6570\u5b57\uff0c\u5176\u4e2d n \u662f\u8868\u4e2d\u7684\u884c\u6570\u3002\n
\n\n

 

\n\n

\u7535\u68af\u6700\u5927\u8f7d\u91cd\u91cf\u4e3a 1000\u3002

\n\n

\u5199\u4e00\u6761 SQL \u67e5\u8be2\u8bed\u53e5\u67e5\u627e\u6700\u540e\u4e00\u4e2a\u80fd\u8fdb\u5165\u7535\u68af\u4e14\u4e0d\u8d85\u8fc7\u91cd\u91cf\u9650\u5236\u7684 person_name \u3002\u9898\u76ee\u786e\u4fdd\u961f\u5217\u4e2d\u7b2c\u4e00\u4f4d\u7684\u4eba\u53ef\u4ee5\u8fdb\u5165\u7535\u68af \u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u5982\u4e0b\u6240\u793a :

\n\n
Queue \u8868\n+-----------+-------------------+--------+------+\n| person_id | person_name       | weight | turn |\n+-----------+-------------------+--------+------+\n| 5         | George Washington | 250    | 1    |\n| 3         | John Adams        | 350    | 2    |\n| 6         | Thomas Jefferson  | 400    | 3    |\n| 2         | Will Johnliams    | 200    | 4    |\n| 4         | Thomas Jefferson  | 175    | 5    |\n| 1         | James Elephant    | 500    | 6    |\n+-----------+-------------------+--------+------+\n\nResult \u8868\n+-------------------+\n| person_name       |\n+-------------------+\n| Thomas Jefferson  |\n+-------------------+\n\n\u4e3a\u4e86\u7b80\u5316\uff0cQueue \u8868\u6309 turn \u5217\u7531\u5c0f\u5230\u5927\u6392\u5e8f\u3002\n\u4e0a\u4f8b\u4e2d George Washington(id 5), John Adams(id 3) \u548c Thomas Jefferson(id 6) \u5c06\u53ef\u4ee5\u8fdb\u5165\u7535\u68af,\u56e0\u4e3a\u4ed6\u4eec\u7684\u4f53\u91cd\u548c\u4e3a 250 + 350 + 400 = 1000\u3002\nThomas Jefferson(id 6) \u662f\u6700\u540e\u4e00\u4e2a\u4f53\u91cd\u5408\u9002\u5e76\u8fdb\u5165\u7535\u68af\u7684\u4eba\u3002\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1204](https://leetcode-cn.com/problems/last-person-to-fit-in-the-elevator)", "[\u6700\u540e\u4e00\u4e2a\u80fd\u8fdb\u5165\u7535\u68af\u7684\u4eba](/solution/1200-1299/1204.Last%20Person%20to%20Fit%20in%20the%20Elevator/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1204](https://leetcode.com/problems/last-person-to-fit-in-the-elevator)", "[Last Person to Fit in the Elevator](/solution/1200-1299/1204.Last%20Person%20to%20Fit%20in%20the%20Elevator/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1326", "frontend_question_id": "1862", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sum-of-floored-pairs", "url_en": "https://leetcode.com/problems/sum-of-floored-pairs", "relative_path_cn": "/solution/1800-1899/1862.Sum%20of%20Floored%20Pairs/README.md", "relative_path_en": "/solution/1800-1899/1862.Sum%20of%20Floored%20Pairs/README_EN.md", "title_cn": "\u5411\u4e0b\u53d6\u6574\u6570\u5bf9\u548c", "title_en": "Sum of Floored Pairs", "question_title_slug": "sum-of-floored-pairs", "content_en": "

Given an integer array nums, return the sum of floor(nums[i] / nums[j]) for all pairs of indices 0 <= i, j < nums.length in the array. Since the answer may be too large, return it modulo 109 + 7.

\n\n

The floor() function returns the integer part of the division.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [2,5,9]\nOutput: 10\nExplanation:\nfloor(2 / 5) = floor(2 / 9) = floor(5 / 9) = 0\nfloor(2 / 2) = floor(5 / 5) = floor(9 / 9) = 1\nfloor(5 / 2) = 2\nfloor(9 / 2) = 4\nfloor(9 / 5) = 1\nWe calculate the floor of the division for every pair of indices in the array then sum them up.\n
\n\n

Example 2:

\n\n
\nInput: nums = [7,7,7,7,7,7,7]\nOutput: 49\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 105
  • \n\t
  • 1 <= nums[i] <= 105
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0nums\u00a0\uff0c\u8bf7\u4f60\u8fd4\u56de\u6240\u6709\u4e0b\u6807\u5bf9\u00a00 <= i, j < nums.length\u00a0\u7684\u00a0floor(nums[i] / nums[j])\u00a0\u7ed3\u679c\u4e4b\u548c\u3002\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u4f1a\u5f88\u5927\uff0c\u8bf7\u4f60\u8fd4\u56de\u7b54\u6848\u5bf9109 + 7\u00a0\u53d6\u4f59\u00a0\u7684\u7ed3\u679c\u3002

\n\n

\u51fd\u6570\u00a0floor()\u00a0\u8fd4\u56de\u8f93\u5165\u6570\u5b57\u7684\u6574\u6570\u90e8\u5206\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anums = [2,5,9]\n\u8f93\u51fa\uff1a10\n\u89e3\u91ca\uff1a\nfloor(2 / 5) = floor(2 / 9) = floor(5 / 9) = 0\nfloor(2 / 2) = floor(5 / 5) = floor(9 / 9) = 1\nfloor(5 / 2) = 2\nfloor(9 / 2) = 4\nfloor(9 / 5) = 1\n\u6211\u4eec\u8ba1\u7b97\u6bcf\u4e00\u4e2a\u6570\u5bf9\u5546\u5411\u4e0b\u53d6\u6574\u7684\u7ed3\u679c\u5e76\u6c42\u548c\u5f97\u5230 10 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anums = [7,7,7,7,7,7,7]\n\u8f93\u51fa\uff1a49\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 105
  • \n\t
  • 1 <= nums[i] <= 105
  • \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int sumOfFlooredPairs(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int sumOfFlooredPairs(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def sumOfFlooredPairs(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def sumOfFlooredPairs(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint sumOfFlooredPairs(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SumOfFlooredPairs(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar sumOfFlooredPairs = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef sum_of_floored_pairs(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func sumOfFlooredPairs(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func sumOfFlooredPairs(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def sumOfFlooredPairs(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun sumOfFlooredPairs(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sum_of_floored_pairs(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function sumOfFlooredPairs($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function sumOfFlooredPairs(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (sum-of-floored-pairs nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1862](https://leetcode-cn.com/problems/sum-of-floored-pairs)", "[\u5411\u4e0b\u53d6\u6574\u6570\u5bf9\u548c](/solution/1800-1899/1862.Sum%20of%20Floored%20Pairs/README.md)", "`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[1862](https://leetcode.com/problems/sum-of-floored-pairs)", "[Sum of Floored Pairs](/solution/1800-1899/1862.Sum%20of%20Floored%20Pairs/README_EN.md)", "`Math`", "Hard", ""]}, {"question_id": "1325", "frontend_question_id": "1514", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/path-with-maximum-probability", "url_en": "https://leetcode.com/problems/path-with-maximum-probability", "relative_path_cn": "/solution/1500-1599/1514.Path%20with%20Maximum%20Probability/README.md", "relative_path_en": "/solution/1500-1599/1514.Path%20with%20Maximum%20Probability/README_EN.md", "title_cn": "\u6982\u7387\u6700\u5927\u7684\u8def\u5f84", "title_en": "Path with Maximum Probability", "question_title_slug": "path-with-maximum-probability", "content_en": "

You are given an undirected weighted graph of n nodes (0-indexed), represented by an edge list where edges[i] = [a, b] is an undirected edge connecting the nodes a and b with a probability of success of traversing that edge succProb[i].

\r\n\r\n

Given two nodes start and end, find the path with the maximum probability of success to go from start to end and return its success probability.

\r\n\r\n

If there is no path from start to end, return 0. Your answer will be accepted if it differs from the correct answer by at most 1e-5.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n

\"\"

\r\n\r\n
\r\nInput: n = 3, edges = [[0,1],[1,2],[0,2]], succProb = [0.5,0.5,0.2], start = 0, end = 2\r\nOutput: 0.25000\r\nExplanation: There are two paths from start to end, one having a probability of success = 0.2 and the other has 0.5 * 0.5 = 0.25.\r\n
\r\n\r\n

Example 2:

\r\n\r\n

\"\"

\r\n\r\n
\r\nInput: n = 3, edges = [[0,1],[1,2],[0,2]], succProb = [0.5,0.5,0.3], start = 0, end = 2\r\nOutput: 0.30000\r\n
\r\n\r\n

Example 3:

\r\n\r\n

\"\"

\r\n\r\n
\r\nInput: n = 3, edges = [[0,1]], succProb = [0.5], start = 0, end = 2\r\nOutput: 0.00000\r\nExplanation: There is no path between 0 and 2.\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 2 <= n <= 10^4
  • \r\n\t
  • 0 <= start, end < n
  • \r\n\t
  • start != end
  • \r\n\t
  • 0 <= a, b < n
  • \r\n\t
  • a != b
  • \r\n\t
  • 0 <= succProb.length == edges.length <= 2*10^4
  • \r\n\t
  • 0 <= succProb[i] <= 1
  • \r\n\t
  • There is at most one edge between every two nodes.
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u7531 n \u4e2a\u8282\u70b9\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\u7ec4\u6210\u7684\u65e0\u5411\u52a0\u6743\u56fe\uff0c\u8be5\u56fe\u7531\u4e00\u4e2a\u63cf\u8ff0\u8fb9\u7684\u5217\u8868\u7ec4\u6210\uff0c\u5176\u4e2d edges[i] = [a, b] \u8868\u793a\u8fde\u63a5\u8282\u70b9 a \u548c b \u7684\u4e00\u6761\u65e0\u5411\u8fb9\uff0c\u4e14\u8be5\u8fb9\u904d\u5386\u6210\u529f\u7684\u6982\u7387\u4e3a succProb[i] \u3002

\n\n

\u6307\u5b9a\u4e24\u4e2a\u8282\u70b9\u5206\u522b\u4f5c\u4e3a\u8d77\u70b9 start \u548c\u7ec8\u70b9 end \uff0c\u8bf7\u4f60\u627e\u51fa\u4ece\u8d77\u70b9\u5230\u7ec8\u70b9\u6210\u529f\u6982\u7387\u6700\u5927\u7684\u8def\u5f84\uff0c\u5e76\u8fd4\u56de\u5176\u6210\u529f\u6982\u7387\u3002

\n\n

\u5982\u679c\u4e0d\u5b58\u5728\u4ece start \u5230 end \u7684\u8def\u5f84\uff0c\u8bf7 \u8fd4\u56de 0 \u3002\u53ea\u8981\u7b54\u6848\u4e0e\u6807\u51c6\u7b54\u6848\u7684\u8bef\u5dee\u4e0d\u8d85\u8fc7 1e-5 \uff0c\u5c31\u4f1a\u88ab\u89c6\u4f5c\u6b63\u786e\u7b54\u6848\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1an = 3, edges = [[0,1],[1,2],[0,2]], succProb = [0.5,0.5,0.2], start = 0, end = 2\n\u8f93\u51fa\uff1a0.25000\n\u89e3\u91ca\uff1a\u4ece\u8d77\u70b9\u5230\u7ec8\u70b9\u6709\u4e24\u6761\u8def\u5f84\uff0c\u5176\u4e2d\u4e00\u6761\u7684\u6210\u529f\u6982\u7387\u4e3a 0.2 \uff0c\u800c\u53e6\u4e00\u6761\u4e3a 0.5 * 0.5 = 0.25\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1an = 3, edges = [[0,1],[1,2],[0,2]], succProb = [0.5,0.5,0.3], start = 0, end = 2\n\u8f93\u51fa\uff1a0.30000\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1an = 3, edges = [[0,1]], succProb = [0.5], start = 0, end = 2\n\u8f93\u51fa\uff1a0.00000\n\u89e3\u91ca\uff1a\u8282\u70b9 0 \u548c \u8282\u70b9 2 \u4e4b\u95f4\u4e0d\u5b58\u5728\u8def\u5f84\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= n <= 10^4
  • \n\t
  • 0 <= start, end < n
  • \n\t
  • start != end
  • \n\t
  • 0 <= a, b < n
  • \n\t
  • a != b
  • \n\t
  • 0 <= succProb.length == edges.length <= 2*10^4
  • \n\t
  • 0 <= succProb[i] <= 1
  • \n\t
  • \u6bcf\u4e24\u4e2a\u8282\u70b9\u4e4b\u95f4\u6700\u591a\u6709\u4e00\u6761\u8fb9
  • \n
\n", "tags_en": ["Graph"], "tags_cn": ["\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n double maxProbability(int n, vector>& edges, vector& succProb, int start, int end) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double maxProbability(int n, int[][] edges, double[] succProb, int start, int end) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxProbability(self, n, edges, succProb, start, end):\n \"\"\"\n :type n: int\n :type edges: List[List[int]]\n :type succProb: List[float]\n :type start: int\n :type end: int\n :rtype: float\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxProbability(self, n: int, edges: List[List[int]], succProb: List[float], start: int, end: int) -> float:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\ndouble maxProbability(int n, int** edges, int edgesSize, int* edgesColSize, double* succProb, int succProbSize, int start, int end){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double MaxProbability(int n, int[][] edges, double[] succProb, int start, int end) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} edges\n * @param {number[]} succProb\n * @param {number} start\n * @param {number} end\n * @return {number}\n */\nvar maxProbability = function(n, edges, succProb, start, end) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} edges\n# @param {Float[]} succ_prob\n# @param {Integer} start\n# @param {Integer} end\n# @return {Float}\ndef max_probability(n, edges, succ_prob, start, end)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxProbability(_ n: Int, _ edges: [[Int]], _ succProb: [Double], _ start: Int, _ end: Int) -> Double {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxProbability(n int, edges [][]int, succProb []float64, start int, end int) float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxProbability(n: Int, edges: Array[Array[Int]], succProb: Array[Double], start: Int, end: Int): Double = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxProbability(n: Int, edges: Array, succProb: DoubleArray, start: Int, end: Int): Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_probability(n: i32, edges: Vec>, succ_prob: Vec, start: i32, end: i32) -> f64 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $edges\n * @param Float[] $succProb\n * @param Integer $start\n * @param Integer $end\n * @return Float\n */\n function maxProbability($n, $edges, $succProb, $start, $end) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxProbability(n: number, edges: number[][], succProb: number[], start: number, end: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-probability n edges succProb start end)\n (-> exact-integer? (listof (listof exact-integer?)) (listof flonum?) exact-integer? exact-integer? flonum?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1514](https://leetcode-cn.com/problems/path-with-maximum-probability)", "[\u6982\u7387\u6700\u5927\u7684\u8def\u5f84](/solution/1500-1599/1514.Path%20with%20Maximum%20Probability/README.md)", "`\u56fe`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1514](https://leetcode.com/problems/path-with-maximum-probability)", "[Path with Maximum Probability](/solution/1500-1599/1514.Path%20with%20Maximum%20Probability/README_EN.md)", "`Graph`", "Medium", ""]}, {"question_id": "1324", "frontend_question_id": "1706", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/where-will-the-ball-fall", "url_en": "https://leetcode.com/problems/where-will-the-ball-fall", "relative_path_cn": "/solution/1700-1799/1706.Where%20Will%20the%20Ball%20Fall/README.md", "relative_path_en": "/solution/1700-1799/1706.Where%20Will%20the%20Ball%20Fall/README_EN.md", "title_cn": "\u7403\u4f1a\u843d\u4f55\u5904", "title_en": "Where Will the Ball Fall", "question_title_slug": "where-will-the-ball-fall", "content_en": "

You have a 2-D grid of size m x n representing a box, and you have n balls. The box is open on the top and bottom sides.

\n\n

Each cell in the box has a diagonal board spanning two corners of the cell that can redirect a ball to the right or to the left.

\n\n
    \n\t
  • A board that redirects the ball to the right spans the top-left corner to the bottom-right corner and is represented in the grid as 1.
  • \n\t
  • A board that redirects the ball to the left spans the top-right corner to the bottom-left corner and is represented in the grid as -1.
  • \n
\n\n

We drop one ball at the top of each column of the box. Each ball can get stuck in the box or fall out of the bottom. A ball gets stuck if it hits a "V" shaped pattern between two boards or if a board redirects the ball into either wall of the box.

\n\n

Return an array answer of size n where answer[i] is the column that the ball falls out of at the bottom after dropping the ball from the ith column at the top, or -1 if the ball gets stuck in the box.

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: grid = [[1,1,1,-1,-1],[1,1,1,-1,-1],[-1,-1,-1,1,1],[1,1,1,1,-1],[-1,-1,-1,-1,-1]]\nOutput: [1,-1,-1,-1,-1]\nExplanation: This example is shown in the photo.\nBall b0 is dropped at column 0 and falls out of the box at column 1.\nBall b1 is dropped at column 1 and will get stuck in the box between column 2 and 3 and row 1.\nBall b2 is dropped at column 2 and will get stuck on the box between column 2 and 3 and row 0.\nBall b3 is dropped at column 3 and will get stuck on the box between column 2 and 3 and row 0.\nBall b4 is dropped at column 4 and will get stuck on the box between column 2 and 3 and row 1.\n
\n\n

Example 2:

\n\n
\nInput: grid = [[-1]]\nOutput: [-1]\nExplanation: The ball gets stuck against the left wall.\n
\n\n

Example 3:

\n\n
\nInput: grid = [[1,1,1,1,1,1],[-1,-1,-1,-1,-1,-1],[1,1,1,1,1,1],[-1,-1,-1,-1,-1,-1]]\nOutput: [0,1,2,3,4,-1]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • m == grid.length
  • \n\t
  • n == grid[i].length
  • \n\t
  • 1 <= m, n <= 100
  • \n\t
  • grid[i][j] is 1 or -1.
  • \n
\n", "content_cn": "

\u7528\u4e00\u4e2a\u5927\u5c0f\u4e3a m x n \u7684\u4e8c\u7ef4\u7f51\u683c grid \u8868\u793a\u4e00\u4e2a\u7bb1\u5b50\u3002\u4f60\u6709 n \u9897\u7403\u3002\u7bb1\u5b50\u7684\u9876\u90e8\u548c\u5e95\u90e8\u90fd\u662f\u5f00\u7740\u7684\u3002

\n\n

\u7bb1\u5b50\u4e2d\u7684\u6bcf\u4e2a\u5355\u5143\u683c\u90fd\u6709\u4e00\u4e2a\u5bf9\u89d2\u7ebf\u6321\u677f\uff0c\u8de8\u8fc7\u5355\u5143\u683c\u7684\u4e24\u4e2a\u89d2\uff0c\u53ef\u4ee5\u5c06\u7403\u5bfc\u5411\u5de6\u4fa7\u6216\u8005\u53f3\u4fa7\u3002

\n\n
    \n\t
  • \u5c06\u7403\u5bfc\u5411\u53f3\u4fa7\u7684\u6321\u677f\u8de8\u8fc7\u5de6\u4e0a\u89d2\u548c\u53f3\u4e0b\u89d2\uff0c\u5728\u7f51\u683c\u4e2d\u7528 1 \u8868\u793a\u3002
  • \n\t
  • \u5c06\u7403\u5bfc\u5411\u5de6\u4fa7\u7684\u6321\u677f\u8de8\u8fc7\u53f3\u4e0a\u89d2\u548c\u5de6\u4e0b\u89d2\uff0c\u5728\u7f51\u683c\u4e2d\u7528 -1 \u8868\u793a\u3002
  • \n
\n\n

\u5728\u7bb1\u5b50\u6bcf\u4e00\u5217\u7684\u9876\u7aef\u5404\u653e\u4e00\u9897\u7403\u3002\u6bcf\u9897\u7403\u90fd\u53ef\u80fd\u5361\u5728\u7bb1\u5b50\u91cc\u6216\u4ece\u5e95\u90e8\u6389\u51fa\u6765\u3002\u5982\u679c\u7403\u6070\u597d\u5361\u5728\u4e24\u5757\u6321\u677f\u4e4b\u95f4\u7684 \"V\" \u5f62\u56fe\u6848\uff0c\u6216\u8005\u88ab\u4e00\u5757\u6321\u5bfc\u5411\u5230\u7bb1\u5b50\u7684\u4efb\u610f\u4e00\u4fa7\u8fb9\u4e0a\uff0c\u5c31\u4f1a\u5361\u4f4f\u3002

\n\n

\u8fd4\u56de\u4e00\u4e2a\u5927\u5c0f\u4e3a n \u7684\u6570\u7ec4 answer \uff0c\u5176\u4e2d answer[i] \u662f\u7403\u653e\u5728\u9876\u90e8\u7684\u7b2c i \u5217\u540e\u4ece\u5e95\u90e8\u6389\u51fa\u6765\u7684\u90a3\u4e00\u5217\u5bf9\u5e94\u7684\u4e0b\u6807\uff0c\u5982\u679c\u7403\u5361\u5728\u76d2\u5b50\u91cc\uff0c\u5219\u8fd4\u56de -1 \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1agrid = [[1,1,1,-1,-1],[1,1,1,-1,-1],[-1,-1,-1,1,1],[1,1,1,1,-1],[-1,-1,-1,-1,-1]]\n\u8f93\u51fa\uff1a[1,-1,-1,-1,-1]\n\u89e3\u91ca\uff1a\u793a\u4f8b\u5982\u56fe\uff1a\nb0 \u7403\u5f00\u59cb\u653e\u5728\u7b2c 0 \u5217\u4e0a\uff0c\u6700\u7ec8\u4ece\u7bb1\u5b50\u5e95\u90e8\u7b2c 1 \u5217\u6389\u51fa\u3002\nb1 \u7403\u5f00\u59cb\u653e\u5728\u7b2c 1 \u5217\u4e0a\uff0c\u4f1a\u5361\u5728\u7b2c 2\u30013 \u5217\u548c\u7b2c 1 \u884c\u4e4b\u95f4\u7684 \"V\" \u5f62\u91cc\u3002\nb2 \u7403\u5f00\u59cb\u653e\u5728\u7b2c 2 \u5217\u4e0a\uff0c\u4f1a\u5361\u5728\u7b2c 2\u30013 \u5217\u548c\u7b2c 0 \u884c\u4e4b\u95f4\u7684 \"V\" \u5f62\u91cc\u3002\nb3 \u7403\u5f00\u59cb\u653e\u5728\u7b2c 3 \u5217\u4e0a\uff0c\u4f1a\u5361\u5728\u7b2c 2\u30013 \u5217\u548c\u7b2c 0 \u884c\u4e4b\u95f4\u7684 \"V\" \u5f62\u91cc\u3002\nb4 \u7403\u5f00\u59cb\u653e\u5728\u7b2c 4 \u5217\u4e0a\uff0c\u4f1a\u5361\u5728\u7b2c 2\u30013 \u5217\u548c\u7b2c 1 \u884c\u4e4b\u95f4\u7684 \"V\" \u5f62\u91cc\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1agrid = [[-1]]\n\u8f93\u51fa\uff1a[-1]\n\u89e3\u91ca\uff1a\u7403\u88ab\u5361\u5728\u7bb1\u5b50\u5de6\u4fa7\u8fb9\u4e0a\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1agrid = [[1,1,1,1,1,1],[-1,-1,-1,-1,-1,-1],[1,1,1,1,1,1],[-1,-1,-1,-1,-1,-1]]\n\u8f93\u51fa\uff1a[0,1,2,3,4,-1]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • m == grid.length
  • \n\t
  • n == grid[i].length
  • \n\t
  • 1 <= m, n <= 100
  • \n\t
  • grid[i][j] \u4e3a 1 \u6216 -1
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findBall(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] findBall(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findBall(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findBall(self, grid: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* findBall(int** grid, int gridSize, int* gridColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] FindBall(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number[]}\n */\nvar findBall = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer[]}\ndef find_ball(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findBall(_ grid: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findBall(grid [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findBall(grid: Array[Array[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findBall(grid: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_ball(grid: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer[]\n */\n function findBall($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findBall(grid: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-ball grid)\n (-> (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1706](https://leetcode-cn.com/problems/where-will-the-ball-fall)", "[\u7403\u4f1a\u843d\u4f55\u5904](/solution/1700-1799/1706.Where%20Will%20the%20Ball%20Fall/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1706](https://leetcode.com/problems/where-will-the-ball-fall)", "[Where Will the Ball Fall](/solution/1700-1799/1706.Where%20Will%20the%20Ball%20Fall/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "1322", "frontend_question_id": "1210", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-moves-to-reach-target-with-rotations", "url_en": "https://leetcode.com/problems/minimum-moves-to-reach-target-with-rotations", "relative_path_cn": "/solution/1200-1299/1210.Minimum%20Moves%20to%20Reach%20Target%20with%20Rotations/README.md", "relative_path_en": "/solution/1200-1299/1210.Minimum%20Moves%20to%20Reach%20Target%20with%20Rotations/README_EN.md", "title_cn": "\u7a7f\u8fc7\u8ff7\u5bab\u7684\u6700\u5c11\u79fb\u52a8\u6b21\u6570", "title_en": "Minimum Moves to Reach Target with Rotations", "question_title_slug": "minimum-moves-to-reach-target-with-rotations", "content_en": "

In an n*n grid, there is a snake that spans 2 cells and starts moving from the top left corner at (0, 0) and (0, 1). The grid has empty cells represented by zeros and blocked cells represented by ones. The snake wants to reach the lower right corner at (n-1, n-2) and (n-1, n-1).

\n\n

In one move the snake can:

\n\n
    \n\t
  • Move one cell to the right if there are no blocked cells there. This move keeps the horizontal/vertical position of the snake as it is.
  • \n\t
  • Move down one cell if there are no blocked cells there. This move keeps the horizontal/vertical position of the snake as it is.
  • \n\t
  • Rotate clockwise if it's in a horizontal position and the two cells under it are both empty. In that case the snake moves from (r, c) and (r, c+1) to (r, c) and (r+1, c).
    \n\t\"\"
  • \n\t
  • Rotate counterclockwise if it's in a vertical position and the two cells to its right are both empty. In that case the snake moves from (r, c) and (r+1, c) to (r, c) and (r, c+1).
    \n\t\"\"
  • \n
\n\n

Return the minimum number of moves to reach the target.

\n\n

If there is no way to reach the target, return -1.

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: grid = [[0,0,0,0,0,1],\n               [1,1,0,0,1,0],\n               [0,0,0,0,1,1],\n               [0,0,1,0,1,0],\n               [0,1,1,0,0,0],\n               [0,1,1,0,0,0]]\nOutput: 11\nExplanation:\nOne possible solution is [right, right, rotate clockwise, right, down, down, down, down, rotate counterclockwise, right, down].\n
\n\n

Example 2:

\n\n
\nInput: grid = [[0,0,1,1,1,1],\n               [0,0,0,0,1,1],\n               [1,1,0,0,0,1],\n               [1,1,1,0,0,1],\n               [1,1,1,0,0,1],\n               [1,1,1,0,0,0]]\nOutput: 9\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= n <= 100
  • \n\t
  • 0 <= grid[i][j] <= 1
  • \n\t
  • It is guaranteed that the snake starts at empty cells.
  • \n
\n", "content_cn": "

\u4f60\u8fd8\u8bb0\u5f97\u90a3\u6761\u98ce\u9761\u5168\u7403\u7684\u8d2a\u5403\u86c7\u5417\uff1f

\n\n

\u6211\u4eec\u5728\u4e00\u4e2a n*n \u7684\u7f51\u683c\u4e0a\u6784\u5efa\u4e86\u65b0\u7684\u8ff7\u5bab\u5730\u56fe\uff0c\u86c7\u7684\u957f\u5ea6\u4e3a 2\uff0c\u4e5f\u5c31\u662f\u8bf4\u5b83\u4f1a\u5360\u53bb\u4e24\u4e2a\u5355\u5143\u683c\u3002\u86c7\u4f1a\u4ece\u5de6\u4e0a\u89d2\uff08(0, 0) \u548c (0, 1)\uff09\u5f00\u59cb\u79fb\u52a8\u3002\u6211\u4eec\u7528 0 \u8868\u793a\u7a7a\u5355\u5143\u683c\uff0c\u7528 1 \u8868\u793a\u969c\u788d\u7269\u3002\u86c7\u9700\u8981\u79fb\u52a8\u5230\u8ff7\u5bab\u7684\u53f3\u4e0b\u89d2\uff08(n-1, n-2) \u548c (n-1, n-1)\uff09\u3002

\n\n

\u6bcf\u6b21\u79fb\u52a8\uff0c\u86c7\u53ef\u4ee5\u8fd9\u6837\u8d70\uff1a

\n\n
    \n\t
  • \u5982\u679c\u6ca1\u6709\u969c\u788d\uff0c\u5219\u5411\u53f3\u79fb\u52a8\u4e00\u4e2a\u5355\u5143\u683c\u3002\u5e76\u4ecd\u7136\u4fdd\u6301\u8eab\u4f53\u7684\u6c34\u5e73\uff0f\u7ad6\u76f4\u72b6\u6001\u3002
  • \n\t
  • \u5982\u679c\u6ca1\u6709\u969c\u788d\uff0c\u5219\u5411\u4e0b\u79fb\u52a8\u4e00\u4e2a\u5355\u5143\u683c\u3002\u5e76\u4ecd\u7136\u4fdd\u6301\u8eab\u4f53\u7684\u6c34\u5e73\uff0f\u7ad6\u76f4\u72b6\u6001\u3002
  • \n\t
  • \u5982\u679c\u5b83\u5904\u4e8e\u6c34\u5e73\u72b6\u6001\u5e76\u4e14\u5176\u4e0b\u9762\u7684\u4e24\u4e2a\u5355\u5143\u90fd\u662f\u7a7a\u7684\uff0c\u5c31\u987a\u65f6\u9488\u65cb\u8f6c 90 \u5ea6\u3002\u86c7\u4ece\uff08(r, c)\u3001(r, c+1)\uff09\u79fb\u52a8\u5230 \uff08(r, c)\u3001(r+1, c)\uff09\u3002
    \n\t\"\"
  • \n\t
  • \u5982\u679c\u5b83\u5904\u4e8e\u7ad6\u76f4\u72b6\u6001\u5e76\u4e14\u5176\u53f3\u9762\u7684\u4e24\u4e2a\u5355\u5143\u90fd\u662f\u7a7a\u7684\uff0c\u5c31\u9006\u65f6\u9488\u65cb\u8f6c 90 \u5ea6\u3002\u86c7\u4ece\uff08(r, c)\u3001(r+1, c)\uff09\u79fb\u52a8\u5230\uff08(r, c)\u3001(r, c+1)\uff09\u3002
    \n\t\"\"
  • \n
\n\n

\u8fd4\u56de\u86c7\u62b5\u8fbe\u76ee\u7684\u5730\u6240\u9700\u7684\u6700\u5c11\u79fb\u52a8\u6b21\u6570\u3002

\n\n

\u5982\u679c\u65e0\u6cd5\u5230\u8fbe\u76ee\u7684\u5730\uff0c\u8bf7\u8fd4\u56de -1\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1agrid = [[0,0,0,0,0,1],\n               [1,1,0,0,1,0],\n               [0,0,0,0,1,1],\n               [0,0,1,0,1,0],\n               [0,1,1,0,0,0],\n               [0,1,1,0,0,0]]\n\u8f93\u51fa\uff1a11\n\u89e3\u91ca\uff1a\n\u4e00\u79cd\u53ef\u80fd\u7684\u89e3\u51b3\u65b9\u6848\u662f [\u53f3, \u53f3, \u987a\u65f6\u9488\u65cb\u8f6c, \u53f3, \u4e0b, \u4e0b, \u4e0b, \u4e0b, \u9006\u65f6\u9488\u65cb\u8f6c, \u53f3, \u4e0b]\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1agrid = [[0,0,1,1,1,1],\n               [0,0,0,0,1,1],\n               [1,1,0,0,0,1],\n               [1,1,1,0,0,1],\n               [1,1,1,0,0,1],\n               [1,1,1,0,0,0]]\n\u8f93\u51fa\uff1a9\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= n <= 100
  • \n\t
  • 0 <= grid[i][j] <= 1
  • \n\t
  • \u86c7\u4fdd\u8bc1\u4ece\u7a7a\u5355\u5143\u683c\u5f00\u59cb\u51fa\u53d1\u3002
  • \n
\n", "tags_en": ["Breadth-first Search"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minimumMoves(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minimumMoves(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimumMoves(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimumMoves(self, grid: List[List[int]]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minimumMoves(int** grid, int gridSize, int* gridColSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinimumMoves(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar minimumMoves = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef minimum_moves(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimumMoves(_ grid: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimumMoves(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimumMoves(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimumMoves(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimum_moves(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function minimumMoves($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimumMoves(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimum-moves grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1210](https://leetcode-cn.com/problems/minimum-moves-to-reach-target-with-rotations)", "[\u7a7f\u8fc7\u8ff7\u5bab\u7684\u6700\u5c11\u79fb\u52a8\u6b21\u6570](/solution/1200-1299/1210.Minimum%20Moves%20to%20Reach%20Target%20with%20Rotations/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[1210](https://leetcode.com/problems/minimum-moves-to-reach-target-with-rotations)", "[Minimum Moves to Reach Target with Rotations](/solution/1200-1299/1210.Minimum%20Moves%20to%20Reach%20Target%20with%20Rotations/README_EN.md)", "`Breadth-first Search`", "Hard", ""]}, {"question_id": "1321", "frontend_question_id": "1208", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/get-equal-substrings-within-budget", "url_en": "https://leetcode.com/problems/get-equal-substrings-within-budget", "relative_path_cn": "/solution/1200-1299/1208.Get%20Equal%20Substrings%20Within%20Budget/README.md", "relative_path_en": "/solution/1200-1299/1208.Get%20Equal%20Substrings%20Within%20Budget/README_EN.md", "title_cn": "\u5c3d\u53ef\u80fd\u4f7f\u5b57\u7b26\u4e32\u76f8\u7b49", "title_en": "Get Equal Substrings Within Budget", "question_title_slug": "get-equal-substrings-within-budget", "content_en": "

You are given two strings s and t of the same length. You want to change s to t. Changing the i-th character of s to i-th character of t costs |s[i] - t[i]| that is, the absolute difference between the ASCII values of the characters.

\n\n

You are also given an integer maxCost.

\n\n

Return the maximum length of a substring of s that can be changed to be the same as the corresponding substring of twith a cost less than or equal to maxCost.

\n\n

If there is no substring from s that can be changed to its corresponding substring from t, return 0.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "abcd", t = "bcdf", maxCost = 3\nOutput: 3\nExplanation: "abc" of s can change to "bcd". That costs 3, so the maximum length is 3.
\n\n

Example 2:

\n\n
\nInput: s = "abcd", t = "cdef", maxCost = 3\nOutput: 1\nExplanation: Each character in s costs 2 to change to charactor in t, so the maximum length is 1.\n
\n\n

Example 3:

\n\n
\nInput: s = "abcd", t = "acde", maxCost = 0\nOutput: 1\nExplanation: You can't make any change, so the maximum length is 1.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length, t.length <= 10^5
  • \n\t
  • 0 <= maxCost <= 10^6
  • \n\t
  • s and t only contain lower case English letters.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e24\u4e2a\u957f\u5ea6\u76f8\u540c\u7684\u5b57\u7b26\u4e32\uff0cs \u548c t\u3002

\n\n

\u5c06 s\u00a0\u4e2d\u7684\u7b2c\u00a0i\u00a0\u4e2a\u5b57\u7b26\u53d8\u5230\u00a0t\u00a0\u4e2d\u7684\u7b2c i \u4e2a\u5b57\u7b26\u9700\u8981\u00a0|s[i] - t[i]|\u00a0\u7684\u5f00\u9500\uff08\u5f00\u9500\u53ef\u80fd\u4e3a 0\uff09\uff0c\u4e5f\u5c31\u662f\u4e24\u4e2a\u5b57\u7b26\u7684 ASCII \u7801\u503c\u7684\u5dee\u7684\u7edd\u5bf9\u503c\u3002

\n\n

\u7528\u4e8e\u53d8\u66f4\u5b57\u7b26\u4e32\u7684\u6700\u5927\u9884\u7b97\u662f\u00a0maxCost\u3002\u5728\u8f6c\u5316\u5b57\u7b26\u4e32\u65f6\uff0c\u603b\u5f00\u9500\u5e94\u5f53\u5c0f\u4e8e\u7b49\u4e8e\u8be5\u9884\u7b97\uff0c\u8fd9\u4e5f\u610f\u5473\u7740\u5b57\u7b26\u4e32\u7684\u8f6c\u5316\u53ef\u80fd\u662f\u4e0d\u5b8c\u5168\u7684\u3002

\n\n

\u5982\u679c\u4f60\u53ef\u4ee5\u5c06 s \u7684\u5b50\u5b57\u7b26\u4e32\u8f6c\u5316\u4e3a\u5b83\u5728 t \u4e2d\u5bf9\u5e94\u7684\u5b50\u5b57\u7b26\u4e32\uff0c\u5219\u8fd4\u56de\u53ef\u4ee5\u8f6c\u5316\u7684\u6700\u5927\u957f\u5ea6\u3002

\n\n

\u5982\u679c s \u4e2d\u6ca1\u6709\u5b50\u5b57\u7b26\u4e32\u53ef\u4ee5\u8f6c\u5316\u6210 t \u4e2d\u5bf9\u5e94\u7684\u5b50\u5b57\u7b26\u4e32\uff0c\u5219\u8fd4\u56de 0\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"abcd\", t = \"bcdf\", maxCost = 3\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1as \u4e2d\u7684 \"abc\" \u53ef\u4ee5\u53d8\u4e3a \"bcd\"\u3002\u5f00\u9500\u4e3a 3\uff0c\u6240\u4ee5\u6700\u5927\u957f\u5ea6\u4e3a 3\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"abcd\", t = \"cdef\", maxCost = 3\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1as \u4e2d\u7684\u4efb\u4e00\u5b57\u7b26\u8981\u60f3\u53d8\u6210 t \u4e2d\u5bf9\u5e94\u7684\u5b57\u7b26\uff0c\u5176\u5f00\u9500\u90fd\u662f 2\u3002\u56e0\u6b64\uff0c\u6700\u5927\u957f\u5ea6\u4e3a 1\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"abcd\", t = \"acde\", maxCost = 0\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1aa -> a, cost = 0\uff0c\u5b57\u7b26\u4e32\u672a\u53d1\u751f\u53d8\u5316\uff0c\u6240\u4ee5\u6700\u5927\u957f\u5ea6\u4e3a 1\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length, t.length <= 10^5
  • \n\t
  • 0 <= maxCost <= 10^6
  • \n\t
  • s \u548c\u00a0t\u00a0\u90fd\u53ea\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
  • \n
\n", "tags_en": ["Array", "Sliding Window"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int equalSubstring(string s, string t, int maxCost) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int equalSubstring(String s, String t, int maxCost) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def equalSubstring(self, s, t, maxCost):\n \"\"\"\n :type s: str\n :type t: str\n :type maxCost: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def equalSubstring(self, s: str, t: str, maxCost: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint equalSubstring(char * s, char * t, int maxCost){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int EqualSubstring(string s, string t, int maxCost) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string} t\n * @param {number} maxCost\n * @return {number}\n */\nvar equalSubstring = function(s, t, maxCost) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String} t\n# @param {Integer} max_cost\n# @return {Integer}\ndef equal_substring(s, t, max_cost)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func equalSubstring(_ s: String, _ t: String, _ maxCost: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func equalSubstring(s string, t string, maxCost int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def equalSubstring(s: String, t: String, maxCost: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun equalSubstring(s: String, t: String, maxCost: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn equal_substring(s: String, t: String, max_cost: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String $t\n * @param Integer $maxCost\n * @return Integer\n */\n function equalSubstring($s, $t, $maxCost) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function equalSubstring(s: string, t: string, maxCost: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (equal-substring s t maxCost)\n (-> string? string? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1208](https://leetcode-cn.com/problems/get-equal-substrings-within-budget)", "[\u5c3d\u53ef\u80fd\u4f7f\u5b57\u7b26\u4e32\u76f8\u7b49](/solution/1200-1299/1208.Get%20Equal%20Substrings%20Within%20Budget/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1208](https://leetcode.com/problems/get-equal-substrings-within-budget)", "[Get Equal Substrings Within Budget](/solution/1200-1299/1208.Get%20Equal%20Substrings%20Within%20Budget/README_EN.md)", "`Array`,`Sliding Window`", "Medium", ""]}, {"question_id": "1320", "frontend_question_id": "1209", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string-ii", "url_en": "https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string-ii", "relative_path_cn": "/solution/1200-1299/1209.Remove%20All%20Adjacent%20Duplicates%20in%20String%20II/README.md", "relative_path_en": "/solution/1200-1299/1209.Remove%20All%20Adjacent%20Duplicates%20in%20String%20II/README_EN.md", "title_cn": "\u5220\u9664\u5b57\u7b26\u4e32\u4e2d\u7684\u6240\u6709\u76f8\u90bb\u91cd\u590d\u9879 II", "title_en": "Remove All Adjacent Duplicates in String II", "question_title_slug": "remove-all-adjacent-duplicates-in-string-ii", "content_en": "

You are given a string s and an integer k, a k duplicate removal consists of choosing k adjacent and equal letters from s and removing them, causing the left and the right side of the deleted substring to concatenate together.

\n\n

We repeatedly make k duplicate removals on s until we no longer can.

\n\n

Return the final string after all such duplicate removals have been made. It is guaranteed that the answer is unique.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "abcd", k = 2\nOutput: "abcd"\nExplanation: There's nothing to delete.
\n\n

Example 2:

\n\n
\nInput: s = "deeedbbcccbdaa", k = 3\nOutput: "aa"\nExplanation: \nFirst delete "eee" and "ccc", get "ddbbbdaa"\nThen delete "bbb", get "dddaa"\nFinally delete "ddd", get "aa"
\n\n

Example 3:

\n\n
\nInput: s = "pbbcggttciiippooaais", k = 2\nOutput: "ps"\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 105
  • \n\t
  • 2 <= k <= 104
  • \n\t
  • s only contains lower case English letters.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s\uff0c\u300ck \u500d\u91cd\u590d\u9879\u5220\u9664\u64cd\u4f5c\u300d\u5c06\u4f1a\u4ece s \u4e2d\u9009\u62e9 k \u4e2a\u76f8\u90bb\u4e14\u76f8\u7b49\u7684\u5b57\u6bcd\uff0c\u5e76\u5220\u9664\u5b83\u4eec\uff0c\u4f7f\u88ab\u5220\u53bb\u7684\u5b57\u7b26\u4e32\u7684\u5de6\u4fa7\u548c\u53f3\u4fa7\u8fde\u5728\u4e00\u8d77\u3002

\n\n

\u4f60\u9700\u8981\u5bf9 s \u91cd\u590d\u8fdb\u884c\u65e0\u9650\u6b21\u8fd9\u6837\u7684\u5220\u9664\u64cd\u4f5c\uff0c\u76f4\u5230\u65e0\u6cd5\u7ee7\u7eed\u4e3a\u6b62\u3002

\n\n

\u5728\u6267\u884c\u5b8c\u6240\u6709\u5220\u9664\u64cd\u4f5c\u540e\uff0c\u8fd4\u56de\u6700\u7ec8\u5f97\u5230\u7684\u5b57\u7b26\u4e32\u3002

\n\n

\u672c\u9898\u7b54\u6848\u4fdd\u8bc1\u552f\u4e00\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1as = "abcd", k = 2\n\u8f93\u51fa\uff1a"abcd"\n\u89e3\u91ca\uff1a\u6ca1\u6709\u8981\u5220\u9664\u7684\u5185\u5bb9\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1as = "deeedbbcccbdaa", k = 3\n\u8f93\u51fa\uff1a"aa"\n\u89e3\u91ca\uff1a \n\u5148\u5220\u9664 "eee" \u548c "ccc"\uff0c\u5f97\u5230 "ddbbbdaa"\n\u518d\u5220\u9664 "bbb"\uff0c\u5f97\u5230 "dddaa"\n\u6700\u540e\u5220\u9664 "ddd"\uff0c\u5f97\u5230 "aa"
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1as = "pbbcggttciiippooaais", k = 2\n\u8f93\u51fa\uff1a"ps"\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length <= 10^5
  • \n\t
  • 2 <= k <= 10^4
  • \n\t
  • s \u4e2d\u53ea\u542b\u6709\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
  • \n
\n", "tags_en": ["Stack"], "tags_cn": ["\u6808"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string removeDuplicates(string s, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String removeDuplicates(String s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def removeDuplicates(self, s, k):\n \"\"\"\n :type s: str\n :type k: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def removeDuplicates(self, s: str, k: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * removeDuplicates(char * s, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string RemoveDuplicates(string s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number} k\n * @return {string}\n */\nvar removeDuplicates = function(s, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer} k\n# @return {String}\ndef remove_duplicates(s, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func removeDuplicates(_ s: String, _ k: Int) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func removeDuplicates(s string, k int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def removeDuplicates(s: String, k: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun removeDuplicates(s: String, k: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn remove_duplicates(s: String, k: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer $k\n * @return String\n */\n function removeDuplicates($s, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function removeDuplicates(s: string, k: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (remove-duplicates s k)\n (-> string? exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1209](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string-ii)", "[\u5220\u9664\u5b57\u7b26\u4e32\u4e2d\u7684\u6240\u6709\u76f8\u90bb\u91cd\u590d\u9879 II](/solution/1200-1299/1209.Remove%20All%20Adjacent%20Duplicates%20in%20String%20II/README.md)", "`\u6808`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1209](https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string-ii)", "[Remove All Adjacent Duplicates in String II](/solution/1200-1299/1209.Remove%20All%20Adjacent%20Duplicates%20in%20String%20II/README_EN.md)", "`Stack`", "Medium", ""]}, {"question_id": "1319", "frontend_question_id": "1207", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/unique-number-of-occurrences", "url_en": "https://leetcode.com/problems/unique-number-of-occurrences", "relative_path_cn": "/solution/1200-1299/1207.Unique%20Number%20of%20Occurrences/README.md", "relative_path_en": "/solution/1200-1299/1207.Unique%20Number%20of%20Occurrences/README_EN.md", "title_cn": "\u72ec\u4e00\u65e0\u4e8c\u7684\u51fa\u73b0\u6b21\u6570", "title_en": "Unique Number of Occurrences", "question_title_slug": "unique-number-of-occurrences", "content_en": "

Given an array of integers arr, write a function that returns true if and only if the number of occurrences of each value in the array is unique.

\n\n

 

\n

Example 1:

\n\n
\nInput: arr = [1,2,2,1,1,3]\nOutput: true\nExplanation: The value 1 has 3 occurrences, 2 has 2 and 3 has 1. No two values have the same number of occurrences.
\n\n

Example 2:

\n\n
\nInput: arr = [1,2]\nOutput: false\n
\n\n

Example 3:

\n\n
\nInput: arr = [-3,0,1,-3,1,1,1,-3,10,0]\nOutput: true\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= arr.length <= 1000
  • \n\t
  • -1000 <= arr[i] <= 1000
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr\uff0c\u8bf7\u4f60\u5e2e\u5fd9\u7edf\u8ba1\u6570\u7ec4\u4e2d\u6bcf\u4e2a\u6570\u7684\u51fa\u73b0\u6b21\u6570\u3002

\n\n

\u5982\u679c\u6bcf\u4e2a\u6570\u7684\u51fa\u73b0\u6b21\u6570\u90fd\u662f\u72ec\u4e00\u65e0\u4e8c\u7684\uff0c\u5c31\u8fd4\u56de true\uff1b\u5426\u5219\u8fd4\u56de false\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aarr = [1,2,2,1,1,3]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u5728\u8be5\u6570\u7ec4\u4e2d\uff0c1 \u51fa\u73b0\u4e86 3 \u6b21\uff0c2 \u51fa\u73b0\u4e86 2 \u6b21\uff0c3 \u53ea\u51fa\u73b0\u4e86 1 \u6b21\u3002\u6ca1\u6709\u4e24\u4e2a\u6570\u7684\u51fa\u73b0\u6b21\u6570\u76f8\u540c\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aarr = [1,2]\n\u8f93\u51fa\uff1afalse\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aarr = [-3,0,1,-3,1,1,1,-3,10,0]\n\u8f93\u51fa\uff1atrue\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= arr.length <= 1000
  • \n\t
  • -1000 <= arr[i] <= 1000
  • \n
\n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool uniqueOccurrences(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean uniqueOccurrences(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def uniqueOccurrences(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: bool\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def uniqueOccurrences(self, arr: List[int]) -> bool:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool uniqueOccurrences(int* arr, int arrSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool UniqueOccurrences(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {boolean}\n */\nvar uniqueOccurrences = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Boolean}\ndef unique_occurrences(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func uniqueOccurrences(_ arr: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func uniqueOccurrences(arr []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def uniqueOccurrences(arr: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun uniqueOccurrences(arr: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn unique_occurrences(arr: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Boolean\n */\n function uniqueOccurrences($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function uniqueOccurrences(arr: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (unique-occurrences arr)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1207](https://leetcode-cn.com/problems/unique-number-of-occurrences)", "[\u72ec\u4e00\u65e0\u4e8c\u7684\u51fa\u73b0\u6b21\u6570](/solution/1200-1299/1207.Unique%20Number%20of%20Occurrences/README.md)", "`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[1207](https://leetcode.com/problems/unique-number-of-occurrences)", "[Unique Number of Occurrences](/solution/1200-1299/1207.Unique%20Number%20of%20Occurrences/README_EN.md)", "`Hash Table`", "Easy", ""]}, {"question_id": "1318", "frontend_question_id": "1194", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/tournament-winners", "url_en": "https://leetcode.com/problems/tournament-winners", "relative_path_cn": "/solution/1100-1199/1194.Tournament%20Winners/README.md", "relative_path_en": "/solution/1100-1199/1194.Tournament%20Winners/README_EN.md", "title_cn": "\u9526\u6807\u8d5b\u4f18\u80dc\u8005", "title_en": "Tournament Winners", "question_title_slug": "tournament-winners", "content_en": "

Table: Players

\n\n
\n+-------------+-------+\n| Column Name | Type  |\n+-------------+-------+\n| player_id   | int   |\n| group_id    | int   |\n+-------------+-------+\nplayer_id is the primary key of this table.\nEach row of this table indicates the group of each player.\n
\n\n

Table: Matches

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| match_id      | int     |\n| first_player  | int     |\n| second_player | int     | \n| first_score   | int     |\n| second_score  | int     |\n+---------------+---------+\nmatch_id is the primary key of this table.\nEach row is a record of a match, first_player and second_player contain the player_id of each match.\nfirst_score and second_score contain the number of points of the first_player and second_player respectively.\nYou may assume that, in each match, players belongs to the same group.\n
\n\n

 

\n\n

The winner in each group is the player who scored the maximum total points within the group. In the case of a tie, the lowest player_id wins.

\n\n

Write an SQL query to find the winner in each group.

\n\n

The query result format is in the following example:

\n\n
\nPlayers table:\n+-----------+------------+\n| player_id | group_id   |\n+-----------+------------+\n| 15        | 1          |\n| 25        | 1          |\n| 30        | 1          |\n| 45        | 1          |\n| 10        | 2          |\n| 35        | 2          |\n| 50        | 2          |\n| 20        | 3          |\n| 40        | 3          |\n+-----------+------------+\n\nMatches table:\n+------------+--------------+---------------+-------------+--------------+\n| match_id   | first_player | second_player | first_score | second_score |\n+------------+--------------+---------------+-------------+--------------+\n| 1          | 15           | 45            | 3           | 0            |\n| 2          | 30           | 25            | 1           | 2            |\n| 3          | 30           | 15            | 2           | 0            |\n| 4          | 40           | 20            | 5           | 2            |\n| 5          | 35           | 50            | 1           | 1            |\n+------------+--------------+---------------+-------------+--------------+\n\nResult table:\n+-----------+------------+\n| group_id  | player_id  |\n+-----------+------------+ \n| 1         | 15         |\n| 2         | 35         |\n| 3         | 40         |\n+-----------+------------+\n
\n", "content_cn": "

Players\u00a0\u73a9\u5bb6\u8868

\n\n
\n+-------------+-------+\n| Column Name | Type  |\n+-------------+-------+\n| player_id   | int   |\n| group_id    | int   |\n+-------------+-------+\nplayer_id \u662f\u6b64\u8868\u7684\u4e3b\u952e\u3002\n\u6b64\u8868\u7684\u6bcf\u4e00\u884c\u8868\u793a\u6bcf\u4e2a\u73a9\u5bb6\u7684\u7ec4\u3002\n
\n\n

Matches\u00a0\u8d5b\u4e8b\u8868

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| match_id      | int     |\n| first_player  | int     |\n| second_player | int     | \n| first_score   | int     |\n| second_score  | int     |\n+---------------+---------+\nmatch_id \u662f\u6b64\u8868\u7684\u4e3b\u952e\u3002\n\u6bcf\u4e00\u884c\u662f\u4e00\u573a\u6bd4\u8d5b\u7684\u8bb0\u5f55\uff0cfirst_player \u548c second_player \u8868\u793a\u8be5\u573a\u6bd4\u8d5b\u7684\u7403\u5458 ID\u3002\nfirst_score \u548c second_score \u5206\u522b\u8868\u793a first_player \u548c second_player \u7684\u5f97\u5206\u3002\n\u4f60\u53ef\u4ee5\u5047\u8bbe\uff0c\u5728\u6bcf\u4e00\u573a\u6bd4\u8d5b\u4e2d\uff0c\u7403\u5458\u90fd\u5c5e\u4e8e\u540c\u4e00\u7ec4\u3002\n
\n\n

\u00a0

\n\n

\u6bcf\u7ec4\u7684\u83b7\u80dc\u8005\u662f\u5728\u7ec4\u5185\u7d2f\u79ef\u5f97\u5206\u6700\u9ad8\u7684\u9009\u624b\u3002\u5982\u679c\u5e73\u5c40\uff0cplayer_id \u6700\u5c0f\u00a0\u7684\u9009\u624b\u83b7\u80dc\u3002

\n\n

\u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\u6765\u67e5\u627e\u6bcf\u7ec4\u4e2d\u7684\u83b7\u80dc\u8005\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u6240\u793a

\n\n
\nPlayers \u8868:\n+-----------+------------+\n| player_id | group_id   |\n+-----------+------------+\n| 15        | 1          |\n| 25        | 1          |\n| 30        | 1          |\n| 45        | 1          |\n| 10        | 2          |\n| 35        | 2          |\n| 50        | 2          |\n| 20        | 3          |\n| 40        | 3          |\n+-----------+------------+\n\nMatches \u8868:\n+------------+--------------+---------------+-------------+--------------+\n| match_id   | first_player | second_player | first_score | second_score |\n+------------+--------------+---------------+-------------+--------------+\n| 1          | 15           | 45            | 3           | 0            |\n| 2          | 30           | 25            | 1           | 2            |\n| 3          | 30           | 15            | 2           | 0            |\n| 4          | 40           | 20            | 5           | 2            |\n| 5          | 35           | 50            | 1           | 1            |\n+------------+--------------+---------------+-------------+--------------+\n\nResult \u8868:\n+-----------+------------+\n| group_id  | player_id  |\n+-----------+------------+ \n| 1         | 15         |\n| 2         | 35         |\n| 3         | 40         |\n+-----------+------------+\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1194](https://leetcode-cn.com/problems/tournament-winners)", "[\u9526\u6807\u8d5b\u4f18\u80dc\u8005](/solution/1100-1199/1194.Tournament%20Winners/README.md)", "", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1194](https://leetcode.com/problems/tournament-winners)", "[Tournament Winners](/solution/1100-1199/1194.Tournament%20Winners/README_EN.md)", "", "Hard", "\ud83d\udd12"]}, {"question_id": "1317", "frontend_question_id": "1193", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/monthly-transactions-i", "url_en": "https://leetcode.com/problems/monthly-transactions-i", "relative_path_cn": "/solution/1100-1199/1193.Monthly%20Transactions%20I/README.md", "relative_path_en": "/solution/1100-1199/1193.Monthly%20Transactions%20I/README_EN.md", "title_cn": "\u6bcf\u6708\u4ea4\u6613 I", "title_en": "Monthly Transactions I", "question_title_slug": "monthly-transactions-i", "content_en": "

Table: Transactions

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| country       | varchar |\n| state         | enum    |\n| amount        | int     |\n| trans_date    | date    |\n+---------------+---------+\nid is the primary key of this table.\nThe table has information about incoming transactions.\nThe state column is an enum of type ["approved", "declined"].\n
\n\n

 

\n\n

Write an SQL query to find for each month and country, the number of transactions and their total amount, the number of approved transactions and their total amount.

\n\n

The query result format is in the following example:

\n\n
\nTransactions table:\n+------+---------+----------+--------+------------+\n| id   | country | state    | amount | trans_date |\n+------+---------+----------+--------+------------+\n| 121  | US      | approved | 1000   | 2018-12-18 |\n| 122  | US      | declined | 2000   | 2018-12-19 |\n| 123  | US      | approved | 2000   | 2019-01-01 |\n| 124  | DE      | approved | 2000   | 2019-01-07 |\n+------+---------+----------+--------+------------+\n\nResult table:\n+----------+---------+-------------+----------------+--------------------+-----------------------+\n| month    | country | trans_count | approved_count | trans_total_amount | approved_total_amount |\n+----------+---------+-------------+----------------+--------------------+-----------------------+\n| 2018-12  | US      | 2           | 1              | 3000               | 1000                  |\n| 2019-01  | US      | 1           | 1              | 2000               | 2000                  |\n| 2019-01  | DE      | 1           | 1              | 2000               | 2000                  |\n+----------+---------+-------------+----------------+--------------------+-----------------------+\n
\n", "content_cn": "

Table: Transactions

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| country       | varchar |\n| state         | enum    |\n| amount        | int     |\n| trans_date    | date    |\n+---------------+---------+\nid \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\u3002\n\u8be5\u8868\u5305\u542b\u6709\u5173\u4f20\u5165\u4e8b\u52a1\u7684\u4fe1\u606f\u3002\nstate \u5217\u7c7b\u578b\u4e3a “[”\u6279\u51c6“\uff0c”\u62d2\u7edd“] \u4e4b\u4e00\u3002\n
\n\n

 

\n\n

\u7f16\u5199\u4e00\u4e2a sql \u67e5\u8be2\u6765\u67e5\u627e\u6bcf\u4e2a\u6708\u548c\u6bcf\u4e2a\u56fd\u5bb6/\u5730\u533a\u7684\u4e8b\u52a1\u6570\u53ca\u5176\u603b\u91d1\u989d\u3001\u5df2\u6279\u51c6\u7684\u4e8b\u52a1\u6570\u53ca\u5176\u603b\u91d1\u989d\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u6240\u793a\uff1a

\n\n
\nTransactions table:\n+------+---------+----------+--------+------------+\n| id   | country | state    | amount | trans_date |\n+------+---------+----------+--------+------------+\n| 121  | US      | approved | 1000   | 2018-12-18 |\n| 122  | US      | declined | 2000   | 2018-12-19 |\n| 123  | US      | approved | 2000   | 2019-01-01 |\n| 124  | DE      | approved | 2000   | 2019-01-07 |\n+------+---------+----------+--------+------------+\n\nResult table:\n+----------+---------+-------------+----------------+--------------------+-----------------------+\n| month    | country | trans_count | approved_count | trans_total_amount | approved_total_amount |\n+----------+---------+-------------+----------------+--------------------+-----------------------+\n| 2018-12  | US      | 2           | 1              | 3000               | 1000                  |\n| 2019-01  | US      | 1           | 1              | 2000               | 2000                  |\n| 2019-01  | DE      | 1           | 1              | 2000               | 2000                  |\n+----------+---------+-------------+----------------+--------------------+-----------------------+\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1193](https://leetcode-cn.com/problems/monthly-transactions-i)", "[\u6bcf\u6708\u4ea4\u6613 I](/solution/1100-1199/1193.Monthly%20Transactions%20I/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1193](https://leetcode.com/problems/monthly-transactions-i)", "[Monthly Transactions I](/solution/1100-1199/1193.Monthly%20Transactions%20I/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1316", "frontend_question_id": "1195", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/fizz-buzz-multithreaded", "url_en": "https://leetcode.com/problems/fizz-buzz-multithreaded", "relative_path_cn": "/solution/1100-1199/1195.Fizz%20Buzz%20Multithreaded/README.md", "relative_path_en": "/solution/1100-1199/1195.Fizz%20Buzz%20Multithreaded/README_EN.md", "title_cn": "\u4ea4\u66ff\u6253\u5370\u5b57\u7b26\u4e32", "title_en": "Fizz Buzz Multithreaded", "question_title_slug": "fizz-buzz-multithreaded", "content_en": "

Write a program that outputs the string representation of numbers from 1 to n, however:

\n\n
    \n\t
  • If the number is divisible by 3, output "fizz".
  • \n\t
  • If the number is divisible by 5, output "buzz".
  • \n\t
  • If the number is divisible by both 3 and 5, output "fizzbuzz".
  • \n
\n\n

For example, for n = 15, we output: 1, 2, fizz, 4, buzz, fizz, 7, 8, fizz, buzz, 11, fizz, 13, 14, fizzbuzz.

\n\n

Suppose you are given the following code:

\n\n
\nclass FizzBuzz {\n  public FizzBuzz(int n) { ... }               // constructor\n  public void fizz(printFizz) { ... }          // only output "fizz"\n  public void buzz(printBuzz) { ... }          // only output "buzz"\n  public void fizzbuzz(printFizzBuzz) { ... }  // only output "fizzbuzz"\n  public void number(printNumber) { ... }      // only output the numbers\n}
\n\n

Implement a multithreaded version of FizzBuzz with four threads. The same instance of FizzBuzz will be passed to four different threads:

\n\n
    \n\t
  1. Thread A will call fizz() to check for divisibility of 3 and outputs fizz.
  2. \n\t
  3. Thread B will call buzz() to check for divisibility of 5 and outputs buzz.
  4. \n\t
  5. Thread C will call fizzbuzz() to check for divisibility of 3 and 5 and outputs fizzbuzz.
  6. \n\t
  7. Thread D will call number() which should only output the numbers.
  8. \n
\n", "content_cn": "

\u7f16\u5199\u4e00\u4e2a\u53ef\u4ee5\u4ece 1 \u5230 n \u8f93\u51fa\u4ee3\u8868\u8fd9\u4e2a\u6570\u5b57\u7684\u5b57\u7b26\u4e32\u7684\u7a0b\u5e8f\uff0c\u4f46\u662f\uff1a

\n\n
    \n\t
  • \u5982\u679c\u8fd9\u4e2a\u6570\u5b57\u53ef\u4ee5\u88ab 3 \u6574\u9664\uff0c\u8f93\u51fa \"fizz\"\u3002
  • \n\t
  • \u5982\u679c\u8fd9\u4e2a\u6570\u5b57\u53ef\u4ee5\u88ab 5 \u6574\u9664\uff0c\u8f93\u51fa\u00a0\"buzz\"\u3002
  • \n\t
  • \u5982\u679c\u8fd9\u4e2a\u6570\u5b57\u53ef\u4ee5\u540c\u65f6\u88ab 3 \u548c 5 \u6574\u9664\uff0c\u8f93\u51fa \"fizzbuzz\"\u3002
  • \n
\n\n

\u4f8b\u5982\uff0c\u5f53\u00a0n = 15\uff0c\u8f93\u51fa\uff1a\u00a01, 2, fizz, 4, buzz, fizz, 7, 8, fizz, buzz, 11, fizz, 13, 14, fizzbuzz\u3002

\n\n

\u5047\u8bbe\u6709\u8fd9\u4e48\u4e00\u4e2a\u7c7b\uff1a

\n\n
\nclass FizzBuzz {\n\u00a0 public FizzBuzz(int n) { ... }\u00a0              // constructor\n  public void fizz(printFizz) { ... }          // only output \"fizz\"\n  public void buzz(printBuzz) { ... }          // only output \"buzz\"\n  public void fizzbuzz(printFizzBuzz) { ... }  // only output \"fizzbuzz\"\n  public void number(printNumber) { ... }      // only output the numbers\n}
\n\n

\u8bf7\u4f60\u5b9e\u73b0\u4e00\u4e2a\u6709\u56db\u4e2a\u7ebf\u7a0b\u7684\u591a\u7ebf\u7a0b\u7248\u00a0\u00a0FizzBuzz\uff0c\u00a0\u540c\u4e00\u4e2a\u00a0FizzBuzz\u00a0\u5b9e\u4f8b\u4f1a\u88ab\u5982\u4e0b\u56db\u4e2a\u7ebf\u7a0b\u4f7f\u7528\uff1a

\n\n
    \n\t
  1. \u7ebf\u7a0bA\u5c06\u8c03\u7528\u00a0fizz()\u00a0\u6765\u5224\u65ad\u662f\u5426\u80fd\u88ab 3 \u6574\u9664\uff0c\u5982\u679c\u53ef\u4ee5\uff0c\u5219\u8f93\u51fa\u00a0fizz\u3002
  2. \n\t
  3. \u7ebf\u7a0bB\u5c06\u8c03\u7528\u00a0buzz()\u00a0\u6765\u5224\u65ad\u662f\u5426\u80fd\u88ab 5 \u6574\u9664\uff0c\u5982\u679c\u53ef\u4ee5\uff0c\u5219\u8f93\u51fa\u00a0buzz\u3002
  4. \n\t
  5. \u7ebf\u7a0bC\u5c06\u8c03\u7528\u00a0fizzbuzz()\u00a0\u6765\u5224\u65ad\u662f\u5426\u540c\u65f6\u80fd\u88ab 3 \u548c 5 \u6574\u9664\uff0c\u5982\u679c\u53ef\u4ee5\uff0c\u5219\u8f93\u51fa\u00a0fizzbuzz\u3002
  6. \n\t
  7. \u7ebf\u7a0bD\u5c06\u8c03\u7528\u00a0number()\u00a0\u6765\u5b9e\u73b0\u8f93\u51fa\u65e2\u4e0d\u80fd\u88ab 3 \u6574\u9664\u4e5f\u4e0d\u80fd\u88ab 5 \u6574\u9664\u7684\u6570\u5b57\u3002
  8. \n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u672c\u9898\u5df2\u7ecf\u63d0\u4f9b\u4e86\u6253\u5370\u5b57\u7b26\u4e32\u7684\u76f8\u5173\u65b9\u6cd5\uff0c\u5982 printFizz() \u7b49\uff0c\u5177\u4f53\u65b9\u6cd5\u540d\u8bf7\u53c2\u8003\u7b54\u9898\u6a21\u677f\u4e2d\u7684\u6ce8\u91ca\u90e8\u5206\u3002
  • \n
\n\n

\u00a0

\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class FizzBuzz {\nprivate:\n int n;\n\npublic:\n FizzBuzz(int n) {\n this->n = n;\n }\n\n // printFizz() outputs \"fizz\".\n void fizz(function printFizz) {\n \n }\n\n // printBuzz() outputs \"buzz\".\n void buzz(function printBuzz) {\n \n }\n\n // printFizzBuzz() outputs \"fizzbuzz\".\n\tvoid fizzbuzz(function printFizzBuzz) {\n \n }\n\n // printNumber(x) outputs \"x\", where x is an integer.\n void number(function printNumber) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class FizzBuzz {\n private int n;\n\n public FizzBuzz(int n) {\n this.n = n;\n }\n\n // printFizz.run() outputs \"fizz\".\n public void fizz(Runnable printFizz) throws InterruptedException {\n \n }\n\n // printBuzz.run() outputs \"buzz\".\n public void buzz(Runnable printBuzz) throws InterruptedException {\n \n }\n\n // printFizzBuzz.run() outputs \"fizzbuzz\".\n public void fizzbuzz(Runnable printFizzBuzz) throws InterruptedException {\n \n }\n\n // printNumber.accept(x) outputs \"x\", where x is an integer.\n public void number(IntConsumer printNumber) throws InterruptedException {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class FizzBuzz(object):\n def __init__(self, n):\n self.n = n\n\n # printFizz() outputs \"fizz\"\n def fizz(self, printFizz):\n \"\"\"\n :type printFizz: method\n :rtype: void\n \"\"\"\n \t\n\n # printBuzz() outputs \"buzz\"\n def buzz(self, printBuzz):\n \"\"\"\n :type printBuzz: method\n :rtype: void\n \"\"\"\n \t\n\n # printFizzBuzz() outputs \"fizzbuzz\"\n def fizzbuzz(self, printFizzBuzz):\n \"\"\"\n :type printFizzBuzz: method\n :rtype: void\n \"\"\"\n \n\n # printNumber(x) outputs \"x\", where x is an integer.\n def number(self, printNumber):\n \"\"\"\n :type printNumber: method\n :rtype: void\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class FizzBuzz:\n def __init__(self, n: int):\n self.n = n\n\n # printFizz() outputs \"fizz\"\n def fizz(self, printFizz: 'Callable[[], None]') -> None:\n \t\n\n # printBuzz() outputs \"buzz\"\n def buzz(self, printBuzz: 'Callable[[], None]') -> None:\n \t\n\n # printFizzBuzz() outputs \"fizzbuzz\"\n def fizzbuzz(self, printFizzBuzz: 'Callable[[], None]') -> None:\n \n\n # printNumber(x) outputs \"x\", where x is an integer.\n def number(self, printNumber: 'Callable[[int], None]') -> None:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "typedef struct {\n int n;\n} FizzBuzz;\n\nFizzBuzz* fizzBuzzCreate(int n) {\n FizzBuzz* obj = (FizzBuzz*) malloc(sizeof(FizzBuzz));\n obj->n = n;\n return obj;\n}\n\n// printFizz() outputs \"fizz\".\nvoid fizz(FizzBuzz* obj) {\n \n}\n\n// printBuzz() outputs \"buzz\".\nvoid buzz(FizzBuzz* obj) {\n \n}\n\n// printFizzBuzz() outputs \"fizzbuzz\".\nvoid fizzbuzz(FizzBuzz* obj) {\n \n}\n\n// You may call global function `void printNumber(int x)`\n// to output \"x\", where x is an integer.\nvoid number(FizzBuzz* obj) {\n \n}\n\nvoid fizzBuzzFree(FizzBuzz* obj) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class FizzBuzz {\n private int n;\n\n public FizzBuzz(int n) {\n this.n = n;\n }\n\n // printFizz() outputs \"fizz\".\n public void Fizz(Action printFizz) {\n \n }\n\n // printBuzzz() outputs \"buzz\".\n public void Buzz(Action printBuzz) {\n \n }\n\n // printFizzBuzz() outputs \"fizzbuzz\".\n public void Fizzbuzz(Action printFizzBuzz) {\n \n }\n\n // printNumber(x) outputs \"x\", where x is an integer.\n public void Number(Action printNumber) {\n \n }\n}", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1195](https://leetcode-cn.com/problems/fizz-buzz-multithreaded)", "[\u4ea4\u66ff\u6253\u5370\u5b57\u7b26\u4e32](/solution/1100-1199/1195.Fizz%20Buzz%20Multithreaded/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1195](https://leetcode.com/problems/fizz-buzz-multithreaded)", "[Fizz Buzz Multithreaded](/solution/1100-1199/1195.Fizz%20Buzz%20Multithreaded/README_EN.md)", "", "Medium", ""]}, {"question_id": "1309", "frontend_question_id": "1203", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sort-items-by-groups-respecting-dependencies", "url_en": "https://leetcode.com/problems/sort-items-by-groups-respecting-dependencies", "relative_path_cn": "/solution/1200-1299/1203.Sort%20Items%20by%20Groups%20Respecting%20Dependencies/README.md", "relative_path_en": "/solution/1200-1299/1203.Sort%20Items%20by%20Groups%20Respecting%20Dependencies/README_EN.md", "title_cn": "\u9879\u76ee\u7ba1\u7406", "title_en": "Sort Items by Groups Respecting Dependencies", "question_title_slug": "sort-items-by-groups-respecting-dependencies", "content_en": "

There are n items each belonging to zero or one of m groups where group[i] is the group that the i-th item belongs to and it's equal to -1 if the i-th item belongs to no group. The items and the groups are zero indexed. A group can have no item belonging to it.

\n\n

Return a sorted list of the items such that:

\n\n
    \n\t
  • The items that belong to the same group are next to each other in the sorted list.
  • \n\t
  • There are some relations between these items where beforeItems[i] is a list containing all the items that should come before the i-th item in the sorted array (to the left of the i-th item).
  • \n
\n\n

Return any solution if there is more than one solution and return an empty list if there is no solution.

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: n = 8, m = 2, group = [-1,-1,1,0,0,1,0,-1], beforeItems = [[],[6],[5],[6],[3,6],[],[],[]]\nOutput: [6,3,4,1,5,2,0,7]\n
\n\n

Example 2:

\n\n
\nInput: n = 8, m = 2, group = [-1,-1,1,0,0,1,0,-1], beforeItems = [[],[6],[5],[6],[3],[],[4],[]]\nOutput: []\nExplanation: This is the same as example 1 except that 4 needs to be before 6 in the sorted list.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= m <= n <= 3 * 104
  • \n\t
  • group.length == beforeItems.length == n
  • \n\t
  • -1 <= group[i] <= m - 1
  • \n\t
  • 0 <= beforeItems[i].length <= n - 1
  • \n\t
  • 0 <= beforeItems[i][j] <= n - 1
  • \n\t
  • i != beforeItems[i][j]
  • \n\t
  • beforeItems[i] does not contain duplicates elements.
  • \n
\n", "content_cn": "

\u6709 n \u4e2a\u9879\u76ee\uff0c\u6bcf\u4e2a\u9879\u76ee\u6216\u8005\u4e0d\u5c5e\u4e8e\u4efb\u4f55\u5c0f\u7ec4\uff0c\u6216\u8005\u5c5e\u4e8e m \u4e2a\u5c0f\u7ec4\u4e4b\u4e00\u3002group[i] \u8868\u793a\u7b2c i \u4e2a\u9879\u76ee\u6240\u5c5e\u7684\u5c0f\u7ec4\uff0c\u5982\u679c\u7b2c i \u4e2a\u9879\u76ee\u4e0d\u5c5e\u4e8e\u4efb\u4f55\u5c0f\u7ec4\uff0c\u5219 group[i] \u7b49\u4e8e -1\u3002\u9879\u76ee\u548c\u5c0f\u7ec4\u90fd\u662f\u4ece\u96f6\u5f00\u59cb\u7f16\u53f7\u7684\u3002\u53ef\u80fd\u5b58\u5728\u5c0f\u7ec4\u4e0d\u8d1f\u8d23\u4efb\u4f55\u9879\u76ee\uff0c\u5373\u6ca1\u6709\u4efb\u4f55\u9879\u76ee\u5c5e\u4e8e\u8fd9\u4e2a\u5c0f\u7ec4\u3002

\n\n

\u8bf7\u4f60\u5e2e\u5fd9\u6309\u8981\u6c42\u5b89\u6392\u8fd9\u4e9b\u9879\u76ee\u7684\u8fdb\u5ea6\uff0c\u5e76\u8fd4\u56de\u6392\u5e8f\u540e\u7684\u9879\u76ee\u5217\u8868\uff1a

\n\n
    \n\t
  • \u540c\u4e00\u5c0f\u7ec4\u7684\u9879\u76ee\uff0c\u6392\u5e8f\u540e\u5728\u5217\u8868\u4e2d\u5f7c\u6b64\u76f8\u90bb\u3002
  • \n\t
  • \u9879\u76ee\u4e4b\u95f4\u5b58\u5728\u4e00\u5b9a\u7684\u4f9d\u8d56\u5173\u7cfb\uff0c\u6211\u4eec\u7528\u4e00\u4e2a\u5217\u8868 beforeItems\u00a0\u6765\u8868\u793a\uff0c\u5176\u4e2d\u00a0beforeItems[i]\u00a0\u8868\u793a\u5728\u8fdb\u884c\u7b2c\u00a0i\u00a0\u4e2a\u9879\u76ee\u524d\uff08\u4f4d\u4e8e\u7b2c i\u00a0\u4e2a\u9879\u76ee\u5de6\u4fa7\uff09\u5e94\u8be5\u5b8c\u6210\u7684\u6240\u6709\u9879\u76ee\u3002
  • \n
\n\n

\u5982\u679c\u5b58\u5728\u591a\u4e2a\u89e3\u51b3\u65b9\u6848\uff0c\u53ea\u9700\u8981\u8fd4\u56de\u5176\u4e2d\u4efb\u610f\u4e00\u4e2a\u5373\u53ef\u3002\u5982\u679c\u6ca1\u6709\u5408\u9002\u7684\u89e3\u51b3\u65b9\u6848\uff0c\u5c31\u8bf7\u8fd4\u56de\u4e00\u4e2a \u7a7a\u5217\u8868 \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1an = 8, m = 2, group = [-1,-1,1,0,0,1,0,-1], beforeItems = [[],[6],[5],[6],[3,6],[],[],[]]\n\u8f93\u51fa\uff1a[6,3,4,1,5,2,0,7]\n
\n\n

\u793a\u4f8b\u00a02\uff1a

\n\n
\n\u8f93\u5165\uff1an = 8, m = 2, group = [-1,-1,1,0,0,1,0,-1], beforeItems = [[],[6],[5],[6],[3],[],[4],[]]\n\u8f93\u51fa\uff1a[]\n\u89e3\u91ca\uff1a\u4e0e\u793a\u4f8b 1 \u5927\u81f4\u76f8\u540c\uff0c\u4f46\u662f\u5728\u6392\u5e8f\u540e\u7684\u5217\u8868\u4e2d\uff0c4 \u5fc5\u987b\u653e\u5728 6 \u7684\u524d\u9762\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= m <= n <= 3 * 104
  • \n\t
  • group.length == beforeItems.length == n
  • \n\t
  • -1 <= group[i] <= m - 1
  • \n\t
  • 0 <= beforeItems[i].length <= n - 1
  • \n\t
  • 0 <= beforeItems[i][j] <= n - 1
  • \n\t
  • i != beforeItems[i][j]
  • \n\t
  • beforeItems[i] \u4e0d\u542b\u91cd\u590d\u5143\u7d20
  • \n
\n", "tags_en": ["Depth-first Search", "Graph", "Topological Sort"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u56fe", "\u62d3\u6251\u6392\u5e8f"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector sortItems(int n, int m, vector& group, vector>& beforeItems) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] sortItems(int n, int m, int[] group, List> beforeItems) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def sortItems(self, n, m, group, beforeItems):\n \"\"\"\n :type n: int\n :type m: int\n :type group: List[int]\n :type beforeItems: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def sortItems(self, n: int, m: int, group: List[int], beforeItems: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* sortItems(int n, int m, int* group, int groupSize, int** beforeItems, int beforeItemsSize, int* beforeItemsColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] SortItems(int n, int m, int[] group, IList> beforeItems) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} m\n * @param {number[]} group\n * @param {number[][]} beforeItems\n * @return {number[]}\n */\nvar sortItems = function(n, m, group, beforeItems) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} m\n# @param {Integer[]} group\n# @param {Integer[][]} before_items\n# @return {Integer[]}\ndef sort_items(n, m, group, before_items)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func sortItems(_ n: Int, _ m: Int, _ group: [Int], _ beforeItems: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func sortItems(n int, m int, group []int, beforeItems [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def sortItems(n: Int, m: Int, group: Array[Int], beforeItems: List[List[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun sortItems(n: Int, m: Int, group: IntArray, beforeItems: List>): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sort_items(n: i32, m: i32, group: Vec, before_items: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $m\n * @param Integer[] $group\n * @param Integer[][] $beforeItems\n * @return Integer[]\n */\n function sortItems($n, $m, $group, $beforeItems) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function sortItems(n: number, m: number, group: number[], beforeItems: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (sort-items n m group beforeItems)\n (-> exact-integer? exact-integer? (listof exact-integer?) (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1203](https://leetcode-cn.com/problems/sort-items-by-groups-respecting-dependencies)", "[\u9879\u76ee\u7ba1\u7406](/solution/1200-1299/1203.Sort%20Items%20by%20Groups%20Respecting%20Dependencies/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u56fe`,`\u62d3\u6251\u6392\u5e8f`", "\u56f0\u96be", ""], "md_table_row_en": ["[1203](https://leetcode.com/problems/sort-items-by-groups-respecting-dependencies)", "[Sort Items by Groups Respecting Dependencies](/solution/1200-1299/1203.Sort%20Items%20by%20Groups%20Respecting%20Dependencies/README_EN.md)", "`Depth-first Search`,`Graph`,`Topological Sort`", "Hard", ""]}, {"question_id": "1308", "frontend_question_id": "1202", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/smallest-string-with-swaps", "url_en": "https://leetcode.com/problems/smallest-string-with-swaps", "relative_path_cn": "/solution/1200-1299/1202.Smallest%20String%20With%20Swaps/README.md", "relative_path_en": "/solution/1200-1299/1202.Smallest%20String%20With%20Swaps/README_EN.md", "title_cn": "\u4ea4\u6362\u5b57\u7b26\u4e32\u4e2d\u7684\u5143\u7d20", "title_en": "Smallest String With Swaps", "question_title_slug": "smallest-string-with-swaps", "content_en": "

You are given a string s, and an array of pairs of indices in the string pairs where pairs[i] = [a, b] indicates 2 indices(0-indexed) of the string.

\n\n

You can swap the characters at any pair of indices in the given pairs any number of times.

\n\n

Return the lexicographically smallest string that s can be changed to after using the swaps.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "dcab", pairs = [[0,3],[1,2]]\nOutput: "bacd"\nExplaination: \nSwap s[0] and s[3], s = "bcad"\nSwap s[1] and s[2], s = "bacd"\n
\n\n

Example 2:

\n\n
\nInput: s = "dcab", pairs = [[0,3],[1,2],[0,2]]\nOutput: "abcd"\nExplaination: \nSwap s[0] and s[3], s = "bcad"\nSwap s[0] and s[2], s = "acbd"\nSwap s[1] and s[2], s = "abcd"
\n\n

Example 3:

\n\n
\nInput: s = "cba", pairs = [[0,1],[1,2]]\nOutput: "abc"\nExplaination: \nSwap s[0] and s[1], s = "bca"\nSwap s[1] and s[2], s = "bac"\nSwap s[0] and s[1], s = "abc"\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 10^5
  • \n\t
  • 0 <= pairs.length <= 10^5
  • \n\t
  • 0 <= pairs[i][0], pairs[i][1] < s.length
  • \n\t
  • s only contains lower case English letters.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s\uff0c\u4ee5\u53ca\u8be5\u5b57\u7b26\u4e32\u4e2d\u7684\u4e00\u4e9b\u300c\u7d22\u5f15\u5bf9\u300d\u6570\u7ec4 pairs\uff0c\u5176\u4e2d pairs[i] = [a, b] \u8868\u793a\u5b57\u7b26\u4e32\u4e2d\u7684\u4e24\u4e2a\u7d22\u5f15\uff08\u7f16\u53f7\u4ece 0 \u5f00\u59cb\uff09\u3002

\n\n

\u4f60\u53ef\u4ee5 \u4efb\u610f\u591a\u6b21\u4ea4\u6362 \u5728 pairs \u4e2d\u4efb\u610f\u4e00\u5bf9\u7d22\u5f15\u5904\u7684\u5b57\u7b26\u3002

\n\n

\u8fd4\u56de\u5728\u7ecf\u8fc7\u82e5\u5e72\u6b21\u4ea4\u6362\u540e\uff0cs \u53ef\u4ee5\u53d8\u6210\u7684\u6309\u5b57\u5178\u5e8f\u6700\u5c0f\u7684\u5b57\u7b26\u4e32\u3002

\n\n

 

\n\n

\u793a\u4f8b 1:

\n\n
\u8f93\u5165\uff1as = "dcab", pairs = [[0,3],[1,2]]\n\u8f93\u51fa\uff1a"bacd"\n\u89e3\u91ca\uff1a \n\u4ea4\u6362 s[0] \u548c s[3], s = "bcad"\n\u4ea4\u6362 s[1] \u548c s[2], s = "bacd"\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1as = "dcab", pairs = [[0,3],[1,2],[0,2]]\n\u8f93\u51fa\uff1a"abcd"\n\u89e3\u91ca\uff1a\n\u4ea4\u6362 s[0] \u548c s[3], s = "bcad"\n\u4ea4\u6362 s[0] \u548c s[2], s = "acbd"\n\u4ea4\u6362 s[1] \u548c s[2], s = "abcd"
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1as = "cba", pairs = [[0,1],[1,2]]\n\u8f93\u51fa\uff1a"abc"\n\u89e3\u91ca\uff1a\n\u4ea4\u6362 s[0] \u548c s[1], s = "bca"\n\u4ea4\u6362 s[1] \u548c s[2], s = "bac"\n\u4ea4\u6362 s[0] \u548c s[1], s = "abc"\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length <= 10^5
  • \n\t
  • 0 <= pairs.length <= 10^5
  • \n\t
  • 0 <= pairs[i][0], pairs[i][1] < s.length
  • \n\t
  • s \u4e2d\u53ea\u542b\u6709\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd
  • \n
\n", "tags_en": ["Union Find", "Array"], "tags_cn": ["\u5e76\u67e5\u96c6", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string smallestStringWithSwaps(string s, vector>& pairs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String smallestStringWithSwaps(String s, List> pairs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def smallestStringWithSwaps(self, s, pairs):\n \"\"\"\n :type s: str\n :type pairs: List[List[int]]\n :rtype: str\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def smallestStringWithSwaps(self, s: str, pairs: List[List[int]]) -> str:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * smallestStringWithSwaps(char * s, int** pairs, int pairsSize, int* pairsColSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string SmallestStringWithSwaps(string s, IList> pairs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number[][]} pairs\n * @return {string}\n */\nvar smallestStringWithSwaps = function(s, pairs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer[][]} pairs\n# @return {String}\ndef smallest_string_with_swaps(s, pairs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func smallestStringWithSwaps(_ s: String, _ pairs: [[Int]]) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func smallestStringWithSwaps(s string, pairs [][]int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def smallestStringWithSwaps(s: String, pairs: List[List[Int]]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun smallestStringWithSwaps(s: String, pairs: List>): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn smallest_string_with_swaps(s: String, pairs: Vec>) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer[][] $pairs\n * @return String\n */\n function smallestStringWithSwaps($s, $pairs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function smallestStringWithSwaps(s: string, pairs: number[][]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (smallest-string-with-swaps s pairs)\n (-> string? (listof (listof exact-integer?)) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1202](https://leetcode-cn.com/problems/smallest-string-with-swaps)", "[\u4ea4\u6362\u5b57\u7b26\u4e32\u4e2d\u7684\u5143\u7d20](/solution/1200-1299/1202.Smallest%20String%20With%20Swaps/README.md)", "`\u5e76\u67e5\u96c6`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1202](https://leetcode.com/problems/smallest-string-with-swaps)", "[Smallest String With Swaps](/solution/1200-1299/1202.Smallest%20String%20With%20Swaps/README_EN.md)", "`Union Find`,`Array`", "Medium", ""]}, {"question_id": "1307", "frontend_question_id": "1201", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/ugly-number-iii", "url_en": "https://leetcode.com/problems/ugly-number-iii", "relative_path_cn": "/solution/1200-1299/1201.Ugly%20Number%20III/README.md", "relative_path_en": "/solution/1200-1299/1201.Ugly%20Number%20III/README_EN.md", "title_cn": "\u4e11\u6570 III", "title_en": "Ugly Number III", "question_title_slug": "ugly-number-iii", "content_en": "

An ugly number is a positive integer that is divisible by a, b, or c.

\n\n

Given four integers n, a, b, and c, return the nth ugly number.

\n\n

 

\n

Example 1:

\n\n
\nInput: n = 3, a = 2, b = 3, c = 5\nOutput: 4\nExplanation: The ugly numbers are 2, 3, 4, 5, 6, 8, 9, 10... The 3rd is 4.\n
\n\n

Example 2:

\n\n
\nInput: n = 4, a = 2, b = 3, c = 4\nOutput: 6\nExplanation: The ugly numbers are 2, 3, 4, 6, 8, 9, 10, 12... The 4th is 6.\n
\n\n

Example 3:

\n\n
\nInput: n = 5, a = 2, b = 11, c = 13\nOutput: 10\nExplanation: The ugly numbers are 2, 4, 6, 8, 10, 11, 12, 13... The 5th is 10.\n
\n\n

Example 4:

\n\n
\nInput: n = 1000000000, a = 2, b = 217983653, c = 336916467\nOutput: 1999999984\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n, a, b, c <= 109
  • \n\t
  • 1 <= a * b * c <= 1018
  • \n\t
  • It is guaranteed that the result will be in range [1, 2 * 109].
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u56db\u4e2a\u6574\u6570\uff1an \u3001a \u3001b \u3001c \uff0c\u8bf7\u4f60\u8bbe\u8ba1\u4e00\u4e2a\u7b97\u6cd5\u6765\u627e\u51fa\u7b2c\u00a0n\u00a0\u4e2a\u4e11\u6570\u3002

\n\n

\u4e11\u6570\u662f\u53ef\u4ee5\u88ab\u00a0a\u00a0\u6216\u00a0b\u00a0\u6216 c\u00a0\u6574\u9664\u7684 \u6b63\u6574\u6570 \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1an = 3, a = 2, b = 3, c = 5\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u4e11\u6570\u5e8f\u5217\u4e3a 2, 3, 4, 5, 6, 8, 9, 10... \u5176\u4e2d\u7b2c 3 \u4e2a\u662f 4\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1an = 4, a = 2, b = 3, c = 4\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u4e11\u6570\u5e8f\u5217\u4e3a 2, 3, 4, 6, 8, 9, 10, 12... \u5176\u4e2d\u7b2c 4 \u4e2a\u662f 6\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1an = 5, a = 2, b = 11, c = 13\n\u8f93\u51fa\uff1a10\n\u89e3\u91ca\uff1a\u4e11\u6570\u5e8f\u5217\u4e3a 2, 4, 6, 8, 10, 11, 12, 13... \u5176\u4e2d\u7b2c 5 \u4e2a\u662f 10\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1an = 1000000000, a = 2, b = 217983653, c = 336916467\n\u8f93\u51fa\uff1a1999999984\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n, a, b, c <= 10^9
  • \n\t
  • 1 <= a * b * c <= 10^18
  • \n\t
  • \u672c\u9898\u7ed3\u679c\u5728\u00a0[1,\u00a02 * 10^9]\u00a0\u7684\u8303\u56f4\u5185
  • \n
\n", "tags_en": ["Math", "Binary Search"], "tags_cn": ["\u6570\u5b66", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int nthUglyNumber(int n, int a, int b, int c) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int nthUglyNumber(int n, int a, int b, int c) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def nthUglyNumber(self, n, a, b, c):\n \"\"\"\n :type n: int\n :type a: int\n :type b: int\n :type c: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def nthUglyNumber(self, n: int, a: int, b: int, c: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint nthUglyNumber(int n, int a, int b, int c){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NthUglyNumber(int n, int a, int b, int c) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} a\n * @param {number} b\n * @param {number} c\n * @return {number}\n */\nvar nthUglyNumber = function(n, a, b, c) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} a\n# @param {Integer} b\n# @param {Integer} c\n# @return {Integer}\ndef nth_ugly_number(n, a, b, c)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func nthUglyNumber(_ n: Int, _ a: Int, _ b: Int, _ c: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func nthUglyNumber(n int, a int, b int, c int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def nthUglyNumber(n: Int, a: Int, b: Int, c: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun nthUglyNumber(n: Int, a: Int, b: Int, c: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn nth_ugly_number(n: i32, a: i32, b: i32, c: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $a\n * @param Integer $b\n * @param Integer $c\n * @return Integer\n */\n function nthUglyNumber($n, $a, $b, $c) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function nthUglyNumber(n: number, a: number, b: number, c: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (nth-ugly-number n a b c)\n (-> exact-integer? exact-integer? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1201](https://leetcode-cn.com/problems/ugly-number-iii)", "[\u4e11\u6570 III](/solution/1200-1299/1201.Ugly%20Number%20III/README.md)", "`\u6570\u5b66`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1201](https://leetcode.com/problems/ugly-number-iii)", "[Ugly Number III](/solution/1200-1299/1201.Ugly%20Number%20III/README_EN.md)", "`Math`,`Binary Search`", "Medium", ""]}, {"question_id": "1306", "frontend_question_id": "1200", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-absolute-difference", "url_en": "https://leetcode.com/problems/minimum-absolute-difference", "relative_path_cn": "/solution/1200-1299/1200.Minimum%20Absolute%20Difference/README.md", "relative_path_en": "/solution/1200-1299/1200.Minimum%20Absolute%20Difference/README_EN.md", "title_cn": "\u6700\u5c0f\u7edd\u5bf9\u5dee", "title_en": "Minimum Absolute Difference", "question_title_slug": "minimum-absolute-difference", "content_en": "

Given an array of distinct integers arr, find all pairs of elements with the minimum absolute difference of any two elements. 

\n\n

Return a list of pairs in ascending order(with respect to pairs), each pair [a, b] follows

\n\n
    \n\t
  • a, b are from arr
  • \n\t
  • a < b
  • \n\t
  • b - a equals to the minimum absolute difference of any two elements in arr
  • \n
\n\n

 

\n

Example 1:

\n\n
\nInput: arr = [4,2,1,3]\nOutput: [[1,2],[2,3],[3,4]]\nExplanation: The minimum absolute difference is 1. List all pairs with difference equal to 1 in ascending order.
\n\n

Example 2:

\n\n
\nInput: arr = [1,3,6,10,15]\nOutput: [[1,3]]\n
\n\n

Example 3:

\n\n
\nInput: arr = [3,8,-10,23,19,-4,-14,27]\nOutput: [[-14,-10],[19,23],[23,27]]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= arr.length <= 10^5
  • \n\t
  • -10^6 <= arr[i] <= 10^6
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e2a\u6574\u6570\u6570\u7ec4 arr\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5143\u7d20\u90fd \u4e0d\u76f8\u540c\u3002

\n\n

\u8bf7\u4f60\u627e\u5230\u6240\u6709\u5177\u6709\u6700\u5c0f\u7edd\u5bf9\u5dee\u7684\u5143\u7d20\u5bf9\uff0c\u5e76\u4e14\u6309\u5347\u5e8f\u7684\u987a\u5e8f\u8fd4\u56de\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aarr = [4,2,1,3]\n\u8f93\u51fa\uff1a[[1,2],[2,3],[3,4]]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aarr = [1,3,6,10,15]\n\u8f93\u51fa\uff1a[[1,3]]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aarr = [3,8,-10,23,19,-4,-14,27]\n\u8f93\u51fa\uff1a[[-14,-10],[19,23],[23,27]]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= arr.length <= 10^5
  • \n\t
  • -10^6 <= arr[i] <= 10^6
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> minimumAbsDifference(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> minimumAbsDifference(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimumAbsDifference(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: List[List[int]]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimumAbsDifference(self, arr: List[int]) -> List[List[int]]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** minimumAbsDifference(int* arr, int arrSize, int* returnSize, int** returnColumnSizes){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> MinimumAbsDifference(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number[][]}\n */\nvar minimumAbsDifference = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer[][]}\ndef minimum_abs_difference(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimumAbsDifference(_ arr: [Int]) -> [[Int]] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimumAbsDifference(arr []int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimumAbsDifference(arr: Array[Int]): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimumAbsDifference(arr: IntArray): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimum_abs_difference(arr: Vec) -> Vec> {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer[][]\n */\n function minimumAbsDifference($arr) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimumAbsDifference(arr: number[]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimum-abs-difference arr)\n (-> (listof exact-integer?) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1200](https://leetcode-cn.com/problems/minimum-absolute-difference)", "[\u6700\u5c0f\u7edd\u5bf9\u5dee](/solution/1200-1299/1200.Minimum%20Absolute%20Difference/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1200](https://leetcode.com/problems/minimum-absolute-difference)", "[Minimum Absolute Difference](/solution/1200-1299/1200.Minimum%20Absolute%20Difference/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1304", "frontend_question_id": "1405", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-happy-string", "url_en": "https://leetcode.com/problems/longest-happy-string", "relative_path_cn": "/solution/1400-1499/1405.Longest%20Happy%20String/README.md", "relative_path_en": "/solution/1400-1499/1405.Longest%20Happy%20String/README_EN.md", "title_cn": "\u6700\u957f\u5feb\u4e50\u5b57\u7b26\u4e32", "title_en": "Longest Happy String", "question_title_slug": "longest-happy-string", "content_en": "

A string is called happy if it does not have any of the strings 'aaa', 'bbb' or 'ccc' as a substring.

\n\n

Given three integers a, b and c, return any string s, which satisfies following conditions:

\n\n
    \n\t
  • s is happy and longest possible.
  • \n\t
  • s contains at most a occurrences of the letter 'a', at most b occurrences of the letter 'b' and at most c occurrences of the letter 'c'.
  • \n\t
  • will only contain 'a', 'b' and 'c' letters.
  • \n
\n\n

If there is no such string s return the empty string "".

\n\n

 

\n

Example 1:

\n\n
\nInput: a = 1, b = 1, c = 7\nOutput: "ccaccbcc"\nExplanation: "ccbccacc" would also be a correct answer.\n
\n\n

Example 2:

\n\n
\nInput: a = 2, b = 2, c = 1\nOutput: "aabbc"\n
\n\n

Example 3:

\n\n
\nInput: a = 7, b = 1, c = 0\nOutput: "aabaa"\nExplanation: It's the only correct answer in this case.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 0 <= a, b, c <= 100
  • \n\t
  • a + b + c > 0
  • \n
\n", "content_cn": "

\u5982\u679c\u5b57\u7b26\u4e32\u4e2d\u4e0d\u542b\u6709\u4efb\u4f55 'aaa'\uff0c'bbb' \u6216 'ccc' \u8fd9\u6837\u7684\u5b57\u7b26\u4e32\u4f5c\u4e3a\u5b50\u4e32\uff0c\u90a3\u4e48\u8be5\u5b57\u7b26\u4e32\u5c31\u662f\u4e00\u4e2a\u300c\u5feb\u4e50\u5b57\u7b26\u4e32\u300d\u3002

\n\n

\u7ed9\u4f60\u4e09\u4e2a\u6574\u6570 a\uff0cb \uff0cc\uff0c\u8bf7\u4f60\u8fd4\u56de \u4efb\u610f\u4e00\u4e2a \u6ee1\u8db3\u4e0b\u5217\u5168\u90e8\u6761\u4ef6\u7684\u5b57\u7b26\u4e32 s\uff1a

\n\n
    \n\t
  • s \u662f\u4e00\u4e2a\u5c3d\u53ef\u80fd\u957f\u7684\u5feb\u4e50\u5b57\u7b26\u4e32\u3002
  • \n\t
  • s \u4e2d \u6700\u591a \u6709a \u4e2a\u5b57\u6bcd 'a'\u3001b \u4e2a\u5b57\u6bcd 'b'\u3001c \u4e2a\u5b57\u6bcd 'c' \u3002
  • \n\t
  • s \u4e2d\u53ea\u542b\u6709 'a'\u3001'b' \u3001'c' \u4e09\u79cd\u5b57\u6bcd\u3002
  • \n
\n\n

\u5982\u679c\u4e0d\u5b58\u5728\u8fd9\u6837\u7684\u5b57\u7b26\u4e32 s \uff0c\u8bf7\u8fd4\u56de\u4e00\u4e2a\u7a7a\u5b57\u7b26\u4e32 ""\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aa = 1, b = 1, c = 7\n\u8f93\u51fa\uff1a"ccaccbcc"\n\u89e3\u91ca\uff1a"ccbccacc" \u4e5f\u662f\u4e00\u79cd\u6b63\u786e\u7b54\u6848\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aa = 2, b = 2, c = 1\n\u8f93\u51fa\uff1a"aabbc"\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aa = 7, b = 1, c = 0\n\u8f93\u51fa\uff1a"aabaa"\n\u89e3\u91ca\uff1a\u8fd9\u662f\u8be5\u6d4b\u8bd5\u7528\u4f8b\u7684\u552f\u4e00\u6b63\u786e\u7b54\u6848\u3002
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 0 <= a, b, c <= 100
  • \n\t
  • a + b + c > 0
  • \n
\n", "tags_en": ["Greedy", "Dynamic Programming"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string longestDiverseString(int a, int b, int c) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String longestDiverseString(int a, int b, int c) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestDiverseString(self, a, b, c):\n \"\"\"\n :type a: int\n :type b: int\n :type c: int\n :rtype: str\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestDiverseString(self, a: int, b: int, c: int) -> str:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * longestDiverseString(int a, int b, int c){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string LongestDiverseString(int a, int b, int c) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} a\n * @param {number} b\n * @param {number} c\n * @return {string}\n */\nvar longestDiverseString = function(a, b, c) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} a\n# @param {Integer} b\n# @param {Integer} c\n# @return {String}\ndef longest_diverse_string(a, b, c)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestDiverseString(_ a: Int, _ b: Int, _ c: Int) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestDiverseString(a int, b int, c int) string {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestDiverseString(a: Int, b: Int, c: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestDiverseString(a: Int, b: Int, c: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_diverse_string(a: i32, b: i32, c: i32) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $a\n * @param Integer $b\n * @param Integer $c\n * @return String\n */\n function longestDiverseString($a, $b, $c) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestDiverseString(a: number, b: number, c: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-diverse-string a b c)\n (-> exact-integer? exact-integer? exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1405](https://leetcode-cn.com/problems/longest-happy-string)", "[\u6700\u957f\u5feb\u4e50\u5b57\u7b26\u4e32](/solution/1400-1499/1405.Longest%20Happy%20String/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1405](https://leetcode.com/problems/longest-happy-string)", "[Longest Happy String](/solution/1400-1499/1405.Longest%20Happy%20String/README_EN.md)", "`Greedy`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "1301", "frontend_question_id": "1179", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reformat-department-table", "url_en": "https://leetcode.com/problems/reformat-department-table", "relative_path_cn": "/solution/1100-1199/1179.Reformat%20Department%20Table/README.md", "relative_path_en": "/solution/1100-1199/1179.Reformat%20Department%20Table/README_EN.md", "title_cn": "\u91cd\u65b0\u683c\u5f0f\u5316\u90e8\u95e8\u8868", "title_en": "Reformat Department Table", "question_title_slug": "reformat-department-table", "content_en": "

Table: Department

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| revenue       | int     |\n| month         | varchar |\n+---------------+---------+\n(id, month) is the primary key of this table.\nThe table has information about the revenue of each department per month.\nThe month has values in ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"].\n
\n\n

 

\n\n

Write an SQL query to reformat the table such that there is a department id column and a revenue column for each month.

\n\n

The query result format is in the following example:

\n\n
\nDepartment table:\n+------+---------+-------+\n| id   | revenue | month |\n+------+---------+-------+\n| 1    | 8000    | Jan   |\n| 2    | 9000    | Jan   |\n| 3    | 10000   | Feb   |\n| 1    | 7000    | Feb   |\n| 1    | 6000    | Mar   |\n+------+---------+-------+\n\nResult table:\n+------+-------------+-------------+-------------+-----+-------------+\n| id   | Jan_Revenue | Feb_Revenue | Mar_Revenue | ... | Dec_Revenue |\n+------+-------------+-------------+-------------+-----+-------------+\n| 1    | 8000        | 7000        | 6000        | ... | null        |\n| 2    | 9000        | null        | null        | ... | null        |\n| 3    | null        | 10000       | null        | ... | null        |\n+------+-------------+-------------+-------------+-----+-------------+\n\nNote that the result table has 13 columns (1 for the department id + 12 for the months).\n
\n", "content_cn": "

\u90e8\u95e8\u8868 Department\uff1a

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| revenue       | int     |\n| month         | varchar |\n+---------------+---------+\n(id, month) \u662f\u8868\u7684\u8054\u5408\u4e3b\u952e\u3002\n\u8fd9\u4e2a\u8868\u683c\u6709\u5173\u4e8e\u6bcf\u4e2a\u90e8\u95e8\u6bcf\u6708\u6536\u5165\u7684\u4fe1\u606f\u3002\n\u6708\u4efd\uff08month\uff09\u53ef\u4ee5\u53d6\u4e0b\u5217\u503c ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]\u3002\n
\n\n

 

\n\n

\u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\u6765\u91cd\u65b0\u683c\u5f0f\u5316\u8868\uff0c\u4f7f\u5f97\u65b0\u7684\u8868\u4e2d\u6709\u4e00\u4e2a\u90e8\u95e8 id \u5217\u548c\u4e00\u4e9b\u5bf9\u5e94 \u6bcf\u4e2a\u6708 \u7684\u6536\u5165\uff08revenue\uff09\u5217\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u9762\u7684\u793a\u4f8b\u6240\u793a\uff1a

\n\n
\nDepartment \u8868\uff1a\n+------+---------+-------+\n| id   | revenue | month |\n+------+---------+-------+\n| 1    | 8000    | Jan   |\n| 2    | 9000    | Jan   |\n| 3    | 10000   | Feb   |\n| 1    | 7000    | Feb   |\n| 1    | 6000    | Mar   |\n+------+---------+-------+\n\n\u67e5\u8be2\u5f97\u5230\u7684\u7ed3\u679c\u8868\uff1a\n+------+-------------+-------------+-------------+-----+-------------+\n| id   | Jan_Revenue | Feb_Revenue | Mar_Revenue | ... | Dec_Revenue |\n+------+-------------+-------------+-------------+-----+-------------+\n| 1    | 8000        | 7000        | 6000        | ... | null        |\n| 2    | 9000        | null        | null        | ... | null        |\n| 3    | null        | 10000       | null        | ... | null        |\n+------+-------------+-------------+-------------+-----+-------------+\n\n\u6ce8\u610f\uff0c\u7ed3\u679c\u8868\u6709 13 \u5217 (1\u4e2a\u90e8\u95e8 id \u5217 + 12\u4e2a\u6708\u4efd\u7684\u6536\u5165\u5217)\u3002\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1179](https://leetcode-cn.com/problems/reformat-department-table)", "[\u91cd\u65b0\u683c\u5f0f\u5316\u90e8\u95e8\u8868](/solution/1100-1199/1179.Reformat%20Department%20Table/README.md)", "", "\u7b80\u5355", ""], "md_table_row_en": ["[1179](https://leetcode.com/problems/reformat-department-table)", "[Reformat Department Table](/solution/1100-1199/1179.Reformat%20Department%20Table/README_EN.md)", "", "Easy", ""]}, {"question_id": "1300", "frontend_question_id": "1192", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/critical-connections-in-a-network", "url_en": "https://leetcode.com/problems/critical-connections-in-a-network", "relative_path_cn": "/solution/1100-1199/1192.Critical%20Connections%20in%20a%20Network/README.md", "relative_path_en": "/solution/1100-1199/1192.Critical%20Connections%20in%20a%20Network/README_EN.md", "title_cn": "\u67e5\u627e\u96c6\u7fa4\u5185\u7684\u300c\u5173\u952e\u8fde\u63a5\u300d", "title_en": "Critical Connections in a Network", "question_title_slug": "critical-connections-in-a-network", "content_en": "

There are n servers numbered from 0 to n - 1 connected by undirected server-to-server connections forming a network where connections[i] = [ai, bi] represents a connection between servers ai and bi. Any server can reach other servers directly or indirectly through the network.

\n\n

A critical connection is a connection that, if removed, will make some servers unable to reach some other server.

\n\n

Return all critical connections in the network in any order.

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: n = 4, connections = [[0,1],[1,2],[2,0],[1,3]]\nOutput: [[1,3]]\nExplanation: [[3,1]] is also accepted.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= n <= 105
  • \n\t
  • n - 1 <= connections.length <= 105
  • \n\t
  • 0 <= ai, bi <= n - 1
  • \n\t
  • ai != bi
  • \n\t
  • There are no repeated connections.
  • \n
\n", "content_cn": "

\u529b\u6263\u6570\u636e\u4e2d\u5fc3\u6709 n \u53f0\u670d\u52a1\u5668\uff0c\u5206\u522b\u6309\u4ece 0 \u5230 n-1 \u7684\u65b9\u5f0f\u8fdb\u884c\u4e86\u7f16\u53f7\u3002

\n\n

\u5b83\u4eec\u4e4b\u95f4\u4ee5\u300c\u670d\u52a1\u5668\u5230\u670d\u52a1\u5668\u300d\u70b9\u5bf9\u70b9\u7684\u5f62\u5f0f\u76f8\u4e92\u8fde\u63a5\u7ec4\u6210\u4e86\u4e00\u4e2a\u5185\u90e8\u96c6\u7fa4\uff0c\u5176\u4e2d\u8fde\u63a5 connections \u662f\u65e0\u5411\u7684\u3002

\n\n

\u4ece\u5f62\u5f0f\u4e0a\u8bb2\uff0cconnections[i] = [a, b] \u8868\u793a\u670d\u52a1\u5668 a \u548c b \u4e4b\u95f4\u5f62\u6210\u8fde\u63a5\u3002\u4efb\u4f55\u670d\u52a1\u5668\u90fd\u53ef\u4ee5\u76f4\u63a5\u6216\u8005\u95f4\u63a5\u5730\u901a\u8fc7\u7f51\u7edc\u5230\u8fbe\u4efb\u4f55\u5176\u4ed6\u670d\u52a1\u5668\u3002

\n\n

\u300c\u5173\u952e\u8fde\u63a5\u300d\u662f\u5728\u8be5\u96c6\u7fa4\u4e2d\u7684\u91cd\u8981\u8fde\u63a5\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u5047\u5982\u6211\u4eec\u5c06\u5b83\u79fb\u9664\uff0c\u4fbf\u4f1a\u5bfc\u81f4\u67d0\u4e9b\u670d\u52a1\u5668\u65e0\u6cd5\u8bbf\u95ee\u5176\u4ed6\u670d\u52a1\u5668\u3002

\n\n

\u8bf7\u4f60\u4ee5\u4efb\u610f\u987a\u5e8f\u8fd4\u56de\u8be5\u96c6\u7fa4\u5185\u7684\u6240\u6709 \u300c\u5173\u952e\u8fde\u63a5\u300d\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1an = 4, connections = [[0,1],[1,2],[2,0],[1,3]]\n\u8f93\u51fa\uff1a[[1,3]]\n\u89e3\u91ca\uff1a[[3,1]] \u4e5f\u662f\u6b63\u786e\u7684\u3002
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 10^5
  • \n\t
  • n-1 <= connections.length <= 10^5
  • \n\t
  • connections[i][0] != connections[i][1]
  • \n\t
  • \u4e0d\u5b58\u5728\u91cd\u590d\u7684\u8fde\u63a5
  • \n
\n", "tags_en": ["Depth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> criticalConnections(int n, vector>& connections) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> criticalConnections(int n, List> connections) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def criticalConnections(self, n, connections):\n \"\"\"\n :type n: int\n :type connections: List[List[int]]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def criticalConnections(self, n: int, connections: List[List[int]]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** criticalConnections(int n, int** connections, int connectionsSize, int* connectionsColSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> CriticalConnections(int n, IList> connections) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} connections\n * @return {number[][]}\n */\nvar criticalConnections = function(n, connections) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} connections\n# @return {Integer[][]}\ndef critical_connections(n, connections)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func criticalConnections(_ n: Int, _ connections: [[Int]]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func criticalConnections(n int, connections [][]int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def criticalConnections(n: Int, connections: List[List[Int]]): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun criticalConnections(n: Int, connections: List>): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn critical_connections(n: i32, connections: Vec>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $connections\n * @return Integer[][]\n */\n function criticalConnections($n, $connections) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function criticalConnections(n: number, connections: number[][]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (critical-connections n connections)\n (-> exact-integer? (listof (listof exact-integer?)) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1192](https://leetcode-cn.com/problems/critical-connections-in-a-network)", "[\u67e5\u627e\u96c6\u7fa4\u5185\u7684\u300c\u5173\u952e\u8fde\u63a5\u300d](/solution/1100-1199/1192.Critical%20Connections%20in%20a%20Network/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[1192](https://leetcode.com/problems/critical-connections-in-a-network)", "[Critical Connections in a Network](/solution/1100-1199/1192.Critical%20Connections%20in%20a%20Network/README_EN.md)", "`Depth-first Search`", "Hard", ""]}, {"question_id": "1299", "frontend_question_id": "1191", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/k-concatenation-maximum-sum", "url_en": "https://leetcode.com/problems/k-concatenation-maximum-sum", "relative_path_cn": "/solution/1100-1199/1191.K-Concatenation%20Maximum%20Sum/README.md", "relative_path_en": "/solution/1100-1199/1191.K-Concatenation%20Maximum%20Sum/README_EN.md", "title_cn": "K \u6b21\u4e32\u8054\u540e\u6700\u5927\u5b50\u6570\u7ec4\u4e4b\u548c", "title_en": "K-Concatenation Maximum Sum", "question_title_slug": "k-concatenation-maximum-sum", "content_en": "

Given an integer array arr and an integer k, modify the array by repeating it k times.

\n\n

For example, if arr = [1, 2] and k = 3 then the modified array will be [1, 2, 1, 2, 1, 2].

\n\n

Return the maximum sub-array sum in the modified array. Note that the length of the sub-array can be 0 and its sum in that case is 0.

\n\n

As the answer can be very large, return the answer modulo 109 + 7.

\n\n

 

\n

Example 1:

\n\n
\nInput: arr = [1,2], k = 3\nOutput: 9\n
\n\n

Example 2:

\n\n
\nInput: arr = [1,-2,1], k = 5\nOutput: 2\n
\n\n

Example 3:

\n\n
\nInput: arr = [-1,-2], k = 7\nOutput: 0\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= arr.length <= 105
  • \n\t
  • 1 <= k <= 105
  • \n\t
  • -104 <= arr[i] <= 104
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr \u548c\u4e00\u4e2a\u6574\u6570 k\u3002

\n\n

\u9996\u5148\uff0c\u6211\u4eec\u8981\u5bf9\u8be5\u6570\u7ec4\u8fdb\u884c\u4fee\u6539\uff0c\u5373\u628a\u539f\u6570\u7ec4 arr \u91cd\u590d k \u6b21\u3002

\n\n
\n

\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u5982\u679c arr = [1, 2] \u4e14 k = 3\uff0c\u90a3\u4e48\u4fee\u6539\u540e\u7684\u6570\u7ec4\u5c31\u662f [1, 2, 1, 2, 1, 2]\u3002

\n
\n\n

\u7136\u540e\uff0c\u8bf7\u4f60\u8fd4\u56de\u4fee\u6539\u540e\u7684\u6570\u7ec4\u4e2d\u7684\u6700\u5927\u7684\u5b50\u6570\u7ec4\u4e4b\u548c\u3002

\n\n

\u6ce8\u610f\uff0c\u5b50\u6570\u7ec4\u957f\u5ea6\u53ef\u4ee5\u662f 0\uff0c\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\u5b83\u7684\u603b\u548c\u4e5f\u662f 0\u3002

\n\n

\u7531\u4e8e \u7ed3\u679c\u53ef\u80fd\u4f1a\u5f88\u5927\uff0c\u6240\u4ee5\u9700\u8981 \u6a21\uff08mod\uff09 10^9 + 7 \u540e\u518d\u8fd4\u56de\u3002 

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aarr = [1,2], k = 3\n\u8f93\u51fa\uff1a9\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aarr = [1,-2,1], k = 5\n\u8f93\u51fa\uff1a2\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aarr = [-1,-2], k = 7\n\u8f93\u51fa\uff1a0\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= arr.length <= 10^5
  • \n\t
  • 1 <= k <= 10^5
  • \n\t
  • -10^4 <= arr[i] <= 10^4
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int kConcatenationMaxSum(vector& arr, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int kConcatenationMaxSum(int[] arr, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def kConcatenationMaxSum(self, arr, k):\n \"\"\"\n :type arr: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def kConcatenationMaxSum(self, arr: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint kConcatenationMaxSum(int* arr, int arrSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int KConcatenationMaxSum(int[] arr, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @param {number} k\n * @return {number}\n */\nvar kConcatenationMaxSum = function(arr, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @param {Integer} k\n# @return {Integer}\ndef k_concatenation_max_sum(arr, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func kConcatenationMaxSum(_ arr: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func kConcatenationMaxSum(arr []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def kConcatenationMaxSum(arr: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun kConcatenationMaxSum(arr: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn k_concatenation_max_sum(arr: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @param Integer $k\n * @return Integer\n */\n function kConcatenationMaxSum($arr, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function kConcatenationMaxSum(arr: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (k-concatenation-max-sum arr k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1191](https://leetcode-cn.com/problems/k-concatenation-maximum-sum)", "[K \u6b21\u4e32\u8054\u540e\u6700\u5927\u5b50\u6570\u7ec4\u4e4b\u548c](/solution/1100-1199/1191.K-Concatenation%20Maximum%20Sum/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1191](https://leetcode.com/problems/k-concatenation-maximum-sum)", "[K-Concatenation Maximum Sum](/solution/1100-1199/1191.K-Concatenation%20Maximum%20Sum/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "1298", "frontend_question_id": "1190", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reverse-substrings-between-each-pair-of-parentheses", "url_en": "https://leetcode.com/problems/reverse-substrings-between-each-pair-of-parentheses", "relative_path_cn": "/solution/1100-1199/1190.Reverse%20Substrings%20Between%20Each%20Pair%20of%20Parentheses/README.md", "relative_path_en": "/solution/1100-1199/1190.Reverse%20Substrings%20Between%20Each%20Pair%20of%20Parentheses/README_EN.md", "title_cn": "\u53cd\u8f6c\u6bcf\u5bf9\u62ec\u53f7\u95f4\u7684\u5b50\u4e32", "title_en": "Reverse Substrings Between Each Pair of Parentheses", "question_title_slug": "reverse-substrings-between-each-pair-of-parentheses", "content_en": "

You are given a string s that consists of lower case English letters and brackets. 

\n\n

Reverse the strings in each pair of matching parentheses, starting from the innermost one.

\n\n

Your result should not contain any brackets.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "(abcd)"\nOutput: "dcba"\n
\n\n

Example 2:

\n\n
\nInput: s = "(u(love)i)"\nOutput: "iloveu"\nExplanation: The substring "love" is reversed first, then the whole string is reversed.\n
\n\n

Example 3:

\n\n
\nInput: s = "(ed(et(oc))el)"\nOutput: "leetcode"\nExplanation: First, we reverse the substring "oc", then "etco", and finally, the whole string.\n
\n\n

Example 4:

\n\n
\nInput: s = "a(bcdefghijkl(mno)p)q"\nOutput: "apmnolkjihgfedcbq"\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 0 <= s.length <= 2000
  • \n\t
  • s only contains lower case English characters and parentheses.
  • \n\t
  • It's guaranteed that all parentheses are balanced.
  • \n
\n", "content_cn": "

\u7ed9\u51fa\u4e00\u4e2a\u5b57\u7b26\u4e32\u00a0s\uff08\u4ec5\u542b\u6709\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u548c\u62ec\u53f7\uff09\u3002

\n\n

\u8bf7\u4f60\u6309\u7167\u4ece\u62ec\u53f7\u5185\u5230\u5916\u7684\u987a\u5e8f\uff0c\u9010\u5c42\u53cd\u8f6c\u6bcf\u5bf9\u5339\u914d\u62ec\u53f7\u4e2d\u7684\u5b57\u7b26\u4e32\uff0c\u5e76\u8fd4\u56de\u6700\u7ec8\u7684\u7ed3\u679c\u3002

\n\n

\u6ce8\u610f\uff0c\u60a8\u7684\u7ed3\u679c\u4e2d \u4e0d\u5e94 \u5305\u542b\u4efb\u4f55\u62ec\u53f7\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"(abcd)\"\n\u8f93\u51fa\uff1a\"dcba\"\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"(u(love)i)\"\n\u8f93\u51fa\uff1a\"iloveu\"\n\u89e3\u91ca\uff1a\u5148\u53cd\u8f6c\u5b50\u5b57\u7b26\u4e32 \"love\" \uff0c\u7136\u540e\u53cd\u8f6c\u6574\u4e2a\u5b57\u7b26\u4e32\u3002
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"(ed(et(oc))el)\"\n\u8f93\u51fa\uff1a\"leetcode\"\n\u89e3\u91ca\uff1a\u5148\u53cd\u8f6c\u5b50\u5b57\u7b26\u4e32 \"oc\" \uff0c\u63a5\u7740\u53cd\u8f6c \"etco\" \uff0c\u7136\u540e\u53cd\u8f6c\u6574\u4e2a\u5b57\u7b26\u4e32\u3002
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"a(bcdefghijkl(mno)p)q\"\n\u8f93\u51fa\uff1a\"apmnolkjihgfedcbq\"\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 0 <= s.length <= 2000
  • \n\t
  • s \u4e2d\u53ea\u6709\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u548c\u62ec\u53f7
  • \n\t
  • \u9898\u76ee\u6d4b\u8bd5\u7528\u4f8b\u786e\u4fdd\u6240\u6709\u62ec\u53f7\u90fd\u662f\u6210\u5bf9\u51fa\u73b0\u7684
  • \n
\n", "tags_en": ["Stack"], "tags_cn": ["\u6808"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string reverseParentheses(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String reverseParentheses(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def reverseParentheses(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def reverseParentheses(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * reverseParentheses(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ReverseParentheses(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar reverseParentheses = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef reverse_parentheses(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func reverseParentheses(_ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func reverseParentheses(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def reverseParentheses(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun reverseParentheses(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn reverse_parentheses(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function reverseParentheses($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function reverseParentheses(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (reverse-parentheses s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1190](https://leetcode-cn.com/problems/reverse-substrings-between-each-pair-of-parentheses)", "[\u53cd\u8f6c\u6bcf\u5bf9\u62ec\u53f7\u95f4\u7684\u5b50\u4e32](/solution/1100-1199/1190.Reverse%20Substrings%20Between%20Each%20Pair%20of%20Parentheses/README.md)", "`\u6808`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1190](https://leetcode.com/problems/reverse-substrings-between-each-pair-of-parentheses)", "[Reverse Substrings Between Each Pair of Parentheses](/solution/1100-1199/1190.Reverse%20Substrings%20Between%20Each%20Pair%20of%20Parentheses/README_EN.md)", "`Stack`", "Medium", ""]}, {"question_id": "1297", "frontend_question_id": "1189", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-number-of-balloons", "url_en": "https://leetcode.com/problems/maximum-number-of-balloons", "relative_path_cn": "/solution/1100-1199/1189.Maximum%20Number%20of%20Balloons/README.md", "relative_path_en": "/solution/1100-1199/1189.Maximum%20Number%20of%20Balloons/README_EN.md", "title_cn": "\u201c\u6c14\u7403\u201d \u7684\u6700\u5927\u6570\u91cf", "title_en": "Maximum Number of Balloons", "question_title_slug": "maximum-number-of-balloons", "content_en": "

Given a string text, you want to use the characters of text to form as many instances of the word "balloon" as possible.

\n\n

You can use each character in text at most once. Return the maximum number of instances that can be formed.

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: text = "nlaebolko"\nOutput: 1\n
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: text = "loonbalxballpoon"\nOutput: 2\n
\n\n

Example 3:

\n\n
\nInput: text = "leetcode"\nOutput: 0\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= text.length <= 104
  • \n\t
  • text consists of lower case English letters only.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 text\uff0c\u4f60\u9700\u8981\u4f7f\u7528 text \u4e2d\u7684\u5b57\u6bcd\u6765\u62fc\u51d1\u5c3d\u53ef\u80fd\u591a\u7684\u5355\u8bcd "balloon"\uff08\u6c14\u7403\uff09\u3002

\n\n

\u5b57\u7b26\u4e32 text \u4e2d\u7684\u6bcf\u4e2a\u5b57\u6bcd\u6700\u591a\u53ea\u80fd\u88ab\u4f7f\u7528\u4e00\u6b21\u3002\u8bf7\u4f60\u8fd4\u56de\u6700\u591a\u53ef\u4ee5\u62fc\u51d1\u51fa\u591a\u5c11\u4e2a\u5355\u8bcd "balloon"\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1atext = "nlaebolko"\n\u8f93\u51fa\uff1a1\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1atext = "loonbalxballpoon"\n\u8f93\u51fa\uff1a2\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1atext = "leetcode"\n\u8f93\u51fa\uff1a0\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= text.length <= 10^4
  • \n\t
  • text \u5168\u90e8\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
  • \n
\n", "tags_en": ["Hash Table", "String"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxNumberOfBalloons(string text) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxNumberOfBalloons(String text) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxNumberOfBalloons(self, text):\n \"\"\"\n :type text: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxNumberOfBalloons(self, text: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxNumberOfBalloons(char * text){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxNumberOfBalloons(string text) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} text\n * @return {number}\n */\nvar maxNumberOfBalloons = function(text) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} text\n# @return {Integer}\ndef max_number_of_balloons(text)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxNumberOfBalloons(_ text: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxNumberOfBalloons(text string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxNumberOfBalloons(text: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxNumberOfBalloons(text: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_number_of_balloons(text: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $text\n * @return Integer\n */\n function maxNumberOfBalloons($text) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxNumberOfBalloons(text: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-number-of-balloons text)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1189](https://leetcode-cn.com/problems/maximum-number-of-balloons)", "[\u201c\u6c14\u7403\u201d \u7684\u6700\u5927\u6570\u91cf](/solution/1100-1199/1189.Maximum%20Number%20of%20Balloons/README.md)", "`\u54c8\u5e0c\u8868`,`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1189](https://leetcode.com/problems/maximum-number-of-balloons)", "[Maximum Number of Balloons](/solution/1100-1199/1189.Maximum%20Number%20of%20Balloons/README_EN.md)", "`Hash Table`,`String`", "Easy", ""]}, {"question_id": "1296", "frontend_question_id": "1483", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/kth-ancestor-of-a-tree-node", "url_en": "https://leetcode.com/problems/kth-ancestor-of-a-tree-node", "relative_path_cn": "/solution/1400-1499/1483.Kth%20Ancestor%20of%20a%20Tree%20Node/README.md", "relative_path_en": "/solution/1400-1499/1483.Kth%20Ancestor%20of%20a%20Tree%20Node/README_EN.md", "title_cn": "\u6811\u8282\u70b9\u7684\u7b2c K \u4e2a\u7956\u5148", "title_en": "Kth Ancestor of a Tree Node", "question_title_slug": "kth-ancestor-of-a-tree-node", "content_en": "

You are given a tree with n nodes numbered from 0 to n-1 in the form of a parent array where parent[i] is the parent of node i. The root of the tree is node 0.

\r\n\r\n

Implement the function getKthAncestor(int node, int k) to return the k-th ancestor of the given node. If there is no such ancestor, return -1.

\r\n\r\n

The k-th ancestor of a tree node is the k-th node in the path from that node to the root.

\r\n\r\n

 

\r\n\r\n

Example:

\r\n\r\n

\"\"

\r\n\r\n
\r\nInput:\r\n["TreeAncestor","getKthAncestor","getKthAncestor","getKthAncestor"]\r\n[[7,[-1,0,0,1,1,2,2]],[3,1],[5,2],[6,3]]\r\n\r\nOutput:\r\n[null,1,0,-1]\r\n\r\nExplanation:\r\nTreeAncestor treeAncestor = new TreeAncestor(7, [-1, 0, 0, 1, 1, 2, 2]);\r\n\r\ntreeAncestor.getKthAncestor(3, 1);  // returns 1 which is the parent of 3\r\ntreeAncestor.getKthAncestor(5, 2);  // returns 0 which is the grandparent of 5\r\ntreeAncestor.getKthAncestor(6, 3);  // returns -1 because there is no such ancestor\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= k <= n <= 5*10^4
  • \r\n\t
  • parent[0] == -1 indicating that 0 is the root node.
  • \r\n\t
  • 0 <= parent[i] < n for all 0 < i < n
  • \r\n\t
  • 0 <= node < n
  • \r\n\t
  • There will be at most 5*10^4 queries.
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u68f5\u6811\uff0c\u6811\u4e0a\u6709 n \u4e2a\u8282\u70b9\uff0c\u6309\u4ece 0 \u5230 n-1 \u7f16\u53f7\u3002\u6811\u4ee5\u7236\u8282\u70b9\u6570\u7ec4\u7684\u5f62\u5f0f\u7ed9\u51fa\uff0c\u5176\u4e2d parent[i] \u662f\u8282\u70b9 i \u7684\u7236\u8282\u70b9\u3002\u6811\u7684\u6839\u8282\u70b9\u662f\u7f16\u53f7\u4e3a 0 \u7684\u8282\u70b9\u3002

\n\n

\u8bf7\u4f60\u8bbe\u8ba1\u5e76\u5b9e\u73b0 getKthAncestor(int node, int k) \u51fd\u6570\uff0c\u51fd\u6570\u8fd4\u56de\u8282\u70b9 node \u7684\u7b2c k \u4e2a\u7956\u5148\u8282\u70b9\u3002\u5982\u679c\u4e0d\u5b58\u5728\u8fd9\u6837\u7684\u7956\u5148\u8282\u70b9\uff0c\u8fd4\u56de -1 \u3002

\n\n

\u6811\u8282\u70b9\u7684\u7b2c k \u4e2a\u7956\u5148\u8282\u70b9\u662f\u4ece\u8be5\u8282\u70b9\u5230\u6839\u8282\u70b9\u8def\u5f84\u4e0a\u7684\u7b2c k \u4e2a\u8282\u70b9\u3002

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1a\n["TreeAncestor","getKthAncestor","getKthAncestor","getKthAncestor"]\n[[7,[-1,0,0,1,1,2,2]],[3,1],[5,2],[6,3]]\n\n\u8f93\u51fa\uff1a\n[null,1,0,-1]\n\n\u89e3\u91ca\uff1a\nTreeAncestor treeAncestor = new TreeAncestor(7, [-1, 0, 0, 1, 1, 2, 2]);\n\ntreeAncestor.getKthAncestor(3, 1);  // \u8fd4\u56de 1 \uff0c\u5b83\u662f 3 \u7684\u7236\u8282\u70b9\ntreeAncestor.getKthAncestor(5, 2);  // \u8fd4\u56de 0 \uff0c\u5b83\u662f 5 \u7684\u7956\u7236\u8282\u70b9\ntreeAncestor.getKthAncestor(6, 3);  // \u8fd4\u56de -1 \u56e0\u4e3a\u4e0d\u5b58\u5728\u6ee1\u8db3\u8981\u6c42\u7684\u7956\u5148\u8282\u70b9\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= k <= n <= 5*10^4
  • \n\t
  • parent[0] == -1 \u8868\u793a\u7f16\u53f7\u4e3a 0 \u7684\u8282\u70b9\u662f\u6839\u8282\u70b9\u3002
  • \n\t
  • \u5bf9\u4e8e\u6240\u6709\u7684 0 < i < n \uff0c0 <= parent[i] < n \u603b\u6210\u7acb
  • \n\t
  • 0 <= node < n
  • \n\t
  • \u81f3\u591a\u67e5\u8be2 5*10^4 \u6b21
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class TreeAncestor {\npublic:\n TreeAncestor(int n, vector& parent) {\n\n }\n \n int getKthAncestor(int node, int k) {\n\n }\n};\n\n/**\n * Your TreeAncestor object will be instantiated and called as such:\n * TreeAncestor* obj = new TreeAncestor(n, parent);\n * int param_1 = obj->getKthAncestor(node,k);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class TreeAncestor {\n\n public TreeAncestor(int n, int[] parent) {\n\n }\n \n public int getKthAncestor(int node, int k) {\n\n }\n}\n\n/**\n * Your TreeAncestor object will be instantiated and called as such:\n * TreeAncestor obj = new TreeAncestor(n, parent);\n * int param_1 = obj.getKthAncestor(node,k);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class TreeAncestor(object):\n\n def __init__(self, n, parent):\n \"\"\"\n :type n: int\n :type parent: List[int]\n \"\"\"\n\n\n def getKthAncestor(self, node, k):\n \"\"\"\n :type node: int\n :type k: int\n :rtype: int\n \"\"\"\n\n\n\n# Your TreeAncestor object will be instantiated and called as such:\n# obj = TreeAncestor(n, parent)\n# param_1 = obj.getKthAncestor(node,k)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class TreeAncestor:\n\n def __init__(self, n: int, parent: List[int]):\n\n\n def getKthAncestor(self, node: int, k: int) -> int:\n\n\n\n# Your TreeAncestor object will be instantiated and called as such:\n# obj = TreeAncestor(n, parent)\n# param_1 = obj.getKthAncestor(node,k)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} TreeAncestor;\n\n\nTreeAncestor* treeAncestorCreate(int n, int* parent, int parentSize) {\n\n}\n\nint treeAncestorGetKthAncestor(TreeAncestor* obj, int node, int k) {\n\n}\n\nvoid treeAncestorFree(TreeAncestor* obj) {\n\n}\n\n/**\n * Your TreeAncestor struct will be instantiated and called as such:\n * TreeAncestor* obj = treeAncestorCreate(n, parent, parentSize);\n * int param_1 = treeAncestorGetKthAncestor(obj, node, k);\n \n * treeAncestorFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class TreeAncestor {\n\n public TreeAncestor(int n, int[] parent) {\n\n }\n \n public int GetKthAncestor(int node, int k) {\n\n }\n}\n\n/**\n * Your TreeAncestor object will be instantiated and called as such:\n * TreeAncestor obj = new TreeAncestor(n, parent);\n * int param_1 = obj.GetKthAncestor(node,k);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[]} parent\n */\nvar TreeAncestor = function(n, parent) {\n\n};\n\n/** \n * @param {number} node \n * @param {number} k\n * @return {number}\n */\nTreeAncestor.prototype.getKthAncestor = function(node, k) {\n\n};\n\n/**\n * Your TreeAncestor object will be instantiated and called as such:\n * var obj = new TreeAncestor(n, parent)\n * var param_1 = obj.getKthAncestor(node,k)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class TreeAncestor\n\n=begin\n :type n: Integer\n :type parent: Integer[]\n=end\n def initialize(n, parent)\n\n end\n\n\n=begin\n :type node: Integer\n :type k: Integer\n :rtype: Integer\n=end\n def get_kth_ancestor(node, k)\n\n end\n\n\nend\n\n# Your TreeAncestor object will be instantiated and called as such:\n# obj = TreeAncestor.new(n, parent)\n# param_1 = obj.get_kth_ancestor(node, k)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass TreeAncestor {\n\n init(_ n: Int, _ parent: [Int]) {\n \n }\n \n func getKthAncestor(_ node: Int, _ k: Int) -> Int {\n \n }\n}\n\n/**\n * Your TreeAncestor object will be instantiated and called as such:\n * let obj = TreeAncestor(n, parent)\n * let ret_1: Int = obj.getKthAncestor(node, k)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type TreeAncestor struct {\n\n}\n\n\nfunc Constructor(n int, parent []int) TreeAncestor {\n\n}\n\n\nfunc (this *TreeAncestor) GetKthAncestor(node int, k int) int {\n\n}\n\n\n/**\n * Your TreeAncestor object will be instantiated and called as such:\n * obj := Constructor(n, parent);\n * param_1 := obj.GetKthAncestor(node,k);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class TreeAncestor(_n: Int, _parent: Array[Int]) {\n\n def getKthAncestor(node: Int, k: Int): Int = {\n\n }\n\n}\n\n/**\n * Your TreeAncestor object will be instantiated and called as such:\n * var obj = new TreeAncestor(n, parent)\n * var param_1 = obj.getKthAncestor(node,k)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class TreeAncestor(n: Int, parent: IntArray) {\n\n fun getKthAncestor(node: Int, k: Int): Int {\n\n }\n\n}\n\n/**\n * Your TreeAncestor object will be instantiated and called as such:\n * var obj = TreeAncestor(n, parent)\n * var param_1 = obj.getKthAncestor(node,k)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct TreeAncestor {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl TreeAncestor {\n\n fn new(n: i32, parent: Vec) -> Self {\n\n }\n \n fn get_kth_ancestor(&self, node: i32, k: i32) -> i32 {\n\n }\n}\n\n/**\n * Your TreeAncestor object will be instantiated and called as such:\n * let obj = TreeAncestor::new(n, parent);\n * let ret_1: i32 = obj.get_kth_ancestor(node, k);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class TreeAncestor {\n /**\n * @param Integer $n\n * @param Integer[] $parent\n */\n function __construct($n, $parent) {\n \n }\n \n /**\n * @param Integer $node\n * @param Integer $k\n * @return Integer\n */\n function getKthAncestor($node, $k) {\n \n }\n}\n\n/**\n * Your TreeAncestor object will be instantiated and called as such:\n * $obj = TreeAncestor($n, $parent);\n * $ret_1 = $obj->getKthAncestor($node, $k);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class TreeAncestor {\n constructor(n: number, parent: number[]) {\n\n }\n\n getKthAncestor(node: number, k: number): number {\n\n }\n}\n\n/**\n * Your TreeAncestor object will be instantiated and called as such:\n * var obj = new TreeAncestor(n, parent)\n * var param_1 = obj.getKthAncestor(node,k)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define tree-ancestor%\n (class object%\n (super-new)\n\n ; n : exact-integer?\n\n ; parent : (listof exact-integer?)\n (init-field\n n\n parent)\n \n ; get-kth-ancestor : exact-integer? exact-integer? -> exact-integer?\n (define/public (get-kth-ancestor node k)\n\n )))\n\n;; Your tree-ancestor% object will be instantiated and called as such:\n;; (define obj (new tree-ancestor% [n n] [parent parent]))\n;; (define param_1 (send obj get-kth-ancestor node k))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1483](https://leetcode-cn.com/problems/kth-ancestor-of-a-tree-node)", "[\u6811\u8282\u70b9\u7684\u7b2c K \u4e2a\u7956\u5148](/solution/1400-1499/1483.Kth%20Ancestor%20of%20a%20Tree%20Node/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1483](https://leetcode.com/problems/kth-ancestor-of-a-tree-node)", "[Kth Ancestor of a Tree Node](/solution/1400-1499/1483.Kth%20Ancestor%20of%20a%20Tree%20Node/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1293", "frontend_question_id": "1550", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/three-consecutive-odds", "url_en": "https://leetcode.com/problems/three-consecutive-odds", "relative_path_cn": "/solution/1500-1599/1550.Three%20Consecutive%20Odds/README.md", "relative_path_en": "/solution/1500-1599/1550.Three%20Consecutive%20Odds/README_EN.md", "title_cn": "\u5b58\u5728\u8fde\u7eed\u4e09\u4e2a\u5947\u6570\u7684\u6570\u7ec4", "title_en": "Three Consecutive Odds", "question_title_slug": "three-consecutive-odds", "content_en": "Given an integer array arr, return true if there are three consecutive odd numbers in the array. Otherwise, return false.\n

 

\n

Example 1:

\n\n
\nInput: arr = [2,6,4,1]\nOutput: false\nExplanation: There are no three consecutive odds.\n
\n\n

Example 2:

\n\n
\nInput: arr = [1,2,34,3,4,5,7,23,12]\nOutput: true\nExplanation: [5,7,23] are three consecutive odds.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= arr.length <= 1000
  • \n\t
  • 1 <= arr[i] <= 1000
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr\uff0c\u8bf7\u4f60\u5224\u65ad\u6570\u7ec4\u4e2d\u662f\u5426\u5b58\u5728\u8fde\u7eed\u4e09\u4e2a\u5143\u7d20\u90fd\u662f\u5947\u6570\u7684\u60c5\u51b5\uff1a\u5982\u679c\u5b58\u5728\uff0c\u8bf7\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aarr = [2,6,4,1]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u4e0d\u5b58\u5728\u8fde\u7eed\u4e09\u4e2a\u5143\u7d20\u90fd\u662f\u5947\u6570\u7684\u60c5\u51b5\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aarr = [1,2,34,3,4,5,7,23,12]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u5b58\u5728\u8fde\u7eed\u4e09\u4e2a\u5143\u7d20\u90fd\u662f\u5947\u6570\u7684\u60c5\u51b5\uff0c\u5373 [5,7,23] \u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= arr.length <= 1000
  • \n\t
  • 1 <= arr[i] <= 1000
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool threeConsecutiveOdds(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean threeConsecutiveOdds(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def threeConsecutiveOdds(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def threeConsecutiveOdds(self, arr: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool threeConsecutiveOdds(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool ThreeConsecutiveOdds(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {boolean}\n */\nvar threeConsecutiveOdds = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Boolean}\ndef three_consecutive_odds(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func threeConsecutiveOdds(_ arr: [Int]) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func threeConsecutiveOdds(arr []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def threeConsecutiveOdds(arr: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun threeConsecutiveOdds(arr: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn three_consecutive_odds(arr: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Boolean\n */\n function threeConsecutiveOdds($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function threeConsecutiveOdds(arr: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (three-consecutive-odds arr)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1550](https://leetcode-cn.com/problems/three-consecutive-odds)", "[\u5b58\u5728\u8fde\u7eed\u4e09\u4e2a\u5947\u6570\u7684\u6570\u7ec4](/solution/1500-1599/1550.Three%20Consecutive%20Odds/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1550](https://leetcode.com/problems/three-consecutive-odds)", "[Three Consecutive Odds](/solution/1500-1599/1550.Three%20Consecutive%20Odds/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1292", "frontend_question_id": "1174", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/immediate-food-delivery-ii", "url_en": "https://leetcode.com/problems/immediate-food-delivery-ii", "relative_path_cn": "/solution/1100-1199/1174.Immediate%20Food%20Delivery%20II/README.md", "relative_path_en": "/solution/1100-1199/1174.Immediate%20Food%20Delivery%20II/README_EN.md", "title_cn": "\u5373\u65f6\u98df\u7269\u914d\u9001 II", "title_en": "Immediate Food Delivery II", "question_title_slug": "immediate-food-delivery-ii", "content_en": "

Table: Delivery

\n\n
\n+-----------------------------+---------+\n| Column Name                 | Type    |\n+-----------------------------+---------+\n| delivery_id                 | int     |\n| customer_id                 | int     |\n| order_date                  | date    |\n| customer_pref_delivery_date | date    |\n+-----------------------------+---------+\ndelivery_id is the primary key of this table.\nThe table holds information about food delivery to customers that make orders at some date and specify a preferred delivery date (on the same order date or after it).\n
\n\n

 

\n\n

If the preferred delivery date of the customer is the same as the order date then the order is called immediate otherwise it's called scheduled.

\n\n

The first order of a customer is the order with the earliest order date that customer made. It is guaranteed that a customer has exactly one first order.

\n\n

Write an SQL query to find the percentage of immediate orders in the first orders of all customers, rounded to 2 decimal places.

\n\n

The query result format is in the following example:

\n\n
\nDelivery table:\n+-------------+-------------+------------+-----------------------------+\n| delivery_id | customer_id | order_date | customer_pref_delivery_date |\n+-------------+-------------+------------+-----------------------------+\n| 1           | 1           | 2019-08-01 | 2019-08-02                  |\n| 2           | 2           | 2019-08-02 | 2019-08-02                  |\n| 3           | 1           | 2019-08-11 | 2019-08-12                  |\n| 4           | 3           | 2019-08-24 | 2019-08-24                  |\n| 5           | 3           | 2019-08-21 | 2019-08-22                  |\n| 6           | 2           | 2019-08-11 | 2019-08-13                  |\n| 7           | 4           | 2019-08-09 | 2019-08-09                  |\n+-------------+-------------+------------+-----------------------------+\n\nResult table:\n+----------------------+\n| immediate_percentage |\n+----------------------+\n| 50.00                |\n+----------------------+\nThe customer id 1 has a first order with delivery id 1 and it is scheduled.\nThe customer id 2 has a first order with delivery id 2 and it is immediate.\nThe customer id 3 has a first order with delivery id 5 and it is scheduled.\nThe customer id 4 has a first order with delivery id 7 and it is immediate.\nHence, half the customers have immediate first orders.\n
\n", "content_cn": "

\u914d\u9001\u8868: Delivery

\n\n
+-----------------------------+---------+\n| Column Name                 | Type    |\n+-----------------------------+---------+\n| delivery_id                 | int     |\n| customer_id                 | int     |\n| order_date                  | date    |\n| customer_pref_delivery_date | date    |\n+-----------------------------+---------+\ndelivery_id \u662f\u8868\u7684\u4e3b\u952e\u3002\n\u8be5\u8868\u4fdd\u5b58\u7740\u987e\u5ba2\u7684\u98df\u7269\u914d\u9001\u4fe1\u606f\uff0c\u987e\u5ba2\u5728\u67d0\u4e2a\u65e5\u671f\u4e0b\u4e86\u8ba2\u5355\uff0c\u5e76\u6307\u5b9a\u4e86\u4e00\u4e2a\u671f\u671b\u7684\u914d\u9001\u65e5\u671f\uff08\u548c\u4e0b\u5355\u65e5\u671f\u76f8\u540c\u6216\u8005\u5728\u90a3\u4e4b\u540e\uff09\u3002\n
\n\n

 

\n\n

\u5982\u679c\u987e\u5ba2\u671f\u671b\u7684\u914d\u9001\u65e5\u671f\u548c\u4e0b\u5355\u65e5\u671f\u76f8\u540c\uff0c\u5219\u8be5\u8ba2\u5355\u79f0\u4e3a \u300c\u5373\u65f6\u8ba2\u5355\u300d\uff0c\u5426\u5219\u79f0\u4e3a\u300c\u8ba1\u5212\u8ba2\u5355\u300d\u3002

\n\n

\u300c\u9996\u6b21\u8ba2\u5355\u300d\u662f\u987e\u5ba2\u6700\u65e9\u521b\u5efa\u7684\u8ba2\u5355\u3002\u6211\u4eec\u4fdd\u8bc1\u4e00\u4e2a\u987e\u5ba2\u53ea\u4f1a\u6709\u4e00\u4e2a\u300c\u9996\u6b21\u8ba2\u5355\u300d\u3002

\n\n

\u5199\u4e00\u6761 SQL \u67e5\u8be2\u8bed\u53e5\u83b7\u53d6\u5373\u65f6\u8ba2\u5355\u5728\u6240\u6709\u7528\u6237\u7684\u9996\u6b21\u8ba2\u5355\u4e2d\u7684\u6bd4\u4f8b\u3002\u4fdd\u7559\u4e24\u4f4d\u5c0f\u6570\u3002

\n\n

 

\n\n

\u67e5\u8be2\u7ed3\u679c\u5982\u4e0b\u6240\u793a\uff1a

\n\n
Delivery \u8868\uff1a\n+-------------+-------------+------------+-----------------------------+\n| delivery_id | customer_id | order_date | customer_pref_delivery_date |\n+-------------+-------------+------------+-----------------------------+\n| 1           | 1           | 2019-08-01 | 2019-08-02                  |\n| 2           | 2           | 2019-08-02 | 2019-08-02                  |\n| 3           | 1           | 2019-08-11 | 2019-08-12                  |\n| 4           | 3           | 2019-08-24 | 2019-08-24                  |\n| 5           | 3           | 2019-08-21 | 2019-08-22                  |\n| 6           | 2           | 2019-08-11 | 2019-08-13                  |\n| 7           | 4           | 2019-08-09 | 2019-08-09                  |\n+-------------+-------------+------------+-----------------------------+\n\nResult \u8868\uff1a\n+----------------------+\n| immediate_percentage |\n+----------------------+\n| 50.00                |\n+----------------------+\n1 \u53f7\u987e\u5ba2\u7684 1 \u53f7\u8ba2\u5355\u662f\u9996\u6b21\u8ba2\u5355\uff0c\u5e76\u4e14\u662f\u8ba1\u5212\u8ba2\u5355\u3002\n2 \u53f7\u987e\u5ba2\u7684 2 \u53f7\u8ba2\u5355\u662f\u9996\u6b21\u8ba2\u5355\uff0c\u5e76\u4e14\u662f\u5373\u65f6\u8ba2\u5355\u3002\n3 \u53f7\u987e\u5ba2\u7684 5 \u53f7\u8ba2\u5355\u662f\u9996\u6b21\u8ba2\u5355\uff0c\u5e76\u4e14\u662f\u8ba1\u5212\u8ba2\u5355\u3002\n4 \u53f7\u987e\u5ba2\u7684 7 \u53f7\u8ba2\u5355\u662f\u9996\u6b21\u8ba2\u5355\uff0c\u5e76\u4e14\u662f\u5373\u65f6\u8ba2\u5355\u3002\n\u56e0\u6b64\uff0c\u4e00\u534a\u987e\u5ba2\u7684\u9996\u6b21\u8ba2\u5355\u662f\u5373\u65f6\u7684\u3002\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1174](https://leetcode-cn.com/problems/immediate-food-delivery-ii)", "[\u5373\u65f6\u98df\u7269\u914d\u9001 II](/solution/1100-1199/1174.Immediate%20Food%20Delivery%20II/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1174](https://leetcode.com/problems/immediate-food-delivery-ii)", "[Immediate Food Delivery II](/solution/1100-1199/1174.Immediate%20Food%20Delivery%20II/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1291", "frontend_question_id": "1173", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/immediate-food-delivery-i", "url_en": "https://leetcode.com/problems/immediate-food-delivery-i", "relative_path_cn": "/solution/1100-1199/1173.Immediate%20Food%20Delivery%20I/README.md", "relative_path_en": "/solution/1100-1199/1173.Immediate%20Food%20Delivery%20I/README_EN.md", "title_cn": "\u5373\u65f6\u98df\u7269\u914d\u9001 I", "title_en": "Immediate Food Delivery I", "question_title_slug": "immediate-food-delivery-i", "content_en": "

Table: Delivery

\n\n
\n+-----------------------------+---------+\n| Column Name                 | Type    |\n+-----------------------------+---------+\n| delivery_id                 | int     |\n| customer_id                 | int     |\n| order_date                  | date    |\n| customer_pref_delivery_date | date    |\n+-----------------------------+---------+\ndelivery_id is the primary key of this table.\nThe table holds information about food delivery to customers that make orders at some date and specify a preferred delivery date (on the same order date or after it).\n
\n\n

 

\n\n

If the preferred delivery date of the customer is the same as the order date then the order is called immediate otherwise it's called scheduled.

\n\n

Write an SQL query to find the percentage of immediate orders in the table, rounded to 2 decimal places.

\n\n

The query result format is in the following example:

\n\n
\nDelivery table:\n+-------------+-------------+------------+-----------------------------+\n| delivery_id | customer_id | order_date | customer_pref_delivery_date |\n+-------------+-------------+------------+-----------------------------+\n| 1           | 1           | 2019-08-01 | 2019-08-02                  |\n| 2           | 5           | 2019-08-02 | 2019-08-02                  |\n| 3           | 1           | 2019-08-11 | 2019-08-11                  |\n| 4           | 3           | 2019-08-24 | 2019-08-26                  |\n| 5           | 4           | 2019-08-21 | 2019-08-22                  |\n| 6           | 2           | 2019-08-11 | 2019-08-13                  |\n+-------------+-------------+------------+-----------------------------+\n\nResult table:\n+----------------------+\n| immediate_percentage |\n+----------------------+\n| 33.33                |\n+----------------------+\nThe orders with delivery id 2 and 3 are immediate while the others are scheduled.\n
\n", "content_cn": "

\u914d\u9001\u8868: Delivery

\n\n
+-----------------------------+---------+\n| Column Name                 | Type    |\n+-----------------------------+---------+\n| delivery_id                 | int     |\n| customer_id                 | int     |\n| order_date                  | date    |\n| customer_pref_delivery_date | date    |\n+-----------------------------+---------+\ndelivery_id \u662f\u8868\u7684\u4e3b\u952e\u3002\n\u8be5\u8868\u4fdd\u5b58\u7740\u987e\u5ba2\u7684\u98df\u7269\u914d\u9001\u4fe1\u606f\uff0c\u987e\u5ba2\u5728\u67d0\u4e2a\u65e5\u671f\u4e0b\u4e86\u8ba2\u5355\uff0c\u5e76\u6307\u5b9a\u4e86\u4e00\u4e2a\u671f\u671b\u7684\u914d\u9001\u65e5\u671f\uff08\u548c\u4e0b\u5355\u65e5\u671f\u76f8\u540c\u6216\u8005\u5728\u90a3\u4e4b\u540e\uff09\u3002\n
\n\n

 

\n\n

\u5982\u679c\u987e\u5ba2\u671f\u671b\u7684\u914d\u9001\u65e5\u671f\u548c\u4e0b\u5355\u65e5\u671f\u76f8\u540c\uff0c\u5219\u8be5\u8ba2\u5355\u79f0\u4e3a \u300c\u5373\u65f6\u8ba2\u5355\u300d\uff0c\u5426\u5219\u79f0\u4e3a\u300c\u8ba1\u5212\u8ba2\u5355\u300d\u3002

\n\n

\u5199\u4e00\u6761 SQL \u67e5\u8be2\u8bed\u53e5\u83b7\u53d6\u5373\u65f6\u8ba2\u5355\u6240\u5360\u7684\u767e\u5206\u6bd4\uff0c \u4fdd\u7559\u4e24\u4f4d\u5c0f\u6570\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u5982\u4e0b\u6240\u793a\uff1a

\n\n
Delivery \u8868:\n+-------------+-------------+------------+-----------------------------+\n| delivery_id | customer_id | order_date | customer_pref_delivery_date |\n+-------------+-------------+------------+-----------------------------+\n| 1           | 1           | 2019-08-01 | 2019-08-02                  |\n| 2           | 5           | 2019-08-02 | 2019-08-02                  |\n| 3           | 1           | 2019-08-11 | 2019-08-11                  |\n| 4           | 3           | 2019-08-24 | 2019-08-26                  |\n| 5           | 4           | 2019-08-21 | 2019-08-22                  |\n| 6           | 2           | 2019-08-11 | 2019-08-13                  |\n+-------------+-------------+------------+-----------------------------+\n\nResult \u8868:\n+----------------------+\n| immediate_percentage |\n+----------------------+\n| 33.33                |\n+----------------------+\n2 \u548c 3 \u53f7\u8ba2\u5355\u4e3a\u5373\u65f6\u8ba2\u5355\uff0c\u5176\u4ed6\u7684\u4e3a\u8ba1\u5212\u8ba2\u5355\u3002
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1173](https://leetcode-cn.com/problems/immediate-food-delivery-i)", "[\u5373\u65f6\u98df\u7269\u914d\u9001 I](/solution/1100-1199/1173.Immediate%20Food%20Delivery%20I/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1173](https://leetcode.com/problems/immediate-food-delivery-i)", "[Immediate Food Delivery I](/solution/1100-1199/1173.Immediate%20Food%20Delivery%20I/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1290", "frontend_question_id": "1187", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/make-array-strictly-increasing", "url_en": "https://leetcode.com/problems/make-array-strictly-increasing", "relative_path_cn": "/solution/1100-1199/1187.Make%20Array%20Strictly%20Increasing/README.md", "relative_path_en": "/solution/1100-1199/1187.Make%20Array%20Strictly%20Increasing/README_EN.md", "title_cn": "\u4f7f\u6570\u7ec4\u4e25\u683c\u9012\u589e", "title_en": "Make Array Strictly Increasing", "question_title_slug": "make-array-strictly-increasing", "content_en": "

Given two integer arrays arr1 and arr2, return the minimum number of operations (possibly zero) needed to make arr1 strictly increasing.

\r\n\r\n

In one operation, you can choose two indices 0 <= i < arr1.length and 0 <= j < arr2.length and do the assignment arr1[i] = arr2[j].

\r\n\r\n

If there is no way to make arr1 strictly increasing, return -1.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: arr1 = [1,5,3,6,7], arr2 = [1,3,2,4]\r\nOutput: 1\r\nExplanation: Replace 5 with 2, then arr1 = [1, 2, 3, 6, 7].\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: arr1 = [1,5,3,6,7], arr2 = [4,3,1]\r\nOutput: 2\r\nExplanation: Replace 5 with 3 and then replace 3 with 4. arr1 = [1, 3, 4, 6, 7].\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: arr1 = [1,5,3,6,7], arr2 = [1,6,3,3]\r\nOutput: -1\r\nExplanation: You can't make arr1 strictly increasing.
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= arr1.length, arr2.length <= 2000
  • \r\n\t
  • 0 <= arr1[i], arr2[i] <= 10^9
  • \r\n
\r\n\r\n

 

", "content_cn": "

\u7ed9\u4f60\u4e24\u4e2a\u6574\u6570\u6570\u7ec4 arr1 \u548c arr2\uff0c\u8fd4\u56de\u4f7f arr1 \u4e25\u683c\u9012\u589e\u6240\u9700\u8981\u7684\u6700\u5c0f\u300c\u64cd\u4f5c\u300d\u6570\uff08\u53ef\u80fd\u4e3a 0\uff09\u3002

\n\n

\u6bcf\u4e00\u6b65\u300c\u64cd\u4f5c\u300d\u4e2d\uff0c\u4f60\u53ef\u4ee5\u5206\u522b\u4ece arr1 \u548c arr2 \u4e2d\u5404\u9009\u51fa\u4e00\u4e2a\u7d22\u5f15\uff0c\u5206\u522b\u4e3a i \u548c j\uff0c0 <= i < arr1.length \u548c 0 <= j < arr2.length\uff0c\u7136\u540e\u8fdb\u884c\u8d4b\u503c\u8fd0\u7b97 arr1[i] = arr2[j]\u3002

\n\n

\u5982\u679c\u65e0\u6cd5\u8ba9 arr1 \u4e25\u683c\u9012\u589e\uff0c\u8bf7\u8fd4\u56de -1\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aarr1 = [1,5,3,6,7], arr2 = [1,3,2,4]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u7528 2 \u6765\u66ff\u6362 5\uff0c\u4e4b\u540e arr1 = [1, 2, 3, 6, 7]\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aarr1 = [1,5,3,6,7], arr2 = [4,3,1]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u7528 3 \u6765\u66ff\u6362 5\uff0c\u7136\u540e\u7528 4 \u6765\u66ff\u6362 3\uff0c\u5f97\u5230 arr1 = [1, 3, 4, 6, 7]\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aarr1 = [1,5,3,6,7], arr2 = [1,6,3,3]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u65e0\u6cd5\u4f7f arr1 \u4e25\u683c\u9012\u589e\u3002
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= arr1.length, arr2.length <= 2000
  • \n\t
  • 0 <= arr1[i], arr2[i] <= 10^9
  • \n
\n\n

 

\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int makeArrayIncreasing(vector& arr1, vector& arr2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int makeArrayIncreasing(int[] arr1, int[] arr2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def makeArrayIncreasing(self, arr1, arr2):\n \"\"\"\n :type arr1: List[int]\n :type arr2: List[int]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def makeArrayIncreasing(self, arr1: List[int], arr2: List[int]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint makeArrayIncreasing(int* arr1, int arr1Size, int* arr2, int arr2Size){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MakeArrayIncreasing(int[] arr1, int[] arr2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr1\n * @param {number[]} arr2\n * @return {number}\n */\nvar makeArrayIncreasing = function(arr1, arr2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr1\n# @param {Integer[]} arr2\n# @return {Integer}\ndef make_array_increasing(arr1, arr2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func makeArrayIncreasing(_ arr1: [Int], _ arr2: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func makeArrayIncreasing(arr1 []int, arr2 []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def makeArrayIncreasing(arr1: Array[Int], arr2: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun makeArrayIncreasing(arr1: IntArray, arr2: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn make_array_increasing(arr1: Vec, arr2: Vec) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr1\n * @param Integer[] $arr2\n * @return Integer\n */\n function makeArrayIncreasing($arr1, $arr2) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function makeArrayIncreasing(arr1: number[], arr2: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (make-array-increasing arr1 arr2)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1187](https://leetcode-cn.com/problems/make-array-strictly-increasing)", "[\u4f7f\u6570\u7ec4\u4e25\u683c\u9012\u589e](/solution/1100-1199/1187.Make%20Array%20Strictly%20Increasing/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1187](https://leetcode.com/problems/make-array-strictly-increasing)", "[Make Array Strictly Increasing](/solution/1100-1199/1187.Make%20Array%20Strictly%20Increasing/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1289", "frontend_question_id": "1185", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/day-of-the-week", "url_en": "https://leetcode.com/problems/day-of-the-week", "relative_path_cn": "/solution/1100-1199/1185.Day%20of%20the%20Week/README.md", "relative_path_en": "/solution/1100-1199/1185.Day%20of%20the%20Week/README_EN.md", "title_cn": "\u4e00\u5468\u4e2d\u7684\u7b2c\u51e0\u5929", "title_en": "Day of the Week", "question_title_slug": "day-of-the-week", "content_en": "

Given a date, return the corresponding day of the week for that date.

\n\n

The input is given as three integers representing the day, month and year respectively.

\n\n

Return the answer as one of the following values {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}.

\n\n

 

\n

Example 1:

\n\n
\nInput: day = 31, month = 8, year = 2019\nOutput: "Saturday"\n
\n\n

Example 2:

\n\n
\nInput: day = 18, month = 7, year = 1999\nOutput: "Sunday"\n
\n\n

Example 3:

\n\n
\nInput: day = 15, month = 8, year = 1993\nOutput: "Sunday"\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The given dates are valid dates between the years 1971 and 2100.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u65e5\u671f\uff0c\u8bf7\u4f60\u8bbe\u8ba1\u4e00\u4e2a\u7b97\u6cd5\u6765\u5224\u65ad\u5b83\u662f\u5bf9\u5e94\u4e00\u5468\u4e2d\u7684\u54ea\u4e00\u5929\u3002

\n\n

\u8f93\u5165\u4e3a\u4e09\u4e2a\u6574\u6570\uff1aday\u3001month \u548c year\uff0c\u5206\u522b\u8868\u793a\u65e5\u3001\u6708\u3001\u5e74\u3002

\n\n

\u60a8\u8fd4\u56de\u7684\u7ed3\u679c\u5fc5\u987b\u662f\u8fd9\u51e0\u4e2a\u503c\u4e2d\u7684\u4e00\u4e2a {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aday = 31, month = 8, year = 2019\n\u8f93\u51fa\uff1a"Saturday"\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aday = 18, month = 7, year = 1999\n\u8f93\u51fa\uff1a"Sunday"\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aday = 15, month = 8, year = 1993\n\u8f93\u51fa\uff1a"Sunday"\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u7ed9\u51fa\u7684\u65e5\u671f\u4e00\u5b9a\u662f\u5728 1971 \u5230 2100 \u5e74\u4e4b\u95f4\u7684\u6709\u6548\u65e5\u671f\u3002
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string dayOfTheWeek(int day, int month, int year) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String dayOfTheWeek(int day, int month, int year) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def dayOfTheWeek(self, day, month, year):\n \"\"\"\n :type day: int\n :type month: int\n :type year: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def dayOfTheWeek(self, day: int, month: int, year: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * dayOfTheWeek(int day, int month, int year){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string DayOfTheWeek(int day, int month, int year) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} day\n * @param {number} month\n * @param {number} year\n * @return {string}\n */\nvar dayOfTheWeek = function(day, month, year) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} day\n# @param {Integer} month\n# @param {Integer} year\n# @return {String}\ndef day_of_the_week(day, month, year)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func dayOfTheWeek(_ day: Int, _ month: Int, _ year: Int) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func dayOfTheWeek(day int, month int, year int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def dayOfTheWeek(day: Int, month: Int, year: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun dayOfTheWeek(day: Int, month: Int, year: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn day_of_the_week(day: i32, month: i32, year: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $day\n * @param Integer $month\n * @param Integer $year\n * @return String\n */\n function dayOfTheWeek($day, $month, $year) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function dayOfTheWeek(day: number, month: number, year: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (day-of-the-week day month year)\n (-> exact-integer? exact-integer? exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1185](https://leetcode-cn.com/problems/day-of-the-week)", "[\u4e00\u5468\u4e2d\u7684\u7b2c\u51e0\u5929](/solution/1100-1199/1185.Day%20of%20the%20Week/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1185](https://leetcode.com/problems/day-of-the-week)", "[Day of the Week](/solution/1100-1199/1185.Day%20of%20the%20Week/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1288", "frontend_question_id": "1186", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-subarray-sum-with-one-deletion", "url_en": "https://leetcode.com/problems/maximum-subarray-sum-with-one-deletion", "relative_path_cn": "/solution/1100-1199/1186.Maximum%20Subarray%20Sum%20with%20One%20Deletion/README.md", "relative_path_en": "/solution/1100-1199/1186.Maximum%20Subarray%20Sum%20with%20One%20Deletion/README_EN.md", "title_cn": "\u5220\u9664\u4e00\u6b21\u5f97\u5230\u5b50\u6570\u7ec4\u6700\u5927\u548c", "title_en": "Maximum Subarray Sum with One Deletion", "question_title_slug": "maximum-subarray-sum-with-one-deletion", "content_en": "

Given an array of integers, return the maximum sum for a non-empty subarray (contiguous elements) with at most one element deletion. In other words, you want to choose a subarray and optionally delete one element from it so that there is still at least one element left and the sum of the remaining elements is maximum possible.

\n\n

Note that the subarray needs to be non-empty after deleting one element.

\n\n

 

\n

Example 1:

\n\n
\nInput: arr = [1,-2,0,3]\nOutput: 4\nExplanation: Because we can choose [1, -2, 0, 3] and drop -2, thus the subarray [1, 0, 3] becomes the maximum value.
\n\n

Example 2:

\n\n
\nInput: arr = [1,-2,-2,3]\nOutput: 3\nExplanation: We just choose [3] and it's the maximum sum.\n
\n\n

Example 3:

\n\n
\nInput: arr = [-1,-1,-1,-1]\nOutput: -1\nExplanation: The final subarray needs to be non-empty. You can't choose [-1] and delete -1 from it, then get an empty subarray to make the sum equals to 0.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= arr.length <= 105
  • \n\t
  • -104 <= arr[i] <= 104
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\uff0c\u8fd4\u56de\u5b83\u7684\u67d0\u4e2a \u975e\u7a7a \u5b50\u6570\u7ec4\uff08\u8fde\u7eed\u5143\u7d20\uff09\u5728\u6267\u884c\u4e00\u6b21\u53ef\u9009\u7684\u5220\u9664\u64cd\u4f5c\u540e\uff0c\u6240\u80fd\u5f97\u5230\u7684\u6700\u5927\u5143\u7d20\u603b\u548c\u3002

\n\n

\u6362\u53e5\u8bdd\u8bf4\uff0c\u4f60\u53ef\u4ee5\u4ece\u539f\u6570\u7ec4\u4e2d\u9009\u51fa\u4e00\u4e2a\u5b50\u6570\u7ec4\uff0c\u5e76\u53ef\u4ee5\u51b3\u5b9a\u8981\u4e0d\u8981\u4ece\u4e2d\u5220\u9664\u4e00\u4e2a\u5143\u7d20\uff08\u53ea\u80fd\u5220\u4e00\u6b21\u54e6\uff09\uff0c\uff08\u5220\u9664\u540e\uff09\u5b50\u6570\u7ec4\u4e2d\u81f3\u5c11\u5e94\u5f53\u6709\u4e00\u4e2a\u5143\u7d20\uff0c\u7136\u540e\u8be5\u5b50\u6570\u7ec4\uff08\u5269\u4e0b\uff09\u7684\u5143\u7d20\u603b\u548c\u662f\u6240\u6709\u5b50\u6570\u7ec4\u4e4b\u4e2d\u6700\u5927\u7684\u3002

\n\n

\u6ce8\u610f\uff0c\u5220\u9664\u4e00\u4e2a\u5143\u7d20\u540e\uff0c\u5b50\u6570\u7ec4 \u4e0d\u80fd\u4e3a\u7a7a\u3002

\n\n

\u8bf7\u770b\u793a\u4f8b\uff1a

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aarr = [1,-2,0,3]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u6211\u4eec\u53ef\u4ee5\u9009\u51fa [1, -2, 0, 3]\uff0c\u7136\u540e\u5220\u6389 -2\uff0c\u8fd9\u6837\u5f97\u5230 [1, 0, 3]\uff0c\u548c\u6700\u5927\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aarr = [1,-2,-2,3]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6211\u4eec\u76f4\u63a5\u9009\u51fa [3]\uff0c\u8fd9\u5c31\u662f\u6700\u5927\u548c\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aarr = [-1,-1,-1,-1]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u6700\u540e\u5f97\u5230\u7684\u5b50\u6570\u7ec4\u4e0d\u80fd\u4e3a\u7a7a\uff0c\u6240\u4ee5\u6211\u4eec\u4e0d\u80fd\u9009\u62e9 [-1] \u5e76\u4ece\u4e2d\u5220\u53bb -1 \u6765\u5f97\u5230 0\u3002\n     \u6211\u4eec\u5e94\u8be5\u76f4\u63a5\u9009\u62e9 [-1]\uff0c\u6216\u8005\u9009\u62e9 [-1, -1] \u518d\u4ece\u4e2d\u5220\u53bb\u4e00\u4e2a -1\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= arr.length <= 10^5
  • \n\t
  • -10^4 <= arr[i] <= 10^4
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maximumSum(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maximumSum(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximumSum(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximumSum(self, arr: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maximumSum(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaximumSum(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar maximumSum = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef maximum_sum(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximumSum(_ arr: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximumSum(arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximumSum(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximumSum(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximum_sum(arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function maximumSum($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximumSum(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximum-sum arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1186](https://leetcode-cn.com/problems/maximum-subarray-sum-with-one-deletion)", "[\u5220\u9664\u4e00\u6b21\u5f97\u5230\u5b50\u6570\u7ec4\u6700\u5927\u548c](/solution/1100-1199/1186.Maximum%20Subarray%20Sum%20with%20One%20Deletion/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1186](https://leetcode.com/problems/maximum-subarray-sum-with-one-deletion)", "[Maximum Subarray Sum with One Deletion](/solution/1100-1199/1186.Maximum%20Subarray%20Sum%20with%20One%20Deletion/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "1287", "frontend_question_id": "1184", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/distance-between-bus-stops", "url_en": "https://leetcode.com/problems/distance-between-bus-stops", "relative_path_cn": "/solution/1100-1199/1184.Distance%20Between%20Bus%20Stops/README.md", "relative_path_en": "/solution/1100-1199/1184.Distance%20Between%20Bus%20Stops/README_EN.md", "title_cn": "\u516c\u4ea4\u7ad9\u95f4\u7684\u8ddd\u79bb", "title_en": "Distance Between Bus Stops", "question_title_slug": "distance-between-bus-stops", "content_en": "

A bus has n stops numbered from 0 to n - 1 that form a circle. We know the distance between all pairs of neighboring stops where distance[i] is the distance between the stops number i and (i + 1) % n.

\r\n\r\n

The bus goes along both directions i.e. clockwise and counterclockwise.

\r\n\r\n

Return the shortest distance between the given start and destination stops.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n

\"\"

\r\n\r\n
\r\nInput: distance = [1,2,3,4], start = 0, destination = 1\r\nOutput: 1\r\nExplanation: Distance between 0 and 1 is 1 or 9, minimum is 1.
\r\n\r\n

 

\r\n\r\n

Example 2:

\r\n\r\n

\"\"

\r\n\r\n
\r\nInput: distance = [1,2,3,4], start = 0, destination = 2\r\nOutput: 3\r\nExplanation: Distance between 0 and 2 is 3 or 7, minimum is 3.\r\n
\r\n\r\n

 

\r\n\r\n

Example 3:

\r\n\r\n

\"\"

\r\n\r\n
\r\nInput: distance = [1,2,3,4], start = 0, destination = 3\r\nOutput: 4\r\nExplanation: Distance between 0 and 3 is 6 or 4, minimum is 4.\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= n <= 10^4
  • \r\n\t
  • distance.length == n
  • \r\n\t
  • 0 <= start, destination < n
  • \r\n\t
  • 0 <= distance[i] <= 10^4
  • \r\n
", "content_cn": "

\u73af\u5f62\u516c\u4ea4\u8def\u7ebf\u4e0a\u6709 n \u4e2a\u7ad9\uff0c\u6309\u6b21\u5e8f\u4ece 0 \u5230 n - 1 \u8fdb\u884c\u7f16\u53f7\u3002\u6211\u4eec\u5df2\u77e5\u6bcf\u4e00\u5bf9\u76f8\u90bb\u516c\u4ea4\u7ad9\u4e4b\u95f4\u7684\u8ddd\u79bb\uff0cdistance[i] \u8868\u793a\u7f16\u53f7\u4e3a i \u7684\u8f66\u7ad9\u548c\u7f16\u53f7\u4e3a (i + 1) % n \u7684\u8f66\u7ad9\u4e4b\u95f4\u7684\u8ddd\u79bb\u3002

\n\n

\u73af\u7ebf\u4e0a\u7684\u516c\u4ea4\u8f66\u90fd\u53ef\u4ee5\u6309\u987a\u65f6\u9488\u548c\u9006\u65f6\u9488\u7684\u65b9\u5411\u884c\u9a76\u3002

\n\n

\u8fd4\u56de\u4e58\u5ba2\u4ece\u51fa\u53d1\u70b9 start \u5230\u76ee\u7684\u5730 destination \u4e4b\u95f4\u7684\u6700\u77ed\u8ddd\u79bb\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1adistance = [1,2,3,4], start = 0, destination = 1\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u516c\u4ea4\u7ad9 0 \u548c 1 \u4e4b\u95f4\u7684\u8ddd\u79bb\u662f 1 \u6216 9\uff0c\u6700\u5c0f\u503c\u662f 1\u3002
\n\n

 

\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1adistance = [1,2,3,4], start = 0, destination = 2\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u516c\u4ea4\u7ad9 0 \u548c 2 \u4e4b\u95f4\u7684\u8ddd\u79bb\u662f 3 \u6216 7\uff0c\u6700\u5c0f\u503c\u662f 3\u3002\n
\n\n

 

\n\n

\u793a\u4f8b 3\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1adistance = [1,2,3,4], start = 0, destination = 3\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u516c\u4ea4\u7ad9 0 \u548c 3 \u4e4b\u95f4\u7684\u8ddd\u79bb\u662f 6 \u6216 4\uff0c\u6700\u5c0f\u503c\u662f 4\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 10^4
  • \n\t
  • distance.length == n
  • \n\t
  • 0 <= start, destination < n
  • \n\t
  • 0 <= distance[i] <= 10^4
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int distanceBetweenBusStops(vector& distance, int start, int destination) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int distanceBetweenBusStops(int[] distance, int start, int destination) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def distanceBetweenBusStops(self, distance, start, destination):\n \"\"\"\n :type distance: List[int]\n :type start: int\n :type destination: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def distanceBetweenBusStops(self, distance: List[int], start: int, destination: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint distanceBetweenBusStops(int* distance, int distanceSize, int start, int destination){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int DistanceBetweenBusStops(int[] distance, int start, int destination) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} distance\n * @param {number} start\n * @param {number} destination\n * @return {number}\n */\nvar distanceBetweenBusStops = function(distance, start, destination) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} distance\n# @param {Integer} start\n# @param {Integer} destination\n# @return {Integer}\ndef distance_between_bus_stops(distance, start, destination)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func distanceBetweenBusStops(_ distance: [Int], _ start: Int, _ destination: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func distanceBetweenBusStops(distance []int, start int, destination int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def distanceBetweenBusStops(distance: Array[Int], start: Int, destination: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun distanceBetweenBusStops(distance: IntArray, start: Int, destination: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn distance_between_bus_stops(distance: Vec, start: i32, destination: i32) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $distance\n * @param Integer $start\n * @param Integer $destination\n * @return Integer\n */\n function distanceBetweenBusStops($distance, $start, $destination) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function distanceBetweenBusStops(distance: number[], start: number, destination: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (distance-between-bus-stops distance start destination)\n (-> (listof exact-integer?) exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1184](https://leetcode-cn.com/problems/distance-between-bus-stops)", "[\u516c\u4ea4\u7ad9\u95f4\u7684\u8ddd\u79bb](/solution/1100-1199/1184.Distance%20Between%20Bus%20Stops/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1184](https://leetcode.com/problems/distance-between-bus-stops)", "[Distance Between Bus Stops](/solution/1100-1199/1184.Distance%20Between%20Bus%20Stops/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1286", "frontend_question_id": "1425", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/constrained-subsequence-sum", "url_en": "https://leetcode.com/problems/constrained-subsequence-sum", "relative_path_cn": "/solution/1400-1499/1425.Constrained%20Subsequence%20Sum/README.md", "relative_path_en": "/solution/1400-1499/1425.Constrained%20Subsequence%20Sum/README_EN.md", "title_cn": "\u5e26\u9650\u5236\u7684\u5b50\u5e8f\u5217\u548c", "title_en": "Constrained Subsequence Sum", "question_title_slug": "constrained-subsequence-sum", "content_en": "

Given an integer array nums and an integer k, return the maximum sum of a non-empty subsequence of that array such that for every two consecutive integers in the subsequence, nums[i] and nums[j], where i < j, the condition j - i <= k is satisfied.

\n\n

A subsequence of an array is obtained by deleting some number of elements (can be zero) from the array, leaving the remaining elements in their original order.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [10,2,-10,5,20], k = 2\nOutput: 37\nExplanation: The subsequence is [10, 2, 5, 20].\n
\n\n

Example 2:

\n\n
\nInput: nums = [-1,-2,-3], k = 1\nOutput: -1\nExplanation: The subsequence must be non-empty, so we choose the largest number.\n
\n\n

Example 3:

\n\n
\nInput: nums = [10,-2,-10,-5,20], k = 2\nOutput: 23\nExplanation: The subsequence is [10, -2, -5, 20].\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= k <= nums.length <= 105
  • \n\t
  • -104 <= nums[i] <= 104
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \u548c\u4e00\u4e2a\u6574\u6570 k \uff0c\u8bf7\u4f60\u8fd4\u56de \u975e\u7a7a \u5b50\u5e8f\u5217\u5143\u7d20\u548c\u7684\u6700\u5927\u503c\uff0c\u5b50\u5e8f\u5217\u9700\u8981\u6ee1\u8db3\uff1a\u5b50\u5e8f\u5217\u4e2d\u6bcf\u4e24\u4e2a \u76f8\u90bb \u7684\u6574\u6570 nums[i] \u548c nums[j] \uff0c\u5b83\u4eec\u5728\u539f\u6570\u7ec4\u4e2d\u7684\u4e0b\u6807 i \u548c j \u6ee1\u8db3 i < j \u4e14 j - i <= k \u3002

\n\n

\u6570\u7ec4\u7684\u5b50\u5e8f\u5217\u5b9a\u4e49\u4e3a\uff1a\u5c06\u6570\u7ec4\u4e2d\u7684\u82e5\u5e72\u4e2a\u6570\u5b57\u5220\u9664\uff08\u53ef\u4ee5\u5220\u9664 0 \u4e2a\u6570\u5b57\uff09\uff0c\u5269\u4e0b\u7684\u6570\u5b57\u6309\u7167\u539f\u672c\u7684\u987a\u5e8f\u6392\u5e03\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anums = [10,2,-10,5,20], k = 2\n\u8f93\u51fa\uff1a37\n\u89e3\u91ca\uff1a\u5b50\u5e8f\u5217\u4e3a [10, 2, 5, 20] \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anums = [-1,-2,-3], k = 1\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u5b50\u5e8f\u5217\u5fc5\u987b\u662f\u975e\u7a7a\u7684\uff0c\u6240\u4ee5\u6211\u4eec\u9009\u62e9\u6700\u5927\u7684\u6570\u5b57\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1anums = [10,-2,-10,-5,20], k = 2\n\u8f93\u51fa\uff1a23\n\u89e3\u91ca\uff1a\u5b50\u5e8f\u5217\u4e3a [10, -2, -5, 20] \u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= k <= nums.length <= 10^5
  • \n\t
  • -10^4 <= nums[i] <= 10^4
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int constrainedSubsetSum(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int constrainedSubsetSum(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def constrainedSubsetSum(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def constrainedSubsetSum(self, nums: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint constrainedSubsetSum(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ConstrainedSubsetSum(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar constrainedSubsetSum = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef constrained_subset_sum(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func constrainedSubsetSum(_ nums: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func constrainedSubsetSum(nums []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def constrainedSubsetSum(nums: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun constrainedSubsetSum(nums: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn constrained_subset_sum(nums: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer\n */\n function constrainedSubsetSum($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function constrainedSubsetSum(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (constrained-subset-sum nums k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1425](https://leetcode-cn.com/problems/constrained-subsequence-sum)", "[\u5e26\u9650\u5236\u7684\u5b50\u5e8f\u5217\u548c](/solution/1400-1499/1425.Constrained%20Subsequence%20Sum/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1425](https://leetcode.com/problems/constrained-subsequence-sum)", "[Constrained Subsequence Sum](/solution/1400-1499/1425.Constrained%20Subsequence%20Sum/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1285", "frontend_question_id": "1382", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/balance-a-binary-search-tree", "url_en": "https://leetcode.com/problems/balance-a-binary-search-tree", "relative_path_cn": "/solution/1300-1399/1382.Balance%20a%20Binary%20Search%20Tree/README.md", "relative_path_en": "/solution/1300-1399/1382.Balance%20a%20Binary%20Search%20Tree/README_EN.md", "title_cn": "\u5c06\u4e8c\u53c9\u641c\u7d22\u6811\u53d8\u5e73\u8861", "title_en": "Balance a Binary Search Tree", "question_title_slug": "balance-a-binary-search-tree", "content_en": "

Given a binary search tree, return a balanced binary search tree with the same node values.

\r\n\r\n

A binary search tree is balanced if and only if the depth of the two subtrees of every node never differ by more than 1.

\r\n\r\n

If there is more than one answer, return any of them.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n

\"\"\"\"

\r\n\r\n
\r\nInput: root = [1,null,2,null,3,null,4,null,null]\r\nOutput: [2,1,3,null,null,null,4]\r\nExplanation: This is not the only correct answer, [3,1,4,null,2,null,null] is also correct.\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • The number of nodes in the tree is between 1 and 10^4.
  • \r\n\t
  • The tree nodes will have distinct values between 1 and 10^5.
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u68f5\u4e8c\u53c9\u641c\u7d22\u6811\uff0c\u8bf7\u4f60\u8fd4\u56de\u4e00\u68f5 \u5e73\u8861\u540e \u7684\u4e8c\u53c9\u641c\u7d22\u6811\uff0c\u65b0\u751f\u6210\u7684\u6811\u5e94\u8be5\u4e0e\u539f\u6765\u7684\u6811\u6709\u7740\u76f8\u540c\u7684\u8282\u70b9\u503c\u3002

\n\n

\u5982\u679c\u4e00\u68f5\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\uff0c\u6bcf\u4e2a\u8282\u70b9\u7684\u4e24\u68f5\u5b50\u6811\u9ad8\u5ea6\u5dee\u4e0d\u8d85\u8fc7 1 \uff0c\u6211\u4eec\u5c31\u79f0\u8fd9\u68f5\u4e8c\u53c9\u641c\u7d22\u6811\u662f \u5e73\u8861\u7684 \u3002

\n\n

\u5982\u679c\u6709\u591a\u79cd\u6784\u9020\u65b9\u6cd5\uff0c\u8bf7\u4f60\u8fd4\u56de\u4efb\u610f\u4e00\u79cd\u3002

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n

\"\"\"\"

\n\n
\u8f93\u5165\uff1aroot = [1,null,2,null,3,null,4,null,null]\n\u8f93\u51fa\uff1a[2,1,3,null,null,null,4]\n\u89e3\u91ca\uff1a\u8fd9\u4e0d\u662f\u552f\u4e00\u7684\u6b63\u786e\u7b54\u6848\uff0c[3,1,4,null,2,null,null] \u4e5f\u662f\u4e00\u4e2a\u53ef\u884c\u7684\u6784\u9020\u65b9\u6848\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u6811\u8282\u70b9\u7684\u6570\u76ee\u5728 1 \u5230 10^4 \u4e4b\u95f4\u3002
  • \n\t
  • \u6811\u8282\u70b9\u7684\u503c\u4e92\u4e0d\u76f8\u540c\uff0c\u4e14\u5728 1 \u5230 10^5 \u4e4b\u95f4\u3002
  • \n
\n", "tags_en": ["Binary Search Tree"], "tags_cn": ["\u4e8c\u53c9\u641c\u7d22\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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 */\nclass Solution {\npublic:\n TreeNode* balanceBST(TreeNode* root) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode(int x) { val = x; }\n * }\n */\nclass Solution {\n public TreeNode balanceBST(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution(object):\n def balanceBST(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: TreeNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution:\n def balanceBST(self, root: TreeNode) -> TreeNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* balanceBST(struct TreeNode* root){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int x) { val = x; }\n * }\n */\npublic class Solution {\n public TreeNode BalanceBST(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val) {\n * this.val = val;\n * this.left = this.right = null;\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {TreeNode}\n */\nvar balanceBST = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val)\n# @val = val\n# @left, @right = nil, nil\n# end\n# end\n\n# @param {TreeNode} root\n# @return {TreeNode}\ndef balance_bst(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.left = nil\n * self.right = nil\n * }\n * }\n */\nclass Solution {\n func balanceBST(_ root: TreeNode?) -> TreeNode? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc balanceBST(root *TreeNode) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(var _value: Int) {\n * var value: Int = _value\n * var left: TreeNode = null\n * var right: TreeNode = null\n * }\n */\nobject Solution {\n def balanceBST(root: TreeNode): TreeNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun balanceBST(root: TreeNode?): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n// \n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn balance_bst(root: Option>>) -> Option>> {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($value) { $this->val = $value; }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return TreeNode\n */\n function balanceBST($root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction balanceBST(root: TreeNode | null): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (balance-bst root)\n (-> (or/c tree-node? #f) (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1382](https://leetcode-cn.com/problems/balance-a-binary-search-tree)", "[\u5c06\u4e8c\u53c9\u641c\u7d22\u6811\u53d8\u5e73\u8861](/solution/1300-1399/1382.Balance%20a%20Binary%20Search%20Tree/README.md)", "`\u4e8c\u53c9\u641c\u7d22\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1382](https://leetcode.com/problems/balance-a-binary-search-tree)", "[Balance a Binary Search Tree](/solution/1300-1399/1382.Balance%20a%20Binary%20Search%20Tree/README_EN.md)", "`Binary Search Tree`", "Medium", ""]}, {"question_id": "1284", "frontend_question_id": "1390", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/four-divisors", "url_en": "https://leetcode.com/problems/four-divisors", "relative_path_cn": "/solution/1300-1399/1390.Four%20Divisors/README.md", "relative_path_en": "/solution/1300-1399/1390.Four%20Divisors/README_EN.md", "title_cn": "\u56db\u56e0\u6570", "title_en": "Four Divisors", "question_title_slug": "four-divisors", "content_en": "

Given an integer array nums, return the sum of divisors of the integers in that array that have exactly four divisors.

\n\n

If there is no such integer in the array, return 0.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [21,4,7]\nOutput: 32\nExplanation:\n21 has 4 divisors: 1, 3, 7, 21\n4 has 3 divisors: 1, 2, 4\n7 has 2 divisors: 1, 7\nThe answer is the sum of divisors of 21 only.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 10^4
  • \n\t
  • 1 <= nums[i] <= 10^5
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums\uff0c\u8bf7\u4f60\u8fd4\u56de\u8be5\u6570\u7ec4\u4e2d\u6070\u6709\u56db\u4e2a\u56e0\u6570\u7684\u8fd9\u4e9b\u6574\u6570\u7684\u5404\u56e0\u6570\u4e4b\u548c\u3002

\n\n

\u5982\u679c\u6570\u7ec4\u4e2d\u4e0d\u5b58\u5728\u6ee1\u8db3\u9898\u610f\u7684\u6574\u6570\uff0c\u5219\u8fd4\u56de 0 \u3002

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1anums = [21,4,7]\n\u8f93\u51fa\uff1a32\n\u89e3\u91ca\uff1a\n21 \u6709 4 \u4e2a\u56e0\u6570\uff1a1, 3, 7, 21\n4 \u6709 3 \u4e2a\u56e0\u6570\uff1a1, 2, 4\n7 \u6709 2 \u4e2a\u56e0\u6570\uff1a1, 7\n\u7b54\u6848\u4ec5\u4e3a 21 \u7684\u6240\u6709\u56e0\u6570\u7684\u548c\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 10^4
  • \n\t
  • 1 <= nums[i] <= 10^5
  • \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int sumFourDivisors(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int sumFourDivisors(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def sumFourDivisors(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def sumFourDivisors(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint sumFourDivisors(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SumFourDivisors(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar sumFourDivisors = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef sum_four_divisors(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func sumFourDivisors(_ nums: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func sumFourDivisors(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def sumFourDivisors(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun sumFourDivisors(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sum_four_divisors(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function sumFourDivisors($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function sumFourDivisors(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (sum-four-divisors nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1390](https://leetcode-cn.com/problems/four-divisors)", "[\u56db\u56e0\u6570](/solution/1300-1399/1390.Four%20Divisors/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1390](https://leetcode.com/problems/four-divisors)", "[Four Divisors](/solution/1300-1399/1390.Four%20Divisors/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "1283", "frontend_question_id": "1507", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reformat-date", "url_en": "https://leetcode.com/problems/reformat-date", "relative_path_cn": "/solution/1500-1599/1507.Reformat%20Date/README.md", "relative_path_en": "/solution/1500-1599/1507.Reformat%20Date/README_EN.md", "title_cn": "\u8f6c\u53d8\u65e5\u671f\u683c\u5f0f", "title_en": "Reformat Date", "question_title_slug": "reformat-date", "content_en": "

Given a date string in the form Day Month Year, where:

\n\n
    \n\t
  • Day is in the set {"1st", "2nd", "3rd", "4th", ..., "30th", "31st"}.
  • \n\t
  • Month is in the set {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}.
  • \n\t
  • Year is in the range [1900, 2100].
  • \n
\n\n

Convert the date string to the format YYYY-MM-DD, where:

\n\n
    \n\t
  • YYYY denotes the 4 digit year.
  • \n\t
  • MM denotes the 2 digit month.
  • \n\t
  • DD denotes the 2 digit day.
  • \n
\n\n

 

\n

Example 1:

\n\n
\nInput: date = "20th Oct 2052"\nOutput: "2052-10-20"\n
\n\n

Example 2:

\n\n
\nInput: date = "6th Jun 1933"\nOutput: "1933-06-06"\n
\n\n

Example 3:

\n\n
\nInput: date = "26th May 1960"\nOutput: "1960-05-26"\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The given dates are guaranteed to be valid, so no error handling is necessary.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 date \uff0c\u5b83\u7684\u683c\u5f0f\u4e3a Day Month Year \uff0c\u5176\u4e2d\uff1a

\n\n
    \n\t
  • Day \u662f\u96c6\u5408 {"1st", "2nd", "3rd", "4th", ..., "30th", "31st"} \u4e2d\u7684\u4e00\u4e2a\u5143\u7d20\u3002
  • \n\t
  • Month \u662f\u96c6\u5408 {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"} \u4e2d\u7684\u4e00\u4e2a\u5143\u7d20\u3002
  • \n\t
  • Year \u7684\u8303\u56f4\u5728 \u200b[1900, 2100] \u4e4b\u95f4\u3002
  • \n
\n\n

\u8bf7\u4f60\u5c06\u5b57\u7b26\u4e32\u8f6c\u53d8\u4e3a YYYY-MM-DD \u7684\u683c\u5f0f\uff0c\u5176\u4e2d\uff1a

\n\n
    \n\t
  • YYYY \u8868\u793a 4 \u4f4d\u7684\u5e74\u4efd\u3002
  • \n\t
  • MM \u8868\u793a 2 \u4f4d\u7684\u6708\u4efd\u3002
  • \n\t
  • DD \u8868\u793a 2 \u4f4d\u7684\u5929\u6570\u3002
  • \n
\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1adate = "20th Oct 2052"\n\u8f93\u51fa\uff1a"2052-10-20"\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1adate = "6th Jun 1933"\n\u8f93\u51fa\uff1a"1933-06-06"\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1adate = "26th May 1960"\n\u8f93\u51fa\uff1a"1960-05-26"\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u7ed9\u5b9a\u65e5\u671f\u4fdd\u8bc1\u662f\u5408\u6cd5\u7684\uff0c\u6240\u4ee5\u4e0d\u9700\u8981\u5904\u7406\u5f02\u5e38\u8f93\u5165\u3002
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string reformatDate(string date) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String reformatDate(String date) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def reformatDate(self, date):\n \"\"\"\n :type date: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def reformatDate(self, date: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * reformatDate(char * date){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ReformatDate(string date) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} date\n * @return {string}\n */\nvar reformatDate = function(date) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} date\n# @return {String}\ndef reformat_date(date)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func reformatDate(_ date: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func reformatDate(date string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def reformatDate(date: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun reformatDate(date: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn reformat_date(date: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $date\n * @return String\n */\n function reformatDate($date) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function reformatDate(date: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (reformat-date date)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1507](https://leetcode-cn.com/problems/reformat-date)", "[\u8f6c\u53d8\u65e5\u671f\u683c\u5f0f](/solution/1500-1599/1507.Reformat%20Date/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1507](https://leetcode.com/problems/reformat-date)", "[Reformat Date](/solution/1500-1599/1507.Reformat%20Date/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1282", "frontend_question_id": "1178", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-valid-words-for-each-puzzle", "url_en": "https://leetcode.com/problems/number-of-valid-words-for-each-puzzle", "relative_path_cn": "/solution/1100-1199/1178.Number%20of%20Valid%20Words%20for%20Each%20Puzzle/README.md", "relative_path_en": "/solution/1100-1199/1178.Number%20of%20Valid%20Words%20for%20Each%20Puzzle/README_EN.md", "title_cn": "\u731c\u5b57\u8c1c", "title_en": "Number of Valid Words for Each Puzzle", "question_title_slug": "number-of-valid-words-for-each-puzzle", "content_en": "With respect to a given puzzle string, a word is valid if both the following conditions are satisfied:\n
    \n\t
  • word contains the first letter of puzzle.
  • \n\t
  • For each letter in word, that letter is in puzzle.
    \n\tFor example, if the puzzle is "abcdefg", then valid words are "faced", "cabbage", and "baggage"; while invalid words are "beefed" (doesn't include "a") and "based" (includes "s" which isn't in the puzzle).
  • \n
\nReturn an array answer, where answer[i] is the number of words in the given word list words that are valid with respect to the puzzle puzzles[i].\n

 

\n

Example :

\n\n
\nInput: \nwords = ["aaaa","asas","able","ability","actt","actor","access"], \npuzzles = ["aboveyz","abrodyz","abslute","absoryz","actresz","gaswxyz"]\nOutput: [1,1,3,2,4,0]\nExplanation:\n1 valid word for "aboveyz" : "aaaa" \n1 valid word for "abrodyz" : "aaaa"\n3 valid words for "abslute" : "aaaa", "asas", "able"\n2 valid words for "absoryz" : "aaaa", "asas"\n4 valid words for "actresz" : "aaaa", "asas", "actt", "access"\nThere're no valid words for "gaswxyz" cause none of the words in the list contains letter 'g'.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= words.length <= 10^5
  • \n\t
  • 4 <= words[i].length <= 50
  • \n\t
  • 1 <= puzzles.length <= 10^4
  • \n\t
  • puzzles[i].length == 7
  • \n\t
  • words[i][j], puzzles[i][j] are English lowercase letters.
  • \n\t
  • Each puzzles[i] doesn't contain repeated characters.
  • \n
\n", "content_cn": "

\u5916\u56fd\u53cb\u4eba\u4eff\u7167\u4e2d\u56fd\u5b57\u8c1c\u8bbe\u8ba1\u4e86\u4e00\u4e2a\u82f1\u6587\u7248\u731c\u5b57\u8c1c\u5c0f\u6e38\u620f\uff0c\u8bf7\u4f60\u6765\u731c\u731c\u770b\u5427\u3002

\n\n

\u5b57\u8c1c\u7684\u8ff7\u9762\u00a0puzzle \u6309\u5b57\u7b26\u4e32\u5f62\u5f0f\u7ed9\u51fa\uff0c\u5982\u679c\u4e00\u4e2a\u5355\u8bcd\u00a0word\u00a0\u7b26\u5408\u4e0b\u9762\u4e24\u4e2a\u6761\u4ef6\uff0c\u90a3\u4e48\u5b83\u5c31\u53ef\u4ee5\u7b97\u4f5c\u8c1c\u5e95\uff1a

\n\n
    \n\t
  • \u5355\u8bcd\u00a0word\u00a0\u4e2d\u5305\u542b\u8c1c\u9762\u00a0puzzle\u00a0\u7684\u7b2c\u4e00\u4e2a\u5b57\u6bcd\u3002
  • \n\t
  • \u5355\u8bcd\u00a0word\u00a0\u4e2d\u7684\u6bcf\u4e00\u4e2a\u5b57\u6bcd\u90fd\u53ef\u4ee5\u5728\u8c1c\u9762\u00a0puzzle\u00a0\u4e2d\u627e\u5230\u3002
    \n\t\u4f8b\u5982\uff0c\u5982\u679c\u5b57\u8c1c\u7684\u8c1c\u9762\u662f \"abcdefg\"\uff0c\u90a3\u4e48\u53ef\u4ee5\u4f5c\u4e3a\u8c1c\u5e95\u7684\u5355\u8bcd\u6709 \"faced\", \"cabbage\", \u548c \"baggage\"\uff1b\u800c \"beefed\"\uff08\u4e0d\u542b\u5b57\u6bcd \"a\"\uff09\u4ee5\u53ca\u00a0\"based\"\uff08\u5176\u4e2d\u7684 \"s\" \u6ca1\u6709\u51fa\u73b0\u5728\u8c1c\u9762\u4e2d\uff09\u90fd\u4e0d\u80fd\u4f5c\u4e3a\u8c1c\u5e95\u3002
  • \n
\n\n

\u8fd4\u56de\u4e00\u4e2a\u7b54\u6848\u6570\u7ec4\u00a0answer\uff0c\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u00a0answer[i]\u00a0\u662f\u5728\u7ed9\u51fa\u7684\u5355\u8bcd\u5217\u8868 words \u4e2d\u53ef\u4ee5\u4f5c\u4e3a\u5b57\u8c1c\u8ff7\u9762\u00a0puzzles[i]\u00a0\u6240\u5bf9\u5e94\u7684\u8c1c\u5e95\u7684\u5355\u8bcd\u6570\u76ee\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b\uff1a

\n\n
\n\u8f93\u5165\uff1a\nwords = [\"aaaa\",\"asas\",\"able\",\"ability\",\"actt\",\"actor\",\"access\"], \npuzzles = [\"aboveyz\",\"abrodyz\",\"abslute\",\"absoryz\",\"actresz\",\"gaswxyz\"]\n\u8f93\u51fa\uff1a[1,1,3,2,4,0]\n\u89e3\u91ca\uff1a\n1 \u4e2a\u5355\u8bcd\u53ef\u4ee5\u4f5c\u4e3a \"aboveyz\" \u7684\u8c1c\u5e95 : \"aaaa\" \n1 \u4e2a\u5355\u8bcd\u53ef\u4ee5\u4f5c\u4e3a \"abrodyz\" \u7684\u8c1c\u5e95 : \"aaaa\"\n3 \u4e2a\u5355\u8bcd\u53ef\u4ee5\u4f5c\u4e3a \"abslute\" \u7684\u8c1c\u5e95 : \"aaaa\", \"asas\", \"able\"\n2 \u4e2a\u5355\u8bcd\u53ef\u4ee5\u4f5c\u4e3a\u00a0\"absoryz\" \u7684\u8c1c\u5e95 : \"aaaa\", \"asas\"\n4 \u4e2a\u5355\u8bcd\u53ef\u4ee5\u4f5c\u4e3a\u00a0\"actresz\" \u7684\u8c1c\u5e95 : \"aaaa\", \"asas\", \"actt\", \"access\"\n\u6ca1\u6709\u5355\u8bcd\u53ef\u4ee5\u4f5c\u4e3a\u00a0\"gaswxyz\" \u7684\u8c1c\u5e95\uff0c\u56e0\u4e3a\u5217\u8868\u4e2d\u7684\u5355\u8bcd\u90fd\u4e0d\u542b\u5b57\u6bcd 'g'\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= words.length <= 10^5
  • \n\t
  • 4 <= words[i].length <= 50
  • \n\t
  • 1 <= puzzles.length <= 10^4
  • \n\t
  • puzzles[i].length == 7
  • \n\t
  • words[i][j], puzzles[i][j]\u00a0\u90fd\u662f\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
  • \n\t
  • \u6bcf\u4e2a\u00a0puzzles[i]\u00a0\u6240\u5305\u542b\u7684\u5b57\u7b26\u90fd\u4e0d\u91cd\u590d\u3002
  • \n
\n", "tags_en": ["Bit Manipulation", "Hash Table"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u54c8\u5e0c\u8868"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findNumOfValidWords(vector& words, vector& puzzles) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List findNumOfValidWords(String[] words, String[] puzzles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findNumOfValidWords(self, words, puzzles):\n \"\"\"\n :type words: List[str]\n :type puzzles: List[str]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findNumOfValidWords(self, words: List[str], puzzles: List[str]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* findNumOfValidWords(char ** words, int wordsSize, char ** puzzles, int puzzlesSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList FindNumOfValidWords(string[] words, string[] puzzles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @param {string[]} puzzles\n * @return {number[]}\n */\nvar findNumOfValidWords = function(words, puzzles) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @param {String[]} puzzles\n# @return {Integer[]}\ndef find_num_of_valid_words(words, puzzles)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findNumOfValidWords(_ words: [String], _ puzzles: [String]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findNumOfValidWords(words []string, puzzles []string) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findNumOfValidWords(words: Array[String], puzzles: Array[String]): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findNumOfValidWords(words: Array, puzzles: Array): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_num_of_valid_words(words: Vec, puzzles: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @param String[] $puzzles\n * @return Integer[]\n */\n function findNumOfValidWords($words, $puzzles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findNumOfValidWords(words: string[], puzzles: string[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-num-of-valid-words words puzzles)\n (-> (listof string?) (listof string?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1178](https://leetcode-cn.com/problems/number-of-valid-words-for-each-puzzle)", "[\u731c\u5b57\u8c1c](/solution/1100-1199/1178.Number%20of%20Valid%20Words%20for%20Each%20Puzzle/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u54c8\u5e0c\u8868`", "\u56f0\u96be", ""], "md_table_row_en": ["[1178](https://leetcode.com/problems/number-of-valid-words-for-each-puzzle)", "[Number of Valid Words for Each Puzzle](/solution/1100-1199/1178.Number%20of%20Valid%20Words%20for%20Each%20Puzzle/README_EN.md)", "`Bit Manipulation`,`Hash Table`", "Hard", ""]}, {"question_id": "1281", "frontend_question_id": "1177", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/can-make-palindrome-from-substring", "url_en": "https://leetcode.com/problems/can-make-palindrome-from-substring", "relative_path_cn": "/solution/1100-1199/1177.Can%20Make%20Palindrome%20from%20Substring/README.md", "relative_path_en": "/solution/1100-1199/1177.Can%20Make%20Palindrome%20from%20Substring/README_EN.md", "title_cn": "\u6784\u5efa\u56de\u6587\u4e32\u68c0\u6d4b", "title_en": "Can Make Palindrome from Substring", "question_title_slug": "can-make-palindrome-from-substring", "content_en": "

Given a string s, we make queries on substrings of s.

\n\n

For each query queries[i] = [left, right, k], we may rearrange the substring s[left], ..., s[right], and then choose up to k of them to replace with any lowercase English letter. 

\n\n

If the substring is possible to be a palindrome string after the operations above, the result of the query is true. Otherwise, the result is false.

\n\n

Return an array answer[], where answer[i] is the result of the i-th query queries[i].

\n\n

Note that: Each letter is counted individually for replacement so if for example s[left..right] = "aaa", and k = 2, we can only replace two of the letters.  (Also, note that the initial string s is never modified by any query.)

\n\n

 

\n

Example :

\n\n
\nInput: s = "abcda", queries = [[3,3,0],[1,2,0],[0,3,1],[0,3,2],[0,4,1]]\nOutput: [true,false,false,true,true]\nExplanation:\nqueries[0] : substring = "d", is palidrome.\nqueries[1] : substring = "bc", is not palidrome.\nqueries[2] : substring = "abcd", is not palidrome after replacing only 1 character.\nqueries[3] : substring = "abcd", could be changed to "abba" which is palidrome. Also this can be changed to "baab" first rearrange it "bacd" then replace "cd" with "ab".\nqueries[4] : substring = "abcda", could be changed to "abcba" which is palidrome.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length, queries.length <= 10^5
  • \n\t
  • 0 <= queries[i][0] <= queries[i][1] < s.length
  • \n\t
  • 0 <= queries[i][2] <= s.length
  • \n\t
  • s only contains lowercase English letters.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s\uff0c\u8bf7\u4f60\u5bf9 s \u7684\u5b50\u4e32\u8fdb\u884c\u68c0\u6d4b\u3002

\n\n

\u6bcf\u6b21\u68c0\u6d4b\uff0c\u5f85\u68c0\u5b50\u4e32\u90fd\u53ef\u4ee5\u8868\u793a\u4e3a queries[i] = [left, right, k]\u3002\u6211\u4eec\u53ef\u4ee5 \u91cd\u65b0\u6392\u5217 \u5b50\u4e32 s[left], ..., s[right]\uff0c\u5e76\u4ece\u4e2d\u9009\u62e9 \u6700\u591a k \u9879\u66ff\u6362\u6210\u4efb\u4f55\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002 

\n\n

\u5982\u679c\u5728\u4e0a\u8ff0\u68c0\u6d4b\u8fc7\u7a0b\u4e2d\uff0c\u5b50\u4e32\u53ef\u4ee5\u53d8\u6210\u56de\u6587\u5f62\u5f0f\u7684\u5b57\u7b26\u4e32\uff0c\u90a3\u4e48\u68c0\u6d4b\u7ed3\u679c\u4e3a true\uff0c\u5426\u5219\u7ed3\u679c\u4e3a false\u3002

\n\n

\u8fd4\u56de\u7b54\u6848\u6570\u7ec4 answer[]\uff0c\u5176\u4e2d answer[i] \u662f\u7b2c i \u4e2a\u5f85\u68c0\u5b50\u4e32 queries[i] \u7684\u68c0\u6d4b\u7ed3\u679c\u3002

\n\n

\u6ce8\u610f\uff1a\u5728\u66ff\u6362\u65f6\uff0c\u5b50\u4e32\u4e2d\u7684\u6bcf\u4e2a\u5b57\u6bcd\u90fd\u5fc5\u987b\u4f5c\u4e3a \u72ec\u7acb\u7684 \u9879\u8fdb\u884c\u8ba1\u6570\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u5982\u679c s[left..right] = "aaa" \u4e14 k = 2\uff0c\u6211\u4eec\u53ea\u80fd\u66ff\u6362\u5176\u4e2d\u7684\u4e24\u4e2a\u5b57\u6bcd\u3002\uff08\u53e6\u5916\uff0c\u4efb\u4f55\u68c0\u6d4b\u90fd\u4e0d\u4f1a\u4fee\u6539\u539f\u59cb\u5b57\u7b26\u4e32 s\uff0c\u53ef\u4ee5\u8ba4\u4e3a\u6bcf\u6b21\u68c0\u6d4b\u90fd\u662f\u72ec\u7acb\u7684\uff09

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1as = "abcda", queries = [[3,3,0],[1,2,0],[0,3,1],[0,3,2],[0,4,1]]\n\u8f93\u51fa\uff1a[true,false,false,true,true]\n\u89e3\u91ca\uff1a\nqueries[0] : \u5b50\u4e32 = "d"\uff0c\u56de\u6587\u3002\nqueries[1] : \u5b50\u4e32 = "bc"\uff0c\u4e0d\u662f\u56de\u6587\u3002\nqueries[2] : \u5b50\u4e32 = "abcd"\uff0c\u53ea\u66ff\u6362 1 \u4e2a\u5b57\u7b26\u662f\u53d8\u4e0d\u6210\u56de\u6587\u4e32\u7684\u3002\nqueries[3] : \u5b50\u4e32 = "abcd"\uff0c\u53ef\u4ee5\u53d8\u6210\u56de\u6587\u7684 "abba"\u3002 \u4e5f\u53ef\u4ee5\u53d8\u6210 "baab"\uff0c\u5148\u91cd\u65b0\u6392\u5e8f\u53d8\u6210 "bacd"\uff0c\u7136\u540e\u628a "cd" \u66ff\u6362\u4e3a "ab"\u3002\nqueries[4] : \u5b50\u4e32 = "abcda"\uff0c\u53ef\u4ee5\u53d8\u6210\u56de\u6587\u7684 "abcba"\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length, queries.length <= 10^5
  • \n\t
  • 0 <= queries[i][0] <= queries[i][1] < s.length
  • \n\t
  • 0 <= queries[i][2] <= s.length
  • \n\t
  • s \u4e2d\u53ea\u6709\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd
  • \n
\n", "tags_en": ["Array", "String"], "tags_cn": ["\u6570\u7ec4", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector canMakePaliQueries(string s, vector>& queries) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List canMakePaliQueries(String s, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canMakePaliQueries(self, s, queries):\n \"\"\"\n :type s: str\n :type queries: List[List[int]]\n :rtype: List[bool]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canMakePaliQueries(self, s: str, queries: List[List[int]]) -> List[bool]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nbool* canMakePaliQueries(char * s, int** queries, int queriesSize, int* queriesColSize, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList CanMakePaliQueries(string s, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number[][]} queries\n * @return {boolean[]}\n */\nvar canMakePaliQueries = function(s, queries) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer[][]} queries\n# @return {Boolean[]}\ndef can_make_pali_queries(s, queries)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canMakePaliQueries(_ s: String, _ queries: [[Int]]) -> [Bool] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canMakePaliQueries(s string, queries [][]int) []bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canMakePaliQueries(s: String, queries: Array[Array[Int]]): Array[Boolean] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canMakePaliQueries(s: String, queries: Array): BooleanArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_make_pali_queries(s: String, queries: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer[][] $queries\n * @return Boolean[]\n */\n function canMakePaliQueries($s, $queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canMakePaliQueries(s: string, queries: number[][]): boolean[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-make-pali-queries s queries)\n (-> string? (listof (listof exact-integer?)) (listof boolean?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1177](https://leetcode-cn.com/problems/can-make-palindrome-from-substring)", "[\u6784\u5efa\u56de\u6587\u4e32\u68c0\u6d4b](/solution/1100-1199/1177.Can%20Make%20Palindrome%20from%20Substring/README.md)", "`\u6570\u7ec4`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1177](https://leetcode.com/problems/can-make-palindrome-from-substring)", "[Can Make Palindrome from Substring](/solution/1100-1199/1177.Can%20Make%20Palindrome%20from%20Substring/README_EN.md)", "`Array`,`String`", "Medium", ""]}, {"question_id": "1280", "frontend_question_id": "1176", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/diet-plan-performance", "url_en": "https://leetcode.com/problems/diet-plan-performance", "relative_path_cn": "/solution/1100-1199/1176.Diet%20Plan%20Performance/README.md", "relative_path_en": "/solution/1100-1199/1176.Diet%20Plan%20Performance/README_EN.md", "title_cn": "\u5065\u8eab\u8ba1\u5212\u8bc4\u4f30", "title_en": "Diet Plan Performance", "question_title_slug": "diet-plan-performance", "content_en": "

A dieter consumes calories[i] calories on the i-th day. 

\n\n

Given an integer k, for every consecutive sequence of k days (calories[i], calories[i+1], ..., calories[i+k-1] for all 0 <= i <= n-k), they look at T, the total calories consumed during that sequence of k days (calories[i] + calories[i+1] + ... + calories[i+k-1]):

\n\n
    \n\t
  • If T < lower, they performed poorly on their diet and lose 1 point; 
  • \n\t
  • If T > upper, they performed well on their diet and gain 1 point;
  • \n\t
  • Otherwise, they performed normally and there is no change in points.
  • \n
\n\n

Initially, the dieter has zero points. Return the total number of points the dieter has after dieting for calories.length days.

\n\n

Note that the total points can be negative.

\n\n

 

\n

Example 1:

\n\n
\nInput: calories = [1,2,3,4,5], k = 1, lower = 3, upper = 3\nOutput: 0\nExplanation: Since k = 1, we consider each element of the array separately and compare it to lower and upper.\ncalories[0] and calories[1] are less than lower so 2 points are lost.\ncalories[3] and calories[4] are greater than upper so 2 points are gained.\n
\n\n

Example 2:

\n\n
\nInput: calories = [3,2], k = 2, lower = 0, upper = 1\nOutput: 1\nExplanation: Since k = 2, we consider subarrays of length 2.\ncalories[0] + calories[1] > upper so 1 point is gained.\n
\n\n

Example 3:

\n\n
\nInput: calories = [6,5,0,0], k = 2, lower = 1, upper = 5\nOutput: 0\nExplanation:\ncalories[0] + calories[1] > upper so 1 point is gained.\nlower <= calories[1] + calories[2] <= upper so no change in points.\ncalories[2] + calories[3] < lower so 1 point is lost.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= k <= calories.length <= 10^5
  • \n\t
  • 0 <= calories[i] <= 20000
  • \n\t
  • 0 <= lower <= upper
  • \n
\n", "content_cn": "

\u4f60\u7684\u597d\u53cb\u662f\u4e00\u4f4d\u5065\u8eab\u7231\u597d\u8005\u3002\u524d\u6bb5\u65e5\u5b50\uff0c\u4ed6\u7ed9\u81ea\u5df1\u5236\u5b9a\u4e86\u4e00\u4efd\u5065\u8eab\u8ba1\u5212\u3002\u73b0\u5728\u60f3\u8bf7\u4f60\u5e2e\u4ed6\u8bc4\u4f30\u4e00\u4e0b\u8fd9\u4efd\u8ba1\u5212\u662f\u5426\u5408\u7406\u3002

\n\n

\u4ed6\u4f1a\u6709\u4e00\u4efd\u8ba1\u5212\u6d88\u8017\u7684\u5361\u8def\u91cc\u8868\uff0c\u5176\u4e2d calories[i] \u7ed9\u51fa\u4e86\u4f60\u7684\u8fd9\u4f4d\u597d\u53cb\u5728\u7b2c i \u5929\u9700\u8981\u6d88\u8017\u7684\u5361\u8def\u91cc\u603b\u91cf\u3002

\n\n

\u4e3a\u4e86\u66f4\u597d\u5730\u8bc4\u4f30\u8fd9\u4efd\u8ba1\u5212\uff0c\u5bf9\u4e8e\u5361\u8def\u91cc\u8868\u4e2d\u7684\u6bcf\u4e00\u5929\uff0c\u4f60\u90fd\u9700\u8981\u8ba1\u7b97\u4ed6 \u300c\u8fd9\u4e00\u5929\u4ee5\u53ca\u4e4b\u540e\u7684\u8fde\u7eed\u51e0\u5929\u300d \uff08\u5171 k \u5929\uff09\u5185\u6d88\u8017\u7684\u603b\u5361\u8def\u91cc T\uff1a

\n\n
    \n\t
  • \u5982\u679c T < lower\uff0c\u90a3\u4e48\u8fd9\u4efd\u8ba1\u5212\u76f8\u5bf9\u7cdf\u7cd5\uff0c\u5e76\u5931\u53bb 1 \u5206\uff1b 
  • \n\t
  • \u5982\u679c T > upper\uff0c\u90a3\u4e48\u8fd9\u4efd\u8ba1\u5212\u76f8\u5bf9\u4f18\u79c0\uff0c\u5e76\u83b7\u5f97 1 \u5206\uff1b
  • \n\t
  • \u5426\u5219\uff0c\u8fd9\u4efd\u8ba1\u5212\u666e\u666e\u901a\u901a\uff0c\u5206\u503c\u4e0d\u505a\u53d8\u52a8\u3002
  • \n
\n\n

\u8bf7\u8fd4\u56de\u7edf\u8ba1\u5b8c\u6240\u6709 calories.length \u5929\u540e\u5f97\u5230\u7684\u603b\u5206\u4f5c\u4e3a\u8bc4\u4f30\u7ed3\u679c\u3002

\n\n

\u6ce8\u610f\uff1a\u603b\u5206\u53ef\u80fd\u662f\u8d1f\u6570\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1acalories = [1,2,3,4,5], k = 1, lower = 3, upper = 3\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1acalories[0], calories[1] < lower \u800c calories[3], calories[4] > upper, \u603b\u5206 = 0.
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1acalories = [3,2], k = 2, lower = 0, upper = 1\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1acalories[0] + calories[1] > upper, \u603b\u5206 = 1.\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1acalories = [6,5,0,0], k = 2, lower = 1, upper = 5\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1acalories[0] + calories[1] > upper, calories[2] + calories[3] < lower, \u603b\u5206 = 0.\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= k <= calories.length <= 10^5
  • \n\t
  • 0 <= calories[i] <= 20000
  • \n\t
  • 0 <= lower <= upper
  • \n
\n", "tags_en": ["Array", "Sliding Window"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int dietPlanPerformance(vector& calories, int k, int lower, int upper) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int dietPlanPerformance(int[] calories, int k, int lower, int upper) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def dietPlanPerformance(self, calories, k, lower, upper):\n \"\"\"\n :type calories: List[int]\n :type k: int\n :type lower: int\n :type upper: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def dietPlanPerformance(self, calories: List[int], k: int, lower: int, upper: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint dietPlanPerformance(int* calories, int caloriesSize, int k, int lower, int upper){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int DietPlanPerformance(int[] calories, int k, int lower, int upper) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} calories\n * @param {number} k\n * @param {number} lower\n * @param {number} upper\n * @return {number}\n */\nvar dietPlanPerformance = function(calories, k, lower, upper) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} calories\n# @param {Integer} k\n# @param {Integer} lower\n# @param {Integer} upper\n# @return {Integer}\ndef diet_plan_performance(calories, k, lower, upper)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func dietPlanPerformance(_ calories: [Int], _ k: Int, _ lower: Int, _ upper: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func dietPlanPerformance(calories []int, k int, lower int, upper int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def dietPlanPerformance(calories: Array[Int], k: Int, lower: Int, upper: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun dietPlanPerformance(calories: IntArray, k: Int, lower: Int, upper: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn diet_plan_performance(calories: Vec, k: i32, lower: i32, upper: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $calories\n * @param Integer $k\n * @param Integer $lower\n * @param Integer $upper\n * @return Integer\n */\n function dietPlanPerformance($calories, $k, $lower, $upper) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function dietPlanPerformance(calories: number[], k: number, lower: number, upper: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (diet-plan-performance calories k lower upper)\n (-> (listof exact-integer?) exact-integer? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1176](https://leetcode-cn.com/problems/diet-plan-performance)", "[\u5065\u8eab\u8ba1\u5212\u8bc4\u4f30](/solution/1100-1199/1176.Diet%20Plan%20Performance/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1176](https://leetcode.com/problems/diet-plan-performance)", "[Diet Plan Performance](/solution/1100-1199/1176.Diet%20Plan%20Performance/README_EN.md)", "`Array`,`Sliding Window`", "Easy", "\ud83d\udd12"]}, {"question_id": "1279", "frontend_question_id": "1175", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/prime-arrangements", "url_en": "https://leetcode.com/problems/prime-arrangements", "relative_path_cn": "/solution/1100-1199/1175.Prime%20Arrangements/README.md", "relative_path_en": "/solution/1100-1199/1175.Prime%20Arrangements/README_EN.md", "title_cn": "\u8d28\u6570\u6392\u5217", "title_en": "Prime Arrangements", "question_title_slug": "prime-arrangements", "content_en": "

Return the number of permutations of 1 to n so that prime numbers are at prime indices (1-indexed.)

\n\n

(Recall that an integer is prime if and only if it is greater than 1, and cannot be written as a product of two positive integers both smaller than it.)

\n\n

Since the answer may be large, return the answer modulo 10^9 + 7.

\n\n

 

\n

Example 1:

\n\n
\nInput: n = 5\nOutput: 12\nExplanation: For example [1,2,5,4,3] is a valid permutation, but [5,2,3,4,1] is not because the prime number 5 is at index 1.\n
\n\n

Example 2:

\n\n
\nInput: n = 100\nOutput: 682289015\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 100
  • \n
\n", "content_cn": "

\u8bf7\u4f60\u5e2e\u5fd9\u7ed9\u4ece 1 \u5230 n \u7684\u6570\u8bbe\u8ba1\u6392\u5217\u65b9\u6848\uff0c\u4f7f\u5f97\u6240\u6709\u7684\u300c\u8d28\u6570\u300d\u90fd\u5e94\u8be5\u88ab\u653e\u5728\u300c\u8d28\u6570\u7d22\u5f15\u300d\uff08\u7d22\u5f15\u4ece 1 \u5f00\u59cb\uff09\u4e0a\uff1b\u4f60\u9700\u8981\u8fd4\u56de\u53ef\u80fd\u7684\u65b9\u6848\u603b\u6570\u3002

\n\n

\u8ba9\u6211\u4eec\u4e00\u8d77\u6765\u56de\u987e\u4e00\u4e0b\u300c\u8d28\u6570\u300d\uff1a\u8d28\u6570\u4e00\u5b9a\u662f\u5927\u4e8e 1 \u7684\uff0c\u5e76\u4e14\u4e0d\u80fd\u7528\u4e24\u4e2a\u5c0f\u4e8e\u5b83\u7684\u6b63\u6574\u6570\u7684\u4e58\u79ef\u6765\u8868\u793a\u3002

\n\n

\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u4f1a\u5f88\u5927\uff0c\u6240\u4ee5\u8bf7\u4f60\u8fd4\u56de\u7b54\u6848 \u6a21 mod 10^9 + 7 \u4e4b\u540e\u7684\u7ed3\u679c\u5373\u53ef\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1an = 5\n\u8f93\u51fa\uff1a12\n\u89e3\u91ca\uff1a\u4e3e\u4e2a\u4f8b\u5b50\uff0c[1,2,5,4,3] \u662f\u4e00\u4e2a\u6709\u6548\u7684\u6392\u5217\uff0c\u4f46 [5,2,3,4,1] \u4e0d\u662f\uff0c\u56e0\u4e3a\u5728\u7b2c\u4e8c\u79cd\u60c5\u51b5\u91cc\u8d28\u6570 5 \u88ab\u9519\u8bef\u5730\u653e\u5728\u7d22\u5f15\u4e3a 1 \u7684\u4f4d\u7f6e\u4e0a\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1an = 100\n\u8f93\u51fa\uff1a682289015\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 100
  • \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numPrimeArrangements(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numPrimeArrangements(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numPrimeArrangements(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numPrimeArrangements(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numPrimeArrangements(int n){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumPrimeArrangements(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar numPrimeArrangements = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef num_prime_arrangements(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numPrimeArrangements(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numPrimeArrangements(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numPrimeArrangements(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numPrimeArrangements(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_prime_arrangements(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function numPrimeArrangements($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numPrimeArrangements(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-prime-arrangements n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1175](https://leetcode-cn.com/problems/prime-arrangements)", "[\u8d28\u6570\u6392\u5217](/solution/1100-1199/1175.Prime%20Arrangements/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[1175](https://leetcode.com/problems/prime-arrangements)", "[Prime Arrangements](/solution/1100-1199/1175.Prime%20Arrangements/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "1278", "frontend_question_id": "1164", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/product-price-at-a-given-date", "url_en": "https://leetcode.com/problems/product-price-at-a-given-date", "relative_path_cn": "/solution/1100-1199/1164.Product%20Price%20at%20a%20Given%20Date/README.md", "relative_path_en": "/solution/1100-1199/1164.Product%20Price%20at%20a%20Given%20Date/README_EN.md", "title_cn": "\u6307\u5b9a\u65e5\u671f\u7684\u4ea7\u54c1\u4ef7\u683c", "title_en": "Product Price at a Given Date", "question_title_slug": "product-price-at-a-given-date", "content_en": "

Table: Products

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| product_id    | int     |\n| new_price     | int     |\n| change_date   | date    |\n+---------------+---------+\n(product_id, change_date) is the primary key of this table.\nEach row of this table indicates that the price of some product was changed to a new price at some date.
\n\n

 

\n\n

Write an SQL query to find the prices of all products on 2019-08-16. Assume the price of all products before any change is 10.

\n\n

The query result format is in the following example:

\n\n
\nProducts table:\n+------------+-----------+-------------+\n| product_id | new_price | change_date |\n+------------+-----------+-------------+\n| 1          | 20        | 2019-08-14  |\n| 2          | 50        | 2019-08-14  |\n| 1          | 30        | 2019-08-15  |\n| 1          | 35        | 2019-08-16  |\n| 2          | 65        | 2019-08-17  |\n| 3          | 20        | 2019-08-18  |\n+------------+-----------+-------------+\n\nResult table:\n+------------+-------+\n| product_id | price |\n+------------+-------+\n| 2          | 50    |\n| 1          | 35    |\n| 3          | 10    |\n+------------+-------+\n
\n", "content_cn": "

\u4ea7\u54c1\u6570\u636e\u8868: Products

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| product_id    | int     |\n| new_price     | int     |\n| change_date   | date    |\n+---------------+---------+\n\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\u662f (product_id, change_date)\u3002\n\u8fd9\u5f20\u8868\u7684\u6bcf\u4e00\u884c\u5206\u522b\u8bb0\u5f55\u4e86 \u67d0\u4ea7\u54c1 \u5728\u67d0\u4e2a\u65e5\u671f \u66f4\u6539\u540e \u7684\u65b0\u4ef7\u683c\u3002
\n\n

 

\n\n

\u5199\u4e00\u6bb5 SQL\u6765\u67e5\u627e\u5728 2019-08-16 \u65f6\u5168\u90e8\u4ea7\u54c1\u7684\u4ef7\u683c\uff0c\u5047\u8bbe\u6240\u6709\u4ea7\u54c1\u5728\u4fee\u6539\u524d\u7684\u4ef7\u683c\u90fd\u662f 10\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a\uff1a

\n\n
\nProducts table:\n+------------+-----------+-------------+\n| product_id | new_price | change_date |\n+------------+-----------+-------------+\n| 1          | 20        | 2019-08-14  |\n| 2          | 50        | 2019-08-14  |\n| 1          | 30        | 2019-08-15  |\n| 1          | 35        | 2019-08-16  |\n| 2          | 65        | 2019-08-17  |\n| 3          | 20        | 2019-08-18  |\n+------------+-----------+-------------+\n\nResult table:\n+------------+-------+\n| product_id | price |\n+------------+-------+\n| 2          | 50    |\n| 1          | 35    |\n| 3          | 10    |\n+------------+-------+\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1164](https://leetcode-cn.com/problems/product-price-at-a-given-date)", "[\u6307\u5b9a\u65e5\u671f\u7684\u4ea7\u54c1\u4ef7\u683c](/solution/1100-1199/1164.Product%20Price%20at%20a%20Given%20Date/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1164](https://leetcode.com/problems/product-price-at-a-given-date)", "[Product Price at a Given Date](/solution/1100-1199/1164.Product%20Price%20at%20a%20Given%20Date/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1277", "frontend_question_id": "1363", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/largest-multiple-of-three", "url_en": "https://leetcode.com/problems/largest-multiple-of-three", "relative_path_cn": "/solution/1300-1399/1363.Largest%20Multiple%20of%20Three/README.md", "relative_path_en": "/solution/1300-1399/1363.Largest%20Multiple%20of%20Three/README_EN.md", "title_cn": "\u5f62\u6210\u4e09\u7684\u6700\u5927\u500d\u6570", "title_en": "Largest Multiple of Three", "question_title_slug": "largest-multiple-of-three", "content_en": "

Given an integer array of digits, return the largest multiple of three that can be formed by concatenating some of the given digits in any order.

\n\n

Since the answer may not fit in an integer data type, return the answer as a string.

\n\n

If there is no answer return an empty string.

\n\n

 

\n

Example 1:

\n\n
\nInput: digits = [8,1,9]\nOutput: "981"\n
\n\n

Example 2:

\n\n
\nInput: digits = [8,6,7,1,0]\nOutput: "8760"\n
\n\n

Example 3:

\n\n
\nInput: digits = [1]\nOutput: ""\n
\n\n

Example 4:

\n\n
\nInput: digits = [0,0,0,0,0,0]\nOutput: "0"\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= digits.length <= 10^4
  • \n\t
  • 0 <= digits[i] <= 9
  • \n\t
  • The returning answer must not contain unnecessary leading zeros.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 digits\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u6309\u4efb\u610f\u987a\u5e8f\u8fde\u63a5\u5176\u4e2d\u67d0\u4e9b\u6570\u5b57\u6765\u5f62\u6210 3 \u7684\u500d\u6570\uff0c\u8bf7\u4f60\u8fd4\u56de\u6240\u80fd\u5f97\u5230\u7684\u6700\u5927\u7684 3 \u7684\u500d\u6570\u3002

\n\n

\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u4e0d\u5728\u6574\u6570\u6570\u636e\u7c7b\u578b\u8303\u56f4\u5185\uff0c\u8bf7\u4ee5\u5b57\u7b26\u4e32\u5f62\u5f0f\u8fd4\u56de\u7b54\u6848\u3002

\n\n

\u5982\u679c\u65e0\u6cd5\u5f97\u5230\u7b54\u6848\uff0c\u8bf7\u8fd4\u56de\u4e00\u4e2a\u7a7a\u5b57\u7b26\u4e32\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1adigits = [8,1,9]\n\u8f93\u51fa\uff1a"981"\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1adigits = [8,6,7,1,0]\n\u8f93\u51fa\uff1a"8760"\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1adigits = [1]\n\u8f93\u51fa\uff1a""\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1adigits = [0,0,0,0,0,0]\n\u8f93\u51fa\uff1a"0"\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= digits.length <= 10^4
  • \n\t
  • 0 <= digits[i] <= 9
  • \n\t
  • \u8fd4\u56de\u7684\u7ed3\u679c\u4e0d\u5e94\u5305\u542b\u4e0d\u5fc5\u8981\u7684\u524d\u5bfc\u96f6\u3002
  • \n
\n", "tags_en": ["Math", "Dynamic Programming"], "tags_cn": ["\u6570\u5b66", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string largestMultipleOfThree(vector& digits) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String largestMultipleOfThree(int[] digits) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def largestMultipleOfThree(self, digits):\n \"\"\"\n :type digits: List[int]\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def largestMultipleOfThree(self, digits: List[int]) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * largestMultipleOfThree(int* digits, int digitsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string LargestMultipleOfThree(int[] digits) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} digits\n * @return {string}\n */\nvar largestMultipleOfThree = function(digits) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} digits\n# @return {String}\ndef largest_multiple_of_three(digits)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func largestMultipleOfThree(_ digits: [Int]) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func largestMultipleOfThree(digits []int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def largestMultipleOfThree(digits: Array[Int]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun largestMultipleOfThree(digits: IntArray): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn largest_multiple_of_three(digits: Vec) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $digits\n * @return String\n */\n function largestMultipleOfThree($digits) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function largestMultipleOfThree(digits: number[]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (largest-multiple-of-three digits)\n (-> (listof exact-integer?) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1363](https://leetcode-cn.com/problems/largest-multiple-of-three)", "[\u5f62\u6210\u4e09\u7684\u6700\u5927\u500d\u6570](/solution/1300-1399/1363.Largest%20Multiple%20of%20Three/README.md)", "`\u6570\u5b66`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1363](https://leetcode.com/problems/largest-multiple-of-three)", "[Largest Multiple of Three](/solution/1300-1399/1363.Largest%20Multiple%20of%20Three/README_EN.md)", "`Math`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "1276", "frontend_question_id": "1362", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/closest-divisors", "url_en": "https://leetcode.com/problems/closest-divisors", "relative_path_cn": "/solution/1300-1399/1362.Closest%20Divisors/README.md", "relative_path_en": "/solution/1300-1399/1362.Closest%20Divisors/README_EN.md", "title_cn": "\u6700\u63a5\u8fd1\u7684\u56e0\u6570", "title_en": "Closest Divisors", "question_title_slug": "closest-divisors", "content_en": "

Given an integer num, find the closest two integers in absolute difference whose product equals num + 1 or num + 2.

\n\n

Return the two integers in any order.

\n\n

 

\n

Example 1:

\n\n
\nInput: num = 8\nOutput: [3,3]\nExplanation: For num + 1 = 9, the closest divisors are 3 & 3, for num + 2 = 10, the closest divisors are 2 & 5, hence 3 & 3 is chosen.\n
\n\n

Example 2:

\n\n
\nInput: num = 123\nOutput: [5,25]\n
\n\n

Example 3:

\n\n
\nInput: num = 999\nOutput: [40,25]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= num <= 10^9
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 num\uff0c\u8bf7\u4f60\u627e\u51fa\u540c\u65f6\u6ee1\u8db3\u4e0b\u9762\u5168\u90e8\u8981\u6c42\u7684\u4e24\u4e2a\u6574\u6570\uff1a

\n\n
    \n\t
  • \u4e24\u6570\u4e58\u79ef\u7b49\u4e8e  num + 1 \u6216 num + 2
  • \n\t
  • \u4ee5\u7edd\u5bf9\u5dee\u8fdb\u884c\u5ea6\u91cf\uff0c\u4e24\u6570\u5927\u5c0f\u6700\u63a5\u8fd1
  • \n
\n\n

\u4f60\u53ef\u4ee5\u6309\u4efb\u610f\u987a\u5e8f\u8fd4\u56de\u8fd9\u4e24\u4e2a\u6574\u6570\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anum = 8\n\u8f93\u51fa\uff1a[3,3]\n\u89e3\u91ca\uff1a\u5bf9\u4e8e num + 1 = 9\uff0c\u6700\u63a5\u8fd1\u7684\u4e24\u4e2a\u56e0\u6570\u662f 3 & 3\uff1b\u5bf9\u4e8e num + 2 = 10, \u6700\u63a5\u8fd1\u7684\u4e24\u4e2a\u56e0\u6570\u662f 2 & 5\uff0c\u56e0\u6b64\u8fd4\u56de 3 & 3 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anum = 123\n\u8f93\u51fa\uff1a[5,25]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1anum = 999\n\u8f93\u51fa\uff1a[40,25]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= num <= 10^9
  • \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector closestDivisors(int num) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] closestDivisors(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def closestDivisors(self, num):\n \"\"\"\n :type num: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def closestDivisors(self, num: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* closestDivisors(int num, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] ClosestDivisors(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} num\n * @return {number[]}\n */\nvar closestDivisors = function(num) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} num\n# @return {Integer[]}\ndef closest_divisors(num)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func closestDivisors(_ num: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func closestDivisors(num int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def closestDivisors(num: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun closestDivisors(num: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn closest_divisors(num: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $num\n * @return Integer[]\n */\n function closestDivisors($num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function closestDivisors(num: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (closest-divisors num)\n (-> exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1362](https://leetcode-cn.com/problems/closest-divisors)", "[\u6700\u63a5\u8fd1\u7684\u56e0\u6570](/solution/1300-1399/1362.Closest%20Divisors/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1362](https://leetcode.com/problems/closest-divisors)", "[Closest Divisors](/solution/1300-1399/1362.Closest%20Divisors/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "1275", "frontend_question_id": "1361", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/validate-binary-tree-nodes", "url_en": "https://leetcode.com/problems/validate-binary-tree-nodes", "relative_path_cn": "/solution/1300-1399/1361.Validate%20Binary%20Tree%20Nodes/README.md", "relative_path_en": "/solution/1300-1399/1361.Validate%20Binary%20Tree%20Nodes/README_EN.md", "title_cn": "\u9a8c\u8bc1\u4e8c\u53c9\u6811", "title_en": "Validate Binary Tree Nodes", "question_title_slug": "validate-binary-tree-nodes", "content_en": "

You have n binary tree nodes numbered from 0 to n - 1 where node i has two children leftChild[i] and rightChild[i], return true if and only if all the given nodes form exactly one valid binary tree.

\n\n

If node i has no left child then leftChild[i] will equal -1, similarly for the right child.

\n\n

Note that the nodes have no values and that we only use the node numbers in this problem.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: n = 4, leftChild = [1,-1,3,-1], rightChild = [2,-1,-1,-1]\nOutput: true\n
\n\n

Example 2:

\n\"\"\n
\nInput: n = 4, leftChild = [1,-1,3,-1], rightChild = [2,3,-1,-1]\nOutput: false\n
\n\n

Example 3:

\n\"\"\n
\nInput: n = 2, leftChild = [1,0], rightChild = [-1,-1]\nOutput: false\n
\n\n

Example 4:

\n\"\"\n
\nInput: n = 6, leftChild = [1,-1,-1,4,-1,-1], rightChild = [2,-1,-1,5,-1,-1]\nOutput: false\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 104
  • \n\t
  • leftChild.length == rightChild.length == n
  • \n\t
  • -1 <= leftChild[i], rightChild[i] <= n - 1
  • \n
\n", "content_cn": "

\u4e8c\u53c9\u6811\u4e0a\u6709 n \u4e2a\u8282\u70b9\uff0c\u6309\u4ece 0 \u5230 n - 1 \u7f16\u53f7\uff0c\u5176\u4e2d\u8282\u70b9 i \u7684\u4e24\u4e2a\u5b50\u8282\u70b9\u5206\u522b\u662f leftChild[i] \u548c rightChild[i]\u3002

\n\n

\u53ea\u6709 \u6240\u6709 \u8282\u70b9\u80fd\u591f\u5f62\u6210\u4e14 \u53ea \u5f62\u6210 \u4e00\u9897 \u6709\u6548\u7684\u4e8c\u53c9\u6811\u65f6\uff0c\u8fd4\u56de true\uff1b\u5426\u5219\u8fd4\u56de false\u3002

\n\n

\u5982\u679c\u8282\u70b9 i \u6ca1\u6709\u5de6\u5b50\u8282\u70b9\uff0c\u90a3\u4e48 leftChild[i] \u5c31\u7b49\u4e8e -1\u3002\u53f3\u5b50\u8282\u70b9\u4e5f\u7b26\u5408\u8be5\u89c4\u5219\u3002

\n\n

\u6ce8\u610f\uff1a\u8282\u70b9\u6ca1\u6709\u503c\uff0c\u672c\u95ee\u9898\u4e2d\u4ec5\u4ec5\u4f7f\u7528\u8282\u70b9\u7f16\u53f7\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1an = 4, leftChild = [1,-1,3,-1], rightChild = [2,-1,-1,-1]\n\u8f93\u51fa\uff1atrue\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1an = 4, leftChild = [1,-1,3,-1], rightChild = [2,3,-1,-1]\n\u8f93\u51fa\uff1afalse\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1an = 2, leftChild = [1,0], rightChild = [-1,-1]\n\u8f93\u51fa\uff1afalse\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1an = 6, leftChild = [1,-1,-1,4,-1,-1], rightChild = [2,-1,-1,5,-1,-1]\n\u8f93\u51fa\uff1afalse\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 10^4
  • \n\t
  • leftChild.length == rightChild.length == n
  • \n\t
  • -1 <= leftChild[i], rightChild[i] <= n - 1
  • \n
\n", "tags_en": ["Graph"], "tags_cn": ["\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool validateBinaryTreeNodes(int n, vector& leftChild, vector& rightChild) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean validateBinaryTreeNodes(int n, int[] leftChild, int[] rightChild) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def validateBinaryTreeNodes(self, n, leftChild, rightChild):\n \"\"\"\n :type n: int\n :type leftChild: List[int]\n :type rightChild: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def validateBinaryTreeNodes(self, n: int, leftChild: List[int], rightChild: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool validateBinaryTreeNodes(int n, int* leftChild, int leftChildSize, int* rightChild, int rightChildSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool ValidateBinaryTreeNodes(int n, int[] leftChild, int[] rightChild) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[]} leftChild\n * @param {number[]} rightChild\n * @return {boolean}\n */\nvar validateBinaryTreeNodes = function(n, leftChild, rightChild) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[]} left_child\n# @param {Integer[]} right_child\n# @return {Boolean}\ndef validate_binary_tree_nodes(n, left_child, right_child)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func validateBinaryTreeNodes(_ n: Int, _ leftChild: [Int], _ rightChild: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func validateBinaryTreeNodes(n int, leftChild []int, rightChild []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def validateBinaryTreeNodes(n: Int, leftChild: Array[Int], rightChild: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun validateBinaryTreeNodes(n: Int, leftChild: IntArray, rightChild: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn validate_binary_tree_nodes(n: i32, left_child: Vec, right_child: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[] $leftChild\n * @param Integer[] $rightChild\n * @return Boolean\n */\n function validateBinaryTreeNodes($n, $leftChild, $rightChild) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function validateBinaryTreeNodes(n: number, leftChild: number[], rightChild: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (validate-binary-tree-nodes n leftChild rightChild)\n (-> exact-integer? (listof exact-integer?) (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1361](https://leetcode-cn.com/problems/validate-binary-tree-nodes)", "[\u9a8c\u8bc1\u4e8c\u53c9\u6811](/solution/1300-1399/1361.Validate%20Binary%20Tree%20Nodes/README.md)", "`\u56fe`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1361](https://leetcode.com/problems/validate-binary-tree-nodes)", "[Validate Binary Tree Nodes](/solution/1300-1399/1361.Validate%20Binary%20Tree%20Nodes/README_EN.md)", "`Graph`", "Medium", ""]}, {"question_id": "1274", "frontend_question_id": "1360", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-days-between-two-dates", "url_en": "https://leetcode.com/problems/number-of-days-between-two-dates", "relative_path_cn": "/solution/1300-1399/1360.Number%20of%20Days%20Between%20Two%20Dates/README.md", "relative_path_en": "/solution/1300-1399/1360.Number%20of%20Days%20Between%20Two%20Dates/README_EN.md", "title_cn": "\u65e5\u671f\u4e4b\u95f4\u9694\u51e0\u5929", "title_en": "Number of Days Between Two Dates", "question_title_slug": "number-of-days-between-two-dates", "content_en": "

Write a program to count the number of days between two dates.

\n\n

The two dates are given as strings, their format is YYYY-MM-DD as shown in the examples.

\n\n

 

\n

Example 1:

\n
Input: date1 = \"2019-06-29\", date2 = \"2019-06-30\"\nOutput: 1\n

Example 2:

\n
Input: date1 = \"2020-01-15\", date2 = \"2019-12-31\"\nOutput: 15\n
\n

 

\n

Constraints:

\n\n
    \n\t
  • The given dates are valid dates between the years 1971 and 2100.
  • \n
\n", "content_cn": "

\u8bf7\u4f60\u7f16\u5199\u4e00\u4e2a\u7a0b\u5e8f\u6765\u8ba1\u7b97\u4e24\u4e2a\u65e5\u671f\u4e4b\u95f4\u9694\u4e86\u591a\u5c11\u5929\u3002

\n\n

\u65e5\u671f\u4ee5\u5b57\u7b26\u4e32\u5f62\u5f0f\u7ed9\u51fa\uff0c\u683c\u5f0f\u4e3a YYYY-MM-DD\uff0c\u5982\u793a\u4f8b\u6240\u793a\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1adate1 = "2019-06-29", date2 = "2019-06-30"\n\u8f93\u51fa\uff1a1\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1adate1 = "2020-01-15", date2 = "2019-12-31"\n\u8f93\u51fa\uff1a15\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u7ed9\u5b9a\u7684\u65e5\u671f\u662f 1971 \u5e74\u5230 2100 \u5e74\u4e4b\u95f4\u7684\u6709\u6548\u65e5\u671f\u3002
  • \n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int daysBetweenDates(string date1, string date2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int daysBetweenDates(String date1, String date2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def daysBetweenDates(self, date1, date2):\n \"\"\"\n :type date1: str\n :type date2: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def daysBetweenDates(self, date1: str, date2: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint daysBetweenDates(char * date1, char * date2){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int DaysBetweenDates(string date1, string date2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} date1\n * @param {string} date2\n * @return {number}\n */\nvar daysBetweenDates = function(date1, date2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} date1\n# @param {String} date2\n# @return {Integer}\ndef days_between_dates(date1, date2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func daysBetweenDates(_ date1: String, _ date2: String) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func daysBetweenDates(date1 string, date2 string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def daysBetweenDates(date1: String, date2: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun daysBetweenDates(date1: String, date2: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn days_between_dates(date1: String, date2: String) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $date1\n * @param String $date2\n * @return Integer\n */\n function daysBetweenDates($date1, $date2) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function daysBetweenDates(date1: string, date2: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (days-between-dates date1 date2)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1360](https://leetcode-cn.com/problems/number-of-days-between-two-dates)", "[\u65e5\u671f\u4e4b\u95f4\u9694\u51e0\u5929](/solution/1300-1399/1360.Number%20of%20Days%20Between%20Two%20Dates/README.md)", "", "\u7b80\u5355", ""], "md_table_row_en": ["[1360](https://leetcode.com/problems/number-of-days-between-two-dates)", "[Number of Days Between Two Dates](/solution/1300-1399/1360.Number%20of%20Days%20Between%20Two%20Dates/README_EN.md)", "", "Easy", ""]}, {"question_id": "1273", "frontend_question_id": "1170", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/compare-strings-by-frequency-of-the-smallest-character", "url_en": "https://leetcode.com/problems/compare-strings-by-frequency-of-the-smallest-character", "relative_path_cn": "/solution/1100-1199/1170.Compare%20Strings%20by%20Frequency%20of%20the%20Smallest%20Character/README.md", "relative_path_en": "/solution/1100-1199/1170.Compare%20Strings%20by%20Frequency%20of%20the%20Smallest%20Character/README_EN.md", "title_cn": "\u6bd4\u8f83\u5b57\u7b26\u4e32\u6700\u5c0f\u5b57\u6bcd\u51fa\u73b0\u9891\u6b21", "title_en": "Compare Strings by Frequency of the Smallest Character", "question_title_slug": "compare-strings-by-frequency-of-the-smallest-character", "content_en": "

Let the function f(s) be the frequency of the lexicographically smallest character in a non-empty string s. For example, if s = "dcce" then f(s) = 2 because the lexicographically smallest character is 'c', which has a frequency of 2.

\n\n

You are given an array of strings words and another array of query strings queries. For each query queries[i], count the number of words in words such that f(queries[i]) < f(W) for each W in words.

\n\n

Return an integer array answer, where each answer[i] is the answer to the ith query.

\n\n

 

\n

Example 1:

\n\n
\nInput: queries = ["cbd"], words = ["zaaaz"]\nOutput: [1]\nExplanation: On the first query we have f("cbd") = 1, f("zaaaz") = 3 so f("cbd") < f("zaaaz").\n
\n\n

Example 2:

\n\n
\nInput: queries = ["bbb","cc"], words = ["a","aa","aaa","aaaa"]\nOutput: [1,2]\nExplanation: On the first query only f("bbb") < f("aaaa"). On the second query both f("aaa") and f("aaaa") are both > f("cc").\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= queries.length <= 2000
  • \n\t
  • 1 <= words.length <= 2000
  • \n\t
  • 1 <= queries[i].length, words[i].length <= 10
  • \n\t
  • queries[i][j], words[i][j] consist of lowercase English letters.
  • \n
\n", "content_cn": "

\u5b9a\u4e49\u4e00\u4e2a\u51fd\u6570\u00a0f(s)\uff0c\u7edf\u8ba1\u00a0s \u00a0\u4e2d\uff08\u6309\u5b57\u5178\u5e8f\u6bd4\u8f83\uff09\u6700\u5c0f\u5b57\u6bcd\u7684\u51fa\u73b0\u9891\u6b21 \uff0c\u5176\u4e2d s\u00a0\u662f\u4e00\u4e2a\u975e\u7a7a\u5b57\u7b26\u4e32\u3002

\n\n

\u4f8b\u5982\uff0c\u82e5\u00a0s = \"dcce\"\uff0c\u90a3\u4e48\u00a0f(s) = 2\uff0c\u56e0\u4e3a\u5b57\u5178\u5e8f\u6700\u5c0f\u5b57\u6bcd\u662f\u00a0\"c\"\uff0c\u5b83\u51fa\u73b0\u4e86\u00a02 \u6b21\u3002

\n\n

\u73b0\u5728\uff0c\u7ed9\u4f60\u4e24\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4\u5f85\u67e5\u8868\u00a0queries\u00a0\u548c\u8bcd\u6c47\u8868\u00a0words \u3002\u5bf9\u4e8e\u6bcf\u6b21\u67e5\u8be2\u00a0queries[i] \uff0c\u9700\u7edf\u8ba1 words \u4e2d\u6ee1\u8db3\u00a0f(queries[i])\u00a0< f(W)\u00a0\u7684 \u8bcd\u7684\u6570\u76ee \uff0cW \u8868\u793a\u8bcd\u6c47\u8868\u00a0words\u00a0\u4e2d\u7684\u6bcf\u4e2a\u8bcd\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0answer\u00a0\u4f5c\u4e3a\u7b54\u6848\uff0c\u5176\u4e2d\u6bcf\u4e2a\u00a0answer[i]\u00a0\u662f\u7b2c i \u6b21\u67e5\u8be2\u7684\u7ed3\u679c\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aqueries = [\"cbd\"], words = [\"zaaaz\"]\n\u8f93\u51fa\uff1a[1]\n\u89e3\u91ca\uff1a\u67e5\u8be2 f(\"cbd\") = 1\uff0c\u800c f(\"zaaaz\") = 3 \u6240\u4ee5 f(\"cbd\") < f(\"zaaaz\")\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aqueries = [\"bbb\",\"cc\"], words = [\"a\",\"aa\",\"aaa\",\"aaaa\"]\n\u8f93\u51fa\uff1a[1,2]\n\u89e3\u91ca\uff1a\u7b2c\u4e00\u4e2a\u67e5\u8be2 f(\"bbb\") < f(\"aaaa\")\uff0c\u7b2c\u4e8c\u4e2a\u67e5\u8be2 f(\"aaa\") \u548c f(\"aaaa\") \u90fd > f(\"cc\")\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= queries.length <= 2000
  • \n\t
  • 1 <= words.length <= 2000
  • \n\t
  • 1 <= queries[i].length, words[i].length <= 10
  • \n\t
  • queries[i][j]\u3001words[i][j] \u90fd\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
  • \n
\n", "tags_en": ["Array", "String", "Binary Search"], "tags_cn": ["\u6570\u7ec4", "\u5b57\u7b26\u4e32", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector numSmallerByFrequency(vector& queries, vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] numSmallerByFrequency(String[] queries, String[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numSmallerByFrequency(self, queries, words):\n \"\"\"\n :type queries: List[str]\n :type words: List[str]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numSmallerByFrequency(self, queries: List[str], words: List[str]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* numSmallerByFrequency(char ** queries, int queriesSize, char ** words, int wordsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] NumSmallerByFrequency(string[] queries, string[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} queries\n * @param {string[]} words\n * @return {number[]}\n */\nvar numSmallerByFrequency = function(queries, words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} queries\n# @param {String[]} words\n# @return {Integer[]}\ndef num_smaller_by_frequency(queries, words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numSmallerByFrequency(_ queries: [String], _ words: [String]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numSmallerByFrequency(queries []string, words []string) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numSmallerByFrequency(queries: Array[String], words: Array[String]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numSmallerByFrequency(queries: Array, words: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_smaller_by_frequency(queries: Vec, words: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $queries\n * @param String[] $words\n * @return Integer[]\n */\n function numSmallerByFrequency($queries, $words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numSmallerByFrequency(queries: string[], words: string[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-smaller-by-frequency queries words)\n (-> (listof string?) (listof string?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1170](https://leetcode-cn.com/problems/compare-strings-by-frequency-of-the-smallest-character)", "[\u6bd4\u8f83\u5b57\u7b26\u4e32\u6700\u5c0f\u5b57\u6bcd\u51fa\u73b0\u9891\u6b21](/solution/1100-1199/1170.Compare%20Strings%20by%20Frequency%20of%20the%20Smallest%20Character/README.md)", "`\u6570\u7ec4`,`\u5b57\u7b26\u4e32`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1170](https://leetcode.com/problems/compare-strings-by-frequency-of-the-smallest-character)", "[Compare Strings by Frequency of the Smallest Character](/solution/1100-1199/1170.Compare%20Strings%20by%20Frequency%20of%20the%20Smallest%20Character/README_EN.md)", "`Array`,`String`,`Binary Search`", "Medium", ""]}, {"question_id": "1272", "frontend_question_id": "1169", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/invalid-transactions", "url_en": "https://leetcode.com/problems/invalid-transactions", "relative_path_cn": "/solution/1100-1199/1169.Invalid%20Transactions/README.md", "relative_path_en": "/solution/1100-1199/1169.Invalid%20Transactions/README_EN.md", "title_cn": "\u67e5\u8be2\u65e0\u6548\u4ea4\u6613", "title_en": "Invalid Transactions", "question_title_slug": "invalid-transactions", "content_en": "

A transaction is possibly invalid if:

\n\n
    \n\t
  • the amount exceeds $1000, or;
  • \n\t
  • if it occurs within (and including) 60 minutes of another transaction with the same name in a different city.
  • \n
\n\n

You are given an array of strings transaction where transactions[i] consists of comma-separated values representing the name, time (in minutes), amount, and city of the transaction.

\n\n

Return a list of transactions that are possibly invalid. You may return the answer in any order.

\n\n

 

\n

Example 1:

\n\n
\nInput: transactions = ["alice,20,800,mtv","alice,50,100,beijing"]\nOutput: ["alice,20,800,mtv","alice,50,100,beijing"]\nExplanation: The first transaction is invalid because the second transaction occurs within a difference of 60 minutes, have the same name and is in a different city. Similarly the second one is invalid too.
\n\n

Example 2:

\n\n
\nInput: transactions = ["alice,20,800,mtv","alice,50,1200,mtv"]\nOutput: ["alice,50,1200,mtv"]\n
\n\n

Example 3:

\n\n
\nInput: transactions = ["alice,20,800,mtv","bob,50,1200,mtv"]\nOutput: ["bob,50,1200,mtv"]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • transactions.length <= 1000
  • \n\t
  • Each transactions[i] takes the form "{name},{time},{amount},{city}"
  • \n\t
  • Each {name} and {city} consist of lowercase English letters, and have lengths between 1 and 10.
  • \n\t
  • Each {time} consist of digits, and represent an integer between 0 and 1000.
  • \n\t
  • Each {amount} consist of digits, and represent an integer between 0 and 2000.
  • \n
\n", "content_cn": "

\u5982\u679c\u51fa\u73b0\u4e0b\u8ff0\u4e24\u79cd\u60c5\u51b5\uff0c\u4ea4\u6613 \u53ef\u80fd\u65e0\u6548\uff1a

\n\n
    \n\t
  • \u4ea4\u6613\u91d1\u989d\u8d85\u8fc7 ¥1000
  • \n\t
  • \u6216\u8005\uff0c\u5b83\u548c\u53e6\u4e00\u4e2a\u57ce\u5e02\u4e2d\u540c\u540d\u7684\u53e6\u4e00\u7b14\u4ea4\u6613\u76f8\u9694\u4e0d\u8d85\u8fc7 60 \u5206\u949f\uff08\u5305\u542b 60 \u5206\u949f\u6574\uff09
  • \n
\n\n

\u6bcf\u4e2a\u4ea4\u6613\u5b57\u7b26\u4e32 transactions[i] \u7531\u4e00\u4e9b\u7528\u9017\u53f7\u5206\u9694\u7684\u503c\u7ec4\u6210\uff0c\u8fd9\u4e9b\u503c\u5206\u522b\u8868\u793a\u4ea4\u6613\u7684\u540d\u79f0\uff0c\u65f6\u95f4\uff08\u4ee5\u5206\u949f\u8ba1\uff09\uff0c\u91d1\u989d\u4ee5\u53ca\u57ce\u5e02\u3002

\n\n

\u7ed9\u4f60\u4e00\u4efd\u4ea4\u6613\u6e05\u5355 transactions\uff0c\u8fd4\u56de\u53ef\u80fd\u65e0\u6548\u7684\u4ea4\u6613\u5217\u8868\u3002\u4f60\u53ef\u4ee5\u6309\u4efb\u4f55\u987a\u5e8f\u8fd4\u56de\u7b54\u6848\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1atransactions = ["alice,20,800,mtv","alice,50,100,beijing"]\n\u8f93\u51fa\uff1a["alice,20,800,mtv","alice,50,100,beijing"]\n\u89e3\u91ca\uff1a\u7b2c\u4e00\u7b14\u4ea4\u6613\u662f\u65e0\u6548\u7684\uff0c\u56e0\u4e3a\u7b2c\u4e8c\u7b14\u4ea4\u6613\u548c\u5b83\u95f4\u9694\u4e0d\u8d85\u8fc7 60 \u5206\u949f\u3001\u540d\u79f0\u76f8\u540c\u4e14\u53d1\u751f\u5728\u4e0d\u540c\u7684\u57ce\u5e02\u3002\u540c\u6837\uff0c\u7b2c\u4e8c\u7b14\u4ea4\u6613\u4e5f\u662f\u65e0\u6548\u7684\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1atransactions = ["alice,20,800,mtv","alice,50,1200,mtv"]\n\u8f93\u51fa\uff1a["alice,50,1200,mtv"]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1atransactions = ["alice,20,800,mtv","bob,50,1200,mtv"]\n\u8f93\u51fa\uff1a["bob,50,1200,mtv"]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • transactions.length <= 1000
  • \n\t
  • \u6bcf\u7b14\u4ea4\u6613 transactions[i] \u6309 "{name},{time},{amount},{city}" \u7684\u683c\u5f0f\u8fdb\u884c\u8bb0\u5f55
  • \n\t
  • \u6bcf\u4e2a\u4ea4\u6613\u540d\u79f0 {name} \u548c\u57ce\u5e02 {city} \u90fd\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\uff0c\u957f\u5ea6\u5728 1 \u5230 10 \u4e4b\u95f4
  • \n\t
  • \u6bcf\u4e2a\u4ea4\u6613\u65f6\u95f4 {time} \u7531\u4e00\u4e9b\u6570\u5b57\u7ec4\u6210\uff0c\u8868\u793a\u4e00\u4e2a 0 \u5230 1000 \u4e4b\u95f4\u7684\u6574\u6570
  • \n\t
  • \u6bcf\u7b14\u4ea4\u6613\u91d1\u989d {amount} \u7531\u4e00\u4e9b\u6570\u5b57\u7ec4\u6210\uff0c\u8868\u793a\u4e00\u4e2a 0 \u5230 2000 \u4e4b\u95f4\u7684\u6574\u6570
  • \n
\n", "tags_en": ["Array", "String"], "tags_cn": ["\u6570\u7ec4", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector invalidTransactions(vector& transactions) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List invalidTransactions(String[] transactions) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def invalidTransactions(self, transactions):\n \"\"\"\n :type transactions: List[str]\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def invalidTransactions(self, transactions: List[str]) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** invalidTransactions(char ** transactions, int transactionsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList InvalidTransactions(string[] transactions) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} transactions\n * @return {string[]}\n */\nvar invalidTransactions = function(transactions) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} transactions\n# @return {String[]}\ndef invalid_transactions(transactions)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func invalidTransactions(_ transactions: [String]) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func invalidTransactions(transactions []string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def invalidTransactions(transactions: Array[String]): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun invalidTransactions(transactions: Array): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn invalid_transactions(transactions: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $transactions\n * @return String[]\n */\n function invalidTransactions($transactions) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function invalidTransactions(transactions: string[]): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (invalid-transactions transactions)\n (-> (listof string?) (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1169](https://leetcode-cn.com/problems/invalid-transactions)", "[\u67e5\u8be2\u65e0\u6548\u4ea4\u6613](/solution/1100-1199/1169.Invalid%20Transactions/README.md)", "`\u6570\u7ec4`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1169](https://leetcode.com/problems/invalid-transactions)", "[Invalid Transactions](/solution/1100-1199/1169.Invalid%20Transactions/README_EN.md)", "`Array`,`String`", "Medium", ""]}, {"question_id": "1271", "frontend_question_id": "1236", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/web-crawler", "url_en": "https://leetcode.com/problems/web-crawler", "relative_path_cn": "/solution/1200-1299/1236.Web%20Crawler/README.md", "relative_path_en": "/solution/1200-1299/1236.Web%20Crawler/README_EN.md", "title_cn": "\u7f51\u7edc\u722c\u866b", "title_en": "Web Crawler", "question_title_slug": "web-crawler", "content_en": "

Given a url startUrl and an interface HtmlParser, implement a web crawler to crawl all links that are under the same hostname as startUrl

\n\n

Return all urls obtained by your web crawler in any order.

\n\n

Your crawler should:

\n\n
    \n\t
  • Start from the page: startUrl
  • \n\t
  • Call HtmlParser.getUrls(url) to get all urls from a webpage of given url.
  • \n\t
  • Do not crawl the same link twice.
  • \n\t
  • Explore only the links that are under the same hostname as startUrl.
  • \n
\n\n

\"\"

\n\n

As shown in the example url above, the hostname is example.org. For simplicity sake, you may assume all urls use http protocol without any port specified. For example, the urls http://leetcode.com/problems and http://leetcode.com/contest are under the same hostname, while urls http://example.org/test and http://example.com/abc are not under the same hostname.

\n\n

The HtmlParser interface is defined as such: 

\n\n
\ninterface HtmlParser {\n  // Return a list of all urls from a webpage of given url.\n  public List<String> getUrls(String url);\n}
\n\n

Below are two examples explaining the functionality of the problem, for custom testing purposes you'll have three variables urlsedges and startUrl. Notice that you will only have access to startUrl in your code, while urls and edges are not directly accessible to you in code.

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput:\nurls = [\n  "http://news.yahoo.com",\n  "http://news.yahoo.com/news",\n  "http://news.yahoo.com/news/topics/",\n  "http://news.google.com",\n  "http://news.yahoo.com/us"\n]\nedges = [[2,0],[2,1],[3,2],[3,1],[0,4]]\nstartUrl = "http://news.yahoo.com/news/topics/"\nOutput: [\n  "http://news.yahoo.com",\n  "http://news.yahoo.com/news",\n  "http://news.yahoo.com/news/topics/",\n  "http://news.yahoo.com/us"\n]\n
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: \nurls = [\n  "http://news.yahoo.com",\n  "http://news.yahoo.com/news",\n  "http://news.yahoo.com/news/topics/",\n  "http://news.google.com"\n]\nedges = [[0,2],[2,1],[3,2],[3,1],[3,0]]\nstartUrl = "http://news.google.com"\nOutput: ["http://news.google.com"]\nExplanation: The startUrl links to all other pages that do not share the same hostname.
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= urls.length <= 1000
  • \n\t
  • 1 <= urls[i].length <= 300
  • \n\t
  • startUrl is one of the urls.
  • \n\t
  • Hostname label must be from 1 to 63 characters long, including the dots, may contain only the ASCII letters from 'a' to 'z', digits  from '0' to '9' and the hyphen-minus character ('-').
  • \n\t
  • The hostname may not start or end with the hyphen-minus character ('-'). 
  • \n\t
  • See:  https://en.wikipedia.org/wiki/Hostname#Restrictions_on_valid_hostnames
  • \n\t
  • You may assume there're no duplicates in url library.
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u94fe\u63a5 startUrl \u548c\u4e00\u4e2a\u63a5\u53e3 HtmlParser \uff0c\u8bf7\u4f60\u5b9e\u73b0\u4e00\u4e2a\u7f51\u7edc\u722c\u866b\uff0c\u4ee5\u5b9e\u73b0\u722c\u53d6\u540c startUrl \u62e5\u6709\u76f8\u540c \u57df\u540d\u6807\u7b7e \u7684\u5168\u90e8\u94fe\u63a5\u3002\u8be5\u722c\u866b\u5f97\u5230\u7684\u5168\u90e8\u94fe\u63a5\u53ef\u4ee5 \u4efb\u4f55\u987a\u5e8f \u8fd4\u56de\u7ed3\u679c\u3002

\n\n

\u4f60\u7684\u7f51\u7edc\u722c\u866b\u5e94\u5f53\u6309\u7167\u5982\u4e0b\u6a21\u5f0f\u5de5\u4f5c\uff1a

\n\n
    \n\t
  • \u81ea\u94fe\u63a5 startUrl \u5f00\u59cb\u722c\u53d6
  • \n\t
  • \u8c03\u7528 HtmlParser.getUrls(url) \u6765\u83b7\u5f97\u94fe\u63a5url\u9875\u9762\u4e2d\u7684\u5168\u90e8\u94fe\u63a5
  • \n\t
  • \u540c\u4e00\u4e2a\u94fe\u63a5\u6700\u591a\u53ea\u722c\u53d6\u4e00\u6b21
  • \n\t
  • \u53ea\u8f93\u51fa \u57df\u540d \u4e0e startUrl \u76f8\u540c \u7684\u94fe\u63a5\u96c6\u5408
  • \n
\n\n

\"\"

\n\n

\u5982\u4e0a\u6240\u793a\u7684\u4e00\u4e2a\u94fe\u63a5\uff0c\u5176\u57df\u540d\u4e3a example.org\u3002\u7b80\u5355\u8d77\u89c1\uff0c\u4f60\u53ef\u4ee5\u5047\u8bbe\u6240\u6709\u7684\u94fe\u63a5\u90fd\u91c7\u7528 http\u534f\u8bae \u5e76\u6ca1\u6709\u6307\u5b9a \u7aef\u53e3\u3002\u4f8b\u5982\uff0c\u94fe\u63a5 http://leetcode.com/problems \u548c http://leetcode.com/contest \u662f\u540c\u4e00\u4e2a\u57df\u540d\u4e0b\u7684\uff0c\u800c\u94fe\u63a5http://example.org/test \u548c http://example.com/abc \u662f\u4e0d\u5728\u540c\u4e00\u57df\u540d\u4e0b\u7684\u3002

\n\n

HtmlParser \u63a5\u53e3\u5b9a\u4e49\u5982\u4e0b\uff1a 

\n\n
interface HtmlParser {\n  // \u8fd4\u56de\u7ed9\u5b9a url \u5bf9\u5e94\u7684\u9875\u9762\u4e2d\u7684\u5168\u90e8 url \u3002\n  public List<String> getUrls(String url);\n}
\n\n

\u4e0b\u9762\u662f\u4e24\u4e2a\u5b9e\u4f8b\uff0c\u7528\u4ee5\u89e3\u91ca\u8be5\u95ee\u9898\u7684\u8bbe\u8ba1\u529f\u80fd\uff0c\u5bf9\u4e8e\u81ea\u5b9a\u4e49\u6d4b\u8bd5\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4e09\u4e2a\u53d8\u91cf  urlsedges \u548c startUrl\u3002\u6ce8\u610f\u5728\u4ee3\u7801\u5b9e\u73b0\u4e2d\uff0c\u4f60\u53ea\u53ef\u4ee5\u8bbf\u95ee startUrl \uff0c\u800c urls \u548c edges \u4e0d\u53ef\u4ee5\u5728\u4f60\u7684\u4ee3\u7801\u4e2d\u88ab\u76f4\u63a5\u8bbf\u95ee\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1a\nurls = [\n  "http://news.yahoo.com",\n  "http://news.yahoo.com/news",\n  "http://news.yahoo.com/news/topics/",\n  "http://news.google.com",\n  "http://news.yahoo.com/us"\n]\nedges = [[2,0],[2,1],[3,2],[3,1],[0,4]]\nstartUrl = "http://news.yahoo.com/news/topics/"\n\u8f93\u51fa\uff1a[\n  "http://news.yahoo.com",\n  "http://news.yahoo.com/news",\n  "http://news.yahoo.com/news/topics/",\n  "http://news.yahoo.com/us"\n]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1a\nurls = [\n  "http://news.yahoo.com",\n  "http://news.yahoo.com/news",\n  "http://news.yahoo.com/news/topics/",\n  "http://news.google.com"\n]\nedges = [[0,2],[2,1],[3,2],[3,1],[3,0]]\nstartUrl = "http://news.google.com"\n\u8f93\u5165\uff1a["http://news.google.com"]\n\u89e3\u91ca\uff1astartUrl \u94fe\u63a5\u5230\u6240\u6709\u5176\u4ed6\u4e0d\u5171\u4eab\u76f8\u540c\u4e3b\u673a\u540d\u7684\u9875\u9762\u3002
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= urls.length <= 1000
  • \n\t
  • 1 <= urls[i].length <= 300
  • \n\t
  • startUrl \u4e3a urls \u4e2d\u7684\u4e00\u4e2a\u3002
  • \n\t
  • \u57df\u540d\u6807\u7b7e\u7684\u957f\u4e3a1\u523063\u4e2a\u5b57\u7b26\uff08\u5305\u62ec\u70b9\uff09\uff0c\u53ea\u80fd\u5305\u542b\u4ece‘a’\u5230‘z’\u7684ASCII\u5b57\u6bcd\u3001‘0’\u5230‘9’\u7684\u6570\u5b57\u4ee5\u53ca\u8fde\u5b57\u7b26\u5373\u51cf\u53f7\uff08‘-’\uff09\u3002
  • \n\t
  • \u57df\u540d\u6807\u7b7e\u4e0d\u4f1a\u4ee5\u8fde\u5b57\u7b26\u5373\u51cf\u53f7\uff08‘-’\uff09\u5f00\u5934\u6216\u7ed3\u5c3e\u3002
  • \n\t
  • \u5173\u4e8e\u57df\u540d\u6709\u6548\u6027\u7684\u7ea6\u675f\u53ef\u53c2\u8003:  https://en.wikipedia.org/wiki/Hostname#Restrictions_on_valid_hostnames
  • \n\t
  • \u4f60\u53ef\u4ee5\u5047\u5b9aurl\u5e93\u4e2d\u4e0d\u5305\u542b\u91cd\u590d\u9879\u3002
  • \n
\n", "tags_en": ["Depth-first Search", "Breadth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * // This is the HtmlParser's API interface.\n * // You should not implement it, or speculate about its implementation\n * class HtmlParser {\n * public:\n * vector getUrls(string url);\n * };\n */\n\nclass Solution {\npublic:\n vector crawl(string startUrl, HtmlParser htmlParser) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * // This is the HtmlParser's API interface.\n * // You should not implement it, or speculate about its implementation\n * interface HtmlParser {\n * public List getUrls(String url) {}\n * }\n */\n\nclass Solution {\n public List crawl(String startUrl, HtmlParser htmlParser) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# \"\"\"\n# This is HtmlParser's API interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class HtmlParser(object):\n# def getUrls(self, url):\n# \"\"\"\n# :type url: str\n# :rtype List[str]\n# \"\"\"\n\nclass Solution(object):\n def crawl(self, startUrl, htmlParser):\n \"\"\"\n :type startUrl: str\n :type htmlParser: HtmlParser\n :rtype: List[str]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# \"\"\"\n# This is HtmlParser's API interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class HtmlParser(object):\n# def getUrls(self, url):\n# \"\"\"\n# :type url: str\n# :rtype List[str]\n# \"\"\"\n\nclass Solution:\n def crawl(self, startUrl: str, htmlParser: 'HtmlParser') -> List[str]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * // This is the HtmlParser's API interface.\n * // You should not implement it, or speculate about its implementation\n * class HtmlParser {\n * public List GetUrls(String url) {}\n * }\n */\n\nclass Solution {\n public IList Crawl(string startUrl, HtmlParser htmlParser) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // This is the HtmlParser's API interface.\n * // You should not implement it, or speculate about its implementation\n * function HtmlParser() {\n *\n *\t\t@param {string} url\n * \t@return {string[]}\n * \tthis.getUrls = function(url) {\n * \t...\n * \t};\n * };\n */\n\n/**\n * @param {string} startUrl\n * @param {HtmlParser} htmlParser\n * @return {string[]}\n*/\nvar crawl = function(startUrl, htmlParser) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# This is HtmlParser's API interface.\n# You should not implement it, or speculate about its implementation\n# class HtmlParser\n# def getUrls(url)\n# @return {List[String]}\n# end\n# end\n\n# @param {String} startUrl\n# @param {HtmlParser} htmlParser\n# @return {String}\ndef crawl(startUrl, htmlParser)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * // This is the HtmlParser's API interface.\n * // You should not implement it, or speculate about its implementation\n * public class HtmlParser {\n * public func getUrls(_ url: String) -> [String] {}\n * }\n */\n\nclass Solution { \n func crawl(_ startUrl: String, _ htmlParser: HtmlParser) -> [String] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * // This is HtmlParser's API interface.\n * // You should not implement it, or speculate about its implementation\n * type HtmlParser struct {\n * func GetUrls(url string) []string {}\n * }\n */\n\nfunc crawl(startUrl string, htmlParser HtmlParser) []string {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * // This is the HtmlParser's API interface.\n * // You should not implement it, or speculate about its implementation\n * class HtmlParser {\n * def getUrls(url: String): List[String] = {}\n * }\n */\n\nobject Solution {\n def crawl(startUrl: String, htmlParser: HtmlParser): Array[String] = {\n \t\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * // This is the HtmlParser's API interface.\n * // You should not implement it, or speculate about its implementation\n * class HtmlParser {\n * fun getUrls(url:String):List {}\n * }\n */\n\nclass Solution {\n fun crawl(startUrl:String, htmlParser:HtmlParser):List {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * // This is the HtmlParser's API interface.\n * // You should not implement it, or speculate about its implementation\n * class {\n * public function getUrls($url) {}\n * }\n */\n\nclass Solution {\n /**\n * @param String $startUrl\n * @param HtmlParser $htmlParser\n * @return String[]\n */\n function crawl($startUrl, $htmlParser) {\n\t\t\n\t}\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * // This is the HtmlParser's API interface.\n * // You should not implement it, or speculate about its implementation\n * class HtmlParser {\n * getUrls(url: string): string[] {}\n * }\n */\n\nfunction crawl(startUrl: string, htmlParser: HtmlParser): string[] {\n\t\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1236](https://leetcode-cn.com/problems/web-crawler)", "[\u7f51\u7edc\u722c\u866b](/solution/1200-1299/1236.Web%20Crawler/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1236](https://leetcode.com/problems/web-crawler)", "[Web Crawler](/solution/1200-1299/1236.Web%20Crawler/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`", "Medium", "\ud83d\udd12"]}, {"question_id": "1270", "frontend_question_id": "1172", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/dinner-plate-stacks", "url_en": "https://leetcode.com/problems/dinner-plate-stacks", "relative_path_cn": "/solution/1100-1199/1172.Dinner%20Plate%20Stacks/README.md", "relative_path_en": "/solution/1100-1199/1172.Dinner%20Plate%20Stacks/README_EN.md", "title_cn": "\u9910\u76d8\u6808", "title_en": "Dinner Plate Stacks", "question_title_slug": "dinner-plate-stacks", "content_en": "

You have an infinite number of stacks arranged in a row and numbered (left to right) from 0, each of the stacks has the same maximum capacity.

\n\n

Implement the DinnerPlates class:

\n\n
    \n\t
  • DinnerPlates(int capacity) Initializes the object with the maximum capacity of the stacks.
  • \n\t
  • void push(int val) Pushes the given positive integer val into the leftmost stack with size less than capacity.
  • \n\t
  • int pop() Returns the value at the top of the rightmost non-empty stack and removes it from that stack, and returns -1 if all stacks are empty.
  • \n\t
  • int popAtStack(int index) Returns the value at the top of the stack with the given index and removes it from that stack, and returns -1 if the stack with that given index is empty.
  • \n
\n\n

Example:

\n\n
\nInput: \n["DinnerPlates","push","push","push","push","push","popAtStack","push","push","popAtStack","popAtStack","pop","pop","pop","pop","pop"]\n[[2],[1],[2],[3],[4],[5],[0],[20],[21],[0],[2],[],[],[],[],[]]\nOutput: \n[null,null,null,null,null,null,2,null,null,20,21,5,4,3,1,-1]\n\nExplanation: \nDinnerPlates D = DinnerPlates(2);  // Initialize with capacity = 2\nD.push(1);\nD.push(2);\nD.push(3);\nD.push(4);\nD.push(5);         // The stacks are now:  2  4\n                                           1  3  5\n                                           \ufe48 \ufe48 \ufe48\nD.popAtStack(0);   // Returns 2.  The stacks are now:     4\n                                                       1  3  5\n                                                       \ufe48 \ufe48 \ufe48\nD.push(20);        // The stacks are now: 20  4\n                                           1  3  5\n                                           \ufe48 \ufe48 \ufe48\nD.push(21);        // The stacks are now: 20  4 21\n                                           1  3  5\n                                           \ufe48 \ufe48 \ufe48\nD.popAtStack(0);   // Returns 20.  The stacks are now:     4 21\n                                                        1  3  5\n                                                        \ufe48 \ufe48 \ufe48\nD.popAtStack(2);   // Returns 21.  The stacks are now:     4\n                                                        1  3  5\n                                                        \ufe48 \ufe48 \ufe48 \nD.pop()            // Returns 5.  The stacks are now:      4\n                                                        1  3 \n                                                        \ufe48 \ufe48  \nD.pop()            // Returns 4.  The stacks are now:   1  3 \n                                                        \ufe48 \ufe48   \nD.pop()            // Returns 3.  The stacks are now:   1 \n                                                        \ufe48   \nD.pop()            // Returns 1.  There are no stacks.\nD.pop()            // Returns -1.  There are still no stacks.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= capacity <= 20000
  • \n\t
  • 1 <= val <= 20000
  • \n\t
  • 0 <= index <= 100000
  • \n\t
  • At most 200000 calls will be made to push, pop, and popAtStack.
  • \n
\n", "content_cn": "

\u6211\u4eec\u628a\u65e0\u9650\u6570\u91cf ∞ \u7684\u6808\u6392\u6210\u4e00\u884c\uff0c\u6309\u4ece\u5de6\u5230\u53f3\u7684\u6b21\u5e8f\u4ece 0 \u5f00\u59cb\u7f16\u53f7\u3002\u6bcf\u4e2a\u6808\u7684\u7684\u6700\u5927\u5bb9\u91cf capacity \u90fd\u76f8\u540c\u3002

\n\n

\u5b9e\u73b0\u4e00\u4e2a\u53eb\u300c\u9910\u76d8\u300d\u7684\u7c7b DinnerPlates\uff1a

\n\n
    \n\t
  • DinnerPlates(int capacity) - \u7ed9\u51fa\u6808\u7684\u6700\u5927\u5bb9\u91cf capacity\u3002
  • \n\t
  • void push(int val) - \u5c06\u7ed9\u51fa\u7684\u6b63\u6574\u6570 val \u63a8\u5165 \u4ece\u5de6\u5f80\u53f3\u7b2c\u4e00\u4e2a \u6ca1\u6709\u6ee1\u7684\u6808\u3002
  • \n\t
  • int pop() - \u8fd4\u56de \u4ece\u53f3\u5f80\u5de6\u7b2c\u4e00\u4e2a \u975e\u7a7a\u6808\u9876\u90e8\u7684\u503c\uff0c\u5e76\u5c06\u5176\u4ece\u6808\u4e2d\u5220\u9664\uff1b\u5982\u679c\u6240\u6709\u7684\u6808\u90fd\u662f\u7a7a\u7684\uff0c\u8bf7\u8fd4\u56de -1\u3002
  • \n\t
  • int popAtStack(int index) - \u8fd4\u56de\u7f16\u53f7 index \u7684\u6808\u9876\u90e8\u7684\u503c\uff0c\u5e76\u5c06\u5176\u4ece\u6808\u4e2d\u5220\u9664\uff1b\u5982\u679c\u7f16\u53f7 index \u7684\u6808\u662f\u7a7a\u7684\uff0c\u8bf7\u8fd4\u56de -1\u3002
  • \n
\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1a \n["DinnerPlates","push","push","push","push","push","popAtStack","push","push","popAtStack","popAtStack","pop","pop","pop","pop","pop"]\n[[2],[1],[2],[3],[4],[5],[0],[20],[21],[0],[2],[],[],[],[],[]]\n\u8f93\u51fa\uff1a\n[null,null,null,null,null,null,2,null,null,20,21,5,4,3,1,-1]\n\n\u89e3\u91ca\uff1a\nDinnerPlates D = DinnerPlates(2);  // \u521d\u59cb\u5316\uff0c\u6808\u6700\u5927\u5bb9\u91cf capacity = 2\nD.push(1);\nD.push(2);\nD.push(3);\nD.push(4);\nD.push(5);         // \u6808\u7684\u73b0\u72b6\u4e3a\uff1a    2  4\n                                    1  3  5\n                                    \ufe48 \ufe48 \ufe48\nD.popAtStack(0);   // \u8fd4\u56de 2\u3002\u6808\u7684\u73b0\u72b6\u4e3a\uff1a      4\n                                          1  3  5\n                                          \ufe48 \ufe48 \ufe48\nD.push(20);        // \u6808\u7684\u73b0\u72b6\u4e3a\uff1a  20  4\n                                   1  3  5\n                                   \ufe48 \ufe48 \ufe48\nD.push(21);        // \u6808\u7684\u73b0\u72b6\u4e3a\uff1a  20  4 21\n                                   1  3  5\n                                   \ufe48 \ufe48 \ufe48\nD.popAtStack(0);   // \u8fd4\u56de 20\u3002\u6808\u7684\u73b0\u72b6\u4e3a\uff1a       4 21\n                                            1  3  5\n                                            \ufe48 \ufe48 \ufe48\nD.popAtStack(2);   // \u8fd4\u56de 21\u3002\u6808\u7684\u73b0\u72b6\u4e3a\uff1a       4\n                                            1  3  5\n                                            \ufe48 \ufe48 \ufe48 \nD.pop()            // \u8fd4\u56de 5\u3002\u6808\u7684\u73b0\u72b6\u4e3a\uff1a        4\n                                            1  3 \n                                            \ufe48 \ufe48  \nD.pop()            // \u8fd4\u56de 4\u3002\u6808\u7684\u73b0\u72b6\u4e3a\uff1a    1  3 \n                                           \ufe48 \ufe48   \nD.pop()            // \u8fd4\u56de 3\u3002\u6808\u7684\u73b0\u72b6\u4e3a\uff1a    1 \n                                           \ufe48   \nD.pop()            // \u8fd4\u56de 1\u3002\u73b0\u5728\u6ca1\u6709\u6808\u3002\nD.pop()            // \u8fd4\u56de -1\u3002\u4ecd\u7136\u6ca1\u6709\u6808\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= capacity <= 20000
  • \n\t
  • 1 <= val <= 20000
  • \n\t
  • 0 <= index <= 100000
  • \n\t
  • \u6700\u591a\u4f1a\u5bf9 push\uff0cpop\uff0c\u548c popAtStack \u8fdb\u884c 200000 \u6b21\u8c03\u7528\u3002
  • \n
\n", "tags_en": ["Design"], "tags_cn": ["\u8bbe\u8ba1"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class DinnerPlates {\npublic:\n DinnerPlates(int capacity) {\n\n }\n \n void push(int val) {\n\n }\n \n int pop() {\n\n }\n \n int popAtStack(int index) {\n\n }\n};\n\n/**\n * Your DinnerPlates object will be instantiated and called as such:\n * DinnerPlates* obj = new DinnerPlates(capacity);\n * obj->push(val);\n * int param_2 = obj->pop();\n * int param_3 = obj->popAtStack(index);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class DinnerPlates {\n\n public DinnerPlates(int capacity) {\n\n }\n \n public void push(int val) {\n\n }\n \n public int pop() {\n\n }\n \n public int popAtStack(int index) {\n\n }\n}\n\n/**\n * Your DinnerPlates object will be instantiated and called as such:\n * DinnerPlates obj = new DinnerPlates(capacity);\n * obj.push(val);\n * int param_2 = obj.pop();\n * int param_3 = obj.popAtStack(index);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class DinnerPlates(object):\n\n def __init__(self, capacity):\n \"\"\"\n :type capacity: int\n \"\"\"\n\n\n def push(self, val):\n \"\"\"\n :type val: int\n :rtype: None\n \"\"\"\n\n\n def pop(self):\n \"\"\"\n :rtype: int\n \"\"\"\n\n\n def popAtStack(self, index):\n \"\"\"\n :type index: int\n :rtype: int\n \"\"\"\n\n\n\n# Your DinnerPlates object will be instantiated and called as such:\n# obj = DinnerPlates(capacity)\n# obj.push(val)\n# param_2 = obj.pop()\n# param_3 = obj.popAtStack(index)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class DinnerPlates:\n\n def __init__(self, capacity: int):\n\n\n def push(self, val: int) -> None:\n\n\n def pop(self) -> int:\n\n\n def popAtStack(self, index: int) -> int:\n\n\n\n# Your DinnerPlates object will be instantiated and called as such:\n# obj = DinnerPlates(capacity)\n# obj.push(val)\n# param_2 = obj.pop()\n# param_3 = obj.popAtStack(index)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} DinnerPlates;\n\n\nDinnerPlates* dinnerPlatesCreate(int capacity) {\n\n}\n\nvoid dinnerPlatesPush(DinnerPlates* obj, int val) {\n\n}\n\nint dinnerPlatesPop(DinnerPlates* obj) {\n\n}\n\nint dinnerPlatesPopAtStack(DinnerPlates* obj, int index) {\n\n}\n\nvoid dinnerPlatesFree(DinnerPlates* obj) {\n\n}\n\n/**\n * Your DinnerPlates struct will be instantiated and called as such:\n * DinnerPlates* obj = dinnerPlatesCreate(capacity);\n * dinnerPlatesPush(obj, val);\n \n * int param_2 = dinnerPlatesPop(obj);\n \n * int param_3 = dinnerPlatesPopAtStack(obj, index);\n \n * dinnerPlatesFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class DinnerPlates {\n\n public DinnerPlates(int capacity) {\n\n }\n \n public void Push(int val) {\n\n }\n \n public int Pop() {\n\n }\n \n public int PopAtStack(int index) {\n\n }\n}\n\n/**\n * Your DinnerPlates object will be instantiated and called as such:\n * DinnerPlates obj = new DinnerPlates(capacity);\n * obj.Push(val);\n * int param_2 = obj.Pop();\n * int param_3 = obj.PopAtStack(index);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} capacity\n */\nvar DinnerPlates = function(capacity) {\n\n};\n\n/** \n * @param {number} val\n * @return {void}\n */\nDinnerPlates.prototype.push = function(val) {\n\n};\n\n/**\n * @return {number}\n */\nDinnerPlates.prototype.pop = function() {\n\n};\n\n/** \n * @param {number} index\n * @return {number}\n */\nDinnerPlates.prototype.popAtStack = function(index) {\n\n};\n\n/**\n * Your DinnerPlates object will be instantiated and called as such:\n * var obj = new DinnerPlates(capacity)\n * obj.push(val)\n * var param_2 = obj.pop()\n * var param_3 = obj.popAtStack(index)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class DinnerPlates\n\n=begin\n :type capacity: Integer\n=end\n def initialize(capacity)\n\n end\n\n\n=begin\n :type val: Integer\n :rtype: Void\n=end\n def push(val)\n\n end\n\n\n=begin\n :rtype: Integer\n=end\n def pop()\n\n end\n\n\n=begin\n :type index: Integer\n :rtype: Integer\n=end\n def pop_at_stack(index)\n\n end\n\n\nend\n\n# Your DinnerPlates object will be instantiated and called as such:\n# obj = DinnerPlates.new(capacity)\n# obj.push(val)\n# param_2 = obj.pop()\n# param_3 = obj.pop_at_stack(index)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass DinnerPlates {\n\n init(_ capacity: Int) {\n\n }\n \n func push(_ val: Int) {\n\n }\n \n func pop() -> Int {\n\n }\n \n func popAtStack(_ index: Int) -> Int {\n\n }\n}\n\n/**\n * Your DinnerPlates object will be instantiated and called as such:\n * let obj = DinnerPlates(capacity)\n * obj.push(val)\n * let ret_2: Int = obj.pop()\n * let ret_3: Int = obj.popAtStack(index)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type DinnerPlates struct {\n\n}\n\n\nfunc Constructor(capacity int) DinnerPlates {\n\n}\n\n\nfunc (this *DinnerPlates) Push(val int) {\n\n}\n\n\nfunc (this *DinnerPlates) Pop() int {\n\n}\n\n\nfunc (this *DinnerPlates) PopAtStack(index int) int {\n\n}\n\n\n/**\n * Your DinnerPlates object will be instantiated and called as such:\n * obj := Constructor(capacity);\n * obj.Push(val);\n * param_2 := obj.Pop();\n * param_3 := obj.PopAtStack(index);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class DinnerPlates(_capacity: Int) {\n\n def push(`val`: Int) {\n\n }\n\n def pop(): Int = {\n\n }\n\n def popAtStack(index: Int): Int = {\n\n }\n\n}\n\n/**\n * Your DinnerPlates object will be instantiated and called as such:\n * var obj = new DinnerPlates(capacity)\n * obj.push(`val`)\n * var param_2 = obj.pop()\n * var param_3 = obj.popAtStack(index)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class DinnerPlates(capacity: Int) {\n\n fun push(`val`: Int) {\n\n }\n\n fun pop(): Int {\n\n }\n\n fun popAtStack(index: Int): Int {\n\n }\n\n}\n\n/**\n * Your DinnerPlates object will be instantiated and called as such:\n * var obj = DinnerPlates(capacity)\n * obj.push(`val`)\n * var param_2 = obj.pop()\n * var param_3 = obj.popAtStack(index)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct DinnerPlates {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl DinnerPlates {\n\n fn new(capacity: i32) -> Self {\n\n }\n \n fn push(&self, val: i32) {\n\n }\n \n fn pop(&self) -> i32 {\n\n }\n \n fn pop_at_stack(&self, index: i32) -> i32 {\n\n }\n}\n\n/**\n * Your DinnerPlates object will be instantiated and called as such:\n * let obj = DinnerPlates::new(capacity);\n * obj.push(val);\n * let ret_2: i32 = obj.pop();\n * let ret_3: i32 = obj.pop_at_stack(index);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class DinnerPlates {\n /**\n * @param Integer $capacity\n */\n function __construct($capacity) {\n\n }\n\n /**\n * @param Integer $val\n * @return NULL\n */\n function push($val) {\n\n }\n\n /**\n * @return Integer\n */\n function pop() {\n\n }\n\n /**\n * @param Integer $index\n * @return Integer\n */\n function popAtStack($index) {\n\n }\n}\n\n/**\n * Your DinnerPlates object will be instantiated and called as such:\n * $obj = DinnerPlates($capacity);\n * $obj->push($val);\n * $ret_2 = $obj->pop();\n * $ret_3 = $obj->popAtStack($index);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class DinnerPlates {\n constructor(capacity: number) {\n\n }\n\n push(val: number): void {\n\n }\n\n pop(): number {\n\n }\n\n popAtStack(index: number): number {\n\n }\n}\n\n/**\n * Your DinnerPlates object will be instantiated and called as such:\n * var obj = new DinnerPlates(capacity)\n * obj.push(val)\n * var param_2 = obj.pop()\n * var param_3 = obj.popAtStack(index)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define dinner-plates%\n (class object%\n (super-new)\n\n ; capacity : exact-integer?\n (init-field\n capacity)\n \n ; push : exact-integer? -> void?\n (define/public (push val)\n\n )\n ; pop : -> exact-integer?\n (define/public (pop)\n\n )\n ; pop-at-stack : exact-integer? -> exact-integer?\n (define/public (pop-at-stack index)\n\n )))\n\n;; Your dinner-plates% object will be instantiated and called as such:\n;; (define obj (new dinner-plates% [capacity capacity]))\n;; (send obj push val)\n;; (define param_2 (send obj pop))\n;; (define param_3 (send obj pop-at-stack index))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1172](https://leetcode-cn.com/problems/dinner-plate-stacks)", "[\u9910\u76d8\u6808](/solution/1100-1199/1172.Dinner%20Plate%20Stacks/README.md)", "`\u8bbe\u8ba1`", "\u56f0\u96be", ""], "md_table_row_en": ["[1172](https://leetcode.com/problems/dinner-plate-stacks)", "[Dinner Plate Stacks](/solution/1100-1199/1172.Dinner%20Plate%20Stacks/README_EN.md)", "`Design`", "Hard", ""]}, {"question_id": "1269", "frontend_question_id": "1159", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/market-analysis-ii", "url_en": "https://leetcode.com/problems/market-analysis-ii", "relative_path_cn": "/solution/1100-1199/1159.Market%20Analysis%20II/README.md", "relative_path_en": "/solution/1100-1199/1159.Market%20Analysis%20II/README_EN.md", "title_cn": "\u5e02\u573a\u5206\u6790 II", "title_en": "Market Analysis II", "question_title_slug": "market-analysis-ii", "content_en": "

Table: Users

\n\n
\n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| user_id        | int     |\n| join_date      | date    |\n| favorite_brand | varchar |\n+----------------+---------+\nuser_id is the primary key of this table.\nThis table has the info of the users of an online shopping website where users can sell and buy items.
\n\n

Table: Orders

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| order_id      | int     |\n| order_date    | date    |\n| item_id       | int     |\n| buyer_id      | int     |\n| seller_id     | int     |\n+---------------+---------+\norder_id is the primary key of this table.\nitem_id is a foreign key to the Items table.\nbuyer_id and seller_id are foreign keys to the Users table.\n
\n\n

Table: Items

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| item_id       | int     |\n| item_brand    | varchar |\n+---------------+---------+\nitem_id is the primary key of this table.\n
\n\n

 

\n\n

Write an SQL query to find for each user, whether the brand of the second item (by date) they sold is their favorite brand. If a user sold less than two items, report the answer for that user as no.

\n\n

It is guaranteed that no seller sold more than one item on a day.

\n\n

The query result format is in the following example:

\n\n
\nUsers table:\n+---------+------------+----------------+\n| user_id | join_date  | favorite_brand |\n+---------+------------+----------------+\n| 1       | 2019-01-01 | Lenovo         |\n| 2       | 2019-02-09 | Samsung        |\n| 3       | 2019-01-19 | LG             |\n| 4       | 2019-05-21 | HP             |\n+---------+------------+----------------+\n\nOrders table:\n+----------+------------+---------+----------+-----------+\n| order_id | order_date | item_id | buyer_id | seller_id |\n+----------+------------+---------+----------+-----------+\n| 1        | 2019-08-01 | 4       | 1        | 2         |\n| 2        | 2019-08-02 | 2       | 1        | 3         |\n| 3        | 2019-08-03 | 3       | 2        | 3         |\n| 4        | 2019-08-04 | 1       | 4        | 2         |\n| 5        | 2019-08-04 | 1       | 3        | 4         |\n| 6        | 2019-08-05 | 2       | 2        | 4         |\n+----------+------------+---------+----------+-----------+\n\nItems table:\n+---------+------------+\n| item_id | item_brand |\n+---------+------------+\n| 1       | Samsung    |\n| 2       | Lenovo     |\n| 3       | LG         |\n| 4       | HP         |\n+---------+------------+\n\nResult table:\n+-----------+--------------------+\n| seller_id | 2nd_item_fav_brand |\n+-----------+--------------------+\n| 1         | no                 |\n| 2         | yes                |\n| 3         | yes                |\n| 4         | no                 |\n+-----------+--------------------+\n\nThe answer for the user with id 1 is no because they sold nothing.\nThe answer for the users with id 2 and 3 is yes because the brands of their second sold items are their favorite brands.\nThe answer for the user with id 4 is no because the brand of their second sold item is not their favorite brand.
\n", "content_cn": "

\u8868: Users

\n\n
\n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| user_id        | int     |\n| join_date      | date    |\n| favorite_brand | varchar |\n+----------------+---------+\nuser_id \u662f\u8be5\u8868\u7684\u4e3b\u952e\n\u8868\u4e2d\u5305\u542b\u4e00\u4f4d\u5728\u7ebf\u8d2d\u7269\u7f51\u7ad9\u7528\u6237\u7684\u4e2a\u4eba\u4fe1\u606f\uff0c\u7528\u6237\u53ef\u4ee5\u5728\u8be5\u7f51\u7ad9\u51fa\u552e\u548c\u8d2d\u4e70\u5546\u54c1\u3002\n
\n\n

\u8868: Orders

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| order_id      | int     |\n| order_date    | date    |\n| item_id       | int     |\n| buyer_id      | int     |\n| seller_id     | int     |\n+---------------+---------+\norder_id \u662f\u8be5\u8868\u7684\u4e3b\u952e\nitem_id \u662f Items \u8868\u7684\u5916\u952e\nbuyer_id \u548c seller_id \u662f Users \u8868\u7684\u5916\u952e\n
\n\n

\u8868: Items

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| item_id       | int     |\n| item_brand    | varchar |\n+---------------+---------+\nitem_id \u662f\u8be5\u8868\u7684\u4e3b\u952e\n
\n\n

 

\n\n

\u5199\u4e00\u4e2a SQL \u67e5\u8be2\u786e\u5b9a\u6bcf\u4e00\u4e2a\u7528\u6237\u6309\u65e5\u671f\u987a\u5e8f\u5356\u51fa\u7684\u7b2c\u4e8c\u4ef6\u5546\u54c1\u7684\u54c1\u724c\u662f\u5426\u662f\u4ed6\u4eec\u6700\u559c\u7231\u7684\u54c1\u724c\u3002\u5982\u679c\u4e00\u4e2a\u7528\u6237\u5356\u51fa\u5c11\u4e8e\u4e24\u4ef6\u5546\u54c1\uff0c\u67e5\u8be2\u7684\u7ed3\u679c\u662f no \u3002

\n\n

\u9898\u76ee\u4fdd\u8bc1\u6ca1\u6709\u4e00\u4e2a\u7528\u6237\u5728\u4e00\u5929\u4e2d\u5356\u51fa\u8d85\u8fc7\u4e00\u4ef6\u5546\u54c1

\n\n

\u4e0b\u9762\u662f\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u7684\u4f8b\u5b50\uff1a

\n\n
\nUsers table:\n+---------+------------+----------------+\n| user_id | join_date  | favorite_brand |\n+---------+------------+----------------+\n| 1       | 2019-01-01 | Lenovo         |\n| 2       | 2019-02-09 | Samsung        |\n| 3       | 2019-01-19 | LG             |\n| 4       | 2019-05-21 | HP             |\n+---------+------------+----------------+\n\nOrders table:\n+----------+------------+---------+----------+-----------+\n| order_id | order_date | item_id | buyer_id | seller_id |\n+----------+------------+---------+----------+-----------+\n| 1        | 2019-08-01 | 4       | 1        | 2         |\n| 2        | 2019-08-02 | 2       | 1        | 3         |\n| 3        | 2019-08-03 | 3       | 2        | 3         |\n| 4        | 2019-08-04 | 1       | 4        | 2         |\n| 5        | 2019-08-04 | 1       | 3        | 4         |\n| 6        | 2019-08-05 | 2       | 2        | 4         |\n+----------+------------+---------+----------+-----------+\n\nItems table:\n+---------+------------+\n| item_id | item_brand |\n+---------+------------+\n| 1       | Samsung    |\n| 2       | Lenovo     |\n| 3       | LG         |\n| 4       | HP         |\n+---------+------------+\n\nResult table:\n+-----------+--------------------+\n| seller_id | 2nd_item_fav_brand |\n+-----------+--------------------+\n| 1         | no                 |\n| 2         | yes                |\n| 3         | yes                |\n| 4         | no                 |\n+-----------+--------------------+\n\nid \u4e3a 1 \u7684\u7528\u6237\u7684\u67e5\u8be2\u7ed3\u679c\u662f no\uff0c\u56e0\u4e3a\u4ed6\u4ec0\u4e48\u4e5f\u6ca1\u6709\u5356\u51fa\nid\u4e3a 2 \u548c 3 \u7684\u7528\u6237\u7684\u67e5\u8be2\u7ed3\u679c\u662f yes\uff0c\u56e0\u4e3a\u4ed6\u4eec\u5356\u51fa\u7684\u7b2c\u4e8c\u4ef6\u5546\u54c1\u7684\u54c1\u724c\u662f\u4ed6\u4eec\u81ea\u5df1\u6700\u559c\u7231\u7684\u54c1\u724c\nid\u4e3a 4 \u7684\u7528\u6237\u7684\u67e5\u8be2\u7ed3\u679c\u662f no\uff0c\u56e0\u4e3a\u4ed6\u5356\u51fa\u7684\u7b2c\u4e8c\u4ef6\u5546\u54c1\u7684\u54c1\u724c\u4e0d\u662f\u4ed6\u6700\u559c\u7231\u7684\u54c1\u724c\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1159](https://leetcode-cn.com/problems/market-analysis-ii)", "[\u5e02\u573a\u5206\u6790 II](/solution/1100-1199/1159.Market%20Analysis%20II/README.md)", "", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1159](https://leetcode.com/problems/market-analysis-ii)", "[Market Analysis II](/solution/1100-1199/1159.Market%20Analysis%20II/README_EN.md)", "", "Hard", "\ud83d\udd12"]}, {"question_id": "1268", "frontend_question_id": "1158", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/market-analysis-i", "url_en": "https://leetcode.com/problems/market-analysis-i", "relative_path_cn": "/solution/1100-1199/1158.Market%20Analysis%20I/README.md", "relative_path_en": "/solution/1100-1199/1158.Market%20Analysis%20I/README_EN.md", "title_cn": "\u5e02\u573a\u5206\u6790 I", "title_en": "Market Analysis I", "question_title_slug": "market-analysis-i", "content_en": "

Table: Users

\n\n
\n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| user_id        | int     |\n| join_date      | date    |\n| favorite_brand | varchar |\n+----------------+---------+\nuser_id is the primary key of this table.\nThis table has the info of the users of an online shopping website where users can sell and buy items.
\n\n

Table: Orders

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| order_id      | int     |\n| order_date    | date    |\n| item_id       | int     |\n| buyer_id      | int     |\n| seller_id     | int     |\n+---------------+---------+\norder_id is the primary key of this table.\nitem_id is a foreign key to the Items table.\nbuyer_id and seller_id are foreign keys to the Users table.\n
\n\n

Table: Items

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| item_id       | int     |\n| item_brand    | varchar |\n+---------------+---------+\nitem_id is the primary key of this table.\n
\n\n

 

\n\n

Write an SQL query to find for each user, the join date and the number of orders they made as a buyer in 2019.

\n\n

The query result format is in the following example:

\n\n
\nUsers table:\n+---------+------------+----------------+\n| user_id | join_date  | favorite_brand |\n+---------+------------+----------------+\n| 1       | 2018-01-01 | Lenovo         |\n| 2       | 2018-02-09 | Samsung        |\n| 3       | 2018-01-19 | LG             |\n| 4       | 2018-05-21 | HP             |\n+---------+------------+----------------+\n\nOrders table:\n+----------+------------+---------+----------+-----------+\n| order_id | order_date | item_id | buyer_id | seller_id |\n+----------+------------+---------+----------+-----------+\n| 1        | 2019-08-01 | 4       | 1        | 2         |\n| 2        | 2018-08-02 | 2       | 1        | 3         |\n| 3        | 2019-08-03 | 3       | 2        | 3         |\n| 4        | 2018-08-04 | 1       | 4        | 2         |\n| 5        | 2018-08-04 | 1       | 3        | 4         |\n| 6        | 2019-08-05 | 2       | 2        | 4         |\n+----------+------------+---------+----------+-----------+\n\nItems table:\n+---------+------------+\n| item_id | item_brand |\n+---------+------------+\n| 1       | Samsung    |\n| 2       | Lenovo     |\n| 3       | LG         |\n| 4       | HP         |\n+---------+------------+\n\nResult table:\n+-----------+------------+----------------+\n| buyer_id  | join_date  | orders_in_2019 |\n+-----------+------------+----------------+\n| 1         | 2018-01-01 | 1              |\n| 2         | 2018-02-09 | 2              |\n| 3         | 2018-01-19 | 0              |\n| 4         | 2018-05-21 | 0              |\n+-----------+------------+----------------+\n
\n", "content_cn": "

Table: Users

\n\n
\n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| user_id        | int     |\n| join_date      | date    |\n| favorite_brand | varchar |\n+----------------+---------+\n\u6b64\u8868\u4e3b\u952e\u662f user_id\uff0c\u8868\u4e2d\u63cf\u8ff0\u4e86\u8d2d\u7269\u7f51\u7ad9\u7684\u7528\u6237\u4fe1\u606f\uff0c\u7528\u6237\u53ef\u4ee5\u5728\u6b64\u7f51\u7ad9\u4e0a\u8fdb\u884c\u5546\u54c1\u4e70\u5356\u3002\n
\n\n

Table: Orders

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| order_id      | int     |\n| order_date    | date    |\n| item_id       | int     |\n| buyer_id      | int     |\n| seller_id     | int     |\n+---------------+---------+\n\u6b64\u8868\u4e3b\u952e\u662f order_id\uff0c\u5916\u952e\u662f item_id \u548c\uff08buyer_id\uff0cseller_id\uff09\u3002\n
\n\n

Table: Item

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| item_id       | int     |\n| item_brand    | varchar |\n+---------------+---------+\n\u6b64\u8868\u4e3b\u952e\u662f item_id\u3002\n
\n\n

 

\n\n

\u8bf7\u5199\u51fa\u4e00\u6761SQL\u8bed\u53e5\u4ee5\u67e5\u8be2\u6bcf\u4e2a\u7528\u6237\u7684\u6ce8\u518c\u65e5\u671f\u548c\u5728 2019 \u5e74\u4f5c\u4e3a\u4e70\u5bb6\u7684\u8ba2\u5355\u603b\u6570\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\uff1a

\n\n
\nUsers table:\n+---------+------------+----------------+\n| user_id | join_date  | favorite_brand |\n+---------+------------+----------------+\n| 1       | 2018-01-01 | Lenovo         |\n| 2       | 2018-02-09 | Samsung        |\n| 3       | 2018-01-19 | LG             |\n| 4       | 2018-05-21 | HP             |\n+---------+------------+----------------+\n\nOrders table:\n+----------+------------+---------+----------+-----------+\n| order_id | order_date | item_id | buyer_id | seller_id |\n+----------+------------+---------+----------+-----------+\n| 1        | 2019-08-01 | 4       | 1        | 2         |\n| 2        | 2018-08-02 | 2       | 1        | 3         |\n| 3        | 2019-08-03 | 3       | 2        | 3         |\n| 4        | 2018-08-04 | 1       | 4        | 2         |\n| 5        | 2018-08-04 | 1       | 3        | 4         |\n| 6        | 2019-08-05 | 2       | 2        | 4         |\n+----------+------------+---------+----------+-----------+\n\nItems table:\n+---------+------------+\n| item_id | item_brand |\n+---------+------------+\n| 1       | Samsung    |\n| 2       | Lenovo     |\n| 3       | LG         |\n| 4       | HP         |\n+---------+------------+\n\nResult table:\n+-----------+------------+----------------+\n| buyer_id  | join_date  | orders_in_2019 |\n+-----------+------------+----------------+\n| 1         | 2018-01-01 | 1              |\n| 2         | 2018-02-09 | 2              |\n| 3         | 2018-01-19 | 0              |\n| 4         | 2018-05-21 | 0              |\n+-----------+------------+----------------+\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1158](https://leetcode-cn.com/problems/market-analysis-i)", "[\u5e02\u573a\u5206\u6790 I](/solution/1100-1199/1158.Market%20Analysis%20I/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1158](https://leetcode.com/problems/market-analysis-i)", "[Market Analysis I](/solution/1100-1199/1158.Market%20Analysis%20I/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1267", "frontend_question_id": "1171", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/remove-zero-sum-consecutive-nodes-from-linked-list", "url_en": "https://leetcode.com/problems/remove-zero-sum-consecutive-nodes-from-linked-list", "relative_path_cn": "/solution/1100-1199/1171.Remove%20Zero%20Sum%20Consecutive%20Nodes%20from%20Linked%20List/README.md", "relative_path_en": "/solution/1100-1199/1171.Remove%20Zero%20Sum%20Consecutive%20Nodes%20from%20Linked%20List/README_EN.md", "title_cn": "\u4ece\u94fe\u8868\u4e2d\u5220\u53bb\u603b\u548c\u503c\u4e3a\u96f6\u7684\u8fde\u7eed\u8282\u70b9", "title_en": "Remove Zero Sum Consecutive Nodes from Linked List", "question_title_slug": "remove-zero-sum-consecutive-nodes-from-linked-list", "content_en": "

Given the head of a linked list, we repeatedly delete consecutive sequences of nodes that sum to 0 until there are no such sequences.

\r\n\r\n

After doing so, return the head of the final linked list.  You may return any such answer.

\r\n\n

 

\n

(Note that in the examples below, all sequences are serializations of ListNode objects.)

\n\n

Example 1:

\n\n
\nInput: head = [1,2,-3,3,1]\nOutput: [3,1]\nNote: The answer [1,2,1] would also be accepted.\n
\n\n

Example 2:

\n\n
\nInput: head = [1,2,3,-3,4]\nOutput: [1,2,4]\n
\n\n

Example 3:

\n\n
\nInput: head = [1,2,3,-3,-2]\nOutput: [1]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The given linked list will contain between 1 and 1000 nodes.
  • \n\t
  • Each node in the linked list has -1000 <= node.val <= 1000.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u94fe\u8868\u7684\u5934\u8282\u70b9 head\uff0c\u8bf7\u4f60\u7f16\u5199\u4ee3\u7801\uff0c\u53cd\u590d\u5220\u53bb\u94fe\u8868\u4e2d\u7531 \u603b\u548c \u503c\u4e3a 0 \u7684\u8fde\u7eed\u8282\u70b9\u7ec4\u6210\u7684\u5e8f\u5217\uff0c\u76f4\u5230\u4e0d\u5b58\u5728\u8fd9\u6837\u7684\u5e8f\u5217\u4e3a\u6b62\u3002

\n\n

\u5220\u9664\u5b8c\u6bd5\u540e\uff0c\u8bf7\u4f60\u8fd4\u56de\u6700\u7ec8\u7ed3\u679c\u94fe\u8868\u7684\u5934\u8282\u70b9\u3002

\n\n

 

\n\n

\u4f60\u53ef\u4ee5\u8fd4\u56de\u4efb\u4f55\u6ee1\u8db3\u9898\u76ee\u8981\u6c42\u7684\u7b54\u6848\u3002

\n\n

\uff08\u6ce8\u610f\uff0c\u4e0b\u9762\u793a\u4f8b\u4e2d\u7684\u6240\u6709\u5e8f\u5217\uff0c\u90fd\u662f\u5bf9 ListNode \u5bf9\u8c61\u5e8f\u5217\u5316\u7684\u8868\u793a\u3002\uff09

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1ahead = [1,2,-3,3,1]\n\u8f93\u51fa\uff1a[3,1]\n\u63d0\u793a\uff1a\u7b54\u6848 [1,2,1] \u4e5f\u662f\u6b63\u786e\u7684\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1ahead = [1,2,3,-3,4]\n\u8f93\u51fa\uff1a[1,2,4]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1ahead = [1,2,3,-3,-2]\n\u8f93\u51fa\uff1a[1]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u7ed9\u4f60\u7684\u94fe\u8868\u4e2d\u53ef\u80fd\u6709 1 \u5230 1000 \u4e2a\u8282\u70b9\u3002
  • \n\t
  • \u5bf9\u4e8e\u94fe\u8868\u4e2d\u7684\u6bcf\u4e2a\u8282\u70b9\uff0c\u8282\u70b9\u7684\u503c\uff1a-1000 <= node.val <= 1000.
  • \n
\n", "tags_en": ["Linked List"], "tags_cn": ["\u94fe\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\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 ListNode* removeZeroSumSublists(ListNode* head) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode(int x) { val = x; }\n * }\n */\nclass Solution {\n public ListNode removeZeroSumSublists(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.next = None\n\nclass Solution(object):\n def removeZeroSumSublists(self, head):\n \"\"\"\n :type head: ListNode\n :rtype: ListNode\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, x):\n# self.val = x\n# self.next = None\n\nclass Solution:\n def removeZeroSumSublists(self, head: ListNode) -> ListNode:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nstruct ListNode* removeZeroSumSublists(struct ListNode* head){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int x) { val = x; }\n * }\n */\npublic class Solution {\n public ListNode RemoveZeroSumSublists(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val) {\n * this.val = val;\n * this.next = null;\n * }\n */\n/**\n * @param {ListNode} head\n * @return {ListNode}\n */\nvar removeZeroSumSublists = function(head) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val)\n# @val = val\n# @next = nil\n# end\n# end\n\n# @param {ListNode} head\n# @return {ListNode}\ndef remove_zero_sum_sublists(head)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.next = nil\n * }\n * }\n */\nclass Solution {\n func removeZeroSumSublists(_ head: ListNode?) -> ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc removeZeroSumSublists(head *ListNode) *ListNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(var _x: Int = 0) {\n * var next: ListNode = null\n * var x: Int = _x\n * }\n */\nobject Solution {\n def removeZeroSumSublists(head: ListNode): ListNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun removeZeroSumSublists(head: ListNode?): ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n// \n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn remove_zero_sum_sublists(head: Option>) -> Option> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val) { $this->val = $val; }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @return ListNode\n */\n function removeZeroSumSublists($head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction removeZeroSumSublists(head: ListNode | null): ListNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (remove-zero-sum-sublists head)\n (-> (or/c list-node? #f) (or/c list-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1171](https://leetcode-cn.com/problems/remove-zero-sum-consecutive-nodes-from-linked-list)", "[\u4ece\u94fe\u8868\u4e2d\u5220\u53bb\u603b\u548c\u503c\u4e3a\u96f6\u7684\u8fde\u7eed\u8282\u70b9](/solution/1100-1199/1171.Remove%20Zero%20Sum%20Consecutive%20Nodes%20from%20Linked%20List/README.md)", "`\u94fe\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1171](https://leetcode.com/problems/remove-zero-sum-consecutive-nodes-from-linked-list)", "[Remove Zero Sum Consecutive Nodes from Linked List](/solution/1100-1199/1171.Remove%20Zero%20Sum%20Consecutive%20Nodes%20from%20Linked%20List/README_EN.md)", "`Linked List`", "Medium", ""]}, {"question_id": "1263", "frontend_question_id": "1155", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-dice-rolls-with-target-sum", "url_en": "https://leetcode.com/problems/number-of-dice-rolls-with-target-sum", "relative_path_cn": "/solution/1100-1199/1155.Number%20of%20Dice%20Rolls%20With%20Target%20Sum/README.md", "relative_path_en": "/solution/1100-1199/1155.Number%20of%20Dice%20Rolls%20With%20Target%20Sum/README_EN.md", "title_cn": "\u63b7\u9ab0\u5b50\u7684N\u79cd\u65b9\u6cd5", "title_en": "Number of Dice Rolls With Target Sum", "question_title_slug": "number-of-dice-rolls-with-target-sum", "content_en": "

You have d dice and each die has f faces numbered 1, 2, ..., f.

\n\n

Return the number of possible ways (out of fd total ways) modulo 109 + 7 to roll the dice so the sum of the face-up numbers equals target.

\n\n

 

\n

Example 1:

\n\n
\nInput: d = 1, f = 6, target = 3\nOutput: 1\nExplanation: \nYou throw one die with 6 faces.  There is only one way to get a sum of 3.\n
\n\n

Example 2:

\n\n
\nInput: d = 2, f = 6, target = 7\nOutput: 6\nExplanation: \nYou throw two dice, each with 6 faces.  There are 6 ways to get a sum of 7:\n1+6, 2+5, 3+4, 4+3, 5+2, 6+1.\n
\n\n

Example 3:

\n\n
\nInput: d = 2, f = 5, target = 10\nOutput: 1\nExplanation: \nYou throw two dice, each with 5 faces.  There is only one way to get a sum of 10: 5+5.\n
\n\n

Example 4:

\n\n
\nInput: d = 1, f = 2, target = 3\nOutput: 0\nExplanation: \nYou throw one die with 2 faces.  There is no way to get a sum of 3.\n
\n\n

Example 5:

\n\n
\nInput: d = 30, f = 30, target = 500\nOutput: 222616187\nExplanation: \nThe answer must be returned modulo 10^9 + 7.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= d, f <= 30
  • \n\t
  • 1 <= target <= 1000
  • \n
\n", "content_cn": "

\u8fd9\u91cc\u6709 d \u4e2a\u4e00\u6837\u7684\u9ab0\u5b50\uff0c\u6bcf\u4e2a\u9ab0\u5b50\u4e0a\u90fd\u6709 f \u4e2a\u9762\uff0c\u5206\u522b\u6807\u53f7\u4e3a 1, 2, ..., f\u3002

\n\n

\u6211\u4eec\u7ea6\u5b9a\uff1a\u63b7\u9ab0\u5b50\u7684\u5f97\u5230\u603b\u70b9\u6570\u4e3a\u5404\u9ab0\u5b50\u9762\u671d\u4e0a\u7684\u6570\u5b57\u7684\u603b\u548c\u3002

\n\n

\u5982\u679c\u9700\u8981\u63b7\u51fa\u7684\u603b\u70b9\u6570\u4e3a target\uff0c\u8bf7\u4f60\u8ba1\u7b97\u51fa\u6709\u591a\u5c11\u79cd\u4e0d\u540c\u7684\u7ec4\u5408\u60c5\u51b5\uff08\u6240\u6709\u7684\u7ec4\u5408\u60c5\u51b5\u603b\u5171\u6709 f^d \u79cd\uff09\uff0c\u6a21 10^9 + 7 \u540e\u8fd4\u56de\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1ad = 1, f = 6, target = 3\n\u8f93\u51fa\uff1a1\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1ad = 2, f = 6, target = 7\n\u8f93\u51fa\uff1a6\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1ad = 2, f = 5, target = 10\n\u8f93\u51fa\uff1a1\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1ad = 1, f = 2, target = 3\n\u8f93\u51fa\uff1a0\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1ad = 30, f = 30, target = 500\n\u8f93\u51fa\uff1a222616187
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= d, f <= 30
  • \n\t
  • 1 <= target <= 1000
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numRollsToTarget(int d, int f, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numRollsToTarget(int d, int f, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numRollsToTarget(self, d, f, target):\n \"\"\"\n :type d: int\n :type f: int\n :type target: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numRollsToTarget(self, d: int, f: int, target: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numRollsToTarget(int d, int f, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumRollsToTarget(int d, int f, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} d\n * @param {number} f\n * @param {number} target\n * @return {number}\n */\nvar numRollsToTarget = function(d, f, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} d\n# @param {Integer} f\n# @param {Integer} target\n# @return {Integer}\ndef num_rolls_to_target(d, f, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numRollsToTarget(_ d: Int, _ f: Int, _ target: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numRollsToTarget(d int, f int, target int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numRollsToTarget(d: Int, f: Int, target: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numRollsToTarget(d: Int, f: Int, target: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_rolls_to_target(d: i32, f: i32, target: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $d\n * @param Integer $f\n * @param Integer $target\n * @return Integer\n */\n function numRollsToTarget($d, $f, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numRollsToTarget(d: number, f: number, target: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-rolls-to-target d f target)\n (-> exact-integer? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1155](https://leetcode-cn.com/problems/number-of-dice-rolls-with-target-sum)", "[\u63b7\u9ab0\u5b50\u7684N\u79cd\u65b9\u6cd5](/solution/1100-1199/1155.Number%20of%20Dice%20Rolls%20With%20Target%20Sum/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1155](https://leetcode.com/problems/number-of-dice-rolls-with-target-sum)", "[Number of Dice Rolls With Target Sum](/solution/1100-1199/1155.Number%20of%20Dice%20Rolls%20With%20Target%20Sum/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "1262", "frontend_question_id": "1157", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/online-majority-element-in-subarray", "url_en": "https://leetcode.com/problems/online-majority-element-in-subarray", "relative_path_cn": "/solution/1100-1199/1157.Online%20Majority%20Element%20In%20Subarray/README.md", "relative_path_en": "/solution/1100-1199/1157.Online%20Majority%20Element%20In%20Subarray/README_EN.md", "title_cn": "\u5b50\u6570\u7ec4\u4e2d\u5360\u7edd\u5927\u591a\u6570\u7684\u5143\u7d20", "title_en": "Online Majority Element In Subarray", "question_title_slug": "online-majority-element-in-subarray", "content_en": "

Implementing the class MajorityChecker, which has the following API:

\n\n
    \n\t
  • MajorityChecker(int[] arr) constructs an instance of MajorityChecker with the given array arr;
  • \n\t
  • int query(int left, int right, int threshold) has arguments such that:\n\t
      \n\t\t
    • 0 <= left <= right < arr.length representing a subarray of arr;
    • \n\t\t
    • 2 * threshold > right - left + 1, ie. the threshold is always a strict majority of the length of the subarray
    • \n\t
    \n\t
  • \n
\n\n

Each query(...) returns the element in arr[left], arr[left+1], ..., arr[right] that occurs at least threshold times, or -1 if no such element exists.

\n\n

 

\n\n

Example:

\n\n
\nMajorityChecker majorityChecker = new MajorityChecker([1,1,2,2,1,1]);\nmajorityChecker.query(0,5,4); // returns 1\nmajorityChecker.query(0,3,3); // returns -1\nmajorityChecker.query(2,3,2); // returns 2\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= arr.length <= 20000
  • \n\t
  • 1 <= arr[i] <= 20000
  • \n\t
  • For each query, 0 <= left <= right < len(arr)
  • \n\t
  • For each query, 2 * threshold > right - left + 1
  • \n\t
  • The number of queries is at most 10000
  • \n
\n", "content_cn": "

\u5b9e\u73b0\u4e00\u4e2a MajorityChecker \u7684\u7c7b\uff0c\u5b83\u5e94\u8be5\u5177\u6709\u4e0b\u8ff0\u51e0\u4e2a API\uff1a

\n\n
    \n\t
  • MajorityChecker(int[] arr) \u4f1a\u7528\u7ed9\u5b9a\u7684\u6570\u7ec4 arr \u6765\u6784\u9020\u4e00\u4e2a MajorityChecker \u7684\u5b9e\u4f8b\u3002
  • \n\t
  • int query(int left, int right, int threshold) \u6709\u8fd9\u4e48\u51e0\u4e2a\u53c2\u6570\uff1a\n\t
      \n\t\t
    • 0 <= left <= right < arr.length \u8868\u793a\u6570\u7ec4 arr \u7684\u5b50\u6570\u7ec4\u7684\u957f\u5ea6\u3002
    • \n\t\t
    • 2 * threshold > right - left + 1\uff0c\u4e5f\u5c31\u662f\u8bf4\u9608\u503c threshold \u59cb\u7ec8\u6bd4\u5b50\u5e8f\u5217\u957f\u5ea6\u7684\u4e00\u534a\u8fd8\u8981\u5927\u3002
    • \n\t
    \n\t
  • \n
\n\n

\u6bcf\u6b21\u67e5\u8be2 query(...) \u4f1a\u8fd4\u56de\u5728 arr[left], arr[left+1], ..., arr[right] \u4e2d\u81f3\u5c11\u51fa\u73b0\u9608\u503c\u6b21\u6570 threshold \u7684\u5143\u7d20\uff0c\u5982\u679c\u4e0d\u5b58\u5728\u8fd9\u6837\u7684\u5143\u7d20\uff0c\u5c31\u8fd4\u56de -1\u3002

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
MajorityChecker majorityChecker = new MajorityChecker([1,1,2,2,1,1]);\nmajorityChecker.query(0,5,4); // \u8fd4\u56de 1\nmajorityChecker.query(0,3,3); // \u8fd4\u56de -1\nmajorityChecker.query(2,3,2); // \u8fd4\u56de 2\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= arr.length <= 20000
  • \n\t
  • 1 <= arr[i] <= 20000
  • \n\t
  • \u5bf9\u4e8e\u6bcf\u6b21\u67e5\u8be2\uff0c0 <= left <= right < len(arr)
  • \n\t
  • \u5bf9\u4e8e\u6bcf\u6b21\u67e5\u8be2\uff0c2 * threshold > right - left + 1
  • \n\t
  • \u67e5\u8be2\u6b21\u6570\u6700\u591a\u4e3a 10000
  • \n
\n", "tags_en": ["Segment Tree", "Array", "Binary Search"], "tags_cn": ["\u7ebf\u6bb5\u6811", "\u6570\u7ec4", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class MajorityChecker {\npublic:\n MajorityChecker(vector& arr) {\n\n }\n \n int query(int left, int right, int threshold) {\n\n }\n};\n\n/**\n * Your MajorityChecker object will be instantiated and called as such:\n * MajorityChecker* obj = new MajorityChecker(arr);\n * int param_1 = obj->query(left,right,threshold);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class MajorityChecker {\n\n public MajorityChecker(int[] arr) {\n\n }\n \n public int query(int left, int right, int threshold) {\n\n }\n}\n\n/**\n * Your MajorityChecker object will be instantiated and called as such:\n * MajorityChecker obj = new MajorityChecker(arr);\n * int param_1 = obj.query(left,right,threshold);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class MajorityChecker(object):\n\n def __init__(self, arr):\n \"\"\"\n :type arr: List[int]\n \"\"\"\n\n\n def query(self, left, right, threshold):\n \"\"\"\n :type left: int\n :type right: int\n :type threshold: int\n :rtype: int\n \"\"\"\n\n\n\n# Your MajorityChecker object will be instantiated and called as such:\n# obj = MajorityChecker(arr)\n# param_1 = obj.query(left,right,threshold)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class MajorityChecker:\n\n def __init__(self, arr: List[int]):\n\n\n def query(self, left: int, right: int, threshold: int) -> int:\n\n\n\n# Your MajorityChecker object will be instantiated and called as such:\n# obj = MajorityChecker(arr)\n# param_1 = obj.query(left,right,threshold)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} MajorityChecker;\n\n\nMajorityChecker* majorityCheckerCreate(int* arr, int arrSize) {\n\n}\n\nint majorityCheckerQuery(MajorityChecker* obj, int left, int right, int threshold) {\n\n}\n\nvoid majorityCheckerFree(MajorityChecker* obj) {\n\n}\n\n/**\n * Your MajorityChecker struct will be instantiated and called as such:\n * MajorityChecker* obj = majorityCheckerCreate(arr, arrSize);\n * int param_1 = majorityCheckerQuery(obj, left, right, threshold);\n \n * majorityCheckerFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class MajorityChecker {\n\n public MajorityChecker(int[] arr) {\n\n }\n \n public int Query(int left, int right, int threshold) {\n\n }\n}\n\n/**\n * Your MajorityChecker object will be instantiated and called as such:\n * MajorityChecker obj = new MajorityChecker(arr);\n * int param_1 = obj.Query(left,right,threshold);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n */\nvar MajorityChecker = function(arr) {\n\n};\n\n/** \n * @param {number} left \n * @param {number} right \n * @param {number} threshold\n * @return {number}\n */\nMajorityChecker.prototype.query = function(left, right, threshold) {\n\n};\n\n/**\n * Your MajorityChecker object will be instantiated and called as such:\n * var obj = new MajorityChecker(arr)\n * var param_1 = obj.query(left,right,threshold)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class MajorityChecker\n\n=begin\n :type arr: Integer[]\n=end\n def initialize(arr)\n\n end\n\n\n=begin\n :type left: Integer\n :type right: Integer\n :type threshold: Integer\n :rtype: Integer\n=end\n def query(left, right, threshold)\n\n end\n\n\nend\n\n# Your MajorityChecker object will be instantiated and called as such:\n# obj = MajorityChecker.new(arr)\n# param_1 = obj.query(left, right, threshold)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass MajorityChecker {\n\n init(_ arr: [Int]) {\n\n }\n \n func query(_ left: Int, _ right: Int, _ threshold: Int) -> Int {\n\n }\n}\n\n/**\n * Your MajorityChecker object will be instantiated and called as such:\n * let obj = MajorityChecker(arr)\n * let ret_1: Int = obj.query(left, right, threshold)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type MajorityChecker struct {\n\n}\n\n\nfunc Constructor(arr []int) MajorityChecker {\n\n}\n\n\nfunc (this *MajorityChecker) Query(left int, right int, threshold int) int {\n\n}\n\n\n/**\n * Your MajorityChecker object will be instantiated and called as such:\n * obj := Constructor(arr);\n * param_1 := obj.Query(left,right,threshold);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class MajorityChecker(_arr: Array[Int]) {\n\n def query(left: Int, right: Int, threshold: Int): Int = {\n\n }\n\n}\n\n/**\n * Your MajorityChecker object will be instantiated and called as such:\n * var obj = new MajorityChecker(arr)\n * var param_1 = obj.query(left,right,threshold)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class MajorityChecker(arr: IntArray) {\n\n fun query(left: Int, right: Int, threshold: Int): Int {\n\n }\n\n}\n\n/**\n * Your MajorityChecker object will be instantiated and called as such:\n * var obj = MajorityChecker(arr)\n * var param_1 = obj.query(left,right,threshold)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct MajorityChecker {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl MajorityChecker {\n\n fn new(arr: Vec) -> Self {\n\n }\n \n fn query(&self, left: i32, right: i32, threshold: i32) -> i32 {\n\n }\n}\n\n/**\n * Your MajorityChecker object will be instantiated and called as such:\n * let obj = MajorityChecker::new(arr);\n * let ret_1: i32 = obj.query(left, right, threshold);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class MajorityChecker {\n /**\n * @param Integer[] $arr\n */\n function __construct($arr) {\n\n }\n\n /**\n * @param Integer $left\n * @param Integer $right\n * @param Integer $threshold\n * @return Integer\n */\n function query($left, $right, $threshold) {\n\n }\n}\n\n/**\n * Your MajorityChecker object will be instantiated and called as such:\n * $obj = MajorityChecker($arr);\n * $ret_1 = $obj->query($left, $right, $threshold);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class MajorityChecker {\n constructor(arr: number[]) {\n\n }\n\n query(left: number, right: number, threshold: number): number {\n\n }\n}\n\n/**\n * Your MajorityChecker object will be instantiated and called as such:\n * var obj = new MajorityChecker(arr)\n * var param_1 = obj.query(left,right,threshold)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define majority-checker%\n (class object%\n (super-new)\n\n ; arr : (listof exact-integer?)\n (init-field\n arr)\n \n ; query : exact-integer? exact-integer? exact-integer? -> exact-integer?\n (define/public (query left right threshold)\n\n )))\n\n;; Your majority-checker% object will be instantiated and called as such:\n;; (define obj (new majority-checker% [arr arr]))\n;; (define param_1 (send obj query left right threshold))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1157](https://leetcode-cn.com/problems/online-majority-element-in-subarray)", "[\u5b50\u6570\u7ec4\u4e2d\u5360\u7edd\u5927\u591a\u6570\u7684\u5143\u7d20](/solution/1100-1199/1157.Online%20Majority%20Element%20In%20Subarray/README.md)", "`\u7ebf\u6bb5\u6811`,`\u6570\u7ec4`,`\u4e8c\u5206\u67e5\u627e`", "\u56f0\u96be", ""], "md_table_row_en": ["[1157](https://leetcode.com/problems/online-majority-element-in-subarray)", "[Online Majority Element In Subarray](/solution/1100-1199/1157.Online%20Majority%20Element%20In%20Subarray/README_EN.md)", "`Segment Tree`,`Array`,`Binary Search`", "Hard", ""]}, {"question_id": "1261", "frontend_question_id": "1156", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/swap-for-longest-repeated-character-substring", "url_en": "https://leetcode.com/problems/swap-for-longest-repeated-character-substring", "relative_path_cn": "/solution/1100-1199/1156.Swap%20For%20Longest%20Repeated%20Character%20Substring/README.md", "relative_path_en": "/solution/1100-1199/1156.Swap%20For%20Longest%20Repeated%20Character%20Substring/README_EN.md", "title_cn": "\u5355\u5b57\u7b26\u91cd\u590d\u5b50\u4e32\u7684\u6700\u5927\u957f\u5ea6", "title_en": "Swap For Longest Repeated Character Substring", "question_title_slug": "swap-for-longest-repeated-character-substring", "content_en": "

Given a string text, we are allowed to swap two of the characters in the string. Find the length of the longest substring with repeated characters.

\n\n

 

\n

Example 1:

\n\n
\nInput: text = "ababa"\nOutput: 3\nExplanation: We can swap the first 'b' with the last 'a', or the last 'b' with the first 'a'. Then, the longest repeated character substring is "aaa", which its length is 3.\n
\n\n

Example 2:

\n\n
\nInput: text = "aaabaaa"\nOutput: 6\nExplanation: Swap 'b' with the last 'a' (or the first 'a'), and we get longest repeated character substring "aaaaaa", which its length is 6.\n
\n\n

Example 3:

\n\n
\nInput: text = "aaabbaaa"\nOutput: 4\n
\n\n

Example 4:

\n\n
\nInput: text = "aaaaa"\nOutput: 5\nExplanation: No need to swap, longest repeated character substring is "aaaaa", length is 5.\n
\n\n

Example 5:

\n\n
\nInput: text = "abcdef"\nOutput: 1\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= text.length <= 20000
  • \n\t
  • text consist of lowercase English characters only.
  • \n
\n", "content_cn": "

\u5982\u679c\u5b57\u7b26\u4e32\u4e2d\u7684\u6240\u6709\u5b57\u7b26\u90fd\u76f8\u540c\uff0c\u90a3\u4e48\u8fd9\u4e2a\u5b57\u7b26\u4e32\u662f\u5355\u5b57\u7b26\u91cd\u590d\u7684\u5b57\u7b26\u4e32\u3002

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 text\uff0c\u4f60\u53ea\u80fd\u4ea4\u6362\u5176\u4e2d\u4e24\u4e2a\u5b57\u7b26\u4e00\u6b21\u6216\u8005\u4ec0\u4e48\u90fd\u4e0d\u505a\uff0c\u7136\u540e\u5f97\u5230\u4e00\u4e9b\u5355\u5b57\u7b26\u91cd\u590d\u7684\u5b50\u4e32\u3002\u8fd4\u56de\u5176\u4e2d\u6700\u957f\u7684\u5b50\u4e32\u7684\u957f\u5ea6\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1atext = "ababa"\n\u8f93\u51fa\uff1a3\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1atext = "aaabaaa"\n\u8f93\u51fa\uff1a6\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1atext = "aaabbaaa"\n\u8f93\u51fa\uff1a4\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1atext = "aaaaa"\n\u8f93\u51fa\uff1a5\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1atext = "abcdef"\n\u8f93\u51fa\uff1a1\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= text.length <= 20000
  • \n\t
  • text \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\u3002
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxRepOpt1(string text) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxRepOpt1(String text) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxRepOpt1(self, text):\n \"\"\"\n :type text: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxRepOpt1(self, text: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxRepOpt1(char * text){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxRepOpt1(string text) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} text\n * @return {number}\n */\nvar maxRepOpt1 = function(text) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} text\n# @return {Integer}\ndef max_rep_opt1(text)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxRepOpt1(_ text: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxRepOpt1(text string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxRepOpt1(text: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxRepOpt1(text: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_rep_opt1(text: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $text\n * @return Integer\n */\n function maxRepOpt1($text) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxRepOpt1(text: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-rep-opt1 text)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1156](https://leetcode-cn.com/problems/swap-for-longest-repeated-character-substring)", "[\u5355\u5b57\u7b26\u91cd\u590d\u5b50\u4e32\u7684\u6700\u5927\u957f\u5ea6](/solution/1100-1199/1156.Swap%20For%20Longest%20Repeated%20Character%20Substring/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1156](https://leetcode.com/problems/swap-for-longest-repeated-character-substring)", "[Swap For Longest Repeated Character Substring](/solution/1100-1199/1156.Swap%20For%20Longest%20Repeated%20Character%20Substring/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "1260", "frontend_question_id": "1154", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/day-of-the-year", "url_en": "https://leetcode.com/problems/day-of-the-year", "relative_path_cn": "/solution/1100-1199/1154.Day%20of%20the%20Year/README.md", "relative_path_en": "/solution/1100-1199/1154.Day%20of%20the%20Year/README_EN.md", "title_cn": "\u4e00\u5e74\u4e2d\u7684\u7b2c\u51e0\u5929", "title_en": "Day of the Year", "question_title_slug": "day-of-the-year", "content_en": "

Given a string date representing a Gregorian calendar date formatted as YYYY-MM-DD, return the day number of the year.

\n\n

 

\n

Example 1:

\n\n
\nInput: date = "2019-01-09"\nOutput: 9\nExplanation: Given date is the 9th day of the year in 2019.\n
\n\n

Example 2:

\n\n
\nInput: date = "2019-02-10"\nOutput: 41\n
\n\n

Example 3:

\n\n
\nInput: date = "2003-03-01"\nOutput: 60\n
\n\n

Example 4:

\n\n
\nInput: date = "2004-03-01"\nOutput: 61\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • date.length == 10
  • \n\t
  • date[4] == date[7] == '-', and all other date[i]'s are digits
  • \n\t
  • date represents a calendar date between Jan 1st, 1900 and Dec 31, 2019.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6309 YYYY-MM-DD \u683c\u5f0f\u8868\u793a\u65e5\u671f\u7684\u5b57\u7b26\u4e32 date\uff0c\u8bf7\u4f60\u8ba1\u7b97\u5e76\u8fd4\u56de\u8be5\u65e5\u671f\u662f\u5f53\u5e74\u7684\u7b2c\u51e0\u5929\u3002

\n\n

\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u8ba4\u4e3a 1 \u6708 1 \u65e5\u662f\u6bcf\u5e74\u7684\u7b2c 1 \u5929\uff0c1 \u6708 2 \u65e5\u662f\u6bcf\u5e74\u7684\u7b2c 2 \u5929\uff0c\u4f9d\u6b64\u7c7b\u63a8\u3002\u6bcf\u4e2a\u6708\u7684\u5929\u6570\u4e0e\u73b0\u884c\u516c\u5143\u7eaa\u5e74\u6cd5\uff08\u683c\u91cc\u9ad8\u5229\u5386\uff09\u4e00\u81f4\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1adate = "2019-01-09"\n\u8f93\u51fa\uff1a9\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1adate = "2019-02-10"\n\u8f93\u51fa\uff1a41\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1adate = "2003-03-01"\n\u8f93\u51fa\uff1a60\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1adate = "2004-03-01"\n\u8f93\u51fa\uff1a61
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • date.length == 10
  • \n\t
  • date[4] == date[7] == '-'\uff0c\u5176\u4ed6\u7684 date[i] \u90fd\u662f\u6570\u5b57\u3002
  • \n\t
  • date \u8868\u793a\u7684\u8303\u56f4\u4ece 1900 \u5e74 1 \u6708 1 \u65e5\u81f3 2019 \u5e74 12 \u6708 31 \u65e5\u3002
  • \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int dayOfYear(string date) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int dayOfYear(String date) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def dayOfYear(self, date):\n \"\"\"\n :type date: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def dayOfYear(self, date: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint dayOfYear(char * date){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int DayOfYear(string date) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} date\n * @return {number}\n */\nvar dayOfYear = function(date) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} date\n# @return {Integer}\ndef day_of_year(date)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func dayOfYear(_ date: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func dayOfYear(date string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def dayOfYear(date: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun dayOfYear(date: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn day_of_year(date: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $date\n * @return Integer\n */\n function dayOfYear($date) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function dayOfYear(date: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (day-of-year date)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1154](https://leetcode-cn.com/problems/day-of-the-year)", "[\u4e00\u5e74\u4e2d\u7684\u7b2c\u51e0\u5929](/solution/1100-1199/1154.Day%20of%20the%20Year/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[1154](https://leetcode.com/problems/day-of-the-year)", "[Day of the Year](/solution/1100-1199/1154.Day%20of%20the%20Year/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "1259", "frontend_question_id": "1149", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/article-views-ii", "url_en": "https://leetcode.com/problems/article-views-ii", "relative_path_cn": "/solution/1100-1199/1149.Article%20Views%20II/README.md", "relative_path_en": "/solution/1100-1199/1149.Article%20Views%20II/README_EN.md", "title_cn": "\u6587\u7ae0\u6d4f\u89c8 II", "title_en": "Article Views II", "question_title_slug": "article-views-ii", "content_en": "

Table: Views

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| article_id    | int     |\n| author_id     | int     |\n| viewer_id     | int     |\n| view_date     | date    |\n+---------------+---------+\nThere is no primary key for this table, it may have duplicate rows.\nEach row of this table indicates that some viewer viewed an article (written by some author) on some date. \nNote that equal author_id and viewer_id indicate the same person.
\n\n

 

\n\n

Write an SQL query to find all the people who viewed more than one article on the same date, sorted in ascending order by their id.

\n\n

The query result format is in the following example:

\n\n
\nViews table:\n+------------+-----------+-----------+------------+\n| article_id | author_id | viewer_id | view_date  |\n+------------+-----------+-----------+------------+\n| 1          | 3         | 5         | 2019-08-01 |\n| 3          | 4         | 5         | 2019-08-01 |\n| 1          | 3         | 6         | 2019-08-02 |\n| 2          | 7         | 7         | 2019-08-01 |\n| 2          | 7         | 6         | 2019-08-02 |\n| 4          | 7         | 1         | 2019-07-22 |\n| 3          | 4         | 4         | 2019-07-21 |\n| 3          | 4         | 4         | 2019-07-21 |\n+------------+-----------+-----------+------------+\n\nResult table:\n+------+\n| id   |\n+------+\n| 5    |\n| 6    |\n+------+
\n", "content_cn": "

Table: Views

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| article_id    | int     |\n| author_id     | int     |\n| viewer_id     | int     |\n| view_date     | date    |\n+---------------+---------+\n\u6b64\u8868\u65e0\u4e3b\u952e\uff0c\u56e0\u6b64\u53ef\u80fd\u4f1a\u5b58\u5728\u91cd\u590d\u884c\u3002\u6b64\u8868\u7684\u6bcf\u4e00\u884c\u90fd\u8868\u793a\u67d0\u4eba\u5728\u67d0\u5929\u6d4f\u89c8\u4e86\u67d0\u4f4d\u4f5c\u8005\u7684\u67d0\u7bc7\u6587\u7ae0\u3002 \u8bf7\u6ce8\u610f\uff0c\u540c\u4e00\u4eba\u7684 author_id \u548c viewer_id \u662f\u76f8\u540c\u7684\u3002\n
\n\n

 

\n\n

\u7f16\u5199\u4e00\u6761 SQL \u67e5\u8be2\u6765\u627e\u51fa\u5728\u540c\u4e00\u5929\u9605\u8bfb\u81f3\u5c11\u4e24\u7bc7\u6587\u7ae0\u7684\u4eba\uff0c\u7ed3\u679c\u6309\u7167 id \u5347\u5e8f\u6392\u5e8f\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u7684\u683c\u5f0f\u5982\u4e0b\uff1a

\n\n
\nViews table:\n+------------+-----------+-----------+------------+\n| article_id | author_id | viewer_id | view_date  |\n+------------+-----------+-----------+------------+\n| 1          | 3         | 5         | 2019-08-01 |\n| 3          | 4         | 5         | 2019-08-01 |\n| 1          | 3         | 6         | 2019-08-02 |\n| 2          | 7         | 7         | 2019-08-01 |\n| 2          | 7         | 6         | 2019-08-02 |\n| 4          | 7         | 1         | 2019-07-22 |\n| 3          | 4         | 4         | 2019-07-21 |\n| 3          | 4         | 4         | 2019-07-21 |\n+------------+-----------+-----------+------------+\n\nResult table:\n+------+\n| id   |\n+------+\n| 5    |\n| 6    |\n+------+
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1149](https://leetcode-cn.com/problems/article-views-ii)", "[\u6587\u7ae0\u6d4f\u89c8 II](/solution/1100-1199/1149.Article%20Views%20II/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1149](https://leetcode.com/problems/article-views-ii)", "[Article Views II](/solution/1100-1199/1149.Article%20Views%20II/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1258", "frontend_question_id": "1148", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/article-views-i", "url_en": "https://leetcode.com/problems/article-views-i", "relative_path_cn": "/solution/1100-1199/1148.Article%20Views%20I/README.md", "relative_path_en": "/solution/1100-1199/1148.Article%20Views%20I/README_EN.md", "title_cn": "\u6587\u7ae0\u6d4f\u89c8 I", "title_en": "Article Views I", "question_title_slug": "article-views-i", "content_en": "

Table: Views

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| article_id    | int     |\n| author_id     | int     |\n| viewer_id     | int     |\n| view_date     | date    |\n+---------------+---------+\nThere is no primary key for this table, it may have duplicate rows.\nEach row of this table indicates that some viewer viewed an article (written by some author) on some date. \nNote that equal author_id and viewer_id indicate the same person.
\n\n

 

\n\n

Write an SQL query to find all the authors that viewed at least one of their own articles, sorted in ascending order by their id.

\n\n

The query result format is in the following example:

\n\n
\nViews table:\n+------------+-----------+-----------+------------+\n| article_id | author_id | viewer_id | view_date  |\n+------------+-----------+-----------+------------+\n| 1          | 3         | 5         | 2019-08-01 |\n| 1          | 3         | 6         | 2019-08-02 |\n| 2          | 7         | 7         | 2019-08-01 |\n| 2          | 7         | 6         | 2019-08-02 |\n| 4          | 7         | 1         | 2019-07-22 |\n| 3          | 4         | 4         | 2019-07-21 |\n| 3          | 4         | 4         | 2019-07-21 |\n+------------+-----------+-----------+------------+\n\nResult table:\n+------+\n| id   |\n+------+\n| 4    |\n| 7    |\n+------+\n
\n", "content_cn": "

Views \u8868\uff1a

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| article_id    | int     |\n| author_id     | int     |\n| viewer_id     | int     |\n| view_date     | date    |\n+---------------+---------+\n\u6b64\u8868\u65e0\u4e3b\u952e\uff0c\u56e0\u6b64\u53ef\u80fd\u4f1a\u5b58\u5728\u91cd\u590d\u884c\u3002\n\u6b64\u8868\u7684\u6bcf\u4e00\u884c\u90fd\u8868\u793a\u67d0\u4eba\u5728\u67d0\u5929\u6d4f\u89c8\u4e86\u67d0\u4f4d\u4f5c\u8005\u7684\u67d0\u7bc7\u6587\u7ae0\u3002\n\u8bf7\u6ce8\u610f\uff0c\u540c\u4e00\u4eba\u7684 author_id \u548c viewer_id \u662f\u76f8\u540c\u7684\u3002\n
\n\n

 

\n\n

\u8bf7\u7f16\u5199\u4e00\u6761 SQL \u67e5\u8be2\u4ee5\u627e\u51fa\u6240\u6709\u6d4f\u89c8\u8fc7\u81ea\u5df1\u6587\u7ae0\u7684\u4f5c\u8005\uff0c\u7ed3\u679c\u6309\u7167 id \u5347\u5e8f\u6392\u5217\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u7684\u683c\u5f0f\u5982\u4e0b\u6240\u793a\uff1a

\n\n
\nViews \u8868\uff1a\n+------------+-----------+-----------+------------+\n| article_id | author_id | viewer_id | view_date  |\n+------------+-----------+-----------+------------+\n| 1          | 3         | 5         | 2019-08-01 |\n| 1          | 3         | 6         | 2019-08-02 |\n| 2          | 7         | 7         | 2019-08-01 |\n| 2          | 7         | 6         | 2019-08-02 |\n| 4          | 7         | 1         | 2019-07-22 |\n| 3          | 4         | 4         | 2019-07-21 |\n| 3          | 4         | 4         | 2019-07-21 |\n+------------+-----------+-----------+------------+\n\n\u7ed3\u679c\u8868\uff1a\n+------+\n| id   |\n+------+\n| 4    |\n| 7    |\n+------+\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1148](https://leetcode-cn.com/problems/article-views-i)", "[\u6587\u7ae0\u6d4f\u89c8 I](/solution/1100-1199/1148.Article%20Views%20I/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1148](https://leetcode.com/problems/article-views-i)", "[Article Views I](/solution/1100-1199/1148.Article%20Views%20I/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1257", "frontend_question_id": "1632", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/rank-transform-of-a-matrix", "url_en": "https://leetcode.com/problems/rank-transform-of-a-matrix", "relative_path_cn": "/solution/1600-1699/1632.Rank%20Transform%20of%20a%20Matrix/README.md", "relative_path_en": "/solution/1600-1699/1632.Rank%20Transform%20of%20a%20Matrix/README_EN.md", "title_cn": "\u77e9\u9635\u8f6c\u6362\u540e\u7684\u79e9", "title_en": "Rank Transform of a Matrix", "question_title_slug": "rank-transform-of-a-matrix", "content_en": "

Given an m x n matrix, return a new matrix answer where answer[row][col] is the rank of matrix[row][col].

\n\n

The rank is an integer that represents how large an element is compared to other elements. It is calculated using the following rules:

\n\n
    \n\t
  • The rank is an integer starting from 1.
  • \n\t
  • If two elements p and q are in the same row or column, then:\n\t
      \n\t\t
    • If p < q then rank(p) < rank(q)
    • \n\t\t
    • If p == q then rank(p) == rank(q)
    • \n\t\t
    • If p > q then rank(p) > rank(q)
    • \n\t
    \n\t
  • \n\t
  • The rank should be as small as possible.
  • \n
\n\n

It is guaranteed that answer is unique under the given rules.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: matrix = [[1,2],[3,4]]\nOutput: [[1,2],[2,3]]\nExplanation:\nThe rank of matrix[0][0] is 1 because it is the smallest integer in its row and column.\nThe rank of matrix[0][1] is 2 because matrix[0][1] > matrix[0][0] and matrix[0][0] is rank 1.\nThe rank of matrix[1][0] is 2 because matrix[1][0] > matrix[0][0] and matrix[0][0] is rank 1.\nThe rank of matrix[1][1] is 3 because matrix[1][1] > matrix[0][1], matrix[1][1] > matrix[1][0], and both matrix[0][1] and matrix[1][0] are rank 2.\n
\n\n

Example 2:

\n\"\"\n
\nInput: matrix = [[7,7],[7,7]]\nOutput: [[1,1],[1,1]]\n
\n\n

Example 3:

\n\"\"\n
\nInput: matrix = [[20,-21,14],[-19,4,19],[22,-47,24],[-19,4,19]]\nOutput: [[4,2,3],[1,3,4],[5,1,6],[1,3,4]]\n
\n\n

Example 4:

\n\"\"\n
\nInput: matrix = [[7,3,6],[1,4,5],[9,8,2]]\nOutput: [[5,1,4],[1,2,3],[6,3,1]]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • m == matrix.length
  • \n\t
  • n == matrix[i].length
  • \n\t
  • 1 <= m, n <= 500
  • \n\t
  • -109 <= matrix[row][col] <= 109
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u00a0m x n\u00a0\u7684\u77e9\u9635 matrix\u00a0\uff0c\u8bf7\u4f60\u8fd4\u56de\u4e00\u4e2a\u65b0\u7684\u77e9\u9635\u00a0answer\u00a0\uff0c\u5176\u4e2d\u00a0answer[row][col]\u00a0\u662f\u00a0matrix[row][col]\u00a0\u7684\u79e9\u3002

\n\n

\u6bcf\u4e2a\u5143\u7d20\u7684\u00a0\u79e9\u00a0\u662f\u4e00\u4e2a\u6574\u6570\uff0c\u8868\u793a\u8fd9\u4e2a\u5143\u7d20\u76f8\u5bf9\u4e8e\u5176\u4ed6\u5143\u7d20\u7684\u5927\u5c0f\u5173\u7cfb\uff0c\u5b83\u6309\u7167\u5982\u4e0b\u89c4\u5219\u8ba1\u7b97\uff1a

\n\n
    \n\t
  • \u79e9\u662f\u4ece 1 \u5f00\u59cb\u7684\u4e00\u4e2a\u6574\u6570\u3002
  • \n\t
  • \u5982\u679c\u4e24\u4e2a\u5143\u7d20\u00a0p \u548c\u00a0q\u00a0\u5728 \u540c\u4e00\u884c\u00a0\u6216\u8005 \u540c\u4e00\u5217\u00a0\uff0c\u90a3\u4e48\uff1a\n\t
      \n\t\t
    • \u5982\u679c\u00a0p < q \uff0c\u90a3\u4e48\u00a0rank(p) < rank(q)
    • \n\t\t
    • \u5982\u679c\u00a0p == q\u00a0\uff0c\u90a3\u4e48\u00a0rank(p) == rank(q)
    • \n\t\t
    • \u5982\u679c\u00a0p > q\u00a0\uff0c\u90a3\u4e48\u00a0rank(p) > rank(q)
    • \n\t
    \n\t
  • \n\t
  • \u79e9\u00a0\u9700\u8981\u8d8a \u5c0f\u00a0\u8d8a\u597d\u3002
  • \n
\n\n

\u9898\u76ee\u4fdd\u8bc1\u6309\u7167\u4e0a\u9762\u89c4\u5219\u00a0answer\u00a0\u6570\u7ec4\u662f\u552f\u4e00\u7684\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1amatrix = [[1,2],[3,4]]\n\u8f93\u51fa\uff1a[[1,2],[2,3]]\n\u89e3\u91ca\uff1a\nmatrix[0][0] \u7684\u79e9\u4e3a 1 \uff0c\u56e0\u4e3a\u5b83\u662f\u6240\u5728\u884c\u548c\u5217\u7684\u6700\u5c0f\u6574\u6570\u3002\nmatrix[0][1] \u7684\u79e9\u4e3a 2 \uff0c\u56e0\u4e3a matrix[0][1] > matrix[0][0] \u4e14 matrix[0][0] \u7684\u79e9\u4e3a 1 \u3002\nmatrix[1][0] \u7684\u79e9\u4e3a 2 \uff0c\u56e0\u4e3a matrix[1][0] > matrix[0][0] \u4e14 matrix[0][0] \u7684\u79e9\u4e3a 1 \u3002\nmatrix[1][1] \u7684\u79e9\u4e3a 3 \uff0c\u56e0\u4e3a matrix[1][1] > matrix[0][1]\uff0c matrix[1][1] > matrix[1][0] \u4e14 matrix[0][1] \u548c matrix[1][0] \u7684\u79e9\u90fd\u4e3a 2 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1amatrix = [[7,7],[7,7]]\n\u8f93\u51fa\uff1a[[1,1],[1,1]]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1amatrix = [[20,-21,14],[-19,4,19],[22,-47,24],[-19,4,19]]\n\u8f93\u51fa\uff1a[[4,2,3],[1,3,4],[5,1,6],[1,3,4]]\n
\n\n

\u793a\u4f8b 4\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1amatrix = [[7,3,6],[1,4,5],[9,8,2]]\n\u8f93\u51fa\uff1a[[5,1,4],[1,2,3],[6,3,1]]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • m == matrix.length
  • \n\t
  • n == matrix[i].length
  • \n\t
  • 1 <= m, n <= 500
  • \n\t
  • -109 <= matrix[row][col] <= 109
  • \n
\n", "tags_en": ["Greedy", "Union Find"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u5e76\u67e5\u96c6"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> matrixRankTransform(vector>& matrix) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[][] matrixRankTransform(int[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def matrixRankTransform(self, matrix):\n \"\"\"\n :type matrix: List[List[int]]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def matrixRankTransform(self, matrix: List[List[int]]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** matrixRankTransform(int** matrix, int matrixSize, int* matrixColSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[][] MatrixRankTransform(int[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} matrix\n * @return {number[][]}\n */\nvar matrixRankTransform = function(matrix) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} matrix\n# @return {Integer[][]}\ndef matrix_rank_transform(matrix)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func matrixRankTransform(_ matrix: [[Int]]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func matrixRankTransform(matrix [][]int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def matrixRankTransform(matrix: Array[Array[Int]]): Array[Array[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun matrixRankTransform(matrix: Array): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn matrix_rank_transform(matrix: Vec>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $matrix\n * @return Integer[][]\n */\n function matrixRankTransform($matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function matrixRankTransform(matrix: number[][]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (matrix-rank-transform matrix)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1632](https://leetcode-cn.com/problems/rank-transform-of-a-matrix)", "[\u77e9\u9635\u8f6c\u6362\u540e\u7684\u79e9](/solution/1600-1699/1632.Rank%20Transform%20of%20a%20Matrix/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u5e76\u67e5\u96c6`", "\u56f0\u96be", ""], "md_table_row_en": ["[1632](https://leetcode.com/problems/rank-transform-of-a-matrix)", "[Rank Transform of a Matrix](/solution/1600-1699/1632.Rank%20Transform%20of%20a%20Matrix/README_EN.md)", "`Greedy`,`Union Find`", "Hard", ""]}, {"question_id": "1256", "frontend_question_id": "1331", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/rank-transform-of-an-array", "url_en": "https://leetcode.com/problems/rank-transform-of-an-array", "relative_path_cn": "/solution/1300-1399/1331.Rank%20Transform%20of%20an%20Array/README.md", "relative_path_en": "/solution/1300-1399/1331.Rank%20Transform%20of%20an%20Array/README_EN.md", "title_cn": "\u6570\u7ec4\u5e8f\u53f7\u8f6c\u6362", "title_en": "Rank Transform of an Array", "question_title_slug": "rank-transform-of-an-array", "content_en": "

Given an array of integers arr, replace each element with its rank.

\r\n\r\n

The rank represents how large the element is. The rank has the following rules:

\r\n\r\n
    \r\n\t
  • Rank is an integer starting from 1.
  • \r\n\t
  • The larger the element, the larger the rank. If two elements are equal, their rank must be the same.
  • \r\n\t
  • Rank should be as small as possible.
  • \r\n
\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: arr = [40,10,20,30]\r\nOutput: [4,1,2,3]\r\nExplanation: 40 is the largest element. 10 is the smallest. 20 is the second smallest. 30 is the third smallest.
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: arr = [100,100,100]\r\nOutput: [1,1,1]\r\nExplanation: Same elements share the same rank.\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: arr = [37,12,28,9,100,56,80,5,12]\r\nOutput: [5,3,4,2,8,6,7,1,3]\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 0 <= arr.length <= 105
  • \r\n\t
  • -109 <= arr[i] <= 109
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr \uff0c\u8bf7\u4f60\u5c06\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u66ff\u6362\u4e3a\u5b83\u4eec\u6392\u5e8f\u540e\u7684\u5e8f\u53f7\u3002

\n\n

\u5e8f\u53f7\u4ee3\u8868\u4e86\u4e00\u4e2a\u5143\u7d20\u6709\u591a\u5927\u3002\u5e8f\u53f7\u7f16\u53f7\u7684\u89c4\u5219\u5982\u4e0b\uff1a

\n\n
    \n\t
  • \u5e8f\u53f7\u4ece 1 \u5f00\u59cb\u7f16\u53f7\u3002
  • \n\t
  • \u4e00\u4e2a\u5143\u7d20\u8d8a\u5927\uff0c\u90a3\u4e48\u5e8f\u53f7\u8d8a\u5927\u3002\u5982\u679c\u4e24\u4e2a\u5143\u7d20\u76f8\u7b49\uff0c\u90a3\u4e48\u5b83\u4eec\u7684\u5e8f\u53f7\u76f8\u540c\u3002
  • \n\t
  • \u6bcf\u4e2a\u6570\u5b57\u7684\u5e8f\u53f7\u90fd\u5e94\u8be5\u5c3d\u53ef\u80fd\u5730\u5c0f\u3002
  • \n
\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aarr = [40,10,20,30]\n\u8f93\u51fa\uff1a[4,1,2,3]\n\u89e3\u91ca\uff1a40 \u662f\u6700\u5927\u7684\u5143\u7d20\u3002 10 \u662f\u6700\u5c0f\u7684\u5143\u7d20\u3002 20 \u662f\u7b2c\u4e8c\u5c0f\u7684\u6570\u5b57\u3002 30 \u662f\u7b2c\u4e09\u5c0f\u7684\u6570\u5b57\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aarr = [100,100,100]\n\u8f93\u51fa\uff1a[1,1,1]\n\u89e3\u91ca\uff1a\u6240\u6709\u5143\u7d20\u6709\u76f8\u540c\u7684\u5e8f\u53f7\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aarr = [37,12,28,9,100,56,80,5,12]\n\u8f93\u51fa\uff1a[5,3,4,2,8,6,7,1,3]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 0 <= arr.length <= 105
  • \n\t
  • -109 <= arr[i] <= 109
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector arrayRankTransform(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] arrayRankTransform(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def arrayRankTransform(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: List[int]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def arrayRankTransform(self, arr: List[int]) -> List[int]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* arrayRankTransform(int* arr, int arrSize, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] ArrayRankTransform(int[] arr) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number[]}\n */\nvar arrayRankTransform = function(arr) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer[]}\ndef array_rank_transform(arr)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func arrayRankTransform(_ arr: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func arrayRankTransform(arr []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def arrayRankTransform(arr: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun arrayRankTransform(arr: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn array_rank_transform(arr: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer[]\n */\n function arrayRankTransform($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function arrayRankTransform(arr: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (array-rank-transform arr)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1331](https://leetcode-cn.com/problems/rank-transform-of-an-array)", "[\u6570\u7ec4\u5e8f\u53f7\u8f6c\u6362](/solution/1300-1399/1331.Rank%20Transform%20of%20an%20Array/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1331](https://leetcode.com/problems/rank-transform-of-an-array)", "[Rank Transform of an Array](/solution/1300-1399/1331.Rank%20Transform%20of%20an%20Array/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1255", "frontend_question_id": "1330", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reverse-subarray-to-maximize-array-value", "url_en": "https://leetcode.com/problems/reverse-subarray-to-maximize-array-value", "relative_path_cn": "/solution/1300-1399/1330.Reverse%20Subarray%20To%20Maximize%20Array%20Value/README.md", "relative_path_en": "/solution/1300-1399/1330.Reverse%20Subarray%20To%20Maximize%20Array%20Value/README_EN.md", "title_cn": "\u7ffb\u8f6c\u5b50\u6570\u7ec4\u5f97\u5230\u6700\u5927\u7684\u6570\u7ec4\u503c", "title_en": "Reverse Subarray To Maximize Array Value", "question_title_slug": "reverse-subarray-to-maximize-array-value", "content_en": "

You are given an integer array nums. The value of this array is defined as the sum of |nums[i]-nums[i+1]| for all 0 <= i < nums.length-1.

\r\n\r\n

You are allowed to select any subarray of the given array and reverse it. You can perform this operation only once.

\r\n\r\n

Find maximum possible value of the final array.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: nums = [2,3,1,5,4]\r\nOutput: 10\r\nExplanation: By reversing the subarray [3,1,5] the array becomes [2,5,1,3,4] whose value is 10.\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: nums = [2,4,9,24,2,1,10]\r\nOutput: 68\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= nums.length <= 3*10^4
  • \r\n\t
  • -10^5 <= nums[i] <= 10^5
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \u3002\u300c\u6570\u7ec4\u503c\u300d\u5b9a\u4e49\u4e3a\u6240\u6709\u6ee1\u8db3 0 <= i < nums.length-1 \u7684 |nums[i]-nums[i+1]| \u7684\u548c\u3002

\n\n

\u4f60\u53ef\u4ee5\u9009\u62e9\u7ed9\u5b9a\u6570\u7ec4\u7684\u4efb\u610f\u5b50\u6570\u7ec4\uff0c\u5e76\u5c06\u8be5\u5b50\u6570\u7ec4\u7ffb\u8f6c\u3002\u4f46\u4f60\u53ea\u80fd\u6267\u884c\u8fd9\u4e2a\u64cd\u4f5c \u4e00\u6b21 \u3002

\n\n

\u8bf7\u4f60\u627e\u5230\u53ef\u884c\u7684\u6700\u5927 \u6570\u7ec4\u503c \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anums = [2,3,1,5,4]\n\u8f93\u51fa\uff1a10\n\u89e3\u91ca\uff1a\u901a\u8fc7\u7ffb\u8f6c\u5b50\u6570\u7ec4 [3,1,5] \uff0c\u6570\u7ec4\u53d8\u6210 [2,5,1,3,4] \uff0c\u6570\u7ec4\u503c\u4e3a 10 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anums = [2,4,9,24,2,1,10]\n\u8f93\u51fa\uff1a68\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 3*10^4
  • \n\t
  • -10^5 <= nums[i] <= 10^5
  • \n
\n", "tags_en": ["Array", "Math"], "tags_cn": ["\u6570\u7ec4", "\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxValueAfterReverse(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxValueAfterReverse(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxValueAfterReverse(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxValueAfterReverse(self, nums: List[int]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxValueAfterReverse(int* nums, int numsSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxValueAfterReverse(int[] nums) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar maxValueAfterReverse = function(nums) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef max_value_after_reverse(nums)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxValueAfterReverse(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxValueAfterReverse(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxValueAfterReverse(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxValueAfterReverse(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_value_after_reverse(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function maxValueAfterReverse($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxValueAfterReverse(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-value-after-reverse nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1330](https://leetcode-cn.com/problems/reverse-subarray-to-maximize-array-value)", "[\u7ffb\u8f6c\u5b50\u6570\u7ec4\u5f97\u5230\u6700\u5927\u7684\u6570\u7ec4\u503c](/solution/1300-1399/1330.Reverse%20Subarray%20To%20Maximize%20Array%20Value/README.md)", "`\u6570\u7ec4`,`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[1330](https://leetcode.com/problems/reverse-subarray-to-maximize-array-value)", "[Reverse Subarray To Maximize Array Value](/solution/1300-1399/1330.Reverse%20Subarray%20To%20Maximize%20Array%20Value/README_EN.md)", "`Array`,`Math`", "Hard", ""]}, {"question_id": "1254", "frontend_question_id": "1302", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/deepest-leaves-sum", "url_en": "https://leetcode.com/problems/deepest-leaves-sum", "relative_path_cn": "/solution/1300-1399/1302.Deepest%20Leaves%20Sum/README.md", "relative_path_en": "/solution/1300-1399/1302.Deepest%20Leaves%20Sum/README_EN.md", "title_cn": "\u5c42\u6570\u6700\u6df1\u53f6\u5b50\u8282\u70b9\u7684\u548c", "title_en": "Deepest Leaves Sum", "question_title_slug": "deepest-leaves-sum", "content_en": "Given the root of a binary tree, return the sum of values of its deepest leaves.\n

 

\n

Example 1:

\n\"\"\n
\nInput: root = [1,2,3,4,5,null,6,7,null,null,null,null,8]\nOutput: 15\n
\n\n

Example 2:

\n\n
\nInput: root = [6,7,8,2,7,1,3,9,null,1,4,null,null,null,5]\nOutput: 19\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The number of nodes in the tree is in the range [1, 104].
  • \n\t
  • 1 <= Node.val <= 100
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u68f5\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9 root \uff0c\u8bf7\u4f60\u8fd4\u56de \u5c42\u6570\u6700\u6df1\u7684\u53f6\u5b50\u8282\u70b9\u7684\u548c \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1aroot = [1,2,3,4,5,null,6,7,null,null,null,null,8]\n\u8f93\u51fa\uff1a15\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aroot = [6,7,8,2,7,1,3,9,null,1,4,null,null,null,5]\n\u8f93\u51fa\uff1a19\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u6811\u4e2d\u8282\u70b9\u6570\u76ee\u5728\u8303\u56f4 [1, 104]\u00a0\u4e4b\u95f4\u3002
  • \n\t
  • 1 <= Node.val <= 100
  • \n
\n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int deepestLeavesSum(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int deepestLeavesSum(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def deepestLeavesSum(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def deepestLeavesSum(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint deepestLeavesSum(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int DeepestLeavesSum(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar deepestLeavesSum = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef deepest_leaves_sum(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func deepestLeavesSum(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc deepestLeavesSum(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def deepestLeavesSum(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun deepestLeavesSum(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn deepest_leaves_sum(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function deepestLeavesSum($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction deepestLeavesSum(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (deepest-leaves-sum root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1302](https://leetcode-cn.com/problems/deepest-leaves-sum)", "[\u5c42\u6570\u6700\u6df1\u53f6\u5b50\u8282\u70b9\u7684\u548c](/solution/1300-1399/1302.Deepest%20Leaves%20Sum/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1302](https://leetcode.com/problems/deepest-leaves-sum)", "[Deepest Leaves Sum](/solution/1300-1399/1302.Deepest%20Leaves%20Sum/README_EN.md)", "`Tree`,`Depth-first Search`", "Medium", ""]}, {"question_id": "1253", "frontend_question_id": "1329", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sort-the-matrix-diagonally", "url_en": "https://leetcode.com/problems/sort-the-matrix-diagonally", "relative_path_cn": "/solution/1300-1399/1329.Sort%20the%20Matrix%20Diagonally/README.md", "relative_path_en": "/solution/1300-1399/1329.Sort%20the%20Matrix%20Diagonally/README_EN.md", "title_cn": "\u5c06\u77e9\u9635\u6309\u5bf9\u89d2\u7ebf\u6392\u5e8f", "title_en": "Sort the Matrix Diagonally", "question_title_slug": "sort-the-matrix-diagonally", "content_en": "

A matrix diagonal is a diagonal line of cells starting from some cell in either the topmost row or leftmost column and going in the bottom-right direction until reaching the matrix's end. For example, the matrix diagonal starting from mat[2][0], where mat is a 6 x 3 matrix, includes cells mat[2][0], mat[3][1], and mat[4][2].

\n\n

Given an m x n matrix mat of integers, sort each matrix diagonal in ascending order and return the resulting matrix.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: mat = [[3,3,1,1],[2,2,1,2],[1,1,1,2]]\nOutput: [[1,1,1,1],[1,2,2,2],[1,2,3,3]]\n
\n\n

Example 2:

\n\n
\nInput: mat = [[11,25,66,1,69,7],[23,55,17,45,15,52],[75,31,36,44,58,8],[22,27,33,25,68,4],[84,28,14,11,5,50]]\nOutput: [[5,17,4,1,52,7],[11,11,25,45,8,69],[14,23,25,44,58,15],[22,27,31,36,50,66],[84,28,75,33,55,68]]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • m == mat.length
  • \n\t
  • n == mat[i].length
  • \n\t
  • 1 <= m, n <= 100
  • \n\t
  • 1 <= mat[i][j] <= 100
  • \n
\n", "content_cn": "

\u77e9\u9635\u5bf9\u89d2\u7ebf \u662f\u4e00\u6761\u4ece\u77e9\u9635\u6700\u4e0a\u9762\u884c\u6216\u8005\u6700\u5de6\u4fa7\u5217\u4e2d\u7684\u67d0\u4e2a\u5143\u7d20\u5f00\u59cb\u7684\u5bf9\u89d2\u7ebf\uff0c\u6cbf\u53f3\u4e0b\u65b9\u5411\u4e00\u76f4\u5230\u77e9\u9635\u672b\u5c3e\u7684\u5143\u7d20\u3002\u4f8b\u5982\uff0c\u77e9\u9635 mat \u6709 6 \u884c 3 \u5217\uff0c\u4ece mat[2][0] \u5f00\u59cb\u7684 \u77e9\u9635\u5bf9\u89d2\u7ebf \u5c06\u4f1a\u7ecf\u8fc7 mat[2][0]\u3001mat[3][1] \u548c mat[4][2] \u3002

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u00a0m * n\u00a0\u7684\u6574\u6570\u77e9\u9635\u00a0mat\u00a0\uff0c\u8bf7\u4f60\u5c06\u540c\u4e00\u6761 \u77e9\u9635\u5bf9\u89d2\u7ebf \u4e0a\u7684\u5143\u7d20\u6309\u5347\u5e8f\u6392\u5e8f\u540e\uff0c\u8fd4\u56de\u6392\u597d\u5e8f\u7684\u77e9\u9635\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1amat = [[3,3,1,1],[2,2,1,2],[1,1,1,2]]\n\u8f93\u51fa\uff1a[[1,1,1,1],[1,2,2,2],[1,2,3,3]]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1amat = [[11,25,66,1,69,7],[23,55,17,45,15,52],[75,31,36,44,58,8],[22,27,33,25,68,4],[84,28,14,11,5,50]]\n\u8f93\u51fa\uff1a[[5,17,4,1,52,7],[11,11,25,45,8,69],[14,23,25,44,58,15],[22,27,31,36,50,66],[84,28,75,33,55,68]]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • m ==\u00a0mat.length
  • \n\t
  • n ==\u00a0mat[i].length
  • \n\t
  • 1 <= m, n\u00a0<= 100
  • \n\t
  • 1 <= mat[i][j] <= 100
  • \n
\n", "tags_en": ["Sort", "Array"], "tags_cn": ["\u6392\u5e8f", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> diagonalSort(vector>& mat) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[][] diagonalSort(int[][] mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def diagonalSort(self, mat):\n \"\"\"\n :type mat: List[List[int]]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def diagonalSort(self, mat: List[List[int]]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** diagonalSort(int** mat, int matSize, int* matColSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[][] DiagonalSort(int[][] mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} mat\n * @return {number[][]}\n */\nvar diagonalSort = function(mat) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} mat\n# @return {Integer[][]}\ndef diagonal_sort(mat)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func diagonalSort(_ mat: [[Int]]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func diagonalSort(mat [][]int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def diagonalSort(mat: Array[Array[Int]]): Array[Array[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun diagonalSort(mat: Array): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn diagonal_sort(mat: Vec>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $mat\n * @return Integer[][]\n */\n function diagonalSort($mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function diagonalSort(mat: number[][]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (diagonal-sort mat)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1329](https://leetcode-cn.com/problems/sort-the-matrix-diagonally)", "[\u5c06\u77e9\u9635\u6309\u5bf9\u89d2\u7ebf\u6392\u5e8f](/solution/1300-1399/1329.Sort%20the%20Matrix%20Diagonally/README.md)", "`\u6392\u5e8f`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1329](https://leetcode.com/problems/sort-the-matrix-diagonally)", "[Sort the Matrix Diagonally](/solution/1300-1399/1329.Sort%20the%20Matrix%20Diagonally/README_EN.md)", "`Sort`,`Array`", "Medium", ""]}, {"question_id": "1252", "frontend_question_id": "1328", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/break-a-palindrome", "url_en": "https://leetcode.com/problems/break-a-palindrome", "relative_path_cn": "/solution/1300-1399/1328.Break%20a%20Palindrome/README.md", "relative_path_en": "/solution/1300-1399/1328.Break%20a%20Palindrome/README_EN.md", "title_cn": "\u7834\u574f\u56de\u6587\u4e32", "title_en": "Break a Palindrome", "question_title_slug": "break-a-palindrome", "content_en": "

Given a palindromic string of lowercase English letters palindrome, replace exactly one character with any lowercase English letter so that the resulting string is not a palindrome and that it is the lexicographically smallest one possible.

\n\n

Return the resulting string. If there is no way to replace a character to make it not a palindrome, return an empty string.

\n\n

A string a is lexicographically smaller than a string b (of the same length) if in the first position where a and b differ, a has a character strictly smaller than the corresponding character in b. For example, "abcc" is lexicographically smaller than "abcd" because the first position they differ is at the fourth character, and 'c' is smaller than 'd'.

\n\n

 

\n

Example 1:

\n\n
\nInput: palindrome = "abccba"\nOutput: "aaccba"\nExplanation: There are many ways to make "abccba" not a palindrome, such as "zbccba", "aaccba", and "abacba".\nOf all the ways, "aaccba" is the lexicographically smallest.\n
\n\n

Example 2:

\n\n
\nInput: palindrome = "a"\nOutput: ""\nExplanation: There is no way to replace a single character to make "a" not a palindrome, so return an empty string.\n
\n\n

Example 3:

\n\n
\nInput: palindrome = "aa"\nOutput: "ab"
\n\n

Example 4:

\n\n
\nInput: palindrome = "aba"\nOutput: "abb"\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= palindrome.length <= 1000
  • \n\t
  • palindrome consists of only lowercase English letters.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u56de\u6587\u5b57\u7b26\u4e32 palindrome \uff0c\u8bf7\u4f60\u5c06\u5176\u4e2d \u4e00\u4e2a \u5b57\u7b26\u7528\u4efb\u610f\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u66ff\u6362\uff0c\u4f7f\u5f97\u7ed3\u679c\u5b57\u7b26\u4e32\u7684\u5b57\u5178\u5e8f\u6700\u5c0f\uff0c\u4e14 \u4e0d\u662f \u56de\u6587\u4e32\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u7ed3\u679c\u5b57\u7b26\u4e32\u3002\u5982\u679c\u65e0\u6cd5\u505a\u5230\uff0c\u5219\u8fd4\u56de\u4e00\u4e2a\u7a7a\u4e32\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1apalindrome = "abccba"\n\u8f93\u51fa\uff1a"aaccba"\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1apalindrome = "a"\n\u8f93\u51fa\uff1a""\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= palindrome.length <= 1000
  • \n\t
  • palindrome \u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string breakPalindrome(string palindrome) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String breakPalindrome(String palindrome) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def breakPalindrome(self, palindrome):\n \"\"\"\n :type palindrome: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def breakPalindrome(self, palindrome: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * breakPalindrome(char * palindrome){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string BreakPalindrome(string palindrome) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} palindrome\n * @return {string}\n */\nvar breakPalindrome = function(palindrome) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} palindrome\n# @return {String}\ndef break_palindrome(palindrome)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func breakPalindrome(_ palindrome: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func breakPalindrome(palindrome string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def breakPalindrome(palindrome: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun breakPalindrome(palindrome: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn break_palindrome(palindrome: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $palindrome\n * @return String\n */\n function breakPalindrome($palindrome) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function breakPalindrome(palindrome: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (break-palindrome palindrome)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1328](https://leetcode-cn.com/problems/break-a-palindrome)", "[\u7834\u574f\u56de\u6587\u4e32](/solution/1300-1399/1328.Break%20a%20Palindrome/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1328](https://leetcode.com/problems/break-a-palindrome)", "[Break a Palindrome](/solution/1300-1399/1328.Break%20a%20Palindrome/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "1251", "frontend_question_id": "1147", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-chunked-palindrome-decomposition", "url_en": "https://leetcode.com/problems/longest-chunked-palindrome-decomposition", "relative_path_cn": "/solution/1100-1199/1147.Longest%20Chunked%20Palindrome%20Decomposition/README.md", "relative_path_en": "/solution/1100-1199/1147.Longest%20Chunked%20Palindrome%20Decomposition/README_EN.md", "title_cn": "\u6bb5\u5f0f\u56de\u6587", "title_en": "Longest Chunked Palindrome Decomposition", "question_title_slug": "longest-chunked-palindrome-decomposition", "content_en": "

You are given a string text. You should split it to k substrings (subtext1, subtext2, ..., subtextk) such that:

\n\n
    \n\t
  • subtexti is a non-empty string.
  • \n\t
  • The concatenation of all the substrings is equal to text (i.e., subtext1 + subtext2 + ... + subtextk == text).
  • \n\t
  • subtexti == subtextk - i + 1 for all valid values of i (i.e., 1 <= i <= k).
  • \n
\n\n

Return the largest possible value of k.

\n\n

 

\n

Example 1:

\n\n
\nInput: text = "ghiabcdefhelloadamhelloabcdefghi"\nOutput: 7\nExplanation: We can split the string on "(ghi)(abcdef)(hello)(adam)(hello)(abcdef)(ghi)".\n
\n\n

Example 2:

\n\n
\nInput: text = "merchant"\nOutput: 1\nExplanation: We can split the string on "(merchant)".\n
\n\n

Example 3:

\n\n
\nInput: text = "antaprezatepzapreanta"\nOutput: 11\nExplanation: We can split the string on "(a)(nt)(a)(pre)(za)(tpe)(za)(pre)(a)(nt)(a)".\n
\n\n

Example 4:

\n\n
\nInput: text = "aaa"\nOutput: 3\nExplanation: We can split the string on "(a)(a)(a)".\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= text.length <= 1000
  • \n\t
  • text consists only of lowercase English characters.
  • \n
\n", "content_cn": "

\u6bb5\u5f0f\u56de\u6587 \u5176\u5b9e\u4e0e \u4e00\u822c\u56de\u6587 \u7c7b\u4f3c\uff0c\u53ea\u4e0d\u8fc7\u662f\u6700\u5c0f\u7684\u5355\u4f4d\u662f \u4e00\u6bb5\u5b57\u7b26 \u800c\u4e0d\u662f \u5355\u4e2a\u5b57\u6bcd\u3002

\n\n

\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u5bf9\u4e8e\u4e00\u822c\u56de\u6587 "abcba" \u662f\u56de\u6587\uff0c\u800c "volvo" \u4e0d\u662f\uff0c\u4f46\u5982\u679c\u6211\u4eec\u628a "volvo" \u5206\u4e3a "vo"\u3001"l"\u3001"vo" \u4e09\u6bb5\uff0c\u5219\u53ef\u4ee5\u8ba4\u4e3a “(vo)(l)(vo)” \u662f\u6bb5\u5f0f\u56de\u6587\uff08\u5206\u4e3a 3 \u6bb5\uff09\u3002

\n\n

 

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 text\uff0c\u5728\u786e\u4fdd\u5b83\u6ee1\u8db3\u6bb5\u5f0f\u56de\u6587\u7684\u524d\u63d0\u4e0b\uff0c\u8bf7\u4f60\u8fd4\u56de \u6bb5 \u7684 \u6700\u5927\u6570\u91cf k\u3002

\n\n

\u5982\u679c\u6bb5\u7684\u6700\u5927\u6570\u91cf\u4e3a k\uff0c\u90a3\u4e48\u5b58\u5728\u6ee1\u8db3\u4ee5\u4e0b\u6761\u4ef6\u7684 a_1, a_2, ..., a_k\uff1a

\n\n
    \n\t
  • \u6bcf\u4e2a a_i \u90fd\u662f\u4e00\u4e2a\u975e\u7a7a\u5b57\u7b26\u4e32\uff1b
  • \n\t
  • \u5c06\u8fd9\u4e9b\u5b57\u7b26\u4e32\u9996\u4f4d\u76f8\u8fde\u7684\u7ed3\u679c a_1 + a_2 + ... + a_k \u548c\u539f\u59cb\u5b57\u7b26\u4e32 text \u76f8\u540c\uff1b
  • \n\t
  • \u5bf9\u4e8e\u6240\u67091 <= i <= k\uff0c\u90fd\u6709 a_i = a_{k+1 - i}\u3002
  • \n
\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1atext = "ghiabcdefhelloadamhelloabcdefghi"\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\u6211\u4eec\u53ef\u4ee5\u628a\u5b57\u7b26\u4e32\u62c6\u5206\u6210 "(ghi)(abcdef)(hello)(adam)(hello)(abcdef)(ghi)"\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1atext = "merchant"\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u6211\u4eec\u53ef\u4ee5\u628a\u5b57\u7b26\u4e32\u62c6\u5206\u6210 "(merchant)"\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1atext = "antaprezatepzapreanta"\n\u8f93\u51fa\uff1a11\n\u89e3\u91ca\uff1a\u6211\u4eec\u53ef\u4ee5\u628a\u5b57\u7b26\u4e32\u62c6\u5206\u6210 "(a)(nt)(a)(pre)(za)(tpe)(za)(pre)(a)(nt)(a)"\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1atext = "aaa"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6211\u4eec\u53ef\u4ee5\u628a\u5b57\u7b26\u4e32\u62c6\u5206\u6210 "(a)(a)(a)"\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • text \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u7b26\u7ec4\u6210\u3002
  • \n\t
  • 1 <= text.length <= 1000
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int longestDecomposition(string text) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int longestDecomposition(String text) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestDecomposition(self, text):\n \"\"\"\n :type text: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestDecomposition(self, text: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint longestDecomposition(char * text){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LongestDecomposition(string text) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} text\n * @return {number}\n */\nvar longestDecomposition = function(text) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} text\n# @return {Integer}\ndef longest_decomposition(text)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestDecomposition(_ text: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestDecomposition(text string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestDecomposition(text: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestDecomposition(text: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_decomposition(text: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $text\n * @return Integer\n */\n function longestDecomposition($text) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestDecomposition(text: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-decomposition text)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1147](https://leetcode-cn.com/problems/longest-chunked-palindrome-decomposition)", "[\u6bb5\u5f0f\u56de\u6587](/solution/1100-1199/1147.Longest%20Chunked%20Palindrome%20Decomposition/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1147](https://leetcode.com/problems/longest-chunked-palindrome-decomposition)", "[Longest Chunked Palindrome Decomposition](/solution/1100-1199/1147.Longest%20Chunked%20Palindrome%20Decomposition/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1250", "frontend_question_id": "1143", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-common-subsequence", "url_en": "https://leetcode.com/problems/longest-common-subsequence", "relative_path_cn": "/solution/1100-1199/1143.Longest%20Common%20Subsequence/README.md", "relative_path_en": "/solution/1100-1199/1143.Longest%20Common%20Subsequence/README_EN.md", "title_cn": "\u6700\u957f\u516c\u5171\u5b50\u5e8f\u5217", "title_en": "Longest Common Subsequence", "question_title_slug": "longest-common-subsequence", "content_en": "

Given two strings text1 and text2, return the length of their longest common subsequence. If there is no common subsequence, return 0.

\n\n

A subsequence of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters.

\n\n
    \n\t
  • For example, "ace" is a subsequence of "abcde".
  • \n
\n\n

A common subsequence of two strings is a subsequence that is common to both strings.

\n\n

 

\n

Example 1:

\n\n
\nInput: text1 = "abcde", text2 = "ace" \nOutput: 3  \nExplanation: The longest common subsequence is "ace" and its length is 3.\n
\n\n

Example 2:

\n\n
\nInput: text1 = "abc", text2 = "abc"\nOutput: 3\nExplanation: The longest common subsequence is "abc" and its length is 3.\n
\n\n

Example 3:

\n\n
\nInput: text1 = "abc", text2 = "def"\nOutput: 0\nExplanation: There is no such common subsequence, so the result is 0.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= text1.length, text2.length <= 1000
  • \n\t
  • text1 and text2 consist of only lowercase English characters.
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e24\u4e2a\u5b57\u7b26\u4e32\u00a0text1 \u548c\u00a0text2\uff0c\u8fd4\u56de\u8fd9\u4e24\u4e2a\u5b57\u7b26\u4e32\u7684\u6700\u957f \u516c\u5171\u5b50\u5e8f\u5217 \u7684\u957f\u5ea6\u3002\u5982\u679c\u4e0d\u5b58\u5728 \u516c\u5171\u5b50\u5e8f\u5217 \uff0c\u8fd4\u56de 0 \u3002

\n\n

\u4e00\u4e2a\u5b57\u7b26\u4e32\u7684\u00a0\u5b50\u5e8f\u5217\u00a0\u662f\u6307\u8fd9\u6837\u4e00\u4e2a\u65b0\u7684\u5b57\u7b26\u4e32\uff1a\u5b83\u662f\u7531\u539f\u5b57\u7b26\u4e32\u5728\u4e0d\u6539\u53d8\u5b57\u7b26\u7684\u76f8\u5bf9\u987a\u5e8f\u7684\u60c5\u51b5\u4e0b\u5220\u9664\u67d0\u4e9b\u5b57\u7b26\uff08\u4e5f\u53ef\u4ee5\u4e0d\u5220\u9664\u4efb\u4f55\u5b57\u7b26\uff09\u540e\u7ec4\u6210\u7684\u65b0\u5b57\u7b26\u4e32\u3002

\n\n
    \n\t
  • \u4f8b\u5982\uff0c\"ace\" \u662f \"abcde\" \u7684\u5b50\u5e8f\u5217\uff0c\u4f46 \"aec\" \u4e0d\u662f \"abcde\" \u7684\u5b50\u5e8f\u5217\u3002
  • \n
\n\n

\u4e24\u4e2a\u5b57\u7b26\u4e32\u7684 \u516c\u5171\u5b50\u5e8f\u5217 \u662f\u8fd9\u4e24\u4e2a\u5b57\u7b26\u4e32\u6240\u5171\u540c\u62e5\u6709\u7684\u5b50\u5e8f\u5217\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1atext1 = \"abcde\", text2 = \"ace\" \n\u8f93\u51fa\uff1a3  \n\u89e3\u91ca\uff1a\u6700\u957f\u516c\u5171\u5b50\u5e8f\u5217\u662f \"ace\" \uff0c\u5b83\u7684\u957f\u5ea6\u4e3a 3 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1atext1 = \"abc\", text2 = \"abc\"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6700\u957f\u516c\u5171\u5b50\u5e8f\u5217\u662f \"abc\" \uff0c\u5b83\u7684\u957f\u5ea6\u4e3a 3 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1atext1 = \"abc\", text2 = \"def\"\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u4e24\u4e2a\u5b57\u7b26\u4e32\u6ca1\u6709\u516c\u5171\u5b50\u5e8f\u5217\uff0c\u8fd4\u56de 0 \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= text1.length, text2.length <= 1000
  • \n\t
  • text1 \u548c\u00a0text2 \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u7b26\u7ec4\u6210\u3002
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int longestCommonSubsequence(string text1, string text2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int longestCommonSubsequence(String text1, String text2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestCommonSubsequence(self, text1, text2):\n \"\"\"\n :type text1: str\n :type text2: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestCommonSubsequence(self, text1: str, text2: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint longestCommonSubsequence(char * text1, char * text2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LongestCommonSubsequence(string text1, string text2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} text1\n * @param {string} text2\n * @return {number}\n */\nvar longestCommonSubsequence = function(text1, text2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} text1\n# @param {String} text2\n# @return {Integer}\ndef longest_common_subsequence(text1, text2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestCommonSubsequence(_ text1: String, _ text2: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestCommonSubsequence(text1 string, text2 string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestCommonSubsequence(text1: String, text2: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestCommonSubsequence(text1: String, text2: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_common_subsequence(text1: String, text2: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $text1\n * @param String $text2\n * @return Integer\n */\n function longestCommonSubsequence($text1, $text2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestCommonSubsequence(text1: string, text2: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-common-subsequence text1 text2)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1143](https://leetcode-cn.com/problems/longest-common-subsequence)", "[\u6700\u957f\u516c\u5171\u5b50\u5e8f\u5217](/solution/1100-1199/1143.Longest%20Common%20Subsequence/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1143](https://leetcode.com/problems/longest-common-subsequence)", "[Longest Common Subsequence](/solution/1100-1199/1143.Longest%20Common%20Subsequence/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "1249", "frontend_question_id": "1146", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/snapshot-array", "url_en": "https://leetcode.com/problems/snapshot-array", "relative_path_cn": "/solution/1100-1199/1146.Snapshot%20Array/README.md", "relative_path_en": "/solution/1100-1199/1146.Snapshot%20Array/README_EN.md", "title_cn": "\u5feb\u7167\u6570\u7ec4", "title_en": "Snapshot Array", "question_title_slug": "snapshot-array", "content_en": "

Implement a SnapshotArray that supports the following interface:

\n\n
    \n\t
  • SnapshotArray(int length) initializes an array-like data structure with the given length.  Initially, each element equals 0.
  • \n\t
  • void set(index, val) sets the element at the given index to be equal to val.
  • \n\t
  • int snap() takes a snapshot of the array and returns the snap_id: the total number of times we called snap() minus 1.
  • \n\t
  • int get(index, snap_id) returns the value at the given index, at the time we took the snapshot with the given snap_id
  • \n
\n\n

 

\n

Example 1:

\n\n
\nInput: ["SnapshotArray","set","snap","set","get"]\n[[3],[0,5],[],[0,6],[0,0]]\nOutput: [null,null,0,null,5]\nExplanation: \nSnapshotArray snapshotArr = new SnapshotArray(3); // set the length to be 3\nsnapshotArr.set(0,5);  // Set array[0] = 5\nsnapshotArr.snap();  // Take a snapshot, return snap_id = 0\nsnapshotArr.set(0,6);\nsnapshotArr.get(0,0);  // Get the value of array[0] with snap_id = 0, return 5
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= length <= 50000
  • \n\t
  • At most 50000 calls will be made to set, snap, and get.
  • \n\t
  • 0 <= index < length
  • \n\t
  • 0 <= snap_id < (the total number of times we call snap())
  • \n\t
  • 0 <= val <= 10^9
  • \n
\n", "content_cn": "

\u5b9e\u73b0\u652f\u6301\u4e0b\u5217\u63a5\u53e3\u7684\u300c\u5feb\u7167\u6570\u7ec4\u300d- SnapshotArray\uff1a

\n\n
    \n\t
  • SnapshotArray(int length) - \u521d\u59cb\u5316\u4e00\u4e2a\u4e0e\u6307\u5b9a\u957f\u5ea6\u76f8\u7b49\u7684 \u7c7b\u6570\u7ec4 \u7684\u6570\u636e\u7ed3\u6784\u3002\u521d\u59cb\u65f6\uff0c\u6bcf\u4e2a\u5143\u7d20\u90fd\u7b49\u4e8e 0\u3002
  • \n\t
  • void set(index, val) - \u4f1a\u5c06\u6307\u5b9a\u7d22\u5f15 index \u5904\u7684\u5143\u7d20\u8bbe\u7f6e\u4e3a val\u3002
  • \n\t
  • int snap() - \u83b7\u53d6\u8be5\u6570\u7ec4\u7684\u5feb\u7167\uff0c\u5e76\u8fd4\u56de\u5feb\u7167\u7684\u7f16\u53f7 snap_id\uff08\u5feb\u7167\u53f7\u662f\u8c03\u7528 snap() \u7684\u603b\u6b21\u6570\u51cf\u53bb 1\uff09\u3002
  • \n\t
  • int get(index, snap_id) - \u6839\u636e\u6307\u5b9a\u7684 snap_id \u9009\u62e9\u5feb\u7167\uff0c\u5e76\u8fd4\u56de\u8be5\u5feb\u7167\u6307\u5b9a\u7d22\u5f15 index \u7684\u503c\u3002
  • \n
\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1a["SnapshotArray","set","snap","set","get"]\n     [[3],[0,5],[],[0,6],[0,0]]\n\u8f93\u51fa\uff1a[null,null,0,null,5]\n\u89e3\u91ca\uff1a\nSnapshotArray snapshotArr = new SnapshotArray(3); // \u521d\u59cb\u5316\u4e00\u4e2a\u957f\u5ea6\u4e3a 3 \u7684\u5feb\u7167\u6570\u7ec4\nsnapshotArr.set(0,5);  // \u4ee4 array[0] = 5\nsnapshotArr.snap();  // \u83b7\u53d6\u5feb\u7167\uff0c\u8fd4\u56de snap_id = 0\nsnapshotArr.set(0,6);\nsnapshotArr.get(0,0);  // \u83b7\u53d6 snap_id = 0 \u7684\u5feb\u7167\u4e2d array[0] \u7684\u503c\uff0c\u8fd4\u56de 5
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= length <= 50000
  • \n\t
  • \u9898\u76ee\u6700\u591a\u8fdb\u884c50000 \u6b21set\uff0csnap\uff0c\u548c get\u7684\u8c03\u7528 \u3002
  • \n\t
  • 0 <= index < length
  • \n\t
  • 0 <= snap_id < \u6211\u4eec\u8c03\u7528 snap() \u7684\u603b\u6b21\u6570
  • \n\t
  • 0 <= val <= 10^9
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class SnapshotArray {\npublic:\n SnapshotArray(int length) {\n\n }\n \n void set(int index, int val) {\n\n }\n \n int snap() {\n\n }\n \n int get(int index, int snap_id) {\n\n }\n};\n\n/**\n * Your SnapshotArray object will be instantiated and called as such:\n * SnapshotArray* obj = new SnapshotArray(length);\n * obj->set(index,val);\n * int param_2 = obj->snap();\n * int param_3 = obj->get(index,snap_id);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class SnapshotArray {\n\n public SnapshotArray(int length) {\n\n }\n \n public void set(int index, int val) {\n\n }\n \n public int snap() {\n\n }\n \n public int get(int index, int snap_id) {\n\n }\n}\n\n/**\n * Your SnapshotArray object will be instantiated and called as such:\n * SnapshotArray obj = new SnapshotArray(length);\n * obj.set(index,val);\n * int param_2 = obj.snap();\n * int param_3 = obj.get(index,snap_id);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class SnapshotArray(object):\n\n def __init__(self, length):\n \"\"\"\n :type length: int\n \"\"\"\n\n\n def set(self, index, val):\n \"\"\"\n :type index: int\n :type val: int\n :rtype: None\n \"\"\"\n\n\n def snap(self):\n \"\"\"\n :rtype: int\n \"\"\"\n\n\n def get(self, index, snap_id):\n \"\"\"\n :type index: int\n :type snap_id: int\n :rtype: int\n \"\"\"\n\n\n\n# Your SnapshotArray object will be instantiated and called as such:\n# obj = SnapshotArray(length)\n# obj.set(index,val)\n# param_2 = obj.snap()\n# param_3 = obj.get(index,snap_id)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class SnapshotArray:\n\n def __init__(self, length: int):\n\n\n def set(self, index: int, val: int) -> None:\n\n\n def snap(self) -> int:\n\n\n def get(self, index: int, snap_id: int) -> int:\n\n\n\n# Your SnapshotArray object will be instantiated and called as such:\n# obj = SnapshotArray(length)\n# obj.set(index,val)\n# param_2 = obj.snap()\n# param_3 = obj.get(index,snap_id)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} SnapshotArray;\n\n\nSnapshotArray* snapshotArrayCreate(int length) {\n\n}\n\nvoid snapshotArraySet(SnapshotArray* obj, int index, int val) {\n\n}\n\nint snapshotArraySnap(SnapshotArray* obj) {\n\n}\n\nint snapshotArrayGet(SnapshotArray* obj, int index, int snap_id) {\n\n}\n\nvoid snapshotArrayFree(SnapshotArray* obj) {\n\n}\n\n/**\n * Your SnapshotArray struct will be instantiated and called as such:\n * SnapshotArray* obj = snapshotArrayCreate(length);\n * snapshotArraySet(obj, index, val);\n \n * int param_2 = snapshotArraySnap(obj);\n \n * int param_3 = snapshotArrayGet(obj, index, snap_id);\n \n * snapshotArrayFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class SnapshotArray {\n\n public SnapshotArray(int length) {\n\n }\n \n public void Set(int index, int val) {\n\n }\n \n public int Snap() {\n\n }\n \n public int Get(int index, int snap_id) {\n\n }\n}\n\n/**\n * Your SnapshotArray object will be instantiated and called as such:\n * SnapshotArray obj = new SnapshotArray(length);\n * obj.Set(index,val);\n * int param_2 = obj.Snap();\n * int param_3 = obj.Get(index,snap_id);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} length\n */\nvar SnapshotArray = function(length) {\n\n};\n\n/** \n * @param {number} index \n * @param {number} val\n * @return {void}\n */\nSnapshotArray.prototype.set = function(index, val) {\n\n};\n\n/**\n * @return {number}\n */\nSnapshotArray.prototype.snap = function() {\n\n};\n\n/** \n * @param {number} index \n * @param {number} snap_id\n * @return {number}\n */\nSnapshotArray.prototype.get = function(index, snap_id) {\n\n};\n\n/**\n * Your SnapshotArray object will be instantiated and called as such:\n * var obj = new SnapshotArray(length)\n * obj.set(index,val)\n * var param_2 = obj.snap()\n * var param_3 = obj.get(index,snap_id)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class SnapshotArray\n\n=begin\n :type length: Integer\n=end\n def initialize(length)\n\n end\n\n\n=begin\n :type index: Integer\n :type val: Integer\n :rtype: Void\n=end\n def set(index, val)\n\n end\n\n\n=begin\n :rtype: Integer\n=end\n def snap()\n\n end\n\n\n=begin\n :type index: Integer\n :type snap_id: Integer\n :rtype: Integer\n=end\n def get(index, snap_id)\n\n end\n\n\nend\n\n# Your SnapshotArray object will be instantiated and called as such:\n# obj = SnapshotArray.new(length)\n# obj.set(index, val)\n# param_2 = obj.snap()\n# param_3 = obj.get(index, snap_id)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass SnapshotArray {\n\n init(_ length: Int) {\n\n }\n \n func set(_ index: Int, _ val: Int) {\n\n }\n \n func snap() -> Int {\n\n }\n \n func get(_ index: Int, _ snap_id: Int) -> Int {\n\n }\n}\n\n/**\n * Your SnapshotArray object will be instantiated and called as such:\n * let obj = SnapshotArray(length)\n * obj.set(index, val)\n * let ret_2: Int = obj.snap()\n * let ret_3: Int = obj.get(index, snap_id)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type SnapshotArray struct {\n\n}\n\n\nfunc Constructor(length int) SnapshotArray {\n\n}\n\n\nfunc (this *SnapshotArray) Set(index int, val int) {\n\n}\n\n\nfunc (this *SnapshotArray) Snap() int {\n\n}\n\n\nfunc (this *SnapshotArray) Get(index int, snap_id int) int {\n\n}\n\n\n/**\n * Your SnapshotArray object will be instantiated and called as such:\n * obj := Constructor(length);\n * obj.Set(index,val);\n * param_2 := obj.Snap();\n * param_3 := obj.Get(index,snap_id);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class SnapshotArray(_length: Int) {\n\n def set(index: Int, `val`: Int) {\n\n }\n\n def snap(): Int = {\n\n }\n\n def get(index: Int, snap_id: Int): Int = {\n\n }\n\n}\n\n/**\n * Your SnapshotArray object will be instantiated and called as such:\n * var obj = new SnapshotArray(length)\n * obj.set(index,`val`)\n * var param_2 = obj.snap()\n * var param_3 = obj.get(index,snap_id)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class SnapshotArray(length: Int) {\n\n fun set(index: Int, `val`: Int) {\n\n }\n\n fun snap(): Int {\n\n }\n\n fun get(index: Int, snap_id: Int): Int {\n\n }\n\n}\n\n/**\n * Your SnapshotArray object will be instantiated and called as such:\n * var obj = SnapshotArray(length)\n * obj.set(index,`val`)\n * var param_2 = obj.snap()\n * var param_3 = obj.get(index,snap_id)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct SnapshotArray {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl SnapshotArray {\n\n fn new(length: i32) -> Self {\n\n }\n \n fn set(&self, index: i32, val: i32) {\n\n }\n \n fn snap(&self) -> i32 {\n\n }\n \n fn get(&self, index: i32, snap_id: i32) -> i32 {\n\n }\n}\n\n/**\n * Your SnapshotArray object will be instantiated and called as such:\n * let obj = SnapshotArray::new(length);\n * obj.set(index, val);\n * let ret_2: i32 = obj.snap();\n * let ret_3: i32 = obj.get(index, snap_id);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class SnapshotArray {\n /**\n * @param Integer $length\n */\n function __construct($length) {\n\n }\n\n /**\n * @param Integer $index\n * @param Integer $val\n * @return NULL\n */\n function set($index, $val) {\n\n }\n\n /**\n * @return Integer\n */\n function snap() {\n\n }\n\n /**\n * @param Integer $index\n * @param Integer $snap_id\n * @return Integer\n */\n function get($index, $snap_id) {\n\n }\n}\n\n/**\n * Your SnapshotArray object will be instantiated and called as such:\n * $obj = SnapshotArray($length);\n * $obj->set($index, $val);\n * $ret_2 = $obj->snap();\n * $ret_3 = $obj->get($index, $snap_id);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class SnapshotArray {\n constructor(length: number) {\n\n }\n\n set(index: number, val: number): void {\n\n }\n\n snap(): number {\n\n }\n\n get(index: number, snap_id: number): number {\n\n }\n}\n\n/**\n * Your SnapshotArray object will be instantiated and called as such:\n * var obj = new SnapshotArray(length)\n * obj.set(index,val)\n * var param_2 = obj.snap()\n * var param_3 = obj.get(index,snap_id)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define snapshot-array%\n (class object%\n (super-new)\n\n ; length : exact-integer?\n (init-field\n length)\n \n ; set : exact-integer? exact-integer? -> void?\n (define/public (set index val)\n\n )\n ; snap : -> exact-integer?\n (define/public (snap)\n\n )\n ; get : exact-integer? exact-integer? -> exact-integer?\n (define/public (get index snap_id)\n\n )))\n\n;; Your snapshot-array% object will be instantiated and called as such:\n;; (define obj (new snapshot-array% [length length]))\n;; (send obj set index val)\n;; (define param_2 (send obj snap))\n;; (define param_3 (send obj get index snap_id))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1146](https://leetcode-cn.com/problems/snapshot-array)", "[\u5feb\u7167\u6570\u7ec4](/solution/1100-1199/1146.Snapshot%20Array/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1146](https://leetcode.com/problems/snapshot-array)", "[Snapshot Array](/solution/1100-1199/1146.Snapshot%20Array/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "1248", "frontend_question_id": "1145", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/binary-tree-coloring-game", "url_en": "https://leetcode.com/problems/binary-tree-coloring-game", "relative_path_cn": "/solution/1100-1199/1145.Binary%20Tree%20Coloring%20Game/README.md", "relative_path_en": "/solution/1100-1199/1145.Binary%20Tree%20Coloring%20Game/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u7740\u8272\u6e38\u620f", "title_en": "Binary Tree Coloring Game", "question_title_slug": "binary-tree-coloring-game", "content_en": "

Two players play a turn based game on a binary tree.  We are given the root of this binary tree, and the number of nodes n in the tree.  n is odd, and each node has a distinct value from 1 to n.

\n\n

Initially, the first player names a value x with 1 <= x <= n, and the second player names a value y with 1 <= y <= n and y != x.  The first player colors the node with value x red, and the second player colors the node with value y blue.

\n\n

Then, the players take turns starting with the first player.  In each turn, that player chooses a node of their color (red if player 1, blue if player 2) and colors an uncolored neighbor of the chosen node (either the left child, right child, or parent of the chosen node.)

\n\n

If (and only if) a player cannot choose such a node in this way, they must pass their turn.  If both players pass their turn, the game ends, and the winner is the player that colored more nodes.

\n\n

You are the second player.  If it is possible to choose such a y to ensure you win the game, return true.  If it is not possible, return false.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: root = [1,2,3,4,5,6,7,8,9,10,11], n = 11, x = 3\nOutput: true\nExplanation: The second player can choose the node with value 2.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • root is the root of a binary tree with n nodes and distinct node values from 1 to n.
  • \n\t
  • n is odd.
  • \n\t
  • 1 <= x <= n <= 100
  • \n
\n", "content_cn": "

\u6709\u4e24\u4f4d\u6781\u5ba2\u73a9\u5bb6\u53c2\u4e0e\u4e86\u4e00\u573a\u300c\u4e8c\u53c9\u6811\u7740\u8272\u300d\u7684\u6e38\u620f\u3002\u6e38\u620f\u4e2d\uff0c\u7ed9\u51fa\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9 root\uff0c\u6811\u4e0a\u603b\u5171\u6709 n \u4e2a\u8282\u70b9\uff0c\u4e14 n \u4e3a\u5947\u6570\uff0c\u5176\u4e2d\u6bcf\u4e2a\u8282\u70b9\u4e0a\u7684\u503c\u4ece 1 \u5230 n \u5404\u4e0d\u76f8\u540c\u3002

\n\n

 

\n\n

\u6e38\u620f\u4ece\u300c\u4e00\u53f7\u300d\u73a9\u5bb6\u5f00\u59cb\uff08\u300c\u4e00\u53f7\u300d\u73a9\u5bb6\u4e3a\u7ea2\u8272\uff0c\u300c\u4e8c\u53f7\u300d\u73a9\u5bb6\u4e3a\u84dd\u8272\uff09\uff0c\u6700\u5f00\u59cb\u65f6\uff0c

\n\n

\u300c\u4e00\u53f7\u300d\u73a9\u5bb6\u4ece [1, n] \u4e2d\u53d6\u4e00\u4e2a\u503c x\uff081 <= x <= n\uff09\uff1b

\n\n

\u300c\u4e8c\u53f7\u300d\u73a9\u5bb6\u4e5f\u4ece [1, n] \u4e2d\u53d6\u4e00\u4e2a\u503c y\uff081 <= y <= n\uff09\u4e14 y != x\u3002

\n\n

\u300c\u4e00\u53f7\u300d\u73a9\u5bb6\u7ed9\u503c\u4e3a x \u7684\u8282\u70b9\u67d3\u4e0a\u7ea2\u8272\uff0c\u800c\u300c\u4e8c\u53f7\u300d\u73a9\u5bb6\u7ed9\u503c\u4e3a y \u7684\u8282\u70b9\u67d3\u4e0a\u84dd\u8272\u3002

\n\n

 

\n\n

\u4e4b\u540e\u4e24\u4f4d\u73a9\u5bb6\u8f6e\u6d41\u8fdb\u884c\u64cd\u4f5c\uff0c\u6bcf\u4e00\u56de\u5408\uff0c\u73a9\u5bb6\u9009\u62e9\u4e00\u4e2a\u4ed6\u4e4b\u524d\u6d82\u597d\u989c\u8272\u7684\u8282\u70b9\uff0c\u5c06\u6240\u9009\u8282\u70b9\u4e00\u4e2a \u672a\u7740\u8272 \u7684\u90bb\u8282\u70b9\uff08\u5373\u5de6\u53f3\u5b50\u8282\u70b9\u3001\u6216\u7236\u8282\u70b9\uff09\u8fdb\u884c\u67d3\u8272\u3002

\n\n

\u5982\u679c\u5f53\u524d\u73a9\u5bb6\u65e0\u6cd5\u627e\u5230\u8fd9\u6837\u7684\u8282\u70b9\u6765\u67d3\u8272\u65f6\uff0c\u4ed6\u7684\u56de\u5408\u5c31\u4f1a\u88ab\u8df3\u8fc7\u3002

\n\n

\u82e5\u4e24\u4e2a\u73a9\u5bb6\u90fd\u6ca1\u6709\u53ef\u4ee5\u67d3\u8272\u7684\u8282\u70b9\u65f6\uff0c\u6e38\u620f\u7ed3\u675f\u3002\u7740\u8272\u8282\u70b9\u6700\u591a\u7684\u90a3\u4f4d\u73a9\u5bb6\u83b7\u5f97\u80dc\u5229 \u270c\ufe0f\u3002

\n\n

 

\n\n

\u73b0\u5728\uff0c\u5047\u8bbe\u4f60\u662f\u300c\u4e8c\u53f7\u300d\u73a9\u5bb6\uff0c\u6839\u636e\u6240\u7ed9\u51fa\u7684\u8f93\u5165\uff0c\u5047\u5982\u5b58\u5728\u4e00\u4e2a y \u503c\u53ef\u4ee5\u786e\u4fdd\u4f60\u8d62\u5f97\u8fd9\u573a\u6e38\u620f\uff0c\u5219\u8fd4\u56de true\uff1b\u82e5\u65e0\u6cd5\u83b7\u80dc\uff0c\u5c31\u8bf7\u8fd4\u56de false\u3002

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1aroot = [1,2,3,4,5,6,7,8,9,10,11], n = 11, x = 3\n\u8f93\u51fa\uff1aTrue\n\u89e3\u91ca\uff1a\u7b2c\u4e8c\u4e2a\u73a9\u5bb6\u53ef\u4ee5\u9009\u62e9\u503c\u4e3a 2 \u7684\u8282\u70b9\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9\u4e3a root\uff0c\u6811\u4e0a\u7531 n \u4e2a\u8282\u70b9\uff0c\u8282\u70b9\u4e0a\u7684\u503c\u4ece 1 \u5230 n \u5404\u4e0d\u76f8\u540c\u3002
  • \n\t
  • n \u4e3a\u5947\u6570\u3002
  • \n\t
  • 1 <= x <= n <= 100
  • \n
\n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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 */\nclass Solution {\npublic:\n bool btreeGameWinningMove(TreeNode* root, int n, int x) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode(int x) { val = x; }\n * }\n */\nclass Solution {\n public boolean btreeGameWinningMove(TreeNode root, int n, int x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution(object):\n def btreeGameWinningMove(self, root, n, x):\n \"\"\"\n :type root: TreeNode\n :type n: int\n :type x: int\n :rtype: bool\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution:\n def btreeGameWinningMove(self, root: TreeNode, n: int, x: int) -> bool:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nbool btreeGameWinningMove(struct TreeNode* root, int n, int x){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int x) { val = x; }\n * }\n */\npublic class Solution {\n public bool BtreeGameWinningMove(TreeNode root, int n, int x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val) {\n * this.val = val;\n * this.left = this.right = null;\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number} n\n * @param {number} x\n * @return {boolean}\n */\nvar btreeGameWinningMove = function(root, n, x) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val)\n# @val = val\n# @left, @right = nil, nil\n# end\n# end\n\n# @param {TreeNode} root\n# @param {Integer} n\n# @param {Integer} x\n# @return {Boolean}\ndef btree_game_winning_move(root, n, x)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.left = nil\n * self.right = nil\n * }\n * }\n */\nclass Solution {\n func btreeGameWinningMove(_ root: TreeNode?, _ n: Int, _ x: Int) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc btreeGameWinningMove(root *TreeNode, n int, x int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(var _value: Int) {\n * var value: Int = _value\n * var left: TreeNode = null\n * var right: TreeNode = null\n * }\n */\nobject Solution {\n def btreeGameWinningMove(root: TreeNode, n: Int, x: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun btreeGameWinningMove(root: TreeNode?, n: Int, x: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n// \n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn btree_game_winning_move(root: Option>>, n: i32, x: i32) -> bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($value) { $this->val = $value; }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param Integer $n\n * @param Integer $x\n * @return Boolean\n */\n function btreeGameWinningMove($root, $n, $x) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction btreeGameWinningMove(root: TreeNode | null, n: number, x: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (btree-game-winning-move root n x)\n (-> (or/c tree-node? #f) exact-integer? exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1145](https://leetcode-cn.com/problems/binary-tree-coloring-game)", "[\u4e8c\u53c9\u6811\u7740\u8272\u6e38\u620f](/solution/1100-1199/1145.Binary%20Tree%20Coloring%20Game/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1145](https://leetcode.com/problems/binary-tree-coloring-game)", "[Binary Tree Coloring Game](/solution/1100-1199/1145.Binary%20Tree%20Coloring%20Game/README_EN.md)", "`Tree`,`Depth-first Search`", "Medium", ""]}, {"question_id": "1247", "frontend_question_id": "1144", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/decrease-elements-to-make-array-zigzag", "url_en": "https://leetcode.com/problems/decrease-elements-to-make-array-zigzag", "relative_path_cn": "/solution/1100-1199/1144.Decrease%20Elements%20To%20Make%20Array%20Zigzag/README.md", "relative_path_en": "/solution/1100-1199/1144.Decrease%20Elements%20To%20Make%20Array%20Zigzag/README_EN.md", "title_cn": "\u9012\u51cf\u5143\u7d20\u4f7f\u6570\u7ec4\u5448\u952f\u9f7f\u72b6", "title_en": "Decrease Elements To Make Array Zigzag", "question_title_slug": "decrease-elements-to-make-array-zigzag", "content_en": "

Given an array nums of integers, a move consists of choosing any element and decreasing it by 1.

\n\n

An array A is a zigzag array if either:

\n\n
    \n\t
  • Every even-indexed element is greater than adjacent elements, ie. A[0] > A[1] < A[2] > A[3] < A[4] > ...
  • \n\t
  • OR, every odd-indexed element is greater than adjacent elements, ie. A[0] < A[1] > A[2] < A[3] > A[4] < ...
  • \n
\n\n

Return the minimum number of moves to transform the given array nums into a zigzag array.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [1,2,3]\nOutput: 2\nExplanation: We can decrease 2 to 0 or 3 to 1.\n
\n\n

Example 2:

\n\n
\nInput: nums = [9,6,1,6,2]\nOutput: 4\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 1000
  • \n\t
  • 1 <= nums[i] <= 1000
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums\uff0c\u6bcf\u6b21 \u64cd\u4f5c \u4f1a\u4ece\u4e2d\u9009\u62e9\u4e00\u4e2a\u5143\u7d20\u5e76 \u5c06\u8be5\u5143\u7d20\u7684\u503c\u51cf\u5c11 1\u3002

\n\n

\u5982\u679c\u7b26\u5408\u4e0b\u5217\u60c5\u51b5\u4e4b\u4e00\uff0c\u5219\u6570\u7ec4 A \u5c31\u662f \u952f\u9f7f\u6570\u7ec4\uff1a

\n\n
    \n\t
  • \u6bcf\u4e2a\u5076\u6570\u7d22\u5f15\u5bf9\u5e94\u7684\u5143\u7d20\u90fd\u5927\u4e8e\u76f8\u90bb\u7684\u5143\u7d20\uff0c\u5373 A[0] > A[1] < A[2] > A[3] < A[4] > ...
  • \n\t
  • \u6216\u8005\uff0c\u6bcf\u4e2a\u5947\u6570\u7d22\u5f15\u5bf9\u5e94\u7684\u5143\u7d20\u90fd\u5927\u4e8e\u76f8\u90bb\u7684\u5143\u7d20\uff0c\u5373 A[0] < A[1] > A[2] < A[3] > A[4] < ...
  • \n
\n\n

\u8fd4\u56de\u5c06\u6570\u7ec4 nums \u8f6c\u6362\u4e3a\u952f\u9f7f\u6570\u7ec4\u6240\u9700\u7684\u6700\u5c0f\u64cd\u4f5c\u6b21\u6570\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,2,3]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6211\u4eec\u53ef\u4ee5\u628a 2 \u9012\u51cf\u5230 0\uff0c\u6216\u628a 3 \u9012\u51cf\u5230 1\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anums = [9,6,1,6,2]\n\u8f93\u51fa\uff1a4\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 1000
  • \n\t
  • 1 <= nums[i] <= 1000
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int movesToMakeZigzag(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int movesToMakeZigzag(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def movesToMakeZigzag(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def movesToMakeZigzag(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint movesToMakeZigzag(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MovesToMakeZigzag(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar movesToMakeZigzag = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef moves_to_make_zigzag(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func movesToMakeZigzag(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func movesToMakeZigzag(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def movesToMakeZigzag(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun movesToMakeZigzag(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn moves_to_make_zigzag(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function movesToMakeZigzag($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function movesToMakeZigzag(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (moves-to-make-zigzag nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1144](https://leetcode-cn.com/problems/decrease-elements-to-make-array-zigzag)", "[\u9012\u51cf\u5143\u7d20\u4f7f\u6570\u7ec4\u5448\u952f\u9f7f\u72b6](/solution/1100-1199/1144.Decrease%20Elements%20To%20Make%20Array%20Zigzag/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1144](https://leetcode.com/problems/decrease-elements-to-make-array-zigzag)", "[Decrease Elements To Make Array Zigzag](/solution/1100-1199/1144.Decrease%20Elements%20To%20Make%20Array%20Zigzag/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "1246", "frontend_question_id": "1142", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/user-activity-for-the-past-30-days-ii", "url_en": "https://leetcode.com/problems/user-activity-for-the-past-30-days-ii", "relative_path_cn": "/solution/1100-1199/1142.User%20Activity%20for%20the%20Past%2030%20Days%20II/README.md", "relative_path_en": "/solution/1100-1199/1142.User%20Activity%20for%20the%20Past%2030%20Days%20II/README_EN.md", "title_cn": "\u8fc7\u53bb30\u5929\u7684\u7528\u6237\u6d3b\u52a8 II", "title_en": "User Activity for the Past 30 Days II", "question_title_slug": "user-activity-for-the-past-30-days-ii", "content_en": "

Table: Activity

\r\n\r\n
\r\n+---------------+---------+\r\n| Column Name   | Type    |\r\n+---------------+---------+\r\n| user_id       | int     |\r\n| session_id    | int     |\r\n| activity_date | date    |\r\n| activity_type | enum    |\r\n+---------------+---------+\r\nThere is no primary key for this table, it may have duplicate rows.\r\nThe activity_type column is an ENUM of type ('open_session', 'end_session', 'scroll_down', 'send_message').\r\nThe table shows the user activities for a social media website.\r\nNote that each session belongs to exactly one user.
\r\n\r\n

 

\r\n\r\n

Write an SQL query to find the average number of sessions per user for a period of 30 days ending 2019-07-27 inclusively, rounded to 2 decimal places. The sessions we want to count for a user are those with at least one activity in that time period.

\r\n\r\n

The query result format is in the following example:

\r\n\r\n
\r\nActivity table:\r\n+---------+------------+---------------+---------------+\r\n| user_id | session_id | activity_date | activity_type |\r\n+---------+------------+---------------+---------------+\r\n| 1       | 1          | 2019-07-20    | open_session  |\r\n| 1       | 1          | 2019-07-20    | scroll_down   |\r\n| 1       | 1          | 2019-07-20    | end_session   |\r\n| 2       | 4          | 2019-07-20    | open_session  |\r\n| 2       | 4          | 2019-07-21    | send_message  |\r\n| 2       | 4          | 2019-07-21    | end_session   |\r\n| 3       | 2          | 2019-07-21    | open_session  |\r\n| 3       | 2          | 2019-07-21    | send_message  |\r\n| 3       | 2          | 2019-07-21    | end_session   |\r\n| 3       | 5          | 2019-07-21    | open_session  |\r\n| 3       | 5          | 2019-07-21    | scroll_down   |\r\n| 3       | 5          | 2019-07-21    | end_session   |\r\n| 4       | 3          | 2019-06-25    | open_session  |\r\n| 4       | 3          | 2019-06-25    | end_session   |\r\n+---------+------------+---------------+---------------+\r\n\r\nResult table:\r\n+---------------------------+ \r\n| average_sessions_per_user |\r\n+---------------------------+ \r\n| 1.33                      |\r\n+---------------------------+ \r\nUser 1 and 2 each had 1 session in the past 30 days while user 3 had 2 sessions so the average is (1 + 1 + 2) / 3 = 1.33.
", "content_cn": "

Table: Activity

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| user_id       | int     |\n| session_id    | int     |\n| activity_date | date    |\n| activity_type | enum    |\n+---------------+---------+\n\u8be5\u8868\u6ca1\u6709\u4e3b\u952e\uff0c\u5b83\u53ef\u80fd\u6709\u91cd\u590d\u7684\u884c\u3002\nactivity_type \u5217\u662f ENUM\uff08\u201c open_session\u201d\uff0c\u201c end_session\u201d\uff0c\u201c scroll_down\u201d\uff0c\u201c send_message\u201d\uff09\u4e2d\u7684\u67d0\u4e00\u7c7b\u578b\u3002\n\u8be5\u8868\u663e\u793a\u4e86\u793e\u4ea4\u5a92\u4f53\u7f51\u7ad9\u7684\u7528\u6237\u6d3b\u52a8\u3002\n\u8bf7\u6ce8\u610f\uff0c\u6bcf\u4e2a\u4f1a\u8bdd\u5b8c\u5168\u5c5e\u4e8e\u4e00\u4e2a\u7528\u6237\u3002
\n\n

\u00a0

\n\n

\u7f16\u5199SQL\u67e5\u8be2\u4ee5\u67e5\u627e\u622a\u81f32019\u5e747\u670827\u65e5\uff08\u542b\uff09\u768430\u5929\u5185\u6bcf\u4e2a\u7528\u6237\u7684\u5e73\u5747\u4f1a\u8bdd\u6570\uff0c\u56db\u820d\u4e94\u5165\u5230\u5c0f\u6570\u70b9\u540e\u4e24\u4f4d\u3002\u6211\u4eec\u53ea\u7edf\u8ba1\u90a3\u4e9b\u4f1a\u8bdd\u671f\u95f4\u7528\u6237\u81f3\u5c11\u8fdb\u884c\u4e00\u9879\u6d3b\u52a8\u7684\u6709\u6548\u4f1a\u8bdd\u3002

\n\n

\u00a0

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a\uff1a

\n\n
\nActivity table:\n+---------+------------+---------------+---------------+\n| user_id | session_id | activity_date | activity_type |\n+---------+------------+---------------+---------------+\n| 1       | 1          | 2019-07-20    | open_session  |\n| 1       | 1          | 2019-07-20    | scroll_down   |\n| 1       | 1          | 2019-07-20    | end_session   |\n| 2       | 4          | 2019-07-20    | open_session  |\n| 2       | 4          | 2019-07-21    | send_message  |\n| 2       | 4          | 2019-07-21    | end_session   |\n| 3       | 2          | 2019-07-21    | open_session  |\n| 3       | 2          | 2019-07-21    | send_message  |\n| 3       | 2          | 2019-07-21    | end_session   |\n| 3       | 5          | 2019-07-21    | open_session  |\n| 3       | 5          | 2019-07-21    | scroll_down   |\n| 3       | 5          | 2019-07-21    | end_session   |\n| 4       | 3          | 2019-06-25    | open_session  |\n| 4       | 3          | 2019-06-25    | end_session   |\n+---------+------------+---------------+---------------+\n\nResult table:\n+---------------------------+ \n| average_sessions_per_user |\n+---------------------------+ \n| 1.33                      |\n+---------------------------+ \nUser 1 \u548c 2 \u5728\u8fc7\u53bb30\u5929\u5185\u5404\u81ea\u8fdb\u884c\u4e861\u6b21\u4f1a\u8bdd\uff0c\u800c\u7528\u62373\u8fdb\u884c\u4e862\u6b21\u4f1a\u8bdd\uff0c\u56e0\u6b64\u5e73\u5747\u503c\u4e3a\uff081 +1 + 2\uff09/ 3 = 1.33\u3002
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1142](https://leetcode-cn.com/problems/user-activity-for-the-past-30-days-ii)", "[\u8fc7\u53bb30\u5929\u7684\u7528\u6237\u6d3b\u52a8 II](/solution/1100-1199/1142.User%20Activity%20for%20the%20Past%2030%20Days%20II/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1142](https://leetcode.com/problems/user-activity-for-the-past-30-days-ii)", "[User Activity for the Past 30 Days II](/solution/1100-1199/1142.User%20Activity%20for%20the%20Past%2030%20Days%20II/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1245", "frontend_question_id": "1141", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/user-activity-for-the-past-30-days-i", "url_en": "https://leetcode.com/problems/user-activity-for-the-past-30-days-i", "relative_path_cn": "/solution/1100-1199/1141.User%20Activity%20for%20the%20Past%2030%20Days%20I/README.md", "relative_path_en": "/solution/1100-1199/1141.User%20Activity%20for%20the%20Past%2030%20Days%20I/README_EN.md", "title_cn": "\u67e5\u8be2\u8fd130\u5929\u6d3b\u8dc3\u7528\u6237\u6570", "title_en": "User Activity for the Past 30 Days I", "question_title_slug": "user-activity-for-the-past-30-days-i", "content_en": "

Table: Activity

\r\n\r\n
\r\n+---------------+---------+\r\n| Column Name   | Type    |\r\n+---------------+---------+\r\n| user_id       | int     |\r\n| session_id    | int     |\r\n| activity_date | date    |\r\n| activity_type | enum    |\r\n+---------------+---------+\r\nThere is no primary key for this table, it may have duplicate rows.\r\nThe activity_type column is an ENUM of type ('open_session', 'end_session', 'scroll_down', 'send_message').\r\nThe table shows the user activities for a social media website. \r\nNote that each session belongs to exactly one user.\r\n
\r\n\r\n

 

\r\n\r\n

Write an SQL query to find the daily active user count for a period of 30 days ending 2019-07-27 inclusively. A user was active on some day if he/she made at least one activity on that day.

\r\n\r\n

The query result format is in the following example:

\r\n\r\n
\r\nActivity table:\r\n+---------+------------+---------------+---------------+\r\n| user_id | session_id | activity_date | activity_type |\r\n+---------+------------+---------------+---------------+\r\n| 1       | 1          | 2019-07-20    | open_session  |\r\n| 1       | 1          | 2019-07-20    | scroll_down   |\r\n| 1       | 1          | 2019-07-20    | end_session   |\r\n| 2       | 4          | 2019-07-20    | open_session  |\r\n| 2       | 4          | 2019-07-21    | send_message  |\r\n| 2       | 4          | 2019-07-21    | end_session   |\r\n| 3       | 2          | 2019-07-21    | open_session  |\r\n| 3       | 2          | 2019-07-21    | send_message  |\r\n| 3       | 2          | 2019-07-21    | end_session   |\r\n| 4       | 3          | 2019-06-25    | open_session  |\r\n| 4       | 3          | 2019-06-25    | end_session   |\r\n+---------+------------+---------------+---------------+\r\n\r\nResult table:\r\n+------------+--------------+ \r\n| day        | active_users |\r\n+------------+--------------+ \r\n| 2019-07-20 | 2            |\r\n| 2019-07-21 | 2            |\r\n+------------+--------------+ \r\nNote that we do not care about days with zero active users.\r\n
", "content_cn": "

\u6d3b\u52a8\u8bb0\u5f55\u8868\uff1aActivity

\n\n
+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| user_id       | int     |\n| session_id    | int     |\n| activity_date | date    |\n| activity_type | enum    |\n+---------------+---------+\n\u8be5\u8868\u662f\u7528\u6237\u5728\u793e\u4ea4\u7f51\u7ad9\u7684\u6d3b\u52a8\u8bb0\u5f55\u3002\n\u8be5\u8868\u6ca1\u6709\u4e3b\u952e\uff0c\u53ef\u80fd\u5305\u542b\u91cd\u590d\u6570\u636e\u3002\nactivity_type \u5b57\u6bb5\u4e3a\u4ee5\u4e0b\u56db\u79cd\u503c ('open_session', 'end_session', 'scroll_down', 'send_message')\u3002\n\u6bcf\u4e2a session_id \u53ea\u5c5e\u4e8e\u4e00\u4e2a\u7528\u6237\u3002\n
\n\n

 

\n\n

\u8bf7\u5199SQL\u67e5\u8be2\u51fa\u622a\u81f3 2019-07-27\uff08\u5305\u542b2019-07-27\uff09\uff0c\u8fd1 30\u5929\u7684\u6bcf\u65e5\u6d3b\u8dc3\u7528\u6237\u6570\uff08\u5f53\u5929\u53ea\u8981\u6709\u4e00\u6761\u6d3b\u52a8\u8bb0\u5f55\uff0c\u5373\u4e3a\u6d3b\u8dc3\u7528\u6237\uff09\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u793a\u4f8b\u5982\u4e0b\uff1a

\n\n
Activity table:\n+---------+------------+---------------+---------------+\n| user_id | session_id | activity_date | activity_type |\n+---------+------------+---------------+---------------+\n| 1       | 1          | 2019-07-20    | open_session  |\n| 1       | 1          | 2019-07-20    | scroll_down   |\n| 1       | 1          | 2019-07-20    | end_session   |\n| 2       | 4          | 2019-07-20    | open_session  |\n| 2       | 4          | 2019-07-21    | send_message  |\n| 2       | 4          | 2019-07-21    | end_session   |\n| 3       | 2          | 2019-07-21    | open_session  |\n| 3       | 2          | 2019-07-21    | send_message  |\n| 3       | 2          | 2019-07-21    | end_session   |\n| 4       | 3          | 2019-06-25    | open_session  |\n| 4       | 3          | 2019-06-25    | end_session   |\n+---------+------------+---------------+---------------+\n\nResult table:\n+------------+--------------+ \n| day        | active_users |\n+------------+--------------+ \n| 2019-07-20 | 2            |\n| 2019-07-21 | 2            |\n+------------+--------------+ \n\u975e\u6d3b\u8dc3\u7528\u6237\u7684\u8bb0\u5f55\u4e0d\u9700\u8981\u5c55\u793a\u3002
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1141](https://leetcode-cn.com/problems/user-activity-for-the-past-30-days-i)", "[\u67e5\u8be2\u8fd130\u5929\u6d3b\u8dc3\u7528\u6237\u6570](/solution/1100-1199/1141.User%20Activity%20for%20the%20Past%2030%20Days%20I/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1141](https://leetcode.com/problems/user-activity-for-the-past-30-days-i)", "[User Activity for the Past 30 Days I](/solution/1100-1199/1141.User%20Activity%20for%20the%20Past%2030%20Days%20I/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1244", "frontend_question_id": "1316", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/distinct-echo-substrings", "url_en": "https://leetcode.com/problems/distinct-echo-substrings", "relative_path_cn": "/solution/1300-1399/1316.Distinct%20Echo%20Substrings/README.md", "relative_path_en": "/solution/1300-1399/1316.Distinct%20Echo%20Substrings/README_EN.md", "title_cn": "\u4e0d\u540c\u7684\u5faa\u73af\u5b50\u5b57\u7b26\u4e32", "title_en": "Distinct Echo Substrings", "question_title_slug": "distinct-echo-substrings", "content_en": "

Return the number of distinct non-empty substrings of text that can be written as the concatenation of some string with itself (i.e. it can be written as a + a where a is some string).

\n\n

 

\n

Example 1:

\n\n
\nInput: text = "abcabcabc"\nOutput: 3\nExplanation: The 3 substrings are "abcabc", "bcabca" and "cabcab".\n
\n\n

Example 2:

\n\n
\nInput: text = "leetcodeleetcode"\nOutput: 2\nExplanation: The 2 substrings are "ee" and "leetcodeleetcode".\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= text.length <= 2000
  • \n\t
  • text has only lowercase English letters.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 text \uff0c\u8bf7\u4f60\u8fd4\u56de\u6ee1\u8db3\u4e0b\u8ff0\u6761\u4ef6\u7684 \u4e0d\u540c \u975e\u7a7a\u5b50\u5b57\u7b26\u4e32\u7684\u6570\u76ee\uff1a

\n\n
    \n\t
  • \u53ef\u4ee5\u5199\u6210\u67d0\u4e2a\u5b57\u7b26\u4e32\u4e0e\u5176\u81ea\u8eab\u76f8\u8fde\u63a5\u7684\u5f62\u5f0f\uff08\u5373\uff0c\u53ef\u4ee5\u5199\u4e3a a + a\uff0c\u5176\u4e2d a \u662f\u67d0\u4e2a\u5b57\u7b26\u4e32\uff09\u3002
  • \n
\n\n

\u4f8b\u5982\uff0cabcabc \u5c31\u662f abc \u548c\u5b83\u81ea\u8eab\u8fde\u63a5\u5f62\u6210\u7684\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1atext = "abcabcabc"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a3 \u4e2a\u5b50\u5b57\u7b26\u4e32\u5206\u522b\u4e3a "abcabc"\uff0c"bcabca" \u548c "cabcab" \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1atext = "leetcodeleetcode"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a2 \u4e2a\u5b50\u5b57\u7b26\u4e32\u4e3a "ee" \u548c "leetcodeleetcode" \u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= text.length <= 2000
  • \n\t
  • text \u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int distinctEchoSubstrings(string text) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int distinctEchoSubstrings(String text) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def distinctEchoSubstrings(self, text):\n \"\"\"\n :type text: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def distinctEchoSubstrings(self, text: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint distinctEchoSubstrings(char * text){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int DistinctEchoSubstrings(string text) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} text\n * @return {number}\n */\nvar distinctEchoSubstrings = function(text) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} text\n# @return {Integer}\ndef distinct_echo_substrings(text)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func distinctEchoSubstrings(_ text: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func distinctEchoSubstrings(text string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def distinctEchoSubstrings(text: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun distinctEchoSubstrings(text: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn distinct_echo_substrings(text: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $text\n * @return Integer\n */\n function distinctEchoSubstrings($text) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function distinctEchoSubstrings(text: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (distinct-echo-substrings text)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1316](https://leetcode-cn.com/problems/distinct-echo-substrings)", "[\u4e0d\u540c\u7684\u5faa\u73af\u5b50\u5b57\u7b26\u4e32](/solution/1300-1399/1316.Distinct%20Echo%20Substrings/README.md)", "`\u5b57\u7b26\u4e32`", "\u56f0\u96be", ""], "md_table_row_en": ["[1316](https://leetcode.com/problems/distinct-echo-substrings)", "[Distinct Echo Substrings](/solution/1300-1399/1316.Distinct%20Echo%20Substrings/README_EN.md)", "`String`", "Hard", ""]}, {"question_id": "1243", "frontend_question_id": "1315", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sum-of-nodes-with-even-valued-grandparent", "url_en": "https://leetcode.com/problems/sum-of-nodes-with-even-valued-grandparent", "relative_path_cn": "/solution/1300-1399/1315.Sum%20of%20Nodes%20with%20Even-Valued%20Grandparent/README.md", "relative_path_en": "/solution/1300-1399/1315.Sum%20of%20Nodes%20with%20Even-Valued%20Grandparent/README_EN.md", "title_cn": "\u7956\u7236\u8282\u70b9\u503c\u4e3a\u5076\u6570\u7684\u8282\u70b9\u548c", "title_en": "Sum of Nodes with Even-Valued Grandparent", "question_title_slug": "sum-of-nodes-with-even-valued-grandparent", "content_en": "

Given a binary tree, return the sum of values of nodes with even-valued grandparent.  (A grandparent of a node is the parent of its parent, if it exists.)

\r\n\r\n

If there are no nodes with an even-valued grandparent, return 0.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n

\"\"

\r\n\r\n
\r\nInput: root = [6,7,8,2,7,1,3,9,null,1,4,null,null,null,5]\r\nOutput: 18\r\nExplanation: The red nodes are the nodes with even-value grandparent while the blue nodes are the even-value grandparents.\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • The number of nodes in the tree is between 1 and 10^4.
  • \r\n\t
  • The value of nodes is between 1 and 100.
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u68f5\u4e8c\u53c9\u6811\uff0c\u8bf7\u4f60\u8fd4\u56de\u6ee1\u8db3\u4ee5\u4e0b\u6761\u4ef6\u7684\u6240\u6709\u8282\u70b9\u7684\u503c\u4e4b\u548c\uff1a

\n\n
    \n\t
  • \u8be5\u8282\u70b9\u7684\u7956\u7236\u8282\u70b9\u7684\u503c\u4e3a\u5076\u6570\u3002\uff08\u4e00\u4e2a\u8282\u70b9\u7684\u7956\u7236\u8282\u70b9\u662f\u6307\u8be5\u8282\u70b9\u7684\u7236\u8282\u70b9\u7684\u7236\u8282\u70b9\u3002\uff09
  • \n
\n\n

\u5982\u679c\u4e0d\u5b58\u5728\u7956\u7236\u8282\u70b9\u503c\u4e3a\u5076\u6570\u7684\u8282\u70b9\uff0c\u90a3\u4e48\u8fd4\u56de 0 \u3002

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1aroot = [6,7,8,2,7,1,3,9,null,1,4,null,null,null,5]\n\u8f93\u51fa\uff1a18\n\u89e3\u91ca\uff1a\u56fe\u4e2d\u7ea2\u8272\u8282\u70b9\u7684\u7956\u7236\u8282\u70b9\u7684\u503c\u4e3a\u5076\u6570\uff0c\u84dd\u8272\u8282\u70b9\u4e3a\u8fd9\u4e9b\u7ea2\u8272\u8282\u70b9\u7684\u7956\u7236\u8282\u70b9\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u6811\u4e2d\u8282\u70b9\u7684\u6570\u76ee\u5728 1 \u5230 10^4 \u4e4b\u95f4\u3002
  • \n\t
  • \u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u5728 1 \u5230 100 \u4e4b\u95f4\u3002
  • \n
\n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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 */\nclass Solution {\npublic:\n int sumEvenGrandparent(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode(int x) { val = x; }\n * }\n */\nclass Solution {\n public int sumEvenGrandparent(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution(object):\n def sumEvenGrandparent(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution:\n def sumEvenGrandparent(self, root: TreeNode) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint sumEvenGrandparent(struct TreeNode* root){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int x) { val = x; }\n * }\n */\npublic class Solution {\n public int SumEvenGrandparent(TreeNode root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val) {\n * this.val = val;\n * this.left = this.right = null;\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar sumEvenGrandparent = function(root) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val)\n# @val = val\n# @left, @right = nil, nil\n# end\n# end\n\n# @param {TreeNode} root\n# @return {Integer}\ndef sum_even_grandparent(root)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.left = nil\n * self.right = nil\n * }\n * }\n */\nclass Solution {\n func sumEvenGrandparent(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc sumEvenGrandparent(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(var _value: Int) {\n * var value: Int = _value\n * var left: TreeNode = null\n * var right: TreeNode = null\n * }\n */\nobject Solution {\n def sumEvenGrandparent(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun sumEvenGrandparent(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n// \n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn sum_even_grandparent(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($value) { $this->val = $value; }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function sumEvenGrandparent($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction sumEvenGrandparent(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (sum-even-grandparent root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1315](https://leetcode-cn.com/problems/sum-of-nodes-with-even-valued-grandparent)", "[\u7956\u7236\u8282\u70b9\u503c\u4e3a\u5076\u6570\u7684\u8282\u70b9\u548c](/solution/1300-1399/1315.Sum%20of%20Nodes%20with%20Even-Valued%20Grandparent/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1315](https://leetcode.com/problems/sum-of-nodes-with-even-valued-grandparent)", "[Sum of Nodes with Even-Valued Grandparent](/solution/1300-1399/1315.Sum%20of%20Nodes%20with%20Even-Valued%20Grandparent/README_EN.md)", "`Tree`,`Depth-first Search`", "Medium", ""]}, {"question_id": "1242", "frontend_question_id": "1314", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/matrix-block-sum", "url_en": "https://leetcode.com/problems/matrix-block-sum", "relative_path_cn": "/solution/1300-1399/1314.Matrix%20Block%20Sum/README.md", "relative_path_en": "/solution/1300-1399/1314.Matrix%20Block%20Sum/README_EN.md", "title_cn": "\u77e9\u9635\u533a\u57df\u548c", "title_en": "Matrix Block Sum", "question_title_slug": "matrix-block-sum", "content_en": "

Given a m x n matrix mat and an integer k, return a matrix answer where each answer[i][j] is the sum of all elements mat[r][c] for:

\n\n
    \n\t
  • i - k <= r <= i + k,
  • \n\t
  • j - k <= c <= j + k, and
  • \n\t
  • (r, c) is a valid position in the matrix.
  • \n
\n\n

 

\n

Example 1:

\n\n
\nInput: mat = [[1,2,3],[4,5,6],[7,8,9]], k = 1\nOutput: [[12,21,16],[27,45,33],[24,39,28]]\n
\n\n

Example 2:

\n\n
\nInput: mat = [[1,2,3],[4,5,6],[7,8,9]], k = 2\nOutput: [[45,45,45],[45,45,45],[45,45,45]]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • m == mat.length
  • \n\t
  • n == mat[i].length
  • \n\t
  • 1 <= m, n, k <= 100
  • \n\t
  • 1 <= mat[i][j] <= 100
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u00a0m x n\u00a0\u7684\u77e9\u9635\u00a0mat\u00a0\u548c\u4e00\u4e2a\u6574\u6570 k \uff0c\u8bf7\u4f60\u8fd4\u56de\u4e00\u4e2a\u77e9\u9635\u00a0answer\u00a0\uff0c\u5176\u4e2d\u6bcf\u4e2a\u00a0answer[i][j]\u00a0\u662f\u6240\u6709\u6ee1\u8db3\u4e0b\u8ff0\u6761\u4ef6\u7684\u5143\u7d20\u00a0mat[r][c] \u7684\u548c\uff1a\u00a0

\n\n
    \n\t
  • i - k <= r <= i + k,
  • \n\t
  • j - k <= c <= j + k \u4e14
  • \n\t
  • (r, c)\u00a0\u5728\u77e9\u9635\u5185\u3002
  • \n
\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1amat = [[1,2,3],[4,5,6],[7,8,9]], k = 1\n\u8f93\u51fa\uff1a[[12,21,16],[27,45,33],[24,39,28]]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1amat = [[1,2,3],[4,5,6],[7,8,9]], k = 2\n\u8f93\u51fa\uff1a[[45,45,45],[45,45,45],[45,45,45]]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • m ==\u00a0mat.length
  • \n\t
  • n ==\u00a0mat[i].length
  • \n\t
  • 1 <= m, n, k <= 100
  • \n\t
  • 1 <= mat[i][j] <= 100
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> matrixBlockSum(vector>& mat, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[][] matrixBlockSum(int[][] mat, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def matrixBlockSum(self, mat, k):\n \"\"\"\n :type mat: List[List[int]]\n :type k: int\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def matrixBlockSum(self, mat: List[List[int]], k: int) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** matrixBlockSum(int** mat, int matSize, int* matColSize, int k, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[][] MatrixBlockSum(int[][] mat, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} mat\n * @param {number} k\n * @return {number[][]}\n */\nvar matrixBlockSum = function(mat, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} mat\n# @param {Integer} k\n# @return {Integer[][]}\ndef matrix_block_sum(mat, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func matrixBlockSum(_ mat: [[Int]], _ k: Int) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func matrixBlockSum(mat [][]int, k int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def matrixBlockSum(mat: Array[Array[Int]], k: Int): Array[Array[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun matrixBlockSum(mat: Array, k: Int): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn matrix_block_sum(mat: Vec>, k: i32) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $mat\n * @param Integer $k\n * @return Integer[][]\n */\n function matrixBlockSum($mat, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function matrixBlockSum(mat: number[][], k: number): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (matrix-block-sum mat k)\n (-> (listof (listof exact-integer?)) exact-integer? (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1314](https://leetcode-cn.com/problems/matrix-block-sum)", "[\u77e9\u9635\u533a\u57df\u548c](/solution/1300-1399/1314.Matrix%20Block%20Sum/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1314](https://leetcode.com/problems/matrix-block-sum)", "[Matrix Block Sum](/solution/1300-1399/1314.Matrix%20Block%20Sum/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "1241", "frontend_question_id": "1313", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/decompress-run-length-encoded-list", "url_en": "https://leetcode.com/problems/decompress-run-length-encoded-list", "relative_path_cn": "/solution/1300-1399/1313.Decompress%20Run-Length%20Encoded%20List/README.md", "relative_path_en": "/solution/1300-1399/1313.Decompress%20Run-Length%20Encoded%20List/README_EN.md", "title_cn": "\u89e3\u538b\u7f29\u7f16\u7801\u5217\u8868", "title_en": "Decompress Run-Length Encoded List", "question_title_slug": "decompress-run-length-encoded-list", "content_en": "

We are given a list nums of integers representing a list compressed with run-length encoding.

\n\n

Consider each adjacent pair of elements [freq, val] = [nums[2*i], nums[2*i+1]] (with i >= 0).  For each such pair, there are freq elements with value val concatenated in a sublist. Concatenate all the sublists from left to right to generate the decompressed list.

\n\n

Return the decompressed list.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [1,2,3,4]\nOutput: [2,4,4,4]\nExplanation: The first pair [1,2] means we have freq = 1 and val = 2 so we generate the array [2].\nThe second pair [3,4] means we have freq = 3 and val = 4 so we generate [4,4,4].\nAt the end the concatenation [2] + [4,4,4] is [2,4,4,4].\n
\n\n

Example 2:

\n\n
\nInput: nums = [1,1,2,3]\nOutput: [1,3,3]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= nums.length <= 100
  • \n\t
  • nums.length % 2 == 0
  • \n\t
  • 1 <= nums[i] <= 100
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u4ee5\u884c\u7a0b\u957f\u5ea6\u7f16\u7801\u538b\u7f29\u7684\u6574\u6570\u5217\u8868\u00a0nums\u00a0\u3002

\n\n

\u8003\u8651\u6bcf\u5bf9\u76f8\u90bb\u7684\u4e24\u4e2a\u5143\u7d20 [freq, val] = [nums[2*i], nums[2*i+1]]\u00a0\uff08\u5176\u4e2d\u00a0i >= 0\u00a0\uff09\uff0c\u6bcf\u4e00\u5bf9\u90fd\u8868\u793a\u89e3\u538b\u540e\u5b50\u5217\u8868\u4e2d\u6709 freq\u00a0\u4e2a\u503c\u4e3a\u00a0val\u00a0\u7684\u5143\u7d20\uff0c\u4f60\u9700\u8981\u4ece\u5de6\u5230\u53f3\u8fde\u63a5\u6240\u6709\u5b50\u5217\u8868\u4ee5\u751f\u6210\u89e3\u538b\u540e\u7684\u5217\u8868\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u89e3\u538b\u540e\u7684\u5217\u8868\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [1,2,3,4]\n\u8f93\u51fa\uff1a[2,4,4,4]\n\u89e3\u91ca\uff1a\u7b2c\u4e00\u5bf9 [1,2] \u4ee3\u8868\u7740 2 \u7684\u51fa\u73b0\u9891\u6b21\u4e3a 1\uff0c\u6240\u4ee5\u751f\u6210\u6570\u7ec4 [2]\u3002\n\u7b2c\u4e8c\u5bf9 [3,4] \u4ee3\u8868\u7740 4 \u7684\u51fa\u73b0\u9891\u6b21\u4e3a 3\uff0c\u6240\u4ee5\u751f\u6210\u6570\u7ec4 [4,4,4]\u3002\n\u6700\u540e\u5c06\u5b83\u4eec\u4e32\u8054\u5230\u4e00\u8d77 [2] + [4,4,4] = [2,4,4,4]\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [1,1,2,3]\n\u8f93\u51fa\uff1a[1,3,3]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= nums.length <= 100
  • \n\t
  • nums.length % 2 == 0
  • \n\t
  • 1 <= nums[i] <= 100
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector decompressRLElist(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] decompressRLElist(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def decompressRLElist(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def decompressRLElist(self, nums: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* decompressRLElist(int* nums, int numsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] DecompressRLElist(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar decompressRLElist = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer[]}\ndef decompress_rl_elist(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func decompressRLElist(_ nums: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func decompressRLElist(nums []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def decompressRLElist(nums: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun decompressRLElist(nums: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn decompress_rl_elist(nums: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer[]\n */\n function decompressRLElist($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function decompressRLElist(nums: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (decompress-rl-elist nums)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1313](https://leetcode-cn.com/problems/decompress-run-length-encoded-list)", "[\u89e3\u538b\u7f29\u7f16\u7801\u5217\u8868](/solution/1300-1399/1313.Decompress%20Run-Length%20Encoded%20List/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1313](https://leetcode.com/problems/decompress-run-length-encoded-list)", "[Decompress Run-Length Encoded List](/solution/1300-1399/1313.Decompress%20Run-Length%20Encoded%20List/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1240", "frontend_question_id": "1140", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/stone-game-ii", "url_en": "https://leetcode.com/problems/stone-game-ii", "relative_path_cn": "/solution/1100-1199/1140.Stone%20Game%20II/README.md", "relative_path_en": "/solution/1100-1199/1140.Stone%20Game%20II/README_EN.md", "title_cn": "\u77f3\u5b50\u6e38\u620f II", "title_en": "Stone Game II", "question_title_slug": "stone-game-ii", "content_en": "

Alice and Bob continue their games with piles of stones.  There are a number of piles arranged in a row, and each pile has a positive integer number of stones piles[i].  The objective of the game is to end with the most stones. 

\n\n

Alice and Bob take turns, with Alice starting first.  Initially, M = 1.

\n\n

On each player's turn, that player can take all the stones in the first X remaining piles, where 1 <= X <= 2M.  Then, we set M = max(M, X).

\n\n

The game continues until all the stones have been taken.

\n\n

Assuming Alice and Bob play optimally, return the maximum number of stones Alice can get.

\n\n

 

\n

Example 1:

\n\n
\nInput: piles = [2,7,9,4,4]\nOutput: 10\nExplanation:  If Alice takes one pile at the beginning, Bob takes two piles, then Alice takes 2 piles again. Alice can get 2 + 4 + 4 = 10 piles in total. If Alice takes two piles at the beginning, then Bob can take all three piles left. In this case, Alice get 2 + 7 = 9 piles in total. So we return 10 since it's larger. \n
\n\n

Example 2:

\n\n
\nInput: piles = [1,2,3,4,5,100]\nOutput: 104\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= piles.length <= 100
  • \n\t
  • 1 <= piles[i] <= 104
  • \n
\n", "content_cn": "

\u4e9a\u5386\u514b\u65af\u548c\u674e\u7ee7\u7eed\u4ed6\u4eec\u7684\u77f3\u5b50\u6e38\u620f\u3002\u8bb8\u591a\u5806\u77f3\u5b50 \u6392\u6210\u4e00\u884c\uff0c\u6bcf\u5806\u90fd\u6709\u6b63\u6574\u6570\u9897\u77f3\u5b50 piles[i]\u3002\u6e38\u620f\u4ee5\u8c01\u624b\u4e2d\u7684\u77f3\u5b50\u6700\u591a\u6765\u51b3\u51fa\u80dc\u8d1f\u3002

\n\n

\u4e9a\u5386\u514b\u65af\u548c\u674e\u8f6e\u6d41\u8fdb\u884c\uff0c\u4e9a\u5386\u514b\u65af\u5148\u5f00\u59cb\u3002\u6700\u521d\uff0cM = 1\u3002

\n\n

\u5728\u6bcf\u4e2a\u73a9\u5bb6\u7684\u56de\u5408\u4e2d\uff0c\u8be5\u73a9\u5bb6\u53ef\u4ee5\u62ff\u8d70\u5269\u4e0b\u7684 \u524d X \u5806\u7684\u6240\u6709\u77f3\u5b50\uff0c\u5176\u4e2d 1 <= X <= 2M\u3002\u7136\u540e\uff0c\u4ee4 M = max(M, X)\u3002

\n\n

\u6e38\u620f\u4e00\u76f4\u6301\u7eed\u5230\u6240\u6709\u77f3\u5b50\u90fd\u88ab\u62ff\u8d70\u3002

\n\n

\u5047\u8bbe\u4e9a\u5386\u514b\u65af\u548c\u674e\u90fd\u53d1\u6325\u51fa\u6700\u4f73\u6c34\u5e73\uff0c\u8fd4\u56de\u4e9a\u5386\u514b\u65af\u53ef\u4ee5\u5f97\u5230\u7684\u6700\u5927\u6570\u91cf\u7684\u77f3\u5934\u3002

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1apiles = [2,7,9,4,4]\n\u8f93\u51fa\uff1a10\n\u89e3\u91ca\uff1a\n\u5982\u679c\u4e9a\u5386\u514b\u65af\u5728\u5f00\u59cb\u65f6\u62ff\u8d70\u4e00\u5806\u77f3\u5b50\uff0c\u674e\u62ff\u8d70\u4e24\u5806\uff0c\u63a5\u7740\u4e9a\u5386\u514b\u65af\u4e5f\u62ff\u8d70\u4e24\u5806\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u4e9a\u5386\u514b\u65af\u53ef\u4ee5\u62ff\u5230 2 + 4 + 4 = 10 \u9897\u77f3\u5b50\u3002 \n\u5982\u679c\u4e9a\u5386\u514b\u65af\u5728\u5f00\u59cb\u65f6\u62ff\u8d70\u4e24\u5806\u77f3\u5b50\uff0c\u90a3\u4e48\u674e\u5c31\u53ef\u4ee5\u62ff\u8d70\u5269\u4e0b\u5168\u90e8\u4e09\u5806\u77f3\u5b50\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u4e9a\u5386\u514b\u65af\u53ef\u4ee5\u62ff\u5230 2 + 7 = 9 \u9897\u77f3\u5b50\u3002\n\u6240\u4ee5\u6211\u4eec\u8fd4\u56de\u66f4\u5927\u7684 10\u3002 \n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= piles.length <= 100
  • \n\t
  • 1 <= piles[i] <= 10 ^ 4
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int stoneGameII(vector& piles) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int stoneGameII(int[] piles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def stoneGameII(self, piles):\n \"\"\"\n :type piles: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def stoneGameII(self, piles: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint stoneGameII(int* piles, int pilesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int StoneGameII(int[] piles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} piles\n * @return {number}\n */\nvar stoneGameII = function(piles) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} piles\n# @return {Integer}\ndef stone_game_ii(piles)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func stoneGameII(_ piles: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func stoneGameII(piles []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def stoneGameII(piles: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun stoneGameII(piles: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn stone_game_ii(piles: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $piles\n * @return Integer\n */\n function stoneGameII($piles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function stoneGameII(piles: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (stone-game-ii piles)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1140](https://leetcode-cn.com/problems/stone-game-ii)", "[\u77f3\u5b50\u6e38\u620f II](/solution/1100-1199/1140.Stone%20Game%20II/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1140](https://leetcode.com/problems/stone-game-ii)", "[Stone Game II](/solution/1100-1199/1140.Stone%20Game%20II/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "1239", "frontend_question_id": "1139", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/largest-1-bordered-square", "url_en": "https://leetcode.com/problems/largest-1-bordered-square", "relative_path_cn": "/solution/1100-1199/1139.Largest%201-Bordered%20Square/README.md", "relative_path_en": "/solution/1100-1199/1139.Largest%201-Bordered%20Square/README_EN.md", "title_cn": "\u6700\u5927\u7684\u4ee5 1 \u4e3a\u8fb9\u754c\u7684\u6b63\u65b9\u5f62", "title_en": "Largest 1-Bordered Square", "question_title_slug": "largest-1-bordered-square", "content_en": "

Given a 2D grid of 0s and 1s, return the number of elements in the largest square subgrid that has all 1s on its border, or 0 if such a subgrid doesn't exist in the grid.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: grid = [[1,1,1],[1,0,1],[1,1,1]]\r\nOutput: 9\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: grid = [[1,1,0,0]]\r\nOutput: 1\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= grid.length <= 100
  • \r\n\t
  • 1 <= grid[0].length <= 100
  • \r\n\t
  • grid[i][j] is 0 or 1
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u7531\u82e5\u5e72 0 \u548c 1 \u7ec4\u6210\u7684\u4e8c\u7ef4\u7f51\u683c grid\uff0c\u8bf7\u4f60\u627e\u51fa\u8fb9\u754c\u5168\u90e8\u7531 1 \u7ec4\u6210\u7684\u6700\u5927 \u6b63\u65b9\u5f62 \u5b50\u7f51\u683c\uff0c\u5e76\u8fd4\u56de\u8be5\u5b50\u7f51\u683c\u4e2d\u7684\u5143\u7d20\u6570\u91cf\u3002\u5982\u679c\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de 0\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1agrid = [[1,1,1],[1,0,1],[1,1,1]]\n\u8f93\u51fa\uff1a9\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1agrid = [[1,1,0,0]]\n\u8f93\u51fa\uff1a1\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= grid.length <= 100
  • \n\t
  • 1 <= grid[0].length <= 100
  • \n\t
  • grid[i][j] \u4e3a 0 \u6216 1
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int largest1BorderedSquare(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int largest1BorderedSquare(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def largest1BorderedSquare(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def largest1BorderedSquare(self, grid: List[List[int]]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint largest1BorderedSquare(int** grid, int gridSize, int* gridColSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int Largest1BorderedSquare(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar largest1BorderedSquare = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef largest1_bordered_square(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func largest1BorderedSquare(_ grid: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func largest1BorderedSquare(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def largest1BorderedSquare(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun largest1BorderedSquare(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn largest1_bordered_square(grid: Vec>) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function largest1BorderedSquare($grid) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function largest1BorderedSquare(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (largest1-bordered-square grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1139](https://leetcode-cn.com/problems/largest-1-bordered-square)", "[\u6700\u5927\u7684\u4ee5 1 \u4e3a\u8fb9\u754c\u7684\u6b63\u65b9\u5f62](/solution/1100-1199/1139.Largest%201-Bordered%20Square/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1139](https://leetcode.com/problems/largest-1-bordered-square)", "[Largest 1-Bordered Square](/solution/1100-1199/1139.Largest%201-Bordered%20Square/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "1238", "frontend_question_id": "1138", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/alphabet-board-path", "url_en": "https://leetcode.com/problems/alphabet-board-path", "relative_path_cn": "/solution/1100-1199/1138.Alphabet%20Board%20Path/README.md", "relative_path_en": "/solution/1100-1199/1138.Alphabet%20Board%20Path/README_EN.md", "title_cn": "\u5b57\u6bcd\u677f\u4e0a\u7684\u8def\u5f84", "title_en": "Alphabet Board Path", "question_title_slug": "alphabet-board-path", "content_en": "

On an alphabet board, we start at position (0, 0), corresponding to character board[0][0].

\r\n\r\n

Here, board = ["abcde", "fghij", "klmno", "pqrst", "uvwxy", "z"], as shown in the diagram below.

\r\n\r\n

\"\"

\r\n\r\n

We may make the following moves:

\r\n\r\n
    \r\n\t
  • 'U' moves our position up one row, if the position exists on the board;
  • \r\n\t
  • 'D' moves our position down one row, if the position exists on the board;
  • \r\n\t
  • 'L' moves our position left one column, if the position exists on the board;
  • \r\n\t
  • 'R' moves our position right one column, if the position exists on the board;
  • \r\n\t
  • '!' adds the character board[r][c] at our current position (r, c) to the answer.
  • \r\n
\r\n\r\n

(Here, the only positions that exist on the board are positions with letters on them.)

\r\n\r\n

Return a sequence of moves that makes our answer equal to target in the minimum number of moves.  You may return any path that does so.

\r\n\r\n

 

\r\n

Example 1:

\r\n
Input: target = \"leet\"\r\nOutput: \"DDR!UURRR!!DDD!\"\r\n

Example 2:

\r\n
Input: target = \"code\"\r\nOutput: \"RR!DDRR!UUL!R!\"\r\n
\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= target.length <= 100
  • \r\n\t
  • target consists only of English lowercase letters.
  • \r\n
", "content_cn": "

\u6211\u4eec\u4ece\u4e00\u5757\u5b57\u6bcd\u677f\u4e0a\u7684\u4f4d\u7f6e (0, 0) \u51fa\u53d1\uff0c\u8be5\u5750\u6807\u5bf9\u5e94\u7684\u5b57\u7b26\u4e3a board[0][0]\u3002

\n\n

\u5728\u672c\u9898\u91cc\uff0c\u5b57\u6bcd\u677f\u4e3aboard = ["abcde", "fghij", "klmno", "pqrst", "uvwxy", "z"]\uff0c\u5982\u4e0b\u6240\u793a\u3002

\n\n

\"\"

\n\n

\u6211\u4eec\u53ef\u4ee5\u6309\u4e0b\u9762\u7684\u6307\u4ee4\u89c4\u5219\u884c\u52a8\uff1a

\n\n
    \n\t
  • \u5982\u679c\u65b9\u683c\u5b58\u5728\uff0c'U' \u610f\u5473\u7740\u5c06\u6211\u4eec\u7684\u4f4d\u7f6e\u4e0a\u79fb\u4e00\u884c\uff1b
  • \n\t
  • \u5982\u679c\u65b9\u683c\u5b58\u5728\uff0c'D' \u610f\u5473\u7740\u5c06\u6211\u4eec\u7684\u4f4d\u7f6e\u4e0b\u79fb\u4e00\u884c\uff1b
  • \n\t
  • \u5982\u679c\u65b9\u683c\u5b58\u5728\uff0c'L' \u610f\u5473\u7740\u5c06\u6211\u4eec\u7684\u4f4d\u7f6e\u5de6\u79fb\u4e00\u5217\uff1b
  • \n\t
  • \u5982\u679c\u65b9\u683c\u5b58\u5728\uff0c'R' \u610f\u5473\u7740\u5c06\u6211\u4eec\u7684\u4f4d\u7f6e\u53f3\u79fb\u4e00\u5217\uff1b
  • \n\t
  • '!' \u4f1a\u628a\u5728\u6211\u4eec\u5f53\u524d\u4f4d\u7f6e (r, c) \u7684\u5b57\u7b26 board[r][c] \u6dfb\u52a0\u5230\u7b54\u6848\u4e2d\u3002
  • \n
\n\n

\uff08\u6ce8\u610f\uff0c\u5b57\u6bcd\u677f\u4e0a\u53ea\u5b58\u5728\u6709\u5b57\u6bcd\u7684\u4f4d\u7f6e\u3002\uff09

\n\n

\u8fd4\u56de\u6307\u4ee4\u5e8f\u5217\uff0c\u7528\u6700\u5c0f\u7684\u884c\u52a8\u6b21\u6570\u8ba9\u7b54\u6848\u548c\u76ee\u6807 target \u76f8\u540c\u3002\u4f60\u53ef\u4ee5\u8fd4\u56de\u4efb\u4f55\u8fbe\u6210\u76ee\u6807\u7684\u8def\u5f84\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1atarget = "leet"\n\u8f93\u51fa\uff1a"DDR!UURRR!!DDD!"\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1atarget = "code"\n\u8f93\u51fa\uff1a"RR!DDRR!UUL!R!"\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= target.length <= 100
  • \n\t
  • target \u4ec5\u542b\u6709\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
  • \n
\n", "tags_en": ["Hash Table", "String"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string alphabetBoardPath(string target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String alphabetBoardPath(String target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def alphabetBoardPath(self, target):\n \"\"\"\n :type target: str\n :rtype: str\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def alphabetBoardPath(self, target: str) -> str:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * alphabetBoardPath(char * target){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string AlphabetBoardPath(string target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} target\n * @return {string}\n */\nvar alphabetBoardPath = function(target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} target\n# @return {String}\ndef alphabet_board_path(target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func alphabetBoardPath(_ target: String) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func alphabetBoardPath(target string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def alphabetBoardPath(target: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun alphabetBoardPath(target: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn alphabet_board_path(target: String) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $target\n * @return String\n */\n function alphabetBoardPath($target) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function alphabetBoardPath(target: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (alphabet-board-path target)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1138](https://leetcode-cn.com/problems/alphabet-board-path)", "[\u5b57\u6bcd\u677f\u4e0a\u7684\u8def\u5f84](/solution/1100-1199/1138.Alphabet%20Board%20Path/README.md)", "`\u54c8\u5e0c\u8868`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1138](https://leetcode.com/problems/alphabet-board-path)", "[Alphabet Board Path](/solution/1100-1199/1138.Alphabet%20Board%20Path/README_EN.md)", "`Hash Table`,`String`", "Medium", ""]}, {"question_id": "1237", "frontend_question_id": "1132", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/reported-posts-ii", "url_en": "https://leetcode.com/problems/reported-posts-ii", "relative_path_cn": "/solution/1100-1199/1132.Reported%20Posts%20II/README.md", "relative_path_en": "/solution/1100-1199/1132.Reported%20Posts%20II/README_EN.md", "title_cn": "\u62a5\u544a\u7684\u8bb0\u5f55 II", "title_en": "Reported Posts II", "question_title_slug": "reported-posts-ii", "content_en": "

Table: Actions

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| user_id       | int     |\n| post_id       | int     |\n| action_date   | date    |\n| action        | enum    |\n| extra         | varchar |\n+---------------+---------+\nThere is no primary key for this table, it may have duplicate rows.\nThe action column is an ENUM type of ('view', 'like', 'reaction', 'comment', 'report', 'share').\nThe extra column has optional information about the action such as a reason for report or a type of reaction. 
\n\n

Table: Removals

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| post_id       | int     |\n| remove_date   | date    | \n+---------------+---------+\npost_id is the primary key of this table.\nEach row in this table indicates that some post was removed as a result of being reported or as a result of an admin review.\n
\n\n

 

\n\n

Write an SQL query to find the average for daily percentage of posts that got removed after being reported as spam, rounded to 2 decimal places.

\n\n

The query result format is in the following example:

\n\n
\nActions table:\n+---------+---------+-------------+--------+--------+\n| user_id | post_id | action_date | action | extra  |\n+---------+---------+-------------+--------+--------+\n| 1       | 1       | 2019-07-01  | view   | null   |\n| 1       | 1       | 2019-07-01  | like   | null   |\n| 1       | 1       | 2019-07-01  | share  | null   |\n| 2       | 2       | 2019-07-04  | view   | null   |\n| 2       | 2       | 2019-07-04  | report | spam   |\n| 3       | 4       | 2019-07-04  | view   | null   |\n| 3       | 4       | 2019-07-04  | report | spam   |\n| 4       | 3       | 2019-07-02  | view   | null   |\n| 4       | 3       | 2019-07-02  | report | spam   |\n| 5       | 2       | 2019-07-03  | view   | null   |\n| 5       | 2       | 2019-07-03  | report | racism |\n| 5       | 5       | 2019-07-03  | view   | null   |\n| 5       | 5       | 2019-07-03  | report | racism |\n+---------+---------+-------------+--------+--------+\n\nRemovals table:\n+---------+-------------+\n| post_id | remove_date |\n+---------+-------------+\n| 2       | 2019-07-20  |\n| 3       | 2019-07-18  |\n+---------+-------------+\n\nResult table:\n+-----------------------+\n| average_daily_percent |\n+-----------------------+\n| 75.00                 |\n+-----------------------+\nThe percentage for 2019-07-04 is 50% because only one post of two spam reported posts was removed.\nThe percentage for 2019-07-02 is 100% because one post was reported as spam and it was removed.\nThe other days had no spam reports so the average is (50 + 100) / 2 = 75%\nNote that the output is only one number and that we do not care about the remove dates.
\n", "content_cn": "

\u52a8\u4f5c\u8868\uff1a Actions

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| user_id       | int     |\n| post_id       | int     |\n| action_date   | date    |\n| action        | enum    |\n| extra         | varchar |\n+---------------+---------+\n\u8fd9\u5f20\u8868\u6ca1\u6709\u4e3b\u952e\uff0c\u5e76\u6709\u53ef\u80fd\u5b58\u5728\u91cd\u590d\u7684\u884c\u3002\naction \u5217\u7684\u7c7b\u578b\u662f ENUM\uff0c\u53ef\u80fd\u7684\u503c\u4e3a ('view', 'like', 'reaction', 'comment', 'report', 'share')\u3002\nextra \u5217\u62e5\u6709\u4e00\u4e9b\u53ef\u9009\u4fe1\u606f\uff0c\u4f8b\u5982\uff1a\u62a5\u544a\u7406\u7531\uff08a reason for report\uff09\u6216\u53cd\u5e94\u7c7b\u578b\uff08a type of reaction\uff09\u7b49\u3002
\n\n

\u79fb\u9664\u8868\uff1a Removals

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| post_id       | int     |\n| remove_date   | date    | \n+---------------+---------+\n\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\u662f post_id\u3002\n\u8fd9\u5f20\u8868\u7684\u6bcf\u4e00\u884c\u8868\u793a\u4e00\u4e2a\u88ab\u79fb\u9664\u7684\u5e16\u5b50\uff0c\u539f\u56e0\u53ef\u80fd\u662f\u7531\u4e8e\u88ab\u4e3e\u62a5\u6216\u88ab\u7ba1\u7406\u5458\u5ba1\u67e5\u3002\n
\n\n

 

\n\n

\u7f16\u5199\u4e00\u6bb5 SQL \u6765\u67e5\u627e\uff1a\u5728\u88ab\u62a5\u544a\u4e3a\u5783\u573e\u5e7f\u544a\u7684\u5e16\u5b50\u4e2d\uff0c\u88ab\u79fb\u9664\u7684\u5e16\u5b50\u7684\u6bcf\u65e5\u5e73\u5747\u5360\u6bd4\uff0c\u56db\u820d\u4e94\u5165\u5230\u5c0f\u6570\u70b9\u540e 2 \u4f4d\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u7684\u683c\u5f0f\u5982\u4e0b\uff1a

\n\n
\nActions table:\n+---------+---------+-------------+--------+--------+\n| user_id | post_id | action_date | action | extra  |\n+---------+---------+-------------+--------+--------+\n| 1       | 1       | 2019-07-01  | view   | null   |\n| 1       | 1       | 2019-07-01  | like   | null   |\n| 1       | 1       | 2019-07-01  | share  | null   |\n| 2       | 2       | 2019-07-04  | view   | null   |\n| 2       | 2       | 2019-07-04  | report | spam   |\n| 3       | 4       | 2019-07-04  | view   | null   |\n| 3       | 4       | 2019-07-04  | report | spam   |\n| 4       | 3       | 2019-07-02  | view   | null   |\n| 4       | 3       | 2019-07-02  | report | spam   |\n| 5       | 2       | 2019-07-03  | view   | null   |\n| 5       | 2       | 2019-07-03  | report | racism |\n| 5       | 5       | 2019-07-03  | view   | null   |\n| 5       | 5       | 2019-07-03  | report | racism |\n+---------+---------+-------------+--------+--------+\n\nRemovals table:\n+---------+-------------+\n| post_id | remove_date |\n+---------+-------------+\n| 2       | 2019-07-20  |\n| 3       | 2019-07-18  |\n+---------+-------------+\n\nResult table:\n+-----------------------+\n| average_daily_percent |\n+-----------------------+\n| 75.00                 |\n+-----------------------+\n2019-07-04 \u7684\u5783\u573e\u5e7f\u544a\u79fb\u9664\u7387\u662f 50%\uff0c\u56e0\u4e3a\u6709\u4e24\u5f20\u5e16\u5b50\u88ab\u62a5\u544a\u4e3a\u5783\u573e\u5e7f\u544a\uff0c\u4f46\u53ea\u6709\u4e00\u4e2a\u5f97\u5230\u79fb\u9664\u3002\n2019-07-02 \u7684\u5783\u573e\u5e7f\u544a\u79fb\u9664\u7387\u662f 100%\uff0c\u56e0\u4e3a\u6709\u4e00\u5f20\u5e16\u5b50\u88ab\u4e3e\u62a5\u4e3a\u5783\u573e\u5e7f\u544a\u5e76\u5f97\u5230\u79fb\u9664\u3002\n\u5176\u4f59\u51e0\u5929\u6ca1\u6709\u6536\u5230\u5783\u573e\u5e7f\u544a\u7684\u4e3e\u62a5\uff0c\u56e0\u6b64\u5e73\u5747\u503c\u4e3a\uff1a(50 + 100) / 2 = 75%\n\u6ce8\u610f\uff0c\u8f93\u51fa\u4ec5\u9700\u8981\u4e00\u4e2a\u5e73\u5747\u503c\u5373\u53ef\uff0c\u6211\u4eec\u5e76\u4e0d\u5173\u6ce8\u79fb\u9664\u64cd\u4f5c\u7684\u65e5\u671f\u3002
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1132](https://leetcode-cn.com/problems/reported-posts-ii)", "[\u62a5\u544a\u7684\u8bb0\u5f55 II](/solution/1100-1199/1132.Reported%20Posts%20II/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1132](https://leetcode.com/problems/reported-posts-ii)", "[Reported Posts II](/solution/1100-1199/1132.Reported%20Posts%20II/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1236", "frontend_question_id": "1137", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/n-th-tribonacci-number", "url_en": "https://leetcode.com/problems/n-th-tribonacci-number", "relative_path_cn": "/solution/1100-1199/1137.N-th%20Tribonacci%20Number/README.md", "relative_path_en": "/solution/1100-1199/1137.N-th%20Tribonacci%20Number/README_EN.md", "title_cn": "\u7b2c N \u4e2a\u6cf0\u6ce2\u90a3\u5951\u6570", "title_en": "N-th Tribonacci Number", "question_title_slug": "n-th-tribonacci-number", "content_en": "

The Tribonacci sequence Tn is defined as follows: 

\r\n\r\n

T0 = 0, T1 = 1, T2 = 1, and Tn+3 = Tn + Tn+1 + Tn+2 for n >= 0.

\r\n\r\n

Given n, return the value of Tn.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: n = 4\r\nOutput: 4\r\nExplanation:\r\nT_3 = 0 + 1 + 1 = 2\r\nT_4 = 1 + 1 + 2 = 4\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: n = 25\r\nOutput: 1389537\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 0 <= n <= 37
  • \r\n\t
  • The answer is guaranteed to fit within a 32-bit integer, ie. answer <= 2^31 - 1.
  • \r\n
", "content_cn": "

\u6cf0\u6ce2\u90a3\u5951\u5e8f\u5217 Tn \u5b9a\u4e49\u5982\u4e0b\uff1a 

\n\n

T0 = 0, T1 = 1, T2 = 1, \u4e14\u5728 n >= 0 \u7684\u6761\u4ef6\u4e0b Tn+3 = Tn + Tn+1 + Tn+2

\n\n

\u7ed9\u4f60\u6574\u6570 n\uff0c\u8bf7\u8fd4\u56de\u7b2c n \u4e2a\u6cf0\u6ce2\u90a3\u5951\u6570 Tn \u7684\u503c\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1an = 4\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\nT_3 = 0 + 1 + 1 = 2\nT_4 = 1 + 1 + 2 = 4\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1an = 25\n\u8f93\u51fa\uff1a1389537\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 0 <= n <= 37
  • \n\t
  • \u7b54\u6848\u4fdd\u8bc1\u662f\u4e00\u4e2a 32 \u4f4d\u6574\u6570\uff0c\u5373 answer <= 2^31 - 1\u3002
  • \n
\n", "tags_en": ["Recursion"], "tags_cn": ["\u9012\u5f52"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int tribonacci(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int tribonacci(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def tribonacci(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def tribonacci(self, n: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint tribonacci(int n){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int Tribonacci(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar tribonacci = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef tribonacci(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func tribonacci(_ n: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func tribonacci(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def tribonacci(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun tribonacci(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn tribonacci(n: i32) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function tribonacci($n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function tribonacci(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (tribonacci n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1137](https://leetcode-cn.com/problems/n-th-tribonacci-number)", "[\u7b2c N \u4e2a\u6cf0\u6ce2\u90a3\u5951\u6570](/solution/1100-1199/1137.N-th%20Tribonacci%20Number/README.md)", "`\u9012\u5f52`", "\u7b80\u5355", ""], "md_table_row_en": ["[1137](https://leetcode.com/problems/n-th-tribonacci-number)", "[N-th Tribonacci Number](/solution/1100-1199/1137.N-th%20Tribonacci%20Number/README_EN.md)", "`Recursion`", "Easy", ""]}, {"question_id": "1234", "frontend_question_id": "1301", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-paths-with-max-score", "url_en": "https://leetcode.com/problems/number-of-paths-with-max-score", "relative_path_cn": "/solution/1300-1399/1301.Number%20of%20Paths%20with%20Max%20Score/README.md", "relative_path_en": "/solution/1300-1399/1301.Number%20of%20Paths%20with%20Max%20Score/README_EN.md", "title_cn": "\u6700\u5927\u5f97\u5206\u7684\u8def\u5f84\u6570\u76ee", "title_en": "Number of Paths with Max Score", "question_title_slug": "number-of-paths-with-max-score", "content_en": "

You are given a square board of characters. You can move on the board starting at the bottom right square marked with the character 'S'.

\r\n\r\n

You need to reach the top left square marked with the character 'E'. The rest of the squares are labeled either with a numeric character 1, 2, ..., 9 or with an obstacle 'X'. In one move you can go up, left or up-left (diagonally) only if there is no obstacle there.

\r\n\r\n

Return a list of two integers: the first integer is the maximum sum of numeric characters you can collect, and the second is the number of such paths that you can take to get that maximum sum, taken modulo 10^9 + 7.

\r\n\r\n

In case there is no path, return [0, 0].

\r\n\r\n

 

\r\n

Example 1:

\r\n
Input: board = [\"E23\",\"2X2\",\"12S\"]\r\nOutput: [7,1]\r\n

Example 2:

\r\n
Input: board = [\"E12\",\"1X1\",\"21S\"]\r\nOutput: [4,2]\r\n

Example 3:

\r\n
Input: board = [\"E11\",\"XXX\",\"11S\"]\r\nOutput: [0,0]\r\n
\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 2 <= board.length == board[i].length <= 100
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6b63\u65b9\u5f62\u5b57\u7b26\u6570\u7ec4 board \uff0c\u4f60\u4ece\u6570\u7ec4\u6700\u53f3\u4e0b\u65b9\u7684\u5b57\u7b26 'S' \u51fa\u53d1\u3002

\n\n

\u4f60\u7684\u76ee\u6807\u662f\u5230\u8fbe\u6570\u7ec4\u6700\u5de6\u4e0a\u89d2\u7684\u5b57\u7b26 'E' \uff0c\u6570\u7ec4\u5269\u4f59\u7684\u90e8\u5206\u4e3a\u6570\u5b57\u5b57\u7b26 1, 2, ..., 9 \u6216\u8005\u969c\u788d 'X'\u3002\u5728\u6bcf\u4e00\u6b65\u79fb\u52a8\u4e2d\uff0c\u4f60\u53ef\u4ee5\u5411\u4e0a\u3001\u5411\u5de6\u6216\u8005\u5de6\u4e0a\u65b9\u79fb\u52a8\uff0c\u53ef\u4ee5\u79fb\u52a8\u7684\u524d\u63d0\u662f\u5230\u8fbe\u7684\u683c\u5b50\u6ca1\u6709\u969c\u788d\u3002

\n\n

\u4e00\u6761\u8def\u5f84\u7684 \u300c\u5f97\u5206\u300d \u5b9a\u4e49\u4e3a\uff1a\u8def\u5f84\u4e0a\u6240\u6709\u6570\u5b57\u7684\u548c\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u4e00\u4e2a\u5217\u8868\uff0c\u5305\u542b\u4e24\u4e2a\u6574\u6570\uff1a\u7b2c\u4e00\u4e2a\u6574\u6570\u662f \u300c\u5f97\u5206\u300d \u7684\u6700\u5927\u503c\uff0c\u7b2c\u4e8c\u4e2a\u6574\u6570\u662f\u5f97\u5230\u6700\u5927\u5f97\u5206\u7684\u65b9\u6848\u6570\uff0c\u8bf7\u628a\u7ed3\u679c\u5bf9 10^9 + 7 \u53d6\u4f59\u3002

\n\n

\u5982\u679c\u6ca1\u6709\u4efb\u4f55\u8def\u5f84\u53ef\u4ee5\u5230\u8fbe\u7ec8\u70b9\uff0c\u8bf7\u8fd4\u56de [0, 0] \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aboard = ["E23","2X2","12S"]\n\u8f93\u51fa\uff1a[7,1]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aboard = ["E12","1X1","21S"]\n\u8f93\u51fa\uff1a[4,2]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1aboard = ["E11","XXX","11S"]\n\u8f93\u51fa\uff1a[0,0]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= board.length == board[i].length <= 100
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector pathsWithMaxScore(vector& board) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] pathsWithMaxScore(List board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def pathsWithMaxScore(self, board):\n \"\"\"\n :type board: List[str]\n :rtype: List[int]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def pathsWithMaxScore(self, board: List[str]) -> List[int]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* pathsWithMaxScore(char ** board, int boardSize, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] PathsWithMaxScore(IList board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} board\n * @return {number[]}\n */\nvar pathsWithMaxScore = function(board) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} board\n# @return {Integer[]}\ndef paths_with_max_score(board)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func pathsWithMaxScore(_ board: [String]) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func pathsWithMaxScore(board []string) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def pathsWithMaxScore(board: List[String]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun pathsWithMaxScore(board: List): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn paths_with_max_score(board: Vec) -> Vec {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $board\n * @return Integer[]\n */\n function pathsWithMaxScore($board) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function pathsWithMaxScore(board: string[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (paths-with-max-score board)\n (-> (listof string?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1301](https://leetcode-cn.com/problems/number-of-paths-with-max-score)", "[\u6700\u5927\u5f97\u5206\u7684\u8def\u5f84\u6570\u76ee](/solution/1300-1399/1301.Number%20of%20Paths%20with%20Max%20Score/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1301](https://leetcode.com/problems/number-of-paths-with-max-score)", "[Number of Paths with Max Score](/solution/1300-1399/1301.Number%20of%20Paths%20with%20Max%20Score/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1233", "frontend_question_id": "1274", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/number-of-ships-in-a-rectangle", "url_en": "https://leetcode.com/problems/number-of-ships-in-a-rectangle", "relative_path_cn": "/solution/1200-1299/1274.Number%20of%20Ships%20in%20a%20Rectangle/README.md", "relative_path_en": "/solution/1200-1299/1274.Number%20of%20Ships%20in%20a%20Rectangle/README_EN.md", "title_cn": "\u77e9\u5f62\u5185\u8239\u53ea\u7684\u6570\u76ee", "title_en": "Number of Ships in a Rectangle", "question_title_slug": "number-of-ships-in-a-rectangle", "content_en": "

(This problem is an interactive problem.)

\n\n

Each ship is located at an integer point on the sea represented by a cartesian plane, and each integer point may contain at most 1 ship.

\n\n

You have a function Sea.hasShips(topRight, bottomLeft) which takes two points as arguments and returns true If there is at least one ship in the rectangle represented by the two points, including on the boundary.

\n\n

Given two points: the top right and bottom left corners of a rectangle, return the number of ships present in that rectangle. It is guaranteed that there are at most 10 ships in that rectangle.

\n\n

Submissions making more than 400 calls to hasShips will be judged Wrong Answer. Also, any solutions that attempt to circumvent the judge will result in disqualification.

\n\n

 

\n

Example :

\n\n

\"\"

\n\n
\nInput: \nships = [[1,1],[2,2],[3,3],[5,5]], topRight = [4,4], bottomLeft = [0,0]\nOutput: 3\nExplanation: From [0,0] to [4,4] we can count 3 ships within the range.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • On the input ships is only given to initialize the map internally. You must solve this problem "blindfolded". In other words, you must find the answer using the given hasShips API, without knowing the ships position.
  • \n\t
  • 0 <= bottomLeft[0] <= topRight[0] <= 1000
  • \n\t
  • 0 <= bottomLeft[1] <= topRight[1] <= 1000
  • \n\t
  • topRight != bottomLeft
  • \n
\n", "content_cn": "

(\u6b64\u9898\u662f \u4ea4\u4e92\u5f0f\u95ee\u9898 )

\n\n

\u5728\u7528\u7b1b\u5361\u5c14\u5750\u6807\u7cfb\u8868\u793a\u7684\u4e8c\u7ef4\u6d77\u5e73\u9762\u4e0a\uff0c\u6709\u4e00\u4e9b\u8239\u3002\u6bcf\u4e00\u8258\u8239\u90fd\u5728\u4e00\u4e2a\u6574\u6570\u70b9\u4e0a\uff0c\u4e14\u6bcf\u4e00\u4e2a\u6574\u6570\u70b9\u6700\u591a\u53ea\u6709 1 \u8258\u8239\u3002

\n\n

\u6709\u4e00\u4e2a\u51fd\u6570 Sea.hasShips(topRight, bottomLeft) \uff0c\u8f93\u5165\u53c2\u6570\u4e3a\u53f3\u4e0a\u89d2\u548c\u5de6\u4e0b\u89d2\u4e24\u4e2a\u70b9\u7684\u5750\u6807\uff0c\u5f53\u4e14\u4ec5\u5f53\u8fd9\u4e24\u4e2a\u70b9\u6240\u8868\u793a\u7684\u77e9\u5f62\u533a\u57df\uff08\u5305\u542b\u8fb9\u754c\uff09\u5185\u81f3\u5c11\u6709\u4e00\u8258\u8239\u65f6\uff0c\u8fd9\u4e2a\u51fd\u6570\u624d\u8fd4\u56de true \uff0c\u5426\u5219\u8fd4\u56de false \u3002

\n\n

\u7ed9\u4f60\u77e9\u5f62\u7684\u53f3\u4e0a\u89d2 topRight \u548c\u5de6\u4e0b\u89d2 bottomLeft \u7684\u5750\u6807\uff0c\u8bf7\u4f60\u8fd4\u56de\u6b64\u77e9\u5f62\u5185\u8239\u53ea\u7684\u6570\u76ee\u3002\u9898\u76ee\u4fdd\u8bc1\u77e9\u5f62\u5185 \u81f3\u591a\u53ea\u6709 10 \u8258\u8239\u3002

\n\n

\u8c03\u7528\u51fd\u6570 hasShips \u8d85\u8fc7400\u6b21 \u7684\u63d0\u4ea4\u5c06\u88ab\u5224\u4e3a \u9519\u8bef\u7b54\u6848\uff08Wrong Answer\uff09 \u3002\u540c\u65f6\uff0c\u4efb\u4f55\u5c1d\u8bd5\u7ed5\u8fc7\u8bc4\u6d4b\u7cfb\u7edf\u7684\u884c\u4e3a\u90fd\u5c06\u88ab\u53d6\u6d88\u6bd4\u8d5b\u8d44\u683c\u3002

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1a\nships = [[1,1],[2,2],[3,3],[5,5]], topRight = [4,4], bottomLeft = [0,0]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u5728 [0,0] \u5230 [4,4] \u7684\u8303\u56f4\u5185\u603b\u5171\u6709 3 \u8258\u8239\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • ships \u6570\u7ec4\u53ea\u7528\u4e8e\u8bc4\u6d4b\u7cfb\u7edf\u5185\u90e8\u521d\u59cb\u5316\u3002\u4f60\u65e0\u6cd5\u5f97\u77e5 ships \u7684\u4fe1\u606f\uff0c\u6240\u4ee5\u53ea\u80fd\u901a\u8fc7\u8c03\u7528 hasShips \u63a5\u53e3\u6765\u6c42\u89e3\u3002
  • \n\t
  • 0 <= bottomLeft[0] <= topRight[0] <= 1000
  • \n\t
  • 0 <= bottomLeft[1] <= topRight[1] <= 1000
  • \n
\n", "tags_en": ["Divide and Conquer"], "tags_cn": ["\u5206\u6cbb\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * // This is Sea's API interface.\n * // You should not implement it, or speculate about its implementation\n * class Sea {\n * public:\n * bool hasShips(vector topRight, vector bottomLeft);\n * };\n */\n\nclass Solution {\npublic:\n int countShips(Sea sea, vector topRight, vector bottomLeft) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * // This is Sea's API interface.\n * // You should not implement it, or speculate about its implementation\n * class Sea {\n * public boolean hasShips(int[] topRight, int[] bottomLeft);\n * }\n */\n\nclass Solution {\n public int countShips(Sea sea, int[] topRight, int[] bottomLeft) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# \"\"\"\n# This is Sea's API interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class Sea(object):\n# def hasShips(self, topRight, bottomLeft):\n# \"\"\"\n# :type topRight: Point\n#\t\t :type bottomLeft: Point\n# :rtype bool\n# \"\"\"\n#\n#class Point(object):\n#\tdef __init__(self, x, y):\n#\t\tself.x = x\n#\t\tself.y = y\n\nclass Solution(object):\n def countShips(self, sea, topRight, bottomLeft):\n \"\"\"\n :type sea: Sea\n :type topRight: Point\n :type bottomLeft: Point\n :rtype: integer\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# \"\"\"\n# This is Sea's API interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class Sea(object):\n# def hasShips(self, topRight: 'Point', bottomLeft: 'Point') -> bool:\n#\n#class Point(object):\n#\tdef __init__(self, x: int, y: int):\n#\t\tself.x = x\n#\t\tself.y = y\n\nclass Solution(object):\n def countShips(self, sea: 'Sea', topRight: 'Point', bottomLeft: 'Point') -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * // The hasShips API is already defined for you.\n * // You should not implement it, or speculate about its implementation\n * bool hasShips(int topRightX, int topRightY, int bottomLeftX, int bottomLeftY);\n */\n\nint countShips(int topRightX, int topRightY, int bottomLeftX, int bottomLeftY) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * // This is Sea's API interface.\n * // You should not implement it, or speculate about its implementation\n * class Sea {\n * public bool HasShips(int[] topRight, int[] bottomLeft);\n * }\n */\n\nclass Solution {\n public int CountShips(Sea sea, int[] topRight, int[] bottomLeft) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // This is Sea's API interface.\n * // You should not implement it, or speculate about its implementation\n * function Sea() {\n * @param {integer[]} topRight\n * @param {integer[]} bottomLeft\n * @return {boolean}\n * this.hasShips = function(topRight, bottomLeft) {\n * ...\n * };\n * };\n */\n\n/**\n * @param {Sea} sea\n * @param {integer[]} topRight\n * @param {integer[]} bottomLeft\n * @return {integer}\n */\nvar countShips = function(sea, topRight, bottomLeft) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# This is Sea's API interface.\n# You should not implement it, or speculate about its implementation\n# class Sea\n# def hasShips(topRight, bottomLeft)\n#\t\t\n# end\n# end\n\n# @param {Sea} sea\n# @param {List[int]} topRight\n# @param {List[int]} bottomLeft\n# @return {int}\ndef countShips(sea, topRight, bottomLeft)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * // This is Sea's API interface.\n * // You should not implement it, or speculate about its implementation\n * class Sea {\n * public func hasShips(_ topRight: [Int], _ bottomLeft: [Int]) -> Bool {}\n * }\n */\n\nclass Solution {\n func countShips(_ sea: Sea, _ topRight: [Int], _ bottomLeft: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * // This is Sea's API interface.\n * // You should not implement it, or speculate about its implementation\n * type Sea struct {\n * func hasShips(topRight, bottomLeft []int) bool {}\n * }\n */\n\nfunc countShips(sea Sea, topRight, bottomLeft []int) int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * // This is Sea's API interface.\n * // You should not implement it, or speculate about its implementation\n * class Sea {\n * def hasShips(topRight: Array[Int], bottomLeft: Array[Int]): Boolean = {}\n * }\n */\n\nobject Solution {\n def countShips(sea: Sea, topRight: Array[Int], bottomLeft: Array[Int]): Int = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * // This is Sea's API interface.\n * // You should not implement it, or speculate about its implementation\n * class Sea {\n * fun hasShips(topRight: IntArray, bottomLeft: IntArray): Boolean{}\n * }\n */\n\nclass Solution {\n fun countShips(sea: Sea, topRight: IntArray, bottomLeft: IntArray): Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "/**\n * // This is Sea's API interface.\n * // You should not implement it, or speculate about its implementation\n * struct Sea;\n * impl Sea {\n * pub fn hasShips(topRight: Vec,bottomLeft: Vec)->bool{}\n * }\n */\n\nimpl Solution {\n pub fn count_ships(sea: &Sea, topRight: Vec, bottomLeft: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * // This is Sea's API interface.\n * // You should not implement it, or speculate about its implementation\n * class Sea {\n * function hasShips ($topRight, $bottomLeft) {}\n * }\n */\n\nclass Solution {\n /**\n * @param Sea $sea\n * @param Integer[] $topRight\n * @param Integer[] $bottomLeft\n * @return Integer[]\n */\n function countShips ($sea, $topRight, $bottomLeft) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * // This is the Sea's API interface.\n * // You should not implement it, or speculate about its implementation\n * class Sea {\n * hasShips(topRight: number[], bottomLeft: number[]): boolean {}\n * }\n */\n\nfunction countShips(sea: Sea, topRight: number[], bottomLeft: number[]): number {\n\t\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1274](https://leetcode-cn.com/problems/number-of-ships-in-a-rectangle)", "[\u77e9\u5f62\u5185\u8239\u53ea\u7684\u6570\u76ee](/solution/1200-1299/1274.Number%20of%20Ships%20in%20a%20Rectangle/README.md)", "`\u5206\u6cbb\u7b97\u6cd5`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1274](https://leetcode.com/problems/number-of-ships-in-a-rectangle)", "[Number of Ships in a Rectangle](/solution/1200-1299/1274.Number%20of%20Ships%20in%20a%20Rectangle/README_EN.md)", "`Divide and Conquer`", "Hard", "\ud83d\udd12"]}, {"question_id": "1232", "frontend_question_id": "1300", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sum-of-mutated-array-closest-to-target", "url_en": "https://leetcode.com/problems/sum-of-mutated-array-closest-to-target", "relative_path_cn": "/solution/1300-1399/1300.Sum%20of%20Mutated%20Array%20Closest%20to%20Target/README.md", "relative_path_en": "/solution/1300-1399/1300.Sum%20of%20Mutated%20Array%20Closest%20to%20Target/README_EN.md", "title_cn": "\u8f6c\u53d8\u6570\u7ec4\u540e\u6700\u63a5\u8fd1\u76ee\u6807\u503c\u7684\u6570\u7ec4\u548c", "title_en": "Sum of Mutated Array Closest to Target", "question_title_slug": "sum-of-mutated-array-closest-to-target", "content_en": "

Given an integer array arr and a target value target, return the integer value such that when we change all the integers larger than value in the given array to be equal to value, the sum of the array gets as close as possible (in absolute difference) to target.

\n\n

In case of a tie, return the minimum such integer.

\n\n

Notice that the answer is not neccesarilly a number from arr.

\n\n

 

\n

Example 1:

\n\n
\nInput: arr = [4,9,3], target = 10\nOutput: 3\nExplanation: When using 3 arr converts to [3, 3, 3] which sums 9 and that's the optimal answer.\n
\n\n

Example 2:

\n\n
\nInput: arr = [2,3,5], target = 10\nOutput: 5\n
\n\n

Example 3:

\n\n
\nInput: arr = [60864,25176,27249,21296,20204], target = 56803\nOutput: 11361\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= arr.length <= 104
  • \n\t
  • 1 <= arr[i], target <= 105
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr \u548c\u4e00\u4e2a\u76ee\u6807\u503c target \uff0c\u8bf7\u4f60\u8fd4\u56de\u4e00\u4e2a\u6574\u6570 value \uff0c\u4f7f\u5f97\u5c06\u6570\u7ec4\u4e2d\u6240\u6709\u5927\u4e8e value \u7684\u503c\u53d8\u6210 value \u540e\uff0c\u6570\u7ec4\u7684\u548c\u6700\u63a5\u8fd1  target \uff08\u6700\u63a5\u8fd1\u8868\u793a\u4e24\u8005\u4e4b\u5dee\u7684\u7edd\u5bf9\u503c\u6700\u5c0f\uff09\u3002

\n\n

\u5982\u679c\u6709\u591a\u79cd\u4f7f\u5f97\u548c\u6700\u63a5\u8fd1 target \u7684\u65b9\u6848\uff0c\u8bf7\u4f60\u8fd4\u56de\u8fd9\u4e9b\u6574\u6570\u4e2d\u7684\u6700\u5c0f\u503c\u3002

\n\n

\u8bf7\u6ce8\u610f\uff0c\u7b54\u6848\u4e0d\u4e00\u5b9a\u662f arr \u4e2d\u7684\u6570\u5b57\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aarr = [4,9,3], target = 10\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u5f53\u9009\u62e9 value \u4e3a 3 \u65f6\uff0c\u6570\u7ec4\u4f1a\u53d8\u6210 [3, 3, 3]\uff0c\u548c\u4e3a 9 \uff0c\u8fd9\u662f\u6700\u63a5\u8fd1 target \u7684\u65b9\u6848\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aarr = [2,3,5], target = 10\n\u8f93\u51fa\uff1a5\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aarr = [60864,25176,27249,21296,20204], target = 56803\n\u8f93\u51fa\uff1a11361\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= arr.length <= 10^4
  • \n\t
  • 1 <= arr[i], target <= 10^5
  • \n
\n", "tags_en": ["Array", "Binary Search"], "tags_cn": ["\u6570\u7ec4", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findBestValue(vector& arr, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findBestValue(int[] arr, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findBestValue(self, arr, target):\n \"\"\"\n :type arr: List[int]\n :type target: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findBestValue(self, arr: List[int], target: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findBestValue(int* arr, int arrSize, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindBestValue(int[] arr, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @param {number} target\n * @return {number}\n */\nvar findBestValue = function(arr, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @param {Integer} target\n# @return {Integer}\ndef find_best_value(arr, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findBestValue(_ arr: [Int], _ target: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findBestValue(arr []int, target int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findBestValue(arr: Array[Int], target: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findBestValue(arr: IntArray, target: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_best_value(arr: Vec, target: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @param Integer $target\n * @return Integer\n */\n function findBestValue($arr, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findBestValue(arr: number[], target: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-best-value arr target)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1300](https://leetcode-cn.com/problems/sum-of-mutated-array-closest-to-target)", "[\u8f6c\u53d8\u6570\u7ec4\u540e\u6700\u63a5\u8fd1\u76ee\u6807\u503c\u7684\u6570\u7ec4\u548c](/solution/1300-1399/1300.Sum%20of%20Mutated%20Array%20Closest%20to%20Target/README.md)", "`\u6570\u7ec4`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1300](https://leetcode.com/problems/sum-of-mutated-array-closest-to-target)", "[Sum of Mutated Array Closest to Target](/solution/1300-1399/1300.Sum%20of%20Mutated%20Array%20Closest%20to%20Target/README_EN.md)", "`Array`,`Binary Search`", "Medium", ""]}, {"question_id": "1231", "frontend_question_id": "1299", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/replace-elements-with-greatest-element-on-right-side", "url_en": "https://leetcode.com/problems/replace-elements-with-greatest-element-on-right-side", "relative_path_cn": "/solution/1200-1299/1299.Replace%20Elements%20with%20Greatest%20Element%20on%20Right%20Side/README.md", "relative_path_en": "/solution/1200-1299/1299.Replace%20Elements%20with%20Greatest%20Element%20on%20Right%20Side/README_EN.md", "title_cn": "\u5c06\u6bcf\u4e2a\u5143\u7d20\u66ff\u6362\u4e3a\u53f3\u4fa7\u6700\u5927\u5143\u7d20", "title_en": "Replace Elements with Greatest Element on Right Side", "question_title_slug": "replace-elements-with-greatest-element-on-right-side", "content_en": "

Given an array arr, replace every element in that array with the greatest element among the elements to its right, and replace the last element with -1.

\n\n

After doing so, return the array.

\n\n

 

\n

Example 1:

\n\n
\nInput: arr = [17,18,5,4,6,1]\nOutput: [18,6,6,6,1,-1]\nExplanation: \n- index 0 --> the greatest element to the right of index 0 is index 1 (18).\n- index 1 --> the greatest element to the right of index 1 is index 4 (6).\n- index 2 --> the greatest element to the right of index 2 is index 4 (6).\n- index 3 --> the greatest element to the right of index 3 is index 4 (6).\n- index 4 --> the greatest element to the right of index 4 is index 5 (1).\n- index 5 --> there are no elements to the right of index 5, so we put -1.\n
\n\n

Example 2:

\n\n
\nInput: arr = [400]\nOutput: [-1]\nExplanation: There are no elements to the right of index 0.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= arr.length <= 104
  • \n\t
  • 1 <= arr[i] <= 105
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4\u00a0arr\u00a0\uff0c\u8bf7\u4f60\u5c06\u6bcf\u4e2a\u5143\u7d20\u7528\u5b83\u53f3\u8fb9\u6700\u5927\u7684\u5143\u7d20\u66ff\u6362\uff0c\u5982\u679c\u662f\u6700\u540e\u4e00\u4e2a\u5143\u7d20\uff0c\u7528\u00a0-1 \u66ff\u6362\u3002

\n\n

\u5b8c\u6210\u6240\u6709\u66ff\u6362\u64cd\u4f5c\u540e\uff0c\u8bf7\u4f60\u8fd4\u56de\u8fd9\u4e2a\u6570\u7ec4\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [17,18,5,4,6,1]\n\u8f93\u51fa\uff1a[18,6,6,6,1,-1]\n\u89e3\u91ca\uff1a\n- \u4e0b\u6807 0 \u7684\u5143\u7d20 --> \u53f3\u4fa7\u6700\u5927\u5143\u7d20\u662f\u4e0b\u6807 1 \u7684\u5143\u7d20 (18)\n- \u4e0b\u6807 1 \u7684\u5143\u7d20 --> \u53f3\u4fa7\u6700\u5927\u5143\u7d20\u662f\u4e0b\u6807 4 \u7684\u5143\u7d20 (6)\n- \u4e0b\u6807 2 \u7684\u5143\u7d20 --> \u53f3\u4fa7\u6700\u5927\u5143\u7d20\u662f\u4e0b\u6807 4 \u7684\u5143\u7d20 (6)\n- \u4e0b\u6807 3 \u7684\u5143\u7d20 --> \u53f3\u4fa7\u6700\u5927\u5143\u7d20\u662f\u4e0b\u6807 4 \u7684\u5143\u7d20 (6)\n- \u4e0b\u6807 4 \u7684\u5143\u7d20 --> \u53f3\u4fa7\u6700\u5927\u5143\u7d20\u662f\u4e0b\u6807 5 \u7684\u5143\u7d20 (1)\n- \u4e0b\u6807 5 \u7684\u5143\u7d20 --> \u53f3\u4fa7\u6ca1\u6709\u5176\u4ed6\u5143\u7d20\uff0c\u66ff\u6362\u4e3a -1\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [400]\n\u8f93\u51fa\uff1a[-1]\n\u89e3\u91ca\uff1a\u4e0b\u6807 0 \u7684\u5143\u7d20\u53f3\u4fa7\u6ca1\u6709\u5176\u4ed6\u5143\u7d20\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= arr.length <= 104
  • \n\t
  • 1 <= arr[i] <= 105
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector replaceElements(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] replaceElements(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def replaceElements(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def replaceElements(self, arr: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* replaceElements(int* arr, int arrSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] ReplaceElements(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number[]}\n */\nvar replaceElements = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer[]}\ndef replace_elements(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func replaceElements(_ arr: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func replaceElements(arr []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def replaceElements(arr: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun replaceElements(arr: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn replace_elements(arr: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer[]\n */\n function replaceElements($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function replaceElements(arr: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (replace-elements arr)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1299](https://leetcode-cn.com/problems/replace-elements-with-greatest-element-on-right-side)", "[\u5c06\u6bcf\u4e2a\u5143\u7d20\u66ff\u6362\u4e3a\u53f3\u4fa7\u6700\u5927\u5143\u7d20](/solution/1200-1299/1299.Replace%20Elements%20with%20Greatest%20Element%20on%20Right%20Side/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1299](https://leetcode.com/problems/replace-elements-with-greatest-element-on-right-side)", "[Replace Elements with Greatest Element on Right Side](/solution/1200-1299/1299.Replace%20Elements%20with%20Greatest%20Element%20on%20Right%20Side/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1230", "frontend_question_id": "1131", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-of-absolute-value-expression", "url_en": "https://leetcode.com/problems/maximum-of-absolute-value-expression", "relative_path_cn": "/solution/1100-1199/1131.Maximum%20of%20Absolute%20Value%20Expression/README.md", "relative_path_en": "/solution/1100-1199/1131.Maximum%20of%20Absolute%20Value%20Expression/README_EN.md", "title_cn": "\u7edd\u5bf9\u503c\u8868\u8fbe\u5f0f\u7684\u6700\u5927\u503c", "title_en": "Maximum of Absolute Value Expression", "question_title_slug": "maximum-of-absolute-value-expression", "content_en": "

Given two arrays of integers with equal lengths, return the maximum value of:

\r\n\r\n

|arr1[i] - arr1[j]| + |arr2[i] - arr2[j]| + |i - j|

\r\n\r\n

where the maximum is taken over all 0 <= i, j < arr1.length.

\r\n\n

 

\n

Example 1:

\n\n
\nInput: arr1 = [1,2,3,4], arr2 = [-1,4,5,6]\nOutput: 13\n
\n\n

Example 2:

\n\n
\nInput: arr1 = [1,-2,-5,0,10], arr2 = [0,-2,-1,-7,-4]\nOutput: 20\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= arr1.length == arr2.length <= 40000
  • \n\t
  • -10^6 <= arr1[i], arr2[i] <= 10^6
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e24\u4e2a\u957f\u5ea6\u76f8\u7b49\u7684\u6574\u6570\u6570\u7ec4\uff0c\u8fd4\u56de\u4e0b\u9762\u8868\u8fbe\u5f0f\u7684\u6700\u5927\u503c\uff1a

\n\n

|arr1[i] - arr1[j]| + |arr2[i] - arr2[j]| + |i - j|

\n\n

\u5176\u4e2d\u4e0b\u6807 i\uff0cj \u6ee1\u8db3 0 <= i, j < arr1.length\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aarr1 = [1,2,3,4], arr2 = [-1,4,5,6]\n\u8f93\u51fa\uff1a13\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aarr1 = [1,-2,-5,0,10], arr2 = [0,-2,-1,-7,-4]\n\u8f93\u51fa\uff1a20
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= arr1.length == arr2.length <= 40000
  • \n\t
  • -10^6 <= arr1[i], arr2[i] <= 10^6
  • \n
\n", "tags_en": ["Bit Manipulation", "Math"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxAbsValExpr(vector& arr1, vector& arr2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxAbsValExpr(int[] arr1, int[] arr2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxAbsValExpr(self, arr1, arr2):\n \"\"\"\n :type arr1: List[int]\n :type arr2: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxAbsValExpr(self, arr1: List[int], arr2: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxAbsValExpr(int* arr1, int arr1Size, int* arr2, int arr2Size){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxAbsValExpr(int[] arr1, int[] arr2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr1\n * @param {number[]} arr2\n * @return {number}\n */\nvar maxAbsValExpr = function(arr1, arr2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr1\n# @param {Integer[]} arr2\n# @return {Integer}\ndef max_abs_val_expr(arr1, arr2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxAbsValExpr(_ arr1: [Int], _ arr2: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxAbsValExpr(arr1 []int, arr2 []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxAbsValExpr(arr1: Array[Int], arr2: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxAbsValExpr(arr1: IntArray, arr2: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_abs_val_expr(arr1: Vec, arr2: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr1\n * @param Integer[] $arr2\n * @return Integer\n */\n function maxAbsValExpr($arr1, $arr2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxAbsValExpr(arr1: number[], arr2: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-abs-val-expr arr1 arr2)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1131](https://leetcode-cn.com/problems/maximum-of-absolute-value-expression)", "[\u7edd\u5bf9\u503c\u8868\u8fbe\u5f0f\u7684\u6700\u5927\u503c](/solution/1100-1199/1131.Maximum%20of%20Absolute%20Value%20Expression/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1131](https://leetcode.com/problems/maximum-of-absolute-value-expression)", "[Maximum of Absolute Value Expression](/solution/1100-1199/1131.Maximum%20of%20Absolute%20Value%20Expression/README_EN.md)", "`Bit Manipulation`,`Math`", "Medium", ""]}, {"question_id": "1229", "frontend_question_id": "1129", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/shortest-path-with-alternating-colors", "url_en": "https://leetcode.com/problems/shortest-path-with-alternating-colors", "relative_path_cn": "/solution/1100-1199/1129.Shortest%20Path%20with%20Alternating%20Colors/README.md", "relative_path_en": "/solution/1100-1199/1129.Shortest%20Path%20with%20Alternating%20Colors/README_EN.md", "title_cn": "\u989c\u8272\u4ea4\u66ff\u7684\u6700\u77ed\u8def\u5f84", "title_en": "Shortest Path with Alternating Colors", "question_title_slug": "shortest-path-with-alternating-colors", "content_en": "

Consider a directed graph, with nodes labelled 0, 1, ..., n-1.  In this graph, each edge is either red or blue, and there could be self-edges or parallel edges.

\r\n\r\n

Each [i, j] in red_edges denotes a red directed edge from node i to node j.  Similarly, each [i, j] in blue_edges denotes a blue directed edge from node i to node j.

\r\n\r\n

Return an array answer of length n, where each answer[X] is the length of the shortest path from node 0 to node X such that the edge colors alternate along the path (or -1 if such a path doesn't exist).

\r\n\r\n

 

\r\n

Example 1:

\r\n
Input: n = 3, red_edges = [[0,1],[1,2]], blue_edges = []\r\nOutput: [0,1,-1]\r\n

Example 2:

\r\n
Input: n = 3, red_edges = [[0,1]], blue_edges = [[2,1]]\r\nOutput: [0,1,-1]\r\n

Example 3:

\r\n
Input: n = 3, red_edges = [[1,0]], blue_edges = [[2,1]]\r\nOutput: [0,-1,-1]\r\n

Example 4:

\r\n
Input: n = 3, red_edges = [[0,1]], blue_edges = [[1,2]]\r\nOutput: [0,1,2]\r\n

Example 5:

\r\n
Input: n = 3, red_edges = [[0,1],[0,2]], blue_edges = [[1,0]]\r\nOutput: [0,1,1]\r\n
\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= n <= 100
  • \r\n\t
  • red_edges.length <= 400
  • \r\n\t
  • blue_edges.length <= 400
  • \r\n\t
  • red_edges[i].length == blue_edges[i].length == 2
  • \r\n\t
  • 0 <= red_edges[i][j], blue_edges[i][j] < n
  • \r\n
", "content_cn": "

\u5728\u4e00\u4e2a\u6709\u5411\u56fe\u4e2d\uff0c\u8282\u70b9\u5206\u522b\u6807\u8bb0\u4e3a 0, 1, ..., n-1\u3002\u8fd9\u4e2a\u56fe\u4e2d\u7684\u6bcf\u6761\u8fb9\u4e0d\u662f\u7ea2\u8272\u5c31\u662f\u84dd\u8272\uff0c\u4e14\u5b58\u5728\u81ea\u73af\u6216\u5e73\u884c\u8fb9\u3002

\n\n

red_edges \u4e2d\u7684\u6bcf\u4e00\u4e2a [i, j] \u5bf9\u8868\u793a\u4ece\u8282\u70b9 i \u5230\u8282\u70b9 j \u7684\u7ea2\u8272\u6709\u5411\u8fb9\u3002\u7c7b\u4f3c\u5730\uff0cblue_edges \u4e2d\u7684\u6bcf\u4e00\u4e2a [i, j] \u5bf9\u8868\u793a\u4ece\u8282\u70b9 i \u5230\u8282\u70b9 j \u7684\u84dd\u8272\u6709\u5411\u8fb9\u3002

\n\n

\u8fd4\u56de\u957f\u5ea6\u4e3a n \u7684\u6570\u7ec4 answer\uff0c\u5176\u4e2d answer[X] \u662f\u4ece\u8282\u70b9 0 \u5230\u8282\u70b9 X \u7684\u7ea2\u8272\u8fb9\u548c\u84dd\u8272\u8fb9\u4ea4\u66ff\u51fa\u73b0\u7684\u6700\u77ed\u8def\u5f84\u7684\u957f\u5ea6\u3002\u5982\u679c\u4e0d\u5b58\u5728\u8fd9\u6837\u7684\u8def\u5f84\uff0c\u90a3\u4e48 answer[x] = -1\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1an = 3, red_edges = [[0,1],[1,2]], blue_edges = []\n\u8f93\u51fa\uff1a[0,1,-1]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1an = 3, red_edges = [[0,1]], blue_edges = [[2,1]]\n\u8f93\u51fa\uff1a[0,1,-1]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1an = 3, red_edges = [[1,0]], blue_edges = [[2,1]]\n\u8f93\u51fa\uff1a[0,-1,-1]\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1an = 3, red_edges = [[0,1]], blue_edges = [[1,2]]\n\u8f93\u51fa\uff1a[0,1,2]\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1an = 3, red_edges = [[0,1],[0,2]], blue_edges = [[1,0]]\n\u8f93\u51fa\uff1a[0,1,1]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 100
  • \n\t
  • red_edges.length <= 400
  • \n\t
  • blue_edges.length <= 400
  • \n\t
  • red_edges[i].length == blue_edges[i].length == 2
  • \n\t
  • 0 <= red_edges[i][j], blue_edges[i][j] < n
  • \n
\n", "tags_en": ["Breadth-first Search", "Graph"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector shortestAlternatingPaths(int n, vector>& red_edges, vector>& blue_edges) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] shortestAlternatingPaths(int n, int[][] red_edges, int[][] blue_edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def shortestAlternatingPaths(self, n, red_edges, blue_edges):\n \"\"\"\n :type n: int\n :type red_edges: List[List[int]]\n :type blue_edges: List[List[int]]\n :rtype: List[int]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def shortestAlternatingPaths(self, n: int, red_edges: List[List[int]], blue_edges: List[List[int]]) -> List[int]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* shortestAlternatingPaths(int n, int** red_edges, int red_edgesSize, int* red_edgesColSize, int** blue_edges, int blue_edgesSize, int* blue_edgesColSize, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] ShortestAlternatingPaths(int n, int[][] red_edges, int[][] blue_edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} red_edges\n * @param {number[][]} blue_edges\n * @return {number[]}\n */\nvar shortestAlternatingPaths = function(n, red_edges, blue_edges) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} red_edges\n# @param {Integer[][]} blue_edges\n# @return {Integer[]}\ndef shortest_alternating_paths(n, red_edges, blue_edges)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func shortestAlternatingPaths(_ n: Int, _ red_edges: [[Int]], _ blue_edges: [[Int]]) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func shortestAlternatingPaths(n int, red_edges [][]int, blue_edges [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def shortestAlternatingPaths(n: Int, red_edges: Array[Array[Int]], blue_edges: Array[Array[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun shortestAlternatingPaths(n: Int, red_edges: Array, blue_edges: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn shortest_alternating_paths(n: i32, red_edges: Vec>, blue_edges: Vec>) -> Vec {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $red_edges\n * @param Integer[][] $blue_edges\n * @return Integer[]\n */\n function shortestAlternatingPaths($n, $red_edges, $blue_edges) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function shortestAlternatingPaths(n: number, red_edges: number[][], blue_edges: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (shortest-alternating-paths n red_edges blue_edges)\n (-> exact-integer? (listof (listof exact-integer?)) (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1129](https://leetcode-cn.com/problems/shortest-path-with-alternating-colors)", "[\u989c\u8272\u4ea4\u66ff\u7684\u6700\u77ed\u8def\u5f84](/solution/1100-1199/1129.Shortest%20Path%20with%20Alternating%20Colors/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u56fe`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1129](https://leetcode.com/problems/shortest-path-with-alternating-colors)", "[Shortest Path with Alternating Colors](/solution/1100-1199/1129.Shortest%20Path%20with%20Alternating%20Colors/README_EN.md)", "`Breadth-first Search`,`Graph`", "Medium", ""]}, {"question_id": "1228", "frontend_question_id": "1130", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-cost-tree-from-leaf-values", "url_en": "https://leetcode.com/problems/minimum-cost-tree-from-leaf-values", "relative_path_cn": "/solution/1100-1199/1130.Minimum%20Cost%20Tree%20From%20Leaf%20Values/README.md", "relative_path_en": "/solution/1100-1199/1130.Minimum%20Cost%20Tree%20From%20Leaf%20Values/README_EN.md", "title_cn": "\u53f6\u503c\u7684\u6700\u5c0f\u4ee3\u4ef7\u751f\u6210\u6811", "title_en": "Minimum Cost Tree From Leaf Values", "question_title_slug": "minimum-cost-tree-from-leaf-values", "content_en": "

Given an array arr of positive integers, consider all binary trees such that:

\r\n\r\n
    \r\n\t
  • Each node has either 0 or 2 children;
  • \r\n\t
  • The values of arr correspond to the values of each leaf in an in-order traversal of the tree.  (Recall that a node is a leaf if and only if it has 0 children.)
  • \r\n\t
  • The value of each non-leaf node is equal to the product of the largest leaf value in its left and right subtree respectively.
  • \r\n
\r\n\r\n

Among all possible binary trees considered, return the smallest possible sum of the values of each non-leaf node.  It is guaranteed this sum fits into a 32-bit integer.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: arr = [6,2,4]\r\nOutput: 32\r\nExplanation:\r\nThere are two possible trees.  The first has non-leaf node sum 36, and the second has non-leaf node sum 32.\r\n\r\n    24            24\r\n   /  \\          /  \\\r\n  12   4        6    8\r\n /  \\               / \\\r\n6    2             2   4\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 2 <= arr.length <= 40
  • \r\n\t
  • 1 <= arr[i] <= 15
  • \r\n\t
  • It is guaranteed that the answer fits into a 32-bit signed integer (ie. it is less than 2^31).
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6b63\u6574\u6570\u6570\u7ec4 arr\uff0c\u8003\u8651\u6240\u6709\u6ee1\u8db3\u4ee5\u4e0b\u6761\u4ef6\u7684\u4e8c\u53c9\u6811\uff1a

\n\n
    \n\t
  • \u6bcf\u4e2a\u8282\u70b9\u90fd\u6709 0 \u4e2a\u6216\u662f 2 \u4e2a\u5b50\u8282\u70b9\u3002
  • \n\t
  • \u6570\u7ec4 arr \u4e2d\u7684\u503c\u4e0e\u6811\u7684\u4e2d\u5e8f\u904d\u5386\u4e2d\u6bcf\u4e2a\u53f6\u8282\u70b9\u7684\u503c\u4e00\u4e00\u5bf9\u5e94\u3002\uff08\u77e5\u8bc6\u56de\u987e\uff1a\u5982\u679c\u4e00\u4e2a\u8282\u70b9\u6709 0 \u4e2a\u5b50\u8282\u70b9\uff0c\u90a3\u4e48\u8be5\u8282\u70b9\u4e3a\u53f6\u8282\u70b9\u3002\uff09
  • \n\t
  • \u6bcf\u4e2a\u975e\u53f6\u8282\u70b9\u7684\u503c\u7b49\u4e8e\u5176\u5de6\u5b50\u6811\u548c\u53f3\u5b50\u6811\u4e2d\u53f6\u8282\u70b9\u7684\u6700\u5927\u503c\u7684\u4e58\u79ef\u3002
  • \n
\n\n

\u5728\u6240\u6709\u8fd9\u6837\u7684\u4e8c\u53c9\u6811\u4e2d\uff0c\u8fd4\u56de\u6bcf\u4e2a\u975e\u53f6\u8282\u70b9\u7684\u503c\u7684\u6700\u5c0f\u53ef\u80fd\u603b\u548c\u3002\u8fd9\u4e2a\u548c\u7684\u503c\u662f\u4e00\u4e2a 32 \u4f4d\u6574\u6570\u3002

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1aarr = [6,2,4]\n\u8f93\u51fa\uff1a32\n\u89e3\u91ca\uff1a\n\u6709\u4e24\u79cd\u53ef\u80fd\u7684\u6811\uff0c\u7b2c\u4e00\u79cd\u7684\u975e\u53f6\u8282\u70b9\u7684\u603b\u548c\u4e3a 36\uff0c\u7b2c\u4e8c\u79cd\u975e\u53f6\u8282\u70b9\u7684\u603b\u548c\u4e3a 32\u3002\n\n    24            24\n   /  \\          /  \\\n  12   4        6    8\n /  \\               / \\\n6    2             2   4
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= arr.length <= 40
  • \n\t
  • 1 <= arr[i] <= 15
  • \n\t
  • \u7b54\u6848\u4fdd\u8bc1\u662f\u4e00\u4e2a 32 \u4f4d\u5e26\u7b26\u53f7\u6574\u6570\uff0c\u5373\u5c0f\u4e8e 2^31\u3002
  • \n
\n", "tags_en": ["Stack", "Tree", "Dynamic Programming"], "tags_cn": ["\u6808", "\u6811", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int mctFromLeafValues(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int mctFromLeafValues(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def mctFromLeafValues(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def mctFromLeafValues(self, arr: List[int]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint mctFromLeafValues(int* arr, int arrSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MctFromLeafValues(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar mctFromLeafValues = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef mct_from_leaf_values(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func mctFromLeafValues(_ arr: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func mctFromLeafValues(arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def mctFromLeafValues(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun mctFromLeafValues(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn mct_from_leaf_values(arr: Vec) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function mctFromLeafValues($arr) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function mctFromLeafValues(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (mct-from-leaf-values arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1130](https://leetcode-cn.com/problems/minimum-cost-tree-from-leaf-values)", "[\u53f6\u503c\u7684\u6700\u5c0f\u4ee3\u4ef7\u751f\u6210\u6811](/solution/1100-1199/1130.Minimum%20Cost%20Tree%20From%20Leaf%20Values/README.md)", "`\u6808`,`\u6811`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1130](https://leetcode.com/problems/minimum-cost-tree-from-leaf-values)", "[Minimum Cost Tree From Leaf Values](/solution/1100-1199/1130.Minimum%20Cost%20Tree%20From%20Leaf%20Values/README_EN.md)", "`Stack`,`Tree`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "1227", "frontend_question_id": "1128", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-equivalent-domino-pairs", "url_en": "https://leetcode.com/problems/number-of-equivalent-domino-pairs", "relative_path_cn": "/solution/1100-1199/1128.Number%20of%20Equivalent%20Domino%20Pairs/README.md", "relative_path_en": "/solution/1100-1199/1128.Number%20of%20Equivalent%20Domino%20Pairs/README_EN.md", "title_cn": "\u7b49\u4ef7\u591a\u7c73\u8bfa\u9aa8\u724c\u5bf9\u7684\u6570\u91cf", "title_en": "Number of Equivalent Domino Pairs", "question_title_slug": "number-of-equivalent-domino-pairs", "content_en": "

Given a list of dominoesdominoes[i] = [a, b] is equivalent to dominoes[j] = [c, d] if and only if either (a==c and b==d), or (a==d and b==c) - that is, one domino can be rotated to be equal to another domino.

\r\n\r\n

Return the number of pairs (i, j) for which 0 <= i < j < dominoes.length, and dominoes[i] is equivalent to dominoes[j].

\r\n\r\n

 

\r\n

Example 1:

\r\n
Input: dominoes = [[1,2],[2,1],[3,4],[5,6]]\r\nOutput: 1\r\n
\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= dominoes.length <= 40000
  • \r\n\t
  • 1 <= dominoes[i][j] <= 9
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u7531\u4e00\u4e9b\u591a\u7c73\u8bfa\u9aa8\u724c\u7ec4\u6210\u7684\u5217\u8868 dominoes\u3002

\n\n

\u5982\u679c\u5176\u4e2d\u67d0\u4e00\u5f20\u591a\u7c73\u8bfa\u9aa8\u724c\u53ef\u4ee5\u901a\u8fc7\u65cb\u8f6c 0 \u5ea6\u6216 180 \u5ea6\u5f97\u5230\u53e6\u4e00\u5f20\u591a\u7c73\u8bfa\u9aa8\u724c\uff0c\u6211\u4eec\u5c31\u8ba4\u4e3a\u8fd9\u4e24\u5f20\u724c\u662f\u7b49\u4ef7\u7684\u3002

\n\n

\u5f62\u5f0f\u4e0a\uff0cdominoes[i] = [a, b] \u548c dominoes[j] = [c, d] \u7b49\u4ef7\u7684\u524d\u63d0\u662f a==c \u4e14 b==d\uff0c\u6216\u662f a==d \u4e14 b==c\u3002

\n\n

\u5728 0 <= i < j < dominoes.length \u7684\u524d\u63d0\u4e0b\uff0c\u627e\u51fa\u6ee1\u8db3 dominoes[i] \u548c dominoes[j] \u7b49\u4ef7\u7684\u9aa8\u724c\u5bf9 (i, j) \u7684\u6570\u91cf\u3002

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1adominoes = [[1,2],[2,1],[3,4],[5,6]]\n\u8f93\u51fa\uff1a1\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= dominoes.length <= 40000
  • \n\t
  • 1 <= dominoes[i][j] <= 9
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numEquivDominoPairs(vector>& dominoes) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numEquivDominoPairs(int[][] dominoes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numEquivDominoPairs(self, dominoes):\n \"\"\"\n :type dominoes: List[List[int]]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numEquivDominoPairs(self, dominoes: List[List[int]]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numEquivDominoPairs(int** dominoes, int dominoesSize, int* dominoesColSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumEquivDominoPairs(int[][] dominoes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} dominoes\n * @return {number}\n */\nvar numEquivDominoPairs = function(dominoes) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} dominoes\n# @return {Integer}\ndef num_equiv_domino_pairs(dominoes)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numEquivDominoPairs(_ dominoes: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numEquivDominoPairs(dominoes [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numEquivDominoPairs(dominoes: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numEquivDominoPairs(dominoes: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_equiv_domino_pairs(dominoes: Vec>) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $dominoes\n * @return Integer\n */\n function numEquivDominoPairs($dominoes) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numEquivDominoPairs(dominoes: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-equiv-domino-pairs dominoes)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1128](https://leetcode-cn.com/problems/number-of-equivalent-domino-pairs)", "[\u7b49\u4ef7\u591a\u7c73\u8bfa\u9aa8\u724c\u5bf9\u7684\u6570\u91cf](/solution/1100-1199/1128.Number%20of%20Equivalent%20Domino%20Pairs/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1128](https://leetcode.com/problems/number-of-equivalent-domino-pairs)", "[Number of Equivalent Domino Pairs](/solution/1100-1199/1128.Number%20of%20Equivalent%20Domino%20Pairs/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1226", "frontend_question_id": "1127", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/user-purchase-platform", "url_en": "https://leetcode.com/problems/user-purchase-platform", "relative_path_cn": "/solution/1100-1199/1127.User%20Purchase%20Platform/README.md", "relative_path_en": "/solution/1100-1199/1127.User%20Purchase%20Platform/README_EN.md", "title_cn": "\u7528\u6237\u8d2d\u4e70\u5e73\u53f0", "title_en": "User Purchase Platform", "question_title_slug": "user-purchase-platform", "content_en": "

Table: Spending

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| user_id     | int     |\n| spend_date  | date    |\n| platform    | enum    | \n| amount      | int     |\n+-------------+---------+\nThe table logs the spendings history of users that make purchases from an online shopping website which has a desktop and a mobile application.\n(user_id, spend_date, platform) is the primary key of this table.\nThe platform column is an ENUM type of ('desktop', 'mobile').\n
\n\n

Write an SQL query to find the total number of users and the total amount spent using mobile only, desktop only and both mobile and desktop together for each date.

\n\n

The query result format is in the following example:

\n\n
\nSpending table:\n+---------+------------+----------+--------+\n| user_id | spend_date | platform | amount |\n+---------+------------+----------+--------+\n| 1       | 2019-07-01 | mobile   | 100    |\n| 1       | 2019-07-01 | desktop  | 100    |\n| 2       | 2019-07-01 | mobile   | 100    |\n| 2       | 2019-07-02 | mobile   | 100    |\n| 3       | 2019-07-01 | desktop  | 100    |\n| 3       | 2019-07-02 | desktop  | 100    |\n+---------+------------+----------+--------+\n\nResult table:\n+------------+----------+--------------+-------------+\n| spend_date | platform | total_amount | total_users |\n+------------+----------+--------------+-------------+\n| 2019-07-01 | desktop  | 100          | 1           |\n| 2019-07-01 | mobile   | 100          | 1           |\n| 2019-07-01 | both     | 200          | 1           |\n| 2019-07-02 | desktop  | 100          | 1           |\n| 2019-07-02 | mobile   | 100          | 1           |\n| 2019-07-02 | both     | 0            | 0           |\n+------------+----------+--------------+-------------+ \nOn 2019-07-01, user 1 purchased using both desktop and mobile, user 2 purchased using mobile only and user 3 purchased using desktop only.\nOn 2019-07-02, user 2 purchased using mobile only, user 3 purchased using desktop only and no one purchased using both platforms.
\n", "content_cn": "

\u652f\u51fa\u8868: Spending

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| user_id     | int     |\n| spend_date  | date    |\n| platform    | enum    | \n| amount      | int     |\n+-------------+---------+\n\u8fd9\u5f20\u8868\u8bb0\u5f55\u4e86\u7528\u6237\u5728\u4e00\u4e2a\u5728\u7ebf\u8d2d\u7269\u7f51\u7ad9\u7684\u652f\u51fa\u5386\u53f2\uff0c\u8be5\u5728\u7ebf\u8d2d\u7269\u5e73\u53f0\u540c\u65f6\u62e5\u6709\u684c\u9762\u7aef\uff08'desktop'\uff09\u548c\u624b\u673a\u7aef\uff08'mobile'\uff09\u7684\u5e94\u7528\u7a0b\u5e8f\u3002\n\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\u662f (user_id, spend_date, platform)\u3002\n\u5e73\u53f0\u5217 platform \u662f\u4e00\u79cd ENUM \uff0c\u7c7b\u578b\u4e3a\uff08'desktop', 'mobile'\uff09\u3002
\n\n

 

\n\n

\u5199\u4e00\u6bb5 SQL \u6765\u67e5\u627e\u6bcf\u5929 \u4ec5 \u4f7f\u7528\u624b\u673a\u7aef\u7528\u6237\u3001\u4ec5 \u4f7f\u7528\u684c\u9762\u7aef\u7528\u6237\u548c \u540c\u65f6 \u4f7f\u7528\u684c\u9762\u7aef\u548c\u624b\u673a\u7aef\u7684\u7528\u6237\u4eba\u6570\u548c\u603b\u652f\u51fa\u91d1\u989d\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a\uff1a

\n\n
\nSpending table:\n+---------+------------+----------+--------+\n| user_id | spend_date | platform | amount |\n+---------+------------+----------+--------+\n| 1       | 2019-07-01 | mobile   | 100    |\n| 1       | 2019-07-01 | desktop  | 100    |\n| 2       | 2019-07-01 | mobile   | 100    |\n| 2       | 2019-07-02 | mobile   | 100    |\n| 3       | 2019-07-01 | desktop  | 100    |\n| 3       | 2019-07-02 | desktop  | 100    |\n+---------+------------+----------+--------+\n\nResult table:\n+------------+----------+--------------+-------------+\n| spend_date | platform | total_amount | total_users |\n+------------+----------+--------------+-------------+\n| 2019-07-01 | desktop  | 100          | 1           |\n| 2019-07-01 | mobile   | 100          | 1           |\n| 2019-07-01 | both     | 200          | 1           |\n| 2019-07-02 | desktop  | 100          | 1           |\n| 2019-07-02 | mobile   | 100          | 1           |\n| 2019-07-02 | both     | 0            | 0           |\n+------------+----------+--------------+-------------+ \n\u5728 2019-07-01, \u7528\u62371 \u540c\u65f6 \u4f7f\u7528\u684c\u9762\u7aef\u548c\u624b\u673a\u7aef\u8d2d\u4e70, \u7528\u62372 \u4ec5 \u4f7f\u7528\u4e86\u624b\u673a\u7aef\u8d2d\u4e70\uff0c\u800c\u7528\u62373 \u4ec5 \u4f7f\u7528\u4e86\u684c\u9762\u7aef\u8d2d\u4e70\u3002\n\u5728 2019-07-02, \u7528\u62372 \u4ec5 \u4f7f\u7528\u4e86\u624b\u673a\u7aef\u8d2d\u4e70, \u7528\u62373 \u4ec5 \u4f7f\u7528\u4e86\u684c\u9762\u7aef\u8d2d\u4e70\uff0c\u4e14\u6ca1\u6709\u7528\u6237 \u540c\u65f6 \u4f7f\u7528\u684c\u9762\u7aef\u548c\u624b\u673a\u7aef\u8d2d\u4e70\u3002
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1127](https://leetcode-cn.com/problems/user-purchase-platform)", "[\u7528\u6237\u8d2d\u4e70\u5e73\u53f0](/solution/1100-1199/1127.User%20Purchase%20Platform/README.md)", "", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1127](https://leetcode.com/problems/user-purchase-platform)", "[User Purchase Platform](/solution/1100-1199/1127.User%20Purchase%20Platform/README_EN.md)", "", "Hard", "\ud83d\udd12"]}, {"question_id": "1225", "frontend_question_id": "1126", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/active-businesses", "url_en": "https://leetcode.com/problems/active-businesses", "relative_path_cn": "/solution/1100-1199/1126.Active%20Businesses/README.md", "relative_path_en": "/solution/1100-1199/1126.Active%20Businesses/README_EN.md", "title_cn": "\u67e5\u8be2\u6d3b\u8dc3\u4e1a\u52a1", "title_en": "Active Businesses", "question_title_slug": "active-businesses", "content_en": "

Table: Events

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| business_id   | int     |\n| event_type    | varchar |\n| occurences    | int     | \n+---------------+---------+\n(business_id, event_type) is the primary key of this table.\nEach row in the table logs the info that an event of some type occured at some business for a number of times.
\n\n

 

\n\n

Write an SQL query to find all active businesses.

\n\n

An active business is a business that has more than one event type with occurences greater than the average occurences of that event type among all businesses.

\n\n

The query result format is in the following example:

\n\n
\nEvents table:\n+-------------+------------+------------+\n| business_id | event_type | occurences |\n+-------------+------------+------------+\n| 1           | reviews    | 7          |\n| 3           | reviews    | 3          |\n| 1           | ads        | 11         |\n| 2           | ads        | 7          |\n| 3           | ads        | 6          |\n| 1           | page views | 3          |\n| 2           | page views | 12         |\n+-------------+------------+------------+\n\nResult table:\n+-------------+\n| business_id |\n+-------------+\n| 1           |\n+-------------+ \nAverage for 'reviews', 'ads' and 'page views' are (7+3)/2=5, (11+7+6)/3=8, (3+12)/2=7.5 respectively.\nBusiness with id 1 has 7 'reviews' events (more than 5) and 11 'ads' events (more than 8) so it is an active business.
\n", "content_cn": "

\u4e8b\u4ef6\u8868\uff1aEvents

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| business_id   | int     |\n| event_type    | varchar |\n| occurences    | int     | \n+---------------+---------+\n\u6b64\u8868\u7684\u4e3b\u952e\u662f (business_id, event_type)\u3002\n\u8868\u4e2d\u7684\u6bcf\u4e00\u884c\u8bb0\u5f55\u4e86\u67d0\u79cd\u7c7b\u578b\u7684\u4e8b\u4ef6\u5728\u67d0\u4e9b\u4e1a\u52a1\u4e2d\u591a\u6b21\u53d1\u751f\u7684\u4fe1\u606f\u3002\n
\n\n

 

\n\n

\u5199\u4e00\u6bb5 SQL \u6765\u67e5\u8be2\u6240\u6709\u6d3b\u8dc3\u7684\u4e1a\u52a1\u3002

\n\n

\u5982\u679c\u4e00\u4e2a\u4e1a\u52a1\u7684\u67d0\u4e2a\u4e8b\u4ef6\u7c7b\u578b\u7684\u53d1\u751f\u6b21\u6570\u5927\u4e8e\u6b64\u4e8b\u4ef6\u7c7b\u578b\u5728\u6240\u6709\u4e1a\u52a1\u4e2d\u7684\u5e73\u5747\u53d1\u751f\u6b21\u6570\uff0c\u5e76\u4e14\u8be5\u4e1a\u52a1\u81f3\u5c11\u6709\u4e24\u4e2a\u8fd9\u6837\u7684\u4e8b\u4ef6\u7c7b\u578b\uff0c\u90a3\u4e48\u8be5\u4e1a\u52a1\u5c31\u53ef\u88ab\u770b\u505a\u662f\u6d3b\u8dc3\u4e1a\u52a1\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u6240\u793a\uff1a

\n\n
\nEvents table:\n+-------------+------------+------------+\n| business_id | event_type | occurences |\n+-------------+------------+------------+\n| 1           | reviews    | 7          |\n| 3           | reviews    | 3          |\n| 1           | ads        | 11         |\n| 2           | ads        | 7          |\n| 3           | ads        | 6          |\n| 1           | page views | 3          |\n| 2           | page views | 12         |\n+-------------+------------+------------+\n\n\u7ed3\u679c\u8868\n+-------------+\n| business_id |\n+-------------+\n| 1           |\n+-------------+ \n'reviews'\u3001 'ads' \u548c 'page views' \u7684\u603b\u5e73\u5747\u53d1\u751f\u6b21\u6570\u5206\u522b\u662f (7+3)/2=5, (11+7+6)/3=8, (3+12)/2=7.5\u3002\nid \u4e3a 1 \u7684\u4e1a\u52a1\u6709 7 \u4e2a 'reviews' \u4e8b\u4ef6\uff08\u5927\u4e8e 5\uff09\u548c 11 \u4e2a 'ads' \u4e8b\u4ef6\uff08\u5927\u4e8e 8\uff09\uff0c\u6240\u4ee5\u5b83\u662f\u6d3b\u8dc3\u4e1a\u52a1\u3002
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1126](https://leetcode-cn.com/problems/active-businesses)", "[\u67e5\u8be2\u6d3b\u8dc3\u4e1a\u52a1](/solution/1100-1199/1126.Active%20Businesses/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1126](https://leetcode.com/problems/active-businesses)", "[Active Businesses](/solution/1100-1199/1126.Active%20Businesses/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1224", "frontend_question_id": "1289", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-falling-path-sum-ii", "url_en": "https://leetcode.com/problems/minimum-falling-path-sum-ii", "relative_path_cn": "/solution/1200-1299/1289.Minimum%20Falling%20Path%20Sum%20II/README.md", "relative_path_en": "/solution/1200-1299/1289.Minimum%20Falling%20Path%20Sum%20II/README_EN.md", "title_cn": "\u4e0b\u964d\u8def\u5f84\u6700\u5c0f\u548c II", "title_en": "Minimum Falling Path Sum II", "question_title_slug": "minimum-falling-path-sum-ii", "content_en": "

Given a square grid of integers arr, a falling path with non-zero shifts is a choice of exactly one element from each row of arr, such that no two elements chosen in adjacent rows are in the same column.

\n\n

Return the minimum sum of a falling path with non-zero shifts.

\n\n

 

\n

Example 1:

\n\n
\nInput: arr = [[1,2,3],[4,5,6],[7,8,9]]\nOutput: 13\nExplanation: \nThe possible falling paths are:\n[1,5,9], [1,5,7], [1,6,7], [1,6,8],\n[2,4,8], [2,4,9], [2,6,7], [2,6,8],\n[3,4,8], [3,4,9], [3,5,7], [3,5,9]\nThe falling path with the smallest sum is [1,5,7], so the answer is 13.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= arr.length == arr[i].length <= 200
  • \n\t
  • -99 <= arr[i][j] <= 99
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u65b9\u9635 arr \uff0c\u5b9a\u4e49\u300c\u975e\u96f6\u504f\u79fb\u4e0b\u964d\u8def\u5f84\u300d\u4e3a\uff1a\u4ece arr \u6570\u7ec4\u4e2d\u7684\u6bcf\u4e00\u884c\u9009\u62e9\u4e00\u4e2a\u6570\u5b57\uff0c\u4e14\u6309\u987a\u5e8f\u9009\u51fa\u6765\u7684\u6570\u5b57\u4e2d\uff0c\u76f8\u90bb\u6570\u5b57\u4e0d\u5728\u539f\u6570\u7ec4\u7684\u540c\u4e00\u5217\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u975e\u96f6\u504f\u79fb\u4e0b\u964d\u8def\u5f84\u6570\u5b57\u548c\u7684\u6700\u5c0f\u503c\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [[1,2,3],[4,5,6],[7,8,9]]\n\u8f93\u51fa\uff1a13\n\u89e3\u91ca\uff1a\n\u6240\u6709\u975e\u96f6\u504f\u79fb\u4e0b\u964d\u8def\u5f84\u5305\u62ec\uff1a\n[1,5,9], [1,5,7], [1,6,7], [1,6,8],\n[2,4,8], [2,4,9], [2,6,7], [2,6,8],\n[3,4,8], [3,4,9], [3,5,7], [3,5,9]\n\u4e0b\u964d\u8def\u5f84\u4e2d\u6570\u5b57\u548c\u6700\u5c0f\u7684\u662f [1,5,7] \uff0c\u6240\u4ee5\u7b54\u6848\u662f 13 \u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= arr.length == arr[i].length <= 200
  • \n\t
  • -99 <= arr[i][j] <= 99
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minFallingPathSum(vector>& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minFallingPathSum(int[][] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minFallingPathSum(self, arr):\n \"\"\"\n :type arr: List[List[int]]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minFallingPathSum(self, arr: List[List[int]]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minFallingPathSum(int** arr, int arrSize, int* arrColSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinFallingPathSum(int[][] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} arr\n * @return {number}\n */\nvar minFallingPathSum = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} arr\n# @return {Integer}\ndef min_falling_path_sum(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minFallingPathSum(_ arr: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minFallingPathSum(arr [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minFallingPathSum(arr: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minFallingPathSum(arr: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_falling_path_sum(arr: Vec>) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $arr\n * @return Integer\n */\n function minFallingPathSum($arr) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minFallingPathSum(arr: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-falling-path-sum arr)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1289](https://leetcode-cn.com/problems/minimum-falling-path-sum-ii)", "[\u4e0b\u964d\u8def\u5f84\u6700\u5c0f\u548c II](/solution/1200-1299/1289.Minimum%20Falling%20Path%20Sum%20II/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1289](https://leetcode.com/problems/minimum-falling-path-sum-ii)", "[Minimum Falling Path Sum II](/solution/1200-1299/1289.Minimum%20Falling%20Path%20Sum%20II/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1223", "frontend_question_id": "1627", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/graph-connectivity-with-threshold", "url_en": "https://leetcode.com/problems/graph-connectivity-with-threshold", "relative_path_cn": "/solution/1600-1699/1627.Graph%20Connectivity%20With%20Threshold/README.md", "relative_path_en": "/solution/1600-1699/1627.Graph%20Connectivity%20With%20Threshold/README_EN.md", "title_cn": "\u5e26\u9608\u503c\u7684\u56fe\u8fde\u901a\u6027", "title_en": "Graph Connectivity With Threshold", "question_title_slug": "graph-connectivity-with-threshold", "content_en": "

We have n cities labeled from 1 to n. Two different cities with labels x and y are directly connected by a bidirectional road if and only if x and y share a common divisor strictly greater than some threshold. More formally, cities with labels x and y have a road between them if there exists an integer z such that all of the following are true:

\n\n
    \n\t
  • x % z == 0,
  • \n\t
  • y % z == 0, and
  • \n\t
  • z > threshold.
  • \n
\n\n

Given the two integers, n and threshold, and an array of queries, you must determine for each queries[i] = [ai, bi] if cities ai and bi are connected directly or indirectly. (i.e. there is some path between them).

\n\n

Return an array answer, where answer.length == queries.length and answer[i] is true if for the ith query, there is a path between ai and bi, or answer[i] is false if there is no path.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: n = 6, threshold = 2, queries = [[1,4],[2,5],[3,6]]\nOutput: [false,false,true]\nExplanation: The divisors for each number:\n1:   1\n2:   1, 2\n3:   1, 3\n4:   1, 2, 4\n5:   1, 5\n6:   1, 2, 3, 6\nUsing the underlined divisors above the threshold, only cities 3 and 6 share a common divisor, so they are the\nonly ones directly connected. The result of each query:\n[1,4]   1 is not connected to 4\n[2,5]   2 is not connected to 5\n[3,6]   3 is connected to 6 through path 3--6\n
\n\n

Example 2:

\n\"\"\n
\nInput: n = 6, threshold = 0, queries = [[4,5],[3,4],[3,2],[2,6],[1,3]]\nOutput: [true,true,true,true,true]\nExplanation: The divisors for each number are the same as the previous example. However, since the threshold is 0,\nall divisors can be used. Since all numbers share 1 as a divisor, all cities are connected.\n
\n\n

Example 3:

\n\"\"\n
\nInput: n = 5, threshold = 1, queries = [[4,5],[4,5],[3,2],[2,3],[3,4]]\nOutput: [false,false,false,false,false]\nExplanation: Only cities 2 and 4 share a common divisor 2 which is strictly greater than the threshold 1, so they are the only ones directly connected.\nPlease notice that there can be multiple queries for the same pair of nodes [x, y], and that the query [x, y] is equivalent to the query [y, x].\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= n <= 104
  • \n\t
  • 0 <= threshold <= n
  • \n\t
  • 1 <= queries.length <= 105
  • \n\t
  • queries[i].length == 2
  • \n\t
  • 1 <= ai, bi <= cities
  • \n\t
  • ai != bi
  • \n
\n", "content_cn": "

\u6709 n \u5ea7\u57ce\u5e02\uff0c\u7f16\u53f7\u4ece 1 \u5230 n \u3002\u7f16\u53f7\u4e3a x \u548c y \u7684\u4e24\u5ea7\u57ce\u5e02\u76f4\u63a5\u8fde\u901a\u7684\u524d\u63d0\u662f\uff1a x \u548c y \u7684\u516c\u56e0\u6570\u4e2d\uff0c\u81f3\u5c11\u6709\u4e00\u4e2a \u4e25\u683c\u5927\u4e8e \u67d0\u4e2a\u9608\u503c threshold \u3002\u66f4\u6b63\u5f0f\u5730\u8bf4\uff0c\u5982\u679c\u5b58\u5728\u6574\u6570 z \uff0c\u4e14\u6ee1\u8db3\u4ee5\u4e0b\u6240\u6709\u6761\u4ef6\uff0c\u5219\u7f16\u53f7 x \u548c y \u7684\u57ce\u5e02\u4e4b\u95f4\u6709\u4e00\u6761\u9053\u8def\uff1a

\n\n
    \n\t
  • x % z == 0
  • \n\t
  • y % z == 0
  • \n\t
  • z > threshold
  • \n
\n\n

\u7ed9\u4f60\u4e24\u4e2a\u6574\u6570 n \u548c threshold \uff0c\u4ee5\u53ca\u4e00\u4e2a\u5f85\u67e5\u8be2\u6570\u7ec4\uff0c\u8bf7\u4f60\u5224\u65ad\u6bcf\u4e2a\u67e5\u8be2 queries[i] = [ai, bi] \u6307\u5411\u7684\u57ce\u5e02 ai \u548c bi \u662f\u5426\u8fde\u901a\uff08\u5373\uff0c\u5b83\u4eec\u4e4b\u95f4\u662f\u5426\u5b58\u5728\u4e00\u6761\u8def\u5f84\uff09\u3002

\n\n

\u8fd4\u56de\u6570\u7ec4 answer \uff0c\u5176\u4e2danswer.length == queries.length \u3002\u5982\u679c\u7b2c i \u4e2a\u67e5\u8be2\u4e2d\u6307\u5411\u7684\u57ce\u5e02 ai \u548c bi \u8fde\u901a\uff0c\u5219 answer[i] \u4e3a true \uff1b\u5982\u679c\u4e0d\u8fde\u901a\uff0c\u5219 answer[i] \u4e3a false \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n

\u00a0

\n\n
\n\u8f93\u5165\uff1an = 6, threshold = 2, queries = [[1,4],[2,5],[3,6]]\n\u8f93\u51fa\uff1a[false,false,true]\n\u89e3\u91ca\uff1a\u6bcf\u4e2a\u6570\u7684\u56e0\u6570\u5982\u4e0b\uff1a\n1:   1\n2:   1, 2\n3:   1, 3\n4:   1, 2, 4\n5:   1, 5\n6:   1, 2, 3, 6\n\u6240\u6709\u5927\u4e8e\u9608\u503c\u7684\u7684\u56e0\u6570\u5df2\u7ecf\u52a0\u7c97\u6807\u8bc6\uff0c\u53ea\u6709\u57ce\u5e02 3 \u548c 6 \u5171\u4eab\u516c\u7ea6\u6570 3 \uff0c\u56e0\u6b64\u7ed3\u679c\u662f\uff1a \n[1,4]   1 \u4e0e 4 \u4e0d\u8fde\u901a\n[2,5]   2 \u4e0e 5 \u4e0d\u8fde\u901a\n[3,6]   3 \u4e0e 6 \u8fde\u901a\uff0c\u5b58\u5728\u8def\u5f84 3--6\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n

\u00a0

\n\n
\n\u8f93\u5165\uff1an = 6, threshold = 0, queries = [[4,5],[3,4],[3,2],[2,6],[1,3]]\n\u8f93\u51fa\uff1a[true,true,true,true,true]\n\u89e3\u91ca\uff1a\u6bcf\u4e2a\u6570\u7684\u56e0\u6570\u4e0e\u4e0a\u4e00\u4e2a\u4f8b\u5b50\u76f8\u540c\u3002\u4f46\u662f\uff0c\u7531\u4e8e\u9608\u503c\u4e3a 0 \uff0c\u6240\u6709\u7684\u56e0\u6570\u90fd\u5927\u4e8e\u9608\u503c\u3002\u56e0\u4e3a\u6240\u6709\u7684\u6570\u5b57\u5171\u4eab\u516c\u56e0\u6570 1 \uff0c\u6240\u4ee5\u6240\u6709\u7684\u57ce\u5e02\u90fd\u4e92\u76f8\u8fde\u901a\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n

\"\"

\n\n

\u00a0

\n\n
\n\u8f93\u5165\uff1an = 5, threshold = 1, queries = [[4,5],[4,5],[3,2],[2,3],[3,4]]\n\u8f93\u51fa\uff1a[false,false,false,false,false]\n\u89e3\u91ca\uff1a\u53ea\u6709\u57ce\u5e02 2 \u548c 4 \u5171\u4eab\u7684\u516c\u7ea6\u6570 2 \u4e25\u683c\u5927\u4e8e\u9608\u503c 1 \uff0c\u6240\u4ee5\u53ea\u6709\u8fd9\u4e24\u5ea7\u57ce\u5e02\u662f\u8fde\u901a\u7684\u3002\n\u6ce8\u610f\uff0c\u540c\u4e00\u5bf9\u8282\u70b9 [x, y] \u53ef\u4ee5\u6709\u591a\u4e2a\u67e5\u8be2\uff0c\u5e76\u4e14\u67e5\u8be2 [x\uff0cy] \u7b49\u540c\u4e8e\u67e5\u8be2 [y\uff0cx] \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= n <= 104
  • \n\t
  • 0 <= threshold <= n
  • \n\t
  • 1 <= queries.length <= 105
  • \n\t
  • queries[i].length == 2
  • \n\t
  • 1 <= ai, bi <= cities
  • \n\t
  • ai != bi
  • \n
\n", "tags_en": ["Union Find", "Math"], "tags_cn": ["\u5e76\u67e5\u96c6", "\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector areConnected(int n, int threshold, vector>& queries) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List areConnected(int n, int threshold, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def areConnected(self, n, threshold, queries):\n \"\"\"\n :type n: int\n :type threshold: int\n :type queries: List[List[int]]\n :rtype: List[bool]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def areConnected(self, n: int, threshold: int, queries: List[List[int]]) -> List[bool]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nbool* areConnected(int n, int threshold, int** queries, int queriesSize, int* queriesColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList AreConnected(int n, int threshold, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} threshold\n * @param {number[][]} queries\n * @return {boolean[]}\n */\nvar areConnected = function(n, threshold, queries) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} threshold\n# @param {Integer[][]} queries\n# @return {Boolean[]}\ndef are_connected(n, threshold, queries)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func areConnected(_ n: Int, _ threshold: Int, _ queries: [[Int]]) -> [Bool] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func areConnected(n int, threshold int, queries [][]int) []bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def areConnected(n: Int, threshold: Int, queries: Array[Array[Int]]): List[Boolean] = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun areConnected(n: Int, threshold: Int, queries: Array): List {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn are_connected(n: i32, threshold: i32, queries: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $threshold\n * @param Integer[][] $queries\n * @return Boolean[]\n */\n function areConnected($n, $threshold, $queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function areConnected(n: number, threshold: number, queries: number[][]): boolean[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (are-connected n threshold queries)\n (-> exact-integer? exact-integer? (listof (listof exact-integer?)) (listof boolean?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1627](https://leetcode-cn.com/problems/graph-connectivity-with-threshold)", "[\u5e26\u9608\u503c\u7684\u56fe\u8fde\u901a\u6027](/solution/1600-1699/1627.Graph%20Connectivity%20With%20Threshold/README.md)", "`\u5e76\u67e5\u96c6`,`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[1627](https://leetcode.com/problems/graph-connectivity-with-threshold)", "[Graph Connectivity With Threshold](/solution/1600-1699/1627.Graph%20Connectivity%20With%20Threshold/README_EN.md)", "`Union Find`,`Math`", "Hard", ""]}, {"question_id": "1222", "frontend_question_id": "1288", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/remove-covered-intervals", "url_en": "https://leetcode.com/problems/remove-covered-intervals", "relative_path_cn": "/solution/1200-1299/1288.Remove%20Covered%20Intervals/README.md", "relative_path_en": "/solution/1200-1299/1288.Remove%20Covered%20Intervals/README_EN.md", "title_cn": "\u5220\u9664\u88ab\u8986\u76d6\u533a\u95f4", "title_en": "Remove Covered Intervals", "question_title_slug": "remove-covered-intervals", "content_en": "

Given a list of intervals, remove all intervals that are covered by another interval in the list.

\r\n\r\n

Interval [a,b) is covered by interval [c,d) if and only if c <= a and b <= d.

\r\n\r\n

After doing so, return the number of remaining intervals.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: intervals = [[1,4],[3,6],[2,8]]\r\nOutput: 2\r\nExplanation: Interval [3,6] is covered by [2,8], therefore it is removed.\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: intervals = [[1,4],[2,3]]\r\nOutput: 1\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: intervals = [[0,10],[5,12]]\r\nOutput: 2\r\n
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: intervals = [[3,10],[4,10],[5,11]]\r\nOutput: 2\r\n
\r\n\r\n

Example 5:

\r\n\r\n
\r\nInput: intervals = [[1,2],[1,4],[3,4]]\r\nOutput: 1\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 1 <= intervals.length <= 1000
  • \r\n\t
  • intervals[i].length == 2
  • \r\n\t
  • 0 <= intervals[i][0] < intervals[i][1] <= 10^5
  • \r\n\t
  • All the intervals are unique.
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u533a\u95f4\u5217\u8868\uff0c\u8bf7\u4f60\u5220\u9664\u5217\u8868\u4e2d\u88ab\u5176\u4ed6\u533a\u95f4\u6240\u8986\u76d6\u7684\u533a\u95f4\u3002

\n\n

\u53ea\u6709\u5f53 c <= a \u4e14 b <= d \u65f6\uff0c\u6211\u4eec\u624d\u8ba4\u4e3a\u533a\u95f4 [a,b) \u88ab\u533a\u95f4 [c,d) \u8986\u76d6\u3002

\n\n

\u5728\u5b8c\u6210\u6240\u6709\u5220\u9664\u64cd\u4f5c\u540e\uff0c\u8bf7\u4f60\u8fd4\u56de\u5217\u8868\u4e2d\u5269\u4f59\u533a\u95f4\u7684\u6570\u76ee\u3002

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\n\u8f93\u5165\uff1aintervals = [[1,4],[3,6],[2,8]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u533a\u95f4 [3,6] \u88ab\u533a\u95f4 [2,8] \u8986\u76d6\uff0c\u6240\u4ee5\u5b83\u88ab\u5220\u9664\u4e86\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a\u200b\u200b\u200b\u200b\u200b\u200b

\n\n
    \n\t
  • 1 <= intervals.length <= 1000
  • \n\t
  • 0 <= intervals[i][0] < intervals[i][1] <= 10^5
  • \n\t
  • \u5bf9\u4e8e\u6240\u6709\u7684 i != j\uff1aintervals[i] != intervals[j]
  • \n
\n", "tags_en": ["Greedy", "Sort", "Line Sweep"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6392\u5e8f"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int removeCoveredIntervals(vector>& intervals) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int removeCoveredIntervals(int[][] intervals) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def removeCoveredIntervals(self, intervals):\n \"\"\"\n :type intervals: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint removeCoveredIntervals(int** intervals, int intervalsSize, int* intervalsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int RemoveCoveredIntervals(int[][] intervals) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} intervals\n * @return {number}\n */\nvar removeCoveredIntervals = function(intervals) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} intervals\n# @return {Integer}\ndef remove_covered_intervals(intervals)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func removeCoveredIntervals(_ intervals: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func removeCoveredIntervals(intervals [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def removeCoveredIntervals(intervals: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun removeCoveredIntervals(intervals: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn remove_covered_intervals(intervals: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $intervals\n * @return Integer\n */\n function removeCoveredIntervals($intervals) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function removeCoveredIntervals(intervals: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (remove-covered-intervals intervals)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1288](https://leetcode-cn.com/problems/remove-covered-intervals)", "[\u5220\u9664\u88ab\u8986\u76d6\u533a\u95f4](/solution/1200-1299/1288.Remove%20Covered%20Intervals/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6392\u5e8f`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1288](https://leetcode.com/problems/remove-covered-intervals)", "[Remove Covered Intervals](/solution/1200-1299/1288.Remove%20Covered%20Intervals/README_EN.md)", "`Greedy`,`Sort`,`Line Sweep`", "Medium", ""]}, {"question_id": "1221", "frontend_question_id": "1287", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/element-appearing-more-than-25-in-sorted-array", "url_en": "https://leetcode.com/problems/element-appearing-more-than-25-in-sorted-array", "relative_path_cn": "/solution/1200-1299/1287.Element%20Appearing%20More%20Than%2025%25%20In%20Sorted%20Array/README.md", "relative_path_en": "/solution/1200-1299/1287.Element%20Appearing%20More%20Than%2025%25%20In%20Sorted%20Array/README_EN.md", "title_cn": "\u6709\u5e8f\u6570\u7ec4\u4e2d\u51fa\u73b0\u6b21\u6570\u8d85\u8fc725%\u7684\u5143\u7d20", "title_en": "Element Appearing More Than 25% In Sorted Array", "question_title_slug": "element-appearing-more-than-25-in-sorted-array", "content_en": "

Given an integer array sorted in non-decreasing order, there is exactly one integer in the array that occurs more than 25% of the time, return that integer.

\n\n

 

\n

Example 1:

\n\n
\nInput: arr = [1,2,2,6,6,6,6,7,10]\nOutput: 6\n
\n\n

Example 2:

\n\n
\nInput: arr = [1,1]\nOutput: 1\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= arr.length <= 104
  • \n\t
  • 0 <= arr[i] <= 105
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u975e\u9012\u51cf\u7684 \u6709\u5e8f \u6574\u6570\u6570\u7ec4\uff0c\u5df2\u77e5\u8fd9\u4e2a\u6570\u7ec4\u4e2d\u6070\u597d\u6709\u4e00\u4e2a\u6574\u6570\uff0c\u5b83\u7684\u51fa\u73b0\u6b21\u6570\u8d85\u8fc7\u6570\u7ec4\u5143\u7d20\u603b\u6570\u7684 25%\u3002

\n\n

\u8bf7\u4f60\u627e\u5230\u5e76\u8fd4\u56de\u8fd9\u4e2a\u6574\u6570

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [1,2,2,6,6,6,6,7,10]\n\u8f93\u51fa\uff1a6\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= arr.length <= 10^4
  • \n\t
  • 0 <= arr[i] <= 10^5
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findSpecialInteger(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findSpecialInteger(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findSpecialInteger(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findSpecialInteger(self, arr: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findSpecialInteger(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindSpecialInteger(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar findSpecialInteger = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef find_special_integer(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findSpecialInteger(_ arr: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findSpecialInteger(arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findSpecialInteger(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findSpecialInteger(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_special_integer(arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function findSpecialInteger($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findSpecialInteger(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-special-integer arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1287](https://leetcode-cn.com/problems/element-appearing-more-than-25-in-sorted-array)", "[\u6709\u5e8f\u6570\u7ec4\u4e2d\u51fa\u73b0\u6b21\u6570\u8d85\u8fc725%\u7684\u5143\u7d20](/solution/1200-1299/1287.Element%20Appearing%20More%20Than%2025%25%20In%20Sorted%20Array/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1287](https://leetcode.com/problems/element-appearing-more-than-25-in-sorted-array)", "[Element Appearing More Than 25% In Sorted Array](/solution/1200-1299/1287.Element%20Appearing%20More%20Than%2025%25%20In%20Sorted%20Array/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1220", "frontend_question_id": "1125", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/smallest-sufficient-team", "url_en": "https://leetcode.com/problems/smallest-sufficient-team", "relative_path_cn": "/solution/1100-1199/1125.Smallest%20Sufficient%20Team/README.md", "relative_path_en": "/solution/1100-1199/1125.Smallest%20Sufficient%20Team/README_EN.md", "title_cn": "\u6700\u5c0f\u7684\u5fc5\u8981\u56e2\u961f", "title_en": "Smallest Sufficient Team", "question_title_slug": "smallest-sufficient-team", "content_en": "

In a project, you have a list of required skills req_skills, and a list of people. The ith person people[i] contains a list of skills that the person has.

\n\n

Consider a sufficient team: a set of people such that for every required skill in req_skills, there is at least one person in the team who has that skill. We can represent these teams by the index of each person.

\n\n
    \n\t
  • For example, team = [0, 1, 3] represents the people with skills people[0], people[1], and people[3].
  • \n
\n\n

Return any sufficient team of the smallest possible size, represented by the index of each person. You may return the answer in any order.

\n\n

It is guaranteed an answer exists.

\n\n

 

\n

Example 1:

\n
Input: req_skills = [\"java\",\"nodejs\",\"reactjs\"], people = [[\"java\"],[\"nodejs\"],[\"nodejs\",\"reactjs\"]]\nOutput: [0,2]\n

Example 2:

\n
Input: req_skills = [\"algorithms\",\"math\",\"java\",\"reactjs\",\"csharp\",\"aws\"], people = [[\"algorithms\",\"math\",\"java\"],[\"algorithms\",\"math\",\"reactjs\"],[\"java\",\"csharp\",\"aws\"],[\"reactjs\",\"csharp\"],[\"csharp\",\"math\"],[\"aws\",\"java\"]]\nOutput: [1,2]\n
\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= req_skills.length <= 16
  • \n\t
  • 1 <= req_skills[i].length <= 16
  • \n\t
  • req_skills[i] consists of lowercase English letters.
  • \n\t
  • All the strings of req_skills are unique.
  • \n\t
  • 1 <= people.length <= 60
  • \n\t
  • 0 <= people[i].length <= 16
  • \n\t
  • 1 <= people[i][j].length <= 16
  • \n\t
  • people[i][j] consists of lowercase English letters.
  • \n\t
  • All the strings of people[i] are unique.
  • \n\t
  • Every skill in people[i] is a skill in req_skills.
  • \n\t
  • It is guaranteed a sufficient team exists.
  • \n
\n", "content_cn": "

\u4f5c\u4e3a\u9879\u76ee\u7ecf\u7406\uff0c\u4f60\u89c4\u5212\u4e86\u4e00\u4efd\u9700\u6c42\u7684\u6280\u80fd\u6e05\u5355\u00a0req_skills\uff0c\u5e76\u6253\u7b97\u4ece\u5907\u9009\u4eba\u5458\u540d\u5355\u00a0people\u00a0\u4e2d\u9009\u51fa\u4e9b\u4eba\u7ec4\u6210\u4e00\u4e2a\u300c\u5fc5\u8981\u56e2\u961f\u300d\uff08 \u7f16\u53f7\u4e3a\u00a0i\u00a0\u7684\u5907\u9009\u4eba\u5458\u00a0people[i]\u00a0\u542b\u6709\u4e00\u4efd\u8be5\u5907\u9009\u4eba\u5458\u638c\u63e1\u7684\u6280\u80fd\u5217\u8868\uff09\u3002

\n\n

\u6240\u8c13\u300c\u5fc5\u8981\u56e2\u961f\u300d\uff0c\u5c31\u662f\u5728\u8fd9\u4e2a\u56e2\u961f\u4e2d\uff0c\u5bf9\u4e8e\u6240\u9700\u6c42\u7684\u6280\u80fd\u5217\u8868\u00a0req_skills \u4e2d\u5217\u51fa\u7684\u6bcf\u9879\u6280\u80fd\uff0c\u56e2\u961f\u4e2d\u81f3\u5c11\u6709\u4e00\u540d\u6210\u5458\u5df2\u7ecf\u638c\u63e1\u3002\u53ef\u4ee5\u7528\u6bcf\u4e2a\u4eba\u7684\u7f16\u53f7\u6765\u8868\u793a\u56e2\u961f\u4e2d\u7684\u6210\u5458\uff1a

\n\n
    \n\t
  • \u4f8b\u5982\uff0c\u56e2\u961f\u00a0team = [0, 1, 3]\u00a0\u8868\u793a\u638c\u63e1\u6280\u80fd\u5206\u522b\u4e3a\u00a0people[0]\uff0cpeople[1]\uff0c\u548c\u00a0people[3]\u00a0\u7684\u5907\u9009\u4eba\u5458\u3002
  • \n
\n\n

\u8bf7\u4f60\u8fd4\u56de \u4efb\u4e00\u00a0\u89c4\u6a21\u6700\u5c0f\u7684\u5fc5\u8981\u56e2\u961f\uff0c\u56e2\u961f\u6210\u5458\u7528\u4eba\u5458\u7f16\u53f7\u8868\u793a\u3002\u4f60\u53ef\u4ee5\u6309 \u4efb\u610f\u987a\u5e8f \u8fd4\u56de\u7b54\u6848\uff0c\u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u7b54\u6848\u5b58\u5728\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1areq_skills = [\"java\",\"nodejs\",\"reactjs\"], people = [[\"java\"],[\"nodejs\"],[\"nodejs\",\"reactjs\"]]\n\u8f93\u51fa\uff1a[0,2]\n
\n\n

\u793a\u4f8b\u00a02\uff1a

\n\n
\n\u8f93\u5165\uff1areq_skills = [\"algorithms\",\"math\",\"java\",\"reactjs\",\"csharp\",\"aws\"], people = [[\"algorithms\",\"math\",\"java\"],[\"algorithms\",\"math\",\"reactjs\"],[\"java\",\"csharp\",\"aws\"],[\"reactjs\",\"csharp\"],[\"csharp\",\"math\"],[\"aws\",\"java\"]]\n\u8f93\u51fa\uff1a[1,2]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= req_skills.length <= 16
  • \n\t
  • 1 <= req_skills[i].length <= 16
  • \n\t
  • req_skills[i] \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
  • \n\t
  • req_skills \u4e2d\u7684\u6240\u6709\u5b57\u7b26\u4e32 \u4e92\u4e0d\u76f8\u540c
  • \n\t
  • 1 <= people.length <= 60
  • \n\t
  • 0 <= people[i].length <= 16
  • \n\t
  • 1 <= people[i][j].length <= 16
  • \n\t
  • people[i][j] \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
  • \n\t
  • people[i] \u4e2d\u7684\u6240\u6709\u5b57\u7b26\u4e32 \u4e92\u4e0d\u76f8\u540c
  • \n\t
  • people[i] \u4e2d\u7684\u6bcf\u4e2a\u6280\u80fd\u662f req_skills \u4e2d\u7684\u6280\u80fd
  • \n\t
  • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u300c\u5fc5\u8981\u56e2\u961f\u300d\u4e00\u5b9a\u5b58\u5728
  • \n
\n", "tags_en": ["Bit Manipulation", "Dynamic Programming"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector smallestSufficientTeam(vector& req_skills, vector>& people) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] smallestSufficientTeam(String[] req_skills, List> people) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def smallestSufficientTeam(self, req_skills, people):\n \"\"\"\n :type req_skills: List[str]\n :type people: List[List[str]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def smallestSufficientTeam(self, req_skills: List[str], people: List[List[str]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* smallestSufficientTeam(char ** req_skills, int req_skillsSize, char *** people, int peopleSize, int* peopleColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] SmallestSufficientTeam(string[] req_skills, IList> people) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} req_skills\n * @param {string[][]} people\n * @return {number[]}\n */\nvar smallestSufficientTeam = function(req_skills, people) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} req_skills\n# @param {String[][]} people\n# @return {Integer[]}\ndef smallest_sufficient_team(req_skills, people)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func smallestSufficientTeam(_ req_skills: [String], _ people: [[String]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func smallestSufficientTeam(req_skills []string, people [][]string) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def smallestSufficientTeam(req_skills: Array[String], people: List[List[String]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun smallestSufficientTeam(req_skills: Array, people: List>): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn smallest_sufficient_team(req_skills: Vec, people: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $req_skills\n * @param String[][] $people\n * @return Integer[]\n */\n function smallestSufficientTeam($req_skills, $people) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function smallestSufficientTeam(req_skills: string[], people: string[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (smallest-sufficient-team req_skills people)\n (-> (listof string?) (listof (listof string?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1125](https://leetcode-cn.com/problems/smallest-sufficient-team)", "[\u6700\u5c0f\u7684\u5fc5\u8981\u56e2\u961f](/solution/1100-1199/1125.Smallest%20Sufficient%20Team/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1125](https://leetcode.com/problems/smallest-sufficient-team)", "[Smallest Sufficient Team](/solution/1100-1199/1125.Smallest%20Sufficient%20Team/README_EN.md)", "`Bit Manipulation`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "1219", "frontend_question_id": "1124", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-well-performing-interval", "url_en": "https://leetcode.com/problems/longest-well-performing-interval", "relative_path_cn": "/solution/1100-1199/1124.Longest%20Well-Performing%20Interval/README.md", "relative_path_en": "/solution/1100-1199/1124.Longest%20Well-Performing%20Interval/README_EN.md", "title_cn": "\u8868\u73b0\u826f\u597d\u7684\u6700\u957f\u65f6\u95f4\u6bb5", "title_en": "Longest Well-Performing Interval", "question_title_slug": "longest-well-performing-interval", "content_en": "

We are given hours, a list of the number of hours worked per day for a given employee.

\n\n

A day is considered to be a tiring day if and only if the number of hours worked is (strictly) greater than 8.

\n\n

A well-performing interval is an interval of days for which the number of tiring days is strictly larger than the number of non-tiring days.

\n\n

Return the length of the longest well-performing interval.

\n\n

 

\n

Example 1:

\n\n
\nInput: hours = [9,9,6,0,6,6,9]\nOutput: 3\nExplanation: The longest well-performing interval is [9,9,6].\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= hours.length <= 10000
  • \n\t
  • 0 <= hours[i] <= 16
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4efd\u5de5\u4f5c\u65f6\u95f4\u8868 hours\uff0c\u4e0a\u9762\u8bb0\u5f55\u7740\u67d0\u4e00\u4f4d\u5458\u5de5\u6bcf\u5929\u7684\u5de5\u4f5c\u5c0f\u65f6\u6570\u3002

\n\n

\u6211\u4eec\u8ba4\u4e3a\u5f53\u5458\u5de5\u4e00\u5929\u4e2d\u7684\u5de5\u4f5c\u5c0f\u65f6\u6570\u5927\u4e8e 8 \u5c0f\u65f6\u7684\u65f6\u5019\uff0c\u90a3\u4e48\u8fd9\u4e00\u5929\u5c31\u662f\u300c\u52b3\u7d2f\u7684\u4e00\u5929\u300d\u3002

\n\n

\u6240\u8c13\u300c\u8868\u73b0\u826f\u597d\u7684\u65f6\u95f4\u6bb5\u300d\uff0c\u610f\u5473\u5728\u8fd9\u6bb5\u65f6\u95f4\u5185\uff0c\u300c\u52b3\u7d2f\u7684\u5929\u6570\u300d\u662f\u4e25\u683c \u5927\u4e8e\u300c\u4e0d\u52b3\u7d2f\u7684\u5929\u6570\u300d\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u300c\u8868\u73b0\u826f\u597d\u65f6\u95f4\u6bb5\u300d\u7684\u6700\u5927\u957f\u5ea6\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1ahours = [9,9,6,0,6,6,9]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6700\u957f\u7684\u8868\u73b0\u826f\u597d\u65f6\u95f4\u6bb5\u662f [9,9,6]\u3002
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= hours.length <= 10000
  • \n\t
  • 0 <= hours[i] <= 16
  • \n
\n", "tags_en": ["Stack"], "tags_cn": ["\u6808"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int longestWPI(vector& hours) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int longestWPI(int[] hours) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestWPI(self, hours):\n \"\"\"\n :type hours: List[int]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestWPI(self, hours: List[int]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint longestWPI(int* hours, int hoursSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LongestWPI(int[] hours) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} hours\n * @return {number}\n */\nvar longestWPI = function(hours) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} hours\n# @return {Integer}\ndef longest_wpi(hours)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestWPI(_ hours: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestWPI(hours []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestWPI(hours: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestWPI(hours: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_wpi(hours: Vec) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $hours\n * @return Integer\n */\n function longestWPI($hours) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestWPI(hours: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-wpi hours)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1124](https://leetcode-cn.com/problems/longest-well-performing-interval)", "[\u8868\u73b0\u826f\u597d\u7684\u6700\u957f\u65f6\u95f4\u6bb5](/solution/1100-1199/1124.Longest%20Well-Performing%20Interval/README.md)", "`\u6808`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1124](https://leetcode.com/problems/longest-well-performing-interval)", "[Longest Well-Performing Interval](/solution/1100-1199/1124.Longest%20Well-Performing%20Interval/README_EN.md)", "`Stack`", "Medium", ""]}, {"question_id": "1218", "frontend_question_id": "1123", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/lowest-common-ancestor-of-deepest-leaves", "url_en": "https://leetcode.com/problems/lowest-common-ancestor-of-deepest-leaves", "relative_path_cn": "/solution/1100-1199/1123.Lowest%20Common%20Ancestor%20of%20Deepest%20Leaves/README.md", "relative_path_en": "/solution/1100-1199/1123.Lowest%20Common%20Ancestor%20of%20Deepest%20Leaves/README_EN.md", "title_cn": "\u6700\u6df1\u53f6\u8282\u70b9\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148", "title_en": "Lowest Common Ancestor of Deepest Leaves", "question_title_slug": "lowest-common-ancestor-of-deepest-leaves", "content_en": "

Given the root of a binary tree, return the lowest common ancestor of its deepest leaves.

\n\n

Recall that:

\n\n
    \n\t
  • The node of a binary tree is a leaf if and only if it has no children
  • \n\t
  • The depth of the root of the tree is 0. if the depth of a node is d, the depth of each of its children is d + 1.
  • \n\t
  • The lowest common ancestor of a set S of nodes, is the node A with the largest depth such that every node in S is in the subtree with root A.
  • \n
\n\n

Note: This question is the same as 865: https://leetcode.com/problems/smallest-subtree-with-all-the-deepest-nodes/

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: root = [3,5,1,6,2,0,8,null,null,7,4]\nOutput: [2,7,4]\nExplanation: We return the node with value 2, colored in yellow in the diagram.\nThe nodes coloured in blue are the deepest leaf-nodes of the tree.\nNote that nodes 6, 0, and 8 are also leaf nodes, but the depth of them is 2, but the depth of nodes 7 and 4 is 3.
\n\n

Example 2:

\n\n
\nInput: root = [1]\nOutput: [1]\nExplanation: The root is the deepest node in the tree, and it's the lca of itself.\n
\n\n

Example 3:

\n\n
\nInput: root = [0,1,3,null,2]\nOutput: [2]\nExplanation: The deepest leaf node in the tree is 2, the lca of one node is itself.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The number of nodes in the tree will be in the range [1, 1000].
  • \n\t
  • 0 <= Node.val <= 1000
  • \n\t
  • The values of the nodes in the tree are unique.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6709\u6839\u8282\u70b9\u7684\u4e8c\u53c9\u6811\uff0c\u627e\u5230\u5b83\u6700\u6df1\u7684\u53f6\u8282\u70b9\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148\u3002

\n\n

\u56de\u60f3\u4e00\u4e0b\uff1a

\n\n
    \n\t
  • \u53f6\u8282\u70b9 \u662f\u4e8c\u53c9\u6811\u4e2d\u6ca1\u6709\u5b50\u8282\u70b9\u7684\u8282\u70b9
  • \n\t
  • \u6811\u7684\u6839\u8282\u70b9\u7684\u00a0\u6df1\u5ea6\u00a0\u4e3a\u00a00\uff0c\u5982\u679c\u67d0\u4e00\u8282\u70b9\u7684\u6df1\u5ea6\u4e3a\u00a0d\uff0c\u90a3\u5b83\u7684\u5b50\u8282\u70b9\u7684\u6df1\u5ea6\u5c31\u662f\u00a0d+1
  • \n\t
  • \u5982\u679c\u6211\u4eec\u5047\u5b9a A \u662f\u4e00\u7ec4\u8282\u70b9\u00a0S\u00a0\u7684 \u6700\u8fd1\u516c\u5171\u7956\u5148\uff0cS\u00a0\u4e2d\u7684\u6bcf\u4e2a\u8282\u70b9\u90fd\u5728\u4ee5 A \u4e3a\u6839\u8282\u70b9\u7684\u5b50\u6811\u4e2d\uff0c\u4e14 A\u00a0\u7684\u6df1\u5ea6\u8fbe\u5230\u6b64\u6761\u4ef6\u4e0b\u53ef\u80fd\u7684\u6700\u5927\u503c\u3002
  • \n
\n\n

\u00a0

\n\n

\u6ce8\u610f\uff1a\u672c\u9898\u4e0e\u529b\u6263 865 \u91cd\u590d\uff1ahttps://leetcode-cn.com/problems/smallest-subtree-with-all-the-deepest-nodes/

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1aroot = [3,5,1,6,2,0,8,null,null,7,4]\n\u8f93\u51fa\uff1a[2,7,4]\n\u89e3\u91ca\uff1a\n\u6211\u4eec\u8fd4\u56de\u503c\u4e3a 2 \u7684\u8282\u70b9\uff0c\u5728\u56fe\u4e2d\u7528\u9ec4\u8272\u6807\u8bb0\u3002\n\u5728\u56fe\u4e2d\u7528\u84dd\u8272\u6807\u8bb0\u7684\u662f\u6811\u7684\u6700\u6df1\u7684\u8282\u70b9\u3002\n\u6ce8\u610f\uff0c\u8282\u70b9 6\u30010 \u548c 8 \u4e5f\u662f\u53f6\u8282\u70b9\uff0c\u4f46\u662f\u5b83\u4eec\u7684\u6df1\u5ea6\u662f 2 \uff0c\u800c\u8282\u70b9 7 \u548c 4 \u7684\u6df1\u5ea6\u662f 3 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aroot = [1]\n\u8f93\u51fa\uff1a[1]\n\u89e3\u91ca\uff1a\u6839\u8282\u70b9\u662f\u6811\u4e2d\u6700\u6df1\u7684\u8282\u70b9\uff0c\u5b83\u662f\u5b83\u672c\u8eab\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1aroot = [0,1,3,null,2]\n\u8f93\u51fa\uff1a[2]\n\u89e3\u91ca\uff1a\u6811\u4e2d\u6700\u6df1\u7684\u53f6\u8282\u70b9\u662f 2 \uff0c\u6700\u8fd1\u516c\u5171\u7956\u5148\u662f\u5b83\u81ea\u5df1\u3002
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u7ed9\u4f60\u7684\u6811\u4e2d\u5c06\u6709\u00a01 \u5230 1000 \u4e2a\u8282\u70b9\u3002
  • \n\t
  • \u6811\u4e2d\u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u90fd\u5728 1 \u5230 1000 \u4e4b\u95f4\u3002
  • \n\t
  • \u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u90fd\u662f\u72ec\u4e00\u65e0\u4e8c\u7684\u3002
  • \n
\n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* lcaDeepestLeaves(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode lcaDeepestLeaves(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def lcaDeepestLeaves(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: TreeNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def lcaDeepestLeaves(self, root: TreeNode) -> TreeNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* lcaDeepestLeaves(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode LcaDeepestLeaves(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {TreeNode}\n */\nvar lcaDeepestLeaves = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {TreeNode}\ndef lca_deepest_leaves(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func lcaDeepestLeaves(_ root: TreeNode?) -> TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc lcaDeepestLeaves(root *TreeNode) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def lcaDeepestLeaves(root: TreeNode): TreeNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun lcaDeepestLeaves(root: TreeNode?): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn lca_deepest_leaves(root: Option>>) -> Option>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return TreeNode\n */\n function lcaDeepestLeaves($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction lcaDeepestLeaves(root: TreeNode | null): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (lca-deepest-leaves root)\n (-> (or/c tree-node? #f) (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1123](https://leetcode-cn.com/problems/lowest-common-ancestor-of-deepest-leaves)", "[\u6700\u6df1\u53f6\u8282\u70b9\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148](/solution/1100-1199/1123.Lowest%20Common%20Ancestor%20of%20Deepest%20Leaves/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1123](https://leetcode.com/problems/lowest-common-ancestor-of-deepest-leaves)", "[Lowest Common Ancestor of Deepest Leaves](/solution/1100-1199/1123.Lowest%20Common%20Ancestor%20of%20Deepest%20Leaves/README_EN.md)", "`Tree`,`Depth-first Search`", "Medium", ""]}, {"question_id": "1217", "frontend_question_id": "1122", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/relative-sort-array", "url_en": "https://leetcode.com/problems/relative-sort-array", "relative_path_cn": "/solution/1100-1199/1122.Relative%20Sort%20Array/README.md", "relative_path_en": "/solution/1100-1199/1122.Relative%20Sort%20Array/README_EN.md", "title_cn": "\u6570\u7ec4\u7684\u76f8\u5bf9\u6392\u5e8f", "title_en": "Relative Sort Array", "question_title_slug": "relative-sort-array", "content_en": "

Given two arrays arr1 and arr2, the elements of arr2 are distinct, and all elements in arr2 are also in arr1.

\n\n

Sort the elements of arr1 such that the relative ordering of items in arr1 are the same as in arr2.  Elements that don't appear in arr2 should be placed at the end of arr1 in ascending order.

\n\n

 

\n

Example 1:

\n
Input: arr1 = [2,3,1,3,2,4,6,7,9,2,19], arr2 = [2,1,4,3,9,6]\nOutput: [2,2,2,1,4,3,3,9,6,7,19]\n
\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= arr1.length, arr2.length <= 1000
  • \n\t
  • 0 <= arr1[i], arr2[i] <= 1000
  • \n\t
  • All the elements of arr2 are distinct.
  • \n\t
  • Each arr2[i] is in arr1.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e24\u4e2a\u6570\u7ec4\uff0carr1 \u548c\u00a0arr2\uff0c

\n\n
    \n\t
  • arr2\u00a0\u4e2d\u7684\u5143\u7d20\u5404\u4e0d\u76f8\u540c
  • \n\t
  • arr2 \u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u90fd\u51fa\u73b0\u5728\u00a0arr1\u00a0\u4e2d
  • \n
\n\n

\u5bf9 arr1\u00a0\u4e2d\u7684\u5143\u7d20\u8fdb\u884c\u6392\u5e8f\uff0c\u4f7f arr1 \u4e2d\u9879\u7684\u76f8\u5bf9\u987a\u5e8f\u548c\u00a0arr2\u00a0\u4e2d\u7684\u76f8\u5bf9\u987a\u5e8f\u76f8\u540c\u3002\u672a\u5728\u00a0arr2\u00a0\u4e2d\u51fa\u73b0\u8fc7\u7684\u5143\u7d20\u9700\u8981\u6309\u7167\u5347\u5e8f\u653e\u5728\u00a0arr1\u00a0\u7684\u672b\u5c3e\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b\uff1a

\n\n
\n\u8f93\u5165\uff1aarr1 = [2,3,1,3,2,4,6,7,9,2,19], arr2 = [2,1,4,3,9,6]\n\u8f93\u51fa\uff1a[2,2,2,1,4,3,3,9,6,7,19]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= arr1.length, arr2.length <= 1000
  • \n\t
  • 0 <= arr1[i], arr2[i] <= 1000
  • \n\t
  • arr2\u00a0\u4e2d\u7684\u5143\u7d20\u00a0arr2[i]\u00a0\u5404\u4e0d\u76f8\u540c
  • \n\t
  • arr2 \u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u00a0arr2[i]\u00a0\u90fd\u51fa\u73b0\u5728\u00a0arr1\u00a0\u4e2d
  • \n
\n", "tags_en": ["Sort", "Array"], "tags_cn": ["\u6392\u5e8f", "\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector relativeSortArray(vector& arr1, vector& arr2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] relativeSortArray(int[] arr1, int[] arr2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def relativeSortArray(self, arr1, arr2):\n \"\"\"\n :type arr1: List[int]\n :type arr2: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def relativeSortArray(self, arr1: List[int], arr2: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* relativeSortArray(int* arr1, int arr1Size, int* arr2, int arr2Size, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] RelativeSortArray(int[] arr1, int[] arr2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr1\n * @param {number[]} arr2\n * @return {number[]}\n */\nvar relativeSortArray = function(arr1, arr2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr1\n# @param {Integer[]} arr2\n# @return {Integer[]}\ndef relative_sort_array(arr1, arr2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func relativeSortArray(_ arr1: [Int], _ arr2: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func relativeSortArray(arr1 []int, arr2 []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def relativeSortArray(arr1: Array[Int], arr2: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun relativeSortArray(arr1: IntArray, arr2: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn relative_sort_array(arr1: Vec, arr2: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr1\n * @param Integer[] $arr2\n * @return Integer[]\n */\n function relativeSortArray($arr1, $arr2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function relativeSortArray(arr1: number[], arr2: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (relative-sort-array arr1 arr2)\n (-> (listof exact-integer?) (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1122](https://leetcode-cn.com/problems/relative-sort-array)", "[\u6570\u7ec4\u7684\u76f8\u5bf9\u6392\u5e8f](/solution/1100-1199/1122.Relative%20Sort%20Array/README.md)", "`\u6392\u5e8f`,`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1122](https://leetcode.com/problems/relative-sort-array)", "[Relative Sort Array](/solution/1100-1199/1122.Relative%20Sort%20Array/README_EN.md)", "`Sort`,`Array`", "Easy", ""]}, {"question_id": "1216", "frontend_question_id": "1116", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/print-zero-even-odd", "url_en": "https://leetcode.com/problems/print-zero-even-odd", "relative_path_cn": "/solution/1100-1199/1116.Print%20Zero%20Even%20Odd/README.md", "relative_path_en": "/solution/1100-1199/1116.Print%20Zero%20Even%20Odd/README_EN.md", "title_cn": "\u6253\u5370\u96f6\u4e0e\u5947\u5076\u6570", "title_en": "Print Zero Even Odd", "question_title_slug": "print-zero-even-odd", "content_en": "

Suppose you are given the following code:

\n\n
\nclass ZeroEvenOdd {\n  public ZeroEvenOdd(int n) { ... }      // constructor\n  public void zero(printNumber) { ... }  // only output 0's\n  public void even(printNumber) { ... }  // only output even numbers\n  public void odd(printNumber) { ... }   // only output odd numbers\n}\n
\n\n

The same instance of ZeroEvenOdd will be passed to three different threads:

\n\n
    \n\t
  1. Thread A will call zero() which should only output 0's.
  2. \n\t
  3. Thread B will call even() which should only ouput even numbers.
  4. \n\t
  5. Thread C will call odd() which should only output odd numbers.
  6. \n
\n\n

Each of the threads is given a printNumber method to output an integer. Modify the given program to output the series 010203040506... where the length of the series must be 2n.

\n\n

 

\n\n

Example 1:

\n\n
\nInput: n = 2\nOutput: "0102"\nExplanation: There are three threads being fired asynchronously. One of them calls zero(), the other calls even(), and the last one calls odd(). "0102" is the correct output.\n
\n\n

Example 2:

\n\n
\nInput: n = 5\nOutput: "0102030405"\n
\n", "content_cn": "

\u5047\u8bbe\u6709\u8fd9\u4e48\u4e00\u4e2a\u7c7b\uff1a

\n\n
class ZeroEvenOdd {\n  public ZeroEvenOdd(int n) { ... }      // \u6784\u9020\u51fd\u6570\n  public void zero(printNumber) { ... }  // \u4ec5\u6253\u5370\u51fa 0\n  public void even(printNumber) { ... }  // \u4ec5\u6253\u5370\u51fa \u5076\u6570\n  public void odd(printNumber) { ... }   // \u4ec5\u6253\u5370\u51fa \u5947\u6570\n}\n
\n\n

\u76f8\u540c\u7684\u4e00\u4e2a ZeroEvenOdd \u7c7b\u5b9e\u4f8b\u5c06\u4f1a\u4f20\u9012\u7ed9\u4e09\u4e2a\u4e0d\u540c\u7684\u7ebf\u7a0b\uff1a

\n\n
    \n\t
  1. \u7ebf\u7a0b A \u5c06\u8c03\u7528 zero()\uff0c\u5b83\u53ea\u8f93\u51fa 0 \u3002
  2. \n\t
  3. \u7ebf\u7a0b B \u5c06\u8c03\u7528 even()\uff0c\u5b83\u53ea\u8f93\u51fa\u5076\u6570\u3002
  4. \n\t
  5. \u7ebf\u7a0b C \u5c06\u8c03\u7528 odd()\uff0c\u5b83\u53ea\u8f93\u51fa\u5947\u6570\u3002
  6. \n
\n\n

\u6bcf\u4e2a\u7ebf\u7a0b\u90fd\u6709\u4e00\u4e2a printNumber \u65b9\u6cd5\u6765\u8f93\u51fa\u4e00\u4e2a\u6574\u6570\u3002\u8bf7\u4fee\u6539\u7ed9\u51fa\u7684\u4ee3\u7801\u4ee5\u8f93\u51fa\u6574\u6570\u5e8f\u5217 010203040506... \uff0c\u5176\u4e2d\u5e8f\u5217\u7684\u957f\u5ea6\u5fc5\u987b\u4e3a 2n\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1an = 2\n\u8f93\u51fa\uff1a"0102"\n\u8bf4\u660e\uff1a\u4e09\u6761\u7ebf\u7a0b\u5f02\u6b65\u6267\u884c\uff0c\u5176\u4e2d\u4e00\u4e2a\u8c03\u7528 zero()\uff0c\u53e6\u4e00\u4e2a\u7ebf\u7a0b\u8c03\u7528 even()\uff0c\u6700\u540e\u4e00\u4e2a\u7ebf\u7a0b\u8c03\u7528odd()\u3002\u6b63\u786e\u7684\u8f93\u51fa\u4e3a "0102"\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1an = 5\n\u8f93\u51fa\uff1a"0102030405"\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class ZeroEvenOdd {\nprivate:\n int n;\n\npublic:\n ZeroEvenOdd(int n) {\n this->n = n;\n }\n\n // printNumber(x) outputs \"x\", where x is an integer.\n void zero(function printNumber) {\n \n }\n\n void even(function printNumber) {\n \n }\n\n void odd(function printNumber) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class ZeroEvenOdd {\n private int n;\n \n public ZeroEvenOdd(int n) {\n this.n = n;\n }\n\n // printNumber.accept(x) outputs \"x\", where x is an integer.\n public void zero(IntConsumer printNumber) throws InterruptedException {\n \n }\n\n public void even(IntConsumer printNumber) throws InterruptedException {\n \n }\n\n public void odd(IntConsumer printNumber) throws InterruptedException {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class ZeroEvenOdd(object):\n def __init__(self, n):\n self.n = n\n \n \n\t# printNumber(x) outputs \"x\", where x is an integer.\n def zero(self, printNumber):\n \"\"\"\n :type printNumber: method\n :rtype: void\n \"\"\"\n \n \n \n def even(self, printNumber):\n \"\"\"\n :type printNumber: method\n :rtype: void\n \"\"\"\n \n \n \n def odd(self, printNumber):\n \"\"\"\n :type printNumber: method\n :rtype: void\n \"\"\"\n \n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class ZeroEvenOdd:\n def __init__(self, n):\n self.n = n\n \n \n\t# printNumber(x) outputs \"x\", where x is an integer.\n def zero(self, printNumber: 'Callable[[int], None]') -> None:\n \n \n \n def even(self, printNumber: 'Callable[[int], None]') -> None:\n \n \n \n def odd(self, printNumber: 'Callable[[int], None]') -> None:\n \n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "typedef struct {\n int n;\n} ZeroEvenOdd;\n\nZeroEvenOdd* zeroEvenOddCreate(int n) {\n ZeroEvenOdd* obj = (ZeroEvenOdd*) malloc(sizeof(ZeroEvenOdd));\n obj->n = n;\n return obj;\n}\n\n// You may call global function `void printNumber(int x)`\n// to output \"x\", where x is an integer.\n\nvoid zero(ZeroEvenOdd* obj) {\n \n}\n\nvoid even(ZeroEvenOdd* obj) {\n \n}\n\nvoid odd(ZeroEvenOdd* obj) {\n \n}\n\nvoid zeroEvenOddFree(ZeroEvenOdd* obj) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class ZeroEvenOdd {\n private int n;\n \n public ZeroEvenOdd(int n) {\n this.n = n;\n }\n\n // printNumber(x) outputs \"x\", where x is an integer.\n public void Zero(Action printNumber) {\n \n }\n\n public void Even(Action printNumber) {\n \n }\n\n public void Odd(Action printNumber) {\n \n }\n}", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1116](https://leetcode-cn.com/problems/print-zero-even-odd)", "[\u6253\u5370\u96f6\u4e0e\u5947\u5076\u6570](/solution/1100-1199/1116.Print%20Zero%20Even%20Odd/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1116](https://leetcode.com/problems/print-zero-even-odd)", "[Print Zero Even Odd](/solution/1100-1199/1116.Print%20Zero%20Even%20Odd/README_EN.md)", "", "Medium", ""]}, {"question_id": "1215", "frontend_question_id": "1113", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/reported-posts", "url_en": "https://leetcode.com/problems/reported-posts", "relative_path_cn": "/solution/1100-1199/1113.Reported%20Posts/README.md", "relative_path_en": "/solution/1100-1199/1113.Reported%20Posts/README_EN.md", "title_cn": "\u62a5\u544a\u7684\u8bb0\u5f55", "title_en": "Reported Posts", "question_title_slug": "reported-posts", "content_en": "

Table: Actions

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| user_id       | int     |\n| post_id       | int     |\n| action_date   | date    | \n| action        | enum    |\n| extra         | varchar |\n+---------------+---------+\nThere is no primary key for this table, it may have duplicate rows.\nThe action column is an ENUM type of ('view', 'like', 'reaction', 'comment', 'report', 'share').\nThe extra column has optional information about the action such as a reason for report or a type of reaction. 
\n\n

 

\n\n

Write an SQL query that reports the number of posts reported yesterday for each report reason. Assume today is 2019-07-05.

\n\n

The query result format is in the following example:

\n\n
\nActions table:\n+---------+---------+-------------+--------+--------+\n| user_id | post_id | action_date | action | extra  |\n+---------+---------+-------------+--------+--------+\n| 1       | 1       | 2019-07-01  | view   | null   |\n| 1       | 1       | 2019-07-01  | like   | null   |\n| 1       | 1       | 2019-07-01  | share  | null   |\n| 2       | 4       | 2019-07-04  | view   | null   |\n| 2       | 4       | 2019-07-04  | report | spam   |\n| 3       | 4       | 2019-07-04  | view   | null   |\n| 3       | 4       | 2019-07-04  | report | spam   |\n| 4       | 3       | 2019-07-02  | view   | null   |\n| 4       | 3       | 2019-07-02  | report | spam   |\n| 5       | 2       | 2019-07-04  | view   | null   |\n| 5       | 2       | 2019-07-04  | report | racism |\n| 5       | 5       | 2019-07-04  | view   | null   |\n| 5       | 5       | 2019-07-04  | report | racism |\n+---------+---------+-------------+--------+--------+\n\nResult table:\n+---------------+--------------+\n| report_reason | report_count |\n+---------------+--------------+\n| spam          | 1            |\n| racism        | 2            |\n+---------------+--------------+ \nNote that we only care about report reasons with non zero number of reports.
\n", "content_cn": "

\u52a8\u4f5c\u8868\uff1aActions

\n\n
+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| user_id       | int     |\n| post_id       | int     |\n| action_date   | date    | \n| action        | enum    |\n| extra         | varchar |\n+---------------+---------+\n\u6b64\u8868\u6ca1\u6709\u4e3b\u952e\uff0c\u6240\u4ee5\u53ef\u80fd\u4f1a\u6709\u91cd\u590d\u7684\u884c\u3002\naction \u5b57\u6bb5\u662f ENUM \u7c7b\u578b\u7684\uff0c\u5305\u542b:('view', 'like', 'reaction', 'comment', 'report', 'share')\nextra \u5b57\u6bb5\u662f\u53ef\u9009\u7684\u4fe1\u606f\uff08\u53ef\u80fd\u4e3a null\uff09\uff0c\u5176\u4e2d\u7684\u4fe1\u606f\u4f8b\u5982\u6709\uff1a1.\u62a5\u544a\u7406\u7531(a reason for report) 2.\u53cd\u5e94\u7c7b\u578b(a type of reaction)\n
\n\n

 

\n\n

\u7f16\u5199\u4e00\u6761SQL\uff0c\u67e5\u8be2\u6bcf\u79cd \u62a5\u544a\u7406\u7531\uff08report reason\uff09\u5728\u6628\u5929\u7684\u4e0d\u540c\u62a5\u544a\u6570\u91cf\uff08post_id\uff09\u3002\u5047\u8bbe\u4eca\u5929\u662f 2019-07-05\u3002

\n\n

\u67e5\u8be2\u53ca\u7ed3\u679c\u7684\u683c\u5f0f\u793a\u4f8b\uff1a

\n\n
Actions table:\n+---------+---------+-------------+--------+--------+\n| user_id | post_id | action_date | action | extra  |\n+---------+---------+-------------+--------+--------+\n| 1       | 1       | 2019-07-01  | view   | null   |\n| 1       | 1       | 2019-07-01  | like   | null   |\n| 1       | 1       | 2019-07-01  | share  | null   |\n| 2       | 4       | 2019-07-04  | view   | null   |\n| 2       | 4       | 2019-07-04  | report | spam   |\n| 3       | 4       | 2019-07-04  | view   | null   |\n| 3       | 4       | 2019-07-04  | report | spam   |\n| 4       | 3       | 2019-07-02  | view   | null   |\n| 4       | 3       | 2019-07-02  | report | spam   |\n| 5       | 2       | 2019-07-04  | view   | null   |\n| 5       | 2       | 2019-07-04  | report | racism |\n| 5       | 5       | 2019-07-04  | view   | null   |\n| 5       | 5       | 2019-07-04  | report | racism |\n+---------+---------+-------------+--------+--------+\n\nResult table:\n+---------------+--------------+\n| report_reason | report_count |\n+---------------+--------------+\n| spam          | 1            |\n| racism        | 2            |\n+---------------+--------------+ \n\u6ce8\u610f\uff0c\u6211\u4eec\u53ea\u5173\u5fc3\u62a5\u544a\u6570\u91cf\u975e\u96f6\u7684\u7ed3\u679c\u3002\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1113](https://leetcode-cn.com/problems/reported-posts)", "[\u62a5\u544a\u7684\u8bb0\u5f55](/solution/1100-1199/1113.Reported%20Posts/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1113](https://leetcode.com/problems/reported-posts)", "[Reported Posts](/solution/1100-1199/1113.Reported%20Posts/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1214", "frontend_question_id": "1112", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/highest-grade-for-each-student", "url_en": "https://leetcode.com/problems/highest-grade-for-each-student", "relative_path_cn": "/solution/1100-1199/1112.Highest%20Grade%20For%20Each%20Student/README.md", "relative_path_en": "/solution/1100-1199/1112.Highest%20Grade%20For%20Each%20Student/README_EN.md", "title_cn": "\u6bcf\u4f4d\u5b66\u751f\u7684\u6700\u9ad8\u6210\u7ee9", "title_en": "Highest Grade For Each Student", "question_title_slug": "highest-grade-for-each-student", "content_en": "

Table: Enrollments

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| student_id    | int     |\n| course_id     | int     |\n| grade         | int     |\n+---------------+---------+\n(student_id, course_id) is the primary key of this table.\n\n
\n\n

Write a SQL query to find the highest grade with its corresponding course for each student. In case of a tie, you should find the course with the smallest course_id. The output must be sorted by increasing student_id.

\n\n

The query result format is in the following example:

\n\n
\nEnrollments table:\n+------------+-------------------+\n| student_id | course_id | grade |\n+------------+-----------+-------+\n| 2          | 2         | 95    |\n| 2          | 3         | 95    |\n| 1          | 1         | 90    |\n| 1          | 2         | 99    |\n| 3          | 1         | 80    |\n| 3          | 2         | 75    |\n| 3          | 3         | 82    |\n+------------+-----------+-------+\n\nResult table:\n+------------+-------------------+\n| student_id | course_id | grade |\n+------------+-----------+-------+\n| 1          | 2         | 99    |\n| 2          | 2         | 95    |\n| 3          | 3         | 82    |\n+------------+-----------+-------+\n
\n", "content_cn": "

\u8868\uff1aEnrollments

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| student_id    | int     |\n| course_id     | int     |\n| grade         | int     |\n+---------------+---------+\n(student_id, course_id) \u662f\u8be5\u8868\u7684\u4e3b\u952e\u3002\n\n
\n\n

 

\n\n

\u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\uff0c\u67e5\u8be2\u6bcf\u4f4d\u5b66\u751f\u83b7\u5f97\u7684\u6700\u9ad8\u6210\u7ee9\u548c\u5b83\u6240\u5bf9\u5e94\u7684\u79d1\u76ee\uff0c\u82e5\u79d1\u76ee\u6210\u7ee9\u5e76\u5217\uff0c\u53d6 course_id \u6700\u5c0f\u7684\u4e00\u95e8\u3002\u67e5\u8be2\u7ed3\u679c\u9700\u6309 student_id \u589e\u5e8f\u8fdb\u884c\u6392\u5e8f\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u6240\u793a\uff1a

\n\n
\nEnrollments \u8868\uff1a\n+------------+-------------------+\n| student_id | course_id | grade |\n+------------+-----------+-------+\n| 2          | 2         | 95    |\n| 2          | 3         | 95    |\n| 1          | 1         | 90    |\n| 1          | 2         | 99    |\n| 3          | 1         | 80    |\n| 3          | 2         | 75    |\n| 3          | 3         | 82    |\n+------------+-----------+-------+\n\nResult \u8868\uff1a\n+------------+-------------------+\n| student_id | course_id | grade |\n+------------+-----------+-------+\n| 1          | 2         | 99    |\n| 2          | 2         | 95    |\n| 3          | 3         | 82    |\n+------------+-----------+-------+\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1112](https://leetcode-cn.com/problems/highest-grade-for-each-student)", "[\u6bcf\u4f4d\u5b66\u751f\u7684\u6700\u9ad8\u6210\u7ee9](/solution/1100-1199/1112.Highest%20Grade%20For%20Each%20Student/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1112](https://leetcode.com/problems/highest-grade-for-each-student)", "[Highest Grade For Each Student](/solution/1100-1199/1112.Highest%20Grade%20For%20Each%20Student/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1213", "frontend_question_id": "1259", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/handshakes-that-dont-cross", "url_en": "https://leetcode.com/problems/handshakes-that-dont-cross", "relative_path_cn": "/solution/1200-1299/1259.Handshakes%20That%20Don%27t%20Cross/README.md", "relative_path_en": "/solution/1200-1299/1259.Handshakes%20That%20Don%27t%20Cross/README_EN.md", "title_cn": "\u4e0d\u76f8\u4ea4\u7684\u63e1\u624b", "title_en": "Handshakes That Don't Cross", "question_title_slug": "handshakes-that-dont-cross", "content_en": "

You are given an even number of people num_people that stand around a circle and each person shakes hands with someone else, so that there are num_people / 2 handshakes total.

\n\n

Return the number of ways these handshakes could occur such that none of the handshakes cross.

\n\n

Since this number could be very big, return the answer mod 10^9 + 7

\n\n

 

\n

Example 1:

\n\n
\nInput: num_people = 2\nOutput: 1\n
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: num_people = 4\nOutput: 2\nExplanation: There are two ways to do it, the first way is [(1,2),(3,4)] and the second one is [(2,3),(4,1)].\n
\n\n

Example 3:

\n\n

\"\"

\n\n
\nInput: num_people = 6\nOutput: 5\n
\n\n

Example 4:

\n\n
\nInput: num_people = 8\nOutput: 14\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= num_people <= 1000
  • \n\t
  • num_people % 2 == 0
  • \n
\n", "content_cn": "

\u5076\u6570 \u4e2a\u4eba\u7ad9\u6210\u4e00\u4e2a\u5706\uff0c\u603b\u4eba\u6570\u4e3a num_people \u3002\u6bcf\u4e2a\u4eba\u4e0e\u9664\u81ea\u5df1\u5916\u7684\u4e00\u4e2a\u4eba\u63e1\u624b\uff0c\u6240\u4ee5\u603b\u5171\u4f1a\u6709 num_people / 2 \u6b21\u63e1\u624b\u3002

\n\n

\u5c06\u63e1\u624b\u7684\u4eba\u4e4b\u95f4\u8fde\u7ebf\uff0c\u8bf7\u4f60\u8fd4\u56de\u8fde\u7ebf\u4e0d\u4f1a\u76f8\u4ea4\u7684\u63e1\u624b\u65b9\u6848\u6570\u3002

\n\n

\u7531\u4e8e\u7ed3\u679c\u53ef\u80fd\u4f1a\u5f88\u5927\uff0c\u8bf7\u4f60\u8fd4\u56de\u7b54\u6848 \u6a21 10^9+7 \u540e\u7684\u7ed3\u679c\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anum_people = 2\n\u8f93\u51fa\uff1a1\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1anum_people = 4\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u603b\u5171\u6709\u4e24\u79cd\u65b9\u6848\uff0c\u7b2c\u4e00\u79cd\u65b9\u6848\u662f [(1,2),(3,4)] \uff0c\u7b2c\u4e8c\u79cd\u65b9\u6848\u662f [(2,3),(4,1)] \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1anum_people = 6\n\u8f93\u51fa\uff1a5\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1anum_people = 8\n\u8f93\u51fa\uff1a14\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= num_people <= 1000
  • \n\t
  • num_people % 2 == 0
  • \n
\n", "tags_en": ["Math", "Dynamic Programming"], "tags_cn": ["\u6570\u5b66", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numberOfWays(int num_people) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numberOfWays(int num_people) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numberOfWays(self, num_people):\n \"\"\"\n :type num_people: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numberOfWays(self, num_people: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numberOfWays(int num_people){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumberOfWays(int num_people) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} num_people\n * @return {number}\n */\nvar numberOfWays = function(num_people) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} num_people\n# @return {Integer}\ndef number_of_ways(num_people)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numberOfWays(_ num_people: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numberOfWays(num_people int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numberOfWays(num_people: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numberOfWays(num_people: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn number_of_ways(num_people: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $num_people\n * @return Integer\n */\n function numberOfWays($num_people) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numberOfWays(num_people: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (number-of-ways num_people)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1259](https://leetcode-cn.com/problems/handshakes-that-dont-cross)", "[\u4e0d\u76f8\u4ea4\u7684\u63e1\u624b](/solution/1200-1299/1259.Handshakes%20That%20Don%27t%20Cross/README.md)", "`\u6570\u5b66`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1259](https://leetcode.com/problems/handshakes-that-dont-cross)", "[Handshakes That Don't Cross](/solution/1200-1299/1259.Handshakes%20That%20Don%27t%20Cross/README_EN.md)", "`Math`,`Dynamic Programming`", "Hard", "\ud83d\udd12"]}, {"question_id": "1212", "frontend_question_id": "1291", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sequential-digits", "url_en": "https://leetcode.com/problems/sequential-digits", "relative_path_cn": "/solution/1200-1299/1291.Sequential%20Digits/README.md", "relative_path_en": "/solution/1200-1299/1291.Sequential%20Digits/README_EN.md", "title_cn": "\u987a\u6b21\u6570", "title_en": "Sequential Digits", "question_title_slug": "sequential-digits", "content_en": "

An integer has sequential digits if and only if each digit in the number is one more than the previous digit.

\n\n

Return a sorted list of all the integers in the range [low, high] inclusive that have sequential digits.

\n\n

 

\n

Example 1:

\n
Input: low = 100, high = 300\nOutput: [123,234]\n

Example 2:

\n
Input: low = 1000, high = 13000\nOutput: [1234,2345,3456,4567,5678,6789,12345]\n
\n

 

\n

Constraints:

\n\n
    \n\t
  • 10 <= low <= high <= 10^9
  • \n
\n", "content_cn": "

\u6211\u4eec\u5b9a\u4e49\u300c\u987a\u6b21\u6570\u300d\u4e3a\uff1a\u6bcf\u4e00\u4f4d\u4e0a\u7684\u6570\u5b57\u90fd\u6bd4\u524d\u4e00\u4f4d\u4e0a\u7684\u6570\u5b57\u5927 1 \u7684\u6574\u6570\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u7531 [low, high] \u8303\u56f4\u5185\u6240\u6709\u987a\u6b21\u6570\u7ec4\u6210\u7684 \u6709\u5e8f \u5217\u8868\uff08\u4ece\u5c0f\u5230\u5927\u6392\u5e8f\uff09\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u51fa\uff1alow = 100, high = 300\n\u8f93\u51fa\uff1a[123,234]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u51fa\uff1alow = 1000, high = 13000\n\u8f93\u51fa\uff1a[1234,2345,3456,4567,5678,6789,12345]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 10 <= low <= high <= 10^9
  • \n
\n", "tags_en": ["Backtracking"], "tags_cn": ["\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector sequentialDigits(int low, int high) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List sequentialDigits(int low, int high) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def sequentialDigits(self, low, high):\n \"\"\"\n :type low: int\n :type high: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def sequentialDigits(self, low: int, high: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* sequentialDigits(int low, int high, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList SequentialDigits(int low, int high) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} low\n * @param {number} high\n * @return {number[]}\n */\nvar sequentialDigits = function(low, high) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} low\n# @param {Integer} high\n# @return {Integer[]}\ndef sequential_digits(low, high)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func sequentialDigits(_ low: Int, _ high: Int) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func sequentialDigits(low int, high int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def sequentialDigits(low: Int, high: Int): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun sequentialDigits(low: Int, high: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sequential_digits(low: i32, high: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $low\n * @param Integer $high\n * @return Integer[]\n */\n function sequentialDigits($low, $high) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function sequentialDigits(low: number, high: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (sequential-digits low high)\n (-> exact-integer? exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1291](https://leetcode-cn.com/problems/sequential-digits)", "[\u987a\u6b21\u6570](/solution/1200-1299/1291.Sequential%20Digits/README.md)", "`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1291](https://leetcode.com/problems/sequential-digits)", "[Sequential Digits](/solution/1200-1299/1291.Sequential%20Digits/README_EN.md)", "`Backtracking`", "Medium", ""]}, {"question_id": "1211", "frontend_question_id": "1286", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/iterator-for-combination", "url_en": "https://leetcode.com/problems/iterator-for-combination", "relative_path_cn": "/solution/1200-1299/1286.Iterator%20for%20Combination/README.md", "relative_path_en": "/solution/1200-1299/1286.Iterator%20for%20Combination/README_EN.md", "title_cn": "\u5b57\u6bcd\u7ec4\u5408\u8fed\u4ee3\u5668", "title_en": "Iterator for Combination", "question_title_slug": "iterator-for-combination", "content_en": "

Design the CombinationIterator class:

\n\n
    \n\t
  • CombinationIterator(string characters, int combinationLength) Initializes the object with a string characters of sorted distinct lowercase English letters and a number combinationLength as arguments.
  • \n\t
  • next() Returns the next combination of length combinationLength in lexicographical order.
  • \n\t
  • hasNext() Returns true if and only if there exists a next combination.
  • \n
\n\n

 

\n

Example 1:

\n\n
\nInput\n["CombinationIterator", "next", "hasNext", "next", "hasNext", "next", "hasNext"]\n[["abc", 2], [], [], [], [], [], []]\nOutput\n[null, "ab", true, "ac", true, "bc", false]\n\nExplanation\nCombinationIterator itr = new CombinationIterator("abc", 2);\nitr.next();    // return "ab"\nitr.hasNext(); // return True\nitr.next();    // return "ac"\nitr.hasNext(); // return True\nitr.next();    // return "bc"\nitr.hasNext(); // return False\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= combinationLength <= characters.length <= 15
  • \n\t
  • All the characters of characters are unique.
  • \n\t
  • At most 104 calls will be made to next and hasNext.
  • \n\t
  • It's guaranteed that all calls of the function next are valid.
  • \n
\n", "content_cn": "

\u8bf7\u4f60\u8bbe\u8ba1\u4e00\u4e2a\u8fed\u4ee3\u5668\u7c7b\uff0c\u5305\u62ec\u4ee5\u4e0b\u5185\u5bb9\uff1a

\n\n
    \n\t
  • \u4e00\u4e2a\u6784\u9020\u51fd\u6570\uff0c\u8f93\u5165\u53c2\u6570\u5305\u62ec\uff1a\u4e00\u4e2a \u6709\u5e8f\u4e14\u5b57\u7b26\u552f\u4e00 \u7684\u5b57\u7b26\u4e32 characters\uff08\u8be5\u5b57\u7b26\u4e32\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\uff09\u548c\u4e00\u4e2a\u6570\u5b57 combinationLength \u3002
  • \n\t
  • \u51fd\u6570 next() \uff0c\u6309 \u5b57\u5178\u5e8f \u8fd4\u56de\u957f\u5ea6\u4e3a combinationLength \u7684\u4e0b\u4e00\u4e2a\u5b57\u6bcd\u7ec4\u5408\u3002
  • \n\t
  • \u51fd\u6570 hasNext() \uff0c\u53ea\u6709\u5b58\u5728\u957f\u5ea6\u4e3a combinationLength \u7684\u4e0b\u4e00\u4e2a\u5b57\u6bcd\u7ec4\u5408\u65f6\uff0c\u624d\u8fd4\u56de True\uff1b\u5426\u5219\uff0c\u8fd4\u56de False\u3002
  • \n
\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
CombinationIterator iterator = new CombinationIterator("abc", 2); // \u521b\u5efa\u8fed\u4ee3\u5668 iterator\n\niterator.next(); // \u8fd4\u56de "ab"\niterator.hasNext(); // \u8fd4\u56de true\niterator.next(); // \u8fd4\u56de "ac"\niterator.hasNext(); // \u8fd4\u56de true\niterator.next(); // \u8fd4\u56de "bc"\niterator.hasNext(); // \u8fd4\u56de false\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= combinationLength <= characters.length <= 15
  • \n\t
  • \u6bcf\u7ec4\u6d4b\u8bd5\u6570\u636e\u6700\u591a\u5305\u542b 10^4 \u6b21\u51fd\u6570\u8c03\u7528\u3002
  • \n\t
  • \u9898\u76ee\u4fdd\u8bc1\u6bcf\u6b21\u8c03\u7528\u51fd\u6570 next \u65f6\u90fd\u5b58\u5728\u4e0b\u4e00\u4e2a\u5b57\u6bcd\u7ec4\u5408\u3002
  • \n
\n", "tags_en": ["Design", "Backtracking"], "tags_cn": ["\u8bbe\u8ba1", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class CombinationIterator {\npublic:\n CombinationIterator(string characters, int combinationLength) {\n\n }\n \n string next() {\n\n }\n \n bool hasNext() {\n\n }\n};\n\n/**\n * Your CombinationIterator object will be instantiated and called as such:\n * CombinationIterator* obj = new CombinationIterator(characters, combinationLength);\n * string param_1 = obj->next();\n * bool param_2 = obj->hasNext();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class CombinationIterator {\n\n public CombinationIterator(String characters, int combinationLength) {\n\n }\n \n public String next() {\n\n }\n \n public boolean hasNext() {\n\n }\n}\n\n/**\n * Your CombinationIterator object will be instantiated and called as such:\n * CombinationIterator obj = new CombinationIterator(characters, combinationLength);\n * String param_1 = obj.next();\n * boolean param_2 = obj.hasNext();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class CombinationIterator(object):\n\n def __init__(self, characters, combinationLength):\n \"\"\"\n :type characters: str\n :type combinationLength: int\n \"\"\"\n\n\n def next(self):\n \"\"\"\n :rtype: str\n \"\"\"\n\n\n def hasNext(self):\n \"\"\"\n :rtype: bool\n \"\"\"\n\n\n\n# Your CombinationIterator object will be instantiated and called as such:\n# obj = CombinationIterator(characters, combinationLength)\n# param_1 = obj.next()\n# param_2 = obj.hasNext()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class CombinationIterator:\n\n def __init__(self, characters: str, combinationLength: int):\n\n\n def next(self) -> str:\n\n\n def hasNext(self) -> bool:\n\n\n\n# Your CombinationIterator object will be instantiated and called as such:\n# obj = CombinationIterator(characters, combinationLength)\n# param_1 = obj.next()\n# param_2 = obj.hasNext()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} CombinationIterator;\n\n\nCombinationIterator* combinationIteratorCreate(char * characters, int combinationLength) {\n \n}\n\nchar * combinationIteratorNext(CombinationIterator* obj) {\n \n}\n\nbool combinationIteratorHasNext(CombinationIterator* obj) {\n \n}\n\nvoid combinationIteratorFree(CombinationIterator* obj) {\n \n}\n\n/**\n * Your CombinationIterator struct will be instantiated and called as such:\n * CombinationIterator* obj = combinationIteratorCreate(characters, combinationLength);\n * char * param_1 = combinationIteratorNext(obj);\n \n * bool param_2 = combinationIteratorHasNext(obj);\n \n * combinationIteratorFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class CombinationIterator {\n\n public CombinationIterator(string characters, int combinationLength) {\n\n }\n \n public string Next() {\n\n }\n \n public bool HasNext() {\n\n }\n}\n\n/**\n * Your CombinationIterator object will be instantiated and called as such:\n * CombinationIterator obj = new CombinationIterator(characters, combinationLength);\n * string param_1 = obj.Next();\n * bool param_2 = obj.HasNext();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} characters\n * @param {number} combinationLength\n */\nvar CombinationIterator = function(characters, combinationLength) {\n\n};\n\n/**\n * @return {string}\n */\nCombinationIterator.prototype.next = function() {\n\n};\n\n/**\n * @return {boolean}\n */\nCombinationIterator.prototype.hasNext = function() {\n\n};\n\n/**\n * Your CombinationIterator object will be instantiated and called as such:\n * var obj = new CombinationIterator(characters, combinationLength)\n * var param_1 = obj.next()\n * var param_2 = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class CombinationIterator\n\n=begin\n :type characters: String\n :type combination_length: Integer\n=end\n def initialize(characters, combination_length)\n\n end\n\n\n=begin\n :rtype: String\n=end\n def next()\n\n end\n\n\n=begin\n :rtype: Boolean\n=end\n def has_next()\n\n end\n\n\nend\n\n# Your CombinationIterator object will be instantiated and called as such:\n# obj = CombinationIterator.new(characters, combination_length)\n# param_1 = obj.next()\n# param_2 = obj.has_next()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass CombinationIterator {\n\n init(_ characters: String, _ combinationLength: Int) {\n\n }\n \n func next() -> String {\n\n }\n \n func hasNext() -> Bool {\n\n }\n}\n\n/**\n * Your CombinationIterator object will be instantiated and called as such:\n * let obj = CombinationIterator(characters, combinationLength)\n * let ret_1: String = obj.next()\n * let ret_2: Bool = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type CombinationIterator struct {\n\n}\n\n\nfunc Constructor(characters string, combinationLength int) CombinationIterator {\n\n}\n\n\nfunc (this *CombinationIterator) Next() string {\n\n}\n\n\nfunc (this *CombinationIterator) HasNext() bool {\n\n}\n\n\n/**\n * Your CombinationIterator object will be instantiated and called as such:\n * obj := Constructor(characters, combinationLength);\n * param_1 := obj.Next();\n * param_2 := obj.HasNext();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class CombinationIterator(_characters: String, _combinationLength: Int) {\n\n def next(): String = {\n\n }\n\n def hasNext(): Boolean = {\n\n }\n\n}\n\n/**\n * Your CombinationIterator object will be instantiated and called as such:\n * var obj = new CombinationIterator(characters, combinationLength)\n * var param_1 = obj.next()\n * var param_2 = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class CombinationIterator(characters: String, combinationLength: Int) {\n\n fun next(): String {\n\n }\n\n fun hasNext(): Boolean {\n\n }\n\n}\n\n/**\n * Your CombinationIterator object will be instantiated and called as such:\n * var obj = CombinationIterator(characters, combinationLength)\n * var param_1 = obj.next()\n * var param_2 = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct CombinationIterator {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl CombinationIterator {\n\n fn new(characters: String, combinationLength: i32) -> Self {\n\n }\n \n fn next(&self) -> String {\n\n }\n \n fn has_next(&self) -> bool {\n\n }\n}\n\n/**\n * Your CombinationIterator object will be instantiated and called as such:\n * let obj = CombinationIterator::new(characters, combinationLength);\n * let ret_1: String = obj.next();\n * let ret_2: bool = obj.has_next();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class CombinationIterator {\n /**\n * @param String $characters\n * @param Integer $combinationLength\n */\n function __construct($characters, $combinationLength) {\n\n }\n\n /**\n * @return String\n */\n function next() {\n\n }\n\n /**\n * @return Boolean\n */\n function hasNext() {\n\n }\n}\n\n/**\n * Your CombinationIterator object will be instantiated and called as such:\n * $obj = CombinationIterator($characters, $combinationLength);\n * $ret_1 = $obj->next();\n * $ret_2 = $obj->hasNext();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class CombinationIterator {\n constructor(characters: string, combinationLength: number) {\n\n }\n\n next(): string {\n\n }\n\n hasNext(): boolean {\n\n }\n}\n\n/**\n * Your CombinationIterator object will be instantiated and called as such:\n * var obj = new CombinationIterator(characters, combinationLength)\n * var param_1 = obj.next()\n * var param_2 = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define combination-iterator%\n (class object%\n (super-new)\n\n ; characters : string?\n\n ; combination-length : exact-integer?\n (init-field\n characters\n combination-length)\n \n ; next : -> string?\n (define/public (next)\n\n )\n ; has-next : -> boolean?\n (define/public (has-next)\n\n )))\n\n;; Your combination-iterator% object will be instantiated and called as such:\n;; (define obj (new combination-iterator% [characters characters] [combinationLength combinationLength]))\n;; (define param_1 (send obj next))\n;; (define param_2 (send obj has-next))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1286](https://leetcode-cn.com/problems/iterator-for-combination)", "[\u5b57\u6bcd\u7ec4\u5408\u8fed\u4ee3\u5668](/solution/1200-1299/1286.Iterator%20for%20Combination/README.md)", "`\u8bbe\u8ba1`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1286](https://leetcode.com/problems/iterator-for-combination)", "[Iterator for Combination](/solution/1200-1299/1286.Iterator%20for%20Combination/README_EN.md)", "`Design`,`Backtracking`", "Medium", ""]}, {"question_id": "1210", "frontend_question_id": "1619", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/mean-of-array-after-removing-some-elements", "url_en": "https://leetcode.com/problems/mean-of-array-after-removing-some-elements", "relative_path_cn": "/solution/1600-1699/1619.Mean%20of%20Array%20After%20Removing%20Some%20Elements/README.md", "relative_path_en": "/solution/1600-1699/1619.Mean%20of%20Array%20After%20Removing%20Some%20Elements/README_EN.md", "title_cn": "\u5220\u9664\u67d0\u4e9b\u5143\u7d20\u540e\u7684\u6570\u7ec4\u5747\u503c", "title_en": "Mean of Array After Removing Some Elements", "question_title_slug": "mean-of-array-after-removing-some-elements", "content_en": "

Given an integer array arr, return the mean of the remaining integers after removing the smallest 5% and the largest 5% of the elements.

\n\n

Answers within 10-5 of the actual answer will be considered accepted.

\n\n

 

\n

Example 1:

\n\n
\nInput: arr = [1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3]\nOutput: 2.00000\nExplanation: After erasing the minimum and the maximum values of this array, all elements are equal to 2, so the mean is 2.\n
\n\n

Example 2:

\n\n
\nInput: arr = [6,2,7,5,1,2,0,3,10,2,5,0,5,5,0,8,7,6,8,0]\nOutput: 4.00000\n
\n\n

Example 3:

\n\n
\nInput: arr = [6,0,7,0,7,5,7,8,3,4,0,7,8,1,6,8,1,1,2,4,8,1,9,5,4,3,8,5,10,8,6,6,1,0,6,10,8,2,3,4]\nOutput: 4.77778\n
\n\n

Example 4:

\n\n
\nInput: arr = [9,7,8,7,7,8,4,4,6,8,8,7,6,8,8,9,2,6,0,0,1,10,8,6,3,3,5,1,10,9,0,7,10,0,10,4,1,10,6,9,3,6,0,0,2,7,0,6,7,2,9,7,7,3,0,1,6,1,10,3]\nOutput: 5.27778\n
\n\n

Example 5:

\n\n
\nInput: arr = [4,8,4,10,0,7,1,3,7,8,8,3,4,1,6,2,1,1,8,0,9,8,0,3,9,10,3,10,1,10,7,3,2,1,4,9,10,7,6,4,0,8,5,1,2,1,6,2,5,0,7,10,9,10,3,7,10,5,8,5,7,6,7,6,10,9,5,10,5,5,7,2,10,7,7,8,2,0,1,1]\nOutput: 5.29167\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 20 <= arr.length <= 1000
  • \n\t
  • arr.length is a multiple of 20.
  • \n\t
  • 0 <= arr[i] <= 105
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0arr\u00a0\uff0c\u8bf7\u4f60\u5220\u9664\u6700\u5c0f\u00a05%\u00a0\u7684\u6570\u5b57\u548c\u6700\u5927 5%\u00a0\u7684\u6570\u5b57\u540e\uff0c\u5269\u4f59\u6570\u5b57\u7684\u5e73\u5747\u503c\u3002

\n\n

\u4e0e \u6807\u51c6\u7b54\u6848\u00a0\u8bef\u5dee\u5728\u00a010-5\u00a0\u7684\u7ed3\u679c\u90fd\u88ab\u89c6\u4e3a\u6b63\u786e\u7ed3\u679c\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3]\n\u8f93\u51fa\uff1a2.00000\n\u89e3\u91ca\uff1a\u5220\u9664\u6570\u7ec4\u4e2d\u6700\u5927\u548c\u6700\u5c0f\u7684\u5143\u7d20\u540e\uff0c\u6240\u6709\u5143\u7d20\u90fd\u7b49\u4e8e 2\uff0c\u6240\u4ee5\u5e73\u5747\u503c\u4e3a 2 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [6,2,7,5,1,2,0,3,10,2,5,0,5,5,0,8,7,6,8,0]\n\u8f93\u51fa\uff1a4.00000\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [6,0,7,0,7,5,7,8,3,4,0,7,8,1,6,8,1,1,2,4,8,1,9,5,4,3,8,5,10,8,6,6,1,0,6,10,8,2,3,4]\n\u8f93\u51fa\uff1a4.77778\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [9,7,8,7,7,8,4,4,6,8,8,7,6,8,8,9,2,6,0,0,1,10,8,6,3,3,5,1,10,9,0,7,10,0,10,4,1,10,6,9,3,6,0,0,2,7,0,6,7,2,9,7,7,3,0,1,6,1,10,3]\n\u8f93\u51fa\uff1a5.27778\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [4,8,4,10,0,7,1,3,7,8,8,3,4,1,6,2,1,1,8,0,9,8,0,3,9,10,3,10,1,10,7,3,2,1,4,9,10,7,6,4,0,8,5,1,2,1,6,2,5,0,7,10,9,10,3,7,10,5,8,5,7,6,7,6,10,9,5,10,5,5,7,2,10,7,7,8,2,0,1,1]\n\u8f93\u51fa\uff1a5.29167\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 20 <= arr.length <= 1000
  • \n\t
  • arr.length\u00a0\u662f\u00a020\u00a0\u7684\u00a0\u500d\u6570\u00a0
  • \n\t
  • 0 <= arr[i] <= 105
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n double trimMean(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double trimMean(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def trimMean(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: float\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def trimMean(self, arr: List[int]) -> float:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\ndouble trimMean(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double TrimMean(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar trimMean = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Float}\ndef trim_mean(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func trimMean(_ arr: [Int]) -> Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func trimMean(arr []int) float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def trimMean(arr: Array[Int]): Double = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun trimMean(arr: IntArray): Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn trim_mean(arr: Vec) -> f64 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Float\n */\n function trimMean($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function trimMean(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (trim-mean arr)\n (-> (listof exact-integer?) flonum?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1619](https://leetcode-cn.com/problems/mean-of-array-after-removing-some-elements)", "[\u5220\u9664\u67d0\u4e9b\u5143\u7d20\u540e\u7684\u6570\u7ec4\u5747\u503c](/solution/1600-1699/1619.Mean%20of%20Array%20After%20Removing%20Some%20Elements/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1619](https://leetcode.com/problems/mean-of-array-after-removing-some-elements)", "[Mean of Array After Removing Some Elements](/solution/1600-1699/1619.Mean%20of%20Array%20After%20Removing%20Some%20Elements/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1209", "frontend_question_id": "1188", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/design-bounded-blocking-queue", "url_en": "https://leetcode.com/problems/design-bounded-blocking-queue", "relative_path_cn": "/solution/1100-1199/1188.Design%20Bounded%20Blocking%20Queue/README.md", "relative_path_en": "/solution/1100-1199/1188.Design%20Bounded%20Blocking%20Queue/README_EN.md", "title_cn": "\u8bbe\u8ba1\u6709\u9650\u963b\u585e\u961f\u5217", "title_en": "Design Bounded Blocking Queue", "question_title_slug": "design-bounded-blocking-queue", "content_en": "

Implement a thread-safe bounded blocking queue that has the following methods:

\n\n
    \n\t
  • BoundedBlockingQueue(int capacity) The constructor initializes the queue with a maximum capacity.
  • \n\t
  • void enqueue(int element) Adds an element to the front of the queue. If the queue is full, the calling thread is blocked until the queue is no longer full.
  • \n\t
  • int dequeue() Returns the element at the rear of the queue and removes it. If the queue is empty, the calling thread is blocked until the queue is no longer empty.
  • \n\t
  • int size() Returns the number of elements currently in the queue.
  • \n
\n\n

Your implementation will be tested using multiple threads at the same time. Each thread will either be a producer thread that only makes calls to the enqueue method or a consumer thread that only makes calls to the dequeue method. The size method will be called after every test case.

\n\n

Please do not use built-in implementations of bounded blocking queue as this will not be accepted in an interview.

\n\n

 

\n

Example 1:

\n\n
\nInput:\n1\n1\n["BoundedBlockingQueue","enqueue","dequeue","dequeue","enqueue","enqueue","enqueue","enqueue","dequeue"]\n[[2],[1],[],[],[0],[2],[3],[4],[]]\n\nOutput:\n[1,0,2,2]\n\nExplanation:\nNumber of producer threads = 1\nNumber of consumer threads = 1\n\nBoundedBlockingQueue queue = new BoundedBlockingQueue(2);   // initialize the queue with capacity = 2.\n\nqueue.enqueue(1);   // The producer thread enqueues 1 to the queue.\nqueue.dequeue();    // The consumer thread calls dequeue and returns 1 from the queue.\nqueue.dequeue();    // Since the queue is empty, the consumer thread is blocked.\nqueue.enqueue(0);   // The producer thread enqueues 0 to the queue. The consumer thread is unblocked and returns 0 from the queue.\nqueue.enqueue(2);   // The producer thread enqueues 2 to the queue.\nqueue.enqueue(3);   // The producer thread enqueues 3 to the queue.\nqueue.enqueue(4);   // The producer thread is blocked because the queue's capacity (2) is reached.\nqueue.dequeue();    // The consumer thread returns 2 from the queue. The producer thread is unblocked and enqueues 4 to the queue.\nqueue.size();       // 2 elements remaining in the queue. size() is always called at the end of each test case.\n
\n\n

Example 2:

\n\n
\nInput:\n3\n4\n["BoundedBlockingQueue","enqueue","enqueue","enqueue","dequeue","dequeue","dequeue","enqueue"]\n[[3],[1],[0],[2],[],[],[],[3]]\nOutput:\n[1,0,2,1]\n\nExplanation:\nNumber of producer threads = 3\nNumber of consumer threads = 4\n\nBoundedBlockingQueue queue = new BoundedBlockingQueue(3);   // initialize the queue with capacity = 3.\n\nqueue.enqueue(1);   // Producer thread P1 enqueues 1 to the queue.\nqueue.enqueue(0);   // Producer thread P2 enqueues 0 to the queue.\nqueue.enqueue(2);   // Producer thread P3 enqueues 2 to the queue.\nqueue.dequeue();    // Consumer thread C1 calls dequeue.\nqueue.dequeue();    // Consumer thread C2 calls dequeue.\nqueue.dequeue();    // Consumer thread C3 calls dequeue.\nqueue.enqueue(3);   // One of the producer threads enqueues 3 to the queue.\nqueue.size();       // 1 element remaining in the queue.\n\nSince the number of threads for producer/consumer is greater than 1, we do not know how the threads will be scheduled in the operating system, even though the input seems to imply the ordering. Therefore, any of the output [1,0,2] or [1,2,0] or [0,1,2] or [0,2,1] or [2,0,1] or [2,1,0] will be accepted.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= Number of Prdoucers <= 8
  • \n\t
  • 1 <= Number of Consumers <= 8
  • \n\t
  • 1 <= size <= 30
  • \n\t
  • 0 <= element <= 20
  • \n\t
  • The number of calls to enqueue is greater than or equal to the number of calls to dequeue.
  • \n\t
  • At most 40 calls will be made to enque, deque, and size.
  • \n
\n", "content_cn": "

\u5b9e\u73b0\u4e00\u4e2a\u62e5\u6709\u5982\u4e0b\u65b9\u6cd5\u7684\u7ebf\u7a0b\u5b89\u5168\u6709\u9650\u963b\u585e\u961f\u5217\uff1a

\n\n
    \n\t
  • BoundedBlockingQueue(int capacity) \u6784\u9020\u65b9\u6cd5\u521d\u59cb\u5316\u961f\u5217\uff0c\u5176\u4e2dcapacity\u4ee3\u8868\u961f\u5217\u957f\u5ea6\u4e0a\u9650\u3002
  • \n\t
  • void enqueue(int element) \u5728\u961f\u9996\u589e\u52a0\u4e00\u4e2aelement. \u5982\u679c\u961f\u5217\u6ee1\uff0c\u8c03\u7528\u7ebf\u7a0b\u88ab\u963b\u585e\u76f4\u5230\u961f\u5217\u975e\u6ee1\u3002
  • \n\t
  • int dequeue() \u8fd4\u56de\u961f\u5c3e\u5143\u7d20\u5e76\u4ece\u961f\u5217\u4e2d\u5c06\u5176\u5220\u9664. \u5982\u679c\u961f\u5217\u4e3a\u7a7a\uff0c\u8c03\u7528\u7ebf\u7a0b\u88ab\u963b\u585e\u76f4\u5230\u961f\u5217\u975e\u7a7a\u3002
  • \n\t
  • int size() \u8fd4\u56de\u5f53\u524d\u961f\u5217\u5143\u7d20\u4e2a\u6570\u3002
  • \n
\n\n

\u4f60\u7684\u5b9e\u73b0\u5c06\u4f1a\u88ab\u591a\u7ebf\u7a0b\u540c\u65f6\u8bbf\u95ee\u8fdb\u884c\u6d4b\u8bd5\u3002\u6bcf\u4e00\u4e2a\u7ebf\u7a0b\u8981\u4e48\u662f\u4e00\u4e2a\u53ea\u8c03\u7528enqueue\u65b9\u6cd5\u7684\u751f\u4ea7\u8005\u7ebf\u7a0b\uff0c\u8981\u4e48\u662f\u4e00\u4e2a\u53ea\u8c03\u7528dequeue\u65b9\u6cd5\u7684\u6d88\u8d39\u8005\u7ebf\u7a0b\u3002size\u65b9\u6cd5\u5c06\u4f1a\u5728\u6bcf\u4e00\u4e2a\u6d4b\u8bd5\u7528\u4f8b\u4e4b\u540e\u8fdb\u884c\u8c03\u7528\u3002

\n\n

\u8bf7\u4e0d\u8981\u4f7f\u7528\u5185\u7f6e\u7684\u6709\u9650\u963b\u585e\u961f\u5217\u5b9e\u73b0\uff0c\u5426\u5219\u9762\u8bd5\u5c06\u4e0d\u4f1a\u901a\u8fc7\u3002

\n\n

 

\n\n

\u793a\u4f8b 1:

\n\n
\n\u8f93\u5165:\n1\n1\n["BoundedBlockingQueue","enqueue","dequeue","dequeue","enqueue","enqueue","enqueue","enqueue","dequeue"]\n[[2],[1],[],[],[0],[2],[3],[4],[]]\n\n\u8f93\u51fa:\n[1,0,2,2]\n\n\u89e3\u91ca:\n\u751f\u4ea7\u8005\u7ebf\u7a0b\u6570\u76ee = 1\n\u6d88\u8d39\u8005\u7ebf\u7a0b\u6570\u76ee = 1\n\nBoundedBlockingQueue queue = new BoundedBlockingQueue(2);   // \u4f7f\u7528capacity = 2\u521d\u59cb\u5316\u961f\u5217\u3002\n\nqueue.enqueue(1);   // \u751f\u4ea7\u8005\u7ebf\u7a0b\u5c061\u63d2\u5165\u961f\u5217\u3002\nqueue.dequeue();    // \u6d88\u8d39\u8005\u7ebf\u7a0b\u8c03\u7528dequeue\u5e76\u8fd4\u56de1\u3002\nqueue.dequeue();    // \u7531\u4e8e\u961f\u5217\u4e3a\u7a7a\uff0c\u6d88\u8d39\u8005\u7ebf\u7a0b\u88ab\u963b\u585e\u3002\nqueue.enqueue(0);   // \u751f\u4ea7\u8005\u7ebf\u7a0b\u5c060\u63d2\u5165\u961f\u5217\u3002\u6d88\u8d39\u8005\u7ebf\u7a0b\u88ab\u89e3\u9664\u963b\u585e\u540c\u65f6\u5c060\u5f39\u51fa\u961f\u5217\u5e76\u8fd4\u56de\u3002\nqueue.enqueue(2);   // \u751f\u4ea7\u8005\u7ebf\u7a0b\u5c062\u63d2\u5165\u961f\u5217\u3002\nqueue.enqueue(3);   // \u751f\u4ea7\u8005\u7ebf\u7a0b\u5c063\u63d2\u5165\u961f\u5217\u3002\nqueue.enqueue(4);   // \u751f\u4ea7\u8005\u7ebf\u7a0b\u7531\u4e8e\u961f\u5217\u957f\u5ea6\u5df2\u8fbe\u5230\u4e0a\u96502\u800c\u88ab\u963b\u585e\u3002\nqueue.dequeue();    // \u6d88\u8d39\u8005\u7ebf\u7a0b\u5c062\u4ece\u961f\u5217\u5f39\u51fa\u5e76\u8fd4\u56de\u3002\u751f\u4ea7\u8005\u7ebf\u7a0b\u89e3\u9664\u963b\u585e\u540c\u65f6\u5c064\u63d2\u5165\u961f\u5217\u3002\nqueue.size();       // \u961f\u5217\u4e2d\u8fd8\u67092\u4e2a\u5143\u7d20\u3002size()\u65b9\u6cd5\u5728\u6bcf\u7ec4\u6d4b\u8bd5\u7528\u4f8b\u6700\u540e\u8c03\u7528\u3002\n
\n\n

 

\n\n

\u793a\u4f8b 2:

\n\n
\n\u8f93\u5165:\n3\n4\n["BoundedBlockingQueue","enqueue","enqueue","enqueue","dequeue","dequeue","dequeue","enqueue"]\n[[3],[1],[0],[2],[],[],[],[3]]\n\n\u8f93\u51fa:\n[1,0,2,1]\n\n\u89e3\u91ca:\n\u751f\u4ea7\u8005\u7ebf\u7a0b\u6570\u76ee = 3\n\u6d88\u8d39\u8005\u7ebf\u7a0b\u6570\u76ee = 4\n\nBoundedBlockingQueue queue = new BoundedBlockingQueue(3);   // \u4f7f\u7528capacity = 3\u521d\u59cb\u5316\u961f\u5217\u3002\n\nqueue.enqueue(1);   // \u751f\u4ea7\u8005\u7ebf\u7a0bP1\u5c061\u63d2\u5165\u961f\u5217\u3002\nqueue.enqueue(0);   // \u751f\u4ea7\u8005\u7ebf\u7a0bP2\u5c060\u63d2\u5165\u961f\u5217\u3002\nqueue.enqueue(2);   // \u751f\u4ea7\u8005\u7ebf\u7a0bP3\u5c062\u63d2\u5165\u961f\u5217\u3002\nqueue.dequeue();    // \u6d88\u8d39\u8005\u7ebf\u7a0bC1\u8c03\u7528dequeue\u3002\nqueue.dequeue();    // \u6d88\u8d39\u8005\u7ebf\u7a0bC2\u8c03\u7528dequeue\u3002\nqueue.dequeue();    // \u6d88\u8d39\u8005\u7ebf\u7a0bC3\u8c03\u7528dequeue\u3002\nqueue.enqueue(3);   // \u5176\u4e2d\u4e00\u4e2a\u751f\u4ea7\u8005\u7ebf\u7a0b\u5c063\u63d2\u5165\u961f\u5217\u3002\nqueue.size();       // \u961f\u5217\u4e2d\u8fd8\u67091\u4e2a\u5143\u7d20\u3002\n\n\u7531\u4e8e\u751f\u4ea7\u8005/\u6d88\u8d39\u8005\u7ebf\u7a0b\u7684\u6570\u76ee\u53ef\u80fd\u5927\u4e8e1\uff0c\u6211\u4eec\u5e76\u4e0d\u77e5\u9053\u7ebf\u7a0b\u5982\u4f55\u88ab\u64cd\u4f5c\u7cfb\u7edf\u8c03\u5ea6\uff0c\u5373\u4f7f\u8f93\u5165\u770b\u4e0a\u53bb\u9690\u542b\u4e86\u987a\u5e8f\u3002\u56e0\u6b64\u4efb\u610f\u4e00\u79cd\u8f93\u51fa[1,0,2]\u6216[1,2,0]\u6216[0,1,2]\u6216[0,2,1]\u6216[2,0,1]\u6216[2,1,0]\u90fd\u53ef\u88ab\u63a5\u53d7\u3002
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class BoundedBlockingQueue {\npublic:\n BoundedBlockingQueue(int capacity) {\n \n }\n \n void enqueue(int element) {\n \n }\n \n int dequeue() {\n \n }\n \n int size() {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class BoundedBlockingQueue {\n\n public BoundedBlockingQueue(int capacity) {\n \n }\n \n public void enqueue(int element) throws InterruptedException {\n \n }\n \n public int dequeue() throws InterruptedException {\n \n }\n \n public int size() {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class BoundedBlockingQueue(object):\n def __init__(self, capacity):\n \"\"\"\n :type capacity: int\n \"\"\"\n \n\n def enqueue(self, element):\n \"\"\"\n :type element: int\n :rtype: void\n \"\"\"\n \n\n def dequeue(self):\n \"\"\"\n :rtype: int\n \"\"\"\n \n\n def size(self):\n \"\"\"\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class BoundedBlockingQueue(object):\n\n def __init__(self, capacity: int):\n \n\n def enqueue(self, element: int) -> None:\n \n\n def dequeue(self) -> int:\n \n\n def size(self) -> int:\n ", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1188](https://leetcode-cn.com/problems/design-bounded-blocking-queue)", "[\u8bbe\u8ba1\u6709\u9650\u963b\u585e\u961f\u5217](/solution/1100-1199/1188.Design%20Bounded%20Blocking%20Queue/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1188](https://leetcode.com/problems/design-bounded-blocking-queue)", "[Design Bounded Blocking Queue](/solution/1100-1199/1188.Design%20Bounded%20Blocking%20Queue/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1208", "frontend_question_id": "1111", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-nesting-depth-of-two-valid-parentheses-strings", "url_en": "https://leetcode.com/problems/maximum-nesting-depth-of-two-valid-parentheses-strings", "relative_path_cn": "/solution/1100-1199/1111.Maximum%20Nesting%20Depth%20of%20Two%20Valid%20Parentheses%20Strings/README.md", "relative_path_en": "/solution/1100-1199/1111.Maximum%20Nesting%20Depth%20of%20Two%20Valid%20Parentheses%20Strings/README_EN.md", "title_cn": "\u6709\u6548\u62ec\u53f7\u7684\u5d4c\u5957\u6df1\u5ea6", "title_en": "Maximum Nesting Depth of Two Valid Parentheses Strings", "question_title_slug": "maximum-nesting-depth-of-two-valid-parentheses-strings", "content_en": "

A string is a valid parentheses string (denoted VPS) if and only if it consists of "(" and ")" characters only, and:

\r\n\r\n
    \r\n\t
  • It is the empty string, or
  • \r\n\t
  • It can be written as AB (A concatenated with B), where A and B are VPS's, or
  • \r\n\t
  • It can be written as (A), where A is a VPS.
  • \r\n
\r\n\r\n

We can similarly define the nesting depth depth(S) of any VPS S as follows:

\r\n\r\n
    \r\n\t
  • depth("") = 0
  • \r\n\t
  • depth(A + B) = max(depth(A), depth(B)), where A and B are VPS's
  • \r\n\t
  • depth("(" + A + ")") = 1 + depth(A), where A is a VPS.
  • \r\n
\r\n\r\n

For example,  """()()", and "()(()())" are VPS's (with nesting depths 0, 1, and 2), and ")(" and "(()" are not VPS's.

\r\n\r\n

 

\r\n\r\n

Given a VPS seq, split it into two disjoint subsequences A and B, such that A and B are VPS's (and A.length + B.length = seq.length).

\r\n\r\n

Now choose any such A and B such that max(depth(A), depth(B)) is the minimum possible value.

\r\n\r\n

Return an answer array (of length seq.length) that encodes such a choice of A and Banswer[i] = 0 if seq[i] is part of A, else answer[i] = 1.  Note that even though multiple answers may exist, you may return any of them.

\r\n\n

 

\n

Example 1:

\n\n
\nInput: seq = "(()())"\nOutput: [0,1,1,1,1,0]\n
\n\n

Example 2:

\n\n
\nInput: seq = "()(())()"\nOutput: [0,0,0,1,1,0,1,1]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= seq.size <= 10000
  • \n
\n", "content_cn": "

\u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32 \u5b9a\u4e49\uff1a\u5bf9\u4e8e\u6bcf\u4e2a\u5de6\u62ec\u53f7\uff0c\u90fd\u80fd\u627e\u5230\u4e0e\u4e4b\u5bf9\u5e94\u7684\u53f3\u62ec\u53f7\uff0c\u53cd\u4e4b\u4ea6\u7136\u3002\u8be6\u60c5\u53c2\u89c1\u9898\u672b\u300c\u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32\u300d\u90e8\u5206\u3002

\n\n

\u5d4c\u5957\u6df1\u5ea6 depth \u5b9a\u4e49\uff1a\u5373\u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32\u5d4c\u5957\u7684\u5c42\u6570\uff0cdepth(A) \u8868\u793a\u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32 A \u7684\u5d4c\u5957\u6df1\u5ea6\u3002\u8be6\u60c5\u53c2\u89c1\u9898\u672b\u300c\u5d4c\u5957\u6df1\u5ea6\u300d\u90e8\u5206\u3002

\n\n

\u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32\u7c7b\u578b\u4e0e\u5bf9\u5e94\u7684\u5d4c\u5957\u6df1\u5ea6\u8ba1\u7b97\u65b9\u6cd5\u5982\u4e0b\u56fe\u6240\u793a\uff1a

\n\n

\"\"

\n\n

 

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u300c\u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32\u300d seq\uff0c\u8bf7\u4f60\u5c06\u5176\u5206\u6210\u4e24\u4e2a\u4e0d\u76f8\u4ea4\u7684\u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32\uff0cA \u548c B\uff0c\u5e76\u4f7f\u8fd9\u4e24\u4e2a\u5b57\u7b26\u4e32\u7684\u6df1\u5ea6\u6700\u5c0f\u3002

\n\n
    \n\t
  • \u4e0d\u76f8\u4ea4\uff1a\u6bcf\u4e2a seq[i] \u53ea\u80fd\u5206\u7ed9 A \u548c B \u4e8c\u8005\u4e2d\u7684\u4e00\u4e2a\uff0c\u4e0d\u80fd\u65e2\u5c5e\u4e8e A \u4e5f\u5c5e\u4e8e B \u3002
  • \n\t
  • A \u6216 B \u4e2d\u7684\u5143\u7d20\u5728\u539f\u5b57\u7b26\u4e32\u4e2d\u53ef\u4ee5\u4e0d\u8fde\u7eed\u3002
  • \n\t
  • A.length + B.length = seq.length
  • \n\t
  • \u6df1\u5ea6\u6700\u5c0f\uff1amax(depth(A), depth(B)) \u7684\u53ef\u80fd\u53d6\u503c\u6700\u5c0f\u3002 
  • \n
\n\n

\u5212\u5206\u65b9\u6848\u7528\u4e00\u4e2a\u957f\u5ea6\u4e3a seq.length \u7684\u7b54\u6848\u6570\u7ec4 answer \u8868\u793a\uff0c\u7f16\u7801\u89c4\u5219\u5982\u4e0b\uff1a

\n\n
    \n\t
  • answer[i] = 0\uff0cseq[i] \u5206\u7ed9 A \u3002
  • \n\t
  • answer[i] = 1\uff0cseq[i] \u5206\u7ed9 B \u3002
  • \n
\n\n

\u5982\u679c\u5b58\u5728\u591a\u4e2a\u6ee1\u8db3\u8981\u6c42\u7684\u7b54\u6848\uff0c\u53ea\u9700\u8fd4\u56de\u5176\u4e2d\u4efb\u610f \u4e00\u4e2a \u5373\u53ef\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aseq = "(()())"\n\u8f93\u51fa\uff1a[0,1,1,1,1,0]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aseq = "()(())()"\n\u8f93\u51fa\uff1a[0,0,0,1,1,0,1,1]\n\u89e3\u91ca\uff1a\u672c\u793a\u4f8b\u7b54\u6848\u4e0d\u552f\u4e00\u3002\n\u6309\u6b64\u8f93\u51fa A = "()()", B = "()()", max(depth(A), depth(B)) = 1\uff0c\u5b83\u4eec\u7684\u6df1\u5ea6\u6700\u5c0f\u3002\n\u50cf [1,1,1,0,0,1,1,1]\uff0c\u4e5f\u662f\u6b63\u786e\u7ed3\u679c\uff0c\u5176\u4e2d A = "()()()", B = "()", max(depth(A), depth(B)) = 1 \u3002 \n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 < seq.size <= 10000
  • \n
\n\n

 

\n\n

\u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32\uff1a

\n\n
\u4ec5\u7531 "(" \u548c ")" \u6784\u6210\u7684\u5b57\u7b26\u4e32\uff0c\u5bf9\u4e8e\u6bcf\u4e2a\u5de6\u62ec\u53f7\uff0c\u90fd\u80fd\u627e\u5230\u4e0e\u4e4b\u5bf9\u5e94\u7684\u53f3\u62ec\u53f7\uff0c\u53cd\u4e4b\u4ea6\u7136\u3002\n\u4e0b\u8ff0\u51e0\u79cd\u60c5\u51b5\u540c\u6837\u5c5e\u4e8e\u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32\uff1a\n\n  1. \u7a7a\u5b57\u7b26\u4e32\n  2. \u8fde\u63a5\uff0c\u53ef\u4ee5\u8bb0\u4f5c AB\uff08A \u4e0e B \u8fde\u63a5\uff09\uff0c\u5176\u4e2d A \u548c B \u90fd\u662f\u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32\n  3. \u5d4c\u5957\uff0c\u53ef\u4ee5\u8bb0\u4f5c (A)\uff0c\u5176\u4e2d A \u662f\u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32\n
\n\n

\u5d4c\u5957\u6df1\u5ea6\uff1a

\n\n
\u7c7b\u4f3c\u5730\uff0c\u6211\u4eec\u53ef\u4ee5\u5b9a\u4e49\u4efb\u610f\u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32 s \u7684 \u5d4c\u5957\u6df1\u5ea6 depth(S)\uff1a\n\n  1. s \u4e3a\u7a7a\u65f6\uff0cdepth("") = 0\n  2. s \u4e3a A \u4e0e B \u8fde\u63a5\u65f6\uff0cdepth(A + B) = max(depth(A), depth(B))\uff0c\u5176\u4e2d A \u548c B \u90fd\u662f\u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32\n  3. s \u4e3a\u5d4c\u5957\u60c5\u51b5\uff0cdepth("(" + A + ")") = 1 + depth(A)\uff0c\u5176\u4e2d A \u662f\u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32\n\n\u4f8b\u5982\uff1a""\uff0c"()()"\uff0c\u548c "()(()())" \u90fd\u662f\u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32\uff0c\u5d4c\u5957\u6df1\u5ea6\u5206\u522b\u4e3a 0\uff0c1\uff0c2\uff0c\u800c ")(" \u548c "(()" \u90fd\u4e0d\u662f\u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32\u3002\n
\n", "tags_en": ["Greedy", "Binary Search"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector maxDepthAfterSplit(string seq) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] maxDepthAfterSplit(String seq) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxDepthAfterSplit(self, seq):\n \"\"\"\n :type seq: str\n :rtype: List[int]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxDepthAfterSplit(self, seq: str) -> List[int]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* maxDepthAfterSplit(char * seq, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] MaxDepthAfterSplit(string seq) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} seq\n * @return {number[]}\n */\nvar maxDepthAfterSplit = function(seq) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} seq\n# @return {Integer[]}\ndef max_depth_after_split(seq)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxDepthAfterSplit(_ seq: String) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxDepthAfterSplit(seq string) []int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxDepthAfterSplit(seq: String): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxDepthAfterSplit(seq: String): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_depth_after_split(seq: String) -> Vec {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $seq\n * @return Integer[]\n */\n function maxDepthAfterSplit($seq) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxDepthAfterSplit(seq: string): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-depth-after-split seq)\n (-> string? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1111](https://leetcode-cn.com/problems/maximum-nesting-depth-of-two-valid-parentheses-strings)", "[\u6709\u6548\u62ec\u53f7\u7684\u5d4c\u5957\u6df1\u5ea6](/solution/1100-1199/1111.Maximum%20Nesting%20Depth%20of%20Two%20Valid%20Parentheses%20Strings/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1111](https://leetcode.com/problems/maximum-nesting-depth-of-two-valid-parentheses-strings)", "[Maximum Nesting Depth of Two Valid Parentheses Strings](/solution/1100-1199/1111.Maximum%20Nesting%20Depth%20of%20Two%20Valid%20Parentheses%20Strings/README_EN.md)", "`Greedy`,`Binary Search`", "Medium", ""]}, {"question_id": "1207", "frontend_question_id": "1110", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/delete-nodes-and-return-forest", "url_en": "https://leetcode.com/problems/delete-nodes-and-return-forest", "relative_path_cn": "/solution/1100-1199/1110.Delete%20Nodes%20And%20Return%20Forest/README.md", "relative_path_en": "/solution/1100-1199/1110.Delete%20Nodes%20And%20Return%20Forest/README_EN.md", "title_cn": "\u5220\u70b9\u6210\u6797", "title_en": "Delete Nodes And Return Forest", "question_title_slug": "delete-nodes-and-return-forest", "content_en": "

Given the root of a binary tree, each node in the tree has a distinct value.

\n\n

After deleting all nodes with a value in to_delete, we are left with a forest (a disjoint union of trees).

\n\n

Return the roots of the trees in the remaining forest. You may return the result in any order.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: root = [1,2,3,4,5,6,7], to_delete = [3,5]\nOutput: [[1,2,null,4],[6],[7]]\n
\n\n

Example 2:

\n\n
\nInput: root = [1,2,4,null,3], to_delete = [3]\nOutput: [[1,2,4]]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The number of nodes in the given tree is at most 1000.
  • \n\t
  • Each node has a distinct value between 1 and 1000.
  • \n\t
  • to_delete.length <= 1000
  • \n\t
  • to_delete contains distinct values between 1 and 1000.
  • \n
\n", "content_cn": "

\u7ed9\u51fa\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9 root\uff0c\u6811\u4e0a\u6bcf\u4e2a\u8282\u70b9\u90fd\u6709\u4e00\u4e2a\u4e0d\u540c\u7684\u503c\u3002

\n\n

\u5982\u679c\u8282\u70b9\u503c\u5728 to_delete \u4e2d\u51fa\u73b0\uff0c\u6211\u4eec\u5c31\u628a\u8be5\u8282\u70b9\u4ece\u6811\u4e0a\u5220\u53bb\uff0c\u6700\u540e\u5f97\u5230\u4e00\u4e2a\u68ee\u6797\uff08\u4e00\u4e9b\u4e0d\u76f8\u4ea4\u7684\u6811\u6784\u6210\u7684\u96c6\u5408\uff09\u3002

\n\n

\u8fd4\u56de\u68ee\u6797\u4e2d\u7684\u6bcf\u68f5\u6811\u3002\u4f60\u53ef\u4ee5\u6309\u4efb\u610f\u987a\u5e8f\u7ec4\u7ec7\u7b54\u6848\u3002

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1aroot = [1,2,3,4,5,6,7], to_delete = [3,5]\n\u8f93\u51fa\uff1a[[1,2,null,4],[6],[7]]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u6811\u4e2d\u7684\u8282\u70b9\u6570\u6700\u5927\u4e3a 1000\u3002
  • \n\t
  • \u6bcf\u4e2a\u8282\u70b9\u90fd\u6709\u4e00\u4e2a\u4ecb\u4e8e 1 \u5230 1000 \u4e4b\u95f4\u7684\u503c\uff0c\u4e14\u5404\u4e0d\u76f8\u540c\u3002
  • \n\t
  • to_delete.length <= 1000
  • \n\t
  • to_delete \u5305\u542b\u4e00\u4e9b\u4ece 1 \u5230 1000\u3001\u5404\u4e0d\u76f8\u540c\u7684\u503c\u3002
  • \n
\n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector delNodes(TreeNode* root, vector& to_delete) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public List delNodes(TreeNode root, int[] to_delete) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def delNodes(self, root, to_delete):\n \"\"\"\n :type root: TreeNode\n :type to_delete: List[int]\n :rtype: List[TreeNode]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def delNodes(self, root: TreeNode, to_delete: List[int]) -> List[TreeNode]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nstruct TreeNode** delNodes(struct TreeNode* root, int* to_delete, int to_deleteSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public IList DelNodes(TreeNode root, int[] to_delete) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number[]} to_delete\n * @return {TreeNode[]}\n */\nvar delNodes = function(root, to_delete) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @param {Integer[]} to_delete\n# @return {TreeNode[]}\ndef del_nodes(root, to_delete)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func delNodes(_ root: TreeNode?, _ to_delete: [Int]) -> [TreeNode?] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc delNodes(root *TreeNode, to_delete []int) []*TreeNode {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def delNodes(root: TreeNode, to_delete: Array[Int]): List[TreeNode] = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun delNodes(root: TreeNode?, to_delete: IntArray): List {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n// \n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn del_nodes(root: Option>>, to_delete: Vec) -> Vec>>> {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param Integer[] $to_delete\n * @return TreeNode[]\n */\n function delNodes($root, $to_delete) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction delNodes(root: TreeNode | null, to_delete: number[]): Array {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1110](https://leetcode-cn.com/problems/delete-nodes-and-return-forest)", "[\u5220\u70b9\u6210\u6797](/solution/1100-1199/1110.Delete%20Nodes%20And%20Return%20Forest/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1110](https://leetcode.com/problems/delete-nodes-and-return-forest)", "[Delete Nodes And Return Forest](/solution/1100-1199/1110.Delete%20Nodes%20And%20Return%20Forest/README_EN.md)", "`Tree`,`Depth-first Search`", "Medium", ""]}, {"question_id": "1206", "frontend_question_id": "1109", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/corporate-flight-bookings", "url_en": "https://leetcode.com/problems/corporate-flight-bookings", "relative_path_cn": "/solution/1100-1199/1109.Corporate%20Flight%20Bookings/README.md", "relative_path_en": "/solution/1100-1199/1109.Corporate%20Flight%20Bookings/README_EN.md", "title_cn": "\u822a\u73ed\u9884\u8ba2\u7edf\u8ba1", "title_en": "Corporate Flight Bookings", "question_title_slug": "corporate-flight-bookings", "content_en": "

There are n flights that are labeled from 1 to n.

\n\n

You are given an array of flight bookings bookings, where bookings[i] = [firsti, lasti, seatsi] represents a booking for flights firsti through lasti (inclusive) with seatsi seats reserved for each flight in the range.

\n\n

Return an array answer of length n, where answer[i] is the total number of seats reserved for flight i.

\n\n

 

\n

Example 1:

\n\n
\nInput: bookings = [[1,2,10],[2,3,20],[2,5,25]], n = 5\nOutput: [10,55,45,25,25]\nExplanation:\nFlight labels:        1   2   3   4   5\nBooking 1 reserved:  10  10\nBooking 2 reserved:      20  20\nBooking 3 reserved:      25  25  25  25\nTotal seats:         10  55  45  25  25\nHence, answer = [10,55,45,25,25]\n
\n\n

Example 2:

\n\n
\nInput: bookings = [[1,2,10],[2,2,15]], n = 2\nOutput: [10,25]\nExplanation:\nFlight labels:        1   2\nBooking 1 reserved:  10  10\nBooking 2 reserved:      15\nTotal seats:         10  25\nHence, answer = [10,25]\n\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 2 * 104
  • \n\t
  • 1 <= bookings.length <= 2 * 104
  • \n\t
  • bookings[i].length == 3
  • \n\t
  • 1 <= firsti <= lasti <= n
  • \n\t
  • 1 <= seatsi <= 104
  • \n
\n", "content_cn": "

\u8fd9\u91cc\u6709\u00a0n\u00a0\u4e2a\u822a\u73ed\uff0c\u5b83\u4eec\u5206\u522b\u4ece 1 \u5230 n \u8fdb\u884c\u7f16\u53f7\u3002

\n\n

\u6709\u4e00\u4efd\u822a\u73ed\u9884\u8ba2\u8868\u00a0bookings \uff0c\u8868\u4e2d\u7b2c\u00a0i\u00a0\u6761\u9884\u8ba2\u8bb0\u5f55\u00a0bookings[i] = [firsti, lasti, seatsi]\u00a0\u610f\u5473\u7740\u5728\u4ece firsti\u00a0\u5230 lasti \uff08\u5305\u542b firsti \u548c lasti \uff09\u7684 \u6bcf\u4e2a\u822a\u73ed \u4e0a\u9884\u8ba2\u4e86 seatsi\u00a0\u4e2a\u5ea7\u4f4d\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u6570\u7ec4\u00a0answer\uff0c\u5176\u4e2d answer[i] \u662f\u822a\u73ed i \u4e0a\u9884\u8ba2\u7684\u5ea7\u4f4d\u603b\u6570\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1abookings = [[1,2,10],[2,3,20],[2,5,25]], n = 5\n\u8f93\u51fa\uff1a[10,55,45,25,25]\n\u89e3\u91ca\uff1a\n\u822a\u73ed\u7f16\u53f7        1   2   3   4   5\n\u9884\u8ba2\u8bb0\u5f55 1 \uff1a   10  10\n\u9884\u8ba2\u8bb0\u5f55 2 \uff1a       20  20\n\u9884\u8ba2\u8bb0\u5f55 3 \uff1a       25  25  25  25\n\u603b\u5ea7\u4f4d\u6570\uff1a      10  55  45  25  25\n\u56e0\u6b64\uff0canswer = [10,55,45,25,25]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1abookings = [[1,2,10],[2,2,15]], n = 2\n\u8f93\u51fa\uff1a[10,25]\n\u89e3\u91ca\uff1a\n\u822a\u73ed\u7f16\u53f7        1   2\n\u9884\u8ba2\u8bb0\u5f55 1 \uff1a   10  10\n\u9884\u8ba2\u8bb0\u5f55 2 \uff1a       15\n\u603b\u5ea7\u4f4d\u6570\uff1a      10  25\n\u56e0\u6b64\uff0canswer = [10,25]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 2 * 104
  • \n\t
  • 1 <= bookings.length <= 2 * 104
  • \n\t
  • bookings[i].length == 3
  • \n\t
  • 1 <= firsti <= lasti <= n
  • \n\t
  • 1 <= seatsi <= 104
  • \n
\n", "tags_en": ["Array", "Math"], "tags_cn": ["\u6570\u7ec4", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector corpFlightBookings(vector>& bookings, int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] corpFlightBookings(int[][] bookings, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def corpFlightBookings(self, bookings, n):\n \"\"\"\n :type bookings: List[List[int]]\n :type n: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def corpFlightBookings(self, bookings: List[List[int]], n: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* corpFlightBookings(int** bookings, int bookingsSize, int* bookingsColSize, int n, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] CorpFlightBookings(int[][] bookings, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} bookings\n * @param {number} n\n * @return {number[]}\n */\nvar corpFlightBookings = function(bookings, n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} bookings\n# @param {Integer} n\n# @return {Integer[]}\ndef corp_flight_bookings(bookings, n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func corpFlightBookings(_ bookings: [[Int]], _ n: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func corpFlightBookings(bookings [][]int, n int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def corpFlightBookings(bookings: Array[Array[Int]], n: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun corpFlightBookings(bookings: Array, n: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn corp_flight_bookings(bookings: Vec>, n: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $bookings\n * @param Integer $n\n * @return Integer[]\n */\n function corpFlightBookings($bookings, $n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function corpFlightBookings(bookings: number[][], n: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (corp-flight-bookings bookings n)\n (-> (listof (listof exact-integer?)) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1109](https://leetcode-cn.com/problems/corporate-flight-bookings)", "[\u822a\u73ed\u9884\u8ba2\u7edf\u8ba1](/solution/1100-1199/1109.Corporate%20Flight%20Bookings/README.md)", "`\u6570\u7ec4`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1109](https://leetcode.com/problems/corporate-flight-bookings)", "[Corporate Flight Bookings](/solution/1100-1199/1109.Corporate%20Flight%20Bookings/README_EN.md)", "`Array`,`Math`", "Medium", ""]}, {"question_id": "1205", "frontend_question_id": "1108", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/defanging-an-ip-address", "url_en": "https://leetcode.com/problems/defanging-an-ip-address", "relative_path_cn": "/solution/1100-1199/1108.Defanging%20an%20IP%20Address/README.md", "relative_path_en": "/solution/1100-1199/1108.Defanging%20an%20IP%20Address/README_EN.md", "title_cn": "IP \u5730\u5740\u65e0\u6548\u5316", "title_en": "Defanging an IP Address", "question_title_slug": "defanging-an-ip-address", "content_en": "

Given a valid (IPv4) IP address, return a defanged version of that IP address.

\r\n\r\n

A defanged IP address replaces every period "." with "[.]".

\r\n\r\n

 

\r\n

Example 1:

\r\n
Input: address = \"1.1.1.1\"\r\nOutput: \"1[.]1[.]1[.]1\"\r\n

Example 2:

\r\n
Input: address = \"255.100.50.0\"\r\nOutput: \"255[.]100[.]50[.]0\"\r\n
\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • The given address is a valid IPv4 address.
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6709\u6548\u7684 IPv4 \u5730\u5740 address\uff0c\u8fd4\u56de\u8fd9\u4e2a IP \u5730\u5740\u7684\u65e0\u6548\u5316\u7248\u672c\u3002

\n\n

\u6240\u8c13\u65e0\u6548\u5316 IP \u5730\u5740\uff0c\u5176\u5b9e\u5c31\u662f\u7528 "[.]" \u4ee3\u66ff\u4e86\u6bcf\u4e2a "."\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aaddress = "1.1.1.1"\n\u8f93\u51fa\uff1a"1[.]1[.]1[.]1"\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aaddress = "255.100.50.0"\n\u8f93\u51fa\uff1a"255[.]100[.]50[.]0"\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u7ed9\u51fa\u7684 address \u662f\u4e00\u4e2a\u6709\u6548\u7684 IPv4 \u5730\u5740
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string defangIPaddr(string address) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String defangIPaddr(String address) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def defangIPaddr(self, address):\n \"\"\"\n :type address: str\n :rtype: str\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def defangIPaddr(self, address: str) -> str:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * defangIPaddr(char * address){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string DefangIPaddr(string address) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} address\n * @return {string}\n */\nvar defangIPaddr = function(address) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} address\n# @return {String}\ndef defang_i_paddr(address)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func defangIPaddr(_ address: String) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func defangIPaddr(address string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def defangIPaddr(address: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun defangIPaddr(address: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn defang_i_paddr(address: String) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $address\n * @return String\n */\n function defangIPaddr($address) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function defangIPaddr(address: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (defang-i-paddr address)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1108](https://leetcode-cn.com/problems/defanging-an-ip-address)", "[IP \u5730\u5740\u65e0\u6548\u5316](/solution/1100-1199/1108.Defanging%20an%20IP%20Address/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1108](https://leetcode.com/problems/defanging-an-ip-address)", "[Defanging an IP Address](/solution/1100-1199/1108.Defanging%20an%20IP%20Address/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1204", "frontend_question_id": "1107", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/new-users-daily-count", "url_en": "https://leetcode.com/problems/new-users-daily-count", "relative_path_cn": "/solution/1100-1199/1107.New%20Users%20Daily%20Count/README.md", "relative_path_en": "/solution/1100-1199/1107.New%20Users%20Daily%20Count/README_EN.md", "title_cn": "\u6bcf\u65e5\u65b0\u7528\u6237\u7edf\u8ba1", "title_en": "New Users Daily Count", "question_title_slug": "new-users-daily-count", "content_en": "

Table: Traffic

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| user_id       | int     |\n| activity      | enum    |\n| activity_date | date    |\n+---------------+---------+\nThere is no primary key for this table, it may have duplicate rows.\nThe activity column is an ENUM type of ('login', 'logout', 'jobs', 'groups', 'homepage').\n
\n\n

 

\n\n

Write an SQL query that reports for every date within at most 90 days from today, the number of users that logged in for the first time on that date. Assume today is 2019-06-30.

\n\n

The query result format is in the following example:

\n\n
\nTraffic table:\n+---------+----------+---------------+\n| user_id | activity | activity_date |\n+---------+----------+---------------+\n| 1       | login    | 2019-05-01    |\n| 1       | homepage | 2019-05-01    |\n| 1       | logout   | 2019-05-01    |\n| 2       | login    | 2019-06-21    |\n| 2       | logout   | 2019-06-21    |\n| 3       | login    | 2019-01-01    |\n| 3       | jobs     | 2019-01-01    |\n| 3       | logout   | 2019-01-01    |\n| 4       | login    | 2019-06-21    |\n| 4       | groups   | 2019-06-21    |\n| 4       | logout   | 2019-06-21    |\n| 5       | login    | 2019-03-01    |\n| 5       | logout   | 2019-03-01    |\n| 5       | login    | 2019-06-21    |\n| 5       | logout   | 2019-06-21    |\n+---------+----------+---------------+\n\nResult table:\n+------------+-------------+\n| login_date | user_count  |\n+------------+-------------+\n| 2019-05-01 | 1           |\n| 2019-06-21 | 2           |\n+------------+-------------+\nNote that we only care about dates with non zero user count.\nThe user with id 5 first logged in on 2019-03-01 so he's not counted on 2019-06-21.\n
\n", "content_cn": "

Traffic \u8868\uff1a

\n\n
+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| user_id       | int     |\n| activity      | enum    |\n| activity_date | date    |\n+---------------+---------+\n\u8be5\u8868\u6ca1\u6709\u4e3b\u952e\uff0c\u5b83\u53ef\u80fd\u6709\u91cd\u590d\u7684\u884c\u3002\nactivity \u5217\u662f ENUM \u7c7b\u578b\uff0c\u53ef\u80fd\u53d6 ('login', 'logout', 'jobs', 'groups', 'homepage') \u51e0\u4e2a\u503c\u4e4b\u4e00\u3002\n
\n\n

 

\n\n

\u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\uff0c\u4ee5\u67e5\u8be2\u4ece\u4eca\u5929\u8d77\u6700\u591a 90 \u5929\u5185\uff0c\u6bcf\u4e2a\u65e5\u671f\u8be5\u65e5\u671f\u9996\u6b21\u767b\u5f55\u7684\u7528\u6237\u6570\u3002\u5047\u8bbe\u4eca\u5929\u662f 2019-06-30.

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a\uff1a

\n\n
Traffic \u8868\uff1a\n+---------+----------+---------------+\n| user_id | activity | activity_date |\n+---------+----------+---------------+\n| 1       | login    | 2019-05-01    |\n| 1       | homepage | 2019-05-01    |\n| 1       | logout   | 2019-05-01    |\n| 2       | login    | 2019-06-21    |\n| 2       | logout   | 2019-06-21    |\n| 3       | login    | 2019-01-01    |\n| 3       | jobs     | 2019-01-01    |\n| 3       | logout   | 2019-01-01    |\n| 4       | login    | 2019-06-21    |\n| 4       | groups   | 2019-06-21    |\n| 4       | logout   | 2019-06-21    |\n| 5       | login    | 2019-03-01    |\n| 5       | logout   | 2019-03-01    |\n| 5       | login    | 2019-06-21    |\n| 5       | logout   | 2019-06-21    |\n+---------+----------+---------------+\n\nResult \u8868\uff1a\n+------------+-------------+\n| login_date | user_count  |\n+------------+-------------+\n| 2019-05-01 | 1           |\n| 2019-06-21 | 2           |\n+------------+-------------+\n\u8bf7\u6ce8\u610f\uff0c\u6211\u4eec\u53ea\u5173\u5fc3\u7528\u6237\u6570\u975e\u96f6\u7684\u65e5\u671f.\nID \u4e3a 5 \u7684\u7528\u6237\u7b2c\u4e00\u6b21\u767b\u9646\u4e8e 2019-03-01\uff0c\u56e0\u6b64\u4ed6\u4e0d\u7b97\u5728 2019-06-21 \u7684\u7684\u7edf\u8ba1\u5185\u3002\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1107](https://leetcode-cn.com/problems/new-users-daily-count)", "[\u6bcf\u65e5\u65b0\u7528\u6237\u7edf\u8ba1](/solution/1100-1199/1107.New%20Users%20Daily%20Count/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1107](https://leetcode.com/problems/new-users-daily-count)", "[New Users Daily Count](/solution/1100-1199/1107.New%20Users%20Daily%20Count/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1203", "frontend_question_id": "1114", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/print-in-order", "url_en": "https://leetcode.com/problems/print-in-order", "relative_path_cn": "/solution/1100-1199/1114.Print%20in%20Order/README.md", "relative_path_en": "/solution/1100-1199/1114.Print%20in%20Order/README_EN.md", "title_cn": "\u6309\u5e8f\u6253\u5370", "title_en": "Print in Order", "question_title_slug": "print-in-order", "content_en": "

Suppose we have a class:

\n\n
\npublic class Foo {\n  public void first() { print("first"); }\n  public void second() { print("second"); }\n  public void third() { print("third"); }\n}\n
\n\n

The same instance of Foo will be passed to three different threads. Thread A will call first(), thread B will call second(), and thread C will call third(). Design a mechanism and modify the program to ensure that second() is executed after first(), and third() is executed after second().

\n\n

Note:

\n\n

We do not know how the threads will be scheduled in the operating system, even though the numbers in the input seem to imply the ordering. The input format you see is mainly to ensure our tests' comprehensiveness.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [1,2,3]\nOutput: "firstsecondthird"\nExplanation: There are three threads being fired asynchronously. The input [1,2,3] means thread A calls first(), thread B calls second(), and thread C calls third(). "firstsecondthird" is the correct output.\n
\n\n

Example 2:

\n\n
\nInput: nums = [1,3,2]\nOutput: "firstsecondthird"\nExplanation: The input [1,3,2] means thread A calls first(), thread B calls third(), and thread C calls second(). "firstsecondthird" is the correct output.\n
\n", "content_cn": "

\u6211\u4eec\u63d0\u4f9b\u4e86\u4e00\u4e2a\u7c7b\uff1a

\n\n
\npublic class Foo {\n\u00a0 public void first() { print(\"first\"); }\n\u00a0 public void second() { print(\"second\"); }\n\u00a0 public void third() { print(\"third\"); }\n}
\n\n

\u4e09\u4e2a\u4e0d\u540c\u7684\u7ebf\u7a0b A\u3001B\u3001C \u5c06\u4f1a\u5171\u7528\u4e00\u4e2a\u00a0Foo\u00a0\u5b9e\u4f8b\u3002

\n\n
    \n\t
  • \u4e00\u4e2a\u5c06\u4f1a\u8c03\u7528 first() \u65b9\u6cd5
  • \n\t
  • \u4e00\u4e2a\u5c06\u4f1a\u8c03\u7528\u00a0second() \u65b9\u6cd5
  • \n\t
  • \u8fd8\u6709\u4e00\u4e2a\u5c06\u4f1a\u8c03\u7528 third() \u65b9\u6cd5
  • \n
\n\n

\u8bf7\u8bbe\u8ba1\u4fee\u6539\u7a0b\u5e8f\uff0c\u4ee5\u786e\u4fdd second() \u65b9\u6cd5\u5728 first() \u65b9\u6cd5\u4e4b\u540e\u88ab\u6267\u884c\uff0cthird() \u65b9\u6cd5\u5728 second() \u65b9\u6cd5\u4e4b\u540e\u88ab\u6267\u884c\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1:

\n\n
\n\u8f93\u5165: [1,2,3]\n\u8f93\u51fa: \"firstsecondthird\"\n\u89e3\u91ca: \n\u6709\u4e09\u4e2a\u7ebf\u7a0b\u4f1a\u88ab\u5f02\u6b65\u542f\u52a8\u3002\n\u8f93\u5165 [1,2,3] \u8868\u793a\u7ebf\u7a0b A \u5c06\u4f1a\u8c03\u7528 first() \u65b9\u6cd5\uff0c\u7ebf\u7a0b B \u5c06\u4f1a\u8c03\u7528 second() \u65b9\u6cd5\uff0c\u7ebf\u7a0b C \u5c06\u4f1a\u8c03\u7528 third() \u65b9\u6cd5\u3002\n\u6b63\u786e\u7684\u8f93\u51fa\u662f \"firstsecondthird\"\u3002\n
\n\n

\u793a\u4f8b 2:

\n\n
\n\u8f93\u5165: [1,3,2]\n\u8f93\u51fa: \"firstsecondthird\"\n\u89e3\u91ca: \n\u8f93\u5165 [1,3,2] \u8868\u793a\u7ebf\u7a0b A \u5c06\u4f1a\u8c03\u7528 first() \u65b9\u6cd5\uff0c\u7ebf\u7a0b B \u5c06\u4f1a\u8c03\u7528 third() \u65b9\u6cd5\uff0c\u7ebf\u7a0b C \u5c06\u4f1a\u8c03\u7528 second() \u65b9\u6cd5\u3002\n\u6b63\u786e\u7684\u8f93\u51fa\u662f \"firstsecondthird\"\u3002
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u5c3d\u7ba1\u8f93\u5165\u4e2d\u7684\u6570\u5b57\u4f3c\u4e4e\u6697\u793a\u4e86\u987a\u5e8f\uff0c\u4f46\u662f\u6211\u4eec\u5e76\u4e0d\u4fdd\u8bc1\u7ebf\u7a0b\u5728\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u7684\u8c03\u5ea6\u987a\u5e8f\u3002
  • \n\t
  • \u4f60\u770b\u5230\u7684\u8f93\u5165\u683c\u5f0f\u4e3b\u8981\u662f\u4e3a\u4e86\u786e\u4fdd\u6d4b\u8bd5\u7684\u5168\u9762\u6027\u3002
  • \n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Foo {\npublic:\n Foo() {\n \n }\n\n void first(function printFirst) {\n \n // printFirst() outputs \"first\". Do not change or remove this line.\n printFirst();\n }\n\n void second(function printSecond) {\n \n // printSecond() outputs \"second\". Do not change or remove this line.\n printSecond();\n }\n\n void third(function printThird) {\n \n // printThird() outputs \"third\". Do not change or remove this line.\n printThird();\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Foo {\n\n public Foo() {\n \n }\n\n public void first(Runnable printFirst) throws InterruptedException {\n \n // printFirst.run() outputs \"first\". Do not change or remove this line.\n printFirst.run();\n }\n\n public void second(Runnable printSecond) throws InterruptedException {\n \n // printSecond.run() outputs \"second\". Do not change or remove this line.\n printSecond.run();\n }\n\n public void third(Runnable printThird) throws InterruptedException {\n \n // printThird.run() outputs \"third\". Do not change or remove this line.\n printThird.run();\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Foo(object):\n def __init__(self):\n pass\n\n\n def first(self, printFirst):\n \"\"\"\n :type printFirst: method\n :rtype: void\n \"\"\"\n \n # printFirst() outputs \"first\". Do not change or remove this line.\n printFirst()\n\n\n def second(self, printSecond):\n \"\"\"\n :type printSecond: method\n :rtype: void\n \"\"\"\n \n # printSecond() outputs \"second\". Do not change or remove this line.\n printSecond()\n \n \n def third(self, printThird):\n \"\"\"\n :type printThird: method\n :rtype: void\n \"\"\"\n \n # printThird() outputs \"third\". Do not change or remove this line.\n printThird()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Foo:\n def __init__(self):\n pass\n\n\n def first(self, printFirst: 'Callable[[], None]') -> None:\n \n # printFirst() outputs \"first\". Do not change or remove this line.\n printFirst()\n\n\n def second(self, printSecond: 'Callable[[], None]') -> None:\n \n # printSecond() outputs \"second\". Do not change or remove this line.\n printSecond()\n\n\n def third(self, printThird: 'Callable[[], None]') -> None:\n \n # printThird() outputs \"third\". Do not change or remove this line.\n printThird()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "typedef struct {\n // User defined data may be declared here.\n \n} Foo;\n\nFoo* fooCreate() {\n Foo* obj = (Foo*) malloc(sizeof(Foo));\n \n // Initialize user defined data here.\n \n return obj;\n}\n\nvoid first(Foo* obj) {\n \n // printFirst() outputs \"first\". Do not change or remove this line.\n printFirst();\n}\n\nvoid second(Foo* obj) {\n \n // printSecond() outputs \"second\". Do not change or remove this line.\n printSecond();\n}\n\nvoid third(Foo* obj) {\n \n // printThird() outputs \"third\". Do not change or remove this line.\n printThird();\n}\n\nvoid fooFree(Foo* obj) {\n // User defined data may be cleaned up here.\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Foo {\n\n public Foo() {\n \n }\n\n public void First(Action printFirst) {\n \n // printFirst() outputs \"first\". Do not change or remove this line.\n printFirst();\n }\n\n public void Second(Action printSecond) {\n \n // printSecond() outputs \"second\". Do not change or remove this line.\n printSecond();\n }\n\n public void Third(Action printThird) {\n \n // printThird() outputs \"third\". Do not change or remove this line.\n printThird();\n }\n}", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1114](https://leetcode-cn.com/problems/print-in-order)", "[\u6309\u5e8f\u6253\u5370](/solution/1100-1199/1114.Print%20in%20Order/README.md)", "", "\u7b80\u5355", ""], "md_table_row_en": ["[1114](https://leetcode.com/problems/print-in-order)", "[Print in Order](/solution/1100-1199/1114.Print%20in%20Order/README_EN.md)", "", "Easy", ""]}, {"question_id": "1202", "frontend_question_id": "1246", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/palindrome-removal", "url_en": "https://leetcode.com/problems/palindrome-removal", "relative_path_cn": "/solution/1200-1299/1246.Palindrome%20Removal/README.md", "relative_path_en": "/solution/1200-1299/1246.Palindrome%20Removal/README_EN.md", "title_cn": "\u5220\u9664\u56de\u6587\u5b50\u6570\u7ec4", "title_en": "Palindrome Removal", "question_title_slug": "palindrome-removal", "content_en": "

Given an integer array arr, in one move you can select a palindromic subarray arr[i], arr[i+1], ..., arr[j] where i <= j, and remove that subarray from the given array. Note that after removing a subarray, the elements on the left and on the right of that subarray move to fill the gap left by the removal.

\n\n

Return the minimum number of moves needed to remove all numbers from the array.

\n\n

 

\n

Example 1:

\n\n
\nInput: arr = [1,2]\nOutput: 2\n
\n\n

Example 2:

\n\n
\nInput: arr = [1,3,4,1,5]\nOutput: 3\nExplanation: Remove [4] then remove [1,3,1] then remove [5].\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= arr.length <= 100
  • \n\t
  • 1 <= arr[i] <= 20
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr\uff0c\u6bcf\u4e00\u6b21\u64cd\u4f5c\u4f60\u90fd\u53ef\u4ee5\u9009\u62e9\u5e76\u5220\u9664\u5b83\u7684\u4e00\u4e2a \u56de\u6587 \u5b50\u6570\u7ec4 arr[i], arr[i+1], ..., arr[j]\uff08 i <= j\uff09\u3002

\n\n

\u6ce8\u610f\uff0c\u6bcf\u5f53\u4f60\u5220\u9664\u6389\u4e00\u4e2a\u5b50\u6570\u7ec4\uff0c\u53f3\u4fa7\u5143\u7d20\u90fd\u4f1a\u81ea\u884c\u5411\u524d\u79fb\u52a8\u586b\u8865\u7a7a\u4f4d\u3002

\n\n

\u8bf7\u4f60\u8ba1\u7b97\u5e76\u8fd4\u56de\u4ece\u6570\u7ec4\u4e2d\u5220\u9664\u6240\u6709\u6570\u5b57\u6240\u9700\u7684\u6700\u5c11\u64cd\u4f5c\u6b21\u6570\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aarr = [1,2]\n\u8f93\u51fa\uff1a2\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aarr = [1,3,4,1,5]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u5148\u5220\u9664 [4]\uff0c\u7136\u540e\u5220\u9664 [1,3,1]\uff0c\u6700\u540e\u518d\u5220\u9664 [5]\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= arr.length <= 100
  • \n\t
  • 1 <= arr[i] <= 20
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minimumMoves(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minimumMoves(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimumMoves(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimumMoves(self, arr: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minimumMoves(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinimumMoves(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar minimumMoves = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef minimum_moves(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimumMoves(_ arr: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimumMoves(arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimumMoves(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimumMoves(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimum_moves(arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function minimumMoves($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimumMoves(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimum-moves arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1246](https://leetcode-cn.com/problems/palindrome-removal)", "[\u5220\u9664\u56de\u6587\u5b50\u6570\u7ec4](/solution/1200-1299/1246.Palindrome%20Removal/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1246](https://leetcode.com/problems/palindrome-removal)", "[Palindrome Removal](/solution/1200-1299/1246.Palindrome%20Removal/README_EN.md)", "`Dynamic Programming`", "Hard", "\ud83d\udd12"]}, {"question_id": "1201", "frontend_question_id": "1273", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/delete-tree-nodes", "url_en": "https://leetcode.com/problems/delete-tree-nodes", "relative_path_cn": "/solution/1200-1299/1273.Delete%20Tree%20Nodes/README.md", "relative_path_en": "/solution/1200-1299/1273.Delete%20Tree%20Nodes/README_EN.md", "title_cn": "\u5220\u9664\u6811\u8282\u70b9", "title_en": "Delete Tree Nodes", "question_title_slug": "delete-tree-nodes", "content_en": "

A tree rooted at node 0 is given as follows:

\n\n
    \n\t
  • The number of nodes is nodes;
  • \n\t
  • The value of the i-th node is value[i];
  • \n\t
  • The parent of the i-th node is parent[i].
  • \n
\n\n

Remove every subtree whose sum of values of nodes is zero.

\n\n

After doing so, return the number of nodes remaining in the tree.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: nodes = 7, parent = [-1,0,0,1,2,2,2], value = [1,-2,4,0,-2,-1,-1]\nOutput: 2\n
\n\n

Example 2:

\n\n
\nInput: nodes = 7, parent = [-1,0,0,1,2,2,2], value = [1,-2,4,0,-2,-1,-2]\nOutput: 6\n
\n\n

Example 3:

\n\n
\nInput: nodes = 5, parent = [-1,0,1,0,0], value = [-672,441,18,728,378]\nOutput: 5\n
\n\n

Example 4:

\n\n
\nInput: nodes = 5, parent = [-1,0,0,1,1], value = [-686,-842,616,-739,-746]\nOutput: 5\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nodes <= 10^4
  • \n\t
  • parent.length == nodes
  • \n\t
  • 0 <= parent[i] <= nodes - 1
  • \n\t
  • parent[0] == -1 which indicates that 0 is the root.
  • \n\t
  • value.length == nodes
  • \n\t
  • -10^5 <= value[i] <= 10^5
  • \n\t
  • The given input is guaranteed to represent a valid tree.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u68f5\u4ee5\u8282\u70b9 0 \u4e3a\u6839\u8282\u70b9\u7684\u6811\uff0c\u5b9a\u4e49\u5982\u4e0b\uff1a

\n\n
    \n\t
  • \u8282\u70b9\u7684\u603b\u6570\u4e3a nodes \u4e2a\uff1b
  • \n\t
  • \u7b2c i \u4e2a\u8282\u70b9\u7684\u503c\u4e3a value[i] \uff1b
  • \n\t
  • \u7b2c i \u4e2a\u8282\u70b9\u7684\u7236\u8282\u70b9\u662f parent[i] \u3002
  • \n
\n\n

\u8bf7\u4f60\u5220\u9664\u8282\u70b9\u503c\u4e4b\u548c\u4e3a 0 \u7684\u6bcf\u4e00\u68f5\u5b50\u6811\u3002

\n\n

\u5728\u5b8c\u6210\u6240\u6709\u5220\u9664\u4e4b\u540e\uff0c\u8fd4\u56de\u6811\u4e2d\u5269\u4f59\u8282\u70b9\u7684\u6570\u76ee\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1anodes = 7, parent = [-1,0,0,1,2,2,2], value = [1,-2,4,0,-2,-1,-1]\n\u8f93\u51fa\uff1a2\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anodes = 7, parent = [-1,0,0,1,2,2,2], value = [1,-2,4,0,-2,-1,-2]\n\u8f93\u51fa\uff1a6\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1anodes = 5, parent = [-1,0,1,0,0], value = [-672,441,18,728,378]\n\u8f93\u51fa\uff1a5\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1anodes = 5, parent = [-1,0,0,1,1], value = [-686,-842,616,-739,-746]\n\u8f93\u51fa\uff1a5\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nodes <= 10^4
  • \n\t
  • parent.length == nodes
  • \n\t
  • 0 <= parent[i] <= nodes - 1
  • \n\t
  • parent[0] == -1 \u8868\u793a\u8282\u70b9 0 \u662f\u6811\u7684\u6839\u3002
  • \n\t
  • value.length == nodes
  • \n\t
  • -10^5 <= value[i] <= 10^5
  • \n\t
  • \u9898\u76ee\u8f93\u5165\u6570\u636e \u4fdd\u8bc1 \u662f\u4e00\u68f5 \u6709\u6548\u7684\u6811 \u3002
  • \n
\n", "tags_en": ["Depth-first Search", "Dynamic Programming"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int deleteTreeNodes(int nodes, vector& parent, vector& value) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int deleteTreeNodes(int nodes, int[] parent, int[] value) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def deleteTreeNodes(self, nodes, parent, value):\n \"\"\"\n :type nodes: int\n :type parent: List[int]\n :type value: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def deleteTreeNodes(self, nodes: int, parent: List[int], value: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint deleteTreeNodes(int nodes, int* parent, int parentSize, int* value, int valueSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int DeleteTreeNodes(int nodes, int[] parent, int[] value) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} nodes\n * @param {number[]} parent\n * @param {number[]} value\n * @return {number}\n */\nvar deleteTreeNodes = function(nodes, parent, value) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} nodes\n# @param {Integer[]} parent\n# @param {Integer[]} value\n# @return {Integer}\ndef delete_tree_nodes(nodes, parent, value)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func deleteTreeNodes(_ nodes: Int, _ parent: [Int], _ value: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func deleteTreeNodes(nodes int, parent []int, value []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def deleteTreeNodes(nodes: Int, parent: Array[Int], value: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun deleteTreeNodes(nodes: Int, parent: IntArray, value: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn delete_tree_nodes(nodes: i32, parent: Vec, value: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $nodes\n * @param Integer[] $parent\n * @param Integer[] $value\n * @return Integer\n */\n function deleteTreeNodes($nodes, $parent, $value) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function deleteTreeNodes(nodes: number, parent: number[], value: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (delete-tree-nodes nodes parent value)\n (-> exact-integer? (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1273](https://leetcode-cn.com/problems/delete-tree-nodes)", "[\u5220\u9664\u6811\u8282\u70b9](/solution/1200-1299/1273.Delete%20Tree%20Nodes/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1273](https://leetcode.com/problems/delete-tree-nodes)", "[Delete Tree Nodes](/solution/1200-1299/1273.Delete%20Tree%20Nodes/README_EN.md)", "`Depth-first Search`,`Dynamic Programming`", "Medium", "\ud83d\udd12"]}, {"question_id": "1200", "frontend_question_id": "1272", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/remove-interval", "url_en": "https://leetcode.com/problems/remove-interval", "relative_path_cn": "/solution/1200-1299/1272.Remove%20Interval/README.md", "relative_path_en": "/solution/1200-1299/1272.Remove%20Interval/README_EN.md", "title_cn": "\u5220\u9664\u533a\u95f4", "title_en": "Remove Interval", "question_title_slug": "remove-interval", "content_en": "

A set of real numbers can be represented as the union of several disjoint intervals, where each interval is in the form [a, b). A real number x is in the set if one of its intervals [a, b) contains x (i.e. a <= x < b).

\n\n

You are given a sorted list of disjoint intervals intervals representing a set of real numbers as described above, where intervals[i] = [ai, bi] represents the interval [ai, bi). You are also given another interval toBeRemoved.

\n\n

Return the set of real numbers with the interval toBeRemoved removed from intervals. In other words, return the set of real numbers such that every x in the set is in intervals but not in toBeRemoved. Your answer should be a sorted list of disjoint intervals as described above.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: intervals = [[0,2],[3,4],[5,7]], toBeRemoved = [1,6]\nOutput: [[0,1],[6,7]]\n
\n\n

Example 2:

\n\"\"\n
\nInput: intervals = [[0,5]], toBeRemoved = [2,3]\nOutput: [[0,2],[3,5]]\n
\n\n

Example 3:

\n\n
\nInput: intervals = [[-5,-4],[-3,-2],[1,2],[3,5],[8,9]], toBeRemoved = [-1,4]\nOutput: [[-5,-4],[-3,-2],[4,5],[8,9]]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= intervals.length <= 104
  • \n\t
  • -109 <= ai < bi <= 109
  • \n
\n", "content_cn": "

\u5b9e\u6570\u96c6\u5408\u53ef\u4ee5\u8868\u793a\u4e3a\u82e5\u5e72\u4e0d\u76f8\u4ea4\u533a\u95f4\u7684\u5e76\u96c6\uff0c\u5176\u4e2d\u6bcf\u4e2a\u533a\u95f4\u7684\u5f62\u5f0f\u4e3a [a, b)\uff08\u5de6\u95ed\u53f3\u5f00\uff09\uff0c\u8868\u793a\u6ee1\u8db3\u00a0a <= x < b \u7684\u6240\u6709\u5b9e\u6570\u00a0 x\u00a0\u7684\u96c6\u5408\u3002\u5982\u679c\u67d0\u4e2a\u533a\u95f4\u00a0[a, b) \u4e2d\u5305\u542b\u5b9e\u6570 x \uff0c\u5219\u79f0\u5b9e\u6570 x \u5728\u96c6\u5408\u4e2d\u3002

\n\n

\u7ed9\u4f60\u4e00\u4e2a \u6709\u5e8f\u7684 \u4e0d\u76f8\u4ea4\u533a\u95f4\u5217\u8868 intervals \u548c\u4e00\u4e2a\u8981\u5220\u9664\u7684\u533a\u95f4 toBeRemoved \u3002intervals \u8868\u793a\u4e00\u4e2a\u5b9e\u6570\u96c6\u5408\uff0c\u5176\u4e2d\u6bcf\u4e00\u9879 intervals[i] = [ai, bi] \u90fd\u8868\u793a\u4e00\u4e2a\u533a\u95f4 [ai, bi) \u3002

\n\n

\u8bf7\u4f60 intervals \u4e2d\u4efb\u610f\u533a\u95f4\u4e0e toBeRemoved \u6709\u4ea4\u96c6\u7684\u90e8\u5206\u90fd\u5220\u9664\u3002\u8fd4\u56de\u5220\u9664\u6240\u6709\u4ea4\u96c6\u533a\u95f4\u540e\uff0c intervals \u5269\u4f59\u90e8\u5206\u7684 \u6709\u5e8f \u5217\u8868\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u8fd4\u56de\u5b9e\u6570\u96c6\u5408\uff0c\u5e76\u6ee1\u8db3\u96c6\u5408\u4e2d\u7684\u6bcf\u4e2a\u5b9e\u6570 x \u90fd\u5728\u00a0intervals \u4e2d\uff0c\u4f46\u4e0d\u5728 toBeRemoved \u4e2d\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1aintervals = [[0,2],[3,4],[5,7]], toBeRemoved = [1,6]\n\u8f93\u51fa\uff1a[[0,1],[6,7]]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1aintervals = [[0,5]], toBeRemoved = [2,3]\n\u8f93\u51fa\uff1a[[0,2],[3,5]]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1aintervals = [[-5,-4],[-3,-2],[1,2],[3,5],[8,9]], toBeRemoved = [-1,4]\n\u8f93\u51fa\uff1a[[-5,-4],[-3,-2],[4,5],[8,9]]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= intervals.length <= 104
  • \n\t
  • -109 <= ai < bi <= 109
  • \n
\n", "tags_en": ["Math", "Line Sweep"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> removeInterval(vector>& intervals, vector& toBeRemoved) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> removeInterval(int[][] intervals, int[] toBeRemoved) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def removeInterval(self, intervals, toBeRemoved):\n \"\"\"\n :type intervals: List[List[int]]\n :type toBeRemoved: List[int]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def removeInterval(self, intervals: List[List[int]], toBeRemoved: List[int]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** removeInterval(int** intervals, int intervalsSize, int* intervalsColSize, int* toBeRemoved, int toBeRemovedSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> RemoveInterval(int[][] intervals, int[] toBeRemoved) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} intervals\n * @param {number[]} toBeRemoved\n * @return {number[][]}\n */\nvar removeInterval = function(intervals, toBeRemoved) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} intervals\n# @param {Integer[]} to_be_removed\n# @return {Integer[][]}\ndef remove_interval(intervals, to_be_removed)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func removeInterval(_ intervals: [[Int]], _ toBeRemoved: [Int]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func removeInterval(intervals [][]int, toBeRemoved []int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def removeInterval(intervals: Array[Array[Int]], toBeRemoved: Array[Int]): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun removeInterval(intervals: Array, toBeRemoved: IntArray): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn remove_interval(intervals: Vec>, to_be_removed: Vec) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $intervals\n * @param Integer[] $toBeRemoved\n * @return Integer[][]\n */\n function removeInterval($intervals, $toBeRemoved) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function removeInterval(intervals: number[][], toBeRemoved: number[]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (remove-interval intervals toBeRemoved)\n (-> (listof (listof exact-integer?)) (listof exact-integer?) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1272](https://leetcode-cn.com/problems/remove-interval)", "[\u5220\u9664\u533a\u95f4](/solution/1200-1299/1272.Remove%20Interval/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1272](https://leetcode.com/problems/remove-interval)", "[Remove Interval](/solution/1200-1299/1272.Remove%20Interval/README_EN.md)", "`Math`,`Line Sweep`", "Medium", "\ud83d\udd12"]}, {"question_id": "1199", "frontend_question_id": "1271", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/hexspeak", "url_en": "https://leetcode.com/problems/hexspeak", "relative_path_cn": "/solution/1200-1299/1271.Hexspeak/README.md", "relative_path_en": "/solution/1200-1299/1271.Hexspeak/README_EN.md", "title_cn": "\u5341\u516d\u8fdb\u5236\u9b54\u672f\u6570\u5b57", "title_en": "Hexspeak", "question_title_slug": "hexspeak", "content_en": "

A decimal number can be converted to its Hexspeak representation by first converting it to an uppercase hexadecimal string, then replacing all occurrences of the digit 0 with the letter O, and the digit 1 with the letter I.  Such a representation is valid if and only if it consists only of the letters in the set {"A", "B", "C", "D", "E", "F", "I", "O"}.

\n\n

Given a string num representing a decimal integer N, return the Hexspeak representation of N if it is valid, otherwise return "ERROR".

\n\n

 

\n

Example 1:

\n\n
\nInput: num = "257"\nOutput: "IOI"\nExplanation:  257 is 101 in hexadecimal.\n
\n\n

Example 2:

\n\n
\nInput: num = "3"\nOutput: "ERROR"\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= N <= 10^12
  • \n\t
  • There are no leading zeros in the given string.
  • \n\t
  • All answers must be in uppercase letters.
  • \n
\n", "content_cn": "

\u4f60\u6709\u4e00\u4e2a\u5341\u8fdb\u5236\u6570\u5b57\uff0c\u8bf7\u6309\u7167\u6b64\u89c4\u5219\u5c06\u5b83\u53d8\u6210\u300c\u5341\u516d\u8fdb\u5236\u9b54\u672f\u6570\u5b57\u300d\uff1a\u9996\u5148\u5c06\u5b83\u53d8\u6210\u5b57\u6bcd\u5927\u5199\u7684\u5341\u516d\u8fdb\u5236\u5b57\u7b26\u4e32\uff0c\u7136\u540e\u5c06\u6240\u6709\u7684\u6570\u5b57 0 \u53d8\u6210\u5b57\u6bcd O \uff0c\u5c06\u6570\u5b57 1  \u53d8\u6210\u5b57\u6bcd I \u3002

\n\n

\u5982\u679c\u4e00\u4e2a\u6570\u5b57\u5728\u8f6c\u6362\u540e\u53ea\u5305\u542b {"A", "B", "C", "D", "E", "F", "I", "O"} \uff0c\u90a3\u4e48\u6211\u4eec\u5c31\u8ba4\u4e3a\u8fd9\u4e2a\u8f6c\u6362\u662f\u6709\u6548\u7684\u3002

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 num \uff0c\u5b83\u8868\u793a\u4e00\u4e2a\u5341\u8fdb\u5236\u6570 N\uff0c\u5982\u679c\u5b83\u7684\u5341\u516d\u8fdb\u5236\u9b54\u672f\u6570\u5b57\u8f6c\u6362\u662f\u6709\u6548\u7684\uff0c\u8bf7\u8fd4\u56de\u8f6c\u6362\u540e\u7684\u7ed3\u679c\uff0c\u5426\u5219\u8fd4\u56de "ERROR" \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anum = "257"\n\u8f93\u51fa\uff1a"IOI"\n\u89e3\u91ca\uff1a257 \u7684\u5341\u516d\u8fdb\u5236\u8868\u793a\u662f 101 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anum = "3"\n\u8f93\u51fa\uff1a"ERROR"\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= N <= 10^12
  • \n\t
  • \u7ed9\u5b9a\u5b57\u7b26\u4e32\u4e0d\u4f1a\u6709\u524d\u5bfc 0 \u3002
  • \n\t
  • \u7ed3\u679c\u4e2d\u7684\u6240\u6709\u5b57\u6bcd\u90fd\u5e94\u8be5\u662f\u5927\u5199\u5b57\u6bcd\u3002
  • \n
\n", "tags_en": ["Math", "String"], "tags_cn": ["\u6570\u5b66", "\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string toHexspeak(string num) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String toHexspeak(String num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def toHexspeak(self, num):\n \"\"\"\n :type num: str\n :rtype: str\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def toHexspeak(self, num: str) -> str:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * toHexspeak(char * num){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ToHexspeak(string num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} num\n * @return {string}\n */\nvar toHexspeak = function(num) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} num\n# @return {String}\ndef to_hexspeak(num)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func toHexspeak(_ num: String) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func toHexspeak(num string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def toHexspeak(num: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun toHexspeak(num: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn to_hexspeak(num: String) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $num\n * @return String\n */\n function toHexspeak($num) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function toHexspeak(num: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (to-hexspeak num)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1271](https://leetcode-cn.com/problems/hexspeak)", "[\u5341\u516d\u8fdb\u5236\u9b54\u672f\u6570\u5b57](/solution/1200-1299/1271.Hexspeak/README.md)", "`\u6570\u5b66`,`\u5b57\u7b26\u4e32`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1271](https://leetcode.com/problems/hexspeak)", "[Hexspeak](/solution/1200-1299/1271.Hexspeak/README_EN.md)", "`Math`,`String`", "Easy", "\ud83d\udd12"]}, {"question_id": "1198", "frontend_question_id": "1098", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/unpopular-books", "url_en": "https://leetcode.com/problems/unpopular-books", "relative_path_cn": "/solution/1000-1099/1098.Unpopular%20Books/README.md", "relative_path_en": "/solution/1000-1099/1098.Unpopular%20Books/README_EN.md", "title_cn": "\u5c0f\u4f17\u4e66\u7c4d", "title_en": "Unpopular Books", "question_title_slug": "unpopular-books", "content_en": "

Table: Books

\n\n
\n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| book_id        | int     |\n| name           | varchar |\n| available_from | date    |\n+----------------+---------+\nbook_id is the primary key of this table.\n
\n\n

Table: Orders

\n\n
\n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| order_id       | int     |\n| book_id        | int     |\n| quantity       | int     |\n| dispatch_date  | date    |\n+----------------+---------+\norder_id is the primary key of this table.\nbook_id is a foreign key to the Books table.\n
\n\n

 

\n\n

Write an SQL query that reports the books that have sold less than 10 copies in the last year, excluding books that have been available for less than 1 month from today. Assume today is 2019-06-23.

\n\n

The query result format is in the following example:

\n\n
\nBooks table:\n+---------+--------------------+----------------+\n| book_id | name               | available_from |\n+---------+--------------------+----------------+\n| 1       | "Kalila And Demna" | 2010-01-01     |\n| 2       | "28 Letters"       | 2012-05-12     |\n| 3       | "The Hobbit"       | 2019-06-10     |\n| 4       | "13 Reasons Why"   | 2019-06-01     |\n| 5       | "The Hunger Games" | 2008-09-21     |\n+---------+--------------------+----------------+\n\nOrders table:\n+----------+---------+----------+---------------+\n| order_id | book_id | quantity | dispatch_date |\n+----------+---------+----------+---------------+\n| 1        | 1       | 2        | 2018-07-26    |\n| 2        | 1       | 1        | 2018-11-05    |\n| 3        | 3       | 8        | 2019-06-11    |\n| 4        | 4       | 6        | 2019-06-05    |\n| 5        | 4       | 5        | 2019-06-20    |\n| 6        | 5       | 9        | 2009-02-02    |\n| 7        | 5       | 8        | 2010-04-13    |\n+----------+---------+----------+---------------+\n\nResult table:\n+-----------+--------------------+\n| book_id   | name               |\n+-----------+--------------------+\n| 1         | "Kalila And Demna" |\n| 2         | "28 Letters"       |\n| 5         | "The Hunger Games" |\n+-----------+--------------------+\n
\n", "content_cn": "

\u4e66\u7c4d\u8868 Books\uff1a

\n\n
+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| book_id        | int     |\n| name           | varchar |\n| available_from | date    |\n+----------------+---------+\nbook_id \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\u3002\n
\n\n

\u8ba2\u5355\u8868 Orders\uff1a

\n\n
+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| order_id       | int     |\n| book_id        | int     |\n| quantity       | int     |\n| dispatch_date  | date    |\n+----------------+---------+\norder_id \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\u3002\nbook_id  \u662f Books \u8868\u7684\u5916\u952e\u3002\n
\n\n

 

\n\n

\u4f60\u9700\u8981\u5199\u4e00\u6bb5 SQL \u547d\u4ee4\uff0c\u7b5b\u9009\u51fa\u8fc7\u53bb\u4e00\u5e74\u4e2d\u8ba2\u5355\u603b\u91cf \u5c11\u4e8e10\u672c \u7684 \u4e66\u7c4d \u3002

\n\n

\u6ce8\u610f\uff1a\u4e0d\u8003\u8651 \u4e0a\u67b6\uff08available from\uff09\u8ddd\u4eca \u4e0d\u6ee1\u4e00\u4e2a\u6708 \u7684\u4e66\u7c4d\u3002\u5e76\u4e14 \u5047\u8bbe\u4eca\u5929\u662f 2019-06-23 \u3002

\n\n

 

\n\n

\u4e0b\u9762\u662f\u6837\u4f8b\u8f93\u51fa\u7ed3\u679c\uff1a

\n\n
Books \u8868\uff1a\n+---------+--------------------+----------------+\n| book_id | name               | available_from |\n+---------+--------------------+----------------+\n| 1       | "Kalila And Demna" | 2010-01-01     |\n| 2       | "28 Letters"       | 2012-05-12     |\n| 3       | "The Hobbit"       | 2019-06-10     |\n| 4       | "13 Reasons Why"   | 2019-06-01     |\n| 5       | "The Hunger Games" | 2008-09-21     |\n+---------+--------------------+----------------+\n\nOrders \u8868\uff1a\n+----------+---------+----------+---------------+\n| order_id | book_id | quantity | dispatch_date |\n+----------+---------+----------+---------------+\n| 1        | 1       | 2        | 2018-07-26    |\n| 2        | 1       | 1        | 2018-11-05    |\n| 3        | 3       | 8        | 2019-06-11    |\n| 4        | 4       | 6        | 2019-06-05    |\n| 5        | 4       | 5        | 2019-06-20    |\n| 6        | 5       | 9        | 2009-02-02    |\n| 7        | 5       | 8        | 2010-04-13    |\n+----------+---------+----------+---------------+\n\nResult \u8868\uff1a\n+-----------+--------------------+\n| book_id   | name               |\n+-----------+--------------------+\n| 1         | "Kalila And Demna" |\n| 2         | "28 Letters"       |\n| 5         | "The Hunger Games" |\n+-----------+--------------------+\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1098](https://leetcode-cn.com/problems/unpopular-books)", "[\u5c0f\u4f17\u4e66\u7c4d](/solution/1000-1099/1098.Unpopular%20Books/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1098](https://leetcode.com/problems/unpopular-books)", "[Unpopular Books](/solution/1000-1099/1098.Unpopular%20Books/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1197", "frontend_question_id": "1106", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/parsing-a-boolean-expression", "url_en": "https://leetcode.com/problems/parsing-a-boolean-expression", "relative_path_cn": "/solution/1100-1199/1106.Parsing%20A%20Boolean%20Expression/README.md", "relative_path_en": "/solution/1100-1199/1106.Parsing%20A%20Boolean%20Expression/README_EN.md", "title_cn": "\u89e3\u6790\u5e03\u5c14\u8868\u8fbe\u5f0f", "title_en": "Parsing A Boolean Expression", "question_title_slug": "parsing-a-boolean-expression", "content_en": "

Return the result of evaluating a given boolean expression, represented as a string.

\n\n

An expression can either be:

\n\n
    \n\t
  • "t", evaluating to True;
  • \n\t
  • "f", evaluating to False;
  • \n\t
  • "!(expr)", evaluating to the logical NOT of the inner expression expr;
  • \n\t
  • "&(expr1,expr2,...)", evaluating to the logical AND of 2 or more inner expressions expr1, expr2, ...;
  • \n\t
  • "|(expr1,expr2,...)", evaluating to the logical OR of 2 or more inner expressions expr1, expr2, ...
  • \n
\n\n

 

\n

Example 1:

\n\n
\nInput: expression = "!(f)"\nOutput: true\n
\n\n

Example 2:

\n\n
\nInput: expression = "|(f,t)"\nOutput: true\n
\n\n

Example 3:

\n\n
\nInput: expression = "&(t,f)"\nOutput: false\n
\n\n

Example 4:

\n\n
\nInput: expression = "|(&(t,f,t),!(t))"\nOutput: false\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= expression.length <= 20000
  • \n\t
  • expression[i] consists of characters in {'(', ')', '&', '|', '!', 't', 'f', ','}.
  • \n\t
  • expression is a valid expression representing a boolean, as given in the description.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u4ee5\u5b57\u7b26\u4e32\u5f62\u5f0f\u8868\u8ff0\u7684 \u5e03\u5c14\u8868\u8fbe\u5f0f\uff08boolean\uff09 expression\uff0c\u8fd4\u56de\u8be5\u5f0f\u7684\u8fd0\u7b97\u7ed3\u679c\u3002

\n\n

\u6709\u6548\u7684\u8868\u8fbe\u5f0f\u9700\u9075\u5faa\u4ee5\u4e0b\u7ea6\u5b9a\uff1a

\n\n
    \n\t
  • "t"\uff0c\u8fd0\u7b97\u7ed3\u679c\u4e3a True
  • \n\t
  • "f"\uff0c\u8fd0\u7b97\u7ed3\u679c\u4e3a False
  • \n\t
  • "!(expr)"\uff0c\u8fd0\u7b97\u8fc7\u7a0b\u4e3a\u5bf9\u5185\u90e8\u8868\u8fbe\u5f0f expr \u8fdb\u884c\u903b\u8f91 \u975e\u7684\u8fd0\u7b97\uff08NOT\uff09
  • \n\t
  • "&(expr1,expr2,...)"\uff0c\u8fd0\u7b97\u8fc7\u7a0b\u4e3a\u5bf9 2 \u4e2a\u6216\u4ee5\u4e0a\u5185\u90e8\u8868\u8fbe\u5f0f expr1, expr2, ... \u8fdb\u884c\u903b\u8f91 \u4e0e\u7684\u8fd0\u7b97\uff08AND\uff09
  • \n\t
  • "|(expr1,expr2,...)"\uff0c\u8fd0\u7b97\u8fc7\u7a0b\u4e3a\u5bf9 2 \u4e2a\u6216\u4ee5\u4e0a\u5185\u90e8\u8868\u8fbe\u5f0f expr1, expr2, ... \u8fdb\u884c\u903b\u8f91 \u6216\u7684\u8fd0\u7b97\uff08OR\uff09
  • \n
\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aexpression = "!(f)"\n\u8f93\u51fa\uff1atrue\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aexpression = "|(f,t)"\n\u8f93\u51fa\uff1atrue\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aexpression = "&(t,f)"\n\u8f93\u51fa\uff1afalse\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1aexpression = "|(&(t,f,t),!(t))"\n\u8f93\u51fa\uff1afalse\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= expression.length <= 20000
  • \n\t
  • expression[i] \u7531 {'(', ')', '&', '|', '!', 't', 'f', ','} \u4e2d\u7684\u5b57\u7b26\u7ec4\u6210\u3002
  • \n\t
  • expression \u662f\u4ee5\u4e0a\u8ff0\u5f62\u5f0f\u7ed9\u51fa\u7684\u6709\u6548\u8868\u8fbe\u5f0f\uff0c\u8868\u793a\u4e00\u4e2a\u5e03\u5c14\u503c\u3002
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool parseBoolExpr(string expression) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean parseBoolExpr(String expression) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def parseBoolExpr(self, expression):\n \"\"\"\n :type expression: str\n :rtype: bool\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def parseBoolExpr(self, expression: str) -> bool:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool parseBoolExpr(char * expression){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool ParseBoolExpr(string expression) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} expression\n * @return {boolean}\n */\nvar parseBoolExpr = function(expression) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} expression\n# @return {Boolean}\ndef parse_bool_expr(expression)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func parseBoolExpr(_ expression: String) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func parseBoolExpr(expression string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def parseBoolExpr(expression: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun parseBoolExpr(expression: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn parse_bool_expr(expression: String) -> bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $expression\n * @return Boolean\n */\n function parseBoolExpr($expression) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function parseBoolExpr(expression: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (parse-bool-expr expression)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1106](https://leetcode-cn.com/problems/parsing-a-boolean-expression)", "[\u89e3\u6790\u5e03\u5c14\u8868\u8fbe\u5f0f](/solution/1100-1199/1106.Parsing%20A%20Boolean%20Expression/README.md)", "`\u5b57\u7b26\u4e32`", "\u56f0\u96be", ""], "md_table_row_en": ["[1106](https://leetcode.com/problems/parsing-a-boolean-expression)", "[Parsing A Boolean Expression](/solution/1100-1199/1106.Parsing%20A%20Boolean%20Expression/README_EN.md)", "`String`", "Hard", ""]}, {"question_id": "1196", "frontend_question_id": "1105", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/filling-bookcase-shelves", "url_en": "https://leetcode.com/problems/filling-bookcase-shelves", "relative_path_cn": "/solution/1100-1199/1105.Filling%20Bookcase%20Shelves/README.md", "relative_path_en": "/solution/1100-1199/1105.Filling%20Bookcase%20Shelves/README_EN.md", "title_cn": "\u586b\u5145\u4e66\u67b6", "title_en": "Filling Bookcase Shelves", "question_title_slug": "filling-bookcase-shelves", "content_en": "

We have a sequence of books: the i-th book has thickness books[i][0] and height books[i][1].

\n\n

We want to place these books in order onto bookcase shelves that have total width shelf_width.

\n\n

We choose some of the books to place on this shelf (such that the sum of their thickness is <= shelf_width), then build another level of shelf of the bookcase so that the total height of the bookcase has increased by the maximum height of the books we just put down.  We repeat this process until there are no more books to place.

\n\n

Note again that at each step of the above process, the order of the books we place is the same order as the given sequence of books.  For example, if we have an ordered list of 5 books, we might place the first and second book onto the first shelf, the third book on the second shelf, and the fourth and fifth book on the last shelf.

\n\n

Return the minimum possible height that the total bookshelf can be after placing shelves in this manner.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: books = [[1,1],[2,3],[2,3],[1,1],[1,1],[1,1],[1,2]], shelf_width = 4\nOutput: 6\nExplanation:\nThe sum of the heights of the 3 shelves are 1 + 3 + 2 = 6.\nNotice that book number 2 does not have to be on the first shelf.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= books.length <= 1000
  • \n\t
  • 1 <= books[i][0] <= shelf_width <= 1000
  • \n\t
  • 1 <= books[i][1] <= 1000
  • \n
\n", "content_cn": "

\u9644\u8fd1\u7684\u5bb6\u5c45\u57ce\u4fc3\u9500\uff0c\u4f60\u4e70\u56de\u4e86\u4e00\u76f4\u5fc3\u4eea\u7684\u53ef\u8c03\u8282\u4e66\u67b6\uff0c\u6253\u7b97\u628a\u81ea\u5df1\u7684\u4e66\u90fd\u6574\u7406\u5230\u65b0\u7684\u4e66\u67b6\u4e0a\u3002

\n\n

\u4f60\u628a\u8981\u6446\u653e\u7684\u4e66 books \u90fd\u6574\u7406\u597d\uff0c\u53e0\u6210\u4e00\u645e\uff1a\u4ece\u4e0a\u5f80\u4e0b\uff0c\u7b2c i \u672c\u4e66\u7684\u539a\u5ea6\u4e3a books[i][0]\uff0c\u9ad8\u5ea6\u4e3a books[i][1]\u3002

\n\n

\u6309\u987a\u5e8f \u5c06\u8fd9\u4e9b\u4e66\u6446\u653e\u5230\u603b\u5bbd\u5ea6\u4e3a shelf_width \u7684\u4e66\u67b6\u4e0a\u3002

\n\n

\u5148\u9009\u51e0\u672c\u4e66\u653e\u5728\u4e66\u67b6\u4e0a\uff08\u5b83\u4eec\u7684\u539a\u5ea6\u4e4b\u548c\u5c0f\u4e8e\u7b49\u4e8e\u4e66\u67b6\u7684\u5bbd\u5ea6 shelf_width\uff09\uff0c\u7136\u540e\u518d\u5efa\u4e00\u5c42\u4e66\u67b6\u3002\u91cd\u590d\u8fd9\u4e2a\u8fc7\u7a0b\uff0c\u76f4\u5230\u628a\u6240\u6709\u7684\u4e66\u90fd\u653e\u5728\u4e66\u67b6\u4e0a\u3002

\n\n

\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5728\u4e0a\u8ff0\u8fc7\u7a0b\u7684\u6bcf\u4e2a\u6b65\u9aa4\u4e2d\uff0c\u6446\u653e\u4e66\u7684\u987a\u5e8f\u4e0e\u4f60\u6574\u7406\u597d\u7684\u987a\u5e8f\u76f8\u540c\u3002 \u4f8b\u5982\uff0c\u5982\u679c\u8fd9\u91cc\u6709 5 \u672c\u4e66\uff0c\u90a3\u4e48\u53ef\u80fd\u7684\u4e00\u79cd\u6446\u653e\u60c5\u51b5\u662f\uff1a\u7b2c\u4e00\u548c\u7b2c\u4e8c\u672c\u4e66\u653e\u5728\u7b2c\u4e00\u5c42\u4e66\u67b6\u4e0a\uff0c\u7b2c\u4e09\u672c\u4e66\u653e\u5728\u7b2c\u4e8c\u5c42\u4e66\u67b6\u4e0a\uff0c\u7b2c\u56db\u548c\u7b2c\u4e94\u672c\u4e66\u653e\u5728\u6700\u540e\u4e00\u5c42\u4e66\u67b6\u4e0a\u3002

\n\n

\u6bcf\u4e00\u5c42\u6240\u6446\u653e\u7684\u4e66\u7684\u6700\u5927\u9ad8\u5ea6\u5c31\u662f\u8fd9\u4e00\u5c42\u4e66\u67b6\u7684\u5c42\u9ad8\uff0c\u4e66\u67b6\u6574\u4f53\u7684\u9ad8\u5ea6\u4e3a\u5404\u5c42\u9ad8\u4e4b\u548c\u3002

\n\n

\u4ee5\u8fd9\u79cd\u65b9\u5f0f\u5e03\u7f6e\u4e66\u67b6\uff0c\u8fd4\u56de\u4e66\u67b6\u6574\u4f53\u53ef\u80fd\u7684\u6700\u5c0f\u9ad8\u5ea6\u3002

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1abooks = [[1,1],[2,3],[2,3],[1,1],[1,1],[1,1],[1,2]], shelf_width = 4\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\n3 \u5c42\u4e66\u67b6\u7684\u9ad8\u5ea6\u548c\u4e3a 1 + 3 + 2 = 6 \u3002\n\u7b2c 2 \u672c\u4e66\u4e0d\u5fc5\u653e\u5728\u7b2c\u4e00\u5c42\u4e66\u67b6\u4e0a\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= books.length <= 1000
  • \n\t
  • 1 <= books[i][0] <= shelf_width <= 1000
  • \n\t
  • 1 <= books[i][1] <= 1000
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minHeightShelves(vector>& books, int shelf_width) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minHeightShelves(int[][] books, int shelf_width) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minHeightShelves(self, books, shelf_width):\n \"\"\"\n :type books: List[List[int]]\n :type shelf_width: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minHeightShelves(self, books: List[List[int]], shelf_width: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minHeightShelves(int** books, int booksSize, int* booksColSize, int shelf_width){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinHeightShelves(int[][] books, int shelf_width) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} books\n * @param {number} shelf_width\n * @return {number}\n */\nvar minHeightShelves = function(books, shelf_width) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} books\n# @param {Integer} shelf_width\n# @return {Integer}\ndef min_height_shelves(books, shelf_width)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minHeightShelves(_ books: [[Int]], _ shelf_width: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minHeightShelves(books [][]int, shelf_width int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minHeightShelves(books: Array[Array[Int]], shelf_width: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minHeightShelves(books: Array, shelf_width: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_height_shelves(books: Vec>, shelf_width: i32) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $books\n * @param Integer $shelf_width\n * @return Integer\n */\n function minHeightShelves($books, $shelf_width) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minHeightShelves(books: number[][], shelf_width: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-height-shelves books shelf_width)\n (-> (listof (listof exact-integer?)) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1105](https://leetcode-cn.com/problems/filling-bookcase-shelves)", "[\u586b\u5145\u4e66\u67b6](/solution/1100-1199/1105.Filling%20Bookcase%20Shelves/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1105](https://leetcode.com/problems/filling-bookcase-shelves)", "[Filling Bookcase Shelves](/solution/1100-1199/1105.Filling%20Bookcase%20Shelves/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "1195", "frontend_question_id": "1103", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/distribute-candies-to-people", "url_en": "https://leetcode.com/problems/distribute-candies-to-people", "relative_path_cn": "/solution/1100-1199/1103.Distribute%20Candies%20to%20People/README.md", "relative_path_en": "/solution/1100-1199/1103.Distribute%20Candies%20to%20People/README_EN.md", "title_cn": "\u5206\u7cd6\u679c II", "title_en": "Distribute Candies to People", "question_title_slug": "distribute-candies-to-people", "content_en": "

We distribute some number of candies, to a row of n = num_people people in the following way:

\n\n

We then give 1 candy to the first person, 2 candies to the second person, and so on until we give n candies to the last person.

\n\n

Then, we go back to the start of the row, giving n + 1 candies to the first person, n + 2 candies to the second person, and so on until we give 2 * n candies to the last person.

\n\n

This process repeats (with us giving one more candy each time, and moving to the start of the row after we reach the end) until we run out of candies.  The last person will receive all of our remaining candies (not necessarily one more than the previous gift).

\n\n

Return an array (of length num_people and sum candies) that represents the final distribution of candies.

\n\n

 

\n

Example 1:

\n\n
\nInput: candies = 7, num_people = 4\nOutput: [1,2,3,1]\nExplanation:\nOn the first turn, ans[0] += 1, and the array is [1,0,0,0].\nOn the second turn, ans[1] += 2, and the array is [1,2,0,0].\nOn the third turn, ans[2] += 3, and the array is [1,2,3,0].\nOn the fourth turn, ans[3] += 1 (because there is only one candy left), and the final array is [1,2,3,1].\n
\n\n

Example 2:

\n\n
\nInput: candies = 10, num_people = 3\nOutput: [5,2,3]\nExplanation: \nOn the first turn, ans[0] += 1, and the array is [1,0,0].\nOn the second turn, ans[1] += 2, and the array is [1,2,0].\nOn the third turn, ans[2] += 3, and the array is [1,2,3].\nOn the fourth turn, ans[0] += 4, and the final array is [5,2,3].\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= candies <= 10^9
  • \n\t
  • 1 <= num_people <= 1000
  • \n
\n", "content_cn": "

\u6392\u6392\u5750\uff0c\u5206\u7cd6\u679c\u3002

\n\n

\u6211\u4eec\u4e70\u4e86\u4e00\u4e9b\u7cd6\u679c candies\uff0c\u6253\u7b97\u628a\u5b83\u4eec\u5206\u7ed9\u6392\u597d\u961f\u7684 n = num_people \u4e2a\u5c0f\u670b\u53cb\u3002

\n\n

\u7ed9\u7b2c\u4e00\u4e2a\u5c0f\u670b\u53cb 1 \u9897\u7cd6\u679c\uff0c\u7b2c\u4e8c\u4e2a\u5c0f\u670b\u53cb 2 \u9897\uff0c\u4f9d\u6b64\u7c7b\u63a8\uff0c\u76f4\u5230\u7ed9\u6700\u540e\u4e00\u4e2a\u5c0f\u670b\u53cb n \u9897\u7cd6\u679c\u3002

\n\n

\u7136\u540e\uff0c\u6211\u4eec\u518d\u56de\u5230\u961f\u4f0d\u7684\u8d77\u70b9\uff0c\u7ed9\u7b2c\u4e00\u4e2a\u5c0f\u670b\u53cb n + 1 \u9897\u7cd6\u679c\uff0c\u7b2c\u4e8c\u4e2a\u5c0f\u670b\u53cb n + 2 \u9897\uff0c\u4f9d\u6b64\u7c7b\u63a8\uff0c\u76f4\u5230\u7ed9\u6700\u540e\u4e00\u4e2a\u5c0f\u670b\u53cb 2 * n \u9897\u7cd6\u679c\u3002

\n\n

\u91cd\u590d\u4e0a\u8ff0\u8fc7\u7a0b\uff08\u6bcf\u6b21\u90fd\u6bd4\u4e0a\u4e00\u6b21\u591a\u7ed9\u51fa\u4e00\u9897\u7cd6\u679c\uff0c\u5f53\u5230\u8fbe\u961f\u4f0d\u7ec8\u70b9\u540e\u518d\u6b21\u4ece\u961f\u4f0d\u8d77\u70b9\u5f00\u59cb\uff09\uff0c\u76f4\u5230\u6211\u4eec\u5206\u5b8c\u6240\u6709\u7684\u7cd6\u679c\u3002\u6ce8\u610f\uff0c\u5c31\u7b97\u6211\u4eec\u624b\u4e2d\u7684\u5269\u4e0b\u7cd6\u679c\u6570\u4e0d\u591f\uff08\u4e0d\u6bd4\u524d\u4e00\u6b21\u53d1\u51fa\u7684\u7cd6\u679c\u591a\uff09\uff0c\u8fd9\u4e9b\u7cd6\u679c\u4e5f\u4f1a\u5168\u90e8\u53d1\u7ed9\u5f53\u524d\u7684\u5c0f\u670b\u53cb\u3002

\n\n

\u8fd4\u56de\u4e00\u4e2a\u957f\u5ea6\u4e3a num_people\u3001\u5143\u7d20\u4e4b\u548c\u4e3a candies \u7684\u6570\u7ec4\uff0c\u4ee5\u8868\u793a\u7cd6\u679c\u7684\u6700\u7ec8\u5206\u53d1\u60c5\u51b5\uff08\u5373 ans[i] \u8868\u793a\u7b2c i \u4e2a\u5c0f\u670b\u53cb\u5206\u5230\u7684\u7cd6\u679c\u6570\uff09\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1acandies = 7, num_people = 4\n\u8f93\u51fa\uff1a[1,2,3,1]\n\u89e3\u91ca\uff1a\n\u7b2c\u4e00\u6b21\uff0cans[0] += 1\uff0c\u6570\u7ec4\u53d8\u4e3a [1,0,0,0]\u3002\n\u7b2c\u4e8c\u6b21\uff0cans[1] += 2\uff0c\u6570\u7ec4\u53d8\u4e3a [1,2,0,0]\u3002\n\u7b2c\u4e09\u6b21\uff0cans[2] += 3\uff0c\u6570\u7ec4\u53d8\u4e3a [1,2,3,0]\u3002\n\u7b2c\u56db\u6b21\uff0cans[3] += 1\uff08\u56e0\u4e3a\u6b64\u65f6\u53ea\u5269\u4e0b 1 \u9897\u7cd6\u679c\uff09\uff0c\u6700\u7ec8\u6570\u7ec4\u53d8\u4e3a [1,2,3,1]\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1acandies = 10, num_people = 3\n\u8f93\u51fa\uff1a[5,2,3]\n\u89e3\u91ca\uff1a\n\u7b2c\u4e00\u6b21\uff0cans[0] += 1\uff0c\u6570\u7ec4\u53d8\u4e3a [1,0,0]\u3002\n\u7b2c\u4e8c\u6b21\uff0cans[1] += 2\uff0c\u6570\u7ec4\u53d8\u4e3a [1,2,0]\u3002\n\u7b2c\u4e09\u6b21\uff0cans[2] += 3\uff0c\u6570\u7ec4\u53d8\u4e3a [1,2,3]\u3002\n\u7b2c\u56db\u6b21\uff0cans[0] += 4\uff0c\u6700\u7ec8\u6570\u7ec4\u53d8\u4e3a [5,2,3]\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= candies <= 10^9
  • \n\t
  • 1 <= num_people <= 1000
  • \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector distributeCandies(int candies, int num_people) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] distributeCandies(int candies, int num_people) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def distributeCandies(self, candies, num_people):\n \"\"\"\n :type candies: int\n :type num_people: int\n :rtype: List[int]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def distributeCandies(self, candies: int, num_people: int) -> List[int]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* distributeCandies(int candies, int num_people, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] DistributeCandies(int candies, int num_people) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} candies\n * @param {number} num_people\n * @return {number[]}\n */\nvar distributeCandies = function(candies, num_people) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} candies\n# @param {Integer} num_people\n# @return {Integer[]}\ndef distribute_candies(candies, num_people)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func distributeCandies(_ candies: Int, _ num_people: Int) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func distributeCandies(candies int, num_people int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def distributeCandies(candies: Int, num_people: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun distributeCandies(candies: Int, num_people: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn distribute_candies(candies: i32, num_people: i32) -> Vec {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $candies\n * @param Integer $num_people\n * @return Integer[]\n */\n function distributeCandies($candies, $num_people) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function distributeCandies(candies: number, num_people: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (distribute-candies candies num_people)\n (-> exact-integer? exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1103](https://leetcode-cn.com/problems/distribute-candies-to-people)", "[\u5206\u7cd6\u679c II](/solution/1100-1199/1103.Distribute%20Candies%20to%20People/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[1103](https://leetcode.com/problems/distribute-candies-to-people)", "[Distribute Candies to People](/solution/1100-1199/1103.Distribute%20Candies%20to%20People/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "1194", "frontend_question_id": "1104", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/path-in-zigzag-labelled-binary-tree", "url_en": "https://leetcode.com/problems/path-in-zigzag-labelled-binary-tree", "relative_path_cn": "/solution/1100-1199/1104.Path%20In%20Zigzag%20Labelled%20Binary%20Tree/README.md", "relative_path_en": "/solution/1100-1199/1104.Path%20In%20Zigzag%20Labelled%20Binary%20Tree/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u5bfb\u8def", "title_en": "Path In Zigzag Labelled Binary Tree", "question_title_slug": "path-in-zigzag-labelled-binary-tree", "content_en": "

In an infinite binary tree where every node has two children, the nodes are labelled in row order.

\n\n

In the odd numbered rows (ie., the first, third, fifth,...), the labelling is left to right, while in the even numbered rows (second, fourth, sixth,...), the labelling is right to left.

\n\n

\"\"

\n\n

Given the label of a node in this tree, return the labels in the path from the root of the tree to the node with that label.

\n\n

 

\n

Example 1:

\n\n
\nInput: label = 14\nOutput: [1,3,4,14]\n
\n\n

Example 2:

\n\n
\nInput: label = 26\nOutput: [1,2,6,10,26]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= label <= 10^6
  • \n
\n", "content_cn": "

\u5728\u4e00\u68f5\u65e0\u9650\u7684\u4e8c\u53c9\u6811\u4e0a\uff0c\u6bcf\u4e2a\u8282\u70b9\u90fd\u6709\u4e24\u4e2a\u5b50\u8282\u70b9\uff0c\u6811\u4e2d\u7684\u8282\u70b9 \u9010\u884c \u4f9d\u6b21\u6309 “\u4e4b” \u5b57\u5f62\u8fdb\u884c\u6807\u8bb0\u3002

\n\n

\u5982\u4e0b\u56fe\u6240\u793a\uff0c\u5728\u5947\u6570\u884c\uff08\u5373\uff0c\u7b2c\u4e00\u884c\u3001\u7b2c\u4e09\u884c\u3001\u7b2c\u4e94\u884c……\uff09\u4e2d\uff0c\u6309\u4ece\u5de6\u5230\u53f3\u7684\u987a\u5e8f\u8fdb\u884c\u6807\u8bb0\uff1b

\n\n

\u800c\u5076\u6570\u884c\uff08\u5373\uff0c\u7b2c\u4e8c\u884c\u3001\u7b2c\u56db\u884c\u3001\u7b2c\u516d\u884c……\uff09\u4e2d\uff0c\u6309\u4ece\u53f3\u5230\u5de6\u7684\u987a\u5e8f\u8fdb\u884c\u6807\u8bb0\u3002

\n\n

\"\"

\n\n

\u7ed9\u4f60\u6811\u4e0a\u67d0\u4e00\u4e2a\u8282\u70b9\u7684\u6807\u53f7 label\uff0c\u8bf7\u4f60\u8fd4\u56de\u4ece\u6839\u8282\u70b9\u5230\u8be5\u6807\u53f7\u4e3a label \u8282\u70b9\u7684\u8def\u5f84\uff0c\u8be5\u8def\u5f84\u662f\u7531\u9014\u7ecf\u7684\u8282\u70b9\u6807\u53f7\u6240\u7ec4\u6210\u7684\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1alabel = 14\n\u8f93\u51fa\uff1a[1,3,4,14]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1alabel = 26\n\u8f93\u51fa\uff1a[1,2,6,10,26]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= label <= 10^6
  • \n
\n", "tags_en": ["Tree", "Math"], "tags_cn": ["\u6811", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector pathInZigZagTree(int label) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List pathInZigZagTree(int label) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def pathInZigZagTree(self, label):\n \"\"\"\n :type label: int\n :rtype: List[int]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def pathInZigZagTree(self, label: int) -> List[int]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* pathInZigZagTree(int label, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList PathInZigZagTree(int label) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} label\n * @return {number[]}\n */\nvar pathInZigZagTree = function(label) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} label\n# @return {Integer[]}\ndef path_in_zig_zag_tree(label)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func pathInZigZagTree(_ label: Int) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func pathInZigZagTree(label int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def pathInZigZagTree(label: Int): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun pathInZigZagTree(label: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn path_in_zig_zag_tree(label: i32) -> Vec {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $label\n * @return Integer[]\n */\n function pathInZigZagTree($label) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function pathInZigZagTree(label: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (path-in-zig-zag-tree label)\n (-> exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1104](https://leetcode-cn.com/problems/path-in-zigzag-labelled-binary-tree)", "[\u4e8c\u53c9\u6811\u5bfb\u8def](/solution/1100-1199/1104.Path%20In%20Zigzag%20Labelled%20Binary%20Tree/README.md)", "`\u6811`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1104](https://leetcode.com/problems/path-in-zigzag-labelled-binary-tree)", "[Path In Zigzag Labelled Binary Tree](/solution/1100-1199/1104.Path%20In%20Zigzag%20Labelled%20Binary%20Tree/README_EN.md)", "`Tree`,`Math`", "Medium", ""]}, {"question_id": "1193", "frontend_question_id": "1097", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/game-play-analysis-v", "url_en": "https://leetcode.com/problems/game-play-analysis-v", "relative_path_cn": "/solution/1000-1099/1097.Game%20Play%20Analysis%20V/README.md", "relative_path_en": "/solution/1000-1099/1097.Game%20Play%20Analysis%20V/README_EN.md", "title_cn": "\u6e38\u620f\u73a9\u6cd5\u5206\u6790 V", "title_en": "Game Play Analysis V", "question_title_slug": "game-play-analysis-v", "content_en": "

Table: Activity

\n\n
\n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| player_id    | int     |\n| device_id    | int     |\n| event_date   | date    |\n| games_played | int     |\n+--------------+---------+\n(player_id, event_date) is the primary key of this table.\nThis table shows the activity of players of some game.\nEach row is a record of a player who logged in and played a number of games (possibly 0) before logging out on some day using some device.\n
\n\n

 

\n\n

We define the install date of a player to be the first login day of that player.

\n\n

We also define day 1 retention of some date X to be the number of players whose install date is X and they logged back in on the day right after X, divided by the number of players whose install date is X, rounded to 2 decimal places.

\n\n

Write an SQL query that reports for each install date, the number of players that installed the game on that day and the day 1 retention.

\n\n

The query result format is in the following example:

\n\n
\nActivity table:\n+-----------+-----------+------------+--------------+\n| player_id | device_id | event_date | games_played |\n+-----------+-----------+------------+--------------+\n| 1         | 2         | 2016-03-01 | 5            |\n| 1         | 2         | 2016-03-02 | 6            |\n| 2         | 3         | 2017-06-25 | 1            |\n| 3         | 1         | 2016-03-01 | 0            |\n| 3         | 4         | 2016-07-03 | 5            |\n+-----------+-----------+------------+--------------+\n\nResult table:\n+------------+----------+----------------+\n| install_dt | installs | Day1_retention |\n+------------+----------+----------------+\n| 2016-03-01 | 2        | 0.50           |\n| 2017-06-25 | 1        | 0.00           |\n+------------+----------+----------------+\nPlayer 1 and 3 installed the game on 2016-03-01 but only player 1 logged back in on 2016-03-02 so the day 1 retention of 2016-03-01 is 1 / 2 = 0.50\nPlayer 2 installed the game on 2017-06-25 but didn't log back in on 2017-06-26 so the day 1 retention of 2017-06-25 is 0 / 1 = 0.00\n
\n", "content_cn": "

Activity \u6d3b\u52a8\u8bb0\u5f55\u8868

\n\n
\n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| player_id    | int     |\n| device_id    | int     |\n| event_date   | date    |\n| games_played | int     |\n+--------------+---------+\n\uff08player_id\uff0cevent_date\uff09\u662f\u6b64\u8868\u7684\u4e3b\u952e\n\u8fd9\u5f20\u8868\u663e\u793a\u4e86\u67d0\u4e9b\u6e38\u620f\u7684\u73a9\u5bb6\u7684\u6d3b\u52a8\u60c5\u51b5\n\u6bcf\u4e00\u884c\u8868\u793a\u4e00\u4e2a\u73a9\u5bb6\u7684\u8bb0\u5f55\uff0c\u5728\u67d0\u4e00\u5929\u4f7f\u7528\u67d0\u4e2a\u8bbe\u5907\u6ce8\u9500\u4e4b\u524d\uff0c\u767b\u5f55\u5e76\u73a9\u4e86\u5f88\u591a\u6e38\u620f\uff08\u53ef\u80fd\u662f 0\uff09\n
\n\n

\u00a0

\n\n

\u73a9\u5bb6\u7684 \u5b89\u88c5\u65e5\u671f \u5b9a\u4e49\u4e3a\u8be5\u73a9\u5bb6\u7684\u7b2c\u4e00\u4e2a\u767b\u5f55\u65e5\u3002

\n\n

\u73a9\u5bb6\u7684 \u7b2c\u4e00\u5929\u7559\u5b58\u7387 \u5b9a\u4e49\u4e3a\uff1a\u5047\u5b9a\u5b89\u88c5\u65e5\u671f\u4e3a X\u00a0\u7684\u73a9\u5bb6\u7684\u6570\u91cf\u4e3a N \uff0c\u5176\u4e2d\u5728 X\u00a0\u4e4b\u540e\u7684\u4e00\u5929\u91cd\u65b0\u767b\u5f55\u7684\u73a9\u5bb6\u6570\u91cf\u4e3a M \uff0cM/N \u5c31\u662f\u7b2c\u4e00\u5929\u7559\u5b58\u7387\uff0c\u56db\u820d\u4e94\u5165\u5230\u5c0f\u6570\u70b9\u540e\u4e24\u4f4d\u3002

\n\n

\u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\uff0c\u62a5\u544a\u6240\u6709\u5b89\u88c5\u65e5\u671f\u3001\u5f53\u5929\u5b89\u88c5\u6e38\u620f\u7684\u73a9\u5bb6\u6570\u91cf\u548c\u73a9\u5bb6\u7684\u7b2c\u4e00\u5929\u7559\u5b58\u7387\u3002

\n\n

\u00a0

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u6240\u793a\uff1a

\n\n
\nActivity \u8868\uff1a\n+-----------+-----------+------------+--------------+\n| player_id | device_id | event_date | games_played |\n+-----------+-----------+------------+--------------+\n| 1         | 2         | 2016-03-01 | 5            |\n| 1         | 2         | 2016-03-02 | 6            |\n| 2         | 3         | 2017-06-25 | 1            |\n| 3         | 1         | 2016-03-01 | 0            |\n| 3         | 4         | 2016-07-03 | 5            |\n+-----------+-----------+------------+--------------+\n\nResult \u8868\uff1a\n+------------+----------+----------------+\n| install_dt | installs | Day1_retention |\n+------------+----------+----------------+\n| 2016-03-01 | 2        | 0.50           |\n| 2017-06-25 | 1        | 0.00           |\n+------------+----------+----------------+\n\u73a9\u5bb6 1 \u548c 3 \u5728 2016-03-01 \u5b89\u88c5\u4e86\u6e38\u620f\uff0c\u4f46\u53ea\u6709\u73a9\u5bb6 1 \u5728 2016-03-02 \u91cd\u65b0\u767b\u5f55\uff0c\u6240\u4ee5 2016-03-01 \u7684\u7b2c\u4e00\u5929\u7559\u5b58\u7387\u662f 1/2=0.50\n\u73a9\u5bb6 2 \u5728 2017-06-25 \u5b89\u88c5\u4e86\u6e38\u620f\uff0c\u4f46\u5728 2017-06-26 \u6ca1\u6709\u91cd\u65b0\u767b\u5f55\uff0c\u56e0\u6b64 2017-06-25 \u7684\u7b2c\u4e00\u5929\u7559\u5b58\u7387\u4e3a 0/1=0.00\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1097](https://leetcode-cn.com/problems/game-play-analysis-v)", "[\u6e38\u620f\u73a9\u6cd5\u5206\u6790 V](/solution/1000-1099/1097.Game%20Play%20Analysis%20V/README.md)", "", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1097](https://leetcode.com/problems/game-play-analysis-v)", "[Game Play Analysis V](/solution/1000-1099/1097.Game%20Play%20Analysis%20V/README_EN.md)", "", "Hard", "\ud83d\udd12"]}, {"question_id": "1192", "frontend_question_id": "1231", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/divide-chocolate", "url_en": "https://leetcode.com/problems/divide-chocolate", "relative_path_cn": "/solution/1200-1299/1231.Divide%20Chocolate/README.md", "relative_path_en": "/solution/1200-1299/1231.Divide%20Chocolate/README_EN.md", "title_cn": "\u5206\u4eab\u5de7\u514b\u529b", "title_en": "Divide Chocolate", "question_title_slug": "divide-chocolate", "content_en": "

You have one chocolate bar that consists of some chunks. Each chunk has its own sweetness given by the array sweetness.

\n\n

You want to share the chocolate with your K friends so you start cutting the chocolate bar into K+1 pieces using K cuts, each piece consists of some consecutive chunks.

\n\n

Being generous, you will eat the piece with the minimum total sweetness and give the other pieces to your friends.

\n\n

Find the maximum total sweetness of the piece you can get by cutting the chocolate bar optimally.

\n\n

 

\n

Example 1:

\n\n
\nInput: sweetness = [1,2,3,4,5,6,7,8,9], K = 5\nOutput: 6\nExplanation: You can divide the chocolate to [1,2,3], [4,5], [6], [7], [8], [9]\n
\n\n

Example 2:

\n\n
\nInput: sweetness = [5,6,7,8,9,1,2,3,4], K = 8\nOutput: 1\nExplanation: There is only one way to cut the bar into 9 pieces.\n
\n\n

Example 3:

\n\n
\nInput: sweetness = [1,2,2,1,2,2,1,2,2], K = 2\nOutput: 5\nExplanation: You can divide the chocolate to [1,2,2], [1,2,2], [1,2,2]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 0 <= K < sweetness.length <= 10^4
  • \n\t
  • 1 <= sweetness[i] <= 10^5
  • \n
\n", "content_cn": "

\u4f60\u6709\u4e00\u5927\u5757\u5de7\u514b\u529b\uff0c\u5b83\u7531\u4e00\u4e9b\u751c\u5ea6\u4e0d\u5b8c\u5168\u76f8\u540c\u7684\u5c0f\u5757\u7ec4\u6210\u3002\u6211\u4eec\u7528\u6570\u7ec4 sweetness \u6765\u8868\u793a\u6bcf\u4e00\u5c0f\u5757\u7684\u751c\u5ea6\u3002

\n\n

\u4f60\u6253\u7b97\u548c K \u540d\u670b\u53cb\u4e00\u8d77\u5206\u4eab\u8fd9\u5757\u5de7\u514b\u529b\uff0c\u6240\u4ee5\u4f60\u9700\u8981\u5c06\u5207\u5272 K \u6b21\u624d\u80fd\u5f97\u5230 K+1 \u5757\uff0c\u6bcf\u4e00\u5757\u90fd\u7531\u4e00\u4e9b \u8fde\u7eed \u7684\u5c0f\u5757\u7ec4\u6210\u3002

\n\n

\u4e3a\u4e86\u8868\u73b0\u51fa\u4f60\u7684\u6177\u6168\uff0c\u4f60\u5c06\u4f1a\u5403\u6389 \u603b\u751c\u5ea6\u6700\u5c0f \u7684\u4e00\u5757\uff0c\u5e76\u5c06\u5176\u4f59\u51e0\u5757\u5206\u7ed9\u4f60\u7684\u670b\u53cb\u4eec\u3002

\n\n

\u8bf7\u627e\u51fa\u4e00\u4e2a\u6700\u4f73\u7684\u5207\u5272\u7b56\u7565\uff0c\u4f7f\u5f97\u4f60\u6240\u5206\u5f97\u7684\u5de7\u514b\u529b \u603b\u751c\u5ea6\u6700\u5927\uff0c\u5e76\u8fd4\u56de\u8fd9\u4e2a \u6700\u5927\u603b\u751c\u5ea6\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1asweetness = [1,2,3,4,5,6,7,8,9], K = 5\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u628a\u5de7\u514b\u529b\u5206\u6210 [1,2,3], [4,5], [6], [7], [8], [9]\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1asweetness = [5,6,7,8,9,1,2,3,4], K = 8\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u53ea\u6709\u4e00\u79cd\u529e\u6cd5\u53ef\u4ee5\u628a\u5de7\u514b\u529b\u5206\u6210 9 \u5757\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1asweetness = [1,2,2,1,2,2,1,2,2], K = 2\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u628a\u5de7\u514b\u529b\u5206\u6210 [1,2,2], [1,2,2], [1,2,2]\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 0 <= K < sweetness.length <= 10^4
  • \n\t
  • 1 <= sweetness[i] <= 10^5
  • \n
\n", "tags_en": ["Greedy", "Binary Search"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maximizeSweetness(vector& sweetness, int K) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maximizeSweetness(int[] sweetness, int K) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximizeSweetness(self, sweetness, K):\n \"\"\"\n :type sweetness: List[int]\n :type K: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximizeSweetness(self, sweetness: List[int], K: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maximizeSweetness(int* sweetness, int sweetnessSize, int K){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaximizeSweetness(int[] sweetness, int K) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} sweetness\n * @param {number} K\n * @return {number}\n */\nvar maximizeSweetness = function(sweetness, K) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} sweetness\n# @param {Integer} k\n# @return {Integer}\ndef maximize_sweetness(sweetness, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximizeSweetness(_ sweetness: [Int], _ K: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximizeSweetness(sweetness []int, K int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximizeSweetness(sweetness: Array[Int], K: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximizeSweetness(sweetness: IntArray, K: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximize_sweetness(sweetness: Vec, k: i32) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $sweetness\n * @param Integer $K\n * @return Integer\n */\n function maximizeSweetness($sweetness, $K) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximizeSweetness(sweetness: number[], K: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximize-sweetness sweetness K)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1231](https://leetcode-cn.com/problems/divide-chocolate)", "[\u5206\u4eab\u5de7\u514b\u529b](/solution/1200-1299/1231.Divide%20Chocolate/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u4e8c\u5206\u67e5\u627e`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1231](https://leetcode.com/problems/divide-chocolate)", "[Divide Chocolate](/solution/1200-1299/1231.Divide%20Chocolate/README_EN.md)", "`Greedy`,`Binary Search`", "Hard", "\ud83d\udd12"]}, {"question_id": "1191", "frontend_question_id": "1258", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/synonymous-sentences", "url_en": "https://leetcode.com/problems/synonymous-sentences", "relative_path_cn": "/solution/1200-1299/1258.Synonymous%20Sentences/README.md", "relative_path_en": "/solution/1200-1299/1258.Synonymous%20Sentences/README_EN.md", "title_cn": "\u8fd1\u4e49\u8bcd\u53e5\u5b50", "title_en": "Synonymous Sentences", "question_title_slug": "synonymous-sentences", "content_en": "Given a list of pairs of equivalent words synonyms and a sentence text, Return all possible synonymous sentences sorted lexicographically.\n

 

\n

Example 1:

\n\n
\nInput:\nsynonyms = [["happy","joy"],["sad","sorrow"],["joy","cheerful"]],\ntext = "I am happy today but was sad yesterday"\nOutput:\n["I am cheerful today but was sad yesterday",\n"I am cheerful today but was sorrow yesterday",\n"I am happy today but was sad yesterday",\n"I am happy today but was sorrow yesterday",\n"I am joy today but was sad yesterday",\n"I am joy today but was sorrow yesterday"]\n
\n\n

Example 2:

\n\n
\nInput: synonyms = [["happy","joy"],["cheerful","glad"]], text = "I am happy today but was sad yesterday"\nOutput: ["I am happy today but was sad yesterday","I am joy today but was sad yesterday"]\n
\n\n

Example 3:

\n\n
\nInput: synonyms = [["a","b"],["c","d"],["e","f"]], text = "a c e"\nOutput: ["a c e","a c f","a d e","a d f","b c e","b c f","b d e","b d f"]\n
\n\n

Example 4:

\n\n
\nInput: synonyms = [["a","QrbCl"]], text = "d QrbCl ya ya NjZQ"\nOutput: ["d QrbCl ya ya NjZQ","d a ya ya NjZQ"]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 0 <= synonyms.length <= 10
  • \n\t
  • synonyms[i].length == 2
  • \n\t
  • synonyms[i][0] != synonyms[i][1]
  • \n\t
  • All words consist of at most 10 English letters only.
  • \n\t
  • text is a single space separated sentence of at most 10 words.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u8fd1\u4e49\u8bcd\u8868 synonyms \u548c\u4e00\u4e2a\u53e5\u5b50 text \uff0c synonyms \u8868\u4e2d\u662f\u4e00\u4e9b\u8fd1\u4e49\u8bcd\u5bf9 \uff0c\u4f60\u53ef\u4ee5\u5c06\u53e5\u5b50 text \u4e2d\u6bcf\u4e2a\u5355\u8bcd\u7528\u5b83\u7684\u8fd1\u4e49\u8bcd\u6765\u66ff\u6362\u3002

\n\n

\u8bf7\u4f60\u627e\u51fa\u6240\u6709\u7528\u8fd1\u4e49\u8bcd\u66ff\u6362\u540e\u7684\u53e5\u5b50\uff0c\u6309 \u5b57\u5178\u5e8f\u6392\u5e8f \u540e\u8fd4\u56de\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1a\nsynonyms = [["happy","joy"],["sad","sorrow"],["joy","cheerful"]],\ntext = "I am happy today but was sad yesterday"\n\u8f93\u51fa\uff1a\n["I am cheerful today but was sad yesterday",\n"I am cheerful today but was sorrow yesterday",\n"I am happy today but was sad yesterday",\n"I am happy today but was sorrow yesterday",\n"I am joy today but was sad yesterday",\n"I am joy today but was sorrow yesterday"]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 0 <= synonyms.length <= 10
  • \n\t
  • synonyms[i].length == 2
  • \n\t
  • synonyms[0] != synonyms[1]
  • \n\t
  • \u6240\u6709\u5355\u8bcd\u4ec5\u5305\u542b\u82f1\u6587\u5b57\u6bcd\uff0c\u4e14\u957f\u5ea6\u6700\u591a\u4e3a 10 \u3002
  • \n\t
  • text \u6700\u591a\u5305\u542b 10 \u4e2a\u5355\u8bcd\uff0c\u4e14\u5355\u8bcd\u95f4\u7528\u5355\u4e2a\u7a7a\u683c\u5206\u9694\u5f00\u3002
  • \n
\n", "tags_en": ["Backtracking"], "tags_cn": ["\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector generateSentences(vector>& synonyms, string text) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List generateSentences(List> synonyms, String text) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def generateSentences(self, synonyms, text):\n \"\"\"\n :type synonyms: List[List[str]]\n :type text: str\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def generateSentences(self, synonyms: List[List[str]], text: str) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** generateSentences(char *** synonyms, int synonymsSize, int* synonymsColSize, char * text, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList GenerateSentences(IList> synonyms, string text) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[][]} synonyms\n * @param {string} text\n * @return {string[]}\n */\nvar generateSentences = function(synonyms, text) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[][]} synonyms\n# @param {String} text\n# @return {String[]}\ndef generate_sentences(synonyms, text)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func generateSentences(_ synonyms: [[String]], _ text: String) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func generateSentences(synonyms [][]string, text string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def generateSentences(synonyms: List[List[String]], text: String): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun generateSentences(synonyms: List>, text: String): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn generate_sentences(synonyms: Vec>, text: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $synonyms\n * @param String $text\n * @return String[]\n */\n function generateSentences($synonyms, $text) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function generateSentences(synonyms: string[][], text: string): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (generate-sentences synonyms text)\n (-> (listof (listof string?)) string? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1258](https://leetcode-cn.com/problems/synonymous-sentences)", "[\u8fd1\u4e49\u8bcd\u53e5\u5b50](/solution/1200-1299/1258.Synonymous%20Sentences/README.md)", "`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1258](https://leetcode.com/problems/synonymous-sentences)", "[Synonymous Sentences](/solution/1200-1299/1258.Synonymous%20Sentences/README_EN.md)", "`Backtracking`", "Medium", "\ud83d\udd12"]}, {"question_id": "1190", "frontend_question_id": "1257", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/smallest-common-region", "url_en": "https://leetcode.com/problems/smallest-common-region", "relative_path_cn": "/solution/1200-1299/1257.Smallest%20Common%20Region/README.md", "relative_path_en": "/solution/1200-1299/1257.Smallest%20Common%20Region/README_EN.md", "title_cn": "\u6700\u5c0f\u516c\u5171\u533a\u57df", "title_en": "Smallest Common Region", "question_title_slug": "smallest-common-region", "content_en": "

You are given some lists of regions where the first region of each list includes all other regions in that list.

\n\n

Naturally, if a region X contains another region Y then X is bigger than Y. Also by definition a region X contains itself.

\n\n

Given two regions region1, region2, find out the smallest region that contains both of them.

\n\n

If you are given regions r1, r2 and r3 such that r1 includes r3, it is guaranteed there is no r2 such that r2 includes r3.
\n
\nIt's guaranteed the smallest region exists.

\n\n

 

\n

Example 1:

\n\n
\nInput:\nregions = [["Earth","North America","South America"],\n["North America","United States","Canada"],\n["United States","New York","Boston"],\n["Canada","Ontario","Quebec"],\n["South America","Brazil"]],\nregion1 = "Quebec",\nregion2 = "New York"\nOutput: "North America"\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= regions.length <= 10^4
  • \n\t
  • region1 != region2
  • \n\t
  • All strings consist of English letters and spaces with at most 20 letters.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e9b\u533a\u57df\u5217\u8868 regions \uff0c\u6bcf\u4e2a\u5217\u8868\u7684\u7b2c\u4e00\u4e2a\u533a\u57df\u90fd\u5305\u542b\u8fd9\u4e2a\u5217\u8868\u5185\u6240\u6709\u5176\u4ed6\u533a\u57df\u3002

\n\n

\u5f88\u81ea\u7136\u5730\uff0c\u5982\u679c\u533a\u57df X \u5305\u542b\u533a\u57df Y \uff0c\u90a3\u4e48\u533a\u57df X  \u6bd4\u533a\u57df Y \u5927\u3002

\n\n

\u7ed9\u5b9a\u4e24\u4e2a\u533a\u57df region1 \u548c region2 \uff0c\u627e\u5230\u540c\u65f6\u5305\u542b\u8fd9\u4e24\u4e2a\u533a\u57df\u7684 \u6700\u5c0f \u533a\u57df\u3002

\n\n

\u5982\u679c\u533a\u57df\u5217\u8868\u4e2d r1 \u5305\u542b r2 \u548c r3 \uff0c\u90a3\u4e48\u6570\u636e\u4fdd\u8bc1 r2 \u4e0d\u4f1a\u5305\u542b r3 \u3002

\n\n

\u6570\u636e\u540c\u6837\u4fdd\u8bc1\u6700\u5c0f\u516c\u5171\u533a\u57df\u4e00\u5b9a\u5b58\u5728\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1a\nregions = [["Earth","North America","South America"],\n["North America","United States","Canada"],\n["United States","New York","Boston"],\n["Canada","Ontario","Quebec"],\n["South America","Brazil"]],\nregion1 = "Quebec",\nregion2 = "New York"\n\u8f93\u51fa\uff1a"North America"\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= regions.length <= 10^4
  • \n\t
  • region1 != region2
  • \n\t
  • \u6240\u6709\u5b57\u7b26\u4e32\u53ea\u5305\u542b\u82f1\u6587\u5b57\u6bcd\u548c\u7a7a\u683c\uff0c\u4e14\u6700\u591a\u53ea\u6709 20 \u4e2a\u5b57\u6bcd\u3002
  • \n
\n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string findSmallestRegion(vector>& regions, string region1, string region2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String findSmallestRegion(List> regions, String region1, String region2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findSmallestRegion(self, regions, region1, region2):\n \"\"\"\n :type regions: List[List[str]]\n :type region1: str\n :type region2: str\n :rtype: str\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findSmallestRegion(self, regions: List[List[str]], region1: str, region2: str) -> str:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * findSmallestRegion(char *** regions, int regionsSize, int* regionsColSize, char * region1, char * region2){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string FindSmallestRegion(IList> regions, string region1, string region2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[][]} regions\n * @param {string} region1\n * @param {string} region2\n * @return {string}\n */\nvar findSmallestRegion = function(regions, region1, region2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[][]} regions\n# @param {String} region1\n# @param {String} region2\n# @return {String}\ndef find_smallest_region(regions, region1, region2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findSmallestRegion(_ regions: [[String]], _ region1: String, _ region2: String) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findSmallestRegion(regions [][]string, region1 string, region2 string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findSmallestRegion(regions: List[List[String]], region1: String, region2: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findSmallestRegion(regions: List>, region1: String, region2: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_smallest_region(regions: Vec>, region1: String, region2: String) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $regions\n * @param String $region1\n * @param String $region2\n * @return String\n */\n function findSmallestRegion($regions, $region1, $region2) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findSmallestRegion(regions: string[][], region1: string, region2: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-smallest-region regions region1 region2)\n (-> (listof (listof string?)) string? string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1257](https://leetcode-cn.com/problems/smallest-common-region)", "[\u6700\u5c0f\u516c\u5171\u533a\u57df](/solution/1200-1299/1257.Smallest%20Common%20Region/README.md)", "`\u6811`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1257](https://leetcode.com/problems/smallest-common-region)", "[Smallest Common Region](/solution/1200-1299/1257.Smallest%20Common%20Region/README_EN.md)", "`Tree`", "Medium", "\ud83d\udd12"]}, {"question_id": "1189", "frontend_question_id": "1256", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/encode-number", "url_en": "https://leetcode.com/problems/encode-number", "relative_path_cn": "/solution/1200-1299/1256.Encode%20Number/README.md", "relative_path_en": "/solution/1200-1299/1256.Encode%20Number/README_EN.md", "title_cn": "\u52a0\u5bc6\u6570\u5b57", "title_en": "Encode Number", "question_title_slug": "encode-number", "content_en": "

Given a non-negative integer num, Return its encoding string.

\r\n\r\n

The encoding is done by converting the integer to a string using a secret function that you should deduce from the following table:

\r\n\r\n

\"\"

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: num = 23\r\nOutput: "1000"\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: num = 107\r\nOutput: "101100"\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 0 <= num <= 10^9
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u975e\u8d1f\u6574\u6570 num \uff0c\u8fd4\u56de\u5b83\u7684\u300c\u52a0\u5bc6\u5b57\u7b26\u4e32\u300d\u3002

\n\n

\u52a0\u5bc6\u7684\u8fc7\u7a0b\u662f\u628a\u4e00\u4e2a\u6574\u6570\u7528\u67d0\u4e2a\u672a\u77e5\u51fd\u6570\u8fdb\u884c\u8f6c\u5316\uff0c\u4f60\u9700\u8981\u4ece\u4e0b\u8868\u63a8\u6d4b\u51fa\u8be5\u8f6c\u5316\u51fd\u6570\uff1a

\n\n

\"\"

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anum = 23\n\u8f93\u51fa\uff1a"1000"\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anum = 107\n\u8f93\u51fa\uff1a"101100"\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 0 <= num <= 10^9
  • \n
\n", "tags_en": ["Bit Manipulation", "Math"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string encode(int num) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String encode(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def encode(self, num):\n \"\"\"\n :type num: int\n :rtype: str\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def encode(self, num: int) -> str:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * encode(int num){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string Encode(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} num\n * @return {string}\n */\nvar encode = function(num) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} num\n# @return {String}\ndef encode(num)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func encode(_ num: Int) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func encode(num int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def encode(num: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun encode(num: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn encode(num: i32) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $num\n * @return String\n */\n function encode($num) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function encode(num: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (encode num)\n (-> exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1256](https://leetcode-cn.com/problems/encode-number)", "[\u52a0\u5bc6\u6570\u5b57](/solution/1200-1299/1256.Encode%20Number/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u6570\u5b66`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1256](https://leetcode.com/problems/encode-number)", "[Encode Number](/solution/1200-1299/1256.Encode%20Number/README_EN.md)", "`Bit Manipulation`,`Math`", "Medium", "\ud83d\udd12"]}, {"question_id": "1188", "frontend_question_id": "1096", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/brace-expansion-ii", "url_en": "https://leetcode.com/problems/brace-expansion-ii", "relative_path_cn": "/solution/1000-1099/1096.Brace%20Expansion%20II/README.md", "relative_path_en": "/solution/1000-1099/1096.Brace%20Expansion%20II/README_EN.md", "title_cn": "\u82b1\u62ec\u53f7\u5c55\u5f00 II", "title_en": "Brace Expansion II", "question_title_slug": "brace-expansion-ii", "content_en": "

Under a grammar given below, strings can represent a set of lowercase words.  Let's use R(expr) to denote the set of words the expression represents.

\n\n

Grammar can best be understood through simple examples:

\n\n
    \n\t
  • Single letters represent a singleton set containing that word.\n\t
      \n\t\t
    • R("a") = {"a"}
    • \n\t\t
    • R("w") = {"w"}
    • \n\t
    \n\t
  • \n\t
  • When we take a comma delimited list of 2 or more expressions, we take the union of possibilities.\n\t
      \n\t\t
    • R("{a,b,c}") = {"a","b","c"}
    • \n\t\t
    • R("{{a,b},{b,c}}") = {"a","b","c"} (notice the final set only contains each word at most once)
    • \n\t
    \n\t
  • \n\t
  • When we concatenate two expressions, we take the set of possible concatenations between two words where the first word comes from the first expression and the second word comes from the second expression.\n\t
      \n\t\t
    • R("{a,b}{c,d}") = {"ac","ad","bc","bd"}
    • \n\t\t
    • R("a{b,c}{d,e}f{g,h}") = {"abdfg", "abdfh", "abefg", "abefh", "acdfg", "acdfh", "acefg", "acefh"}
    • \n\t
    \n\t
  • \n
\n\n

Formally, the 3 rules for our grammar:

\n\n
    \n\t
  • For every lowercase letter x, we have R(x) = {x}
  • \n\t
  • For expressions e_1, e_2, ... , e_k with k >= 2, we have R({e_1,e_2,...}) = R(e_1) ∪ R(e_2) ∪ ...
  • \n\t
  • For expressions e_1 and e_2, we have R(e_1 + e_2) = {a + b for (a, b) in R(e_1) × R(e_2)}, where + denotes concatenation, and × denotes the cartesian product.
  • \n
\n\n

Given an expression representing a set of words under the given grammar, return the sorted list of words that the expression represents.

\n\n

 

\n\n
\n

Example 1:

\n\n
\nInput: "{a,b}{c,{d,e}}"\nOutput: ["ac","ad","ae","bc","bd","be"]\n
\n\n
\n

Example 2:

\n\n
\nInput: "{{a,z},a{b,c},{ab,z}}"\nOutput: ["a","ab","ac","z"]\nExplanation: Each distinct word is written only once in the final answer.\n
\n\n

 

\n\n

Constraints:

\n\n
    \n\t
  1. 1 <= expression.length <= 60
  2. \n\t
  3. expression[i] consists of '{', '}', ','or lowercase English letters.
  4. \n\t
  5. The given expression represents a set of words based on the grammar given in the description.
  6. \n
\n
\n
\n", "content_cn": "

\u5982\u679c\u4f60\u719f\u6089 Shell \u7f16\u7a0b\uff0c\u90a3\u4e48\u4e00\u5b9a\u4e86\u89e3\u8fc7\u82b1\u62ec\u53f7\u5c55\u5f00\uff0c\u5b83\u53ef\u4ee5\u7528\u6765\u751f\u6210\u4efb\u610f\u5b57\u7b26\u4e32\u3002

\n\n

\u82b1\u62ec\u53f7\u5c55\u5f00\u7684\u8868\u8fbe\u5f0f\u53ef\u4ee5\u770b\u4f5c\u4e00\u4e2a\u7531 \u82b1\u62ec\u53f7\u3001\u9017\u53f7 \u548c \u5c0f\u5199\u82f1\u6587\u5b57\u6bcd \u7ec4\u6210\u7684\u5b57\u7b26\u4e32\uff0c\u5b9a\u4e49\u4e0b\u9762\u51e0\u6761\u8bed\u6cd5\u89c4\u5219\uff1a

\n\n
    \n\t
  • \u5982\u679c\u53ea\u7ed9\u51fa\u5355\u4e00\u7684\u5143\u7d20\u00a0x\uff0c\u90a3\u4e48\u8868\u8fbe\u5f0f\u8868\u793a\u7684\u5b57\u7b26\u4e32\u5c31\u53ea\u6709\u00a0\"x\"\u3002R(x) = {x}\n\n\t
      \n\t\t
    • \u4f8b\u5982\uff0c\u8868\u8fbe\u5f0f {\"a\"}\u00a0\u8868\u793a\u5b57\u7b26\u4e32 \"a\"\u3002
    • \n\t\t
    • \u800c\u8868\u8fbe\u5f0f {\"w\"}\u00a0\u5c31\u8868\u793a\u5b57\u7b26\u4e32 \"w\"\u3002
    • \n\t
    \n\t
  • \n\t
  • \u5f53\u4e24\u4e2a\u6216\u591a\u4e2a\u8868\u8fbe\u5f0f\u5e76\u5217\uff0c\u4ee5\u9017\u53f7\u5206\u9694\u65f6\uff0c\u6211\u4eec\u53d6\u8fd9\u4e9b\u8868\u8fbe\u5f0f\u4e2d\u5143\u7d20\u7684\u5e76\u96c6\u3002R({e_1,e_2,...}) = R(e_1)\u00a0\u222a R(e_2)\u00a0\u222a ...\n\t
      \n\t\t
    • \u4f8b\u5982\uff0c\u8868\u8fbe\u5f0f \"{a,b,c}\" \u8868\u793a\u5b57\u7b26\u4e32\u00a0\"a\",\"b\",\"c\"\u3002
    • \n\t\t
    • \u800c\u8868\u8fbe\u5f0f \"{{a,b},{b,c}}\" \u4e5f\u53ef\u4ee5\u8868\u793a\u5b57\u7b26\u4e32\u00a0\"a\",\"b\",\"c\"\u3002
    • \n\t
    \n\t
  • \n\t
  • \u8981\u662f\u4e24\u4e2a\u6216\u591a\u4e2a\u8868\u8fbe\u5f0f\u76f8\u63a5\uff0c\u4e2d\u95f4\u6ca1\u6709\u9694\u5f00\u65f6\uff0c\u6211\u4eec\u4ece\u8fd9\u4e9b\u8868\u8fbe\u5f0f\u4e2d\u5404\u53d6\u4e00\u4e2a\u5143\u7d20\u4f9d\u6b21\u8fde\u63a5\u5f62\u6210\u5b57\u7b26\u4e32\u3002R(e_1 + e_2) = {a + b for (a, b) in\u00a0R(e_1)\u00a0\u00d7 R(e_2)}\n\t
      \n\t\t
    • \u4f8b\u5982\uff0c\u8868\u8fbe\u5f0f \"{a,b}{c,d}\" \u8868\u793a\u5b57\u7b26\u4e32\u00a0\"ac\",\"ad\",\"bc\",\"bd\"\u3002
    • \n\t
    \n\t
  • \n\t
  • \u8868\u8fbe\u5f0f\u4e4b\u95f4\u5141\u8bb8\u5d4c\u5957\uff0c\u5355\u4e00\u5143\u7d20\u4e0e\u8868\u8fbe\u5f0f\u7684\u8fde\u63a5\u4e5f\u662f\u5141\u8bb8\u7684\u3002\n\t
      \n\t\t
    • \u4f8b\u5982\uff0c\u8868\u8fbe\u5f0f \"a{b,c,d}\" \u8868\u793a\u5b57\u7b26\u4e32\u00a0\"ab\",\"ac\",\"ad\"\u200b\u200b\u200b\u200b\u200b\u200b\u3002
    • \n\t\t
    • \u4f8b\u5982\uff0c\u8868\u8fbe\u5f0f \"a{b,c}{d,e}f{g,h}\" \u53ef\u4ee5\u8868\u793a\u5b57\u7b26\u4e32\u00a0\"abdfg\", \"abdfh\", \"abefg\", \"abefh\", \"acdfg\", \"acdfh\", \"acefg\", \"acefh\"\u3002
    • \n\t
    \n\t
  • \n
\n\n

\u7ed9\u51fa\u8868\u793a\u57fa\u4e8e\u7ed9\u5b9a\u8bed\u6cd5\u89c4\u5219\u7684\u8868\u8fbe\u5f0f\u00a0expression\uff0c\u8fd4\u56de\u5b83\u6240\u8868\u793a\u7684\u6240\u6709\u5b57\u7b26\u4e32\u7ec4\u6210\u7684\u6709\u5e8f\u5217\u8868\u3002

\n\n

\u5047\u5982\u4f60\u5e0c\u671b\u4ee5\u300c\u96c6\u5408\u300d\u7684\u6982\u5ff5\u4e86\u89e3\u6b64\u9898\uff0c\u4e5f\u53ef\u4ee5\u901a\u8fc7\u70b9\u51fb \u201c\u663e\u793a\u82f1\u6587\u63cf\u8ff0\u201d \u83b7\u53d6\u8be6\u60c5\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1a\"{a,b}{c,{d,e}}\"\n\u8f93\u51fa\uff1a[\"ac\",\"ad\",\"ae\",\"bc\",\"bd\",\"be\"]
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1a\"{{a,z},a{b,c},{ab,z}}\"\n\u8f93\u51fa\uff1a[\"a\",\"ab\",\"ac\",\"z\"]\n\u89e3\u91ca\uff1a\u8f93\u51fa\u4e2d \u4e0d\u5e94 \u51fa\u73b0\u91cd\u590d\u7684\u7ec4\u5408\u7ed3\u679c\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= expression.length <= 50
  2. \n\t
  3. expression[i] \u7531 '{'\uff0c'}'\uff0c','\u00a0\u6216\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
  4. \n\t
  5. \u7ed9\u51fa\u7684\u8868\u8fbe\u5f0f\u00a0expression\u00a0\u7528\u4ee5\u8868\u793a\u4e00\u7ec4\u57fa\u4e8e\u9898\u76ee\u63cf\u8ff0\u4e2d\u8bed\u6cd5\u6784\u9020\u7684\u5b57\u7b26\u4e32
  6. \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector braceExpansionII(string expression) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List braceExpansionII(String expression) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def braceExpansionII(self, expression):\n \"\"\"\n :type expression: str\n :rtype: List[str]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def braceExpansionII(self, expression: str) -> List[str]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** braceExpansionII(char * expression, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList BraceExpansionII(string expression) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} expression\n * @return {string[]}\n */\nvar braceExpansionII = function(expression) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} expression\n# @return {String[]}\ndef brace_expansion_ii(expression)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func braceExpansionII(_ expression: String) -> [String] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func braceExpansionII(expression string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def braceExpansionII(expression: String): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun braceExpansionII(expression: String): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn brace_expansion_ii(expression: String) -> Vec {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $expression\n * @return String[]\n */\n function braceExpansionII($expression) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function braceExpansionII(expression: string): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (brace-expansion-ii expression)\n (-> string? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1096](https://leetcode-cn.com/problems/brace-expansion-ii)", "[\u82b1\u62ec\u53f7\u5c55\u5f00 II](/solution/1000-1099/1096.Brace%20Expansion%20II/README.md)", "`\u5b57\u7b26\u4e32`", "\u56f0\u96be", ""], "md_table_row_en": ["[1096](https://leetcode.com/problems/brace-expansion-ii)", "[Brace Expansion II](/solution/1000-1099/1096.Brace%20Expansion%20II/README_EN.md)", "`String`", "Hard", ""]}, {"question_id": "1187", "frontend_question_id": "1115", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/print-foobar-alternately", "url_en": "https://leetcode.com/problems/print-foobar-alternately", "relative_path_cn": "/solution/1100-1199/1115.Print%20FooBar%20Alternately/README.md", "relative_path_en": "/solution/1100-1199/1115.Print%20FooBar%20Alternately/README_EN.md", "title_cn": "\u4ea4\u66ff\u6253\u5370FooBar", "title_en": "Print FooBar Alternately", "question_title_slug": "print-foobar-alternately", "content_en": "

Suppose you are given the following code:

\n\n
\nclass FooBar {\n  public void foo() {\n    for (int i = 0; i < n; i++) {\n      print("foo");\n    }\n  }\n\n  public void bar() {\n    for (int i = 0; i < n; i++) {\n      print("bar");\n    }\n  }\n}\n
\n\n

The same instance of FooBar will be passed to two different threads. Thread A will call foo() while thread B will call bar(). Modify the given program to output "foobar" n times.

\n\n

 

\n\n

Example 1:

\n\n
\nInput: n = 1\nOutput: "foobar"\nExplanation: There are two threads being fired asynchronously. One of them calls foo(), while the other calls bar(). "foobar" is being output 1 time.\n
\n\n

Example 2:

\n\n
\nInput: n = 2\nOutput: "foobarfoobar"\nExplanation: "foobar" is being output 2 times.\n
\n", "content_cn": "

\u6211\u4eec\u63d0\u4f9b\u4e00\u4e2a\u7c7b\uff1a

\n\n
\nclass FooBar {\n  public void foo() {\n    for (int i = 0; i < n; i++) {\n      print("foo");\n    }\n  }\n\n  public void bar() {\n    for (int i = 0; i < n; i++) {\n      print("bar");\n    }\n  }\n}\n
\n\n

\u4e24\u4e2a\u4e0d\u540c\u7684\u7ebf\u7a0b\u5c06\u4f1a\u5171\u7528\u4e00\u4e2a FooBar \u5b9e\u4f8b\u3002\u5176\u4e2d\u4e00\u4e2a\u7ebf\u7a0b\u5c06\u4f1a\u8c03\u7528 foo() \u65b9\u6cd5\uff0c\u53e6\u4e00\u4e2a\u7ebf\u7a0b\u5c06\u4f1a\u8c03\u7528 bar() \u65b9\u6cd5\u3002

\n\n

\u8bf7\u8bbe\u8ba1\u4fee\u6539\u7a0b\u5e8f\uff0c\u4ee5\u786e\u4fdd "foobar" \u88ab\u8f93\u51fa n \u6b21\u3002

\n\n

 

\n\n

\u793a\u4f8b 1:

\n\n
\n\u8f93\u5165: n = 1\n\u8f93\u51fa: "foobar"\n\u89e3\u91ca: \u8fd9\u91cc\u6709\u4e24\u4e2a\u7ebf\u7a0b\u88ab\u5f02\u6b65\u542f\u52a8\u3002\u5176\u4e2d\u4e00\u4e2a\u8c03\u7528 foo() \u65b9\u6cd5, \u53e6\u4e00\u4e2a\u8c03\u7528 bar() \u65b9\u6cd5\uff0c"foobar" \u5c06\u88ab\u8f93\u51fa\u4e00\u6b21\u3002\n
\n\n

\u793a\u4f8b 2:

\n\n
\n\u8f93\u5165: n = 2\n\u8f93\u51fa: "foobarfoobar"\n\u89e3\u91ca: "foobar" \u5c06\u88ab\u8f93\u51fa\u4e24\u6b21\u3002\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class FooBar {\nprivate:\n int n;\n\npublic:\n FooBar(int n) {\n this->n = n;\n }\n\n void foo(function printFoo) {\n \n for (int i = 0; i < n; i++) {\n \n \t// printFoo() outputs \"foo\". Do not change or remove this line.\n \tprintFoo();\n }\n }\n\n void bar(function printBar) {\n \n for (int i = 0; i < n; i++) {\n \n \t// printBar() outputs \"bar\". Do not change or remove this line.\n \tprintBar();\n }\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class FooBar {\n private int n;\n\n public FooBar(int n) {\n this.n = n;\n }\n\n public void foo(Runnable printFoo) throws InterruptedException {\n \n for (int i = 0; i < n; i++) {\n \n \t// printFoo.run() outputs \"foo\". Do not change or remove this line.\n \tprintFoo.run();\n }\n }\n\n public void bar(Runnable printBar) throws InterruptedException {\n \n for (int i = 0; i < n; i++) {\n \n // printBar.run() outputs \"bar\". Do not change or remove this line.\n \tprintBar.run();\n }\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class FooBar(object):\n def __init__(self, n):\n self.n = n\n\n\n def foo(self, printFoo):\n \"\"\"\n :type printFoo: method\n :rtype: void\n \"\"\"\n for i in xrange(self.n):\n \n # printFoo() outputs \"foo\". Do not change or remove this line.\n \tprintFoo()\n\n\n def bar(self, printBar):\n \"\"\"\n :type printBar: method\n :rtype: void\n \"\"\"\n for i in xrange(self.n):\n \n # printBar() outputs \"bar\". Do not change or remove this line.\n \tprintBar()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class FooBar:\n def __init__(self, n):\n self.n = n\n\n\n def foo(self, printFoo: 'Callable[[], None]') -> None:\n \n for i in range(self.n):\n \n # printFoo() outputs \"foo\". Do not change or remove this line.\n \tprintFoo()\n\n\n def bar(self, printBar: 'Callable[[], None]') -> None:\n \n for i in range(self.n):\n \n # printBar() outputs \"bar\". Do not change or remove this line.\n \tprintBar()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "typedef struct {\n int n;\n} FooBar;\n\nFooBar* fooBarCreate(int n) {\n FooBar* obj = (FooBar*) malloc(sizeof(FooBar));\n obj->n = n;\n return obj;\n}\n\nvoid foo(FooBar* obj) {\n \n for (int i = 0; i < obj->n; i++) {\n \n // printFoo() outputs \"foo\". Do not change or remove this line.\n printFoo();\n }\n}\n\nvoid bar(FooBar* obj) {\n \n for (int i = 0; i < obj->n; i++) {\n \n // printBar() outputs \"bar\". Do not change or remove this line.\n printBar();\n }\n}\n\nvoid fooBarFree(FooBar* obj) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class FooBar {\n private int n;\n\n public FooBar(int n) {\n this.n = n;\n }\n\n public void Foo(Action printFoo) {\n \n for (int i = 0; i < n; i++) {\n \n \t// printFoo() outputs \"foo\". Do not change or remove this line.\n \tprintFoo();\n }\n }\n\n public void Bar(Action printBar) {\n \n for (int i = 0; i < n; i++) {\n \n // printBar() outputs \"bar\". Do not change or remove this line.\n \tprintBar();\n }\n }\n}", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1115](https://leetcode-cn.com/problems/print-foobar-alternately)", "[\u4ea4\u66ff\u6253\u5370FooBar](/solution/1100-1199/1115.Print%20FooBar%20Alternately/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1115](https://leetcode.com/problems/print-foobar-alternately)", "[Print FooBar Alternately](/solution/1100-1199/1115.Print%20FooBar%20Alternately/README_EN.md)", "", "Medium", ""]}, {"question_id": "1186", "frontend_question_id": "1117", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/building-h2o", "url_en": "https://leetcode.com/problems/building-h2o", "relative_path_cn": "/solution/1100-1199/1117.Building%20H2O/README.md", "relative_path_en": "/solution/1100-1199/1117.Building%20H2O/README_EN.md", "title_cn": "H2O \u751f\u6210", "title_en": "Building H2O", "question_title_slug": "building-h2o", "content_en": "

There are two kinds of threads, oxygen and hydrogen. Your goal is to group these threads to form water molecules. There is a barrier where each thread has to wait until a complete molecule can be formed. Hydrogen and oxygen threads will be given releaseHydrogen and releaseOxygen methods respectively, which will allow them to pass the barrier. These threads should pass the barrier in groups of three, and they must be able to immediately bond with each other to form a water molecule. You must guarantee that all the threads from one molecule bond before any other threads from the next molecule do.

\n\n

In other words:

\n\n
    \n\t
  • If an oxygen thread arrives at the barrier when no hydrogen threads are present, it has to wait for two hydrogen threads.
  • \n\t
  • If a hydrogen thread arrives at the barrier when no other threads are present, it has to wait for an oxygen thread and another hydrogen thread.
  • \n
\n\n

We don’t have to worry about matching the threads up explicitly; that is, the threads do not necessarily know which other threads they are paired up with. The key is just that threads pass the barrier in complete sets; thus, if we examine the sequence of threads that bond and divide them into groups of three, each group should contain one oxygen and two hydrogen threads.

\n\n

Write synchronization code for oxygen and hydrogen molecules that enforces these constraints.

\n\n
\n

 

\n
\n\n
\n

Example 1:

\n\n
\nInput: "HOH"\nOutput: "HHO"\nExplanation: "HOH" and "OHH" are also valid answers.\n
\n\n
\n

Example 2:

\n\n
\nInput: "OOHHHH"\nOutput: "HHOHHO"\nExplanation: "HOHHHO", "OHHHHO", "HHOHOH", "HOHHOH", "OHHHOH", "HHOOHH", "HOHOHH" and "OHHOHH" are also valid answers.\n
\n
\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • Total length of input string will be 3n, where 1 ≤ n ≤ 20.
  • \n\t
  • Total number of H will be 2n in the input string.
  • \n\t
  • Total number of O will be n in the input string.
  • \n
\n", "content_cn": "

\u73b0\u5728\u6709\u4e24\u79cd\u7ebf\u7a0b\uff0c\u6c27 oxygen \u548c\u6c22 hydrogen\uff0c\u4f60\u7684\u76ee\u6807\u662f\u7ec4\u7ec7\u8fd9\u4e24\u79cd\u7ebf\u7a0b\u6765\u4ea7\u751f\u6c34\u5206\u5b50\u3002

\n\n

\u5b58\u5728\u4e00\u4e2a\u5c4f\u969c\uff08barrier\uff09\u4f7f\u5f97\u6bcf\u4e2a\u7ebf\u7a0b\u5fc5\u987b\u7b49\u5019\u76f4\u5230\u4e00\u4e2a\u5b8c\u6574\u6c34\u5206\u5b50\u80fd\u591f\u88ab\u4ea7\u751f\u51fa\u6765\u3002

\n\n

\u6c22\u548c\u6c27\u7ebf\u7a0b\u4f1a\u88ab\u5206\u522b\u7ed9\u4e88 releaseHydrogen \u548c releaseOxygen \u65b9\u6cd5\u6765\u5141\u8bb8\u5b83\u4eec\u7a81\u7834\u5c4f\u969c\u3002

\n\n

\u8fd9\u4e9b\u7ebf\u7a0b\u5e94\u8be5\u4e09\u4e09\u6210\u7ec4\u7a81\u7834\u5c4f\u969c\u5e76\u80fd\u7acb\u5373\u7ec4\u5408\u4ea7\u751f\u4e00\u4e2a\u6c34\u5206\u5b50\u3002

\n\n

\u4f60\u5fc5\u987b\u4fdd\u8bc1\u4ea7\u751f\u4e00\u4e2a\u6c34\u5206\u5b50\u6240\u9700\u7ebf\u7a0b\u7684\u7ed3\u5408\u5fc5\u987b\u53d1\u751f\u5728\u4e0b\u4e00\u4e2a\u6c34\u5206\u5b50\u4ea7\u751f\u4e4b\u524d\u3002

\n\n

\u6362\u53e5\u8bdd\u8bf4:

\n\n
    \n\t
  • \u5982\u679c\u4e00\u4e2a\u6c27\u7ebf\u7a0b\u5230\u8fbe\u5c4f\u969c\u65f6\u6ca1\u6709\u6c22\u7ebf\u7a0b\u5230\u8fbe\uff0c\u5b83\u5fc5\u987b\u7b49\u5019\u76f4\u5230\u4e24\u4e2a\u6c22\u7ebf\u7a0b\u5230\u8fbe\u3002
  • \n\t
  • \u5982\u679c\u4e00\u4e2a\u6c22\u7ebf\u7a0b\u5230\u8fbe\u5c4f\u969c\u65f6\u6ca1\u6709\u5176\u5b83\u7ebf\u7a0b\u5230\u8fbe\uff0c\u5b83\u5fc5\u987b\u7b49\u5019\u76f4\u5230\u4e00\u4e2a\u6c27\u7ebf\u7a0b\u548c\u53e6\u4e00\u4e2a\u6c22\u7ebf\u7a0b\u5230\u8fbe\u3002
  • \n
\n\n

\u4e66\u5199\u6ee1\u8db3\u8fd9\u4e9b\u9650\u5236\u6761\u4ef6\u7684\u6c22\u3001\u6c27\u7ebf\u7a0b\u540c\u6b65\u4ee3\u7801\u3002

\n\n

 

\n\n

\u793a\u4f8b 1:

\n\n
\u8f93\u5165: "HOH"\n\u8f93\u51fa: "HHO"\n\u89e3\u91ca: "HOH" \u548c "OHH" \u4f9d\u7136\u90fd\u662f\u6709\u6548\u89e3\u3002\n
\n\n

\u793a\u4f8b 2:

\n\n
\u8f93\u5165: "OOHHHH"\n\u8f93\u51fa: "HHOHHO"\n\u89e3\u91ca: "HOHHHO", "OHHHHO", "HHOHOH", "HOHHOH", "OHHHOH", "HHOOHH", "HOHOHH" \u548c "OHHOHH" \u4f9d\u7136\u90fd\u662f\u6709\u6548\u89e3\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u8f93\u5165\u5b57\u7b26\u4e32\u7684\u603b\u957f\u5c06\u4f1a\u662f 3n, 1 ≤ n ≤ 50\uff1b
  • \n\t
  • \u8f93\u5165\u5b57\u7b26\u4e32\u4e2d\u7684 “H” \u603b\u6570\u5c06\u4f1a\u662f 2n \u3002
  • \n\t
  • \u8f93\u5165\u5b57\u7b26\u4e32\u4e2d\u7684 “O” \u603b\u6570\u5c06\u4f1a\u662f n \u3002
  • \n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class H2O {\npublic:\n H2O() {\n \n }\n\n void hydrogen(function releaseHydrogen) {\n \n // releaseHydrogen() outputs \"H\". Do not change or remove this line.\n releaseHydrogen();\n }\n\n void oxygen(function releaseOxygen) {\n \n // releaseOxygen() outputs \"O\". Do not change or remove this line.\n releaseOxygen();\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class H2O {\n\n public H2O() {\n \n }\n\n public void hydrogen(Runnable releaseHydrogen) throws InterruptedException {\n\t\t\n // releaseHydrogen.run() outputs \"H\". Do not change or remove this line.\n releaseHydrogen.run();\n }\n\n public void oxygen(Runnable releaseOxygen) throws InterruptedException {\n \n // releaseOxygen.run() outputs \"O\". Do not change or remove this line.\n\t\treleaseOxygen.run();\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class H2O(object):\n def __init__(self):\n pass\n\n\n def hydrogen(self, releaseHydrogen):\n \"\"\"\n :type releaseHydrogen: method\n :rtype: void\n \"\"\"\n \n # releaseHydrogen() outputs \"H\". Do not change or remove this line.\n releaseHydrogen()\n\n\n def oxygen(self, releaseOxygen):\n \"\"\"\n :type releaseOxygen: method\n :rtype: void\n \"\"\"\n \n # releaseOxygen() outputs \"O\". Do not change or remove this line.\n releaseOxygen()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class H2O:\n def __init__(self):\n pass\n\n\n def hydrogen(self, releaseHydrogen: 'Callable[[], None]') -> None:\n \n # releaseHydrogen() outputs \"H\". Do not change or remove this line.\n releaseHydrogen()\n\n\n def oxygen(self, releaseOxygen: 'Callable[[], None]') -> None:\n \n # releaseOxygen() outputs \"O\". Do not change or remove this line.\n releaseOxygen()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "typedef struct {\n // User defined data may be declared here.\n \n} H2O;\n\nH2O* h2oCreate() {\n H2O* obj = (H2O*) malloc(sizeof(H2O));\n \n // Initialize user defined data here.\n \n return obj;\n}\n\nvoid hydrogen(H2O* obj) {\n \n // releaseHydrogen() outputs \"H\". Do not change or remove this line.\n releaseHydrogen();\n}\n\nvoid oxygen(H2O* obj) {\n \n // releaseOxygen() outputs \"O\". Do not change or remove this line.\n releaseOxygen();\n}\n\nvoid h2oFree(H2O* obj) {\n // User defined data may be cleaned up here.\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class H2O {\n\n public H2O() {\n \n }\n\n public void Hydrogen(Action releaseHydrogen) {\n\t\t\n // releaseHydrogen() outputs \"H\". Do not change or remove this line.\n releaseHydrogen();\n }\n\n public void Oxygen(Action releaseOxygen) {\n \n // releaseOxygen() outputs \"O\". Do not change or remove this line.\n\t\treleaseOxygen();\n }\n}", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1117](https://leetcode-cn.com/problems/building-h2o)", "[H2O \u751f\u6210](/solution/1100-1199/1117.Building%20H2O/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1117](https://leetcode.com/problems/building-h2o)", "[Building H2O](/solution/1100-1199/1117.Building%20H2O/README_EN.md)", "", "Medium", ""]}, {"question_id": "1185", "frontend_question_id": "1095", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-in-mountain-array", "url_en": "https://leetcode.com/problems/find-in-mountain-array", "relative_path_cn": "/solution/1000-1099/1095.Find%20in%20Mountain%20Array/README.md", "relative_path_en": "/solution/1000-1099/1095.Find%20in%20Mountain%20Array/README_EN.md", "title_cn": "\u5c71\u8109\u6570\u7ec4\u4e2d\u67e5\u627e\u76ee\u6807\u503c", "title_en": "Find in Mountain Array", "question_title_slug": "find-in-mountain-array", "content_en": "

(This problem is an interactive problem.)

\n\n

You may recall that an array A is a mountain array if and only if:

\n\n
    \n\t
  • A.length >= 3
  • \n\t
  • There exists some i with 0 < i < A.length - 1 such that:\n\t
      \n\t\t
    • A[0] < A[1] < ... A[i-1] < A[i]
    • \n\t\t
    • A[i] > A[i+1] > ... > A[A.length - 1]
    • \n\t
    \n\t
  • \n
\n\n

Given a mountain array mountainArr, return the minimum index such that mountainArr.get(index) == target.  If such an index doesn't exist, return -1.

\n\n

You can't access the mountain array directly.  You may only access the array using a MountainArray interface:

\n\n
    \n\t
  • MountainArray.get(k) returns the element of the array at index k (0-indexed).
  • \n\t
  • MountainArray.length() returns the length of the array.
  • \n
\n\n

Submissions making more than 100 calls to MountainArray.get will be judged Wrong Answer.  Also, any solutions that attempt to circumvent the judge will result in disqualification.

\n\n
    \n
\n\n

 

\n

Example 1:

\n\n
\nInput: array = [1,2,3,4,5,3,1], target = 3\nOutput: 2\nExplanation: 3 exists in the array, at index=2 and index=5. Return the minimum index, which is 2.
\n\n

Example 2:

\n\n
\nInput: array = [0,1,2,4,2,1], target = 3\nOutput: -1\nExplanation: 3 does not exist in the array, so we return -1.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 3 <= mountain_arr.length() <= 10000
  • \n\t
  • 0 <= target <= 10^9
  • \n\t
  • 0 <= mountain_arr.get(index) <= 10^9
  • \n
\n", "content_cn": "

\uff08\u8fd9\u662f\u4e00\u4e2a \u4ea4\u4e92\u5f0f\u95ee\u9898 \uff09

\n\n

\u7ed9\u4f60\u4e00\u4e2a \u5c71\u8109\u6570\u7ec4 mountainArr\uff0c\u8bf7\u4f60\u8fd4\u56de\u80fd\u591f\u4f7f\u5f97 mountainArr.get(index) \u7b49\u4e8e target \u6700\u5c0f \u7684\u4e0b\u6807 index \u503c\u3002

\n\n

\u5982\u679c\u4e0d\u5b58\u5728\u8fd9\u6837\u7684\u4e0b\u6807 index\uff0c\u5c31\u8bf7\u8fd4\u56de -1\u3002

\n\n

 

\n\n

\u4f55\u4e3a\u5c71\u8109\u6570\u7ec4\uff1f\u5982\u679c\u6570\u7ec4 A \u662f\u4e00\u4e2a\u5c71\u8109\u6570\u7ec4\u7684\u8bdd\uff0c\u90a3\u5b83\u6ee1\u8db3\u5982\u4e0b\u6761\u4ef6\uff1a

\n\n

\u9996\u5148\uff0cA.length >= 3

\n\n

\u5176\u6b21\uff0c\u5728 0 < i < A.length - 1 \u6761\u4ef6\u4e0b\uff0c\u5b58\u5728 i \u4f7f\u5f97\uff1a

\n\n
    \n\t
  • A[0] < A[1] < ... A[i-1] < A[i]
  • \n\t
  • A[i] > A[i+1] > ... > A[A.length - 1]
  • \n
\n\n

 

\n\n

\u4f60\u5c06 \u4e0d\u80fd\u76f4\u63a5\u8bbf\u95ee\u8be5\u5c71\u8109\u6570\u7ec4\uff0c\u5fc5\u987b\u901a\u8fc7 MountainArray \u63a5\u53e3\u6765\u83b7\u53d6\u6570\u636e\uff1a

\n\n
    \n\t
  • MountainArray.get(k) - \u4f1a\u8fd4\u56de\u6570\u7ec4\u4e2d\u7d22\u5f15\u4e3ak \u7684\u5143\u7d20\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09
  • \n\t
  • MountainArray.length() - \u4f1a\u8fd4\u56de\u8be5\u6570\u7ec4\u7684\u957f\u5ea6
  • \n
\n\n

 

\n\n

\u6ce8\u610f\uff1a

\n\n

\u5bf9 MountainArray.get \u53d1\u8d77\u8d85\u8fc7 100 \u6b21\u8c03\u7528\u7684\u63d0\u4ea4\u5c06\u88ab\u89c6\u4e3a\u9519\u8bef\u7b54\u6848\u3002\u6b64\u5916\uff0c\u4efb\u4f55\u8bd5\u56fe\u89c4\u907f\u5224\u9898\u7cfb\u7edf\u7684\u89e3\u51b3\u65b9\u6848\u90fd\u5c06\u4f1a\u5bfc\u81f4\u6bd4\u8d5b\u8d44\u683c\u88ab\u53d6\u6d88\u3002

\n\n

\u4e3a\u4e86\u5e2e\u52a9\u5927\u5bb6\u66f4\u597d\u5730\u7406\u89e3\u4ea4\u4e92\u5f0f\u95ee\u9898\uff0c\u6211\u4eec\u51c6\u5907\u4e86\u4e00\u4e2a\u6837\u4f8b “\u7b54\u6848”\uff1ahttps://leetcode-cn.com/playground/RKhe3ave\uff0c\u8bf7\u6ce8\u610f\u8fd9 \u4e0d\u662f\u4e00\u4e2a\u6b63\u786e\u7b54\u6848\u3002

\n\n
    \n
\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aarray = [1,2,3,4,5,3,1], target = 3\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a3 \u5728\u6570\u7ec4\u4e2d\u51fa\u73b0\u4e86\u4e24\u6b21\uff0c\u4e0b\u6807\u5206\u522b\u4e3a 2 \u548c 5\uff0c\u6211\u4eec\u8fd4\u56de\u6700\u5c0f\u7684\u4e0b\u6807 2\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aarray = [0,1,2,4,2,1], target = 3\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a3 \u5728\u6570\u7ec4\u4e2d\u6ca1\u6709\u51fa\u73b0\uff0c\u8fd4\u56de -1\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 3 <= mountain_arr.length() <= 10000
  • \n\t
  • 0 <= target <= 10^9
  • \n\t
  • 0 <= mountain_arr.get(index) <= 10^9
  • \n
\n", "tags_en": ["Binary Search"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * // This is the MountainArray's API interface.\n * // You should not implement it, or speculate about its implementation\n * class MountainArray {\n * public:\n * int get(int index);\n * int length();\n * };\n */\n\nclass Solution {\npublic:\n int findInMountainArray(int target, MountainArray &mountainArr) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * // This is MountainArray's API interface.\n * // You should not implement it, or speculate about its implementation\n * interface MountainArray {\n * public int get(int index) {}\n * public int length() {}\n * }\n */\n \nclass Solution {\n public int findInMountainArray(int target, MountainArray mountainArr) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# \"\"\"\n# This is MountainArray's API interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class MountainArray(object):\n# def get(self, index):\n# \"\"\"\n# :type index: int\n# :rtype int\n# \"\"\"\n#\n# def length(self):\n# \"\"\"\n# :rtype int\n# \"\"\"\n\nclass Solution(object):\n def findInMountainArray(self, target, mountain_arr):\n \"\"\"\n :type target: integer\n :type mountain_arr: MountainArray\n :rtype: integer\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# \"\"\"\n# This is MountainArray's API interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class MountainArray:\n# def get(self, index: int) -> int:\n# def length(self) -> int:\n\nclass Solution:\n def findInMountainArray(self, target: int, mountain_arr: 'MountainArray') -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * *********************************************************************\n * // This is the MountainArray's API interface.\n * // You should not implement it, or speculate about its implementation\n * *********************************************************************\n *\n * int get(MountainArray *, int index);\n * int length(MountainArray *);\n */\n\nint findInMountainArray(int target, MountainArray* mountainArr) {\n\t\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * // This is MountainArray's API interface.\n * // You should not implement it, or speculate about its implementation\n * class MountainArray {\n * public int Get(int index) {}\n * public int Length() {}\n * }\n */\n\nclass Solution {\n public int FindInMountainArray(int target, MountainArray mountainArr) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // This is the MountainArray's API interface.\n * // You should not implement it, or speculate about its implementation\n * function MountainArray() {\n * @param {number} index\n * @return {number}\n * this.get = function(index) {\n * ...\n * };\n *\n * @return {number}\n * this.length = function() {\n * ...\n * };\n * };\n */\n\n/**\n * @param {number} target\n * @param {MountainArray} mountainArr\n * @return {number}\n */\nvar findInMountainArray = function(target, mountainArr) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# This is MountainArray's API interface.\n# You should not implement it, or speculate about its implementation\n# class MountainArray\n# def get(index):\n# \n# end\n#\n# def length()\n#\t\t\n#\t end\n# end\n\n# @param {int} int\n# @param {MountainArray} mountain_arr\n# @return {int}\ndef findInMountainArray(target, mountain_arr)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * // This is MountainArray's API interface.\n * // You should not implement it, or speculate about its implementation\n * interface MountainArray {\n * public func get(_ index: Int) -> Int {}\n * public func length() -> Int {}\n * }\n */\n\nclass Solution {\n func findInMountainArray(_ target: Int, _ mountainArr: MountainArray) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * // This is the MountainArray's API interface.\n * // You should not implement it, or speculate about its implementation\n * type MountainArray struct {\n * }\n *\n * func (this *MountainArray) get(index int) int {}\n * func (this *MountainArray) length() int {}\n */\n\nfunc findInMountainArray(target int, mountainArr *MountainArray) int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * // This is MountainArray's API interface.\n * // You should not implement it, or speculate about its implementation\n * class MountainArray {\n * def get(index: Int): Int = {}\n * def length(): Int = {}\n * }\n */\n\nobject Solution {\n def findInMountainArray(value: Int, mountainArr: MountainArray): Int = {\n \n\t}\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * // This is MountainArray's API interface.\n * // You should not implement it, or speculate about its implementation\n * class MountainArray {\n * fun get(index: Int): Int {}\n * fun length(): Int {}\n * }\n */\n\nclass Solution {\n fun findInMountainArray(target: Int, mountainArr: MountainArray): Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "/**\n * // This is the MountainArray's API interface.\n * // You should not implement it, or speculate about its implementation\n * struct MountainArray;\n * impl MountainArray {\n * fn get(index:i32)->i32;\n * fn length()->i32;\n * };\n */\n\nimpl Solution {\n pub fn find_in_mountain_array(target: i32, mountainArr: &MountainArray) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * // This is MountainArray's API interface.\n * // You should not implement it, or speculate about its implementation\n * class MountainArray {\n * function get($index) {}\n * function length() {}\n * }\n */\n\nclass Solution {\n /**\n * @param Integer $target\n * @param MountainArray $mountainArr\n * @return Integer\n */\n function findInMountainArray($target, $mountainArr) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * // This is the MountainArray's API interface.\n * // You should not implement it, or speculate about its implementation\n * class Master {\n * get(index: number): number {}\n *\n * length(): number {}\n * }\n */\n\nfunction findInMountainArray(target: number, mountainArr: MountainArray) {\n\t\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1095](https://leetcode-cn.com/problems/find-in-mountain-array)", "[\u5c71\u8109\u6570\u7ec4\u4e2d\u67e5\u627e\u76ee\u6807\u503c](/solution/1000-1099/1095.Find%20in%20Mountain%20Array/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u56f0\u96be", ""], "md_table_row_en": ["[1095](https://leetcode.com/problems/find-in-mountain-array)", "[Find in Mountain Array](/solution/1000-1099/1095.Find%20in%20Mountain%20Array/README_EN.md)", "`Binary Search`", "Hard", ""]}, {"question_id": "1184", "frontend_question_id": "1094", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/car-pooling", "url_en": "https://leetcode.com/problems/car-pooling", "relative_path_cn": "/solution/1000-1099/1094.Car%20Pooling/README.md", "relative_path_en": "/solution/1000-1099/1094.Car%20Pooling/README_EN.md", "title_cn": "\u62fc\u8f66", "title_en": "Car Pooling", "question_title_slug": "car-pooling", "content_en": "

You are driving a vehicle that has capacity empty seats initially available for passengers.  The vehicle only drives east (ie. it cannot turn around and drive west.)

\n\n

Given a list of trips, trip[i] = [num_passengers, start_location, end_location] contains information about the i-th trip: the number of passengers that must be picked up, and the locations to pick them up and drop them off.  The locations are given as the number of kilometers due east from your vehicle's initial location.

\n\n

Return true if and only if it is possible to pick up and drop off all passengers for all the given trips. 

\n\n

 

\n\n

Example 1:

\n\n
\nInput: trips = [[2,1,5],[3,3,7]], capacity = 4\nOutput: false\n
\n\n
\n

Example 2:

\n\n
\nInput: trips = [[2,1,5],[3,3,7]], capacity = 5\nOutput: true\n
\n\n
\n

Example 3:

\n\n
\nInput: trips = [[2,1,5],[3,5,7]], capacity = 3\nOutput: true\n
\n\n
\n

Example 4:

\n\n
\nInput: trips = [[3,2,7],[3,7,9],[8,3,9]], capacity = 11\nOutput: true\n
\n
\n
\n
\n\n
\n
\n
\n
 
\n
\n
\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  1. trips.length <= 1000
  2. \n\t
  3. trips[i].length == 3
  4. \n\t
  5. 1 <= trips[i][0] <= 100
  6. \n\t
  7. 0 <= trips[i][1] < trips[i][2] <= 1000
  8. \n\t
  9. 1 <= capacity <= 100000
  10. \n
\n", "content_cn": "

\u5047\u8bbe\u4f60\u662f\u4e00\u4f4d\u987a\u98ce\u8f66\u53f8\u673a\uff0c\u8f66\u4e0a\u6700\u521d\u6709 capacity \u4e2a\u7a7a\u5ea7\u4f4d\u53ef\u4ee5\u7528\u6765\u8f7d\u5ba2\u3002\u7531\u4e8e\u9053\u8def\u7684\u9650\u5236\uff0c\u8f66 \u53ea\u80fd \u5411\u4e00\u4e2a\u65b9\u5411\u884c\u9a76\uff08\u4e5f\u5c31\u662f\u8bf4\uff0c\u4e0d\u5141\u8bb8\u6389\u5934\u6216\u6539\u53d8\u65b9\u5411\uff0c\u4f60\u53ef\u4ee5\u5c06\u5176\u60f3\u8c61\u4e3a\u4e00\u4e2a\u5411\u91cf\uff09\u3002

\n\n

\u8fd9\u513f\u6709\u4e00\u4efd\u4e58\u5ba2\u884c\u7a0b\u8ba1\u5212\u8868 trips[][]\uff0c\u5176\u4e2d trips[i] = [num_passengers, start_location, end_location] \u5305\u542b\u4e86\u7b2c i \u7ec4\u4e58\u5ba2\u7684\u884c\u7a0b\u4fe1\u606f\uff1a

\n\n
    \n\t
  • \u5fc5\u987b\u63a5\u9001\u7684\u4e58\u5ba2\u6570\u91cf\uff1b
  • \n\t
  • \u4e58\u5ba2\u7684\u4e0a\u8f66\u5730\u70b9\uff1b
  • \n\t
  • \u4ee5\u53ca\u4e58\u5ba2\u7684\u4e0b\u8f66\u5730\u70b9\u3002
  • \n
\n\n

\u8fd9\u4e9b\u7ed9\u51fa\u7684\u5730\u70b9\u4f4d\u7f6e\u662f\u4ece\u4f60\u7684 \u521d\u59cb \u51fa\u53d1\u4f4d\u7f6e\u5411\u524d\u884c\u9a76\u5230\u8fd9\u4e9b\u5730\u70b9\u6240\u9700\u7684\u8ddd\u79bb\uff08\u5b83\u4eec\u4e00\u5b9a\u5728\u4f60\u7684\u884c\u9a76\u65b9\u5411\u4e0a\uff09\u3002

\n\n

\u8bf7\u4f60\u6839\u636e\u7ed9\u51fa\u7684\u884c\u7a0b\u8ba1\u5212\u8868\u548c\u8f66\u5b50\u7684\u5ea7\u4f4d\u6570\uff0c\u6765\u5224\u65ad\u4f60\u7684\u8f66\u662f\u5426\u53ef\u4ee5\u987a\u5229\u5b8c\u6210\u63a5\u9001\u6240\u6709\u4e58\u5ba2\u7684\u4efb\u52a1\uff08\u5f53\u4e14\u4ec5\u5f53\u4f60\u53ef\u4ee5\u5728\u6240\u6709\u7ed9\u5b9a\u7684\u884c\u7a0b\u4e2d\u63a5\u9001\u6240\u6709\u4e58\u5ba2\u65f6\uff0c\u8fd4\u56de true\uff0c\u5426\u5219\u8bf7\u8fd4\u56de false\uff09\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1atrips = [[2,1,5],[3,3,7]], capacity = 4\n\u8f93\u51fa\uff1afalse\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1atrips = [[2,1,5],[3,3,7]], capacity = 5\n\u8f93\u51fa\uff1atrue\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1atrips = [[2,1,5],[3,5,7]], capacity = 3\n\u8f93\u51fa\uff1atrue\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1atrips = [[3,2,7],[3,7,9],[8,3,9]], capacity = 11\n\u8f93\u51fa\uff1atrue\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u4f60\u53ef\u4ee5\u5047\u8bbe\u4e58\u5ba2\u4f1a\u81ea\u89c9\u9075\u5b88 “\u5148\u4e0b\u540e\u4e0a” \u7684\u826f\u597d\u7d20\u8d28
  • \n\t
  • trips.length <= 1000
  • \n\t
  • trips[i].length == 3
  • \n\t
  • 1 <= trips[i][0] <= 100
  • \n\t
  • 0 <= trips[i][1] < trips[i][2] <= 1000
  • \n\t
  • 1 <= capacity <= 100000
  • \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool carPooling(vector>& trips, int capacity) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean carPooling(int[][] trips, int capacity) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def carPooling(self, trips, capacity):\n \"\"\"\n :type trips: List[List[int]]\n :type capacity: int\n :rtype: bool\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def carPooling(self, trips: List[List[int]], capacity: int) -> bool:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool carPooling(int** trips, int tripsSize, int* tripsColSize, int capacity){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CarPooling(int[][] trips, int capacity) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} trips\n * @param {number} capacity\n * @return {boolean}\n */\nvar carPooling = function(trips, capacity) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} trips\n# @param {Integer} capacity\n# @return {Boolean}\ndef car_pooling(trips, capacity)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func carPooling(_ trips: [[Int]], _ capacity: Int) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func carPooling(trips [][]int, capacity int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def carPooling(trips: Array[Array[Int]], capacity: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun carPooling(trips: Array, capacity: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn car_pooling(trips: Vec>, capacity: i32) -> bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $trips\n * @param Integer $capacity\n * @return Boolean\n */\n function carPooling($trips, $capacity) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function carPooling(trips: number[][], capacity: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (car-pooling trips capacity)\n (-> (listof (listof exact-integer?)) exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1094](https://leetcode-cn.com/problems/car-pooling)", "[\u62fc\u8f66](/solution/1000-1099/1094.Car%20Pooling/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1094](https://leetcode.com/problems/car-pooling)", "[Car Pooling](/solution/1000-1099/1094.Car%20Pooling/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1183", "frontend_question_id": "1093", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/statistics-from-a-large-sample", "url_en": "https://leetcode.com/problems/statistics-from-a-large-sample", "relative_path_cn": "/solution/1000-1099/1093.Statistics%20from%20a%20Large%20Sample/README.md", "relative_path_en": "/solution/1000-1099/1093.Statistics%20from%20a%20Large%20Sample/README_EN.md", "title_cn": "\u5927\u6837\u672c\u7edf\u8ba1", "title_en": "Statistics from a Large Sample", "question_title_slug": "statistics-from-a-large-sample", "content_en": "

You are given a large sample of integers in the range [0, 255]. Since the sample is so large, it is represented by an array count where count[k] is the number of times that k appears in the sample.

\n\n

Calculate the following statistics:

\n\n
    \n\t
  • minimum: The minimum element in the sample.
  • \n\t
  • maximum: The maximum element in the sample.
  • \n\t
  • mean: The average of the sample, calculated as the total sum of all elements divided by the total number of elements.
  • \n\t
  • median:\n\t
      \n\t\t
    • If the sample has an odd number of elements, then the median is the middle element once the sample is sorted.
    • \n\t\t
    • If the sample has an even number of elements, then the median is the average of the two middle elements once the sample is sorted.
    • \n\t
    \n\t
  • \n\t
  • mode: The number that appears the most in the sample. It is guaranteed to be unique.
  • \n
\n\n

Return the statistics of the sample as an array of floating-point numbers [minimum, maximum, mean, median, mode]. Answers within 10-5 of the actual answer will be accepted.

\n\n

 

\n

Example 1:

\n\n
\nInput: count = [0,1,3,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]\nOutput: [1.00000,3.00000,2.37500,2.50000,3.00000]\nExplanation: The sample represented by count is [1,2,2,2,3,3,3,3].\nThe minimum and maximum are 1 and 3 respectively.\nThe mean is (1+2+2+2+3+3+3+3) / 8 = 19 / 8 = 2.375.\nSince the size of the sample is even, the median is the average of the two middle elements 2 and 3, which is 2.5.\nThe mode is 3 as it appears the most in the sample.\n
\n\n

Example 2:

\n\n
\nInput: count = [0,4,3,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]\nOutput: [1.00000,4.00000,2.18182,2.00000,1.00000]\nExplanation: The sample represented by count is [1,1,1,1,2,2,2,3,3,4,4].\nThe minimum and maximum are 1 and 4 respectively.\nThe mean is (1+1+1+1+2+2+2+3+3+4+4) / 11 = 24 / 11 = 2.18181818... (for display purposes, the output shows the rounded number 2.18182).\nSince the size of the sample is odd, the median is the middle element 2.\nThe mode is 1 as it appears the most in the sample.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • count.length == 256
  • \n\t
  • 0 <= count[i] <= 109
  • \n\t
  • 1 <= sum(count) <= 109
  • \n\t
  • The mode of the sample that count represents is unique.
  • \n
\n", "content_cn": "

\u6211\u4eec\u5bf9 0 \u5230 255 \u4e4b\u95f4\u7684\u6574\u6570\u8fdb\u884c\u91c7\u6837\uff0c\u5e76\u5c06\u7ed3\u679c\u5b58\u50a8\u5728\u6570\u7ec4 count \u4e2d\uff1acount[k] \u5c31\u662f\u6574\u6570 k \u7684\u91c7\u6837\u4e2a\u6570\u3002

\n\n

\u6211\u4eec\u4ee5 \u6d6e\u70b9\u6570 \u6570\u7ec4\u7684\u5f62\u5f0f\uff0c\u5206\u522b\u8fd4\u56de\u6837\u672c\u7684\u6700\u5c0f\u503c\u3001\u6700\u5927\u503c\u3001\u5e73\u5747\u503c\u3001\u4e2d\u4f4d\u6570\u548c\u4f17\u6570\u3002\u5176\u4e2d\uff0c\u4f17\u6570\u662f\u4fdd\u8bc1\u552f\u4e00\u7684\u3002

\n\n

\u6211\u4eec\u5148\u6765\u56de\u987e\u4e00\u4e0b\u4e2d\u4f4d\u6570\u7684\u77e5\u8bc6\uff1a

\n\n
    \n\t
  • \u5982\u679c\u6837\u672c\u4e2d\u7684\u5143\u7d20\u6709\u5e8f\uff0c\u5e76\u4e14\u5143\u7d20\u6570\u91cf\u4e3a\u5947\u6570\u65f6\uff0c\u4e2d\u4f4d\u6570\u4e3a\u6700\u4e2d\u95f4\u7684\u90a3\u4e2a\u5143\u7d20\uff1b
  • \n\t
  • \u5982\u679c\u6837\u672c\u4e2d\u7684\u5143\u7d20\u6709\u5e8f\uff0c\u5e76\u4e14\u5143\u7d20\u6570\u91cf\u4e3a\u5076\u6570\u65f6\uff0c\u4e2d\u4f4d\u6570\u4e3a\u4e2d\u95f4\u7684\u4e24\u4e2a\u5143\u7d20\u7684\u5e73\u5747\u503c\u3002
  • \n
\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1acount = [0,1,3,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]\n\u8f93\u51fa\uff1a[1.00000,3.00000,2.37500,2.50000,3.00000]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1acount = [0,4,3,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]\n\u8f93\u51fa\uff1a[1.00000,4.00000,2.18182,2.00000,1.00000]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. count.length == 256
  2. \n\t
  3. 1 <= sum(count) <= 10^9
  4. \n\t
  5. \u8ba1\u6570\u8868\u793a\u7684\u4f17\u6570\u662f\u552f\u4e00\u7684
  6. \n\t
  7. \u7b54\u6848\u4e0e\u771f\u5b9e\u503c\u8bef\u5dee\u5728 10^-5 \u4ee5\u5185\u5c31\u4f1a\u88ab\u89c6\u4e3a\u6b63\u786e\u7b54\u6848
  8. \n
\n", "tags_en": ["Math", "Two Pointers"], "tags_cn": ["\u6570\u5b66", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector sampleStats(vector& count) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double[] sampleStats(int[] count) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def sampleStats(self, count):\n \"\"\"\n :type count: List[int]\n :rtype: List[float]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def sampleStats(self, count: List[int]) -> List[float]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\ndouble* sampleStats(int* count, int countSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double[] SampleStats(int[] count) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} count\n * @return {number[]}\n */\nvar sampleStats = function(count) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} count\n# @return {Float[]}\ndef sample_stats(count)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func sampleStats(_ count: [Int]) -> [Double] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func sampleStats(count []int) []float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def sampleStats(count: Array[Int]): Array[Double] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun sampleStats(count: IntArray): DoubleArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sample_stats(count: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $count\n * @return Float[]\n */\n function sampleStats($count) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function sampleStats(count: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (sample-stats count)\n (-> (listof exact-integer?) (listof flonum?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1093](https://leetcode-cn.com/problems/statistics-from-a-large-sample)", "[\u5927\u6837\u672c\u7edf\u8ba1](/solution/1000-1099/1093.Statistics%20from%20a%20Large%20Sample/README.md)", "`\u6570\u5b66`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1093](https://leetcode.com/problems/statistics-from-a-large-sample)", "[Statistics from a Large Sample](/solution/1000-1099/1093.Statistics%20from%20a%20Large%20Sample/README_EN.md)", "`Math`,`Two Pointers`", "Medium", ""]}, {"question_id": "1182", "frontend_question_id": "0550", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/game-play-analysis-iv", "url_en": "https://leetcode.com/problems/game-play-analysis-iv", "relative_path_cn": "/solution/0500-0599/0550.Game%20Play%20Analysis%20IV/README.md", "relative_path_en": "/solution/0500-0599/0550.Game%20Play%20Analysis%20IV/README_EN.md", "title_cn": "\u6e38\u620f\u73a9\u6cd5\u5206\u6790 IV", "title_en": "Game Play Analysis IV", "question_title_slug": "game-play-analysis-iv", "content_en": "

Table: Activity

\n\n
\n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| player_id    | int     |\n| device_id    | int     |\n| event_date   | date    |\n| games_played | int     |\n+--------------+---------+\n(player_id, event_date) is the primary key of this table.\nThis table shows the activity of players of some game.\nEach row is a record of a player who logged in and played a number of games (possibly 0) before logging out on some day using some device.\n
\n\n

 

\n\n

Write an SQL query that reports the fraction of players that logged in again on the day after the day they first logged in, rounded to 2 decimal places. In other words, you need to count the number of players that logged in for at least two consecutive days starting from their first login date, then divide that number by the total number of players.

\n\n

The query result format is in the following example:

\n\n
\nActivity table:\n+-----------+-----------+------------+--------------+\n| player_id | device_id | event_date | games_played |\n+-----------+-----------+------------+--------------+\n| 1         | 2         | 2016-03-01 | 5            |\n| 1         | 2         | 2016-03-02 | 6            |\n| 2         | 3         | 2017-06-25 | 1            |\n| 3         | 1         | 2016-03-02 | 0            |\n| 3         | 4         | 2018-07-03 | 5            |\n+-----------+-----------+------------+--------------+\n\nResult table:\n+-----------+\n| fraction  |\n+-----------+\n| 0.33      |\n+-----------+\nOnly the player with id 1 logged back in after the first day he had logged in so the answer is 1/3 = 0.33\n
\n", "content_cn": "

Table: Activity

\n\n
+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| player_id    | int     |\n| device_id    | int     |\n| event_date   | date    |\n| games_played | int     |\n+--------------+---------+\n\uff08player_id\uff0cevent_date\uff09\u662f\u6b64\u8868\u7684\u4e3b\u952e\u3002\n\u8fd9\u5f20\u8868\u663e\u793a\u4e86\u67d0\u4e9b\u6e38\u620f\u7684\u73a9\u5bb6\u7684\u6d3b\u52a8\u60c5\u51b5\u3002\n\u6bcf\u4e00\u884c\u662f\u4e00\u4e2a\u73a9\u5bb6\u7684\u8bb0\u5f55\uff0c\u4ed6\u5728\u67d0\u4e00\u5929\u4f7f\u7528\u67d0\u4e2a\u8bbe\u5907\u6ce8\u9500\u4e4b\u524d\u767b\u5f55\u5e76\u73a9\u4e86\u5f88\u591a\u6e38\u620f\uff08\u53ef\u80fd\u662f 0\uff09\u3002\n
\n\n

 

\n\n

\u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\uff0c\u62a5\u544a\u5728\u9996\u6b21\u767b\u5f55\u7684\u7b2c\u4e8c\u5929\u518d\u6b21\u767b\u5f55\u7684\u73a9\u5bb6\u7684\u6bd4\u7387\uff0c\u56db\u820d\u4e94\u5165\u5230\u5c0f\u6570\u70b9\u540e\u4e24\u4f4d\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u60a8\u9700\u8981\u8ba1\u7b97\u4ece\u9996\u6b21\u767b\u5f55\u65e5\u671f\u5f00\u59cb\u81f3\u5c11\u8fde\u7eed\u4e24\u5929\u767b\u5f55\u7684\u73a9\u5bb6\u7684\u6570\u91cf\uff0c\u7136\u540e\u9664\u4ee5\u73a9\u5bb6\u603b\u6570\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u6240\u793a\uff1a

\n\n
Activity table:\n+-----------+-----------+------------+--------------+\n| player_id | device_id | event_date | games_played |\n+-----------+-----------+------------+--------------+\n| 1         | 2         | 2016-03-01 | 5            |\n| 1         | 2         | 2016-03-02 | 6            |\n| 2         | 3         | 2017-06-25 | 1            |\n| 3         | 1         | 2016-03-02 | 0            |\n| 3         | 4         | 2018-07-03 | 5            |\n+-----------+-----------+------------+--------------+\n\nResult table:\n+-----------+\n| fraction  |\n+-----------+\n| 0.33      |\n+-----------+\n\u53ea\u6709 ID \u4e3a 1 \u7684\u73a9\u5bb6\u5728\u7b2c\u4e00\u5929\u767b\u5f55\u540e\u624d\u91cd\u65b0\u767b\u5f55\uff0c\u6240\u4ee5\u7b54\u6848\u662f 1/3 = 0.33\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0550](https://leetcode-cn.com/problems/game-play-analysis-iv)", "[\u6e38\u620f\u73a9\u6cd5\u5206\u6790 IV](/solution/0500-0599/0550.Game%20Play%20Analysis%20IV/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0550](https://leetcode.com/problems/game-play-analysis-iv)", "[Game Play Analysis IV](/solution/0500-0599/0550.Game%20Play%20Analysis%20IV/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1181", "frontend_question_id": "0534", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/game-play-analysis-iii", "url_en": "https://leetcode.com/problems/game-play-analysis-iii", "relative_path_cn": "/solution/0500-0599/0534.Game%20Play%20Analysis%20III/README.md", "relative_path_en": "/solution/0500-0599/0534.Game%20Play%20Analysis%20III/README_EN.md", "title_cn": "\u6e38\u620f\u73a9\u6cd5\u5206\u6790 III", "title_en": "Game Play Analysis III", "question_title_slug": "game-play-analysis-iii", "content_en": "

Table: Activity

\n\n
\n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| player_id    | int     |\n| device_id    | int     |\n| event_date   | date    |\n| games_played | int     |\n+--------------+---------+\n(player_id, event_date) is the primary key of this table.\nThis table shows the activity of players of some game.\nEach row is a record of a player who logged in and played a number of games (possibly 0) before logging out on some day using some device.\n
\n\n

 

\n\n

Write an SQL query that reports for each player and date, how many games played so far by the player. That is, the total number of games played by the player until that date. Check the example for clarity.

\n\n

The query result format is in the following example:

\n\n
\nActivity table:\n+-----------+-----------+------------+--------------+\n| player_id | device_id | event_date | games_played |\n+-----------+-----------+------------+--------------+\n| 1         | 2         | 2016-03-01 | 5            |\n| 1         | 2         | 2016-05-02 | 6            |\n| 1         | 3         | 2017-06-25 | 1            |\n| 3         | 1         | 2016-03-02 | 0            |\n| 3         | 4         | 2018-07-03 | 5            |\n+-----------+-----------+------------+--------------+\n\nResult table:\n+-----------+------------+---------------------+\n| player_id | event_date | games_played_so_far |\n+-----------+------------+---------------------+\n| 1         | 2016-03-01 | 5                   |\n| 1         | 2016-05-02 | 11                  |\n| 1         | 2017-06-25 | 12                  |\n| 3         | 2016-03-02 | 0                   |\n| 3         | 2018-07-03 | 5                   |\n+-----------+------------+---------------------+\nFor the player with id 1, 5 + 6 = 11 games played by 2016-05-02, and 5 + 6 + 1 = 12 games played by 2017-06-25.\nFor the player with id 3, 0 + 5 = 5 games played by 2018-07-03.\nNote that for each player we only care about the days when the player logged in.\n
\n", "content_cn": "

Table: Activity

\n\n
\n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| player_id    | int     |\n| device_id    | int     |\n| event_date   | date    |\n| games_played | int     |\n+--------------+---------+\n\uff08player_id\uff0cevent_date\uff09\u662f\u6b64\u8868\u7684\u4e3b\u952e\u3002\n\u8fd9\u5f20\u8868\u663e\u793a\u4e86\u67d0\u4e9b\u6e38\u620f\u7684\u73a9\u5bb6\u7684\u6d3b\u52a8\u60c5\u51b5\u3002\n\u6bcf\u4e00\u884c\u662f\u4e00\u4e2a\u73a9\u5bb6\u7684\u8bb0\u5f55\uff0c\u4ed6\u5728\u67d0\u4e00\u5929\u4f7f\u7528\u67d0\u4e2a\u8bbe\u5907\u6ce8\u9500\u4e4b\u524d\u767b\u5f55\u5e76\u73a9\u4e86\u5f88\u591a\u6e38\u620f\uff08\u53ef\u80fd\u662f 0 \uff09\u3002\n
\n\n

 

\n\n

\u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\uff0c\u540c\u65f6\u62a5\u544a\u6bcf\u7ec4\u73a9\u5bb6\u548c\u65e5\u671f\uff0c\u4ee5\u53ca\u73a9\u5bb6\u5230\u76ee\u524d\u4e3a\u6b62\u73a9\u4e86\u591a\u5c11\u6e38\u620f\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u5728\u6b64\u65e5\u671f\u4e4b\u524d\u73a9\u5bb6\u6240\u73a9\u7684\u6e38\u620f\u603b\u6570\u3002\u8be6\u7ec6\u60c5\u51b5\u8bf7\u67e5\u770b\u793a\u4f8b\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u6240\u793a\uff1a

\n\n
\nActivity table:\n+-----------+-----------+------------+--------------+\n| player_id | device_id | event_date | games_played |\n+-----------+-----------+------------+--------------+\n| 1         | 2         | 2016-03-01 | 5            |\n| 1         | 2         | 2016-05-02 | 6            |\n| 1         | 3         | 2017-06-25 | 1            |\n| 3         | 1         | 2016-03-02 | 0            |\n| 3         | 4         | 2018-07-03 | 5            |\n+-----------+-----------+------------+--------------+\n\nResult table:\n+-----------+------------+---------------------+\n| player_id | event_date | games_played_so_far |\n+-----------+------------+---------------------+\n| 1         | 2016-03-01 | 5                   |\n| 1         | 2016-05-02 | 11                  |\n| 1         | 2017-06-25 | 12                  |\n| 3         | 2016-03-02 | 0                   |\n| 3         | 2018-07-03 | 5                   |\n+-----------+------------+---------------------+\n\u5bf9\u4e8e ID \u4e3a 1 \u7684\u73a9\u5bb6\uff0c2016-05-02 \u5171\u73a9\u4e86 5+6=11 \u4e2a\u6e38\u620f\uff0c2017-06-25 \u5171\u73a9\u4e86 5+6+1=12 \u4e2a\u6e38\u620f\u3002\n\u5bf9\u4e8e ID \u4e3a 3 \u7684\u73a9\u5bb6\uff0c2018-07-03 \u5171\u73a9\u4e86 0+5=5 \u4e2a\u6e38\u620f\u3002\n\u8bf7\u6ce8\u610f\uff0c\u5bf9\u4e8e\u6bcf\u4e2a\u73a9\u5bb6\uff0c\u6211\u4eec\u53ea\u5173\u5fc3\u73a9\u5bb6\u7684\u767b\u5f55\u65e5\u671f\u3002\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0534](https://leetcode-cn.com/problems/game-play-analysis-iii)", "[\u6e38\u620f\u73a9\u6cd5\u5206\u6790 III](/solution/0500-0599/0534.Game%20Play%20Analysis%20III/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0534](https://leetcode.com/problems/game-play-analysis-iii)", "[Game Play Analysis III](/solution/0500-0599/0534.Game%20Play%20Analysis%20III/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1180", "frontend_question_id": "0512", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/game-play-analysis-ii", "url_en": "https://leetcode.com/problems/game-play-analysis-ii", "relative_path_cn": "/solution/0500-0599/0512.Game%20Play%20Analysis%20II/README.md", "relative_path_en": "/solution/0500-0599/0512.Game%20Play%20Analysis%20II/README_EN.md", "title_cn": "\u6e38\u620f\u73a9\u6cd5\u5206\u6790 II", "title_en": "Game Play Analysis II", "question_title_slug": "game-play-analysis-ii", "content_en": "

Table: Activity

\n\n
\n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| player_id    | int     |\n| device_id    | int     |\n| event_date   | date    |\n| games_played | int     |\n+--------------+---------+\n(player_id, event_date) is the primary key of this table.\nThis table shows the activity of players of some game.\nEach row is a record of a player who logged in and played a number of games (possibly 0) before logging out on some day using some device.\n
\n\n

 

\n\n

Write a SQL query that reports the device that is first logged in for each player.

\n\n

The query result format is in the following example:

\n\n
\nActivity table:\n+-----------+-----------+------------+--------------+\n| player_id | device_id | event_date | games_played |\n+-----------+-----------+------------+--------------+\n| 1         | 2         | 2016-03-01 | 5            |\n| 1         | 2         | 2016-05-02 | 6            |\n| 2         | 3         | 2017-06-25 | 1            |\n| 3         | 1         | 2016-03-02 | 0            |\n| 3         | 4         | 2018-07-03 | 5            |\n+-----------+-----------+------------+--------------+\n\nResult table:\n+-----------+-----------+\n| player_id | device_id |\n+-----------+-----------+\n| 1         | 2         |\n| 2         | 3         |\n| 3         | 1         |\n+-----------+-----------+
\n", "content_cn": "

Table: Activity

\n\n
\n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| player_id    | int     |\n| device_id    | int     |\n| event_date   | date    |\n| games_played | int     |\n+--------------+---------+\n(player_id, event_date) \u662f\u8fd9\u4e2a\u8868\u7684\u4e24\u4e2a\u4e3b\u952e\n\u8fd9\u4e2a\u8868\u663e\u793a\u7684\u662f\u67d0\u4e9b\u6e38\u620f\u73a9\u5bb6\u7684\u6e38\u620f\u6d3b\u52a8\u60c5\u51b5\n\u6bcf\u4e00\u884c\u662f\u5728\u67d0\u5929\u4f7f\u7528\u67d0\u4e2a\u8bbe\u5907\u767b\u51fa\u4e4b\u524d\u767b\u5f55\u5e76\u73a9\u591a\u4e2a\u6e38\u620f\uff08\u53ef\u80fd\u4e3a0\uff09\u7684\u73a9\u5bb6\u7684\u8bb0\u5f55\n
\n\n

\u8bf7\u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\uff0c\u63cf\u8ff0\u6bcf\u4e00\u4e2a\u73a9\u5bb6\u9996\u6b21\u767b\u9646\u7684\u8bbe\u5907\u540d\u79f0

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5728\u4ee5\u4e0b\u793a\u4f8b\u4e2d\uff1a

\n\n
\nActivity table:\n+-----------+-----------+------------+--------------+\n| player_id | device_id | event_date | games_played |\n+-----------+-----------+------------+--------------+\n| 1         | 2         | 2016-03-01 | 5            |\n| 1         | 2         | 2016-05-02 | 6            |\n| 2         | 3         | 2017-06-25 | 1            |\n| 3         | 1         | 2016-03-02 | 0            |\n| 3         | 4         | 2018-07-03 | 5            |\n+-----------+-----------+------------+--------------+\n\nResult table:\n+-----------+-----------+\n| player_id | device_id |\n+-----------+-----------+\n| 1         | 2         |\n| 2         | 3         |\n| 3         | 1         |\n+-----------+-----------+
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0512](https://leetcode-cn.com/problems/game-play-analysis-ii)", "[\u6e38\u620f\u73a9\u6cd5\u5206\u6790 II](/solution/0500-0599/0512.Game%20Play%20Analysis%20II/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0512](https://leetcode.com/problems/game-play-analysis-ii)", "[Game Play Analysis II](/solution/0500-0599/0512.Game%20Play%20Analysis%20II/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1179", "frontend_question_id": "0511", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/game-play-analysis-i", "url_en": "https://leetcode.com/problems/game-play-analysis-i", "relative_path_cn": "/solution/0500-0599/0511.Game%20Play%20Analysis%20I/README.md", "relative_path_en": "/solution/0500-0599/0511.Game%20Play%20Analysis%20I/README_EN.md", "title_cn": "\u6e38\u620f\u73a9\u6cd5\u5206\u6790 I", "title_en": "Game Play Analysis I", "question_title_slug": "game-play-analysis-i", "content_en": "

Table: Activity

\n\n
\n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| player_id    | int     |\n| device_id    | int     |\n| event_date   | date    |\n| games_played | int     |\n+--------------+---------+\n(player_id, event_date) is the primary key of this table.\nThis table shows the activity of players of some game.\nEach row is a record of a player who logged in and played a number of games (possibly 0) before logging out on some day using some device.\n
\n\n

 

\n\n

Write an SQL query that reports the first login date for each player.

\n\n

The query result format is in the following example:

\n\n
\nActivity table:\n+-----------+-----------+------------+--------------+\n| player_id | device_id | event_date | games_played |\n+-----------+-----------+------------+--------------+\n| 1         | 2         | 2016-03-01 | 5            |\n| 1         | 2         | 2016-05-02 | 6            |\n| 2         | 3         | 2017-06-25 | 1            |\n| 3         | 1         | 2016-03-02 | 0            |\n| 3         | 4         | 2018-07-03 | 5            |\n+-----------+-----------+------------+--------------+\n\nResult table:\n+-----------+-------------+\n| player_id | first_login |\n+-----------+-------------+\n| 1         | 2016-03-01  |\n| 2         | 2017-06-25  |\n| 3         | 2016-03-02  |\n+-----------+-------------+\n
\n", "content_cn": "

\u6d3b\u52a8\u8868 Activity\uff1a

\n\n
\n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| player_id    | int     |\n| device_id    | int     |\n| event_date   | date    |\n| games_played | int     |\n+--------------+---------+\n\u8868\u7684\u4e3b\u952e\u662f (player_id, event_date)\u3002\n\u8fd9\u5f20\u8868\u5c55\u793a\u4e86\u4e00\u4e9b\u6e38\u620f\u73a9\u5bb6\u5728\u6e38\u620f\u5e73\u53f0\u4e0a\u7684\u884c\u4e3a\u6d3b\u52a8\u3002\n\u6bcf\u884c\u6570\u636e\u8bb0\u5f55\u4e86\u4e00\u540d\u73a9\u5bb6\u5728\u9000\u51fa\u5e73\u53f0\u4e4b\u524d\uff0c\u5f53\u5929\u4f7f\u7528\u540c\u4e00\u53f0\u8bbe\u5907\u767b\u5f55\u5e73\u53f0\u540e\u6253\u5f00\u7684\u6e38\u620f\u7684\u6570\u76ee\uff08\u53ef\u80fd\u662f 0 \u4e2a\uff09\u3002\n
\n\n

 

\n\n

\u5199\u4e00\u6761 SQL \u67e5\u8be2\u8bed\u53e5\u83b7\u53d6\u6bcf\u4f4d\u73a9\u5bb6 \u7b2c\u4e00\u6b21\u767b\u9646\u5e73\u53f0\u7684\u65e5\u671f\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u7684\u683c\u5f0f\u5982\u4e0b\u6240\u793a\uff1a

\n\n
\nActivity \u8868\uff1a\n+-----------+-----------+------------+--------------+\n| player_id | device_id | event_date | games_played |\n+-----------+-----------+------------+--------------+\n| 1         | 2         | 2016-03-01 | 5            |\n| 1         | 2         | 2016-05-02 | 6            |\n| 2         | 3         | 2017-06-25 | 1            |\n| 3         | 1         | 2016-03-02 | 0            |\n| 3         | 4         | 2018-07-03 | 5            |\n+-----------+-----------+------------+--------------+\n\nResult \u8868\uff1a\n+-----------+-------------+\n| player_id | first_login |\n+-----------+-------------+\n| 1         | 2016-03-01  |\n| 2         | 2017-06-25  |\n| 3         | 2016-03-02  |\n+-----------+-------------+\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0511](https://leetcode-cn.com/problems/game-play-analysis-i)", "[\u6e38\u620f\u73a9\u6cd5\u5206\u6790 I](/solution/0500-0599/0511.Game%20Play%20Analysis%20I/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0511](https://leetcode.com/problems/game-play-analysis-i)", "[Game Play Analysis I](/solution/0500-0599/0511.Game%20Play%20Analysis%20I/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1178", "frontend_question_id": "1216", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/valid-palindrome-iii", "url_en": "https://leetcode.com/problems/valid-palindrome-iii", "relative_path_cn": "/solution/1200-1299/1216.Valid%20Palindrome%20III/README.md", "relative_path_en": "/solution/1200-1299/1216.Valid%20Palindrome%20III/README_EN.md", "title_cn": "\u9a8c\u8bc1\u56de\u6587\u5b57\u7b26\u4e32 III", "title_en": "Valid Palindrome III", "question_title_slug": "valid-palindrome-iii", "content_en": "

Given a string s and an integer k, return true if s is a k-palindrome.

\n\n

A string is k-palindrome if it can be transformed into a palindrome by removing at most k characters from it.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "abcdeca", k = 2\nOutput: true\nExplanation: Remove 'b' and 'e' characters.\n
\n\n

Example 2:

\n\n
\nInput: s = "abbababa", k = 1\nOutput: true\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 1000
  • \n\t
  • s consists of only lowercase English letters.
  • \n\t
  • 1 <= k <= s.length
  • \n
\n", "content_cn": "

\u7ed9\u51fa\u4e00\u4e2a\u5b57\u7b26\u4e32 s \u548c\u4e00\u4e2a\u6574\u6570 k\uff0c\u8bf7\u4f60\u5e2e\u5fd9\u5224\u65ad\u8fd9\u4e2a\u5b57\u7b26\u4e32\u662f\u4e0d\u662f\u4e00\u4e2a\u300cK \u56de\u6587\u300d\u3002

\n\n

\u6240\u8c13\u300cK \u56de\u6587\u300d\uff1a\u5982\u679c\u53ef\u4ee5\u901a\u8fc7\u4ece\u5b57\u7b26\u4e32\u4e2d\u5220\u53bb\u6700\u591a k \u4e2a\u5b57\u7b26\u5c06\u5176\u8f6c\u6362\u4e3a\u56de\u6587\uff0c\u90a3\u4e48\u8fd9\u4e2a\u5b57\u7b26\u4e32\u5c31\u662f\u4e00\u4e2a\u300cK \u56de\u6587\u300d\u3002

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1as = "abcdeca", k = 2\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u5220\u9664\u5b57\u7b26 “b” \u548c “e”\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length <= 1000
  • \n\t
  • s \u4e2d\u53ea\u542b\u6709\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd
  • \n\t
  • 1 <= k <= s.length
  • \n
\n", "tags_en": ["String", "Dynamic Programming"], "tags_cn": ["\u5b57\u7b26\u4e32", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isValidPalindrome(string s, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isValidPalindrome(String s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isValidPalindrome(self, s, k):\n \"\"\"\n :type s: str\n :type k: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isValidPalindrome(self, s: str, k: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isValidPalindrome(char * s, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsValidPalindrome(string s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number} k\n * @return {boolean}\n */\nvar isValidPalindrome = function(s, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer} k\n# @return {Boolean}\ndef is_valid_palindrome(s, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isValidPalindrome(_ s: String, _ k: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isValidPalindrome(s string, k int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isValidPalindrome(s: String, k: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isValidPalindrome(s: String, k: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_valid_palindrome(s: String, k: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer $k\n * @return Boolean\n */\n function isValidPalindrome($s, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isValidPalindrome(s: string, k: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-valid-palindrome s k)\n (-> string? exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1216](https://leetcode-cn.com/problems/valid-palindrome-iii)", "[\u9a8c\u8bc1\u56de\u6587\u5b57\u7b26\u4e32 III](/solution/1200-1299/1216.Valid%20Palindrome%20III/README.md)", "`\u5b57\u7b26\u4e32`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1216](https://leetcode.com/problems/valid-palindrome-iii)", "[Valid Palindrome III](/solution/1200-1299/1216.Valid%20Palindrome%20III/README_EN.md)", "`String`,`Dynamic Programming`", "Hard", "\ud83d\udd12"]}, {"question_id": "1177", "frontend_question_id": "1245", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/tree-diameter", "url_en": "https://leetcode.com/problems/tree-diameter", "relative_path_cn": "/solution/1200-1299/1245.Tree%20Diameter/README.md", "relative_path_en": "/solution/1200-1299/1245.Tree%20Diameter/README_EN.md", "title_cn": "\u6811\u7684\u76f4\u5f84", "title_en": "Tree Diameter", "question_title_slug": "tree-diameter", "content_en": "

Given an undirected tree, return its diameter: the number of edges in a longest path in that tree.

\n\n

The tree is given as an array of edges where edges[i] = [u, v] is a bidirectional edge between nodes u and v.  Each node has labels in the set {0, 1, ..., edges.length}.

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: edges = [[0,1],[0,2]]\nOutput: 2\nExplanation: \nA longest path of the tree is the path 1 - 0 - 2.\n
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: edges = [[0,1],[1,2],[2,3],[1,4],[4,5]]\nOutput: 4\nExplanation: \nA longest path of the tree is the path 3 - 2 - 1 - 4 - 5.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 0 <= edges.length < 10^4
  • \n\t
  • edges[i][0] != edges[i][1]
  • \n\t
  • 0 <= edges[i][j] <= edges.length
  • \n\t
  • The given edges form an undirected tree.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u8fd9\u68f5\u300c\u65e0\u5411\u6811\u300d\uff0c\u8bf7\u4f60\u6d4b\u7b97\u5e76\u8fd4\u56de\u5b83\u7684\u300c\u76f4\u5f84\u300d\uff1a\u8fd9\u68f5\u6811\u4e0a\u6700\u957f\u7b80\u5355\u8def\u5f84\u7684 \u8fb9\u6570\u3002

\n\n

\u6211\u4eec\u7528\u4e00\u4e2a\u7531\u6240\u6709\u300c\u8fb9\u300d\u7ec4\u6210\u7684\u6570\u7ec4 edges \u6765\u8868\u793a\u4e00\u68f5\u65e0\u5411\u6811\uff0c\u5176\u4e2d edges[i] = [u, v] \u8868\u793a\u8282\u70b9 u \u548c v \u4e4b\u95f4\u7684\u53cc\u5411\u8fb9\u3002

\n\n

\u6811\u4e0a\u7684\u8282\u70b9\u90fd\u5df2\u7ecf\u7528 {0, 1, ..., edges.length} \u4e2d\u7684\u6570\u505a\u4e86\u6807\u8bb0\uff0c\u6bcf\u4e2a\u8282\u70b9\u4e0a\u7684\u6807\u8bb0\u90fd\u662f\u72ec\u4e00\u65e0\u4e8c\u7684\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1aedges = [[0,1],[0,2]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n\u8fd9\u68f5\u6811\u4e0a\u6700\u957f\u7684\u8def\u5f84\u662f 1 - 0 - 2\uff0c\u8fb9\u6570\u4e3a 2\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1aedges = [[0,1],[1,2],[2,3],[1,4],[4,5]]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a \n\u8fd9\u68f5\u6811\u4e0a\u6700\u957f\u7684\u8def\u5f84\u662f 3 - 2 - 1 - 4 - 5\uff0c\u8fb9\u6570\u4e3a 4\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 0 <= edges.length < 10^4
  • \n\t
  • edges[i][0] != edges[i][1]
  • \n\t
  • 0 <= edges[i][j] <= edges.length
  • \n\t
  • edges \u4f1a\u5f62\u6210\u4e00\u68f5\u65e0\u5411\u6811
  • \n
\n", "tags_en": ["Tree", "Depth-first Search", "Breadth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int treeDiameter(vector>& edges) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int treeDiameter(int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def treeDiameter(self, edges):\n \"\"\"\n :type edges: List[List[int]]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def treeDiameter(self, edges: List[List[int]]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint treeDiameter(int** edges, int edgesSize, int* edgesColSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int TreeDiameter(int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} edges\n * @return {number}\n */\nvar treeDiameter = function(edges) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} edges\n# @return {Integer}\ndef tree_diameter(edges)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func treeDiameter(_ edges: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func treeDiameter(edges [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def treeDiameter(edges: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun treeDiameter(edges: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn tree_diameter(edges: Vec>) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $edges\n * @return Integer\n */\n function treeDiameter($edges) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function treeDiameter(edges: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (tree-diameter edges)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1245](https://leetcode-cn.com/problems/tree-diameter)", "[\u6811\u7684\u76f4\u5f84](/solution/1200-1299/1245.Tree%20Diameter/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1245](https://leetcode.com/problems/tree-diameter)", "[Tree Diameter](/solution/1200-1299/1245.Tree%20Diameter/README_EN.md)", "`Tree`,`Depth-first Search`,`Breadth-first Search`", "Medium", "\ud83d\udd12"]}, {"question_id": "1176", "frontend_question_id": "1244", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/design-a-leaderboard", "url_en": "https://leetcode.com/problems/design-a-leaderboard", "relative_path_cn": "/solution/1200-1299/1244.Design%20A%20Leaderboard/README.md", "relative_path_en": "/solution/1200-1299/1244.Design%20A%20Leaderboard/README_EN.md", "title_cn": "\u529b\u6263\u6392\u884c\u699c", "title_en": "Design A Leaderboard", "question_title_slug": "design-a-leaderboard", "content_en": "

Design a Leaderboard class, which has 3 functions:

\n\n
    \n\t
  1. addScore(playerId, score): Update the leaderboard by adding score to the given player's score. If there is no player with such id in the leaderboard, add him to the leaderboard with the given score.
  2. \n\t
  3. top(K): Return the score sum of the top K players.
  4. \n\t
  5. reset(playerId): Reset the score of the player with the given id to 0 (in other words erase it from the leaderboard). It is guaranteed that the player was added to the leaderboard before calling this function.
  6. \n
\n\n

Initially, the leaderboard is empty.

\n\n

 

\n

Example 1:

\n\n
\nInput: \n["Leaderboard","addScore","addScore","addScore","addScore","addScore","top","reset","reset","addScore","top"]\n[[],[1,73],[2,56],[3,39],[4,51],[5,4],[1],[1],[2],[2,51],[3]]\nOutput: \n[null,null,null,null,null,null,73,null,null,null,141]\n\nExplanation: \nLeaderboard leaderboard = new Leaderboard ();\nleaderboard.addScore(1,73);   // leaderboard = [[1,73]];\nleaderboard.addScore(2,56);   // leaderboard = [[1,73],[2,56]];\nleaderboard.addScore(3,39);   // leaderboard = [[1,73],[2,56],[3,39]];\nleaderboard.addScore(4,51);   // leaderboard = [[1,73],[2,56],[3,39],[4,51]];\nleaderboard.addScore(5,4);    // leaderboard = [[1,73],[2,56],[3,39],[4,51],[5,4]];\nleaderboard.top(1);           // returns 73;\nleaderboard.reset(1);         // leaderboard = [[2,56],[3,39],[4,51],[5,4]];\nleaderboard.reset(2);         // leaderboard = [[3,39],[4,51],[5,4]];\nleaderboard.addScore(2,51);   // leaderboard = [[2,51],[3,39],[4,51],[5,4]];\nleaderboard.top(3);           // returns 141 = 51 + 51 + 39;\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= playerId, K <= 10000
  • \n\t
  • It's guaranteed that K is less than or equal to the current number of players.
  • \n\t
  • 1 <= score <= 100
  • \n\t
  • There will be at most 1000 function calls.
  • \n
\n", "content_cn": "

\u65b0\u4e00\u8f6e\u7684\u300c\u529b\u6263\u676f\u300d\u7f16\u7a0b\u5927\u8d5b\u5373\u5c06\u542f\u52a8\uff0c\u4e3a\u4e86\u52a8\u6001\u663e\u793a\u53c2\u8d5b\u8005\u7684\u5f97\u5206\u6570\u636e\uff0c\u9700\u8981\u8bbe\u8ba1\u4e00\u4e2a\u6392\u884c\u699c Leaderboard\u3002

\n\n

\u8bf7\u4f60\u5e2e\u5fd9\u6765\u8bbe\u8ba1\u8fd9\u4e2a\u00a0Leaderboard \u7c7b\uff0c\u4f7f\u5f97\u5b83\u6709\u5982\u4e0b\u00a03 \u4e2a\u51fd\u6570\uff1a

\n\n
    \n\t
  1. addScore(playerId, score)\uff1a\n\n\t
      \n\t\t
    • \u5047\u5982\u53c2\u8d5b\u8005\u5df2\u7ecf\u5728\u6392\u884c\u699c\u4e0a\uff0c\u5c31\u7ed9\u4ed6\u7684\u5f53\u524d\u5f97\u5206\u589e\u52a0\u00a0score\u00a0\u70b9\u5206\u503c\u5e76\u66f4\u65b0\u6392\u884c\u3002
    • \n\t\t
    • \u5047\u5982\u8be5\u53c2\u8d5b\u8005\u4e0d\u5728\u6392\u884c\u699c\u4e0a\uff0c\u5c31\u628a\u4ed6\u6dfb\u52a0\u5230\u699c\u5355\u4e0a\uff0c\u5e76\u4e14\u5c06\u5206\u6570\u8bbe\u7f6e\u4e3a\u00a0score\u3002
    • \n\t
    \n\t
  2. \n\t
  3. top(K)\uff1a\u8fd4\u56de\u524d\u00a0K\u00a0\u540d\u53c2\u8d5b\u8005\u7684\u00a0\u5f97\u5206\u603b\u548c\u3002
  4. \n\t
  5. reset(playerId)\uff1a\u5c06\u6307\u5b9a\u53c2\u8d5b\u8005\u7684\u6210\u7ee9\u6e05\u96f6\uff08\u6362\u53e5\u8bdd\u8bf4\uff0c\u5c06\u5176\u4ece\u6392\u884c\u699c\u4e2d\u5220\u9664\uff09\u3002\u9898\u76ee\u4fdd\u8bc1\u5728\u8c03\u7528\u6b64\u51fd\u6570\u524d\uff0c\u8be5\u53c2\u8d5b\u8005\u5df2\u6709\u6210\u7ee9\uff0c\u5e76\u4e14\u5728\u699c\u5355\u4e0a\u3002
  6. \n
\n\n

\u8bf7\u6ce8\u610f\uff0c\u5728\u521d\u59cb\u72b6\u6001\u4e0b\uff0c\u6392\u884c\u699c\u662f\u7a7a\u7684\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1a \n[\"Leaderboard\",\"addScore\",\"addScore\",\"addScore\",\"addScore\",\"addScore\",\"top\",\"reset\",\"reset\",\"addScore\",\"top\"]\n[[],[1,73],[2,56],[3,39],[4,51],[5,4],[1],[1],[2],[2,51],[3]]\n\u8f93\u51fa\uff1a\n[null,null,null,null,null,null,73,null,null,null,141]\n\n\u89e3\u91ca\uff1a \nLeaderboard leaderboard = new Leaderboard ();\nleaderboard.addScore(1,73);   // leaderboard = [[1,73]];\nleaderboard.addScore(2,56);   // leaderboard = [[1,73],[2,56]];\nleaderboard.addScore(3,39);   // leaderboard = [[1,73],[2,56],[3,39]];\nleaderboard.addScore(4,51);   // leaderboard = [[1,73],[2,56],[3,39],[4,51]];\nleaderboard.addScore(5,4);    // leaderboard = [[1,73],[2,56],[3,39],[4,51],[5,4]];\nleaderboard.top(1);           // returns 73;\nleaderboard.reset(1);         // leaderboard = [[2,56],[3,39],[4,51],[5,4]];\nleaderboard.reset(2);         // leaderboard = [[3,39],[4,51],[5,4]];\nleaderboard.addScore(2,51);   // leaderboard = [[2,51],[3,39],[4,51],[5,4]];\nleaderboard.top(3);           // returns 141 = 51 + 51 + 39;\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= playerId, K <= 10000
  • \n\t
  • \u9898\u76ee\u4fdd\u8bc1\u00a0K\u00a0\u5c0f\u4e8e\u6216\u7b49\u4e8e\u5f53\u524d\u53c2\u8d5b\u8005\u7684\u6570\u91cf
  • \n\t
  • 1 <= score\u00a0<= 100
  • \n\t
  • \u6700\u591a\u8fdb\u884c\u00a01000\u00a0\u6b21\u51fd\u6570\u8c03\u7528
  • \n
\n", "tags_en": ["Sort", "Design", "Hash Table"], "tags_cn": ["\u6392\u5e8f", "\u8bbe\u8ba1", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Leaderboard {\npublic:\n Leaderboard() {\n\n }\n \n void addScore(int playerId, int score) {\n\n }\n \n int top(int K) {\n\n }\n \n void reset(int playerId) {\n\n }\n};\n\n/**\n * Your Leaderboard object will be instantiated and called as such:\n * Leaderboard* obj = new Leaderboard();\n * obj->addScore(playerId,score);\n * int param_2 = obj->top(K);\n * obj->reset(playerId);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Leaderboard {\n\n public Leaderboard() {\n\n }\n \n public void addScore(int playerId, int score) {\n\n }\n \n public int top(int K) {\n\n }\n \n public void reset(int playerId) {\n\n }\n}\n\n/**\n * Your Leaderboard object will be instantiated and called as such:\n * Leaderboard obj = new Leaderboard();\n * obj.addScore(playerId,score);\n * int param_2 = obj.top(K);\n * obj.reset(playerId);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Leaderboard(object):\n\n def __init__(self):\n\n\n def addScore(self, playerId, score):\n \"\"\"\n :type playerId: int\n :type score: int\n :rtype: None\n \"\"\"\n\n\n def top(self, K):\n \"\"\"\n :type K: int\n :rtype: int\n \"\"\"\n\n\n def reset(self, playerId):\n \"\"\"\n :type playerId: int\n :rtype: None\n \"\"\"\n\n\n\n# Your Leaderboard object will be instantiated and called as such:\n# obj = Leaderboard()\n# obj.addScore(playerId,score)\n# param_2 = obj.top(K)\n# obj.reset(playerId)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Leaderboard:\n\n def __init__(self):\n\n\n def addScore(self, playerId: int, score: int) -> None:\n\n\n def top(self, K: int) -> int:\n\n\n def reset(self, playerId: int) -> None:\n\n\n\n# Your Leaderboard object will be instantiated and called as such:\n# obj = Leaderboard()\n# obj.addScore(playerId,score)\n# param_2 = obj.top(K)\n# obj.reset(playerId)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} Leaderboard;\n\n\nLeaderboard* leaderboardCreate() {\n\n}\n\nvoid leaderboardAddScore(Leaderboard* obj, int playerId, int score) {\n\n}\n\nint leaderboardTop(Leaderboard* obj, int K) {\n\n}\n\nvoid leaderboardReset(Leaderboard* obj, int playerId) {\n\n}\n\nvoid leaderboardFree(Leaderboard* obj) {\n\n}\n\n/**\n * Your Leaderboard struct will be instantiated and called as such:\n * Leaderboard* obj = leaderboardCreate();\n * leaderboardAddScore(obj, playerId, score);\n \n * int param_2 = leaderboardTop(obj, K);\n \n * leaderboardReset(obj, playerId);\n \n * leaderboardFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Leaderboard {\n\n public Leaderboard() {\n\n }\n \n public void AddScore(int playerId, int score) {\n\n }\n \n public int Top(int K) {\n\n }\n \n public void Reset(int playerId) {\n\n }\n}\n\n/**\n * Your Leaderboard object will be instantiated and called as such:\n * Leaderboard obj = new Leaderboard();\n * obj.AddScore(playerId,score);\n * int param_2 = obj.Top(K);\n * obj.Reset(playerId);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "\nvar Leaderboard = function() {\n\n};\n\n/** \n * @param {number} playerId \n * @param {number} score\n * @return {void}\n */\nLeaderboard.prototype.addScore = function(playerId, score) {\n\n};\n\n/** \n * @param {number} K\n * @return {number}\n */\nLeaderboard.prototype.top = function(K) {\n\n};\n\n/** \n * @param {number} playerId\n * @return {void}\n */\nLeaderboard.prototype.reset = function(playerId) {\n\n};\n\n/**\n * Your Leaderboard object will be instantiated and called as such:\n * var obj = new Leaderboard()\n * obj.addScore(playerId,score)\n * var param_2 = obj.top(K)\n * obj.reset(playerId)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class Leaderboard\n def initialize()\n\n end\n\n\n=begin\n :type player_id: Integer\n :type score: Integer\n :rtype: Void\n=end\n def add_score(player_id, score)\n\n end\n\n\n=begin\n :type k: Integer\n :rtype: Integer\n=end\n def top(k)\n\n end\n\n\n=begin\n :type player_id: Integer\n :rtype: Void\n=end\n def reset(player_id)\n\n end\n\n\nend\n\n# Your Leaderboard object will be instantiated and called as such:\n# obj = Leaderboard.new()\n# obj.add_score(player_id, score)\n# param_2 = obj.top(k)\n# obj.reset(player_id)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass Leaderboard {\n\n init() {\n \n }\n \n func addScore(_ playerId: Int, _ score: Int) {\n \n }\n \n func top(_ K: Int) -> Int {\n \n }\n \n func reset(_ playerId: Int) {\n \n }\n}\n\n/**\n * Your Leaderboard object will be instantiated and called as such:\n * let obj = Leaderboard()\n * obj.addScore(playerId, score)\n * let ret_2: Int = obj.top(K)\n * obj.reset(playerId)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type Leaderboard struct {\n\n}\n\n\nfunc Constructor() Leaderboard {\n\n}\n\n\nfunc (this *Leaderboard) AddScore(playerId int, score int) {\n\n}\n\n\nfunc (this *Leaderboard) Top(K int) int {\n\n}\n\n\nfunc (this *Leaderboard) Reset(playerId int) {\n\n}\n\n\n/**\n * Your Leaderboard object will be instantiated and called as such:\n * obj := Constructor();\n * obj.AddScore(playerId,score);\n * param_2 := obj.Top(K);\n * obj.Reset(playerId);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class Leaderboard() {\n\n def addScore(playerId: Int, score: Int) {\n\n }\n\n def top(K: Int): Int = {\n\n }\n\n def reset(playerId: Int) {\n\n }\n\n}\n\n/**\n * Your Leaderboard object will be instantiated and called as such:\n * var obj = new Leaderboard()\n * obj.addScore(playerId,score)\n * var param_2 = obj.top(K)\n * obj.reset(playerId)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Leaderboard() {\n\n fun addScore(playerId: Int, score: Int) {\n\n }\n\n fun top(K: Int): Int {\n\n }\n\n fun reset(playerId: Int) {\n\n }\n\n}\n\n/**\n * Your Leaderboard object will be instantiated and called as such:\n * var obj = Leaderboard()\n * obj.addScore(playerId,score)\n * var param_2 = obj.top(K)\n * obj.reset(playerId)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct Leaderboard {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl Leaderboard {\n\n fn new() -> Self {\n\n }\n \n fn add_score(&self, player_id: i32, score: i32) {\n\n }\n \n fn top(&self, k: i32) -> i32 {\n\n }\n \n fn reset(&self, player_id: i32) {\n\n }\n}\n\n/**\n * Your Leaderboard object will be instantiated and called as such:\n * let obj = Leaderboard::new();\n * obj.add_score(playerId, score);\n * let ret_2: i32 = obj.top(K);\n * obj.reset(playerId);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Leaderboard {\n /**\n */\n function __construct() {\n\n }\n\n /**\n * @param Integer $playerId\n * @param Integer $score\n * @return NULL\n */\n function addScore($playerId, $score) {\n\n }\n\n /**\n * @param Integer $K\n * @return Integer\n */\n function top($K) {\n\n }\n\n /**\n * @param Integer $playerId\n * @return NULL\n */\n function reset($playerId) {\n\n }\n}\n\n/**\n * Your Leaderboard object will be instantiated and called as such:\n * $obj = Leaderboard();\n * $obj->addScore($playerId, $score);\n * $ret_2 = $obj->top($K);\n * $obj->reset($playerId);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class Leaderboard {\n constructor() {\n\n }\n\n addScore(playerId: number, score: number): void {\n\n }\n\n top(K: number): number {\n\n }\n\n reset(playerId: number): void {\n\n }\n}\n\n/**\n * Your Leaderboard object will be instantiated and called as such:\n * var obj = new Leaderboard()\n * obj.addScore(playerId,score)\n * var param_2 = obj.top(K)\n * obj.reset(playerId)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define leaderboard%\n (class object%\n (super-new)\n (init-field)\n \n ; add-score : exact-integer? exact-integer? -> void?\n (define/public (add-score playerId score)\n\n )\n ; top : exact-integer? -> exact-integer?\n (define/public (top K)\n\n )\n ; reset : exact-integer? -> void?\n (define/public (reset playerId)\n\n )))\n\n;; Your leaderboard% object will be instantiated and called as such:\n;; (define obj (new leaderboard%))\n;; (send obj add-score player-id score)\n;; (define param_2 (send obj top k))\n;; (send obj reset player-id)", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1244](https://leetcode-cn.com/problems/design-a-leaderboard)", "[\u529b\u6263\u6392\u884c\u699c](/solution/1200-1299/1244.Design%20A%20Leaderboard/README.md)", "`\u6392\u5e8f`,`\u8bbe\u8ba1`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1244](https://leetcode.com/problems/design-a-leaderboard)", "[Design A Leaderboard](/solution/1200-1299/1244.Design%20A%20Leaderboard/README_EN.md)", "`Sort`,`Design`,`Hash Table`", "Medium", "\ud83d\udd12"]}, {"question_id": "1175", "frontend_question_id": "1243", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/array-transformation", "url_en": "https://leetcode.com/problems/array-transformation", "relative_path_cn": "/solution/1200-1299/1243.Array%20Transformation/README.md", "relative_path_en": "/solution/1200-1299/1243.Array%20Transformation/README_EN.md", "title_cn": "\u6570\u7ec4\u53d8\u6362", "title_en": "Array Transformation", "question_title_slug": "array-transformation", "content_en": "

Given an initial array arr, every day you produce a new array using the array of the previous day.

\n\n

On the i-th day, you do the following operations on the array of day i-1 to produce the array of day i:

\n\n
    \n\t
  1. If an element is smaller than both its left neighbor and its right neighbor, then this element is incremented.
  2. \n\t
  3. If an element is bigger than both its left neighbor and its right neighbor, then this element is decremented.
  4. \n\t
  5. The first and last elements never change.
  6. \n
\n\n

After some days, the array does not change. Return that final array.

\n\n

 

\n

Example 1:

\n\n
\nInput: arr = [6,2,3,4]\nOutput: [6,3,3,4]\nExplanation: \nOn the first day, the array is changed from [6,2,3,4] to [6,3,3,4].\nNo more operations can be done to this array.\n
\n\n

Example 2:

\n\n
\nInput: arr = [1,6,3,4,3,5]\nOutput: [1,4,4,4,4,5]\nExplanation: \nOn the first day, the array is changed from [1,6,3,4,3,5] to [1,5,4,3,4,5].\nOn the second day, the array is changed from [1,5,4,3,4,5] to [1,4,4,4,4,5].\nNo more operations can be done to this array.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 3 <= arr.length <= 100
  • \n\t
  • 1 <= arr[i] <= 100
  • \n
\n", "content_cn": "

\u9996\u5148\uff0c\u7ed9\u4f60\u4e00\u4e2a\u521d\u59cb\u6570\u7ec4 arr\u3002\u7136\u540e\uff0c\u6bcf\u5929\u4f60\u90fd\u8981\u6839\u636e\u524d\u4e00\u5929\u7684\u6570\u7ec4\u751f\u6210\u4e00\u4e2a\u65b0\u7684\u6570\u7ec4\u3002

\n\n

\u7b2c i \u5929\u6240\u751f\u6210\u7684\u6570\u7ec4\uff0c\u662f\u7531\u4f60\u5bf9\u7b2c i-1 \u5929\u7684\u6570\u7ec4\u8fdb\u884c\u5982\u4e0b\u64cd\u4f5c\u6240\u5f97\u7684\uff1a

\n\n
    \n\t
  1. \u5047\u5982\u4e00\u4e2a\u5143\u7d20\u5c0f\u4e8e\u5b83\u7684\u5de6\u53f3\u90bb\u5c45\uff0c\u90a3\u4e48\u8be5\u5143\u7d20\u81ea\u589e 1\u3002
  2. \n\t
  3. \u5047\u5982\u4e00\u4e2a\u5143\u7d20\u5927\u4e8e\u5b83\u7684\u5de6\u53f3\u90bb\u5c45\uff0c\u90a3\u4e48\u8be5\u5143\u7d20\u81ea\u51cf 1\u3002
  4. \n\t
  5. \u9996\u3001\u5c3e\u5143\u7d20 \u6c38\u4e0d \u6539\u53d8\u3002
  6. \n
\n\n

\u8fc7\u4e9b\u65f6\u65e5\uff0c\u4f60\u4f1a\u53d1\u73b0\u6570\u7ec4\u5c06\u4f1a\u4e0d\u518d\u53d1\u751f\u53d8\u5316\uff0c\u8bf7\u8fd4\u56de\u6700\u7ec8\u6240\u5f97\u5230\u7684\u6570\u7ec4\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a[6,2,3,4]\n\u8f93\u51fa\uff1a[6,3,3,4]\n\u89e3\u91ca\uff1a\n\u7b2c\u4e00\u5929\uff0c\u6570\u7ec4\u4ece [6,2,3,4] \u53d8\u4e3a [6,3,3,4]\u3002\n\u65e0\u6cd5\u518d\u5bf9\u8be5\u6570\u7ec4\u8fdb\u884c\u66f4\u591a\u64cd\u4f5c\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a[1,6,3,4,3,5]\n\u8f93\u51fa\uff1a[1,4,4,4,4,5]\n\u89e3\u91ca\uff1a\n\u7b2c\u4e00\u5929\uff0c\u6570\u7ec4\u4ece [1,6,3,4,3,5] \u53d8\u4e3a [1,5,4,3,4,5]\u3002\n\u7b2c\u4e8c\u5929\uff0c\u6570\u7ec4\u4ece [1,5,4,3,4,5] \u53d8\u4e3a [1,4,4,4,4,5]\u3002\n\u65e0\u6cd5\u518d\u5bf9\u8be5\u6570\u7ec4\u8fdb\u884c\u66f4\u591a\u64cd\u4f5c\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= arr.length <= 100
  2. \n\t
  3. 1 <= arr[i] <= 100
  4. \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector transformArray(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List transformArray(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def transformArray(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def transformArray(self, arr: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* transformArray(int* arr, int arrSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList TransformArray(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number[]}\n */\nvar transformArray = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer[]}\ndef transform_array(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func transformArray(_ arr: [Int]) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func transformArray(arr []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def transformArray(arr: Array[Int]): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun transformArray(arr: IntArray): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn transform_array(arr: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer[]\n */\n function transformArray($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function transformArray(arr: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (transform-array arr)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1243](https://leetcode-cn.com/problems/array-transformation)", "[\u6570\u7ec4\u53d8\u6362](/solution/1200-1299/1243.Array%20Transformation/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1243](https://leetcode.com/problems/array-transformation)", "[Array Transformation](/solution/1200-1299/1243.Array%20Transformation/README_EN.md)", "`Array`", "Easy", "\ud83d\udd12"]}, {"question_id": "1174", "frontend_question_id": "1084", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/sales-analysis-iii", "url_en": "https://leetcode.com/problems/sales-analysis-iii", "relative_path_cn": "/solution/1000-1099/1084.Sales%20Analysis%20III/README.md", "relative_path_en": "/solution/1000-1099/1084.Sales%20Analysis%20III/README_EN.md", "title_cn": "\u9500\u552e\u5206\u6790III", "title_en": "Sales Analysis III", "question_title_slug": "sales-analysis-iii", "content_en": "

Table: Product

\n\n
\n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| product_id   | int     |\n| product_name | varchar |\n| unit_price   | int     |\n+--------------+---------+\nproduct_id is the primary key of this table.\n
\n\n

Table: Sales

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| seller_id   | int     |\n| product_id  | int     |\n| buyer_id    | int     |\n| sale_date   | date    |\n| quantity    | int     |\n| price       | int     |\n+------ ------+---------+\nThis table has no primary key, it can have repeated rows.\nproduct_id is a foreign key to Product table.\n
\n\n

 

\n\n

Write an SQL query that reports the products that were only sold in spring 2019. That is, between 2019-01-01 and 2019-03-31 inclusive.

\n\n

The query result format is in the following example:

\n\n
\nProduct table:\n+------------+--------------+------------+\n| product_id | product_name | unit_price |\n+------------+--------------+------------+\n| 1          | S8           | 1000       |\n| 2          | G4           | 800        |\n| 3          | iPhone       | 1400       |\n+------------+--------------+------------+\n\nSales table:\n+-----------+------------+----------+------------+----------+-------+\n| seller_id | product_id | buyer_id | sale_date  | quantity | price |\n+-----------+------------+----------+------------+----------+-------+\n| 1         | 1          | 1        | 2019-01-21 | 2        | 2000  |\n| 1         | 2          | 2        | 2019-02-17 | 1        | 800   |\n| 2         | 2          | 3        | 2019-06-02 | 1        | 800   |\n| 3         | 3          | 4        | 2019-05-13 | 2        | 2800  |\n+-----------+------------+----------+------------+----------+-------+\n\nResult table:\n+-------------+--------------+\n| product_id  | product_name |\n+-------------+--------------+\n| 1           | S8           |\n+-------------+--------------+\nThe product with id 1 was only sold in spring 2019 while the other two were sold after.
\n", "content_cn": "

Table: Product

\n\n
+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| product_id   | int     |\n| product_name | varchar |\n| unit_price   | int     |\n+--------------+---------+\nproduct_id \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\n
\n\n

Table: Sales

\n\n
+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| seller_id   | int     |\n| product_id  | int     |\n| buyer_id    | int     |\n| sale_date   | date    |\n| quantity    | int     |\n| price       | int     |\n+------ ------+---------+\n\u8fd9\u4e2a\u8868\u6ca1\u6709\u4e3b\u952e\uff0c\u5b83\u53ef\u4ee5\u6709\u91cd\u590d\u7684\u884c.\nproduct_id \u662f Product \u8868\u7684\u5916\u952e.
\n\n

 

\n\n

\u7f16\u5199\u4e00\u4e2aSQL\u67e5\u8be2\uff0c\u62a5\u544a2019\u5e74\u6625\u5b63\u624d\u552e\u51fa\u7684\u4ea7\u54c1\u3002\u5373\u4ec5\u57282019-01-01\u81f32019-03-31\uff08\u542b\uff09\u4e4b\u95f4\u51fa\u552e\u7684\u5546\u54c1\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u6240\u793a\uff1a

\n\n
Product table:\n+------------+--------------+------------+\n| product_id | product_name | unit_price |\n+------------+--------------+------------+\n| 1          | S8           | 1000       |\n| 2          | G4           | 800        |\n| 3          | iPhone       | 1400       |\n+------------+--------------+------------+\n\nSales table:\n+-----------+------------+----------+------------+----------+-------+\n| seller_id | product_id | buyer_id | sale_date  | quantity | price |\n+-----------+------------+----------+------------+----------+-------+\n| 1         | 1          | 1        | 2019-01-21 | 2        | 2000  |\n| 1         | 2          | 2        | 2019-02-17 | 1        | 800   |\n| 2         | 2          | 3        | 2019-06-02 | 1        | 800   |\n| 3         | 3          | 4        | 2019-05-13 | 2        | 2800  |\n+-----------+------------+----------+------------+----------+-------+\n\nResult table:\n+-------------+--------------+\n| product_id  | product_name |\n+-------------+--------------+\n| 1           | S8           |\n+-------------+--------------+\nid\u4e3a1\u7684\u4ea7\u54c1\u4ec5\u57282019\u5e74\u6625\u5b63\u9500\u552e\uff0c\u5176\u4ed6\u4e24\u4e2a\u4ea7\u54c1\u5728\u4e4b\u540e\u9500\u552e\u3002
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1084](https://leetcode-cn.com/problems/sales-analysis-iii)", "[\u9500\u552e\u5206\u6790III](/solution/1000-1099/1084.Sales%20Analysis%20III/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1084](https://leetcode.com/problems/sales-analysis-iii)", "[Sales Analysis III](/solution/1000-1099/1084.Sales%20Analysis%20III/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1173", "frontend_question_id": "1083", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/sales-analysis-ii", "url_en": "https://leetcode.com/problems/sales-analysis-ii", "relative_path_cn": "/solution/1000-1099/1083.Sales%20Analysis%20II/README.md", "relative_path_en": "/solution/1000-1099/1083.Sales%20Analysis%20II/README_EN.md", "title_cn": "\u9500\u552e\u5206\u6790 II", "title_en": "Sales Analysis II", "question_title_slug": "sales-analysis-ii", "content_en": "

Table: Product

\r\n\r\n
\r\n+--------------+---------+\r\n| Column Name  | Type    |\r\n+--------------+---------+\r\n| product_id   | int     |\r\n| product_name | varchar |\r\n| unit_price   | int     |\r\n+--------------+---------+\r\nproduct_id is the primary key of this table.\r\n
\r\n\r\n

Table: Sales

\r\n\r\n
\r\n+-------------+---------+\r\n| Column Name | Type    |\r\n+-------------+---------+\r\n| seller_id   | int     |\r\n| product_id  | int     |\r\n| buyer_id    | int     |\r\n| sale_date   | date    |\r\n| quantity    | int     |\r\n| price       | int     |\r\n+------ ------+---------+\r\nThis table has no primary key, it can have repeated rows.\r\nproduct_id is a foreign key to Product table.\r\n
\r\n\r\n

 

\r\n\r\n

Write an SQL query that reports the buyers who have bought S8 but not iPhone. Note that S8 and iPhone are products present in the Product table.

\r\n\r\n

The query result format is in the following example:

\r\n\r\n
\r\nProduct table:\r\n+------------+--------------+------------+\r\n| product_id | product_name | unit_price |\r\n+------------+--------------+------------+\r\n| 1          | S8           | 1000       |\r\n| 2          | G4           | 800        |\r\n| 3          | iPhone       | 1400       |\r\n+------------+--------------+------------+\r\n\r\nSales table:\r\n+-----------+------------+----------+------------+----------+-------+\r\n| seller_id | product_id | buyer_id | sale_date  | quantity | price |\r\n+-----------+------------+----------+------------+----------+-------+\r\n| 1         | 1          | 1        | 2019-01-21 | 2        | 2000  |\r\n| 1         | 2          | 2        | 2019-02-17 | 1        | 800   |\r\n| 2         | 1          | 3        | 2019-06-02 | 1        | 800   |\r\n| 3         | 3          | 3        | 2019-05-13 | 2        | 2800  |\r\n+-----------+------------+----------+------------+----------+-------+\r\n\r\nResult table:\r\n+-------------+\r\n| buyer_id    |\r\n+-------------+\r\n| 1           |\r\n+-------------+\r\nThe buyer with id 1 bought an S8 but didn't buy an iPhone. The buyer with id 3 bought both.
\r\n", "content_cn": "

Table: Product

\n\n
+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| product_id   | int     |\n| product_name | varchar |\n| unit_price   | int     |\n+--------------+---------+\nproduct_id \u662f\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\n
\n\n

Table: Sales

\n\n
+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| seller_id   | int     |\n| product_id  | int     |\n| buyer_id    | int     |\n| sale_date   | date    |\n| quantity    | int     |\n| price       | int     |\n+------ ------+---------+\n\u8fd9\u4e2a\u8868\u6ca1\u6709\u4e3b\u952e\uff0c\u5b83\u53ef\u4ee5\u6709\u91cd\u590d\u7684\u884c.\nproduct_id \u662f Product \u8868\u7684\u5916\u952e.\n
\n\n

\u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\uff0c\u67e5\u8be2\u8d2d\u4e70\u4e86 S8 \u624b\u673a\u5374\u6ca1\u6709\u8d2d\u4e70 iPhone \u7684\u4e70\u5bb6\u3002\u6ce8\u610f\u8fd9\u91cc S8 \u548c iPhone \u662f Product \u8868\u4e2d\u7684\u4ea7\u54c1\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u56fe\u8868\u793a\uff1a

\n\n
Product table:\n+------------+--------------+------------+\n| product_id | product_name | unit_price |\n+------------+--------------+------------+\n| 1          | S8           | 1000       |\n| 2          | G4           | 800        |\n| 3          | iPhone       | 1400       |\n+------------+--------------+------------+\n\nSales table:\n+-----------+------------+----------+------------+----------+-------+\n| seller_id | product_id | buyer_id | sale_date  | quantity | price |\n+-----------+------------+----------+------------+----------+-------+\n| 1         | 1          | 1        | 2019-01-21 | 2        | 2000  |\n| 1         | 2          | 2        | 2019-02-17 | 1        | 800   |\n| 2         | 1          | 3        | 2019-06-02 | 1        | 800   |\n| 3         | 3          | 3        | 2019-05-13 | 2        | 2800  |\n+-----------+------------+----------+------------+----------+-------+\n\nResult table:\n+-------------+\n| buyer_id    |\n+-------------+\n| 1           |\n+-------------+\nid \u4e3a 1 \u7684\u4e70\u5bb6\u8d2d\u4e70\u4e86\u4e00\u90e8 S8\uff0c\u4f46\u662f\u5374\u6ca1\u6709\u8d2d\u4e70 iPhone\uff0c\u800c id \u4e3a 3 \u7684\u4e70\u5bb6\u5374\u540c\u65f6\u8d2d\u4e70\u4e86\u8fd9 2 \u90e8\u624b\u673a\u3002\n\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1083](https://leetcode-cn.com/problems/sales-analysis-ii)", "[\u9500\u552e\u5206\u6790 II](/solution/1000-1099/1083.Sales%20Analysis%20II/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1083](https://leetcode.com/problems/sales-analysis-ii)", "[Sales Analysis II](/solution/1000-1099/1083.Sales%20Analysis%20II/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1172", "frontend_question_id": "1082", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/sales-analysis-i", "url_en": "https://leetcode.com/problems/sales-analysis-i", "relative_path_cn": "/solution/1000-1099/1082.Sales%20Analysis%20I/README.md", "relative_path_en": "/solution/1000-1099/1082.Sales%20Analysis%20I/README_EN.md", "title_cn": "\u9500\u552e\u5206\u6790 I ", "title_en": "Sales Analysis I", "question_title_slug": "sales-analysis-i", "content_en": "

Table: Product

\n\n
\n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| product_id   | int     |\n| product_name | varchar |\n| unit_price   | int     |\n+--------------+---------+\nproduct_id is the primary key of this table.\n
\n\n

Table: Sales

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| seller_id   | int     |\n| product_id  | int     |\n| buyer_id    | int     |\n| sale_date   | date    |\n| quantity    | int     |\n| price       | int     |\n+------ ------+---------+\nThis table has no primary key, it can have repeated rows.\nproduct_id is a foreign key to Product table.\n
\n\n

 

\n\n

Write an SQL query that reports the best seller by total sales price, If there is a tie, report them all.

\n\n

The query result format is in the following example:

\n\n
\nProduct table:\n+------------+--------------+------------+\n| product_id | product_name | unit_price |\n+------------+--------------+------------+\n| 1          | S8           | 1000       |\n| 2          | G4           | 800        |\n| 3          | iPhone       | 1400       |\n+------------+--------------+------------+\n\nSales table:\n+-----------+------------+----------+------------+----------+-------+\n| seller_id | product_id | buyer_id | sale_date  | quantity | price |\n+-----------+------------+----------+------------+----------+-------+\n| 1         | 1          | 1        | 2019-01-21 | 2        | 2000  |\n| 1         | 2          | 2        | 2019-02-17 | 1        | 800   |\n| 2         | 2          | 3        | 2019-06-02 | 1        | 800   |\n| 3         | 3          | 4        | 2019-05-13 | 2        | 2800  |\n+-----------+------------+----------+------------+----------+-------+\n\nResult table:\n+-------------+\n| seller_id   |\n+-------------+\n| 1           |\n| 3           |\n+-------------+\nBoth sellers with id 1 and 3 sold products with the most total price of 2800.
\n", "content_cn": "

\u4ea7\u54c1\u8868\uff1aProduct

\n\n
+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| product_id   | int     |\n| product_name | varchar |\n| unit_price   | int     |\n+--------------+---------+\nproduct_id \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e.\n
\n\n

\u9500\u552e\u8868\uff1aSales

\n\n
+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| seller_id   | int     |\n| product_id  | int     |\n| buyer_id    | int     |\n| sale_date   | date    |\n| quantity    | int     |\n| price       | int     |\n+------ ------+---------+\n\u8fd9\u4e2a\u8868\u6ca1\u6709\u4e3b\u952e\uff0c\u5b83\u53ef\u4ee5\u6709\u91cd\u590d\u7684\u884c.\nproduct_id \u662f Product \u8868\u7684\u5916\u952e.\n
\n\n

 

\n\n

\u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\uff0c\u67e5\u8be2\u603b\u9500\u552e\u989d\u6700\u9ad8\u7684\u9500\u552e\u8005\uff0c\u5982\u679c\u6709\u5e76\u5217\u7684\uff0c\u5c31\u90fd\u5c55\u793a\u51fa\u6765\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u6240\u793a\uff1a

\n\n
Product \u8868\uff1a\n+------------+--------------+------------+\n| product_id | product_name | unit_price |\n+------------+--------------+------------+\n| 1          | S8           | 1000       |\n| 2          | G4           | 800        |\n| 3          | iPhone       | 1400       |\n+------------+--------------+------------+\n\nSales \u8868\uff1a\n+-----------+------------+----------+------------+----------+-------+\n| seller_id | product_id | buyer_id | sale_date  | quantity | price |\n+-----------+------------+----------+------------+----------+-------+\n| 1         | 1          | 1        | 2019-01-21 | 2        | 2000  |\n| 1         | 2          | 2        | 2019-02-17 | 1        | 800   |\n| 2         | 2          | 3        | 2019-06-02 | 1        | 800   |\n| 3         | 3          | 4        | 2019-05-13 | 2        | 2800  |\n+-----------+------------+----------+------------+----------+-------+\n\nResult \u8868\uff1a\n+-------------+\n| seller_id   |\n+-------------+\n| 1           |\n| 3           |\n+-------------+\nId \u4e3a 1 \u548c 3 \u7684\u9500\u552e\u8005\uff0c\u9500\u552e\u603b\u91d1\u989d\u90fd\u4e3a\u6700\u9ad8\u7684 2800\u3002
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1082](https://leetcode-cn.com/problems/sales-analysis-i)", "[\u9500\u552e\u5206\u6790 I ](/solution/1000-1099/1082.Sales%20Analysis%20I/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1082](https://leetcode.com/problems/sales-analysis-i)", "[Sales Analysis I](/solution/1000-1099/1082.Sales%20Analysis%20I/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1171", "frontend_question_id": "1091", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/shortest-path-in-binary-matrix", "url_en": "https://leetcode.com/problems/shortest-path-in-binary-matrix", "relative_path_cn": "/solution/1000-1099/1091.Shortest%20Path%20in%20Binary%20Matrix/README.md", "relative_path_en": "/solution/1000-1099/1091.Shortest%20Path%20in%20Binary%20Matrix/README_EN.md", "title_cn": "\u4e8c\u8fdb\u5236\u77e9\u9635\u4e2d\u7684\u6700\u77ed\u8def\u5f84", "title_en": "Shortest Path in Binary Matrix", "question_title_slug": "shortest-path-in-binary-matrix", "content_en": "

Given an n x n binary matrix grid, return the length of the shortest clear path in the matrix. If there is no clear path, return -1.

\n\n

A clear path in a binary matrix is a path from the top-left cell (i.e., (0, 0)) to the bottom-right cell (i.e., (n - 1, n - 1)) such that:

\n\n
    \n\t
  • All the visited cells of the path are 0.
  • \n\t
  • All the adjacent cells of the path are 8-directionally connected (i.e., they are different and they share an edge or a corner).
  • \n
\n\n

The length of a clear path is the number of visited cells of this path.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: grid = [[0,1],[1,0]]\nOutput: 2\n
\n\n

Example 2:

\n\"\"\n
\nInput: grid = [[0,0,0],[1,1,0],[1,1,0]]\nOutput: 4\n
\n\n

Example 3:

\n\n
\nInput: grid = [[1,0,0],[1,1,0],[1,1,0]]\nOutput: -1\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == grid.length
  • \n\t
  • n == grid[i].length
  • \n\t
  • 1 <= n <= 100
  • \n\t
  • grid[i][j] is 0 or 1
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a n x n \u7684\u4e8c\u8fdb\u5236\u77e9\u9635 grid \u4e2d\uff0c\u8fd4\u56de\u77e9\u9635\u4e2d\u6700\u77ed \u7545\u901a\u8def\u5f84 \u7684\u957f\u5ea6\u3002\u5982\u679c\u4e0d\u5b58\u5728\u8fd9\u6837\u7684\u8def\u5f84\uff0c\u8fd4\u56de -1 \u3002

\n\n

\u4e8c\u8fdb\u5236\u77e9\u9635\u4e2d\u7684 \u7545\u901a\u8def\u5f84 \u662f\u4e00\u6761\u4ece \u5de6\u4e0a\u89d2 \u5355\u5143\u683c\uff08\u5373\uff0c(0, 0)\uff09\u5230 \u53f3\u4e0b\u89d2 \u5355\u5143\u683c\uff08\u5373\uff0c(n - 1, n - 1)\uff09\u7684\u8def\u5f84\uff0c\u8be5\u8def\u5f84\u540c\u65f6\u6ee1\u8db3\u4e0b\u8ff0\u8981\u6c42\uff1a

\n\n
    \n\t
  • \u8def\u5f84\u9014\u7ecf\u7684\u6240\u6709\u5355\u5143\u683c\u90fd\u7684\u503c\u90fd\u662f 0 \u3002
  • \n\t
  • \u8def\u5f84\u4e2d\u6240\u6709\u76f8\u90bb\u7684\u5355\u5143\u683c\u5e94\u5f53\u5728 8 \u4e2a\u65b9\u5411\u4e4b\u4e00 \u4e0a\u8fde\u901a\uff08\u5373\uff0c\u76f8\u90bb\u4e24\u5355\u5143\u4e4b\u95f4\u5f7c\u6b64\u4e0d\u540c\u4e14\u5171\u4eab\u4e00\u6761\u8fb9\u6216\u8005\u4e00\u4e2a\u89d2\uff09\u3002
  • \n
\n\n

\u7545\u901a\u8def\u5f84\u7684\u957f\u5ea6 \u662f\u8be5\u8def\u5f84\u9014\u7ecf\u7684\u5355\u5143\u683c\u603b\u6570\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1agrid = [[0,1],[1,0]]\n\u8f93\u51fa\uff1a2\n
\n\n

\u793a\u4f8b 2\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1agrid = [[0,0,0],[1,1,0],[1,1,0]]\n\u8f93\u51fa\uff1a4\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1agrid = [[1,0,0],[1,1,0],[1,1,0]]\n\u8f93\u51fa\uff1a-1\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • n == grid.length
  • \n\t
  • n == grid[i].length
  • \n\t
  • 1 <= n <= 100
  • \n\t
  • grid[i][j] \u4e3a 0 \u6216 1
  • \n
\n", "tags_en": ["Breadth-first Search"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int shortestPathBinaryMatrix(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int shortestPathBinaryMatrix(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def shortestPathBinaryMatrix(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def shortestPathBinaryMatrix(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint shortestPathBinaryMatrix(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ShortestPathBinaryMatrix(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar shortestPathBinaryMatrix = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef shortest_path_binary_matrix(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func shortestPathBinaryMatrix(_ grid: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func shortestPathBinaryMatrix(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def shortestPathBinaryMatrix(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun shortestPathBinaryMatrix(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn shortest_path_binary_matrix(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function shortestPathBinaryMatrix($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function shortestPathBinaryMatrix(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (shortest-path-binary-matrix grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1091](https://leetcode-cn.com/problems/shortest-path-in-binary-matrix)", "[\u4e8c\u8fdb\u5236\u77e9\u9635\u4e2d\u7684\u6700\u77ed\u8def\u5f84](/solution/1000-1099/1091.Shortest%20Path%20in%20Binary%20Matrix/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1091](https://leetcode.com/problems/shortest-path-in-binary-matrix)", "[Shortest Path in Binary Matrix](/solution/1000-1099/1091.Shortest%20Path%20in%20Binary%20Matrix/README_EN.md)", "`Breadth-first Search`", "Medium", ""]}, {"question_id": "1170", "frontend_question_id": "1092", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/shortest-common-supersequence", "url_en": "https://leetcode.com/problems/shortest-common-supersequence", "relative_path_cn": "/solution/1000-1099/1092.Shortest%20Common%20Supersequence/README.md", "relative_path_en": "/solution/1000-1099/1092.Shortest%20Common%20Supersequence/README_EN.md", "title_cn": "\u6700\u77ed\u516c\u5171\u8d85\u5e8f\u5217", "title_en": "Shortest Common Supersequence", "question_title_slug": "shortest-common-supersequence", "content_en": "

Given two strings str1 and str2, return the shortest string that has both str1 and str2 as subsequences.  If multiple answers exist, you may return any of them.

\n\n

(A string S is a subsequence of string T if deleting some number of characters from T (possibly 0, and the characters are chosen anywhere from T) results in the string S.)

\n\n

 

\n\n

Example 1:

\n\n
\nInput: str1 = "abac", str2 = "cab"\nOutput: "cabac"\nExplanation: \nstr1 = "abac" is a subsequence of "cabac" because we can delete the first "c".\nstr2 = "cab" is a subsequence of "cabac" because we can delete the last "ac".\nThe answer provided is the shortest such string that satisfies these properties.\n
\n\n

 

\n\n

Note:

\n\n
    \n\t
  1. 1 <= str1.length, str2.length <= 1000
  2. \n\t
  3. str1 and str2 consist of lowercase English letters.
  4. \n
\n", "content_cn": "

\u7ed9\u51fa\u4e24\u4e2a\u5b57\u7b26\u4e32 str1 \u548c str2\uff0c\u8fd4\u56de\u540c\u65f6\u4ee5 str1 \u548c str2 \u4f5c\u4e3a\u5b50\u5e8f\u5217\u7684\u6700\u77ed\u5b57\u7b26\u4e32\u3002\u5982\u679c\u7b54\u6848\u4e0d\u6b62\u4e00\u4e2a\uff0c\u5219\u53ef\u4ee5\u8fd4\u56de\u6ee1\u8db3\u6761\u4ef6\u7684\u4efb\u610f\u4e00\u4e2a\u7b54\u6848\u3002

\n\n

\uff08\u5982\u679c\u4ece\u5b57\u7b26\u4e32 T \u4e2d\u5220\u9664\u4e00\u4e9b\u5b57\u7b26\uff08\u4e5f\u53ef\u80fd\u4e0d\u5220\u9664\uff0c\u5e76\u4e14\u9009\u51fa\u7684\u8fd9\u4e9b\u5b57\u7b26\u53ef\u4ee5\u4f4d\u4e8e T \u4e2d\u7684 \u4efb\u610f\u4f4d\u7f6e\uff09\uff0c\u53ef\u4ee5\u5f97\u5230\u5b57\u7b26\u4e32 S\uff0c\u90a3\u4e48 S \u5c31\u662f T \u7684\u5b50\u5e8f\u5217\uff09

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1astr1 = "abac", str2 = "cab"\n\u8f93\u51fa\uff1a"cabac"\n\u89e3\u91ca\uff1a\nstr1 = "abac" \u662f "cabac" \u7684\u4e00\u4e2a\u5b50\u4e32\uff0c\u56e0\u4e3a\u6211\u4eec\u53ef\u4ee5\u5220\u53bb "cabac" \u7684\u7b2c\u4e00\u4e2a "c"\u5f97\u5230 "abac"\u3002 \nstr2 = "cab" \u662f "cabac" \u7684\u4e00\u4e2a\u5b50\u4e32\uff0c\u56e0\u4e3a\u6211\u4eec\u53ef\u4ee5\u5220\u53bb "cabac" \u672b\u5c3e\u7684 "ac" \u5f97\u5230 "cab"\u3002\n\u6700\u7ec8\u6211\u4eec\u7ed9\u51fa\u7684\u7b54\u6848\u662f\u6ee1\u8db3\u4e0a\u8ff0\u5c5e\u6027\u7684\u6700\u77ed\u5b57\u7b26\u4e32\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= str1.length, str2.length <= 1000
  2. \n\t
  3. str1 \u548c str2 \u90fd\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\u3002
  4. \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string shortestCommonSupersequence(string str1, string str2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String shortestCommonSupersequence(String str1, String str2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def shortestCommonSupersequence(self, str1, str2):\n \"\"\"\n :type str1: str\n :type str2: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def shortestCommonSupersequence(self, str1: str, str2: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * shortestCommonSupersequence(char * str1, char * str2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ShortestCommonSupersequence(string str1, string str2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} str1\n * @param {string} str2\n * @return {string}\n */\nvar shortestCommonSupersequence = function(str1, str2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} str1\n# @param {String} str2\n# @return {String}\ndef shortest_common_supersequence(str1, str2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func shortestCommonSupersequence(_ str1: String, _ str2: String) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func shortestCommonSupersequence(str1 string, str2 string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def shortestCommonSupersequence(str1: String, str2: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun shortestCommonSupersequence(str1: String, str2: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn shortest_common_supersequence(str1: String, str2: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $str1\n * @param String $str2\n * @return String\n */\n function shortestCommonSupersequence($str1, $str2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function shortestCommonSupersequence(str1: string, str2: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (shortest-common-supersequence str1 str2)\n (-> string? string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1092](https://leetcode-cn.com/problems/shortest-common-supersequence)", "[\u6700\u77ed\u516c\u5171\u8d85\u5e8f\u5217](/solution/1000-1099/1092.Shortest%20Common%20Supersequence/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1092](https://leetcode.com/problems/shortest-common-supersequence)", "[Shortest Common Supersequence](/solution/1000-1099/1092.Shortest%20Common%20Supersequence/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1169", "frontend_question_id": "1090", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/largest-values-from-labels", "url_en": "https://leetcode.com/problems/largest-values-from-labels", "relative_path_cn": "/solution/1000-1099/1090.Largest%20Values%20From%20Labels/README.md", "relative_path_en": "/solution/1000-1099/1090.Largest%20Values%20From%20Labels/README_EN.md", "title_cn": "\u53d7\u6807\u7b7e\u5f71\u54cd\u7684\u6700\u5927\u503c", "title_en": "Largest Values From Labels", "question_title_slug": "largest-values-from-labels", "content_en": "

We have a set of items: the i-th item has value values[i] and label labels[i].

\r\n\r\n

Then, we choose a subset S of these items, such that:

\r\n\r\n
    \r\n\t
  • |S| <= num_wanted
  • \r\n\t
  • For every label L, the number of items in S with label L is <= use_limit.
  • \r\n
\r\n\r\n

Return the largest possible sum of the subset S.

\r\n\r\n

 

\r\n\r\n
\r\n

Example 1:

\r\n\r\n
\r\nInput: values = [5,4,3,2,1], labels = [1,1,2,2,3], num_wanted = 3, use_limit = 1\r\nOutput: 9\r\nExplanation: The subset chosen is the first, third, and fifth item.\r\n
\r\n\r\n
\r\n

Example 2:

\r\n\r\n
\r\nInput: values = [5,4,3,2,1], labels = [1,3,3,3,2], num_wanted = 3, use_limit = 2\r\nOutput: 12\r\nExplanation: The subset chosen is the first, second, and third item.\r\n
\r\n\r\n
\r\n

Example 3:

\r\n\r\n
\r\nInput: values = [9,8,8,7,6], labels = [0,0,0,1,1], num_wanted = 3, use_limit = 1\r\nOutput: 16\r\nExplanation: The subset chosen is the first and fourth item.\r\n
\r\n\r\n
\r\n

Example 4:

\r\n\r\n
\r\nInput: values = [9,8,8,7,6], labels = [0,0,0,1,1], num_wanted = 3, use_limit = 2\r\nOutput: 24\r\nExplanation: The subset chosen is the first, second, and fourth item.\r\n
\r\n\r\n

 

\r\n\r\n

Note:

\r\n\r\n
    \r\n\t
  1. 1 <= values.length == labels.length <= 20000
  2. \r\n\t
  3. 0 <= values[i], labels[i] <= 20000
  4. \r\n\t
  5. 1 <= num_wanted, use_limit <= values.length
  6. \r\n
\r\n
\r\n
\r\n
\r\n
", "content_cn": "

\u6211\u4eec\u6709\u4e00\u4e2a\u9879\u7684\u96c6\u5408\uff0c\u5176\u4e2d\u7b2c i \u9879\u7684\u503c\u4e3a values[i]\uff0c\u6807\u7b7e\u4e3a labels[i]\u3002

\n\n

\u6211\u4eec\u4ece\u8fd9\u4e9b\u9879\u4e2d\u9009\u51fa\u4e00\u4e2a\u5b50\u96c6 S\uff0c\u8fd9\u6837\u4e00\u6765\uff1a

\n\n
    \n\t
  • |S| <= num_wanted
  • \n\t
  • \u5bf9\u4e8e\u4efb\u610f\u7684\u6807\u7b7e L\uff0c\u5b50\u96c6 S \u4e2d\u6807\u7b7e\u4e3a L \u7684\u9879\u7684\u6570\u76ee\u603b\u6ee1\u8db3 <= use_limit\u3002
  • \n
\n\n

\u8fd4\u56de\u5b50\u96c6 S \u7684\u6700\u5927\u53ef\u80fd\u7684 \u548c\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1avalues = [5,4,3,2,1], labels = [1,1,2,2,3], num_wanted = 3, use_limit = 1\n\u8f93\u51fa\uff1a9\n\u89e3\u91ca\uff1a\u9009\u51fa\u7684\u5b50\u96c6\u662f\u7b2c\u4e00\u9879\uff0c\u7b2c\u4e09\u9879\u548c\u7b2c\u4e94\u9879\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1avalues = [5,4,3,2,1], labels = [1,3,3,3,2], num_wanted = 3, use_limit = 2\n\u8f93\u51fa\uff1a12\n\u89e3\u91ca\uff1a\u9009\u51fa\u7684\u5b50\u96c6\u662f\u7b2c\u4e00\u9879\uff0c\u7b2c\u4e8c\u9879\u548c\u7b2c\u4e09\u9879\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1avalues = [9,8,8,7,6], labels = [0,0,0,1,1], num_wanted = 3, use_limit = 1\n\u8f93\u51fa\uff1a16\n\u89e3\u91ca\uff1a\u9009\u51fa\u7684\u5b50\u96c6\u662f\u7b2c\u4e00\u9879\u548c\u7b2c\u56db\u9879\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1avalues = [9,8,8,7,6], labels = [0,0,0,1,1], num_wanted = 3, use_limit = 2\n\u8f93\u51fa\uff1a24\n\u89e3\u91ca\uff1a\u9009\u51fa\u7684\u5b50\u96c6\u662f\u7b2c\u4e00\u9879\uff0c\u7b2c\u4e8c\u9879\u548c\u7b2c\u56db\u9879\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= values.length == labels.length <= 20000
  2. \n\t
  3. 0 <= values[i], labels[i] <= 20000
  4. \n\t
  5. 1 <= num_wanted, use_limit <= values.length
  6. \n
\n", "tags_en": ["Greedy", "Hash Table"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int largestValsFromLabels(vector& values, vector& labels, int num_wanted, int use_limit) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int largestValsFromLabels(int[] values, int[] labels, int num_wanted, int use_limit) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def largestValsFromLabels(self, values, labels, num_wanted, use_limit):\n \"\"\"\n :type values: List[int]\n :type labels: List[int]\n :type num_wanted: int\n :type use_limit: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def largestValsFromLabels(self, values: List[int], labels: List[int], num_wanted: int, use_limit: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint largestValsFromLabels(int* values, int valuesSize, int* labels, int labelsSize, int num_wanted, int use_limit){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LargestValsFromLabels(int[] values, int[] labels, int num_wanted, int use_limit) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} values\n * @param {number[]} labels\n * @param {number} num_wanted\n * @param {number} use_limit\n * @return {number}\n */\nvar largestValsFromLabels = function(values, labels, num_wanted, use_limit) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} values\n# @param {Integer[]} labels\n# @param {Integer} num_wanted\n# @param {Integer} use_limit\n# @return {Integer}\ndef largest_vals_from_labels(values, labels, num_wanted, use_limit)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func largestValsFromLabels(_ values: [Int], _ labels: [Int], _ num_wanted: Int, _ use_limit: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func largestValsFromLabels(values []int, labels []int, num_wanted int, use_limit int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def largestValsFromLabels(values: Array[Int], labels: Array[Int], num_wanted: Int, use_limit: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun largestValsFromLabels(values: IntArray, labels: IntArray, num_wanted: Int, use_limit: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn largest_vals_from_labels(values: Vec, labels: Vec, num_wanted: i32, use_limit: i32) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $values\n * @param Integer[] $labels\n * @param Integer $num_wanted\n * @param Integer $use_limit\n * @return Integer\n */\n function largestValsFromLabels($values, $labels, $num_wanted, $use_limit) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function largestValsFromLabels(values: number[], labels: number[], num_wanted: number, use_limit: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (largest-vals-from-labels values labels num_wanted use_limit)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1090](https://leetcode-cn.com/problems/largest-values-from-labels)", "[\u53d7\u6807\u7b7e\u5f71\u54cd\u7684\u6700\u5927\u503c](/solution/1000-1099/1090.Largest%20Values%20From%20Labels/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1090](https://leetcode.com/problems/largest-values-from-labels)", "[Largest Values From Labels](/solution/1000-1099/1090.Largest%20Values%20From%20Labels/README_EN.md)", "`Greedy`,`Hash Table`", "Medium", ""]}, {"question_id": "1168", "frontend_question_id": "1089", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/duplicate-zeros", "url_en": "https://leetcode.com/problems/duplicate-zeros", "relative_path_cn": "/solution/1000-1099/1089.Duplicate%20Zeros/README.md", "relative_path_en": "/solution/1000-1099/1089.Duplicate%20Zeros/README_EN.md", "title_cn": "\u590d\u5199\u96f6", "title_en": "Duplicate Zeros", "question_title_slug": "duplicate-zeros", "content_en": "

Given a fixed length array arr of integers, duplicate each occurrence of zero, shifting the remaining elements to the right.

\r\n\r\n

Note that elements beyond the length of the original array are not written.

\r\n\r\n

Do the above modifications to the input array in place, do not return anything from your function.

\r\n\r\n

 

\r\n\r\n

Example 1:

\r\n\r\n
\r\nInput: [1,0,2,3,0,4,5,0]\r\nOutput: null\r\nExplanation: After calling your function, the input array is modified to: [1,0,0,2,3,0,0,4]\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: [1,2,3]\r\nOutput: null\r\nExplanation: After calling your function, the input array is modified to: [1,2,3]\r\n
\r\n\r\n

 

\r\n\r\n

Note:

\r\n\r\n
    \r\n\t
  1. 1 <= arr.length <= 10000
  2. \r\n\t
  3. 0 <= arr[i] <= 9
  4. \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u56fa\u5b9a\u7684\u6574\u6570\u6570\u7ec4 arr\uff0c\u8bf7\u4f60\u5c06\u8be5\u6570\u7ec4\u4e2d\u51fa\u73b0\u7684\u6bcf\u4e2a\u96f6\u90fd\u590d\u5199\u4e00\u904d\uff0c\u5e76\u5c06\u5176\u4f59\u7684\u5143\u7d20\u5411\u53f3\u5e73\u79fb\u3002

\n\n

\u6ce8\u610f\uff1a\u8bf7\u4e0d\u8981\u5728\u8d85\u8fc7\u8be5\u6570\u7ec4\u957f\u5ea6\u7684\u4f4d\u7f6e\u5199\u5165\u5143\u7d20\u3002

\n\n

\u8981\u6c42\uff1a\u8bf7\u5bf9\u8f93\u5165\u7684\u6570\u7ec4 \u5c31\u5730 \u8fdb\u884c\u4e0a\u8ff0\u4fee\u6539\uff0c\u4e0d\u8981\u4ece\u51fd\u6570\u8fd4\u56de\u4efb\u4f55\u4e1c\u897f\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a[1,0,2,3,0,4,5,0]\n\u8f93\u51fa\uff1anull\n\u89e3\u91ca\uff1a\u8c03\u7528\u51fd\u6570\u540e\uff0c\u8f93\u5165\u7684\u6570\u7ec4\u5c06\u88ab\u4fee\u6539\u4e3a\uff1a[1,0,0,2,3,0,0,4]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a[1,2,3]\n\u8f93\u51fa\uff1anull\n\u89e3\u91ca\uff1a\u8c03\u7528\u51fd\u6570\u540e\uff0c\u8f93\u5165\u7684\u6570\u7ec4\u5c06\u88ab\u4fee\u6539\u4e3a\uff1a[1,2,3]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= arr.length <= 10000
  2. \n\t
  3. 0 <= arr[i] <= 9
  4. \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n void duplicateZeros(vector& arr) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public void duplicateZeros(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def duplicateZeros(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: None Do not return anything, modify arr in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def duplicateZeros(self, arr: List[int]) -> None:\n \"\"\"\n Do not return anything, modify arr in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nvoid duplicateZeros(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public void DuplicateZeros(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {void} Do not return anything, modify arr in-place instead.\n */\nvar duplicateZeros = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Void} Do not return anything, modify arr in-place instead.\ndef duplicate_zeros(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func duplicateZeros(_ arr: inout [Int]) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func duplicateZeros(arr []int) {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def duplicateZeros(arr: Array[Int]): Unit = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun duplicateZeros(arr: IntArray): Unit {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn duplicate_zeros(arr: &mut Vec) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return NULL\n */\n function duplicateZeros(&$arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n Do not return anything, modify arr in-place instead.\n */\nfunction duplicateZeros(arr: number[]): void {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1089](https://leetcode-cn.com/problems/duplicate-zeros)", "[\u590d\u5199\u96f6](/solution/1000-1099/1089.Duplicate%20Zeros/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1089](https://leetcode.com/problems/duplicate-zeros)", "[Duplicate Zeros](/solution/1000-1099/1089.Duplicate%20Zeros/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1167", "frontend_question_id": "1199", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/minimum-time-to-build-blocks", "url_en": "https://leetcode.com/problems/minimum-time-to-build-blocks", "relative_path_cn": "/solution/1100-1199/1199.Minimum%20Time%20to%20Build%20Blocks/README.md", "relative_path_en": "/solution/1100-1199/1199.Minimum%20Time%20to%20Build%20Blocks/README_EN.md", "title_cn": "\u5efa\u9020\u8857\u533a\u7684\u6700\u77ed\u65f6\u95f4", "title_en": "Minimum Time to Build Blocks", "question_title_slug": "minimum-time-to-build-blocks", "content_en": "

You are given a list of blocks, where blocks[i] = t means that the i-th block needs t units of time to be built. A block can only be built by exactly one worker.

\n\n

A worker can either split into two workers (number of workers increases by one) or build a block then go home. Both decisions cost some time.

\n\n

The time cost of spliting one worker into two workers is given as an integer split. Note that if two workers split at the same time, they split in parallel so the cost would be split.

\n\n

Output the minimum time needed to build all blocks.

\n\n

Initially, there is only one worker.

\n\n

 

\n

Example 1:

\n\n
\nInput: blocks = [1], split = 1\nOutput: 1\nExplanation: We use 1 worker to build 1 block in 1 time unit.\n
\n\n

Example 2:

\n\n
\nInput: blocks = [1,2], split = 5\nOutput: 7\nExplanation: We split the worker into 2 workers in 5 time units then assign each of them to a block so the cost is 5 + max(1, 2) = 7.\n
\n\n

Example 3:

\n\n
\nInput: blocks = [1,2,3], split = 1\nOutput: 4\nExplanation: Split 1 worker into 2, then assign the first worker to the last block and split the second worker into 2.\nThen, use the two unassigned workers to build the first two blocks.\nThe cost is 1 + max(3, 1 + max(1, 2)) = 4.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= blocks.length <= 1000
  • \n\t
  • 1 <= blocks[i] <= 10^5
  • \n\t
  • 1 <= split <= 100
  • \n
\n", "content_cn": "

\u4f60\u662f\u4e2a\u57ce\u5e02\u89c4\u5212\u5de5\u4f5c\u8005\uff0c\u624b\u91cc\u8d1f\u8d23\u7ba1\u8f96\u4e00\u7cfb\u5217\u7684\u8857\u533a\u3002\u5728\u8fd9\u4e2a\u8857\u533a\u5217\u8868\u4e2d blocks[i] = t \u610f\u5473\u7740\u7b2c  i \u4e2a\u8857\u533a\u9700\u8981 t \u4e2a\u5355\u4f4d\u7684\u65f6\u95f4\u6765\u5efa\u9020\u3002

\n\n

\u7531\u4e8e\u4e00\u4e2a\u8857\u533a\u53ea\u80fd\u7531\u4e00\u4e2a\u5de5\u4eba\u6765\u5b8c\u6210\u5efa\u9020\u3002

\n\n

\u6240\u4ee5\uff0c\u4e00\u4e2a\u5de5\u4eba\u8981\u4e48\u9700\u8981\u518d\u53ec\u5524\u4e00\u4e2a\u5de5\u4eba\uff08\u5de5\u4eba\u6570\u589e\u52a0 1\uff09\uff1b\u8981\u4e48\u5efa\u9020\u5b8c\u4e00\u4e2a\u8857\u533a\u540e\u56de\u5bb6\u3002\u8fd9\u4e24\u4e2a\u51b3\u5b9a\u90fd\u9700\u8981\u82b1\u8d39\u4e00\u5b9a\u7684\u65f6\u95f4\u3002

\n\n

\u4e00\u4e2a\u5de5\u4eba\u518d\u53ec\u5524\u4e00\u4e2a\u5de5\u4eba\u6240\u82b1\u8d39\u7684\u65f6\u95f4\u7531\u6574\u6570 split \u7ed9\u51fa\u3002

\n\n

\u6ce8\u610f\uff1a\u5982\u679c\u4e24\u4e2a\u5de5\u4eba\u540c\u65f6\u53ec\u5524\u522b\u7684\u5de5\u4eba\uff0c\u90a3\u4e48\u4ed6\u4eec\u7684\u884c\u4e3a\u662f\u5e76\u884c\u7684\uff0c\u6240\u4ee5\u65f6\u95f4\u82b1\u8d39\u4ecd\u7136\u662f split\u3002

\n\n

\u6700\u5f00\u59cb\u7684\u65f6\u5019\u53ea\u6709 \u4e00\u4e2a \u5de5\u4eba\uff0c\u8bf7\u4f60\u6700\u540e\u8f93\u51fa\u5efa\u9020\u5b8c\u6240\u6709\u8857\u533a\u6240\u9700\u8981\u7684\u6700\u5c11\u65f6\u95f4\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1ablocks = [1], split = 1\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u6211\u4eec\u4f7f\u7528 1 \u4e2a\u5de5\u4eba\u5728 1 \u4e2a\u65f6\u95f4\u5355\u4f4d\u5185\u6765\u5efa\u5b8c 1 \u4e2a\u8857\u533a\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1ablocks = [1,2], split = 5\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\u6211\u4eec\u7528 5 \u4e2a\u65f6\u95f4\u5355\u4f4d\u5c06\u8fd9\u4e2a\u5de5\u4eba\u5206\u88c2\u4e3a 2 \u4e2a\u5de5\u4eba\uff0c\u7136\u540e\u6307\u6d3e\u6bcf\u4e2a\u5de5\u4eba\u5206\u522b\u53bb\u5efa\u9020\u8857\u533a\uff0c\u4ece\u800c\u65f6\u95f4\u82b1\u8d39\u4e3a 5 + max(1, 2) = 7\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1ablocks = [1,2,3], split = 1\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\n\u5c06 1 \u4e2a\u5de5\u4eba\u5206\u88c2\u4e3a 2 \u4e2a\u5de5\u4eba\uff0c\u7136\u540e\u6307\u6d3e\u7b2c\u4e00\u4e2a\u5de5\u4eba\u53bb\u5efa\u9020\u6700\u540e\u4e00\u4e2a\u8857\u533a\uff0c\u5e76\u5c06\u7b2c\u4e8c\u4e2a\u5de5\u4eba\u5206\u88c2\u4e3a 2 \u4e2a\u5de5\u4eba\u3002\n\u7136\u540e\uff0c\u7528\u8fd9\u4e24\u4e2a\u672a\u5206\u6d3e\u7684\u5de5\u4eba\u5206\u522b\u53bb\u5efa\u9020\u524d\u4e24\u4e2a\u8857\u533a\u3002\n\u65f6\u95f4\u82b1\u8d39\u4e3a 1 + max(3, 1 + max(1, 2)) = 4\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= blocks.length <= 1000
  2. \n\t
  3. 1 <= blocks[i] <= 10^5
  4. \n\t
  5. 1 <= split <= 100
  6. \n
\n", "tags_en": ["Math", "Dynamic Programming"], "tags_cn": ["\u6570\u5b66", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minBuildTime(vector& blocks, int split) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minBuildTime(int[] blocks, int split) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minBuildTime(self, blocks, split):\n \"\"\"\n :type blocks: List[int]\n :type split: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minBuildTime(self, blocks: List[int], split: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minBuildTime(int* blocks, int blocksSize, int split){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinBuildTime(int[] blocks, int split) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} blocks\n * @param {number} split\n * @return {number}\n */\nvar minBuildTime = function(blocks, split) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} blocks\n# @param {Integer} split\n# @return {Integer}\ndef min_build_time(blocks, split)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minBuildTime(_ blocks: [Int], _ split: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minBuildTime(blocks []int, split int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minBuildTime(blocks: Array[Int], split: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minBuildTime(blocks: IntArray, split: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_build_time(blocks: Vec, split: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $blocks\n * @param Integer $split\n * @return Integer\n */\n function minBuildTime($blocks, $split) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minBuildTime(blocks: number[], split: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-build-time blocks split)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1199](https://leetcode-cn.com/problems/minimum-time-to-build-blocks)", "[\u5efa\u9020\u8857\u533a\u7684\u6700\u77ed\u65f6\u95f4](/solution/1100-1199/1199.Minimum%20Time%20to%20Build%20Blocks/README.md)", "`\u6570\u5b66`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1199](https://leetcode.com/problems/minimum-time-to-build-blocks)", "[Minimum Time to Build Blocks](/solution/1100-1199/1199.Minimum%20Time%20to%20Build%20Blocks/README_EN.md)", "`Math`,`Dynamic Programming`", "Hard", "\ud83d\udd12"]}, {"question_id": "1166", "frontend_question_id": "1230", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/toss-strange-coins", "url_en": "https://leetcode.com/problems/toss-strange-coins", "relative_path_cn": "/solution/1200-1299/1230.Toss%20Strange%20Coins/README.md", "relative_path_en": "/solution/1200-1299/1230.Toss%20Strange%20Coins/README_EN.md", "title_cn": "\u629b\u63b7\u786c\u5e01", "title_en": "Toss Strange Coins", "question_title_slug": "toss-strange-coins", "content_en": "

You have some coins.  The i-th coin has a probability prob[i] of facing heads when tossed.

\n\n

Return the probability that the number of coins facing heads equals target if you toss every coin exactly once.

\n\n

 

\n

Example 1:

\n
Input: prob = [0.4], target = 1\nOutput: 0.40000\n

Example 2:

\n
Input: prob = [0.5,0.5,0.5,0.5,0.5], target = 0\nOutput: 0.03125\n
\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= prob.length <= 1000
  • \n\t
  • 0 <= prob[i] <= 1
  • \n\t
  • 0 <= target <= prob.length
  • \n\t
  • Answers will be accepted as correct if they are within 10^-5 of the correct answer.
  • \n
\n", "content_cn": "

\u6709\u4e00\u4e9b\u4e0d\u89c4\u5219\u7684\u786c\u5e01\u3002\u5728\u8fd9\u4e9b\u786c\u5e01\u4e2d\uff0cprob[i] \u8868\u793a\u7b2c i \u679a\u786c\u5e01\u6b63\u9762\u671d\u4e0a\u7684\u6982\u7387\u3002

\n\n

\u8bf7\u5bf9\u6bcf\u4e00\u679a\u786c\u5e01\u629b\u63b7 \u4e00\u6b21\uff0c\u7136\u540e\u8fd4\u56de\u6b63\u9762\u671d\u4e0a\u7684\u786c\u5e01\u6570\u7b49\u4e8e target \u7684\u6982\u7387\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aprob = [0.4], target = 1\n\u8f93\u51fa\uff1a0.40000\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aprob = [0.5,0.5,0.5,0.5,0.5], target = 0\n\u8f93\u51fa\uff1a0.03125\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= prob.length <= 1000
  • \n\t
  • 0 <= prob[i] <= 1
  • \n\t
  • 0 <= target <= prob.length
  • \n\t
  • \u5982\u679c\u7b54\u6848\u4e0e\u6807\u51c6\u7b54\u6848\u7684\u8bef\u5dee\u5728 10^-5 \u5185\uff0c\u5219\u88ab\u89c6\u4e3a\u6b63\u786e\u7b54\u6848\u3002
  • \n
\n", "tags_en": ["Math", "Dynamic Programming"], "tags_cn": ["\u6570\u5b66", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n double probabilityOfHeads(vector& prob, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double probabilityOfHeads(double[] prob, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def probabilityOfHeads(self, prob, target):\n \"\"\"\n :type prob: List[float]\n :type target: int\n :rtype: float\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def probabilityOfHeads(self, prob: List[float], target: int) -> float:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\ndouble probabilityOfHeads(double* prob, int probSize, int target){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double ProbabilityOfHeads(double[] prob, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} prob\n * @param {number} target\n * @return {number}\n */\nvar probabilityOfHeads = function(prob, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Float[]} prob\n# @param {Integer} target\n# @return {Float}\ndef probability_of_heads(prob, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func probabilityOfHeads(_ prob: [Double], _ target: Int) -> Double {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func probabilityOfHeads(prob []float64, target int) float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def probabilityOfHeads(prob: Array[Double], target: Int): Double = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun probabilityOfHeads(prob: DoubleArray, target: Int): Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn probability_of_heads(prob: Vec, target: i32) -> f64 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Float[] $prob\n * @param Integer $target\n * @return Float\n */\n function probabilityOfHeads($prob, $target) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function probabilityOfHeads(prob: number[], target: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (probability-of-heads prob target)\n (-> (listof flonum?) exact-integer? flonum?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1230](https://leetcode-cn.com/problems/toss-strange-coins)", "[\u629b\u63b7\u786c\u5e01](/solution/1200-1299/1230.Toss%20Strange%20Coins/README.md)", "`\u6570\u5b66`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1230](https://leetcode.com/problems/toss-strange-coins)", "[Toss Strange Coins](/solution/1200-1299/1230.Toss%20Strange%20Coins/README_EN.md)", "`Math`,`Dynamic Programming`", "Medium", "\ud83d\udd12"]}, {"question_id": "1165", "frontend_question_id": "1229", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/meeting-scheduler", "url_en": "https://leetcode.com/problems/meeting-scheduler", "relative_path_cn": "/solution/1200-1299/1229.Meeting%20Scheduler/README.md", "relative_path_en": "/solution/1200-1299/1229.Meeting%20Scheduler/README_EN.md", "title_cn": "\u5b89\u6392\u4f1a\u8bae\u65e5\u7a0b", "title_en": "Meeting Scheduler", "question_title_slug": "meeting-scheduler", "content_en": "

Given the availability time slots arrays slots1 and slots2 of two people and a meeting duration duration, return the earliest time slot that works for both of them and is of duration duration.

\n\n

If there is no common time slot that satisfies the requirements, return an empty array.

\n\n

The format of a time slot is an array of two elements [start, end] representing an inclusive time range from start to end.

\n\n

It is guaranteed that no two availability slots of the same person intersect with each other. That is, for any two time slots [start1, end1] and [start2, end2] of the same person, either start1 > end2 or start2 > end1.

\n\n

 

\n

Example 1:

\n\n
\nInput: slots1 = [[10,50],[60,120],[140,210]], slots2 = [[0,15],[60,70]], duration = 8\nOutput: [60,68]\n
\n\n

Example 2:

\n\n
\nInput: slots1 = [[10,50],[60,120],[140,210]], slots2 = [[0,15],[60,70]], duration = 12\nOutput: []\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= slots1.length, slots2.length <= 104
  • \n\t
  • slots1[i].length, slots2[i].length == 2
  • \n\t
  • slots1[i][0] < slots1[i][1]
  • \n\t
  • slots2[i][0] < slots2[i][1]
  • \n\t
  • 0 <= slots1[i][j], slots2[i][j] <= 109
  • \n\t
  • 1 <= duration <= 106
  • \n
\n", "content_cn": "

\u4f60\u662f\u4e00\u540d\u884c\u653f\u52a9\u7406\uff0c\u624b\u91cc\u6709\u4e24\u4f4d\u5ba2\u6237\u7684\u7a7a\u95f2\u65f6\u95f4\u8868\uff1aslots1 \u548c slots2\uff0c\u4ee5\u53ca\u4f1a\u8bae\u7684\u9884\u8ba1\u6301\u7eed\u65f6\u95f4 duration\uff0c\u8bf7\u4f60\u4e3a\u4ed6\u4eec\u5b89\u6392\u5408\u9002\u7684\u4f1a\u8bae\u65f6\u95f4\u3002

\n\n

\u300c\u4f1a\u8bae\u65f6\u95f4\u300d\u662f\u4e24\u4f4d\u5ba2\u6237\u90fd\u6709\u7a7a\u53c2\u52a0\uff0c\u5e76\u4e14\u6301\u7eed\u65f6\u95f4\u80fd\u591f\u6ee1\u8db3\u9884\u8ba1\u65f6\u95f4 duration \u7684 \u6700\u65e9\u7684\u65f6\u95f4\u95f4\u9694\u3002

\n\n

\u5982\u679c\u6ca1\u6709\u6ee1\u8db3\u8981\u6c42\u7684\u4f1a\u8bae\u65f6\u95f4\uff0c\u5c31\u8bf7\u8fd4\u56de\u4e00\u4e2a \u7a7a\u6570\u7ec4\u3002

\n\n

 

\n\n

\u300c\u7a7a\u95f2\u65f6\u95f4\u300d\u7684\u683c\u5f0f\u662f [start, end]\uff0c\u7531\u5f00\u59cb\u65f6\u95f4 start \u548c\u7ed3\u675f\u65f6\u95f4 end \u7ec4\u6210\uff0c\u8868\u793a\u4ece start \u5f00\u59cb\uff0c\u5230 end \u7ed3\u675f\u3002 

\n\n

\u9898\u76ee\u4fdd\u8bc1\u6570\u636e\u6709\u6548\uff1a\u540c\u4e00\u4e2a\u4eba\u7684\u7a7a\u95f2\u65f6\u95f4\u4e0d\u4f1a\u51fa\u73b0\u4ea4\u53e0\u7684\u60c5\u51b5\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u5bf9\u4e8e\u540c\u4e00\u4e2a\u4eba\u7684\u4e24\u4e2a\u7a7a\u95f2\u65f6\u95f4 [start1, end1] \u548c [start2, end2]\uff0c\u8981\u4e48 start1 > end2\uff0c\u8981\u4e48 start2 > end1\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aslots1 = [[10,50],[60,120],[140,210]], slots2 = [[0,15],[60,70]], duration = 8\n\u8f93\u51fa\uff1a[60,68]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aslots1 = [[10,50],[60,120],[140,210]], slots2 = [[0,15],[60,70]], duration = 12\n\u8f93\u51fa\uff1a[]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= slots1.length, slots2.length <= 10^4
  • \n\t
  • slots1[i].length, slots2[i].length == 2
  • \n\t
  • slots1[i][0] < slots1[i][1]
  • \n\t
  • slots2[i][0] < slots2[i][1]
  • \n\t
  • 0 <= slots1[i][j], slots2[i][j] <= 10^9
  • \n\t
  • 1 <= duration <= 10^6 
  • \n
\n", "tags_en": ["Sort", "Two Pointers", "Line Sweep"], "tags_cn": ["\u6392\u5e8f", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector minAvailableDuration(vector>& slots1, vector>& slots2, int duration) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List minAvailableDuration(int[][] slots1, int[][] slots2, int duration) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minAvailableDuration(self, slots1, slots2, duration):\n \"\"\"\n :type slots1: List[List[int]]\n :type slots2: List[List[int]]\n :type duration: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minAvailableDuration(self, slots1: List[List[int]], slots2: List[List[int]], duration: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* minAvailableDuration(int** slots1, int slots1Size, int* slots1ColSize, int** slots2, int slots2Size, int* slots2ColSize, int duration, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList MinAvailableDuration(int[][] slots1, int[][] slots2, int duration) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} slots1\n * @param {number[][]} slots2\n * @param {number} duration\n * @return {number[]}\n */\nvar minAvailableDuration = function(slots1, slots2, duration) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} slots1\n# @param {Integer[][]} slots2\n# @param {Integer} duration\n# @return {Integer[]}\ndef min_available_duration(slots1, slots2, duration)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minAvailableDuration(_ slots1: [[Int]], _ slots2: [[Int]], _ duration: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minAvailableDuration(slots1 [][]int, slots2 [][]int, duration int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minAvailableDuration(slots1: Array[Array[Int]], slots2: Array[Array[Int]], duration: Int): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minAvailableDuration(slots1: Array, slots2: Array, duration: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_available_duration(slots1: Vec>, slots2: Vec>, duration: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $slots1\n * @param Integer[][] $slots2\n * @param Integer $duration\n * @return Integer[]\n */\n function minAvailableDuration($slots1, $slots2, $duration) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minAvailableDuration(slots1: number[][], slots2: number[][], duration: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-available-duration slots1 slots2 duration)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1229](https://leetcode-cn.com/problems/meeting-scheduler)", "[\u5b89\u6392\u4f1a\u8bae\u65e5\u7a0b](/solution/1200-1299/1229.Meeting%20Scheduler/README.md)", "`\u6392\u5e8f`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1229](https://leetcode.com/problems/meeting-scheduler)", "[Meeting Scheduler](/solution/1200-1299/1229.Meeting%20Scheduler/README_EN.md)", "`Sort`,`Two Pointers`,`Line Sweep`", "Medium", "\ud83d\udd12"]}, {"question_id": "1164", "frontend_question_id": "1228", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/missing-number-in-arithmetic-progression", "url_en": "https://leetcode.com/problems/missing-number-in-arithmetic-progression", "relative_path_cn": "/solution/1200-1299/1228.Missing%20Number%20In%20Arithmetic%20Progression/README.md", "relative_path_en": "/solution/1200-1299/1228.Missing%20Number%20In%20Arithmetic%20Progression/README_EN.md", "title_cn": "\u7b49\u5dee\u6570\u5217\u4e2d\u7f3a\u5931\u7684\u6570\u5b57", "title_en": "Missing Number In Arithmetic Progression", "question_title_slug": "missing-number-in-arithmetic-progression", "content_en": "

In some array arr, the values were in arithmetic progression: the values arr[i + 1] - arr[i] are all equal for every 0 <= i < arr.length - 1.

\n\n

A value from arr was removed that was not the first or last value in the array.

\n\n

Given arr, return the removed value.

\n\n

 

\n

Example 1:

\n\n
\nInput: arr = [5,7,11,13]\nOutput: 9\nExplanation: The previous array was [5,7,9,11,13].\n
\n\n

Example 2:

\n\n
\nInput: arr = [15,13,12]\nOutput: 14\nExplanation: The previous array was [15,14,13,12].
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 3 <= arr.length <= 1000
  • \n\t
  • 0 <= arr[i] <= 105
  • \n\t
  • The given array is guaranteed to be a valid array.
  • \n
\n", "content_cn": "

\u6709\u4e00\u4e2a\u6570\u7ec4\uff0c\u5176\u4e2d\u7684\u503c\u7b26\u5408\u7b49\u5dee\u6570\u5217\u7684\u6570\u503c\u89c4\u5f8b\uff0c\u4e5f\u5c31\u662f\u8bf4\uff1a

\n\n
    \n\t
  • \u5728 0 <= i < arr.length - 1 \u7684\u524d\u63d0\u4e0b\uff0carr[i+1] - arr[i] \u7684\u503c\u90fd\u76f8\u7b49\u3002
  • \n
\n\n

\u6211\u4eec\u4f1a\u4ece\u8be5\u6570\u7ec4\u4e2d\u5220\u9664\u4e00\u4e2a \u65e2\u4e0d\u662f\u7b2c\u4e00\u4e2a \u4e5f \u4e0d\u662f\u6700\u540e\u4e00\u4e2a\u7684\u503c\uff0c\u5f97\u5230\u4e00\u4e2a\u65b0\u7684\u6570\u7ec4  arr\u3002

\n\n

\u7ed9\u4f60\u8fd9\u4e2a\u7f3a\u503c\u7684\u6570\u7ec4 arr\uff0c\u8bf7\u4f60\u5e2e\u5fd9\u627e\u51fa\u88ab\u5220\u9664\u7684\u90a3\u4e2a\u6570\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aarr = [5,7,11,13]\n\u8f93\u51fa\uff1a9\n\u89e3\u91ca\uff1a\u539f\u6765\u7684\u6570\u7ec4\u662f [5,7,9,11,13]\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aarr = [15,13,12]\n\u8f93\u51fa\uff1a14\n\u89e3\u91ca\uff1a\u539f\u6765\u7684\u6570\u7ec4\u662f [15,14,13,12]\u3002
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 3 <= arr.length <= 1000
  • \n\t
  • 0 <= arr[i] <= 10^5
  • \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int missingNumber(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int missingNumber(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def missingNumber(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def missingNumber(self, arr: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint missingNumber(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MissingNumber(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar missingNumber = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef missing_number(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func missingNumber(_ arr: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func missingNumber(arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def missingNumber(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun missingNumber(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn missing_number(arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function missingNumber($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function missingNumber(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (missing-number arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1228](https://leetcode-cn.com/problems/missing-number-in-arithmetic-progression)", "[\u7b49\u5dee\u6570\u5217\u4e2d\u7f3a\u5931\u7684\u6570\u5b57](/solution/1200-1299/1228.Missing%20Number%20In%20Arithmetic%20Progression/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1228](https://leetcode.com/problems/missing-number-in-arithmetic-progression)", "[Missing Number In Arithmetic Progression](/solution/1200-1299/1228.Missing%20Number%20In%20Arithmetic%20Progression/README_EN.md)", "`Math`", "Easy", "\ud83d\udd12"]}, {"question_id": "1163", "frontend_question_id": "1077", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/project-employees-iii", "url_en": "https://leetcode.com/problems/project-employees-iii", "relative_path_cn": "/solution/1000-1099/1077.Project%20Employees%20III/README.md", "relative_path_en": "/solution/1000-1099/1077.Project%20Employees%20III/README_EN.md", "title_cn": "\u9879\u76ee\u5458\u5de5 III", "title_en": "Project Employees III", "question_title_slug": "project-employees-iii", "content_en": "

Table: Project

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| project_id  | int     |\n| employee_id | int     |\n+-------------+---------+\n(project_id, employee_id) is the primary key of this table.\nemployee_id is a foreign key to Employee table.\n
\n\n

Table: Employee

\n\n
\n+------------------+---------+\n| Column Name      | Type    |\n+------------------+---------+\n| employee_id      | int     |\n| name             | varchar |\n| experience_years | int     |\n+------------------+---------+\nemployee_id is the primary key of this table.\n
\n\n

 

\n\n

Write an SQL query that reports the most experienced employees in each project. In case of a tie, report all employees with the maximum number of experience years.

\n\n

The query result format is in the following example:

\n\n
\nProject table:\n+-------------+-------------+\n| project_id  | employee_id |\n+-------------+-------------+\n| 1           | 1           |\n| 1           | 2           |\n| 1           | 3           |\n| 2           | 1           |\n| 2           | 4           |\n+-------------+-------------+\n\nEmployee table:\n+-------------+--------+------------------+\n| employee_id | name   | experience_years |\n+-------------+--------+------------------+\n| 1           | Khaled | 3                |\n| 2           | Ali    | 2                |\n| 3           | John   | 3                |\n| 4           | Doe    | 2                |\n+-------------+--------+------------------+\n\nResult table:\n+-------------+---------------+\n| project_id  | employee_id   |\n+-------------+---------------+\n| 1           | 1             |\n| 1           | 3             |\n| 2           | 1             |\n+-------------+---------------+\nBoth employees with id 1 and 3 have the most experience among the employees of the first project. For the second project, the employee with id 1 has the most experience.
\n", "content_cn": "

\u9879\u76ee\u8868 Project\uff1a

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| project_id  | int     |\n| employee_id | int     |\n+-------------+---------+\n(project_id, employee_id) \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\nemployee_id \u662f\u5458\u5de5\u8868 Employee \u7684\u5916\u952e\n
\n\n

\u5458\u5de5\u8868 Employee\uff1a

\n\n
\n+------------------+---------+\n| Column Name      | Type    |\n+------------------+---------+\n| employee_id      | int     |\n| name             | varchar |\n| experience_years | int     |\n+------------------+---------+\nemployee_id \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\n
\n\n

 

\n\n

\u5199 \u4e00\u4e2a SQL \u67e5\u8be2\u8bed\u53e5\uff0c\u62a5\u544a\u5728\u6bcf\u4e00\u4e2a\u9879\u76ee\u4e2d\u7ecf\u9a8c\u6700\u4e30\u5bcc\u7684\u96c7\u5458\u662f\u8c01\u3002\u5982\u679c\u51fa\u73b0\u7ecf\u9a8c\u5e74\u6570\u76f8\u540c\u7684\u60c5\u51b5\uff0c\u8bf7\u62a5\u544a\u6240\u6709\u5177\u6709\u6700\u5927\u7ecf\u9a8c\u5e74\u6570\u7684\u5458\u5de5\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5728\u4ee5\u4e0b\u793a\u4f8b\u4e2d\uff1a

\n\n
\nProject \u8868\uff1a\n+-------------+-------------+\n| project_id  | employee_id |\n+-------------+-------------+\n| 1           | 1           |\n| 1           | 2           |\n| 1           | 3           |\n| 2           | 1           |\n| 2           | 4           |\n+-------------+-------------+\n\nEmployee \u8868\uff1a\n+-------------+--------+------------------+\n| employee_id | name   | experience_years |\n+-------------+--------+------------------+\n| 1           | Khaled | 3                |\n| 2           | Ali    | 2                |\n| 3           | John   | 3                |\n| 4           | Doe    | 2                |\n+-------------+--------+------------------+\n\nResult \u8868\uff1a\n+-------------+---------------+\n| project_id  | employee_id   |\n+-------------+---------------+\n| 1           | 1             |\n| 1           | 3             |\n| 2           | 1             |\n+-------------+---------------+\nemployee_id \u4e3a 1 \u548c 3 \u7684\u5458\u5de5\u5728 project_id \u4e3a 1 \u7684\u9879\u76ee\u4e2d\u62e5\u6709\u6700\u4e30\u5bcc\u7684\u7ecf\u9a8c\u3002\u5728 project_id \u4e3a 2 \u7684\u9879\u76ee\u4e2d\uff0cemployee_id \u4e3a 1 \u7684\u5458\u5de5\u62e5\u6709\u6700\u4e30\u5bcc\u7684\u7ecf\u9a8c\u3002
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1077](https://leetcode-cn.com/problems/project-employees-iii)", "[\u9879\u76ee\u5458\u5de5 III](/solution/1000-1099/1077.Project%20Employees%20III/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1077](https://leetcode.com/problems/project-employees-iii)", "[Project Employees III](/solution/1000-1099/1077.Project%20Employees%20III/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1162", "frontend_question_id": "1076", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/project-employees-ii", "url_en": "https://leetcode.com/problems/project-employees-ii", "relative_path_cn": "/solution/1000-1099/1076.Project%20Employees%20II/README.md", "relative_path_en": "/solution/1000-1099/1076.Project%20Employees%20II/README_EN.md", "title_cn": "\u9879\u76ee\u5458\u5de5II", "title_en": "Project Employees II", "question_title_slug": "project-employees-ii", "content_en": "

Table: Project

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| project_id  | int     |\n| employee_id | int     |\n+-------------+---------+\n(project_id, employee_id) is the primary key of this table.\nemployee_id is a foreign key to Employee table.\n
\n\n

 

\n\n

Table: Employee

\n\n
\n+------------------+---------+\n| Column Name      | Type    |\n+------------------+---------+\n| employee_id      | int     |\n| name             | varchar |\n| experience_years | int     |\n+------------------+---------+\nemployee_id is the primary key of this table.\n
\n\n

 

\n\n

Write an SQL query that reports all the projects that have the most employees.

\n\n

The query result format is in the following example:

\n\n

 

\n\n
\nProject table:\n+-------------+-------------+\n| project_id  | employee_id |\n+-------------+-------------+\n| 1           | 1           |\n| 1           | 2           |\n| 1           | 3           |\n| 2           | 1           |\n| 2           | 4           |\n+-------------+-------------+\n\nEmployee table:\n+-------------+--------+------------------+\n| employee_id | name   | experience_years |\n+-------------+--------+------------------+\n| 1           | Khaled | 3                |\n| 2           | Ali    | 2                |\n| 3           | John   | 1                |\n| 4           | Doe    | 2                |\n+-------------+--------+------------------+\n\nResult table:\n+-------------+\n| project_id  |\n+-------------+\n| 1           |\n+-------------+\nThe first project has 3 employees while the second one has 2.
\n", "content_cn": "

Table: Project

\n\n
+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| project_id  | int     |\n| employee_id | int     |\n+-------------+---------+\n\u4e3b\u952e\u4e3a (project_id, employee_id)\u3002\nemployee_id \u662f\u5458\u5de5\u8868 Employee \u8868\u7684\u5916\u952e\u3002\n
\n\n

Table: Employee

\n\n
+------------------+---------+\n| Column Name      | Type    |\n+------------------+---------+\n| employee_id      | int     |\n| name             | varchar |\n| experience_years | int     |\n+------------------+---------+\n\u4e3b\u952e\u662f employee_id\u3002
\n\n

 

\n\n

\u7f16\u5199\u4e00\u4e2aSQL\u67e5\u8be2\uff0c\u62a5\u544a\u6240\u6709\u96c7\u5458\u6700\u591a\u7684\u9879\u76ee\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u6240\u793a\uff1a

\n\n
Project table:\n+-------------+-------------+\n| project_id  | employee_id |\n+-------------+-------------+\n| 1           | 1           |\n| 1           | 2           |\n| 1           | 3           |\n| 2           | 1           |\n| 2           | 4           |\n+-------------+-------------+\n\nEmployee table:\n+-------------+--------+------------------+\n| employee_id | name   | experience_years |\n+-------------+--------+------------------+\n| 1           | Khaled | 3                |\n| 2           | Ali    | 2                |\n| 3           | John   | 1                |\n| 4           | Doe    | 2                |\n+-------------+--------+------------------+\n\nResult table:\n+-------------+\n| project_id  |\n+-------------+\n| 1           |\n+-------------+\n\u7b2c\u4e00\u4e2a\u9879\u76ee\u67093\u540d\u5458\u5de5\uff0c\u7b2c\u4e8c\u4e2a\u9879\u76ee\u67092\u540d\u5458\u5de5\u3002
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1076](https://leetcode-cn.com/problems/project-employees-ii)", "[\u9879\u76ee\u5458\u5de5II](/solution/1000-1099/1076.Project%20Employees%20II/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1076](https://leetcode.com/problems/project-employees-ii)", "[Project Employees II](/solution/1000-1099/1076.Project%20Employees%20II/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1161", "frontend_question_id": "1075", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/project-employees-i", "url_en": "https://leetcode.com/problems/project-employees-i", "relative_path_cn": "/solution/1000-1099/1075.Project%20Employees%20I/README.md", "relative_path_en": "/solution/1000-1099/1075.Project%20Employees%20I/README_EN.md", "title_cn": "\u9879\u76ee\u5458\u5de5 I", "title_en": "Project Employees I", "question_title_slug": "project-employees-i", "content_en": "

Table: Project

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| project_id  | int     |\n| employee_id | int     |\n+-------------+---------+\n(project_id, employee_id) is the primary key of this table.\nemployee_id is a foreign key to Employee table.\n
\n\n

Table: Employee

\n\n
\n+------------------+---------+\n| Column Name      | Type    |\n+------------------+---------+\n| employee_id      | int     |\n| name             | varchar |\n| experience_years | int     |\n+------------------+---------+\nemployee_id is the primary key of this table.\n
\n\n

 

\n\n

Write an SQL query that reports the average experience years of all the employees for each project, rounded to 2 digits.

\n\n

The query result format is in the following example:

\n\n
\nProject table:\n+-------------+-------------+\n| project_id  | employee_id |\n+-------------+-------------+\n| 1           | 1           |\n| 1           | 2           |\n| 1           | 3           |\n| 2           | 1           |\n| 2           | 4           |\n+-------------+-------------+\n\nEmployee table:\n+-------------+--------+------------------+\n| employee_id | name   | experience_years |\n+-------------+--------+------------------+\n| 1           | Khaled | 3                |\n| 2           | Ali    | 2                |\n| 3           | John   | 1                |\n| 4           | Doe    | 2                |\n+-------------+--------+------------------+\n\nResult table:\n+-------------+---------------+\n| project_id  | average_years |\n+-------------+---------------+\n| 1           | 2.00          |\n| 2           | 2.50          |\n+-------------+---------------+\nThe average experience years for the first project is (3 + 2 + 1) / 3 = 2.00 and for the second project is (3 + 2) / 2 = 2.50\n
\n", "content_cn": "

\u9879\u76ee\u8868 Project\uff1a 

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| project_id  | int     |\n| employee_id | int     |\n+-------------+---------+\n\u4e3b\u952e\u4e3a (project_id, employee_id)\u3002\nemployee_id \u662f\u5458\u5de5\u8868 Employee \u8868\u7684\u5916\u952e\u3002\n
\n\n

\u5458\u5de5\u8868 Employee\uff1a

\n\n
\n+------------------+---------+\n| Column Name      | Type    |\n+------------------+---------+\n| employee_id      | int     |\n| name             | varchar |\n| experience_years | int     |\n+------------------+---------+\n\u4e3b\u952e\u662f employee_id\u3002\n
\n\n

 

\n\n

\u8bf7\u5199\u4e00\u4e2a SQL \u8bed\u53e5\uff0c\u67e5\u8be2\u6bcf\u4e00\u4e2a\u9879\u76ee\u4e2d\u5458\u5de5\u7684 \u5e73\u5747 \u5de5\u4f5c\u5e74\u9650\uff0c\u7cbe\u786e\u5230\u5c0f\u6570\u70b9\u540e\u4e24\u4f4d\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u7684\u683c\u5f0f\u5982\u4e0b\uff1a

\n\n
\nProject \u8868\uff1a\n+-------------+-------------+\n| project_id  | employee_id |\n+-------------+-------------+\n| 1           | 1           |\n| 1           | 2           |\n| 1           | 3           |\n| 2           | 1           |\n| 2           | 4           |\n+-------------+-------------+\n\nEmployee \u8868\uff1a\n+-------------+--------+------------------+\n| employee_id | name   | experience_years |\n+-------------+--------+------------------+\n| 1           | Khaled | 3                |\n| 2           | Ali    | 2                |\n| 3           | John   | 1                |\n| 4           | Doe    | 2                |\n+-------------+--------+------------------+\n\nResult \u8868\uff1a\n+-------------+---------------+\n| project_id  | average_years |\n+-------------+---------------+\n| 1           | 2.00          |\n| 2           | 2.50          |\n+-------------+---------------+\n\u7b2c\u4e00\u4e2a\u9879\u76ee\u4e2d\uff0c\u5458\u5de5\u7684\u5e73\u5747\u5de5\u4f5c\u5e74\u9650\u662f (3 + 2 + 1) / 3 = 2.00\uff1b\u7b2c\u4e8c\u4e2a\u9879\u76ee\u4e2d\uff0c\u5458\u5de5\u7684\u5e73\u5747\u5de5\u4f5c\u5e74\u9650\u662f (3 + 2) / 2 = 2.50\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1075](https://leetcode-cn.com/problems/project-employees-i)", "[\u9879\u76ee\u5458\u5de5 I](/solution/1000-1099/1075.Project%20Employees%20I/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1075](https://leetcode.com/problems/project-employees-i)", "[Project Employees I](/solution/1000-1099/1075.Project%20Employees%20I/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1160", "frontend_question_id": "1079", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/letter-tile-possibilities", "url_en": "https://leetcode.com/problems/letter-tile-possibilities", "relative_path_cn": "/solution/1000-1099/1079.Letter%20Tile%20Possibilities/README.md", "relative_path_en": "/solution/1000-1099/1079.Letter%20Tile%20Possibilities/README_EN.md", "title_cn": "\u6d3b\u5b57\u5370\u5237", "title_en": "Letter Tile Possibilities", "question_title_slug": "letter-tile-possibilities", "content_en": "

You have n  tiles, where each tile has one letter tiles[i] printed on it.

\n\n

Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.

\n\n

 

\n

Example 1:

\n\n
\nInput: tiles = "AAB"\nOutput: 8\nExplanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA".\n
\n\n

Example 2:

\n\n
\nInput: tiles = "AAABBC"\nOutput: 188\n
\n\n

Example 3:

\n\n
\nInput: tiles = "V"\nOutput: 1\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= tiles.length <= 7
  • \n\t
  • tiles consists of uppercase English letters.
  • \n
\n", "content_cn": "

\u4f60\u6709\u4e00\u5957\u6d3b\u5b57\u5b57\u6a21 tiles\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5b57\u6a21\u4e0a\u90fd\u523b\u6709\u4e00\u4e2a\u5b57\u6bcd tiles[i]\u3002\u8fd4\u56de\u4f60\u53ef\u4ee5\u5370\u51fa\u7684\u975e\u7a7a\u5b57\u6bcd\u5e8f\u5217\u7684\u6570\u76ee\u3002

\n\n

\u6ce8\u610f\uff1a\u672c\u9898\u4e2d\uff0c\u6bcf\u4e2a\u6d3b\u5b57\u5b57\u6a21\u53ea\u80fd\u4f7f\u7528\u4e00\u6b21\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a"AAB"\n\u8f93\u51fa\uff1a8\n\u89e3\u91ca\uff1a\u53ef\u80fd\u7684\u5e8f\u5217\u4e3a "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA"\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a"AAABBC"\n\u8f93\u51fa\uff1a188\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= tiles.length <= 7
  2. \n\t
  3. tiles \u7531\u5927\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
  4. \n
\n", "tags_en": ["Backtracking"], "tags_cn": ["\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numTilePossibilities(string tiles) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numTilePossibilities(String tiles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numTilePossibilities(self, tiles):\n \"\"\"\n :type tiles: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numTilePossibilities(self, tiles: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numTilePossibilities(char * tiles){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumTilePossibilities(string tiles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} tiles\n * @return {number}\n */\nvar numTilePossibilities = function(tiles) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} tiles\n# @return {Integer}\ndef num_tile_possibilities(tiles)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numTilePossibilities(_ tiles: String) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numTilePossibilities(tiles string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numTilePossibilities(tiles: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numTilePossibilities(tiles: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_tile_possibilities(tiles: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $tiles\n * @return Integer\n */\n function numTilePossibilities($tiles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numTilePossibilities(tiles: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-tile-possibilities tiles)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1079](https://leetcode-cn.com/problems/letter-tile-possibilities)", "[\u6d3b\u5b57\u5370\u5237](/solution/1000-1099/1079.Letter%20Tile%20Possibilities/README.md)", "`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1079](https://leetcode.com/problems/letter-tile-possibilities)", "[Letter Tile Possibilities](/solution/1000-1099/1079.Letter%20Tile%20Possibilities/README_EN.md)", "`Backtracking`", "Medium", ""]}, {"question_id": "1159", "frontend_question_id": "1081", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/smallest-subsequence-of-distinct-characters", "url_en": "https://leetcode.com/problems/smallest-subsequence-of-distinct-characters", "relative_path_cn": "/solution/1000-1099/1081.Smallest%20Subsequence%20of%20Distinct%20Characters/README.md", "relative_path_en": "/solution/1000-1099/1081.Smallest%20Subsequence%20of%20Distinct%20Characters/README_EN.md", "title_cn": "\u4e0d\u540c\u5b57\u7b26\u7684\u6700\u5c0f\u5b50\u5e8f\u5217", "title_en": "Smallest Subsequence of Distinct Characters", "question_title_slug": "smallest-subsequence-of-distinct-characters", "content_en": "

Return the lexicographically smallest subsequence of s that contains all the distinct characters of s exactly once.

\n\n

Note: This question is the same as 316: https://leetcode.com/problems/remove-duplicate-letters/

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "bcabc"\nOutput: "abc"\n
\n\n

Example 2:

\n\n
\nInput: s = "cbacdcbc"\nOutput: "acdb"\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 1000
  • \n\t
  • s consists of lowercase English letters.
  • \n
\n", "content_cn": "

\u8fd4\u56de s \u5b57\u5178\u5e8f\u6700\u5c0f\u7684\u5b50\u5e8f\u5217\uff0c\u8be5\u5b50\u5e8f\u5217\u5305\u542b s \u7684\u6240\u6709\u4e0d\u540c\u5b57\u7b26\uff0c\u4e14\u53ea\u5305\u542b\u4e00\u6b21\u3002

\n\n

\u6ce8\u610f\uff1a\u8be5\u9898\u4e0e 316 https://leetcode.com/problems/remove-duplicate-letters/ \u76f8\u540c

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"bcabc\"\n\u8f93\u51fa\uff1a\"abc\"\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"cbacdcbc\"\n\u8f93\u51fa\uff1a\"acdb\"
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length <= 1000
  • \n\t
  • s \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
  • \n
\n", "tags_en": ["Stack", "Greedy", "String"], "tags_cn": ["\u6808", "\u8d2a\u5fc3\u7b97\u6cd5", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string smallestSubsequence(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String smallestSubsequence(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def smallestSubsequence(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def smallestSubsequence(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * smallestSubsequence(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string SmallestSubsequence(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar smallestSubsequence = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef smallest_subsequence(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func smallestSubsequence(_ s: String) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func smallestSubsequence(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def smallestSubsequence(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun smallestSubsequence(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn smallest_subsequence(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function smallestSubsequence($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function smallestSubsequence(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (smallest-subsequence s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1081](https://leetcode-cn.com/problems/smallest-subsequence-of-distinct-characters)", "[\u4e0d\u540c\u5b57\u7b26\u7684\u6700\u5c0f\u5b50\u5e8f\u5217](/solution/1000-1099/1081.Smallest%20Subsequence%20of%20Distinct%20Characters/README.md)", "`\u6808`,`\u8d2a\u5fc3\u7b97\u6cd5`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1081](https://leetcode.com/problems/smallest-subsequence-of-distinct-characters)", "[Smallest Subsequence of Distinct Characters](/solution/1000-1099/1081.Smallest%20Subsequence%20of%20Distinct%20Characters/README_EN.md)", "`Stack`,`Greedy`,`String`", "Medium", ""]}, {"question_id": "1157", "frontend_question_id": "1080", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/insufficient-nodes-in-root-to-leaf-paths", "url_en": "https://leetcode.com/problems/insufficient-nodes-in-root-to-leaf-paths", "relative_path_cn": "/solution/1000-1099/1080.Insufficient%20Nodes%20in%20Root%20to%20Leaf%20Paths/README.md", "relative_path_en": "/solution/1000-1099/1080.Insufficient%20Nodes%20in%20Root%20to%20Leaf%20Paths/README_EN.md", "title_cn": "\u6839\u5230\u53f6\u8def\u5f84\u4e0a\u7684\u4e0d\u8db3\u8282\u70b9", "title_en": "Insufficient Nodes in Root to Leaf Paths", "question_title_slug": "insufficient-nodes-in-root-to-leaf-paths", "content_en": "

Given the root of a binary tree, consider all root to leaf paths: paths from the root to any leaf.  (A leaf is a node with no children.)

\r\n\r\n

A node is insufficient if every such root to leaf path intersecting this node has sum strictly less than limit.

\r\n\r\n

Delete all insufficient nodes simultaneously, and return the root of the resulting binary tree.

\r\n\r\n

 

\r\n\r\n

Example 1:

\r\n\r\n
\r\n\"\"\r\nInput: root = [1,2,3,4,-99,-99,7,8,9,-99,-99,12,13,-99,14], limit = 1\r\n\"\"\r\nOutput: [1,2,3,4,null,null,7,8,9,null,14]\r\n
\r\n\r\n
\r\n

Example 2:

\r\n\r\n
\r\n\"\"\r\nInput: root = [5,4,8,11,null,17,4,7,1,null,null,5,3], limit = 22\r\n\"\"\r\nOutput: [5,4,8,11,null,17,4,7,null,null,null,5]
\r\n\r\n

 

\r\n\r\n

Example 3:

\r\n\r\n
\r\n\"\"\r\nInput: root = [1,2,-3,-5,null,4,null], limit = -1\r\n\"\"\r\nOutput: [1,null,-3,4]
\r\n
\r\n\r\n

 

\r\n\r\n

Note:

\r\n\r\n
    \r\n\t
  1. The given tree will have between 1 and 5000 nodes.
  2. \r\n\t
  3. -10^5 <= node.val <= 10^5
  4. \r\n\t
  5. -10^9 <= limit <= 10^9
  6. \r\n
\r\n\r\n
\r\n
 
\r\n
\r\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u68f5\u4e8c\u53c9\u6811\u7684\u6839 root\uff0c\u8bf7\u4f60\u8003\u8651\u5b83\u6240\u6709 \u4ece\u6839\u5230\u53f6\u7684\u8def\u5f84\uff1a\u4ece\u6839\u5230\u4efb\u4f55\u53f6\u7684\u8def\u5f84\u3002\uff08\u6240\u8c13\u4e00\u4e2a\u53f6\u5b50\u8282\u70b9\uff0c\u5c31\u662f\u4e00\u4e2a\u6ca1\u6709\u5b50\u8282\u70b9\u7684\u8282\u70b9\uff09

\n\n

\u5047\u5982\u901a\u8fc7\u8282\u70b9 node \u7684\u6bcf\u79cd\u53ef\u80fd\u7684 “\u6839-\u53f6” \u8def\u5f84\u4e0a\u503c\u7684\u603b\u548c\u5168\u90fd\u5c0f\u4e8e\u7ed9\u5b9a\u7684 limit\uff0c\u5219\u8be5\u8282\u70b9\u88ab\u79f0\u4e4b\u4e3a\u300c\u4e0d\u8db3\u8282\u70b9\u300d\uff0c\u9700\u8981\u88ab\u5220\u9664\u3002

\n\n

\u8bf7\u4f60\u5220\u9664\u6240\u6709\u4e0d\u8db3\u8282\u70b9\uff0c\u5e76\u8fd4\u56de\u751f\u6210\u7684\u4e8c\u53c9\u6811\u7684\u6839\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\"\"\n\u8f93\u5165\uff1aroot = [1,2,3,4,-99,-99,7,8,9,-99,-99,12,13,-99,14], limit = 1\n\"\"\n\u8f93\u51fa\uff1a[1,2,3,4,null,null,7,8,9,null,14]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\"\"\n\u8f93\u5165\uff1aroot = [5,4,8,11,null,17,4,7,1,null,null,5,3], limit = 22\n\"\"\n\u8f93\u51fa\uff1a[5,4,8,11,null,17,4,7,null,null,null,5]
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\"\"\n\u8f93\u5165\uff1aroot = [5,-6,-6], limit = 0\n\u8f93\u51fa\uff1a[]
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. \u7ed9\u5b9a\u7684\u6811\u6709 1 \u5230 5000 \u4e2a\u8282\u70b9
  2. \n\t
  3. -10^5 <= node.val <= 10^5
  4. \n\t
  5. -10^9 <= limit <= 10^9
  6. \n
\n\n

 

\n", "tags_en": ["Depth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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 */\nclass Solution {\npublic:\n TreeNode* sufficientSubset(TreeNode* root, int limit) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode(int x) { val = x; }\n * }\n */\nclass Solution {\n public TreeNode sufficientSubset(TreeNode root, int limit) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution(object):\n def sufficientSubset(self, root, limit):\n \"\"\"\n :type root: TreeNode\n :type limit: int\n :rtype: TreeNode\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution:\n def sufficientSubset(self, root: TreeNode, limit: int) -> TreeNode:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* sufficientSubset(struct TreeNode* root, int limit){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int x) { val = x; }\n * }\n */\npublic class Solution {\n public TreeNode SufficientSubset(TreeNode root, int limit) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val) {\n * this.val = val;\n * this.left = this.right = null;\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number} limit\n * @return {TreeNode}\n */\nvar sufficientSubset = function(root, limit) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val)\n# @val = val\n# @left, @right = nil, nil\n# end\n# end\n\n# @param {TreeNode} root\n# @param {Integer} limit\n# @return {TreeNode}\ndef sufficient_subset(root, limit)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.left = nil\n * self.right = nil\n * }\n * }\n */\nclass Solution {\n func sufficientSubset(_ root: TreeNode?, _ limit: Int) -> TreeNode? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc sufficientSubset(root *TreeNode, limit int) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(var _value: Int) {\n * var value: Int = _value\n * var left: TreeNode = null\n * var right: TreeNode = null\n * }\n */\nobject Solution {\n def sufficientSubset(root: TreeNode, limit: Int): TreeNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun sufficientSubset(root: TreeNode?, limit: Int): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n// \n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn sufficient_subset(root: Option>>, limit: i32) -> Option>> {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($value) { $this->val = $value; }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param Integer $limit\n * @return TreeNode\n */\n function sufficientSubset($root, $limit) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction sufficientSubset(root: TreeNode | null, limit: number): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (sufficient-subset root limit)\n (-> (or/c tree-node? #f) exact-integer? (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1080](https://leetcode-cn.com/problems/insufficient-nodes-in-root-to-leaf-paths)", "[\u6839\u5230\u53f6\u8def\u5f84\u4e0a\u7684\u4e0d\u8db3\u8282\u70b9](/solution/1000-1099/1080.Insufficient%20Nodes%20in%20Root%20to%20Leaf%20Paths/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1080](https://leetcode.com/problems/insufficient-nodes-in-root-to-leaf-paths)", "[Insufficient Nodes in Root to Leaf Paths](/solution/1000-1099/1080.Insufficient%20Nodes%20in%20Root%20to%20Leaf%20Paths/README_EN.md)", "`Depth-first Search`", "Medium", ""]}, {"question_id": "1156", "frontend_question_id": "1078", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/occurrences-after-bigram", "url_en": "https://leetcode.com/problems/occurrences-after-bigram", "relative_path_cn": "/solution/1000-1099/1078.Occurrences%20After%20Bigram/README.md", "relative_path_en": "/solution/1000-1099/1078.Occurrences%20After%20Bigram/README_EN.md", "title_cn": "Bigram \u5206\u8bcd", "title_en": "Occurrences After Bigram", "question_title_slug": "occurrences-after-bigram", "content_en": "

Given two strings first and second, consider occurrences in some text of the form "first second third", where second comes immediately after first, and third comes immediately after second.

\n\n

Return an array of all the words third for each occurrence of "first second third".

\n\n

 

\n

Example 1:

\n
Input: text = \"alice is a good girl she is a good student\", first = \"a\", second = \"good\"\nOutput: [\"girl\",\"student\"]\n

Example 2:

\n
Input: text = \"we will we will rock you\", first = \"we\", second = \"will\"\nOutput: [\"we\",\"rock\"]\n
\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= text.length <= 1000
  • \n\t
  • text consists of lowercase English letters and spaces.
  • \n\t
  • All the words in text a separated by a single space.
  • \n\t
  • 1 <= first.length, second.length <= 10
  • \n\t
  • first and second consist of lowercase English letters.
  • \n
\n", "content_cn": "

\u7ed9\u51fa\u7b2c\u4e00\u4e2a\u8bcd first \u548c\u7b2c\u4e8c\u4e2a\u8bcd second\uff0c\u8003\u8651\u5728\u67d0\u4e9b\u6587\u672c text \u4e2d\u53ef\u80fd\u4ee5 "first second third" \u5f62\u5f0f\u51fa\u73b0\u7684\u60c5\u51b5\uff0c\u5176\u4e2d second \u7d27\u968f first \u51fa\u73b0\uff0cthird \u7d27\u968f second \u51fa\u73b0\u3002

\n\n

\u5bf9\u4e8e\u6bcf\u79cd\u8fd9\u6837\u7684\u60c5\u51b5\uff0c\u5c06\u7b2c\u4e09\u4e2a\u8bcd "third" \u6dfb\u52a0\u5230\u7b54\u6848\u4e2d\uff0c\u5e76\u8fd4\u56de\u7b54\u6848\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1atext = "alice is a good girl she is a good student", first = "a", second = "good"\n\u8f93\u51fa\uff1a["girl","student"]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1atext = "we will we will rock you", first = "we", second = "will"\n\u8f93\u51fa\uff1a["we","rock"]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= text.length <= 1000
  2. \n\t
  3. text \u7531\u4e00\u4e9b\u7528\u7a7a\u683c\u5206\u9694\u7684\u5355\u8bcd\u7ec4\u6210\uff0c\u6bcf\u4e2a\u5355\u8bcd\u90fd\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
  4. \n\t
  5. 1 <= first.length, second.length <= 10
  6. \n\t
  7. first \u548c second \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
  8. \n
\n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findOcurrences(string text, string first, string second) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String[] findOcurrences(String text, String first, String second) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findOcurrences(self, text, first, second):\n \"\"\"\n :type text: str\n :type first: str\n :type second: str\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findOcurrences(self, text: str, first: str, second: str) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** findOcurrences(char * text, char * first, char * second, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string[] FindOcurrences(string text, string first, string second) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} text\n * @param {string} first\n * @param {string} second\n * @return {string[]}\n */\nvar findOcurrences = function(text, first, second) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} text\n# @param {String} first\n# @param {String} second\n# @return {String[]}\ndef find_ocurrences(text, first, second)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findOcurrences(_ text: String, _ first: String, _ second: String) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findOcurrences(text string, first string, second string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findOcurrences(text: String, first: String, second: String): Array[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findOcurrences(text: String, first: String, second: String): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_ocurrences(text: String, first: String, second: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $text\n * @param String $first\n * @param String $second\n * @return String[]\n */\n function findOcurrences($text, $first, $second) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findOcurrences(text: string, first: string, second: string): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-ocurrences text first second)\n (-> string? string? string? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1078](https://leetcode-cn.com/problems/occurrences-after-bigram)", "[Bigram \u5206\u8bcd](/solution/1000-1099/1078.Occurrences%20After%20Bigram/README.md)", "`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[1078](https://leetcode.com/problems/occurrences-after-bigram)", "[Occurrences After Bigram](/solution/1000-1099/1078.Occurrences%20After%20Bigram/README_EN.md)", "`Hash Table`", "Easy", ""]}, {"question_id": "1155", "frontend_question_id": "1070", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/product-sales-analysis-iii", "url_en": "https://leetcode.com/problems/product-sales-analysis-iii", "relative_path_cn": "/solution/1000-1099/1070.Product%20Sales%20Analysis%20III/README.md", "relative_path_en": "/solution/1000-1099/1070.Product%20Sales%20Analysis%20III/README_EN.md", "title_cn": "\u4ea7\u54c1\u9500\u552e\u5206\u6790 III", "title_en": "Product Sales Analysis III", "question_title_slug": "product-sales-analysis-iii", "content_en": "

Table: Sales

\r\n\r\n
\r\n+-------------+-------+\r\n| Column Name | Type  |\r\n+-------------+-------+\r\n| sale_id     | int   |\r\n| product_id  | int   |\r\n| year        | int   |\r\n| quantity    | int   |\r\n| price       | int   |\r\n+-------------+-------+\r\nsale_id is the primary key of this table.\r\nproduct_id is a foreign key to Product table.\r\nNote that the price is per unit.\r\n
\r\n\r\n

Table: Product

\r\n\r\n
\r\n+--------------+---------+\r\n| Column Name  | Type    |\r\n+--------------+---------+\r\n| product_id   | int     |\r\n| product_name | varchar |\r\n+--------------+---------+\r\nproduct_id is the primary key of this table.\r\n
\r\n\r\n

 

\r\n\r\n

Write an SQL query that selects the product id, year, quantity, and price for the first year of every product sold.

\r\n\r\n

The query result format is in the following example:

\r\n\r\n
\r\nSales table:\r\n+---------+------------+------+----------+-------+\r\n| sale_id | product_id | year | quantity | price |\r\n+---------+------------+------+----------+-------+ \r\n| 1       | 100        | 2008 | 10       | 5000  |\r\n| 2       | 100        | 2009 | 12       | 5000  |\r\n| 7       | 200        | 2011 | 15       | 9000  |\r\n+---------+------------+------+----------+-------+\r\n\r\nProduct table:\r\n+------------+--------------+\r\n| product_id | product_name |\r\n+------------+--------------+\r\n| 100        | Nokia        |\r\n| 200        | Apple        |\r\n| 300        | Samsung      |\r\n+------------+--------------+\r\n\r\nResult table:\r\n+------------+------------+----------+-------+\r\n| product_id | first_year | quantity | price |\r\n+------------+------------+----------+-------+ \r\n| 100        | 2008       | 10       | 5000  |\r\n| 200        | 2011       | 15       | 9000  |\r\n+------------+------------+----------+-------+\r\n
\r\n", "content_cn": "

\u9500\u552e\u8868 Sales\uff1a

\n\n
+-------------+-------+\n| Column Name | Type  |\n+-------------+-------+\n| sale_id     | int   |\n| product_id  | int   |\n| year        | int   |\n| quantity    | int   |\n| price       | int   |\n+-------------+-------+\nsale_id \u662f\u6b64\u8868\u7684\u4e3b\u952e\u3002\nproduct_id \u662f\u4ea7\u54c1\u8868\u7684\u5916\u952e\u3002\n\u8bf7\u6ce8\u610f\uff0c\u4ef7\u683c\u662f\u6309\u6bcf\u5355\u4f4d\u8ba1\u7684\u3002\n
\n\n

\u4ea7\u54c1\u8868 Product\uff1a

\n\n
+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| product_id   | int     |\n| product_name | varchar |\n+--------------+---------+\nproduct_id \u662f\u6b64\u8868\u7684\u4e3b\u952e\u3002
\n\n

 

\n\n

\u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\uff0c\u9009\u51fa\u6bcf\u4e2a\u9500\u552e\u4ea7\u54c1\u7684 \u7b2c\u4e00\u5e74 \u7684 \u4ea7\u54c1 id\u3001\u5e74\u4efd\u3001\u6570\u91cf \u548c \u4ef7\u683c\u3002

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\uff1a

\n\n
Sales table:\n+---------+------------+------+----------+-------+\n| sale_id | product_id | year | quantity | price |\n+---------+------------+------+----------+-------+ \n| 1       | 100        | 2008 | 10       | 5000  |\n| 2       | 100        | 2009 | 12       | 5000  |\n| 7       | 200        | 2011 | 15       | 9000  |\n+---------+------------+------+----------+-------+\n\nProduct table:\n+------------+--------------+\n| product_id | product_name |\n+------------+--------------+\n| 100        | Nokia        |\n| 200        | Apple        |\n| 300        | Samsung      |\n+------------+--------------+\n\nResult table:\n+------------+------------+----------+-------+\n| product_id | first_year | quantity | price |\n+------------+------------+----------+-------+ \n| 100        | 2008       | 10       | 5000  |\n| 200        | 2011       | 15       | 9000  |\n+------------+------------+----------+-------+\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1070](https://leetcode-cn.com/problems/product-sales-analysis-iii)", "[\u4ea7\u54c1\u9500\u552e\u5206\u6790 III](/solution/1000-1099/1070.Product%20Sales%20Analysis%20III/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1070](https://leetcode.com/problems/product-sales-analysis-iii)", "[Product Sales Analysis III](/solution/1000-1099/1070.Product%20Sales%20Analysis%20III/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1154", "frontend_question_id": "1069", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/product-sales-analysis-ii", "url_en": "https://leetcode.com/problems/product-sales-analysis-ii", "relative_path_cn": "/solution/1000-1099/1069.Product%20Sales%20Analysis%20II/README.md", "relative_path_en": "/solution/1000-1099/1069.Product%20Sales%20Analysis%20II/README_EN.md", "title_cn": "\u4ea7\u54c1\u9500\u552e\u5206\u6790 II", "title_en": "Product Sales Analysis II", "question_title_slug": "product-sales-analysis-ii", "content_en": "

Table: Sales

\r\n\r\n
\r\n+-------------+-------+\r\n| Column Name | Type  |\r\n+-------------+-------+\r\n| sale_id     | int   |\r\n| product_id  | int   |\r\n| year        | int   |\r\n| quantity    | int   |\r\n| price       | int   |\r\n+-------------+-------+\r\nsale_id is the primary key of this table.\r\nproduct_id is a foreign key to Product table.\r\nNote that the price is per unit.\r\n
\r\n\r\n

Table: Product

\r\n\r\n
\r\n+--------------+---------+\r\n| Column Name  | Type    |\r\n+--------------+---------+\r\n| product_id   | int     |\r\n| product_name | varchar |\r\n+--------------+---------+\r\nproduct_id is the primary key of this table.\r\n
\r\n\r\n

 

\r\n\r\n

Write an SQL query that reports the total quantity sold for every product id.

\r\n\r\n

The query result format is in the following example:

\r\n\r\n
\r\nSales table:\r\n+---------+------------+------+----------+-------+\r\n| sale_id | product_id | year | quantity | price |\r\n+---------+------------+------+----------+-------+ \r\n| 1       | 100        | 2008 | 10       | 5000  |\r\n| 2       | 100        | 2009 | 12       | 5000  |\r\n| 7       | 200        | 2011 | 15       | 9000  |\r\n+---------+------------+------+----------+-------+\r\n\r\nProduct table:\r\n+------------+--------------+\r\n| product_id | product_name |\r\n+------------+--------------+\r\n| 100        | Nokia        |\r\n| 200        | Apple        |\r\n| 300        | Samsung      |\r\n+------------+--------------+\r\n\r\nResult table:\r\n+--------------+----------------+\r\n| product_id   | total_quantity |\r\n+--------------+----------------+\r\n| 100          | 22             |\r\n| 200          | 15             |\r\n+--------------+----------------+
\r\n", "content_cn": "

\u9500\u552e\u8868\uff1aSales

\n\n
+-------------+-------+\n| Column Name | Type  |\n+-------------+-------+\n| sale_id     | int   |\n| product_id  | int   |\n| year        | int   |\n| quantity    | int   |\n| price       | int   |\n+-------------+-------+\nsale_id \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\u3002\nproduct_id \u662f Product \u8868\u7684\u5916\u952e\u3002\n\u8bf7\u6ce8\u610f\u4ef7\u683c\u662f\u6bcf\u5355\u4f4d\u7684\u3002\n
\n\n

\u4ea7\u54c1\u8868\uff1aProduct

\n\n
+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| product_id   | int     |\n| product_name | varchar |\n+--------------+---------+\nproduct_id \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\u3002\n
\n\n

 

\n\n

\u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\uff0c\u6309\u4ea7\u54c1 id product_id \u6765\u7edf\u8ba1\u6bcf\u4e2a\u4ea7\u54c1\u7684\u9500\u552e\u603b\u91cf\u3002

\n\n

 

\n\n

\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u9762\u4f8b\u5b50\u6240\u793a:

\n\n
Sales \u8868\uff1a\n+---------+------------+------+----------+-------+\n| sale_id | product_id | year | quantity | price |\n+---------+------------+------+----------+-------+ \n| 1       | 100        | 2008 | 10       | 5000  |\n| 2       | 100        | 2009 | 12       | 5000  |\n| 7       | 200        | 2011 | 15       | 9000  |\n+---------+------------+------+----------+-------+\n\nProduct \u8868\uff1a\n+------------+--------------+\n| product_id | product_name |\n+------------+--------------+\n| 100        | Nokia        |\n| 200        | Apple        |\n| 300        | Samsung      |\n+------------+--------------+\n\nResult \u8868\uff1a\n+--------------+----------------+\n| product_id   | total_quantity |\n+--------------+----------------+\n| 100          | 22             |\n| 200          | 15             |\n+--------------+----------------+
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1069](https://leetcode-cn.com/problems/product-sales-analysis-ii)", "[\u4ea7\u54c1\u9500\u552e\u5206\u6790 II](/solution/1000-1099/1069.Product%20Sales%20Analysis%20II/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1069](https://leetcode.com/problems/product-sales-analysis-ii)", "[Product Sales Analysis II](/solution/1000-1099/1069.Product%20Sales%20Analysis%20II/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1153", "frontend_question_id": "1068", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/product-sales-analysis-i", "url_en": "https://leetcode.com/problems/product-sales-analysis-i", "relative_path_cn": "/solution/1000-1099/1068.Product%20Sales%20Analysis%20I/README.md", "relative_path_en": "/solution/1000-1099/1068.Product%20Sales%20Analysis%20I/README_EN.md", "title_cn": "\u4ea7\u54c1\u9500\u552e\u5206\u6790 I", "title_en": "Product Sales Analysis I", "question_title_slug": "product-sales-analysis-i", "content_en": "

Table: Sales

\n\n
\n+-------------+-------+\n| Column Name | Type  |\n+-------------+-------+\n| sale_id     | int   |\n| product_id  | int   |\n| year        | int   |\n| quantity    | int   |\n| price       | int   |\n+-------------+-------+\n(sale_id, year) is the primary key of this table.\nproduct_id is a foreign key to Product table.\nNote that the price is per unit.\n
\n\n

 

\n\n

Table: Product

\n\n
\n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| product_id   | int     |\n| product_name | varchar |\n+--------------+---------+\nproduct_id is the primary key of this table.\n
\n\n

 

\n\n

Write an SQL query that reports the product_name, year, and price for each sale_id in the Sales table.

\n\n

Return the resulting table in any order.

\n\n

The query result format is in the following example:

\n\n

 

\n\n
\nSales table:\n+---------+------------+------+----------+-------+\n| sale_id | product_id | year | quantity | price |\n+---------+------------+------+----------+-------+ \n| 1       | 100        | 2008 | 10       | 5000  |\n| 2       | 100        | 2009 | 12       | 5000  |\n| 7       | 200        | 2011 | 15       | 9000  |\n+---------+------------+------+----------+-------+\n\nProduct table:\n+------------+--------------+\n| product_id | product_name |\n+------------+--------------+\n| 100        | Nokia        |\n| 200        | Apple        |\n| 300        | Samsung      |\n+------------+--------------+\n\nResult table:\n+--------------+-------+-------+\n| product_name | year  | price |\n+--------------+-------+-------+\n| Nokia        | 2008  | 5000  |\n| Nokia        | 2009  | 5000  |\n| Apple        | 2011  | 9000  |\n+--------------+-------+-------+\nFrom sale_id = 1, we can conclude that Nokia was sold for 5000 in the year 2008.\nFrom sale_id = 2, we can conclude that Nokia was sold for 5000 in the year 2009.\nFrom sale_id = 7, we can conclude that Apple was sold for 9000 in the year 2011.\n
\n", "content_cn": "

\u9500\u552e\u8868 Sales\uff1a

\n\n
+-------------+-------+\n| Column Name | Type  |\n+-------------+-------+\n| sale_id     | int   |\n| product_id  | int   |\n| year        | int   |\n| quantity    | int   |\n| price       | int   |\n+-------------+-------+\n(sale_id, year) \u662f\u9500\u552e\u8868 Sales \u7684\u4e3b\u952e.\nproduct_id \u662f\u5173\u8054\u5230\u4ea7\u54c1\u8868 Product \u7684\u5916\u952e.\n\u6ce8\u610f: price \u8868\u793a\u6bcf\u5355\u4f4d\u4ef7\u683c\n
\n\n

\u4ea7\u54c1\u8868 Product\uff1a

\n\n
+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| product_id   | int     |\n| product_name | varchar |\n+--------------+---------+\nproduct_id \u662f\u8868\u7684\u4e3b\u952e.\n
\n\n

 

\n\n

\u5199\u4e00\u6761SQL \u67e5\u8be2\u8bed\u53e5\u83b7\u53d6 Sales \u8868\u4e2d\u6240\u6709\u4ea7\u54c1\u5bf9\u5e94\u7684 \u4ea7\u54c1\u540d\u79f0 product_name \u4ee5\u53ca\u8be5\u4ea7\u54c1\u7684\u6240\u6709 \u552e\u5356\u5e74\u4efd year \u548c \u4ef7\u683c price \u3002

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
Sales \u8868\uff1a\n+---------+------------+------+----------+-------+\n| sale_id | product_id | year | quantity | price |\n+---------+------------+------+----------+-------+ \n| 1       | 100        | 2008 | 10       | 5000  |\n| 2       | 100        | 2009 | 12       | 5000  |\n| 7       | 200        | 2011 | 15       | 9000  |\n+---------+------------+------+----------+-------+\n\nProduct \u8868\uff1a\n+------------+--------------+\n| product_id | product_name |\n+------------+--------------+\n| 100        | Nokia        |\n| 200        | Apple        |\n| 300        | Samsung      |\n+------------+--------------+\n\nResult \u8868\uff1a\n+--------------+-------+-------+\n| product_name | year  | price |\n+--------------+-------+-------+\n| Nokia        | 2008  | 5000  |\n| Nokia        | 2009  | 5000  |\n| Apple        | 2011  | 9000  |\n+--------------+-------+-------+\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1068](https://leetcode-cn.com/problems/product-sales-analysis-i)", "[\u4ea7\u54c1\u9500\u552e\u5206\u6790 I](/solution/1000-1099/1068.Product%20Sales%20Analysis%20I/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1068](https://leetcode.com/problems/product-sales-analysis-i)", "[Product Sales Analysis I](/solution/1000-1099/1068.Product%20Sales%20Analysis%20I/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1152", "frontend_question_id": "1183", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/maximum-number-of-ones", "url_en": "https://leetcode.com/problems/maximum-number-of-ones", "relative_path_cn": "/solution/1100-1199/1183.Maximum%20Number%20of%20Ones/README.md", "relative_path_en": "/solution/1100-1199/1183.Maximum%20Number%20of%20Ones/README_EN.md", "title_cn": "\u77e9\u9635\u4e2d 1 \u7684\u6700\u5927\u6570\u91cf", "title_en": "Maximum Number of Ones", "question_title_slug": "maximum-number-of-ones", "content_en": "

Consider a matrix M with dimensions width * height, such that every cell has value 0 or 1, and any square sub-matrix of M of size sideLength * sideLength has at most maxOnes ones.

\n\n

Return the maximum possible number of ones that the matrix M can have.

\n\n

 

\n

Example 1:

\n\n
\nInput: width = 3, height = 3, sideLength = 2, maxOnes = 1\nOutput: 4\nExplanation:\nIn a 3*3 matrix, no 2*2 sub-matrix can have more than 1 one.\nThe best solution that has 4 ones is:\n[1,0,1]\n[0,0,0]\n[1,0,1]\n
\n\n

Example 2:

\n\n
\nInput: width = 3, height = 3, sideLength = 2, maxOnes = 2\nOutput: 6\nExplanation:\n[1,0,1]\n[1,0,1]\n[1,0,1]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= width, height <= 100
  • \n\t
  • 1 <= sideLength <= width, height
  • \n\t
  • 0 <= maxOnes <= sideLength * sideLength
  • \n
\n", "content_cn": "

\u73b0\u5728\u6709\u4e00\u4e2a\u5c3a\u5bf8\u4e3a width * height \u7684\u77e9\u9635 M\uff0c\u77e9\u9635\u4e2d\u7684\u6bcf\u4e2a\u5355\u5143\u683c\u7684\u503c\u4e0d\u662f 0 \u5c31\u662f 1\u3002

\n\n

\u800c\u4e14\u77e9\u9635 M \u4e2d\u6bcf\u4e2a\u5927\u5c0f\u4e3a sideLength * sideLength \u7684 \u6b63\u65b9\u5f62 \u5b50\u9635\u4e2d\uff0c1 \u7684\u6570\u91cf\u4e0d\u5f97\u8d85\u8fc7 maxOnes\u3002

\n\n

\u8bf7\u4f60\u8bbe\u8ba1\u4e00\u4e2a\u7b97\u6cd5\uff0c\u8ba1\u7b97\u77e9\u9635\u4e2d\u6700\u591a\u53ef\u4ee5\u6709\u591a\u5c11\u4e2a 1\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1awidth = 3, height = 3, sideLength = 2, maxOnes = 1\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\n\u9898\u76ee\u8981\u6c42\uff1a\u5728\u4e00\u4e2a 3*3 \u7684\u77e9\u9635\u4e2d\uff0c\u6bcf\u4e00\u4e2a 2*2 \u7684\u5b50\u9635\u4e2d\u7684 1 \u7684\u6570\u76ee\u4e0d\u8d85\u8fc7 1 \u4e2a\u3002\n\u6700\u597d\u7684\u89e3\u51b3\u65b9\u6848\u4e2d\uff0c\u77e9\u9635 M \u91cc\u6700\u591a\u53ef\u4ee5\u6709 4 \u4e2a 1\uff0c\u5982\u4e0b\u6240\u793a\uff1a\n[1,0,1]\n[0,0,0]\n[1,0,1]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1awidth = 3, height = 3, sideLength = 2, maxOnes = 2\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\n[1,0,1]\n[1,0,1]\n[1,0,1]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= width, height <= 100
  • \n\t
  • 1 <= sideLength <= width, height
  • \n\t
  • 0 <= maxOnes <= sideLength * sideLength
  • \n
\n", "tags_en": ["Sort", "Math"], "tags_cn": ["\u6392\u5e8f", "\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maximumNumberOfOnes(int width, int height, int sideLength, int maxOnes) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maximumNumberOfOnes(int width, int height, int sideLength, int maxOnes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximumNumberOfOnes(self, width, height, sideLength, maxOnes):\n \"\"\"\n :type width: int\n :type height: int\n :type sideLength: int\n :type maxOnes: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximumNumberOfOnes(self, width: int, height: int, sideLength: int, maxOnes: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maximumNumberOfOnes(int width, int height, int sideLength, int maxOnes){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaximumNumberOfOnes(int width, int height, int sideLength, int maxOnes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} width\n * @param {number} height\n * @param {number} sideLength\n * @param {number} maxOnes\n * @return {number}\n */\nvar maximumNumberOfOnes = function(width, height, sideLength, maxOnes) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} width\n# @param {Integer} height\n# @param {Integer} side_length\n# @param {Integer} max_ones\n# @return {Integer}\ndef maximum_number_of_ones(width, height, side_length, max_ones)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximumNumberOfOnes(_ width: Int, _ height: Int, _ sideLength: Int, _ maxOnes: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximumNumberOfOnes(width int, height int, sideLength int, maxOnes int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximumNumberOfOnes(width: Int, height: Int, sideLength: Int, maxOnes: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximumNumberOfOnes(width: Int, height: Int, sideLength: Int, maxOnes: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximum_number_of_ones(width: i32, height: i32, side_length: i32, max_ones: i32) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $width\n * @param Integer $height\n * @param Integer $sideLength\n * @param Integer $maxOnes\n * @return Integer\n */\n function maximumNumberOfOnes($width, $height, $sideLength, $maxOnes) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximumNumberOfOnes(width: number, height: number, sideLength: number, maxOnes: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximum-number-of-ones width height sideLength maxOnes)\n (-> exact-integer? exact-integer? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1183](https://leetcode-cn.com/problems/maximum-number-of-ones)", "[\u77e9\u9635\u4e2d 1 \u7684\u6700\u5927\u6570\u91cf](/solution/1100-1199/1183.Maximum%20Number%20of%20Ones/README.md)", "`\u6392\u5e8f`,`\u6570\u5b66`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1183](https://leetcode.com/problems/maximum-number-of-ones)", "[Maximum Number of Ones](/solution/1100-1199/1183.Maximum%20Number%20of%20Ones/README_EN.md)", "`Sort`,`Math`", "Hard", "\ud83d\udd12"]}, {"question_id": "1151", "frontend_question_id": "1215", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/stepping-numbers", "url_en": "https://leetcode.com/problems/stepping-numbers", "relative_path_cn": "/solution/1200-1299/1215.Stepping%20Numbers/README.md", "relative_path_en": "/solution/1200-1299/1215.Stepping%20Numbers/README_EN.md", "title_cn": "\u6b65\u8fdb\u6570", "title_en": "Stepping Numbers", "question_title_slug": "stepping-numbers", "content_en": "

A Stepping Number is an integer such that all of its adjacent digits have an absolute difference of exactly 1. For example, 321 is a Stepping Number while 421 is not.

\n\n

Given two integers low and high, find and return a sorted list of all the Stepping Numbers in the range [low, high] inclusive.

\n\n

 

\n

Example 1:

\n
Input: low = 0, high = 21\nOutput: [0,1,2,3,4,5,6,7,8,9,10,12,21]\n
\n

 

\n

Constraints:

\n\n
    \n\t
  • 0 <= low <= high <= 2 * 10^9
  • \n
\n", "content_cn": "

\u5982\u679c\u4e00\u4e2a\u6574\u6570\u4e0a\u7684\u6bcf\u4e00\u4f4d\u6570\u5b57\u4e0e\u5176\u76f8\u90bb\u4f4d\u4e0a\u7684\u6570\u5b57\u7684\u7edd\u5bf9\u5dee\u90fd\u662f 1\uff0c\u90a3\u4e48\u8fd9\u4e2a\u6570\u5c31\u662f\u4e00\u4e2a\u300c\u6b65\u8fdb\u6570\u300d\u3002

\n\n

\u4f8b\u5982\uff0c321 \u662f\u4e00\u4e2a\u6b65\u8fdb\u6570\uff0c\u800c 421 \u4e0d\u662f\u3002

\n\n

\u7ed9\u4f60\u4e24\u4e2a\u6574\u6570\uff0clow \u548c high\uff0c\u8bf7\u4f60\u627e\u51fa\u5728 [low, high] \u8303\u56f4\u5185\u7684\u6240\u6709\u6b65\u8fdb\u6570\uff0c\u5e76\u8fd4\u56de \u6392\u5e8f\u540e \u7684\u7ed3\u679c\u3002

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1alow = 0, high = 21\n\u8f93\u51fa\uff1a[0,1,2,3,4,5,6,7,8,9,10,12,21]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 0 <= low <= high <= 2 * 10^9
  • \n
\n", "tags_en": ["Backtracking"], "tags_cn": ["\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector countSteppingNumbers(int low, int high) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List countSteppingNumbers(int low, int high) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countSteppingNumbers(self, low, high):\n \"\"\"\n :type low: int\n :type high: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countSteppingNumbers(self, low: int, high: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* countSteppingNumbers(int low, int high, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList CountSteppingNumbers(int low, int high) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} low\n * @param {number} high\n * @return {number[]}\n */\nvar countSteppingNumbers = function(low, high) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} low\n# @param {Integer} high\n# @return {Integer[]}\ndef count_stepping_numbers(low, high)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countSteppingNumbers(_ low: Int, _ high: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countSteppingNumbers(low int, high int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countSteppingNumbers(low: Int, high: Int): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countSteppingNumbers(low: Int, high: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_stepping_numbers(low: i32, high: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $low\n * @param Integer $high\n * @return Integer[]\n */\n function countSteppingNumbers($low, $high) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countSteppingNumbers(low: number, high: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-stepping-numbers low high)\n (-> exact-integer? exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1215](https://leetcode-cn.com/problems/stepping-numbers)", "[\u6b65\u8fdb\u6570](/solution/1200-1299/1215.Stepping%20Numbers/README.md)", "`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1215](https://leetcode.com/problems/stepping-numbers)", "[Stepping Numbers](/solution/1200-1299/1215.Stepping%20Numbers/README_EN.md)", "`Backtracking`", "Medium", "\ud83d\udd12"]}, {"question_id": "1150", "frontend_question_id": "1214", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/two-sum-bsts", "url_en": "https://leetcode.com/problems/two-sum-bsts", "relative_path_cn": "/solution/1200-1299/1214.Two%20Sum%20BSTs/README.md", "relative_path_en": "/solution/1200-1299/1214.Two%20Sum%20BSTs/README_EN.md", "title_cn": "\u67e5\u627e\u4e24\u68f5\u4e8c\u53c9\u641c\u7d22\u6811\u4e4b\u548c", "title_en": "Two Sum BSTs", "question_title_slug": "two-sum-bsts", "content_en": "

Given the roots of two binary search trees, root1 and root2, return true if and only if there is a node in the first tree and a node in the second tree whose values sum up to a given integer target.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: root1 = [2,1,4], root2 = [1,0,3], target = 5\nOutput: true\nExplanation: 2 and 3 sum up to 5.\n
\n\n

Example 2:

\n\"\"\n
\nInput: root1 = [0,-10,10], root2 = [5,1,7,0,2], target = 18\nOutput: false\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The number of nodes in each tree is in the range [1, 5000].
  • \n\t
  • -109 <= Node.val, target <= 109
  • \n
\n", "content_cn": "

\u7ed9\u51fa\u4e24\u68f5\u4e8c\u53c9\u641c\u7d22\u6811\uff0c\u8bf7\u4f60\u4ece\u4e24\u68f5\u6811\u4e2d\u5404\u627e\u51fa\u4e00\u4e2a\u8282\u70b9\uff0c\u4f7f\u5f97\u8fd9\u4e24\u4e2a\u8282\u70b9\u7684\u503c\u4e4b\u548c\u7b49\u4e8e\u76ee\u6807\u503c Target\u3002

\n\n

\u5982\u679c\u53ef\u4ee5\u627e\u5230\u8fd4\u56de True\uff0c\u5426\u5219\u8fd4\u56de False\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"\"\"

\n\n
\u8f93\u5165\uff1aroot1 = [2,1,4], root2 = [1,0,3], target = 5\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a2 \u52a0 3 \u548c\u4e3a 5 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"\"\"

\n\n
\u8f93\u5165\uff1aroot1 = [0,-10,10], root2 = [5,1,7,0,2], target = 18\n\u8f93\u51fa\uff1afalse
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. \u6bcf\u68f5\u6811\u4e0a\u6700\u591a\u6709 5000 \u4e2a\u8282\u70b9\u3002
  2. \n\t
  3. -10^9 <= target, node.val <= 10^9
  4. \n
\n", "tags_en": ["Binary Search Tree"], "tags_cn": ["\u4e8c\u53c9\u641c\u7d22\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n bool twoSumBSTs(TreeNode* root1, TreeNode* root2, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public boolean twoSumBSTs(TreeNode root1, TreeNode root2, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def twoSumBSTs(self, root1, root2, target):\n \"\"\"\n :type root1: TreeNode\n :type root2: TreeNode\n :type target: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def twoSumBSTs(self, root1: TreeNode, root2: TreeNode, target: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nbool twoSumBSTs(struct TreeNode* root1, struct TreeNode* root2, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public bool TwoSumBSTs(TreeNode root1, TreeNode root2, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root1\n * @param {TreeNode} root2\n * @param {number} target\n * @return {boolean}\n */\nvar twoSumBSTs = function(root1, root2, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root1\n# @param {TreeNode} root2\n# @param {Integer} target\n# @return {Boolean}\ndef two_sum_bs_ts(root1, root2, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func twoSumBSTs(_ root1: TreeNode?, _ root2: TreeNode?, _ target: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc twoSumBSTs(root1 *TreeNode, root2 *TreeNode, target int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def twoSumBSTs(root1: TreeNode, root2: TreeNode, target: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun twoSumBSTs(root1: TreeNode?, root2: TreeNode?, target: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn two_sum_bs_ts(root1: Option>>, root2: Option>>, target: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root1\n * @param TreeNode $root2\n * @param Integer $target\n * @return Boolean\n */\n function twoSumBSTs($root1, $root2, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction twoSumBSTs(root1: TreeNode | null, root2: TreeNode | null, target: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (two-sum-bs-ts root1 root2 target)\n (-> (or/c tree-node? #f) (or/c tree-node? #f) exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1214](https://leetcode-cn.com/problems/two-sum-bsts)", "[\u67e5\u627e\u4e24\u68f5\u4e8c\u53c9\u641c\u7d22\u6811\u4e4b\u548c](/solution/1200-1299/1214.Two%20Sum%20BSTs/README.md)", "`\u4e8c\u53c9\u641c\u7d22\u6811`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1214](https://leetcode.com/problems/two-sum-bsts)", "[Two Sum BSTs](/solution/1200-1299/1214.Two%20Sum%20BSTs/README_EN.md)", "`Binary Search Tree`", "Medium", "\ud83d\udd12"]}, {"question_id": "1149", "frontend_question_id": "1213", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/intersection-of-three-sorted-arrays", "url_en": "https://leetcode.com/problems/intersection-of-three-sorted-arrays", "relative_path_cn": "/solution/1200-1299/1213.Intersection%20of%20Three%20Sorted%20Arrays/README.md", "relative_path_en": "/solution/1200-1299/1213.Intersection%20of%20Three%20Sorted%20Arrays/README_EN.md", "title_cn": "\u4e09\u4e2a\u6709\u5e8f\u6570\u7ec4\u7684\u4ea4\u96c6", "title_en": "Intersection of Three Sorted Arrays", "question_title_slug": "intersection-of-three-sorted-arrays", "content_en": "

Given three integer arrays arr1, arr2 and arr3 sorted in strictly increasing order, return a sorted array of only the integers that appeared in all three arrays.

\n\n

 

\n

Example 1:

\n\n
\nInput: arr1 = [1,2,3,4,5], arr2 = [1,2,5,7,9], arr3 = [1,3,4,5,8]\nOutput: [1,5]\nExplanation: Only 1 and 5 appeared in the three arrays.\n
\n\n

Example 2:

\n\n
\nInput: arr1 = [197,418,523,876,1356], arr2 = [501,880,1593,1710,1870], arr3 = [521,682,1337,1395,1764]\nOutput: []\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= arr1.length, arr2.length, arr3.length <= 1000
  • \n\t
  • 1 <= arr1[i], arr2[i], arr3[i] <= 2000
  • \n
\n", "content_cn": "

\u7ed9\u51fa\u4e09\u4e2a\u5747\u4e3a \u4e25\u683c\u9012\u589e\u6392\u5217 \u7684\u6574\u6570\u6570\u7ec4 arr1\uff0carr2 \u548c arr3\u3002

\n\n

\u8fd4\u56de\u4e00\u4e2a\u7531 \u4ec5 \u5728\u8fd9\u4e09\u4e2a\u6570\u7ec4\u4e2d \u540c\u65f6\u51fa\u73b0 \u7684\u6574\u6570\u6240\u6784\u6210\u7684\u6709\u5e8f\u6570\u7ec4\u3002

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165: arr1 = [1,2,3,4,5], arr2 = [1,2,5,7,9], arr3 = [1,3,4,5,8]\n\u8f93\u51fa: [1,5]\n\u89e3\u91ca: \u53ea\u6709 1 \u548c 5 \u540c\u65f6\u5728\u8fd9\u4e09\u4e2a\u6570\u7ec4\u4e2d\u51fa\u73b0.\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= arr1.length, arr2.length, arr3.length <= 1000
  2. \n\t
  3. 1 <= arr1[i], arr2[i], arr3[i] <= 2000
  4. \n
\n", "tags_en": ["Hash Table", "Two Pointers"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u53cc\u6307\u9488"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector arraysIntersection(vector& arr1, vector& arr2, vector& arr3) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List arraysIntersection(int[] arr1, int[] arr2, int[] arr3) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def arraysIntersection(self, arr1, arr2, arr3):\n \"\"\"\n :type arr1: List[int]\n :type arr2: List[int]\n :type arr3: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def arraysIntersection(self, arr1: List[int], arr2: List[int], arr3: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* arraysIntersection(int* arr1, int arr1Size, int* arr2, int arr2Size, int* arr3, int arr3Size, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList ArraysIntersection(int[] arr1, int[] arr2, int[] arr3) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr1\n * @param {number[]} arr2\n * @param {number[]} arr3\n * @return {number[]}\n */\nvar arraysIntersection = function(arr1, arr2, arr3) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr1\n# @param {Integer[]} arr2\n# @param {Integer[]} arr3\n# @return {Integer[]}\ndef arrays_intersection(arr1, arr2, arr3)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func arraysIntersection(_ arr1: [Int], _ arr2: [Int], _ arr3: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func arraysIntersection(arr1 []int, arr2 []int, arr3 []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def arraysIntersection(arr1: Array[Int], arr2: Array[Int], arr3: Array[Int]): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun arraysIntersection(arr1: IntArray, arr2: IntArray, arr3: IntArray): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn arrays_intersection(arr1: Vec, arr2: Vec, arr3: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr1\n * @param Integer[] $arr2\n * @param Integer[] $arr3\n * @return Integer[]\n */\n function arraysIntersection($arr1, $arr2, $arr3) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function arraysIntersection(arr1: number[], arr2: number[], arr3: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (arrays-intersection arr1 arr2 arr3)\n (-> (listof exact-integer?) (listof exact-integer?) (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1213](https://leetcode-cn.com/problems/intersection-of-three-sorted-arrays)", "[\u4e09\u4e2a\u6709\u5e8f\u6570\u7ec4\u7684\u4ea4\u96c6](/solution/1200-1299/1213.Intersection%20of%20Three%20Sorted%20Arrays/README.md)", "`\u54c8\u5e0c\u8868`,`\u53cc\u6307\u9488`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1213](https://leetcode.com/problems/intersection-of-three-sorted-arrays)", "[Intersection of Three Sorted Arrays](/solution/1200-1299/1213.Intersection%20of%20Three%20Sorted%20Arrays/README_EN.md)", "`Hash Table`,`Two Pointers`", "Easy", "\ud83d\udd12"]}, {"question_id": "1148", "frontend_question_id": "1073", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/adding-two-negabinary-numbers", "url_en": "https://leetcode.com/problems/adding-two-negabinary-numbers", "relative_path_cn": "/solution/1000-1099/1073.Adding%20Two%20Negabinary%20Numbers/README.md", "relative_path_en": "/solution/1000-1099/1073.Adding%20Two%20Negabinary%20Numbers/README_EN.md", "title_cn": "\u8d1f\u4e8c\u8fdb\u5236\u6570\u76f8\u52a0", "title_en": "Adding Two Negabinary Numbers", "question_title_slug": "adding-two-negabinary-numbers", "content_en": "

Given two numbers arr1 and arr2 in base -2, return the result of adding them together.

\n\n

Each number is given in array format:  as an array of 0s and 1s, from most significant bit to least significant bit.  For example, arr = [1,1,0,1] represents the number (-2)^3 + (-2)^2 + (-2)^0 = -3.  A number arr in array, format is also guaranteed to have no leading zeros: either arr == [0] or arr[0] == 1.

\n\n

Return the result of adding arr1 and arr2 in the same format: as an array of 0s and 1s with no leading zeros.

\n\n

 

\n

Example 1:

\n\n
\nInput: arr1 = [1,1,1,1,1], arr2 = [1,0,1]\nOutput: [1,0,0,0,0]\nExplanation: arr1 represents 11, arr2 represents 5, the output represents 16.\n
\n\n

Example 2:

\n\n
\nInput: arr1 = [0], arr2 = [0]\nOutput: [0]\n
\n\n

Example 3:

\n\n
\nInput: arr1 = [0], arr2 = [1]\nOutput: [1]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= arr1.length, arr2.length <= 1000
  • \n\t
  • arr1[i] and arr2[i] are 0 or 1
  • \n\t
  • arr1 and arr2 have no leading zeros
  • \n
\n", "content_cn": "

\u7ed9\u51fa\u57fa\u6570\u4e3a -2 \u7684\u4e24\u4e2a\u6570 arr1 \u548c arr2\uff0c\u8fd4\u56de\u4e24\u6570\u76f8\u52a0\u7684\u7ed3\u679c\u3002

\n\n

\u6570\u5b57\u4ee5 \u6570\u7ec4\u5f62\u5f0f \u7ed9\u51fa\uff1a\u6570\u7ec4\u7531\u82e5\u5e72 0 \u548c 1 \u7ec4\u6210\uff0c\u6309\u6700\u9ad8\u6709\u6548\u4f4d\u5230\u6700\u4f4e\u6709\u6548\u4f4d\u7684\u987a\u5e8f\u6392\u5217\u3002\u4f8b\u5982\uff0carr = [1,1,0,1] \u8868\u793a\u6570\u5b57 (-2)^3 + (-2)^2 + (-2)^0 = -3\u3002\u6570\u7ec4\u5f62\u5f0f \u7684\u6570\u5b57\u4e5f\u540c\u6837\u4e0d\u542b\u524d\u5bfc\u96f6\uff1a\u4ee5 arr \u4e3a\u4f8b\uff0c\u8fd9\u610f\u5473\u7740\u8981\u4e48 arr == [0]\uff0c\u8981\u4e48 arr[0] == 1\u3002

\n\n

\u8fd4\u56de\u76f8\u540c\u8868\u793a\u5f62\u5f0f\u7684 arr1 \u548c arr2 \u76f8\u52a0\u7684\u7ed3\u679c\u3002\u4e24\u6570\u7684\u8868\u793a\u5f62\u5f0f\u4e3a\uff1a\u4e0d\u542b\u524d\u5bfc\u96f6\u3001\u7531\u82e5\u5e72 0 \u548c 1 \u7ec4\u6210\u7684\u6570\u7ec4\u3002

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1aarr1 = [1,1,1,1,1], arr2 = [1,0,1]\n\u8f93\u51fa\uff1a[1,0,0,0,0]\n\u89e3\u91ca\uff1aarr1 \u8868\u793a 11\uff0carr2 \u8868\u793a 5\uff0c\u8f93\u51fa\u8868\u793a 16 \u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= arr1.length <= 1000
  2. \n\t
  3. 1 <= arr2.length <= 1000
  4. \n\t
  5. arr1 \u548c arr2 \u90fd\u4e0d\u542b\u524d\u5bfc\u96f6
  6. \n\t
  7. arr1[i] \u4e3a 0 \u6216 1
  8. \n\t
  9. arr2[i] \u4e3a 0 \u6216 1
  10. \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector addNegabinary(vector& arr1, vector& arr2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] addNegabinary(int[] arr1, int[] arr2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def addNegabinary(self, arr1, arr2):\n \"\"\"\n :type arr1: List[int]\n :type arr2: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def addNegabinary(self, arr1: List[int], arr2: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* addNegabinary(int* arr1, int arr1Size, int* arr2, int arr2Size, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] AddNegabinary(int[] arr1, int[] arr2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr1\n * @param {number[]} arr2\n * @return {number[]}\n */\nvar addNegabinary = function(arr1, arr2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr1\n# @param {Integer[]} arr2\n# @return {Integer[]}\ndef add_negabinary(arr1, arr2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func addNegabinary(_ arr1: [Int], _ arr2: [Int]) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func addNegabinary(arr1 []int, arr2 []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def addNegabinary(arr1: Array[Int], arr2: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun addNegabinary(arr1: IntArray, arr2: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn add_negabinary(arr1: Vec, arr2: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr1\n * @param Integer[] $arr2\n * @return Integer[]\n */\n function addNegabinary($arr1, $arr2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function addNegabinary(arr1: number[], arr2: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (add-negabinary arr1 arr2)\n (-> (listof exact-integer?) (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1073](https://leetcode-cn.com/problems/adding-two-negabinary-numbers)", "[\u8d1f\u4e8c\u8fdb\u5236\u6570\u76f8\u52a0](/solution/1000-1099/1073.Adding%20Two%20Negabinary%20Numbers/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1073](https://leetcode.com/problems/adding-two-negabinary-numbers)", "[Adding Two Negabinary Numbers](/solution/1000-1099/1073.Adding%20Two%20Negabinary%20Numbers/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "1147", "frontend_question_id": "1072", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/flip-columns-for-maximum-number-of-equal-rows", "url_en": "https://leetcode.com/problems/flip-columns-for-maximum-number-of-equal-rows", "relative_path_cn": "/solution/1000-1099/1072.Flip%20Columns%20For%20Maximum%20Number%20of%20Equal%20Rows/README.md", "relative_path_en": "/solution/1000-1099/1072.Flip%20Columns%20For%20Maximum%20Number%20of%20Equal%20Rows/README_EN.md", "title_cn": "\u6309\u5217\u7ffb\u8f6c\u5f97\u5230\u6700\u5927\u503c\u7b49\u884c\u6570", "title_en": "Flip Columns For Maximum Number of Equal Rows", "question_title_slug": "flip-columns-for-maximum-number-of-equal-rows", "content_en": "

You are given an m x n binary matrix matrix.

\n\n

You can choose any number of columns in the matrix and flip every cell in that column (i.e., Change the value of the cell from 0 to 1 or vice versa).

\n\n

Return the maximum number of rows that have all values equal after some number of flips.

\n\n

 

\n

Example 1:

\n\n
\nInput: matrix = [[0,1],[1,1]]\nOutput: 1\nExplanation: After flipping no values, 1 row has all values equal.\n
\n\n

Example 2:

\n\n
\nInput: matrix = [[0,1],[1,0]]\nOutput: 2\nExplanation: After flipping values in the first column, both rows have equal values.\n
\n\n

Example 3:

\n\n
\nInput: matrix = [[0,0,0],[0,0,1],[1,1,0]]\nOutput: 2\nExplanation: After flipping values in the first two columns, the last two rows have equal values.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • m == matrix.length
  • \n\t
  • n == matrix[i].length
  • \n\t
  • 1 <= m, n <= 300
  • \n\t
  • matrix[i][j] is either 0 or 1.
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u7531\u82e5\u5e72 0 \u548c 1 \u7ec4\u6210\u7684\u77e9\u9635\u00a0matrix\uff0c\u4ece\u4e2d\u9009\u51fa\u4efb\u610f\u6570\u91cf\u7684\u5217\u5e76\u7ffb\u8f6c\u5176\u4e0a\u7684\u00a0\u6bcf\u4e2a\u00a0\u5355\u5143\u683c\u3002\u7ffb\u8f6c\u540e\uff0c\u5355\u5143\u683c\u7684\u503c\u4ece 0 \u53d8\u6210 1\uff0c\u6216\u8005\u4ece 1 \u53d8\u4e3a 0 \u3002

\n\n

\u56de\u7ecf\u8fc7\u4e00\u4e9b\u7ffb\u8f6c\u540e\uff0c\u884c\u4e0e\u884c\u4e4b\u95f4\u6240\u6709\u503c\u90fd\u76f8\u7b49\u7684\u6700\u5927\u884c\u6570\u3002

\n\n

\u00a0

\n\n
    \n
\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1a[[0,1],[1,1]]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u4e0d\u8fdb\u884c\u7ffb\u8f6c\uff0c\u6709 1 \u884c\u6240\u6709\u503c\u90fd\u76f8\u7b49\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1a[[0,1],[1,0]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u7ffb\u8f6c\u7b2c\u4e00\u5217\u7684\u503c\u4e4b\u540e\uff0c\u8fd9\u4e24\u884c\u90fd\u7531\u76f8\u7b49\u7684\u503c\u7ec4\u6210\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1a[[0,0,0],[0,0,1],[1,1,0]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u7ffb\u8f6c\u524d\u4e24\u5217\u7684\u503c\u4e4b\u540e\uff0c\u540e\u4e24\u884c\u7531\u76f8\u7b49\u7684\u503c\u7ec4\u6210\u3002
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= matrix.length <= 300
  2. \n\t
  3. 1 <= matrix[i].length <= 300
  4. \n\t
  5. \u6240\u6709 matrix[i].length\u00a0\u90fd\u76f8\u7b49
  6. \n\t
  7. matrix[i][j] \u4e3a\u00a00 \u6216\u00a01
  8. \n
\n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxEqualRowsAfterFlips(vector>& matrix) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxEqualRowsAfterFlips(int[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxEqualRowsAfterFlips(self, matrix):\n \"\"\"\n :type matrix: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxEqualRowsAfterFlips(self, matrix: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxEqualRowsAfterFlips(int** matrix, int matrixSize, int* matrixColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxEqualRowsAfterFlips(int[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} matrix\n * @return {number}\n */\nvar maxEqualRowsAfterFlips = function(matrix) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} matrix\n# @return {Integer}\ndef max_equal_rows_after_flips(matrix)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxEqualRowsAfterFlips(_ matrix: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxEqualRowsAfterFlips(matrix [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxEqualRowsAfterFlips(matrix: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxEqualRowsAfterFlips(matrix: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_equal_rows_after_flips(matrix: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $matrix\n * @return Integer\n */\n function maxEqualRowsAfterFlips($matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxEqualRowsAfterFlips(matrix: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-equal-rows-after-flips matrix)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1072](https://leetcode-cn.com/problems/flip-columns-for-maximum-number-of-equal-rows)", "[\u6309\u5217\u7ffb\u8f6c\u5f97\u5230\u6700\u5927\u503c\u7b49\u884c\u6570](/solution/1000-1099/1072.Flip%20Columns%20For%20Maximum%20Number%20of%20Equal%20Rows/README.md)", "`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1072](https://leetcode.com/problems/flip-columns-for-maximum-number-of-equal-rows)", "[Flip Columns For Maximum Number of Equal Rows](/solution/1000-1099/1072.Flip%20Columns%20For%20Maximum%20Number%20of%20Equal%20Rows/README_EN.md)", "`Hash Table`", "Medium", ""]}, {"question_id": "1146", "frontend_question_id": "1071", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/greatest-common-divisor-of-strings", "url_en": "https://leetcode.com/problems/greatest-common-divisor-of-strings", "relative_path_cn": "/solution/1000-1099/1071.Greatest%20Common%20Divisor%20of%20Strings/README.md", "relative_path_en": "/solution/1000-1099/1071.Greatest%20Common%20Divisor%20of%20Strings/README_EN.md", "title_cn": "\u5b57\u7b26\u4e32\u7684\u6700\u5927\u516c\u56e0\u5b50", "title_en": "Greatest Common Divisor of Strings", "question_title_slug": "greatest-common-divisor-of-strings", "content_en": "

For two strings s and t, we say "t divides s" if and only if s = t + ... + t  (t concatenated with itself 1 or more times)

\n\n

Given two strings str1 and str2, return the largest string x such that x divides both str1 and str2.

\n\n

 

\n

Example 1:

\n
Input: str1 = \"ABCABC\", str2 = \"ABC\"\nOutput: \"ABC\"\n

Example 2:

\n
Input: str1 = \"ABABAB\", str2 = \"ABAB\"\nOutput: \"AB\"\n

Example 3:

\n
Input: str1 = \"LEET\", str2 = \"CODE\"\nOutput: \"\"\n

Example 4:

\n
Input: str1 = \"ABCDEF\", str2 = \"ABC\"\nOutput: \"\"\n
\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= str1.length <= 1000
  • \n\t
  • 1 <= str2.length <= 1000
  • \n\t
  • str1 and str2 consist of English uppercase letters.
  • \n
\n", "content_cn": "

\u5bf9\u4e8e\u5b57\u7b26\u4e32\u00a0S \u548c\u00a0T\uff0c\u53ea\u6709\u5728 S = T + ... + T\uff08T \u81ea\u8eab\u8fde\u63a5 1 \u6b21\u6216\u591a\u6b21\uff09\u65f6\uff0c\u6211\u4eec\u624d\u8ba4\u5b9a\u00a0\u201cT \u80fd\u9664\u5c3d S\u201d\u3002

\n\n

\u8fd4\u56de\u6700\u957f\u5b57\u7b26\u4e32\u00a0X\uff0c\u8981\u6c42\u6ee1\u8db3\u00a0X \u80fd\u9664\u5c3d str1 \u4e14\u00a0X \u80fd\u9664\u5c3d str2\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1astr1 = \"ABCABC\", str2 = \"ABC\"\n\u8f93\u51fa\uff1a\"ABC\"\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1astr1 = \"ABABAB\", str2 = \"ABAB\"\n\u8f93\u51fa\uff1a\"AB\"\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1astr1 = \"LEET\", str2 = \"CODE\"\n\u8f93\u51fa\uff1a\"\"\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= str1.length <= 1000
  2. \n\t
  3. 1 <= str2.length <= 1000
  4. \n\t
  5. str1[i] \u548c\u00a0str2[i] \u4e3a\u5927\u5199\u82f1\u6587\u5b57\u6bcd
  6. \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string gcdOfStrings(string str1, string str2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String gcdOfStrings(String str1, String str2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def gcdOfStrings(self, str1, str2):\n \"\"\"\n :type str1: str\n :type str2: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def gcdOfStrings(self, str1: str, str2: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * gcdOfStrings(char * str1, char * str2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string GcdOfStrings(string str1, string str2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} str1\n * @param {string} str2\n * @return {string}\n */\nvar gcdOfStrings = function(str1, str2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} str1\n# @param {String} str2\n# @return {String}\ndef gcd_of_strings(str1, str2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func gcdOfStrings(_ str1: String, _ str2: String) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func gcdOfStrings(str1 string, str2 string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def gcdOfStrings(str1: String, str2: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun gcdOfStrings(str1: String, str2: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn gcd_of_strings(str1: String, str2: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $str1\n * @param String $str2\n * @return String\n */\n function gcdOfStrings($str1, $str2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function gcdOfStrings(str1: string, str2: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (gcd-of-strings str1 str2)\n (-> string? string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1071](https://leetcode-cn.com/problems/greatest-common-divisor-of-strings)", "[\u5b57\u7b26\u4e32\u7684\u6700\u5927\u516c\u56e0\u5b50](/solution/1000-1099/1071.Greatest%20Common%20Divisor%20of%20Strings/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1071](https://leetcode.com/problems/greatest-common-divisor-of-strings)", "[Greatest Common Divisor of Strings](/solution/1000-1099/1071.Greatest%20Common%20Divisor%20of%20Strings/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1145", "frontend_question_id": "1074", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-submatrices-that-sum-to-target", "url_en": "https://leetcode.com/problems/number-of-submatrices-that-sum-to-target", "relative_path_cn": "/solution/1000-1099/1074.Number%20of%20Submatrices%20That%20Sum%20to%20Target/README.md", "relative_path_en": "/solution/1000-1099/1074.Number%20of%20Submatrices%20That%20Sum%20to%20Target/README_EN.md", "title_cn": "\u5143\u7d20\u548c\u4e3a\u76ee\u6807\u503c\u7684\u5b50\u77e9\u9635\u6570\u91cf", "title_en": "Number of Submatrices That Sum to Target", "question_title_slug": "number-of-submatrices-that-sum-to-target", "content_en": "

Given a matrix and a target, return the number of non-empty submatrices that sum to target.

\n\n

A submatrix x1, y1, x2, y2 is the set of all cells matrix[x][y] with x1 <= x <= x2 and y1 <= y <= y2.

\n\n

Two submatrices (x1, y1, x2, y2) and (x1', y1', x2', y2') are different if they have some coordinate that is different: for example, if x1 != x1'.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: matrix = [[0,1,0],[1,1,1],[0,1,0]], target = 0\nOutput: 4\nExplanation: The four 1x1 submatrices that only contain 0.\n
\n\n

Example 2:

\n\n
\nInput: matrix = [[1,-1],[-1,1]], target = 0\nOutput: 5\nExplanation: The two 1x2 submatrices, plus the two 2x1 submatrices, plus the 2x2 submatrix.\n
\n\n

Example 3:

\n\n
\nInput: matrix = [[904]], target = 0\nOutput: 0\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= matrix.length <= 100
  • \n\t
  • 1 <= matrix[0].length <= 100
  • \n\t
  • -1000 <= matrix[i] <= 1000
  • \n\t
  • -10^8 <= target <= 10^8
  • \n
\n", "content_cn": "

\u7ed9\u51fa\u77e9\u9635\u00a0matrix\u00a0\u548c\u76ee\u6807\u503c\u00a0target\uff0c\u8fd4\u56de\u5143\u7d20\u603b\u548c\u7b49\u4e8e\u76ee\u6807\u503c\u7684\u975e\u7a7a\u5b50\u77e9\u9635\u7684\u6570\u91cf\u3002

\n\n

\u5b50\u77e9\u9635\u00a0x1, y1, x2, y2\u00a0\u662f\u6ee1\u8db3 x1 <= x <= x2\u00a0\u4e14\u00a0y1 <= y <= y2\u00a0\u7684\u6240\u6709\u5355\u5143\u00a0matrix[x][y]\u00a0\u7684\u96c6\u5408\u3002

\n\n

\u5982\u679c\u00a0(x1, y1, x2, y2) \u548c\u00a0(x1', y1', x2', y2')\u00a0\u4e24\u4e2a\u5b50\u77e9\u9635\u4e2d\u90e8\u5206\u5750\u6807\u4e0d\u540c\uff08\u5982\uff1ax1 != x1'\uff09\uff0c\u90a3\u4e48\u8fd9\u4e24\u4e2a\u5b50\u77e9\u9635\u4e5f\u4e0d\u540c\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1amatrix = [[0,1,0],[1,1,1],[0,1,0]], target = 0\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u56db\u4e2a\u53ea\u542b 0 \u7684 1x1 \u5b50\u77e9\u9635\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1amatrix = [[1,-1],[-1,1]], target = 0\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u4e24\u4e2a 1x2 \u5b50\u77e9\u9635\uff0c\u52a0\u4e0a\u4e24\u4e2a 2x1 \u5b50\u77e9\u9635\uff0c\u518d\u52a0\u4e0a\u4e00\u4e2a 2x2 \u5b50\u77e9\u9635\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1amatrix = [[904]], target = 0\n\u8f93\u51fa\uff1a0\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= matrix.length <= 100
  • \n\t
  • 1 <= matrix[0].length <= 100
  • \n\t
  • -1000 <= matrix[i] <= 1000
  • \n\t
  • -10^8 <= target <= 10^8
  • \n
\n", "tags_en": ["Array", "Dynamic Programming", "Sliding Window"], "tags_cn": ["\u6570\u7ec4", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numSubmatrixSumTarget(vector>& matrix, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numSubmatrixSumTarget(int[][] matrix, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numSubmatrixSumTarget(self, matrix, target):\n \"\"\"\n :type matrix: List[List[int]]\n :type target: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numSubmatrixSumTarget(self, matrix: List[List[int]], target: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numSubmatrixSumTarget(int** matrix, int matrixSize, int* matrixColSize, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumSubmatrixSumTarget(int[][] matrix, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} matrix\n * @param {number} target\n * @return {number}\n */\nvar numSubmatrixSumTarget = function(matrix, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} matrix\n# @param {Integer} target\n# @return {Integer}\ndef num_submatrix_sum_target(matrix, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numSubmatrixSumTarget(_ matrix: [[Int]], _ target: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numSubmatrixSumTarget(matrix [][]int, target int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numSubmatrixSumTarget(matrix: Array[Array[Int]], target: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numSubmatrixSumTarget(matrix: Array, target: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_submatrix_sum_target(matrix: Vec>, target: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $matrix\n * @param Integer $target\n * @return Integer\n */\n function numSubmatrixSumTarget($matrix, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numSubmatrixSumTarget(matrix: number[][], target: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-submatrix-sum-target matrix target)\n (-> (listof (listof exact-integer?)) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1074](https://leetcode-cn.com/problems/number-of-submatrices-that-sum-to-target)", "[\u5143\u7d20\u548c\u4e3a\u76ee\u6807\u503c\u7684\u5b50\u77e9\u9635\u6570\u91cf](/solution/1000-1099/1074.Number%20of%20Submatrices%20That%20Sum%20to%20Target/README.md)", "`\u6570\u7ec4`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1074](https://leetcode.com/problems/number-of-submatrices-that-sum-to-target)", "[Number of Submatrices That Sum to Target](/solution/1000-1099/1074.Number%20of%20Submatrices%20That%20Sum%20to%20Target/README_EN.md)", "`Array`,`Dynamic Programming`,`Sliding Window`", "Hard", ""]}, {"question_id": "1144", "frontend_question_id": "1168", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/optimize-water-distribution-in-a-village", "url_en": "https://leetcode.com/problems/optimize-water-distribution-in-a-village", "relative_path_cn": "/solution/1100-1199/1168.Optimize%20Water%20Distribution%20in%20a%20Village/README.md", "relative_path_en": "/solution/1100-1199/1168.Optimize%20Water%20Distribution%20in%20a%20Village/README_EN.md", "title_cn": "\u6c34\u8d44\u6e90\u5206\u914d\u4f18\u5316", "title_en": "Optimize Water Distribution in a Village", "question_title_slug": "optimize-water-distribution-in-a-village", "content_en": "

There are n houses in a village. We want to supply water for all the houses by building wells and laying pipes.

\n\n

For each house i, we can either build a well inside it directly with cost wells[i - 1] (note the -1 due to 0-indexing), or pipe in water from another well to it. The costs to lay pipes between houses are given by the array pipes, where each pipes[j] = [house1j, house2j, costj] represents the cost to connect house1j and house2j together using a pipe. Connections are bidirectional.

\n\n

Return the minimum total cost to supply water to all houses.

\n\n

 

\n

Example 1:

\n\n

\"\"

\n\n
\nInput: n = 3, wells = [1,2,2], pipes = [[1,2,1],[2,3,1]]\nOutput: 3\nExplanation: \nThe image shows the costs of connecting houses using pipes.\nThe best strategy is to build a well in the first house with cost 1 and connect the other houses to it with cost 2 so the total cost is 3.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 104
  • \n\t
  • wells.length == n
  • \n\t
  • 0 <= wells[i] <= 105
  • \n\t
  • 1 <= pipes.length <= 104
  • \n\t
  • pipes[j].length == 3
  • \n\t
  • 1 <= house1j, house2j <= n
  • \n\t
  • 0 <= costj <= 105
  • \n\t
  • house1j != house2j
  • \n
\n", "content_cn": "

\u6751\u91cc\u9762\u4e00\u5171\u6709 n \u680b\u623f\u5b50\u3002\u6211\u4eec\u5e0c\u671b\u901a\u8fc7\u5efa\u9020\u6c34\u4e95\u548c\u94fa\u8bbe\u7ba1\u9053\u6765\u4e3a\u6240\u6709\u623f\u5b50\u4f9b\u6c34\u3002

\n\n

\u5bf9\u4e8e\u6bcf\u4e2a\u623f\u5b50 i\uff0c\u6211\u4eec\u6709\u4e24\u79cd\u53ef\u9009\u7684\u4f9b\u6c34\u65b9\u6848\uff1a

\n\n
    \n\t
  • \u4e00\u79cd\u662f\u76f4\u63a5\u5728\u623f\u5b50\u5185\u5efa\u9020\u6c34\u4e95\uff0c\u6210\u672c\u4e3a wells[i]\uff1b
  • \n\t
  • \u53e6\u4e00\u79cd\u662f\u4ece\u53e6\u4e00\u53e3\u4e95\u94fa\u8bbe\u7ba1\u9053\u5f15\u6c34\uff0c\u6570\u7ec4 pipes \u7ed9\u51fa\u4e86\u5728\u623f\u5b50\u95f4\u94fa\u8bbe\u7ba1\u9053\u7684\u6210\u672c\uff0c\u5176\u4e2d\u6bcf\u4e2a pipes[i] = [house1, house2, cost] \u4ee3\u8868\u7528\u7ba1\u9053\u5c06 house1 \u548c house2 \u8fde\u63a5\u5728\u4e00\u8d77\u7684\u6210\u672c\u3002\u5f53\u7136\uff0c\u8fde\u63a5\u662f\u53cc\u5411\u7684\u3002
  • \n
\n\n

\u8bf7\u4f60\u5e2e\u5fd9\u8ba1\u7b97\u4e3a\u6240\u6709\u623f\u5b50\u90fd\u4f9b\u6c34\u7684\u6700\u4f4e\u603b\u6210\u672c\u3002

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1an = 3, wells = [1,2,2], pipes = [[1,2,1],[2,3,1]]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a \n\u4e0a\u56fe\u5c55\u793a\u4e86\u94fa\u8bbe\u7ba1\u9053\u8fde\u63a5\u623f\u5c4b\u7684\u6210\u672c\u3002\n\u6700\u597d\u7684\u7b56\u7565\u662f\u5728\u7b2c\u4e00\u4e2a\u623f\u5b50\u91cc\u5efa\u9020\u6c34\u4e95\uff08\u6210\u672c\u4e3a 1\uff09\uff0c\u7136\u540e\u5c06\u5176\u4ed6\u623f\u5b50\u94fa\u8bbe\u7ba1\u9053\u8fde\u8d77\u6765\uff08\u6210\u672c\u4e3a 2\uff09\uff0c\u6240\u4ee5\u603b\u6210\u672c\u4e3a 3\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 10000
  • \n\t
  • wells.length == n
  • \n\t
  • 0 <= wells[i] <= 10^5
  • \n\t
  • 1 <= pipes.length <= 10000
  • \n\t
  • 1 <= pipes[i][0], pipes[i][1] <= n
  • \n\t
  • 0 <= pipes[i][2] <= 10^5
  • \n\t
  • pipes[i][0] != pipes[i][1]
  • \n
\n", "tags_en": ["Union Find", "Graph"], "tags_cn": ["\u5e76\u67e5\u96c6", "\u56fe"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minCostToSupplyWater(int n, vector& wells, vector>& pipes) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minCostToSupplyWater(int n, int[] wells, int[][] pipes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minCostToSupplyWater(self, n, wells, pipes):\n \"\"\"\n :type n: int\n :type wells: List[int]\n :type pipes: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minCostToSupplyWater(self, n: int, wells: List[int], pipes: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minCostToSupplyWater(int n, int* wells, int wellsSize, int** pipes, int pipesSize, int* pipesColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinCostToSupplyWater(int n, int[] wells, int[][] pipes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[]} wells\n * @param {number[][]} pipes\n * @return {number}\n */\nvar minCostToSupplyWater = function(n, wells, pipes) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[]} wells\n# @param {Integer[][]} pipes\n# @return {Integer}\ndef min_cost_to_supply_water(n, wells, pipes)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minCostToSupplyWater(_ n: Int, _ wells: [Int], _ pipes: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minCostToSupplyWater(n int, wells []int, pipes [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minCostToSupplyWater(n: Int, wells: Array[Int], pipes: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minCostToSupplyWater(n: Int, wells: IntArray, pipes: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_cost_to_supply_water(n: i32, wells: Vec, pipes: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[] $wells\n * @param Integer[][] $pipes\n * @return Integer\n */\n function minCostToSupplyWater($n, $wells, $pipes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minCostToSupplyWater(n: number, wells: number[], pipes: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-cost-to-supply-water n wells pipes)\n (-> exact-integer? (listof exact-integer?) (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1168](https://leetcode-cn.com/problems/optimize-water-distribution-in-a-village)", "[\u6c34\u8d44\u6e90\u5206\u914d\u4f18\u5316](/solution/1100-1199/1168.Optimize%20Water%20Distribution%20in%20a%20Village/README.md)", "`\u5e76\u67e5\u96c6`,`\u56fe`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1168](https://leetcode.com/problems/optimize-water-distribution-in-a-village)", "[Optimize Water Distribution in a Village](/solution/1100-1199/1168.Optimize%20Water%20Distribution%20in%20a%20Village/README_EN.md)", "`Union Find`,`Graph`", "Hard", "\ud83d\udd12"]}, {"question_id": "1143", "frontend_question_id": "1198", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/find-smallest-common-element-in-all-rows", "url_en": "https://leetcode.com/problems/find-smallest-common-element-in-all-rows", "relative_path_cn": "/solution/1100-1199/1198.Find%20Smallest%20Common%20Element%20in%20All%20Rows/README.md", "relative_path_en": "/solution/1100-1199/1198.Find%20Smallest%20Common%20Element%20in%20All%20Rows/README_EN.md", "title_cn": "\u627e\u51fa\u6240\u6709\u884c\u4e2d\u6700\u5c0f\u516c\u5171\u5143\u7d20", "title_en": "Find Smallest Common Element in All Rows", "question_title_slug": "find-smallest-common-element-in-all-rows", "content_en": "

Given an m x n matrix mat where every row is sorted in strictly increasing order, return the smallest common element in all rows.

\n\n

If there is no common element, return -1.

\n\n

 

\n

Example 1:

\n\n
\nInput: mat = [[1,2,3,4,5],[2,4,5,8,10],[3,5,7,9,11],[1,3,5,7,9]]\nOutput: 5\n
\n\n

Example 2:

\n\n
\nInput: mat = [[1,2,3],[2,3,4],[2,3,5]]\nOutput: 2\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • m == mat.length
  • \n\t
  • n == mat[i].length
  • \n\t
  • 1 <= m, n <= 500
  • \n\t
  • 1 <= mat[i][j] <= 104
  • \n\t
  • mat[i] is sorted in strictly increasing order.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u77e9\u9635\u00a0mat\uff0c\u5176\u4e2d\u6bcf\u4e00\u884c\u7684\u5143\u7d20\u90fd\u5df2\u7ecf\u6309 \u4e25\u683c\u9012\u589e \u987a\u5e8f\u6392\u597d\u4e86\u3002\u8bf7\u4f60\u5e2e\u5fd9\u627e\u51fa\u5728\u6240\u6709\u8fd9\u4e9b\u884c\u4e2d \u6700\u5c0f\u7684\u516c\u5171\u5143\u7d20\u3002

\n\n

\u5982\u679c\u77e9\u9635\u4e2d\u6ca1\u6709\u8fd9\u6837\u7684\u516c\u5171\u5143\u7d20\uff0c\u5c31\u8bf7\u8fd4\u56de\u00a0-1\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b\uff1a

\n\n
\n\u8f93\u5165\uff1amat = [[1,2,3,4,5],[2,4,5,8,10],[3,5,7,9,11],[1,3,5,7,9]]\n\u8f93\u51fa\uff1a5\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= mat.length, mat[i].length <= 500
  • \n\t
  • 1 <= mat[i][j] <= 10^4
  • \n\t
  • mat[i]\u00a0\u5df2\u6309\u4e25\u683c\u9012\u589e\u987a\u5e8f\u6392\u5217\u3002
  • \n
\n", "tags_en": ["Hash Table", "Binary Search"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int smallestCommonElement(vector>& mat) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int smallestCommonElement(int[][] mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def smallestCommonElement(self, mat):\n \"\"\"\n :type mat: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def smallestCommonElement(self, mat: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint smallestCommonElement(int** mat, int matSize, int* matColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SmallestCommonElement(int[][] mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} mat\n * @return {number}\n */\nvar smallestCommonElement = function(mat) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} mat\n# @return {Integer}\ndef smallest_common_element(mat)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func smallestCommonElement(_ mat: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func smallestCommonElement(mat [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def smallestCommonElement(mat: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun smallestCommonElement(mat: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn smallest_common_element(mat: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $mat\n * @return Integer\n */\n function smallestCommonElement($mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function smallestCommonElement(mat: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (smallest-common-element mat)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1198](https://leetcode-cn.com/problems/find-smallest-common-element-in-all-rows)", "[\u627e\u51fa\u6240\u6709\u884c\u4e2d\u6700\u5c0f\u516c\u5171\u5143\u7d20](/solution/1100-1199/1198.Find%20Smallest%20Common%20Element%20in%20All%20Rows/README.md)", "`\u54c8\u5e0c\u8868`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1198](https://leetcode.com/problems/find-smallest-common-element-in-all-rows)", "[Find Smallest Common Element in All Rows](/solution/1100-1199/1198.Find%20Smallest%20Common%20Element%20in%20All%20Rows/README_EN.md)", "`Hash Table`,`Binary Search`", "Medium", "\ud83d\udd12"]}, {"question_id": "1142", "frontend_question_id": "1197", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/minimum-knight-moves", "url_en": "https://leetcode.com/problems/minimum-knight-moves", "relative_path_cn": "/solution/1100-1199/1197.Minimum%20Knight%20Moves/README.md", "relative_path_en": "/solution/1100-1199/1197.Minimum%20Knight%20Moves/README_EN.md", "title_cn": "\u8fdb\u51fb\u7684\u9a91\u58eb", "title_en": "Minimum Knight Moves", "question_title_slug": "minimum-knight-moves", "content_en": "

In an infinite chess board with coordinates from -infinity to +infinity, you have a knight at square [0, 0].

\n\n

A knight has 8 possible moves it can make, as illustrated below. Each move is two squares in a cardinal direction, then one square in an orthogonal direction.

\n\n

\n\n

Return the minimum number of steps needed to move the knight to the square [x, y].  It is guaranteed the answer exists.

\n\n

 

\n

Example 1:

\n\n
\nInput: x = 2, y = 1\nOutput: 1\nExplanation: [0, 0] → [2, 1]\n
\n\n

Example 2:

\n\n
\nInput: x = 5, y = 5\nOutput: 4\nExplanation: [0, 0] → [2, 1] → [4, 2] → [3, 4] → [5, 5]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • |x| + |y| <= 300
  • \n
\n", "content_cn": "

\u4e00\u4e2a\u5750\u6807\u53ef\u4ee5\u4ece -infinity \u5ef6\u4f38\u5230 +infinity \u7684 \u65e0\u9650\u5927\u7684 \u68cb\u76d8\u4e0a\uff0c\u4f60\u7684 \u9a91\u58eb \u9a7b\u624e\u5728\u5750\u6807\u4e3a [0, 0] \u7684\u65b9\u683c\u91cc\u3002

\n\n

\u9a91\u58eb\u7684\u8d70\u6cd5\u548c\u4e2d\u56fd\u8c61\u68cb\u4e2d\u7684\u9a6c\u76f8\u4f3c\uff0c\u8d70 “\u65e5” \u5b57\uff1a\u5373\u5148\u5411\u5de6\uff08\u6216\u53f3\uff09\u8d70 1 \u683c\uff0c\u518d\u5411\u4e0a\uff08\u6216\u4e0b\uff09\u8d70 2 \u683c\uff1b\u6216\u5148\u5411\u5de6\uff08\u6216\u53f3\uff09\u8d70 2 \u683c\uff0c\u518d\u5411\u4e0a\uff08\u6216\u4e0b\uff09\u8d70 1 \u683c\u3002

\n\n

\u6bcf\u6b21\u79fb\u52a8\uff0c\u4ed6\u90fd\u53ef\u4ee5\u6309\u56fe\u793a\u516b\u4e2a\u65b9\u5411\u4e4b\u4e00\u524d\u8fdb\u3002

\n\n

\n\n

\u73b0\u5728\uff0c\u9a91\u58eb\u9700\u8981\u524d\u53bb\u5f81\u670d\u5750\u6807\u4e3a [x, y] \u7684\u90e8\u843d\uff0c\u8bf7\u4f60\u4e3a\u4ed6\u89c4\u5212\u8def\u7ebf\u3002

\n\n

\u6700\u540e\u8fd4\u56de\u6240\u9700\u7684\u6700\u5c0f\u79fb\u52a8\u6b21\u6570\u5373\u53ef\u3002\u672c\u9898\u786e\u4fdd\u7b54\u6848\u662f\u4e00\u5b9a\u5b58\u5728\u7684\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1ax = 2, y = 1\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a[0, 0] → [2, 1]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1ax = 5, y = 5\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a[0, 0] → [2, 1] → [4, 2] → [3, 4] → [5, 5]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • |x| + |y| <= 300
  • \n
\n", "tags_en": ["Breadth-first Search"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minKnightMoves(int x, int y) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minKnightMoves(int x, int y) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minKnightMoves(self, x, y):\n \"\"\"\n :type x: int\n :type y: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minKnightMoves(self, x: int, y: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minKnightMoves(int x, int y){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinKnightMoves(int x, int y) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} x\n * @param {number} y\n * @return {number}\n */\nvar minKnightMoves = function(x, y) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} x\n# @param {Integer} y\n# @return {Integer}\ndef min_knight_moves(x, y)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minKnightMoves(_ x: Int, _ y: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minKnightMoves(x int, y int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minKnightMoves(x: Int, y: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minKnightMoves(x: Int, y: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_knight_moves(x: i32, y: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $x\n * @param Integer $y\n * @return Integer\n */\n function minKnightMoves($x, $y) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minKnightMoves(x: number, y: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-knight-moves x y)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1197](https://leetcode-cn.com/problems/minimum-knight-moves)", "[\u8fdb\u51fb\u7684\u9a91\u58eb](/solution/1100-1199/1197.Minimum%20Knight%20Moves/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1197](https://leetcode.com/problems/minimum-knight-moves)", "[Minimum Knight Moves](/solution/1100-1199/1197.Minimum%20Knight%20Moves/README_EN.md)", "`Breadth-first Search`", "Medium", "\ud83d\udd12"]}, {"question_id": "1141", "frontend_question_id": "1196", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/how-many-apples-can-you-put-into-the-basket", "url_en": "https://leetcode.com/problems/how-many-apples-can-you-put-into-the-basket", "relative_path_cn": "/solution/1100-1199/1196.How%20Many%20Apples%20Can%20You%20Put%20into%20the%20Basket/README.md", "relative_path_en": "/solution/1100-1199/1196.How%20Many%20Apples%20Can%20You%20Put%20into%20the%20Basket/README_EN.md", "title_cn": "\u6700\u591a\u53ef\u4ee5\u4e70\u5230\u7684\u82f9\u679c\u6570\u91cf", "title_en": "How Many Apples Can You Put into the Basket", "question_title_slug": "how-many-apples-can-you-put-into-the-basket", "content_en": "

You have some apples, where arr[i] is the weight of the i-th apple.  You also have a basket that can carry up to 5000 units of weight.

\n\n

Return the maximum number of apples you can put in the basket.

\n\n

 

\n

Example 1:

\n\n
\nInput: arr = [100,200,150,1000]\nOutput: 4\nExplanation: All 4 apples can be carried by the basket since their sum of weights is 1450.\n
\n\n

Example 2:

\n\n
\nInput: arr = [900,950,800,1000,700,800]\nOutput: 5\nExplanation: The sum of weights of the 6 apples exceeds 5000 so we choose any 5 of them.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= arr.length <= 10^3
  • \n\t
  • 1 <= arr[i] <= 10^3
  • \n
\n", "content_cn": "

\u697c\u4e0b\u6c34\u679c\u5e97\u6b63\u5728\u4fc3\u9500\uff0c\u4f60\u6253\u7b97\u4e70\u4e9b\u82f9\u679c\uff0carr[i] \u8868\u793a\u7b2c i \u4e2a\u82f9\u679c\u7684\u5355\u4f4d\u91cd\u91cf\u3002

\n\n

\u4f60\u6709\u4e00\u4e2a\u8d2d\u7269\u888b\uff0c\u6700\u591a\u53ef\u4ee5\u88c5 5000 \u5355\u4f4d\u91cd\u91cf\u7684\u4e1c\u897f\uff0c\u7b97\u4e00\u7b97\uff0c\u6700\u591a\u53ef\u4ee5\u5f80\u8d2d\u7269\u888b\u91cc\u88c5\u5165\u591a\u5c11\u82f9\u679c\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aarr = [100,200,150,1000]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u6240\u6709 4 \u4e2a\u82f9\u679c\u90fd\u53ef\u4ee5\u88c5\u8fdb\u53bb\uff0c\u56e0\u4e3a\u5b83\u4eec\u7684\u91cd\u91cf\u4e4b\u548c\u4e3a 1450\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aarr = [900,950,800,1000,700,800]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a6 \u4e2a\u82f9\u679c\u7684\u603b\u91cd\u91cf\u8d85\u8fc7\u4e86 5000\uff0c\u6240\u4ee5\u6211\u4eec\u53ea\u80fd\u4ece\u4e2d\u4efb\u9009 5 \u4e2a\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= arr.length <= 10^3
  • \n\t
  • 1 <= arr[i] <= 10^3
  • \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxNumberOfApples(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxNumberOfApples(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxNumberOfApples(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxNumberOfApples(self, arr: List[int]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxNumberOfApples(int* arr, int arrSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxNumberOfApples(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar maxNumberOfApples = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef max_number_of_apples(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxNumberOfApples(_ arr: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxNumberOfApples(arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxNumberOfApples(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxNumberOfApples(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_number_of_apples(arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function maxNumberOfApples($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxNumberOfApples(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-number-of-apples arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1196](https://leetcode-cn.com/problems/how-many-apples-can-you-put-into-the-basket)", "[\u6700\u591a\u53ef\u4ee5\u4e70\u5230\u7684\u82f9\u679c\u6570\u91cf](/solution/1100-1199/1196.How%20Many%20Apples%20Can%20You%20Put%20into%20the%20Basket/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1196](https://leetcode.com/problems/how-many-apples-can-you-put-into-the-basket)", "[How Many Apples Can You Put into the Basket](/solution/1100-1199/1196.How%20Many%20Apples%20Can%20You%20Put%20into%20the%20Basket/README_EN.md)", "`Greedy`", "Easy", "\ud83d\udd12"]}, {"question_id": "1140", "frontend_question_id": "1054", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/distant-barcodes", "url_en": "https://leetcode.com/problems/distant-barcodes", "relative_path_cn": "/solution/1000-1099/1054.Distant%20Barcodes/README.md", "relative_path_en": "/solution/1000-1099/1054.Distant%20Barcodes/README_EN.md", "title_cn": "\u8ddd\u79bb\u76f8\u7b49\u7684\u6761\u5f62\u7801", "title_en": "Distant Barcodes", "question_title_slug": "distant-barcodes", "content_en": "

In a warehouse, there is a row of barcodes, where the ith barcode is barcodes[i].

\n\n

Rearrange the barcodes so that no two adjacent barcodes are equal. You may return any answer, and it is guaranteed an answer exists.

\n\n

 

\n

Example 1:

\n
Input: barcodes = [1,1,1,2,2,2]\nOutput: [2,1,2,1,2,1]\n

Example 2:

\n
Input: barcodes = [1,1,1,1,2,2,3,3]\nOutput: [1,3,1,3,1,2,1,2]\n
\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= barcodes.length <= 10000
  • \n\t
  • 1 <= barcodes[i] <= 10000
  • \n
\n", "content_cn": "

\u5728\u4e00\u4e2a\u4ed3\u5e93\u91cc\uff0c\u6709\u4e00\u6392\u6761\u5f62\u7801\uff0c\u5176\u4e2d\u7b2c i \u4e2a\u6761\u5f62\u7801\u4e3a barcodes[i]\u3002

\n\n

\u8bf7\u4f60\u91cd\u65b0\u6392\u5217\u8fd9\u4e9b\u6761\u5f62\u7801\uff0c\u4f7f\u5176\u4e2d\u4e24\u4e2a\u76f8\u90bb\u7684\u6761\u5f62\u7801 \u4e0d\u80fd \u76f8\u7b49\u3002 \u4f60\u53ef\u4ee5\u8fd4\u56de\u4efb\u4f55\u6ee1\u8db3\u8be5\u8981\u6c42\u7684\u7b54\u6848\uff0c\u6b64\u9898\u4fdd\u8bc1\u5b58\u5728\u7b54\u6848\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a[1,1,1,2,2,2]\n\u8f93\u51fa\uff1a[2,1,2,1,2,1]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a[1,1,1,1,2,2,3,3]\n\u8f93\u51fa\uff1a[1,3,1,3,2,1,2,1]
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= barcodes.length <= 10000
  2. \n\t
  3. 1 <= barcodes[i] <= 10000
  4. \n
\n\n

 

\n", "tags_en": ["Heap", "Sort"], "tags_cn": ["\u5806", "\u6392\u5e8f"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector rearrangeBarcodes(vector& barcodes) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] rearrangeBarcodes(int[] barcodes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def rearrangeBarcodes(self, barcodes):\n \"\"\"\n :type barcodes: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def rearrangeBarcodes(self, barcodes: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* rearrangeBarcodes(int* barcodes, int barcodesSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] RearrangeBarcodes(int[] barcodes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} barcodes\n * @return {number[]}\n */\nvar rearrangeBarcodes = function(barcodes) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} barcodes\n# @return {Integer[]}\ndef rearrange_barcodes(barcodes)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func rearrangeBarcodes(_ barcodes: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func rearrangeBarcodes(barcodes []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def rearrangeBarcodes(barcodes: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun rearrangeBarcodes(barcodes: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn rearrange_barcodes(barcodes: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $barcodes\n * @return Integer[]\n */\n function rearrangeBarcodes($barcodes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function rearrangeBarcodes(barcodes: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (rearrange-barcodes barcodes)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1054](https://leetcode-cn.com/problems/distant-barcodes)", "[\u8ddd\u79bb\u76f8\u7b49\u7684\u6761\u5f62\u7801](/solution/1000-1099/1054.Distant%20Barcodes/README.md)", "`\u5806`,`\u6392\u5e8f`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1054](https://leetcode.com/problems/distant-barcodes)", "[Distant Barcodes](/solution/1000-1099/1054.Distant%20Barcodes/README_EN.md)", "`Heap`,`Sort`", "Medium", ""]}, {"question_id": "1139", "frontend_question_id": "1053", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/previous-permutation-with-one-swap", "url_en": "https://leetcode.com/problems/previous-permutation-with-one-swap", "relative_path_cn": "/solution/1000-1099/1053.Previous%20Permutation%20With%20One%20Swap/README.md", "relative_path_en": "/solution/1000-1099/1053.Previous%20Permutation%20With%20One%20Swap/README_EN.md", "title_cn": "\u4ea4\u6362\u4e00\u6b21\u7684\u5148\u524d\u6392\u5217", "title_en": "Previous Permutation With One Swap", "question_title_slug": "previous-permutation-with-one-swap", "content_en": "

Given an array of positive integers arr (not necessarily distinct), return the lexicographically largest permutation that is smaller than arr, that can be made with exactly one swap (A swap exchanges the positions of two numbers arr[i] and arr[j]). If it cannot be done, then return the same array.

\n\n

 

\n

Example 1:

\n\n
\nInput: arr = [3,2,1]\nOutput: [3,1,2]\nExplanation: Swapping 2 and 1.\n
\n\n

Example 2:

\n\n
\nInput: arr = [1,1,5]\nOutput: [1,1,5]\nExplanation: This is already the smallest permutation.\n
\n\n

Example 3:

\n\n
\nInput: arr = [1,9,4,6,7]\nOutput: [1,7,4,6,9]\nExplanation: Swapping 9 and 7.\n
\n\n

Example 4:

\n\n
\nInput: arr = [3,1,1,3]\nOutput: [1,3,1,3]\nExplanation: Swapping 1 and 3.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= arr.length <= 104
  • \n\t
  • 1 <= arr[i] <= 104
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6b63\u6574\u6570\u7684\u6570\u7ec4 A\uff08\u5176\u4e2d\u7684\u5143\u7d20\u4e0d\u4e00\u5b9a\u5b8c\u5168\u4e0d\u540c\uff09\uff0c\u8bf7\u4f60\u8fd4\u56de\u53ef\u5728\u00a0\u4e00\u6b21\u4ea4\u6362\uff08\u4ea4\u6362\u4e24\u6570\u5b57 A[i] \u548c A[j] \u7684\u4f4d\u7f6e\uff09\u540e\u5f97\u5230\u7684\u3001\u6309\u5b57\u5178\u5e8f\u6392\u5217\u5c0f\u4e8e A \u7684\u6700\u5927\u53ef\u80fd\u6392\u5217\u3002

\n\n

\u5982\u679c\u65e0\u6cd5\u8fd9\u4e48\u64cd\u4f5c\uff0c\u5c31\u8bf7\u8fd4\u56de\u539f\u6570\u7ec4\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [3,2,1]\n\u8f93\u51fa\uff1a[3,1,2]\n\u89e3\u91ca\uff1a\u4ea4\u6362 2 \u548c 1\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [1,1,5]\n\u8f93\u51fa\uff1a[1,1,5]\n\u89e3\u91ca\uff1a\u5df2\u7ecf\u662f\u6700\u5c0f\u6392\u5217\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [1,9,4,6,7]\n\u8f93\u51fa\uff1a[1,7,4,6,9]\n\u89e3\u91ca\uff1a\u4ea4\u6362 9 \u548c 7\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [3,1,1,3]\n\u8f93\u51fa\uff1a[1,3,1,3]\n\u89e3\u91ca\uff1a\u4ea4\u6362 1 \u548c 3\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= arr.length <= 104
  • \n\t
  • 1 <= arr[i] <= 104
  • \n
\n", "tags_en": ["Greedy", "Array"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector prevPermOpt1(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] prevPermOpt1(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def prevPermOpt1(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def prevPermOpt1(self, arr: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* prevPermOpt1(int* arr, int arrSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] PrevPermOpt1(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number[]}\n */\nvar prevPermOpt1 = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer[]}\ndef prev_perm_opt1(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func prevPermOpt1(_ arr: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func prevPermOpt1(arr []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def prevPermOpt1(arr: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun prevPermOpt1(arr: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn prev_perm_opt1(arr: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer[]\n */\n function prevPermOpt1($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function prevPermOpt1(arr: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (prev-perm-opt1 arr)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1053](https://leetcode-cn.com/problems/previous-permutation-with-one-swap)", "[\u4ea4\u6362\u4e00\u6b21\u7684\u5148\u524d\u6392\u5217](/solution/1000-1099/1053.Previous%20Permutation%20With%20One%20Swap/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1053](https://leetcode.com/problems/previous-permutation-with-one-swap)", "[Previous Permutation With One Swap](/solution/1000-1099/1053.Previous%20Permutation%20With%20One%20Swap/README_EN.md)", "`Greedy`,`Array`", "Medium", ""]}, {"question_id": "1138", "frontend_question_id": "1052", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/grumpy-bookstore-owner", "url_en": "https://leetcode.com/problems/grumpy-bookstore-owner", "relative_path_cn": "/solution/1000-1099/1052.Grumpy%20Bookstore%20Owner/README.md", "relative_path_en": "/solution/1000-1099/1052.Grumpy%20Bookstore%20Owner/README_EN.md", "title_cn": "\u7231\u751f\u6c14\u7684\u4e66\u5e97\u8001\u677f", "title_en": "Grumpy Bookstore Owner", "question_title_slug": "grumpy-bookstore-owner", "content_en": "

Today, the bookstore owner has a store open for customers.length minutes.  Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.

\n\n

On some minutes, the bookstore owner is grumpy.  If the bookstore owner is grumpy on the i-th minute, grumpy[i] = 1, otherwise grumpy[i] = 0.  When the bookstore owner is grumpy, the customers of that minute are not satisfied, otherwise they are satisfied.

\n\n

The bookstore owner knows a secret technique to keep themselves not grumpy for minutes minutes straight, but can only use it once.

\n\n

Return the maximum number of customers that can be satisfied throughout the day.

\n\n

 

\n\n

Example 1:

\n\n
\nInput: customers = [1,0,1,2,1,1,7,5], grumpy = [0,1,0,1,0,1,0,1], minutes = 3\nOutput: 16\nExplanation: The bookstore owner keeps themselves not grumpy for the last 3 minutes. \nThe maximum number of customers that can be satisfied = 1 + 1 + 1 + 1 + 7 + 5 = 16.\n
\n\n

 

\n\n

Note:

\n\n
    \n\t
  • 1 <= minutes <= customers.length == grumpy.length <= 20000
  • \n\t
  • 0 <= customers[i] <= 1000
  • \n\t
  • 0 <= grumpy[i] <= 1
  • \n
\n", "content_cn": "

\u4eca\u5929\uff0c\u4e66\u5e97\u8001\u677f\u6709\u4e00\u5bb6\u5e97\u6253\u7b97\u8bd5\u8425\u4e1a\u00a0customers.length\u00a0\u5206\u949f\u3002\u6bcf\u5206\u949f\u90fd\u6709\u4e00\u4e9b\u987e\u5ba2\uff08customers[i]\uff09\u4f1a\u8fdb\u5165\u4e66\u5e97\uff0c\u6240\u6709\u8fd9\u4e9b\u987e\u5ba2\u90fd\u4f1a\u5728\u90a3\u4e00\u5206\u949f\u7ed3\u675f\u540e\u79bb\u5f00\u3002

\n\n

\u5728\u67d0\u4e9b\u65f6\u5019\uff0c\u4e66\u5e97\u8001\u677f\u4f1a\u751f\u6c14\u3002 \u5982\u679c\u4e66\u5e97\u8001\u677f\u5728\u7b2c i \u5206\u949f\u751f\u6c14\uff0c\u90a3\u4e48 grumpy[i] = 1\uff0c\u5426\u5219 grumpy[i] = 0\u3002 \u5f53\u4e66\u5e97\u8001\u677f\u751f\u6c14\u65f6\uff0c\u90a3\u4e00\u5206\u949f\u7684\u987e\u5ba2\u5c31\u4f1a\u4e0d\u6ee1\u610f\uff0c\u4e0d\u751f\u6c14\u5219\u4ed6\u4eec\u662f\u6ee1\u610f\u7684\u3002

\n\n

\u4e66\u5e97\u8001\u677f\u77e5\u9053\u4e00\u4e2a\u79d8\u5bc6\u6280\u5de7\uff0c\u80fd\u6291\u5236\u81ea\u5df1\u7684\u60c5\u7eea\uff0c\u53ef\u4ee5\u8ba9\u81ea\u5df1\u8fde\u7eed\u00a0X \u5206\u949f\u4e0d\u751f\u6c14\uff0c\u4f46\u5374\u53ea\u80fd\u4f7f\u7528\u4e00\u6b21\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u8fd9\u4e00\u5929\u8425\u4e1a\u4e0b\u6765\uff0c\u6700\u591a\u6709\u591a\u5c11\u5ba2\u6237\u80fd\u591f\u611f\u5230\u6ee1\u610f\u3002
\n\u00a0

\n\n

\u793a\u4f8b\uff1a

\n\n
\n\u8f93\u5165\uff1acustomers = [1,0,1,2,1,1,7,5], grumpy = [0,1,0,1,0,1,0,1], X = 3\n\u8f93\u51fa\uff1a16\n\u89e3\u91ca\uff1a\n\u4e66\u5e97\u8001\u677f\u5728\u6700\u540e 3 \u5206\u949f\u4fdd\u6301\u51b7\u9759\u3002\n\u611f\u5230\u6ee1\u610f\u7684\u6700\u5927\u5ba2\u6237\u6570\u91cf = 1 + 1 + 1 + 1 + 7 + 5 = 16.\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= X <=\u00a0customers.length ==\u00a0grumpy.length <= 20000
  • \n\t
  • 0 <=\u00a0customers[i] <= 1000
  • \n\t
  • 0 <=\u00a0grumpy[i] <= 1
  • \n
\n", "tags_en": ["Array", "Sliding Window"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxSatisfied(vector& customers, vector& grumpy, int minutes) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxSatisfied(int[] customers, int[] grumpy, int minutes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxSatisfied(self, customers, grumpy, minutes):\n \"\"\"\n :type customers: List[int]\n :type grumpy: List[int]\n :type minutes: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxSatisfied(self, customers: List[int], grumpy: List[int], minutes: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxSatisfied(int* customers, int customersSize, int* grumpy, int grumpySize, int minutes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxSatisfied(int[] customers, int[] grumpy, int minutes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} customers\n * @param {number[]} grumpy\n * @param {number} minutes\n * @return {number}\n */\nvar maxSatisfied = function(customers, grumpy, minutes) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} customers\n# @param {Integer[]} grumpy\n# @param {Integer} minutes\n# @return {Integer}\ndef max_satisfied(customers, grumpy, minutes)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxSatisfied(_ customers: [Int], _ grumpy: [Int], _ minutes: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxSatisfied(customers []int, grumpy []int, minutes int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxSatisfied(customers: Array[Int], grumpy: Array[Int], minutes: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxSatisfied(customers: IntArray, grumpy: IntArray, minutes: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_satisfied(customers: Vec, grumpy: Vec, minutes: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $customers\n * @param Integer[] $grumpy\n * @param Integer $minutes\n * @return Integer\n */\n function maxSatisfied($customers, $grumpy, $minutes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxSatisfied(customers: number[], grumpy: number[], minutes: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-satisfied customers grumpy minutes)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1052](https://leetcode-cn.com/problems/grumpy-bookstore-owner)", "[\u7231\u751f\u6c14\u7684\u4e66\u5e97\u8001\u677f](/solution/1000-1099/1052.Grumpy%20Bookstore%20Owner/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1052](https://leetcode.com/problems/grumpy-bookstore-owner)", "[Grumpy Bookstore Owner](/solution/1000-1099/1052.Grumpy%20Bookstore%20Owner/README_EN.md)", "`Array`,`Sliding Window`", "Medium", ""]}, {"question_id": "1137", "frontend_question_id": "1051", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/height-checker", "url_en": "https://leetcode.com/problems/height-checker", "relative_path_cn": "/solution/1000-1099/1051.Height%20Checker/README.md", "relative_path_en": "/solution/1000-1099/1051.Height%20Checker/README_EN.md", "title_cn": "\u9ad8\u5ea6\u68c0\u67e5\u5668", "title_en": "Height Checker", "question_title_slug": "height-checker", "content_en": "

A school is trying to take an annual photo of all the students. The students are asked to stand in a single file line in non-decreasing order by height. Let this ordering be represented by the integer array expected where expected[i] is the expected height of the ith student in line.

\n\n

You are given an integer array heights representing the current order that the students are standing in. Each heights[i] is the height of the ith student in line (0-indexed).

\n\n

Return the number of indices where heights[i] != expected[i].

\n\n

 

\n

Example 1:

\n\n
\nInput: heights = [1,1,4,2,1,3]\nOutput: 3\nExplanation: \nheights:  [1,1,4,2,1,3]\nexpected: [1,1,1,2,3,4]\nIndices 2, 4, and 5 do not match.\n
\n\n

Example 2:

\n\n
\nInput: heights = [5,1,2,3,4]\nOutput: 5\nExplanation:\nheights:  [5,1,2,3,4]\nexpected: [1,2,3,4,5]\nAll indices do not match.\n
\n\n

Example 3:

\n\n
\nInput: heights = [1,2,3,4,5]\nOutput: 0\nExplanation:\nheights:  [1,2,3,4,5]\nexpected: [1,2,3,4,5]\nAll indices match.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= heights.length <= 100
  • \n\t
  • 1 <= heights[i] <= 100
  • \n
\n", "content_cn": "

\u5b66\u6821\u5728\u62cd\u5e74\u5ea6\u7eaa\u5ff5\u7167\u65f6\uff0c\u4e00\u822c\u8981\u6c42\u5b66\u751f\u6309\u7167 \u975e\u9012\u51cf \u7684\u9ad8\u5ea6\u987a\u5e8f\u6392\u5217\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u80fd\u8ba9\u6240\u6709\u5b66\u751f\u4ee5 \u975e\u9012\u51cf \u9ad8\u5ea6\u6392\u5217\u7684\u6700\u5c0f\u5fc5\u8981\u79fb\u52a8\u4eba\u6570\u3002

\n\n

\u6ce8\u610f\uff0c\u5f53\u4e00\u7ec4\u5b66\u751f\u88ab\u9009\u4e2d\u65f6\uff0c\u4ed6\u4eec\u4e4b\u95f4\u53ef\u4ee5\u4ee5\u4efb\u4f55\u53ef\u80fd\u7684\u65b9\u5f0f\u91cd\u65b0\u6392\u5e8f\uff0c\u800c\u672a\u88ab\u9009\u4e2d\u7684\u5b66\u751f\u5e94\u8be5\u4fdd\u6301\u4e0d\u52a8\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b\uff1a

\n\n
\n\u8f93\u5165\uff1aheights =\u00a0[1,1,4,2,1,3]\n\u8f93\u51fa\uff1a3 \n\u89e3\u91ca\uff1a\n\u5f53\u524d\u6570\u7ec4\uff1a[1,1,4,2,1,3]\n\u76ee\u6807\u6570\u7ec4\uff1a[1,1,1,2,3,4]\n\u5728\u4e0b\u6807 2 \u5904\uff08\u4ece 0 \u5f00\u59cb\u8ba1\u6570\uff09\u51fa\u73b0 4 vs 1 \uff0c\u6240\u4ee5\u6211\u4eec\u5fc5\u987b\u79fb\u52a8\u8fd9\u540d\u5b66\u751f\u3002\n\u5728\u4e0b\u6807 4 \u5904\uff08\u4ece 0 \u5f00\u59cb\u8ba1\u6570\uff09\u51fa\u73b0 1 vs 3 \uff0c\u6240\u4ee5\u6211\u4eec\u5fc5\u987b\u79fb\u52a8\u8fd9\u540d\u5b66\u751f\u3002\n\u5728\u4e0b\u6807 5 \u5904\uff08\u4ece 0 \u5f00\u59cb\u8ba1\u6570\uff09\u51fa\u73b0 3 vs 4 \uff0c\u6240\u4ee5\u6211\u4eec\u5fc5\u987b\u79fb\u52a8\u8fd9\u540d\u5b66\u751f\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aheights = [5,1,2,3,4]\n\u8f93\u51fa\uff1a5\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1aheights = [1,2,3,4,5]\n\u8f93\u51fa\uff1a0\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= heights.length <= 100
  • \n\t
  • 1 <= heights[i] <= 100
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int heightChecker(vector& heights) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int heightChecker(int[] heights) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def heightChecker(self, heights):\n \"\"\"\n :type heights: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def heightChecker(self, heights: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint heightChecker(int* heights, int heightsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int HeightChecker(int[] heights) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} heights\n * @return {number}\n */\nvar heightChecker = function(heights) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} heights\n# @return {Integer}\ndef height_checker(heights)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func heightChecker(_ heights: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func heightChecker(heights []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def heightChecker(heights: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun heightChecker(heights: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn height_checker(heights: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $heights\n * @return Integer\n */\n function heightChecker($heights) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function heightChecker(heights: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (height-checker heights)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1051](https://leetcode-cn.com/problems/height-checker)", "[\u9ad8\u5ea6\u68c0\u67e5\u5668](/solution/1000-1099/1051.Height%20Checker/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1051](https://leetcode.com/problems/height-checker)", "[Height Checker](/solution/1000-1099/1051.Height%20Checker/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1136", "frontend_question_id": "1050", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/actors-and-directors-who-cooperated-at-least-three-times", "url_en": "https://leetcode.com/problems/actors-and-directors-who-cooperated-at-least-three-times", "relative_path_cn": "/solution/1000-1099/1050.Actors%20and%20Directors%20Who%20Cooperated%20At%20Least%20Three%20Times/README.md", "relative_path_en": "/solution/1000-1099/1050.Actors%20and%20Directors%20Who%20Cooperated%20At%20Least%20Three%20Times/README_EN.md", "title_cn": "\u5408\u4f5c\u8fc7\u81f3\u5c11\u4e09\u6b21\u7684\u6f14\u5458\u548c\u5bfc\u6f14", "title_en": "Actors and Directors Who Cooperated At Least Three Times", "question_title_slug": "actors-and-directors-who-cooperated-at-least-three-times", "content_en": "

Table: ActorDirector

\r\n\r\n
\r\n+-------------+---------+\r\n| Column Name | Type    |\r\n+-------------+---------+\r\n| actor_id    | int     |\r\n| director_id | int     |\r\n| timestamp   | int     |\r\n+-------------+---------+\r\ntimestamp is the primary key column for this table.\r\n
\r\n\r\n

 

\r\n\r\n

Write a SQL query for a report that provides the pairs (actor_id, director_id) where the actor have cooperated with the director at least 3 times.

\r\n\r\n

Example:

\r\n\r\n
\r\nActorDirector table:\r\n+-------------+-------------+-------------+\r\n| actor_id    | director_id | timestamp   |\r\n+-------------+-------------+-------------+\r\n| 1           | 1           | 0           |\r\n| 1           | 1           | 1           |\r\n| 1           | 1           | 2           |\r\n| 1           | 2           | 3           |\r\n| 1           | 2           | 4           |\r\n| 2           | 1           | 5           |\r\n| 2           | 1           | 6           |\r\n+-------------+-------------+-------------+\r\n\r\nResult table:\r\n+-------------+-------------+\r\n| actor_id    | director_id |\r\n+-------------+-------------+\r\n| 1           | 1           |\r\n+-------------+-------------+\r\nThe only pair is (1, 1) where they cooperated exactly 3 times.\r\n
\r\n", "content_cn": "

ActorDirector \u8868\uff1a

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| actor_id    | int     |\n| director_id | int     |\n| timestamp   | int     |\n+-------------+---------+\ntimestamp \u662f\u8fd9\u5f20\u8868\u7684\u4e3b\u952e.\n
\n\n

 

\n\n

\u5199\u4e00\u6761SQL\u67e5\u8be2\u8bed\u53e5\u83b7\u53d6\u5408\u4f5c\u8fc7\u81f3\u5c11\u4e09\u6b21\u7684\u6f14\u5458\u548c\u5bfc\u6f14\u7684 id \u5bf9 (actor_id, director_id)

\n\n

\u793a\u4f8b\uff1a

\n\n
\nActorDirector \u8868\uff1a\n+-------------+-------------+-------------+\n| actor_id    | director_id | timestamp   |\n+-------------+-------------+-------------+\n| 1           | 1           | 0           |\n| 1           | 1           | 1           |\n| 1           | 1           | 2           |\n| 1           | 2           | 3           |\n| 1           | 2           | 4           |\n| 2           | 1           | 5           |\n| 2           | 1           | 6           |\n+-------------+-------------+-------------+\n\nResult \u8868\uff1a\n+-------------+-------------+\n| actor_id    | director_id |\n+-------------+-------------+\n| 1           | 1           |\n+-------------+-------------+\n\u552f\u4e00\u7684 id \u5bf9\u662f (1, 1)\uff0c\u4ed6\u4eec\u6070\u597d\u5408\u4f5c\u4e86 3 \u6b21\u3002
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1050](https://leetcode-cn.com/problems/actors-and-directors-who-cooperated-at-least-three-times)", "[\u5408\u4f5c\u8fc7\u81f3\u5c11\u4e09\u6b21\u7684\u6f14\u5458\u548c\u5bfc\u6f14](/solution/1000-1099/1050.Actors%20and%20Directors%20Who%20Cooperated%20At%20Least%20Three%20Times/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1050](https://leetcode.com/problems/actors-and-directors-who-cooperated-at-least-three-times)", "[Actors and Directors Who Cooperated At Least Three Times](/solution/1000-1099/1050.Actors%20and%20Directors%20Who%20Cooperated%20At%20Least%20Three%20Times/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1135", "frontend_question_id": "1045", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/customers-who-bought-all-products", "url_en": "https://leetcode.com/problems/customers-who-bought-all-products", "relative_path_cn": "/solution/1000-1099/1045.Customers%20Who%20Bought%20All%20Products/README.md", "relative_path_en": "/solution/1000-1099/1045.Customers%20Who%20Bought%20All%20Products/README_EN.md", "title_cn": "\u4e70\u4e0b\u6240\u6709\u4ea7\u54c1\u7684\u5ba2\u6237", "title_en": "Customers Who Bought All Products", "question_title_slug": "customers-who-bought-all-products", "content_en": "

Table: Customer

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| customer_id | int     |\n| product_key | int     |\n+-------------+---------+\nproduct_key is a foreign key to Product table.\n
\n\n

 

\n\n

Table: Product

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| product_key | int     |\n+-------------+---------+\nproduct_key is the primary key column for this table.\n
\n\n

 

\n\n

Write an SQL query for a report that provides the customer ids from the Customer table that bought all the products in the Product table.

\n\n

Return the result table in any order.

\n\n

The query result format is in the following example:

\n\n

 

\n\n
\nCustomer table:\n+-------------+-------------+\n| customer_id | product_key |\n+-------------+-------------+\n| 1           | 5           |\n| 2           | 6           |\n| 3           | 5           |\n| 3           | 6           |\n| 1           | 6           |\n+-------------+-------------+\n\nProduct table:\n+-------------+\n| product_key |\n+-------------+\n| 5           |\n| 6           |\n+-------------+\n\nResult table:\n+-------------+\n| customer_id |\n+-------------+\n| 1           |\n| 3           |\n+-------------+\nThe customers who bought all the products (5 and 6) are customers with id 1 and 3.\n
\n", "content_cn": "

Customer \u8868\uff1a

\n\n
+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| customer_id | int     |\n| product_key | int     |\n+-------------+---------+\nproduct_key \u662f Customer \u8868\u7684\u5916\u952e\u3002\n
\n\n

Product \u8868\uff1a

\n\n
+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| product_key | int     |\n+-------------+---------+\nproduct_key \u662f\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\u3002\n
\n\n

 

\n\n

\u5199\u4e00\u6761 SQL \u67e5\u8be2\u8bed\u53e5\uff0c\u4ece Customer \u8868\u4e2d\u67e5\u8be2\u8d2d\u4e70\u4e86 Product \u8868\u4e2d\u6240\u6709\u4ea7\u54c1\u7684\u5ba2\u6237\u7684 id\u3002

\n\n

\u793a\u4f8b\uff1a

\n\n
Customer \u8868\uff1a\n+-------------+-------------+\n| customer_id | product_key |\n+-------------+-------------+\n| 1           | 5           |\n| 2           | 6           |\n| 3           | 5           |\n| 3           | 6           |\n| 1           | 6           |\n+-------------+-------------+\n\nProduct \u8868\uff1a\n+-------------+\n| product_key |\n+-------------+\n| 5           |\n| 6           |\n+-------------+\n\nResult \u8868\uff1a\n+-------------+\n| customer_id |\n+-------------+\n| 1           |\n| 3           |\n+-------------+\n\u8d2d\u4e70\u4e86\u6240\u6709\u4ea7\u54c1\uff085 \u548c 6\uff09\u7684\u5ba2\u6237\u7684 id \u662f 1 \u548c 3 \u3002\n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1045](https://leetcode-cn.com/problems/customers-who-bought-all-products)", "[\u4e70\u4e0b\u6240\u6709\u4ea7\u54c1\u7684\u5ba2\u6237](/solution/1000-1099/1045.Customers%20Who%20Bought%20All%20Products/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1045](https://leetcode.com/problems/customers-who-bought-all-products)", "[Customers Who Bought All Products](/solution/1000-1099/1045.Customers%20Who%20Bought%20All%20Products/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1134", "frontend_question_id": "1182", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/shortest-distance-to-target-color", "url_en": "https://leetcode.com/problems/shortest-distance-to-target-color", "relative_path_cn": "/solution/1100-1199/1182.Shortest%20Distance%20to%20Target%20Color/README.md", "relative_path_en": "/solution/1100-1199/1182.Shortest%20Distance%20to%20Target%20Color/README_EN.md", "title_cn": "\u4e0e\u76ee\u6807\u989c\u8272\u95f4\u7684\u6700\u77ed\u8ddd\u79bb", "title_en": "Shortest Distance to Target Color", "question_title_slug": "shortest-distance-to-target-color", "content_en": "

You are given an array colors, in which there are three colors: 1, 2 and 3.

\n\n

You are also given some queries. Each query consists of two integers i and c, return the shortest distance between the given index i and the target color c. If there is no solution return -1.

\n\n

 

\n

Example 1:

\n\n
\nInput: colors = [1,1,2,1,3,2,2,3,3], queries = [[1,3],[2,2],[6,1]]\nOutput: [3,0,3]\nExplanation: \nThe nearest 3 from index 1 is at index 4 (3 steps away).\nThe nearest 2 from index 2 is at index 2 itself (0 steps away).\nThe nearest 1 from index 6 is at index 3 (3 steps away).\n
\n\n

Example 2:

\n\n
\nInput: colors = [1,2], queries = [[0,3]]\nOutput: [-1]\nExplanation: There is no 3 in the array.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= colors.length <= 5*10^4
  • \n\t
  • 1 <= colors[i] <= 3
  • \n\t
  • 1 <= queries.length <= 5*10^4
  • \n\t
  • queries[i].length == 2
  • \n\t
  • 0 <= queries[i][0] < colors.length
  • \n\t
  • 1 <= queries[i][1] <= 3
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 colors\uff0c\u91cc\u9762\u6709  1\u30012\u3001 3 \u4e09\u79cd\u989c\u8272\u3002

\n\n

\u6211\u4eec\u9700\u8981\u5728 colors \u4e0a\u8fdb\u884c\u4e00\u4e9b\u67e5\u8be2\u64cd\u4f5c queries\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5f85\u67e5\u9879\u90fd\u7531\u4e24\u4e2a\u6574\u6570 i \u548c c \u7ec4\u6210\u3002

\n\n

\u73b0\u5728\u8bf7\u4f60\u5e2e\u5fd9\u8bbe\u8ba1\u4e00\u4e2a\u7b97\u6cd5\uff0c\u67e5\u627e\u4ece\u7d22\u5f15 i \u5230\u5177\u6709\u76ee\u6807\u989c\u8272 c \u7684\u5143\u7d20\u4e4b\u95f4\u7684\u6700\u77ed\u8ddd\u79bb\u3002

\n\n

\u5982\u679c\u4e0d\u5b58\u5728\u89e3\u51b3\u65b9\u6848\uff0c\u8bf7\u8fd4\u56de -1\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1acolors = [1,1,2,1,3,2,2,3,3], queries = [[1,3],[2,2],[6,1]]\n\u8f93\u51fa\uff1a[3,0,3]\n\u89e3\u91ca\uff1a \n\u8ddd\u79bb\u7d22\u5f15 1 \u6700\u8fd1\u7684\u989c\u8272 3 \u4f4d\u4e8e\u7d22\u5f15 4\uff08\u8ddd\u79bb\u4e3a 3\uff09\u3002\n\u8ddd\u79bb\u7d22\u5f15 2 \u6700\u8fd1\u7684\u989c\u8272 2 \u5c31\u662f\u5b83\u81ea\u5df1\uff08\u8ddd\u79bb\u4e3a 0\uff09\u3002\n\u8ddd\u79bb\u7d22\u5f15 6 \u6700\u8fd1\u7684\u989c\u8272 1 \u4f4d\u4e8e\u7d22\u5f15 3\uff08\u8ddd\u79bb\u4e3a 3\uff09\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1acolors = [1,2], queries = [[0,3]]\n\u8f93\u51fa\uff1a[-1]\n\u89e3\u91ca\uff1acolors \u4e2d\u6ca1\u6709\u989c\u8272 3\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= colors.length <= 5*10^4
  • \n\t
  • 1 <= colors[i] <= 3
  • \n\t
  • 1 <= queries.length <= 5*10^4
  • \n\t
  • queries[i].length == 2
  • \n\t
  • 0 <= queries[i][0] < colors.length
  • \n\t
  • 1 <= queries[i][1] <= 3
  • \n
\n", "tags_en": ["Binary Search"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector shortestDistanceColor(vector& colors, vector>& queries) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List shortestDistanceColor(int[] colors, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def shortestDistanceColor(self, colors, queries):\n \"\"\"\n :type colors: List[int]\n :type queries: List[List[int]]\n :rtype: List[int]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def shortestDistanceColor(self, colors: List[int], queries: List[List[int]]) -> List[int]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* shortestDistanceColor(int* colors, int colorsSize, int** queries, int queriesSize, int* queriesColSize, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList ShortestDistanceColor(int[] colors, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} colors\n * @param {number[][]} queries\n * @return {number[]}\n */\nvar shortestDistanceColor = function(colors, queries) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} colors\n# @param {Integer[][]} queries\n# @return {Integer[]}\ndef shortest_distance_color(colors, queries)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func shortestDistanceColor(_ colors: [Int], _ queries: [[Int]]) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func shortestDistanceColor(colors []int, queries [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def shortestDistanceColor(colors: Array[Int], queries: Array[Array[Int]]): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun shortestDistanceColor(colors: IntArray, queries: Array): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn shortest_distance_color(colors: Vec, queries: Vec>) -> Vec {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $colors\n * @param Integer[][] $queries\n * @return Integer[]\n */\n function shortestDistanceColor($colors, $queries) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function shortestDistanceColor(colors: number[], queries: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (shortest-distance-color colors queries)\n (-> (listof exact-integer?) (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1182](https://leetcode-cn.com/problems/shortest-distance-to-target-color)", "[\u4e0e\u76ee\u6807\u989c\u8272\u95f4\u7684\u6700\u77ed\u8ddd\u79bb](/solution/1100-1199/1182.Shortest%20Distance%20to%20Target%20Color/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1182](https://leetcode.com/problems/shortest-distance-to-target-color)", "[Shortest Distance to Target Color](/solution/1100-1199/1182.Shortest%20Distance%20to%20Target%20Color/README_EN.md)", "`Binary Search`", "Medium", "\ud83d\udd12"]}, {"question_id": "1133", "frontend_question_id": "1163", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/last-substring-in-lexicographical-order", "url_en": "https://leetcode.com/problems/last-substring-in-lexicographical-order", "relative_path_cn": "/solution/1100-1199/1163.Last%20Substring%20in%20Lexicographical%20Order/README.md", "relative_path_en": "/solution/1100-1199/1163.Last%20Substring%20in%20Lexicographical%20Order/README_EN.md", "title_cn": "\u6309\u5b57\u5178\u5e8f\u6392\u5728\u6700\u540e\u7684\u5b50\u4e32", "title_en": "Last Substring in Lexicographical Order", "question_title_slug": "last-substring-in-lexicographical-order", "content_en": "

Given a string s, return the last substring of s in lexicographical order.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "abab"\nOutput: "bab"\nExplanation: The substrings are ["a", "ab", "aba", "abab", "b", "ba", "bab"]. The lexicographically maximum substring is "bab".\n
\n\n

Example 2:

\n\n
\nInput: s = "leetcode"\nOutput: "tcode"\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 4 * 105
  • \n\t
  • s contains only lowercase English letters.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s\uff0c\u627e\u51fa\u5b83\u7684\u6240\u6709\u5b50\u4e32\u5e76\u6309\u5b57\u5178\u5e8f\u6392\u5217\uff0c\u8fd4\u56de\u6392\u5728\u6700\u540e\u7684\u90a3\u4e2a\u5b50\u4e32\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a"abab"\n\u8f93\u51fa\uff1a"bab"\n\u89e3\u91ca\uff1a\u6211\u4eec\u53ef\u4ee5\u627e\u51fa 7 \u4e2a\u5b50\u4e32 ["a", "ab", "aba", "abab", "b", "ba", "bab"]\u3002\u6309\u5b57\u5178\u5e8f\u6392\u5728\u6700\u540e\u7684\u5b50\u4e32\u662f "bab"\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a"leetcode"\n\u8f93\u51fa\uff1a"tcode"\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= s.length <= 4 * 10^5
  2. \n\t
  3. s \u4ec5\u542b\u6709\u5c0f\u5199\u82f1\u6587\u5b57\u7b26\u3002
  4. \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string lastSubstring(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String lastSubstring(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def lastSubstring(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def lastSubstring(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * lastSubstring(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string LastSubstring(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar lastSubstring = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef last_substring(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func lastSubstring(_ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func lastSubstring(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def lastSubstring(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun lastSubstring(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn last_substring(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function lastSubstring($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function lastSubstring(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (last-substring s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1163](https://leetcode-cn.com/problems/last-substring-in-lexicographical-order)", "[\u6309\u5b57\u5178\u5e8f\u6392\u5728\u6700\u540e\u7684\u5b50\u4e32](/solution/1100-1199/1163.Last%20Substring%20in%20Lexicographical%20Order/README.md)", "`\u5b57\u7b26\u4e32`", "\u56f0\u96be", ""], "md_table_row_en": ["[1163](https://leetcode.com/problems/last-substring-in-lexicographical-order)", "[Last Substring in Lexicographical Order](/solution/1100-1199/1163.Last%20Substring%20in%20Lexicographical%20Order/README_EN.md)", "`String`", "Hard", ""]}, {"question_id": "1132", "frontend_question_id": "1181", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/before-and-after-puzzle", "url_en": "https://leetcode.com/problems/before-and-after-puzzle", "relative_path_cn": "/solution/1100-1199/1181.Before%20and%20After%20Puzzle/README.md", "relative_path_en": "/solution/1100-1199/1181.Before%20and%20After%20Puzzle/README_EN.md", "title_cn": "\u524d\u540e\u62fc\u63a5", "title_en": "Before and After Puzzle", "question_title_slug": "before-and-after-puzzle", "content_en": "

Given a list of phrases, generate a list of Before and After puzzles.

\n\n

A phrase is a string that consists of lowercase English letters and spaces only. No space appears in the start or the end of a phrase. There are no consecutive spaces in a phrase.

\n\n

Before and After puzzles are phrases that are formed by merging two phrases where the last word of the first phrase is the same as the first word of the second phrase.

\n\n

Return the Before and After puzzles that can be formed by every two phrases phrases[i] and phrases[j] where i != j. Note that the order of matching two phrases matters, we want to consider both orders.

\n\n

You should return a list of distinct strings sorted lexicographically.

\n\n

 

\n

Example 1:

\n\n
\nInput: phrases = ["writing code","code rocks"]\nOutput: ["writing code rocks"]\n
\n\n

Example 2:

\n\n
\nInput: phrases = ["mission statement",\n                  "a quick bite to eat",\n                  "a chip off the old block",\n                  "chocolate bar",\n                  "mission impossible",\n                  "a man on a mission",\n                  "block party",\n                  "eat my words",\n                  "bar of soap"]\nOutput: ["a chip off the old block party",\n         "a man on a mission impossible",\n         "a man on a mission statement",\n         "a quick bite to eat my words",\n         "chocolate bar of soap"]\n
\n\n

Example 3:

\n\n
\nInput: phrases = ["a","b","a"]\nOutput: ["a"]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= phrases.length <= 100
  • \n\t
  • 1 <= phrases[i].length <= 100
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u300c\u77ed\u8bed\u300d\u5217\u8868 phrases\uff0c\u8bf7\u4f60\u5e2e\u5fd9\u6309\u89c4\u5219\u751f\u6210\u62fc\u63a5\u540e\u7684\u300c\u65b0\u77ed\u8bed\u300d\u5217\u8868\u3002

\n\n

\u300c\u77ed\u8bed\u300d\uff08phrase\uff09\u662f\u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u548c\u7a7a\u683c\u7ec4\u6210\u7684\u5b57\u7b26\u4e32\u3002\u300c\u77ed\u8bed\u300d\u7684\u5f00\u5934\u548c\u7ed3\u5c3e\u90fd\u4e0d\u4f1a\u51fa\u73b0\u7a7a\u683c\uff0c\u300c\u77ed\u8bed\u300d\u4e2d\u7684\u7a7a\u683c\u4e0d\u4f1a\u8fde\u7eed\u51fa\u73b0\u3002

\n\n

\u300c\u524d\u540e\u62fc\u63a5\u300d\uff08Before and After puzzles\uff09\u662f\u5408\u5e76\u4e24\u4e2a\u300c\u77ed\u8bed\u300d\u5f62\u6210\u300c\u65b0\u77ed\u8bed\u300d\u7684\u65b9\u6cd5\u3002\u6211\u4eec\u89c4\u5b9a\u62fc\u63a5\u65f6\uff0c\u7b2c\u4e00\u4e2a\u77ed\u8bed\u7684\u6700\u540e\u4e00\u4e2a\u5355\u8bcd \u548c \u7b2c\u4e8c\u4e2a\u77ed\u8bed\u7684\u7b2c\u4e00\u4e2a\u5355\u8bcd \u5fc5\u987b\u76f8\u540c\u3002

\n\n

\u8fd4\u56de\u6bcf\u4e24\u4e2a\u300c\u77ed\u8bed\u300d phrases[i] \u548c phrases[j]\uff08i != j\uff09\u8fdb\u884c\u300c\u524d\u540e\u62fc\u63a5\u300d\u5f97\u5230\u7684\u300c\u65b0\u77ed\u8bed\u300d\u3002

\n\n

\u6ce8\u610f\uff0c\u4e24\u4e2a\u300c\u77ed\u8bed\u300d\u62fc\u63a5\u65f6\u7684\u987a\u5e8f\u4e5f\u5f88\u91cd\u8981\uff0c\u6211\u4eec\u9700\u8981\u540c\u65f6\u8003\u8651\u8fd9\u4e24\u4e2a\u300c\u77ed\u8bed\u300d\u3002\u53e6\u5916\uff0c\u540c\u4e00\u4e2a\u300c\u77ed\u8bed\u300d\u53ef\u4ee5\u591a\u6b21\u53c2\u4e0e\u62fc\u63a5\uff0c\u4f46\u300c\u65b0\u77ed\u8bed\u300d\u4e0d\u80fd\u518d\u53c2\u4e0e\u62fc\u63a5\u3002

\n\n

\u8bf7\u4f60\u6309\u5b57\u5178\u5e8f\u6392\u5217\u5e76\u8fd4\u56de\u300c\u65b0\u77ed\u8bed\u300d\u5217\u8868\uff0c\u5217\u8868\u4e2d\u7684\u5b57\u7b26\u4e32\u5e94\u8be5\u662f \u4e0d\u91cd\u590d\u7684 \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aphrases = ["writing code","code rocks"]\n\u8f93\u51fa\uff1a["writing code rocks"]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aphrases = ["mission statement",\n                "a quick bite to eat",\n                "a chip off the old block",\n                "chocolate bar",\n                "mission impossible",\n                "a man on a mission",\n                "block party",\n                "eat my words",\n                "bar of soap"]\n\u8f93\u51fa\uff1a["a chip off the old block party",\n      "a man on a mission impossible",\n      "a man on a mission statement",\n      "a quick bite to eat my words",\n      "chocolate bar of soap"]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aphrases = ["a","b","a"]\n\u8f93\u51fa\uff1a["a"]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= phrases.length <= 100
  • \n\t
  • 1 <= phrases[i].length <= 100
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector beforeAndAfterPuzzles(vector& phrases) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List beforeAndAfterPuzzles(String[] phrases) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def beforeAndAfterPuzzles(self, phrases):\n \"\"\"\n :type phrases: List[str]\n :rtype: List[str]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def beforeAndAfterPuzzles(self, phrases: List[str]) -> List[str]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** beforeAndAfterPuzzles(char ** phrases, int phrasesSize, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList BeforeAndAfterPuzzles(string[] phrases) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} phrases\n * @return {string[]}\n */\nvar beforeAndAfterPuzzles = function(phrases) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} phrases\n# @return {String[]}\ndef before_and_after_puzzles(phrases)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func beforeAndAfterPuzzles(_ phrases: [String]) -> [String] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func beforeAndAfterPuzzles(phrases []string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def beforeAndAfterPuzzles(phrases: Array[String]): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun beforeAndAfterPuzzles(phrases: Array): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn before_and_after_puzzles(phrases: Vec) -> Vec {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $phrases\n * @return String[]\n */\n function beforeAndAfterPuzzles($phrases) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function beforeAndAfterPuzzles(phrases: string[]): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (before-and-after-puzzles phrases)\n (-> (listof string?) (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1181](https://leetcode-cn.com/problems/before-and-after-puzzle)", "[\u524d\u540e\u62fc\u63a5](/solution/1100-1199/1181.Before%20and%20After%20Puzzle/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1181](https://leetcode.com/problems/before-and-after-puzzle)", "[Before and After Puzzle](/solution/1100-1199/1181.Before%20and%20After%20Puzzle/README_EN.md)", "`String`", "Medium", "\ud83d\udd12"]}, {"question_id": "1131", "frontend_question_id": "1180", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/count-substrings-with-only-one-distinct-letter", "url_en": "https://leetcode.com/problems/count-substrings-with-only-one-distinct-letter", "relative_path_cn": "/solution/1100-1199/1180.Count%20Substrings%20with%20Only%20One%20Distinct%20Letter/README.md", "relative_path_en": "/solution/1100-1199/1180.Count%20Substrings%20with%20Only%20One%20Distinct%20Letter/README_EN.md", "title_cn": "\u7edf\u8ba1\u53ea\u542b\u5355\u4e00\u5b57\u6bcd\u7684\u5b50\u4e32", "title_en": "Count Substrings with Only One Distinct Letter", "question_title_slug": "count-substrings-with-only-one-distinct-letter", "content_en": "

Given a string s, return the number of substrings that have only one distinct letter.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "aaaba"\nOutput: 8\nExplanation: The substrings with one distinct letter are "aaa", "aa", "a", "b".\n"aaa" occurs 1 time.\n"aa" occurs 2 times.\n"a" occurs 4 times.\n"b" occurs 1 time.\nSo the answer is 1 + 2 + 4 + 1 = 8.\n
\n\n

Example 2:

\n\n
\nInput: s = "aaaaaaaaaa"\nOutput: 55\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 1000
  • \n\t
  • s[i] consists of only lowercase English letters.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 S\uff0c\u8fd4\u56de\u53ea\u542b \u5355\u4e00\u5b57\u6bcd \u7684\u5b50\u4e32\u4e2a\u6570\u3002

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a "aaaba"\n\u8f93\u51fa\uff1a 8\n\u89e3\u91ca\uff1a \n\u53ea\u542b\u5355\u4e00\u5b57\u6bcd\u7684\u5b50\u4e32\u5206\u522b\u662f "aaa"\uff0c "aa"\uff0c "a"\uff0c "b"\u3002\n"aaa" \u51fa\u73b0 1 \u6b21\u3002\n"aa" \u51fa\u73b0 2 \u6b21\u3002\n"a" \u51fa\u73b0 4 \u6b21\u3002\n"b" \u51fa\u73b0 1 \u6b21\u3002\n\u6240\u4ee5\u7b54\u6848\u662f 1 + 2 + 4 + 1 = 8\u3002\n
\n\n

\u793a\u4f8b 2:

\n\n
\u8f93\u5165\uff1a "aaaaaaaaaa"\n\u8f93\u51fa\uff1a 55\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= S.length <= 1000
  2. \n\t
  3. S[i] \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\u3002
  4. \n
\n", "tags_en": ["Math", "String"], "tags_cn": ["\u6570\u5b66", "\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countLetters(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countLetters(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countLetters(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countLetters(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countLetters(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountLetters(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar countLetters = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef count_letters(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countLetters(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countLetters(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countLetters(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countLetters(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_letters(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function countLetters($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countLetters(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-letters s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1180](https://leetcode-cn.com/problems/count-substrings-with-only-one-distinct-letter)", "[\u7edf\u8ba1\u53ea\u542b\u5355\u4e00\u5b57\u6bcd\u7684\u5b50\u4e32](/solution/1100-1199/1180.Count%20Substrings%20with%20Only%20One%20Distinct%20Letter/README.md)", "`\u6570\u5b66`,`\u5b57\u7b26\u4e32`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1180](https://leetcode.com/problems/count-substrings-with-only-one-distinct-letter)", "[Count Substrings with Only One Distinct Letter](/solution/1100-1199/1180.Count%20Substrings%20with%20Only%20One%20Distinct%20Letter/README_EN.md)", "`Math`,`String`", "Easy", "\ud83d\udd12"]}, {"question_id": "1130", "frontend_question_id": "1049", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/last-stone-weight-ii", "url_en": "https://leetcode.com/problems/last-stone-weight-ii", "relative_path_cn": "/solution/1000-1099/1049.Last%20Stone%20Weight%20II/README.md", "relative_path_en": "/solution/1000-1099/1049.Last%20Stone%20Weight%20II/README_EN.md", "title_cn": "\u6700\u540e\u4e00\u5757\u77f3\u5934\u7684\u91cd\u91cf II", "title_en": "Last Stone Weight II", "question_title_slug": "last-stone-weight-ii", "content_en": "

You are given an array of integers stones where stones[i] is the weight of the ith stone.

\n\n

We are playing a game with the stones. On each turn, we choose any two stones and smash them together. Suppose the stones have weights x and y with x <= y. The result of this smash is:

\n\n
    \n\t
  • If x == y, both stones are destroyed, and
  • \n\t
  • If x != y, the stone of weight x is destroyed, and the stone of weight y has new weight y - x.
  • \n
\n\n

At the end of the game, there is at most one stone left.

\n\n

Return the smallest possible weight of the left stone. If there are no stones left, return 0.

\n\n

 

\n

Example 1:

\n\n
\nInput: stones = [2,7,4,1,8,1]\nOutput: 1\nExplanation:\nWe can combine 2 and 4 to get 2, so the array converts to [2,7,1,8,1] then,\nwe can combine 7 and 8 to get 1, so the array converts to [2,1,1,1] then,\nwe can combine 2 and 1 to get 1, so the array converts to [1,1,1] then,\nwe can combine 1 and 1 to get 0, so the array converts to [1], then that's the optimal value.\n
\n\n

Example 2:

\n\n
\nInput: stones = [31,26,33,21,40]\nOutput: 5\n
\n\n

Example 3:

\n\n
\nInput: stones = [1,2]\nOutput: 1\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= stones.length <= 30
  • \n\t
  • 1 <= stones[i] <= 100
  • \n
\n", "content_cn": "

\u6709\u4e00\u5806\u77f3\u5934\uff0c\u6bcf\u5757\u77f3\u5934\u7684\u91cd\u91cf\u90fd\u662f\u6b63\u6574\u6570\u3002

\n\n

\u6bcf\u4e00\u56de\u5408\uff0c\u4ece\u4e2d\u9009\u51fa\u4efb\u610f\u4e24\u5757\u77f3\u5934\uff0c\u7136\u540e\u5c06\u5b83\u4eec\u4e00\u8d77\u7c89\u788e\u3002\u5047\u8bbe\u77f3\u5934\u7684\u91cd\u91cf\u5206\u522b\u4e3a x \u548c y\uff0c\u4e14 x <= y\u3002\u90a3\u4e48\u7c89\u788e\u7684\u53ef\u80fd\u7ed3\u679c\u5982\u4e0b\uff1a

\n\n
    \n\t
  • \u5982\u679c x == y\uff0c\u90a3\u4e48\u4e24\u5757\u77f3\u5934\u90fd\u4f1a\u88ab\u5b8c\u5168\u7c89\u788e\uff1b
  • \n\t
  • \u5982\u679c x != y\uff0c\u90a3\u4e48\u91cd\u91cf\u4e3a x \u7684\u77f3\u5934\u5c06\u4f1a\u5b8c\u5168\u7c89\u788e\uff0c\u800c\u91cd\u91cf\u4e3a y \u7684\u77f3\u5934\u65b0\u91cd\u91cf\u4e3a y-x\u3002
  • \n
\n\n

\u6700\u540e\uff0c\u6700\u591a\u53ea\u4f1a\u5269\u4e0b\u4e00\u5757\u77f3\u5934\u3002\u8fd4\u56de\u6b64\u77f3\u5934\u6700\u5c0f\u7684\u53ef\u80fd\u91cd\u91cf\u3002\u5982\u679c\u6ca1\u6709\u77f3\u5934\u5269\u4e0b\uff0c\u5c31\u8fd4\u56de 0\u3002

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1a[2,7,4,1,8,1]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\n\u7ec4\u5408 2 \u548c 4\uff0c\u5f97\u5230 2\uff0c\u6240\u4ee5\u6570\u7ec4\u8f6c\u5316\u4e3a [2,7,1,8,1]\uff0c\n\u7ec4\u5408 7 \u548c 8\uff0c\u5f97\u5230 1\uff0c\u6240\u4ee5\u6570\u7ec4\u8f6c\u5316\u4e3a [2,1,1,1]\uff0c\n\u7ec4\u5408 2 \u548c 1\uff0c\u5f97\u5230 1\uff0c\u6240\u4ee5\u6570\u7ec4\u8f6c\u5316\u4e3a [1,1,1]\uff0c\n\u7ec4\u5408 1 \u548c 1\uff0c\u5f97\u5230 0\uff0c\u6240\u4ee5\u6570\u7ec4\u8f6c\u5316\u4e3a [1]\uff0c\u8fd9\u5c31\u662f\u6700\u4f18\u503c\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= stones.length <= 30
  2. \n\t
  3. 1 <= stones[i] <= 1000
  4. \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int lastStoneWeightII(vector& stones) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int lastStoneWeightII(int[] stones) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def lastStoneWeightII(self, stones):\n \"\"\"\n :type stones: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def lastStoneWeightII(self, stones: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint lastStoneWeightII(int* stones, int stonesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LastStoneWeightII(int[] stones) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} stones\n * @return {number}\n */\nvar lastStoneWeightII = function(stones) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} stones\n# @return {Integer}\ndef last_stone_weight_ii(stones)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func lastStoneWeightII(_ stones: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func lastStoneWeightII(stones []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def lastStoneWeightII(stones: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun lastStoneWeightII(stones: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn last_stone_weight_ii(stones: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $stones\n * @return Integer\n */\n function lastStoneWeightII($stones) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function lastStoneWeightII(stones: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (last-stone-weight-ii stones)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1049](https://leetcode-cn.com/problems/last-stone-weight-ii)", "[\u6700\u540e\u4e00\u5757\u77f3\u5934\u7684\u91cd\u91cf II](/solution/1000-1099/1049.Last%20Stone%20Weight%20II/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1049](https://leetcode.com/problems/last-stone-weight-ii)", "[Last Stone Weight II](/solution/1000-1099/1049.Last%20Stone%20Weight%20II/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "1129", "frontend_question_id": "1048", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-string-chain", "url_en": "https://leetcode.com/problems/longest-string-chain", "relative_path_cn": "/solution/1000-1099/1048.Longest%20String%20Chain/README.md", "relative_path_en": "/solution/1000-1099/1048.Longest%20String%20Chain/README_EN.md", "title_cn": "\u6700\u957f\u5b57\u7b26\u4e32\u94fe", "title_en": "Longest String Chain", "question_title_slug": "longest-string-chain", "content_en": "

You are given an array of words where each word consists of lowercase English letters.

\n\n

wordA is a predecessor of wordB if and only if we can insert exactly one letter anywhere in wordA without changing the order of the other characters to make it equal to wordB.

\n\n
    \n\t
  • For example, "abc" is a predecessor of "abac", while "cba" is not a predecessor of "bcad".
  • \n
\n\n

A word chain is a sequence of words [word1, word2, ..., wordk] with k >= 1, where word1 is a predecessor of word2, word2 is a predecessor of word3, and so on. A single word is trivially a word chain with k == 1.

\n\n

Return the length of the longest possible word chain with words chosen from the given list of words.

\n\n

 

\n

Example 1:

\n\n
\nInput: words = ["a","b","ba","bca","bda","bdca"]\nOutput: 4\nExplanation: One of the longest word chains is ["a","ba","bda","bdca"].\n
\n\n

Example 2:

\n\n
\nInput: words = ["xbc","pcxbcf","xb","cxbc","pcxbc"]\nOutput: 5\nExplanation: All the words can be put in a word chain ["xb", "xbc", "cxbc", "pcxbc", "pcxbcf"].\n
\n\n

Example 3:

\n\n
\nInput: words = ["abcd","dbqca"]\nOutput: 1\nExplanation: The trivial word chain ["abcd"] is one of the longest word chains.\n["abcd","dbqca"] is not a valid word chain because the ordering of the letters is changed.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= words.length <= 1000
  • \n\t
  • 1 <= words[i].length <= 16
  • \n\t
  • words[i] only consists of lowercase English letters.
  • \n
\n", "content_cn": "

\u7ed9\u51fa\u4e00\u4e2a\u5355\u8bcd\u5217\u8868\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5355\u8bcd\u90fd\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\u3002

\n\n

\u5982\u679c\u6211\u4eec\u53ef\u4ee5\u5728 word1 \u7684\u4efb\u4f55\u5730\u65b9\u6dfb\u52a0\u4e00\u4e2a\u5b57\u6bcd\u4f7f\u5176\u53d8\u6210 word2\uff0c\u90a3\u4e48\u6211\u4eec\u8ba4\u4e3a word1 \u662f word2 \u7684\u524d\u8eab\u3002\u4f8b\u5982\uff0c"abc" \u662f "abac" \u7684\u524d\u8eab\u3002

\n\n

\u8bcd\u94fe\u662f\u5355\u8bcd [word_1, word_2, ..., word_k] \u7ec4\u6210\u7684\u5e8f\u5217\uff0ck >= 1\uff0c\u5176\u4e2d word_1 \u662f word_2 \u7684\u524d\u8eab\uff0cword_2 \u662f word_3 \u7684\u524d\u8eab\uff0c\u4f9d\u6b64\u7c7b\u63a8\u3002

\n\n

\u4ece\u7ed9\u5b9a\u5355\u8bcd\u5217\u8868 words \u4e2d\u9009\u62e9\u5355\u8bcd\u7ec4\u6210\u8bcd\u94fe\uff0c\u8fd4\u56de\u8bcd\u94fe\u7684\u6700\u957f\u53ef\u80fd\u957f\u5ea6\u3002
\n 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1a["a","b","ba","bca","bda","bdca"]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u6700\u957f\u5355\u8bcd\u94fe\u4e4b\u4e00\u4e3a "a","ba","bda","bdca"\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= words.length <= 1000
  2. \n\t
  3. 1 <= words[i].length <= 16
  4. \n\t
  5. words[i] \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\u3002
  6. \n
\n\n

 

\n", "tags_en": ["Hash Table", "Dynamic Programming"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int longestStrChain(vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int longestStrChain(String[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestStrChain(self, words):\n \"\"\"\n :type words: List[str]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestStrChain(self, words: List[str]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint longestStrChain(char ** words, int wordsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LongestStrChain(string[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @return {number}\n */\nvar longestStrChain = function(words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @return {Integer}\ndef longest_str_chain(words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestStrChain(_ words: [String]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestStrChain(words []string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestStrChain(words: Array[String]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestStrChain(words: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_str_chain(words: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @return Integer\n */\n function longestStrChain($words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestStrChain(words: string[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-str-chain words)\n (-> (listof string?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1048](https://leetcode-cn.com/problems/longest-string-chain)", "[\u6700\u957f\u5b57\u7b26\u4e32\u94fe](/solution/1000-1099/1048.Longest%20String%20Chain/README.md)", "`\u54c8\u5e0c\u8868`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1048](https://leetcode.com/problems/longest-string-chain)", "[Longest String Chain](/solution/1000-1099/1048.Longest%20String%20Chain/README_EN.md)", "`Hash Table`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "1128", "frontend_question_id": "1047", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string", "url_en": "https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string", "relative_path_cn": "/solution/1000-1099/1047.Remove%20All%20Adjacent%20Duplicates%20In%20String/README.md", "relative_path_en": "/solution/1000-1099/1047.Remove%20All%20Adjacent%20Duplicates%20In%20String/README_EN.md", "title_cn": "\u5220\u9664\u5b57\u7b26\u4e32\u4e2d\u7684\u6240\u6709\u76f8\u90bb\u91cd\u590d\u9879", "title_en": "Remove All Adjacent Duplicates In String", "question_title_slug": "remove-all-adjacent-duplicates-in-string", "content_en": "

You are given a string s consisting of lowercase English letters. A duplicate removal consists of choosing two adjacent and equal letters and removing them.

\n\n

We repeatedly make duplicate removals on s until we no longer can.

\n\n

Return the final string after all such duplicate removals have been made. It can be proven that the answer is unique.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "abbaca"\nOutput: "ca"\nExplanation: \nFor example, in "abbaca" we could remove "bb" since the letters are adjacent and equal, and this is the only possible move.  The result of this move is that the string is "aaca", of which only "aa" is possible, so the final string is "ca".\n
\n\n

Example 2:

\n\n
\nInput: s = "azxxzy"\nOutput: "ay"\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 105
  • \n\t
  • s consists of lowercase English letters.
  • \n
\n", "content_cn": "

\u7ed9\u51fa\u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210\u7684\u5b57\u7b26\u4e32 S\uff0c\u91cd\u590d\u9879\u5220\u9664\u64cd\u4f5c\u4f1a\u9009\u62e9\u4e24\u4e2a\u76f8\u90bb\u4e14\u76f8\u540c\u7684\u5b57\u6bcd\uff0c\u5e76\u5220\u9664\u5b83\u4eec\u3002

\n\n

\u5728 S \u4e0a\u53cd\u590d\u6267\u884c\u91cd\u590d\u9879\u5220\u9664\u64cd\u4f5c\uff0c\u76f4\u5230\u65e0\u6cd5\u7ee7\u7eed\u5220\u9664\u3002

\n\n

\u5728\u5b8c\u6210\u6240\u6709\u91cd\u590d\u9879\u5220\u9664\u64cd\u4f5c\u540e\u8fd4\u56de\u6700\u7ec8\u7684\u5b57\u7b26\u4e32\u3002\u7b54\u6848\u4fdd\u8bc1\u552f\u4e00\u3002

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1a"abbaca"\n\u8f93\u51fa\uff1a"ca"\n\u89e3\u91ca\uff1a\n\u4f8b\u5982\uff0c\u5728 "abbaca" \u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u5220\u9664 "bb" \u7531\u4e8e\u4e24\u5b57\u6bcd\u76f8\u90bb\u4e14\u76f8\u540c\uff0c\u8fd9\u662f\u6b64\u65f6\u552f\u4e00\u53ef\u4ee5\u6267\u884c\u5220\u9664\u64cd\u4f5c\u7684\u91cd\u590d\u9879\u3002\u4e4b\u540e\u6211\u4eec\u5f97\u5230\u5b57\u7b26\u4e32 "aaca"\uff0c\u5176\u4e2d\u53c8\u53ea\u6709 "aa" \u53ef\u4ee5\u6267\u884c\u91cd\u590d\u9879\u5220\u9664\u64cd\u4f5c\uff0c\u6240\u4ee5\u6700\u540e\u7684\u5b57\u7b26\u4e32\u4e3a "ca"\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= S.length <= 20000
  2. \n\t
  3. S \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\u3002
  4. \n
\n", "tags_en": ["Stack"], "tags_cn": ["\u6808"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string removeDuplicates(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String removeDuplicates(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def removeDuplicates(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def removeDuplicates(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * removeDuplicates(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string RemoveDuplicates(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar removeDuplicates = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef remove_duplicates(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func removeDuplicates(_ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func removeDuplicates(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def removeDuplicates(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun removeDuplicates(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn remove_duplicates(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function removeDuplicates($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function removeDuplicates(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (remove-duplicates s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1047](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string)", "[\u5220\u9664\u5b57\u7b26\u4e32\u4e2d\u7684\u6240\u6709\u76f8\u90bb\u91cd\u590d\u9879](/solution/1000-1099/1047.Remove%20All%20Adjacent%20Duplicates%20In%20String/README.md)", "`\u6808`", "\u7b80\u5355", ""], "md_table_row_en": ["[1047](https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string)", "[Remove All Adjacent Duplicates In String](/solution/1000-1099/1047.Remove%20All%20Adjacent%20Duplicates%20In%20String/README_EN.md)", "`Stack`", "Easy", ""]}, {"question_id": "1127", "frontend_question_id": "1046", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/last-stone-weight", "url_en": "https://leetcode.com/problems/last-stone-weight", "relative_path_cn": "/solution/1000-1099/1046.Last%20Stone%20Weight/README.md", "relative_path_en": "/solution/1000-1099/1046.Last%20Stone%20Weight/README_EN.md", "title_cn": "\u6700\u540e\u4e00\u5757\u77f3\u5934\u7684\u91cd\u91cf", "title_en": "Last Stone Weight", "question_title_slug": "last-stone-weight", "content_en": "

We have a collection of stones, each stone has a positive integer weight.

\n\n

Each turn, we choose the two heaviest stones and smash them together.  Suppose the stones have weights x and y with x <= y.  The result of this smash is:

\n\n
    \n\t
  • If x == y, both stones are totally destroyed;
  • \n\t
  • If x != y, the stone of weight x is totally destroyed, and the stone of weight y has new weight y-x.
  • \n
\n\n

At the end, there is at most 1 stone left.  Return the weight of this stone (or 0 if there are no stones left.)

\n\n

 

\n\n

Example 1:

\n\n
\nInput: [2,7,4,1,8,1]\nOutput: 1\nExplanation: \nWe combine 7 and 8 to get 1 so the array converts to [2,4,1,1,1] then,\nwe combine 2 and 4 to get 2 so the array converts to [2,1,1,1] then,\nwe combine 2 and 1 to get 1 so the array converts to [1,1,1] then,\nwe combine 1 and 1 to get 0 so the array converts to [1] then that's the value of last stone.
\n\n

 

\n\n

Note:

\n\n
    \n\t
  1. 1 <= stones.length <= 30
  2. \n\t
  3. 1 <= stones[i] <= 1000
  4. \n
\n", "content_cn": "

\u6709\u4e00\u5806\u77f3\u5934\uff0c\u6bcf\u5757\u77f3\u5934\u7684\u91cd\u91cf\u90fd\u662f\u6b63\u6574\u6570\u3002

\n\n

\u6bcf\u4e00\u56de\u5408\uff0c\u4ece\u4e2d\u9009\u51fa\u4e24\u5757 \u6700\u91cd\u7684 \u77f3\u5934\uff0c\u7136\u540e\u5c06\u5b83\u4eec\u4e00\u8d77\u7c89\u788e\u3002\u5047\u8bbe\u77f3\u5934\u7684\u91cd\u91cf\u5206\u522b\u4e3a\u00a0x \u548c\u00a0y\uff0c\u4e14\u00a0x <= y\u3002\u90a3\u4e48\u7c89\u788e\u7684\u53ef\u80fd\u7ed3\u679c\u5982\u4e0b\uff1a

\n\n
    \n\t
  • \u5982\u679c\u00a0x == y\uff0c\u90a3\u4e48\u4e24\u5757\u77f3\u5934\u90fd\u4f1a\u88ab\u5b8c\u5168\u7c89\u788e\uff1b
  • \n\t
  • \u5982\u679c\u00a0x != y\uff0c\u90a3\u4e48\u91cd\u91cf\u4e3a\u00a0x\u00a0\u7684\u77f3\u5934\u5c06\u4f1a\u5b8c\u5168\u7c89\u788e\uff0c\u800c\u91cd\u91cf\u4e3a\u00a0y\u00a0\u7684\u77f3\u5934\u65b0\u91cd\u91cf\u4e3a\u00a0y-x\u3002
  • \n
\n\n

\u6700\u540e\uff0c\u6700\u591a\u53ea\u4f1a\u5269\u4e0b\u4e00\u5757\u77f3\u5934\u3002\u8fd4\u56de\u6b64\u77f3\u5934\u7684\u91cd\u91cf\u3002\u5982\u679c\u6ca1\u6709\u77f3\u5934\u5269\u4e0b\uff0c\u5c31\u8fd4\u56de 0\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b\uff1a

\n\n
\n\u8f93\u5165\uff1a[2,7,4,1,8,1]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\n\u5148\u9009\u51fa 7 \u548c 8\uff0c\u5f97\u5230 1\uff0c\u6240\u4ee5\u6570\u7ec4\u8f6c\u6362\u4e3a [2,4,1,1,1]\uff0c\n\u518d\u9009\u51fa 2 \u548c 4\uff0c\u5f97\u5230 2\uff0c\u6240\u4ee5\u6570\u7ec4\u8f6c\u6362\u4e3a [2,1,1,1]\uff0c\n\u63a5\u7740\u662f 2 \u548c 1\uff0c\u5f97\u5230 1\uff0c\u6240\u4ee5\u6570\u7ec4\u8f6c\u6362\u4e3a [1,1,1]\uff0c\n\u6700\u540e\u9009\u51fa 1 \u548c 1\uff0c\u5f97\u5230 0\uff0c\u6700\u7ec8\u6570\u7ec4\u8f6c\u6362\u4e3a [1]\uff0c\u8fd9\u5c31\u662f\u6700\u540e\u5269\u4e0b\u90a3\u5757\u77f3\u5934\u7684\u91cd\u91cf\u3002
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= stones.length <= 30
  • \n\t
  • 1 <= stones[i] <= 1000
  • \n
\n", "tags_en": ["Heap", "Greedy"], "tags_cn": ["\u5806", "\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int lastStoneWeight(vector& stones) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int lastStoneWeight(int[] stones) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def lastStoneWeight(self, stones):\n \"\"\"\n :type stones: List[int]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def lastStoneWeight(self, stones: List[int]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint lastStoneWeight(int* stones, int stonesSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LastStoneWeight(int[] stones) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} stones\n * @return {number}\n */\nvar lastStoneWeight = function(stones) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} stones\n# @return {Integer}\ndef last_stone_weight(stones)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func lastStoneWeight(_ stones: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func lastStoneWeight(stones []int) int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def lastStoneWeight(stones: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun lastStoneWeight(stones: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn last_stone_weight(stones: Vec) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $stones\n * @return Integer\n */\n function lastStoneWeight($stones) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function lastStoneWeight(stones: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (last-stone-weight stones)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1046](https://leetcode-cn.com/problems/last-stone-weight)", "[\u6700\u540e\u4e00\u5757\u77f3\u5934\u7684\u91cd\u91cf](/solution/1000-1099/1046.Last%20Stone%20Weight/README.md)", "`\u5806`,`\u8d2a\u5fc3\u7b97\u6cd5`", "\u7b80\u5355", ""], "md_table_row_en": ["[1046](https://leetcode.com/problems/last-stone-weight)", "[Last Stone Weight](/solution/1000-1099/1046.Last%20Stone%20Weight/README_EN.md)", "`Heap`,`Greedy`", "Easy", ""]}, {"question_id": "1126", "frontend_question_id": "1167", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/minimum-cost-to-connect-sticks", "url_en": "https://leetcode.com/problems/minimum-cost-to-connect-sticks", "relative_path_cn": "/solution/1100-1199/1167.Minimum%20Cost%20to%20Connect%20Sticks/README.md", "relative_path_en": "/solution/1100-1199/1167.Minimum%20Cost%20to%20Connect%20Sticks/README_EN.md", "title_cn": "\u8fde\u63a5\u68d2\u6750\u7684\u6700\u4f4e\u8d39\u7528", "title_en": "Minimum Cost to Connect Sticks", "question_title_slug": "minimum-cost-to-connect-sticks", "content_en": "

You have some number of sticks with positive integer lengths. These lengths are given as an array sticks, where sticks[i] is the length of the ith stick.

\n\n

You can connect any two sticks of lengths x and y into one stick by paying a cost of x + y. You must connect all the sticks until there is only one stick remaining.

\n\n

Return the minimum cost of connecting all the given sticks into one stick in this way.

\n\n

 

\n

Example 1:

\n\n
\nInput: sticks = [2,4,3]\nOutput: 14\nExplanation: You start with sticks = [2,4,3].\n1. Combine sticks 2 and 3 for a cost of 2 + 3 = 5. Now you have sticks = [5,4].\n2. Combine sticks 5 and 4 for a cost of 5 + 4 = 9. Now you have sticks = [9].\nThere is only one stick left, so you are done. The total cost is 5 + 9 = 14.\n
\n\n

Example 2:

\n\n
\nInput: sticks = [1,8,3,5]\nOutput: 30\nExplanation: You start with sticks = [1,8,3,5].\n1. Combine sticks 1 and 3 for a cost of 1 + 3 = 4. Now you have sticks = [4,8,5].\n2. Combine sticks 4 and 5 for a cost of 4 + 5 = 9. Now you have sticks = [9,8].\n3. Combine sticks 9 and 8 for a cost of 9 + 8 = 17. Now you have sticks = [17].\nThere is only one stick left, so you are done. The total cost is 4 + 9 + 17 = 30.\n
\n\n

Example 3:

\n\n
\nInput: sticks = [5]\nOutput: 0\nExplanation: There is only one stick, so you don't need to do anything. The total cost is 0.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= sticks.length <= 104
  • \n\t
  • 1 <= sticks[i] <= 104
  • \n
\n", "content_cn": "

\u4e3a\u4e86\u88c5\u4fee\u65b0\u623f\uff0c\u4f60\u9700\u8981\u52a0\u5de5\u4e00\u4e9b\u957f\u5ea6\u4e3a\u6b63\u6574\u6570\u7684\u68d2\u6750 \u3002\u68d2\u6750\u4ee5\u6570\u7ec4 sticks \u7684\u5f62\u5f0f\u7ed9\u51fa\uff0c\u5176\u4e2d sticks[i] \u662f\u7b2c i \u6839\u68d2\u6750\u7684\u957f\u5ea6\u3002

\n\n

\u5982\u679c\u8981\u5c06\u957f\u5ea6\u5206\u522b\u4e3a x \u548c y \u7684\u4e24\u6839\u68d2\u6750\u8fde\u63a5\u5728\u4e00\u8d77\uff0c\u4f60\u9700\u8981\u652f\u4ed8 x + y \u7684\u8d39\u7528\u3002 \u7531\u4e8e\u65bd\u5de5\u9700\u8981\uff0c\u4f60\u5fc5\u987b\u5c06\u6240\u6709\u68d2\u6750\u8fde\u63a5\u6210\u4e00\u6839\u3002

\n\n

\u8fd4\u56de\u4f60\u628a\u6240\u6709\u68d2\u6750\u00a0sticks\u00a0\u8fde\u6210\u4e00\u6839\u6240\u9700\u8981\u7684\u6700\u4f4e\u8d39\u7528\u3002\u6ce8\u610f\u4f60\u53ef\u4ee5\u4efb\u610f\u9009\u62e9\u68d2\u6750\u8fde\u63a5\u7684\u987a\u5e8f\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1asticks = [2,4,3]\n\u8f93\u51fa\uff1a14\n\u89e3\u91ca\uff1a\u4ece sticks = [2,4,3] \u5f00\u59cb\u3002\n1. \u8fde\u63a5 2 \u548c 3 \uff0c\u8d39\u7528\u4e3a 2 + 3 = 5 \u3002\u73b0\u5728 sticks = [5,4]\n2. \u8fde\u63a5 5 \u548c 4 \uff0c\u8d39\u7528\u4e3a 5 + 4 = 9 \u3002\u73b0\u5728 sticks = [9]\n\u6240\u6709\u68d2\u6750\u5df2\u7ecf\u8fde\u6210\u4e00\u6839\uff0c\u603b\u8d39\u7528 5 + 9 = 14\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1asticks = [1,8,3,5]\n\u8f93\u51fa\uff1a30\n\u89e3\u91ca\uff1a\u4ece sticks = [1,8,3,5] \u5f00\u59cb\u3002\n1. \u8fde\u63a5 1 \u548c 3 \uff0c\u8d39\u7528\u4e3a 1 + 3 = 4 \u3002\u73b0\u5728 sticks = [4,8,5]\n2. \u8fde\u63a5 4 \u548c 5 \uff0c\u8d39\u7528\u4e3a 4 + 5 = 9 \u3002\u73b0\u5728 sticks = [9,8]\n3. \u8fde\u63a5 9 \u548c 8 \uff0c\u8d39\u7528\u4e3a 9 + 8 = 17 \u3002\u73b0\u5728 sticks = [17]\n\u6240\u6709\u68d2\u6750\u5df2\u7ecf\u8fde\u6210\u4e00\u6839\uff0c\u603b\u8d39\u7528 4 + 9 + 17 = 30\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1asticks = [5]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u53ea\u6709\u4e00\u6839\u68d2\u6750\uff0c\u4e0d\u5fc5\u518d\u8fde\u63a5\u3002\u603b\u8d39\u7528 0\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= sticks.length <= 104
  • \n\t
  • 1 <= sticks[i] <= 104
  • \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int connectSticks(vector& sticks) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int connectSticks(int[] sticks) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def connectSticks(self, sticks):\n \"\"\"\n :type sticks: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def connectSticks(self, sticks: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint connectSticks(int* sticks, int sticksSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ConnectSticks(int[] sticks) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} sticks\n * @return {number}\n */\nvar connectSticks = function(sticks) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} sticks\n# @return {Integer}\ndef connect_sticks(sticks)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func connectSticks(_ sticks: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func connectSticks(sticks []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def connectSticks(sticks: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun connectSticks(sticks: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn connect_sticks(sticks: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $sticks\n * @return Integer\n */\n function connectSticks($sticks) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function connectSticks(sticks: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (connect-sticks sticks)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1167](https://leetcode-cn.com/problems/minimum-cost-to-connect-sticks)", "[\u8fde\u63a5\u68d2\u6750\u7684\u6700\u4f4e\u8d39\u7528](/solution/1100-1199/1167.Minimum%20Cost%20to%20Connect%20Sticks/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1167](https://leetcode.com/problems/minimum-cost-to-connect-sticks)", "[Minimum Cost to Connect Sticks](/solution/1100-1199/1167.Minimum%20Cost%20to%20Connect%20Sticks/README_EN.md)", "`Greedy`", "Medium", "\ud83d\udd12"]}, {"question_id": "1125", "frontend_question_id": "1166", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/design-file-system", "url_en": "https://leetcode.com/problems/design-file-system", "relative_path_cn": "/solution/1100-1199/1166.Design%20File%20System/README.md", "relative_path_en": "/solution/1100-1199/1166.Design%20File%20System/README_EN.md", "title_cn": "\u8bbe\u8ba1\u6587\u4ef6\u7cfb\u7edf", "title_en": "Design File System", "question_title_slug": "design-file-system", "content_en": "

You are asked to design a file system that allows you to create new paths and associate them with different values.

\n\n

The format of a path is one or more concatenated strings of the form: / followed by one or more lowercase English letters. For example, "/leetcode" and "/leetcode/problems" are valid paths while an empty string "" and "/" are not.

\n\n

Implement the FileSystem class:

\n\n
    \n\t
  • bool createPath(string path, int value) Creates a new path and associates a value to it if possible and returns true. Returns false if the path already exists or its parent path doesn't exist.
  • \n\t
  • int get(string path) Returns the value associated with path or returns -1 if the path doesn't exist.
  • \n
\n\n

 

\n

Example 1:

\n\n
\nInput: \n["FileSystem","createPath","get"]\n[[],["/a",1],["/a"]]\nOutput: \n[null,true,1]\nExplanation: \nFileSystem fileSystem = new FileSystem();\n\nfileSystem.createPath("/a", 1); // return true\nfileSystem.get("/a"); // return 1\n
\n\n

Example 2:

\n\n
\nInput: \n["FileSystem","createPath","createPath","get","createPath","get"]\n[[],["/leet",1],["/leet/code",2],["/leet/code"],["/c/d",1],["/c"]]\nOutput: \n[null,true,true,2,false,-1]\nExplanation: \nFileSystem fileSystem = new FileSystem();\n\nfileSystem.createPath("/leet", 1); // return true\nfileSystem.createPath("/leet/code", 2); // return true\nfileSystem.get("/leet/code"); // return 2\nfileSystem.createPath("/c/d", 1); // return false because the parent path "/c" doesn't exist.\nfileSystem.get("/c"); // return -1 because this path doesn't exist.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The number of calls to the two functions is less than or equal to 104 in total.
  • \n\t
  • 2 <= path.length <= 100
  • \n\t
  • 1 <= value <= 109
  • \n
\n", "content_cn": "

\u4f60\u9700\u8981\u8bbe\u8ba1\u4e00\u4e2a\u80fd\u63d0\u4f9b\u4e0b\u9762\u4e24\u4e2a\u51fd\u6570\u7684\u6587\u4ef6\u7cfb\u7edf\uff1a

\n\n
    \n\t
  • create(path, value): \u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u8def\u5f84\uff0c\u5e76\u5c3d\u53ef\u80fd\u5c06\u503c value \u4e0e\u8def\u5f84 path \u5173\u8054\uff0c\u7136\u540e\u8fd4\u56de True\u3002\u5982\u679c\u8def\u5f84\u5df2\u7ecf\u5b58\u5728\u6216\u8005\u8def\u5f84\u7684\u7236\u8def\u5f84\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de False\u3002
  • \n\t
  • get(path): \u8fd4\u56de\u4e0e\u8def\u5f84\u5173\u8054\u7684\u503c\u3002\u5982\u679c\u8def\u5f84\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de -1\u3002
  • \n
\n\n

“\u8def\u5f84” \u662f\u7531\u4e00\u4e2a\u6216\u591a\u4e2a\u7b26\u5408\u4e0b\u8ff0\u683c\u5f0f\u7684\u5b57\u7b26\u4e32\u8fde\u63a5\u8d77\u6765\u5f62\u6210\u7684\uff1a\u5728 / \u540e\u8ddf\u7740\u4e00\u4e2a\u6216\u591a\u4e2a\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002

\n\n

\u4f8b\u5982 /leetcode \u548c /leetcode/problems \u90fd\u662f\u6709\u6548\u7684\u8def\u5f84\uff0c\u4f46\u7a7a\u5b57\u7b26\u4e32\u548c / \u4e0d\u662f\u6709\u6548\u7684\u8def\u5f84\u3002

\n\n

\u597d\u4e86\uff0c\u63a5\u4e0b\u6765\u5c31\u8bf7\u4f60\u6765\u5b9e\u73b0\u8fd9\u4e24\u4e2a\u51fd\u6570\u5427\uff01\uff08\u8bf7\u53c2\u8003\u793a\u4f8b\u4ee5\u83b7\u5f97\u66f4\u591a\u4fe1\u606f\uff09

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a \n["FileSystem","create","get"]\n[[],["/a",1],["/a"]]\n\u8f93\u51fa\uff1a \n[null,true,1]\n\u89e3\u91ca\uff1a \nFileSystem fileSystem = new FileSystem();\n\nfileSystem.create("/a", 1); // \u8fd4\u56de true\nfileSystem.get("/a"); // \u8fd4\u56de 1\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a \n["FileSystem","create","create","get","create","get"]\n[[],["/leet",1],["/leet/code",2],["/leet/code"],["/c/d",1],["/c"]]\n\u8f93\u51fa\uff1a \n[null,true,true,2,false,-1]\n\u89e3\u91ca\uff1a\nFileSystem fileSystem = new FileSystem();\n\nfileSystem.create("/leet", 1); // \u8fd4\u56de true\nfileSystem.create("/leet/code", 2); // \u8fd4\u56de true\nfileSystem.get("/leet/code"); // \u8fd4\u56de 2\nfileSystem.create("/c/d", 1); // \u8fd4\u56de false \u56e0\u4e3a\u7236\u8def\u5f84 "/c" \u4e0d\u5b58\u5728\u3002\nfileSystem.get("/c"); // \u8fd4\u56de -1 \u56e0\u4e3a\u8be5\u8def\u5f84\u4e0d\u5b58\u5728\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u5bf9\u4e24\u4e2a\u51fd\u6570\u7684\u8c03\u7528\u6b21\u6570\u52a0\u8d77\u6765\u5c0f\u4e8e\u7b49\u4e8e 10^4
  • \n\t
  • 2 <= path.length <= 100
  • \n\t
  • 1 <= value <= 10^9
  • \n
\n", "tags_en": ["Design", "Hash Table"], "tags_cn": ["\u8bbe\u8ba1", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class FileSystem {\npublic:\n FileSystem() {\n\n }\n \n bool createPath(string path, int value) {\n\n }\n \n int get(string path) {\n\n }\n};\n\n/**\n * Your FileSystem object will be instantiated and called as such:\n * FileSystem* obj = new FileSystem();\n * bool param_1 = obj->createPath(path,value);\n * int param_2 = obj->get(path);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class FileSystem {\n\n public FileSystem() {\n\n }\n \n public boolean createPath(String path, int value) {\n\n }\n \n public int get(String path) {\n\n }\n}\n\n/**\n * Your FileSystem object will be instantiated and called as such:\n * FileSystem obj = new FileSystem();\n * boolean param_1 = obj.createPath(path,value);\n * int param_2 = obj.get(path);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class FileSystem(object):\n\n def __init__(self):\n\n\n def createPath(self, path, value):\n \"\"\"\n :type path: str\n :type value: int\n :rtype: bool\n \"\"\"\n\n\n def get(self, path):\n \"\"\"\n :type path: str\n :rtype: int\n \"\"\"\n\n\n\n# Your FileSystem object will be instantiated and called as such:\n# obj = FileSystem()\n# param_1 = obj.createPath(path,value)\n# param_2 = obj.get(path)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class FileSystem:\n\n def __init__(self):\n\n\n def createPath(self, path: str, value: int) -> bool:\n\n\n def get(self, path: str) -> int:\n\n\n\n# Your FileSystem object will be instantiated and called as such:\n# obj = FileSystem()\n# param_1 = obj.createPath(path,value)\n# param_2 = obj.get(path)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} FileSystem;\n\n\nFileSystem* fileSystemCreate() {\n \n}\n\nbool fileSystemCreatePath(FileSystem* obj, char * path, int value) {\n \n}\n\nint fileSystemGet(FileSystem* obj, char * path) {\n \n}\n\nvoid fileSystemFree(FileSystem* obj) {\n \n}\n\n/**\n * Your FileSystem struct will be instantiated and called as such:\n * FileSystem* obj = fileSystemCreate();\n * bool param_1 = fileSystemCreatePath(obj, path, value);\n \n * int param_2 = fileSystemGet(obj, path);\n \n * fileSystemFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class FileSystem {\n\n public FileSystem() {\n\n }\n \n public bool CreatePath(string path, int value) {\n\n }\n \n public int Get(string path) {\n\n }\n}\n\n/**\n * Your FileSystem object will be instantiated and called as such:\n * FileSystem obj = new FileSystem();\n * bool param_1 = obj.CreatePath(path,value);\n * int param_2 = obj.Get(path);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "\nvar FileSystem = function() {\n\n};\n\n/** \n * @param {string} path \n * @param {number} value\n * @return {boolean}\n */\nFileSystem.prototype.createPath = function(path, value) {\n\n};\n\n/** \n * @param {string} path\n * @return {number}\n */\nFileSystem.prototype.get = function(path) {\n\n};\n\n/**\n * Your FileSystem object will be instantiated and called as such:\n * var obj = new FileSystem()\n * var param_1 = obj.createPath(path,value)\n * var param_2 = obj.get(path)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class FileSystem\n def initialize()\n\n end\n\n\n=begin\n :type path: String\n :type value: Integer\n :rtype: Boolean\n=end\n def create_path(path, value)\n\n end\n\n\n=begin\n :type path: String\n :rtype: Integer\n=end\n def get(path)\n\n end\n\n\nend\n\n# Your FileSystem object will be instantiated and called as such:\n# obj = FileSystem.new()\n# param_1 = obj.create_path(path, value)\n# param_2 = obj.get(path)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass FileSystem {\n\n init() {\n \n }\n \n func createPath(_ path: String, _ value: Int) -> Bool {\n \n }\n \n func get(_ path: String) -> Int {\n \n }\n}\n\n/**\n * Your FileSystem object will be instantiated and called as such:\n * let obj = FileSystem()\n * let ret_1: Bool = obj.createPath(path, value)\n * let ret_2: Int = obj.get(path)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type FileSystem struct {\n\n}\n\n\nfunc Constructor() FileSystem {\n\n}\n\n\nfunc (this *FileSystem) CreatePath(path string, value int) bool {\n\n}\n\n\nfunc (this *FileSystem) Get(path string) int {\n\n}\n\n\n/**\n * Your FileSystem object will be instantiated and called as such:\n * obj := Constructor();\n * param_1 := obj.CreatePath(path,value);\n * param_2 := obj.Get(path);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class FileSystem() {\n\n def createPath(path: String, value: Int): Boolean = {\n\n }\n\n def get(path: String): Int = {\n\n }\n\n}\n\n/**\n * Your FileSystem object will be instantiated and called as such:\n * var obj = new FileSystem()\n * var param_1 = obj.createPath(path,value)\n * var param_2 = obj.get(path)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class FileSystem() {\n\n fun createPath(path: String, value: Int): Boolean {\n\n }\n\n fun get(path: String): Int {\n\n }\n\n}\n\n/**\n * Your FileSystem object will be instantiated and called as such:\n * var obj = FileSystem()\n * var param_1 = obj.createPath(path,value)\n * var param_2 = obj.get(path)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct FileSystem {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl FileSystem {\n\n fn new() -> Self {\n\n }\n \n fn create_path(&self, path: String, value: i32) -> bool {\n\n }\n \n fn get(&self, path: String) -> i32 {\n\n }\n}\n\n/**\n * Your FileSystem object will be instantiated and called as such:\n * let obj = FileSystem::new();\n * let ret_1: bool = obj.create_path(path, value);\n * let ret_2: i32 = obj.get(path);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class FileSystem {\n /**\n */\n function __construct() {\n\n }\n\n /**\n * @param String $path\n * @param Integer $value\n * @return Boolean\n */\n function createPath($path, $value) {\n\n }\n\n /**\n * @param String $path\n * @return Integer\n */\n function get($path) {\n\n }\n}\n\n/**\n * Your FileSystem object will be instantiated and called as such:\n * $obj = FileSystem();\n * $ret_1 = $obj->createPath($path, $value);\n * $ret_2 = $obj->get($path);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class FileSystem {\n constructor() {\n\n }\n\n createPath(path: string, value: number): boolean {\n\n }\n\n get(path: string): number {\n\n }\n}\n\n/**\n * Your FileSystem object will be instantiated and called as such:\n * var obj = new FileSystem()\n * var param_1 = obj.createPath(path,value)\n * var param_2 = obj.get(path)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define file-system%\n (class object%\n (super-new)\n (init-field)\n \n ; create-path : string? exact-integer? -> boolean?\n (define/public (create-path path value)\n\n )\n ; get : string? -> exact-integer?\n (define/public (get path)\n\n )))\n\n;; Your file-system% object will be instantiated and called as such:\n;; (define obj (new file-system%))\n;; (define param_1 (send obj create-path path value))\n;; (define param_2 (send obj get path))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1166](https://leetcode-cn.com/problems/design-file-system)", "[\u8bbe\u8ba1\u6587\u4ef6\u7cfb\u7edf](/solution/1100-1199/1166.Design%20File%20System/README.md)", "`\u8bbe\u8ba1`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1166](https://leetcode.com/problems/design-file-system)", "[Design File System](/solution/1100-1199/1166.Design%20File%20System/README_EN.md)", "`Design`,`Hash Table`", "Medium", "\ud83d\udd12"]}, {"question_id": "1124", "frontend_question_id": "1153", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/string-transforms-into-another-string", "url_en": "https://leetcode.com/problems/string-transforms-into-another-string", "relative_path_cn": "/solution/1100-1199/1153.String%20Transforms%20Into%20Another%20String/README.md", "relative_path_en": "/solution/1100-1199/1153.String%20Transforms%20Into%20Another%20String/README_EN.md", "title_cn": "\u5b57\u7b26\u4e32\u8f6c\u5316", "title_en": "String Transforms Into Another String", "question_title_slug": "string-transforms-into-another-string", "content_en": "

Given two strings str1 and str2 of the same length, determine whether you can transform str1 into str2 by doing zero or more conversions.

\n\n

In one conversion you can convert all occurrences of one character in str1 to any other lowercase English character.

\n\n

Return true if and only if you can transform str1 into str2.

\n\n

 

\n

Example 1:

\n\n
\nInput: str1 = "aabcc", str2 = "ccdee"\nOutput: true\nExplanation: Convert 'c' to 'e' then 'b' to 'd' then 'a' to 'c'. Note that the order of conversions matter.\n
\n\n

Example 2:

\n\n
\nInput: str1 = "leetcode", str2 = "codeleet"\nOutput: false\nExplanation: There is no way to transform str1 to str2.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= str1.length == str2.length <= 104
  • \n\t
  • str1 and str2 contain only lowercase English letters.
  • \n
\n", "content_cn": "

\u7ed9\u51fa\u4e24\u4e2a\u957f\u5ea6\u76f8\u540c\u7684\u5b57\u7b26\u4e32\uff0c\u5206\u522b\u662f str1 \u548c str2\u3002\u8bf7\u4f60\u5e2e\u5fd9\u5224\u65ad\u5b57\u7b26\u4e32 str1 \u80fd\u4e0d\u80fd\u5728 \u96f6\u6b21 \u6216 \u591a\u6b21 \u8f6c\u5316\u540e\u53d8\u6210\u5b57\u7b26\u4e32 str2\u3002

\n\n

\u6bcf\u4e00\u6b21\u8f6c\u5316\u65f6\uff0c\u5c06\u4f1a\u4e00\u6b21\u6027\u5c06 str1 \u4e2d\u51fa\u73b0\u7684 \u6240\u6709 \u76f8\u540c\u5b57\u6bcd\u53d8\u6210\u5176\u4ed6 \u4efb\u4f55 \u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\uff08\u89c1\u793a\u4f8b\uff09\u3002

\n\n

\u53ea\u6709\u5728\u5b57\u7b26\u4e32 str1 \u80fd\u591f\u901a\u8fc7\u4e0a\u8ff0\u65b9\u5f0f\u987a\u5229\u8f6c\u5316\u4e3a\u5b57\u7b26\u4e32 str2 \u65f6\u624d\u80fd\u8fd4\u56de True\uff0c\u5426\u5219\u8fd4\u56de False\u3002\u200b\u200b

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1astr1 = "aabcc", str2 = "ccdee"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u5c06 'c' \u53d8\u6210 'e'\uff0c\u7136\u540e\u628a 'b' \u53d8\u6210 'd'\uff0c\u63a5\u7740\u518d\u628a 'a' \u53d8\u6210 'c'\u3002\u6ce8\u610f\uff0c\u8f6c\u5316\u7684\u987a\u5e8f\u4e5f\u5f88\u91cd\u8981\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1astr1 = "leetcode", str2 = "codeleet"\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u6211\u4eec\u6ca1\u6709\u529e\u6cd5\u80fd\u591f\u628a str1 \u8f6c\u5316\u4e3a str2\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= str1.length == str2.length <= 10^4
  2. \n\t
  3. str1 \u548c str2 \u4e2d\u90fd\u53ea\u4f1a\u51fa\u73b0 \u5c0f\u5199\u82f1\u6587\u5b57\u6bcd
  4. \n
\n", "tags_en": ["Graph"], "tags_cn": ["\u56fe"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canConvert(string str1, string str2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canConvert(String str1, String str2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canConvert(self, str1, str2):\n \"\"\"\n :type str1: str\n :type str2: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canConvert(self, str1: str, str2: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canConvert(char * str1, char * str2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanConvert(string str1, string str2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} str1\n * @param {string} str2\n * @return {boolean}\n */\nvar canConvert = function(str1, str2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} str1\n# @param {String} str2\n# @return {Boolean}\ndef can_convert(str1, str2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canConvert(_ str1: String, _ str2: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canConvert(str1 string, str2 string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canConvert(str1: String, str2: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canConvert(str1: String, str2: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_convert(str1: String, str2: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $str1\n * @param String $str2\n * @return Boolean\n */\n function canConvert($str1, $str2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canConvert(str1: string, str2: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-convert str1 str2)\n (-> string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1153](https://leetcode-cn.com/problems/string-transforms-into-another-string)", "[\u5b57\u7b26\u4e32\u8f6c\u5316](/solution/1100-1199/1153.String%20Transforms%20Into%20Another%20String/README.md)", "`\u56fe`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1153](https://leetcode.com/problems/string-transforms-into-another-string)", "[String Transforms Into Another String](/solution/1100-1199/1153.String%20Transforms%20Into%20Another%20String/README_EN.md)", "`Graph`", "Hard", "\ud83d\udd12"]}, {"question_id": "1123", "frontend_question_id": "1165", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/single-row-keyboard", "url_en": "https://leetcode.com/problems/single-row-keyboard", "relative_path_cn": "/solution/1100-1199/1165.Single-Row%20Keyboard/README.md", "relative_path_en": "/solution/1100-1199/1165.Single-Row%20Keyboard/README_EN.md", "title_cn": "\u5355\u884c\u952e\u76d8", "title_en": "Single-Row Keyboard", "question_title_slug": "single-row-keyboard", "content_en": "

There is a special keyboard with all keys in a single row.

\n\n

Given a string keyboard of length 26 indicating the layout of the keyboard (indexed from 0 to 25). Initially, your finger is at index 0. To type a character, you have to move your finger to the index of the desired character. The time taken to move your finger from index i to index j is |i - j|.

\n\n

You want to type a string word. Write a function to calculate how much time it takes to type it with one finger.

\n\n

 

\n

Example 1:

\n\n
\nInput: keyboard = "abcdefghijklmnopqrstuvwxyz", word = "cba"\nOutput: 4\nExplanation: The index moves from 0 to 2 to write 'c' then to 1 to write 'b' then to 0 again to write 'a'.\nTotal time = 2 + 1 + 1 = 4. \n
\n\n

Example 2:

\n\n
\nInput: keyboard = "pqrstuvwxyzabcdefghijklmno", word = "leetcode"\nOutput: 73\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • keyboard.length == 26
  • \n\t
  • keyboard contains each English lowercase letter exactly once in some order.
  • \n\t
  • 1 <= word.length <= 104
  • \n\t
  • word[i] is an English lowercase letter.
  • \n
\n", "content_cn": "

\u6211\u4eec\u5b9a\u5236\u4e86\u4e00\u6b3e\u7279\u6b8a\u7684\u529b\u6263\u952e\u76d8\uff0c\u6240\u6709\u7684\u952e\u90fd\u6392\u5217\u5728\u4e00\u884c\u4e0a\u3002

\n\n

\u6211\u4eec\u53ef\u4ee5\u6309\u4ece\u5de6\u5230\u53f3\u7684\u987a\u5e8f\uff0c\u7528\u4e00\u4e2a\u957f\u5ea6\u4e3a 26 \u7684\u5b57\u7b26\u4e32 keyboard \uff08\u7d22\u5f15\u4ece 0 \u5f00\u59cb\uff0c\u5230 25 \u7ed3\u675f\uff09\u6765\u8868\u793a\u8be5\u952e\u76d8\u7684\u952e\u4f4d\u5e03\u5c40\u3002

\n\n

\u73b0\u5728\u9700\u8981\u6d4b\u8bd5\u8fd9\u4e2a\u952e\u76d8\u662f\u5426\u80fd\u591f\u6709\u6548\u5de5\u4f5c\uff0c\u90a3\u4e48\u6211\u4eec\u5c31\u9700\u8981\u4e2a\u673a\u68b0\u624b\u6765\u6d4b\u8bd5\u8fd9\u4e2a\u952e\u76d8\u3002

\n\n

\u6700\u521d\u7684\u65f6\u5019\uff0c\u673a\u68b0\u624b\u4f4d\u4e8e\u5de6\u8fb9\u8d77\u7b2c\u4e00\u4e2a\u952e\uff08\u4e5f\u5c31\u662f\u7d22\u5f15\u4e3a 0 \u7684\u952e\uff09\u7684\u4e0a\u65b9\u3002\u5f53\u673a\u68b0\u624b\u79fb\u52a8\u5230\u67d0\u4e00\u5b57\u7b26\u6240\u5728\u7684\u952e\u4f4d\u65f6\uff0c\u5c31\u4f1a\u5728\u7ec8\u7aef\u4e0a\u8f93\u51fa\u8be5\u5b57\u7b26\u3002

\n\n

\u673a\u68b0\u624b\u4ece\u7d22\u5f15 i \u79fb\u52a8\u5230\u7d22\u5f15 j \u6240\u9700\u8981\u7684\u65f6\u95f4\u662f |i - j|\u3002

\n\n

\u5f53\u524d\u6d4b\u8bd5\u9700\u8981\u4f60\u4f7f\u7528\u673a\u68b0\u624b\u8f93\u51fa\u6307\u5b9a\u7684\u5355\u8bcd word\uff0c\u8bf7\u4f60\u7f16\u5199\u4e00\u4e2a\u51fd\u6570\u6765\u8ba1\u7b97\u673a\u68b0\u624b\u8f93\u51fa\u8be5\u5355\u8bcd\u6240\u9700\u7684\u65f6\u95f4\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1akeyboard = "abcdefghijklmnopqrstuvwxyz", word = "cba"\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\n\u673a\u68b0\u624b\u4ece 0 \u53f7\u952e\u79fb\u52a8\u5230 2 \u53f7\u952e\u6765\u8f93\u51fa 'c'\uff0c\u53c8\u79fb\u52a8\u5230 1 \u53f7\u952e\u6765\u8f93\u51fa 'b'\uff0c\u63a5\u7740\u79fb\u52a8\u5230 0 \u53f7\u952e\u6765\u8f93\u51fa 'a'\u3002\n\u603b\u7528\u65f6 = 2 + 1 + 1 = 4. \n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1akeyboard = "pqrstuvwxyzabcdefghijklmno", word = "leetcode"\n\u8f93\u51fa\uff1a73\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • keyboard.length == 26
  • \n\t
  • keyboard \u6309\u67d0\u79cd\u7279\u5b9a\u987a\u5e8f\u6392\u5217\uff0c\u5e76\u5305\u542b\u6bcf\u4e2a\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u4e00\u6b21\u3002
  • \n\t
  • 1 <= word.length <= 10^4
  • \n\t
  • word[i] \u662f\u4e00\u4e2a\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int calculateTime(string keyboard, string word) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int calculateTime(String keyboard, String word) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def calculateTime(self, keyboard, word):\n \"\"\"\n :type keyboard: str\n :type word: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def calculateTime(self, keyboard: str, word: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint calculateTime(char * keyboard, char * word){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CalculateTime(string keyboard, string word) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} keyboard\n * @param {string} word\n * @return {number}\n */\nvar calculateTime = function(keyboard, word) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} keyboard\n# @param {String} word\n# @return {Integer}\ndef calculate_time(keyboard, word)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func calculateTime(_ keyboard: String, _ word: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func calculateTime(keyboard string, word string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def calculateTime(keyboard: String, word: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun calculateTime(keyboard: String, word: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn calculate_time(keyboard: String, word: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $keyboard\n * @param String $word\n * @return Integer\n */\n function calculateTime($keyboard, $word) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function calculateTime(keyboard: string, word: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (calculate-time keyboard word)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1165](https://leetcode-cn.com/problems/single-row-keyboard)", "[\u5355\u884c\u952e\u76d8](/solution/1100-1199/1165.Single-Row%20Keyboard/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1165](https://leetcode.com/problems/single-row-keyboard)", "[Single-Row Keyboard](/solution/1100-1199/1165.Single-Row%20Keyboard/README_EN.md)", "`String`", "Easy", "\ud83d\udd12"]}, {"question_id": "1122", "frontend_question_id": "1044", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-duplicate-substring", "url_en": "https://leetcode.com/problems/longest-duplicate-substring", "relative_path_cn": "/solution/1000-1099/1044.Longest%20Duplicate%20Substring/README.md", "relative_path_en": "/solution/1000-1099/1044.Longest%20Duplicate%20Substring/README_EN.md", "title_cn": "\u6700\u957f\u91cd\u590d\u5b50\u4e32", "title_en": "Longest Duplicate Substring", "question_title_slug": "longest-duplicate-substring", "content_en": "

Given a string s, consider all duplicated substrings: (contiguous) substrings of s that occur 2 or more times. The occurrences may overlap.

\n\n

Return any duplicated substring that has the longest possible length. If s does not have a duplicated substring, the answer is "".

\n\n

 

\n

Example 1:

\n
Input: s = \"banana\"\nOutput: \"ana\"\n

Example 2:

\n
Input: s = \"abcd\"\nOutput: \"\"\n
\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= s.length <= 3 * 104
  • \n\t
  • s consists of lowercase English letters.
  • \n
\n", "content_cn": "

\u7ed9\u51fa\u4e00\u4e2a\u5b57\u7b26\u4e32 S\uff0c\u8003\u8651\u5176\u6240\u6709\u91cd\u590d\u5b50\u4e32\uff08S \u7684\u8fde\u7eed\u5b50\u4e32\uff0c\u51fa\u73b0\u4e24\u6b21\u6216\u591a\u6b21\uff0c\u53ef\u80fd\u4f1a\u6709\u91cd\u53e0\uff09\u3002

\n\n

\u8fd4\u56de\u4efb\u4f55\u5177\u6709\u6700\u957f\u53ef\u80fd\u957f\u5ea6\u7684\u91cd\u590d\u5b50\u4e32\u3002\uff08\u5982\u679c S \u4e0d\u542b\u91cd\u590d\u5b50\u4e32\uff0c\u90a3\u4e48\u7b54\u6848\u4e3a ""\u3002\uff09

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a"banana"\n\u8f93\u51fa\uff1a"ana"\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a"abcd"\n\u8f93\u51fa\uff1a""\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 2 <= S.length <= 10^5
  2. \n\t
  3. S \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\u3002
  4. \n
\n", "tags_en": ["Hash Table", "Binary Search"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string longestDupSubstring(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String longestDupSubstring(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestDupSubstring(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestDupSubstring(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * longestDupSubstring(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string LongestDupSubstring(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar longestDupSubstring = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef longest_dup_substring(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestDupSubstring(_ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestDupSubstring(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestDupSubstring(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestDupSubstring(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_dup_substring(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function longestDupSubstring($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestDupSubstring(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-dup-substring s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1044](https://leetcode-cn.com/problems/longest-duplicate-substring)", "[\u6700\u957f\u91cd\u590d\u5b50\u4e32](/solution/1000-1099/1044.Longest%20Duplicate%20Substring/README.md)", "`\u54c8\u5e0c\u8868`,`\u4e8c\u5206\u67e5\u627e`", "\u56f0\u96be", ""], "md_table_row_en": ["[1044](https://leetcode.com/problems/longest-duplicate-substring)", "[Longest Duplicate Substring](/solution/1000-1099/1044.Longest%20Duplicate%20Substring/README_EN.md)", "`Hash Table`,`Binary Search`", "Hard", ""]}, {"question_id": "1121", "frontend_question_id": "1043", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/partition-array-for-maximum-sum", "url_en": "https://leetcode.com/problems/partition-array-for-maximum-sum", "relative_path_cn": "/solution/1000-1099/1043.Partition%20Array%20for%20Maximum%20Sum/README.md", "relative_path_en": "/solution/1000-1099/1043.Partition%20Array%20for%20Maximum%20Sum/README_EN.md", "title_cn": "\u5206\u9694\u6570\u7ec4\u4ee5\u5f97\u5230\u6700\u5927\u548c", "title_en": "Partition Array for Maximum Sum", "question_title_slug": "partition-array-for-maximum-sum", "content_en": "

Given an integer array arr, partition the array into (contiguous) subarrays of length at most k. After partitioning, each subarray has their values changed to become the maximum value of that subarray.

\n\n

Return the largest sum of the given array after partitioning. Test cases are generated so that the answer fits in a 32-bit integer.

\n\n

 

\n

Example 1:

\n\n
\nInput: arr = [1,15,7,9,2,5,10], k = 3\nOutput: 84\nExplanation: arr becomes [15,15,15,9,10,10,10]\n
\n\n

Example 2:

\n\n
\nInput: arr = [1,4,1,5,7,3,6,1,9,9,3], k = 4\nOutput: 83\n
\n\n

Example 3:

\n\n
\nInput: arr = [1], k = 1\nOutput: 1\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= arr.length <= 500
  • \n\t
  • 0 <= arr[i] <= 109
  • \n\t
  • 1 <= k <= arr.length
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr\uff0c\u8bf7\u4f60\u5c06\u8be5\u6570\u7ec4\u5206\u9694\u4e3a\u957f\u5ea6\u6700\u591a\u4e3a k \u7684\u4e00\u4e9b\uff08\u8fde\u7eed\uff09\u5b50\u6570\u7ec4\u3002\u5206\u9694\u5b8c\u6210\u540e\uff0c\u6bcf\u4e2a\u5b50\u6570\u7ec4\u7684\u4e2d\u7684\u6240\u6709\u503c\u90fd\u4f1a\u53d8\u4e3a\u8be5\u5b50\u6570\u7ec4\u4e2d\u7684\u6700\u5927\u503c\u3002

\n\n

\u8fd4\u56de\u5c06\u6570\u7ec4\u5206\u9694\u53d8\u6362\u540e\u80fd\u591f\u5f97\u5230\u7684\u5143\u7d20\u6700\u5927\u548c\u3002

\n\n

\u00a0

\n\n

\u6ce8\u610f\uff0c\u539f\u6570\u7ec4\u548c\u5206\u9694\u540e\u7684\u6570\u7ec4\u5bf9\u5e94\u987a\u5e8f\u5e94\u5f53\u4e00\u81f4\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u4f60\u53ea\u80fd\u9009\u62e9\u5206\u9694\u6570\u7ec4\u7684\u4f4d\u7f6e\u800c\u4e0d\u80fd\u8c03\u6574\u6570\u7ec4\u4e2d\u7684\u987a\u5e8f\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [1,15,7,9,2,5,10], k = 3\n\u8f93\u51fa\uff1a84\n\u89e3\u91ca\uff1a\n\u56e0\u4e3a k=3 \u53ef\u4ee5\u5206\u9694\u6210 [1,15,7] [9] [2,5,10]\uff0c\u7ed3\u679c\u4e3a [15,15,15,9,10,10,10]\uff0c\u548c\u4e3a 84\uff0c\u662f\u8be5\u6570\u7ec4\u6240\u6709\u5206\u9694\u53d8\u6362\u540e\u5143\u7d20\u603b\u548c\u6700\u5927\u7684\u3002\n\u82e5\u662f\u5206\u9694\u6210 [1] [15,7,9] [2,5,10]\uff0c\u7ed3\u679c\u5c31\u662f [1, 15, 15, 15, 10, 10, 10] \u4f46\u8fd9\u79cd\u5206\u9694\u65b9\u5f0f\u7684\u5143\u7d20\u603b\u548c\uff0876\uff09\u5c0f\u4e8e\u4e0a\u4e00\u79cd\u3002 
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [1,4,1,5,7,3,6,1,9,9,3], k = 4\n\u8f93\u51fa\uff1a83\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [1], k = 1\n\u8f93\u51fa\uff1a1\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= arr.length <= 500
  • \n\t
  • 0 <= arr[i] <= 109
  • \n\t
  • 1 <= k <= arr.length
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxSumAfterPartitioning(vector& arr, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxSumAfterPartitioning(int[] arr, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxSumAfterPartitioning(self, arr, k):\n \"\"\"\n :type arr: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxSumAfterPartitioning(self, arr: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxSumAfterPartitioning(int* arr, int arrSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxSumAfterPartitioning(int[] arr, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @param {number} k\n * @return {number}\n */\nvar maxSumAfterPartitioning = function(arr, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @param {Integer} k\n# @return {Integer}\ndef max_sum_after_partitioning(arr, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxSumAfterPartitioning(_ arr: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxSumAfterPartitioning(arr []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxSumAfterPartitioning(arr: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxSumAfterPartitioning(arr: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_sum_after_partitioning(arr: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @param Integer $k\n * @return Integer\n */\n function maxSumAfterPartitioning($arr, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxSumAfterPartitioning(arr: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-sum-after-partitioning arr k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1043](https://leetcode-cn.com/problems/partition-array-for-maximum-sum)", "[\u5206\u9694\u6570\u7ec4\u4ee5\u5f97\u5230\u6700\u5927\u548c](/solution/1000-1099/1043.Partition%20Array%20for%20Maximum%20Sum/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1043](https://leetcode.com/problems/partition-array-for-maximum-sum)", "[Partition Array for Maximum Sum](/solution/1000-1099/1043.Partition%20Array%20for%20Maximum%20Sum/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "1120", "frontend_question_id": "1042", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/flower-planting-with-no-adjacent", "url_en": "https://leetcode.com/problems/flower-planting-with-no-adjacent", "relative_path_cn": "/solution/1000-1099/1042.Flower%20Planting%20With%20No%20Adjacent/README.md", "relative_path_en": "/solution/1000-1099/1042.Flower%20Planting%20With%20No%20Adjacent/README_EN.md", "title_cn": "\u4e0d\u90bb\u63a5\u690d\u82b1", "title_en": "Flower Planting With No Adjacent", "question_title_slug": "flower-planting-with-no-adjacent", "content_en": "

You have n gardens, labeled from 1 to n, and an array paths where paths[i] = [xi, yi] describes a bidirectional path between garden xi to garden yi. In each garden, you want to plant one of 4 types of flowers.

\n\n

All gardens have at most 3 paths coming into or leaving it.

\n\n

Your task is to choose a flower type for each garden such that, for any two gardens connected by a path, they have different types of flowers.

\n\n

Return any such a choice as an array answer, where answer[i] is the type of flower planted in the (i+1)th garden. The flower types are denoted 1, 2, 3, or 4. It is guaranteed an answer exists.

\n\n

 

\n

Example 1:

\n\n
\nInput: n = 3, paths = [[1,2],[2,3],[3,1]]\nOutput: [1,2,3]\nExplanation:\nGardens 1 and 2 have different types.\nGardens 2 and 3 have different types.\nGardens 3 and 1 have different types.\nHence, [1,2,3] is a valid answer. Other valid answers include [1,2,4], [1,4,2], and [3,2,1].\n
\n\n

Example 2:

\n\n
\nInput: n = 4, paths = [[1,2],[3,4]]\nOutput: [1,2,1,2]\n
\n\n

Example 3:

\n\n
\nInput: n = 4, paths = [[1,2],[2,3],[3,4],[4,1],[1,3],[2,4]]\nOutput: [1,2,3,4]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 104
  • \n\t
  • 0 <= paths.length <= 2 * 104
  • \n\t
  • paths[i].length == 2
  • \n\t
  • 1 <= xi, yi <= n
  • \n\t
  • xi != yi
  • \n\t
  • Every garden has at most 3 paths coming into or leaving it.
  • \n
\n", "content_cn": "

\u6709 n \u4e2a\u82b1\u56ed\uff0c\u6309\u4ece\u00a01\u00a0\u5230 n \u6807\u8bb0\u3002\u53e6\u6709\u6570\u7ec4 paths \uff0c\u5176\u4e2d paths[i] = [xi, yi]\u00a0\u63cf\u8ff0\u4e86\u82b1\u56ed\u00a0xi \u5230\u82b1\u56ed\u00a0yi \u7684\u53cc\u5411\u8def\u5f84\u3002\u5728\u6bcf\u4e2a\u82b1\u56ed\u4e2d\uff0c\u4f60\u6253\u7b97\u79cd\u4e0b\u56db\u79cd\u82b1\u4e4b\u4e00\u3002

\n\n

\u53e6\u5916\uff0c\u6240\u6709\u82b1\u56ed \u6700\u591a \u6709 3 \u6761\u8def\u5f84\u53ef\u4ee5\u8fdb\u5165\u6216\u79bb\u5f00.

\n\n

\u4f60\u9700\u8981\u4e3a\u6bcf\u4e2a\u82b1\u56ed\u9009\u62e9\u4e00\u79cd\u82b1\uff0c\u4f7f\u5f97\u901a\u8fc7\u8def\u5f84\u76f8\u8fde\u7684\u4efb\u4f55\u4e24\u4e2a\u82b1\u56ed\u4e2d\u7684\u82b1\u7684\u79cd\u7c7b\u4e92\u4e0d\u76f8\u540c\u3002

\n\n

\u4ee5\u6570\u7ec4\u5f62\u5f0f\u8fd4\u56de \u4efb\u4e00 \u53ef\u884c\u7684\u65b9\u6848\u4f5c\u4e3a\u7b54\u6848\u00a0answer\uff0c\u5176\u4e2d\u00a0answer[i]\u00a0\u4e3a\u5728\u7b2c\u00a0(i+1)\u00a0\u4e2a\u82b1\u56ed\u4e2d\u79cd\u690d\u7684\u82b1\u7684\u79cd\u7c7b\u3002\u82b1\u7684\u79cd\u7c7b\u7528 \u00a01\u30012\u30013\u30014 \u8868\u793a\u3002\u4fdd\u8bc1\u5b58\u5728\u7b54\u6848\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1an = 3, paths = [[1,2],[2,3],[3,1]]\n\u8f93\u51fa\uff1a[1,2,3]\n\u89e3\u91ca\uff1a\n\u82b1\u56ed 1 \u548c 2 \u82b1\u7684\u79cd\u7c7b\u4e0d\u540c\u3002\n\u82b1\u56ed 2 \u548c 3 \u82b1\u7684\u79cd\u7c7b\u4e0d\u540c\u3002\n\u82b1\u56ed 3 \u548c 1 \u82b1\u7684\u79cd\u7c7b\u4e0d\u540c\u3002\n\u56e0\u6b64\uff0c[1,2,3] \u662f\u4e00\u4e2a\u6ee1\u8db3\u9898\u610f\u7684\u7b54\u6848\u3002\u5176\u4ed6\u6ee1\u8db3\u9898\u610f\u7684\u7b54\u6848\u6709 [1,2,4]\u3001[1,4,2] \u548c [3,2,1]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1an = 4, paths = [[1,2],[3,4]]\n\u8f93\u51fa\uff1a[1,2,1,2]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1an = 4, paths = [[1,2],[2,3],[3,4],[4,1],[1,3],[2,4]]\n\u8f93\u51fa\uff1a[1,2,3,4]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 104
  • \n\t
  • 0 <= paths.length <= 2 * 104
  • \n\t
  • paths[i].length == 2
  • \n\t
  • 1 <= xi, yi <= n
  • \n\t
  • xi != yi
  • \n\t
  • \u6bcf\u4e2a\u82b1\u56ed \u6700\u591a \u6709 3 \u6761\u8def\u5f84\u53ef\u4ee5\u8fdb\u5165\u6216\u79bb\u5f00
  • \n
\n", "tags_en": ["Graph"], "tags_cn": ["\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector gardenNoAdj(int n, vector>& paths) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] gardenNoAdj(int n, int[][] paths) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def gardenNoAdj(self, n, paths):\n \"\"\"\n :type n: int\n :type paths: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def gardenNoAdj(self, n: int, paths: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* gardenNoAdj(int n, int** paths, int pathsSize, int* pathsColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] GardenNoAdj(int n, int[][] paths) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} paths\n * @return {number[]}\n */\nvar gardenNoAdj = function(n, paths) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} paths\n# @return {Integer[]}\ndef garden_no_adj(n, paths)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func gardenNoAdj(_ n: Int, _ paths: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func gardenNoAdj(n int, paths [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def gardenNoAdj(n: Int, paths: Array[Array[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun gardenNoAdj(n: Int, paths: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn garden_no_adj(n: i32, paths: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $paths\n * @return Integer[]\n */\n function gardenNoAdj($n, $paths) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function gardenNoAdj(n: number, paths: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (garden-no-adj n paths)\n (-> exact-integer? (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1042](https://leetcode-cn.com/problems/flower-planting-with-no-adjacent)", "[\u4e0d\u90bb\u63a5\u690d\u82b1](/solution/1000-1099/1042.Flower%20Planting%20With%20No%20Adjacent/README.md)", "`\u56fe`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1042](https://leetcode.com/problems/flower-planting-with-no-adjacent)", "[Flower Planting With No Adjacent](/solution/1000-1099/1042.Flower%20Planting%20With%20No%20Adjacent/README_EN.md)", "`Graph`", "Medium", ""]}, {"question_id": "1119", "frontend_question_id": "1041", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/robot-bounded-in-circle", "url_en": "https://leetcode.com/problems/robot-bounded-in-circle", "relative_path_cn": "/solution/1000-1099/1041.Robot%20Bounded%20In%20Circle/README.md", "relative_path_en": "/solution/1000-1099/1041.Robot%20Bounded%20In%20Circle/README_EN.md", "title_cn": "\u56f0\u4e8e\u73af\u4e2d\u7684\u673a\u5668\u4eba", "title_en": "Robot Bounded In Circle", "question_title_slug": "robot-bounded-in-circle", "content_en": "

On an infinite plane, a robot initially stands at (0, 0) and faces north. The robot can receive one of three instructions:

\n\n
    \n\t
  • "G": go straight 1 unit;
  • \n\t
  • "L": turn 90 degrees to the left;
  • \n\t
  • "R": turn 90 degrees to the right.
  • \n
\n\n

The robot performs the instructions given in order, and repeats them forever.

\n\n

Return true if and only if there exists a circle in the plane such that the robot never leaves the circle.

\n\n

 

\n

Example 1:

\n\n
\nInput: instructions = "GGLLGG"\nOutput: true\nExplanation: The robot moves from (0,0) to (0,2), turns 180 degrees, and then returns to (0,0).\nWhen repeating these instructions, the robot remains in the circle of radius 2 centered at the origin.
\n\n

Example 2:

\n\n
\nInput: instructions = "GG"\nOutput: false\nExplanation: The robot moves north indefinitely.
\n\n

Example 3:

\n\n
\nInput: instructions = "GL"\nOutput: true\nExplanation: The robot moves from (0, 0) -> (0, 1) -> (-1, 1) -> (-1, 0) -> (0, 0) -> ...
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= instructions.length <= 100
  • \n\t
  • instructions[i] is 'G', 'L' or, 'R'.
  • \n
\n", "content_cn": "

\u5728\u65e0\u9650\u7684\u5e73\u9762\u4e0a\uff0c\u673a\u5668\u4eba\u6700\u521d\u4f4d\u4e8e (0, 0) \u5904\uff0c\u9762\u671d\u5317\u65b9\u3002\u673a\u5668\u4eba\u53ef\u4ee5\u63a5\u53d7\u4e0b\u5217\u4e09\u6761\u6307\u4ee4\u4e4b\u4e00\uff1a

\n\n
    \n\t
  • "G"\uff1a\u76f4\u8d70 1 \u4e2a\u5355\u4f4d
  • \n\t
  • "L"\uff1a\u5de6\u8f6c 90 \u5ea6
  • \n\t
  • "R"\uff1a\u53f3\u8f6c 90 \u5ea6
  • \n
\n\n

\u673a\u5668\u4eba\u6309\u987a\u5e8f\u6267\u884c\u6307\u4ee4 instructions\uff0c\u5e76\u4e00\u76f4\u91cd\u590d\u5b83\u4eec\u3002

\n\n

\u53ea\u6709\u5728\u5e73\u9762\u4e2d\u5b58\u5728\u73af\u4f7f\u5f97\u673a\u5668\u4eba\u6c38\u8fdc\u65e0\u6cd5\u79bb\u5f00\u65f6\uff0c\u8fd4\u56de true\u3002\u5426\u5219\uff0c\u8fd4\u56de false\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a"GGLLGG"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\n\u673a\u5668\u4eba\u4ece (0,0) \u79fb\u52a8\u5230 (0,2)\uff0c\u8f6c 180 \u5ea6\uff0c\u7136\u540e\u56de\u5230 (0,0)\u3002\n\u91cd\u590d\u8fd9\u4e9b\u6307\u4ee4\uff0c\u673a\u5668\u4eba\u5c06\u4fdd\u6301\u5728\u4ee5\u539f\u70b9\u4e3a\u4e2d\u5fc3\uff0c2 \u4e3a\u534a\u5f84\u7684\u73af\u4e2d\u8fdb\u884c\u79fb\u52a8\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a"GG"\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\n\u673a\u5668\u4eba\u65e0\u9650\u5411\u5317\u79fb\u52a8\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1a"GL"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\n\u673a\u5668\u4eba\u6309 (0, 0) -> (0, 1) -> (-1, 1) -> (-1, 0) -> (0, 0) -> ... \u8fdb\u884c\u79fb\u52a8\u3002
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= instructions.length <= 100
  2. \n\t
  3. instructions[i] \u5728 {'G', 'L', 'R'} \u4e2d
  4. \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isRobotBounded(string instructions) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isRobotBounded(String instructions) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isRobotBounded(self, instructions):\n \"\"\"\n :type instructions: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isRobotBounded(self, instructions: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isRobotBounded(char * instructions){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsRobotBounded(string instructions) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} instructions\n * @return {boolean}\n */\nvar isRobotBounded = function(instructions) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} instructions\n# @return {Boolean}\ndef is_robot_bounded(instructions)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isRobotBounded(_ instructions: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isRobotBounded(instructions string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isRobotBounded(instructions: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isRobotBounded(instructions: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_robot_bounded(instructions: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $instructions\n * @return Boolean\n */\n function isRobotBounded($instructions) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isRobotBounded(instructions: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-robot-bounded instructions)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1041](https://leetcode-cn.com/problems/robot-bounded-in-circle)", "[\u56f0\u4e8e\u73af\u4e2d\u7684\u673a\u5668\u4eba](/solution/1000-1099/1041.Robot%20Bounded%20In%20Circle/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1041](https://leetcode.com/problems/robot-bounded-in-circle)", "[Robot Bounded In Circle](/solution/1000-1099/1041.Robot%20Bounded%20In%20Circle/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "1118", "frontend_question_id": "1121", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/divide-array-into-increasing-sequences", "url_en": "https://leetcode.com/problems/divide-array-into-increasing-sequences", "relative_path_cn": "/solution/1100-1199/1121.Divide%20Array%20Into%20Increasing%20Sequences/README.md", "relative_path_en": "/solution/1100-1199/1121.Divide%20Array%20Into%20Increasing%20Sequences/README_EN.md", "title_cn": "\u5c06\u6570\u7ec4\u5206\u6210\u51e0\u4e2a\u9012\u589e\u5e8f\u5217", "title_en": "Divide Array Into Increasing Sequences", "question_title_slug": "divide-array-into-increasing-sequences", "content_en": "

Given a non-decreasing array of positive integers nums and an integer k, find out if this array can be divided into one or more disjoint increasing subsequences of length at least k.

\n\n

 

\n\n

Example 1:

\n\n
\nInput: nums = [1,2,2,3,3,4,4], k = 3\nOutput: true\nExplanation: \nThe array can be divided into the two subsequences [1,2,3,4] and [2,3,4] with lengths at least 3 each.\n
\n\n

Example 2:

\n\n
\nInput: nums = [5,6,6,7,8], k = 3\nOutput: false\nExplanation: \nThere is no way to divide the array using the conditions required.\n
\n\n

 

\n\n

Note:

\n\n
    \n\t
  1. 1 <= nums.length <= 105
  2. \n\t
  3. 1 <= k <= nums.length
  4. \n\t
  5. 1 <= nums[i] <= 105
  6. \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a \u975e\u9012\u51cf \u7684\u6b63\u6574\u6570\u6570\u7ec4 nums \u548c\u6574\u6570 K\uff0c\u5224\u65ad\u8be5\u6570\u7ec4\u662f\u5426\u53ef\u4ee5\u88ab\u5206\u6210\u4e00\u4e2a\u6216\u51e0\u4e2a \u957f\u5ea6\u81f3\u5c11 \u4e3a K \u7684 \u4e0d\u76f8\u4ea4\u7684\u9012\u589e\u5b50\u5e8f\u5217\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anums = [1,2,2,3,3,4,4], K = 3\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\n\u8be5\u6570\u7ec4\u53ef\u4ee5\u5206\u6210\u4e24\u4e2a\u5b50\u5e8f\u5217 [1,2,3,4] \u548c [2,3,4]\uff0c\u6bcf\u4e2a\u5b50\u5e8f\u5217\u7684\u957f\u5ea6\u90fd\u81f3\u5c11\u662f 3\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anums = [5,6,6,7,8], K = 3\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\n\u6ca1\u6709\u529e\u6cd5\u6839\u636e\u6761\u4ef6\u6765\u5212\u5206\u6570\u7ec4\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= nums.length <= 10^5
  2. \n\t
  3. 1 <= K <= nums.length
  4. \n\t
  5. 1 <= nums[i] <= 10^5
  6. \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canDivideIntoSubsequences(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canDivideIntoSubsequences(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canDivideIntoSubsequences(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canDivideIntoSubsequences(self, nums: List[int], k: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canDivideIntoSubsequences(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanDivideIntoSubsequences(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {boolean}\n */\nvar canDivideIntoSubsequences = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Boolean}\ndef can_divide_into_subsequences(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canDivideIntoSubsequences(_ nums: [Int], _ k: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canDivideIntoSubsequences(nums []int, k int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canDivideIntoSubsequences(nums: Array[Int], k: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canDivideIntoSubsequences(nums: IntArray, k: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_divide_into_subsequences(nums: Vec, k: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Boolean\n */\n function canDivideIntoSubsequences($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canDivideIntoSubsequences(nums: number[], k: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-divide-into-subsequences nums k)\n (-> (listof exact-integer?) exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1121](https://leetcode-cn.com/problems/divide-array-into-increasing-sequences)", "[\u5c06\u6570\u7ec4\u5206\u6210\u51e0\u4e2a\u9012\u589e\u5e8f\u5217](/solution/1100-1199/1121.Divide%20Array%20Into%20Increasing%20Sequences/README.md)", "`\u6570\u5b66`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1121](https://leetcode.com/problems/divide-array-into-increasing-sequences)", "[Divide Array Into Increasing Sequences](/solution/1100-1199/1121.Divide%20Array%20Into%20Increasing%20Sequences/README_EN.md)", "`Math`", "Hard", "\ud83d\udd12"]}, {"question_id": "1117", "frontend_question_id": "1162", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/as-far-from-land-as-possible", "url_en": "https://leetcode.com/problems/as-far-from-land-as-possible", "relative_path_cn": "/solution/1100-1199/1162.As%20Far%20from%20Land%20as%20Possible/README.md", "relative_path_en": "/solution/1100-1199/1162.As%20Far%20from%20Land%20as%20Possible/README_EN.md", "title_cn": "\u5730\u56fe\u5206\u6790", "title_en": "As Far from Land as Possible", "question_title_slug": "as-far-from-land-as-possible", "content_en": "

Given an n x n grid containing only values 0 and 1, where 0 represents water and 1 represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or water exists in the grid, return -1.

\n\n

The distance used in this problem is the Manhattan distance: the distance between two cells (x0, y0) and (x1, y1) is |x0 - x1| + |y0 - y1|.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: grid = [[1,0,1],[0,0,0],[1,0,1]]\nOutput: 2\nExplanation: The cell (1, 1) is as far as possible from all the land with distance 2.\n
\n\n

Example 2:

\n\"\"\n
\nInput: grid = [[1,0,0],[0,0,0],[0,0,0]]\nOutput: 4\nExplanation: The cell (2, 2) is as far as possible from all the land with distance 4.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == grid.length
  • \n\t
  • n == grid[i].length
  • \n\t
  • 1 <= n <= 100
  • \n\t
  • grid[i][j] is 0 or 1
  • \n
\n", "content_cn": "

\u4f60\u73b0\u5728\u624b\u91cc\u6709\u4e00\u4efd\u5927\u5c0f\u4e3a N x N \u7684 \u7f51\u683c grid\uff0c\u4e0a\u9762\u7684\u6bcf\u4e2a \u5355\u5143\u683c \u90fd\u7528 0 \u548c 1 \u6807\u8bb0\u597d\u4e86\u3002\u5176\u4e2d 0 \u4ee3\u8868\u6d77\u6d0b\uff0c1 \u4ee3\u8868\u9646\u5730\uff0c\u8bf7\u4f60\u627e\u51fa\u4e00\u4e2a\u6d77\u6d0b\u5355\u5143\u683c\uff0c\u8fd9\u4e2a\u6d77\u6d0b\u5355\u5143\u683c\u5230\u79bb\u5b83\u6700\u8fd1\u7684\u9646\u5730\u5355\u5143\u683c\u7684\u8ddd\u79bb\u662f\u6700\u5927\u7684\u3002

\n\n

\u6211\u4eec\u8fd9\u91cc\u8bf4\u7684\u8ddd\u79bb\u662f\u300c\u66fc\u54c8\u987f\u8ddd\u79bb\u300d\uff08 Manhattan Distance\uff09\uff1a(x0, y0) \u548c (x1, y1) \u8fd9\u4e24\u4e2a\u5355\u5143\u683c\u4e4b\u95f4\u7684\u8ddd\u79bb\u662f |x0 - x1| + |y0 - y1| \u3002

\n\n

\u5982\u679c\u7f51\u683c\u4e0a\u53ea\u6709\u9646\u5730\u6216\u8005\u6d77\u6d0b\uff0c\u8bf7\u8fd4\u56de -1\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1a[[1,0,1],[0,0,0],[1,0,1]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a \n\u6d77\u6d0b\u5355\u5143\u683c (1, 1) \u548c\u6240\u6709\u9646\u5730\u5355\u5143\u683c\u4e4b\u95f4\u7684\u8ddd\u79bb\u90fd\u8fbe\u5230\u6700\u5927\uff0c\u6700\u5927\u8ddd\u79bb\u4e3a 2\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1a[[1,0,0],[0,0,0],[0,0,0]]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a \n\u6d77\u6d0b\u5355\u5143\u683c (2, 2) \u548c\u6240\u6709\u9646\u5730\u5355\u5143\u683c\u4e4b\u95f4\u7684\u8ddd\u79bb\u90fd\u8fbe\u5230\u6700\u5927\uff0c\u6700\u5927\u8ddd\u79bb\u4e3a 4\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= grid.length == grid[0].length <= 100
  2. \n\t
  3. grid[i][j] \u4e0d\u662f 0 \u5c31\u662f 1
  4. \n
\n", "tags_en": ["Breadth-first Search", "Graph"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxDistance(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxDistance(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxDistance(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxDistance(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxDistance(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxDistance(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar maxDistance = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef max_distance(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxDistance(_ grid: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxDistance(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxDistance(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxDistance(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_distance(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function maxDistance($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxDistance(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-distance grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1162](https://leetcode-cn.com/problems/as-far-from-land-as-possible)", "[\u5730\u56fe\u5206\u6790](/solution/1100-1199/1162.As%20Far%20from%20Land%20as%20Possible/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u56fe`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1162](https://leetcode.com/problems/as-far-from-land-as-possible)", "[As Far from Land as Possible](/solution/1100-1199/1162.As%20Far%20from%20Land%20as%20Possible/README_EN.md)", "`Breadth-first Search`,`Graph`", "Medium", ""]}, {"question_id": "1116", "frontend_question_id": "1161", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-level-sum-of-a-binary-tree", "url_en": "https://leetcode.com/problems/maximum-level-sum-of-a-binary-tree", "relative_path_cn": "/solution/1100-1199/1161.Maximum%20Level%20Sum%20of%20a%20Binary%20Tree/README.md", "relative_path_en": "/solution/1100-1199/1161.Maximum%20Level%20Sum%20of%20a%20Binary%20Tree/README_EN.md", "title_cn": "\u6700\u5927\u5c42\u5185\u5143\u7d20\u548c", "title_en": "Maximum Level Sum of a Binary Tree", "question_title_slug": "maximum-level-sum-of-a-binary-tree", "content_en": "

Given the root of a binary tree, the level of its root is 1, the level of its children is 2, and so on.

\n\n

Return the smallest level x such that the sum of all the values of nodes at level x is maximal.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: root = [1,7,0,7,-8,null,null]\nOutput: 2\nExplanation: \nLevel 1 sum = 1.\nLevel 2 sum = 7 + 0 = 7.\nLevel 3 sum = 7 + -8 = -1.\nSo we return the level with the maximum sum which is level 2.\n
\n\n

Example 2:

\n\n
\nInput: root = [989,null,10250,98693,-89388,null,null,null,-32127]\nOutput: 2\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The number of nodes in the tree is in the range [1, 104].
  • \n\t
  • -105 <= Node.val <= 105
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9 root\u3002\u8bbe\u6839\u8282\u70b9\u4f4d\u4e8e\u4e8c\u53c9\u6811\u7684\u7b2c 1 \u5c42\uff0c\u800c\u6839\u8282\u70b9\u7684\u5b50\u8282\u70b9\u4f4d\u4e8e\u7b2c 2 \u5c42\uff0c\u4f9d\u6b64\u7c7b\u63a8\u3002

\n\n

\u8bf7\u4f60\u627e\u51fa\u5c42\u5185\u5143\u7d20\u4e4b\u548c \u6700\u5927 \u7684\u90a3\u51e0\u5c42\uff08\u53ef\u80fd\u53ea\u6709\u4e00\u5c42\uff09\u7684\u5c42\u53f7\uff0c\u5e76\u8fd4\u56de\u5176\u4e2d \u6700\u5c0f \u7684\u90a3\u4e2a\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1aroot = [1,7,0,7,-8,null,null]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n\u7b2c 1 \u5c42\u5404\u5143\u7d20\u4e4b\u548c\u4e3a 1\uff0c\n\u7b2c 2 \u5c42\u5404\u5143\u7d20\u4e4b\u548c\u4e3a 7 + 0 = 7\uff0c\n\u7b2c 3 \u5c42\u5404\u5143\u7d20\u4e4b\u548c\u4e3a 7 + -8 = -1\uff0c\n\u6240\u4ee5\u6211\u4eec\u8fd4\u56de\u7b2c 2 \u5c42\u7684\u5c42\u53f7\uff0c\u5b83\u7684\u5c42\u5185\u5143\u7d20\u4e4b\u548c\u6700\u5927\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aroot = [989,null,10250,98693,-89388,null,null,null,-32127]\n\u8f93\u51fa\uff1a2\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u6811\u4e2d\u7684\u8282\u70b9\u6570\u4ecb\u4e8e 1 \u548c 10^4 \u4e4b\u95f4
  • \n\t
  • -10^5 <= node.val <= 10^5
  • \n
\n", "tags_en": ["Tree", "Breadth-first Search"], "tags_cn": ["\u6811", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int maxLevelSum(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int maxLevelSum(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def maxLevelSum(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def maxLevelSum(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint maxLevelSum(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int MaxLevelSum(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar maxLevelSum = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef max_level_sum(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func maxLevelSum(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc maxLevelSum(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def maxLevelSum(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun maxLevelSum(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn max_level_sum(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function maxLevelSum($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction maxLevelSum(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (max-level-sum root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1161](https://leetcode-cn.com/problems/maximum-level-sum-of-a-binary-tree)", "[\u6700\u5927\u5c42\u5185\u5143\u7d20\u548c](/solution/1100-1199/1161.Maximum%20Level%20Sum%20of%20a%20Binary%20Tree/README.md)", "`\u6811`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1161](https://leetcode.com/problems/maximum-level-sum-of-a-binary-tree)", "[Maximum Level Sum of a Binary Tree](/solution/1100-1199/1161.Maximum%20Level%20Sum%20of%20a%20Binary%20Tree/README_EN.md)", "`Tree`,`Breadth-first Search`", "Medium", ""]}, {"question_id": "1115", "frontend_question_id": "1037", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/valid-boomerang", "url_en": "https://leetcode.com/problems/valid-boomerang", "relative_path_cn": "/solution/1000-1099/1037.Valid%20Boomerang/README.md", "relative_path_en": "/solution/1000-1099/1037.Valid%20Boomerang/README_EN.md", "title_cn": "\u6709\u6548\u7684\u56de\u65cb\u9556", "title_en": "Valid Boomerang", "question_title_slug": "valid-boomerang", "content_en": "

Given an array points where points[i] = [xi, yi] represents a point on the X-Y plane, return true if these points are a boomerang.

\n\n

A boomerang is a set of three points that are all distinct and not in a straight line.

\n\n

 

\n

Example 1:

\n
Input: points = [[1,1],[2,3],[3,2]]\nOutput: true\n

Example 2:

\n
Input: points = [[1,1],[2,2],[3,3]]\nOutput: false\n
\n

 

\n

Constraints:

\n\n
    \n\t
  • points.length == 3
  • \n\t
  • points[i].length == 2
  • \n\t
  • 0 <= xi, yi <= 100
  • \n
\n", "content_cn": "

\u56de\u65cb\u9556\u5b9a\u4e49\u4e3a\u4e00\u7ec4\u4e09\u4e2a\u70b9\uff0c\u8fd9\u4e9b\u70b9\u5404\u4e0d\u76f8\u540c\u4e14\u4e0d\u5728\u4e00\u6761\u76f4\u7ebf\u4e0a\u3002

\n\n

\u7ed9\u51fa\u5e73\u9762\u4e0a\u4e09\u4e2a\u70b9\u7ec4\u6210\u7684\u5217\u8868\uff0c\u5224\u65ad\u8fd9\u4e9b\u70b9\u662f\u5426\u53ef\u4ee5\u6784\u6210\u56de\u65cb\u9556\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a[[1,1],[2,3],[3,2]]\n\u8f93\u51fa\uff1atrue\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a[[1,1],[2,2],[3,3]]\n\u8f93\u51fa\uff1afalse
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. points.length == 3
  2. \n\t
  3. points[i].length == 2
  4. \n\t
  5. 0 <= points[i][j] <= 100
  6. \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isBoomerang(vector>& points) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isBoomerang(int[][] points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isBoomerang(self, points):\n \"\"\"\n :type points: List[List[int]]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isBoomerang(self, points: List[List[int]]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isBoomerang(int** points, int pointsSize, int* pointsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsBoomerang(int[][] points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} points\n * @return {boolean}\n */\nvar isBoomerang = function(points) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} points\n# @return {Boolean}\ndef is_boomerang(points)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isBoomerang(_ points: [[Int]]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isBoomerang(points [][]int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isBoomerang(points: Array[Array[Int]]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isBoomerang(points: Array): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_boomerang(points: Vec>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $points\n * @return Boolean\n */\n function isBoomerang($points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isBoomerang(points: number[][]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-boomerang points)\n (-> (listof (listof exact-integer?)) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1037](https://leetcode-cn.com/problems/valid-boomerang)", "[\u6709\u6548\u7684\u56de\u65cb\u9556](/solution/1000-1099/1037.Valid%20Boomerang/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[1037](https://leetcode.com/problems/valid-boomerang)", "[Valid Boomerang](/solution/1000-1099/1037.Valid%20Boomerang/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "1114", "frontend_question_id": "1038", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/binary-search-tree-to-greater-sum-tree", "url_en": "https://leetcode.com/problems/binary-search-tree-to-greater-sum-tree", "relative_path_cn": "/solution/1000-1099/1038.Binary%20Search%20Tree%20to%20Greater%20Sum%20Tree/README.md", "relative_path_en": "/solution/1000-1099/1038.Binary%20Search%20Tree%20to%20Greater%20Sum%20Tree/README_EN.md", "title_cn": "\u628a\u4e8c\u53c9\u641c\u7d22\u6811\u8f6c\u6362\u4e3a\u7d2f\u52a0\u6811", "title_en": "Binary Search Tree to Greater Sum Tree", "question_title_slug": "binary-search-tree-to-greater-sum-tree", "content_en": "

Given the root of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus sum of all keys greater than the original key in BST.

\r\n\r\n

As a reminder, a binary search tree is a tree that satisfies these constraints:

\r\n\r\n
    \r\n\t
  • The left subtree of a node contains only nodes with keys less than the node's key.
  • \r\n\t
  • The right subtree of a node contains only nodes with keys greater than the node's key.
  • \r\n\t
  • Both the left and right subtrees must also be binary search trees.
  • \r\n
\r\n\r\n

Note: This question is the same as 538: https://leetcode.com/problems/convert-bst-to-greater-tree/

\r\n\r\n

 

\r\n

Example 1:

\r\n\"\"\r\n
\r\nInput: root = [4,1,6,0,2,5,7,null,null,null,3,null,null,null,8]\r\nOutput: [30,36,21,36,35,26,15,null,null,null,33,null,null,null,8]\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: root = [0,null,1]\r\nOutput: [1,null,1]\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: root = [1,0,2]\r\nOutput: [3,3,2]\r\n
\r\n\r\n

Example 4:

\r\n\r\n
\r\nInput: root = [3,2,4,1]\r\nOutput: [7,9,4,10]\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • The number of nodes in the tree is in the range [1, 100].
  • \r\n\t
  • 0 <= Node.val <= 100
  • \r\n\t
  • All the values in the tree are unique.
  • \r\n\t
  • root is guaranteed to be a valid binary search tree.
  • \r\n
", "content_cn": "

\u7ed9\u51fa\u4e8c\u53c9 \u641c\u7d22 \u6811\u7684\u6839\u8282\u70b9\uff0c\u8be5\u6811\u7684\u8282\u70b9\u503c\u5404\u4e0d\u76f8\u540c\uff0c\u8bf7\u4f60\u5c06\u5176\u8f6c\u6362\u4e3a\u7d2f\u52a0\u6811\uff08Greater Sum Tree\uff09\uff0c\u4f7f\u6bcf\u4e2a\u8282\u70b9 node \u7684\u65b0\u503c\u7b49\u4e8e\u539f\u6811\u4e2d\u5927\u4e8e\u6216\u7b49\u4e8e node.val \u7684\u503c\u4e4b\u548c\u3002

\n\n

\u63d0\u9192\u4e00\u4e0b\uff0c\u4e8c\u53c9\u641c\u7d22\u6811\u6ee1\u8db3\u4e0b\u5217\u7ea6\u675f\u6761\u4ef6\uff1a

\n\n
    \n\t
  • \u8282\u70b9\u7684\u5de6\u5b50\u6811\u4ec5\u5305\u542b\u952e \u5c0f\u4e8e \u8282\u70b9\u952e\u7684\u8282\u70b9\u3002
  • \n\t
  • \u8282\u70b9\u7684\u53f3\u5b50\u6811\u4ec5\u5305\u542b\u952e \u5927\u4e8e \u8282\u70b9\u952e\u7684\u8282\u70b9\u3002
  • \n\t
  • \u5de6\u53f3\u5b50\u6811\u4e5f\u5fc5\u987b\u662f\u4e8c\u53c9\u641c\u7d22\u6811\u3002
  • \n
\n\n

\u6ce8\u610f\uff1a\u8be5\u9898\u76ee\u4e0e 538: https://leetcode-cn.com/problems/convert-bst-to-greater-tree/  \u76f8\u540c

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1a[4,1,6,0,2,5,7,null,null,null,3,null,null,null,8]\n\u8f93\u51fa\uff1a[30,36,21,36,35,26,15,null,null,null,33,null,null,null,8]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aroot = [0,null,1]\n\u8f93\u51fa\uff1a[1,null,1]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aroot = [1,0,2]\n\u8f93\u51fa\uff1a[3,3,2]\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1aroot = [3,2,4,1]\n\u8f93\u51fa\uff1a[7,9,4,10]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u6811\u4e2d\u7684\u8282\u70b9\u6570\u4ecb\u4e8e 1 \u548c 100 \u4e4b\u95f4\u3002
  • \n\t
  • \u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u4ecb\u4e8e 0 \u548c 100 \u4e4b\u95f4\u3002
  • \n\t
  • \u6811\u4e2d\u7684\u6240\u6709\u503c \u4e92\u4e0d\u76f8\u540c \u3002
  • \n\t
  • \u7ed9\u5b9a\u7684\u6811\u4e3a\u4e8c\u53c9\u641c\u7d22\u6811\u3002
  • \n
\n", "tags_en": ["Tree", "Depth-first Search", "Binary Search Tree", "Recursion"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u4e8c\u53c9\u641c\u7d22\u6811", "\u9012\u5f52"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* bstToGst(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode bstToGst(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def bstToGst(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: TreeNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def bstToGst(self, root: TreeNode) -> TreeNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* bstToGst(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode BstToGst(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {TreeNode}\n */\nvar bstToGst = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {TreeNode}\ndef bst_to_gst(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func bstToGst(_ root: TreeNode?) -> TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc bstToGst(root *TreeNode) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def bstToGst(root: TreeNode): TreeNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun bstToGst(root: TreeNode?): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn bst_to_gst(root: Option>>) -> Option>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return TreeNode\n */\n function bstToGst($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction bstToGst(root: TreeNode | null): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (bst-to-gst root)\n (-> (or/c tree-node? #f) (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1038](https://leetcode-cn.com/problems/binary-search-tree-to-greater-sum-tree)", "[\u628a\u4e8c\u53c9\u641c\u7d22\u6811\u8f6c\u6362\u4e3a\u7d2f\u52a0\u6811](/solution/1000-1099/1038.Binary%20Search%20Tree%20to%20Greater%20Sum%20Tree/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u4e8c\u53c9\u641c\u7d22\u6811`,`\u9012\u5f52`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1038](https://leetcode.com/problems/binary-search-tree-to-greater-sum-tree)", "[Binary Search Tree to Greater Sum Tree](/solution/1000-1099/1038.Binary%20Search%20Tree%20to%20Greater%20Sum%20Tree/README_EN.md)", "`Tree`,`Depth-first Search`,`Binary Search Tree`,`Recursion`", "Medium", ""]}, {"question_id": "1113", "frontend_question_id": "1040", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/moving-stones-until-consecutive-ii", "url_en": "https://leetcode.com/problems/moving-stones-until-consecutive-ii", "relative_path_cn": "/solution/1000-1099/1040.Moving%20Stones%20Until%20Consecutive%20II/README.md", "relative_path_en": "/solution/1000-1099/1040.Moving%20Stones%20Until%20Consecutive%20II/README_EN.md", "title_cn": "\u79fb\u52a8\u77f3\u5b50\u76f4\u5230\u8fde\u7eed II", "title_en": "Moving Stones Until Consecutive II", "question_title_slug": "moving-stones-until-consecutive-ii", "content_en": "

On an infinite number line, the position of the i-th stone is given by stones[i].  Call a stone an endpoint stone if it has the smallest or largest position.

\r\n\r\n

Each turn, you pick up an endpoint stone and move it to an unoccupied position so that it is no longer an endpoint stone.

\r\n\r\n

In particular, if the stones are at say, stones = [1,2,5], you cannot move the endpoint stone at position 5, since moving it to any position (such as 0, or 3) will still keep that stone as an endpoint stone.

\r\n\r\n

The game ends when you cannot make any more moves, ie. the stones are in consecutive positions.

\r\n\r\n

When the game ends, what is the minimum and maximum number of moves that you could have made?  Return the answer as an length 2 array: answer = [minimum_moves, maximum_moves]

\r\n\r\n

 

\r\n\r\n

Example 1:

\r\n\r\n
\r\nInput: [7,4,9]\r\nOutput: [1,2]\r\nExplanation: \r\nWe can move 4 -> 8 for one move to finish the game.\r\nOr, we can move 9 -> 5, 4 -> 6 for two moves to finish the game.\r\n
\r\n\r\n
\r\n

Example 2:

\r\n\r\n
\r\nInput: [6,5,4,3,10]\r\nOutput: [2,3]\r\nWe can move 3 -> 8 then 10 -> 7 to finish the game.\r\nOr, we can move 3 -> 7, 4 -> 8, 5 -> 9 to finish the game.\r\nNotice we cannot move 10 -> 2 to finish the game, because that would be an illegal move.\r\n
\r\n\r\n
\r\n

Example 3:

\r\n\r\n
\r\nInput: [100,101,104,102,103]\r\nOutput: [0,0]
\r\n\r\n

 

\r\n
\r\n
\r\n\r\n

Note:

\r\n\r\n
    \r\n\t
  1. 3 <= stones.length <= 10^4
  2. \r\n\t
  3. 1 <= stones[i] <= 10^9
  4. \r\n\t
  5. stones[i] have distinct values.
  6. \r\n
\r\n\r\n
\r\n
\r\n
 
\r\n
\r\n
\r\n", "content_cn": "

\u5728\u4e00\u4e2a\u957f\u5ea6 \u65e0\u9650 \u7684\u6570\u8f74\u4e0a\uff0c\u7b2c i \u9897\u77f3\u5b50\u7684\u4f4d\u7f6e\u4e3a\u00a0stones[i]\u3002\u5982\u679c\u4e00\u9897\u77f3\u5b50\u7684\u4f4d\u7f6e\u6700\u5c0f/\u6700\u5927\uff0c\u90a3\u4e48\u8be5\u77f3\u5b50\u88ab\u79f0\u4f5c \u7aef\u70b9\u77f3\u5b50 \u3002

\n\n

\u6bcf\u4e2a\u56de\u5408\uff0c\u4f60\u53ef\u4ee5\u5c06\u4e00\u9897\u7aef\u70b9\u77f3\u5b50\u62ff\u8d77\u5e76\u79fb\u52a8\u5230\u4e00\u4e2a\u672a\u5360\u7528\u7684\u4f4d\u7f6e\uff0c\u4f7f\u5f97\u8be5\u77f3\u5b50\u4e0d\u518d\u662f\u4e00\u9897\u7aef\u70b9\u77f3\u5b50\u3002

\n\n

\u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0c\u5982\u679c\u77f3\u5b50\u50cf\u00a0stones = [1,2,5]\u00a0\u8fd9\u6837\uff0c\u4f60\u5c06 \u65e0\u6cd5 \u79fb\u52a8\u4f4d\u4e8e\u4f4d\u7f6e 5 \u7684\u7aef\u70b9\u77f3\u5b50\uff0c\u56e0\u4e3a\u65e0\u8bba\u5c06\u5b83\u79fb\u52a8\u5230\u4efb\u4f55\u4f4d\u7f6e\uff08\u4f8b\u5982 0 \u6216 3\uff09\uff0c\u8be5\u77f3\u5b50\u90fd\u4ecd\u7136\u4f1a\u662f\u7aef\u70b9\u77f3\u5b50\u3002

\n\n

\u5f53\u4f60\u65e0\u6cd5\u8fdb\u884c\u4efb\u4f55\u79fb\u52a8\u65f6\uff0c\u5373\uff0c\u8fd9\u4e9b\u77f3\u5b50\u7684\u4f4d\u7f6e\u8fde\u7eed\u65f6\uff0c\u6e38\u620f\u7ed3\u675f\u3002

\n\n

\u8981\u4f7f\u6e38\u620f\u7ed3\u675f\uff0c\u4f60\u53ef\u4ee5\u6267\u884c\u7684\u6700\u5c0f\u548c\u6700\u5927\u79fb\u52a8\u6b21\u6570\u5206\u522b\u662f\u591a\u5c11\uff1f \u4ee5\u957f\u5ea6\u4e3a 2 \u7684\u6570\u7ec4\u5f62\u5f0f\u8fd4\u56de\u7b54\u6848\uff1aanswer = [minimum_moves, maximum_moves] \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1a[7,4,9]\n\u8f93\u51fa\uff1a[1,2]\n\u89e3\u91ca\uff1a\n\u6211\u4eec\u53ef\u4ee5\u79fb\u52a8\u4e00\u6b21\uff0c4 -> 8\uff0c\u6e38\u620f\u7ed3\u675f\u3002\n\u6216\u8005\uff0c\u6211\u4eec\u53ef\u4ee5\u79fb\u52a8\u4e24\u6b21 9 -> 5\uff0c4 -> 6\uff0c\u6e38\u620f\u7ed3\u675f\u3002\n
\n\n

\u793a\u4f8b\u00a02\uff1a

\n\n
\n\u8f93\u5165\uff1a[6,5,4,3,10]\n\u8f93\u51fa\uff1a[2,3]\n\u89e3\u91ca\uff1a\n\u6211\u4eec\u53ef\u4ee5\u79fb\u52a8 3 -> 8\uff0c\u63a5\u7740\u662f 10 -> 7\uff0c\u6e38\u620f\u7ed3\u675f\u3002\n\u6216\u8005\uff0c\u6211\u4eec\u53ef\u4ee5\u79fb\u52a8 3 -> 7, 4 -> 8, 5 -> 9\uff0c\u6e38\u620f\u7ed3\u675f\u3002\n\u6ce8\u610f\uff0c\u6211\u4eec\u65e0\u6cd5\u8fdb\u884c 10 -> 2 \u8fd9\u6837\u7684\u79fb\u52a8\u6765\u7ed3\u675f\u6e38\u620f\uff0c\u56e0\u4e3a\u8fd9\u662f\u4e0d\u5408\u8981\u6c42\u7684\u79fb\u52a8\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1a[100,101,104,102,103]\n\u8f93\u51fa\uff1a[0,0]
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 3 <= stones.length <= 10^4
  • \n\t
  • 1 <= stones[i] <= 10^9
  • \n\t
  • stones[i]\u00a0\u7684\u503c\u5404\u4e0d\u76f8\u540c\u3002
  • \n
\n\n

\u00a0

\n", "tags_en": ["Array", "Sliding Window"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector numMovesStonesII(vector& stones) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] numMovesStonesII(int[] stones) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numMovesStonesII(self, stones):\n \"\"\"\n :type stones: List[int]\n :rtype: List[int]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numMovesStonesII(self, stones: List[int]) -> List[int]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* numMovesStonesII(int* stones, int stonesSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] NumMovesStonesII(int[] stones) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} stones\n * @return {number[]}\n */\nvar numMovesStonesII = function(stones) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} stones\n# @return {Integer[]}\ndef num_moves_stones_ii(stones)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numMovesStonesII(_ stones: [Int]) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numMovesStonesII(stones []int) []int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numMovesStonesII(stones: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numMovesStonesII(stones: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_moves_stones_ii(stones: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $stones\n * @return Integer[]\n */\n function numMovesStonesII($stones) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numMovesStonesII(stones: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-moves-stones-ii stones)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1040](https://leetcode-cn.com/problems/moving-stones-until-consecutive-ii)", "[\u79fb\u52a8\u77f3\u5b50\u76f4\u5230\u8fde\u7eed II](/solution/1000-1099/1040.Moving%20Stones%20Until%20Consecutive%20II/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1040](https://leetcode.com/problems/moving-stones-until-consecutive-ii)", "[Moving Stones Until Consecutive II](/solution/1000-1099/1040.Moving%20Stones%20Until%20Consecutive%20II/README_EN.md)", "`Array`,`Sliding Window`", "Medium", ""]}, {"question_id": "1112", "frontend_question_id": "1160", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-words-that-can-be-formed-by-characters", "url_en": "https://leetcode.com/problems/find-words-that-can-be-formed-by-characters", "relative_path_cn": "/solution/1100-1199/1160.Find%20Words%20That%20Can%20Be%20Formed%20by%20Characters/README.md", "relative_path_en": "/solution/1100-1199/1160.Find%20Words%20That%20Can%20Be%20Formed%20by%20Characters/README_EN.md", "title_cn": "\u62fc\u5199\u5355\u8bcd", "title_en": "Find Words That Can Be Formed by Characters", "question_title_slug": "find-words-that-can-be-formed-by-characters", "content_en": "

You are given an array of strings words and a string chars.

\r\n\r\n

A string is good if it can be formed by characters from chars (each character can only be used once).

\r\n\r\n

Return the sum of lengths of all good strings in words.

\r\n\r\n

 

\r\n\r\n

Example 1:

\r\n\r\n
\r\nInput: words = ["cat","bt","hat","tree"], chars = "atach"\r\nOutput: 6\r\nExplanation: \r\nThe strings that can be formed are "cat" and "hat" so the answer is 3 + 3 = 6.\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: words = ["hello","world","leetcode"], chars = "welldonehoneyr"\r\nOutput: 10\r\nExplanation: \r\nThe strings that can be formed are "hello" and "world" so the answer is 5 + 5 = 10.\r\n
\r\n\r\n

 

\r\n\r\n

Note:

\r\n\r\n
    \r\n\t
  1. 1 <= words.length <= 1000
  2. \r\n\t
  3. 1 <= words[i].length, chars.length <= 100
  4. \r\n\t
  5. All strings contain lowercase English letters only.
  6. \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u4efd\u300e\u8bcd\u6c47\u8868\u300f\uff08\u5b57\u7b26\u4e32\u6570\u7ec4\uff09 words \u548c\u4e00\u5f20\u300e\u5b57\u6bcd\u8868\u300f\uff08\u5b57\u7b26\u4e32\uff09 chars\u3002

\n\n

\u5047\u5982\u4f60\u53ef\u4ee5\u7528 chars \u4e2d\u7684\u300e\u5b57\u6bcd\u300f\uff08\u5b57\u7b26\uff09\u62fc\u5199\u51fa words \u4e2d\u7684\u67d0\u4e2a\u300e\u5355\u8bcd\u300f\uff08\u5b57\u7b26\u4e32\uff09\uff0c\u90a3\u4e48\u6211\u4eec\u5c31\u8ba4\u4e3a\u4f60\u638c\u63e1\u4e86\u8fd9\u4e2a\u5355\u8bcd\u3002

\n\n

\u6ce8\u610f\uff1a\u6bcf\u6b21\u62fc\u5199\uff08\u6307\u62fc\u5199\u8bcd\u6c47\u8868\u4e2d\u7684\u4e00\u4e2a\u5355\u8bcd\uff09\u65f6\uff0cchars \u4e2d\u7684\u6bcf\u4e2a\u5b57\u6bcd\u90fd\u53ea\u80fd\u7528\u4e00\u6b21\u3002

\n\n

\u8fd4\u56de\u8bcd\u6c47\u8868 words \u4e2d\u4f60\u638c\u63e1\u7684\u6240\u6709\u5355\u8bcd\u7684 \u957f\u5ea6\u4e4b\u548c\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1awords = ["cat","bt","hat","tree"], chars = "atach"\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a \n\u53ef\u4ee5\u5f62\u6210\u5b57\u7b26\u4e32 "cat" \u548c "hat"\uff0c\u6240\u4ee5\u7b54\u6848\u662f 3 + 3 = 6\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1awords = ["hello","world","leetcode"], chars = "welldonehoneyr"\n\u8f93\u51fa\uff1a10\n\u89e3\u91ca\uff1a\n\u53ef\u4ee5\u5f62\u6210\u5b57\u7b26\u4e32 "hello" \u548c "world"\uff0c\u6240\u4ee5\u7b54\u6848\u662f 5 + 5 = 10\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= words.length <= 1000
  2. \n\t
  3. 1 <= words[i].length, chars.length <= 100
  4. \n\t
  5. \u6240\u6709\u5b57\u7b26\u4e32\u4e2d\u90fd\u4ec5\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd
  6. \n
\n", "tags_en": ["Array", "Hash Table"], "tags_cn": ["\u6570\u7ec4", "\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countCharacters(vector& words, string chars) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countCharacters(String[] words, String chars) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countCharacters(self, words, chars):\n \"\"\"\n :type words: List[str]\n :type chars: str\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countCharacters(self, words: List[str], chars: str) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countCharacters(char ** words, int wordsSize, char * chars){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountCharacters(string[] words, string chars) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @param {string} chars\n * @return {number}\n */\nvar countCharacters = function(words, chars) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @param {String} chars\n# @return {Integer}\ndef count_characters(words, chars)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countCharacters(_ words: [String], _ chars: String) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countCharacters(words []string, chars string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countCharacters(words: Array[String], chars: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countCharacters(words: Array, chars: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_characters(words: Vec, chars: String) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @param String $chars\n * @return Integer\n */\n function countCharacters($words, $chars) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countCharacters(words: string[], chars: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-characters words chars)\n (-> (listof string?) string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1160](https://leetcode-cn.com/problems/find-words-that-can-be-formed-by-characters)", "[\u62fc\u5199\u5355\u8bcd](/solution/1100-1199/1160.Find%20Words%20That%20Can%20Be%20Formed%20by%20Characters/README.md)", "`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[1160](https://leetcode.com/problems/find-words-that-can-be-formed-by-characters)", "[Find Words That Can Be Formed by Characters](/solution/1100-1199/1160.Find%20Words%20That%20Can%20Be%20Formed%20by%20Characters/README_EN.md)", "`Array`,`Hash Table`", "Easy", ""]}, {"question_id": "1111", "frontend_question_id": "1039", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-score-triangulation-of-polygon", "url_en": "https://leetcode.com/problems/minimum-score-triangulation-of-polygon", "relative_path_cn": "/solution/1000-1099/1039.Minimum%20Score%20Triangulation%20of%20Polygon/README.md", "relative_path_en": "/solution/1000-1099/1039.Minimum%20Score%20Triangulation%20of%20Polygon/README_EN.md", "title_cn": "\u591a\u8fb9\u5f62\u4e09\u89d2\u5256\u5206\u7684\u6700\u4f4e\u5f97\u5206", "title_en": "Minimum Score Triangulation of Polygon", "question_title_slug": "minimum-score-triangulation-of-polygon", "content_en": "

You have a convex n-sided polygon where each vertex has an integer value. You are given an integer array values where values[i] is the value of the ith vertex (i.e., clockwise order).

\n\n

You will triangulate the polygon into n - 2 triangles. For each triangle, the value of that triangle is the product of the values of its vertices, and the total score of the triangulation is the sum of these values over all n - 2 triangles in the triangulation.

\n\n

Return the smallest possible total score that you can achieve with some triangulation of the polygon.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: values = [1,2,3]\nOutput: 6\nExplanation: The polygon is already triangulated, and the score of the only triangle is 6.\n
\n\n

Example 2:

\n\"\"\n
\nInput: values = [3,7,4,5]\nOutput: 144\nExplanation: There are two triangulations, with possible scores: 3*7*5 + 4*5*7 = 245, or 3*4*5 + 3*4*7 = 144.\nThe minimum score is 144.\n
\n\n

Example 3:

\n\"\"\n
\nInput: values = [1,3,1,4,1,5]\nOutput: 13\nExplanation: The minimum score triangulation has score 1*1*3 + 1*1*4 + 1*1*5 + 1*1*1 = 13.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == values.length
  • \n\t
  • 3 <= n <= 50
  • \n\t
  • 1 <= values[i] <= 100
  • \n
\n", "content_cn": "

\u7ed9\u5b9a N\uff0c\u60f3\u8c61\u4e00\u4e2a\u51f8 N \u8fb9\u591a\u8fb9\u5f62\uff0c\u5176\u9876\u70b9\u6309\u987a\u65f6\u9488\u987a\u5e8f\u4f9d\u6b21\u6807\u8bb0\u4e3a A[0], A[i], ..., A[N-1]\u3002

\n\n

\u5047\u8bbe\u60a8\u5c06\u591a\u8fb9\u5f62\u5256\u5206\u4e3a N-2 \u4e2a\u4e09\u89d2\u5f62\u3002\u5bf9\u4e8e\u6bcf\u4e2a\u4e09\u89d2\u5f62\uff0c\u8be5\u4e09\u89d2\u5f62\u7684\u503c\u662f\u9876\u70b9\u6807\u8bb0\u7684\u4e58\u79ef\uff0c\u4e09\u89d2\u5256\u5206\u7684\u5206\u6570\u662f\u8fdb\u884c\u4e09\u89d2\u5256\u5206\u540e\u6240\u6709 N-2 \u4e2a\u4e09\u89d2\u5f62\u7684\u503c\u4e4b\u548c\u3002

\n\n

\u8fd4\u56de\u591a\u8fb9\u5f62\u8fdb\u884c\u4e09\u89d2\u5256\u5206\u540e\u53ef\u4ee5\u5f97\u5230\u7684\u6700\u4f4e\u5206\u3002
\n 

\n\n
    \n
\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a[1,2,3]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u591a\u8fb9\u5f62\u5df2\u7ecf\u4e09\u89d2\u5316\uff0c\u552f\u4e00\u4e09\u89d2\u5f62\u7684\u5206\u6570\u4e3a 6\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1a[3,7,4,5]\n\u8f93\u51fa\uff1a144\n\u89e3\u91ca\uff1a\u6709\u4e24\u79cd\u4e09\u89d2\u5256\u5206\uff0c\u53ef\u80fd\u5f97\u5206\u5206\u522b\u4e3a\uff1a3*7*5 + 4*5*7 = 245\uff0c\u6216 3*4*5 + 3*4*7 = 144\u3002\u6700\u4f4e\u5206\u6570\u4e3a 144\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1a[1,3,1,4,1,5]\n\u8f93\u51fa\uff1a13\n\u89e3\u91ca\uff1a\u6700\u4f4e\u5206\u6570\u4e09\u89d2\u5256\u5206\u7684\u5f97\u5206\u60c5\u51b5\u4e3a 1*1*3 + 1*1*4 + 1*1*5 + 1*1*1 = 13\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 3 <= A.length <= 50
  2. \n\t
  3. 1 <= A[i] <= 100
  4. \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minScoreTriangulation(vector& values) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minScoreTriangulation(int[] values) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minScoreTriangulation(self, values):\n \"\"\"\n :type values: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minScoreTriangulation(self, values: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minScoreTriangulation(int* values, int valuesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinScoreTriangulation(int[] values) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} values\n * @return {number}\n */\nvar minScoreTriangulation = function(values) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} values\n# @return {Integer}\ndef min_score_triangulation(values)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minScoreTriangulation(_ values: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minScoreTriangulation(values []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minScoreTriangulation(values: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minScoreTriangulation(values: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_score_triangulation(values: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $values\n * @return Integer\n */\n function minScoreTriangulation($values) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minScoreTriangulation(values: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-score-triangulation values)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1039](https://leetcode-cn.com/problems/minimum-score-triangulation-of-polygon)", "[\u591a\u8fb9\u5f62\u4e09\u89d2\u5256\u5206\u7684\u6700\u4f4e\u5f97\u5206](/solution/1000-1099/1039.Minimum%20Score%20Triangulation%20of%20Polygon/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1039](https://leetcode.com/problems/minimum-score-triangulation-of-polygon)", "[Minimum Score Triangulation of Polygon](/solution/1000-1099/1039.Minimum%20Score%20Triangulation%20of%20Polygon/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "1108", "frontend_question_id": "1152", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/analyze-user-website-visit-pattern", "url_en": "https://leetcode.com/problems/analyze-user-website-visit-pattern", "relative_path_cn": "/solution/1100-1199/1152.Analyze%20User%20Website%20Visit%20Pattern/README.md", "relative_path_en": "/solution/1100-1199/1152.Analyze%20User%20Website%20Visit%20Pattern/README_EN.md", "title_cn": "\u7528\u6237\u7f51\u7ad9\u8bbf\u95ee\u884c\u4e3a\u5206\u6790", "title_en": "Analyze User Website Visit Pattern", "question_title_slug": "analyze-user-website-visit-pattern", "content_en": "

We are given some website visits: the user with name username[i] visited the website website[i] at time timestamp[i].

\n\n

A 3-sequence is a list of websites of length 3 sorted in ascending order by the time of their visits.  (The websites in a 3-sequence are not necessarily distinct.)

\n\n

Find the 3-sequence visited by the largest number of users. If there is more than one solution, return the lexicographically smallest such 3-sequence.

\n\n

 

\n\n

Example 1:

\n\n
\nInput: username = ["joe","joe","joe","james","james","james","james","mary","mary","mary"], timestamp = [1,2,3,4,5,6,7,8,9,10], website = ["home","about","career","home","cart","maps","home","home","about","career"]\nOutput: ["home","about","career"]\nExplanation: \nThe tuples in this example are:\n["joe", 1, "home"]\n["joe", 2, "about"]\n["joe", 3, "career"]\n["james", 4, "home"]\n["james", 5, "cart"]\n["james", 6, "maps"]\n["james", 7, "home"]\n["mary", 8, "home"]\n["mary", 9, "about"]\n["mary", 10, "career"]\nThe 3-sequence ("home", "about", "career") was visited at least once by 2 users.\nThe 3-sequence ("home", "cart", "maps") was visited at least once by 1 user.\nThe 3-sequence ("home", "cart", "home") was visited at least once by 1 user.\nThe 3-sequence ("home", "maps", "home") was visited at least once by 1 user.\nThe 3-sequence ("cart", "maps", "home") was visited at least once by 1 user.\n
\n\n

 

\n\n

Note:

\n\n
    \n\t
  1. 3 <= N = username.length = timestamp.length = website.length <= 50
  2. \n\t
  3. 1 <= username[i].length <= 10
  4. \n\t
  5. 0 <= timestamp[i] <= 10^9
  6. \n\t
  7. 1 <= website[i].length <= 10
  8. \n\t
  9. Both username[i] and website[i] contain only lowercase characters.
  10. \n\t
  11. It is guaranteed that there is at least one user who visited at least 3 websites.
  12. \n\t
  13. No user visits two websites at the same time.
  14. \n
\n", "content_cn": "

\u4e3a\u4e86\u8bc4\u4f30\u67d0\u7f51\u7ad9\u7684\u7528\u6237\u8f6c\u5316\u7387\uff0c\u6211\u4eec\u9700\u8981\u5bf9\u7528\u6237\u7684\u8bbf\u95ee\u884c\u4e3a\u8fdb\u884c\u5206\u6790\uff0c\u5e76\u5efa\u7acb\u7528\u6237\u884c\u4e3a\u6a21\u578b\u3002\u65e5\u5fd7\u6587\u4ef6\u4e2d\u5df2\u7ecf\u8bb0\u5f55\u4e86\u7528\u6237\u540d\u3001\u8bbf\u95ee\u65f6\u95f4 \u4ee5\u53ca \u9875\u9762\u8def\u5f84\u3002

\n\n

\u4e3a\u4e86\u65b9\u4fbf\u5206\u6790\uff0c\u65e5\u5fd7\u6587\u4ef6\u4e2d\u7684 N \u6761\u8bb0\u5f55\u5df2\u7ecf\u88ab\u89e3\u6790\u6210\u4e09\u4e2a\u957f\u5ea6\u76f8\u540c\u4e14\u957f\u5ea6\u90fd\u4e3a N \u7684\u6570\u7ec4\uff0c\u5206\u522b\u662f\uff1a\u7528\u6237\u540d username\uff0c\u8bbf\u95ee\u65f6\u95f4 timestamp \u548c \u9875\u9762\u8def\u5f84 website\u3002\u7b2c i \u6761\u8bb0\u5f55\u610f\u5473\u7740\u7528\u6237\u540d\u662f username[i] \u7684\u7528\u6237\u5728 timestamp[i] \u7684\u65f6\u5019\u8bbf\u95ee\u4e86\u8def\u5f84\u4e3a website[i] \u7684\u9875\u9762\u3002

\n\n

\u6211\u4eec\u9700\u8981\u627e\u5230\u7528\u6237\u8bbf\u95ee\u7f51\u7ad9\u65f6\u7684 \u300e\u5171\u6027\u884c\u4e3a\u8def\u5f84\u300f\uff0c\u4e5f\u5c31\u662f\u6709\u6700\u591a\u7684\u7528\u6237\u90fd \u81f3\u5c11\u6309\u67d0\u79cd\u6b21\u5e8f\u8bbf\u95ee\u8fc7\u4e00\u6b21 \u7684\u4e09\u4e2a\u9875\u9762\u8def\u5f84\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u7528\u6237 \u53ef\u80fd\u4e0d\u662f\u8fde\u7eed\u8bbf\u95ee \u8fd9\u4e09\u4e2a\u8def\u5f84\u7684\u3002

\n\n

\u300e\u5171\u6027\u884c\u4e3a\u8def\u5f84\u300f\u662f\u4e00\u4e2a \u957f\u5ea6\u4e3a 3 \u7684\u9875\u9762\u8def\u5f84\u5217\u8868\uff0c\u5217\u8868\u4e2d\u7684\u8def\u5f84 \u4e0d\u5fc5\u4e0d\u540c\uff0c\u5e76\u4e14\u6309\u7167\u8bbf\u95ee\u65f6\u95f4\u7684\u5148\u540e\u5347\u5e8f\u6392\u5217\u3002

\n\n

\u5982\u679c\u6709\u591a\u4e2a\u6ee1\u8db3\u8981\u6c42\u7684\u7b54\u6848\uff0c\u90a3\u4e48\u5c31\u8bf7\u8fd4\u56de\u6309\u5b57\u5178\u5e8f\u6392\u5217\u6700\u5c0f\u7684\u90a3\u4e2a\u3002\uff08\u9875\u9762\u8def\u5f84\u5217\u8868 X \u6309\u5b57\u5178\u5e8f\u5c0f\u4e8e Y \u7684\u524d\u63d0\u6761\u4ef6\u662f\uff1aX[0] < Y[0] \u6216 X[0] == Y[0] \u4e14 (X[1] < Y[1] \u6216 X[1] == Y[1] \u4e14 X[2] < Y[2])\uff09

\n\n

\u9898\u76ee\u4fdd\u8bc1\u4e00\u4e2a\u7528\u6237\u4f1a\u81f3\u5c11\u8bbf\u95ee 3 \u4e2a\u8def\u5f84\u4e00\u81f4\u7684\u9875\u9762\uff0c\u5e76\u4e14\u4e00\u4e2a\u7528\u6237\u4e0d\u4f1a\u5728\u540c\u4e00\u65f6\u95f4\u8bbf\u95ee\u4e24\u4e2a\u8def\u5f84\u4e0d\u540c\u7684\u9875\u9762\u3002

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1ausername = ["joe","joe","joe","james","james","james","james","mary","mary","mary"], timestamp = [1,2,3,4,5,6,7,8,9,10], website = ["home","about","career","home","cart","maps","home","home","about","career"]\n\u8f93\u51fa\uff1a["home","about","career"]\n\u89e3\u91ca\uff1a\n\u7531\u793a\u4f8b\u8f93\u5165\u5f97\u5230\u7684\u8bb0\u5f55\u5982\u4e0b\uff1a\n["joe", 1, "home"]\n["joe", 2, "about"]\n["joe", 3, "career"]\n["james", 4, "home"]\n["james", 5, "cart"]\n["james", 6, "maps"]\n["james", 7, "home"]\n["mary", 8, "home"]\n["mary", 9, "about"]\n["mary", 10, "career"]\n\u6709 2 \u4e2a\u7528\u6237\u81f3\u5c11\u8bbf\u95ee\u8fc7\u4e00\u6b21 ("home", "about", "career")\u3002\n\u6709 1 \u4e2a\u7528\u6237\u81f3\u5c11\u8bbf\u95ee\u8fc7\u4e00\u6b21 ("home", "cart", "maps")\u3002\n\u6709 1 \u4e2a\u7528\u6237\u81f3\u5c11\u8bbf\u95ee\u8fc7\u4e00\u6b21 ("home", "cart", "home")\u3002\n\u6709 1 \u4e2a\u7528\u6237\u81f3\u5c11\u8bbf\u95ee\u8fc7\u4e00\u6b21 ("home", "maps", "home")\u3002\n\u6709 1 \u4e2a\u7528\u6237\u81f3\u5c11\u8bbf\u95ee\u8fc7\u4e00\u6b21 ("cart", "maps", "home")\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 3 <= N = username.length = timestamp.length = website.length <= 50
  2. \n\t
  3. 1 <= username[i].length <= 10
  4. \n\t
  5. 0 <= timestamp[i] <= 10^9
  6. \n\t
  7. 1 <= website[i].length <= 10
  8. \n\t
  9. username[i] \u548c website[i] \u90fd\u53ea\u542b\u5c0f\u5199\u5b57\u7b26
  10. \n
\n", "tags_en": ["Sort", "Array", "Hash Table"], "tags_cn": ["\u6392\u5e8f", "\u6570\u7ec4", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector mostVisitedPattern(vector& username, vector& timestamp, vector& website) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List mostVisitedPattern(String[] username, int[] timestamp, String[] website) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def mostVisitedPattern(self, username, timestamp, website):\n \"\"\"\n :type username: List[str]\n :type timestamp: List[int]\n :type website: List[str]\n :rtype: List[str]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def mostVisitedPattern(self, username: List[str], timestamp: List[int], website: List[str]) -> List[str]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** mostVisitedPattern(char ** username, int usernameSize, int* timestamp, int timestampSize, char ** website, int websiteSize, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList MostVisitedPattern(string[] username, int[] timestamp, string[] website) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} username\n * @param {number[]} timestamp\n * @param {string[]} website\n * @return {string[]}\n */\nvar mostVisitedPattern = function(username, timestamp, website) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} username\n# @param {Integer[]} timestamp\n# @param {String[]} website\n# @return {String[]}\ndef most_visited_pattern(username, timestamp, website)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func mostVisitedPattern(_ username: [String], _ timestamp: [Int], _ website: [String]) -> [String] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func mostVisitedPattern(username []string, timestamp []int, website []string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def mostVisitedPattern(username: Array[String], timestamp: Array[Int], website: Array[String]): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun mostVisitedPattern(username: Array, timestamp: IntArray, website: Array): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn most_visited_pattern(username: Vec, timestamp: Vec, website: Vec) -> Vec {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $username\n * @param Integer[] $timestamp\n * @param String[] $website\n * @return String[]\n */\n function mostVisitedPattern($username, $timestamp, $website) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function mostVisitedPattern(username: string[], timestamp: number[], website: string[]): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (most-visited-pattern username timestamp website)\n (-> (listof string?) (listof exact-integer?) (listof string?) (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1152](https://leetcode-cn.com/problems/analyze-user-website-visit-pattern)", "[\u7528\u6237\u7f51\u7ad9\u8bbf\u95ee\u884c\u4e3a\u5206\u6790](/solution/1100-1199/1152.Analyze%20User%20Website%20Visit%20Pattern/README.md)", "`\u6392\u5e8f`,`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1152](https://leetcode.com/problems/analyze-user-website-visit-pattern)", "[Analyze User Website Visit Pattern](/solution/1100-1199/1152.Analyze%20User%20Website%20Visit%20Pattern/README_EN.md)", "`Sort`,`Array`,`Hash Table`", "Medium", "\ud83d\udd12"]}, {"question_id": "1107", "frontend_question_id": "1151", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/minimum-swaps-to-group-all-1s-together", "url_en": "https://leetcode.com/problems/minimum-swaps-to-group-all-1s-together", "relative_path_cn": "/solution/1100-1199/1151.Minimum%20Swaps%20to%20Group%20All%201%27s%20Together/README.md", "relative_path_en": "/solution/1100-1199/1151.Minimum%20Swaps%20to%20Group%20All%201%27s%20Together/README_EN.md", "title_cn": "\u6700\u5c11\u4ea4\u6362\u6b21\u6570\u6765\u7ec4\u5408\u6240\u6709\u7684 1", "title_en": "Minimum Swaps to Group All 1's Together", "question_title_slug": "minimum-swaps-to-group-all-1s-together", "content_en": "

Given a binary array data, return the minimum number of swaps required to group all 1’s present in the array together in any place in the array.

\n\n

 

\n

Example 1:

\n\n
\nInput: data = [1,0,1,0,1]\nOutput: 1\nExplanation: \nThere are 3 ways to group all 1's together:\n[1,1,1,0,0] using 1 swap.\n[0,1,1,1,0] using 2 swaps.\n[0,0,1,1,1] using 1 swap.\nThe minimum is 1.\n
\n\n

Example 2:

\n\n
\nInput: data = [0,0,0,1,0]\nOutput: 0\nExplanation: \nSince there is only one 1 in the array, no swaps needed.\n
\n\n

Example 3:

\n\n
\nInput: data = [1,0,1,0,1,0,0,1,1,0,1]\nOutput: 3\nExplanation: \nOne possible solution that uses 3 swaps is [0,0,0,0,0,1,1,1,1,1,1].\n
\n\n

Example 4:

\n\n
\nInput: data = [1,0,1,0,1,0,1,1,1,0,1,0,0,1,1,1,0,0,1,1,1,0,1,0,1,1,0,0,0,1,1,1,1,0,0,1]\nOutput: 8\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= data.length <= 105
  • \n\t
  • data[i] is 0 or 1.
  • \n
\n", "content_cn": "

\u7ed9\u51fa\u4e00\u4e2a\u4e8c\u8fdb\u5236\u6570\u7ec4 data\uff0c\u4f60\u9700\u8981\u901a\u8fc7\u4ea4\u6362\u4f4d\u7f6e\uff0c\u5c06\u6570\u7ec4\u4e2d \u4efb\u4f55\u4f4d\u7f6e \u4e0a\u7684 1 \u7ec4\u5408\u5230\u4e00\u8d77\uff0c\u5e76\u8fd4\u56de\u6240\u6709\u53ef\u80fd\u4e2d\u6240\u9700 \u6700\u5c11\u7684\u4ea4\u6362\u6b21\u6570\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a[1,0,1,0,1]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a \n\u6709\u4e09\u79cd\u53ef\u80fd\u7684\u65b9\u6cd5\u53ef\u4ee5\u628a\u6240\u6709\u7684 1 \u7ec4\u5408\u5728\u4e00\u8d77\uff1a\n[1,1,1,0,0]\uff0c\u4ea4\u6362 1 \u6b21\uff1b\n[0,1,1,1,0]\uff0c\u4ea4\u6362 2 \u6b21\uff1b\n[0,0,1,1,1]\uff0c\u4ea4\u6362 1 \u6b21\u3002\n\u6240\u4ee5\u6700\u5c11\u7684\u4ea4\u6362\u6b21\u6570\u4e3a 1\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a[0,0,0,1,0]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a \n\u7531\u4e8e\u6570\u7ec4\u4e2d\u53ea\u6709\u4e00\u4e2a 1\uff0c\u6240\u4ee5\u4e0d\u9700\u8981\u4ea4\u6362\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1a[1,0,1,0,1,0,0,1,1,0,1]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\n\u4ea4\u6362 3 \u6b21\uff0c\u4e00\u79cd\u53ef\u884c\u7684\u53ea\u7528 3 \u6b21\u4ea4\u6362\u7684\u89e3\u51b3\u65b9\u6848\u662f [0,0,0,0,0,1,1,1,1,1,1]\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= data.length <= 10^5
  2. \n\t
  3. 0 <= data[i] <= 1
  4. \n
\n", "tags_en": ["Array", "Sliding Window"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minSwaps(vector& data) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minSwaps(int[] data) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minSwaps(self, data):\n \"\"\"\n :type data: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minSwaps(self, data: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minSwaps(int* data, int dataSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinSwaps(int[] data) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} data\n * @return {number}\n */\nvar minSwaps = function(data) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} data\n# @return {Integer}\ndef min_swaps(data)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minSwaps(_ data: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minSwaps(data []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minSwaps(data: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minSwaps(data: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_swaps(data: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $data\n * @return Integer\n */\n function minSwaps($data) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minSwaps(data: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-swaps data)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1151](https://leetcode-cn.com/problems/minimum-swaps-to-group-all-1s-together)", "[\u6700\u5c11\u4ea4\u6362\u6b21\u6570\u6765\u7ec4\u5408\u6240\u6709\u7684 1](/solution/1100-1199/1151.Minimum%20Swaps%20to%20Group%20All%201%27s%20Together/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1151](https://leetcode.com/problems/minimum-swaps-to-group-all-1s-together)", "[Minimum Swaps to Group All 1's Together](/solution/1100-1199/1151.Minimum%20Swaps%20to%20Group%20All%201%27s%20Together/README_EN.md)", "`Array`,`Sliding Window`", "Medium", "\ud83d\udd12"]}, {"question_id": "1106", "frontend_question_id": "1036", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/escape-a-large-maze", "url_en": "https://leetcode.com/problems/escape-a-large-maze", "relative_path_cn": "/solution/1000-1099/1036.Escape%20a%20Large%20Maze/README.md", "relative_path_en": "/solution/1000-1099/1036.Escape%20a%20Large%20Maze/README_EN.md", "title_cn": "\u9003\u79bb\u5927\u8ff7\u5bab", "title_en": "Escape a Large Maze", "question_title_slug": "escape-a-large-maze", "content_en": "

There is a 1 million by 1 million grid on an XY-plane, and the coordinates of each grid square are (x, y).

\n\n

We start at the source = [sx, sy] square and want to reach the target = [tx, ty] square. There is also an array of blocked squares, where each blocked[i] = [xi, yi] represents a blocked square with coordinates (xi, yi).

\n\n

Each move, we can walk one square north, east, south, or west if the square is not in the array of blocked squares. We are also not allowed to walk outside of the grid.

\n\n

Return true if and only if it is possible to reach the target square from the source square through a sequence of valid moves.

\n\n

 

\n

Example 1:

\n\n
\nInput: blocked = [[0,1],[1,0]], source = [0,0], target = [0,2]\nOutput: false\nExplanation: The target square is inaccessible starting from the source square because we cannot move.\nWe cannot move north or east because those squares are blocked.\nWe cannot move south or west because we cannot go outside of the grid.\n
\n\n

Example 2:

\n\n
\nInput: blocked = [], source = [0,0], target = [999999,999999]\nOutput: true\nExplanation: Because there are no blocked cells, it is possible to reach the target square.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 0 <= blocked.length <= 200
  • \n\t
  • blocked[i].length == 2
  • \n\t
  • 0 <= xi, yi < 106
  • \n\t
  • source.length == target.length == 2
  • \n\t
  • 0 <= sx, sy, tx, ty < 106
  • \n\t
  • source != target
  • \n\t
  • It is guaranteed that source and target are not blocked.
  • \n
\n", "content_cn": "

\u5728\u4e00\u4e2a 106 x 106 \u7684\u7f51\u683c\u4e2d\uff0c\u6bcf\u4e2a\u7f51\u683c\u4e0a\u65b9\u683c\u7684\u5750\u6807\u4e3a\u00a0(x, y) \u3002

\n\n

\u73b0\u5728\u4ece\u6e90\u65b9\u683c\u00a0source = [sx, sy]\u00a0\u5f00\u59cb\u51fa\u53d1\uff0c\u610f\u56fe\u8d76\u5f80\u76ee\u6807\u65b9\u683c\u00a0target = [tx, ty] \u3002\u6570\u7ec4 blocked \u662f\u5c01\u9501\u7684\u65b9\u683c\u5217\u8868\uff0c\u5176\u4e2d\u6bcf\u4e2a blocked[i] = [xi, yi] \u8868\u793a\u5750\u6807\u4e3a (xi, yi) \u7684\u65b9\u683c\u662f\u7981\u6b62\u901a\u884c\u7684\u3002

\n\n

\u6bcf\u6b21\u79fb\u52a8\uff0c\u90fd\u53ef\u4ee5\u8d70\u5230\u7f51\u683c\u4e2d\u5728\u56db\u4e2a\u65b9\u5411\u4e0a\u76f8\u90bb\u7684\u65b9\u683c\uff0c\u53ea\u8981\u8be5\u65b9\u683c \u4e0d \u5728\u7ed9\u51fa\u7684\u5c01\u9501\u5217\u8868\u00a0blocked\u00a0\u4e0a\u3002\u540c\u65f6\uff0c\u4e0d\u5141\u8bb8\u8d70\u51fa\u7f51\u683c\u3002

\n\n

\u53ea\u6709\u5728\u53ef\u4ee5\u901a\u8fc7\u4e00\u7cfb\u5217\u7684\u79fb\u52a8\u4ece\u6e90\u65b9\u683c\u00a0source \u5230\u8fbe\u76ee\u6807\u65b9\u683c\u00a0target \u65f6\u624d\u8fd4\u56de\u00a0true\u3002\u5426\u5219\uff0c\u8fd4\u56de false\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1ablocked = [[0,1],[1,0]], source = [0,0], target = [0,2]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\n\u4ece\u6e90\u65b9\u683c\u65e0\u6cd5\u5230\u8fbe\u76ee\u6807\u65b9\u683c\uff0c\u56e0\u4e3a\u6211\u4eec\u65e0\u6cd5\u5728\u7f51\u683c\u4e2d\u79fb\u52a8\u3002\n\u65e0\u6cd5\u5411\u5317\u6216\u8005\u5411\u4e1c\u79fb\u52a8\u662f\u56e0\u4e3a\u65b9\u683c\u7981\u6b62\u901a\u884c\u3002\n\u65e0\u6cd5\u5411\u5357\u6216\u8005\u5411\u897f\u79fb\u52a8\u662f\u56e0\u4e3a\u4e0d\u80fd\u8d70\u51fa\u7f51\u683c\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1ablocked = [], source = [0,0], target = [999999,999999]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\n\u56e0\u4e3a\u6ca1\u6709\u65b9\u683c\u88ab\u5c01\u9501\uff0c\u6240\u4ee5\u4e00\u5b9a\u53ef\u4ee5\u5230\u8fbe\u76ee\u6807\u65b9\u683c\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 0 <= blocked.length <= 200
  • \n\t
  • blocked[i].length == 2
  • \n\t
  • 0 <= xi, yi < 106
  • \n\t
  • source.length == target.length == 2
  • \n\t
  • 0 <= sx, sy, tx, ty < 106
  • \n\t
  • source != target
  • \n\t
  • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1 source \u548c target \u4e0d\u5728\u5c01\u9501\u5217\u8868\u5185
  • \n
\n", "tags_en": ["Breadth-first Search"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isEscapePossible(vector>& blocked, vector& source, vector& target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isEscapePossible(int[][] blocked, int[] source, int[] target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isEscapePossible(self, blocked, source, target):\n \"\"\"\n :type blocked: List[List[int]]\n :type source: List[int]\n :type target: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isEscapePossible(self, blocked: List[List[int]], source: List[int], target: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isEscapePossible(int** blocked, int blockedSize, int* blockedColSize, int* source, int sourceSize, int* target, int targetSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsEscapePossible(int[][] blocked, int[] source, int[] target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} blocked\n * @param {number[]} source\n * @param {number[]} target\n * @return {boolean}\n */\nvar isEscapePossible = function(blocked, source, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} blocked\n# @param {Integer[]} source\n# @param {Integer[]} target\n# @return {Boolean}\ndef is_escape_possible(blocked, source, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isEscapePossible(_ blocked: [[Int]], _ source: [Int], _ target: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isEscapePossible(blocked [][]int, source []int, target []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isEscapePossible(blocked: Array[Array[Int]], source: Array[Int], target: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isEscapePossible(blocked: Array, source: IntArray, target: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_escape_possible(blocked: Vec>, source: Vec, target: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $blocked\n * @param Integer[] $source\n * @param Integer[] $target\n * @return Boolean\n */\n function isEscapePossible($blocked, $source, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isEscapePossible(blocked: number[][], source: number[], target: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-escape-possible blocked source target)\n (-> (listof (listof exact-integer?)) (listof exact-integer?) (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1036](https://leetcode-cn.com/problems/escape-a-large-maze)", "[\u9003\u79bb\u5927\u8ff7\u5bab](/solution/1000-1099/1036.Escape%20a%20Large%20Maze/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[1036](https://leetcode.com/problems/escape-a-large-maze)", "[Escape a Large Maze](/solution/1000-1099/1036.Escape%20a%20Large%20Maze/README_EN.md)", "`Breadth-first Search`", "Hard", ""]}, {"question_id": "1105", "frontend_question_id": "1035", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/uncrossed-lines", "url_en": "https://leetcode.com/problems/uncrossed-lines", "relative_path_cn": "/solution/1000-1099/1035.Uncrossed%20Lines/README.md", "relative_path_en": "/solution/1000-1099/1035.Uncrossed%20Lines/README_EN.md", "title_cn": "\u4e0d\u76f8\u4ea4\u7684\u7ebf", "title_en": "Uncrossed Lines", "question_title_slug": "uncrossed-lines", "content_en": "

We write the integers of nums1 and nums2 (in the order they are given) on two separate horizontal lines.

\n\n

Now, we may draw connecting lines: a straight line connecting two numbers nums1[i] and nums2[j] such that:

\n\n
    \n\t
  • nums1[i] == nums2[j];
  • \n\t
  • The line we draw does not intersect any other connecting (non-horizontal) line.
  • \n
\n\n

Note that a connecting lines cannot intersect even at the endpoints: each number can only belong to one connecting line.

\n\n

Return the maximum number of connecting lines we can draw in this way.

\n\n

 

\n\n

Example 1:

\n\"\"\n
\nInput: nums1 = [1,4,2], nums2 = [1,2,4]\nOutput: 2\nExplanation: We can draw 2 uncrossed lines as in the diagram.\nWe cannot draw 3 uncrossed lines, because the line from nums1[1]=4 to nums2[2]=4 will intersect the line from nums1[2]=2 to nums2[1]=2.\n
\n\n
\n

Example 2:

\n\n
\nInput: nums1 = [2,5,1,2,5], nums2 = [10,5,2,1,5,2]\nOutput: 3\n
\n\n
\n

Example 3:

\n\n
\nInput: nums1 = [1,3,7,1,7,5], nums2 = [1,9,2,5,1]\nOutput: 2
\n\n

 

\n
\n
\n\n

Note:

\n\n
    \n\t
  1. 1 <= nums1.length <= 500
  2. \n\t
  3. 1 <= nums2.length <= 500
  4. \n\t
  5. 1 <= nums1[i], nums2[i] <= 2000
  6. \n
\n", "content_cn": "

\u5728\u4e24\u6761\u72ec\u7acb\u7684\u6c34\u5e73\u7ebf\u4e0a\u6309\u7ed9\u5b9a\u7684\u987a\u5e8f\u5199\u4e0b nums1 \u548c nums2 \u4e2d\u7684\u6574\u6570\u3002

\n\n

\u73b0\u5728\uff0c\u53ef\u4ee5\u7ed8\u5236\u4e00\u4e9b\u8fde\u63a5\u4e24\u4e2a\u6570\u5b57 nums1[i]\u00a0\u548c nums2[j]\u00a0\u7684\u76f4\u7ebf\uff0c\u8fd9\u4e9b\u76f4\u7ebf\u9700\u8981\u540c\u65f6\u6ee1\u8db3\u6ee1\u8db3\uff1a

\n\n
    \n\t
  • \u00a0nums1[i] == nums2[j]
  • \n\t
  • \u4e14\u7ed8\u5236\u7684\u76f4\u7ebf\u4e0d\u4e0e\u4efb\u4f55\u5176\u4ed6\u8fde\u7ebf\uff08\u975e\u6c34\u5e73\u7ebf\uff09\u76f8\u4ea4\u3002
  • \n
\n\n

\u8bf7\u6ce8\u610f\uff0c\u8fde\u7ebf\u5373\u4f7f\u5728\u7aef\u70b9\u4e5f\u4e0d\u80fd\u76f8\u4ea4\uff1a\u6bcf\u4e2a\u6570\u5b57\u53ea\u80fd\u5c5e\u4e8e\u4e00\u6761\u8fde\u7ebf\u3002

\n\n

\u4ee5\u8fd9\u79cd\u65b9\u6cd5\u7ed8\u5236\u7ebf\u6761\uff0c\u5e76\u8fd4\u56de\u53ef\u4ee5\u7ed8\u5236\u7684\u6700\u5927\u8fde\u7ebf\u6570\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\"\"\n\n
\n\u8f93\u5165\uff1anums1 = [1,4,2], nums2 = [1,2,4]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u53ef\u4ee5\u753b\u51fa\u4e24\u6761\u4e0d\u4ea4\u53c9\u7684\u7ebf\uff0c\u5982\u4e0a\u56fe\u6240\u793a\u3002 \n\u4f46\u65e0\u6cd5\u753b\u51fa\u7b2c\u4e09\u6761\u4e0d\u76f8\u4ea4\u7684\u76f4\u7ebf\uff0c\u56e0\u4e3a\u4ece nums1[1]=4 \u5230 nums2[2]=4 \u7684\u76f4\u7ebf\u5c06\u4e0e\u4ece nums1[2]=2 \u5230 nums2[1]=2 \u7684\u76f4\u7ebf\u76f8\u4ea4\u3002\n
\n\n
\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1anums1 = [2,5,1,2,5], nums2 = [10,5,2,1,5,2]\n\u8f93\u51fa\uff1a3\n
\n\n
\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1anums1 = [1,3,7,1,7,5], nums2 = [1,9,2,5,1]\n\u8f93\u51fa\uff1a2
\n\n

\u00a0

\n
\n
\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums1.length <= 500
  • \n\t
  • 1 <= nums2.length <= 500
  • \n\t
  • 1 <= nums1[i], nums2[i] <= 2000
  • \n
\n\n

\u00a0

\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxUncrossedLines(vector& nums1, vector& nums2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxUncrossedLines(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxUncrossedLines(self, nums1, nums2):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxUncrossedLines(self, nums1: List[int], nums2: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxUncrossedLines(int* nums1, int nums1Size, int* nums2, int nums2Size){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxUncrossedLines(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums1\n * @param {number[]} nums2\n * @return {number}\n */\nvar maxUncrossedLines = function(nums1, nums2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums1\n# @param {Integer[]} nums2\n# @return {Integer}\ndef max_uncrossed_lines(nums1, nums2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxUncrossedLines(_ nums1: [Int], _ nums2: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxUncrossedLines(nums1 []int, nums2 []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxUncrossedLines(nums1: Array[Int], nums2: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxUncrossedLines(nums1: IntArray, nums2: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_uncrossed_lines(nums1: Vec, nums2: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums1\n * @param Integer[] $nums2\n * @return Integer\n */\n function maxUncrossedLines($nums1, $nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxUncrossedLines(nums1: number[], nums2: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-uncrossed-lines nums1 nums2)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1035](https://leetcode-cn.com/problems/uncrossed-lines)", "[\u4e0d\u76f8\u4ea4\u7684\u7ebf](/solution/1000-1099/1035.Uncrossed%20Lines/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1035](https://leetcode.com/problems/uncrossed-lines)", "[Uncrossed Lines](/solution/1000-1099/1035.Uncrossed%20Lines/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "1104", "frontend_question_id": "1034", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/coloring-a-border", "url_en": "https://leetcode.com/problems/coloring-a-border", "relative_path_cn": "/solution/1000-1099/1034.Coloring%20A%20Border/README.md", "relative_path_en": "/solution/1000-1099/1034.Coloring%20A%20Border/README_EN.md", "title_cn": "\u8fb9\u6846\u7740\u8272", "title_en": "Coloring A Border", "question_title_slug": "coloring-a-border", "content_en": "

Given a 2-dimensional grid of integers, each value in the grid represents the color of the grid square at that location.

\r\n\r\n

Two squares belong to the same connected component if and only if they have the same color and are next to each other in any of the 4 directions.

\r\n\r\n

The border of a connected component is all the squares in the connected component that are either 4-directionally adjacent to a square not in the component, or on the boundary of the grid (the first or last row or column).

\r\n\r\n

Given a square at location (r0, c0) in the grid and a color, color the border of the connected component of that square with the given color, and return the final grid.

\r\n\r\n

 

\r\n\r\n

Example 1:

\r\n\r\n
\r\nInput: grid = [[1,1],[1,2]], r0 = 0, c0 = 0, color = 3\r\nOutput: [[3, 3], [3, 2]]\r\n
\r\n\r\n
\r\n

Example 2:

\r\n\r\n
\r\nInput: grid = [[1,2,2],[2,3,2]], r0 = 0, c0 = 1, color = 3\r\nOutput: [[1, 3, 3], [2, 3, 3]]\r\n
\r\n\r\n
\r\n

Example 3:

\r\n\r\n
\r\nInput: grid = [[1,1,1],[1,1,1],[1,1,1]], r0 = 1, c0 = 1, color = 2\r\nOutput: [[2, 2, 2], [2, 1, 2], [2, 2, 2]]
\r\n
\r\n
\r\n\r\n

 

\r\n\r\n

Note:

\r\n\r\n
    \r\n\t
  1. 1 <= grid.length <= 50
  2. \r\n\t
  3. 1 <= grid[0].length <= 50
  4. \r\n\t
  5. 1 <= grid[i][j] <= 1000
  6. \r\n\t
  7. 0 <= r0 < grid.length
  8. \r\n\t
  9. 0 <= c0 < grid[0].length
  10. \r\n\t
  11. 1 <= color <= 1000
  12. \r\n
", "content_cn": "

\u7ed9\u51fa\u4e00\u4e2a\u4e8c\u7ef4\u6574\u6570\u7f51\u683c grid\uff0c\u7f51\u683c\u4e2d\u7684\u6bcf\u4e2a\u503c\u8868\u793a\u8be5\u4f4d\u7f6e\u5904\u7684\u7f51\u683c\u5757\u7684\u989c\u8272\u3002

\n\n

\u53ea\u6709\u5f53\u4e24\u4e2a\u7f51\u683c\u5757\u7684\u989c\u8272\u76f8\u540c\uff0c\u800c\u4e14\u5728\u56db\u4e2a\u65b9\u5411\u4e2d\u4efb\u610f\u4e00\u4e2a\u65b9\u5411\u4e0a\u76f8\u90bb\u65f6\uff0c\u5b83\u4eec\u5c5e\u4e8e\u540c\u4e00\u8fde\u901a\u5206\u91cf\u3002

\n\n

\u8fde\u901a\u5206\u91cf\u7684\u8fb9\u754c\u662f\u6307\u8fde\u901a\u5206\u91cf\u4e2d\u7684\u6240\u6709\u4e0e\u4e0d\u5728\u5206\u91cf\u4e2d\u7684\u6b63\u65b9\u5f62\u76f8\u90bb\uff08\u56db\u4e2a\u65b9\u5411\u4e0a\uff09\u7684\u6240\u6709\u6b63\u65b9\u5f62\uff0c\u6216\u8005\u5728\u7f51\u683c\u7684\u8fb9\u754c\u4e0a\uff08\u7b2c\u4e00\u884c/\u5217\u6216\u6700\u540e\u4e00\u884c/\u5217\uff09\u7684\u6240\u6709\u6b63\u65b9\u5f62\u3002

\n\n

\u7ed9\u51fa\u4f4d\u4e8e (r0, c0) \u7684\u7f51\u683c\u5757\u548c\u989c\u8272 color\uff0c\u4f7f\u7528\u6307\u5b9a\u989c\u8272 color \u4e3a\u6240\u7ed9\u7f51\u683c\u5757\u7684\u8fde\u901a\u5206\u91cf\u7684\u8fb9\u754c\u8fdb\u884c\u7740\u8272\uff0c\u5e76\u8fd4\u56de\u6700\u7ec8\u7684\u7f51\u683c grid \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1agrid = [[1,1],[1,2]], r0 = 0, c0 = 0, color = 3\n\u8f93\u51fa\uff1a[[3, 3], [3, 2]]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1agrid = [[1,2,2],[2,3,2]], r0 = 0, c0 = 1, color = 3\n\u8f93\u51fa\uff1a[[1, 3, 3], [2, 3, 3]]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1agrid = [[1,1,1],[1,1,1],[1,1,1]], r0 = 1, c0 = 1, color = 2\n\u8f93\u51fa\uff1a[[2, 2, 2], [2, 1, 2], [2, 2, 2]]
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= grid.length <= 50
  2. \n\t
  3. 1 <= grid[0].length <= 50
  4. \n\t
  5. 1 <= grid[i][j] <= 1000
  6. \n\t
  7. 0 <= r0 < grid.length
  8. \n\t
  9. 0 <= c0 < grid[0].length
  10. \n\t
  11. 1 <= color <= 1000
  12. \n
\n\n

 

\n", "tags_en": ["Depth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> colorBorder(vector>& grid, int r0, int c0, int color) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[][] colorBorder(int[][] grid, int r0, int c0, int color) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def colorBorder(self, grid, r0, c0, color):\n \"\"\"\n :type grid: List[List[int]]\n :type r0: int\n :type c0: int\n :type color: int\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def colorBorder(self, grid: List[List[int]], r0: int, c0: int, color: int) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** colorBorder(int** grid, int gridSize, int* gridColSize, int r0, int c0, int color, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[][] ColorBorder(int[][] grid, int r0, int c0, int color) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @param {number} r0\n * @param {number} c0\n * @param {number} color\n * @return {number[][]}\n */\nvar colorBorder = function(grid, r0, c0, color) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @param {Integer} r0\n# @param {Integer} c0\n# @param {Integer} color\n# @return {Integer[][]}\ndef color_border(grid, r0, c0, color)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func colorBorder(_ grid: [[Int]], _ r0: Int, _ c0: Int, _ color: Int) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func colorBorder(grid [][]int, r0 int, c0 int, color int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def colorBorder(grid: Array[Array[Int]], r0: Int, c0: Int, color: Int): Array[Array[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun colorBorder(grid: Array, r0: Int, c0: Int, color: Int): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn color_border(grid: Vec>, r0: i32, c0: i32, color: i32) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @param Integer $r0\n * @param Integer $c0\n * @param Integer $color\n * @return Integer[][]\n */\n function colorBorder($grid, $r0, $c0, $color) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function colorBorder(grid: number[][], r0: number, c0: number, color: number): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (color-border grid r0 c0 color)\n (-> (listof (listof exact-integer?)) exact-integer? exact-integer? exact-integer? (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1034](https://leetcode-cn.com/problems/coloring-a-border)", "[\u8fb9\u6846\u7740\u8272](/solution/1000-1099/1034.Coloring%20A%20Border/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1034](https://leetcode.com/problems/coloring-a-border)", "[Coloring A Border](/solution/1000-1099/1034.Coloring%20A%20Border/README_EN.md)", "`Depth-first Search`", "Medium", ""]}, {"question_id": "1103", "frontend_question_id": "1033", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/moving-stones-until-consecutive", "url_en": "https://leetcode.com/problems/moving-stones-until-consecutive", "relative_path_cn": "/solution/1000-1099/1033.Moving%20Stones%20Until%20Consecutive/README.md", "relative_path_en": "/solution/1000-1099/1033.Moving%20Stones%20Until%20Consecutive/README_EN.md", "title_cn": "\u79fb\u52a8\u77f3\u5b50\u76f4\u5230\u8fde\u7eed", "title_en": "Moving Stones Until Consecutive", "question_title_slug": "moving-stones-until-consecutive", "content_en": "

Three stones are on a number line at positions a, b, and c.

\r\n\r\n

Each turn, you pick up a stone at an endpoint (ie., either the lowest or highest position stone), and move it to an unoccupied position between those endpoints.  Formally, let's say the stones are currently at positions x, y, z with x < y < z.  You pick up the stone at either position x or position z, and move that stone to an integer position k, with x < k < z and k != y.

\r\n\r\n

The game ends when you cannot make any more moves, ie. the stones are in consecutive positions.

\r\n\r\n

When the game ends, what is the minimum and maximum number of moves that you could have made?  Return the answer as an length 2 array: answer = [minimum_moves, maximum_moves]

\r\n\r\n

 

\r\n\r\n

Example 1:

\r\n\r\n
\r\nInput: a = 1, b = 2, c = 5\r\nOutput: [1,2]\r\nExplanation: Move the stone from 5 to 3, or move the stone from 5 to 4 to 3.\r\n
\r\n\r\n
\r\n

Example 2:

\r\n\r\n
\r\nInput: a = 4, b = 3, c = 2\r\nOutput: [0,0]\r\nExplanation: We cannot make any moves.\r\n
\r\n\r\n
\r\n

Example 3:

\r\n\r\n
\r\nInput: a = 3, b = 5, c = 1\r\nOutput: [1,2]\r\nExplanation: Move the stone from 1 to 4; or move the stone from 1 to 2 to 4.\r\n
\r\n\r\n

 

\r\n
\r\n
\r\n\r\n

Note:

\r\n\r\n
    \r\n\t
  1. 1 <= a <= 100
  2. \r\n\t
  3. 1 <= b <= 100
  4. \r\n\t
  5. 1 <= c <= 100
  6. \r\n\t
  7. a != b, b != c, c != a
  8. \r\n
\r\n\r\n
\r\n

 

\r\n\r\n
\r\n
 
\r\n
\r\n
\r\n", "content_cn": "

\u4e09\u679a\u77f3\u5b50\u653e\u7f6e\u5728\u6570\u8f74\u4e0a\uff0c\u4f4d\u7f6e\u5206\u522b\u4e3a a\uff0cb\uff0cc\u3002

\n\n

\u6bcf\u4e00\u56de\u5408\uff0c\u4f60\u53ef\u4ee5\u4ece\u4e24\u7aef\u4e4b\u4e00\u62ff\u8d77\u4e00\u679a\u77f3\u5b50\uff08\u4f4d\u7f6e\u6700\u5927\u6216\u6700\u5c0f\uff09\uff0c\u5e76\u5c06\u5176\u653e\u5165\u4e24\u7aef\u4e4b\u95f4\u7684\u4efb\u4e00\u7a7a\u95f2\u4f4d\u7f6e\u3002\u5f62\u5f0f\u4e0a\uff0c\u5047\u8bbe\u8fd9\u4e09\u679a\u77f3\u5b50\u5f53\u524d\u5206\u522b\u4f4d\u4e8e\u4f4d\u7f6e x, y, z \u4e14 x < y < z\u3002\u90a3\u4e48\u5c31\u53ef\u4ee5\u4ece\u4f4d\u7f6e x \u6216\u8005\u662f\u4f4d\u7f6e z \u62ff\u8d77\u4e00\u679a\u77f3\u5b50\uff0c\u5e76\u5c06\u8be5\u77f3\u5b50\u79fb\u52a8\u5230\u67d0\u4e00\u6574\u6570\u4f4d\u7f6e k \u5904\uff0c\u5176\u4e2d x < k < z \u4e14 k != y\u3002

\n\n

\u5f53\u4f60\u65e0\u6cd5\u8fdb\u884c\u4efb\u4f55\u79fb\u52a8\u65f6\uff0c\u5373\uff0c\u8fd9\u4e9b\u77f3\u5b50\u7684\u4f4d\u7f6e\u8fde\u7eed\u65f6\uff0c\u6e38\u620f\u7ed3\u675f\u3002

\n\n

\u8981\u4f7f\u6e38\u620f\u7ed3\u675f\uff0c\u4f60\u53ef\u4ee5\u6267\u884c\u7684\u6700\u5c0f\u548c\u6700\u5927\u79fb\u52a8\u6b21\u6570\u5206\u522b\u662f\u591a\u5c11\uff1f \u4ee5\u957f\u5ea6\u4e3a 2 \u7684\u6570\u7ec4\u5f62\u5f0f\u8fd4\u56de\u7b54\u6848\uff1aanswer = [minimum_moves, maximum_moves]

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aa = 1, b = 2, c = 5\n\u8f93\u51fa\uff1a[1, 2]\n\u89e3\u91ca\uff1a\u5c06\u77f3\u5b50\u4ece 5 \u79fb\u52a8\u5230 4 \u518d\u79fb\u52a8\u5230 3\uff0c\u6216\u8005\u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u5c06\u77f3\u5b50\u79fb\u52a8\u5230 3\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aa = 4, b = 3, c = 2\n\u8f93\u51fa\uff1a[0, 0]\n\u89e3\u91ca\uff1a\u6211\u4eec\u65e0\u6cd5\u8fdb\u884c\u4efb\u4f55\u79fb\u52a8\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= a <= 100
  2. \n\t
  3. 1 <= b <= 100
  4. \n\t
  5. 1 <= c <= 100
  6. \n\t
  7. a != b, b != c, c != a
  8. \n
\n", "tags_en": ["Brainteaser"], "tags_cn": ["\u8111\u7b4b\u6025\u8f6c\u5f2f"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector numMovesStones(int a, int b, int c) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] numMovesStones(int a, int b, int c) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numMovesStones(self, a, b, c):\n \"\"\"\n :type a: int\n :type b: int\n :type c: int\n :rtype: List[int]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* numMovesStones(int a, int b, int c, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] NumMovesStones(int a, int b, int c) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} a\n * @param {number} b\n * @param {number} c\n * @return {number[]}\n */\nvar numMovesStones = function(a, b, c) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} a\n# @param {Integer} b\n# @param {Integer} c\n# @return {Integer[]}\ndef num_moves_stones(a, b, c)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numMovesStones(_ a: Int, _ b: Int, _ c: Int) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numMovesStones(a int, b int, c int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numMovesStones(a: Int, b: Int, c: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numMovesStones(a: Int, b: Int, c: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_moves_stones(a: i32, b: i32, c: i32) -> Vec {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $a\n * @param Integer $b\n * @param Integer $c\n * @return Integer[]\n */\n function numMovesStones($a, $b, $c) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numMovesStones(a: number, b: number, c: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-moves-stones a b c)\n (-> exact-integer? exact-integer? exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1033](https://leetcode-cn.com/problems/moving-stones-until-consecutive)", "[\u79fb\u52a8\u77f3\u5b50\u76f4\u5230\u8fde\u7eed](/solution/1000-1099/1033.Moving%20Stones%20Until%20Consecutive/README.md)", "`\u8111\u7b4b\u6025\u8f6c\u5f2f`", "\u7b80\u5355", ""], "md_table_row_en": ["[1033](https://leetcode.com/problems/moving-stones-until-consecutive)", "[Moving Stones Until Consecutive](/solution/1000-1099/1033.Moving%20Stones%20Until%20Consecutive/README_EN.md)", "`Brainteaser`", "Easy", ""]}, {"question_id": "1102", "frontend_question_id": "1150", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/check-if-a-number-is-majority-element-in-a-sorted-array", "url_en": "https://leetcode.com/problems/check-if-a-number-is-majority-element-in-a-sorted-array", "relative_path_cn": "/solution/1100-1199/1150.Check%20If%20a%20Number%20Is%20Majority%20Element%20in%20a%20Sorted%20Array/README.md", "relative_path_en": "/solution/1100-1199/1150.Check%20If%20a%20Number%20Is%20Majority%20Element%20in%20a%20Sorted%20Array/README_EN.md", "title_cn": "\u68c0\u67e5\u4e00\u4e2a\u6570\u662f\u5426\u5728\u6570\u7ec4\u4e2d\u5360\u7edd\u5927\u591a\u6570", "title_en": "Check If a Number Is Majority Element in a Sorted Array", "question_title_slug": "check-if-a-number-is-majority-element-in-a-sorted-array", "content_en": "

Given an array nums sorted in non-decreasing order, and a number target, return True if and only if target is a majority element.

\n\n

A majority element is an element that appears more than N/2 times in an array of length N.

\n\n

 

\n\n

Example 1:

\n\n
\nInput: nums = [2,4,5,5,5,5,5,6,6], target = 5\nOutput: true\nExplanation: \nThe value 5 appears 5 times and the length of the array is 9.\nThus, 5 is a majority element because 5 > 9/2 is true.\n
\n\n

Example 2:

\n\n
\nInput: nums = [10,100,101,101], target = 101\nOutput: false\nExplanation: \nThe value 101 appears 2 times and the length of the array is 4.\nThus, 101 is not a majority element because 2 > 4/2 is false.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 1000
  • \n\t
  • 1 <= nums[i] <= 10^9
  • \n\t
  • 1 <= target <= 10^9
  • \n
\n", "content_cn": "

\u7ed9\u51fa\u4e00\u4e2a\u6309 \u975e\u9012\u51cf\u00a0\u987a\u5e8f\u6392\u5217\u7684\u6570\u7ec4\u00a0nums\uff0c\u548c\u4e00\u4e2a\u76ee\u6807\u6570\u503c\u00a0target\u3002\u5047\u5982\u6570\u7ec4\u00a0nums \u4e2d\u7edd\u5927\u591a\u6570\u5143\u7d20\u7684\u6570\u503c\u90fd\u7b49\u4e8e\u00a0target\uff0c\u5219\u8fd4\u56de\u00a0True\uff0c\u5426\u5219\u8bf7\u8fd4\u56de\u00a0False\u3002

\n\n

\u6240\u8c13\u5360\u7edd\u5927\u591a\u6570\uff0c\u662f\u6307\u5728\u957f\u5ea6\u4e3a N\u00a0\u7684\u6570\u7ec4\u4e2d\u51fa\u73b0\u5fc5\u987b\u00a0\u8d85\u8fc7\u00a0N/2\u00a0\u6b21\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [2,4,5,5,5,5,5,6,6], target = 5\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\n\u6570\u5b57 5 \u51fa\u73b0\u4e86 5 \u6b21\uff0c\u800c\u6570\u7ec4\u7684\u957f\u5ea6\u4e3a 9\u3002\n\u6240\u4ee5\uff0c5 \u5728\u6570\u7ec4\u4e2d\u5360\u7edd\u5927\u591a\u6570\uff0c\u56e0\u4e3a 5 \u6b21 > 9/2\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [10,100,101,101], target = 101\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\n\u6570\u5b57 101 \u51fa\u73b0\u4e86 2 \u6b21\uff0c\u800c\u6570\u7ec4\u7684\u957f\u5ea6\u662f 4\u3002\n\u6240\u4ee5\uff0c101 \u4e0d\u662f \u6570\u7ec4\u5360\u7edd\u5927\u591a\u6570\u7684\u5143\u7d20\uff0c\u56e0\u4e3a 2 \u6b21 = 4/2\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 1000
  • \n\t
  • 1 <= nums[i] <= 10^9
  • \n\t
  • 1 <= target <= 10^9
  • \n
\n", "tags_en": ["Array", "Binary Search"], "tags_cn": ["\u6570\u7ec4", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isMajorityElement(vector& nums, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isMajorityElement(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isMajorityElement(self, nums, target):\n \"\"\"\n :type nums: List[int]\n :type target: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isMajorityElement(self, nums: List[int], target: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isMajorityElement(int* nums, int numsSize, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsMajorityElement(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} target\n * @return {boolean}\n */\nvar isMajorityElement = function(nums, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} target\n# @return {Boolean}\ndef is_majority_element(nums, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isMajorityElement(_ nums: [Int], _ target: Int) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isMajorityElement(nums []int, target int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isMajorityElement(nums: Array[Int], target: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isMajorityElement(nums: IntArray, target: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_majority_element(nums: Vec, target: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $target\n * @return Boolean\n */\n function isMajorityElement($nums, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isMajorityElement(nums: number[], target: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-majority-element nums target)\n (-> (listof exact-integer?) exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1150](https://leetcode-cn.com/problems/check-if-a-number-is-majority-element-in-a-sorted-array)", "[\u68c0\u67e5\u4e00\u4e2a\u6570\u662f\u5426\u5728\u6570\u7ec4\u4e2d\u5360\u7edd\u5927\u591a\u6570](/solution/1100-1199/1150.Check%20If%20a%20Number%20Is%20Majority%20Element%20in%20a%20Sorted%20Array/README.md)", "`\u6570\u7ec4`,`\u4e8c\u5206\u67e5\u627e`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1150](https://leetcode.com/problems/check-if-a-number-is-majority-element-in-a-sorted-array)", "[Check If a Number Is Majority Element in a Sorted Array](/solution/1100-1199/1150.Check%20If%20a%20Number%20Is%20Majority%20Element%20in%20a%20Sorted%20Array/README_EN.md)", "`Array`,`Binary Search`", "Easy", "\ud83d\udd12"]}, {"question_id": "1101", "frontend_question_id": "1136", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/parallel-courses", "url_en": "https://leetcode.com/problems/parallel-courses", "relative_path_cn": "/solution/1100-1199/1136.Parallel%20Courses/README.md", "relative_path_en": "/solution/1100-1199/1136.Parallel%20Courses/README_EN.md", "title_cn": "\u5e73\u884c\u8bfe\u7a0b", "title_en": "Parallel Courses", "question_title_slug": "parallel-courses", "content_en": "

You are given an integer n, which indicates that there are n courses labeled from 1 to n. You are also given an array relations where relations[i] = [prevCoursei, nextCoursei], representing a prerequisite relationship between course prevCoursei and course nextCoursei: course prevCoursei has to be taken before course nextCoursei.

\n\n

In one semester, you can take any number of courses as long as you have taken all the prerequisites in the previous semester for the courses you are taking.

\n\n

Return the minimum number of semesters needed to take all courses. If there is no way to take all the courses, return -1.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: n = 3, relations = [[1,3],[2,3]]\nOutput: 2\nExplanation: The figure above represents the given graph.\nIn the first semester, you can take courses 1 and 2.\nIn the second semester, you can take course 3.\n
\n\n

Example 2:

\n\"\"\n
\nInput: n = 3, relations = [[1,2],[2,3],[3,1]]\nOutput: -1\nExplanation: No course can be studied because they are prerequisites of each other.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 5000
  • \n\t
  • 1 <= relations.length <= 5000
  • \n\t
  • relations[i].length == 2
  • \n\t
  • 1 <= prevCoursei, nextCoursei <= n
  • \n\t
  • prevCoursei != nextCoursei
  • \n\t
  • All the pairs [prevCoursei, nextCoursei] are unique.
  • \n
\n", "content_cn": "

\u5df2\u77e5\u6709 N \u95e8\u8bfe\u7a0b\uff0c\u5b83\u4eec\u4ee5 1 \u5230 N \u8fdb\u884c\u7f16\u53f7\u3002

\n\n

\u7ed9\u4f60\u4e00\u4efd\u8bfe\u7a0b\u5173\u7cfb\u8868 relations[i] = [X, Y]\uff0c\u7528\u4ee5\u8868\u793a\u8bfe\u7a0b X \u548c\u8bfe\u7a0b Y \u4e4b\u95f4\u7684\u5148\u4fee\u5173\u7cfb\uff1a\u8bfe\u7a0b X \u5fc5\u987b\u5728\u8bfe\u7a0b Y \u4e4b\u524d\u4fee\u5b8c\u3002

\n\n

\u5047\u8bbe\u5728\u4e00\u4e2a\u5b66\u671f\u91cc\uff0c\u4f60\u53ef\u4ee5\u5b66\u4e60\u4efb\u4f55\u6570\u91cf\u7684\u8bfe\u7a0b\uff0c\u4f46\u524d\u63d0\u662f\u4f60\u5df2\u7ecf\u5b66\u4e60\u4e86\u5c06\u8981\u5b66\u4e60\u7684\u8fd9\u4e9b\u8bfe\u7a0b\u7684\u6240\u6709\u5148\u4fee\u8bfe\u7a0b\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u5b66\u5b8c\u5168\u90e8\u8bfe\u7a0b\u6240\u9700\u7684\u6700\u5c11\u5b66\u671f\u6570\u3002

\n\n

\u5982\u679c\u6ca1\u6709\u529e\u6cd5\u505a\u5230\u5b66\u5b8c\u5168\u90e8\u8fd9\u4e9b\u8bfe\u7a0b\u7684\u8bdd\uff0c\u5c31\u8fd4\u56de -1\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1aN = 3, relations = [[1,3],[2,3]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n\u5728\u7b2c\u4e00\u4e2a\u5b66\u671f\u5b66\u4e60\u8bfe\u7a0b 1 \u548c 2\uff0c\u5728\u7b2c\u4e8c\u4e2a\u5b66\u671f\u5b66\u4e60\u8bfe\u7a0b 3\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1aN = 3, relations = [[1,2],[2,3],[3,1]]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\n\u6ca1\u6709\u8bfe\u7a0b\u53ef\u4ee5\u5b66\u4e60\uff0c\u56e0\u4e3a\u5b83\u4eec\u76f8\u4e92\u4f9d\u8d56\u3002
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= N <= 5000
  2. \n\t
  3. 1 <= relations.length <= 5000
  4. \n\t
  5. relations[i][0] != relations[i][1]
  6. \n\t
  7. \u8f93\u5165\u4e2d\u6ca1\u6709\u91cd\u590d\u7684\u5173\u7cfb
  8. \n
\n", "tags_en": ["Depth-first Search", "Graph", "Dynamic Programming"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u56fe", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minimumSemesters(int n, vector>& relations) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minimumSemesters(int n, int[][] relations) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimumSemesters(self, n, relations):\n \"\"\"\n :type n: int\n :type relations: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimumSemesters(self, n: int, relations: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minimumSemesters(int n, int** relations, int relationsSize, int* relationsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinimumSemesters(int n, int[][] relations) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} relations\n * @return {number}\n */\nvar minimumSemesters = function(n, relations) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} relations\n# @return {Integer}\ndef minimum_semesters(n, relations)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimumSemesters(_ n: Int, _ relations: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimumSemesters(n int, relations [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimumSemesters(n: Int, relations: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimumSemesters(n: Int, relations: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimum_semesters(n: i32, relations: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $relations\n * @return Integer\n */\n function minimumSemesters($n, $relations) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimumSemesters(n: number, relations: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimum-semesters n relations)\n (-> exact-integer? (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1136](https://leetcode-cn.com/problems/parallel-courses)", "[\u5e73\u884c\u8bfe\u7a0b](/solution/1100-1199/1136.Parallel%20Courses/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u56fe`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1136](https://leetcode.com/problems/parallel-courses)", "[Parallel Courses](/solution/1100-1199/1136.Parallel%20Courses/README_EN.md)", "`Depth-first Search`,`Graph`,`Dynamic Programming`", "Medium", "\ud83d\udd12"]}, {"question_id": "1100", "frontend_question_id": "1135", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/connecting-cities-with-minimum-cost", "url_en": "https://leetcode.com/problems/connecting-cities-with-minimum-cost", "relative_path_cn": "/solution/1100-1199/1135.Connecting%20Cities%20With%20Minimum%20Cost/README.md", "relative_path_en": "/solution/1100-1199/1135.Connecting%20Cities%20With%20Minimum%20Cost/README_EN.md", "title_cn": "\u6700\u4f4e\u6210\u672c\u8054\u901a\u6240\u6709\u57ce\u5e02", "title_en": "Connecting Cities With Minimum Cost", "question_title_slug": "connecting-cities-with-minimum-cost", "content_en": "

There are n cities numbered from 1 to n.

\n\n

You are given connections, where each connections[i] = [city1, city2, cost] represents the cost to connect city1 and city2 together.  (A connection is bidirectional: connecting city1 and city2 is the same as connecting city2 and city1.)

\n\n

Return the minimum cost so that for every pair of cities, there exists a path of connections (possibly of length 1) that connects those two cities together.  The cost is the sum of the connection costs used. If the task is impossible, return -1.

\n\n

 

\n\n

Example 1:

\n\n

\"\"

\n\n
\nInput: n = 3, connections = [[1,2,5],[1,3,6],[2,3,1]]\nOutput: 6\nExplanation: \nChoosing any 2 edges will connect all cities so we choose the minimum 2.\n
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: n = 4, connections = [[1,2,3],[3,4,4]]\nOutput: -1\nExplanation: \nThere is no way to connect all cities even if all edges are used.\n
\n\n

 

\n\n

Note:

\n\n
    \n\t
  1. 1 <= n <= 10000
  2. \n\t
  3. 1 <= connections.length <= 10000
  4. \n\t
  5. 1 <= connections[i][0], connections[i][1] <= n
  6. \n\t
  7. 0 <= connections[i][2] <= 105
  8. \n\t
  9. connections[i][0] != connections[i][1]
  10. \n
\n", "content_cn": "

\u60f3\u8c61\u4e00\u4e0b\u4f60\u662f\u4e2a\u57ce\u5e02\u57fa\u5efa\u89c4\u5212\u8005\uff0c\u5730\u56fe\u4e0a\u6709 N \u5ea7\u57ce\u5e02\uff0c\u5b83\u4eec\u6309\u4ee5 1 \u5230 N \u7684\u6b21\u5e8f\u7f16\u53f7\u3002

\n\n

\u7ed9\u4f60\u4e00\u4e9b\u53ef\u8fde\u63a5\u7684\u9009\u9879 conections\uff0c\u5176\u4e2d\u6bcf\u4e2a\u9009\u9879 conections[i] = [city1, city2, cost] \u8868\u793a\u5c06\u57ce\u5e02 city1 \u548c\u57ce\u5e02 city2 \u8fde\u63a5\u6240\u8981\u7684\u6210\u672c\u3002\uff08\u8fde\u63a5\u662f\u53cc\u5411\u7684\uff0c\u4e5f\u5c31\u662f\u8bf4\u57ce\u5e02 city1 \u548c\u57ce\u5e02 city2 \u76f8\u8fde\u4e5f\u540c\u6837\u610f\u5473\u7740\u57ce\u5e02 city2 \u548c\u57ce\u5e02 city1 \u76f8\u8fde\uff09\u3002

\n\n

\u8fd4\u56de\u4f7f\u5f97\u6bcf\u5bf9\u57ce\u5e02\u95f4\u90fd\u5b58\u5728\u5c06\u5b83\u4eec\u8fde\u63a5\u5728\u4e00\u8d77\u7684\u8fde\u901a\u8def\u5f84\uff08\u53ef\u80fd\u957f\u5ea6\u4e3a 1 \u7684\uff09\u6700\u5c0f\u6210\u672c\u3002\u8be5\u6700\u5c0f\u6210\u672c\u5e94\u8be5\u662f\u6240\u7528\u5168\u90e8\u8fde\u63a5\u4ee3\u4ef7\u7684\u7efc\u5408\u3002\u5982\u679c\u6839\u636e\u5df2\u77e5\u6761\u4ef6\u65e0\u6cd5\u5b8c\u6210\u8be5\u9879\u4efb\u52a1\uff0c\u5219\u8bf7\u4f60\u8fd4\u56de -1\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1aN = 3, conections = [[1,2,5],[1,3,6],[2,3,1]]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\n\u9009\u51fa\u4efb\u610f 2 \u6761\u8fb9\u90fd\u53ef\u4ee5\u8fde\u63a5\u6240\u6709\u57ce\u5e02\uff0c\u6211\u4eec\u4ece\u4e2d\u9009\u53d6\u6210\u672c\u6700\u5c0f\u7684 2 \u6761\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1aN = 4, conections = [[1,2,3],[3,4,4]]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a \n\u5373\u4f7f\u8fde\u901a\u6240\u6709\u7684\u8fb9\uff0c\u4e5f\u65e0\u6cd5\u8fde\u63a5\u6240\u6709\u57ce\u5e02\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= N <= 10000
  2. \n\t
  3. 1 <= conections.length <= 10000
  4. \n\t
  5. 1 <= conections[i][0], conections[i][1] <= N
  6. \n\t
  7. 0 <= conections[i][2] <= 10^5
  8. \n\t
  9. conections[i][0] != conections[i][1]
  10. \n
\n", "tags_en": ["Union Find", "Graph"], "tags_cn": ["\u5e76\u67e5\u96c6", "\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minimumCost(int n, vector>& connections) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minimumCost(int n, int[][] connections) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimumCost(self, n, connections):\n \"\"\"\n :type n: int\n :type connections: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimumCost(self, n: int, connections: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minimumCost(int n, int** connections, int connectionsSize, int* connectionsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinimumCost(int n, int[][] connections) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} connections\n * @return {number}\n */\nvar minimumCost = function(n, connections) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} connections\n# @return {Integer}\ndef minimum_cost(n, connections)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimumCost(_ n: Int, _ connections: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimumCost(n int, connections [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimumCost(n: Int, connections: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimumCost(n: Int, connections: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimum_cost(n: i32, connections: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $connections\n * @return Integer\n */\n function minimumCost($n, $connections) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimumCost(n: number, connections: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimum-cost n connections)\n (-> exact-integer? (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1135](https://leetcode-cn.com/problems/connecting-cities-with-minimum-cost)", "[\u6700\u4f4e\u6210\u672c\u8054\u901a\u6240\u6709\u57ce\u5e02](/solution/1100-1199/1135.Connecting%20Cities%20With%20Minimum%20Cost/README.md)", "`\u5e76\u67e5\u96c6`,`\u56fe`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1135](https://leetcode.com/problems/connecting-cities-with-minimum-cost)", "[Connecting Cities With Minimum Cost](/solution/1100-1199/1135.Connecting%20Cities%20With%20Minimum%20Cost/README_EN.md)", "`Union Find`,`Graph`", "Medium", "\ud83d\udd12"]}, {"question_id": "1099", "frontend_question_id": "1102", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/path-with-maximum-minimum-value", "url_en": "https://leetcode.com/problems/path-with-maximum-minimum-value", "relative_path_cn": "/solution/1100-1199/1102.Path%20With%20Maximum%20Minimum%20Value/README.md", "relative_path_en": "/solution/1100-1199/1102.Path%20With%20Maximum%20Minimum%20Value/README_EN.md", "title_cn": "\u5f97\u5206\u6700\u9ad8\u7684\u8def\u5f84", "title_en": "Path With Maximum Minimum Value", "question_title_slug": "path-with-maximum-minimum-value", "content_en": "

Given a matrix of integers grid with m rows and n columns, find the maximum score of a path starting at [0,0] and ending at [m-1,n-1].

\n\n

The score of a path is the minimum value in that path.  For example, the value of the path 8 →  4 →  5 →  9 is 4.

\n\n

A path moves some number of times from one visited cell to any neighbouring unvisited cell in one of the 4 cardinal directions (north, east, west, south).

\n\n

 

\n\n

Example 1:

\n\n

\"\"

\n\n
\nInput: [[5,4,5],[1,2,6],[7,4,6]]\nOutput: 4\nExplanation: \nThe path with the maximum score is highlighted in yellow. \n
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: [[2,2,1,2,2,2],[1,2,2,2,1,2]]\nOutput: 2
\n\n

Example 3:

\n\n

\"\"

\n\n
\nInput: [[3,4,6,3,4],[0,2,1,1,7],[8,8,3,2,7],[3,2,4,9,8],[4,1,2,0,0],[4,6,5,4,3]]\nOutput: 3
\n\n

 

\n\n

Note:

\n\n
    \n\t
  1. 1 <= m, n <= 100
  2. \n\t
  3. 0 <= grid[i][j] <= 109
  4. \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a R \u884c C \u5217\u7684\u6574\u6570\u77e9\u9635 A\u3002\u77e9\u9635\u4e0a\u7684\u8def\u5f84\u4ece [0,0] \u5f00\u59cb\uff0c\u5728 [R-1,C-1] \u7ed3\u675f\u3002

\n\n

\u8def\u5f84\u6cbf\u56db\u4e2a\u57fa\u672c\u65b9\u5411\uff08\u4e0a\u3001\u4e0b\u3001\u5de6\u3001\u53f3\uff09\u5c55\u5f00\uff0c\u4ece\u4e00\u4e2a\u5df2\u8bbf\u95ee\u5355\u5143\u683c\u79fb\u52a8\u5230\u4efb\u4e00\u76f8\u90bb\u7684\u672a\u8bbf\u95ee\u5355\u5143\u683c\u3002

\n\n

\u8def\u5f84\u7684\u5f97\u5206\u662f\u8be5\u8def\u5f84\u4e0a\u7684 \u6700\u5c0f \u503c\u3002\u4f8b\u5982\uff0c\u8def\u5f84 8 →  4 →  5 →  9 \u7684\u503c\u4e3a 4 \u3002

\n\n

\u627e\u51fa\u6240\u6709\u8def\u5f84\u4e2d\u5f97\u5206 \u6700\u9ad8 \u7684\u90a3\u6761\u8def\u5f84\uff0c\u8fd4\u56de\u5176 \u5f97\u5206\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1a[[5,4,5],[1,2,6],[7,4,6]]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a \n\u5f97\u5206\u6700\u9ad8\u7684\u8def\u5f84\u7528\u9ec4\u8272\u7a81\u51fa\u663e\u793a\u3002 \n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1a[[2,2,1,2,2,2],[1,2,2,2,1,2]]\n\u8f93\u51fa\uff1a2
\n\n

\u793a\u4f8b 3\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1a[[3,4,6,3,4],[0,2,1,1,7],[8,8,3,2,7],[3,2,4,9,8],[4,1,2,0,0],[4,6,5,4,3]]\n\u8f93\u51fa\uff1a3
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= R, C <= 100
  2. \n\t
  3. 0 <= A[i][j] <= 10^9
  4. \n
\n", "tags_en": ["Depth-first Search", "Union Find", "Graph"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e76\u67e5\u96c6", "\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maximumMinimumPath(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maximumMinimumPath(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximumMinimumPath(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximumMinimumPath(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maximumMinimumPath(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaximumMinimumPath(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar maximumMinimumPath = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef maximum_minimum_path(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximumMinimumPath(_ grid: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximumMinimumPath(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximumMinimumPath(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximumMinimumPath(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximum_minimum_path(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function maximumMinimumPath($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximumMinimumPath(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximum-minimum-path grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1102](https://leetcode-cn.com/problems/path-with-maximum-minimum-value)", "[\u5f97\u5206\u6700\u9ad8\u7684\u8def\u5f84](/solution/1100-1199/1102.Path%20With%20Maximum%20Minimum%20Value/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e76\u67e5\u96c6`,`\u56fe`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1102](https://leetcode.com/problems/path-with-maximum-minimum-value)", "[Path With Maximum Minimum Value](/solution/1100-1199/1102.Path%20With%20Maximum%20Minimum%20Value/README_EN.md)", "`Depth-first Search`,`Union Find`,`Graph`", "Medium", "\ud83d\udd12"]}, {"question_id": "1098", "frontend_question_id": "1133", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/largest-unique-number", "url_en": "https://leetcode.com/problems/largest-unique-number", "relative_path_cn": "/solution/1100-1199/1133.Largest%20Unique%20Number/README.md", "relative_path_en": "/solution/1100-1199/1133.Largest%20Unique%20Number/README_EN.md", "title_cn": "\u6700\u5927\u552f\u4e00\u6570", "title_en": "Largest Unique Number", "question_title_slug": "largest-unique-number", "content_en": "

Given an array of integers A, return the largest integer that only occurs once.

\r\n\r\n

If no integer occurs once, return -1.

\r\n\r\n

 

\r\n\r\n

Example 1:

\r\n\r\n
\r\nInput: [5,7,3,9,4,9,8,3,1]\r\nOutput: 8\r\nExplanation: \r\nThe maximum integer in the array is 9 but it is repeated. The number 8 occurs only once, so it's the answer.\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: [9,9,8,8]\r\nOutput: -1\r\nExplanation: \r\nThere is no number that occurs only once.\r\n
\r\n\r\n

 

\r\n\r\n

Note:

\r\n\r\n
    \r\n\t
  1. 1 <= A.length <= 2000
  2. \r\n\t
  3. 0 <= A[i] <= 1000
  4. \r\n
\r\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 A\uff0c\u8bf7\u627e\u51fa\u5e76\u8fd4\u56de\u5728\u8be5\u6570\u7ec4\u4e2d\u4ec5\u51fa\u73b0\u4e00\u6b21\u7684\u6700\u5927\u6574\u6570\u3002

\n\n

\u5982\u679c\u4e0d\u5b58\u5728\u8fd9\u4e2a\u53ea\u51fa\u73b0\u4e00\u6b21\u7684\u6574\u6570\uff0c\u5219\u8fd4\u56de -1\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a[5,7,3,9,4,9,8,3,1]\n\u8f93\u51fa\uff1a8\n\u89e3\u91ca\uff1a \n\u6570\u7ec4\u4e2d\u6700\u5927\u7684\u6574\u6570\u662f 9\uff0c\u4f46\u5b83\u5728\u6570\u7ec4\u4e2d\u91cd\u590d\u51fa\u73b0\u4e86\u3002\u800c\u7b2c\u4e8c\u5927\u7684\u6574\u6570\u662f 8\uff0c\u5b83\u53ea\u51fa\u73b0\u4e86\u4e00\u6b21\uff0c\u6240\u4ee5\u7b54\u6848\u662f 8\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a[9,9,8,8]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a \n\u6570\u7ec4\u4e2d\u4e0d\u5b58\u5728\u4ec5\u51fa\u73b0\u4e00\u6b21\u7684\u6574\u6570\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= A.length <= 2000
  2. \n\t
  3. 0 <= A[i] <= 1000
  4. \n
\n", "tags_en": ["Array", "Hash Table"], "tags_cn": ["\u6570\u7ec4", "\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int largestUniqueNumber(vector& A) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int largestUniqueNumber(int[] A) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def largestUniqueNumber(self, A):\n \"\"\"\n :type A: List[int]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def largestUniqueNumber(self, A: List[int]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint largestUniqueNumber(int* A, int ASize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LargestUniqueNumber(int[] A) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} A\n * @return {number}\n */\nvar largestUniqueNumber = function(A) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} a\n# @return {Integer}\ndef largest_unique_number(a)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func largestUniqueNumber(_ A: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func largestUniqueNumber(A []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def largestUniqueNumber(A: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun largestUniqueNumber(A: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn largest_unique_number(a: Vec) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $A\n * @return Integer\n */\n function largestUniqueNumber($A) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function largestUniqueNumber(A: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (largest-unique-number A)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1133](https://leetcode-cn.com/problems/largest-unique-number)", "[\u6700\u5927\u552f\u4e00\u6570](/solution/1100-1199/1133.Largest%20Unique%20Number/README.md)", "`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1133](https://leetcode.com/problems/largest-unique-number)", "[Largest Unique Number](/solution/1100-1199/1133.Largest%20Unique%20Number/README_EN.md)", "`Array`,`Hash Table`", "Easy", "\ud83d\udd12"]}, {"question_id": "1097", "frontend_question_id": "1032", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/stream-of-characters", "url_en": "https://leetcode.com/problems/stream-of-characters", "relative_path_cn": "/solution/1000-1099/1032.Stream%20of%20Characters/README.md", "relative_path_en": "/solution/1000-1099/1032.Stream%20of%20Characters/README_EN.md", "title_cn": "\u5b57\u7b26\u6d41", "title_en": "Stream of Characters", "question_title_slug": "stream-of-characters", "content_en": "

Implement the StreamChecker class as follows:

\r\n\r\n
    \r\n\t
  • StreamChecker(words): Constructor, init the data structure with the given words.
  • \r\n\t
  • query(letter): returns true if and only if for some k >= 1, the last k characters queried (in order from oldest to newest, including this letter just queried) spell one of the words in the given list.
  • \r\n
\r\n\r\n

 

\r\n\r\n

Example:

\r\n\r\n
\r\nStreamChecker streamChecker = new StreamChecker(["cd","f","kl"]); // init the dictionary.\r\nstreamChecker.query('a');          // return false\r\nstreamChecker.query('b');          // return false\r\nstreamChecker.query('c');          // return false\r\nstreamChecker.query('d');          // return true, because 'cd' is in the wordlist\r\nstreamChecker.query('e');          // return false\r\nstreamChecker.query('f');          // return true, because 'f' is in the wordlist\r\nstreamChecker.query('g');          // return false\r\nstreamChecker.query('h');          // return false\r\nstreamChecker.query('i');          // return false\r\nstreamChecker.query('j');          // return false\r\nstreamChecker.query('k');          // return false\r\nstreamChecker.query('l');          // return true, because 'kl' is in the wordlist\r\n
\r\n\r\n

 

\r\n\r\n

Note:

\r\n\r\n
    \r\n\t
  • 1 <= words.length <= 2000
  • \r\n\t
  • 1 <= words[i].length <= 2000
  • \r\n\t
  • Words will only consist of lowercase English letters.
  • \r\n\t
  • Queries will only consist of lowercase English letters.
  • \r\n\t
  • The number of queries is at most 40000.
  • \r\n
\r\n", "content_cn": "

\u6309\u4e0b\u8ff0\u8981\u6c42\u5b9e\u73b0 StreamChecker \u7c7b\uff1a

\n\n
    \n\t
  • StreamChecker(words)\uff1a\u6784\u9020\u51fd\u6570\uff0c\u7528\u7ed9\u5b9a\u7684\u5b57\u8bcd\u521d\u59cb\u5316\u6570\u636e\u7ed3\u6784\u3002
  • \n\t
  • query(letter)\uff1a\u5982\u679c\u5b58\u5728\u67d0\u4e9b k >= 1\uff0c\u53ef\u4ee5\u7528\u67e5\u8be2\u7684\u6700\u540e k\u4e2a\u5b57\u7b26\uff08\u6309\u4ece\u65e7\u5230\u65b0\u987a\u5e8f\uff0c\u5305\u62ec\u521a\u521a\u67e5\u8be2\u7684\u5b57\u6bcd\uff09\u62fc\u5199\u51fa\u7ed9\u5b9a\u5b57\u8bcd\u8868\u4e2d\u7684\u67d0\u4e00\u5b57\u8bcd\u65f6\uff0c\u8fd4\u56de true\u3002\u5426\u5219\uff0c\u8fd4\u56de false\u3002
  • \n
\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
StreamChecker streamChecker = new StreamChecker(["cd","f","kl"]); // \u521d\u59cb\u5316\u5b57\u5178\nstreamChecker.query('a');          // \u8fd4\u56de false\nstreamChecker.query('b');          // \u8fd4\u56de false\nstreamChecker.query('c');          // \u8fd4\u56de false\nstreamChecker.query('d');          // \u8fd4\u56de true\uff0c\u56e0\u4e3a 'cd' \u5728\u5b57\u8bcd\u8868\u4e2d\nstreamChecker.query('e');          // \u8fd4\u56de false\nstreamChecker.query('f');          // \u8fd4\u56de true\uff0c\u56e0\u4e3a 'f' \u5728\u5b57\u8bcd\u8868\u4e2d\nstreamChecker.query('g');          // \u8fd4\u56de false\nstreamChecker.query('h');          // \u8fd4\u56de false\nstreamChecker.query('i');          // \u8fd4\u56de false\nstreamChecker.query('j');          // \u8fd4\u56de false\nstreamChecker.query('k');          // \u8fd4\u56de false\nstreamChecker.query('l');          // \u8fd4\u56de true\uff0c\u56e0\u4e3a 'kl' \u5728\u5b57\u8bcd\u8868\u4e2d\u3002
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= words.length <= 2000
  • \n\t
  • 1 <= words[i].length <= 2000
  • \n\t
  • \u5b57\u8bcd\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
  • \n\t
  • \u5f85\u67e5\u9879\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
  • \n\t
  • \u5f85\u67e5\u9879\u6700\u591a 40000 \u4e2a\u3002
  • \n
\n", "tags_en": ["Trie"], "tags_cn": ["\u5b57\u5178\u6811"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class StreamChecker {\npublic:\n StreamChecker(vector& words) {\n\n }\n \n bool query(char letter) {\n\n }\n};\n\n/**\n * Your StreamChecker object will be instantiated and called as such:\n * StreamChecker* obj = new StreamChecker(words);\n * bool param_1 = obj->query(letter);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class StreamChecker {\n\n public StreamChecker(String[] words) {\n\n }\n \n public boolean query(char letter) {\n\n }\n}\n\n/**\n * Your StreamChecker object will be instantiated and called as such:\n * StreamChecker obj = new StreamChecker(words);\n * boolean param_1 = obj.query(letter);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class StreamChecker(object):\n\n def __init__(self, words):\n \"\"\"\n :type words: List[str]\n \"\"\"\n\n\n def query(self, letter):\n \"\"\"\n :type letter: str\n :rtype: bool\n \"\"\"\n\n\n\n# Your StreamChecker object will be instantiated and called as such:\n# obj = StreamChecker(words)\n# param_1 = obj.query(letter)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class StreamChecker:\n\n def __init__(self, words: List[str]):\n\n\n def query(self, letter: str) -> bool:\n\n\n\n# Your StreamChecker object will be instantiated and called as such:\n# obj = StreamChecker(words)\n# param_1 = obj.query(letter)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} StreamChecker;\n\n\nStreamChecker* streamCheckerCreate(char ** words, int wordsSize) {\n \n}\n\nbool streamCheckerQuery(StreamChecker* obj, char letter) {\n \n}\n\nvoid streamCheckerFree(StreamChecker* obj) {\n \n}\n\n/**\n * Your StreamChecker struct will be instantiated and called as such:\n * StreamChecker* obj = streamCheckerCreate(words, wordsSize);\n * bool param_1 = streamCheckerQuery(obj, letter);\n \n * streamCheckerFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class StreamChecker {\n\n public StreamChecker(string[] words) {\n\n }\n \n public bool Query(char letter) {\n\n }\n}\n\n/**\n * Your StreamChecker object will be instantiated and called as such:\n * StreamChecker obj = new StreamChecker(words);\n * bool param_1 = obj.Query(letter);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n */\nvar StreamChecker = function(words) {\n\n};\n\n/** \n * @param {character} letter\n * @return {boolean}\n */\nStreamChecker.prototype.query = function(letter) {\n\n};\n\n/**\n * Your StreamChecker object will be instantiated and called as such:\n * var obj = new StreamChecker(words)\n * var param_1 = obj.query(letter)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class StreamChecker\n\n=begin\n :type words: String[]\n=end\n def initialize(words)\n\n end\n\n\n=begin\n :type letter: Character\n :rtype: Boolean\n=end\n def query(letter)\n\n end\n\n\nend\n\n# Your StreamChecker object will be instantiated and called as such:\n# obj = StreamChecker.new(words)\n# param_1 = obj.query(letter)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass StreamChecker {\n\n init(_ words: [String]) {\n \n }\n \n func query(_ letter: Character) -> Bool {\n \n }\n}\n\n/**\n * Your StreamChecker object will be instantiated and called as such:\n * let obj = StreamChecker(words)\n * let ret_1: Bool = obj.query(letter)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type StreamChecker struct {\n\n}\n\n\nfunc Constructor(words []string) StreamChecker {\n\n}\n\n\nfunc (this *StreamChecker) Query(letter byte) bool {\n\n}\n\n\n/**\n * Your StreamChecker object will be instantiated and called as such:\n * obj := Constructor(words);\n * param_1 := obj.Query(letter);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class StreamChecker(_words: Array[String]) {\n\n def query(letter: Char): Boolean = {\n\n }\n\n}\n\n/**\n * Your StreamChecker object will be instantiated and called as such:\n * var obj = new StreamChecker(words)\n * var param_1 = obj.query(letter)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class StreamChecker(words: Array) {\n\n fun query(letter: Char): Boolean {\n\n }\n\n}\n\n/**\n * Your StreamChecker object will be instantiated and called as such:\n * var obj = StreamChecker(words)\n * var param_1 = obj.query(letter)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct StreamChecker {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl StreamChecker {\n\n fn new(words: Vec) -> Self {\n\n }\n \n fn query(&self, letter: char) -> bool {\n\n }\n}\n\n/**\n * Your StreamChecker object will be instantiated and called as such:\n * let obj = StreamChecker::new(words);\n * let ret_1: bool = obj.query(letter);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class StreamChecker {\n /**\n * @param String[] $words\n */\n function __construct($words) {\n \n }\n \n /**\n * @param String $letter\n * @return Boolean\n */\n function query($letter) {\n \n }\n}\n\n/**\n * Your StreamChecker object will be instantiated and called as such:\n * $obj = StreamChecker($words);\n * $ret_1 = $obj->query($letter);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class StreamChecker {\n constructor(words: string[]) {\n\n }\n\n query(letter: string): boolean {\n\n }\n}\n\n/**\n * Your StreamChecker object will be instantiated and called as such:\n * var obj = new StreamChecker(words)\n * var param_1 = obj.query(letter)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define stream-checker%\n (class object%\n (super-new)\n\n ; words : (listof string?)\n (init-field\n words)\n \n ; query : char? -> boolean?\n (define/public (query letter)\n\n )))\n\n;; Your stream-checker% object will be instantiated and called as such:\n;; (define obj (new stream-checker% [words words]))\n;; (define param_1 (send obj query letter))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1032](https://leetcode-cn.com/problems/stream-of-characters)", "[\u5b57\u7b26\u6d41](/solution/1000-1099/1032.Stream%20of%20Characters/README.md)", "`\u5b57\u5178\u6811`", "\u56f0\u96be", ""], "md_table_row_en": ["[1032](https://leetcode.com/problems/stream-of-characters)", "[Stream of Characters](/solution/1000-1099/1032.Stream%20of%20Characters/README_EN.md)", "`Trie`", "Hard", ""]}, {"question_id": "1096", "frontend_question_id": "1031", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-sum-of-two-non-overlapping-subarrays", "url_en": "https://leetcode.com/problems/maximum-sum-of-two-non-overlapping-subarrays", "relative_path_cn": "/solution/1000-1099/1031.Maximum%20Sum%20of%20Two%20Non-Overlapping%20Subarrays/README.md", "relative_path_en": "/solution/1000-1099/1031.Maximum%20Sum%20of%20Two%20Non-Overlapping%20Subarrays/README_EN.md", "title_cn": "\u4e24\u4e2a\u975e\u91cd\u53e0\u5b50\u6570\u7ec4\u7684\u6700\u5927\u548c", "title_en": "Maximum Sum of Two Non-Overlapping Subarrays", "question_title_slug": "maximum-sum-of-two-non-overlapping-subarrays", "content_en": "

Given an array nums of non-negative integers, return the maximum sum of elements in two non-overlapping (contiguous) subarrays, which have lengths firstLen and secondLen.  (For clarification, the firstLen-length subarray could occur before or after the secondLen-length subarray.)

\n\n

Formally, return the largest V for which V = (nums[i] + nums[i+1] + ... + nums[i+firstLen-1]) + (nums[j] + nums[j+1] + ... + nums[j+secondLen-1]) and either:

\n\n
    \n\t
  • 0 <= i < i + firstLen - 1 < j < j + secondLen - 1 < nums.length, or
  • \n\t
  • 0 <= j < j + secondLen - 1 < i < i + firstLen - 1 < nums.length.
  • \n
\n\n

 

\n\n
    \n
\n\n
\n

Example 1:

\n\n
\nInput: nums = [0,6,5,2,2,5,1,9,4], firstLen = 1, secondLen = 2\nOutput: 20\nExplanation: One choice of subarrays is [9] with length 1, and [6,5] with length 2.\n
\n\n
\n

Example 2:

\n\n
\nInput: nums = [3,8,1,3,2,1,8,9,0], firstLen = 3, secondLen = 2\nOutput: 29\nExplanation: One choice of subarrays is [3,8,1] with length 3, and [8,9] with length 2.\n
\n\n
\n

Example 3:

\n\n
\nInput: nums = [2,1,5,6,0,9,5,0,3,8], firstLen = 4, secondLen = 3\nOutput: 31\nExplanation: One choice of subarrays is [5,6,0,9] with length 4, and [3,8] with length 3.\n
\n\n

 

\n\n

Note:

\n\n
    \n\t
  1. firstLen >= 1
  2. \n\t
  3. secondLen >= 1
  4. \n\t
  5. firstLen + secondLen <= nums.length <= 1000
  6. \n\t
  7. 0 <= nums[i] <= 1000
  8. \n
\n
\n
\n
\n", "content_cn": "

\u7ed9\u51fa\u975e\u8d1f\u6574\u6570\u6570\u7ec4 A \uff0c\u8fd4\u56de\u4e24\u4e2a\u975e\u91cd\u53e0\uff08\u8fde\u7eed\uff09\u5b50\u6570\u7ec4\u4e2d\u5143\u7d20\u7684\u6700\u5927\u548c\uff0c\u5b50\u6570\u7ec4\u7684\u957f\u5ea6\u5206\u522b\u4e3a L \u548c M\u3002\uff08\u8fd9\u91cc\u9700\u8981\u6f84\u6e05\u7684\u662f\uff0c\u957f\u4e3a L \u7684\u5b50\u6570\u7ec4\u53ef\u4ee5\u51fa\u73b0\u5728\u957f\u4e3a M \u7684\u5b50\u6570\u7ec4\u4e4b\u524d\u6216\u4e4b\u540e\u3002\uff09

\n\n

\u4ece\u5f62\u5f0f\u4e0a\u770b\uff0c\u8fd4\u56de\u6700\u5927\u7684 V\uff0c\u800c V = (A[i] + A[i+1] + ... + A[i+L-1]) + (A[j] + A[j+1] + ... + A[j+M-1]) \u5e76\u6ee1\u8db3\u4e0b\u5217\u6761\u4ef6\u4e4b\u4e00\uff1a

\n\n

 

\n\n
    \n\t
  • 0 <= i < i + L - 1 < j < j + M - 1 < A.length, \u6216
  • \n\t
  • 0 <= j < j + M - 1 < i < i + L - 1 < A.length.
  • \n
\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aA = [0,6,5,2,2,5,1,9,4], L = 1, M = 2\n\u8f93\u51fa\uff1a20\n\u89e3\u91ca\uff1a\u5b50\u6570\u7ec4\u7684\u4e00\u79cd\u9009\u62e9\u4e2d\uff0c[9] \u957f\u5ea6\u4e3a 1\uff0c[6,5] \u957f\u5ea6\u4e3a 2\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aA = [3,8,1,3,2,1,8,9,0], L = 3, M = 2\n\u8f93\u51fa\uff1a29\n\u89e3\u91ca\uff1a\u5b50\u6570\u7ec4\u7684\u4e00\u79cd\u9009\u62e9\u4e2d\uff0c[3,8,1] \u957f\u5ea6\u4e3a 3\uff0c[8,9] \u957f\u5ea6\u4e3a 2\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aA = [2,1,5,6,0,9,5,0,3,8], L = 4, M = 3\n\u8f93\u51fa\uff1a31\n\u89e3\u91ca\uff1a\u5b50\u6570\u7ec4\u7684\u4e00\u79cd\u9009\u62e9\u4e2d\uff0c[5,6,0,9] \u957f\u5ea6\u4e3a 4\uff0c[0,3,8] \u957f\u5ea6\u4e3a 3\u3002
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. L >= 1
  2. \n\t
  3. M >= 1
  4. \n\t
  5. L + M <= A.length <= 1000
  6. \n\t
  7. 0 <= A[i] <= 1000
  8. \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxSumTwoNoOverlap(vector& nums, int firstLen, int secondLen) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxSumTwoNoOverlap(int[] nums, int firstLen, int secondLen) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxSumTwoNoOverlap(self, nums, firstLen, secondLen):\n \"\"\"\n :type nums: List[int]\n :type firstLen: int\n :type secondLen: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxSumTwoNoOverlap(self, nums: List[int], firstLen: int, secondLen: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxSumTwoNoOverlap(int* nums, int numsSize, int firstLen, int secondLen){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxSumTwoNoOverlap(int[] nums, int firstLen, int secondLen) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} firstLen\n * @param {number} secondLen\n * @return {number}\n */\nvar maxSumTwoNoOverlap = function(nums, firstLen, secondLen) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} first_len\n# @param {Integer} second_len\n# @return {Integer}\ndef max_sum_two_no_overlap(nums, first_len, second_len)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxSumTwoNoOverlap(_ nums: [Int], _ firstLen: Int, _ secondLen: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxSumTwoNoOverlap(nums []int, firstLen int, secondLen int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxSumTwoNoOverlap(nums: Array[Int], firstLen: Int, secondLen: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxSumTwoNoOverlap(nums: IntArray, firstLen: Int, secondLen: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_sum_two_no_overlap(nums: Vec, first_len: i32, second_len: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $firstLen\n * @param Integer $secondLen\n * @return Integer\n */\n function maxSumTwoNoOverlap($nums, $firstLen, $secondLen) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxSumTwoNoOverlap(nums: number[], firstLen: number, secondLen: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-sum-two-no-overlap nums firstLen secondLen)\n (-> (listof exact-integer?) exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1031](https://leetcode-cn.com/problems/maximum-sum-of-two-non-overlapping-subarrays)", "[\u4e24\u4e2a\u975e\u91cd\u53e0\u5b50\u6570\u7ec4\u7684\u6700\u5927\u548c](/solution/1000-1099/1031.Maximum%20Sum%20of%20Two%20Non-Overlapping%20Subarrays/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1031](https://leetcode.com/problems/maximum-sum-of-two-non-overlapping-subarrays)", "[Maximum Sum of Two Non-Overlapping Subarrays](/solution/1000-1099/1031.Maximum%20Sum%20of%20Two%20Non-Overlapping%20Subarrays/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "1095", "frontend_question_id": "1029", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/two-city-scheduling", "url_en": "https://leetcode.com/problems/two-city-scheduling", "relative_path_cn": "/solution/1000-1099/1029.Two%20City%20Scheduling/README.md", "relative_path_en": "/solution/1000-1099/1029.Two%20City%20Scheduling/README_EN.md", "title_cn": "\u4e24\u5730\u8c03\u5ea6", "title_en": "Two City Scheduling", "question_title_slug": "two-city-scheduling", "content_en": "

A company is planning to interview 2n people. Given the array costs where costs[i] = [aCosti, bCosti], the cost of flying the ith person to city a is aCosti, and the cost of flying the ith person to city b is bCosti.

\n\n

Return the minimum cost to fly every person to a city such that exactly n people arrive in each city.

\n\n

 

\n

Example 1:

\n\n
\nInput: costs = [[10,20],[30,200],[400,50],[30,20]]\nOutput: 110\nExplanation: \nThe first person goes to city A for a cost of 10.\nThe second person goes to city A for a cost of 30.\nThe third person goes to city B for a cost of 50.\nThe fourth person goes to city B for a cost of 20.\n\nThe total minimum cost is 10 + 30 + 50 + 20 = 110 to have half the people interviewing in each city.\n
\n\n

Example 2:

\n\n
\nInput: costs = [[259,770],[448,54],[926,667],[184,139],[840,118],[577,469]]\nOutput: 1859\n
\n\n

Example 3:

\n\n
\nInput: costs = [[515,563],[451,713],[537,709],[343,819],[855,779],[457,60],[650,359],[631,42]]\nOutput: 3086\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 * n == costs.length
  • \n\t
  • 2 <= costs.length <= 100
  • \n\t
  • costs.length is even.
  • \n\t
  • 1 <= aCosti, bCosti <= 1000
  • \n
\n", "content_cn": "

\u516c\u53f8\u8ba1\u5212\u9762\u8bd5 2N \u4eba\u3002\u7b2c i \u4eba\u98de\u5f80 A \u5e02\u7684\u8d39\u7528\u4e3a costs[i][0]\uff0c\u98de\u5f80 B \u5e02\u7684\u8d39\u7528\u4e3a costs[i][1]\u3002

\n\n

\u8fd4\u56de\u5c06\u6bcf\u4e2a\u4eba\u90fd\u98de\u5230\u67d0\u5ea7\u57ce\u5e02\u7684\u6700\u4f4e\u8d39\u7528\uff0c\u8981\u6c42\u6bcf\u4e2a\u57ce\u5e02\u90fd\u6709 N \u4eba\u62b5\u8fbe\u3002

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1a[[10,20],[30,200],[400,50],[30,20]]\n\u8f93\u51fa\uff1a110\n\u89e3\u91ca\uff1a\n\u7b2c\u4e00\u4e2a\u4eba\u53bb A \u5e02\uff0c\u8d39\u7528\u4e3a 10\u3002\n\u7b2c\u4e8c\u4e2a\u4eba\u53bb A \u5e02\uff0c\u8d39\u7528\u4e3a 30\u3002\n\u7b2c\u4e09\u4e2a\u4eba\u53bb B \u5e02\uff0c\u8d39\u7528\u4e3a 50\u3002\n\u7b2c\u56db\u4e2a\u4eba\u53bb B \u5e02\uff0c\u8d39\u7528\u4e3a 20\u3002\n\n\u6700\u4f4e\u603b\u8d39\u7528\u4e3a 10 + 30 + 50 + 20 = 110\uff0c\u6bcf\u4e2a\u57ce\u5e02\u90fd\u6709\u4e00\u534a\u7684\u4eba\u5728\u9762\u8bd5\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= costs.length <= 100
  2. \n\t
  3. costs.length \u4e3a\u5076\u6570
  4. \n\t
  5. 1 <= costs[i][0], costs[i][1] <= 1000
  6. \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int twoCitySchedCost(vector>& costs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int twoCitySchedCost(int[][] costs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def twoCitySchedCost(self, costs):\n \"\"\"\n :type costs: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def twoCitySchedCost(self, costs: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint twoCitySchedCost(int** costs, int costsSize, int* costsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int TwoCitySchedCost(int[][] costs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} costs\n * @return {number}\n */\nvar twoCitySchedCost = function(costs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} costs\n# @return {Integer}\ndef two_city_sched_cost(costs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func twoCitySchedCost(_ costs: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func twoCitySchedCost(costs [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def twoCitySchedCost(costs: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun twoCitySchedCost(costs: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn two_city_sched_cost(costs: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $costs\n * @return Integer\n */\n function twoCitySchedCost($costs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function twoCitySchedCost(costs: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (two-city-sched-cost costs)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1029](https://leetcode-cn.com/problems/two-city-scheduling)", "[\u4e24\u5730\u8c03\u5ea6](/solution/1000-1099/1029.Two%20City%20Scheduling/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1029](https://leetcode.com/problems/two-city-scheduling)", "[Two City Scheduling](/solution/1000-1099/1029.Two%20City%20Scheduling/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1094", "frontend_question_id": "1030", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/matrix-cells-in-distance-order", "url_en": "https://leetcode.com/problems/matrix-cells-in-distance-order", "relative_path_cn": "/solution/1000-1099/1030.Matrix%20Cells%20in%20Distance%20Order/README.md", "relative_path_en": "/solution/1000-1099/1030.Matrix%20Cells%20in%20Distance%20Order/README_EN.md", "title_cn": "\u8ddd\u79bb\u987a\u5e8f\u6392\u5217\u77e9\u9635\u5355\u5143\u683c", "title_en": "Matrix Cells in Distance Order", "question_title_slug": "matrix-cells-in-distance-order", "content_en": "

We are given a matrix with rows rows and cols columns has cells with integer coordinates (r, c), where 0 <= r < rows and 0 <= c < cols.

\n\n

Additionally, we are given a cell in that matrix with coordinates (rCenter, cCenter).

\n\n

Return the coordinates of all cells in the matrix, sorted by their distance from (rCenter, cCenter) from smallest distance to largest distance.  Here, the distance between two cells (r1, c1) and (r2, c2) is the Manhattan distance, |r1 - r2| + |c1 - c2|.  (You may return the answer in any order that satisfies this condition.)

\n\n

 

\n\n
\n

Example 1:

\n\n
\nInput: rows = 1, cols = 2, rCenter = 0, cCenter = 0\nOutput: [[0,0],[0,1]]\nExplanation: The distances from (0, 0) to other cells are: [0,1]\n
\n\n
\n

Example 2:

\n\n
\nInput: rows = 2, cols = 2, rCenter = 0, cCenter = 1\nOutput: [[0,1],[0,0],[1,1],[1,0]]\nExplanation: The distances from (0, 1) to other cells are: [0,1,1,2]\nThe answer [[0,1],[1,1],[0,0],[1,0]] would also be accepted as correct.\n
\n\n
\n

Example 3:

\n\n
\nInput: rows = 2, cols = 3, rCenter = 1, cCenter = 2\nOutput: [[1,2],[0,2],[1,1],[0,1],[1,0],[0,0]]\nExplanation: The distances from (1, 2) to other cells are: [0,1,1,2,2,3]\nThere are other answers that would also be accepted as correct, such as [[1,2],[1,1],[0,2],[1,0],[0,1],[0,0]].\n
\n\n

 

\n\n

Note:

\n\n
    \n\t
  1. 1 <= rows <= 100
  2. \n\t
  3. 1 <= cols <= 100
  4. \n\t
  5. 0 <= rCenter < rows
  6. \n\t
  7. 0 <= cCenter < cols
  8. \n
\n
\n
\n
\n", "content_cn": "

\u7ed9\u51fa R \u884c C \u5217\u7684\u77e9\u9635\uff0c\u5176\u4e2d\u7684\u5355\u5143\u683c\u7684\u6574\u6570\u5750\u6807\u4e3a (r, c)\uff0c\u6ee1\u8db3 0 <= r < R \u4e14 0 <= c < C\u3002

\n\n

\u53e6\u5916\uff0c\u6211\u4eec\u5728\u8be5\u77e9\u9635\u4e2d\u7ed9\u51fa\u4e86\u4e00\u4e2a\u5750\u6807\u4e3a (r0, c0) \u7684\u5355\u5143\u683c\u3002

\n\n

\u8fd4\u56de\u77e9\u9635\u4e2d\u7684\u6240\u6709\u5355\u5143\u683c\u7684\u5750\u6807\uff0c\u5e76\u6309\u5230 (r0, c0) \u7684\u8ddd\u79bb\u4ece\u6700\u5c0f\u5230\u6700\u5927\u7684\u987a\u5e8f\u6392\uff0c\u5176\u4e2d\uff0c\u4e24\u5355\u5143\u683c(r1, c1) \u548c (r2, c2) \u4e4b\u95f4\u7684\u8ddd\u79bb\u662f\u66fc\u54c8\u987f\u8ddd\u79bb\uff0c|r1 - r2| + |c1 - c2|\u3002\uff08\u4f60\u53ef\u4ee5\u6309\u4efb\u4f55\u6ee1\u8db3\u6b64\u6761\u4ef6\u7684\u987a\u5e8f\u8fd4\u56de\u7b54\u6848\u3002\uff09

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aR = 1, C = 2, r0 = 0, c0 = 0\n\u8f93\u51fa\uff1a[[0,0],[0,1]]\n\u89e3\u91ca\uff1a\u4ece (r0, c0) \u5230\u5176\u4ed6\u5355\u5143\u683c\u7684\u8ddd\u79bb\u4e3a\uff1a[0,1]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aR = 2, C = 2, r0 = 0, c0 = 1\n\u8f93\u51fa\uff1a[[0,1],[0,0],[1,1],[1,0]]\n\u89e3\u91ca\uff1a\u4ece (r0, c0) \u5230\u5176\u4ed6\u5355\u5143\u683c\u7684\u8ddd\u79bb\u4e3a\uff1a[0,1,1,2]\n[[0,1],[1,1],[0,0],[1,0]] \u4e5f\u4f1a\u88ab\u89c6\u4f5c\u6b63\u786e\u7b54\u6848\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aR = 2, C = 3, r0 = 1, c0 = 2\n\u8f93\u51fa\uff1a[[1,2],[0,2],[1,1],[0,1],[1,0],[0,0]]\n\u89e3\u91ca\uff1a\u4ece (r0, c0) \u5230\u5176\u4ed6\u5355\u5143\u683c\u7684\u8ddd\u79bb\u4e3a\uff1a[0,1,1,2,2,3]\n\u5176\u4ed6\u6ee1\u8db3\u9898\u76ee\u8981\u6c42\u7684\u7b54\u6848\u4e5f\u4f1a\u88ab\u89c6\u4e3a\u6b63\u786e\uff0c\u4f8b\u5982 [[1,2],[1,1],[0,2],[1,0],[0,1],[0,0]]\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= R <= 100
  2. \n\t
  3. 1 <= C <= 100
  4. \n\t
  5. 0 <= r0 < R
  6. \n\t
  7. 0 <= c0 < C
  8. \n
\n", "tags_en": ["Sort"], "tags_cn": ["\u6392\u5e8f"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> allCellsDistOrder(int rows, int cols, int rCenter, int cCenter) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[][] allCellsDistOrder(int rows, int cols, int rCenter, int cCenter) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def allCellsDistOrder(self, rows, cols, rCenter, cCenter):\n \"\"\"\n :type rows: int\n :type cols: int\n :type rCenter: int\n :type cCenter: int\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def allCellsDistOrder(self, rows: int, cols: int, rCenter: int, cCenter: int) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** allCellsDistOrder(int rows, int cols, int rCenter, int cCenter, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[][] AllCellsDistOrder(int rows, int cols, int rCenter, int cCenter) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} rows\n * @param {number} cols\n * @param {number} rCenter\n * @param {number} cCenter\n * @return {number[][]}\n */\nvar allCellsDistOrder = function(rows, cols, rCenter, cCenter) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} rows\n# @param {Integer} cols\n# @param {Integer} r_center\n# @param {Integer} c_center\n# @return {Integer[][]}\ndef all_cells_dist_order(rows, cols, r_center, c_center)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func allCellsDistOrder(_ rows: Int, _ cols: Int, _ rCenter: Int, _ cCenter: Int) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func allCellsDistOrder(rows int, cols int, rCenter int, cCenter int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def allCellsDistOrder(rows: Int, cols: Int, rCenter: Int, cCenter: Int): Array[Array[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun allCellsDistOrder(rows: Int, cols: Int, rCenter: Int, cCenter: Int): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn all_cells_dist_order(rows: i32, cols: i32, r_center: i32, c_center: i32) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $rows\n * @param Integer $cols\n * @param Integer $rCenter\n * @param Integer $cCenter\n * @return Integer[][]\n */\n function allCellsDistOrder($rows, $cols, $rCenter, $cCenter) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function allCellsDistOrder(rows: number, cols: number, rCenter: number, cCenter: number): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (all-cells-dist-order rows cols rCenter cCenter)\n (-> exact-integer? exact-integer? exact-integer? exact-integer? (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1030](https://leetcode-cn.com/problems/matrix-cells-in-distance-order)", "[\u8ddd\u79bb\u987a\u5e8f\u6392\u5217\u77e9\u9635\u5355\u5143\u683c](/solution/1000-1099/1030.Matrix%20Cells%20in%20Distance%20Order/README.md)", "`\u6392\u5e8f`", "\u7b80\u5355", ""], "md_table_row_en": ["[1030](https://leetcode.com/problems/matrix-cells-in-distance-order)", "[Matrix Cells in Distance Order](/solution/1000-1099/1030.Matrix%20Cells%20in%20Distance%20Order/README_EN.md)", "`Sort`", "Easy", ""]}, {"question_id": "1093", "frontend_question_id": "1028", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/recover-a-tree-from-preorder-traversal", "url_en": "https://leetcode.com/problems/recover-a-tree-from-preorder-traversal", "relative_path_cn": "/solution/1000-1099/1028.Recover%20a%20Tree%20From%20Preorder%20Traversal/README.md", "relative_path_en": "/solution/1000-1099/1028.Recover%20a%20Tree%20From%20Preorder%20Traversal/README_EN.md", "title_cn": "\u4ece\u5148\u5e8f\u904d\u5386\u8fd8\u539f\u4e8c\u53c9\u6811", "title_en": "Recover a Tree From Preorder Traversal", "question_title_slug": "recover-a-tree-from-preorder-traversal", "content_en": "

We run a preorder depth-first search (DFS) on the root of a binary tree.

\n\n

At each node in this traversal, we output D dashes (where D is the depth of this node), then we output the value of this node.  If the depth of a node is D, the depth of its immediate child is D + 1.  The depth of the root node is 0.

\n\n

If a node has only one child, that child is guaranteed to be the left child.

\n\n

Given the output traversal of this traversal, recover the tree and return its root.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: traversal = "1-2--3--4-5--6--7"\nOutput: [1,2,5,3,4,6,7]\n
\n\n

Example 2:

\n\"\"\n
\nInput: traversal = "1-2--3---4-5--6---7"\nOutput: [1,2,5,3,null,6,null,4,null,7]\n
\n\n

Example 3:

\n\"\"\n
\nInput: traversal = "1-401--349---90--88"\nOutput: [1,401,null,349,88,90]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The number of nodes in the original tree is in the range [1, 1000].
  • \n\t
  • 1 <= Node.val <= 109
  • \n
\n", "content_cn": "

\u6211\u4eec\u4ece\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9 root \u5f00\u59cb\u8fdb\u884c\u6df1\u5ea6\u4f18\u5148\u641c\u7d22\u3002

\n\n

\u5728\u904d\u5386\u4e2d\u7684\u6bcf\u4e2a\u8282\u70b9\u5904\uff0c\u6211\u4eec\u8f93\u51fa D \u6761\u77ed\u5212\u7ebf\uff08\u5176\u4e2d D \u662f\u8be5\u8282\u70b9\u7684\u6df1\u5ea6\uff09\uff0c\u7136\u540e\u8f93\u51fa\u8be5\u8282\u70b9\u7684\u503c\u3002\uff08\u5982\u679c\u8282\u70b9\u7684\u6df1\u5ea6\u4e3a D\uff0c\u5219\u5176\u76f4\u63a5\u5b50\u8282\u70b9\u7684\u6df1\u5ea6\u4e3a D + 1\u3002\u6839\u8282\u70b9\u7684\u6df1\u5ea6\u4e3a 0\uff09\u3002

\n\n

\u5982\u679c\u8282\u70b9\u53ea\u6709\u4e00\u4e2a\u5b50\u8282\u70b9\uff0c\u90a3\u4e48\u4fdd\u8bc1\u8be5\u5b50\u8282\u70b9\u4e3a\u5de6\u5b50\u8282\u70b9\u3002

\n\n

\u7ed9\u51fa\u904d\u5386\u8f93\u51fa S\uff0c\u8fd8\u539f\u6811\u5e76\u8fd4\u56de\u5176\u6839\u8282\u70b9 root\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1a"1-2--3--4-5--6--7"\n\u8f93\u51fa\uff1a[1,2,5,3,4,6,7]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1a"1-2--3---4-5--6---7"\n\u8f93\u51fa\uff1a[1,2,5,3,null,6,null,4,null,7]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1a"1-401--349---90--88"\n\u8f93\u51fa\uff1a[1,401,null,349,88,90]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u539f\u59cb\u6811\u4e2d\u7684\u8282\u70b9\u6570\u4ecb\u4e8e 1 \u548c 1000 \u4e4b\u95f4\u3002
  • \n\t
  • \u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u4ecb\u4e8e 1 \u548c 10 ^ 9 \u4e4b\u95f4\u3002
  • \n
\n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* recoverFromPreorder(string traversal) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode recoverFromPreorder(String traversal) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def recoverFromPreorder(self, traversal):\n \"\"\"\n :type traversal: str\n :rtype: TreeNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def recoverFromPreorder(self, traversal: str) -> TreeNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* recoverFromPreorder(char * traversal){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode RecoverFromPreorder(string traversal) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {string} traversal\n * @return {TreeNode}\n */\nvar recoverFromPreorder = function(traversal) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {String} traversal\n# @return {TreeNode}\ndef recover_from_preorder(traversal)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func recoverFromPreorder(_ traversal: String) -> TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc recoverFromPreorder(traversal string) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def recoverFromPreorder(traversal: String): TreeNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun recoverFromPreorder(traversal: String): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn recover_from_preorder(traversal: String) -> Option>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param String $traversal\n * @return TreeNode\n */\n function recoverFromPreorder($traversal) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction recoverFromPreorder(traversal: string): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (recover-from-preorder traversal)\n (-> string? (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1028](https://leetcode-cn.com/problems/recover-a-tree-from-preorder-traversal)", "[\u4ece\u5148\u5e8f\u904d\u5386\u8fd8\u539f\u4e8c\u53c9\u6811](/solution/1000-1099/1028.Recover%20a%20Tree%20From%20Preorder%20Traversal/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[1028](https://leetcode.com/problems/recover-a-tree-from-preorder-traversal)", "[Recover a Tree From Preorder Traversal](/solution/1000-1099/1028.Recover%20a%20Tree%20From%20Preorder%20Traversal/README_EN.md)", "`Tree`,`Depth-first Search`", "Hard", ""]}, {"question_id": "1092", "frontend_question_id": "1026", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-difference-between-node-and-ancestor", "url_en": "https://leetcode.com/problems/maximum-difference-between-node-and-ancestor", "relative_path_cn": "/solution/1000-1099/1026.Maximum%20Difference%20Between%20Node%20and%20Ancestor/README.md", "relative_path_en": "/solution/1000-1099/1026.Maximum%20Difference%20Between%20Node%20and%20Ancestor/README_EN.md", "title_cn": "\u8282\u70b9\u4e0e\u5176\u7956\u5148\u4e4b\u95f4\u7684\u6700\u5927\u5dee\u503c", "title_en": "Maximum Difference Between Node and Ancestor", "question_title_slug": "maximum-difference-between-node-and-ancestor", "content_en": "

Given the root of a binary tree, find the maximum value V for which there exist different nodes A and B where V = |A.val - B.val| and A is an ancestor of B.

\n\n

A node A is an ancestor of B if either: any child of A is equal to B, or any child of A is an ancestor of B.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: root = [8,3,10,1,6,null,14,null,null,4,7,13]\nOutput: 7\nExplanation: We have various ancestor-node differences, some of which are given below :\n|8 - 3| = 5\n|3 - 7| = 4\n|8 - 1| = 7\n|10 - 13| = 3\nAmong all possible differences, the maximum value of 7 is obtained by |8 - 1| = 7.
\n\n

Example 2:

\n\"\"\n
\nInput: root = [1,null,2,null,0,3]\nOutput: 3\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The number of nodes in the tree is in the range [2, 5000].
  • \n\t
  • 0 <= Node.val <= 105
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9\u00a0root\uff0c\u627e\u51fa\u5b58\u5728\u4e8e \u4e0d\u540c \u8282\u70b9\u00a0A \u548c\u00a0B\u00a0\u4e4b\u95f4\u7684\u6700\u5927\u503c V\uff0c\u5176\u4e2d\u00a0V = |A.val - B.val|\uff0c\u4e14\u00a0A\u00a0\u662f\u00a0B\u00a0\u7684\u7956\u5148\u3002

\n\n

\uff08\u5982\u679c A \u7684\u4efb\u4f55\u5b50\u8282\u70b9\u4e4b\u4e00\u4e3a B\uff0c\u6216\u8005 A \u7684\u4efb\u4f55\u5b50\u8282\u70b9\u662f B \u7684\u7956\u5148\uff0c\u90a3\u4e48\u6211\u4eec\u8ba4\u4e3a A \u662f B \u7684\u7956\u5148\uff09

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1aroot = [8,3,10,1,6,null,14,null,null,4,7,13]\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a \n\u6211\u4eec\u6709\u5927\u91cf\u7684\u8282\u70b9\u4e0e\u5176\u7956\u5148\u7684\u5dee\u503c\uff0c\u5176\u4e2d\u4e00\u4e9b\u5982\u4e0b\uff1a\n|8 - 3| = 5\n|3 - 7| = 4\n|8 - 1| = 7\n|10 - 13| = 3\n\u5728\u6240\u6709\u53ef\u80fd\u7684\u5dee\u503c\u4e2d\uff0c\u6700\u5927\u503c 7 \u7531 |8 - 1| = 7 \u5f97\u51fa\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1aroot = [1,null,2,null,0,3]\n\u8f93\u51fa\uff1a3\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u6811\u4e2d\u7684\u8282\u70b9\u6570\u5728\u00a02\u00a0\u5230\u00a05000\u00a0\u4e4b\u95f4\u3002
  • \n\t
  • 0 <= Node.val <= 105
  • \n
\n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int maxAncestorDiff(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int maxAncestorDiff(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def maxAncestorDiff(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def maxAncestorDiff(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint maxAncestorDiff(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int MaxAncestorDiff(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar maxAncestorDiff = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef max_ancestor_diff(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func maxAncestorDiff(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc maxAncestorDiff(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def maxAncestorDiff(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun maxAncestorDiff(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn max_ancestor_diff(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function maxAncestorDiff($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction maxAncestorDiff(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (max-ancestor-diff root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1026](https://leetcode-cn.com/problems/maximum-difference-between-node-and-ancestor)", "[\u8282\u70b9\u4e0e\u5176\u7956\u5148\u4e4b\u95f4\u7684\u6700\u5927\u5dee\u503c](/solution/1000-1099/1026.Maximum%20Difference%20Between%20Node%20and%20Ancestor/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1026](https://leetcode.com/problems/maximum-difference-between-node-and-ancestor)", "[Maximum Difference Between Node and Ancestor](/solution/1000-1099/1026.Maximum%20Difference%20Between%20Node%20and%20Ancestor/README_EN.md)", "`Tree`,`Depth-first Search`", "Medium", ""]}, {"question_id": "1091", "frontend_question_id": "1120", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/maximum-average-subtree", "url_en": "https://leetcode.com/problems/maximum-average-subtree", "relative_path_cn": "/solution/1100-1199/1120.Maximum%20Average%20Subtree/README.md", "relative_path_en": "/solution/1100-1199/1120.Maximum%20Average%20Subtree/README_EN.md", "title_cn": "\u5b50\u6811\u7684\u6700\u5927\u5e73\u5747\u503c", "title_en": "Maximum Average Subtree", "question_title_slug": "maximum-average-subtree", "content_en": "

Given the root of a binary tree, find the maximum average value of any subtree of that tree.

\n\n

(A subtree of a tree is any node of that tree plus all its descendants. The average value of a tree is the sum of its values, divided by the number of nodes.)

\n\n

 

\n\n

Example 1:

\n\n

\"\"

\n\n
\nInput: [5,6,1]\nOutput: 6.00000\nExplanation: \nFor the node with value = 5 we have an average of (5 + 6 + 1) / 3 = 4.\nFor the node with value = 6 we have an average of 6 / 1 = 6.\nFor the node with value = 1 we have an average of 1 / 1 = 1.\nSo the answer is 6 which is the maximum.\n
\n\n

 

\n\n

Note:

\n\n
    \n\t
  1. The number of nodes in the tree is between 1 and 5000.
  2. \n\t
  3. Each node will have a value between 0 and 100000.
  4. \n\t
  5. Answers will be accepted as correct if they are within 10^-5 of the correct answer.
  6. \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u68f5\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9 root\uff0c\u627e\u51fa\u8fd9\u68f5\u6811\u7684 \u6bcf\u4e00\u68f5 \u5b50\u6811\u7684 \u5e73\u5747\u503c \u4e2d\u7684 \u6700\u5927 \u503c\u3002

\n\n

\u5b50\u6811\u662f\u6811\u4e2d\u7684\u4efb\u610f\u8282\u70b9\u548c\u5b83\u7684\u6240\u6709\u540e\u4ee3\u6784\u6210\u7684\u96c6\u5408\u3002

\n\n

\u6811\u7684\u5e73\u5747\u503c\u662f\u6811\u4e2d\u8282\u70b9\u503c\u7684\u603b\u548c\u9664\u4ee5\u8282\u70b9\u6570\u3002

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1a[5,6,1]\n\u8f93\u51fa\uff1a6.00000\n\u89e3\u91ca\uff1a \n\u4ee5 value = 5 \u7684\u8282\u70b9\u4f5c\u4e3a\u5b50\u6811\u7684\u6839\u8282\u70b9\uff0c\u5f97\u5230\u7684\u5e73\u5747\u503c\u4e3a (5 + 6 + 1) / 3 = 4\u3002\n\u4ee5 value = 6 \u7684\u8282\u70b9\u4f5c\u4e3a\u5b50\u6811\u7684\u6839\u8282\u70b9\uff0c\u5f97\u5230\u7684\u5e73\u5747\u503c\u4e3a 6 / 1 = 6\u3002\n\u4ee5 value = 1 \u7684\u8282\u70b9\u4f5c\u4e3a\u5b50\u6811\u7684\u6839\u8282\u70b9\uff0c\u5f97\u5230\u7684\u5e73\u5747\u503c\u4e3a 1 / 1 = 1\u3002\n\u6240\u4ee5\u7b54\u6848\u53d6\u6700\u5927\u503c 6\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. \u6811\u4e2d\u7684\u8282\u70b9\u6570\u4ecb\u4e8e 1 \u5230 5000\u4e4b\u95f4\u3002
  2. \n\t
  3. \u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u4ecb\u4e8e 0 \u5230 100000 \u4e4b\u95f4\u3002
  4. \n\t
  5. \u5982\u679c\u7ed3\u679c\u4e0e\u6807\u51c6\u7b54\u6848\u7684\u8bef\u5dee\u4e0d\u8d85\u8fc7 10^-5\uff0c\u90a3\u4e48\u8be5\u7ed3\u679c\u5c06\u88ab\u89c6\u4e3a\u6b63\u786e\u7b54\u6848\u3002
  6. \n
\n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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 */\nclass Solution {\npublic:\n double maximumAverageSubtree(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode(int x) { val = x; }\n * }\n */\nclass Solution {\n public double maximumAverageSubtree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution(object):\n def maximumAverageSubtree(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: float\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution:\n def maximumAverageSubtree(self, root: TreeNode) -> float:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\ndouble maximumAverageSubtree(struct TreeNode* root){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int x) { val = x; }\n * }\n */\npublic class Solution {\n public double MaximumAverageSubtree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val) {\n * this.val = val;\n * this.left = this.right = null;\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar maximumAverageSubtree = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val)\n# @val = val\n# @left, @right = nil, nil\n# end\n# end\n\n# @param {TreeNode} root\n# @return {Float}\ndef maximum_average_subtree(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.left = nil\n * self.right = nil\n * }\n * }\n */\nclass Solution {\n func maximumAverageSubtree(_ root: TreeNode?) -> Double {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc maximumAverageSubtree(root *TreeNode) float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(var _value: Int) {\n * var value: Int = _value\n * var left: TreeNode = null\n * var right: TreeNode = null\n * }\n */\nobject Solution {\n def maximumAverageSubtree(root: TreeNode): Double = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun maximumAverageSubtree(root: TreeNode?): Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n// \n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn maximum_average_subtree(root: Option>>) -> f64 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($value) { $this->val = $value; }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Float\n */\n function maximumAverageSubtree($root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction maximumAverageSubtree(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (maximum-average-subtree root)\n (-> (or/c tree-node? #f) flonum?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1120](https://leetcode-cn.com/problems/maximum-average-subtree)", "[\u5b50\u6811\u7684\u6700\u5927\u5e73\u5747\u503c](/solution/1100-1199/1120.Maximum%20Average%20Subtree/README.md)", "`\u6811`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1120](https://leetcode.com/problems/maximum-average-subtree)", "[Maximum Average Subtree](/solution/1100-1199/1120.Maximum%20Average%20Subtree/README_EN.md)", "`Tree`", "Medium", "\ud83d\udd12"]}, {"question_id": "1090", "frontend_question_id": "1134", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/armstrong-number", "url_en": "https://leetcode.com/problems/armstrong-number", "relative_path_cn": "/solution/1100-1199/1134.Armstrong%20Number/README.md", "relative_path_en": "/solution/1100-1199/1134.Armstrong%20Number/README_EN.md", "title_cn": "\u963f\u59c6\u65af\u7279\u6717\u6570", "title_en": "Armstrong Number", "question_title_slug": "armstrong-number", "content_en": "

Given an integer n, return true if and only if it is an Armstrong number.

\n\n

The k-digit number n is an Armstrong number if and only if the kth power of each digit sums to n.

\n\n

 

\n

Example 1:

\n\n
\nInput: n = 153\nOutput: true\nExplanation: 153 is a 3-digit number, and 153 = 13 + 53 + 33.\n
\n\n

Example 2:

\n\n
\nInput: n = 123\nOutput: false\nExplanation: 123 is a 3-digit number, and 123 != 13 + 23 + 33 = 36.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 108
  • \n
\n", "content_cn": "

\u5047\u8bbe\u5b58\u5728\u4e00\u4e2a k \u4f4d\u6570 N\uff0c\u5176\u6bcf\u4e00\u4f4d\u4e0a\u7684\u6570\u5b57\u7684 k \u6b21\u5e42\u7684\u603b\u548c\u4e5f\u662f N\uff0c\u90a3\u4e48\u8fd9\u4e2a\u6570\u662f\u963f\u59c6\u65af\u7279\u6717\u6570\u3002

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u6b63\u6574\u6570 N\uff0c\u8ba9\u4f60\u6765\u5224\u5b9a\u4ed6\u662f\u5426\u662f\u963f\u59c6\u65af\u7279\u6717\u6570\uff0c\u662f\u5219\u8fd4\u56de true\uff0c\u4e0d\u662f\u5219\u8fd4\u56de false\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a153\n\u8f93\u51fa\uff1atrue\n\u793a\u4f8b\uff1a \n153 \u662f\u4e00\u4e2a 3 \u4f4d\u6570\uff0c\u4e14 153 = 1^3 + 5^3 + 3^3\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a123\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a \n123 \u662f\u4e00\u4e2a 3 \u4f4d\u6570\uff0c\u4e14 123 != 1^3 + 2^3 + 3^3 = 36\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= N <= 10^8
  2. \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isArmstrong(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isArmstrong(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isArmstrong(self, n):\n \"\"\"\n :type n: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isArmstrong(self, n: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isArmstrong(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsArmstrong(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {boolean}\n */\nvar isArmstrong = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Boolean}\ndef is_armstrong(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isArmstrong(_ n: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isArmstrong(n int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isArmstrong(n: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isArmstrong(n: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_armstrong(n: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Boolean\n */\n function isArmstrong($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isArmstrong(n: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-armstrong n)\n (-> exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1134](https://leetcode-cn.com/problems/armstrong-number)", "[\u963f\u59c6\u65af\u7279\u6717\u6570](/solution/1100-1199/1134.Armstrong%20Number/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1134](https://leetcode.com/problems/armstrong-number)", "[Armstrong Number](/solution/1100-1199/1134.Armstrong%20Number/README_EN.md)", "`Math`", "Easy", "\ud83d\udd12"]}, {"question_id": "1089", "frontend_question_id": "1119", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/remove-vowels-from-a-string", "url_en": "https://leetcode.com/problems/remove-vowels-from-a-string", "relative_path_cn": "/solution/1100-1199/1119.Remove%20Vowels%20from%20a%20String/README.md", "relative_path_en": "/solution/1100-1199/1119.Remove%20Vowels%20from%20a%20String/README_EN.md", "title_cn": "\u5220\u53bb\u5b57\u7b26\u4e32\u4e2d\u7684\u5143\u97f3", "title_en": "Remove Vowels from a String", "question_title_slug": "remove-vowels-from-a-string", "content_en": "

Given a string s, remove the vowels 'a', 'e', 'i', 'o', and 'u' from it, and return the new string.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "leetcodeisacommunityforcoders"\nOutput: "ltcdscmmntyfrcdrs"\n
\n\n

Example 2:

\n\n
\nInput: s = "aeiou"\nOutput: ""\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 1000
  • \n\t
  • s consists of only lowercase English letters.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 S\uff0c\u8bf7\u4f60\u5220\u53bb\u5176\u4e2d\u7684\u6240\u6709\u5143\u97f3\u5b57\u6bcd\uff08 'a'\uff0c'e'\uff0c'i'\uff0c'o'\uff0c'u'\uff09\uff0c\u5e76\u8fd4\u56de\u8fd9\u4e2a\u65b0\u5b57\u7b26\u4e32\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a"leetcodeisacommunityforcoders"\n\u8f93\u51fa\uff1a"ltcdscmmntyfrcdrs"\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a"aeiou"\n\u8f93\u51fa\uff1a""\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. S \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\u3002
  2. \n\t
  3. 1 <= S.length <= 1000
  4. \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string removeVowels(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String removeVowels(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def removeVowels(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def removeVowels(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * removeVowels(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string RemoveVowels(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar removeVowels = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef remove_vowels(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func removeVowels(_ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func removeVowels(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def removeVowels(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun removeVowels(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn remove_vowels(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function removeVowels($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function removeVowels(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (remove-vowels s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1119](https://leetcode-cn.com/problems/remove-vowels-from-a-string)", "[\u5220\u53bb\u5b57\u7b26\u4e32\u4e2d\u7684\u5143\u97f3](/solution/1100-1199/1119.Remove%20Vowels%20from%20a%20String/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1119](https://leetcode.com/problems/remove-vowels-from-a-string)", "[Remove Vowels from a String](/solution/1100-1199/1119.Remove%20Vowels%20from%20a%20String/README_EN.md)", "`String`", "Easy", "\ud83d\udd12"]}, {"question_id": "1088", "frontend_question_id": "1118", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/number-of-days-in-a-month", "url_en": "https://leetcode.com/problems/number-of-days-in-a-month", "relative_path_cn": "/solution/1100-1199/1118.Number%20of%20Days%20in%20a%20Month/README.md", "relative_path_en": "/solution/1100-1199/1118.Number%20of%20Days%20in%20a%20Month/README_EN.md", "title_cn": "\u4e00\u6708\u6709\u591a\u5c11\u5929", "title_en": "Number of Days in a Month", "question_title_slug": "number-of-days-in-a-month", "content_en": "

Given a year Y and a month M, return how many days there are in that month.

\r\n\r\n

 

\r\n\r\n

Example 1:

\r\n\r\n
\r\nInput: Y = 1992, M = 7\r\nOutput: 31\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: Y = 2000, M = 2\r\nOutput: 29\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: Y = 1900, M = 2\r\nOutput: 28\r\n
\r\n\r\n

 

\r\n\r\n

Note:

\r\n\r\n
    \r\n\t
  1. 1583 <= Y <= 2100
  2. \r\n\t
  3. 1 <= M <= 12
  4. \r\n
\r\n", "content_cn": "

\u6307\u5b9a\u5e74\u4efd Y \u548c\u6708\u4efd M\uff0c\u8bf7\u4f60\u5e2e\u5fd9\u8ba1\u7b97\u51fa\u8be5\u6708\u4e00\u5171\u6709\u591a\u5c11\u5929\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aY = 1992, M = 7\n\u8f93\u51fa\uff1a31\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aY = 2000, M = 2\n\u8f93\u51fa\uff1a29\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aY = 1900, M = 2\n\u8f93\u51fa\uff1a28\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1583 <= Y <= 2100
  2. \n\t
  3. 1 <= M <= 12
  4. \n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numberOfDays(int Y, int M) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numberOfDays(int Y, int M) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numberOfDays(self, Y, M):\n \"\"\"\n :type Y: int\n :type M: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numberOfDays(self, Y: int, M: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numberOfDays(int Y, int M){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumberOfDays(int Y, int M) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} Y\n * @param {number} M\n * @return {number}\n */\nvar numberOfDays = function(Y, M) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} y\n# @param {Integer} m\n# @return {Integer}\ndef number_of_days(y, m)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numberOfDays(_ Y: Int, _ M: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numberOfDays(Y int, M int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numberOfDays(Y: Int, M: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numberOfDays(Y: Int, M: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn number_of_days(y: i32, m: i32) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $Y\n * @param Integer $M\n * @return Integer\n */\n function numberOfDays($Y, $M) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numberOfDays(Y: number, M: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (number-of-days Y M)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1118](https://leetcode-cn.com/problems/number-of-days-in-a-month)", "[\u4e00\u6708\u6709\u591a\u5c11\u5929](/solution/1100-1199/1118.Number%20of%20Days%20in%20a%20Month/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1118](https://leetcode.com/problems/number-of-days-in-a-month)", "[Number of Days in a Month](/solution/1100-1199/1118.Number%20of%20Days%20in%20a%20Month/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1087", "frontend_question_id": "1027", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-arithmetic-subsequence", "url_en": "https://leetcode.com/problems/longest-arithmetic-subsequence", "relative_path_cn": "/solution/1000-1099/1027.Longest%20Arithmetic%20Subsequence/README.md", "relative_path_en": "/solution/1000-1099/1027.Longest%20Arithmetic%20Subsequence/README_EN.md", "title_cn": "\u6700\u957f\u7b49\u5dee\u6570\u5217", "title_en": "Longest Arithmetic Subsequence", "question_title_slug": "longest-arithmetic-subsequence", "content_en": "

Given an array nums of integers, return the length of the longest arithmetic subsequence in nums.

\n\n

Recall that a subsequence of an array nums is a list nums[i1], nums[i2], ..., nums[ik] with 0 <= i1 < i2 < ... < ik <= nums.length - 1, and that a sequence seq is arithmetic if seq[i+1] - seq[i] are all the same value (for 0 <= i < seq.length - 1).

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [3,6,9,12]\nOutput: 4\nExplanation: \nThe whole array is an arithmetic sequence with steps of length = 3.\n
\n\n

Example 2:

\n\n
\nInput: nums = [9,4,7,2,10]\nOutput: 3\nExplanation: \nThe longest arithmetic subsequence is [4,7,10].\n
\n\n

Example 3:

\n\n
\nInput: nums = [20,1,15,3,10,5,8]\nOutput: 4\nExplanation: \nThe longest arithmetic subsequence is [20,15,10,5].\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= nums.length <= 1000
  • \n\t
  • 0 <= nums[i] <= 500
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 A\uff0c\u8fd4\u56de A \u4e2d\u6700\u957f\u7b49\u5dee\u5b50\u5e8f\u5217\u7684\u957f\u5ea6\u3002

\n\n

\u56de\u60f3\u4e00\u4e0b\uff0cA \u7684\u5b50\u5e8f\u5217\u662f\u5217\u8868 A[i_1], A[i_2], ..., A[i_k] \u5176\u4e2d 0 <= i_1 < i_2 < ... < i_k <= A.length - 1\u3002\u5e76\u4e14\u5982\u679c B[i+1] - B[i]0 <= i < B.length - 1) \u7684\u503c\u90fd\u76f8\u540c\uff0c\u90a3\u4e48\u5e8f\u5217 B \u662f\u7b49\u5dee\u7684\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a[3,6,9,12]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a \n\u6574\u4e2a\u6570\u7ec4\u662f\u516c\u5dee\u4e3a 3 \u7684\u7b49\u5dee\u6570\u5217\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a[9,4,7,2,10]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\n\u6700\u957f\u7684\u7b49\u5dee\u5b50\u5e8f\u5217\u662f [4,7,10]\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1a[20,1,15,3,10,5,8]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\n\u6700\u957f\u7684\u7b49\u5dee\u5b50\u5e8f\u5217\u662f [20,15,10,5]\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 2 <= A.length <= 2000
  2. \n\t
  3. 0 <= A[i] <= 10000
  4. \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int longestArithSeqLength(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int longestArithSeqLength(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestArithSeqLength(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestArithSeqLength(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint longestArithSeqLength(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LongestArithSeqLength(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar longestArithSeqLength = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef longest_arith_seq_length(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestArithSeqLength(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestArithSeqLength(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestArithSeqLength(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestArithSeqLength(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_arith_seq_length(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function longestArithSeqLength($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestArithSeqLength(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-arith-seq-length nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1027](https://leetcode-cn.com/problems/longest-arithmetic-subsequence)", "[\u6700\u957f\u7b49\u5dee\u6570\u5217](/solution/1000-1099/1027.Longest%20Arithmetic%20Subsequence/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1027](https://leetcode.com/problems/longest-arithmetic-subsequence)", "[Longest Arithmetic Subsequence](/solution/1000-1099/1027.Longest%20Arithmetic%20Subsequence/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "1086", "frontend_question_id": "1025", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/divisor-game", "url_en": "https://leetcode.com/problems/divisor-game", "relative_path_cn": "/solution/1000-1099/1025.Divisor%20Game/README.md", "relative_path_en": "/solution/1000-1099/1025.Divisor%20Game/README_EN.md", "title_cn": "\u9664\u6570\u535a\u5f08", "title_en": "Divisor Game", "question_title_slug": "divisor-game", "content_en": "

Alice and Bob take turns playing a game, with Alice starting first.

\n\n

Initially, there is a number n on the chalkboard. On each player's turn, that player makes a move consisting of:

\n\n
    \n\t
  • Choosing any x with 0 < x < n and n % x == 0.
  • \n\t
  • Replacing the number n on the chalkboard with n - x.
  • \n
\n\n

Also, if a player cannot make a move, they lose the game.

\n\n

Return true if and only if Alice wins the game, assuming both players play optimally.

\n\n

 

\n

Example 1:

\n\n
\nInput: n = 2\nOutput: true\nExplanation: Alice chooses 1, and Bob has no more moves.\n
\n\n

Example 2:

\n\n
\nInput: n = 3\nOutput: false\nExplanation: Alice chooses 1, Bob chooses 1, and Alice has no more moves.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 1000
  • \n
\n", "content_cn": "

\u7231\u4e3d\u4e1d\u548c\u9c8d\u52c3\u4e00\u8d77\u73a9\u6e38\u620f\uff0c\u4ed6\u4eec\u8f6e\u6d41\u884c\u52a8\u3002\u7231\u4e3d\u4e1d\u5148\u624b\u5f00\u5c40\u3002

\n\n

\u6700\u521d\uff0c\u9ed1\u677f\u4e0a\u6709\u4e00\u4e2a\u6570\u5b57 N \u3002\u5728\u6bcf\u4e2a\u73a9\u5bb6\u7684\u56de\u5408\uff0c\u73a9\u5bb6\u9700\u8981\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\uff1a

\n\n
    \n\t
  • \u9009\u51fa\u4efb\u4e00 x\uff0c\u6ee1\u8db3 0 < x < N \u4e14 N % x == 0 \u3002
  • \n\t
  • \u7528 N - x \u66ff\u6362\u9ed1\u677f\u4e0a\u7684\u6570\u5b57 N \u3002
  • \n
\n\n

\u5982\u679c\u73a9\u5bb6\u65e0\u6cd5\u6267\u884c\u8fd9\u4e9b\u64cd\u4f5c\uff0c\u5c31\u4f1a\u8f93\u6389\u6e38\u620f\u3002

\n\n

\u53ea\u6709\u5728\u7231\u4e3d\u4e1d\u5728\u6e38\u620f\u4e2d\u53d6\u5f97\u80dc\u5229\u65f6\u624d\u8fd4\u56de True\uff0c\u5426\u5219\u8fd4\u56de False\u3002\u5047\u8bbe\u4e24\u4e2a\u73a9\u5bb6\u90fd\u4ee5\u6700\u4f73\u72b6\u6001\u53c2\u4e0e\u6e38\u620f\u3002

\n\n

 

\n\n
    \n
\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a2\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u7231\u4e3d\u4e1d\u9009\u62e9 1\uff0c\u9c8d\u52c3\u65e0\u6cd5\u8fdb\u884c\u64cd\u4f5c\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a3\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u7231\u4e3d\u4e1d\u9009\u62e9 1\uff0c\u9c8d\u52c3\u4e5f\u9009\u62e9 1\uff0c\u7136\u540e\u7231\u4e3d\u4e1d\u65e0\u6cd5\u8fdb\u884c\u64cd\u4f5c\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= N <= 1000
  2. \n
\n", "tags_en": ["Math", "Dynamic Programming"], "tags_cn": ["\u6570\u5b66", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool divisorGame(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean divisorGame(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def divisorGame(self, n):\n \"\"\"\n :type n: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def divisorGame(self, n: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool divisorGame(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool DivisorGame(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {boolean}\n */\nvar divisorGame = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Boolean}\ndef divisor_game(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func divisorGame(_ n: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func divisorGame(n int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def divisorGame(n: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun divisorGame(n: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn divisor_game(n: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Boolean\n */\n function divisorGame($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function divisorGame(n: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (divisor-game n)\n (-> exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1025](https://leetcode-cn.com/problems/divisor-game)", "[\u9664\u6570\u535a\u5f08](/solution/1000-1099/1025.Divisor%20Game/README.md)", "`\u6570\u5b66`,`\u52a8\u6001\u89c4\u5212`", "\u7b80\u5355", ""], "md_table_row_en": ["[1025](https://leetcode.com/problems/divisor-game)", "[Divisor Game](/solution/1000-1099/1025.Divisor%20Game/README_EN.md)", "`Math`,`Dynamic Programming`", "Easy", ""]}, {"question_id": "1085", "frontend_question_id": "1101", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/the-earliest-moment-when-everyone-become-friends", "url_en": "https://leetcode.com/problems/the-earliest-moment-when-everyone-become-friends", "relative_path_cn": "/solution/1100-1199/1101.The%20Earliest%20Moment%20When%20Everyone%20Become%20Friends/README.md", "relative_path_en": "/solution/1100-1199/1101.The%20Earliest%20Moment%20When%20Everyone%20Become%20Friends/README_EN.md", "title_cn": "\u5f7c\u6b64\u719f\u8bc6\u7684\u6700\u65e9\u65f6\u95f4", "title_en": "The Earliest Moment When Everyone Become Friends", "question_title_slug": "the-earliest-moment-when-everyone-become-friends", "content_en": "

In a social group, there are n people, with unique integer ids from 0 to n-1.

\n\n

We have a list of logs, where each logs[i] = [timestamp, id_A, id_B] contains a non-negative integer timestamp, and the ids of two different people.

\n\n

Each log represents the time in which two different people became friends.  Friendship is symmetric: if A is friends with B, then B is friends with A.

\n\n

Let's say that person A is acquainted with person B if A is friends with B, or A is a friend of someone acquainted with B.

\n\n

Return the earliest time for which every person became acquainted with every other person. Return -1 if there is no such earliest time.

\n\n

 

\n\n

Example 1:

\n\n
\nInput: logs = [[20190101,0,1],[20190104,3,4],[20190107,2,3],[20190211,1,5],[20190224,2,4],[20190301,0,3],[20190312,1,2],[20190322,4,5]], n = 6\nOutput: 20190301\nExplanation: \nThe first event occurs at timestamp = 20190101 and after 0 and 1 become friends we have the following friendship groups [0,1], [2], [3], [4], [5].\nThe second event occurs at timestamp = 20190104 and after 3 and 4 become friends we have the following friendship groups [0,1], [2], [3,4], [5].\nThe third event occurs at timestamp = 20190107 and after 2 and 3 become friends we have the following friendship groups [0,1], [2,3,4], [5].\nThe fourth event occurs at timestamp = 20190211 and after 1 and 5 become friends we have the following friendship groups [0,1,5], [2,3,4].\nThe fifth event occurs at timestamp = 20190224 and as 2 and 4 are already friend anything happens.\nThe sixth event occurs at timestamp = 20190301 and after 0 and 3 become friends we have that all become friends.\n
\n\n

 

\n\n

Note:

\n\n
    \n\t
  1. 2 <= n <= 100
  2. \n\t
  3. 1 <= logs.length <= 104
  4. \n\t
  5. 0 <= logs[i][0] <= 109
  6. \n\t
  7. 0 <= logs[i][1], logs[i][2] <= n - 1
  8. \n\t
  9. It's guaranteed that all timestamps in logs[i][0] are different.
  10. \n\t
  11. logs are not necessarily ordered by some criteria.
  12. \n\t
  13. logs[i][1] != logs[i][2]
  14. \n
\n", "content_cn": "

\u5728\u4e00\u4e2a\u793e\u4ea4\u5708\u5b50\u5f53\u4e2d\uff0c\u6709 N \u4e2a\u4eba\u3002\u6bcf\u4e2a\u4eba\u90fd\u6709\u4e00\u4e2a\u4ece 0 \u5230 N-1 \u552f\u4e00\u7684 id \u7f16\u53f7\u3002

\n\n

\u6211\u4eec\u6709\u4e00\u4efd\u65e5\u5fd7\u5217\u8868 logs\uff0c\u5176\u4e2d\u6bcf\u6761\u8bb0\u5f55\u90fd\u5305\u542b\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\u7684\u65f6\u95f4\u6233\uff0c\u4ee5\u53ca\u5206\u5c5e\u4e24\u4e2a\u4eba\u7684\u4e0d\u540c id\uff0clogs[i] = [timestamp, id_A, id_B]\u3002

\n\n

\u6bcf\u6761\u65e5\u5fd7\u6807\u8bc6\u51fa\u4e24\u4e2a\u4eba\u6210\u4e3a\u597d\u53cb\u7684\u65f6\u95f4\uff0c\u53cb\u8c0a\u662f\u76f8\u4e92\u7684\uff1a\u5982\u679c A \u548c B \u662f\u597d\u53cb\uff0c\u90a3\u4e48 B \u548c A \u4e5f\u662f\u597d\u53cb\u3002

\n\n

\u5982\u679c A \u662f B \u7684\u597d\u53cb\uff0c\u6216\u8005 A \u662f B \u7684\u597d\u53cb\u7684\u597d\u53cb\uff0c\u90a3\u4e48\u5c31\u53ef\u4ee5\u8ba4\u4e3a A \u4e5f\u4e0e B \u719f\u8bc6\u3002

\n\n

\u8fd4\u56de\u5708\u5b50\u91cc\u6240\u6709\u4eba\u4e4b\u95f4\u90fd\u719f\u8bc6\u7684\u6700\u65e9\u65f6\u95f4\u3002\u5982\u679c\u627e\u4e0d\u5230\u6700\u65e9\u65f6\u95f4\uff0c\u5c31\u8fd4\u56de -1 \u3002

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1alogs = [[20190101,0,1],[20190104,3,4],[20190107,2,3],[20190211,1,5],[20190224,2,4],[20190301,0,3],[20190312,1,2],[20190322,4,5]], N = 6\n\u8f93\u51fa\uff1a20190301\n\u89e3\u91ca\uff1a\n\u7b2c\u4e00\u6b21\u7ed3\u4ea4\u53d1\u751f\u5728 timestamp = 20190101\uff0c0 \u548c 1 \u6210\u4e3a\u597d\u53cb\uff0c\u793e\u4ea4\u670b\u53cb\u5708\u5982\u4e0b [0,1], [2], [3], [4], [5]\u3002\n\u7b2c\u4e8c\u6b21\u7ed3\u4ea4\u53d1\u751f\u5728 timestamp = 20190104\uff0c3 \u548c 4 \u6210\u4e3a\u597d\u53cb\uff0c\u793e\u4ea4\u670b\u53cb\u5708\u5982\u4e0b [0,1], [2], [3,4], [5].\n\u7b2c\u4e09\u6b21\u7ed3\u4ea4\u53d1\u751f\u5728 timestamp = 20190107\uff0c2 \u548c 3 \u6210\u4e3a\u597d\u53cb\uff0c\u793e\u4ea4\u670b\u53cb\u5708\u5982\u4e0b [0,1], [2,3,4], [5].\n\u7b2c\u56db\u6b21\u7ed3\u4ea4\u53d1\u751f\u5728 timestamp = 20190211\uff0c1 \u548c 5 \u6210\u4e3a\u597d\u53cb\uff0c\u793e\u4ea4\u670b\u53cb\u5708\u5982\u4e0b [0,1,5], [2,3,4].\n\u7b2c\u4e94\u6b21\u7ed3\u4ea4\u53d1\u751f\u5728 timestamp = 20190224\uff0c2 \u548c 4 \u5df2\u7ecf\u662f\u597d\u53cb\u4e86\u3002\n\u7b2c\u516d\u6b21\u7ed3\u4ea4\u53d1\u751f\u5728 timestamp = 20190301\uff0c0 \u548c 3 \u6210\u4e3a\u597d\u53cb\uff0c\u5927\u5bb6\u90fd\u4e92\u76f8\u719f\u8bc6\u4e86\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= N <= 100
  2. \n\t
  3. 1 <= logs.length <= 10^4
  4. \n\t
  5. 0 <= logs[i][0] <= 10^9
  6. \n\t
  7. 0 <= logs[i][1], logs[i][2] <= N - 1
  8. \n\t
  9. \u4fdd\u8bc1 logs[i][0] \u4e2d\u7684\u6240\u6709\u65f6\u95f4\u6233\u90fd\u4e0d\u540c
  10. \n\t
  11. Logs \u4e0d\u4e00\u5b9a\u6309\u67d0\u4e00\u6807\u51c6\u6392\u5e8f
  12. \n\t
  13. logs[i][1] != logs[i][2]
  14. \n
\n", "tags_en": ["Union Find"], "tags_cn": ["\u5e76\u67e5\u96c6"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int earliestAcq(vector>& logs, int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int earliestAcq(int[][] logs, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def earliestAcq(self, logs, n):\n \"\"\"\n :type logs: List[List[int]]\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def earliestAcq(self, logs: List[List[int]], n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint earliestAcq(int** logs, int logsSize, int* logsColSize, int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int EarliestAcq(int[][] logs, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} logs\n * @param {number} n\n * @return {number}\n */\nvar earliestAcq = function(logs, n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} logs\n# @param {Integer} n\n# @return {Integer}\ndef earliest_acq(logs, n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func earliestAcq(_ logs: [[Int]], _ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func earliestAcq(logs [][]int, n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def earliestAcq(logs: Array[Array[Int]], n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun earliestAcq(logs: Array, n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn earliest_acq(logs: Vec>, n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $logs\n * @param Integer $n\n * @return Integer\n */\n function earliestAcq($logs, $n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function earliestAcq(logs: number[][], n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (earliest-acq logs n)\n (-> (listof (listof exact-integer?)) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1101](https://leetcode-cn.com/problems/the-earliest-moment-when-everyone-become-friends)", "[\u5f7c\u6b64\u719f\u8bc6\u7684\u6700\u65e9\u65f6\u95f4](/solution/1100-1199/1101.The%20Earliest%20Moment%20When%20Everyone%20Become%20Friends/README.md)", "`\u5e76\u67e5\u96c6`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1101](https://leetcode.com/problems/the-earliest-moment-when-everyone-become-friends)", "[The Earliest Moment When Everyone Become Friends](/solution/1100-1199/1101.The%20Earliest%20Moment%20When%20Everyone%20Become%20Friends/README_EN.md)", "`Union Find`", "Medium", "\ud83d\udd12"]}, {"question_id": "1084", "frontend_question_id": "1100", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/find-k-length-substrings-with-no-repeated-characters", "url_en": "https://leetcode.com/problems/find-k-length-substrings-with-no-repeated-characters", "relative_path_cn": "/solution/1100-1199/1100.Find%20K-Length%20Substrings%20With%20No%20Repeated%20Characters/README.md", "relative_path_en": "/solution/1100-1199/1100.Find%20K-Length%20Substrings%20With%20No%20Repeated%20Characters/README_EN.md", "title_cn": "\u957f\u5ea6\u4e3a K \u7684\u65e0\u91cd\u590d\u5b57\u7b26\u5b50\u4e32", "title_en": "Find K-Length Substrings With No Repeated Characters", "question_title_slug": "find-k-length-substrings-with-no-repeated-characters", "content_en": "

Given a string s, return the number of substrings of length k with no repeated characters.

\n\n

 

\n\n

Example 1:

\n\n
\nInput: s = "havefunonleetcode", k = 5\nOutput: 6\nExplanation: \nThere are 6 substrings they are : 'havef','avefu','vefun','efuno','etcod','tcode'.\n
\n\n

Example 2:

\n\n
\nInput: s = "home", k = 5\nOutput: 0\nExplanation: \nNotice k can be larger than the length of s. In this case is not possible to find any substring.\n
\n\n

 

\n\n

Note:

\n\n
    \n\t
  1. 1 <= s.length <= 104
  2. \n\t
  3. All characters of s are lowercase English letters.
  4. \n\t
  5. 1 <= k <= 104
  6. \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 S\uff0c\u627e\u51fa\u6240\u6709\u957f\u5ea6\u4e3a K \u4e14\u4e0d\u542b\u91cd\u590d\u5b57\u7b26\u7684\u5b50\u4e32\uff0c\u8bf7\u4f60\u8fd4\u56de\u5168\u90e8\u6ee1\u8db3\u8981\u6c42\u7684\u5b50\u4e32\u7684 \u6570\u76ee\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aS = "havefunonleetcode", K = 5\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\n\u8fd9\u91cc\u6709 6 \u4e2a\u6ee1\u8db3\u9898\u610f\u7684\u5b50\u4e32\uff0c\u5206\u522b\u662f\uff1a'havef','avefu','vefun','efuno','etcod','tcode'\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aS = "home", K = 5\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\n\u6ce8\u610f\uff1aK \u53ef\u80fd\u4f1a\u5927\u4e8e S \u7684\u957f\u5ea6\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u5c31\u65e0\u6cd5\u627e\u5230\u4efb\u4f55\u957f\u5ea6\u4e3a K \u7684\u5b50\u4e32\u3002
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= S.length <= 10^4
  2. \n\t
  3. S \u4e2d\u7684\u6240\u6709\u5b57\u7b26\u5747\u4e3a\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd
  4. \n\t
  5. 1 <= K <= 10^4
  6. \n
\n", "tags_en": ["String", "Sliding Window"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numKLenSubstrNoRepeats(string s, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numKLenSubstrNoRepeats(String s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numKLenSubstrNoRepeats(self, s, k):\n \"\"\"\n :type s: str\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numKLenSubstrNoRepeats(self, s: str, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numKLenSubstrNoRepeats(char * s, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumKLenSubstrNoRepeats(string s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number} k\n * @return {number}\n */\nvar numKLenSubstrNoRepeats = function(s, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer} k\n# @return {Integer}\ndef num_k_len_substr_no_repeats(s, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numKLenSubstrNoRepeats(_ s: String, _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numKLenSubstrNoRepeats(s string, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numKLenSubstrNoRepeats(s: String, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numKLenSubstrNoRepeats(s: String, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_k_len_substr_no_repeats(s: String, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer $k\n * @return Integer\n */\n function numKLenSubstrNoRepeats($s, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numKLenSubstrNoRepeats(s: string, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-k-len-substr-no-repeats s k)\n (-> string? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1100](https://leetcode-cn.com/problems/find-k-length-substrings-with-no-repeated-characters)", "[\u957f\u5ea6\u4e3a K \u7684\u65e0\u91cd\u590d\u5b57\u7b26\u5b50\u4e32](/solution/1100-1199/1100.Find%20K-Length%20Substrings%20With%20No%20Repeated%20Characters/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1100](https://leetcode.com/problems/find-k-length-substrings-with-no-repeated-characters)", "[Find K-Length Substrings With No Repeated Characters](/solution/1100-1199/1100.Find%20K-Length%20Substrings%20With%20No%20Repeated%20Characters/README_EN.md)", "`String`,`Sliding Window`", "Medium", "\ud83d\udd12"]}, {"question_id": "1083", "frontend_question_id": "1099", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/two-sum-less-than-k", "url_en": "https://leetcode.com/problems/two-sum-less-than-k", "relative_path_cn": "/solution/1000-1099/1099.Two%20Sum%20Less%20Than%20K/README.md", "relative_path_en": "/solution/1000-1099/1099.Two%20Sum%20Less%20Than%20K/README_EN.md", "title_cn": "\u5c0f\u4e8e K \u7684\u4e24\u6570\u4e4b\u548c", "title_en": "Two Sum Less Than K", "question_title_slug": "two-sum-less-than-k", "content_en": "

Given an array nums of integers and integer k, return the maximum sum such that there exists i < j with nums[i] + nums[j] = sum and sum < k. If no i, j exist satisfying this equation, return -1.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [34,23,1,24,75,33,54,8], k = 60\nOutput: 58\nExplanation: We can use 34 and 24 to sum 58 which is less than 60.\n
\n\n

Example 2:

\n\n
\nInput: nums = [10,20,30], k = 15\nOutput: -1\nExplanation: In this case it is not possible to get a pair sum less that 15.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 100
  • \n\t
  • 1 <= nums[i] <= 1000
  • \n\t
  • 1 <= k <= 2000
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \u548c\u6574\u6570 k \uff0c\u8fd4\u56de\u6700\u5927\u548c sum \uff0c\u6ee1\u8db3\u5b58\u5728 i < j \u4f7f\u5f97 nums[i] + nums[j] = sum \u4e14 sum < k \u3002\u5982\u679c\u6ca1\u6709\u6ee1\u8db3\u6b64\u7b49\u5f0f\u7684 i,j \u5b58\u5728\uff0c\u5219\u8fd4\u56de -1 \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [34,23,1,24,75,33,54,8], k = 60\n\u8f93\u51fa\uff1a58\n\u89e3\u91ca\uff1a\n34 \u548c 24 \u76f8\u52a0\u5f97\u5230 58\uff0c58 \u5c0f\u4e8e 60\uff0c\u6ee1\u8db3\u9898\u610f\u3002\n
\n\n

\u793a\u4f8b\u00a02\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [10,20,30], k = 15\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\n\u6211\u4eec\u65e0\u6cd5\u627e\u5230\u548c\u5c0f\u4e8e 15 \u7684\u4e24\u4e2a\u5143\u7d20\u3002
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 100
  • \n\t
  • 1 <= nums[i] <= 1000
  • \n\t
  • 1 <= k <= 2000
  • \n
\n", "tags_en": ["Sort", "Array", "Two Pointers"], "tags_cn": ["\u6392\u5e8f", "\u6570\u7ec4", "\u53cc\u6307\u9488"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int twoSumLessThanK(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int twoSumLessThanK(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def twoSumLessThanK(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def twoSumLessThanK(self, nums: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint twoSumLessThanK(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int TwoSumLessThanK(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar twoSumLessThanK = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef two_sum_less_than_k(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func twoSumLessThanK(_ nums: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func twoSumLessThanK(nums []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def twoSumLessThanK(nums: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun twoSumLessThanK(nums: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn two_sum_less_than_k(nums: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer\n */\n function twoSumLessThanK($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function twoSumLessThanK(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (two-sum-less-than-k nums k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1099](https://leetcode-cn.com/problems/two-sum-less-than-k)", "[\u5c0f\u4e8e K \u7684\u4e24\u6570\u4e4b\u548c](/solution/1000-1099/1099.Two%20Sum%20Less%20Than%20K/README.md)", "`\u6392\u5e8f`,`\u6570\u7ec4`,`\u53cc\u6307\u9488`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1099](https://leetcode.com/problems/two-sum-less-than-k)", "[Two Sum Less Than K](/solution/1000-1099/1099.Two%20Sum%20Less%20Than%20K/README_EN.md)", "`Sort`,`Array`,`Two Pointers`", "Easy", "\ud83d\udd12"]}, {"question_id": "1082", "frontend_question_id": "1085", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/sum-of-digits-in-the-minimum-number", "url_en": "https://leetcode.com/problems/sum-of-digits-in-the-minimum-number", "relative_path_cn": "/solution/1000-1099/1085.Sum%20of%20Digits%20in%20the%20Minimum%20Number/README.md", "relative_path_en": "/solution/1000-1099/1085.Sum%20of%20Digits%20in%20the%20Minimum%20Number/README_EN.md", "title_cn": "\u6700\u5c0f\u5143\u7d20\u5404\u6570\u4f4d\u4e4b\u548c", "title_en": "Sum of Digits in the Minimum Number", "question_title_slug": "sum-of-digits-in-the-minimum-number", "content_en": "

Given an array nums of positive integers, let minDigitSum be the sum of the digits of the minimal element of nums.

\n\n

Return 0 if minDigitSum is odd, otherwise return 1.

\n\n

 

\n\n

Example 1:

\n\n
\nInput: nums = [34,23,1,24,75,33,54,8]\nOutput: 0\nExplanation: \nThe minimal element is 1, and the sum of those digits is minDigitSum = 1 which is odd, so the answer is 0.\n
\n\n

Example 2:

\n\n
\nInput: nums = [99,77,33,66,55]\nOutput: 1\nExplanation: \nThe minimal element is 33, and the sum of those digits is minDigitSum = 3 + 3 = 6 which is even, so the answer is 1.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 100
  • \n\t
  • 1 <= nums[i] <= 100
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6b63\u6574\u6570\u7684\u6570\u7ec4\u00a0A\u3002

\n\n

\u7136\u540e\u8ba1\u7b97\u00a0S\uff0c\u4f7f\u5176\u7b49\u4e8e\u6570\u7ec4\u00a0A\u00a0\u5f53\u4e2d\u6700\u5c0f\u7684\u90a3\u4e2a\u5143\u7d20\u5404\u4e2a\u6570\u4f4d\u4e0a\u6570\u5b57\u4e4b\u548c\u3002

\n\n

\u6700\u540e\uff0c\u5047\u5982\u00a0S\u00a0\u6240\u5f97\u8ba1\u7b97\u7ed3\u679c\u662f\u00a0\u5947\u6570 \uff0c\u8fd4\u56de 0 \uff1b\u5426\u5219\u8bf7\u8fd4\u56de 1\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1:

\n\n
\n\u8f93\u5165\uff1a[34,23,1,24,75,33,54,8]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\n\u6700\u5c0f\u5143\u7d20\u4e3a 1 \uff0c\u8be5\u5143\u7d20\u5404\u4e2a\u6570\u4f4d\u4e0a\u7684\u6570\u5b57\u4e4b\u548c S = 1 \uff0c\u662f\u5947\u6570\u6240\u4ee5\u7b54\u6848\u4e3a 0 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1a[99,77,33,66,55]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\n\u6700\u5c0f\u5143\u7d20\u4e3a 33 \uff0c\u8be5\u5143\u7d20\u5404\u4e2a\u6570\u4f4d\u4e0a\u7684\u6570\u5b57\u4e4b\u548c S = 3 + 3 = 6 \uff0c\u662f\u5076\u6570\u6240\u4ee5\u7b54\u6848\u4e3a 1 \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= A.length <= 100
  • \n\t
  • 1 <= A[i] <= 100
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int sumOfDigits(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int sumOfDigits(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def sumOfDigits(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def sumOfDigits(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint sumOfDigits(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SumOfDigits(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar sumOfDigits = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef sum_of_digits(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func sumOfDigits(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func sumOfDigits(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def sumOfDigits(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun sumOfDigits(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sum_of_digits(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function sumOfDigits($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function sumOfDigits(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (sum-of-digits nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1085](https://leetcode-cn.com/problems/sum-of-digits-in-the-minimum-number)", "[\u6700\u5c0f\u5143\u7d20\u5404\u6570\u4f4d\u4e4b\u548c](/solution/1000-1099/1085.Sum%20of%20Digits%20in%20the%20Minimum%20Number/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1085](https://leetcode.com/problems/sum-of-digits-in-the-minimum-number)", "[Sum of Digits in the Minimum Number](/solution/1000-1099/1085.Sum%20of%20Digits%20in%20the%20Minimum%20Number/README_EN.md)", "`Array`", "Easy", "\ud83d\udd12"]}, {"question_id": "1081", "frontend_question_id": "1024", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/video-stitching", "url_en": "https://leetcode.com/problems/video-stitching", "relative_path_cn": "/solution/1000-1099/1024.Video%20Stitching/README.md", "relative_path_en": "/solution/1000-1099/1024.Video%20Stitching/README_EN.md", "title_cn": "\u89c6\u9891\u62fc\u63a5", "title_en": "Video Stitching", "question_title_slug": "video-stitching", "content_en": "

You are given a series of video clips from a sporting event that lasted time seconds. These video clips can be overlapping with each other and have varying lengths.

\n\n

Each video clip is described by an array clips where clips[i] = [starti, endi] indicates that the ith clip started at starti and ended at endi.

\n\n

We can cut these clips into segments freely.

\n\n
    \n\t
  • For example, a clip [0, 7] can be cut into segments [0, 1] + [1, 3] + [3, 7].
  • \n
\n\n

Return the minimum number of clips needed so that we can cut the clips into segments that cover the entire sporting event [0, time]. If the task is impossible, return -1.

\n\n

 

\n

Example 1:

\n\n
\nInput: clips = [[0,2],[4,6],[8,10],[1,9],[1,5],[5,9]], time = 10\nOutput: 3\nExplanation: \nWe take the clips [0,2], [8,10], [1,9]; a total of 3 clips.\nThen, we can reconstruct the sporting event as follows:\nWe cut [1,9] into segments [1,2] + [2,8] + [8,9].\nNow we have segments [0,2] + [2,8] + [8,10] which cover the sporting event [0, 10].\n
\n\n

Example 2:

\n\n
\nInput: clips = [[0,1],[1,2]], time = 5\nOutput: -1\nExplanation: We can't cover [0,5] with only [0,1] and [1,2].\n
\n\n

Example 3:

\n\n
\nInput: clips = [[0,1],[6,8],[0,2],[5,6],[0,4],[0,3],[6,7],[1,3],[4,7],[1,4],[2,5],[2,6],[3,4],[4,5],[5,7],[6,9]], time = 9\nOutput: 3\nExplanation: We can take clips [0,4], [4,7], and [6,9].\n
\n\n

Example 4:

\n\n
\nInput: clips = [[0,4],[2,8]], time = 5\nOutput: 2\nExplanation: Notice you can have extra video after the event ends.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= clips.length <= 100
  • \n\t
  • 0 <= clips[i][0] <= clips[i][1] <= 100
  • \n\t
  • 1 <= time <= 100
  • \n
\n", "content_cn": "

\u4f60\u5c06\u4f1a\u83b7\u5f97\u4e00\u7cfb\u5217\u89c6\u9891\u7247\u6bb5\uff0c\u8fd9\u4e9b\u7247\u6bb5\u6765\u81ea\u4e8e\u4e00\u9879\u6301\u7eed\u65f6\u957f\u4e3a\u00a0T\u00a0\u79d2\u7684\u4f53\u80b2\u8d5b\u4e8b\u3002\u8fd9\u4e9b\u7247\u6bb5\u53ef\u80fd\u6709\u6240\u91cd\u53e0\uff0c\u4e5f\u53ef\u80fd\u957f\u5ea6\u4e0d\u4e00\u3002

\n\n

\u89c6\u9891\u7247\u6bb5\u00a0clips[i]\u00a0\u90fd\u7528\u533a\u95f4\u8fdb\u884c\u8868\u793a\uff1a\u5f00\u59cb\u4e8e\u00a0clips[i][0]\u00a0\u5e76\u4e8e\u00a0clips[i][1]\u00a0\u7ed3\u675f\u3002\u6211\u4eec\u751a\u81f3\u53ef\u4ee5\u5bf9\u8fd9\u4e9b\u7247\u6bb5\u81ea\u7531\u5730\u518d\u526a\u8f91\uff0c\u4f8b\u5982\u7247\u6bb5\u00a0[0, 7]\u00a0\u53ef\u4ee5\u526a\u5207\u6210\u00a0[0, 1] +\u00a0[1, 3] + [3, 7]\u00a0\u4e09\u90e8\u5206\u3002

\n\n

\u6211\u4eec\u9700\u8981\u5c06\u8fd9\u4e9b\u7247\u6bb5\u8fdb\u884c\u518d\u526a\u8f91\uff0c\u5e76\u5c06\u526a\u8f91\u540e\u7684\u5185\u5bb9\u62fc\u63a5\u6210\u8986\u76d6\u6574\u4e2a\u8fd0\u52a8\u8fc7\u7a0b\u7684\u7247\u6bb5\uff08[0, T]\uff09\u3002\u8fd4\u56de\u6240\u9700\u7247\u6bb5\u7684\u6700\u5c0f\u6570\u76ee\uff0c\u5982\u679c\u65e0\u6cd5\u5b8c\u6210\u8be5\u4efb\u52a1\uff0c\u5219\u8fd4\u56de\u00a0-1 \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aclips = [[0,2],[4,6],[8,10],[1,9],[1,5],[5,9]], T = 10\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\n\u6211\u4eec\u9009\u4e2d [0,2], [8,10], [1,9] \u8fd9\u4e09\u4e2a\u7247\u6bb5\u3002\n\u7136\u540e\uff0c\u6309\u4e0b\u9762\u7684\u65b9\u6848\u91cd\u5236\u6bd4\u8d5b\u7247\u6bb5\uff1a\n\u5c06 [1,9] \u518d\u526a\u8f91\u4e3a [1,2] + [2,8] + [8,9] \u3002\n\u73b0\u5728\u6211\u4eec\u624b\u4e0a\u6709 [0,2] + [2,8] + [8,10]\uff0c\u800c\u8fd9\u4e9b\u6db5\u76d6\u4e86\u6574\u573a\u6bd4\u8d5b [0, 10]\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aclips = [[0,1],[1,2]], T = 5\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\n\u6211\u4eec\u65e0\u6cd5\u53ea\u7528 [0,1] \u548c [1,2] \u8986\u76d6 [0,5] \u7684\u6574\u4e2a\u8fc7\u7a0b\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1aclips = [[0,1],[6,8],[0,2],[5,6],[0,4],[0,3],[6,7],[1,3],[4,7],[1,4],[2,5],[2,6],[3,4],[4,5],[5,7],[6,9]], T = 9\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a \n\u6211\u4eec\u9009\u53d6\u7247\u6bb5 [0,4], [4,7] \u548c [6,9] \u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1aclips = [[0,4],[2,8]], T = 5\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n\u6ce8\u610f\uff0c\u4f60\u53ef\u80fd\u5f55\u5236\u8d85\u8fc7\u6bd4\u8d5b\u7ed3\u675f\u65f6\u95f4\u7684\u89c6\u9891\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= clips.length <= 100
  • \n\t
  • 0 <= clips[i][0] <=\u00a0clips[i][1] <= 100
  • \n\t
  • 0 <= T <= 100
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int videoStitching(vector>& clips, int time) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int videoStitching(int[][] clips, int time) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def videoStitching(self, clips, time):\n \"\"\"\n :type clips: List[List[int]]\n :type time: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def videoStitching(self, clips: List[List[int]], time: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint videoStitching(int** clips, int clipsSize, int* clipsColSize, int time){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int VideoStitching(int[][] clips, int time) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} clips\n * @param {number} time\n * @return {number}\n */\nvar videoStitching = function(clips, time) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} clips\n# @param {Integer} time\n# @return {Integer}\ndef video_stitching(clips, time)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func videoStitching(_ clips: [[Int]], _ time: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func videoStitching(clips [][]int, time int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def videoStitching(clips: Array[Array[Int]], time: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun videoStitching(clips: Array, time: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn video_stitching(clips: Vec>, time: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $clips\n * @param Integer $time\n * @return Integer\n */\n function videoStitching($clips, $time) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function videoStitching(clips: number[][], time: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (video-stitching clips time)\n (-> (listof (listof exact-integer?)) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1024](https://leetcode-cn.com/problems/video-stitching)", "[\u89c6\u9891\u62fc\u63a5](/solution/1000-1099/1024.Video%20Stitching/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1024](https://leetcode.com/problems/video-stitching)", "[Video Stitching](/solution/1000-1099/1024.Video%20Stitching/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "1080", "frontend_question_id": "1023", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/camelcase-matching", "url_en": "https://leetcode.com/problems/camelcase-matching", "relative_path_cn": "/solution/1000-1099/1023.Camelcase%20Matching/README.md", "relative_path_en": "/solution/1000-1099/1023.Camelcase%20Matching/README_EN.md", "title_cn": "\u9a7c\u5cf0\u5f0f\u5339\u914d", "title_en": "Camelcase Matching", "question_title_slug": "camelcase-matching", "content_en": "

A query word matches a given pattern if we can insert lowercase letters to the pattern word so that it equals the query. (We may insert each character at any position, and may insert 0 characters.)

\r\n\r\n

Given a list of queries, and a pattern, return an answer list of booleans, where answer[i] is true if and only if queries[i] matches the pattern.

\r\n\r\n

 

\r\n\r\n

Example 1:

\r\n\r\n
\r\nInput: queries = ["FooBar","FooBarTest","FootBall","FrameBuffer","ForceFeedBack"], pattern = "FB"\r\nOutput: [true,false,true,true,false]\r\nExplanation: \r\n"FooBar" can be generated like this "F" + "oo" + "B" + "ar".\r\n"FootBall" can be generated like this "F" + "oot" + "B" + "all".\r\n"FrameBuffer" can be generated like this "F" + "rame" + "B" + "uffer".
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: queries = ["FooBar","FooBarTest","FootBall","FrameBuffer","ForceFeedBack"], pattern = "FoBa"\r\nOutput: [true,false,true,false,false]\r\nExplanation: \r\n"FooBar" can be generated like this "Fo" + "o" + "Ba" + "r".\r\n"FootBall" can be generated like this "Fo" + "ot" + "Ba" + "ll".\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: queries = ["FooBar","FooBarTest","FootBall","FrameBuffer","ForceFeedBack"], pattern = "FoBaT"\r\nOutput: [false,true,false,false,false]\r\nExplanation: \r\n"FooBarTest" can be generated like this "Fo" + "o" + "Ba" + "r" + "T" + "est".\r\n
\r\n\r\n

 

\r\n\r\n

Note:

\r\n\r\n
    \r\n\t
  1. 1 <= queries.length <= 100
  2. \r\n\t
  3. 1 <= queries[i].length <= 100
  4. \r\n\t
  5. 1 <= pattern.length <= 100
  6. \r\n\t
  7. All strings consists only of lower and upper case English letters.
  8. \r\n
\r\n", "content_cn": "

\u5982\u679c\u6211\u4eec\u53ef\u4ee5\u5c06\u5c0f\u5199\u5b57\u6bcd\u63d2\u5165\u6a21\u5f0f\u4e32 pattern \u5f97\u5230\u5f85\u67e5\u8be2\u9879 query\uff0c\u90a3\u4e48\u5f85\u67e5\u8be2\u9879\u4e0e\u7ed9\u5b9a\u6a21\u5f0f\u4e32\u5339\u914d\u3002\uff08\u6211\u4eec\u53ef\u4ee5\u5728\u4efb\u4f55\u4f4d\u7f6e\u63d2\u5165\u6bcf\u4e2a\u5b57\u7b26\uff0c\u4e5f\u53ef\u4ee5\u63d2\u5165 0 \u4e2a\u5b57\u7b26\u3002\uff09

\n\n

\u7ed9\u5b9a\u5f85\u67e5\u8be2\u5217\u8868 queries\uff0c\u548c\u6a21\u5f0f\u4e32 pattern\uff0c\u8fd4\u56de\u7531\u5e03\u5c14\u503c\u7ec4\u6210\u7684\u7b54\u6848\u5217\u8868 answer\u3002\u53ea\u6709\u5728\u5f85\u67e5\u9879 queries[i] \u4e0e\u6a21\u5f0f\u4e32 pattern \u5339\u914d\u65f6\uff0c answer[i] \u624d\u4e3a true\uff0c\u5426\u5219\u4e3a false\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aqueries = ["FooBar","FooBarTest","FootBall","FrameBuffer","ForceFeedBack"], pattern = "FB"\n\u8f93\u51fa\uff1a[true,false,true,true,false]\n\u793a\u4f8b\uff1a\n"FooBar" \u53ef\u4ee5\u8fd9\u6837\u751f\u6210\uff1a"F" + "oo" + "B" + "ar"\u3002\n"FootBall" \u53ef\u4ee5\u8fd9\u6837\u751f\u6210\uff1a"F" + "oot" + "B" + "all".\n"FrameBuffer" \u53ef\u4ee5\u8fd9\u6837\u751f\u6210\uff1a"F" + "rame" + "B" + "uffer".
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aqueries = ["FooBar","FooBarTest","FootBall","FrameBuffer","ForceFeedBack"], pattern = "FoBa"\n\u8f93\u51fa\uff1a[true,false,true,false,false]\n\u89e3\u91ca\uff1a\n"FooBar" \u53ef\u4ee5\u8fd9\u6837\u751f\u6210\uff1a"Fo" + "o" + "Ba" + "r".\n"FootBall" \u53ef\u4ee5\u8fd9\u6837\u751f\u6210\uff1a"Fo" + "ot" + "Ba" + "ll".\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u51fa\uff1aqueries = ["FooBar","FooBarTest","FootBall","FrameBuffer","ForceFeedBack"], pattern = "FoBaT"\n\u8f93\u5165\uff1a[false,true,false,false,false]\n\u89e3\u91ca\uff1a \n"FooBarTest" \u53ef\u4ee5\u8fd9\u6837\u751f\u6210\uff1a"Fo" + "o" + "Ba" + "r" + "T" + "est".\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= queries.length <= 100
  2. \n\t
  3. 1 <= queries[i].length <= 100
  4. \n\t
  5. 1 <= pattern.length <= 100
  6. \n\t
  7. \u6240\u6709\u5b57\u7b26\u4e32\u90fd\u4ec5\u7531\u5927\u5199\u548c\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\u3002
  8. \n
\n", "tags_en": ["Trie", "String"], "tags_cn": ["\u5b57\u5178\u6811", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector camelMatch(vector& queries, string pattern) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List camelMatch(String[] queries, String pattern) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def camelMatch(self, queries, pattern):\n \"\"\"\n :type queries: List[str]\n :type pattern: str\n :rtype: List[bool]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def camelMatch(self, queries: List[str], pattern: str) -> List[bool]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nbool* camelMatch(char ** queries, int queriesSize, char * pattern, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList CamelMatch(string[] queries, string pattern) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} queries\n * @param {string} pattern\n * @return {boolean[]}\n */\nvar camelMatch = function(queries, pattern) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} queries\n# @param {String} pattern\n# @return {Boolean[]}\ndef camel_match(queries, pattern)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func camelMatch(_ queries: [String], _ pattern: String) -> [Bool] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func camelMatch(queries []string, pattern string) []bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def camelMatch(queries: Array[String], pattern: String): Array[Boolean] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun camelMatch(queries: Array, pattern: String): BooleanArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn camel_match(queries: Vec, pattern: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $queries\n * @param String $pattern\n * @return Boolean[]\n */\n function camelMatch($queries, $pattern) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function camelMatch(queries: string[], pattern: string): boolean[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (camel-match queries pattern)\n (-> (listof string?) string? (listof boolean?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1023](https://leetcode-cn.com/problems/camelcase-matching)", "[\u9a7c\u5cf0\u5f0f\u5339\u914d](/solution/1000-1099/1023.Camelcase%20Matching/README.md)", "`\u5b57\u5178\u6811`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1023](https://leetcode.com/problems/camelcase-matching)", "[Camelcase Matching](/solution/1000-1099/1023.Camelcase%20Matching/README_EN.md)", "`Trie`,`String`", "Medium", ""]}, {"question_id": "1079", "frontend_question_id": "1022", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sum-of-root-to-leaf-binary-numbers", "url_en": "https://leetcode.com/problems/sum-of-root-to-leaf-binary-numbers", "relative_path_cn": "/solution/1000-1099/1022.Sum%20of%20Root%20To%20Leaf%20Binary%20Numbers/README.md", "relative_path_en": "/solution/1000-1099/1022.Sum%20of%20Root%20To%20Leaf%20Binary%20Numbers/README_EN.md", "title_cn": "\u4ece\u6839\u5230\u53f6\u7684\u4e8c\u8fdb\u5236\u6570\u4e4b\u548c", "title_en": "Sum of Root To Leaf Binary Numbers", "question_title_slug": "sum-of-root-to-leaf-binary-numbers", "content_en": "

You are given the root of a binary tree where each node has a value 0 or 1.  Each root-to-leaf path represents a binary number starting with the most significant bit.  For example, if the path is 0 -> 1 -> 1 -> 0 -> 1, then this could represent 01101 in binary, which is 13.

\n\n

For all leaves in the tree, consider the numbers represented by the path from the root to that leaf.

\n\n

Return the sum of these numbers. The answer is guaranteed to fit in a 32-bits integer.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: root = [1,0,1,0,1,0,1]\nOutput: 22\nExplanation: (100) + (101) + (110) + (111) = 4 + 5 + 6 + 7 = 22\n
\n\n

Example 2:

\n\n
\nInput: root = [0]\nOutput: 0\n
\n\n

Example 3:

\n\n
\nInput: root = [1]\nOutput: 1\n
\n\n

Example 4:

\n\n
\nInput: root = [1,1]\nOutput: 3\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The number of nodes in the tree is in the range [1, 1000].
  • \n\t
  • Node.val is 0 or 1.
  • \n
\n", "content_cn": "

\u7ed9\u51fa\u4e00\u68f5\u4e8c\u53c9\u6811\uff0c\u5176\u4e0a\u6bcf\u4e2a\u7ed3\u70b9\u7684\u503c\u90fd\u662f\u00a00\u00a0\u6216\u00a01\u00a0\u3002\u6bcf\u4e00\u6761\u4ece\u6839\u5230\u53f6\u7684\u8def\u5f84\u90fd\u4ee3\u8868\u4e00\u4e2a\u4ece\u6700\u9ad8\u6709\u6548\u4f4d\u5f00\u59cb\u7684\u4e8c\u8fdb\u5236\u6570\u3002\u4f8b\u5982\uff0c\u5982\u679c\u8def\u5f84\u4e3a\u00a00 -> 1 -> 1 -> 0 -> 1\uff0c\u90a3\u4e48\u5b83\u8868\u793a\u4e8c\u8fdb\u5236\u6570\u00a001101\uff0c\u4e5f\u5c31\u662f\u00a013\u00a0\u3002

\n\n

\u5bf9\u6811\u4e0a\u7684\u6bcf\u4e00\u7247\u53f6\u5b50\uff0c\u6211\u4eec\u90fd\u8981\u627e\u51fa\u4ece\u6839\u5230\u8be5\u53f6\u5b50\u7684\u8def\u5f84\u6240\u8868\u793a\u7684\u6570\u5b57\u3002

\n\n

\u8fd4\u56de\u8fd9\u4e9b\u6570\u5b57\u4e4b\u548c\u3002\u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u7b54\u6848\u662f\u4e00\u4e2a 32 \u4f4d \u6574\u6570\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1aroot = [1,0,1,0,1,0,1]\n\u8f93\u51fa\uff1a22\n\u89e3\u91ca\uff1a(100) + (101) + (110) + (111) = 4 + 5 + 6 + 7 = 22\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aroot = [0]\n\u8f93\u51fa\uff1a0\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1aroot = [1]\n\u8f93\u51fa\uff1a1\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1aroot = [1,1]\n\u8f93\u51fa\uff1a3\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u6811\u4e2d\u7684\u7ed3\u70b9\u6570\u4ecb\u4e8e 1 \u548c 1000 \u4e4b\u95f4\u3002
  • \n\t
  • Node.val \u4e3a 0 \u6216 1 \u3002
  • \n
\n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int sumRootToLeaf(TreeNode* root) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int sumRootToLeaf(TreeNode root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def sumRootToLeaf(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def sumRootToLeaf(self, root: TreeNode) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint sumRootToLeaf(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int SumRootToLeaf(TreeNode root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar sumRootToLeaf = function(root) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef sum_root_to_leaf(root)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func sumRootToLeaf(_ root: TreeNode?) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc sumRootToLeaf(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def sumRootToLeaf(root: TreeNode): Int = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun sumRootToLeaf(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn sum_root_to_leaf(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function sumRootToLeaf($root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction sumRootToLeaf(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (sum-root-to-leaf root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1022](https://leetcode-cn.com/problems/sum-of-root-to-leaf-binary-numbers)", "[\u4ece\u6839\u5230\u53f6\u7684\u4e8c\u8fdb\u5236\u6570\u4e4b\u548c](/solution/1000-1099/1022.Sum%20of%20Root%20To%20Leaf%20Binary%20Numbers/README.md)", "`\u6811`", "\u7b80\u5355", ""], "md_table_row_en": ["[1022](https://leetcode.com/problems/sum-of-root-to-leaf-binary-numbers)", "[Sum of Root To Leaf Binary Numbers](/solution/1000-1099/1022.Sum%20of%20Root%20To%20Leaf%20Binary%20Numbers/README_EN.md)", "`Tree`", "Easy", ""]}, {"question_id": "1078", "frontend_question_id": "1021", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/remove-outermost-parentheses", "url_en": "https://leetcode.com/problems/remove-outermost-parentheses", "relative_path_cn": "/solution/1000-1099/1021.Remove%20Outermost%20Parentheses/README.md", "relative_path_en": "/solution/1000-1099/1021.Remove%20Outermost%20Parentheses/README_EN.md", "title_cn": "\u5220\u9664\u6700\u5916\u5c42\u7684\u62ec\u53f7", "title_en": "Remove Outermost Parentheses", "question_title_slug": "remove-outermost-parentheses", "content_en": "

A valid parentheses string is either empty (""), "(" + A + ")", or A + B, where A and B are valid parentheses strings, and + represents string concatenation.  For example, "", "()", "(())()", and "(()(()))" are all valid parentheses strings.

\n\n

A valid parentheses string s is primitive if it is nonempty, and there does not exist a way to split it into s = A+B, with A and B nonempty valid parentheses strings.

\n\n

Given a valid parentheses string s, consider its primitive decomposition: s = P_1 + P_2 + ... + P_k, where P_i are primitive valid parentheses strings.

\n\n

Return s after removing the outermost parentheses of every primitive string in the primitive decomposition of S.

\n\n

 

\n\n

Example 1:

\n\n
\nInput: s = "(()())(())"\nOutput: "()()()"\nExplanation: \nThe input string is "(()())(())", with primitive decomposition "(()())" + "(())".\nAfter removing outer parentheses of each part, this is "()()" + "()" = "()()()".\n
\n\n
\n

Example 2:

\n\n
\nInput: s = "(()())(())(()(()))"\nOutput: "()()()()(())"\nExplanation: \nThe input string is "(()())(())(()(()))", with primitive decomposition "(()())" + "(())" + "(()(()))".\nAfter removing outer parentheses of each part, this is "()()" + "()" + "()(())" = "()()()()(())".\n
\n\n
\n

Example 3:

\n\n
\nInput: s = "()()"\nOutput: ""\nExplanation: \nThe input string is "()()", with primitive decomposition "()" + "()".\nAfter removing outer parentheses of each part, this is "" + "" = "".\n
\n\n

 

\n
\n
\n\n

Note:

\n\n
    \n\t
  1. s.length <= 10000
  2. \n\t
  3. s[i] is "(" or ")"
  4. \n\t
  5. s is a valid parentheses string
  6. \n
\n\n
\n
\n
 
\n
\n
\n", "content_cn": "

\u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32\u4e3a\u7a7a ("")\u3001"(" + A + ")" \u6216 A + B\uff0c\u5176\u4e2d A \u548c B \u90fd\u662f\u6709\u6548\u7684\u62ec\u53f7\u5b57\u7b26\u4e32\uff0c+ \u4ee3\u8868\u5b57\u7b26\u4e32\u7684\u8fde\u63a5\u3002\u4f8b\u5982\uff0c""\uff0c"()"\uff0c"(())()" \u548c "(()(()))" \u90fd\u662f\u6709\u6548\u7684\u62ec\u53f7\u5b57\u7b26\u4e32\u3002

\n\n

\u5982\u679c\u6709\u6548\u5b57\u7b26\u4e32 S \u975e\u7a7a\uff0c\u4e14\u4e0d\u5b58\u5728\u5c06\u5176\u62c6\u5206\u4e3a S = A+B \u7684\u65b9\u6cd5\uff0c\u6211\u4eec\u79f0\u5176\u4e3a\u539f\u8bed\uff08primitive\uff09\uff0c\u5176\u4e2d A \u548c B \u90fd\u662f\u975e\u7a7a\u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32\u3002

\n\n

\u7ed9\u51fa\u4e00\u4e2a\u975e\u7a7a\u6709\u6548\u5b57\u7b26\u4e32 S\uff0c\u8003\u8651\u5c06\u5176\u8fdb\u884c\u539f\u8bed\u5316\u5206\u89e3\uff0c\u4f7f\u5f97\uff1aS = P_1 + P_2 + ... + P_k\uff0c\u5176\u4e2d P_i \u662f\u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32\u539f\u8bed\u3002

\n\n

\u5bf9 S \u8fdb\u884c\u539f\u8bed\u5316\u5206\u89e3\uff0c\u5220\u9664\u5206\u89e3\u4e2d\u6bcf\u4e2a\u539f\u8bed\u5b57\u7b26\u4e32\u7684\u6700\u5916\u5c42\u62ec\u53f7\uff0c\u8fd4\u56de S \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a"(()())(())"\n\u8f93\u51fa\uff1a"()()()"\n\u89e3\u91ca\uff1a\n\u8f93\u5165\u5b57\u7b26\u4e32\u4e3a "(()())(())"\uff0c\u539f\u8bed\u5316\u5206\u89e3\u5f97\u5230 "(()())" + "(())"\uff0c\n\u5220\u9664\u6bcf\u4e2a\u90e8\u5206\u4e2d\u7684\u6700\u5916\u5c42\u62ec\u53f7\u540e\u5f97\u5230 "()()" + "()" = "()()()"\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a"(()())(())(()(()))"\n\u8f93\u51fa\uff1a"()()()()(())"\n\u89e3\u91ca\uff1a\n\u8f93\u5165\u5b57\u7b26\u4e32\u4e3a "(()())(())(()(()))"\uff0c\u539f\u8bed\u5316\u5206\u89e3\u5f97\u5230 "(()())" + "(())" + "(()(()))"\uff0c\n\u5220\u9664\u6bcf\u4e2a\u90e8\u5206\u4e2d\u7684\u6700\u5916\u5c42\u62ec\u53f7\u540e\u5f97\u5230 "()()" + "()" + "()(())" = "()()()()(())"\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1a"()()"\n\u8f93\u51fa\uff1a""\n\u89e3\u91ca\uff1a\n\u8f93\u5165\u5b57\u7b26\u4e32\u4e3a "()()"\uff0c\u539f\u8bed\u5316\u5206\u89e3\u5f97\u5230 "()" + "()"\uff0c\n\u5220\u9664\u6bcf\u4e2a\u90e8\u5206\u4e2d\u7684\u6700\u5916\u5c42\u62ec\u53f7\u540e\u5f97\u5230 "" + "" = ""\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. S.length <= 10000
  2. \n\t
  3. S[i] \u4e3a "(" \u6216 ")"
  4. \n\t
  5. S \u662f\u4e00\u4e2a\u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32
  6. \n
\n", "tags_en": ["Stack"], "tags_cn": ["\u6808"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string removeOuterParentheses(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String removeOuterParentheses(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def removeOuterParentheses(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def removeOuterParentheses(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * removeOuterParentheses(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string RemoveOuterParentheses(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar removeOuterParentheses = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef remove_outer_parentheses(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func removeOuterParentheses(_ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func removeOuterParentheses(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def removeOuterParentheses(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun removeOuterParentheses(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn remove_outer_parentheses(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function removeOuterParentheses($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function removeOuterParentheses(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (remove-outer-parentheses s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1021](https://leetcode-cn.com/problems/remove-outermost-parentheses)", "[\u5220\u9664\u6700\u5916\u5c42\u7684\u62ec\u53f7](/solution/1000-1099/1021.Remove%20Outermost%20Parentheses/README.md)", "`\u6808`", "\u7b80\u5355", ""], "md_table_row_en": ["[1021](https://leetcode.com/problems/remove-outermost-parentheses)", "[Remove Outermost Parentheses](/solution/1000-1099/1021.Remove%20Outermost%20Parentheses/README_EN.md)", "`Stack`", "Easy", ""]}, {"question_id": "1077", "frontend_question_id": "1088", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/confusing-number-ii", "url_en": "https://leetcode.com/problems/confusing-number-ii", "relative_path_cn": "/solution/1000-1099/1088.Confusing%20Number%20II/README.md", "relative_path_en": "/solution/1000-1099/1088.Confusing%20Number%20II/README_EN.md", "title_cn": "\u6613\u6df7\u6dc6\u6570 II", "title_en": "Confusing Number II", "question_title_slug": "confusing-number-ii", "content_en": "

We can rotate digits by 180 degrees to form new digits. When 0, 1, 6, 8, 9 are rotated 180 degrees, they become 0, 1, 9, 8, 6 respectively. When 2, 3, 4, 5 and 7 are rotated 180 degrees, they become invalid.

\n\n

A confusing number is a number that when rotated 180 degrees becomes a different number with each digit valid.(Note that the rotated number can be greater than the original number.)

\n\n

Given a positive integer n, return the number of confusing numbers between 1 and n inclusive.

\n\n

 

\n\n

Example 1:

\n\n
\nInput: n = 20\nOutput: 6\nExplanation: \nThe confusing numbers are [6,9,10,16,18,19].\n6 converts to 9.\n9 converts to 6.\n10 converts to 01 which is just 1.\n16 converts to 91.\n18 converts to 81.\n19 converts to 61.\n
\n\n

Example 2:

\n\n
\nInput: n = 100\nOutput: 19\nExplanation: \nThe confusing numbers are [6,9,10,16,18,19,60,61,66,68,80,81,86,89,90,91,98,99,100].\n
\n\n

 

\n\n

Note:

\n\n
    \n\t
  1. 1 <= n <= 109
  2. \n
\n", "content_cn": "

\u672c\u9898\u6211\u4eec\u4f1a\u5c06\u6570\u5b57\u65cb\u8f6c 180° \u6765\u751f\u6210\u4e00\u4e2a\u65b0\u7684\u6570\u5b57\u3002

\n\n

\u6bd4\u5982 0\u30011\u30016\u30018\u30019 \u65cb\u8f6c 180° \u4ee5\u540e\uff0c\u6211\u4eec\u5f97\u5230\u7684\u65b0\u6570\u5b57\u5206\u522b\u4e3a 0\u30011\u30019\u30018\u30016\u3002

\n\n

2\u30013\u30014\u30015\u30017 \u65cb\u8f6c 180° \u540e\uff0c\u662f \u65e0\u6cd5 \u5f97\u5230\u4efb\u4f55\u6570\u5b57\u7684\u3002

\n\n

\u6613\u6df7\u6dc6\u6570\uff08Confusing Number\uff09\u6307\u7684\u662f\u4e00\u4e2a\u6570\u5b57\u5728\u6574\u4f53\u65cb\u8f6c 180° \u4ee5\u540e\uff0c\u80fd\u591f\u5f97\u5230\u4e00\u4e2a\u548c\u539f\u6765 \u4e0d\u540c \u7684\u6570\uff0c\u4e14\u65b0\u6570\u5b57\u7684\u6bcf\u4e00\u4f4d\u90fd\u5e94\u8be5\u662f\u6709\u6548\u7684\u3002\uff08\u8bf7\u6ce8\u610f\uff0c\u65cb\u8f6c\u540e\u5f97\u5230\u7684\u65b0\u6570\u5b57\u53ef\u80fd\u5927\u4e8e\u539f\u6570\u5b57\uff09

\n\n

\u7ed9\u51fa\u6b63\u6574\u6570 N\uff0c\u8bf7\u4f60\u8fd4\u56de 1 \u5230 N \u4e4b\u95f4\u6613\u6df7\u6dc6\u6570\u5b57\u7684\u6570\u91cf\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a20\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\n\u6613\u6df7\u6dc6\u6570\u4e3a [6,9,10,16,18,19]\u3002\n6 \u8f6c\u6362\u4e3a 9\n9 \u8f6c\u6362\u4e3a 6\n10 \u8f6c\u6362\u4e3a 01 \u4e5f\u5c31\u662f 1\n16 \u8f6c\u6362\u4e3a 91\n18 \u8f6c\u6362\u4e3a 81\n19 \u8f6c\u6362\u4e3a 61\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a100\n\u8f93\u51fa\uff1a19\n\u89e3\u91ca\uff1a\n\u6613\u6df7\u6dc6\u6570\u4e3a [6,9,10,16,18,19,60,61,66,68,80,81,86,89,90,91,98,99,100]\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= N <= 10^9
  2. \n
\n", "tags_en": ["Math", "Backtracking"], "tags_cn": ["\u6570\u5b66", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int confusingNumberII(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int confusingNumberII(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def confusingNumberII(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def confusingNumberII(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint confusingNumberII(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ConfusingNumberII(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar confusingNumberII = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef confusing_number_ii(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func confusingNumberII(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func confusingNumberII(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def confusingNumberII(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun confusingNumberII(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn confusing_number_ii(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function confusingNumberII($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function confusingNumberII(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (confusing-number-ii n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1088](https://leetcode-cn.com/problems/confusing-number-ii)", "[\u6613\u6df7\u6dc6\u6570 II](/solution/1000-1099/1088.Confusing%20Number%20II/README.md)", "`\u6570\u5b66`,`\u56de\u6eaf\u7b97\u6cd5`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1088](https://leetcode.com/problems/confusing-number-ii)", "[Confusing Number II](/solution/1000-1099/1088.Confusing%20Number%20II/README_EN.md)", "`Math`,`Backtracking`", "Hard", "\ud83d\udd12"]}, {"question_id": "1076", "frontend_question_id": "1087", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/brace-expansion", "url_en": "https://leetcode.com/problems/brace-expansion", "relative_path_cn": "/solution/1000-1099/1087.Brace%20Expansion/README.md", "relative_path_en": "/solution/1000-1099/1087.Brace%20Expansion/README_EN.md", "title_cn": "\u82b1\u62ec\u53f7\u5c55\u5f00", "title_en": "Brace Expansion", "question_title_slug": "brace-expansion", "content_en": "

You are given a string s representing a list of words. Each letter in the word has one or more options.

\n\n
    \n\t
  • If there is one option, the letter is represented as is.
  • \n\t
  • If there is more than one option, then curly braces delimit the options. For example, "{a,b,c}" represents options ["a", "b", "c"].
  • \n
\n\n

For example, if s = "a{b,c}", the first character is always 'a', but the second character can be 'b' or 'c'. The original list is ["ab", "ac"].

\n\n

Return all words that can be formed in this manner, sorted in lexicographical order.

\n\n

 

\n

Example 1:

\n
Input: s = \"{a,b}c{d,e}f\"\nOutput: [\"acdf\",\"acef\",\"bcdf\",\"bcef\"]\n

Example 2:

\n
Input: s = \"abcd\"\nOutput: [\"abcd\"]\n
\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 50
  • \n\t
  • s consists of curly brackets '{}', commas ',', and lowercase English letters.
  • \n\t
  • s is guaranteed to be a valid input.
  • \n\t
  • There are no nested curly brackets.
  • \n\t
  • All characters inside a pair of consecutive opening and ending curly brackets are different.
  • \n
\n", "content_cn": "

\u6211\u4eec\u7528\u4e00\u4e2a\u7279\u6b8a\u7684\u5b57\u7b26\u4e32 S \u6765\u8868\u793a\u4e00\u4efd\u5355\u8bcd\u5217\u8868\uff0c\u4e4b\u6240\u4ee5\u80fd\u5c55\u5f00\u6210\u4e3a\u4e00\u4e2a\u5217\u8868\uff0c\u662f\u56e0\u4e3a\u8fd9\u4e2a\u5b57\u7b26\u4e32 S \u4e2d\u5b58\u5728\u4e00\u4e2a\u53eb\u505a\u300c\u9009\u9879\u300d\u7684\u6982\u5ff5\uff1a

\n\n

\u5355\u8bcd\u4e2d\u7684\u6bcf\u4e2a\u5b57\u6bcd\u53ef\u80fd\u53ea\u6709\u4e00\u4e2a\u9009\u9879\u6216\u5b58\u5728\u591a\u4e2a\u5907\u9009\u9879\u3002\u5982\u679c\u53ea\u6709\u4e00\u4e2a\u9009\u9879\uff0c\u90a3\u4e48\u8be5\u5b57\u6bcd\u6309\u539f\u6837\u8868\u793a\u3002

\n\n

\u5982\u679c\u5b58\u5728\u591a\u4e2a\u9009\u9879\uff0c\u5c31\u4f1a\u4ee5\u82b1\u62ec\u53f7\u5305\u88f9\u6765\u8868\u793a\u8fd9\u4e9b\u9009\u9879\uff08\u4f7f\u5b83\u4eec\u4e0e\u5176\u4ed6\u5b57\u6bcd\u5206\u9694\u5f00\uff09\uff0c\u4f8b\u5982 "{a,b,c}" \u8868\u793a ["a", "b", "c"]\u3002

\n\n

\u4f8b\u5b50\uff1a"{a,b,c}d{e,f}" \u53ef\u4ee5\u8868\u793a\u5355\u8bcd\u5217\u8868 ["ade", "adf", "bde", "bdf", "cde", "cdf"]\u3002

\n\n

\u8bf7\u4f60\u6309\u5b57\u5178\u987a\u5e8f\uff0c\u8fd4\u56de\u6240\u6709\u4ee5\u8fd9\u79cd\u65b9\u5f0f\u5f62\u6210\u7684\u5355\u8bcd\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a"{a,b}c{d,e}f"\n\u8f93\u51fa\uff1a["acdf","acef","bcdf","bcef"]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a"abcd"\n\u8f93\u51fa\uff1a["abcd"]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= S.length <= 50
  2. \n\t
  3. \u4f60\u53ef\u4ee5\u5047\u8bbe\u9898\u76ee\u4e2d\u4e0d\u5b58\u5728\u5d4c\u5957\u7684\u82b1\u62ec\u53f7
  4. \n\t
  5. \u5728\u4e00\u5bf9\u8fde\u7eed\u7684\u82b1\u62ec\u53f7\uff08\u5f00\u82b1\u62ec\u53f7\u4e0e\u95ed\u82b1\u62ec\u53f7\uff09\u4e4b\u95f4\u7684\u6240\u6709\u5b57\u6bcd\u90fd\u4e0d\u4f1a\u76f8\u540c
  6. \n
\n", "tags_en": ["Backtracking"], "tags_cn": ["\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector expand(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String[] expand(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def expand(self, s):\n \"\"\"\n :type s: str\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def expand(self, s: str) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** expand(char * s, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string[] Expand(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string[]}\n */\nvar expand = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String[]}\ndef expand(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func expand(_ s: String) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func expand(s string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def expand(s: String): Array[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun expand(s: String): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn expand(s: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String[]\n */\n function expand($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function expand(s: string): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (expand s)\n (-> string? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1087](https://leetcode-cn.com/problems/brace-expansion)", "[\u82b1\u62ec\u53f7\u5c55\u5f00](/solution/1000-1099/1087.Brace%20Expansion/README.md)", "`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1087](https://leetcode.com/problems/brace-expansion)", "[Brace Expansion](/solution/1000-1099/1087.Brace%20Expansion/README_EN.md)", "`Backtracking`", "Medium", "\ud83d\udd12"]}, {"question_id": "1075", "frontend_question_id": "1065", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/index-pairs-of-a-string", "url_en": "https://leetcode.com/problems/index-pairs-of-a-string", "relative_path_cn": "/solution/1000-1099/1065.Index%20Pairs%20of%20a%20String/README.md", "relative_path_en": "/solution/1000-1099/1065.Index%20Pairs%20of%20a%20String/README_EN.md", "title_cn": "\u5b57\u7b26\u4e32\u7684\u7d22\u5f15\u5bf9", "title_en": "Index Pairs of a String", "question_title_slug": "index-pairs-of-a-string", "content_en": "

Given a text string and words (a list of strings), return all index pairs [i, j] so that the substring text[i]...text[j] is in the list of words.

\r\n\r\n

 

\r\n\r\n

Example 1:

\r\n\r\n
\r\nInput: text = "thestoryofleetcodeandme", words = ["story","fleet","leetcode"]\r\nOutput: [[3,7],[9,13],[10,17]]\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: text = "ababa", words = ["aba","ab"]\r\nOutput: [[0,1],[0,2],[2,3],[2,4]]\r\nExplanation: \r\nNotice that matches can overlap, see "aba" is found in [0,2] and [2,4].\r\n
\r\n\r\n

 

\r\n\r\n

Note:

\r\n\r\n
    \r\n\t
  1. All strings contains only lowercase English letters.
  2. \r\n\t
  3. It's guaranteed that all strings in words are different.
  4. \r\n\t
  5. 1 <= text.length <= 100
  6. \r\n\t
  7. 1 <= words.length <= 20
  8. \r\n\t
  9. 1 <= words[i].length <= 50
  10. \r\n\t
  11. Return the pairs [i,j] in sorted order (i.e. sort them by their first coordinate in case of ties sort them by their second coordinate).
  12. \r\n
", "content_cn": "

\u7ed9\u51fa \u5b57\u7b26\u4e32 text \u548c \u5b57\u7b26\u4e32\u5217\u8868 words, \u8fd4\u56de\u6240\u6709\u7684\u7d22\u5f15\u5bf9 [i, j] \u4f7f\u5f97\u5728\u7d22\u5f15\u5bf9\u8303\u56f4\u5185\u7684\u5b50\u5b57\u7b26\u4e32 text[i]...text[j]\uff08\u5305\u62ec i \u548c j\uff09\u5c5e\u4e8e\u5b57\u7b26\u4e32\u5217\u8868 words\u3002

\n\n

 

\n\n

\u793a\u4f8b 1:

\n\n
\u8f93\u5165: text = "thestoryofleetcodeandme", words = ["story","fleet","leetcode"]\n\u8f93\u51fa: [[3,7],[9,13],[10,17]]\n
\n\n

\u793a\u4f8b 2:

\n\n
\u8f93\u5165: text = "ababa", words = ["aba","ab"]\n\u8f93\u51fa: [[0,1],[0,2],[2,3],[2,4]]\n\u89e3\u91ca: \n\u6ce8\u610f\uff0c\u8fd4\u56de\u7684\u914d\u5bf9\u53ef\u4ee5\u6709\u4ea4\u53c9\uff0c\u6bd4\u5982\uff0c"aba" \u65e2\u5728 [0,2] \u4e2d\u4e5f\u5728 [2,4] \u4e2d\n
\n\n

 

\n\n

\u63d0\u793a:

\n\n
    \n\t
  1. \u6240\u6709\u5b57\u7b26\u4e32\u90fd\u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd\u3002
  2. \n\t
  3. \u4fdd\u8bc1 words \u4e2d\u7684\u5b57\u7b26\u4e32\u65e0\u91cd\u590d\u3002
  4. \n\t
  5. 1 <= text.length <= 100
  6. \n\t
  7. 1 <= words.length <= 20
  8. \n\t
  9. 1 <= words[i].length <= 50
  10. \n\t
  11. \u6309\u5e8f\u8fd4\u56de\u7d22\u5f15\u5bf9 [i,j]\uff08\u5373\uff0c\u6309\u7167\u7d22\u5f15\u5bf9\u7684\u7b2c\u4e00\u4e2a\u7d22\u5f15\u8fdb\u884c\u6392\u5e8f\uff0c\u5f53\u7b2c\u4e00\u4e2a\u7d22\u5f15\u5bf9\u76f8\u540c\u65f6\u6309\u7167\u7b2c\u4e8c\u4e2a\u7d22\u5f15\u5bf9\u6392\u5e8f\uff09\u3002
  12. \n
\n", "tags_en": ["Trie", "String"], "tags_cn": ["\u5b57\u5178\u6811", "\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> indexPairs(string text, vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[][] indexPairs(String text, String[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def indexPairs(self, text, words):\n \"\"\"\n :type text: str\n :type words: List[str]\n :rtype: List[List[int]]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def indexPairs(self, text: str, words: List[str]) -> List[List[int]]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** indexPairs(char * text, char ** words, int wordsSize, int* returnSize, int** returnColumnSizes){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[][] IndexPairs(string text, string[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} text\n * @param {string[]} words\n * @return {number[][]}\n */\nvar indexPairs = function(text, words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} text\n# @param {String[]} words\n# @return {Integer[][]}\ndef index_pairs(text, words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func indexPairs(_ text: String, _ words: [String]) -> [[Int]] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func indexPairs(text string, words []string) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def indexPairs(text: String, words: Array[String]): Array[Array[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun indexPairs(text: String, words: Array): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn index_pairs(text: String, words: Vec) -> Vec> {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $text\n * @param String[] $words\n * @return Integer[][]\n */\n function indexPairs($text, $words) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function indexPairs(text: string, words: string[]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (index-pairs text words)\n (-> string? (listof string?) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1065](https://leetcode-cn.com/problems/index-pairs-of-a-string)", "[\u5b57\u7b26\u4e32\u7684\u7d22\u5f15\u5bf9](/solution/1000-1099/1065.Index%20Pairs%20of%20a%20String/README.md)", "`\u5b57\u5178\u6811`,`\u5b57\u7b26\u4e32`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1065](https://leetcode.com/problems/index-pairs-of-a-string)", "[Index Pairs of a String](/solution/1000-1099/1065.Index%20Pairs%20of%20a%20String/README_EN.md)", "`Trie`,`String`", "Easy", "\ud83d\udd12"]}, {"question_id": "1074", "frontend_question_id": "1086", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/high-five", "url_en": "https://leetcode.com/problems/high-five", "relative_path_cn": "/solution/1000-1099/1086.High%20Five/README.md", "relative_path_en": "/solution/1000-1099/1086.High%20Five/README_EN.md", "title_cn": "\u524d\u4e94\u79d1\u7684\u5747\u5206", "title_en": "High Five", "question_title_slug": "high-five", "content_en": "

Given a list of the scores of different students, items, where items[i] = [IDi, scorei] represents one score from a student with IDi, calculate each student's top five average.

\n\n

Return the answer as an array of pairs result, where result[j] = [IDj, topFiveAveragej] represents the student with IDj and their top five average. Sort result by IDj in increasing order.

\n\n

A student's top five average is calculated by taking the sum of their top five scores and dividing it by 5 using integer division.

\n\n

 

\n

Example 1:

\n\n
\nInput: items = [[1,91],[1,92],[2,93],[2,97],[1,60],[2,77],[1,65],[1,87],[1,100],[2,100],[2,76]]\nOutput: [[1,87],[2,88]]\nExplanation: \nThe student with ID = 1 got scores 91, 92, 60, 65, 87, and 100. Their top five average is (100 + 92 + 91 + 87 + 65) / 5 = 87.\nThe student with ID = 2 got scores 93, 97, 77, 100, and 76. Their top five average is (100 + 97 + 93 + 77 + 76) / 5 = 88.6, but with integer division their average converts to 88.\n
\n\n

Example 2:

\n\n
\nInput: items = [[1,100],[7,100],[1,100],[7,100],[1,100],[7,100],[1,100],[7,100],[1,100],[7,100]]\nOutput: [[1,100],[7,100]]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= items.length <= 1000
  • \n\t
  • items[i].length == 2
  • \n\t
  • 1 <= IDi <= 1000
  • \n\t
  • 0 <= scorei <= 100
  • \n\t
  • For each IDi, there will be at least five scores.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u4e0d\u540c\u5b66\u751f\u7684\u5206\u6570\u5217\u8868 items\uff0c\u5176\u4e2d items[i] = [IDi, scorei] \u8868\u793a IDi \u7684\u5b66\u751f\u7684\u4e00\u79d1\u5206\u6570\uff0c\u4f60\u9700\u8981\u8ba1\u7b97\u6bcf\u4e2a\u5b66\u751f\u00a0\u6700\u9ad8\u7684\u4e94\u79d1\u00a0\u6210\u7ee9\u7684\u00a0\u5e73\u5747\u5206\u3002

\n\n

\u8fd4\u56de\u7b54\u6848\u00a0result \u4ee5\u6570\u5bf9\u6570\u7ec4\u5f62\u5f0f\u7ed9\u51fa\uff0c\u5176\u4e2d result[j] = [IDj, topFiveAveragej] \u8868\u793a IDj \u7684\u5b66\u751f\u548c\u4ed6 \u6700\u9ad8\u7684\u4e94\u79d1\u00a0\u6210\u7ee9\u7684\u00a0\u5e73\u5747\u5206\u3002result \u9700\u8981\u6309 IDj\u00a0 \u9012\u589e\u7684 \u987a\u5e8f\u6392\u5217 \u3002

\n\n

\u5b66\u751f \u6700\u9ad8\u7684\u4e94\u79d1\u00a0\u6210\u7ee9\u7684\u00a0\u5e73\u5747\u5206 \u7684\u8ba1\u7b97\u65b9\u6cd5\u662f\u5c06\u6700\u9ad8\u7684\u4e94\u79d1\u5206\u6570\u76f8\u52a0\uff0c\u7136\u540e\u7528 \u6574\u6570\u9664\u6cd5 \u9664\u4ee5 5 \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aitems = [[1,91],[1,92],[2,93],[2,97],[1,60],[2,77],[1,65],[1,87],[1,100],[2,100],[2,76]]\n\u8f93\u51fa\uff1a[[1,87],[2,88]]\n\u89e3\u91ca\uff1a\nID = 1 \u7684\u5b66\u751f\u5206\u6570\u4e3a 91\u300192\u300160\u300165\u300187 \u548c 100 \u3002\u524d\u4e94\u79d1\u7684\u5e73\u5747\u5206 (100 + 92 + 91 + 87 + 65) / 5 = 87\nID = 2 \u7684\u5b66\u751f\u5206\u6570\u4e3a 93\u300197\u300177\u3001100 \u548c 76 \u3002\u524d\u4e94\u79d1\u7684\u5e73\u5747\u5206 (100 + 97 + 93 + 77 + 76) / 5 = 88.6\uff0c\u4f46\u662f\u7531\u4e8e\u4f7f\u7528\u6574\u6570\u9664\u6cd5\uff0c\u7ed3\u679c\u8f6c\u6362\u4e3a 88\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aitems = [[1,100],[7,100],[1,100],[7,100],[1,100],[7,100],[1,100],[7,100],[1,100],[7,100]]\n\u8f93\u51fa\uff1a[[1,100],[7,100]]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= items.length <= 1000
  • \n\t
  • items[i].length == 2
  • \n\t
  • 1 <= IDi <= 1000
  • \n\t
  • 0 <= scorei <= 100
  • \n\t
  • \u5bf9\u4e8e\u6bcf\u4e2a IDi\uff0c\u81f3\u5c11 \u5b58\u5728\u4e94\u4e2a\u5206\u6570
  • \n
\n", "tags_en": ["Sort", "Array", "Hash Table"], "tags_cn": ["\u6392\u5e8f", "\u6570\u7ec4", "\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> highFive(vector>& items) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[][] highFive(int[][] items) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def highFive(self, items):\n \"\"\"\n :type items: List[List[int]]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def highFive(self, items: List[List[int]]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** highFive(int** items, int itemsSize, int* itemsColSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[][] HighFive(int[][] items) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} items\n * @return {number[][]}\n */\nvar highFive = function(items) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} items\n# @return {Integer[][]}\ndef high_five(items)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func highFive(_ items: [[Int]]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func highFive(items [][]int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def highFive(items: Array[Array[Int]]): Array[Array[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun highFive(items: Array): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn high_five(items: Vec>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $items\n * @return Integer[][]\n */\n function highFive($items) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function highFive(items: number[][]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (high-five items)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1086](https://leetcode-cn.com/problems/high-five)", "[\u524d\u4e94\u79d1\u7684\u5747\u5206](/solution/1000-1099/1086.High%20Five/README.md)", "`\u6392\u5e8f`,`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1086](https://leetcode.com/problems/high-five)", "[High Five](/solution/1000-1099/1086.High%20Five/README_EN.md)", "`Sort`,`Array`,`Hash Table`", "Easy", "\ud83d\udd12"]}, {"question_id": "1073", "frontend_question_id": "1020", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-enclaves", "url_en": "https://leetcode.com/problems/number-of-enclaves", "relative_path_cn": "/solution/1000-1099/1020.Number%20of%20Enclaves/README.md", "relative_path_en": "/solution/1000-1099/1020.Number%20of%20Enclaves/README_EN.md", "title_cn": "\u98de\u5730\u7684\u6570\u91cf", "title_en": "Number of Enclaves", "question_title_slug": "number-of-enclaves", "content_en": "

You are given an m x n binary matrix grid, where 0 represents a sea cell and 1 represents a land cell.

\n\n

A move consists of walking from one land cell to another adjacent (4-directionally) land cell or walking off the boundary of the grid.

\n\n

Return the number of land cells in grid for which we cannot walk off the boundary of the grid in any number of moves.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: grid = [[0,0,0,0],[1,0,1,0],[0,1,1,0],[0,0,0,0]]\nOutput: 3\nExplanation: There are three 1s that are enclosed by 0s, and one 1 that is not enclosed because its on the boundary.\n
\n\n

Example 2:

\n\"\"\n
\nInput: grid = [[0,1,1,0],[0,0,1,0],[0,0,1,0],[0,0,0,0]]\nOutput: 0\nExplanation: All 1s are either on the boundary or can reach the boundary.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • m == grid.length
  • \n\t
  • n == grid[i].length
  • \n\t
  • 1 <= m, n <= 500
  • \n\t
  • grid[i][j] is either 0 or 1.
  • \n
\n", "content_cn": "

\u7ed9\u51fa\u4e00\u4e2a\u4e8c\u7ef4\u6570\u7ec4 A\uff0c\u6bcf\u4e2a\u5355\u5143\u683c\u4e3a 0\uff08\u4ee3\u8868\u6d77\uff09\u6216 1\uff08\u4ee3\u8868\u9646\u5730\uff09\u3002

\n\n

\u79fb\u52a8\u662f\u6307\u5728\u9646\u5730\u4e0a\u4ece\u4e00\u4e2a\u5730\u65b9\u8d70\u5230\u53e6\u4e00\u4e2a\u5730\u65b9\uff08\u671d\u56db\u4e2a\u65b9\u5411\u4e4b\u4e00\uff09\u6216\u79bb\u5f00\u7f51\u683c\u7684\u8fb9\u754c\u3002

\n\n

\u8fd4\u56de\u7f51\u683c\u4e2d\u65e0\u6cd5\u5728\u4efb\u610f\u6b21\u6570\u7684\u79fb\u52a8\u4e2d\u79bb\u5f00\u7f51\u683c\u8fb9\u754c\u7684\u9646\u5730\u5355\u5143\u683c\u7684\u6570\u91cf\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a[[0,0,0,0],[1,0,1,0],[0,1,1,0],[0,0,0,0]]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a \n\u6709\u4e09\u4e2a 1 \u88ab 0 \u5305\u56f4\u3002\u4e00\u4e2a 1 \u6ca1\u6709\u88ab\u5305\u56f4\uff0c\u56e0\u4e3a\u5b83\u5728\u8fb9\u754c\u4e0a\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a[[0,1,1,0],[0,0,1,0],[0,0,1,0],[0,0,0,0]]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\n\u6240\u6709 1 \u90fd\u5728\u8fb9\u754c\u4e0a\u6216\u53ef\u4ee5\u5230\u8fbe\u8fb9\u754c\u3002
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= A.length <= 500
  2. \n\t
  3. 1 <= A[i].length <= 500
  4. \n\t
  5. 0 <= A[i][j] <= 1
  6. \n\t
  7. \u6240\u6709\u884c\u7684\u5927\u5c0f\u90fd\u76f8\u540c
  8. \n
\n", "tags_en": ["Depth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numEnclaves(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numEnclaves(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numEnclaves(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numEnclaves(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numEnclaves(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumEnclaves(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar numEnclaves = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef num_enclaves(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numEnclaves(_ grid: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numEnclaves(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numEnclaves(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numEnclaves(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_enclaves(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function numEnclaves($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numEnclaves(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-enclaves grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1020](https://leetcode-cn.com/problems/number-of-enclaves)", "[\u98de\u5730\u7684\u6570\u91cf](/solution/1000-1099/1020.Number%20of%20Enclaves/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1020](https://leetcode.com/problems/number-of-enclaves)", "[Number of Enclaves](/solution/1000-1099/1020.Number%20of%20Enclaves/README_EN.md)", "`Depth-first Search`", "Medium", ""]}, {"question_id": "1072", "frontend_question_id": "1019", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/next-greater-node-in-linked-list", "url_en": "https://leetcode.com/problems/next-greater-node-in-linked-list", "relative_path_cn": "/solution/1000-1099/1019.Next%20Greater%20Node%20In%20Linked%20List/README.md", "relative_path_en": "/solution/1000-1099/1019.Next%20Greater%20Node%20In%20Linked%20List/README_EN.md", "title_cn": "\u94fe\u8868\u4e2d\u7684\u4e0b\u4e00\u4e2a\u66f4\u5927\u8282\u70b9", "title_en": "Next Greater Node In Linked List", "question_title_slug": "next-greater-node-in-linked-list", "content_en": "

We are given a linked list with head as the first node.  Let's number the nodes in the list: node_1, node_2, node_3, ... etc.

\r\n\r\n

Each node may have a next larger value: for node_inext_larger(node_i) is the node_j.val such that j > i, node_j.val > node_i.val, and j is the smallest possible choice.  If such a j does not exist, the next larger value is 0.

\r\n\r\n

Return an array of integers answer, where answer[i] = next_larger(node_{i+1}).

\r\n\r\n

Note that in the example inputs (not outputs) below, arrays such as [2,1,5] represent the serialization of a linked list with a head node value of 2, second node value of 1, and third node value of 5.

\r\n\r\n

 

\r\n\r\n
\r\n

Example 1:

\r\n\r\n
\r\nInput: [2,1,5]\r\nOutput: [5,5,0]\r\n
\r\n\r\n
\r\n

Example 2:

\r\n\r\n
\r\nInput: [2,7,4,3,5]\r\nOutput: [7,0,5,5,0]\r\n
\r\n\r\n
\r\n

Example 3:

\r\n\r\n
\r\nInput: [1,7,5,1,9,2,5,1]\r\nOutput: [7,9,9,9,0,5,0,0]\r\n
\r\n\r\n

 

\r\n\r\n

Note:

\r\n\r\n
    \r\n\t
  1. 1 <= node.val <= 10^9 for each node in the linked list.
  2. \r\n\t
  3. The given list has length in the range [0, 10000].
  4. \r\n
\r\n
\r\n
\r\n
", "content_cn": "

\u7ed9\u51fa\u4e00\u4e2a\u4ee5\u5934\u8282\u70b9 head \u4f5c\u4e3a\u7b2c\u4e00\u4e2a\u8282\u70b9\u7684\u94fe\u8868\u3002\u94fe\u8868\u4e2d\u7684\u8282\u70b9\u5206\u522b\u7f16\u53f7\u4e3a\uff1anode_1, node_2, node_3, ... \u3002

\n\n

\u6bcf\u4e2a\u8282\u70b9\u90fd\u53ef\u80fd\u6709\u4e0b\u4e00\u4e2a\u66f4\u5927\u503c\uff08next larger value\uff09\uff1a\u5bf9\u4e8e node_i\uff0c\u5982\u679c\u5176 next_larger(node_i) \u662f node_j.val\uff0c\u90a3\u4e48\u5c31\u6709 j > i \u4e14  node_j.val > node_i.val\uff0c\u800c j \u662f\u53ef\u80fd\u7684\u9009\u9879\u4e2d\u6700\u5c0f\u7684\u90a3\u4e2a\u3002\u5982\u679c\u4e0d\u5b58\u5728\u8fd9\u6837\u7684 j\uff0c\u90a3\u4e48\u4e0b\u4e00\u4e2a\u66f4\u5927\u503c\u4e3a 0 \u3002

\n\n

\u8fd4\u56de\u6574\u6570\u7b54\u6848\u6570\u7ec4 answer\uff0c\u5176\u4e2d answer[i] = next_larger(node_{i+1}) \u3002

\n\n

\u6ce8\u610f\uff1a\u5728\u4e0b\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u8bf8\u5982 [2,1,5] \u8fd9\u6837\u7684\u8f93\u5165\uff08\u4e0d\u662f\u8f93\u51fa\uff09\u662f\u94fe\u8868\u7684\u5e8f\u5217\u5316\u8868\u793a\uff0c\u5176\u5934\u8282\u70b9\u7684\u503c\u4e3a 2\uff0c\u7b2c\u4e8c\u4e2a\u8282\u70b9\u503c\u4e3a 1\uff0c\u7b2c\u4e09\u4e2a\u8282\u70b9\u503c\u4e3a 5 \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a[2,1,5]\n\u8f93\u51fa\uff1a[5,5,0]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a[2,7,4,3,5]\n\u8f93\u51fa\uff1a[7,0,5,5,0]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1a[1,7,5,1,9,2,5,1]\n\u8f93\u51fa\uff1a[7,9,9,9,0,5,0,0]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. \u5bf9\u4e8e\u94fe\u8868\u4e2d\u7684\u6bcf\u4e2a\u8282\u70b9\uff0c1 <= node.val <= 10^9
  2. \n\t
  3. \u7ed9\u5b9a\u5217\u8868\u7684\u957f\u5ea6\u5728 [0, 10000] \u8303\u56f4\u5185
  4. \n
\n", "tags_en": ["Stack", "Linked List"], "tags_cn": ["\u6808", "\u94fe\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\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 nextLargerNodes(ListNode* head) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode(int x) { val = x; }\n * }\n */\nclass Solution {\n public int[] nextLargerNodes(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.next = None\n\nclass Solution(object):\n def nextLargerNodes(self, head):\n \"\"\"\n :type head: ListNode\n :rtype: List[int]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, x):\n# self.val = x\n# self.next = None\n\nclass Solution:\n def nextLargerNodes(self, head: ListNode) -> List[int]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* nextLargerNodes(struct ListNode* head, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int x) { val = x; }\n * }\n */\npublic class Solution {\n public int[] NextLargerNodes(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val) {\n * this.val = val;\n * this.next = null;\n * }\n */\n/**\n * @param {ListNode} head\n * @return {number[]}\n */\nvar nextLargerNodes = function(head) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val)\n# @val = val\n# @next = nil\n# end\n# end\n\n# @param {ListNode} head\n# @return {Integer[]}\ndef next_larger_nodes(head)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.next = nil\n * }\n * }\n */\nclass Solution {\n func nextLargerNodes(_ head: ListNode?) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc nextLargerNodes(head *ListNode) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(var _x: Int = 0) {\n * var next: ListNode = null\n * var x: Int = _x\n * }\n */\nobject Solution {\n def nextLargerNodes(head: ListNode): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun nextLargerNodes(head: ListNode?): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n// \n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn next_larger_nodes(head: Option>) -> Vec {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val) { $this->val = $val; }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @return Integer[]\n */\n function nextLargerNodes($head) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction nextLargerNodes(head: ListNode | null): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (next-larger-nodes head)\n (-> (or/c list-node? #f) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1019](https://leetcode-cn.com/problems/next-greater-node-in-linked-list)", "[\u94fe\u8868\u4e2d\u7684\u4e0b\u4e00\u4e2a\u66f4\u5927\u8282\u70b9](/solution/1000-1099/1019.Next%20Greater%20Node%20In%20Linked%20List/README.md)", "`\u6808`,`\u94fe\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1019](https://leetcode.com/problems/next-greater-node-in-linked-list)", "[Next Greater Node In Linked List](/solution/1000-1099/1019.Next%20Greater%20Node%20In%20Linked%20List/README_EN.md)", "`Stack`,`Linked List`", "Medium", ""]}, {"question_id": "1071", "frontend_question_id": "1018", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/binary-prefix-divisible-by-5", "url_en": "https://leetcode.com/problems/binary-prefix-divisible-by-5", "relative_path_cn": "/solution/1000-1099/1018.Binary%20Prefix%20Divisible%20By%205/README.md", "relative_path_en": "/solution/1000-1099/1018.Binary%20Prefix%20Divisible%20By%205/README_EN.md", "title_cn": "\u53ef\u88ab 5 \u6574\u9664\u7684\u4e8c\u8fdb\u5236\u524d\u7f00", "title_en": "Binary Prefix Divisible By 5", "question_title_slug": "binary-prefix-divisible-by-5", "content_en": "

Given an array nums of 0s and 1s, consider xi: the i-th subarray from nums[0] to nums[i] interpreted as a binary number (from most-significant-bit to least-significant-bit.)

\n\n

Return a list of booleans answer, where answer[i] is true if and only if xi is divisible by 5.

\n\n

Example 1:

\n\n
\nInput: nums = [0,1,1]\nOutput: [true,false,false]\nExplanation: \nThe input numbers in binary are 0, 01, 011; which are 0, 1, and 3 in base-10.  Only the first number is divisible by 5, so answer[0] is true.\n
\n\n

Example 2:

\n\n
\nInput: nums = [1,1,1]\nOutput: [false,false,false]\n
\n\n

Example 3:

\n\n
\nInput: nums = [0,1,1,1,1,1]\nOutput: [true,false,false,false,true,false]\n
\n\n

Example 4:

\n\n
\nInput: nums = [1,1,1,0,1]\nOutput: [false,false,false,false,false]\n
\n\n

 

\n\n

Note:

\n\n
    \n\t
  1. 1 <= nums.length <= 30000
  2. \n\t
  3. nums[i] is 0 or 1
  4. \n
\n", "content_cn": "

\u7ed9\u5b9a\u7531\u82e5\u5e72 0 \u548c 1 \u7ec4\u6210\u7684\u6570\u7ec4 A\u3002\u6211\u4eec\u5b9a\u4e49 N_i\uff1a\u4ece A[0] \u5230 A[i] \u7684\u7b2c i \u4e2a\u5b50\u6570\u7ec4\u88ab\u89e3\u91ca\u4e3a\u4e00\u4e2a\u4e8c\u8fdb\u5236\u6570\uff08\u4ece\u6700\u9ad8\u6709\u6548\u4f4d\u5230\u6700\u4f4e\u6709\u6548\u4f4d\uff09\u3002

\n\n

\u8fd4\u56de\u5e03\u5c14\u503c\u5217\u8868 answer\uff0c\u53ea\u6709\u5f53 N_i \u53ef\u4ee5\u88ab 5 \u6574\u9664\u65f6\uff0c\u7b54\u6848 answer[i] \u4e3a true\uff0c\u5426\u5219\u4e3a false\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a[0,1,1]\n\u8f93\u51fa\uff1a[true,false,false]\n\u89e3\u91ca\uff1a\n\u8f93\u5165\u6570\u5b57\u4e3a 0, 01, 011\uff1b\u4e5f\u5c31\u662f\u5341\u8fdb\u5236\u4e2d\u7684 0, 1, 3 \u3002\u53ea\u6709\u7b2c\u4e00\u4e2a\u6570\u53ef\u4ee5\u88ab 5 \u6574\u9664\uff0c\u56e0\u6b64 answer[0] \u4e3a\u771f\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a[1,1,1]\n\u8f93\u51fa\uff1a[false,false,false]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1a[0,1,1,1,1,1]\n\u8f93\u51fa\uff1a[true,false,false,false,true,false]\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1a[1,1,1,0,1]\n\u8f93\u51fa\uff1a[false,false,false,false,false]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= A.length <= 30000
  2. \n\t
  3. A[i] \u4e3a 0 \u6216 1
  4. \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector prefixesDivBy5(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List prefixesDivBy5(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def prefixesDivBy5(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[bool]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def prefixesDivBy5(self, nums: List[int]) -> List[bool]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nbool* prefixesDivBy5(int* nums, int numsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList PrefixesDivBy5(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {boolean[]}\n */\nvar prefixesDivBy5 = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Boolean[]}\ndef prefixes_div_by5(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func prefixesDivBy5(_ nums: [Int]) -> [Bool] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func prefixesDivBy5(nums []int) []bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def prefixesDivBy5(nums: Array[Int]): List[Boolean] = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun prefixesDivBy5(nums: IntArray): List {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn prefixes_div_by5(nums: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Boolean[]\n */\n function prefixesDivBy5($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function prefixesDivBy5(nums: number[]): boolean[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (prefixes-div-by5 nums)\n (-> (listof exact-integer?) (listof boolean?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1018](https://leetcode-cn.com/problems/binary-prefix-divisible-by-5)", "[\u53ef\u88ab 5 \u6574\u9664\u7684\u4e8c\u8fdb\u5236\u524d\u7f00](/solution/1000-1099/1018.Binary%20Prefix%20Divisible%20By%205/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1018](https://leetcode.com/problems/binary-prefix-divisible-by-5)", "[Binary Prefix Divisible By 5](/solution/1000-1099/1018.Binary%20Prefix%20Divisible%20By%205/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1070", "frontend_question_id": "1017", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/convert-to-base-2", "url_en": "https://leetcode.com/problems/convert-to-base-2", "relative_path_cn": "/solution/1000-1099/1017.Convert%20to%20Base%20-2/README.md", "relative_path_en": "/solution/1000-1099/1017.Convert%20to%20Base%20-2/README_EN.md", "title_cn": "\u8d1f\u4e8c\u8fdb\u5236\u8f6c\u6362", "title_en": "Convert to Base -2", "question_title_slug": "convert-to-base-2", "content_en": "

Given a number n, return a string consisting of "0"s and "1"s that represents its value in base -2 (negative two).

\n\n

The returned string must have no leading zeroes, unless the string is "0".

\n\n

 

\n\n
\n

Example 1:

\n\n
\nInput: n = 2\nOutput: "110"\nExplantion: (-2) ^ 2 + (-2) ^ 1 = 2\n
\n\n
\n

Example 2:

\n\n
\nInput: n = 3\nOutput: "111"\nExplantion: (-2) ^ 2 + (-2) ^ 1 + (-2) ^ 0 = 3\n
\n\n
\n

Example 3:

\n\n
\nInput: n = 4\nOutput: "100"\nExplantion: (-2) ^ 2 = 4\n
\n\n

 

\n\n

Note:

\n\n
    \n\t
  1. 0 <= n <= 109
  2. \n
\n
\n
\n
\n", "content_cn": "

\u7ed9\u51fa\u6570\u5b57 N\uff0c\u8fd4\u56de\u7531\u82e5\u5e72 "0" \u548c "1"\u7ec4\u6210\u7684\u5b57\u7b26\u4e32\uff0c\u8be5\u5b57\u7b26\u4e32\u4e3a N \u7684\u8d1f\u4e8c\u8fdb\u5236\uff08base -2\uff09\u8868\u793a\u3002

\n\n

\u9664\u975e\u5b57\u7b26\u4e32\u5c31\u662f "0"\uff0c\u5426\u5219\u8fd4\u56de\u7684\u5b57\u7b26\u4e32\u4e2d\u4e0d\u80fd\u542b\u6709\u524d\u5bfc\u96f6\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a2\n\u8f93\u51fa\uff1a"110"\n\u89e3\u91ca\uff1a(-2) ^ 2 + (-2) ^ 1 = 2\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a3\n\u8f93\u51fa\uff1a"111"\n\u89e3\u91ca\uff1a(-2) ^ 2 + (-2) ^ 1 + (-2) ^ 0 = 3\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1a4\n\u8f93\u51fa\uff1a"100"\n\u89e3\u91ca\uff1a(-2) ^ 2 = 4\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 0 <= N <= 10^9
  2. \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string baseNeg2(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String baseNeg2(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def baseNeg2(self, n):\n \"\"\"\n :type n: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def baseNeg2(self, n: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * baseNeg2(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string BaseNeg2(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {string}\n */\nvar baseNeg2 = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {String}\ndef base_neg2(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func baseNeg2(_ n: Int) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func baseNeg2(n int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def baseNeg2(n: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun baseNeg2(n: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn base_neg2(n: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return String\n */\n function baseNeg2($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function baseNeg2(n: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (base-neg2 n)\n (-> exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1017](https://leetcode-cn.com/problems/convert-to-base-2)", "[\u8d1f\u4e8c\u8fdb\u5236\u8f6c\u6362](/solution/1000-1099/1017.Convert%20to%20Base%20-2/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1017](https://leetcode.com/problems/convert-to-base-2)", "[Convert to Base -2](/solution/1000-1099/1017.Convert%20to%20Base%20-2/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "1069", "frontend_question_id": "1056", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/confusing-number", "url_en": "https://leetcode.com/problems/confusing-number", "relative_path_cn": "/solution/1000-1099/1056.Confusing%20Number/README.md", "relative_path_en": "/solution/1000-1099/1056.Confusing%20Number/README_EN.md", "title_cn": "\u6613\u6df7\u6dc6\u6570", "title_en": "Confusing Number", "question_title_slug": "confusing-number", "content_en": "

Given a number n, return true if and only if it is a confusing number, which satisfies the following condition:

\n\n

We can rotate digits by 180 degrees to form new digits. When 0, 1, 6, 8, 9 are rotated 180 degrees, they become 0, 1, 9, 8, 6 respectively. When 2, 3, 4, 5 and 7 are rotated 180 degrees, they become invalid. A confusing number is a number that when rotated 180 degrees becomes a different number with each digit valid.

\n\n

 

\n\n

Example 1:

\n\n

\"\"

\n\n
\nInput: n = 6\nOutput: true\nExplanation: \nWe get 9 after rotating 6, 9 is a valid number and 9!=6.\n
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: n = 89\nOutput: true\nExplanation: \nWe get 68 after rotating 89, 86 is a valid number and 86!=89.\n
\n\n

Example 3:

\n\n

\"\"

\n\n
\nInput: n = 11\nOutput: false\nExplanation: \nWe get 11 after rotating 11, 11 is a valid number but the value remains the same, thus 11 is not a confusing number.\n
\n\n

Example 4:

\n\n

\"\"

\n\n
\nInput: n = 25\nOutput: false\nExplanation: \nWe get an invalid number after rotating 25.\n
\n\n

 

\n\n

Note:

\n\n
    \n\t
  1. 0 <= n <= 109
  2. \n\t
  3. After the rotation we can ignore leading zeros, for example if after rotation we have 0008 then this number is considered as just 8.
  4. \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u6570\u5b57 N\uff0c\u5f53\u5b83\u6ee1\u8db3\u4ee5\u4e0b\u6761\u4ef6\u7684\u65f6\u5019\u8fd4\u56de true\uff1a

\n\n

\u539f\u6570\u5b57\u65cb\u8f6c 180° \u4ee5\u540e\u53ef\u4ee5\u5f97\u5230\u65b0\u7684\u6570\u5b57\u3002

\n\n

\u5982 0, 1, 6, 8, 9 \u65cb\u8f6c 180° \u4ee5\u540e\uff0c\u5f97\u5230\u4e86\u65b0\u7684\u6570\u5b57 0, 1, 9, 8, 6 \u3002

\n\n

2, 3, 4, 5, 7 \u65cb\u8f6c 180° \u540e\uff0c\u5f97\u5230\u7684\u4e0d\u662f\u6570\u5b57\u3002

\n\n

\u6613\u6df7\u6dc6\u6570 (confusing number) \u5728\u65cb\u8f6c180°\u4ee5\u540e\uff0c\u53ef\u4ee5\u5f97\u5230\u548c\u539f\u6765\u4e0d\u540c\u7684\u6570\uff0c\u4e14\u65b0\u6570\u5b57\u7684\u6bcf\u4e00\u4f4d\u90fd\u662f\u6709\u6548\u7684\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1a6\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a \n\u628a 6 \u65cb\u8f6c 180° \u4ee5\u540e\u5f97\u5230 9\uff0c9 \u662f\u6709\u6548\u6570\u5b57\u4e14 9!=6 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1a89\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca: \n\u628a 89 \u65cb\u8f6c 180° \u4ee5\u540e\u5f97\u5230 68\uff0c86 \u662f\u6709\u6548\u6570\u5b57\u4e14 86!=89 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1a11\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\n\u628a 11 \u65cb\u8f6c 180° \u4ee5\u540e\u5f97\u5230 11\uff0c11 \u662f\u6709\u6548\u6570\u5b57\u4f46\u662f\u503c\u4fdd\u6301\u4e0d\u53d8\uff0c\u6240\u4ee5 11 \u4e0d\u662f\u6613\u6df7\u6dc6\u6570\u5b57\u3002 \n
\n\n

\u793a\u4f8b 4\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1a25\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\n\u628a 25 \u65cb\u8f6c 180° \u4ee5\u540e\u5f97\u5230\u7684\u4e0d\u662f\u6570\u5b57\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 0 <= N <= 10^9
  2. \n\t
  3. \u53ef\u4ee5\u5ffd\u7565\u6389\u65cb\u8f6c\u540e\u5f97\u5230\u7684\u524d\u5bfc\u96f6\uff0c\u4f8b\u5982\uff0c\u5982\u679c\u6211\u4eec\u65cb\u8f6c\u540e\u5f97\u5230 0008 \u90a3\u4e48\u8be5\u6570\u5b57\u5c31\u662f 8 \u3002
  4. \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool confusingNumber(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean confusingNumber(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def confusingNumber(self, n):\n \"\"\"\n :type n: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def confusingNumber(self, n: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool confusingNumber(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool ConfusingNumber(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {boolean}\n */\nvar confusingNumber = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Boolean}\ndef confusing_number(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func confusingNumber(_ n: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func confusingNumber(n int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def confusingNumber(n: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun confusingNumber(n: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn confusing_number(n: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Boolean\n */\n function confusingNumber($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function confusingNumber(n: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (confusing-number n)\n (-> exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1056](https://leetcode-cn.com/problems/confusing-number)", "[\u6613\u6df7\u6dc6\u6570](/solution/1000-1099/1056.Confusing%20Number/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1056](https://leetcode.com/problems/confusing-number)", "[Confusing Number](/solution/1000-1099/1056.Confusing%20Number/README_EN.md)", "`Math`", "Easy", "\ud83d\udd12"]}, {"question_id": "1068", "frontend_question_id": "1067", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/digit-count-in-range", "url_en": "https://leetcode.com/problems/digit-count-in-range", "relative_path_cn": "/solution/1000-1099/1067.Digit%20Count%20in%20Range/README.md", "relative_path_en": "/solution/1000-1099/1067.Digit%20Count%20in%20Range/README_EN.md", "title_cn": "\u8303\u56f4\u5185\u7684\u6570\u5b57\u8ba1\u6570", "title_en": "Digit Count in Range", "question_title_slug": "digit-count-in-range", "content_en": "Given an integer d between 0 and 9, and two positive integers low and high as lower and upper bounds, respectively. Return the number of times that d occurs as a digit in all integers between low and high, including the bounds low and high.\r\n

 

\r\n\r\n

Example 1:

\r\n\r\n
\r\nInput: d = 1, low = 1, high = 13\r\nOutput: 6\r\nExplanation: \r\nThe digit d=1 occurs 6 times in 1,10,11,12,13. Note that the digit d=1 occurs twice in the number 11.\r\n
\r\n\r\n
\r\n

Example 2:

\r\n\r\n
\r\nInput: d = 3, low = 100, high = 250\r\nOutput: 35\r\nExplanation: \r\nThe digit d=3 occurs 35 times in 103,113,123,130,131,...,238,239,243.\r\n
\r\n\r\n

 

\r\n\r\n

Note:

\r\n\r\n
    \r\n\t
  1. 0 <= d <= 9
  2. \r\n\t
  3. 1 <= low <= high <= 2×10^8
  4. \r\n
\r\n
", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u5728 0 \u5230 9 \u4e4b\u95f4\u7684\u6574\u6570 d\uff0c\u548c\u4e24\u4e2a\u6b63\u6574\u6570 low \u548c high \u5206\u522b\u4f5c\u4e3a\u4e0a\u4e0b\u754c\u3002\u8fd4\u56de d \u5728 low \u548c high \u4e4b\u95f4\u7684\u6574\u6570\u4e2d\u51fa\u73b0\u7684\u6b21\u6570\uff0c\u5305\u62ec\u8fb9\u754c low \u548c high\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1ad = 1, low = 1, high = 13\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a \n\u6570\u5b57 d=1 \u5728 1,10,11,12,13 \u4e2d\u51fa\u73b0 6 \u6b21\u3002\u6ce8\u610f d=1 \u5728\u6570\u5b57 11 \u4e2d\u51fa\u73b0\u4e24\u6b21\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1ad = 3, low = 100, high = 250\n\u8f93\u51fa\uff1a35\n\u89e3\u91ca\uff1a\n\u6570\u5b57 d=3 \u5728 103,113,123,130,131,...,238,239,243 \u51fa\u73b0 35 \u6b21\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 0 <= d <= 9
  2. \n\t
  3. 1 <= low <= high <= 2×10^8
  4. \n
\n", "tags_en": ["Math", "Dynamic Programming"], "tags_cn": ["\u6570\u5b66", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int digitsCount(int d, int low, int high) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int digitsCount(int d, int low, int high) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def digitsCount(self, d, low, high):\n \"\"\"\n :type d: int\n :type low: int\n :type high: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def digitsCount(self, d: int, low: int, high: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint digitsCount(int d, int low, int high){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int DigitsCount(int d, int low, int high) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} d\n * @param {number} low\n * @param {number} high\n * @return {number}\n */\nvar digitsCount = function(d, low, high) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} d\n# @param {Integer} low\n# @param {Integer} high\n# @return {Integer}\ndef digits_count(d, low, high)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func digitsCount(_ d: Int, _ low: Int, _ high: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func digitsCount(d int, low int, high int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def digitsCount(d: Int, low: Int, high: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun digitsCount(d: Int, low: Int, high: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn digits_count(d: i32, low: i32, high: i32) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $d\n * @param Integer $low\n * @param Integer $high\n * @return Integer\n */\n function digitsCount($d, $low, $high) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function digitsCount(d: number, low: number, high: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (digits-count d low high)\n (-> exact-integer? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1067](https://leetcode-cn.com/problems/digit-count-in-range)", "[\u8303\u56f4\u5185\u7684\u6570\u5b57\u8ba1\u6570](/solution/1000-1099/1067.Digit%20Count%20in%20Range/README.md)", "`\u6570\u5b66`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1067](https://leetcode.com/problems/digit-count-in-range)", "[Digit Count in Range](/solution/1000-1099/1067.Digit%20Count%20in%20Range/README_EN.md)", "`Math`,`Dynamic Programming`", "Hard", "\ud83d\udd12"]}, {"question_id": "1067", "frontend_question_id": "1066", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/campus-bikes-ii", "url_en": "https://leetcode.com/problems/campus-bikes-ii", "relative_path_cn": "/solution/1000-1099/1066.Campus%20Bikes%20II/README.md", "relative_path_en": "/solution/1000-1099/1066.Campus%20Bikes%20II/README_EN.md", "title_cn": "\u6821\u56ed\u81ea\u884c\u8f66\u5206\u914d II", "title_en": "Campus Bikes II", "question_title_slug": "campus-bikes-ii", "content_en": "

On a campus represented as a 2D grid, there are N workers and M bikes, with N <= M. Each worker and bike is a 2D coordinate on this grid.

\n\n

We assign one unique bike to each worker so that the sum of the Manhattan distances between each worker and their assigned bike is minimized.

\n\n

The Manhattan distance between two points p1 and p2 is Manhattan(p1, p2) = |p1.x - p2.x| + |p1.y - p2.y|.

\n\n

Return the minimum possible sum of Manhattan distances between each worker and their assigned bike.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: workers = [[0,0],[2,1]], bikes = [[1,2],[3,3]]\nOutput: 6\nExplanation: \nWe assign bike 0 to worker 0, bike 1 to worker 1. The Manhattan distance of both assignments is 3, so the output is 6.\n
\n\n

Example 2:

\n\"\"\n
\nInput: workers = [[0,0],[1,1],[2,0]], bikes = [[1,0],[2,2],[2,1]]\nOutput: 4\nExplanation: \nWe first assign bike 0 to worker 0, then assign bike 1 to worker 1 or worker 2, bike 2 to worker 2 or worker 1. Both assignments lead to sum of the Manhattan distances as 4.\n
\n\n

Example 3:

\n\n
\nInput: workers = [[0,0],[1,0],[2,0],[3,0],[4,0]], bikes = [[0,999],[1,999],[2,999],[3,999],[4,999]]\nOutput: 4995\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • N == workers.length
  • \n\t
  • M == bikes.length
  • \n\t
  • 1 <= N <= M <= 10
  • \n\t
  • workers[i].length == 2
  • \n\t
  • bikes[i].length == 2
  • \n\t
  • 0 <= workers[i][0], workers[i][1], bikes[i][0], bikes[i][1] < 1000
  • \n\t
  • All the workers and the bikes locations are unique.
  • \n
\n", "content_cn": "

\u5728\u7531 2D \u7f51\u683c\u8868\u793a\u7684\u6821\u56ed\u91cc\u6709 n \u4f4d\u5de5\u4eba\uff08worker\uff09\u548c m \u8f86\u81ea\u884c\u8f66\uff08bike\uff09\uff0cn <= m\u3002\u6240\u6709\u5de5\u4eba\u548c\u81ea\u884c\u8f66\u7684\u4f4d\u7f6e\u90fd\u7528\u7f51\u683c\u4e0a\u7684 2D \u5750\u6807\u8868\u793a\u3002

\n\n

\u6211\u4eec\u4e3a\u6bcf\u4e00\u4f4d\u5de5\u4eba\u5206\u914d\u4e00\u8f86\u4e13\u5c5e\u81ea\u884c\u8f66\uff0c\u4f7f\u6bcf\u4e2a\u5de5\u4eba\u4e0e\u5176\u5206\u914d\u5230\u7684\u81ea\u884c\u8f66\u4e4b\u95f4\u7684\u66fc\u54c8\u987f\u8ddd\u79bb\u6700\u5c0f\u5316\u3002

\n\n

p1 \u548c p2 \u4e4b\u95f4\u7684\u66fc\u54c8\u987f\u8ddd\u79bb\u4e3a Manhattan(p1, p2) = |p1.x - p2.x| + |p1.y - p2.y|\u3002

\n\n

\u8fd4\u56de\u6bcf\u4e2a\u5de5\u4eba\u4e0e\u5206\u914d\u5230\u7684\u81ea\u884c\u8f66\u4e4b\u95f4\u7684\u66fc\u54c8\u987f\u8ddd\u79bb\u7684\u6700\u5c0f\u53ef\u80fd\u603b\u548c\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1aworkers = [[0,0],[2,1]], bikes = [[1,2],[3,3]]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\n\u81ea\u884c\u8f66 0 \u5206\u914d\u7ed9\u5de5\u4eba 0\uff0c\u81ea\u884c\u8f66 1 \u5206\u914d\u7ed9\u5de5\u4eba 1 \u3002\u5206\u914d\u5f97\u5230\u7684\u66fc\u54c8\u987f\u8ddd\u79bb\u90fd\u662f 3, \u6240\u4ee5\u8f93\u51fa\u4e3a 6 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1aworkers = [[0,0],[1,1],[2,0]], bikes = [[1,0],[2,2],[2,1]]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\n\u5148\u5c06\u81ea\u884c\u8f66 0 \u5206\u914d\u7ed9\u5de5\u4eba 0\uff0c\u518d\u5c06\u81ea\u884c\u8f66 1 \u5206\u914d\u7ed9\u5de5\u4eba 1\uff08\u6216\u5de5\u4eba 2\uff09\uff0c\u81ea\u884c\u8f66 2 \u7ed9\u5de5\u4eba 2\uff08\u6216\u5de5\u4eba 1\uff09\u3002\u5982\u6b64\u5206\u914d\u4f7f\u5f97\u66fc\u54c8\u987f\u8ddd\u79bb\u7684\u603b\u548c\u4e3a 4\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 0 <= workers[i][0], workers[i][1], bikes[i][0], bikes[i][1] < 1000
  2. \n\t
  3. \u6240\u6709\u5de5\u4eba\u548c\u81ea\u884c\u8f66\u7684\u4f4d\u7f6e\u90fd\u4e0d\u76f8\u540c\u3002
  4. \n\t
  5. 1 <= workers.length <= bikes.length <= 10
  6. \n
\n", "tags_en": ["Dynamic Programming", "Backtracking"], "tags_cn": ["\u52a8\u6001\u89c4\u5212", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int assignBikes(vector>& workers, vector>& bikes) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int assignBikes(int[][] workers, int[][] bikes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def assignBikes(self, workers, bikes):\n \"\"\"\n :type workers: List[List[int]]\n :type bikes: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def assignBikes(self, workers: List[List[int]], bikes: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint assignBikes(int** workers, int workersSize, int* workersColSize, int** bikes, int bikesSize, int* bikesColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int AssignBikes(int[][] workers, int[][] bikes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} workers\n * @param {number[][]} bikes\n * @return {number}\n */\nvar assignBikes = function(workers, bikes) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} workers\n# @param {Integer[][]} bikes\n# @return {Integer}\ndef assign_bikes(workers, bikes)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func assignBikes(_ workers: [[Int]], _ bikes: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func assignBikes(workers [][]int, bikes [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def assignBikes(workers: Array[Array[Int]], bikes: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun assignBikes(workers: Array, bikes: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn assign_bikes(workers: Vec>, bikes: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $workers\n * @param Integer[][] $bikes\n * @return Integer\n */\n function assignBikes($workers, $bikes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function assignBikes(workers: number[][], bikes: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (assign-bikes workers bikes)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1066](https://leetcode-cn.com/problems/campus-bikes-ii)", "[\u6821\u56ed\u81ea\u884c\u8f66\u5206\u914d II](/solution/1000-1099/1066.Campus%20Bikes%20II/README.md)", "`\u52a8\u6001\u89c4\u5212`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1066](https://leetcode.com/problems/campus-bikes-ii)", "[Campus Bikes II](/solution/1000-1099/1066.Campus%20Bikes%20II/README_EN.md)", "`Dynamic Programming`,`Backtracking`", "Medium", "\ud83d\udd12"]}, {"question_id": "1066", "frontend_question_id": "1064", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/fixed-point", "url_en": "https://leetcode.com/problems/fixed-point", "relative_path_cn": "/solution/1000-1099/1064.Fixed%20Point/README.md", "relative_path_en": "/solution/1000-1099/1064.Fixed%20Point/README_EN.md", "title_cn": "\u4e0d\u52a8\u70b9", "title_en": "Fixed Point", "question_title_slug": "fixed-point", "content_en": "

Given an array of distinct integers arr, where arr is sorted in ascending order, return the smallest index i that satisfies arr[i] == i. If there is no such index, return -1.

\n\n

 

\n

Example 1:

\n\n
\nInput: arr = [-10,-5,0,3,7]\nOutput: 3\nExplanation: For the given array, arr[0] = -10, arr[1] = -5, arr[2] = 0, arr[3] = 3, thus the output is 3.
\n\n

Example 2:

\n\n
\nInput: arr = [0,2,5,8,17]\nOutput: 0\nExplanation: arr[0] = 0, thus the output is 0.
\n\n

Example 3:

\n\n
\nInput: arr = [-10,-5,3,4,7,9]\nOutput: -1\nExplanation: There is no such i that arr[i] == i, thus the output is -1.
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= arr.length < 104
  • \n\t
  • -109 <= arr[i] <= 109
  • \n
\n\n

 

\nFollow up: The O(n) solution is very straightforward. Can we do better?", "content_cn": "

\u7ed9\u5b9a\u5df2\u7ecf\u6309 \u5347\u5e8f \u6392\u5217\u3001\u7531\u4e0d\u540c\u6574\u6570\u7ec4\u6210\u7684\u6570\u7ec4 arr\uff0c\u8fd4\u56de\u6ee1\u8db3 arr[i] == i \u7684\u6700\u5c0f\u7d22\u5f15\u00a0i\u3002\u5982\u679c\u4e0d\u5b58\u5728\u8fd9\u6837\u7684\u00a0i\uff0c\u8fd4\u56de -1\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [-10,-5,0,3,7]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u5bf9\u4e8e\u7ed9\u5b9a\u7684\u6570\u7ec4\uff0carr[0] = -10\uff0carr[1] = -5\uff0carr[2] = 0\uff0carr[3] = 3\uff0c\u56e0\u6b64\u8f93\u51fa\u4e3a 3 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [0,2,5,8,17]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1aarr[0] = 0\uff0c\u56e0\u6b64\u8f93\u51fa\u4e3a 0 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [-10,-5,3,4,7,9]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u4e0d\u5b58\u5728\u8fd9\u6837\u7684 i \u6ee1\u8db3 arr[i] = i\uff0c\u56e0\u6b64\u8f93\u51fa\u4e3a -1 \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= arr.length < 104
  • \n\t
  • -109 <= arr[i] <= 109
  • \n
\n\n

\u00a0

\n\n

\u8fdb\u9636\uff1a\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n) \u7684\u89e3\u51b3\u65b9\u6848\u5f88\u76f4\u89c2\u4e5f\u5f88\u7b80\u5355\u3002\u4f60\u53ef\u4ee5\u8bbe\u8ba1\u66f4\u4f18\u7684\u89e3\u51b3\u65b9\u6848\u5417\uff1f

\n", "tags_en": ["Array", "Binary Search"], "tags_cn": ["\u6570\u7ec4", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int fixedPoint(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int fixedPoint(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def fixedPoint(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def fixedPoint(self, arr: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint fixedPoint(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FixedPoint(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar fixedPoint = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef fixed_point(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func fixedPoint(_ arr: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func fixedPoint(arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def fixedPoint(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun fixedPoint(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn fixed_point(arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function fixedPoint($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function fixedPoint(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (fixed-point arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1064](https://leetcode-cn.com/problems/fixed-point)", "[\u4e0d\u52a8\u70b9](/solution/1000-1099/1064.Fixed%20Point/README.md)", "`\u6570\u7ec4`,`\u4e8c\u5206\u67e5\u627e`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1064](https://leetcode.com/problems/fixed-point)", "[Fixed Point](/solution/1000-1099/1064.Fixed%20Point/README_EN.md)", "`Array`,`Binary Search`", "Easy", "\ud83d\udd12"]}, {"question_id": "1065", "frontend_question_id": "1016", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/binary-string-with-substrings-representing-1-to-n", "url_en": "https://leetcode.com/problems/binary-string-with-substrings-representing-1-to-n", "relative_path_cn": "/solution/1000-1099/1016.Binary%20String%20With%20Substrings%20Representing%201%20To%20N/README.md", "relative_path_en": "/solution/1000-1099/1016.Binary%20String%20With%20Substrings%20Representing%201%20To%20N/README_EN.md", "title_cn": "\u5b50\u4e32\u80fd\u8868\u793a\u4ece 1 \u5230 N \u6570\u5b57\u7684\u4e8c\u8fdb\u5236\u4e32", "title_en": "Binary String With Substrings Representing 1 To N", "question_title_slug": "binary-string-with-substrings-representing-1-to-n", "content_en": "

Given a binary string s (a string consisting only of '0' and '1's) and a positive integer n, return true if and only if for every integer x from 1 to n, the binary representation of x is a substring of s.

\n\n

 

\n\n

Example 1:

\n\n
\nInput: s = "0110", n = 3\nOutput: true\n
\n\n

Example 2:

\n\n
\nInput: s = "0110", n = 4\nOutput: false\n
\n\n

 

\n\n

Note:

\n\n
    \n\t
  1. 1 <= s.length <= 1000
  2. \n\t
  3. 1 <= n <= 109
  4. \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32 S\uff08\u4e00\u4e2a\u4ec5\u7531\u82e5\u5e72 '0' \u548c '1' \u6784\u6210\u7684\u5b57\u7b26\u4e32\uff09\u548c\u4e00\u4e2a\u6b63\u6574\u6570 N\uff0c\u5982\u679c\u5bf9\u4e8e\u4ece 1 \u5230 N \u7684\u6bcf\u4e2a\u6574\u6570 X\uff0c\u5176\u4e8c\u8fdb\u5236\u8868\u793a\u90fd\u662f S \u7684\u5b50\u4e32\uff0c\u5c31\u8fd4\u56de true\uff0c\u5426\u5219\u8fd4\u56de false\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aS = "0110", N = 3\n\u8f93\u51fa\uff1atrue\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aS = "0110", N = 4\n\u8f93\u51fa\uff1afalse\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= S.length <= 1000
  2. \n\t
  3. 1 <= N <= 10^9
  4. \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool queryString(string s, int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean queryString(String s, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def queryString(self, s, n):\n \"\"\"\n :type s: str\n :type n: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def queryString(self, s: str, n: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool queryString(char * s, int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool QueryString(string s, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number} n\n * @return {boolean}\n */\nvar queryString = function(s, n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer} n\n# @return {Boolean}\ndef query_string(s, n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func queryString(_ s: String, _ n: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func queryString(s string, n int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def queryString(s: String, n: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun queryString(s: String, n: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn query_string(s: String, n: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer $n\n * @return Boolean\n */\n function queryString($s, $n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function queryString(s: string, n: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (query-string s n)\n (-> string? exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1016](https://leetcode-cn.com/problems/binary-string-with-substrings-representing-1-to-n)", "[\u5b50\u4e32\u80fd\u8868\u793a\u4ece 1 \u5230 N \u6570\u5b57\u7684\u4e8c\u8fdb\u5236\u4e32](/solution/1000-1099/1016.Binary%20String%20With%20Substrings%20Representing%201%20To%20N/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1016](https://leetcode.com/problems/binary-string-with-substrings-representing-1-to-n)", "[Binary String With Substrings Representing 1 To N](/solution/1000-1099/1016.Binary%20String%20With%20Substrings%20Representing%201%20To%20N/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "1064", "frontend_question_id": "1015", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/smallest-integer-divisible-by-k", "url_en": "https://leetcode.com/problems/smallest-integer-divisible-by-k", "relative_path_cn": "/solution/1000-1099/1015.Smallest%20Integer%20Divisible%20by%20K/README.md", "relative_path_en": "/solution/1000-1099/1015.Smallest%20Integer%20Divisible%20by%20K/README_EN.md", "title_cn": "\u53ef\u88ab K \u6574\u9664\u7684\u6700\u5c0f\u6574\u6570", "title_en": "Smallest Integer Divisible by K", "question_title_slug": "smallest-integer-divisible-by-k", "content_en": "

Given a positive integer k, you need to find the length of the smallest positive integer n such that n is divisible by k, and n only contains the digit 1.

\n\n

Return the length of n. If there is no such n, return -1.

\n\n

Note: n may not fit in a 64-bit signed integer.

\n\n

 

\n

Example 1:

\n\n
\nInput: k = 1\nOutput: 1\nExplanation: The smallest answer is n = 1, which has length 1.\n
\n\n

Example 2:

\n\n
\nInput: k = 2\nOutput: -1\nExplanation: There is no such positive integer n divisible by 2.\n
\n\n

Example 3:

\n\n
\nInput: k = 3\nOutput: 3\nExplanation: The smallest answer is n = 111, which has length 3.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= k <= 105
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u6b63\u6574\u6570 K\uff0c\u4f60\u9700\u8981\u627e\u51fa\u53ef\u4ee5\u88ab K \u6574\u9664\u7684\u3001\u4ec5\u5305\u542b\u6570\u5b57 1 \u7684\u6700\u5c0f\u6b63\u6574\u6570 N\u3002

\n\n

\u8fd4\u56de N \u7684\u957f\u5ea6\u3002\u5982\u679c\u4e0d\u5b58\u5728\u8fd9\u6837\u7684 N\uff0c\u5c31\u8fd4\u56de -1\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a1\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u6700\u5c0f\u7684\u7b54\u6848\u662f N = 1\uff0c\u5176\u957f\u5ea6\u4e3a 1\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a2\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u4e0d\u5b58\u5728\u53ef\u88ab 2 \u6574\u9664\u7684\u6b63\u6574\u6570 N \u3002
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1a3\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6700\u5c0f\u7684\u7b54\u6848\u662f N = 111\uff0c\u5176\u957f\u5ea6\u4e3a 3\u3002
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= K <= 10^5
  • \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int smallestRepunitDivByK(int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int smallestRepunitDivByK(int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def smallestRepunitDivByK(self, k):\n \"\"\"\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def smallestRepunitDivByK(self, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint smallestRepunitDivByK(int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SmallestRepunitDivByK(int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} k\n * @return {number}\n */\nvar smallestRepunitDivByK = function(k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} k\n# @return {Integer}\ndef smallest_repunit_div_by_k(k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func smallestRepunitDivByK(_ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func smallestRepunitDivByK(k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def smallestRepunitDivByK(k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun smallestRepunitDivByK(k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn smallest_repunit_div_by_k(k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $k\n * @return Integer\n */\n function smallestRepunitDivByK($k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function smallestRepunitDivByK(k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (smallest-repunit-div-by-k k)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1015](https://leetcode-cn.com/problems/smallest-integer-divisible-by-k)", "[\u53ef\u88ab K \u6574\u9664\u7684\u6700\u5c0f\u6574\u6570](/solution/1000-1099/1015.Smallest%20Integer%20Divisible%20by%20K/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1015](https://leetcode.com/problems/smallest-integer-divisible-by-k)", "[Smallest Integer Divisible by K](/solution/1000-1099/1015.Smallest%20Integer%20Divisible%20by%20K/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "1063", "frontend_question_id": "1014", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/best-sightseeing-pair", "url_en": "https://leetcode.com/problems/best-sightseeing-pair", "relative_path_cn": "/solution/1000-1099/1014.Best%20Sightseeing%20Pair/README.md", "relative_path_en": "/solution/1000-1099/1014.Best%20Sightseeing%20Pair/README_EN.md", "title_cn": "\u6700\u4f73\u89c2\u5149\u7ec4\u5408", "title_en": "Best Sightseeing Pair", "question_title_slug": "best-sightseeing-pair", "content_en": "

You are given an integer array values where values[i] represents the value of the ith sightseeing spot. Two sightseeing spots i and j have a distance j - i between them.

\n\n

The score of a pair (i < j) of sightseeing spots is values[i] + values[j] + i - j: the sum of the values of the sightseeing spots, minus the distance between them.

\n\n

Return the maximum score of a pair of sightseeing spots.

\n\n

 

\n

Example 1:

\n\n
\nInput: values = [8,1,5,2,6]\nOutput: 11\nExplanation: i = 0, j = 2, values[i] + values[j] + i - j = 8 + 5 + 0 - 2 = 11\n
\n\n

Example 2:

\n\n
\nInput: values = [1,2]\nOutput: 2\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= values.length <= 5 * 104
  • \n\t
  • 1 <= values[i] <= 1000
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6b63\u6574\u6570\u6570\u7ec4 values\uff0c\u5176\u4e2d values[i]\u00a0\u8868\u793a\u7b2c i \u4e2a\u89c2\u5149\u666f\u70b9\u7684\u8bc4\u5206\uff0c\u5e76\u4e14\u4e24\u4e2a\u666f\u70b9\u00a0i \u548c\u00a0j\u00a0\u4e4b\u95f4\u7684 \u8ddd\u79bb \u4e3a\u00a0j - i\u3002

\n\n

\u4e00\u5bf9\u666f\u70b9\uff08i < j\uff09\u7ec4\u6210\u7684\u89c2\u5149\u7ec4\u5408\u7684\u5f97\u5206\u4e3a values[i] + values[j] + i - j \uff0c\u4e5f\u5c31\u662f\u666f\u70b9\u7684\u8bc4\u5206\u4e4b\u548c \u51cf\u53bb \u5b83\u4eec\u4e24\u8005\u4e4b\u95f4\u7684\u8ddd\u79bb\u3002

\n\n

\u8fd4\u56de\u4e00\u5bf9\u89c2\u5149\u666f\u70b9\u80fd\u53d6\u5f97\u7684\u6700\u9ad8\u5206\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1avalues = [8,1,5,2,6]\n\u8f93\u51fa\uff1a11\n\u89e3\u91ca\uff1ai = 0, j = 2, values[i] + values[j] + i - j = 8 + 5 + 0 - 2 = 11\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1avalues = [1,2]\n\u8f93\u51fa\uff1a2\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= values.length <= 5 * 104
  • \n\t
  • 1 <= values[i] <= 1000
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxScoreSightseeingPair(vector& values) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxScoreSightseeingPair(int[] values) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxScoreSightseeingPair(self, values):\n \"\"\"\n :type values: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxScoreSightseeingPair(self, values: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxScoreSightseeingPair(int* values, int valuesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxScoreSightseeingPair(int[] values) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} values\n * @return {number}\n */\nvar maxScoreSightseeingPair = function(values) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} values\n# @return {Integer}\ndef max_score_sightseeing_pair(values)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxScoreSightseeingPair(_ values: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxScoreSightseeingPair(values []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxScoreSightseeingPair(values: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxScoreSightseeingPair(values: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_score_sightseeing_pair(values: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $values\n * @return Integer\n */\n function maxScoreSightseeingPair($values) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxScoreSightseeingPair(values: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-score-sightseeing-pair values)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1014](https://leetcode-cn.com/problems/best-sightseeing-pair)", "[\u6700\u4f73\u89c2\u5149\u7ec4\u5408](/solution/1000-1099/1014.Best%20Sightseeing%20Pair/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1014](https://leetcode.com/problems/best-sightseeing-pair)", "[Best Sightseeing Pair](/solution/1000-1099/1014.Best%20Sightseeing%20Pair/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "1062", "frontend_question_id": "1013", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/partition-array-into-three-parts-with-equal-sum", "url_en": "https://leetcode.com/problems/partition-array-into-three-parts-with-equal-sum", "relative_path_cn": "/solution/1000-1099/1013.Partition%20Array%20Into%20Three%20Parts%20With%20Equal%20Sum/README.md", "relative_path_en": "/solution/1000-1099/1013.Partition%20Array%20Into%20Three%20Parts%20With%20Equal%20Sum/README_EN.md", "title_cn": "\u5c06\u6570\u7ec4\u5206\u6210\u548c\u76f8\u7b49\u7684\u4e09\u4e2a\u90e8\u5206", "title_en": "Partition Array Into Three Parts With Equal Sum", "question_title_slug": "partition-array-into-three-parts-with-equal-sum", "content_en": "

Given an array of integers arr, return true if we can partition the array into three non-empty parts with equal sums.

\n\n

Formally, we can partition the array if we can find indexes i + 1 < j with (arr[0] + arr[1] + ... + arr[i] == arr[i + 1] + arr[i + 2] + ... + arr[j - 1] == arr[j] + arr[j + 1] + ... + arr[arr.length - 1])

\n\n

 

\n

Example 1:

\n\n
\nInput: arr = [0,2,1,-6,6,-7,9,1,2,0,1]\nOutput: true\nExplanation: 0 + 2 + 1 = -6 + 6 - 7 + 9 + 1 = 2 + 0 + 1\n
\n\n

Example 2:

\n\n
\nInput: arr = [0,2,1,-6,6,7,9,-1,2,0,1]\nOutput: false\n
\n\n

Example 3:

\n\n
\nInput: arr = [3,3,6,5,-2,2,5,1,-9,4]\nOutput: true\nExplanation: 3 + 3 = 6 = 5 - 2 + 2 + 5 + 1 - 9 + 4\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 3 <= arr.length <= 5 * 104
  • \n\t
  • -104 <= arr[i] <= 104
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 A\uff0c\u53ea\u6709\u53ef\u4ee5\u5c06\u5176\u5212\u5206\u4e3a\u4e09\u4e2a\u548c\u76f8\u7b49\u7684\u975e\u7a7a\u90e8\u5206\u65f6\u624d\u8fd4\u56de true\uff0c\u5426\u5219\u8fd4\u56de false\u3002

\n\n

\u5f62\u5f0f\u4e0a\uff0c\u5982\u679c\u53ef\u4ee5\u627e\u51fa\u7d22\u5f15 i+1 < j \u4e14\u6ee1\u8db3 A[0] + A[1] + ... + A[i] == A[i+1] + A[i+2] + ... + A[j-1] == A[j] + A[j-1] + ... + A[A.length - 1] \u5c31\u53ef\u4ee5\u5c06\u6570\u7ec4\u4e09\u7b49\u5206\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a[0,2,1,-6,6,-7,9,1,2,0,1]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a0 + 2 + 1 = -6 + 6 - 7 + 9 + 1 = 2 + 0 + 1\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a[0,2,1,-6,6,7,9,-1,2,0,1]\n\u8f93\u51fa\uff1afalse\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1a[3,3,6,5,-2,2,5,1,-9,4]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a3 + 3 = 6 = 5 - 2 + 2 + 5 + 1 - 9 + 4\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 3 <= A.length <= 50000
  2. \n\t
  3. -10^4 <= A[i] <= 10^4
  4. \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canThreePartsEqualSum(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canThreePartsEqualSum(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canThreePartsEqualSum(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canThreePartsEqualSum(self, arr: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canThreePartsEqualSum(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanThreePartsEqualSum(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {boolean}\n */\nvar canThreePartsEqualSum = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Boolean}\ndef can_three_parts_equal_sum(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canThreePartsEqualSum(_ arr: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canThreePartsEqualSum(arr []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canThreePartsEqualSum(arr: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canThreePartsEqualSum(arr: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_three_parts_equal_sum(arr: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Boolean\n */\n function canThreePartsEqualSum($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canThreePartsEqualSum(arr: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-three-parts-equal-sum arr)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1013](https://leetcode-cn.com/problems/partition-array-into-three-parts-with-equal-sum)", "[\u5c06\u6570\u7ec4\u5206\u6210\u548c\u76f8\u7b49\u7684\u4e09\u4e2a\u90e8\u5206](/solution/1000-1099/1013.Partition%20Array%20Into%20Three%20Parts%20With%20Equal%20Sum/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1013](https://leetcode.com/problems/partition-array-into-three-parts-with-equal-sum)", "[Partition Array Into Three Parts With Equal Sum](/solution/1000-1099/1013.Partition%20Array%20Into%20Three%20Parts%20With%20Equal%20Sum/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1061", "frontend_question_id": "1063", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/number-of-valid-subarrays", "url_en": "https://leetcode.com/problems/number-of-valid-subarrays", "relative_path_cn": "/solution/1000-1099/1063.Number%20of%20Valid%20Subarrays/README.md", "relative_path_en": "/solution/1000-1099/1063.Number%20of%20Valid%20Subarrays/README_EN.md", "title_cn": "\u6709\u6548\u5b50\u6570\u7ec4\u7684\u6570\u76ee", "title_en": "Number of Valid Subarrays", "question_title_slug": "number-of-valid-subarrays", "content_en": "

Given an array nums of integers, return the number of non-empty continuous subarrays that satisfy the following condition:

\n\n

The leftmost element of the subarray is not larger than other elements in the subarray.

\n\n

 

\n\n

Example 1:

\n\n
\nInput: nums = [1,4,2,5,3]\nOutput: 11\nExplanation: There are 11 valid subarrays: [1],[4],[2],[5],[3],[1,4],[2,5],[1,4,2],[2,5,3],[1,4,2,5],[1,4,2,5,3].\n
\n\n

Example 2:

\n\n
\nInput: nums = [3,2,1]\nOutput: 3\nExplanation: The 3 valid subarrays are: [3],[2],[1].\n
\n\n

Example 3:

\n\n
\nInput: nums = [2,2,2]\nOutput: 6\nExplanation: There are 6 valid subarrays: [2],[2],[2],[2,2],[2,2],[2,2,2].\n
\n\n

 

\n\n

Note:

\n\n
    \n\t
  1. 1 <= nums.length <= 50000
  2. \n\t
  3. 0 <= nums[i] <= 100000
  4. \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 A\uff0c\u8fd4\u56de\u6ee1\u8db3\u4e0b\u9762\u6761\u4ef6\u7684 \u975e\u7a7a\u3001\u8fde\u7eed \u5b50\u6570\u7ec4\u7684\u6570\u76ee\uff1a

\n\n

\u5b50\u6570\u7ec4\u4e2d\uff0c\u6700\u5de6\u4fa7\u7684\u5143\u7d20\u4e0d\u5927\u4e8e\u5176\u4ed6\u5143\u7d20\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a[1,4,2,5,3]\n\u8f93\u51fa\uff1a11\n\u89e3\u91ca\uff1a\u6709 11 \u4e2a\u6709\u6548\u5b50\u6570\u7ec4\uff0c\u5206\u522b\u662f\uff1a[1],[4],[2],[5],[3],[1,4],[2,5],[1,4,2],[2,5,3],[1,4,2,5],[1,4,2,5,3] \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a[3,2,1]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6709 3 \u4e2a\u6709\u6548\u5b50\u6570\u7ec4\uff0c\u5206\u522b\u662f\uff1a[3],[2],[1] \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1a[2,2,2]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u6709 6 \u4e2a\u6709\u6548\u5b50\u6570\u7ec4\uff0c\u5206\u522b\u4e3a\u662f\uff1a[2],[2],[2],[2,2],[2,2],[2,2,2] \u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= A.length <= 50000
  2. \n\t
  3. 0 <= A[i] <= 100000
  4. \n
\n", "tags_en": ["Stack"], "tags_cn": ["\u6808"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int validSubarrays(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int validSubarrays(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def validSubarrays(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def validSubarrays(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint validSubarrays(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ValidSubarrays(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar validSubarrays = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef valid_subarrays(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func validSubarrays(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func validSubarrays(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def validSubarrays(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun validSubarrays(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn valid_subarrays(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function validSubarrays($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function validSubarrays(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (valid-subarrays nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1063](https://leetcode-cn.com/problems/number-of-valid-subarrays)", "[\u6709\u6548\u5b50\u6570\u7ec4\u7684\u6570\u76ee](/solution/1000-1099/1063.Number%20of%20Valid%20Subarrays/README.md)", "`\u6808`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1063](https://leetcode.com/problems/number-of-valid-subarrays)", "[Number of Valid Subarrays](/solution/1000-1099/1063.Number%20of%20Valid%20Subarrays/README_EN.md)", "`Stack`", "Hard", "\ud83d\udd12"]}, {"question_id": "1060", "frontend_question_id": "1062", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/longest-repeating-substring", "url_en": "https://leetcode.com/problems/longest-repeating-substring", "relative_path_cn": "/solution/1000-1099/1062.Longest%20Repeating%20Substring/README.md", "relative_path_en": "/solution/1000-1099/1062.Longest%20Repeating%20Substring/README_EN.md", "title_cn": "\u6700\u957f\u91cd\u590d\u5b50\u4e32", "title_en": "Longest Repeating Substring", "question_title_slug": "longest-repeating-substring", "content_en": "

Given a string s, find out the length of the longest repeating substring(s). Return 0 if no repeating substring exists.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "abcd"\nOutput: 0\nExplanation: There is no repeating substring.\n
\n\n

Example 2:

\n\n
\nInput: s = "abbaba"\nOutput: 2\nExplanation: The longest repeating substrings are "ab" and "ba", each of which occurs twice.\n
\n\n

Example 3:

\n\n
\nInput: s = "aabcaabdaab"\nOutput: 3\nExplanation: The longest repeating substring is "aab", which occurs 3 times.\n
\n\n

Example 4:

\n\n
\nInput: s = "aaaaa"\nOutput: 4\nExplanation: The longest repeating substring is "aaaa", which occurs twice.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The string s consists of only lowercase English letters from 'a' - 'z'.
  • \n\t
  • 1 <= s.length <= 1500
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u5b57\u7b26\u4e32 S\uff0c\u627e\u51fa\u6700\u957f\u91cd\u590d\u5b50\u4e32\u7684\u957f\u5ea6\u3002\u5982\u679c\u4e0d\u5b58\u5728\u91cd\u590d\u5b50\u4e32\u5c31\u8fd4\u56de 0\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a"abcd"\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6ca1\u6709\u91cd\u590d\u5b50\u4e32\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a"abbaba"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6700\u957f\u7684\u91cd\u590d\u5b50\u4e32\u4e3a "ab" \u548c "ba"\uff0c\u6bcf\u4e2a\u51fa\u73b0 2 \u6b21\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1a"aabcaabdaab"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6700\u957f\u7684\u91cd\u590d\u5b50\u4e32\u4e3a "aab"\uff0c\u51fa\u73b0 3 \u6b21\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1a"aaaaa"\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u6700\u957f\u7684\u91cd\u590d\u5b50\u4e32\u4e3a "aaaa"\uff0c\u51fa\u73b0 2 \u6b21\u3002
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. \u5b57\u7b26\u4e32 S \u4ec5\u5305\u542b\u4ece 'a' \u5230 'z' \u7684\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
  2. \n\t
  3. 1 <= S.length <= 1500
  4. \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int longestRepeatingSubstring(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int longestRepeatingSubstring(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestRepeatingSubstring(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestRepeatingSubstring(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint longestRepeatingSubstring(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LongestRepeatingSubstring(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar longestRepeatingSubstring = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef longest_repeating_substring(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestRepeatingSubstring(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestRepeatingSubstring(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestRepeatingSubstring(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestRepeatingSubstring(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_repeating_substring(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function longestRepeatingSubstring($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestRepeatingSubstring(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-repeating-substring s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1062](https://leetcode-cn.com/problems/longest-repeating-substring)", "[\u6700\u957f\u91cd\u590d\u5b50\u4e32](/solution/1000-1099/1062.Longest%20Repeating%20Substring/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1062](https://leetcode.com/problems/longest-repeating-substring)", "[Longest Repeating Substring](/solution/1000-1099/1062.Longest%20Repeating%20Substring/README_EN.md)", "`String`", "Medium", "\ud83d\udd12"]}, {"question_id": "1059", "frontend_question_id": "1060", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/missing-element-in-sorted-array", "url_en": "https://leetcode.com/problems/missing-element-in-sorted-array", "relative_path_cn": "/solution/1000-1099/1060.Missing%20Element%20in%20Sorted%20Array/README.md", "relative_path_en": "/solution/1000-1099/1060.Missing%20Element%20in%20Sorted%20Array/README_EN.md", "title_cn": "\u6709\u5e8f\u6570\u7ec4\u4e2d\u7684\u7f3a\u5931\u5143\u7d20", "title_en": "Missing Element in Sorted Array", "question_title_slug": "missing-element-in-sorted-array", "content_en": "

Given an integer array nums which is sorted in ascending order and all of its elements are unique and given also an integer k, return the kth missing number starting from the leftmost number of the array.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [4,7,9,10], k = 1\nOutput: 5\nExplanation: The first missing number is 5.\n
\n\n

Example 2:

\n\n
\nInput: nums = [4,7,9,10], k = 3\nOutput: 8\nExplanation: The missing numbers are [5,6,8,...], hence the third missing number is 8.\n
\n\n

Example 3:

\n\n
\nInput: nums = [1,2,4], k = 3\nOutput: 6\nExplanation: The missing numbers are [3,5,6,7,...], hence the third missing number is 6.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 5 * 104
  • \n\t
  • 1 <= nums[i] <= 107
  • \n\t
  • nums is sorted in ascending order, and all the elements are unique.
  • \n\t
  • 1 <= k <= 108
  • \n
\n\n

 

\nFollow up: Can you find a logarithmic time complexity (i.e., O(log(n))) solution?", "content_cn": "

\u73b0\u6709\u4e00\u4e2a\u6309 \u5347\u5e8f \u6392\u5217\u7684\u6574\u6570\u6570\u7ec4 nums \uff0c\u5176\u4e2d\u6bcf\u4e2a\u6570\u5b57\u90fd \u4e92\u4e0d\u76f8\u540c \u3002

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 k \uff0c\u8bf7\u4f60\u627e\u51fa\u5e76\u8fd4\u56de\u4ece\u6570\u7ec4\u6700\u5de6\u8fb9\u5f00\u59cb\u7684\u7b2c k \u4e2a\u7f3a\u5931\u6570\u5b57\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [4,7,9,10], k = 1\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u7b2c\u4e00\u4e2a\u7f3a\u5931\u6570\u5b57\u4e3a 5 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [4,7,9,10], k = 3\n\u8f93\u51fa\uff1a8\n\u89e3\u91ca\uff1a\u7f3a\u5931\u6570\u5b57\u6709 [5,6,8,...]\uff0c\u56e0\u6b64\u7b2c\u4e09\u4e2a\u7f3a\u5931\u6570\u5b57\u4e3a 8 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [1,2,4], k = 3\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u7f3a\u5931\u6570\u5b57\u6709 [3,5,6,7,...]\uff0c\u56e0\u6b64\u7b2c\u4e09\u4e2a\u7f3a\u5931\u6570\u5b57\u4e3a 6 \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 5 * 104
  • \n\t
  • 1 <= nums[i] <= 107
  • \n\t
  • nums \u6309 \u5347\u5e8f \u6392\u5217\uff0c\u5176\u4e2d\u6240\u6709\u5143\u7d20 \u4e92\u4e0d\u76f8\u540c \u3002
  • \n\t
  • 1 <= k <= 108
  • \n
\n\n

\u00a0

\n\n

\u8fdb\u9636\uff1a\u4f60\u53ef\u4ee5\u8bbe\u8ba1\u4e00\u4e2a\u5bf9\u6570\u65f6\u95f4\u590d\u6742\u5ea6\uff08\u5373\uff0cO(log(n))\uff09\u7684\u89e3\u51b3\u65b9\u6848\u5417\uff1f

\n", "tags_en": ["Binary Search"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int missingElement(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int missingElement(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def missingElement(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def missingElement(self, nums: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint missingElement(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MissingElement(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar missingElement = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef missing_element(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func missingElement(_ nums: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func missingElement(nums []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def missingElement(nums: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun missingElement(nums: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn missing_element(nums: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer\n */\n function missingElement($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function missingElement(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (missing-element nums k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1060](https://leetcode-cn.com/problems/missing-element-in-sorted-array)", "[\u6709\u5e8f\u6570\u7ec4\u4e2d\u7684\u7f3a\u5931\u5143\u7d20](/solution/1000-1099/1060.Missing%20Element%20in%20Sorted%20Array/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1060](https://leetcode.com/problems/missing-element-in-sorted-array)", "[Missing Element in Sorted Array](/solution/1000-1099/1060.Missing%20Element%20in%20Sorted%20Array/README_EN.md)", "`Binary Search`", "Medium", "\ud83d\udd12"]}, {"question_id": "1058", "frontend_question_id": "1061", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/lexicographically-smallest-equivalent-string", "url_en": "https://leetcode.com/problems/lexicographically-smallest-equivalent-string", "relative_path_cn": "/solution/1000-1099/1061.Lexicographically%20Smallest%20Equivalent%20String/README.md", "relative_path_en": "/solution/1000-1099/1061.Lexicographically%20Smallest%20Equivalent%20String/README_EN.md", "title_cn": "\u6309\u5b57\u5178\u5e8f\u6392\u5217\u6700\u5c0f\u7684\u7b49\u6548\u5b57\u7b26\u4e32", "title_en": "Lexicographically Smallest Equivalent String", "question_title_slug": "lexicographically-smallest-equivalent-string", "content_en": "

Given strings s1 and s2 of the same length, we say s1[i] and s2[i] are equivalent characters. For example, if s1 = "abc" and s2 = "cde", then we have 'a' == 'c', 'b' == 'd', 'c' == 'e'.

\n\n

Equivalent characters follow the usual rules of any equivalence relation:

\n\n
    \n\t
  • Reflexivity: 'a' == 'a'
  • \n\t
  • Symmetry: 'a' == 'b' implies 'b' == 'a'
  • \n\t
  • Transitivity: 'a' == 'b' and 'b' == 'c' implies 'a' == 'c'
  • \n
\n\n

For example, given the equivalency information from s1 and s2 above and baseStr = "eed", "acd" and "aab" are equivalent strings of baseStr, and "aab" is the lexicographically smallest equivalent string of baseStr.

\n\n

Return the lexicographically smallest equivalent string of baseStr by using the equivalency information from s1 and s2.

\n\n

 

\n\n

Example 1:

\n\n
\nInput: s1 = "parker", s2 = "morris", baseStr = "parser"\nOutput: "makkek"\nExplanation: Based on the equivalency information in s1 and s2, we can group their characters as [m,p], [a,o], [k,r,s], [e,i]. The characters in each group are equivalent and sorted in lexicographical order. So the answer is "makkek".\n
\n\n

Example 2:

\n\n
\nInput: s1 = "hello", s2 = "world", baseStr = "hold"\nOutput: "hdld"\nExplanation:  Based on the equivalency information in s1 and s2, we can group their characters as [h,w], [d,e,o], [l,r]. So only the second letter 'o' in baseStr is changed to 'd', the answer is "hdld".\n
\n\n

Example 3:

\n\n
\nInput: s1 = "leetcode", s2 = "programs", baseStr = "sourcecode"\nOutput: "aauaaaaada"\nExplanation:  We group the equivalent characters in s1 and s2 as [a,o,e,r,s,c], [l,p], [g,t] and [d,m], thus all letters in baseStr except 'u' and 'd' are transformed to 'a', the answer is "aauaaaaada".\n
\n\n

 

\n\n

Note:

\n\n
    \n\t
  1. Strings s1, s2, and baseStr consist of only lowercase English letters from 'a' - 'z'.
  2. \n\t
  3. The lengths of string s1, s2, and baseStr are between 1 and 1000.
  4. \n\t
  5. Strings s1 and s2 are of the same length.
  6. \n
\n", "content_cn": "

\u7ed9\u51fa\u957f\u5ea6\u76f8\u540c\u7684\u4e24\u4e2a\u5b57\u7b26\u4e32\uff1aA \u548c B\uff0c\u5176\u4e2d A[i] \u548c B[i] \u662f\u4e00\u7ec4\u7b49\u4ef7\u5b57\u7b26\u3002\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u5982\u679c A = "abc" \u4e14 B = "cde"\uff0c\u90a3\u4e48\u5c31\u6709 'a' == 'c', 'b' == 'd', 'c' == 'e'\u3002

\n\n

\u7b49\u4ef7\u5b57\u7b26\u9075\u5faa\u4efb\u4f55\u7b49\u4ef7\u5173\u7cfb\u7684\u4e00\u822c\u89c4\u5219\uff1a

\n\n
    \n\t
  • \u81ea\u53cd\u6027\uff1a'a' == 'a'
  • \n\t
  • \u5bf9\u79f0\u6027\uff1a'a' == 'b' \u5219\u5fc5\u5b9a\u6709 'b' == 'a'
  • \n\t
  • \u4f20\u9012\u6027\uff1a'a' == 'b' \u4e14 'b' == 'c' \u5c31\u8868\u660e 'a' == 'c'
  • \n
\n\n

\u4f8b\u5982\uff0cA \u548c B \u7684\u7b49\u4ef7\u4fe1\u606f\u548c\u4e4b\u524d\u7684\u4f8b\u5b50\u4e00\u6837\uff0c\u90a3\u4e48 S = "eed", "acd" \u6216 "aab"\uff0c\u8fd9\u4e09\u4e2a\u5b57\u7b26\u4e32\u90fd\u662f\u7b49\u4ef7\u7684\uff0c\u800c "aab" \u662f S \u7684\u6309\u5b57\u5178\u5e8f\u6700\u5c0f\u7684\u7b49\u4ef7\u5b57\u7b26\u4e32

\n\n

\u5229\u7528 A \u548c B \u7684\u7b49\u4ef7\u4fe1\u606f\uff0c\u627e\u51fa\u5e76\u8fd4\u56de S \u7684\u6309\u5b57\u5178\u5e8f\u6392\u5217\u6700\u5c0f\u7684\u7b49\u4ef7\u5b57\u7b26\u4e32\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aA = "parker", B = "morris", S = "parser"\n\u8f93\u51fa\uff1a"makkek"\n\u89e3\u91ca\uff1a\u6839\u636e A \u548c B \u4e2d\u7684\u7b49\u4ef7\u4fe1\u606f\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u8fd9\u4e9b\u5b57\u7b26\u5206\u4e3a [m,p], [a,o], [k,r,s], [e,i] \u5171 4 \u7ec4\u3002\u6bcf\u7ec4\u4e2d\u7684\u5b57\u7b26\u90fd\u662f\u7b49\u4ef7\u7684\uff0c\u5e76\u6309\u5b57\u5178\u5e8f\u6392\u5217\u3002\u6240\u4ee5\u7b54\u6848\u662f "makkek"\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aA = "hello", B = "world", S = "hold"\n\u8f93\u51fa\uff1a"hdld"\n\u89e3\u91ca\uff1a\u6839\u636e A \u548c B \u4e2d\u7684\u7b49\u4ef7\u4fe1\u606f\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u8fd9\u4e9b\u5b57\u7b26\u5206\u4e3a [h,w], [d,e,o], [l,r] \u5171 3 \u7ec4\u3002\u6240\u4ee5\u53ea\u6709 S \u4e2d\u7684\u7b2c\u4e8c\u4e2a\u5b57\u7b26 'o' \u53d8\u6210 'd'\uff0c\u6700\u540e\u7b54\u6848\u4e3a "hdld"\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aA = "leetcode", B = "programs", S = "sourcecode"\n\u8f93\u51fa\uff1a"aauaaaaada"\n\u89e3\u91ca\uff1a\u6211\u4eec\u53ef\u4ee5\u628a A \u548c B \u4e2d\u7684\u7b49\u4ef7\u5b57\u7b26\u5206\u4e3a [a,o,e,r,s,c], [l,p], [g,t] \u548c [d,m] \u5171 4 \u7ec4\uff0c\u56e0\u6b64 S \u4e2d\u9664\u4e86 'u' \u548c 'd' \u4e4b\u5916\u7684\u6240\u6709\u5b57\u6bcd\u90fd\u8f6c\u5316\u6210\u4e86 'a'\uff0c\u6700\u540e\u7b54\u6848\u4e3a "aauaaaaada"\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. \u5b57\u7b26\u4e32 A\uff0cB \u548c S \u4ec5\u6709\u4ece 'a' \u5230 'z' \u7684\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\u3002
  2. \n\t
  3. \u5b57\u7b26\u4e32 A\uff0cB \u548c S \u7684\u957f\u5ea6\u5728 1 \u5230 1000 \u4e4b\u95f4\u3002
  4. \n\t
  5. \u5b57\u7b26\u4e32 A \u548c B \u957f\u5ea6\u76f8\u540c\u3002
  6. \n
\n", "tags_en": ["Depth-first Search", "Union Find"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e76\u67e5\u96c6"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string smallestEquivalentString(string s1, string s2, string baseStr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String smallestEquivalentString(String s1, String s2, String baseStr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def smallestEquivalentString(self, s1, s2, baseStr):\n \"\"\"\n :type s1: str\n :type s2: str\n :type baseStr: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def smallestEquivalentString(self, s1: str, s2: str, baseStr: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * smallestEquivalentString(char * s1, char * s2, char * baseStr){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string SmallestEquivalentString(string s1, string s2, string baseStr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s1\n * @param {string} s2\n * @param {string} baseStr\n * @return {string}\n */\nvar smallestEquivalentString = function(s1, s2, baseStr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s1\n# @param {String} s2\n# @param {String} base_str\n# @return {String}\ndef smallest_equivalent_string(s1, s2, base_str)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func smallestEquivalentString(_ s1: String, _ s2: String, _ baseStr: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func smallestEquivalentString(s1 string, s2 string, baseStr string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def smallestEquivalentString(s1: String, s2: String, baseStr: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun smallestEquivalentString(s1: String, s2: String, baseStr: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn smallest_equivalent_string(s1: String, s2: String, base_str: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s1\n * @param String $s2\n * @param String $baseStr\n * @return String\n */\n function smallestEquivalentString($s1, $s2, $baseStr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function smallestEquivalentString(s1: string, s2: string, baseStr: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (smallest-equivalent-string s1 s2 baseStr)\n (-> string? string? string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1061](https://leetcode-cn.com/problems/lexicographically-smallest-equivalent-string)", "[\u6309\u5b57\u5178\u5e8f\u6392\u5217\u6700\u5c0f\u7684\u7b49\u6548\u5b57\u7b26\u4e32](/solution/1000-1099/1061.Lexicographically%20Smallest%20Equivalent%20String/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e76\u67e5\u96c6`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1061](https://leetcode.com/problems/lexicographically-smallest-equivalent-string)", "[Lexicographically Smallest Equivalent String](/solution/1000-1099/1061.Lexicographically%20Smallest%20Equivalent%20String/README_EN.md)", "`Depth-first Search`,`Union Find`", "Medium", "\ud83d\udd12"]}, {"question_id": "1057", "frontend_question_id": "1012", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/numbers-with-repeated-digits", "url_en": "https://leetcode.com/problems/numbers-with-repeated-digits", "relative_path_cn": "/solution/1000-1099/1012.Numbers%20With%20Repeated%20Digits/README.md", "relative_path_en": "/solution/1000-1099/1012.Numbers%20With%20Repeated%20Digits/README_EN.md", "title_cn": "\u81f3\u5c11\u6709 1 \u4f4d\u91cd\u590d\u7684\u6570\u5b57", "title_en": "Numbers With Repeated Digits", "question_title_slug": "numbers-with-repeated-digits", "content_en": "

Given a positive integer n, return the number of positive integers less than or equal to n that have at least 1 repeated digit.

\n\n

 

\n\n
\n

Example 1:

\n\n
\nInput: n = 20\nOutput: 1\nExplanation: The only positive number (<= 20) with at least 1 repeated digit is 11.\n
\n\n
\n

Example 2:

\n\n
\nInput: n = 100\nOutput: 10\nExplanation: The positive numbers (<= 100) with atleast 1 repeated digit are 11, 22, 33, 44, 55, 66, 77, 88, 99, and 100.\n
\n\n
\n

Example 3:

\n\n
\nInput: n = 1000\nOutput: 262\n
\n
\n\n

 

\n\n

Note:

\n\n
    \n\t
  1. 1 <= n <= 109
  2. \n
\n
\n
\n", "content_cn": "

\u7ed9\u5b9a\u6b63\u6574\u6570 N\uff0c\u8fd4\u56de\u5c0f\u4e8e\u7b49\u4e8e N \u4e14\u5177\u6709\u81f3\u5c11 1 \u4f4d\u91cd\u590d\u6570\u5b57\u7684\u6b63\u6574\u6570\u7684\u4e2a\u6570\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a20\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u5177\u6709\u81f3\u5c11 1 \u4f4d\u91cd\u590d\u6570\u5b57\u7684\u6b63\u6570\uff08<= 20\uff09\u53ea\u6709 11 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a100\n\u8f93\u51fa\uff1a10\n\u89e3\u91ca\uff1a\u5177\u6709\u81f3\u5c11 1 \u4f4d\u91cd\u590d\u6570\u5b57\u7684\u6b63\u6570\uff08<= 100\uff09\u6709 11\uff0c22\uff0c33\uff0c44\uff0c55\uff0c66\uff0c77\uff0c88\uff0c99 \u548c 100 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1a1000\n\u8f93\u51fa\uff1a262\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= N <= 10^9
  2. \n
\n", "tags_en": ["Math", "Dynamic Programming"], "tags_cn": ["\u6570\u5b66", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numDupDigitsAtMostN(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numDupDigitsAtMostN(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numDupDigitsAtMostN(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numDupDigitsAtMostN(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numDupDigitsAtMostN(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumDupDigitsAtMostN(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar numDupDigitsAtMostN = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef num_dup_digits_at_most_n(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numDupDigitsAtMostN(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numDupDigitsAtMostN(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numDupDigitsAtMostN(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numDupDigitsAtMostN(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_dup_digits_at_most_n(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function numDupDigitsAtMostN($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numDupDigitsAtMostN(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-dup-digits-at-most-n n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1012](https://leetcode-cn.com/problems/numbers-with-repeated-digits)", "[\u81f3\u5c11\u6709 1 \u4f4d\u91cd\u590d\u7684\u6570\u5b57](/solution/1000-1099/1012.Numbers%20With%20Repeated%20Digits/README.md)", "`\u6570\u5b66`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1012](https://leetcode.com/problems/numbers-with-repeated-digits)", "[Numbers With Repeated Digits](/solution/1000-1099/1012.Numbers%20With%20Repeated%20Digits/README_EN.md)", "`Math`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "1056", "frontend_question_id": "1011", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/capacity-to-ship-packages-within-d-days", "url_en": "https://leetcode.com/problems/capacity-to-ship-packages-within-d-days", "relative_path_cn": "/solution/1000-1099/1011.Capacity%20To%20Ship%20Packages%20Within%20D%20Days/README.md", "relative_path_en": "/solution/1000-1099/1011.Capacity%20To%20Ship%20Packages%20Within%20D%20Days/README_EN.md", "title_cn": "\u5728 D \u5929\u5185\u9001\u8fbe\u5305\u88f9\u7684\u80fd\u529b", "title_en": "Capacity To Ship Packages Within D Days", "question_title_slug": "capacity-to-ship-packages-within-d-days", "content_en": "

A conveyor belt has packages that must be shipped from one port to another within days days.

\n\n

The ith package on the conveyor belt has a weight of weights[i]. Each day, we load the ship with packages on the conveyor belt (in the order given by weights). We may not load more weight than the maximum weight capacity of the ship.

\n\n

Return the least weight capacity of the ship that will result in all the packages on the conveyor belt being shipped within days days.

\n\n

 

\n

Example 1:

\n\n
\nInput: weights = [1,2,3,4,5,6,7,8,9,10], days = 5\nOutput: 15\nExplanation: A ship capacity of 15 is the minimum to ship all the packages in 5 days like this:\n1st day: 1, 2, 3, 4, 5\n2nd day: 6, 7\n3rd day: 8\n4th day: 9\n5th day: 10\n\nNote that the cargo must be shipped in the order given, so using a ship of capacity 14 and splitting the packages into parts like (2, 3, 4, 5), (1, 6, 7), (8), (9), (10) is not allowed.\n
\n\n

Example 2:

\n\n
\nInput: weights = [3,2,2,4,1,4], days = 3\nOutput: 6\nExplanation: A ship capacity of 6 is the minimum to ship all the packages in 3 days like this:\n1st day: 3, 2\n2nd day: 2, 4\n3rd day: 1, 4\n
\n\n

Example 3:

\n\n
\nInput: weights = [1,2,3,1,1], days = 4\nOutput: 3\nExplanation:\n1st day: 1\n2nd day: 2\n3rd day: 3\n4th day: 1, 1\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= days <= weights.length <= 5 * 104
  • \n\t
  • 1 <= weights[i] <= 500
  • \n
\n", "content_cn": "

\u4f20\u9001\u5e26\u4e0a\u7684\u5305\u88f9\u5fc5\u987b\u5728 D \u5929\u5185\u4ece\u4e00\u4e2a\u6e2f\u53e3\u8fd0\u9001\u5230\u53e6\u4e00\u4e2a\u6e2f\u53e3\u3002

\n\n

\u4f20\u9001\u5e26\u4e0a\u7684\u7b2c i\u00a0\u4e2a\u5305\u88f9\u7684\u91cd\u91cf\u4e3a\u00a0weights[i]\u3002\u6bcf\u4e00\u5929\uff0c\u6211\u4eec\u90fd\u4f1a\u6309\u7ed9\u51fa\u91cd\u91cf\u7684\u987a\u5e8f\u5f80\u4f20\u9001\u5e26\u4e0a\u88c5\u8f7d\u5305\u88f9\u3002\u6211\u4eec\u88c5\u8f7d\u7684\u91cd\u91cf\u4e0d\u4f1a\u8d85\u8fc7\u8239\u7684\u6700\u5927\u8fd0\u8f7d\u91cd\u91cf\u3002

\n\n

\u8fd4\u56de\u80fd\u5728 D \u5929\u5185\u5c06\u4f20\u9001\u5e26\u4e0a\u7684\u6240\u6709\u5305\u88f9\u9001\u8fbe\u7684\u8239\u7684\u6700\u4f4e\u8fd0\u8f7d\u80fd\u529b\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aweights = [1,2,3,4,5,6,7,8,9,10], D = 5\n\u8f93\u51fa\uff1a15\n\u89e3\u91ca\uff1a\n\u8239\u8236\u6700\u4f4e\u8f7d\u91cd 15 \u5c31\u80fd\u591f\u5728 5 \u5929\u5185\u9001\u8fbe\u6240\u6709\u5305\u88f9\uff0c\u5982\u4e0b\u6240\u793a\uff1a\n\u7b2c 1 \u5929\uff1a1, 2, 3, 4, 5\n\u7b2c 2 \u5929\uff1a6, 7\n\u7b2c 3 \u5929\uff1a8\n\u7b2c 4 \u5929\uff1a9\n\u7b2c 5 \u5929\uff1a10\n\n\u8bf7\u6ce8\u610f\uff0c\u8d27\u7269\u5fc5\u987b\u6309\u7167\u7ed9\u5b9a\u7684\u987a\u5e8f\u88c5\u8fd0\uff0c\u56e0\u6b64\u4f7f\u7528\u8f7d\u91cd\u80fd\u529b\u4e3a 14 \u7684\u8239\u8236\u5e76\u5c06\u5305\u88c5\u5206\u6210 (2, 3, 4, 5), (1, 6, 7), (8), (9), (10) \u662f\u4e0d\u5141\u8bb8\u7684\u3002 \n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aweights = [3,2,2,4,1,4], D = 3\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\n\u8239\u8236\u6700\u4f4e\u8f7d\u91cd 6 \u5c31\u80fd\u591f\u5728 3 \u5929\u5185\u9001\u8fbe\u6240\u6709\u5305\u88f9\uff0c\u5982\u4e0b\u6240\u793a\uff1a\n\u7b2c 1 \u5929\uff1a3, 2\n\u7b2c 2 \u5929\uff1a2, 4\n\u7b2c 3 \u5929\uff1a1, 4\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1aweights = [1,2,3,1,1], D = 4\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\n\u7b2c 1 \u5929\uff1a1\n\u7b2c 2 \u5929\uff1a2\n\u7b2c 3 \u5929\uff1a3\n\u7b2c 4 \u5929\uff1a1, 1\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= D <= weights.length <= 5 * 104
  • \n\t
  • 1 <= weights[i] <= 500
  • \n
\n", "tags_en": ["Array", "Binary Search"], "tags_cn": ["\u6570\u7ec4", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int shipWithinDays(vector& weights, int days) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int shipWithinDays(int[] weights, int days) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def shipWithinDays(self, weights, days):\n \"\"\"\n :type weights: List[int]\n :type days: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def shipWithinDays(self, weights: List[int], days: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint shipWithinDays(int* weights, int weightsSize, int days){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ShipWithinDays(int[] weights, int days) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} weights\n * @param {number} days\n * @return {number}\n */\nvar shipWithinDays = function(weights, days) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} weights\n# @param {Integer} days\n# @return {Integer}\ndef ship_within_days(weights, days)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func shipWithinDays(_ weights: [Int], _ days: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func shipWithinDays(weights []int, days int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def shipWithinDays(weights: Array[Int], days: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun shipWithinDays(weights: IntArray, days: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn ship_within_days(weights: Vec, days: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $weights\n * @param Integer $days\n * @return Integer\n */\n function shipWithinDays($weights, $days) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function shipWithinDays(weights: number[], days: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (ship-within-days weights days)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1011](https://leetcode-cn.com/problems/capacity-to-ship-packages-within-d-days)", "[\u5728 D \u5929\u5185\u9001\u8fbe\u5305\u88f9\u7684\u80fd\u529b](/solution/1000-1099/1011.Capacity%20To%20Ship%20Packages%20Within%20D%20Days/README.md)", "`\u6570\u7ec4`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1011](https://leetcode.com/problems/capacity-to-ship-packages-within-d-days)", "[Capacity To Ship Packages Within D Days](/solution/1000-1099/1011.Capacity%20To%20Ship%20Packages%20Within%20D%20Days/README_EN.md)", "`Array`,`Binary Search`", "Medium", ""]}, {"question_id": "1055", "frontend_question_id": "1010", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/pairs-of-songs-with-total-durations-divisible-by-60", "url_en": "https://leetcode.com/problems/pairs-of-songs-with-total-durations-divisible-by-60", "relative_path_cn": "/solution/1000-1099/1010.Pairs%20of%20Songs%20With%20Total%20Durations%20Divisible%20by%2060/README.md", "relative_path_en": "/solution/1000-1099/1010.Pairs%20of%20Songs%20With%20Total%20Durations%20Divisible%20by%2060/README_EN.md", "title_cn": "\u603b\u6301\u7eed\u65f6\u95f4\u53ef\u88ab 60 \u6574\u9664\u7684\u6b4c\u66f2", "title_en": "Pairs of Songs With Total Durations Divisible by 60", "question_title_slug": "pairs-of-songs-with-total-durations-divisible-by-60", "content_en": "

You are given a list of songs where the ith song has a duration of time[i] seconds.

\n\n

Return the number of pairs of songs for which their total duration in seconds is divisible by 60. Formally, we want the number of indices i, j such that i < j with (time[i] + time[j]) % 60 == 0.

\n\n

 

\n

Example 1:

\n\n
\nInput: time = [30,20,150,100,40]\nOutput: 3\nExplanation: Three pairs have a total duration divisible by 60:\n(time[0] = 30, time[2] = 150): total duration 180\n(time[1] = 20, time[3] = 100): total duration 120\n(time[1] = 20, time[4] = 40): total duration 60\n
\n\n

Example 2:

\n\n
\nInput: time = [60,60,60]\nOutput: 3\nExplanation: All three pairs have a total duration of 120, which is divisible by 60.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= time.length <= 6 * 104
  • \n\t
  • 1 <= time[i] <= 500
  • \n
\n", "content_cn": "

\u5728\u6b4c\u66f2\u5217\u8868\u4e2d\uff0c\u7b2c i \u9996\u6b4c\u66f2\u7684\u6301\u7eed\u65f6\u95f4\u4e3a time[i] \u79d2\u3002

\n\n

\u8fd4\u56de\u5176\u603b\u6301\u7eed\u65f6\u95f4\uff08\u4ee5\u79d2\u4e3a\u5355\u4f4d\uff09\u53ef\u88ab 60 \u6574\u9664\u7684\u6b4c\u66f2\u5bf9\u7684\u6570\u91cf\u3002\u5f62\u5f0f\u4e0a\uff0c\u6211\u4eec\u5e0c\u671b\u7d22\u5f15\u7684\u6570\u5b57 i \u548c j \u6ee1\u8db3  i < j \u4e14\u6709 (time[i] + time[j]) % 60 == 0\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a[30,20,150,100,40]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u8fd9\u4e09\u5bf9\u7684\u603b\u6301\u7eed\u65f6\u95f4\u53ef\u88ab 60 \u6574\u6570\uff1a\n(time[0] = 30, time[2] = 150): \u603b\u6301\u7eed\u65f6\u95f4 180\n(time[1] = 20, time[3] = 100): \u603b\u6301\u7eed\u65f6\u95f4 120\n(time[1] = 20, time[4] = 40): \u603b\u6301\u7eed\u65f6\u95f4 60\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a[60,60,60]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6240\u6709\u4e09\u5bf9\u7684\u603b\u6301\u7eed\u65f6\u95f4\u90fd\u662f 120\uff0c\u53ef\u4ee5\u88ab 60 \u6574\u6570\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= time.length <= 60000
  2. \n\t
  3. 1 <= time[i] <= 500
  4. \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numPairsDivisibleBy60(vector& time) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numPairsDivisibleBy60(int[] time) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numPairsDivisibleBy60(self, time):\n \"\"\"\n :type time: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numPairsDivisibleBy60(self, time: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numPairsDivisibleBy60(int* time, int timeSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumPairsDivisibleBy60(int[] time) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} time\n * @return {number}\n */\nvar numPairsDivisibleBy60 = function(time) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} time\n# @return {Integer}\ndef num_pairs_divisible_by60(time)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numPairsDivisibleBy60(_ time: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numPairsDivisibleBy60(time []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numPairsDivisibleBy60(time: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numPairsDivisibleBy60(time: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_pairs_divisible_by60(time: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $time\n * @return Integer\n */\n function numPairsDivisibleBy60($time) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numPairsDivisibleBy60(time: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-pairs-divisible-by60 time)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1010](https://leetcode-cn.com/problems/pairs-of-songs-with-total-durations-divisible-by-60)", "[\u603b\u6301\u7eed\u65f6\u95f4\u53ef\u88ab 60 \u6574\u9664\u7684\u6b4c\u66f2](/solution/1000-1099/1010.Pairs%20of%20Songs%20With%20Total%20Durations%20Divisible%20by%2060/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1010](https://leetcode.com/problems/pairs-of-songs-with-total-durations-divisible-by-60)", "[Pairs of Songs With Total Durations Divisible by 60](/solution/1000-1099/1010.Pairs%20of%20Songs%20With%20Total%20Durations%20Divisible%20by%2060/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "1054", "frontend_question_id": "1009", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/complement-of-base-10-integer", "url_en": "https://leetcode.com/problems/complement-of-base-10-integer", "relative_path_cn": "/solution/1000-1099/1009.Complement%20of%20Base%2010%20Integer/README.md", "relative_path_en": "/solution/1000-1099/1009.Complement%20of%20Base%2010%20Integer/README_EN.md", "title_cn": "\u5341\u8fdb\u5236\u6574\u6570\u7684\u53cd\u7801", "title_en": "Complement of Base 10 Integer", "question_title_slug": "complement-of-base-10-integer", "content_en": "

Every non-negative integer n has a binary representation.  For example, 5 can be represented as "101" in binary, 11 as "1011" in binary, and so on.  Note that except for n = 0, there are no leading zeroes in any binary representation.

\n\n

The complement of a binary representation is the number in binary you get when changing every 1 to a 0 and 0 to a 1.  For example, the complement of "101" in binary is "010" in binary.

\n\n

For a given number n in base-10, return the complement of it's binary representation as a base-10 integer.

\n\n

 

\n\n
    \n
\n\n
\n

Example 1:

\n\n
\nInput: n = 5\nOutput: 2\nExplanation: 5 is "101" in binary, with complement "010" in binary, which is 2 in base-10.\n
\n\n
\n

Example 2:

\n\n
\nInput: n = 7\nOutput: 0\nExplanation: 7 is "111" in binary, with complement "000" in binary, which is 0 in base-10.\n
\n\n
\n

Example 3:

\n\n
\nInput: n = 10\nOutput: 5\nExplanation: 10 is "1010" in binary, with complement "0101" in binary, which is 5 in base-10.\n
\n\n

 

\n\n

Note:

\n\n
    \n\t
  1. 0 <= n < 109
  2. \n\t
  3. This question is the same as 476: https://leetcode.com/problems/number-complement/
  4. \n
\n
\n
\n
\n", "content_cn": "

\u6bcf\u4e2a\u975e\u8d1f\u6574\u6570 N \u90fd\u6709\u5176\u4e8c\u8fdb\u5236\u8868\u793a\u3002\u4f8b\u5982\uff0c 5 \u53ef\u4ee5\u88ab\u8868\u793a\u4e3a\u4e8c\u8fdb\u5236 "101"\uff0c11 \u53ef\u4ee5\u7528\u4e8c\u8fdb\u5236 "1011" \u8868\u793a\uff0c\u4f9d\u6b64\u7c7b\u63a8\u3002\u6ce8\u610f\uff0c\u9664 N = 0 \u5916\uff0c\u4efb\u4f55\u4e8c\u8fdb\u5236\u8868\u793a\u4e2d\u90fd\u4e0d\u542b\u524d\u5bfc\u96f6\u3002

\n\n

\u4e8c\u8fdb\u5236\u7684\u53cd\u7801\u8868\u793a\u662f\u5c06\u6bcf\u4e2a 1 \u6539\u4e3a 0 \u4e14\u6bcf\u4e2a 0 \u53d8\u4e3a 1\u3002\u4f8b\u5982\uff0c\u4e8c\u8fdb\u5236\u6570 "101" \u7684\u4e8c\u8fdb\u5236\u53cd\u7801\u4e3a "010"\u3002

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u5341\u8fdb\u5236\u6570 N\uff0c\u8bf7\u4f60\u8fd4\u56de\u5176\u4e8c\u8fdb\u5236\u8868\u793a\u7684\u53cd\u7801\u6240\u5bf9\u5e94\u7684\u5341\u8fdb\u5236\u6574\u6570\u3002

\n\n

 

\n\n
    \n
\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a5\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a5 \u7684\u4e8c\u8fdb\u5236\u8868\u793a\u4e3a "101"\uff0c\u5176\u4e8c\u8fdb\u5236\u53cd\u7801\u4e3a "010"\uff0c\u4e5f\u5c31\u662f\u5341\u8fdb\u5236\u4e2d\u7684 2 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a7\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a7 \u7684\u4e8c\u8fdb\u5236\u8868\u793a\u4e3a "111"\uff0c\u5176\u4e8c\u8fdb\u5236\u53cd\u7801\u4e3a "000"\uff0c\u4e5f\u5c31\u662f\u5341\u8fdb\u5236\u4e2d\u7684 0 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1a10\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a10 \u7684\u4e8c\u8fdb\u5236\u8868\u793a\u4e3a "1010"\uff0c\u5176\u4e8c\u8fdb\u5236\u53cd\u7801\u4e3a "0101"\uff0c\u4e5f\u5c31\u662f\u5341\u8fdb\u5236\u4e2d\u7684 5 \u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 0 <= N < 10^9
  2. \n\t
  3. \u672c\u9898\u4e0e 476\uff1ahttps://leetcode-cn.com/problems/number-complement/ \u76f8\u540c
  4. \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int bitwiseComplement(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int bitwiseComplement(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def bitwiseComplement(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def bitwiseComplement(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint bitwiseComplement(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int BitwiseComplement(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar bitwiseComplement = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef bitwise_complement(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func bitwiseComplement(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func bitwiseComplement(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def bitwiseComplement(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun bitwiseComplement(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn bitwise_complement(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function bitwiseComplement($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function bitwiseComplement(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (bitwise-complement n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1009](https://leetcode-cn.com/problems/complement-of-base-10-integer)", "[\u5341\u8fdb\u5236\u6574\u6570\u7684\u53cd\u7801](/solution/1000-1099/1009.Complement%20of%20Base%2010%20Integer/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[1009](https://leetcode.com/problems/complement-of-base-10-integer)", "[Complement of Base 10 Integer](/solution/1000-1099/1009.Complement%20of%20Base%2010%20Integer/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "1053", "frontend_question_id": "1058", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/minimize-rounding-error-to-meet-target", "url_en": "https://leetcode.com/problems/minimize-rounding-error-to-meet-target", "relative_path_cn": "/solution/1000-1099/1058.Minimize%20Rounding%20Error%20to%20Meet%20Target/README.md", "relative_path_en": "/solution/1000-1099/1058.Minimize%20Rounding%20Error%20to%20Meet%20Target/README_EN.md", "title_cn": "\u6700\u5c0f\u5316\u820d\u5165\u8bef\u5dee\u4ee5\u6ee1\u8db3\u76ee\u6807", "title_en": "Minimize Rounding Error to Meet Target", "question_title_slug": "minimize-rounding-error-to-meet-target", "content_en": "

Given an array of prices [p1,p2...,pn] and a target, round each price pi to Roundi(pi) so that the rounded array [Round1(p1),Round2(p2)...,Roundn(pn)] sums to the given target. Each operation Roundi(pi) could be either Floor(pi) or Ceil(pi).

\n\n

Return the string "-1" if the rounded array is impossible to sum to target. Otherwise, return the smallest rounding error, which is defined as Σ |Roundi(pi) - (pi)| for i from 1 to n, as a string with three places after the decimal.

\n\n

 

\n

Example 1:

\n\n
\nInput: prices = ["0.700","2.800","4.900"], target = 8\nOutput: "1.000"\nExplanation:\nUse Floor, Ceil and Ceil operations to get (0.7 - 0) + (3 - 2.8) + (5 - 4.9) = 0.7 + 0.2 + 0.1 = 1.0 .\n
\n\n

Example 2:

\n\n
\nInput: prices = ["1.500","2.500","3.500"], target = 10\nOutput: "-1"\nExplanation: It is impossible to meet the target.\n
\n\n

Example 3:

\n\n
\nInput: prices = ["1.500","2.500","3.500"], target = 9\nOutput: "1.500"\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= prices.length <= 500
  • \n\t
  • Each string prices[i] represents a real number in the range [0.0, 1000.0] and has exactly 3 decimal places.
  • \n\t
  • 0 <= target <= 106
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u7cfb\u5217\u4ef7\u683c [p1,p2...,pn] \u548c\u4e00\u4e2a\u76ee\u6807 target\uff0c\u5c06\u6bcf\u4e2a\u4ef7\u683c pi \u820d\u5165\u4e3a Roundi(pi) \u4ee5\u4f7f\u5f97\u820d\u5165\u6570\u7ec4 [Round1(p1),Round2(p2)...,Roundn(pn)] \u4e4b\u548c\u8fbe\u5230\u7ed9\u5b9a\u7684\u76ee\u6807\u503c target\u3002\u6bcf\u6b21\u820d\u5165\u64cd\u4f5c Roundi(pi) \u53ef\u4ee5\u662f\u5411\u4e0b\u820d Floor(pi) \u4e5f\u53ef\u4ee5\u662f\u5411\u4e0a\u5165 Ceil(pi)\u3002

\n\n

\u5982\u679c\u820d\u5165\u6570\u7ec4\u4e4b\u548c\u65e0\u8bba\u5982\u4f55\u90fd\u65e0\u6cd5\u8fbe\u5230\u76ee\u6807\u503c target\uff0c\u5c31\u8fd4\u56de -1\u3002\u5426\u5219\uff0c\u4ee5\u4fdd\u7559\u5230\u5c0f\u6570\u70b9\u540e\u4e09\u4f4d\u7684\u5b57\u7b26\u4e32\u683c\u5f0f\u8fd4\u56de\u6700\u5c0f\u7684\u820d\u5165\u8bef\u5dee\uff0c\u5176\u5b9a\u4e49\u4e3a Σ |Roundi(pi) - (pi)|\uff08 i \u4ece 1 \u5230 n \uff09\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aprices = ["0.700","2.800","4.900"], target = 8\n\u8f93\u51fa\uff1a"1.000"\n\u89e3\u91ca\uff1a \n\u4f7f\u7528 Floor\uff0cCeil \u548c Ceil \u64cd\u4f5c\u5f97\u5230 (0.7 - 0) + (3 - 2.8) + (5 - 4.9) = 0.7 + 0.2 + 0.1 = 1.0 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aprices = ["1.500","2.500","3.500"], target = 10\n\u8f93\u51fa\uff1a"-1"\n\u89e3\u91ca\uff1a\n\u8fbe\u5230\u76ee\u6807\u662f\u4e0d\u53ef\u80fd\u7684\u3002
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= prices.length <= 500
  2. \n\t
  3. \u8868\u793a\u4ef7\u683c\u7684\u6bcf\u4e2a\u5b57\u7b26\u4e32 prices[i] \u90fd\u4ee3\u8868\u4e00\u4e2a\u4ecb\u4e8e 0 \u548c 1000 \u4e4b\u95f4\u7684\u5b9e\u6570\uff0c\u5e76\u4e14\u6b63\u597d\u6709 3 \u4e2a\u5c0f\u6570\u4f4d\u3002
  4. \n\t
  5. target \u4ecb\u4e8e 0 \u548c 1000000 \u4e4b\u95f4\u3002
  6. \n
\n", "tags_en": ["Greedy", "Math", "Dynamic Programming"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u5b66", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string minimizeError(vector& prices, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String minimizeError(String[] prices, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimizeError(self, prices, target):\n \"\"\"\n :type prices: List[str]\n :type target: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimizeError(self, prices: List[str], target: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * minimizeError(char ** prices, int pricesSize, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string MinimizeError(string[] prices, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} prices\n * @param {number} target\n * @return {string}\n */\nvar minimizeError = function(prices, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} prices\n# @param {Integer} target\n# @return {String}\ndef minimize_error(prices, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimizeError(_ prices: [String], _ target: Int) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimizeError(prices []string, target int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimizeError(prices: Array[String], target: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimizeError(prices: Array, target: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimize_error(prices: Vec, target: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $prices\n * @param Integer $target\n * @return String\n */\n function minimizeError($prices, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimizeError(prices: string[], target: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimize-error prices target)\n (-> (listof string?) exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1058](https://leetcode-cn.com/problems/minimize-rounding-error-to-meet-target)", "[\u6700\u5c0f\u5316\u820d\u5165\u8bef\u5dee\u4ee5\u6ee1\u8db3\u76ee\u6807](/solution/1000-1099/1058.Minimize%20Rounding%20Error%20to%20Meet%20Target/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u5b66`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1058](https://leetcode.com/problems/minimize-rounding-error-to-meet-target)", "[Minimize Rounding Error to Meet Target](/solution/1000-1099/1058.Minimize%20Rounding%20Error%20to%20Meet%20Target/README_EN.md)", "`Greedy`,`Math`,`Dynamic Programming`", "Medium", "\ud83d\udd12"]}, {"question_id": "1052", "frontend_question_id": "1057", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/campus-bikes", "url_en": "https://leetcode.com/problems/campus-bikes", "relative_path_cn": "/solution/1000-1099/1057.Campus%20Bikes/README.md", "relative_path_en": "/solution/1000-1099/1057.Campus%20Bikes/README_EN.md", "title_cn": "\u6821\u56ed\u81ea\u884c\u8f66\u5206\u914d", "title_en": "Campus Bikes", "question_title_slug": "campus-bikes", "content_en": "

On a campus represented as a 2D grid, there are N workers and M bikes, with N <= M. Each worker and bike is a 2D coordinate on this grid.

\r\n\r\n

Our goal is to assign a bike to each worker. Among the available bikes and workers, we choose the (worker, bike) pair with the shortest Manhattan distance between each other, and assign the bike to that worker. (If there are multiple (worker, bike) pairs with the same shortest Manhattan distance, we choose the pair with the smallest worker index; if there are multiple ways to do that, we choose the pair with the smallest bike index). We repeat this process until there are no available workers.

\r\n\r\n

The Manhattan distance between two points p1 and p2 is Manhattan(p1, p2) = |p1.x - p2.x| + |p1.y - p2.y|.

\r\n\r\n

Return a vector ans of length N, where ans[i] is the index (0-indexed) of the bike that the i-th worker is assigned to.

\r\n\r\n

 

\r\n\r\n

Example 1:

\r\n\r\n

\"\"

\r\n\r\n
\r\nInput: workers = [[0,0],[2,1]], bikes = [[1,2],[3,3]]\r\nOutput: [1,0]\r\nExplanation: \r\nWorker 1 grabs Bike 0 as they are closest (without ties), and Worker 0 is assigned Bike 1. So the output is [1, 0].\r\n
\r\n\r\n

Example 2:

\r\n\r\n

\"\"

\r\n\r\n
\r\nInput: workers = [[0,0],[1,1],[2,0]], bikes = [[1,0],[2,2],[2,1]]\r\nOutput: [0,2,1]\r\nExplanation: \r\nWorker 0 grabs Bike 0 at first. Worker 1 and Worker 2 share the same distance to Bike 2, thus Worker 1 is assigned to Bike 2, and Worker 2 will take Bike 1. So the output is [0,2,1].\r\n
\r\n\r\n

 

\r\n\r\n

Note:

\r\n\r\n
    \r\n\t
  1. 0 <= workers[i][j], bikes[i][j] < 1000
  2. \r\n\t
  3. All worker and bike locations are distinct.
  4. \r\n\t
  5. 1 <= workers.length <= bikes.length <= 1000
  6. \r\n
\r\n", "content_cn": "

\u5728\u7531 2D \u7f51\u683c\u8868\u793a\u7684\u6821\u56ed\u91cc\u6709 n \u4f4d\u5de5\u4eba\uff08worker\uff09\u548c m \u8f86\u81ea\u884c\u8f66\uff08bike\uff09\uff0cn <= m\u3002\u6240\u6709\u5de5\u4eba\u548c\u81ea\u884c\u8f66\u7684\u4f4d\u7f6e\u90fd\u7528\u7f51\u683c\u4e0a\u7684 2D \u5750\u6807\u8868\u793a\u3002

\n\n

\u6211\u4eec\u9700\u8981\u4e3a\u6bcf\u4f4d\u5de5\u4eba\u5206\u914d\u4e00\u8f86\u81ea\u884c\u8f66\u3002\u5728\u6240\u6709\u53ef\u7528\u7684\u81ea\u884c\u8f66\u548c\u5de5\u4eba\u4e2d\uff0c\u6211\u4eec\u9009\u53d6\u5f7c\u6b64\u4e4b\u95f4\u66fc\u54c8\u987f\u8ddd\u79bb\u6700\u77ed\u7684\u5de5\u4eba\u81ea\u884c\u8f66\u5bf9  (worker, bike) \uff0c\u5e76\u5c06\u5176\u4e2d\u7684\u81ea\u884c\u8f66\u5206\u914d\u7d66\u5de5\u4eba\u3002\u5982\u679c\u6709\u591a\u4e2a (worker, bike) \u5bf9\u4e4b\u95f4\u7684\u66fc\u54c8\u987f\u8ddd\u79bb\u76f8\u540c\uff0c\u90a3\u4e48\u6211\u4eec\u9009\u62e9\u5de5\u4eba\u7d22\u5f15\u6700\u5c0f\u7684\u90a3\u5bf9\u3002\u7c7b\u4f3c\u5730\uff0c\u5982\u679c\u6709\u591a\u79cd\u4e0d\u540c\u7684\u5206\u914d\u65b9\u6cd5\uff0c\u5219\u9009\u62e9\u81ea\u884c\u8f66\u7d22\u5f15\u6700\u5c0f\u7684\u4e00\u5bf9\u3002\u4e0d\u65ad\u91cd\u590d\u8fd9\u4e00\u8fc7\u7a0b\uff0c\u76f4\u5230\u6240\u6709\u5de5\u4eba\u90fd\u5206\u914d\u5230\u81ea\u884c\u8f66\u4e3a\u6b62\u3002

\n\n

\u7ed9\u5b9a\u4e24\u70b9 p1 \u548c p2 \u4e4b\u95f4\u7684\u66fc\u54c8\u987f\u8ddd\u79bb\u4e3a Manhattan(p1, p2) = |p1.x - p2.x| + |p1.y - p2.y|\u3002

\n\n

\u8fd4\u56de\u957f\u5ea6\u4e3a n \u7684\u5411\u91cf ans\uff0c\u5176\u4e2d a[i] \u662f\u7b2c i \u4f4d\u5de5\u4eba\u5206\u914d\u5230\u7684\u81ea\u884c\u8f66\u7684\u7d22\u5f15\uff08\u4ece 0 \u5f00\u59cb\uff09\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1aworkers = [[0,0],[2,1]], bikes = [[1,2],[3,3]]\n\u8f93\u51fa\uff1a[1,0]\n\u89e3\u91ca\uff1a\n\u5de5\u4eba 1 \u5206\u914d\u5230\u81ea\u884c\u8f66 0\uff0c\u56e0\u4e3a\u4ed6\u4eec\u6700\u63a5\u8fd1\u4e14\u4e0d\u5b58\u5728\u51b2\u7a81\uff0c\u5de5\u4eba 0 \u5206\u914d\u5230\u81ea\u884c\u8f66 1 \u3002\u6240\u4ee5\u8f93\u51fa\u662f [1,0]\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1aworkers = [[0,0],[1,1],[2,0]], bikes = [[1,0],[2,2],[2,1]]\n\u8f93\u51fa\uff1a[0,2,1]\n\u89e3\u91ca\uff1a\n\u5de5\u4eba 0 \u9996\u5148\u5206\u914d\u5230\u81ea\u884c\u8f66 0 \u3002\u5de5\u4eba 1 \u548c\u5de5\u4eba 2 \u4e0e\u81ea\u884c\u8f66 2 \u8ddd\u79bb\u76f8\u540c\uff0c\u56e0\u6b64\u5de5\u4eba 1 \u5206\u914d\u5230\u81ea\u884c\u8f66 2\uff0c\u5de5\u4eba 2 \u5c06\u5206\u914d\u5230\u81ea\u884c\u8f66 1 \u3002\u56e0\u6b64\u8f93\u51fa\u4e3a [0,2,1]\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 0 <= workers[i][j], bikes[i][j] < 1000
  2. \n\t
  3. \u6240\u6709\u5de5\u4eba\u548c\u81ea\u884c\u8f66\u7684\u4f4d\u7f6e\u90fd\u4e0d\u76f8\u540c\u3002
  4. \n\t
  5. 1 <= workers.length <= bikes.length <= 1000
  6. \n
\n", "tags_en": ["Greedy", "Sort"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6392\u5e8f"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector assignBikes(vector>& workers, vector>& bikes) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] assignBikes(int[][] workers, int[][] bikes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def assignBikes(self, workers, bikes):\n \"\"\"\n :type workers: List[List[int]]\n :type bikes: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def assignBikes(self, workers: List[List[int]], bikes: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* assignBikes(int** workers, int workersSize, int* workersColSize, int** bikes, int bikesSize, int* bikesColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] AssignBikes(int[][] workers, int[][] bikes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} workers\n * @param {number[][]} bikes\n * @return {number[]}\n */\nvar assignBikes = function(workers, bikes) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} workers\n# @param {Integer[][]} bikes\n# @return {Integer[]}\ndef assign_bikes(workers, bikes)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func assignBikes(_ workers: [[Int]], _ bikes: [[Int]]) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func assignBikes(workers [][]int, bikes [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def assignBikes(workers: Array[Array[Int]], bikes: Array[Array[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun assignBikes(workers: Array, bikes: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn assign_bikes(workers: Vec>, bikes: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $workers\n * @param Integer[][] $bikes\n * @return Integer[]\n */\n function assignBikes($workers, $bikes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function assignBikes(workers: number[][], bikes: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (assign-bikes workers bikes)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1057](https://leetcode-cn.com/problems/campus-bikes)", "[\u6821\u56ed\u81ea\u884c\u8f66\u5206\u914d](/solution/1000-1099/1057.Campus%20Bikes/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6392\u5e8f`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1057](https://leetcode.com/problems/campus-bikes)", "[Campus Bikes](/solution/1000-1099/1057.Campus%20Bikes/README_EN.md)", "`Greedy`,`Sort`", "Medium", "\ud83d\udd12"]}, {"question_id": "1051", "frontend_question_id": "1055", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/shortest-way-to-form-string", "url_en": "https://leetcode.com/problems/shortest-way-to-form-string", "relative_path_cn": "/solution/1000-1099/1055.Shortest%20Way%20to%20Form%20String/README.md", "relative_path_en": "/solution/1000-1099/1055.Shortest%20Way%20to%20Form%20String/README_EN.md", "title_cn": "\u5f62\u6210\u5b57\u7b26\u4e32\u7684\u6700\u77ed\u8def\u5f84", "title_en": "Shortest Way to Form String", "question_title_slug": "shortest-way-to-form-string", "content_en": "

From any string, we can form a subsequence of that string by deleting some number of characters (possibly no deletions).

\r\n\r\n

Given two strings source and target, return the minimum number of subsequences of source such that their concatenation equals target. If the task is impossible, return -1.

\r\n\r\n

 

\r\n\r\n

Example 1:

\r\n\r\n
\r\nInput: source = "abc", target = "abcbc"\r\nOutput: 2\r\nExplanation: The target "abcbc" can be formed by "abc" and "bc", which are subsequences of source "abc".\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: source = "abc", target = "acdbc"\r\nOutput: -1\r\nExplanation: The target string cannot be constructed from the subsequences of source string due to the character "d" in target string.\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: source = "xyz", target = "xzyxz"\r\nOutput: 3\r\nExplanation: The target string can be constructed as follows "xz" + "y" + "xz".\r\n
\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • Both the source and target strings consist of only lowercase English letters from "a"-"z".
  • \r\n\t
  • The lengths of source and target string are between 1 and 1000.
  • \r\n
", "content_cn": "

\u5bf9\u4e8e\u4efb\u4f55\u5b57\u7b26\u4e32\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u5220\u9664\u5176\u4e2d\u4e00\u4e9b\u5b57\u7b26\uff08\u4e5f\u53ef\u80fd\u4e0d\u5220\u9664\uff09\u6765\u6784\u9020\u8be5\u5b57\u7b26\u4e32\u7684\u5b50\u5e8f\u5217\u3002

\n\n

\u7ed9\u5b9a\u6e90\u5b57\u7b26\u4e32 source \u548c\u76ee\u6807\u5b57\u7b26\u4e32 target\uff0c\u627e\u51fa\u6e90\u5b57\u7b26\u4e32\u4e2d\u80fd\u901a\u8fc7\u4e32\u8054\u5f62\u6210\u76ee\u6807\u5b57\u7b26\u4e32\u7684\u5b50\u5e8f\u5217\u7684\u6700\u5c0f\u6570\u91cf\u3002\u5982\u679c\u65e0\u6cd5\u901a\u8fc7\u4e32\u8054\u6e90\u5b57\u7b26\u4e32\u4e2d\u7684\u5b50\u5e8f\u5217\u6765\u6784\u9020\u76ee\u6807\u5b57\u7b26\u4e32\uff0c\u5219\u8fd4\u56de -1\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1asource = "abc", target = "abcbc"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u76ee\u6807\u5b57\u7b26\u4e32 "abcbc" \u53ef\u4ee5\u7531 "abc" \u548c "bc" \u5f62\u6210\uff0c\u5b83\u4eec\u90fd\u662f\u6e90\u5b57\u7b26\u4e32 "abc" \u7684\u5b50\u5e8f\u5217\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1asource = "abc", target = "acdbc"\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u7531\u4e8e\u76ee\u6807\u5b57\u7b26\u4e32\u4e2d\u5305\u542b\u5b57\u7b26 "d"\uff0c\u6240\u4ee5\u65e0\u6cd5\u7531\u6e90\u5b57\u7b26\u4e32\u7684\u5b50\u5e8f\u5217\u6784\u5efa\u76ee\u6807\u5b57\u7b26\u4e32\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1asource = "xyz", target = "xzyxz"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u76ee\u6807\u5b57\u7b26\u4e32\u53ef\u4ee5\u6309\u5982\u4e0b\u65b9\u5f0f\u6784\u5efa\uff1a "xz" + "y" + "xz"\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. source \u548c target \u4e24\u4e2a\u5b57\u7b26\u4e32\u90fd\u53ea\u5305\u542b "a"-"z" \u7684\u82f1\u6587\u5c0f\u5199\u5b57\u6bcd\u3002
  2. \n\t
  3. source \u548c target \u4e24\u4e2a\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u4ecb\u4e8e 1 \u548c 1000 \u4e4b\u95f4\u3002
  4. \n
\n", "tags_en": ["Greedy", "Dynamic Programming"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int shortestWay(string source, string target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int shortestWay(String source, String target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def shortestWay(self, source, target):\n \"\"\"\n :type source: str\n :type target: str\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def shortestWay(self, source: str, target: str) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint shortestWay(char * source, char * target){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ShortestWay(string source, string target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} source\n * @param {string} target\n * @return {number}\n */\nvar shortestWay = function(source, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} source\n# @param {String} target\n# @return {Integer}\ndef shortest_way(source, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func shortestWay(_ source: String, _ target: String) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func shortestWay(source string, target string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def shortestWay(source: String, target: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun shortestWay(source: String, target: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn shortest_way(source: String, target: String) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $source\n * @param String $target\n * @return Integer\n */\n function shortestWay($source, $target) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function shortestWay(source: string, target: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (shortest-way source target)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1055](https://leetcode-cn.com/problems/shortest-way-to-form-string)", "[\u5f62\u6210\u5b57\u7b26\u4e32\u7684\u6700\u77ed\u8def\u5f84](/solution/1000-1099/1055.Shortest%20Way%20to%20Form%20String/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1055](https://leetcode.com/problems/shortest-way-to-form-string)", "[Shortest Way to Form String](/solution/1000-1099/1055.Shortest%20Way%20to%20Form%20String/README_EN.md)", "`Greedy`,`Dynamic Programming`", "Medium", "\ud83d\udd12"]}, {"question_id": "1050", "frontend_question_id": "1008", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/construct-binary-search-tree-from-preorder-traversal", "url_en": "https://leetcode.com/problems/construct-binary-search-tree-from-preorder-traversal", "relative_path_cn": "/solution/1000-1099/1008.Construct%20Binary%20Search%20Tree%20from%20Preorder%20Traversal/README.md", "relative_path_en": "/solution/1000-1099/1008.Construct%20Binary%20Search%20Tree%20from%20Preorder%20Traversal/README_EN.md", "title_cn": "\u524d\u5e8f\u904d\u5386\u6784\u9020\u4e8c\u53c9\u641c\u7d22\u6811", "title_en": "Construct Binary Search Tree from Preorder Traversal", "question_title_slug": "construct-binary-search-tree-from-preorder-traversal", "content_en": "

Given an array of integers preorder, which represents the preorder traversal of a BST (i.e., binary search tree), construct the tree and return its root.

\n\n

It is guaranteed that there is always possible to find a binary search tree with the given requirements for the given test cases.

\n\n

A binary search tree is a binary tree where for every node, any descendant of Node.left has a value strictly less than Node.val, and any descendant of Node.right has a value strictly greater than Node.val.

\n\n

A preorder traversal of a binary tree displays the value of the node first, then traverses Node.left, then traverses Node.right.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: preorder = [8,5,1,7,10,12]\nOutput: [8,5,10,1,7,null,12]\n
\n\n

Example 2:

\n\n
\nInput: preorder = [1,3]\nOutput: [1,null,3]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= preorder.length <= 100
  • \n\t
  • 1 <= preorder[i] <= 108
  • \n\t
  • All the values of preorder are unique.
  • \n
\n", "content_cn": "

\u8fd4\u56de\u4e0e\u7ed9\u5b9a\u524d\u5e8f\u904d\u5386 preorder \u76f8\u5339\u914d\u7684\u4e8c\u53c9\u641c\u7d22\u6811\uff08binary search tree\uff09\u7684\u6839\u7ed3\u70b9\u3002

\n\n

(\u56de\u60f3\u4e00\u4e0b\uff0c\u4e8c\u53c9\u641c\u7d22\u6811\u662f\u4e8c\u53c9\u6811\u7684\u4e00\u79cd\uff0c\u5176\u6bcf\u4e2a\u8282\u70b9\u90fd\u6ee1\u8db3\u4ee5\u4e0b\u89c4\u5219\uff0c\u5bf9\u4e8e node.left \u7684\u4efb\u4f55\u540e\u4ee3\uff0c\u503c\u603b < node.val\uff0c\u800c node.right \u7684\u4efb\u4f55\u540e\u4ee3\uff0c\u503c\u603b > node.val\u3002\u6b64\u5916\uff0c\u524d\u5e8f\u904d\u5386\u9996\u5148\u663e\u793a\u8282\u70b9 node \u7684\u503c\uff0c\u7136\u540e\u904d\u5386 node.left\uff0c\u63a5\u7740\u904d\u5386 node.right\u3002\uff09

\n\n

\u9898\u76ee\u4fdd\u8bc1\uff0c\u5bf9\u4e8e\u7ed9\u5b9a\u7684\u6d4b\u8bd5\u7528\u4f8b\uff0c\u603b\u80fd\u627e\u5230\u6ee1\u8db3\u8981\u6c42\u7684\u4e8c\u53c9\u641c\u7d22\u6811\u3002

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1a[8,5,1,7,10,12]\n\u8f93\u51fa\uff1a[8,5,10,1,7,null,12]\n\"\"\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= preorder.length <= 100
  • \n\t
  • 1 <= preorder[i] <= 10^8
  • \n\t
  • preorder \u4e2d\u7684\u503c\u4e92\u4e0d\u76f8\u540c
  • \n
\n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* bstFromPreorder(vector& preorder) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode bstFromPreorder(int[] preorder) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def bstFromPreorder(self, preorder):\n \"\"\"\n :type preorder: List[int]\n :rtype: TreeNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def bstFromPreorder(self, preorder: List[int]) -> TreeNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* bstFromPreorder(int* preorder, int preorderSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode BstFromPreorder(int[] preorder) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {number[]} preorder\n * @return {TreeNode}\n */\nvar bstFromPreorder = function(preorder) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {Integer[]} preorder\n# @return {TreeNode}\ndef bst_from_preorder(preorder)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func bstFromPreorder(_ preorder: [Int]) -> TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc bstFromPreorder(preorder []int) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def bstFromPreorder(preorder: Array[Int]): TreeNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun bstFromPreorder(preorder: IntArray): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn bst_from_preorder(preorder: Vec) -> Option>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param Integer[] $preorder\n * @return TreeNode\n */\n function bstFromPreorder($preorder) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction bstFromPreorder(preorder: number[]): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (bst-from-preorder preorder)\n (-> (listof exact-integer?) (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1008](https://leetcode-cn.com/problems/construct-binary-search-tree-from-preorder-traversal)", "[\u524d\u5e8f\u904d\u5386\u6784\u9020\u4e8c\u53c9\u641c\u7d22\u6811](/solution/1000-1099/1008.Construct%20Binary%20Search%20Tree%20from%20Preorder%20Traversal/README.md)", "`\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1008](https://leetcode.com/problems/construct-binary-search-tree-from-preorder-traversal)", "[Construct Binary Search Tree from Preorder Traversal](/solution/1000-1099/1008.Construct%20Binary%20Search%20Tree%20from%20Preorder%20Traversal/README_EN.md)", "`Tree`", "Medium", ""]}, {"question_id": "1049", "frontend_question_id": "1007", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-domino-rotations-for-equal-row", "url_en": "https://leetcode.com/problems/minimum-domino-rotations-for-equal-row", "relative_path_cn": "/solution/1000-1099/1007.Minimum%20Domino%20Rotations%20For%20Equal%20Row/README.md", "relative_path_en": "/solution/1000-1099/1007.Minimum%20Domino%20Rotations%20For%20Equal%20Row/README_EN.md", "title_cn": "\u884c\u76f8\u7b49\u7684\u6700\u5c11\u591a\u7c73\u8bfa\u65cb\u8f6c", "title_en": "Minimum Domino Rotations For Equal Row", "question_title_slug": "minimum-domino-rotations-for-equal-row", "content_en": "

In a row of dominoes, tops[i] and bottoms[i] represent the top and bottom halves of the ith domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)

\n\n

We may rotate the ith domino, so that tops[i] and bottoms[i] swap values.

\n\n

Return the minimum number of rotations so that all the values in tops are the same, or all the values in bottoms are the same.

\n\n

If it cannot be done, return -1.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: tops = [2,1,2,4,2,2], bottoms = [5,2,6,2,3,2]\nOutput: 2\nExplanation: \nThe first figure represents the dominoes as given by tops and bottoms: before we do any rotations.\nIf we rotate the second and fourth dominoes, we can make every value in the top row equal to 2, as indicated by the second figure.\n
\n\n

Example 2:

\n\n
\nInput: tops = [3,5,1,2,3], bottoms = [3,6,3,3,4]\nOutput: -1\nExplanation: \nIn this case, it is not possible to rotate the dominoes to make one row of values equal.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= tops.length == bottoms.length <= 2 * 104
  • \n\t
  • 1 <= tops[i], bottoms[i] <= 6
  • \n
\n", "content_cn": "

\u5728\u4e00\u6392\u591a\u7c73\u8bfa\u9aa8\u724c\u4e2d\uff0cA[i] \u548c B[i] \u5206\u522b\u4ee3\u8868\u7b2c i \u4e2a\u591a\u7c73\u8bfa\u9aa8\u724c\u7684\u4e0a\u534a\u90e8\u5206\u548c\u4e0b\u534a\u90e8\u5206\u3002\uff08\u4e00\u4e2a\u591a\u7c73\u8bfa\u662f\u4e24\u4e2a\u4ece 1 \u5230 6 \u7684\u6570\u5b57\u540c\u5217\u5e73\u94fa\u5f62\u6210\u7684 —— \u8be5\u5e73\u94fa\u7684\u6bcf\u4e00\u534a\u4e0a\u90fd\u6709\u4e00\u4e2a\u6570\u5b57\u3002\uff09

\n\n

\u6211\u4eec\u53ef\u4ee5\u65cb\u8f6c\u7b2c i \u5f20\u591a\u7c73\u8bfa\uff0c\u4f7f\u5f97 A[i] \u548c B[i] \u7684\u503c\u4ea4\u6362\u3002

\n\n

\u8fd4\u56de\u80fd\u4f7f A \u4e2d\u6240\u6709\u503c\u6216\u8005 B \u4e2d\u6240\u6709\u503c\u90fd\u76f8\u540c\u7684\u6700\u5c0f\u65cb\u8f6c\u6b21\u6570\u3002

\n\n

\u5982\u679c\u65e0\u6cd5\u505a\u5230\uff0c\u8fd4\u56de -1.

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1aA = [2,1,2,4,2,2], B = [5,2,6,2,3,2]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n\u56fe\u4e00\u8868\u793a\uff1a\u5728\u6211\u4eec\u65cb\u8f6c\u4e4b\u524d\uff0c A \u548c B \u7ed9\u51fa\u7684\u591a\u7c73\u8bfa\u724c\u3002\n\u5982\u679c\u6211\u4eec\u65cb\u8f6c\u7b2c\u4e8c\u4e2a\u548c\u7b2c\u56db\u4e2a\u591a\u7c73\u8bfa\u9aa8\u724c\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u4e0a\u9762\u4e00\u884c\u4e2d\u7684\u6bcf\u4e2a\u503c\u90fd\u7b49\u4e8e 2\uff0c\u5982\u56fe\u4e8c\u6240\u793a\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aA = [3,5,1,2,3], B = [3,6,3,3,4]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\n\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u4e0d\u53ef\u80fd\u65cb\u8f6c\u591a\u7c73\u8bfa\u724c\u4f7f\u4e00\u884c\u7684\u503c\u76f8\u7b49\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= A[i], B[i] <= 6
  2. \n\t
  3. 2 <= A.length == B.length <= 20000
  4. \n
\n", "tags_en": ["Greedy", "Array"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minDominoRotations(vector& tops, vector& bottoms) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minDominoRotations(int[] tops, int[] bottoms) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minDominoRotations(self, tops, bottoms):\n \"\"\"\n :type tops: List[int]\n :type bottoms: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minDominoRotations(self, tops: List[int], bottoms: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minDominoRotations(int* tops, int topsSize, int* bottoms, int bottomsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinDominoRotations(int[] tops, int[] bottoms) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} tops\n * @param {number[]} bottoms\n * @return {number}\n */\nvar minDominoRotations = function(tops, bottoms) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} tops\n# @param {Integer[]} bottoms\n# @return {Integer}\ndef min_domino_rotations(tops, bottoms)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minDominoRotations(_ tops: [Int], _ bottoms: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minDominoRotations(tops []int, bottoms []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minDominoRotations(tops: Array[Int], bottoms: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minDominoRotations(tops: IntArray, bottoms: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_domino_rotations(tops: Vec, bottoms: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $tops\n * @param Integer[] $bottoms\n * @return Integer\n */\n function minDominoRotations($tops, $bottoms) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minDominoRotations(tops: number[], bottoms: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-domino-rotations tops bottoms)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1007](https://leetcode-cn.com/problems/minimum-domino-rotations-for-equal-row)", "[\u884c\u76f8\u7b49\u7684\u6700\u5c11\u591a\u7c73\u8bfa\u65cb\u8f6c](/solution/1000-1099/1007.Minimum%20Domino%20Rotations%20For%20Equal%20Row/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1007](https://leetcode.com/problems/minimum-domino-rotations-for-equal-row)", "[Minimum Domino Rotations For Equal Row](/solution/1000-1099/1007.Minimum%20Domino%20Rotations%20For%20Equal%20Row/README_EN.md)", "`Greedy`,`Array`", "Medium", ""]}, {"question_id": "1048", "frontend_question_id": "1006", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/clumsy-factorial", "url_en": "https://leetcode.com/problems/clumsy-factorial", "relative_path_cn": "/solution/1000-1099/1006.Clumsy%20Factorial/README.md", "relative_path_en": "/solution/1000-1099/1006.Clumsy%20Factorial/README_EN.md", "title_cn": "\u7b28\u9636\u4e58", "title_en": "Clumsy Factorial", "question_title_slug": "clumsy-factorial", "content_en": "

Normally, the factorial of a positive integer n is the product of all positive integers less than or equal to n.  For example, factorial(10) = 10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1.

\n\n

We instead make a clumsy factorial: using the integers in decreasing order, we swap out the multiply operations for a fixed rotation of operations: multiply (*), divide (/), add (+) and subtract (-) in this order.

\n\n

For example, clumsy(10) = 10 * 9 / 8 + 7 - 6 * 5 / 4 + 3 - 2 * 1.  However, these operations are still applied using the usual order of operations of arithmetic: we do all multiplication and division steps before any addition or subtraction steps, and multiplication and division steps are processed left to right.

\n\n

Additionally, the division that we use is floor division such that 10 * 9 / 8 equals 11.  This guarantees the result is an integer.

\n\n

Implement the clumsy function as defined above: given an integer n, it returns the clumsy factorial of n.

\n\n

 

\n\n

Example 1:

\n\n
\nInput: n = 4\nOutput: 7\nExplanation: 7 = 4 * 3 / 2 + 1\n
\n\n

Example 2:

\n\n
\nInput: n = 10\nOutput: 12\nExplanation: 12 = 10 * 9 / 8 + 7 - 6 * 5 / 4 + 3 - 2 * 1\n
\n\n

 

\n\n

Note:

\n\n
    \n\t
  1. 1 <= n <= 10000
  2. \n\t
  3. -231 <= answer <= 231 - 1  (The answer is guaranteed to fit within a 32-bit integer.)
  4. \n
\n", "content_cn": "

\u901a\u5e38\uff0c\u6b63\u6574\u6570 n \u7684\u9636\u4e58\u662f\u6240\u6709\u5c0f\u4e8e\u6216\u7b49\u4e8e n \u7684\u6b63\u6574\u6570\u7684\u4e58\u79ef\u3002\u4f8b\u5982\uff0cfactorial(10) = 10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1\u3002

\n\n

\u76f8\u53cd\uff0c\u6211\u4eec\u8bbe\u8ba1\u4e86\u4e00\u4e2a\u7b28\u9636\u4e58 clumsy\uff1a\u5728\u6574\u6570\u7684\u9012\u51cf\u5e8f\u5217\u4e2d\uff0c\u6211\u4eec\u4ee5\u4e00\u4e2a\u56fa\u5b9a\u987a\u5e8f\u7684\u64cd\u4f5c\u7b26\u5e8f\u5217\u6765\u4f9d\u6b21\u66ff\u6362\u539f\u6709\u7684\u4e58\u6cd5\u64cd\u4f5c\u7b26\uff1a\u4e58\u6cd5(*)\uff0c\u9664\u6cd5(/)\uff0c\u52a0\u6cd5(+)\u548c\u51cf\u6cd5(-)\u3002

\n\n

\u4f8b\u5982\uff0cclumsy(10) = 10 * 9 / 8 + 7 - 6 * 5 / 4 + 3 - 2 * 1\u3002\u7136\u800c\uff0c\u8fd9\u4e9b\u8fd0\u7b97\u4ecd\u7136\u4f7f\u7528\u901a\u5e38\u7684\u7b97\u672f\u8fd0\u7b97\u987a\u5e8f\uff1a\u6211\u4eec\u5728\u4efb\u4f55\u52a0\u3001\u51cf\u6b65\u9aa4\u4e4b\u524d\u6267\u884c\u6240\u6709\u7684\u4e58\u6cd5\u548c\u9664\u6cd5\u6b65\u9aa4\uff0c\u5e76\u4e14\u6309\u4ece\u5de6\u5230\u53f3\u5904\u7406\u4e58\u6cd5\u548c\u9664\u6cd5\u6b65\u9aa4\u3002

\n\n

\u53e6\u5916\uff0c\u6211\u4eec\u4f7f\u7528\u7684\u9664\u6cd5\u662f\u5730\u677f\u9664\u6cd5\uff08floor division\uff09\uff0c\u6240\u4ee5 10 * 9 / 8 \u7b49\u4e8e 11\u3002\u8fd9\u4fdd\u8bc1\u7ed3\u679c\u662f\u4e00\u4e2a\u6574\u6570\u3002

\n\n

\u5b9e\u73b0\u4e0a\u9762\u5b9a\u4e49\u7684\u7b28\u51fd\u6570\uff1a\u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570 N\uff0c\u5b83\u8fd4\u56de N \u7684\u7b28\u9636\u4e58\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a4\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a7 = 4 * 3 / 2 + 1\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a10\n\u8f93\u51fa\uff1a12\n\u89e3\u91ca\uff1a12 = 10 * 9 / 8 + 7 - 6 * 5 / 4 + 3 - 2 * 1\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= N <= 10000
  2. \n\t
  3. -2^31 <= answer <= 2^31 - 1  \uff08\u7b54\u6848\u4fdd\u8bc1\u7b26\u5408 32 \u4f4d\u6574\u6570\u3002\uff09
  4. \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int clumsy(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int clumsy(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def clumsy(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def clumsy(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint clumsy(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int Clumsy(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar clumsy = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef clumsy(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func clumsy(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func clumsy(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def clumsy(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun clumsy(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn clumsy(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function clumsy($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function clumsy(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (clumsy n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1006](https://leetcode-cn.com/problems/clumsy-factorial)", "[\u7b28\u9636\u4e58](/solution/1000-1099/1006.Clumsy%20Factorial/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1006](https://leetcode.com/problems/clumsy-factorial)", "[Clumsy Factorial](/solution/1000-1099/1006.Clumsy%20Factorial/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "1047", "frontend_question_id": "1005", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximize-sum-of-array-after-k-negations", "url_en": "https://leetcode.com/problems/maximize-sum-of-array-after-k-negations", "relative_path_cn": "/solution/1000-1099/1005.Maximize%20Sum%20Of%20Array%20After%20K%20Negations/README.md", "relative_path_en": "/solution/1000-1099/1005.Maximize%20Sum%20Of%20Array%20After%20K%20Negations/README_EN.md", "title_cn": "K \u6b21\u53d6\u53cd\u540e\u6700\u5927\u5316\u7684\u6570\u7ec4\u548c", "title_en": "Maximize Sum Of Array After K Negations", "question_title_slug": "maximize-sum-of-array-after-k-negations", "content_en": "

Given an array nums of integers, we must modify the array in the following way: we choose an i and replace nums[i] with -nums[i], and we repeat this process k times in total.  (We may choose the same index i multiple times.)

\n\n

Return the largest possible sum of the array after modifying it in this way.

\n\n

 

\n\n

Example 1:

\n\n
\nInput: nums = [4,2,3], k = 1\nOutput: 5\nExplanation: Choose indices (1,) and nums becomes [4,-2,3].\n
\n\n
\n

Example 2:

\n\n
\nInput: nums = [3,-1,0,2], k = 3\nOutput: 6\nExplanation: Choose indices (1, 2, 2) and nums becomes [3,1,0,2].\n
\n\n
\n

Example 3:

\n\n
\nInput: nums = [2,-3,-1,5,-4], k = 2\nOutput: 13\nExplanation: Choose indices (1, 4) and nums becomes [2,3,-1,5,4].\n
\n
\n
\n\n

 

\n\n

Note:

\n\n
    \n\t
  1. 1 <= nums.length <= 10000
  2. \n\t
  3. 1 <= k <= 10000
  4. \n\t
  5. -100 <= nums[i] <= 100
  6. \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 A\uff0c\u6211\u4eec\u53ea\u80fd\u7528\u4ee5\u4e0b\u65b9\u6cd5\u4fee\u6539\u8be5\u6570\u7ec4\uff1a\u6211\u4eec\u9009\u62e9\u67d0\u4e2a\u7d22\u5f15 i \u5e76\u5c06 A[i] \u66ff\u6362\u4e3a -A[i]\uff0c\u7136\u540e\u603b\u5171\u91cd\u590d\u8fd9\u4e2a\u8fc7\u7a0b K \u6b21\u3002\uff08\u6211\u4eec\u53ef\u4ee5\u591a\u6b21\u9009\u62e9\u540c\u4e00\u4e2a\u7d22\u5f15 i\u3002\uff09

\n\n

\u4ee5\u8fd9\u79cd\u65b9\u5f0f\u4fee\u6539\u6570\u7ec4\u540e\uff0c\u8fd4\u56de\u6570\u7ec4\u53ef\u80fd\u7684\u6700\u5927\u548c\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aA = [4,2,3], K = 1\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u9009\u62e9\u7d22\u5f15 (1,) \uff0c\u7136\u540e A \u53d8\u4e3a [4,-2,3]\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aA = [3,-1,0,2], K = 3\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u9009\u62e9\u7d22\u5f15 (1, 2, 2) \uff0c\u7136\u540e A \u53d8\u4e3a [3,1,0,2]\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aA = [2,-3,-1,5,-4], K = 2\n\u8f93\u51fa\uff1a13\n\u89e3\u91ca\uff1a\u9009\u62e9\u7d22\u5f15 (1, 4) \uff0c\u7136\u540e A \u53d8\u4e3a [2,3,-1,5,4]\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= A.length <= 10000
  2. \n\t
  3. 1 <= K <= 10000
  4. \n\t
  5. -100 <= A[i] <= 100
  6. \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int largestSumAfterKNegations(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int largestSumAfterKNegations(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def largestSumAfterKNegations(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def largestSumAfterKNegations(self, nums: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint largestSumAfterKNegations(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LargestSumAfterKNegations(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar largestSumAfterKNegations = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef largest_sum_after_k_negations(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func largestSumAfterKNegations(_ nums: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func largestSumAfterKNegations(nums []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def largestSumAfterKNegations(nums: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun largestSumAfterKNegations(nums: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn largest_sum_after_k_negations(nums: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer\n */\n function largestSumAfterKNegations($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function largestSumAfterKNegations(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (largest-sum-after-k-negations nums k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1005](https://leetcode-cn.com/problems/maximize-sum-of-array-after-k-negations)", "[K \u6b21\u53d6\u53cd\u540e\u6700\u5927\u5316\u7684\u6570\u7ec4\u548c](/solution/1000-1099/1005.Maximize%20Sum%20Of%20Array%20After%20K%20Negations/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u7b80\u5355", ""], "md_table_row_en": ["[1005](https://leetcode.com/problems/maximize-sum-of-array-after-k-negations)", "[Maximize Sum Of Array After K Negations](/solution/1000-1099/1005.Maximize%20Sum%20Of%20Array%20After%20K%20Negations/README_EN.md)", "`Greedy`", "Easy", ""]}, {"question_id": "1046", "frontend_question_id": "1004", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/max-consecutive-ones-iii", "url_en": "https://leetcode.com/problems/max-consecutive-ones-iii", "relative_path_cn": "/solution/1000-1099/1004.Max%20Consecutive%20Ones%20III/README.md", "relative_path_en": "/solution/1000-1099/1004.Max%20Consecutive%20Ones%20III/README_EN.md", "title_cn": "\u6700\u5927\u8fde\u7eed1\u7684\u4e2a\u6570 III", "title_en": "Max Consecutive Ones III", "question_title_slug": "max-consecutive-ones-iii", "content_en": "

Given a binary array nums and an integer k, return the maximum number of consecutive 1's in the array if you can flip at most k 0's.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [1,1,1,0,0,0,1,1,1,1,0], k = 2\nOutput: 6\nExplanation: [1,1,1,0,0,1,1,1,1,1,1]\nBolded numbers were flipped from 0 to 1. The longest subarray is underlined.
\n\n

Example 2:

\n\n
\nInput: nums = [0,0,1,1,0,0,1,1,1,0,1,1,0,0,0,1,1,1,1], k = 3\nOutput: 10\nExplanation: [0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1]\nBolded numbers were flipped from 0 to 1. The longest subarray is underlined.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 105
  • \n\t
  • nums[i] is either 0 or 1.
  • \n\t
  • 0 <= k <= nums.length
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u7531\u82e5\u5e72 0 \u548c 1 \u7ec4\u6210\u7684\u6570\u7ec4 A\uff0c\u6211\u4eec\u6700\u591a\u53ef\u4ee5\u5c06 K \u4e2a\u503c\u4ece 0 \u53d8\u6210 1 \u3002

\n\n

\u8fd4\u56de\u4ec5\u5305\u542b 1 \u7684\u6700\u957f\uff08\u8fde\u7eed\uff09\u5b50\u6570\u7ec4\u7684\u957f\u5ea6\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aA = [1,1,1,0,0,0,1,1,1,1,0], K = 2\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a \n[1,1,1,0,0,1,1,1,1,1,1]\n\u7c97\u4f53\u6570\u5b57\u4ece 0 \u7ffb\u8f6c\u5230 1\uff0c\u6700\u957f\u7684\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 6\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aA = [0,0,1,1,0,0,1,1,1,0,1,1,0,0,0,1,1,1,1], K = 3\n\u8f93\u51fa\uff1a10\n\u89e3\u91ca\uff1a\n[0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1]\n\u7c97\u4f53\u6570\u5b57\u4ece 0 \u7ffb\u8f6c\u5230 1\uff0c\u6700\u957f\u7684\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 10\u3002
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= A.length <= 20000
  2. \n\t
  3. 0 <= K <= A.length
  4. \n\t
  5. A[i] \u4e3a 0 \u6216 1 
  6. \n
\n", "tags_en": ["Two Pointers", "Sliding Window"], "tags_cn": ["\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int longestOnes(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int longestOnes(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestOnes(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestOnes(self, nums: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint longestOnes(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LongestOnes(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar longestOnes = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef longest_ones(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestOnes(_ nums: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestOnes(nums []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestOnes(nums: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestOnes(nums: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_ones(nums: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer\n */\n function longestOnes($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestOnes(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-ones nums k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1004](https://leetcode-cn.com/problems/max-consecutive-ones-iii)", "[\u6700\u5927\u8fde\u7eed1\u7684\u4e2a\u6570 III](/solution/1000-1099/1004.Max%20Consecutive%20Ones%20III/README.md)", "`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1004](https://leetcode.com/problems/max-consecutive-ones-iii)", "[Max Consecutive Ones III](/solution/1000-1099/1004.Max%20Consecutive%20Ones%20III/README_EN.md)", "`Two Pointers`,`Sliding Window`", "Medium", ""]}, {"question_id": "1045", "frontend_question_id": "1003", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/check-if-word-is-valid-after-substitutions", "url_en": "https://leetcode.com/problems/check-if-word-is-valid-after-substitutions", "relative_path_cn": "/solution/1000-1099/1003.Check%20If%20Word%20Is%20Valid%20After%20Substitutions/README.md", "relative_path_en": "/solution/1000-1099/1003.Check%20If%20Word%20Is%20Valid%20After%20Substitutions/README_EN.md", "title_cn": "\u68c0\u67e5\u66ff\u6362\u540e\u7684\u8bcd\u662f\u5426\u6709\u6548", "title_en": "Check If Word Is Valid After Substitutions", "question_title_slug": "check-if-word-is-valid-after-substitutions", "content_en": "

Given a string s, determine if it is valid.

\n\n

A string s is valid if, starting with an empty string t = "", you can transform t into s after performing the following operation any number of times:

\n\n
    \n\t
  • Insert string "abc" into any position in t. More formally, t becomes tleft + "abc" + tright, where t == tleft + tright. Note that tleft and tright may be empty.
  • \n
\n\n

Return true if s is a valid string, otherwise, return false.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "aabcbc"\nOutput: true\nExplanation:\n"" -> "abc" -> "aabcbc"\nThus, "aabcbc" is valid.
\n\n

Example 2:

\n\n
\nInput: s = "abcabcababcc"\nOutput: true\nExplanation:\n"" -> "abc" -> "abcabc" -> "abcabcabc" -> "abcabcababcc"\nThus, "abcabcababcc" is valid.\n
\n\n

Example 3:

\n\n
\nInput: s = "abccba"\nOutput: false\nExplanation: It is impossible to get "abccba" using the operation.\n
\n\n

Example 4:

\n\n
\nInput: s = "cababc"\nOutput: false\nExplanation: It is impossible to get "cababc" using the operation.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 2 * 104
  • \n\t
  • s consists of letters 'a', 'b', and 'c'
  • \n
\n", "content_cn": "\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \uff0c\u8bf7\u4f60\u5224\u65ad\u5b83\u662f\u5426 \u6709\u6548 \u3002\n

\u5b57\u7b26\u4e32 s \u6709\u6548 \u9700\u8981\u6ee1\u8db3\uff1a\u5047\u8bbe\u5f00\u59cb\u6709\u4e00\u4e2a\u7a7a\u5b57\u7b26\u4e32 t = \"\" \uff0c\u4f60\u53ef\u4ee5\u6267\u884c \u4efb\u610f\u6b21 \u4e0b\u8ff0\u64cd\u4f5c\u5c06 t \u8f6c\u6362\u4e3a s \uff1a

\n\n
    \n\t
  • \u5c06\u5b57\u7b26\u4e32 \"abc\" \u63d2\u5165\u5230 t \u4e2d\u7684\u4efb\u610f\u4f4d\u7f6e\u3002\u5f62\u5f0f\u4e0a\uff0ct \u53d8\u4e3a tleft + \"abc\" + tright\uff0c\u5176\u4e2d t == tleft + tright \u3002\u6ce8\u610f\uff0ctleft \u548c tright \u53ef\u80fd\u4e3a \u7a7a \u3002
  • \n
\n\n

\u5982\u679c\u5b57\u7b26\u4e32 s \u6709\u6548\uff0c\u5219\u8fd4\u56de true\uff1b\u5426\u5219\uff0c\u8fd4\u56de false\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"aabcbc\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\n\"\" -> \"abc\" -> \"aabcbc\"\n\u56e0\u6b64\uff0c\"aabcbc\" \u6709\u6548\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"abcabcababcc\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\n\"\" -> \"abc\" -> \"abcabc\" -> \"abcabcabc\" -> \"abcabcababcc\"\n\u56e0\u6b64\uff0c\"abcabcababcc\" \u6709\u6548\u3002
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"abccba\"\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u6267\u884c\u64cd\u4f5c\u65e0\u6cd5\u5f97\u5230 \"abccba\" \u3002
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"cababc\"\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u6267\u884c\u64cd\u4f5c\u65e0\u6cd5\u5f97\u5230 \"cababc\" \u3002
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length <= 2 * 104
  • \n\t
  • s \u7531\u5b57\u6bcd 'a'\u3001'b' \u548c 'c' \u7ec4\u6210
  • \n
\n", "tags_en": ["Stack", "String"], "tags_cn": ["\u6808", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isValid(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isValid(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isValid(self, s):\n \"\"\"\n :type s: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isValid(self, s: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isValid(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsValid(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {boolean}\n */\nvar isValid = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Boolean}\ndef is_valid(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isValid(_ s: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isValid(s string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isValid(s: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isValid(s: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_valid(s: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Boolean\n */\n function isValid($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isValid(s: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-valid s)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1003](https://leetcode-cn.com/problems/check-if-word-is-valid-after-substitutions)", "[\u68c0\u67e5\u66ff\u6362\u540e\u7684\u8bcd\u662f\u5426\u6709\u6548](/solution/1000-1099/1003.Check%20If%20Word%20Is%20Valid%20After%20Substitutions/README.md)", "`\u6808`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1003](https://leetcode.com/problems/check-if-word-is-valid-after-substitutions)", "[Check If Word Is Valid After Substitutions](/solution/1000-1099/1003.Check%20If%20Word%20Is%20Valid%20After%20Substitutions/README_EN.md)", "`Stack`,`String`", "Medium", ""]}, {"question_id": "1044", "frontend_question_id": "1002", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-common-characters", "url_en": "https://leetcode.com/problems/find-common-characters", "relative_path_cn": "/solution/1000-1099/1002.Find%20Common%20Characters/README.md", "relative_path_en": "/solution/1000-1099/1002.Find%20Common%20Characters/README_EN.md", "title_cn": "\u67e5\u627e\u5e38\u7528\u5b57\u7b26", "title_en": "Find Common Characters", "question_title_slug": "find-common-characters", "content_en": "

Given an array words of strings made only from lowercase letters, return a list of all characters that show up in all strings within the list (including duplicates).  For example, if a character occurs 3 times in all strings but not 4 times, you need to include that character three times in the final answer.

\n\n

You may return the answer in any order.

\n\n

 

\n\n
\n

Example 1:

\n\n
\nInput: ["bella","label","roller"]\nOutput: ["e","l","l"]\n
\n\n
\n

Example 2:

\n\n
\nInput: ["cool","lock","cook"]\nOutput: ["c","o"]\n
\n\n

 

\n\n

Note:

\n\n
    \n\t
  1. 1 <= words.length <= 100
  2. \n\t
  3. 1 <= words[i].length <= 100
  4. \n\t
  5. words[i] consists of lowercase English letters.
  6. \n
\n
\n
\n", "content_cn": "

\u7ed9\u5b9a\u4ec5\u6709\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210\u7684\u5b57\u7b26\u4e32\u6570\u7ec4 A\uff0c\u8fd4\u56de\u5217\u8868\u4e2d\u7684\u6bcf\u4e2a\u5b57\u7b26\u4e32\u4e2d\u90fd\u663e\u793a\u7684\u5168\u90e8\u5b57\u7b26\uff08\u5305\u62ec\u91cd\u590d\u5b57\u7b26\uff09\u7ec4\u6210\u7684\u5217\u8868\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4e00\u4e2a\u5b57\u7b26\u5728\u6bcf\u4e2a\u5b57\u7b26\u4e32\u4e2d\u51fa\u73b0 3 \u6b21\uff0c\u4f46\u4e0d\u662f 4 \u6b21\uff0c\u5219\u9700\u8981\u5728\u6700\u7ec8\u7b54\u6848\u4e2d\u5305\u542b\u8be5\u5b57\u7b26 3 \u6b21\u3002

\n\n

\u4f60\u53ef\u4ee5\u6309\u4efb\u610f\u987a\u5e8f\u8fd4\u56de\u7b54\u6848\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a["bella","label","roller"]\n\u8f93\u51fa\uff1a["e","l","l"]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a["cool","lock","cook"]\n\u8f93\u51fa\uff1a["c","o"]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= A.length <= 100
  2. \n\t
  3. 1 <= A[i].length <= 100
  4. \n\t
  5. A[i][j] \u662f\u5c0f\u5199\u5b57\u6bcd
  6. \n
\n", "tags_en": ["Array", "Hash Table"], "tags_cn": ["\u6570\u7ec4", "\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector commonChars(vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List commonChars(String[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def commonChars(self, words):\n \"\"\"\n :type words: List[str]\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def commonChars(self, words: List[str]) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** commonChars(char ** words, int wordsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList CommonChars(string[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @return {string[]}\n */\nvar commonChars = function(words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @return {String[]}\ndef common_chars(words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func commonChars(_ words: [String]) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func commonChars(words []string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def commonChars(words: Array[String]): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun commonChars(words: Array): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn common_chars(words: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @return String[]\n */\n function commonChars($words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function commonChars(words: string[]): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (common-chars words)\n (-> (listof string?) (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1002](https://leetcode-cn.com/problems/find-common-characters)", "[\u67e5\u627e\u5e38\u7528\u5b57\u7b26](/solution/1000-1099/1002.Find%20Common%20Characters/README.md)", "`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[1002](https://leetcode.com/problems/find-common-characters)", "[Find Common Characters](/solution/1000-1099/1002.Find%20Common%20Characters/README_EN.md)", "`Array`,`Hash Table`", "Easy", ""]}, {"question_id": "1043", "frontend_question_id": "1001", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/grid-illumination", "url_en": "https://leetcode.com/problems/grid-illumination", "relative_path_cn": "/solution/1000-1099/1001.Grid%20Illumination/README.md", "relative_path_en": "/solution/1000-1099/1001.Grid%20Illumination/README_EN.md", "title_cn": "\u7f51\u683c\u7167\u660e", "title_en": "Grid Illumination", "question_title_slug": "grid-illumination", "content_en": "

There is a 2D grid of size n x n where each cell of this grid has a lamp that is initially turned off.

\n\n

You are given a 2D array of lamp positions lamps, where lamps[i] = [rowi, coli] indicates that the lamp at grid[rowi][coli] is turned on. Even if the same lamp is listed more than once, it is turned on.

\n\n

When a lamp is turned on, it illuminates its cell and all other cells in the same row, column, or diagonal.

\n\n

You are also given another 2D array queries, where queries[j] = [rowj, colj]. For the jth query, determine whether grid[rowj][colj] is illuminated or not. After answering the jth query, turn off the lamp at grid[rowj][colj] and its 8 adjacent lamps if they exist. A lamp is adjacent if its cell shares either a side or corner with grid[rowj][colj].

\n\n

Return an array of integers ans, where ans[j] should be 1 if the cell in the jth query was illuminated, or 0 if the lamp was not.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: n = 5, lamps = [[0,0],[4,4]], queries = [[1,1],[1,0]]\nOutput: [1,0]\nExplanation: We have the initial grid with all lamps turned off. In the above picture we see the grid after turning on the lamp at grid[0][0] then turning on the lamp at grid[4][4].\nThe 0th query asks if the lamp at grid[1][1] is illuminated or not (the blue square). It is illuminated, so set ans[0] = 1. Then, we turn off all lamps in the red square.\n\"\"\nThe 1st query asks if the lamp at grid[1][0] is illuminated or not (the blue square). It is not illuminated, so set ans[1] = 0. Then, we turn off all lamps in the red rectangle.\n\"\"\n
\n\n

Example 2:

\n\n
\nInput: n = 5, lamps = [[0,0],[4,4]], queries = [[1,1],[1,1]]\nOutput: [1,1]\n
\n\n

Example 3:

\n\n
\nInput: n = 5, lamps = [[0,0],[0,4]], queries = [[0,4],[0,1],[1,4]]\nOutput: [1,1,0]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 109
  • \n\t
  • 0 <= lamps.length <= 20000
  • \n\t
  • 0 <= queries.length <= 20000
  • \n\t
  • lamps[i].length == 2
  • \n\t
  • 0 <= rowi, coli < n
  • \n\t
  • queries[j].length == 2
  • \n\t
  • 0 <= rowj, colj < n
  • \n
\n", "content_cn": "

\u5728\u00a0N x N\u00a0\u7684\u7f51\u683c grid \u4e0a\uff0c\u6bcf\u4e2a\u5355\u5143\u683c\u90fd\u6709\u4e00\u76cf\u706f\uff0c\u6700\u521d\u706f\u90fd\u5904\u4e8e \u5173\u95ed \u72b6\u6001\u3002

\n\n

\u6570\u7ec4\u00a0lamps \u8868\u793a\u6253\u5f00\u7684\u706f\u7684\u4f4d\u7f6e\u3002lamps[i] = [rowi, coli] \u8868\u793a \u6253\u5f00 \u4f4d\u4e8e grid[rowi][coli] \u7684\u7b2c i \u76cf\u706f \u3002\u6bcf\u76cf\u706f\u90fd\u7167\u4eae\u81ea\u8eab\u5355\u5143\u683c\u4ee5\u53ca\u540c\u4e00\u884c\u3001\u540c\u4e00\u5217\u548c\u4e24\u6761\u5bf9\u89d2\u7ebf\u4e0a\u7684\u6240\u6709\u5176\u4ed6\u5355\u5143\u683c\u3002

\n\n

\u67e5\u8be2\u6570\u7ec4 queries \u4e2d\uff0c\u7b2c i \u6b21\u67e5\u8be2\u00a0queries[i] = [rowi, coli]\uff0c\u5982\u679c\u5355\u5143\u683c [rowi, coli] \u662f\u88ab\u7167\u4eae\u7684\uff0c\u5219\u67e5\u8be2\u7ed3\u679c\u4e3a 1 \uff0c\u5426\u5219\u4e3a 0 \u3002\u5728\u7b2c i \u6b21\u67e5\u8be2\u4e4b\u540e [\u6309\u7167\u67e5\u8be2\u7684\u987a\u5e8f] \uff0c\u5173\u95ed \u4f4d\u4e8e\u5355\u5143\u683c grid[rowi][coli] \u4e0a\u6216\u5176\u76f8\u90bb 8 \u4e2a\u65b9\u5411\u4e0a\uff08\u4e0e\u5355\u5143\u683c grid[rowi][coli] \u5171\u4eab\u89d2\u6216\u8fb9\uff09\u7684\u4efb\u4f55\u706f\u3002

\n\n

\u8fd4\u56de\u7b54\u6848\u6570\u7ec4 ans \uff0c answer[i] \u5e94\u7b49\u4e8e\u7b2c i\u00a0\u6b21\u67e5\u8be2\u00a0queries[i]\u00a0\u7684\u7ed3\u679c\uff0c1 \u8868\u793a\u7167\u4eae\uff0c0 \u8868\u793a\u672a\u7167\u4eae\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1aN = 5, lamps = [[0,0],[4,4]], queries = [[1,1],[1,0]]\n\u8f93\u51fa\uff1a[1,0]\n\u89e3\u91ca\uff1a\u6700\u521d\u6240\u6709\u706f\u90fd\u662f\u5173\u95ed\u7684\u3002\u5728\u6267\u884c\u67e5\u8be2\u4e4b\u524d\uff0c\u6253\u5f00\u4f4d\u4e8e [0, 0] \u548c [4, 4] \u7684\u706f\u3002\u7b2c 0\u00a0\u6b21\u67e5\u8be2\u68c0\u67e5 grid[1][1] \u662f\u5426\u88ab\u7167\u4eae\uff08\u84dd\u8272\u65b9\u6846\uff09\u3002\u8be5\u5355\u5143\u683c\u88ab\u7167\u4eae\uff0c\u6240\u4ee5 ans[0] = 1 \u3002\u7136\u540e\uff0c\u5173\u95ed\u7ea2\u8272\u65b9\u6846\u4e2d\u7684\u6240\u6709\u706f\u3002\n\"\"\n\u7b2c 1\u00a0\u6b21\u67e5\u8be2\u68c0\u67e5 grid[1][0] \u662f\u5426\u88ab\u7167\u4eae\uff08\u84dd\u8272\u65b9\u6846\uff09\u3002\u8be5\u5355\u5143\u683c\u6ca1\u6709\u88ab\u7167\u4eae\uff0c\u6240\u4ee5 ans[1] = 0 \u3002\u7136\u540e\uff0c\u5173\u95ed\u7ea2\u8272\u77e9\u5f62\u4e2d\u7684\u6240\u6709\u706f\u3002\n\"\"\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aN = 5, lamps = [[0,0],[4,4]], queries = [[1,1],[1,1]]\n\u8f93\u51fa\uff1a[1,1]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1aN = 5, lamps = [[0,0],[0,4]], queries = [[0,4],[0,1],[1,4]]\n\u8f93\u51fa\uff1a[1,1,0]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= N <= 109
  • \n\t
  • 0 <= lamps.length <= 20000
  • \n\t
  • lamps[i].length == 2
  • \n\t
  • 0 <= lamps[i][j] < N
  • \n\t
  • 0 <= queries.length <= 20000
  • \n\t
  • queries[i].length == 2
  • \n\t
  • 0 <= queries[i][j] < N
  • \n
\n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector gridIllumination(int n, vector>& lamps, vector>& queries) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] gridIllumination(int n, int[][] lamps, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def gridIllumination(self, n, lamps, queries):\n \"\"\"\n :type n: int\n :type lamps: List[List[int]]\n :type queries: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def gridIllumination(self, n: int, lamps: List[List[int]], queries: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* gridIllumination(int n, int** lamps, int lampsSize, int* lampsColSize, int** queries, int queriesSize, int* queriesColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] GridIllumination(int n, int[][] lamps, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} lamps\n * @param {number[][]} queries\n * @return {number[]}\n */\nvar gridIllumination = function(n, lamps, queries) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} lamps\n# @param {Integer[][]} queries\n# @return {Integer[]}\ndef grid_illumination(n, lamps, queries)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func gridIllumination(_ n: Int, _ lamps: [[Int]], _ queries: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func gridIllumination(n int, lamps [][]int, queries [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def gridIllumination(n: Int, lamps: Array[Array[Int]], queries: Array[Array[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun gridIllumination(n: Int, lamps: Array, queries: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn grid_illumination(n: i32, lamps: Vec>, queries: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $lamps\n * @param Integer[][] $queries\n * @return Integer[]\n */\n function gridIllumination($n, $lamps, $queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function gridIllumination(n: number, lamps: number[][], queries: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (grid-illumination n lamps queries)\n (-> exact-integer? (listof (listof exact-integer?)) (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1001](https://leetcode-cn.com/problems/grid-illumination)", "[\u7f51\u683c\u7167\u660e](/solution/1000-1099/1001.Grid%20Illumination/README.md)", "`\u54c8\u5e0c\u8868`", "\u56f0\u96be", ""], "md_table_row_en": ["[1001](https://leetcode.com/problems/grid-illumination)", "[Grid Illumination](/solution/1000-1099/1001.Grid%20Illumination/README_EN.md)", "`Hash Table`", "Hard", ""]}, {"question_id": "1042", "frontend_question_id": "1000", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-cost-to-merge-stones", "url_en": "https://leetcode.com/problems/minimum-cost-to-merge-stones", "relative_path_cn": "/solution/1000-1099/1000.Minimum%20Cost%20to%20Merge%20Stones/README.md", "relative_path_en": "/solution/1000-1099/1000.Minimum%20Cost%20to%20Merge%20Stones/README_EN.md", "title_cn": "\u5408\u5e76\u77f3\u5934\u7684\u6700\u4f4e\u6210\u672c", "title_en": "Minimum Cost to Merge Stones", "question_title_slug": "minimum-cost-to-merge-stones", "content_en": "

There are n piles of stones arranged in a row. The ith pile has stones[i] stones.

\n\n

A move consists of merging exactly k consecutive piles into one pile, and the cost of this move is equal to the total number of stones in these k piles.

\n\n

Return the minimum cost to merge all piles of stones into one pile. If it is impossible, return -1.

\n\n

 

\n

Example 1:

\n\n
\nInput: stones = [3,2,4,1], k = 2\nOutput: 20\nExplanation: We start with [3, 2, 4, 1].\nWe merge [3, 2] for a cost of 5, and we are left with [5, 4, 1].\nWe merge [4, 1] for a cost of 5, and we are left with [5, 5].\nWe merge [5, 5] for a cost of 10, and we are left with [10].\nThe total cost was 20, and this is the minimum possible.\n
\n\n

Example 2:

\n\n
\nInput: stones = [3,2,4,1], k = 3\nOutput: -1\nExplanation: After any merge operation, there are 2 piles left, and we can't merge anymore.  So the task is impossible.\n
\n\n

Example 3:

\n\n
\nInput: stones = [3,5,1,2,6], k = 3\nOutput: 25\nExplanation: We start with [3, 5, 1, 2, 6].\nWe merge [5, 1, 2] for a cost of 8, and we are left with [3, 8, 6].\nWe merge [3, 8, 6] for a cost of 17, and we are left with [17].\nThe total cost was 25, and this is the minimum possible.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == stones.length
  • \n\t
  • 1 <= n <= 30
  • \n\t
  • 1 <= stones[i] <= 100
  • \n\t
  • 2 <= k <= 30
  • \n
\n", "content_cn": "

\u6709 N \u5806\u77f3\u5934\u6392\u6210\u4e00\u6392\uff0c\u7b2c i \u5806\u4e2d\u6709 stones[i] \u5757\u77f3\u5934\u3002

\n\n

\u6bcf\u6b21\u79fb\u52a8\uff08move\uff09\u9700\u8981\u5c06\u8fde\u7eed\u7684 K \u5806\u77f3\u5934\u5408\u5e76\u4e3a\u4e00\u5806\uff0c\u800c\u8fd9\u4e2a\u79fb\u52a8\u7684\u6210\u672c\u4e3a\u8fd9 K \u5806\u77f3\u5934\u7684\u603b\u6570\u3002

\n\n

\u627e\u51fa\u628a\u6240\u6709\u77f3\u5934\u5408\u5e76\u6210\u4e00\u5806\u7684\u6700\u4f4e\u6210\u672c\u3002\u5982\u679c\u4e0d\u53ef\u80fd\uff0c\u8fd4\u56de -1 \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1astones = [3,2,4,1], K = 2\n\u8f93\u51fa\uff1a20\n\u89e3\u91ca\uff1a\n\u4ece [3, 2, 4, 1] \u5f00\u59cb\u3002\n\u5408\u5e76 [3, 2]\uff0c\u6210\u672c\u4e3a 5\uff0c\u5269\u4e0b [5, 4, 1]\u3002\n\u5408\u5e76 [4, 1]\uff0c\u6210\u672c\u4e3a 5\uff0c\u5269\u4e0b [5, 5]\u3002\n\u5408\u5e76 [5, 5]\uff0c\u6210\u672c\u4e3a 10\uff0c\u5269\u4e0b [10]\u3002\n\u603b\u6210\u672c 20\uff0c\u8fd9\u662f\u53ef\u80fd\u7684\u6700\u5c0f\u503c\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1astones = [3,2,4,1], K = 3\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u4efb\u4f55\u5408\u5e76\u64cd\u4f5c\u540e\uff0c\u90fd\u4f1a\u5269\u4e0b 2 \u5806\uff0c\u6211\u4eec\u65e0\u6cd5\u518d\u8fdb\u884c\u5408\u5e76\u3002\u6240\u4ee5\u8fd9\u9879\u4efb\u52a1\u662f\u4e0d\u53ef\u80fd\u5b8c\u6210\u7684\u3002.\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1astones = [3,5,1,2,6], K = 3\n\u8f93\u51fa\uff1a25\n\u89e3\u91ca\uff1a\n\u4ece [3, 5, 1, 2, 6] \u5f00\u59cb\u3002\n\u5408\u5e76 [5, 1, 2]\uff0c\u6210\u672c\u4e3a 8\uff0c\u5269\u4e0b [3, 8, 6]\u3002\n\u5408\u5e76 [3, 8, 6]\uff0c\u6210\u672c\u4e3a 17\uff0c\u5269\u4e0b [17]\u3002\n\u603b\u6210\u672c 25\uff0c\u8fd9\u662f\u53ef\u80fd\u7684\u6700\u5c0f\u503c\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= stones.length <= 30
  • \n\t
  • 2 <= K <= 30
  • \n\t
  • 1 <= stones[i] <= 100
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int mergeStones(vector& stones, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int mergeStones(int[] stones, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def mergeStones(self, stones, k):\n \"\"\"\n :type stones: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def mergeStones(self, stones: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint mergeStones(int* stones, int stonesSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MergeStones(int[] stones, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} stones\n * @param {number} k\n * @return {number}\n */\nvar mergeStones = function(stones, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} stones\n# @param {Integer} k\n# @return {Integer}\ndef merge_stones(stones, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func mergeStones(_ stones: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func mergeStones(stones []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def mergeStones(stones: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun mergeStones(stones: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn merge_stones(stones: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $stones\n * @param Integer $k\n * @return Integer\n */\n function mergeStones($stones, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function mergeStones(stones: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (merge-stones stones k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1000](https://leetcode-cn.com/problems/minimum-cost-to-merge-stones)", "[\u5408\u5e76\u77f3\u5934\u7684\u6700\u4f4e\u6210\u672c](/solution/1000-1099/1000.Minimum%20Cost%20to%20Merge%20Stones/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1000](https://leetcode.com/problems/minimum-cost-to-merge-stones)", "[Minimum Cost to Merge Stones](/solution/1000-1099/1000.Minimum%20Cost%20to%20Merge%20Stones/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1041", "frontend_question_id": "0999", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/available-captures-for-rook", "url_en": "https://leetcode.com/problems/available-captures-for-rook", "relative_path_cn": "/solution/0900-0999/0999.Available%20Captures%20for%20Rook/README.md", "relative_path_en": "/solution/0900-0999/0999.Available%20Captures%20for%20Rook/README_EN.md", "title_cn": "\u53ef\u4ee5\u88ab\u4e00\u6b65\u6355\u83b7\u7684\u68cb\u5b50\u6570", "title_en": "Available Captures for Rook", "question_title_slug": "available-captures-for-rook", "content_en": "

On an 8 x 8 chessboard, there is exactly one white rook 'R' and some number of white bishops 'B', black pawns 'p', and empty squares '.'.

\n\n

When the rook moves, it chooses one of four cardinal directions (north, east, south, or west), then moves in that direction until it chooses to stop, reaches the edge of the board, captures a black pawn, or is blocked by a white bishop. A rook is considered attacking a pawn if the rook can capture the pawn on the rook's turn. The number of available captures for the white rook is the number of pawns that the rook is attacking.

\n\n

Return the number of available captures for the white rook.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: board = [[".",".",".",".",".",".",".","."],[".",".",".","p",".",".",".","."],[".",".",".","R",".",".",".","p"],[".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".","."],[".",".",".","p",".",".",".","."],[".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".","."]]\nOutput: 3\nExplanation: In this example, the rook is attacking all the pawns.\n
\n\n

Example 2:

\n\"\"\n
\nInput: board = [[".",".",".",".",".",".",".","."],[".","p","p","p","p","p",".","."],[".","p","p","B","p","p",".","."],[".","p","B","R","B","p",".","."],[".","p","p","B","p","p",".","."],[".","p","p","p","p","p",".","."],[".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".","."]]\nOutput: 0\nExplanation: The bishops are blocking the rook from attacking any of the pawns.\n
\n\n

Example 3:

\n\"\"\n
\nInput: board = [[".",".",".",".",".",".",".","."],[".",".",".","p",".",".",".","."],[".",".",".","p",".",".",".","."],["p","p",".","R",".","p","B","."],[".",".",".",".",".",".",".","."],[".",".",".","B",".",".",".","."],[".",".",".","p",".",".",".","."],[".",".",".",".",".",".",".","."]]\nOutput: 3\nExplanation: The rook is attacking the pawns at positions b5, d6, and f5.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • board.length == 8
  • \n\t
  • board[i].length == 8
  • \n\t
  • board[i][j] is either 'R', '.', 'B', or 'p'
  • \n\t
  • There is exactly one cell with board[i][j] == 'R'
  • \n
\n", "content_cn": "

\u5728\u4e00\u4e2a 8 x 8 \u7684\u68cb\u76d8\u4e0a\uff0c\u6709\u4e00\u4e2a\u767d\u8272\u7684\u8f66\uff08Rook\uff09\uff0c\u7528\u5b57\u7b26 'R' \u8868\u793a\u3002\u68cb\u76d8\u4e0a\u8fd8\u53ef\u80fd\u5b58\u5728\u7a7a\u65b9\u5757\uff0c\u767d\u8272\u7684\u8c61\uff08Bishop\uff09\u4ee5\u53ca\u9ed1\u8272\u7684\u5352\uff08pawn\uff09\uff0c\u5206\u522b\u7528\u5b57\u7b26 '.'\uff0c'B' \u548c 'p' \u8868\u793a\u3002\u4e0d\u96be\u770b\u51fa\uff0c\u5927\u5199\u5b57\u7b26\u8868\u793a\u7684\u662f\u767d\u68cb\uff0c\u5c0f\u5199\u5b57\u7b26\u8868\u793a\u7684\u662f\u9ed1\u68cb\u3002

\n\n

\u8f66\u6309\u56fd\u9645\u8c61\u68cb\u4e2d\u7684\u89c4\u5219\u79fb\u52a8\u3002\u4e1c\uff0c\u897f\uff0c\u5357\uff0c\u5317\u56db\u4e2a\u57fa\u672c\u65b9\u5411\u4efb\u9009\u5176\u4e00\uff0c\u7136\u540e\u4e00\u76f4\u5411\u9009\u5b9a\u7684\u65b9\u5411\u79fb\u52a8\uff0c\u76f4\u5230\u6ee1\u8db3\u4e0b\u5217\u56db\u4e2a\u6761\u4ef6\u4e4b\u4e00\uff1a

\n\n
    \n\t
  • \u68cb\u624b\u9009\u62e9\u4e3b\u52a8\u505c\u4e0b\u6765\u3002
  • \n\t
  • \u68cb\u5b50\u56e0\u5230\u8fbe\u68cb\u76d8\u7684\u8fb9\u7f18\u800c\u505c\u4e0b\u3002
  • \n\t
  • \u68cb\u5b50\u79fb\u52a8\u5230\u67d0\u4e00\u65b9\u683c\u6765\u6355\u83b7\u4f4d\u4e8e\u8be5\u65b9\u683c\u4e0a\u654c\u65b9\uff08\u9ed1\u8272\uff09\u7684\u5352\uff0c\u505c\u5728\u8be5\u65b9\u683c\u5185\u3002
  • \n\t
  • \u8f66\u4e0d\u80fd\u8fdb\u5165/\u8d8a\u8fc7\u5df2\u7ecf\u653e\u6709\u5176\u4ed6\u53cb\u65b9\u68cb\u5b50\uff08\u767d\u8272\u7684\u8c61\uff09\u7684\u65b9\u683c\uff0c\u505c\u5728\u53cb\u65b9\u68cb\u5b50\u524d\u3002
  • \n
\n\n

\u4f60\u73b0\u5728\u53ef\u4ee5\u63a7\u5236\u8f66\u79fb\u52a8\u4e00\u6b21\uff0c\u8bf7\u4f60\u7edf\u8ba1\u6709\u591a\u5c11\u654c\u65b9\u7684\u5352\u5904\u4e8e\u4f60\u7684\u6355\u83b7\u8303\u56f4\u5185\uff08\u5373\uff0c\u53ef\u4ee5\u88ab\u4e00\u6b65\u6355\u83b7\u7684\u68cb\u5b50\u6570\uff09\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1a[[".",".",".",".",".",".",".","."],[".",".",".","p",".",".",".","."],[".",".",".","R",".",".",".","p"],[".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".","."],[".",".",".","p",".",".",".","."],[".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".","."]]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\n\u5728\u672c\u4f8b\u4e2d\uff0c\u8f66\u80fd\u591f\u6355\u83b7\u6240\u6709\u7684\u5352\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1a[[".",".",".",".",".",".",".","."],[".","p","p","p","p","p",".","."],[".","p","p","B","p","p",".","."],[".","p","B","R","B","p",".","."],[".","p","p","B","p","p",".","."],[".","p","p","p","p","p",".","."],[".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".","."]]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\n\u8c61\u963b\u6b62\u4e86\u8f66\u6355\u83b7\u4efb\u4f55\u5352\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1a[[".",".",".",".",".",".",".","."],[".",".",".","p",".",".",".","."],[".",".",".","p",".",".",".","."],["p","p",".","R",".","p","B","."],[".",".",".",".",".",".",".","."],[".",".",".","B",".",".",".","."],[".",".",".","p",".",".",".","."],[".",".",".",".",".",".",".","."]]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a \n\u8f66\u53ef\u4ee5\u6355\u83b7\u4f4d\u7f6e b5\uff0cd6 \u548c f5 \u7684\u5352\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. board.length == board[i].length == 8
  2. \n\t
  3. board[i][j] \u53ef\u4ee5\u662f 'R'\uff0c'.'\uff0c'B' \u6216 'p'
  4. \n\t
  5. \u53ea\u6709\u4e00\u4e2a\u683c\u5b50\u4e0a\u5b58\u5728 board[i][j] == 'R'
  6. \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numRookCaptures(vector>& board) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numRookCaptures(char[][] board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numRookCaptures(self, board):\n \"\"\"\n :type board: List[List[str]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numRookCaptures(self, board: List[List[str]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numRookCaptures(char** board, int boardSize, int* boardColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumRookCaptures(char[][] board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {character[][]} board\n * @return {number}\n */\nvar numRookCaptures = function(board) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Character[][]} board\n# @return {Integer}\ndef num_rook_captures(board)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numRookCaptures(_ board: [[Character]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numRookCaptures(board [][]byte) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numRookCaptures(board: Array[Array[Char]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numRookCaptures(board: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_rook_captures(board: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $board\n * @return Integer\n */\n function numRookCaptures($board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numRookCaptures(board: string[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-rook-captures board)\n (-> (listof (listof char?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0999](https://leetcode-cn.com/problems/available-captures-for-rook)", "[\u53ef\u4ee5\u88ab\u4e00\u6b65\u6355\u83b7\u7684\u68cb\u5b50\u6570](/solution/0900-0999/0999.Available%20Captures%20for%20Rook/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0999](https://leetcode.com/problems/available-captures-for-rook)", "[Available Captures for Rook](/solution/0900-0999/0999.Available%20Captures%20for%20Rook/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1040", "frontend_question_id": "0998", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-binary-tree-ii", "url_en": "https://leetcode.com/problems/maximum-binary-tree-ii", "relative_path_cn": "/solution/0900-0999/0998.Maximum%20Binary%20Tree%20II/README.md", "relative_path_en": "/solution/0900-0999/0998.Maximum%20Binary%20Tree%20II/README_EN.md", "title_cn": "\u6700\u5927\u4e8c\u53c9\u6811 II", "title_en": "Maximum Binary Tree II", "question_title_slug": "maximum-binary-tree-ii", "content_en": "

We are given the root node of a maximum tree: a tree where every node has a value greater than any other value in its subtree.

\n\n

Just as in the previous problem, the given tree was constructed from an list A (root = Construct(A)) recursively with the following Construct(A) routine:

\n\n
    \n\t
  • If A is empty, return null.
  • \n\t
  • Otherwise, let A[i] be the largest element of A.  Create a root node with value A[i].
  • \n\t
  • The left child of root will be Construct([A[0], A[1], ..., A[i-1]])
  • \n\t
  • The right child of root will be Construct([A[i+1], A[i+2], ..., A[A.length - 1]])
  • \n\t
  • Return root.
  • \n
\n\n

Note that we were not given A directly, only a root node root = Construct(A).

\n\n

Suppose B is a copy of A with the value val appended to it.  It is guaranteed that B has unique values.

\n\n

Return Construct(B).

\n\n

 

\n

Example 1:

\n\n

\"\"\"\"

\n\n
\nInput: root = [4,1,3,null,null,2], val = 5\nOutput: [5,4,null,1,3,null,null,2]\nExplanation: A = [1,4,2,3], B = [1,4,2,3,5]\n
\n\n

Example 2:

\n\n

\"\"\"\"

\n\n
\nInput: root = [5,2,4,null,1], val = 3\nOutput: [5,2,4,null,1,null,3]\nExplanation: A = [2,1,5,4], B = [2,1,5,4,3]\n
\n\n

Example 3:

\n\n

\"\"\"\"

\n\n
\nInput: root = [5,2,3,null,1], val = 4\nOutput: [5,2,4,null,1,3]\nExplanation: A = [2,1,5,3], B = [2,1,5,3,4]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= B.length <= 100
  • \n
\n", "content_cn": "

\u6700\u5927\u6811\u5b9a\u4e49\uff1a\u4e00\u4e2a\u6811\uff0c\u5176\u4e2d\u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u90fd\u5927\u4e8e\u5176\u5b50\u6811\u4e2d\u7684\u4efb\u4f55\u5176\u4ed6\u503c\u3002

\n\n

\u7ed9\u51fa\u6700\u5927\u6811\u7684\u6839\u8282\u70b9 root\u3002

\n\n

\u5c31\u50cf\u4e4b\u524d\u7684\u95ee\u9898\u90a3\u6837\uff0c\u7ed9\u5b9a\u7684\u6811\u662f\u4ece\u5217\u8868\u00a0A\uff08root = Construct(A)\uff09\u9012\u5f52\u5730\u4f7f\u7528\u4e0b\u8ff0\u00a0Construct(A)\u00a0\u4f8b\u7a0b\u6784\u9020\u7684\uff1a

\n\n
    \n\t
  • \u5982\u679c\u00a0A\u00a0\u4e3a\u7a7a\uff0c\u8fd4\u56de\u00a0null
  • \n\t
  • \u5426\u5219\uff0c\u4ee4\u00a0A[i]\u00a0\u4f5c\u4e3a A \u7684\u6700\u5927\u5143\u7d20\u3002\u521b\u5efa\u4e00\u4e2a\u503c\u4e3a\u00a0A[i]\u00a0\u7684\u6839\u8282\u70b9 root
  • \n\t
  • root\u00a0\u7684\u5de6\u5b50\u6811\u5c06\u88ab\u6784\u5efa\u4e3a\u00a0Construct([A[0], A[1], ..., A[i-1]])
  • \n\t
  • root\u00a0\u7684\u53f3\u5b50\u6811\u5c06\u88ab\u6784\u5efa\u4e3a Construct([A[i+1], A[i+2], ..., A[A.length - 1]])
  • \n\t
  • \u8fd4\u56de\u00a0root
  • \n
\n\n

\u8bf7\u6ce8\u610f\uff0c\u6211\u4eec\u6ca1\u6709\u76f4\u63a5\u7ed9\u5b9a\u00a0A\uff0c\u53ea\u6709\u4e00\u4e2a\u6839\u8282\u70b9\u00a0root = Construct(A).

\n\n

\u5047\u8bbe B \u662f A \u7684\u526f\u672c\uff0c\u5e76\u5728\u672b\u5c3e\u9644\u52a0\u503c val\u3002\u9898\u76ee\u6570\u636e\u4fdd\u8bc1 B\u00a0\u4e2d\u7684\u503c\u662f\u4e0d\u540c\u7684\u3002

\n\n

\u8fd4\u56de\u00a0Construct(B)\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"\"\"

\n\n
\n\u8f93\u5165\uff1aroot = [4,1,3,null,null,2], val = 5\n\u8f93\u51fa\uff1a[5,4,null,1,3,null,null,2]\n\u89e3\u91ca\uff1aA = [1,4,2,3], B = [1,4,2,3,5]\n
\n\n

\u793a\u4f8b 2\uff1a
\n\"\"\"\"

\n\n
\n\u8f93\u5165\uff1aroot = [5,2,4,null,1], val = 3\n\u8f93\u51fa\uff1a[5,2,4,null,1,null,3]\n\u89e3\u91ca\uff1aA = [2,1,5,4], B = [2,1,5,4,3]\n
\n\n

\u793a\u4f8b 3\uff1a
\n\"\"\"\"

\n\n
\n\u8f93\u5165\uff1aroot = [5,2,3,null,1], val = 4\n\u8f93\u51fa\uff1a[5,2,4,null,1,3]\n\u89e3\u91ca\uff1aA = [2,1,5,3], B = [2,1,5,3,4]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= B.length <= 100
  • \n
\n\n

\u00a0

\n\n

\u00a0

\n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* insertIntoMaxTree(TreeNode* root, int val) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode insertIntoMaxTree(TreeNode root, int val) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def insertIntoMaxTree(self, root, val):\n \"\"\"\n :type root: TreeNode\n :type val: int\n :rtype: TreeNode\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def insertIntoMaxTree(self, root: TreeNode, val: int) -> TreeNode:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* insertIntoMaxTree(struct TreeNode* root, int val){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode InsertIntoMaxTree(TreeNode root, int val) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number} val\n * @return {TreeNode}\n */\nvar insertIntoMaxTree = function(root, val) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @param {Integer} val\n# @return {TreeNode}\ndef insert_into_max_tree(root, val)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func insertIntoMaxTree(_ root: TreeNode?, _ val: Int) -> TreeNode? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc insertIntoMaxTree(root *TreeNode, val int) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def insertIntoMaxTree(root: TreeNode, `val`: Int): TreeNode = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun insertIntoMaxTree(root: TreeNode?, `val`: Int): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn insert_into_max_tree(root: Option>>, val: i32) -> Option>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param Integer $val\n * @return TreeNode\n */\n function insertIntoMaxTree($root, $val) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction insertIntoMaxTree(root: TreeNode | null, val: number): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (insert-into-max-tree root val)\n (-> (or/c tree-node? #f) exact-integer? (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0998](https://leetcode-cn.com/problems/maximum-binary-tree-ii)", "[\u6700\u5927\u4e8c\u53c9\u6811 II](/solution/0900-0999/0998.Maximum%20Binary%20Tree%20II/README.md)", "`\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0998](https://leetcode.com/problems/maximum-binary-tree-ii)", "[Maximum Binary Tree II](/solution/0900-0999/0998.Maximum%20Binary%20Tree%20II/README_EN.md)", "`Tree`", "Medium", ""]}, {"question_id": "1039", "frontend_question_id": "0997", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-the-town-judge", "url_en": "https://leetcode.com/problems/find-the-town-judge", "relative_path_cn": "/solution/0900-0999/0997.Find%20the%20Town%20Judge/README.md", "relative_path_en": "/solution/0900-0999/0997.Find%20the%20Town%20Judge/README_EN.md", "title_cn": "\u627e\u5230\u5c0f\u9547\u7684\u6cd5\u5b98", "title_en": "Find the Town Judge", "question_title_slug": "find-the-town-judge", "content_en": "

In a town, there are n people labelled from 1 to n.  There is a rumor that one of these people is secretly the town judge.

\n\n

If the town judge exists, then:

\n\n
    \n\t
  1. The town judge trusts nobody.
  2. \n\t
  3. Everybody (except for the town judge) trusts the town judge.
  4. \n\t
  5. There is exactly one person that satisfies properties 1 and 2.
  6. \n
\n\n

You are given trust, an array of pairs trust[i] = [a, b] representing that the person labelled a trusts the person labelled b.

\n\n

If the town judge exists and can be identified, return the label of the town judge.  Otherwise, return -1.

\n\n

 

\n

Example 1:

\n\n
\nInput: n = 2, trust = [[1,2]]\nOutput: 2\n
\n\n

Example 2:

\n\n
\nInput: n = 3, trust = [[1,3],[2,3]]\nOutput: 3\n
\n\n

Example 3:

\n\n
\nInput: n = 3, trust = [[1,3],[2,3],[3,1]]\nOutput: -1\n
\n\n

Example 4:

\n\n
\nInput: n = 3, trust = [[1,2],[2,3]]\nOutput: -1\n
\n\n

Example 5:

\n\n
\nInput: n = 4, trust = [[1,3],[1,4],[2,3],[2,4],[4,3]]\nOutput: 3\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 1000
  • \n\t
  • 0 <= trust.length <= 104
  • \n\t
  • trust[i].length == 2
  • \n\t
  • trust[i] are all different
  • \n\t
  • trust[i][0] != trust[i][1]
  • \n\t
  • 1 <= trust[i][0], trust[i][1] <= n
  • \n
\n", "content_cn": "

\u5728\u4e00\u4e2a\u5c0f\u9547\u91cc\uff0c\u6309\u4ece 1 \u5230 N \u6807\u8bb0\u4e86 N \u4e2a\u4eba\u3002\u4f20\u8a00\u79f0\uff0c\u8fd9\u4e9b\u4eba\u4e2d\u6709\u4e00\u4e2a\u662f\u5c0f\u9547\u4e0a\u7684\u79d8\u5bc6\u6cd5\u5b98\u3002

\n\n

\u5982\u679c\u5c0f\u9547\u7684\u6cd5\u5b98\u771f\u7684\u5b58\u5728\uff0c\u90a3\u4e48\uff1a

\n\n
    \n\t
  1. \u5c0f\u9547\u7684\u6cd5\u5b98\u4e0d\u76f8\u4fe1\u4efb\u4f55\u4eba\u3002
  2. \n\t
  3. \u6bcf\u4e2a\u4eba\uff08\u9664\u4e86\u5c0f\u9547\u6cd5\u5b98\u5916\uff09\u90fd\u4fe1\u4efb\u5c0f\u9547\u7684\u6cd5\u5b98\u3002
  4. \n\t
  5. \u53ea\u6709\u4e00\u4e2a\u4eba\u540c\u65f6\u6ee1\u8db3\u5c5e\u6027 1 \u548c\u5c5e\u6027 2 \u3002
  6. \n
\n\n

\u7ed9\u5b9a\u6570\u7ec4 trust\uff0c\u8be5\u6570\u7ec4\u7531\u4fe1\u4efb\u5bf9 trust[i] = [a, b] \u7ec4\u6210\uff0c\u8868\u793a\u6807\u8bb0\u4e3a a \u7684\u4eba\u4fe1\u4efb\u6807\u8bb0\u4e3a b \u7684\u4eba\u3002

\n\n

\u5982\u679c\u5c0f\u9547\u5b58\u5728\u79d8\u5bc6\u6cd5\u5b98\u5e76\u4e14\u53ef\u4ee5\u786e\u5b9a\u4ed6\u7684\u8eab\u4efd\uff0c\u8bf7\u8fd4\u56de\u8be5\u6cd5\u5b98\u7684\u6807\u8bb0\u3002\u5426\u5219\uff0c\u8fd4\u56de -1\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aN = 2, trust = [[1,2]]\n\u8f93\u51fa\uff1a2\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aN = 3, trust = [[1,3],[2,3]]\n\u8f93\u51fa\uff1a3\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aN = 3, trust = [[1,3],[2,3],[3,1]]\n\u8f93\u51fa\uff1a-1\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1aN = 3, trust = [[1,2],[2,3]]\n\u8f93\u51fa\uff1a-1\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1aN = 4, trust = [[1,3],[1,4],[2,3],[2,4],[4,3]]\n\u8f93\u51fa\uff1a3
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= N <= 1000
  2. \n\t
  3. trust.length <= 10000
  4. \n\t
  5. trust[i] \u662f\u5b8c\u5168\u4e0d\u540c\u7684
  6. \n\t
  7. trust[i][0] != trust[i][1]
  8. \n\t
  9. 1 <= trust[i][0], trust[i][1] <= N
  10. \n
\n", "tags_en": ["Graph"], "tags_cn": ["\u56fe"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findJudge(int n, vector>& trust) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findJudge(int n, int[][] trust) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findJudge(self, n, trust):\n \"\"\"\n :type n: int\n :type trust: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findJudge(self, n: int, trust: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findJudge(int n, int** trust, int trustSize, int* trustColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindJudge(int n, int[][] trust) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} trust\n * @return {number}\n */\nvar findJudge = function(n, trust) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} trust\n# @return {Integer}\ndef find_judge(n, trust)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findJudge(_ n: Int, _ trust: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findJudge(n int, trust [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findJudge(n: Int, trust: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findJudge(n: Int, trust: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_judge(n: i32, trust: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $trust\n * @return Integer\n */\n function findJudge($n, $trust) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findJudge(n: number, trust: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-judge n trust)\n (-> exact-integer? (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0997](https://leetcode-cn.com/problems/find-the-town-judge)", "[\u627e\u5230\u5c0f\u9547\u7684\u6cd5\u5b98](/solution/0900-0999/0997.Find%20the%20Town%20Judge/README.md)", "`\u56fe`", "\u7b80\u5355", ""], "md_table_row_en": ["[0997](https://leetcode.com/problems/find-the-town-judge)", "[Find the Town Judge](/solution/0900-0999/0997.Find%20the%20Town%20Judge/README_EN.md)", "`Graph`", "Easy", ""]}, {"question_id": "1038", "frontend_question_id": "0996", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-squareful-arrays", "url_en": "https://leetcode.com/problems/number-of-squareful-arrays", "relative_path_cn": "/solution/0900-0999/0996.Number%20of%20Squareful%20Arrays/README.md", "relative_path_en": "/solution/0900-0999/0996.Number%20of%20Squareful%20Arrays/README_EN.md", "title_cn": "\u6b63\u65b9\u5f62\u6570\u7ec4\u7684\u6570\u76ee", "title_en": "Number of Squareful Arrays", "question_title_slug": "number-of-squareful-arrays", "content_en": "

Given an array nums of non-negative integers, the array is squareful if for every pair of adjacent elements, their sum is a perfect square.

\n\n

Return the number of permutations of nums that are squareful.  Two permutations perm1 and perm2 differ if and only if there is some index i such that perm1[i] != perm2[i].

\n\n

 

\n\n

Example 1:

\n\n
\nInput: nums = [1,17,8]\nOutput: 2\nExplanation: \n[1,8,17] and [17,8,1] are the valid permutations.\n
\n\n

Example 2:

\n\n
\nInput: nums = [2,2,2]\nOutput: 1\n
\n\n

 

\n\n

Note:

\n\n
    \n\t
  1. 1 <= nums.length <= 12
  2. \n\t
  3. 0 <= nums[i] <= 109
  4. \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\u6570\u7ec4 A\uff0c\u5982\u679c\u8be5\u6570\u7ec4\u6bcf\u5bf9\u76f8\u90bb\u5143\u7d20\u4e4b\u548c\u662f\u4e00\u4e2a\u5b8c\u5168\u5e73\u65b9\u6570\uff0c\u5219\u79f0\u8fd9\u4e00\u6570\u7ec4\u4e3a\u6b63\u65b9\u5f62\u6570\u7ec4\u3002

\n\n

\u8fd4\u56de A \u7684\u6b63\u65b9\u5f62\u6392\u5217\u7684\u6570\u76ee\u3002\u4e24\u4e2a\u6392\u5217 A1 \u548c A2 \u4e0d\u540c\u7684\u5145\u8981\u6761\u4ef6\u662f\u5b58\u5728\u67d0\u4e2a\u7d22\u5f15 i\uff0c\u4f7f\u5f97 A1[i] != A2[i]\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a[1,17,8]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n[1,8,17] \u548c [17,8,1] \u90fd\u662f\u6709\u6548\u7684\u6392\u5217\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a[2,2,2]\n\u8f93\u51fa\uff1a1\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= A.length <= 12
  2. \n\t
  3. 0 <= A[i] <= 1e9
  4. \n
\n", "tags_en": ["Graph", "Math", "Backtracking"], "tags_cn": ["\u56fe", "\u6570\u5b66", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numSquarefulPerms(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numSquarefulPerms(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numSquarefulPerms(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numSquarefulPerms(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numSquarefulPerms(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumSquarefulPerms(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar numSquarefulPerms = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef num_squareful_perms(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numSquarefulPerms(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numSquarefulPerms(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numSquarefulPerms(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numSquarefulPerms(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_squareful_perms(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function numSquarefulPerms($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numSquarefulPerms(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-squareful-perms nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0996](https://leetcode-cn.com/problems/number-of-squareful-arrays)", "[\u6b63\u65b9\u5f62\u6570\u7ec4\u7684\u6570\u76ee](/solution/0900-0999/0996.Number%20of%20Squareful%20Arrays/README.md)", "`\u56fe`,`\u6570\u5b66`,`\u56de\u6eaf\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[0996](https://leetcode.com/problems/number-of-squareful-arrays)", "[Number of Squareful Arrays](/solution/0900-0999/0996.Number%20of%20Squareful%20Arrays/README_EN.md)", "`Graph`,`Math`,`Backtracking`", "Hard", ""]}, {"question_id": "1037", "frontend_question_id": "0995", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-number-of-k-consecutive-bit-flips", "url_en": "https://leetcode.com/problems/minimum-number-of-k-consecutive-bit-flips", "relative_path_cn": "/solution/0900-0999/0995.Minimum%20Number%20of%20K%20Consecutive%20Bit%20Flips/README.md", "relative_path_en": "/solution/0900-0999/0995.Minimum%20Number%20of%20K%20Consecutive%20Bit%20Flips/README_EN.md", "title_cn": "K \u8fde\u7eed\u4f4d\u7684\u6700\u5c0f\u7ffb\u8f6c\u6b21\u6570", "title_en": "Minimum Number of K Consecutive Bit Flips", "question_title_slug": "minimum-number-of-k-consecutive-bit-flips", "content_en": "

In an array nums containing only 0s and 1s, a k-bit flip consists of choosing a (contiguous) subarray of length k and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0.

\n\n

Return the minimum number of k-bit flips required so that there is no 0 in the array.  If it is not possible, return -1.

\n\n

 

\n\n

Example 1:

\n\n
\nInput: nums = [0,1,0], k = 1\nOutput: 2\nExplanation: Flip nums[0], then flip nums[2].\n
\n\n
\n

Example 2:

\n\n
\nInput: nums = [1,1,0], k = 2\nOutput: -1\nExplanation: No matter how we flip subarrays of size 2, we can't make the array become [1,1,1].\n
\n\n
\n

Example 3:

\n\n
\nInput: nums = [0,0,0,1,0,1,1,0], k = 3\nOutput: 3\nExplanation:\nFlip nums[0],nums[1],nums[2]: nums becomes [1,1,1,1,0,1,1,0]\nFlip nums[4],nums[5],nums[6]: nums becomes [1,1,1,1,1,0,0,0]\nFlip nums[5],nums[6],nums[7]: nums becomes [1,1,1,1,1,1,1,1]\n
\n\n

 

\n
\n
\n\n

Note:

\n\n
    \n\t
  1. 1 <= nums.length <= 30000
  2. \n\t
  3. 1 <= k <= nums.length
  4. \n
\n", "content_cn": "

\u5728\u4ec5\u5305\u542b 0 \u548c 1 \u7684\u6570\u7ec4 A \u4e2d\uff0c\u4e00\u6b21 K \u4f4d\u7ffb\u8f6c\u5305\u62ec\u9009\u62e9\u4e00\u4e2a\u957f\u5ea6\u4e3a K \u7684\uff08\u8fde\u7eed\uff09\u5b50\u6570\u7ec4\uff0c\u540c\u65f6\u5c06\u5b50\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a 0 \u66f4\u6539\u4e3a 1\uff0c\u800c\u6bcf\u4e2a 1 \u66f4\u6539\u4e3a 0\u3002

\n\n

\u8fd4\u56de\u6240\u9700\u7684 K \u4f4d\u7ffb\u8f6c\u7684\u6700\u5c0f\u6b21\u6570\uff0c\u4ee5\u4fbf\u6570\u7ec4\u6ca1\u6709\u503c\u4e3a 0 \u7684\u5143\u7d20\u3002\u5982\u679c\u4e0d\u53ef\u80fd\uff0c\u8fd4\u56de -1\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aA = [0,1,0], K = 1\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5148\u7ffb\u8f6c A[0]\uff0c\u7136\u540e\u7ffb\u8f6c A[2]\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aA = [1,1,0], K = 2\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u65e0\u8bba\u6211\u4eec\u600e\u6837\u7ffb\u8f6c\u5927\u5c0f\u4e3a 2 \u7684\u5b50\u6570\u7ec4\uff0c\u6211\u4eec\u90fd\u4e0d\u80fd\u4f7f\u6570\u7ec4\u53d8\u4e3a [1,1,1]\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1aA = [0,0,0,1,0,1,1,0], K = 3\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\n\u7ffb\u8f6c A[0],A[1],A[2]:\u00a0A\u53d8\u6210 [1,1,1,1,0,1,1,0]\n\u7ffb\u8f6c A[4],A[5],A[6]:\u00a0A\u53d8\u6210 [1,1,1,1,1,0,0,0]\n\u7ffb\u8f6c A[5],A[6],A[7]:\u00a0A\u53d8\u6210 [1,1,1,1,1,1,1,1]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= A.length <=\u00a030000
  2. \n\t
  3. 1 <= K <= A.length
  4. \n
\n", "tags_en": ["Greedy", "Sliding Window"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minKBitFlips(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minKBitFlips(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minKBitFlips(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minKBitFlips(self, nums: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minKBitFlips(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinKBitFlips(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar minKBitFlips = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef min_k_bit_flips(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minKBitFlips(_ nums: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minKBitFlips(nums []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minKBitFlips(nums: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minKBitFlips(nums: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_k_bit_flips(nums: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer\n */\n function minKBitFlips($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minKBitFlips(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-k-bit-flips nums k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0995](https://leetcode-cn.com/problems/minimum-number-of-k-consecutive-bit-flips)", "[K \u8fde\u7eed\u4f4d\u7684\u6700\u5c0f\u7ffb\u8f6c\u6b21\u6570](/solution/0900-0999/0995.Minimum%20Number%20of%20K%20Consecutive%20Bit%20Flips/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[0995](https://leetcode.com/problems/minimum-number-of-k-consecutive-bit-flips)", "[Minimum Number of K Consecutive Bit Flips](/solution/0900-0999/0995.Minimum%20Number%20of%20K%20Consecutive%20Bit%20Flips/README_EN.md)", "`Greedy`,`Sliding Window`", "Hard", ""]}, {"question_id": "1036", "frontend_question_id": "0994", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/rotting-oranges", "url_en": "https://leetcode.com/problems/rotting-oranges", "relative_path_cn": "/solution/0900-0999/0994.Rotting%20Oranges/README.md", "relative_path_en": "/solution/0900-0999/0994.Rotting%20Oranges/README_EN.md", "title_cn": "\u8150\u70c2\u7684\u6a58\u5b50", "title_en": "Rotting Oranges", "question_title_slug": "rotting-oranges", "content_en": "

You are given an m x n grid where each cell can have one of three values:

\n\n
    \n\t
  • 0 representing an empty cell,
  • \n\t
  • 1 representing a fresh orange, or
  • \n\t
  • 2 representing a rotten orange.
  • \n
\n\n

Every minute, any fresh orange that is 4-directionally adjacent to a rotten orange becomes rotten.

\n\n

Return the minimum number of minutes that must elapse until no cell has a fresh orange. If this is impossible, return -1.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: grid = [[2,1,1],[1,1,0],[0,1,1]]\nOutput: 4\n
\n\n

Example 2:

\n\n
\nInput: grid = [[2,1,1],[0,1,1],[1,0,1]]\nOutput: -1\nExplanation: The orange in the bottom left corner (row 2, column 0) is never rotten, because rotting only happens 4-directionally.\n
\n\n

Example 3:

\n\n
\nInput: grid = [[0,2]]\nOutput: 0\nExplanation: Since there are already no fresh oranges at minute 0, the answer is just 0.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • m == grid.length
  • \n\t
  • n == grid[i].length
  • \n\t
  • 1 <= m, n <= 10
  • \n\t
  • grid[i][j] is 0, 1, or 2.
  • \n
\n", "content_cn": "

\u5728\u7ed9\u5b9a\u7684\u7f51\u683c\u4e2d\uff0c\u6bcf\u4e2a\u5355\u5143\u683c\u53ef\u4ee5\u6709\u4ee5\u4e0b\u4e09\u4e2a\u503c\u4e4b\u4e00\uff1a

\n\n
    \n\t
  • \u503c 0 \u4ee3\u8868\u7a7a\u5355\u5143\u683c\uff1b
  • \n\t
  • \u503c 1 \u4ee3\u8868\u65b0\u9c9c\u6a58\u5b50\uff1b
  • \n\t
  • \u503c 2 \u4ee3\u8868\u8150\u70c2\u7684\u6a58\u5b50\u3002
  • \n
\n\n

\u6bcf\u5206\u949f\uff0c\u4efb\u4f55\u4e0e\u8150\u70c2\u7684\u6a58\u5b50\uff08\u5728 4 \u4e2a\u6b63\u65b9\u5411\u4e0a\uff09\u76f8\u90bb\u7684\u65b0\u9c9c\u6a58\u5b50\u90fd\u4f1a\u8150\u70c2\u3002

\n\n

\u8fd4\u56de\u76f4\u5230\u5355\u5143\u683c\u4e2d\u6ca1\u6709\u65b0\u9c9c\u6a58\u5b50\u4e3a\u6b62\u6240\u5fc5\u987b\u7ecf\u8fc7\u7684\u6700\u5c0f\u5206\u949f\u6570\u3002\u5982\u679c\u4e0d\u53ef\u80fd\uff0c\u8fd4\u56de -1\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1a[[2,1,1],[1,1,0],[0,1,1]]\n\u8f93\u51fa\uff1a4\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a[[2,1,1],[0,1,1],[1,0,1]]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u5de6\u4e0b\u89d2\u7684\u6a58\u5b50\uff08\u7b2c 2 \u884c\uff0c \u7b2c 0 \u5217\uff09\u6c38\u8fdc\u4e0d\u4f1a\u8150\u70c2\uff0c\u56e0\u4e3a\u8150\u70c2\u53ea\u4f1a\u53d1\u751f\u5728 4 \u4e2a\u6b63\u5411\u4e0a\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1a[[0,2]]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u56e0\u4e3a 0 \u5206\u949f\u65f6\u5df2\u7ecf\u6ca1\u6709\u65b0\u9c9c\u6a58\u5b50\u4e86\uff0c\u6240\u4ee5\u7b54\u6848\u5c31\u662f 0 \u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= grid.length <= 10
  2. \n\t
  3. 1 <= grid[0].length <= 10
  4. \n\t
  5. grid[i][j] \u4ec5\u4e3a 0\u30011 \u6216 2
  6. \n
\n", "tags_en": ["Breadth-first Search"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int orangesRotting(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int orangesRotting(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def orangesRotting(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def orangesRotting(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint orangesRotting(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int OrangesRotting(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar orangesRotting = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef oranges_rotting(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func orangesRotting(_ grid: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func orangesRotting(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def orangesRotting(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun orangesRotting(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn oranges_rotting(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function orangesRotting($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function orangesRotting(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (oranges-rotting grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0994](https://leetcode-cn.com/problems/rotting-oranges)", "[\u8150\u70c2\u7684\u6a58\u5b50](/solution/0900-0999/0994.Rotting%20Oranges/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0994](https://leetcode.com/problems/rotting-oranges)", "[Rotting Oranges](/solution/0900-0999/0994.Rotting%20Oranges/README_EN.md)", "`Breadth-first Search`", "Medium", ""]}, {"question_id": "1035", "frontend_question_id": "0993", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/cousins-in-binary-tree", "url_en": "https://leetcode.com/problems/cousins-in-binary-tree", "relative_path_cn": "/solution/0900-0999/0993.Cousins%20in%20Binary%20Tree/README.md", "relative_path_en": "/solution/0900-0999/0993.Cousins%20in%20Binary%20Tree/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u7684\u5802\u5144\u5f1f\u8282\u70b9", "title_en": "Cousins in Binary Tree", "question_title_slug": "cousins-in-binary-tree", "content_en": "

In a binary tree, the root node is at depth 0, and children of each depth k node are at depth k+1.

\n\n

Two nodes of a binary tree are cousins if they have the same depth, but have different parents.

\n\n

We are given the root of a binary tree with unique values, and the values x and y of two different nodes in the tree.

\n\n

Return true if and only if the nodes corresponding to the values x and y are cousins.

\n\n

 

\n\n

Example 1:
\n\"\"

\n\n
\nInput: root = [1,2,3,4], x = 4, y = 3\nOutput: false\n
\n\n
\n

Example 2:
\n\"\"

\n\n
\nInput: root = [1,2,3,null,4,null,5], x = 5, y = 4\nOutput: true\n
\n\n
\n

Example 3:

\n\n

\"\"

\n\n
\nInput: root = [1,2,3,null,4], x = 2, y = 3\nOutput: false\n
\n
\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The number of nodes in the tree will be between 2 and 100.
  • \n\t
  • Each node has a unique integer value from 1 to 100.
  • \n
\n", "content_cn": "

\u5728\u4e8c\u53c9\u6811\u4e2d\uff0c\u6839\u8282\u70b9\u4f4d\u4e8e\u6df1\u5ea6 0 \u5904\uff0c\u6bcf\u4e2a\u6df1\u5ea6\u4e3a k \u7684\u8282\u70b9\u7684\u5b50\u8282\u70b9\u4f4d\u4e8e\u6df1\u5ea6 k+1 \u5904\u3002

\n\n

\u5982\u679c\u4e8c\u53c9\u6811\u7684\u4e24\u4e2a\u8282\u70b9\u6df1\u5ea6\u76f8\u540c\uff0c\u4f46 \u7236\u8282\u70b9\u4e0d\u540c \uff0c\u5219\u5b83\u4eec\u662f\u4e00\u5bf9\u5802\u5144\u5f1f\u8282\u70b9\u3002

\n\n

\u6211\u4eec\u7ed9\u51fa\u4e86\u5177\u6709\u552f\u4e00\u503c\u7684\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9 root \uff0c\u4ee5\u53ca\u6811\u4e2d\u4e24\u4e2a\u4e0d\u540c\u8282\u70b9\u7684\u503c x \u548c y \u3002

\n\n

\u53ea\u6709\u4e0e\u503c x \u548c y \u5bf9\u5e94\u7684\u8282\u70b9\u662f\u5802\u5144\u5f1f\u8282\u70b9\u65f6\uff0c\u624d\u8fd4\u56de true \u3002\u5426\u5219\uff0c\u8fd4\u56de false\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a
\n\"\"

\n\n
\n\u8f93\u5165\uff1aroot = [1,2,3,4], x = 4, y = 3\n\u8f93\u51fa\uff1afalse\n
\n\n

\u793a\u4f8b 2\uff1a
\n\"\"

\n\n
\n\u8f93\u5165\uff1aroot = [1,2,3,null,4,null,5], x = 5, y = 4\n\u8f93\u51fa\uff1atrue\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1aroot = [1,2,3,null,4], x = 2, y = 3\n\u8f93\u51fa\uff1afalse
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u4e8c\u53c9\u6811\u7684\u8282\u70b9\u6570\u4ecb\u4e8e\u00a02 \u5230\u00a0100\u00a0\u4e4b\u95f4\u3002
  • \n\t
  • \u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u90fd\u662f\u552f\u4e00\u7684\u3001\u8303\u56f4\u4e3a\u00a01 \u5230\u00a0100\u00a0\u7684\u6574\u6570\u3002
  • \n
\n\n

\u00a0

\n", "tags_en": ["Tree", "Breadth-first Search"], "tags_cn": ["\u6811", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n bool isCousins(TreeNode* root, int x, int y) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public boolean isCousins(TreeNode root, int x, int y) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def isCousins(self, root, x, y):\n \"\"\"\n :type root: TreeNode\n :type x: int\n :type y: int\n :rtype: bool\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def isCousins(self, root: TreeNode, x: int, y: int) -> bool:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nbool isCousins(struct TreeNode* root, int x, int y){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public bool IsCousins(TreeNode root, int x, int y) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number} x\n * @param {number} y\n * @return {boolean}\n */\nvar isCousins = function(root, x, y) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @param {Integer} x\n# @param {Integer} y\n# @return {Boolean}\ndef is_cousins(root, x, y)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func isCousins(_ root: TreeNode?, _ x: Int, _ y: Int) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc isCousins(root *TreeNode, x int, y int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def isCousins(root: TreeNode, x: Int, y: Int): Boolean = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun isCousins(root: TreeNode?, x: Int, y: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn is_cousins(root: Option>>, x: i32, y: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param Integer $x\n * @param Integer $y\n * @return Boolean\n */\n function isCousins($root, $x, $y) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction isCousins(root: TreeNode | null, x: number, y: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (is-cousins root x y)\n (-> (or/c tree-node? #f) exact-integer? exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0993](https://leetcode-cn.com/problems/cousins-in-binary-tree)", "[\u4e8c\u53c9\u6811\u7684\u5802\u5144\u5f1f\u8282\u70b9](/solution/0900-0999/0993.Cousins%20in%20Binary%20Tree/README.md)", "`\u6811`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u7b80\u5355", ""], "md_table_row_en": ["[0993](https://leetcode.com/problems/cousins-in-binary-tree)", "[Cousins in Binary Tree](/solution/0900-0999/0993.Cousins%20in%20Binary%20Tree/README_EN.md)", "`Tree`,`Breadth-first Search`", "Easy", ""]}, {"question_id": "1034", "frontend_question_id": "0992", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/subarrays-with-k-different-integers", "url_en": "https://leetcode.com/problems/subarrays-with-k-different-integers", "relative_path_cn": "/solution/0900-0999/0992.Subarrays%20with%20K%20Different%20Integers/README.md", "relative_path_en": "/solution/0900-0999/0992.Subarrays%20with%20K%20Different%20Integers/README_EN.md", "title_cn": "K \u4e2a\u4e0d\u540c\u6574\u6570\u7684\u5b50\u6570\u7ec4", "title_en": "Subarrays with K Different Integers", "question_title_slug": "subarrays-with-k-different-integers", "content_en": "

Given an array nums of positive integers, call a (contiguous, not necessarily distinct) subarray of nums good if the number of different integers in that subarray is exactly k.

\n\n

(For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.)

\n\n

Return the number of good subarrays of nums.

\n\n

 

\n\n

Example 1:

\n\n
\nInput: nums = [1,2,1,2,3], k = 2\nOutput: 7\nExplanation: Subarrays formed with exactly 2 different integers: [1,2], [2,1], [1,2], [2,3], [1,2,1], [2,1,2], [1,2,1,2].\n
\n\n

Example 2:

\n\n
\nInput: nums = [1,2,1,3,4], k = 3\nOutput: 3\nExplanation: Subarrays formed with exactly 3 different integers: [1,2,1,3], [2,1,3], [1,3,4].\n
\n\n

 

\n\n

Note:

\n\n
    \n\t
  1. 1 <= nums.length <= 20000
  2. \n\t
  3. 1 <= nums[i] <= nums.length
  4. \n\t
  5. 1 <= k <= nums.length
  6. \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u6b63\u6574\u6570\u6570\u7ec4 A\uff0c\u5982\u679c A\u00a0\u7684\u67d0\u4e2a\u5b50\u6570\u7ec4\u4e2d\u4e0d\u540c\u6574\u6570\u7684\u4e2a\u6570\u6070\u597d\u4e3a K\uff0c\u5219\u79f0 A \u7684\u8fd9\u4e2a\u8fde\u7eed\u3001\u4e0d\u4e00\u5b9a\u4e0d\u540c\u7684\u5b50\u6570\u7ec4\u4e3a\u597d\u5b50\u6570\u7ec4\u3002

\n\n

\uff08\u4f8b\u5982\uff0c[1,2,3,1,2] \u4e2d\u6709\u00a03\u00a0\u4e2a\u4e0d\u540c\u7684\u6574\u6570\uff1a1\uff0c2\uff0c\u4ee5\u53ca\u00a03\u3002\uff09

\n\n

\u8fd4\u56de\u00a0A\u00a0\u4e2d\u597d\u5b50\u6570\u7ec4\u7684\u6570\u76ee\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aA = [1,2,1,2,3], K = 2\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\u6070\u597d\u7531 2 \u4e2a\u4e0d\u540c\u6574\u6570\u7ec4\u6210\u7684\u5b50\u6570\u7ec4\uff1a[1,2], [2,1], [1,2], [2,3], [1,2,1], [2,1,2], [1,2,1,2].\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aA = [1,2,1,3,4], K = 3\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6070\u597d\u7531 3 \u4e2a\u4e0d\u540c\u6574\u6570\u7ec4\u6210\u7684\u5b50\u6570\u7ec4\uff1a[1,2,1,3], [2,1,3], [1,3,4].\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= A.length <= 20000
  2. \n\t
  3. 1 <= A[i] <= A.length
  4. \n\t
  5. 1 <= K <= A.length
  6. \n
\n", "tags_en": ["Hash Table", "Two Pointers", "Sliding Window"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u53cc\u6307\u9488"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int subarraysWithKDistinct(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int subarraysWithKDistinct(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def subarraysWithKDistinct(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def subarraysWithKDistinct(self, nums: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint subarraysWithKDistinct(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SubarraysWithKDistinct(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar subarraysWithKDistinct = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef subarrays_with_k_distinct(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func subarraysWithKDistinct(_ nums: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func subarraysWithKDistinct(nums []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def subarraysWithKDistinct(nums: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun subarraysWithKDistinct(nums: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn subarrays_with_k_distinct(nums: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer\n */\n function subarraysWithKDistinct($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function subarraysWithKDistinct(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (subarrays-with-k-distinct nums k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0992](https://leetcode-cn.com/problems/subarrays-with-k-different-integers)", "[K \u4e2a\u4e0d\u540c\u6574\u6570\u7684\u5b50\u6570\u7ec4](/solution/0900-0999/0992.Subarrays%20with%20K%20Different%20Integers/README.md)", "`\u54c8\u5e0c\u8868`,`\u53cc\u6307\u9488`", "\u56f0\u96be", ""], "md_table_row_en": ["[0992](https://leetcode.com/problems/subarrays-with-k-different-integers)", "[Subarrays with K Different Integers](/solution/0900-0999/0992.Subarrays%20with%20K%20Different%20Integers/README_EN.md)", "`Hash Table`,`Two Pointers`,`Sliding Window`", "Hard", ""]}, {"question_id": "1033", "frontend_question_id": "0991", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/broken-calculator", "url_en": "https://leetcode.com/problems/broken-calculator", "relative_path_cn": "/solution/0900-0999/0991.Broken%20Calculator/README.md", "relative_path_en": "/solution/0900-0999/0991.Broken%20Calculator/README_EN.md", "title_cn": "\u574f\u4e86\u7684\u8ba1\u7b97\u5668", "title_en": "Broken Calculator", "question_title_slug": "broken-calculator", "content_en": "

On a broken calculator that has a number showing on its display, we can perform two operations:

\n\n
    \n\t
  • Double: Multiply the number on the display by 2, or;
  • \n\t
  • Decrement: Subtract 1 from the number on the display.
  • \n
\n\n

Initially, the calculator is displaying the number x.

\n\n

Return the minimum number of operations needed to display the number y.

\n\n

 

\n\n

Example 1:

\n\n
\nInput: x = 2, y = 3\nOutput: 2\nExplanation: Use double operation and then decrement operation {2 -> 4 -> 3}.\n
\n\n

Example 2:

\n\n
\nInput: x = 5, y = 8\nOutput: 2\nExplanation: Use decrement and then double {5 -> 4 -> 8}.\n
\n\n

Example 3:

\n\n
\nInput: x = 3, y = 10\nOutput: 3\nExplanation:  Use double, decrement and double {3 -> 6 -> 5 -> 10}.\n
\n\n

Example 4:

\n\n
\nInput: x = 1024, y = 1\nOutput: 1023\nExplanation: Use decrement operations 1023 times.\n
\n\n

 

\n\n

Note:

\n\n
    \n\t
  1. 1 <= x <= 109
  2. \n\t
  3. 1 <= y <= 109
  4. \n
\n", "content_cn": "

\u5728\u663e\u793a\u7740\u6570\u5b57\u7684\u574f\u8ba1\u7b97\u5668\u4e0a\uff0c\u6211\u4eec\u53ef\u4ee5\u6267\u884c\u4ee5\u4e0b\u4e24\u79cd\u64cd\u4f5c\uff1a

\n\n
    \n\t
  • \u53cc\u500d\uff08Double\uff09\uff1a\u5c06\u663e\u793a\u5c4f\u4e0a\u7684\u6570\u5b57\u4e58 2\uff1b
  • \n\t
  • \u9012\u51cf\uff08Decrement\uff09\uff1a\u5c06\u663e\u793a\u5c4f\u4e0a\u7684\u6570\u5b57\u51cf 1 \u3002
  • \n
\n\n

\u6700\u521d\uff0c\u8ba1\u7b97\u5668\u663e\u793a\u6570\u5b57 X\u3002

\n\n

\u8fd4\u56de\u663e\u793a\u6570\u5b57 Y \u6240\u9700\u7684\u6700\u5c0f\u64cd\u4f5c\u6570\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aX = 2, Y = 3\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5148\u8fdb\u884c\u53cc\u500d\u8fd0\u7b97\uff0c\u7136\u540e\u518d\u8fdb\u884c\u9012\u51cf\u8fd0\u7b97 {2 -> 4 -> 3}.\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aX = 5, Y = 8\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5148\u9012\u51cf\uff0c\u518d\u53cc\u500d {5 -> 4 -> 8}.\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aX = 3, Y = 10\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u5148\u53cc\u500d\uff0c\u7136\u540e\u9012\u51cf\uff0c\u518d\u53cc\u500d {3 -> 6 -> 5 -> 10}.\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1aX = 1024, Y = 1\n\u8f93\u51fa\uff1a1023\n\u89e3\u91ca\uff1a\u6267\u884c\u9012\u51cf\u8fd0\u7b97 1023 \u6b21\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= X <= 10^9
  2. \n\t
  3. 1 <= Y <= 10^9
  4. \n
\n", "tags_en": ["Greedy", "Math"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int brokenCalc(int x, int y) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int brokenCalc(int x, int y) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def brokenCalc(self, x, y):\n \"\"\"\n :type x: int\n :type y: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def brokenCalc(self, x: int, y: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint brokenCalc(int x, int y){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int BrokenCalc(int x, int y) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} x\n * @param {number} y\n * @return {number}\n */\nvar brokenCalc = function(x, y) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} x\n# @param {Integer} y\n# @return {Integer}\ndef broken_calc(x, y)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func brokenCalc(_ x: Int, _ y: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func brokenCalc(x int, y int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def brokenCalc(x: Int, y: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun brokenCalc(x: Int, y: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn broken_calc(x: i32, y: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $x\n * @param Integer $y\n * @return Integer\n */\n function brokenCalc($x, $y) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function brokenCalc(x: number, y: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (broken-calc x y)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0991](https://leetcode-cn.com/problems/broken-calculator)", "[\u574f\u4e86\u7684\u8ba1\u7b97\u5668](/solution/0900-0999/0991.Broken%20Calculator/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0991](https://leetcode.com/problems/broken-calculator)", "[Broken Calculator](/solution/0900-0999/0991.Broken%20Calculator/README_EN.md)", "`Greedy`,`Math`", "Medium", ""]}, {"question_id": "1032", "frontend_question_id": "0990", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/satisfiability-of-equality-equations", "url_en": "https://leetcode.com/problems/satisfiability-of-equality-equations", "relative_path_cn": "/solution/0900-0999/0990.Satisfiability%20of%20Equality%20Equations/README.md", "relative_path_en": "/solution/0900-0999/0990.Satisfiability%20of%20Equality%20Equations/README_EN.md", "title_cn": "\u7b49\u5f0f\u65b9\u7a0b\u7684\u53ef\u6ee1\u8db3\u6027", "title_en": "Satisfiability of Equality Equations", "question_title_slug": "satisfiability-of-equality-equations", "content_en": "

Given an array equations of strings that represent relationships between variables, each string equations[i] has length 4 and takes one of two different forms: "a==b" or "a!=b".  Here, a and b are lowercase letters (not necessarily different) that represent one-letter variable names.

\r\n\r\n

Return true if and only if it is possible to assign integers to variable names so as to satisfy all the given equations.

\r\n\r\n

 

\r\n\r\n
    \r\n
\r\n\r\n
\r\n

Example 1:

\r\n\r\n
\r\nInput: ["a==b","b!=a"]\r\nOutput: false\r\nExplanation: If we assign say, a = 1 and b = 1, then the first equation is satisfied, but not the second.  There is no way to assign the variables to satisfy both equations.\r\n
\r\n\r\n
\r\n

Example 2:

\r\n\r\n
\r\nInput: ["b==a","a==b"]\r\nOutput: true\r\nExplanation: We could assign a = 1 and b = 1 to satisfy both equations.\r\n
\r\n\r\n
\r\n

Example 3:

\r\n\r\n
\r\nInput: ["a==b","b==c","a==c"]\r\nOutput: true\r\n
\r\n\r\n
\r\n

Example 4:

\r\n\r\n
\r\nInput: ["a==b","b!=c","c==a"]\r\nOutput: false\r\n
\r\n\r\n
\r\n

Example 5:

\r\n\r\n
\r\nInput: ["c==c","b==d","x!=z"]\r\nOutput: true\r\n
\r\n\r\n

 

\r\n\r\n

Note:

\r\n\r\n
    \r\n\t
  1. 1 <= equations.length <= 500
  2. \r\n\t
  3. equations[i].length == 4
  4. \r\n\t
  5. equations[i][0] and equations[i][3] are lowercase letters
  6. \r\n\t
  7. equations[i][1] is either '=' or '!'
  8. \r\n\t
  9. equations[i][2] is '='
  10. \r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u7531\u8868\u793a\u53d8\u91cf\u4e4b\u95f4\u5173\u7cfb\u7684\u5b57\u7b26\u4e32\u65b9\u7a0b\u7ec4\u6210\u7684\u6570\u7ec4\uff0c\u6bcf\u4e2a\u5b57\u7b26\u4e32\u65b9\u7a0b equations[i] \u7684\u957f\u5ea6\u4e3a 4\uff0c\u5e76\u91c7\u7528\u4e24\u79cd\u4e0d\u540c\u7684\u5f62\u5f0f\u4e4b\u4e00\uff1a"a==b" \u6216 "a!=b"\u3002\u5728\u8fd9\u91cc\uff0ca \u548c b \u662f\u5c0f\u5199\u5b57\u6bcd\uff08\u4e0d\u4e00\u5b9a\u4e0d\u540c\uff09\uff0c\u8868\u793a\u5355\u5b57\u6bcd\u53d8\u91cf\u540d\u3002

\n\n

\u53ea\u6709\u5f53\u53ef\u4ee5\u5c06\u6574\u6570\u5206\u914d\u7ed9\u53d8\u91cf\u540d\uff0c\u4ee5\u4fbf\u6ee1\u8db3\u6240\u6709\u7ed9\u5b9a\u7684\u65b9\u7a0b\u65f6\u624d\u8fd4\u56de true\uff0c\u5426\u5219\u8fd4\u56de false\u3002 

\n\n

 

\n\n
    \n
\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a["a==b","b!=a"]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u5982\u679c\u6211\u4eec\u6307\u5b9a\uff0ca = 1 \u4e14 b = 1\uff0c\u90a3\u4e48\u53ef\u4ee5\u6ee1\u8db3\u7b2c\u4e00\u4e2a\u65b9\u7a0b\uff0c\u4f46\u65e0\u6cd5\u6ee1\u8db3\u7b2c\u4e8c\u4e2a\u65b9\u7a0b\u3002\u6ca1\u6709\u529e\u6cd5\u5206\u914d\u53d8\u91cf\u540c\u65f6\u6ee1\u8db3\u8fd9\u4e24\u4e2a\u65b9\u7a0b\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a["b==a","a==b"]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u6211\u4eec\u53ef\u4ee5\u6307\u5b9a a = 1 \u4e14 b = 1 \u4ee5\u6ee1\u8db3\u6ee1\u8db3\u8fd9\u4e24\u4e2a\u65b9\u7a0b\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1a["a==b","b==c","a==c"]\n\u8f93\u51fa\uff1atrue\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1a["a==b","b!=c","c==a"]\n\u8f93\u51fa\uff1afalse\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1a["c==c","b==d","x!=z"]\n\u8f93\u51fa\uff1atrue\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= equations.length <= 500
  2. \n\t
  3. equations[i].length == 4
  4. \n\t
  5. equations[i][0] \u548c equations[i][3] \u662f\u5c0f\u5199\u5b57\u6bcd
  6. \n\t
  7. equations[i][1] \u8981\u4e48\u662f '='\uff0c\u8981\u4e48\u662f '!'
  8. \n\t
  9. equations[i][2] \u662f '='
  10. \n
\n", "tags_en": ["Union Find", "Graph"], "tags_cn": ["\u5e76\u67e5\u96c6", "\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool equationsPossible(vector& equations) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean equationsPossible(String[] equations) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def equationsPossible(self, equations):\n \"\"\"\n :type equations: List[str]\n :rtype: bool\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def equationsPossible(self, equations: List[str]) -> bool:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool equationsPossible(char ** equations, int equationsSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool EquationsPossible(string[] equations) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} equations\n * @return {boolean}\n */\nvar equationsPossible = function(equations) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} equations\n# @return {Boolean}\ndef equations_possible(equations)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func equationsPossible(_ equations: [String]) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func equationsPossible(equations []string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def equationsPossible(equations: Array[String]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun equationsPossible(equations: Array): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn equations_possible(equations: Vec) -> bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $equations\n * @return Boolean\n */\n function equationsPossible($equations) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function equationsPossible(equations: string[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (equations-possible equations)\n (-> (listof string?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0990](https://leetcode-cn.com/problems/satisfiability-of-equality-equations)", "[\u7b49\u5f0f\u65b9\u7a0b\u7684\u53ef\u6ee1\u8db3\u6027](/solution/0900-0999/0990.Satisfiability%20of%20Equality%20Equations/README.md)", "`\u5e76\u67e5\u96c6`,`\u56fe`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0990](https://leetcode.com/problems/satisfiability-of-equality-equations)", "[Satisfiability of Equality Equations](/solution/0900-0999/0990.Satisfiability%20of%20Equality%20Equations/README_EN.md)", "`Union Find`,`Graph`", "Medium", ""]}, {"question_id": "1031", "frontend_question_id": "0989", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/add-to-array-form-of-integer", "url_en": "https://leetcode.com/problems/add-to-array-form-of-integer", "relative_path_cn": "/solution/0900-0999/0989.Add%20to%20Array-Form%20of%20Integer/README.md", "relative_path_en": "/solution/0900-0999/0989.Add%20to%20Array-Form%20of%20Integer/README_EN.md", "title_cn": "\u6570\u7ec4\u5f62\u5f0f\u7684\u6574\u6570\u52a0\u6cd5", "title_en": "Add to Array-Form of Integer", "question_title_slug": "add-to-array-form-of-integer", "content_en": "

The array-form of an integer num is an array representing its digits in left to right order.

\n\n
    \n\t
  • For example, for num = 1321, the array form is [1,3,2,1].
  • \n
\n\n

Given num, the array-form of an integer, and an integer k, return the array-form of the integer num + k.

\n\n

 

\n

Example 1:

\n\n
\nInput: num = [1,2,0,0], k = 34\nOutput: [1,2,3,4]\nExplanation: 1200 + 34 = 1234\n
\n\n

Example 2:

\n\n
\nInput: num = [2,7,4], k = 181\nOutput: [4,5,5]\nExplanation: 274 + 181 = 455\n
\n\n

Example 3:

\n\n
\nInput: num = [2,1,5], k = 806\nOutput: [1,0,2,1]\nExplanation: 215 + 806 = 1021\n
\n\n

Example 4:

\n\n
\nInput: num = [9,9,9,9,9,9,9,9,9,9], k = 1\nOutput: [1,0,0,0,0,0,0,0,0,0,0]\nExplanation: 9999999999 + 1 = 10000000000\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= num.length <= 104
  • \n\t
  • 0 <= num[i] <= 9
  • \n\t
  • num does not contain any leading zeros except for the zero itself.
  • \n\t
  • 1 <= k <= 104
  • \n
\n", "content_cn": "

\u5bf9\u4e8e\u975e\u8d1f\u6574\u6570 X \u800c\u8a00\uff0cX \u7684\u6570\u7ec4\u5f62\u5f0f\u662f\u6bcf\u4f4d\u6570\u5b57\u6309\u4ece\u5de6\u5230\u53f3\u7684\u987a\u5e8f\u5f62\u6210\u7684\u6570\u7ec4\u3002\u4f8b\u5982\uff0c\u5982\u679c X = 1231\uff0c\u90a3\u4e48\u5176\u6570\u7ec4\u5f62\u5f0f\u4e3a [1,2,3,1]\u3002

\n\n

\u7ed9\u5b9a\u975e\u8d1f\u6574\u6570 X \u7684\u6570\u7ec4\u5f62\u5f0f A\uff0c\u8fd4\u56de\u6574\u6570 X+K \u7684\u6570\u7ec4\u5f62\u5f0f\u3002

\n\n

 

\n\n
    \n
\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aA = [1,2,0,0], K = 34\n\u8f93\u51fa\uff1a[1,2,3,4]\n\u89e3\u91ca\uff1a1200 + 34 = 1234\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aA = [2,7,4], K = 181\n\u8f93\u51fa\uff1a[4,5,5]\n\u89e3\u91ca\uff1a274 + 181 = 455\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aA = [2,1,5], K = 806\n\u8f93\u51fa\uff1a[1,0,2,1]\n\u89e3\u91ca\uff1a215 + 806 = 1021\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1aA = [9,9,9,9,9,9,9,9,9,9], K = 1\n\u8f93\u51fa\uff1a[1,0,0,0,0,0,0,0,0,0,0]\n\u89e3\u91ca\uff1a9999999999 + 1 = 10000000000\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= A.length <= 10000
  2. \n\t
  3. 0 <= A[i] <= 9
  4. \n\t
  5. 0 <= K <= 10000
  6. \n\t
  7. \u5982\u679c A.length > 1\uff0c\u90a3\u4e48 A[0] != 0
  8. \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector addToArrayForm(vector& num, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List addToArrayForm(int[] num, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def addToArrayForm(self, num, k):\n \"\"\"\n :type num: List[int]\n :type k: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def addToArrayForm(self, num: List[int], k: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* addToArrayForm(int* num, int numSize, int k, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList AddToArrayForm(int[] num, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} num\n * @param {number} k\n * @return {number[]}\n */\nvar addToArrayForm = function(num, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} num\n# @param {Integer} k\n# @return {Integer[]}\ndef add_to_array_form(num, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func addToArrayForm(_ num: [Int], _ k: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func addToArrayForm(num []int, k int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def addToArrayForm(num: Array[Int], k: Int): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun addToArrayForm(num: IntArray, k: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn add_to_array_form(num: Vec, k: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $num\n * @param Integer $k\n * @return Integer[]\n */\n function addToArrayForm($num, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function addToArrayForm(num: number[], k: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (add-to-array-form num k)\n (-> (listof exact-integer?) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0989](https://leetcode-cn.com/problems/add-to-array-form-of-integer)", "[\u6570\u7ec4\u5f62\u5f0f\u7684\u6574\u6570\u52a0\u6cd5](/solution/0900-0999/0989.Add%20to%20Array-Form%20of%20Integer/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0989](https://leetcode.com/problems/add-to-array-form-of-integer)", "[Add to Array-Form of Integer](/solution/0900-0999/0989.Add%20to%20Array-Form%20of%20Integer/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1030", "frontend_question_id": "0988", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/smallest-string-starting-from-leaf", "url_en": "https://leetcode.com/problems/smallest-string-starting-from-leaf", "relative_path_cn": "/solution/0900-0999/0988.Smallest%20String%20Starting%20From%20Leaf/README.md", "relative_path_en": "/solution/0900-0999/0988.Smallest%20String%20Starting%20From%20Leaf/README_EN.md", "title_cn": "\u4ece\u53f6\u7ed3\u70b9\u5f00\u59cb\u7684\u6700\u5c0f\u5b57\u7b26\u4e32", "title_en": "Smallest String Starting From Leaf", "question_title_slug": "smallest-string-starting-from-leaf", "content_en": "

Given the root of a binary tree, each node has a value from 0 to 25 representing the letters 'a' to 'z': a value of 0 represents 'a', a value of 1 represents 'b', and so on.

\r\n\r\n

Find the lexicographically smallest string that starts at a leaf of this tree and ends at the root.

\r\n\r\n

(As a reminder, any shorter prefix of a string is lexicographically smaller: for example, "ab" is lexicographically smaller than "aba".  A leaf of a node is a node that has no children.)

\r\n\r\n
\r\n
\r\n

 

\r\n\r\n
    \r\n
\r\n
\r\n
\r\n\r\n
\r\n

Example 1:

\r\n\r\n

\"\"

\r\n\r\n
\r\nInput: [0,1,2,3,4,3,4]\r\nOutput: "dba"\r\n
\r\n\r\n
\r\n

Example 2:

\r\n\r\n

\"\"

\r\n\r\n
\r\nInput: [25,1,3,1,3,0,2]\r\nOutput: "adz"\r\n
\r\n\r\n
\r\n

Example 3:

\r\n\r\n

\"\"

\r\n\r\n
\r\nInput: [2,2,1,null,1,0,null,0]\r\nOutput: "abc"\r\n
\r\n\r\n

 

\r\n\r\n

Note:

\r\n\r\n
    \r\n\t
  1. The number of nodes in the given tree will be between 1 and 8500.
  2. \r\n\t
  3. Each node in the tree will have a value between 0 and 25.
  4. \r\n
\r\n
\r\n
\r\n
", "content_cn": "

\u7ed9\u5b9a\u4e00\u9897\u6839\u7ed3\u70b9\u4e3a root \u7684\u4e8c\u53c9\u6811\uff0c\u6811\u4e2d\u7684\u6bcf\u4e00\u4e2a\u7ed3\u70b9\u90fd\u6709\u4e00\u4e2a\u4ece 0 \u5230 25 \u7684\u503c\uff0c\u5206\u522b\u4ee3\u8868\u5b57\u6bcd 'a' \u5230 'z'\uff1a\u503c 0 \u4ee3\u8868 'a'\uff0c\u503c 1 \u4ee3\u8868 'b'\uff0c\u4f9d\u6b64\u7c7b\u63a8\u3002

\n\n

\u627e\u51fa\u6309\u5b57\u5178\u5e8f\u6700\u5c0f\u7684\u5b57\u7b26\u4e32\uff0c\u8be5\u5b57\u7b26\u4e32\u4ece\u8fd9\u68f5\u6811\u7684\u4e00\u4e2a\u53f6\u7ed3\u70b9\u5f00\u59cb\uff0c\u5230\u6839\u7ed3\u70b9\u7ed3\u675f\u3002

\n\n

\uff08\u5c0f\u8d34\u58eb\uff1a\u5b57\u7b26\u4e32\u4e2d\u4efb\u4f55\u8f83\u77ed\u7684\u524d\u7f00\u5728\u5b57\u5178\u5e8f\u4e0a\u90fd\u662f\u8f83\u5c0f\u7684\uff1a\u4f8b\u5982\uff0c\u5728\u5b57\u5178\u5e8f\u4e0a "ab" \u6bd4 "aba" \u8981\u5c0f\u3002\u53f6\u7ed3\u70b9\u662f\u6307\u6ca1\u6709\u5b50\u7ed3\u70b9\u7684\u7ed3\u70b9\u3002\uff09

\n\n

 

\n\n
    \n
\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1a[0,1,2,3,4,3,4]\n\u8f93\u51fa\uff1a"dba"\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1a[25,1,3,1,3,0,2]\n\u8f93\u51fa\uff1a"adz"\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1a[2,2,1,null,1,0,null,0]\n\u8f93\u51fa\uff1a"abc"\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. \u7ed9\u5b9a\u6811\u7684\u7ed3\u70b9\u6570\u4ecb\u4e8e 1 \u548c 8500 \u4e4b\u95f4\u3002
  2. \n\t
  3. \u6811\u4e2d\u7684\u6bcf\u4e2a\u7ed3\u70b9\u90fd\u6709\u4e00\u4e2a\u4ecb\u4e8e 0 \u548c 25 \u4e4b\u95f4\u7684\u503c\u3002
  4. \n
\n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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 */\nclass Solution {\npublic:\n string smallestFromLeaf(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode(int x) { val = x; }\n * }\n */\nclass Solution {\n public String smallestFromLeaf(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution(object):\n def smallestFromLeaf(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: str\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution:\n def smallestFromLeaf(self, root: TreeNode) -> str:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nchar * smallestFromLeaf(struct TreeNode* root){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int x) { val = x; }\n * }\n */\npublic class Solution {\n public string SmallestFromLeaf(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val) {\n * this.val = val;\n * this.left = this.right = null;\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {string}\n */\nvar smallestFromLeaf = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val)\n# @val = val\n# @left, @right = nil, nil\n# end\n# end\n\n# @param {TreeNode} root\n# @return {String}\ndef smallest_from_leaf(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.left = nil\n * self.right = nil\n * }\n * }\n */\nclass Solution {\n func smallestFromLeaf(_ root: TreeNode?) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc smallestFromLeaf(root *TreeNode) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(var _value: Int) {\n * var value: Int = _value\n * var left: TreeNode = null\n * var right: TreeNode = null\n * }\n */\nobject Solution {\n def smallestFromLeaf(root: TreeNode): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun smallestFromLeaf(root: TreeNode?): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n// \n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn smallest_from_leaf(root: Option>>) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($value) { $this->val = $value; }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return String\n */\n function smallestFromLeaf($root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction smallestFromLeaf(root: TreeNode | null): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (smallest-from-leaf root)\n (-> (or/c tree-node? #f) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0988](https://leetcode-cn.com/problems/smallest-string-starting-from-leaf)", "[\u4ece\u53f6\u7ed3\u70b9\u5f00\u59cb\u7684\u6700\u5c0f\u5b57\u7b26\u4e32](/solution/0900-0999/0988.Smallest%20String%20Starting%20From%20Leaf/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0988](https://leetcode.com/problems/smallest-string-starting-from-leaf)", "[Smallest String Starting From Leaf](/solution/0900-0999/0988.Smallest%20String%20Starting%20From%20Leaf/README_EN.md)", "`Tree`,`Depth-first Search`", "Medium", ""]}, {"question_id": "1029", "frontend_question_id": "0987", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/vertical-order-traversal-of-a-binary-tree", "url_en": "https://leetcode.com/problems/vertical-order-traversal-of-a-binary-tree", "relative_path_cn": "/solution/0900-0999/0987.Vertical%20Order%20Traversal%20of%20a%20Binary%20Tree/README.md", "relative_path_en": "/solution/0900-0999/0987.Vertical%20Order%20Traversal%20of%20a%20Binary%20Tree/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u7684\u5782\u5e8f\u904d\u5386", "title_en": "Vertical Order Traversal of a Binary Tree", "question_title_slug": "vertical-order-traversal-of-a-binary-tree", "content_en": "

Given the root of a binary tree, calculate the vertical order traversal of the binary tree.

\n\n

For each node at position (row, col), its left and right children will be at positions (row + 1, col - 1) and (row + 1, col + 1) respectively. The root of the tree is at (0, 0).

\n\n

The vertical order traversal of a binary tree is a list of top-to-bottom orderings for each column index starting from the leftmost column and ending on the rightmost column. There may be multiple nodes in the same row and same column. In such a case, sort these nodes by their values.

\n\n

Return the vertical order traversal of the binary tree.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: root = [3,9,20,null,null,15,7]\nOutput: [[9],[3,15],[20],[7]]\nExplanation:\nColumn -1: Only node 9 is in this column.\nColumn 0: Nodes 3 and 15 are in this column in that order from top to bottom.\nColumn 1: Only node 20 is in this column.\nColumn 2: Only node 7 is in this column.
\n\n

Example 2:

\n\"\"\n
\nInput: root = [1,2,3,4,5,6,7]\nOutput: [[4],[2],[1,5,6],[3],[7]]\nExplanation:\nColumn -2: Only node 4 is in this column.\nColumn -1: Only node 2 is in this column.\nColumn 0: Nodes 1, 5, and 6 are in this column.\n          1 is at the top, so it comes first.\n          5 and 6 are at the same position (2, 0), so we order them by their value, 5 before 6.\nColumn 1: Only node 3 is in this column.\nColumn 2: Only node 7 is in this column.\n
\n\n

Example 3:

\n\"\"\n
\nInput: root = [1,2,3,4,6,5,7]\nOutput: [[4],[2],[1,5,6],[3],[7]]\nExplanation:\nThis case is the exact same as example 2, but with nodes 5 and 6 swapped.\nNote that the solution remains the same since 5 and 6 are in the same location and should be ordered by their values.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The number of nodes in the tree is in the range [1, 1000].
  • \n\t
  • 0 <= Node.val <= 1000
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e8c\u53c9\u6811\u7684\u6839\u7ed3\u70b9 root \uff0c\u8bf7\u4f60\u8bbe\u8ba1\u7b97\u6cd5\u8ba1\u7b97\u4e8c\u53c9\u6811\u7684 \u5782\u5e8f\u904d\u5386 \u5e8f\u5217\u3002

\n\n

\u5bf9\u4f4d\u4e8e\u00a0(row, col)\u00a0\u7684\u6bcf\u4e2a\u7ed3\u70b9\u800c\u8a00\uff0c\u5176\u5de6\u53f3\u5b50\u7ed3\u70b9\u5206\u522b\u4f4d\u4e8e\u00a0(row + 1, col - 1)\u00a0\u548c\u00a0(row + 1, col + 1) \u3002\u6811\u7684\u6839\u7ed3\u70b9\u4f4d\u4e8e (0, 0) \u3002

\n\n

\u4e8c\u53c9\u6811\u7684 \u5782\u5e8f\u904d\u5386 \u4ece\u6700\u5de6\u8fb9\u7684\u5217\u5f00\u59cb\u76f4\u5230\u6700\u53f3\u8fb9\u7684\u5217\u7ed3\u675f\uff0c\u6309\u5217\u7d22\u5f15\u6bcf\u4e00\u5217\u4e0a\u7684\u6240\u6709\u7ed3\u70b9\uff0c\u5f62\u6210\u4e00\u4e2a\u6309\u51fa\u73b0\u4f4d\u7f6e\u4ece\u4e0a\u5230\u4e0b\u6392\u5e8f\u7684\u6709\u5e8f\u5217\u8868\u3002\u5982\u679c\u540c\u884c\u540c\u5217\u4e0a\u6709\u591a\u4e2a\u7ed3\u70b9\uff0c\u5219\u6309\u7ed3\u70b9\u7684\u503c\u4ece\u5c0f\u5230\u5927\u8fdb\u884c\u6392\u5e8f\u3002

\n\n

\u8fd4\u56de\u4e8c\u53c9\u6811\u7684 \u5782\u5e8f\u904d\u5386 \u5e8f\u5217\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1aroot = [3,9,20,null,null,15,7]\n\u8f93\u51fa\uff1a[[9],[3,15],[20],[7]]\n\u89e3\u91ca\uff1a\n\u5217 -1 \uff1a\u53ea\u6709\u7ed3\u70b9 9 \u5728\u6b64\u5217\u4e2d\u3002\n\u5217  0 \uff1a\u53ea\u6709\u7ed3\u70b9 3 \u548c 15 \u5728\u6b64\u5217\u4e2d\uff0c\u6309\u4ece\u4e0a\u5230\u4e0b\u987a\u5e8f\u3002\n\u5217  1 \uff1a\u53ea\u6709\u7ed3\u70b9 20 \u5728\u6b64\u5217\u4e2d\u3002\n\u5217  2 \uff1a\u53ea\u6709\u7ed3\u70b9 7 \u5728\u6b64\u5217\u4e2d\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1aroot = [1,2,3,4,5,6,7]\n\u8f93\u51fa\uff1a[[4],[2],[1,5,6],[3],[7]]\n\u89e3\u91ca\uff1a\n\u5217 -2 \uff1a\u53ea\u6709\u7ed3\u70b9 4 \u5728\u6b64\u5217\u4e2d\u3002\n\u5217 -1 \uff1a\u53ea\u6709\u7ed3\u70b9 2 \u5728\u6b64\u5217\u4e2d\u3002\n\u5217  0 \uff1a\u7ed3\u70b9 1 \u30015 \u548c 6 \u90fd\u5728\u6b64\u5217\u4e2d\u3002\n          1 \u5728\u4e0a\u9762\uff0c\u6240\u4ee5\u5b83\u51fa\u73b0\u5728\u524d\u9762\u3002\n          5 \u548c 6 \u4f4d\u7f6e\u90fd\u662f (2, 0) \uff0c\u6240\u4ee5\u6309\u503c\u4ece\u5c0f\u5230\u5927\u6392\u5e8f\uff0c5 \u5728 6 \u7684\u524d\u9762\u3002\n\u5217  1 \uff1a\u53ea\u6709\u7ed3\u70b9 3 \u5728\u6b64\u5217\u4e2d\u3002\n\u5217  2 \uff1a\u53ea\u6709\u7ed3\u70b9 7 \u5728\u6b64\u5217\u4e2d\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1aroot = [1,2,3,4,6,5,7]\n\u8f93\u51fa\uff1a[[4],[2],[1,5,6],[3],[7]]\n\u89e3\u91ca\uff1a\n\u8fd9\u4e2a\u793a\u4f8b\u5b9e\u9645\u4e0a\u4e0e\u793a\u4f8b 2 \u5b8c\u5168\u76f8\u540c\uff0c\u53ea\u662f\u7ed3\u70b9 5 \u548c 6 \u5728\u6811\u4e2d\u7684\u4f4d\u7f6e\u53d1\u751f\u4e86\u4ea4\u6362\u3002\n\u56e0\u4e3a 5 \u548c 6 \u7684\u4f4d\u7f6e\u4ecd\u7136\u76f8\u540c\uff0c\u6240\u4ee5\u7b54\u6848\u4fdd\u6301\u4e0d\u53d8\uff0c\u4ecd\u7136\u6309\u503c\u4ece\u5c0f\u5230\u5927\u6392\u5e8f\u3002
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u6811\u4e2d\u7ed3\u70b9\u6570\u76ee\u603b\u6570\u5728\u8303\u56f4 [1, 1000] \u5185
  • \n\t
  • 0 <= Node.val <= 1000
  • \n
\n", "tags_en": ["Tree", "Depth-first Search", "Breadth-first Search", "Hash Table"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u54c8\u5e0c\u8868"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector> verticalTraversal(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public List> verticalTraversal(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def verticalTraversal(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def verticalTraversal(self, root: TreeNode) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** verticalTraversal(struct TreeNode* root, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public IList> VerticalTraversal(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number[][]}\n */\nvar verticalTraversal = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer[][]}\ndef vertical_traversal(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func verticalTraversal(_ root: TreeNode?) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc verticalTraversal(root *TreeNode) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def verticalTraversal(root: TreeNode): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun verticalTraversal(root: TreeNode?): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn vertical_traversal(root: Option>>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer[][]\n */\n function verticalTraversal($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction verticalTraversal(root: TreeNode | null): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (vertical-traversal root)\n (-> (or/c tree-node? #f) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0987](https://leetcode-cn.com/problems/vertical-order-traversal-of-a-binary-tree)", "[\u4e8c\u53c9\u6811\u7684\u5782\u5e8f\u904d\u5386](/solution/0900-0999/0987.Vertical%20Order%20Traversal%20of%20a%20Binary%20Tree/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u54c8\u5e0c\u8868`", "\u56f0\u96be", ""], "md_table_row_en": ["[0987](https://leetcode.com/problems/vertical-order-traversal-of-a-binary-tree)", "[Vertical Order Traversal of a Binary Tree](/solution/0900-0999/0987.Vertical%20Order%20Traversal%20of%20a%20Binary%20Tree/README_EN.md)", "`Tree`,`Depth-first Search`,`Breadth-first Search`,`Hash Table`", "Hard", ""]}, {"question_id": "1028", "frontend_question_id": "0986", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/interval-list-intersections", "url_en": "https://leetcode.com/problems/interval-list-intersections", "relative_path_cn": "/solution/0900-0999/0986.Interval%20List%20Intersections/README.md", "relative_path_en": "/solution/0900-0999/0986.Interval%20List%20Intersections/README_EN.md", "title_cn": "\u533a\u95f4\u5217\u8868\u7684\u4ea4\u96c6", "title_en": "Interval List Intersections", "question_title_slug": "interval-list-intersections", "content_en": "

You are given two lists of closed intervals, firstList and secondList, where firstList[i] = [starti, endi] and secondList[j] = [startj, endj]. Each list of intervals is pairwise disjoint and in sorted order.

\n\n

Return the intersection of these two interval lists.

\n\n

A closed interval [a, b] (with a < b) denotes the set of real numbers x with a <= x <= b.

\n\n

The intersection of two closed intervals is a set of real numbers that are either empty or represented as a closed interval. For example, the intersection of [1, 3] and [2, 4] is [2, 3].

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: firstList = [[0,2],[5,10],[13,23],[24,25]], secondList = [[1,5],[8,12],[15,24],[25,26]]\nOutput: [[1,2],[5,5],[8,10],[15,23],[24,24],[25,25]]\n
\n\n

Example 2:

\n\n
\nInput: firstList = [[1,3],[5,9]], secondList = []\nOutput: []\n
\n\n

Example 3:

\n\n
\nInput: firstList = [], secondList = [[4,8],[10,12]]\nOutput: []\n
\n\n

Example 4:

\n\n
\nInput: firstList = [[1,7]], secondList = [[3,10]]\nOutput: [[3,7]]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 0 <= firstList.length, secondList.length <= 1000
  • \n\t
  • firstList.length + secondList.length >= 1
  • \n\t
  • 0 <= starti < endi <= 109
  • \n\t
  • endi < starti+1
  • \n\t
  • 0 <= startj < endj <= 109
  • \n\t
  • endj < startj+1
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e24\u4e2a\u7531\u4e00\u4e9b \u95ed\u533a\u95f4 \u7ec4\u6210\u7684\u5217\u8868\uff0cfirstList \u548c secondList \uff0c\u5176\u4e2d firstList[i] = [starti, endi] \u800c\u00a0secondList[j] = [startj, endj] \u3002\u6bcf\u4e2a\u533a\u95f4\u5217\u8868\u90fd\u662f\u6210\u5bf9 \u4e0d\u76f8\u4ea4 \u7684\uff0c\u5e76\u4e14 \u5df2\u7ecf\u6392\u5e8f \u3002

\n\n

\u8fd4\u56de\u8fd9 \u4e24\u4e2a\u533a\u95f4\u5217\u8868\u7684\u4ea4\u96c6 \u3002

\n\n

\u5f62\u5f0f\u4e0a\uff0c\u95ed\u533a\u95f4\u00a0[a, b]\uff08\u5176\u4e2d\u00a0a <= b\uff09\u8868\u793a\u5b9e\u6570\u00a0x\u00a0\u7684\u96c6\u5408\uff0c\u800c\u00a0a <= x <= b \u3002

\n\n

\u4e24\u4e2a\u95ed\u533a\u95f4\u7684 \u4ea4\u96c6 \u662f\u4e00\u7ec4\u5b9e\u6570\uff0c\u8981\u4e48\u4e3a\u7a7a\u96c6\uff0c\u8981\u4e48\u4e3a\u95ed\u533a\u95f4\u3002\u4f8b\u5982\uff0c[1, 3] \u548c [2, 4] \u7684\u4ea4\u96c6\u4e3a [2, 3] \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1afirstList = [[0,2],[5,10],[13,23],[24,25]], secondList = [[1,5],[8,12],[15,24],[25,26]]\n\u8f93\u51fa\uff1a[[1,2],[5,5],[8,10],[15,23],[24,24],[25,25]]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1afirstList = [[1,3],[5,9]], secondList = []\n\u8f93\u51fa\uff1a[]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1afirstList = [], secondList = [[4,8],[10,12]]\n\u8f93\u51fa\uff1a[]\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1afirstList = [[1,7]], secondList = [[3,10]]\n\u8f93\u51fa\uff1a[[3,7]]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 0 <= firstList.length, secondList.length <= 1000
  • \n\t
  • firstList.length + secondList.length >= 1
  • \n\t
  • 0 <= starti < endi <= 109
  • \n\t
  • endi < starti+1
  • \n\t
  • 0 <= startj < endj <= 109
  • \n\t
  • endj < startj+1
  • \n
\n", "tags_en": ["Two Pointers"], "tags_cn": ["\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> intervalIntersection(vector>& firstList, vector>& secondList) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[][] intervalIntersection(int[][] firstList, int[][] secondList) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def intervalIntersection(self, firstList, secondList):\n \"\"\"\n :type firstList: List[List[int]]\n :type secondList: List[List[int]]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def intervalIntersection(self, firstList: List[List[int]], secondList: List[List[int]]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** intervalIntersection(int** firstList, int firstListSize, int* firstListColSize, int** secondList, int secondListSize, int* secondListColSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[][] IntervalIntersection(int[][] firstList, int[][] secondList) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} firstList\n * @param {number[][]} secondList\n * @return {number[][]}\n */\nvar intervalIntersection = function(firstList, secondList) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} first_list\n# @param {Integer[][]} second_list\n# @return {Integer[][]}\ndef interval_intersection(first_list, second_list)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func intervalIntersection(_ firstList: [[Int]], _ secondList: [[Int]]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func intervalIntersection(firstList [][]int, secondList [][]int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def intervalIntersection(firstList: Array[Array[Int]], secondList: Array[Array[Int]]): Array[Array[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun intervalIntersection(firstList: Array, secondList: Array): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn interval_intersection(first_list: Vec>, second_list: Vec>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $firstList\n * @param Integer[][] $secondList\n * @return Integer[][]\n */\n function intervalIntersection($firstList, $secondList) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function intervalIntersection(firstList: number[][], secondList: number[][]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (interval-intersection firstList secondList)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0986](https://leetcode-cn.com/problems/interval-list-intersections)", "[\u533a\u95f4\u5217\u8868\u7684\u4ea4\u96c6](/solution/0900-0999/0986.Interval%20List%20Intersections/README.md)", "`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0986](https://leetcode.com/problems/interval-list-intersections)", "[Interval List Intersections](/solution/0900-0999/0986.Interval%20List%20Intersections/README_EN.md)", "`Two Pointers`", "Medium", ""]}, {"question_id": "1027", "frontend_question_id": "0985", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sum-of-even-numbers-after-queries", "url_en": "https://leetcode.com/problems/sum-of-even-numbers-after-queries", "relative_path_cn": "/solution/0900-0999/0985.Sum%20of%20Even%20Numbers%20After%20Queries/README.md", "relative_path_en": "/solution/0900-0999/0985.Sum%20of%20Even%20Numbers%20After%20Queries/README_EN.md", "title_cn": "\u67e5\u8be2\u540e\u7684\u5076\u6570\u548c", "title_en": "Sum of Even Numbers After Queries", "question_title_slug": "sum-of-even-numbers-after-queries", "content_en": "

We have an array nums of integers, and an array queries of queries.

\n\n

For the i-th query val = queries[i][0], index = queries[i][1], we add val to nums[index].  Then, the answer to the i-th query is the sum of the even values of A.

\n\n

(Here, the given index = queries[i][1] is a 0-based index, and each query permanently modifies the array nums.)

\n\n

Return the answer to all queries.  Your answer array should have answer[i] as the answer to the i-th query.

\n\n

 

\n\n

Example 1:

\n\n
\nInput: nums = [1,2,3,4], queries = [[1,0],[-3,1],[-4,0],[2,3]]\nOutput: [8,6,2,4]\nExplanation: \nAt the beginning, the array is [1,2,3,4].\nAfter adding 1 to nums[0], the array is [2,2,3,4], and the sum of even values is 2 + 2 + 4 = 8.\nAfter adding -3 to nums[1], the array is [2,-1,3,4], and the sum of even values is 2 + 4 = 6.\nAfter adding -4 to nums[0], the array is [-2,-1,3,4], and the sum of even values is -2 + 4 = 2.\nAfter adding 2 to nums[3], the array is [-2,-1,3,6], and the sum of even values is -2 + 6 = 4.\n
\n\n

 

\n\n

Note:

\n\n
    \n\t
  1. 1 <= nums.length <= 10000
  2. \n\t
  3. -10000 <= nums[i] <= 10000
  4. \n\t
  5. 1 <= queries.length <= 10000
  6. \n\t
  7. -10000 <= queries[i][0] <= 10000
  8. \n\t
  9. 0 <= queries[i][1] < nums.length
  10. \n
\n", "content_cn": "

\u7ed9\u51fa\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 A \u548c\u4e00\u4e2a\u67e5\u8be2\u6570\u7ec4 queries\u3002

\n\n

\u5bf9\u4e8e\u7b2c i \u6b21\u67e5\u8be2\uff0c\u6709 val = queries[i][0], index = queries[i][1]\uff0c\u6211\u4eec\u4f1a\u628a val \u52a0\u5230 A[index] \u4e0a\u3002\u7136\u540e\uff0c\u7b2c i \u6b21\u67e5\u8be2\u7684\u7b54\u6848\u662f A \u4e2d\u5076\u6570\u503c\u7684\u548c\u3002

\n\n

\uff08\u6b64\u5904\u7ed9\u5b9a\u7684 index = queries[i][1] \u662f\u4ece 0 \u5f00\u59cb\u7684\u7d22\u5f15\uff0c\u6bcf\u6b21\u67e5\u8be2\u90fd\u4f1a\u6c38\u4e45\u4fee\u6539\u6570\u7ec4 A\u3002\uff09

\n\n

\u8fd4\u56de\u6240\u6709\u67e5\u8be2\u7684\u7b54\u6848\u3002\u4f60\u7684\u7b54\u6848\u5e94\u5f53\u4ee5\u6570\u7ec4 answer \u7ed9\u51fa\uff0canswer[i] \u4e3a\u7b2c i \u6b21\u67e5\u8be2\u7684\u7b54\u6848\u3002

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1aA = [1,2,3,4], queries = [[1,0],[-3,1],[-4,0],[2,3]]\n\u8f93\u51fa\uff1a[8,6,2,4]\n\u89e3\u91ca\uff1a\n\u5f00\u59cb\u65f6\uff0c\u6570\u7ec4\u4e3a [1,2,3,4]\u3002\n\u5c06 1 \u52a0\u5230 A[0] \u4e0a\u4e4b\u540e\uff0c\u6570\u7ec4\u4e3a [2,2,3,4]\uff0c\u5076\u6570\u503c\u4e4b\u548c\u4e3a 2 + 2 + 4 = 8\u3002\n\u5c06 -3 \u52a0\u5230 A[1] \u4e0a\u4e4b\u540e\uff0c\u6570\u7ec4\u4e3a [2,-1,3,4]\uff0c\u5076\u6570\u503c\u4e4b\u548c\u4e3a 2 + 4 = 6\u3002\n\u5c06 -4 \u52a0\u5230 A[0] \u4e0a\u4e4b\u540e\uff0c\u6570\u7ec4\u4e3a [-2,-1,3,4]\uff0c\u5076\u6570\u503c\u4e4b\u548c\u4e3a -2 + 4 = 2\u3002\n\u5c06 2 \u52a0\u5230 A[3] \u4e0a\u4e4b\u540e\uff0c\u6570\u7ec4\u4e3a [-2,-1,3,6]\uff0c\u5076\u6570\u503c\u4e4b\u548c\u4e3a -2 + 6 = 4\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= A.length <= 10000
  2. \n\t
  3. -10000 <= A[i] <= 10000
  4. \n\t
  5. 1 <= queries.length <= 10000
  6. \n\t
  7. -10000 <= queries[i][0] <= 10000
  8. \n\t
  9. 0 <= queries[i][1] < A.length
  10. \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector sumEvenAfterQueries(vector& nums, vector>& queries) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] sumEvenAfterQueries(int[] nums, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def sumEvenAfterQueries(self, nums, queries):\n \"\"\"\n :type nums: List[int]\n :type queries: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def sumEvenAfterQueries(self, nums: List[int], queries: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* sumEvenAfterQueries(int* nums, int numsSize, int** queries, int queriesSize, int* queriesColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] SumEvenAfterQueries(int[] nums, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number[][]} queries\n * @return {number[]}\n */\nvar sumEvenAfterQueries = function(nums, queries) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer[][]} queries\n# @return {Integer[]}\ndef sum_even_after_queries(nums, queries)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func sumEvenAfterQueries(_ nums: [Int], _ queries: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func sumEvenAfterQueries(nums []int, queries [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def sumEvenAfterQueries(nums: Array[Int], queries: Array[Array[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun sumEvenAfterQueries(nums: IntArray, queries: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sum_even_after_queries(nums: Vec, queries: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer[][] $queries\n * @return Integer[]\n */\n function sumEvenAfterQueries($nums, $queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function sumEvenAfterQueries(nums: number[], queries: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (sum-even-after-queries nums queries)\n (-> (listof exact-integer?) (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0985](https://leetcode-cn.com/problems/sum-of-even-numbers-after-queries)", "[\u67e5\u8be2\u540e\u7684\u5076\u6570\u548c](/solution/0900-0999/0985.Sum%20of%20Even%20Numbers%20After%20Queries/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0985](https://leetcode.com/problems/sum-of-even-numbers-after-queries)", "[Sum of Even Numbers After Queries](/solution/0900-0999/0985.Sum%20of%20Even%20Numbers%20After%20Queries/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1026", "frontend_question_id": "0984", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/string-without-aaa-or-bbb", "url_en": "https://leetcode.com/problems/string-without-aaa-or-bbb", "relative_path_cn": "/solution/0900-0999/0984.String%20Without%20AAA%20or%20BBB/README.md", "relative_path_en": "/solution/0900-0999/0984.String%20Without%20AAA%20or%20BBB/README_EN.md", "title_cn": "\u4e0d\u542b AAA \u6216 BBB \u7684\u5b57\u7b26\u4e32", "title_en": "String Without AAA or BBB", "question_title_slug": "string-without-aaa-or-bbb", "content_en": "

Given two integers a and b, return any string s such that:

\n\n
    \n\t
  • s has length a + b and contains exactly a 'a' letters, and exactly b 'b' letters,
  • \n\t
  • The substring 'aaa' does not occur in s, and
  • \n\t
  • The substring 'bbb' does not occur in s.
  • \n
\n\n

 

\n

Example 1:

\n\n
\nInput: a = 1, b = 2\nOutput: "abb"\nExplanation: "abb", "bab" and "bba" are all correct answers.\n
\n\n

Example 2:

\n\n
\nInput: a = 4, b = 1\nOutput: "aabaa"\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 0 <= a, b <= 100
  • \n\t
  • It is guaranteed such an s exists for the given a and b.
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e24\u4e2a\u6574\u6570 A \u548c B\uff0c\u8fd4\u56de\u4efb\u610f\u5b57\u7b26\u4e32 S\uff0c\u8981\u6c42\u6ee1\u8db3\uff1a

\n\n
    \n\t
  • S \u7684\u957f\u5ea6\u4e3a A + B\uff0c\u4e14\u6b63\u597d\u5305\u542b A \u4e2a 'a' \u5b57\u6bcd\u4e0e B \u4e2a 'b' \u5b57\u6bcd\uff1b
  • \n\t
  • \u5b50\u4e32 'aaa' \u6ca1\u6709\u51fa\u73b0\u5728 S \u4e2d\uff1b
  • \n\t
  • \u5b50\u4e32 'bbb' \u6ca1\u6709\u51fa\u73b0\u5728 S \u4e2d\u3002
  • \n
\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aA = 1, B = 2\n\u8f93\u51fa\uff1a"abb"\n\u89e3\u91ca\uff1a"abb", "bab" \u548c "bba" \u90fd\u662f\u6b63\u786e\u7b54\u6848\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aA = 4, B = 1\n\u8f93\u51fa\uff1a"aabaa"
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 0 <= A <= 100
  2. \n\t
  3. 0 <= B <= 100
  4. \n\t
  5. \u5bf9\u4e8e\u7ed9\u5b9a\u7684 A \u548c B\uff0c\u4fdd\u8bc1\u5b58\u5728\u6ee1\u8db3\u8981\u6c42\u7684 S\u3002
  6. \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string strWithout3a3b(int a, int b) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String strWithout3a3b(int a, int b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def strWithout3a3b(self, a, b):\n \"\"\"\n :type a: int\n :type b: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def strWithout3a3b(self, a: int, b: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * strWithout3a3b(int a, int b){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string StrWithout3a3b(int a, int b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} a\n * @param {number} b\n * @return {string}\n */\nvar strWithout3a3b = function(a, b) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} a\n# @param {Integer} b\n# @return {String}\ndef str_without3a3b(a, b)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func strWithout3a3b(_ a: Int, _ b: Int) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func strWithout3a3b(a int, b int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def strWithout3a3b(a: Int, b: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun strWithout3a3b(a: Int, b: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn str_without3a3b(a: i32, b: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $a\n * @param Integer $b\n * @return String\n */\n function strWithout3a3b($a, $b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function strWithout3a3b(a: number, b: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (str-without3a3b a b)\n (-> exact-integer? exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0984](https://leetcode-cn.com/problems/string-without-aaa-or-bbb)", "[\u4e0d\u542b AAA \u6216 BBB \u7684\u5b57\u7b26\u4e32](/solution/0900-0999/0984.String%20Without%20AAA%20or%20BBB/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0984](https://leetcode.com/problems/string-without-aaa-or-bbb)", "[String Without AAA or BBB](/solution/0900-0999/0984.String%20Without%20AAA%20or%20BBB/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1025", "frontend_question_id": "0983", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-cost-for-tickets", "url_en": "https://leetcode.com/problems/minimum-cost-for-tickets", "relative_path_cn": "/solution/0900-0999/0983.Minimum%20Cost%20For%20Tickets/README.md", "relative_path_en": "/solution/0900-0999/0983.Minimum%20Cost%20For%20Tickets/README_EN.md", "title_cn": "\u6700\u4f4e\u7968\u4ef7", "title_en": "Minimum Cost For Tickets", "question_title_slug": "minimum-cost-for-tickets", "content_en": "

You have planned some train traveling one year in advance. The days of the year in which you will travel are given as an integer array days. Each day is an integer from 1 to 365.

\n\n

Train tickets are sold in three different ways:

\n\n
    \n\t
  • a 1-day pass is sold for costs[0] dollars,
  • \n\t
  • a 7-day pass is sold for costs[1] dollars, and
  • \n\t
  • a 30-day pass is sold for costs[2] dollars.
  • \n
\n\n

The passes allow that many days of consecutive travel.

\n\n
    \n\t
  • For example, if we get a 7-day pass on day 2, then we can travel for 7 days: 2, 3, 4, 5, 6, 7, and 8.
  • \n
\n\n

Return the minimum number of dollars you need to travel every day in the given list of days.

\n\n

 

\n

Example 1:

\n\n
\nInput: days = [1,4,6,7,8,20], costs = [2,7,15]\nOutput: 11\nExplanation: For example, here is one way to buy passes that lets you travel your travel plan:\nOn day 1, you bought a 1-day pass for costs[0] = $2, which covered day 1.\nOn day 3, you bought a 7-day pass for costs[1] = $7, which covered days 3, 4, ..., 9.\nOn day 20, you bought a 1-day pass for costs[0] = $2, which covered day 20.\nIn total, you spent $11 and covered all the days of your travel.\n
\n\n

Example 2:

\n\n
\nInput: days = [1,2,3,4,5,6,7,8,9,10,30,31], costs = [2,7,15]\nOutput: 17\nExplanation: For example, here is one way to buy passes that lets you travel your travel plan:\nOn day 1, you bought a 30-day pass for costs[2] = $15 which covered days 1, 2, ..., 30.\nOn day 31, you bought a 1-day pass for costs[0] = $2 which covered day 31.\nIn total, you spent $17 and covered all the days of your travel.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= days.length <= 365
  • \n\t
  • 1 <= days[i] <= 365
  • \n\t
  • days is in strictly increasing order.
  • \n\t
  • costs.length == 3
  • \n\t
  • 1 <= costs[i] <= 1000
  • \n
\n", "content_cn": "

\u5728\u4e00\u4e2a\u706b\u8f66\u65c5\u884c\u5f88\u53d7\u6b22\u8fce\u7684\u56fd\u5ea6\uff0c\u4f60\u63d0\u524d\u4e00\u5e74\u8ba1\u5212\u4e86\u4e00\u4e9b\u706b\u8f66\u65c5\u884c\u3002\u5728\u63a5\u4e0b\u6765\u7684\u4e00\u5e74\u91cc\uff0c\u4f60\u8981\u65c5\u884c\u7684\u65e5\u5b50\u5c06\u4ee5\u4e00\u4e2a\u540d\u4e3a days \u7684\u6570\u7ec4\u7ed9\u51fa\u3002\u6bcf\u4e00\u9879\u662f\u4e00\u4e2a\u4ece 1 \u5230 365 \u7684\u6574\u6570\u3002

\n\n

\u706b\u8f66\u7968\u6709\u4e09\u79cd\u4e0d\u540c\u7684\u9500\u552e\u65b9\u5f0f\uff1a

\n\n
    \n\t
  • \u4e00\u5f20\u4e3a\u671f\u4e00\u5929\u7684\u901a\u884c\u8bc1\u552e\u4ef7\u4e3a costs[0] \u7f8e\u5143\uff1b
  • \n\t
  • \u4e00\u5f20\u4e3a\u671f\u4e03\u5929\u7684\u901a\u884c\u8bc1\u552e\u4ef7\u4e3a costs[1] \u7f8e\u5143\uff1b
  • \n\t
  • \u4e00\u5f20\u4e3a\u671f\u4e09\u5341\u5929\u7684\u901a\u884c\u8bc1\u552e\u4ef7\u4e3a costs[2] \u7f8e\u5143\u3002
  • \n
\n\n

\u901a\u884c\u8bc1\u5141\u8bb8\u6570\u5929\u65e0\u9650\u5236\u7684\u65c5\u884c\u3002 \u4f8b\u5982\uff0c\u5982\u679c\u6211\u4eec\u5728\u7b2c 2 \u5929\u83b7\u5f97\u4e00\u5f20\u4e3a\u671f 7 \u5929\u7684\u901a\u884c\u8bc1\uff0c\u90a3\u4e48\u6211\u4eec\u53ef\u4ee5\u8fde\u7740\u65c5\u884c 7 \u5929\uff1a\u7b2c 2 \u5929\u3001\u7b2c 3 \u5929\u3001\u7b2c 4 \u5929\u3001\u7b2c 5 \u5929\u3001\u7b2c 6 \u5929\u3001\u7b2c 7 \u5929\u548c\u7b2c 8 \u5929\u3002

\n\n

\u8fd4\u56de\u4f60\u60f3\u8981\u5b8c\u6210\u5728\u7ed9\u5b9a\u7684\u5217\u8868 days \u4e2d\u5217\u51fa\u7684\u6bcf\u4e00\u5929\u7684\u65c5\u884c\u6240\u9700\u8981\u7684\u6700\u4f4e\u6d88\u8d39\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1adays = [1,4,6,7,8,20], costs = [2,7,15]\n\u8f93\u51fa\uff1a11\n\u89e3\u91ca\uff1a \n\u4f8b\u5982\uff0c\u8fd9\u91cc\u6709\u4e00\u79cd\u8d2d\u4e70\u901a\u884c\u8bc1\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u8ba9\u4f60\u5b8c\u6210\u4f60\u7684\u65c5\u884c\u8ba1\u5212\uff1a\n\u5728\u7b2c 1 \u5929\uff0c\u4f60\u82b1\u4e86 costs[0] = $2 \u4e70\u4e86\u4e00\u5f20\u4e3a\u671f 1 \u5929\u7684\u901a\u884c\u8bc1\uff0c\u5b83\u5c06\u5728\u7b2c 1 \u5929\u751f\u6548\u3002\n\u5728\u7b2c 3 \u5929\uff0c\u4f60\u82b1\u4e86 costs[1] = $7 \u4e70\u4e86\u4e00\u5f20\u4e3a\u671f 7 \u5929\u7684\u901a\u884c\u8bc1\uff0c\u5b83\u5c06\u5728\u7b2c 3, 4, ..., 9 \u5929\u751f\u6548\u3002\n\u5728\u7b2c 20 \u5929\uff0c\u4f60\u82b1\u4e86 costs[0] = $2 \u4e70\u4e86\u4e00\u5f20\u4e3a\u671f 1 \u5929\u7684\u901a\u884c\u8bc1\uff0c\u5b83\u5c06\u5728\u7b2c 20 \u5929\u751f\u6548\u3002\n\u4f60\u603b\u5171\u82b1\u4e86 $11\uff0c\u5e76\u5b8c\u6210\u4e86\u4f60\u8ba1\u5212\u7684\u6bcf\u4e00\u5929\u65c5\u884c\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1adays = [1,2,3,4,5,6,7,8,9,10,30,31], costs = [2,7,15]\n\u8f93\u51fa\uff1a17\n\u89e3\u91ca\uff1a\n\u4f8b\u5982\uff0c\u8fd9\u91cc\u6709\u4e00\u79cd\u8d2d\u4e70\u901a\u884c\u8bc1\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u8ba9\u4f60\u5b8c\u6210\u4f60\u7684\u65c5\u884c\u8ba1\u5212\uff1a \n\u5728\u7b2c 1 \u5929\uff0c\u4f60\u82b1\u4e86 costs[2] = $15 \u4e70\u4e86\u4e00\u5f20\u4e3a\u671f 30 \u5929\u7684\u901a\u884c\u8bc1\uff0c\u5b83\u5c06\u5728\u7b2c 1, 2, ..., 30 \u5929\u751f\u6548\u3002\n\u5728\u7b2c 31 \u5929\uff0c\u4f60\u82b1\u4e86 costs[0] = $2 \u4e70\u4e86\u4e00\u5f20\u4e3a\u671f 1 \u5929\u7684\u901a\u884c\u8bc1\uff0c\u5b83\u5c06\u5728\u7b2c 31 \u5929\u751f\u6548\u3002 \n\u4f60\u603b\u5171\u82b1\u4e86 $17\uff0c\u5e76\u5b8c\u6210\u4e86\u4f60\u8ba1\u5212\u7684\u6bcf\u4e00\u5929\u65c5\u884c\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= days.length <= 365
  2. \n\t
  3. 1 <= days[i] <= 365
  4. \n\t
  5. days \u6309\u987a\u5e8f\u4e25\u683c\u9012\u589e
  6. \n\t
  7. costs.length == 3
  8. \n\t
  9. 1 <= costs[i] <= 1000
  10. \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int mincostTickets(vector& days, vector& costs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int mincostTickets(int[] days, int[] costs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def mincostTickets(self, days, costs):\n \"\"\"\n :type days: List[int]\n :type costs: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def mincostTickets(self, days: List[int], costs: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint mincostTickets(int* days, int daysSize, int* costs, int costsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MincostTickets(int[] days, int[] costs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} days\n * @param {number[]} costs\n * @return {number}\n */\nvar mincostTickets = function(days, costs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} days\n# @param {Integer[]} costs\n# @return {Integer}\ndef mincost_tickets(days, costs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func mincostTickets(_ days: [Int], _ costs: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func mincostTickets(days []int, costs []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def mincostTickets(days: Array[Int], costs: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun mincostTickets(days: IntArray, costs: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn mincost_tickets(days: Vec, costs: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $days\n * @param Integer[] $costs\n * @return Integer\n */\n function mincostTickets($days, $costs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function mincostTickets(days: number[], costs: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (mincost-tickets days costs)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0983](https://leetcode-cn.com/problems/minimum-cost-for-tickets)", "[\u6700\u4f4e\u7968\u4ef7](/solution/0900-0999/0983.Minimum%20Cost%20For%20Tickets/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0983](https://leetcode.com/problems/minimum-cost-for-tickets)", "[Minimum Cost For Tickets](/solution/0900-0999/0983.Minimum%20Cost%20For%20Tickets/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "1024", "frontend_question_id": "0982", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/triples-with-bitwise-and-equal-to-zero", "url_en": "https://leetcode.com/problems/triples-with-bitwise-and-equal-to-zero", "relative_path_cn": "/solution/0900-0999/0982.Triples%20with%20Bitwise%20AND%20Equal%20To%20Zero/README.md", "relative_path_en": "/solution/0900-0999/0982.Triples%20with%20Bitwise%20AND%20Equal%20To%20Zero/README_EN.md", "title_cn": "\u6309\u4f4d\u4e0e\u4e3a\u96f6\u7684\u4e09\u5143\u7ec4", "title_en": "Triples with Bitwise AND Equal To Zero", "question_title_slug": "triples-with-bitwise-and-equal-to-zero", "content_en": "

Given an array of integers nums, find the number of triples of indices (i, j, k) such that:

\n\n
    \n\t
  • 0 <= i < nums.length
  • \n\t
  • 0 <= j < nums.length
  • \n\t
  • 0 <= k < nums.length
  • \n\t
  • nums[i] & nums[j] & nums[k] == 0, where & represents the bitwise-AND operator.
  • \n
\n\n

 

\n\n

Example 1:

\n\n
\nInput: nums = [2,1,3]\nOutput: 12\nExplanation: We could choose the following i, j, k triples:\n(i=0, j=0, k=1) : 2 & 2 & 1\n(i=0, j=1, k=0) : 2 & 1 & 2\n(i=0, j=1, k=1) : 2 & 1 & 1\n(i=0, j=1, k=2) : 2 & 1 & 3\n(i=0, j=2, k=1) : 2 & 3 & 1\n(i=1, j=0, k=0) : 1 & 2 & 2\n(i=1, j=0, k=1) : 1 & 2 & 1\n(i=1, j=0, k=2) : 1 & 2 & 3\n(i=1, j=1, k=0) : 1 & 1 & 2\n(i=1, j=2, k=0) : 1 & 3 & 2\n(i=2, j=0, k=1) : 3 & 2 & 1\n(i=2, j=1, k=0) : 3 & 1 & 2\n
\n\n

 

\n\n

Note:

\n\n
    \n\t
  1. 1 <= nums.length <= 1000
  2. \n\t
  3. 0 <= nums[i] < 216
  4. \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 A\uff0c\u627e\u51fa\u7d22\u5f15\u4e3a (i, j, k) \u7684\u4e09\u5143\u7ec4\uff0c\u4f7f\u5f97\uff1a

\n\n
    \n\t
  • 0 <= i < A.length
  • \n\t
  • 0 <= j < A.length
  • \n\t
  • 0 <= k < A.length
  • \n\t
  • A[i] & A[j] & A[k] == 0\uff0c\u5176\u4e2d & \u8868\u793a\u6309\u4f4d\u4e0e\uff08AND\uff09\u64cd\u4f5c\u7b26\u3002
  • \n
\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1a[2,1,3]\n\u8f93\u51fa\uff1a12\n\u89e3\u91ca\uff1a\u6211\u4eec\u53ef\u4ee5\u9009\u51fa\u5982\u4e0b i, j, k \u4e09\u5143\u7ec4\uff1a\n(i=0, j=0, k=1) : 2 & 2 & 1\n(i=0, j=1, k=0) : 2 & 1 & 2\n(i=0, j=1, k=1) : 2 & 1 & 1\n(i=0, j=1, k=2) : 2 & 1 & 3\n(i=0, j=2, k=1) : 2 & 3 & 1\n(i=1, j=0, k=0) : 1 & 2 & 2\n(i=1, j=0, k=1) : 1 & 2 & 1\n(i=1, j=0, k=2) : 1 & 2 & 3\n(i=1, j=1, k=0) : 1 & 1 & 2\n(i=1, j=2, k=0) : 1 & 3 & 2\n(i=2, j=0, k=1) : 3 & 2 & 1\n(i=2, j=1, k=0) : 3 & 1 & 2\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= A.length <= 1000
  2. \n\t
  3. 0 <= A[i] < 2^16
  4. \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countTriplets(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countTriplets(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countTriplets(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countTriplets(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countTriplets(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountTriplets(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar countTriplets = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef count_triplets(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countTriplets(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countTriplets(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countTriplets(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countTriplets(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_triplets(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function countTriplets($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countTriplets(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-triplets nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0982](https://leetcode-cn.com/problems/triples-with-bitwise-and-equal-to-zero)", "[\u6309\u4f4d\u4e0e\u4e3a\u96f6\u7684\u4e09\u5143\u7ec4](/solution/0900-0999/0982.Triples%20with%20Bitwise%20AND%20Equal%20To%20Zero/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0982](https://leetcode.com/problems/triples-with-bitwise-and-equal-to-zero)", "[Triples with Bitwise AND Equal To Zero](/solution/0900-0999/0982.Triples%20with%20Bitwise%20AND%20Equal%20To%20Zero/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1023", "frontend_question_id": "0981", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/time-based-key-value-store", "url_en": "https://leetcode.com/problems/time-based-key-value-store", "relative_path_cn": "/solution/0900-0999/0981.Time%20Based%20Key-Value%20Store/README.md", "relative_path_en": "/solution/0900-0999/0981.Time%20Based%20Key-Value%20Store/README_EN.md", "title_cn": "\u57fa\u4e8e\u65f6\u95f4\u7684\u952e\u503c\u5b58\u50a8", "title_en": "Time Based Key-Value Store", "question_title_slug": "time-based-key-value-store", "content_en": "

Create a timebased key-value store class TimeMap, that supports two operations.

\r\n\r\n

1. set(string key, string value, int timestamp)

\r\n\r\n
    \r\n\t
  • Stores the key and value, along with the given timestamp.
  • \r\n
\r\n\r\n

2. get(string key, int timestamp)

\r\n\r\n
    \r\n\t
  • Returns a value such that set(key, value, timestamp_prev) was called previously, with timestamp_prev <= timestamp.
  • \r\n\t
  • If there are multiple such values, it returns the one with the largest timestamp_prev.
  • \r\n\t
  • If there are no values, it returns the empty string ("").
  • \r\n
\r\n\r\n

 

\r\n\r\n
\r\n

Example 1:

\r\n\r\n
\r\nInput: inputs = ["TimeMap","set","get","get","set","get","get"], inputs = [[],["foo","bar",1],["foo",1],["foo",3],["foo","bar2",4],["foo",4],["foo",5]]\r\nOutput: [null,null,"bar","bar",null,"bar2","bar2"]\r\nExplanation:   \r\nTimeMap kv;   \r\nkv.set("foo", "bar", 1); // store the key "foo" and value "bar" along with timestamp = 1   \r\nkv.get("foo", 1);  // output "bar"   \r\nkv.get("foo", 3); // output "bar" since there is no value corresponding to foo at timestamp 3 and timestamp 2, then the only value is at timestamp 1 ie "bar"   \r\nkv.set("foo", "bar2", 4);   \r\nkv.get("foo", 4); // output "bar2"   \r\nkv.get("foo", 5); //output "bar2"   \r\n\r\n
\r\n\r\n
\r\n

Example 2:

\r\n\r\n
\r\nInput: inputs = ["TimeMap","set","set","get","get","get","get","get"], inputs = [[],["love","high",10],["love","low",20],["love",5],["love",10],["love",15],["love",20],["love",25]]\r\nOutput: [null,null,null,"","high","high","low","low"]\r\n
\r\n
\r\n
\r\n\r\n

 

\r\n\r\n

Note:

\r\n\r\n
    \r\n\t
  1. All key/value strings are lowercase.
  2. \r\n\t
  3. All key/value strings have length in the range [1, 100]
  4. \r\n\t
  5. The timestamps for all TimeMap.set operations are strictly increasing.
  6. \r\n\t
  7. 1 <= timestamp <= 10^7
  8. \r\n\t
  9. TimeMap.set and TimeMap.get functions will be called a total of 120000 times (combined) per test case.
  10. \r\n
\r\n", "content_cn": "

\u521b\u5efa\u4e00\u4e2a\u57fa\u4e8e\u65f6\u95f4\u7684\u952e\u503c\u5b58\u50a8\u7c7b TimeMap\uff0c\u5b83\u652f\u6301\u4e0b\u9762\u4e24\u4e2a\u64cd\u4f5c\uff1a

\n\n

1. set(string key, string value, int timestamp)

\n\n
    \n\t
  • \u5b58\u50a8\u952e key\u3001\u503c value\uff0c\u4ee5\u53ca\u7ed9\u5b9a\u7684\u65f6\u95f4\u6233 timestamp\u3002
  • \n
\n\n

2. get(string key, int timestamp)

\n\n
    \n\t
  • \u8fd4\u56de\u5148\u524d\u8c03\u7528 set(key, value, timestamp_prev) \u6240\u5b58\u50a8\u7684\u503c\uff0c\u5176\u4e2d timestamp_prev <= timestamp\u3002
  • \n\t
  • \u5982\u679c\u6709\u591a\u4e2a\u8fd9\u6837\u7684\u503c\uff0c\u5219\u8fd4\u56de\u5bf9\u5e94\u6700\u5927\u7684  timestamp_prev \u7684\u90a3\u4e2a\u503c\u3002
  • \n\t
  • \u5982\u679c\u6ca1\u6709\u503c\uff0c\u5219\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32\uff08""\uff09\u3002
  • \n
\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1ainputs = ["TimeMap","set","get","get","set","get","get"], inputs = [[],["foo","bar",1],["foo",1],["foo",3],["foo","bar2",4],["foo",4],["foo",5]]\n\u8f93\u51fa\uff1a[null,null,"bar","bar",null,"bar2","bar2"]\n\u89e3\u91ca\uff1a  \nTimeMap kv;   \nkv.set("foo", "bar", 1); // \u5b58\u50a8\u952e "foo" \u548c\u503c "bar" \u4ee5\u53ca\u65f6\u95f4\u6233 timestamp = 1   \nkv.get("foo", 1);  // \u8f93\u51fa "bar"   \nkv.get("foo", 3); // \u8f93\u51fa "bar" \u56e0\u4e3a\u5728\u65f6\u95f4\u6233 3 \u548c\u65f6\u95f4\u6233 2 \u5904\u6ca1\u6709\u5bf9\u5e94 "foo" \u7684\u503c\uff0c\u6240\u4ee5\u552f\u4e00\u7684\u503c\u4f4d\u4e8e\u65f6\u95f4\u6233 1 \u5904\uff08\u5373 "bar"\uff09   \nkv.set("foo", "bar2", 4);   \nkv.get("foo", 4); // \u8f93\u51fa "bar2"   \nkv.get("foo", 5); // \u8f93\u51fa "bar2"   \n\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1ainputs = ["TimeMap","set","set","get","get","get","get","get"], inputs = [[],["love","high",10],["love","low",20],["love",5],["love",10],["love",15],["love",20],["love",25]]\n\u8f93\u51fa\uff1a[null,null,null,"","high","high","low","low"]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. \u6240\u6709\u7684\u952e/\u503c\u5b57\u7b26\u4e32\u90fd\u662f\u5c0f\u5199\u7684\u3002
  2. \n\t
  3. \u6240\u6709\u7684\u952e/\u503c\u5b57\u7b26\u4e32\u957f\u5ea6\u90fd\u5728 [1, 100] \u8303\u56f4\u5185\u3002
  4. \n\t
  5. \u6240\u6709 TimeMap.set \u64cd\u4f5c\u4e2d\u7684\u65f6\u95f4\u6233 timestamps \u90fd\u662f\u4e25\u683c\u9012\u589e\u7684\u3002
  6. \n\t
  7. 1 <= timestamp <= 10^7
  8. \n\t
  9. TimeMap.set \u548c TimeMap.get \u51fd\u6570\u5728\u6bcf\u4e2a\u6d4b\u8bd5\u7528\u4f8b\u4e2d\u5c06\uff08\u7ec4\u5408\uff09\u8c03\u7528\u603b\u8ba1 120000 \u6b21\u3002
  10. \n
\n", "tags_en": ["Hash Table", "Binary Search"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class TimeMap {\npublic:\n /** Initialize your data structure here. */\n TimeMap() {\n\n }\n \n void set(string key, string value, int timestamp) {\n\n }\n \n string get(string key, int timestamp) {\n\n }\n};\n\n/**\n * Your TimeMap object will be instantiated and called as such:\n * TimeMap* obj = new TimeMap();\n * obj->set(key,value,timestamp);\n * string param_2 = obj->get(key,timestamp);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class TimeMap {\n\n /** Initialize your data structure here. */\n public TimeMap() {\n\n }\n \n public void set(String key, String value, int timestamp) {\n\n }\n \n public String get(String key, int timestamp) {\n\n }\n}\n\n/**\n * Your TimeMap object will be instantiated and called as such:\n * TimeMap obj = new TimeMap();\n * obj.set(key,value,timestamp);\n * String param_2 = obj.get(key,timestamp);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class TimeMap(object):\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n \n\n def set(self, key, value, timestamp):\n \"\"\"\n :type key: str\n :type value: str\n :type timestamp: int\n :rtype: None\n \"\"\"\n \n\n def get(self, key, timestamp):\n \"\"\"\n :type key: str\n :type timestamp: int\n :rtype: str\n \"\"\"\n \n\n\n# Your TimeMap object will be instantiated and called as such:\n# obj = TimeMap()\n# obj.set(key,value,timestamp)\n# param_2 = obj.get(key,timestamp)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class TimeMap:\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n \n\n def set(self, key: str, value: str, timestamp: int) -> None:\n \n\n def get(self, key: str, timestamp: int) -> str:\n \n\n\n# Your TimeMap object will be instantiated and called as such:\n# obj = TimeMap()\n# obj.set(key,value,timestamp)\n# param_2 = obj.get(key,timestamp)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} TimeMap;\n\n/** Initialize your data structure here. */\n\nTimeMap* timeMapCreate() {\n \n}\n\nvoid timeMapSet(TimeMap* obj, char * key, char * value, int timestamp) {\n \n}\n\nchar * timeMapGet(TimeMap* obj, char * key, int timestamp) {\n \n}\n\nvoid timeMapFree(TimeMap* obj) {\n \n}\n\n/**\n * Your TimeMap struct will be instantiated and called as such:\n * TimeMap* obj = timeMapCreate();\n * timeMapSet(obj, key, value, timestamp);\n \n * char * param_2 = timeMapGet(obj, key, timestamp);\n \n * timeMapFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class TimeMap {\n\n /** Initialize your data structure here. */\n public TimeMap() {\n\n }\n \n public void Set(string key, string value, int timestamp) {\n\n }\n \n public string Get(string key, int timestamp) {\n\n }\n}\n\n/**\n * Your TimeMap object will be instantiated and called as such:\n * TimeMap obj = new TimeMap();\n * obj.Set(key,value,timestamp);\n * string param_2 = obj.Get(key,timestamp);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Initialize your data structure here.\n */\nvar TimeMap = function() {\n\n};\n\n/** \n * @param {string} key \n * @param {string} value \n * @param {number} timestamp\n * @return {void}\n */\nTimeMap.prototype.set = function(key, value, timestamp) {\n\n};\n\n/** \n * @param {string} key \n * @param {number} timestamp\n * @return {string}\n */\nTimeMap.prototype.get = function(key, timestamp) {\n\n};\n\n/**\n * Your TimeMap object will be instantiated and called as such:\n * var obj = new TimeMap()\n * obj.set(key,value,timestamp)\n * var param_2 = obj.get(key,timestamp)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class TimeMap\n\n=begin\n Initialize your data structure here.\n=end\n def initialize()\n\n end\n\n\n=begin\n :type key: String\n :type value: String\n :type timestamp: Integer\n :rtype: Void\n=end\n def set(key, value, timestamp)\n\n end\n\n\n=begin\n :type key: String\n :type timestamp: Integer\n :rtype: String\n=end\n def get(key, timestamp)\n\n end\n\n\nend\n\n# Your TimeMap object will be instantiated and called as such:\n# obj = TimeMap.new()\n# obj.set(key, value, timestamp)\n# param_2 = obj.get(key, timestamp)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass TimeMap {\n\n /** Initialize your data structure here. */\n init() {\n \n }\n \n func set(_ key: String, _ value: String, _ timestamp: Int) {\n \n }\n \n func get(_ key: String, _ timestamp: Int) -> String {\n \n }\n}\n\n/**\n * Your TimeMap object will be instantiated and called as such:\n * let obj = TimeMap()\n * obj.set(key, value, timestamp)\n * let ret_2: String = obj.get(key, timestamp)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type TimeMap struct {\n\n}\n\n\n/** Initialize your data structure here. */\nfunc Constructor() TimeMap {\n\n}\n\n\nfunc (this *TimeMap) Set(key string, value string, timestamp int) {\n\n}\n\n\nfunc (this *TimeMap) Get(key string, timestamp int) string {\n\n}\n\n\n/**\n * Your TimeMap object will be instantiated and called as such:\n * obj := Constructor();\n * obj.Set(key,value,timestamp);\n * param_2 := obj.Get(key,timestamp);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class TimeMap() {\n\n /** Initialize your data structure here. */\n\n\n def set(key: String, value: String, timestamp: Int) {\n\n }\n\n def get(key: String, timestamp: Int): String = {\n\n }\n\n}\n\n/**\n * Your TimeMap object will be instantiated and called as such:\n * var obj = new TimeMap()\n * obj.set(key,value,timestamp)\n * var param_2 = obj.get(key,timestamp)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class TimeMap() {\n\n /** Initialize your data structure here. */\n\n\n fun set(key: String, value: String, timestamp: Int) {\n\n }\n\n fun get(key: String, timestamp: Int): String {\n\n }\n\n}\n\n/**\n * Your TimeMap object will be instantiated and called as such:\n * var obj = TimeMap()\n * obj.set(key,value,timestamp)\n * var param_2 = obj.get(key,timestamp)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct TimeMap {\n\n}\n\n\n/** \n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl TimeMap {\n\n /** Initialize your data structure here. */\n fn new() -> Self {\n \n }\n \n fn set(&self, key: String, value: String, timestamp: i32) {\n \n }\n \n fn get(&self, key: String, timestamp: i32) -> String {\n \n }\n}\n\n/**\n * Your TimeMap object will be instantiated and called as such:\n * let obj = TimeMap::new();\n * obj.set(key, value, timestamp);\n * let ret_2: String = obj.get(key, timestamp);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class TimeMap {\n /**\n * Initialize your data structure here.\n */\n function __construct() {\n \n }\n \n /**\n * @param String $key\n * @param String $value\n * @param Integer $timestamp\n * @return NULL\n */\n function set($key, $value, $timestamp) {\n \n }\n \n /**\n * @param String $key\n * @param Integer $timestamp\n * @return String\n */\n function get($key, $timestamp) {\n \n }\n}\n\n/**\n * Your TimeMap object will be instantiated and called as such:\n * $obj = TimeMap();\n * $obj->set($key, $value, $timestamp);\n * $ret_2 = $obj->get($key, $timestamp);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class TimeMap {\n constructor() {\n\n }\n\n set(key: string, value: string, timestamp: number): void {\n\n }\n\n get(key: string, timestamp: number): string {\n\n }\n}\n\n/**\n * Your TimeMap object will be instantiated and called as such:\n * var obj = new TimeMap()\n * obj.set(key,value,timestamp)\n * var param_2 = obj.get(key,timestamp)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define time-map%\n (class object%\n (super-new)\n (init-field)\n \n ; set : string? string? exact-integer? -> void?\n (define/public (set key value timestamp)\n\n )\n ; get : string? exact-integer? -> string?\n (define/public (get key timestamp)\n\n )))\n\n;; Your time-map% object will be instantiated and called as such:\n;; (define obj (new time-map%))\n;; (send obj set key value timestamp)\n;; (define param_2 (send obj get key timestamp))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0981](https://leetcode-cn.com/problems/time-based-key-value-store)", "[\u57fa\u4e8e\u65f6\u95f4\u7684\u952e\u503c\u5b58\u50a8](/solution/0900-0999/0981.Time%20Based%20Key-Value%20Store/README.md)", "`\u54c8\u5e0c\u8868`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0981](https://leetcode.com/problems/time-based-key-value-store)", "[Time Based Key-Value Store](/solution/0900-0999/0981.Time%20Based%20Key-Value%20Store/README_EN.md)", "`Hash Table`,`Binary Search`", "Medium", ""]}, {"question_id": "1022", "frontend_question_id": "0980", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/unique-paths-iii", "url_en": "https://leetcode.com/problems/unique-paths-iii", "relative_path_cn": "/solution/0900-0999/0980.Unique%20Paths%20III/README.md", "relative_path_en": "/solution/0900-0999/0980.Unique%20Paths%20III/README_EN.md", "title_cn": "\u4e0d\u540c\u8def\u5f84 III", "title_en": "Unique Paths III", "question_title_slug": "unique-paths-iii", "content_en": "

On a 2-dimensional grid, there are 4 types of squares:

\r\n\r\n
    \r\n\t
  • 1 represents the starting square.  There is exactly one starting square.
  • \r\n\t
  • 2 represents the ending square.  There is exactly one ending square.
  • \r\n\t
  • 0 represents empty squares we can walk over.
  • \r\n\t
  • -1 represents obstacles that we cannot walk over.
  • \r\n
\r\n\r\n

Return the number of 4-directional walks from the starting square to the ending square, that walk over every non-obstacle square exactly once.

\r\n\r\n

 

\r\n\r\n
\r\n

Example 1:

\r\n\r\n
\r\nInput: [[1,0,0,0],[0,0,0,0],[0,0,2,-1]]\r\nOutput: 2\r\nExplanation: We have the following two paths: \r\n1. (0,0),(0,1),(0,2),(0,3),(1,3),(1,2),(1,1),(1,0),(2,0),(2,1),(2,2)\r\n2. (0,0),(1,0),(2,0),(2,1),(1,1),(0,1),(0,2),(0,3),(1,3),(1,2),(2,2)
\r\n\r\n
\r\n

Example 2:

\r\n\r\n
\r\nInput: [[1,0,0,0],[0,0,0,0],[0,0,0,2]]\r\nOutput: 4\r\nExplanation: We have the following four paths: \r\n1. (0,0),(0,1),(0,2),(0,3),(1,3),(1,2),(1,1),(1,0),(2,0),(2,1),(2,2),(2,3)\r\n2. (0,0),(0,1),(1,1),(1,0),(2,0),(2,1),(2,2),(1,2),(0,2),(0,3),(1,3),(2,3)\r\n3. (0,0),(1,0),(2,0),(2,1),(2,2),(1,2),(1,1),(0,1),(0,2),(0,3),(1,3),(2,3)\r\n4. (0,0),(1,0),(2,0),(2,1),(1,1),(0,1),(0,2),(0,3),(1,3),(1,2),(2,2),(2,3)
\r\n\r\n
\r\n

Example 3:

\r\n\r\n
\r\nInput: [[0,1],[2,0]]\r\nOutput: 0\r\nExplanation: \r\nThere is no path that walks over every empty square exactly once.\r\nNote that the starting and ending square can be anywhere in the grid.\r\n
\r\n
\r\n
\r\n
\r\n\r\n

 

\r\n\r\n

Note:

\r\n\r\n
    \r\n\t
  1. 1 <= grid.length * grid[0].length <= 20
  2. \r\n
", "content_cn": "

\u5728\u4e8c\u7ef4\u7f51\u683c grid \u4e0a\uff0c\u6709 4 \u79cd\u7c7b\u578b\u7684\u65b9\u683c\uff1a

\n\n
    \n\t
  • 1 \u8868\u793a\u8d77\u59cb\u65b9\u683c\u3002\u4e14\u53ea\u6709\u4e00\u4e2a\u8d77\u59cb\u65b9\u683c\u3002
  • \n\t
  • 2 \u8868\u793a\u7ed3\u675f\u65b9\u683c\uff0c\u4e14\u53ea\u6709\u4e00\u4e2a\u7ed3\u675f\u65b9\u683c\u3002
  • \n\t
  • 0 \u8868\u793a\u6211\u4eec\u53ef\u4ee5\u8d70\u8fc7\u7684\u7a7a\u65b9\u683c\u3002
  • \n\t
  • -1 \u8868\u793a\u6211\u4eec\u65e0\u6cd5\u8de8\u8d8a\u7684\u969c\u788d\u3002
  • \n
\n\n

\u8fd4\u56de\u5728\u56db\u4e2a\u65b9\u5411\uff08\u4e0a\u3001\u4e0b\u3001\u5de6\u3001\u53f3\uff09\u4e0a\u884c\u8d70\u65f6\uff0c\u4ece\u8d77\u59cb\u65b9\u683c\u5230\u7ed3\u675f\u65b9\u683c\u7684\u4e0d\u540c\u8def\u5f84\u7684\u6570\u76ee\u3002

\n\n

\u6bcf\u4e00\u4e2a\u65e0\u969c\u788d\u65b9\u683c\u90fd\u8981\u901a\u8fc7\u4e00\u6b21\uff0c\u4f46\u662f\u4e00\u6761\u8def\u5f84\u4e2d\u4e0d\u80fd\u91cd\u590d\u901a\u8fc7\u540c\u4e00\u4e2a\u65b9\u683c\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a[[1,0,0,0],[0,0,0,0],[0,0,2,-1]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6211\u4eec\u6709\u4ee5\u4e0b\u4e24\u6761\u8def\u5f84\uff1a\n1. (0,0),(0,1),(0,2),(0,3),(1,3),(1,2),(1,1),(1,0),(2,0),(2,1),(2,2)\n2. (0,0),(1,0),(2,0),(2,1),(1,1),(0,1),(0,2),(0,3),(1,3),(1,2),(2,2)
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a[[1,0,0,0],[0,0,0,0],[0,0,0,2]]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u6211\u4eec\u6709\u4ee5\u4e0b\u56db\u6761\u8def\u5f84\uff1a \n1. (0,0),(0,1),(0,2),(0,3),(1,3),(1,2),(1,1),(1,0),(2,0),(2,1),(2,2),(2,3)\n2. (0,0),(0,1),(1,1),(1,0),(2,0),(2,1),(2,2),(1,2),(0,2),(0,3),(1,3),(2,3)\n3. (0,0),(1,0),(2,0),(2,1),(2,2),(1,2),(1,1),(0,1),(0,2),(0,3),(1,3),(2,3)\n4. (0,0),(1,0),(2,0),(2,1),(1,1),(0,1),(0,2),(0,3),(1,3),(1,2),(2,2),(2,3)
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1a[[0,1],[2,0]]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\n\u6ca1\u6709\u4e00\u6761\u8def\u80fd\u5b8c\u5168\u7a7f\u8fc7\u6bcf\u4e00\u4e2a\u7a7a\u7684\u65b9\u683c\u4e00\u6b21\u3002\n\u8bf7\u6ce8\u610f\uff0c\u8d77\u59cb\u548c\u7ed3\u675f\u65b9\u683c\u53ef\u4ee5\u4f4d\u4e8e\u7f51\u683c\u4e2d\u7684\u4efb\u610f\u4f4d\u7f6e\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= grid.length * grid[0].length <= 20
  • \n
\n", "tags_en": ["Depth-first Search", "Backtracking"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int uniquePathsIII(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int uniquePathsIII(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def uniquePathsIII(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def uniquePathsIII(self, grid: List[List[int]]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint uniquePathsIII(int** grid, int gridSize, int* gridColSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int UniquePathsIII(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar uniquePathsIII = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef unique_paths_iii(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func uniquePathsIII(_ grid: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func uniquePathsIII(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def uniquePathsIII(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun uniquePathsIII(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn unique_paths_iii(grid: Vec>) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function uniquePathsIII($grid) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function uniquePathsIII(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (unique-paths-iii grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0980](https://leetcode-cn.com/problems/unique-paths-iii)", "[\u4e0d\u540c\u8def\u5f84 III](/solution/0900-0999/0980.Unique%20Paths%20III/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u56de\u6eaf\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[0980](https://leetcode.com/problems/unique-paths-iii)", "[Unique Paths III](/solution/0900-0999/0980.Unique%20Paths%20III/README_EN.md)", "`Depth-first Search`,`Backtracking`", "Hard", ""]}, {"question_id": "1021", "frontend_question_id": "0979", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/distribute-coins-in-binary-tree", "url_en": "https://leetcode.com/problems/distribute-coins-in-binary-tree", "relative_path_cn": "/solution/0900-0999/0979.Distribute%20Coins%20in%20Binary%20Tree/README.md", "relative_path_en": "/solution/0900-0999/0979.Distribute%20Coins%20in%20Binary%20Tree/README_EN.md", "title_cn": "\u5728\u4e8c\u53c9\u6811\u4e2d\u5206\u914d\u786c\u5e01", "title_en": "Distribute Coins in Binary Tree", "question_title_slug": "distribute-coins-in-binary-tree", "content_en": "

You are given the root of a binary tree with n nodes where each node in the tree has node.val coins. There are n coins in total throughout the whole tree.

\n\n

In one move, we may choose two adjacent nodes and move one coin from one node to another. A move may be from parent to child, or from child to parent.

\n\n

Return the minimum number of moves required to make every node have exactly one coin.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: root = [3,0,0]\nOutput: 2\nExplanation: From the root of the tree, we move one coin to its left child, and one coin to its right child.\n
\n\n

Example 2:

\n\"\"\n
\nInput: root = [0,3,0]\nOutput: 3\nExplanation: From the left child of the root, we move two coins to the root [taking two moves]. Then, we move one coin from the root of the tree to the right child.\n
\n\n

Example 3:

\n\"\"\n
\nInput: root = [1,0,2]\nOutput: 2\n
\n\n

Example 4:

\n\"\"\n
\nInput: root = [1,0,0,null,3]\nOutput: 4\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The number of nodes in the tree is n.
  • \n\t
  • 1 <= n <= 100
  • \n\t
  • 0 <= Node.val <= n
  • \n\t
  • The sum of all Node.val is n.
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u6709 N \u4e2a\u7ed3\u70b9\u7684\u4e8c\u53c9\u6811\u7684\u6839\u7ed3\u70b9 root\uff0c\u6811\u4e2d\u7684\u6bcf\u4e2a\u7ed3\u70b9\u4e0a\u90fd\u5bf9\u5e94\u6709 node.val \u679a\u786c\u5e01\uff0c\u5e76\u4e14\u603b\u5171\u6709 N \u679a\u786c\u5e01\u3002

\n\n

\u5728\u4e00\u6b21\u79fb\u52a8\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u9009\u62e9\u4e24\u4e2a\u76f8\u90bb\u7684\u7ed3\u70b9\uff0c\u7136\u540e\u5c06\u4e00\u679a\u786c\u5e01\u4ece\u5176\u4e2d\u4e00\u4e2a\u7ed3\u70b9\u79fb\u52a8\u5230\u53e6\u4e00\u4e2a\u7ed3\u70b9\u3002(\u79fb\u52a8\u53ef\u4ee5\u662f\u4ece\u7236\u7ed3\u70b9\u5230\u5b50\u7ed3\u70b9\uff0c\u6216\u8005\u4ece\u5b50\u7ed3\u70b9\u79fb\u52a8\u5230\u7236\u7ed3\u70b9\u3002)\u3002

\n\n

\u8fd4\u56de\u4f7f\u6bcf\u4e2a\u7ed3\u70b9\u4e0a\u53ea\u6709\u4e00\u679a\u786c\u5e01\u6240\u9700\u7684\u79fb\u52a8\u6b21\u6570\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1a[3,0,0]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u4ece\u6811\u7684\u6839\u7ed3\u70b9\u5f00\u59cb\uff0c\u6211\u4eec\u5c06\u4e00\u679a\u786c\u5e01\u79fb\u5230\u5b83\u7684\u5de6\u5b50\u7ed3\u70b9\u4e0a\uff0c\u4e00\u679a\u786c\u5e01\u79fb\u5230\u5b83\u7684\u53f3\u5b50\u7ed3\u70b9\u4e0a\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1a[0,3,0]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u4ece\u6839\u7ed3\u70b9\u7684\u5de6\u5b50\u7ed3\u70b9\u5f00\u59cb\uff0c\u6211\u4eec\u5c06\u4e24\u679a\u786c\u5e01\u79fb\u5230\u6839\u7ed3\u70b9\u4e0a [\u79fb\u52a8\u4e24\u6b21]\u3002\u7136\u540e\uff0c\u6211\u4eec\u628a\u4e00\u679a\u786c\u5e01\u4ece\u6839\u7ed3\u70b9\u79fb\u5230\u53f3\u5b50\u7ed3\u70b9\u4e0a\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1a[1,0,2]\n\u8f93\u51fa\uff1a2\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1a[1,0,0,null,3]\n\u8f93\u51fa\uff1a4\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1<= N <= 100
  2. \n\t
  3. 0 <= node.val <= N
  4. \n
\n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int distributeCoins(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int distributeCoins(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def distributeCoins(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def distributeCoins(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint distributeCoins(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int DistributeCoins(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar distributeCoins = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef distribute_coins(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func distributeCoins(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc distributeCoins(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def distributeCoins(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun distributeCoins(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn distribute_coins(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function distributeCoins($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction distributeCoins(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (distribute-coins root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0979](https://leetcode-cn.com/problems/distribute-coins-in-binary-tree)", "[\u5728\u4e8c\u53c9\u6811\u4e2d\u5206\u914d\u786c\u5e01](/solution/0900-0999/0979.Distribute%20Coins%20in%20Binary%20Tree/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0979](https://leetcode.com/problems/distribute-coins-in-binary-tree)", "[Distribute Coins in Binary Tree](/solution/0900-0999/0979.Distribute%20Coins%20in%20Binary%20Tree/README_EN.md)", "`Tree`,`Depth-first Search`", "Medium", ""]}, {"question_id": "1020", "frontend_question_id": "0978", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-turbulent-subarray", "url_en": "https://leetcode.com/problems/longest-turbulent-subarray", "relative_path_cn": "/solution/0900-0999/0978.Longest%20Turbulent%20Subarray/README.md", "relative_path_en": "/solution/0900-0999/0978.Longest%20Turbulent%20Subarray/README_EN.md", "title_cn": "\u6700\u957f\u6e4d\u6d41\u5b50\u6570\u7ec4", "title_en": "Longest Turbulent Subarray", "question_title_slug": "longest-turbulent-subarray", "content_en": "

Given an integer array arr, return the length of a maximum size turbulent subarray of arr.

\n\n

A subarray is turbulent if the comparison sign flips between each adjacent pair of elements in the subarray.

\n\n

More formally, a subarray [arr[i], arr[i + 1], ..., arr[j]] of arr is said to be turbulent if and only if:

\n\n
    \n\t
  • For i <= k < j:\n\n\t
      \n\t\t
    • arr[k] > arr[k + 1] when k is odd, and
    • \n\t\t
    • arr[k] < arr[k + 1] when k is even.
    • \n\t
    \n\t
  • \n\t
  • Or, for i <= k < j:\n\t
      \n\t\t
    • arr[k] > arr[k + 1] when k is even, and
    • \n\t\t
    • arr[k] < arr[k + 1] when k is odd.
    • \n\t
    \n\t
  • \n
\n\n

 

\n

Example 1:

\n\n
\nInput: arr = [9,4,2,10,7,8,8,1,9]\nOutput: 5\nExplanation: arr[1] > arr[2] < arr[3] > arr[4] < arr[5]\n
\n\n

Example 2:

\n\n
\nInput: arr = [4,8,12,16]\nOutput: 2\n
\n\n

Example 3:

\n\n
\nInput: arr = [100]\nOutput: 1\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= arr.length <= 4 * 104
  • \n\t
  • 0 <= arr[i] <= 109
  • \n
\n", "content_cn": "

\u5f53 A \u7684\u5b50\u6570\u7ec4 A[i], A[i+1], ..., A[j] \u6ee1\u8db3\u4e0b\u5217\u6761\u4ef6\u65f6\uff0c\u6211\u4eec\u79f0\u5176\u4e3a\u6e4d\u6d41\u5b50\u6570\u7ec4\uff1a

\n\n
    \n\t
  • \u82e5 i <= k < j\uff0c\u5f53 k \u4e3a\u5947\u6570\u65f6\uff0c A[k] > A[k+1]\uff0c\u4e14\u5f53 k \u4e3a\u5076\u6570\u65f6\uff0cA[k] < A[k+1]\uff1b
  • \n\t
  • \u6216 \u82e5 i <= k < j\uff0c\u5f53 k \u4e3a\u5076\u6570\u65f6\uff0cA[k] > A[k+1] \uff0c\u4e14\u5f53 k \u4e3a\u5947\u6570\u65f6\uff0c A[k] < A[k+1]\u3002
  • \n
\n\n

\u4e5f\u5c31\u662f\u8bf4\uff0c\u5982\u679c\u6bd4\u8f83\u7b26\u53f7\u5728\u5b50\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u76f8\u90bb\u5143\u7d20\u5bf9\u4e4b\u95f4\u7ffb\u8f6c\uff0c\u5219\u8be5\u5b50\u6570\u7ec4\u662f\u6e4d\u6d41\u5b50\u6570\u7ec4\u3002

\n\n

\u8fd4\u56de A \u7684\u6700\u5927\u6e4d\u6d41\u5b50\u6570\u7ec4\u7684\u957f\u5ea6\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a[9,4,2,10,7,8,8,1,9]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a(A[1] > A[2] < A[3] > A[4] < A[5])\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a[4,8,12,16]\n\u8f93\u51fa\uff1a2\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1a[100]\n\u8f93\u51fa\uff1a1\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= A.length <= 40000
  2. \n\t
  3. 0 <= A[i] <= 10^9
  4. \n
\n", "tags_en": ["Array", "Dynamic Programming", "Sliding Window"], "tags_cn": ["\u6570\u7ec4", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxTurbulenceSize(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxTurbulenceSize(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxTurbulenceSize(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxTurbulenceSize(self, arr: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxTurbulenceSize(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxTurbulenceSize(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar maxTurbulenceSize = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef max_turbulence_size(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxTurbulenceSize(_ arr: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxTurbulenceSize(arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxTurbulenceSize(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxTurbulenceSize(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_turbulence_size(arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function maxTurbulenceSize($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxTurbulenceSize(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-turbulence-size arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0978](https://leetcode-cn.com/problems/longest-turbulent-subarray)", "[\u6700\u957f\u6e4d\u6d41\u5b50\u6570\u7ec4](/solution/0900-0999/0978.Longest%20Turbulent%20Subarray/README.md)", "`\u6570\u7ec4`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0978](https://leetcode.com/problems/longest-turbulent-subarray)", "[Longest Turbulent Subarray](/solution/0900-0999/0978.Longest%20Turbulent%20Subarray/README_EN.md)", "`Array`,`Dynamic Programming`,`Sliding Window`", "Medium", ""]}, {"question_id": "1019", "frontend_question_id": "0977", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/squares-of-a-sorted-array", "url_en": "https://leetcode.com/problems/squares-of-a-sorted-array", "relative_path_cn": "/solution/0900-0999/0977.Squares%20of%20a%20Sorted%20Array/README.md", "relative_path_en": "/solution/0900-0999/0977.Squares%20of%20a%20Sorted%20Array/README_EN.md", "title_cn": "\u6709\u5e8f\u6570\u7ec4\u7684\u5e73\u65b9", "title_en": "Squares of a Sorted Array", "question_title_slug": "squares-of-a-sorted-array", "content_en": "

Given an integer array nums sorted in non-decreasing order, return an array of the squares of each number sorted in non-decreasing order.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [-4,-1,0,3,10]\nOutput: [0,1,9,16,100]\nExplanation: After squaring, the array becomes [16,1,0,9,100].\nAfter sorting, it becomes [0,1,9,16,100].\n
\n\n

Example 2:

\n\n
\nInput: nums = [-7,-3,2,3,11]\nOutput: [4,9,9,49,121]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 104
  • \n\t
  • -104 <= nums[i] <= 104
  • \n\t
  • nums is sorted in non-decreasing order.
  • \n
\n\n

 

\nFollow up: Squaring each element and sorting the new array is very trivial, could you find an O(n) solution using a different approach?", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6309 \u975e\u9012\u51cf\u987a\u5e8f \u6392\u5e8f\u7684\u6574\u6570\u6570\u7ec4 nums\uff0c\u8fd4\u56de \u6bcf\u4e2a\u6570\u5b57\u7684\u5e73\u65b9 \u7ec4\u6210\u7684\u65b0\u6570\u7ec4\uff0c\u8981\u6c42\u4e5f\u6309 \u975e\u9012\u51cf\u987a\u5e8f \u6392\u5e8f\u3002

\n\n
    \n
\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [-4,-1,0,3,10]\n\u8f93\u51fa\uff1a[0,1,9,16,100]\n\u89e3\u91ca\uff1a\u5e73\u65b9\u540e\uff0c\u6570\u7ec4\u53d8\u4e3a [16,1,0,9,100]\n\u6392\u5e8f\u540e\uff0c\u6570\u7ec4\u53d8\u4e3a [0,1,9,16,100]
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [-7,-3,2,3,11]\n\u8f93\u51fa\uff1a[4,9,9,49,121]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 104
  • \n\t
  • -104 <= nums[i] <= 104
  • \n\t
  • nums \u5df2\u6309 \u975e\u9012\u51cf\u987a\u5e8f \u6392\u5e8f
  • \n
\n\n

\u00a0

\n\n

\u8fdb\u9636\uff1a

\n\n
    \n\t
  • \u8bf7\u4f60\u8bbe\u8ba1\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n) \u7684\u7b97\u6cd5\u89e3\u51b3\u672c\u95ee\u9898
  • \n
\n", "tags_en": ["Array", "Two Pointers"], "tags_cn": ["\u6570\u7ec4", "\u53cc\u6307\u9488"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector sortedSquares(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] sortedSquares(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def sortedSquares(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def sortedSquares(self, nums: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* sortedSquares(int* nums, int numsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] SortedSquares(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar sortedSquares = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer[]}\ndef sorted_squares(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func sortedSquares(_ nums: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func sortedSquares(nums []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def sortedSquares(nums: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun sortedSquares(nums: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sorted_squares(nums: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer[]\n */\n function sortedSquares($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function sortedSquares(nums: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (sorted-squares nums)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0977](https://leetcode-cn.com/problems/squares-of-a-sorted-array)", "[\u6709\u5e8f\u6570\u7ec4\u7684\u5e73\u65b9](/solution/0900-0999/0977.Squares%20of%20a%20Sorted%20Array/README.md)", "`\u6570\u7ec4`,`\u53cc\u6307\u9488`", "\u7b80\u5355", ""], "md_table_row_en": ["[0977](https://leetcode.com/problems/squares-of-a-sorted-array)", "[Squares of a Sorted Array](/solution/0900-0999/0977.Squares%20of%20a%20Sorted%20Array/README_EN.md)", "`Array`,`Two Pointers`", "Easy", ""]}, {"question_id": "1018", "frontend_question_id": "0976", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/largest-perimeter-triangle", "url_en": "https://leetcode.com/problems/largest-perimeter-triangle", "relative_path_cn": "/solution/0900-0999/0976.Largest%20Perimeter%20Triangle/README.md", "relative_path_en": "/solution/0900-0999/0976.Largest%20Perimeter%20Triangle/README_EN.md", "title_cn": "\u4e09\u89d2\u5f62\u7684\u6700\u5927\u5468\u957f", "title_en": "Largest Perimeter Triangle", "question_title_slug": "largest-perimeter-triangle", "content_en": "

Given an integer array nums, return the largest perimeter of a triangle with a non-zero area, formed from three of these lengths. If it is impossible to form any triangle of a non-zero area, return 0.

\n\n

 

\n

Example 1:

\n
Input: nums = [2,1,2]\nOutput: 5\n

Example 2:

\n
Input: nums = [1,2,1]\nOutput: 0\n

Example 3:

\n
Input: nums = [3,2,3,4]\nOutput: 10\n

Example 4:

\n
Input: nums = [3,6,2,3]\nOutput: 8\n
\n

 

\n

Constraints:

\n\n
    \n\t
  • 3 <= nums.length <= 104
  • \n\t
  • 1 <= nums[i] <= 106
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u7531\u4e00\u4e9b\u6b63\u6570\uff08\u4ee3\u8868\u957f\u5ea6\uff09\u7ec4\u6210\u7684\u6570\u7ec4 A\uff0c\u8fd4\u56de\u7531\u5176\u4e2d\u4e09\u4e2a\u957f\u5ea6\u7ec4\u6210\u7684\u3001\u9762\u79ef\u4e0d\u4e3a\u96f6\u7684\u4e09\u89d2\u5f62\u7684\u6700\u5927\u5468\u957f\u3002

\n\n

\u5982\u679c\u4e0d\u80fd\u5f62\u6210\u4efb\u4f55\u9762\u79ef\u4e0d\u4e3a\u96f6\u7684\u4e09\u89d2\u5f62\uff0c\u8fd4\u56de 0\u3002

\n\n

 

\n\n
    \n
\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a[2,1,2]\n\u8f93\u51fa\uff1a5\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a[1,2,1]\n\u8f93\u51fa\uff1a0\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1a[3,2,3,4]\n\u8f93\u51fa\uff1a10\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1a[3,6,2,3]\n\u8f93\u51fa\uff1a8\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 3 <= A.length <= 10000
  2. \n\t
  3. 1 <= A[i] <= 10^6
  4. \n
\n", "tags_en": ["Sort", "Math"], "tags_cn": ["\u6392\u5e8f", "\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int largestPerimeter(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int largestPerimeter(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def largestPerimeter(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def largestPerimeter(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint largestPerimeter(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LargestPerimeter(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar largestPerimeter = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef largest_perimeter(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func largestPerimeter(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func largestPerimeter(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def largestPerimeter(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun largestPerimeter(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn largest_perimeter(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function largestPerimeter($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function largestPerimeter(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (largest-perimeter nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0976](https://leetcode-cn.com/problems/largest-perimeter-triangle)", "[\u4e09\u89d2\u5f62\u7684\u6700\u5927\u5468\u957f](/solution/0900-0999/0976.Largest%20Perimeter%20Triangle/README.md)", "`\u6392\u5e8f`,`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0976](https://leetcode.com/problems/largest-perimeter-triangle)", "[Largest Perimeter Triangle](/solution/0900-0999/0976.Largest%20Perimeter%20Triangle/README_EN.md)", "`Sort`,`Math`", "Easy", ""]}, {"question_id": "1017", "frontend_question_id": "0975", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/odd-even-jump", "url_en": "https://leetcode.com/problems/odd-even-jump", "relative_path_cn": "/solution/0900-0999/0975.Odd%20Even%20Jump/README.md", "relative_path_en": "/solution/0900-0999/0975.Odd%20Even%20Jump/README_EN.md", "title_cn": "\u5947\u5076\u8df3", "title_en": "Odd Even Jump", "question_title_slug": "odd-even-jump", "content_en": "

You are given an integer array arr. From some starting index, you can make a series of jumps. The (1st, 3rd, 5th, ...) jumps in the series are called odd-numbered jumps, and the (2nd, 4th, 6th, ...) jumps in the series are called even-numbered jumps. Note that the jumps are numbered, not the indices.

\n\n

You may jump forward from index i to index j (with i < j) in the following way:

\n\n
    \n\t
  • During odd-numbered jumps (i.e., jumps 1, 3, 5, ...), you jump to the index j such that arr[i] <= arr[j] and arr[j] is the smallest possible value. If there are multiple such indices j, you can only jump to the smallest such index j.
  • \n\t
  • During even-numbered jumps (i.e., jumps 2, 4, 6, ...), you jump to the index j such that arr[i] >= arr[j] and arr[j] is the largest possible value. If there are multiple such indices j, you can only jump to the smallest such index j.
  • \n\t
  • It may be the case that for some index i, there are no legal jumps.
  • \n
\n\n

A starting index is good if, starting from that index, you can reach the end of the array (index arr.length - 1) by jumping some number of times (possibly 0 or more than once).

\n\n

Return the number of good starting indices.

\n\n

 

\n

Example 1:

\n\n
\nInput: arr = [10,13,12,14,15]\nOutput: 2\nExplanation: \nFrom starting index i = 0, we can make our 1st jump to i = 2 (since arr[2] is the smallest among arr[1], arr[2], arr[3], arr[4] that is greater or equal to arr[0]), then we cannot jump any more.\nFrom starting index i = 1 and i = 2, we can make our 1st jump to i = 3, then we cannot jump any more.\nFrom starting index i = 3, we can make our 1st jump to i = 4, so we have reached the end.\nFrom starting index i = 4, we have reached the end already.\nIn total, there are 2 different starting indices i = 3 and i = 4, where we can reach the end with some number of\njumps.\n
\n\n

Example 2:

\n\n
\nInput: arr = [2,3,1,1,4]\nOutput: 3\nExplanation: \nFrom starting index i = 0, we make jumps to i = 1, i = 2, i = 3:\nDuring our 1st jump (odd-numbered), we first jump to i = 1 because arr[1] is the smallest value in [arr[1], arr[2], arr[3], arr[4]] that is greater than or equal to arr[0].\nDuring our 2nd jump (even-numbered), we jump from i = 1 to i = 2 because arr[2] is the largest value in [arr[2], arr[3], arr[4]] that is less than or equal to arr[1]. arr[3] is also the largest value, but 2 is a smaller index, so we can only jump to i = 2 and not i = 3\nDuring our 3rd jump (odd-numbered), we jump from i = 2 to i = 3 because arr[3] is the smallest value in [arr[3], arr[4]] that is greater than or equal to arr[2].\nWe can't jump from i = 3 to i = 4, so the starting index i = 0 is not good.\nIn a similar manner, we can deduce that:\nFrom starting index i = 1, we jump to i = 4, so we reach the end.\nFrom starting index i = 2, we jump to i = 3, and then we can't jump anymore.\nFrom starting index i = 3, we jump to i = 4, so we reach the end.\nFrom starting index i = 4, we are already at the end.\nIn total, there are 3 different starting indices i = 1, i = 3, and i = 4, where we can reach the end with some\nnumber of jumps.\n
\n\n

Example 3:

\n\n
\nInput: arr = [5,1,3,4,2]\nOutput: 3\nExplanation: We can reach the end from starting indices 1, 2, and 4.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= arr.length <= 2 * 104
  • \n\t
  • 0 <= arr[i] < 105
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 A\uff0c\u4f60\u53ef\u4ee5\u4ece\u67d0\u4e00\u8d77\u59cb\u7d22\u5f15\u51fa\u53d1\uff0c\u8df3\u8dc3\u4e00\u5b9a\u6b21\u6570\u3002\u5728\u4f60\u8df3\u8dc3\u7684\u8fc7\u7a0b\u4e2d\uff0c\u7b2c 1\u30013\u30015... \u6b21\u8df3\u8dc3\u79f0\u4e3a\u5947\u6570\u8df3\u8dc3\uff0c\u800c\u7b2c 2\u30014\u30016... \u6b21\u8df3\u8dc3\u79f0\u4e3a\u5076\u6570\u8df3\u8dc3\u3002

\n\n

\u4f60\u53ef\u4ee5\u6309\u4ee5\u4e0b\u65b9\u5f0f\u4ece\u7d22\u5f15 i \u5411\u540e\u8df3\u8f6c\u5230\u7d22\u5f15 j\uff08\u5176\u4e2d i < j\uff09\uff1a

\n\n
    \n\t
  • \u5728\u8fdb\u884c\u5947\u6570\u8df3\u8dc3\u65f6\uff08\u5982\uff0c\u7b2c 1\uff0c3\uff0c5... \u6b21\u8df3\u8dc3\uff09\uff0c\u4f60\u5c06\u4f1a\u8df3\u5230\u7d22\u5f15 j\uff0c\u4f7f\u5f97 A[i] <= A[j]\uff0cA[j] \u662f\u53ef\u80fd\u7684\u6700\u5c0f\u503c\u3002\u5982\u679c\u5b58\u5728\u591a\u4e2a\u8fd9\u6837\u7684\u7d22\u5f15 j\uff0c\u4f60\u53ea\u80fd\u8df3\u5230\u6ee1\u8db3\u8981\u6c42\u7684\u6700\u5c0f\u7d22\u5f15 j \u4e0a\u3002
  • \n\t
  • \u5728\u8fdb\u884c\u5076\u6570\u8df3\u8dc3\u65f6\uff08\u5982\uff0c\u7b2c 2\uff0c4\uff0c6... \u6b21\u8df3\u8dc3\uff09\uff0c\u4f60\u5c06\u4f1a\u8df3\u5230\u7d22\u5f15 j\uff0c\u4f7f\u5f97 A[i] >= A[j]\uff0cA[j] \u662f\u53ef\u80fd\u7684\u6700\u5927\u503c\u3002\u5982\u679c\u5b58\u5728\u591a\u4e2a\u8fd9\u6837\u7684\u7d22\u5f15 j\uff0c\u4f60\u53ea\u80fd\u8df3\u5230\u6ee1\u8db3\u8981\u6c42\u7684\u6700\u5c0f\u7d22\u5f15 j \u4e0a\u3002
  • \n\t
  • \uff08\u5bf9\u4e8e\u67d0\u4e9b\u7d22\u5f15 i\uff0c\u53ef\u80fd\u65e0\u6cd5\u8fdb\u884c\u5408\u4e4e\u8981\u6c42\u7684\u8df3\u8dc3\u3002\uff09
  • \n
\n\n

\u5982\u679c\u4ece\u67d0\u4e00\u7d22\u5f15\u5f00\u59cb\u8df3\u8dc3\u4e00\u5b9a\u6b21\u6570\uff08\u53ef\u80fd\u662f 0 \u6b21\u6216\u591a\u6b21\uff09\uff0c\u5c31\u53ef\u4ee5\u5230\u8fbe\u6570\u7ec4\u7684\u672b\u5c3e\uff08\u7d22\u5f15 A.length - 1\uff09\uff0c\u90a3\u4e48\u8be5\u7d22\u5f15\u5c31\u4f1a\u88ab\u8ba4\u4e3a\u662f\u597d\u7684\u8d77\u59cb\u7d22\u5f15\u3002

\n\n

\u8fd4\u56de\u597d\u7684\u8d77\u59cb\u7d22\u5f15\u7684\u6570\u91cf\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a[10,13,12,14,15]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a \n\u4ece\u8d77\u59cb\u7d22\u5f15 i = 0 \u51fa\u53d1\uff0c\u6211\u4eec\u53ef\u4ee5\u8df3\u5230 i = 2\uff0c\uff08\u56e0\u4e3a A[2] \u662f A[1]\uff0cA[2]\uff0cA[3]\uff0cA[4] \u4e2d\u5927\u4e8e\u6216\u7b49\u4e8e A[0] \u7684\u6700\u5c0f\u503c\uff09\uff0c\u7136\u540e\u6211\u4eec\u5c31\u65e0\u6cd5\u7ee7\u7eed\u8df3\u4e0b\u53bb\u4e86\u3002\n\u4ece\u8d77\u59cb\u7d22\u5f15 i = 1 \u548c i = 2 \u51fa\u53d1\uff0c\u6211\u4eec\u53ef\u4ee5\u8df3\u5230 i = 3\uff0c\u7136\u540e\u6211\u4eec\u5c31\u65e0\u6cd5\u7ee7\u7eed\u8df3\u4e0b\u53bb\u4e86\u3002\n\u4ece\u8d77\u59cb\u7d22\u5f15 i = 3 \u51fa\u53d1\uff0c\u6211\u4eec\u53ef\u4ee5\u8df3\u5230 i = 4\uff0c\u5230\u8fbe\u6570\u7ec4\u672b\u5c3e\u3002\n\u4ece\u8d77\u59cb\u7d22\u5f15 i = 4 \u51fa\u53d1\uff0c\u6211\u4eec\u5df2\u7ecf\u5230\u8fbe\u6570\u7ec4\u672b\u5c3e\u3002\n\u603b\u4e4b\uff0c\u6211\u4eec\u53ef\u4ee5\u4ece 2 \u4e2a\u4e0d\u540c\u7684\u8d77\u59cb\u7d22\u5f15\uff08i = 3, i = 4\uff09\u51fa\u53d1\uff0c\u901a\u8fc7\u4e00\u5b9a\u6570\u91cf\u7684\u8df3\u8dc3\u5230\u8fbe\u6570\u7ec4\u672b\u5c3e\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a[2,3,1,1,4]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\n\u4ece\u8d77\u59cb\u7d22\u5f15 i=0 \u51fa\u53d1\uff0c\u6211\u4eec\u4f9d\u6b21\u53ef\u4ee5\u8df3\u5230 i = 1\uff0ci = 2\uff0ci = 3\uff1a\n\n\u5728\u6211\u4eec\u7684\u7b2c\u4e00\u6b21\u8df3\u8dc3\uff08\u5947\u6570\uff09\u4e2d\uff0c\u6211\u4eec\u5148\u8df3\u5230 i = 1\uff0c\u56e0\u4e3a A[1] \u662f\uff08A[1]\uff0cA[2]\uff0cA[3]\uff0cA[4]\uff09\u4e2d\u5927\u4e8e\u6216\u7b49\u4e8e A[0] \u7684\u6700\u5c0f\u503c\u3002\n\n\u5728\u6211\u4eec\u7684\u7b2c\u4e8c\u6b21\u8df3\u8dc3\uff08\u5076\u6570\uff09\u4e2d\uff0c\u6211\u4eec\u4ece i = 1 \u8df3\u5230 i = 2\uff0c\u56e0\u4e3a A[2] \u662f\uff08A[2]\uff0cA[3]\uff0cA[4]\uff09\u4e2d\u5c0f\u4e8e\u6216\u7b49\u4e8e A[1] \u7684\u6700\u5927\u503c\u3002A[3] \u4e5f\u662f\u6700\u5927\u7684\u503c\uff0c\u4f46 2 \u662f\u4e00\u4e2a\u8f83\u5c0f\u7684\u7d22\u5f15\uff0c\u6240\u4ee5\u6211\u4eec\u53ea\u80fd\u8df3\u5230 i = 2\uff0c\u800c\u4e0d\u80fd\u8df3\u5230 i = 3\u3002\n\n\u5728\u6211\u4eec\u7684\u7b2c\u4e09\u6b21\u8df3\u8dc3\uff08\u5947\u6570\uff09\u4e2d\uff0c\u6211\u4eec\u4ece i = 2 \u8df3\u5230 i = 3\uff0c\u56e0\u4e3a A[3] \u662f\uff08A[3]\uff0cA[4]\uff09\u4e2d\u5927\u4e8e\u6216\u7b49\u4e8e A[2] \u7684\u6700\u5c0f\u503c\u3002\n\n\u6211\u4eec\u4e0d\u80fd\u4ece i = 3 \u8df3\u5230 i = 4\uff0c\u6240\u4ee5\u8d77\u59cb\u7d22\u5f15 i = 0 \u4e0d\u662f\u597d\u7684\u8d77\u59cb\u7d22\u5f15\u3002\n\n\u7c7b\u4f3c\u5730\uff0c\u6211\u4eec\u53ef\u4ee5\u63a8\u65ad\uff1a\n\u4ece\u8d77\u59cb\u7d22\u5f15 i = 1 \u51fa\u53d1\uff0c \u6211\u4eec\u8df3\u5230 i = 4\uff0c\u8fd9\u6837\u6211\u4eec\u5c31\u5230\u8fbe\u6570\u7ec4\u672b\u5c3e\u3002\n\u4ece\u8d77\u59cb\u7d22\u5f15 i = 2 \u51fa\u53d1\uff0c \u6211\u4eec\u8df3\u5230 i = 3\uff0c\u7136\u540e\u6211\u4eec\u5c31\u4e0d\u80fd\u518d\u8df3\u4e86\u3002\n\u4ece\u8d77\u59cb\u7d22\u5f15 i = 3 \u51fa\u53d1\uff0c \u6211\u4eec\u8df3\u5230 i = 4\uff0c\u8fd9\u6837\u6211\u4eec\u5c31\u5230\u8fbe\u6570\u7ec4\u672b\u5c3e\u3002\n\u4ece\u8d77\u59cb\u7d22\u5f15 i = 4 \u51fa\u53d1\uff0c\u6211\u4eec\u5df2\u7ecf\u5230\u8fbe\u6570\u7ec4\u672b\u5c3e\u3002\n\u603b\u4e4b\uff0c\u6211\u4eec\u53ef\u4ee5\u4ece 3 \u4e2a\u4e0d\u540c\u7684\u8d77\u59cb\u7d22\u5f15\uff08i = 1, i = 3, i = 4\uff09\u51fa\u53d1\uff0c\u901a\u8fc7\u4e00\u5b9a\u6570\u91cf\u7684\u8df3\u8dc3\u5230\u8fbe\u6570\u7ec4\u672b\u5c3e\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1a[5,1,3,4,2]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a \n\u6211\u4eec\u53ef\u4ee5\u4ece\u8d77\u59cb\u7d22\u5f15 1\uff0c2\uff0c4 \u51fa\u53d1\u5230\u8fbe\u6570\u7ec4\u672b\u5c3e\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= A.length <= 20000
  2. \n\t
  3. 0 <= A[i] < 100000
  4. \n
\n", "tags_en": ["Stack", "Dynamic Programming", "Ordered Map"], "tags_cn": ["\u6808", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int oddEvenJumps(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int oddEvenJumps(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def oddEvenJumps(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def oddEvenJumps(self, arr: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint oddEvenJumps(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int OddEvenJumps(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar oddEvenJumps = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef odd_even_jumps(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func oddEvenJumps(_ arr: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func oddEvenJumps(arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def oddEvenJumps(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun oddEvenJumps(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn odd_even_jumps(arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function oddEvenJumps($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function oddEvenJumps(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (odd-even-jumps arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0975](https://leetcode-cn.com/problems/odd-even-jump)", "[\u5947\u5076\u8df3](/solution/0900-0999/0975.Odd%20Even%20Jump/README.md)", "`\u6808`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0975](https://leetcode.com/problems/odd-even-jump)", "[Odd Even Jump](/solution/0900-0999/0975.Odd%20Even%20Jump/README_EN.md)", "`Stack`,`Dynamic Programming`,`Ordered Map`", "Hard", ""]}, {"question_id": "1016", "frontend_question_id": "0974", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/subarray-sums-divisible-by-k", "url_en": "https://leetcode.com/problems/subarray-sums-divisible-by-k", "relative_path_cn": "/solution/0900-0999/0974.Subarray%20Sums%20Divisible%20by%20K/README.md", "relative_path_en": "/solution/0900-0999/0974.Subarray%20Sums%20Divisible%20by%20K/README_EN.md", "title_cn": "\u548c\u53ef\u88ab K \u6574\u9664\u7684\u5b50\u6570\u7ec4", "title_en": "Subarray Sums Divisible by K", "question_title_slug": "subarray-sums-divisible-by-k", "content_en": "

Given an array nums of integers, return the number of (contiguous, non-empty) subarrays that have a sum divisible by k.

\n\n

 

\n\n
\n

Example 1:

\n\n
\nInput: nums = [4,5,0,-2,-3,1], k = 5\nOutput: 7\nExplanation: There are 7 subarrays with a sum divisible by k = 5:\n[4, 5, 0, -2, -3, 1], [5], [5, 0], [5, 0, -2, -3], [0], [0, -2, -3], [-2, -3]\n
\n\n

 

\n\n

Note:

\n\n
    \n\t
  1. 1 <= nums.length <= 30000
  2. \n\t
  3. -10000 <= nums[i] <= 10000
  4. \n\t
  5. 2 <= k <= 10000
  6. \n
\n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 A\uff0c\u8fd4\u56de\u5176\u4e2d\u5143\u7d20\u4e4b\u548c\u53ef\u88ab K \u6574\u9664\u7684\uff08\u8fde\u7eed\u3001\u975e\u7a7a\uff09\u5b50\u6570\u7ec4\u7684\u6570\u76ee\u3002

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1aA = [4,5,0,-2,-3,1], K = 5\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\n\u6709 7 \u4e2a\u5b50\u6570\u7ec4\u6ee1\u8db3\u5176\u5143\u7d20\u4e4b\u548c\u53ef\u88ab K = 5 \u6574\u9664\uff1a\n[4, 5, 0, -2, -3, 1], [5], [5, 0], [5, 0, -2, -3], [0], [0, -2, -3], [-2, -3]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= A.length <= 30000
  2. \n\t
  3. -10000 <= A[i] <= 10000
  4. \n\t
  5. 2 <= K <= 10000
  6. \n
\n", "tags_en": ["Array", "Hash Table"], "tags_cn": ["\u6570\u7ec4", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int subarraysDivByK(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int subarraysDivByK(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def subarraysDivByK(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def subarraysDivByK(self, nums: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint subarraysDivByK(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SubarraysDivByK(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar subarraysDivByK = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef subarrays_div_by_k(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func subarraysDivByK(_ nums: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func subarraysDivByK(nums []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def subarraysDivByK(nums: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun subarraysDivByK(nums: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn subarrays_div_by_k(nums: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer\n */\n function subarraysDivByK($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function subarraysDivByK(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (subarrays-div-by-k nums k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0974](https://leetcode-cn.com/problems/subarray-sums-divisible-by-k)", "[\u548c\u53ef\u88ab K \u6574\u9664\u7684\u5b50\u6570\u7ec4](/solution/0900-0999/0974.Subarray%20Sums%20Divisible%20by%20K/README.md)", "`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0974](https://leetcode.com/problems/subarray-sums-divisible-by-k)", "[Subarray Sums Divisible by K](/solution/0900-0999/0974.Subarray%20Sums%20Divisible%20by%20K/README_EN.md)", "`Array`,`Hash Table`", "Medium", ""]}, {"question_id": "1014", "frontend_question_id": "0973", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/k-closest-points-to-origin", "url_en": "https://leetcode.com/problems/k-closest-points-to-origin", "relative_path_cn": "/solution/0900-0999/0973.K%20Closest%20Points%20to%20Origin/README.md", "relative_path_en": "/solution/0900-0999/0973.K%20Closest%20Points%20to%20Origin/README_EN.md", "title_cn": "\u6700\u63a5\u8fd1\u539f\u70b9\u7684 K \u4e2a\u70b9", "title_en": "K Closest Points to Origin", "question_title_slug": "k-closest-points-to-origin", "content_en": "

Given an array of points where points[i] = [xi, yi] represents a point on the X-Y plane and an integer k, return the k closest points to the origin (0, 0).

\n\n

The distance between two points on the X-Y plane is the Euclidean distance (i.e., √(x1 - x2)2 + (y1 - y2)2).

\n\n

You may return the answer in any order. The answer is guaranteed to be unique (except for the order that it is in).

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: points = [[1,3],[-2,2]], k = 1\nOutput: [[-2,2]]\nExplanation:\nThe distance between (1, 3) and the origin is sqrt(10).\nThe distance between (-2, 2) and the origin is sqrt(8).\nSince sqrt(8) < sqrt(10), (-2, 2) is closer to the origin.\nWe only want the closest k = 1 points from the origin, so the answer is just [[-2,2]].\n
\n\n

Example 2:

\n\n
\nInput: points = [[3,3],[5,-1],[-2,4]], k = 2\nOutput: [[3,3],[-2,4]]\nExplanation: The answer [[-2,4],[3,3]] would also be accepted.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= k <= points.length <= 104
  • \n\t
  • -104 < xi, yi < 104
  • \n
\n", "content_cn": "

\u6211\u4eec\u6709\u4e00\u4e2a\u7531\u5e73\u9762\u4e0a\u7684\u70b9\u7ec4\u6210\u7684\u5217\u8868 points\u3002\u9700\u8981\u4ece\u4e2d\u627e\u51fa K \u4e2a\u8ddd\u79bb\u539f\u70b9 (0, 0) \u6700\u8fd1\u7684\u70b9\u3002

\n\n

\uff08\u8fd9\u91cc\uff0c\u5e73\u9762\u4e0a\u4e24\u70b9\u4e4b\u95f4\u7684\u8ddd\u79bb\u662f\u6b27\u51e0\u91cc\u5fb7\u8ddd\u79bb\u3002\uff09

\n\n

\u4f60\u53ef\u4ee5\u6309\u4efb\u4f55\u987a\u5e8f\u8fd4\u56de\u7b54\u6848\u3002\u9664\u4e86\u70b9\u5750\u6807\u7684\u987a\u5e8f\u4e4b\u5916\uff0c\u7b54\u6848\u786e\u4fdd\u662f\u552f\u4e00\u7684\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1apoints = [[1,3],[-2,2]], K = 1\n\u8f93\u51fa\uff1a[[-2,2]]\n\u89e3\u91ca\uff1a \n(1, 3) \u548c\u539f\u70b9\u4e4b\u95f4\u7684\u8ddd\u79bb\u4e3a sqrt(10)\uff0c\n(-2, 2) \u548c\u539f\u70b9\u4e4b\u95f4\u7684\u8ddd\u79bb\u4e3a sqrt(8)\uff0c\n\u7531\u4e8e sqrt(8) < sqrt(10)\uff0c(-2, 2) \u79bb\u539f\u70b9\u66f4\u8fd1\u3002\n\u6211\u4eec\u53ea\u9700\u8981\u8ddd\u79bb\u539f\u70b9\u6700\u8fd1\u7684 K = 1 \u4e2a\u70b9\uff0c\u6240\u4ee5\u7b54\u6848\u5c31\u662f [[-2,2]]\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1apoints = [[3,3],[5,-1],[-2,4]], K = 2\n\u8f93\u51fa\uff1a[[3,3],[-2,4]]\n\uff08\u7b54\u6848 [[-2,4],[3,3]] \u4e5f\u4f1a\u88ab\u63a5\u53d7\u3002\uff09\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= K <= points.length <= 10000
  2. \n\t
  3. -10000 < points[i][0] < 10000
  4. \n\t
  5. -10000 < points[i][1] < 10000
  6. \n
\n", "tags_en": ["Heap", "Sort", "Divide and Conquer"], "tags_cn": ["\u5806", "\u6392\u5e8f", "\u5206\u6cbb\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> kClosest(vector>& points, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[][] kClosest(int[][] points, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def kClosest(self, points, k):\n \"\"\"\n :type points: List[List[int]]\n :type k: int\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def kClosest(self, points: List[List[int]], k: int) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** kClosest(int** points, int pointsSize, int* pointsColSize, int k, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[][] KClosest(int[][] points, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} points\n * @param {number} k\n * @return {number[][]}\n */\nvar kClosest = function(points, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} points\n# @param {Integer} k\n# @return {Integer[][]}\ndef k_closest(points, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func kClosest(_ points: [[Int]], _ k: Int) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func kClosest(points [][]int, k int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def kClosest(points: Array[Array[Int]], k: Int): Array[Array[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun kClosest(points: Array, k: Int): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn k_closest(points: Vec>, k: i32) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $points\n * @param Integer $k\n * @return Integer[][]\n */\n function kClosest($points, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function kClosest(points: number[][], k: number): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (k-closest points k)\n (-> (listof (listof exact-integer?)) exact-integer? (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0973](https://leetcode-cn.com/problems/k-closest-points-to-origin)", "[\u6700\u63a5\u8fd1\u539f\u70b9\u7684 K \u4e2a\u70b9](/solution/0900-0999/0973.K%20Closest%20Points%20to%20Origin/README.md)", "`\u5806`,`\u6392\u5e8f`,`\u5206\u6cbb\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0973](https://leetcode.com/problems/k-closest-points-to-origin)", "[K Closest Points to Origin](/solution/0900-0999/0973.K%20Closest%20Points%20to%20Origin/README_EN.md)", "`Heap`,`Sort`,`Divide and Conquer`", "Medium", ""]}, {"question_id": "1013", "frontend_question_id": "0509", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/fibonacci-number", "url_en": "https://leetcode.com/problems/fibonacci-number", "relative_path_cn": "/solution/0500-0599/0509.Fibonacci%20Number/README.md", "relative_path_en": "/solution/0500-0599/0509.Fibonacci%20Number/README_EN.md", "title_cn": "\u6590\u6ce2\u90a3\u5951\u6570", "title_en": "Fibonacci Number", "question_title_slug": "fibonacci-number", "content_en": "

The Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1. That is,

\n\n
\nF(0) = 0, F(1) = 1\nF(n) = F(n - 1) + F(n - 2), for n > 1.\n
\n\n

Given n, calculate F(n).

\n\n

 

\n

Example 1:

\n\n
\nInput: n = 2\nOutput: 1\nExplanation: F(2) = F(1) + F(0) = 1 + 0 = 1.\n
\n\n

Example 2:

\n\n
\nInput: n = 3\nOutput: 2\nExplanation: F(3) = F(2) + F(1) = 1 + 1 = 2.\n
\n\n

Example 3:

\n\n
\nInput: n = 4\nOutput: 3\nExplanation: F(4) = F(3) + F(2) = 2 + 1 = 3.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 0 <= n <= 30
  • \n
\n", "content_cn": "

\u6590\u6ce2\u90a3\u5951\u6570\uff0c\u901a\u5e38\u7528\u00a0F(n) \u8868\u793a\uff0c\u5f62\u6210\u7684\u5e8f\u5217\u79f0\u4e3a \u6590\u6ce2\u90a3\u5951\u6570\u5217 \u3002\u8be5\u6570\u5217\u7531\u00a00 \u548c 1 \u5f00\u59cb\uff0c\u540e\u9762\u7684\u6bcf\u4e00\u9879\u6570\u5b57\u90fd\u662f\u524d\u9762\u4e24\u9879\u6570\u5b57\u7684\u548c\u3002\u4e5f\u5c31\u662f\uff1a

\n\n
\nF(0) = 0\uff0cF(1)\u00a0= 1\nF(n) = F(n - 1) + F(n - 2)\uff0c\u5176\u4e2d n > 1\n
\n\n

\u7ed9\u4f60 n \uff0c\u8bf7\u8ba1\u7b97 F(n) \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1a2\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1aF(2) = F(1) + F(0) = 1 + 0 = 1\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1a3\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1aF(3) = F(2) + F(1) = 1 + 1 = 2\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1a4\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1aF(4) = F(3) + F(2) = 2 + 1 = 3\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 0 <= n <= 30
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int fib(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int fib(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def fib(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def fib(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint fib(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int Fib(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar fib = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef fib(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func fib(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func fib(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def fib(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun fib(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn fib(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function fib($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function fib(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (fib n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0509](https://leetcode-cn.com/problems/fibonacci-number)", "[\u6590\u6ce2\u90a3\u5951\u6570](/solution/0500-0599/0509.Fibonacci%20Number/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0509](https://leetcode.com/problems/fibonacci-number)", "[Fibonacci Number](/solution/0500-0599/0509.Fibonacci%20Number/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1012", "frontend_question_id": "0972", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/equal-rational-numbers", "url_en": "https://leetcode.com/problems/equal-rational-numbers", "relative_path_cn": "/solution/0900-0999/0972.Equal%20Rational%20Numbers/README.md", "relative_path_en": "/solution/0900-0999/0972.Equal%20Rational%20Numbers/README_EN.md", "title_cn": "\u76f8\u7b49\u7684\u6709\u7406\u6570", "title_en": "Equal Rational Numbers", "question_title_slug": "equal-rational-numbers", "content_en": "

Given two strings s and t, each of which represents a non-negative rational number, return true if and only if they represent the same number. The strings may use parentheses to denote the repeating part of the rational number.

\n\n

A rational number can be represented using up to three parts: <IntegerPart>, <NonRepeatingPart>, and a <RepeatingPart>. The number will be represented in one of the following three ways:

\n\n
    \n\t
  • <IntegerPart>\n\n\t
      \n\t\t
    • For example, 12, 0, and 123.
    • \n\t
    \n\t
  • \n\t
  • <IntegerPart><.><NonRepeatingPart>\n\t
      \n\t\t
    • For example, 0.5, 1., 2.12, and 123.0001.
    • \n\t
    \n\t
  • \n\t
  • <IntegerPart><.><NonRepeatingPart><(><RepeatingPart><)>\n\t
      \n\t\t
    • For example, 0.1(6), 1.(9), 123.00(1212).
    • \n\t
    \n\t
  • \n
\n\n

The repeating portion of a decimal expansion is conventionally denoted within a pair of round brackets. For example:

\n\n
    \n\t
  • 1/6 = 0.16666666... = 0.1(6) = 0.1666(6) = 0.166(66).
  • \n
\n\n

 

\n

Example 1:

\n\n
\nInput: s = "0.(52)", t = "0.5(25)"\nOutput: true\nExplanation: Because "0.(52)" represents 0.52525252..., and "0.5(25)" represents 0.52525252525..... , the strings represent the same number.\n
\n\n

Example 2:

\n\n
\nInput: s = "0.1666(6)", t = "0.166(66)"\nOutput: true\n
\n\n

Example 3:

\n\n
\nInput: s = "0.9(9)", t = "1."\nOutput: true\nExplanation: "0.9(9)" represents 0.999999999... repeated forever, which equals 1.  [See this link for an explanation.]\n"1." represents the number 1, which is formed correctly: (IntegerPart) = "1" and (NonRepeatingPart) = "".\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • Each part consists only of digits.
  • \n\t
  • The <IntegerPart> does not have leading zeros (except for the zero itself).
  • \n\t
  • 1 <= <IntegerPart>.length <= 4
  • \n\t
  • 0 <= <NonRepeatingPart>.length <= 4
  • \n\t
  • 1 <= <RepeatingPart>.length <= 4
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e24\u4e2a\u5b57\u7b26\u4e32 S \u548c T\uff0c\u6bcf\u4e2a\u5b57\u7b26\u4e32\u4ee3\u8868\u4e00\u4e2a\u975e\u8d1f\u6709\u7406\u6570\uff0c\u53ea\u6709\u5f53\u5b83\u4eec\u8868\u793a\u76f8\u540c\u7684\u6570\u5b57\u65f6\u624d\u8fd4\u56de true\uff1b\u5426\u5219\uff0c\u8fd4\u56de false\u3002\u5b57\u7b26\u4e32\u4e2d\u53ef\u4ee5\u4f7f\u7528\u62ec\u53f7\u6765\u8868\u793a\u6709\u7406\u6570\u7684\u91cd\u590d\u90e8\u5206\u3002

\n\n

\u901a\u5e38\uff0c\u6709\u7406\u6570\u6700\u591a\u53ef\u4ee5\u7528\u4e09\u4e2a\u90e8\u5206\u6765\u8868\u793a\uff1a\u6574\u6570\u90e8\u5206 <IntegerPart>\u3001\u5c0f\u6570\u975e\u91cd\u590d\u90e8\u5206 <NonRepeatingPart> \u548c\u5c0f\u6570\u91cd\u590d\u90e8\u5206 <(><RepeatingPart><)>\u3002\u6570\u5b57\u53ef\u4ee5\u7528\u4ee5\u4e0b\u4e09\u79cd\u65b9\u6cd5\u4e4b\u4e00\u6765\u8868\u793a\uff1a

\n\n
    \n\t
  • <IntegerPart>\uff08\u4f8b\uff1a0\uff0c12\uff0c123\uff09
  • \n\t
  • <IntegerPart><.><NonRepeatingPart> \uff08\u4f8b\uff1a0.5\uff0c2.12\uff0c2.0001\uff09
  • \n\t
  • <IntegerPart><.><NonRepeatingPart><(><RepeatingPart><)>\uff08\u4f8b\uff1a0.1(6)\uff0c0.9(9)\uff0c0.00(1212)\uff09
  • \n
\n\n

\u5341\u8fdb\u5236\u5c55\u5f00\u7684\u91cd\u590d\u90e8\u5206\u901a\u5e38\u5728\u4e00\u5bf9\u5706\u62ec\u53f7\u5185\u8868\u793a\u3002\u4f8b\u5982\uff1a

\n\n

1 / 6 = 0.16666666... = 0.1(6) = 0.1666(6) = 0.166(66)

\n\n

0.1(6) \u6216 0.1666(6) \u6216 0.166(66) \u90fd\u662f 1 / 6 \u7684\u6b63\u786e\u8868\u793a\u5f62\u5f0f\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aS = "0.(52)", T = "0.5(25)"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u56e0\u4e3a "0.(52)" \u4ee3\u8868 0.52525252...\uff0c\u800c "0.5(25)" \u4ee3\u8868 0.52525252525.....\uff0c\u5219\u8fd9\u4e24\u4e2a\u5b57\u7b26\u4e32\u8868\u793a\u76f8\u540c\u7684\u6570\u5b57\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aS = "0.1666(6)", T = "0.166(66)"\n\u8f93\u51fa\uff1atrue\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aS = "0.9(9)", T = "1."\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\n"0.9(9)" \u4ee3\u8868 0.999999999... \u6c38\u8fdc\u91cd\u590d\uff0c\u7b49\u4e8e 1 \u3002[\u6709\u5173\u8bf4\u660e\uff0c\u8bf7\u53c2\u9605\u6b64\u94fe\u63a5]\n"1." \u8868\u793a\u6570\u5b57 1\uff0c\u5176\u683c\u5f0f\u6b63\u786e\uff1a(IntegerPart) = "1" \u4e14 (NonRepeatingPart) = "" \u3002
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. \u6bcf\u4e2a\u90e8\u5206\u4ec5\u7531\u6570\u5b57\u7ec4\u6210\u3002
  2. \n\t
  3. \u6574\u6570\u90e8\u5206 <IntegerPart> \u4e0d\u4f1a\u4ee5 2 \u4e2a\u6216\u66f4\u591a\u7684\u96f6\u5f00\u5934\u3002\uff08\u5bf9\u6bcf\u4e2a\u90e8\u5206\u7684\u6570\u5b57\u6ca1\u6709\u5176\u4ed6\u9650\u5236\uff09\u3002
  4. \n\t
  5. 1 <= <IntegerPart>.length <= 4
  6. \n\t
  7. 0 <= <NonRepeatingPart>.length <= 4
  8. \n\t
  9. 1 <= <RepeatingPart>.length <= 4
  10. \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isRationalEqual(string s, string t) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isRationalEqual(String s, String t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isRationalEqual(self, s, t):\n \"\"\"\n :type s: str\n :type t: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isRationalEqual(self, s: str, t: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isRationalEqual(char * s, char * t){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsRationalEqual(string s, string t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string} t\n * @return {boolean}\n */\nvar isRationalEqual = function(s, t) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String} t\n# @return {Boolean}\ndef is_rational_equal(s, t)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isRationalEqual(_ s: String, _ t: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isRationalEqual(s string, t string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isRationalEqual(s: String, t: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isRationalEqual(s: String, t: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_rational_equal(s: String, t: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String $t\n * @return Boolean\n */\n function isRationalEqual($s, $t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isRationalEqual(s: string, t: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-rational-equal s t)\n (-> string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0972](https://leetcode-cn.com/problems/equal-rational-numbers)", "[\u76f8\u7b49\u7684\u6709\u7406\u6570](/solution/0900-0999/0972.Equal%20Rational%20Numbers/README.md)", "`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[0972](https://leetcode.com/problems/equal-rational-numbers)", "[Equal Rational Numbers](/solution/0900-0999/0972.Equal%20Rational%20Numbers/README_EN.md)", "`Math`", "Hard", ""]}, {"question_id": "1011", "frontend_question_id": "0971", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/flip-binary-tree-to-match-preorder-traversal", "url_en": "https://leetcode.com/problems/flip-binary-tree-to-match-preorder-traversal", "relative_path_cn": "/solution/0900-0999/0971.Flip%20Binary%20Tree%20To%20Match%20Preorder%20Traversal/README.md", "relative_path_en": "/solution/0900-0999/0971.Flip%20Binary%20Tree%20To%20Match%20Preorder%20Traversal/README_EN.md", "title_cn": "\u7ffb\u8f6c\u4e8c\u53c9\u6811\u4ee5\u5339\u914d\u5148\u5e8f\u904d\u5386", "title_en": "Flip Binary Tree To Match Preorder Traversal", "question_title_slug": "flip-binary-tree-to-match-preorder-traversal", "content_en": "

You are given the root of a binary tree with n nodes, where each node is uniquely assigned a value from 1 to n. You are also given a sequence of n values voyage, which is the desired pre-order traversal of the binary tree.

\n\n

Any node in the binary tree can be flipped by swapping its left and right subtrees. For example, flipping node 1 will have the following effect:

\n\"\"\n

Flip the smallest number of nodes so that the pre-order traversal of the tree matches voyage.

\n\n

Return a list of the values of all flipped nodes. You may return the answer in any order. If it is impossible to flip the nodes in the tree to make the pre-order traversal match voyage, return the list [-1].

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: root = [1,2], voyage = [2,1]\nOutput: [-1]\nExplanation: It is impossible to flip the nodes such that the pre-order traversal matches voyage.\n
\n\n

Example 2:

\n\"\"\n
\nInput: root = [1,2,3], voyage = [1,3,2]\nOutput: [1]\nExplanation: Flipping node 1 swaps nodes 2 and 3, so the pre-order traversal matches voyage.
\n\n

Example 3:

\n\"\"\n
\nInput: root = [1,2,3], voyage = [1,2,3]\nOutput: []\nExplanation: The tree's pre-order traversal already matches voyage, so no nodes need to be flipped.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The number of nodes in the tree is n.
  • \n\t
  • n == voyage.length
  • \n\t
  • 1 <= n <= 100
  • \n\t
  • 1 <= Node.val, voyage[i] <= n
  • \n\t
  • All the values in the tree are unique.
  • \n\t
  • All the values in voyage are unique.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u68f5\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9 root \uff0c\u6811\u4e2d\u6709 n \u4e2a\u8282\u70b9\uff0c\u6bcf\u4e2a\u8282\u70b9\u90fd\u6709\u4e00\u4e2a\u4e0d\u540c\u4e8e\u5176\u4ed6\u8282\u70b9\u4e14\u5904\u4e8e 1 \u5230 n \u4e4b\u95f4\u7684\u503c\u3002

\n\n

\u53e6\u7ed9\u4f60\u4e00\u4e2a\u7531 n \u4e2a\u503c\u7ec4\u6210\u7684\u884c\u7a0b\u5e8f\u5217 voyage \uff0c\u8868\u793a \u9884\u671f \u7684\u4e8c\u53c9\u6811 \u5148\u5e8f\u904d\u5386 \u7ed3\u679c\u3002

\n\n

\u901a\u8fc7\u4ea4\u6362\u8282\u70b9\u7684\u5de6\u53f3\u5b50\u6811\uff0c\u53ef\u4ee5 \u7ffb\u8f6c \u8be5\u4e8c\u53c9\u6811\u4e2d\u7684\u4efb\u610f\u8282\u70b9\u3002\u4f8b\uff0c\u7ffb\u8f6c\u8282\u70b9 1 \u7684\u6548\u679c\u5982\u4e0b\uff1a

\n\"\"\n

\u8bf7\u7ffb\u8f6c \u6700\u5c11 \u7684\u6811\u4e2d\u8282\u70b9\uff0c\u4f7f\u4e8c\u53c9\u6811\u7684 \u5148\u5e8f\u904d\u5386 \u4e0e\u9884\u671f\u7684\u904d\u5386\u884c\u7a0b\u00a0voyage\u00a0\u76f8\u5339\u914d \u3002\u00a0

\n\n

\u5982\u679c\u53ef\u4ee5\uff0c\u5219\u8fd4\u56de \u7ffb\u8f6c\u7684 \u6240\u6709\u8282\u70b9\u7684\u503c\u7684\u5217\u8868\u3002\u4f60\u53ef\u4ee5\u6309\u4efb\u4f55\u987a\u5e8f\u8fd4\u56de\u7b54\u6848\u3002\u5982\u679c\u4e0d\u80fd\uff0c\u5219\u8fd4\u56de\u5217\u8868 [-1]\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1aroot = [1,2], voyage = [2,1]\n\u8f93\u51fa\uff1a[-1]\n\u89e3\u91ca\uff1a\u7ffb\u8f6c\u8282\u70b9\u65e0\u6cd5\u4ee4\u5148\u5e8f\u904d\u5386\u5339\u914d\u9884\u671f\u884c\u7a0b\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1aroot = [1,2,3], voyage = [1,3,2]\n\u8f93\u51fa\uff1a[1]\n\u89e3\u91ca\uff1a\u4ea4\u6362\u8282\u70b9 2 \u548c 3 \u6765\u7ffb\u8f6c\u8282\u70b9 1 \uff0c\u5148\u5e8f\u904d\u5386\u53ef\u4ee5\u5339\u914d\u9884\u671f\u884c\u7a0b\u3002
\n\n

\u793a\u4f8b 3\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1aroot = [1,2,3], voyage = [1,2,3]\n\u8f93\u51fa\uff1a[]\n\u89e3\u91ca\uff1a\u5148\u5e8f\u904d\u5386\u5df2\u7ecf\u5339\u914d\u9884\u671f\u884c\u7a0b\uff0c\u6240\u4ee5\u4e0d\u9700\u8981\u7ffb\u8f6c\u8282\u70b9\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u6811\u4e2d\u7684\u8282\u70b9\u6570\u76ee\u4e3a n
  • \n\t
  • n == voyage.length
  • \n\t
  • 1 <= n <= 100
  • \n\t
  • 1 <= Node.val, voyage[i] <= n
  • \n\t
  • \u6811\u4e2d\u7684\u6240\u6709\u503c \u4e92\u4e0d\u76f8\u540c
  • \n\t
  • voyage \u4e2d\u7684\u6240\u6709\u503c \u4e92\u4e0d\u76f8\u540c
  • \n
\n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector flipMatchVoyage(TreeNode* root, vector& voyage) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public List flipMatchVoyage(TreeNode root, int[] voyage) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def flipMatchVoyage(self, root, voyage):\n \"\"\"\n :type root: TreeNode\n :type voyage: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def flipMatchVoyage(self, root: TreeNode, voyage: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* flipMatchVoyage(struct TreeNode* root, int* voyage, int voyageSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public IList FlipMatchVoyage(TreeNode root, int[] voyage) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number[]} voyage\n * @return {number[]}\n */\nvar flipMatchVoyage = function(root, voyage) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @param {Integer[]} voyage\n# @return {Integer[]}\ndef flip_match_voyage(root, voyage)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func flipMatchVoyage(_ root: TreeNode?, _ voyage: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc flipMatchVoyage(root *TreeNode, voyage []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def flipMatchVoyage(root: TreeNode, voyage: Array[Int]): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun flipMatchVoyage(root: TreeNode?, voyage: IntArray): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn flip_match_voyage(root: Option>>, voyage: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param Integer[] $voyage\n * @return Integer[]\n */\n function flipMatchVoyage($root, $voyage) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction flipMatchVoyage(root: TreeNode | null, voyage: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (flip-match-voyage root voyage)\n (-> (or/c tree-node? #f) (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0971](https://leetcode-cn.com/problems/flip-binary-tree-to-match-preorder-traversal)", "[\u7ffb\u8f6c\u4e8c\u53c9\u6811\u4ee5\u5339\u914d\u5148\u5e8f\u904d\u5386](/solution/0900-0999/0971.Flip%20Binary%20Tree%20To%20Match%20Preorder%20Traversal/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0971](https://leetcode.com/problems/flip-binary-tree-to-match-preorder-traversal)", "[Flip Binary Tree To Match Preorder Traversal](/solution/0900-0999/0971.Flip%20Binary%20Tree%20To%20Match%20Preorder%20Traversal/README_EN.md)", "`Tree`,`Depth-first Search`", "Medium", ""]}, {"question_id": "1010", "frontend_question_id": "0970", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/powerful-integers", "url_en": "https://leetcode.com/problems/powerful-integers", "relative_path_cn": "/solution/0900-0999/0970.Powerful%20Integers/README.md", "relative_path_en": "/solution/0900-0999/0970.Powerful%20Integers/README_EN.md", "title_cn": "\u5f3a\u6574\u6570", "title_en": "Powerful Integers", "question_title_slug": "powerful-integers", "content_en": "

Given three integers x, y, and bound, return a list of all the powerful integers that have a value less than or equal to bound.

\n\n

An integer is powerful if it can be represented as xi + yj for some integers i >= 0 and j >= 0.

\n\n

You may return the answer in any order. In your answer, each value should occur at most once.

\n\n

 

\n

Example 1:

\n\n
\nInput: x = 2, y = 3, bound = 10\nOutput: [2,3,4,5,7,9,10]\nExplanation:\n2 = 20 + 30\n3 = 21 + 30\n4 = 20 + 31\n5 = 21 + 31\n7 = 22 + 31\n9 = 23 + 30\n10 = 20 + 32\n
\n\n

Example 2:

\n\n
\nInput: x = 3, y = 5, bound = 15\nOutput: [2,4,6,8,10,14]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= x, y <= 100
  • \n\t
  • 0 <= bound <= 106
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e24\u4e2a\u6b63\u6574\u6570 x \u548c y\uff0c\u5982\u679c\u67d0\u4e00\u6574\u6570\u7b49\u4e8e x^i + y^j\uff0c\u5176\u4e2d\u6574\u6570 i >= 0 \u4e14 j >= 0\uff0c\u90a3\u4e48\u6211\u4eec\u8ba4\u4e3a\u8be5\u6574\u6570\u662f\u4e00\u4e2a\u5f3a\u6574\u6570\u3002

\n\n

\u8fd4\u56de\u503c\u5c0f\u4e8e\u6216\u7b49\u4e8e bound \u7684\u6240\u6709\u5f3a\u6574\u6570\u7ec4\u6210\u7684\u5217\u8868\u3002

\n\n

\u4f60\u53ef\u4ee5\u6309\u4efb\u4f55\u987a\u5e8f\u8fd4\u56de\u7b54\u6848\u3002\u5728\u4f60\u7684\u56de\u7b54\u4e2d\uff0c\u6bcf\u4e2a\u503c\u6700\u591a\u51fa\u73b0\u4e00\u6b21\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1ax = 2, y = 3, bound = 10\n\u8f93\u51fa\uff1a[2,3,4,5,7,9,10]\n\u89e3\u91ca\uff1a \n2 = 2^0 + 3^0\n3 = 2^1 + 3^0\n4 = 2^0 + 3^1\n5 = 2^1 + 3^1\n7 = 2^2 + 3^1\n9 = 2^3 + 3^0\n10 = 2^0 + 3^2\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1ax = 3, y = 5, bound = 15\n\u8f93\u51fa\uff1a[2,4,6,8,10,14]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= x <= 100
  • \n\t
  • 1 <= y <= 100
  • \n\t
  • 0 <= bound <= 10^6
  • \n
\n", "tags_en": ["Hash Table", "Math"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector powerfulIntegers(int x, int y, int bound) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List powerfulIntegers(int x, int y, int bound) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def powerfulIntegers(self, x, y, bound):\n \"\"\"\n :type x: int\n :type y: int\n :type bound: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def powerfulIntegers(self, x: int, y: int, bound: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* powerfulIntegers(int x, int y, int bound, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList PowerfulIntegers(int x, int y, int bound) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} x\n * @param {number} y\n * @param {number} bound\n * @return {number[]}\n */\nvar powerfulIntegers = function(x, y, bound) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} x\n# @param {Integer} y\n# @param {Integer} bound\n# @return {Integer[]}\ndef powerful_integers(x, y, bound)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func powerfulIntegers(_ x: Int, _ y: Int, _ bound: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func powerfulIntegers(x int, y int, bound int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def powerfulIntegers(x: Int, y: Int, bound: Int): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun powerfulIntegers(x: Int, y: Int, bound: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn powerful_integers(x: i32, y: i32, bound: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $x\n * @param Integer $y\n * @param Integer $bound\n * @return Integer[]\n */\n function powerfulIntegers($x, $y, $bound) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function powerfulIntegers(x: number, y: number, bound: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (powerful-integers x y bound)\n (-> exact-integer? exact-integer? exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0970](https://leetcode-cn.com/problems/powerful-integers)", "[\u5f3a\u6574\u6570](/solution/0900-0999/0970.Powerful%20Integers/README.md)", "`\u54c8\u5e0c\u8868`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0970](https://leetcode.com/problems/powerful-integers)", "[Powerful Integers](/solution/0900-0999/0970.Powerful%20Integers/README_EN.md)", "`Hash Table`,`Math`", "Medium", ""]}, {"question_id": "1009", "frontend_question_id": "0969", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/pancake-sorting", "url_en": "https://leetcode.com/problems/pancake-sorting", "relative_path_cn": "/solution/0900-0999/0969.Pancake%20Sorting/README.md", "relative_path_en": "/solution/0900-0999/0969.Pancake%20Sorting/README_EN.md", "title_cn": "\u714e\u997c\u6392\u5e8f", "title_en": "Pancake Sorting", "question_title_slug": "pancake-sorting", "content_en": "

Given an array of integers arr, sort the array by performing a series of pancake flips.

\n\n

In one pancake flip we do the following steps:

\n\n
    \n\t
  • Choose an integer k where 1 <= k <= arr.length.
  • \n\t
  • Reverse the sub-array arr[0...k-1] (0-indexed).
  • \n
\n\n

For example, if arr = [3,2,1,4] and we performed a pancake flip choosing k = 3, we reverse the sub-array [3,2,1], so arr = [1,2,3,4] after the pancake flip at k = 3.

\n\n

Return an array of the k-values corresponding to a sequence of pancake flips that sort arr. Any valid answer that sorts the array within 10 * arr.length flips will be judged as correct.

\n\n

 

\n

Example 1:

\n\n
\nInput: arr = [3,2,4,1]\nOutput: [4,2,4,3]\nExplanation: \nWe perform 4 pancake flips, with k values 4, 2, 4, and 3.\nStarting state: arr = [3, 2, 4, 1]\nAfter 1st flip (k = 4): arr = [1, 4, 2, 3]\nAfter 2nd flip (k = 2): arr = [4, 1, 2, 3]\nAfter 3rd flip (k = 4): arr = [3, 2, 1, 4]\nAfter 4th flip (k = 3): arr = [1, 2, 3, 4], which is sorted.\n
\n\n

Example 2:

\n\n
\nInput: arr = [1,2,3]\nOutput: []\nExplanation: The input is already sorted, so there is no need to flip anything.\nNote that other answers, such as [3, 3], would also be accepted.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= arr.length <= 100
  • \n\t
  • 1 <= arr[i] <= arr.length
  • \n\t
  • All integers in arr are unique (i.e. arr is a permutation of the integers from 1 to arr.length).
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr \uff0c\u8bf7\u4f7f\u7528 \u714e\u997c\u7ffb\u8f6c \u5b8c\u6210\u5bf9\u6570\u7ec4\u7684\u6392\u5e8f\u3002

\n\n

\u4e00\u6b21\u714e\u997c\u7ffb\u8f6c\u7684\u6267\u884c\u8fc7\u7a0b\u5982\u4e0b\uff1a

\n\n
    \n\t
  • \u9009\u62e9\u4e00\u4e2a\u6574\u6570 k \uff0c1 <= k <= arr.length
  • \n\t
  • \u53cd\u8f6c\u5b50\u6570\u7ec4 arr[0...k-1]\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09
  • \n
\n\n

\u4f8b\u5982\uff0carr = [3,2,1,4] \uff0c\u9009\u62e9 k = 3 \u8fdb\u884c\u4e00\u6b21\u714e\u997c\u7ffb\u8f6c\uff0c\u53cd\u8f6c\u5b50\u6570\u7ec4 [3,2,1] \uff0c\u5f97\u5230 arr = [1,2,3,4] \u3002

\n\n

\u4ee5\u6570\u7ec4\u5f62\u5f0f\u8fd4\u56de\u80fd\u4f7f arr \u6709\u5e8f\u7684\u714e\u997c\u7ffb\u8f6c\u64cd\u4f5c\u6240\u5bf9\u5e94\u7684 k \u503c\u5e8f\u5217\u3002\u4efb\u4f55\u5c06\u6570\u7ec4\u6392\u5e8f\u4e14\u7ffb\u8f6c\u6b21\u6570\u5728\u00a010 * arr.length \u8303\u56f4\u5185\u7684\u6709\u6548\u7b54\u6848\u90fd\u5c06\u88ab\u5224\u65ad\u4e3a\u6b63\u786e\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1a[3,2,4,1]\n\u8f93\u51fa\uff1a[4,2,4,3]\n\u89e3\u91ca\uff1a\n\u6211\u4eec\u6267\u884c 4 \u6b21\u714e\u997c\u7ffb\u8f6c\uff0ck \u503c\u5206\u522b\u4e3a 4\uff0c2\uff0c4\uff0c\u548c 3\u3002\n\u521d\u59cb\u72b6\u6001 arr = [3, 2, 4, 1]\n\u7b2c\u4e00\u6b21\u7ffb\u8f6c\u540e\uff08k = 4\uff09\uff1aarr = [1, 4, 2, 3]\n\u7b2c\u4e8c\u6b21\u7ffb\u8f6c\u540e\uff08k = 2\uff09\uff1aarr = [4, 1, 2, 3]\n\u7b2c\u4e09\u6b21\u7ffb\u8f6c\u540e\uff08k = 4\uff09\uff1aarr = [3, 2, 1, 4]\n\u7b2c\u56db\u6b21\u7ffb\u8f6c\u540e\uff08k = 3\uff09\uff1aarr = [1, 2, 3, 4]\uff0c\u6b64\u65f6\u5df2\u5b8c\u6210\u6392\u5e8f\u3002 \n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1a[1,2,3]\n\u8f93\u51fa\uff1a[]\n\u89e3\u91ca\uff1a\n\u8f93\u5165\u5df2\u7ecf\u6392\u5e8f\uff0c\u56e0\u6b64\u4e0d\u9700\u8981\u7ffb\u8f6c\u4efb\u4f55\u5185\u5bb9\u3002\n\u8bf7\u6ce8\u610f\uff0c\u5176\u4ed6\u53ef\u80fd\u7684\u7b54\u6848\uff0c\u5982 [3\uff0c3] \uff0c\u4e5f\u5c06\u88ab\u5224\u65ad\u4e3a\u6b63\u786e\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= arr.length <= 100
  • \n\t
  • 1 <= arr[i] <= arr.length
  • \n\t
  • arr \u4e2d\u7684\u6240\u6709\u6574\u6570\u4e92\u4e0d\u76f8\u540c\uff08\u5373\uff0carr \u662f\u4ece 1 \u5230 arr.length \u6574\u6570\u7684\u4e00\u4e2a\u6392\u5217\uff09
  • \n
\n", "tags_en": ["Sort", "Array"], "tags_cn": ["\u6392\u5e8f", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector pancakeSort(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List pancakeSort(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def pancakeSort(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def pancakeSort(self, arr: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* pancakeSort(int* arr, int arrSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList PancakeSort(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number[]}\n */\nvar pancakeSort = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer[]}\ndef pancake_sort(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func pancakeSort(_ arr: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func pancakeSort(arr []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def pancakeSort(arr: Array[Int]): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun pancakeSort(arr: IntArray): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn pancake_sort(arr: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer[]\n */\n function pancakeSort($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function pancakeSort(arr: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (pancake-sort arr)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0969](https://leetcode-cn.com/problems/pancake-sorting)", "[\u714e\u997c\u6392\u5e8f](/solution/0900-0999/0969.Pancake%20Sorting/README.md)", "`\u6392\u5e8f`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0969](https://leetcode.com/problems/pancake-sorting)", "[Pancake Sorting](/solution/0900-0999/0969.Pancake%20Sorting/README_EN.md)", "`Sort`,`Array`", "Medium", ""]}, {"question_id": "1008", "frontend_question_id": "0968", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/binary-tree-cameras", "url_en": "https://leetcode.com/problems/binary-tree-cameras", "relative_path_cn": "/solution/0900-0999/0968.Binary%20Tree%20Cameras/README.md", "relative_path_en": "/solution/0900-0999/0968.Binary%20Tree%20Cameras/README_EN.md", "title_cn": "\u76d1\u63a7\u4e8c\u53c9\u6811", "title_en": "Binary Tree Cameras", "question_title_slug": "binary-tree-cameras", "content_en": "

You are given the root of a binary tree. We install cameras on the tree nodes where each camera at a node can monitor its parent, itself, and its immediate children.

\n\n

Return the minimum number of cameras needed to monitor all nodes of the tree.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: root = [0,0,null,0,0]\nOutput: 1\nExplanation: One camera is enough to monitor all nodes if placed as shown.\n
\n\n

Example 2:

\n\"\"\n
\nInput: root = [0,0,null,0,null,0,null,null,0]\nOutput: 2\nExplanation: At least two cameras are needed to monitor all nodes of the tree. The above image shows one of the valid configurations of camera placement.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The number of nodes in the tree is in the range [1, 1000].
  • \n\t
  • Node.val == 0
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811\uff0c\u6211\u4eec\u5728\u6811\u7684\u8282\u70b9\u4e0a\u5b89\u88c5\u6444\u50cf\u5934\u3002

\n\n

\u8282\u70b9\u4e0a\u7684\u6bcf\u4e2a\u6444\u5f71\u5934\u90fd\u53ef\u4ee5\u76d1\u89c6\u5176\u7236\u5bf9\u8c61\u3001\u81ea\u8eab\u53ca\u5176\u76f4\u63a5\u5b50\u5bf9\u8c61\u3002

\n\n

\u8ba1\u7b97\u76d1\u63a7\u6811\u7684\u6240\u6709\u8282\u70b9\u6240\u9700\u7684\u6700\u5c0f\u6444\u50cf\u5934\u6570\u91cf\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1a[0,0,null,0,0]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u5982\u56fe\u6240\u793a\uff0c\u4e00\u53f0\u6444\u50cf\u5934\u8db3\u4ee5\u76d1\u63a7\u6240\u6709\u8282\u70b9\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1a[0,0,null,0,null,0,null,null,0]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u9700\u8981\u81f3\u5c11\u4e24\u4e2a\u6444\u50cf\u5934\u6765\u76d1\u89c6\u6811\u7684\u6240\u6709\u8282\u70b9\u3002 \u4e0a\u56fe\u663e\u793a\u4e86\u6444\u50cf\u5934\u653e\u7f6e\u7684\u6709\u6548\u4f4d\u7f6e\u4e4b\u4e00\u3002\n
\n\n


\n\u63d0\u793a\uff1a

\n\n
    \n\t
  1. \u7ed9\u5b9a\u6811\u7684\u8282\u70b9\u6570\u7684\u8303\u56f4\u662f [1, 1000]\u3002
  2. \n\t
  3. \u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u90fd\u662f 0\u3002
  4. \n
\n", "tags_en": ["Tree", "Depth-first Search", "Dynamic Programming"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int minCameraCover(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int minCameraCover(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def minCameraCover(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def minCameraCover(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint minCameraCover(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int MinCameraCover(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar minCameraCover = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef min_camera_cover(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func minCameraCover(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc minCameraCover(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def minCameraCover(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun minCameraCover(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn min_camera_cover(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function minCameraCover($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction minCameraCover(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (min-camera-cover root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0968](https://leetcode-cn.com/problems/binary-tree-cameras)", "[\u76d1\u63a7\u4e8c\u53c9\u6811](/solution/0900-0999/0968.Binary%20Tree%20Cameras/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0968](https://leetcode.com/problems/binary-tree-cameras)", "[Binary Tree Cameras](/solution/0900-0999/0968.Binary%20Tree%20Cameras/README_EN.md)", "`Tree`,`Depth-first Search`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "1007", "frontend_question_id": "0967", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/numbers-with-same-consecutive-differences", "url_en": "https://leetcode.com/problems/numbers-with-same-consecutive-differences", "relative_path_cn": "/solution/0900-0999/0967.Numbers%20With%20Same%20Consecutive%20Differences/README.md", "relative_path_en": "/solution/0900-0999/0967.Numbers%20With%20Same%20Consecutive%20Differences/README_EN.md", "title_cn": "\u8fde\u7eed\u5dee\u76f8\u540c\u7684\u6570\u5b57", "title_en": "Numbers With Same Consecutive Differences", "question_title_slug": "numbers-with-same-consecutive-differences", "content_en": "

Return all non-negative integers of length n such that the absolute difference between every two consecutive digits is k.

\n\n

Note that every number in the answer must not have leading zeros. For example, 01 has one leading zero and is invalid.

\n\n

You may return the answer in any order.

\n\n

 

\n

Example 1:

\n\n
\nInput: n = 3, k = 7\nOutput: [181,292,707,818,929]\nExplanation: Note that 070 is not a valid number, because it has leading zeroes.\n
\n\n

Example 2:

\n\n
\nInput: n = 2, k = 1\nOutput: [10,12,21,23,32,34,43,45,54,56,65,67,76,78,87,89,98]\n
\n\n

Example 3:

\n\n
\nInput: n = 2, k = 0\nOutput: [11,22,33,44,55,66,77,88,99]\n
\n\n

Example 4:

\n\n
\nInput: n = 2, k = 2\nOutput: [13,20,24,31,35,42,46,53,57,64,68,75,79,86,97]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= n <= 9
  • \n\t
  • 0 <= k <= 9
  • \n
\n", "content_cn": "

\u8fd4\u56de\u6240\u6709\u957f\u5ea6\u4e3a n \u4e14\u6ee1\u8db3\u5176\u6bcf\u4e24\u4e2a\u8fde\u7eed\u4f4d\u4e0a\u7684\u6570\u5b57\u4e4b\u95f4\u7684\u5dee\u7684\u7edd\u5bf9\u503c\u4e3a k \u7684 \u975e\u8d1f\u6574\u6570 \u3002

\n\n

\u8bf7\u6ce8\u610f\uff0c\u9664\u4e86 \u6570\u5b57 0 \u672c\u8eab\u4e4b\u5916\uff0c\u7b54\u6848\u4e2d\u7684\u6bcf\u4e2a\u6570\u5b57\u90fd \u4e0d\u80fd \u6709\u524d\u5bfc\u96f6\u3002\u4f8b\u5982\uff0c01 \u6709\u4e00\u4e2a\u524d\u5bfc\u96f6\uff0c\u6240\u4ee5\u662f\u65e0\u6548\u7684\uff1b\u4f46 0\u00a0\u662f\u6709\u6548\u7684\u3002

\n\n

\u4f60\u53ef\u4ee5\u6309 \u4efb\u4f55\u987a\u5e8f \u8fd4\u56de\u7b54\u6848\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1an = 3, k = 7\n\u8f93\u51fa\uff1a[181,292,707,818,929]\n\u89e3\u91ca\uff1a\u6ce8\u610f\uff0c070 \u4e0d\u662f\u4e00\u4e2a\u6709\u6548\u7684\u6570\u5b57\uff0c\u56e0\u4e3a\u5b83\u6709\u524d\u5bfc\u96f6\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1an = 2, k = 1\n\u8f93\u51fa\uff1a[10,12,21,23,32,34,43,45,54,56,65,67,76,78,87,89,98]
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1an = 2, k = 0\n\u8f93\u51fa\uff1a[11,22,33,44,55,66,77,88,99]\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1an = 2, k = 2\n\u8f93\u51fa\uff1a[13,20,24,31,35,42,46,53,57,64,68,75,79,86,97]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= n <= 9
  • \n\t
  • 0 <= k <= 9
  • \n
\n", "tags_en": ["Depth-first Search", "Breadth-first Search", "Recursion", "Backtracking"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u9012\u5f52", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector numsSameConsecDiff(int n, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] numsSameConsecDiff(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numsSameConsecDiff(self, n, k):\n \"\"\"\n :type n: int\n :type k: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numsSameConsecDiff(self, n: int, k: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* numsSameConsecDiff(int n, int k, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] NumsSameConsecDiff(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} k\n * @return {number[]}\n */\nvar numsSameConsecDiff = function(n, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} k\n# @return {Integer[]}\ndef nums_same_consec_diff(n, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numsSameConsecDiff(_ n: Int, _ k: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numsSameConsecDiff(n int, k int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numsSameConsecDiff(n: Int, k: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numsSameConsecDiff(n: Int, k: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn nums_same_consec_diff(n: i32, k: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $k\n * @return Integer[]\n */\n function numsSameConsecDiff($n, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numsSameConsecDiff(n: number, k: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (nums-same-consec-diff n k)\n (-> exact-integer? exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0967](https://leetcode-cn.com/problems/numbers-with-same-consecutive-differences)", "[\u8fde\u7eed\u5dee\u76f8\u540c\u7684\u6570\u5b57](/solution/0900-0999/0967.Numbers%20With%20Same%20Consecutive%20Differences/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u9012\u5f52`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0967](https://leetcode.com/problems/numbers-with-same-consecutive-differences)", "[Numbers With Same Consecutive Differences](/solution/0900-0999/0967.Numbers%20With%20Same%20Consecutive%20Differences/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`,`Recursion`,`Backtracking`", "Medium", ""]}, {"question_id": "1006", "frontend_question_id": "0966", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/vowel-spellchecker", "url_en": "https://leetcode.com/problems/vowel-spellchecker", "relative_path_cn": "/solution/0900-0999/0966.Vowel%20Spellchecker/README.md", "relative_path_en": "/solution/0900-0999/0966.Vowel%20Spellchecker/README_EN.md", "title_cn": "\u5143\u97f3\u62fc\u5199\u68c0\u67e5\u5668", "title_en": "Vowel Spellchecker", "question_title_slug": "vowel-spellchecker", "content_en": "

Given a wordlist, we want to implement a spellchecker that converts a query word into a correct word.

\n\n

For a given query word, the spell checker handles two categories of spelling mistakes:

\n\n
    \n\t
  • Capitalization: If the query matches a word in the wordlist (case-insensitive), then the query word is returned with the same case as the case in the wordlist.\n\n\t
      \n\t\t
    • Example: wordlist = ["yellow"], query = "YellOw": correct = "yellow"
    • \n\t\t
    • Example: wordlist = ["Yellow"], query = "yellow": correct = "Yellow"
    • \n\t\t
    • Example: wordlist = ["yellow"], query = "yellow": correct = "yellow"
    • \n\t
    \n\t
  • \n\t
  • Vowel Errors: If after replacing the vowels ('a', 'e', 'i', 'o', 'u') of the query word with any vowel individually, it matches a word in the wordlist (case-insensitive), then the query word is returned with the same case as the match in the wordlist.\n\t
      \n\t\t
    • Example: wordlist = ["YellOw"], query = "yollow": correct = "YellOw"
    • \n\t\t
    • Example: wordlist = ["YellOw"], query = "yeellow": correct = "" (no match)
    • \n\t\t
    • Example: wordlist = ["YellOw"], query = "yllw": correct = "" (no match)
    • \n\t
    \n\t
  • \n
\n\n

In addition, the spell checker operates under the following precedence rules:

\n\n
    \n\t
  • When the query exactly matches a word in the wordlist (case-sensitive), you should return the same word back.
  • \n\t
  • When the query matches a word up to capitlization, you should return the first such match in the wordlist.
  • \n\t
  • When the query matches a word up to vowel errors, you should return the first such match in the wordlist.
  • \n\t
  • If the query has no matches in the wordlist, you should return the empty string.
  • \n
\n\n

Given some queries, return a list of words answer, where answer[i] is the correct word for query = queries[i].

\n\n

 

\n

Example 1:

\n
Input: wordlist = [\"KiTe\",\"kite\",\"hare\",\"Hare\"], queries = [\"kite\",\"Kite\",\"KiTe\",\"Hare\",\"HARE\",\"Hear\",\"hear\",\"keti\",\"keet\",\"keto\"]\nOutput: [\"kite\",\"KiTe\",\"KiTe\",\"Hare\",\"hare\",\"\",\"\",\"KiTe\",\"\",\"KiTe\"]\n

Example 2:

\n
Input: wordlist = [\"yellow\"], queries = [\"YellOw\"]\nOutput: [\"yellow\"]\n
\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= wordlist.length, queries.length <= 5000
  • \n\t
  • 1 <= wordlist[i].length, queries[i].length <= 7
  • \n\t
  • wordlist[i] and queries[i] consist only of only English letters.
  • \n
\n", "content_cn": "

\u5728\u7ed9\u5b9a\u5355\u8bcd\u5217\u8868 wordlist \u7684\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u5e0c\u671b\u5b9e\u73b0\u4e00\u4e2a\u62fc\u5199\u68c0\u67e5\u5668\uff0c\u5c06\u67e5\u8be2\u5355\u8bcd\u8f6c\u6362\u4e3a\u6b63\u786e\u7684\u5355\u8bcd\u3002

\n\n

\u5bf9\u4e8e\u7ed9\u5b9a\u7684\u67e5\u8be2\u5355\u8bcd query\uff0c\u62fc\u5199\u68c0\u67e5\u5668\u5c06\u4f1a\u5904\u7406\u4e24\u7c7b\u62fc\u5199\u9519\u8bef\uff1a

\n\n
    \n\t
  • \u5927\u5c0f\u5199\uff1a\u5982\u679c\u67e5\u8be2\u5339\u914d\u5355\u8bcd\u5217\u8868\u4e2d\u7684\u67d0\u4e2a\u5355\u8bcd\uff08\u4e0d\u533a\u5206\u5927\u5c0f\u5199\uff09\uff0c\u5219\u8fd4\u56de\u7684\u6b63\u786e\u5355\u8bcd\u4e0e\u5355\u8bcd\u5217\u8868\u4e2d\u7684\u5927\u5c0f\u5199\u76f8\u540c\u3002\n\n\t
      \n\t\t
    • \u4f8b\u5982\uff1awordlist = ["yellow"], query = "YellOw": correct = "yellow"
    • \n\t\t
    • \u4f8b\u5982\uff1awordlist = ["Yellow"], query = "yellow": correct = "Yellow"
    • \n\t\t
    • \u4f8b\u5982\uff1awordlist = ["yellow"], query = "yellow": correct = "yellow"
    • \n\t
    \n\t
  • \n\t
  • \u5143\u97f3\u9519\u8bef\uff1a\u5982\u679c\u5728\u5c06\u67e5\u8be2\u5355\u8bcd\u4e2d\u7684\u5143\u97f3\uff08‘a’\u3001‘e’\u3001‘i’\u3001‘o’\u3001‘u’\uff09\u5206\u522b\u66ff\u6362\u4e3a\u4efb\u4f55\u5143\u97f3\u540e\uff0c\u80fd\u4e0e\u5355\u8bcd\u5217\u8868\u4e2d\u7684\u5355\u8bcd\u5339\u914d\uff08\u4e0d\u533a\u5206\u5927\u5c0f\u5199\uff09\uff0c\u5219\u8fd4\u56de\u7684\u6b63\u786e\u5355\u8bcd\u4e0e\u5355\u8bcd\u5217\u8868\u4e2d\u7684\u5339\u914d\u9879\u5927\u5c0f\u5199\u76f8\u540c\u3002\n\t
      \n\t\t
    • \u4f8b\u5982\uff1awordlist = ["YellOw"], query = "yollow": correct = "YellOw"
    • \n\t\t
    • \u4f8b\u5982\uff1awordlist = ["YellOw"], query = "yeellow": correct = "" \uff08\u65e0\u5339\u914d\u9879\uff09
    • \n\t\t
    • \u4f8b\u5982\uff1awordlist = ["YellOw"], query = "yllw": correct = "" \uff08\u65e0\u5339\u914d\u9879\uff09
    • \n\t
    \n\t
  • \n
\n\n

\u6b64\u5916\uff0c\u62fc\u5199\u68c0\u67e5\u5668\u8fd8\u6309\u7167\u4ee5\u4e0b\u4f18\u5148\u7ea7\u89c4\u5219\u64cd\u4f5c\uff1a

\n\n
    \n\t
  • \u5f53\u67e5\u8be2\u5b8c\u5168\u5339\u914d\u5355\u8bcd\u5217\u8868\u4e2d\u7684\u67d0\u4e2a\u5355\u8bcd\uff08\u533a\u5206\u5927\u5c0f\u5199\uff09\u65f6\uff0c\u5e94\u8fd4\u56de\u76f8\u540c\u7684\u5355\u8bcd\u3002
  • \n\t
  • \u5f53\u67e5\u8be2\u5339\u914d\u5230\u5927\u5c0f\u5199\u95ee\u9898\u7684\u5355\u8bcd\u65f6\uff0c\u60a8\u5e94\u8be5\u8fd4\u56de\u5355\u8bcd\u5217\u8868\u4e2d\u7684\u7b2c\u4e00\u4e2a\u8fd9\u6837\u7684\u5339\u914d\u9879\u3002
  • \n\t
  • \u5f53\u67e5\u8be2\u5339\u914d\u5230\u5143\u97f3\u9519\u8bef\u7684\u5355\u8bcd\u65f6\uff0c\u60a8\u5e94\u8be5\u8fd4\u56de\u5355\u8bcd\u5217\u8868\u4e2d\u7684\u7b2c\u4e00\u4e2a\u8fd9\u6837\u7684\u5339\u914d\u9879\u3002
  • \n\t
  • \u5982\u679c\u8be5\u67e5\u8be2\u5728\u5355\u8bcd\u5217\u8868\u4e2d\u6ca1\u6709\u5339\u914d\u9879\uff0c\u5219\u5e94\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32\u3002
  • \n
\n\n

\u7ed9\u51fa\u4e00\u4e9b\u67e5\u8be2 queries\uff0c\u8fd4\u56de\u4e00\u4e2a\u5355\u8bcd\u5217\u8868 answer\uff0c\u5176\u4e2d answer[i] \u662f\u7531\u67e5\u8be2 query = queries[i] \u5f97\u5230\u7684\u6b63\u786e\u5355\u8bcd\u3002

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1awordlist = ["KiTe","kite","hare","Hare"], queries = ["kite","Kite","KiTe","Hare","HARE","Hear","hear","keti","keet","keto"]\n\u8f93\u51fa\uff1a["kite","KiTe","KiTe","Hare","hare","","","KiTe","","KiTe"]
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= wordlist.length <= 5000
  2. \n\t
  3. 1 <= queries.length <= 5000
  4. \n\t
  5. 1 <= wordlist[i].length <= 7
  6. \n\t
  7. 1 <= queries[i].length <= 7
  8. \n\t
  9. wordlist \u548c queries \u4e2d\u7684\u6240\u6709\u5b57\u7b26\u4e32\u4ec5\u7531\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\u3002
  10. \n
\n", "tags_en": ["Hash Table", "String"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector spellchecker(vector& wordlist, vector& queries) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String[] spellchecker(String[] wordlist, String[] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def spellchecker(self, wordlist, queries):\n \"\"\"\n :type wordlist: List[str]\n :type queries: List[str]\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def spellchecker(self, wordlist: List[str], queries: List[str]) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** spellchecker(char ** wordlist, int wordlistSize, char ** queries, int queriesSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string[] Spellchecker(string[] wordlist, string[] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} wordlist\n * @param {string[]} queries\n * @return {string[]}\n */\nvar spellchecker = function(wordlist, queries) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} wordlist\n# @param {String[]} queries\n# @return {String[]}\ndef spellchecker(wordlist, queries)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func spellchecker(_ wordlist: [String], _ queries: [String]) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func spellchecker(wordlist []string, queries []string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def spellchecker(wordlist: Array[String], queries: Array[String]): Array[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun spellchecker(wordlist: Array, queries: Array): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn spellchecker(wordlist: Vec, queries: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $wordlist\n * @param String[] $queries\n * @return String[]\n */\n function spellchecker($wordlist, $queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function spellchecker(wordlist: string[], queries: string[]): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (spellchecker wordlist queries)\n (-> (listof string?) (listof string?) (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0966](https://leetcode-cn.com/problems/vowel-spellchecker)", "[\u5143\u97f3\u62fc\u5199\u68c0\u67e5\u5668](/solution/0900-0999/0966.Vowel%20Spellchecker/README.md)", "`\u54c8\u5e0c\u8868`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0966](https://leetcode.com/problems/vowel-spellchecker)", "[Vowel Spellchecker](/solution/0900-0999/0966.Vowel%20Spellchecker/README_EN.md)", "`Hash Table`,`String`", "Medium", ""]}, {"question_id": "1005", "frontend_question_id": "0965", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/univalued-binary-tree", "url_en": "https://leetcode.com/problems/univalued-binary-tree", "relative_path_cn": "/solution/0900-0999/0965.Univalued%20Binary%20Tree/README.md", "relative_path_en": "/solution/0900-0999/0965.Univalued%20Binary%20Tree/README_EN.md", "title_cn": "\u5355\u503c\u4e8c\u53c9\u6811", "title_en": "Univalued Binary Tree", "question_title_slug": "univalued-binary-tree", "content_en": "

A binary tree is univalued if every node in the tree has the same value.

\r\n\r\n

Return true if and only if the given tree is univalued.

\r\n\r\n

 

\r\n\r\n

Example 1:

\r\n\"\"\r\n
\r\nInput: [1,1,1,1,1,null,1]\r\nOutput: true\r\n
\r\n\r\n
\r\n

Example 2:

\r\n\"\"\r\n
\r\nInput: [2,2,2,5,2]\r\nOutput: false\r\n
\r\n
\r\n\r\n

 

\r\n\r\n

Note:

\r\n\r\n
    \r\n\t
  1. The number of nodes in the given tree will be in the range [1, 100].
  2. \r\n\t
  3. Each node's value will be an integer in the range [0, 99].
  4. \r\n
\r\n", "content_cn": "

\u5982\u679c\u4e8c\u53c9\u6811\u6bcf\u4e2a\u8282\u70b9\u90fd\u5177\u6709\u76f8\u540c\u7684\u503c\uff0c\u90a3\u4e48\u8be5\u4e8c\u53c9\u6811\u5c31\u662f\u5355\u503c\u4e8c\u53c9\u6811\u3002

\n\n

\u53ea\u6709\u7ed9\u5b9a\u7684\u6811\u662f\u5355\u503c\u4e8c\u53c9\u6811\u65f6\uff0c\u624d\u8fd4\u56de true\uff1b\u5426\u5219\u8fd4\u56de false\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1a[1,1,1,1,1,null,1]\n\u8f93\u51fa\uff1atrue\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1a[2,2,2,5,2]\n\u8f93\u51fa\uff1afalse\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. \u7ed9\u5b9a\u6811\u7684\u8282\u70b9\u6570\u8303\u56f4\u662f [1, 100]\u3002
  2. \n\t
  3. \u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u90fd\u662f\u6574\u6570\uff0c\u8303\u56f4\u4e3a [0, 99] \u3002
  4. \n
\n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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 */\nclass Solution {\npublic:\n bool isUnivalTree(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode(int x) { val = x; }\n * }\n */\nclass Solution {\n public boolean isUnivalTree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution(object):\n def isUnivalTree(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: bool\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution:\n def isUnivalTree(self, root: TreeNode) -> bool:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nbool isUnivalTree(struct TreeNode* root){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int x) { val = x; }\n * }\n */\npublic class Solution {\n public bool IsUnivalTree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val) {\n * this.val = val;\n * this.left = this.right = null;\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {boolean}\n */\nvar isUnivalTree = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val)\n# @val = val\n# @left, @right = nil, nil\n# end\n# end\n\n# @param {TreeNode} root\n# @return {Boolean}\ndef is_unival_tree(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.left = nil\n * self.right = nil\n * }\n * }\n */\nclass Solution {\n func isUnivalTree(_ root: TreeNode?) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc isUnivalTree(root *TreeNode) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(var _value: Int) {\n * var value: Int = _value\n * var left: TreeNode = null\n * var right: TreeNode = null\n * }\n */\nobject Solution {\n def isUnivalTree(root: TreeNode): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun isUnivalTree(root: TreeNode?): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n// \n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn is_unival_tree(root: Option>>) -> bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($value) { $this->val = $value; }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Boolean\n */\n function isUnivalTree($root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction isUnivalTree(root: TreeNode | null): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (is-unival-tree root)\n (-> (or/c tree-node? #f) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0965](https://leetcode-cn.com/problems/univalued-binary-tree)", "[\u5355\u503c\u4e8c\u53c9\u6811](/solution/0900-0999/0965.Univalued%20Binary%20Tree/README.md)", "`\u6811`", "\u7b80\u5355", ""], "md_table_row_en": ["[0965](https://leetcode.com/problems/univalued-binary-tree)", "[Univalued Binary Tree](/solution/0900-0999/0965.Univalued%20Binary%20Tree/README_EN.md)", "`Tree`", "Easy", ""]}, {"question_id": "1004", "frontend_question_id": "0964", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/least-operators-to-express-number", "url_en": "https://leetcode.com/problems/least-operators-to-express-number", "relative_path_cn": "/solution/0900-0999/0964.Least%20Operators%20to%20Express%20Number/README.md", "relative_path_en": "/solution/0900-0999/0964.Least%20Operators%20to%20Express%20Number/README_EN.md", "title_cn": "\u8868\u793a\u6570\u5b57\u7684\u6700\u5c11\u8fd0\u7b97\u7b26", "title_en": "Least Operators to Express Number", "question_title_slug": "least-operators-to-express-number", "content_en": "

Given a single positive integer x, we will write an expression of the form x (op1) x (op2) x (op3) x ... where each operator op1, op2, etc. is either addition, subtraction, multiplication, or division (+, -, *, or /). For example, with x = 3, we might write 3 * 3 / 3 + 3 - 3 which is a value of 3.

\n\n

When writing such an expression, we adhere to the following conventions:

\n\n
    \n\t
  • The division operator (/) returns rational numbers.
  • \n\t
  • There are no parentheses placed anywhere.
  • \n\t
  • We use the usual order of operations: multiplication and division happen before addition and subtraction.
  • \n\t
  • It is not allowed to use the unary negation operator (-). For example, "x - x" is a valid expression as it only uses subtraction, but "-x + x" is not because it uses negation.
  • \n
\n\n

We would like to write an expression with the least number of operators such that the expression equals the given target. Return the least number of operators used.

\n\n

 

\n

Example 1:

\n\n
\nInput: x = 3, target = 19\nOutput: 5\nExplanation: 3 * 3 + 3 * 3 + 3 / 3.\nThe expression contains 5 operations.\n
\n\n

Example 2:

\n\n
\nInput: x = 5, target = 501\nOutput: 8\nExplanation: 5 * 5 * 5 * 5 - 5 * 5 * 5 + 5 / 5.\nThe expression contains 8 operations.\n
\n\n

Example 3:

\n\n
\nInput: x = 100, target = 100000000\nOutput: 3\nExplanation: 100 * 100 * 100 * 100.\nThe expression contains 3 operations.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= x <= 100
  • \n\t
  • 1 <= target <= 2 * 108
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u6b63\u6574\u6570 x\uff0c\u6211\u4eec\u5c06\u4f1a\u5199\u51fa\u4e00\u4e2a\u5f62\u5982 x (op1) x (op2) x (op3) x ... \u7684\u8868\u8fbe\u5f0f\uff0c\u5176\u4e2d\u6bcf\u4e2a\u8fd0\u7b97\u7b26 op1\uff0cop2\uff0c… \u53ef\u4ee5\u662f\u52a0\u3001\u51cf\u3001\u4e58\u3001\u9664\uff08+\uff0c-\uff0c*\uff0c\u6216\u662f /\uff09\u4e4b\u4e00\u3002\u4f8b\u5982\uff0c\u5bf9\u4e8e x = 3\uff0c\u6211\u4eec\u53ef\u4ee5\u5199\u51fa\u8868\u8fbe\u5f0f 3 * 3 / 3 + 3 - 3\uff0c\u8be5\u5f0f\u7684\u503c\u4e3a 3 \u3002

\n\n

\u5728\u5199\u8fd9\u6837\u7684\u8868\u8fbe\u5f0f\u65f6\uff0c\u6211\u4eec\u9700\u8981\u9075\u5b88\u4e0b\u9762\u7684\u60ef\u4f8b\uff1a

\n\n
    \n\t
  1. \u9664\u8fd0\u7b97\u7b26\uff08/\uff09\u8fd4\u56de\u6709\u7406\u6570\u3002
  2. \n\t
  3. \u4efb\u4f55\u5730\u65b9\u90fd\u6ca1\u6709\u62ec\u53f7\u3002
  4. \n\t
  5. \u6211\u4eec\u4f7f\u7528\u901a\u5e38\u7684\u64cd\u4f5c\u987a\u5e8f\uff1a\u4e58\u6cd5\u548c\u9664\u6cd5\u53d1\u751f\u5728\u52a0\u6cd5\u548c\u51cf\u6cd5\u4e4b\u524d\u3002
  6. \n\t
  7. \u4e0d\u5141\u8bb8\u4f7f\u7528\u4e00\u5143\u5426\u5b9a\u8fd0\u7b97\u7b26\uff08-\uff09\u3002\u4f8b\u5982\uff0c“x - x” \u662f\u4e00\u4e2a\u6709\u6548\u7684\u8868\u8fbe\u5f0f\uff0c\u56e0\u4e3a\u5b83\u53ea\u4f7f\u7528\u51cf\u6cd5\uff0c\u4f46\u662f “-x + x” \u4e0d\u662f\uff0c\u56e0\u4e3a\u5b83\u4f7f\u7528\u4e86\u5426\u5b9a\u8fd0\u7b97\u7b26\u3002 
  8. \n
\n\n

\u6211\u4eec\u5e0c\u671b\u7f16\u5199\u4e00\u4e2a\u80fd\u4f7f\u8868\u8fbe\u5f0f\u7b49\u4e8e\u7ed9\u5b9a\u7684\u76ee\u6807\u503c target \u4e14\u8fd0\u7b97\u7b26\u6700\u5c11\u7684\u8868\u8fbe\u5f0f\u3002\u8fd4\u56de\u6240\u7528\u8fd0\u7b97\u7b26\u7684\u6700\u5c11\u6570\u91cf\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1ax = 3, target = 19\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a3 * 3 + 3 * 3 + 3 / 3 \u3002\u8868\u8fbe\u5f0f\u5305\u542b 5 \u4e2a\u8fd0\u7b97\u7b26\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1ax = 5, target = 501\n\u8f93\u51fa\uff1a8\n\u89e3\u91ca\uff1a5 * 5 * 5 * 5 - 5 * 5 * 5 + 5 / 5 \u3002\u8868\u8fbe\u5f0f\u5305\u542b 8 \u4e2a\u8fd0\u7b97\u7b26\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1ax = 100, target = 100000000\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a100 * 100 * 100 * 100 \u3002\u8868\u8fbe\u5f0f\u5305\u542b 3 \u4e2a\u8fd0\u7b97\u7b26\u3002
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= x <= 100
  • \n\t
  • 1 <= target <= 2 * 10^8
  • \n
\n\n

 

\n", "tags_en": ["Math", "Dynamic Programming"], "tags_cn": ["\u6570\u5b66", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int leastOpsExpressTarget(int x, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int leastOpsExpressTarget(int x, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def leastOpsExpressTarget(self, x, target):\n \"\"\"\n :type x: int\n :type target: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def leastOpsExpressTarget(self, x: int, target: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint leastOpsExpressTarget(int x, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LeastOpsExpressTarget(int x, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} x\n * @param {number} target\n * @return {number}\n */\nvar leastOpsExpressTarget = function(x, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} x\n# @param {Integer} target\n# @return {Integer}\ndef least_ops_express_target(x, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func leastOpsExpressTarget(_ x: Int, _ target: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func leastOpsExpressTarget(x int, target int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def leastOpsExpressTarget(x: Int, target: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun leastOpsExpressTarget(x: Int, target: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn least_ops_express_target(x: i32, target: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $x\n * @param Integer $target\n * @return Integer\n */\n function leastOpsExpressTarget($x, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function leastOpsExpressTarget(x: number, target: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (least-ops-express-target x target)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0964](https://leetcode-cn.com/problems/least-operators-to-express-number)", "[\u8868\u793a\u6570\u5b57\u7684\u6700\u5c11\u8fd0\u7b97\u7b26](/solution/0900-0999/0964.Least%20Operators%20to%20Express%20Number/README.md)", "`\u6570\u5b66`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0964](https://leetcode.com/problems/least-operators-to-express-number)", "[Least Operators to Express Number](/solution/0900-0999/0964.Least%20Operators%20to%20Express%20Number/README_EN.md)", "`Math`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "1003", "frontend_question_id": "0963", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-area-rectangle-ii", "url_en": "https://leetcode.com/problems/minimum-area-rectangle-ii", "relative_path_cn": "/solution/0900-0999/0963.Minimum%20Area%20Rectangle%20II/README.md", "relative_path_en": "/solution/0900-0999/0963.Minimum%20Area%20Rectangle%20II/README_EN.md", "title_cn": "\u6700\u5c0f\u9762\u79ef\u77e9\u5f62 II", "title_en": "Minimum Area Rectangle II", "question_title_slug": "minimum-area-rectangle-ii", "content_en": "

Given a set of points in the xy-plane, determine the minimum area of any rectangle formed from these points, with sides not necessarily parallel to the x and y axes.

\r\n\r\n

If there isn't any rectangle, return 0.

\r\n\r\n

 

\r\n\r\n

Example 1:

\r\n\r\n

\"\"

\r\n\r\n
\r\nInput: [[1,2],[2,1],[1,0],[0,1]]\r\nOutput: 2.00000\r\nExplanation: The minimum area rectangle occurs at [1,2],[2,1],[1,0],[0,1], with an area of 2.\r\n
\r\n\r\n
\r\n

Example 2:

\r\n\r\n

\"\"

\r\n\r\n
\r\nInput: [[0,1],[2,1],[1,1],[1,0],[2,0]]\r\nOutput: 1.00000\r\nExplanation: The minimum area rectangle occurs at [1,0],[1,1],[2,1],[2,0], with an area of 1.\r\n
\r\n\r\n
\r\n

Example 3:

\r\n\r\n

\"\"

\r\n\r\n
\r\nInput: [[0,3],[1,2],[3,1],[1,3],[2,1]]\r\nOutput: 0\r\nExplanation: There is no possible rectangle to form from these points.\r\n
\r\n\r\n
\r\n

Example 4:

\r\n\r\n

\"\"

\r\n\r\n
\r\nInput: [[3,1],[1,1],[0,1],[2,1],[3,3],[3,2],[0,2],[2,3]]\r\nOutput: 2.00000\r\nExplanation: The minimum area rectangle occurs at [2,1],[2,3],[3,3],[3,1], with an area of 2.\r\n
\r\n
\r\n\r\n

 

\r\n
\r\n
\r\n\r\n

Note:

\r\n\r\n
    \r\n\t
  1. 1 <= points.length <= 50
  2. \r\n\t
  3. 0 <= points[i][0] <= 40000
  4. \r\n\t
  5. 0 <= points[i][1] <= 40000
  6. \r\n\t
  7. All points are distinct.
  8. \r\n\t
  9. Answers within 10^-5 of the actual value will be accepted as correct.
  10. \r\n
\r\n", "content_cn": "

\u7ed9\u5b9a\u5728 xy \u5e73\u9762\u4e0a\u7684\u4e00\u7ec4\u70b9\uff0c\u786e\u5b9a\u7531\u8fd9\u4e9b\u70b9\u7ec4\u6210\u7684\u4efb\u4f55\u77e9\u5f62\u7684\u6700\u5c0f\u9762\u79ef\uff0c\u5176\u4e2d\u77e9\u5f62\u7684\u8fb9\u4e0d\u4e00\u5b9a\u5e73\u884c\u4e8e x \u8f74\u548c y \u8f74\u3002

\n\n

\u5982\u679c\u6ca1\u6709\u4efb\u4f55\u77e9\u5f62\uff0c\u5c31\u8fd4\u56de 0\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1a[[1,2],[2,1],[1,0],[0,1]]\n\u8f93\u51fa\uff1a2.00000\n\u89e3\u91ca\uff1a\u6700\u5c0f\u9762\u79ef\u7684\u77e9\u5f62\u51fa\u73b0\u5728 [1,2],[2,1],[1,0],[0,1] \u5904\uff0c\u9762\u79ef\u4e3a 2\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1a[[0,1],[2,1],[1,1],[1,0],[2,0]]\n\u8f93\u51fa\uff1a1.00000\n\u89e3\u91ca\uff1a\u6700\u5c0f\u9762\u79ef\u7684\u77e9\u5f62\u51fa\u73b0\u5728 [1,0],[1,1],[2,1],[2,0] \u5904\uff0c\u9762\u79ef\u4e3a 1\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1a[[0,3],[1,2],[3,1],[1,3],[2,1]]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6ca1\u6cd5\u4ece\u8fd9\u4e9b\u70b9\u4e2d\u7ec4\u6210\u4efb\u4f55\u77e9\u5f62\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1a[[3,1],[1,1],[0,1],[2,1],[3,3],[3,2],[0,2],[2,3]]\n\u8f93\u51fa\uff1a2.00000\n\u89e3\u91ca\uff1a\u6700\u5c0f\u9762\u79ef\u7684\u77e9\u5f62\u51fa\u73b0\u5728 [2,1],[2,3],[3,3],[3,1] \u5904\uff0c\u9762\u79ef\u4e3a 2\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= points.length <= 50
  2. \n\t
  3. 0 <= points[i][0] <= 40000
  4. \n\t
  5. 0 <= points[i][1] <= 40000
  6. \n\t
  7. \u6240\u6709\u7684\u70b9\u90fd\u662f\u4e0d\u540c\u7684\u3002
  8. \n\t
  9. \u4e0e\u771f\u5b9e\u503c\u8bef\u5dee\u4e0d\u8d85\u8fc7 10^-5 \u7684\u7b54\u6848\u5c06\u89c6\u4e3a\u6b63\u786e\u7ed3\u679c\u3002
  10. \n
\n", "tags_en": ["Geometry", "Math"], "tags_cn": ["\u51e0\u4f55", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n double minAreaFreeRect(vector>& points) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double minAreaFreeRect(int[][] points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minAreaFreeRect(self, points):\n \"\"\"\n :type points: List[List[int]]\n :rtype: float\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minAreaFreeRect(self, points: List[List[int]]) -> float:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\ndouble minAreaFreeRect(int** points, int pointsSize, int* pointsColSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double MinAreaFreeRect(int[][] points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} points\n * @return {number}\n */\nvar minAreaFreeRect = function(points) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} points\n# @return {Float}\ndef min_area_free_rect(points)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minAreaFreeRect(_ points: [[Int]]) -> Double {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minAreaFreeRect(points [][]int) float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minAreaFreeRect(points: Array[Array[Int]]): Double = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minAreaFreeRect(points: Array): Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_area_free_rect(points: Vec>) -> f64 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $points\n * @return Float\n */\n function minAreaFreeRect($points) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minAreaFreeRect(points: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-area-free-rect points)\n (-> (listof (listof exact-integer?)) flonum?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0963](https://leetcode-cn.com/problems/minimum-area-rectangle-ii)", "[\u6700\u5c0f\u9762\u79ef\u77e9\u5f62 II](/solution/0900-0999/0963.Minimum%20Area%20Rectangle%20II/README.md)", "`\u51e0\u4f55`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0963](https://leetcode.com/problems/minimum-area-rectangle-ii)", "[Minimum Area Rectangle II](/solution/0900-0999/0963.Minimum%20Area%20Rectangle%20II/README_EN.md)", "`Geometry`,`Math`", "Medium", ""]}, {"question_id": "1002", "frontend_question_id": "0962", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-width-ramp", "url_en": "https://leetcode.com/problems/maximum-width-ramp", "relative_path_cn": "/solution/0900-0999/0962.Maximum%20Width%20Ramp/README.md", "relative_path_en": "/solution/0900-0999/0962.Maximum%20Width%20Ramp/README_EN.md", "title_cn": "\u6700\u5927\u5bbd\u5ea6\u5761", "title_en": "Maximum Width Ramp", "question_title_slug": "maximum-width-ramp", "content_en": "

Given an array nums of integers, a ramp is a tuple (i, j) for which i < j and nums[i] <= nums[j].  The width of such a ramp is j - i.

\n\n

Find the maximum width of a ramp in nums.  If one doesn't exist, return 0.

\n\n

 

\n\n

Example 1:

\n\n
\nInput: nums = [6,0,8,2,1,5]\nOutput: 4\nExplanation: \nThe maximum width ramp is achieved at (i, j) = (1, 5): nums[1] = 0 and nums[5] = 5.\n
\n\n
\n

Example 2:

\n\n
\nInput: nums = [9,8,1,0,1,9,4,0,4,1]\nOutput: 7\nExplanation: \nThe maximum width ramp is achieved at (i, j) = (2, 9): nums[2] = 1 and nums[9] = 1.\n
\n
\n\n
\n
\n

 

\n\n

Note:

\n\n
    \n\t
  1. 2 <= nums.length <= 50000
  2. \n\t
  3. 0 <= nums[i] <= 50000
  4. \n
\n
\n
\n\n
\n
 
\n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 A\uff0c\u5761\u662f\u5143\u7ec4 (i, j)\uff0c\u5176\u4e2d  i < j \u4e14 A[i] <= A[j]\u3002\u8fd9\u6837\u7684\u5761\u7684\u5bbd\u5ea6\u4e3a j - i\u3002

\n\n

\u627e\u51fa A \u4e2d\u7684\u5761\u7684\u6700\u5927\u5bbd\u5ea6\uff0c\u5982\u679c\u4e0d\u5b58\u5728\uff0c\u8fd4\u56de 0 \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a[6,0,8,2,1,5]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\n\u6700\u5927\u5bbd\u5ea6\u7684\u5761\u4e3a (i, j) = (1, 5): A[1] = 0 \u4e14 A[5] = 5.\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a[9,8,1,0,1,9,4,0,4,1]\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\n\u6700\u5927\u5bbd\u5ea6\u7684\u5761\u4e3a (i, j) = (2, 9): A[2] = 1 \u4e14 A[9] = 1.\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 2 <= A.length <= 50000
  2. \n\t
  3. 0 <= A[i] <= 50000
  4. \n
\n\n

 

\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxWidthRamp(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxWidthRamp(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxWidthRamp(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxWidthRamp(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxWidthRamp(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxWidthRamp(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar maxWidthRamp = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef max_width_ramp(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxWidthRamp(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxWidthRamp(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxWidthRamp(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxWidthRamp(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_width_ramp(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function maxWidthRamp($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxWidthRamp(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-width-ramp nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0962](https://leetcode-cn.com/problems/maximum-width-ramp)", "[\u6700\u5927\u5bbd\u5ea6\u5761](/solution/0900-0999/0962.Maximum%20Width%20Ramp/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0962](https://leetcode.com/problems/maximum-width-ramp)", "[Maximum Width Ramp](/solution/0900-0999/0962.Maximum%20Width%20Ramp/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "1001", "frontend_question_id": "0961", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/n-repeated-element-in-size-2n-array", "url_en": "https://leetcode.com/problems/n-repeated-element-in-size-2n-array", "relative_path_cn": "/solution/0900-0999/0961.N-Repeated%20Element%20in%20Size%202N%20Array/README.md", "relative_path_en": "/solution/0900-0999/0961.N-Repeated%20Element%20in%20Size%202N%20Array/README_EN.md", "title_cn": "\u91cd\u590d N \u6b21\u7684\u5143\u7d20", "title_en": "N-Repeated Element in Size 2N Array", "question_title_slug": "n-repeated-element-in-size-2n-array", "content_en": "

In a array nums of size 2 * n, there are n + 1 unique elements, and exactly one of these elements is repeated n times.

\n\n

Return the element repeated n times.

\n\n

 

\n\n
    \n
\n\n
\n

Example 1:

\n\n
\nInput: nums[1,2,3,3]\nOutput: 3\n
\n\n
\n

Example 2:

\n\n
\nInput: nums[2,1,2,5,3,2]\nOutput: 2\n
\n\n
\n

Example 3:

\n\n
\nInput: nums[5,1,5,2,5,3,5,4]\nOutput: 5\n
\n\n

 

\n\n

Note:

\n\n
    \n\t
  • 4 <= nums.length <= 10000
  • \n\t
  • 0 <= nums[i] < 10000
  • \n\t
  • nums.length is even
  • \n
\n
\n
\n
\n", "content_cn": "

\u5728\u5927\u5c0f\u4e3a 2N\u00a0\u7684\u6570\u7ec4 A\u00a0\u4e2d\u6709 N+1 \u4e2a\u4e0d\u540c\u7684\u5143\u7d20\uff0c\u5176\u4e2d\u6709\u4e00\u4e2a\u5143\u7d20\u91cd\u590d\u4e86 N \u6b21\u3002

\n\n

\u8fd4\u56de\u91cd\u590d\u4e86 N\u00a0\u6b21\u7684\u90a3\u4e2a\u5143\u7d20\u3002

\n\n

\u00a0

\n\n
    \n
\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1a[1,2,3,3]\n\u8f93\u51fa\uff1a3\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1a[2,1,2,5,3,2]\n\u8f93\u51fa\uff1a2\n
\n\n

\u793a\u4f8b\u00a03\uff1a

\n\n
\n\u8f93\u5165\uff1a[5,1,5,2,5,3,5,4]\n\u8f93\u51fa\uff1a5\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 4 <= A.length <= 10000
  • \n\t
  • 0 <= A[i] < 10000
  • \n\t
  • A.length\u00a0\u4e3a\u5076\u6570
  • \n
\n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int repeatedNTimes(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int repeatedNTimes(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def repeatedNTimes(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def repeatedNTimes(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint repeatedNTimes(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int RepeatedNTimes(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar repeatedNTimes = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef repeated_n_times(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func repeatedNTimes(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func repeatedNTimes(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def repeatedNTimes(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun repeatedNTimes(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn repeated_n_times(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function repeatedNTimes($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function repeatedNTimes(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (repeated-n-times nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0961](https://leetcode-cn.com/problems/n-repeated-element-in-size-2n-array)", "[\u91cd\u590d N \u6b21\u7684\u5143\u7d20](/solution/0900-0999/0961.N-Repeated%20Element%20in%20Size%202N%20Array/README.md)", "`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0961](https://leetcode.com/problems/n-repeated-element-in-size-2n-array)", "[N-Repeated Element in Size 2N Array](/solution/0900-0999/0961.N-Repeated%20Element%20in%20Size%202N%20Array/README_EN.md)", "`Hash Table`", "Easy", ""]}, {"question_id": "1000", "frontend_question_id": "0960", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/delete-columns-to-make-sorted-iii", "url_en": "https://leetcode.com/problems/delete-columns-to-make-sorted-iii", "relative_path_cn": "/solution/0900-0999/0960.Delete%20Columns%20to%20Make%20Sorted%20III/README.md", "relative_path_en": "/solution/0900-0999/0960.Delete%20Columns%20to%20Make%20Sorted%20III/README_EN.md", "title_cn": "\u5220\u5217\u9020\u5e8f III", "title_en": "Delete Columns to Make Sorted III", "question_title_slug": "delete-columns-to-make-sorted-iii", "content_en": "

You are given an array of n strings strs, all of the same length.

\n\n

We may choose any deletion indices, and we delete all the characters in those indices for each string.

\n\n

For example, if we have strs = ["abcdef","uvwxyz"] and deletion indices {0, 2, 3}, then the final array after deletions is ["bef", "vyz"].

\n\n

Suppose we chose a set of deletion indices answer such that after deletions, the final array has every string (row) in lexicographic order. (i.e., (strs[0][0] <= strs[0][1] <= ... <= strs[0][strs[0].length - 1]), and (strs[1][0] <= strs[1][1] <= ... <= strs[1][strs[1].length - 1]), and so on). Return the minimum possible value of answer.length.

\n\n

 

\n

Example 1:

\n\n
\nInput: strs = ["babca","bbazb"]\nOutput: 3\nExplanation: After deleting columns 0, 1, and 4, the final array is strs = ["bc", "az"].\nBoth these rows are individually in lexicographic order (ie. strs[0][0] <= strs[0][1] and strs[1][0] <= strs[1][1]).\nNote that strs[0] > strs[1] - the array strs is not necessarily in lexicographic order.
\n\n

Example 2:

\n\n
\nInput: strs = ["edcba"]\nOutput: 4\nExplanation: If we delete less than 4 columns, the only row will not be lexicographically sorted.\n
\n\n

Example 3:

\n\n
\nInput: strs = ["ghi","def","abc"]\nOutput: 0\nExplanation: All rows are already lexicographically sorted.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == strs.length
  • \n\t
  • 1 <= n <= 100
  • \n\t
  • 1 <= strs[i].length <= 100
  • \n\t
  • strs[i] consists of lowercase English letters.
  • \n
\n\n
    \n\t
  •  
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u7531 N \u4e2a\u5c0f\u5199\u5b57\u6bcd\u5b57\u7b26\u4e32\u7ec4\u6210\u7684\u6570\u7ec4 A\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5b57\u7b26\u4e32\u957f\u5ea6\u76f8\u7b49\u3002

\n\n

\u9009\u53d6\u4e00\u4e2a\u5220\u9664\u7d22\u5f15\u5e8f\u5217\uff0c\u5bf9\u4e8e A \u4e2d\u7684\u6bcf\u4e2a\u5b57\u7b26\u4e32\uff0c\u5220\u9664\u5bf9\u5e94\u6bcf\u4e2a\u7d22\u5f15\u5904\u7684\u5b57\u7b26\u3002

\n\n

\u6bd4\u5982\uff0c\u6709 A = ["babca","bbazb"]\uff0c\u5220\u9664\u7d22\u5f15\u5e8f\u5217 {0, 1, 4}\uff0c\u5220\u9664\u540e A \u4e3a["bc","az"]\u3002

\n\n

\u5047\u8bbe\uff0c\u6211\u4eec\u9009\u62e9\u4e86\u4e00\u7ec4\u5220\u9664\u7d22\u5f15 D\uff0c\u90a3\u4e48\u5728\u6267\u884c\u5220\u9664\u64cd\u4f5c\u4e4b\u540e\uff0c\u6700\u7ec8\u5f97\u5230\u7684\u6570\u7ec4\u7684\u884c\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u90fd\u662f\u6309\u5b57\u5178\u5e8f\u6392\u5217\u7684\u3002

\n\n

\u6e05\u695a\u8d77\u89c1\uff0cA[0] \u662f\u6309\u5b57\u5178\u5e8f\u6392\u5217\u7684\uff08\u5373\uff0cA[0][0] <= A[0][1] <= ... <= A[0][A[0].length - 1]\uff09\uff0cA[1] \u662f\u6309\u5b57\u5178\u5e8f\u6392\u5217\u7684\uff08\u5373\uff0cA[1][0] <= A[1][1] <= ... <= A[1][A[1].length - 1]\uff09\uff0c\u4f9d\u6b64\u7c7b\u63a8\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de D.length \u7684\u6700\u5c0f\u53ef\u80fd\u503c\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a["babca","bbazb"]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\n\u5220\u9664 0\u30011 \u548c 4 \u8fd9\u4e09\u5217\u540e\uff0c\u6700\u7ec8\u5f97\u5230\u7684\u6570\u7ec4\u662f A = ["bc", "az"]\u3002\n\u8fd9\u4e24\u884c\u662f\u5206\u522b\u6309\u5b57\u5178\u5e8f\u6392\u5217\u7684\uff08\u5373\uff0cA[0][0] <= A[0][1] \u4e14 A[1][0] <= A[1][1]\uff09\u3002\n\u6ce8\u610f\uff0cA[0] > A[1] —— \u6570\u7ec4 A \u4e0d\u4e00\u5b9a\u662f\u6309\u5b57\u5178\u5e8f\u6392\u5217\u7684\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a["edcba"]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u5982\u679c\u5220\u9664\u7684\u5217\u5c11\u4e8e 4 \u5217\uff0c\u5219\u5269\u4e0b\u7684\u884c\u90fd\u4e0d\u4f1a\u6309\u5b57\u5178\u5e8f\u6392\u5217\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1a["ghi","def","abc"]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6240\u6709\u884c\u90fd\u5df2\u6309\u5b57\u5178\u5e8f\u6392\u5217\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= A.length <= 100
  2. \n\t
  3. 1 <= A[i].length <= 100
  4. \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minDeletionSize(vector& strs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minDeletionSize(String[] strs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minDeletionSize(self, strs):\n \"\"\"\n :type strs: List[str]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minDeletionSize(self, strs: List[str]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minDeletionSize(char ** strs, int strsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinDeletionSize(string[] strs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} strs\n * @return {number}\n */\nvar minDeletionSize = function(strs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} strs\n# @return {Integer}\ndef min_deletion_size(strs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minDeletionSize(_ strs: [String]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minDeletionSize(strs []string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minDeletionSize(strs: Array[String]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minDeletionSize(strs: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_deletion_size(strs: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $strs\n * @return Integer\n */\n function minDeletionSize($strs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minDeletionSize(strs: string[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-deletion-size strs)\n (-> (listof string?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0960](https://leetcode-cn.com/problems/delete-columns-to-make-sorted-iii)", "[\u5220\u5217\u9020\u5e8f III](/solution/0900-0999/0960.Delete%20Columns%20to%20Make%20Sorted%20III/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0960](https://leetcode.com/problems/delete-columns-to-make-sorted-iii)", "[Delete Columns to Make Sorted III](/solution/0900-0999/0960.Delete%20Columns%20to%20Make%20Sorted%20III/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "0999", "frontend_question_id": "0959", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/regions-cut-by-slashes", "url_en": "https://leetcode.com/problems/regions-cut-by-slashes", "relative_path_cn": "/solution/0900-0999/0959.Regions%20Cut%20By%20Slashes/README.md", "relative_path_en": "/solution/0900-0999/0959.Regions%20Cut%20By%20Slashes/README_EN.md", "title_cn": "\u7531\u659c\u6760\u5212\u5206\u533a\u57df", "title_en": "Regions Cut By Slashes", "question_title_slug": "regions-cut-by-slashes", "content_en": "

An n x n grid is composed of 1 x 1 squares where each 1 x 1 square consists of a '/', '\\', or blank space ' '. These characters divide the square into contiguous regions.

\n\n

Given the grid grid represented as a string array, return the number of regions.

\n\n

Note that backslash characters are escaped, so a '\\' is represented as '\\\\'.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: grid = [" /","/ "]\nOutput: 2\n
\n\n

Example 2:

\n\"\"\n
\nInput: grid = [" /","  "]\nOutput: 1\n
\n\n

Example 3:

\n\"\"\n
\nInput: grid = ["\\\\/","/\\\\"]\nOutput: 4\nExplanation: (Recall that because \\ characters are escaped, "\\\\/" refers to \\/, and "/\\\\" refers to /\\.)\n
\n\n

Example 4:

\n\"\"\n
\nInput: grid = ["/\\\\","\\\\/"]\nOutput: 5\nExplanation: (Recall that because \\ characters are escaped, "\\\\/" refers to \\/, and "/\\\\" refers to /\\.)\n
\n\n

Example 5:

\n\"\"\n
\nInput: grid = ["//","/ "]\nOutput: 3\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == grid.length
  • \n\t
  • n == grid[i].length
  • \n\t
  • 1 <= n <= 30
  • \n\t
  • grid[i][j] is either '/', '\\', or ' '.
  • \n
\n", "content_cn": "

\u5728\u7531 1 x 1 \u65b9\u683c\u7ec4\u6210\u7684 N x N \u7f51\u683c grid \u4e2d\uff0c\u6bcf\u4e2a 1 x 1 \u65b9\u5757\u7531 /\u3001\\ \u6216\u7a7a\u683c\u6784\u6210\u3002\u8fd9\u4e9b\u5b57\u7b26\u4f1a\u5c06\u65b9\u5757\u5212\u5206\u4e3a\u4e00\u4e9b\u5171\u8fb9\u7684\u533a\u57df\u3002

\n\n

\uff08\u8bf7\u6ce8\u610f\uff0c\u53cd\u659c\u6760\u5b57\u7b26\u662f\u8f6c\u4e49\u7684\uff0c\u56e0\u6b64 \\ \u7528 "\\\\" \u8868\u793a\u3002\uff09\u3002

\n\n

\u8fd4\u56de\u533a\u57df\u7684\u6570\u76ee\u3002

\n\n

 

\n\n
    \n
\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a\n[\n  " /",\n  "/ "\n]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a2x2 \u7f51\u683c\u5982\u4e0b\uff1a\n\"\"
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a\n[\n  " /",\n  "  "\n]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a2x2 \u7f51\u683c\u5982\u4e0b\uff1a\n\"\"
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1a\n[\n  "\\\\/",\n  "/\\\\"\n]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\uff08\u56de\u60f3\u4e00\u4e0b\uff0c\u56e0\u4e3a \\ \u5b57\u7b26\u662f\u8f6c\u4e49\u7684\uff0c\u6240\u4ee5 "\\\\/" \u8868\u793a \\/\uff0c\u800c "/\\\\" \u8868\u793a /\\\u3002\uff09\n2x2 \u7f51\u683c\u5982\u4e0b\uff1a\n\"\"
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1a\n[\n  "/\\\\",\n  "\\\\/"\n]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\uff08\u56de\u60f3\u4e00\u4e0b\uff0c\u56e0\u4e3a \\ \u5b57\u7b26\u662f\u8f6c\u4e49\u7684\uff0c\u6240\u4ee5 "/\\\\" \u8868\u793a /\\\uff0c\u800c "\\\\/" \u8868\u793a \\/\u3002\uff09\n2x2 \u7f51\u683c\u5982\u4e0b\uff1a\n\"\"
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1a\n[\n  "//",\n  "/ "\n]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a2x2 \u7f51\u683c\u5982\u4e0b\uff1a\n\"\"\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= grid.length == grid[0].length <= 30
  2. \n\t
  3. grid[i][j] \u662f '/'\u3001'\\'\u3001\u6216 ' '\u3002
  4. \n
\n", "tags_en": ["Depth-first Search", "Union Find", "Graph"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e76\u67e5\u96c6", "\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int regionsBySlashes(vector& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int regionsBySlashes(String[] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def regionsBySlashes(self, grid):\n \"\"\"\n :type grid: List[str]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def regionsBySlashes(self, grid: List[str]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint regionsBySlashes(char ** grid, int gridSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int RegionsBySlashes(string[] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} grid\n * @return {number}\n */\nvar regionsBySlashes = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} grid\n# @return {Integer}\ndef regions_by_slashes(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func regionsBySlashes(_ grid: [String]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func regionsBySlashes(grid []string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def regionsBySlashes(grid: Array[String]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun regionsBySlashes(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn regions_by_slashes(grid: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $grid\n * @return Integer\n */\n function regionsBySlashes($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function regionsBySlashes(grid: string[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (regions-by-slashes grid)\n (-> (listof string?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0959](https://leetcode-cn.com/problems/regions-cut-by-slashes)", "[\u7531\u659c\u6760\u5212\u5206\u533a\u57df](/solution/0900-0999/0959.Regions%20Cut%20By%20Slashes/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e76\u67e5\u96c6`,`\u56fe`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0959](https://leetcode.com/problems/regions-cut-by-slashes)", "[Regions Cut By Slashes](/solution/0900-0999/0959.Regions%20Cut%20By%20Slashes/README_EN.md)", "`Depth-first Search`,`Union Find`,`Graph`", "Medium", ""]}, {"question_id": "0998", "frontend_question_id": "0958", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/check-completeness-of-a-binary-tree", "url_en": "https://leetcode.com/problems/check-completeness-of-a-binary-tree", "relative_path_cn": "/solution/0900-0999/0958.Check%20Completeness%20of%20a%20Binary%20Tree/README.md", "relative_path_en": "/solution/0900-0999/0958.Check%20Completeness%20of%20a%20Binary%20Tree/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u7684\u5b8c\u5168\u6027\u68c0\u9a8c", "title_en": "Check Completeness of a Binary Tree", "question_title_slug": "check-completeness-of-a-binary-tree", "content_en": "

Given the root of a binary tree, determine if it is a complete binary tree.

\n\n

In a complete binary tree, every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as possible. It can have between 1 and 2h nodes inclusive at the last level h.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: root = [1,2,3,4,5,6]\nOutput: true\nExplanation: Every level before the last is full (ie. levels with node-values {1} and {2, 3}), and all nodes in the last level ({4, 5, 6}) are as far left as possible.\n
\n\n

Example 2:

\n\"\"\n
\nInput: root = [1,2,3,4,5,null,7]\nOutput: false\nExplanation: The node with value 7 isn't as far left as possible.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The number of nodes in the tree is in the range [1, 100].
  • \n\t
  • 1 <= Node.val <= 1000
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811\uff0c\u786e\u5b9a\u5b83\u662f\u5426\u662f\u4e00\u4e2a\u5b8c\u5168\u4e8c\u53c9\u6811\u3002

\n\n

\u767e\u5ea6\u767e\u79d1\u4e2d\u5bf9\u5b8c\u5168\u4e8c\u53c9\u6811\u7684\u5b9a\u4e49\u5982\u4e0b\uff1a

\n\n

\u82e5\u8bbe\u4e8c\u53c9\u6811\u7684\u6df1\u5ea6\u4e3a h\uff0c\u9664\u7b2c h \u5c42\u5916\uff0c\u5176\u5b83\u5404\u5c42 (1\uff5eh-1) \u7684\u7ed3\u70b9\u6570\u90fd\u8fbe\u5230\u6700\u5927\u4e2a\u6570\uff0c\u7b2c h \u5c42\u6240\u6709\u7684\u7ed3\u70b9\u90fd\u8fde\u7eed\u96c6\u4e2d\u5728\u6700\u5de6\u8fb9\uff0c\u8fd9\u5c31\u662f\u5b8c\u5168\u4e8c\u53c9\u6811\u3002\uff08\u6ce8\uff1a\u7b2c h \u5c42\u53ef\u80fd\u5305\u542b 1~ 2h \u4e2a\u8282\u70b9\u3002\uff09

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1a[1,2,3,4,5,6]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u6700\u540e\u4e00\u5c42\u524d\u7684\u6bcf\u4e00\u5c42\u90fd\u662f\u6ee1\u7684\uff08\u5373\uff0c\u7ed3\u70b9\u503c\u4e3a {1} \u548c {2,3} \u7684\u4e24\u5c42\uff09\uff0c\u4e14\u6700\u540e\u4e00\u5c42\u4e2d\u7684\u6240\u6709\u7ed3\u70b9\uff08{4,5,6}\uff09\u90fd\u5c3d\u53ef\u80fd\u5730\u5411\u5de6\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1a[1,2,3,4,5,null,7]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u503c\u4e3a 7 \u7684\u7ed3\u70b9\u6ca1\u6709\u5c3d\u53ef\u80fd\u9760\u5411\u5de6\u4fa7\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. \u6811\u4e2d\u5c06\u4f1a\u6709 1 \u5230 100 \u4e2a\u7ed3\u70b9\u3002
  2. \n
\n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n bool isCompleteTree(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public boolean isCompleteTree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def isCompleteTree(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def isCompleteTree(self, root: TreeNode) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nbool isCompleteTree(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public bool IsCompleteTree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {boolean}\n */\nvar isCompleteTree = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Boolean}\ndef is_complete_tree(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func isCompleteTree(_ root: TreeNode?) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc isCompleteTree(root *TreeNode) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def isCompleteTree(root: TreeNode): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun isCompleteTree(root: TreeNode?): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn is_complete_tree(root: Option>>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Boolean\n */\n function isCompleteTree($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction isCompleteTree(root: TreeNode | null): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (is-complete-tree root)\n (-> (or/c tree-node? #f) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0958](https://leetcode-cn.com/problems/check-completeness-of-a-binary-tree)", "[\u4e8c\u53c9\u6811\u7684\u5b8c\u5168\u6027\u68c0\u9a8c](/solution/0900-0999/0958.Check%20Completeness%20of%20a%20Binary%20Tree/README.md)", "`\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0958](https://leetcode.com/problems/check-completeness-of-a-binary-tree)", "[Check Completeness of a Binary Tree](/solution/0900-0999/0958.Check%20Completeness%20of%20a%20Binary%20Tree/README_EN.md)", "`Tree`", "Medium", ""]}, {"question_id": "0994", "frontend_question_id": "0957", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/prison-cells-after-n-days", "url_en": "https://leetcode.com/problems/prison-cells-after-n-days", "relative_path_cn": "/solution/0900-0999/0957.Prison%20Cells%20After%20N%20Days/README.md", "relative_path_en": "/solution/0900-0999/0957.Prison%20Cells%20After%20N%20Days/README_EN.md", "title_cn": "N \u5929\u540e\u7684\u7262\u623f", "title_en": "Prison Cells After N Days", "question_title_slug": "prison-cells-after-n-days", "content_en": "

There are 8 prison cells in a row and each cell is either occupied or vacant.

\n\n

Each day, whether the cell is occupied or vacant changes according to the following rules:

\n\n
    \n\t
  • If a cell has two adjacent neighbors that are both occupied or both vacant, then the cell becomes occupied.
  • \n\t
  • Otherwise, it becomes vacant.
  • \n
\n\n

Note that because the prison is a row, the first and the last cells in the row can't have two adjacent neighbors.

\n\n

You are given an integer array cells where cells[i] == 1 if the ith cell is occupied and cells[i] == 0 if the ith cell is vacant, and you are given an integer n.

\n\n

Return the state of the prison after n days (i.e., n such changes described above).

\n\n

 

\n

Example 1:

\n\n
\nInput: cells = [0,1,0,1,1,0,0,1], n = 7\nOutput: [0,0,1,1,0,0,0,0]\nExplanation: The following table summarizes the state of the prison on each day:\nDay 0: [0, 1, 0, 1, 1, 0, 0, 1]\nDay 1: [0, 1, 1, 0, 0, 0, 0, 0]\nDay 2: [0, 0, 0, 0, 1, 1, 1, 0]\nDay 3: [0, 1, 1, 0, 0, 1, 0, 0]\nDay 4: [0, 0, 0, 0, 0, 1, 0, 0]\nDay 5: [0, 1, 1, 1, 0, 1, 0, 0]\nDay 6: [0, 0, 1, 0, 1, 1, 0, 0]\nDay 7: [0, 0, 1, 1, 0, 0, 0, 0]\n
\n\n

Example 2:

\n\n
\nInput: cells = [1,0,0,1,0,0,1,0], n = 1000000000\nOutput: [0,0,1,1,1,1,1,0]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • cells.length == 8
  • \n\t
  • cells[i] is either 0 or 1.
  • \n\t
  • 1 <= n <= 109
  • \n
\n", "content_cn": "

8 \u95f4\u7262\u623f\u6392\u6210\u4e00\u6392\uff0c\u6bcf\u95f4\u7262\u623f\u4e0d\u662f\u6709\u4eba\u4f4f\u5c31\u662f\u7a7a\u7740\u3002

\n\n

\u6bcf\u5929\uff0c\u65e0\u8bba\u7262\u623f\u662f\u88ab\u5360\u7528\u6216\u7a7a\u7f6e\uff0c\u90fd\u4f1a\u6839\u636e\u4ee5\u4e0b\u89c4\u5219\u8fdb\u884c\u66f4\u6539\uff1a

\n\n
    \n\t
  • \u5982\u679c\u4e00\u95f4\u7262\u623f\u7684\u4e24\u4e2a\u76f8\u90bb\u7684\u623f\u95f4\u90fd\u88ab\u5360\u7528\u6216\u90fd\u662f\u7a7a\u7684\uff0c\u90a3\u4e48\u8be5\u7262\u623f\u5c31\u4f1a\u88ab\u5360\u7528\u3002
  • \n\t
  • \u5426\u5219\uff0c\u5b83\u5c31\u4f1a\u88ab\u7a7a\u7f6e\u3002
  • \n
\n\n

\uff08\u8bf7\u6ce8\u610f\uff0c\u7531\u4e8e\u76d1\u72f1\u4e2d\u7684\u7262\u623f\u6392\u6210\u4e00\u884c\uff0c\u6240\u4ee5\u884c\u4e2d\u7684\u7b2c\u4e00\u4e2a\u548c\u6700\u540e\u4e00\u4e2a\u623f\u95f4\u65e0\u6cd5\u6709\u4e24\u4e2a\u76f8\u90bb\u7684\u623f\u95f4\u3002\uff09

\n\n

\u6211\u4eec\u7528\u4ee5\u4e0b\u65b9\u5f0f\u63cf\u8ff0\u76d1\u72f1\u7684\u5f53\u524d\u72b6\u6001\uff1a\u5982\u679c\u7b2c i \u95f4\u7262\u623f\u88ab\u5360\u7528\uff0c\u5219 cell[i]==1\uff0c\u5426\u5219 cell[i]==0\u3002

\n\n

\u6839\u636e\u76d1\u72f1\u7684\u521d\u59cb\u72b6\u6001\uff0c\u5728 N \u5929\u540e\u8fd4\u56de\u76d1\u72f1\u7684\u72b6\u51b5\uff08\u548c\u4e0a\u8ff0 N \u79cd\u53d8\u5316\uff09\u3002

\n\n

 

\n\n
    \n
\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1acells = [0,1,0,1,1,0,0,1], N = 7\n\u8f93\u51fa\uff1a[0,0,1,1,0,0,0,0]\n\u89e3\u91ca\uff1a\n\u4e0b\u8868\u6982\u8ff0\u4e86\u76d1\u72f1\u6bcf\u5929\u7684\u72b6\u51b5\uff1a\nDay 0: [0, 1, 0, 1, 1, 0, 0, 1]\nDay 1: [0, 1, 1, 0, 0, 0, 0, 0]\nDay 2: [0, 0, 0, 0, 1, 1, 1, 0]\nDay 3: [0, 1, 1, 0, 0, 1, 0, 0]\nDay 4: [0, 0, 0, 0, 0, 1, 0, 0]\nDay 5: [0, 1, 1, 1, 0, 1, 0, 0]\nDay 6: [0, 0, 1, 0, 1, 1, 0, 0]\nDay 7: [0, 0, 1, 1, 0, 0, 0, 0]\n\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1acells = [1,0,0,1,0,0,1,0], N = 1000000000\n\u8f93\u51fa\uff1a[0,0,1,1,1,1,1,0]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. cells.length == 8
  2. \n\t
  3. cells[i] \u7684\u503c\u4e3a 0 \u6216 1 
  4. \n\t
  5. 1 <= N <= 10^9
  6. \n
\n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector prisonAfterNDays(vector& cells, int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] prisonAfterNDays(int[] cells, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def prisonAfterNDays(self, cells, n):\n \"\"\"\n :type cells: List[int]\n :type n: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def prisonAfterNDays(self, cells: List[int], n: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* prisonAfterNDays(int* cells, int cellsSize, int n, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] PrisonAfterNDays(int[] cells, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} cells\n * @param {number} n\n * @return {number[]}\n */\nvar prisonAfterNDays = function(cells, n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} cells\n# @param {Integer} n\n# @return {Integer[]}\ndef prison_after_n_days(cells, n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func prisonAfterNDays(_ cells: [Int], _ n: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func prisonAfterNDays(cells []int, n int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def prisonAfterNDays(cells: Array[Int], n: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun prisonAfterNDays(cells: IntArray, n: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn prison_after_n_days(cells: Vec, n: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $cells\n * @param Integer $n\n * @return Integer[]\n */\n function prisonAfterNDays($cells, $n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function prisonAfterNDays(cells: number[], n: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (prison-after-n-days cells n)\n (-> (listof exact-integer?) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0957](https://leetcode-cn.com/problems/prison-cells-after-n-days)", "[N \u5929\u540e\u7684\u7262\u623f](/solution/0900-0999/0957.Prison%20Cells%20After%20N%20Days/README.md)", "`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0957](https://leetcode.com/problems/prison-cells-after-n-days)", "[Prison Cells After N Days](/solution/0900-0999/0957.Prison%20Cells%20After%20N%20Days/README_EN.md)", "`Hash Table`", "Medium", ""]}, {"question_id": "0993", "frontend_question_id": "0956", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/tallest-billboard", "url_en": "https://leetcode.com/problems/tallest-billboard", "relative_path_cn": "/solution/0900-0999/0956.Tallest%20Billboard/README.md", "relative_path_en": "/solution/0900-0999/0956.Tallest%20Billboard/README_EN.md", "title_cn": "\u6700\u9ad8\u7684\u5e7f\u544a\u724c", "title_en": "Tallest Billboard", "question_title_slug": "tallest-billboard", "content_en": "

You are installing a billboard and want it to have the largest height. The billboard will have two steel supports, one on each side. Each steel support must be an equal height.

\n\n

You are given a collection of rods that can be welded together. For example, if you have rods of lengths 1, 2, and 3, you can weld them together to make a support of length 6.

\n\n

Return the largest possible height of your billboard installation. If you cannot support the billboard, return 0.

\n\n

 

\n

Example 1:

\n\n
\nInput: rods = [1,2,3,6]\nOutput: 6\nExplanation: We have two disjoint subsets {1,2,3} and {6}, which have the same sum = 6.\n
\n\n

Example 2:

\n\n
\nInput: rods = [1,2,3,4,5,6]\nOutput: 10\nExplanation: We have two disjoint subsets {2,3,5} and {4,6}, which have the same sum = 10.\n
\n\n

Example 3:

\n\n
\nInput: rods = [1,2]\nOutput: 0\nExplanation: The billboard cannot be supported, so we return 0.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= rods.length <= 20
  • \n\t
  • 1 <= rods[i] <= 1000
  • \n\t
  • sum(rods[i]) <= 5000
  • \n
\n", "content_cn": "

\u4f60\u6b63\u5728\u5b89\u88c5\u4e00\u4e2a\u5e7f\u544a\u724c\uff0c\u5e76\u5e0c\u671b\u5b83\u9ad8\u5ea6\u6700\u5927\u3002\u8fd9\u5757\u5e7f\u544a\u724c\u5c06\u6709\u4e24\u4e2a\u94a2\u5236\u652f\u67b6\uff0c\u4e24\u8fb9\u5404\u4e00\u4e2a\u3002\u6bcf\u4e2a\u94a2\u652f\u67b6\u7684\u9ad8\u5ea6\u5fc5\u987b\u76f8\u7b49\u3002

\n\n

\u4f60\u6709\u4e00\u5806\u53ef\u4ee5\u710a\u63a5\u5728\u4e00\u8d77\u7684\u94a2\u7b4b rods\u3002\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u5982\u679c\u94a2\u7b4b\u7684\u957f\u5ea6\u4e3a 1\u30012 \u548c 3\uff0c\u5219\u53ef\u4ee5\u5c06\u5b83\u4eec\u710a\u63a5\u5728\u4e00\u8d77\u5f62\u6210\u957f\u5ea6\u4e3a 6 \u7684\u652f\u67b6\u3002

\n\n

\u8fd4\u56de\u5e7f\u544a\u724c\u7684\u6700\u5927\u53ef\u80fd\u5b89\u88c5\u9ad8\u5ea6\u3002\u5982\u679c\u6ca1\u6cd5\u5b89\u88c5\u5e7f\u544a\u724c\uff0c\u8bf7\u8fd4\u56de 0\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a[1,2,3,6]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u6211\u4eec\u6709\u4e24\u4e2a\u4e0d\u76f8\u4ea4\u7684\u5b50\u96c6 {1,2,3} \u548c {6}\uff0c\u5b83\u4eec\u5177\u6709\u76f8\u540c\u7684\u548c sum = 6\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a[1,2,3,4,5,6]\n\u8f93\u51fa\uff1a10\n\u89e3\u91ca\uff1a\u6211\u4eec\u6709\u4e24\u4e2a\u4e0d\u76f8\u4ea4\u7684\u5b50\u96c6 {2,3,5} \u548c {4,6}\uff0c\u5b83\u4eec\u5177\u6709\u76f8\u540c\u7684\u548c sum = 10\u3002
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1a[1,2]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6ca1\u6cd5\u5b89\u88c5\u5e7f\u544a\u724c\uff0c\u6240\u4ee5\u8fd4\u56de 0\u3002
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 0 <= rods.length <= 20
  2. \n\t
  3. 1 <= rods[i] <= 1000
  4. \n\t
  5. \u94a2\u7b4b\u7684\u957f\u5ea6\u603b\u548c\u6700\u591a\u4e3a 5000
  6. \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int tallestBillboard(vector& rods) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int tallestBillboard(int[] rods) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def tallestBillboard(self, rods):\n \"\"\"\n :type rods: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def tallestBillboard(self, rods: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint tallestBillboard(int* rods, int rodsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int TallestBillboard(int[] rods) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} rods\n * @return {number}\n */\nvar tallestBillboard = function(rods) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} rods\n# @return {Integer}\ndef tallest_billboard(rods)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func tallestBillboard(_ rods: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func tallestBillboard(rods []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def tallestBillboard(rods: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun tallestBillboard(rods: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn tallest_billboard(rods: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $rods\n * @return Integer\n */\n function tallestBillboard($rods) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function tallestBillboard(rods: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (tallest-billboard rods)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0956](https://leetcode-cn.com/problems/tallest-billboard)", "[\u6700\u9ad8\u7684\u5e7f\u544a\u724c](/solution/0900-0999/0956.Tallest%20Billboard/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0956](https://leetcode.com/problems/tallest-billboard)", "[Tallest Billboard](/solution/0900-0999/0956.Tallest%20Billboard/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "0992", "frontend_question_id": "0955", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/delete-columns-to-make-sorted-ii", "url_en": "https://leetcode.com/problems/delete-columns-to-make-sorted-ii", "relative_path_cn": "/solution/0900-0999/0955.Delete%20Columns%20to%20Make%20Sorted%20II/README.md", "relative_path_en": "/solution/0900-0999/0955.Delete%20Columns%20to%20Make%20Sorted%20II/README_EN.md", "title_cn": "\u5220\u5217\u9020\u5e8f II", "title_en": "Delete Columns to Make Sorted II", "question_title_slug": "delete-columns-to-make-sorted-ii", "content_en": "

You are given an array of n strings strs, all of the same length.

\n\n

We may choose any deletion indices, and we delete all the characters in those indices for each string.

\n\n

For example, if we have strs = ["abcdef","uvwxyz"] and deletion indices {0, 2, 3}, then the final array after deletions is ["bef", "vyz"].

\n\n

Suppose we chose a set of deletion indices answer such that after deletions, the final array has its elements in lexicographic order (i.e., strs[0] <= strs[1] <= strs[2] <= ... <= strs[n - 1]). Return the minimum possible value of answer.length.

\n\n

 

\n

Example 1:

\n\n
\nInput: strs = ["ca","bb","ac"]\nOutput: 1\nExplanation: \nAfter deleting the first column, strs = ["a", "b", "c"].\nNow strs is in lexicographic order (ie. strs[0] <= strs[1] <= strs[2]).\nWe require at least 1 deletion since initially strs was not in lexicographic order, so the answer is 1.\n
\n\n

Example 2:

\n\n
\nInput: strs = ["xc","yb","za"]\nOutput: 0\nExplanation: \nstrs is already in lexicographic order, so we do not need to delete anything.\nNote that the rows of strs are not necessarily in lexicographic order:\ni.e., it is NOT necessarily true that (strs[0][0] <= strs[0][1] <= ...)\n
\n\n

Example 3:

\n\n
\nInput: strs = ["zyx","wvu","tsr"]\nOutput: 3\nExplanation: We have to delete every column.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == strs.length
  • \n\t
  • 1 <= n <= 100
  • \n\t
  • 1 <= strs[i].length <= 100
  • \n\t
  • strs[i] consists of lowercase English letters.
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u7531 n \u4e2a\u5b57\u7b26\u4e32\u7ec4\u6210\u7684\u6570\u7ec4 strs\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5b57\u7b26\u4e32\u957f\u5ea6\u76f8\u7b49\u3002

\n\n

\u9009\u53d6\u4e00\u4e2a\u5220\u9664\u7d22\u5f15\u5e8f\u5217\uff0c\u5bf9\u4e8e strs \u4e2d\u7684\u6bcf\u4e2a\u5b57\u7b26\u4e32\uff0c\u5220\u9664\u5bf9\u5e94\u6bcf\u4e2a\u7d22\u5f15\u5904\u7684\u5b57\u7b26\u3002

\n\n

\u6bd4\u5982\uff0c\u6709 strs = [\"abcdef\", \"uvwxyz\"]\uff0c\u5220\u9664\u7d22\u5f15\u5e8f\u5217\u00a0{0, 2, 3}\uff0c\u5220\u9664\u540e strs \u4e3a[\"bef\", \"vyz\"]\u3002

\n\n

\u5047\u8bbe\uff0c\u6211\u4eec\u9009\u62e9\u4e86\u4e00\u7ec4\u5220\u9664\u7d22\u5f15 answer\uff0c\u90a3\u4e48\u5728\u6267\u884c\u5220\u9664\u64cd\u4f5c\u4e4b\u540e\uff0c\u6700\u7ec8\u5f97\u5230\u7684\u6570\u7ec4\u7684\u5143\u7d20\u662f\u6309 \u5b57\u5178\u5e8f\uff08strs[0] <= strs[1] <= strs[2] ... <= strs[n - 1]\uff09\u6392\u5217\u7684\uff0c\u7136\u540e\u8bf7\u4f60\u8fd4\u56de answer.length\u00a0\u7684\u6700\u5c0f\u53ef\u80fd\u503c\u3002

\n\n

\u00a0

\n\n
    \n
\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1astrs = [\"ca\",\"bb\",\"ac\"]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a \n\u5220\u9664\u7b2c\u4e00\u5217\u540e\uff0cstrs = [\"a\", \"b\", \"c\"]\u3002\n\u73b0\u5728 strs \u4e2d\u5143\u7d20\u662f\u6309\u5b57\u5178\u6392\u5217\u7684 (\u5373\uff0cstrs[0] <= strs[1] <= strs[2])\u3002\n\u6211\u4eec\u81f3\u5c11\u9700\u8981\u8fdb\u884c 1 \u6b21\u5220\u9664\uff0c\u56e0\u4e3a\u6700\u521d strs \u4e0d\u662f\u6309\u5b57\u5178\u5e8f\u6392\u5217\u7684\uff0c\u6240\u4ee5\u7b54\u6848\u662f 1\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1astrs = [\"xc\",\"yb\",\"za\"]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\nstrs \u7684\u5217\u5df2\u7ecf\u662f\u6309\u5b57\u5178\u5e8f\u6392\u5217\u4e86\uff0c\u6240\u4ee5\u6211\u4eec\u4e0d\u9700\u8981\u5220\u9664\u4efb\u4f55\u4e1c\u897f\u3002\n\u6ce8\u610f strs \u7684\u884c\u4e0d\u9700\u8981\u6309\u5b57\u5178\u5e8f\u6392\u5217\u3002\n\u4e5f\u5c31\u662f\u8bf4\uff0cstrs[0][0] <= strs[0][1] <= ... \u4e0d\u4e00\u5b9a\u6210\u7acb\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1astrs = [\"zyx\",\"wvu\",\"tsr\"]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\n\u6211\u4eec\u5fc5\u987b\u5220\u6389\u6bcf\u4e00\u5217\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • n == strs.length
  • \n\t
  • 1 <= n <= 100
  • \n\t
  • 1 <= strs[i].length <= 100
  • \n\t
  • strs[i] \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
  • \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minDeletionSize(vector& strs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minDeletionSize(String[] strs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minDeletionSize(self, strs):\n \"\"\"\n :type strs: List[str]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minDeletionSize(self, strs: List[str]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minDeletionSize(char ** strs, int strsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinDeletionSize(string[] strs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} strs\n * @return {number}\n */\nvar minDeletionSize = function(strs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} strs\n# @return {Integer}\ndef min_deletion_size(strs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minDeletionSize(_ strs: [String]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minDeletionSize(strs []string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minDeletionSize(strs: Array[String]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minDeletionSize(strs: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_deletion_size(strs: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $strs\n * @return Integer\n */\n function minDeletionSize($strs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minDeletionSize(strs: string[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-deletion-size strs)\n (-> (listof string?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0955](https://leetcode-cn.com/problems/delete-columns-to-make-sorted-ii)", "[\u5220\u5217\u9020\u5e8f II](/solution/0900-0999/0955.Delete%20Columns%20to%20Make%20Sorted%20II/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0955](https://leetcode.com/problems/delete-columns-to-make-sorted-ii)", "[Delete Columns to Make Sorted II](/solution/0900-0999/0955.Delete%20Columns%20to%20Make%20Sorted%20II/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "0991", "frontend_question_id": "0954", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/array-of-doubled-pairs", "url_en": "https://leetcode.com/problems/array-of-doubled-pairs", "relative_path_cn": "/solution/0900-0999/0954.Array%20of%20Doubled%20Pairs/README.md", "relative_path_en": "/solution/0900-0999/0954.Array%20of%20Doubled%20Pairs/README_EN.md", "title_cn": "\u4e8c\u500d\u6570\u5bf9\u6570\u7ec4", "title_en": "Array of Doubled Pairs", "question_title_slug": "array-of-doubled-pairs", "content_en": "

Given an array of integers arr of even length, return true if and only if it is possible to reorder it such that arr[2 * i + 1] = 2 * arr[2 * i] for every 0 <= i < len(arr) / 2.

\n\n

 

\n

Example 1:

\n\n
\nInput: arr = [3,1,3,6]\nOutput: false\n
\n\n

Example 2:

\n\n
\nInput: arr = [2,1,2,6]\nOutput: false\n
\n\n

Example 3:

\n\n
\nInput: arr = [4,-2,2,-4]\nOutput: true\nExplanation: We can take two groups, [-2,-4] and [2,4] to form [-2,-4,2,4] or [2,4,-2,-4].\n
\n\n

Example 4:

\n\n
\nInput: arr = [1,2,4,16,8,4]\nOutput: false\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 0 <= arr.length <= 3 * 104
  • \n\t
  • arr.length is even.
  • \n\t
  • -105 <= arr[i] <= 105
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u957f\u5ea6\u4e3a\u5076\u6570\u7684\u6574\u6570\u6570\u7ec4 arr\uff0c\u53ea\u6709\u5bf9 arr \u8fdb\u884c\u91cd\u7ec4\u540e\u53ef\u4ee5\u6ee1\u8db3 \u201c\u5bf9\u4e8e\u6bcf\u4e2a 0 <=\u00a0i < len(arr) / 2\uff0c\u90fd\u6709 arr[2 * i + 1] = 2 * arr[2 * i]\u201d\u00a0\u65f6\uff0c\u8fd4\u56de true\uff1b\u5426\u5219\uff0c\u8fd4\u56de false\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [3,1,3,6]\n\u8f93\u51fa\uff1afalse\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [2,1,2,6]\n\u8f93\u51fa\uff1afalse\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [4,-2,2,-4]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u53ef\u4ee5\u7528 [-2,-4] \u548c [2,4] \u8fd9\u4e24\u7ec4\u7ec4\u6210 [-2,-4,2,4] \u6216\u662f [2,4,-2,-4]\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [1,2,4,16,8,4]\n\u8f93\u51fa\uff1afalse\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 0 <= arr.length <= 3 * 104
  • \n\t
  • arr.length \u662f\u5076\u6570
  • \n\t
  • -105 <= arr[i] <= 105
  • \n
\n", "tags_en": ["Array", "Hash Table"], "tags_cn": ["\u6570\u7ec4", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canReorderDoubled(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canReorderDoubled(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canReorderDoubled(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canReorderDoubled(self, arr: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canReorderDoubled(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanReorderDoubled(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {boolean}\n */\nvar canReorderDoubled = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Boolean}\ndef can_reorder_doubled(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canReorderDoubled(_ arr: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canReorderDoubled(arr []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canReorderDoubled(arr: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canReorderDoubled(arr: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_reorder_doubled(arr: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Boolean\n */\n function canReorderDoubled($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canReorderDoubled(arr: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-reorder-doubled arr)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0954](https://leetcode-cn.com/problems/array-of-doubled-pairs)", "[\u4e8c\u500d\u6570\u5bf9\u6570\u7ec4](/solution/0900-0999/0954.Array%20of%20Doubled%20Pairs/README.md)", "`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0954](https://leetcode.com/problems/array-of-doubled-pairs)", "[Array of Doubled Pairs](/solution/0900-0999/0954.Array%20of%20Doubled%20Pairs/README_EN.md)", "`Array`,`Hash Table`", "Medium", ""]}, {"question_id": "0990", "frontend_question_id": "0953", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/verifying-an-alien-dictionary", "url_en": "https://leetcode.com/problems/verifying-an-alien-dictionary", "relative_path_cn": "/solution/0900-0999/0953.Verifying%20an%20Alien%20Dictionary/README.md", "relative_path_en": "/solution/0900-0999/0953.Verifying%20an%20Alien%20Dictionary/README_EN.md", "title_cn": "\u9a8c\u8bc1\u5916\u661f\u8bed\u8bcd\u5178", "title_en": "Verifying an Alien Dictionary", "question_title_slug": "verifying-an-alien-dictionary", "content_en": "

In an alien language, surprisingly they also use english lowercase letters, but possibly in a different order. The order of the alphabet is some permutation of lowercase letters.

\n\n

Given a sequence of words written in the alien language, and the order of the alphabet, return true if and only if the given words are sorted lexicographicaly in this alien language.

\n

 

\n

Example 1:

\n\n
\nInput: words = ["hello","leetcode"], order = "hlabcdefgijkmnopqrstuvwxyz"\nOutput: true\nExplanation: As 'h' comes before 'l' in this language, then the sequence is sorted.\n
\n\n

Example 2:

\n\n
\nInput: words = ["word","world","row"], order = "worldabcefghijkmnpqstuvxyz"\nOutput: false\nExplanation: As 'd' comes after 'l' in this language, then words[0] > words[1], hence the sequence is unsorted.\n
\n\n

Example 3:

\n\n
\nInput: words = ["apple","app"], order = "abcdefghijklmnopqrstuvwxyz"\nOutput: false\nExplanation: The first three characters "app" match, and the second string is shorter (in size.) According to lexicographical rules "apple" > "app", because 'l' > '∅', where '∅' is defined as the blank character which is less than any other character (More info).\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= words.length <= 100
  • \n\t
  • 1 <= words[i].length <= 20
  • \n\t
  • order.length == 26
  • \n\t
  • All characters in words[i] and order are English lowercase letters.
  • \n
\n", "content_cn": "

\u67d0\u79cd\u5916\u661f\u8bed\u4e5f\u4f7f\u7528\u82f1\u6587\u5c0f\u5199\u5b57\u6bcd\uff0c\u4f46\u53ef\u80fd\u987a\u5e8f order \u4e0d\u540c\u3002\u5b57\u6bcd\u8868\u7684\u987a\u5e8f\uff08order\uff09\u662f\u4e00\u4e9b\u5c0f\u5199\u5b57\u6bcd\u7684\u6392\u5217\u3002

\n\n

\u7ed9\u5b9a\u4e00\u7ec4\u7528\u5916\u661f\u8bed\u4e66\u5199\u7684\u5355\u8bcd words\uff0c\u4ee5\u53ca\u5176\u5b57\u6bcd\u8868\u7684\u987a\u5e8f order\uff0c\u53ea\u6709\u5f53\u7ed9\u5b9a\u7684\u5355\u8bcd\u5728\u8fd9\u79cd\u5916\u661f\u8bed\u4e2d\u6309\u5b57\u5178\u5e8f\u6392\u5217\u65f6\uff0c\u8fd4\u56de true\uff1b\u5426\u5219\uff0c\u8fd4\u56de false\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1awords = ["hello","leetcode"], order = "hlabcdefgijkmnopqrstuvwxyz"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u5728\u8be5\u8bed\u8a00\u7684\u5b57\u6bcd\u8868\u4e2d\uff0c'h' \u4f4d\u4e8e 'l' \u4e4b\u524d\uff0c\u6240\u4ee5\u5355\u8bcd\u5e8f\u5217\u662f\u6309\u5b57\u5178\u5e8f\u6392\u5217\u7684\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1awords = ["word","world","row"], order = "worldabcefghijkmnpqstuvxyz"\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u5728\u8be5\u8bed\u8a00\u7684\u5b57\u6bcd\u8868\u4e2d\uff0c'd' \u4f4d\u4e8e 'l' \u4e4b\u540e\uff0c\u90a3\u4e48 words[0] > words[1]\uff0c\u56e0\u6b64\u5355\u8bcd\u5e8f\u5217\u4e0d\u662f\u6309\u5b57\u5178\u5e8f\u6392\u5217\u7684\u3002
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1awords = ["apple","app"], order = "abcdefghijklmnopqrstuvwxyz"\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u5f53\u524d\u4e09\u4e2a\u5b57\u7b26 "app" \u5339\u914d\u65f6\uff0c\u7b2c\u4e8c\u4e2a\u5b57\u7b26\u4e32\u76f8\u5bf9\u77ed\u4e00\u4e9b\uff0c\u7136\u540e\u6839\u636e\u8bcd\u5178\u7f16\u7e82\u89c4\u5219 "apple" > "app"\uff0c\u56e0\u4e3a 'l' > '∅'\uff0c\u5176\u4e2d '∅' \u662f\u7a7a\u767d\u5b57\u7b26\uff0c\u5b9a\u4e49\u4e3a\u6bd4\u4efb\u4f55\u5176\u4ed6\u5b57\u7b26\u90fd\u5c0f\uff08\u66f4\u591a\u4fe1\u606f\uff09\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= words.length <= 100
  2. \n\t
  3. 1 <= words[i].length <= 20
  4. \n\t
  5. order.length == 26
  6. \n\t
  7. \u5728 words[i] \u548c order \u4e2d\u7684\u6240\u6709\u5b57\u7b26\u90fd\u662f\u82f1\u6587\u5c0f\u5199\u5b57\u6bcd\u3002
  8. \n
\n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isAlienSorted(vector& words, string order) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isAlienSorted(String[] words, String order) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isAlienSorted(self, words, order):\n \"\"\"\n :type words: List[str]\n :type order: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isAlienSorted(self, words: List[str], order: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isAlienSorted(char ** words, int wordsSize, char * order){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsAlienSorted(string[] words, string order) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @param {string} order\n * @return {boolean}\n */\nvar isAlienSorted = function(words, order) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @param {String} order\n# @return {Boolean}\ndef is_alien_sorted(words, order)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isAlienSorted(_ words: [String], _ order: String) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isAlienSorted(words []string, order string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isAlienSorted(words: Array[String], order: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isAlienSorted(words: Array, order: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_alien_sorted(words: Vec, order: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @param String $order\n * @return Boolean\n */\n function isAlienSorted($words, $order) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isAlienSorted(words: string[], order: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-alien-sorted words order)\n (-> (listof string?) string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0953](https://leetcode-cn.com/problems/verifying-an-alien-dictionary)", "[\u9a8c\u8bc1\u5916\u661f\u8bed\u8bcd\u5178](/solution/0900-0999/0953.Verifying%20an%20Alien%20Dictionary/README.md)", "`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0953](https://leetcode.com/problems/verifying-an-alien-dictionary)", "[Verifying an Alien Dictionary](/solution/0900-0999/0953.Verifying%20an%20Alien%20Dictionary/README_EN.md)", "`Hash Table`", "Easy", ""]}, {"question_id": "0989", "frontend_question_id": "0952", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/largest-component-size-by-common-factor", "url_en": "https://leetcode.com/problems/largest-component-size-by-common-factor", "relative_path_cn": "/solution/0900-0999/0952.Largest%20Component%20Size%20by%20Common%20Factor/README.md", "relative_path_en": "/solution/0900-0999/0952.Largest%20Component%20Size%20by%20Common%20Factor/README_EN.md", "title_cn": "\u6309\u516c\u56e0\u6570\u8ba1\u7b97\u6700\u5927\u7ec4\u4ef6\u5927\u5c0f", "title_en": "Largest Component Size by Common Factor", "question_title_slug": "largest-component-size-by-common-factor", "content_en": "

Given a non-empty array of unique positive integers nums, consider the following graph:

\n\n
    \n\t
  • There are nums.length nodes, labelled nums[0] to nums[nums.length - 1];
  • \n\t
  • There is an edge between nums[i] and nums[j] if and only if nums[i] and nums[j] share a common factor greater than 1.
  • \n
\n\n

Return the size of the largest connected component in the graph.

\n\n

 

\n\n
    \n
\n\n
\n

Example 1:

\n\n
\nInput: nums = [4,6,15,35]\nOutput: 4\n\"\"\n
\n\n
\n

Example 2:

\n\n
\nInput: nums = [20,50,9,63]\nOutput: 2\n\"\"\n
\n\n
\n

Example 3:

\n\n
\nInput: nums = [2,3,6,7,4,12,21,39]\nOutput: 8\n\"\"\n
\n\n

Note:

\n\n
    \n\t
  1. 1 <= nums.length <= 20000
  2. \n\t
  3. 1 <= nums[i] <= 100000
  4. \n
\n
\n
\n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u7531\u4e0d\u540c\u6b63\u6574\u6570\u7684\u7ec4\u6210\u7684\u975e\u7a7a\u6570\u7ec4 A\uff0c\u8003\u8651\u4e0b\u9762\u7684\u56fe\uff1a

\n\n
    \n\t
  • \u6709\u00a0A.length\u00a0\u4e2a\u8282\u70b9\uff0c\u6309\u4ece\u00a0A[0]\u00a0\u5230\u00a0A[A.length - 1]\u00a0\u6807\u8bb0\uff1b
  • \n\t
  • \u53ea\u6709\u5f53 A[i] \u548c A[j] \u5171\u7528\u4e00\u4e2a\u5927\u4e8e 1 \u7684\u516c\u56e0\u6570\u65f6\uff0cA[i]\u00a0\u548c A[j] \u4e4b\u95f4\u624d\u6709\u4e00\u6761\u8fb9\u3002
  • \n
\n\n

\u8fd4\u56de\u56fe\u4e2d\u6700\u5927\u8fde\u901a\u7ec4\u4ef6\u7684\u5927\u5c0f\u3002

\n\n

\u00a0

\n\n
    \n
\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1a[4,6,15,35]\n\u8f93\u51fa\uff1a4\n\"\"\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1a[20,50,9,63]\n\u8f93\u51fa\uff1a2\n\"\"\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1a[2,3,6,7,4,12,21,39]\n\u8f93\u51fa\uff1a8\n\"\"\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= A.length <= 20000
  2. \n\t
  3. 1 <= A[i] <= 100000
  4. \n
\n", "tags_en": ["Union Find", "Math"], "tags_cn": ["\u5e76\u67e5\u96c6", "\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int largestComponentSize(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int largestComponentSize(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def largestComponentSize(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def largestComponentSize(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint largestComponentSize(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LargestComponentSize(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar largestComponentSize = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef largest_component_size(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func largestComponentSize(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func largestComponentSize(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def largestComponentSize(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun largestComponentSize(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn largest_component_size(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function largestComponentSize($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function largestComponentSize(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (largest-component-size nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0952](https://leetcode-cn.com/problems/largest-component-size-by-common-factor)", "[\u6309\u516c\u56e0\u6570\u8ba1\u7b97\u6700\u5927\u7ec4\u4ef6\u5927\u5c0f](/solution/0900-0999/0952.Largest%20Component%20Size%20by%20Common%20Factor/README.md)", "`\u5e76\u67e5\u96c6`,`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[0952](https://leetcode.com/problems/largest-component-size-by-common-factor)", "[Largest Component Size by Common Factor](/solution/0900-0999/0952.Largest%20Component%20Size%20by%20Common%20Factor/README_EN.md)", "`Union Find`,`Math`", "Hard", ""]}, {"question_id": "0988", "frontend_question_id": "0951", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/flip-equivalent-binary-trees", "url_en": "https://leetcode.com/problems/flip-equivalent-binary-trees", "relative_path_cn": "/solution/0900-0999/0951.Flip%20Equivalent%20Binary%20Trees/README.md", "relative_path_en": "/solution/0900-0999/0951.Flip%20Equivalent%20Binary%20Trees/README_EN.md", "title_cn": "\u7ffb\u8f6c\u7b49\u4ef7\u4e8c\u53c9\u6811", "title_en": "Flip Equivalent Binary Trees", "question_title_slug": "flip-equivalent-binary-trees", "content_en": "

For a binary tree T, we can define a flip operation as follows: choose any node, and swap the left and right child subtrees.

\n\n

A binary tree X is flip equivalent to a binary tree Y if and only if we can make X equal to Y after some number of flip operations.

\n\n

Given the roots of two binary trees root1 and root2, return true if the two trees are flip equivelent or false otherwise.

\n\n

 

\n

Example 1:

\n\"Flipped\n
\nInput: root1 = [1,2,3,4,5,6,null,null,null,7,8], root2 = [1,3,2,null,6,4,5,null,null,null,null,8,7]\nOutput: true\nExplanation: We flipped at nodes with values 1, 3, and 5.\n
\n\n

Example 2:

\n\n
\nInput: root1 = [], root2 = []\nOutput: true\n
\n\n

Example 3:

\n\n
\nInput: root1 = [], root2 = [1]\nOutput: false\n
\n\n

Example 4:

\n\n
\nInput: root1 = [0,null,1], root2 = []\nOutput: false\n
\n\n

Example 5:

\n\n
\nInput: root1 = [0,null,1], root2 = [0,1]\nOutput: true\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The number of nodes in each tree is in the range [0, 100].
  • \n\t
  • Each tree will have unique node values in the range [0, 99].
  • \n
\n", "content_cn": "

\u6211\u4eec\u53ef\u4ee5\u4e3a\u4e8c\u53c9\u6811 T \u5b9a\u4e49\u4e00\u4e2a\u7ffb\u8f6c\u64cd\u4f5c\uff0c\u5982\u4e0b\u6240\u793a\uff1a\u9009\u62e9\u4efb\u610f\u8282\u70b9\uff0c\u7136\u540e\u4ea4\u6362\u5b83\u7684\u5de6\u5b50\u6811\u548c\u53f3\u5b50\u6811\u3002

\n\n

\u53ea\u8981\u7ecf\u8fc7\u4e00\u5b9a\u6b21\u6570\u7684\u7ffb\u8f6c\u64cd\u4f5c\u540e\uff0c\u80fd\u4f7f X \u7b49\u4e8e Y\uff0c\u6211\u4eec\u5c31\u79f0\u4e8c\u53c9\u6811 X \u7ffb\u8f6c\u7b49\u4ef7\u4e8e\u4e8c\u53c9\u6811 Y\u3002

\n\n

\u7f16\u5199\u4e00\u4e2a\u5224\u65ad\u4e24\u4e2a\u4e8c\u53c9\u6811\u662f\u5426\u662f\u7ffb\u8f6c\u7b49\u4ef7\u7684\u51fd\u6570\u3002\u8fd9\u4e9b\u6811\u7531\u6839\u8282\u70b9 root1 \u548c root2 \u7ed9\u51fa\u3002

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1aroot1 = [1,2,3,4,5,6,null,null,null,7,8], root2 = [1,3,2,null,6,4,5,null,null,null,null,8,7]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u6211\u4eec\u7ffb\u8f6c\u503c\u4e3a 1\uff0c3 \u4ee5\u53ca 5 \u7684\u4e09\u4e2a\u8282\u70b9\u3002\n\"Flipped\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. \u6bcf\u68f5\u6811\u6700\u591a\u6709 100 \u4e2a\u8282\u70b9\u3002
  2. \n\t
  3. \u6bcf\u68f5\u6811\u4e2d\u7684\u6bcf\u4e2a\u503c\u90fd\u662f\u552f\u4e00\u7684\u3001\u5728 [0, 99] \u8303\u56f4\u5185\u7684\u6574\u6570\u3002
  4. \n
\n\n

 

\n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n bool flipEquiv(TreeNode* root1, TreeNode* root2) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public boolean flipEquiv(TreeNode root1, TreeNode root2) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def flipEquiv(self, root1, root2):\n \"\"\"\n :type root1: TreeNode\n :type root2: TreeNode\n :rtype: bool\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def flipEquiv(self, root1: TreeNode, root2: TreeNode) -> bool:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nbool flipEquiv(struct TreeNode* root1, struct TreeNode* root2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public bool FlipEquiv(TreeNode root1, TreeNode root2) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root1\n * @param {TreeNode} root2\n * @return {boolean}\n */\nvar flipEquiv = function(root1, root2) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root1\n# @param {TreeNode} root2\n# @return {Boolean}\ndef flip_equiv(root1, root2)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func flipEquiv(_ root1: TreeNode?, _ root2: TreeNode?) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc flipEquiv(root1 *TreeNode, root2 *TreeNode) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def flipEquiv(root1: TreeNode, root2: TreeNode): Boolean = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun flipEquiv(root1: TreeNode?, root2: TreeNode?): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn flip_equiv(root1: Option>>, root2: Option>>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root1\n * @param TreeNode $root2\n * @return Boolean\n */\n function flipEquiv($root1, $root2) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction flipEquiv(root1: TreeNode | null, root2: TreeNode | null): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (flip-equiv root1 root2)\n (-> (or/c tree-node? #f) (or/c tree-node? #f) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0951](https://leetcode-cn.com/problems/flip-equivalent-binary-trees)", "[\u7ffb\u8f6c\u7b49\u4ef7\u4e8c\u53c9\u6811](/solution/0900-0999/0951.Flip%20Equivalent%20Binary%20Trees/README.md)", "`\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0951](https://leetcode.com/problems/flip-equivalent-binary-trees)", "[Flip Equivalent Binary Trees](/solution/0900-0999/0951.Flip%20Equivalent%20Binary%20Trees/README_EN.md)", "`Tree`", "Medium", ""]}, {"question_id": "0987", "frontend_question_id": "0950", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reveal-cards-in-increasing-order", "url_en": "https://leetcode.com/problems/reveal-cards-in-increasing-order", "relative_path_cn": "/solution/0900-0999/0950.Reveal%20Cards%20In%20Increasing%20Order/README.md", "relative_path_en": "/solution/0900-0999/0950.Reveal%20Cards%20In%20Increasing%20Order/README_EN.md", "title_cn": "\u6309\u9012\u589e\u987a\u5e8f\u663e\u793a\u5361\u724c", "title_en": "Reveal Cards In Increasing Order", "question_title_slug": "reveal-cards-in-increasing-order", "content_en": "

In a deck of cards, every card has a unique integer.  You can order the deck in any order you want.

\n\n

Initially, all the cards start face down (unrevealed) in one deck.

\n\n

Now, you do the following steps repeatedly, until all cards are revealed:

\n\n
    \n\t
  1. Take the top card of the deck, reveal it, and take it out of the deck.
  2. \n\t
  3. If there are still cards in the deck, put the next top card of the deck at the bottom of the deck.
  4. \n\t
  5. If there are still unrevealed cards, go back to step 1.  Otherwise, stop.
  6. \n
\n\n

Return an ordering of the deck that would reveal the cards in increasing order.

\n\n

The first entry in the answer is considered to be the top of the deck.

\n\n

 

\n\n
\n

Example 1:

\n\n
\nInput: [17,13,11,2,3,5,7]\nOutput: [2,13,3,11,5,17,7]\nExplanation: \nWe get the deck in the order [17,13,11,2,3,5,7] (this order doesn't matter), and reorder it.\nAfter reordering, the deck starts as [2,13,3,11,5,17,7], where 2 is the top of the deck.\nWe reveal 2, and move 13 to the bottom.  The deck is now [3,11,5,17,7,13].\nWe reveal 3, and move 11 to the bottom.  The deck is now [5,17,7,13,11].\nWe reveal 5, and move 17 to the bottom.  The deck is now [7,13,11,17].\nWe reveal 7, and move 13 to the bottom.  The deck is now [11,17,13].\nWe reveal 11, and move 17 to the bottom.  The deck is now [13,17].\nWe reveal 13, and move 17 to the bottom.  The deck is now [17].\nWe reveal 17.\nSince all the cards revealed are in increasing order, the answer is correct.\n
\n\n
\n

 

\n\n

Note:

\n\n
    \n\t
  1. 1 <= deck.length <= 1000
  2. \n\t
  3. 1 <= deck[i] <= 10^6
  4. \n\t
  5. deck[i] != deck[j] for all i != j
  6. \n
\n
\n
\n", "content_cn": "

\u724c\u7ec4\u4e2d\u7684\u6bcf\u5f20\u5361\u724c\u90fd\u5bf9\u5e94\u6709\u4e00\u4e2a\u552f\u4e00\u7684\u6574\u6570\u3002\u4f60\u53ef\u4ee5\u6309\u4f60\u60f3\u8981\u7684\u987a\u5e8f\u5bf9\u8fd9\u5957\u5361\u7247\u8fdb\u884c\u6392\u5e8f\u3002

\n\n

\u6700\u521d\uff0c\u8fd9\u4e9b\u5361\u724c\u5728\u724c\u7ec4\u91cc\u662f\u6b63\u9762\u671d\u4e0b\u7684\uff08\u5373\uff0c\u672a\u663e\u793a\u72b6\u6001\uff09\u3002

\n\n

\u73b0\u5728\uff0c\u91cd\u590d\u6267\u884c\u4ee5\u4e0b\u6b65\u9aa4\uff0c\u76f4\u5230\u663e\u793a\u6240\u6709\u5361\u724c\u4e3a\u6b62\uff1a

\n\n
    \n\t
  1. \u4ece\u724c\u7ec4\u9876\u90e8\u62bd\u4e00\u5f20\u724c\uff0c\u663e\u793a\u5b83\uff0c\u7136\u540e\u5c06\u5176\u4ece\u724c\u7ec4\u4e2d\u79fb\u51fa\u3002
  2. \n\t
  3. \u5982\u679c\u724c\u7ec4\u4e2d\u4ecd\u6709\u724c\uff0c\u5219\u5c06\u4e0b\u4e00\u5f20\u5904\u4e8e\u724c\u7ec4\u9876\u90e8\u7684\u724c\u653e\u5728\u724c\u7ec4\u7684\u5e95\u90e8\u3002
  4. \n\t
  5. \u5982\u679c\u4ecd\u6709\u672a\u663e\u793a\u7684\u724c\uff0c\u90a3\u4e48\u8fd4\u56de\u6b65\u9aa4 1\u3002\u5426\u5219\uff0c\u505c\u6b62\u884c\u52a8\u3002
  6. \n
\n\n

\u8fd4\u56de\u80fd\u4ee5\u9012\u589e\u987a\u5e8f\u663e\u793a\u5361\u724c\u7684\u724c\u7ec4\u987a\u5e8f\u3002

\n\n

\u7b54\u6848\u4e2d\u7684\u7b2c\u4e00\u5f20\u724c\u88ab\u8ba4\u4e3a\u5904\u4e8e\u724c\u5806\u9876\u90e8\u3002

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1a[17,13,11,2,3,5,7]\n\u8f93\u51fa\uff1a[2,13,3,11,5,17,7]\n\u89e3\u91ca\uff1a\n\u6211\u4eec\u5f97\u5230\u7684\u724c\u7ec4\u987a\u5e8f\u4e3a [17,13,11,2,3,5,7]\uff08\u8fd9\u4e2a\u987a\u5e8f\u4e0d\u91cd\u8981\uff09\uff0c\u7136\u540e\u5c06\u5176\u91cd\u65b0\u6392\u5e8f\u3002\n\u91cd\u65b0\u6392\u5e8f\u540e\uff0c\u724c\u7ec4\u4ee5 [2,13,3,11,5,17,7] \u5f00\u59cb\uff0c\u5176\u4e2d 2 \u4f4d\u4e8e\u724c\u7ec4\u7684\u9876\u90e8\u3002\n\u6211\u4eec\u663e\u793a 2\uff0c\u7136\u540e\u5c06 13 \u79fb\u5230\u5e95\u90e8\u3002\u724c\u7ec4\u73b0\u5728\u662f [3,11,5,17,7,13]\u3002\n\u6211\u4eec\u663e\u793a 3\uff0c\u5e76\u5c06 11 \u79fb\u5230\u5e95\u90e8\u3002\u724c\u7ec4\u73b0\u5728\u662f [5,17,7,13,11]\u3002\n\u6211\u4eec\u663e\u793a 5\uff0c\u7136\u540e\u5c06 17 \u79fb\u5230\u5e95\u90e8\u3002\u724c\u7ec4\u73b0\u5728\u662f [7,13,11,17]\u3002\n\u6211\u4eec\u663e\u793a 7\uff0c\u5e76\u5c06 13 \u79fb\u5230\u5e95\u90e8\u3002\u724c\u7ec4\u73b0\u5728\u662f [11,17,13]\u3002\n\u6211\u4eec\u663e\u793a 11\uff0c\u7136\u540e\u5c06 17 \u79fb\u5230\u5e95\u90e8\u3002\u724c\u7ec4\u73b0\u5728\u662f [13,17]\u3002\n\u6211\u4eec\u5c55\u793a 13\uff0c\u7136\u540e\u5c06 17 \u79fb\u5230\u5e95\u90e8\u3002\u724c\u7ec4\u73b0\u5728\u662f [17]\u3002\n\u6211\u4eec\u663e\u793a 17\u3002\n\u7531\u4e8e\u6240\u6709\u5361\u7247\u90fd\u662f\u6309\u9012\u589e\u987a\u5e8f\u6392\u5217\u663e\u793a\u7684\uff0c\u6240\u4ee5\u7b54\u6848\u662f\u6b63\u786e\u7684\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= A.length <= 1000
  2. \n\t
  3. 1 <= A[i] <= 10^6
  4. \n\t
  5. \u5bf9\u4e8e\u6240\u6709\u7684 i != j\uff0cA[i] != A[j]
  6. \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector deckRevealedIncreasing(vector& deck) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] deckRevealedIncreasing(int[] deck) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def deckRevealedIncreasing(self, deck):\n \"\"\"\n :type deck: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def deckRevealedIncreasing(self, deck: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* deckRevealedIncreasing(int* deck, int deckSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] DeckRevealedIncreasing(int[] deck) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} deck\n * @return {number[]}\n */\nvar deckRevealedIncreasing = function(deck) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} deck\n# @return {Integer[]}\ndef deck_revealed_increasing(deck)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func deckRevealedIncreasing(_ deck: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func deckRevealedIncreasing(deck []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def deckRevealedIncreasing(deck: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun deckRevealedIncreasing(deck: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn deck_revealed_increasing(deck: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $deck\n * @return Integer[]\n */\n function deckRevealedIncreasing($deck) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function deckRevealedIncreasing(deck: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (deck-revealed-increasing deck)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0950](https://leetcode-cn.com/problems/reveal-cards-in-increasing-order)", "[\u6309\u9012\u589e\u987a\u5e8f\u663e\u793a\u5361\u724c](/solution/0900-0999/0950.Reveal%20Cards%20In%20Increasing%20Order/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0950](https://leetcode.com/problems/reveal-cards-in-increasing-order)", "[Reveal Cards In Increasing Order](/solution/0900-0999/0950.Reveal%20Cards%20In%20Increasing%20Order/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0986", "frontend_question_id": "0949", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/largest-time-for-given-digits", "url_en": "https://leetcode.com/problems/largest-time-for-given-digits", "relative_path_cn": "/solution/0900-0999/0949.Largest%20Time%20for%20Given%20Digits/README.md", "relative_path_en": "/solution/0900-0999/0949.Largest%20Time%20for%20Given%20Digits/README_EN.md", "title_cn": "\u7ed9\u5b9a\u6570\u5b57\u80fd\u7ec4\u6210\u7684\u6700\u5927\u65f6\u95f4", "title_en": "Largest Time for Given Digits", "question_title_slug": "largest-time-for-given-digits", "content_en": "

Given an array arr of 4 digits, find the latest 24-hour time that can be made using each digit exactly once.

\n\n

24-hour times are formatted as "HH:MM", where HH is between 00 and 23, and MM is between 00 and 59. The earliest 24-hour time is 00:00, and the latest is 23:59.

\n\n

Return the latest 24-hour time in "HH:MM" format.  If no valid time can be made, return an empty string.

\n\n

 

\n

Example 1:

\n\n
\nInput: arr = [1,2,3,4]\nOutput: "23:41"\nExplanation: The valid 24-hour times are "12:34", "12:43", "13:24", "13:42", "14:23", "14:32", "21:34", "21:43", "23:14", and "23:41". Of these times, "23:41" is the latest.\n
\n\n

Example 2:

\n\n
\nInput: arr = [5,5,5,5]\nOutput: ""\nExplanation: There are no valid 24-hour times as "55:55" is not valid.\n
\n\n

Example 3:

\n\n
\nInput: arr = [0,0,0,0]\nOutput: "00:00"\n
\n\n

Example 4:

\n\n
\nInput: arr = [0,0,1,0]\nOutput: "10:00"\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • arr.length == 4
  • \n\t
  • 0 <= arr[i] <= 9
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u7531 4 \u4f4d\u6570\u5b57\u7ec4\u6210\u7684\u6570\u7ec4\uff0c\u8fd4\u56de\u53ef\u4ee5\u8bbe\u7f6e\u7684\u7b26\u5408 24 \u5c0f\u65f6\u5236\u7684\u6700\u5927\u65f6\u95f4\u3002

\n\n

24 \u5c0f\u65f6\u683c\u5f0f\u4e3a \"HH:MM\" \uff0c\u5176\u4e2d HH \u5728 00 \u5230 23 \u4e4b\u95f4\uff0cMM \u5728 00 \u5230 59 \u4e4b\u95f4\u3002\u6700\u5c0f\u7684 24 \u5c0f\u65f6\u5236\u65f6\u95f4\u662f\u00a000:00 \uff0c\u800c\u6700\u5927\u7684\u662f\u00a023:59 \u3002\u4ece 00:00 \uff08\u5348\u591c\uff09\u5f00\u59cb\u7b97\u8d77\uff0c\u8fc7\u5f97\u8d8a\u4e45\uff0c\u65f6\u95f4\u8d8a\u5927\u3002

\n\n

\u4ee5\u957f\u5ea6\u4e3a 5 \u7684\u5b57\u7b26\u4e32\uff0c\u6309 \"HH:MM\" \u683c\u5f0f\u8fd4\u56de\u7b54\u6848\u3002\u5982\u679c\u4e0d\u80fd\u786e\u5b9a\u6709\u6548\u65f6\u95f4\uff0c\u5219\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [1,2,3,4]\n\u8f93\u51fa\uff1a\"23:41\"\n\u89e3\u91ca\uff1a\u6709\u6548\u7684 24 \u5c0f\u65f6\u5236\u65f6\u95f4\u662f \"12:34\"\uff0c\"12:43\"\uff0c\"13:24\"\uff0c\"13:42\"\uff0c\"14:23\"\uff0c\"14:32\"\uff0c\"21:34\"\uff0c\"21:43\"\uff0c\"23:14\" \u548c \"23:41\" \u3002\u8fd9\u4e9b\u65f6\u95f4\u4e2d\uff0c\"23:41\" \u662f\u6700\u5927\u65f6\u95f4\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [5,5,5,5]\n\u8f93\u51fa\uff1a\"\"\n\u89e3\u91ca\uff1a\u4e0d\u5b58\u5728\u6709\u6548\u7684 24 \u5c0f\u65f6\u5236\u65f6\u95f4\uff0c\u56e0\u4e3a \"55:55\" \u65e0\u6548\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [0,0,0,0]\n\u8f93\u51fa\uff1a\"00:00\"\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [0,0,1,0]\n\u8f93\u51fa\uff1a\"10:00\"\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • arr.length == 4
  • \n\t
  • 0 <= arr[i] <= 9
  • \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string largestTimeFromDigits(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String largestTimeFromDigits(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def largestTimeFromDigits(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def largestTimeFromDigits(self, arr: List[int]) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * largestTimeFromDigits(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string LargestTimeFromDigits(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {string}\n */\nvar largestTimeFromDigits = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {String}\ndef largest_time_from_digits(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func largestTimeFromDigits(_ arr: [Int]) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func largestTimeFromDigits(arr []int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def largestTimeFromDigits(arr: Array[Int]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun largestTimeFromDigits(arr: IntArray): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn largest_time_from_digits(arr: Vec) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return String\n */\n function largestTimeFromDigits($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function largestTimeFromDigits(arr: number[]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (largest-time-from-digits arr)\n (-> (listof exact-integer?) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0949](https://leetcode-cn.com/problems/largest-time-for-given-digits)", "[\u7ed9\u5b9a\u6570\u5b57\u80fd\u7ec4\u6210\u7684\u6700\u5927\u65f6\u95f4](/solution/0900-0999/0949.Largest%20Time%20for%20Given%20Digits/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0949](https://leetcode.com/problems/largest-time-for-given-digits)", "[Largest Time for Given Digits](/solution/0900-0999/0949.Largest%20Time%20for%20Given%20Digits/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "0985", "frontend_question_id": "0948", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/bag-of-tokens", "url_en": "https://leetcode.com/problems/bag-of-tokens", "relative_path_cn": "/solution/0900-0999/0948.Bag%20of%20Tokens/README.md", "relative_path_en": "/solution/0900-0999/0948.Bag%20of%20Tokens/README_EN.md", "title_cn": "\u4ee4\u724c\u653e\u7f6e", "title_en": "Bag of Tokens", "question_title_slug": "bag-of-tokens", "content_en": "

You have an initial power of power, an initial score of 0, and a bag of tokens where tokens[i] is the value of the ith token (0-indexed).

\n\n

Your goal is to maximize your total score by potentially playing each token in one of two ways:

\n\n
    \n\t
  • If your current power is at least tokens[i], you may play the ith token face up, losing tokens[i] power and gaining 1 score.
  • \n\t
  • If your current score is at least 1, you may play the ith token face down, gaining tokens[i] power and losing 1 score.
  • \n
\n\n

Each token may be played at most once and in any order. You do not have to play all the tokens.

\n\n

Return the largest possible score you can achieve after playing any number of tokens.

\n\n

 

\n

Example 1:

\n\n
\nInput: tokens = [100], power = 50\nOutput: 0\nExplanation: Playing the only token in the bag is impossible because you either have too little power or too little score.\n
\n\n

Example 2:

\n\n
\nInput: tokens = [100,200], power = 150\nOutput: 1\nExplanation: Play the 0th token (100) face up, your power becomes 50 and score becomes 1.\nThere is no need to play the 1st token since you cannot play it face up to add to your score.\n
\n\n

Example 3:

\n\n
\nInput: tokens = [100,200,300,400], power = 200\nOutput: 2\nExplanation: Play the tokens in this order to get a score of 2:\n1. Play the 0th token (100) face up, your power becomes 100 and score becomes 1.\n2. Play the 3rd token (400) face down, your power becomes 500 and score becomes 0.\n3. Play the 1st token (200) face up, your power becomes 300 and score becomes 1.\n4. Play the 2nd token (300) face up, your power becomes 0 and score becomes 2.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 0 <= tokens.length <= 1000
  • \n\t
  • 0 <= tokens[i], power < 104
  • \n
\n", "content_cn": "

\u4f60\u7684\u521d\u59cb \u80fd\u91cf \u4e3a\u00a0P\uff0c\u521d\u59cb \u5206\u6570 \u4e3a\u00a00\uff0c\u53ea\u6709\u4e00\u5305\u4ee4\u724c tokens \u3002\u5176\u4e2d tokens[i] \u662f\u7b2c i \u4e2a\u4ee4\u724c\u7684\u503c\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\u3002

\n\n

\u4ee4\u724c\u53ef\u80fd\u7684\u4e24\u79cd\u4f7f\u7528\u65b9\u6cd5\u5982\u4e0b\uff1a

\n\n
    \n\t
  • \u5982\u679c\u4f60\u81f3\u5c11\u6709\u00a0token[i]\u00a0\u70b9 \u80fd\u91cf \uff0c\u53ef\u4ee5\u5c06\u4ee4\u724c i \u7f6e\u4e3a\u6b63\u9762\u671d\u4e0a\uff0c\u5931\u53bb\u00a0token[i]\u00a0\u70b9 \u80fd\u91cf \uff0c\u5e76\u5f97\u5230\u00a01\u00a0\u5206 \u3002
  • \n\t
  • \u5982\u679c\u6211\u4eec\u81f3\u5c11\u6709\u00a01\u00a0\u5206 \uff0c\u53ef\u4ee5\u5c06\u4ee4\u724c i \u7f6e\u4e3a\u53cd\u9762\u671d\u4e0a\uff0c\u83b7\u5f97\u00a0token[i] \u70b9 \u80fd\u91cf \uff0c\u5e76\u5931\u53bb\u00a01\u00a0\u5206 \u3002
  • \n
\n\n

\u6bcf\u4e2a\u4ee4\u724c \u6700\u591a \u53ea\u80fd\u4f7f\u7528\u4e00\u6b21\uff0c\u4f7f\u7528 \u987a\u5e8f\u4e0d\u9650 \uff0c\u4e0d\u9700 \u4f7f\u7528\u6240\u6709\u4ee4\u724c\u3002

\n\n

\u5728\u4f7f\u7528\u4efb\u610f\u6570\u91cf\u7684\u4ee4\u724c\u540e\uff0c\u8fd4\u56de\u6211\u4eec\u53ef\u4ee5\u5f97\u5230\u7684\u6700\u5927 \u5206\u6570 \u3002

\n\n

\u00a0

\n\n
    \n
\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1atokens = [100], P = 50\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u65e0\u6cd5\u4f7f\u7528\u552f\u4e00\u7684\u4ee4\u724c\uff0c\u56e0\u4e3a\u80fd\u91cf\u548c\u5206\u6570\u90fd\u592a\u5c11\u4e86\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1atokens = [100,200], P = 150\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u4ee4\u724c 0 \u6b63\u9762\u671d\u4e0a\uff0c\u80fd\u91cf\u53d8\u4e3a 50\uff0c\u5206\u6570\u53d8\u4e3a 1 \u3002\u4e0d\u5fc5\u4f7f\u7528\u4ee4\u724c 1 \uff0c\u56e0\u4e3a\u4f60\u65e0\u6cd5\u4f7f\u7528\u5b83\u6765\u63d0\u9ad8\u5206\u6570\u3002
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1atokens = [100,200,300,400], P = 200\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6309\u4e0b\u9762\u987a\u5e8f\u4f7f\u7528\u4ee4\u724c\u53ef\u4ee5\u5f97\u5230 2 \u5206\uff1a\n1. \u4ee4\u724c 0 \u6b63\u9762\u671d\u4e0a\uff0c\u80fd\u91cf\u53d8\u4e3a 100 \uff0c\u5206\u6570\u53d8\u4e3a 1\n2. \u4ee4\u724c 3 \u6b63\u9762\u671d\u4e0b\uff0c\u80fd\u91cf\u53d8\u4e3a 500 \uff0c\u5206\u6570\u53d8\u4e3a 0\n3. \u4ee4\u724c 1 \u6b63\u9762\u671d\u4e0a\uff0c\u80fd\u91cf\u53d8\u4e3a 300 \uff0c\u5206\u6570\u53d8\u4e3a 1\n4. \u4ee4\u724c 2 \u6b63\u9762\u671d\u4e0a\uff0c\u80fd\u91cf\u53d8\u4e3a 0 \uff0c\u5206\u6570\u53d8\u4e3a 2
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 0 <= tokens.length <= 1000
  • \n\t
  • 0 <= tokens[i],\u00a0P < 104
  • \n
\n", "tags_en": ["Greedy", "Sort", "Two Pointers"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6392\u5e8f", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int bagOfTokensScore(vector& tokens, int power) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int bagOfTokensScore(int[] tokens, int power) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def bagOfTokensScore(self, tokens, power):\n \"\"\"\n :type tokens: List[int]\n :type power: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def bagOfTokensScore(self, tokens: List[int], power: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint bagOfTokensScore(int* tokens, int tokensSize, int power){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int BagOfTokensScore(int[] tokens, int power) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} tokens\n * @param {number} power\n * @return {number}\n */\nvar bagOfTokensScore = function(tokens, power) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} tokens\n# @param {Integer} power\n# @return {Integer}\ndef bag_of_tokens_score(tokens, power)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func bagOfTokensScore(_ tokens: [Int], _ power: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func bagOfTokensScore(tokens []int, power int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def bagOfTokensScore(tokens: Array[Int], power: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun bagOfTokensScore(tokens: IntArray, power: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn bag_of_tokens_score(tokens: Vec, power: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $tokens\n * @param Integer $power\n * @return Integer\n */\n function bagOfTokensScore($tokens, $power) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function bagOfTokensScore(tokens: number[], power: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (bag-of-tokens-score tokens power)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0948](https://leetcode-cn.com/problems/bag-of-tokens)", "[\u4ee4\u724c\u653e\u7f6e](/solution/0900-0999/0948.Bag%20of%20Tokens/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6392\u5e8f`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0948](https://leetcode.com/problems/bag-of-tokens)", "[Bag of Tokens](/solution/0900-0999/0948.Bag%20of%20Tokens/README_EN.md)", "`Greedy`,`Sort`,`Two Pointers`", "Medium", ""]}, {"question_id": "0984", "frontend_question_id": "0947", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/most-stones-removed-with-same-row-or-column", "url_en": "https://leetcode.com/problems/most-stones-removed-with-same-row-or-column", "relative_path_cn": "/solution/0900-0999/0947.Most%20Stones%20Removed%20with%20Same%20Row%20or%20Column/README.md", "relative_path_en": "/solution/0900-0999/0947.Most%20Stones%20Removed%20with%20Same%20Row%20or%20Column/README_EN.md", "title_cn": "\u79fb\u9664\u6700\u591a\u7684\u540c\u884c\u6216\u540c\u5217\u77f3\u5934", "title_en": "Most Stones Removed with Same Row or Column", "question_title_slug": "most-stones-removed-with-same-row-or-column", "content_en": "

On a 2D plane, we place n stones at some integer coordinate points. Each coordinate point may have at most one stone.

\n\n

A stone can be removed if it shares either the same row or the same column as another stone that has not been removed.

\n\n

Given an array stones of length n where stones[i] = [xi, yi] represents the location of the ith stone, return the largest possible number of stones that can be removed.

\n\n

 

\n

Example 1:

\n\n
\nInput: stones = [[0,0],[0,1],[1,0],[1,2],[2,1],[2,2]]\nOutput: 5\nExplanation: One way to remove 5 stones is as follows:\n1. Remove stone [2,2] because it shares the same row as [2,1].\n2. Remove stone [2,1] because it shares the same column as [0,1].\n3. Remove stone [1,2] because it shares the same row as [1,0].\n4. Remove stone [1,0] because it shares the same column as [0,0].\n5. Remove stone [0,1] because it shares the same row as [0,0].\nStone [0,0] cannot be removed since it does not share a row/column with another stone still on the plane.\n
\n\n

Example 2:

\n\n
\nInput: stones = [[0,0],[0,2],[1,1],[2,0],[2,2]]\nOutput: 3\nExplanation: One way to make 3 moves is as follows:\n1. Remove stone [2,2] because it shares the same row as [2,0].\n2. Remove stone [2,0] because it shares the same column as [0,0].\n3. Remove stone [0,2] because it shares the same row as [0,0].\nStones [0,0] and [1,1] cannot be removed since they do not share a row/column with another stone still on the plane.\n
\n\n

Example 3:

\n\n
\nInput: stones = [[0,0]]\nOutput: 0\nExplanation: [0,0] is the only stone on the plane, so you cannot remove it.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= stones.length <= 1000
  • \n\t
  • 0 <= xi, yi <= 104
  • \n\t
  • No two stones are at the same coordinate point.
  • \n
\n", "content_cn": "

n \u5757\u77f3\u5934\u653e\u7f6e\u5728\u4e8c\u7ef4\u5e73\u9762\u4e2d\u7684\u4e00\u4e9b\u6574\u6570\u5750\u6807\u70b9\u4e0a\u3002\u6bcf\u4e2a\u5750\u6807\u70b9\u4e0a\u6700\u591a\u53ea\u80fd\u6709\u4e00\u5757\u77f3\u5934\u3002

\n\n

\u5982\u679c\u4e00\u5757\u77f3\u5934\u7684 \u540c\u884c\u6216\u8005\u540c\u5217 \u4e0a\u6709\u5176\u4ed6\u77f3\u5934\u5b58\u5728\uff0c\u90a3\u4e48\u5c31\u53ef\u4ee5\u79fb\u9664\u8fd9\u5757\u77f3\u5934\u3002

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u6570\u7ec4 stones \uff0c\u5176\u4e2d stones[i] = [xi, yi] \u8868\u793a\u7b2c i \u5757\u77f3\u5934\u7684\u4f4d\u7f6e\uff0c\u8fd4\u56de \u53ef\u4ee5\u79fb\u9664\u7684\u77f3\u5b50 \u7684\u6700\u5927\u6570\u91cf\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1astones = [[0,0],[0,1],[1,0],[1,2],[2,1],[2,2]]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u4e00\u79cd\u79fb\u9664 5 \u5757\u77f3\u5934\u7684\u65b9\u6cd5\u5982\u4e0b\u6240\u793a\uff1a\n1. \u79fb\u9664\u77f3\u5934 [2,2] \uff0c\u56e0\u4e3a\u5b83\u548c [2,1] \u540c\u884c\u3002\n2. \u79fb\u9664\u77f3\u5934 [2,1] \uff0c\u56e0\u4e3a\u5b83\u548c [0,1] \u540c\u5217\u3002\n3. \u79fb\u9664\u77f3\u5934 [1,2] \uff0c\u56e0\u4e3a\u5b83\u548c [1,0] \u540c\u884c\u3002\n4. \u79fb\u9664\u77f3\u5934 [1,0] \uff0c\u56e0\u4e3a\u5b83\u548c [0,0] \u540c\u5217\u3002\n5. \u79fb\u9664\u77f3\u5934 [0,1] \uff0c\u56e0\u4e3a\u5b83\u548c [0,0] \u540c\u884c\u3002\n\u77f3\u5934 [0,0] \u4e0d\u80fd\u79fb\u9664\uff0c\u56e0\u4e3a\u5b83\u6ca1\u6709\u4e0e\u53e6\u4e00\u5757\u77f3\u5934\u540c\u884c/\u5217\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1astones = [[0,0],[0,2],[1,1],[2,0],[2,2]]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u4e00\u79cd\u79fb\u9664 3 \u5757\u77f3\u5934\u7684\u65b9\u6cd5\u5982\u4e0b\u6240\u793a\uff1a\n1. \u79fb\u9664\u77f3\u5934 [2,2] \uff0c\u56e0\u4e3a\u5b83\u548c [2,0] \u540c\u884c\u3002\n2. \u79fb\u9664\u77f3\u5934 [2,0] \uff0c\u56e0\u4e3a\u5b83\u548c [0,0] \u540c\u5217\u3002\n3. \u79fb\u9664\u77f3\u5934 [0,2] \uff0c\u56e0\u4e3a\u5b83\u548c [0,0] \u540c\u884c\u3002\n\u77f3\u5934 [0,0] \u548c [1,1] \u4e0d\u80fd\u79fb\u9664\uff0c\u56e0\u4e3a\u5b83\u4eec\u6ca1\u6709\u4e0e\u53e6\u4e00\u5757\u77f3\u5934\u540c\u884c/\u5217\u3002
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1astones = [[0,0]]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a[0,0] \u662f\u5e73\u9762\u4e0a\u552f\u4e00\u4e00\u5757\u77f3\u5934\uff0c\u6240\u4ee5\u4e0d\u53ef\u4ee5\u79fb\u9664\u5b83\u3002
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= stones.length <= 1000
  • \n\t
  • 0 <= xi, yi <= 104
  • \n\t
  • \u4e0d\u4f1a\u6709\u4e24\u5757\u77f3\u5934\u653e\u5728\u540c\u4e00\u4e2a\u5750\u6807\u70b9\u4e0a
  • \n
\n", "tags_en": ["Depth-first Search", "Union Find"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e76\u67e5\u96c6"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int removeStones(vector>& stones) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int removeStones(int[][] stones) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def removeStones(self, stones):\n \"\"\"\n :type stones: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def removeStones(self, stones: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint removeStones(int** stones, int stonesSize, int* stonesColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int RemoveStones(int[][] stones) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} stones\n * @return {number}\n */\nvar removeStones = function(stones) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} stones\n# @return {Integer}\ndef remove_stones(stones)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func removeStones(_ stones: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func removeStones(stones [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def removeStones(stones: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun removeStones(stones: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn remove_stones(stones: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $stones\n * @return Integer\n */\n function removeStones($stones) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function removeStones(stones: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (remove-stones stones)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0947](https://leetcode-cn.com/problems/most-stones-removed-with-same-row-or-column)", "[\u79fb\u9664\u6700\u591a\u7684\u540c\u884c\u6216\u540c\u5217\u77f3\u5934](/solution/0900-0999/0947.Most%20Stones%20Removed%20with%20Same%20Row%20or%20Column/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e76\u67e5\u96c6`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0947](https://leetcode.com/problems/most-stones-removed-with-same-row-or-column)", "[Most Stones Removed with Same Row or Column](/solution/0900-0999/0947.Most%20Stones%20Removed%20with%20Same%20Row%20or%20Column/README_EN.md)", "`Depth-first Search`,`Union Find`", "Medium", ""]}, {"question_id": "0983", "frontend_question_id": "0946", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/validate-stack-sequences", "url_en": "https://leetcode.com/problems/validate-stack-sequences", "relative_path_cn": "/solution/0900-0999/0946.Validate%20Stack%20Sequences/README.md", "relative_path_en": "/solution/0900-0999/0946.Validate%20Stack%20Sequences/README_EN.md", "title_cn": "\u9a8c\u8bc1\u6808\u5e8f\u5217", "title_en": "Validate Stack Sequences", "question_title_slug": "validate-stack-sequences", "content_en": "

Given two sequences pushed and popped with distinct values, return true if and only if this could have been the result of a sequence of push and pop operations on an initially empty stack.

\n\n

 

\n\n
\n

Example 1:

\n\n
\nInput: pushed = [1,2,3,4,5], popped = [4,5,3,2,1]\nOutput: true\nExplanation: We might do the following sequence:\npush(1), push(2), push(3), push(4), pop() -> 4,\npush(5), pop() -> 5, pop() -> 3, pop() -> 2, pop() -> 1\n
\n\n
\n

Example 2:

\n\n
\nInput: pushed = [1,2,3,4,5], popped = [4,3,5,1,2]\nOutput: false\nExplanation: 1 cannot be popped before 2.\n
\n
\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 0 <= pushed.length == popped.length <= 1000
  • \n\t
  • 0 <= pushed[i], popped[i] < 1000
  • \n\t
  • pushed is a permutation of popped.
  • \n\t
  • pushed and popped have distinct values.
  • \n
\n", "content_cn": "

\u7ed9\u5b9a pushed \u548c popped \u4e24\u4e2a\u5e8f\u5217\uff0c\u6bcf\u4e2a\u5e8f\u5217\u4e2d\u7684 \u503c\u90fd\u4e0d\u91cd\u590d\uff0c\u53ea\u6709\u5f53\u5b83\u4eec\u53ef\u80fd\u662f\u5728\u6700\u521d\u7a7a\u6808\u4e0a\u8fdb\u884c\u7684\u63a8\u5165 push \u548c\u5f39\u51fa pop \u64cd\u4f5c\u5e8f\u5217\u7684\u7ed3\u679c\u65f6\uff0c\u8fd4\u56de true\uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1apushed = [1,2,3,4,5], popped = [4,5,3,2,1]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u6211\u4eec\u53ef\u4ee5\u6309\u4ee5\u4e0b\u987a\u5e8f\u6267\u884c\uff1a\npush(1), push(2), push(3), push(4), pop() -> 4,\npush(5), pop() -> 5, pop() -> 3, pop() -> 2, pop() -> 1\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1apushed = [1,2,3,4,5], popped = [4,3,5,1,2]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a1 \u4e0d\u80fd\u5728 2 \u4e4b\u524d\u5f39\u51fa\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 0 <= pushed.length == popped.length <= 1000
  2. \n\t
  3. 0 <= pushed[i], popped[i] < 1000
  4. \n\t
  5. pushed \u662f popped \u7684\u6392\u5217\u3002
  6. \n
\n", "tags_en": ["Stack"], "tags_cn": ["\u6808"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool validateStackSequences(vector& pushed, vector& popped) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean validateStackSequences(int[] pushed, int[] popped) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def validateStackSequences(self, pushed, popped):\n \"\"\"\n :type pushed: List[int]\n :type popped: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def validateStackSequences(self, pushed: List[int], popped: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool validateStackSequences(int* pushed, int pushedSize, int* popped, int poppedSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool ValidateStackSequences(int[] pushed, int[] popped) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} pushed\n * @param {number[]} popped\n * @return {boolean}\n */\nvar validateStackSequences = function(pushed, popped) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} pushed\n# @param {Integer[]} popped\n# @return {Boolean}\ndef validate_stack_sequences(pushed, popped)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func validateStackSequences(_ pushed: [Int], _ popped: [Int]) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func validateStackSequences(pushed []int, popped []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def validateStackSequences(pushed: Array[Int], popped: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun validateStackSequences(pushed: IntArray, popped: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn validate_stack_sequences(pushed: Vec, popped: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $pushed\n * @param Integer[] $popped\n * @return Boolean\n */\n function validateStackSequences($pushed, $popped) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function validateStackSequences(pushed: number[], popped: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (validate-stack-sequences pushed popped)\n (-> (listof exact-integer?) (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0946](https://leetcode-cn.com/problems/validate-stack-sequences)", "[\u9a8c\u8bc1\u6808\u5e8f\u5217](/solution/0900-0999/0946.Validate%20Stack%20Sequences/README.md)", "`\u6808`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0946](https://leetcode.com/problems/validate-stack-sequences)", "[Validate Stack Sequences](/solution/0900-0999/0946.Validate%20Stack%20Sequences/README_EN.md)", "`Stack`", "Medium", ""]}, {"question_id": "0982", "frontend_question_id": "0945", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-increment-to-make-array-unique", "url_en": "https://leetcode.com/problems/minimum-increment-to-make-array-unique", "relative_path_cn": "/solution/0900-0999/0945.Minimum%20Increment%20to%20Make%20Array%20Unique/README.md", "relative_path_en": "/solution/0900-0999/0945.Minimum%20Increment%20to%20Make%20Array%20Unique/README_EN.md", "title_cn": "\u4f7f\u6570\u7ec4\u552f\u4e00\u7684\u6700\u5c0f\u589e\u91cf", "title_en": "Minimum Increment to Make Array Unique", "question_title_slug": "minimum-increment-to-make-array-unique", "content_en": "

Given an array of integers nums, a move consists of choosing any nums[i], and incrementing it by 1.

\n\n

Return the least number of moves to make every value in nums unique.

\n\n

 

\n\n

Example 1:

\n\n
\nInput: nums = [1,2,2]\nOutput: 1\nExplanation:  After 1 move, the array could be [1, 2, 3].\n
\n\n
\n

Example 2:

\n\n
\nInput: nums = [3,2,1,2,1,7]\nOutput: 6\nExplanation:  After 6 moves, the array could be [3, 4, 1, 2, 5, 7].\nIt can be shown with 5 or less moves that it is impossible for the array to have all unique values.\n
\n\n

 

\n
\n\n

Note:

\n\n
    \n\t
  1. 0 <= nums.length <= 40000
  2. \n\t
  3. 0 <= nums[i] < 40000
  4. \n
\n\n
\n
 
\n
\n", "content_cn": "

\u7ed9\u5b9a\u6574\u6570\u6570\u7ec4 A\uff0c\u6bcf\u6b21 move \u64cd\u4f5c\u5c06\u4f1a\u9009\u62e9\u4efb\u610f A[i]\uff0c\u5e76\u5c06\u5176\u9012\u589e 1\u3002

\n\n

\u8fd4\u56de\u4f7f A \u4e2d\u7684\u6bcf\u4e2a\u503c\u90fd\u662f\u552f\u4e00\u7684\u6700\u5c11\u64cd\u4f5c\u6b21\u6570\u3002

\n\n

\u793a\u4f8b 1:

\n\n
\u8f93\u5165\uff1a[1,2,2]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u7ecf\u8fc7\u4e00\u6b21 move \u64cd\u4f5c\uff0c\u6570\u7ec4\u5c06\u53d8\u4e3a [1, 2, 3]\u3002
\n\n

\u793a\u4f8b 2:

\n\n
\u8f93\u5165\uff1a[3,2,1,2,1,7]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u7ecf\u8fc7 6 \u6b21 move \u64cd\u4f5c\uff0c\u6570\u7ec4\u5c06\u53d8\u4e3a [3, 4, 1, 2, 5, 7]\u3002\n\u53ef\u4ee5\u770b\u51fa 5 \u6b21\u6216 5 \u6b21\u4ee5\u4e0b\u7684 move \u64cd\u4f5c\u662f\u4e0d\u80fd\u8ba9\u6570\u7ec4\u7684\u6bcf\u4e2a\u503c\u552f\u4e00\u7684\u3002\n
\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 0 <= A.length <= 40000
  2. \n\t
  3. 0 <= A[i] < 40000
  4. \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minIncrementForUnique(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minIncrementForUnique(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minIncrementForUnique(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minIncrementForUnique(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minIncrementForUnique(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinIncrementForUnique(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar minIncrementForUnique = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef min_increment_for_unique(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minIncrementForUnique(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minIncrementForUnique(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minIncrementForUnique(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minIncrementForUnique(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_increment_for_unique(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function minIncrementForUnique($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minIncrementForUnique(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-increment-for-unique nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0945](https://leetcode-cn.com/problems/minimum-increment-to-make-array-unique)", "[\u4f7f\u6570\u7ec4\u552f\u4e00\u7684\u6700\u5c0f\u589e\u91cf](/solution/0900-0999/0945.Minimum%20Increment%20to%20Make%20Array%20Unique/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0945](https://leetcode.com/problems/minimum-increment-to-make-array-unique)", "[Minimum Increment to Make Array Unique](/solution/0900-0999/0945.Minimum%20Increment%20to%20Make%20Array%20Unique/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0981", "frontend_question_id": "0944", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/delete-columns-to-make-sorted", "url_en": "https://leetcode.com/problems/delete-columns-to-make-sorted", "relative_path_cn": "/solution/0900-0999/0944.Delete%20Columns%20to%20Make%20Sorted/README.md", "relative_path_en": "/solution/0900-0999/0944.Delete%20Columns%20to%20Make%20Sorted/README_EN.md", "title_cn": "\u5220\u5217\u9020\u5e8f", "title_en": "Delete Columns to Make Sorted", "question_title_slug": "delete-columns-to-make-sorted", "content_en": "

You are given an array of n strings strs, all of the same length.

\n\n

The strings can be arranged such that there is one on each line, making a grid. For example, strs = ["abc", "bce", "cae"] can be arranged as:

\n\n
\nabc\nbce\ncae\n
\n\n

You want to delete the columns that are not sorted lexicographically. In the above example (0-indexed), columns 0 ('a', 'b', 'c') and 2 ('c', 'e', 'e') are sorted while column 1 ('b', 'c', 'a') is not, so you would delete column 1.

\n\n

Return the number of columns that you will delete.

\n\n

 

\n

Example 1:

\n\n
\nInput: strs = ["cba","daf","ghi"]\nOutput: 1\nExplanation: The grid looks as follows:\n  cba\n  daf\n  ghi\nColumns 0 and 2 are sorted, but column 1 is not, so you only need to delete 1 column.\n
\n\n

Example 2:

\n\n
\nInput: strs = ["a","b"]\nOutput: 0\nExplanation: The grid looks as follows:\n  a\n  b\nColumn 0 is the only column and is sorted, so you will not delete any columns.\n
\n\n

Example 3:

\n\n
\nInput: strs = ["zyx","wvu","tsr"]\nOutput: 3\nExplanation: The grid looks as follows:\n  zyx\n  wvu\n  tsr\nAll 3 columns are not sorted, so you will delete all 3.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == strs.length
  • \n\t
  • 1 <= n <= 100
  • \n\t
  • 1 <= strs[i].length <= 1000
  • \n\t
  • strs[i] consists of lowercase English letters.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u7531 n \u4e2a\u5c0f\u5199\u5b57\u6bcd\u5b57\u7b26\u4e32\u7ec4\u6210\u7684\u6570\u7ec4 strs\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5b57\u7b26\u4e32\u957f\u5ea6\u76f8\u7b49\u3002

\n\n

\u8fd9\u4e9b\u5b57\u7b26\u4e32\u53ef\u4ee5\u6bcf\u4e2a\u4e00\u884c\uff0c\u6392\u6210\u4e00\u4e2a\u7f51\u683c\u3002\u4f8b\u5982\uff0cstrs = [\"abc\", \"bce\", \"cae\"] \u53ef\u4ee5\u6392\u5217\u4e3a\uff1a

\n\n
\nabc\nbce\ncae
\n\n

\u4f60\u9700\u8981\u627e\u51fa\u5e76\u5220\u9664 \u4e0d\u662f\u6309\u5b57\u5178\u5e8f\u5347\u5e8f\u6392\u5217\u7684 \u5217\u3002\u5728\u4e0a\u9762\u7684\u4f8b\u5b50\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\u4e2d\uff0c\u5217 0\uff08'a', 'b', 'c'\uff09\u548c\u5217 2\uff08'c', 'e', 'e'\uff09\u90fd\u662f\u6309\u5347\u5e8f\u6392\u5217\u7684\uff0c\u800c\u5217 1\uff08'b', 'c', 'a'\uff09\u4e0d\u662f\uff0c\u6240\u4ee5\u8981\u5220\u9664\u5217 1 \u3002

\n\n

\u8fd4\u56de\u4f60\u9700\u8981\u5220\u9664\u7684\u5217\u6570\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1astrs = [\"cba\",\"daf\",\"ghi\"]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u7f51\u683c\u793a\u610f\u5982\u4e0b\uff1a\n  cba\n  daf\n  ghi\n\u5217 0 \u548c\u5217 2 \u6309\u5347\u5e8f\u6392\u5217\uff0c\u4f46\u5217 1 \u4e0d\u662f\uff0c\u6240\u4ee5\u53ea\u9700\u8981\u5220\u9664\u5217 1 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1astrs = [\"a\",\"b\"]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u7f51\u683c\u793a\u610f\u5982\u4e0b\uff1a\n  a\n  b\n\u53ea\u6709\u5217 0 \u8fd9\u4e00\u5217\uff0c\u4e14\u5df2\u7ecf\u6309\u5347\u5e8f\u6392\u5217\uff0c\u6240\u4ee5\u4e0d\u7528\u5220\u9664\u4efb\u4f55\u5217\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1astrs = [\"zyx\",\"wvu\",\"tsr\"]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u7f51\u683c\u793a\u610f\u5982\u4e0b\uff1a\n  zyx\n  wvu\n  tsr\n\u6240\u6709 3 \u5217\u90fd\u662f\u975e\u5347\u5e8f\u6392\u5217\u7684\uff0c\u6240\u4ee5\u90fd\u8981\u5220\u9664\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • n == strs.length
  • \n\t
  • 1 <= n <= 100
  • \n\t
  • 1 <= strs[i].length <= 1000
  • \n\t
  • strs[i] \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
  • \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minDeletionSize(vector& strs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minDeletionSize(String[] strs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minDeletionSize(self, strs):\n \"\"\"\n :type strs: List[str]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minDeletionSize(self, strs: List[str]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minDeletionSize(char ** strs, int strsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinDeletionSize(string[] strs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} strs\n * @return {number}\n */\nvar minDeletionSize = function(strs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} strs\n# @return {Integer}\ndef min_deletion_size(strs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minDeletionSize(_ strs: [String]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minDeletionSize(strs []string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minDeletionSize(strs: Array[String]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minDeletionSize(strs: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_deletion_size(strs: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $strs\n * @return Integer\n */\n function minDeletionSize($strs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minDeletionSize(strs: string[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-deletion-size strs)\n (-> (listof string?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0944](https://leetcode-cn.com/problems/delete-columns-to-make-sorted)", "[\u5220\u5217\u9020\u5e8f](/solution/0900-0999/0944.Delete%20Columns%20to%20Make%20Sorted/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u7b80\u5355", ""], "md_table_row_en": ["[0944](https://leetcode.com/problems/delete-columns-to-make-sorted)", "[Delete Columns to Make Sorted](/solution/0900-0999/0944.Delete%20Columns%20to%20Make%20Sorted/README_EN.md)", "`Greedy`", "Easy", ""]}, {"question_id": "0980", "frontend_question_id": "0943", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-the-shortest-superstring", "url_en": "https://leetcode.com/problems/find-the-shortest-superstring", "relative_path_cn": "/solution/0900-0999/0943.Find%20the%20Shortest%20Superstring/README.md", "relative_path_en": "/solution/0900-0999/0943.Find%20the%20Shortest%20Superstring/README_EN.md", "title_cn": "\u6700\u77ed\u8d85\u7ea7\u4e32", "title_en": "Find the Shortest Superstring", "question_title_slug": "find-the-shortest-superstring", "content_en": "

Given an array of strings words, return the smallest string that contains each string in words as a substring. If there are multiple valid strings of the smallest length, return any of them.

\n\n

You may assume that no string in words is a substring of another string in words.

\n\n

 

\n

Example 1:

\n\n
\nInput: words = ["alex","loves","leetcode"]\nOutput: "alexlovesleetcode"\nExplanation: All permutations of "alex","loves","leetcode" would also be accepted.\n
\n\n

Example 2:

\n\n
\nInput: words = ["catg","ctaagt","gcta","ttca","atgcatc"]\nOutput: "gctaagttcatgcatc"\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= words.length <= 12
  • \n\t
  • 1 <= words[i].length <= 20
  • \n\t
  • words[i] consists of lowercase English letters.
  • \n\t
  • All the strings of words are unique.
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4 words\uff0c\u627e\u5230\u4ee5 words \u4e2d\u6bcf\u4e2a\u5b57\u7b26\u4e32\u4f5c\u4e3a\u5b50\u5b57\u7b26\u4e32\u7684\u6700\u77ed\u5b57\u7b26\u4e32\u3002\u5982\u679c\u6709\u591a\u4e2a\u6709\u6548\u6700\u77ed\u5b57\u7b26\u4e32\u6ee1\u8db3\u9898\u76ee\u6761\u4ef6\uff0c\u8fd4\u56de\u5176\u4e2d \u4efb\u610f\u4e00\u4e2a \u5373\u53ef\u3002

\n\n

\u6211\u4eec\u53ef\u4ee5\u5047\u8bbe words \u4e2d\u6ca1\u6709\u5b57\u7b26\u4e32\u662f words \u4e2d\u53e6\u4e00\u4e2a\u5b57\u7b26\u4e32\u7684\u5b50\u5b57\u7b26\u4e32\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1awords = [\"alex\",\"loves\",\"leetcode\"]\n\u8f93\u51fa\uff1a\"alexlovesleetcode\"\n\u89e3\u91ca\uff1a\"alex\"\uff0c\"loves\"\uff0c\"leetcode\" \u7684\u6240\u6709\u6392\u5217\u90fd\u4f1a\u88ab\u63a5\u53d7\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1awords = [\"catg\",\"ctaagt\",\"gcta\",\"ttca\",\"atgcatc\"]\n\u8f93\u51fa\uff1a\"gctaagttcatgcatc\"
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= words.length <= 12
  • \n\t
  • 1 <= words[i].length <= 20
  • \n\t
  • words[i] \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
  • \n\t
  • words \u4e2d\u7684\u6240\u6709\u5b57\u7b26\u4e32 \u4e92\u4e0d\u76f8\u540c
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string shortestSuperstring(vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String shortestSuperstring(String[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def shortestSuperstring(self, words):\n \"\"\"\n :type words: List[str]\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def shortestSuperstring(self, words: List[str]) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * shortestSuperstring(char ** words, int wordsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ShortestSuperstring(string[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @return {string}\n */\nvar shortestSuperstring = function(words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @return {String}\ndef shortest_superstring(words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func shortestSuperstring(_ words: [String]) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func shortestSuperstring(words []string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def shortestSuperstring(words: Array[String]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun shortestSuperstring(words: Array): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn shortest_superstring(words: Vec) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @return String\n */\n function shortestSuperstring($words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function shortestSuperstring(words: string[]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (shortest-superstring words)\n (-> (listof string?) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0943](https://leetcode-cn.com/problems/find-the-shortest-superstring)", "[\u6700\u77ed\u8d85\u7ea7\u4e32](/solution/0900-0999/0943.Find%20the%20Shortest%20Superstring/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0943](https://leetcode.com/problems/find-the-shortest-superstring)", "[Find the Shortest Superstring](/solution/0900-0999/0943.Find%20the%20Shortest%20Superstring/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "0979", "frontend_question_id": "0942", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/di-string-match", "url_en": "https://leetcode.com/problems/di-string-match", "relative_path_cn": "/solution/0900-0999/0942.DI%20String%20Match/README.md", "relative_path_en": "/solution/0900-0999/0942.DI%20String%20Match/README_EN.md", "title_cn": "\u589e\u51cf\u5b57\u7b26\u4e32\u5339\u914d", "title_en": "DI String Match", "question_title_slug": "di-string-match", "content_en": "

A permutation perm of n + 1 integers of all the integers in the range [0, n] can be represented as a string s of length n where:

\n\n
    \n\t
  • s[i] == 'I' if perm[i] < perm[i + 1], and
  • \n\t
  • s[i] == 'D' if perm[i] > perm[i + 1].
  • \n
\n\n

Given a string s, reconstruct the permutation perm and return it. If there are multiple valid permutations perm, return any of them.

\n\n

 

\n

Example 1:

\n
Input: s = \"IDID\"\nOutput: [0,4,1,3,2]\n

Example 2:

\n
Input: s = \"III\"\nOutput: [0,1,2,3]\n

Example 3:

\n
Input: s = \"DDI\"\nOutput: [3,2,0,1]\n
\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 105
  • \n\t
  • s[i] is either 'I' or 'D'.
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u53ea\u542b "I"\uff08\u589e\u5927\uff09\u6216 "D"\uff08\u51cf\u5c0f\uff09\u7684\u5b57\u7b26\u4e32 S \uff0c\u4ee4 N = S.length\u3002

\n\n

\u8fd4\u56de [0, 1, ..., N] \u7684\u4efb\u610f\u6392\u5217 A \u4f7f\u5f97\u5bf9\u4e8e\u6240\u6709 i = 0, ..., N-1\uff0c\u90fd\u6709\uff1a

\n\n
    \n\t
  • \u5982\u679c S[i] == "I"\uff0c\u90a3\u4e48 A[i] < A[i+1]
  • \n\t
  • \u5982\u679c S[i] == "D"\uff0c\u90a3\u4e48 A[i] > A[i+1]
  • \n
\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a"IDID"\n\u8f93\u51fa\uff1a[0,4,1,3,2]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a"III"\n\u8f93\u51fa\uff1a[0,1,2,3]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1a"DDI"\n\u8f93\u51fa\uff1a[3,2,0,1]
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= S.length <= 10000
  • \n\t
  • S \u53ea\u5305\u542b\u5b57\u7b26 "I" \u6216 "D"\u3002
  • \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector diStringMatch(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] diStringMatch(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def diStringMatch(self, s):\n \"\"\"\n :type s: str\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def diStringMatch(self, s: str) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* diStringMatch(char * s, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] DiStringMatch(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number[]}\n */\nvar diStringMatch = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer[]}\ndef di_string_match(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func diStringMatch(_ s: String) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func diStringMatch(s string) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def diStringMatch(s: String): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun diStringMatch(s: String): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn di_string_match(s: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer[]\n */\n function diStringMatch($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function diStringMatch(s: string): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (di-string-match s)\n (-> string? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0942](https://leetcode-cn.com/problems/di-string-match)", "[\u589e\u51cf\u5b57\u7b26\u4e32\u5339\u914d](/solution/0900-0999/0942.DI%20String%20Match/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0942](https://leetcode.com/problems/di-string-match)", "[DI String Match](/solution/0900-0999/0942.DI%20String%20Match/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "0978", "frontend_question_id": "0941", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/valid-mountain-array", "url_en": "https://leetcode.com/problems/valid-mountain-array", "relative_path_cn": "/solution/0900-0999/0941.Valid%20Mountain%20Array/README.md", "relative_path_en": "/solution/0900-0999/0941.Valid%20Mountain%20Array/README_EN.md", "title_cn": "\u6709\u6548\u7684\u5c71\u8109\u6570\u7ec4", "title_en": "Valid Mountain Array", "question_title_slug": "valid-mountain-array", "content_en": "

Given an array of integers arr, return true if and only if it is a valid mountain array.

\n\n

Recall that arr is a mountain array if and only if:

\n\n
    \n\t
  • arr.length >= 3
  • \n\t
  • There exists some i with 0 < i < arr.length - 1 such that:\n\t
      \n\t\t
    • arr[0] < arr[1] < ... < arr[i - 1] < arr[i]
    • \n\t\t
    • arr[i] > arr[i + 1] > ... > arr[arr.length - 1]
    • \n\t
    \n\t
  • \n
\n\n

 

\n

Example 1:

\n
Input: arr = [2,1]\nOutput: false\n

Example 2:

\n
Input: arr = [3,5,5]\nOutput: false\n

Example 3:

\n
Input: arr = [0,3,2,1]\nOutput: true\n
\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= arr.length <= 104
  • \n\t
  • 0 <= arr[i] <= 104
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr\uff0c\u5982\u679c\u5b83\u662f\u6709\u6548\u7684\u5c71\u8109\u6570\u7ec4\u5c31\u8fd4\u56de\u00a0true\uff0c\u5426\u5219\u8fd4\u56de false\u3002

\n\n

\u8ba9\u6211\u4eec\u56de\u987e\u4e00\u4e0b\uff0c\u5982\u679c A \u6ee1\u8db3\u4e0b\u8ff0\u6761\u4ef6\uff0c\u90a3\u4e48\u5b83\u662f\u4e00\u4e2a\u5c71\u8109\u6570\u7ec4\uff1a

\n\n
    \n\t
  • arr.length >= 3
  • \n\t
  • \u5728\u00a00 < i\u00a0< arr.length - 1\u00a0\u6761\u4ef6\u4e0b\uff0c\u5b58\u5728\u00a0i\u00a0\u4f7f\u5f97\uff1a\n\t
      \n\t\t
    • arr[0] < arr[1] < ... arr[i-1] < arr[i]
    • \n\t\t
    • arr[i] > arr[i+1] > ... > arr[arr.length - 1]
    • \n\t
    \n\t
  • \n
\n\n

\u00a0

\n\n

\"\"

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [2,1]\n\u8f93\u51fa\uff1afalse\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [3,5,5]\n\u8f93\u51fa\uff1afalse\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [0,3,2,1]\n\u8f93\u51fa\uff1atrue
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= arr.length <= 104
  • \n\t
  • 0 <= arr[i] <= 104
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool validMountainArray(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean validMountainArray(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def validMountainArray(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def validMountainArray(self, arr: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool validMountainArray(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool ValidMountainArray(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {boolean}\n */\nvar validMountainArray = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Boolean}\ndef valid_mountain_array(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func validMountainArray(_ arr: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func validMountainArray(arr []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def validMountainArray(arr: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun validMountainArray(arr: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn valid_mountain_array(arr: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Boolean\n */\n function validMountainArray($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function validMountainArray(arr: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (valid-mountain-array arr)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0941](https://leetcode-cn.com/problems/valid-mountain-array)", "[\u6709\u6548\u7684\u5c71\u8109\u6570\u7ec4](/solution/0900-0999/0941.Valid%20Mountain%20Array/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0941](https://leetcode.com/problems/valid-mountain-array)", "[Valid Mountain Array](/solution/0900-0999/0941.Valid%20Mountain%20Array/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0977", "frontend_question_id": "0940", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/distinct-subsequences-ii", "url_en": "https://leetcode.com/problems/distinct-subsequences-ii", "relative_path_cn": "/solution/0900-0999/0940.Distinct%20Subsequences%20II/README.md", "relative_path_en": "/solution/0900-0999/0940.Distinct%20Subsequences%20II/README_EN.md", "title_cn": "\u4e0d\u540c\u7684\u5b50\u5e8f\u5217 II", "title_en": "Distinct Subsequences II", "question_title_slug": "distinct-subsequences-ii", "content_en": "

Given a string s, count the number of distinct, non-empty subsequences of s .

\n\n

Since the result may be large, return the answer modulo 109 + 7.

\n\n

 

\n\n

Example 1:

\n\n
\nInput: s = "abc"\nOutput: 7\nExplanation: The 7 distinct subsequences are "a", "b", "c", "ab", "ac", "bc", and "abc".\n
\n\n
\n

Example 2:

\n\n
\nInput: s = "aba"\nOutput: 6\nExplanation: The 6 distinct subsequences are "a", "b", "ab", "ba", "aa" and "aba".\n
\n\n
\n

Example 3:

\n\n
\nInput: s = "aaa"\nOutput: 3\nExplanation: The 3 distinct subsequences are "a", "aa" and "aaa".\n
\n
\n
\n\n

 

\n\n

 

\n\n

Note:

\n\n
    \n\t
  1. s contains only lowercase letters.
  2. \n\t
  3. 1 <= s.length <= 2000
  4. \n
\n\n
\n

 

\n\n
\n
 
\n
\n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32 S\uff0c\u8ba1\u7b97 S \u7684\u4e0d\u540c\u975e\u7a7a\u5b50\u5e8f\u5217\u7684\u4e2a\u6570\u3002

\n\n

\u56e0\u4e3a\u7ed3\u679c\u53ef\u80fd\u5f88\u5927\uff0c\u6240\u4ee5\u8fd4\u56de\u7b54\u6848\u6a21 10^9 + 7.

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a"abc"\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a7 \u4e2a\u4e0d\u540c\u7684\u5b50\u5e8f\u5217\u5206\u522b\u662f "a", "b", "c", "ab", "ac", "bc", \u4ee5\u53ca "abc"\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a"aba"\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a6 \u4e2a\u4e0d\u540c\u7684\u5b50\u5e8f\u5217\u5206\u522b\u662f "a", "b", "ab", "ba", "aa" \u4ee5\u53ca "aba"\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1a"aaa"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a3 \u4e2a\u4e0d\u540c\u7684\u5b50\u5e8f\u5217\u5206\u522b\u662f "a", "aa" \u4ee5\u53ca "aaa"\u3002\n
\n\n

 

\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. S \u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd\u3002
  2. \n\t
  3. 1 <= S.length <= 2000
  4. \n
\n\n

 

\n\n

 

\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int distinctSubseqII(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int distinctSubseqII(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def distinctSubseqII(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def distinctSubseqII(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint distinctSubseqII(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int DistinctSubseqII(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar distinctSubseqII = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef distinct_subseq_ii(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func distinctSubseqII(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func distinctSubseqII(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def distinctSubseqII(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun distinctSubseqII(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn distinct_subseq_ii(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function distinctSubseqII($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function distinctSubseqII(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (distinct-subseq-ii s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0940](https://leetcode-cn.com/problems/distinct-subsequences-ii)", "[\u4e0d\u540c\u7684\u5b50\u5e8f\u5217 II](/solution/0900-0999/0940.Distinct%20Subsequences%20II/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0940](https://leetcode.com/problems/distinct-subsequences-ii)", "[Distinct Subsequences II](/solution/0900-0999/0940.Distinct%20Subsequences%20II/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "0976", "frontend_question_id": "0939", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-area-rectangle", "url_en": "https://leetcode.com/problems/minimum-area-rectangle", "relative_path_cn": "/solution/0900-0999/0939.Minimum%20Area%20Rectangle/README.md", "relative_path_en": "/solution/0900-0999/0939.Minimum%20Area%20Rectangle/README_EN.md", "title_cn": "\u6700\u5c0f\u9762\u79ef\u77e9\u5f62", "title_en": "Minimum Area Rectangle", "question_title_slug": "minimum-area-rectangle", "content_en": "

Given a set of points in the xy-plane, determine the minimum area of a rectangle formed from these points, with sides parallel to the x and y axes.

\r\n\r\n

If there isn't any rectangle, return 0.

\r\n\r\n

 

\r\n\r\n
\r\n

Example 1:

\r\n\r\n
\r\nInput: [[1,1],[1,3],[3,1],[3,3],[2,2]]\r\nOutput: 4\r\n
\r\n\r\n
\r\n

Example 2:

\r\n\r\n
\r\nInput: [[1,1],[1,3],[3,1],[3,3],[4,1],[4,3]]\r\nOutput: 2\r\n
\r\n\r\n

 

\r\n\r\n

Note:

\r\n\r\n
    \r\n\t
  1. 1 <= points.length <= 500
  2. \r\n\t
  3. 0 <= points[i][0] <= 40000
  4. \r\n\t
  5. 0 <= points[i][1] <= 40000
  6. \r\n\t
  7. All points are distinct.
  8. \r\n
\r\n
\r\n
", "content_cn": "

\u7ed9\u5b9a\u5728 xy \u5e73\u9762\u4e0a\u7684\u4e00\u7ec4\u70b9\uff0c\u786e\u5b9a\u7531\u8fd9\u4e9b\u70b9\u7ec4\u6210\u7684\u77e9\u5f62\u7684\u6700\u5c0f\u9762\u79ef\uff0c\u5176\u4e2d\u77e9\u5f62\u7684\u8fb9\u5e73\u884c\u4e8e x \u8f74\u548c y \u8f74\u3002

\n\n

\u5982\u679c\u6ca1\u6709\u4efb\u4f55\u77e9\u5f62\uff0c\u5c31\u8fd4\u56de 0\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a[[1,1],[1,3],[3,1],[3,3],[2,2]]\n\u8f93\u51fa\uff1a4\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a[[1,1],[1,3],[3,1],[3,3],[4,1],[4,3]]\n\u8f93\u51fa\uff1a2\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= points.length <= 500
  2. \n\t
  3. 0 <= points[i][0] <= 40000
  4. \n\t
  5. 0 <= points[i][1] <= 40000
  6. \n\t
  7. \u6240\u6709\u7684\u70b9\u90fd\u662f\u4e0d\u540c\u7684\u3002
  8. \n
\n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minAreaRect(vector>& points) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minAreaRect(int[][] points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minAreaRect(self, points):\n \"\"\"\n :type points: List[List[int]]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minAreaRect(self, points: List[List[int]]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minAreaRect(int** points, int pointsSize, int* pointsColSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinAreaRect(int[][] points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} points\n * @return {number}\n */\nvar minAreaRect = function(points) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} points\n# @return {Integer}\ndef min_area_rect(points)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minAreaRect(_ points: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minAreaRect(points [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minAreaRect(points: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minAreaRect(points: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_area_rect(points: Vec>) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $points\n * @return Integer\n */\n function minAreaRect($points) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minAreaRect(points: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-area-rect points)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0939](https://leetcode-cn.com/problems/minimum-area-rectangle)", "[\u6700\u5c0f\u9762\u79ef\u77e9\u5f62](/solution/0900-0999/0939.Minimum%20Area%20Rectangle/README.md)", "`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0939](https://leetcode.com/problems/minimum-area-rectangle)", "[Minimum Area Rectangle](/solution/0900-0999/0939.Minimum%20Area%20Rectangle/README_EN.md)", "`Hash Table`", "Medium", ""]}, {"question_id": "0975", "frontend_question_id": "0938", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/range-sum-of-bst", "url_en": "https://leetcode.com/problems/range-sum-of-bst", "relative_path_cn": "/solution/0900-0999/0938.Range%20Sum%20of%20BST/README.md", "relative_path_en": "/solution/0900-0999/0938.Range%20Sum%20of%20BST/README_EN.md", "title_cn": "\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u8303\u56f4\u548c", "title_en": "Range Sum of BST", "question_title_slug": "range-sum-of-bst", "content_en": "

Given the root node of a binary search tree and two integers low and high, return the sum of values of all nodes with a value in the inclusive range [low, high].

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: root = [10,5,15,3,7,null,18], low = 7, high = 15\nOutput: 32\nExplanation: Nodes 7, 10, and 15 are in the range [7, 15]. 7 + 10 + 15 = 32.\n
\n\n

Example 2:

\n\"\"\n
\nInput: root = [10,5,15,3,7,13,18,1,null,6], low = 6, high = 10\nOutput: 23\nExplanation: Nodes 6, 7, and 10 are in the range [6, 10]. 6 + 7 + 10 = 23.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The number of nodes in the tree is in the range [1, 2 * 104].
  • \n\t
  • 1 <= Node.val <= 105
  • \n\t
  • 1 <= low <= high <= 105
  • \n\t
  • All Node.val are unique.
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6839\u7ed3\u70b9\u00a0root\uff0c\u8fd4\u56de\u503c\u4f4d\u4e8e\u8303\u56f4 [low, high] \u4e4b\u95f4\u7684\u6240\u6709\u7ed3\u70b9\u7684\u503c\u7684\u548c\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1aroot = [10,5,15,3,7,null,18], low = 7, high = 15\n\u8f93\u51fa\uff1a32\n
\n\n

\u793a\u4f8b 2\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1aroot = [10,5,15,3,7,13,18,1,null,6], low = 6, high = 10\n\u8f93\u51fa\uff1a23\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u6811\u4e2d\u8282\u70b9\u6570\u76ee\u5728\u8303\u56f4 [1, 2 * 104] \u5185
  • \n\t
  • 1 <= Node.val <= 105
  • \n\t
  • 1 <= low <= high <= 105
  • \n\t
  • \u6240\u6709 Node.val \u4e92\u4e0d\u76f8\u540c
  • \n
\n", "tags_en": ["Tree", "Depth-first Search", "Recursion"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u9012\u5f52"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int rangeSumBST(TreeNode* root, int low, int high) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int rangeSumBST(TreeNode root, int low, int high) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def rangeSumBST(self, root, low, high):\n \"\"\"\n :type root: TreeNode\n :type low: int\n :type high: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def rangeSumBST(self, root: TreeNode, low: int, high: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint rangeSumBST(struct TreeNode* root, int low, int high){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int RangeSumBST(TreeNode root, int low, int high) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number} low\n * @param {number} high\n * @return {number}\n */\nvar rangeSumBST = function(root, low, high) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @param {Integer} low\n# @param {Integer} high\n# @return {Integer}\ndef range_sum_bst(root, low, high)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func rangeSumBST(_ root: TreeNode?, _ low: Int, _ high: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc rangeSumBST(root *TreeNode, low int, high int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def rangeSumBST(root: TreeNode, low: Int, high: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun rangeSumBST(root: TreeNode?, low: Int, high: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn range_sum_bst(root: Option>>, low: i32, high: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param Integer $low\n * @param Integer $high\n * @return Integer\n */\n function rangeSumBST($root, $low, $high) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction rangeSumBST(root: TreeNode | null, low: number, high: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (range-sum-bst root low high)\n (-> (or/c tree-node? #f) exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0938](https://leetcode-cn.com/problems/range-sum-of-bst)", "[\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u8303\u56f4\u548c](/solution/0900-0999/0938.Range%20Sum%20of%20BST/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u9012\u5f52`", "\u7b80\u5355", ""], "md_table_row_en": ["[0938](https://leetcode.com/problems/range-sum-of-bst)", "[Range Sum of BST](/solution/0900-0999/0938.Range%20Sum%20of%20BST/README_EN.md)", "`Tree`,`Depth-first Search`,`Recursion`", "Easy", ""]}, {"question_id": "0974", "frontend_question_id": "0937", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reorder-data-in-log-files", "url_en": "https://leetcode.com/problems/reorder-data-in-log-files", "relative_path_cn": "/solution/0900-0999/0937.Reorder%20Data%20in%20Log%20Files/README.md", "relative_path_en": "/solution/0900-0999/0937.Reorder%20Data%20in%20Log%20Files/README_EN.md", "title_cn": "\u91cd\u65b0\u6392\u5217\u65e5\u5fd7\u6587\u4ef6", "title_en": "Reorder Data in Log Files", "question_title_slug": "reorder-data-in-log-files", "content_en": "

You are given an array of logs. Each log is a space-delimited string of words, where the first word is the identifier.

\n\n

There are two types of logs:

\n\n
    \n\t
  • Letter-logs: All words (except the identifier) consist of lowercase English letters.
  • \n\t
  • Digit-logs: All words (except the identifier) consist of digits.
  • \n
\n\n

Reorder these logs so that:

\n\n
    \n\t
  1. The letter-logs come before all digit-logs.
  2. \n\t
  3. The letter-logs are sorted lexicographically by their contents. If their contents are the same, then sort them lexicographically by their identifiers.
  4. \n\t
  5. The digit-logs maintain their relative ordering.
  6. \n
\n\n

Return the final order of the logs.

\n\n

 

\n

Example 1:

\n\n
\nInput: logs = ["dig1 8 1 5 1","let1 art can","dig2 3 6","let2 own kit dig","let3 art zero"]\nOutput: ["let1 art can","let3 art zero","let2 own kit dig","dig1 8 1 5 1","dig2 3 6"]\nExplanation:\nThe letter-log contents are all different, so their ordering is "art can", "art zero", "own kit dig".\nThe digit-logs have a relative order of "dig1 8 1 5 1", "dig2 3 6".\n
\n\n

Example 2:

\n\n
\nInput: logs = ["a1 9 2 3 1","g1 act car","zo4 4 7","ab1 off key dog","a8 act zoo"]\nOutput: ["g1 act car","a8 act zoo","ab1 off key dog","a1 9 2 3 1","zo4 4 7"]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= logs.length <= 100
  • \n\t
  • 3 <= logs[i].length <= 100
  • \n\t
  • All the tokens of logs[i] are separated by a single space.
  • \n\t
  • logs[i] is guaranteed to have an identifier and at least one word after the identifier.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u65e5\u5fd7\u6570\u7ec4 logs\u3002\u6bcf\u6761\u65e5\u5fd7\u90fd\u662f\u4ee5\u7a7a\u683c\u5206\u9694\u7684\u5b57\u4e32\uff0c\u5176\u7b2c\u4e00\u4e2a\u5b57\u4e3a\u5b57\u6bcd\u4e0e\u6570\u5b57\u6df7\u5408\u7684 \u6807\u8bc6\u7b26 \u3002

\n\n

\u6709\u4e24\u79cd\u4e0d\u540c\u7c7b\u578b\u7684\u65e5\u5fd7\uff1a

\n\n
    \n\t
  • \u5b57\u6bcd\u65e5\u5fd7\uff1a\u9664\u6807\u8bc6\u7b26\u4e4b\u5916\uff0c\u6240\u6709\u5b57\u5747\u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210
  • \n\t
  • \u6570\u5b57\u65e5\u5fd7\uff1a\u9664\u6807\u8bc6\u7b26\u4e4b\u5916\uff0c\u6240\u6709\u5b57\u5747\u7531\u6570\u5b57\u7ec4\u6210
  • \n
\n\n

\u8bf7\u6309\u4e0b\u8ff0\u89c4\u5219\u5c06\u65e5\u5fd7\u91cd\u65b0\u6392\u5e8f\uff1a

\n\n
    \n\t
  • \u6240\u6709 \u5b57\u6bcd\u65e5\u5fd7 \u90fd\u6392\u5728 \u6570\u5b57\u65e5\u5fd7 \u4e4b\u524d\u3002
  • \n\t
  • \u5b57\u6bcd\u65e5\u5fd7 \u5728\u5185\u5bb9\u4e0d\u540c\u65f6\uff0c\u5ffd\u7565\u6807\u8bc6\u7b26\u540e\uff0c\u6309\u5185\u5bb9\u5b57\u6bcd\u987a\u5e8f\u6392\u5e8f\uff1b\u5728\u5185\u5bb9\u76f8\u540c\u65f6\uff0c\u6309\u6807\u8bc6\u7b26\u6392\u5e8f\u3002
  • \n\t
  • \u6570\u5b57\u65e5\u5fd7 \u5e94\u8be5\u4fdd\u7559\u539f\u6765\u7684\u76f8\u5bf9\u987a\u5e8f\u3002
  • \n
\n\n

\u8fd4\u56de\u65e5\u5fd7\u7684\u6700\u7ec8\u987a\u5e8f\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1alogs = [\"dig1 8 1 5 1\",\"let1 art can\",\"dig2 3 6\",\"let2 own kit dig\",\"let3 art zero\"]\n\u8f93\u51fa\uff1a[\"let1 art can\",\"let3 art zero\",\"let2 own kit dig\",\"dig1 8 1 5 1\",\"dig2 3 6\"]\n\u89e3\u91ca\uff1a\n\u5b57\u6bcd\u65e5\u5fd7\u7684\u5185\u5bb9\u90fd\u4e0d\u540c\uff0c\u6240\u4ee5\u987a\u5e8f\u4e3a \"art can\", \"art zero\", \"own kit dig\" \u3002\n\u6570\u5b57\u65e5\u5fd7\u4fdd\u7559\u539f\u6765\u7684\u76f8\u5bf9\u987a\u5e8f \"dig1 8 1 5 1\", \"dig2 3 6\" \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1alogs = [\"a1 9 2 3 1\",\"g1 act car\",\"zo4 4 7\",\"ab1 off key dog\",\"a8 act zoo\"]\n\u8f93\u51fa\uff1a[\"g1 act car\",\"a8 act zoo\",\"ab1 off key dog\",\"a1 9 2 3 1\",\"zo4 4 7\"]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= logs.length <= 100
  • \n\t
  • 3 <= logs[i].length <= 100
  • \n\t
  • logs[i] \u4e2d\uff0c\u5b57\u4e0e\u5b57\u4e4b\u95f4\u90fd\u7528 \u5355\u4e2a \u7a7a\u683c\u5206\u9694
  • \n\t
  • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1 logs[i] \u90fd\u6709\u4e00\u4e2a\u6807\u8bc6\u7b26\uff0c\u5e76\u4e14\u5728\u6807\u8bc6\u7b26\u4e4b\u540e\u81f3\u5c11\u5b58\u5728\u4e00\u4e2a\u5b57
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector reorderLogFiles(vector& logs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String[] reorderLogFiles(String[] logs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def reorderLogFiles(self, logs):\n \"\"\"\n :type logs: List[str]\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def reorderLogFiles(self, logs: List[str]) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** reorderLogFiles(char ** logs, int logsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string[] ReorderLogFiles(string[] logs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} logs\n * @return {string[]}\n */\nvar reorderLogFiles = function(logs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} logs\n# @return {String[]}\ndef reorder_log_files(logs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func reorderLogFiles(_ logs: [String]) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func reorderLogFiles(logs []string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def reorderLogFiles(logs: Array[String]): Array[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun reorderLogFiles(logs: Array): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn reorder_log_files(logs: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $logs\n * @return String[]\n */\n function reorderLogFiles($logs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function reorderLogFiles(logs: string[]): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (reorder-log-files logs)\n (-> (listof string?) (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0937](https://leetcode-cn.com/problems/reorder-data-in-log-files)", "[\u91cd\u65b0\u6392\u5217\u65e5\u5fd7\u6587\u4ef6](/solution/0900-0999/0937.Reorder%20Data%20in%20Log%20Files/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0937](https://leetcode.com/problems/reorder-data-in-log-files)", "[Reorder Data in Log Files](/solution/0900-0999/0937.Reorder%20Data%20in%20Log%20Files/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "0973", "frontend_question_id": "0936", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/stamping-the-sequence", "url_en": "https://leetcode.com/problems/stamping-the-sequence", "relative_path_cn": "/solution/0900-0999/0936.Stamping%20The%20Sequence/README.md", "relative_path_en": "/solution/0900-0999/0936.Stamping%20The%20Sequence/README_EN.md", "title_cn": "\u6233\u5370\u5e8f\u5217", "title_en": "Stamping The Sequence", "question_title_slug": "stamping-the-sequence", "content_en": "

You want to form a target string of lowercase letters.

\r\n\r\n

At the beginning, your sequence is target.length '?' marks.  You also have a stamp of lowercase letters.

\r\n\r\n

On each turn, you may place the stamp over the sequence, and replace every letter in the sequence with the corresponding letter from the stamp.  You can make up to 10 * target.length turns.

\r\n\r\n

For example, if the initial sequence is "?????", and your stamp is "abc",  then you may make "abc??", "?abc?", "??abc" in the first turn.  (Note that the stamp must be fully contained in the boundaries of the sequence in order to stamp.)

\r\n\r\n

If the sequence is possible to stamp, then return an array of the index of the left-most letter being stamped at each turn.  If the sequence is not possible to stamp, return an empty array.

\r\n\r\n

For example, if the sequence is "ababc", and the stamp is "abc", then we could return the answer [0, 2], corresponding to the moves "?????" -> "abc??" -> "ababc".

\r\n\r\n

Also, if the sequence is possible to stamp, it is guaranteed it is possible to stamp within 10 * target.length moves.  Any answers specifying more than this number of moves will not be accepted.

\r\n\r\n

 

\r\n\r\n

Example 1:

\r\n\r\n
\r\nInput: stamp = "abc", target = "ababc"\r\nOutput: [0,2]\r\n([1,0,2] would also be accepted as an answer, as well as some other answers.)\r\n
\r\n\r\n
\r\n

Example 2:

\r\n\r\n
\r\nInput: stamp = "abca", target = "aabcaca"\r\nOutput: [3,0,1]\r\n
\r\n\r\n
\r\n

 

\r\n\r\n

Note:

\r\n
\r\n
\r\n\r\n
    \r\n\t
  1. 1 <= stamp.length <= target.length <= 1000
  2. \r\n\t
  3. stamp and target only contain lowercase letters.
  4. \r\n
", "content_cn": "

\u4f60\u60f3\u8981\u7528\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210\u4e00\u4e2a\u76ee\u6807\u5b57\u7b26\u4e32 target\u3002 

\n\n

\u5f00\u59cb\u7684\u65f6\u5019\uff0c\u5e8f\u5217\u7531 target.length \u4e2a '?' \u8bb0\u53f7\u7ec4\u6210\u3002\u800c\u4f60\u6709\u4e00\u4e2a\u5c0f\u5199\u5b57\u6bcd\u5370\u7ae0 stamp\u3002

\n\n

\u5728\u6bcf\u4e2a\u56de\u5408\uff0c\u4f60\u53ef\u4ee5\u5c06\u5370\u7ae0\u653e\u5728\u5e8f\u5217\u4e0a\uff0c\u5e76\u5c06\u5e8f\u5217\u4e2d\u7684\u6bcf\u4e2a\u5b57\u6bcd\u66ff\u6362\u4e3a\u5370\u7ae0\u4e0a\u7684\u76f8\u5e94\u5b57\u6bcd\u3002\u4f60\u6700\u591a\u53ef\u4ee5\u8fdb\u884c 10 * target.length  \u4e2a\u56de\u5408\u3002

\n\n

\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u5982\u679c\u521d\u59cb\u5e8f\u5217\u4e3a "?????"\uff0c\u800c\u4f60\u7684\u5370\u7ae0 stamp \u662f "abc"\uff0c\u90a3\u4e48\u5728\u7b2c\u4e00\u56de\u5408\uff0c\u4f60\u53ef\u4ee5\u5f97\u5230 "abc??"\u3001"?abc?"\u3001"??abc"\u3002\uff08\u8bf7\u6ce8\u610f\uff0c\u5370\u7ae0\u5fc5\u987b\u5b8c\u5168\u5305\u542b\u5728\u5e8f\u5217\u7684\u8fb9\u754c\u5185\u624d\u80fd\u76d6\u4e0b\u53bb\u3002\uff09

\n\n

\u5982\u679c\u53ef\u4ee5\u5370\u51fa\u5e8f\u5217\uff0c\u90a3\u4e48\u8fd4\u56de\u4e00\u4e2a\u6570\u7ec4\uff0c\u8be5\u6570\u7ec4\u7531\u6bcf\u4e2a\u56de\u5408\u4e2d\u88ab\u5370\u4e0b\u7684\u6700\u5de6\u8fb9\u5b57\u6bcd\u7684\u7d22\u5f15\u7ec4\u6210\u3002\u5982\u679c\u4e0d\u80fd\u5370\u51fa\u5e8f\u5217\uff0c\u5c31\u8fd4\u56de\u4e00\u4e2a\u7a7a\u6570\u7ec4\u3002

\n\n

\u4f8b\u5982\uff0c\u5982\u679c\u5e8f\u5217\u662f "ababc"\uff0c\u5370\u7ae0\u662f "abc"\uff0c\u90a3\u4e48\u6211\u4eec\u5c31\u53ef\u4ee5\u8fd4\u56de\u4e0e\u64cd\u4f5c "?????" -> "abc??" -> "ababc" \u76f8\u5bf9\u5e94\u7684\u7b54\u6848 [0, 2]\uff1b

\n\n

\u53e6\u5916\uff0c\u5982\u679c\u53ef\u4ee5\u5370\u51fa\u5e8f\u5217\uff0c\u90a3\u4e48\u9700\u8981\u4fdd\u8bc1\u53ef\u4ee5\u5728 10 * target.length \u4e2a\u56de\u5408\u5185\u5b8c\u6210\u3002\u4efb\u4f55\u8d85\u8fc7\u6b64\u6570\u5b57\u7684\u7b54\u6848\u5c06\u4e0d\u88ab\u63a5\u53d7\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1astamp = "abc", target = "ababc"\n\u8f93\u51fa\uff1a[0,2]\n\uff08[1,0,2] \u4ee5\u53ca\u5176\u4ed6\u4e00\u4e9b\u53ef\u80fd\u7684\u7ed3\u679c\u4e5f\u5c06\u4f5c\u4e3a\u7b54\u6848\u88ab\u63a5\u53d7\uff09\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1astamp = "abca", target = "aabcaca"\n\u8f93\u51fa\uff1a[3,0,1]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= stamp.length <= target.length <= 1000
  2. \n\t
  3. stamp \u548c target \u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd\u3002
  4. \n
\n", "tags_en": ["Greedy", "String"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector movesToStamp(string stamp, string target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] movesToStamp(String stamp, String target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def movesToStamp(self, stamp, target):\n \"\"\"\n :type stamp: str\n :type target: str\n :rtype: List[int]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def movesToStamp(self, stamp: str, target: str) -> List[int]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* movesToStamp(char * stamp, char * target, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] MovesToStamp(string stamp, string target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} stamp\n * @param {string} target\n * @return {number[]}\n */\nvar movesToStamp = function(stamp, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} stamp\n# @param {String} target\n# @return {Integer[]}\ndef moves_to_stamp(stamp, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func movesToStamp(_ stamp: String, _ target: String) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func movesToStamp(stamp string, target string) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def movesToStamp(stamp: String, target: String): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun movesToStamp(stamp: String, target: String): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn moves_to_stamp(stamp: String, target: String) -> Vec {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $stamp\n * @param String $target\n * @return Integer[]\n */\n function movesToStamp($stamp, $target) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function movesToStamp(stamp: string, target: string): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (moves-to-stamp stamp target)\n (-> string? string? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0936](https://leetcode-cn.com/problems/stamping-the-sequence)", "[\u6233\u5370\u5e8f\u5217](/solution/0900-0999/0936.Stamping%20The%20Sequence/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u5b57\u7b26\u4e32`", "\u56f0\u96be", ""], "md_table_row_en": ["[0936](https://leetcode.com/problems/stamping-the-sequence)", "[Stamping The Sequence](/solution/0900-0999/0936.Stamping%20The%20Sequence/README_EN.md)", "`Greedy`,`String`", "Hard", ""]}, {"question_id": "0972", "frontend_question_id": "0935", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/knight-dialer", "url_en": "https://leetcode.com/problems/knight-dialer", "relative_path_cn": "/solution/0900-0999/0935.Knight%20Dialer/README.md", "relative_path_en": "/solution/0900-0999/0935.Knight%20Dialer/README_EN.md", "title_cn": "\u9a91\u58eb\u62e8\u53f7\u5668", "title_en": "Knight Dialer", "question_title_slug": "knight-dialer", "content_en": "

The chess knight has a unique movement, it may move two squares vertically and one square horizontally, or two squares horizontally and one square vertically (with both forming the shape of an L). The possible movements of chess knight are shown in this diagaram:

\n\n

A chess knight can move as indicated in the chess diagram below:

\n\"\"\n

We have a chess knight and a phone pad as shown below, the knight can only stand on a numeric cell (i.e. blue cell).

\n\"\"\n

Given an integer n, return how many distinct phone numbers of length n we can dial.

\n\n

You are allowed to place the knight on any numeric cell initially and then you should perform n - 1 jumps to dial a number of length n. All jumps should be valid knight jumps.

\n\n

As the answer may be very large, return the answer modulo 109 + 7.

\n\n

 

\n

Example 1:

\n\n
\nInput: n = 1\nOutput: 10\nExplanation: We need to dial a number of length 1, so placing the knight over any numeric cell of the 10 cells is sufficient.\n
\n\n

Example 2:

\n\n
\nInput: n = 2\nOutput: 20\nExplanation: All the valid number we can dial are [04, 06, 16, 18, 27, 29, 34, 38, 40, 43, 49, 60, 61, 67, 72, 76, 81, 83, 92, 94]\n
\n\n

Example 3:

\n\n
\nInput: n = 3\nOutput: 46\n
\n\n

Example 4:

\n\n
\nInput: n = 4\nOutput: 104\n
\n\n

Example 5:

\n\n
\nInput: n = 3131\nOutput: 136006598\nExplanation: Please take care of the mod.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 5000
  • \n
\n", "content_cn": "

\u56fd\u9645\u8c61\u68cb\u4e2d\u7684\u9a91\u58eb\u53ef\u4ee5\u6309\u4e0b\u56fe\u6240\u793a\u8fdb\u884c\u79fb\u52a8\uff1a

\n\n

\"\" .           \"\"

\n\n


\n\u8fd9\u4e00\u6b21\uff0c\u6211\u4eec\u5c06 “\u9a91\u58eb” \u653e\u5728\u7535\u8bdd\u62e8\u53f7\u76d8\u7684\u4efb\u610f\u6570\u5b57\u952e\uff08\u5982\u4e0a\u56fe\u6240\u793a\uff09\u4e0a\uff0c\u63a5\u4e0b\u6765\uff0c\u9a91\u58eb\u5c06\u4f1a\u8df3 N-1 \u6b65\u3002\u6bcf\u4e00\u6b65\u5fc5\u987b\u662f\u4ece\u4e00\u4e2a\u6570\u5b57\u952e\u8df3\u5230\u53e6\u4e00\u4e2a\u6570\u5b57\u952e\u3002

\n\n

\u6bcf\u5f53\u5b83\u843d\u5728\u4e00\u4e2a\u952e\u4e0a\uff08\u5305\u62ec\u9a91\u58eb\u7684\u521d\u59cb\u4f4d\u7f6e\uff09\uff0c\u90fd\u4f1a\u62e8\u51fa\u952e\u6240\u5bf9\u5e94\u7684\u6570\u5b57\uff0c\u603b\u5171\u6309\u4e0b N \u4f4d\u6570\u5b57\u3002

\n\n

\u4f60\u80fd\u7528\u8fd9\u79cd\u65b9\u5f0f\u62e8\u51fa\u591a\u5c11\u4e2a\u4e0d\u540c\u7684\u53f7\u7801\uff1f

\n\n

\u56e0\u4e3a\u7b54\u6848\u53ef\u80fd\u5f88\u5927\uff0c\u6240\u4ee5\u8f93\u51fa\u7b54\u6848\u6a21 10^9 + 7\u3002

\n\n

 

\n\n
    \n
\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a1\n\u8f93\u51fa\uff1a10\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a2\n\u8f93\u51fa\uff1a20\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1a3\n\u8f93\u51fa\uff1a46\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= N <= 5000
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int knightDialer(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int knightDialer(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def knightDialer(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def knightDialer(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint knightDialer(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int KnightDialer(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar knightDialer = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef knight_dialer(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func knightDialer(_ n: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func knightDialer(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def knightDialer(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun knightDialer(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn knight_dialer(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function knightDialer($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function knightDialer(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (knight-dialer n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0935](https://leetcode-cn.com/problems/knight-dialer)", "[\u9a91\u58eb\u62e8\u53f7\u5668](/solution/0900-0999/0935.Knight%20Dialer/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0935](https://leetcode.com/problems/knight-dialer)", "[Knight Dialer](/solution/0900-0999/0935.Knight%20Dialer/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0971", "frontend_question_id": "0934", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/shortest-bridge", "url_en": "https://leetcode.com/problems/shortest-bridge", "relative_path_cn": "/solution/0900-0999/0934.Shortest%20Bridge/README.md", "relative_path_en": "/solution/0900-0999/0934.Shortest%20Bridge/README_EN.md", "title_cn": "\u6700\u77ed\u7684\u6865", "title_en": "Shortest Bridge", "question_title_slug": "shortest-bridge", "content_en": "

In a given 2D binary array grid, there are two islands.  (An island is a 4-directionally connected group of 1s not connected to any other 1s.)

\n\n

Now, we may change 0s to 1s so as to connect the two islands together to form 1 island.

\n\n

Return the smallest number of 0s that must be flipped.  (It is guaranteed that the answer is at least 1.)

\n\n

 

\n

Example 1:

\n\n
\nInput: grid = [[0,1],[1,0]]\nOutput: 1\n
\n\n

Example 2:

\n\n
\nInput: grid = [[0,1,0],[0,0,0],[0,0,1]]\nOutput: 2\n
\n\n

Example 3:

\n\n
\nInput: grid = [[1,1,1,1,1],[1,0,0,0,1],[1,0,1,0,1],[1,0,0,0,1],[1,1,1,1,1]]\nOutput: 1\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= grid.length == grid[0].length <= 100
  • \n\t
  • grid[i][j] == 0 or grid[i][j] == 1
  • \n
\n", "content_cn": "

\u5728\u7ed9\u5b9a\u7684\u4e8c\u7ef4\u4e8c\u8fdb\u5236\u6570\u7ec4\u00a0A\u00a0\u4e2d\uff0c\u5b58\u5728\u4e24\u5ea7\u5c9b\u3002\uff08\u5c9b\u662f\u7531\u56db\u9762\u76f8\u8fde\u7684 1 \u5f62\u6210\u7684\u4e00\u4e2a\u6700\u5927\u7ec4\u3002\uff09

\n\n

\u73b0\u5728\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u00a00\u00a0\u53d8\u4e3a\u00a01\uff0c\u4ee5\u4f7f\u4e24\u5ea7\u5c9b\u8fde\u63a5\u8d77\u6765\uff0c\u53d8\u6210\u4e00\u5ea7\u5c9b\u3002

\n\n

\u8fd4\u56de\u5fc5\u987b\u7ffb\u8f6c\u7684\u00a00 \u7684\u6700\u5c0f\u6570\u76ee\u3002\uff08\u53ef\u4ee5\u4fdd\u8bc1\u7b54\u6848\u81f3\u5c11\u662f 1 \u3002\uff09

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aA = [[0,1],[1,0]]\n\u8f93\u51fa\uff1a1\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aA = [[0,1,0],[0,0,0],[0,0,1]]\n\u8f93\u51fa\uff1a2\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1aA = [[1,1,1,1,1],[1,0,0,0,1],[1,0,1,0,1],[1,0,0,0,1],[1,1,1,1,1]]\n\u8f93\u51fa\uff1a1
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= A.length == A[0].length <= 100
  • \n\t
  • A[i][j] == 0 \u6216 A[i][j] == 1
  • \n
\n", "tags_en": ["Depth-first Search", "Breadth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int shortestBridge(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int shortestBridge(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def shortestBridge(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def shortestBridge(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint shortestBridge(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ShortestBridge(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar shortestBridge = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef shortest_bridge(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func shortestBridge(_ grid: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func shortestBridge(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def shortestBridge(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun shortestBridge(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn shortest_bridge(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function shortestBridge($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function shortestBridge(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (shortest-bridge grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0934](https://leetcode-cn.com/problems/shortest-bridge)", "[\u6700\u77ed\u7684\u6865](/solution/0900-0999/0934.Shortest%20Bridge/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0934](https://leetcode.com/problems/shortest-bridge)", "[Shortest Bridge](/solution/0900-0999/0934.Shortest%20Bridge/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`", "Medium", ""]}, {"question_id": "0969", "frontend_question_id": "0933", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-recent-calls", "url_en": "https://leetcode.com/problems/number-of-recent-calls", "relative_path_cn": "/solution/0900-0999/0933.Number%20of%20Recent%20Calls/README.md", "relative_path_en": "/solution/0900-0999/0933.Number%20of%20Recent%20Calls/README_EN.md", "title_cn": "\u6700\u8fd1\u7684\u8bf7\u6c42\u6b21\u6570", "title_en": "Number of Recent Calls", "question_title_slug": "number-of-recent-calls", "content_en": "

You have a RecentCounter class which counts the number of recent requests within a certain time frame.

\n\n

Implement the RecentCounter class:

\n\n
    \n\t
  • RecentCounter() Initializes the counter with zero recent requests.
  • \n\t
  • int ping(int t) Adds a new request at time t, where t represents some time in milliseconds, and returns the number of requests that has happened in the past 3000 milliseconds (including the new request). Specifically, return the number of requests that have happened in the inclusive range [t - 3000, t].
  • \n
\n\n

It is guaranteed that every call to ping uses a strictly larger value of t than the previous call.

\n\n

 

\n

Example 1:

\n\n
\nInput\n["RecentCounter", "ping", "ping", "ping", "ping"]\n[[], [1], [100], [3001], [3002]]\nOutput\n[null, 1, 2, 3, 3]\n\nExplanation\nRecentCounter recentCounter = new RecentCounter();\nrecentCounter.ping(1);     // requests = [1], range is [-2999,1], return 1\nrecentCounter.ping(100);   // requests = [1, 100], range is [-2900,100], return 2\nrecentCounter.ping(3001);  // requests = [1, 100, 3001], range is [1,3001], return 3\nrecentCounter.ping(3002);  // requests = [1, 100, 3001, 3002], range is [2,3002], return 3\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= t <= 109
  • \n\t
  • Each test case will call ping with strictly increasing values of t.
  • \n\t
  • At most 104 calls will be made to ping.
  • \n
\n", "content_cn": "

\u5199\u4e00\u4e2a\u00a0RecentCounter\u00a0\u7c7b\u6765\u8ba1\u7b97\u7279\u5b9a\u65f6\u95f4\u8303\u56f4\u5185\u6700\u8fd1\u7684\u8bf7\u6c42\u3002

\n\n

\u8bf7\u4f60\u5b9e\u73b0 RecentCounter \u7c7b\uff1a

\n\n
    \n\t
  • RecentCounter() \u521d\u59cb\u5316\u8ba1\u6570\u5668\uff0c\u8bf7\u6c42\u6570\u4e3a 0 \u3002
  • \n\t
  • int ping(int t) \u5728\u65f6\u95f4 t \u6dfb\u52a0\u4e00\u4e2a\u65b0\u8bf7\u6c42\uff0c\u5176\u4e2d t \u8868\u793a\u4ee5\u6beb\u79d2\u4e3a\u5355\u4f4d\u7684\u67d0\u4e2a\u65f6\u95f4\uff0c\u5e76\u8fd4\u56de\u8fc7\u53bb 3000 \u6beb\u79d2\u5185\u53d1\u751f\u7684\u6240\u6709\u8bf7\u6c42\u6570\uff08\u5305\u62ec\u65b0\u8bf7\u6c42\uff09\u3002\u786e\u5207\u5730\u8bf4\uff0c\u8fd4\u56de\u5728 [t-3000, t] \u5185\u53d1\u751f\u7684\u8bf7\u6c42\u6570\u3002
  • \n
\n\n

\u4fdd\u8bc1 \u6bcf\u6b21\u5bf9 ping \u7684\u8c03\u7528\u90fd\u4f7f\u7528\u6bd4\u4e4b\u524d\u66f4\u5927\u7684 t \u503c\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b\uff1a

\n\n
\n\u8f93\u5165\uff1a\n[\"RecentCounter\", \"ping\", \"ping\", \"ping\", \"ping\"]\n[[], [1], [100], [3001], [3002]]\n\u8f93\u51fa\uff1a\n[null, 1, 2, 3, 3]\n\n\u89e3\u91ca\uff1a\nRecentCounter recentCounter = new RecentCounter();\nrecentCounter.ping(1);     // requests = [1]\uff0c\u8303\u56f4\u662f [-2999,1]\uff0c\u8fd4\u56de 1\nrecentCounter.ping(100);   // requests = [1, 100]\uff0c\u8303\u56f4\u662f [-2900,100]\uff0c\u8fd4\u56de 2\nrecentCounter.ping(3001);  // requests = [1, 100, 3001]\uff0c\u8303\u56f4\u662f [1,3001]\uff0c\u8fd4\u56de 3\nrecentCounter.ping(3002);  // requests = [1, 100, 3001, 3002]\uff0c\u8303\u56f4\u662f [2,3002]\uff0c\u8fd4\u56de 3\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= t <= 109
  • \n\t
  • \u4fdd\u8bc1\u6bcf\u6b21\u5bf9 ping \u8c03\u7528\u6240\u4f7f\u7528\u7684 t \u503c\u90fd \u4e25\u683c\u9012\u589e
  • \n\t
  • \u81f3\u591a\u8c03\u7528 ping \u65b9\u6cd5 104 \u6b21
  • \n
\n", "tags_en": ["Queue"], "tags_cn": ["\u961f\u5217"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class RecentCounter {\npublic:\n RecentCounter() {\n\n }\n \n int ping(int t) {\n\n }\n};\n\n/**\n * Your RecentCounter object will be instantiated and called as such:\n * RecentCounter* obj = new RecentCounter();\n * int param_1 = obj->ping(t);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class RecentCounter {\n\n public RecentCounter() {\n\n }\n \n public int ping(int t) {\n\n }\n}\n\n/**\n * Your RecentCounter object will be instantiated and called as such:\n * RecentCounter obj = new RecentCounter();\n * int param_1 = obj.ping(t);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class RecentCounter(object):\n\n def __init__(self):\n\n\n def ping(self, t):\n \"\"\"\n :type t: int\n :rtype: int\n \"\"\"\n\n\n\n# Your RecentCounter object will be instantiated and called as such:\n# obj = RecentCounter()\n# param_1 = obj.ping(t)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class RecentCounter:\n\n def __init__(self):\n\n\n def ping(self, t: int) -> int:\n\n\n\n# Your RecentCounter object will be instantiated and called as such:\n# obj = RecentCounter()\n# param_1 = obj.ping(t)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} RecentCounter;\n\n\nRecentCounter* recentCounterCreate() {\n\n}\n\nint recentCounterPing(RecentCounter* obj, int t) {\n\n}\n\nvoid recentCounterFree(RecentCounter* obj) {\n\n}\n\n/**\n * Your RecentCounter struct will be instantiated and called as such:\n * RecentCounter* obj = recentCounterCreate();\n * int param_1 = recentCounterPing(obj, t);\n \n * recentCounterFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class RecentCounter {\n\n public RecentCounter() {\n\n }\n \n public int Ping(int t) {\n\n }\n}\n\n/**\n * Your RecentCounter object will be instantiated and called as such:\n * RecentCounter obj = new RecentCounter();\n * int param_1 = obj.Ping(t);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "\nvar RecentCounter = function() {\n\n};\n\n/** \n * @param {number} t\n * @return {number}\n */\nRecentCounter.prototype.ping = function(t) {\n\n};\n\n/**\n * Your RecentCounter object will be instantiated and called as such:\n * var obj = new RecentCounter()\n * var param_1 = obj.ping(t)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class RecentCounter\n def initialize()\n\n end\n\n\n=begin\n :type t: Integer\n :rtype: Integer\n=end\n def ping(t)\n\n end\n\n\nend\n\n# Your RecentCounter object will be instantiated and called as such:\n# obj = RecentCounter.new()\n# param_1 = obj.ping(t)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass RecentCounter {\n\n init() {\n \n }\n \n func ping(_ t: Int) -> Int {\n \n }\n}\n\n/**\n * Your RecentCounter object will be instantiated and called as such:\n * let obj = RecentCounter()\n * let ret_1: Int = obj.ping(t)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type RecentCounter struct {\n\n}\n\n\nfunc Constructor() RecentCounter {\n\n}\n\n\nfunc (this *RecentCounter) Ping(t int) int {\n\n}\n\n\n/**\n * Your RecentCounter object will be instantiated and called as such:\n * obj := Constructor();\n * param_1 := obj.Ping(t);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class RecentCounter() {\n\n def ping(t: Int): Int = {\n\n }\n\n}\n\n/**\n * Your RecentCounter object will be instantiated and called as such:\n * var obj = new RecentCounter()\n * var param_1 = obj.ping(t)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class RecentCounter() {\n\n fun ping(t: Int): Int {\n\n }\n\n}\n\n/**\n * Your RecentCounter object will be instantiated and called as such:\n * var obj = RecentCounter()\n * var param_1 = obj.ping(t)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct RecentCounter {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl RecentCounter {\n\n fn new() -> Self {\n\n }\n \n fn ping(&self, t: i32) -> i32 {\n\n }\n}\n\n/**\n * Your RecentCounter object will be instantiated and called as such:\n * let obj = RecentCounter::new();\n * let ret_1: i32 = obj.ping(t);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class RecentCounter {\n /**\n */\n function __construct() {\n\n }\n\n /**\n * @param Integer $t\n * @return Integer\n */\n function ping($t) {\n\n }\n}\n\n/**\n * Your RecentCounter object will be instantiated and called as such:\n * $obj = RecentCounter();\n * $ret_1 = $obj->ping($t);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class RecentCounter {\n constructor() {\n\n }\n\n ping(t: number): number {\n\n }\n}\n\n/**\n * Your RecentCounter object will be instantiated and called as such:\n * var obj = new RecentCounter()\n * var param_1 = obj.ping(t)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define recent-counter%\n (class object%\n (super-new)\n (init-field)\n \n ; ping : exact-integer? -> exact-integer?\n (define/public (ping t)\n\n )))\n\n;; Your recent-counter% object will be instantiated and called as such:\n;; (define obj (new recent-counter%))\n;; (define param_1 (send obj ping t))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0933](https://leetcode-cn.com/problems/number-of-recent-calls)", "[\u6700\u8fd1\u7684\u8bf7\u6c42\u6b21\u6570](/solution/0900-0999/0933.Number%20of%20Recent%20Calls/README.md)", "`\u961f\u5217`", "\u7b80\u5355", ""], "md_table_row_en": ["[0933](https://leetcode.com/problems/number-of-recent-calls)", "[Number of Recent Calls](/solution/0900-0999/0933.Number%20of%20Recent%20Calls/README_EN.md)", "`Queue`", "Easy", ""]}, {"question_id": "0968", "frontend_question_id": "0932", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/beautiful-array", "url_en": "https://leetcode.com/problems/beautiful-array", "relative_path_cn": "/solution/0900-0999/0932.Beautiful%20Array/README.md", "relative_path_en": "/solution/0900-0999/0932.Beautiful%20Array/README_EN.md", "title_cn": "\u6f02\u4eae\u6570\u7ec4", "title_en": "Beautiful Array", "question_title_slug": "beautiful-array", "content_en": "

For some fixed n, an array nums is beautiful if it is a permutation of the integers 1, 2, ..., n, such that:

\n\n

For every i < j, there is no k with i < k < j such that nums[k] * 2 = nums[i] + nums[j].

\n\n

Given n, return any beautiful array nums.  (It is guaranteed that one exists.)

\n\n

 

\n\n

Example 1:

\n\n
\nInput: n = 4\nOutput: [2,1,4,3]\n
\n\n
\n

Example 2:

\n\n
\nInput: n = 5\nOutput: [3,1,2,5,4]
\n\n

 

\n
\n\n

Note:

\n\n
    \n\t
  • 1 <= n <= 1000
  • \n
\n\n
\n
 
\n
\n", "content_cn": "

\u5bf9\u4e8e\u67d0\u4e9b\u56fa\u5b9a\u7684 N\uff0c\u5982\u679c\u6570\u7ec4 A \u662f\u6574\u6570 1, 2, ..., N \u7ec4\u6210\u7684\u6392\u5217\uff0c\u4f7f\u5f97\uff1a

\n\n

\u5bf9\u4e8e\u6bcf\u4e2a i < j\uff0c\u90fd\u4e0d\u5b58\u5728 k \u6ee1\u8db3 i < k < j \u4f7f\u5f97 A[k] * 2 = A[i] + A[j]\u3002

\n\n

\u90a3\u4e48\u6570\u7ec4 A \u662f\u6f02\u4eae\u6570\u7ec4\u3002

\n\n

 

\n\n

\u7ed9\u5b9a N\uff0c\u8fd4\u56de\u4efb\u610f\u6f02\u4eae\u6570\u7ec4 A\uff08\u4fdd\u8bc1\u5b58\u5728\u4e00\u4e2a\uff09\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a4\n\u8f93\u51fa\uff1a[2,1,4,3]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a5\n\u8f93\u51fa\uff1a[3,1,2,5,4]
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= N <= 1000
  • \n
\n\n

 

\n", "tags_en": ["Divide and Conquer"], "tags_cn": ["\u5206\u6cbb\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector beautifulArray(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] beautifulArray(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def beautifulArray(self, n):\n \"\"\"\n :type n: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def beautifulArray(self, n: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* beautifulArray(int n, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] BeautifulArray(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number[]}\n */\nvar beautifulArray = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer[]}\ndef beautiful_array(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func beautifulArray(_ n: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func beautifulArray(n int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def beautifulArray(n: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun beautifulArray(n: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn beautiful_array(n: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer[]\n */\n function beautifulArray($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function beautifulArray(n: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (beautiful-array n)\n (-> exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0932](https://leetcode-cn.com/problems/beautiful-array)", "[\u6f02\u4eae\u6570\u7ec4](/solution/0900-0999/0932.Beautiful%20Array/README.md)", "`\u5206\u6cbb\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0932](https://leetcode.com/problems/beautiful-array)", "[Beautiful Array](/solution/0900-0999/0932.Beautiful%20Array/README_EN.md)", "`Divide and Conquer`", "Medium", ""]}, {"question_id": "0967", "frontend_question_id": "0931", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-falling-path-sum", "url_en": "https://leetcode.com/problems/minimum-falling-path-sum", "relative_path_cn": "/solution/0900-0999/0931.Minimum%20Falling%20Path%20Sum/README.md", "relative_path_en": "/solution/0900-0999/0931.Minimum%20Falling%20Path%20Sum/README_EN.md", "title_cn": "\u4e0b\u964d\u8def\u5f84\u6700\u5c0f\u548c", "title_en": "Minimum Falling Path Sum", "question_title_slug": "minimum-falling-path-sum", "content_en": "

Given an n x n array of integers matrix, return the minimum sum of any falling path through matrix.

\n\n

A falling path starts at any element in the first row and chooses the element in the next row that is either directly below or diagonally left/right. Specifically, the next element from position (row, col) will be (row + 1, col - 1), (row + 1, col), or (row + 1, col + 1).

\n\n

 

\n

Example 1:

\n\n
\nInput: matrix = [[2,1,3],[6,5,4],[7,8,9]]\nOutput: 13\nExplanation: There are two falling paths with a minimum sum underlined below:\n[[2,1,3],      [[2,1,3],\n [6,5,4],       [6,5,4],\n [7,8,9]]       [7,8,9]]\n
\n\n

Example 2:

\n\n
\nInput: matrix = [[-19,57],[-40,-5]]\nOutput: -59\nExplanation: The falling path with a minimum sum is underlined below:\n[[-19,57],\n [-40,-5]]\n
\n\n

Example 3:

\n\n
\nInput: matrix = [[-48]]\nOutput: -48\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == matrix.length
  • \n\t
  • n == matrix[i].length
  • \n\t
  • 1 <= n <= 100
  • \n\t
  • -100 <= matrix[i][j] <= 100
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a n x n \u7684 \u65b9\u5f62 \u6574\u6570\u6570\u7ec4\u00a0matrix \uff0c\u8bf7\u4f60\u627e\u51fa\u5e76\u8fd4\u56de\u901a\u8fc7 matrix \u7684\u4e0b\u964d\u8def\u5f84 \u7684 \u6700\u5c0f\u548c \u3002

\n\n

\u4e0b\u964d\u8def\u5f84 \u53ef\u4ee5\u4ece\u7b2c\u4e00\u884c\u4e2d\u7684\u4efb\u4f55\u5143\u7d20\u5f00\u59cb\uff0c\u5e76\u4ece\u6bcf\u4e00\u884c\u4e2d\u9009\u62e9\u4e00\u4e2a\u5143\u7d20\u3002\u5728\u4e0b\u4e00\u884c\u9009\u62e9\u7684\u5143\u7d20\u548c\u5f53\u524d\u884c\u6240\u9009\u5143\u7d20\u6700\u591a\u76f8\u9694\u4e00\u5217\uff08\u5373\u4f4d\u4e8e\u6b63\u4e0b\u65b9\u6216\u8005\u6cbf\u5bf9\u89d2\u7ebf\u5411\u5de6\u6216\u8005\u5411\u53f3\u7684\u7b2c\u4e00\u4e2a\u5143\u7d20\uff09\u3002\u5177\u4f53\u6765\u8bf4\uff0c\u4f4d\u7f6e (row, col) \u7684\u4e0b\u4e00\u4e2a\u5143\u7d20\u5e94\u5f53\u662f (row + 1, col - 1)\u3001(row + 1, col) \u6216\u8005 (row + 1, col + 1) \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1amatrix = [[2,1,3],[6,5,4],[7,8,9]]\n\u8f93\u51fa\uff1a13\n\u89e3\u91ca\uff1a\u4e0b\u9762\u662f\u4e24\u6761\u548c\u6700\u5c0f\u7684\u4e0b\u964d\u8def\u5f84\uff0c\u7528\u52a0\u7c97\u6807\u6ce8\uff1a\n[[2,1,3],      [[2,1,3],\n [6,5,4],       [6,5,4],\n [7,8,9]]       [7,8,9]]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1amatrix = [[-19,57],[-40,-5]]\n\u8f93\u51fa\uff1a-59\n\u89e3\u91ca\uff1a\u4e0b\u9762\u662f\u4e00\u6761\u548c\u6700\u5c0f\u7684\u4e0b\u964d\u8def\u5f84\uff0c\u7528\u52a0\u7c97\u6807\u6ce8\uff1a\n[[-19,57],\n [-40,-5]]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1amatrix = [[-48]]\n\u8f93\u51fa\uff1a-48\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • n == matrix.length
  • \n\t
  • n == matrix[i].length
  • \n\t
  • 1 <= n <= 100
  • \n\t
  • -100 <= matrix[i][j] <= 100
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minFallingPathSum(vector>& matrix) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minFallingPathSum(int[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minFallingPathSum(self, matrix):\n \"\"\"\n :type matrix: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minFallingPathSum(self, matrix: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minFallingPathSum(int** matrix, int matrixSize, int* matrixColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinFallingPathSum(int[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} matrix\n * @return {number}\n */\nvar minFallingPathSum = function(matrix) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} matrix\n# @return {Integer}\ndef min_falling_path_sum(matrix)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minFallingPathSum(_ matrix: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minFallingPathSum(matrix [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minFallingPathSum(matrix: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minFallingPathSum(matrix: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_falling_path_sum(matrix: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $matrix\n * @return Integer\n */\n function minFallingPathSum($matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minFallingPathSum(matrix: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-falling-path-sum matrix)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0931](https://leetcode-cn.com/problems/minimum-falling-path-sum)", "[\u4e0b\u964d\u8def\u5f84\u6700\u5c0f\u548c](/solution/0900-0999/0931.Minimum%20Falling%20Path%20Sum/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0931](https://leetcode.com/problems/minimum-falling-path-sum)", "[Minimum Falling Path Sum](/solution/0900-0999/0931.Minimum%20Falling%20Path%20Sum/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0966", "frontend_question_id": "0930", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/binary-subarrays-with-sum", "url_en": "https://leetcode.com/problems/binary-subarrays-with-sum", "relative_path_cn": "/solution/0900-0999/0930.Binary%20Subarrays%20With%20Sum/README.md", "relative_path_en": "/solution/0900-0999/0930.Binary%20Subarrays%20With%20Sum/README_EN.md", "title_cn": "\u548c\u76f8\u540c\u7684\u4e8c\u5143\u5b50\u6570\u7ec4", "title_en": "Binary Subarrays With Sum", "question_title_slug": "binary-subarrays-with-sum", "content_en": "

Given a binary array nums and an integer goal, return the number of non-empty subarrays with a sum goal.

\n\n

A subarray is a contiguous part of the array.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [1,0,1,0,1], goal = 2\nOutput: 4\nExplanation: The 4 subarrays are bolded and underlined below:\n[1,0,1,0,1]\n[1,0,1,0,1]\n[1,0,1,0,1]\n[1,0,1,0,1]\n
\n\n

Example 2:

\n\n
\nInput: nums = [0,0,0,0,0], goal = 0\nOutput: 15\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 3 * 104
  • \n\t
  • nums[i] is either 0 or 1.
  • \n\t
  • 0 <= goal <= nums.length
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u4e8c\u5143\u6570\u7ec4 nums \uff0c\u548c\u4e00\u4e2a\u6574\u6570 goal \uff0c\u8bf7\u4f60\u7edf\u8ba1\u5e76\u6709\u591a\u5c11\u4e2a\u548c\u4e3a goal \u7684 \u975e\u7a7a \u5b50\u6570\u7ec4\u3002

\n\n

\u5b50\u6570\u7ec4 \u662f\u6570\u7ec4\u7684\u4e00\u6bb5\u8fde\u7eed\u90e8\u5206\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [1,0,1,0,1], goal = 2\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\n\u5982\u4e0b\u9762\u9ed1\u4f53\u6240\u793a\uff0c\u6709 4 \u4e2a\u6ee1\u8db3\u9898\u76ee\u8981\u6c42\u7684\u5b50\u6570\u7ec4\uff1a\n[1,0,1,0,1]\n[1,0,1,0,1]\n[1,0,1,0,1]\n[1,0,1,0,1]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [0,0,0,0,0], goal = 0\n\u8f93\u51fa\uff1a15\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= nums.length <= 3 * 104
  • \n\t
  • nums[i] \u4e0d\u662f 0 \u5c31\u662f 1
  • \n\t
  • 0 <= goal <= nums.length
  • \n
\n", "tags_en": ["Hash Table", "Two Pointers"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numSubarraysWithSum(vector& nums, int goal) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numSubarraysWithSum(int[] nums, int goal) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numSubarraysWithSum(self, nums, goal):\n \"\"\"\n :type nums: List[int]\n :type goal: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numSubarraysWithSum(self, nums: List[int], goal: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numSubarraysWithSum(int* nums, int numsSize, int goal){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumSubarraysWithSum(int[] nums, int goal) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} goal\n * @return {number}\n */\nvar numSubarraysWithSum = function(nums, goal) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} goal\n# @return {Integer}\ndef num_subarrays_with_sum(nums, goal)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numSubarraysWithSum(_ nums: [Int], _ goal: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numSubarraysWithSum(nums []int, goal int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numSubarraysWithSum(nums: Array[Int], goal: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numSubarraysWithSum(nums: IntArray, goal: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_subarrays_with_sum(nums: Vec, goal: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $goal\n * @return Integer\n */\n function numSubarraysWithSum($nums, $goal) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numSubarraysWithSum(nums: number[], goal: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-subarrays-with-sum nums goal)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0930](https://leetcode-cn.com/problems/binary-subarrays-with-sum)", "[\u548c\u76f8\u540c\u7684\u4e8c\u5143\u5b50\u6570\u7ec4](/solution/0900-0999/0930.Binary%20Subarrays%20With%20Sum/README.md)", "`\u54c8\u5e0c\u8868`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0930](https://leetcode.com/problems/binary-subarrays-with-sum)", "[Binary Subarrays With Sum](/solution/0900-0999/0930.Binary%20Subarrays%20With%20Sum/README_EN.md)", "`Hash Table`,`Two Pointers`", "Medium", ""]}, {"question_id": "0965", "frontend_question_id": "0929", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/unique-email-addresses", "url_en": "https://leetcode.com/problems/unique-email-addresses", "relative_path_cn": "/solution/0900-0999/0929.Unique%20Email%20Addresses/README.md", "relative_path_en": "/solution/0900-0999/0929.Unique%20Email%20Addresses/README_EN.md", "title_cn": "\u72ec\u7279\u7684\u7535\u5b50\u90ae\u4ef6\u5730\u5740", "title_en": "Unique Email Addresses", "question_title_slug": "unique-email-addresses", "content_en": "

Every valid email consists of a local name and a domain name, separated by the '@' sign. Besides lowercase letters, the email may contain one or more '.' or '+'.

\n\n
    \n\t
  • For example, in "alice@leetcode.com", "alice" is the local name, and "leetcode.com" is the domain name.
  • \n
\n\n

If you add periods '.' between some characters in the local name part of an email address, mail sent there will be forwarded to the same address without dots in the local name. Note that this rule does not apply to domain names.

\n\n
    \n\t
  • For example, "alice.z@leetcode.com" and "alicez@leetcode.com" forward to the same email address.
  • \n
\n\n

If you add a plus '+' in the local name, everything after the first plus sign will be ignored. This allows certain emails to be filtered. Note that this rule does not apply to domain names.

\n\n
    \n\t
  • For example, "m.y+name@email.com" will be forwarded to "my@email.com".
  • \n
\n\n

It is possible to use both of these rules at the same time.

\n\n

Given an array of strings emails where we send one email to each email[i], return the number of different addresses that actually receive mails.

\n\n

 

\n

Example 1:

\n\n
\nInput: emails = ["test.email+alex@leetcode.com","test.e.mail+bob.cathy@leetcode.com","testemail+david@lee.tcode.com"]\nOutput: 2\nExplanation: "testemail@leetcode.com" and "testemail@lee.tcode.com" actually receive mails.\n
\n\n

Example 2:

\n\n
\nInput: emails = ["a@leetcode.com","b@leetcode.com","c@leetcode.com"]\nOutput: 3\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= emails.length <= 100
  • \n\t
  • 1 <= emails[i].length <= 100
  • \n\t
  • email[i] consist of lowercase English letters, '+', '.' and '@'.
  • \n\t
  • Each emails[i] contains exactly one '@' character.
  • \n\t
  • All local and domain names are non-empty.
  • \n\t
  • Local names do not start with a '+' character.
  • \n
\n", "content_cn": "

\u6bcf\u5c01\u7535\u5b50\u90ae\u4ef6\u90fd\u7531\u4e00\u4e2a\u672c\u5730\u540d\u79f0\u548c\u4e00\u4e2a\u57df\u540d\u7ec4\u6210\uff0c\u4ee5 @ \u7b26\u53f7\u5206\u9694\u3002

\n\n

\u4f8b\u5982\uff0c\u5728 alice@leetcode.com\u4e2d\uff0c alice \u662f\u672c\u5730\u540d\u79f0\uff0c\u800c leetcode.com \u662f\u57df\u540d\u3002

\n\n

\u9664\u4e86\u5c0f\u5199\u5b57\u6bcd\uff0c\u8fd9\u4e9b\u7535\u5b50\u90ae\u4ef6\u8fd8\u53ef\u80fd\u5305\u542b '.' \u6216 '+'\u3002

\n\n

\u5982\u679c\u5728\u7535\u5b50\u90ae\u4ef6\u5730\u5740\u7684\u672c\u5730\u540d\u79f0\u90e8\u5206\u4e2d\u7684\u67d0\u4e9b\u5b57\u7b26\u4e4b\u95f4\u6dfb\u52a0\u53e5\u70b9\uff08'.'\uff09\uff0c\u5219\u53d1\u5f80\u90a3\u91cc\u7684\u90ae\u4ef6\u5c06\u4f1a\u8f6c\u53d1\u5230\u672c\u5730\u540d\u79f0\u4e2d\u6ca1\u6709\u70b9\u7684\u540c\u4e00\u5730\u5740\u3002\u4f8b\u5982\uff0c"alice.z@leetcode.com” \u548c “alicez@leetcode.com” \u4f1a\u8f6c\u53d1\u5230\u540c\u4e00\u7535\u5b50\u90ae\u4ef6\u5730\u5740\u3002 \uff08\u8bf7\u6ce8\u610f\uff0c\u6b64\u89c4\u5219\u4e0d\u9002\u7528\u4e8e\u57df\u540d\u3002\uff09

\n\n

\u5982\u679c\u5728\u672c\u5730\u540d\u79f0\u4e2d\u6dfb\u52a0\u52a0\u53f7\uff08'+'\uff09\uff0c\u5219\u4f1a\u5ffd\u7565\u7b2c\u4e00\u4e2a\u52a0\u53f7\u540e\u9762\u7684\u6240\u6709\u5185\u5bb9\u3002\u8fd9\u5141\u8bb8\u8fc7\u6ee4\u67d0\u4e9b\u7535\u5b50\u90ae\u4ef6\uff0c\u4f8b\u5982 m.y+name@email.com \u5c06\u8f6c\u53d1\u5230 my@email.com\u3002 \uff08\u540c\u6837\uff0c\u6b64\u89c4\u5219\u4e0d\u9002\u7528\u4e8e\u57df\u540d\u3002\uff09

\n\n

\u53ef\u4ee5\u540c\u65f6\u4f7f\u7528\u8fd9\u4e24\u4e2a\u89c4\u5219\u3002

\n\n

\u7ed9\u5b9a\u7535\u5b50\u90ae\u4ef6\u5217\u8868 emails\uff0c\u6211\u4eec\u4f1a\u5411\u5217\u8868\u4e2d\u7684\u6bcf\u4e2a\u5730\u5740\u53d1\u9001\u4e00\u5c01\u7535\u5b50\u90ae\u4ef6\u3002\u5b9e\u9645\u6536\u5230\u90ae\u4ef6\u7684\u4e0d\u540c\u5730\u5740\u6709\u591a\u5c11\uff1f

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1a["test.email+alex@leetcode.com","test.e.mail+bob.cathy@leetcode.com","testemail+david@lee.tcode.com"]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5b9e\u9645\u6536\u5230\u90ae\u4ef6\u7684\u662f "testemail@leetcode.com" \u548c "testemail@lee.tcode.com"\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= emails[i].length <= 100
  • \n\t
  • 1 <= emails.length <= 100
  • \n\t
  • \u6bcf\u5c01 emails[i] \u90fd\u5305\u542b\u6709\u4e14\u4ec5\u6709\u4e00\u4e2a '@' \u5b57\u7b26\u3002
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numUniqueEmails(vector& emails) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numUniqueEmails(String[] emails) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numUniqueEmails(self, emails):\n \"\"\"\n :type emails: List[str]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numUniqueEmails(self, emails: List[str]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numUniqueEmails(char ** emails, int emailsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumUniqueEmails(string[] emails) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} emails\n * @return {number}\n */\nvar numUniqueEmails = function(emails) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} emails\n# @return {Integer}\ndef num_unique_emails(emails)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numUniqueEmails(_ emails: [String]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numUniqueEmails(emails []string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numUniqueEmails(emails: Array[String]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numUniqueEmails(emails: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_unique_emails(emails: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $emails\n * @return Integer\n */\n function numUniqueEmails($emails) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numUniqueEmails(emails: string[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-unique-emails emails)\n (-> (listof string?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0929](https://leetcode-cn.com/problems/unique-email-addresses)", "[\u72ec\u7279\u7684\u7535\u5b50\u90ae\u4ef6\u5730\u5740](/solution/0900-0999/0929.Unique%20Email%20Addresses/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0929](https://leetcode.com/problems/unique-email-addresses)", "[Unique Email Addresses](/solution/0900-0999/0929.Unique%20Email%20Addresses/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "0964", "frontend_question_id": "0928", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimize-malware-spread-ii", "url_en": "https://leetcode.com/problems/minimize-malware-spread-ii", "relative_path_cn": "/solution/0900-0999/0928.Minimize%20Malware%20Spread%20II/README.md", "relative_path_en": "/solution/0900-0999/0928.Minimize%20Malware%20Spread%20II/README_EN.md", "title_cn": "\u5c3d\u91cf\u51cf\u5c11\u6076\u610f\u8f6f\u4ef6\u7684\u4f20\u64ad II", "title_en": "Minimize Malware Spread II", "question_title_slug": "minimize-malware-spread-ii", "content_en": "

You are given a network of n nodes represented as an n x n adjacency matrix graph, where the ith node is directly connected to the jth node if graph[i][j] == 1.

\n\n

Some nodes initial are initially infected by malware. Whenever two nodes are directly connected, and at least one of those two nodes is infected by malware, both nodes will be infected by malware. This spread of malware will continue until no more nodes can be infected in this manner.

\n\n

Suppose M(initial) is the final number of nodes infected with malware in the entire network after the spread of malware stops.

\n\n

We will remove exactly one node from initial, completely removing it and any connections from this node to any other node.

\n\n

Return the node that, if removed, would minimize M(initial). If multiple nodes could be removed to minimize M(initial), return such a node with the smallest index.

\n\n

 

\n

Example 1:

\n
Input: graph = [[1,1,0],[1,1,0],[0,0,1]], initial = [0,1]\nOutput: 0\n

Example 2:

\n
Input: graph = [[1,1,0],[1,1,1],[0,1,1]], initial = [0,1]\nOutput: 1\n

Example 3:

\n
Input: graph = [[1,1,0,0],[1,1,1,0],[0,1,1,1],[0,0,1,1]], initial = [0,1]\nOutput: 1\n
\n

 

\n

Constraints:

\n\n
    \n\t
  • n == graph.length
  • \n\t
  • n == graph[i].length
  • \n\t
  • 2 <= n <= 300
  • \n\t
  • graph[i][j] is 0 or 1.
  • \n\t
  • graph[i][j] == graph[j][i]
  • \n\t
  • graph[i][i] == 1
  • \n\t
  • 1 <= initial.length < n
  • \n\t
  • 0 <= initial[i] <= n - 1
  • \n\t
  • All the integers in initial are unique.
  • \n
\n", "content_cn": "

(\u8fd9\u4e2a\u95ee\u9898\u4e0e \u5c3d\u91cf\u51cf\u5c11\u6076\u610f\u8f6f\u4ef6\u7684\u4f20\u64ad \u662f\u4e00\u6837\u7684\uff0c\u4e0d\u540c\u4e4b\u5904\u7528\u7c97\u4f53\u8868\u793a\u3002)

\n\n

\u5728\u8282\u70b9\u7f51\u7edc\u4e2d\uff0c\u53ea\u6709\u5f53 graph[i][j] = 1 \u65f6\uff0c\u6bcf\u4e2a\u8282\u70b9 i \u80fd\u591f\u76f4\u63a5\u8fde\u63a5\u5230\u53e6\u4e00\u4e2a\u8282\u70b9 j\u3002

\n\n

\u4e00\u4e9b\u8282\u70b9 initial \u6700\u521d\u88ab\u6076\u610f\u8f6f\u4ef6\u611f\u67d3\u3002\u53ea\u8981\u4e24\u4e2a\u8282\u70b9\u76f4\u63a5\u8fde\u63a5\uff0c\u4e14\u5176\u4e2d\u81f3\u5c11\u4e00\u4e2a\u8282\u70b9\u53d7\u5230\u6076\u610f\u8f6f\u4ef6\u7684\u611f\u67d3\uff0c\u90a3\u4e48\u4e24\u4e2a\u8282\u70b9\u90fd\u5c06\u88ab\u6076\u610f\u8f6f\u4ef6\u611f\u67d3\u3002\u8fd9\u79cd\u6076\u610f\u8f6f\u4ef6\u7684\u4f20\u64ad\u5c06\u7ee7\u7eed\uff0c\u76f4\u5230\u6ca1\u6709\u66f4\u591a\u7684\u8282\u70b9\u53ef\u4ee5\u88ab\u8fd9\u79cd\u65b9\u5f0f\u611f\u67d3\u3002

\n\n

\u5047\u8bbe M(initial) \u662f\u5728\u6076\u610f\u8f6f\u4ef6\u505c\u6b62\u4f20\u64ad\u4e4b\u540e\uff0c\u6574\u4e2a\u7f51\u7edc\u4e2d\u611f\u67d3\u6076\u610f\u8f6f\u4ef6\u7684\u6700\u7ec8\u8282\u70b9\u6570\u3002

\n\n

\u6211\u4eec\u53ef\u4ee5\u4ece\u521d\u59cb\u5217\u8868\u4e2d\u5220\u9664\u4e00\u4e2a\u8282\u70b9\uff0c\u5e76\u5b8c\u5168\u79fb\u9664\u8be5\u8282\u70b9\u4ee5\u53ca\u4ece\u8be5\u8282\u70b9\u5230\u4efb\u4f55\u5176\u4ed6\u8282\u70b9\u7684\u4efb\u4f55\u8fde\u63a5\u3002\u5982\u679c\u79fb\u9664\u8fd9\u4e00\u8282\u70b9\u5c06\u6700\u5c0f\u5316 M(initial)\uff0c \u5219\u8fd4\u56de\u8be5\u8282\u70b9\u3002\u5982\u679c\u6709\u591a\u4e2a\u8282\u70b9\u6ee1\u8db3\u6761\u4ef6\uff0c\u5c31\u8fd4\u56de\u7d22\u5f15\u6700\u5c0f\u7684\u8282\u70b9\u3002

\n\n

 

\n\n
    \n
\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u51fa\uff1agraph = [[1,1,0],[1,1,0],[0,0,1]], initial = [0,1]\n\u8f93\u5165\uff1a0\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1agraph = [[1,1,0],[1,1,1],[0,1,1]], initial = [0,1]\n\u8f93\u51fa\uff1a1\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1agraph = [[1,1,0,0],[1,1,1,0],[0,1,1,1],[0,0,1,1]], initial = [0,1]\n\u8f93\u51fa\uff1a1\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 < graph.length = graph[0].length <= 300
  2. \n\t
  3. 0 <= graph[i][j] == graph[j][i] <= 1
  4. \n\t
  5. graph[i][i] = 1
  6. \n\t
  7. 1 <= initial.length < graph.length
  8. \n\t
  9. 0 <= initial[i] < graph.length
  10. \n
\n", "tags_en": ["Depth-first Search", "Union Find", "Graph"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e76\u67e5\u96c6", "\u56fe"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minMalwareSpread(vector>& graph, vector& initial) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minMalwareSpread(int[][] graph, int[] initial) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minMalwareSpread(self, graph, initial):\n \"\"\"\n :type graph: List[List[int]]\n :type initial: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minMalwareSpread(self, graph: List[List[int]], initial: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minMalwareSpread(int** graph, int graphSize, int* graphColSize, int* initial, int initialSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinMalwareSpread(int[][] graph, int[] initial) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} graph\n * @param {number[]} initial\n * @return {number}\n */\nvar minMalwareSpread = function(graph, initial) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} graph\n# @param {Integer[]} initial\n# @return {Integer}\ndef min_malware_spread(graph, initial)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minMalwareSpread(_ graph: [[Int]], _ initial: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minMalwareSpread(graph [][]int, initial []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minMalwareSpread(graph: Array[Array[Int]], initial: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minMalwareSpread(graph: Array, initial: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_malware_spread(graph: Vec>, initial: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $graph\n * @param Integer[] $initial\n * @return Integer\n */\n function minMalwareSpread($graph, $initial) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minMalwareSpread(graph: number[][], initial: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-malware-spread graph initial)\n (-> (listof (listof exact-integer?)) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0928](https://leetcode-cn.com/problems/minimize-malware-spread-ii)", "[\u5c3d\u91cf\u51cf\u5c11\u6076\u610f\u8f6f\u4ef6\u7684\u4f20\u64ad II](/solution/0900-0999/0928.Minimize%20Malware%20Spread%20II/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e76\u67e5\u96c6`,`\u56fe`", "\u56f0\u96be", ""], "md_table_row_en": ["[0928](https://leetcode.com/problems/minimize-malware-spread-ii)", "[Minimize Malware Spread II](/solution/0900-0999/0928.Minimize%20Malware%20Spread%20II/README_EN.md)", "`Depth-first Search`,`Union Find`,`Graph`", "Hard", ""]}, {"question_id": "0963", "frontend_question_id": "0927", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/three-equal-parts", "url_en": "https://leetcode.com/problems/three-equal-parts", "relative_path_cn": "/solution/0900-0999/0927.Three%20Equal%20Parts/README.md", "relative_path_en": "/solution/0900-0999/0927.Three%20Equal%20Parts/README_EN.md", "title_cn": "\u4e09\u7b49\u5206", "title_en": "Three Equal Parts", "question_title_slug": "three-equal-parts", "content_en": "

You are given an array arr which consists of only zeros and ones, divide the array into three non-empty parts such that all of these parts represent the same binary value.

\n\n

If it is possible, return any [i, j] with i + 1 < j, such that:

\n\n
    \n\t
  • arr[0], arr[1], ..., arr[i] is the first part,
  • \n\t
  • arr[i + 1], arr[i + 2], ..., arr[j - 1] is the second part, and
  • \n\t
  • arr[j], arr[j + 1], ..., arr[arr.length - 1] is the third part.
  • \n\t
  • All three parts have equal binary values.
  • \n
\n\n

If it is not possible, return [-1, -1].

\n\n

Note that the entire part is used when considering what binary value it represents. For example, [1,1,0] represents 6 in decimal, not 3. Also, leading zeros are allowed, so [0,1,1] and [1,1] represent the same value.

\n\n

 

\n

Example 1:

\n
Input: arr = [1,0,1,0,1]\nOutput: [0,3]\n

Example 2:

\n
Input: arr = [1,1,0,1,1]\nOutput: [-1,-1]\n

Example 3:

\n
Input: arr = [1,1,0,0,1]\nOutput: [0,2]\n
\n

 

\n

Constraints:

\n\n
    \n\t
  • 3 <= arr.length <= 3 * 104
  • \n\t
  • arr[i] is 0 or 1
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u7531 0 \u548c 1 \u7ec4\u6210\u7684\u6570\u7ec4 A\uff0c\u5c06\u6570\u7ec4\u5206\u6210 3 \u4e2a\u975e\u7a7a\u7684\u90e8\u5206\uff0c\u4f7f\u5f97\u6240\u6709\u8fd9\u4e9b\u90e8\u5206\u8868\u793a\u76f8\u540c\u7684\u4e8c\u8fdb\u5236\u503c\u3002

\n\n

\u5982\u679c\u53ef\u4ee5\u505a\u5230\uff0c\u8bf7\u8fd4\u56de\u4efb\u4f55 [i, j]\uff0c\u5176\u4e2d i+1 < j\uff0c\u8fd9\u6837\u4e00\u6765\uff1a

\n\n
    \n\t
  • A[0], A[1], ..., A[i] \u7ec4\u6210\u7b2c\u4e00\u90e8\u5206\uff1b
  • \n\t
  • A[i+1], A[i+2], ..., A[j-1] \u4f5c\u4e3a\u7b2c\u4e8c\u90e8\u5206\uff1b
  • \n\t
  • A[j], A[j+1], ..., A[A.length - 1] \u662f\u7b2c\u4e09\u90e8\u5206\u3002
  • \n\t
  • \u8fd9\u4e09\u4e2a\u90e8\u5206\u6240\u8868\u793a\u7684\u4e8c\u8fdb\u5236\u503c\u76f8\u7b49\u3002
  • \n
\n\n

\u5982\u679c\u65e0\u6cd5\u505a\u5230\uff0c\u5c31\u8fd4\u56de [-1, -1]\u3002

\n\n

\u6ce8\u610f\uff0c\u5728\u8003\u8651\u6bcf\u4e2a\u90e8\u5206\u6240\u8868\u793a\u7684\u4e8c\u8fdb\u5236\u65f6\uff0c\u5e94\u5f53\u5c06\u5176\u770b\u4f5c\u4e00\u4e2a\u6574\u4f53\u3002\u4f8b\u5982\uff0c[1,1,0] \u8868\u793a\u5341\u8fdb\u5236\u4e2d\u7684 6\uff0c\u800c\u4e0d\u4f1a\u662f 3\u3002\u6b64\u5916\uff0c\u524d\u5bfc\u96f6\u4e5f\u662f\u88ab\u5141\u8bb8\u7684\uff0c\u6240\u4ee5 [0,1,1] \u548c [1,1] \u8868\u793a\u76f8\u540c\u7684\u503c\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a[1,0,1,0,1]\n\u8f93\u51fa\uff1a[0,3]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u51fa\uff1a[1,1,0,1,1]\n\u8f93\u51fa\uff1a[-1,-1]
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 3 <= A.length <= 30000
  2. \n\t
  3. A[i] == 0 \u6216 A[i] == 1
  4. \n
\n\n

 

\n", "tags_en": ["Greedy", "Math", "Binary Search"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u5b66", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector threeEqualParts(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] threeEqualParts(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def threeEqualParts(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def threeEqualParts(self, arr: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* threeEqualParts(int* arr, int arrSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] ThreeEqualParts(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number[]}\n */\nvar threeEqualParts = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer[]}\ndef three_equal_parts(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func threeEqualParts(_ arr: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func threeEqualParts(arr []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def threeEqualParts(arr: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun threeEqualParts(arr: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn three_equal_parts(arr: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer[]\n */\n function threeEqualParts($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function threeEqualParts(arr: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (three-equal-parts arr)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0927](https://leetcode-cn.com/problems/three-equal-parts)", "[\u4e09\u7b49\u5206](/solution/0900-0999/0927.Three%20Equal%20Parts/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u5b66`,`\u4e8c\u5206\u67e5\u627e`", "\u56f0\u96be", ""], "md_table_row_en": ["[0927](https://leetcode.com/problems/three-equal-parts)", "[Three Equal Parts](/solution/0900-0999/0927.Three%20Equal%20Parts/README_EN.md)", "`Greedy`,`Math`,`Binary Search`", "Hard", ""]}, {"question_id": "0962", "frontend_question_id": "0926", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/flip-string-to-monotone-increasing", "url_en": "https://leetcode.com/problems/flip-string-to-monotone-increasing", "relative_path_cn": "/solution/0900-0999/0926.Flip%20String%20to%20Monotone%20Increasing/README.md", "relative_path_en": "/solution/0900-0999/0926.Flip%20String%20to%20Monotone%20Increasing/README_EN.md", "title_cn": "\u5c06\u5b57\u7b26\u4e32\u7ffb\u8f6c\u5230\u5355\u8c03\u9012\u589e", "title_en": "Flip String to Monotone Increasing", "question_title_slug": "flip-string-to-monotone-increasing", "content_en": "

A string of '0's and '1's is monotone increasing if it consists of some number of '0's (possibly 0), followed by some number of '1's (also possibly 0.)

\n\n

We are given a string s of '0's and '1's, and we may flip any '0' to a '1' or a '1' to a '0'.

\n\n

Return the minimum number of flips to make s monotone increasing.

\n\n

 

\n\n
\n

Example 1:

\n\n
\nInput: s = "00110"\nOutput: 1\nExplanation: We flip the last digit to get 00111.\n
\n\n
\n

Example 2:

\n\n
\nInput: s = "010110"\nOutput: 2\nExplanation: We flip to get 011111, or alternatively 000111.\n
\n\n
\n

Example 3:

\n\n
\nInput: s = "00011000"\nOutput: 2\nExplanation: We flip to get 00000000.\n
\n\n

 

\n\n

Note:

\n\n
    \n\t
  1. 1 <= s.length <= 20000
  2. \n\t
  3. s only consists of '0' and '1' characters.
  4. \n
\n
\n
\n
\n", "content_cn": "

\u5982\u679c\u4e00\u4e2a\u7531 '0' \u548c '1' \u7ec4\u6210\u7684\u5b57\u7b26\u4e32\uff0c\u662f\u4ee5\u4e00\u4e9b '0'\uff08\u53ef\u80fd\u6ca1\u6709 '0'\uff09\u540e\u9762\u8ddf\u7740\u4e00\u4e9b '1'\uff08\u4e5f\u53ef\u80fd\u6ca1\u6709 '1'\uff09\u7684\u5f62\u5f0f\u7ec4\u6210\u7684\uff0c\u90a3\u4e48\u8be5\u5b57\u7b26\u4e32\u662f\u5355\u8c03\u9012\u589e\u7684\u3002

\n\n

\u6211\u4eec\u7ed9\u51fa\u4e00\u4e2a\u7531\u5b57\u7b26 '0' \u548c '1' \u7ec4\u6210\u7684\u5b57\u7b26\u4e32 S\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u4efb\u4f55 '0' \u7ffb\u8f6c\u4e3a '1' \u6216\u8005\u5c06 '1' \u7ffb\u8f6c\u4e3a '0'\u3002

\n\n

\u8fd4\u56de\u4f7f S \u5355\u8c03\u9012\u589e\u7684\u6700\u5c0f\u7ffb\u8f6c\u6b21\u6570\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a"00110"\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u6211\u4eec\u7ffb\u8f6c\u6700\u540e\u4e00\u4f4d\u5f97\u5230 00111.\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a"010110"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6211\u4eec\u7ffb\u8f6c\u5f97\u5230 011111\uff0c\u6216\u8005\u662f 000111\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1a"00011000"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6211\u4eec\u7ffb\u8f6c\u5f97\u5230 00000000\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= S.length <= 20000
  2. \n\t
  3. S \u4e2d\u53ea\u5305\u542b\u5b57\u7b26 '0' \u548c '1'
  4. \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minFlipsMonoIncr(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minFlipsMonoIncr(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minFlipsMonoIncr(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minFlipsMonoIncr(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minFlipsMonoIncr(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinFlipsMonoIncr(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar minFlipsMonoIncr = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef min_flips_mono_incr(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minFlipsMonoIncr(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minFlipsMonoIncr(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minFlipsMonoIncr(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minFlipsMonoIncr(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_flips_mono_incr(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function minFlipsMonoIncr($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minFlipsMonoIncr(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-flips-mono-incr s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0926](https://leetcode-cn.com/problems/flip-string-to-monotone-increasing)", "[\u5c06\u5b57\u7b26\u4e32\u7ffb\u8f6c\u5230\u5355\u8c03\u9012\u589e](/solution/0900-0999/0926.Flip%20String%20to%20Monotone%20Increasing/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0926](https://leetcode.com/problems/flip-string-to-monotone-increasing)", "[Flip String to Monotone Increasing](/solution/0900-0999/0926.Flip%20String%20to%20Monotone%20Increasing/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0961", "frontend_question_id": "0925", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/long-pressed-name", "url_en": "https://leetcode.com/problems/long-pressed-name", "relative_path_cn": "/solution/0900-0999/0925.Long%20Pressed%20Name/README.md", "relative_path_en": "/solution/0900-0999/0925.Long%20Pressed%20Name/README_EN.md", "title_cn": "\u957f\u6309\u952e\u5165", "title_en": "Long Pressed Name", "question_title_slug": "long-pressed-name", "content_en": "

Your friend is typing his name into a keyboard. Sometimes, when typing a character c, the key might get long pressed, and the character will be typed 1 or more times.

\n\n

You examine the typed characters of the keyboard. Return True if it is possible that it was your friends name, with some characters (possibly none) being long pressed.

\n\n

 

\n

Example 1:

\n\n
\nInput: name = "alex", typed = "aaleex"\nOutput: true\nExplanation: 'a' and 'e' in 'alex' were long pressed.\n
\n\n

Example 2:

\n\n
\nInput: name = "saeed", typed = "ssaaedd"\nOutput: false\nExplanation: 'e' must have been pressed twice, but it wasn't in the typed output.\n
\n\n

Example 3:

\n\n
\nInput: name = "leelee", typed = "lleeelee"\nOutput: true\n
\n\n

Example 4:

\n\n
\nInput: name = "laiden", typed = "laiden"\nOutput: true\nExplanation: It's not necessary to long press any character.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= name.length <= 1000
  • \n\t
  • 1 <= typed.length <= 1000
  • \n\t
  • name and typed contain only lowercase English letters.
  • \n
\n", "content_cn": "

\u4f60\u7684\u670b\u53cb\u6b63\u5728\u4f7f\u7528\u952e\u76d8\u8f93\u5165\u4ed6\u7684\u540d\u5b57 name\u3002\u5076\u5c14\uff0c\u5728\u952e\u5165\u5b57\u7b26 c \u65f6\uff0c\u6309\u952e\u53ef\u80fd\u4f1a\u88ab\u957f\u6309\uff0c\u800c\u5b57\u7b26\u53ef\u80fd\u88ab\u8f93\u5165 1 \u6b21\u6216\u591a\u6b21\u3002

\n\n

\u4f60\u5c06\u4f1a\u68c0\u67e5\u952e\u76d8\u8f93\u5165\u7684\u5b57\u7b26 typed\u3002\u5982\u679c\u5b83\u5bf9\u5e94\u7684\u53ef\u80fd\u662f\u4f60\u7684\u670b\u53cb\u7684\u540d\u5b57\uff08\u5176\u4e2d\u4e00\u4e9b\u5b57\u7b26\u53ef\u80fd\u88ab\u957f\u6309\uff09\uff0c\u90a3\u4e48\u5c31\u8fd4\u56de True\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aname = "alex", typed = "aaleex"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a'alex' \u4e2d\u7684 'a' \u548c 'e' \u88ab\u957f\u6309\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aname = "saeed", typed = "ssaaedd"\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a'e' \u4e00\u5b9a\u9700\u8981\u88ab\u952e\u5165\u4e24\u6b21\uff0c\u4f46\u5728 typed \u7684\u8f93\u51fa\u4e2d\u4e0d\u662f\u8fd9\u6837\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aname = "leelee", typed = "lleeelee"\n\u8f93\u51fa\uff1atrue\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1aname = "laiden", typed = "laiden"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u957f\u6309\u540d\u5b57\u4e2d\u7684\u5b57\u7b26\u5e76\u4e0d\u662f\u5fc5\u8981\u7684\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. name.length <= 1000
  2. \n\t
  3. typed.length <= 1000
  4. \n\t
  5. name \u548c typed \u7684\u5b57\u7b26\u90fd\u662f\u5c0f\u5199\u5b57\u6bcd\u3002
  6. \n
\n\n

 

\n\n

 

\n", "tags_en": ["Two Pointers", "String"], "tags_cn": ["\u53cc\u6307\u9488", "\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isLongPressedName(string name, string typed) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isLongPressedName(String name, String typed) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isLongPressedName(self, name, typed):\n \"\"\"\n :type name: str\n :type typed: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isLongPressedName(self, name: str, typed: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isLongPressedName(char * name, char * typed){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsLongPressedName(string name, string typed) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} name\n * @param {string} typed\n * @return {boolean}\n */\nvar isLongPressedName = function(name, typed) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} name\n# @param {String} typed\n# @return {Boolean}\ndef is_long_pressed_name(name, typed)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isLongPressedName(_ name: String, _ typed: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isLongPressedName(name string, typed string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isLongPressedName(name: String, typed: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isLongPressedName(name: String, typed: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_long_pressed_name(name: String, typed: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $name\n * @param String $typed\n * @return Boolean\n */\n function isLongPressedName($name, $typed) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isLongPressedName(name: string, typed: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-long-pressed-name name typed)\n (-> string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0925](https://leetcode-cn.com/problems/long-pressed-name)", "[\u957f\u6309\u952e\u5165](/solution/0900-0999/0925.Long%20Pressed%20Name/README.md)", "`\u53cc\u6307\u9488`,`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0925](https://leetcode.com/problems/long-pressed-name)", "[Long Pressed Name](/solution/0900-0999/0925.Long%20Pressed%20Name/README_EN.md)", "`Two Pointers`,`String`", "Easy", ""]}, {"question_id": "0960", "frontend_question_id": "0924", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimize-malware-spread", "url_en": "https://leetcode.com/problems/minimize-malware-spread", "relative_path_cn": "/solution/0900-0999/0924.Minimize%20Malware%20Spread/README.md", "relative_path_en": "/solution/0900-0999/0924.Minimize%20Malware%20Spread/README_EN.md", "title_cn": "\u5c3d\u91cf\u51cf\u5c11\u6076\u610f\u8f6f\u4ef6\u7684\u4f20\u64ad", "title_en": "Minimize Malware Spread", "question_title_slug": "minimize-malware-spread", "content_en": "

You are given a network of n nodes represented as an n x n adjacency matrix graph, where the ith node is directly connected to the jth node if graph[i][j] == 1.

\n\n

Some nodes initial are initially infected by malware. Whenever two nodes are directly connected, and at least one of those two nodes is infected by malware, both nodes will be infected by malware. This spread of malware will continue until no more nodes can be infected in this manner.

\n\n

Suppose M(initial) is the final number of nodes infected with malware in the entire network after the spread of malware stops. We will remove exactly one node from initial.

\n\n

Return the node that, if removed, would minimize M(initial). If multiple nodes could be removed to minimize M(initial), return such a node with the smallest index.

\n\n

Note that if a node was removed from the initial list of infected nodes, it might still be infected later due to the malware spread.

\n\n

 

\n

Example 1:

\n
Input: graph = [[1,1,0],[1,1,0],[0,0,1]], initial = [0,1]\nOutput: 0\n

Example 2:

\n
Input: graph = [[1,0,0],[0,1,0],[0,0,1]], initial = [0,2]\nOutput: 0\n

Example 3:

\n
Input: graph = [[1,1,1],[1,1,1],[1,1,1]], initial = [1,2]\nOutput: 1\n
\n

 

\n

Constraints:

\n\n
    \n\t
  • n == graph.length
  • \n\t
  • n == graph[i].length
  • \n\t
  • 2 <= n <= 300
  • \n\t
  • graph[i][j] is 0 or 1.
  • \n\t
  • graph[i][j] == graph[j][i]
  • \n\t
  • graph[i][i] == 1
  • \n\t
  • 1 <= initial.length <= n
  • \n\t
  • 0 <= initial[i] <= n - 1
  • \n\t
  • All the integers in initial are unique.
  • \n
\n", "content_cn": "

\u5728\u8282\u70b9\u7f51\u7edc\u4e2d\uff0c\u53ea\u6709\u5f53 graph[i][j] = 1 \u65f6\uff0c\u6bcf\u4e2a\u8282\u70b9 i \u80fd\u591f\u76f4\u63a5\u8fde\u63a5\u5230\u53e6\u4e00\u4e2a\u8282\u70b9 j\u3002

\n\n

\u4e00\u4e9b\u8282\u70b9 initial \u6700\u521d\u88ab\u6076\u610f\u8f6f\u4ef6\u611f\u67d3\u3002\u53ea\u8981\u4e24\u4e2a\u8282\u70b9\u76f4\u63a5\u8fde\u63a5\uff0c\u4e14\u5176\u4e2d\u81f3\u5c11\u4e00\u4e2a\u8282\u70b9\u53d7\u5230\u6076\u610f\u8f6f\u4ef6\u7684\u611f\u67d3\uff0c\u90a3\u4e48\u4e24\u4e2a\u8282\u70b9\u90fd\u5c06\u88ab\u6076\u610f\u8f6f\u4ef6\u611f\u67d3\u3002\u8fd9\u79cd\u6076\u610f\u8f6f\u4ef6\u7684\u4f20\u64ad\u5c06\u7ee7\u7eed\uff0c\u76f4\u5230\u6ca1\u6709\u66f4\u591a\u7684\u8282\u70b9\u53ef\u4ee5\u88ab\u8fd9\u79cd\u65b9\u5f0f\u611f\u67d3\u3002

\n\n

\u5047\u8bbe M(initial) \u662f\u5728\u6076\u610f\u8f6f\u4ef6\u505c\u6b62\u4f20\u64ad\u4e4b\u540e\uff0c\u6574\u4e2a\u7f51\u7edc\u4e2d\u611f\u67d3\u6076\u610f\u8f6f\u4ef6\u7684\u6700\u7ec8\u8282\u70b9\u6570\u3002

\n\n

\u6211\u4eec\u53ef\u4ee5\u4ece\u521d\u59cb\u5217\u8868\u4e2d\u5220\u9664\u4e00\u4e2a\u8282\u70b9\u3002\u5982\u679c\u79fb\u9664\u8fd9\u4e00\u8282\u70b9\u5c06\u6700\u5c0f\u5316 M(initial)\uff0c \u5219\u8fd4\u56de\u8be5\u8282\u70b9\u3002\u5982\u679c\u6709\u591a\u4e2a\u8282\u70b9\u6ee1\u8db3\u6761\u4ef6\uff0c\u5c31\u8fd4\u56de\u7d22\u5f15\u6700\u5c0f\u7684\u8282\u70b9\u3002

\n\n

\u8bf7\u6ce8\u610f\uff0c\u5982\u679c\u67d0\u4e2a\u8282\u70b9\u5df2\u4ece\u53d7\u611f\u67d3\u8282\u70b9\u7684\u5217\u8868 initial \u4e2d\u5220\u9664\uff0c\u5b83\u4ee5\u540e\u53ef\u80fd\u4ecd\u7136\u56e0\u6076\u610f\u8f6f\u4ef6\u4f20\u64ad\u800c\u53d7\u5230\u611f\u67d3\u3002

\n\n

 

\n\n
    \n
\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1agraph = [[1,1,0],[1,1,0],[0,0,1]], initial = [0,1]\n\u8f93\u51fa\uff1a0\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1agraph = [[1,0,0],[0,1,0],[0,0,1]], initial = [0,2]\n\u8f93\u51fa\uff1a0\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1agraph = [[1,1,1],[1,1,1],[1,1,1]], initial = [1,2]\n\u8f93\u51fa\uff1a1\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 < graph.length = graph[0].length <= 300
  • \n\t
  • 0 <= graph[i][j] == graph[j][i] <= 1
  • \n\t
  • graph[i][i] == 1
  • \n\t
  • 1 <= initial.length < graph.length
  • \n\t
  • 0 <= initial[i] < graph.length
  • \n
\n", "tags_en": ["Depth-first Search", "Union Find"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e76\u67e5\u96c6"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minMalwareSpread(vector>& graph, vector& initial) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minMalwareSpread(int[][] graph, int[] initial) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minMalwareSpread(self, graph, initial):\n \"\"\"\n :type graph: List[List[int]]\n :type initial: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minMalwareSpread(self, graph: List[List[int]], initial: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minMalwareSpread(int** graph, int graphSize, int* graphColSize, int* initial, int initialSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinMalwareSpread(int[][] graph, int[] initial) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} graph\n * @param {number[]} initial\n * @return {number}\n */\nvar minMalwareSpread = function(graph, initial) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} graph\n# @param {Integer[]} initial\n# @return {Integer}\ndef min_malware_spread(graph, initial)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minMalwareSpread(_ graph: [[Int]], _ initial: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minMalwareSpread(graph [][]int, initial []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minMalwareSpread(graph: Array[Array[Int]], initial: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minMalwareSpread(graph: Array, initial: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_malware_spread(graph: Vec>, initial: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $graph\n * @param Integer[] $initial\n * @return Integer\n */\n function minMalwareSpread($graph, $initial) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minMalwareSpread(graph: number[][], initial: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-malware-spread graph initial)\n (-> (listof (listof exact-integer?)) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0924](https://leetcode-cn.com/problems/minimize-malware-spread)", "[\u5c3d\u91cf\u51cf\u5c11\u6076\u610f\u8f6f\u4ef6\u7684\u4f20\u64ad](/solution/0900-0999/0924.Minimize%20Malware%20Spread/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e76\u67e5\u96c6`", "\u56f0\u96be", ""], "md_table_row_en": ["[0924](https://leetcode.com/problems/minimize-malware-spread)", "[Minimize Malware Spread](/solution/0900-0999/0924.Minimize%20Malware%20Spread/README_EN.md)", "`Depth-first Search`,`Union Find`", "Hard", ""]}, {"question_id": "0959", "frontend_question_id": "0923", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/3sum-with-multiplicity", "url_en": "https://leetcode.com/problems/3sum-with-multiplicity", "relative_path_cn": "/solution/0900-0999/0923.3Sum%20With%20Multiplicity/README.md", "relative_path_en": "/solution/0900-0999/0923.3Sum%20With%20Multiplicity/README_EN.md", "title_cn": "\u4e09\u6570\u4e4b\u548c\u7684\u591a\u79cd\u53ef\u80fd", "title_en": "3Sum With Multiplicity", "question_title_slug": "3sum-with-multiplicity", "content_en": "

Given an integer array arr, and an integer target, return the number of tuples i, j, k such that i < j < k and arr[i] + arr[j] + arr[k] == target.

\n\n

As the answer can be very large, return it modulo 109 + 7.

\n\n

 

\n

Example 1:

\n\n
\nInput: arr = [1,1,2,2,3,3,4,4,5,5], target = 8\nOutput: 20\nExplanation: \nEnumerating by the values (arr[i], arr[j], arr[k]):\n(1, 2, 5) occurs 8 times;\n(1, 3, 4) occurs 8 times;\n(2, 2, 4) occurs 2 times;\n(2, 3, 3) occurs 2 times.\n
\n\n

Example 2:

\n\n
\nInput: arr = [1,1,2,2,2,2], target = 5\nOutput: 12\nExplanation: \narr[i] = 1, arr[j] = arr[k] = 2 occurs 12 times:\nWe choose one 1 from [1,1] in 2 ways,\nand two 2s from [2,2,2,2] in 6 ways.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 3 <= arr.length <= 3000
  • \n\t
  • 0 <= arr[i] <= 100
  • \n\t
  • 0 <= target <= 300
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 A\uff0c\u4ee5\u53ca\u4e00\u4e2a\u6574\u6570 target \u4f5c\u4e3a\u76ee\u6807\u503c\uff0c\u8fd4\u56de\u6ee1\u8db3 i < j < k \u4e14 A[i] + A[j] + A[k] == target \u7684\u5143\u7ec4 i, j, k \u7684\u6570\u91cf\u3002

\n\n

\u7531\u4e8e\u7ed3\u679c\u4f1a\u975e\u5e38\u5927\uff0c\u8bf7\u8fd4\u56de \u7ed3\u679c\u9664\u4ee5 10^9 + 7 \u7684\u4f59\u6570\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aA = [1,1,2,2,3,3,4,4,5,5], target = 8\n\u8f93\u51fa\uff1a20\n\u89e3\u91ca\uff1a\n\u6309\u503c\u679a\u4e3e\uff08A[i]\uff0cA[j]\uff0cA[k]\uff09\uff1a\n(1, 2, 5) \u51fa\u73b0 8 \u6b21\uff1b\n(1, 3, 4) \u51fa\u73b0 8 \u6b21\uff1b\n(2, 2, 4) \u51fa\u73b0 2 \u6b21\uff1b\n(2, 3, 3) \u51fa\u73b0 2 \u6b21\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aA = [1,1,2,2,2,2], target = 5\n\u8f93\u51fa\uff1a12\n\u89e3\u91ca\uff1a\nA[i] = 1\uff0cA[j] = A[k] = 2 \u51fa\u73b0 12 \u6b21\uff1a\n\u6211\u4eec\u4ece [1,1] \u4e2d\u9009\u62e9\u4e00\u4e2a 1\uff0c\u6709 2 \u79cd\u60c5\u51b5\uff0c\n\u4ece [2,2,2,2] \u4e2d\u9009\u51fa\u4e24\u4e2a 2\uff0c\u6709 6 \u79cd\u60c5\u51b5\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 3 <= A.length <= 3000
  2. \n\t
  3. 0 <= A[i] <= 100
  4. \n\t
  5. 0 <= target <= 300
  6. \n
\n", "tags_en": ["Two Pointers"], "tags_cn": ["\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int threeSumMulti(vector& arr, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int threeSumMulti(int[] arr, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def threeSumMulti(self, arr, target):\n \"\"\"\n :type arr: List[int]\n :type target: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def threeSumMulti(self, arr: List[int], target: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint threeSumMulti(int* arr, int arrSize, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ThreeSumMulti(int[] arr, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @param {number} target\n * @return {number}\n */\nvar threeSumMulti = function(arr, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @param {Integer} target\n# @return {Integer}\ndef three_sum_multi(arr, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func threeSumMulti(_ arr: [Int], _ target: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func threeSumMulti(arr []int, target int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def threeSumMulti(arr: Array[Int], target: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun threeSumMulti(arr: IntArray, target: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn three_sum_multi(arr: Vec, target: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @param Integer $target\n * @return Integer\n */\n function threeSumMulti($arr, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function threeSumMulti(arr: number[], target: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (three-sum-multi arr target)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0923](https://leetcode-cn.com/problems/3sum-with-multiplicity)", "[\u4e09\u6570\u4e4b\u548c\u7684\u591a\u79cd\u53ef\u80fd](/solution/0900-0999/0923.3Sum%20With%20Multiplicity/README.md)", "`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0923](https://leetcode.com/problems/3sum-with-multiplicity)", "[3Sum With Multiplicity](/solution/0900-0999/0923.3Sum%20With%20Multiplicity/README_EN.md)", "`Two Pointers`", "Medium", ""]}, {"question_id": "0958", "frontend_question_id": "0922", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sort-array-by-parity-ii", "url_en": "https://leetcode.com/problems/sort-array-by-parity-ii", "relative_path_cn": "/solution/0900-0999/0922.Sort%20Array%20By%20Parity%20II/README.md", "relative_path_en": "/solution/0900-0999/0922.Sort%20Array%20By%20Parity%20II/README_EN.md", "title_cn": "\u6309\u5947\u5076\u6392\u5e8f\u6570\u7ec4 II", "title_en": "Sort Array By Parity II", "question_title_slug": "sort-array-by-parity-ii", "content_en": "

Given an array of integers nums, half of the integers in nums are odd, and the other half are even.

\n\n

Sort the array so that whenever nums[i] is odd, i is odd, and whenever nums[i] is even, i is even.

\n\n

Return any answer array that satisfies this condition.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [4,2,5,7]\nOutput: [4,5,2,7]\nExplanation: [4,7,2,5], [2,5,4,7], [2,7,4,5] would also have been accepted.\n
\n\n

Example 2:

\n\n
\nInput: nums = [2,3]\nOutput: [2,3]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= nums.length <= 2 * 104
  • \n\t
  • nums.length is even.
  • \n\t
  • Half of the integers in nums are even.
  • \n\t
  • 0 <= nums[i] <= 1000
  • \n
\n\n

 

\n

Follow Up: Could you solve it in-place?

\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\u6570\u7ec4 A\uff0c A \u4e2d\u4e00\u534a\u6574\u6570\u662f\u5947\u6570\uff0c\u4e00\u534a\u6574\u6570\u662f\u5076\u6570\u3002

\n\n

\u5bf9\u6570\u7ec4\u8fdb\u884c\u6392\u5e8f\uff0c\u4ee5\u4fbf\u5f53 A[i] \u4e3a\u5947\u6570\u65f6\uff0ci \u4e5f\u662f\u5947\u6570\uff1b\u5f53 A[i] \u4e3a\u5076\u6570\u65f6\uff0c i \u4e5f\u662f\u5076\u6570\u3002

\n\n

\u4f60\u53ef\u4ee5\u8fd4\u56de\u4efb\u4f55\u6ee1\u8db3\u4e0a\u8ff0\u6761\u4ef6\u7684\u6570\u7ec4\u4f5c\u4e3a\u7b54\u6848\u3002

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1a[4,2,5,7]\n\u8f93\u51fa\uff1a[4,5,2,7]\n\u89e3\u91ca\uff1a[4,7,2,5]\uff0c[2,5,4,7]\uff0c[2,7,4,5] \u4e5f\u4f1a\u88ab\u63a5\u53d7\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 2 <= A.length <= 20000
  2. \n\t
  3. A.length % 2 == 0
  4. \n\t
  5. 0 <= A[i] <= 1000
  6. \n
\n\n

 

\n", "tags_en": ["Sort", "Array"], "tags_cn": ["\u6392\u5e8f", "\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector sortArrayByParityII(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] sortArrayByParityII(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def sortArrayByParityII(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def sortArrayByParityII(self, nums: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* sortArrayByParityII(int* nums, int numsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] SortArrayByParityII(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar sortArrayByParityII = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer[]}\ndef sort_array_by_parity_ii(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func sortArrayByParityII(_ nums: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func sortArrayByParityII(nums []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def sortArrayByParityII(nums: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun sortArrayByParityII(nums: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sort_array_by_parity_ii(nums: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer[]\n */\n function sortArrayByParityII($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function sortArrayByParityII(nums: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (sort-array-by-parity-ii nums)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0922](https://leetcode-cn.com/problems/sort-array-by-parity-ii)", "[\u6309\u5947\u5076\u6392\u5e8f\u6570\u7ec4 II](/solution/0900-0999/0922.Sort%20Array%20By%20Parity%20II/README.md)", "`\u6392\u5e8f`,`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0922](https://leetcode.com/problems/sort-array-by-parity-ii)", "[Sort Array By Parity II](/solution/0900-0999/0922.Sort%20Array%20By%20Parity%20II/README_EN.md)", "`Sort`,`Array`", "Easy", ""]}, {"question_id": "0957", "frontend_question_id": "0921", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-add-to-make-parentheses-valid", "url_en": "https://leetcode.com/problems/minimum-add-to-make-parentheses-valid", "relative_path_cn": "/solution/0900-0999/0921.Minimum%20Add%20to%20Make%20Parentheses%20Valid/README.md", "relative_path_en": "/solution/0900-0999/0921.Minimum%20Add%20to%20Make%20Parentheses%20Valid/README_EN.md", "title_cn": "\u4f7f\u62ec\u53f7\u6709\u6548\u7684\u6700\u5c11\u6dfb\u52a0", "title_en": "Minimum Add to Make Parentheses Valid", "question_title_slug": "minimum-add-to-make-parentheses-valid", "content_en": "

Given a string s of '(' and ')' parentheses, we add the minimum number of parentheses ( '(' or ')', and in any positions ) so that the resulting parentheses string is valid.

\n\n

Formally, a parentheses string is valid if and only if:

\n\n
    \n\t
  • It is the empty string, or
  • \n\t
  • It can be written as AB (A concatenated with B), where A and B are valid strings, or
  • \n\t
  • It can be written as (A), where A is a valid string.
  • \n
\n\n

Given a parentheses string, return the minimum number of parentheses we must add to make the resulting string valid.

\n\n

 

\n\n

Example 1:

\n\n
\nInput: s = "())"\nOutput: 1\n
\n\n
\n

Example 2:

\n\n
\nInput: s = "((("\nOutput: 3\n
\n\n
\n

Example 3:

\n\n
\nInput: s = "()"\nOutput: 0\n
\n\n
\n

Example 4:

\n\n
\nInput: s = "()))(("\nOutput: 4
\n\n

 

\n
\n
\n
\n\n

Note:

\n\n
    \n\t
  1. s.length <= 1000
  2. \n\t
  3. s only consists of '(' and ')' characters.
  4. \n
\n\n
\n
\n
\n
 
\n
\n
\n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u7531 '(' \u548c ')' \u62ec\u53f7\u7ec4\u6210\u7684\u5b57\u7b26\u4e32 S\uff0c\u6211\u4eec\u9700\u8981\u6dfb\u52a0\u6700\u5c11\u7684\u62ec\u53f7\uff08 '(' \u6216\u662f ')'\uff0c\u53ef\u4ee5\u5728\u4efb\u4f55\u4f4d\u7f6e\uff09\uff0c\u4ee5\u4f7f\u5f97\u5230\u7684\u62ec\u53f7\u5b57\u7b26\u4e32\u6709\u6548\u3002

\n\n

\u4ece\u5f62\u5f0f\u4e0a\u8bb2\uff0c\u53ea\u6709\u6ee1\u8db3\u4e0b\u9762\u51e0\u70b9\u4e4b\u4e00\uff0c\u62ec\u53f7\u5b57\u7b26\u4e32\u624d\u662f\u6709\u6548\u7684\uff1a

\n\n
    \n\t
  • \u5b83\u662f\u4e00\u4e2a\u7a7a\u5b57\u7b26\u4e32\uff0c\u6216\u8005
  • \n\t
  • \u5b83\u53ef\u4ee5\u88ab\u5199\u6210 AB \uff08A \u4e0e B \u8fde\u63a5\uff09, \u5176\u4e2d A \u548c B \u90fd\u662f\u6709\u6548\u5b57\u7b26\u4e32\uff0c\u6216\u8005
  • \n\t
  • \u5b83\u53ef\u4ee5\u88ab\u5199\u4f5c (A)\uff0c\u5176\u4e2d A \u662f\u6709\u6548\u5b57\u7b26\u4e32\u3002
  • \n
\n\n

\u7ed9\u5b9a\u4e00\u4e2a\u62ec\u53f7\u5b57\u7b26\u4e32\uff0c\u8fd4\u56de\u4e3a\u4f7f\u7ed3\u679c\u5b57\u7b26\u4e32\u6709\u6548\u800c\u5fc5\u987b\u6dfb\u52a0\u7684\u6700\u5c11\u62ec\u53f7\u6570\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a"())"\n\u8f93\u51fa\uff1a1\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a"((("\n\u8f93\u51fa\uff1a3\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1a"()"\n\u8f93\u51fa\uff1a0\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1a"()))(("\n\u8f93\u51fa\uff1a4
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. S.length <= 1000
  2. \n\t
  3. S \u53ea\u5305\u542b '(' \u548c ')' \u5b57\u7b26\u3002
  4. \n
\n\n

 

\n", "tags_en": ["Stack", "Greedy"], "tags_cn": ["\u6808", "\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minAddToMakeValid(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minAddToMakeValid(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minAddToMakeValid(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minAddToMakeValid(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minAddToMakeValid(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinAddToMakeValid(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar minAddToMakeValid = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef min_add_to_make_valid(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minAddToMakeValid(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minAddToMakeValid(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minAddToMakeValid(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minAddToMakeValid(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_add_to_make_valid(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function minAddToMakeValid($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minAddToMakeValid(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-add-to-make-valid s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0921](https://leetcode-cn.com/problems/minimum-add-to-make-parentheses-valid)", "[\u4f7f\u62ec\u53f7\u6709\u6548\u7684\u6700\u5c11\u6dfb\u52a0](/solution/0900-0999/0921.Minimum%20Add%20to%20Make%20Parentheses%20Valid/README.md)", "`\u6808`,`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0921](https://leetcode.com/problems/minimum-add-to-make-parentheses-valid)", "[Minimum Add to Make Parentheses Valid](/solution/0900-0999/0921.Minimum%20Add%20to%20Make%20Parentheses%20Valid/README_EN.md)", "`Stack`,`Greedy`", "Medium", ""]}, {"question_id": "0956", "frontend_question_id": "0920", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-music-playlists", "url_en": "https://leetcode.com/problems/number-of-music-playlists", "relative_path_cn": "/solution/0900-0999/0920.Number%20of%20Music%20Playlists/README.md", "relative_path_en": "/solution/0900-0999/0920.Number%20of%20Music%20Playlists/README_EN.md", "title_cn": "\u64ad\u653e\u5217\u8868\u7684\u6570\u91cf", "title_en": "Number of Music Playlists", "question_title_slug": "number-of-music-playlists", "content_en": "

Your music player contains n different songs and she wants to listen to goal (not necessarily different) songs during your trip.  You create a playlist so that:

\n\n
    \n\t
  • Every song is played at least once
  • \n\t
  • A song can only be played again only if k other songs have been played
  • \n
\n\n

Return the number of possible playlists.  As the answer can be very large, return it modulo 109 + 7.

\n\n

 

\n\n
\n
\n
\n

Example 1:

\n\n
\nInput: n = 3, goal = 3, k = 1\nOutput: 6\nExplanation: There are 6 possible playlists. [1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1].\n
\n\n
\n

Example 2:

\n\n
\nInput: n = 2, goal = 3, k = 0\nOutput: 6\nExplanation: There are 6 possible playlists. [1, 1, 2], [1, 2, 1], [2, 1, 1], [2, 2, 1], [2, 1, 2], [1, 2, 2]\n
\n\n
\n

Example 3:

\n\n
\nInput: n = 2, goal = 3, k = 1\nOutput: 2\nExplanation: There are 2 possible playlists. [1, 2, 1], [2, 1, 2]\n
\n
\n
\n\n

 

\n\n

Note:

\n\n
    \n\t
  1. 0 <= k < n <= goal <= 100
  2. \n
\n
\n
\n
\n", "content_cn": "

\u4f60\u7684\u97f3\u4e50\u64ad\u653e\u5668\u91cc\u6709 N \u9996\u4e0d\u540c\u7684\u6b4c\uff0c\u5728\u65c5\u9014\u4e2d\uff0c\u4f60\u7684\u65c5\u4f34\u60f3\u8981\u542c L \u9996\u6b4c\uff08\u4e0d\u4e00\u5b9a\u4e0d\u540c\uff0c\u5373\uff0c\u5141\u8bb8\u6b4c\u66f2\u91cd\u590d\uff09\u3002\u8bf7\u4f60\u4e3a\u5979\u6309\u5982\u4e0b\u89c4\u5219\u521b\u5efa\u4e00\u4e2a\u64ad\u653e\u5217\u8868\uff1a

\n\n
    \n\t
  • \u6bcf\u9996\u6b4c\u81f3\u5c11\u64ad\u653e\u4e00\u6b21\u3002
  • \n\t
  • \u4e00\u9996\u6b4c\u53ea\u6709\u5728\u5176\u4ed6 K \u9996\u6b4c\u64ad\u653e\u5b8c\u4e4b\u540e\u624d\u80fd\u518d\u6b21\u64ad\u653e\u3002
  • \n
\n\n

\u8fd4\u56de\u53ef\u4ee5\u6ee1\u8db3\u8981\u6c42\u7684\u64ad\u653e\u5217\u8868\u7684\u6570\u91cf\u3002\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u975e\u5e38\u5927\uff0c\u8bf7\u8fd4\u56de\u5b83\u6a21 10^9 + 7 \u7684\u7ed3\u679c\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aN = 3, L = 3, K = 1\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u6709 6 \u79cd\u53ef\u80fd\u7684\u64ad\u653e\u5217\u8868\u3002[1, 2, 3]\uff0c[1, 3, 2]\uff0c[2, 1, 3]\uff0c[2, 3, 1]\uff0c[3, 1, 2]\uff0c[3, 2, 1].\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aN = 2, L = 3, K = 0\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u6709 6 \u79cd\u53ef\u80fd\u7684\u64ad\u653e\u5217\u8868\u3002[1, 1, 2]\uff0c[1, 2, 1]\uff0c[2, 1, 1]\uff0c[2, 2, 1]\uff0c[2, 1, 2]\uff0c[1, 2, 2]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aN = 2, L = 3, K = 1\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6709 2 \u79cd\u53ef\u80fd\u7684\u64ad\u653e\u5217\u8868\u3002[1, 2, 1]\uff0c[2, 1, 2]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 0 <= K < N <= L <= 100
  2. \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numMusicPlaylists(int n, int goal, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numMusicPlaylists(int n, int goal, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numMusicPlaylists(self, n, goal, k):\n \"\"\"\n :type n: int\n :type goal: int\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numMusicPlaylists(self, n: int, goal: int, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numMusicPlaylists(int n, int goal, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumMusicPlaylists(int n, int goal, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} goal\n * @param {number} k\n * @return {number}\n */\nvar numMusicPlaylists = function(n, goal, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} goal\n# @param {Integer} k\n# @return {Integer}\ndef num_music_playlists(n, goal, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numMusicPlaylists(_ n: Int, _ goal: Int, _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numMusicPlaylists(n int, goal int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numMusicPlaylists(n: Int, goal: Int, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numMusicPlaylists(n: Int, goal: Int, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_music_playlists(n: i32, goal: i32, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $goal\n * @param Integer $k\n * @return Integer\n */\n function numMusicPlaylists($n, $goal, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numMusicPlaylists(n: number, goal: number, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-music-playlists n goal k)\n (-> exact-integer? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0920](https://leetcode-cn.com/problems/number-of-music-playlists)", "[\u64ad\u653e\u5217\u8868\u7684\u6570\u91cf](/solution/0900-0999/0920.Number%20of%20Music%20Playlists/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0920](https://leetcode.com/problems/number-of-music-playlists)", "[Number of Music Playlists](/solution/0900-0999/0920.Number%20of%20Music%20Playlists/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "0955", "frontend_question_id": "0919", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/complete-binary-tree-inserter", "url_en": "https://leetcode.com/problems/complete-binary-tree-inserter", "relative_path_cn": "/solution/0900-0999/0919.Complete%20Binary%20Tree%20Inserter/README.md", "relative_path_en": "/solution/0900-0999/0919.Complete%20Binary%20Tree%20Inserter/README_EN.md", "title_cn": "\u5b8c\u5168\u4e8c\u53c9\u6811\u63d2\u5165\u5668", "title_en": "Complete Binary Tree Inserter", "question_title_slug": "complete-binary-tree-inserter", "content_en": "

A complete binary tree is a binary tree in which every level, except possibly the last, is completely filled, and all nodes are as far left as possible.

\r\n\r\n

Write a data structure CBTInserter that is initialized with a complete binary tree and supports the following operations:

\r\n\r\n
    \r\n\t
  • CBTInserter(TreeNode root) initializes the data structure on a given tree with head node root;
  • \r\n\t
  • CBTInserter.insert(int v) will insert a TreeNode into the tree with value node.val = v so that the tree remains complete, and returns the value of the parent of the inserted TreeNode;
  • \r\n\t
  • CBTInserter.get_root() will return the head node of the tree.
  • \r\n
\r\n\r\n
    \r\n
\r\n\r\n
\r\n

 

\r\n\r\n

Example 1:

\r\n\r\n
\r\nInput: inputs = ["CBTInserter","insert","get_root"], inputs = [[[1]],[2],[]]\r\nOutput: [null,1,[1,2]]\r\n
\r\n\r\n
\r\n

Example 2:

\r\n\r\n
\r\nInput: inputs = ["CBTInserter","insert","insert","get_root"], inputs = [[[1,2,3,4,5,6]],[7],[8],[]]\r\nOutput: [null,3,4,[1,2,3,4,5,6,7,8]]
\r\n
\r\n\r\n
\r\n

 

\r\n\r\n

Note:

\r\n\r\n
    \r\n\t
  1. The initial given tree is complete and contains between 1 and 1000 nodes.
  2. \r\n\t
  3. CBTInserter.insert is called at most 10000 times per test case.
  4. \r\n\t
  5. Every value of a given or inserted node is between 0 and 5000.
  6. \r\n
\r\n
\r\n
\r\n\r\n
\r\n

 

\r\n\r\n
 
\r\n
\r\n", "content_cn": "

\u5b8c\u5168\u4e8c\u53c9\u6811\u662f\u6bcf\u4e00\u5c42\uff08\u9664\u6700\u540e\u4e00\u5c42\u5916\uff09\u90fd\u662f\u5b8c\u5168\u586b\u5145\uff08\u5373\uff0c\u8282\u70b9\u6570\u8fbe\u5230\u6700\u5927\uff09\u7684\uff0c\u5e76\u4e14\u6240\u6709\u7684\u8282\u70b9\u90fd\u5c3d\u53ef\u80fd\u5730\u96c6\u4e2d\u5728\u5de6\u4fa7\u3002

\n\n

\u8bbe\u8ba1\u4e00\u4e2a\u7528\u5b8c\u5168\u4e8c\u53c9\u6811\u521d\u59cb\u5316\u7684\u6570\u636e\u7ed3\u6784 CBTInserter\uff0c\u5b83\u652f\u6301\u4ee5\u4e0b\u51e0\u79cd\u64cd\u4f5c\uff1a

\n\n
    \n\t
  • CBTInserter(TreeNode root) \u4f7f\u7528\u5934\u8282\u70b9\u4e3a root \u7684\u7ed9\u5b9a\u6811\u521d\u59cb\u5316\u8be5\u6570\u636e\u7ed3\u6784\uff1b
  • \n\t
  • CBTInserter.insert(int v)  \u5411\u6811\u4e2d\u63d2\u5165\u4e00\u4e2a\u65b0\u8282\u70b9\uff0c\u8282\u70b9\u7c7b\u578b\u4e3a TreeNode\uff0c\u503c\u4e3a v \u3002\u4f7f\u6811\u4fdd\u6301\u5b8c\u5168\u4e8c\u53c9\u6811\u7684\u72b6\u6001\uff0c\u5e76\u8fd4\u56de\u63d2\u5165\u7684\u65b0\u8282\u70b9\u7684\u7236\u8282\u70b9\u7684\u503c\uff1b
  • \n\t
  • CBTInserter.get_root() \u5c06\u8fd4\u56de\u6811\u7684\u5934\u8282\u70b9\u3002
  • \n
\n\n

 

\n\n
    \n
\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1ainputs = ["CBTInserter","insert","get_root"], inputs = [[[1]],[2],[]]\n\u8f93\u51fa\uff1a[null,1,[1,2]]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1ainputs = ["CBTInserter","insert","insert","get_root"], inputs = [[[1,2,3,4,5,6]],[7],[8],[]]\n\u8f93\u51fa\uff1a[null,3,4,[1,2,3,4,5,6,7,8]]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. \u6700\u521d\u7ed9\u5b9a\u7684\u6811\u662f\u5b8c\u5168\u4e8c\u53c9\u6811\uff0c\u4e14\u5305\u542b 1 \u5230 1000 \u4e2a\u8282\u70b9\u3002
  2. \n\t
  3. \u6bcf\u4e2a\u6d4b\u8bd5\u7528\u4f8b\u6700\u591a\u8c03\u7528 CBTInserter.insert  \u64cd\u4f5c 10000 \u6b21\u3002
  4. \n\t
  5. \u7ed9\u5b9a\u8282\u70b9\u6216\u63d2\u5165\u8282\u70b9\u7684\u6bcf\u4e2a\u503c\u90fd\u5728 0 \u5230 5000 \u4e4b\u95f4\u3002
  6. \n
\n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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 */\nclass CBTInserter {\npublic:\n CBTInserter(TreeNode* root) {\n\n }\n \n int insert(int v) {\n\n }\n \n TreeNode* get_root() {\n\n }\n};\n\n/**\n * Your CBTInserter object will be instantiated and called as such:\n * CBTInserter* obj = new CBTInserter(root);\n * int param_1 = obj->insert(v);\n * TreeNode* param_2 = obj->get_root();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode(int x) { val = x; }\n * }\n */\nclass CBTInserter {\n\n public CBTInserter(TreeNode root) {\n\n }\n \n public int insert(int v) {\n\n }\n \n public TreeNode get_root() {\n\n }\n}\n\n/**\n * Your CBTInserter object will be instantiated and called as such:\n * CBTInserter obj = new CBTInserter(root);\n * int param_1 = obj.insert(v);\n * TreeNode param_2 = obj.get_root();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass CBTInserter(object):\n\n def __init__(self, root):\n \"\"\"\n :type root: TreeNode\n \"\"\"\n \n\n def insert(self, v):\n \"\"\"\n :type v: int\n :rtype: int\n \"\"\"\n \n\n def get_root(self):\n \"\"\"\n :rtype: TreeNode\n \"\"\"\n \n\n\n# Your CBTInserter object will be instantiated and called as such:\n# obj = CBTInserter(root)\n# param_1 = obj.insert(v)\n# param_2 = obj.get_root()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass CBTInserter:\n\n def __init__(self, root: TreeNode):\n \n\n def insert(self, v: int) -> int:\n \n\n def get_root(self) -> TreeNode:\n \n\n\n# Your CBTInserter object will be instantiated and called as such:\n# obj = CBTInserter(root)\n# param_1 = obj.insert(v)\n# param_2 = obj.get_root()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n\ntypedef struct {\n \n} CBTInserter;\n\n\nCBTInserter* cBTInserterCreate(struct TreeNode* root) {\n \n}\n\nint cBTInserterInsert(CBTInserter* obj, int v) {\n \n}\n\nstruct TreeNode* cBTInserterGet_root(CBTInserter* obj) {\n \n}\n\nvoid cBTInserterFree(CBTInserter* obj) {\n \n}\n\n/**\n * Your CBTInserter struct will be instantiated and called as such:\n * CBTInserter* obj = cBTInserterCreate(root);\n * int param_1 = cBTInserterInsert(obj, v);\n \n * struct TreeNode* param_2 = cBTInserterGet_root(obj);\n \n * cBTInserterFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int x) { val = x; }\n * }\n */\npublic class CBTInserter {\n\n public CBTInserter(TreeNode root) {\n\n }\n \n public int Insert(int v) {\n\n }\n \n public TreeNode Get_root() {\n\n }\n}\n\n/**\n * Your CBTInserter object will be instantiated and called as such:\n * CBTInserter obj = new CBTInserter(root);\n * int param_1 = obj.Insert(v);\n * TreeNode param_2 = obj.Get_root();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val) {\n * this.val = val;\n * this.left = this.right = null;\n * }\n */\n/**\n * @param {TreeNode} root\n */\nvar CBTInserter = function(root) {\n\n};\n\n/** \n * @param {number} v\n * @return {number}\n */\nCBTInserter.prototype.insert = function(v) {\n\n};\n\n/**\n * @return {TreeNode}\n */\nCBTInserter.prototype.get_root = function() {\n\n};\n\n/**\n * Your CBTInserter object will be instantiated and called as such:\n * var obj = new CBTInserter(root)\n * var param_1 = obj.insert(v)\n * var param_2 = obj.get_root()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val)\n# @val = val\n# @left, @right = nil, nil\n# end\n# end\n\nclass CBTInserter\n\n=begin\n :type root: TreeNode\n=end\n def initialize(root)\n\n end\n\n\n=begin\n :type v: Integer\n :rtype: Integer\n=end\n def insert(v)\n\n end\n\n\n=begin\n :rtype: TreeNode\n=end\n def get_root()\n\n end\n\n\nend\n\n# Your CBTInserter object will be instantiated and called as such:\n# obj = CBTInserter.new(root)\n# param_1 = obj.insert(v)\n# param_2 = obj.get_root()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.left = nil\n * self.right = nil\n * }\n * }\n */\n\nclass CBTInserter {\n\n init(_ root: TreeNode?) {\n \n }\n \n func insert(_ v: Int) -> Int {\n \n }\n \n func get_root() -> TreeNode? {\n \n }\n}\n\n/**\n * Your CBTInserter object will be instantiated and called as such:\n * let obj = CBTInserter(root)\n * let ret_1: Int = obj.insert(v)\n * let ret_2: TreeNode? = obj.get_root()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\ntype CBTInserter struct {\n\n}\n\n\nfunc Constructor(root *TreeNode) CBTInserter {\n\n}\n\n\nfunc (this *CBTInserter) Insert(v int) int {\n\n}\n\n\nfunc (this *CBTInserter) Get_root() *TreeNode {\n\n}\n\n\n/**\n * Your CBTInserter object will be instantiated and called as such:\n * obj := Constructor(root);\n * param_1 := obj.Insert(v);\n * param_2 := obj.Get_root();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(var _value: Int) {\n * var value: Int = _value\n * var left: TreeNode = null\n * var right: TreeNode = null\n * }\n */\nclass CBTInserter(_root: TreeNode) {\n\n def insert(v: Int): Int = {\n\n }\n\n def get_root(): TreeNode = {\n\n }\n\n}\n\n/**\n * Your CBTInserter object will be instantiated and called as such:\n * var obj = new CBTInserter(root)\n * var param_1 = obj.insert(v)\n * var param_2 = obj.get_root()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass CBTInserter(root: TreeNode?) {\n\n fun insert(v: Int): Int {\n\n }\n\n fun get_root(): TreeNode? {\n\n }\n\n}\n\n/**\n * Your CBTInserter object will be instantiated and called as such:\n * var obj = CBTInserter(root)\n * var param_1 = obj.insert(v)\n * var param_2 = obj.get_root()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n// \n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nstruct CBTInserter {\n\n}\n\n\n/** \n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl CBTInserter {\n\n fn new(root: Option>>) -> Self {\n \n }\n \n fn insert(&self, v: i32) -> i32 {\n \n }\n \n fn get_root(&self) -> Option>> {\n \n }\n}\n\n/**\n * Your CBTInserter object will be instantiated and called as such:\n * let obj = CBTInserter::new(root);\n * let ret_1: i32 = obj.insert(v);\n * let ret_2: Option>> = obj.get_root();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($value) { $this->val = $value; }\n * }\n */\nclass CBTInserter {\n /**\n * @param TreeNode $root\n */\n function __construct($root) {\n \n }\n \n /**\n * @param Integer $v\n * @return Integer\n */\n function insert($v) {\n \n }\n \n /**\n * @return TreeNode\n */\n function get_root() {\n \n }\n}\n\n/**\n * Your CBTInserter object will be instantiated and called as such:\n * $obj = CBTInserter($root);\n * $ret_1 = $obj->insert($v);\n * $ret_2 = $obj->get_root();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nclass CBTInserter {\n constructor(root: TreeNode | null) {\n\n }\n\n insert(v: number): number {\n\n }\n\n get_root(): TreeNode | null {\n\n }\n}\n\n/**\n * Your CBTInserter object will be instantiated and called as such:\n * var obj = new CBTInserter(root)\n * var param_1 = obj.insert(v)\n * var param_2 = obj.get_root()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define cbt-inserter%\n (class object%\n (super-new)\n\n ; root : (or/c tree-node? #f)\n (init-field\n root)\n \n ; insert : exact-integer? -> exact-integer?\n (define/public (insert v)\n\n )\n ; get_root : -> (or/c tree-node? #f)\n (define/public (get_root)\n\n )))\n\n;; Your cbt-inserter% object will be instantiated and called as such:\n;; (define obj (new cbt-inserter% [root root]))\n;; (define param_1 (send obj insert v))\n;; (define param_2 (send obj get_root))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0919](https://leetcode-cn.com/problems/complete-binary-tree-inserter)", "[\u5b8c\u5168\u4e8c\u53c9\u6811\u63d2\u5165\u5668](/solution/0900-0999/0919.Complete%20Binary%20Tree%20Inserter/README.md)", "`\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0919](https://leetcode.com/problems/complete-binary-tree-inserter)", "[Complete Binary Tree Inserter](/solution/0900-0999/0919.Complete%20Binary%20Tree%20Inserter/README_EN.md)", "`Tree`", "Medium", ""]}, {"question_id": "0954", "frontend_question_id": "0918", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-sum-circular-subarray", "url_en": "https://leetcode.com/problems/maximum-sum-circular-subarray", "relative_path_cn": "/solution/0900-0999/0918.Maximum%20Sum%20Circular%20Subarray/README.md", "relative_path_en": "/solution/0900-0999/0918.Maximum%20Sum%20Circular%20Subarray/README_EN.md", "title_cn": "\u73af\u5f62\u5b50\u6570\u7ec4\u7684\u6700\u5927\u548c", "title_en": "Maximum Sum Circular Subarray", "question_title_slug": "maximum-sum-circular-subarray", "content_en": "

Given a circular integer array nums of length n, return the maximum possible sum of a non-empty subarray of nums.

\n\n

A circular array means the end of the array connects to the beginning of the array. Formally, the next element of nums[i] is nums[(i + 1) % n] and the previous element of nums[i] is nums[(i - 1 + n) % n].

\n\n

A subarray may only include each element of the fixed buffer nums at most once. Formally, for a subarray nums[i], nums[i + 1], ..., nums[j], there does not exist i <= k1, k2 <= j with k1 % n == k2 % n.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [1,-2,3,-2]\nOutput: 3\nExplanation: Subarray [3] has maximum sum 3\n
\n\n

Example 2:

\n\n
\nInput: nums = [5,-3,5]\nOutput: 10\nExplanation: Subarray [5,5] has maximum sum 5 + 5 = 10\n
\n\n

Example 3:

\n\n
\nInput: nums = [3,-1,2,-1]\nOutput: 4\nExplanation: Subarray [2,-1,3] has maximum sum 2 + (-1) + 3 = 4\n
\n\n

Example 4:

\n\n
\nInput: nums = [3,-2,2,-3]\nOutput: 3\nExplanation: Subarray [3] and [3,-2,2] both have maximum sum 3\n
\n\n

Example 5:

\n\n
\nInput: nums = [-2,-3,-1]\nOutput: -1\nExplanation: Subarray [-1] has maximum sum -1\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == nums.length
  • \n\t
  • 1 <= n <= 3 * 104
  • \n\t
  • -3 * 104 <= nums[i] <= 3 * 104
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u7531\u6574\u6570\u6570\u7ec4 A \u8868\u793a\u7684\u73af\u5f62\u6570\u7ec4 C\uff0c\u6c42 C \u7684\u975e\u7a7a\u5b50\u6570\u7ec4\u7684\u6700\u5927\u53ef\u80fd\u548c\u3002

\n\n

\u5728\u6b64\u5904\uff0c\u73af\u5f62\u6570\u7ec4\u610f\u5473\u7740\u6570\u7ec4\u7684\u672b\u7aef\u5c06\u4f1a\u4e0e\u5f00\u5934\u76f8\u8fde\u5448\u73af\u72b6\u3002\uff08\u5f62\u5f0f\u4e0a\uff0c\u5f530 <= i < A.length \u65f6 C[i] = A[i]\uff0c\u4e14\u5f53 i >= 0 \u65f6 C[i+A.length] = C[i]\uff09

\n\n

\u6b64\u5916\uff0c\u5b50\u6570\u7ec4\u6700\u591a\u53ea\u80fd\u5305\u542b\u56fa\u5b9a\u7f13\u51b2\u533a A \u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u4e00\u6b21\u3002\uff08\u5f62\u5f0f\u4e0a\uff0c\u5bf9\u4e8e\u5b50\u6570\u7ec4 C[i], C[i+1], ..., C[j]\uff0c\u4e0d\u5b58\u5728 i <= k1, k2 <= j \u5176\u4e2d k1 % A.length = k2 % A.length\uff09

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a[1,-2,3,-2]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u4ece\u5b50\u6570\u7ec4 [3] \u5f97\u5230\u6700\u5927\u548c 3\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a[5,-3,5]\n\u8f93\u51fa\uff1a10\n\u89e3\u91ca\uff1a\u4ece\u5b50\u6570\u7ec4 [5,5] \u5f97\u5230\u6700\u5927\u548c 5 + 5 = 10\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1a[3,-1,2,-1]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u4ece\u5b50\u6570\u7ec4 [2,-1,3] \u5f97\u5230\u6700\u5927\u548c 2 + (-1) + 3 = 4\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1a[3,-2,2,-3]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u4ece\u5b50\u6570\u7ec4 [3] \u548c [3,-2,2] \u90fd\u53ef\u4ee5\u5f97\u5230\u6700\u5927\u548c 3\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1a[-2,-3,-1]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u4ece\u5b50\u6570\u7ec4 [-1] \u5f97\u5230\u6700\u5927\u548c -1\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. -30000 <= A[i] <= 30000
  2. \n\t
  3. 1 <= A.length <= 30000
  4. \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxSubarraySumCircular(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxSubarraySumCircular(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxSubarraySumCircular(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxSubarraySumCircular(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxSubarraySumCircular(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxSubarraySumCircular(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar maxSubarraySumCircular = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef max_subarray_sum_circular(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxSubarraySumCircular(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxSubarraySumCircular(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxSubarraySumCircular(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxSubarraySumCircular(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_subarray_sum_circular(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function maxSubarraySumCircular($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxSubarraySumCircular(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-subarray-sum-circular nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0918](https://leetcode-cn.com/problems/maximum-sum-circular-subarray)", "[\u73af\u5f62\u5b50\u6570\u7ec4\u7684\u6700\u5927\u548c](/solution/0900-0999/0918.Maximum%20Sum%20Circular%20Subarray/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0918](https://leetcode.com/problems/maximum-sum-circular-subarray)", "[Maximum Sum Circular Subarray](/solution/0900-0999/0918.Maximum%20Sum%20Circular%20Subarray/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0953", "frontend_question_id": "0917", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reverse-only-letters", "url_en": "https://leetcode.com/problems/reverse-only-letters", "relative_path_cn": "/solution/0900-0999/0917.Reverse%20Only%20Letters/README.md", "relative_path_en": "/solution/0900-0999/0917.Reverse%20Only%20Letters/README_EN.md", "title_cn": "\u4ec5\u4ec5\u53cd\u8f6c\u5b57\u6bcd", "title_en": "Reverse Only Letters", "question_title_slug": "reverse-only-letters", "content_en": "

Given a string s, return the "reversed" string where all characters that are not a letter stay in the same place, and all letters reverse their positions.

\n\n

 

\n\n
\n
\n
\n
    \n
\n
\n
\n
\n\n
\n

Example 1:

\n\n
\nInput: s = "ab-cd"\nOutput: "dc-ba"\n
\n\n
\n

Example 2:

\n\n
\nInput: s = "a-bC-dEf-ghIj"\nOutput: "j-Ih-gfE-dCba"\n
\n\n
\n

Example 3:

\n\n
\nInput: s = "Test1ng-Leet=code-Q!"\nOutput: "Qedo1ct-eeLg=ntse-T!"\n
\n\n

 

\n\n
\n

Note:

\n\n
    \n\t
  1. s.length <= 100
  2. \n\t
  3. 33 <= s[i].ASCIIcode <= 122 
  4. \n\t
  5. s doesn't contain \\ or "
  6. \n
\n
\n
\n
\n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32 S\uff0c\u8fd4\u56de “\u53cd\u8f6c\u540e\u7684” \u5b57\u7b26\u4e32\uff0c\u5176\u4e2d\u4e0d\u662f\u5b57\u6bcd\u7684\u5b57\u7b26\u90fd\u4fdd\u7559\u5728\u539f\u5730\uff0c\u800c\u6240\u6709\u5b57\u6bcd\u7684\u4f4d\u7f6e\u53d1\u751f\u53cd\u8f6c\u3002

\n\n

 

\n\n
    \n
\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a"ab-cd"\n\u8f93\u51fa\uff1a"dc-ba"\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a"a-bC-dEf-ghIj"\n\u8f93\u51fa\uff1a"j-Ih-gfE-dCba"\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1a"Test1ng-Leet=code-Q!"\n\u8f93\u51fa\uff1a"Qedo1ct-eeLg=ntse-T!"\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. S.length <= 100
  2. \n\t
  3. 33 <= S[i].ASCIIcode <= 122 
  4. \n\t
  5. S \u4e2d\u4e0d\u5305\u542b \\ or "
  6. \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string reverseOnlyLetters(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String reverseOnlyLetters(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def reverseOnlyLetters(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def reverseOnlyLetters(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * reverseOnlyLetters(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ReverseOnlyLetters(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar reverseOnlyLetters = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef reverse_only_letters(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func reverseOnlyLetters(_ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func reverseOnlyLetters(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def reverseOnlyLetters(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun reverseOnlyLetters(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn reverse_only_letters(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function reverseOnlyLetters($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function reverseOnlyLetters(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (reverse-only-letters s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0917](https://leetcode-cn.com/problems/reverse-only-letters)", "[\u4ec5\u4ec5\u53cd\u8f6c\u5b57\u6bcd](/solution/0900-0999/0917.Reverse%20Only%20Letters/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0917](https://leetcode.com/problems/reverse-only-letters)", "[Reverse Only Letters](/solution/0900-0999/0917.Reverse%20Only%20Letters/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "0952", "frontend_question_id": "0916", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/word-subsets", "url_en": "https://leetcode.com/problems/word-subsets", "relative_path_cn": "/solution/0900-0999/0916.Word%20Subsets/README.md", "relative_path_en": "/solution/0900-0999/0916.Word%20Subsets/README_EN.md", "title_cn": "\u5355\u8bcd\u5b50\u96c6", "title_en": "Word Subsets", "question_title_slug": "word-subsets", "content_en": "

We are given two arrays words1 and words2 of words.  Each word is a string of lowercase letters.

\n\n

Now, say that word b is a subset of word a if every letter in b occurs in a, including multiplicity.  For example, "wrr" is a subset of "warrior", but is not a subset of "world".

\n\n

Now say a word a from words1 is universal if for every b in words2, b is a subset of a

\n\n

Return a list of all universal words in words1.  You can return the words in any order.

\n\n

 

\n\n
    \n
\n\n
\n

Example 1:

\n\n
\nInput: words1 = ["amazon","apple","facebook","google","leetcode"], words2 = ["e","o"]\nOutput: ["facebook","google","leetcode"]\n
\n\n
\n

Example 2:

\n\n
\nInput: words1 = ["amazon","apple","facebook","google","leetcode"], words2 = ["l","e"]\nOutput: ["apple","google","leetcode"]\n
\n\n
\n

Example 3:

\n\n
\nInput: words1 = ["amazon","apple","facebook","google","leetcode"], words2 = ["e","oo"]\nOutput: ["facebook","google"]\n
\n\n
\n

Example 4:

\n\n
\nInput: words1 = ["amazon","apple","facebook","google","leetcode"], words2 = ["lo","eo"]\nOutput: ["google","leetcode"]\n
\n\n
\n

Example 5:

\n\n
\nInput: words1 = ["amazon","apple","facebook","google","leetcode"], words2 = ["ec","oc","ceo"]\nOutput: ["facebook","leetcode"]\n
\n\n

 

\n\n

Note:

\n\n
    \n\t
  1. 1 <= words1.length, words2.length <= 10000
  2. \n\t
  3. 1 <= words1[i].length, words2[i].length <= 10
  4. \n\t
  5. words1[i] and words2[i] consist only of lowercase letters.
  6. \n\t
  7. All words in words1[i] are unique: there isn't i != j with words1[i] == words1[j].
  8. \n
\n
\n
\n
\n
\n
\n", "content_cn": "

\u6211\u4eec\u7ed9\u51fa\u4e24\u4e2a\u5355\u8bcd\u6570\u7ec4 A \u548c B\u3002\u6bcf\u4e2a\u5355\u8bcd\u90fd\u662f\u4e00\u4e32\u5c0f\u5199\u5b57\u6bcd\u3002

\n\n

\u73b0\u5728\uff0c\u5982\u679c b \u4e2d\u7684\u6bcf\u4e2a\u5b57\u6bcd\u90fd\u51fa\u73b0\u5728 a \u4e2d\uff0c\u5305\u62ec\u91cd\u590d\u51fa\u73b0\u7684\u5b57\u6bcd\uff0c\u90a3\u4e48\u79f0\u5355\u8bcd b \u662f\u5355\u8bcd a \u7684\u5b50\u96c6\u3002 \u4f8b\u5982\uff0c“wrr” \u662f “warrior” \u7684\u5b50\u96c6\uff0c\u4f46\u4e0d\u662f “world” \u7684\u5b50\u96c6\u3002

\n\n

\u5982\u679c\u5bf9 B \u4e2d\u7684\u6bcf\u4e00\u4e2a\u5355\u8bcd b\uff0cb \u90fd\u662f a \u7684\u5b50\u96c6\uff0c\u90a3\u4e48\u6211\u4eec\u79f0 A \u4e2d\u7684\u5355\u8bcd a \u662f\u901a\u7528\u7684\u3002

\n\n

\u4f60\u53ef\u4ee5\u6309\u4efb\u610f\u987a\u5e8f\u4ee5\u5217\u8868\u5f62\u5f0f\u8fd4\u56de A \u4e2d\u6240\u6709\u7684\u901a\u7528\u5355\u8bcd\u3002

\n\n

 

\n\n
    \n
\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aA = ["amazon","apple","facebook","google","leetcode"], B = ["e","o"]\n\u8f93\u51fa\uff1a["facebook","google","leetcode"]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aA = ["amazon","apple","facebook","google","leetcode"], B = ["l","e"]\n\u8f93\u51fa\uff1a["apple","google","leetcode"]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aA = ["amazon","apple","facebook","google","leetcode"], B = ["e","oo"]\n\u8f93\u51fa\uff1a["facebook","google"]\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1aA = ["amazon","apple","facebook","google","leetcode"], B = ["lo","eo"]\n\u8f93\u51fa\uff1a["google","leetcode"]\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1aA = ["amazon","apple","facebook","google","leetcode"], B = ["ec","oc","ceo"]\n\u8f93\u51fa\uff1a["facebook","leetcode"]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= A.length, B.length <= 10000
  2. \n\t
  3. 1 <= A[i].length, B[i].length <= 10
  4. \n\t
  5. A[i] \u548c B[i] \u53ea\u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210\u3002
  6. \n\t
  7. A[i] \u4e2d\u6240\u6709\u7684\u5355\u8bcd\u90fd\u662f\u72ec\u4e00\u65e0\u4e8c\u7684\uff0c\u4e5f\u5c31\u662f\u8bf4\u4e0d\u5b58\u5728 i != j \u4f7f\u5f97 A[i] == A[j]\u3002
  8. \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector wordSubsets(vector& words1, vector& words2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List wordSubsets(String[] words1, String[] words2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def wordSubsets(self, words1, words2):\n \"\"\"\n :type words1: List[str]\n :type words2: List[str]\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def wordSubsets(self, words1: List[str], words2: List[str]) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** wordSubsets(char ** words1, int words1Size, char ** words2, int words2Size, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList WordSubsets(string[] words1, string[] words2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words1\n * @param {string[]} words2\n * @return {string[]}\n */\nvar wordSubsets = function(words1, words2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words1\n# @param {String[]} words2\n# @return {String[]}\ndef word_subsets(words1, words2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func wordSubsets(_ words1: [String], _ words2: [String]) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func wordSubsets(words1 []string, words2 []string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def wordSubsets(words1: Array[String], words2: Array[String]): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun wordSubsets(words1: Array, words2: Array): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn word_subsets(words1: Vec, words2: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words1\n * @param String[] $words2\n * @return String[]\n */\n function wordSubsets($words1, $words2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function wordSubsets(words1: string[], words2: string[]): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (word-subsets words1 words2)\n (-> (listof string?) (listof string?) (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0916](https://leetcode-cn.com/problems/word-subsets)", "[\u5355\u8bcd\u5b50\u96c6](/solution/0900-0999/0916.Word%20Subsets/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0916](https://leetcode.com/problems/word-subsets)", "[Word Subsets](/solution/0900-0999/0916.Word%20Subsets/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "0951", "frontend_question_id": "0915", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/partition-array-into-disjoint-intervals", "url_en": "https://leetcode.com/problems/partition-array-into-disjoint-intervals", "relative_path_cn": "/solution/0900-0999/0915.Partition%20Array%20into%20Disjoint%20Intervals/README.md", "relative_path_en": "/solution/0900-0999/0915.Partition%20Array%20into%20Disjoint%20Intervals/README_EN.md", "title_cn": "\u5206\u5272\u6570\u7ec4", "title_en": "Partition Array into Disjoint Intervals", "question_title_slug": "partition-array-into-disjoint-intervals", "content_en": "

Given an array nums, partition it into two (contiguous) subarrays left and right so that:

\n\n
    \n\t
  • Every element in left is less than or equal to every element in right.
  • \n\t
  • left and right are non-empty.
  • \n\t
  • left has the smallest possible size.
  • \n
\n\n

Return the length of left after such a partitioning.  It is guaranteed that such a partitioning exists.

\n\n

 

\n\n

Example 1:

\n\n
\nInput: nums = [5,0,3,8,6]\nOutput: 3\nExplanation: left = [5,0,3], right = [8,6]\n
\n\n
\n

Example 2:

\n\n
\nInput: nums = [1,1,1,0,6,12]\nOutput: 4\nExplanation: left = [1,1,1,0], right = [6,12]\n
\n\n

 

\n
\n\n

Note:

\n\n
    \n\t
  1. 2 <= nums.length <= 30000
  2. \n\t
  3. 0 <= nums[i] <= 106
  4. \n\t
  5. It is guaranteed there is at least one way to partition nums as described.
  6. \n
\n\n
\n
 
\n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u6570\u7ec4\u00a0A\uff0c\u5c06\u5176\u5212\u5206\u4e3a\u4e24\u4e2a\u8fde\u7eed\u5b50\u6570\u7ec4\u00a0left\u00a0\u548c\u00a0right\uff0c\u00a0\u4f7f\u5f97\uff1a

\n\n
    \n\t
  • left\u00a0\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u90fd\u5c0f\u4e8e\u6216\u7b49\u4e8e\u00a0right\u00a0\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u3002
  • \n\t
  • left \u548c\u00a0right\u00a0\u90fd\u662f\u975e\u7a7a\u7684\u3002
  • \n\t
  • left \u7684\u957f\u5ea6\u8981\u5c3d\u53ef\u80fd\u5c0f\u3002
  • \n
\n\n

\u5728\u5b8c\u6210\u8fd9\u6837\u7684\u5206\u7ec4\u540e\u8fd4\u56de\u00a0left\u00a0\u7684\u957f\u5ea6\u3002\u53ef\u4ee5\u4fdd\u8bc1\u5b58\u5728\u8fd9\u6837\u7684\u5212\u5206\u65b9\u6cd5\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1a[5,0,3,8,6]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1aleft = [5,0,3]\uff0cright = [8,6]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1a[1,1,1,0,6,12]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1aleft = [1,1,1,0]\uff0cright = [6,12]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 2 <= A.length\u00a0<= 30000
  2. \n\t
  3. 0 <= A[i] <= 10^6
  4. \n\t
  5. \u53ef\u4ee5\u4fdd\u8bc1\u81f3\u5c11\u6709\u4e00\u79cd\u65b9\u6cd5\u80fd\u591f\u6309\u9898\u76ee\u6240\u63cf\u8ff0\u7684\u90a3\u6837\u5bf9 A \u8fdb\u884c\u5212\u5206\u3002
  6. \n
\n\n

\u00a0

\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int partitionDisjoint(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int partitionDisjoint(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def partitionDisjoint(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def partitionDisjoint(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint partitionDisjoint(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int PartitionDisjoint(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar partitionDisjoint = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef partition_disjoint(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func partitionDisjoint(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func partitionDisjoint(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def partitionDisjoint(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun partitionDisjoint(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn partition_disjoint(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function partitionDisjoint($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function partitionDisjoint(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (partition-disjoint nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0915](https://leetcode-cn.com/problems/partition-array-into-disjoint-intervals)", "[\u5206\u5272\u6570\u7ec4](/solution/0900-0999/0915.Partition%20Array%20into%20Disjoint%20Intervals/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0915](https://leetcode.com/problems/partition-array-into-disjoint-intervals)", "[Partition Array into Disjoint Intervals](/solution/0900-0999/0915.Partition%20Array%20into%20Disjoint%20Intervals/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0950", "frontend_question_id": "0914", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/x-of-a-kind-in-a-deck-of-cards", "url_en": "https://leetcode.com/problems/x-of-a-kind-in-a-deck-of-cards", "relative_path_cn": "/solution/0900-0999/0914.X%20of%20a%20Kind%20in%20a%20Deck%20of%20Cards/README.md", "relative_path_en": "/solution/0900-0999/0914.X%20of%20a%20Kind%20in%20a%20Deck%20of%20Cards/README_EN.md", "title_cn": "\u5361\u724c\u5206\u7ec4", "title_en": "X of a Kind in a Deck of Cards", "question_title_slug": "x-of-a-kind-in-a-deck-of-cards", "content_en": "

In a deck of cards, each card has an integer written on it.

\n\n

Return true if and only if you can choose X >= 2 such that it is possible to split the entire deck into 1 or more groups of cards, where:

\n\n
    \n\t
  • Each group has exactly X cards.
  • \n\t
  • All the cards in each group have the same integer.
  • \n
\n\n

 

\n

Example 1:

\n\n
\nInput: deck = [1,2,3,4,4,3,2,1]\nOutput: true\nExplanation: Possible partition [1,1],[2,2],[3,3],[4,4].\n
\n\n

Example 2:

\n\n
\nInput: deck = [1,1,1,2,2,2,3,3]\nOutput: false\nExplanation: No possible partition.\n
\n\n

Example 3:

\n\n
\nInput: deck = [1]\nOutput: false\nExplanation: No possible partition.\n
\n\n

Example 4:

\n\n
\nInput: deck = [1,1]\nOutput: true\nExplanation: Possible partition [1,1].\n
\n\n

Example 5:

\n\n
\nInput: deck = [1,1,2,2,2,2]\nOutput: true\nExplanation: Possible partition [1,1],[2,2],[2,2].\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= deck.length <= 104
  • \n\t
  • 0 <= deck[i] < 104
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u526f\u724c\uff0c\u6bcf\u5f20\u724c\u4e0a\u90fd\u5199\u7740\u4e00\u4e2a\u6574\u6570\u3002

\n\n

\u6b64\u65f6\uff0c\u4f60\u9700\u8981\u9009\u5b9a\u4e00\u4e2a\u6570\u5b57 X\uff0c\u4f7f\u6211\u4eec\u53ef\u4ee5\u5c06\u6574\u526f\u724c\u6309\u4e0b\u8ff0\u89c4\u5219\u5206\u6210 1 \u7ec4\u6216\u66f4\u591a\u7ec4\uff1a

\n\n
    \n\t
  • \u6bcf\u7ec4\u90fd\u6709 X \u5f20\u724c\u3002
  • \n\t
  • \u7ec4\u5185\u6240\u6709\u7684\u724c\u4e0a\u90fd\u5199\u7740\u76f8\u540c\u7684\u6574\u6570\u3002
  • \n
\n\n

\u4ec5\u5f53\u4f60\u53ef\u9009\u7684 X >= 2 \u65f6\u8fd4\u56de true\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a[1,2,3,4,4,3,2,1]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u53ef\u884c\u7684\u5206\u7ec4\u662f [1,1]\uff0c[2,2]\uff0c[3,3]\uff0c[4,4]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a[1,1,1,2,2,2,3,3]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u6ca1\u6709\u6ee1\u8db3\u8981\u6c42\u7684\u5206\u7ec4\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1a[1]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u6ca1\u6709\u6ee1\u8db3\u8981\u6c42\u7684\u5206\u7ec4\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1a[1,1]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u53ef\u884c\u7684\u5206\u7ec4\u662f [1,1]\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1a[1,1,2,2,2,2]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u53ef\u884c\u7684\u5206\u7ec4\u662f [1,1]\uff0c[2,2]\uff0c[2,2]\n
\n\n


\n\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= deck.length <= 10000
  2. \n\t
  3. 0 <= deck[i] < 10000
  4. \n
\n\n

 

\n", "tags_en": ["Array", "Math"], "tags_cn": ["\u6570\u7ec4", "\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool hasGroupsSizeX(vector& deck) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean hasGroupsSizeX(int[] deck) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def hasGroupsSizeX(self, deck):\n \"\"\"\n :type deck: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def hasGroupsSizeX(self, deck: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool hasGroupsSizeX(int* deck, int deckSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool HasGroupsSizeX(int[] deck) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} deck\n * @return {boolean}\n */\nvar hasGroupsSizeX = function(deck) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} deck\n# @return {Boolean}\ndef has_groups_size_x(deck)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func hasGroupsSizeX(_ deck: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func hasGroupsSizeX(deck []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def hasGroupsSizeX(deck: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun hasGroupsSizeX(deck: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn has_groups_size_x(deck: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $deck\n * @return Boolean\n */\n function hasGroupsSizeX($deck) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function hasGroupsSizeX(deck: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (has-groups-size-x deck)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0914](https://leetcode-cn.com/problems/x-of-a-kind-in-a-deck-of-cards)", "[\u5361\u724c\u5206\u7ec4](/solution/0900-0999/0914.X%20of%20a%20Kind%20in%20a%20Deck%20of%20Cards/README.md)", "`\u6570\u7ec4`,`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0914](https://leetcode.com/problems/x-of-a-kind-in-a-deck-of-cards)", "[X of a Kind in a Deck of Cards](/solution/0900-0999/0914.X%20of%20a%20Kind%20in%20a%20Deck%20of%20Cards/README_EN.md)", "`Array`,`Math`", "Easy", ""]}, {"question_id": "0949", "frontend_question_id": "0913", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/cat-and-mouse", "url_en": "https://leetcode.com/problems/cat-and-mouse", "relative_path_cn": "/solution/0900-0999/0913.Cat%20and%20Mouse/README.md", "relative_path_en": "/solution/0900-0999/0913.Cat%20and%20Mouse/README_EN.md", "title_cn": "\u732b\u548c\u8001\u9f20", "title_en": "Cat and Mouse", "question_title_slug": "cat-and-mouse", "content_en": "

A game on an undirected graph is played by two players, Mouse and Cat, who alternate turns.

\n\n

The graph is given as follows: graph[a] is a list of all nodes b such that ab is an edge of the graph.

\n\n

The mouse starts at node 1 and goes first, the cat starts at node 2 and goes second, and there is a hole at node 0.

\n\n

During each player's turn, they must travel along one edge of the graph that meets where they are.  For example, if the Mouse is at node 1, it must travel to any node in graph[1].

\n\n

Additionally, it is not allowed for the Cat to travel to the Hole (node 0.)

\n\n

Then, the game can end in three ways:

\n\n
    \n\t
  • If ever the Cat occupies the same node as the Mouse, the Cat wins.
  • \n\t
  • If ever the Mouse reaches the Hole, the Mouse wins.
  • \n\t
  • If ever a position is repeated (i.e., the players are in the same position as a previous turn, and it is the same player's turn to move), the game is a draw.
  • \n
\n\n

Given a graph, and assuming both players play optimally, return

\n\n
    \n\t
  • 1 if the mouse wins the game,
  • \n\t
  • 2 if the cat wins the game, or
  • \n\t
  • 0 if the game is a draw.
  • \n
\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: graph = [[2,5],[3],[0,4,5],[1,4,5],[2,3],[0,2,3]]\nOutput: 0\n
\n\n

Example 2:

\n\"\"\n
\nInput: graph = [[1,3],[0],[3],[0,2]]\nOutput: 1\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 3 <= graph.length <= 50
  • \n\t
  • 1 <= graph[i].length < graph.length
  • \n\t
  • 0 <= graph[i][j] < graph.length
  • \n\t
  • graph[i][j] != i
  • \n\t
  • graph[i] is unique.
  • \n\t
  • The mouse and the cat can always move. 
  • \n
\n", "content_cn": "

\u4e24\u4e2a\u73a9\u5bb6\u5206\u522b\u626e\u6f14\u732b\uff08Cat\uff09\u548c\u8001\u9f20\uff08Mouse\uff09\u5728\u65e0\u5411\u56fe\u4e0a\u8fdb\u884c\u6e38\u620f\uff0c\u4ed6\u4eec\u8f6e\u6d41\u884c\u52a8\u3002

\n\n

\u8be5\u56fe\u6309\u4e0b\u8ff0\u89c4\u5219\u7ed9\u51fa\uff1agraph[a] \u662f\u6240\u6709\u7ed3\u70b9 b \u7684\u5217\u8868\uff0c\u4f7f\u5f97 ab \u662f\u56fe\u7684\u4e00\u6761\u8fb9\u3002

\n\n

\u8001\u9f20\u4ece\u7ed3\u70b9 1 \u5f00\u59cb\u5e76\u7387\u5148\u51fa\u53d1\uff0c\u732b\u4ece\u7ed3\u70b9 2 \u5f00\u59cb\u4e14\u968f\u540e\u51fa\u53d1\uff0c\u5728\u7ed3\u70b9 0 \u5904\u6709\u4e00\u4e2a\u6d1e\u3002

\n\n

\u5728\u6bcf\u4e2a\u73a9\u5bb6\u7684\u56de\u5408\u4e2d\uff0c\u4ed6\u4eec\u5fc5\u987b\u6cbf\u7740\u4e0e\u4ed6\u4eec\u6240\u5728\u4f4d\u7f6e\u76f8\u543b\u5408\u7684\u56fe\u7684\u4e00\u6761\u8fb9\u79fb\u52a8\u3002\u4f8b\u5982\uff0c\u5982\u679c\u8001\u9f20\u4f4d\u4e8e\u7ed3\u70b9 1\uff0c\u90a3\u4e48\u5b83\u53ea\u80fd\u79fb\u52a8\u5230 graph[1] \u4e2d\u7684\uff08\u4efb\u4f55\uff09\u7ed3\u70b9\u53bb\u3002

\n\n

\u6b64\u5916\uff0c\u732b\u65e0\u6cd5\u79fb\u52a8\u5230\u6d1e\uff08\u7ed3\u70b9 0\uff09\u91cc\u3002

\n\n

\u7136\u540e\uff0c\u6e38\u620f\u5728\u51fa\u73b0\u4ee5\u4e0b\u4e09\u79cd\u60c5\u5f62\u4e4b\u4e00\u65f6\u7ed3\u675f\uff1a

\n\n
    \n\t
  • \u5982\u679c\u732b\u548c\u8001\u9f20\u5360\u636e\u76f8\u540c\u7684\u7ed3\u70b9\uff0c\u732b\u83b7\u80dc\u3002
  • \n\t
  • \u5982\u679c\u8001\u9f20\u8eb2\u5165\u6d1e\u91cc\uff0c\u8001\u9f20\u83b7\u80dc\u3002
  • \n\t
  • \u5982\u679c\u67d0\u4e00\u4f4d\u7f6e\u91cd\u590d\u51fa\u73b0\uff08\u5373\uff0c\u73a9\u5bb6\u4eec\u7684\u4f4d\u7f6e\u548c\u79fb\u52a8\u987a\u5e8f\u90fd\u4e0e\u4e0a\u4e00\u4e2a\u56de\u5408\u76f8\u540c\uff09\uff0c\u6e38\u620f\u5e73\u5c40\u3002
  • \n
\n\n

\u7ed9\u5b9a graph\uff0c\u5e76\u5047\u8bbe\u4e24\u4e2a\u73a9\u5bb6\u90fd\u4ee5\u6700\u4f73\u72b6\u6001\u53c2\u4e0e\u6e38\u620f\uff0c\u5982\u679c\u8001\u9f20\u83b7\u80dc\uff0c\u5219\u8fd4\u56de 1\uff1b\u5982\u679c\u732b\u83b7\u80dc\uff0c\u5219\u8fd4\u56de 2\uff1b\u5982\u679c\u5e73\u5c40\uff0c\u5219\u8fd4\u56de 0\u3002

\n\n

 

\n\n
    \n
\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1a[[2,5],[3],[0,4,5],[1,4,5],[2,3],[0,2,3]]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\n4---3---1\n|   |\n2---5\n \\ /\n  0\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 3 <= graph.length <= 200
  2. \n\t
  3. \u4fdd\u8bc1 graph[1] \u975e\u7a7a\u3002
  4. \n\t
  5. \u4fdd\u8bc1 graph[2] \u5305\u542b\u975e\u96f6\u5143\u7d20\u3002
  6. \n
\n", "tags_en": ["Breadth-first Search", "Minimax"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u6781\u5c0f\u5316\u6781\u5927"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int catMouseGame(vector>& graph) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int catMouseGame(int[][] graph) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def catMouseGame(self, graph):\n \"\"\"\n :type graph: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def catMouseGame(self, graph: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint catMouseGame(int** graph, int graphSize, int* graphColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CatMouseGame(int[][] graph) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} graph\n * @return {number}\n */\nvar catMouseGame = function(graph) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} graph\n# @return {Integer}\ndef cat_mouse_game(graph)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func catMouseGame(_ graph: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func catMouseGame(graph [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def catMouseGame(graph: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun catMouseGame(graph: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn cat_mouse_game(graph: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $graph\n * @return Integer\n */\n function catMouseGame($graph) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function catMouseGame(graph: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (cat-mouse-game graph)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0913](https://leetcode-cn.com/problems/cat-and-mouse)", "[\u732b\u548c\u8001\u9f20](/solution/0900-0999/0913.Cat%20and%20Mouse/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u6781\u5c0f\u5316\u6781\u5927`", "\u56f0\u96be", ""], "md_table_row_en": ["[0913](https://leetcode.com/problems/cat-and-mouse)", "[Cat and Mouse](/solution/0900-0999/0913.Cat%20and%20Mouse/README_EN.md)", "`Breadth-first Search`,`Minimax`", "Hard", ""]}, {"question_id": "0948", "frontend_question_id": "0912", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sort-an-array", "url_en": "https://leetcode.com/problems/sort-an-array", "relative_path_cn": "/solution/0900-0999/0912.Sort%20an%20Array/README.md", "relative_path_en": "/solution/0900-0999/0912.Sort%20an%20Array/README_EN.md", "title_cn": "\u6392\u5e8f\u6570\u7ec4", "title_en": "Sort an Array", "question_title_slug": "sort-an-array", "content_en": "

Given an array of integers nums, sort the array in ascending order.

\n\n

 

\n

Example 1:

\n
Input: nums = [5,2,3,1]\nOutput: [1,2,3,5]\n

Example 2:

\n
Input: nums = [5,1,1,2,0,0]\nOutput: [0,0,1,1,2,5]\n
\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 5 * 104
  • \n\t
  • -5 * 104 <= nums[i] <= 5 * 104
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums\uff0c\u8bf7\u4f60\u5c06\u8be5\u6570\u7ec4\u5347\u5e8f\u6392\u5217\u3002

\n\n

 

\n\n
    \n
\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1anums = [5,2,3,1]\n\u8f93\u51fa\uff1a[1,2,3,5]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1anums = [5,1,1,2,0,0]\n\u8f93\u51fa\uff1a[0,0,1,1,2,5]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= nums.length <= 50000
  2. \n\t
  3. -50000 <= nums[i] <= 50000
  4. \n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector sortArray(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] sortArray(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def sortArray(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def sortArray(self, nums: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* sortArray(int* nums, int numsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] SortArray(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar sortArray = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer[]}\ndef sort_array(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func sortArray(_ nums: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func sortArray(nums []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def sortArray(nums: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun sortArray(nums: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sort_array(nums: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer[]\n */\n function sortArray($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function sortArray(nums: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (sort-array nums)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0912](https://leetcode-cn.com/problems/sort-an-array)", "[\u6392\u5e8f\u6570\u7ec4](/solution/0900-0999/0912.Sort%20an%20Array/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0912](https://leetcode.com/problems/sort-an-array)", "[Sort an Array](/solution/0900-0999/0912.Sort%20an%20Array/README_EN.md)", "", "Medium", ""]}, {"question_id": "0947", "frontend_question_id": "0911", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/online-election", "url_en": "https://leetcode.com/problems/online-election", "relative_path_cn": "/solution/0900-0999/0911.Online%20Election/README.md", "relative_path_en": "/solution/0900-0999/0911.Online%20Election/README_EN.md", "title_cn": "\u5728\u7ebf\u9009\u4e3e", "title_en": "Online Election", "question_title_slug": "online-election", "content_en": "

In an election, the i-th vote was cast for persons[i] at time times[i].

\r\n\r\n

Now, we would like to implement the following query function: TopVotedCandidate.q(int t) will return the number of the person that was leading the election at time t.  

\r\n\r\n

Votes cast at time t will count towards our query.  In the case of a tie, the most recent vote (among tied candidates) wins.

\r\n\r\n

 

\r\n\r\n
\r\n

Example 1:

\r\n\r\n
\r\nInput: ["TopVotedCandidate","q","q","q","q","q","q"], [[[0,1,1,0,0,1,0],[0,5,10,15,20,25,30]],[3],[12],[25],[15],[24],[8]]\r\nOutput: [null,0,1,1,0,0,1]\r\nExplanation: \r\nAt time 3, the votes are [0], and 0 is leading.\r\nAt time 12, the votes are [0,1,1], and 1 is leading.\r\nAt time 25, the votes are [0,1,1,0,0,1], and 1 is leading (as ties go to the most recent vote.)\r\nThis continues for 3 more queries at time 15, 24, and 8.\r\n
\r\n\r\n

 

\r\n\r\n

Note:

\r\n\r\n
    \r\n\t
  1. 1 <= persons.length = times.length <= 5000
  2. \r\n\t
  3. 0 <= persons[i] <= persons.length
  4. \r\n\t
  5. times is a strictly increasing array with all elements in [0, 10^9].
  6. \r\n\t
  7. TopVotedCandidate.q is called at most 10000 times per test case.
  8. \r\n\t
  9. TopVotedCandidate.q(int t) is always called with t >= times[0].
  10. \r\n
\r\n
\r\n", "content_cn": "

\u5728\u9009\u4e3e\u4e2d\uff0c\u7b2c i \u5f20\u7968\u662f\u5728\u65f6\u95f4\u4e3a times[i] \u65f6\u6295\u7ed9 persons[i] \u7684\u3002

\n\n

\u73b0\u5728\uff0c\u6211\u4eec\u60f3\u8981\u5b9e\u73b0\u4e0b\u9762\u7684\u67e5\u8be2\u51fd\u6570\uff1a TopVotedCandidate.q(int t) \u5c06\u8fd4\u56de\u5728 t \u65f6\u523b\u4e3b\u5bfc\u9009\u4e3e\u7684\u5019\u9009\u4eba\u7684\u7f16\u53f7\u3002

\n\n

\u5728 t \u65f6\u523b\u6295\u51fa\u7684\u9009\u7968\u4e5f\u5c06\u88ab\u8ba1\u5165\u6211\u4eec\u7684\u67e5\u8be2\u4e4b\u4e2d\u3002\u5728\u5e73\u5c40\u7684\u60c5\u51b5\u4e0b\uff0c\u6700\u8fd1\u83b7\u5f97\u6295\u7968\u7684\u5019\u9009\u4eba\u5c06\u4f1a\u83b7\u80dc\u3002

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1a["TopVotedCandidate","q","q","q","q","q","q"], [[[0,1,1,0,0,1,0],[0,5,10,15,20,25,30]],[3],[12],[25],[15],[24],[8]]\n\u8f93\u51fa\uff1a[null,0,1,1,0,0,1]\n\u89e3\u91ca\uff1a\n\u65f6\u95f4\u4e3a 3\uff0c\u7968\u6570\u5206\u5e03\u60c5\u51b5\u662f [0]\uff0c\u7f16\u53f7\u4e3a 0 \u7684\u5019\u9009\u4eba\u9886\u5148\u3002\n\u65f6\u95f4\u4e3a 12\uff0c\u7968\u6570\u5206\u5e03\u60c5\u51b5\u662f [0,1,1]\uff0c\u7f16\u53f7\u4e3a 1 \u7684\u5019\u9009\u4eba\u9886\u5148\u3002\n\u65f6\u95f4\u4e3a 25\uff0c\u7968\u6570\u5206\u5e03\u60c5\u51b5\u662f [0,1,1,0,0,1]\uff0c\u7f16\u53f7\u4e3a 1 \u7684\u5019\u9009\u4eba\u9886\u5148\uff08\u56e0\u4e3a\u6700\u8fd1\u7684\u6295\u7968\u7ed3\u679c\u662f\u5e73\u5c40\uff09\u3002\n\u5728\u65f6\u95f4 15\u300124 \u548c 8 \u5904\u7ee7\u7eed\u6267\u884c 3 \u4e2a\u67e5\u8be2\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= persons.length = times.length <= 5000
  2. \n\t
  3. 0 <= persons[i] <= persons.length
  4. \n\t
  5. times \u662f\u4e25\u683c\u9012\u589e\u7684\u6570\u7ec4\uff0c\u6240\u6709\u5143\u7d20\u90fd\u5728 [0, 10^9] \u8303\u56f4\u4e2d\u3002
  6. \n\t
  7. \u6bcf\u4e2a\u6d4b\u8bd5\u7528\u4f8b\u6700\u591a\u8c03\u7528 10000 \u6b21 TopVotedCandidate.q\u3002
  8. \n\t
  9. TopVotedCandidate.q(int t) \u88ab\u8c03\u7528\u65f6\u603b\u662f\u6ee1\u8db3 t >= times[0]\u3002
  10. \n
\n", "tags_en": ["Binary Search"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class TopVotedCandidate {\npublic:\n TopVotedCandidate(vector& persons, vector& times) {\n\n }\n \n int q(int t) {\n\n }\n};\n\n/**\n * Your TopVotedCandidate object will be instantiated and called as such:\n * TopVotedCandidate* obj = new TopVotedCandidate(persons, times);\n * int param_1 = obj->q(t);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class TopVotedCandidate {\n\n public TopVotedCandidate(int[] persons, int[] times) {\n\n }\n \n public int q(int t) {\n\n }\n}\n\n/**\n * Your TopVotedCandidate object will be instantiated and called as such:\n * TopVotedCandidate obj = new TopVotedCandidate(persons, times);\n * int param_1 = obj.q(t);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class TopVotedCandidate(object):\n\n def __init__(self, persons, times):\n \"\"\"\n :type persons: List[int]\n :type times: List[int]\n \"\"\"\n \n\n def q(self, t):\n \"\"\"\n :type t: int\n :rtype: int\n \"\"\"\n \n\n\n# Your TopVotedCandidate object will be instantiated and called as such:\n# obj = TopVotedCandidate(persons, times)\n# param_1 = obj.q(t)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class TopVotedCandidate:\n\n def __init__(self, persons: List[int], times: List[int]):\n \n\n def q(self, t: int) -> int:\n \n\n\n# Your TopVotedCandidate object will be instantiated and called as such:\n# obj = TopVotedCandidate(persons, times)\n# param_1 = obj.q(t)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} TopVotedCandidate;\n\n\nTopVotedCandidate* topVotedCandidateCreate(int* persons, int personsSize, int* times, int timesSize) {\n \n}\n\nint topVotedCandidateQ(TopVotedCandidate* obj, int t) {\n \n}\n\nvoid topVotedCandidateFree(TopVotedCandidate* obj) {\n \n}\n\n/**\n * Your TopVotedCandidate struct will be instantiated and called as such:\n * TopVotedCandidate* obj = topVotedCandidateCreate(persons, personsSize, times, timesSize);\n * int param_1 = topVotedCandidateQ(obj, t);\n \n * topVotedCandidateFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class TopVotedCandidate {\n\n public TopVotedCandidate(int[] persons, int[] times) {\n\n }\n \n public int Q(int t) {\n\n }\n}\n\n/**\n * Your TopVotedCandidate object will be instantiated and called as such:\n * TopVotedCandidate obj = new TopVotedCandidate(persons, times);\n * int param_1 = obj.Q(t);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} persons\n * @param {number[]} times\n */\nvar TopVotedCandidate = function(persons, times) {\n\n};\n\n/** \n * @param {number} t\n * @return {number}\n */\nTopVotedCandidate.prototype.q = function(t) {\n\n};\n\n/**\n * Your TopVotedCandidate object will be instantiated and called as such:\n * var obj = new TopVotedCandidate(persons, times)\n * var param_1 = obj.q(t)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class TopVotedCandidate\n\n=begin\n :type persons: Integer[]\n :type times: Integer[]\n=end\n def initialize(persons, times)\n\n end\n\n\n=begin\n :type t: Integer\n :rtype: Integer\n=end\n def q(t)\n\n end\n\n\nend\n\n# Your TopVotedCandidate object will be instantiated and called as such:\n# obj = TopVotedCandidate.new(persons, times)\n# param_1 = obj.q(t)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass TopVotedCandidate {\n\n init(_ persons: [Int], _ times: [Int]) {\n \n }\n \n func q(_ t: Int) -> Int {\n \n }\n}\n\n/**\n * Your TopVotedCandidate object will be instantiated and called as such:\n * let obj = TopVotedCandidate(persons, times)\n * let ret_1: Int = obj.q(t)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type TopVotedCandidate struct {\n\n}\n\n\nfunc Constructor(persons []int, times []int) TopVotedCandidate {\n\n}\n\n\nfunc (this *TopVotedCandidate) Q(t int) int {\n\n}\n\n\n/**\n * Your TopVotedCandidate object will be instantiated and called as such:\n * obj := Constructor(persons, times);\n * param_1 := obj.Q(t);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class TopVotedCandidate(_persons: Array[Int], _times: Array[Int]) {\n\n def q(t: Int): Int = {\n\n }\n\n}\n\n/**\n * Your TopVotedCandidate object will be instantiated and called as such:\n * var obj = new TopVotedCandidate(persons, times)\n * var param_1 = obj.q(t)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class TopVotedCandidate(persons: IntArray, times: IntArray) {\n\n fun q(t: Int): Int {\n\n }\n\n}\n\n/**\n * Your TopVotedCandidate object will be instantiated and called as such:\n * var obj = TopVotedCandidate(persons, times)\n * var param_1 = obj.q(t)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct TopVotedCandidate {\n\n}\n\n\n/** \n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl TopVotedCandidate {\n\n fn new(persons: Vec, times: Vec) -> Self {\n \n }\n \n fn q(&self, t: i32) -> i32 {\n \n }\n}\n\n/**\n * Your TopVotedCandidate object will be instantiated and called as such:\n * let obj = TopVotedCandidate::new(persons, times);\n * let ret_1: i32 = obj.q(t);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class TopVotedCandidate {\n /**\n * @param Integer[] $persons\n * @param Integer[] $times\n */\n function __construct($persons, $times) {\n \n }\n \n /**\n * @param Integer $t\n * @return Integer\n */\n function q($t) {\n \n }\n}\n\n/**\n * Your TopVotedCandidate object will be instantiated and called as such:\n * $obj = TopVotedCandidate($persons, $times);\n * $ret_1 = $obj->q($t);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class TopVotedCandidate {\n constructor(persons: number[], times: number[]) {\n\n }\n\n q(t: number): number {\n\n }\n}\n\n/**\n * Your TopVotedCandidate object will be instantiated and called as such:\n * var obj = new TopVotedCandidate(persons, times)\n * var param_1 = obj.q(t)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define top-voted-candidate%\n (class object%\n (super-new)\n\n ; persons : (listof exact-integer?)\n\n ; times : (listof exact-integer?)\n (init-field\n persons\n times)\n \n ; q : exact-integer? -> exact-integer?\n (define/public (q t)\n\n )))\n\n;; Your top-voted-candidate% object will be instantiated and called as such:\n;; (define obj (new top-voted-candidate% [persons persons] [times times]))\n;; (define param_1 (send obj q t))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0911](https://leetcode-cn.com/problems/online-election)", "[\u5728\u7ebf\u9009\u4e3e](/solution/0900-0999/0911.Online%20Election/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0911](https://leetcode.com/problems/online-election)", "[Online Election](/solution/0900-0999/0911.Online%20Election/README_EN.md)", "`Binary Search`", "Medium", ""]}, {"question_id": "0946", "frontend_question_id": "0910", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/smallest-range-ii", "url_en": "https://leetcode.com/problems/smallest-range-ii", "relative_path_cn": "/solution/0900-0999/0910.Smallest%20Range%20II/README.md", "relative_path_en": "/solution/0900-0999/0910.Smallest%20Range%20II/README_EN.md", "title_cn": "\u6700\u5c0f\u5dee\u503c II", "title_en": "Smallest Range II", "question_title_slug": "smallest-range-ii", "content_en": "

Given an array nums of integers, for each integer nums[i] we need to choose either x = -k or x = k, and add x to nums[i] (only once).

\n\n

After this process, we have some array result.

\n\n

Return the smallest possible difference between the maximum value of result and the minimum value of result.

\n\n

 

\n\n
    \n
\n\n
\n

Example 1:

\n\n
\nInput: nums = [1], k = 0\nOutput: 0\nExplanation: result = [1]\n
\n\n
\n

Example 2:

\n\n
\nInput: nums = [0,10], k = 2\nOutput: 6\nExplanation: result = [2,8]\n
\n\n
\n

Example 3:

\n\n
\nInput: nums = [1,3,6], k = 3\nOutput: 3\nExplanation: result = [4,6,3]\n
\n\n

 

\n\n

Note:

\n\n
    \n\t
  1. 1 <= nums.length <= 10000
  2. \n\t
  3. 0 <= nums[i] <= 10000
  4. \n\t
  5. 0 <= k <= 10000
  6. \n
\n
\n
\n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 A\uff0c\u5bf9\u4e8e\u6bcf\u4e2a\u6574\u6570 A[i]\uff0c\u53ef\u4ee5\u9009\u62e9\u00a0x = -K\u00a0\u6216\u662f\u00a0x = K \uff08K \u603b\u662f\u975e\u8d1f\u6574\u6570\uff09\uff0c\u5e76\u5c06\u00a0x\u00a0\u52a0\u5230\u00a0A[i]\u00a0\u4e2d\u3002

\n\n

\u5728\u6b64\u8fc7\u7a0b\u4e4b\u540e\uff0c\u5f97\u5230\u6570\u7ec4\u00a0B\u3002

\n\n

\u8fd4\u56de B\u00a0\u7684\u6700\u5927\u503c\u548c B\u00a0\u7684\u6700\u5c0f\u503c\u4e4b\u95f4\u53ef\u80fd\u5b58\u5728\u7684\u6700\u5c0f\u5dee\u503c\u3002

\n\n

\u00a0

\n\n
    \n
\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aA = [1], K = 0\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1aB = [1]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aA = [0,10], K = 2\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1aB = [2,8]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1aA = [1,3,6], K = 3\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1aB = [4,6,3]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= A.length <= 10000
  • \n\t
  • 0 <= A[i] <= 10000
  • \n\t
  • 0 <= K <= 10000
  • \n
\n", "tags_en": ["Greedy", "Math"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int smallestRangeII(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int smallestRangeII(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def smallestRangeII(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def smallestRangeII(self, nums: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint smallestRangeII(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SmallestRangeII(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar smallestRangeII = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef smallest_range_ii(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func smallestRangeII(_ nums: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func smallestRangeII(nums []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def smallestRangeII(nums: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun smallestRangeII(nums: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn smallest_range_ii(nums: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer\n */\n function smallestRangeII($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function smallestRangeII(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (smallest-range-ii nums k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0910](https://leetcode-cn.com/problems/smallest-range-ii)", "[\u6700\u5c0f\u5dee\u503c II](/solution/0900-0999/0910.Smallest%20Range%20II/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0910](https://leetcode.com/problems/smallest-range-ii)", "[Smallest Range II](/solution/0900-0999/0910.Smallest%20Range%20II/README_EN.md)", "`Greedy`,`Math`", "Medium", ""]}, {"question_id": "0945", "frontend_question_id": "0909", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/snakes-and-ladders", "url_en": "https://leetcode.com/problems/snakes-and-ladders", "relative_path_cn": "/solution/0900-0999/0909.Snakes%20and%20Ladders/README.md", "relative_path_en": "/solution/0900-0999/0909.Snakes%20and%20Ladders/README_EN.md", "title_cn": "\u86c7\u68af\u68cb", "title_en": "Snakes and Ladders", "question_title_slug": "snakes-and-ladders", "content_en": "

On an N x N board, the numbers from 1 to N*N are written boustrophedonically starting from the bottom left of the board, and alternating direction each row.  For example, for a 6 x 6 board, the numbers are written as follows:

\r\n\r\n
\r\n\"\"\r\n
\r\n\r\n

You start on square 1 of the board (which is always in the last row and first column).  Each move, starting from square x, consists of the following:

\r\n\r\n
    \r\n\t
  • You choose a destination square S with number x+1, x+2, x+3, x+4, x+5, or x+6, provided this number is <= N*N.\r\n\r\n\t
      \r\n\t\t
    • (This choice simulates the result of a standard 6-sided die roll: ie., there are always at most 6 destinations, regardless of the size of the board.)
    • \r\n\t
    \r\n\t
  • \r\n\t
  • If S has a snake or ladder, you move to the destination of that snake or ladder.  Otherwise, you move to S.
  • \r\n
\r\n\r\n

A board square on row r and column c has a "snake or ladder" if board[r][c] != -1.  The destination of that snake or ladder is board[r][c].

\r\n\r\n

Note that you only take a snake or ladder at most once per move: if the destination to a snake or ladder is the start of another snake or ladder, you do not continue moving.  (For example, if the board is `[[4,-1],[-1,3]]`, and on the first move your destination square is `2`, then you finish your first move at `3`, because you do not continue moving to `4`.)

\r\n\r\n

Return the least number of moves required to reach square N*N.  If it is not possible, return -1.

\r\n\r\n

Example 1:

\r\n\r\n
\r\nInput: [\r\n[-1,-1,-1,-1,-1,-1],\r\n[-1,-1,-1,-1,-1,-1],\r\n[-1,-1,-1,-1,-1,-1],\r\n[-1,35,-1,-1,13,-1],\r\n[-1,-1,-1,-1,-1,-1],\r\n[-1,15,-1,-1,-1,-1]]\r\nOutput: 4\r\nExplanation: \r\nAt the beginning, you start at square 1 [at row 5, column 0].\r\nYou decide to move to square 2, and must take the ladder to square 15.\r\nYou then decide to move to square 17 (row 3, column 5), and must take the snake to square 13.\r\nYou then decide to move to square 14, and must take the ladder to square 35.\r\nYou then decide to move to square 36, ending the game.\r\nIt can be shown that you need at least 4 moves to reach the N*N-th square, so the answer is 4.\r\n
\r\n\r\n

Note:

\r\n\r\n
    \r\n\t
  1. 2 <= board.length = board[0].length <= 20
  2. \r\n\t
  3. board[i][j] is between 1 and N*N or is equal to -1.
  4. \r\n\t
  5. The board square with number 1 has no snake or ladder.
  6. \r\n\t
  7. The board square with number N*N has no snake or ladder.
  8. \r\n
\r\n", "content_cn": "

N x N \u7684\u68cb\u76d8 board \u4e0a\uff0c\u6309\u4ece 1 \u5230 N*N \u7684\u6570\u5b57\u7ed9\u65b9\u683c\u7f16\u53f7\uff0c\u7f16\u53f7 \u4ece\u5de6\u4e0b\u89d2\u5f00\u59cb\uff0c\u6bcf\u4e00\u884c\u4ea4\u66ff\u65b9\u5411\u3002

\n\n

\u4f8b\u5982\uff0c\u4e00\u5757 6 x 6 \u5927\u5c0f\u7684\u68cb\u76d8\uff0c\u7f16\u53f7\u5982\u4e0b\uff1a

\n\n
\"\"\n
\n\n

r \u884c c \u5217\u7684\u68cb\u76d8\uff0c\u6309\u524d\u8ff0\u65b9\u6cd5\u7f16\u53f7\uff0c\u68cb\u76d8\u683c\u4e2d\u53ef\u80fd\u5b58\u5728 “\u86c7” \u6216 “\u68af\u5b50”\uff1b\u5982\u679c board[r][c] != -1\uff0c\u90a3\u4e2a\u86c7\u6216\u68af\u5b50\u7684\u76ee\u7684\u5730\u5c06\u4f1a\u662f board[r][c]\u3002

\n\n

\u73a9\u5bb6\u4ece\u68cb\u76d8\u4e0a\u7684\u65b9\u683c 1 \uff08\u603b\u662f\u5728\u6700\u540e\u4e00\u884c\u3001\u7b2c\u4e00\u5217\uff09\u5f00\u59cb\u51fa\u53d1\u3002

\n\n

\u6bcf\u4e00\u56de\u5408\uff0c\u73a9\u5bb6\u9700\u8981\u4ece\u5f53\u524d\u65b9\u683c x \u5f00\u59cb\u51fa\u53d1\uff0c\u6309\u4e0b\u8ff0\u8981\u6c42\u524d\u8fdb\uff1a

\n\n
    \n\t
  • \u9009\u5b9a\u76ee\u6807\u65b9\u683c\uff1a\u9009\u62e9\u4ece\u7f16\u53f7 x+1\uff0cx+2\uff0cx+3\uff0cx+4\uff0cx+5\uff0c\u6216\u8005 x+6 \u7684\u65b9\u683c\u4e2d\u9009\u51fa\u4e00\u4e2a\u76ee\u6807\u65b9\u683c s \uff0c\u76ee\u6807\u65b9\u683c\u7684\u7f16\u53f7 <= N*N\u3002\n\n\t
      \n\t\t
    • \u8be5\u9009\u62e9\u6a21\u62df\u4e86\u63b7\u9ab0\u5b50\u7684\u60c5\u666f\uff0c\u65e0\u8bba\u68cb\u76d8\u5927\u5c0f\u5982\u4f55\uff0c\u4f60\u7684\u76ee\u7684\u5730\u8303\u56f4\u4e5f\u53ea\u80fd\u5904\u4e8e\u533a\u95f4 [x+1, x+6] \u4e4b\u95f4\u3002
    • \n\t
    \n\t
  • \n\t
  • \u4f20\u9001\u73a9\u5bb6\uff1a\u5982\u679c\u76ee\u6807\u65b9\u683c S \u5904\u5b58\u5728\u86c7\u6216\u68af\u5b50\uff0c\u90a3\u4e48\u73a9\u5bb6\u4f1a\u4f20\u9001\u5230\u86c7\u6216\u68af\u5b50\u7684\u76ee\u7684\u5730\u3002\u5426\u5219\uff0c\u73a9\u5bb6\u4f20\u9001\u5230\u76ee\u6807\u65b9\u683c S\u3002 
  • \n
\n\n

\u6ce8\u610f\uff0c\u73a9\u5bb6\u5728\u6bcf\u56de\u5408\u7684\u524d\u8fdb\u8fc7\u7a0b\u4e2d\u6700\u591a\u53ea\u80fd\u722c\u8fc7\u86c7\u6216\u68af\u5b50\u4e00\u6b21\uff1a\u5c31\u7b97\u76ee\u7684\u5730\u662f\u53e6\u4e00\u6761\u86c7\u6216\u68af\u5b50\u7684\u8d77\u70b9\uff0c\u4f60\u4e5f\u4e0d\u4f1a\u7ee7\u7eed\u79fb\u52a8\u3002

\n\n

\u8fd4\u56de\u8fbe\u5230\u65b9\u683c N*N \u6240\u9700\u7684\u6700\u5c11\u79fb\u52a8\u6b21\u6570\uff0c\u5982\u679c\u4e0d\u53ef\u80fd\uff0c\u5219\u8fd4\u56de -1\u3002

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1a[\n[-1,-1,-1,-1,-1,-1],\n[-1,-1,-1,-1,-1,-1],\n[-1,-1,-1,-1,-1,-1],\n[-1,35,-1,-1,13,-1],\n[-1,-1,-1,-1,-1,-1],\n[-1,15,-1,-1,-1,-1]]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\n\u9996\u5148\uff0c\u4ece\u65b9\u683c 1 [\u7b2c 5 \u884c\uff0c\u7b2c 0 \u5217] \u5f00\u59cb\u3002\n\u4f60\u51b3\u5b9a\u79fb\u52a8\u5230\u65b9\u683c 2\uff0c\u5e76\u5fc5\u987b\u722c\u8fc7\u68af\u5b50\u79fb\u52a8\u5230\u5230\u65b9\u683c 15\u3002\n\u7136\u540e\u4f60\u51b3\u5b9a\u79fb\u52a8\u5230\u65b9\u683c 17 [\u7b2c 3 \u884c\uff0c\u7b2c 5 \u5217]\uff0c\u5fc5\u987b\u722c\u8fc7\u86c7\u5230\u65b9\u683c 13\u3002\n\u7136\u540e\u4f60\u51b3\u5b9a\u79fb\u52a8\u5230\u65b9\u683c 14\uff0c\u4e14\u5fc5\u987b\u901a\u8fc7\u68af\u5b50\u79fb\u52a8\u5230\u65b9\u683c 35\u3002\n\u7136\u540e\u4f60\u51b3\u5b9a\u79fb\u52a8\u5230\u65b9\u683c 36, \u6e38\u620f\u7ed3\u675f\u3002\n\u53ef\u4ee5\u8bc1\u660e\u4f60\u9700\u8981\u81f3\u5c11 4 \u6b21\u79fb\u52a8\u624d\u80fd\u5230\u8fbe\u7b2c N*N \u4e2a\u65b9\u683c\uff0c\u6240\u4ee5\u7b54\u6848\u662f 4\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= board.length = board[0].length <= 20
  • \n\t
  • board[i][j] \u4ecb\u4e8e 1 \u548c N*N \u4e4b\u95f4\u6216\u8005\u7b49\u4e8e -1\u3002
  • \n\t
  • \u7f16\u53f7\u4e3a 1 \u7684\u65b9\u683c\u4e0a\u6ca1\u6709\u86c7\u6216\u68af\u5b50\u3002
  • \n\t
  • \u7f16\u53f7\u4e3a N*N \u7684\u65b9\u683c\u4e0a\u6ca1\u6709\u86c7\u6216\u68af\u5b50\u3002
  • \n
\n", "tags_en": ["Breadth-first Search"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int snakesAndLadders(vector>& board) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int snakesAndLadders(int[][] board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def snakesAndLadders(self, board):\n \"\"\"\n :type board: List[List[int]]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def snakesAndLadders(self, board: List[List[int]]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint snakesAndLadders(int** board, int boardSize, int* boardColSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SnakesAndLadders(int[][] board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} board\n * @return {number}\n */\nvar snakesAndLadders = function(board) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} board\n# @return {Integer}\ndef snakes_and_ladders(board)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func snakesAndLadders(_ board: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func snakesAndLadders(board [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def snakesAndLadders(board: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun snakesAndLadders(board: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn snakes_and_ladders(board: Vec>) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $board\n * @return Integer\n */\n function snakesAndLadders($board) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function snakesAndLadders(board: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (snakes-and-ladders board)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0909](https://leetcode-cn.com/problems/snakes-and-ladders)", "[\u86c7\u68af\u68cb](/solution/0900-0999/0909.Snakes%20and%20Ladders/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0909](https://leetcode.com/problems/snakes-and-ladders)", "[Snakes and Ladders](/solution/0900-0999/0909.Snakes%20and%20Ladders/README_EN.md)", "`Breadth-first Search`", "Medium", ""]}, {"question_id": "0944", "frontend_question_id": "0908", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/smallest-range-i", "url_en": "https://leetcode.com/problems/smallest-range-i", "relative_path_cn": "/solution/0900-0999/0908.Smallest%20Range%20I/README.md", "relative_path_en": "/solution/0900-0999/0908.Smallest%20Range%20I/README_EN.md", "title_cn": "\u6700\u5c0f\u5dee\u503c I", "title_en": "Smallest Range I", "question_title_slug": "smallest-range-i", "content_en": "

Given an array nums of integers, for each integer nums[i] we may choose any x with -k <= x <= k, and add x to nums[i].

\n\n

After this process, we have some array result.

\n\n

Return the smallest possible difference between the maximum value of result and the minimum value of result.

\n\n

 

\n\n
    \n
\n\n
\n

Example 1:

\n\n
\nInput: nums = [1], k = 0\nOutput: 0\nExplanation: result = [1]\n
\n\n
\n

Example 2:

\n\n
\nInput: nums = [0,10], k = 2\nOutput: 6\nExplanation: result = [2,8]\n
\n\n
\n

Example 3:

\n\n
\nInput: nums = [1,3,6], k = 3\nOutput: 0\nExplanation: result = [3,3,3] or result = [4,4,4]\n
\n\n

 

\n\n

Note:

\n\n
    \n\t
  1. 1 <= nums.length <= 10000
  2. \n\t
  3. 0 <= nums[i] <= 10000
  4. \n\t
  5. 0 <= k <= 10000
  6. \n
\n
\n
\n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 A\uff0c\u8bf7\u4f60\u7ed9\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20 A[i] \u90fd\u52a0\u4e0a\u4e00\u4e2a\u4efb\u610f\u6570\u5b57 x \uff08-K <= x <= K\uff09\uff0c\u4ece\u800c\u5f97\u5230\u4e00\u4e2a\u65b0\u6570\u7ec4 B \u3002

\n\n

\u8fd4\u56de\u6570\u7ec4 B \u7684\u6700\u5927\u503c\u548c\u6700\u5c0f\u503c\u4e4b\u95f4\u53ef\u80fd\u5b58\u5728\u7684\u6700\u5c0f\u5dee\u503c\u3002

\n\n

 

\n\n
    \n
\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aA = [1], K = 0\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1aB = [1]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aA = [0,10], K = 2\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1aB = [2,8]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aA = [1,3,6], K = 3\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1aB = [3,3,3] \u6216 B = [4,4,4]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= A.length <= 10000
  2. \n\t
  3. 0 <= A[i] <= 10000
  4. \n\t
  5. 0 <= K <= 10000
  6. \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int smallestRangeI(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int smallestRangeI(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def smallestRangeI(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def smallestRangeI(self, nums: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint smallestRangeI(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SmallestRangeI(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar smallestRangeI = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef smallest_range_i(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func smallestRangeI(_ nums: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func smallestRangeI(nums []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def smallestRangeI(nums: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun smallestRangeI(nums: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn smallest_range_i(nums: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer\n */\n function smallestRangeI($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function smallestRangeI(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (smallest-range-i nums k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0908](https://leetcode-cn.com/problems/smallest-range-i)", "[\u6700\u5c0f\u5dee\u503c I](/solution/0900-0999/0908.Smallest%20Range%20I/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0908](https://leetcode.com/problems/smallest-range-i)", "[Smallest Range I](/solution/0900-0999/0908.Smallest%20Range%20I/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "0943", "frontend_question_id": "0907", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sum-of-subarray-minimums", "url_en": "https://leetcode.com/problems/sum-of-subarray-minimums", "relative_path_cn": "/solution/0900-0999/0907.Sum%20of%20Subarray%20Minimums/README.md", "relative_path_en": "/solution/0900-0999/0907.Sum%20of%20Subarray%20Minimums/README_EN.md", "title_cn": "\u5b50\u6570\u7ec4\u7684\u6700\u5c0f\u503c\u4e4b\u548c", "title_en": "Sum of Subarray Minimums", "question_title_slug": "sum-of-subarray-minimums", "content_en": "

Given an array of integers arr, find the sum of min(b), where b ranges over every (contiguous) subarray of arr. Since the answer may be large, return the answer modulo 109 + 7.

\n\n

 

\n

Example 1:

\n\n
\nInput: arr = [3,1,2,4]\nOutput: 17\nExplanation: \nSubarrays are [3], [1], [2], [4], [3,1], [1,2], [2,4], [3,1,2], [1,2,4], [3,1,2,4]. \nMinimums are 3, 1, 2, 4, 1, 1, 2, 1, 1, 1.\nSum is 17.\n
\n\n

Example 2:

\n\n
\nInput: arr = [11,81,94,43,3]\nOutput: 444\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= arr.length <= 3 * 104
  • \n\t
  • 1 <= arr[i] <= 3 * 104
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr\uff0c\u627e\u5230 min(b)\u00a0\u7684\u603b\u548c\uff0c\u5176\u4e2d b \u7684\u8303\u56f4\u4e3a arr \u7684\u6bcf\u4e2a\uff08\u8fde\u7eed\uff09\u5b50\u6570\u7ec4\u3002

\n\n

\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u5f88\u5927\uff0c\u56e0\u6b64 \u8fd4\u56de\u7b54\u6848\u6a21 10^9 + 7 \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [3,1,2,4]\n\u8f93\u51fa\uff1a17\n\u89e3\u91ca\uff1a\n\u5b50\u6570\u7ec4\u4e3a [3]\uff0c[1]\uff0c[2]\uff0c[4]\uff0c[3,1]\uff0c[1,2]\uff0c[2,4]\uff0c[3,1,2]\uff0c[1,2,4]\uff0c[3,1,2,4]\u3002 \n\u6700\u5c0f\u503c\u4e3a 3\uff0c1\uff0c2\uff0c4\uff0c1\uff0c1\uff0c2\uff0c1\uff0c1\uff0c1\uff0c\u548c\u4e3a 17\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [11,81,94,43,3]\n\u8f93\u51fa\uff1a444\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= arr.length <= 3 * 104
  • \n\t
  • 1 <= arr[i] <= 3 * 104
  • \n
\n\n

\u00a0

\n", "tags_en": ["Stack", "Array"], "tags_cn": ["\u6808", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int sumSubarrayMins(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int sumSubarrayMins(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def sumSubarrayMins(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def sumSubarrayMins(self, arr: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint sumSubarrayMins(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SumSubarrayMins(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar sumSubarrayMins = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef sum_subarray_mins(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func sumSubarrayMins(_ arr: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func sumSubarrayMins(arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def sumSubarrayMins(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun sumSubarrayMins(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sum_subarray_mins(arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function sumSubarrayMins($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function sumSubarrayMins(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (sum-subarray-mins arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0907](https://leetcode-cn.com/problems/sum-of-subarray-minimums)", "[\u5b50\u6570\u7ec4\u7684\u6700\u5c0f\u503c\u4e4b\u548c](/solution/0900-0999/0907.Sum%20of%20Subarray%20Minimums/README.md)", "`\u6808`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0907](https://leetcode.com/problems/sum-of-subarray-minimums)", "[Sum of Subarray Minimums](/solution/0900-0999/0907.Sum%20of%20Subarray%20Minimums/README_EN.md)", "`Stack`,`Array`", "Medium", ""]}, {"question_id": "0942", "frontend_question_id": "0906", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/super-palindromes", "url_en": "https://leetcode.com/problems/super-palindromes", "relative_path_cn": "/solution/0900-0999/0906.Super%20Palindromes/README.md", "relative_path_en": "/solution/0900-0999/0906.Super%20Palindromes/README_EN.md", "title_cn": "\u8d85\u7ea7\u56de\u6587\u6570", "title_en": "Super Palindromes", "question_title_slug": "super-palindromes", "content_en": "

Let's say a positive integer is a super-palindrome if it is a palindrome, and it is also the square of a palindrome.

\n\n

Given two positive integers left and right represented as strings, return the number of super-palindromes integers in the inclusive range [left, right].

\n\n

 

\n

Example 1:

\n\n
\nInput: left = "4", right = "1000"\nOutput: 4\nExplanation: 4, 9, 121, and 484 are superpalindromes.\nNote that 676 is not a superpalindrome: 26 * 26 = 676, but 26 is not a palindrome.\n
\n\n

Example 2:

\n\n
\nInput: left = "1", right = "2"\nOutput: 1\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= left.length, right.length <= 18
  • \n\t
  • left and right consist of only digits.
  • \n\t
  • left and right cannot have leading zeros.
  • \n\t
  • left and right represent integers in the range [1, 1018 - 1].
  • \n\t
  • left is less than or equal to right.
  • \n
\n", "content_cn": "

\u5982\u679c\u4e00\u4e2a\u6b63\u6574\u6570\u81ea\u8eab\u662f\u56de\u6587\u6570\uff0c\u800c\u4e14\u5b83\u4e5f\u662f\u4e00\u4e2a\u56de\u6587\u6570\u7684\u5e73\u65b9\uff0c\u90a3\u4e48\u6211\u4eec\u79f0\u8fd9\u4e2a\u6570\u4e3a\u8d85\u7ea7\u56de\u6587\u6570\u3002

\n\n

\u73b0\u5728\uff0c\u7ed9\u5b9a\u4e24\u4e2a\u6b63\u6574\u6570 L \u548c R \uff08\u4ee5\u5b57\u7b26\u4e32\u5f62\u5f0f\u8868\u793a\uff09\uff0c\u8fd4\u56de\u5305\u542b\u5728\u8303\u56f4 [L, R] \u4e2d\u7684\u8d85\u7ea7\u56de\u6587\u6570\u7684\u6570\u76ee\u3002

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1aL = "4", R = "1000"\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\n4\uff0c9\uff0c121\uff0c\u4ee5\u53ca 484 \u662f\u8d85\u7ea7\u56de\u6587\u6570\u3002\n\u6ce8\u610f 676 \u4e0d\u662f\u4e00\u4e2a\u8d85\u7ea7\u56de\u6587\u6570\uff1a 26 * 26 = 676\uff0c\u4f46\u662f 26 \u4e0d\u662f\u56de\u6587\u6570\u3002
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= len(L) <= 18
  2. \n\t
  3. 1 <= len(R) <= 18
  4. \n\t
  5. L \u548c R \u662f\u8868\u793a [1, 10^18) \u8303\u56f4\u7684\u6574\u6570\u7684\u5b57\u7b26\u4e32\u3002
  6. \n\t
  7. int(L) <= int(R)
  8. \n
\n\n

 

\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int superpalindromesInRange(string left, string right) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int superpalindromesInRange(String left, String right) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def superpalindromesInRange(self, left, right):\n \"\"\"\n :type left: str\n :type right: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def superpalindromesInRange(self, left: str, right: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint superpalindromesInRange(char * left, char * right){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SuperpalindromesInRange(string left, string right) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} left\n * @param {string} right\n * @return {number}\n */\nvar superpalindromesInRange = function(left, right) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} left\n# @param {String} right\n# @return {Integer}\ndef superpalindromes_in_range(left, right)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func superpalindromesInRange(_ left: String, _ right: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func superpalindromesInRange(left string, right string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def superpalindromesInRange(left: String, right: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun superpalindromesInRange(left: String, right: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn superpalindromes_in_range(left: String, right: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $left\n * @param String $right\n * @return Integer\n */\n function superpalindromesInRange($left, $right) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function superpalindromesInRange(left: string, right: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (superpalindromes-in-range left right)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0906](https://leetcode-cn.com/problems/super-palindromes)", "[\u8d85\u7ea7\u56de\u6587\u6570](/solution/0900-0999/0906.Super%20Palindromes/README.md)", "`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[0906](https://leetcode.com/problems/super-palindromes)", "[Super Palindromes](/solution/0900-0999/0906.Super%20Palindromes/README_EN.md)", "`Math`", "Hard", ""]}, {"question_id": "0941", "frontend_question_id": "0905", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sort-array-by-parity", "url_en": "https://leetcode.com/problems/sort-array-by-parity", "relative_path_cn": "/solution/0900-0999/0905.Sort%20Array%20By%20Parity/README.md", "relative_path_en": "/solution/0900-0999/0905.Sort%20Array%20By%20Parity/README_EN.md", "title_cn": "\u6309\u5947\u5076\u6392\u5e8f\u6570\u7ec4", "title_en": "Sort Array By Parity", "question_title_slug": "sort-array-by-parity", "content_en": "

Given an array nums of non-negative integers, return an array consisting of all the even elements of nums, followed by all the odd elements of nums.

\n\n

You may return any answer array that satisfies this condition.

\n\n

 

\n\n
\n

Example 1:

\n\n
\nInput: nums = [3,1,2,4]\nOutput: [2,4,3,1]\nThe outputs [4,2,3,1], [2,4,1,3], and [4,2,1,3] would also be accepted.\n
\n\n

 

\n\n

Note:

\n\n
    \n\t
  1. 1 <= nums.length <= 5000
  2. \n\t
  3. 0 <= nums[i] <= 5000
  4. \n
\n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\u6570\u7ec4 A\uff0c\u8fd4\u56de\u4e00\u4e2a\u6570\u7ec4\uff0c\u5728\u8be5\u6570\u7ec4\u4e2d\uff0c A \u7684\u6240\u6709\u5076\u6570\u5143\u7d20\u4e4b\u540e\u8ddf\u7740\u6240\u6709\u5947\u6570\u5143\u7d20\u3002

\n\n

\u4f60\u53ef\u4ee5\u8fd4\u56de\u6ee1\u8db3\u6b64\u6761\u4ef6\u7684\u4efb\u4f55\u6570\u7ec4\u4f5c\u4e3a\u7b54\u6848\u3002

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1a[3,1,2,4]\n\u8f93\u51fa\uff1a[2,4,3,1]\n\u8f93\u51fa [4,2,3,1]\uff0c[2,4,1,3] \u548c [4,2,1,3] \u4e5f\u4f1a\u88ab\u63a5\u53d7\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= A.length <= 5000
  2. \n\t
  3. 0 <= A[i] <= 5000
  4. \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector sortArrayByParity(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] sortArrayByParity(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def sortArrayByParity(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def sortArrayByParity(self, nums: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* sortArrayByParity(int* nums, int numsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] SortArrayByParity(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar sortArrayByParity = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer[]}\ndef sort_array_by_parity(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func sortArrayByParity(_ nums: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func sortArrayByParity(nums []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def sortArrayByParity(nums: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun sortArrayByParity(nums: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sort_array_by_parity(nums: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer[]\n */\n function sortArrayByParity($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function sortArrayByParity(nums: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (sort-array-by-parity nums)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0905](https://leetcode-cn.com/problems/sort-array-by-parity)", "[\u6309\u5947\u5076\u6392\u5e8f\u6570\u7ec4](/solution/0900-0999/0905.Sort%20Array%20By%20Parity/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0905](https://leetcode.com/problems/sort-array-by-parity)", "[Sort Array By Parity](/solution/0900-0999/0905.Sort%20Array%20By%20Parity/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0940", "frontend_question_id": "0904", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/fruit-into-baskets", "url_en": "https://leetcode.com/problems/fruit-into-baskets", "relative_path_cn": "/solution/0900-0999/0904.Fruit%20Into%20Baskets/README.md", "relative_path_en": "/solution/0900-0999/0904.Fruit%20Into%20Baskets/README_EN.md", "title_cn": "\u6c34\u679c\u6210\u7bee", "title_en": "Fruit Into Baskets", "question_title_slug": "fruit-into-baskets", "content_en": "

In a row of trees, the i-th tree produces fruit with type tree[i].

\r\n\r\n

You start at any tree of your choice, then repeatedly perform the following steps:

\r\n\r\n
    \r\n\t
  1. Add one piece of fruit from this tree to your baskets.  If you cannot, stop.
  2. \r\n\t
  3. Move to the next tree to the right of the current tree.  If there is no tree to the right, stop.
  4. \r\n
\r\n\r\n

Note that you do not have any choice after the initial choice of starting tree: you must perform step 1, then step 2, then back to step 1, then step 2, and so on until you stop.

\r\n\r\n

You have two baskets, and each basket can carry any quantity of fruit, but you want each basket to only carry one type of fruit each.

\r\n\r\n

What is the total amount of fruit you can collect with this procedure?

\r\n\r\n

 

\r\n\r\n

Example 1:

\r\n\r\n
\r\nInput: [1,2,1]\r\nOutput: 3\r\nExplanation: We can collect [1,2,1].\r\n
\r\n\r\n
\r\n

Example 2:

\r\n\r\n
\r\nInput: [0,1,2,2]\r\nOutput: 3\r\nExplanation: We can collect [1,2,2].\r\nIf we started at the first tree, we would only collect [0, 1].\r\n
\r\n\r\n
\r\n

Example 3:

\r\n\r\n
\r\nInput: [1,2,3,2,2]\r\nOutput: 4\r\nExplanation: We can collect [2,3,2,2].\r\nIf we started at the first tree, we would only collect [1, 2].\r\n
\r\n\r\n
\r\n

Example 4:

\r\n\r\n
\r\nInput: [3,3,3,1,2,1,1,2,3,3,4]\r\nOutput: 5\r\nExplanation: We can collect [1,2,1,1,2].\r\nIf we started at the first tree or the eighth tree, we would only collect 4 fruits.\r\n
\r\n\r\n

 

\r\n
\r\n
\r\n
\r\n\r\n

Note:

\r\n\r\n
    \r\n\t
  1. 1 <= tree.length <= 40000
  2. \r\n\t
  3. 0 <= tree[i] < tree.length
  4. \r\n
\r\n", "content_cn": "

\u5728\u4e00\u6392\u6811\u4e2d\uff0c\u7b2c i \u68f5\u6811\u4ea7\u751f tree[i] \u578b\u7684\u6c34\u679c\u3002
\n\u4f60\u53ef\u4ee5\u4ece\u4f60\u9009\u62e9\u7684\u4efb\u4f55\u6811\u5f00\u59cb\uff0c\u7136\u540e\u91cd\u590d\u6267\u884c\u4ee5\u4e0b\u6b65\u9aa4\uff1a

\n\n
    \n\t
  1. \u628a\u8fd9\u68f5\u6811\u4e0a\u7684\u6c34\u679c\u653e\u8fdb\u4f60\u7684\u7bee\u5b50\u91cc\u3002\u5982\u679c\u4f60\u505a\u4e0d\u5230\uff0c\u5c31\u505c\u4e0b\u6765\u3002
  2. \n\t
  3. \u79fb\u52a8\u5230\u5f53\u524d\u6811\u53f3\u4fa7\u7684\u4e0b\u4e00\u68f5\u6811\u3002\u5982\u679c\u53f3\u8fb9\u6ca1\u6709\u6811\uff0c\u5c31\u505c\u4e0b\u6765\u3002
  4. \n
\n\n

\u8bf7\u6ce8\u610f\uff0c\u5728\u9009\u62e9\u4e00\u9897\u6811\u540e\uff0c\u4f60\u6ca1\u6709\u4efb\u4f55\u9009\u62e9\uff1a\u4f60\u5fc5\u987b\u6267\u884c\u6b65\u9aa4 1\uff0c\u7136\u540e\u6267\u884c\u6b65\u9aa4 2\uff0c\u7136\u540e\u8fd4\u56de\u6b65\u9aa4 1\uff0c\u7136\u540e\u6267\u884c\u6b65\u9aa4 2\uff0c\u4f9d\u6b64\u7c7b\u63a8\uff0c\u76f4\u81f3\u505c\u6b62\u3002

\n\n

\u4f60\u6709\u4e24\u4e2a\u7bee\u5b50\uff0c\u6bcf\u4e2a\u7bee\u5b50\u53ef\u4ee5\u643a\u5e26\u4efb\u4f55\u6570\u91cf\u7684\u6c34\u679c\uff0c\u4f46\u4f60\u5e0c\u671b\u6bcf\u4e2a\u7bee\u5b50\u53ea\u643a\u5e26\u4e00\u79cd\u7c7b\u578b\u7684\u6c34\u679c\u3002

\n\n

\u7528\u8fd9\u4e2a\u7a0b\u5e8f\u4f60\u80fd\u6536\u96c6\u7684\u6c34\u679c\u6811\u7684\u6700\u5927\u603b\u91cf\u662f\u591a\u5c11\uff1f

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a[1,2,1]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6211\u4eec\u53ef\u4ee5\u6536\u96c6 [1,2,1]\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a[0,1,2,2]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6211\u4eec\u53ef\u4ee5\u6536\u96c6 [1,2,2]\n\u5982\u679c\u6211\u4eec\u4ece\u7b2c\u4e00\u68f5\u6811\u5f00\u59cb\uff0c\u6211\u4eec\u5c06\u53ea\u80fd\u6536\u96c6\u5230 [0, 1]\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1a[1,2,3,2,2]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u6211\u4eec\u53ef\u4ee5\u6536\u96c6 [2,3,2,2]\n\u5982\u679c\u6211\u4eec\u4ece\u7b2c\u4e00\u68f5\u6811\u5f00\u59cb\uff0c\u6211\u4eec\u5c06\u53ea\u80fd\u6536\u96c6\u5230 [1, 2]\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1a[3,3,3,1,2,1,1,2,3,3,4]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u6211\u4eec\u53ef\u4ee5\u6536\u96c6 [1,2,1,1,2]\n\u5982\u679c\u6211\u4eec\u4ece\u7b2c\u4e00\u68f5\u6811\u6216\u7b2c\u516b\u68f5\u6811\u5f00\u59cb\uff0c\u6211\u4eec\u5c06\u53ea\u80fd\u6536\u96c6\u5230 4 \u68f5\u6c34\u679c\u6811\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= tree.length <= 40000
  • \n\t
  • 0 <= tree[i] < tree.length
  • \n
\n", "tags_en": ["Two Pointers"], "tags_cn": ["\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int totalFruit(vector& tree) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int totalFruit(int[] tree) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def totalFruit(self, tree):\n \"\"\"\n :type tree: List[int]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def totalFruit(self, tree: List[int]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint totalFruit(int* tree, int treeSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int TotalFruit(int[] tree) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} tree\n * @return {number}\n */\nvar totalFruit = function(tree) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} tree\n# @return {Integer}\ndef total_fruit(tree)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func totalFruit(_ tree: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func totalFruit(tree []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def totalFruit(tree: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun totalFruit(tree: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn total_fruit(tree: Vec) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $tree\n * @return Integer\n */\n function totalFruit($tree) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function totalFruit(tree: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (total-fruit tree)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0904](https://leetcode-cn.com/problems/fruit-into-baskets)", "[\u6c34\u679c\u6210\u7bee](/solution/0900-0999/0904.Fruit%20Into%20Baskets/README.md)", "`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0904](https://leetcode.com/problems/fruit-into-baskets)", "[Fruit Into Baskets](/solution/0900-0999/0904.Fruit%20Into%20Baskets/README_EN.md)", "`Two Pointers`", "Medium", ""]}, {"question_id": "0939", "frontend_question_id": "0903", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/valid-permutations-for-di-sequence", "url_en": "https://leetcode.com/problems/valid-permutations-for-di-sequence", "relative_path_cn": "/solution/0900-0999/0903.Valid%20Permutations%20for%20DI%20Sequence/README.md", "relative_path_en": "/solution/0900-0999/0903.Valid%20Permutations%20for%20DI%20Sequence/README_EN.md", "title_cn": "DI \u5e8f\u5217\u7684\u6709\u6548\u6392\u5217", "title_en": "Valid Permutations for DI Sequence", "question_title_slug": "valid-permutations-for-di-sequence", "content_en": "

We are given s, a length n string of characters from the set {'D', 'I'}. (These letters stand for "decreasing" and "increasing".)

\n\n

valid permutation is a permutation p[0], p[1], ..., p[n] of integers {0, 1, ..., n}, such that for all i:

\n\n
    \n\t
  • If s[i] == 'D', then p[i] > p[i+1], and;
  • \n\t
  • If s[i] == 'I', then p[i] < p[i+1].
  • \n
\n\n

How many valid permutations are there?  Since the answer may be large, return your answer modulo 109 + 7.

\n\n

 

\n\n

Example 1:

\n\n
\nInput: s = "DID"\nOutput: 5\nExplanation: \nThe 5 valid permutations of (0, 1, 2, 3) are:\n(1, 0, 3, 2)\n(2, 0, 3, 1)\n(2, 1, 3, 0)\n(3, 0, 2, 1)\n(3, 1, 2, 0)\n
\n\n

 

\n\n

Note:

\n\n
    \n\t
  1. 1 <= s.length <= 200
  2. \n\t
  3. s consists only of characters from the set {'D', 'I'}.
  4. \n
\n\n
\n

 

\n
\n", "content_cn": "

\u6211\u4eec\u7ed9\u51fa S\uff0c\u4e00\u4e2a\u6e90\u4e8e {'D', 'I'} \u7684\u957f\u5ea6\u4e3a n \u7684\u5b57\u7b26\u4e32 \u3002\uff08\u8fd9\u4e9b\u5b57\u6bcd\u4ee3\u8868 “\u51cf\u5c11” \u548c “\u589e\u52a0”\u3002\uff09
\n\u6709\u6548\u6392\u5217 \u662f\u5bf9\u6574\u6570 {0, 1, ..., n} \u7684\u4e00\u4e2a\u6392\u5217 P[0], P[1], ..., P[n]\uff0c\u4f7f\u5f97\u5bf9\u6240\u6709\u7684 i\uff1a

\n\n
    \n\t
  • \u5982\u679c S[i] == 'D'\uff0c\u90a3\u4e48 P[i] > P[i+1]\uff0c\u4ee5\u53ca\uff1b
  • \n\t
  • \u5982\u679c S[i] == 'I'\uff0c\u90a3\u4e48 P[i] < P[i+1]\u3002
  • \n
\n\n

\u6709\u591a\u5c11\u4e2a\u6709\u6548\u6392\u5217\uff1f\u56e0\u4e3a\u7b54\u6848\u53ef\u80fd\u5f88\u5927\uff0c\u6240\u4ee5\u8bf7\u8fd4\u56de\u4f60\u7684\u7b54\u6848\u6a21 10^9 + 7.

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1a"DID"\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\n(0, 1, 2, 3) \u7684\u4e94\u4e2a\u6709\u6548\u6392\u5217\u662f\uff1a\n(1, 0, 3, 2)\n(2, 0, 3, 1)\n(2, 1, 3, 0)\n(3, 0, 2, 1)\n(3, 1, 2, 0)\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= S.length <= 200
  2. \n\t
  3. S \u4ec5\u7531\u96c6\u5408 {'D', 'I'} \u4e2d\u7684\u5b57\u7b26\u7ec4\u6210\u3002
  4. \n
\n\n

 

\n", "tags_en": ["Divide and Conquer", "Dynamic Programming"], "tags_cn": ["\u5206\u6cbb\u7b97\u6cd5", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numPermsDISequence(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numPermsDISequence(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numPermsDISequence(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numPermsDISequence(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numPermsDISequence(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumPermsDISequence(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar numPermsDISequence = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef num_perms_di_sequence(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numPermsDISequence(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numPermsDISequence(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numPermsDISequence(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numPermsDISequence(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_perms_di_sequence(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function numPermsDISequence($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numPermsDISequence(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-perms-di-sequence s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0903](https://leetcode-cn.com/problems/valid-permutations-for-di-sequence)", "[DI \u5e8f\u5217\u7684\u6709\u6548\u6392\u5217](/solution/0900-0999/0903.Valid%20Permutations%20for%20DI%20Sequence/README.md)", "`\u5206\u6cbb\u7b97\u6cd5`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0903](https://leetcode.com/problems/valid-permutations-for-di-sequence)", "[Valid Permutations for DI Sequence](/solution/0900-0999/0903.Valid%20Permutations%20for%20DI%20Sequence/README_EN.md)", "`Divide and Conquer`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0938", "frontend_question_id": "0902", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/numbers-at-most-n-given-digit-set", "url_en": "https://leetcode.com/problems/numbers-at-most-n-given-digit-set", "relative_path_cn": "/solution/0900-0999/0902.Numbers%20At%20Most%20N%20Given%20Digit%20Set/README.md", "relative_path_en": "/solution/0900-0999/0902.Numbers%20At%20Most%20N%20Given%20Digit%20Set/README_EN.md", "title_cn": "\u6700\u5927\u4e3a N \u7684\u6570\u5b57\u7ec4\u5408", "title_en": "Numbers At Most N Given Digit Set", "question_title_slug": "numbers-at-most-n-given-digit-set", "content_en": "

Given an array of digits which is sorted in non-decreasing order. You can write numbers using each digits[i] as many times as we want. For example, if digits = ['1','3','5'], we may write numbers such as '13', '551', and '1351315'.

\n\n

Return the number of positive integers that can be generated that are less than or equal to a given integer n.

\n\n

 

\n

Example 1:

\n\n
\nInput: digits = ["1","3","5","7"], n = 100\nOutput: 20\nExplanation: \nThe 20 numbers that can be written are:\n1, 3, 5, 7, 11, 13, 15, 17, 31, 33, 35, 37, 51, 53, 55, 57, 71, 73, 75, 77.\n
\n\n

Example 2:

\n\n
\nInput: digits = ["1","4","9"], n = 1000000000\nOutput: 29523\nExplanation: \nWe can write 3 one digit numbers, 9 two digit numbers, 27 three digit numbers,\n81 four digit numbers, 243 five digit numbers, 729 six digit numbers,\n2187 seven digit numbers, 6561 eight digit numbers, and 19683 nine digit numbers.\nIn total, this is 29523 integers that can be written using the digits array.\n
\n\n

Example 3:

\n\n
\nInput: digits = ["7"], n = 8\nOutput: 1\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= digits.length <= 9
  • \n\t
  • digits[i].length == 1
  • \n\t
  • digits[i] is a digit from '1' to '9'.
  • \n\t
  • All the values in digits are unique.
  • \n\t
  • digits is sorted in non-decreasing order.
  • \n\t
  • 1 <= n <= 109
  • \n
\n", "content_cn": "

\u6211\u4eec\u6709\u4e00\u7ec4\u6392\u5e8f\u7684\u6570\u5b57 D\uff0c\u5b83\u662f  {'1','2','3','4','5','6','7','8','9'} \u7684\u975e\u7a7a\u5b50\u96c6\u3002\uff08\u8bf7\u6ce8\u610f\uff0c'0' \u4e0d\u5305\u62ec\u5728\u5185\u3002\uff09

\n\n

\u73b0\u5728\uff0c\u6211\u4eec\u7528\u8fd9\u4e9b\u6570\u5b57\u8fdb\u884c\u7ec4\u5408\u5199\u6570\u5b57\uff0c\u60f3\u7528\u591a\u5c11\u6b21\u5c31\u7528\u591a\u5c11\u6b21\u3002\u4f8b\u5982 D = {'1','3','5'}\uff0c\u6211\u4eec\u53ef\u4ee5\u5199\u51fa\u50cf '13', '551', '1351315' \u8fd9\u6837\u7684\u6570\u5b57\u3002

\n\n

\u8fd4\u56de\u53ef\u4ee5\u7528 D \u4e2d\u7684\u6570\u5b57\u5199\u51fa\u7684\u5c0f\u4e8e\u6216\u7b49\u4e8e N \u7684\u6b63\u6574\u6570\u7684\u6570\u76ee\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aD = ["1","3","5","7"], N = 100\n\u8f93\u51fa\uff1a20\n\u89e3\u91ca\uff1a\n\u53ef\u5199\u51fa\u7684 20 \u4e2a\u6570\u5b57\u662f\uff1a\n1, 3, 5, 7, 11, 13, 15, 17, 31, 33, 35, 37, 51, 53, 55, 57, 71, 73, 75, 77.\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aD = ["1","4","9"], N = 1000000000\n\u8f93\u51fa\uff1a29523\n\u89e3\u91ca\uff1a\n\u6211\u4eec\u53ef\u4ee5\u5199 3 \u4e2a\u4e00\u4f4d\u6570\u5b57\uff0c9 \u4e2a\u4e24\u4f4d\u6570\u5b57\uff0c27 \u4e2a\u4e09\u4f4d\u6570\u5b57\uff0c\n81 \u4e2a\u56db\u4f4d\u6570\u5b57\uff0c243 \u4e2a\u4e94\u4f4d\u6570\u5b57\uff0c729 \u4e2a\u516d\u4f4d\u6570\u5b57\uff0c\n2187 \u4e2a\u4e03\u4f4d\u6570\u5b57\uff0c6561 \u4e2a\u516b\u4f4d\u6570\u5b57\u548c 19683 \u4e2a\u4e5d\u4f4d\u6570\u5b57\u3002\n\u603b\u5171\uff0c\u53ef\u4ee5\u4f7f\u7528D\u4e2d\u7684\u6570\u5b57\u5199\u51fa 29523 \u4e2a\u6574\u6570\u3002
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. D \u662f\u6309\u6392\u5e8f\u987a\u5e8f\u7684\u6570\u5b57 '1'-'9' \u7684\u5b50\u96c6\u3002
  2. \n\t
  3. 1 <= N <= 10^9
  4. \n
\n", "tags_en": ["Math", "Dynamic Programming"], "tags_cn": ["\u6570\u5b66", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int atMostNGivenDigitSet(vector& digits, int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int atMostNGivenDigitSet(String[] digits, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def atMostNGivenDigitSet(self, digits, n):\n \"\"\"\n :type digits: List[str]\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def atMostNGivenDigitSet(self, digits: List[str], n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint atMostNGivenDigitSet(char ** digits, int digitsSize, int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int AtMostNGivenDigitSet(string[] digits, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} digits\n * @param {number} n\n * @return {number}\n */\nvar atMostNGivenDigitSet = function(digits, n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} digits\n# @param {Integer} n\n# @return {Integer}\ndef at_most_n_given_digit_set(digits, n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func atMostNGivenDigitSet(_ digits: [String], _ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func atMostNGivenDigitSet(digits []string, n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def atMostNGivenDigitSet(digits: Array[String], n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun atMostNGivenDigitSet(digits: Array, n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn at_most_n_given_digit_set(digits: Vec, n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $digits\n * @param Integer $n\n * @return Integer\n */\n function atMostNGivenDigitSet($digits, $n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function atMostNGivenDigitSet(digits: string[], n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (at-most-n-given-digit-set digits n)\n (-> (listof string?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0902](https://leetcode-cn.com/problems/numbers-at-most-n-given-digit-set)", "[\u6700\u5927\u4e3a N \u7684\u6570\u5b57\u7ec4\u5408](/solution/0900-0999/0902.Numbers%20At%20Most%20N%20Given%20Digit%20Set/README.md)", "`\u6570\u5b66`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0902](https://leetcode.com/problems/numbers-at-most-n-given-digit-set)", "[Numbers At Most N Given Digit Set](/solution/0900-0999/0902.Numbers%20At%20Most%20N%20Given%20Digit%20Set/README_EN.md)", "`Math`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0937", "frontend_question_id": "0901", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/online-stock-span", "url_en": "https://leetcode.com/problems/online-stock-span", "relative_path_cn": "/solution/0900-0999/0901.Online%20Stock%20Span/README.md", "relative_path_en": "/solution/0900-0999/0901.Online%20Stock%20Span/README_EN.md", "title_cn": "\u80a1\u7968\u4ef7\u683c\u8de8\u5ea6", "title_en": "Online Stock Span", "question_title_slug": "online-stock-span", "content_en": "

Write a class StockSpanner which collects daily price quotes for some stock, and returns the span of that stock's price for the current day.

\r\n\r\n

The span of the stock's price today is defined as the maximum number of consecutive days (starting from today and going backwards) for which the price of the stock was less than or equal to today's price.

\r\n\r\n

For example, if the price of a stock over the next 7 days were [100, 80, 60, 70, 60, 75, 85], then the stock spans would be [1, 1, 1, 2, 1, 4, 6].

\r\n\r\n

 

\r\n\r\n
\r\n

Example 1:

\r\n\r\n
\r\nInput: ["StockSpanner","next","next","next","next","next","next","next"], [[],[100],[80],[60],[70],[60],[75],[85]]\r\nOutput: [null,1,1,1,2,1,4,6]\r\nExplanation: \r\nFirst, S = StockSpanner() is initialized.  Then:\r\nS.next(100) is called and returns 1,\r\nS.next(80) is called and returns 1,\r\nS.next(60) is called and returns 1,\r\nS.next(70) is called and returns 2,\r\nS.next(60) is called and returns 1,\r\nS.next(75) is called and returns 4,\r\nS.next(85) is called and returns 6.\r\n\r\nNote that (for example) S.next(75) returned 4, because the last 4 prices\r\n(including today's price of 75) were less than or equal to today's price.\r\n
\r\n\r\n

 

\r\n\r\n

Note:

\r\n\r\n
    \r\n\t
  1. Calls to StockSpanner.next(int price) will have 1 <= price <= 10^5.
  2. \r\n\t
  3. There will be at most 10000 calls to StockSpanner.next per test case.
  4. \r\n\t
  5. There will be at most 150000 calls to StockSpanner.next across all test cases.
  6. \r\n\t
  7. The total time limit for this problem has been reduced by 75% for C++, and 50% for all other languages.
  8. \r\n
\r\n
\r\n", "content_cn": "

\u7f16\u5199\u4e00\u4e2a StockSpanner \u7c7b\uff0c\u5b83\u6536\u96c6\u67d0\u4e9b\u80a1\u7968\u7684\u6bcf\u65e5\u62a5\u4ef7\uff0c\u5e76\u8fd4\u56de\u8be5\u80a1\u7968\u5f53\u65e5\u4ef7\u683c\u7684\u8de8\u5ea6\u3002

\n\n

\u4eca\u5929\u80a1\u7968\u4ef7\u683c\u7684\u8de8\u5ea6\u88ab\u5b9a\u4e49\u4e3a\u80a1\u7968\u4ef7\u683c\u5c0f\u4e8e\u6216\u7b49\u4e8e\u4eca\u5929\u4ef7\u683c\u7684\u6700\u5927\u8fde\u7eed\u65e5\u6570\uff08\u4ece\u4eca\u5929\u5f00\u59cb\u5f80\u56de\u6570\uff0c\u5305\u62ec\u4eca\u5929\uff09\u3002

\n\n

\u4f8b\u5982\uff0c\u5982\u679c\u672a\u67657\u5929\u80a1\u7968\u7684\u4ef7\u683c\u662f [100, 80, 60, 70, 60, 75, 85]\uff0c\u90a3\u4e48\u80a1\u7968\u8de8\u5ea6\u5c06\u662f [1, 1, 1, 2, 1, 4, 6]\u3002

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1a["StockSpanner","next","next","next","next","next","next","next"], [[],[100],[80],[60],[70],[60],[75],[85]]\n\u8f93\u51fa\uff1a[null,1,1,1,2,1,4,6]\n\u89e3\u91ca\uff1a\n\u9996\u5148\uff0c\u521d\u59cb\u5316 S = StockSpanner()\uff0c\u7136\u540e\uff1a\nS.next(100) \u88ab\u8c03\u7528\u5e76\u8fd4\u56de 1\uff0c\nS.next(80) \u88ab\u8c03\u7528\u5e76\u8fd4\u56de 1\uff0c\nS.next(60) \u88ab\u8c03\u7528\u5e76\u8fd4\u56de 1\uff0c\nS.next(70) \u88ab\u8c03\u7528\u5e76\u8fd4\u56de 2\uff0c\nS.next(60) \u88ab\u8c03\u7528\u5e76\u8fd4\u56de 1\uff0c\nS.next(75) \u88ab\u8c03\u7528\u5e76\u8fd4\u56de 4\uff0c\nS.next(85) \u88ab\u8c03\u7528\u5e76\u8fd4\u56de 6\u3002\n\n\u6ce8\u610f (\u4f8b\u5982) S.next(75) \u8fd4\u56de 4\uff0c\u56e0\u4e3a\u622a\u81f3\u4eca\u5929\u7684\u6700\u540e 4 \u4e2a\u4ef7\u683c\n(\u5305\u62ec\u4eca\u5929\u7684\u4ef7\u683c 75) \u5c0f\u4e8e\u6216\u7b49\u4e8e\u4eca\u5929\u7684\u4ef7\u683c\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. \u8c03\u7528 StockSpanner.next(int price) \u65f6\uff0c\u5c06\u6709 1 <= price <= 10^5\u3002
  2. \n\t
  3. \u6bcf\u4e2a\u6d4b\u8bd5\u7528\u4f8b\u6700\u591a\u53ef\u4ee5\u8c03\u7528  10000 \u6b21 StockSpanner.next\u3002
  4. \n\t
  5. \u5728\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u4e2d\uff0c\u6700\u591a\u8c03\u7528 150000 \u6b21 StockSpanner.next\u3002
  6. \n\t
  7. \u6b64\u95ee\u9898\u7684\u603b\u65f6\u95f4\u9650\u5236\u51cf\u5c11\u4e86 50%\u3002
  8. \n
\n", "tags_en": ["Stack"], "tags_cn": ["\u6808"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class StockSpanner {\npublic:\n StockSpanner() {\n\n }\n \n int next(int price) {\n\n }\n};\n\n/**\n * Your StockSpanner object will be instantiated and called as such:\n * StockSpanner* obj = new StockSpanner();\n * int param_1 = obj->next(price);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class StockSpanner {\n\n public StockSpanner() {\n\n }\n \n public int next(int price) {\n\n }\n}\n\n/**\n * Your StockSpanner object will be instantiated and called as such:\n * StockSpanner obj = new StockSpanner();\n * int param_1 = obj.next(price);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class StockSpanner(object):\n\n def __init__(self):\n\n\n def next(self, price):\n \"\"\"\n :type price: int\n :rtype: int\n \"\"\"\n\n\n\n# Your StockSpanner object will be instantiated and called as such:\n# obj = StockSpanner()\n# param_1 = obj.next(price)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class StockSpanner:\n\n def __init__(self):\n\n\n def next(self, price: int) -> int:\n\n\n\n# Your StockSpanner object will be instantiated and called as such:\n# obj = StockSpanner()\n# param_1 = obj.next(price)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} StockSpanner;\n\n\nStockSpanner* stockSpannerCreate() {\n\n}\n\nint stockSpannerNext(StockSpanner* obj, int price) {\n\n}\n\nvoid stockSpannerFree(StockSpanner* obj) {\n\n}\n\n/**\n * Your StockSpanner struct will be instantiated and called as such:\n * StockSpanner* obj = stockSpannerCreate();\n * int param_1 = stockSpannerNext(obj, price);\n \n * stockSpannerFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class StockSpanner {\n\n public StockSpanner() {\n\n }\n \n public int Next(int price) {\n\n }\n}\n\n/**\n * Your StockSpanner object will be instantiated and called as such:\n * StockSpanner obj = new StockSpanner();\n * int param_1 = obj.Next(price);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "\nvar StockSpanner = function() {\n\n};\n\n/** \n * @param {number} price\n * @return {number}\n */\nStockSpanner.prototype.next = function(price) {\n\n};\n\n/**\n * Your StockSpanner object will be instantiated and called as such:\n * var obj = new StockSpanner()\n * var param_1 = obj.next(price)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class StockSpanner\n def initialize()\n\n end\n\n\n=begin\n :type price: Integer\n :rtype: Integer\n=end\n def next(price)\n\n end\n\n\nend\n\n# Your StockSpanner object will be instantiated and called as such:\n# obj = StockSpanner.new()\n# param_1 = obj.next(price)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass StockSpanner {\n\n init() {\n\n }\n \n func next(_ price: Int) -> Int {\n\n }\n}\n\n/**\n * Your StockSpanner object will be instantiated and called as such:\n * let obj = StockSpanner()\n * let ret_1: Int = obj.next(price)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type StockSpanner struct {\n\n}\n\n\nfunc Constructor() StockSpanner {\n\n}\n\n\nfunc (this *StockSpanner) Next(price int) int {\n\n}\n\n\n/**\n * Your StockSpanner object will be instantiated and called as such:\n * obj := Constructor();\n * param_1 := obj.Next(price);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class StockSpanner() {\n\n def next(price: Int): Int = {\n\n }\n\n}\n\n/**\n * Your StockSpanner object will be instantiated and called as such:\n * var obj = new StockSpanner()\n * var param_1 = obj.next(price)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class StockSpanner() {\n\n fun next(price: Int): Int {\n\n }\n\n}\n\n/**\n * Your StockSpanner object will be instantiated and called as such:\n * var obj = StockSpanner()\n * var param_1 = obj.next(price)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct StockSpanner {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl StockSpanner {\n\n fn new() -> Self {\n\n }\n \n fn next(&self, price: i32) -> i32 {\n\n }\n}\n\n/**\n * Your StockSpanner object will be instantiated and called as such:\n * let obj = StockSpanner::new();\n * let ret_1: i32 = obj.next(price);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class StockSpanner {\n /**\n */\n function __construct() {\n\n }\n\n /**\n * @param Integer $price\n * @return Integer\n */\n function next($price) {\n\n }\n}\n\n/**\n * Your StockSpanner object will be instantiated and called as such:\n * $obj = StockSpanner();\n * $ret_1 = $obj->next($price);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class StockSpanner {\n constructor() {\n\n }\n\n next(price: number): number {\n\n }\n}\n\n/**\n * Your StockSpanner object will be instantiated and called as such:\n * var obj = new StockSpanner()\n * var param_1 = obj.next(price)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define stock-spanner%\n (class object%\n (super-new)\n (init-field)\n \n ; next : exact-integer? -> exact-integer?\n (define/public (next price)\n\n )))\n\n;; Your stock-spanner% object will be instantiated and called as such:\n;; (define obj (new stock-spanner%))\n;; (define param_1 (send obj next price))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0901](https://leetcode-cn.com/problems/online-stock-span)", "[\u80a1\u7968\u4ef7\u683c\u8de8\u5ea6](/solution/0900-0999/0901.Online%20Stock%20Span/README.md)", "`\u6808`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0901](https://leetcode.com/problems/online-stock-span)", "[Online Stock Span](/solution/0900-0999/0901.Online%20Stock%20Span/README_EN.md)", "`Stack`", "Medium", ""]}, {"question_id": "0936", "frontend_question_id": "0900", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/rle-iterator", "url_en": "https://leetcode.com/problems/rle-iterator", "relative_path_cn": "/solution/0900-0999/0900.RLE%20Iterator/README.md", "relative_path_en": "/solution/0900-0999/0900.RLE%20Iterator/README_EN.md", "title_cn": "RLE \u8fed\u4ee3\u5668", "title_en": "RLE Iterator", "question_title_slug": "rle-iterator", "content_en": "

We can use run-length encoding (i.e., RLE) to encode a sequence of integers. In a run-length encoded array of even length encoding (0-indexed), for all even i, encoding[i] tells us the number of times that the non-negative integer value encoding[i + 1] is repeated in the sequence.

\n\n
    \n\t
  • For example, the sequence arr = [8,8,8,5,5] can be encoded to be encoding = [3,8,2,5]. encoding = [3,8,0,9,2,5] and encoding = [2,8,1,8,2,5] are also valid RLE of arr.
  • \n
\n\n

Given a run-length encoded array, design an iterator that iterates through it.

\n\n

Implement the RLEIterator class:

\n\n
    \n\t
  • RLEIterator(int[] encoded) Initializes the object with the encoded array encoded.
  • \n\t
  • int next(int n) Exhausts the next n elements and returns the last element exhausted in this way. If there is no element left to exhaust, return -1 instead.
  • \n
\n\n

 

\n

Example 1:

\n\n
\nInput\n["RLEIterator", "next", "next", "next", "next"]\n[[[3, 8, 0, 9, 2, 5]], [2], [1], [1], [2]]\nOutput\n[null, 8, 8, 5, -1]\n\nExplanation\nRLEIterator rLEIterator = new RLEIterator([3, 8, 0, 9, 2, 5]); // This maps to the sequence [8,8,8,5,5].\nrLEIterator.next(2); // exhausts 2 terms of the sequence, returning 8. The remaining sequence is now [8, 5, 5].\nrLEIterator.next(1); // exhausts 1 term of the sequence, returning 8. The remaining sequence is now [5, 5].\nrLEIterator.next(1); // exhausts 1 term of the sequence, returning 5. The remaining sequence is now [5].\nrLEIterator.next(2); // exhausts 2 terms, returning -1. This is because the first term exhausted was 5,\nbut the second term did not exist. Since the last term exhausted does not exist, we return -1.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= encoding.length <= 1000
  • \n\t
  • encoding.length is even.
  • \n\t
  • 0 <= encoding[i] <= 109
  • \n\t
  • 1 <= n <= 109
  • \n\t
  • At most 1000 calls will be made to next.
  • \n
\n", "content_cn": "

\u7f16\u5199\u4e00\u4e2a\u904d\u5386\u6e38\u7a0b\u7f16\u7801\u5e8f\u5217\u7684\u8fed\u4ee3\u5668\u3002

\n\n

\u8fed\u4ee3\u5668\u7531 RLEIterator(int[] A) \u521d\u59cb\u5316\uff0c\u5176\u4e2d A \u662f\u67d0\u4e2a\u5e8f\u5217\u7684\u6e38\u7a0b\u7f16\u7801\u3002\u66f4\u5177\u4f53\u5730\uff0c\u5bf9\u4e8e\u6240\u6709\u5076\u6570 i\uff0cA[i] \u544a\u8bc9\u6211\u4eec\u5728\u5e8f\u5217\u4e2d\u91cd\u590d\u975e\u8d1f\u6574\u6570\u503c A[i + 1] \u7684\u6b21\u6570\u3002

\n\n

\u8fed\u4ee3\u5668\u652f\u6301\u4e00\u4e2a\u51fd\u6570\uff1anext(int n)\uff0c\u5b83\u8017\u5c3d\u63a5\u4e0b\u6765\u7684  n \u4e2a\u5143\u7d20\uff08n >= 1\uff09\u5e76\u8fd4\u56de\u4ee5\u8fd9\u79cd\u65b9\u5f0f\u8017\u53bb\u7684\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u3002\u5982\u679c\u6ca1\u6709\u5269\u4f59\u7684\u5143\u7d20\u53ef\u4f9b\u8017\u5c3d\uff0c\u5219  next \u8fd4\u56de -1 \u3002

\n\n

\u4f8b\u5982\uff0c\u6211\u4eec\u4ee5 A = [3,8,0,9,2,5] \u5f00\u59cb\uff0c\u8fd9\u662f\u5e8f\u5217 [8,8,8,5,5] \u7684\u6e38\u7a0b\u7f16\u7801\u3002\u8fd9\u662f\u56e0\u4e3a\u8be5\u5e8f\u5217\u53ef\u4ee5\u8bfb\u4f5c “\u4e09\u4e2a\u516b\uff0c\u96f6\u4e2a\u4e5d\uff0c\u4e24\u4e2a\u4e94”\u3002

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1a["RLEIterator","next","next","next","next"], [[[3,8,0,9,2,5]],[2],[1],[1],[2]]\n\u8f93\u51fa\uff1a[null,8,8,5,-1]\n\u89e3\u91ca\uff1a\nRLEIterator \u7531 RLEIterator([3,8,0,9,2,5]) \u521d\u59cb\u5316\u3002\n\u8fd9\u6620\u5c04\u5230\u5e8f\u5217 [8,8,8,5,5]\u3002\n\u7136\u540e\u8c03\u7528 RLEIterator.next 4\u6b21\u3002\n\n.next(2) \u8017\u53bb\u5e8f\u5217\u7684 2 \u4e2a\u9879\uff0c\u8fd4\u56de 8\u3002\u73b0\u5728\u5269\u4e0b\u7684\u5e8f\u5217\u662f [8, 5, 5]\u3002\n\n.next(1) \u8017\u53bb\u5e8f\u5217\u7684 1 \u4e2a\u9879\uff0c\u8fd4\u56de 8\u3002\u73b0\u5728\u5269\u4e0b\u7684\u5e8f\u5217\u662f [5, 5]\u3002\n\n.next(1) \u8017\u53bb\u5e8f\u5217\u7684 1 \u4e2a\u9879\uff0c\u8fd4\u56de 5\u3002\u73b0\u5728\u5269\u4e0b\u7684\u5e8f\u5217\u662f [5]\u3002\n\n.next(2) \u8017\u53bb\u5e8f\u5217\u7684 2 \u4e2a\u9879\uff0c\u8fd4\u56de -1\u3002 \u8fd9\u662f\u7531\u4e8e\u7b2c\u4e00\u4e2a\u88ab\u8017\u53bb\u7684\u9879\u662f 5\uff0c\n\u4f46\u7b2c\u4e8c\u4e2a\u9879\u5e76\u4e0d\u5b58\u5728\u3002\u7531\u4e8e\u6700\u540e\u4e00\u4e2a\u8981\u8017\u53bb\u7684\u9879\u4e0d\u5b58\u5728\uff0c\u6211\u4eec\u8fd4\u56de -1\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 0 <= A.length <= 1000
  2. \n\t
  3. A.length \u662f\u5076\u6570\u3002
  4. \n\t
  5. 0 <= A[i] <= 10^9
  6. \n\t
  7. \u6bcf\u4e2a\u6d4b\u8bd5\u7528\u4f8b\u6700\u591a\u8c03\u7528 1000 \u6b21 RLEIterator.next(int n)\u3002
  8. \n\t
  9. \u6bcf\u6b21\u8c03\u7528 RLEIterator.next(int n) \u90fd\u6709 1 <= n <= 10^9 \u3002
  10. \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class RLEIterator {\npublic:\n RLEIterator(vector& encoding) {\n\n }\n \n int next(int n) {\n\n }\n};\n\n/**\n * Your RLEIterator object will be instantiated and called as such:\n * RLEIterator* obj = new RLEIterator(encoding);\n * int param_1 = obj->next(n);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class RLEIterator {\n\n public RLEIterator(int[] encoding) {\n\n }\n \n public int next(int n) {\n\n }\n}\n\n/**\n * Your RLEIterator object will be instantiated and called as such:\n * RLEIterator obj = new RLEIterator(encoding);\n * int param_1 = obj.next(n);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class RLEIterator(object):\n\n def __init__(self, encoding):\n \"\"\"\n :type encoding: List[int]\n \"\"\"\n\n\n def next(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"\n\n\n\n# Your RLEIterator object will be instantiated and called as such:\n# obj = RLEIterator(encoding)\n# param_1 = obj.next(n)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class RLEIterator:\n\n def __init__(self, encoding: List[int]):\n\n\n def next(self, n: int) -> int:\n\n\n\n# Your RLEIterator object will be instantiated and called as such:\n# obj = RLEIterator(encoding)\n# param_1 = obj.next(n)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} RLEIterator;\n\n\nRLEIterator* rLEIteratorCreate(int* encoding, int encodingSize) {\n\n}\n\nint rLEIteratorNext(RLEIterator* obj, int n) {\n\n}\n\nvoid rLEIteratorFree(RLEIterator* obj) {\n\n}\n\n/**\n * Your RLEIterator struct will be instantiated and called as such:\n * RLEIterator* obj = rLEIteratorCreate(encoding, encodingSize);\n * int param_1 = rLEIteratorNext(obj, n);\n \n * rLEIteratorFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class RLEIterator {\n\n public RLEIterator(int[] encoding) {\n\n }\n \n public int Next(int n) {\n\n }\n}\n\n/**\n * Your RLEIterator object will be instantiated and called as such:\n * RLEIterator obj = new RLEIterator(encoding);\n * int param_1 = obj.Next(n);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} encoding\n */\nvar RLEIterator = function(encoding) {\n\n};\n\n/** \n * @param {number} n\n * @return {number}\n */\nRLEIterator.prototype.next = function(n) {\n\n};\n\n/**\n * Your RLEIterator object will be instantiated and called as such:\n * var obj = new RLEIterator(encoding)\n * var param_1 = obj.next(n)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class RLEIterator\n\n=begin\n :type encoding: Integer[]\n=end\n def initialize(encoding)\n\n end\n\n\n=begin\n :type n: Integer\n :rtype: Integer\n=end\n def next(n)\n\n end\n\n\nend\n\n# Your RLEIterator object will be instantiated and called as such:\n# obj = RLEIterator.new(encoding)\n# param_1 = obj.next(n)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass RLEIterator {\n\n init(_ encoding: [Int]) {\n\n }\n \n func next(_ n: Int) -> Int {\n\n }\n}\n\n/**\n * Your RLEIterator object will be instantiated and called as such:\n * let obj = RLEIterator(encoding)\n * let ret_1: Int = obj.next(n)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type RLEIterator struct {\n\n}\n\n\nfunc Constructor(encoding []int) RLEIterator {\n\n}\n\n\nfunc (this *RLEIterator) Next(n int) int {\n\n}\n\n\n/**\n * Your RLEIterator object will be instantiated and called as such:\n * obj := Constructor(encoding);\n * param_1 := obj.Next(n);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class RLEIterator(_encoding: Array[Int]) {\n\n def next(n: Int): Int = {\n\n }\n\n}\n\n/**\n * Your RLEIterator object will be instantiated and called as such:\n * var obj = new RLEIterator(encoding)\n * var param_1 = obj.next(n)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class RLEIterator(encoding: IntArray) {\n\n fun next(n: Int): Int {\n\n }\n\n}\n\n/**\n * Your RLEIterator object will be instantiated and called as such:\n * var obj = RLEIterator(encoding)\n * var param_1 = obj.next(n)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct RLEIterator {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl RLEIterator {\n\n fn new(encoding: Vec) -> Self {\n\n }\n \n fn next(&self, n: i32) -> i32 {\n\n }\n}\n\n/**\n * Your RLEIterator object will be instantiated and called as such:\n * let obj = RLEIterator::new(encoding);\n * let ret_1: i32 = obj.next(n);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class RLEIterator {\n /**\n * @param Integer[] $encoding\n */\n function __construct($encoding) {\n\n }\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function next($n) {\n\n }\n}\n\n/**\n * Your RLEIterator object will be instantiated and called as such:\n * $obj = RLEIterator($encoding);\n * $ret_1 = $obj->next($n);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class RLEIterator {\n constructor(encoding: number[]) {\n\n }\n\n next(n: number): number {\n\n }\n}\n\n/**\n * Your RLEIterator object will be instantiated and called as such:\n * var obj = new RLEIterator(encoding)\n * var param_1 = obj.next(n)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define rle-iterator%\n (class object%\n (super-new)\n\n ; encoding : (listof exact-integer?)\n (init-field\n encoding)\n \n ; next : exact-integer? -> exact-integer?\n (define/public (next n)\n\n )))\n\n;; Your rle-iterator% object will be instantiated and called as such:\n;; (define obj (new rle-iterator% [encoding encoding]))\n;; (define param_1 (send obj next n))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0900](https://leetcode-cn.com/problems/rle-iterator)", "[RLE \u8fed\u4ee3\u5668](/solution/0900-0999/0900.RLE%20Iterator/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0900](https://leetcode.com/problems/rle-iterator)", "[RLE Iterator](/solution/0900-0999/0900.RLE%20Iterator/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0935", "frontend_question_id": "0899", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/orderly-queue", "url_en": "https://leetcode.com/problems/orderly-queue", "relative_path_cn": "/solution/0800-0899/0899.Orderly%20Queue/README.md", "relative_path_en": "/solution/0800-0899/0899.Orderly%20Queue/README_EN.md", "title_cn": "\u6709\u5e8f\u961f\u5217", "title_en": "Orderly Queue", "question_title_slug": "orderly-queue", "content_en": "

A string s of lowercase letters is given.  Then, we may make any number of moves.

\n\n

In each move, we choose one of the first k letters (starting from the left), remove it, and place it at the end of the string.

\n\n

Return the lexicographically smallest string we could have after any number of moves.

\n\n

 

\n\n
\n

Example 1:

\n\n
\nInput: s = "cba", k = 1\nOutput: "acb"\nExplanation: \nIn the first move, we move the 1st character ("c") to the end, obtaining the string "bac".\nIn the second move, we move the 1st character ("b") to the end, obtaining the final result "acb".\n
\n\n
\n

Example 2:

\n\n
\nInput: s = "baaca", k = 3\nOutput: "aaabc"\nExplanation: \nIn the first move, we move the 1st character ("b") to the end, obtaining the string "aacab".\nIn the second move, we move the 3rd character ("c") to the end, obtaining the final result "aaabc".\n
\n\n

 

\n\n

Note:

\n\n
    \n\t
  1. 1 <= k <= s.length <= 1000
  2. \n\t
  3. s consists of lowercase letters only.
  4. \n
\n
\n
\n", "content_cn": "

\u7ed9\u51fa\u4e86\u4e00\u4e2a\u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210\u7684\u5b57\u7b26\u4e32 S\u3002\u7136\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u8fdb\u884c\u4efb\u610f\u6b21\u6570\u7684\u79fb\u52a8\u3002

\n\n

\u5728\u6bcf\u6b21\u79fb\u52a8\u4e2d\uff0c\u6211\u4eec\u9009\u62e9\u524d K \u4e2a\u5b57\u6bcd\u4e2d\u7684\u4e00\u4e2a\uff08\u4ece\u5de6\u4fa7\u5f00\u59cb\uff09\uff0c\u5c06\u5176\u4ece\u539f\u4f4d\u7f6e\u79fb\u9664\uff0c\u5e76\u653e\u7f6e\u5728\u5b57\u7b26\u4e32\u7684\u672b\u5c3e\u3002

\n\n

\u8fd4\u56de\u6211\u4eec\u5728\u4efb\u610f\u6b21\u6570\u7684\u79fb\u52a8\u4e4b\u540e\u53ef\u4ee5\u62e5\u6709\u7684\u6309\u5b57\u5178\u987a\u5e8f\u6392\u5217\u7684\u6700\u5c0f\u5b57\u7b26\u4e32\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aS = "cba", K = 1\n\u8f93\u51fa\uff1a"acb"\n\u89e3\u91ca\uff1a\n\u5728\u7b2c\u4e00\u6b65\u4e2d\uff0c\u6211\u4eec\u5c06\u7b2c\u4e00\u4e2a\u5b57\u7b26\uff08“c”\uff09\u79fb\u52a8\u5230\u6700\u540e\uff0c\u83b7\u5f97\u5b57\u7b26\u4e32 “bac”\u3002\n\u5728\u7b2c\u4e8c\u6b65\u4e2d\uff0c\u6211\u4eec\u5c06\u7b2c\u4e00\u4e2a\u5b57\u7b26\uff08“b”\uff09\u79fb\u52a8\u5230\u6700\u540e\uff0c\u83b7\u5f97\u6700\u7ec8\u7ed3\u679c “acb”\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aS = "baaca", K = 3\n\u8f93\u51fa\uff1a"aaabc"\n\u89e3\u91ca\uff1a\n\u5728\u7b2c\u4e00\u6b65\u4e2d\uff0c\u6211\u4eec\u5c06\u7b2c\u4e00\u4e2a\u5b57\u7b26\uff08“b”\uff09\u79fb\u52a8\u5230\u6700\u540e\uff0c\u83b7\u5f97\u5b57\u7b26\u4e32 “aacab”\u3002\n\u5728\u7b2c\u4e8c\u6b65\u4e2d\uff0c\u6211\u4eec\u5c06\u7b2c\u4e09\u4e2a\u5b57\u7b26\uff08“c”\uff09\u79fb\u52a8\u5230\u6700\u540e\uff0c\u83b7\u5f97\u6700\u7ec8\u7ed3\u679c “aaabc”\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= K <= S.length <= 1000
  2. \n\t
  3. S \u53ea\u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210\u3002
  4. \n
\n", "tags_en": ["Math", "String"], "tags_cn": ["\u6570\u5b66", "\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string orderlyQueue(string s, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String orderlyQueue(String s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def orderlyQueue(self, s, k):\n \"\"\"\n :type s: str\n :type k: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def orderlyQueue(self, s: str, k: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * orderlyQueue(char * s, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string OrderlyQueue(string s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number} k\n * @return {string}\n */\nvar orderlyQueue = function(s, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer} k\n# @return {String}\ndef orderly_queue(s, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func orderlyQueue(_ s: String, _ k: Int) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func orderlyQueue(s string, k int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def orderlyQueue(s: String, k: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun orderlyQueue(s: String, k: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn orderly_queue(s: String, k: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer $k\n * @return String\n */\n function orderlyQueue($s, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function orderlyQueue(s: string, k: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (orderly-queue s k)\n (-> string? exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0899](https://leetcode-cn.com/problems/orderly-queue)", "[\u6709\u5e8f\u961f\u5217](/solution/0800-0899/0899.Orderly%20Queue/README.md)", "`\u6570\u5b66`,`\u5b57\u7b26\u4e32`", "\u56f0\u96be", ""], "md_table_row_en": ["[0899](https://leetcode.com/problems/orderly-queue)", "[Orderly Queue](/solution/0800-0899/0899.Orderly%20Queue/README_EN.md)", "`Math`,`String`", "Hard", ""]}, {"question_id": "0934", "frontend_question_id": "0898", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/bitwise-ors-of-subarrays", "url_en": "https://leetcode.com/problems/bitwise-ors-of-subarrays", "relative_path_cn": "/solution/0800-0899/0898.Bitwise%20ORs%20of%20Subarrays/README.md", "relative_path_en": "/solution/0800-0899/0898.Bitwise%20ORs%20of%20Subarrays/README_EN.md", "title_cn": "\u5b50\u6570\u7ec4\u6309\u4f4d\u6216\u64cd\u4f5c", "title_en": "Bitwise ORs of Subarrays", "question_title_slug": "bitwise-ors-of-subarrays", "content_en": "

We have an array arr of non-negative integers.

\n\n

For every (contiguous) subarray sub = [arr[i], arr[i + 1], ..., arr[j]] (with i <= j), we take the bitwise OR of all the elements in sub, obtaining a result arr[i] | arr[i + 1] | ... | arr[j].

\n\n

Return the number of possible results. Results that occur more than once are only counted once in the final answer

\n\n

 

\n

Example 1:

\n\n
\nInput: arr = [0]\nOutput: 1\nExplanation: There is only one possible result: 0.\n
\n\n

Example 2:

\n\n
\nInput: arr = [1,1,2]\nOutput: 3\nExplanation: The possible subarrays are [1], [1], [2], [1, 1], [1, 2], [1, 1, 2].\nThese yield the results 1, 1, 2, 1, 3, 3.\nThere are 3 unique values, so the answer is 3.\n
\n\n

Example 3:

\n\n
\nInput: arr = [1,2,4]\nOutput: 6\nExplanation: The possible results are 1, 2, 3, 4, 6, and 7.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 5 * 104
  • \n\t
  • 0 <= nums[i] <= 109
  • \n
\n", "content_cn": "

\u6211\u4eec\u6709\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\u6570\u7ec4 A\u3002

\n\n

\u5bf9\u4e8e\u6bcf\u4e2a\uff08\u8fde\u7eed\u7684\uff09\u5b50\u6570\u7ec4 B = [A[i], A[i+1], ..., A[j]] \uff08 i <= j\uff09\uff0c\u6211\u4eec\u5bf9 B \u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u8fdb\u884c\u6309\u4f4d\u6216\u64cd\u4f5c\uff0c\u83b7\u5f97\u7ed3\u679c A[i] | A[i+1] | ... | A[j]\u3002

\n\n

\u8fd4\u56de\u53ef\u80fd\u7ed3\u679c\u7684\u6570\u91cf\u3002 \uff08\u591a\u6b21\u51fa\u73b0\u7684\u7ed3\u679c\u5728\u6700\u7ec8\u7b54\u6848\u4e2d\u4ec5\u8ba1\u7b97\u4e00\u6b21\u3002\uff09

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a[0]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\n\u53ea\u6709\u4e00\u4e2a\u53ef\u80fd\u7684\u7ed3\u679c 0 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a[1,1,2]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\n\u53ef\u80fd\u7684\u5b50\u6570\u7ec4\u4e3a [1]\uff0c[1]\uff0c[2]\uff0c[1, 1]\uff0c[1, 2]\uff0c[1, 1, 2]\u3002\n\u4ea7\u751f\u7684\u7ed3\u679c\u4e3a 1\uff0c1\uff0c2\uff0c1\uff0c3\uff0c3 \u3002\n\u6709\u4e09\u4e2a\u552f\u4e00\u503c\uff0c\u6240\u4ee5\u7b54\u6848\u662f 3 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1a[1,2,4]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\n\u53ef\u80fd\u7684\u7ed3\u679c\u662f 1\uff0c2\uff0c3\uff0c4\uff0c6\uff0c\u4ee5\u53ca 7 \u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= A.length <= 50000
  2. \n\t
  3. 0 <= A[i] <= 10^9
  4. \n
\n", "tags_en": ["Bit Manipulation", "Dynamic Programming"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int subarrayBitwiseORs(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int subarrayBitwiseORs(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def subarrayBitwiseORs(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def subarrayBitwiseORs(self, arr: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint subarrayBitwiseORs(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SubarrayBitwiseORs(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar subarrayBitwiseORs = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef subarray_bitwise_o_rs(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func subarrayBitwiseORs(_ arr: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func subarrayBitwiseORs(arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def subarrayBitwiseORs(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun subarrayBitwiseORs(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn subarray_bitwise_o_rs(arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function subarrayBitwiseORs($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function subarrayBitwiseORs(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (subarray-bitwise-o-rs arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0898](https://leetcode-cn.com/problems/bitwise-ors-of-subarrays)", "[\u5b50\u6570\u7ec4\u6309\u4f4d\u6216\u64cd\u4f5c](/solution/0800-0899/0898.Bitwise%20ORs%20of%20Subarrays/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0898](https://leetcode.com/problems/bitwise-ors-of-subarrays)", "[Bitwise ORs of Subarrays](/solution/0800-0899/0898.Bitwise%20ORs%20of%20Subarrays/README_EN.md)", "`Bit Manipulation`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0933", "frontend_question_id": "0897", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/increasing-order-search-tree", "url_en": "https://leetcode.com/problems/increasing-order-search-tree", "relative_path_cn": "/solution/0800-0899/0897.Increasing%20Order%20Search%20Tree/README.md", "relative_path_en": "/solution/0800-0899/0897.Increasing%20Order%20Search%20Tree/README_EN.md", "title_cn": "\u9012\u589e\u987a\u5e8f\u641c\u7d22\u6811", "title_en": "Increasing Order Search Tree", "question_title_slug": "increasing-order-search-tree", "content_en": "

Given the root of a binary search tree, rearrange the tree in in-order so that the leftmost node in the tree is now the root of the tree, and every node has no left child and only one right child.

\r\n\r\n

 

\r\n

Example 1:

\r\n\"\"\r\n
\r\nInput: root = [5,3,6,2,4,null,8,1,null,null,null,7,9]\r\nOutput: [1,null,2,null,3,null,4,null,5,null,6,null,7,null,8,null,9]\r\n
\r\n\r\n

Example 2:

\r\n\"\"\r\n
\r\nInput: root = [5,1,7]\r\nOutput: [1,null,5,null,7]\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • The number of nodes in the given tree will be in the range [1, 100].
  • \r\n\t
  • 0 <= Node.val <= 1000
  • \r\n
", "content_cn": "

\u7ed9\u4f60\u4e00\u68f5\u4e8c\u53c9\u641c\u7d22\u6811\uff0c\u8bf7\u4f60 \u6309\u4e2d\u5e8f\u904d\u5386 \u5c06\u5176\u91cd\u65b0\u6392\u5217\u4e3a\u4e00\u68f5\u9012\u589e\u987a\u5e8f\u641c\u7d22\u6811\uff0c\u4f7f\u6811\u4e2d\u6700\u5de6\u8fb9\u7684\u8282\u70b9\u6210\u4e3a\u6811\u7684\u6839\u8282\u70b9\uff0c\u5e76\u4e14\u6bcf\u4e2a\u8282\u70b9\u6ca1\u6709\u5de6\u5b50\u8282\u70b9\uff0c\u53ea\u6709\u4e00\u4e2a\u53f3\u5b50\u8282\u70b9\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1aroot = [5,3,6,2,4,null,8,1,null,null,null,7,9]\n\u8f93\u51fa\uff1a[1,null,2,null,3,null,4,null,5,null,6,null,7,null,8,null,9]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1aroot = [5,1,7]\n\u8f93\u51fa\uff1a[1,null,5,null,7]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u6811\u4e2d\u8282\u70b9\u6570\u7684\u53d6\u503c\u8303\u56f4\u662f [1, 100]
  • \n\t
  • 0 <= Node.val <= 1000
  • \n
\n", "tags_en": ["Tree", "Depth-first Search", "Recursion"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u9012\u5f52"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* increasingBST(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode increasingBST(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def increasingBST(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: TreeNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def increasingBST(self, root: TreeNode) -> TreeNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* increasingBST(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode IncreasingBST(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {TreeNode}\n */\nvar increasingBST = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {TreeNode}\ndef increasing_bst(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func increasingBST(_ root: TreeNode?) -> TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc increasingBST(root *TreeNode) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def increasingBST(root: TreeNode): TreeNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun increasingBST(root: TreeNode?): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn increasing_bst(root: Option>>) -> Option>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return TreeNode\n */\n function increasingBST($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction increasingBST(root: TreeNode | null): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (increasing-bst root)\n (-> (or/c tree-node? #f) (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0897](https://leetcode-cn.com/problems/increasing-order-search-tree)", "[\u9012\u589e\u987a\u5e8f\u641c\u7d22\u6811](/solution/0800-0899/0897.Increasing%20Order%20Search%20Tree/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u9012\u5f52`", "\u7b80\u5355", ""], "md_table_row_en": ["[0897](https://leetcode.com/problems/increasing-order-search-tree)", "[Increasing Order Search Tree](/solution/0800-0899/0897.Increasing%20Order%20Search%20Tree/README_EN.md)", "`Tree`,`Depth-first Search`,`Recursion`", "Easy", ""]}, {"question_id": "0932", "frontend_question_id": "0896", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/monotonic-array", "url_en": "https://leetcode.com/problems/monotonic-array", "relative_path_cn": "/solution/0800-0899/0896.Monotonic%20Array/README.md", "relative_path_en": "/solution/0800-0899/0896.Monotonic%20Array/README_EN.md", "title_cn": "\u5355\u8c03\u6570\u5217", "title_en": "Monotonic Array", "question_title_slug": "monotonic-array", "content_en": "

An array is monotonic if it is either monotone increasing or monotone decreasing.

\n\n

An array nums is monotone increasing if for all i <= j, nums[i] <= nums[j].  An array nums is monotone decreasing if for all i <= j, nums[i] >= nums[j].

\n\n

Return true if and only if the given array nums is monotonic.

\n\n

 

\n\n
    \n
\n\n
\n

Example 1:

\n\n
\nInput: nums = [1,2,2,3]\nOutput: true\n
\n\n
\n

Example 2:

\n\n
\nInput: nums = [6,5,4,4]\nOutput: true\n
\n\n
\n

Example 3:

\n\n
\nInput: nums = [1,3,2]\nOutput: false\n
\n\n
\n

Example 4:

\n\n
\nInput: nums = [1,2,4,5]\nOutput: true\n
\n\n
\n

Example 5:

\n\n
\nInput: nums = [1,1,1]\nOutput: true\n
\n\n

 

\n\n

Note:

\n\n
    \n\t
  1. 1 <= nums.length <= 50000
  2. \n\t
  3. -100000 <= nums[i] <= 100000
  4. \n
\n
\n
\n
\n
\n
\n", "content_cn": "

\u5982\u679c\u6570\u7ec4\u662f\u5355\u8c03\u9012\u589e\u6216\u5355\u8c03\u9012\u51cf\u7684\uff0c\u90a3\u4e48\u5b83\u662f\u5355\u8c03\u7684\u3002

\n\n

\u5982\u679c\u5bf9\u4e8e\u6240\u6709 i <= j\uff0cA[i] <= A[j]\uff0c\u90a3\u4e48\u6570\u7ec4 A \u662f\u5355\u8c03\u9012\u589e\u7684\u3002 \u5982\u679c\u5bf9\u4e8e\u6240\u6709 i <= j\uff0cA[i]> = A[j]\uff0c\u90a3\u4e48\u6570\u7ec4 A \u662f\u5355\u8c03\u9012\u51cf\u7684\u3002

\n\n

\u5f53\u7ed9\u5b9a\u7684\u6570\u7ec4 A \u662f\u5355\u8c03\u6570\u7ec4\u65f6\u8fd4\u56de true\uff0c\u5426\u5219\u8fd4\u56de false\u3002

\n\n

 

\n\n
    \n
\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a[1,2,2,3]\n\u8f93\u51fa\uff1atrue\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a[6,5,4,4]\n\u8f93\u51fa\uff1atrue\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1a[1,3,2]\n\u8f93\u51fa\uff1afalse\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1a[1,2,4,5]\n\u8f93\u51fa\uff1atrue\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1a[1,1,1]\n\u8f93\u51fa\uff1atrue\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= A.length <= 50000
  2. \n\t
  3. -100000 <= A[i] <= 100000
  4. \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isMonotonic(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isMonotonic(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isMonotonic(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isMonotonic(self, nums: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isMonotonic(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsMonotonic(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {boolean}\n */\nvar isMonotonic = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Boolean}\ndef is_monotonic(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isMonotonic(_ nums: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isMonotonic(nums []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isMonotonic(nums: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isMonotonic(nums: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_monotonic(nums: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Boolean\n */\n function isMonotonic($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isMonotonic(nums: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-monotonic nums)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0896](https://leetcode-cn.com/problems/monotonic-array)", "[\u5355\u8c03\u6570\u5217](/solution/0800-0899/0896.Monotonic%20Array/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0896](https://leetcode.com/problems/monotonic-array)", "[Monotonic Array](/solution/0800-0899/0896.Monotonic%20Array/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0931", "frontend_question_id": "0895", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-frequency-stack", "url_en": "https://leetcode.com/problems/maximum-frequency-stack", "relative_path_cn": "/solution/0800-0899/0895.Maximum%20Frequency%20Stack/README.md", "relative_path_en": "/solution/0800-0899/0895.Maximum%20Frequency%20Stack/README_EN.md", "title_cn": "\u6700\u5927\u9891\u7387\u6808", "title_en": "Maximum Frequency Stack", "question_title_slug": "maximum-frequency-stack", "content_en": "

Design a stack-like data structure to push elements to the stack and pop the most frequent element from the stack.

\n\n

Implement the FreqStack class:

\n\n
    \n\t
  • FreqStack() constructs an empty frequency stack.
  • \n\t
  • void push(int val) pushes an integer val onto the top of the stack.
  • \n\t
  • int pop() removes and returns the most frequent element in the stack.\n\t
      \n\t\t
    • If there is a tie for the most frequent element, the element closest to the stack's top is removed and returned.
    • \n\t
    \n\t
  • \n
\n\n

 

\n

Example 1:

\n\n
\nInput\n["FreqStack", "push", "push", "push", "push", "push", "push", "pop", "pop", "pop", "pop"]\n[[], [5], [7], [5], [7], [4], [5], [], [], [], []]\nOutput\n[null, null, null, null, null, null, null, 5, 7, 5, 4]\n\nExplanation\nFreqStack freqStack = new FreqStack();\nfreqStack.push(5); // The stack is [5]\nfreqStack.push(7); // The stack is [5,7]\nfreqStack.push(5); // The stack is [5,7,5]\nfreqStack.push(7); // The stack is [5,7,5,7]\nfreqStack.push(4); // The stack is [5,7,5,7,4]\nfreqStack.push(5); // The stack is [5,7,5,7,4,5]\nfreqStack.pop();   // return 5, as 5 is the most frequent. The stack becomes [5,7,5,7,4].\nfreqStack.pop();   // return 7, as 5 and 7 is the most frequent, but 7 is closest to the top. The stack becomes [5,7,5,4].\nfreqStack.pop();   // return 5, as 5 is the most frequent. The stack becomes [5,7,4].\nfreqStack.pop();   // return 4, as 4, 5 and 7 is the most frequent, but 4 is closest to the top. The stack becomes [5,7].\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 0 <= val <= 109
  • \n\t
  • At most 2 * 104 calls will be made to push and pop.
  • \n\t
  • It is guaranteed that there will be at least one element in the stack before calling pop.
  • \n
\n", "content_cn": "

\u5b9e\u73b0 FreqStack\uff0c\u6a21\u62df\u7c7b\u4f3c\u6808\u7684\u6570\u636e\u7ed3\u6784\u7684\u64cd\u4f5c\u7684\u4e00\u4e2a\u7c7b\u3002

\n\n

FreqStack \u6709\u4e24\u4e2a\u51fd\u6570\uff1a

\n\n
    \n\t
  • push(int x)\uff0c\u5c06\u6574\u6570 x \u63a8\u5165\u6808\u4e2d\u3002
  • \n\t
  • pop()\uff0c\u5b83\u79fb\u9664\u5e76\u8fd4\u56de\u6808\u4e2d\u51fa\u73b0\u6700\u9891\u7e41\u7684\u5143\u7d20\u3002\n\t
      \n\t\t
    • \u5982\u679c\u6700\u9891\u7e41\u7684\u5143\u7d20\u4e0d\u53ea\u4e00\u4e2a\uff0c\u5219\u79fb\u9664\u5e76\u8fd4\u56de\u6700\u63a5\u8fd1\u6808\u9876\u7684\u5143\u7d20\u3002
    • \n\t
    \n\t
  • \n
\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1a\n["FreqStack","push","push","push","push","push","push","pop","pop","pop","pop"],\n[[],[5],[7],[5],[7],[4],[5],[],[],[],[]]\n\u8f93\u51fa\uff1a[null,null,null,null,null,null,null,5,7,5,4]\n\u89e3\u91ca\uff1a\n\u6267\u884c\u516d\u6b21 .push \u64cd\u4f5c\u540e\uff0c\u6808\u81ea\u5e95\u5411\u4e0a\u4e3a [5,7,5,7,4,5]\u3002\u7136\u540e\uff1a\n\npop() -> \u8fd4\u56de 5\uff0c\u56e0\u4e3a 5 \u662f\u51fa\u73b0\u9891\u7387\u6700\u9ad8\u7684\u3002\n\u6808\u53d8\u6210 [5,7,5,7,4]\u3002\n\npop() -> \u8fd4\u56de 7\uff0c\u56e0\u4e3a 5 \u548c 7 \u90fd\u662f\u9891\u7387\u6700\u9ad8\u7684\uff0c\u4f46 7 \u6700\u63a5\u8fd1\u6808\u9876\u3002\n\u6808\u53d8\u6210 [5,7,5,4]\u3002\n\npop() -> \u8fd4\u56de 5 \u3002\n\u6808\u53d8\u6210 [5,7,4]\u3002\n\npop() -> \u8fd4\u56de 4 \u3002\n\u6808\u53d8\u6210 [5,7]\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u5bf9 FreqStack.push(int x) \u7684\u8c03\u7528\u4e2d 0 <= x <= 10^9\u3002
  • \n\t
  • \u5982\u679c\u6808\u7684\u5143\u7d20\u6570\u76ee\u4e3a\u96f6\uff0c\u5219\u4fdd\u8bc1\u4e0d\u4f1a\u8c03\u7528  FreqStack.pop()\u3002
  • \n\t
  • \u5355\u4e2a\u6d4b\u8bd5\u6837\u4f8b\u4e2d\uff0c\u5bf9 FreqStack.push \u7684\u603b\u8c03\u7528\u6b21\u6570\u4e0d\u4f1a\u8d85\u8fc7 10000\u3002
  • \n\t
  • \u5355\u4e2a\u6d4b\u8bd5\u6837\u4f8b\u4e2d\uff0c\u5bf9 FreqStack.pop \u7684\u603b\u8c03\u7528\u6b21\u6570\u4e0d\u4f1a\u8d85\u8fc7 10000\u3002
  • \n\t
  • \u6240\u6709\u6d4b\u8bd5\u6837\u4f8b\u4e2d\uff0c\u5bf9 FreqStack.push \u548c FreqStack.pop \u7684\u603b\u8c03\u7528\u6b21\u6570\u4e0d\u4f1a\u8d85\u8fc7 150000\u3002
  • \n
\n\n

 

\n", "tags_en": ["Stack", "Hash Table"], "tags_cn": ["\u6808", "\u54c8\u5e0c\u8868"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class FreqStack {\npublic:\n FreqStack() {\n\n }\n \n void push(int val) {\n\n }\n \n int pop() {\n\n }\n};\n\n/**\n * Your FreqStack object will be instantiated and called as such:\n * FreqStack* obj = new FreqStack();\n * obj->push(val);\n * int param_2 = obj->pop();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class FreqStack {\n\n public FreqStack() {\n\n }\n \n public void push(int val) {\n\n }\n \n public int pop() {\n\n }\n}\n\n/**\n * Your FreqStack object will be instantiated and called as such:\n * FreqStack obj = new FreqStack();\n * obj.push(val);\n * int param_2 = obj.pop();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class FreqStack(object):\n\n def __init__(self):\n\n\n def push(self, val):\n \"\"\"\n :type val: int\n :rtype: None\n \"\"\"\n\n\n def pop(self):\n \"\"\"\n :rtype: int\n \"\"\"\n\n\n\n# Your FreqStack object will be instantiated and called as such:\n# obj = FreqStack()\n# obj.push(val)\n# param_2 = obj.pop()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class FreqStack:\n\n def __init__(self):\n\n\n def push(self, val: int) -> None:\n\n\n def pop(self) -> int:\n\n\n\n# Your FreqStack object will be instantiated and called as such:\n# obj = FreqStack()\n# obj.push(val)\n# param_2 = obj.pop()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} FreqStack;\n\n\nFreqStack* freqStackCreate() {\n\n}\n\nvoid freqStackPush(FreqStack* obj, int val) {\n\n}\n\nint freqStackPop(FreqStack* obj) {\n\n}\n\nvoid freqStackFree(FreqStack* obj) {\n\n}\n\n/**\n * Your FreqStack struct will be instantiated and called as such:\n * FreqStack* obj = freqStackCreate();\n * freqStackPush(obj, val);\n \n * int param_2 = freqStackPop(obj);\n \n * freqStackFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class FreqStack {\n\n public FreqStack() {\n\n }\n \n public void Push(int val) {\n\n }\n \n public int Pop() {\n\n }\n}\n\n/**\n * Your FreqStack object will be instantiated and called as such:\n * FreqStack obj = new FreqStack();\n * obj.Push(val);\n * int param_2 = obj.Pop();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "\nvar FreqStack = function() {\n\n};\n\n/** \n * @param {number} val\n * @return {void}\n */\nFreqStack.prototype.push = function(val) {\n\n};\n\n/**\n * @return {number}\n */\nFreqStack.prototype.pop = function() {\n\n};\n\n/**\n * Your FreqStack object will be instantiated and called as such:\n * var obj = new FreqStack()\n * obj.push(val)\n * var param_2 = obj.pop()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class FreqStack\n def initialize()\n\n end\n\n\n=begin\n :type val: Integer\n :rtype: Void\n=end\n def push(val)\n\n end\n\n\n=begin\n :rtype: Integer\n=end\n def pop()\n\n end\n\n\nend\n\n# Your FreqStack object will be instantiated and called as such:\n# obj = FreqStack.new()\n# obj.push(val)\n# param_2 = obj.pop()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass FreqStack {\n\n init() {\n\n }\n \n func push(_ val: Int) {\n\n }\n \n func pop() -> Int {\n\n }\n}\n\n/**\n * Your FreqStack object will be instantiated and called as such:\n * let obj = FreqStack()\n * obj.push(val)\n * let ret_2: Int = obj.pop()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type FreqStack struct {\n\n}\n\n\nfunc Constructor() FreqStack {\n\n}\n\n\nfunc (this *FreqStack) Push(val int) {\n\n}\n\n\nfunc (this *FreqStack) Pop() int {\n\n}\n\n\n/**\n * Your FreqStack object will be instantiated and called as such:\n * obj := Constructor();\n * obj.Push(val);\n * param_2 := obj.Pop();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class FreqStack() {\n\n def push(`val`: Int) {\n\n }\n\n def pop(): Int = {\n\n }\n\n}\n\n/**\n * Your FreqStack object will be instantiated and called as such:\n * var obj = new FreqStack()\n * obj.push(`val`)\n * var param_2 = obj.pop()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class FreqStack() {\n\n fun push(`val`: Int) {\n\n }\n\n fun pop(): Int {\n\n }\n\n}\n\n/**\n * Your FreqStack object will be instantiated and called as such:\n * var obj = FreqStack()\n * obj.push(`val`)\n * var param_2 = obj.pop()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct FreqStack {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl FreqStack {\n\n fn new() -> Self {\n\n }\n \n fn push(&self, val: i32) {\n\n }\n \n fn pop(&self) -> i32 {\n\n }\n}\n\n/**\n * Your FreqStack object will be instantiated and called as such:\n * let obj = FreqStack::new();\n * obj.push(val);\n * let ret_2: i32 = obj.pop();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class FreqStack {\n /**\n */\n function __construct() {\n\n }\n\n /**\n * @param Integer $val\n * @return NULL\n */\n function push($val) {\n\n }\n\n /**\n * @return Integer\n */\n function pop() {\n\n }\n}\n\n/**\n * Your FreqStack object will be instantiated and called as such:\n * $obj = FreqStack();\n * $obj->push($val);\n * $ret_2 = $obj->pop();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class FreqStack {\n constructor() {\n\n }\n\n push(val: number): void {\n\n }\n\n pop(): number {\n\n }\n}\n\n/**\n * Your FreqStack object will be instantiated and called as such:\n * var obj = new FreqStack()\n * obj.push(val)\n * var param_2 = obj.pop()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define freq-stack%\n (class object%\n (super-new)\n (init-field)\n \n ; push : exact-integer? -> void?\n (define/public (push val)\n\n )\n ; pop : -> exact-integer?\n (define/public (pop)\n\n )))\n\n;; Your freq-stack% object will be instantiated and called as such:\n;; (define obj (new freq-stack%))\n;; (send obj push val)\n;; (define param_2 (send obj pop))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0895](https://leetcode-cn.com/problems/maximum-frequency-stack)", "[\u6700\u5927\u9891\u7387\u6808](/solution/0800-0899/0895.Maximum%20Frequency%20Stack/README.md)", "`\u6808`,`\u54c8\u5e0c\u8868`", "\u56f0\u96be", ""], "md_table_row_en": ["[0895](https://leetcode.com/problems/maximum-frequency-stack)", "[Maximum Frequency Stack](/solution/0800-0899/0895.Maximum%20Frequency%20Stack/README_EN.md)", "`Stack`,`Hash Table`", "Hard", ""]}, {"question_id": "0930", "frontend_question_id": "0894", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/all-possible-full-binary-trees", "url_en": "https://leetcode.com/problems/all-possible-full-binary-trees", "relative_path_cn": "/solution/0800-0899/0894.All%20Possible%20Full%20Binary%20Trees/README.md", "relative_path_en": "/solution/0800-0899/0894.All%20Possible%20Full%20Binary%20Trees/README_EN.md", "title_cn": "\u6240\u6709\u53ef\u80fd\u7684\u6ee1\u4e8c\u53c9\u6811", "title_en": "All Possible Full Binary Trees", "question_title_slug": "all-possible-full-binary-trees", "content_en": "

Given an integer n, return a list of all possible full binary trees with n nodes. Each node of each tree in the answer must have Node.val == 0.

\n\n

Each element of the answer is the root node of one possible tree. You may return the final list of trees in any order.

\n\n

A full binary tree is a binary tree where each node has exactly 0 or 2 children.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: n = 7\nOutput: [[0,0,0,null,null,0,0,null,null,0,0],[0,0,0,null,null,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,null,null,null,null,0,0],[0,0,0,0,0,null,null,0,0]]\n
\n\n

Example 2:

\n\n
\nInput: n = 3\nOutput: [[0,0,0]]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 20
  • \n
\n", "content_cn": "

\u6ee1\u4e8c\u53c9\u6811\u662f\u4e00\u7c7b\u4e8c\u53c9\u6811\uff0c\u5176\u4e2d\u6bcf\u4e2a\u7ed3\u70b9\u6070\u597d\u6709 0 \u6216 2 \u4e2a\u5b50\u7ed3\u70b9\u3002

\n\n

\u8fd4\u56de\u5305\u542b N \u4e2a\u7ed3\u70b9\u7684\u6240\u6709\u53ef\u80fd\u6ee1\u4e8c\u53c9\u6811\u7684\u5217\u8868\u3002 \u7b54\u6848\u7684\u6bcf\u4e2a\u5143\u7d20\u90fd\u662f\u4e00\u4e2a\u53ef\u80fd\u6811\u7684\u6839\u7ed3\u70b9\u3002

\n\n

\u7b54\u6848\u4e2d\u6bcf\u4e2a\u6811\u7684\u6bcf\u4e2a\u7ed3\u70b9\u90fd\u5fc5\u987b\u6709 node.val=0\u3002

\n\n

\u4f60\u53ef\u4ee5\u6309\u4efb\u4f55\u987a\u5e8f\u8fd4\u56de\u6811\u7684\u6700\u7ec8\u5217\u8868\u3002

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1a7\n\u8f93\u51fa\uff1a[[0,0,0,null,null,0,0,null,null,0,0],[0,0,0,null,null,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,null,null,null,null,0,0],[0,0,0,0,0,null,null,0,0]]\n\u89e3\u91ca\uff1a\n\"\"\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= N <= 20
  • \n
\n", "tags_en": ["Tree", "Recursion"], "tags_cn": ["\u6811", "\u9012\u5f52"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector allPossibleFBT(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public List allPossibleFBT(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def allPossibleFBT(self, n):\n \"\"\"\n :type n: int\n :rtype: List[TreeNode]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def allPossibleFBT(self, n: int) -> List[TreeNode]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nstruct TreeNode** allPossibleFBT(int n, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public IList AllPossibleFBT(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {number} n\n * @return {TreeNode[]}\n */\nvar allPossibleFBT = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {Integer} n\n# @return {TreeNode[]}\ndef all_possible_fbt(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func allPossibleFBT(_ n: Int) -> [TreeNode?] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc allPossibleFBT(n int) []*TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def allPossibleFBT(n: Int): List[TreeNode] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun allPossibleFBT(n: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn all_possible_fbt(n: i32) -> Vec>>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param Integer $n\n * @return TreeNode[]\n */\n function allPossibleFBT($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction allPossibleFBT(n: number): Array {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (all-possible-fbt n)\n (-> exact-integer? (listof (or/c tree-node? #f)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0894](https://leetcode-cn.com/problems/all-possible-full-binary-trees)", "[\u6240\u6709\u53ef\u80fd\u7684\u6ee1\u4e8c\u53c9\u6811](/solution/0800-0899/0894.All%20Possible%20Full%20Binary%20Trees/README.md)", "`\u6811`,`\u9012\u5f52`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0894](https://leetcode.com/problems/all-possible-full-binary-trees)", "[All Possible Full Binary Trees](/solution/0800-0899/0894.All%20Possible%20Full%20Binary%20Trees/README_EN.md)", "`Tree`,`Recursion`", "Medium", ""]}, {"question_id": "0929", "frontend_question_id": "0893", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/groups-of-special-equivalent-strings", "url_en": "https://leetcode.com/problems/groups-of-special-equivalent-strings", "relative_path_cn": "/solution/0800-0899/0893.Groups%20of%20Special-Equivalent%20Strings/README.md", "relative_path_en": "/solution/0800-0899/0893.Groups%20of%20Special-Equivalent%20Strings/README_EN.md", "title_cn": "\u7279\u6b8a\u7b49\u4ef7\u5b57\u7b26\u4e32\u7ec4", "title_en": "Groups of Special-Equivalent Strings", "question_title_slug": "groups-of-special-equivalent-strings", "content_en": "

You are given an array words of strings.

\n\n

A move onto s consists of swapping any two even indexed characters of s, or any two odd indexed characters of s.

\n\n

Two strings s and t are special-equivalent if after any number of moves onto s, s == t.

\n\n

For example, s = "zzxy" and t = "xyzz" are special-equivalent because we may make the moves "zzxy" -> "xzzy" -> "xyzz" that swap s[0] and s[2], then s[1] and s[3].

\n\n

Now, a group of special-equivalent strings from words is a non-empty subset of words such that:

\n\n
    \n\t
  1. Every pair of strings in the group are special equivalent, and;
  2. \n\t
  3. The group is the largest size possible (ie., there isn't a string s not in the group such that s is special equivalent to every string in the group)
  4. \n
\n\n

Return the number of groups of special-equivalent strings from words.

\n\n
 
\n\n
\n

Example 1:

\n\n
\nInput: words = ["abcd","cdab","cbad","xyzz","zzxy","zzyx"]\nOutput: 3\nExplanation: \nOne group is ["abcd", "cdab", "cbad"], since they are all pairwise special equivalent, and none of the other strings are all pairwise special equivalent to these.\n\nThe other two groups are ["xyzz", "zzxy"] and ["zzyx"].  Note that in particular, "zzxy" is not special equivalent to "zzyx".\n
\n\n
\n

Example 2:

\n\n
\nInput: words = ["abc","acb","bac","bca","cab","cba"]\nOutput: 3
\n\n

 

\n
\n
\n\n
\n
\n
\n
\n

Note:

\n\n
    \n\t
  • 1 <= words.length <= 1000
  • \n\t
  • 1 <= words[i].length <= 20
  • \n\t
  • All words[i] have the same length.
  • \n\t
  • All words[i] consist of only lowercase letters.
  • \n
\n
\n
\n
\n
\n", "content_cn": "

\u4f60\u5c06\u5f97\u5230\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4 A\u3002

\n\n

\u6bcf\u6b21\u79fb\u52a8\u90fd\u53ef\u4ee5\u4ea4\u6362 S \u7684\u4efb\u610f\u4e24\u4e2a\u5076\u6570\u4e0b\u6807\u7684\u5b57\u7b26\u6216\u4efb\u610f\u4e24\u4e2a\u5947\u6570\u4e0b\u6807\u7684\u5b57\u7b26\u3002

\n\n

\u5982\u679c\u7ecf\u8fc7\u4efb\u610f\u6b21\u6570\u7684\u79fb\u52a8\uff0cS == T\uff0c\u90a3\u4e48\u4e24\u4e2a\u5b57\u7b26\u4e32 S \u548c T \u662f \u7279\u6b8a\u7b49\u4ef7 \u7684\u3002

\n\n

\u4f8b\u5982\uff0cS = "zzxy" \u548c T = "xyzz" \u662f\u4e00\u5bf9\u7279\u6b8a\u7b49\u4ef7\u5b57\u7b26\u4e32\uff0c\u56e0\u4e3a\u53ef\u4ee5\u5148\u4ea4\u6362 S[0] \u548c S[2]\uff0c\u7136\u540e\u4ea4\u6362 S[1] \u548c S[3]\uff0c\u4f7f\u5f97 "zzxy" -> "xzzy" -> "xyzz" \u3002

\n\n

\u73b0\u5728\u89c4\u5b9a\uff0cA \u7684 \u4e00\u7ec4\u7279\u6b8a\u7b49\u4ef7\u5b57\u7b26\u4e32 \u5c31\u662f A \u7684\u4e00\u4e2a\u540c\u65f6\u6ee1\u8db3\u4e0b\u8ff0\u6761\u4ef6\u7684\u975e\u7a7a\u5b50\u96c6\uff1a

\n\n
    \n\t
  1. \u8be5\u7ec4\u4e2d\u7684\u6bcf\u4e00\u5bf9\u5b57\u7b26\u4e32\u90fd\u662f \u7279\u6b8a\u7b49\u4ef7 \u7684
  2. \n\t
  3. \u8be5\u7ec4\u5b57\u7b26\u4e32\u5df2\u7ecf\u6db5\u76d6\u4e86\u8be5\u7c7b\u522b\u4e2d\u7684\u6240\u6709\u7279\u6b8a\u7b49\u4ef7\u5b57\u7b26\u4e32\uff0c\u5bb9\u91cf\u8fbe\u5230\u7406\u8bba\u4e0a\u7684\u6700\u5927\u503c\uff08\u4e5f\u5c31\u662f\u8bf4\uff0c\u5982\u679c\u4e00\u4e2a\u5b57\u7b26\u4e32\u4e0d\u5728\u8be5\u7ec4\u4e2d\uff0c\u90a3\u4e48\u8fd9\u4e2a\u5b57\u7b26\u4e32\u5c31 \u4e0d\u4f1a \u4e0e\u8be5\u7ec4\u5185\u4efb\u4f55\u5b57\u7b26\u4e32\u7279\u6b8a\u7b49\u4ef7\uff09
  4. \n
\n\n

\u8fd4\u56de A \u4e2d\u7279\u6b8a\u7b49\u4ef7\u5b57\u7b26\u4e32\u7ec4\u7684\u6570\u91cf\u3002

\n\n

 

\n\n
    \n
\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a["abcd","cdab","cbad","xyzz","zzxy","zzyx"]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\n\u5176\u4e2d\u4e00\u7ec4\u4e3a ["abcd", "cdab", "cbad"]\uff0c\u56e0\u4e3a\u5b83\u4eec\u662f\u6210\u5bf9\u7684\u7279\u6b8a\u7b49\u4ef7\u5b57\u7b26\u4e32\uff0c\u4e14\u6ca1\u6709\u5176\u4ed6\u5b57\u7b26\u4e32\u4e0e\u8fd9\u4e9b\u5b57\u7b26\u4e32\u7279\u6b8a\u7b49\u4ef7\u3002\n\u53e6\u5916\u4e24\u7ec4\u5206\u522b\u662f ["xyzz", "zzxy"] \u548c ["zzyx"]\u3002\u7279\u522b\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c"zzxy" \u4e0d\u4e0e "zzyx" \u7279\u6b8a\u7b49\u4ef7\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a["abc","acb","bac","bca","cab","cba"]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a3 \u7ec4 ["abc","cba"]\uff0c["acb","bca"]\uff0c["bac","cab"]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= A.length <= 1000
  • \n\t
  • 1 <= A[i].length <= 20
  • \n\t
  • \u6240\u6709 A[i] \u90fd\u5177\u6709\u76f8\u540c\u7684\u957f\u5ea6\u3002
  • \n\t
  • \u6240\u6709 A[i] \u90fd\u53ea\u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210\u3002
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numSpecialEquivGroups(vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numSpecialEquivGroups(String[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numSpecialEquivGroups(self, words):\n \"\"\"\n :type words: List[str]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numSpecialEquivGroups(self, words: List[str]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numSpecialEquivGroups(char ** words, int wordsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumSpecialEquivGroups(string[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @return {number}\n */\nvar numSpecialEquivGroups = function(words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @return {Integer}\ndef num_special_equiv_groups(words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numSpecialEquivGroups(_ words: [String]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numSpecialEquivGroups(words []string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numSpecialEquivGroups(words: Array[String]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numSpecialEquivGroups(words: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_special_equiv_groups(words: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @return Integer\n */\n function numSpecialEquivGroups($words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numSpecialEquivGroups(words: string[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-special-equiv-groups words)\n (-> (listof string?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0893](https://leetcode-cn.com/problems/groups-of-special-equivalent-strings)", "[\u7279\u6b8a\u7b49\u4ef7\u5b57\u7b26\u4e32\u7ec4](/solution/0800-0899/0893.Groups%20of%20Special-Equivalent%20Strings/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0893](https://leetcode.com/problems/groups-of-special-equivalent-strings)", "[Groups of Special-Equivalent Strings](/solution/0800-0899/0893.Groups%20of%20Special-Equivalent%20Strings/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "0928", "frontend_question_id": "0892", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/surface-area-of-3d-shapes", "url_en": "https://leetcode.com/problems/surface-area-of-3d-shapes", "relative_path_cn": "/solution/0800-0899/0892.Surface%20Area%20of%203D%20Shapes/README.md", "relative_path_en": "/solution/0800-0899/0892.Surface%20Area%20of%203D%20Shapes/README_EN.md", "title_cn": "\u4e09\u7ef4\u5f62\u4f53\u7684\u8868\u9762\u79ef", "title_en": "Surface Area of 3D Shapes", "question_title_slug": "surface-area-of-3d-shapes", "content_en": "

You are given an n x n grid where you have placed some 1 x 1 x 1 cubes. Each value v = grid[i][j] represents a tower of v cubes placed on top of cell (i, j).

\n\n

After placing these cubes, you have decided to glue any directly adjacent cubes to each other, forming several irregular 3D shapes.

\n\n

Return the total surface area of the resulting shapes.

\n\n

Note: The bottom face of each shape counts toward its surface area.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: grid = [[2]]\nOutput: 10\n
\n\n

Example 2:

\n\"\"\n
\nInput: grid = [[1,2],[3,4]]\nOutput: 34\n
\n\n

Example 3:

\n\"\"\n
\nInput: grid = [[1,0],[0,2]]\nOutput: 16\n
\n\n

Example 4:

\n\"\"\n
\nInput: grid = [[1,1,1],[1,0,1],[1,1,1]]\nOutput: 32\n
\n\n

Example 5:

\n\"\"\n
\nInput: grid = [[2,2,2],[2,1,2],[2,2,2]]\nOutput: 46\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == grid.length
  • \n\t
  • n == grid[i].length
  • \n\t
  • 1 <= n <= 50
  • \n\t
  • 0 <= grid[i][j] <= 50
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a n * n \u7684\u7f51\u683c\u00a0grid \uff0c\u4e0a\u9762\u653e\u7f6e\u7740\u4e00\u4e9b\u00a01 x 1 x 1\u00a0\u7684\u6b63\u65b9\u4f53\u3002

\n\n

\u6bcf\u4e2a\u503c\u00a0v = grid[i][j]\u00a0\u8868\u793a\u00a0v\u00a0\u4e2a\u6b63\u65b9\u4f53\u53e0\u653e\u5728\u5bf9\u5e94\u5355\u5143\u683c\u00a0(i, j)\u00a0\u4e0a\u3002

\n\n

\u653e\u7f6e\u597d\u6b63\u65b9\u4f53\u540e\uff0c\u4efb\u4f55\u76f4\u63a5\u76f8\u90bb\u7684\u6b63\u65b9\u4f53\u90fd\u4f1a\u4e92\u76f8\u7c98\u5728\u4e00\u8d77\uff0c\u5f62\u6210\u4e00\u4e9b\u4e0d\u89c4\u5219\u7684\u4e09\u7ef4\u5f62\u4f53\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u6700\u7ec8\u8fd9\u4e9b\u5f62\u4f53\u7684\u603b\u8868\u9762\u79ef\u3002

\n\n

\u6ce8\u610f\uff1a\u6bcf\u4e2a\u5f62\u4f53\u7684\u5e95\u9762\u4e5f\u9700\u8981\u8ba1\u5165\u8868\u9762\u79ef\u4e2d\u3002

\n\n

\u00a0

\n\n
    \n
\n\n

\u793a\u4f8b 1\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1agrid = [[2]]\n\u8f93\u51fa\uff1a10\n
\n\n

\u793a\u4f8b 2\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1agrid = [[1,2],[3,4]]\n\u8f93\u51fa\uff1a34\n
\n\n

\u793a\u4f8b 3\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1agrid = [[1,0],[0,2]]\n\u8f93\u51fa\uff1a16\n
\n\n

\u793a\u4f8b 4\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1agrid = [[1,1,1],[1,0,1],[1,1,1]]\n\u8f93\u51fa\uff1a32\n
\n\n

\u793a\u4f8b 5\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1agrid = [[2,2,2],[2,1,2],[2,2,2]]\n\u8f93\u51fa\uff1a46\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • n == grid.length
  • \n\t
  • n == grid[i].length
  • \n\t
  • 1 <= n <= 50
  • \n\t
  • 0 <= grid[i][j] <= 50
  • \n
\n", "tags_en": ["Geometry", "Math"], "tags_cn": ["\u51e0\u4f55", "\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int surfaceArea(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int surfaceArea(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def surfaceArea(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def surfaceArea(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint surfaceArea(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SurfaceArea(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar surfaceArea = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef surface_area(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func surfaceArea(_ grid: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func surfaceArea(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def surfaceArea(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun surfaceArea(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn surface_area(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function surfaceArea($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function surfaceArea(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (surface-area grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0892](https://leetcode-cn.com/problems/surface-area-of-3d-shapes)", "[\u4e09\u7ef4\u5f62\u4f53\u7684\u8868\u9762\u79ef](/solution/0800-0899/0892.Surface%20Area%20of%203D%20Shapes/README.md)", "`\u51e0\u4f55`,`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0892](https://leetcode.com/problems/surface-area-of-3d-shapes)", "[Surface Area of 3D Shapes](/solution/0800-0899/0892.Surface%20Area%20of%203D%20Shapes/README_EN.md)", "`Geometry`,`Math`", "Easy", ""]}, {"question_id": "0927", "frontend_question_id": "0891", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sum-of-subsequence-widths", "url_en": "https://leetcode.com/problems/sum-of-subsequence-widths", "relative_path_cn": "/solution/0800-0899/0891.Sum%20of%20Subsequence%20Widths/README.md", "relative_path_en": "/solution/0800-0899/0891.Sum%20of%20Subsequence%20Widths/README_EN.md", "title_cn": "\u5b50\u5e8f\u5217\u5bbd\u5ea6\u4e4b\u548c", "title_en": "Sum of Subsequence Widths", "question_title_slug": "sum-of-subsequence-widths", "content_en": "

Given an array of integers nums, consider all non-empty subsequences of nums.

\n\n

For any sequence seq, let the width of seq be the difference between the maximum and minimum element of seq.

\n\n

Return the sum of the widths of all subsequences of nums

\n\n

As the answer may be very large, return the answer modulo 109 + 7.

\n\n
\n

 

\n\n

Example 1:

\n\n
\nInput: nums = [2,1,3]\nOutput: 6\nExplanation:\nSubsequences are [1], [2], [3], [2,1], [2,3], [1,3], [2,1,3].\nThe corresponding widths are 0, 0, 0, 1, 1, 2, 2.\nThe sum of these widths is 6.\n
\n\n

 

\n\n

Note:

\n\n
    \n\t
  • 1 <= nums.length <= 20000
  • \n\t
  • 1 <= nums[i] <= 20000
  • \n
\n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 A \uff0c\u8003\u8651 A \u7684\u6240\u6709\u975e\u7a7a\u5b50\u5e8f\u5217\u3002

\n\n

\u5bf9\u4e8e\u4efb\u610f\u5e8f\u5217 S \uff0c\u8bbe S \u7684\u5bbd\u5ea6\u662f S \u7684\u6700\u5927\u5143\u7d20\u548c\u6700\u5c0f\u5143\u7d20\u7684\u5dee\u3002

\n\n

\u8fd4\u56de A \u7684\u6240\u6709\u5b50\u5e8f\u5217\u7684\u5bbd\u5ea6\u4e4b\u548c\u3002

\n\n

\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u975e\u5e38\u5927\uff0c\u8bf7\u8fd4\u56de\u7b54\u6848\u6a21 10^9+7\u3002

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1a[2,1,3]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\n\u5b50\u5e8f\u5217\u4e3a [1]\uff0c[2]\uff0c[3]\uff0c[2,1]\uff0c[2,3]\uff0c[1,3]\uff0c[2,1,3] \u3002\n\u76f8\u5e94\u7684\u5bbd\u5ea6\u662f 0\uff0c0\uff0c0\uff0c1\uff0c1\uff0c2\uff0c2 \u3002\n\u8fd9\u4e9b\u5bbd\u5ea6\u4e4b\u548c\u662f 6 \u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= A.length <= 20000
  • \n\t
  • 1 <= A[i] <= 20000
  • \n
\n", "tags_en": ["Array", "Math"], "tags_cn": ["\u6570\u7ec4", "\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int sumSubseqWidths(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int sumSubseqWidths(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def sumSubseqWidths(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def sumSubseqWidths(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint sumSubseqWidths(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SumSubseqWidths(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar sumSubseqWidths = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef sum_subseq_widths(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func sumSubseqWidths(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func sumSubseqWidths(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def sumSubseqWidths(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun sumSubseqWidths(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sum_subseq_widths(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function sumSubseqWidths($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function sumSubseqWidths(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (sum-subseq-widths nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0891](https://leetcode-cn.com/problems/sum-of-subsequence-widths)", "[\u5b50\u5e8f\u5217\u5bbd\u5ea6\u4e4b\u548c](/solution/0800-0899/0891.Sum%20of%20Subsequence%20Widths/README.md)", "`\u6570\u7ec4`,`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[0891](https://leetcode.com/problems/sum-of-subsequence-widths)", "[Sum of Subsequence Widths](/solution/0800-0899/0891.Sum%20of%20Subsequence%20Widths/README_EN.md)", "`Array`,`Math`", "Hard", ""]}, {"question_id": "0926", "frontend_question_id": "0890", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-and-replace-pattern", "url_en": "https://leetcode.com/problems/find-and-replace-pattern", "relative_path_cn": "/solution/0800-0899/0890.Find%20and%20Replace%20Pattern/README.md", "relative_path_en": "/solution/0800-0899/0890.Find%20and%20Replace%20Pattern/README_EN.md", "title_cn": "\u67e5\u627e\u548c\u66ff\u6362\u6a21\u5f0f", "title_en": "Find and Replace Pattern", "question_title_slug": "find-and-replace-pattern", "content_en": "

Given a list of strings words and a string pattern, return a list of words[i] that match pattern. You may return the answer in any order.

\n\n

A word matches the pattern if there exists a permutation of letters p so that after replacing every letter x in the pattern with p(x), we get the desired word.

\n\n

Recall that a permutation of letters is a bijection from letters to letters: every letter maps to another letter, and no two letters map to the same letter.

\n\n

 

\n

Example 1:

\n\n
\nInput: words = ["abc","deq","mee","aqq","dkd","ccc"], pattern = "abb"\nOutput: ["mee","aqq"]\nExplanation: "mee" matches the pattern because there is a permutation {a -> m, b -> e, ...}. \n"ccc" does not match the pattern because {a -> c, b -> c, ...} is not a permutation, since a and b map to the same letter.\n
\n\n

Example 2:

\n\n
\nInput: words = ["a","b","c"], pattern = "a"\nOutput: ["a","b","c"]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= pattern.length <= 20
  • \n\t
  • 1 <= words.length <= 50
  • \n\t
  • words[i].length == pattern.length
  • \n\t
  • pattern and words[i] are lowercase English letters.
  • \n
\n", "content_cn": "

\u4f60\u6709\u4e00\u4e2a\u5355\u8bcd\u5217\u8868 words \u548c\u4e00\u4e2a\u6a21\u5f0f  pattern\uff0c\u4f60\u60f3\u77e5\u9053 words \u4e2d\u7684\u54ea\u4e9b\u5355\u8bcd\u4e0e\u6a21\u5f0f\u5339\u914d\u3002

\n\n

\u5982\u679c\u5b58\u5728\u5b57\u6bcd\u7684\u6392\u5217 p \uff0c\u4f7f\u5f97\u5c06\u6a21\u5f0f\u4e2d\u7684\u6bcf\u4e2a\u5b57\u6bcd x \u66ff\u6362\u4e3a p(x) \u4e4b\u540e\uff0c\u6211\u4eec\u5c31\u5f97\u5230\u4e86\u6240\u9700\u7684\u5355\u8bcd\uff0c\u90a3\u4e48\u5355\u8bcd\u4e0e\u6a21\u5f0f\u662f\u5339\u914d\u7684\u3002

\n\n

\uff08\u56de\u60f3\u4e00\u4e0b\uff0c\u5b57\u6bcd\u7684\u6392\u5217\u662f\u4ece\u5b57\u6bcd\u5230\u5b57\u6bcd\u7684\u53cc\u5c04\uff1a\u6bcf\u4e2a\u5b57\u6bcd\u6620\u5c04\u5230\u53e6\u4e00\u4e2a\u5b57\u6bcd\uff0c\u6ca1\u6709\u4e24\u4e2a\u5b57\u6bcd\u6620\u5c04\u5230\u540c\u4e00\u4e2a\u5b57\u6bcd\u3002\uff09

\n\n

\u8fd4\u56de words \u4e2d\u4e0e\u7ed9\u5b9a\u6a21\u5f0f\u5339\u914d\u7684\u5355\u8bcd\u5217\u8868\u3002

\n\n

\u4f60\u53ef\u4ee5\u6309\u4efb\u4f55\u987a\u5e8f\u8fd4\u56de\u7b54\u6848\u3002

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1awords = ["abc","deq","mee","aqq","dkd","ccc"], pattern = "abb"\n\u8f93\u51fa\uff1a["mee","aqq"]\n\u89e3\u91ca\uff1a\n"mee" \u4e0e\u6a21\u5f0f\u5339\u914d\uff0c\u56e0\u4e3a\u5b58\u5728\u6392\u5217 {a -> m, b -> e, ...}\u3002\n"ccc" \u4e0e\u6a21\u5f0f\u4e0d\u5339\u914d\uff0c\u56e0\u4e3a {a -> c, b -> c, ...} \u4e0d\u662f\u6392\u5217\u3002\n\u56e0\u4e3a a \u548c b \u6620\u5c04\u5230\u540c\u4e00\u4e2a\u5b57\u6bcd\u3002
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= words.length <= 50
  • \n\t
  • 1 <= pattern.length = words[i].length <= 20
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findAndReplacePattern(vector& words, string pattern) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List findAndReplacePattern(String[] words, String pattern) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findAndReplacePattern(self, words, pattern):\n \"\"\"\n :type words: List[str]\n :type pattern: str\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findAndReplacePattern(self, words: List[str], pattern: str) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** findAndReplacePattern(char ** words, int wordsSize, char * pattern, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList FindAndReplacePattern(string[] words, string pattern) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @param {string} pattern\n * @return {string[]}\n */\nvar findAndReplacePattern = function(words, pattern) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @param {String} pattern\n# @return {String[]}\ndef find_and_replace_pattern(words, pattern)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findAndReplacePattern(_ words: [String], _ pattern: String) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findAndReplacePattern(words []string, pattern string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findAndReplacePattern(words: Array[String], pattern: String): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findAndReplacePattern(words: Array, pattern: String): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_and_replace_pattern(words: Vec, pattern: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @param String $pattern\n * @return String[]\n */\n function findAndReplacePattern($words, $pattern) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findAndReplacePattern(words: string[], pattern: string): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-and-replace-pattern words pattern)\n (-> (listof string?) string? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0890](https://leetcode-cn.com/problems/find-and-replace-pattern)", "[\u67e5\u627e\u548c\u66ff\u6362\u6a21\u5f0f](/solution/0800-0899/0890.Find%20and%20Replace%20Pattern/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0890](https://leetcode.com/problems/find-and-replace-pattern)", "[Find and Replace Pattern](/solution/0800-0899/0890.Find%20and%20Replace%20Pattern/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "0925", "frontend_question_id": "0889", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-postorder-traversal", "url_en": "https://leetcode.com/problems/construct-binary-tree-from-preorder-and-postorder-traversal", "relative_path_cn": "/solution/0800-0899/0889.Construct%20Binary%20Tree%20from%20Preorder%20and%20Postorder%20Traversal/README.md", "relative_path_en": "/solution/0800-0899/0889.Construct%20Binary%20Tree%20from%20Preorder%20and%20Postorder%20Traversal/README_EN.md", "title_cn": "\u6839\u636e\u524d\u5e8f\u548c\u540e\u5e8f\u904d\u5386\u6784\u9020\u4e8c\u53c9\u6811", "title_en": "Construct Binary Tree from Preorder and Postorder Traversal", "question_title_slug": "construct-binary-tree-from-preorder-and-postorder-traversal", "content_en": "

Return any binary tree that matches the given preorder and postorder traversals.

\r\n\r\n

Values in the traversals pre and post are distinct positive integers.

\r\n\r\n

 

\r\n\r\n
\r\n

Example 1:

\r\n\r\n
\r\nInput: pre = [1,2,4,5,3,6,7], post = [4,5,2,6,7,3,1]\r\nOutput: [1,2,3,4,5,6,7]\r\n
\r\n\r\n

 

\r\n\r\n

Note:

\r\n\r\n
    \r\n\t
  • 1 <= pre.length == post.length <= 30
  • \r\n\t
  • pre[] and post[] are both permutations of 1, 2, ..., pre.length.
  • \r\n\t
  • It is guaranteed an answer exists. If there exists multiple answers, you can return any of them.
  • \r\n
\r\n
\r\n", "content_cn": "

\u8fd4\u56de\u4e0e\u7ed9\u5b9a\u7684\u524d\u5e8f\u548c\u540e\u5e8f\u904d\u5386\u5339\u914d\u7684\u4efb\u4f55\u4e8c\u53c9\u6811\u3002

\n\n

 pre \u548c post \u904d\u5386\u4e2d\u7684\u503c\u662f\u4e0d\u540c\u7684\u6b63\u6574\u6570\u3002

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1apre = [1,2,4,5,3,6,7], post = [4,5,2,6,7,3,1]\n\u8f93\u51fa\uff1a[1,2,3,4,5,6,7]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= pre.length == post.length <= 30
  • \n\t
  • pre[] \u548c post[] \u90fd\u662f 1, 2, ..., pre.length \u7684\u6392\u5217
  • \n\t
  • \u6bcf\u4e2a\u8f93\u5165\u4fdd\u8bc1\u81f3\u5c11\u6709\u4e00\u4e2a\u7b54\u6848\u3002\u5982\u679c\u6709\u591a\u4e2a\u7b54\u6848\uff0c\u53ef\u4ee5\u8fd4\u56de\u5176\u4e2d\u4e00\u4e2a\u3002
  • \n
\n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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 */\nclass Solution {\npublic:\n TreeNode* constructFromPrePost(vector& pre, vector& post) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode(int x) { val = x; }\n * }\n */\nclass Solution {\n public TreeNode constructFromPrePost(int[] pre, int[] post) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution(object):\n def constructFromPrePost(self, pre, post):\n \"\"\"\n :type pre: List[int]\n :type post: List[int]\n :rtype: TreeNode\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution:\n def constructFromPrePost(self, pre: List[int], post: List[int]) -> TreeNode:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* constructFromPrePost(int* pre, int preSize, int* post, int postSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int x) { val = x; }\n * }\n */\npublic class Solution {\n public TreeNode ConstructFromPrePost(int[] pre, int[] post) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val) {\n * this.val = val;\n * this.left = this.right = null;\n * }\n */\n/**\n * @param {number[]} pre\n * @param {number[]} post\n * @return {TreeNode}\n */\nvar constructFromPrePost = function(pre, post) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val)\n# @val = val\n# @left, @right = nil, nil\n# end\n# end\n\n# @param {Integer[]} pre\n# @param {Integer[]} post\n# @return {TreeNode}\ndef construct_from_pre_post(pre, post)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.left = nil\n * self.right = nil\n * }\n * }\n */\nclass Solution {\n func constructFromPrePost(_ pre: [Int], _ post: [Int]) -> TreeNode? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc constructFromPrePost(pre []int, post []int) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(var _value: Int) {\n * var value: Int = _value\n * var left: TreeNode = null\n * var right: TreeNode = null\n * }\n */\nobject Solution {\n def constructFromPrePost(pre: Array[Int], post: Array[Int]): TreeNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun constructFromPrePost(pre: IntArray, post: IntArray): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n// \n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn construct_from_pre_post(pre: Vec, post: Vec) -> Option>> {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($value) { $this->val = $value; }\n * }\n */\nclass Solution {\n\n /**\n * @param Integer[] $pre\n * @param Integer[] $post\n * @return TreeNode\n */\n function constructFromPrePost($pre, $post) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction constructFromPrePost(pre: number[], post: number[]): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (construct-from-pre-post pre post)\n (-> (listof exact-integer?) (listof exact-integer?) (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0889](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-postorder-traversal)", "[\u6839\u636e\u524d\u5e8f\u548c\u540e\u5e8f\u904d\u5386\u6784\u9020\u4e8c\u53c9\u6811](/solution/0800-0899/0889.Construct%20Binary%20Tree%20from%20Preorder%20and%20Postorder%20Traversal/README.md)", "`\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0889](https://leetcode.com/problems/construct-binary-tree-from-preorder-and-postorder-traversal)", "[Construct Binary Tree from Preorder and Postorder Traversal](/solution/0800-0899/0889.Construct%20Binary%20Tree%20from%20Preorder%20and%20Postorder%20Traversal/README_EN.md)", "`Tree`", "Medium", ""]}, {"question_id": "0924", "frontend_question_id": "0888", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/fair-candy-swap", "url_en": "https://leetcode.com/problems/fair-candy-swap", "relative_path_cn": "/solution/0800-0899/0888.Fair%20Candy%20Swap/README.md", "relative_path_en": "/solution/0800-0899/0888.Fair%20Candy%20Swap/README_EN.md", "title_cn": "\u516c\u5e73\u7684\u7cd6\u679c\u68d2\u4ea4\u6362", "title_en": "Fair Candy Swap", "question_title_slug": "fair-candy-swap", "content_en": "

Alice and Bob have candy bars of different sizes: aliceSizes[i] is the size of the i-th bar of candy that Alice has, and bobSizes[j] is the size of the j-th bar of candy that Bob has.

\n\n

Since they are friends, they would like to exchange one candy bar each so that after the exchange, they both have the same total amount of candy.  (The total amount of candy a person has is the sum of the sizes of candy bars they have.)

\n\n

Return an integer array ans where ans[0] is the size of the candy bar that Alice must exchange, and ans[1] is the size of the candy bar that Bob must exchange.

\n\n

If there are multiple answers, you may return any one of them.  It is guaranteed an answer exists.

\n\n

 

\n\n
\n

Example 1:

\n\n
\nInput: aliceSizes = [1,1], bobSizes = [2,2]\nOutput: [1,2]\n
\n\n
\n

Example 2:

\n\n
\nInput: aliceSizes = [1,2], bobSizes = [2,3]\nOutput: [1,2]\n
\n\n
\n

Example 3:

\n\n
\nInput: aliceSizes = [2], bobSizes = [1,3]\nOutput: [2,3]\n
\n\n
\n

Example 4:

\n\n
\nInput: aliceSizes = [1,2,5], bobSizes = [2,4]\nOutput: [5,4]\n
\n\n

 

\n\n

Note:

\n\n
    \n\t
  • 1 <= aliceSizes.length <= 10000
  • \n\t
  • 1 <= bobSizes.length <= 10000
  • \n\t
  • 1 <= aliceSizes[i] <= 100000
  • \n\t
  • 1 <= bobSizes[i] <= 100000
  • \n\t
  • It is guaranteed that Alice and Bob have different total amounts of candy.
  • \n\t
  • It is guaranteed there exists an answer.
  • \n
\n
\n
\n
\n
\n", "content_cn": "

\u7231\u4e3d\u4e1d\u548c\u9c8d\u52c3\u6709\u4e0d\u540c\u5927\u5c0f\u7684\u7cd6\u679c\u68d2\uff1aA[i] \u662f\u7231\u4e3d\u4e1d\u62e5\u6709\u7684\u7b2c i \u6839\u7cd6\u679c\u68d2\u7684\u5927\u5c0f\uff0cB[j] \u662f\u9c8d\u52c3\u62e5\u6709\u7684\u7b2c j \u6839\u7cd6\u679c\u68d2\u7684\u5927\u5c0f\u3002

\n\n

\u56e0\u4e3a\u4ed6\u4eec\u662f\u670b\u53cb\uff0c\u6240\u4ee5\u4ed6\u4eec\u60f3\u4ea4\u6362\u4e00\u6839\u7cd6\u679c\u68d2\uff0c\u8fd9\u6837\u4ea4\u6362\u540e\uff0c\u4ed6\u4eec\u90fd\u6709\u76f8\u540c\u7684\u7cd6\u679c\u603b\u91cf\u3002\uff08\u4e00\u4e2a\u4eba\u62e5\u6709\u7684\u7cd6\u679c\u603b\u91cf\u662f\u4ed6\u4eec\u62e5\u6709\u7684\u7cd6\u679c\u68d2\u5927\u5c0f\u7684\u603b\u548c\u3002\uff09

\n\n

\u8fd4\u56de\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 ans\uff0c\u5176\u4e2d ans[0] \u662f\u7231\u4e3d\u4e1d\u5fc5\u987b\u4ea4\u6362\u7684\u7cd6\u679c\u68d2\u7684\u5927\u5c0f\uff0cans[1]\u00a0\u662f Bob \u5fc5\u987b\u4ea4\u6362\u7684\u7cd6\u679c\u68d2\u7684\u5927\u5c0f\u3002

\n\n

\u5982\u679c\u6709\u591a\u4e2a\u7b54\u6848\uff0c\u4f60\u53ef\u4ee5\u8fd4\u56de\u5176\u4e2d\u4efb\u4f55\u4e00\u4e2a\u3002\u4fdd\u8bc1\u7b54\u6848\u5b58\u5728\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aA = [1,1], B = [2,2]\n\u8f93\u51fa\uff1a[1,2]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aA = [1,2], B = [2,3]\n\u8f93\u51fa\uff1a[1,2]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1aA = [2], B = [1,3]\n\u8f93\u51fa\uff1a[2,3]\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1aA = [1,2,5], B = [2,4]\n\u8f93\u51fa\uff1a[5,4]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= A.length <= 10000
  • \n\t
  • 1 <= B.length <= 10000
  • \n\t
  • 1 <= A[i] <= 100000
  • \n\t
  • 1 <= B[i] <= 100000
  • \n\t
  • \u4fdd\u8bc1\u7231\u4e3d\u4e1d\u4e0e\u9c8d\u52c3\u7684\u7cd6\u679c\u603b\u91cf\u4e0d\u540c\u3002
  • \n\t
  • \u7b54\u6848\u80af\u5b9a\u5b58\u5728\u3002
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector fairCandySwap(vector& aliceSizes, vector& bobSizes) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] fairCandySwap(int[] aliceSizes, int[] bobSizes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def fairCandySwap(self, aliceSizes, bobSizes):\n \"\"\"\n :type aliceSizes: List[int]\n :type bobSizes: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def fairCandySwap(self, aliceSizes: List[int], bobSizes: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* fairCandySwap(int* aliceSizes, int aliceSizesSize, int* bobSizes, int bobSizesSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] FairCandySwap(int[] aliceSizes, int[] bobSizes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} aliceSizes\n * @param {number[]} bobSizes\n * @return {number[]}\n */\nvar fairCandySwap = function(aliceSizes, bobSizes) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} alice_sizes\n# @param {Integer[]} bob_sizes\n# @return {Integer[]}\ndef fair_candy_swap(alice_sizes, bob_sizes)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func fairCandySwap(_ aliceSizes: [Int], _ bobSizes: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func fairCandySwap(aliceSizes []int, bobSizes []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def fairCandySwap(aliceSizes: Array[Int], bobSizes: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun fairCandySwap(aliceSizes: IntArray, bobSizes: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn fair_candy_swap(alice_sizes: Vec, bob_sizes: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $aliceSizes\n * @param Integer[] $bobSizes\n * @return Integer[]\n */\n function fairCandySwap($aliceSizes, $bobSizes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function fairCandySwap(aliceSizes: number[], bobSizes: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (fair-candy-swap aliceSizes bobSizes)\n (-> (listof exact-integer?) (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0888](https://leetcode-cn.com/problems/fair-candy-swap)", "[\u516c\u5e73\u7684\u7cd6\u679c\u68d2\u4ea4\u6362](/solution/0800-0899/0888.Fair%20Candy%20Swap/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0888](https://leetcode.com/problems/fair-candy-swap)", "[Fair Candy Swap](/solution/0800-0899/0888.Fair%20Candy%20Swap/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0923", "frontend_question_id": "0887", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/super-egg-drop", "url_en": "https://leetcode.com/problems/super-egg-drop", "relative_path_cn": "/solution/0800-0899/0887.Super%20Egg%20Drop/README.md", "relative_path_en": "/solution/0800-0899/0887.Super%20Egg%20Drop/README_EN.md", "title_cn": "\u9e21\u86cb\u6389\u843d", "title_en": "Super Egg Drop", "question_title_slug": "super-egg-drop", "content_en": "

You are given k identical eggs and you have access to a building with n floors labeled from 1 to n.

\n\n

You know that there exists a floor f where 0 <= f <= n such that any egg dropped at a floor higher than f will break, and any egg dropped at or below floor f will not break.

\n\n

Each move, you may take an unbroken egg and drop it from any floor x (where 1 <= x <= n). If the egg breaks, you can no longer use it. However, if the egg does not break, you may reuse it in future moves.

\n\n

Return the minimum number of moves that you need to determine with certainty what the value of f is.

\n\n

 

\n

Example 1:

\n\n
\nInput: k = 1, n = 2\nOutput: 2\nExplanation: \nDrop the egg from floor 1. If it breaks, we know that f = 0.\nOtherwise, drop the egg from floor 2. If it breaks, we know that f = 1.\nIf it does not break, then we know f = 2.\nHence, we need at minimum 2 moves to determine with certainty what the value of f is.\n
\n\n

Example 2:

\n\n
\nInput: k = 2, n = 6\nOutput: 3\n
\n\n

Example 3:

\n\n
\nInput: k = 3, n = 14\nOutput: 4\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= k <= 100
  • \n\t
  • 1 <= n <= 104
  • \n
\n", "content_cn": "

\u7ed9\u4f60 k \u679a\u76f8\u540c\u7684\u9e21\u86cb\uff0c\u5e76\u53ef\u4ee5\u4f7f\u7528\u4e00\u680b\u4ece\u7b2c 1 \u5c42\u5230\u7b2c n \u5c42\u5171\u6709 n \u5c42\u697c\u7684\u5efa\u7b51\u3002

\n\n

\u5df2\u77e5\u5b58\u5728\u697c\u5c42 f \uff0c\u6ee1\u8db3\u00a00 <= f <= n \uff0c\u4efb\u4f55\u4ece \u9ad8\u4e8e f \u7684\u697c\u5c42\u843d\u4e0b\u7684\u9e21\u86cb\u90fd\u4f1a\u788e\uff0c\u4ece f \u697c\u5c42\u6216\u6bd4\u5b83\u4f4e\u7684\u697c\u5c42\u843d\u4e0b\u7684\u9e21\u86cb\u90fd\u4e0d\u4f1a\u7834\u3002

\n\n

\u6bcf\u6b21\u64cd\u4f5c\uff0c\u4f60\u53ef\u4ee5\u53d6\u4e00\u679a\u6ca1\u6709\u788e\u7684\u9e21\u86cb\u5e76\u628a\u5b83\u4ece\u4efb\u4e00\u697c\u5c42 x \u6254\u4e0b\uff08\u6ee1\u8db3\u00a01 <= x <= n\uff09\u3002\u5982\u679c\u9e21\u86cb\u788e\u4e86\uff0c\u4f60\u5c31\u4e0d\u80fd\u518d\u6b21\u4f7f\u7528\u5b83\u3002\u5982\u679c\u67d0\u679a\u9e21\u86cb\u6254\u4e0b\u540e\u6ca1\u6709\u6454\u788e\uff0c\u5219\u53ef\u4ee5\u5728\u4e4b\u540e\u7684\u64cd\u4f5c\u4e2d \u91cd\u590d\u4f7f\u7528 \u8fd9\u679a\u9e21\u86cb\u3002

\n\n

\u8bf7\u4f60\u8ba1\u7b97\u5e76\u8fd4\u56de\u8981\u786e\u5b9a f \u786e\u5207\u7684\u503c \u7684 \u6700\u5c0f\u64cd\u4f5c\u6b21\u6570 \u662f\u591a\u5c11\uff1f

\n\u00a0\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1ak = 1, n = 2\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n\u9e21\u86cb\u4ece 1 \u697c\u6389\u843d\u3002\u5982\u679c\u5b83\u788e\u4e86\uff0c\u80af\u5b9a\u80fd\u5f97\u51fa f = 0 \u3002 \n\u5426\u5219\uff0c\u9e21\u86cb\u4ece 2 \u697c\u6389\u843d\u3002\u5982\u679c\u5b83\u788e\u4e86\uff0c\u80af\u5b9a\u80fd\u5f97\u51fa f = 1 \u3002 \n\u5982\u679c\u5b83\u6ca1\u788e\uff0c\u90a3\u4e48\u80af\u5b9a\u80fd\u5f97\u51fa f = 2 \u3002 \n\u56e0\u6b64\uff0c\u5728\u6700\u574f\u7684\u60c5\u51b5\u4e0b\u6211\u4eec\u9700\u8981\u79fb\u52a8 2 \u6b21\u4ee5\u786e\u5b9a f \u662f\u591a\u5c11\u3002 \n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1ak = 2, n = 6\n\u8f93\u51fa\uff1a3\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1ak = 3, n = 14\n\u8f93\u51fa\uff1a4\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= k <= 100
  • \n\t
  • 1 <= n <= 104
  • \n
\n", "tags_en": ["Math", "Binary Search", "Dynamic Programming"], "tags_cn": ["\u6570\u5b66", "\u4e8c\u5206\u67e5\u627e", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int superEggDrop(int k, int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int superEggDrop(int k, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def superEggDrop(self, k, n):\n \"\"\"\n :type k: int\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def superEggDrop(self, k: int, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint superEggDrop(int k, int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SuperEggDrop(int k, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} k\n * @param {number} n\n * @return {number}\n */\nvar superEggDrop = function(k, n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} k\n# @param {Integer} n\n# @return {Integer}\ndef super_egg_drop(k, n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func superEggDrop(_ k: Int, _ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func superEggDrop(k int, n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def superEggDrop(k: Int, n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun superEggDrop(k: Int, n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn super_egg_drop(k: i32, n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $k\n * @param Integer $n\n * @return Integer\n */\n function superEggDrop($k, $n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function superEggDrop(k: number, n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (super-egg-drop k n)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0887](https://leetcode-cn.com/problems/super-egg-drop)", "[\u9e21\u86cb\u6389\u843d](/solution/0800-0899/0887.Super%20Egg%20Drop/README.md)", "`\u6570\u5b66`,`\u4e8c\u5206\u67e5\u627e`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0887](https://leetcode.com/problems/super-egg-drop)", "[Super Egg Drop](/solution/0800-0899/0887.Super%20Egg%20Drop/README_EN.md)", "`Math`,`Binary Search`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0922", "frontend_question_id": "0886", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/possible-bipartition", "url_en": "https://leetcode.com/problems/possible-bipartition", "relative_path_cn": "/solution/0800-0899/0886.Possible%20Bipartition/README.md", "relative_path_en": "/solution/0800-0899/0886.Possible%20Bipartition/README_EN.md", "title_cn": "\u53ef\u80fd\u7684\u4e8c\u5206\u6cd5", "title_en": "Possible Bipartition", "question_title_slug": "possible-bipartition", "content_en": "

Given a set of n people (numbered 1, 2, ..., n), we would like to split everyone into two groups of any size.

\n\n

Each person may dislike some other people, and they should not go into the same group. 

\n\n

Formally, if dislikes[i] = [a, b], it means it is not allowed to put the people numbered a and b into the same group.

\n\n

Return true if and only if it is possible to split everyone into two groups in this way.

\n\n

 

\n\n
\n
\n
    \n
\n
\n
\n\n
\n

Example 1:

\n\n
\nInput: n = 4, dislikes = [[1,2],[1,3],[2,4]]\nOutput: true\nExplanation: group1 [1,4], group2 [2,3]\n
\n\n
\n

Example 2:

\n\n
\nInput: n = 3, dislikes = [[1,2],[1,3],[2,3]]\nOutput: false\n
\n\n
\n

Example 3:

\n\n
\nInput: n = 5, dislikes = [[1,2],[2,3],[3,4],[4,5],[1,5]]\nOutput: false\n
\n
\n
\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 2000
  • \n\t
  • 0 <= dislikes.length <= 10000
  • \n\t
  • dislikes[i].length == 2
  • \n\t
  • 1 <= dislikes[i][j] <= n
  • \n\t
  • dislikes[i][0] < dislikes[i][1]
  • \n\t
  • There does not exist i != j for which dislikes[i] == dislikes[j].
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u7ec4\u00a0N\u00a0\u4eba\uff08\u7f16\u53f7\u4e3a\u00a01, 2, ..., N\uff09\uff0c\u00a0\u6211\u4eec\u60f3\u628a\u6bcf\u4e2a\u4eba\u5206\u8fdb\u4efb\u610f\u5927\u5c0f\u7684\u4e24\u7ec4\u3002

\n\n

\u6bcf\u4e2a\u4eba\u90fd\u53ef\u80fd\u4e0d\u559c\u6b22\u5176\u4ed6\u4eba\uff0c\u90a3\u4e48\u4ed6\u4eec\u4e0d\u5e94\u8be5\u5c5e\u4e8e\u540c\u4e00\u7ec4\u3002

\n\n

\u5f62\u5f0f\u4e0a\uff0c\u5982\u679c dislikes[i] = [a, b]\uff0c\u8868\u793a\u4e0d\u5141\u8bb8\u5c06\u7f16\u53f7\u4e3a a \u548c b \u7684\u4eba\u5f52\u5165\u540c\u4e00\u7ec4\u3002

\n\n

\u5f53\u53ef\u4ee5\u7528\u8fd9\u79cd\u65b9\u6cd5\u5c06\u6240\u6709\u4eba\u5206\u8fdb\u4e24\u7ec4\u65f6\uff0c\u8fd4\u56de true\uff1b\u5426\u5219\u8fd4\u56de false\u3002

\n\n

\u00a0

\n\n
    \n
\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aN = 4, dislikes = [[1,2],[1,3],[2,4]]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1agroup1 [1,4], group2 [2,3]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aN = 3, dislikes = [[1,2],[1,3],[2,3]]\n\u8f93\u51fa\uff1afalse\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1aN = 5, dislikes = [[1,2],[2,3],[3,4],[4,5],[1,5]]\n\u8f93\u51fa\uff1afalse\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= N <= 2000
  • \n\t
  • 0 <= dislikes.length <= 10000
  • \n\t
  • dislikes[i].length == 2
  • \n\t
  • 1 <= dislikes[i][j] <= N
  • \n\t
  • dislikes[i][0] < dislikes[i][1]
  • \n\t
  • \u5bf9\u4e8e dislikes[i] == dislikes[j] \u4e0d\u5b58\u5728 i != j
  • \n
\n", "tags_en": ["Depth-first Search", "Graph"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool possibleBipartition(int n, vector>& dislikes) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean possibleBipartition(int n, int[][] dislikes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def possibleBipartition(self, n, dislikes):\n \"\"\"\n :type n: int\n :type dislikes: List[List[int]]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def possibleBipartition(self, n: int, dislikes: List[List[int]]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool possibleBipartition(int n, int** dislikes, int dislikesSize, int* dislikesColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool PossibleBipartition(int n, int[][] dislikes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} dislikes\n * @return {boolean}\n */\nvar possibleBipartition = function(n, dislikes) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} dislikes\n# @return {Boolean}\ndef possible_bipartition(n, dislikes)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func possibleBipartition(_ n: Int, _ dislikes: [[Int]]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func possibleBipartition(n int, dislikes [][]int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def possibleBipartition(n: Int, dislikes: Array[Array[Int]]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun possibleBipartition(n: Int, dislikes: Array): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn possible_bipartition(n: i32, dislikes: Vec>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $dislikes\n * @return Boolean\n */\n function possibleBipartition($n, $dislikes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function possibleBipartition(n: number, dislikes: number[][]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (possible-bipartition n dislikes)\n (-> exact-integer? (listof (listof exact-integer?)) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0886](https://leetcode-cn.com/problems/possible-bipartition)", "[\u53ef\u80fd\u7684\u4e8c\u5206\u6cd5](/solution/0800-0899/0886.Possible%20Bipartition/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u56fe`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0886](https://leetcode.com/problems/possible-bipartition)", "[Possible Bipartition](/solution/0800-0899/0886.Possible%20Bipartition/README_EN.md)", "`Depth-first Search`,`Graph`", "Medium", ""]}, {"question_id": "0921", "frontend_question_id": "0885", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/spiral-matrix-iii", "url_en": "https://leetcode.com/problems/spiral-matrix-iii", "relative_path_cn": "/solution/0800-0899/0885.Spiral%20Matrix%20III/README.md", "relative_path_en": "/solution/0800-0899/0885.Spiral%20Matrix%20III/README_EN.md", "title_cn": "\u87ba\u65cb\u77e9\u9635 III", "title_en": "Spiral Matrix III", "question_title_slug": "spiral-matrix-iii", "content_en": "

On a 2 dimensional grid with rows rows and cols columns, we start at (rStart, cStart) facing east.

\n\n

Here, the north-west corner of the grid is at the first row and column, and the south-east corner of the grid is at the last row and column.

\n\n

Now, we walk in a clockwise spiral shape to visit every position in this grid. 

\n\n

Whenever we would move outside the boundary of the grid, we continue our walk outside the grid (but may return to the grid boundary later.) 

\n\n

Eventually, we reach all rows * cols spaces of the grid.

\n\n

Return a list of coordinates representing the positions of the grid in the order they were visited.

\n\n

 

\n\n

Example 1:

\n\n
\nInput: rows = 1, cols = 4, rStart = 0, cStart = 0\nOutput: [[0,0],[0,1],[0,2],[0,3]]\n\n\"\"\n
\n\n

 

\n\n

Example 2:

\n\n
\nInput: rows = 5, cols = 6, rStart = 1, cStart = 4\nOutput: [[1,4],[1,5],[2,5],[2,4],[2,3],[1,3],[0,3],[0,4],[0,5],[3,5],[3,4],[3,3],[3,2],[2,2],[1,2],[0,2],[4,5],[4,4],[4,3],[4,2],[4,1],[3,1],[2,1],[1,1],[0,1],[4,0],[3,0],[2,0],[1,0],[0,0]]\n\n\"\"\n
\n\n
\n
\n

 

\n\n

Note:

\n\n
    \n\t
  1. 1 <= rows <= 100
  2. \n\t
  3. 1 <= cols <= 100
  4. \n\t
  5. 0 <= rStart < rows
  6. \n\t
  7. 0 <= cStart < cols
  8. \n
\n
\n
\n", "content_cn": "

\u5728 R \u884c C \u5217\u7684\u77e9\u9635\u4e0a\uff0c\u6211\u4eec\u4ece (r0, c0) \u9762\u671d\u4e1c\u9762\u5f00\u59cb

\n\n

\u8fd9\u91cc\uff0c\u7f51\u683c\u7684\u897f\u5317\u89d2\u4f4d\u4e8e\u7b2c\u4e00\u884c\u7b2c\u4e00\u5217\uff0c\u7f51\u683c\u7684\u4e1c\u5357\u89d2\u4f4d\u4e8e\u6700\u540e\u4e00\u884c\u6700\u540e\u4e00\u5217\u3002

\n\n

\u73b0\u5728\uff0c\u6211\u4eec\u4ee5\u987a\u65f6\u9488\u6309\u87ba\u65cb\u72b6\u884c\u8d70\uff0c\u8bbf\u95ee\u6b64\u7f51\u683c\u4e2d\u7684\u6bcf\u4e2a\u4f4d\u7f6e\u3002

\n\n

\u6bcf\u5f53\u6211\u4eec\u79fb\u52a8\u5230\u7f51\u683c\u7684\u8fb9\u754c\u4e4b\u5916\u65f6\uff0c\u6211\u4eec\u4f1a\u7ee7\u7eed\u5728\u7f51\u683c\u4e4b\u5916\u884c\u8d70\uff08\u4f46\u7a0d\u540e\u53ef\u80fd\u4f1a\u8fd4\u56de\u5230\u7f51\u683c\u8fb9\u754c\uff09\u3002

\n\n

\u6700\u7ec8\uff0c\u6211\u4eec\u5230\u8fc7\u7f51\u683c\u7684\u6240\u6709 R * C \u4e2a\u7a7a\u95f4\u3002

\n\n

\u6309\u7167\u8bbf\u95ee\u987a\u5e8f\u8fd4\u56de\u8868\u793a\u7f51\u683c\u4f4d\u7f6e\u7684\u5750\u6807\u5217\u8868\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aR = 1, C = 4, r0 = 0, c0 = 0\n\u8f93\u51fa\uff1a[[0,0],[0,1],[0,2],[0,3]]\n\n\"\"\n
\n\n

 

\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aR = 5, C = 6, r0 = 1, c0 = 4\n\u8f93\u51fa\uff1a[[1,4],[1,5],[2,5],[2,4],[2,3],[1,3],[0,3],[0,4],[0,5],[3,5],[3,4],[3,3],[3,2],[2,2],[1,2],[0,2],[4,5],[4,4],[4,3],[4,2],[4,1],[3,1],[2,1],[1,1],[0,1],[4,0],[3,0],[2,0],[1,0],[0,0]]\n\n\"\"\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= R <= 100
  2. \n\t
  3. 1 <= C <= 100
  4. \n\t
  5. 0 <= r0 < R
  6. \n\t
  7. 0 <= c0 < C
  8. \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> spiralMatrixIII(int rows, int cols, int rStart, int cStart) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[][] spiralMatrixIII(int rows, int cols, int rStart, int cStart) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def spiralMatrixIII(self, rows, cols, rStart, cStart):\n \"\"\"\n :type rows: int\n :type cols: int\n :type rStart: int\n :type cStart: int\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def spiralMatrixIII(self, rows: int, cols: int, rStart: int, cStart: int) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** spiralMatrixIII(int rows, int cols, int rStart, int cStart, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[][] SpiralMatrixIII(int rows, int cols, int rStart, int cStart) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} rows\n * @param {number} cols\n * @param {number} rStart\n * @param {number} cStart\n * @return {number[][]}\n */\nvar spiralMatrixIII = function(rows, cols, rStart, cStart) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} rows\n# @param {Integer} cols\n# @param {Integer} r_start\n# @param {Integer} c_start\n# @return {Integer[][]}\ndef spiral_matrix_iii(rows, cols, r_start, c_start)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func spiralMatrixIII(_ rows: Int, _ cols: Int, _ rStart: Int, _ cStart: Int) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func spiralMatrixIII(rows int, cols int, rStart int, cStart int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def spiralMatrixIII(rows: Int, cols: Int, rStart: Int, cStart: Int): Array[Array[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun spiralMatrixIII(rows: Int, cols: Int, rStart: Int, cStart: Int): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn spiral_matrix_iii(rows: i32, cols: i32, r_start: i32, c_start: i32) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $rows\n * @param Integer $cols\n * @param Integer $rStart\n * @param Integer $cStart\n * @return Integer[][]\n */\n function spiralMatrixIII($rows, $cols, $rStart, $cStart) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function spiralMatrixIII(rows: number, cols: number, rStart: number, cStart: number): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (spiral-matrix-iii rows cols rStart cStart)\n (-> exact-integer? exact-integer? exact-integer? exact-integer? (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0885](https://leetcode-cn.com/problems/spiral-matrix-iii)", "[\u87ba\u65cb\u77e9\u9635 III](/solution/0800-0899/0885.Spiral%20Matrix%20III/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0885](https://leetcode.com/problems/spiral-matrix-iii)", "[Spiral Matrix III](/solution/0800-0899/0885.Spiral%20Matrix%20III/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "0920", "frontend_question_id": "0884", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/uncommon-words-from-two-sentences", "url_en": "https://leetcode.com/problems/uncommon-words-from-two-sentences", "relative_path_cn": "/solution/0800-0899/0884.Uncommon%20Words%20from%20Two%20Sentences/README.md", "relative_path_en": "/solution/0800-0899/0884.Uncommon%20Words%20from%20Two%20Sentences/README_EN.md", "title_cn": "\u4e24\u53e5\u8bdd\u4e2d\u7684\u4e0d\u5e38\u89c1\u5355\u8bcd", "title_en": "Uncommon Words from Two Sentences", "question_title_slug": "uncommon-words-from-two-sentences", "content_en": "

We are given two sentences s1 and s2.  (A sentence is a string of space separated words.  Each word consists only of lowercase letters.)

\n\n

A word is uncommon if it appears exactly once in one of the sentences, and does not appear in the other sentence.

\n\n

Return a list of all uncommon words. 

\n\n

You may return the list in any order.

\n\n

 

\n\n
    \n
\n\n
\n

Example 1:

\n\n
\nInput: s1 = "this apple is sweet", s2 = "this apple is sour"\nOutput: ["sweet","sour"]\n
\n\n
\n

Example 2:

\n\n
\nInput: s1 = "apple apple", s2 = "banana"\nOutput: ["banana"]\n
\n\n

 

\n\n

Note:

\n\n
    \n\t
  1. 0 <= s1.length <= 200
  2. \n\t
  3. 0 <= s2.length <= 200
  4. \n\t
  5. s1 and s2 both contain only spaces and lowercase letters.
  6. \n
\n
\n
\n", "content_cn": "

\u7ed9\u5b9a\u4e24\u4e2a\u53e5\u5b50 A \u548c B \u3002 \uff08\u53e5\u5b50\u662f\u4e00\u4e32\u7531\u7a7a\u683c\u5206\u9694\u7684\u5355\u8bcd\u3002\u6bcf\u4e2a\u5355\u8bcd\u4ec5\u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210\u3002\uff09

\n\n

\u5982\u679c\u4e00\u4e2a\u5355\u8bcd\u5728\u5176\u4e2d\u4e00\u4e2a\u53e5\u5b50\u4e2d\u53ea\u51fa\u73b0\u4e00\u6b21\uff0c\u5728\u53e6\u4e00\u4e2a\u53e5\u5b50\u4e2d\u5374\u6ca1\u6709\u51fa\u73b0\uff0c\u90a3\u4e48\u8fd9\u4e2a\u5355\u8bcd\u5c31\u662f\u4e0d\u5e38\u89c1\u7684\u3002

\n\n

\u8fd4\u56de\u6240\u6709\u4e0d\u5e38\u7528\u5355\u8bcd\u7684\u5217\u8868\u3002

\n\n

\u60a8\u53ef\u4ee5\u6309\u4efb\u4f55\u987a\u5e8f\u8fd4\u56de\u5217\u8868\u3002

\n\n

 

\n\n
    \n
\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aA = "this apple is sweet", B = "this apple is sour"\n\u8f93\u51fa\uff1a["sweet","sour"]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aA = "apple apple", B = "banana"\n\u8f93\u51fa\uff1a["banana"]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 0 <= A.length <= 200
  2. \n\t
  3. 0 <= B.length <= 200
  4. \n\t
  5. A \u548c B \u90fd\u53ea\u5305\u542b\u7a7a\u683c\u548c\u5c0f\u5199\u5b57\u6bcd\u3002
  6. \n
\n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector uncommonFromSentences(string s1, string s2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String[] uncommonFromSentences(String s1, String s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def uncommonFromSentences(self, s1, s2):\n \"\"\"\n :type s1: str\n :type s2: str\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** uncommonFromSentences(char * s1, char * s2, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string[] UncommonFromSentences(string s1, string s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s1\n * @param {string} s2\n * @return {string[]}\n */\nvar uncommonFromSentences = function(s1, s2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s1\n# @param {String} s2\n# @return {String[]}\ndef uncommon_from_sentences(s1, s2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func uncommonFromSentences(_ s1: String, _ s2: String) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func uncommonFromSentences(s1 string, s2 string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def uncommonFromSentences(s1: String, s2: String): Array[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun uncommonFromSentences(s1: String, s2: String): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn uncommon_from_sentences(s1: String, s2: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s1\n * @param String $s2\n * @return String[]\n */\n function uncommonFromSentences($s1, $s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function uncommonFromSentences(s1: string, s2: string): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (uncommon-from-sentences s1 s2)\n (-> string? string? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0884](https://leetcode-cn.com/problems/uncommon-words-from-two-sentences)", "[\u4e24\u53e5\u8bdd\u4e2d\u7684\u4e0d\u5e38\u89c1\u5355\u8bcd](/solution/0800-0899/0884.Uncommon%20Words%20from%20Two%20Sentences/README.md)", "`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0884](https://leetcode.com/problems/uncommon-words-from-two-sentences)", "[Uncommon Words from Two Sentences](/solution/0800-0899/0884.Uncommon%20Words%20from%20Two%20Sentences/README_EN.md)", "`Hash Table`", "Easy", ""]}, {"question_id": "0919", "frontend_question_id": "0883", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/projection-area-of-3d-shapes", "url_en": "https://leetcode.com/problems/projection-area-of-3d-shapes", "relative_path_cn": "/solution/0800-0899/0883.Projection%20Area%20of%203D%20Shapes/README.md", "relative_path_en": "/solution/0800-0899/0883.Projection%20Area%20of%203D%20Shapes/README_EN.md", "title_cn": "\u4e09\u7ef4\u5f62\u4f53\u6295\u5f71\u9762\u79ef", "title_en": "Projection Area of 3D Shapes", "question_title_slug": "projection-area-of-3d-shapes", "content_en": "

You are given an n x n grid where we place some 1 x 1 x 1 cubes that are axis-aligned with the x, y, and z axes.

\n\n

Each value v = grid[i][j] represents a tower of v cubes placed on top of the cell (i, j).

\n\n

We view the projection of these cubes onto the xy, yz, and zx planes.

\n\n

A projection is like a shadow, that maps our 3-dimensional figure to a 2-dimensional plane. We are viewing the "shadow" when looking at the cubes from the top, the front, and the side.

\n\n

Return the total area of all three projections.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: grid = [[1,2],[3,4]]\nOutput: 17\nExplanation: Here are the three projections ("shadows") of the shape made with each axis-aligned plane.\n
\n\n

Example 2:

\n\n
\nInput: grid = [[2]]\nOutput: 5\n
\n\n

Example 3:

\n\n
\nInput: grid = [[1,0],[0,2]]\nOutput: 8\n
\n\n

Example 4:

\n\n
\nInput: grid = [[1,1,1],[1,0,1],[1,1,1]]\nOutput: 14\n
\n\n

Example 5:

\n\n
\nInput: grid = [[2,2,2],[2,1,2],[2,2,2]]\nOutput: 21\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == grid.length
  • \n\t
  • n == grid[i].length
  • \n\t
  • 1 <= n <= 50
  • \n\t
  • 0 <= grid[i][j] <= 50
  • \n
\n", "content_cn": "

\u5728 N * N \u7684\u7f51\u683c\u4e2d\uff0c\u6211\u4eec\u653e\u7f6e\u4e86\u4e00\u4e9b\u4e0e x\uff0cy\uff0cz \u4e09\u8f74\u5bf9\u9f50\u7684 1 * 1 * 1 \u7acb\u65b9\u4f53\u3002

\n\n

\u6bcf\u4e2a\u503c v = grid[i][j] \u8868\u793a v \u4e2a\u6b63\u65b9\u4f53\u53e0\u653e\u5728\u5355\u5143\u683c (i, j) \u4e0a\u3002

\n\n

\u73b0\u5728\uff0c\u6211\u4eec\u67e5\u770b\u8fd9\u4e9b\u7acb\u65b9\u4f53\u5728 xy\u3001yz \u548c zx \u5e73\u9762\u4e0a\u7684\u6295\u5f71\u3002

\n\n

\u6295\u5f71\u5c31\u50cf\u5f71\u5b50\uff0c\u5c06\u4e09\u7ef4\u5f62\u4f53\u6620\u5c04\u5230\u4e00\u4e2a\u4e8c\u7ef4\u5e73\u9762\u4e0a\u3002

\n\n

\u5728\u8fd9\u91cc\uff0c\u4ece\u9876\u90e8\u3001\u524d\u9762\u548c\u4fa7\u9762\u770b\u7acb\u65b9\u4f53\u65f6\uff0c\u6211\u4eec\u4f1a\u770b\u5230“\u5f71\u5b50”\u3002

\n\n

\u8fd4\u56de\u6240\u6709\u4e09\u4e2a\u6295\u5f71\u7684\u603b\u9762\u79ef\u3002

\n\n

 

\n\n
    \n
\n\n
    \n
\n\n
    \n
\n\n
    \n
\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a[[2]]\n\u8f93\u51fa\uff1a5\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a[[1,2],[3,4]]\n\u8f93\u51fa\uff1a17\n\u89e3\u91ca\uff1a\n\u8fd9\u91cc\u6709\u8be5\u5f62\u4f53\u5728\u4e09\u4e2a\u8f74\u5bf9\u9f50\u5e73\u9762\u4e0a\u7684\u4e09\u4e2a\u6295\u5f71(“\u9634\u5f71\u90e8\u5206”)\u3002\n\"\"\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1a[[1,0],[0,2]]\n\u8f93\u51fa\uff1a8\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1a[[1,1,1],[1,0,1],[1,1,1]]\n\u8f93\u51fa\uff1a14\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1a[[2,2,2],[2,1,2],[2,2,2]]\n\u8f93\u51fa\uff1a21\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= grid.length = grid[0].length <= 50
  • \n\t
  • 0 <= grid[i][j] <= 50
  • \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int projectionArea(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int projectionArea(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def projectionArea(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def projectionArea(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint projectionArea(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ProjectionArea(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar projectionArea = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef projection_area(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func projectionArea(_ grid: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func projectionArea(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def projectionArea(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun projectionArea(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn projection_area(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function projectionArea($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function projectionArea(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (projection-area grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0883](https://leetcode-cn.com/problems/projection-area-of-3d-shapes)", "[\u4e09\u7ef4\u5f62\u4f53\u6295\u5f71\u9762\u79ef](/solution/0800-0899/0883.Projection%20Area%20of%203D%20Shapes/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0883](https://leetcode.com/problems/projection-area-of-3d-shapes)", "[Projection Area of 3D Shapes](/solution/0800-0899/0883.Projection%20Area%20of%203D%20Shapes/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "0918", "frontend_question_id": "0882", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reachable-nodes-in-subdivided-graph", "url_en": "https://leetcode.com/problems/reachable-nodes-in-subdivided-graph", "relative_path_cn": "/solution/0800-0899/0882.Reachable%20Nodes%20In%20Subdivided%20Graph/README.md", "relative_path_en": "/solution/0800-0899/0882.Reachable%20Nodes%20In%20Subdivided%20Graph/README_EN.md", "title_cn": "\u7ec6\u5206\u56fe\u4e2d\u7684\u53ef\u5230\u8fbe\u7ed3\u70b9", "title_en": "Reachable Nodes In Subdivided Graph", "question_title_slug": "reachable-nodes-in-subdivided-graph", "content_en": "

You are given an undirected graph (the "original graph") with n nodes labeled from 0 to n - 1. You decide to subdivide each edge in the graph into a chain of nodes, with the number of new nodes varying between each edge.

\n\n

The graph is given as a 2D array of edges where edges[i] = [ui, vi, cnti] indicates that there is an edge between nodes ui and vi in the original graph, and cnti is the total number of new nodes that you will subdivide the edge into. Note that cnti == 0 means you will not subdivide the edge.

\n\n

To subdivide the edge [ui, vi], replace it with (cnti + 1) new edges and cnti new nodes. The new nodes are x1, x2, ..., xcnti, and the new edges are [ui, x1], [x1, x2], [x2, x3], ..., [xcnti+1, xcnti], [xcnti, vi].

\n\n

In this new graph, you want to know how many nodes are reachable from the node 0, where a node is reachable if the distance is maxMoves or less.

\n\n

Given the original graph and maxMoves, return the number of nodes that are reachable from node 0 in the new graph.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: edges = [[0,1,10],[0,2,1],[1,2,2]], maxMoves = 6, n = 3\nOutput: 13\nExplanation: The edge subdivisions are shown in the image above.\nThe nodes that are reachable are highlighted in yellow.\n
\n\n

Example 2:

\n\n
\nInput: edges = [[0,1,4],[1,2,6],[0,2,8],[1,3,1]], maxMoves = 10, n = 4\nOutput: 23\n
\n\n

Example 3:

\n\n
\nInput: edges = [[1,2,4],[1,4,5],[1,3,1],[2,3,4],[3,4,5]], maxMoves = 17, n = 5\nOutput: 1\nExplanation: Node 0 is disconnected from the rest of the graph, so only node 0 is reachable.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 0 <= edges.length <= min(n * (n - 1) / 2, 104)
  • \n\t
  • edges[i].length == 3
  • \n\t
  • 0 <= ui < vi < n
  • \n\t
  • There are no multiple edges in the graph.
  • \n\t
  • 0 <= cnti <= 104
  • \n\t
  • 0 <= maxMoves <= 109
  • \n\t
  • 1 <= n <= 3000
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u65e0\u5411\u56fe\uff08\u539f\u59cb\u56fe\uff09\uff0c\u56fe\u4e2d\u6709 n \u4e2a\u8282\u70b9\uff0c\u7f16\u53f7\u4ece 0 \u5230 n - 1 \u3002\u4f60\u51b3\u5b9a\u5c06\u56fe\u4e2d\u7684\u6bcf\u6761\u8fb9\u7ec6\u5206\u4e3a\u4e00\u6761\u8282\u70b9\u94fe\uff0c\u6bcf\u6761\u8fb9\u4e4b\u95f4\u7684\u65b0\u8282\u70b9\u6570\u5404\u4e0d\u76f8\u540c\u3002

\n\n

\u56fe\u7528\u7531\u8fb9\u7ec4\u6210\u7684\u4e8c\u7ef4\u6570\u7ec4 edges \u8868\u793a\uff0c\u5176\u4e2d\u00a0edges[i] = [ui, vi, cnti] \u8868\u793a\u539f\u59cb\u56fe\u4e2d\u8282\u70b9\u00a0ui \u548c\u00a0vi \u4e4b\u95f4\u5b58\u5728\u4e00\u6761\u8fb9\uff0ccnti \u662f\u5c06\u8fb9\u7ec6\u5206\u540e\u7684\u65b0\u8282\u70b9\u603b\u6570\u3002\u6ce8\u610f\uff0ccnti == 0 \u8868\u793a\u8fb9\u4e0d\u53ef\u7ec6\u5206\u3002

\n\n

\u8981\u7ec6\u5206\u8fb9 [ui, vi] \uff0c\u9700\u8981\u5c06\u5176\u66ff\u6362\u4e3a (cnti + 1) \u6761\u65b0\u8fb9\uff0c\u548c\u00a0cnti \u4e2a\u65b0\u8282\u70b9\u3002\u65b0\u8282\u70b9\u4e3a x1, x2, ..., xcnti \uff0c\u65b0\u8fb9\u4e3a [ui, x1], [x1, x2], [x2, x3], ..., [xcnti+1, xcnti], [xcnti, vi] \u3002

\n\n

\u73b0\u5728\u5f97\u5230\u4e00\u4e2a\u65b0\u7684 \u7ec6\u5206\u56fe \uff0c\u8bf7\u4f60\u8ba1\u7b97\u4ece\u8282\u70b9 0 \u51fa\u53d1\uff0c\u53ef\u4ee5\u5230\u8fbe\u591a\u5c11\u4e2a\u8282\u70b9\uff1f\u8282\u70b9 \u662f\u5426\u53ef\u4ee5\u5230\u8fbe\u7684\u5224\u65ad\u6761\u4ef6 \u4e3a\uff1a\u5982\u679c\u8282\u70b9\u95f4\u8ddd\u79bb\u662f maxMoves \u6216\u66f4\u5c11\uff0c\u5219\u89c6\u4e3a\u53ef\u4ee5\u5230\u8fbe\uff1b\u5426\u5219\uff0c\u4e0d\u53ef\u5230\u8fbe\u3002

\n\n

\u7ed9\u4f60\u539f\u59cb\u56fe\u548c maxMoves \uff0c\u8fd4\u56de\u65b0\u7684\u7ec6\u5206\u56fe\u4e2d\u4ece\u8282\u70b9 0 \u51fa\u53d1 \u53ef\u5230\u8fbe\u7684\u8282\u70b9\u6570 \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1aedges = [[0,1,10],[0,2,1],[1,2,2]], maxMoves = 6, n = 3\n\u8f93\u51fa\uff1a13\n\u89e3\u91ca\uff1a\u8fb9\u7684\u7ec6\u5206\u60c5\u51b5\u5982\u4e0a\u56fe\u6240\u793a\u3002\n\u53ef\u4ee5\u5230\u8fbe\u7684\u8282\u70b9\u5df2\u7ecf\u7528\u9ec4\u8272\u6807\u6ce8\u51fa\u6765\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aedges = [[0,1,4],[1,2,6],[0,2,8],[1,3,1]], maxMoves = 10, n = 4\n\u8f93\u51fa\uff1a23\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1aedges = [[1,2,4],[1,4,5],[1,3,1],[2,3,4],[3,4,5]], maxMoves = 17, n = 5\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u8282\u70b9 0 \u4e0e\u56fe\u7684\u5176\u4f59\u90e8\u5206\u6ca1\u6709\u8fde\u901a\uff0c\u6240\u4ee5\u53ea\u6709\u8282\u70b9 0 \u53ef\u4ee5\u5230\u8fbe\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 0 <= edges.length <= min(n * (n - 1) / 2, 104)
  • \n\t
  • edges[i].length == 3
  • \n\t
  • 0 <= ui < vi < n
  • \n\t
  • \u56fe\u4e2d \u4e0d\u5b58\u5728\u5e73\u884c\u8fb9
  • \n\t
  • 0 <= cnti <= 104
  • \n\t
  • 0 <= maxMoves <= 109
  • \n\t
  • 1 <= n <= 3000
  • \n
\n", "tags_en": ["Heap", "Breadth-first Search"], "tags_cn": ["\u5806", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int reachableNodes(vector>& edges, int maxMoves, int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int reachableNodes(int[][] edges, int maxMoves, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def reachableNodes(self, edges, maxMoves, n):\n \"\"\"\n :type edges: List[List[int]]\n :type maxMoves: int\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def reachableNodes(self, edges: List[List[int]], maxMoves: int, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint reachableNodes(int** edges, int edgesSize, int* edgesColSize, int maxMoves, int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ReachableNodes(int[][] edges, int maxMoves, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} edges\n * @param {number} maxMoves\n * @param {number} n\n * @return {number}\n */\nvar reachableNodes = function(edges, maxMoves, n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} edges\n# @param {Integer} max_moves\n# @param {Integer} n\n# @return {Integer}\ndef reachable_nodes(edges, max_moves, n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func reachableNodes(_ edges: [[Int]], _ maxMoves: Int, _ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func reachableNodes(edges [][]int, maxMoves int, n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def reachableNodes(edges: Array[Array[Int]], maxMoves: Int, n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun reachableNodes(edges: Array, maxMoves: Int, n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn reachable_nodes(edges: Vec>, max_moves: i32, n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $edges\n * @param Integer $maxMoves\n * @param Integer $n\n * @return Integer\n */\n function reachableNodes($edges, $maxMoves, $n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function reachableNodes(edges: number[][], maxMoves: number, n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (reachable-nodes edges maxMoves n)\n (-> (listof (listof exact-integer?)) exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0882](https://leetcode-cn.com/problems/reachable-nodes-in-subdivided-graph)", "[\u7ec6\u5206\u56fe\u4e2d\u7684\u53ef\u5230\u8fbe\u7ed3\u70b9](/solution/0800-0899/0882.Reachable%20Nodes%20In%20Subdivided%20Graph/README.md)", "`\u5806`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[0882](https://leetcode.com/problems/reachable-nodes-in-subdivided-graph)", "[Reachable Nodes In Subdivided Graph](/solution/0800-0899/0882.Reachable%20Nodes%20In%20Subdivided%20Graph/README_EN.md)", "`Heap`,`Breadth-first Search`", "Hard", ""]}, {"question_id": "0917", "frontend_question_id": "0881", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/boats-to-save-people", "url_en": "https://leetcode.com/problems/boats-to-save-people", "relative_path_cn": "/solution/0800-0899/0881.Boats%20to%20Save%20People/README.md", "relative_path_en": "/solution/0800-0899/0881.Boats%20to%20Save%20People/README_EN.md", "title_cn": "\u6551\u751f\u8247", "title_en": "Boats to Save People", "question_title_slug": "boats-to-save-people", "content_en": "

You are given an array people where people[i] is the weight of the ith person, and an infinite number of boats where each boat can carry a maximum weight of limit. Each boat carries at most two people at the same time, provided the sum of the weight of those people is at most limit.

\n\n

Return the minimum number of boats to carry every given person.

\n\n

 

\n

Example 1:

\n\n
\nInput: people = [1,2], limit = 3\nOutput: 1\nExplanation: 1 boat (1, 2)\n
\n\n

Example 2:

\n\n
\nInput: people = [3,2,2,1], limit = 3\nOutput: 3\nExplanation: 3 boats (1, 2), (2) and (3)\n
\n\n

Example 3:

\n\n
\nInput: people = [3,5,3,4], limit = 5\nOutput: 4\nExplanation: 4 boats (3), (3), (4), (5)\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= people.length <= 5 * 104
  • \n\t
  • 1 <= people[i] <= limit <= 3 * 104
  • \n
\n", "content_cn": "

\u7b2c i \u4e2a\u4eba\u7684\u4f53\u91cd\u4e3a people[i]\uff0c\u6bcf\u8258\u8239\u53ef\u4ee5\u627f\u8f7d\u7684\u6700\u5927\u91cd\u91cf\u4e3a limit\u3002

\n\n

\u6bcf\u8258\u8239\u6700\u591a\u53ef\u540c\u65f6\u8f7d\u4e24\u4eba\uff0c\u4f46\u6761\u4ef6\u662f\u8fd9\u4e9b\u4eba\u7684\u91cd\u91cf\u4e4b\u548c\u6700\u591a\u4e3a limit\u3002

\n\n

\u8fd4\u56de\u8f7d\u5230\u6bcf\u4e00\u4e2a\u4eba\u6240\u9700\u7684\u6700\u5c0f\u8239\u6570\u3002(\u4fdd\u8bc1\u6bcf\u4e2a\u4eba\u90fd\u80fd\u88ab\u8239\u8f7d)\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1apeople = [1,2], limit = 3\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a1 \u8258\u8239\u8f7d (1, 2)\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1apeople = [3,2,2,1], limit = 3\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a3 \u8258\u8239\u5206\u522b\u8f7d (1, 2), (2) \u548c (3)\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1apeople = [3,5,3,4], limit = 5\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a4 \u8258\u8239\u5206\u522b\u8f7d (3), (3), (4), (5)
\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= people.length <= 50000
  • \n\t
  • 1 <= people[i] <= limit <= 30000
  • \n
\n", "tags_en": ["Greedy", "Two Pointers"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numRescueBoats(vector& people, int limit) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numRescueBoats(int[] people, int limit) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numRescueBoats(self, people, limit):\n \"\"\"\n :type people: List[int]\n :type limit: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numRescueBoats(self, people: List[int], limit: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numRescueBoats(int* people, int peopleSize, int limit){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumRescueBoats(int[] people, int limit) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} people\n * @param {number} limit\n * @return {number}\n */\nvar numRescueBoats = function(people, limit) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} people\n# @param {Integer} limit\n# @return {Integer}\ndef num_rescue_boats(people, limit)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numRescueBoats(_ people: [Int], _ limit: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numRescueBoats(people []int, limit int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numRescueBoats(people: Array[Int], limit: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numRescueBoats(people: IntArray, limit: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_rescue_boats(people: Vec, limit: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $people\n * @param Integer $limit\n * @return Integer\n */\n function numRescueBoats($people, $limit) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numRescueBoats(people: number[], limit: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-rescue-boats people limit)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0881](https://leetcode-cn.com/problems/boats-to-save-people)", "[\u6551\u751f\u8247](/solution/0800-0899/0881.Boats%20to%20Save%20People/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0881](https://leetcode.com/problems/boats-to-save-people)", "[Boats to Save People](/solution/0800-0899/0881.Boats%20to%20Save%20People/README_EN.md)", "`Greedy`,`Two Pointers`", "Medium", ""]}, {"question_id": "0916", "frontend_question_id": "0880", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/decoded-string-at-index", "url_en": "https://leetcode.com/problems/decoded-string-at-index", "relative_path_cn": "/solution/0800-0899/0880.Decoded%20String%20at%20Index/README.md", "relative_path_en": "/solution/0800-0899/0880.Decoded%20String%20at%20Index/README_EN.md", "title_cn": "\u7d22\u5f15\u5904\u7684\u89e3\u7801\u5b57\u7b26\u4e32", "title_en": "Decoded String at Index", "question_title_slug": "decoded-string-at-index", "content_en": "

An encoded string s is given.  To find and write the decoded string to a tape, the encoded string is read one character at a time and the following steps are taken:

\n\n
    \n\t
  • If the character read is a letter, that letter is written onto the tape.
  • \n\t
  • If the character read is a digit (say d), the entire current tape is repeatedly written d-1 more times in total.
  • \n
\n\n

Now for some encoded string s, and an index k, find and return the k-th letter (1 indexed) in the decoded string.

\n\n

 

\n\n
\n

Example 1:

\n\n
\nInput: s = "leet2code3", k = 10\nOutput: "o"\nExplanation: \nThe decoded string is "leetleetcodeleetleetcodeleetleetcode".\nThe 10th letter in the string is "o".\n
\n\n
\n

Example 2:

\n\n
\nInput: s = "ha22", k = 5\nOutput: "h"\nExplanation: \nThe decoded string is "hahahaha".  The 5th letter is "h".\n
\n\n
\n

Example 3:

\n\n
\nInput: s = "a2345678999999999999999", k = 1\nOutput: "a"\nExplanation: \nThe decoded string is "a" repeated 8301530446056247680 times.  The 1st letter is "a".\n
\n
\n
\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= s.length <= 100
  • \n\t
  • s will only contain lowercase letters and digits 2 through 9.
  • \n\t
  • s starts with a letter.
  • \n\t
  • 1 <= k <= 109
  • \n\t
  • It's guaranteed that k is less than or equal to the length of the decoded string.
  • \n\t
  • The decoded string is guaranteed to have less than 263 letters.
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u7f16\u7801\u5b57\u7b26\u4e32 S\u3002\u8bf7\u4f60\u627e\u51fa \u89e3\u7801\u5b57\u7b26\u4e32 \u5e76\u5c06\u5176\u5199\u5165\u78c1\u5e26\u3002\u89e3\u7801\u65f6\uff0c\u4ece\u7f16\u7801\u5b57\u7b26\u4e32\u4e2d \u6bcf\u6b21\u8bfb\u53d6\u4e00\u4e2a\u5b57\u7b26 \uff0c\u5e76\u91c7\u53d6\u4ee5\u4e0b\u6b65\u9aa4\uff1a

\n\n
    \n\t
  • \u5982\u679c\u6240\u8bfb\u7684\u5b57\u7b26\u662f\u5b57\u6bcd\uff0c\u5219\u5c06\u8be5\u5b57\u6bcd\u5199\u5728\u78c1\u5e26\u4e0a\u3002
  • \n\t
  • \u5982\u679c\u6240\u8bfb\u7684\u5b57\u7b26\u662f\u6570\u5b57\uff08\u4f8b\u5982 d\uff09\uff0c\u5219\u6574\u4e2a\u5f53\u524d\u78c1\u5e26\u603b\u5171\u4f1a\u88ab\u91cd\u590d\u5199 d-1 \u6b21\u3002
  • \n
\n\n

\u73b0\u5728\uff0c\u5bf9\u4e8e\u7ed9\u5b9a\u7684\u7f16\u7801\u5b57\u7b26\u4e32 S \u548c\u7d22\u5f15 K\uff0c\u67e5\u627e\u5e76\u8fd4\u56de\u89e3\u7801\u5b57\u7b26\u4e32\u4e2d\u7684\u7b2c K \u4e2a\u5b57\u6bcd\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aS = "leet2code3", K = 10\n\u8f93\u51fa\uff1a"o"\n\u89e3\u91ca\uff1a\n\u89e3\u7801\u540e\u7684\u5b57\u7b26\u4e32\u4e3a "leetleetcodeleetleetcodeleetleetcode"\u3002\n\u5b57\u7b26\u4e32\u4e2d\u7684\u7b2c 10 \u4e2a\u5b57\u6bcd\u662f "o"\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aS = "ha22", K = 5\n\u8f93\u51fa\uff1a"h"\n\u89e3\u91ca\uff1a\n\u89e3\u7801\u540e\u7684\u5b57\u7b26\u4e32\u4e3a "hahahaha"\u3002\u7b2c 5 \u4e2a\u5b57\u6bcd\u662f "h"\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aS = "a2345678999999999999999", K = 1\n\u8f93\u51fa\uff1a"a"\n\u89e3\u91ca\uff1a\n\u89e3\u7801\u540e\u7684\u5b57\u7b26\u4e32\u4e3a "a" \u91cd\u590d 8301530446056247680 \u6b21\u3002\u7b2c 1 \u4e2a\u5b57\u6bcd\u662f "a"\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= S.length <= 100
  • \n\t
  • S \u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd\u4e0e\u6570\u5b57 2 \u5230 9 \u3002
  • \n\t
  • S \u4ee5\u5b57\u6bcd\u5f00\u5934\u3002
  • \n\t
  • 1 <= K <= 10^9
  • \n\t
  • \u9898\u76ee\u4fdd\u8bc1 K \u5c0f\u4e8e\u6216\u7b49\u4e8e\u89e3\u7801\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u3002
  • \n\t
  • \u89e3\u7801\u540e\u7684\u5b57\u7b26\u4e32\u4fdd\u8bc1\u5c11\u4e8e 2^63 \u4e2a\u5b57\u6bcd\u3002
  • \n
\n", "tags_en": ["Stack"], "tags_cn": ["\u6808"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string decodeAtIndex(string s, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String decodeAtIndex(String s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def decodeAtIndex(self, s, k):\n \"\"\"\n :type s: str\n :type k: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def decodeAtIndex(self, s: str, k: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * decodeAtIndex(char * s, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string DecodeAtIndex(string s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number} k\n * @return {string}\n */\nvar decodeAtIndex = function(s, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer} k\n# @return {String}\ndef decode_at_index(s, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func decodeAtIndex(_ s: String, _ k: Int) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func decodeAtIndex(s string, k int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def decodeAtIndex(s: String, k: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun decodeAtIndex(s: String, k: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn decode_at_index(s: String, k: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer $k\n * @return String\n */\n function decodeAtIndex($s, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function decodeAtIndex(s: string, k: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (decode-at-index s k)\n (-> string? exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0880](https://leetcode-cn.com/problems/decoded-string-at-index)", "[\u7d22\u5f15\u5904\u7684\u89e3\u7801\u5b57\u7b26\u4e32](/solution/0800-0899/0880.Decoded%20String%20at%20Index/README.md)", "`\u6808`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0880](https://leetcode.com/problems/decoded-string-at-index)", "[Decoded String at Index](/solution/0800-0899/0880.Decoded%20String%20at%20Index/README_EN.md)", "`Stack`", "Medium", ""]}, {"question_id": "0915", "frontend_question_id": "0478", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/generate-random-point-in-a-circle", "url_en": "https://leetcode.com/problems/generate-random-point-in-a-circle", "relative_path_cn": "/solution/0400-0499/0478.Generate%20Random%20Point%20in%20a%20Circle/README.md", "relative_path_en": "/solution/0400-0499/0478.Generate%20Random%20Point%20in%20a%20Circle/README_EN.md", "title_cn": "\u5728\u5706\u5185\u968f\u673a\u751f\u6210\u70b9", "title_en": "Generate Random Point in a Circle", "question_title_slug": "generate-random-point-in-a-circle", "content_en": "

Given the radius and the position of the center of a circle, implement the function randPoint which generates a uniform random point inside the circle.

\n\n

Implement the Solution class:

\n\n
    \n\t
  • Solution(double radius, double x_center, double y_center) initializes the object with the radius of the circle radius and the position of the center (x_center, y_center).
  • \n\t
  • randPoint() returns a random point inside the circle. A point on the circumference of the circle is considered to be in the circle. The answer is returned as an array [x, y].
  • \n
\n\n

 

\n

Example 1:

\n\n
\nInput\n["Solution", "randPoint", "randPoint", "randPoint"]\n[[1.0, 0.0, 0.0], [], [], []]\nOutput\n[null, [-0.02493, -0.38077], [0.82314, 0.38945], [0.36572, 0.17248]]\n\nExplanation\nSolution solution = new Solution(1.0, 0.0, 0.0);\nsolution.randPoint(); // return [-0.02493, -0.38077]\nsolution.randPoint(); // return [0.82314, 0.38945]\nsolution.randPoint(); // return [0.36572, 0.17248]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 0 < radius <= 108
  • \n\t
  • -107 <= x_center, y_center <= 107
  • \n\t
  • At most 3 * 104 calls will be made to randPoint.
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u5706\u7684\u534a\u5f84\u548c\u5706\u5fc3\u7684 x\u3001y \u5750\u6807\uff0c\u5199\u4e00\u4e2a\u5728\u5706\u4e2d\u4ea7\u751f\u5747\u5300\u968f\u673a\u70b9\u7684\u51fd\u6570 randPoint \u3002

\n\n

\u8bf4\u660e:

\n\n
    \n\t
  1. \u8f93\u5165\u503c\u548c\u8f93\u51fa\u503c\u90fd\u5c06\u662f\u6d6e\u70b9\u6570\u3002
  2. \n\t
  3. \u5706\u7684\u534a\u5f84\u548c\u5706\u5fc3\u7684 x\u3001y \u5750\u6807\u5c06\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u7ed9\u7c7b\u7684\u6784\u9020\u51fd\u6570\u3002
  4. \n\t
  5. \u5706\u5468\u4e0a\u7684\u70b9\u4e5f\u8ba4\u4e3a\u662f\u5728\u5706\u4e2d\u3002
  6. \n\t
  7. randPoint \u8fd4\u56de\u4e00\u4e2a\u5305\u542b\u968f\u673a\u70b9\u7684x\u5750\u6807\u548cy\u5750\u6807\u7684\u5927\u5c0f\u4e3a2\u7684\u6570\u7ec4\u3002
  8. \n
\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165: \n["Solution","randPoint","randPoint","randPoint"]\n[[1,0,0],[],[],[]]\n\u8f93\u51fa: [null,[-0.72939,-0.65505],[-0.78502,-0.28626],[-0.83119,-0.19803]]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165: \n["Solution","randPoint","randPoint","randPoint"]\n[[10,5,-7.5],[],[],[]]\n\u8f93\u51fa: [null,[11.52438,-8.33273],[2.46992,-16.21705],[11.13430,-12.42337]]
\n\n

\u8f93\u5165\u8bed\u6cd5\u8bf4\u660e\uff1a

\n\n

\u8f93\u5165\u662f\u4e24\u4e2a\u5217\u8868\uff1a\u8c03\u7528\u6210\u5458\u51fd\u6570\u540d\u548c\u8c03\u7528\u7684\u53c2\u6570\u3002Solution \u7684\u6784\u9020\u51fd\u6570\u6709\u4e09\u4e2a\u53c2\u6570\uff0c\u5706\u7684\u534a\u5f84\u3001\u5706\u5fc3\u7684 x \u5750\u6807\u3001\u5706\u5fc3\u7684 y \u5750\u6807\u3002randPoint \u6ca1\u6709\u53c2\u6570\u3002\u8f93\u5165\u53c2\u6570\u662f\u4e00\u4e2a\u5217\u8868\uff0c\u5373\u4f7f\u53c2\u6570\u4e3a\u7a7a\uff0c\u4e5f\u4f1a\u8f93\u5165\u4e00\u4e2a [] \u7a7a\u5217\u8868\u3002

\n", "tags_en": ["Math", "Random", "Rejection Sampling"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n Solution(double radius, double x_center, double y_center) {\n\n }\n \n vector randPoint() {\n\n }\n};\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution* obj = new Solution(radius, x_center, y_center);\n * vector param_1 = obj->randPoint();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n\n public Solution(double radius, double x_center, double y_center) {\n\n }\n \n public double[] randPoint() {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution obj = new Solution(radius, x_center, y_center);\n * double[] param_1 = obj.randPoint();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n\n def __init__(self, radius, x_center, y_center):\n \"\"\"\n :type radius: float\n :type x_center: float\n :type y_center: float\n \"\"\"\n\n\n def randPoint(self):\n \"\"\"\n :rtype: List[float]\n \"\"\"\n\n\n\n# Your Solution object will be instantiated and called as such:\n# obj = Solution(radius, x_center, y_center)\n# param_1 = obj.randPoint()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n\n def __init__(self, radius: float, x_center: float, y_center: float):\n\n\n def randPoint(self) -> List[float]:\n\n\n\n# Your Solution object will be instantiated and called as such:\n# obj = Solution(radius, x_center, y_center)\n# param_1 = obj.randPoint()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} Solution;\n\n\nSolution* solutionCreate(double radius, double x_center, double y_center) {\n\n}\n\ndouble* solutionRandPoint(Solution* obj, int* retSize) {\n\n}\n\nvoid solutionFree(Solution* obj) {\n\n}\n\n/**\n * Your Solution struct will be instantiated and called as such:\n * Solution* obj = solutionCreate(radius, x_center, y_center);\n * double* param_1 = solutionRandPoint(obj, retSize);\n \n * solutionFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n\n public Solution(double radius, double x_center, double y_center) {\n\n }\n \n public double[] RandPoint() {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution obj = new Solution(radius, x_center, y_center);\n * double[] param_1 = obj.RandPoint();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} radius\n * @param {number} x_center\n * @param {number} y_center\n */\nvar Solution = function(radius, x_center, y_center) {\n\n};\n\n/**\n * @return {number[]}\n */\nSolution.prototype.randPoint = function() {\n\n};\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = new Solution(radius, x_center, y_center)\n * var param_1 = obj.randPoint()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class Solution\n\n=begin\n :type radius: Float\n :type x_center: Float\n :type y_center: Float\n=end\n def initialize(radius, x_center, y_center)\n\n end\n\n\n=begin\n :rtype: Float[]\n=end\n def rand_point()\n\n end\n\n\nend\n\n# Your Solution object will be instantiated and called as such:\n# obj = Solution.new(radius, x_center, y_center)\n# param_1 = obj.rand_point()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass Solution {\n\n init(_ radius: Double, _ x_center: Double, _ y_center: Double) {\n\n }\n \n func randPoint() -> [Double] {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * let obj = Solution(radius, x_center, y_center)\n * let ret_1: [Double] = obj.randPoint()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type Solution struct {\n\n}\n\n\nfunc Constructor(radius float64, x_center float64, y_center float64) Solution {\n\n}\n\n\nfunc (this *Solution) RandPoint() []float64 {\n\n}\n\n\n/**\n * Your Solution object will be instantiated and called as such:\n * obj := Constructor(radius, x_center, y_center);\n * param_1 := obj.RandPoint();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class Solution(_radius: Double, _x_center: Double, _y_center: Double) {\n\n def randPoint(): Array[Double] = {\n\n }\n\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = new Solution(radius, x_center, y_center)\n * var param_1 = obj.randPoint()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution(radius: Double, x_center: Double, y_center: Double) {\n\n fun randPoint(): DoubleArray {\n\n }\n\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = Solution(radius, x_center, y_center)\n * var param_1 = obj.randPoint()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct Solution {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl Solution {\n\n fn new(radius: f64, x_center: f64, y_center: f64) -> Self {\n\n }\n \n fn rand_point(&self) -> Vec {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * let obj = Solution::new(radius, x_center, y_center);\n * let ret_1: Vec = obj.rand_point();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n /**\n * @param Float $radius\n * @param Float $x_center\n * @param Float $y_center\n */\n function __construct($radius, $x_center, $y_center) {\n\n }\n\n /**\n * @return Float[]\n */\n function randPoint() {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * $obj = Solution($radius, $x_center, $y_center);\n * $ret_1 = $obj->randPoint();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class Solution {\n constructor(radius: number, x_center: number, y_center: number) {\n\n }\n\n randPoint(): number[] {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = new Solution(radius, x_center, y_center)\n * var param_1 = obj.randPoint()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define solution%\n (class object%\n (super-new)\n\n ; radius : flonum?\n\n ; x_center : flonum?\n\n ; y_center : flonum?\n (init-field\n radius\n x_center\n y_center)\n \n ; rand-point : -> (listof flonum?)\n (define/public (rand-point)\n\n )))\n\n;; Your solution% object will be instantiated and called as such:\n;; (define obj (new solution% [radius radius] [x_center x_center] [y_center y_center]))\n;; (define param_1 (send obj rand-point))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0478](https://leetcode-cn.com/problems/generate-random-point-in-a-circle)", "[\u5728\u5706\u5185\u968f\u673a\u751f\u6210\u70b9](/solution/0400-0499/0478.Generate%20Random%20Point%20in%20a%20Circle/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0478](https://leetcode.com/problems/generate-random-point-in-a-circle)", "[Generate Random Point in a Circle](/solution/0400-0499/0478.Generate%20Random%20Point%20in%20a%20Circle/README_EN.md)", "`Math`,`Random`,`Rejection Sampling`", "Medium", ""]}, {"question_id": "0914", "frontend_question_id": "0497", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/random-point-in-non-overlapping-rectangles", "url_en": "https://leetcode.com/problems/random-point-in-non-overlapping-rectangles", "relative_path_cn": "/solution/0400-0499/0497.Random%20Point%20in%20Non-overlapping%20Rectangles/README.md", "relative_path_en": "/solution/0400-0499/0497.Random%20Point%20in%20Non-overlapping%20Rectangles/README_EN.md", "title_cn": "\u975e\u91cd\u53e0\u77e9\u5f62\u4e2d\u7684\u968f\u673a\u70b9", "title_en": "Random Point in Non-overlapping Rectangles", "question_title_slug": "random-point-in-non-overlapping-rectangles", "content_en": "

Given a list of non-overlapping axis-aligned rectangles rects, write a function pick which randomly and uniformily picks an integer point in the space covered by the rectangles.

\r\n\r\n

Note:

\r\n\r\n
    \r\n\t
  1. An integer point is a point that has integer coordinates. 
  2. \r\n\t
  3. A point on the perimeter of a rectangle is included in the space covered by the rectangles. 
  4. \r\n\t
  5. ith rectangle = rects[i][x1,y1,x2,y2], where [x1, y1] are the integer coordinates of the bottom-left corner, and [x2, y2] are the integer coordinates of the top-right corner.
  6. \r\n\t
  7. length and width of each rectangle does not exceed 2000.
  8. \r\n\t
  9. 1 <= rects.length <= 100
  10. \r\n\t
  11. pick return a point as an array of integer coordinates [p_x, p_y]
  12. \r\n\t
  13. pick is called at most 10000 times.
  14. \r\n
\r\n\r\n
\r\n

Example 1:

\r\n\r\n
\r\nInput: \r\n["Solution","pick","pick","pick"]\r\n[[[[1,1,5,5]]],[],[],[]]\r\nOutput: \r\n[null,[4,1],[4,1],[3,3]]\r\n
\r\n\r\n
\r\n

Example 2:

\r\n\r\n
\r\nInput: \r\n["Solution","pick","pick","pick","pick","pick"]\r\n[[[[-2,-2,-1,-1],[1,0,3,0]]],[],[],[],[],[]]\r\nOutput: \r\n[null,[-1,-2],[2,0],[-2,-1],[3,0],[-2,-2]]
\r\n
\r\n\r\n
\r\n

Explanation of Input Syntax:

\r\n\r\n

The input is two lists: the subroutines called and their arguments. Solution's constructor has one argument, the array of rectangles rects. pick has no arguments. Arguments are always wrapped with a list, even if there aren't any.

\r\n
\r\n
\r\n\r\n
\r\n
 
\r\n
\r\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u975e\u91cd\u53e0\u8f74\u5bf9\u9f50\u77e9\u5f62\u7684\u5217\u8868 rects\uff0c\u5199\u4e00\u4e2a\u51fd\u6570 pick \u968f\u673a\u5747\u5300\u5730\u9009\u53d6\u77e9\u5f62\u8986\u76d6\u7684\u7a7a\u95f4\u4e2d\u7684\u6574\u6570\u70b9\u3002

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. \u6574\u6570\u70b9\u662f\u5177\u6709\u6574\u6570\u5750\u6807\u7684\u70b9\u3002
  2. \n\t
  3. \u77e9\u5f62\u5468\u8fb9\u4e0a\u7684\u70b9\u5305\u542b\u5728\u77e9\u5f62\u8986\u76d6\u7684\u7a7a\u95f4\u4e2d\u3002
  4. \n\t
  5. \u7b2c i \u4e2a\u77e9\u5f62 rects [i] = [x1\uff0cy1\uff0cx2\uff0cy2]\uff0c\u5176\u4e2d [x1\uff0cy1] \u662f\u5de6\u4e0b\u89d2\u7684\u6574\u6570\u5750\u6807\uff0c[x2\uff0cy2] \u662f\u53f3\u4e0a\u89d2\u7684\u6574\u6570\u5750\u6807\u3002
  6. \n\t
  7. \u6bcf\u4e2a\u77e9\u5f62\u7684\u957f\u5ea6\u548c\u5bbd\u5ea6\u4e0d\u8d85\u8fc7 2000\u3002
  8. \n\t
  9. 1 <= rects.length <= 100
  10. \n\t
  11. pick \u4ee5\u6574\u6570\u5750\u6807\u6570\u7ec4 [p_x, p_y] \u7684\u5f62\u5f0f\u8fd4\u56de\u4e00\u4e2a\u70b9\u3002
  12. \n\t
  13. pick \u6700\u591a\u88ab\u8c03\u752810000\u6b21\u3002
  14. \n
\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165: \n["Solution","pick","pick","pick"]\n[[[[1,1,5,5]]],[],[],[]]\n\u8f93\u51fa: \n[null,[4,1],[4,1],[3,3]]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165: \n["Solution","pick","pick","pick","pick","pick"]\n[[[[-2,-2,-1,-1],[1,0,3,0]]],[],[],[],[],[]]\n\u8f93\u51fa: \n[null,[-1,-2],[2,0],[-2,-1],[3,0],[-2,-2]]
\n\n

 

\n\n

\u8f93\u5165\u8bed\u6cd5\u7684\u8bf4\u660e\uff1a

\n\n

\u8f93\u5165\u662f\u4e24\u4e2a\u5217\u8868\uff1a\u8c03\u7528\u7684\u5b50\u4f8b\u7a0b\u53ca\u5176\u53c2\u6570\u3002Solution \u7684\u6784\u9020\u51fd\u6570\u6709\u4e00\u4e2a\u53c2\u6570\uff0c\u5373\u77e9\u5f62\u6570\u7ec4 rects\u3002pick \u6ca1\u6709\u53c2\u6570\u3002\u53c2\u6570\u603b\u662f\u7528\u5217\u8868\u5305\u88c5\u7684\uff0c\u5373\u4f7f\u6ca1\u6709\u4e5f\u662f\u5982\u6b64\u3002

\n\n

 

\n", "tags_en": ["Binary Search", "Random"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n Solution(vector>& rects) {\n\n }\n \n vector pick() {\n\n }\n};\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution* obj = new Solution(rects);\n * vector param_1 = obj->pick();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n\n public Solution(int[][] rects) {\n\n }\n \n public int[] pick() {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution obj = new Solution(rects);\n * int[] param_1 = obj.pick();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n\n def __init__(self, rects):\n \"\"\"\n :type rects: List[List[int]]\n \"\"\"\n \n\n def pick(self):\n \"\"\"\n :rtype: List[int]\n \"\"\"\n \n\n\n# Your Solution object will be instantiated and called as such:\n# obj = Solution(rects)\n# param_1 = obj.pick()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n\n def __init__(self, rects: List[List[int]]):\n \n\n def pick(self) -> List[int]:\n \n\n\n# Your Solution object will be instantiated and called as such:\n# obj = Solution(rects)\n# param_1 = obj.pick()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} Solution;\n\n\nSolution* solutionCreate(int** rects, int rectsSize, int* rectsColSize) {\n \n}\n\nint* solutionPick(Solution* obj, int* retSize) {\n \n}\n\nvoid solutionFree(Solution* obj) {\n \n}\n\n/**\n * Your Solution struct will be instantiated and called as such:\n * Solution* obj = solutionCreate(rects, rectsSize, rectsColSize);\n * int* param_1 = solutionPick(obj, retSize);\n \n * solutionFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n\n public Solution(int[][] rects) {\n\n }\n \n public int[] Pick() {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution obj = new Solution(rects);\n * int[] param_1 = obj.Pick();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} rects\n */\nvar Solution = function(rects) {\n\n};\n\n/**\n * @return {number[]}\n */\nSolution.prototype.pick = function() {\n\n};\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = new Solution(rects)\n * var param_1 = obj.pick()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class Solution\n\n=begin\n :type rects: Integer[][]\n=end\n def initialize(rects)\n\n end\n\n\n=begin\n :rtype: Integer[]\n=end\n def pick()\n\n end\n\n\nend\n\n# Your Solution object will be instantiated and called as such:\n# obj = Solution.new(rects)\n# param_1 = obj.pick()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass Solution {\n\n init(_ rects: [[Int]]) {\n \n }\n \n func pick() -> [Int] {\n \n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * let obj = Solution(rects)\n * let ret_1: [Int] = obj.pick()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type Solution struct {\n\n}\n\n\nfunc Constructor(rects [][]int) Solution {\n\n}\n\n\nfunc (this *Solution) Pick() []int {\n\n}\n\n\n/**\n * Your Solution object will be instantiated and called as such:\n * obj := Constructor(rects);\n * param_1 := obj.Pick();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class Solution(_rects: Array[Array[Int]]) {\n\n def pick(): Array[Int] = {\n\n }\n\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = new Solution(rects)\n * var param_1 = obj.pick()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution(rects: Array) {\n\n fun pick(): IntArray {\n\n }\n\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = Solution(rects)\n * var param_1 = obj.pick()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct Solution {\n\n}\n\n\n/** \n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl Solution {\n\n fn new(rects: Vec>) -> Self {\n \n }\n \n fn pick(&self) -> Vec {\n \n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * let obj = Solution::new(rects);\n * let ret_1: Vec = obj.pick();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n /**\n * @param Integer[][] $rects\n */\n function __construct($rects) {\n \n }\n \n /**\n * @return Integer[]\n */\n function pick() {\n \n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * $obj = Solution($rects);\n * $ret_1 = $obj->pick();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class Solution {\n constructor(rects: number[][]) {\n\n }\n\n pick(): number[] {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = new Solution(rects)\n * var param_1 = obj.pick()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define solution%\n (class object%\n (super-new)\n\n ; rects : (listof (listof exact-integer?))\n (init-field\n rects)\n \n ; pick : -> (listof exact-integer?)\n (define/public (pick)\n\n )))\n\n;; Your solution% object will be instantiated and called as such:\n;; (define obj (new solution% [rects rects]))\n;; (define param_1 (send obj pick))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0497](https://leetcode-cn.com/problems/random-point-in-non-overlapping-rectangles)", "[\u975e\u91cd\u53e0\u77e9\u5f62\u4e2d\u7684\u968f\u673a\u70b9](/solution/0400-0499/0497.Random%20Point%20in%20Non-overlapping%20Rectangles/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0497](https://leetcode.com/problems/random-point-in-non-overlapping-rectangles)", "[Random Point in Non-overlapping Rectangles](/solution/0400-0499/0497.Random%20Point%20in%20Non-overlapping%20Rectangles/README_EN.md)", "`Binary Search`,`Random`", "Medium", ""]}, {"question_id": "0913", "frontend_question_id": "0519", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/random-flip-matrix", "url_en": "https://leetcode.com/problems/random-flip-matrix", "relative_path_cn": "/solution/0500-0599/0519.Random%20Flip%20Matrix/README.md", "relative_path_en": "/solution/0500-0599/0519.Random%20Flip%20Matrix/README_EN.md", "title_cn": "\u968f\u673a\u7ffb\u8f6c\u77e9\u9635", "title_en": "Random Flip Matrix", "question_title_slug": "random-flip-matrix", "content_en": "

You are given the number of rows n_rows and number of columns n_cols of a 2D binary matrix where all values are initially 0. Write a function flip which chooses a 0 value uniformly at random, changes it to 1, and then returns the position [row.id, col.id] of that value. Also, write a function reset which sets all values back to 0. Try to minimize the number of calls to system's Math.random() and optimize the time and space complexity.

\r\n\r\n

Note:

\r\n\r\n
    \r\n\t
  1. 1 <= n_rows, n_cols <= 10000
  2. \r\n\t
  3. 0 <= row.id < n_rows and 0 <= col.id < n_cols
  4. \r\n\t
  5. flip will not be called when the matrix has no 0 values left.
  6. \r\n\t
  7. the total number of calls to flip and reset will not exceed 1000.
  8. \r\n
\r\n\r\n

Example 1:

\r\n\r\n
\r\nInput: \r\n["Solution","flip","flip","flip","flip"]\r\n[[2,3],[],[],[],[]]\r\nOutput: [null,[0,1],[1,2],[1,0],[1,1]]\r\n
\r\n\r\n
\r\n

Example 2:

\r\n\r\n
\r\nInput: \r\n["Solution","flip","flip","reset","flip"]\r\n[[1,2],[],[],[],[]]\r\nOutput: [null,[0,0],[0,1],null,[0,0]]
\r\n
\r\n\r\n

Explanation of Input Syntax:

\r\n\r\n

The input is two lists: the subroutines called and their arguments. Solution's constructor has two arguments, n_rows and n_colsflip and reset have no arguments. Arguments are always wrapped with a list, even if there aren't any.

\r\n", "content_cn": "

\u9898\u4e2d\u7ed9\u51fa\u4e00\u4e2a n_rows \u884c n_cols \u5217\u7684\u4e8c\u7ef4\u77e9\u9635\uff0c\u4e14\u6240\u6709\u503c\u88ab\u521d\u59cb\u5316\u4e3a 0\u3002\u8981\u6c42\u7f16\u5199\u4e00\u4e2a flip \u51fd\u6570\uff0c\u5747\u5300\u968f\u673a\u7684\u5c06\u77e9\u9635\u4e2d\u7684 0 \u53d8\u4e3a 1\uff0c\u5e76\u8fd4\u56de\u8be5\u503c\u7684\u4f4d\u7f6e\u4e0b\u6807 [row_id,col_id]\uff1b\u540c\u6837\u7f16\u5199\u4e00\u4e2a reset \u51fd\u6570\uff0c\u5c06\u6240\u6709\u7684\u503c\u90fd\u91cd\u65b0\u7f6e\u4e3a 0\u3002\u5c3d\u91cf\u6700\u5c11\u8c03\u7528\u968f\u673a\u51fd\u6570 Math.random()\uff0c\u5e76\u4e14\u4f18\u5316\u65f6\u95f4\u548c\u7a7a\u95f4\u590d\u6742\u5ea6\u3002

\n\n

\u6ce8\u610f:

\n\n
    \n\t
  1. 1 <= n_rows, n_cols <= 10000
  2. \n\t
  3. 0 <= row.id < n_rows \u5e76\u4e14 0 <= col.id < n_cols
  4. \n\t
  5. \u5f53\u77e9\u9635\u4e2d\u6ca1\u6709\u503c\u4e3a 0 \u65f6\uff0c\u4e0d\u53ef\u4ee5\u8c03\u7528 flip \u51fd\u6570
  6. \n\t
  7. \u8c03\u7528 flip \u548c reset \u51fd\u6570\u7684\u6b21\u6570\u52a0\u8d77\u6765\u4e0d\u4f1a\u8d85\u8fc7 1000 \u6b21
  8. \n
\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165: \n["Solution","flip","flip","flip","flip"]\n[[2,3],[],[],[],[]]\n\u8f93\u51fa: [null,[0,1],[1,2],[1,0],[1,1]]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165: \n["Solution","flip","flip","reset","flip"]\n[[1,2],[],[],[],[]]\n\u8f93\u51fa: [null,[0,0],[0,1],null,[0,0]]
\n\n

\u8f93\u5165\u8bed\u6cd5\u89e3\u91ca\uff1a

\n\n

\u8f93\u5165\u5305\u542b\u4e24\u4e2a\u5217\u8868\uff1a\u88ab\u8c03\u7528\u7684\u5b50\u7a0b\u5e8f\u548c\u4ed6\u4eec\u7684\u53c2\u6570\u3002Solution \u7684\u6784\u9020\u51fd\u6570\u6709\u4e24\u4e2a\u53c2\u6570\uff0c\u5206\u522b\u4e3a n_rows \u548c n_cols\u3002flip \u548c reset \u6ca1\u6709\u53c2\u6570\uff0c\u53c2\u6570\u603b\u4f1a\u4ee5\u5217\u8868\u5f62\u5f0f\u7ed9\u51fa\uff0c\u54ea\u6015\u8be5\u5217\u8868\u4e3a\u7a7a

\n", "tags_en": ["Random"], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n Solution(int n_rows, int n_cols) {\n\n }\n \n vector flip() {\n\n }\n \n void reset() {\n\n }\n};\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution* obj = new Solution(n_rows, n_cols);\n * vector param_1 = obj->flip();\n * obj->reset();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n\n public Solution(int n_rows, int n_cols) {\n\n }\n \n public int[] flip() {\n\n }\n \n public void reset() {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution obj = new Solution(n_rows, n_cols);\n * int[] param_1 = obj.flip();\n * obj.reset();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n\n def __init__(self, n_rows, n_cols):\n \"\"\"\n :type n_rows: int\n :type n_cols: int\n \"\"\"\n\n\n def flip(self):\n \"\"\"\n :rtype: List[int]\n \"\"\"\n\n\n def reset(self):\n \"\"\"\n :rtype: None\n \"\"\"\n\n\n\n# Your Solution object will be instantiated and called as such:\n# obj = Solution(n_rows, n_cols)\n# param_1 = obj.flip()\n# obj.reset()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n\n def __init__(self, n_rows: int, n_cols: int):\n\n\n def flip(self) -> List[int]:\n\n\n def reset(self) -> None:\n\n\n\n# Your Solution object will be instantiated and called as such:\n# obj = Solution(n_rows, n_cols)\n# param_1 = obj.flip()\n# obj.reset()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} Solution;\n\n\nSolution* solutionCreate(int n_rows, int n_cols) {\n\n}\n\nint* solutionFlip(Solution* obj, int* retSize) {\n\n}\n\nvoid solutionReset(Solution* obj) {\n\n}\n\nvoid solutionFree(Solution* obj) {\n\n}\n\n/**\n * Your Solution struct will be instantiated and called as such:\n * Solution* obj = solutionCreate(n_rows, n_cols);\n * int* param_1 = solutionFlip(obj, retSize);\n \n * solutionReset(obj);\n \n * solutionFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n\n public Solution(int n_rows, int n_cols) {\n\n }\n \n public int[] Flip() {\n\n }\n \n public void Reset() {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution obj = new Solution(n_rows, n_cols);\n * int[] param_1 = obj.Flip();\n * obj.Reset();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n_rows\n * @param {number} n_cols\n */\nvar Solution = function(n_rows, n_cols) {\n\n};\n\n/**\n * @return {number[]}\n */\nSolution.prototype.flip = function() {\n\n};\n\n/**\n * @return {void}\n */\nSolution.prototype.reset = function() {\n\n};\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = new Solution(n_rows, n_cols)\n * var param_1 = obj.flip()\n * obj.reset()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class Solution\n\n=begin\n :type n_rows: Integer\n :type n_cols: Integer\n=end\n def initialize(n_rows, n_cols)\n\n end\n\n\n=begin\n :rtype: Integer[]\n=end\n def flip()\n\n end\n\n\n=begin\n :rtype: Void\n=end\n def reset()\n\n end\n\n\nend\n\n# Your Solution object will be instantiated and called as such:\n# obj = Solution.new(n_rows, n_cols)\n# param_1 = obj.flip()\n# obj.reset()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass Solution {\n\n init(_ n_rows: Int, _ n_cols: Int) {\n\n }\n \n func flip() -> [Int] {\n\n }\n \n func reset() {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * let obj = Solution(n_rows, n_cols)\n * let ret_1: [Int] = obj.flip()\n * obj.reset()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type Solution struct {\n\n}\n\n\nfunc Constructor(n_rows int, n_cols int) Solution {\n\n}\n\n\nfunc (this *Solution) Flip() []int {\n\n}\n\n\nfunc (this *Solution) Reset() {\n\n}\n\n\n/**\n * Your Solution object will be instantiated and called as such:\n * obj := Constructor(n_rows, n_cols);\n * param_1 := obj.Flip();\n * obj.Reset();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class Solution(_n_rows: Int, _n_cols: Int) {\n\n def flip(): Array[Int] = {\n\n }\n\n def reset() {\n\n }\n\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = new Solution(n_rows, n_cols)\n * var param_1 = obj.flip()\n * obj.reset()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution(n_rows: Int, n_cols: Int) {\n\n fun flip(): IntArray {\n\n }\n\n fun reset() {\n\n }\n\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = Solution(n_rows, n_cols)\n * var param_1 = obj.flip()\n * obj.reset()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct Solution {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl Solution {\n\n fn new(n_rows: i32, n_cols: i32) -> Self {\n\n }\n \n fn flip(&self) -> Vec {\n\n }\n \n fn reset(&self) {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * let obj = Solution::new(n_rows, n_cols);\n * let ret_1: Vec = obj.flip();\n * obj.reset();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n /**\n * @param Integer $n_rows\n * @param Integer $n_cols\n */\n function __construct($n_rows, $n_cols) {\n\n }\n\n /**\n * @return Integer[]\n */\n function flip() {\n\n }\n\n /**\n * @return NULL\n */\n function reset() {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * $obj = Solution($n_rows, $n_cols);\n * $ret_1 = $obj->flip();\n * $obj->reset();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class Solution {\n constructor(n_rows: number, n_cols: number) {\n\n }\n\n flip(): number[] {\n\n }\n\n reset(): void {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = new Solution(n_rows, n_cols)\n * var param_1 = obj.flip()\n * obj.reset()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define solution%\n (class object%\n (super-new)\n\n ; n_rows : exact-integer?\n\n ; n_cols : exact-integer?\n (init-field\n n_rows\n n_cols)\n \n ; flip : -> (listof exact-integer?)\n (define/public (flip)\n\n )\n ; reset : -> void?\n (define/public (reset)\n\n )))\n\n;; Your solution% object will be instantiated and called as such:\n;; (define obj (new solution% [n_rows n_rows] [n_cols n_cols]))\n;; (define param_1 (send obj flip))\n;; (send obj reset)", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0519](https://leetcode-cn.com/problems/random-flip-matrix)", "[\u968f\u673a\u7ffb\u8f6c\u77e9\u9635](/solution/0500-0599/0519.Random%20Flip%20Matrix/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0519](https://leetcode.com/problems/random-flip-matrix)", "[Random Flip Matrix](/solution/0500-0599/0519.Random%20Flip%20Matrix/README_EN.md)", "`Random`", "Medium", ""]}, {"question_id": "0912", "frontend_question_id": "0528", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/random-pick-with-weight", "url_en": "https://leetcode.com/problems/random-pick-with-weight", "relative_path_cn": "/solution/0500-0599/0528.Random%20Pick%20with%20Weight/README.md", "relative_path_en": "/solution/0500-0599/0528.Random%20Pick%20with%20Weight/README_EN.md", "title_cn": "\u6309\u6743\u91cd\u968f\u673a\u9009\u62e9", "title_en": "Random Pick with Weight", "question_title_slug": "random-pick-with-weight", "content_en": "

You are given an array of positive integers w where w[i] describes the weight of ith index (0-indexed).

\n\n

We need to call the function pickIndex() which randomly returns an integer in the range [0, w.length - 1]pickIndex() should return the integer proportional to its weight in the w array. For example, for w = [1, 3], the probability of picking the index 0 is 1 / (1 + 3) = 0.25 (i.e 25%) while the probability of picking the index 1 is 3 / (1 + 3) = 0.75 (i.e 75%).

\n\n

More formally, the probability of picking index i is w[i] / sum(w).

\n\n

 

\n

Example 1:

\n\n
\nInput\n["Solution","pickIndex"]\n[[[1]],[]]\nOutput\n[null,0]\n\nExplanation\nSolution solution = new Solution([1]);\nsolution.pickIndex(); // return 0. Since there is only one single element on the array the only option is to return the first element.\n
\n\n

Example 2:

\n\n
\nInput\n["Solution","pickIndex","pickIndex","pickIndex","pickIndex","pickIndex"]\n[[[1,3]],[],[],[],[],[]]\nOutput\n[null,1,1,1,1,0]\n\nExplanation\nSolution solution = new Solution([1, 3]);\nsolution.pickIndex(); // return 1. It's returning the second element (index = 1) that has probability of 3/4.\nsolution.pickIndex(); // return 1\nsolution.pickIndex(); // return 1\nsolution.pickIndex(); // return 1\nsolution.pickIndex(); // return 0. It's returning the first element (index = 0) that has probability of 1/4.\n\nSince this is a randomization problem, multiple answers are allowed so the following outputs can be considered correct :\n[null,1,1,1,1,0]\n[null,1,1,1,1,1]\n[null,1,1,1,0,0]\n[null,1,1,1,0,1]\n[null,1,0,1,0,0]\n......\nand so on.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= w.length <= 10000
  • \n\t
  • 1 <= w[i] <= 10^5
  • \n\t
  • pickIndex will be called at most 10000 times.
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u6b63\u6574\u6570\u6570\u7ec4 w \uff0c\u5176\u4e2d w[i] \u4ee3\u8868\u4e0b\u6807 i \u7684\u6743\u91cd\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\uff0c\u8bf7\u5199\u4e00\u4e2a\u51fd\u6570 pickIndex \uff0c\u5b83\u53ef\u4ee5\u968f\u673a\u5730\u83b7\u53d6\u4e0b\u6807 i\uff0c\u9009\u53d6\u4e0b\u6807 i \u7684\u6982\u7387\u4e0e w[i] \u6210\u6b63\u6bd4\u3002

\n\n
    \n
\n\n

\u4f8b\u5982\uff0c\u5bf9\u4e8e w = [1, 3]\uff0c\u6311\u9009\u4e0b\u6807 0 \u7684\u6982\u7387\u4e3a 1 / (1 + 3) = 0.25 \uff08\u5373\uff0c25%\uff09\uff0c\u800c\u9009\u53d6\u4e0b\u6807 1 \u7684\u6982\u7387\u4e3a 3 / (1 + 3) = 0.75\uff08\u5373\uff0c75%\uff09\u3002

\n\n

\u4e5f\u5c31\u662f\u8bf4\uff0c\u9009\u53d6\u4e0b\u6807 i \u7684\u6982\u7387\u4e3a w[i] / sum(w) \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a\n["Solution","pickIndex"]\n[[[1]],[]]\n\u8f93\u51fa\uff1a\n[null,0]\n\u89e3\u91ca\uff1a\nSolution solution = new Solution([1]);\nsolution.pickIndex(); // \u8fd4\u56de 0\uff0c\u56e0\u4e3a\u6570\u7ec4\u4e2d\u53ea\u6709\u4e00\u4e2a\u5143\u7d20\uff0c\u6240\u4ee5\u552f\u4e00\u7684\u9009\u62e9\u662f\u8fd4\u56de\u4e0b\u6807 0\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a\n["Solution","pickIndex","pickIndex","pickIndex","pickIndex","pickIndex"]\n[[[1,3]],[],[],[],[],[]]\n\u8f93\u51fa\uff1a\n[null,1,1,1,1,0]\n\u89e3\u91ca\uff1a\nSolution solution = new Solution([1, 3]);\nsolution.pickIndex(); // \u8fd4\u56de 1\uff0c\u8fd4\u56de\u4e0b\u6807 1\uff0c\u8fd4\u56de\u8be5\u4e0b\u6807\u6982\u7387\u4e3a 3/4 \u3002\nsolution.pickIndex(); // \u8fd4\u56de 1\nsolution.pickIndex(); // \u8fd4\u56de 1\nsolution.pickIndex(); // \u8fd4\u56de 1\nsolution.pickIndex(); // \u8fd4\u56de 0\uff0c\u8fd4\u56de\u4e0b\u6807 0\uff0c\u8fd4\u56de\u8be5\u4e0b\u6807\u6982\u7387\u4e3a 1/4 \u3002\n\n\u7531\u4e8e\u8fd9\u662f\u4e00\u4e2a\u968f\u673a\u95ee\u9898\uff0c\u5141\u8bb8\u591a\u4e2a\u7b54\u6848\uff0c\u56e0\u6b64\u4e0b\u5217\u8f93\u51fa\u90fd\u53ef\u4ee5\u88ab\u8ba4\u4e3a\u662f\u6b63\u786e\u7684:\n[null,1,1,1,1,0]\n[null,1,1,1,1,1]\n[null,1,1,1,0,0]\n[null,1,1,1,0,1]\n[null,1,0,1,0,0]\n......\n\u8bf8\u82e5\u6b64\u7c7b\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= w.length <= 10000
  • \n\t
  • 1 <= w[i] <= 10^5
  • \n\t
  • pickIndex \u5c06\u88ab\u8c03\u7528\u4e0d\u8d85\u8fc7 10000 \u6b21
  • \n
\n", "tags_en": ["Binary Search", "Random"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n Solution(vector& w) {\n\n }\n \n int pickIndex() {\n\n }\n};\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution* obj = new Solution(w);\n * int param_1 = obj->pickIndex();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n\n public Solution(int[] w) {\n\n }\n \n public int pickIndex() {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution obj = new Solution(w);\n * int param_1 = obj.pickIndex();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n\n def __init__(self, w):\n \"\"\"\n :type w: List[int]\n \"\"\"\n\n\n def pickIndex(self):\n \"\"\"\n :rtype: int\n \"\"\"\n\n\n\n# Your Solution object will be instantiated and called as such:\n# obj = Solution(w)\n# param_1 = obj.pickIndex()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n\n def __init__(self, w: List[int]):\n\n\n def pickIndex(self) -> int:\n\n\n\n# Your Solution object will be instantiated and called as such:\n# obj = Solution(w)\n# param_1 = obj.pickIndex()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} Solution;\n\n\nSolution* solutionCreate(int* w, int wSize) {\n\n}\n\nint solutionPickIndex(Solution* obj) {\n\n}\n\nvoid solutionFree(Solution* obj) {\n\n}\n\n/**\n * Your Solution struct will be instantiated and called as such:\n * Solution* obj = solutionCreate(w, wSize);\n * int param_1 = solutionPickIndex(obj);\n \n * solutionFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n\n public Solution(int[] w) {\n\n }\n \n public int PickIndex() {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution obj = new Solution(w);\n * int param_1 = obj.PickIndex();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} w\n */\nvar Solution = function(w) {\n\n};\n\n/**\n * @return {number}\n */\nSolution.prototype.pickIndex = function() {\n\n};\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = new Solution(w)\n * var param_1 = obj.pickIndex()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class Solution\n\n=begin\n :type w: Integer[]\n=end\n def initialize(w)\n\n end\n\n\n=begin\n :rtype: Integer\n=end\n def pick_index()\n\n end\n\n\nend\n\n# Your Solution object will be instantiated and called as such:\n# obj = Solution.new(w)\n# param_1 = obj.pick_index()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass Solution {\n\n init(_ w: [Int]) {\n \n }\n \n func pickIndex() -> Int {\n \n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * let obj = Solution(w)\n * let ret_1: Int = obj.pickIndex()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type Solution struct {\n\n}\n\n\nfunc Constructor(w []int) Solution {\n\n}\n\n\nfunc (this *Solution) PickIndex() int {\n\n}\n\n\n/**\n * Your Solution object will be instantiated and called as such:\n * obj := Constructor(w);\n * param_1 := obj.PickIndex();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class Solution(_w: Array[Int]) {\n\n def pickIndex(): Int = {\n\n }\n\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = new Solution(w)\n * var param_1 = obj.pickIndex()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution(w: IntArray) {\n\n fun pickIndex(): Int {\n\n }\n\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = Solution(w)\n * var param_1 = obj.pickIndex()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct Solution {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl Solution {\n\n fn new(w: Vec) -> Self {\n\n }\n \n fn pick_index(&self) -> i32 {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * let obj = Solution::new(w);\n * let ret_1: i32 = obj.pick_index();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n /**\n * @param Integer[] $w\n */\n function __construct($w) {\n \n }\n \n /**\n * @return Integer\n */\n function pickIndex() {\n \n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * $obj = Solution($w);\n * $ret_1 = $obj->pickIndex();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class Solution {\n constructor(w: number[]) {\n\n }\n\n pickIndex(): number {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = new Solution(w)\n * var param_1 = obj.pickIndex()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define solution%\n (class object%\n (super-new)\n\n ; w : (listof exact-integer?)\n (init-field\n w)\n \n ; pick-index : -> exact-integer?\n (define/public (pick-index)\n\n )))\n\n;; Your solution% object will be instantiated and called as such:\n;; (define obj (new solution% [w w]))\n;; (define param_1 (send obj pick-index))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0528](https://leetcode-cn.com/problems/random-pick-with-weight)", "[\u6309\u6743\u91cd\u968f\u673a\u9009\u62e9](/solution/0500-0599/0528.Random%20Pick%20with%20Weight/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0528](https://leetcode.com/problems/random-pick-with-weight)", "[Random Pick with Weight](/solution/0500-0599/0528.Random%20Pick%20with%20Weight/README_EN.md)", "`Binary Search`,`Random`", "Medium", ""]}, {"question_id": "0911", "frontend_question_id": "0879", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/profitable-schemes", "url_en": "https://leetcode.com/problems/profitable-schemes", "relative_path_cn": "/solution/0800-0899/0879.Profitable%20Schemes/README.md", "relative_path_en": "/solution/0800-0899/0879.Profitable%20Schemes/README_EN.md", "title_cn": "\u76c8\u5229\u8ba1\u5212", "title_en": "Profitable Schemes", "question_title_slug": "profitable-schemes", "content_en": "

There is a group of n members, and a list of various crimes they could commit. The ith crime generates a profit[i] and requires group[i] members to participate in it. If a member participates in one crime, that member can't participate in another crime.

\n\n

Let's call a profitable scheme any subset of these crimes that generates at least minProfit profit, and the total number of members participating in that subset of crimes is at most n.

\n\n

Return the number of schemes that can be chosen. Since the answer may be very large, return it modulo 109 + 7.

\n\n

 

\n

Example 1:

\n\n
\nInput: n = 5, minProfit = 3, group = [2,2], profit = [2,3]\nOutput: 2\nExplanation: To make a profit of at least 3, the group could either commit crimes 0 and 1, or just crime 1.\nIn total, there are 2 schemes.
\n\n

Example 2:

\n\n
\nInput: n = 10, minProfit = 5, group = [2,3,5], profit = [6,7,8]\nOutput: 7\nExplanation: To make a profit of at least 5, the group could commit any crimes, as long as they commit one.\nThere are 7 possible schemes: (0), (1), (2), (0,1), (0,2), (1,2), and (0,1,2).
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 100
  • \n\t
  • 0 <= minProfit <= 100
  • \n\t
  • 1 <= group.length <= 100
  • \n\t
  • 1 <= group[i] <= 100
  • \n\t
  • profit.length == group.length
  • \n\t
  • 0 <= profit[i] <= 100
  • \n
\n", "content_cn": "

\u96c6\u56e2\u91cc\u6709 n \u540d\u5458\u5de5\uff0c\u4ed6\u4eec\u53ef\u4ee5\u5b8c\u6210\u5404\u79cd\u5404\u6837\u7684\u5de5\u4f5c\u521b\u9020\u5229\u6da6\u3002

\n\n

\u7b2c\u00a0i\u00a0\u79cd\u5de5\u4f5c\u4f1a\u4ea7\u751f\u00a0profit[i]\u00a0\u7684\u5229\u6da6\uff0c\u5b83\u8981\u6c42\u00a0group[i]\u00a0\u540d\u6210\u5458\u5171\u540c\u53c2\u4e0e\u3002\u5982\u679c\u6210\u5458\u53c2\u4e0e\u4e86\u5176\u4e2d\u4e00\u9879\u5de5\u4f5c\uff0c\u5c31\u4e0d\u80fd\u53c2\u4e0e\u53e6\u4e00\u9879\u5de5\u4f5c\u3002

\n\n

\u5de5\u4f5c\u7684\u4efb\u4f55\u81f3\u5c11\u4ea7\u751f\u00a0minProfit \u5229\u6da6\u7684\u5b50\u96c6\u79f0\u4e3a\u76c8\u5229\u8ba1\u5212\u3002\u5e76\u4e14\u5de5\u4f5c\u7684\u6210\u5458\u603b\u6570\u6700\u591a\u4e3a n \u3002

\n\n

\u6709\u591a\u5c11\u79cd\u8ba1\u5212\u53ef\u4ee5\u9009\u62e9\uff1f\u56e0\u4e3a\u7b54\u6848\u5f88\u5927\uff0c\u6240\u4ee5 \u8fd4\u56de\u7ed3\u679c\u6a21\u00a010^9 + 7\u00a0\u7684\u503c\u3002

\n\n
\n
\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1an = 5, minProfit = 3, group = [2,2], profit = [2,3]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u81f3\u5c11\u4ea7\u751f 3 \u7684\u5229\u6da6\uff0c\u8be5\u96c6\u56e2\u53ef\u4ee5\u5b8c\u6210\u5de5\u4f5c 0 \u548c\u5de5\u4f5c 1 \uff0c\u6216\u4ec5\u5b8c\u6210\u5de5\u4f5c 1 \u3002\n\u603b\u7684\u6765\u8bf4\uff0c\u6709\u4e24\u79cd\u8ba1\u5212\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1an = 10, minProfit = 5, group = [2,3,5], profit = [6,7,8]\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\u81f3\u5c11\u4ea7\u751f 5 \u7684\u5229\u6da6\uff0c\u53ea\u8981\u5b8c\u6210\u5176\u4e2d\u4e00\u79cd\u5de5\u4f5c\u5c31\u884c\uff0c\u6240\u4ee5\u8be5\u96c6\u56e2\u53ef\u4ee5\u5b8c\u6210\u4efb\u4f55\u5de5\u4f5c\u3002\n\u6709 7 \u79cd\u53ef\u80fd\u7684\u8ba1\u5212\uff1a(0)\uff0c(1)\uff0c(2)\uff0c(0,1)\uff0c(0,2)\uff0c(1,2)\uff0c\u4ee5\u53ca (0,1,2) \u3002
\n
\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= n <= 100
  • \n\t
  • 0 <= minProfit <= 100
  • \n\t
  • 1 <= group.length <= 100
  • \n\t
  • 1 <= group[i] <= 100
  • \n\t
  • profit.length == group.length
  • \n\t
  • 0 <= profit[i] <= 100
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int profitableSchemes(int n, int minProfit, vector& group, vector& profit) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int profitableSchemes(int n, int minProfit, int[] group, int[] profit) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def profitableSchemes(self, n, minProfit, group, profit):\n \"\"\"\n :type n: int\n :type minProfit: int\n :type group: List[int]\n :type profit: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def profitableSchemes(self, n: int, minProfit: int, group: List[int], profit: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint profitableSchemes(int n, int minProfit, int* group, int groupSize, int* profit, int profitSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ProfitableSchemes(int n, int minProfit, int[] group, int[] profit) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} minProfit\n * @param {number[]} group\n * @param {number[]} profit\n * @return {number}\n */\nvar profitableSchemes = function(n, minProfit, group, profit) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} min_profit\n# @param {Integer[]} group\n# @param {Integer[]} profit\n# @return {Integer}\ndef profitable_schemes(n, min_profit, group, profit)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func profitableSchemes(_ n: Int, _ minProfit: Int, _ group: [Int], _ profit: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func profitableSchemes(n int, minProfit int, group []int, profit []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def profitableSchemes(n: Int, minProfit: Int, group: Array[Int], profit: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun profitableSchemes(n: Int, minProfit: Int, group: IntArray, profit: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn profitable_schemes(n: i32, min_profit: i32, group: Vec, profit: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $minProfit\n * @param Integer[] $group\n * @param Integer[] $profit\n * @return Integer\n */\n function profitableSchemes($n, $minProfit, $group, $profit) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function profitableSchemes(n: number, minProfit: number, group: number[], profit: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (profitable-schemes n minProfit group profit)\n (-> exact-integer? exact-integer? (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0879](https://leetcode-cn.com/problems/profitable-schemes)", "[\u76c8\u5229\u8ba1\u5212](/solution/0800-0899/0879.Profitable%20Schemes/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0879](https://leetcode.com/problems/profitable-schemes)", "[Profitable Schemes](/solution/0800-0899/0879.Profitable%20Schemes/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "0910", "frontend_question_id": "0878", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/nth-magical-number", "url_en": "https://leetcode.com/problems/nth-magical-number", "relative_path_cn": "/solution/0800-0899/0878.Nth%20Magical%20Number/README.md", "relative_path_en": "/solution/0800-0899/0878.Nth%20Magical%20Number/README_EN.md", "title_cn": "\u7b2c N \u4e2a\u795e\u5947\u6570\u5b57", "title_en": "Nth Magical Number", "question_title_slug": "nth-magical-number", "content_en": "

A positive integer is magical if it is divisible by either a or b.

\n\n

Given the three integers n, a, and b, return the nth magical number. Since the answer may be very large, return it modulo 109 + 7.

\n\n

 

\n

Example 1:

\n
Input: n = 1, a = 2, b = 3\nOutput: 2\n

Example 2:

\n
Input: n = 4, a = 2, b = 3\nOutput: 6\n

Example 3:

\n
Input: n = 5, a = 2, b = 4\nOutput: 10\n

Example 4:

\n
Input: n = 3, a = 6, b = 4\nOutput: 8\n
\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 109
  • \n\t
  • 2 <= a, b <= 4 * 104
  • \n
\n", "content_cn": "

\u5982\u679c\u6b63\u6574\u6570\u53ef\u4ee5\u88ab A \u6216 B \u6574\u9664\uff0c\u90a3\u4e48\u5b83\u662f\u795e\u5947\u7684\u3002

\n\n

\u8fd4\u56de\u7b2c N \u4e2a\u795e\u5947\u6570\u5b57\u3002\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u975e\u5e38\u5927\uff0c\u8fd4\u56de\u5b83\u6a21 10^9 + 7 \u7684\u7ed3\u679c\u3002

\n\n

 

\n\n
    \n
\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aN = 1, A = 2, B = 3\n\u8f93\u51fa\uff1a2\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aN = 4, A = 2, B = 3\n\u8f93\u51fa\uff1a6\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aN = 5, A = 2, B = 4\n\u8f93\u51fa\uff1a10\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1aN = 3, A = 6, B = 4\n\u8f93\u51fa\uff1a8\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= N <= 10^9
  2. \n\t
  3. 2 <= A <= 40000
  4. \n\t
  5. 2 <= B <= 40000
  6. \n
\n", "tags_en": ["Math", "Binary Search"], "tags_cn": ["\u6570\u5b66", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int nthMagicalNumber(int n, int a, int b) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int nthMagicalNumber(int n, int a, int b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def nthMagicalNumber(self, n, a, b):\n \"\"\"\n :type n: int\n :type a: int\n :type b: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def nthMagicalNumber(self, n: int, a: int, b: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint nthMagicalNumber(int n, int a, int b){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NthMagicalNumber(int n, int a, int b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} a\n * @param {number} b\n * @return {number}\n */\nvar nthMagicalNumber = function(n, a, b) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} a\n# @param {Integer} b\n# @return {Integer}\ndef nth_magical_number(n, a, b)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func nthMagicalNumber(_ n: Int, _ a: Int, _ b: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func nthMagicalNumber(n int, a int, b int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def nthMagicalNumber(n: Int, a: Int, b: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun nthMagicalNumber(n: Int, a: Int, b: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn nth_magical_number(n: i32, a: i32, b: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $a\n * @param Integer $b\n * @return Integer\n */\n function nthMagicalNumber($n, $a, $b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function nthMagicalNumber(n: number, a: number, b: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (nth-magical-number n a b)\n (-> exact-integer? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0878](https://leetcode-cn.com/problems/nth-magical-number)", "[\u7b2c N \u4e2a\u795e\u5947\u6570\u5b57](/solution/0800-0899/0878.Nth%20Magical%20Number/README.md)", "`\u6570\u5b66`,`\u4e8c\u5206\u67e5\u627e`", "\u56f0\u96be", ""], "md_table_row_en": ["[0878](https://leetcode.com/problems/nth-magical-number)", "[Nth Magical Number](/solution/0800-0899/0878.Nth%20Magical%20Number/README_EN.md)", "`Math`,`Binary Search`", "Hard", ""]}, {"question_id": "0909", "frontend_question_id": "0877", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/stone-game", "url_en": "https://leetcode.com/problems/stone-game", "relative_path_cn": "/solution/0800-0899/0877.Stone%20Game/README.md", "relative_path_en": "/solution/0800-0899/0877.Stone%20Game/README_EN.md", "title_cn": "\u77f3\u5b50\u6e38\u620f", "title_en": "Stone Game", "question_title_slug": "stone-game", "content_en": "

Alex and Lee play a game with piles of stones.  There are an even number of piles arranged in a row, and each pile has a positive integer number of stones piles[i].

\n\n

The objective of the game is to end with the most stones.  The total number of stones is odd, so there are no ties.

\n\n

Alex and Lee take turns, with Alex starting first.  Each turn, a player takes the entire pile of stones from either the beginning or the end of the row.  This continues until there are no more piles left, at which point the person with the most stones wins.

\n\n

Assuming Alex and Lee play optimally, return True if and only if Alex wins the game.

\n\n

 

\n

Example 1:

\n\n
\nInput: piles = [5,3,4,5]\nOutput: true\nExplanation: \nAlex starts first, and can only take the first 5 or the last 5.\nSay he takes the first 5, so that the row becomes [3, 4, 5].\nIf Lee takes 3, then the board is [4, 5], and Alex takes 5 to win with 10 points.\nIf Lee takes the last 5, then the board is [3, 4], and Alex takes 4 to win with 9 points.\nThis demonstrated that taking the first 5 was a winning move for Alex, so we return true.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= piles.length <= 500
  • \n\t
  • piles.length is even.
  • \n\t
  • 1 <= piles[i] <= 500
  • \n\t
  • sum(piles) is odd.
  • \n
\n", "content_cn": "

\u4e9a\u5386\u514b\u65af\u548c\u674e\u7528\u51e0\u5806\u77f3\u5b50\u5728\u505a\u6e38\u620f\u3002\u5076\u6570\u5806\u77f3\u5b50\u6392\u6210\u4e00\u884c\uff0c\u6bcf\u5806\u90fd\u6709\u6b63\u6574\u6570\u9897\u77f3\u5b50 piles[i] \u3002

\n\n

\u6e38\u620f\u4ee5\u8c01\u624b\u4e2d\u7684\u77f3\u5b50\u6700\u591a\u6765\u51b3\u51fa\u80dc\u8d1f\u3002\u77f3\u5b50\u7684\u603b\u6570\u662f\u5947\u6570\uff0c\u6240\u4ee5\u6ca1\u6709\u5e73\u5c40\u3002

\n\n

\u4e9a\u5386\u514b\u65af\u548c\u674e\u8f6e\u6d41\u8fdb\u884c\uff0c\u4e9a\u5386\u514b\u65af\u5148\u5f00\u59cb\u3002 \u6bcf\u56de\u5408\uff0c\u73a9\u5bb6\u4ece\u884c\u7684\u5f00\u59cb\u6216\u7ed3\u675f\u5904\u53d6\u8d70\u6574\u5806\u77f3\u5934\u3002 \u8fd9\u79cd\u60c5\u51b5\u4e00\u76f4\u6301\u7eed\u5230\u6ca1\u6709\u66f4\u591a\u7684\u77f3\u5b50\u5806\u4e3a\u6b62\uff0c\u6b64\u65f6\u624b\u4e2d\u77f3\u5b50\u6700\u591a\u7684\u73a9\u5bb6\u83b7\u80dc\u3002

\n\n

\u5047\u8bbe\u4e9a\u5386\u514b\u65af\u548c\u674e\u90fd\u53d1\u6325\u51fa\u6700\u4f73\u6c34\u5e73\uff0c\u5f53\u4e9a\u5386\u514b\u65af\u8d62\u5f97\u6bd4\u8d5b\u65f6\u8fd4\u56de true \uff0c\u5f53\u674e\u8d62\u5f97\u6bd4\u8d5b\u65f6\u8fd4\u56de false \u3002

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1a[5,3,4,5]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\n\u4e9a\u5386\u514b\u65af\u5148\u5f00\u59cb\uff0c\u53ea\u80fd\u62ff\u524d 5 \u9897\u6216\u540e 5 \u9897\u77f3\u5b50 \u3002\n\u5047\u8bbe\u4ed6\u53d6\u4e86\u524d 5 \u9897\uff0c\u8fd9\u4e00\u884c\u5c31\u53d8\u6210\u4e86 [3,4,5] \u3002\n\u5982\u679c\u674e\u62ff\u8d70\u524d 3 \u9897\uff0c\u90a3\u4e48\u5269\u4e0b\u7684\u662f [4,5]\uff0c\u4e9a\u5386\u514b\u65af\u62ff\u8d70\u540e 5 \u9897\u8d62\u5f97 10 \u5206\u3002\n\u5982\u679c\u674e\u62ff\u8d70\u540e 5 \u9897\uff0c\u90a3\u4e48\u5269\u4e0b\u7684\u662f [3,4]\uff0c\u4e9a\u5386\u514b\u65af\u62ff\u8d70\u540e 4 \u9897\u8d62\u5f97 9 \u5206\u3002\n\u8fd9\u8868\u660e\uff0c\u53d6\u524d 5 \u9897\u77f3\u5b50\u5bf9\u4e9a\u5386\u514b\u65af\u6765\u8bf4\u662f\u4e00\u4e2a\u80dc\u5229\u7684\u4e3e\u52a8\uff0c\u6240\u4ee5\u6211\u4eec\u8fd4\u56de true \u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 2 <= piles.length <= 500
  2. \n\t
  3. piles.length \u662f\u5076\u6570\u3002
  4. \n\t
  5. 1 <= piles[i] <= 500
  6. \n\t
  7. sum(piles) \u662f\u5947\u6570\u3002
  8. \n
\n", "tags_en": ["Minimax", "Math", "Dynamic Programming"], "tags_cn": ["\u6781\u5c0f\u5316\u6781\u5927", "\u6570\u5b66", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool stoneGame(vector& piles) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean stoneGame(int[] piles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def stoneGame(self, piles):\n \"\"\"\n :type piles: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def stoneGame(self, piles: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool stoneGame(int* piles, int pilesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool StoneGame(int[] piles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} piles\n * @return {boolean}\n */\nvar stoneGame = function(piles) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} piles\n# @return {Boolean}\ndef stone_game(piles)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func stoneGame(_ piles: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func stoneGame(piles []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def stoneGame(piles: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun stoneGame(piles: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn stone_game(piles: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $piles\n * @return Boolean\n */\n function stoneGame($piles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function stoneGame(piles: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (stone-game piles)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0877](https://leetcode-cn.com/problems/stone-game)", "[\u77f3\u5b50\u6e38\u620f](/solution/0800-0899/0877.Stone%20Game/README.md)", "`\u6781\u5c0f\u5316\u6781\u5927`,`\u6570\u5b66`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0877](https://leetcode.com/problems/stone-game)", "[Stone Game](/solution/0800-0899/0877.Stone%20Game/README_EN.md)", "`Minimax`,`Math`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0908", "frontend_question_id": "0876", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/middle-of-the-linked-list", "url_en": "https://leetcode.com/problems/middle-of-the-linked-list", "relative_path_cn": "/solution/0800-0899/0876.Middle%20of%20the%20Linked%20List/README.md", "relative_path_en": "/solution/0800-0899/0876.Middle%20of%20the%20Linked%20List/README_EN.md", "title_cn": "\u94fe\u8868\u7684\u4e2d\u95f4\u7ed3\u70b9", "title_en": "Middle of the Linked List", "question_title_slug": "middle-of-the-linked-list", "content_en": "

Given a non-empty, singly linked list with head node head, return a middle node of linked list.

\r\n\r\n

If there are two middle nodes, return the second middle node.

\r\n\r\n

 

\r\n\r\n
\r\n

Example 1:

\r\n\r\n
\r\nInput: [1,2,3,4,5]\r\nOutput: Node 3 from this list (Serialization: [3,4,5])\r\nThe returned node has value 3.  (The judge's serialization of this node is [3,4,5]).\r\nNote that we returned a ListNode object ans, such that:\r\nans.val = 3, ans.next.val = 4, ans.next.next.val = 5, and ans.next.next.next = NULL.\r\n
\r\n\r\n
\r\n

Example 2:

\r\n\r\n
\r\nInput: [1,2,3,4,5,6]\r\nOutput: Node 4 from this list (Serialization: [4,5,6])\r\nSince the list has two middle nodes with values 3 and 4, we return the second one.\r\n
\r\n\r\n

 

\r\n\r\n

Note:

\r\n\r\n
    \r\n\t
  • The number of nodes in the given list will be between 1 and 100.
  • \r\n
\r\n
\r\n
\r\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u5934\u7ed3\u70b9\u4e3a head\u00a0\u7684\u975e\u7a7a\u5355\u94fe\u8868\uff0c\u8fd4\u56de\u94fe\u8868\u7684\u4e2d\u95f4\u7ed3\u70b9\u3002

\n\n

\u5982\u679c\u6709\u4e24\u4e2a\u4e2d\u95f4\u7ed3\u70b9\uff0c\u5219\u8fd4\u56de\u7b2c\u4e8c\u4e2a\u4e2d\u95f4\u7ed3\u70b9\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1a[1,2,3,4,5]\n\u8f93\u51fa\uff1a\u6b64\u5217\u8868\u4e2d\u7684\u7ed3\u70b9 3 (\u5e8f\u5217\u5316\u5f62\u5f0f\uff1a[3,4,5])\n\u8fd4\u56de\u7684\u7ed3\u70b9\u503c\u4e3a 3 \u3002 (\u6d4b\u8bc4\u7cfb\u7edf\u5bf9\u8be5\u7ed3\u70b9\u5e8f\u5217\u5316\u8868\u8ff0\u662f [3,4,5])\u3002\n\u6ce8\u610f\uff0c\u6211\u4eec\u8fd4\u56de\u4e86\u4e00\u4e2a ListNode \u7c7b\u578b\u7684\u5bf9\u8c61 ans\uff0c\u8fd9\u6837\uff1a\nans.val = 3, ans.next.val = 4, ans.next.next.val = 5, \u4ee5\u53ca ans.next.next.next = NULL.\n
\n\n

\u793a\u4f8b\u00a02\uff1a

\n\n
\n\u8f93\u5165\uff1a[1,2,3,4,5,6]\n\u8f93\u51fa\uff1a\u6b64\u5217\u8868\u4e2d\u7684\u7ed3\u70b9 4 (\u5e8f\u5217\u5316\u5f62\u5f0f\uff1a[4,5,6])\n\u7531\u4e8e\u8be5\u5217\u8868\u6709\u4e24\u4e2a\u4e2d\u95f4\u7ed3\u70b9\uff0c\u503c\u5206\u522b\u4e3a 3 \u548c 4\uff0c\u6211\u4eec\u8fd4\u56de\u7b2c\u4e8c\u4e2a\u7ed3\u70b9\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u7ed9\u5b9a\u94fe\u8868\u7684\u7ed3\u70b9\u6570\u4ecb\u4e8e\u00a01\u00a0\u548c\u00a0100\u00a0\u4e4b\u95f4\u3002
  • \n
\n", "tags_en": ["Linked List"], "tags_cn": ["\u94fe\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n ListNode* middleNode(ListNode* head) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public ListNode middleNode(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def middleNode(self, head):\n \"\"\"\n :type head: ListNode\n :rtype: ListNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def middleNode(self, head: ListNode) -> ListNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nstruct ListNode* middleNode(struct ListNode* head){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public ListNode MiddleNode(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} head\n * @return {ListNode}\n */\nvar middleNode = function(head) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode} head\n# @return {ListNode}\ndef middle_node(head)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func middleNode(_ head: ListNode?) -> ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc middleNode(head *ListNode) *ListNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def middleNode(head: ListNode): ListNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun middleNode(head: ListNode?): ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn middle_node(head: Option>) -> Option> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @return ListNode\n */\n function middleNode($head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction middleNode(head: ListNode | null): ListNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (middle-node head)\n (-> (or/c list-node? #f) (or/c list-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0876](https://leetcode-cn.com/problems/middle-of-the-linked-list)", "[\u94fe\u8868\u7684\u4e2d\u95f4\u7ed3\u70b9](/solution/0800-0899/0876.Middle%20of%20the%20Linked%20List/README.md)", "`\u94fe\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0876](https://leetcode.com/problems/middle-of-the-linked-list)", "[Middle of the Linked List](/solution/0800-0899/0876.Middle%20of%20the%20Linked%20List/README_EN.md)", "`Linked List`", "Easy", ""]}, {"question_id": "0907", "frontend_question_id": "0875", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/koko-eating-bananas", "url_en": "https://leetcode.com/problems/koko-eating-bananas", "relative_path_cn": "/solution/0800-0899/0875.Koko%20Eating%20Bananas/README.md", "relative_path_en": "/solution/0800-0899/0875.Koko%20Eating%20Bananas/README_EN.md", "title_cn": "\u7231\u5403\u9999\u8549\u7684\u73c2\u73c2", "title_en": "Koko Eating Bananas", "question_title_slug": "koko-eating-bananas", "content_en": "

Koko loves to eat bananas. There are n piles of bananas, the ith pile has piles[i] bananas. The guards have gone and will come back in h hours.

\n\n

Koko can decide her bananas-per-hour eating speed of k. Each hour, she chooses some pile of bananas and eats k bananas from that pile. If the pile has less than k bananas, she eats all of them instead and will not eat any more bananas during this hour.

\n\n

Koko likes to eat slowly but still wants to finish eating all the bananas before the guards return.

\n\n

Return the minimum integer k such that she can eat all the bananas within h hours.

\n\n

 

\n

Example 1:

\n\n
\nInput: piles = [3,6,7,11], h = 8\nOutput: 4\n
\n\n

Example 2:

\n\n
\nInput: piles = [30,11,23,4,20], h = 5\nOutput: 30\n
\n\n

Example 3:

\n\n
\nInput: piles = [30,11,23,4,20], h = 6\nOutput: 23\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= piles.length <= 104
  • \n\t
  • piles.length <= h <= 109
  • \n\t
  • 1 <= piles[i] <= 109
  • \n
\n", "content_cn": "

\u73c2\u73c2\u559c\u6b22\u5403\u9999\u8549\u3002\u8fd9\u91cc\u6709 N \u5806\u9999\u8549\uff0c\u7b2c i \u5806\u4e2d\u6709 piles[i] \u6839\u9999\u8549\u3002\u8b66\u536b\u5df2\u7ecf\u79bb\u5f00\u4e86\uff0c\u5c06\u5728 H \u5c0f\u65f6\u540e\u56de\u6765\u3002

\n\n

\u73c2\u73c2\u53ef\u4ee5\u51b3\u5b9a\u5979\u5403\u9999\u8549\u7684\u901f\u5ea6 K \uff08\u5355\u4f4d\uff1a\u6839/\u5c0f\u65f6\uff09\u3002\u6bcf\u4e2a\u5c0f\u65f6\uff0c\u5979\u5c06\u4f1a\u9009\u62e9\u4e00\u5806\u9999\u8549\uff0c\u4ece\u4e2d\u5403\u6389 K \u6839\u3002\u5982\u679c\u8fd9\u5806\u9999\u8549\u5c11\u4e8e K \u6839\uff0c\u5979\u5c06\u5403\u6389\u8fd9\u5806\u7684\u6240\u6709\u9999\u8549\uff0c\u7136\u540e\u8fd9\u4e00\u5c0f\u65f6\u5185\u4e0d\u4f1a\u518d\u5403\u66f4\u591a\u7684\u9999\u8549\u3002  

\n\n

\u73c2\u73c2\u559c\u6b22\u6162\u6162\u5403\uff0c\u4f46\u4ecd\u7136\u60f3\u5728\u8b66\u536b\u56de\u6765\u524d\u5403\u6389\u6240\u6709\u7684\u9999\u8549\u3002

\n\n

\u8fd4\u56de\u5979\u53ef\u4ee5\u5728 H \u5c0f\u65f6\u5185\u5403\u6389\u6240\u6709\u9999\u8549\u7684\u6700\u5c0f\u901f\u5ea6 K\uff08K \u4e3a\u6574\u6570\uff09\u3002

\n\n

 

\n\n
    \n
\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165: piles = [3,6,7,11], H = 8\n\u8f93\u51fa: 4\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165: piles = [30,11,23,4,20], H = 5\n\u8f93\u51fa: 30\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165: piles = [30,11,23,4,20], H = 6\n\u8f93\u51fa: 23\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= piles.length <= 10^4
  • \n\t
  • piles.length <= H <= 10^9
  • \n\t
  • 1 <= piles[i] <= 10^9
  • \n
\n", "tags_en": ["Binary Search"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minEatingSpeed(vector& piles, int h) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minEatingSpeed(int[] piles, int h) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minEatingSpeed(self, piles, h):\n \"\"\"\n :type piles: List[int]\n :type h: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minEatingSpeed(self, piles: List[int], h: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minEatingSpeed(int* piles, int pilesSize, int h){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinEatingSpeed(int[] piles, int h) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} piles\n * @param {number} h\n * @return {number}\n */\nvar minEatingSpeed = function(piles, h) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} piles\n# @param {Integer} h\n# @return {Integer}\ndef min_eating_speed(piles, h)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minEatingSpeed(_ piles: [Int], _ h: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minEatingSpeed(piles []int, h int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minEatingSpeed(piles: Array[Int], h: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minEatingSpeed(piles: IntArray, h: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_eating_speed(piles: Vec, h: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $piles\n * @param Integer $h\n * @return Integer\n */\n function minEatingSpeed($piles, $h) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minEatingSpeed(piles: number[], h: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-eating-speed piles h)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0875](https://leetcode-cn.com/problems/koko-eating-bananas)", "[\u7231\u5403\u9999\u8549\u7684\u73c2\u73c2](/solution/0800-0899/0875.Koko%20Eating%20Bananas/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0875](https://leetcode.com/problems/koko-eating-bananas)", "[Koko Eating Bananas](/solution/0800-0899/0875.Koko%20Eating%20Bananas/README_EN.md)", "`Binary Search`", "Medium", ""]}, {"question_id": "0906", "frontend_question_id": "0874", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/walking-robot-simulation", "url_en": "https://leetcode.com/problems/walking-robot-simulation", "relative_path_cn": "/solution/0800-0899/0874.Walking%20Robot%20Simulation/README.md", "relative_path_en": "/solution/0800-0899/0874.Walking%20Robot%20Simulation/README_EN.md", "title_cn": "\u6a21\u62df\u884c\u8d70\u673a\u5668\u4eba", "title_en": "Walking Robot Simulation", "question_title_slug": "walking-robot-simulation", "content_en": "

A robot on an infinite XY-plane starts at point (0, 0) and faces north. The robot can receive one of three possible types of commands:

\n\n
    \n\t
  • -2: turn left 90 degrees,
  • \n\t
  • -1: turn right 90 degrees, or
  • \n\t
  • 1 <= k <= 9: move forward k units.
  • \n
\n\n

Some of the grid squares are obstacles. The ith obstacle is at grid point obstacles[i] = (xi, yi).

\n\n

If the robot would try to move onto them, the robot stays on the previous grid square instead (but still continues following the rest of the route.)

\n\n

Return the maximum Euclidean distance that the robot will be from the origin squared (i.e. if the distance is 5, return 25).

\n\n

Note:

\n\n
    \n\t
  • North means +Y direction.
  • \n\t
  • East means +X direction.
  • \n\t
  • South means -Y direction.
  • \n\t
  • West means -X direction.
  • \n
\n\n

 

\n

Example 1:

\n\n
\nInput: commands = [4,-1,3], obstacles = []\nOutput: 25\nExplanation: The robot starts at (0, 0):\n1. Move north 4 units to (0, 4).\n2. Turn right.\n3. Move east 3 units to (3, 4).\nThe furthest point away from the origin is (3, 4), which is 32 + 42 = 25 units away.\n
\n\n

Example 2:

\n\n
\nInput: commands = [4,-1,4,-2,4], obstacles = [[2,4]]\nOutput: 65\nExplanation: The robot starts at (0, 0):\n1. Move north 4 units to (0, 4).\n2. Turn right.\n3. Move east 1 unit and get blocked by the obstacle at (2, 4), robot is at (1, 4).\n4. Turn left.\n5. Move north 4 units to (1, 8).\nThe furthest point away from the origin is (1, 8), which is 12 + 82 = 65 units away.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= commands.length <= 104
  • \n\t
  • commands[i] is one of the values in the list [-2,-1,1,2,3,4,5,6,7,8,9].
  • \n\t
  • 0 <= obstacles.length <= 104
  • \n\t
  • -3 * 104 <= xi, yi <= 3 * 104
  • \n\t
  • The answer is guaranteed to be less than 231.
  • \n
\n", "content_cn": "

\u673a\u5668\u4eba\u5728\u4e00\u4e2a\u65e0\u9650\u5927\u5c0f\u7684 XY \u7f51\u683c\u5e73\u9762\u4e0a\u884c\u8d70\uff0c\u4ece\u70b9\u00a0(0, 0) \u5904\u5f00\u59cb\u51fa\u53d1\uff0c\u9762\u5411\u5317\u65b9\u3002\u8be5\u673a\u5668\u4eba\u53ef\u4ee5\u63a5\u6536\u4ee5\u4e0b\u4e09\u79cd\u7c7b\u578b\u7684\u547d\u4ee4 commands \uff1a

\n\n
    \n\t
  • -2 \uff1a\u5411\u5de6\u8f6c\u00a090 \u5ea6
  • \n\t
  • -1 \uff1a\u5411\u53f3\u8f6c 90 \u5ea6
  • \n\t
  • 1 <= x <= 9 \uff1a\u5411\u524d\u79fb\u52a8\u00a0x\u00a0\u4e2a\u5355\u4f4d\u957f\u5ea6
  • \n
\n\n

\u5728\u7f51\u683c\u4e0a\u6709\u4e00\u4e9b\u683c\u5b50\u88ab\u89c6\u4e3a\u969c\u788d\u7269\u00a0obstacles \u3002\u7b2c i\u00a0\u4e2a\u969c\u788d\u7269\u4f4d\u4e8e\u7f51\u683c\u70b9 \u00a0obstacles[i] = (xi, yi) \u3002

\n\n

\u673a\u5668\u4eba\u65e0\u6cd5\u8d70\u5230\u969c\u788d\u7269\u4e0a\uff0c\u5b83\u5c06\u4f1a\u505c\u7559\u5728\u969c\u788d\u7269\u7684\u524d\u4e00\u4e2a\u7f51\u683c\u65b9\u5757\u4e0a\uff0c\u4f46\u4ecd\u7136\u53ef\u4ee5\u7ee7\u7eed\u5c1d\u8bd5\u8fdb\u884c\u8be5\u8def\u7ebf\u7684\u5176\u4f59\u90e8\u5206\u3002

\n\n

\u8fd4\u56de\u4ece\u539f\u70b9\u5230\u673a\u5668\u4eba\u6240\u6709\u7ecf\u8fc7\u7684\u8def\u5f84\u70b9\uff08\u5750\u6807\u4e3a\u6574\u6570\uff09\u7684\u6700\u5927\u6b27\u5f0f\u8ddd\u79bb\u7684\u5e73\u65b9\u3002\uff08\u5373\uff0c\u5982\u679c\u8ddd\u79bb\u4e3a 5 \uff0c\u5219\u8fd4\u56de 25 \uff09

\n\n
\n
\n
\n
\n
\u00a0
\n
\n\n
\n

\u6ce8\u610f\uff1a

\n\n
    \n\t
  • \u5317\u8868\u793a +Y \u65b9\u5411\u3002
  • \n\t
  • \u4e1c\u8868\u793a +X \u65b9\u5411\u3002
  • \n\t
  • \u5357\u8868\u793a -Y \u65b9\u5411\u3002
  • \n\t
  • \u897f\u8868\u793a -X \u65b9\u5411\u3002
  • \n
\n
\n
\n
\n
\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1acommands = [4,-1,3], obstacles = []\n\u8f93\u51fa\uff1a25\n\u89e3\u91ca\uff1a\n\u673a\u5668\u4eba\u5f00\u59cb\u4f4d\u4e8e (0, 0)\uff1a\n1. \u5411\u5317\u79fb\u52a8 4 \u4e2a\u5355\u4f4d\uff0c\u5230\u8fbe (0, 4)\n2. \u53f3\u8f6c\n3. \u5411\u4e1c\u79fb\u52a8 3 \u4e2a\u5355\u4f4d\uff0c\u5230\u8fbe (3, 4)\n\u8ddd\u79bb\u539f\u70b9\u6700\u8fdc\u7684\u662f (3, 4) \uff0c\u8ddd\u79bb\u4e3a 32 + 42 = 25
\n\n

\u793a\u4f8b\u00a02\uff1a

\n\n
\n\u8f93\u5165\uff1acommands = [4,-1,4,-2,4], obstacles = [[2,4]]\n\u8f93\u51fa\uff1a65\n\u89e3\u91ca\uff1a\u673a\u5668\u4eba\u5f00\u59cb\u4f4d\u4e8e (0, 0)\uff1a\n1. \u5411\u5317\u79fb\u52a8 4 \u4e2a\u5355\u4f4d\uff0c\u5230\u8fbe (0, 4)\n2. \u53f3\u8f6c\n3. \u5411\u4e1c\u79fb\u52a8 1 \u4e2a\u5355\u4f4d\uff0c\u7136\u540e\u88ab\u4f4d\u4e8e (2, 4) \u7684\u969c\u788d\u7269\u963b\u6321\uff0c\u673a\u5668\u4eba\u505c\u5728 (1, 4)\n4. \u5de6\u8f6c\n5. \u5411\u5317\u8d70 4 \u4e2a\u5355\u4f4d\uff0c\u5230\u8fbe (1, 8)\n\u8ddd\u79bb\u539f\u70b9\u6700\u8fdc\u7684\u662f (1, 8) \uff0c\u8ddd\u79bb\u4e3a 12 + 82 = 65
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= commands.length <= 104
  • \n\t
  • commands[i] is one of the values in the list [-2,-1,1,2,3,4,5,6,7,8,9].
  • \n\t
  • 0 <= obstacles.length <= 104
  • \n\t
  • -3 * 104 <= xi, yi <= 3 * 104
  • \n\t
  • \u7b54\u6848\u4fdd\u8bc1\u5c0f\u4e8e 231
  • \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int robotSim(vector& commands, vector>& obstacles) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int robotSim(int[] commands, int[][] obstacles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def robotSim(self, commands, obstacles):\n \"\"\"\n :type commands: List[int]\n :type obstacles: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def robotSim(self, commands: List[int], obstacles: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint robotSim(int* commands, int commandsSize, int** obstacles, int obstaclesSize, int* obstaclesColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int RobotSim(int[] commands, int[][] obstacles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} commands\n * @param {number[][]} obstacles\n * @return {number}\n */\nvar robotSim = function(commands, obstacles) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} commands\n# @param {Integer[][]} obstacles\n# @return {Integer}\ndef robot_sim(commands, obstacles)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func robotSim(_ commands: [Int], _ obstacles: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func robotSim(commands []int, obstacles [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def robotSim(commands: Array[Int], obstacles: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun robotSim(commands: IntArray, obstacles: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn robot_sim(commands: Vec, obstacles: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $commands\n * @param Integer[][] $obstacles\n * @return Integer\n */\n function robotSim($commands, $obstacles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function robotSim(commands: number[], obstacles: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (robot-sim commands obstacles)\n (-> (listof exact-integer?) (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0874](https://leetcode-cn.com/problems/walking-robot-simulation)", "[\u6a21\u62df\u884c\u8d70\u673a\u5668\u4eba](/solution/0800-0899/0874.Walking%20Robot%20Simulation/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u7b80\u5355", ""], "md_table_row_en": ["[0874](https://leetcode.com/problems/walking-robot-simulation)", "[Walking Robot Simulation](/solution/0800-0899/0874.Walking%20Robot%20Simulation/README_EN.md)", "`Greedy`", "Easy", ""]}, {"question_id": "0905", "frontend_question_id": "0873", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/length-of-longest-fibonacci-subsequence", "url_en": "https://leetcode.com/problems/length-of-longest-fibonacci-subsequence", "relative_path_cn": "/solution/0800-0899/0873.Length%20of%20Longest%20Fibonacci%20Subsequence/README.md", "relative_path_en": "/solution/0800-0899/0873.Length%20of%20Longest%20Fibonacci%20Subsequence/README_EN.md", "title_cn": "\u6700\u957f\u7684\u6590\u6ce2\u90a3\u5951\u5b50\u5e8f\u5217\u7684\u957f\u5ea6", "title_en": "Length of Longest Fibonacci Subsequence", "question_title_slug": "length-of-longest-fibonacci-subsequence", "content_en": "

A sequence x1, x2, ..., xn is Fibonacci-like if:

\n\n
    \n\t
  • n >= 3
  • \n\t
  • xi + xi+1 == xi+2 for all i + 2 <= n
  • \n
\n\n

Given a strictly increasing array arr of positive integers forming a sequence, return the length of the longest Fibonacci-like subsequence of arr. If one does not exist, return 0.

\n\n

A subsequence is derived from another sequence arr by deleting any number of elements (including none) from arr, without changing the order of the remaining elements. For example, [3, 5, 8] is a subsequence of [3, 4, 5, 6, 7, 8].

\n\n

 

\n

Example 1:

\n\n
\nInput: arr = [1,2,3,4,5,6,7,8]\nOutput: 5\nExplanation: The longest subsequence that is fibonacci-like: [1,2,3,5,8].
\n\n

Example 2:

\n\n
\nInput: arr = [1,3,7,11,12,14,18]\nOutput: 3\nExplanation: The longest subsequence that is fibonacci-like: [1,11,12], [3,11,14] or [7,11,18].
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 3 <= arr.length <= 1000
  • \n\t
  • 1 <= arr[i] < arr[i + 1] <= 109
  • \n
\n", "content_cn": "

\u5982\u679c\u5e8f\u5217 X_1, X_2, ..., X_n \u6ee1\u8db3\u4e0b\u5217\u6761\u4ef6\uff0c\u5c31\u8bf4\u5b83\u662f \u6590\u6ce2\u90a3\u5951\u5f0f \u7684\uff1a

\n\n
    \n\t
  • n >= 3
  • \n\t
  • \u5bf9\u4e8e\u6240\u6709 i + 2 <= n\uff0c\u90fd\u6709 X_i + X_{i+1} = X_{i+2}
  • \n
\n\n

\u7ed9\u5b9a\u4e00\u4e2a\u4e25\u683c\u9012\u589e\u7684\u6b63\u6574\u6570\u6570\u7ec4\u5f62\u6210\u5e8f\u5217\uff0c\u627e\u5230 A \u4e2d\u6700\u957f\u7684\u6590\u6ce2\u90a3\u5951\u5f0f\u7684\u5b50\u5e8f\u5217\u7684\u957f\u5ea6\u3002\u5982\u679c\u4e00\u4e2a\u4e0d\u5b58\u5728\uff0c\u8fd4\u56de  0 \u3002

\n\n

\uff08\u56de\u60f3\u4e00\u4e0b\uff0c\u5b50\u5e8f\u5217\u662f\u4ece\u539f\u5e8f\u5217 A \u4e2d\u6d3e\u751f\u51fa\u6765\u7684\uff0c\u5b83\u4ece A \u4e2d\u5220\u6389\u4efb\u610f\u6570\u91cf\u7684\u5143\u7d20\uff08\u4e5f\u53ef\u4ee5\u4e0d\u5220\uff09\uff0c\u800c\u4e0d\u6539\u53d8\u5176\u4f59\u5143\u7d20\u7684\u987a\u5e8f\u3002\u4f8b\u5982\uff0c [3, 5, 8] \u662f [3, 4, 5, 6, 7, 8] \u7684\u4e00\u4e2a\u5b50\u5e8f\u5217\uff09

\n\n

 

\n\n
    \n
\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165: [1,2,3,4,5,6,7,8]\n\u8f93\u51fa: 5\n\u89e3\u91ca:\n\u6700\u957f\u7684\u6590\u6ce2\u90a3\u5951\u5f0f\u5b50\u5e8f\u5217\u4e3a\uff1a[1,2,3,5,8] \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165: [1,3,7,11,12,14,18]\n\u8f93\u51fa: 3\n\u89e3\u91ca:\n\u6700\u957f\u7684\u6590\u6ce2\u90a3\u5951\u5f0f\u5b50\u5e8f\u5217\u6709\uff1a\n[1,11,12]\uff0c[3,11,14] \u4ee5\u53ca [7,11,18] \u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 3 <= A.length <= 1000
  • \n\t
  • 1 <= A[0] < A[1] < ... < A[A.length - 1] <= 10^9
  • \n\t
  • \uff08\u5bf9\u4e8e\u4ee5 Java\uff0cC\uff0cC++\uff0c\u4ee5\u53ca C# \u7684\u63d0\u4ea4\uff0c\u65f6\u95f4\u9650\u5236\u88ab\u51cf\u5c11\u4e86 50%\uff09
  • \n
\n", "tags_en": ["Array", "Dynamic Programming"], "tags_cn": ["\u6570\u7ec4", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int lenLongestFibSubseq(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int lenLongestFibSubseq(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def lenLongestFibSubseq(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def lenLongestFibSubseq(self, arr: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint lenLongestFibSubseq(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LenLongestFibSubseq(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar lenLongestFibSubseq = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef len_longest_fib_subseq(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func lenLongestFibSubseq(_ arr: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func lenLongestFibSubseq(arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def lenLongestFibSubseq(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun lenLongestFibSubseq(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn len_longest_fib_subseq(arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function lenLongestFibSubseq($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function lenLongestFibSubseq(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (len-longest-fib-subseq arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0873](https://leetcode-cn.com/problems/length-of-longest-fibonacci-subsequence)", "[\u6700\u957f\u7684\u6590\u6ce2\u90a3\u5951\u5b50\u5e8f\u5217\u7684\u957f\u5ea6](/solution/0800-0899/0873.Length%20of%20Longest%20Fibonacci%20Subsequence/README.md)", "`\u6570\u7ec4`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0873](https://leetcode.com/problems/length-of-longest-fibonacci-subsequence)", "[Length of Longest Fibonacci Subsequence](/solution/0800-0899/0873.Length%20of%20Longest%20Fibonacci%20Subsequence/README_EN.md)", "`Array`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0904", "frontend_question_id": "0872", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/leaf-similar-trees", "url_en": "https://leetcode.com/problems/leaf-similar-trees", "relative_path_cn": "/solution/0800-0899/0872.Leaf-Similar%20Trees/README.md", "relative_path_en": "/solution/0800-0899/0872.Leaf-Similar%20Trees/README_EN.md", "title_cn": "\u53f6\u5b50\u76f8\u4f3c\u7684\u6811", "title_en": "Leaf-Similar Trees", "question_title_slug": "leaf-similar-trees", "content_en": "

Consider all the leaves of a binary tree, from left to right order, the values of those leaves form a leaf value sequence.

\n\n

\"\"

\n\n

For example, in the given tree above, the leaf value sequence is (6, 7, 4, 9, 8).

\n\n

Two binary trees are considered leaf-similar if their leaf value sequence is the same.

\n\n

Return true if and only if the two given trees with head nodes root1 and root2 are leaf-similar.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: root1 = [3,5,1,6,2,9,8,null,null,7,4], root2 = [3,5,1,6,7,4,2,null,null,null,null,null,null,9,8]\nOutput: true\n
\n\n

Example 2:

\n\n
\nInput: root1 = [1], root2 = [1]\nOutput: true\n
\n\n

Example 3:

\n\n
\nInput: root1 = [1], root2 = [2]\nOutput: false\n
\n\n

Example 4:

\n\n
\nInput: root1 = [1,2], root2 = [2,2]\nOutput: true\n
\n\n

Example 5:

\n\"\"\n
\nInput: root1 = [1,2,3], root2 = [1,3,2]\nOutput: false\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The number of nodes in each tree will be in the range [1, 200].
  • \n\t
  • Both of the given trees will have values in the range [0, 200].
  • \n
\n", "content_cn": "

\u8bf7\u8003\u8651\u4e00\u68f5\u4e8c\u53c9\u6811\u4e0a\u6240\u6709\u7684\u53f6\u5b50\uff0c\u8fd9\u4e9b\u53f6\u5b50\u7684\u503c\u6309\u4ece\u5de6\u5230\u53f3\u7684\u987a\u5e8f\u6392\u5217\u5f62\u6210\u4e00\u4e2a\u00a0\u53f6\u503c\u5e8f\u5217 \u3002

\n\n

\"\"

\n\n

\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u5982\u4e0a\u56fe\u6240\u793a\uff0c\u7ed9\u5b9a\u4e00\u68f5\u53f6\u503c\u5e8f\u5217\u4e3a\u00a0(6, 7, 4, 9, 8)\u00a0\u7684\u6811\u3002

\n\n

\u5982\u679c\u6709\u4e24\u68f5\u4e8c\u53c9\u6811\u7684\u53f6\u503c\u5e8f\u5217\u662f\u76f8\u540c\uff0c\u90a3\u4e48\u6211\u4eec\u5c31\u8ba4\u4e3a\u5b83\u4eec\u662f\u00a0\u53f6\u76f8\u4f3c\u00a0\u7684\u3002

\n\n

\u5982\u679c\u7ed9\u5b9a\u7684\u4e24\u4e2a\u6839\u7ed3\u70b9\u5206\u522b\u4e3a\u00a0root1 \u548c\u00a0root2\u00a0\u7684\u6811\u662f\u53f6\u76f8\u4f3c\u7684\uff0c\u5219\u8fd4\u56de\u00a0true\uff1b\u5426\u5219\u8fd4\u56de false \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1aroot1 = [3,5,1,6,2,9,8,null,null,7,4], root2 = [3,5,1,6,7,4,2,null,null,null,null,null,null,9,8]\n\u8f93\u51fa\uff1atrue\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aroot1 = [1], root2 = [1]\n\u8f93\u51fa\uff1atrue\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1aroot1 = [1], root2 = [2]\n\u8f93\u51fa\uff1afalse\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1aroot1 = [1,2], root2 = [2,2]\n\u8f93\u51fa\uff1atrue\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1aroot1 = [1,2,3], root2 = [1,3,2]\n\u8f93\u51fa\uff1afalse\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u7ed9\u5b9a\u7684\u4e24\u68f5\u6811\u53ef\u80fd\u4f1a\u6709\u00a01\u00a0\u5230 200\u00a0\u4e2a\u7ed3\u70b9\u3002
  • \n\t
  • \u7ed9\u5b9a\u7684\u4e24\u68f5\u6811\u4e0a\u7684\u503c\u4ecb\u4e8e 0 \u5230 200 \u4e4b\u95f4\u3002
  • \n
\n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n bool leafSimilar(TreeNode* root1, TreeNode* root2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public boolean leafSimilar(TreeNode root1, TreeNode root2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def leafSimilar(self, root1, root2):\n \"\"\"\n :type root1: TreeNode\n :type root2: TreeNode\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def leafSimilar(self, root1: TreeNode, root2: TreeNode) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nbool leafSimilar(struct TreeNode* root1, struct TreeNode* root2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public bool LeafSimilar(TreeNode root1, TreeNode root2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root1\n * @param {TreeNode} root2\n * @return {boolean}\n */\nvar leafSimilar = function(root1, root2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root1\n# @param {TreeNode} root2\n# @return {Boolean}\ndef leaf_similar(root1, root2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func leafSimilar(_ root1: TreeNode?, _ root2: TreeNode?) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc leafSimilar(root1 *TreeNode, root2 *TreeNode) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def leafSimilar(root1: TreeNode, root2: TreeNode): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun leafSimilar(root1: TreeNode?, root2: TreeNode?): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn leaf_similar(root1: Option>>, root2: Option>>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root1\n * @param TreeNode $root2\n * @return Boolean\n */\n function leafSimilar($root1, $root2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction leafSimilar(root1: TreeNode | null, root2: TreeNode | null): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (leaf-similar root1 root2)\n (-> (or/c tree-node? #f) (or/c tree-node? #f) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0872](https://leetcode-cn.com/problems/leaf-similar-trees)", "[\u53f6\u5b50\u76f8\u4f3c\u7684\u6811](/solution/0800-0899/0872.Leaf-Similar%20Trees/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u7b80\u5355", ""], "md_table_row_en": ["[0872](https://leetcode.com/problems/leaf-similar-trees)", "[Leaf-Similar Trees](/solution/0800-0899/0872.Leaf-Similar%20Trees/README_EN.md)", "`Tree`,`Depth-first Search`", "Easy", ""]}, {"question_id": "0903", "frontend_question_id": "0470", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/implement-rand10-using-rand7", "url_en": "https://leetcode.com/problems/implement-rand10-using-rand7", "relative_path_cn": "/solution/0400-0499/0470.Implement%20Rand10%28%29%20Using%20Rand7%28%29/README.md", "relative_path_en": "/solution/0400-0499/0470.Implement%20Rand10%28%29%20Using%20Rand7%28%29/README_EN.md", "title_cn": "\u7528 Rand7() \u5b9e\u73b0 Rand10()", "title_en": "Implement Rand10() Using Rand7()", "question_title_slug": "implement-rand10-using-rand7", "content_en": "

Given the API rand7() that generates a uniform random integer in the range [1, 7], write a function rand10() that generates a uniform random integer in the range [1, 10]. You can only call the API rand7(), and you shouldn't call any other API. Please do not use a language's built-in random API.

\n\n

Each test case will have one internal argument n, the number of times that your implemented function rand10() will be called while testing. Note that this is not an argument passed to rand10().

\n\n

Follow up:

\n\n
    \n\t
  • What is the expected value for the number of calls to rand7() function?
  • \n\t
  • Could you minimize the number of calls to rand7()?
  • \n
\n\n

 

\n

Example 1:

\n
Input: n = 1\nOutput: [2]\n

Example 2:

\n
Input: n = 2\nOutput: [2,8]\n

Example 3:

\n
Input: n = 3\nOutput: [3,8,10]\n
\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 105
  • \n
\n", "content_cn": "

\u5df2\u6709\u65b9\u6cd5 rand7 \u53ef\u751f\u6210 1 \u5230 7 \u8303\u56f4\u5185\u7684\u5747\u5300\u968f\u673a\u6574\u6570\uff0c\u8bd5\u5199\u4e00\u4e2a\u65b9\u6cd5 rand10 \u751f\u6210 1 \u5230 10 \u8303\u56f4\u5185\u7684\u5747\u5300\u968f\u673a\u6574\u6570\u3002

\n\n

\u4e0d\u8981\u4f7f\u7528\u7cfb\u7edf\u7684 Math.random() \u65b9\u6cd5\u3002

\n\n
    \n
\n\n

 

\n\n

\u793a\u4f8b 1:

\n\n
\n\u8f93\u5165: 1\n\u8f93\u51fa: [7]\n
\n\n

\u793a\u4f8b 2:

\n\n
\n\u8f93\u5165: 2\n\u8f93\u51fa: [8,4]\n
\n\n

\u793a\u4f8b 3:

\n\n
\n\u8f93\u5165: 3\n\u8f93\u51fa: [8,1,10]\n
\n\n

 

\n\n

\u63d0\u793a:

\n\n
    \n\t
  1. rand7 \u5df2\u5b9a\u4e49\u3002
  2. \n\t
  3. \u4f20\u5165\u53c2\u6570: n \u8868\u793a rand10 \u7684\u8c03\u7528\u6b21\u6570\u3002
  4. \n
\n\n

 

\n\n

\u8fdb\u9636:

\n\n
    \n\t
  1. rand7()\u8c03\u7528\u6b21\u6570\u7684 \u671f\u671b\u503c \u662f\u591a\u5c11 ?
  2. \n\t
  3. \u4f60\u80fd\u5426\u5c3d\u91cf\u5c11\u8c03\u7528 rand7() ?
  4. \n
\n", "tags_en": ["Random", "Rejection Sampling"], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "// The rand7() API is already defined for you.\n// int rand7();\n// @return a random integer in the range 1 to 7\n\nclass Solution {\npublic:\n int rand10() {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * The rand7() API is already defined in the parent class SolBase.\n * public int rand7();\n * @return a random integer in the range 1 to 7\n */\nclass Solution extends SolBase {\n public int rand10() {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# The rand7() API is already defined for you.\n# def rand7():\n# @return a random integer in the range 1 to 7\n\nclass Solution(object):\n def rand10(self):\n \"\"\"\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# The rand7() API is already defined for you.\n# def rand7():\n# @return a random integer in the range 1 to 7\n\nclass Solution:\n def rand10(self):\n \"\"\"\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "// The rand7() API is already defined for you.\n// int rand7();\n// @return a random integer in the range 1 to 7\n\nint rand10() {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * The Rand7() API is already defined in the parent class SolBase.\n * public int Rand7();\n * @return a random integer in the range 1 to 7\n */\npublic class Solution : SolBase {\n public int Rand10() {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * The rand7() API is already defined for you.\n * var rand7 = function() {}\n * @return {number} a random integer in the range 1 to 7\n */\nvar rand10 = function() {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# The rand7() API is already defined for you.\n# def rand7()\n# @return {Integer} a random integer in the range 1 to 7\n\ndef rand10()\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * The rand7() API is already defined in the parent class SolBase.\n * func rand7() -> Int = {}\n * @return a random integer in the range 1 to 7\n */\nclass Solution : SolBase {\n func rand10() -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func rand10() int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * The rand7() API is already defined in the parent class SolBase.\n * def rand7(): Int = {}\n * @return a random integer in the range 1 to 7\n */\nobject Solution extends SolBase {\n def rand10(): Int = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * The rand7() API is already defined in the parent class SolBase.\n * fun rand7(): Int {}\n * @return a random integer in the range 1 to 7\n */\nclass Solution : SolBase() {\n fun rand10(): Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "/** \n * The rand7() API is already defined for you.\n * @return a random integer in the range 1 to 7\n * fn rand7() -> i32;\n */\n\nimpl Solution {\n pub fn rand10() -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/*\n * The rand7() API is already defined for you.\n * @return a random integer in the range 1 to 7\n * function rand7();\n*/\n\nclass Solution {\n /**\n * @param \n * @return Integer\n */\n function rand10() {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * The rand7() API is already defined for you.\n * function rand7(): number {}\n * @return a random integer in the range 1 to 7\n */\n\nfunction rand10(): number {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0470](https://leetcode-cn.com/problems/implement-rand10-using-rand7)", "[\u7528 Rand7() \u5b9e\u73b0 Rand10()](/solution/0400-0499/0470.Implement%20Rand10%28%29%20Using%20Rand7%28%29/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0470](https://leetcode.com/problems/implement-rand10-using-rand7)", "[Implement Rand10() Using Rand7()](/solution/0400-0499/0470.Implement%20Rand10%28%29%20Using%20Rand7%28%29/README_EN.md)", "`Random`,`Rejection Sampling`", "Medium", ""]}, {"question_id": "0902", "frontend_question_id": "0871", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-number-of-refueling-stops", "url_en": "https://leetcode.com/problems/minimum-number-of-refueling-stops", "relative_path_cn": "/solution/0800-0899/0871.Minimum%20Number%20of%20Refueling%20Stops/README.md", "relative_path_en": "/solution/0800-0899/0871.Minimum%20Number%20of%20Refueling%20Stops/README_EN.md", "title_cn": "\u6700\u4f4e\u52a0\u6cb9\u6b21\u6570", "title_en": "Minimum Number of Refueling Stops", "question_title_slug": "minimum-number-of-refueling-stops", "content_en": "

A car travels from a starting position to a destination which is target miles east of the starting position.

\r\n\r\n

Along the way, there are gas stations.  Each station[i] represents a gas station that is station[i][0] miles east of the starting position, and has station[i][1] liters of gas.

\r\n\r\n

The car starts with an infinite tank of gas, which initially has startFuel liters of fuel in it.  It uses 1 liter of gas per 1 mile that it drives.

\r\n\r\n

When the car reaches a gas station, it may stop and refuel, transferring all the gas from the station into the car.

\r\n\r\n

What is the least number of refueling stops the car must make in order to reach its destination?  If it cannot reach the destination, return -1.

\r\n\r\n

Note that if the car reaches a gas station with 0 fuel left, the car can still refuel there.  If the car reaches the destination with 0 fuel left, it is still considered to have arrived.

\r\n\r\n

 

\r\n\r\n
\r\n

Example 1:

\r\n\r\n
\r\nInput: target = 1, startFuel = 1, stations = []\r\nOutput: 0\r\nExplanation: We can reach the target without refueling.\r\n
\r\n\r\n
\r\n

Example 2:

\r\n\r\n
\r\nInput: target = 100, startFuel = 1, stations = [[10,100]]\r\nOutput: -1\r\nExplanation: We can't reach the target (or even the first gas station).\r\n
\r\n\r\n
\r\n

Example 3:

\r\n\r\n
\r\nInput: target = 100, startFuel = 10, stations = [[10,60],[20,30],[30,30],[60,40]]\r\nOutput: 2\r\nExplanation: \r\nWe start with 10 liters of fuel.\r\nWe drive to position 10, expending 10 liters of fuel.  We refuel from 0 liters to 60 liters of gas.\r\nThen, we drive from position 10 to position 60 (expending 50 liters of fuel),\r\nand refuel from 10 liters to 50 liters of gas.  We then drive to and reach the target.\r\nWe made 2 refueling stops along the way, so we return 2.\r\n
\r\n\r\n

 

\r\n\r\n

Note:

\r\n\r\n
    \r\n\t
  1. 1 <= target, startFuel, stations[i][1] <= 10^9
  2. \r\n\t
  3. 0 <= stations.length <= 500
  4. \r\n\t
  5. 0 < stations[0][0] < stations[1][0] < ... < stations[stations.length-1][0] < target
  6. \r\n
\r\n
\r\n
\r\n
\r\n", "content_cn": "

\u6c7d\u8f66\u4ece\u8d77\u70b9\u51fa\u53d1\u9a76\u5411\u76ee\u7684\u5730\uff0c\u8be5\u76ee\u7684\u5730\u4f4d\u4e8e\u51fa\u53d1\u4f4d\u7f6e\u4e1c\u9762 target \u82f1\u91cc\u5904\u3002

\n\n

\u6cbf\u9014\u6709\u52a0\u6cb9\u7ad9\uff0c\u6bcf\u4e2a station[i] \u4ee3\u8868\u4e00\u4e2a\u52a0\u6cb9\u7ad9\uff0c\u5b83\u4f4d\u4e8e\u51fa\u53d1\u4f4d\u7f6e\u4e1c\u9762 station[i][0] \u82f1\u91cc\u5904\uff0c\u5e76\u4e14\u6709 station[i][1] \u5347\u6c7d\u6cb9\u3002

\n\n

\u5047\u8bbe\u6c7d\u8f66\u6cb9\u7bb1\u7684\u5bb9\u91cf\u662f\u65e0\u9650\u7684\uff0c\u5176\u4e2d\u6700\u521d\u6709 startFuel \u5347\u71c3\u6599\u3002\u5b83\u6bcf\u884c\u9a76 1 \u82f1\u91cc\u5c31\u4f1a\u7528\u6389 1 \u5347\u6c7d\u6cb9\u3002

\n\n

\u5f53\u6c7d\u8f66\u5230\u8fbe\u52a0\u6cb9\u7ad9\u65f6\uff0c\u5b83\u53ef\u80fd\u505c\u4e0b\u6765\u52a0\u6cb9\uff0c\u5c06\u6240\u6709\u6c7d\u6cb9\u4ece\u52a0\u6cb9\u7ad9\u8f6c\u79fb\u5230\u6c7d\u8f66\u4e2d\u3002

\n\n

\u4e3a\u4e86\u5230\u8fbe\u76ee\u7684\u5730\uff0c\u6c7d\u8f66\u6240\u5fc5\u8981\u7684\u6700\u4f4e\u52a0\u6cb9\u6b21\u6570\u662f\u591a\u5c11\uff1f\u5982\u679c\u65e0\u6cd5\u5230\u8fbe\u76ee\u7684\u5730\uff0c\u5219\u8fd4\u56de -1 \u3002

\n\n

\u6ce8\u610f\uff1a\u5982\u679c\u6c7d\u8f66\u5230\u8fbe\u52a0\u6cb9\u7ad9\u65f6\u5269\u4f59\u71c3\u6599\u4e3a 0\uff0c\u5b83\u4ecd\u7136\u53ef\u4ee5\u5728\u90a3\u91cc\u52a0\u6cb9\u3002\u5982\u679c\u6c7d\u8f66\u5230\u8fbe\u76ee\u7684\u5730\u65f6\u5269\u4f59\u71c3\u6599\u4e3a 0\uff0c\u4ecd\u7136\u8ba4\u4e3a\u5b83\u5df2\u7ecf\u5230\u8fbe\u76ee\u7684\u5730\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1atarget = 1, startFuel = 1, stations = []\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6211\u4eec\u53ef\u4ee5\u5728\u4e0d\u52a0\u6cb9\u7684\u60c5\u51b5\u4e0b\u5230\u8fbe\u76ee\u7684\u5730\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1atarget = 100, startFuel = 1, stations = [[10,100]]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u6211\u4eec\u65e0\u6cd5\u62b5\u8fbe\u76ee\u7684\u5730\uff0c\u751a\u81f3\u65e0\u6cd5\u5230\u8fbe\u7b2c\u4e00\u4e2a\u52a0\u6cb9\u7ad9\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1atarget = 100, startFuel = 10, stations = [[10,60],[20,30],[30,30],[60,40]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n\u6211\u4eec\u51fa\u53d1\u65f6\u6709 10 \u5347\u71c3\u6599\u3002\n\u6211\u4eec\u5f00\u8f66\u6765\u5230\u8ddd\u8d77\u70b9 10 \u82f1\u91cc\u5904\u7684\u52a0\u6cb9\u7ad9\uff0c\u6d88\u8017 10 \u5347\u71c3\u6599\u3002\u5c06\u6c7d\u6cb9\u4ece 0 \u5347\u52a0\u5230 60 \u5347\u3002\n\u7136\u540e\uff0c\u6211\u4eec\u4ece 10 \u82f1\u91cc\u5904\u7684\u52a0\u6cb9\u7ad9\u5f00\u5230 60 \u82f1\u91cc\u5904\u7684\u52a0\u6cb9\u7ad9\uff08\u6d88\u8017 50 \u5347\u71c3\u6599\uff09\uff0c\n\u5e76\u5c06\u6c7d\u6cb9\u4ece 10 \u5347\u52a0\u5230 50 \u5347\u3002\u7136\u540e\u6211\u4eec\u5f00\u8f66\u62b5\u8fbe\u76ee\u7684\u5730\u3002\n\u6211\u4eec\u6cbf\u9014\u57281\u4e24\u4e2a\u52a0\u6cb9\u7ad9\u505c\u9760\uff0c\u6240\u4ee5\u8fd4\u56de 2 \u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= target, startFuel, stations[i][1] <= 10^9
  2. \n\t
  3. 0 <= stations.length <= 500
  4. \n\t
  5. 0 < stations[0][0] < stations[1][0] < ... < stations[stations.length-1][0] < target
  6. \n
\n", "tags_en": ["Heap", "Dynamic Programming"], "tags_cn": ["\u5806", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minRefuelStops(int target, int startFuel, vector>& stations) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minRefuelStops(int target, int startFuel, int[][] stations) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minRefuelStops(self, target, startFuel, stations):\n \"\"\"\n :type target: int\n :type startFuel: int\n :type stations: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minRefuelStops(self, target: int, startFuel: int, stations: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minRefuelStops(int target, int startFuel, int** stations, int stationsSize, int* stationsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinRefuelStops(int target, int startFuel, int[][] stations) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} target\n * @param {number} startFuel\n * @param {number[][]} stations\n * @return {number}\n */\nvar minRefuelStops = function(target, startFuel, stations) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} target\n# @param {Integer} start_fuel\n# @param {Integer[][]} stations\n# @return {Integer}\ndef min_refuel_stops(target, start_fuel, stations)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minRefuelStops(_ target: Int, _ startFuel: Int, _ stations: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minRefuelStops(target int, startFuel int, stations [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minRefuelStops(target: Int, startFuel: Int, stations: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minRefuelStops(target: Int, startFuel: Int, stations: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_refuel_stops(target: i32, start_fuel: i32, stations: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $target\n * @param Integer $startFuel\n * @param Integer[][] $stations\n * @return Integer\n */\n function minRefuelStops($target, $startFuel, $stations) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minRefuelStops(target: number, startFuel: number, stations: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-refuel-stops target startFuel stations)\n (-> exact-integer? exact-integer? (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0871](https://leetcode-cn.com/problems/minimum-number-of-refueling-stops)", "[\u6700\u4f4e\u52a0\u6cb9\u6b21\u6570](/solution/0800-0899/0871.Minimum%20Number%20of%20Refueling%20Stops/README.md)", "`\u5806`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0871](https://leetcode.com/problems/minimum-number-of-refueling-stops)", "[Minimum Number of Refueling Stops](/solution/0800-0899/0871.Minimum%20Number%20of%20Refueling%20Stops/README_EN.md)", "`Heap`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0901", "frontend_question_id": "0870", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/advantage-shuffle", "url_en": "https://leetcode.com/problems/advantage-shuffle", "relative_path_cn": "/solution/0800-0899/0870.Advantage%20Shuffle/README.md", "relative_path_en": "/solution/0800-0899/0870.Advantage%20Shuffle/README_EN.md", "title_cn": "\u4f18\u52bf\u6d17\u724c", "title_en": "Advantage Shuffle", "question_title_slug": "advantage-shuffle", "content_en": "

Given two arrays nums1 and nums2 of equal size, the advantage of nums1 with respect to nums2 is the number of indices i for which nums1[i] > nums2[i].

\n\n

Return any permutation of nums1 that maximizes its advantage with respect to nums2.

\n\n

 

\n\n
\n

Example 1:

\n\n
\nInput: nums1 = [2,7,11,15], nums2 = [1,10,4,11]\nOutput: [2,11,7,15]\n
\n\n
\n

Example 2:

\n\n
\nInput: nums1 = [12,24,8,32], nums2 = [13,25,32,11]\nOutput: [24,32,8,12]\n
\n\n

 

\n\n

Note:

\n\n
    \n\t
  1. 1 <= nums1.length = nums2.length <= 10000
  2. \n\t
  3. 0 <= nums1[i] <= 109
  4. \n\t
  5. 0 <= nums2[i] <= 109
  6. \n
\n
\n
\n", "content_cn": "

\u7ed9\u5b9a\u4e24\u4e2a\u5927\u5c0f\u76f8\u7b49\u7684\u6570\u7ec4 A \u548c B\uff0cA \u76f8\u5bf9\u4e8e B \u7684\u4f18\u52bf\u53ef\u4ee5\u7528\u6ee1\u8db3 A[i] > B[i] \u7684\u7d22\u5f15 i \u7684\u6570\u76ee\u6765\u63cf\u8ff0\u3002

\n\n

\u8fd4\u56de A \u7684\u4efb\u610f\u6392\u5217\uff0c\u4f7f\u5176\u76f8\u5bf9\u4e8e B \u7684\u4f18\u52bf\u6700\u5927\u5316\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aA = [2,7,11,15], B = [1,10,4,11]\n\u8f93\u51fa\uff1a[2,11,7,15]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aA = [12,24,8,32], B = [13,25,32,11]\n\u8f93\u51fa\uff1a[24,32,8,12]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= A.length = B.length <= 10000
  2. \n\t
  3. 0 <= A[i] <= 10^9
  4. \n\t
  5. 0 <= B[i] <= 10^9
  6. \n
\n", "tags_en": ["Greedy", "Array"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector advantageCount(vector& nums1, vector& nums2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] advantageCount(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def advantageCount(self, nums1, nums2):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def advantageCount(self, nums1: List[int], nums2: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* advantageCount(int* nums1, int nums1Size, int* nums2, int nums2Size, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] AdvantageCount(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums1\n * @param {number[]} nums2\n * @return {number[]}\n */\nvar advantageCount = function(nums1, nums2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums1\n# @param {Integer[]} nums2\n# @return {Integer[]}\ndef advantage_count(nums1, nums2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func advantageCount(_ nums1: [Int], _ nums2: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func advantageCount(nums1 []int, nums2 []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def advantageCount(nums1: Array[Int], nums2: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun advantageCount(nums1: IntArray, nums2: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn advantage_count(nums1: Vec, nums2: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums1\n * @param Integer[] $nums2\n * @return Integer[]\n */\n function advantageCount($nums1, $nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function advantageCount(nums1: number[], nums2: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (advantage-count nums1 nums2)\n (-> (listof exact-integer?) (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0870](https://leetcode-cn.com/problems/advantage-shuffle)", "[\u4f18\u52bf\u6d17\u724c](/solution/0800-0899/0870.Advantage%20Shuffle/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0870](https://leetcode.com/problems/advantage-shuffle)", "[Advantage Shuffle](/solution/0800-0899/0870.Advantage%20Shuffle/README_EN.md)", "`Greedy`,`Array`", "Medium", ""]}, {"question_id": "0900", "frontend_question_id": "0869", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reordered-power-of-2", "url_en": "https://leetcode.com/problems/reordered-power-of-2", "relative_path_cn": "/solution/0800-0899/0869.Reordered%20Power%20of%202/README.md", "relative_path_en": "/solution/0800-0899/0869.Reordered%20Power%20of%202/README_EN.md", "title_cn": "\u91cd\u65b0\u6392\u5e8f\u5f97\u5230 2 \u7684\u5e42", "title_en": "Reordered Power of 2", "question_title_slug": "reordered-power-of-2", "content_en": "

You are given an integer n. We reorder the digits in any order (including the original order) such that the leading digit is not zero.

\n\n

Return true if and only if we can do this so that the resulting number is a power of two.

\n\n

 

\n

Example 1:

\n\n
\nInput: n = 1\nOutput: true\n
\n\n

Example 2:

\n\n
\nInput: n = 10\nOutput: false\n
\n\n

Example 3:

\n\n
\nInput: n = 16\nOutput: true\n
\n\n

Example 4:

\n\n
\nInput: n = 24\nOutput: false\n
\n\n

Example 5:

\n\n
\nInput: n = 46\nOutput: true\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 109
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u6b63\u6574\u6570 N \uff0c\u6211\u4eec\u6309\u4efb\u4f55\u987a\u5e8f\uff08\u5305\u62ec\u539f\u59cb\u987a\u5e8f\uff09\u5c06\u6570\u5b57\u91cd\u65b0\u6392\u5e8f\uff0c\u6ce8\u610f\u5176\u524d\u5bfc\u6570\u5b57\u4e0d\u80fd\u4e3a\u96f6\u3002

\n\n

\u5982\u679c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4e0a\u8ff0\u65b9\u5f0f\u5f97\u5230 2 \u7684\u5e42\uff0c\u8fd4\u56de true\uff1b\u5426\u5219\uff0c\u8fd4\u56de false\u3002

\n\n

 

\n\n
    \n
\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a1\n\u8f93\u51fa\uff1atrue\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a10\n\u8f93\u51fa\uff1afalse\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1a16\n\u8f93\u51fa\uff1atrue\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1a24\n\u8f93\u51fa\uff1afalse\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1a46\n\u8f93\u51fa\uff1atrue\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= N <= 10^9
  2. \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool reorderedPowerOf2(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean reorderedPowerOf2(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def reorderedPowerOf2(self, n):\n \"\"\"\n :type n: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def reorderedPowerOf2(self, n: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool reorderedPowerOf2(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool ReorderedPowerOf2(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {boolean}\n */\nvar reorderedPowerOf2 = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Boolean}\ndef reordered_power_of2(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func reorderedPowerOf2(_ n: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func reorderedPowerOf2(n int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def reorderedPowerOf2(n: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun reorderedPowerOf2(n: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn reordered_power_of2(n: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Boolean\n */\n function reorderedPowerOf2($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function reorderedPowerOf2(n: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (reordered-power-of2 n)\n (-> exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0869](https://leetcode-cn.com/problems/reordered-power-of-2)", "[\u91cd\u65b0\u6392\u5e8f\u5f97\u5230 2 \u7684\u5e42](/solution/0800-0899/0869.Reordered%20Power%20of%202/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0869](https://leetcode.com/problems/reordered-power-of-2)", "[Reordered Power of 2](/solution/0800-0899/0869.Reordered%20Power%20of%202/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "0899", "frontend_question_id": "0868", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/binary-gap", "url_en": "https://leetcode.com/problems/binary-gap", "relative_path_cn": "/solution/0800-0899/0868.Binary%20Gap/README.md", "relative_path_en": "/solution/0800-0899/0868.Binary%20Gap/README_EN.md", "title_cn": "\u4e8c\u8fdb\u5236\u95f4\u8ddd", "title_en": "Binary Gap", "question_title_slug": "binary-gap", "content_en": "

Given a positive integer n, find and return the longest distance between any two adjacent 1's in the binary representation of n. If there are no two adjacent 1's, return 0.

\n\n

Two 1's are adjacent if there are only 0's separating them (possibly no 0's). The distance between two 1's is the absolute difference between their bit positions. For example, the two 1's in "1001" have a distance of 3.

\n\n

 

\n

Example 1:

\n\n
\nInput: n = 22\nOutput: 2\nExplanation: 22 in binary is "10110".\nThe first adjacent pair of 1's is "10110" with a distance of 2.\nThe second adjacent pair of 1's is "10110" with a distance of 1.\nThe answer is the largest of these two distances, which is 2.\nNote that "10110" is not a valid pair since there is a 1 separating the two 1's underlined.\n
\n\n

Example 2:

\n\n
\nInput: n = 5\nOutput: 2\nExplanation: 5 in binary is "101".\n
\n\n

Example 3:

\n\n
\nInput: n = 6\nOutput: 1\nExplanation: 6 in binary is "110".\n
\n\n

Example 4:

\n\n
\nInput: n = 8\nOutput: 0\nExplanation: 8 in binary is "1000".\nThere aren't any adjacent pairs of 1's in the binary representation of 8, so we return 0.\n
\n\n

Example 5:

\n\n
\nInput: n = 1\nOutput: 0\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 109
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u6b63\u6574\u6570 n\uff0c\u627e\u5230\u5e76\u8fd4\u56de n \u7684\u4e8c\u8fdb\u5236\u8868\u793a\u4e2d\u4e24\u4e2a \u76f8\u90bb 1 \u4e4b\u95f4\u7684 \u6700\u957f\u8ddd\u79bb \u3002\u5982\u679c\u4e0d\u5b58\u5728\u4e24\u4e2a\u76f8\u90bb\u7684 1\uff0c\u8fd4\u56de 0 \u3002

\n\n

\u5982\u679c\u53ea\u6709 0 \u5c06\u4e24\u4e2a 1 \u5206\u9694\u5f00\uff08\u53ef\u80fd\u4e0d\u5b58\u5728 0 \uff09\uff0c\u5219\u8ba4\u4e3a\u8fd9\u4e24\u4e2a 1 \u5f7c\u6b64 \u76f8\u90bb \u3002\u4e24\u4e2a 1 \u4e4b\u95f4\u7684\u8ddd\u79bb\u662f\u5b83\u4eec\u7684\u4e8c\u8fdb\u5236\u8868\u793a\u4e2d\u4f4d\u7f6e\u7684\u7edd\u5bf9\u5dee\u3002\u4f8b\u5982\uff0c\"1001\" \u4e2d\u7684\u4e24\u4e2a 1 \u7684\u8ddd\u79bb\u4e3a 3 \u3002

\n\n

\u00a0

\n\n
    \n
\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1an = 22\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n22 \u7684\u4e8c\u8fdb\u5236\u662f \"10110\" \u3002\n\u5728 22 \u7684\u4e8c\u8fdb\u5236\u8868\u793a\u4e2d\uff0c\u6709\u4e09\u4e2a 1\uff0c\u7ec4\u6210\u4e24\u5bf9\u76f8\u90bb\u7684 1 \u3002\n\u7b2c\u4e00\u5bf9\u76f8\u90bb\u7684 1 \u4e2d\uff0c\u4e24\u4e2a 1 \u4e4b\u95f4\u7684\u8ddd\u79bb\u4e3a 2 \u3002\n\u7b2c\u4e8c\u5bf9\u76f8\u90bb\u7684 1 \u4e2d\uff0c\u4e24\u4e2a 1 \u4e4b\u95f4\u7684\u8ddd\u79bb\u4e3a 1 \u3002\n\u7b54\u6848\u53d6\u4e24\u4e2a\u8ddd\u79bb\u4e4b\u4e2d\u6700\u5927\u7684\uff0c\u4e5f\u5c31\u662f 2 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1an = 5\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n5 \u7684\u4e8c\u8fdb\u5236\u662f \"101\" \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1an = 6\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\n6 \u7684\u4e8c\u8fdb\u5236\u662f \"110\" \u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1an = 8\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\n8 \u7684\u4e8c\u8fdb\u5236\u662f \"1000\" \u3002\n\u5728 8 \u7684\u4e8c\u8fdb\u5236\u8868\u793a\u4e2d\u6ca1\u6709\u76f8\u90bb\u7684\u4e24\u4e2a 1\uff0c\u6240\u4ee5\u8fd4\u56de 0 \u3002\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\n\u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1a0\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= N <= 10^9
  • \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int binaryGap(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int binaryGap(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def binaryGap(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def binaryGap(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint binaryGap(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int BinaryGap(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar binaryGap = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef binary_gap(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func binaryGap(_ n: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func binaryGap(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def binaryGap(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun binaryGap(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn binary_gap(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function binaryGap($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function binaryGap(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (binary-gap n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0868](https://leetcode-cn.com/problems/binary-gap)", "[\u4e8c\u8fdb\u5236\u95f4\u8ddd](/solution/0800-0899/0868.Binary%20Gap/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0868](https://leetcode.com/problems/binary-gap)", "[Binary Gap](/solution/0800-0899/0868.Binary%20Gap/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "0898", "frontend_question_id": "0867", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/transpose-matrix", "url_en": "https://leetcode.com/problems/transpose-matrix", "relative_path_cn": "/solution/0800-0899/0867.Transpose%20Matrix/README.md", "relative_path_en": "/solution/0800-0899/0867.Transpose%20Matrix/README_EN.md", "title_cn": "\u8f6c\u7f6e\u77e9\u9635", "title_en": "Transpose Matrix", "question_title_slug": "transpose-matrix", "content_en": "

Given a 2D integer array matrix, return the transpose of matrix.

\n\n

The transpose of a matrix is the matrix flipped over its main diagonal, switching the matrix's row and column indices.

\n\n

\"\"

\n\n

 

\n

Example 1:

\n\n
\nInput: matrix = [[1,2,3],[4,5,6],[7,8,9]]\nOutput: [[1,4,7],[2,5,8],[3,6,9]]\n
\n\n

Example 2:

\n\n
\nInput: matrix = [[1,2,3],[4,5,6]]\nOutput: [[1,4],[2,5],[3,6]]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • m == matrix.length
  • \n\t
  • n == matrix[i].length
  • \n\t
  • 1 <= m, n <= 1000
  • \n\t
  • 1 <= m * n <= 105
  • \n\t
  • -109 <= matrix[i][j] <= 109
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u4e8c\u7ef4\u6574\u6570\u6570\u7ec4 matrix\uff0c\u00a0\u8fd4\u56de matrix \u7684 \u8f6c\u7f6e\u77e9\u9635 \u3002

\n\n

\u77e9\u9635\u7684 \u8f6c\u7f6e \u662f\u6307\u5c06\u77e9\u9635\u7684\u4e3b\u5bf9\u89d2\u7ebf\u7ffb\u8f6c\uff0c\u4ea4\u6362\u77e9\u9635\u7684\u884c\u7d22\u5f15\u4e0e\u5217\u7d22\u5f15\u3002

\n\n

\"\"

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1amatrix = [[1,2,3],[4,5,6],[7,8,9]]\n\u8f93\u51fa\uff1a[[1,4,7],[2,5,8],[3,6,9]]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1amatrix = [[1,2,3],[4,5,6]]\n\u8f93\u51fa\uff1a[[1,4],[2,5],[3,6]]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • m == matrix.length
  • \n\t
  • n == matrix[i].length
  • \n\t
  • 1 <= m, n <= 1000
  • \n\t
  • 1 <= m * n <= 105
  • \n\t
  • -109 <= matrix[i][j] <= 109
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> transpose(vector>& matrix) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[][] transpose(int[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def transpose(self, matrix):\n \"\"\"\n :type matrix: List[List[int]]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def transpose(self, matrix: List[List[int]]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** transpose(int** matrix, int matrixSize, int* matrixColSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[][] Transpose(int[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} matrix\n * @return {number[][]}\n */\nvar transpose = function(matrix) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} matrix\n# @return {Integer[][]}\ndef transpose(matrix)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func transpose(_ matrix: [[Int]]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func transpose(matrix [][]int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def transpose(matrix: Array[Array[Int]]): Array[Array[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun transpose(matrix: Array): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn transpose(matrix: Vec>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $matrix\n * @return Integer[][]\n */\n function transpose($matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function transpose(matrix: number[][]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (transpose matrix)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0867](https://leetcode-cn.com/problems/transpose-matrix)", "[\u8f6c\u7f6e\u77e9\u9635](/solution/0800-0899/0867.Transpose%20Matrix/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0867](https://leetcode.com/problems/transpose-matrix)", "[Transpose Matrix](/solution/0800-0899/0867.Transpose%20Matrix/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0897", "frontend_question_id": "0866", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/prime-palindrome", "url_en": "https://leetcode.com/problems/prime-palindrome", "relative_path_cn": "/solution/0800-0899/0866.Prime%20Palindrome/README.md", "relative_path_en": "/solution/0800-0899/0866.Prime%20Palindrome/README_EN.md", "title_cn": "\u56de\u6587\u7d20\u6570", "title_en": "Prime Palindrome", "question_title_slug": "prime-palindrome", "content_en": "

Find the smallest prime palindrome greater than or equal to n.

\n\n

Recall that a number is prime if it's only divisors are 1 and itself, and it is greater than 1. 

\n\n

For example, 2,3,5,7,11 and 13 are primes.

\n\n

Recall that a number is a palindrome if it reads the same from left to right as it does from right to left. 

\n\n

For example, 12321 is a palindrome.

\n\n

 

\n\n
\n

Example 1:

\n\n
\nInput: n = 6\nOutput: 7\n
\n\n
\n

Example 2:

\n\n
\nInput: n = 8\nOutput: 11\n
\n\n
\n

Example 3:

\n\n
\nInput: n = 13\nOutput: 101
\n
\n
\n
\n\n

 

\n\n

Note:

\n\n
    \n\t
  • 1 <= n <= 108
  • \n\t
  • The answer is guaranteed to exist and be less than 2 * 108.
  • \n
\n", "content_cn": "

\u6c42\u51fa\u5927\u4e8e\u6216\u7b49\u4e8e N \u7684\u6700\u5c0f\u56de\u6587\u7d20\u6570\u3002

\n\n

\u56de\u987e\u4e00\u4e0b\uff0c\u5982\u679c\u4e00\u4e2a\u6570\u5927\u4e8e 1\uff0c\u4e14\u5176\u56e0\u6570\u53ea\u6709 1 \u548c\u5b83\u81ea\u8eab\uff0c\u90a3\u4e48\u8fd9\u4e2a\u6570\u662f\u7d20\u6570\u3002

\n\n

\u4f8b\u5982\uff0c2\uff0c3\uff0c5\uff0c7\uff0c11 \u4ee5\u53ca 13 \u662f\u7d20\u6570\u3002

\n\n

\u56de\u987e\u4e00\u4e0b\uff0c\u5982\u679c\u4e00\u4e2a\u6570\u4ece\u5de6\u5f80\u53f3\u8bfb\u4e0e\u4ece\u53f3\u5f80\u5de6\u8bfb\u662f\u4e00\u6837\u7684\uff0c\u90a3\u4e48\u8fd9\u4e2a\u6570\u662f\u56de\u6587\u6570\u3002

\n\n

\u4f8b\u5982\uff0c12321 \u662f\u56de\u6587\u6570\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a6\n\u8f93\u51fa\uff1a7\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a8\n\u8f93\u51fa\uff1a11\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1a13\n\u8f93\u51fa\uff1a101
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= N <= 10^8
  • \n\t
  • \u7b54\u6848\u80af\u5b9a\u5b58\u5728\uff0c\u4e14\u5c0f\u4e8e 2 * 10^8\u3002
  • \n
\n\n

 

\n\n

 

\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int primePalindrome(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int primePalindrome(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def primePalindrome(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def primePalindrome(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint primePalindrome(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int PrimePalindrome(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar primePalindrome = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef prime_palindrome(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func primePalindrome(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func primePalindrome(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def primePalindrome(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun primePalindrome(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn prime_palindrome(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function primePalindrome($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function primePalindrome(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (prime-palindrome n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0866](https://leetcode-cn.com/problems/prime-palindrome)", "[\u56de\u6587\u7d20\u6570](/solution/0800-0899/0866.Prime%20Palindrome/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0866](https://leetcode.com/problems/prime-palindrome)", "[Prime Palindrome](/solution/0800-0899/0866.Prime%20Palindrome/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "0896", "frontend_question_id": "0865", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/smallest-subtree-with-all-the-deepest-nodes", "url_en": "https://leetcode.com/problems/smallest-subtree-with-all-the-deepest-nodes", "relative_path_cn": "/solution/0800-0899/0865.Smallest%20Subtree%20with%20all%20the%20Deepest%20Nodes/README.md", "relative_path_en": "/solution/0800-0899/0865.Smallest%20Subtree%20with%20all%20the%20Deepest%20Nodes/README_EN.md", "title_cn": "\u5177\u6709\u6240\u6709\u6700\u6df1\u8282\u70b9\u7684\u6700\u5c0f\u5b50\u6811", "title_en": "Smallest Subtree with all the Deepest Nodes", "question_title_slug": "smallest-subtree-with-all-the-deepest-nodes", "content_en": "

Given the root of a binary tree, the depth of each node is the shortest distance to the root.

\r\n\r\n

Return the smallest subtree such that it contains all the deepest nodes in the original tree.

\r\n\r\n

A node is called the deepest if it has the largest depth possible among any node in the entire tree.

\r\n\r\n

The subtree of a node is tree consisting of that node, plus the set of all descendants of that node.

\r\n\r\n

Note: This question is the same as 1123: https://leetcode.com/problems/lowest-common-ancestor-of-deepest-leaves/

\r\n\r\n

 

\r\n

Example 1:

\r\n\"\"\r\n
\r\nInput: root = [3,5,1,6,2,0,8,null,null,7,4]\r\nOutput: [2,7,4]\r\nExplanation: We return the node with value 2, colored in yellow in the diagram.\r\nThe nodes coloured in blue are the deepest nodes of the tree.\r\nNotice that nodes 5, 3 and 2 contain the deepest nodes in the tree but node 2 is the smallest subtree among them, so we return it.\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: root = [1]\r\nOutput: [1]\r\nExplanation: The root is the deepest node in the tree.\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: root = [0,1,3,null,2]\r\nOutput: [2]\r\nExplanation: The deepest node in the tree is 2, the valid subtrees are the subtrees of nodes 2, 1 and 0 but the subtree of node 2 is the smallest.\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • The number of nodes in the tree will be in the range [1, 500].
  • \r\n\t
  • 0 <= Node.val <= 500
  • \r\n\t
  • The values of the nodes in the tree are unique.
  • \r\n
", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u6839\u4e3a\u00a0root\u00a0\u7684\u4e8c\u53c9\u6811\uff0c\u6bcf\u4e2a\u8282\u70b9\u7684\u6df1\u5ea6\u662f \u8be5\u8282\u70b9\u5230\u6839\u7684\u6700\u77ed\u8ddd\u79bb \u3002

\n\n

\u5982\u679c\u4e00\u4e2a\u8282\u70b9\u5728 \u6574\u4e2a\u6811 \u7684\u4efb\u610f\u8282\u70b9\u4e4b\u95f4\u5177\u6709\u6700\u5927\u7684\u6df1\u5ea6\uff0c\u5219\u8be5\u8282\u70b9\u662f \u6700\u6df1\u7684 \u3002

\n\n

\u4e00\u4e2a\u8282\u70b9\u7684 \u5b50\u6811 \u662f\u8be5\u8282\u70b9\u52a0\u4e0a\u5b83\u7684\u6240\u6709\u540e\u4ee3\u7684\u96c6\u5408\u3002

\n\n

\u8fd4\u56de\u80fd\u6ee1\u8db3 \u4ee5\u8be5\u8282\u70b9\u4e3a\u6839\u7684\u5b50\u6811\u4e2d\u5305\u542b\u6240\u6709\u6700\u6df1\u7684\u8282\u70b9 \u8fd9\u4e00\u6761\u4ef6\u7684\u5177\u6709\u6700\u5927\u6df1\u5ea6\u7684\u8282\u70b9\u3002

\n\n

\u00a0

\n\n

\u6ce8\u610f\uff1a\u672c\u9898\u4e0e\u529b\u6263 1123 \u91cd\u590d\uff1ahttps://leetcode-cn.com/problems/lowest-common-ancestor-of-deepest-leaves/

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1aroot = [3,5,1,6,2,0,8,null,null,7,4]\n\u8f93\u51fa\uff1a[2,7,4]\n\u89e3\u91ca\uff1a\n\u6211\u4eec\u8fd4\u56de\u503c\u4e3a 2 \u7684\u8282\u70b9\uff0c\u5728\u56fe\u4e2d\u7528\u9ec4\u8272\u6807\u8bb0\u3002\n\u5728\u56fe\u4e2d\u7528\u84dd\u8272\u6807\u8bb0\u7684\u662f\u6811\u7684\u6700\u6df1\u7684\u8282\u70b9\u3002\n\u6ce8\u610f\uff0c\u8282\u70b9 5\u30013 \u548c 2 \u5305\u542b\u6811\u4e2d\u6700\u6df1\u7684\u8282\u70b9\uff0c\u4f46\u8282\u70b9 2 \u7684\u5b50\u6811\u6700\u5c0f\uff0c\u56e0\u6b64\u6211\u4eec\u8fd4\u56de\u5b83\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aroot = [1]\n\u8f93\u51fa\uff1a[1]\n\u89e3\u91ca\uff1a\u6839\u8282\u70b9\u662f\u6811\u4e2d\u6700\u6df1\u7684\u8282\u70b9\u3002
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1aroot = [0,1,3,null,2]\n\u8f93\u51fa\uff1a[2]\n\u89e3\u91ca\uff1a\u6811\u4e2d\u6700\u6df1\u7684\u8282\u70b9\u4e3a 2 \uff0c\u6709\u6548\u5b50\u6811\u4e3a\u8282\u70b9 2\u30011 \u548c 0 \u7684\u5b50\u6811\uff0c\u4f46\u8282\u70b9 2 \u7684\u5b50\u6811\u6700\u5c0f\u3002
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u6811\u4e2d\u8282\u70b9\u7684\u6570\u91cf\u4ecb\u4e8e\u00a01 \u548c\u00a0500 \u4e4b\u95f4\u3002
  • \n\t
  • 0 <= Node.val <= 500
  • \n\t
  • \u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u90fd\u662f\u72ec\u4e00\u65e0\u4e8c\u7684\u3002
  • \n
\n", "tags_en": ["Tree", "Depth-first Search", "Breadth-first Search", "Recursion"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u9012\u5f52"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* subtreeWithAllDeepest(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode subtreeWithAllDeepest(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def subtreeWithAllDeepest(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: TreeNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def subtreeWithAllDeepest(self, root: TreeNode) -> TreeNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* subtreeWithAllDeepest(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode SubtreeWithAllDeepest(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {TreeNode}\n */\nvar subtreeWithAllDeepest = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {TreeNode}\ndef subtree_with_all_deepest(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func subtreeWithAllDeepest(_ root: TreeNode?) -> TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc subtreeWithAllDeepest(root *TreeNode) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def subtreeWithAllDeepest(root: TreeNode): TreeNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun subtreeWithAllDeepest(root: TreeNode?): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn subtree_with_all_deepest(root: Option>>) -> Option>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return TreeNode\n */\n function subtreeWithAllDeepest($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction subtreeWithAllDeepest(root: TreeNode | null): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (subtree-with-all-deepest root)\n (-> (or/c tree-node? #f) (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0865](https://leetcode-cn.com/problems/smallest-subtree-with-all-the-deepest-nodes)", "[\u5177\u6709\u6240\u6709\u6700\u6df1\u8282\u70b9\u7684\u6700\u5c0f\u5b50\u6811](/solution/0800-0899/0865.Smallest%20Subtree%20with%20all%20the%20Deepest%20Nodes/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u9012\u5f52`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0865](https://leetcode.com/problems/smallest-subtree-with-all-the-deepest-nodes)", "[Smallest Subtree with all the Deepest Nodes](/solution/0800-0899/0865.Smallest%20Subtree%20with%20all%20the%20Deepest%20Nodes/README_EN.md)", "`Tree`,`Depth-first Search`,`Breadth-first Search`,`Recursion`", "Medium", ""]}, {"question_id": "0895", "frontend_question_id": "0864", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/shortest-path-to-get-all-keys", "url_en": "https://leetcode.com/problems/shortest-path-to-get-all-keys", "relative_path_cn": "/solution/0800-0899/0864.Shortest%20Path%20to%20Get%20All%20Keys/README.md", "relative_path_en": "/solution/0800-0899/0864.Shortest%20Path%20to%20Get%20All%20Keys/README_EN.md", "title_cn": "\u83b7\u53d6\u6240\u6709\u94a5\u5319\u7684\u6700\u77ed\u8def\u5f84", "title_en": "Shortest Path to Get All Keys", "question_title_slug": "shortest-path-to-get-all-keys", "content_en": "

We are given a 2-dimensional grid"." is an empty cell, "#" is a wall, "@" is the starting point, ("a", "b", ...) are keys, and ("A""B", ...) are locks.

\r\n\r\n

We start at the starting point, and one move consists of walking one space in one of the 4 cardinal directions.  We cannot walk outside the grid, or walk into a wall.  If we walk over a key, we pick it up.  We can't walk over a lock unless we have the corresponding key.

\r\n\r\n

For some 1 <= K <= 6, there is exactly one lowercase and one uppercase letter of the first K letters of the English alphabet in the grid.  This means that there is exactly one key for each lock, and one lock for each key; and also that the letters used to represent the keys and locks were chosen in the same order as the English alphabet.

\r\n\r\n

Return the lowest number of moves to acquire all keys.  If it's impossible, return -1.

\r\n\r\n

 

\r\n\r\n
\r\n

Example 1:

\r\n\r\n
\r\nInput: ["@.a.#","###.#","b.A.B"]\r\nOutput: 8\r\n
\r\n\r\n
\r\n

Example 2:

\r\n\r\n
\r\nInput: ["@..aA","..B#.","....b"]\r\nOutput: 6\r\n
\r\n
\r\n\r\n

 

\r\n\r\n

Note:

\r\n\r\n
    \r\n\t
  1. 1 <= grid.length <= 30
  2. \r\n\t
  3. 1 <= grid[0].length <= 30
  4. \r\n\t
  5. grid[i][j] contains only '.', '#', '@''a'-'f' and 'A'-'F'
  6. \r\n\t
  7. The number of keys is in [1, 6].  Each key has a different letter and opens exactly one lock.
  8. \r\n
\r\n
\r\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u7ef4\u7f51\u683c grid\u3002 "." \u4ee3\u8868\u4e00\u4e2a\u7a7a\u623f\u95f4\uff0c "#" \u4ee3\u8868\u4e00\u5835\u5899\uff0c "@" \u662f\u8d77\u70b9\uff0c\uff08"a""b", ...\uff09\u4ee3\u8868\u94a5\u5319\uff0c\uff08"A""B", ...\uff09\u4ee3\u8868\u9501\u3002

\n\n

\u6211\u4eec\u4ece\u8d77\u70b9\u5f00\u59cb\u51fa\u53d1\uff0c\u4e00\u6b21\u79fb\u52a8\u662f\u6307\u5411\u56db\u4e2a\u57fa\u672c\u65b9\u5411\u4e4b\u4e00\u884c\u8d70\u4e00\u4e2a\u5355\u4f4d\u7a7a\u95f4\u3002\u6211\u4eec\u4e0d\u80fd\u5728\u7f51\u683c\u5916\u9762\u884c\u8d70\uff0c\u4e5f\u65e0\u6cd5\u7a7f\u8fc7\u4e00\u5835\u5899\u3002\u5982\u679c\u9014\u7ecf\u4e00\u4e2a\u94a5\u5319\uff0c\u6211\u4eec\u5c31\u628a\u5b83\u6361\u8d77\u6765\u3002\u9664\u975e\u6211\u4eec\u624b\u91cc\u6709\u5bf9\u5e94\u7684\u94a5\u5319\uff0c\u5426\u5219\u65e0\u6cd5\u901a\u8fc7\u9501\u3002

\n\n

\u5047\u8bbe K \u4e3a\u94a5\u5319/\u9501\u7684\u4e2a\u6570\uff0c\u4e14\u6ee1\u8db3 1 <= K <= 6\uff0c\u5b57\u6bcd\u8868\u4e2d\u7684\u524d K \u4e2a\u5b57\u6bcd\u5728\u7f51\u683c\u4e2d\u90fd\u6709\u81ea\u5df1\u5bf9\u5e94\u7684\u4e00\u4e2a\u5c0f\u5199\u548c\u4e00\u4e2a\u5927\u5199\u5b57\u6bcd\u3002\u6362\u8a00\u4e4b\uff0c\u6bcf\u4e2a\u9501\u6709\u552f\u4e00\u5bf9\u5e94\u7684\u94a5\u5319\uff0c\u6bcf\u4e2a\u94a5\u5319\u4e5f\u6709\u552f\u4e00\u5bf9\u5e94\u7684\u9501\u3002\u53e6\u5916\uff0c\u4ee3\u8868\u94a5\u5319\u548c\u9501\u7684\u5b57\u6bcd\u4e92\u4e3a\u5927\u5c0f\u5199\u5e76\u6309\u5b57\u6bcd\u987a\u5e8f\u6392\u5217\u3002

\n\n

\u8fd4\u56de\u83b7\u53d6\u6240\u6709\u94a5\u5319\u6240\u9700\u8981\u7684\u79fb\u52a8\u7684\u6700\u5c11\u6b21\u6570\u3002\u5982\u679c\u65e0\u6cd5\u83b7\u53d6\u6240\u6709\u94a5\u5319\uff0c\u8fd4\u56de -1 \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a["@.a.#","###.#","b.A.B"]\n\u8f93\u51fa\uff1a8\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a["@..aA","..B#.","....b"]\n\u8f93\u51fa\uff1a6\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= grid.length <= 30
  2. \n\t
  3. 1 <= grid[0].length <= 30
  4. \n\t
  5. grid[i][j] \u53ea\u542b\u6709 '.''#''@''a'-'f' \u4ee5\u53ca 'A'-'F'
  6. \n\t
  7. \u94a5\u5319\u7684\u6570\u76ee\u8303\u56f4\u662f [1, 6]\uff0c\u6bcf\u4e2a\u94a5\u5319\u90fd\u5bf9\u5e94\u4e00\u4e2a\u4e0d\u540c\u7684\u5b57\u6bcd\uff0c\u6b63\u597d\u6253\u5f00\u4e00\u4e2a\u5bf9\u5e94\u7684\u9501\u3002
  8. \n
\n", "tags_en": ["Heap", "Breadth-first Search"], "tags_cn": ["\u5806", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int shortestPathAllKeys(vector& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int shortestPathAllKeys(String[] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def shortestPathAllKeys(self, grid):\n \"\"\"\n :type grid: List[str]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def shortestPathAllKeys(self, grid: List[str]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint shortestPathAllKeys(char ** grid, int gridSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ShortestPathAllKeys(string[] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} grid\n * @return {number}\n */\nvar shortestPathAllKeys = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} grid\n# @return {Integer}\ndef shortest_path_all_keys(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func shortestPathAllKeys(_ grid: [String]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func shortestPathAllKeys(grid []string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def shortestPathAllKeys(grid: Array[String]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun shortestPathAllKeys(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn shortest_path_all_keys(grid: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $grid\n * @return Integer\n */\n function shortestPathAllKeys($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function shortestPathAllKeys(grid: string[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (shortest-path-all-keys grid)\n (-> (listof string?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0864](https://leetcode-cn.com/problems/shortest-path-to-get-all-keys)", "[\u83b7\u53d6\u6240\u6709\u94a5\u5319\u7684\u6700\u77ed\u8def\u5f84](/solution/0800-0899/0864.Shortest%20Path%20to%20Get%20All%20Keys/README.md)", "`\u5806`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[0864](https://leetcode.com/problems/shortest-path-to-get-all-keys)", "[Shortest Path to Get All Keys](/solution/0800-0899/0864.Shortest%20Path%20to%20Get%20All%20Keys/README_EN.md)", "`Heap`,`Breadth-first Search`", "Hard", ""]}, {"question_id": "0894", "frontend_question_id": "0710", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/random-pick-with-blacklist", "url_en": "https://leetcode.com/problems/random-pick-with-blacklist", "relative_path_cn": "/solution/0700-0799/0710.Random%20Pick%20with%20Blacklist/README.md", "relative_path_en": "/solution/0700-0799/0710.Random%20Pick%20with%20Blacklist/README_EN.md", "title_cn": "\u9ed1\u540d\u5355\u4e2d\u7684\u968f\u673a\u6570", "title_en": "Random Pick with Blacklist", "question_title_slug": "random-pick-with-blacklist", "content_en": "

Given a blacklist blacklist containing unique integers from [0, n), write a function to return a uniform random integer from [0, n) which is NOT in blacklist.

\n\n

Optimize it such that it minimizes the call to system’s Math.random().

\n\n

Note:

\n\n
    \n\t
  1. 1 <= n <= 1000000000
  2. \n\t
  3. 0 <= blacklist.length < min(100000, n)
  4. \n\t
  5. [0, n) does NOT include n. See interval notation.
  6. \n
\n\n

Example 1:

\n\n
\nInput: \n["Solution","pick","pick","pick"]\n[[1,[]],[],[],[]]\nOutput: [null,0,0,0]\n
\n\n

Example 2:

\n\n
\nInput: \n["Solution","pick","pick","pick"]\n[[2,[]],[],[],[]]\nOutput: [null,1,1,1]\n
\n\n

Example 3:

\n\n
\nInput: \n["Solution","pick","pick","pick"]\n[[3,[1]],[],[],[]]\nOutput: [null,0,0,2]\n
\n\n

Example 4:

\n\n
\nInput: \n["Solution","pick","pick","pick"]\n[[4,[2]],[],[],[]]\nOutput: [null,1,3,1]\n
\n\n

Explanation of Input Syntax:

\n\n

The input is two lists: the subroutines called and their arguments. Solution's constructor has two arguments, n and the blacklist blacklist. pick has no arguments. Arguments are always wrapped with a list, even if there aren't any.

\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u5305\u542b [0\uff0cn) \u4e2d\u4e0d\u91cd\u590d\u6574\u6570\u7684\u9ed1\u540d\u5355 blacklist \uff0c\u5199\u4e00\u4e2a\u51fd\u6570\u4ece [0, n) \u4e2d\u8fd4\u56de\u4e00\u4e2a\u4e0d\u5728 blacklist \u4e2d\u7684\u968f\u673a\u6574\u6570\u3002

\n\n

\u5bf9\u5b83\u8fdb\u884c\u4f18\u5316\u4f7f\u5176\u5c3d\u91cf\u5c11\u8c03\u7528\u7cfb\u7edf\u65b9\u6cd5 Math.random() \u3002

\n\n

\u63d0\u793a:

\n\n
    \n\t
  1. 1 <= n <= 1000000000
  2. \n\t
  3. 0 <= blacklist.length < min(100000, N)
  4. \n\t
  5. [0, n)\u00a0\u4e0d\u5305\u542b n \uff0c\u8be6\u7ec6\u53c2\u89c1\u00a0interval notation\u00a0\u3002
  6. \n
\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1a\n[\"Solution\",\"pick\",\"pick\",\"pick\"]\n[[1,[]],[],[],[]]\n\u8f93\u51fa\uff1a[null,0,0,0]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1a\n[\"Solution\",\"pick\",\"pick\",\"pick\"]\n[[2,[]],[],[],[]]\n\u8f93\u51fa\uff1a[null,1,1,1]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1a\n[\"Solution\",\"pick\",\"pick\",\"pick\"]\n[[3,[1]],[],[],[]]\n\u8f93\u51fa\uff1a[null,0,0,2]\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1a \n[\"Solution\",\"pick\",\"pick\",\"pick\"]\n[[4,[2]],[],[],[]]\n\u8f93\u51fa\uff1a[null,1,3,1]\n
\n\n

\u8f93\u5165\u8bed\u6cd5\u8bf4\u660e\uff1a

\n\n

\u8f93\u5165\u662f\u4e24\u4e2a\u5217\u8868\uff1a\u8c03\u7528\u6210\u5458\u51fd\u6570\u540d\u548c\u8c03\u7528\u7684\u53c2\u6570\u3002Solution\u7684\u6784\u9020\u51fd\u6570\u6709\u4e24\u4e2a\u53c2\u6570\uff0cn \u548c\u9ed1\u540d\u5355\u00a0blacklist\u3002pick\u00a0\u6ca1\u6709\u53c2\u6570\uff0c\u8f93\u5165\u53c2\u6570\u662f\u4e00\u4e2a\u5217\u8868\uff0c\u5373\u4f7f\u53c2\u6570\u4e3a\u7a7a\uff0c\u4e5f\u4f1a\u8f93\u5165\u4e00\u4e2a [] \u7a7a\u5217\u8868\u3002

\n", "tags_en": ["Sort", "Hash Table", "Binary Search", "Random"], "tags_cn": ["\u6392\u5e8f", "\u54c8\u5e0c\u8868", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n Solution(int n, vector& blacklist) {\n\n }\n \n int pick() {\n\n }\n};\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution* obj = new Solution(n, blacklist);\n * int param_1 = obj->pick();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n\n public Solution(int n, int[] blacklist) {\n\n }\n \n public int pick() {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution obj = new Solution(n, blacklist);\n * int param_1 = obj.pick();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n\n def __init__(self, n, blacklist):\n \"\"\"\n :type n: int\n :type blacklist: List[int]\n \"\"\"\n\n\n def pick(self):\n \"\"\"\n :rtype: int\n \"\"\"\n\n\n\n# Your Solution object will be instantiated and called as such:\n# obj = Solution(n, blacklist)\n# param_1 = obj.pick()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n\n def __init__(self, n: int, blacklist: List[int]):\n\n\n def pick(self) -> int:\n\n\n\n# Your Solution object will be instantiated and called as such:\n# obj = Solution(n, blacklist)\n# param_1 = obj.pick()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} Solution;\n\n\nSolution* solutionCreate(int n, int* blacklist, int blacklistSize) {\n\n}\n\nint solutionPick(Solution* obj) {\n\n}\n\nvoid solutionFree(Solution* obj) {\n\n}\n\n/**\n * Your Solution struct will be instantiated and called as such:\n * Solution* obj = solutionCreate(n, blacklist, blacklistSize);\n * int param_1 = solutionPick(obj);\n \n * solutionFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n\n public Solution(int n, int[] blacklist) {\n\n }\n \n public int Pick() {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution obj = new Solution(n, blacklist);\n * int param_1 = obj.Pick();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[]} blacklist\n */\nvar Solution = function(n, blacklist) {\n\n};\n\n/**\n * @return {number}\n */\nSolution.prototype.pick = function() {\n\n};\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = new Solution(n, blacklist)\n * var param_1 = obj.pick()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class Solution\n\n=begin\n :type n: Integer\n :type blacklist: Integer[]\n=end\n def initialize(n, blacklist)\n\n end\n\n\n=begin\n :rtype: Integer\n=end\n def pick()\n\n end\n\n\nend\n\n# Your Solution object will be instantiated and called as such:\n# obj = Solution.new(n, blacklist)\n# param_1 = obj.pick()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass Solution {\n\n init(_ n: Int, _ blacklist: [Int]) {\n\n }\n \n func pick() -> Int {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * let obj = Solution(n, blacklist)\n * let ret_1: Int = obj.pick()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type Solution struct {\n\n}\n\n\nfunc Constructor(n int, blacklist []int) Solution {\n\n}\n\n\nfunc (this *Solution) Pick() int {\n\n}\n\n\n/**\n * Your Solution object will be instantiated and called as such:\n * obj := Constructor(n, blacklist);\n * param_1 := obj.Pick();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class Solution(_n: Int, _blacklist: Array[Int]) {\n\n def pick(): Int = {\n\n }\n\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = new Solution(n, blacklist)\n * var param_1 = obj.pick()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution(n: Int, blacklist: IntArray) {\n\n fun pick(): Int {\n\n }\n\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = Solution(n, blacklist)\n * var param_1 = obj.pick()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct Solution {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl Solution {\n\n fn new(n: i32, blacklist: Vec) -> Self {\n\n }\n \n fn pick(&self) -> i32 {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * let obj = Solution::new(n, blacklist);\n * let ret_1: i32 = obj.pick();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n /**\n * @param Integer $n\n * @param Integer[] $blacklist\n */\n function __construct($n, $blacklist) {\n\n }\n\n /**\n * @return Integer\n */\n function pick() {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * $obj = Solution($n, $blacklist);\n * $ret_1 = $obj->pick();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class Solution {\n constructor(n: number, blacklist: number[]) {\n\n }\n\n pick(): number {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = new Solution(n, blacklist)\n * var param_1 = obj.pick()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define solution%\n (class object%\n (super-new)\n\n ; n : exact-integer?\n\n ; blacklist : (listof exact-integer?)\n (init-field\n n\n blacklist)\n \n ; pick : -> exact-integer?\n (define/public (pick)\n\n )))\n\n;; Your solution% object will be instantiated and called as such:\n;; (define obj (new solution% [n n] [blacklist blacklist]))\n;; (define param_1 (send obj pick))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0710](https://leetcode-cn.com/problems/random-pick-with-blacklist)", "[\u9ed1\u540d\u5355\u4e2d\u7684\u968f\u673a\u6570](/solution/0700-0799/0710.Random%20Pick%20with%20Blacklist/README.md)", "`\u6392\u5e8f`,`\u54c8\u5e0c\u8868`,`\u4e8c\u5206\u67e5\u627e`", "\u56f0\u96be", ""], "md_table_row_en": ["[0710](https://leetcode.com/problems/random-pick-with-blacklist)", "[Random Pick with Blacklist](/solution/0700-0799/0710.Random%20Pick%20with%20Blacklist/README_EN.md)", "`Sort`,`Hash Table`,`Binary Search`,`Random`", "Hard", ""]}, {"question_id": "0893", "frontend_question_id": "0863", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/all-nodes-distance-k-in-binary-tree", "url_en": "https://leetcode.com/problems/all-nodes-distance-k-in-binary-tree", "relative_path_cn": "/solution/0800-0899/0863.All%20Nodes%20Distance%20K%20in%20Binary%20Tree/README.md", "relative_path_en": "/solution/0800-0899/0863.All%20Nodes%20Distance%20K%20in%20Binary%20Tree/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u4e2d\u6240\u6709\u8ddd\u79bb\u4e3a K \u7684\u7ed3\u70b9", "title_en": "All Nodes Distance K in Binary Tree", "question_title_slug": "all-nodes-distance-k-in-binary-tree", "content_en": "

We are given a binary tree (with root node root), a target node, and an integer value k.

\n\n

Return a list of the values of all nodes that have a distance k from the target node.  The answer can be returned in any order.

\n\n

 

\n\n
    \n
\n\n
\n

Example 1:

\n\n
\nInput: root = [3,5,1,6,2,0,8,null,null,7,4], target = 5, k = 2\n\nOutput: [7,4,1]\n\nExplanation: \nThe nodes that are a distance 2 from the target node (with value 5)\nhave values 7, 4, and 1.\n\n\"\"\n\nNote that the inputs "root" and "target" are actually TreeNodes.\nThe descriptions of the inputs above are just serializations of these objects.\n
\n\n

 

\n\n

Note:

\n\n
    \n\t
  1. The given tree is non-empty.
  2. \n\t
  3. Each node in the tree has unique values 0 <= node.val <= 500.
  4. \n\t
  5. The target node is a node in the tree.
  6. \n\t
  7. 0 <= k <= 1000.
  8. \n
\n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811\uff08\u5177\u6709\u6839\u7ed3\u70b9 root\uff09\uff0c \u4e00\u4e2a\u76ee\u6807\u7ed3\u70b9 target \uff0c\u548c\u4e00\u4e2a\u6574\u6570\u503c K \u3002

\n\n

\u8fd4\u56de\u5230\u76ee\u6807\u7ed3\u70b9 target \u8ddd\u79bb\u4e3a K \u7684\u6240\u6709\u7ed3\u70b9\u7684\u503c\u7684\u5217\u8868\u3002 \u7b54\u6848\u53ef\u4ee5\u4ee5\u4efb\u4f55\u987a\u5e8f\u8fd4\u56de\u3002

\n\n

 

\n\n
    \n
\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aroot = [3,5,1,6,2,0,8,null,null,7,4], target = 5, K = 2\n\u8f93\u51fa\uff1a[7,4,1]\n\u89e3\u91ca\uff1a\n\u6240\u6c42\u7ed3\u70b9\u4e3a\u4e0e\u76ee\u6807\u7ed3\u70b9\uff08\u503c\u4e3a 5\uff09\u8ddd\u79bb\u4e3a 2 \u7684\u7ed3\u70b9\uff0c\n\u503c\u5206\u522b\u4e3a 7\uff0c4\uff0c\u4ee5\u53ca 1\n\n\"\"\n\n\u6ce8\u610f\uff0c\u8f93\u5165\u7684 "root" \u548c "target" \u5b9e\u9645\u4e0a\u662f\u6811\u4e0a\u7684\u7ed3\u70b9\u3002\n\u4e0a\u9762\u7684\u8f93\u5165\u4ec5\u4ec5\u662f\u5bf9\u8fd9\u4e9b\u5bf9\u8c61\u8fdb\u884c\u4e86\u5e8f\u5217\u5316\u63cf\u8ff0\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. \u7ed9\u5b9a\u7684\u6811\u662f\u975e\u7a7a\u7684\u3002
  2. \n\t
  3. \u6811\u4e0a\u7684\u6bcf\u4e2a\u7ed3\u70b9\u90fd\u5177\u6709\u552f\u4e00\u7684\u503c 0 <= node.val <= 500 \u3002
  4. \n\t
  5. \u76ee\u6807\u7ed3\u70b9 target \u662f\u6811\u4e0a\u7684\u7ed3\u70b9\u3002
  6. \n\t
  7. 0 <= K <= 1000.
  8. \n
\n", "tags_en": ["Tree", "Depth-first Search", "Breadth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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 */\nclass Solution {\npublic:\n vector distanceK(TreeNode* root, TreeNode* target, int k) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode(int x) { val = x; }\n * }\n */\nclass Solution {\n public List distanceK(TreeNode root, TreeNode target, int k) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution(object):\n def distanceK(self, root, target, k):\n \"\"\"\n :type root: TreeNode\n :type target: TreeNode\n :type k: int\n :rtype: List[int]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution:\n def distanceK(self, root: TreeNode, target: TreeNode, k: int) -> List[int]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* distanceK(struct TreeNode* root, struct TreeNode* target, int k, int* returnSize) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int x) { val = x; }\n * }\n */\npublic class Solution {\n public IList DistanceK(TreeNode root, TreeNode target, int k) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val) {\n * this.val = val;\n * this.left = this.right = null;\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {TreeNode} target\n * @param {number} k\n * @return {number[]}\n */\nvar distanceK = function(root, target, k) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val)\n# @val = val\n# @left, @right = nil, nil\n# end\n# end\n# @param {TreeNode} root\n# @param {TreeNode} target\n# @param {Integer} k\n# @return {Integer[]}\ndef distance_k(root, target, k)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.left = nil\n * self.right = nil\n * }\n * }\n */\nclass Solution {\n func distanceK(_ root: TreeNode?, _ target: TreeNode?, _ k: Int) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc distanceK(root *TreeNode, target *TreeNode, k int) []int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(var _value: Int) {\n * var value: Int = _value\n * var left: TreeNode = null\n * var right: TreeNode = null\n * }\n */\nobject Solution {\n def distanceK(root: TreeNode, target: TreeNode, k: Int): List[Int] = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int = 0) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun distanceK(root: TreeNode?, target: TreeNode?, k: Int): List {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n// \n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn distance_k(root: Option>>, target: Option>>, k: i32) -> Vec {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($value) { $this->val = $value; }\n * }\n */\nclass Solution {\n /**\n * @param TreeNode $root\n * @param TreeNode $target\n * @param Integer $k\n * @return Integer[]\n */\n function distanceK($root, $target, $k) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction distanceK(root: TreeNode | null, target: TreeNode | null, k: number): number[] {\n \n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0863](https://leetcode-cn.com/problems/all-nodes-distance-k-in-binary-tree)", "[\u4e8c\u53c9\u6811\u4e2d\u6240\u6709\u8ddd\u79bb\u4e3a K \u7684\u7ed3\u70b9](/solution/0800-0899/0863.All%20Nodes%20Distance%20K%20in%20Binary%20Tree/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0863](https://leetcode.com/problems/all-nodes-distance-k-in-binary-tree)", "[All Nodes Distance K in Binary Tree](/solution/0800-0899/0863.All%20Nodes%20Distance%20K%20in%20Binary%20Tree/README_EN.md)", "`Tree`,`Depth-first Search`,`Breadth-first Search`", "Medium", ""]}, {"question_id": "0892", "frontend_question_id": "0862", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/shortest-subarray-with-sum-at-least-k", "url_en": "https://leetcode.com/problems/shortest-subarray-with-sum-at-least-k", "relative_path_cn": "/solution/0800-0899/0862.Shortest%20Subarray%20with%20Sum%20at%20Least%20K/README.md", "relative_path_en": "/solution/0800-0899/0862.Shortest%20Subarray%20with%20Sum%20at%20Least%20K/README_EN.md", "title_cn": "\u548c\u81f3\u5c11\u4e3a K \u7684\u6700\u77ed\u5b50\u6570\u7ec4", "title_en": "Shortest Subarray with Sum at Least K", "question_title_slug": "shortest-subarray-with-sum-at-least-k", "content_en": "

Return the length of the shortest, non-empty, contiguous subarray of nums with sum at least k.

\n\n

If there is no non-empty subarray with sum at least k, return -1.

\n\n

 

\n\n
    \n
\n\n
\n

Example 1:

\n\n
\nInput: nums = [1], k = 1\nOutput: 1\n
\n\n
\n

Example 2:

\n\n
\nInput: nums = [1,2], k = 4\nOutput: -1\n
\n\n
\n

Example 3:

\n\n
\nInput: nums = [2,-1,2], k = 3\nOutput: 3\n
\n\n

 

\n\n

Note:

\n\n
    \n\t
  1. 1 <= nums.length <= 50000
  2. \n\t
  3. -105 <= nums[i] <= 105
  4. \n\t
  5. 1 <= k <= 109
  6. \n
\n
\n
\n
\n", "content_cn": "

\u8fd4\u56de A \u7684\u6700\u77ed\u7684\u975e\u7a7a\u8fde\u7eed\u5b50\u6570\u7ec4\u7684\u957f\u5ea6\uff0c\u8be5\u5b50\u6570\u7ec4\u7684\u548c\u81f3\u5c11\u4e3a K \u3002

\n\n

\u5982\u679c\u6ca1\u6709\u548c\u81f3\u5c11\u4e3a K \u7684\u975e\u7a7a\u5b50\u6570\u7ec4\uff0c\u8fd4\u56de -1 \u3002

\n\n

 

\n\n
    \n
\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aA = [1], K = 1\n\u8f93\u51fa\uff1a1\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aA = [1,2], K = 4\n\u8f93\u51fa\uff1a-1\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aA = [2,-1,2], K = 3\n\u8f93\u51fa\uff1a3\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= A.length <= 50000
  2. \n\t
  3. -10 ^ 5 <= A[i] <= 10 ^ 5
  4. \n\t
  5. 1 <= K <= 10 ^ 9
  6. \n
\n", "tags_en": ["Queue", "Binary Search"], "tags_cn": ["\u961f\u5217", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int shortestSubarray(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int shortestSubarray(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def shortestSubarray(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def shortestSubarray(self, nums: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint shortestSubarray(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ShortestSubarray(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar shortestSubarray = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef shortest_subarray(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func shortestSubarray(_ nums: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func shortestSubarray(nums []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def shortestSubarray(nums: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun shortestSubarray(nums: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn shortest_subarray(nums: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer\n */\n function shortestSubarray($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function shortestSubarray(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (shortest-subarray nums k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0862](https://leetcode-cn.com/problems/shortest-subarray-with-sum-at-least-k)", "[\u548c\u81f3\u5c11\u4e3a K \u7684\u6700\u77ed\u5b50\u6570\u7ec4](/solution/0800-0899/0862.Shortest%20Subarray%20with%20Sum%20at%20Least%20K/README.md)", "`\u961f\u5217`,`\u4e8c\u5206\u67e5\u627e`", "\u56f0\u96be", ""], "md_table_row_en": ["[0862](https://leetcode.com/problems/shortest-subarray-with-sum-at-least-k)", "[Shortest Subarray with Sum at Least K](/solution/0800-0899/0862.Shortest%20Subarray%20with%20Sum%20at%20Least%20K/README_EN.md)", "`Queue`,`Binary Search`", "Hard", ""]}, {"question_id": "0891", "frontend_question_id": "0861", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/score-after-flipping-matrix", "url_en": "https://leetcode.com/problems/score-after-flipping-matrix", "relative_path_cn": "/solution/0800-0899/0861.Score%20After%20Flipping%20Matrix/README.md", "relative_path_en": "/solution/0800-0899/0861.Score%20After%20Flipping%20Matrix/README_EN.md", "title_cn": "\u7ffb\u8f6c\u77e9\u9635\u540e\u7684\u5f97\u5206", "title_en": "Score After Flipping Matrix", "question_title_slug": "score-after-flipping-matrix", "content_en": "

We have a two dimensional matrix grid where each value is 0 or 1.

\n\n

A move consists of choosing any row or column, and toggling each value in that row or column: changing all 0s to 1s, and all 1s to 0s.

\n\n

After making any number of moves, every row of this matrix is interpreted as a binary number, and the score of the matrix is the sum of these numbers.

\n\n

Return the highest possible score.

\n\n

 

\n\n
    \n
\n\n
\n

Example 1:

\n\n
\nInput: grid = [[0,0,1,1],[1,0,1,0],[1,1,0,0]]\nOutput: 39\nExplanation:\nToggled to [[1,1,1,1],[1,0,0,1],[1,1,1,1]].\n0b1111 + 0b1001 + 0b1111 = 15 + 9 + 15 = 39
\n\n

 

\n\n

Note:

\n\n
    \n\t
  1. 1 <= grid.length <= 20
  2. \n\t
  3. 1 <= grid[0].length <= 20
  4. \n\t
  5. grid[i][j] is 0 or 1.
  6. \n
\n
\n", "content_cn": "

\u6709\u4e00\u4e2a\u4e8c\u7ef4\u77e9\u9635 A \u5176\u4e2d\u6bcf\u4e2a\u5143\u7d20\u7684\u503c\u4e3a 0 \u6216 1 \u3002

\n\n

\u79fb\u52a8\u662f\u6307\u9009\u62e9\u4efb\u4e00\u884c\u6216\u5217\uff0c\u5e76\u8f6c\u6362\u8be5\u884c\u6216\u5217\u4e2d\u7684\u6bcf\u4e00\u4e2a\u503c\uff1a\u5c06\u6240\u6709 0 \u90fd\u66f4\u6539\u4e3a 1\uff0c\u5c06\u6240\u6709 1 \u90fd\u66f4\u6539\u4e3a 0\u3002

\n\n

\u5728\u505a\u51fa\u4efb\u610f\u6b21\u6570\u7684\u79fb\u52a8\u540e\uff0c\u5c06\u8be5\u77e9\u9635\u7684\u6bcf\u4e00\u884c\u90fd\u6309\u7167\u4e8c\u8fdb\u5236\u6570\u6765\u89e3\u91ca\uff0c\u77e9\u9635\u7684\u5f97\u5206\u5c31\u662f\u8fd9\u4e9b\u6570\u5b57\u7684\u603b\u548c\u3002

\n\n

\u8fd4\u56de\u5c3d\u53ef\u80fd\u9ad8\u7684\u5206\u6570\u3002

\n\n

 

\n\n
    \n
\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1a[[0,0,1,1],[1,0,1,0],[1,1,0,0]]\n\u8f93\u51fa\uff1a39\n\u89e3\u91ca\uff1a\n\u8f6c\u6362\u4e3a [[1,1,1,1],[1,0,0,1],[1,1,1,1]]\n0b1111 + 0b1001 + 0b1111 = 15 + 9 + 15 = 39
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= A.length <= 20
  2. \n\t
  3. 1 <= A[0].length <= 20
  4. \n\t
  5. A[i][j] \u662f 0 \u6216 1
  6. \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int matrixScore(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int matrixScore(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def matrixScore(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def matrixScore(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint matrixScore(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MatrixScore(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar matrixScore = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef matrix_score(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func matrixScore(_ grid: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func matrixScore(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def matrixScore(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun matrixScore(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn matrix_score(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function matrixScore($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function matrixScore(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (matrix-score grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0861](https://leetcode-cn.com/problems/score-after-flipping-matrix)", "[\u7ffb\u8f6c\u77e9\u9635\u540e\u7684\u5f97\u5206](/solution/0800-0899/0861.Score%20After%20Flipping%20Matrix/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0861](https://leetcode.com/problems/score-after-flipping-matrix)", "[Score After Flipping Matrix](/solution/0800-0899/0861.Score%20After%20Flipping%20Matrix/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "0890", "frontend_question_id": "0860", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/lemonade-change", "url_en": "https://leetcode.com/problems/lemonade-change", "relative_path_cn": "/solution/0800-0899/0860.Lemonade%20Change/README.md", "relative_path_en": "/solution/0800-0899/0860.Lemonade%20Change/README_EN.md", "title_cn": "\u67e0\u6aac\u6c34\u627e\u96f6", "title_en": "Lemonade Change", "question_title_slug": "lemonade-change", "content_en": "

At a lemonade stand, each lemonade costs $5

\r\n\r\n

Customers are standing in a queue to buy from you, and order one at a time (in the order specified by bills).

\r\n\r\n

Each customer will only buy one lemonade and pay with either a $5, $10, or $20 bill.  You must provide the correct change to each customer, so that the net transaction is that the customer pays $5.

\r\n\r\n

Note that you don't have any change in hand at first.

\r\n\r\n

Return true if and only if you can provide every customer with correct change.

\r\n\r\n

 

\r\n\r\n
\r\n

Example 1:

\r\n\r\n
\r\nInput: [5,5,5,10,20]\r\nOutput: true\r\nExplanation: \r\nFrom the first 3 customers, we collect three $5 bills in order.\r\nFrom the fourth customer, we collect a $10 bill and give back a $5.\r\nFrom the fifth customer, we give a $10 bill and a $5 bill.\r\nSince all customers got correct change, we output true.\r\n
\r\n\r\n
\r\n

Example 2:

\r\n\r\n
\r\nInput: [5,5,10]\r\nOutput: true\r\n
\r\n\r\n
\r\n

Example 3:

\r\n\r\n
\r\nInput: [10,10]\r\nOutput: false\r\n
\r\n\r\n
\r\n

Example 4:

\r\n\r\n
\r\nInput: [5,5,10,10,20]\r\nOutput: false\r\nExplanation: \r\nFrom the first two customers in order, we collect two $5 bills.\r\nFor the next two customers in order, we collect a $10 bill and give back a $5 bill.\r\nFor the last customer, we can't give change of $15 back because we only have two $10 bills.\r\nSince not every customer received correct change, the answer is false.\r\n
\r\n\r\n

 

\r\n\r\n

Note:

\r\n\r\n
    \r\n\t
  • 0 <= bills.length <= 10000
  • \r\n\t
  • bills[i] will be either 5, 10, or 20.
  • \r\n
\r\n
\r\n
\r\n
\r\n
\r\n", "content_cn": "

\u5728\u67e0\u6aac\u6c34\u644a\u4e0a\uff0c\u6bcf\u4e00\u676f\u67e0\u6aac\u6c34\u7684\u552e\u4ef7\u4e3a 5 \u7f8e\u5143\u3002

\n\n

\u987e\u5ba2\u6392\u961f\u8d2d\u4e70\u4f60\u7684\u4ea7\u54c1\uff0c\uff08\u6309\u8d26\u5355 bills \u652f\u4ed8\u7684\u987a\u5e8f\uff09\u4e00\u6b21\u8d2d\u4e70\u4e00\u676f\u3002

\n\n

\u6bcf\u4f4d\u987e\u5ba2\u53ea\u4e70\u4e00\u676f\u67e0\u6aac\u6c34\uff0c\u7136\u540e\u5411\u4f60\u4ed8 5 \u7f8e\u5143\u300110 \u7f8e\u5143\u6216 20 \u7f8e\u5143\u3002\u4f60\u5fc5\u987b\u7ed9\u6bcf\u4e2a\u987e\u5ba2\u6b63\u786e\u627e\u96f6\uff0c\u4e5f\u5c31\u662f\u8bf4\u51c0\u4ea4\u6613\u662f\u6bcf\u4f4d\u987e\u5ba2\u5411\u4f60\u652f\u4ed8 5 \u7f8e\u5143\u3002

\n\n

\u6ce8\u610f\uff0c\u4e00\u5f00\u59cb\u4f60\u624b\u5934\u6ca1\u6709\u4efb\u4f55\u96f6\u94b1\u3002

\n\n

\u5982\u679c\u4f60\u80fd\u7ed9\u6bcf\u4f4d\u987e\u5ba2\u6b63\u786e\u627e\u96f6\uff0c\u8fd4\u56de true \uff0c\u5426\u5219\u8fd4\u56de false \u3002

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a[5,5,5,10,20]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\n\u524d 3 \u4f4d\u987e\u5ba2\u90a3\u91cc\uff0c\u6211\u4eec\u6309\u987a\u5e8f\u6536\u53d6 3 \u5f20 5 \u7f8e\u5143\u7684\u949e\u7968\u3002\n\u7b2c 4 \u4f4d\u987e\u5ba2\u90a3\u91cc\uff0c\u6211\u4eec\u6536\u53d6\u4e00\u5f20 10 \u7f8e\u5143\u7684\u949e\u7968\uff0c\u5e76\u8fd4\u8fd8 5 \u7f8e\u5143\u3002\n\u7b2c 5 \u4f4d\u987e\u5ba2\u90a3\u91cc\uff0c\u6211\u4eec\u627e\u8fd8\u4e00\u5f20 10 \u7f8e\u5143\u7684\u949e\u7968\u548c\u4e00\u5f20 5 \u7f8e\u5143\u7684\u949e\u7968\u3002\n\u7531\u4e8e\u6240\u6709\u5ba2\u6237\u90fd\u5f97\u5230\u4e86\u6b63\u786e\u7684\u627e\u96f6\uff0c\u6240\u4ee5\u6211\u4eec\u8f93\u51fa true\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a[5,5,10]\n\u8f93\u51fa\uff1atrue\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1a[10,10]\n\u8f93\u51fa\uff1afalse\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1a[5,5,10,10,20]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\n\u524d 2 \u4f4d\u987e\u5ba2\u90a3\u91cc\uff0c\u6211\u4eec\u6309\u987a\u5e8f\u6536\u53d6 2 \u5f20 5 \u7f8e\u5143\u7684\u949e\u7968\u3002\n\u5bf9\u4e8e\u63a5\u4e0b\u6765\u7684 2 \u4f4d\u987e\u5ba2\uff0c\u6211\u4eec\u6536\u53d6\u4e00\u5f20 10 \u7f8e\u5143\u7684\u949e\u7968\uff0c\u7136\u540e\u8fd4\u8fd8 5 \u7f8e\u5143\u3002\n\u5bf9\u4e8e\u6700\u540e\u4e00\u4f4d\u987e\u5ba2\uff0c\u6211\u4eec\u65e0\u6cd5\u9000\u56de 15 \u7f8e\u5143\uff0c\u56e0\u4e3a\u6211\u4eec\u73b0\u5728\u53ea\u6709\u4e24\u5f20 10 \u7f8e\u5143\u7684\u949e\u7968\u3002\n\u7531\u4e8e\u4e0d\u662f\u6bcf\u4f4d\u987e\u5ba2\u90fd\u5f97\u5230\u4e86\u6b63\u786e\u7684\u627e\u96f6\uff0c\u6240\u4ee5\u7b54\u6848\u662f false\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 0 <= bills.length <= 10000
  • \n\t
  • bills[i] \u4e0d\u662f 5 \u5c31\u662f 10 \u6216\u662f 20 
  • \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool lemonadeChange(vector& bills) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean lemonadeChange(int[] bills) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def lemonadeChange(self, bills):\n \"\"\"\n :type bills: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def lemonadeChange(self, bills: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool lemonadeChange(int* bills, int billsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool LemonadeChange(int[] bills) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} bills\n * @return {boolean}\n */\nvar lemonadeChange = function(bills) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} bills\n# @return {Boolean}\ndef lemonade_change(bills)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func lemonadeChange(_ bills: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func lemonadeChange(bills []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def lemonadeChange(bills: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun lemonadeChange(bills: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn lemonade_change(bills: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $bills\n * @return Boolean\n */\n function lemonadeChange($bills) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function lemonadeChange(bills: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (lemonade-change bills)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0860](https://leetcode-cn.com/problems/lemonade-change)", "[\u67e0\u6aac\u6c34\u627e\u96f6](/solution/0800-0899/0860.Lemonade%20Change/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u7b80\u5355", ""], "md_table_row_en": ["[0860](https://leetcode.com/problems/lemonade-change)", "[Lemonade Change](/solution/0800-0899/0860.Lemonade%20Change/README_EN.md)", "`Greedy`", "Easy", ""]}, {"question_id": "0889", "frontend_question_id": "0859", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/buddy-strings", "url_en": "https://leetcode.com/problems/buddy-strings", "relative_path_cn": "/solution/0800-0899/0859.Buddy%20Strings/README.md", "relative_path_en": "/solution/0800-0899/0859.Buddy%20Strings/README_EN.md", "title_cn": "\u4eb2\u5bc6\u5b57\u7b26\u4e32", "title_en": "Buddy Strings", "question_title_slug": "buddy-strings", "content_en": "

Given two strings s and goal, return true if you can swap two letters in s so the result is equal to goal, otherwise, return false.

\n\n

Swapping letters is defined as taking two indices i and j (0-indexed) such that i != j and swapping the characters at s[i] and s[j].

\n\n
    \n\t
  • For example, swapping at indices 0 and 2 in "abcd" results in "cbad".
  • \n
\n\n

 

\n

Example 1:

\n\n
\nInput: s = "ab", goal = "ba"\nOutput: true\nExplanation: You can swap s[0] = 'a' and s[1] = 'b' to get "ba", which is equal to goal.\n
\n\n

Example 2:

\n\n
\nInput: s = "ab", goal = "ab"\nOutput: false\nExplanation: The only letters you can swap are s[0] = 'a' and s[1] = 'b', which results in "ba" != goal.\n
\n\n

Example 3:

\n\n
\nInput: s = "aa", goal = "aa"\nOutput: true\nExplanation: You can swap s[0] = 'a' and s[1] = 'a' to get "aa", which is equal to goal.\n
\n\n

Example 4:

\n\n
\nInput: s = "aaaaaaabc", goal = "aaaaaaacb"\nOutput: true\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length, goal.length <= 2 * 104
  • \n\t
  • s and goal consist of lowercase letters.
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e24\u4e2a\u7531\u5c0f\u5199\u5b57\u6bcd\u6784\u6210\u7684\u5b57\u7b26\u4e32\u00a0A\u00a0\u548c\u00a0B\u00a0\uff0c\u53ea\u8981\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4ea4\u6362 A \u4e2d\u7684\u4e24\u4e2a\u5b57\u6bcd\u5f97\u5230\u4e0e B \u76f8\u7b49\u7684\u7ed3\u679c\uff0c\u5c31\u8fd4\u56de\u00a0true\u00a0\uff1b\u5426\u5219\u8fd4\u56de false \u3002

\n\n

\u4ea4\u6362\u5b57\u6bcd\u7684\u5b9a\u4e49\u662f\u53d6\u4e24\u4e2a\u4e0b\u6807 i \u548c j \uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\uff0c\u53ea\u8981 i!=j \u5c31\u4ea4\u6362 A[i] \u548c A[j] \u5904\u7684\u5b57\u7b26\u3002\u4f8b\u5982\uff0c\u5728 \"abcd\" \u4e2d\u4ea4\u6362\u4e0b\u6807 0 \u548c\u4e0b\u6807 2 \u7684\u5143\u7d20\u53ef\u4ee5\u751f\u6210 \"cbad\" \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1a A = \"ab\", B = \"ba\"\n\u8f93\u51fa\uff1a true\n\u89e3\u91ca\uff1a \u4f60\u53ef\u4ee5\u4ea4\u6362 A[0] = 'a' \u548c A[1] = 'b' \u751f\u6210 \"ba\"\uff0c\u6b64\u65f6 A \u548c B \u76f8\u7b49\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1a A = \"ab\", B = \"ab\"\n\u8f93\u51fa\uff1a false\n\u89e3\u91ca\uff1a \u4f60\u53ea\u80fd\u4ea4\u6362 A[0] = 'a' \u548c A[1] = 'b' \u751f\u6210 \"ba\"\uff0c\u6b64\u65f6 A \u548c B \u4e0d\u76f8\u7b49\u3002\n
\n\n

\u793a\u4f8b 3:

\n\n
\n\u8f93\u5165\uff1a A = \"aa\", B = \"aa\"\n\u8f93\u51fa\uff1a true\n\u89e3\u91ca\uff1a \u4f60\u53ef\u4ee5\u4ea4\u6362 A[0] = 'a' \u548c A[1] = 'a' \u751f\u6210 \"aa\"\uff0c\u6b64\u65f6 A \u548c B \u76f8\u7b49\u3002
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1a A = \"aaaaaaabc\", B = \"aaaaaaacb\"\n\u8f93\u51fa\uff1a true\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\n\u8f93\u5165\uff1a A = \"\", B = \"aa\"\n\u8f93\u51fa\uff1a false\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 0 <= A.length <= 20000
  2. \n\t
  3. 0 <= B.length <= 20000
  4. \n\t
  5. A\u00a0\u548c\u00a0B\u00a0\u4ec5\u7531\u5c0f\u5199\u5b57\u6bcd\u6784\u6210\u3002
  6. \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool buddyStrings(string s, string goal) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean buddyStrings(String s, String goal) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def buddyStrings(self, s, goal):\n \"\"\"\n :type s: str\n :type goal: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def buddyStrings(self, s: str, goal: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool buddyStrings(char * s, char * goal){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool BuddyStrings(string s, string goal) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string} goal\n * @return {boolean}\n */\nvar buddyStrings = function(s, goal) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String} goal\n# @return {Boolean}\ndef buddy_strings(s, goal)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func buddyStrings(_ s: String, _ goal: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func buddyStrings(s string, goal string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def buddyStrings(s: String, goal: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun buddyStrings(s: String, goal: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn buddy_strings(s: String, goal: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String $goal\n * @return Boolean\n */\n function buddyStrings($s, $goal) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function buddyStrings(s: string, goal: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (buddy-strings s goal)\n (-> string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0859](https://leetcode-cn.com/problems/buddy-strings)", "[\u4eb2\u5bc6\u5b57\u7b26\u4e32](/solution/0800-0899/0859.Buddy%20Strings/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0859](https://leetcode.com/problems/buddy-strings)", "[Buddy Strings](/solution/0800-0899/0859.Buddy%20Strings/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "0888", "frontend_question_id": "0858", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/mirror-reflection", "url_en": "https://leetcode.com/problems/mirror-reflection", "relative_path_cn": "/solution/0800-0899/0858.Mirror%20Reflection/README.md", "relative_path_en": "/solution/0800-0899/0858.Mirror%20Reflection/README_EN.md", "title_cn": "\u955c\u9762\u53cd\u5c04", "title_en": "Mirror Reflection", "question_title_slug": "mirror-reflection", "content_en": "

There is a special square room with mirrors on each of the four walls.  Except for the southwest corner, there are receptors on each of the remaining corners, numbered 0, 1, and 2.

\n\n

The square room has walls of length p, and a laser ray from the southwest corner first meets the east wall at a distance q from the 0th receptor.

\n\n

Return the number of the receptor that the ray meets first.  (It is guaranteed that the ray will meet a receptor eventually.)

\n\n

 

\n\n
\n

Example 1:

\n\n
\nInput: p = 2, q = 1\nOutput: 2\nExplanation: The ray meets receptor 2 the first time it gets reflected back to the left wall.\n\"\"\n
\n\n

Note:

\n\n
    \n\t
  1. 1 <= p <= 1000
  2. \n\t
  3. 0 <= q <= p
  4. \n
\n
\n", "content_cn": "

\u6709\u4e00\u4e2a\u7279\u6b8a\u7684\u6b63\u65b9\u5f62\u623f\u95f4\uff0c\u6bcf\u9762\u5899\u4e0a\u90fd\u6709\u4e00\u9762\u955c\u5b50\u3002\u9664\u897f\u5357\u89d2\u4ee5\u5916\uff0c\u6bcf\u4e2a\u89d2\u843d\u90fd\u653e\u6709\u4e00\u4e2a\u63a5\u53d7\u5668\uff0c\u7f16\u53f7\u4e3a\u00a00\uff0c\u00a01\uff0c\u4ee5\u53ca\u00a02\u3002

\n\n

\u6b63\u65b9\u5f62\u623f\u95f4\u7684\u5899\u58c1\u957f\u5ea6\u4e3a\u00a0p\uff0c\u4e00\u675f\u6fc0\u5149\u4ece\u897f\u5357\u89d2\u5c04\u51fa\uff0c\u9996\u5148\u4f1a\u4e0e\u4e1c\u5899\u76f8\u9047\uff0c\u5165\u5c04\u70b9\u5230\u63a5\u6536\u5668 0 \u7684\u8ddd\u79bb\u4e3a q \u3002

\n\n

\u8fd4\u56de\u5149\u7ebf\u6700\u5148\u9047\u5230\u7684\u63a5\u6536\u5668\u7684\u7f16\u53f7\uff08\u4fdd\u8bc1\u5149\u7ebf\u6700\u7ec8\u4f1a\u9047\u5230\u4e00\u4e2a\u63a5\u6536\u5668\uff09\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b\uff1a

\n\n
\n\u8f93\u5165\uff1a p = 2, q = 1\n\u8f93\u51fa\uff1a 2\n\u89e3\u91ca\uff1a \u8fd9\u6761\u5149\u7ebf\u5728\u7b2c\u4e00\u6b21\u88ab\u53cd\u5c04\u56de\u5de6\u8fb9\u7684\u5899\u65f6\u5c31\u9047\u5230\u4e86\u63a5\u6536\u5668 2 \u3002\n\"\"
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= p <= 1000
  • \n\t
  • 0 <= q <= p
  • \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int mirrorReflection(int p, int q) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int mirrorReflection(int p, int q) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def mirrorReflection(self, p, q):\n \"\"\"\n :type p: int\n :type q: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def mirrorReflection(self, p: int, q: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint mirrorReflection(int p, int q){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MirrorReflection(int p, int q) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} p\n * @param {number} q\n * @return {number}\n */\nvar mirrorReflection = function(p, q) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} p\n# @param {Integer} q\n# @return {Integer}\ndef mirror_reflection(p, q)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func mirrorReflection(_ p: Int, _ q: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func mirrorReflection(p int, q int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def mirrorReflection(p: Int, q: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun mirrorReflection(p: Int, q: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn mirror_reflection(p: i32, q: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $p\n * @param Integer $q\n * @return Integer\n */\n function mirrorReflection($p, $q) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function mirrorReflection(p: number, q: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (mirror-reflection p q)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0858](https://leetcode-cn.com/problems/mirror-reflection)", "[\u955c\u9762\u53cd\u5c04](/solution/0800-0899/0858.Mirror%20Reflection/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0858](https://leetcode.com/problems/mirror-reflection)", "[Mirror Reflection](/solution/0800-0899/0858.Mirror%20Reflection/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "0887", "frontend_question_id": "0857", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-cost-to-hire-k-workers", "url_en": "https://leetcode.com/problems/minimum-cost-to-hire-k-workers", "relative_path_cn": "/solution/0800-0899/0857.Minimum%20Cost%20to%20Hire%20K%20Workers/README.md", "relative_path_en": "/solution/0800-0899/0857.Minimum%20Cost%20to%20Hire%20K%20Workers/README_EN.md", "title_cn": "\u96c7\u4f63 K \u540d\u5de5\u4eba\u7684\u6700\u4f4e\u6210\u672c", "title_en": "Minimum Cost to Hire K Workers", "question_title_slug": "minimum-cost-to-hire-k-workers", "content_en": "

There are n workers.  The i-th worker has a quality[i] and a minimum wage expectation wage[i].

\n\n

Now we want to hire exactly k workers to form a paid group.  When hiring a group of k workers, we must pay them according to the following rules:

\n\n
    \n\t
  1. Every worker in the paid group should be paid in the ratio of their quality compared to other workers in the paid group.
  2. \n\t
  3. Every worker in the paid group must be paid at least their minimum wage expectation.
  4. \n
\n\n

Return the least amount of money needed to form a paid group satisfying the above conditions.

\n\n

 

\n\n
    \n
\n\n
\n

Example 1:

\n\n
\nInput: quality = [10,20,5], wage = [70,50,30], k = 2\nOutput: 105.00000\nExplanation: We pay 70 to 0-th worker and 35 to 2-th worker.\n
\n\n
\n

Example 2:

\n\n
\nInput: quality = [3,1,10,10,1], wage = [4,8,2,2,7], k = 3\nOutput: 30.66667\nExplanation: We pay 4 to 0-th worker, 13.33333 to 2-th and 3-th workers seperately. \n
\n\n

 

\n\n

Note:

\n\n
    \n\t
  1. 1 <= k <= n <= 10000, where n = quality.length = wage.length
  2. \n\t
  3. 1 <= quality[i] <= 10000
  4. \n\t
  5. 1 <= wage[i] <= 10000
  6. \n\t
  7. Answers within 10-5 of the correct answer will be considered correct.
  8. \n
\n
\n
\n", "content_cn": "

\u6709 N \u540d\u5de5\u4eba\u3002 \u7b2c i \u540d\u5de5\u4eba\u7684\u5de5\u4f5c\u8d28\u91cf\u4e3a quality[i] \uff0c\u5176\u6700\u4f4e\u671f\u671b\u5de5\u8d44\u4e3a wage[i] \u3002

\n\n

\u73b0\u5728\u6211\u4eec\u60f3\u96c7\u4f63 K \u540d\u5de5\u4eba\u7ec4\u6210\u4e00\u4e2a\u5de5\u8d44\u7ec4\u3002\u5728\u96c7\u4f63 \u4e00\u7ec4 K \u540d\u5de5\u4eba\u65f6\uff0c\u6211\u4eec\u5fc5\u987b\u6309\u7167\u4e0b\u8ff0\u89c4\u5219\u5411\u4ed6\u4eec\u652f\u4ed8\u5de5\u8d44\uff1a

\n\n
    \n\t
  1. \u5bf9\u5de5\u8d44\u7ec4\u4e2d\u7684\u6bcf\u540d\u5de5\u4eba\uff0c\u5e94\u5f53\u6309\u5176\u5de5\u4f5c\u8d28\u91cf\u4e0e\u540c\u7ec4\u5176\u4ed6\u5de5\u4eba\u7684\u5de5\u4f5c\u8d28\u91cf\u7684\u6bd4\u4f8b\u6765\u652f\u4ed8\u5de5\u8d44\u3002
  2. \n\t
  3. \u5de5\u8d44\u7ec4\u4e2d\u7684\u6bcf\u540d\u5de5\u4eba\u81f3\u5c11\u5e94\u5f53\u5f97\u5230\u4ed6\u4eec\u7684\u6700\u4f4e\u671f\u671b\u5de5\u8d44\u3002
  4. \n
\n\n

\u8fd4\u56de\u7ec4\u6210\u4e00\u4e2a\u6ee1\u8db3\u4e0a\u8ff0\u6761\u4ef6\u7684\u5de5\u8d44\u7ec4\u81f3\u5c11\u9700\u8981\u591a\u5c11\u94b1\u3002

\n\n

 

\n\n
    \n
\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a quality = [10,20,5], wage = [70,50,30], K = 2\n\u8f93\u51fa\uff1a 105.00000\n\u89e3\u91ca\uff1a \u6211\u4eec\u5411 0 \u53f7\u5de5\u4eba\u652f\u4ed8 70\uff0c\u5411 2 \u53f7\u5de5\u4eba\u652f\u4ed8 35\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a quality = [3,1,10,10,1], wage = [4,8,2,2,7], K = 3\n\u8f93\u51fa\uff1a 30.66667\n\u89e3\u91ca\uff1a \u6211\u4eec\u5411 0 \u53f7\u5de5\u4eba\u652f\u4ed8 4\uff0c\u5411 2 \u53f7\u548c 3 \u53f7\u5206\u522b\u652f\u4ed8 13.33333\u3002
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= K <= N <= 10000\uff0c\u5176\u4e2d N = quality.length = wage.length
  2. \n\t
  3. 1 <= quality[i] <= 10000
  4. \n\t
  5. 1 <= wage[i] <= 10000
  6. \n\t
  7. \u4e0e\u6b63\u786e\u7b54\u6848\u8bef\u5dee\u5728 10^-5 \u4e4b\u5185\u7684\u7b54\u6848\u5c06\u88ab\u89c6\u4e3a\u6b63\u786e\u7684\u3002
  8. \n
\n", "tags_en": ["Heap"], "tags_cn": ["\u5806"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n double mincostToHireWorkers(vector& quality, vector& wage, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double mincostToHireWorkers(int[] quality, int[] wage, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def mincostToHireWorkers(self, quality, wage, k):\n \"\"\"\n :type quality: List[int]\n :type wage: List[int]\n :type k: int\n :rtype: float\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def mincostToHireWorkers(self, quality: List[int], wage: List[int], k: int) -> float:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\ndouble mincostToHireWorkers(int* quality, int qualitySize, int* wage, int wageSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double MincostToHireWorkers(int[] quality, int[] wage, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} quality\n * @param {number[]} wage\n * @param {number} k\n * @return {number}\n */\nvar mincostToHireWorkers = function(quality, wage, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} quality\n# @param {Integer[]} wage\n# @param {Integer} k\n# @return {Float}\ndef mincost_to_hire_workers(quality, wage, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func mincostToHireWorkers(_ quality: [Int], _ wage: [Int], _ k: Int) -> Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func mincostToHireWorkers(quality []int, wage []int, k int) float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def mincostToHireWorkers(quality: Array[Int], wage: Array[Int], k: Int): Double = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun mincostToHireWorkers(quality: IntArray, wage: IntArray, k: Int): Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn mincost_to_hire_workers(quality: Vec, wage: Vec, k: i32) -> f64 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $quality\n * @param Integer[] $wage\n * @param Integer $k\n * @return Float\n */\n function mincostToHireWorkers($quality, $wage, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function mincostToHireWorkers(quality: number[], wage: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (mincost-to-hire-workers quality wage k)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer? flonum?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0857](https://leetcode-cn.com/problems/minimum-cost-to-hire-k-workers)", "[\u96c7\u4f63 K \u540d\u5de5\u4eba\u7684\u6700\u4f4e\u6210\u672c](/solution/0800-0899/0857.Minimum%20Cost%20to%20Hire%20K%20Workers/README.md)", "`\u5806`", "\u56f0\u96be", ""], "md_table_row_en": ["[0857](https://leetcode.com/problems/minimum-cost-to-hire-k-workers)", "[Minimum Cost to Hire K Workers](/solution/0800-0899/0857.Minimum%20Cost%20to%20Hire%20K%20Workers/README_EN.md)", "`Heap`", "Hard", ""]}, {"question_id": "0886", "frontend_question_id": "0856", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/score-of-parentheses", "url_en": "https://leetcode.com/problems/score-of-parentheses", "relative_path_cn": "/solution/0800-0899/0856.Score%20of%20Parentheses/README.md", "relative_path_en": "/solution/0800-0899/0856.Score%20of%20Parentheses/README_EN.md", "title_cn": "\u62ec\u53f7\u7684\u5206\u6570", "title_en": "Score of Parentheses", "question_title_slug": "score-of-parentheses", "content_en": "

Given a balanced parentheses string s, compute the score of the string based on the following rule:

\n\n
    \n\t
  • () has score 1
  • \n\t
  • AB has score A + B, where A and B are balanced parentheses strings.
  • \n\t
  • (A) has score 2 * A, where A is a balanced parentheses string.
  • \n
\n\n

 

\n\n

Example 1:

\n\n
\nInput: s = "()"\nOutput: 1\n
\n\n

Example 2:

\n\n
\nInput: s = "(())"\nOutput: 2\n
\n\n

Example 3:

\n\n
\nInput: s = "()()"\nOutput: 2\n
\n\n

Example 4:

\n\n
\nInput: s = "(()(()))"\nOutput: 6\n
\n\n

 

\n\n

Note:

\n\n
    \n\t
  1. s is a balanced parentheses string, containing only ( and ).
  2. \n\t
  3. 2 <= s.length <= 50
  4. \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u5e73\u8861\u62ec\u53f7\u5b57\u7b26\u4e32 S\uff0c\u6309\u4e0b\u8ff0\u89c4\u5219\u8ba1\u7b97\u8be5\u5b57\u7b26\u4e32\u7684\u5206\u6570\uff1a

\n\n
    \n\t
  • () \u5f97 1 \u5206\u3002
  • \n\t
  • AB \u5f97 A + B \u5206\uff0c\u5176\u4e2d A \u548c B \u662f\u5e73\u8861\u62ec\u53f7\u5b57\u7b26\u4e32\u3002
  • \n\t
  • (A) \u5f97 2 * A \u5206\uff0c\u5176\u4e2d A \u662f\u5e73\u8861\u62ec\u53f7\u5b57\u7b26\u4e32\u3002
  • \n
\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a "()"\n\u8f93\u51fa\uff1a 1\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a "(())"\n\u8f93\u51fa\uff1a 2\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1a "()()"\n\u8f93\u51fa\uff1a 2\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1a "(()(()))"\n\u8f93\u51fa\uff1a 6\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. S \u662f\u5e73\u8861\u62ec\u53f7\u5b57\u7b26\u4e32\uff0c\u4e14\u53ea\u542b\u6709 ( \u548c ) \u3002
  2. \n\t
  3. 2 <= S.length <= 50
  4. \n
\n", "tags_en": ["Stack", "String"], "tags_cn": ["\u6808", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int scoreOfParentheses(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int scoreOfParentheses(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def scoreOfParentheses(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def scoreOfParentheses(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint scoreOfParentheses(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ScoreOfParentheses(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar scoreOfParentheses = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef score_of_parentheses(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func scoreOfParentheses(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func scoreOfParentheses(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def scoreOfParentheses(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun scoreOfParentheses(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn score_of_parentheses(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function scoreOfParentheses($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function scoreOfParentheses(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (score-of-parentheses s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0856](https://leetcode-cn.com/problems/score-of-parentheses)", "[\u62ec\u53f7\u7684\u5206\u6570](/solution/0800-0899/0856.Score%20of%20Parentheses/README.md)", "`\u6808`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0856](https://leetcode.com/problems/score-of-parentheses)", "[Score of Parentheses](/solution/0800-0899/0856.Score%20of%20Parentheses/README_EN.md)", "`Stack`,`String`", "Medium", ""]}, {"question_id": "0885", "frontend_question_id": "0855", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/exam-room", "url_en": "https://leetcode.com/problems/exam-room", "relative_path_cn": "/solution/0800-0899/0855.Exam%20Room/README.md", "relative_path_en": "/solution/0800-0899/0855.Exam%20Room/README_EN.md", "title_cn": "\u8003\u573a\u5c31\u5ea7", "title_en": "Exam Room", "question_title_slug": "exam-room", "content_en": "

In an exam room, there are n seats in a single row, numbered 0, 1, 2, ..., n-1.

\n\n

When a student enters the room, they must sit in the seat that maximizes the distance to the closest person.  If there are multiple such seats, they sit in the seat with the lowest number.  (Also, if no one is in the room, then the student sits at seat number 0.)

\n\n

Return a class ExamRoom(int n) that exposes two functions: ExamRoom.seat() returning an int representing what seat the student sat in, and ExamRoom.leave(int p) representing that the student in seat number p now leaves the room.  It is guaranteed that any calls to ExamRoom.leave(p) have a student sitting in seat p.

\n\n

 

\n\n

Example 1:

\n\n
\nInput: ["ExamRoom","seat","seat","seat","seat","leave","seat"], [[10],[],[],[],[],[4],[]]\nOutput: [null,0,9,4,2,null,5]\nExplanation:\nExamRoom(10) -> null\nseat() -> 0, no one is in the room, then the student sits at seat number 0.\nseat() -> 9, the student sits at the last seat number 9.\nseat() -> 4, the student sits at the last seat number 4.\nseat() -> 2, the student sits at the last seat number 2.\nleave(4) -> null\nseat() -> 5, the student sits at the last seat number 5.\n
\n\n

 

\n\n

Note:

\n\n
    \n\t
  1. 1 <= n <= 109
  2. \n\t
  3. ExamRoom.seat() and ExamRoom.leave() will be called at most 104 times across all test cases.
  4. \n\t
  5. Calls to ExamRoom.leave(p) are guaranteed to have a student currently sitting in seat number p.
  6. \n
\n", "content_cn": "

\u5728\u8003\u573a\u91cc\uff0c\u4e00\u6392\u6709 N \u4e2a\u5ea7\u4f4d\uff0c\u5206\u522b\u7f16\u53f7\u4e3a 0, 1, 2, ..., N-1 \u3002

\n\n

\u5f53\u5b66\u751f\u8fdb\u5165\u8003\u573a\u540e\uff0c\u4ed6\u5fc5\u987b\u5750\u5728\u80fd\u591f\u4f7f\u4ed6\u4e0e\u79bb\u4ed6\u6700\u8fd1\u7684\u4eba\u4e4b\u95f4\u7684\u8ddd\u79bb\u8fbe\u5230\u6700\u5927\u5316\u7684\u5ea7\u4f4d\u4e0a\u3002\u5982\u679c\u6709\u591a\u4e2a\u8fd9\u6837\u7684\u5ea7\u4f4d\uff0c\u4ed6\u4f1a\u5750\u5728\u7f16\u53f7\u6700\u5c0f\u7684\u5ea7\u4f4d\u4e0a\u3002(\u53e6\u5916\uff0c\u5982\u679c\u8003\u573a\u91cc\u6ca1\u6709\u4eba\uff0c\u90a3\u4e48\u5b66\u751f\u5c31\u5750\u5728 0 \u53f7\u5ea7\u4f4d\u4e0a\u3002)

\n\n

\u8fd4\u56de ExamRoom(int N) \u7c7b\uff0c\u5b83\u6709\u4e24\u4e2a\u516c\u5f00\u7684\u51fd\u6570\uff1a\u5176\u4e2d\uff0c\u51fd\u6570 ExamRoom.seat() \u4f1a\u8fd4\u56de\u4e00\u4e2a int \uff08\u6574\u578b\u6570\u636e\uff09\uff0c\u4ee3\u8868\u5b66\u751f\u5750\u7684\u4f4d\u7f6e\uff1b\u51fd\u6570 ExamRoom.leave(int p) \u4ee3\u8868\u5750\u5728\u5ea7\u4f4d p \u4e0a\u7684\u5b66\u751f\u73b0\u5728\u79bb\u5f00\u4e86\u8003\u573a\u3002\u6bcf\u6b21\u8c03\u7528 ExamRoom.leave(p) \u65f6\u90fd\u4fdd\u8bc1\u6709\u5b66\u751f\u5750\u5728\u5ea7\u4f4d p \u4e0a\u3002

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1a["ExamRoom","seat","seat","seat","seat","leave","seat"], [[10],[],[],[],[],[4],[]]\n\u8f93\u51fa\uff1a[null,0,9,4,2,null,5]\n\u89e3\u91ca\uff1a\nExamRoom(10) -> null\nseat() -> 0\uff0c\u6ca1\u6709\u4eba\u5728\u8003\u573a\u91cc\uff0c\u90a3\u4e48\u5b66\u751f\u5750\u5728 0 \u53f7\u5ea7\u4f4d\u4e0a\u3002\nseat() -> 9\uff0c\u5b66\u751f\u6700\u540e\u5750\u5728 9 \u53f7\u5ea7\u4f4d\u4e0a\u3002\nseat() -> 4\uff0c\u5b66\u751f\u6700\u540e\u5750\u5728 4 \u53f7\u5ea7\u4f4d\u4e0a\u3002\nseat() -> 2\uff0c\u5b66\u751f\u6700\u540e\u5750\u5728 2 \u53f7\u5ea7\u4f4d\u4e0a\u3002\nleave(4) -> null\nseat() -> 5\uff0c\u5b66\u751f\u6700\u540e\u5750\u5728 5 \u53f7\u5ea7\u4f4d\u4e0a\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= N <= 10^9
  2. \n\t
  3. \u5728\u6240\u6709\u7684\u6d4b\u8bd5\u6837\u4f8b\u4e2d ExamRoom.seat() \u548c ExamRoom.leave() \u6700\u591a\u88ab\u8c03\u7528 10^4 \u6b21\u3002
  4. \n\t
  5. \u4fdd\u8bc1\u5728\u8c03\u7528 ExamRoom.leave(p) \u65f6\u6709\u5b66\u751f\u6b63\u5750\u5728\u5ea7\u4f4d p \u4e0a\u3002
  6. \n
\n", "tags_en": ["Ordered Map"], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class ExamRoom {\npublic:\n ExamRoom(int n) {\n\n }\n \n int seat() {\n\n }\n \n void leave(int p) {\n\n }\n};\n\n/**\n * Your ExamRoom object will be instantiated and called as such:\n * ExamRoom* obj = new ExamRoom(n);\n * int param_1 = obj->seat();\n * obj->leave(p);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class ExamRoom {\n\n public ExamRoom(int n) {\n\n }\n \n public int seat() {\n\n }\n \n public void leave(int p) {\n\n }\n}\n\n/**\n * Your ExamRoom object will be instantiated and called as such:\n * ExamRoom obj = new ExamRoom(n);\n * int param_1 = obj.seat();\n * obj.leave(p);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class ExamRoom(object):\n\n def __init__(self, n):\n \"\"\"\n :type n: int\n \"\"\"\n\n\n def seat(self):\n \"\"\"\n :rtype: int\n \"\"\"\n\n\n def leave(self, p):\n \"\"\"\n :type p: int\n :rtype: None\n \"\"\"\n\n\n\n# Your ExamRoom object will be instantiated and called as such:\n# obj = ExamRoom(n)\n# param_1 = obj.seat()\n# obj.leave(p)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class ExamRoom:\n\n def __init__(self, n: int):\n\n\n def seat(self) -> int:\n\n\n def leave(self, p: int) -> None:\n\n\n\n# Your ExamRoom object will be instantiated and called as such:\n# obj = ExamRoom(n)\n# param_1 = obj.seat()\n# obj.leave(p)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} ExamRoom;\n\n\nExamRoom* examRoomCreate(int n) {\n\n}\n\nint examRoomSeat(ExamRoom* obj) {\n\n}\n\nvoid examRoomLeave(ExamRoom* obj, int p) {\n\n}\n\nvoid examRoomFree(ExamRoom* obj) {\n\n}\n\n/**\n * Your ExamRoom struct will be instantiated and called as such:\n * ExamRoom* obj = examRoomCreate(n);\n * int param_1 = examRoomSeat(obj);\n \n * examRoomLeave(obj, p);\n \n * examRoomFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class ExamRoom {\n\n public ExamRoom(int n) {\n\n }\n \n public int Seat() {\n\n }\n \n public void Leave(int p) {\n\n }\n}\n\n/**\n * Your ExamRoom object will be instantiated and called as such:\n * ExamRoom obj = new ExamRoom(n);\n * int param_1 = obj.Seat();\n * obj.Leave(p);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n */\nvar ExamRoom = function(n) {\n\n};\n\n/**\n * @return {number}\n */\nExamRoom.prototype.seat = function() {\n\n};\n\n/** \n * @param {number} p\n * @return {void}\n */\nExamRoom.prototype.leave = function(p) {\n\n};\n\n/**\n * Your ExamRoom object will be instantiated and called as such:\n * var obj = new ExamRoom(n)\n * var param_1 = obj.seat()\n * obj.leave(p)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class ExamRoom\n\n=begin\n :type n: Integer\n=end\n def initialize(n)\n\n end\n\n\n=begin\n :rtype: Integer\n=end\n def seat()\n\n end\n\n\n=begin\n :type p: Integer\n :rtype: Void\n=end\n def leave(p)\n\n end\n\n\nend\n\n# Your ExamRoom object will be instantiated and called as such:\n# obj = ExamRoom.new(n)\n# param_1 = obj.seat()\n# obj.leave(p)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass ExamRoom {\n\n init(_ n: Int) {\n\n }\n \n func seat() -> Int {\n\n }\n \n func leave(_ p: Int) {\n\n }\n}\n\n/**\n * Your ExamRoom object will be instantiated and called as such:\n * let obj = ExamRoom(n)\n * let ret_1: Int = obj.seat()\n * obj.leave(p)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type ExamRoom struct {\n\n}\n\n\nfunc Constructor(n int) ExamRoom {\n\n}\n\n\nfunc (this *ExamRoom) Seat() int {\n\n}\n\n\nfunc (this *ExamRoom) Leave(p int) {\n\n}\n\n\n/**\n * Your ExamRoom object will be instantiated and called as such:\n * obj := Constructor(n);\n * param_1 := obj.Seat();\n * obj.Leave(p);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class ExamRoom(_n: Int) {\n\n def seat(): Int = {\n\n }\n\n def leave(p: Int) {\n\n }\n\n}\n\n/**\n * Your ExamRoom object will be instantiated and called as such:\n * var obj = new ExamRoom(n)\n * var param_1 = obj.seat()\n * obj.leave(p)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class ExamRoom(n: Int) {\n\n fun seat(): Int {\n\n }\n\n fun leave(p: Int) {\n\n }\n\n}\n\n/**\n * Your ExamRoom object will be instantiated and called as such:\n * var obj = ExamRoom(n)\n * var param_1 = obj.seat()\n * obj.leave(p)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct ExamRoom {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl ExamRoom {\n\n fn new(n: i32) -> Self {\n\n }\n \n fn seat(&self) -> i32 {\n\n }\n \n fn leave(&self, p: i32) {\n\n }\n}\n\n/**\n * Your ExamRoom object will be instantiated and called as such:\n * let obj = ExamRoom::new(n);\n * let ret_1: i32 = obj.seat();\n * obj.leave(p);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class ExamRoom {\n /**\n * @param Integer $n\n */\n function __construct($n) {\n\n }\n\n /**\n * @return Integer\n */\n function seat() {\n\n }\n\n /**\n * @param Integer $p\n * @return NULL\n */\n function leave($p) {\n\n }\n}\n\n/**\n * Your ExamRoom object will be instantiated and called as such:\n * $obj = ExamRoom($n);\n * $ret_1 = $obj->seat();\n * $obj->leave($p);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class ExamRoom {\n constructor(n: number) {\n\n }\n\n seat(): number {\n\n }\n\n leave(p: number): void {\n\n }\n}\n\n/**\n * Your ExamRoom object will be instantiated and called as such:\n * var obj = new ExamRoom(n)\n * var param_1 = obj.seat()\n * obj.leave(p)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define exam-room%\n (class object%\n (super-new)\n\n ; n : exact-integer?\n (init-field\n n)\n \n ; seat : -> exact-integer?\n (define/public (seat)\n\n )\n ; leave : exact-integer? -> void?\n (define/public (leave p)\n\n )))\n\n;; Your exam-room% object will be instantiated and called as such:\n;; (define obj (new exam-room% [n n]))\n;; (define param_1 (send obj seat))\n;; (send obj leave p)", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0855](https://leetcode-cn.com/problems/exam-room)", "[\u8003\u573a\u5c31\u5ea7](/solution/0800-0899/0855.Exam%20Room/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0855](https://leetcode.com/problems/exam-room)", "[Exam Room](/solution/0800-0899/0855.Exam%20Room/README_EN.md)", "`Ordered Map`", "Medium", ""]}, {"question_id": "0884", "frontend_question_id": "0854", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/k-similar-strings", "url_en": "https://leetcode.com/problems/k-similar-strings", "relative_path_cn": "/solution/0800-0899/0854.K-Similar%20Strings/README.md", "relative_path_en": "/solution/0800-0899/0854.K-Similar%20Strings/README_EN.md", "title_cn": "\u76f8\u4f3c\u5ea6\u4e3a K \u7684\u5b57\u7b26\u4e32", "title_en": "K-Similar Strings", "question_title_slug": "k-similar-strings", "content_en": "

Strings s1 and s2 are k-similar (for some non-negative integer k) if we can swap the positions of two letters in s1 exactly k times so that the resulting string equals s2.

\n\n

Given two anagrams s1 and s2, return the smallest k for which s1 and s2 are k-similar.

\n\n

 

\n

Example 1:

\n
Input: s1 = \"ab\", s2 = \"ba\"\nOutput: 1\n

Example 2:

\n
Input: s1 = \"abc\", s2 = \"bca\"\nOutput: 2\n

Example 3:

\n
Input: s1 = \"abac\", s2 = \"baca\"\nOutput: 2\n

Example 4:

\n
Input: s1 = \"aabc\", s2 = \"abca\"\nOutput: 2\n
\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s1.length <= 20
  • \n\t
  • s2.length == s1.length
  • \n\t
  • s1 and s2 contain only lowercase letters from the set {'a', 'b', 'c', 'd', 'e', 'f'}.
  • \n\t
  • s2 is an anagram of s1.
  • \n
\n", "content_cn": "

\u5982\u679c\u53ef\u4ee5\u901a\u8fc7\u5c06 A \u4e2d\u7684\u4e24\u4e2a\u5c0f\u5199\u5b57\u6bcd\u7cbe\u786e\u5730\u4ea4\u6362\u4f4d\u7f6e K \u6b21\u5f97\u5230\u4e0e B \u76f8\u7b49\u7684\u5b57\u7b26\u4e32\uff0c\u6211\u4eec\u79f0\u5b57\u7b26\u4e32 A \u548c B \u7684\u76f8\u4f3c\u5ea6\u4e3a K\uff08K \u4e3a\u975e\u8d1f\u6574\u6570\uff09\u3002

\n\n

\u7ed9\u5b9a\u4e24\u4e2a\u5b57\u6bcd\u5f02\u4f4d\u8bcd A \u548c B \uff0c\u8fd4\u56de A \u548c B \u7684\u76f8\u4f3c\u5ea6 K \u7684\u6700\u5c0f\u503c\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aA = "ab", B = "ba"\n\u8f93\u51fa\uff1a1\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aA = "abc", B = "bca"\n\u8f93\u51fa\uff1a2\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aA = "abac", B = "baca"\n\u8f93\u51fa\uff1a2\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1aA = "aabc", B = "abca"\n\u8f93\u51fa\uff1a2
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= A.length == B.length <= 20
  2. \n\t
  3. A \u548c B \u53ea\u5305\u542b\u96c6\u5408 {'a', 'b', 'c', 'd', 'e', 'f'} \u4e2d\u7684\u5c0f\u5199\u5b57\u6bcd\u3002
  4. \n
\n", "tags_en": ["Breadth-first Search", "Graph"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u56fe"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int kSimilarity(string s1, string s2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int kSimilarity(String s1, String s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def kSimilarity(self, s1, s2):\n \"\"\"\n :type s1: str\n :type s2: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def kSimilarity(self, s1: str, s2: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint kSimilarity(char * s1, char * s2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int KSimilarity(string s1, string s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s1\n * @param {string} s2\n * @return {number}\n */\nvar kSimilarity = function(s1, s2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s1\n# @param {String} s2\n# @return {Integer}\ndef k_similarity(s1, s2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func kSimilarity(_ s1: String, _ s2: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func kSimilarity(s1 string, s2 string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def kSimilarity(s1: String, s2: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun kSimilarity(s1: String, s2: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn k_similarity(s1: String, s2: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s1\n * @param String $s2\n * @return Integer\n */\n function kSimilarity($s1, $s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function kSimilarity(s1: string, s2: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (k-similarity s1 s2)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0854](https://leetcode-cn.com/problems/k-similar-strings)", "[\u76f8\u4f3c\u5ea6\u4e3a K \u7684\u5b57\u7b26\u4e32](/solution/0800-0899/0854.K-Similar%20Strings/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u56fe`", "\u56f0\u96be", ""], "md_table_row_en": ["[0854](https://leetcode.com/problems/k-similar-strings)", "[K-Similar Strings](/solution/0800-0899/0854.K-Similar%20Strings/README_EN.md)", "`Breadth-first Search`,`Graph`", "Hard", ""]}, {"question_id": "0883", "frontend_question_id": "0853", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/car-fleet", "url_en": "https://leetcode.com/problems/car-fleet", "relative_path_cn": "/solution/0800-0899/0853.Car%20Fleet/README.md", "relative_path_en": "/solution/0800-0899/0853.Car%20Fleet/README_EN.md", "title_cn": "\u8f66\u961f", "title_en": "Car Fleet", "question_title_slug": "car-fleet", "content_en": "

N cars are going to the same destination along a one lane road.  The destination is target miles away.

\r\n\r\n

Each car i has a constant speed speed[i] (in miles per hour), and initial position position[i] miles towards the target along the road.

\r\n\r\n

A car can never pass another car ahead of it, but it can catch up to it, and drive bumper to bumper at the same speed.

\r\n\r\n

The distance between these two cars is ignored - they are assumed to have the same position.

\r\n\r\n

A car fleet is some non-empty set of cars driving at the same position and same speed.  Note that a single car is also a car fleet.

\r\n\r\n

If a car catches up to a car fleet right at the destination point, it will still be considered as one car fleet.

\r\n\r\n


\r\nHow many car fleets will arrive at the destination?

\r\n\r\n

 

\r\n\r\n

Example 1:

\r\n\r\n
\r\nInput: target = 12, position = [10,8,0,5,3], speed = [2,4,1,1,3]\r\nOutput: 3\r\nExplanation:\r\nThe cars starting at 10 and 8 become a fleet, meeting each other at 12.\r\nThe car starting at 0 doesn't catch up to any other car, so it is a fleet by itself.\r\nThe cars starting at 5 and 3 become a fleet, meeting each other at 6.\r\nNote that no other cars meet these fleets before the destination, so the answer is 3.\r\n
\r\n\r\n


\r\nNote:

\r\n\r\n
    \r\n\t
  1. 0 <= N <= 10 ^ 4
  2. \r\n\t
  3. 0 < target <= 10 ^ 6
  4. \r\n\t
  5. 0 < speed[i] <= 10 ^ 6
  6. \r\n\t
  7. 0 <= position[i] < target
  8. \r\n\t
  9. All initial positions are different.
  10. \r\n
", "content_cn": "

N  \u8f86\u8f66\u6cbf\u7740\u4e00\u6761\u8f66\u9053\u9a76\u5411\u4f4d\u4e8e target \u82f1\u91cc\u4e4b\u5916\u7684\u5171\u540c\u76ee\u7684\u5730\u3002

\n\n

\u6bcf\u8f86\u8f66 i \u4ee5\u6052\u5b9a\u7684\u901f\u5ea6 speed[i] \uff08\u82f1\u91cc/\u5c0f\u65f6\uff09\uff0c\u4ece\u521d\u59cb\u4f4d\u7f6e position[i] \uff08\u82f1\u91cc\uff09 \u6cbf\u8f66\u9053\u9a76\u5411\u76ee\u7684\u5730\u3002

\n\n

\u4e00\u8f86\u8f66\u6c38\u8fdc\u4e0d\u4f1a\u8d85\u8fc7\u524d\u9762\u7684\u53e6\u4e00\u8f86\u8f66\uff0c\u4f46\u5b83\u53ef\u4ee5\u8ffd\u4e0a\u53bb\uff0c\u5e76\u4e0e\u524d\u8f66\u4ee5\u76f8\u540c\u7684\u901f\u5ea6\u7d27\u63a5\u7740\u884c\u9a76\u3002

\n\n

\u6b64\u65f6\uff0c\u6211\u4eec\u4f1a\u5ffd\u7565\u8fd9\u4e24\u8f86\u8f66\u4e4b\u95f4\u7684\u8ddd\u79bb\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u5b83\u4eec\u88ab\u5047\u5b9a\u5904\u4e8e\u76f8\u540c\u7684\u4f4d\u7f6e\u3002

\n\n

\u8f66\u961f \u662f\u4e00\u4e9b\u7531\u884c\u9a76\u5728\u76f8\u540c\u4f4d\u7f6e\u3001\u5177\u6709\u76f8\u540c\u901f\u5ea6\u7684\u8f66\u7ec4\u6210\u7684\u975e\u7a7a\u96c6\u5408\u3002\u6ce8\u610f\uff0c\u4e00\u8f86\u8f66\u4e5f\u53ef\u4ee5\u662f\u4e00\u4e2a\u8f66\u961f\u3002

\n\n

\u5373\u4fbf\u4e00\u8f86\u8f66\u5728\u76ee\u7684\u5730\u624d\u8d76\u4e0a\u4e86\u4e00\u4e2a\u8f66\u961f\uff0c\u5b83\u4eec\u4ecd\u7136\u4f1a\u88ab\u89c6\u4f5c\u662f\u540c\u4e00\u4e2a\u8f66\u961f\u3002

\n\n

 

\n\n

\u4f1a\u6709\u591a\u5c11\u8f66\u961f\u5230\u8fbe\u76ee\u7684\u5730?

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1atarget = 12, position = [10,8,0,5,3], speed = [2,4,1,1,3]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\n\u4ece 10 \u548c 8 \u5f00\u59cb\u7684\u8f66\u4f1a\u7ec4\u6210\u4e00\u4e2a\u8f66\u961f\uff0c\u5b83\u4eec\u5728 12 \u5904\u76f8\u9047\u3002\n\u4ece 0 \u5904\u5f00\u59cb\u7684\u8f66\u65e0\u6cd5\u8ffd\u4e0a\u5176\u5b83\u8f66\uff0c\u6240\u4ee5\u5b83\u81ea\u5df1\u5c31\u662f\u4e00\u4e2a\u8f66\u961f\u3002\n\u4ece 5 \u548c 3 \u5f00\u59cb\u7684\u8f66\u4f1a\u7ec4\u6210\u4e00\u4e2a\u8f66\u961f\uff0c\u5b83\u4eec\u5728 6 \u5904\u76f8\u9047\u3002\n\u8bf7\u6ce8\u610f\uff0c\u5728\u5230\u8fbe\u76ee\u7684\u5730\u4e4b\u524d\u6ca1\u6709\u5176\u5b83\u8f66\u4f1a\u9047\u5230\u8fd9\u4e9b\u8f66\u961f\uff0c\u6240\u4ee5\u7b54\u6848\u662f 3\u3002\n
\n\n


\n\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 0 <= N <= 10 ^ 4
  2. \n\t
  3. 0 < target <= 10 ^ 6
  4. \n\t
  5. 0 < speed[i] <= 10 ^ 6
  6. \n\t
  7. 0 <= position[i] < target
  8. \n\t
  9. \u6240\u6709\u8f66\u7684\u521d\u59cb\u4f4d\u7f6e\u5404\u4e0d\u76f8\u540c\u3002
  10. \n
\n", "tags_en": ["Sort"], "tags_cn": ["\u6392\u5e8f"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int carFleet(int target, vector& position, vector& speed) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int carFleet(int target, int[] position, int[] speed) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def carFleet(self, target, position, speed):\n \"\"\"\n :type target: int\n :type position: List[int]\n :type speed: List[int]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def carFleet(self, target: int, position: List[int], speed: List[int]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint carFleet(int target, int* position, int positionSize, int* speed, int speedSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CarFleet(int target, int[] position, int[] speed) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} target\n * @param {number[]} position\n * @param {number[]} speed\n * @return {number}\n */\nvar carFleet = function(target, position, speed) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} target\n# @param {Integer[]} position\n# @param {Integer[]} speed\n# @return {Integer}\ndef car_fleet(target, position, speed)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func carFleet(_ target: Int, _ position: [Int], _ speed: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func carFleet(target int, position []int, speed []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def carFleet(target: Int, position: Array[Int], speed: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun carFleet(target: Int, position: IntArray, speed: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn car_fleet(target: i32, position: Vec, speed: Vec) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $target\n * @param Integer[] $position\n * @param Integer[] $speed\n * @return Integer\n */\n function carFleet($target, $position, $speed) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function carFleet(target: number, position: number[], speed: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (car-fleet target position speed)\n (-> exact-integer? (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0853](https://leetcode-cn.com/problems/car-fleet)", "[\u8f66\u961f](/solution/0800-0899/0853.Car%20Fleet/README.md)", "`\u6392\u5e8f`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0853](https://leetcode.com/problems/car-fleet)", "[Car Fleet](/solution/0800-0899/0853.Car%20Fleet/README_EN.md)", "`Sort`", "Medium", ""]}, {"question_id": "0882", "frontend_question_id": "0852", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/peak-index-in-a-mountain-array", "url_en": "https://leetcode.com/problems/peak-index-in-a-mountain-array", "relative_path_cn": "/solution/0800-0899/0852.Peak%20Index%20in%20a%20Mountain%20Array/README.md", "relative_path_en": "/solution/0800-0899/0852.Peak%20Index%20in%20a%20Mountain%20Array/README_EN.md", "title_cn": "\u5c71\u8109\u6570\u7ec4\u7684\u5cf0\u9876\u7d22\u5f15", "title_en": "Peak Index in a Mountain Array", "question_title_slug": "peak-index-in-a-mountain-array", "content_en": "

Let's call an array arr a mountain if the following properties hold:

\n\n
    \n\t
  • arr.length >= 3
  • \n\t
  • There exists some i with 0 < i < arr.length - 1 such that:\n\t
      \n\t\t
    • arr[0] < arr[1] < ... arr[i-1] < arr[i]
    • \n\t\t
    • arr[i] > arr[i+1] > ... > arr[arr.length - 1]
    • \n\t
    \n\t
  • \n
\n\n

Given an integer array arr that is guaranteed to be a mountain, return any i such that arr[0] < arr[1] < ... arr[i - 1] < arr[i] > arr[i + 1] > ... > arr[arr.length - 1].

\n\n

 

\n

Example 1:

\n
Input: arr = [0,1,0]\nOutput: 1\n

Example 2:

\n
Input: arr = [0,2,1,0]\nOutput: 1\n

Example 3:

\n
Input: arr = [0,10,5,2]\nOutput: 1\n

Example 4:

\n
Input: arr = [3,4,5,1]\nOutput: 2\n

Example 5:

\n
Input: arr = [24,69,100,99,79,78,67,36,26,19]\nOutput: 2\n
\n

 

\n

Constraints:

\n\n
    \n\t
  • 3 <= arr.length <= 104
  • \n\t
  • 0 <= arr[i] <= 106
  • \n\t
  • arr is guaranteed to be a mountain array.
  • \n
\n\n

 

\nFollow up: Finding the O(n) is straightforward, could you find an O(log(n)) solution?", "content_cn": "\u7b26\u5408\u4e0b\u5217\u5c5e\u6027\u7684\u6570\u7ec4 arr \u79f0\u4e3a \u5c71\u8109\u6570\u7ec4 \uff1a\n
    \n\t
  • arr.length >= 3
  • \n\t
  • \u5b58\u5728 i\uff080 < i\u00a0< arr.length - 1\uff09\u4f7f\u5f97\uff1a\n\t
      \n\t\t
    • arr[0] < arr[1] < ... arr[i-1] < arr[i]
    • \n\t\t
    • arr[i] > arr[i+1] > ... > arr[arr.length - 1]
    • \n\t
    \n\t
  • \n
\n\n

\u7ed9\u4f60\u7531\u6574\u6570\u7ec4\u6210\u7684\u5c71\u8109\u6570\u7ec4 arr \uff0c\u8fd4\u56de\u4efb\u4f55\u6ee1\u8db3 arr[0] < arr[1] < ... arr[i - 1] < arr[i] > arr[i + 1] > ... > arr[arr.length - 1] \u7684\u4e0b\u6807 i \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [0,1,0]\n\u8f93\u51fa\uff1a1\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [0,2,1,0]\n\u8f93\u51fa\uff1a1\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [0,10,5,2]\n\u8f93\u51fa\uff1a1\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [3,4,5,1]\n\u8f93\u51fa\uff1a2\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [24,69,100,99,79,78,67,36,26,19]\n\u8f93\u51fa\uff1a2\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 3 <= arr.length <= 104
  • \n\t
  • 0 <= arr[i] <= 106
  • \n\t
  • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1 arr \u662f\u4e00\u4e2a\u5c71\u8109\u6570\u7ec4
  • \n
\n\n

\u00a0

\n\n

\u8fdb\u9636\uff1a\u5f88\u5bb9\u6613\u60f3\u5230\u65f6\u95f4\u590d\u6742\u5ea6 O(n) \u7684\u89e3\u51b3\u65b9\u6848\uff0c\u4f60\u53ef\u4ee5\u8bbe\u8ba1\u4e00\u4e2a O(log(n)) \u7684\u89e3\u51b3\u65b9\u6848\u5417\uff1f

\n", "tags_en": ["Binary Search"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int peakIndexInMountainArray(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int peakIndexInMountainArray(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def peakIndexInMountainArray(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def peakIndexInMountainArray(self, arr: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint peakIndexInMountainArray(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int PeakIndexInMountainArray(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar peakIndexInMountainArray = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef peak_index_in_mountain_array(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func peakIndexInMountainArray(_ arr: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func peakIndexInMountainArray(arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def peakIndexInMountainArray(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun peakIndexInMountainArray(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn peak_index_in_mountain_array(arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function peakIndexInMountainArray($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function peakIndexInMountainArray(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (peak-index-in-mountain-array arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0852](https://leetcode-cn.com/problems/peak-index-in-a-mountain-array)", "[\u5c71\u8109\u6570\u7ec4\u7684\u5cf0\u9876\u7d22\u5f15](/solution/0800-0899/0852.Peak%20Index%20in%20a%20Mountain%20Array/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u7b80\u5355", ""], "md_table_row_en": ["[0852](https://leetcode.com/problems/peak-index-in-a-mountain-array)", "[Peak Index in a Mountain Array](/solution/0800-0899/0852.Peak%20Index%20in%20a%20Mountain%20Array/README_EN.md)", "`Binary Search`", "Easy", ""]}, {"question_id": "0881", "frontend_question_id": "0851", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/loud-and-rich", "url_en": "https://leetcode.com/problems/loud-and-rich", "relative_path_cn": "/solution/0800-0899/0851.Loud%20and%20Rich/README.md", "relative_path_en": "/solution/0800-0899/0851.Loud%20and%20Rich/README_EN.md", "title_cn": "\u55a7\u95f9\u548c\u5bcc\u6709", "title_en": "Loud and Rich", "question_title_slug": "loud-and-rich", "content_en": "

In a group of N people (labelled 0, 1, 2, ..., N-1), each person has different amounts of money, and different levels of quietness.

\r\n\r\n

For convenience, we'll call the person with label x, simply "person x".

\r\n\r\n

We'll say that richer[i] = [x, y] if person x definitely has more money than person y.  Note that richer may only be a subset of valid observations.

\r\n\r\n

Also, we'll say quiet[x] = q if person x has quietness q.

\r\n\r\n

Now, return answer, where answer[x] = y if y is the least quiet person (that is, the person y with the smallest value of quiet[y]), among all people who definitely have equal to or more money than person x.

\r\n\r\n

 

\r\n\r\n
\r\n

Example 1:

\r\n\r\n
\r\nInput: richer = [[1,0],[2,1],[3,1],[3,7],[4,3],[5,3],[6,3]], quiet = [3,2,5,4,6,1,7,0]\r\nOutput: [5,5,2,5,4,5,6,7]\r\nExplanation: \r\nanswer[0] = 5.\r\nPerson 5 has more money than 3, which has more money than 1, which has more money than 0.\r\nThe only person who is quieter (has lower quiet[x]) is person 7, but\r\nit isn't clear if they have more money than person 0.\r\n\r\nanswer[7] = 7.\r\nAmong all people that definitely have equal to or more money than person 7\r\n(which could be persons 3, 4, 5, 6, or 7), the person who is the quietest (has lower quiet[x])\r\nis person 7.\r\n\r\nThe other answers can be filled out with similar reasoning.\r\n
\r\n
\r\n\r\n

Note:

\r\n\r\n
    \r\n\t
  1. 1 <= quiet.length = N <= 500
  2. \r\n\t
  3. 0 <= quiet[i] < N, all quiet[i] are different.
  4. \r\n\t
  5. 0 <= richer.length <= N * (N-1) / 2
  6. \r\n\t
  7. 0 <= richer[i][j] < N
  8. \r\n\t
  9. richer[i][0] != richer[i][1]
  10. \r\n\t
  11. richer[i]'s are all different.
  12. \r\n\t
  13. The observations in richer are all logically consistent.
  14. \r\n
\r\n", "content_cn": "

\u5728\u4e00\u7ec4 N \u4e2a\u4eba\uff08\u7f16\u53f7\u4e3a 0, 1, 2, ..., N-1\uff09\u4e2d\uff0c\u6bcf\u4e2a\u4eba\u90fd\u6709\u4e0d\u540c\u6570\u76ee\u7684\u94b1\uff0c\u4ee5\u53ca\u4e0d\u540c\u7a0b\u5ea6\u7684\u5b89\u9759\uff08quietness\uff09\u3002

\n\n

\u4e3a\u4e86\u65b9\u4fbf\u8d77\u89c1\uff0c\u6211\u4eec\u5c06\u7f16\u53f7\u4e3a x \u7684\u4eba\u7b80\u79f0\u4e3a "person x "\u3002

\n\n

\u5982\u679c\u80fd\u591f\u80af\u5b9a person x \u6bd4 person y \u66f4\u6709\u94b1\u7684\u8bdd\uff0c\u6211\u4eec\u4f1a\u8bf4 richer[i] = [x, y] \u3002\u6ce8\u610f richer \u53ef\u80fd\u53ea\u662f\u6709\u6548\u89c2\u5bdf\u7684\u4e00\u4e2a\u5b50\u96c6\u3002

\n\n

\u53e6\u5916\uff0c\u5982\u679c person x \u7684\u5b89\u9759\u7a0b\u5ea6\u4e3a q \uff0c\u6211\u4eec\u4f1a\u8bf4 quiet[x] = q \u3002

\n\n

\u73b0\u5728\uff0c\u8fd4\u56de\u7b54\u6848 answer \uff0c\u5176\u4e2d answer[x] = y \u7684\u524d\u63d0\u662f\uff0c\u5728\u6240\u6709\u62e5\u6709\u7684\u94b1\u4e0d\u5c11\u4e8e person x \u7684\u4eba\u4e2d\uff0cperson y \u662f\u6700\u5b89\u9759\u7684\u4eba\uff08\u4e5f\u5c31\u662f\u5b89\u9759\u503c quiet[y] \u6700\u5c0f\u7684\u4eba\uff09\u3002

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1aricher = [[1,0],[2,1],[3,1],[3,7],[4,3],[5,3],[6,3]], quiet = [3,2,5,4,6,1,7,0]\n\u8f93\u51fa\uff1a[5,5,2,5,4,5,6,7]\n\u89e3\u91ca\uff1a \nanswer[0] = 5\uff0c\nperson 5 \u6bd4 person 3 \u6709\u66f4\u591a\u7684\u94b1\uff0cperson 3 \u6bd4 person 1 \u6709\u66f4\u591a\u7684\u94b1\uff0cperson 1 \u6bd4 person 0 \u6709\u66f4\u591a\u7684\u94b1\u3002\n\u552f\u4e00\u8f83\u4e3a\u5b89\u9759\uff08\u6709\u8f83\u4f4e\u7684\u5b89\u9759\u503c quiet[x]\uff09\u7684\u4eba\u662f person 7\uff0c\n\u4f46\u662f\u76ee\u524d\u8fd8\u4e0d\u6e05\u695a\u4ed6\u662f\u5426\u6bd4 person 0 \u66f4\u6709\u94b1\u3002\n\nanswer[7] = 7\uff0c\n\u5728\u6240\u6709\u62e5\u6709\u7684\u94b1\u80af\u5b9a\u4e0d\u5c11\u4e8e person 7 \u7684\u4eba\u4e2d(\u8fd9\u53ef\u80fd\u5305\u62ec person 3\uff0c4\uff0c5\uff0c6 \u4ee5\u53ca 7)\uff0c\n\u6700\u5b89\u9759(\u6709\u8f83\u4f4e\u5b89\u9759\u503c quiet[x])\u7684\u4eba\u662f person 7\u3002\n\n\u5176\u4ed6\u7684\u7b54\u6848\u4e5f\u53ef\u4ee5\u7528\u7c7b\u4f3c\u7684\u63a8\u7406\u6765\u89e3\u91ca\u3002\n
\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= quiet.length = N <= 500
  2. \n\t
  3. 0 <= quiet[i] < N\uff0c\u6240\u6709 quiet[i] \u90fd\u4e0d\u76f8\u540c\u3002
  4. \n\t
  5. 0 <= richer.length <= N * (N-1) / 2
  6. \n\t
  7. 0 <= richer[i][j] < N
  8. \n\t
  9. richer[i][0] != richer[i][1]
  10. \n\t
  11. richer[i] \u90fd\u662f\u4e0d\u540c\u7684\u3002
  12. \n\t
  13. \u5bf9 richer \u7684\u89c2\u5bdf\u5728\u903b\u8f91\u4e0a\u662f\u4e00\u81f4\u7684\u3002
  14. \n
\n", "tags_en": ["Depth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector loudAndRich(vector>& richer, vector& quiet) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] loudAndRich(int[][] richer, int[] quiet) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def loudAndRich(self, richer, quiet):\n \"\"\"\n :type richer: List[List[int]]\n :type quiet: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def loudAndRich(self, richer: List[List[int]], quiet: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* loudAndRich(int** richer, int richerSize, int* richerColSize, int* quiet, int quietSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] LoudAndRich(int[][] richer, int[] quiet) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} richer\n * @param {number[]} quiet\n * @return {number[]}\n */\nvar loudAndRich = function(richer, quiet) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} richer\n# @param {Integer[]} quiet\n# @return {Integer[]}\ndef loud_and_rich(richer, quiet)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func loudAndRich(_ richer: [[Int]], _ quiet: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func loudAndRich(richer [][]int, quiet []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def loudAndRich(richer: Array[Array[Int]], quiet: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun loudAndRich(richer: Array, quiet: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn loud_and_rich(richer: Vec>, quiet: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $richer\n * @param Integer[] $quiet\n * @return Integer[]\n */\n function loudAndRich($richer, $quiet) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function loudAndRich(richer: number[][], quiet: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (loud-and-rich richer quiet)\n (-> (listof (listof exact-integer?)) (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0851](https://leetcode-cn.com/problems/loud-and-rich)", "[\u55a7\u95f9\u548c\u5bcc\u6709](/solution/0800-0899/0851.Loud%20and%20Rich/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0851](https://leetcode.com/problems/loud-and-rich)", "[Loud and Rich](/solution/0800-0899/0851.Loud%20and%20Rich/README_EN.md)", "`Depth-first Search`", "Medium", ""]}, {"question_id": "0880", "frontend_question_id": "0850", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/rectangle-area-ii", "url_en": "https://leetcode.com/problems/rectangle-area-ii", "relative_path_cn": "/solution/0800-0899/0850.Rectangle%20Area%20II/README.md", "relative_path_en": "/solution/0800-0899/0850.Rectangle%20Area%20II/README_EN.md", "title_cn": "\u77e9\u5f62\u9762\u79ef II", "title_en": "Rectangle Area II", "question_title_slug": "rectangle-area-ii", "content_en": "

We are given a list of (axis-aligned) rectangles. Each rectangle[i] = [xi1, yi1, xi2, yi2] , where (xi1, yi1) are the coordinates of the bottom-left corner, and (xi2, yi2) are the coordinates of the top-right corner of the ith rectangle.

\n\n

Find the total area covered by all rectangles in the plane. Since the answer may be too large, return it modulo 109 + 7.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: rectangles = [[0,0,2,2],[1,0,2,3],[1,0,3,1]]\nOutput: 6\nExplanation: As illustrated in the picture.\n
\n\n

Example 2:

\n\n
\nInput: rectangles = [[0,0,1000000000,1000000000]]\nOutput: 49\nExplanation: The answer is 1018 modulo (109 + 7), which is (109)2 = (-7)2 = 49.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= rectangles.length <= 200
  • \n\t
  • rectanges[i].length = 4
  • \n\t
  • 0 <= rectangles[i][j] <= 109
  • \n\t
  • The total area covered by all rectangles will never exceed 263 - 1 and thus will fit in a 64-bit signed integer.
  • \n
\n", "content_cn": "

\u6211\u4eec\u7ed9\u51fa\u4e86\u4e00\u4e2a\uff08\u8f74\u5bf9\u9f50\u7684\uff09\u77e9\u5f62\u5217\u8868 rectangles \u3002 \u5bf9\u4e8e rectangle[i] = [x1, y1, x2, y2]\uff0c\u5176\u4e2d\uff08x1\uff0cy1\uff09\u662f\u77e9\u5f62 i \u5de6\u4e0b\u89d2\u7684\u5750\u6807\uff0c\uff08x2\uff0cy2\uff09\u662f\u8be5\u77e9\u5f62\u53f3\u4e0a\u89d2\u7684\u5750\u6807\u3002

\n\n

\u627e\u51fa\u5e73\u9762\u4e2d\u6240\u6709\u77e9\u5f62\u53e0\u52a0\u8986\u76d6\u540e\u7684\u603b\u9762\u79ef\u3002 \u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u592a\u5927\uff0c\u8bf7\u8fd4\u56de\u5b83\u5bf9 10 ^ 9 + 7 \u53d6\u6a21\u7684\u7ed3\u679c\u3002

\n\n

\"\"

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a[[0,0,2,2],[1,0,2,3],[1,0,3,1]]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u5982\u56fe\u6240\u793a\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a[[0,0,1000000000,1000000000]]\n\u8f93\u51fa\uff1a49\n\u89e3\u91ca\uff1a\u7b54\u6848\u662f 10^18 \u5bf9 (10^9 + 7) \u53d6\u6a21\u7684\u7ed3\u679c\uff0c \u5373 (10^9)^2 → (-7)^2 = 49 \u3002\n
\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= rectangles.length <= 200
  • \n\t
  • rectanges[i].length = 4
  • \n\t
  • 0 <= rectangles[i][j] <= 10^9
  • \n\t
  • \u77e9\u5f62\u53e0\u52a0\u8986\u76d6\u540e\u7684\u603b\u9762\u79ef\u4e0d\u4f1a\u8d85\u8d8a 2^63 - 1 \uff0c\u8fd9\u610f\u5473\u7740\u53ef\u4ee5\u7528\u4e00\u4e2a 64 \u4f4d\u6709\u7b26\u53f7\u6574\u6570\u6765\u4fdd\u5b58\u9762\u79ef\u7ed3\u679c\u3002
  • \n
\n", "tags_en": ["Segment Tree", "Line Sweep"], "tags_cn": ["\u7ebf\u6bb5\u6811"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int rectangleArea(vector>& rectangles) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int rectangleArea(int[][] rectangles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def rectangleArea(self, rectangles):\n \"\"\"\n :type rectangles: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def rectangleArea(self, rectangles: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint rectangleArea(int** rectangles, int rectanglesSize, int* rectanglesColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int RectangleArea(int[][] rectangles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} rectangles\n * @return {number}\n */\nvar rectangleArea = function(rectangles) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} rectangles\n# @return {Integer}\ndef rectangle_area(rectangles)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func rectangleArea(_ rectangles: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func rectangleArea(rectangles [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def rectangleArea(rectangles: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun rectangleArea(rectangles: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn rectangle_area(rectangles: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $rectangles\n * @return Integer\n */\n function rectangleArea($rectangles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function rectangleArea(rectangles: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (rectangle-area rectangles)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0850](https://leetcode-cn.com/problems/rectangle-area-ii)", "[\u77e9\u5f62\u9762\u79ef II](/solution/0800-0899/0850.Rectangle%20Area%20II/README.md)", "`\u7ebf\u6bb5\u6811`", "\u56f0\u96be", ""], "md_table_row_en": ["[0850](https://leetcode.com/problems/rectangle-area-ii)", "[Rectangle Area II](/solution/0800-0899/0850.Rectangle%20Area%20II/README_EN.md)", "`Segment Tree`,`Line Sweep`", "Hard", ""]}, {"question_id": "0879", "frontend_question_id": "0849", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximize-distance-to-closest-person", "url_en": "https://leetcode.com/problems/maximize-distance-to-closest-person", "relative_path_cn": "/solution/0800-0899/0849.Maximize%20Distance%20to%20Closest%20Person/README.md", "relative_path_en": "/solution/0800-0899/0849.Maximize%20Distance%20to%20Closest%20Person/README_EN.md", "title_cn": "\u5230\u6700\u8fd1\u7684\u4eba\u7684\u6700\u5927\u8ddd\u79bb", "title_en": "Maximize Distance to Closest Person", "question_title_slug": "maximize-distance-to-closest-person", "content_en": "

You are given an array representing a row of seats where seats[i] = 1 represents a person sitting in the ith seat, and seats[i] = 0 represents that the ith seat is empty (0-indexed).

\n\n

There is at least one empty seat, and at least one person sitting.

\n\n

Alex wants to sit in the seat such that the distance between him and the closest person to him is maximized. 

\n\n

Return that maximum distance to the closest person.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: seats = [1,0,0,0,1,0,1]\nOutput: 2\nExplanation: \nIf Alex sits in the second open seat (i.e. seats[2]), then the closest person has distance 2.\nIf Alex sits in any other open seat, the closest person has distance 1.\nThus, the maximum distance to the closest person is 2.\n
\n\n

Example 2:

\n\n
\nInput: seats = [1,0,0,0]\nOutput: 3\nExplanation: \nIf Alex sits in the last seat (i.e. seats[3]), the closest person is 3 seats away.\nThis is the maximum distance possible, so the answer is 3.\n
\n\n

Example 3:

\n\n
\nInput: seats = [0,1]\nOutput: 1\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= seats.length <= 2 * 104
  • \n\t
  • seats[i] is 0 or 1.
  • \n\t
  • At least one seat is empty.
  • \n\t
  • At least one seat is occupied.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4\u00a0seats \u8868\u793a\u4e00\u6392\u5ea7\u4f4d\uff0c\u5176\u4e2d seats[i] = 1 \u4ee3\u8868\u6709\u4eba\u5750\u5728\u7b2c i \u4e2a\u5ea7\u4f4d\u4e0a\uff0cseats[i] = 0 \u4ee3\u8868\u5ea7\u4f4d i \u4e0a\u662f\u7a7a\u7684\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\u3002

\n\n

\u81f3\u5c11\u6709\u4e00\u4e2a\u7a7a\u5ea7\u4f4d\uff0c\u4e14\u81f3\u5c11\u6709\u4e00\u4eba\u5df2\u7ecf\u5750\u5728\u5ea7\u4f4d\u4e0a\u3002

\n\n

\u4e9a\u5386\u514b\u65af\u5e0c\u671b\u5750\u5728\u4e00\u4e2a\u80fd\u591f\u4f7f\u4ed6\u4e0e\u79bb\u4ed6\u6700\u8fd1\u7684\u4eba\u4e4b\u95f4\u7684\u8ddd\u79bb\u8fbe\u5230\u6700\u5927\u5316\u7684\u5ea7\u4f4d\u4e0a\u3002

\n\n

\u8fd4\u56de\u4ed6\u5230\u79bb\u4ed6\u6700\u8fd1\u7684\u4eba\u7684\u6700\u5927\u8ddd\u79bb\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1aseats = [1,0,0,0,1,0,1]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n\u5982\u679c\u4e9a\u5386\u514b\u65af\u5750\u5728\u7b2c\u4e8c\u4e2a\u7a7a\u4f4d\uff08seats[2]\uff09\u4e0a\uff0c\u4ed6\u5230\u79bb\u4ed6\u6700\u8fd1\u7684\u4eba\u7684\u8ddd\u79bb\u4e3a 2 \u3002\n\u5982\u679c\u4e9a\u5386\u514b\u65af\u5750\u5728\u5176\u5b83\u4efb\u4f55\u4e00\u4e2a\u7a7a\u4f4d\u4e0a\uff0c\u4ed6\u5230\u79bb\u4ed6\u6700\u8fd1\u7684\u4eba\u7684\u8ddd\u79bb\u4e3a 1 \u3002\n\u56e0\u6b64\uff0c\u4ed6\u5230\u79bb\u4ed6\u6700\u8fd1\u7684\u4eba\u7684\u6700\u5927\u8ddd\u79bb\u662f 2 \u3002 \n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aseats = [1,0,0,0]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\n\u5982\u679c\u4e9a\u5386\u514b\u65af\u5750\u5728\u6700\u540e\u4e00\u4e2a\u5ea7\u4f4d\u4e0a\uff0c\u4ed6\u79bb\u6700\u8fd1\u7684\u4eba\u6709 3 \u4e2a\u5ea7\u4f4d\u8fdc\u3002\n\u8fd9\u662f\u53ef\u80fd\u7684\u6700\u5927\u8ddd\u79bb\uff0c\u6240\u4ee5\u7b54\u6848\u662f 3 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1aseats = [0,1]\n\u8f93\u51fa\uff1a1\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= seats.length <= 2 * 104
  • \n\t
  • seats[i] \u4e3a 0 \u6216 1
  • \n\t
  • \u81f3\u5c11\u6709\u4e00\u4e2a \u7a7a\u5ea7\u4f4d
  • \n\t
  • \u81f3\u5c11\u6709\u4e00\u4e2a \u5ea7\u4f4d\u4e0a\u6709\u4eba
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxDistToClosest(vector& seats) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxDistToClosest(int[] seats) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxDistToClosest(self, seats):\n \"\"\"\n :type seats: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxDistToClosest(self, seats: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxDistToClosest(int* seats, int seatsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxDistToClosest(int[] seats) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} seats\n * @return {number}\n */\nvar maxDistToClosest = function(seats) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} seats\n# @return {Integer}\ndef max_dist_to_closest(seats)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxDistToClosest(_ seats: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxDistToClosest(seats []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxDistToClosest(seats: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxDistToClosest(seats: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_dist_to_closest(seats: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $seats\n * @return Integer\n */\n function maxDistToClosest($seats) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxDistToClosest(seats: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-dist-to-closest seats)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0849](https://leetcode-cn.com/problems/maximize-distance-to-closest-person)", "[\u5230\u6700\u8fd1\u7684\u4eba\u7684\u6700\u5927\u8ddd\u79bb](/solution/0800-0899/0849.Maximize%20Distance%20to%20Closest%20Person/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0849](https://leetcode.com/problems/maximize-distance-to-closest-person)", "[Maximize Distance to Closest Person](/solution/0800-0899/0849.Maximize%20Distance%20to%20Closest%20Person/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0878", "frontend_question_id": "0848", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/shifting-letters", "url_en": "https://leetcode.com/problems/shifting-letters", "relative_path_cn": "/solution/0800-0899/0848.Shifting%20Letters/README.md", "relative_path_en": "/solution/0800-0899/0848.Shifting%20Letters/README_EN.md", "title_cn": "\u5b57\u6bcd\u79fb\u4f4d", "title_en": "Shifting Letters", "question_title_slug": "shifting-letters", "content_en": "

We have a string s of lowercase letters, and an integer array shifts.

\n\n

Call the shift of a letter, the next letter in the alphabet, (wrapping around so that 'z' becomes 'a'). 

\n\n

For example, shift('a') = 'b', shift('t') = 'u', and shift('z') = 'a'.

\n\n

Now for each shifts[i] = x, we want to shift the first i+1 letters of S, x times.

\n\n

Return the final string after all such shifts to s are applied.

\n\n

Example 1:

\n\n
\nInput: s = "abc", shifts = [3,5,9]\nOutput: "rpl"\nExplanation: \nWe start with "abc".\nAfter shifting the first 1 letters of S by 3, we have "dbc".\nAfter shifting the first 2 letters of S by 5, we have "igc".\nAfter shifting the first 3 letters of S by 9, we have "rpl", the answer.\n
\n\n

Note:

\n\n
    \n\t
  1. 1 <= s.length = shifts.length <= 20000
  2. \n\t
  3. 0 <= shifts[i] <= 109
  4. \n
\n", "content_cn": "

\u6709\u4e00\u4e2a\u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210\u7684\u5b57\u7b26\u4e32 S\uff0c\u548c\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 shifts\u3002

\n\n

\u6211\u4eec\u5c06\u5b57\u6bcd\u8868\u4e2d\u7684\u4e0b\u4e00\u4e2a\u5b57\u6bcd\u79f0\u4e3a\u539f\u5b57\u6bcd\u7684 \u79fb\u4f4d\uff08\u7531\u4e8e\u5b57\u6bcd\u8868\u662f\u73af\u7ed5\u7684\uff0c 'z' \u5c06\u4f1a\u53d8\u6210 'a'\uff09\u3002

\n\n

\u4f8b\u5982·\uff0cshift('a') = 'b'\uff0c shift('t') = 'u',\uff0c \u4ee5\u53ca shift('z') = 'a'\u3002

\n\n

\u5bf9\u4e8e\u6bcf\u4e2a shifts[i] = x \uff0c \u6211\u4eec\u4f1a\u5c06 S \u4e2d\u7684\u524d i+1 \u4e2a\u5b57\u6bcd\u79fb\u4f4d x \u6b21\u3002

\n\n

\u8fd4\u56de\u5c06\u6240\u6709\u8fd9\u4e9b\u79fb\u4f4d\u90fd\u5e94\u7528\u5230 S \u540e\u6700\u7ec8\u5f97\u5230\u7684\u5b57\u7b26\u4e32\u3002

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1aS = "abc", shifts = [3,5,9]\n\u8f93\u51fa\uff1a"rpl"\n\u89e3\u91ca\uff1a \n\u6211\u4eec\u4ee5 "abc" \u5f00\u59cb\u3002\n\u5c06 S \u4e2d\u7684\u7b2c 1 \u4e2a\u5b57\u6bcd\u79fb\u4f4d 3 \u6b21\u540e\uff0c\u6211\u4eec\u5f97\u5230 "dbc"\u3002\n\u518d\u5c06 S \u4e2d\u7684\u524d 2 \u4e2a\u5b57\u6bcd\u79fb\u4f4d 5 \u6b21\u540e\uff0c\u6211\u4eec\u5f97\u5230 "igc"\u3002\n\u6700\u540e\u5c06 S \u4e2d\u7684\u8fd9 3 \u4e2a\u5b57\u6bcd\u79fb\u4f4d 9 \u6b21\u540e\uff0c\u6211\u4eec\u5f97\u5230\u7b54\u6848 "rpl"\u3002\n
\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= S.length = shifts.length <= 20000
  2. \n\t
  3. 0 <= shifts[i] <= 10 ^ 9
  4. \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string shiftingLetters(string s, vector& shifts) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String shiftingLetters(String s, int[] shifts) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def shiftingLetters(self, s, shifts):\n \"\"\"\n :type s: str\n :type shifts: List[int]\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def shiftingLetters(self, s: str, shifts: List[int]) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * shiftingLetters(char * s, int* shifts, int shiftsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ShiftingLetters(string s, int[] shifts) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number[]} shifts\n * @return {string}\n */\nvar shiftingLetters = function(s, shifts) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer[]} shifts\n# @return {String}\ndef shifting_letters(s, shifts)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func shiftingLetters(_ s: String, _ shifts: [Int]) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func shiftingLetters(s string, shifts []int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def shiftingLetters(s: String, shifts: Array[Int]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun shiftingLetters(s: String, shifts: IntArray): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn shifting_letters(s: String, shifts: Vec) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer[] $shifts\n * @return String\n */\n function shiftingLetters($s, $shifts) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function shiftingLetters(s: string, shifts: number[]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (shifting-letters s shifts)\n (-> string? (listof exact-integer?) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0848](https://leetcode-cn.com/problems/shifting-letters)", "[\u5b57\u6bcd\u79fb\u4f4d](/solution/0800-0899/0848.Shifting%20Letters/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0848](https://leetcode.com/problems/shifting-letters)", "[Shifting Letters](/solution/0800-0899/0848.Shifting%20Letters/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "0877", "frontend_question_id": "0847", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/shortest-path-visiting-all-nodes", "url_en": "https://leetcode.com/problems/shortest-path-visiting-all-nodes", "relative_path_cn": "/solution/0800-0899/0847.Shortest%20Path%20Visiting%20All%20Nodes/README.md", "relative_path_en": "/solution/0800-0899/0847.Shortest%20Path%20Visiting%20All%20Nodes/README_EN.md", "title_cn": "\u8bbf\u95ee\u6240\u6709\u8282\u70b9\u7684\u6700\u77ed\u8def\u5f84", "title_en": "Shortest Path Visiting All Nodes", "question_title_slug": "shortest-path-visiting-all-nodes", "content_en": "

You have an undirected, connected graph of n nodes labeled from 0 to n - 1. You are given an array graph where graph[i] is a list of all the nodes connected with node i by an edge.

\n\n

Return the length of the shortest path that visits every node. You may start and stop at any node, you may revisit nodes multiple times, and you may reuse edges.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: graph = [[1,2,3],[0],[0],[0]]\nOutput: 4\nExplanation: One possible path is [1,0,2,0,3]\n
\n\n

Example 2:

\n\"\"\n
\nInput: graph = [[1],[0,2,4],[1,3,4],[2],[1,2]]\nOutput: 4\nExplanation: One possible path is [0,1,4,2,3]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == graph.length
  • \n\t
  • 1 <= n <= 12
  • \n\t
  • 0 <= graph[i].length < n
  • \n\t
  • graph[i] does not contain i.
  • \n\t
  • If graph[a] contains b, then graph[b] contains a.
  • \n\t
  • The input graph is always connected.
  • \n
\n", "content_cn": "

\u7ed9\u51fa graph \u4e3a\u6709 N \u4e2a\u8282\u70b9\uff08\u7f16\u53f7\u4e3a 0, 1, 2, ..., N-1\uff09\u7684\u65e0\u5411\u8fde\u901a\u56fe\u3002 

\n\n

graph.length = N\uff0c\u4e14\u53ea\u6709\u8282\u70b9 i \u548c j \u8fde\u901a\u65f6\uff0cj != i \u5728\u5217\u8868 graph[i] \u4e2d\u6070\u597d\u51fa\u73b0\u4e00\u6b21\u3002

\n\n

\u8fd4\u56de\u80fd\u591f\u8bbf\u95ee\u6240\u6709\u8282\u70b9\u7684\u6700\u77ed\u8def\u5f84\u7684\u957f\u5ea6\u3002\u4f60\u53ef\u4ee5\u5728\u4efb\u4e00\u8282\u70b9\u5f00\u59cb\u548c\u505c\u6b62\uff0c\u4e5f\u53ef\u4ee5\u591a\u6b21\u91cd\u8bbf\u8282\u70b9\uff0c\u5e76\u4e14\u53ef\u4ee5\u91cd\u7528\u8fb9\u3002

\n\n

 

\n\n
    \n
\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a[[1,2,3],[0],[0],[0]]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u4e00\u4e2a\u53ef\u80fd\u7684\u8def\u5f84\u4e3a [1,0,2,0,3]
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a[[1],[0,2,4],[1,3,4],[2],[1,2]]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u4e00\u4e2a\u53ef\u80fd\u7684\u8def\u5f84\u4e3a [0,1,4,2,3]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= graph.length <= 12
  2. \n\t
  3. 0 <= graph[i].length < graph.length
  4. \n
\n", "tags_en": ["Breadth-first Search", "Dynamic Programming"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int shortestPathLength(vector>& graph) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int shortestPathLength(int[][] graph) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def shortestPathLength(self, graph):\n \"\"\"\n :type graph: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def shortestPathLength(self, graph: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint shortestPathLength(int** graph, int graphSize, int* graphColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ShortestPathLength(int[][] graph) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} graph\n * @return {number}\n */\nvar shortestPathLength = function(graph) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} graph\n# @return {Integer}\ndef shortest_path_length(graph)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func shortestPathLength(_ graph: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func shortestPathLength(graph [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def shortestPathLength(graph: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun shortestPathLength(graph: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn shortest_path_length(graph: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $graph\n * @return Integer\n */\n function shortestPathLength($graph) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function shortestPathLength(graph: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (shortest-path-length graph)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0847](https://leetcode-cn.com/problems/shortest-path-visiting-all-nodes)", "[\u8bbf\u95ee\u6240\u6709\u8282\u70b9\u7684\u6700\u77ed\u8def\u5f84](/solution/0800-0899/0847.Shortest%20Path%20Visiting%20All%20Nodes/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0847](https://leetcode.com/problems/shortest-path-visiting-all-nodes)", "[Shortest Path Visiting All Nodes](/solution/0800-0899/0847.Shortest%20Path%20Visiting%20All%20Nodes/README_EN.md)", "`Breadth-first Search`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0876", "frontend_question_id": "0846", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/hand-of-straights", "url_en": "https://leetcode.com/problems/hand-of-straights", "relative_path_cn": "/solution/0800-0899/0846.Hand%20of%20Straights/README.md", "relative_path_en": "/solution/0800-0899/0846.Hand%20of%20Straights/README_EN.md", "title_cn": "\u4e00\u624b\u987a\u5b50", "title_en": "Hand of Straights", "question_title_slug": "hand-of-straights", "content_en": "

Alice has a hand of cards, given as an array of integers.

\n\n

Now she wants to rearrange the cards into groups so that each group is size groupSize, and consists of groupSize consecutive cards.

\n\n

Return true if and only if she can.

\n\n

Note: This question is the same as 1296: https://leetcode.com/problems/divide-array-in-sets-of-k-consecutive-numbers/

\n\n

 

\n

Example 1:

\n\n
\nInput: hand = [1,2,3,6,2,3,4,7,8], groupSize = 3\nOutput: true\nExplanation: Alice's hand can be rearranged as [1,2,3],[2,3,4],[6,7,8]\n
\n\n

Example 2:

\n\n
\nInput: hand = [1,2,3,4,5], groupSize = 4\nOutput: false\nExplanation: Alice's hand can't be rearranged into groups of 4.\n\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= hand.length <= 10000
  • \n\t
  • 0 <= hand[i] <= 109
  • \n\t
  • 1 <= groupSize <= hand.length
  • \n
\n", "content_cn": "

\u7231\u4e3d\u4e1d\u6709\u4e00\u624b\uff08hand\uff09\u7531\u6574\u6570\u6570\u7ec4\u7ed9\u5b9a\u7684\u724c\u3002\u00a0

\n\n

\u73b0\u5728\u5979\u60f3\u628a\u724c\u91cd\u65b0\u6392\u5217\u6210\u7ec4\uff0c\u4f7f\u5f97\u6bcf\u4e2a\u7ec4\u7684\u5927\u5c0f\u90fd\u662f W\uff0c\u4e14\u7531 W \u5f20\u8fde\u7eed\u7684\u724c\u7ec4\u6210\u3002

\n\n

\u5982\u679c\u5979\u53ef\u4ee5\u5b8c\u6210\u5206\u7ec4\u5c31\u8fd4\u56de true\uff0c\u5426\u5219\u8fd4\u56de false\u3002

\n\n

\u00a0

\n\n

\u6ce8\u610f\uff1a\u6b64\u9898\u76ee\u4e0e 1296 \u91cd\u590d\uff1ahttps://leetcode-cn.com/problems/divide-array-in-sets-of-k-consecutive-numbers/

\n\n

\u00a0

\n\n
    \n
\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1ahand = [1,2,3,6,2,3,4,7,8], W = 3\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u7231\u4e3d\u4e1d\u7684\u624b\u724c\u53ef\u4ee5\u88ab\u91cd\u65b0\u6392\u5217\u4e3a [1,2,3]\uff0c[2,3,4]\uff0c[6,7,8]\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1ahand = [1,2,3,4,5], W = 4\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u7231\u4e3d\u4e1d\u7684\u624b\u724c\u65e0\u6cd5\u88ab\u91cd\u65b0\u6392\u5217\u6210\u51e0\u4e2a\u5927\u5c0f\u4e3a 4 \u7684\u7ec4\u3002
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= hand.length <= 10000
  • \n\t
  • 0 <= hand[i]\u00a0<= 10^9
  • \n\t
  • 1 <= W <= hand.length
  • \n
\n", "tags_en": ["Ordered Map"], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isNStraightHand(vector& hand, int groupSize) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isNStraightHand(int[] hand, int groupSize) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isNStraightHand(self, hand, groupSize):\n \"\"\"\n :type hand: List[int]\n :type groupSize: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isNStraightHand(self, hand: List[int], groupSize: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isNStraightHand(int* hand, int handSize, int groupSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsNStraightHand(int[] hand, int groupSize) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} hand\n * @param {number} groupSize\n * @return {boolean}\n */\nvar isNStraightHand = function(hand, groupSize) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} hand\n# @param {Integer} group_size\n# @return {Boolean}\ndef is_n_straight_hand(hand, group_size)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isNStraightHand(_ hand: [Int], _ groupSize: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isNStraightHand(hand []int, groupSize int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isNStraightHand(hand: Array[Int], groupSize: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isNStraightHand(hand: IntArray, groupSize: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_n_straight_hand(hand: Vec, group_size: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $hand\n * @param Integer $groupSize\n * @return Boolean\n */\n function isNStraightHand($hand, $groupSize) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isNStraightHand(hand: number[], groupSize: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-n-straight-hand hand groupSize)\n (-> (listof exact-integer?) exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0846](https://leetcode-cn.com/problems/hand-of-straights)", "[\u4e00\u624b\u987a\u5b50](/solution/0800-0899/0846.Hand%20of%20Straights/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0846](https://leetcode.com/problems/hand-of-straights)", "[Hand of Straights](/solution/0800-0899/0846.Hand%20of%20Straights/README_EN.md)", "`Ordered Map`", "Medium", ""]}, {"question_id": "0875", "frontend_question_id": "0845", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-mountain-in-array", "url_en": "https://leetcode.com/problems/longest-mountain-in-array", "relative_path_cn": "/solution/0800-0899/0845.Longest%20Mountain%20in%20Array/README.md", "relative_path_en": "/solution/0800-0899/0845.Longest%20Mountain%20in%20Array/README_EN.md", "title_cn": "\u6570\u7ec4\u4e2d\u7684\u6700\u957f\u5c71\u8109", "title_en": "Longest Mountain in Array", "question_title_slug": "longest-mountain-in-array", "content_en": "

You may recall that an array arr is a mountain array if and only if:

\n\n
    \n\t
  • arr.length >= 3
  • \n\t
  • There exists some index i (0-indexed) with 0 < i < arr.length - 1 such that:\n\t
      \n\t\t
    • arr[0] < arr[1] < ... < arr[i - 1] < arr[i]
    • \n\t\t
    • arr[i] > arr[i + 1] > ... > arr[arr.length - 1]
    • \n\t
    \n\t
  • \n
\n\n

Given an integer array arr, return the length of the longest subarray, which is a mountain. Return 0 if there is no mountain subarray.

\n\n

 

\n

Example 1:

\n\n
\nInput: arr = [2,1,4,7,3,2,5]\nOutput: 5\nExplanation: The largest mountain is [1,4,7,3,2] which has length 5.\n
\n\n

Example 2:

\n\n
\nInput: arr = [2,2,2]\nOutput: 0\nExplanation: There is no mountain.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= arr.length <= 104
  • \n\t
  • 0 <= arr[i] <= 104
  • \n
\n\n

 

\n

Follow up:

\n\n
    \n\t
  • Can you solve it using only one pass?
  • \n\t
  • Can you solve it in O(1) space?
  • \n
\n", "content_cn": "

\u6211\u4eec\u628a\u6570\u7ec4 A \u4e2d\u7b26\u5408\u4e0b\u5217\u5c5e\u6027\u7684\u4efb\u610f\u8fde\u7eed\u5b50\u6570\u7ec4 B \u79f0\u4e3a “\u5c71\u8109”\uff1a

\n\n
    \n\t
  • B.length >= 3
  • \n\t
  • \u5b58\u5728 0 < i < B.length - 1 \u4f7f\u5f97 B[0] < B[1] < ... B[i-1] < B[i] > B[i+1] > ... > B[B.length - 1]
  • \n
\n\n

\uff08\u6ce8\u610f\uff1aB \u53ef\u4ee5\u662f A \u7684\u4efb\u610f\u5b50\u6570\u7ec4\uff0c\u5305\u62ec\u6574\u4e2a\u6570\u7ec4 A\u3002\uff09

\n\n

\u7ed9\u51fa\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 A\uff0c\u8fd4\u56de\u6700\u957f “\u5c71\u8109” \u7684\u957f\u5ea6\u3002

\n\n

\u5982\u679c\u4e0d\u542b\u6709 “\u5c71\u8109” \u5219\u8fd4\u56de 0\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a[2,1,4,7,3,2,5]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u6700\u957f\u7684 “\u5c71\u8109” \u662f [1,4,7,3,2]\uff0c\u957f\u5ea6\u4e3a 5\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a[2,2,2]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u4e0d\u542b “\u5c71\u8109”\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 0 <= A.length <= 10000
  2. \n\t
  3. 0 <= A[i] <= 10000
  4. \n
\n", "tags_en": ["Two Pointers"], "tags_cn": ["\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int longestMountain(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int longestMountain(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestMountain(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestMountain(self, arr: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint longestMountain(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LongestMountain(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar longestMountain = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef longest_mountain(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestMountain(_ arr: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestMountain(arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestMountain(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestMountain(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_mountain(arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function longestMountain($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestMountain(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-mountain arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0845](https://leetcode-cn.com/problems/longest-mountain-in-array)", "[\u6570\u7ec4\u4e2d\u7684\u6700\u957f\u5c71\u8109](/solution/0800-0899/0845.Longest%20Mountain%20in%20Array/README.md)", "`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0845](https://leetcode.com/problems/longest-mountain-in-array)", "[Longest Mountain in Array](/solution/0800-0899/0845.Longest%20Mountain%20in%20Array/README_EN.md)", "`Two Pointers`", "Medium", ""]}, {"question_id": "0874", "frontend_question_id": "0844", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/backspace-string-compare", "url_en": "https://leetcode.com/problems/backspace-string-compare", "relative_path_cn": "/solution/0800-0899/0844.Backspace%20String%20Compare/README.md", "relative_path_en": "/solution/0800-0899/0844.Backspace%20String%20Compare/README_EN.md", "title_cn": "\u6bd4\u8f83\u542b\u9000\u683c\u7684\u5b57\u7b26\u4e32", "title_en": "Backspace String Compare", "question_title_slug": "backspace-string-compare", "content_en": "

Given two strings s and t, return true if they are equal when both are typed into empty text editors. '#' means a backspace character.

\n\n

Note that after backspacing an empty text, the text will continue empty.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "ab#c", t = "ad#c"\nOutput: true\nExplanation: Both s and t become "ac".\n
\n\n

Example 2:

\n\n
\nInput: s = "ab##", t = "c#d#"\nOutput: true\nExplanation: Both s and t become "".\n
\n\n

Example 3:

\n\n
\nInput: s = "a##c", t = "#a#c"\nOutput: true\nExplanation: Both s and t become "c".\n
\n\n

Example 4:

\n\n
\nInput: s = "a#c", t = "b"\nOutput: false\nExplanation: s becomes "c" while t becomes "b".\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length, t.length <= 200
  • \n\t
  • s and t only contain lowercase letters and '#' characters.
  • \n
\n\n

 

\n

Follow up: Can you solve it in O(n) time and O(1) space?

\n", "content_cn": "

\u7ed9\u5b9a S \u548c T \u4e24\u4e2a\u5b57\u7b26\u4e32\uff0c\u5f53\u5b83\u4eec\u5206\u522b\u88ab\u8f93\u5165\u5230\u7a7a\u767d\u7684\u6587\u672c\u7f16\u8f91\u5668\u540e\uff0c\u5224\u65ad\u4e8c\u8005\u662f\u5426\u76f8\u7b49\uff0c\u5e76\u8fd4\u56de\u7ed3\u679c\u3002 # \u4ee3\u8868\u9000\u683c\u5b57\u7b26\u3002

\n\n

\u6ce8\u610f\uff1a\u5982\u679c\u5bf9\u7a7a\u6587\u672c\u8f93\u5165\u9000\u683c\u5b57\u7b26\uff0c\u6587\u672c\u7ee7\u7eed\u4e3a\u7a7a\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aS = \"ab#c\", T = \"ad#c\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1aS \u548c T \u90fd\u4f1a\u53d8\u6210 \u201cac\u201d\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aS = \"ab##\", T = \"c#d#\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1aS \u548c T \u90fd\u4f1a\u53d8\u6210 \u201c\u201d\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1aS = \"a##c\", T = \"#a#c\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1aS \u548c T \u90fd\u4f1a\u53d8\u6210 \u201cc\u201d\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1aS = \"a#c\", T = \"b\"\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1aS \u4f1a\u53d8\u6210 \u201cc\u201d\uff0c\u4f46 T \u4ecd\u7136\u662f \u201cb\u201d\u3002
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= S.length <= 200
  • \n\t
  • 1 <= T.length <= 200
  • \n\t
  • S \u548c T \u53ea\u542b\u6709\u5c0f\u5199\u5b57\u6bcd\u4ee5\u53ca\u5b57\u7b26 '#'\u3002
  • \n
\n\n

\u00a0

\n\n

\u8fdb\u9636\uff1a

\n\n
    \n\t
  • \u4f60\u53ef\u4ee5\u7528 O(N) \u7684\u65f6\u95f4\u590d\u6742\u5ea6\u548c O(1) \u7684\u7a7a\u95f4\u590d\u6742\u5ea6\u89e3\u51b3\u8be5\u95ee\u9898\u5417\uff1f
  • \n
\n\n

\u00a0

\n", "tags_en": ["Stack", "Two Pointers"], "tags_cn": ["\u6808", "\u53cc\u6307\u9488"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool backspaceCompare(string s, string t) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean backspaceCompare(String s, String t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def backspaceCompare(self, s, t):\n \"\"\"\n :type s: str\n :type t: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def backspaceCompare(self, s: str, t: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool backspaceCompare(char * s, char * t){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool BackspaceCompare(string s, string t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string} t\n * @return {boolean}\n */\nvar backspaceCompare = function(s, t) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String} t\n# @return {Boolean}\ndef backspace_compare(s, t)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func backspaceCompare(_ s: String, _ t: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func backspaceCompare(s string, t string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def backspaceCompare(s: String, t: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun backspaceCompare(s: String, t: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn backspace_compare(s: String, t: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String $t\n * @return Boolean\n */\n function backspaceCompare($s, $t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function backspaceCompare(s: string, t: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (backspace-compare s t)\n (-> string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0844](https://leetcode-cn.com/problems/backspace-string-compare)", "[\u6bd4\u8f83\u542b\u9000\u683c\u7684\u5b57\u7b26\u4e32](/solution/0800-0899/0844.Backspace%20String%20Compare/README.md)", "`\u6808`,`\u53cc\u6307\u9488`", "\u7b80\u5355", ""], "md_table_row_en": ["[0844](https://leetcode.com/problems/backspace-string-compare)", "[Backspace String Compare](/solution/0800-0899/0844.Backspace%20String%20Compare/README_EN.md)", "`Stack`,`Two Pointers`", "Easy", ""]}, {"question_id": "0873", "frontend_question_id": "0843", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/guess-the-word", "url_en": "https://leetcode.com/problems/guess-the-word", "relative_path_cn": "/solution/0800-0899/0843.Guess%20the%20Word/README.md", "relative_path_en": "/solution/0800-0899/0843.Guess%20the%20Word/README_EN.md", "title_cn": "\u731c\u731c\u8fd9\u4e2a\u5355\u8bcd", "title_en": "Guess the Word", "question_title_slug": "guess-the-word", "content_en": "

This is an interactive problem.

\n\n

You are given an array of unique strings wordlist where wordlist[i] is 6 letters long, and one word in this list is chosen as secret.

\n\n

You may call Master.guess(word) to guess a word. The guessed word should have type string and must be from the original list with 6 lowercase letters.

\n\n

This function returns an integer type, representing the number of exact matches (value and position) of your guess to the secret word. Also, if your guess is not in the given wordlist, it will return -1 instead.

\n\n

For each test case, you have exactly 10 guesses to guess the word. At the end of any number of calls, if you have made 10 or fewer calls to Master.guess and at least one of these guesses was secret, then you pass the test case.

\n\n

 

\n

Example 1:

\n\n
\nInput: secret = "acckzz", wordlist = ["acckzz","ccbazz","eiowzz","abcczz"], numguesses = 10\nOutput: You guessed the secret word correctly.\nExplanation:\nmaster.guess("aaaaaa") returns -1, because "aaaaaa" is not in wordlist.\nmaster.guess("acckzz") returns 6, because "acckzz" is secret and has all 6 matches.\nmaster.guess("ccbazz") returns 3, because "ccbazz" has 3 matches.\nmaster.guess("eiowzz") returns 2, because "eiowzz" has 2 matches.\nmaster.guess("abcczz") returns 4, because "abcczz" has 4 matches.\nWe made 5 calls to master.guess and one of them was the secret, so we pass the test case.\n
\n\n

Example 2:

\n\n
\nInput: secret = "hamada", wordlist = ["hamada","khaled"], numguesses = 10\nOutput: You guessed the secret word correctly.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= wordlist.length <= 100
  • \n\t
  • wordlist[i].length == 6
  • \n\t
  • wordlist[i] consist of lowercase English letters.
  • \n\t
  • All the strings of wordlist are unique.
  • \n\t
  • secret exists in wordlist.
  • \n\t
  • numguesses == 10
  • \n
\n", "content_cn": "

\u8fd9\u4e2a\u95ee\u9898\u662f LeetCode \u5e73\u53f0\u65b0\u589e\u7684\u4ea4\u4e92\u5f0f\u95ee\u9898 \u3002

\n\n

\u6211\u4eec\u7ed9\u51fa\u4e86\u4e00\u4e2a\u7531\u4e00\u4e9b\u72ec\u7279\u7684\u5355\u8bcd\u7ec4\u6210\u7684\u5355\u8bcd\u5217\u8868\uff0c\u6bcf\u4e2a\u5355\u8bcd\u90fd\u662f 6 \u4e2a\u5b57\u6bcd\u957f\uff0c\u5e76\u4e14\u8fd9\u4e2a\u5217\u8868\u4e2d\u7684\u4e00\u4e2a\u5355\u8bcd\u5c06\u88ab\u9009\u4f5c\u79d8\u5bc6\u3002

\n\n

\u4f60\u53ef\u4ee5\u8c03\u7528 master.guess(word) \u6765\u731c\u5355\u8bcd\u3002\u4f60\u6240\u731c\u7684\u5355\u8bcd\u5e94\u5f53\u662f\u5b58\u5728\u4e8e\u539f\u5217\u8868\u5e76\u4e14\u7531 6 \u4e2a\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210\u7684\u7c7b\u578b\u5b57\u7b26\u4e32\u3002

\n\n

\u6b64\u51fd\u6570\u5c06\u4f1a\u8fd4\u56de\u4e00\u4e2a\u6574\u578b\u6570\u5b57\uff0c\u8868\u793a\u4f60\u7684\u731c\u6d4b\u4e0e\u79d8\u5bc6\u5355\u8bcd\u7684\u51c6\u786e\u5339\u914d\uff08\u503c\u548c\u4f4d\u7f6e\u540c\u65f6\u5339\u914d\uff09\u7684\u6570\u76ee\u3002\u6b64\u5916\uff0c\u5982\u679c\u4f60\u7684\u731c\u6d4b\u4e0d\u5728\u7ed9\u5b9a\u7684\u5355\u8bcd\u5217\u8868\u4e2d\uff0c\u5b83\u5c06\u8fd4\u56de -1\u3002

\n\n

\u5bf9\u4e8e\u6bcf\u4e2a\u6d4b\u8bd5\u7528\u4f8b\uff0c\u4f60\u6709 10 \u6b21\u673a\u4f1a\u6765\u731c\u51fa\u8fd9\u4e2a\u5355\u8bcd\u3002\u5f53\u6240\u6709\u8c03\u7528\u90fd\u7ed3\u675f\u65f6\uff0c\u5982\u679c\u60a8\u5bf9 master.guess \u7684\u8c03\u7528\u4e0d\u8d85\u8fc7 10 \u6b21\uff0c\u5e76\u4e14\u81f3\u5c11\u6709\u4e00\u6b21\u731c\u5230\u79d8\u5bc6\uff0c\u90a3\u4e48\u60a8\u5c06\u901a\u8fc7\u8be5\u6d4b\u8bd5\u7528\u4f8b\u3002

\n\n

\u9664\u4e86\u4e0b\u9762\u793a\u4f8b\u7ed9\u51fa\u7684\u6d4b\u8bd5\u7528\u4f8b\u5916\uff0c\u8fd8\u4f1a\u6709 5 \u4e2a\u989d\u5916\u7684\u6d4b\u8bd5\u7528\u4f8b\uff0c\u6bcf\u4e2a\u5355\u8bcd\u5217\u8868\u4e2d\u5c06\u4f1a\u6709 100 \u4e2a\u5355\u8bcd\u3002\u8fd9\u4e9b\u6d4b\u8bd5\u7528\u4f8b\u4e2d\u7684\u6bcf\u4e2a\u5355\u8bcd\u7684\u5b57\u6bcd\u90fd\u662f\u4ece 'a' \u5230 'z' \u4e2d\u968f\u673a\u9009\u53d6\u7684\uff0c\u5e76\u4e14\u4fdd\u8bc1\u7ed9\u5b9a\u5355\u8bcd\u5217\u8868\u4e2d\u7684\u6bcf\u4e2a\u5355\u8bcd\u90fd\u662f\u552f\u4e00\u7684\u3002

\n\n
\u793a\u4f8b 1:\n\u8f93\u5165: secret = "acckzz", wordlist = ["acckzz","ccbazz","eiowzz","abcczz"]\n\n\u89e3\u91ca:\n\nmaster.guess("aaaaaa") \u8fd4\u56de -1, \u56e0\u4e3a "aaaaaa" \u4e0d\u5728 wordlist \u4e2d.\nmaster.guess("acckzz") \u8fd4\u56de 6, \u56e0\u4e3a "acckzz" \u5c31\u662f\u79d8\u5bc6\uff0c6\u4e2a\u5b57\u6bcd\u5b8c\u5168\u5339\u914d\u3002\nmaster.guess("ccbazz") \u8fd4\u56de 3, \u56e0\u4e3a "ccbazz" \u6709 3 \u4e2a\u5339\u914d\u9879\u3002\nmaster.guess("eiowzz") \u8fd4\u56de 2, \u56e0\u4e3a "eiowzz" \u6709 2 \u4e2a\u5339\u914d\u9879\u3002\nmaster.guess("abcczz") \u8fd4\u56de 4, \u56e0\u4e3a "abcczz" \u6709 4 \u4e2a\u5339\u914d\u9879\u3002\n\n\u6211\u4eec\u8c03\u7528\u4e86 5 \u6b21master.guess\uff0c\u5176\u4e2d\u4e00\u6b21\u731c\u5230\u4e86\u79d8\u5bc6\uff0c\u6240\u4ee5\u6211\u4eec\u901a\u8fc7\u4e86\u8fd9\u4e2a\u6d4b\u8bd5\u7528\u4f8b\u3002\n
\n\n

\u63d0\u793a\uff1a\u4efb\u4f55\u8bd5\u56fe\u7ed5\u8fc7\u8bc4\u5224\u7684\u89e3\u51b3\u65b9\u6848\u90fd\u5c06\u5bfc\u81f4\u6bd4\u8d5b\u8d44\u683c\u88ab\u53d6\u6d88\u3002

\n", "tags_en": ["Minimax"], "tags_cn": ["\u6781\u5c0f\u5316\u6781\u5927"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * // This is the Master's API interface.\n * // You should not implement it, or speculate about its implementation\n * class Master {\n * public:\n * int guess(string word);\n * };\n */\nclass Solution {\npublic:\n void findSecretWord(vector& wordlist, Master& master) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * // This is the Master's API interface.\n * // You should not implement it, or speculate about its implementation\n * interface Master {\n * public int guess(String word) {}\n * }\n */\nclass Solution {\n public void findSecretWord(String[] wordlist, Master master) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# \"\"\"\n# This is Master's API interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class Master(object):\n# def guess(self, word):\n# \"\"\"\n# :type word: str\n# :rtype int\n# \"\"\"\n\nclass Solution(object):\n def findSecretWord(self, wordlist, master):\n \"\"\"\n :type wordlist: List[Str]\n :type master: Master\n :rtype: None\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# \"\"\"\n# This is Master's API interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n# class Master:\n# def guess(self, word: str) -> int:\n\nclass Solution:\n def findSecretWord(self, wordlist: List[str], master: 'Master') -> None:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * *********************************************************************\n * // This is the Master's API interface.\n * // You should not implement it, or speculate about its implementation\n * *********************************************************************\n *\n * int guess(Master *, char *word);\n */\nvoid findSecretWord(char** wordlist, int wordlistSize, Master* master) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * // This is the Master's API interface.\n * // You should not implement it, or speculate about its implementation\n * class Master {\n * public int Guess(string word);\n * }\n */\nclass Solution {\n public void FindSecretWord(string[] wordlist, Master master) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // This is the master's API interface.\n * // You should not implement it, or speculate about its implementation\n * function Master() {\n *\n * @param {string[]} wordlist\n * @param {Master} master\n * @return {integer}\n * this.guess = function(word) {\n * ...\n * };\n * };\n */\n/**\n * @param {string[]} wordlist\n * @param {Master} master\n * @return {void}\n */\nvar findSecretWord = function(wordlist, master) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# This is Master's API interface.\n# You should not implement it, or speculate about its implementation\n#\n# class Master\n# =begin\n# :type word: String\n# :rtype: Integer\n# =end\n# def guess(word)\n# ...\n# end\n# end\n#\n\n# @param {String[]} wordlist\n# @param {Master} master\n# @return {Void}\ndef find_secret_word(wordlist, master)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * // This is the Master's API interface.\n * // You should not implement it, or speculate about its implementation\n * class Master {\n * public func guess(word: String) -> Int {}\n * }\n */\nclass Solution {\n func findSecretWord(_ wordlist: [String], _ master: Master) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * // This is the Master's API interface.\n * // You should not implement it, or speculate about its implementation\n * type Master struct {\n * }\n *\n * func (this *Master) Guess(word string) int {}\n */\nfunc findSecretWord(wordlist []string, master *Master) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * // This is the Master's API interface.\n * // You should not implement it, or speculate about its implementation\n * class Master {\n *\n * def guess(word: String): Int = {}\n *\n * }\n */\nobject Solution {\n def findSecretWord(wordlist: Array[String], master: Master): Unit = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * // This is the Master's API interface.\n * // You should not implement it, or speculate about its implementation\n * interface Master {\n * fun guess(word: String): Int {}\n * }\n */\nclass Solution {\n fun findSecretWord(wordlist: Array, master: Master) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "/**\n * // This is the Master's API interface.\n * // You should not implement it, or speculate about its implementation\n * struct Master;\n * impl Master {\n * fn guess(word:String)->int;\n * };\n */\n\nimpl Solution {\n pub fn find_secret_word(words: Vec, master: &Master) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * // This is the Master's API interface.\n * // You should not implement it, or speculate about its implementation\n * interface Master {\n * function guess($word) {}\n * }\n */\n\nclass Solution {\n /**\n * @param String[] $wordlist\n * @param Master $master\n * @return \n */\n function findSecretWord($wordlist, $master) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * // This is the Master's API interface.\n * // You should not implement it, or speculate about its implementation\n * class Master {\n * guess(word: string): number {}\n * }\n */\n\nfunction findSecretWord(wordlist: string[], master: Master) {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0843](https://leetcode-cn.com/problems/guess-the-word)", "[\u731c\u731c\u8fd9\u4e2a\u5355\u8bcd](/solution/0800-0899/0843.Guess%20the%20Word/README.md)", "`\u6781\u5c0f\u5316\u6781\u5927`", "\u56f0\u96be", ""], "md_table_row_en": ["[0843](https://leetcode.com/problems/guess-the-word)", "[Guess the Word](/solution/0800-0899/0843.Guess%20the%20Word/README_EN.md)", "`Minimax`", "Hard", ""]}, {"question_id": "0872", "frontend_question_id": "0842", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/split-array-into-fibonacci-sequence", "url_en": "https://leetcode.com/problems/split-array-into-fibonacci-sequence", "relative_path_cn": "/solution/0800-0899/0842.Split%20Array%20into%20Fibonacci%20Sequence/README.md", "relative_path_en": "/solution/0800-0899/0842.Split%20Array%20into%20Fibonacci%20Sequence/README_EN.md", "title_cn": "\u5c06\u6570\u7ec4\u62c6\u5206\u6210\u6590\u6ce2\u90a3\u5951\u5e8f\u5217", "title_en": "Split Array into Fibonacci Sequence", "question_title_slug": "split-array-into-fibonacci-sequence", "content_en": "

You are given a string of digits num, such as "123456579". We can split it into a Fibonacci-like sequence [123, 456, 579].

\n\n

Formally, a Fibonacci-like sequence is a list f of non-negative integers such that:

\n\n
    \n\t
  • 0 <= f[i] < 231, (that is, each integer fits in a 32-bit signed integer type),
  • \n\t
  • f.length >= 3, and
  • \n\t
  • f[i] + f[i + 1] == f[i + 2] for all 0 <= i < f.length - 2.
  • \n
\n\n

Note that when splitting the string into pieces, each piece must not have extra leading zeroes, except if the piece is the number 0 itself.

\n\n

Return any Fibonacci-like sequence split from num, or return [] if it cannot be done.

\n\n

 

\n

Example 1:

\n\n
\nInput: num = "123456579"\nOutput: [123,456,579]\n
\n\n

Example 2:

\n\n
\nInput: num = "11235813"\nOutput: [1,1,2,3,5,8,13]\n
\n\n

Example 3:

\n\n
\nInput: num = "112358130"\nOutput: []\nExplanation: The task is impossible.\n
\n\n

Example 4:

\n\n
\nInput: num = "0123"\nOutput: []\nExplanation: Leading zeroes are not allowed, so "01", "2", "3" is not valid.\n
\n\n

Example 5:

\n\n
\nInput: num = "1101111"\nOutput: [11,0,11,11]\nExplanation: The output [11, 0, 11, 11] would also be accepted.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= num.length <= 200
  • \n\t
  • num contains only digits.
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u6570\u5b57\u5b57\u7b26\u4e32 S\uff0c\u6bd4\u5982 S = "123456579"\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u5b83\u5206\u6210\u6590\u6ce2\u90a3\u5951\u5f0f\u7684\u5e8f\u5217 [123, 456, 579]\u3002

\n\n

\u5f62\u5f0f\u4e0a\uff0c\u6590\u6ce2\u90a3\u5951\u5f0f\u5e8f\u5217\u662f\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\u5217\u8868 F\uff0c\u4e14\u6ee1\u8db3\uff1a

\n\n
    \n\t
  • 0 <= F[i] <= 2^31 - 1\uff0c\uff08\u4e5f\u5c31\u662f\u8bf4\uff0c\u6bcf\u4e2a\u6574\u6570\u90fd\u7b26\u5408 32 \u4f4d\u6709\u7b26\u53f7\u6574\u6570\u7c7b\u578b\uff09\uff1b
  • \n\t
  • F.length >= 3\uff1b
  • \n\t
  • \u5bf9\u4e8e\u6240\u6709\u76840 <= i < F.length - 2\uff0c\u90fd\u6709 F[i] + F[i+1] = F[i+2] \u6210\u7acb\u3002
  • \n
\n\n

\u53e6\u5916\uff0c\u8bf7\u6ce8\u610f\uff0c\u5c06\u5b57\u7b26\u4e32\u62c6\u5206\u6210\u5c0f\u5757\u65f6\uff0c\u6bcf\u4e2a\u5757\u7684\u6570\u5b57\u4e00\u5b9a\u4e0d\u8981\u4ee5\u96f6\u5f00\u5934\uff0c\u9664\u975e\u8fd9\u4e2a\u5757\u662f\u6570\u5b57 0 \u672c\u8eab\u3002

\n\n

\u8fd4\u56de\u4ece S \u62c6\u5206\u51fa\u6765\u7684\u4efb\u610f\u4e00\u7ec4\u6590\u6ce2\u90a3\u5951\u5f0f\u7684\u5e8f\u5217\u5757\uff0c\u5982\u679c\u4e0d\u80fd\u62c6\u5206\u5219\u8fd4\u56de []\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a"123456579"\n\u8f93\u51fa\uff1a[123,456,579]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165: "11235813"\n\u8f93\u51fa: [1,1,2,3,5,8,13]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165: "112358130"\n\u8f93\u51fa: []\n\u89e3\u91ca: \u8fd9\u9879\u4efb\u52a1\u65e0\u6cd5\u5b8c\u6210\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1a"0123"\n\u8f93\u51fa\uff1a[]\n\u89e3\u91ca\uff1a\u6bcf\u4e2a\u5757\u7684\u6570\u5b57\u4e0d\u80fd\u4ee5\u96f6\u5f00\u5934\uff0c\u56e0\u6b64 "01"\uff0c"2"\uff0c"3" \u4e0d\u662f\u6709\u6548\u7b54\u6848\u3002\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165: "1101111"\n\u8f93\u51fa: [110, 1, 111]\n\u89e3\u91ca: \u8f93\u51fa [11,0,11,11] \u4e5f\u540c\u6837\u88ab\u63a5\u53d7\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= S.length <= 200
  2. \n\t
  3. \u5b57\u7b26\u4e32 S \u4e2d\u53ea\u542b\u6709\u6570\u5b57\u3002
  4. \n
\n", "tags_en": ["Greedy", "String", "Backtracking"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u5b57\u7b26\u4e32", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector splitIntoFibonacci(string num) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List splitIntoFibonacci(String num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def splitIntoFibonacci(self, num):\n \"\"\"\n :type num: str\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def splitIntoFibonacci(self, num: str) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* splitIntoFibonacci(char * num, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList SplitIntoFibonacci(string num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} num\n * @return {number[]}\n */\nvar splitIntoFibonacci = function(num) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} num\n# @return {Integer[]}\ndef split_into_fibonacci(num)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func splitIntoFibonacci(_ num: String) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func splitIntoFibonacci(num string) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def splitIntoFibonacci(num: String): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun splitIntoFibonacci(num: String): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn split_into_fibonacci(num: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $num\n * @return Integer[]\n */\n function splitIntoFibonacci($num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function splitIntoFibonacci(num: string): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (split-into-fibonacci num)\n (-> string? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0842](https://leetcode-cn.com/problems/split-array-into-fibonacci-sequence)", "[\u5c06\u6570\u7ec4\u62c6\u5206\u6210\u6590\u6ce2\u90a3\u5951\u5e8f\u5217](/solution/0800-0899/0842.Split%20Array%20into%20Fibonacci%20Sequence/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u5b57\u7b26\u4e32`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0842](https://leetcode.com/problems/split-array-into-fibonacci-sequence)", "[Split Array into Fibonacci Sequence](/solution/0800-0899/0842.Split%20Array%20into%20Fibonacci%20Sequence/README_EN.md)", "`Greedy`,`String`,`Backtracking`", "Medium", ""]}, {"question_id": "0871", "frontend_question_id": "0841", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/keys-and-rooms", "url_en": "https://leetcode.com/problems/keys-and-rooms", "relative_path_cn": "/solution/0800-0899/0841.Keys%20and%20Rooms/README.md", "relative_path_en": "/solution/0800-0899/0841.Keys%20and%20Rooms/README_EN.md", "title_cn": "\u94a5\u5319\u548c\u623f\u95f4", "title_en": "Keys and Rooms", "question_title_slug": "keys-and-rooms", "content_en": "

There are N rooms and you start in room 0.  Each room has a distinct number in 0, 1, 2, ..., N-1, and each room may have some keys to access the next room. 

\r\n\r\n

Formally, each room i has a list of keys rooms[i], and each key rooms[i][j] is an integer in [0, 1, ..., N-1] where N = rooms.length.  A key rooms[i][j] = v opens the room with number v.

\r\n\r\n

Initially, all the rooms start locked (except for room 0). 

\r\n\r\n

You can walk back and forth between rooms freely.

\r\n\r\n

Return true if and only if you can enter every room.

\r\n\r\n
    \r\n
\r\n\r\n

Example 1:

\r\n\r\n
\r\nInput: [[1],[2],[3],[]]\r\nOutput: true\r\nExplanation:  \r\nWe start in room 0, and pick up key 1.\r\nWe then go to room 1, and pick up key 2.\r\nWe then go to room 2, and pick up key 3.\r\nWe then go to room 3.  Since we were able to go to every room, we return true.\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: [[1,3],[3,0,1],[2],[0]]\r\nOutput: false\r\nExplanation: We can't enter the room with number 2.\r\n
\r\n\r\n

Note:

\r\n\r\n
    \r\n\t
  1. 1 <= rooms.length <= 1000
  2. \r\n\t
  3. 0 <= rooms[i].length <= 1000
  4. \r\n\t
  5. The number of keys in all rooms combined is at most 3000.
  6. \r\n
\r\n", "content_cn": "

\u6709 N \u4e2a\u623f\u95f4\uff0c\u5f00\u59cb\u65f6\u4f60\u4f4d\u4e8e 0 \u53f7\u623f\u95f4\u3002\u6bcf\u4e2a\u623f\u95f4\u6709\u4e0d\u540c\u7684\u53f7\u7801\uff1a0\uff0c1\uff0c2\uff0c...\uff0cN-1\uff0c\u5e76\u4e14\u623f\u95f4\u91cc\u53ef\u80fd\u6709\u4e00\u4e9b\u94a5\u5319\u80fd\u4f7f\u4f60\u8fdb\u5165\u4e0b\u4e00\u4e2a\u623f\u95f4\u3002

\n\n

\u5728\u5f62\u5f0f\u4e0a\uff0c\u5bf9\u4e8e\u6bcf\u4e2a\u623f\u95f4 i \u90fd\u6709\u4e00\u4e2a\u94a5\u5319\u5217\u8868 rooms[i]\uff0c\u6bcf\u4e2a\u94a5\u5319 rooms[i][j] \u7531 [0,1\uff0c...\uff0cN-1] \u4e2d\u7684\u4e00\u4e2a\u6574\u6570\u8868\u793a\uff0c\u5176\u4e2d N = rooms.length\u3002 \u94a5\u5319 rooms[i][j] = v \u53ef\u4ee5\u6253\u5f00\u7f16\u53f7\u4e3a v \u7684\u623f\u95f4\u3002

\n\n

\u6700\u521d\uff0c\u9664 0 \u53f7\u623f\u95f4\u5916\u7684\u5176\u4f59\u6240\u6709\u623f\u95f4\u90fd\u88ab\u9501\u4f4f\u3002

\n\n

\u4f60\u53ef\u4ee5\u81ea\u7531\u5730\u5728\u623f\u95f4\u4e4b\u95f4\u6765\u56de\u8d70\u52a8\u3002

\n\n

\u5982\u679c\u80fd\u8fdb\u5165\u6bcf\u4e2a\u623f\u95f4\u8fd4\u56de true\uff0c\u5426\u5219\u8fd4\u56de false\u3002

\n\n
    \n
\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165: [[1],[2],[3],[]]\n\u8f93\u51fa: true\n\u89e3\u91ca:  \n\u6211\u4eec\u4ece 0 \u53f7\u623f\u95f4\u5f00\u59cb\uff0c\u62ff\u5230\u94a5\u5319 1\u3002\n\u4e4b\u540e\u6211\u4eec\u53bb 1 \u53f7\u623f\u95f4\uff0c\u62ff\u5230\u94a5\u5319 2\u3002\n\u7136\u540e\u6211\u4eec\u53bb 2 \u53f7\u623f\u95f4\uff0c\u62ff\u5230\u94a5\u5319 3\u3002\n\u6700\u540e\u6211\u4eec\u53bb\u4e86 3 \u53f7\u623f\u95f4\u3002\n\u7531\u4e8e\u6211\u4eec\u80fd\u591f\u8fdb\u5165\u6bcf\u4e2a\u623f\u95f4\uff0c\u6211\u4eec\u8fd4\u56de true\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a[[1,3],[3,0,1],[2],[0]]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u6211\u4eec\u4e0d\u80fd\u8fdb\u5165 2 \u53f7\u623f\u95f4\u3002\n
\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= rooms.length <= 1000
  2. \n\t
  3. 0 <= rooms[i].length <= 1000
  4. \n\t
  5. \u6240\u6709\u623f\u95f4\u4e2d\u7684\u94a5\u5319\u6570\u91cf\u603b\u8ba1\u4e0d\u8d85\u8fc7 3000\u3002
  6. \n
\n", "tags_en": ["Depth-first Search", "Graph"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canVisitAllRooms(vector>& rooms) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canVisitAllRooms(List> rooms) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canVisitAllRooms(self, rooms):\n \"\"\"\n :type rooms: List[List[int]]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canVisitAllRooms(self, rooms: List[List[int]]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canVisitAllRooms(int** rooms, int roomsSize, int* roomsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanVisitAllRooms(IList> rooms) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} rooms\n * @return {boolean}\n */\nvar canVisitAllRooms = function(rooms) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} rooms\n# @return {Boolean}\ndef can_visit_all_rooms(rooms)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canVisitAllRooms(_ rooms: [[Int]]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canVisitAllRooms(rooms [][]int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canVisitAllRooms(rooms: List[List[Int]]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canVisitAllRooms(rooms: List>): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_visit_all_rooms(rooms: Vec>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $rooms\n * @return Boolean\n */\n function canVisitAllRooms($rooms) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canVisitAllRooms(rooms: number[][]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-visit-all-rooms rooms)\n (-> (listof (listof exact-integer?)) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0841](https://leetcode-cn.com/problems/keys-and-rooms)", "[\u94a5\u5319\u548c\u623f\u95f4](/solution/0800-0899/0841.Keys%20and%20Rooms/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u56fe`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0841](https://leetcode.com/problems/keys-and-rooms)", "[Keys and Rooms](/solution/0800-0899/0841.Keys%20and%20Rooms/README_EN.md)", "`Depth-first Search`,`Graph`", "Medium", ""]}, {"question_id": "0870", "frontend_question_id": "0840", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/magic-squares-in-grid", "url_en": "https://leetcode.com/problems/magic-squares-in-grid", "relative_path_cn": "/solution/0800-0899/0840.Magic%20Squares%20In%20Grid/README.md", "relative_path_en": "/solution/0800-0899/0840.Magic%20Squares%20In%20Grid/README_EN.md", "title_cn": "\u77e9\u9635\u4e2d\u7684\u5e7b\u65b9", "title_en": "Magic Squares In Grid", "question_title_slug": "magic-squares-in-grid", "content_en": "

A 3 x 3 magic square is a 3 x 3 grid filled with distinct numbers from 1 to 9 such that each row, column, and both diagonals all have the same sum.

\n\n

Given a row x col grid of integers, how many 3 x 3 "magic square" subgrids are there?  (Each subgrid is contiguous).

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: grid = [[4,3,8,4],[9,5,1,9],[2,7,6,2]]\nOutput: 1\nExplanation: \nThe following subgrid is a 3 x 3 magic square:\n\"\"\nwhile this one is not:\n\"\"\nIn total, there is only one magic square inside the given grid.\n
\n\n

Example 2:

\n\n
\nInput: grid = [[8]]\nOutput: 0\n
\n\n

Example 3:

\n\n
\nInput: grid = [[4,4],[3,3]]\nOutput: 0\n
\n\n

Example 4:

\n\n
\nInput: grid = [[4,7,8],[9,5,1],[2,3,6]]\nOutput: 0\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • row == grid.length
  • \n\t
  • col == grid[i].length
  • \n\t
  • 1 <= row, col <= 10
  • \n\t
  • 0 <= grid[i][j] <= 15
  • \n
\n", "content_cn": "

3 x 3 \u7684\u5e7b\u65b9\u662f\u4e00\u4e2a\u586b\u5145\u6709\u4ece 1 \u5230 9 \u7684\u4e0d\u540c\u6570\u5b57\u7684 3 x 3 \u77e9\u9635\uff0c\u5176\u4e2d\u6bcf\u884c\uff0c\u6bcf\u5217\u4ee5\u53ca\u4e24\u6761\u5bf9\u89d2\u7ebf\u4e0a\u7684\u5404\u6570\u4e4b\u548c\u90fd\u76f8\u7b49\u3002

\n\n

\u7ed9\u5b9a\u4e00\u4e2a\u7531\u6574\u6570\u7ec4\u6210\u7684 grid\uff0c\u5176\u4e2d\u6709\u591a\u5c11\u4e2a 3 × 3 \u7684 “\u5e7b\u65b9” \u5b50\u77e9\u9635\uff1f\uff08\u6bcf\u4e2a\u5b50\u77e9\u9635\u90fd\u662f\u8fde\u7eed\u7684\uff09\u3002

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165: [[4,3,8,4],\n      [9,5,1,9],\n      [2,7,6,2]]\n\u8f93\u51fa: 1\n\u89e3\u91ca: \n\u4e0b\u9762\u7684\u5b50\u77e9\u9635\u662f\u4e00\u4e2a 3 x 3 \u7684\u5e7b\u65b9\uff1a\n438\n951\n276\n\n\u800c\u8fd9\u4e00\u4e2a\u4e0d\u662f\uff1a\n384\n519\n762\n\n\u603b\u7684\u6765\u8bf4\uff0c\u5728\u672c\u793a\u4f8b\u6240\u7ed9\u5b9a\u7684\u77e9\u9635\u4e2d\u53ea\u6709\u4e00\u4e2a 3 x 3 \u7684\u5e7b\u65b9\u5b50\u77e9\u9635\u3002\n
\n\n

\u63d0\u793a:

\n\n
    \n\t
  1. 1 <= grid.length <= 10
  2. \n\t
  3. 1 <= grid[0].length <= 10
  4. \n\t
  5. 0 <= grid[i][j] <= 15
  6. \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numMagicSquaresInside(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numMagicSquaresInside(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numMagicSquaresInside(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numMagicSquaresInside(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numMagicSquaresInside(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumMagicSquaresInside(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar numMagicSquaresInside = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef num_magic_squares_inside(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numMagicSquaresInside(_ grid: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numMagicSquaresInside(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numMagicSquaresInside(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numMagicSquaresInside(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_magic_squares_inside(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function numMagicSquaresInside($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numMagicSquaresInside(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-magic-squares-inside grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0840](https://leetcode-cn.com/problems/magic-squares-in-grid)", "[\u77e9\u9635\u4e2d\u7684\u5e7b\u65b9](/solution/0800-0899/0840.Magic%20Squares%20In%20Grid/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0840](https://leetcode.com/problems/magic-squares-in-grid)", "[Magic Squares In Grid](/solution/0800-0899/0840.Magic%20Squares%20In%20Grid/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0869", "frontend_question_id": "0839", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/similar-string-groups", "url_en": "https://leetcode.com/problems/similar-string-groups", "relative_path_cn": "/solution/0800-0899/0839.Similar%20String%20Groups/README.md", "relative_path_en": "/solution/0800-0899/0839.Similar%20String%20Groups/README_EN.md", "title_cn": "\u76f8\u4f3c\u5b57\u7b26\u4e32\u7ec4", "title_en": "Similar String Groups", "question_title_slug": "similar-string-groups", "content_en": "

Two strings X and Y are similar if we can swap two letters (in different positions) of X, so that it equals Y. Also two strings X and Y are similar if they are equal.

\n\n

For example, "tars" and "rats" are similar (swapping at positions 0 and 2), and "rats" and "arts" are similar, but "star" is not similar to "tars", "rats", or "arts".

\n\n

Together, these form two connected groups by similarity: {"tars", "rats", "arts"} and {"star"}.  Notice that "tars" and "arts" are in the same group even though they are not similar.  Formally, each group is such that a word is in the group if and only if it is similar to at least one other word in the group.

\n\n

We are given a list strs of strings where every string in strs is an anagram of every other string in strs. How many groups are there?

\n\n

 

\n

Example 1:

\n\n
\nInput: strs = ["tars","rats","arts","star"]\nOutput: 2\n
\n\n

Example 2:

\n\n
\nInput: strs = ["omv","ovm"]\nOutput: 1\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= strs.length <= 300
  • \n\t
  • 1 <= strs[i].length <= 300
  • \n\t
  • strs[i] consists of lowercase letters only.
  • \n\t
  • All words in strs have the same length and are anagrams of each other.
  • \n
\n", "content_cn": "

\u5982\u679c\u4ea4\u6362\u5b57\u7b26\u4e32\u00a0X \u4e2d\u7684\u4e24\u4e2a\u4e0d\u540c\u4f4d\u7f6e\u7684\u5b57\u6bcd\uff0c\u4f7f\u5f97\u5b83\u548c\u5b57\u7b26\u4e32\u00a0Y \u76f8\u7b49\uff0c\u90a3\u4e48\u79f0 X \u548c Y \u4e24\u4e2a\u5b57\u7b26\u4e32\u76f8\u4f3c\u3002\u5982\u679c\u8fd9\u4e24\u4e2a\u5b57\u7b26\u4e32\u672c\u8eab\u662f\u76f8\u7b49\u7684\uff0c\u90a3\u5b83\u4eec\u4e5f\u662f\u76f8\u4f3c\u7684\u3002

\n\n

\u4f8b\u5982\uff0c\"tars\" \u548c \"rats\" \u662f\u76f8\u4f3c\u7684 (\u4ea4\u6362 0 \u4e0e 2 \u7684\u4f4d\u7f6e)\uff1b\u00a0\"rats\" \u548c \"arts\" \u4e5f\u662f\u76f8\u4f3c\u7684\uff0c\u4f46\u662f \"star\" \u4e0d\u4e0e \"tars\"\uff0c\"rats\"\uff0c\u6216 \"arts\" \u76f8\u4f3c\u3002

\n\n

\u603b\u4e4b\uff0c\u5b83\u4eec\u901a\u8fc7\u76f8\u4f3c\u6027\u5f62\u6210\u4e86\u4e24\u4e2a\u5173\u8054\u7ec4\uff1a{\"tars\", \"rats\", \"arts\"} \u548c {\"star\"}\u3002\u6ce8\u610f\uff0c\"tars\" \u548c \"arts\" \u662f\u5728\u540c\u4e00\u7ec4\u4e2d\uff0c\u5373\u4f7f\u5b83\u4eec\u5e76\u4e0d\u76f8\u4f3c\u3002\u5f62\u5f0f\u4e0a\uff0c\u5bf9\u6bcf\u4e2a\u7ec4\u800c\u8a00\uff0c\u8981\u786e\u5b9a\u4e00\u4e2a\u5355\u8bcd\u5728\u7ec4\u4e2d\uff0c\u53ea\u9700\u8981\u8fd9\u4e2a\u8bcd\u548c\u8be5\u7ec4\u4e2d\u81f3\u5c11\u4e00\u4e2a\u5355\u8bcd\u76f8\u4f3c\u3002

\n\n

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32\u5217\u8868 strs\u3002\u5217\u8868\u4e2d\u7684\u6bcf\u4e2a\u5b57\u7b26\u4e32\u90fd\u662f strs \u4e2d\u5176\u5b83\u6240\u6709\u5b57\u7b26\u4e32\u7684\u4e00\u4e2a\u5b57\u6bcd\u5f02\u4f4d\u8bcd\u3002\u8bf7\u95ee strs \u4e2d\u6709\u591a\u5c11\u4e2a\u76f8\u4f3c\u5b57\u7b26\u4e32\u7ec4\uff1f

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1astrs = [\"tars\",\"rats\",\"arts\",\"star\"]\n\u8f93\u51fa\uff1a2\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1astrs = [\"omv\",\"ovm\"]\n\u8f93\u51fa\uff1a1\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= strs.length <= 300
  • \n\t
  • 1 <= strs[i].length <= 300
  • \n\t
  • strs[i] \u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd\u3002
  • \n\t
  • strs \u4e2d\u7684\u6240\u6709\u5355\u8bcd\u90fd\u5177\u6709\u76f8\u540c\u7684\u957f\u5ea6\uff0c\u4e14\u662f\u5f7c\u6b64\u7684\u5b57\u6bcd\u5f02\u4f4d\u8bcd\u3002
  • \n
\n\n

\u00a0

\n\n

\u5907\u6ce8\uff1a

\n\n

\u00a0\u00a0\u00a0\u00a0\u00a0 \u5b57\u6bcd\u5f02\u4f4d\u8bcd\uff08anagram\uff09\uff0c\u4e00\u79cd\u628a\u67d0\u4e2a\u5b57\u7b26\u4e32\u7684\u5b57\u6bcd\u7684\u4f4d\u7f6e\uff08\u987a\u5e8f\uff09\u52a0\u4ee5\u6539\u6362\u6240\u5f62\u6210\u7684\u65b0\u8bcd\u3002

\n", "tags_en": ["Depth-first Search", "Union Find", "Graph"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e76\u67e5\u96c6", "\u56fe"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numSimilarGroups(vector& strs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numSimilarGroups(String[] strs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numSimilarGroups(self, strs):\n \"\"\"\n :type strs: List[str]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numSimilarGroups(self, strs: List[str]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numSimilarGroups(char ** strs, int strsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumSimilarGroups(string[] strs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} strs\n * @return {number}\n */\nvar numSimilarGroups = function(strs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} strs\n# @return {Integer}\ndef num_similar_groups(strs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numSimilarGroups(_ strs: [String]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numSimilarGroups(strs []string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numSimilarGroups(strs: Array[String]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numSimilarGroups(strs: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_similar_groups(strs: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $strs\n * @return Integer\n */\n function numSimilarGroups($strs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numSimilarGroups(strs: string[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-similar-groups strs)\n (-> (listof string?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0839](https://leetcode-cn.com/problems/similar-string-groups)", "[\u76f8\u4f3c\u5b57\u7b26\u4e32\u7ec4](/solution/0800-0899/0839.Similar%20String%20Groups/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e76\u67e5\u96c6`,`\u56fe`", "\u56f0\u96be", ""], "md_table_row_en": ["[0839](https://leetcode.com/problems/similar-string-groups)", "[Similar String Groups](/solution/0800-0899/0839.Similar%20String%20Groups/README_EN.md)", "`Depth-first Search`,`Union Find`,`Graph`", "Hard", ""]}, {"question_id": "0868", "frontend_question_id": "0838", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/push-dominoes", "url_en": "https://leetcode.com/problems/push-dominoes", "relative_path_cn": "/solution/0800-0899/0838.Push%20Dominoes/README.md", "relative_path_en": "/solution/0800-0899/0838.Push%20Dominoes/README_EN.md", "title_cn": "\u63a8\u591a\u7c73\u8bfa", "title_en": "Push Dominoes", "question_title_slug": "push-dominoes", "content_en": "

There are N dominoes in a line, and we place each domino vertically upright.

\r\n\r\n

In the beginning, we simultaneously push some of the dominoes either to the left or to the right.

\r\n\r\n

\"\"

\r\n\r\n

After each second, each domino that is falling to the left pushes the adjacent domino on the left.

\r\n\r\n

Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right.

\r\n\r\n

When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces.

\r\n\r\n

For the purposes of this question, we will consider that a falling domino expends no additional force to a falling or already fallen domino.

\r\n\r\n

Given a string "S" representing the initial state. S[i] = 'L', if the i-th domino has been pushed to the left; S[i] = 'R', if the i-th domino has been pushed to the right; S[i] = '.', if the i-th domino has not been pushed.

\r\n\r\n

Return a string representing the final state. 

\r\n\r\n

Example 1:

\r\n\r\n
\r\nInput: ".L.R...LR..L.."\r\nOutput: "LL.RR.LLRRLL.."\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: "RR.L"\r\nOutput: "RR.L"\r\nExplanation: The first domino expends no additional force on the second domino.\r\n
\r\n\r\n

Note:

\r\n\r\n
    \r\n\t
  1. 0 <= N <= 10^5
  2. \r\n\t
  3. String dominoes contains only 'L', 'R' and '.'
  4. \r\n
\r\n", "content_cn": "

\u4e00\u884c\u4e2d\u6709 N \u5f20\u591a\u7c73\u8bfa\u9aa8\u724c\uff0c\u6211\u4eec\u5c06\u6bcf\u5f20\u591a\u7c73\u8bfa\u9aa8\u724c\u5782\u76f4\u7ad6\u7acb\u3002

\n\n

\u5728\u5f00\u59cb\u65f6\uff0c\u6211\u4eec\u540c\u65f6\u628a\u4e00\u4e9b\u591a\u7c73\u8bfa\u9aa8\u724c\u5411\u5de6\u6216\u5411\u53f3\u63a8\u3002

\n\n

\"\"

\n\n

\u6bcf\u8fc7\u4e00\u79d2\uff0c\u5012\u5411\u5de6\u8fb9\u7684\u591a\u7c73\u8bfa\u9aa8\u724c\u4f1a\u63a8\u52a8\u5176\u5de6\u4fa7\u76f8\u90bb\u7684\u591a\u7c73\u8bfa\u9aa8\u724c\u3002

\n\n

\u540c\u6837\u5730\uff0c\u5012\u5411\u53f3\u8fb9\u7684\u591a\u7c73\u8bfa\u9aa8\u724c\u4e5f\u4f1a\u63a8\u52a8\u7ad6\u7acb\u5728\u5176\u53f3\u4fa7\u7684\u76f8\u90bb\u591a\u7c73\u8bfa\u9aa8\u724c\u3002

\n\n

\u5982\u679c\u540c\u65f6\u6709\u591a\u7c73\u8bfa\u9aa8\u724c\u843d\u5728\u4e00\u5f20\u5782\u76f4\u7ad6\u7acb\u7684\u591a\u7c73\u8bfa\u9aa8\u724c\u7684\u4e24\u8fb9\uff0c\u7531\u4e8e\u53d7\u529b\u5e73\u8861\uff0c \u8be5\u9aa8\u724c\u4ecd\u7136\u4fdd\u6301\u4e0d\u53d8\u3002

\n\n

\u5c31\u8fd9\u4e2a\u95ee\u9898\u800c\u8a00\uff0c\u6211\u4eec\u4f1a\u8ba4\u4e3a\u6b63\u5728\u4e0b\u964d\u7684\u591a\u7c73\u8bfa\u9aa8\u724c\u4e0d\u4f1a\u5bf9\u5176\u5b83\u6b63\u5728\u4e0b\u964d\u6216\u5df2\u7ecf\u4e0b\u964d\u7684\u591a\u7c73\u8bfa\u9aa8\u724c\u65bd\u52a0\u989d\u5916\u7684\u529b\u3002

\n\n

\u7ed9\u5b9a\u8868\u793a\u521d\u59cb\u72b6\u6001\u7684\u5b57\u7b26\u4e32 "S" \u3002\u5982\u679c\u7b2c i \u5f20\u591a\u7c73\u8bfa\u9aa8\u724c\u88ab\u63a8\u5411\u5de6\u8fb9\uff0c\u5219 S[i] = 'L'\uff1b\u5982\u679c\u7b2c i \u5f20\u591a\u7c73\u8bfa\u9aa8\u724c\u88ab\u63a8\u5411\u53f3\u8fb9\uff0c\u5219 S[i] = 'R'\uff1b\u5982\u679c\u7b2c i \u5f20\u591a\u7c73\u8bfa\u9aa8\u724c\u6ca1\u6709\u88ab\u63a8\u52a8\uff0c\u5219 S[i] = '.'\u3002

\n\n

\u8fd4\u56de\u8868\u793a\u6700\u7ec8\u72b6\u6001\u7684\u5b57\u7b26\u4e32\u3002

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a".L.R...LR..L.."\n\u8f93\u51fa\uff1a"LL.RR.LLRRLL.."
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a"RR.L"\n\u8f93\u51fa\uff1a"RR.L"\n\u8bf4\u660e\uff1a\u7b2c\u4e00\u5f20\u591a\u7c73\u8bfa\u9aa8\u724c\u6ca1\u6709\u7ed9\u7b2c\u4e8c\u5f20\u65bd\u52a0\u989d\u5916\u7684\u529b\u3002
\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 0 <= N <= 10^5
  2. \n\t
  3. \u8868\u793a\u591a\u7c73\u8bfa\u9aa8\u724c\u72b6\u6001\u7684\u5b57\u7b26\u4e32\u53ea\u542b\u6709 'L'\uff0c'R'; \u4ee5\u53ca '.';
  4. \n
\n", "tags_en": ["Two Pointers", "Dynamic Programming"], "tags_cn": ["\u53cc\u6307\u9488", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string pushDominoes(string dominoes) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String pushDominoes(String dominoes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def pushDominoes(self, dominoes):\n \"\"\"\n :type dominoes: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def pushDominoes(self, dominoes: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * pushDominoes(char * dominoes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string PushDominoes(string dominoes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} dominoes\n * @return {string}\n */\nvar pushDominoes = function(dominoes) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} dominoes\n# @return {String}\ndef push_dominoes(dominoes)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func pushDominoes(_ dominoes: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func pushDominoes(dominoes string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def pushDominoes(dominoes: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun pushDominoes(dominoes: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn push_dominoes(dominoes: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $dominoes\n * @return String\n */\n function pushDominoes($dominoes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function pushDominoes(dominoes: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (push-dominoes dominoes)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0838](https://leetcode-cn.com/problems/push-dominoes)", "[\u63a8\u591a\u7c73\u8bfa](/solution/0800-0899/0838.Push%20Dominoes/README.md)", "`\u53cc\u6307\u9488`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0838](https://leetcode.com/problems/push-dominoes)", "[Push Dominoes](/solution/0800-0899/0838.Push%20Dominoes/README_EN.md)", "`Two Pointers`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0867", "frontend_question_id": "0837", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/new-21-game", "url_en": "https://leetcode.com/problems/new-21-game", "relative_path_cn": "/solution/0800-0899/0837.New%2021%20Game/README.md", "relative_path_en": "/solution/0800-0899/0837.New%2021%20Game/README_EN.md", "title_cn": "\u65b021\u70b9", "title_en": "New 21 Game", "question_title_slug": "new-21-game", "content_en": "

Alice plays the following game, loosely based on the card game "21".

\n\n

Alice starts with 0 points and draws numbers while she has less than k points. During each draw, she gains an integer number of points randomly from the range [1, maxPts], where maxPts is an integer. Each draw is independent and the outcomes have equal probabilities.

\n\n

Alice stops drawing numbers when she gets k or more points.

\n\n

Return the probability that Alice has n or fewer points.

\n\n

Answers within 10-5 of the actual answer are considered accepted.

\n\n

 

\n

Example 1:

\n\n
\nInput: n = 10, k = 1, maxPts = 10\nOutput: 1.00000\nExplanation: Alice gets a single card, then stops.\n
\n\n

Example 2:

\n\n
\nInput: n = 6, k = 1, maxPts = 10\nOutput: 0.60000\nExplanation: Alice gets a single card, then stops.\nIn 6 out of 10 possibilities, she is at or below 6 points.\n
\n\n

Example 3:

\n\n
\nInput: n = 21, k = 17, maxPts = 10\nOutput: 0.73278\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 0 <= k <= n <= 104
  • \n\t
  • 1 <= maxPts <= 104
  • \n
\n", "content_cn": "

\u7231\u4e3d\u4e1d\u53c2\u4e0e\u4e00\u4e2a\u5927\u81f4\u57fa\u4e8e\u7eb8\u724c\u6e38\u620f “21\u70b9” \u89c4\u5219\u7684\u6e38\u620f\uff0c\u63cf\u8ff0\u5982\u4e0b\uff1a

\n\n

\u7231\u4e3d\u4e1d\u4ee5 0 \u5206\u5f00\u59cb\uff0c\u5e76\u5728\u5979\u7684\u5f97\u5206\u5c11\u4e8e K \u5206\u65f6\u62bd\u53d6\u6570\u5b57\u3002 \u62bd\u53d6\u65f6\uff0c\u5979\u4ece [1, W] \u7684\u8303\u56f4\u4e2d\u968f\u673a\u83b7\u5f97\u4e00\u4e2a\u6574\u6570\u4f5c\u4e3a\u5206\u6570\u8fdb\u884c\u7d2f\u8ba1\uff0c\u5176\u4e2d W \u662f\u6574\u6570\u3002 \u6bcf\u6b21\u62bd\u53d6\u90fd\u662f\u72ec\u7acb\u7684\uff0c\u5176\u7ed3\u679c\u5177\u6709\u76f8\u540c\u7684\u6982\u7387\u3002

\n\n

\u5f53\u7231\u4e3d\u4e1d\u83b7\u5f97\u4e0d\u5c11\u4e8e K \u5206\u65f6\uff0c\u5979\u5c31\u505c\u6b62\u62bd\u53d6\u6570\u5b57\u3002 \u7231\u4e3d\u4e1d\u7684\u5206\u6570\u4e0d\u8d85\u8fc7 N \u7684\u6982\u7387\u662f\u591a\u5c11\uff1f

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aN = 10, K = 1, W = 10\n\u8f93\u51fa\uff1a1.00000\n\u8bf4\u660e\uff1a\u7231\u4e3d\u4e1d\u5f97\u5230\u4e00\u5f20\u5361\uff0c\u7136\u540e\u505c\u6b62\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aN = 6, K = 1, W = 10\n\u8f93\u51fa\uff1a0.60000\n\u8bf4\u660e\uff1a\u7231\u4e3d\u4e1d\u5f97\u5230\u4e00\u5f20\u5361\uff0c\u7136\u540e\u505c\u6b62\u3002\n\u5728 W = 10 \u7684 6 \u79cd\u53ef\u80fd\u4e0b\uff0c\u5979\u7684\u5f97\u5206\u4e0d\u8d85\u8fc7 N = 6 \u5206\u3002
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1aN = 21, K = 17, W = 10\n\u8f93\u51fa\uff1a0.73278
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 0 <= K <= N <= 10000
  2. \n\t
  3. 1 <= W <= 10000
  4. \n\t
  5. \u5982\u679c\u7b54\u6848\u4e0e\u6b63\u786e\u7b54\u6848\u7684\u8bef\u5dee\u4e0d\u8d85\u8fc7 10^-5\uff0c\u5219\u8be5\u7b54\u6848\u5c06\u88ab\u89c6\u4e3a\u6b63\u786e\u7b54\u6848\u901a\u8fc7\u3002
  6. \n\t
  7. \u6b64\u95ee\u9898\u7684\u5224\u65ad\u9650\u5236\u65f6\u95f4\u5df2\u7ecf\u51cf\u5c11\u3002
  8. \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n double new21Game(int n, int k, int maxPts) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double new21Game(int n, int k, int maxPts) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def new21Game(self, n, k, maxPts):\n \"\"\"\n :type n: int\n :type k: int\n :type maxPts: int\n :rtype: float\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def new21Game(self, n: int, k: int, maxPts: int) -> float:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\ndouble new21Game(int n, int k, int maxPts){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double New21Game(int n, int k, int maxPts) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} k\n * @param {number} maxPts\n * @return {number}\n */\nvar new21Game = function(n, k, maxPts) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} k\n# @param {Integer} max_pts\n# @return {Float}\ndef new21_game(n, k, max_pts)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func new21Game(_ n: Int, _ k: Int, _ maxPts: Int) -> Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func new21Game(n int, k int, maxPts int) float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def new21Game(n: Int, k: Int, maxPts: Int): Double = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun new21Game(n: Int, k: Int, maxPts: Int): Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn new21_game(n: i32, k: i32, max_pts: i32) -> f64 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $k\n * @param Integer $maxPts\n * @return Float\n */\n function new21Game($n, $k, $maxPts) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function new21Game(n: number, k: number, maxPts: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (new21-game n k maxPts)\n (-> exact-integer? exact-integer? exact-integer? flonum?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0837](https://leetcode-cn.com/problems/new-21-game)", "[\u65b021\u70b9](/solution/0800-0899/0837.New%2021%20Game/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0837](https://leetcode.com/problems/new-21-game)", "[New 21 Game](/solution/0800-0899/0837.New%2021%20Game/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0866", "frontend_question_id": "0836", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/rectangle-overlap", "url_en": "https://leetcode.com/problems/rectangle-overlap", "relative_path_cn": "/solution/0800-0899/0836.Rectangle%20Overlap/README.md", "relative_path_en": "/solution/0800-0899/0836.Rectangle%20Overlap/README_EN.md", "title_cn": "\u77e9\u5f62\u91cd\u53e0", "title_en": "Rectangle Overlap", "question_title_slug": "rectangle-overlap", "content_en": "

An axis-aligned rectangle is represented as a list [x1, y1, x2, y2], where (x1, y1) is the coordinate of its bottom-left corner, and (x2, y2) is the coordinate of its top-right corner. Its top and bottom edges are parallel to the X-axis, and its left and right edges are parallel to the Y-axis.

\n\n

Two rectangles overlap if the area of their intersection is positive. To be clear, two rectangles that only touch at the corner or edges do not overlap.

\n\n

Given two axis-aligned rectangles rec1 and rec2, return true if they overlap, otherwise return false.

\n\n

 

\n

Example 1:

\n
Input: rec1 = [0,0,2,2], rec2 = [1,1,3,3]\nOutput: true\n

Example 2:

\n
Input: rec1 = [0,0,1,1], rec2 = [1,0,2,1]\nOutput: false\n

Example 3:

\n
Input: rec1 = [0,0,1,1], rec2 = [2,2,3,3]\nOutput: false\n
\n

 

\n

Constraints:

\n\n
    \n\t
  • rect1.length == 4
  • \n\t
  • rect2.length == 4
  • \n\t
  • -109 <= rec1[i], rec2[i] <= 109
  • \n\t
  • rec1[0] <= rec1[2] and rec1[1] <= rec1[3]
  • \n\t
  • rec2[0] <= rec2[2] and rec2[1] <= rec2[3]
  • \n
\n", "content_cn": "

\u77e9\u5f62\u4ee5\u5217\u8868 [x1, y1, x2, y2] \u7684\u5f62\u5f0f\u8868\u793a\uff0c\u5176\u4e2d (x1, y1) \u4e3a\u5de6\u4e0b\u89d2\u7684\u5750\u6807\uff0c(x2, y2) \u662f\u53f3\u4e0a\u89d2\u7684\u5750\u6807\u3002\u77e9\u5f62\u7684\u4e0a\u4e0b\u8fb9\u5e73\u884c\u4e8e x \u8f74\uff0c\u5de6\u53f3\u8fb9\u5e73\u884c\u4e8e y \u8f74\u3002

\n\n

\u5982\u679c\u76f8\u4ea4\u7684\u9762\u79ef\u4e3a \u6b63 \uff0c\u5219\u79f0\u4e24\u77e9\u5f62\u91cd\u53e0\u3002\u9700\u8981\u660e\u786e\u7684\u662f\uff0c\u53ea\u5728\u89d2\u6216\u8fb9\u63a5\u89e6\u7684\u4e24\u4e2a\u77e9\u5f62\u4e0d\u6784\u6210\u91cd\u53e0\u3002

\n\n

\u7ed9\u51fa\u4e24\u4e2a\u77e9\u5f62 rec1 \u548c rec2 \u3002\u5982\u679c\u5b83\u4eec\u91cd\u53e0\uff0c\u8fd4\u56de true\uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1arec1 = [0,0,2,2], rec2 = [1,1,3,3]\n\u8f93\u51fa\uff1atrue\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1arec1 = [0,0,1,1], rec2 = [1,0,2,1]\n\u8f93\u51fa\uff1afalse\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1arec1 = [0,0,1,1], rec2 = [2,2,3,3]\n\u8f93\u51fa\uff1afalse\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • rect1.length == 4
  • \n\t
  • rect2.length == 4
  • \n\t
  • -109 <= rec1[i], rec2[i] <= 109
  • \n\t
  • rec1[0] <= rec1[2] \u4e14 rec1[1] <= rec1[3]
  • \n\t
  • rec2[0] <= rec2[2] \u4e14 rec2[1] <= rec2[3]
  • \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isRectangleOverlap(vector& rec1, vector& rec2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isRectangleOverlap(int[] rec1, int[] rec2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isRectangleOverlap(self, rec1, rec2):\n \"\"\"\n :type rec1: List[int]\n :type rec2: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isRectangleOverlap(int* rec1, int rec1Size, int* rec2, int rec2Size){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsRectangleOverlap(int[] rec1, int[] rec2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} rec1\n * @param {number[]} rec2\n * @return {boolean}\n */\nvar isRectangleOverlap = function(rec1, rec2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} rec1\n# @param {Integer[]} rec2\n# @return {Boolean}\ndef is_rectangle_overlap(rec1, rec2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isRectangleOverlap(_ rec1: [Int], _ rec2: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isRectangleOverlap(rec1 []int, rec2 []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isRectangleOverlap(rec1: Array[Int], rec2: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isRectangleOverlap(rec1: IntArray, rec2: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_rectangle_overlap(rec1: Vec, rec2: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $rec1\n * @param Integer[] $rec2\n * @return Boolean\n */\n function isRectangleOverlap($rec1, $rec2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isRectangleOverlap(rec1: number[], rec2: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-rectangle-overlap rec1 rec2)\n (-> (listof exact-integer?) (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0836](https://leetcode-cn.com/problems/rectangle-overlap)", "[\u77e9\u5f62\u91cd\u53e0](/solution/0800-0899/0836.Rectangle%20Overlap/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0836](https://leetcode.com/problems/rectangle-overlap)", "[Rectangle Overlap](/solution/0800-0899/0836.Rectangle%20Overlap/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "0865", "frontend_question_id": "0489", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/robot-room-cleaner", "url_en": "https://leetcode.com/problems/robot-room-cleaner", "relative_path_cn": "/solution/0400-0499/0489.Robot%20Room%20Cleaner/README.md", "relative_path_en": "/solution/0400-0499/0489.Robot%20Room%20Cleaner/README_EN.md", "title_cn": "\u626b\u5730\u673a\u5668\u4eba", "title_en": "Robot Room Cleaner", "question_title_slug": "robot-room-cleaner", "content_en": "

Given a robot cleaner in a room modeled as a grid.

\r\n\r\n

Each cell in the grid can be empty or blocked.

\r\n\r\n

The robot cleaner with 4 given APIs can move forward, turn left or turn right. Each turn it made is 90 degrees.

\r\n\r\n

When it tries to move into a blocked cell, its bumper sensor detects the obstacle and it stays on the current cell.

\r\n\r\n

Design an algorithm to clean the entire room using only the 4 given APIs shown below.

\r\n\r\n
\r\ninterface Robot {\r\n  // returns true if next cell is open and robot moves into the cell.\r\n  // returns false if next cell is obstacle and robot stays on the current cell.\r\n  boolean move();\r\n\r\n  // Robot will stay on the same cell after calling turnLeft/turnRight.\r\n  // Each turn will be 90 degrees.\r\n  void turnLeft();\r\n  void turnRight();\r\n\r\n  // Clean the current cell.\r\n  void clean();\r\n}\r\n
\r\n\r\n

Example:

\r\n\r\n
\r\nInput:\r\nroom = [\r\n  [1,1,1,1,1,0,1,1],\r\n  [1,1,1,1,1,0,1,1],\r\n  [1,0,1,1,1,1,1,1],\r\n  [0,0,0,1,0,0,0,0],\r\n  [1,1,1,1,1,1,1,1]\r\n],\r\nrow = 1,\r\ncol = 3\r\n\r\nExplanation:\r\nAll grids in the room are marked by either 0 or 1.\r\n0 means the cell is blocked, while 1 means the cell is accessible.\r\nThe robot initially starts at the position of row=1, col=3.\r\nFrom the top left corner, its position is one row below and three columns right.\r\n
\r\n\r\n

Notes:

\r\n\r\n
    \r\n\t
  1. The input is only given to initialize the room and the robot's position internally. You must solve this problem "blindfolded". In other words, you must control the robot using only the mentioned 4 APIs, without knowing the room layout and the initial robot's position.
  2. \r\n\t
  3. The robot's initial position will always be in an accessible cell.
  4. \r\n\t
  5. The initial direction of the robot will be facing up.
  6. \r\n\t
  7. All accessible cells are connected, which means the all cells marked as 1 will be accessible by the robot.
  8. \r\n\t
  9. Assume all four edges of the grid are all surrounded by wall.
  10. \r\n
\r\n", "content_cn": "

\u623f\u95f4\uff08\u7528\u683c\u6805\u8868\u793a\uff09\u4e2d\u6709\u4e00\u4e2a\u626b\u5730\u673a\u5668\u4eba\u3002\u683c\u6805\u4e2d\u7684\u6bcf\u4e00\u4e2a\u683c\u5b50\u6709\u7a7a\u548c\u969c\u788d\u7269\u4e24\u79cd\u53ef\u80fd\u3002

\n\n

\u626b\u5730\u673a\u5668\u4eba\u63d0\u4f9b4\u4e2aAPI\uff0c\u53ef\u4ee5\u5411\u524d\u8fdb\uff0c\u5411\u5de6\u8f6c\u6216\u8005\u5411\u53f3\u8f6c\u3002\u6bcf\u6b21\u8f6c\u5f2f90\u5ea6\u3002

\n\n

\u5f53\u626b\u5730\u673a\u5668\u4eba\u8bd5\u56fe\u8fdb\u5165\u969c\u788d\u7269\u683c\u5b50\u65f6\uff0c\u5b83\u7684\u78b0\u649e\u4f20\u611f\u5668\u4f1a\u63a2\u6d4b\u51fa\u969c\u788d\u7269\uff0c\u4f7f\u5b83\u505c\u7559\u5728\u539f\u5730\u3002

\n\n

\u8bf7\u5229\u7528\u63d0\u4f9b\u76844\u4e2aAPI\u7f16\u5199\u8ba9\u673a\u5668\u4eba\u6e05\u7406\u6574\u4e2a\u623f\u95f4\u7684\u7b97\u6cd5\u3002

\n\n
interface Robot {\n  // \u82e5\u4e0b\u4e00\u4e2a\u65b9\u683c\u4e3a\u7a7a\uff0c\u5219\u8fd4\u56detrue\uff0c\u5e76\u79fb\u52a8\u81f3\u8be5\u65b9\u683c\n  // \u82e5\u4e0b\u4e00\u4e2a\u65b9\u683c\u4e3a\u969c\u788d\u7269\uff0c\u5219\u8fd4\u56defalse\uff0c\u5e76\u505c\u7559\u5728\u539f\u5730\n  boolean move();\n\n  // \u5728\u8c03\u7528turnLeft/turnRight\u540e\u673a\u5668\u4eba\u4f1a\u505c\u7559\u5728\u539f\u4f4d\u7f6e\n  // \u6bcf\u6b21\u8f6c\u5f2f90\u5ea6\n  void turnLeft();\n  void turnRight();\n\n  // \u6e05\u7406\u6240\u5728\u65b9\u683c\n  void clean();\n}\n
\n\n

\u793a\u4f8b:

\n\n
\u8f93\u5165:\nroom = [\n  [1,1,1,1,1,0,1,1],\n  [1,1,1,1,1,0,1,1],\n  [1,0,1,1,1,1,1,1],\n  [0,0,0,1,0,0,0,0],\n  [1,1,1,1,1,1,1,1]\n],\nrow = 1,\ncol = 3\n\n\u89e3\u6790:\n\u623f\u95f4\u683c\u6805\u75280\u62161\u586b\u5145\u30020\u8868\u793a\u969c\u788d\u7269\uff0c1\u8868\u793a\u53ef\u4ee5\u901a\u8fc7\u3002\n\u673a\u5668\u4eba\u4ecerow=1\uff0ccol=3\u7684\u521d\u59cb\u4f4d\u7f6e\u51fa\u53d1\u3002\u5728\u5de6\u4e0a\u89d2\u7684\u4e00\u884c\u4ee5\u4e0b\uff0c\u4e09\u5217\u4ee5\u53f3\u3002\n
\n\n

\u6ce8\u610f:

\n\n
    \n\t
  1. \u8f93\u5165\u53ea\u7528\u4e8e\u521d\u59cb\u5316\u623f\u95f4\u548c\u673a\u5668\u4eba\u7684\u4f4d\u7f6e\u3002\u4f60\u9700\u8981“\u76f2\u89e3”\u8fd9\u4e2a\u95ee\u9898\u3002\u6362\u800c\u8a00\u4e4b\uff0c\u4f60\u5fc5\u987b\u5728\u5bf9\u623f\u95f4\u548c\u673a\u5668\u4eba\u4f4d\u7f6e\u4e00\u65e0\u6240\u77e5\u7684\u60c5\u51b5\u4e0b\uff0c\u53ea\u4f7f\u75284\u4e2a\u7ed9\u51fa\u7684API\u89e3\u51b3\u95ee\u9898\u3002 
  2. \n\t
  3. \u626b\u5730\u673a\u5668\u4eba\u7684\u521d\u59cb\u4f4d\u7f6e\u4e00\u5b9a\u662f\u7a7a\u5730\u3002
  4. \n\t
  5. \u626b\u5730\u673a\u5668\u4eba\u7684\u521d\u59cb\u65b9\u5411\u5411\u4e0a\u3002
  6. \n\t
  7. \u6240\u6709\u53ef\u62b5\u8fbe\u7684\u683c\u5b50\u90fd\u662f\u76f8\u8fde\u7684\uff0c\u4ea6\u5373\u6240\u6709\u6807\u8bb0\u4e3a1\u7684\u683c\u5b50\u673a\u5668\u4eba\u90fd\u53ef\u4ee5\u62b5\u8fbe\u3002
  8. \n\t
  9. \u53ef\u4ee5\u5047\u5b9a\u683c\u6805\u7684\u56db\u5468\u90fd\u88ab\u5899\u5305\u56f4\u3002
  10. \n
\n", "tags_en": ["Depth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * // This is the robot's control interface.\n * // You should not implement it, or speculate about its implementation\n * class Robot {\n * public:\n * // Returns true if the cell in front is open and robot moves into the cell.\n * // Returns false if the cell in front is blocked and robot stays in the current cell.\n * bool move();\n *\n * // Robot will stay in the same cell after calling turnLeft/turnRight.\n * // Each turn will be 90 degrees.\n * void turnLeft();\n * void turnRight();\n *\n * // Clean the current cell.\n * void clean();\n * };\n */\n\nclass Solution {\npublic:\n void cleanRoom(Robot& robot) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * // This is the robot's control interface.\n * // You should not implement it, or speculate about its implementation\n * interface Robot {\n * // Returns true if the cell in front is open and robot moves into the cell.\n * // Returns false if the cell in front is blocked and robot stays in the current cell.\n * public boolean move();\n *\n * // Robot will stay in the same cell after calling turnLeft/turnRight.\n * // Each turn will be 90 degrees.\n * public void turnLeft();\n * public void turnRight();\n *\n * // Clean the current cell.\n * public void clean();\n * }\n */\n\nclass Solution {\n public void cleanRoom(Robot robot) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# \"\"\"\n# This is the robot's control interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class Robot(object):\n# def move(self):\n# \"\"\"\n# Returns true if the cell in front is open and robot moves into the cell.\n# Returns false if the cell in front is blocked and robot stays in the current cell.\n# :rtype bool\n# \"\"\"\n#\n# def turnLeft(self):\n# \"\"\"\n# Robot will stay in the same cell after calling turnLeft/turnRight.\n# Each turn will be 90 degrees.\n# :rtype void\n# \"\"\"\n#\n# def turnRight(self):\n# \"\"\"\n# Robot will stay in the same cell after calling turnLeft/turnRight.\n# Each turn will be 90 degrees.\n# :rtype void\n# \"\"\"\n#\n# def clean(self):\n# \"\"\"\n# Clean the current cell.\n# :rtype void\n# \"\"\"\n\nclass Solution(object):\n def cleanRoom(self, robot):\n \"\"\"\n :type robot: Robot\n :rtype: None\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# \"\"\"\n# This is the robot's control interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class Robot:\n# def move(self):\n# \"\"\"\n# Returns true if the cell in front is open and robot moves into the cell.\n# Returns false if the cell in front is blocked and robot stays in the current cell.\n# :rtype bool\n# \"\"\"\n#\n# def turnLeft(self):\n# \"\"\"\n# Robot will stay in the same cell after calling turnLeft/turnRight.\n# Each turn will be 90 degrees.\n# :rtype void\n# \"\"\"\n#\n# def turnRight(self):\n# \"\"\"\n# Robot will stay in the same cell after calling turnLeft/turnRight.\n# Each turn will be 90 degrees.\n# :rtype void\n# \"\"\"\n#\n# def clean(self):\n# \"\"\"\n# Clean the current cell.\n# :rtype void\n# \"\"\"\n\nclass Solution:\n def cleanRoom(self, robot):\n \"\"\"\n :type robot: Robot\n :rtype: None\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * // This is the robot's control interface.\n * // You should not implement it, or speculate about its implementation\n * interface Robot {\n * // Returns true if the cell in front is open and robot moves into the cell.\n * // Returns false if the cell in front is blocked and robot stays in the current cell.\n * public bool Move();\n *\n * // Robot will stay in the same cell after calling turnLeft/turnRight.\n * // Each turn will be 90 degrees.\n * public void TurnLeft();\n * public void TurnRight();\n *\n * // Clean the current cell.\n * public void Clean();\n * }\n */\n\nclass Solution {\n public void CleanRoom(Robot robot) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // This is the robot's control interface.\n * // You should not implement it, or speculate about its implementation\n * function Robot() {\n * // Returns true if the cell in front is open and robot moves into the cell.\n * // Returns false if the cell in front is blocked and robot stays in the current cell.\n * @return {boolean}\n * this.move = function() {\n * ...\n * };\n *\n * // Robot will stay in the same cell after calling turnLeft/turnRight.\n * // Each turn will be 90 degrees.\n * @return {void}\n * this.turnLeft = function() {\n * ...\n * };\n * \n * // Robot will stay in the same cell after calling turnLeft/turnRight.\n * // Each turn will be 90 degrees.\n * @return {void} \n * this.turnRight = function() {\n * ...\n * };\n *\n * // Clean the current cell.\n * @return {void}\n * this.clean = function() {\n * ...\n * };\n * };\n */\n\n/**\n * @param {Robot} robot\n * @return {void}\n */\nvar cleanRoom = function(robot) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# This is the robot's control interface.\n# You should not implement it, or speculate about its implementation\n# class Robot\n# def move():\n# Returns true if the cell in front is open and robot moves into the cell.\n# Returns false if the cell in front is blocked and robot stays in the current cell.\n# end\n#\n# def turnLeft():\n# Robot will stay in the same cell after calling turnLeft/turnRight.\n# Each turn will be 90 degrees.\n# end\n#\n# def turnRight():\n# Robot will stay in the same cell after calling turnLeft/turnRight.\n# Each turn will be 90 degrees.\n# end\n#\n# def clean():\n# Clean the current cell.\n# end\n# end\n\n# @param {Robot} robot\n# @return {}\ndef cleanRoom(robot)\n\t\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * // This is the robot's control interface.\n * // You should not implement it, or speculate about its implementation\n * public class Robot {\n * // Returns true if the cell in front is open and robot moves into the cell.\n * // Returns false if the cell in front is blocked and robot stays in the current cell.\n * public func move() -> Bool {}\n *\n * // Robot will stay in the same cell after calling turnLeft/turnRight.\n * // Each turn will be 90 degrees.\n * public func turnLeft() {}\n * public func turnRight() {}\n *\n * // Clean the current cell.\n * public func clean() {}\n * }\n */\n\nclass Solution {\n func cleanRoom(_ robot: Robot) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * // This is the robot's control interface.\n * // You should not implement it, or speculate about its implementation\n * type Robot struct {\n * }\n * \n * // Returns true if the cell in front is open and robot moves into the cell.\n * // Returns false if the cell in front is blocked and robot stays in the current cell.\n * func (robot *Robot) Move() bool {}\n *\n * // Robot will stay in the same cell after calling TurnLeft/TurnRight.\n * // Each turn will be 90 degrees.\n * func (robot *Robot) TurnLeft() {}\n * func (robot *Robot) TurnRight() {}\n *\n * // Clean the current cell.\n * func (robot *Robot) Clean() {}\n */\n\nfunc cleanRoom(robot *Robot) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * // This is the robot's control interface.\n * // You should not implement it, or speculate about its implementation\n * class Robot {\n * // Returns true if the cell in front is open and robot moves into the cell.\n * // Returns false if the cell in front is blocked and robot stays in the current cell.\n * def move(): Boolean = {}\n *\n * // Robot will stay in the same cell after calling turnLeft/turnRight.\n * // Each turn will be 90 degrees.\n * def turnLeft(): Unit = {}\n * def turnRight(): Unit = {}\n *\n * // Clean the current cell.\n * def clean(): Unit = {}\n * }\n */\n\nobject Solution {\n def cleanRoom(robot: Robot): Unit = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * // This is the Robot's API interface.\n * // You should not implement it, or speculate about its implementation\n * class Robot {\n * // Returns true if the cell in front is open and robot moves into the cell.\n * // Returns false if the cell in front is blocked and robot stays in the current cell.\n * fun move(): Boolean {}\n *\n * // Robot will stay in the same cell after calling turnLeft/turnRight.\n * // Each turn will be 90 degrees.\n * fun turnLeft() {}\n * fun turnRight() {}\n *\n * // Clean the current cell.\n * fun clean() {}\n * }\n */\n\nclass Solution {\n fun cleanRoom(robot: Robot) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * // This is the Robot's control interface.\n * // You should not implement it, or speculate about its implementation\n * class Robot {\n * // Returns true if the cell in front is open and robot moves into the cell.\n * // Returns false if the cell in front is blocked and robot stays in the current cell.\n * function move() {}\n *\n * // Robot will stay in the same cell after calling turnLeft/turnRight.\n * // Each turn will be 90 degrees.\n * function turnLeft() {}\n * function turnRight() {}\n *\n * // Clean the current cell.\n * function clean() {}\n * }\n */\n\nclass Solution {\n /**\n * @param Robot $robot\n * @return \n */\n function cleanRoom($robot) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * class Robot {\n * // Returns true if the cell in front is open and robot moves into the cell.\n * // Returns false if the cell in front is blocked and robot stays in the current cell.\n * \t\tmove(): boolean {}\n * \t\t\n * // Robot will stay in the same cell after calling turnLeft/turnRight.\n * // Each turn will be 90 degrees.\n * \t\tturnRight() {}\n * \t\t\n * // Robot will stay in the same cell after calling turnLeft/turnRight.\n * // Each turn will be 90 degrees.\n * \t\tturnLeft() {}\n * \t\t\n * \t\t// Clean the current cell.\n * \t\tclean(): {}\n * }\n */\n\nfunction cleanRoom(robot: Robot) {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0489](https://leetcode-cn.com/problems/robot-room-cleaner)", "[\u626b\u5730\u673a\u5668\u4eba](/solution/0400-0499/0489.Robot%20Room%20Cleaner/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0489](https://leetcode.com/problems/robot-room-cleaner)", "[Robot Room Cleaner](/solution/0400-0499/0489.Robot%20Room%20Cleaner/README_EN.md)", "`Depth-first Search`", "Hard", "\ud83d\udd12"]}, {"question_id": "0864", "frontend_question_id": "0835", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/image-overlap", "url_en": "https://leetcode.com/problems/image-overlap", "relative_path_cn": "/solution/0800-0899/0835.Image%20Overlap/README.md", "relative_path_en": "/solution/0800-0899/0835.Image%20Overlap/README_EN.md", "title_cn": "\u56fe\u50cf\u91cd\u53e0", "title_en": "Image Overlap", "question_title_slug": "image-overlap", "content_en": "

You are given two images img1 and img2 both of size n x n, represented as binary, square matrices of the same size. (A binary matrix has only 0s and 1s as values.)

\n\n

We translate one image however we choose (sliding it left, right, up, or down any number of units), and place it on top of the other image.  After, the overlap of this translation is the number of positions that have a 1 in both images.

\n\n

(Note also that a translation does not include any kind of rotation.)

\n\n

What is the largest possible overlap?

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: img1 = [[1,1,0],[0,1,0],[0,1,0]], img2 = [[0,0,0],[0,1,1],[0,0,1]]\nOutput: 3\nExplanation: We slide img1 to right by 1 unit and down by 1 unit.\n\"\"\nThe number of positions that have a 1 in both images is 3. (Shown in red)\n\"\"\n
\n\n

Example 2:

\n\n
\nInput: img1 = [[1]], img2 = [[1]]\nOutput: 1\n
\n\n

Example 3:

\n\n
\nInput: img1 = [[0]], img2 = [[0]]\nOutput: 0\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == img1.length
  • \n\t
  • n == img1[i].length
  • \n\t
  • n == img2.length
  • \n\t
  • n == img2[i].length
  • \n\t
  • 1 <= n <= 30
  • \n\t
  • img1[i][j] is 0 or 1.
  • \n\t
  • img2[i][j] is 0 or 1.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e24\u4e2a\u56fe\u50cf img1 \u548c img2 \uff0c\u4e24\u4e2a\u56fe\u50cf\u7684\u5927\u5c0f\u90fd\u662f n x n \uff0c\u7528\u5927\u5c0f\u76f8\u540c\u7684\u4e8c\u7ef4\u6b63\u65b9\u5f62\u77e9\u9635\u8868\u793a\u3002\uff08\u5e76\u4e14\u4e3a\u4e8c\u8fdb\u5236\u77e9\u9635\uff0c\u53ea\u5305\u542b\u82e5\u5e72 0 \u548c\u82e5\u5e72 1 \uff09

\n\n

\u8f6c\u6362\u5176\u4e2d\u4e00\u4e2a\u56fe\u50cf\uff0c\u5411\u5de6\uff0c\u53f3\uff0c\u4e0a\uff0c\u6216\u4e0b\u6ed1\u52a8\u4efb\u4f55\u6570\u91cf\u7684\u5355\u4f4d\uff0c\u5e76\u628a\u5b83\u653e\u5728\u53e6\u4e00\u4e2a\u56fe\u50cf\u7684\u4e0a\u9762\u3002\u4e4b\u540e\uff0c\u8be5\u8f6c\u6362\u7684 \u91cd\u53e0 \u662f\u6307\u4e24\u4e2a\u56fe\u50cf\u90fd\u5177\u6709 1 \u7684\u4f4d\u7f6e\u7684\u6570\u76ee\u3002

\n\n
\n
\n

\uff08\u8bf7\u6ce8\u610f\uff0c\u8f6c\u6362 \u4e0d\u5305\u62ec \u5411\u4efb\u4f55\u65b9\u5411\u65cb\u8f6c\u3002\uff09

\n\n

\u6700\u5927\u53ef\u80fd\u7684\u91cd\u53e0\u662f\u591a\u5c11\uff1f

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1aimg1 = [[1,1,0],[0,1,0],[0,1,0]], img2 = [[0,0,0],[0,1,1],[0,0,1]]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u5c06 img1 \u5411\u53f3\u79fb\u52a8 1 \u4e2a\u5355\u4f4d\uff0c\u518d\u5411\u4e0b\u79fb\u52a8 1 \u4e2a\u5355\u4f4d\u3002\n\"\"\n\u4e24\u4e2a\u56fe\u50cf\u90fd\u5177\u6709 1 \u7684\u4f4d\u7f6e\u7684\u6570\u76ee\u662f 3\uff08\u7528\u7ea2\u8272\u6807\u8bc6\uff09\u3002\n\"\"\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aimg1 = [[1]], img2 = [[1]]\n\u8f93\u51fa\uff1a1\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1aimg1 = [[0]], img2 = [[0]]\n\u8f93\u51fa\uff1a0\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • n == img1.length
  • \n\t
  • n == img1[i].length
  • \n\t
  • n == img2.length
  • \n\t
  • n == img2[i].length
  • \n\t
  • 1 <= n <= 30
  • \n\t
  • img1[i][j] \u4e3a 0 \u6216 1
  • \n\t
  • img2[i][j] \u4e3a 0 \u6216 1
  • \n
\n
\n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int largestOverlap(vector>& img1, vector>& img2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int largestOverlap(int[][] img1, int[][] img2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def largestOverlap(self, img1, img2):\n \"\"\"\n :type img1: List[List[int]]\n :type img2: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def largestOverlap(self, img1: List[List[int]], img2: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint largestOverlap(int** img1, int img1Size, int* img1ColSize, int** img2, int img2Size, int* img2ColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LargestOverlap(int[][] img1, int[][] img2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} img1\n * @param {number[][]} img2\n * @return {number}\n */\nvar largestOverlap = function(img1, img2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} img1\n# @param {Integer[][]} img2\n# @return {Integer}\ndef largest_overlap(img1, img2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func largestOverlap(_ img1: [[Int]], _ img2: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func largestOverlap(img1 [][]int, img2 [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def largestOverlap(img1: Array[Array[Int]], img2: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun largestOverlap(img1: Array, img2: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn largest_overlap(img1: Vec>, img2: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $img1\n * @param Integer[][] $img2\n * @return Integer\n */\n function largestOverlap($img1, $img2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function largestOverlap(img1: number[][], img2: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (largest-overlap img1 img2)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0835](https://leetcode-cn.com/problems/image-overlap)", "[\u56fe\u50cf\u91cd\u53e0](/solution/0800-0899/0835.Image%20Overlap/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0835](https://leetcode.com/problems/image-overlap)", "[Image Overlap](/solution/0800-0899/0835.Image%20Overlap/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0863", "frontend_question_id": "0834", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sum-of-distances-in-tree", "url_en": "https://leetcode.com/problems/sum-of-distances-in-tree", "relative_path_cn": "/solution/0800-0899/0834.Sum%20of%20Distances%20in%20Tree/README.md", "relative_path_en": "/solution/0800-0899/0834.Sum%20of%20Distances%20in%20Tree/README_EN.md", "title_cn": "\u6811\u4e2d\u8ddd\u79bb\u4e4b\u548c", "title_en": "Sum of Distances in Tree", "question_title_slug": "sum-of-distances-in-tree", "content_en": "

An undirected, connected tree with n nodes labelled 0...n-1 and n-1 edges are given.

\n\n

The ith edge connects nodes edges[i][0] and edges[i][1] together.

\n\n

Return a list ans, where ans[i] is the sum of the distances between node i and all other nodes.

\n\n

Example 1:

\n\n
\nInput: n = 6, edges = [[0,1],[0,2],[2,3],[2,4],[2,5]]\nOutput: [8,12,6,10,10,10]\nExplanation: \nHere is a diagram of the given tree:\n  0\n / \\\n1   2\n   /|\\\n  3 4 5\nWe can see that dist(0,1) + dist(0,2) + dist(0,3) + dist(0,4) + dist(0,5)\nequals 1 + 1 + 2 + 2 + 2 = 8.  Hence, answer[0] = 8, and so on.\n
\n\n

Note: 1 <= n <= 10000

\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u65e0\u5411\u3001\u8fde\u901a\u7684\u6811\u3002\u6811\u4e2d\u6709 N \u4e2a\u6807\u8bb0\u4e3a 0...N-1 \u7684\u8282\u70b9\u4ee5\u53ca N-1 \u6761\u8fb9 \u3002

\n\n

\u7b2c i \u6761\u8fb9\u8fde\u63a5\u8282\u70b9 edges[i][0] \u548c edges[i][1] \u3002

\n\n

\u8fd4\u56de\u4e00\u4e2a\u8868\u793a\u8282\u70b9 i \u4e0e\u5176\u4ed6\u6240\u6709\u8282\u70b9\u8ddd\u79bb\u4e4b\u548c\u7684\u5217\u8868 ans\u3002

\n\n

\u793a\u4f8b 1:

\n\n
\n\u8f93\u5165: N = 6, edges = [[0,1],[0,2],[2,3],[2,4],[2,5]]\n\u8f93\u51fa: [8,12,6,10,10,10]\n\u89e3\u91ca: \n\u5982\u4e0b\u4e3a\u7ed9\u5b9a\u7684\u6811\u7684\u793a\u610f\u56fe\uff1a\n  0\n / \\\n1   2\n   /|\\\n  3 4 5\n\n\u6211\u4eec\u53ef\u4ee5\u8ba1\u7b97\u51fa dist(0,1) + dist(0,2) + dist(0,3) + dist(0,4) + dist(0,5) \n\u4e5f\u5c31\u662f 1 + 1 + 2 + 2 + 2 = 8\u3002 \u56e0\u6b64\uff0canswer[0] = 8\uff0c\u4ee5\u6b64\u7c7b\u63a8\u3002\n
\n\n

\u8bf4\u660e: 1 <= N <= 10000

\n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector sumOfDistancesInTree(int n, vector>& edges) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] sumOfDistancesInTree(int n, int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def sumOfDistancesInTree(self, n, edges):\n \"\"\"\n :type n: int\n :type edges: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def sumOfDistancesInTree(self, n: int, edges: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* sumOfDistancesInTree(int n, int** edges, int edgesSize, int* edgesColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] SumOfDistancesInTree(int n, int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} edges\n * @return {number[]}\n */\nvar sumOfDistancesInTree = function(n, edges) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} edges\n# @return {Integer[]}\ndef sum_of_distances_in_tree(n, edges)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func sumOfDistancesInTree(_ n: Int, _ edges: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func sumOfDistancesInTree(n int, edges [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def sumOfDistancesInTree(n: Int, edges: Array[Array[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun sumOfDistancesInTree(n: Int, edges: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sum_of_distances_in_tree(n: i32, edges: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $edges\n * @return Integer[]\n */\n function sumOfDistancesInTree($n, $edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function sumOfDistancesInTree(n: number, edges: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (sum-of-distances-in-tree n edges)\n (-> exact-integer? (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0834](https://leetcode-cn.com/problems/sum-of-distances-in-tree)", "[\u6811\u4e2d\u8ddd\u79bb\u4e4b\u548c](/solution/0800-0899/0834.Sum%20of%20Distances%20in%20Tree/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[0834](https://leetcode.com/problems/sum-of-distances-in-tree)", "[Sum of Distances in Tree](/solution/0800-0899/0834.Sum%20of%20Distances%20in%20Tree/README_EN.md)", "`Tree`,`Depth-first Search`", "Hard", ""]}, {"question_id": "0862", "frontend_question_id": "0833", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-and-replace-in-string", "url_en": "https://leetcode.com/problems/find-and-replace-in-string", "relative_path_cn": "/solution/0800-0899/0833.Find%20And%20Replace%20in%20String/README.md", "relative_path_en": "/solution/0800-0899/0833.Find%20And%20Replace%20in%20String/README_EN.md", "title_cn": "\u5b57\u7b26\u4e32\u4e2d\u7684\u67e5\u627e\u4e0e\u66ff\u6362", "title_en": "Find And Replace in String", "question_title_slug": "find-and-replace-in-string", "content_en": "

To some string s, we will perform some replacement operations that replace groups of letters with new ones (not necessarily the same size).

\n\n

Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.

\n\n

For example, if we have s = "abcd" and we have some replacement operation i = 2, x = "cd", y = "ffff", then because "cd" starts at position 2 in the original string s, we will replace it with "ffff".

\n\n

Using another example on s = "abcd", if we have both the replacement operation i = 0, x = "ab", y = "eee", as well as another replacement operation i = 2, x = "ec", y = "ffff", this second operation does nothing because in the original string s[2] = 'c', which doesn't match x[0] = 'e'.

\n\n

All these operations occur simultaneously. It's guaranteed that there won't be any overlap in replacement: for example, s = "abc", indexes = [0, 1], sources = ["ab","bc"] is not a valid test case.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "abcd", indexes = [0, 2], sources = ["a", "cd"], targets = ["eee", "ffff"]\nOutput: "eeebffff"\nExplanation:\n"a" starts at index 0 in s, so it's replaced by "eee".\n"cd" starts at index 2 in s, so it's replaced by "ffff".\n
\n\n

Example 2:

\n\n
\nInput: s = "abcd", indexes = [0, 2], sources = ["ab","ec"], targets = ["eee","ffff"]\nOutput: "eeecd"\nExplanation:\n"ab" starts at index 0 in s, so it's replaced by "eee".\n"ec" doesn't starts at index 2 in the original s, so we do nothing.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 0 <= s.length <= 1000
  • \n\t
  • s consists of only lowercase English letters.
  • \n\t
  • 0 <= indexes.length <= 100
  • \n\t
  • 0 <= indexes[i] < s.length
  • \n\t
  • sources.length == indexes.length
  • \n\t
  • targets.length == indexes.length
  • \n\t
  • 1 <= sources[i].length, targets[i].length <= 50
  • \n\t
  • sources[i] and targets[i] consist of only lowercase English letters.
  • \n
\n", "content_cn": "

\u67d0\u4e2a\u5b57\u7b26\u4e32 S \u9700\u8981\u6267\u884c\u4e00\u4e9b\u66ff\u6362\u64cd\u4f5c\uff0c\u7528\u65b0\u7684\u5b57\u6bcd\u7ec4\u66ff\u6362\u539f\u6709\u7684\u5b57\u6bcd\u7ec4\uff08\u4e0d\u4e00\u5b9a\u5927\u5c0f\u76f8\u540c\uff09\u3002

\n\n

\u6bcf\u4e2a\u66ff\u6362\u64cd\u4f5c\u5177\u6709 3 \u4e2a\u53c2\u6570\uff1a\u8d77\u59cb\u7d22\u5f15 i\uff0c\u6e90\u5b57 x \u548c\u76ee\u6807\u5b57 y\u3002\u89c4\u5219\u662f\uff1a\u5982\u679c x \u4ece\u539f\u59cb\u5b57\u7b26\u4e32 S \u4e2d\u7684\u4f4d\u7f6e i \u5f00\u59cb\uff0c\u90a3\u4e48\u5c31\u7528 y \u66ff\u6362\u51fa\u73b0\u7684 x\u3002\u5982\u679c\u6ca1\u6709\uff0c\u5219\u4ec0\u4e48\u90fd\u4e0d\u505a\u3002

\n\n

\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u5982\u679c S\u00a0= \u201cabcd\u201d \u5e76\u4e14\u66ff\u6362\u64cd\u4f5c i = 2\uff0cx = \u201ccd\u201d\uff0cy = \u201cffff\u201d\uff0c\u90a3\u4e48\u56e0\u4e3a \u201ccd\u201d \u4ece\u539f\u59cb\u5b57\u7b26\u4e32 S \u4e2d\u7684\u4f4d\u7f6e 2 \u5f00\u59cb\uff0c\u6240\u4ee5\u7528\u00a0\u201cffff\u201d \u66ff\u6362\u5b83\u3002

\n\n

\u518d\u6765\u770b S = \u201cabcd\u201d \u4e0a\u7684\u53e6\u4e00\u4e2a\u4f8b\u5b50\uff0c\u5982\u679c\u4e00\u4e2a\u66ff\u6362\u64cd\u4f5c i = 0\uff0cx = \u201cab\u201d\uff0cy = \u201ceee\u201d\uff0c\u4ee5\u53ca\u53e6\u4e00\u4e2a\u66ff\u6362\u64cd\u4f5c i = 2\uff0cx = \u201cec\u201d\uff0cy = \u201cffff\u201d\uff0c\u90a3\u4e48\u7b2c\u4e8c\u4e2a\u64cd\u4f5c\u5c06\u4e0d\u4f1a\u6267\u884c\uff0c\u56e0\u4e3a\u539f\u59cb\u5b57\u7b26\u4e32\u4e2d\u00a0S[2] = 'c'\uff0c\u4e0e x[0] = 'e' \u4e0d\u5339\u914d\u3002

\n\n

\u6240\u6709\u8fd9\u4e9b\u64cd\u4f5c\u540c\u65f6\u53d1\u751f\u3002\u4fdd\u8bc1\u5728\u66ff\u6362\u65f6\u4e0d\u4f1a\u6709\u4efb\u4f55\u91cd\u53e0\uff1a\u00a0S = \"abc\", indexes = [0, 1],\u00a0sources = [\"ab\",\"bc\"] \u4e0d\u662f\u6709\u6548\u7684\u6d4b\u8bd5\u7528\u4f8b\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aS = \"abcd\", indexes = [0,2], sources = [\"a\",\"cd\"], targets = [\"eee\",\"ffff\"]\n\u8f93\u51fa\uff1a\"eeebffff\"\n\u89e3\u91ca\uff1a\n\"a\" \u4ece S \u4e2d\u7684\u7d22\u5f15 0 \u5f00\u59cb\uff0c\u6240\u4ee5\u5b83\u88ab\u66ff\u6362\u4e3a \"eee\"\u3002\n\"cd\" \u4ece S \u4e2d\u7684\u7d22\u5f15 2 \u5f00\u59cb\uff0c\u6240\u4ee5\u5b83\u88ab\u66ff\u6362\u4e3a \"ffff\"\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aS = \"abcd\", indexes = [0,2], sources = [\"ab\",\"ec\"], targets = [\"eee\",\"ffff\"]\n\u8f93\u51fa\uff1a\"eeecd\"\n\u89e3\u91ca\uff1a\n\"ab\" \u4ece S \u4e2d\u7684\u7d22\u5f15 0 \u5f00\u59cb\uff0c\u6240\u4ee5\u5b83\u88ab\u66ff\u6362\u4e3a \"eee\"\u3002\n\"ec\" \u6ca1\u6709\u4ece\u539f\u59cb\u7684 S \u4e2d\u7684\u7d22\u5f15 2 \u5f00\u59cb\uff0c\u6240\u4ee5\u5b83\u6ca1\u6709\u88ab\u66ff\u6362\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 0 <= S.length <= 1000
  • \n\t
  • S \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
  • \n\t
  • 0 <= indexes.length <= 100
  • \n\t
  • 0 <= indexes[i] < S.length
  • \n\t
  • sources.length == indexes.length
  • \n\t
  • targets.length == indexes.length
  • \n\t
  • 1 <= sources[i].length, targets[i].length <= 50
  • \n\t
  • sources[i] \u548c targets[i] \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
  • \n
\n\n

\u00a0

\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string findReplaceString(string s, vector& indexes, vector& sources, vector& targets) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String findReplaceString(String s, int[] indexes, String[] sources, String[] targets) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findReplaceString(self, s, indexes, sources, targets):\n \"\"\"\n :type s: str\n :type indexes: List[int]\n :type sources: List[str]\n :type targets: List[str]\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findReplaceString(self, s: str, indexes: List[int], sources: List[str], targets: List[str]) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * findReplaceString(char * s, int* indexes, int indexesSize, char ** sources, int sourcesSize, char ** targets, int targetsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string FindReplaceString(string s, int[] indexes, string[] sources, string[] targets) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number[]} indexes\n * @param {string[]} sources\n * @param {string[]} targets\n * @return {string}\n */\nvar findReplaceString = function(s, indexes, sources, targets) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer[]} indexes\n# @param {String[]} sources\n# @param {String[]} targets\n# @return {String}\ndef find_replace_string(s, indexes, sources, targets)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findReplaceString(_ s: String, _ indexes: [Int], _ sources: [String], _ targets: [String]) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findReplaceString(s string, indexes []int, sources []string, targets []string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findReplaceString(s: String, indexes: Array[Int], sources: Array[String], targets: Array[String]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findReplaceString(s: String, indexes: IntArray, sources: Array, targets: Array): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_replace_string(s: String, indexes: Vec, sources: Vec, targets: Vec) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer[] $indexes\n * @param String[] $sources\n * @param String[] $targets\n * @return String\n */\n function findReplaceString($s, $indexes, $sources, $targets) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findReplaceString(s: string, indexes: number[], sources: string[], targets: string[]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-replace-string s indexes sources targets)\n (-> string? (listof exact-integer?) (listof string?) (listof string?) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0833](https://leetcode-cn.com/problems/find-and-replace-in-string)", "[\u5b57\u7b26\u4e32\u4e2d\u7684\u67e5\u627e\u4e0e\u66ff\u6362](/solution/0800-0899/0833.Find%20And%20Replace%20in%20String/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0833](https://leetcode.com/problems/find-and-replace-in-string)", "[Find And Replace in String](/solution/0800-0899/0833.Find%20And%20Replace%20in%20String/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "0861", "frontend_question_id": "0832", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/flipping-an-image", "url_en": "https://leetcode.com/problems/flipping-an-image", "relative_path_cn": "/solution/0800-0899/0832.Flipping%20an%20Image/README.md", "relative_path_en": "/solution/0800-0899/0832.Flipping%20an%20Image/README_EN.md", "title_cn": "\u7ffb\u8f6c\u56fe\u50cf", "title_en": "Flipping an Image", "question_title_slug": "flipping-an-image", "content_en": "

Given an n x n binary matrix image, flip the image horizontally, then invert it, and return the resulting image.

\n\n

To flip an image horizontally means that each row of the image is reversed.

\n\n
    \n\t
  • For example, flipping [1,1,0] horizontally results in [0,1,1].
  • \n
\n\n

To invert an image means that each 0 is replaced by 1, and each 1 is replaced by 0.

\n\n
    \n\t
  • For example, inverting [0,1,1] results in [1,0,0].
  • \n
\n\n

 

\n

Example 1:

\n\n
\nInput: image = [[1,1,0],[1,0,1],[0,0,0]]\nOutput: [[1,0,0],[0,1,0],[1,1,1]]\nExplanation: First reverse each row: [[0,1,1],[1,0,1],[0,0,0]].\nThen, invert the image: [[1,0,0],[0,1,0],[1,1,1]]\n
\n\n

Example 2:

\n\n
\nInput: image = [[1,1,0,0],[1,0,0,1],[0,1,1,1],[1,0,1,0]]\nOutput: [[1,1,0,0],[0,1,1,0],[0,0,0,1],[1,0,1,0]]\nExplanation: First reverse each row: [[0,0,1,1],[1,0,0,1],[1,1,1,0],[0,1,0,1]].\nThen invert the image: [[1,1,0,0],[0,1,1,0],[0,0,0,1],[1,0,1,0]]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == image.length
  • \n\t
  • n == image[i].length
  • \n\t
  • 1 <= n <= 20
  • \n\t
  • images[i][j] is either 0 or 1.
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u8fdb\u5236\u77e9\u9635\u00a0A\uff0c\u6211\u4eec\u60f3\u5148\u6c34\u5e73\u7ffb\u8f6c\u56fe\u50cf\uff0c\u7136\u540e\u53cd\u8f6c\u56fe\u50cf\u5e76\u8fd4\u56de\u7ed3\u679c\u3002

\n\n

\u6c34\u5e73\u7ffb\u8f6c\u56fe\u7247\u5c31\u662f\u5c06\u56fe\u7247\u7684\u6bcf\u4e00\u884c\u90fd\u8fdb\u884c\u7ffb\u8f6c\uff0c\u5373\u9006\u5e8f\u3002\u4f8b\u5982\uff0c\u6c34\u5e73\u7ffb\u8f6c\u00a0[1, 1, 0]\u00a0\u7684\u7ed3\u679c\u662f\u00a0[0, 1, 1]\u3002

\n\n

\u53cd\u8f6c\u56fe\u7247\u7684\u610f\u601d\u662f\u56fe\u7247\u4e2d\u7684\u00a00\u00a0\u5168\u90e8\u88ab\u00a01\u00a0\u66ff\u6362\uff0c\u00a01\u00a0\u5168\u90e8\u88ab\u00a00\u00a0\u66ff\u6362\u3002\u4f8b\u5982\uff0c\u53cd\u8f6c\u00a0[0, 1, 1]\u00a0\u7684\u7ed3\u679c\u662f\u00a0[1, 0, 0]\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1a[[1,1,0],[1,0,1],[0,0,0]]\n\u8f93\u51fa\uff1a[[1,0,0],[0,1,0],[1,1,1]]\n\u89e3\u91ca\uff1a\u9996\u5148\u7ffb\u8f6c\u6bcf\u4e00\u884c: [[0,1,1],[1,0,1],[0,0,0]]\uff1b\n     \u7136\u540e\u53cd\u8f6c\u56fe\u7247: [[1,0,0],[0,1,0],[1,1,1]]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1a[[1,1,0,0],[1,0,0,1],[0,1,1,1],[1,0,1,0]]\n\u8f93\u51fa\uff1a[[1,1,0,0],[0,1,1,0],[0,0,0,1],[1,0,1,0]]\n\u89e3\u91ca\uff1a\u9996\u5148\u7ffb\u8f6c\u6bcf\u4e00\u884c: [[0,0,1,1],[1,0,0,1],[1,1,1,0],[0,1,0,1]]\uff1b\n     \u7136\u540e\u53cd\u8f6c\u56fe\u7247: [[1,1,0,0],[0,1,1,0],[0,0,0,1],[1,0,1,0]]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= A.length = A[0].length <= 20
  • \n\t
  • 0 <= A[i][j]\u00a0<=\u00a01
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> flipAndInvertImage(vector>& image) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[][] flipAndInvertImage(int[][] image) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def flipAndInvertImage(self, image):\n \"\"\"\n :type image: List[List[int]]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def flipAndInvertImage(self, image: List[List[int]]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** flipAndInvertImage(int** image, int imageSize, int* imageColSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[][] FlipAndInvertImage(int[][] image) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} image\n * @return {number[][]}\n */\nvar flipAndInvertImage = function(image) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} image\n# @return {Integer[][]}\ndef flip_and_invert_image(image)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func flipAndInvertImage(_ image: [[Int]]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func flipAndInvertImage(image [][]int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def flipAndInvertImage(image: Array[Array[Int]]): Array[Array[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun flipAndInvertImage(image: Array): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn flip_and_invert_image(image: Vec>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $image\n * @return Integer[][]\n */\n function flipAndInvertImage($image) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function flipAndInvertImage(image: number[][]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (flip-and-invert-image image)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0832](https://leetcode-cn.com/problems/flipping-an-image)", "[\u7ffb\u8f6c\u56fe\u50cf](/solution/0800-0899/0832.Flipping%20an%20Image/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0832](https://leetcode.com/problems/flipping-an-image)", "[Flipping an Image](/solution/0800-0899/0832.Flipping%20an%20Image/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0860", "frontend_question_id": "0622", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/design-circular-queue", "url_en": "https://leetcode.com/problems/design-circular-queue", "relative_path_cn": "/solution/0600-0699/0622.Design%20Circular%20Queue/README.md", "relative_path_en": "/solution/0600-0699/0622.Design%20Circular%20Queue/README_EN.md", "title_cn": "\u8bbe\u8ba1\u5faa\u73af\u961f\u5217", "title_en": "Design Circular Queue", "question_title_slug": "design-circular-queue", "content_en": "

Design your implementation of the circular queue. The circular queue is a linear data structure in which the operations are performed based on FIFO (First In First Out) principle and the last position is connected back to the first position to make a circle. It is also called "Ring Buffer".

\n\n

One of the benefits of the circular queue is that we can make use of the spaces in front of the queue. In a normal queue, once the queue becomes full, we cannot insert the next element even if there is a space in front of the queue. But using the circular queue, we can use the space to store new values.

\n\n

Implementation the MyCircularQueue class:

\n\n
    \n\t
  • MyCircularQueue(k) Initializes the object with the size of the queue to be k.
  • \n\t
  • int Front() Gets the front item from the queue. If the queue is empty, return -1.
  • \n\t
  • int Rear() Gets the last item from the queue. If the queue is empty, return -1.
  • \n\t
  • boolean enQueue(int value) Inserts an element into the circular queue. Return true if the operation is successful.
  • \n\t
  • boolean deQueue() Deletes an element from the circular queue. Return true if the operation is successful.
  • \n\t
  • boolean isEmpty() Checks whether the circular queue is empty or not.
  • \n\t
  • boolean isFull() Checks whether the circular queue is full or not.
  • \n
\n\n

You must solve the problem without using the built-in queue data structure in your programming language. 

\n\n

 

\n

Example 1:

\n\n
\nInput\n["MyCircularQueue", "enQueue", "enQueue", "enQueue", "enQueue", "Rear", "isFull", "deQueue", "enQueue", "Rear"]\n[[3], [1], [2], [3], [4], [], [], [], [4], []]\nOutput\n[null, true, true, true, false, 3, true, true, true, 4]\n\nExplanation\nMyCircularQueue myCircularQueue = new MyCircularQueue(3);\nmyCircularQueue.enQueue(1); // return True\nmyCircularQueue.enQueue(2); // return True\nmyCircularQueue.enQueue(3); // return True\nmyCircularQueue.enQueue(4); // return False\nmyCircularQueue.Rear();     // return 3\nmyCircularQueue.isFull();   // return True\nmyCircularQueue.deQueue();  // return True\nmyCircularQueue.enQueue(4); // return True\nmyCircularQueue.Rear();     // return 4\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= k <= 1000
  • \n\t
  • 0 <= value <= 1000
  • \n\t
  • At most 3000 calls will be made to enQueue, deQueueFrontRearisEmpty, and isFull.
  • \n
\n", "content_cn": "

\u8bbe\u8ba1\u4f60\u7684\u5faa\u73af\u961f\u5217\u5b9e\u73b0\u3002 \u5faa\u73af\u961f\u5217\u662f\u4e00\u79cd\u7ebf\u6027\u6570\u636e\u7ed3\u6784\uff0c\u5176\u64cd\u4f5c\u8868\u73b0\u57fa\u4e8e FIFO\uff08\u5148\u8fdb\u5148\u51fa\uff09\u539f\u5219\u5e76\u4e14\u961f\u5c3e\u88ab\u8fde\u63a5\u5728\u961f\u9996\u4e4b\u540e\u4ee5\u5f62\u6210\u4e00\u4e2a\u5faa\u73af\u3002\u5b83\u4e5f\u88ab\u79f0\u4e3a“\u73af\u5f62\u7f13\u51b2\u5668”\u3002

\n\n

\u5faa\u73af\u961f\u5217\u7684\u4e00\u4e2a\u597d\u5904\u662f\u6211\u4eec\u53ef\u4ee5\u5229\u7528\u8fd9\u4e2a\u961f\u5217\u4e4b\u524d\u7528\u8fc7\u7684\u7a7a\u95f4\u3002\u5728\u4e00\u4e2a\u666e\u901a\u961f\u5217\u91cc\uff0c\u4e00\u65e6\u4e00\u4e2a\u961f\u5217\u6ee1\u4e86\uff0c\u6211\u4eec\u5c31\u4e0d\u80fd\u63d2\u5165\u4e0b\u4e00\u4e2a\u5143\u7d20\uff0c\u5373\u4f7f\u5728\u961f\u5217\u524d\u9762\u4ecd\u6709\u7a7a\u95f4\u3002\u4f46\u662f\u4f7f\u7528\u5faa\u73af\u961f\u5217\uff0c\u6211\u4eec\u80fd\u4f7f\u7528\u8fd9\u4e9b\u7a7a\u95f4\u53bb\u5b58\u50a8\u65b0\u7684\u503c\u3002

\n\n

\u4f60\u7684\u5b9e\u73b0\u5e94\u8be5\u652f\u6301\u5982\u4e0b\u64cd\u4f5c\uff1a

\n\n
    \n\t
  • MyCircularQueue(k): \u6784\u9020\u5668\uff0c\u8bbe\u7f6e\u961f\u5217\u957f\u5ea6\u4e3a k \u3002
  • \n\t
  • Front: \u4ece\u961f\u9996\u83b7\u53d6\u5143\u7d20\u3002\u5982\u679c\u961f\u5217\u4e3a\u7a7a\uff0c\u8fd4\u56de -1 \u3002
  • \n\t
  • Rear: \u83b7\u53d6\u961f\u5c3e\u5143\u7d20\u3002\u5982\u679c\u961f\u5217\u4e3a\u7a7a\uff0c\u8fd4\u56de -1 \u3002
  • \n\t
  • enQueue(value): \u5411\u5faa\u73af\u961f\u5217\u63d2\u5165\u4e00\u4e2a\u5143\u7d20\u3002\u5982\u679c\u6210\u529f\u63d2\u5165\u5219\u8fd4\u56de\u771f\u3002
  • \n\t
  • deQueue(): \u4ece\u5faa\u73af\u961f\u5217\u4e2d\u5220\u9664\u4e00\u4e2a\u5143\u7d20\u3002\u5982\u679c\u6210\u529f\u5220\u9664\u5219\u8fd4\u56de\u771f\u3002
  • \n\t
  • isEmpty(): \u68c0\u67e5\u5faa\u73af\u961f\u5217\u662f\u5426\u4e3a\u7a7a\u3002
  • \n\t
  • isFull(): \u68c0\u67e5\u5faa\u73af\u961f\u5217\u662f\u5426\u5df2\u6ee1\u3002
  • \n
\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
MyCircularQueue circularQueue = new MyCircularQueue(3); // \u8bbe\u7f6e\u957f\u5ea6\u4e3a 3\ncircularQueue.enQueue(1);  // \u8fd4\u56de true\ncircularQueue.enQueue(2);  // \u8fd4\u56de true\ncircularQueue.enQueue(3);  // \u8fd4\u56de true\ncircularQueue.enQueue(4);  // \u8fd4\u56de false\uff0c\u961f\u5217\u5df2\u6ee1\ncircularQueue.Rear();  // \u8fd4\u56de 3\ncircularQueue.isFull();  // \u8fd4\u56de true\ncircularQueue.deQueue();  // \u8fd4\u56de true\ncircularQueue.enQueue(4);  // \u8fd4\u56de true\ncircularQueue.Rear();  // \u8fd4\u56de 4
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u6240\u6709\u7684\u503c\u90fd\u5728 0 \u81f3 1000 \u7684\u8303\u56f4\u5185\uff1b
  • \n\t
  • \u64cd\u4f5c\u6570\u5c06\u5728 1 \u81f3 1000 \u7684\u8303\u56f4\u5185\uff1b
  • \n\t
  • \u8bf7\u4e0d\u8981\u4f7f\u7528\u5185\u7f6e\u7684\u961f\u5217\u5e93\u3002
  • \n
\n", "tags_en": ["Design", "Queue"], "tags_cn": ["\u8bbe\u8ba1", "\u961f\u5217"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class MyCircularQueue {\npublic:\n MyCircularQueue(int k) {\n\n }\n \n bool enQueue(int value) {\n\n }\n \n bool deQueue() {\n\n }\n \n int Front() {\n\n }\n \n int Rear() {\n\n }\n \n bool isEmpty() {\n\n }\n \n bool isFull() {\n\n }\n};\n\n/**\n * Your MyCircularQueue object will be instantiated and called as such:\n * MyCircularQueue* obj = new MyCircularQueue(k);\n * bool param_1 = obj->enQueue(value);\n * bool param_2 = obj->deQueue();\n * int param_3 = obj->Front();\n * int param_4 = obj->Rear();\n * bool param_5 = obj->isEmpty();\n * bool param_6 = obj->isFull();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class MyCircularQueue {\n\n public MyCircularQueue(int k) {\n\n }\n \n public boolean enQueue(int value) {\n\n }\n \n public boolean deQueue() {\n\n }\n \n public int Front() {\n\n }\n \n public int Rear() {\n\n }\n \n public boolean isEmpty() {\n\n }\n \n public boolean isFull() {\n\n }\n}\n\n/**\n * Your MyCircularQueue object will be instantiated and called as such:\n * MyCircularQueue obj = new MyCircularQueue(k);\n * boolean param_1 = obj.enQueue(value);\n * boolean param_2 = obj.deQueue();\n * int param_3 = obj.Front();\n * int param_4 = obj.Rear();\n * boolean param_5 = obj.isEmpty();\n * boolean param_6 = obj.isFull();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class MyCircularQueue(object):\n\n def __init__(self, k):\n \"\"\"\n :type k: int\n \"\"\"\n\n\n def enQueue(self, value):\n \"\"\"\n :type value: int\n :rtype: bool\n \"\"\"\n\n\n def deQueue(self):\n \"\"\"\n :rtype: bool\n \"\"\"\n\n\n def Front(self):\n \"\"\"\n :rtype: int\n \"\"\"\n\n\n def Rear(self):\n \"\"\"\n :rtype: int\n \"\"\"\n\n\n def isEmpty(self):\n \"\"\"\n :rtype: bool\n \"\"\"\n\n\n def isFull(self):\n \"\"\"\n :rtype: bool\n \"\"\"\n\n\n\n# Your MyCircularQueue object will be instantiated and called as such:\n# obj = MyCircularQueue(k)\n# param_1 = obj.enQueue(value)\n# param_2 = obj.deQueue()\n# param_3 = obj.Front()\n# param_4 = obj.Rear()\n# param_5 = obj.isEmpty()\n# param_6 = obj.isFull()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class MyCircularQueue:\n\n def __init__(self, k: int):\n\n\n def enQueue(self, value: int) -> bool:\n\n\n def deQueue(self) -> bool:\n\n\n def Front(self) -> int:\n\n\n def Rear(self) -> int:\n\n\n def isEmpty(self) -> bool:\n\n\n def isFull(self) -> bool:\n\n\n\n# Your MyCircularQueue object will be instantiated and called as such:\n# obj = MyCircularQueue(k)\n# param_1 = obj.enQueue(value)\n# param_2 = obj.deQueue()\n# param_3 = obj.Front()\n# param_4 = obj.Rear()\n# param_5 = obj.isEmpty()\n# param_6 = obj.isFull()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} MyCircularQueue;\n\n\nMyCircularQueue* myCircularQueueCreate(int k) {\n\n}\n\nbool myCircularQueueEnQueue(MyCircularQueue* obj, int value) {\n\n}\n\nbool myCircularQueueDeQueue(MyCircularQueue* obj) {\n\n}\n\nint myCircularQueueFront(MyCircularQueue* obj) {\n\n}\n\nint myCircularQueueRear(MyCircularQueue* obj) {\n\n}\n\nbool myCircularQueueIsEmpty(MyCircularQueue* obj) {\n\n}\n\nbool myCircularQueueIsFull(MyCircularQueue* obj) {\n\n}\n\nvoid myCircularQueueFree(MyCircularQueue* obj) {\n\n}\n\n/**\n * Your MyCircularQueue struct will be instantiated and called as such:\n * MyCircularQueue* obj = myCircularQueueCreate(k);\n * bool param_1 = myCircularQueueEnQueue(obj, value);\n \n * bool param_2 = myCircularQueueDeQueue(obj);\n \n * int param_3 = myCircularQueueFront(obj);\n \n * int param_4 = myCircularQueueRear(obj);\n \n * bool param_5 = myCircularQueueIsEmpty(obj);\n \n * bool param_6 = myCircularQueueIsFull(obj);\n \n * myCircularQueueFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class MyCircularQueue {\n\n public MyCircularQueue(int k) {\n\n }\n \n public bool EnQueue(int value) {\n\n }\n \n public bool DeQueue() {\n\n }\n \n public int Front() {\n\n }\n \n public int Rear() {\n\n }\n \n public bool IsEmpty() {\n\n }\n \n public bool IsFull() {\n\n }\n}\n\n/**\n * Your MyCircularQueue object will be instantiated and called as such:\n * MyCircularQueue obj = new MyCircularQueue(k);\n * bool param_1 = obj.EnQueue(value);\n * bool param_2 = obj.DeQueue();\n * int param_3 = obj.Front();\n * int param_4 = obj.Rear();\n * bool param_5 = obj.IsEmpty();\n * bool param_6 = obj.IsFull();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} k\n */\nvar MyCircularQueue = function(k) {\n\n};\n\n/** \n * @param {number} value\n * @return {boolean}\n */\nMyCircularQueue.prototype.enQueue = function(value) {\n\n};\n\n/**\n * @return {boolean}\n */\nMyCircularQueue.prototype.deQueue = function() {\n\n};\n\n/**\n * @return {number}\n */\nMyCircularQueue.prototype.Front = function() {\n\n};\n\n/**\n * @return {number}\n */\nMyCircularQueue.prototype.Rear = function() {\n\n};\n\n/**\n * @return {boolean}\n */\nMyCircularQueue.prototype.isEmpty = function() {\n\n};\n\n/**\n * @return {boolean}\n */\nMyCircularQueue.prototype.isFull = function() {\n\n};\n\n/**\n * Your MyCircularQueue object will be instantiated and called as such:\n * var obj = new MyCircularQueue(k)\n * var param_1 = obj.enQueue(value)\n * var param_2 = obj.deQueue()\n * var param_3 = obj.Front()\n * var param_4 = obj.Rear()\n * var param_5 = obj.isEmpty()\n * var param_6 = obj.isFull()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class MyCircularQueue\n\n=begin\n :type k: Integer\n=end\n def initialize(k)\n\n end\n\n\n=begin\n :type value: Integer\n :rtype: Boolean\n=end\n def en_queue(value)\n\n end\n\n\n=begin\n :rtype: Boolean\n=end\n def de_queue()\n\n end\n\n\n=begin\n :rtype: Integer\n=end\n def front()\n\n end\n\n\n=begin\n :rtype: Integer\n=end\n def rear()\n\n end\n\n\n=begin\n :rtype: Boolean\n=end\n def is_empty()\n\n end\n\n\n=begin\n :rtype: Boolean\n=end\n def is_full()\n\n end\n\n\nend\n\n# Your MyCircularQueue object will be instantiated and called as such:\n# obj = MyCircularQueue.new(k)\n# param_1 = obj.en_queue(value)\n# param_2 = obj.de_queue()\n# param_3 = obj.front()\n# param_4 = obj.rear()\n# param_5 = obj.is_empty()\n# param_6 = obj.is_full()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass MyCircularQueue {\n\n init(_ k: Int) {\n\n }\n \n func enQueue(_ value: Int) -> Bool {\n\n }\n \n func deQueue() -> Bool {\n\n }\n \n func Front() -> Int {\n\n }\n \n func Rear() -> Int {\n\n }\n \n func isEmpty() -> Bool {\n\n }\n \n func isFull() -> Bool {\n\n }\n}\n\n/**\n * Your MyCircularQueue object will be instantiated and called as such:\n * let obj = MyCircularQueue(k)\n * let ret_1: Bool = obj.enQueue(value)\n * let ret_2: Bool = obj.deQueue()\n * let ret_3: Int = obj.Front()\n * let ret_4: Int = obj.Rear()\n * let ret_5: Bool = obj.isEmpty()\n * let ret_6: Bool = obj.isFull()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type MyCircularQueue struct {\n\n}\n\n\nfunc Constructor(k int) MyCircularQueue {\n\n}\n\n\nfunc (this *MyCircularQueue) EnQueue(value int) bool {\n\n}\n\n\nfunc (this *MyCircularQueue) DeQueue() bool {\n\n}\n\n\nfunc (this *MyCircularQueue) Front() int {\n\n}\n\n\nfunc (this *MyCircularQueue) Rear() int {\n\n}\n\n\nfunc (this *MyCircularQueue) IsEmpty() bool {\n\n}\n\n\nfunc (this *MyCircularQueue) IsFull() bool {\n\n}\n\n\n/**\n * Your MyCircularQueue object will be instantiated and called as such:\n * obj := Constructor(k);\n * param_1 := obj.EnQueue(value);\n * param_2 := obj.DeQueue();\n * param_3 := obj.Front();\n * param_4 := obj.Rear();\n * param_5 := obj.IsEmpty();\n * param_6 := obj.IsFull();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class MyCircularQueue(_k: Int) {\n\n def enQueue(value: Int): Boolean = {\n\n }\n\n def deQueue(): Boolean = {\n\n }\n\n def Front(): Int = {\n\n }\n\n def Rear(): Int = {\n\n }\n\n def isEmpty(): Boolean = {\n\n }\n\n def isFull(): Boolean = {\n\n }\n\n}\n\n/**\n * Your MyCircularQueue object will be instantiated and called as such:\n * var obj = new MyCircularQueue(k)\n * var param_1 = obj.enQueue(value)\n * var param_2 = obj.deQueue()\n * var param_3 = obj.Front()\n * var param_4 = obj.Rear()\n * var param_5 = obj.isEmpty()\n * var param_6 = obj.isFull()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class MyCircularQueue(k: Int) {\n\n fun enQueue(value: Int): Boolean {\n\n }\n\n fun deQueue(): Boolean {\n\n }\n\n fun Front(): Int {\n\n }\n\n fun Rear(): Int {\n\n }\n\n fun isEmpty(): Boolean {\n\n }\n\n fun isFull(): Boolean {\n\n }\n\n}\n\n/**\n * Your MyCircularQueue object will be instantiated and called as such:\n * var obj = MyCircularQueue(k)\n * var param_1 = obj.enQueue(value)\n * var param_2 = obj.deQueue()\n * var param_3 = obj.Front()\n * var param_4 = obj.Rear()\n * var param_5 = obj.isEmpty()\n * var param_6 = obj.isFull()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct MyCircularQueue {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl MyCircularQueue {\n\n fn new(k: i32) -> Self {\n\n }\n \n fn en_queue(&self, value: i32) -> bool {\n\n }\n \n fn de_queue(&self) -> bool {\n\n }\n \n fn front(&self) -> i32 {\n\n }\n \n fn rear(&self) -> i32 {\n\n }\n \n fn is_empty(&self) -> bool {\n\n }\n \n fn is_full(&self) -> bool {\n\n }\n}\n\n/**\n * Your MyCircularQueue object will be instantiated and called as such:\n * let obj = MyCircularQueue::new(k);\n * let ret_1: bool = obj.en_queue(value);\n * let ret_2: bool = obj.de_queue();\n * let ret_3: i32 = obj.front();\n * let ret_4: i32 = obj.rear();\n * let ret_5: bool = obj.is_empty();\n * let ret_6: bool = obj.is_full();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class MyCircularQueue {\n /**\n * @param Integer $k\n */\n function __construct($k) {\n\n }\n\n /**\n * @param Integer $value\n * @return Boolean\n */\n function enQueue($value) {\n\n }\n\n /**\n * @return Boolean\n */\n function deQueue() {\n\n }\n\n /**\n * @return Integer\n */\n function Front() {\n\n }\n\n /**\n * @return Integer\n */\n function Rear() {\n\n }\n\n /**\n * @return Boolean\n */\n function isEmpty() {\n\n }\n\n /**\n * @return Boolean\n */\n function isFull() {\n\n }\n}\n\n/**\n * Your MyCircularQueue object will be instantiated and called as such:\n * $obj = MyCircularQueue($k);\n * $ret_1 = $obj->enQueue($value);\n * $ret_2 = $obj->deQueue();\n * $ret_3 = $obj->Front();\n * $ret_4 = $obj->Rear();\n * $ret_5 = $obj->isEmpty();\n * $ret_6 = $obj->isFull();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class MyCircularQueue {\n constructor(k: number) {\n\n }\n\n enQueue(value: number): boolean {\n\n }\n\n deQueue(): boolean {\n\n }\n\n Front(): number {\n\n }\n\n Rear(): number {\n\n }\n\n isEmpty(): boolean {\n\n }\n\n isFull(): boolean {\n\n }\n}\n\n/**\n * Your MyCircularQueue object will be instantiated and called as such:\n * var obj = new MyCircularQueue(k)\n * var param_1 = obj.enQueue(value)\n * var param_2 = obj.deQueue()\n * var param_3 = obj.Front()\n * var param_4 = obj.Rear()\n * var param_5 = obj.isEmpty()\n * var param_6 = obj.isFull()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define my-circular-queue%\n (class object%\n (super-new)\n\n ; k : exact-integer?\n (init-field\n k)\n \n ; en-queue : exact-integer? -> boolean?\n (define/public (en-queue value)\n\n )\n ; de-queue : -> boolean?\n (define/public (de-queue)\n\n )\n ; front : -> exact-integer?\n (define/public (front)\n\n )\n ; rear : -> exact-integer?\n (define/public (rear)\n\n )\n ; is-empty : -> boolean?\n (define/public (is-empty)\n\n )\n ; is-full : -> boolean?\n (define/public (is-full)\n\n )))\n\n;; Your my-circular-queue% object will be instantiated and called as such:\n;; (define obj (new my-circular-queue% [k k]))\n;; (define param_1 (send obj en-queue value))\n;; (define param_2 (send obj de-queue))\n;; (define param_3 (send obj front))\n;; (define param_4 (send obj rear))\n;; (define param_5 (send obj is-empty))\n;; (define param_6 (send obj is-full))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0622](https://leetcode-cn.com/problems/design-circular-queue)", "[\u8bbe\u8ba1\u5faa\u73af\u961f\u5217](/solution/0600-0699/0622.Design%20Circular%20Queue/README.md)", "`\u8bbe\u8ba1`,`\u961f\u5217`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0622](https://leetcode.com/problems/design-circular-queue)", "[Design Circular Queue](/solution/0600-0699/0622.Design%20Circular%20Queue/README_EN.md)", "`Design`,`Queue`", "Medium", ""]}, {"question_id": "0859", "frontend_question_id": "0641", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/design-circular-deque", "url_en": "https://leetcode.com/problems/design-circular-deque", "relative_path_cn": "/solution/0600-0699/0641.Design%20Circular%20Deque/README.md", "relative_path_en": "/solution/0600-0699/0641.Design%20Circular%20Deque/README_EN.md", "title_cn": "\u8bbe\u8ba1\u5faa\u73af\u53cc\u7aef\u961f\u5217", "title_en": "Design Circular Deque", "question_title_slug": "design-circular-deque", "content_en": "

Design your implementation of the circular double-ended queue (deque).

\r\n\r\n

Your implementation should support following operations:

\r\n\r\n
    \r\n\t
  • MyCircularDeque(k): Constructor, set the size of the deque to be k.
  • \r\n\t
  • insertFront(): Adds an item at the front of Deque. Return true if the operation is successful.
  • \r\n\t
  • insertLast(): Adds an item at the rear of Deque. Return true if the operation is successful.
  • \r\n\t
  • deleteFront(): Deletes an item from the front of Deque. Return true if the operation is successful.
  • \r\n\t
  • deleteLast(): Deletes an item from the rear of Deque. Return true if the operation is successful.
  • \r\n\t
  • getFront(): Gets the front item from the Deque. If the deque is empty, return -1.
  • \r\n\t
  • getRear(): Gets the last item from Deque. If the deque is empty, return -1.
  • \r\n\t
  • isEmpty(): Checks whether Deque is empty or not. 
  • \r\n\t
  • isFull(): Checks whether Deque is full or not.
  • \r\n
\r\n\r\n

 

\r\n\r\n

Example:

\r\n\r\n
\r\nMyCircularDeque circularDeque = new MycircularDeque(3); // set the size to be 3\r\ncircularDeque.insertLast(1);\t\t\t// return true\r\ncircularDeque.insertLast(2);\t\t\t// return true\r\ncircularDeque.insertFront(3);\t\t\t// return true\r\ncircularDeque.insertFront(4);\t\t\t// return false, the queue is full\r\ncircularDeque.getRear();  \t\t\t// return 2\r\ncircularDeque.isFull();\t\t\t\t// return true\r\ncircularDeque.deleteLast();\t\t\t// return true\r\ncircularDeque.insertFront(4);\t\t\t// return true\r\ncircularDeque.getFront();\t\t\t// return 4\r\n
\r\n\r\n

 

\r\n\r\n

Note:

\r\n\r\n
    \r\n\t
  • All values will be in the range of [0, 1000].
  • \r\n\t
  • The number of operations will be in the range of [1, 1000].
  • \r\n\t
  • Please do not use the built-in Deque library.
  • \r\n
\r\n", "content_cn": "

\u8bbe\u8ba1\u5b9e\u73b0\u53cc\u7aef\u961f\u5217\u3002
\n\u4f60\u7684\u5b9e\u73b0\u9700\u8981\u652f\u6301\u4ee5\u4e0b\u64cd\u4f5c\uff1a

\n\n
    \n\t
  • MyCircularDeque(k)\uff1a\u6784\u9020\u51fd\u6570,\u53cc\u7aef\u961f\u5217\u7684\u5927\u5c0f\u4e3ak\u3002
  • \n\t
  • insertFront()\uff1a\u5c06\u4e00\u4e2a\u5143\u7d20\u6dfb\u52a0\u5230\u53cc\u7aef\u961f\u5217\u5934\u90e8\u3002 \u5982\u679c\u64cd\u4f5c\u6210\u529f\u8fd4\u56de true\u3002
  • \n\t
  • insertLast()\uff1a\u5c06\u4e00\u4e2a\u5143\u7d20\u6dfb\u52a0\u5230\u53cc\u7aef\u961f\u5217\u5c3e\u90e8\u3002\u5982\u679c\u64cd\u4f5c\u6210\u529f\u8fd4\u56de true\u3002
  • \n\t
  • deleteFront()\uff1a\u4ece\u53cc\u7aef\u961f\u5217\u5934\u90e8\u5220\u9664\u4e00\u4e2a\u5143\u7d20\u3002 \u5982\u679c\u64cd\u4f5c\u6210\u529f\u8fd4\u56de true\u3002
  • \n\t
  • deleteLast()\uff1a\u4ece\u53cc\u7aef\u961f\u5217\u5c3e\u90e8\u5220\u9664\u4e00\u4e2a\u5143\u7d20\u3002\u5982\u679c\u64cd\u4f5c\u6210\u529f\u8fd4\u56de true\u3002
  • \n\t
  • getFront()\uff1a\u4ece\u53cc\u7aef\u961f\u5217\u5934\u90e8\u83b7\u5f97\u4e00\u4e2a\u5143\u7d20\u3002\u5982\u679c\u53cc\u7aef\u961f\u5217\u4e3a\u7a7a\uff0c\u8fd4\u56de -1\u3002
  • \n\t
  • getRear()\uff1a\u83b7\u5f97\u53cc\u7aef\u961f\u5217\u7684\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u3002 \u5982\u679c\u53cc\u7aef\u961f\u5217\u4e3a\u7a7a\uff0c\u8fd4\u56de -1\u3002
  • \n\t
  • isEmpty()\uff1a\u68c0\u67e5\u53cc\u7aef\u961f\u5217\u662f\u5426\u4e3a\u7a7a\u3002
  • \n\t
  • isFull()\uff1a\u68c0\u67e5\u53cc\u7aef\u961f\u5217\u662f\u5426\u6ee1\u4e86\u3002
  • \n
\n\n

\u793a\u4f8b\uff1a

\n\n
MyCircularDeque circularDeque = new MycircularDeque(3); // \u8bbe\u7f6e\u5bb9\u91cf\u5927\u5c0f\u4e3a3\ncircularDeque.insertLast(1);\t\t\t        // \u8fd4\u56de true\ncircularDeque.insertLast(2);\t\t\t        // \u8fd4\u56de true\ncircularDeque.insertFront(3);\t\t\t        // \u8fd4\u56de true\ncircularDeque.insertFront(4);\t\t\t        // \u5df2\u7ecf\u6ee1\u4e86\uff0c\u8fd4\u56de false\ncircularDeque.getRear();  \t\t\t\t// \u8fd4\u56de 2\ncircularDeque.isFull();\t\t\t\t        // \u8fd4\u56de true\ncircularDeque.deleteLast();\t\t\t        // \u8fd4\u56de true\ncircularDeque.insertFront(4);\t\t\t        // \u8fd4\u56de true\ncircularDeque.getFront();\t\t\t\t// \u8fd4\u56de 4\n 
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u6240\u6709\u503c\u7684\u8303\u56f4\u4e3a [1, 1000]
  • \n\t
  • \u64cd\u4f5c\u6b21\u6570\u7684\u8303\u56f4\u4e3a [1, 1000]
  • \n\t
  • \u8bf7\u4e0d\u8981\u4f7f\u7528\u5185\u7f6e\u7684\u53cc\u7aef\u961f\u5217\u5e93\u3002
  • \n
\n", "tags_en": ["Design", "Queue"], "tags_cn": ["\u8bbe\u8ba1", "\u961f\u5217"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class MyCircularDeque {\npublic:\n /** Initialize your data structure here. Set the size of the deque to be k. */\n MyCircularDeque(int k) {\n\n }\n \n /** Adds an item at the front of Deque. Return true if the operation is successful. */\n bool insertFront(int value) {\n\n }\n \n /** Adds an item at the rear of Deque. Return true if the operation is successful. */\n bool insertLast(int value) {\n\n }\n \n /** Deletes an item from the front of Deque. Return true if the operation is successful. */\n bool deleteFront() {\n\n }\n \n /** Deletes an item from the rear of Deque. Return true if the operation is successful. */\n bool deleteLast() {\n\n }\n \n /** Get the front item from the deque. */\n int getFront() {\n\n }\n \n /** Get the last item from the deque. */\n int getRear() {\n\n }\n \n /** Checks whether the circular deque is empty or not. */\n bool isEmpty() {\n\n }\n \n /** Checks whether the circular deque is full or not. */\n bool isFull() {\n\n }\n};\n\n/**\n * Your MyCircularDeque object will be instantiated and called as such:\n * MyCircularDeque* obj = new MyCircularDeque(k);\n * bool param_1 = obj->insertFront(value);\n * bool param_2 = obj->insertLast(value);\n * bool param_3 = obj->deleteFront();\n * bool param_4 = obj->deleteLast();\n * int param_5 = obj->getFront();\n * int param_6 = obj->getRear();\n * bool param_7 = obj->isEmpty();\n * bool param_8 = obj->isFull();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class MyCircularDeque {\n\n /** Initialize your data structure here. Set the size of the deque to be k. */\n public MyCircularDeque(int k) {\n\n }\n \n /** Adds an item at the front of Deque. Return true if the operation is successful. */\n public boolean insertFront(int value) {\n\n }\n \n /** Adds an item at the rear of Deque. Return true if the operation is successful. */\n public boolean insertLast(int value) {\n\n }\n \n /** Deletes an item from the front of Deque. Return true if the operation is successful. */\n public boolean deleteFront() {\n\n }\n \n /** Deletes an item from the rear of Deque. Return true if the operation is successful. */\n public boolean deleteLast() {\n\n }\n \n /** Get the front item from the deque. */\n public int getFront() {\n\n }\n \n /** Get the last item from the deque. */\n public int getRear() {\n\n }\n \n /** Checks whether the circular deque is empty or not. */\n public boolean isEmpty() {\n\n }\n \n /** Checks whether the circular deque is full or not. */\n public boolean isFull() {\n\n }\n}\n\n/**\n * Your MyCircularDeque object will be instantiated and called as such:\n * MyCircularDeque obj = new MyCircularDeque(k);\n * boolean param_1 = obj.insertFront(value);\n * boolean param_2 = obj.insertLast(value);\n * boolean param_3 = obj.deleteFront();\n * boolean param_4 = obj.deleteLast();\n * int param_5 = obj.getFront();\n * int param_6 = obj.getRear();\n * boolean param_7 = obj.isEmpty();\n * boolean param_8 = obj.isFull();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class MyCircularDeque(object):\n\n def __init__(self, k):\n \"\"\"\n Initialize your data structure here. Set the size of the deque to be k.\n :type k: int\n \"\"\"\n \n\n def insertFront(self, value):\n \"\"\"\n Adds an item at the front of Deque. Return true if the operation is successful.\n :type value: int\n :rtype: bool\n \"\"\"\n \n\n def insertLast(self, value):\n \"\"\"\n Adds an item at the rear of Deque. Return true if the operation is successful.\n :type value: int\n :rtype: bool\n \"\"\"\n \n\n def deleteFront(self):\n \"\"\"\n Deletes an item from the front of Deque. Return true if the operation is successful.\n :rtype: bool\n \"\"\"\n \n\n def deleteLast(self):\n \"\"\"\n Deletes an item from the rear of Deque. Return true if the operation is successful.\n :rtype: bool\n \"\"\"\n \n\n def getFront(self):\n \"\"\"\n Get the front item from the deque.\n :rtype: int\n \"\"\"\n \n\n def getRear(self):\n \"\"\"\n Get the last item from the deque.\n :rtype: int\n \"\"\"\n \n\n def isEmpty(self):\n \"\"\"\n Checks whether the circular deque is empty or not.\n :rtype: bool\n \"\"\"\n \n\n def isFull(self):\n \"\"\"\n Checks whether the circular deque is full or not.\n :rtype: bool\n \"\"\"\n \n\n\n# Your MyCircularDeque object will be instantiated and called as such:\n# obj = MyCircularDeque(k)\n# param_1 = obj.insertFront(value)\n# param_2 = obj.insertLast(value)\n# param_3 = obj.deleteFront()\n# param_4 = obj.deleteLast()\n# param_5 = obj.getFront()\n# param_6 = obj.getRear()\n# param_7 = obj.isEmpty()\n# param_8 = obj.isFull()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class MyCircularDeque:\n\n def __init__(self, k: int):\n \"\"\"\n Initialize your data structure here. Set the size of the deque to be k.\n \"\"\"\n \n\n def insertFront(self, value: int) -> bool:\n \"\"\"\n Adds an item at the front of Deque. Return true if the operation is successful.\n \"\"\"\n \n\n def insertLast(self, value: int) -> bool:\n \"\"\"\n Adds an item at the rear of Deque. Return true if the operation is successful.\n \"\"\"\n \n\n def deleteFront(self) -> bool:\n \"\"\"\n Deletes an item from the front of Deque. Return true if the operation is successful.\n \"\"\"\n \n\n def deleteLast(self) -> bool:\n \"\"\"\n Deletes an item from the rear of Deque. Return true if the operation is successful.\n \"\"\"\n \n\n def getFront(self) -> int:\n \"\"\"\n Get the front item from the deque.\n \"\"\"\n \n\n def getRear(self) -> int:\n \"\"\"\n Get the last item from the deque.\n \"\"\"\n \n\n def isEmpty(self) -> bool:\n \"\"\"\n Checks whether the circular deque is empty or not.\n \"\"\"\n \n\n def isFull(self) -> bool:\n \"\"\"\n Checks whether the circular deque is full or not.\n \"\"\"\n \n\n\n# Your MyCircularDeque object will be instantiated and called as such:\n# obj = MyCircularDeque(k)\n# param_1 = obj.insertFront(value)\n# param_2 = obj.insertLast(value)\n# param_3 = obj.deleteFront()\n# param_4 = obj.deleteLast()\n# param_5 = obj.getFront()\n# param_6 = obj.getRear()\n# param_7 = obj.isEmpty()\n# param_8 = obj.isFull()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} MyCircularDeque;\n\n/** Initialize your data structure here. Set the size of the deque to be k. */\n\nMyCircularDeque* myCircularDequeCreate(int k) {\n \n}\n\n/** Adds an item at the front of Deque. Return true if the operation is successful. */\nbool myCircularDequeInsertFront(MyCircularDeque* obj, int value) {\n \n}\n\n/** Adds an item at the rear of Deque. Return true if the operation is successful. */\nbool myCircularDequeInsertLast(MyCircularDeque* obj, int value) {\n \n}\n\n/** Deletes an item from the front of Deque. Return true if the operation is successful. */\nbool myCircularDequeDeleteFront(MyCircularDeque* obj) {\n \n}\n\n/** Deletes an item from the rear of Deque. Return true if the operation is successful. */\nbool myCircularDequeDeleteLast(MyCircularDeque* obj) {\n \n}\n\n/** Get the front item from the deque. */\nint myCircularDequeGetFront(MyCircularDeque* obj) {\n \n}\n\n/** Get the last item from the deque. */\nint myCircularDequeGetRear(MyCircularDeque* obj) {\n \n}\n\n/** Checks whether the circular deque is empty or not. */\nbool myCircularDequeIsEmpty(MyCircularDeque* obj) {\n \n}\n\n/** Checks whether the circular deque is full or not. */\nbool myCircularDequeIsFull(MyCircularDeque* obj) {\n \n}\n\nvoid myCircularDequeFree(MyCircularDeque* obj) {\n \n}\n\n/**\n * Your MyCircularDeque struct will be instantiated and called as such:\n * MyCircularDeque* obj = myCircularDequeCreate(k);\n * bool param_1 = myCircularDequeInsertFront(obj, value);\n \n * bool param_2 = myCircularDequeInsertLast(obj, value);\n \n * bool param_3 = myCircularDequeDeleteFront(obj);\n \n * bool param_4 = myCircularDequeDeleteLast(obj);\n \n * int param_5 = myCircularDequeGetFront(obj);\n \n * int param_6 = myCircularDequeGetRear(obj);\n \n * bool param_7 = myCircularDequeIsEmpty(obj);\n \n * bool param_8 = myCircularDequeIsFull(obj);\n \n * myCircularDequeFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class MyCircularDeque {\n\n /** Initialize your data structure here. Set the size of the deque to be k. */\n public MyCircularDeque(int k) {\n\n }\n \n /** Adds an item at the front of Deque. Return true if the operation is successful. */\n public bool InsertFront(int value) {\n\n }\n \n /** Adds an item at the rear of Deque. Return true if the operation is successful. */\n public bool InsertLast(int value) {\n\n }\n \n /** Deletes an item from the front of Deque. Return true if the operation is successful. */\n public bool DeleteFront() {\n\n }\n \n /** Deletes an item from the rear of Deque. Return true if the operation is successful. */\n public bool DeleteLast() {\n\n }\n \n /** Get the front item from the deque. */\n public int GetFront() {\n\n }\n \n /** Get the last item from the deque. */\n public int GetRear() {\n\n }\n \n /** Checks whether the circular deque is empty or not. */\n public bool IsEmpty() {\n\n }\n \n /** Checks whether the circular deque is full or not. */\n public bool IsFull() {\n\n }\n}\n\n/**\n * Your MyCircularDeque object will be instantiated and called as such:\n * MyCircularDeque obj = new MyCircularDeque(k);\n * bool param_1 = obj.InsertFront(value);\n * bool param_2 = obj.InsertLast(value);\n * bool param_3 = obj.DeleteFront();\n * bool param_4 = obj.DeleteLast();\n * int param_5 = obj.GetFront();\n * int param_6 = obj.GetRear();\n * bool param_7 = obj.IsEmpty();\n * bool param_8 = obj.IsFull();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Initialize your data structure here. Set the size of the deque to be k.\n * @param {number} k\n */\nvar MyCircularDeque = function(k) {\n\n};\n\n/**\n * Adds an item at the front of Deque. Return true if the operation is successful. \n * @param {number} value\n * @return {boolean}\n */\nMyCircularDeque.prototype.insertFront = function(value) {\n\n};\n\n/**\n * Adds an item at the rear of Deque. Return true if the operation is successful. \n * @param {number} value\n * @return {boolean}\n */\nMyCircularDeque.prototype.insertLast = function(value) {\n\n};\n\n/**\n * Deletes an item from the front of Deque. Return true if the operation is successful.\n * @return {boolean}\n */\nMyCircularDeque.prototype.deleteFront = function() {\n\n};\n\n/**\n * Deletes an item from the rear of Deque. Return true if the operation is successful.\n * @return {boolean}\n */\nMyCircularDeque.prototype.deleteLast = function() {\n\n};\n\n/**\n * Get the front item from the deque.\n * @return {number}\n */\nMyCircularDeque.prototype.getFront = function() {\n\n};\n\n/**\n * Get the last item from the deque.\n * @return {number}\n */\nMyCircularDeque.prototype.getRear = function() {\n\n};\n\n/**\n * Checks whether the circular deque is empty or not.\n * @return {boolean}\n */\nMyCircularDeque.prototype.isEmpty = function() {\n\n};\n\n/**\n * Checks whether the circular deque is full or not.\n * @return {boolean}\n */\nMyCircularDeque.prototype.isFull = function() {\n\n};\n\n/**\n * Your MyCircularDeque object will be instantiated and called as such:\n * var obj = new MyCircularDeque(k)\n * var param_1 = obj.insertFront(value)\n * var param_2 = obj.insertLast(value)\n * var param_3 = obj.deleteFront()\n * var param_4 = obj.deleteLast()\n * var param_5 = obj.getFront()\n * var param_6 = obj.getRear()\n * var param_7 = obj.isEmpty()\n * var param_8 = obj.isFull()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class MyCircularDeque\n\n=begin\n Initialize your data structure here. Set the size of the deque to be k.\n :type k: Integer\n=end\n def initialize(k)\n\n end\n\n\n=begin\n Adds an item at the front of Deque. Return true if the operation is successful.\n :type value: Integer\n :rtype: Boolean\n=end\n def insert_front(value)\n\n end\n\n\n=begin\n Adds an item at the rear of Deque. Return true if the operation is successful.\n :type value: Integer\n :rtype: Boolean\n=end\n def insert_last(value)\n\n end\n\n\n=begin\n Deletes an item from the front of Deque. Return true if the operation is successful.\n :rtype: Boolean\n=end\n def delete_front()\n\n end\n\n\n=begin\n Deletes an item from the rear of Deque. Return true if the operation is successful.\n :rtype: Boolean\n=end\n def delete_last()\n\n end\n\n\n=begin\n Get the front item from the deque.\n :rtype: Integer\n=end\n def get_front()\n\n end\n\n\n=begin\n Get the last item from the deque.\n :rtype: Integer\n=end\n def get_rear()\n\n end\n\n\n=begin\n Checks whether the circular deque is empty or not.\n :rtype: Boolean\n=end\n def is_empty()\n\n end\n\n\n=begin\n Checks whether the circular deque is full or not.\n :rtype: Boolean\n=end\n def is_full()\n\n end\n\n\nend\n\n# Your MyCircularDeque object will be instantiated and called as such:\n# obj = MyCircularDeque.new(k)\n# param_1 = obj.insert_front(value)\n# param_2 = obj.insert_last(value)\n# param_3 = obj.delete_front()\n# param_4 = obj.delete_last()\n# param_5 = obj.get_front()\n# param_6 = obj.get_rear()\n# param_7 = obj.is_empty()\n# param_8 = obj.is_full()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass MyCircularDeque {\n\n /** Initialize your data structure here. Set the size of the deque to be k. */\n init(_ k: Int) {\n \n }\n \n /** Adds an item at the front of Deque. Return true if the operation is successful. */\n func insertFront(_ value: Int) -> Bool {\n \n }\n \n /** Adds an item at the rear of Deque. Return true if the operation is successful. */\n func insertLast(_ value: Int) -> Bool {\n \n }\n \n /** Deletes an item from the front of Deque. Return true if the operation is successful. */\n func deleteFront() -> Bool {\n \n }\n \n /** Deletes an item from the rear of Deque. Return true if the operation is successful. */\n func deleteLast() -> Bool {\n \n }\n \n /** Get the front item from the deque. */\n func getFront() -> Int {\n \n }\n \n /** Get the last item from the deque. */\n func getRear() -> Int {\n \n }\n \n /** Checks whether the circular deque is empty or not. */\n func isEmpty() -> Bool {\n \n }\n \n /** Checks whether the circular deque is full or not. */\n func isFull() -> Bool {\n \n }\n}\n\n/**\n * Your MyCircularDeque object will be instantiated and called as such:\n * let obj = MyCircularDeque(k)\n * let ret_1: Bool = obj.insertFront(value)\n * let ret_2: Bool = obj.insertLast(value)\n * let ret_3: Bool = obj.deleteFront()\n * let ret_4: Bool = obj.deleteLast()\n * let ret_5: Int = obj.getFront()\n * let ret_6: Int = obj.getRear()\n * let ret_7: Bool = obj.isEmpty()\n * let ret_8: Bool = obj.isFull()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type MyCircularDeque struct {\n\n}\n\n\n/** Initialize your data structure here. Set the size of the deque to be k. */\nfunc Constructor(k int) MyCircularDeque {\n\n}\n\n\n/** Adds an item at the front of Deque. Return true if the operation is successful. */\nfunc (this *MyCircularDeque) InsertFront(value int) bool {\n\n}\n\n\n/** Adds an item at the rear of Deque. Return true if the operation is successful. */\nfunc (this *MyCircularDeque) InsertLast(value int) bool {\n\n}\n\n\n/** Deletes an item from the front of Deque. Return true if the operation is successful. */\nfunc (this *MyCircularDeque) DeleteFront() bool {\n\n}\n\n\n/** Deletes an item from the rear of Deque. Return true if the operation is successful. */\nfunc (this *MyCircularDeque) DeleteLast() bool {\n\n}\n\n\n/** Get the front item from the deque. */\nfunc (this *MyCircularDeque) GetFront() int {\n\n}\n\n\n/** Get the last item from the deque. */\nfunc (this *MyCircularDeque) GetRear() int {\n\n}\n\n\n/** Checks whether the circular deque is empty or not. */\nfunc (this *MyCircularDeque) IsEmpty() bool {\n\n}\n\n\n/** Checks whether the circular deque is full or not. */\nfunc (this *MyCircularDeque) IsFull() bool {\n\n}\n\n\n/**\n * Your MyCircularDeque object will be instantiated and called as such:\n * obj := Constructor(k);\n * param_1 := obj.InsertFront(value);\n * param_2 := obj.InsertLast(value);\n * param_3 := obj.DeleteFront();\n * param_4 := obj.DeleteLast();\n * param_5 := obj.GetFront();\n * param_6 := obj.GetRear();\n * param_7 := obj.IsEmpty();\n * param_8 := obj.IsFull();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class MyCircularDeque(_k: Int) {\n\n /** Initialize your data structure here. Set the size of the deque to be k. */\n\n\n /** Adds an item at the front of Deque. Return true if the operation is successful. */\n def insertFront(value: Int): Boolean = {\n\n }\n\n /** Adds an item at the rear of Deque. Return true if the operation is successful. */\n def insertLast(value: Int): Boolean = {\n\n }\n\n /** Deletes an item from the front of Deque. Return true if the operation is successful. */\n def deleteFront(): Boolean = {\n\n }\n\n /** Deletes an item from the rear of Deque. Return true if the operation is successful. */\n def deleteLast(): Boolean = {\n\n }\n\n /** Get the front item from the deque. */\n def getFront(): Int = {\n\n }\n\n /** Get the last item from the deque. */\n def getRear(): Int = {\n\n }\n\n /** Checks whether the circular deque is empty or not. */\n def isEmpty(): Boolean = {\n\n }\n\n /** Checks whether the circular deque is full or not. */\n def isFull(): Boolean = {\n\n }\n\n}\n\n/**\n * Your MyCircularDeque object will be instantiated and called as such:\n * var obj = new MyCircularDeque(k)\n * var param_1 = obj.insertFront(value)\n * var param_2 = obj.insertLast(value)\n * var param_3 = obj.deleteFront()\n * var param_4 = obj.deleteLast()\n * var param_5 = obj.getFront()\n * var param_6 = obj.getRear()\n * var param_7 = obj.isEmpty()\n * var param_8 = obj.isFull()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class MyCircularDeque(k: Int) {\n\n /** Initialize your data structure here. Set the size of the deque to be k. */\n\n\n /** Adds an item at the front of Deque. Return true if the operation is successful. */\n fun insertFront(value: Int): Boolean {\n\n }\n\n /** Adds an item at the rear of Deque. Return true if the operation is successful. */\n fun insertLast(value: Int): Boolean {\n\n }\n\n /** Deletes an item from the front of Deque. Return true if the operation is successful. */\n fun deleteFront(): Boolean {\n\n }\n\n /** Deletes an item from the rear of Deque. Return true if the operation is successful. */\n fun deleteLast(): Boolean {\n\n }\n\n /** Get the front item from the deque. */\n fun getFront(): Int {\n\n }\n\n /** Get the last item from the deque. */\n fun getRear(): Int {\n\n }\n\n /** Checks whether the circular deque is empty or not. */\n fun isEmpty(): Boolean {\n\n }\n\n /** Checks whether the circular deque is full or not. */\n fun isFull(): Boolean {\n\n }\n\n}\n\n/**\n * Your MyCircularDeque object will be instantiated and called as such:\n * var obj = MyCircularDeque(k)\n * var param_1 = obj.insertFront(value)\n * var param_2 = obj.insertLast(value)\n * var param_3 = obj.deleteFront()\n * var param_4 = obj.deleteLast()\n * var param_5 = obj.getFront()\n * var param_6 = obj.getRear()\n * var param_7 = obj.isEmpty()\n * var param_8 = obj.isFull()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct MyCircularDeque {\n\n}\n\n\n/** \n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl MyCircularDeque {\n\n /** Initialize your data structure here. Set the size of the deque to be k. */\n fn new(k: i32) -> Self {\n \n }\n \n /** Adds an item at the front of Deque. Return true if the operation is successful. */\n fn insert_front(&self, value: i32) -> bool {\n \n }\n \n /** Adds an item at the rear of Deque. Return true if the operation is successful. */\n fn insert_last(&self, value: i32) -> bool {\n \n }\n \n /** Deletes an item from the front of Deque. Return true if the operation is successful. */\n fn delete_front(&self) -> bool {\n \n }\n \n /** Deletes an item from the rear of Deque. Return true if the operation is successful. */\n fn delete_last(&self) -> bool {\n \n }\n \n /** Get the front item from the deque. */\n fn get_front(&self) -> i32 {\n \n }\n \n /** Get the last item from the deque. */\n fn get_rear(&self) -> i32 {\n \n }\n \n /** Checks whether the circular deque is empty or not. */\n fn is_empty(&self) -> bool {\n \n }\n \n /** Checks whether the circular deque is full or not. */\n fn is_full(&self) -> bool {\n \n }\n}\n\n/**\n * Your MyCircularDeque object will be instantiated and called as such:\n * let obj = MyCircularDeque::new(k);\n * let ret_1: bool = obj.insert_front(value);\n * let ret_2: bool = obj.insert_last(value);\n * let ret_3: bool = obj.delete_front();\n * let ret_4: bool = obj.delete_last();\n * let ret_5: i32 = obj.get_front();\n * let ret_6: i32 = obj.get_rear();\n * let ret_7: bool = obj.is_empty();\n * let ret_8: bool = obj.is_full();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class MyCircularDeque {\n /**\n * Initialize your data structure here. Set the size of the deque to be k.\n * @param Integer $k\n */\n function __construct($k) {\n \n }\n \n /**\n * Adds an item at the front of Deque. Return true if the operation is successful.\n * @param Integer $value\n * @return Boolean\n */\n function insertFront($value) {\n \n }\n \n /**\n * Adds an item at the rear of Deque. Return true if the operation is successful.\n * @param Integer $value\n * @return Boolean\n */\n function insertLast($value) {\n \n }\n \n /**\n * Deletes an item from the front of Deque. Return true if the operation is successful.\n * @return Boolean\n */\n function deleteFront() {\n \n }\n \n /**\n * Deletes an item from the rear of Deque. Return true if the operation is successful.\n * @return Boolean\n */\n function deleteLast() {\n \n }\n \n /**\n * Get the front item from the deque.\n * @return Integer\n */\n function getFront() {\n \n }\n \n /**\n * Get the last item from the deque.\n * @return Integer\n */\n function getRear() {\n \n }\n \n /**\n * Checks whether the circular deque is empty or not.\n * @return Boolean\n */\n function isEmpty() {\n \n }\n \n /**\n * Checks whether the circular deque is full or not.\n * @return Boolean\n */\n function isFull() {\n \n }\n}\n\n/**\n * Your MyCircularDeque object will be instantiated and called as such:\n * $obj = MyCircularDeque($k);\n * $ret_1 = $obj->insertFront($value);\n * $ret_2 = $obj->insertLast($value);\n * $ret_3 = $obj->deleteFront();\n * $ret_4 = $obj->deleteLast();\n * $ret_5 = $obj->getFront();\n * $ret_6 = $obj->getRear();\n * $ret_7 = $obj->isEmpty();\n * $ret_8 = $obj->isFull();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class MyCircularDeque {\n constructor(k: number) {\n\n }\n\n insertFront(value: number): boolean {\n\n }\n\n insertLast(value: number): boolean {\n\n }\n\n deleteFront(): boolean {\n\n }\n\n deleteLast(): boolean {\n\n }\n\n getFront(): number {\n\n }\n\n getRear(): number {\n\n }\n\n isEmpty(): boolean {\n\n }\n\n isFull(): boolean {\n\n }\n}\n\n/**\n * Your MyCircularDeque object will be instantiated and called as such:\n * var obj = new MyCircularDeque(k)\n * var param_1 = obj.insertFront(value)\n * var param_2 = obj.insertLast(value)\n * var param_3 = obj.deleteFront()\n * var param_4 = obj.deleteLast()\n * var param_5 = obj.getFront()\n * var param_6 = obj.getRear()\n * var param_7 = obj.isEmpty()\n * var param_8 = obj.isFull()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define my-circular-deque%\n (class object%\n (super-new)\n\n ; k : exact-integer?\n (init-field\n k)\n \n ; insert-front : exact-integer? -> boolean?\n (define/public (insert-front value)\n\n )\n ; insert-last : exact-integer? -> boolean?\n (define/public (insert-last value)\n\n )\n ; delete-front : -> boolean?\n (define/public (delete-front)\n\n )\n ; delete-last : -> boolean?\n (define/public (delete-last)\n\n )\n ; get-front : -> exact-integer?\n (define/public (get-front)\n\n )\n ; get-rear : -> exact-integer?\n (define/public (get-rear)\n\n )\n ; is-empty : -> boolean?\n (define/public (is-empty)\n\n )\n ; is-full : -> boolean?\n (define/public (is-full)\n\n )))\n\n;; Your my-circular-deque% object will be instantiated and called as such:\n;; (define obj (new my-circular-deque% [k k]))\n;; (define param_1 (send obj insert-front value))\n;; (define param_2 (send obj insert-last value))\n;; (define param_3 (send obj delete-front))\n;; (define param_4 (send obj delete-last))\n;; (define param_5 (send obj get-front))\n;; (define param_6 (send obj get-rear))\n;; (define param_7 (send obj is-empty))\n;; (define param_8 (send obj is-full))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0641](https://leetcode-cn.com/problems/design-circular-deque)", "[\u8bbe\u8ba1\u5faa\u73af\u53cc\u7aef\u961f\u5217](/solution/0600-0699/0641.Design%20Circular%20Deque/README.md)", "`\u8bbe\u8ba1`,`\u961f\u5217`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0641](https://leetcode.com/problems/design-circular-deque)", "[Design Circular Deque](/solution/0600-0699/0641.Design%20Circular%20Deque/README_EN.md)", "`Design`,`Queue`", "Medium", ""]}, {"question_id": "0858", "frontend_question_id": "0831", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/masking-personal-information", "url_en": "https://leetcode.com/problems/masking-personal-information", "relative_path_cn": "/solution/0800-0899/0831.Masking%20Personal%20Information/README.md", "relative_path_en": "/solution/0800-0899/0831.Masking%20Personal%20Information/README_EN.md", "title_cn": "\u9690\u85cf\u4e2a\u4eba\u4fe1\u606f", "title_en": "Masking Personal Information", "question_title_slug": "masking-personal-information", "content_en": "

We are given a personal information string s, which may represent either an email address or a phone number.

\n\n

We would like to mask this personal information according to the following rules:

\n\n


\n1. Email address:

\n\n

We define a name to be a string of length ≥ 2 consisting of only lowercase letters a-z or uppercase letters A-Z.

\n\n

An email address starts with a name, followed by the symbol '@', followed by a name, followed by the dot '.' and followed by a name. 

\n\n

All email addresses are guaranteed to be valid and in the format of "name1@name2.name3".

\n\n

To mask an email, all names must be converted to lowercase and all letters between the first and last letter of the first name must be replaced by 5 asterisks '*'.

\n\n


\n2. Phone number:

\n\n

A phone number is a string consisting of only the digits 0-9 or the characters from the set {'+', '-', '(', ')', ' '}. You may assume a phone number contains 10 to 13 digits.

\n\n

The last 10 digits make up the local number, while the digits before those make up the country code. Note that the country code is optional. We want to expose only the last 4 digits and mask all other digits.

\n\n

The local number should be formatted and masked as "***-***-1111", where 1 represents the exposed digits.

\n\n

To mask a phone number with country code like "+111 111 111 1111", we write it in the form "+***-***-***-1111".  The '+' sign and the first '-' sign before the local number should only exist if there is a country code.  For example, a 12 digit phone number mask should start with "+**-".

\n\n

Note that extraneous characters like "(", ")", " ", as well as extra dashes or plus signs not part of the above formatting scheme should be removed.

\n\n

 

\n\n

Return the correct "mask" of the information provided.

\n\n

 

\n\n

Example 1:

\n\n
\nInput: s = "LeetCode@LeetCode.com"\nOutput: "l*****e@leetcode.com"\nExplanation: All names are converted to lowercase, and the letters between the\n             first and last letter of the first name is replaced by 5 asterisks.\n             Therefore, "leetcode" -> "l*****e".\n
\n\n

Example 2:

\n\n
\nInput: s = "AB@qq.com"\nOutput: "a*****b@qq.com"\nExplanation: There must be 5 asterisks between the first and last letter \n             of the first name "ab". Therefore, "ab" -> "a*****b".\n
\n\n

Example 3:

\n\n
\nInput: s = "1(234)567-890"\nOutput: "***-***-7890"\nExplanation: 10 digits in the phone number, which means all digits make up the local number.\n
\n\n

Example 4:

\n\n
\nInput: s = "86-(10)12345678"\nOutput: "+**-***-***-5678"\nExplanation: 12 digits, 2 digits for country code and 10 digits for local number. \n
\n\n

Notes:

\n\n
    \n\t
  1. s.length <= 40.
  2. \n\t
  3. Emails have length at least 8.
  4. \n\t
  5. Phone numbers have length at least 10.
  6. \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u6761\u4e2a\u4eba\u4fe1\u606f\u5b57\u7b26\u4e32 S\uff0c\u5b83\u53ef\u80fd\u662f\u4e00\u4e2a \u90ae\u7bb1\u5730\u5740 \uff0c\u4e5f\u53ef\u80fd\u662f\u4e00\u4e32 \u7535\u8bdd\u53f7\u7801 \u3002

\n\n

\u6211\u4eec\u5c06\u9690\u85cf\u5b83\u7684\u9690\u79c1\u4fe1\u606f\uff0c\u901a\u8fc7\u5982\u4e0b\u89c4\u5219:

\n\n

 

\n\n

1. \u7535\u5b50\u90ae\u7bb1

\n\n

\u5b9a\u4e49\u540d\u79f0 name \u662f\u957f\u5ea6\u5927\u4e8e\u7b49\u4e8e 2 \uff08length ≥ 2\uff09\uff0c\u5e76\u4e14\u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd a-z \u548c\u5927\u5199\u5b57\u6bcd A-Z \u7684\u5b57\u7b26\u4e32\u3002

\n\n

\u7535\u5b50\u90ae\u7bb1\u5730\u5740\u7531\u540d\u79f0 name \u5f00\u5934\uff0c\u7d27\u63a5\u7740\u662f\u7b26\u53f7 '@'\uff0c\u540e\u9762\u63a5\u7740\u4e00\u4e2a\u540d\u79f0 name\uff0c\u518d\u63a5\u7740\u4e00\u4e2a\u70b9\u53f7 '.'\uff0c\u7136\u540e\u662f\u4e00\u4e2a\u540d\u79f0 name\u3002

\n\n

\u7535\u5b50\u90ae\u7bb1\u5730\u5740\u786e\u5b9a\u4e3a\u6709\u6548\u7684\uff0c\u5e76\u4e14\u683c\u5f0f\u662f "name1@name2.name3"\u3002

\n\n

\u4e3a\u4e86\u9690\u85cf\u7535\u5b50\u90ae\u7bb1\uff0c\u6240\u6709\u7684\u540d\u79f0 name \u5fc5\u987b\u88ab\u8f6c\u6362\u6210\u5c0f\u5199\u7684\uff0c\u5e76\u4e14\u7b2c\u4e00\u4e2a\u540d\u79f0 name \u7684\u7b2c\u4e00\u4e2a\u5b57\u6bcd\u548c\u6700\u540e\u4e00\u4e2a\u5b57\u6bcd\u7684\u4e2d\u95f4\u7684\u6240\u6709\u5b57\u6bcd\u7531 5 \u4e2a '*' \u4ee3\u66ff\u3002

\n\n

 

\n\n

2. \u7535\u8bdd\u53f7\u7801

\n\n

\u7535\u8bdd\u53f7\u7801\u662f\u4e00\u4e32\u5305\u62ec\u6570\u5b57 0-9\uff0c\u4ee5\u53ca {'+', '-', '(', ')', ' '} \u8fd9\u51e0\u4e2a\u5b57\u7b26\u7684\u5b57\u7b26\u4e32\u3002\u4f60\u53ef\u4ee5\u5047\u8bbe\u7535\u8bdd\u53f7\u7801\u5305\u542b 10 \u5230 13 \u4e2a\u6570\u5b57\u3002

\n\n

\u7535\u8bdd\u53f7\u7801\u7684\u6700\u540e 10 \u4e2a\u6570\u5b57\u7ec4\u6210\u672c\u5730\u53f7\u7801\uff0c\u5728\u8fd9\u4e4b\u524d\u7684\u6570\u5b57\u7ec4\u6210\u56fd\u9645\u53f7\u7801\u3002\u6ce8\u610f\uff0c\u56fd\u9645\u53f7\u7801\u662f\u53ef\u9009\u7684\u3002\u6211\u4eec\u53ea\u66b4\u9732\u6700\u540e 4 \u4e2a\u6570\u5b57\u5e76\u9690\u85cf\u6240\u6709\u5176\u4ed6\u6570\u5b57\u3002

\n\n

\u672c\u5730\u53f7\u7801\u662f\u6709\u683c\u5f0f\u7684\uff0c\u5e76\u4e14\u5982 "***-***-1111" \u8fd9\u6837\u663e\u793a\uff0c\u8fd9\u91cc\u7684 1 \u8868\u793a\u66b4\u9732\u7684\u6570\u5b57\u3002

\n\n

\u4e3a\u4e86\u9690\u85cf\u6709\u56fd\u9645\u53f7\u7801\u7684\u7535\u8bdd\u53f7\u7801\uff0c\u50cf "+111 111 111 1111"\uff0c\u6211\u4eec\u4ee5 "+***-***-***-1111" \u7684\u683c\u5f0f\u6765\u663e\u793a\u3002\u5728\u672c\u5730\u53f7\u7801\u524d\u9762\u7684 '+' \u53f7\u548c\u7b2c\u4e00\u4e2a '-' \u53f7\u4ec5\u5f53\u7535\u8bdd\u53f7\u7801\u4e2d\u5305\u542b\u56fd\u9645\u53f7\u7801\u65f6\u5b58\u5728\u3002\u4f8b\u5982\uff0c\u4e00\u4e2a 12 \u4f4d\u7684\u7535\u8bdd\u53f7\u7801\u5e94\u5f53\u4ee5 "+**-" \u5f00\u5934\u8fdb\u884c\u663e\u793a\u3002

\n\n

\u6ce8\u610f\uff1a\u50cf "("\uff0c")"\uff0c" " \u8fd9\u6837\u7684\u4e0d\u76f8\u5e72\u7684\u5b57\u7b26\u4ee5\u53ca\u4e0d\u7b26\u5408\u4e0a\u8ff0\u683c\u5f0f\u7684\u989d\u5916\u7684\u51cf\u53f7\u6216\u8005\u52a0\u53f7\u90fd\u5e94\u5f53\u88ab\u5220\u9664\u3002

\n\n

 

\n\n

\u6700\u540e\uff0c\u5c06\u63d0\u4f9b\u7684\u4fe1\u606f\u6b63\u786e\u9690\u85cf\u540e\u8fd4\u56de\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165: "LeetCode@LeetCode.com"\n\u8f93\u51fa: "l*****e@leetcode.com"\n\u89e3\u91ca\uff1a \n\u6240\u6709\u7684\u540d\u79f0\u8f6c\u6362\u6210\u5c0f\u5199, \u7b2c\u4e00\u4e2a\u540d\u79f0\u7684\u7b2c\u4e00\u4e2a\u5b57\u7b26\u548c\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\u4e2d\u95f4\u7531 5 \u4e2a\u661f\u53f7\u4ee3\u66ff\u3002\n\u56e0\u6b64\uff0c"leetcode" -> "l*****e"\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165: "AB@qq.com"\n\u8f93\u51fa: "a*****b@qq.com"\n\u89e3\u91ca: \n\u7b2c\u4e00\u4e2a\u540d\u79f0"ab"\u7684\u7b2c\u4e00\u4e2a\u5b57\u7b26\u548c\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\u7684\u4e2d\u95f4\u5fc5\u987b\u6709 5 \u4e2a\u661f\u53f7\n\u56e0\u6b64\uff0c"ab" -> "a*****b"\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165: "1(234)567-890"\n\u8f93\u51fa: "***-***-7890"\n\u89e3\u91ca: \n10 \u4e2a\u6570\u5b57\u7684\u7535\u8bdd\u53f7\u7801\uff0c\u90a3\u610f\u5473\u7740\u6240\u6709\u7684\u6570\u5b57\u90fd\u662f\u672c\u5730\u53f7\u7801\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165: "86-(10)12345678"\n\u8f93\u51fa: "+**-***-***-5678"\n\u89e3\u91ca: \n12 \u4f4d\u6570\u5b57\uff0c2 \u4e2a\u6570\u5b57\u662f\u56fd\u9645\u53f7\u7801\u53e6\u5916 10 \u4e2a\u6570\u5b57\u662f\u672c\u5730\u53f7\u7801 \u3002\n
\n\n

 

\n\n

\u6ce8\u610f:

\n\n
    \n\t
  1. S.length <= 40\u3002
  2. \n\t
  3. \u90ae\u7bb1\u7684\u957f\u5ea6\u81f3\u5c11\u662f 8\u3002
  4. \n\t
  5. \u7535\u8bdd\u53f7\u7801\u7684\u957f\u5ea6\u81f3\u5c11\u662f 10\u3002
  6. \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string maskPII(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String maskPII(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maskPII(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maskPII(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * maskPII(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string MaskPII(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar maskPII = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef mask_pii(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maskPII(_ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maskPII(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maskPII(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maskPII(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn mask_pii(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function maskPII($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maskPII(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (mask-pii s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0831](https://leetcode-cn.com/problems/masking-personal-information)", "[\u9690\u85cf\u4e2a\u4eba\u4fe1\u606f](/solution/0800-0899/0831.Masking%20Personal%20Information/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0831](https://leetcode.com/problems/masking-personal-information)", "[Masking Personal Information](/solution/0800-0899/0831.Masking%20Personal%20Information/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "0857", "frontend_question_id": "0830", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/positions-of-large-groups", "url_en": "https://leetcode.com/problems/positions-of-large-groups", "relative_path_cn": "/solution/0800-0899/0830.Positions%20of%20Large%20Groups/README.md", "relative_path_en": "/solution/0800-0899/0830.Positions%20of%20Large%20Groups/README_EN.md", "title_cn": "\u8f83\u5927\u5206\u7ec4\u7684\u4f4d\u7f6e", "title_en": "Positions of Large Groups", "question_title_slug": "positions-of-large-groups", "content_en": "

In a string s of lowercase letters, these letters form consecutive groups of the same character.

\n\n

For example, a string like s = "abbxxxxzyy" has the groups "a", "bb", "xxxx", "z", and "yy".

\n\n

A group is identified by an interval [start, end], where start and end denote the start and end indices (inclusive) of the group. In the above example, "xxxx" has the interval [3,6].

\n\n

A group is considered large if it has 3 or more characters.

\n\n

Return the intervals of every large group sorted in increasing order by start index.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "abbxxxxzzy"\nOutput: [[3,6]]\nExplanation: "xxxx" is the only large group with start index 3 and end index 6.\n
\n\n

Example 2:

\n\n
\nInput: s = "abc"\nOutput: []\nExplanation: We have groups "a", "b", and "c", none of which are large groups.\n
\n\n

Example 3:

\n\n
\nInput: s = "abcdddeeeeaabbbcd"\nOutput: [[3,5],[6,9],[12,14]]\nExplanation: The large groups are "ddd", "eeee", and "bbb".\n
\n\n

Example 4:

\n\n
\nInput: s = "aba"\nOutput: []\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 1000
  • \n\t
  • s contains lower-case English letters only.
  • \n
\n", "content_cn": "

\u5728\u4e00\u4e2a\u7531\u5c0f\u5199\u5b57\u6bcd\u6784\u6210\u7684\u5b57\u7b26\u4e32 s \u4e2d\uff0c\u5305\u542b\u7531\u4e00\u4e9b\u8fde\u7eed\u7684\u76f8\u540c\u5b57\u7b26\u6240\u6784\u6210\u7684\u5206\u7ec4\u3002

\n\n

\u4f8b\u5982\uff0c\u5728\u5b57\u7b26\u4e32 s = \"abbxxxxzyy\"\u00a0\u4e2d\uff0c\u5c31\u542b\u6709 \"a\", \"bb\", \"xxxx\", \"z\" \u548c \"yy\" \u8fd9\u6837\u7684\u4e00\u4e9b\u5206\u7ec4\u3002

\n\n

\u5206\u7ec4\u53ef\u4ee5\u7528\u533a\u95f4 [start, end] \u8868\u793a\uff0c\u5176\u4e2d start \u548c end \u5206\u522b\u8868\u793a\u8be5\u5206\u7ec4\u7684\u8d77\u59cb\u548c\u7ec8\u6b62\u4f4d\u7f6e\u7684\u4e0b\u6807\u3002\u4e0a\u4f8b\u4e2d\u7684 \"xxxx\" \u5206\u7ec4\u7528\u533a\u95f4\u8868\u793a\u4e3a [3,6] \u3002

\n\n

\u6211\u4eec\u79f0\u6240\u6709\u5305\u542b\u5927\u4e8e\u6216\u7b49\u4e8e\u4e09\u4e2a\u8fde\u7eed\u5b57\u7b26\u7684\u5206\u7ec4\u4e3a \u8f83\u5927\u5206\u7ec4 \u3002

\n\n

\u627e\u5230\u6bcf\u4e00\u4e2a \u8f83\u5927\u5206\u7ec4 \u7684\u533a\u95f4\uff0c\u6309\u8d77\u59cb\u4f4d\u7f6e\u4e0b\u6807\u9012\u589e\u987a\u5e8f\u6392\u5e8f\u540e\uff0c\u8fd4\u56de\u7ed3\u679c\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b\u00a01\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"abbxxxxzzy\"\n\u8f93\u51fa\uff1a[[3,6]]\n\u89e3\u91ca\uff1a\"xxxx\" \u662f\u4e00\u4e2a\u8d77\u59cb\u4e8e 3 \u4e14\u7ec8\u6b62\u4e8e 6 \u7684\u8f83\u5927\u5206\u7ec4\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"abc\"\n\u8f93\u51fa\uff1a[]\n\u89e3\u91ca\uff1a\"a\",\"b\" \u548c \"c\" \u5747\u4e0d\u662f\u7b26\u5408\u8981\u6c42\u7684\u8f83\u5927\u5206\u7ec4\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"abcdddeeeeaabbbcd\"\n\u8f93\u51fa\uff1a[[3,5],[6,9],[12,14]]\n\u89e3\u91ca\uff1a\u8f83\u5927\u5206\u7ec4\u4e3a \"ddd\", \"eeee\" \u548c \"bbb\"
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"aba\"\n\u8f93\u51fa\uff1a[]\n
\n\u00a0\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s.length <= 1000
  • \n\t
  • s \u4ec5\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> largeGroupPositions(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> largeGroupPositions(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def largeGroupPositions(self, s):\n \"\"\"\n :type s: str\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def largeGroupPositions(self, s: str) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** largeGroupPositions(char * s, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> LargeGroupPositions(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number[][]}\n */\nvar largeGroupPositions = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer[][]}\ndef large_group_positions(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func largeGroupPositions(_ s: String) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func largeGroupPositions(s string) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def largeGroupPositions(s: String): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun largeGroupPositions(s: String): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn large_group_positions(s: String) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer[][]\n */\n function largeGroupPositions($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function largeGroupPositions(s: string): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (large-group-positions s)\n (-> string? (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0830](https://leetcode-cn.com/problems/positions-of-large-groups)", "[\u8f83\u5927\u5206\u7ec4\u7684\u4f4d\u7f6e](/solution/0800-0899/0830.Positions%20of%20Large%20Groups/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0830](https://leetcode.com/problems/positions-of-large-groups)", "[Positions of Large Groups](/solution/0800-0899/0830.Positions%20of%20Large%20Groups/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0856", "frontend_question_id": "0829", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/consecutive-numbers-sum", "url_en": "https://leetcode.com/problems/consecutive-numbers-sum", "relative_path_cn": "/solution/0800-0899/0829.Consecutive%20Numbers%20Sum/README.md", "relative_path_en": "/solution/0800-0899/0829.Consecutive%20Numbers%20Sum/README_EN.md", "title_cn": "\u8fde\u7eed\u6574\u6570\u6c42\u548c", "title_en": "Consecutive Numbers Sum", "question_title_slug": "consecutive-numbers-sum", "content_en": "

Given a positive integer n, how many ways can we write it as a sum of consecutive positive integers?

\n\n

Example 1:

\n\n
\nInput: n = 5\nOutput: 2\nExplanation: 5 = 5 = 2 + 3
\n\n

Example 2:

\n\n
\nInput: n = 9\nOutput: 3\nExplanation: 9 = 9 = 4 + 5 = 2 + 3 + 4
\n\n

Example 3:

\n\n
\nInput: n = 15\nOutput: 4\nExplanation: 15 = 15 = 8 + 7 = 4 + 5 + 6 = 1 + 2 + 3 + 4 + 5
\n\n

Note: 1 <= n <= 10 ^ 9.

\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u6b63\u6574\u6570 N\uff0c\u8bd5\u6c42\u6709\u591a\u5c11\u7ec4\u8fde\u7eed\u6b63\u6574\u6570\u6ee1\u8db3\u6240\u6709\u6570\u5b57\u4e4b\u548c\u4e3a N?

\n\n

\u793a\u4f8b 1:

\n\n
\n\u8f93\u5165: 5\n\u8f93\u51fa: 2\n\u89e3\u91ca: 5 = 5 = 2 + 3\uff0c\u5171\u6709\u4e24\u7ec4\u8fde\u7eed\u6574\u6570([5],[2,3])\u6c42\u548c\u540e\u4e3a 5\u3002
\n\n

\u793a\u4f8b 2:

\n\n
\n\u8f93\u5165: 9\n\u8f93\u51fa: 3\n\u89e3\u91ca: 9 = 9 = 4 + 5 = 2 + 3 + 4
\n\n

\u793a\u4f8b 3:

\n\n
\n\u8f93\u5165: 15\n\u8f93\u51fa: 4\n\u89e3\u91ca: 15 = 15 = 8 + 7 = 4 + 5 + 6 = 1 + 2 + 3 + 4 + 5
\n\n

\u8bf4\u660e: 1 <= N <= 10 ^ 9

\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int consecutiveNumbersSum(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int consecutiveNumbersSum(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def consecutiveNumbersSum(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def consecutiveNumbersSum(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint consecutiveNumbersSum(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ConsecutiveNumbersSum(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar consecutiveNumbersSum = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef consecutive_numbers_sum(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func consecutiveNumbersSum(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func consecutiveNumbersSum(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def consecutiveNumbersSum(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun consecutiveNumbersSum(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn consecutive_numbers_sum(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function consecutiveNumbersSum($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function consecutiveNumbersSum(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (consecutive-numbers-sum n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0829](https://leetcode-cn.com/problems/consecutive-numbers-sum)", "[\u8fde\u7eed\u6574\u6570\u6c42\u548c](/solution/0800-0899/0829.Consecutive%20Numbers%20Sum/README.md)", "`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[0829](https://leetcode.com/problems/consecutive-numbers-sum)", "[Consecutive Numbers Sum](/solution/0800-0899/0829.Consecutive%20Numbers%20Sum/README_EN.md)", "`Math`", "Hard", ""]}, {"question_id": "0855", "frontend_question_id": "0828", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-unique-characters-of-all-substrings-of-a-given-string", "url_en": "https://leetcode.com/problems/count-unique-characters-of-all-substrings-of-a-given-string", "relative_path_cn": "/solution/0800-0899/0828.Count%20Unique%20Characters%20of%20All%20Substrings%20of%20a%20Given%20String/README.md", "relative_path_en": "/solution/0800-0899/0828.Count%20Unique%20Characters%20of%20All%20Substrings%20of%20a%20Given%20String/README_EN.md", "title_cn": "\u7edf\u8ba1\u5b50\u4e32\u4e2d\u7684\u552f\u4e00\u5b57\u7b26", "title_en": "Count Unique Characters of All Substrings of a Given String", "question_title_slug": "count-unique-characters-of-all-substrings-of-a-given-string", "content_en": "

Let's define a function countUniqueChars(s) that returns the number of unique characters on s, for example if s = "LEETCODE" then "L", "T","C","O","D" are the unique characters since they appear only once in s, therefore countUniqueChars(s) = 5.
\n
\nOn this problem given a string s we need to return the sum of countUniqueChars(t) where t is a substring of s. Notice that some substrings can be repeated so on this case you have to count the repeated ones too.

\n\n

Since the answer can be very large, return the answer modulo 10 ^ 9 + 7.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "ABC"\nOutput: 10\nExplanation: All possible substrings are: "A","B","C","AB","BC" and "ABC".\nEvey substring is composed with only unique letters.\nSum of lengths of all substring is 1 + 1 + 1 + 2 + 2 + 3 = 10\n
\n\n

Example 2:

\n\n
\nInput: s = "ABA"\nOutput: 8\nExplanation: The same as example 1, except countUniqueChars("ABA") = 1.\n
\n\n

Example 3:

\n\n
\nInput: s = "LEETCODE"\nOutput: 92\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 0 <= s.length <= 10^4
  • \n\t
  • s contain upper-case English letters only.
  • \n
\n", "content_cn": "

\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a\u51fd\u6570 countUniqueChars(s) \u6765\u7edf\u8ba1\u5b57\u7b26\u4e32 s \u4e2d\u7684\u552f\u4e00\u5b57\u7b26\uff0c\u5e76\u8fd4\u56de\u552f\u4e00\u5b57\u7b26\u7684\u4e2a\u6570\u3002

\n\n

\u4f8b\u5982\uff1as = \"LEETCODE\" \uff0c\u5219\u5176\u4e2d \"L\", \"T\",\"C\",\"O\",\"D\" \u90fd\u662f\u552f\u4e00\u5b57\u7b26\uff0c\u56e0\u4e3a\u5b83\u4eec\u53ea\u51fa\u73b0\u4e00\u6b21\uff0c\u6240\u4ee5 countUniqueChars(s) = 5 \u3002

\n\n

\u672c\u9898\u5c06\u4f1a\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \uff0c\u6211\u4eec\u9700\u8981\u8fd4\u56de countUniqueChars(t) \u7684\u603b\u548c\uff0c\u5176\u4e2d t \u662f s \u7684\u5b50\u5b57\u7b26\u4e32\u3002\u6ce8\u610f\uff0c\u67d0\u4e9b\u5b50\u5b57\u7b26\u4e32\u53ef\u80fd\u662f\u91cd\u590d\u7684\uff0c\u4f46\u4f60\u7edf\u8ba1\u65f6\u4e5f\u5fc5\u987b\u7b97\u4e0a\u8fd9\u4e9b\u91cd\u590d\u7684\u5b50\u5b57\u7b26\u4e32\uff08\u4e5f\u5c31\u662f\u8bf4\uff0c\u4f60\u5fc5\u987b\u7edf\u8ba1 s \u7684\u6240\u6709\u5b50\u5b57\u7b26\u4e32\u4e2d\u7684\u552f\u4e00\u5b57\u7b26\uff09\u3002

\n\n

\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u975e\u5e38\u5927\uff0c\u8bf7\u5c06\u7ed3\u679c mod 10 ^ 9 + 7 \u540e\u518d\u8fd4\u56de\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165: s = \"ABC\"\n\u8f93\u51fa: 10\n\u89e3\u91ca: \u6240\u6709\u53ef\u80fd\u7684\u5b50\u4e32\u4e3a\uff1a\"A\",\"B\",\"C\",\"AB\",\"BC\" \u548c \"ABC\"\u3002\n     \u5176\u4e2d\uff0c\u6bcf\u4e00\u4e2a\u5b50\u4e32\u90fd\u7531\u72ec\u7279\u5b57\u7b26\u6784\u6210\u3002\n     \u6240\u4ee5\u5176\u957f\u5ea6\u603b\u548c\u4e3a\uff1a1 + 1 + 1 + 2 + 2 + 3 = 10\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165: s = \"ABA\"\n\u8f93\u51fa: 8\n\u89e3\u91ca: \u9664\u4e86 countUniqueChars(\"ABA\") = 1 \u4e4b\u5916\uff0c\u5176\u4f59\u4e0e\u793a\u4f8b 1 \u76f8\u540c\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"LEETCODE\"\n\u8f93\u51fa\uff1a92\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 0 <= s.length <= 10^4
  • \n\t
  • s \u53ea\u5305\u542b\u5927\u5199\u82f1\u6587\u5b57\u7b26
  • \n
\n", "tags_en": ["Two Pointers"], "tags_cn": ["\u53cc\u6307\u9488"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int uniqueLetterString(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int uniqueLetterString(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def uniqueLetterString(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def uniqueLetterString(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint uniqueLetterString(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int UniqueLetterString(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar uniqueLetterString = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef unique_letter_string(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func uniqueLetterString(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func uniqueLetterString(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def uniqueLetterString(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun uniqueLetterString(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn unique_letter_string(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function uniqueLetterString($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function uniqueLetterString(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (unique-letter-string s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0828](https://leetcode-cn.com/problems/count-unique-characters-of-all-substrings-of-a-given-string)", "[\u7edf\u8ba1\u5b50\u4e32\u4e2d\u7684\u552f\u4e00\u5b57\u7b26](/solution/0800-0899/0828.Count%20Unique%20Characters%20of%20All%20Substrings%20of%20a%20Given%20String/README.md)", "`\u53cc\u6307\u9488`", "\u56f0\u96be", ""], "md_table_row_en": ["[0828](https://leetcode.com/problems/count-unique-characters-of-all-substrings-of-a-given-string)", "[Count Unique Characters of All Substrings of a Given String](/solution/0800-0899/0828.Count%20Unique%20Characters%20of%20All%20Substrings%20of%20a%20Given%20String/README_EN.md)", "`Two Pointers`", "Hard", ""]}, {"question_id": "0854", "frontend_question_id": "0827", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/making-a-large-island", "url_en": "https://leetcode.com/problems/making-a-large-island", "relative_path_cn": "/solution/0800-0899/0827.Making%20A%20Large%20Island/README.md", "relative_path_en": "/solution/0800-0899/0827.Making%20A%20Large%20Island/README_EN.md", "title_cn": "\u6700\u5927\u4eba\u5de5\u5c9b", "title_en": "Making A Large Island", "question_title_slug": "making-a-large-island", "content_en": "

You are given an n x n binary matrix grid. You are allowed to change at most one 0 to be 1.

\r\n\r\n

Return the size of the largest island in grid after applying this operation.

\r\n\r\n

An island is a 4-directionally connected group of 1s.

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: grid = [[1,0],[0,1]]\r\nOutput: 3\r\nExplanation: Change one 0 to 1 and connect two 1s, then we get an island with area = 3.\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: grid = [[1,1],[1,0]]\r\nOutput: 4\r\nExplanation: Change the 0 to 1 and make the island bigger, only one island with area = 4.
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: grid = [[1,1],[1,1]]\r\nOutput: 4\r\nExplanation: Can't change any 0 to 1, only one island with area = 4.\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • n == grid.length
  • \r\n\t
  • n == grid[i].length
  • \r\n\t
  • 1 <= n <= 500
  • \r\n\t
  • grid[i][j] is either 0 or 1.
  • \r\n
", "content_cn": "

\u5728\u4e8c\u7ef4\u5730\u56fe\u4e0a\uff0c 0\u4ee3\u8868\u6d77\u6d0b\uff0c 1\u4ee3\u8868\u9646\u5730\uff0c\u6211\u4eec\u6700\u591a\u53ea\u80fd\u5c06\u4e00\u683c 0 \u6d77\u6d0b\u53d8\u6210 1\u53d8\u6210\u9646\u5730\u3002

\n\n

\u8fdb\u884c\u586b\u6d77\u4e4b\u540e\uff0c\u5730\u56fe\u4e0a\u6700\u5927\u7684\u5c9b\u5c7f\u9762\u79ef\u662f\u591a\u5c11\uff1f\uff08\u4e0a\u3001\u4e0b\u3001\u5de6\u3001\u53f3\u56db\u4e2a\u65b9\u5411\u76f8\u8fde\u7684 1 \u53ef\u5f62\u6210\u5c9b\u5c7f\uff09

\n\n

\u793a\u4f8b 1:

\n\n
\n\u8f93\u5165: [[1, 0], [0, 1]]\n\u8f93\u51fa: 3\n\u89e3\u91ca: \u5c06\u4e00\u683c0\u53d8\u62101\uff0c\u6700\u7ec8\u8fde\u901a\u4e24\u4e2a\u5c0f\u5c9b\u5f97\u5230\u9762\u79ef\u4e3a 3 \u7684\u5c9b\u5c7f\u3002\n
\n\n

\u793a\u4f8b 2:

\n\n
\n\u8f93\u5165: [[1, 1], [1, 0]]\n\u8f93\u51fa: 4\n\u89e3\u91ca: \u5c06\u4e00\u683c0\u53d8\u62101\uff0c\u5c9b\u5c7f\u7684\u9762\u79ef\u6269\u5927\u4e3a 4\u3002
\n\n

\u793a\u4f8b 3:

\n\n
\n\u8f93\u5165: [[1, 1], [1, 1]]\n\u8f93\u51fa: 4\n\u89e3\u91ca: \u6ca1\u67090\u53ef\u4ee5\u8ba9\u6211\u4eec\u53d8\u62101\uff0c\u9762\u79ef\u4f9d\u7136\u4e3a 4\u3002
\n\n

\u8bf4\u660e:

\n\n
    \n\t
  • 1 <= grid.length = grid[0].length <= 50
  • \n\t
  • 0 <= grid[i][j] <= 1
  • \n
\n", "tags_en": ["Depth-first Search", "Breadth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int largestIsland(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int largestIsland(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def largestIsland(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def largestIsland(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint largestIsland(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LargestIsland(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar largestIsland = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef largest_island(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func largestIsland(_ grid: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func largestIsland(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def largestIsland(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun largestIsland(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn largest_island(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function largestIsland($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function largestIsland(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (largest-island grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0827](https://leetcode-cn.com/problems/making-a-large-island)", "[\u6700\u5927\u4eba\u5de5\u5c9b](/solution/0800-0899/0827.Making%20A%20Large%20Island/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[0827](https://leetcode.com/problems/making-a-large-island)", "[Making A Large Island](/solution/0800-0899/0827.Making%20A%20Large%20Island/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`", "Hard", ""]}, {"question_id": "0853", "frontend_question_id": "0826", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/most-profit-assigning-work", "url_en": "https://leetcode.com/problems/most-profit-assigning-work", "relative_path_cn": "/solution/0800-0899/0826.Most%20Profit%20Assigning%20Work/README.md", "relative_path_en": "/solution/0800-0899/0826.Most%20Profit%20Assigning%20Work/README_EN.md", "title_cn": "\u5b89\u6392\u5de5\u4f5c\u4ee5\u8fbe\u5230\u6700\u5927\u6536\u76ca", "title_en": "Most Profit Assigning Work", "question_title_slug": "most-profit-assigning-work", "content_en": "

We have jobs: difficulty[i] is the difficulty of the ith job, and profit[i] is the profit of the ith job. 

\r\n\r\n

Now we have some workers. worker[i] is the ability of the ith worker, which means that this worker can only complete a job with difficulty at most worker[i]

\r\n\r\n

Every worker can be assigned at most one job, but one job can be completed multiple times.

\r\n\r\n

For example, if 3 people attempt the same job that pays $1, then the total profit will be $3.  If a worker cannot complete any job, his profit is $0.

\r\n\r\n

What is the most profit we can make?

\r\n\r\n

Example 1:

\r\n\r\n
\r\nInput: difficulty = [2,4,6,8,10], profit = [10,20,30,40,50], worker = [4,5,6,7]\r\nOutput: 100 \r\nExplanation: Workers are assigned jobs of difficulty [4,4,6,6] and they get profit of [20,20,30,30] seperately.
\r\n\r\n

Notes:

\r\n\r\n
    \r\n\t
  • 1 <= difficulty.length = profit.length <= 10000
  • \r\n\t
  • 1 <= worker.length <= 10000
  • \r\n\t
  • difficulty[i], profit[i], worker[i]  are in range [1, 10^5]
  • \r\n
\r\n", "content_cn": "

\u6709\u4e00\u4e9b\u5de5\u4f5c\uff1adifficulty[i] \u8868\u793a\u7b2c i \u4e2a\u5de5\u4f5c\u7684\u96be\u5ea6\uff0cprofit[i] \u8868\u793a\u7b2c i \u4e2a\u5de5\u4f5c\u7684\u6536\u76ca\u3002

\n\n

\u73b0\u5728\u6211\u4eec\u6709\u4e00\u4e9b\u5de5\u4eba\u3002worker[i] \u662f\u7b2c i \u4e2a\u5de5\u4eba\u7684\u80fd\u529b\uff0c\u5373\u8be5\u5de5\u4eba\u53ea\u80fd\u5b8c\u6210\u96be\u5ea6\u5c0f\u4e8e\u7b49\u4e8e worker[i] \u7684\u5de5\u4f5c\u3002

\n\n

\u6bcf\u4e00\u4e2a\u5de5\u4eba\u90fd\u6700\u591a\u53ea\u80fd\u5b89\u6392\u4e00\u4e2a\u5de5\u4f5c\uff0c\u4f46\u662f\u4e00\u4e2a\u5de5\u4f5c\u53ef\u4ee5\u5b8c\u6210\u591a\u6b21\u3002

\n\n

\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u5982\u679c 3 \u4e2a\u5de5\u4eba\u90fd\u5c1d\u8bd5\u5b8c\u6210\u4e00\u4efd\u62a5\u916c\u4e3a 1 \u7684\u540c\u6837\u5de5\u4f5c\uff0c\u90a3\u4e48\u603b\u6536\u76ca\u4e3a $3\u3002\u5982\u679c\u4e00\u4e2a\u5de5\u4eba\u4e0d\u80fd\u5b8c\u6210\u4efb\u4f55\u5de5\u4f5c\uff0c\u4ed6\u7684\u6536\u76ca\u4e3a $0 \u3002

\n\n

\u6211\u4eec\u80fd\u5f97\u5230\u7684\u6700\u5927\u6536\u76ca\u662f\u591a\u5c11\uff1f

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165: difficulty = [2,4,6,8,10], profit = [10,20,30,40,50], worker = [4,5,6,7]\n\u8f93\u51fa: 100 \n\u89e3\u91ca: \u5de5\u4eba\u88ab\u5206\u914d\u7684\u5de5\u4f5c\u96be\u5ea6\u662f [4,4,6,6] \uff0c\u5206\u522b\u83b7\u5f97 [20,20,30,30] \u7684\u6536\u76ca\u3002
\n\n

 

\n\n

\u63d0\u793a:

\n\n
    \n\t
  • 1 <= difficulty.length = profit.length <= 10000
  • \n\t
  • 1 <= worker.length <= 10000
  • \n\t
  • difficulty[i], profit[i], worker[i]  \u7684\u8303\u56f4\u662f [1, 10^5]
  • \n
\n", "tags_en": ["Two Pointers"], "tags_cn": ["\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxProfitAssignment(vector& difficulty, vector& profit, vector& worker) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxProfitAssignment(int[] difficulty, int[] profit, int[] worker) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxProfitAssignment(self, difficulty, profit, worker):\n \"\"\"\n :type difficulty: List[int]\n :type profit: List[int]\n :type worker: List[int]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxProfitAssignment(self, difficulty: List[int], profit: List[int], worker: List[int]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxProfitAssignment(int* difficulty, int difficultySize, int* profit, int profitSize, int* worker, int workerSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxProfitAssignment(int[] difficulty, int[] profit, int[] worker) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} difficulty\n * @param {number[]} profit\n * @param {number[]} worker\n * @return {number}\n */\nvar maxProfitAssignment = function(difficulty, profit, worker) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} difficulty\n# @param {Integer[]} profit\n# @param {Integer[]} worker\n# @return {Integer}\ndef max_profit_assignment(difficulty, profit, worker)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxProfitAssignment(_ difficulty: [Int], _ profit: [Int], _ worker: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxProfitAssignment(difficulty []int, profit []int, worker []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxProfitAssignment(difficulty: Array[Int], profit: Array[Int], worker: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxProfitAssignment(difficulty: IntArray, profit: IntArray, worker: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_profit_assignment(difficulty: Vec, profit: Vec, worker: Vec) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $difficulty\n * @param Integer[] $profit\n * @param Integer[] $worker\n * @return Integer\n */\n function maxProfitAssignment($difficulty, $profit, $worker) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxProfitAssignment(difficulty: number[], profit: number[], worker: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-profit-assignment difficulty profit worker)\n (-> (listof exact-integer?) (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0826](https://leetcode-cn.com/problems/most-profit-assigning-work)", "[\u5b89\u6392\u5de5\u4f5c\u4ee5\u8fbe\u5230\u6700\u5927\u6536\u76ca](/solution/0800-0899/0826.Most%20Profit%20Assigning%20Work/README.md)", "`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0826](https://leetcode.com/problems/most-profit-assigning-work)", "[Most Profit Assigning Work](/solution/0800-0899/0826.Most%20Profit%20Assigning%20Work/README_EN.md)", "`Two Pointers`", "Medium", ""]}, {"question_id": "0852", "frontend_question_id": "0825", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/friends-of-appropriate-ages", "url_en": "https://leetcode.com/problems/friends-of-appropriate-ages", "relative_path_cn": "/solution/0800-0899/0825.Friends%20Of%20Appropriate%20Ages/README.md", "relative_path_en": "/solution/0800-0899/0825.Friends%20Of%20Appropriate%20Ages/README_EN.md", "title_cn": "\u9002\u9f84\u7684\u670b\u53cb", "title_en": "Friends Of Appropriate Ages", "question_title_slug": "friends-of-appropriate-ages", "content_en": "

Some people will make friend requests. The list of their ages is given and ages[i] is the age of the ith person. 

\n\n

Person A will NOT friend request person B (B != A) if any of the following conditions are true:

\n\n
    \n\t
  • age[B] <= 0.5 * age[A] + 7
  • \n\t
  • age[B] > age[A]
  • \n\t
  • age[B] > 100 && age[A] < 100
  • \n
\n\n

Otherwise, A will friend request B.

\n\n

Note that if A requests B, B does not necessarily request A.  Also, people will not friend request themselves.

\n\n

How many total friend requests are made?

\n\n

Example 1:

\n\n
\nInput: [16,16]\nOutput: 2\nExplanation: 2 people friend request each other.\n
\n\n

Example 2:

\n\n
\nInput: [16,17,18]\nOutput: 2\nExplanation: Friend requests are made 17 -> 16, 18 -> 17.
\n\n

Example 3:

\n\n
\nInput: [20,30,100,110,120]\nOutput: 3\nExplanation: Friend requests are made 110 -> 100, 120 -> 110, 120 -> 100.\n
\n\n

 

\n\n

Notes:

\n\n
    \n\t
  • 1 <= ages.length <= 20000.
  • \n\t
  • 1 <= ages[i] <= 120.
  • \n
\n", "content_cn": "

\u4eba\u4eec\u4f1a\u4e92\u76f8\u53d1\u9001\u597d\u53cb\u8bf7\u6c42\uff0c\u73b0\u5728\u7ed9\u5b9a\u4e00\u4e2a\u5305\u542b\u6709\u4ed6\u4eec\u5e74\u9f84\u7684\u6570\u7ec4\uff0cages[i]\u00a0\u8868\u793a\u7b2c i \u4e2a\u4eba\u7684\u5e74\u9f84\u3002

\n\n

\u5f53\u6ee1\u8db3\u4ee5\u4e0b\u4efb\u4e00\u6761\u4ef6\u65f6\uff0cA \u4e0d\u80fd\u7ed9 B\uff08A\u3001B\u4e0d\u4e3a\u540c\u4e00\u4eba\uff09\u53d1\u9001\u597d\u53cb\u8bf7\u6c42\uff1a

\n\n
    \n\t
  • age[B]\u00a0<= 0.5 * age[A]\u00a0+ 7
  • \n\t
  • age[B]\u00a0> age[A]
  • \n\t
  • age[B]\u00a0> 100 &&\u00a0age[A]\u00a0< 100
  • \n
\n\n

\u5426\u5219\uff0cA \u53ef\u4ee5\u7ed9 B \u53d1\u9001\u597d\u53cb\u8bf7\u6c42\u3002

\n\n

\u6ce8\u610f\u5982\u679c A \u5411 B \u53d1\u51fa\u4e86\u8bf7\u6c42\uff0c\u4e0d\u7b49\u4e8e B \u4e5f\u4e00\u5b9a\u4f1a\u5411\u00a0A \u53d1\u51fa\u8bf7\u6c42\u3002\u800c\u4e14\uff0c\u4eba\u4eec\u4e0d\u4f1a\u7ed9\u81ea\u5df1\u53d1\u9001\u597d\u53cb\u8bf7\u6c42\u3002\u00a0

\n\n

\u6c42\u603b\u5171\u4f1a\u53d1\u51fa\u591a\u5c11\u4efd\u597d\u53cb\u8bf7\u6c42?

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1a[16,16]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u4e8c\u4eba\u53ef\u4ee5\u4e92\u53d1\u597d\u53cb\u7533\u8bf7\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1a[16,17,18]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u597d\u53cb\u8bf7\u6c42\u53ef\u4ea7\u751f\u4e8e 17 -> 16, 18 -> 17.
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1a[20,30,100,110,120]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u597d\u53cb\u8bf7\u6c42\u53ef\u4ea7\u751f\u4e8e 110 -> 100, 120 -> 110, 120 -> 100.\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= ages.length\u00a0<= 20000
  • \n\t
  • 1 <= ages[i] <= 120
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numFriendRequests(vector& ages) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numFriendRequests(int[] ages) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numFriendRequests(self, ages):\n \"\"\"\n :type ages: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numFriendRequests(self, ages: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numFriendRequests(int* ages, int agesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumFriendRequests(int[] ages) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} ages\n * @return {number}\n */\nvar numFriendRequests = function(ages) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} ages\n# @return {Integer}\ndef num_friend_requests(ages)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numFriendRequests(_ ages: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numFriendRequests(ages []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numFriendRequests(ages: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numFriendRequests(ages: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_friend_requests(ages: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $ages\n * @return Integer\n */\n function numFriendRequests($ages) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numFriendRequests(ages: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-friend-requests ages)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0825](https://leetcode-cn.com/problems/friends-of-appropriate-ages)", "[\u9002\u9f84\u7684\u670b\u53cb](/solution/0800-0899/0825.Friends%20Of%20Appropriate%20Ages/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0825](https://leetcode.com/problems/friends-of-appropriate-ages)", "[Friends Of Appropriate Ages](/solution/0800-0899/0825.Friends%20Of%20Appropriate%20Ages/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0851", "frontend_question_id": "0824", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/goat-latin", "url_en": "https://leetcode.com/problems/goat-latin", "relative_path_cn": "/solution/0800-0899/0824.Goat%20Latin/README.md", "relative_path_en": "/solution/0800-0899/0824.Goat%20Latin/README_EN.md", "title_cn": "\u5c71\u7f8a\u62c9\u4e01\u6587", "title_en": "Goat Latin", "question_title_slug": "goat-latin", "content_en": "

A sentence sentence is given, composed of words separated by spaces. Each word consists of lowercase and uppercase letters only.

\n\n

We would like to convert the sentence to "Goat Latin" (a made-up language similar to Pig Latin.)

\n\n

The rules of Goat Latin are as follows:

\n\n
    \n\t
  • If a word begins with a vowel (a, e, i, o, or u), append "ma" to the end of the word.
    \n\tFor example, the word 'apple' becomes 'applema'.
    \n\t 
  • \n\t
  • If a word begins with a consonant (i.e. not a vowel), remove the first letter and append it to the end, then add "ma".
    \n\tFor example, the word "goat" becomes "oatgma".
    \n\t 
  • \n\t
  • Add one letter 'a' to the end of each word per its word index in the sentence, starting with 1.
    \n\tFor example, the first word gets "a" added to the end, the second word gets "aa" added to the end and so on.
  • \n
\n\n

Return the final sentence representing the conversion from sentence to Goat Latin. 

\n\n

 

\n\n

Example 1:

\n\n
\nInput: sentence = "I speak Goat Latin"\nOutput: "Imaa peaksmaaa oatGmaaaa atinLmaaaaa"\n
\n\n

Example 2:

\n\n
\nInput: sentence = "The quick brown fox jumped over the lazy dog"\nOutput: "heTmaa uickqmaaa rownbmaaaa oxfmaaaaa umpedjmaaaaaa overmaaaaaaa hetmaaaaaaaa azylmaaaaaaaaa ogdmaaaaaaaaaa"\n
\n\n

 

\n\n

Notes:

\n\n
    \n\t
  • sentence contains only uppercase, lowercase and spaces. Exactly one space between each word.
  • \n\t
  • 1 <= sentence.length <= 150.
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u7531\u7a7a\u683c\u5206\u5272\u5355\u8bcd\u7684\u53e5\u5b50 S\u3002\u6bcf\u4e2a\u5355\u8bcd\u53ea\u5305\u542b\u5927\u5199\u6216\u5c0f\u5199\u5b57\u6bcd\u3002

\n\n

\u6211\u4eec\u8981\u5c06\u53e5\u5b50\u8f6c\u6362\u4e3a “Goat Latin”\uff08\u4e00\u79cd\u7c7b\u4f3c\u4e8e \u732a\u62c9\u4e01\u6587 - Pig Latin \u7684\u865a\u6784\u8bed\u8a00\uff09\u3002

\n\n

\u5c71\u7f8a\u62c9\u4e01\u6587\u7684\u89c4\u5219\u5982\u4e0b\uff1a

\n\n
    \n\t
  • \u5982\u679c\u5355\u8bcd\u4ee5\u5143\u97f3\u5f00\u5934\uff08a, e, i, o, u\uff09\uff0c\u5728\u5355\u8bcd\u540e\u6dfb\u52a0"ma"\u3002
    \n\t\u4f8b\u5982\uff0c\u5355\u8bcd"apple"\u53d8\u4e3a"applema"\u3002
  • \n\t
    \n\t
  • \u5982\u679c\u5355\u8bcd\u4ee5\u8f85\u97f3\u5b57\u6bcd\u5f00\u5934\uff08\u5373\u975e\u5143\u97f3\u5b57\u6bcd\uff09\uff0c\u79fb\u9664\u7b2c\u4e00\u4e2a\u5b57\u7b26\u5e76\u5c06\u5b83\u653e\u5230\u672b\u5c3e\uff0c\u4e4b\u540e\u518d\u6dfb\u52a0"ma"\u3002
    \n\t\u4f8b\u5982\uff0c\u5355\u8bcd"goat"\u53d8\u4e3a"oatgma"\u3002
  • \n\t
    \n\t
  • \u6839\u636e\u5355\u8bcd\u5728\u53e5\u5b50\u4e2d\u7684\u7d22\u5f15\uff0c\u5728\u5355\u8bcd\u6700\u540e\u6dfb\u52a0\u4e0e\u7d22\u5f15\u76f8\u540c\u6570\u91cf\u7684\u5b57\u6bcd'a'\uff0c\u7d22\u5f15\u4ece1\u5f00\u59cb\u3002
    \n\t\u4f8b\u5982\uff0c\u5728\u7b2c\u4e00\u4e2a\u5355\u8bcd\u540e\u6dfb\u52a0"a"\uff0c\u5728\u7b2c\u4e8c\u4e2a\u5355\u8bcd\u540e\u6dfb\u52a0"aa"\uff0c\u4ee5\u6b64\u7c7b\u63a8\u3002
  • \n
\n\n

\u8fd4\u56de\u5c06 S \u8f6c\u6362\u4e3a\u5c71\u7f8a\u62c9\u4e01\u6587\u540e\u7684\u53e5\u5b50\u3002

\n\n

\u793a\u4f8b 1:

\n\n
\n\u8f93\u5165: "I speak Goat Latin"\n\u8f93\u51fa: "Imaa peaksmaaa oatGmaaaa atinLmaaaaa"\n
\n\n

\u793a\u4f8b 2:

\n\n
\n\u8f93\u5165: "The quick brown fox jumped over the lazy dog"\n\u8f93\u51fa: "heTmaa uickqmaaa rownbmaaaa oxfmaaaaa umpedjmaaaaaa overmaaaaaaa hetmaaaaaaaa azylmaaaaaaaaa ogdmaaaaaaaaaa"\n
\n\n

\u8bf4\u660e:

\n\n
    \n\t
  • S \u4e2d\u4ec5\u5305\u542b\u5927\u5c0f\u5199\u5b57\u6bcd\u548c\u7a7a\u683c\u3002\u5355\u8bcd\u95f4\u6709\u4e14\u4ec5\u6709\u4e00\u4e2a\u7a7a\u683c\u3002
  • \n\t
  • 1 <= S.length <= 150\u3002
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string toGoatLatin(string sentence) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String toGoatLatin(String sentence) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def toGoatLatin(self, sentence):\n \"\"\"\n :type sentence: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def toGoatLatin(self, sentence: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * toGoatLatin(char * sentence){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ToGoatLatin(string sentence) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} sentence\n * @return {string}\n */\nvar toGoatLatin = function(sentence) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} sentence\n# @return {String}\ndef to_goat_latin(sentence)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func toGoatLatin(_ sentence: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func toGoatLatin(sentence string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def toGoatLatin(sentence: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun toGoatLatin(sentence: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn to_goat_latin(sentence: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $sentence\n * @return String\n */\n function toGoatLatin($sentence) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function toGoatLatin(sentence: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (to-goat-latin sentence)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0824](https://leetcode-cn.com/problems/goat-latin)", "[\u5c71\u7f8a\u62c9\u4e01\u6587](/solution/0800-0899/0824.Goat%20Latin/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0824](https://leetcode.com/problems/goat-latin)", "[Goat Latin](/solution/0800-0899/0824.Goat%20Latin/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "0850", "frontend_question_id": "0708", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/insert-into-a-sorted-circular-linked-list", "url_en": "https://leetcode.com/problems/insert-into-a-sorted-circular-linked-list", "relative_path_cn": "/solution/0700-0799/0708.Insert%20into%20a%20Sorted%20Circular%20Linked%20List/README.md", "relative_path_en": "/solution/0700-0799/0708.Insert%20into%20a%20Sorted%20Circular%20Linked%20List/README_EN.md", "title_cn": "\u5faa\u73af\u6709\u5e8f\u5217\u8868\u7684\u63d2\u5165", "title_en": "Insert into a Sorted Circular Linked List", "question_title_slug": "insert-into-a-sorted-circular-linked-list", "content_en": "

Given a Circular Linked List node, which is sorted in ascending order, write a function to insert a value insertVal into the list such that it remains a sorted circular list. The given node can be a reference to any single node in the list and may not necessarily be the smallest value in the circular list.

\n\n

If there are multiple suitable places for insertion, you may choose any place to insert the new value. After the insertion, the circular list should remain sorted.

\n\n

If the list is empty (i.e., the given node is null), you should create a new single circular list and return the reference to that single node. Otherwise, you should return the originally given node.

\n\n

 

\n

Example 1:

\n\"\"
\n \n
\nInput: head = [3,4,1], insertVal = 2\nOutput: [3,4,1,2]\nExplanation: In the figure above, there is a sorted circular list of three elements. You are given a reference to the node with value 3, and we need to insert 2 into the list. The new node should be inserted between node 1 and node 3. After the insertion, the list should look like this, and we should still return node 3.\n\n\"\"\n\n
\n\n

Example 2:

\n\n
\nInput: head = [], insertVal = 1\nOutput: [1]\nExplanation: The list is empty (given head is null). We create a new single circular list and return the reference to that single node.\n
\n\n

Example 3:

\n\n
\nInput: head = [1], insertVal = 0\nOutput: [1,0]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 0 <= Number of Nodes <= 5 * 104
  • \n\t
  • -106 <= Node.val, insertVal <= 106
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u5faa\u73af\u5347\u5e8f\u5217\u8868\u4e2d\u7684\u4e00\u4e2a\u70b9\uff0c\u5199\u4e00\u4e2a\u51fd\u6570\u5411\u8fd9\u4e2a\u5217\u8868\u4e2d\u63d2\u5165\u4e00\u4e2a\u65b0\u5143\u7d20\u00a0insertVal \uff0c\u4f7f\u8fd9\u4e2a\u5217\u8868\u4ecd\u7136\u662f\u5faa\u73af\u5347\u5e8f\u7684\u3002

\n\n

\u7ed9\u5b9a\u7684\u53ef\u4ee5\u662f\u8fd9\u4e2a\u5217\u8868\u4e2d\u4efb\u610f\u4e00\u4e2a\u9876\u70b9\u7684\u6307\u9488\uff0c\u5e76\u4e0d\u4e00\u5b9a\u662f\u8fd9\u4e2a\u5217\u8868\u4e2d\u6700\u5c0f\u5143\u7d20\u7684\u6307\u9488\u3002

\n\n

\u5982\u679c\u6709\u591a\u4e2a\u6ee1\u8db3\u6761\u4ef6\u7684\u63d2\u5165\u4f4d\u7f6e\uff0c\u4f60\u53ef\u4ee5\u9009\u62e9\u4efb\u610f\u4e00\u4e2a\u4f4d\u7f6e\u63d2\u5165\u65b0\u7684\u503c\uff0c\u63d2\u5165\u540e\u6574\u4e2a\u5217\u8868\u4ecd\u7136\u4fdd\u6301\u6709\u5e8f\u3002

\n\n

\u5982\u679c\u5217\u8868\u4e3a\u7a7a\uff08\u7ed9\u5b9a\u7684\u8282\u70b9\u662f null\uff09\uff0c\u4f60\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u5faa\u73af\u6709\u5e8f\u5217\u8868\u5e76\u8fd4\u56de\u8fd9\u4e2a\u8282\u70b9\u3002\u5426\u5219\u3002\u8bf7\u8fd4\u56de\u539f\u5148\u7ed9\u5b9a\u7684\u8282\u70b9\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\"\"
\n\u00a0\n
\n\u8f93\u5165\uff1ahead = [3,4,1], insertVal = 2\n\u8f93\u51fa\uff1a[3,4,1,2]\n\u89e3\u91ca\uff1a\u5728\u4e0a\u56fe\u4e2d\uff0c\u6709\u4e00\u4e2a\u5305\u542b\u4e09\u4e2a\u5143\u7d20\u7684\u5faa\u73af\u6709\u5e8f\u5217\u8868\uff0c\u4f60\u83b7\u5f97\u503c\u4e3a 3 \u7684\u8282\u70b9\u7684\u6307\u9488\uff0c\u6211\u4eec\u9700\u8981\u5411\u8868\u4e2d\u63d2\u5165\u5143\u7d20 2 \u3002\u65b0\u63d2\u5165\u7684\u8282\u70b9\u5e94\u8be5\u5728 1 \u548c 3 \u4e4b\u95f4\uff0c\u63d2\u5165\u4e4b\u540e\uff0c\u6574\u4e2a\u5217\u8868\u5982\u4e0a\u56fe\u6240\u793a\uff0c\u6700\u540e\u8fd4\u56de\u8282\u70b9 3 \u3002\n\n\"\"\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1ahead = [], insertVal = 1\n\u8f93\u51fa\uff1a[1]\n\u89e3\u91ca\uff1a\u5217\u8868\u4e3a\u7a7a\uff08\u7ed9\u5b9a\u7684\u8282\u70b9\u662f null\uff09\uff0c\u521b\u5efa\u4e00\u4e2a\u5faa\u73af\u6709\u5e8f\u5217\u8868\u5e76\u8fd4\u56de\u8fd9\u4e2a\u8282\u70b9\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1ahead = [1], insertVal = 0\n\u8f93\u51fa\uff1a[1,0]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 0 <= Number of Nodes <= 5 * 10^4
  • \n\t
  • -10^6 <= Node.val <= 10^6
  • \n\t
  • -10^6 <=\u00a0insertVal <= 10^6
  • \n
\n", "tags_en": ["Linked List"], "tags_cn": ["\u94fe\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* next;\n\n Node() {}\n\n Node(int _val) {\n val = _val;\n next = NULL;\n }\n\n Node(int _val, Node* _next) {\n val = _val;\n next = _next;\n }\n};\n*/\n\nclass Solution {\npublic:\n Node* insert(Node* head, int insertVal) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/*\n// Definition for a Node.\nclass Node {\n public int val;\n public Node next;\n\n public Node() {}\n\n public Node(int _val) {\n val = _val;\n }\n\n public Node(int _val, Node _next) {\n val = _val;\n next = _next;\n }\n};\n*/\n\nclass Solution {\n public Node insert(Node head, int insertVal) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "\"\"\"\n# Definition for a Node.\nclass Node(object):\n def __init__(self, val=None, next=None):\n self.val = val\n self.next = next\n\"\"\"\n\nclass Solution(object):\n def insert(self, head, insertVal):\n \"\"\"\n :type head: Node\n :type insertVal: int\n :rtype: Node\n \"\"\"\n\t\t", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "\"\"\"\n# Definition for a Node.\nclass Node:\n def __init__(self, val=None, next=None):\n self.val = val\n self.next = next\n\"\"\"\n\nclass Solution:\n def insert(self, head: 'Node', insertVal: int) -> 'Node':\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a Node.\n * struct Node {\n * int val;\n * struct TreeNode *next;\n * };\n */\n\nstruct Node* insert(struct Node* head, int insertVal) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/*\n// Definition for a Node.\npublic class Node {\n public int val;\n public Node next;\n\n public Node() {}\n\n public Node(int _val) {\n val = _val;\n next = null;\n }\n\n public Node(int _val, Node _next) {\n val = _val;\n next = _next;\n }\n}\n*/\n\npublic class Solution {\n public Node Insert(Node head, int insertVal) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // Definition for a Node.\n * function Node(val, next) {\n * this.val = val;\n * this.next = next;\n * };\n */\n\n/**\n * @param {Node} head\n * @param {number} insertVal\n * @return {Node}\n */\nvar insert = function(head, insertVal) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a Node.\n# class Node\n# attr_accessor :val, :next\n# def initialize(val=nil, next_=nil)\n# @val = val\n# @next = next_\n# end\n# end\n\n# @param {Node} head\n# @param {Integer} insertVal\n# @return {Node}\ndef insert(head, insertVal)\n\t\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a Node.\n * public class Node {\n * public var val: Int\n * public var next: Node?\n * public init(_ val: Int) {\n * self.val = val\n * self.next = nil\n * }\n * }\n */\n\nclass Solution {\n func insert(_ head: Node?, _ insertVal: Int) -> Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a Node.\n * type Node struct {\n * Val int\n * Next *Node\n * }\n */\n\nfunc insert(aNode *Node, x int) *Node {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a Node.\n * class Node(var _value: Int) {\n * var value: Int = _value\n * var next: Node = null\n * }\n */\n\nobject Solution {\n def insert(head: Node, insertVal: Int): Node = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a Node.\n * class Node(var `val`: Int) {\n * var next: Node? = null\n * }\n */\n\nclass Solution {\n fun insert(head: Node?, insertVal: Int): Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a Node.\n * class Node {\n * public $val = null;\n * public $next = null;\n * function __construct($val = 0) {\n * $this->val = $val;\n * $this->next = null;\n * }\n * }\n */\n\nclass Solution {\n /**\n * @param Node $root\n * @param Integer $insertVal\n * @return Node\n */\n function insert($head, $insertVal) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for node.\n * class Node {\n * val: number\n * next: Node | null\n * constructor(val?: number, next?: Node) {\n * this.val = (val===undefined ? 0 : val);\n * this.next = (next===undefined ? null : next);\n * }\n * }\n */\n\nfunction insert(head: Node | null, insertVal: number): Node | null {\n\t\n}", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0708](https://leetcode-cn.com/problems/insert-into-a-sorted-circular-linked-list)", "[\u5faa\u73af\u6709\u5e8f\u5217\u8868\u7684\u63d2\u5165](/solution/0700-0799/0708.Insert%20into%20a%20Sorted%20Circular%20Linked%20List/README.md)", "`\u94fe\u8868`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0708](https://leetcode.com/problems/insert-into-a-sorted-circular-linked-list)", "[Insert into a Sorted Circular Linked List](/solution/0700-0799/0708.Insert%20into%20a%20Sorted%20Circular%20Linked%20List/README_EN.md)", "`Linked List`", "Medium", "\ud83d\udd12"]}, {"question_id": "0843", "frontend_question_id": "0823", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/binary-trees-with-factors", "url_en": "https://leetcode.com/problems/binary-trees-with-factors", "relative_path_cn": "/solution/0800-0899/0823.Binary%20Trees%20With%20Factors/README.md", "relative_path_en": "/solution/0800-0899/0823.Binary%20Trees%20With%20Factors/README_EN.md", "title_cn": "\u5e26\u56e0\u5b50\u7684\u4e8c\u53c9\u6811", "title_en": "Binary Trees With Factors", "question_title_slug": "binary-trees-with-factors", "content_en": "

Given an array of unique integers, arr, where each integer arr[i] is strictly greater than 1.

\n\n

We make a binary tree using these integers, and each number may be used for any number of times. Each non-leaf node's value should be equal to the product of the values of its children.

\n\n

Return the number of binary trees we can make. The answer may be too large so return the answer modulo 109 + 7.

\n\n

 

\n

Example 1:

\n\n
\nInput: arr = [2,4]\nOutput: 3\nExplanation: We can make these trees: [2], [4], [4, 2, 2]
\n\n

Example 2:

\n\n
\nInput: arr = [2,4,5,10]\nOutput: 7\nExplanation: We can make these trees: [2], [4], [5], [10], [4, 2, 2], [10, 2, 5], [10, 5, 2].
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= arr.length <= 1000
  • \n\t
  • 2 <= arr[i] <= 109
  • \n\t
  • All the values of arr are unique.
  • \n
\n", "content_cn": "

\u7ed9\u51fa\u4e00\u4e2a\u542b\u6709\u4e0d\u91cd\u590d\u6574\u6570\u5143\u7d20\u7684\u6570\u7ec4\uff0c\u6bcf\u4e2a\u6574\u6570\u5747\u5927\u4e8e 1\u3002

\n\n

\u6211\u4eec\u7528\u8fd9\u4e9b\u6574\u6570\u6765\u6784\u5efa\u4e8c\u53c9\u6811\uff0c\u6bcf\u4e2a\u6574\u6570\u53ef\u4ee5\u4f7f\u7528\u4efb\u610f\u6b21\u6570\u3002

\n\n

\u5176\u4e2d\uff1a\u6bcf\u4e2a\u975e\u53f6\u7ed3\u70b9\u7684\u503c\u5e94\u7b49\u4e8e\u5b83\u7684\u4e24\u4e2a\u5b50\u7ed3\u70b9\u7684\u503c\u7684\u4e58\u79ef\u3002

\n\n

\u6ee1\u8db3\u6761\u4ef6\u7684\u4e8c\u53c9\u6811\u4e00\u5171\u6709\u591a\u5c11\u4e2a\uff1f\u8fd4\u56de\u7684\u7ed3\u679c\u5e94\u6a21\u9664 10 ** 9 + 7\u3002

\n\n

 

\n\n

\u793a\u4f8b 1:

\n\n
\n\u8f93\u5165: A = [2, 4]\n\u8f93\u51fa: 3\n\u89e3\u91ca: \u6211\u4eec\u53ef\u4ee5\u5f97\u5230\u8fd9\u4e9b\u4e8c\u53c9\u6811: [2], [4], [4, 2, 2]
\n\n

\u793a\u4f8b 2:

\n\n
\n\u8f93\u5165: A = [2, 4, 5, 10]\n\u8f93\u51fa: 7\n\u89e3\u91ca: \u6211\u4eec\u53ef\u4ee5\u5f97\u5230\u8fd9\u4e9b\u4e8c\u53c9\u6811: [2], [4], [5], [10], [4, 2, 2], [10, 2, 5], [10, 5, 2].
\n\n

 

\n\n

\u63d0\u793a:

\n\n
    \n\t
  1. 1 <= A.length <= 1000.
  2. \n\t
  3. 2 <= A[i] <= 10 ^ 9.
  4. \n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numFactoredBinaryTrees(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numFactoredBinaryTrees(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numFactoredBinaryTrees(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numFactoredBinaryTrees(self, arr: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numFactoredBinaryTrees(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumFactoredBinaryTrees(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar numFactoredBinaryTrees = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef num_factored_binary_trees(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numFactoredBinaryTrees(_ arr: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numFactoredBinaryTrees(arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numFactoredBinaryTrees(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numFactoredBinaryTrees(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_factored_binary_trees(arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function numFactoredBinaryTrees($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numFactoredBinaryTrees(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-factored-binary-trees arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0823](https://leetcode-cn.com/problems/binary-trees-with-factors)", "[\u5e26\u56e0\u5b50\u7684\u4e8c\u53c9\u6811](/solution/0800-0899/0823.Binary%20Trees%20With%20Factors/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0823](https://leetcode.com/problems/binary-trees-with-factors)", "[Binary Trees With Factors](/solution/0800-0899/0823.Binary%20Trees%20With%20Factors/README_EN.md)", "", "Medium", ""]}, {"question_id": "0842", "frontend_question_id": "0822", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/card-flipping-game", "url_en": "https://leetcode.com/problems/card-flipping-game", "relative_path_cn": "/solution/0800-0899/0822.Card%20Flipping%20Game/README.md", "relative_path_en": "/solution/0800-0899/0822.Card%20Flipping%20Game/README_EN.md", "title_cn": "\u7ffb\u8f6c\u5361\u7247\u6e38\u620f", "title_en": "Card Flipping Game", "question_title_slug": "card-flipping-game", "content_en": "

On a table are N cards, with a positive integer printed on the front and back of each card (possibly different).

\r\n\r\n

We flip any number of cards, and after we choose one card. 

\r\n\r\n

If the number X on the back of the chosen card is not on the front of any card, then this number X is good.

\r\n\r\n

What is the smallest number that is good?  If no number is good, output 0.

\r\n\r\n

Here, fronts[i] and backs[i] represent the number on the front and back of card i

\r\n\r\n

A flip swaps the front and back numbers, so the value on the front is now on the back and vice versa.

\r\n\r\n

Example:

\r\n\r\n
\r\nInput: fronts = [1,2,4,4,7], backs = [1,3,4,1,3]\r\nOutput: 2\r\nExplanation: If we flip the second card, the fronts are [1,3,4,4,7] and the backs are [1,2,4,1,3].\r\nWe choose the second card, which has number 2 on the back, and it isn't on the front of any card, so 2 is good.
\r\n\r\n

 

\r\n\r\n

Note:

\r\n\r\n
    \r\n\t
  1. 1 <= fronts.length == backs.length <= 1000.
  2. \r\n\t
  3. 1 <= fronts[i] <= 2000.
  4. \r\n\t
  5. 1 <= backs[i] <= 2000.
  6. \r\n
\r\n", "content_cn": "

\u5728\u684c\u5b50\u4e0a\u6709 N \u5f20\u5361\u7247\uff0c\u6bcf\u5f20\u5361\u7247\u7684\u6b63\u9762\u548c\u80cc\u9762\u90fd\u5199\u7740\u4e00\u4e2a\u6b63\u6570\uff08\u6b63\u9762\u4e0e\u80cc\u9762\u4e0a\u7684\u6570\u6709\u53ef\u80fd\u4e0d\u4e00\u6837\uff09\u3002

\n\n

\u6211\u4eec\u53ef\u4ee5\u5148\u7ffb\u8f6c\u4efb\u610f\u5f20\u5361\u7247\uff0c\u7136\u540e\u9009\u62e9\u5176\u4e2d\u4e00\u5f20\u5361\u7247\u3002

\n\n

\u5982\u679c\u9009\u4e2d\u7684\u90a3\u5f20\u5361\u7247\u80cc\u9762\u7684\u6570\u5b57 X \u4e0e\u4efb\u610f\u4e00\u5f20\u5361\u7247\u7684\u6b63\u9762\u7684\u6570\u5b57\u90fd\u4e0d\u540c\uff0c\u90a3\u4e48\u8fd9\u4e2a\u6570\u5b57\u662f\u6211\u4eec\u60f3\u8981\u7684\u6570\u5b57\u3002

\n\n

\u54ea\u4e2a\u6570\u662f\u8fd9\u4e9b\u60f3\u8981\u7684\u6570\u5b57\u4e2d\u6700\u5c0f\u7684\u6570\uff08\u627e\u5230\u8fd9\u4e9b\u6570\u4e2d\u7684\u6700\u5c0f\u503c\uff09\u5462\uff1f\u5982\u679c\u6ca1\u6709\u4e00\u4e2a\u6570\u5b57\u7b26\u5408\u8981\u6c42\u7684\uff0c\u8f93\u51fa 0\u3002

\n\n

\u5176\u4e2d, fronts[i] \u548c backs[i] \u5206\u522b\u4ee3\u8868\u7b2c i \u5f20\u5361\u7247\u7684\u6b63\u9762\u548c\u80cc\u9762\u7684\u6570\u5b57\u3002

\n\n

\u5982\u679c\u6211\u4eec\u901a\u8fc7\u7ffb\u8f6c\u5361\u7247\u6765\u4ea4\u6362\u6b63\u9762\u4e0e\u80cc\u9762\u4e0a\u7684\u6570\uff0c\u90a3\u4e48\u5f53\u521d\u5728\u6b63\u9762\u7684\u6570\u5c31\u53d8\u6210\u80cc\u9762\u7684\u6570\uff0c\u80cc\u9762\u7684\u6570\u5c31\u53d8\u6210\u6b63\u9762\u7684\u6570\u3002

\n\n

\u793a\u4f8b\uff1a

\n\n
\n\u8f93\u5165\uff1afronts = [1,2,4,4,7], backs = [1,3,4,1,3]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5047\u8bbe\u6211\u4eec\u7ffb\u8f6c\u7b2c\u4e8c\u5f20\u5361\u7247\uff0c\u90a3\u4e48\u5728\u6b63\u9762\u7684\u6570\u53d8\u6210\u4e86 [1,3,4,4,7] \uff0c \u80cc\u9762\u7684\u6570\u53d8\u6210\u4e86 [1,2,4,1,3]\u3002\n\u63a5\u7740\u6211\u4eec\u9009\u62e9\u7b2c\u4e8c\u5f20\u5361\u7247\uff0c\u56e0\u4e3a\u73b0\u5728\u8be5\u5361\u7247\u7684\u80cc\u9762\u7684\u6570\u662f 2\uff0c2 \u4e0e\u4efb\u610f\u5361\u7247\u4e0a\u6b63\u9762\u7684\u6570\u90fd\u4e0d\u540c\uff0c\u6240\u4ee5 2 \u5c31\u662f\u6211\u4eec\u60f3\u8981\u7684\u6570\u5b57\u3002
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. 1 <= fronts.length == backs.length <= 1000
  2. \n\t
  3. 1 <= fronts[i] <= 2000
  4. \n\t
  5. 1 <= backs[i] <= 2000
  6. \n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int flipgame(vector& fronts, vector& backs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int flipgame(int[] fronts, int[] backs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def flipgame(self, fronts, backs):\n \"\"\"\n :type fronts: List[int]\n :type backs: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def flipgame(self, fronts: List[int], backs: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint flipgame(int* fronts, int frontsSize, int* backs, int backsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int Flipgame(int[] fronts, int[] backs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} fronts\n * @param {number[]} backs\n * @return {number}\n */\nvar flipgame = function(fronts, backs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} fronts\n# @param {Integer[]} backs\n# @return {Integer}\ndef flipgame(fronts, backs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func flipgame(_ fronts: [Int], _ backs: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func flipgame(fronts []int, backs []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def flipgame(fronts: Array[Int], backs: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun flipgame(fronts: IntArray, backs: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn flipgame(fronts: Vec, backs: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $fronts\n * @param Integer[] $backs\n * @return Integer\n */\n function flipgame($fronts, $backs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function flipgame(fronts: number[], backs: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (flipgame fronts backs)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0822](https://leetcode-cn.com/problems/card-flipping-game)", "[\u7ffb\u8f6c\u5361\u7247\u6e38\u620f](/solution/0800-0899/0822.Card%20Flipping%20Game/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0822](https://leetcode.com/problems/card-flipping-game)", "[Card Flipping Game](/solution/0800-0899/0822.Card%20Flipping%20Game/README_EN.md)", "", "Medium", ""]}, {"question_id": "0841", "frontend_question_id": "0821", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/shortest-distance-to-a-character", "url_en": "https://leetcode.com/problems/shortest-distance-to-a-character", "relative_path_cn": "/solution/0800-0899/0821.Shortest%20Distance%20to%20a%20Character/README.md", "relative_path_en": "/solution/0800-0899/0821.Shortest%20Distance%20to%20a%20Character/README_EN.md", "title_cn": "\u5b57\u7b26\u7684\u6700\u77ed\u8ddd\u79bb", "title_en": "Shortest Distance to a Character", "question_title_slug": "shortest-distance-to-a-character", "content_en": "

Given a string s and a character c that occurs in s, return an array of integers answer where answer.length == s.length and answer[i] is the distance from index i to the closest occurrence of character c in s.

\n\n

The distance between two indices i and j is abs(i - j), where abs is the absolute value function.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "loveleetcode", c = "e"\nOutput: [3,2,1,0,1,0,0,1,2,2,1,0]\nExplanation: The character 'e' appears at indices 3, 5, 6, and 11 (0-indexed).\nThe closest occurrence of 'e' for index 0 is at index 3, so the distance is abs(0 - 3) = 3.\nThe closest occurrence of 'e' for index 1 is at index 3, so the distance is abs(1 - 3) = 3.\nFor index 4, there is a tie between the 'e' at index 3 and the 'e' at index 5, but the distance is still the same: abs(4 - 3) == abs(4 - 5) = 1.\nThe closest occurrence of 'e' for index 8 is at index 6, so the distance is abs(8 - 6) = 2.\n
\n\n

Example 2:

\n\n
\nInput: s = "aaab", c = "b"\nOutput: [3,2,1,0]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 104
  • \n\t
  • s[i] and c are lowercase English letters.
  • \n\t
  • It is guaranteed that c occurs at least once in s.
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \u548c\u4e00\u4e2a\u5b57\u7b26 c \uff0c\u4e14 c \u662f s \u4e2d\u51fa\u73b0\u8fc7\u7684\u5b57\u7b26\u3002

\n\n

\u8fd4\u56de\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 answer \uff0c\u5176\u4e2d answer.length == s.length \u4e14 answer[i] \u662f s \u4e2d\u4ece\u4e0b\u6807 i \u5230\u79bb\u5b83 \u6700\u8fd1 \u7684\u5b57\u7b26 c \u7684 \u8ddd\u79bb \u3002

\n\n

\u4e24\u4e2a\u4e0b\u6807\u00a0i \u548c j \u4e4b\u95f4\u7684 \u8ddd\u79bb \u4e3a abs(i - j) \uff0c\u5176\u4e2d abs \u662f\u7edd\u5bf9\u503c\u51fd\u6570\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"loveleetcode\", c = \"e\"\n\u8f93\u51fa\uff1a[3,2,1,0,1,0,0,1,2,2,1,0]\n\u89e3\u91ca\uff1a\u5b57\u7b26 'e' \u51fa\u73b0\u5728\u4e0b\u6807 3\u30015\u30016 \u548c 11 \u5904\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\u8ba1\u6570\uff09\u3002\n\u8ddd\u4e0b\u6807 0 \u6700\u8fd1\u7684 'e' \u51fa\u73b0\u5728\u4e0b\u6807 3 \uff0c\u6240\u4ee5\u8ddd\u79bb\u4e3a abs(0 - 3) = 3 \u3002\n\u8ddd\u4e0b\u6807 1 \u6700\u8fd1\u7684 'e' \u51fa\u73b0\u5728\u4e0b\u6807 3 \uff0c\u6240\u4ee5\u8ddd\u79bb\u4e3a abs(1 - 3) = 3 \u3002\n\u5bf9\u4e8e\u4e0b\u6807 4 \uff0c\u51fa\u73b0\u5728\u4e0b\u6807 3 \u548c\u4e0b\u6807 5 \u5904\u7684 'e' \u90fd\u79bb\u5b83\u6700\u8fd1\uff0c\u4f46\u8ddd\u79bb\u662f\u4e00\u6837\u7684 abs(4 - 3) == abs(4 - 5) = 1 \u3002\n\u8ddd\u4e0b\u6807 8 \u6700\u8fd1\u7684 'e' \u51fa\u73b0\u5728\u4e0b\u6807 6 \uff0c\u6240\u4ee5\u8ddd\u79bb\u4e3a abs(8 - 6) = 2 \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"aaab\", c = \"b\"\n\u8f93\u51fa\uff1a[3,2,1,0]\n
\n\n

\u00a0

\n\u63d0\u793a\uff1a\n\n
    \n\t
  • 1 <= s.length <= 104
  • \n\t
  • s[i] \u548c c \u5747\u4e3a\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd
  • \n\t
  • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1 c \u5728 s \u4e2d\u81f3\u5c11\u51fa\u73b0\u4e00\u6b21
  • \n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector shortestToChar(string s, char c) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] shortestToChar(String s, char c) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def shortestToChar(self, s, c):\n \"\"\"\n :type s: str\n :type c: str\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def shortestToChar(self, s: str, c: str) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* shortestToChar(char * s, char c, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] ShortestToChar(string s, char c) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {character} c\n * @return {number[]}\n */\nvar shortestToChar = function(s, c) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Character} c\n# @return {Integer[]}\ndef shortest_to_char(s, c)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func shortestToChar(_ s: String, _ c: Character) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func shortestToChar(s string, c byte) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def shortestToChar(s: String, c: Char): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun shortestToChar(s: String, c: Char): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn shortest_to_char(s: String, c: char) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String $c\n * @return Integer[]\n */\n function shortestToChar($s, $c) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function shortestToChar(s: string, c: string): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (shortest-to-char s c)\n (-> string? char? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0821](https://leetcode-cn.com/problems/shortest-distance-to-a-character)", "[\u5b57\u7b26\u7684\u6700\u77ed\u8ddd\u79bb](/solution/0800-0899/0821.Shortest%20Distance%20to%20a%20Character/README.md)", "", "\u7b80\u5355", ""], "md_table_row_en": ["[0821](https://leetcode.com/problems/shortest-distance-to-a-character)", "[Shortest Distance to a Character](/solution/0800-0899/0821.Shortest%20Distance%20to%20a%20Character/README_EN.md)", "", "Easy", ""]}, {"question_id": "0839", "frontend_question_id": "0820", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/short-encoding-of-words", "url_en": "https://leetcode.com/problems/short-encoding-of-words", "relative_path_cn": "/solution/0800-0899/0820.Short%20Encoding%20of%20Words/README.md", "relative_path_en": "/solution/0800-0899/0820.Short%20Encoding%20of%20Words/README_EN.md", "title_cn": "\u5355\u8bcd\u7684\u538b\u7f29\u7f16\u7801", "title_en": "Short Encoding of Words", "question_title_slug": "short-encoding-of-words", "content_en": "

A valid encoding of an array of words is any reference string s and array of indices indices such that:

\n\n
    \n\t
  • words.length == indices.length
  • \n\t
  • The reference string s ends with the '#' character.
  • \n\t
  • For each index indices[i], the substring of s starting from indices[i] and up to (but not including) the next '#' character is equal to words[i].
  • \n
\n\n

Given an array of words, return the length of the shortest reference string s possible of any valid encoding of words.

\n\n

 

\n

Example 1:

\n\n
\nInput: words = ["time", "me", "bell"]\nOutput: 10\nExplanation: A valid encoding would be s = "time#bell#" and indices = [0, 2, 5].\nwords[0] = "time", the substring of s starting from indices[0] = 0 to the next '#' is underlined in "time#bell#"\nwords[1] = "me", the substring of s starting from indices[1] = 2 to the next '#' is underlined in "time#bell#"\nwords[2] = "bell", the substring of s starting from indices[2] = 5 to the next '#' is underlined in "time#bell#"\n
\n\n

Example 2:

\n\n
\nInput: words = ["t"]\nOutput: 2\nExplanation: A valid encoding would be s = "t#" and indices = [0].\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= words.length <= 2000
  • \n\t
  • 1 <= words[i].length <= 7
  • \n\t
  • words[i] consists of only lowercase letters.
  • \n
\n", "content_cn": "

\u5355\u8bcd\u6570\u7ec4\u00a0words \u7684 \u6709\u6548\u7f16\u7801 \u7531\u4efb\u610f\u52a9\u8bb0\u5b57\u7b26\u4e32 s \u548c\u4e0b\u6807\u6570\u7ec4 indices \u7ec4\u6210\uff0c\u4e14\u6ee1\u8db3\uff1a

\n\n
    \n\t
  • words.length == indices.length
  • \n\t
  • \u52a9\u8bb0\u5b57\u7b26\u4e32 s \u4ee5 '#' \u5b57\u7b26\u7ed3\u5c3e
  • \n\t
  • \u5bf9\u4e8e\u6bcf\u4e2a\u4e0b\u6807 indices[i] \uff0cs \u7684\u4e00\u4e2a\u4ece indices[i] \u5f00\u59cb\u3001\u5230\u4e0b\u4e00\u4e2a '#' \u5b57\u7b26\u7ed3\u675f\uff08\u4f46\u4e0d\u5305\u62ec '#'\uff09\u7684 \u5b50\u5b57\u7b26\u4e32 \u6070\u597d\u4e0e words[i] \u76f8\u7b49
  • \n
\n\n

\u7ed9\u4f60\u4e00\u4e2a\u5355\u8bcd\u6570\u7ec4\u00a0words \uff0c\u8fd4\u56de\u6210\u529f\u5bf9 words \u8fdb\u884c\u7f16\u7801\u7684\u6700\u5c0f\u52a9\u8bb0\u5b57\u7b26\u4e32 s \u7684\u957f\u5ea6 \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1awords = [\"time\", \"me\", \"bell\"]\n\u8f93\u51fa\uff1a10\n\u89e3\u91ca\uff1a\u4e00\u7ec4\u6709\u6548\u7f16\u7801\u4e3a s = \"time#bell#\" \u548c indices = [0, 2, 5] \u3002\nwords[0] = \"time\" \uff0cs \u5f00\u59cb\u4e8e indices[0] = 0 \u5230\u4e0b\u4e00\u4e2a '#' \u7ed3\u675f\u7684\u5b50\u5b57\u7b26\u4e32\uff0c\u5982\u52a0\u7c97\u90e8\u5206\u6240\u793a \"time#bell#\"\nwords[1] = \"me\" \uff0cs \u5f00\u59cb\u4e8e indices[1] = 2 \u5230\u4e0b\u4e00\u4e2a '#' \u7ed3\u675f\u7684\u5b50\u5b57\u7b26\u4e32\uff0c\u5982\u52a0\u7c97\u90e8\u5206\u6240\u793a \"time#bell#\"\nwords[2] = \"bell\" \uff0cs \u5f00\u59cb\u4e8e indices[2] = 5 \u5230\u4e0b\u4e00\u4e2a '#' \u7ed3\u675f\u7684\u5b50\u5b57\u7b26\u4e32\uff0c\u5982\u52a0\u7c97\u90e8\u5206\u6240\u793a \"time#bell#\"\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1awords = [\"t\"]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u4e00\u7ec4\u6709\u6548\u7f16\u7801\u4e3a s = \"t#\" \u548c indices = [0] \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= words.length <= 2000
  • \n\t
  • 1 <= words[i].length <= 7
  • \n\t
  • words[i] \u4ec5\u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210
  • \n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minimumLengthEncoding(vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minimumLengthEncoding(String[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimumLengthEncoding(self, words):\n \"\"\"\n :type words: List[str]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimumLengthEncoding(self, words: List[str]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minimumLengthEncoding(char ** words, int wordsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinimumLengthEncoding(string[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @return {number}\n */\nvar minimumLengthEncoding = function(words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @return {Integer}\ndef minimum_length_encoding(words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimumLengthEncoding(_ words: [String]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimumLengthEncoding(words []string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimumLengthEncoding(words: Array[String]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimumLengthEncoding(words: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimum_length_encoding(words: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @return Integer\n */\n function minimumLengthEncoding($words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimumLengthEncoding(words: string[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimum-length-encoding words)\n (-> (listof string?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0820](https://leetcode-cn.com/problems/short-encoding-of-words)", "[\u5355\u8bcd\u7684\u538b\u7f29\u7f16\u7801](/solution/0800-0899/0820.Short%20Encoding%20of%20Words/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0820](https://leetcode.com/problems/short-encoding-of-words)", "[Short Encoding of Words](/solution/0800-0899/0820.Short%20Encoding%20of%20Words/README_EN.md)", "", "Medium", ""]}, {"question_id": "0838", "frontend_question_id": "0707", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/design-linked-list", "url_en": "https://leetcode.com/problems/design-linked-list", "relative_path_cn": "/solution/0700-0799/0707.Design%20Linked%20List/README.md", "relative_path_en": "/solution/0700-0799/0707.Design%20Linked%20List/README_EN.md", "title_cn": "\u8bbe\u8ba1\u94fe\u8868", "title_en": "Design Linked List", "question_title_slug": "design-linked-list", "content_en": "

Design your implementation of the linked list. You can choose to use a singly or doubly linked list.
\nA node in a singly linked list should have two attributes: val and next. val is the value of the current node, and next is a pointer/reference to the next node.
\nIf you want to use the doubly linked list, you will need one more attribute prev to indicate the previous node in the linked list. Assume all nodes in the linked list are 0-indexed.

\n\n

Implement the MyLinkedList class:

\n\n
    \n\t
  • MyLinkedList() Initializes the MyLinkedList object.
  • \n\t
  • int get(int index) Get the value of the indexth node in the linked list. If the index is invalid, return -1.
  • \n\t
  • void addAtHead(int val) Add a node of value val before the first element of the linked list. After the insertion, the new node will be the first node of the linked list.
  • \n\t
  • void addAtTail(int val) Append a node of value val as the last element of the linked list.
  • \n\t
  • void addAtIndex(int index, int val) Add a node of value val before the indexth node in the linked list. If index equals the length of the linked list, the node will be appended to the end of the linked list. If index is greater than the length, the node will not be inserted.
  • \n\t
  • void deleteAtIndex(int index) Delete the indexth node in the linked list, if the index is valid.
  • \n
\n\n

 

\n

Example 1:

\n\n
\nInput\n["MyLinkedList", "addAtHead", "addAtTail", "addAtIndex", "get", "deleteAtIndex", "get"]\n[[], [1], [3], [1, 2], [1], [1], [1]]\nOutput\n[null, null, null, null, 2, null, 3]\n\nExplanation\nMyLinkedList myLinkedList = new MyLinkedList();\nmyLinkedList.addAtHead(1);\nmyLinkedList.addAtTail(3);\nmyLinkedList.addAtIndex(1, 2);    // linked list becomes 1->2->3\nmyLinkedList.get(1);              // return 2\nmyLinkedList.deleteAtIndex(1);    // now the linked list is 1->3\nmyLinkedList.get(1);              // return 3\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 0 <= index, val <= 1000
  • \n\t
  • Please do not use the built-in LinkedList library.
  • \n\t
  • At most 2000 calls will be made to get, addAtHead, addAtTail, addAtIndex and deleteAtIndex.
  • \n
\n", "content_cn": "

\u8bbe\u8ba1\u94fe\u8868\u7684\u5b9e\u73b0\u3002\u60a8\u53ef\u4ee5\u9009\u62e9\u4f7f\u7528\u5355\u94fe\u8868\u6216\u53cc\u94fe\u8868\u3002\u5355\u94fe\u8868\u4e2d\u7684\u8282\u70b9\u5e94\u8be5\u5177\u6709\u4e24\u4e2a\u5c5e\u6027\uff1aval \u548c next\u3002val \u662f\u5f53\u524d\u8282\u70b9\u7684\u503c\uff0cnext \u662f\u6307\u5411\u4e0b\u4e00\u4e2a\u8282\u70b9\u7684\u6307\u9488/\u5f15\u7528\u3002\u5982\u679c\u8981\u4f7f\u7528\u53cc\u5411\u94fe\u8868\uff0c\u5219\u8fd8\u9700\u8981\u4e00\u4e2a\u5c5e\u6027 prev \u4ee5\u6307\u793a\u94fe\u8868\u4e2d\u7684\u4e0a\u4e00\u4e2a\u8282\u70b9\u3002\u5047\u8bbe\u94fe\u8868\u4e2d\u7684\u6240\u6709\u8282\u70b9\u90fd\u662f 0-index \u7684\u3002

\n\n

\u5728\u94fe\u8868\u7c7b\u4e2d\u5b9e\u73b0\u8fd9\u4e9b\u529f\u80fd\uff1a

\n\n
    \n\t
  • get(index)\uff1a\u83b7\u53d6\u94fe\u8868\u4e2d\u7b2c index \u4e2a\u8282\u70b9\u7684\u503c\u3002\u5982\u679c\u7d22\u5f15\u65e0\u6548\uff0c\u5219\u8fd4\u56de-1\u3002
  • \n\t
  • addAtHead(val)\uff1a\u5728\u94fe\u8868\u7684\u7b2c\u4e00\u4e2a\u5143\u7d20\u4e4b\u524d\u6dfb\u52a0\u4e00\u4e2a\u503c\u4e3a val \u7684\u8282\u70b9\u3002\u63d2\u5165\u540e\uff0c\u65b0\u8282\u70b9\u5c06\u6210\u4e3a\u94fe\u8868\u7684\u7b2c\u4e00\u4e2a\u8282\u70b9\u3002
  • \n\t
  • addAtTail(val)\uff1a\u5c06\u503c\u4e3a val \u7684\u8282\u70b9\u8ffd\u52a0\u5230\u94fe\u8868\u7684\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u3002
  • \n\t
  • addAtIndex(index,val)\uff1a\u5728\u94fe\u8868\u4e2d\u7684\u7b2c index \u4e2a\u8282\u70b9\u4e4b\u524d\u6dfb\u52a0\u503c\u4e3a val  \u7684\u8282\u70b9\u3002\u5982\u679c index \u7b49\u4e8e\u94fe\u8868\u7684\u957f\u5ea6\uff0c\u5219\u8be5\u8282\u70b9\u5c06\u9644\u52a0\u5230\u94fe\u8868\u7684\u672b\u5c3e\u3002\u5982\u679c index \u5927\u4e8e\u94fe\u8868\u957f\u5ea6\uff0c\u5219\u4e0d\u4f1a\u63d2\u5165\u8282\u70b9\u3002\u5982\u679cindex\u5c0f\u4e8e0\uff0c\u5219\u5728\u5934\u90e8\u63d2\u5165\u8282\u70b9\u3002
  • \n\t
  • deleteAtIndex(index)\uff1a\u5982\u679c\u7d22\u5f15 index \u6709\u6548\uff0c\u5219\u5220\u9664\u94fe\u8868\u4e2d\u7684\u7b2c index \u4e2a\u8282\u70b9\u3002
  • \n
\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
MyLinkedList linkedList = new MyLinkedList();\nlinkedList.addAtHead(1);\nlinkedList.addAtTail(3);\nlinkedList.addAtIndex(1,2);   //\u94fe\u8868\u53d8\u4e3a1-> 2-> 3\nlinkedList.get(1);            //\u8fd4\u56de2\nlinkedList.deleteAtIndex(1);  //\u73b0\u5728\u94fe\u8868\u662f1-> 3\nlinkedList.get(1);            //\u8fd4\u56de3\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u6240\u6709val\u503c\u90fd\u5728 [1, 1000] \u4e4b\u5185\u3002
  • \n\t
  • \u64cd\u4f5c\u6b21\u6570\u5c06\u5728  [1, 1000] \u4e4b\u5185\u3002
  • \n\t
  • \u8bf7\u4e0d\u8981\u4f7f\u7528\u5185\u7f6e\u7684 LinkedList \u5e93\u3002
  • \n
\n", "tags_en": ["Design", "Linked List"], "tags_cn": ["\u8bbe\u8ba1", "\u94fe\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class MyLinkedList {\npublic:\n /** Initialize your data structure here. */\n MyLinkedList() {\n\n }\n \n /** Get the value of the index-th node in the linked list. If the index is invalid, return -1. */\n int get(int index) {\n\n }\n \n /** Add a node of value val before the first element of the linked list. After the insertion, the new node will be the first node of the linked list. */\n void addAtHead(int val) {\n\n }\n \n /** Append a node of value val to the last element of the linked list. */\n void addAtTail(int val) {\n\n }\n \n /** Add a node of value val before the index-th node in the linked list. If index equals to the length of linked list, the node will be appended to the end of linked list. If index is greater than the length, the node will not be inserted. */\n void addAtIndex(int index, int val) {\n\n }\n \n /** Delete the index-th node in the linked list, if the index is valid. */\n void deleteAtIndex(int index) {\n\n }\n};\n\n/**\n * Your MyLinkedList object will be instantiated and called as such:\n * MyLinkedList* obj = new MyLinkedList();\n * int param_1 = obj->get(index);\n * obj->addAtHead(val);\n * obj->addAtTail(val);\n * obj->addAtIndex(index,val);\n * obj->deleteAtIndex(index);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class MyLinkedList {\n\n /** Initialize your data structure here. */\n public MyLinkedList() {\n\n }\n \n /** Get the value of the index-th node in the linked list. If the index is invalid, return -1. */\n public int get(int index) {\n\n }\n \n /** Add a node of value val before the first element of the linked list. After the insertion, the new node will be the first node of the linked list. */\n public void addAtHead(int val) {\n\n }\n \n /** Append a node of value val to the last element of the linked list. */\n public void addAtTail(int val) {\n\n }\n \n /** Add a node of value val before the index-th node in the linked list. If index equals to the length of linked list, the node will be appended to the end of linked list. If index is greater than the length, the node will not be inserted. */\n public void addAtIndex(int index, int val) {\n\n }\n \n /** Delete the index-th node in the linked list, if the index is valid. */\n public void deleteAtIndex(int index) {\n\n }\n}\n\n/**\n * Your MyLinkedList object will be instantiated and called as such:\n * MyLinkedList obj = new MyLinkedList();\n * int param_1 = obj.get(index);\n * obj.addAtHead(val);\n * obj.addAtTail(val);\n * obj.addAtIndex(index,val);\n * obj.deleteAtIndex(index);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class MyLinkedList(object):\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def get(self, index):\n \"\"\"\n Get the value of the index-th node in the linked list. If the index is invalid, return -1.\n :type index: int\n :rtype: int\n \"\"\"\n\n\n def addAtHead(self, val):\n \"\"\"\n Add a node of value val before the first element of the linked list. After the insertion, the new node will be the first node of the linked list.\n :type val: int\n :rtype: None\n \"\"\"\n\n\n def addAtTail(self, val):\n \"\"\"\n Append a node of value val to the last element of the linked list.\n :type val: int\n :rtype: None\n \"\"\"\n\n\n def addAtIndex(self, index, val):\n \"\"\"\n Add a node of value val before the index-th node in the linked list. If index equals to the length of linked list, the node will be appended to the end of linked list. If index is greater than the length, the node will not be inserted.\n :type index: int\n :type val: int\n :rtype: None\n \"\"\"\n\n\n def deleteAtIndex(self, index):\n \"\"\"\n Delete the index-th node in the linked list, if the index is valid.\n :type index: int\n :rtype: None\n \"\"\"\n\n\n\n# Your MyLinkedList object will be instantiated and called as such:\n# obj = MyLinkedList()\n# param_1 = obj.get(index)\n# obj.addAtHead(val)\n# obj.addAtTail(val)\n# obj.addAtIndex(index,val)\n# obj.deleteAtIndex(index)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class MyLinkedList:\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def get(self, index: int) -> int:\n \"\"\"\n Get the value of the index-th node in the linked list. If the index is invalid, return -1.\n \"\"\"\n\n\n def addAtHead(self, val: int) -> None:\n \"\"\"\n Add a node of value val before the first element of the linked list. After the insertion, the new node will be the first node of the linked list.\n \"\"\"\n\n\n def addAtTail(self, val: int) -> None:\n \"\"\"\n Append a node of value val to the last element of the linked list.\n \"\"\"\n\n\n def addAtIndex(self, index: int, val: int) -> None:\n \"\"\"\n Add a node of value val before the index-th node in the linked list. If index equals to the length of linked list, the node will be appended to the end of linked list. If index is greater than the length, the node will not be inserted.\n \"\"\"\n\n\n def deleteAtIndex(self, index: int) -> None:\n \"\"\"\n Delete the index-th node in the linked list, if the index is valid.\n \"\"\"\n\n\n\n# Your MyLinkedList object will be instantiated and called as such:\n# obj = MyLinkedList()\n# param_1 = obj.get(index)\n# obj.addAtHead(val)\n# obj.addAtTail(val)\n# obj.addAtIndex(index,val)\n# obj.deleteAtIndex(index)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} MyLinkedList;\n\n/** Initialize your data structure here. */\n\nMyLinkedList* myLinkedListCreate() {\n\n}\n\n/** Get the value of the index-th node in the linked list. If the index is invalid, return -1. */\nint myLinkedListGet(MyLinkedList* obj, int index) {\n\n}\n\n/** Add a node of value val before the first element of the linked list. After the insertion, the new node will be the first node of the linked list. */\nvoid myLinkedListAddAtHead(MyLinkedList* obj, int val) {\n\n}\n\n/** Append a node of value val to the last element of the linked list. */\nvoid myLinkedListAddAtTail(MyLinkedList* obj, int val) {\n\n}\n\n/** Add a node of value val before the index-th node in the linked list. If index equals to the length of linked list, the node will be appended to the end of linked list. If index is greater than the length, the node will not be inserted. */\nvoid myLinkedListAddAtIndex(MyLinkedList* obj, int index, int val) {\n\n}\n\n/** Delete the index-th node in the linked list, if the index is valid. */\nvoid myLinkedListDeleteAtIndex(MyLinkedList* obj, int index) {\n\n}\n\nvoid myLinkedListFree(MyLinkedList* obj) {\n\n}\n\n/**\n * Your MyLinkedList struct will be instantiated and called as such:\n * MyLinkedList* obj = myLinkedListCreate();\n * int param_1 = myLinkedListGet(obj, index);\n \n * myLinkedListAddAtHead(obj, val);\n \n * myLinkedListAddAtTail(obj, val);\n \n * myLinkedListAddAtIndex(obj, index, val);\n \n * myLinkedListDeleteAtIndex(obj, index);\n \n * myLinkedListFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class MyLinkedList {\n\n /** Initialize your data structure here. */\n public MyLinkedList() {\n\n }\n \n /** Get the value of the index-th node in the linked list. If the index is invalid, return -1. */\n public int Get(int index) {\n\n }\n \n /** Add a node of value val before the first element of the linked list. After the insertion, the new node will be the first node of the linked list. */\n public void AddAtHead(int val) {\n\n }\n \n /** Append a node of value val to the last element of the linked list. */\n public void AddAtTail(int val) {\n\n }\n \n /** Add a node of value val before the index-th node in the linked list. If index equals to the length of linked list, the node will be appended to the end of linked list. If index is greater than the length, the node will not be inserted. */\n public void AddAtIndex(int index, int val) {\n\n }\n \n /** Delete the index-th node in the linked list, if the index is valid. */\n public void DeleteAtIndex(int index) {\n\n }\n}\n\n/**\n * Your MyLinkedList object will be instantiated and called as such:\n * MyLinkedList obj = new MyLinkedList();\n * int param_1 = obj.Get(index);\n * obj.AddAtHead(val);\n * obj.AddAtTail(val);\n * obj.AddAtIndex(index,val);\n * obj.DeleteAtIndex(index);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Initialize your data structure here.\n */\nvar MyLinkedList = function() {\n\n};\n\n/**\n * Get the value of the index-th node in the linked list. If the index is invalid, return -1. \n * @param {number} index\n * @return {number}\n */\nMyLinkedList.prototype.get = function(index) {\n\n};\n\n/**\n * Add a node of value val before the first element of the linked list. After the insertion, the new node will be the first node of the linked list. \n * @param {number} val\n * @return {void}\n */\nMyLinkedList.prototype.addAtHead = function(val) {\n\n};\n\n/**\n * Append a node of value val to the last element of the linked list. \n * @param {number} val\n * @return {void}\n */\nMyLinkedList.prototype.addAtTail = function(val) {\n\n};\n\n/**\n * Add a node of value val before the index-th node in the linked list. If index equals to the length of linked list, the node will be appended to the end of linked list. If index is greater than the length, the node will not be inserted. \n * @param {number} index \n * @param {number} val\n * @return {void}\n */\nMyLinkedList.prototype.addAtIndex = function(index, val) {\n\n};\n\n/**\n * Delete the index-th node in the linked list, if the index is valid. \n * @param {number} index\n * @return {void}\n */\nMyLinkedList.prototype.deleteAtIndex = function(index) {\n\n};\n\n/**\n * Your MyLinkedList object will be instantiated and called as such:\n * var obj = new MyLinkedList()\n * var param_1 = obj.get(index)\n * obj.addAtHead(val)\n * obj.addAtTail(val)\n * obj.addAtIndex(index,val)\n * obj.deleteAtIndex(index)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class MyLinkedList\n\n=begin\n Initialize your data structure here.\n=end\n def initialize()\n\n end\n\n\n=begin\n Get the value of the index-th node in the linked list. If the index is invalid, return -1.\n :type index: Integer\n :rtype: Integer\n=end\n def get(index)\n\n end\n\n\n=begin\n Add a node of value val before the first element of the linked list. After the insertion, the new node will be the first node of the linked list.\n :type val: Integer\n :rtype: Void\n=end\n def add_at_head(val)\n\n end\n\n\n=begin\n Append a node of value val to the last element of the linked list.\n :type val: Integer\n :rtype: Void\n=end\n def add_at_tail(val)\n\n end\n\n\n=begin\n Add a node of value val before the index-th node in the linked list. If index equals to the length of linked list, the node will be appended to the end of linked list. If index is greater than the length, the node will not be inserted.\n :type index: Integer\n :type val: Integer\n :rtype: Void\n=end\n def add_at_index(index, val)\n\n end\n\n\n=begin\n Delete the index-th node in the linked list, if the index is valid.\n :type index: Integer\n :rtype: Void\n=end\n def delete_at_index(index)\n\n end\n\n\nend\n\n# Your MyLinkedList object will be instantiated and called as such:\n# obj = MyLinkedList.new()\n# param_1 = obj.get(index)\n# obj.add_at_head(val)\n# obj.add_at_tail(val)\n# obj.add_at_index(index, val)\n# obj.delete_at_index(index)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass MyLinkedList {\n\n /** Initialize your data structure here. */\n init() {\n\n }\n \n /** Get the value of the index-th node in the linked list. If the index is invalid, return -1. */\n func get(_ index: Int) -> Int {\n\n }\n \n /** Add a node of value val before the first element of the linked list. After the insertion, the new node will be the first node of the linked list. */\n func addAtHead(_ val: Int) {\n\n }\n \n /** Append a node of value val to the last element of the linked list. */\n func addAtTail(_ val: Int) {\n\n }\n \n /** Add a node of value val before the index-th node in the linked list. If index equals to the length of linked list, the node will be appended to the end of linked list. If index is greater than the length, the node will not be inserted. */\n func addAtIndex(_ index: Int, _ val: Int) {\n\n }\n \n /** Delete the index-th node in the linked list, if the index is valid. */\n func deleteAtIndex(_ index: Int) {\n\n }\n}\n\n/**\n * Your MyLinkedList object will be instantiated and called as such:\n * let obj = MyLinkedList()\n * let ret_1: Int = obj.get(index)\n * obj.addAtHead(val)\n * obj.addAtTail(val)\n * obj.addAtIndex(index, val)\n * obj.deleteAtIndex(index)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type MyLinkedList struct {\n\n}\n\n\n/** Initialize your data structure here. */\nfunc Constructor() MyLinkedList {\n\n}\n\n\n/** Get the value of the index-th node in the linked list. If the index is invalid, return -1. */\nfunc (this *MyLinkedList) Get(index int) int {\n\n}\n\n\n/** Add a node of value val before the first element of the linked list. After the insertion, the new node will be the first node of the linked list. */\nfunc (this *MyLinkedList) AddAtHead(val int) {\n\n}\n\n\n/** Append a node of value val to the last element of the linked list. */\nfunc (this *MyLinkedList) AddAtTail(val int) {\n\n}\n\n\n/** Add a node of value val before the index-th node in the linked list. If index equals to the length of linked list, the node will be appended to the end of linked list. If index is greater than the length, the node will not be inserted. */\nfunc (this *MyLinkedList) AddAtIndex(index int, val int) {\n\n}\n\n\n/** Delete the index-th node in the linked list, if the index is valid. */\nfunc (this *MyLinkedList) DeleteAtIndex(index int) {\n\n}\n\n\n/**\n * Your MyLinkedList object will be instantiated and called as such:\n * obj := Constructor();\n * param_1 := obj.Get(index);\n * obj.AddAtHead(val);\n * obj.AddAtTail(val);\n * obj.AddAtIndex(index,val);\n * obj.DeleteAtIndex(index);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class MyLinkedList() {\n\n /** Initialize your data structure here. */\n\n\n /** Get the value of the index-th node in the linked list. If the index is invalid, return -1. */\n def get(index: Int): Int = {\n\n }\n\n /** Add a node of value val before the first element of the linked list. After the insertion, the new node will be the first node of the linked list. */\n def addAtHead(`val`: Int) {\n\n }\n\n /** Append a node of value val to the last element of the linked list. */\n def addAtTail(`val`: Int) {\n\n }\n\n /** Add a node of value val before the index-th node in the linked list. If index equals to the length of linked list, the node will be appended to the end of linked list. If index is greater than the length, the node will not be inserted. */\n def addAtIndex(index: Int, `val`: Int) {\n\n }\n\n /** Delete the index-th node in the linked list, if the index is valid. */\n def deleteAtIndex(index: Int) {\n\n }\n\n}\n\n/**\n * Your MyLinkedList object will be instantiated and called as such:\n * var obj = new MyLinkedList()\n * var param_1 = obj.get(index)\n * obj.addAtHead(`val`)\n * obj.addAtTail(`val`)\n * obj.addAtIndex(index,`val`)\n * obj.deleteAtIndex(index)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class MyLinkedList() {\n\n /** Initialize your data structure here. */\n\n\n /** Get the value of the index-th node in the linked list. If the index is invalid, return -1. */\n fun get(index: Int): Int {\n\n }\n\n /** Add a node of value val before the first element of the linked list. After the insertion, the new node will be the first node of the linked list. */\n fun addAtHead(`val`: Int) {\n\n }\n\n /** Append a node of value val to the last element of the linked list. */\n fun addAtTail(`val`: Int) {\n\n }\n\n /** Add a node of value val before the index-th node in the linked list. If index equals to the length of linked list, the node will be appended to the end of linked list. If index is greater than the length, the node will not be inserted. */\n fun addAtIndex(index: Int, `val`: Int) {\n\n }\n\n /** Delete the index-th node in the linked list, if the index is valid. */\n fun deleteAtIndex(index: Int) {\n\n }\n\n}\n\n/**\n * Your MyLinkedList object will be instantiated and called as such:\n * var obj = MyLinkedList()\n * var param_1 = obj.get(index)\n * obj.addAtHead(`val`)\n * obj.addAtTail(`val`)\n * obj.addAtIndex(index,`val`)\n * obj.deleteAtIndex(index)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct MyLinkedList {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl MyLinkedList {\n\n /** Initialize your data structure here. */\n fn new() -> Self {\n\n }\n \n /** Get the value of the index-th node in the linked list. If the index is invalid, return -1. */\n fn get(&self, index: i32) -> i32 {\n\n }\n \n /** Add a node of value val before the first element of the linked list. After the insertion, the new node will be the first node of the linked list. */\n fn add_at_head(&self, val: i32) {\n\n }\n \n /** Append a node of value val to the last element of the linked list. */\n fn add_at_tail(&self, val: i32) {\n\n }\n \n /** Add a node of value val before the index-th node in the linked list. If index equals to the length of linked list, the node will be appended to the end of linked list. If index is greater than the length, the node will not be inserted. */\n fn add_at_index(&self, index: i32, val: i32) {\n\n }\n \n /** Delete the index-th node in the linked list, if the index is valid. */\n fn delete_at_index(&self, index: i32) {\n\n }\n}\n\n/**\n * Your MyLinkedList object will be instantiated and called as such:\n * let obj = MyLinkedList::new();\n * let ret_1: i32 = obj.get(index);\n * obj.add_at_head(val);\n * obj.add_at_tail(val);\n * obj.add_at_index(index, val);\n * obj.delete_at_index(index);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class MyLinkedList {\n /**\n * Initialize your data structure here.\n */\n function __construct() {\n\n }\n\n /**\n * Get the value of the index-th node in the linked list. If the index is invalid, return -1.\n * @param Integer $index\n * @return Integer\n */\n function get($index) {\n\n }\n\n /**\n * Add a node of value val before the first element of the linked list. After the insertion, the new node will be the first node of the linked list.\n * @param Integer $val\n * @return NULL\n */\n function addAtHead($val) {\n\n }\n\n /**\n * Append a node of value val to the last element of the linked list.\n * @param Integer $val\n * @return NULL\n */\n function addAtTail($val) {\n\n }\n\n /**\n * Add a node of value val before the index-th node in the linked list. If index equals to the length of linked list, the node will be appended to the end of linked list. If index is greater than the length, the node will not be inserted.\n * @param Integer $index\n * @param Integer $val\n * @return NULL\n */\n function addAtIndex($index, $val) {\n\n }\n\n /**\n * Delete the index-th node in the linked list, if the index is valid.\n * @param Integer $index\n * @return NULL\n */\n function deleteAtIndex($index) {\n\n }\n}\n\n/**\n * Your MyLinkedList object will be instantiated and called as such:\n * $obj = MyLinkedList();\n * $ret_1 = $obj->get($index);\n * $obj->addAtHead($val);\n * $obj->addAtTail($val);\n * $obj->addAtIndex($index, $val);\n * $obj->deleteAtIndex($index);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class MyLinkedList {\n constructor() {\n\n }\n\n get(index: number): number {\n\n }\n\n addAtHead(val: number): void {\n\n }\n\n addAtTail(val: number): void {\n\n }\n\n addAtIndex(index: number, val: number): void {\n\n }\n\n deleteAtIndex(index: number): void {\n\n }\n}\n\n/**\n * Your MyLinkedList object will be instantiated and called as such:\n * var obj = new MyLinkedList()\n * var param_1 = obj.get(index)\n * obj.addAtHead(val)\n * obj.addAtTail(val)\n * obj.addAtIndex(index,val)\n * obj.deleteAtIndex(index)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define my-linked-list%\n (class object%\n (super-new)\n (init-field)\n \n ; get : exact-integer? -> exact-integer?\n (define/public (get index)\n\n )\n ; add-at-head : exact-integer? -> void?\n (define/public (add-at-head val)\n\n )\n ; add-at-tail : exact-integer? -> void?\n (define/public (add-at-tail val)\n\n )\n ; add-at-index : exact-integer? exact-integer? -> void?\n (define/public (add-at-index index val)\n\n )\n ; delete-at-index : exact-integer? -> void?\n (define/public (delete-at-index index)\n\n )))\n\n;; Your my-linked-list% object will be instantiated and called as such:\n;; (define obj (new my-linked-list%))\n;; (define param_1 (send obj get index))\n;; (send obj add-at-head val)\n;; (send obj add-at-tail val)\n;; (send obj add-at-index index val)\n;; (send obj delete-at-index index)", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0707](https://leetcode-cn.com/problems/design-linked-list)", "[\u8bbe\u8ba1\u94fe\u8868](/solution/0700-0799/0707.Design%20Linked%20List/README.md)", "`\u8bbe\u8ba1`,`\u94fe\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0707](https://leetcode.com/problems/design-linked-list)", "[Design Linked List](/solution/0700-0799/0707.Design%20Linked%20List/README_EN.md)", "`Design`,`Linked List`", "Medium", ""]}, {"question_id": "0837", "frontend_question_id": "0819", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/most-common-word", "url_en": "https://leetcode.com/problems/most-common-word", "relative_path_cn": "/solution/0800-0899/0819.Most%20Common%20Word/README.md", "relative_path_en": "/solution/0800-0899/0819.Most%20Common%20Word/README_EN.md", "title_cn": "\u6700\u5e38\u89c1\u7684\u5355\u8bcd", "title_en": "Most Common Word", "question_title_slug": "most-common-word", "content_en": "

Given a string paragraph and a string array of the banned words banned, return the most frequent word that is not banned. It is guaranteed there is at least one word that is not banned, and that the answer is unique.

\n\n

The words in paragraph are case-insensitive and the answer should be returned in lowercase.

\n\n

 

\n

Example 1:

\n\n
\nInput: paragraph = "Bob hit a ball, the hit BALL flew far after it was hit.", banned = ["hit"]\nOutput: "ball"\nExplanation: \n"hit" occurs 3 times, but it is a banned word.\n"ball" occurs twice (and no other word does), so it is the most frequent non-banned word in the paragraph. \nNote that words in the paragraph are not case sensitive,\nthat punctuation is ignored (even if adjacent to words, such as "ball,"), \nand that "hit" isn't the answer even though it occurs more because it is banned.\n
\n\n

Example 2:

\n\n
\nInput: paragraph = "a.", banned = []\nOutput: "a"\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= paragraph.length <= 1000
  • \n\t
  • paragraph consists of English letters, space ' ', or one of the symbols: "!?',;.".
  • \n\t
  • 0 <= banned.length <= 100
  • \n\t
  • 1 <= banned[i].length <= 10
  • \n\t
  • banned[i] consists of only lowercase English letters.
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u6bb5\u843d (paragraph) \u548c\u4e00\u4e2a\u7981\u7528\u5355\u8bcd\u5217\u8868 (banned)\u3002\u8fd4\u56de\u51fa\u73b0\u6b21\u6570\u6700\u591a\uff0c\u540c\u65f6\u4e0d\u5728\u7981\u7528\u5217\u8868\u4e2d\u7684\u5355\u8bcd\u3002

\n\n

\u9898\u76ee\u4fdd\u8bc1\u81f3\u5c11\u6709\u4e00\u4e2a\u8bcd\u4e0d\u5728\u7981\u7528\u5217\u8868\u4e2d\uff0c\u800c\u4e14\u7b54\u6848\u552f\u4e00\u3002

\n\n

\u7981\u7528\u5217\u8868\u4e2d\u7684\u5355\u8bcd\u7528\u5c0f\u5199\u5b57\u6bcd\u8868\u793a\uff0c\u4e0d\u542b\u6807\u70b9\u7b26\u53f7\u3002\u6bb5\u843d\u4e2d\u7684\u5355\u8bcd\u4e0d\u533a\u5206\u5927\u5c0f\u5199\u3002\u7b54\u6848\u90fd\u662f\u5c0f\u5199\u5b57\u6bcd\u3002

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165: \nparagraph = "Bob hit a ball, the hit BALL flew far after it was hit."\nbanned = ["hit"]\n\u8f93\u51fa: "ball"\n\u89e3\u91ca: \n"hit" \u51fa\u73b0\u4e863\u6b21\uff0c\u4f46\u5b83\u662f\u4e00\u4e2a\u7981\u7528\u7684\u5355\u8bcd\u3002\n"ball" \u51fa\u73b0\u4e862\u6b21 (\u540c\u65f6\u6ca1\u6709\u5176\u4ed6\u5355\u8bcd\u51fa\u73b02\u6b21)\uff0c\u6240\u4ee5\u5b83\u662f\u6bb5\u843d\u91cc\u51fa\u73b0\u6b21\u6570\u6700\u591a\u7684\uff0c\u4e14\u4e0d\u5728\u7981\u7528\u5217\u8868\u4e2d\u7684\u5355\u8bcd\u3002 \n\u6ce8\u610f\uff0c\u6240\u6709\u8fd9\u4e9b\u5355\u8bcd\u5728\u6bb5\u843d\u91cc\u4e0d\u533a\u5206\u5927\u5c0f\u5199\uff0c\u6807\u70b9\u7b26\u53f7\u9700\u8981\u5ffd\u7565\uff08\u5373\u4f7f\u662f\u7d27\u6328\u7740\u5355\u8bcd\u4e5f\u5ffd\u7565\uff0c \u6bd4\u5982 "ball,"\uff09\uff0c \n"hit"\u4e0d\u662f\u6700\u7ec8\u7684\u7b54\u6848\uff0c\u867d\u7136\u5b83\u51fa\u73b0\u6b21\u6570\u66f4\u591a\uff0c\u4f46\u5b83\u5728\u7981\u7528\u5355\u8bcd\u5217\u8868\u4e2d\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= \u6bb5\u843d\u957f\u5ea6 <= 1000
  • \n\t
  • 0 <= \u7981\u7528\u5355\u8bcd\u4e2a\u6570 <= 100
  • \n\t
  • 1 <= \u7981\u7528\u5355\u8bcd\u957f\u5ea6 <= 10
  • \n\t
  • \u7b54\u6848\u662f\u552f\u4e00\u7684, \u4e14\u90fd\u662f\u5c0f\u5199\u5b57\u6bcd (\u5373\u4f7f\u5728 paragraph \u91cc\u662f\u5927\u5199\u7684\uff0c\u5373\u4f7f\u662f\u4e00\u4e9b\u7279\u5b9a\u7684\u540d\u8bcd\uff0c\u7b54\u6848\u90fd\u662f\u5c0f\u5199\u7684\u3002)
  • \n\t
  • paragraph \u53ea\u5305\u542b\u5b57\u6bcd\u3001\u7a7a\u683c\u548c\u4e0b\u5217\u6807\u70b9\u7b26\u53f7!?',;.
  • \n\t
  • \u4e0d\u5b58\u5728\u6ca1\u6709\u8fde\u5b57\u7b26\u6216\u8005\u5e26\u6709\u8fde\u5b57\u7b26\u7684\u5355\u8bcd\u3002
  • \n\t
  • \u5355\u8bcd\u91cc\u53ea\u5305\u542b\u5b57\u6bcd\uff0c\u4e0d\u4f1a\u51fa\u73b0\u7701\u7565\u53f7\u6216\u8005\u5176\u4ed6\u6807\u70b9\u7b26\u53f7\u3002
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string mostCommonWord(string paragraph, vector& banned) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String mostCommonWord(String paragraph, String[] banned) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def mostCommonWord(self, paragraph, banned):\n \"\"\"\n :type paragraph: str\n :type banned: List[str]\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def mostCommonWord(self, paragraph: str, banned: List[str]) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * mostCommonWord(char * paragraph, char ** banned, int bannedSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string MostCommonWord(string paragraph, string[] banned) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} paragraph\n * @param {string[]} banned\n * @return {string}\n */\nvar mostCommonWord = function(paragraph, banned) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} paragraph\n# @param {String[]} banned\n# @return {String}\ndef most_common_word(paragraph, banned)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func mostCommonWord(_ paragraph: String, _ banned: [String]) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func mostCommonWord(paragraph string, banned []string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def mostCommonWord(paragraph: String, banned: Array[String]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun mostCommonWord(paragraph: String, banned: Array): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn most_common_word(paragraph: String, banned: Vec) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $paragraph\n * @param String[] $banned\n * @return String\n */\n function mostCommonWord($paragraph, $banned) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function mostCommonWord(paragraph: string, banned: string[]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (most-common-word paragraph banned)\n (-> string? (listof string?) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0819](https://leetcode-cn.com/problems/most-common-word)", "[\u6700\u5e38\u89c1\u7684\u5355\u8bcd](/solution/0800-0899/0819.Most%20Common%20Word/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0819](https://leetcode.com/problems/most-common-word)", "[Most Common Word](/solution/0800-0899/0819.Most%20Common%20Word/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "0836", "frontend_question_id": "0818", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/race-car", "url_en": "https://leetcode.com/problems/race-car", "relative_path_cn": "/solution/0800-0899/0818.Race%20Car/README.md", "relative_path_en": "/solution/0800-0899/0818.Race%20Car/README_EN.md", "title_cn": "\u8d5b\u8f66", "title_en": "Race Car", "question_title_slug": "race-car", "content_en": "

Your car starts at position 0 and speed +1 on an infinite number line. Your car can go into negative positions. Your car drives automatically according to a sequence of instructions 'A' (accelerate) and 'R' (reverse):

\n\n
    \n\t
  • When you get an instruction 'A', your car does the following:\n\n\t
      \n\t\t
    • position += speed
    • \n\t\t
    • speed *= 2
    • \n\t
    \n\t
  • \n\t
  • When you get an instruction 'R', your car does the following:\n\t
      \n\t\t
    • If your speed is positive then speed = -1
    • \n\t\t
    • otherwise speed = 1
    • \n\t
    \n\tYour position stays the same.
  • \n
\n\n

For example, after commands "AAR", your car goes to positions 0 --> 1 --> 3 --> 3, and your speed goes to 1 --> 2 --> 4 --> -1.

\n\n

Given a target position target, return the length of the shortest sequence of instructions to get there.

\n\n

 

\n

Example 1:

\n\n
\nInput: target = 3\nOutput: 2\nExplanation: \nThe shortest instruction sequence is "AA".\nYour position goes from 0 --> 1 --> 3.\n
\n\n

Example 2:

\n\n
\nInput: target = 6\nOutput: 5\nExplanation: \nThe shortest instruction sequence is "AAARA".\nYour position goes from 0 --> 1 --> 3 --> 7 --> 7 --> 6.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= target <= 104
  • \n
\n", "content_cn": "

\u4f60\u7684\u8d5b\u8f66\u8d77\u59cb\u505c\u7559\u5728\u4f4d\u7f6e 0\uff0c\u901f\u5ea6\u4e3a +1\uff0c\u6b63\u884c\u9a76\u5728\u4e00\u4e2a\u65e0\u9650\u957f\u7684\u6570\u8f74\u4e0a\u3002\uff08\u8f66\u4e5f\u53ef\u4ee5\u5411\u8d1f\u6570\u65b9\u5411\u884c\u9a76\u3002\uff09

\n\n

\u4f60\u7684\u8f66\u4f1a\u6839\u636e\u4e00\u7cfb\u5217\u7531 A\uff08\u52a0\u901f\uff09\u548c R\uff08\u5012\u8f66\uff09\u7ec4\u6210\u7684\u6307\u4ee4\u8fdb\u884c\u81ea\u52a8\u9a7e\u9a76 \u3002

\n\n

\u5f53\u8f66\u5f97\u5230\u6307\u4ee4 "A" \u65f6, \u5c06\u4f1a\u505a\u51fa\u4ee5\u4e0b\u64cd\u4f5c\uff1a position += speed, speed *= 2\u3002

\n\n

\u5f53\u8f66\u5f97\u5230\u6307\u4ee4 "R" \u65f6, \u5c06\u4f1a\u505a\u51fa\u4ee5\u4e0b\u64cd\u4f5c\uff1a\u5982\u679c\u5f53\u524d\u901f\u5ea6\u662f\u6b63\u6570\uff0c\u5219\u5c06\u8f66\u901f\u8c03\u6574\u4e3a speed = -1 \uff1b\u5426\u5219\u5c06\u8f66\u901f\u8c03\u6574\u4e3a speed = 1\u3002  (\u5f53\u524d\u6240\u5904\u4f4d\u7f6e\u4e0d\u53d8\u3002)

\n\n

\u4f8b\u5982\uff0c\u5f53\u5f97\u5230\u4e00\u7cfb\u5217\u6307\u4ee4 "AAR" \u540e, \u4f60\u7684\u8f66\u5c06\u4f1a\u8d70\u8fc7\u4f4d\u7f6e 0->1->3->3\uff0c\u5e76\u4e14\u901f\u5ea6\u53d8\u5316\u4e3a 1->2->4->-1\u3002

\n\n

\u73b0\u5728\u7ed9\u5b9a\u4e00\u4e2a\u76ee\u6807\u4f4d\u7f6e\uff0c\u8bf7\u7ed9\u51fa\u80fd\u591f\u5230\u8fbe\u76ee\u6807\u4f4d\u7f6e\u7684\u6700\u77ed\u6307\u4ee4\u5217\u8868\u7684\u957f\u5ea6\u3002

\n\n
\u793a\u4f8b 1:\n\u8f93\u5165: \ntarget = 3\n\u8f93\u51fa: 2\n\u89e3\u91ca: \n\u6700\u77ed\u6307\u4ee4\u5217\u8868\u4e3a "AA"\n\u4f4d\u7f6e\u53d8\u5316\u4e3a 0->1->3\n
\n\n
\u793a\u4f8b 2:\n\u8f93\u5165: \ntarget = 6\n\u8f93\u51fa: 5\n\u89e3\u91ca: \n\u6700\u77ed\u6307\u4ee4\u5217\u8868\u4e3a "AAARA"\n\u4f4d\u7f6e\u53d8\u5316\u4e3a 0->1->3->7->7->6\n
\n\n

\u8bf4\u660e:

\n\n
    \n\t
  • 1 <= target\uff08\u76ee\u6807\u4f4d\u7f6e\uff09 <= 10000\u3002
  • \n
\n", "tags_en": ["Heap", "Dynamic Programming"], "tags_cn": ["\u5806", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int racecar(int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int racecar(int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def racecar(self, target):\n \"\"\"\n :type target: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def racecar(self, target: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint racecar(int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int Racecar(int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} target\n * @return {number}\n */\nvar racecar = function(target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} target\n# @return {Integer}\ndef racecar(target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func racecar(_ target: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func racecar(target int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def racecar(target: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun racecar(target: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn racecar(target: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $target\n * @return Integer\n */\n function racecar($target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function racecar(target: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (racecar target)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0818](https://leetcode-cn.com/problems/race-car)", "[\u8d5b\u8f66](/solution/0800-0899/0818.Race%20Car/README.md)", "`\u5806`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0818](https://leetcode.com/problems/race-car)", "[Race Car](/solution/0800-0899/0818.Race%20Car/README_EN.md)", "`Heap`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0835", "frontend_question_id": "0817", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/linked-list-components", "url_en": "https://leetcode.com/problems/linked-list-components", "relative_path_cn": "/solution/0800-0899/0817.Linked%20List%20Components/README.md", "relative_path_en": "/solution/0800-0899/0817.Linked%20List%20Components/README_EN.md", "title_cn": "\u94fe\u8868\u7ec4\u4ef6", "title_en": "Linked List Components", "question_title_slug": "linked-list-components", "content_en": "

We are given head, the head node of a linked list containing unique integer values.

\n\n

We are also given the list nums, a subset of the values in the linked list.

\n\n

Return the number of connected components in nums, where two values are connected if they appear consecutively in the linked list.

\n\n

Example 1:

\n\n
\nInput: \nhead: 0->1->2->3\nnums = [0, 1, 3]\nOutput: 2\nExplanation: \n0 and 1 are connected, so [0, 1] and [3] are the two connected components.\n
\n\n

Example 2:

\n\n
\nInput: \nhead: 0->1->2->3->4\nnums = [0, 3, 1, 4]\nOutput: 2\nExplanation: \n0 and 1 are connected, 3 and 4 are connected, so [0, 1] and [3, 4] are the two connected components.\n
\n\n

Note:

\n\n
    \n\t
  • If n is the length of the linked list given by head1 <= n <= 10000.
  • \n\t
  • The value of each node in the linked list will be in the range [0, n - 1].
  • \n\t
  • 1 <= nums.length <= 10000.
  • \n\t
  • nums is a subset of all values in the linked list.
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u94fe\u8868\u5934\u7ed3\u70b9 head\uff0c\u8be5\u94fe\u8868\u4e0a\u7684\u6bcf\u4e2a\u7ed3\u70b9\u90fd\u6709\u4e00\u4e2a \u552f\u4e00\u7684\u6574\u578b\u503c \u3002

\n\n

\u540c\u65f6\u7ed9\u5b9a\u5217\u8868 G\uff0c\u8be5\u5217\u8868\u662f\u4e0a\u8ff0\u94fe\u8868\u4e2d\u6574\u578b\u503c\u7684\u4e00\u4e2a\u5b50\u96c6\u3002

\n\n

\u8fd4\u56de\u5217\u8868 G \u4e2d\u7ec4\u4ef6\u7684\u4e2a\u6570\uff0c\u8fd9\u91cc\u5bf9\u7ec4\u4ef6\u7684\u5b9a\u4e49\u4e3a\uff1a\u94fe\u8868\u4e2d\u4e00\u6bb5\u6700\u957f\u8fde\u7eed\u7ed3\u70b9\u7684\u503c\uff08\u8be5\u503c\u5fc5\u987b\u5728\u5217\u8868 G \u4e2d\uff09\u6784\u6210\u7684\u96c6\u5408\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165: \nhead: 0->1->2->3\nG = [0, 1, 3]\n\u8f93\u51fa: 2\n\u89e3\u91ca: \n\u94fe\u8868\u4e2d,0 \u548c 1 \u662f\u76f8\u8fde\u63a5\u7684\uff0c\u4e14 G \u4e2d\u4e0d\u5305\u542b 2\uff0c\u6240\u4ee5 [0, 1] \u662f G \u7684\u4e00\u4e2a\u7ec4\u4ef6\uff0c\u540c\u7406 [3] \u4e5f\u662f\u4e00\u4e2a\u7ec4\u4ef6\uff0c\u6545\u8fd4\u56de 2\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165: \nhead: 0->1->2->3->4\nG = [0, 3, 1, 4]\n\u8f93\u51fa: 2\n\u89e3\u91ca: \n\u94fe\u8868\u4e2d\uff0c0 \u548c 1 \u662f\u76f8\u8fde\u63a5\u7684\uff0c3 \u548c 4 \u662f\u76f8\u8fde\u63a5\u7684\uff0c\u6240\u4ee5 [0, 1] \u548c [3, 4] \u662f\u4e24\u4e2a\u7ec4\u4ef6\uff0c\u6545\u8fd4\u56de 2\u3002
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u5982\u679c N \u662f\u7ed9\u5b9a\u94fe\u8868 head \u7684\u957f\u5ea6\uff0c1 <= N <= 10000\u3002
  • \n\t
  • \u94fe\u8868\u4e2d\u6bcf\u4e2a\u7ed3\u70b9\u7684\u503c\u6240\u5728\u8303\u56f4\u4e3a [0, N - 1]\u3002
  • \n\t
  • 1 <= G.length <= 10000
  • \n\t
  • G \u662f\u94fe\u8868\u4e2d\u6240\u6709\u7ed3\u70b9\u7684\u503c\u7684\u4e00\u4e2a\u5b50\u96c6.
  • \n
\n", "tags_en": ["Linked List"], "tags_cn": ["\u94fe\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n int numComponents(ListNode* head, vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public int numComponents(ListNode head, int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def numComponents(self, head, nums):\n \"\"\"\n :type head: ListNode\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def numComponents(self, head: ListNode, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nint numComponents(struct ListNode* head, int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public int NumComponents(ListNode head, int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} head\n * @param {number[]} nums\n * @return {number}\n */\nvar numComponents = function(head, nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode} head\n# @param {Integer[]} nums\n# @return {Integer}\ndef num_components(head, nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func numComponents(_ head: ListNode?, _ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc numComponents(head *ListNode, nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def numComponents(head: ListNode, nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun numComponents(head: ListNode?, nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn num_components(head: Option>, nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @param Integer[] $nums\n * @return Integer\n */\n function numComponents($head, $nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction numComponents(head: ListNode | null, nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (num-components head nums)\n (-> (or/c list-node? #f) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0817](https://leetcode-cn.com/problems/linked-list-components)", "[\u94fe\u8868\u7ec4\u4ef6](/solution/0800-0899/0817.Linked%20List%20Components/README.md)", "`\u94fe\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0817](https://leetcode.com/problems/linked-list-components)", "[Linked List Components](/solution/0800-0899/0817.Linked%20List%20Components/README_EN.md)", "`Linked List`", "Medium", ""]}, {"question_id": "0834", "frontend_question_id": "0816", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/ambiguous-coordinates", "url_en": "https://leetcode.com/problems/ambiguous-coordinates", "relative_path_cn": "/solution/0800-0899/0816.Ambiguous%20Coordinates/README.md", "relative_path_en": "/solution/0800-0899/0816.Ambiguous%20Coordinates/README_EN.md", "title_cn": "\u6a21\u7cca\u5750\u6807", "title_en": "Ambiguous Coordinates", "question_title_slug": "ambiguous-coordinates", "content_en": "

We had some 2-dimensional coordinates, like "(1, 3)" or "(2, 0.5)". Then, we removed all commas, decimal points, and spaces and ended up with the string s.

\n\n
    \n\t
  • For example, "(1, 3)" becomes s = "(13)" and "(2, 0.5)" becomes s = "(205)".
  • \n
\n\n

Return a list of strings representing all possibilities for what our original coordinates could have been.

\n\n

Our original representation never had extraneous zeroes, so we never started with numbers like "00", "0.0", "0.00", "1.0", "001", "00.01", or any other number that can be represented with fewer digits. Also, a decimal point within a number never occurs without at least one digit occurring before it, so we never started with numbers like ".1".

\n\n

The final answer list can be returned in any order. All coordinates in the final answer have exactly one space between them (occurring after the comma.)

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "(123)"\nOutput: ["(1, 2.3)","(1, 23)","(1.2, 3)","(12, 3)"]\n
\n\n

Example 2:

\n\n
\nInput: s = "(0123)"\nOutput: ["(0, 1.23)","(0, 12.3)","(0, 123)","(0.1, 2.3)","(0.1, 23)","(0.12, 3)"]\nExplanation: 0.0, 00, 0001 or 00.01 are not allowed.\n
\n\n

Example 3:

\n\n
\nInput: s = "(00011)"\nOutput: ["(0, 0.011)","(0.001, 1)"]\n
\n\n

Example 4:

\n\n
\nInput: s = "(100)"\nOutput: ["(10, 0)"]\nExplanation: 1.0 is not allowed.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 4 <= s.length <= 12
  • \n\t
  • s[0] == '(' and s[s.length - 1] == ')'.
  • \n\t
  • The rest of s are digits.
  • \n
\n", "content_cn": "

\u6211\u4eec\u6709\u4e00\u4e9b\u4e8c\u7ef4\u5750\u6807\uff0c\u5982 "(1, 3)" \u6216 "(2, 0.5)"\uff0c\u7136\u540e\u6211\u4eec\u79fb\u9664\u6240\u6709\u9017\u53f7\uff0c\u5c0f\u6570\u70b9\u548c\u7a7a\u683c\uff0c\u5f97\u5230\u4e00\u4e2a\u5b57\u7b26\u4e32S\u3002\u8fd4\u56de\u6240\u6709\u53ef\u80fd\u7684\u539f\u59cb\u5b57\u7b26\u4e32\u5230\u4e00\u4e2a\u5217\u8868\u4e2d\u3002

\n\n

\u539f\u59cb\u7684\u5750\u6807\u8868\u793a\u6cd5\u4e0d\u4f1a\u5b58\u5728\u591a\u4f59\u7684\u96f6\uff0c\u6240\u4ee5\u4e0d\u4f1a\u51fa\u73b0\u7c7b\u4f3c\u4e8e"00", "0.0", "0.00", "1.0", "001", "00.01"\u6216\u4e00\u4e9b\u5176\u4ed6\u66f4\u5c0f\u7684\u6570\u6765\u8868\u793a\u5750\u6807\u3002\u6b64\u5916\uff0c\u4e00\u4e2a\u5c0f\u6570\u70b9\u524d\u81f3\u5c11\u5b58\u5728\u4e00\u4e2a\u6570\uff0c\u6240\u4ee5\u4e5f\u4e0d\u4f1a\u51fa\u73b0“.1”\u5f62\u5f0f\u7684\u6570\u5b57\u3002

\n\n

\u6700\u540e\u8fd4\u56de\u7684\u5217\u8868\u53ef\u4ee5\u662f\u4efb\u610f\u987a\u5e8f\u7684\u3002\u800c\u4e14\u6ce8\u610f\u8fd4\u56de\u7684\u4e24\u4e2a\u6570\u5b57\u4e2d\u95f4\uff08\u9017\u53f7\u4e4b\u540e\uff09\u90fd\u6709\u4e00\u4e2a\u7a7a\u683c\u3002

\n\n

 

\n\n
\n\u793a\u4f8b 1:\n\u8f93\u5165: "(123)"\n\u8f93\u51fa: ["(1, 23)", "(12, 3)", "(1.2, 3)", "(1, 2.3)"]\n
\n\n
\n\u793a\u4f8b 2:\n\u8f93\u5165: "(00011)"\n\u8f93\u51fa:  ["(0.001, 1)", "(0, 0.011)"]\n\u89e3\u91ca: \n0.0, 00, 0001 \u6216 00.01 \u662f\u4e0d\u88ab\u5141\u8bb8\u7684\u3002\n
\n\n
\n\u793a\u4f8b 3:\n\u8f93\u5165: "(0123)"\n\u8f93\u51fa: ["(0, 123)", "(0, 12.3)", "(0, 1.23)", "(0.1, 23)", "(0.1, 2.3)", "(0.12, 3)"]\n
\n\n
\n\u793a\u4f8b 4:\n\u8f93\u5165: "(100)"\n\u8f93\u51fa: [(10, 0)]\n\u89e3\u91ca: \n1.0 \u662f\u4e0d\u88ab\u5141\u8bb8\u7684\u3002\n
\n\n

 

\n\n

\u63d0\u793a:

\n\n
    \n\t
  • 4 <= S.length <= 12.
  • \n\t
  • S[0] = "(", S[S.length - 1] = ")", \u4e14\u5b57\u7b26\u4e32 S \u4e2d\u7684\u5176\u4ed6\u5143\u7d20\u90fd\u662f\u6570\u5b57\u3002
  • \n
\n\n

 

\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector ambiguousCoordinates(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List ambiguousCoordinates(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def ambiguousCoordinates(self, s):\n \"\"\"\n :type s: str\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def ambiguousCoordinates(self, s: str) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** ambiguousCoordinates(char * s, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList AmbiguousCoordinates(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string[]}\n */\nvar ambiguousCoordinates = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String[]}\ndef ambiguous_coordinates(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func ambiguousCoordinates(_ s: String) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func ambiguousCoordinates(s string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def ambiguousCoordinates(s: String): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun ambiguousCoordinates(s: String): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn ambiguous_coordinates(s: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String[]\n */\n function ambiguousCoordinates($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function ambiguousCoordinates(s: string): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (ambiguous-coordinates s)\n (-> string? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0816](https://leetcode-cn.com/problems/ambiguous-coordinates)", "[\u6a21\u7cca\u5750\u6807](/solution/0800-0899/0816.Ambiguous%20Coordinates/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0816](https://leetcode.com/problems/ambiguous-coordinates)", "[Ambiguous Coordinates](/solution/0800-0899/0816.Ambiguous%20Coordinates/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "0833", "frontend_question_id": "0815", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/bus-routes", "url_en": "https://leetcode.com/problems/bus-routes", "relative_path_cn": "/solution/0800-0899/0815.Bus%20Routes/README.md", "relative_path_en": "/solution/0800-0899/0815.Bus%20Routes/README_EN.md", "title_cn": "\u516c\u4ea4\u8def\u7ebf", "title_en": "Bus Routes", "question_title_slug": "bus-routes", "content_en": "

You are given an array routes representing bus routes where routes[i] is a bus route that the ith bus repeats forever.

\n\n
    \n\t
  • For example, if routes[0] = [1, 5, 7], this means that the 0th bus travels in the sequence 1 -> 5 -> 7 -> 1 -> 5 -> 7 -> 1 -> ... forever.
  • \n
\n\n

You will start at the bus stop source (You are not on any bus initially), and you want to go to the bus stop target. You can travel between bus stops by buses only.

\n\n

Return the least number of buses you must take to travel from source to target. Return -1 if it is not possible.

\n\n

 

\n

Example 1:

\n\n
\nInput: routes = [[1,2,7],[3,6,7]], source = 1, target = 6\nOutput: 2\nExplanation: The best strategy is take the first bus to the bus stop 7, then take the second bus to the bus stop 6.\n
\n\n

Example 2:

\n\n
\nInput: routes = [[7,12],[4,5,15],[6],[15,19],[9,12,13]], source = 15, target = 12\nOutput: -1\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= routes.length <= 500.
  • \n\t
  • 1 <= routes[i].length <= 105
  • \n\t
  • All the values of routes[i] are unique.
  • \n\t
  • sum(routes[i].length) <= 105
  • \n\t
  • 0 <= routes[i][j] < 106
  • \n\t
  • 0 <= source, target < 106
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 routes \uff0c\u8868\u793a\u4e00\u7cfb\u5217\u516c\u4ea4\u7ebf\u8def\uff0c\u5176\u4e2d\u6bcf\u4e2a routes[i] \u8868\u793a\u4e00\u6761\u516c\u4ea4\u7ebf\u8def\uff0c\u7b2c i \u8f86\u516c\u4ea4\u8f66\u5c06\u4f1a\u5728\u4e0a\u9762\u5faa\u73af\u884c\u9a76\u3002

\n\n
    \n\t
  • \u4f8b\u5982\uff0c\u8def\u7ebf routes[0] = [1, 5, 7] \u8868\u793a\u7b2c 0 \u8f86\u516c\u4ea4\u8f66\u4f1a\u4e00\u76f4\u6309\u5e8f\u5217 1 -> 5 -> 7 -> 1 -> 5 -> 7 -> 1 -> ... \u8fd9\u6837\u7684\u8f66\u7ad9\u8def\u7ebf\u884c\u9a76\u3002
  • \n
\n\n

\u73b0\u5728\u4ece source \u8f66\u7ad9\u51fa\u53d1\uff08\u521d\u59cb\u65f6\u4e0d\u5728\u516c\u4ea4\u8f66\u4e0a\uff09\uff0c\u8981\u524d\u5f80 target \u8f66\u7ad9\u3002 \u671f\u95f4\u4ec5\u53ef\u4e58\u5750\u516c\u4ea4\u8f66\u3002

\n\n

\u6c42\u51fa \u6700\u5c11\u4e58\u5750\u7684\u516c\u4ea4\u8f66\u6570\u91cf \u3002\u5982\u679c\u4e0d\u53ef\u80fd\u5230\u8fbe\u7ec8\u70b9\u8f66\u7ad9\uff0c\u8fd4\u56de -1 \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aroutes = [[1,2,7],[3,6,7]], source = 1, target = 6\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6700\u4f18\u7b56\u7565\u662f\u5148\u4e58\u5750\u7b2c\u4e00\u8f86\u516c\u4ea4\u8f66\u5230\u8fbe\u8f66\u7ad9 7 , \u7136\u540e\u6362\u4e58\u7b2c\u4e8c\u8f86\u516c\u4ea4\u8f66\u5230\u8f66\u7ad9 6 \u3002 \n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aroutes = [[7,12],[4,5,15],[6],[15,19],[9,12,13]], source = 15, target = 12\n\u8f93\u51fa\uff1a-1\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= routes.length <= 500.
  • \n\t
  • 1 <= routes[i].length <= 105
  • \n\t
  • routes[i] \u4e2d\u7684\u6240\u6709\u503c \u4e92\u4e0d\u76f8\u540c
  • \n\t
  • sum(routes[i].length) <= 105
  • \n\t
  • 0 <= routes[i][j] < 106
  • \n\t
  • 0 <= source, target < 106
  • \n
\n", "tags_en": ["Breadth-first Search"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numBusesToDestination(vector>& routes, int source, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numBusesToDestination(int[][] routes, int source, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numBusesToDestination(self, routes, source, target):\n \"\"\"\n :type routes: List[List[int]]\n :type source: int\n :type target: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numBusesToDestination(self, routes: List[List[int]], source: int, target: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numBusesToDestination(int** routes, int routesSize, int* routesColSize, int source, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumBusesToDestination(int[][] routes, int source, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} routes\n * @param {number} source\n * @param {number} target\n * @return {number}\n */\nvar numBusesToDestination = function(routes, source, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} routes\n# @param {Integer} source\n# @param {Integer} target\n# @return {Integer}\ndef num_buses_to_destination(routes, source, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numBusesToDestination(_ routes: [[Int]], _ source: Int, _ target: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numBusesToDestination(routes [][]int, source int, target int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numBusesToDestination(routes: Array[Array[Int]], source: Int, target: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numBusesToDestination(routes: Array, source: Int, target: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_buses_to_destination(routes: Vec>, source: i32, target: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $routes\n * @param Integer $source\n * @param Integer $target\n * @return Integer\n */\n function numBusesToDestination($routes, $source, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numBusesToDestination(routes: number[][], source: number, target: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-buses-to-destination routes source target)\n (-> (listof (listof exact-integer?)) exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0815](https://leetcode-cn.com/problems/bus-routes)", "[\u516c\u4ea4\u8def\u7ebf](/solution/0800-0899/0815.Bus%20Routes/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[0815](https://leetcode.com/problems/bus-routes)", "[Bus Routes](/solution/0800-0899/0815.Bus%20Routes/README_EN.md)", "`Breadth-first Search`", "Hard", ""]}, {"question_id": "0832", "frontend_question_id": "0814", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/binary-tree-pruning", "url_en": "https://leetcode.com/problems/binary-tree-pruning", "relative_path_cn": "/solution/0800-0899/0814.Binary%20Tree%20Pruning/README.md", "relative_path_en": "/solution/0800-0899/0814.Binary%20Tree%20Pruning/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u526a\u679d", "title_en": "Binary Tree Pruning", "question_title_slug": "binary-tree-pruning", "content_en": "

Given the root of a binary tree, return the same tree where every subtree (of the given tree) not containing a 1 has been removed.

\n\n

A subtree of a node node is node plus every node that is a descendant of node.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: root = [1,null,0,0,1]\nOutput: [1,null,0,null,1]\nExplanation: \nOnly the red nodes satisfy the property "every subtree not containing a 1".\nThe diagram on the right represents the answer.\n
\n\n

Example 2:

\n\"\"\n
\nInput: root = [1,0,1,0,0,0,1]\nOutput: [1,null,1,null,1]\n
\n\n

Example 3:

\n\"\"\n
\nInput: root = [1,1,0,1,1,0,1,0]\nOutput: [1,1,0,1,1,null,1]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The number of nodes in the tree is in the range [1, 200].
  • \n\t
  • Node.val is either 0 or 1.
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e8c\u53c9\u6811\u6839\u7ed3\u70b9 root \uff0c\u6b64\u5916\u6811\u7684\u6bcf\u4e2a\u7ed3\u70b9\u7684\u503c\u8981\u4e48\u662f 0\uff0c\u8981\u4e48\u662f 1\u3002

\n\n

\u8fd4\u56de\u79fb\u9664\u4e86\u6240\u6709\u4e0d\u5305\u542b 1 \u7684\u5b50\u6811\u7684\u539f\u4e8c\u53c9\u6811\u3002

\n\n

( \u8282\u70b9 X \u7684\u5b50\u6811\u4e3a X \u672c\u8eab\uff0c\u4ee5\u53ca\u6240\u6709 X \u7684\u540e\u4ee3\u3002)

\n\n
\n\u793a\u4f8b1:\n\u8f93\u5165: [1,null,0,0,1]\n\u8f93\u51fa: [1,null,0,null,1]\n \n\u89e3\u91ca: \n\u53ea\u6709\u7ea2\u8272\u8282\u70b9\u6ee1\u8db3\u6761\u4ef6“\u6240\u6709\u4e0d\u5305\u542b 1 \u7684\u5b50\u6811”\u3002\n\u53f3\u56fe\u4e3a\u8fd4\u56de\u7684\u7b54\u6848\u3002\n\n\"\"\n
\n\n
\n\u793a\u4f8b2:\n\u8f93\u5165: [1,0,1,0,0,0,1]\n\u8f93\u51fa: [1,null,1,null,1]\n\n\n\"\"\n
\n\n
\n\u793a\u4f8b3:\n\u8f93\u5165: [1,1,0,1,1,0,1,0]\n\u8f93\u51fa: [1,1,0,1,1,null,1]\n\n\n\"\"\n
\n\n

\u8bf4\u660e:

\n\n
    \n\t
  • \u7ed9\u5b9a\u7684\u4e8c\u53c9\u6811\u6700\u591a\u6709 100 \u4e2a\u8282\u70b9\u3002
  • \n\t
  • \u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u53ea\u4f1a\u4e3a 0 \u6216 1 \u3002
  • \n
\n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* pruneTree(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode pruneTree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def pruneTree(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: TreeNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def pruneTree(self, root: TreeNode) -> TreeNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* pruneTree(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode PruneTree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {TreeNode}\n */\nvar pruneTree = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {TreeNode}\ndef prune_tree(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func pruneTree(_ root: TreeNode?) -> TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc pruneTree(root *TreeNode) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def pruneTree(root: TreeNode): TreeNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun pruneTree(root: TreeNode?): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn prune_tree(root: Option>>) -> Option>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return TreeNode\n */\n function pruneTree($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction pruneTree(root: TreeNode | null): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (prune-tree root)\n (-> (or/c tree-node? #f) (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0814](https://leetcode-cn.com/problems/binary-tree-pruning)", "[\u4e8c\u53c9\u6811\u526a\u679d](/solution/0800-0899/0814.Binary%20Tree%20Pruning/README.md)", "`\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0814](https://leetcode.com/problems/binary-tree-pruning)", "[Binary Tree Pruning](/solution/0800-0899/0814.Binary%20Tree%20Pruning/README_EN.md)", "`Tree`", "Medium", ""]}, {"question_id": "0831", "frontend_question_id": "0813", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/largest-sum-of-averages", "url_en": "https://leetcode.com/problems/largest-sum-of-averages", "relative_path_cn": "/solution/0800-0899/0813.Largest%20Sum%20of%20Averages/README.md", "relative_path_en": "/solution/0800-0899/0813.Largest%20Sum%20of%20Averages/README_EN.md", "title_cn": "\u6700\u5927\u5e73\u5747\u503c\u548c\u7684\u5206\u7ec4", "title_en": "Largest Sum of Averages", "question_title_slug": "largest-sum-of-averages", "content_en": "

We partition a row of numbers nums into at most k adjacent (non-empty) groups, then our score is the sum of the average of each group. What is the largest score we can achieve?

\n\n

Note that our partition must use every number in nums, and that scores are not necessarily integers.

\n\n
\nExample:\nInput: \nnums = [9,1,2,3,9]\nk = 3\nOutput: 20\nExplanation: \nThe best choice is to partition nums into [9], [1, 2, 3], [9]. The answer is 9 + (1 + 2 + 3) / 3 + 9 = 20.\nWe could have also partitioned nums into [9, 1], [2], [3, 9], for example.\nThat partition would lead to a score of 5 + 2 + 6 = 13, which is worse.\n
\n\n

 

\n\n

Note:

\n\n
    \n\t
  • 1 <= nums.length <= 100.
  • \n\t
  • 1 <= nums[i] <= 10000.
  • \n\t
  • 1 <= k <= nums.length.
  • \n\t
  • Answers within 10-6 of the correct answer will be accepted as correct.
  • \n
\n", "content_cn": "

\u6211\u4eec\u5c06\u7ed9\u5b9a\u7684\u6570\u7ec4 A \u5206\u6210 K \u4e2a\u76f8\u90bb\u7684\u975e\u7a7a\u5b50\u6570\u7ec4 \uff0c\u6211\u4eec\u7684\u5206\u6570\u7531\u6bcf\u4e2a\u5b50\u6570\u7ec4\u5185\u7684\u5e73\u5747\u503c\u7684\u603b\u548c\u6784\u6210\u3002\u8ba1\u7b97\u6211\u4eec\u6240\u80fd\u5f97\u5230\u7684\u6700\u5927\u5206\u6570\u662f\u591a\u5c11\u3002

\n\n

\u6ce8\u610f\u6211\u4eec\u5fc5\u987b\u4f7f\u7528 A \u6570\u7ec4\u4e2d\u7684\u6bcf\u4e00\u4e2a\u6570\u8fdb\u884c\u5206\u7ec4\uff0c\u5e76\u4e14\u5206\u6570\u4e0d\u4e00\u5b9a\u9700\u8981\u662f\u6574\u6570\u3002

\n\n
\n\u793a\u4f8b:\n\u8f93\u5165: \nA = [9,1,2,3,9]\nK = 3\n\u8f93\u51fa: 20\n\u89e3\u91ca: \nA \u7684\u6700\u4f18\u5206\u7ec4\u662f[9], [1, 2, 3], [9]. \u5f97\u5230\u7684\u5206\u6570\u662f 9 + (1 + 2 + 3) / 3 + 9 = 20.\n\u6211\u4eec\u4e5f\u53ef\u4ee5\u628a A \u5206\u6210[9, 1], [2], [3, 9].\n\u8fd9\u6837\u7684\u5206\u7ec4\u5f97\u5230\u7684\u5206\u6570\u4e3a 5 + 2 + 6 = 13, \u4f46\u4e0d\u662f\u6700\u5927\u503c.\n
\n\n

\u8bf4\u660e:

\n\n
    \n\t
  • 1 <= A.length <= 100.
  • \n\t
  • 1 <= A[i] <= 10000.
  • \n\t
  • 1 <= K <= A.length.
  • \n\t
  • \u7b54\u6848\u8bef\u5dee\u5728 10^-6 \u5185\u88ab\u89c6\u4e3a\u662f\u6b63\u786e\u7684\u3002
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n double largestSumOfAverages(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double largestSumOfAverages(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def largestSumOfAverages(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: float\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def largestSumOfAverages(self, nums: List[int], k: int) -> float:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\ndouble largestSumOfAverages(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double LargestSumOfAverages(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar largestSumOfAverages = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Float}\ndef largest_sum_of_averages(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func largestSumOfAverages(_ nums: [Int], _ k: Int) -> Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func largestSumOfAverages(nums []int, k int) float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def largestSumOfAverages(nums: Array[Int], k: Int): Double = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun largestSumOfAverages(nums: IntArray, k: Int): Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn largest_sum_of_averages(nums: Vec, k: i32) -> f64 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Float\n */\n function largestSumOfAverages($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function largestSumOfAverages(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (largest-sum-of-averages nums k)\n (-> (listof exact-integer?) exact-integer? flonum?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0813](https://leetcode-cn.com/problems/largest-sum-of-averages)", "[\u6700\u5927\u5e73\u5747\u503c\u548c\u7684\u5206\u7ec4](/solution/0800-0899/0813.Largest%20Sum%20of%20Averages/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0813](https://leetcode.com/problems/largest-sum-of-averages)", "[Largest Sum of Averages](/solution/0800-0899/0813.Largest%20Sum%20of%20Averages/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0830", "frontend_question_id": "0812", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/largest-triangle-area", "url_en": "https://leetcode.com/problems/largest-triangle-area", "relative_path_cn": "/solution/0800-0899/0812.Largest%20Triangle%20Area/README.md", "relative_path_en": "/solution/0800-0899/0812.Largest%20Triangle%20Area/README_EN.md", "title_cn": "\u6700\u5927\u4e09\u89d2\u5f62\u9762\u79ef", "title_en": "Largest Triangle Area", "question_title_slug": "largest-triangle-area", "content_en": "

You have a list of points in the plane. Return the area of the largest triangle that can be formed by any 3 of the points.

\r\n\r\n
\r\nExample:\r\nInput: points = [[0,0],[0,1],[1,0],[0,2],[2,0]]\r\nOutput: 2\r\nExplanation: \r\nThe five points are show in the figure below. The red triangle is the largest.\r\n
\r\n\r\n

\"\"

\r\n\r\n

Notes:

\r\n\r\n
    \r\n\t
  • 3 <= points.length <= 50.
  • \r\n\t
  • No points will be duplicated.
  • \r\n\t
  •  -50 <= points[i][j] <= 50.
  • \r\n\t
  • Answers within 10^-6 of the true value will be accepted as correct.
  • \r\n
\r\n\r\n

 

\r\n", "content_cn": "

\u7ed9\u5b9a\u5305\u542b\u591a\u4e2a\u70b9\u7684\u96c6\u5408\uff0c\u4ece\u5176\u4e2d\u53d6\u4e09\u4e2a\u70b9\u7ec4\u6210\u4e09\u89d2\u5f62\uff0c\u8fd4\u56de\u80fd\u7ec4\u6210\u7684\u6700\u5927\u4e09\u89d2\u5f62\u7684\u9762\u79ef\u3002

\n\n
\n\u793a\u4f8b:\n\u8f93\u5165: points = [[0,0],[0,1],[1,0],[0,2],[2,0]]\n\u8f93\u51fa: 2\n\u89e3\u91ca: \n\u8fd9\u4e94\u4e2a\u70b9\u5982\u4e0b\u56fe\u6240\u793a\u3002\u7ec4\u6210\u7684\u6a59\u8272\u4e09\u89d2\u5f62\u662f\u6700\u5927\u7684\uff0c\u9762\u79ef\u4e3a2\u3002\n
\n\n

\"\"

\n\n

\u6ce8\u610f:

\n\n
    \n\t
  • 3 <= points.length <= 50.
  • \n\t
  • \u4e0d\u5b58\u5728\u91cd\u590d\u7684\u70b9\u3002
  • \n\t
  •  -50 <= points[i][j] <= 50.
  • \n\t
  • \u7ed3\u679c\u8bef\u5dee\u503c\u5728 10^-6 \u4ee5\u5185\u90fd\u8ba4\u4e3a\u662f\u6b63\u786e\u7b54\u6848\u3002
  • \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n double largestTriangleArea(vector>& points) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double largestTriangleArea(int[][] points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def largestTriangleArea(self, points):\n \"\"\"\n :type points: List[List[int]]\n :rtype: float\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def largestTriangleArea(self, points: List[List[int]]) -> float:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\ndouble largestTriangleArea(int** points, int pointsSize, int* pointsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double LargestTriangleArea(int[][] points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} points\n * @return {number}\n */\nvar largestTriangleArea = function(points) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} points\n# @return {Float}\ndef largest_triangle_area(points)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func largestTriangleArea(_ points: [[Int]]) -> Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func largestTriangleArea(points [][]int) float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def largestTriangleArea(points: Array[Array[Int]]): Double = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun largestTriangleArea(points: Array): Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn largest_triangle_area(points: Vec>) -> f64 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $points\n * @return Float\n */\n function largestTriangleArea($points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function largestTriangleArea(points: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (largest-triangle-area points)\n (-> (listof (listof exact-integer?)) flonum?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0812](https://leetcode-cn.com/problems/largest-triangle-area)", "[\u6700\u5927\u4e09\u89d2\u5f62\u9762\u79ef](/solution/0800-0899/0812.Largest%20Triangle%20Area/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0812](https://leetcode.com/problems/largest-triangle-area)", "[Largest Triangle Area](/solution/0800-0899/0812.Largest%20Triangle%20Area/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "0829", "frontend_question_id": "0811", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/subdomain-visit-count", "url_en": "https://leetcode.com/problems/subdomain-visit-count", "relative_path_cn": "/solution/0800-0899/0811.Subdomain%20Visit%20Count/README.md", "relative_path_en": "/solution/0800-0899/0811.Subdomain%20Visit%20Count/README_EN.md", "title_cn": "\u5b50\u57df\u540d\u8bbf\u95ee\u8ba1\u6570", "title_en": "Subdomain Visit Count", "question_title_slug": "subdomain-visit-count", "content_en": "

A website domain like "discuss.leetcode.com" consists of various subdomains. At the top level, we have "com", at the next level, we have "leetcode.com", and at the lowest level, "discuss.leetcode.com". When we visit a domain like "discuss.leetcode.com", we will also visit the parent domains "leetcode.com" and "com" implicitly.

\r\n\r\n

Now, call a "count-paired domain" to be a count (representing the number of visits this domain received), followed by a space, followed by the address. An example of a count-paired domain might be "9001 discuss.leetcode.com".

\r\n\r\n

We are given a list cpdomains of count-paired domains. We would like a list of count-paired domains, (in the same format as the input, and in any order), that explicitly counts the number of visits to each subdomain.

\r\n\r\n
\r\nExample 1:\r\nInput: \r\n["9001 discuss.leetcode.com"]\r\nOutput: \r\n["9001 discuss.leetcode.com", "9001 leetcode.com", "9001 com"]\r\nExplanation: \r\nWe only have one website domain: "discuss.leetcode.com". As discussed above, the subdomain "leetcode.com" and "com" will also be visited. So they will all be visited 9001 times.\r\n\r\n
\r\n\r\n
\r\nExample 2:\r\nInput: \r\n["900 google.mail.com", "50 yahoo.com", "1 intel.mail.com", "5 wiki.org"]\r\nOutput: \r\n["901 mail.com","50 yahoo.com","900 google.mail.com","5 wiki.org","5 org","1 intel.mail.com","951 com"]\r\nExplanation: \r\nWe will visit "google.mail.com" 900 times, "yahoo.com" 50 times, "intel.mail.com" once and "wiki.org" 5 times. For the subdomains, we will visit "mail.com" 900 + 1 = 901 times, "com" 900 + 50 + 1 = 951 times, and "org" 5 times.\r\n\r\n
\r\n\r\n

Notes:

\r\n\r\n
    \r\n\t
  • The length of cpdomains will not exceed 100
  • \r\n\t
  • The length of each domain name will not exceed 100.
  • \r\n\t
  • Each address will have either 1 or 2 "." characters.
  • \r\n\t
  • The input count in any count-paired domain will not exceed 10000.
  • \r\n\t
  • The answer output can be returned in any order.
  • \r\n
\r\n", "content_cn": "

\u4e00\u4e2a\u7f51\u7ad9\u57df\u540d\uff0c\u5982"discuss.leetcode.com"\uff0c\u5305\u542b\u4e86\u591a\u4e2a\u5b50\u57df\u540d\u3002\u4f5c\u4e3a\u9876\u7ea7\u57df\u540d\uff0c\u5e38\u7528\u7684\u6709"com"\uff0c\u4e0b\u4e00\u7ea7\u5219\u6709"leetcode.com"\uff0c\u6700\u4f4e\u7684\u4e00\u7ea7\u4e3a"discuss.leetcode.com"\u3002\u5f53\u6211\u4eec\u8bbf\u95ee\u57df\u540d"discuss.leetcode.com"\u65f6\uff0c\u4e5f\u540c\u65f6\u8bbf\u95ee\u4e86\u5176\u7236\u57df\u540d"leetcode.com"\u4ee5\u53ca\u9876\u7ea7\u57df\u540d "com"\u3002

\n\n

\u7ed9\u5b9a\u4e00\u4e2a\u5e26\u8bbf\u95ee\u6b21\u6570\u548c\u57df\u540d\u7684\u7ec4\u5408\uff0c\u8981\u6c42\u5206\u522b\u8ba1\u7b97\u6bcf\u4e2a\u57df\u540d\u88ab\u8bbf\u95ee\u7684\u6b21\u6570\u3002\u5176\u683c\u5f0f\u4e3a\u8bbf\u95ee\u6b21\u6570+\u7a7a\u683c+\u5730\u5740\uff0c\u4f8b\u5982\uff1a"9001 discuss.leetcode.com"\u3002

\n\n

\u63a5\u4e0b\u6765\u4f1a\u7ed9\u51fa\u4e00\u7ec4\u8bbf\u95ee\u6b21\u6570\u548c\u57df\u540d\u7ec4\u5408\u7684\u5217\u8868cpdomains \u3002\u8981\u6c42\u89e3\u6790\u51fa\u6240\u6709\u57df\u540d\u7684\u8bbf\u95ee\u6b21\u6570\uff0c\u8f93\u51fa\u683c\u5f0f\u548c\u8f93\u5165\u683c\u5f0f\u76f8\u540c\uff0c\u4e0d\u9650\u5b9a\u5148\u540e\u987a\u5e8f\u3002

\n\n
\n\u793a\u4f8b 1:\n\u8f93\u5165: \n["9001 discuss.leetcode.com"]\n\u8f93\u51fa: \n["9001 discuss.leetcode.com", "9001 leetcode.com", "9001 com"]\n\u8bf4\u660e: \n\u4f8b\u5b50\u4e2d\u4ec5\u5305\u542b\u4e00\u4e2a\u7f51\u7ad9\u57df\u540d\uff1a"discuss.leetcode.com"\u3002\u6309\u7167\u524d\u6587\u5047\u8bbe\uff0c\u5b50\u57df\u540d"leetcode.com"\u548c"com"\u90fd\u4f1a\u88ab\u8bbf\u95ee\uff0c\u6240\u4ee5\u5b83\u4eec\u90fd\u88ab\u8bbf\u95ee\u4e869001\u6b21\u3002\n
\n\n
\n\u793a\u4f8b 2\n\u8f93\u5165: \n["900 google.mail.com", "50 yahoo.com", "1 intel.mail.com", "5 wiki.org"]\n\u8f93\u51fa: \n["901 mail.com","50 yahoo.com","900 google.mail.com","5 wiki.org","5 org","1 intel.mail.com","951 com"]\n\u8bf4\u660e: \n\u6309\u7167\u5047\u8bbe\uff0c\u4f1a\u8bbf\u95ee"google.mail.com" 900\u6b21\uff0c"yahoo.com" 50\u6b21\uff0c"intel.mail.com" 1\u6b21\uff0c"wiki.org" 5\u6b21\u3002\n\u800c\u5bf9\u4e8e\u7236\u57df\u540d\uff0c\u4f1a\u8bbf\u95ee"mail.com" 900+1 = 901\u6b21\uff0c"com" 900 + 50 + 1 = 951\u6b21\uff0c\u548c "org" 5 \u6b21\u3002\n
\n\n

\u6ce8\u610f\u4e8b\u9879\uff1a

\n\n
    \n\t
  •  cpdomains \u7684\u957f\u5ea6\u5c0f\u4e8e 100\u3002
  • \n\t
  • \u6bcf\u4e2a\u57df\u540d\u7684\u957f\u5ea6\u5c0f\u4e8e100\u3002
  • \n\t
  • \u6bcf\u4e2a\u57df\u540d\u5730\u5740\u5305\u542b\u4e00\u4e2a\u6216\u4e24\u4e2a"."\u7b26\u53f7\u3002
  • \n\t
  • \u8f93\u5165\u4e2d\u4efb\u610f\u4e00\u4e2a\u57df\u540d\u7684\u8bbf\u95ee\u6b21\u6570\u90fd\u5c0f\u4e8e10000\u3002
  • \n
\n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector subdomainVisits(vector& cpdomains) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List subdomainVisits(String[] cpdomains) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def subdomainVisits(self, cpdomains):\n \"\"\"\n :type cpdomains: List[str]\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def subdomainVisits(self, cpdomains: List[str]) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** subdomainVisits(char ** cpdomains, int cpdomainsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList SubdomainVisits(string[] cpdomains) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} cpdomains\n * @return {string[]}\n */\nvar subdomainVisits = function(cpdomains) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} cpdomains\n# @return {String[]}\ndef subdomain_visits(cpdomains)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func subdomainVisits(_ cpdomains: [String]) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func subdomainVisits(cpdomains []string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def subdomainVisits(cpdomains: Array[String]): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun subdomainVisits(cpdomains: Array): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn subdomain_visits(cpdomains: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $cpdomains\n * @return String[]\n */\n function subdomainVisits($cpdomains) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function subdomainVisits(cpdomains: string[]): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (subdomain-visits cpdomains)\n (-> (listof string?) (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0811](https://leetcode-cn.com/problems/subdomain-visit-count)", "[\u5b50\u57df\u540d\u8bbf\u95ee\u8ba1\u6570](/solution/0800-0899/0811.Subdomain%20Visit%20Count/README.md)", "`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0811](https://leetcode.com/problems/subdomain-visit-count)", "[Subdomain Visit Count](/solution/0800-0899/0811.Subdomain%20Visit%20Count/README_EN.md)", "`Hash Table`", "Easy", ""]}, {"question_id": "0828", "frontend_question_id": "0810", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/chalkboard-xor-game", "url_en": "https://leetcode.com/problems/chalkboard-xor-game", "relative_path_cn": "/solution/0800-0899/0810.Chalkboard%20XOR%20Game/README.md", "relative_path_en": "/solution/0800-0899/0810.Chalkboard%20XOR%20Game/README_EN.md", "title_cn": "\u9ed1\u677f\u5f02\u6216\u6e38\u620f", "title_en": "Chalkboard XOR Game", "question_title_slug": "chalkboard-xor-game", "content_en": "

We are given non-negative integers nums[i] which are written on a chalkboard.  Alice and Bob take turns erasing exactly one number from the chalkboard, with Alice starting first.  If erasing a number causes the bitwise XOR of all the elements of the chalkboard to become 0, then that player loses.  (Also, we'll say the bitwise XOR of one element is that element itself, and the bitwise XOR of no elements is 0.)

\r\n\r\n

Also, if any player starts their turn with the bitwise XOR of all the elements of the chalkboard equal to 0, then that player wins.

\r\n\r\n

Return True if and only if Alice wins the game, assuming both players play optimally.

\r\n\r\n
\r\nExample:\r\nInput: nums = [1, 1, 2]\r\nOutput: false\r\nExplanation: \r\nAlice has two choices: erase 1 or erase 2. \r\nIf she erases 1, the nums array becomes [1, 2]. The bitwise XOR of all the elements of the chalkboard is 1 XOR 2 = 3. Now Bob can remove any element he wants, because Alice will be the one to erase the last element and she will lose. \r\nIf Alice erases 2 first, now nums becomes [1, 1]. The bitwise XOR of all the elements of the chalkboard is 1 XOR 1 = 0. Alice will lose.\r\n\r\n
\r\n\r\n

Notes:

\r\n\r\n
    \r\n\t
  • 1 <= N <= 1000
  • \r\n\t
  • 0 <= nums[i] <= 2^16.
  • \r\n
\r\n\r\n

 

\r\n", "content_cn": "

\u9ed1\u677f\u4e0a\u5199\u7740\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\u6570\u7ec4 nums[i] \u3002Alice \u548c Bob \u8f6e\u6d41\u4ece\u9ed1\u677f\u4e0a\u64e6\u6389\u4e00\u4e2a\u6570\u5b57\uff0cAlice \u5148\u624b\u3002\u5982\u679c\u64e6\u9664\u4e00\u4e2a\u6570\u5b57\u540e\uff0c\u5269\u4f59\u7684\u6240\u6709\u6570\u5b57\u6309\u4f4d\u5f02\u6216\u8fd0\u7b97\u5f97\u51fa\u7684\u7ed3\u679c\u7b49\u4e8e 0 \u7684\u8bdd\uff0c\u5f53\u524d\u73a9\u5bb6\u6e38\u620f\u5931\u8d25\u3002\u00a0(\u53e6\u5916\uff0c\u5982\u679c\u53ea\u5269\u4e00\u4e2a\u6570\u5b57\uff0c\u6309\u4f4d\u5f02\u6216\u8fd0\u7b97\u5f97\u5230\u5b83\u672c\u8eab\uff1b\u5982\u679c\u65e0\u6570\u5b57\u5269\u4f59\uff0c\u6309\u4f4d\u5f02\u6216\u8fd0\u7b97\u7ed3\u679c\u4e3a\u00a00\u3002\uff09

\n\n

\u5e76\u4e14\uff0c\u8f6e\u5230\u67d0\u4e2a\u73a9\u5bb6\u65f6\uff0c\u5982\u679c\u5f53\u524d\u9ed1\u677f\u4e0a\u6240\u6709\u6570\u5b57\u6309\u4f4d\u5f02\u6216\u8fd0\u7b97\u7ed3\u679c\u7b49\u4e8e 0\uff0c\u8fd9\u4e2a\u73a9\u5bb6\u83b7\u80dc\u3002

\n\n

\u5047\u8bbe\u4e24\u4e2a\u73a9\u5bb6\u6bcf\u6b65\u90fd\u4f7f\u7528\u6700\u4f18\u89e3\uff0c\u5f53\u4e14\u4ec5\u5f53 Alice \u83b7\u80dc\u65f6\u8fd4\u56de true\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b\uff1a

\n\n
\n\u8f93\u5165: nums = [1, 1, 2]\n\u8f93\u51fa: false\n\u89e3\u91ca: \nAlice \u6709\u4e24\u4e2a\u9009\u62e9: \u64e6\u6389\u6570\u5b57 1 \u6216 2\u3002\n\u5982\u679c\u64e6\u6389 1, \u6570\u7ec4\u53d8\u6210 [1, 2]\u3002\u5269\u4f59\u6570\u5b57\u6309\u4f4d\u5f02\u6216\u5f97\u5230 1 XOR 2 = 3\u3002\u90a3\u4e48 Bob \u53ef\u4ee5\u64e6\u6389\u4efb\u610f\u6570\u5b57\uff0c\u56e0\u4e3a Alice \u4f1a\u6210\u4e3a\u64e6\u6389\u6700\u540e\u4e00\u4e2a\u6570\u5b57\u7684\u4eba\uff0c\u5979\u603b\u662f\u4f1a\u8f93\u3002\n\u5982\u679c Alice \u64e6\u6389 2\uff0c\u90a3\u4e48\u6570\u7ec4\u53d8\u6210[1, 1]\u3002\u5269\u4f59\u6570\u5b57\u6309\u4f4d\u5f02\u6216\u5f97\u5230 1 XOR 1 = 0\u3002Alice \u4ecd\u7136\u4f1a\u8f93\u6389\u6e38\u620f\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= N <= 1000
  • \n\t
  • 0 <= nums[i] <= 2^16
  • \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool xorGame(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean xorGame(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def xorGame(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: bool\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def xorGame(self, nums: List[int]) -> bool:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool xorGame(int* nums, int numsSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool XorGame(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {boolean}\n */\nvar xorGame = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Boolean}\ndef xor_game(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func xorGame(_ nums: [Int]) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func xorGame(nums []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def xorGame(nums: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun xorGame(nums: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn xor_game(nums: Vec) -> bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Boolean\n */\n function xorGame($nums) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function xorGame(nums: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (xor-game nums)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0810](https://leetcode-cn.com/problems/chalkboard-xor-game)", "[\u9ed1\u677f\u5f02\u6216\u6e38\u620f](/solution/0800-0899/0810.Chalkboard%20XOR%20Game/README.md)", "`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[0810](https://leetcode.com/problems/chalkboard-xor-game)", "[Chalkboard XOR Game](/solution/0800-0899/0810.Chalkboard%20XOR%20Game/README_EN.md)", "`Math`", "Hard", ""]}, {"question_id": "0827", "frontend_question_id": "0809", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/expressive-words", "url_en": "https://leetcode.com/problems/expressive-words", "relative_path_cn": "/solution/0800-0899/0809.Expressive%20Words/README.md", "relative_path_en": "/solution/0800-0899/0809.Expressive%20Words/README_EN.md", "title_cn": "\u60c5\u611f\u4e30\u5bcc\u7684\u6587\u5b57", "title_en": "Expressive Words", "question_title_slug": "expressive-words", "content_en": "

Sometimes people repeat letters to represent extra feeling, such as "hello" -> "heeellooo", "hi" -> "hiiii".  In these strings like "heeellooo", we have groups of adjacent letters that are all the same:  "h", "eee", "ll", "ooo".

\n\n

For some given string s, a query word is stretchy if it can be made to be equal to s by any number of applications of the following extension operation: choose a group consisting of characters c, and add some number of characters c to the group so that the size of the group is 3 or more.

\n\n

For example, starting with "hello", we could do an extension on the group "o" to get "hellooo", but we cannot get "helloo" since the group "oo" has size less than 3.  Also, we could do another extension like "ll" -> "lllll" to get "helllllooo".  If s = "helllllooo", then the query word "hello" would be stretchy because of these two extension operations: query = "hello" -> "hellooo" -> "helllllooo" = s.

\n\n

Given a list of query words, return the number of words that are stretchy. 

\n\n

 

\n\n
\nExample:\nInput: \ns = "heeellooo"\nwords = ["hello", "hi", "helo"]\nOutput: 1\nExplanation: \nWe can extend "e" and "o" in the word "hello" to get "heeellooo".\nWe can't extend "helo" to get "heeellooo" because the group "ll" is not size 3 or more.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 0 <= len(s) <= 100.
  • \n\t
  • 0 <= len(words) <= 100.
  • \n\t
  • 0 <= len(words[i]) <= 100.
  • \n\t
  • s and all words in words consist only of lowercase letters
  • \n
\n", "content_cn": "

\u6709\u65f6\u5019\u4eba\u4eec\u4f1a\u7528\u91cd\u590d\u5199\u4e00\u4e9b\u5b57\u6bcd\u6765\u8868\u793a\u989d\u5916\u7684\u611f\u53d7\uff0c\u6bd4\u5982 \"hello\" -> \"heeellooo\", \"hi\" -> \"hiii\"\u3002\u6211\u4eec\u5c06\u76f8\u90bb\u5b57\u6bcd\u90fd\u76f8\u540c\u7684\u4e00\u4e32\u5b57\u7b26\u5b9a\u4e49\u4e3a\u76f8\u540c\u5b57\u6bcd\u7ec4\uff0c\u4f8b\u5982\uff1a\"h\", \"eee\", \"ll\", \"ooo\"\u3002

\n\n

\u5bf9\u4e8e\u4e00\u4e2a\u7ed9\u5b9a\u7684\u5b57\u7b26\u4e32 S \uff0c\u5982\u679c\u53e6\u4e00\u4e2a\u5355\u8bcd\u80fd\u591f\u901a\u8fc7\u5c06\u4e00\u4e9b\u5b57\u6bcd\u7ec4\u6269\u5f20\u4ece\u800c\u4f7f\u5176\u548c S \u76f8\u540c\uff0c\u6211\u4eec\u5c06\u8fd9\u4e2a\u5355\u8bcd\u5b9a\u4e49\u4e3a\u53ef\u6269\u5f20\u7684\uff08stretchy\uff09\u3002\u6269\u5f20\u64cd\u4f5c\u5b9a\u4e49\u5982\u4e0b\uff1a\u9009\u62e9\u4e00\u4e2a\u5b57\u6bcd\u7ec4\uff08\u5305\u542b\u5b57\u6bcd\u00a0c\u00a0\uff09\uff0c\u7136\u540e\u5f80\u5176\u4e2d\u6dfb\u52a0\u76f8\u540c\u7684\u5b57\u6bcd\u00a0c\u00a0\u4f7f\u5176\u957f\u5ea6\u8fbe\u5230 3 \u6216\u4ee5\u4e0a\u3002

\n\n

\u4f8b\u5982\uff0c\u4ee5\u00a0\"hello\" \u4e3a\u4f8b\uff0c\u6211\u4eec\u53ef\u4ee5\u5bf9\u5b57\u6bcd\u7ec4\u00a0\"o\" \u6269\u5f20\u5f97\u5230 \"hellooo\"\uff0c\u4f46\u662f\u65e0\u6cd5\u4ee5\u540c\u6837\u7684\u65b9\u6cd5\u5f97\u5230 \"helloo\" \u56e0\u4e3a\u5b57\u6bcd\u7ec4 \"oo\" \u957f\u5ea6\u5c0f\u4e8e\u00a03\u3002\u6b64\u5916\uff0c\u6211\u4eec\u53ef\u4ee5\u8fdb\u884c\u53e6\u4e00\u79cd\u6269\u5f20 \"ll\" -> \"lllll\" \u4ee5\u83b7\u5f97\u00a0\"helllllooo\"\u3002\u5982\u679c\u00a0S = \"helllllooo\"\uff0c\u90a3\u4e48\u67e5\u8be2\u8bcd\u00a0\"hello\" \u662f\u53ef\u6269\u5f20\u7684\uff0c\u56e0\u4e3a\u53ef\u4ee5\u5bf9\u5b83\u6267\u884c\u8fd9\u4e24\u79cd\u6269\u5f20\u64cd\u4f5c\u4f7f\u5f97\u00a0query = \"hello\" -> \"hellooo\" ->\u00a0\"helllllooo\" = S\u3002

\n\n

\u8f93\u5165\u4e00\u7ec4\u67e5\u8be2\u5355\u8bcd\uff0c\u8f93\u51fa\u5176\u4e2d\u53ef\u6269\u5f20\u7684\u5355\u8bcd\u6570\u91cf\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b\uff1a

\n\n
\n\u8f93\u5165\uff1a \nS = \"heeellooo\"\nwords = [\"hello\", \"hi\", \"helo\"]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\n\u6211\u4eec\u80fd\u901a\u8fc7\u6269\u5f20 \"hello\" \u7684 \"e\" \u548c \"o\" \u6765\u5f97\u5230 \"heeellooo\"\u3002\n\u6211\u4eec\u4e0d\u80fd\u901a\u8fc7\u6269\u5f20 \"helo\" \u6765\u5f97\u5230 \"heeellooo\" \u56e0\u4e3a \"ll\" \u7684\u957f\u5ea6\u5c0f\u4e8e 3 \u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 0 <= len(S) <= 100\u3002
  • \n\t
  • 0 <= len(words) <= 100\u3002
  • \n\t
  • 0 <= len(words[i]) <= 100\u3002
  • \n\t
  • S\u00a0\u548c\u6240\u6709\u5728\u00a0words\u00a0\u4e2d\u7684\u5355\u8bcd\u90fd\u53ea\u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210\u3002
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int expressiveWords(string s, vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int expressiveWords(String s, String[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def expressiveWords(self, s, words):\n \"\"\"\n :type s: str\n :type words: List[str]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def expressiveWords(self, s: str, words: List[str]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint expressiveWords(char * s, char ** words, int wordsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ExpressiveWords(string s, string[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string[]} words\n * @return {number}\n */\nvar expressiveWords = function(s, words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String[]} words\n# @return {Integer}\ndef expressive_words(s, words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func expressiveWords(_ s: String, _ words: [String]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func expressiveWords(s string, words []string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def expressiveWords(s: String, words: Array[String]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun expressiveWords(s: String, words: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn expressive_words(s: String, words: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String[] $words\n * @return Integer\n */\n function expressiveWords($s, $words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function expressiveWords(s: string, words: string[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (expressive-words s words)\n (-> string? (listof string?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0809](https://leetcode-cn.com/problems/expressive-words)", "[\u60c5\u611f\u4e30\u5bcc\u7684\u6587\u5b57](/solution/0800-0899/0809.Expressive%20Words/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0809](https://leetcode.com/problems/expressive-words)", "[Expressive Words](/solution/0800-0899/0809.Expressive%20Words/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "0826", "frontend_question_id": "0808", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/soup-servings", "url_en": "https://leetcode.com/problems/soup-servings", "relative_path_cn": "/solution/0800-0899/0808.Soup%20Servings/README.md", "relative_path_en": "/solution/0800-0899/0808.Soup%20Servings/README_EN.md", "title_cn": "\u5206\u6c64", "title_en": "Soup Servings", "question_title_slug": "soup-servings", "content_en": "

There are two types of soup: type A and type B. Initially we have n ml of each type of soup. There are four kinds of operations:

\n\n
    \n\t
  1. Serve 100 ml of soup A and 0 ml of soup B
  2. \n\t
  3. Serve 75 ml of soup A and 25 ml of soup B
  4. \n\t
  5. Serve 50 ml of soup A and 50 ml of soup B
  6. \n\t
  7. Serve 25 ml of soup A and 75 ml of soup B
  8. \n
\n\n

When we serve some soup, we give it to someone and we no longer have it. Each turn, we will choose from the four operations with equal probability 0.25. If the remaining volume of soup is not enough to complete the operation, we will serve as much as we can. We stop once we no longer have some quantity of both types of soup.

\n\n

Note that we do not have the operation where all 100 ml's of soup B are used first.

\n\n

Return the probability that soup A will be empty first, plus half the probability that A and B become empty at the same time.

\n\n

 

\n\n
\nExample:\nInput: n = 50\nOutput: 0.625\nExplanation: \nIf we choose the first two operations, A will become empty first. For the third operation, A and B will become empty at the same time. For the fourth operation, B will become empty first. So the total probability of A becoming empty first plus half the probability that A and B become empty at the same time, is 0.25 * (1 + 1 + 0.5 + 0) = 0.625.\n\n
\n\n

Notes:

\n\n
    \n\t
  • 0 <= n <= 109.
  • \n\t
  • Answers within 10-6 of the true value will be accepted as correct.
  • \n
\n", "content_cn": "

\u6709 A \u548c B \u4e24\u79cd\u7c7b\u578b\u7684\u6c64\u3002\u4e00\u5f00\u59cb\u6bcf\u79cd\u7c7b\u578b\u7684\u6c64\u6709 N \u6beb\u5347\u3002\u6709\u56db\u79cd\u5206\u914d\u64cd\u4f5c\uff1a

\n\n
    \n\t
  1. \u63d0\u4f9b 100ml \u7684\u6c64A \u548c 0ml \u7684\u6c64B\u3002
  2. \n\t
  3. \u63d0\u4f9b 75ml \u7684\u6c64A \u548c 25ml \u7684\u6c64B\u3002
  4. \n\t
  5. \u63d0\u4f9b 50ml \u7684\u6c64A \u548c 50ml \u7684\u6c64B\u3002
  6. \n\t
  7. \u63d0\u4f9b 25ml \u7684\u6c64A \u548c 75ml \u7684\u6c64B\u3002
  8. \n
\n\n

\u5f53\u6211\u4eec\u628a\u6c64\u5206\u914d\u7ed9\u67d0\u4eba\u4e4b\u540e\uff0c\u6c64\u5c31\u6ca1\u6709\u4e86\u3002\u6bcf\u4e2a\u56de\u5408\uff0c\u6211\u4eec\u5c06\u4ece\u56db\u79cd\u6982\u7387\u540c\u4e3a0.25\u7684\u64cd\u4f5c\u4e2d\u8fdb\u884c\u5206\u914d\u9009\u62e9\u3002\u5982\u679c\u6c64\u7684\u5269\u4f59\u91cf\u4e0d\u8db3\u4ee5\u5b8c\u6210\u67d0\u6b21\u64cd\u4f5c\uff0c\u6211\u4eec\u5c06\u5c3d\u53ef\u80fd\u5206\u914d\u3002\u5f53\u4e24\u79cd\u7c7b\u578b\u7684\u6c64\u90fd\u5206\u914d\u5b8c\u65f6\uff0c\u505c\u6b62\u64cd\u4f5c\u3002

\n\n

\u6ce8\u610f\u4e0d\u5b58\u5728\u5148\u5206\u914d100 ml\u6c64B\u7684\u64cd\u4f5c\u3002

\n\n

\u9700\u8981\u8fd4\u56de\u7684\u503c\uff1a \u6c64A\u5148\u5206\u914d\u5b8c\u7684\u6982\u7387 + \u6c64A\u548c\u6c64B\u540c\u65f6\u5206\u914d\u5b8c\u7684\u6982\u7387 / 2\u3002

\n\n
\n\u793a\u4f8b:\n\u8f93\u5165: N = 50\n\u8f93\u51fa: 0.625\n\u89e3\u91ca:\n\u5982\u679c\u6211\u4eec\u9009\u62e9\u524d\u4e24\u4e2a\u64cd\u4f5c\uff0cA\u5c06\u9996\u5148\u53d8\u4e3a\u7a7a\u3002\u5bf9\u4e8e\u7b2c\u4e09\u4e2a\u64cd\u4f5c\uff0cA\u548cB\u4f1a\u540c\u65f6\u53d8\u4e3a\u7a7a\u3002\u5bf9\u4e8e\u7b2c\u56db\u4e2a\u64cd\u4f5c\uff0cB\u5c06\u9996\u5148\u53d8\u4e3a\u7a7a\u3002\n\u6240\u4ee5A\u53d8\u4e3a\u7a7a\u7684\u603b\u6982\u7387\u52a0\u4e0aA\u548cB\u540c\u65f6\u53d8\u4e3a\u7a7a\u7684\u6982\u7387\u7684\u4e00\u534a\u662f 0.25 *(1 + 1 + 0.5 + 0)= 0.625\u3002\n
\n\n

\u6ce8\u91ca:

\n\n
    \n\t
  • 0 <= N <= 10^9\u3002
  • \n\t
  • \n\t

    \u8fd4\u56de\u503c\u5728 10^-6 \u7684\u8303\u56f4\u5c06\u88ab\u8ba4\u4e3a\u662f\u6b63\u786e\u7684\u3002

    \n\t
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n double soupServings(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double soupServings(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def soupServings(self, n):\n \"\"\"\n :type n: int\n :rtype: float\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def soupServings(self, n: int) -> float:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\ndouble soupServings(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double SoupServings(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar soupServings = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Float}\ndef soup_servings(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func soupServings(_ n: Int) -> Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func soupServings(n int) float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def soupServings(n: Int): Double = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun soupServings(n: Int): Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn soup_servings(n: i32) -> f64 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Float\n */\n function soupServings($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function soupServings(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (soup-servings n)\n (-> exact-integer? flonum?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0808](https://leetcode-cn.com/problems/soup-servings)", "[\u5206\u6c64](/solution/0800-0899/0808.Soup%20Servings/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0808](https://leetcode.com/problems/soup-servings)", "[Soup Servings](/solution/0800-0899/0808.Soup%20Servings/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0825", "frontend_question_id": "0807", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/max-increase-to-keep-city-skyline", "url_en": "https://leetcode.com/problems/max-increase-to-keep-city-skyline", "relative_path_cn": "/solution/0800-0899/0807.Max%20Increase%20to%20Keep%20City%20Skyline/README.md", "relative_path_en": "/solution/0800-0899/0807.Max%20Increase%20to%20Keep%20City%20Skyline/README_EN.md", "title_cn": "\u4fdd\u6301\u57ce\u5e02\u5929\u9645\u7ebf", "title_en": "Max Increase to Keep City Skyline", "question_title_slug": "max-increase-to-keep-city-skyline", "content_en": "

In a 2 dimensional array grid, each value grid[i][j] represents the height of a building located there. We are allowed to increase the height of any number of buildings, by any amount (the amounts can be different for different buildings). Height 0 is considered to be a building as well. 

\r\n\r\n

At the end, the "skyline" when viewed from all four directions of the grid, i.e. top, bottom, left, and right, must be the same as the skyline of the original grid. A city's skyline is the outer contour of the rectangles formed by all the buildings when viewed from a distance. See the following example.

\r\n\r\n

What is the maximum total sum that the height of the buildings can be increased?

\r\n\r\n
\r\nExample:\r\nInput: grid = [[3,0,8,4],[2,4,5,7],[9,2,6,3],[0,3,1,0]]\r\nOutput: 35\r\nExplanation: \r\nThe grid is:\r\n[ [3, 0, 8, 4], \r\n  [2, 4, 5, 7],\r\n  [9, 2, 6, 3],\r\n  [0, 3, 1, 0] ]\r\n\r\nThe skyline viewed from top or bottom is: [9, 4, 8, 7]\r\nThe skyline viewed from left or right is: [8, 7, 9, 3]\r\n\r\nThe grid after increasing the height of buildings without affecting skylines is:\r\n\r\ngridNew = [ [8, 4, 8, 7],\r\n            [7, 4, 7, 7],\r\n            [9, 4, 8, 7],\r\n            [3, 3, 3, 3] ]\r\n\r\n
\r\n\r\n

Notes:

\r\n\r\n
    \r\n\t
  • 1 < grid.length = grid[0].length <= 50.
  • \r\n\t
  • All heights grid[i][j] are in the range [0, 100].
  • \r\n\t
  • All buildings in grid[i][j] occupy the entire grid cell: that is, they are a 1 x 1 x grid[i][j] rectangular prism.
  • \r\n
\r\n", "content_cn": "

\u5728\u4e8c\u7ef4\u6570\u7ec4grid\u4e2d\uff0cgrid[i][j]\u4ee3\u8868\u4f4d\u4e8e\u67d0\u5904\u7684\u5efa\u7b51\u7269\u7684\u9ad8\u5ea6\u3002 \u6211\u4eec\u88ab\u5141\u8bb8\u589e\u52a0\u4efb\u4f55\u6570\u91cf\uff08\u4e0d\u540c\u5efa\u7b51\u7269\u7684\u6570\u91cf\u53ef\u80fd\u4e0d\u540c\uff09\u7684\u5efa\u7b51\u7269\u7684\u9ad8\u5ea6\u3002 \u9ad8\u5ea6 0 \u4e5f\u88ab\u8ba4\u4e3a\u662f\u5efa\u7b51\u7269\u3002

\n\n

\u6700\u540e\uff0c\u4ece\u65b0\u6570\u7ec4\u7684\u6240\u6709\u56db\u4e2a\u65b9\u5411\uff08\u5373\u9876\u90e8\uff0c\u5e95\u90e8\uff0c\u5de6\u4fa7\u548c\u53f3\u4fa7\uff09\u89c2\u770b\u7684“\u5929\u9645\u7ebf”\u5fc5\u987b\u4e0e\u539f\u59cb\u6570\u7ec4\u7684\u5929\u9645\u7ebf\u76f8\u540c\u3002 \u57ce\u5e02\u7684\u5929\u9645\u7ebf\u662f\u4ece\u8fdc\u5904\u89c2\u770b\u65f6\uff0c\u7531\u6240\u6709\u5efa\u7b51\u7269\u5f62\u6210\u7684\u77e9\u5f62\u7684\u5916\u90e8\u8f6e\u5ed3\u3002 \u8bf7\u770b\u4e0b\u9762\u7684\u4f8b\u5b50\u3002

\n\n

\u5efa\u7b51\u7269\u9ad8\u5ea6\u53ef\u4ee5\u589e\u52a0\u7684\u6700\u5927\u603b\u548c\u662f\u591a\u5c11\uff1f

\n\n
\n\u4f8b\u5b50\uff1a\n\u8f93\u5165\uff1a grid = [[3,0,8,4],[2,4,5,7],[9,2,6,3],[0,3,1,0]]\n\u8f93\u51fa\uff1a 35\n\u89e3\u91ca\uff1a \nThe grid is:\n[ [3, 0, 8, 4], \n  [2, 4, 5, 7],\n  [9, 2, 6, 3],\n  [0, 3, 1, 0] ]\n\n\u4ece\u6570\u7ec4\u7ad6\u76f4\u65b9\u5411\uff08\u5373\u9876\u90e8\uff0c\u5e95\u90e8\uff09\u770b“\u5929\u9645\u7ebf”\u662f\uff1a[9, 4, 8, 7]\n\u4ece\u6c34\u5e73\u6c34\u5e73\u65b9\u5411\uff08\u5373\u5de6\u4fa7\uff0c\u53f3\u4fa7\uff09\u770b“\u5929\u9645\u7ebf”\u662f\uff1a[8, 7, 9, 3]\n\n\u5728\u4e0d\u5f71\u54cd\u5929\u9645\u7ebf\u7684\u60c5\u51b5\u4e0b\u5bf9\u5efa\u7b51\u7269\u8fdb\u884c\u589e\u9ad8\u540e\uff0c\u65b0\u6570\u7ec4\u5982\u4e0b\uff1a\n\ngridNew = [ [8, 4, 8, 7],\n            [7, 4, 7, 7],\n            [9, 4, 8, 7],\n            [3, 3, 3, 3] ]\n
\n\n

\u8bf4\u660e:

\n\n
    \n\t
  • 1 < grid.length = grid[0].length <= 50\u3002
  • \n\t
  •  grid[i][j] \u7684\u9ad8\u5ea6\u8303\u56f4\u662f\uff1a [0, 100]\u3002
  • \n\t
  • \u4e00\u5ea7\u5efa\u7b51\u7269\u5360\u636e\u4e00\u4e2agrid[i][j]\uff1a\u6362\u8a00\u4e4b\uff0c\u5b83\u4eec\u662f 1 x 1 x grid[i][j] \u7684\u957f\u65b9\u4f53\u3002
  • \n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxIncreaseKeepingSkyline(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxIncreaseKeepingSkyline(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxIncreaseKeepingSkyline(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxIncreaseKeepingSkyline(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxIncreaseKeepingSkyline(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxIncreaseKeepingSkyline(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar maxIncreaseKeepingSkyline = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef max_increase_keeping_skyline(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxIncreaseKeepingSkyline(_ grid: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxIncreaseKeepingSkyline(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxIncreaseKeepingSkyline(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxIncreaseKeepingSkyline(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_increase_keeping_skyline(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function maxIncreaseKeepingSkyline($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxIncreaseKeepingSkyline(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-increase-keeping-skyline grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0807](https://leetcode-cn.com/problems/max-increase-to-keep-city-skyline)", "[\u4fdd\u6301\u57ce\u5e02\u5929\u9645\u7ebf](/solution/0800-0899/0807.Max%20Increase%20to%20Keep%20City%20Skyline/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0807](https://leetcode.com/problems/max-increase-to-keep-city-skyline)", "[Max Increase to Keep City Skyline](/solution/0800-0899/0807.Max%20Increase%20to%20Keep%20City%20Skyline/README_EN.md)", "", "Medium", ""]}, {"question_id": "0824", "frontend_question_id": "0806", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-lines-to-write-string", "url_en": "https://leetcode.com/problems/number-of-lines-to-write-string", "relative_path_cn": "/solution/0800-0899/0806.Number%20of%20Lines%20To%20Write%20String/README.md", "relative_path_en": "/solution/0800-0899/0806.Number%20of%20Lines%20To%20Write%20String/README_EN.md", "title_cn": "\u5199\u5b57\u7b26\u4e32\u9700\u8981\u7684\u884c\u6570", "title_en": "Number of Lines To Write String", "question_title_slug": "number-of-lines-to-write-string", "content_en": "

You are given a string s of lowercase English letters and an array widths denoting how many pixels wide each lowercase English letter is. Specifically, widths[0] is the width of 'a', widths[1] is the width of 'b', and so on.

\n\n

You are trying to write s across several lines, where each line is no longer than 100 pixels. Starting at the beginning of s, write as many letters on the first line such that the total width does not exceed 100 pixels. Then, from where you stopped in s, continue writing as many letters as you can on the second line. Continue this process until you have written all of s.

\n\n

Return an array result of length 2 where:

\n\n
    \n\t
  • result[0] is the total number of lines.
  • \n\t
  • result[1] is the width of the last line in pixels.
  • \n
\n\n

 

\n

Example 1:

\n\n
\nInput: widths = [10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10], s = "abcdefghijklmnopqrstuvwxyz"\nOutput: [3,60]\nExplanation: You can write s as follows:\nabcdefghij  // 100 pixels wide\nklmnopqrst  // 100 pixels wide\nuvwxyz      // 60 pixels wide\nThere are a total of 3 lines, and the last line is 60 pixels wide.
\n\n

Example 2:

\n\n
\nInput: widths = [4,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10], s = "bbbcccdddaaa"\nOutput: [2,4]\nExplanation: You can write s as follows:\nbbbcccdddaa  // 98 pixels wide\na            // 4 pixels wide\nThere are a total of 2 lines, and the last line is 4 pixels wide.
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • widths.length == 26
  • \n\t
  • 2 <= widths[i] <= 10
  • \n\t
  • 1 <= s.length <= 1000
  • \n\t
  • s contains only lowercase English letters.
  • \n
\n", "content_cn": "

\u6211\u4eec\u8981\u628a\u7ed9\u5b9a\u7684\u5b57\u7b26\u4e32 S \u4ece\u5de6\u5230\u53f3\u5199\u5230\u6bcf\u4e00\u884c\u4e0a\uff0c\u6bcf\u4e00\u884c\u7684\u6700\u5927\u5bbd\u5ea6\u4e3a100\u4e2a\u5355\u4f4d\uff0c\u5982\u679c\u6211\u4eec\u5728\u5199\u67d0\u4e2a\u5b57\u6bcd\u7684\u65f6\u5019\u4f1a\u4f7f\u8fd9\u884c\u8d85\u8fc7\u4e86100 \u4e2a\u5355\u4f4d\uff0c\u90a3\u4e48\u6211\u4eec\u5e94\u8be5\u628a\u8fd9\u4e2a\u5b57\u6bcd\u5199\u5230\u4e0b\u4e00\u884c\u3002\u6211\u4eec\u7ed9\u5b9a\u4e86\u4e00\u4e2a\u6570\u7ec4 widths \uff0c\u8fd9\u4e2a\u6570\u7ec4 widths[0] \u4ee3\u8868 'a' \u9700\u8981\u7684\u5355\u4f4d\uff0c widths[1] \u4ee3\u8868 'b' \u9700\u8981\u7684\u5355\u4f4d\uff0c...\uff0c widths[25] \u4ee3\u8868 'z' \u9700\u8981\u7684\u5355\u4f4d\u3002

\n\n

\u73b0\u5728\u56de\u7b54\u4e24\u4e2a\u95ee\u9898\uff1a\u81f3\u5c11\u591a\u5c11\u884c\u80fd\u653e\u4e0bS\uff0c\u4ee5\u53ca\u6700\u540e\u4e00\u884c\u4f7f\u7528\u7684\u5bbd\u5ea6\u662f\u591a\u5c11\u4e2a\u5355\u4f4d\uff1f\u5c06\u4f60\u7684\u7b54\u6848\u4f5c\u4e3a\u957f\u5ea6\u4e3a2\u7684\u6574\u6570\u5217\u8868\u8fd4\u56de\u3002

\n\n
\n\u793a\u4f8b 1:\n\u8f93\u5165: \nwidths = [10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10]\nS = "abcdefghijklmnopqrstuvwxyz"\n\u8f93\u51fa: [3, 60]\n\u89e3\u91ca: \n\u6240\u6709\u7684\u5b57\u7b26\u62e5\u6709\u76f8\u540c\u7684\u5360\u7528\u5355\u4f4d10\u3002\u6240\u4ee5\u4e66\u5199\u6240\u6709\u768426\u4e2a\u5b57\u6bcd\uff0c\n\u6211\u4eec\u9700\u89812\u4e2a\u6574\u884c\u548c\u5360\u752860\u4e2a\u5355\u4f4d\u7684\u4e00\u884c\u3002\n
\n\n
\n\u793a\u4f8b 2:\n\u8f93\u5165: \nwidths = [4,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10]\nS = "bbbcccdddaaa"\n\u8f93\u51fa: [2, 4]\n\u89e3\u91ca: \n\u9664\u53bb\u5b57\u6bcd'a'\u6240\u6709\u7684\u5b57\u7b26\u90fd\u662f\u76f8\u540c\u7684\u5355\u4f4d10\uff0c\u5e76\u4e14\u5b57\u7b26\u4e32 "bbbcccdddaa" \u5c06\u4f1a\u8986\u76d6 9 * 10 + 2 * 4 = 98 \u4e2a\u5355\u4f4d.\n\u6700\u540e\u4e00\u4e2a\u5b57\u6bcd 'a' \u5c06\u4f1a\u88ab\u5199\u5230\u7b2c\u4e8c\u884c\uff0c\u56e0\u4e3a\u7b2c\u4e00\u884c\u53ea\u5269\u4e0b2\u4e2a\u5355\u4f4d\u4e86\u3002\n\u6240\u4ee5\uff0c\u8fd9\u4e2a\u7b54\u6848\u662f2\u884c\uff0c\u7b2c\u4e8c\u884c\u67094\u4e2a\u5355\u4f4d\u5bbd\u5ea6\u3002\n
\n\n

 

\n\n

\u6ce8:

\n\n
    \n\t
  • \u5b57\u7b26\u4e32 S \u7684\u957f\u5ea6\u5728 [1, 1000] \u7684\u8303\u56f4\u3002
  • \n\t
  • S \u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd\u3002
  • \n\t
  • widths \u662f\u957f\u5ea6\u4e3a 26\u7684\u6570\u7ec4\u3002
  • \n\t
  • widths[i] \u503c\u7684\u8303\u56f4\u5728 [2, 10]\u3002
  • \n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector numberOfLines(vector& widths, string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] numberOfLines(int[] widths, String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numberOfLines(self, widths, s):\n \"\"\"\n :type widths: List[int]\n :type s: str\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numberOfLines(self, widths: List[int], s: str) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* numberOfLines(int* widths, int widthsSize, char * s, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] NumberOfLines(int[] widths, string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} widths\n * @param {string} s\n * @return {number[]}\n */\nvar numberOfLines = function(widths, s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} widths\n# @param {String} s\n# @return {Integer[]}\ndef number_of_lines(widths, s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numberOfLines(_ widths: [Int], _ s: String) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numberOfLines(widths []int, s string) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numberOfLines(widths: Array[Int], s: String): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numberOfLines(widths: IntArray, s: String): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn number_of_lines(widths: Vec, s: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $widths\n * @param String $s\n * @return Integer[]\n */\n function numberOfLines($widths, $s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numberOfLines(widths: number[], s: string): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (number-of-lines widths s)\n (-> (listof exact-integer?) string? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0806](https://leetcode-cn.com/problems/number-of-lines-to-write-string)", "[\u5199\u5b57\u7b26\u4e32\u9700\u8981\u7684\u884c\u6570](/solution/0800-0899/0806.Number%20of%20Lines%20To%20Write%20String/README.md)", "", "\u7b80\u5355", ""], "md_table_row_en": ["[0806](https://leetcode.com/problems/number-of-lines-to-write-string)", "[Number of Lines To Write String](/solution/0800-0899/0806.Number%20of%20Lines%20To%20Write%20String/README_EN.md)", "", "Easy", ""]}, {"question_id": "0823", "frontend_question_id": "0805", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/split-array-with-same-average", "url_en": "https://leetcode.com/problems/split-array-with-same-average", "relative_path_cn": "/solution/0800-0899/0805.Split%20Array%20With%20Same%20Average/README.md", "relative_path_en": "/solution/0800-0899/0805.Split%20Array%20With%20Same%20Average/README_EN.md", "title_cn": "\u6570\u7ec4\u7684\u5747\u503c\u5206\u5272", "title_en": "Split Array With Same Average", "question_title_slug": "split-array-with-same-average", "content_en": "

You are given an integer array nums.

\n\n

You should move each element of nums into one of the two arrays A and B such that A and B are non-empty, and average(A) == average(B).

\n\n

Return true if it is possible to achieve that and false otherwise.

\n\n

Note that for an array arr, average(arr) is the sum of all the elements of arr over the length of arr.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [1,2,3,4,5,6,7,8]\nOutput: true\nExplanation: We can split the array into [1,4,5,8] and [2,3,6,7], and both of them have an average of 4.5.\n
\n\n

Example 2:

\n\n
\nInput: nums = [3,1]\nOutput: false\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 30
  • \n\t
  • 0 <= nums[i] <= 104
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u7684\u6574\u6570\u6570\u7ec4 A \uff0c\u6211\u4eec\u8981\u5c06 A\u6570\u7ec4 \u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u79fb\u52a8\u5230 B\u6570\u7ec4 \u6216\u8005 C\u6570\u7ec4\u4e2d\u3002\uff08B\u6570\u7ec4\u548cC\u6570\u7ec4\u5728\u5f00\u59cb\u7684\u65f6\u5019\u90fd\u4e3a\u7a7a\uff09

\n\n

\u8fd4\u56detrue \uff0c\u5f53\u4e14\u4ec5\u5f53\u5728\u6211\u4eec\u7684\u5b8c\u6210\u8fd9\u6837\u7684\u79fb\u52a8\u540e\uff0c\u53ef\u4f7f\u5f97B\u6570\u7ec4\u7684\u5e73\u5747\u503c\u548cC\u6570\u7ec4\u7684\u5e73\u5747\u503c\u76f8\u7b49\uff0c\u5e76\u4e14B\u6570\u7ec4\u548cC\u6570\u7ec4\u90fd\u4e0d\u4e3a\u7a7a\u3002

\n\n
\n\u793a\u4f8b:\n\u8f93\u5165: \n[1,2,3,4,5,6,7,8]\n\u8f93\u51fa: true\n\u89e3\u91ca: \u6211\u4eec\u53ef\u4ee5\u5c06\u6570\u7ec4\u5206\u5272\u4e3a [1,4,5,8] \u548c [2,3,6,7], \u4ed6\u4eec\u7684\u5e73\u5747\u503c\u90fd\u662f4.5\u3002\n
\n\n

\u6ce8\u610f:

\n\n
    \n\t
  • A \u6570\u7ec4\u7684\u957f\u5ea6\u8303\u56f4\u4e3a [1, 30].
  • \n\t
  • A[i] \u7684\u6570\u636e\u8303\u56f4\u4e3a [0, 10000].
  • \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool splitArraySameAverage(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean splitArraySameAverage(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def splitArraySameAverage(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def splitArraySameAverage(self, nums: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool splitArraySameAverage(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool SplitArraySameAverage(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {boolean}\n */\nvar splitArraySameAverage = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Boolean}\ndef split_array_same_average(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func splitArraySameAverage(_ nums: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func splitArraySameAverage(nums []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def splitArraySameAverage(nums: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun splitArraySameAverage(nums: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn split_array_same_average(nums: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Boolean\n */\n function splitArraySameAverage($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function splitArraySameAverage(nums: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (split-array-same-average nums)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0805](https://leetcode-cn.com/problems/split-array-with-same-average)", "[\u6570\u7ec4\u7684\u5747\u503c\u5206\u5272](/solution/0800-0899/0805.Split%20Array%20With%20Same%20Average/README.md)", "`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[0805](https://leetcode.com/problems/split-array-with-same-average)", "[Split Array With Same Average](/solution/0800-0899/0805.Split%20Array%20With%20Same%20Average/README_EN.md)", "`Math`", "Hard", ""]}, {"question_id": "0822", "frontend_question_id": "0804", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/unique-morse-code-words", "url_en": "https://leetcode.com/problems/unique-morse-code-words", "relative_path_cn": "/solution/0800-0899/0804.Unique%20Morse%20Code%20Words/README.md", "relative_path_en": "/solution/0800-0899/0804.Unique%20Morse%20Code%20Words/README_EN.md", "title_cn": "\u552f\u4e00\u6469\u5c14\u65af\u5bc6\u7801\u8bcd", "title_en": "Unique Morse Code Words", "question_title_slug": "unique-morse-code-words", "content_en": "

International Morse Code defines a standard encoding where each letter is mapped to a series of dots and dashes, as follows: "a" maps to ".-", "b" maps to "-...", "c" maps to "-.-.", and so on.

\n\n

For convenience, the full table for the 26 letters of the English alphabet is given below:

\n\n
\n[".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."]
\n\n

Now, given a list of words, each word can be written as a concatenation of the Morse code of each letter. For example, "cab" can be written as "-.-..--...", (which is the concatenation "-.-." + ".-" + "-..."). We'll call such a concatenation, the transformation of a word.

\n\n

Return the number of different transformations among all words we have.

\n\n
\nExample:\nInput: words = ["gin", "zen", "gig", "msg"]\nOutput: 2\nExplanation: \nThe transformation of each word is:\n"gin" -> "--...-."\n"zen" -> "--...-."\n"gig" -> "--...--."\n"msg" -> "--...--."\n\nThere are 2 different transformations, "--...-." and "--...--.".\n
\n\n

Note:

\n\n
    \n\t
  • The length of words will be at most 100.
  • \n\t
  • Each words[i] will have length in range [1, 12].
  • \n\t
  • words[i] will only consist of lowercase letters.
  • \n
\n", "content_cn": "

\u56fd\u9645\u6469\u5c14\u65af\u5bc6\u7801\u5b9a\u4e49\u4e00\u79cd\u6807\u51c6\u7f16\u7801\u65b9\u5f0f\uff0c\u5c06\u6bcf\u4e2a\u5b57\u6bcd\u5bf9\u5e94\u4e8e\u4e00\u4e2a\u7531\u4e00\u7cfb\u5217\u70b9\u548c\u77ed\u7ebf\u7ec4\u6210\u7684\u5b57\u7b26\u4e32\uff0c \u6bd4\u5982: "a" \u5bf9\u5e94 ".-", "b" \u5bf9\u5e94 "-...", "c" \u5bf9\u5e94 "-.-.", \u7b49\u7b49\u3002

\n\n

\u4e3a\u4e86\u65b9\u4fbf\uff0c\u6240\u670926\u4e2a\u82f1\u6587\u5b57\u6bcd\u5bf9\u5e94\u6469\u5c14\u65af\u5bc6\u7801\u8868\u5982\u4e0b\uff1a

\n\n
[".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."]
\n\n

\u7ed9\u5b9a\u4e00\u4e2a\u5355\u8bcd\u5217\u8868\uff0c\u6bcf\u4e2a\u5355\u8bcd\u53ef\u4ee5\u5199\u6210\u6bcf\u4e2a\u5b57\u6bcd\u5bf9\u5e94\u6469\u5c14\u65af\u5bc6\u7801\u7684\u7ec4\u5408\u3002\u4f8b\u5982\uff0c"cab" \u53ef\u4ee5\u5199\u6210 "-.-..--..."\uff0c(\u5373 "-.-." + ".-" + "-..." \u5b57\u7b26\u4e32\u7684\u7ed3\u5408)\u3002\u6211\u4eec\u5c06\u8fd9\u6837\u4e00\u4e2a\u8fde\u63a5\u8fc7\u7a0b\u79f0\u4f5c\u5355\u8bcd\u7ffb\u8bd1\u3002

\n\n

\u8fd4\u56de\u6211\u4eec\u53ef\u4ee5\u83b7\u5f97\u6240\u6709\u8bcd\u4e0d\u540c\u5355\u8bcd\u7ffb\u8bd1\u7684\u6570\u91cf\u3002

\n\n
\u4f8b\u5982:\n\u8f93\u5165: words = ["gin", "zen", "gig", "msg"]\n\u8f93\u51fa: 2\n\u89e3\u91ca: \n\u5404\u5355\u8bcd\u7ffb\u8bd1\u5982\u4e0b:\n"gin" -> "--...-."\n"zen" -> "--...-."\n"gig" -> "--...--."\n"msg" -> "--...--."\n\n\u5171\u6709 2 \u79cd\u4e0d\u540c\u7ffb\u8bd1, "--...-." \u548c "--...--.".\n
\n\n

 

\n\n

\u6ce8\u610f:

\n\n
    \n\t
  • \u5355\u8bcd\u5217\u8868words \u7684\u957f\u5ea6\u4e0d\u4f1a\u8d85\u8fc7 100\u3002
  • \n\t
  • \u6bcf\u4e2a\u5355\u8bcd words[i]\u7684\u957f\u5ea6\u8303\u56f4\u4e3a [1, 12]\u3002
  • \n\t
  • \u6bcf\u4e2a\u5355\u8bcd words[i]\u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd\u3002
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int uniqueMorseRepresentations(vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int uniqueMorseRepresentations(String[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def uniqueMorseRepresentations(self, words):\n \"\"\"\n :type words: List[str]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def uniqueMorseRepresentations(self, words: List[str]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint uniqueMorseRepresentations(char ** words, int wordsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int UniqueMorseRepresentations(string[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @return {number}\n */\nvar uniqueMorseRepresentations = function(words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @return {Integer}\ndef unique_morse_representations(words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func uniqueMorseRepresentations(_ words: [String]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func uniqueMorseRepresentations(words []string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def uniqueMorseRepresentations(words: Array[String]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun uniqueMorseRepresentations(words: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn unique_morse_representations(words: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @return Integer\n */\n function uniqueMorseRepresentations($words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function uniqueMorseRepresentations(words: string[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (unique-morse-representations words)\n (-> (listof string?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0804](https://leetcode-cn.com/problems/unique-morse-code-words)", "[\u552f\u4e00\u6469\u5c14\u65af\u5bc6\u7801\u8bcd](/solution/0800-0899/0804.Unique%20Morse%20Code%20Words/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0804](https://leetcode.com/problems/unique-morse-code-words)", "[Unique Morse Code Words](/solution/0800-0899/0804.Unique%20Morse%20Code%20Words/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "0821", "frontend_question_id": "0803", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/bricks-falling-when-hit", "url_en": "https://leetcode.com/problems/bricks-falling-when-hit", "relative_path_cn": "/solution/0800-0899/0803.Bricks%20Falling%20When%20Hit/README.md", "relative_path_en": "/solution/0800-0899/0803.Bricks%20Falling%20When%20Hit/README_EN.md", "title_cn": "\u6253\u7816\u5757", "title_en": "Bricks Falling When Hit", "question_title_slug": "bricks-falling-when-hit", "content_en": "

You are given an m x n binary grid, where each 1 represents a brick and 0 represents an empty space. A brick is stable if:

\n\n
    \n\t
  • It is directly connected to the top of the grid, or
  • \n\t
  • At least one other brick in its four adjacent cells is stable.
  • \n
\n\n

You are also given an array hits, which is a sequence of erasures we want to apply. Each time we want to erase the brick at the location hits[i] = (rowi, coli). The brick on that location (if it exists) will disappear. Some other bricks may no longer be stable because of that erasure and will fall. Once a brick falls, it is immediately erased from the grid (i.e., it does not land on other stable bricks).

\n\n

Return an array result, where each result[i] is the number of bricks that will fall after the ith erasure is applied.

\n\n

Note that an erasure may refer to a location with no brick, and if it does, no bricks drop.

\n\n

 

\n

Example 1:

\n\n
\nInput: grid = [[1,0,0,0],[1,1,1,0]], hits = [[1,0]]\nOutput: [2]\nExplanation: Starting with the grid:\n[[1,0,0,0],\n [1,1,1,0]]\nWe erase the underlined brick at (1,0), resulting in the grid:\n[[1,0,0,0],\n [0,1,1,0]]\nThe two underlined bricks are no longer stable as they are no longer connected to the top nor adjacent to another stable brick, so they will fall. The resulting grid is:\n[[1,0,0,0],\n [0,0,0,0]]\nHence the result is [2].\n
\n\n

Example 2:

\n\n
\nInput: grid = [[1,0,0,0],[1,1,0,0]], hits = [[1,1],[1,0]]\nOutput: [0,0]\nExplanation: Starting with the grid:\n[[1,0,0,0],\n [1,1,0,0]]\nWe erase the underlined brick at (1,1), resulting in the grid:\n[[1,0,0,0],\n [1,0,0,0]]\nAll remaining bricks are still stable, so no bricks fall. The grid remains the same:\n[[1,0,0,0],\n [1,0,0,0]]\nNext, we erase the underlined brick at (1,0), resulting in the grid:\n[[1,0,0,0],\n [0,0,0,0]]\nOnce again, all remaining bricks are still stable, so no bricks fall.\nHence the result is [0,0].\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • m == grid.length
  • \n\t
  • n == grid[i].length
  • \n\t
  • 1 <= m, n <= 200
  • \n\t
  • grid[i][j] is 0 or 1.
  • \n\t
  • 1 <= hits.length <= 4 * 104
  • \n\t
  • hits[i].length == 2
  • \n\t
  • 0 <= x<= m - 1
  • \n\t
  • 0 <= yi <= n - 1
  • \n\t
  • All (xi, yi) are unique.
  • \n
\n", "content_cn": "

\u6709\u4e00\u4e2a m x n \u7684\u4e8c\u5143\u7f51\u683c\uff0c\u5176\u4e2d 1 \u8868\u793a\u7816\u5757\uff0c0 \u8868\u793a\u7a7a\u767d\u3002\u7816\u5757 \u7a33\u5b9a\uff08\u4e0d\u4f1a\u6389\u843d\uff09\u7684\u524d\u63d0\u662f\uff1a

\n\n
    \n\t
  • \u4e00\u5757\u7816\u76f4\u63a5\u8fde\u63a5\u5230\u7f51\u683c\u7684\u9876\u90e8\uff0c\u6216\u8005
  • \n\t
  • \u81f3\u5c11\u6709\u4e00\u5757\u76f8\u90bb\uff084\u00a0\u4e2a\u65b9\u5411\u4e4b\u4e00\uff09\u7816\u5757 \u7a33\u5b9a \u4e0d\u4f1a\u6389\u843d\u65f6
  • \n
\n\n

\u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 hits \uff0c\u8fd9\u662f\u9700\u8981\u4f9d\u6b21\u6d88\u9664\u7816\u5757\u7684\u4f4d\u7f6e\u3002\u6bcf\u5f53\u6d88\u9664\u00a0hits[i] = (rowi, coli) \u4f4d\u7f6e\u4e0a\u7684\u7816\u5757\u65f6\uff0c\u5bf9\u5e94\u4f4d\u7f6e\u7684\u7816\u5757\uff08\u82e5\u5b58\u5728\uff09\u4f1a\u6d88\u5931\uff0c\u7136\u540e\u5176\u4ed6\u7684\u7816\u5757\u53ef\u80fd\u56e0\u4e3a\u8fd9\u4e00\u6d88\u9664\u64cd\u4f5c\u800c\u6389\u843d\u3002\u4e00\u65e6\u7816\u5757\u6389\u843d\uff0c\u5b83\u4f1a\u7acb\u5373\u4ece\u7f51\u683c\u4e2d\u6d88\u5931\uff08\u5373\uff0c\u5b83\u4e0d\u4f1a\u843d\u5728\u5176\u4ed6\u7a33\u5b9a\u7684\u7816\u5757\u4e0a\uff09\u3002

\n\n

\u8fd4\u56de\u4e00\u4e2a\u6570\u7ec4 result \uff0c\u5176\u4e2d result[i] \u8868\u793a\u7b2c i \u6b21\u6d88\u9664\u64cd\u4f5c\u5bf9\u5e94\u6389\u843d\u7684\u7816\u5757\u6570\u76ee\u3002

\n\n

\u6ce8\u610f\uff0c\u6d88\u9664\u53ef\u80fd\u6307\u5411\u662f\u6ca1\u6709\u7816\u5757\u7684\u7a7a\u767d\u4f4d\u7f6e\uff0c\u5982\u679c\u53d1\u751f\u8fd9\u79cd\u60c5\u51b5\uff0c\u5219\u6ca1\u6709\u7816\u5757\u6389\u843d\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1agrid = [[1,0,0,0],[1,1,1,0]], hits = [[1,0]]\n\u8f93\u51fa\uff1a[2]\n\u89e3\u91ca\uff1a\n\u7f51\u683c\u5f00\u59cb\u4e3a\uff1a\n[[1,0,0,0]\uff0c\n [1,1,1,0]]\n\u6d88\u9664 (1,0) \u5904\u52a0\u7c97\u7684\u7816\u5757\uff0c\u5f97\u5230\u7f51\u683c\uff1a\n[[1,0,0,0]\n [0,1,1,0]]\n\u4e24\u4e2a\u52a0\u7c97\u7684\u7816\u4e0d\u518d\u7a33\u5b9a\uff0c\u56e0\u4e3a\u5b83\u4eec\u4e0d\u518d\u4e0e\u9876\u90e8\u76f8\u8fde\uff0c\u4e5f\u4e0d\u518d\u4e0e\u53e6\u4e00\u4e2a\u7a33\u5b9a\u7684\u7816\u76f8\u90bb\uff0c\u56e0\u6b64\u5b83\u4eec\u5c06\u6389\u843d\u3002\u5f97\u5230\u7f51\u683c\uff1a\n[[1,0,0,0],\n [0,0,0,0]]\n\u56e0\u6b64\uff0c\u7ed3\u679c\u4e3a [2] \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1agrid = [[1,0,0,0],[1,1,0,0]], hits = [[1,1],[1,0]]\n\u8f93\u51fa\uff1a[0,0]\n\u89e3\u91ca\uff1a\n\u7f51\u683c\u5f00\u59cb\u4e3a\uff1a\n[[1,0,0,0],\n [1,1,0,0]]\n\u6d88\u9664 (1,1) \u5904\u52a0\u7c97\u7684\u7816\u5757\uff0c\u5f97\u5230\u7f51\u683c\uff1a\n[[1,0,0,0],\n [1,0,0,0]]\n\u5269\u4e0b\u7684\u7816\u90fd\u5f88\u7a33\u5b9a\uff0c\u6240\u4ee5\u4e0d\u4f1a\u6389\u843d\u3002\u7f51\u683c\u4fdd\u6301\u4e0d\u53d8\uff1a\n[[1,0,0,0], \n [1,0,0,0]]\n\u63a5\u4e0b\u6765\u6d88\u9664 (1,0) \u5904\u52a0\u7c97\u7684\u7816\u5757\uff0c\u5f97\u5230\u7f51\u683c\uff1a\n[[1,0,0,0],\n [0,0,0,0]]\n\u5269\u4e0b\u7684\u7816\u5757\u4ecd\u7136\u662f\u7a33\u5b9a\u7684\uff0c\u6240\u4ee5\u4e0d\u4f1a\u6709\u7816\u5757\u6389\u843d\u3002\n\u56e0\u6b64\uff0c\u7ed3\u679c\u4e3a [0,0] \u3002
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • m == grid.length
  • \n\t
  • n == grid[i].length
  • \n\t
  • 1 <= m, n <= 200
  • \n\t
  • grid[i][j] \u4e3a 0 \u6216 1
  • \n\t
  • 1 <= hits.length <= 4 * 104
  • \n\t
  • hits[i].length == 2
  • \n\t
  • 0 <= xi\u00a0<= m - 1
  • \n\t
  • 0 <=\u00a0yi <= n - 1
  • \n\t
  • \u6240\u6709 (xi, yi) \u4e92\u4e0d\u76f8\u540c
  • \n
\n", "tags_en": ["Union Find"], "tags_cn": ["\u5e76\u67e5\u96c6"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector hitBricks(vector>& grid, vector>& hits) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] hitBricks(int[][] grid, int[][] hits) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def hitBricks(self, grid, hits):\n \"\"\"\n :type grid: List[List[int]]\n :type hits: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def hitBricks(self, grid: List[List[int]], hits: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* hitBricks(int** grid, int gridSize, int* gridColSize, int** hits, int hitsSize, int* hitsColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] HitBricks(int[][] grid, int[][] hits) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @param {number[][]} hits\n * @return {number[]}\n */\nvar hitBricks = function(grid, hits) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @param {Integer[][]} hits\n# @return {Integer[]}\ndef hit_bricks(grid, hits)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func hitBricks(_ grid: [[Int]], _ hits: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func hitBricks(grid [][]int, hits [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def hitBricks(grid: Array[Array[Int]], hits: Array[Array[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun hitBricks(grid: Array, hits: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn hit_bricks(grid: Vec>, hits: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @param Integer[][] $hits\n * @return Integer[]\n */\n function hitBricks($grid, $hits) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function hitBricks(grid: number[][], hits: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (hit-bricks grid hits)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0803](https://leetcode-cn.com/problems/bricks-falling-when-hit)", "[\u6253\u7816\u5757](/solution/0800-0899/0803.Bricks%20Falling%20When%20Hit/README.md)", "`\u5e76\u67e5\u96c6`", "\u56f0\u96be", ""], "md_table_row_en": ["[0803](https://leetcode.com/problems/bricks-falling-when-hit)", "[Bricks Falling When Hit](/solution/0800-0899/0803.Bricks%20Falling%20When%20Hit/README_EN.md)", "`Union Find`", "Hard", ""]}, {"question_id": "0820", "frontend_question_id": "0802", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-eventual-safe-states", "url_en": "https://leetcode.com/problems/find-eventual-safe-states", "relative_path_cn": "/solution/0800-0899/0802.Find%20Eventual%20Safe%20States/README.md", "relative_path_en": "/solution/0800-0899/0802.Find%20Eventual%20Safe%20States/README_EN.md", "title_cn": "\u627e\u5230\u6700\u7ec8\u7684\u5b89\u5168\u72b6\u6001", "title_en": "Find Eventual Safe States", "question_title_slug": "find-eventual-safe-states", "content_en": "

We start at some node in a directed graph, and every turn, we walk along a directed edge of the graph. If we reach a terminal node (that is, it has no outgoing directed edges), we stop.

\n\n

We define a starting node to be safe if we must eventually walk to a terminal node. More specifically, there is a natural number k, so that we must have stopped at a terminal node in less than k steps for any choice of where to walk.

\n\n

Return an array containing all the safe nodes of the graph. The answer should be sorted in ascending order.

\n\n

The directed graph has n nodes with labels from 0 to n - 1, where n is the length of graph. The graph is given in the following form: graph[i] is a list of labels j such that (i, j) is a directed edge of the graph, going from node i to node j.

\n\n

 

\n

Example 1:

\n\"Illustration\n
\nInput: graph = [[1,2],[2,3],[5],[0],[5],[],[]]\nOutput: [2,4,5,6]\nExplanation: The given graph is shown above.\n
\n\n

Example 2:

\n\n
\nInput: graph = [[1,2,3,4],[1,2],[3,4],[0,4],[]]\nOutput: [4]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == graph.length
  • \n\t
  • 1 <= n <= 104
  • \n\t
  • 0 <= graph[i].legnth <= n
  • \n\t
  • graph[i] is sorted in a strictly increasing order.
  • \n\t
  • The graph may contain self-loops.
  • \n\t
  • The number of edges in the graph will be in the range [1, 4 * 104].
  • \n
\n", "content_cn": "

\u5728\u6709\u5411\u56fe\u4e2d\uff0c\u4ece\u67d0\u4e2a\u8282\u70b9\u548c\u6bcf\u4e2a\u8f6c\u5411\u5904\u5f00\u59cb\u51fa\u53d1\uff0c\u6cbf\u7740\u56fe\u7684\u6709\u5411\u8fb9\u8d70\u3002\u5982\u679c\u5230\u8fbe\u7684\u8282\u70b9\u662f\u7ec8\u70b9\uff08\u5373\u5b83\u6ca1\u6709\u8fde\u51fa\u7684\u6709\u5411\u8fb9\uff09\uff0c\u5219\u505c\u6b62\u3002

\n\n

\u5982\u679c\u4ece\u8d77\u59cb\u8282\u70b9\u51fa\u53d1\uff0c\u6700\u540e\u5fc5\u7136\u80fd\u8d70\u5230\u7ec8\u70b9\uff0c\u5c31\u8ba4\u4e3a\u8d77\u59cb\u8282\u70b9\u662f \u6700\u7ec8\u5b89\u5168 \u7684\u3002\u66f4\u5177\u4f53\u5730\u8bf4\uff0c\u5bf9\u4e8e\u6700\u7ec8\u5b89\u5168\u7684\u8d77\u59cb\u8282\u70b9\u800c\u8a00\uff0c\u5b58\u5728\u4e00\u4e2a\u81ea\u7136\u6570 k \uff0c\u65e0\u8bba\u9009\u62e9\u6cbf\u54ea\u6761\u6709\u5411\u8fb9\u884c\u8d70 \uff0c\u8d70\u4e86\u4e0d\u5230 k \u6b65\u540e\u5fc5\u80fd\u505c\u6b62\u5728\u4e00\u4e2a\u7ec8\u70b9\u4e0a\u3002

\n\n

\u8fd4\u56de\u4e00\u4e2a\u7531\u56fe\u4e2d\u6240\u6709\u6700\u7ec8\u5b89\u5168\u7684\u8d77\u59cb\u8282\u70b9\u7ec4\u6210\u7684\u6570\u7ec4\u4f5c\u4e3a\u7b54\u6848\u3002\u7b54\u6848\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u5e94\u5f53\u6309 \u5347\u5e8f \u6392\u5217\u3002

\n\n

\u8be5\u6709\u5411\u56fe\u6709 n \u4e2a\u8282\u70b9\uff0c\u6309 0 \u5230 n - 1 \u7f16\u53f7\uff0c\u5176\u4e2d n \u662f\u00a0graph\u00a0\u7684\u8282\u70b9\u6570\u3002\u56fe\u4ee5\u4e0b\u8ff0\u5f62\u5f0f\u7ed9\u51fa\uff1agraph[i] \u662f\u7f16\u53f7 j \u8282\u70b9\u7684\u4e00\u4e2a\u5217\u8868\uff0c\u6ee1\u8db3 (i, j) \u662f\u56fe\u7684\u4e00\u6761\u6709\u5411\u8fb9\u3002

\n\n

\u00a0

\n\n
\n
\n

\u793a\u4f8b 1\uff1a

\n\"Illustration\n
\n\u8f93\u5165\uff1agraph = [[1,2],[2,3],[5],[0],[5],[],[]]\n\u8f93\u51fa\uff1a[2,4,5,6]\n\u89e3\u91ca\uff1a\u793a\u610f\u56fe\u5982\u4e0a\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1agraph = [[1,2,3,4],[1,2],[3,4],[0,4],[]]\n\u8f93\u51fa\uff1a[4]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • n == graph.length
  • \n\t
  • 1 <= n <= 104
  • \n\t
  • 0 <= graph[i].legnth <= n
  • \n\t
  • graph[i] \u6309\u4e25\u683c\u9012\u589e\u987a\u5e8f\u6392\u5217\u3002
  • \n\t
  • \u56fe\u4e2d\u53ef\u80fd\u5305\u542b\u81ea\u73af\u3002
  • \n\t
  • \u56fe\u4e2d\u8fb9\u7684\u6570\u76ee\u5728\u8303\u56f4 [1, 4 * 104] \u5185\u3002
  • \n
\n
\n
\n", "tags_en": ["Depth-first Search", "Graph"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector eventualSafeNodes(vector>& graph) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List eventualSafeNodes(int[][] graph) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def eventualSafeNodes(self, graph):\n \"\"\"\n :type graph: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def eventualSafeNodes(self, graph: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* eventualSafeNodes(int** graph, int graphSize, int* graphColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList EventualSafeNodes(int[][] graph) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} graph\n * @return {number[]}\n */\nvar eventualSafeNodes = function(graph) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} graph\n# @return {Integer[]}\ndef eventual_safe_nodes(graph)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func eventualSafeNodes(_ graph: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func eventualSafeNodes(graph [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def eventualSafeNodes(graph: Array[Array[Int]]): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun eventualSafeNodes(graph: Array): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn eventual_safe_nodes(graph: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $graph\n * @return Integer[]\n */\n function eventualSafeNodes($graph) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function eventualSafeNodes(graph: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (eventual-safe-nodes graph)\n (-> (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0802](https://leetcode-cn.com/problems/find-eventual-safe-states)", "[\u627e\u5230\u6700\u7ec8\u7684\u5b89\u5168\u72b6\u6001](/solution/0800-0899/0802.Find%20Eventual%20Safe%20States/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u56fe`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0802](https://leetcode.com/problems/find-eventual-safe-states)", "[Find Eventual Safe States](/solution/0800-0899/0802.Find%20Eventual%20Safe%20States/README_EN.md)", "`Depth-first Search`,`Graph`", "Medium", ""]}, {"question_id": "0819", "frontend_question_id": "0801", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-swaps-to-make-sequences-increasing", "url_en": "https://leetcode.com/problems/minimum-swaps-to-make-sequences-increasing", "relative_path_cn": "/solution/0800-0899/0801.Minimum%20Swaps%20To%20Make%20Sequences%20Increasing/README.md", "relative_path_en": "/solution/0800-0899/0801.Minimum%20Swaps%20To%20Make%20Sequences%20Increasing/README_EN.md", "title_cn": "\u4f7f\u5e8f\u5217\u9012\u589e\u7684\u6700\u5c0f\u4ea4\u6362\u6b21\u6570", "title_en": "Minimum Swaps To Make Sequences Increasing", "question_title_slug": "minimum-swaps-to-make-sequences-increasing", "content_en": "

We have two integer sequences nums1 and nums2 of the same non-zero length.

\n\n

We are allowed to swap elements nums1[i] and nums2[i]. Note that both elements are in the same index position in their respective sequences.

\n\n

At the end of some number of swaps, nums1 and nums2 are both strictly increasing. (An array A is strictly increasing if and only if A[0] < A[1] < A[2] < ... < A[A.length - 1].)

\n\n

Given nums1 and nums2, return the minimum number of swaps to make both sequences strictly increasing. It is guaranteed that the given input always makes it possible.

\n\n
\nExample:\nInput: nums1 = [1,3,5,4], nums2 = [1,2,3,7]\nOutput: 1\nExplanation: \nSwap nums1[3] and nums2[3].  Then the sequences are:\nnums1 = [1, 3, 5, 7] and nums2 = [1, 2, 3, 4]\nwhich are both strictly increasing.\n
\n\n

Note:

\n\n
    \n\t
  • nums1, nums2 are arrays with the same length, and that length will be in the range [1, 1000].
  • \n\t
  • nums1[i], nums2[i] are integer values in the range [0, 2000].
  • \n
\n", "content_cn": "

\u6211\u4eec\u6709\u4e24\u4e2a\u957f\u5ea6\u76f8\u7b49\u4e14\u4e0d\u4e3a\u7a7a\u7684\u6574\u578b\u6570\u7ec4 A \u548c B \u3002

\n\n

\u6211\u4eec\u53ef\u4ee5\u4ea4\u6362 A[i] \u548c B[i] \u7684\u5143\u7d20\u3002\u6ce8\u610f\u8fd9\u4e24\u4e2a\u5143\u7d20\u5728\u5404\u81ea\u7684\u5e8f\u5217\u4e2d\u5e94\u8be5\u5904\u4e8e\u76f8\u540c\u7684\u4f4d\u7f6e\u3002

\n\n

\u5728\u4ea4\u6362\u8fc7\u4e00\u4e9b\u5143\u7d20\u4e4b\u540e\uff0c\u6570\u7ec4 A \u548c B \u90fd\u5e94\u8be5\u662f\u4e25\u683c\u9012\u589e\u7684\uff08\u6570\u7ec4\u4e25\u683c\u9012\u589e\u7684\u6761\u4ef6\u4ec5\u4e3aA[0] < A[1] < A[2] < ... < A[A.length - 1]\uff09\u3002

\n\n

\u7ed9\u5b9a\u6570\u7ec4 A \u548c B \uff0c\u8bf7\u8fd4\u56de\u4f7f\u5f97\u4e24\u4e2a\u6570\u7ec4\u5747\u4fdd\u6301\u4e25\u683c\u9012\u589e\u72b6\u6001\u7684\u6700\u5c0f\u4ea4\u6362\u6b21\u6570\u3002\u5047\u8bbe\u7ed9\u5b9a\u7684\u8f93\u5165\u603b\u662f\u6709\u6548\u7684\u3002

\n\n
\n\u793a\u4f8b:\n\u8f93\u5165: A = [1,3,5,4], B = [1,2,3,7]\n\u8f93\u51fa: 1\n\u89e3\u91ca: \n\u4ea4\u6362 A[3] \u548c B[3] \u540e\uff0c\u4e24\u4e2a\u6570\u7ec4\u5982\u4e0b:\nA = [1, 3, 5, 7] \uff0c B = [1, 2, 3, 4]\n\u4e24\u4e2a\u6570\u7ec4\u5747\u4e3a\u4e25\u683c\u9012\u589e\u7684\u3002
\n\n

\u6ce8\u610f:

\n\n
    \n\t
  • A, B \u4e24\u4e2a\u6570\u7ec4\u7684\u957f\u5ea6\u603b\u662f\u76f8\u7b49\u7684\uff0c\u4e14\u957f\u5ea6\u7684\u8303\u56f4\u4e3a [1, 1000]\u3002
  • \n\t
  • A[i], B[i] \u5747\u4e3a [0, 2000]\u533a\u95f4\u5185\u7684\u6574\u6570\u3002
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minSwap(vector& nums1, vector& nums2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minSwap(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minSwap(self, nums1, nums2):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minSwap(self, nums1: List[int], nums2: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minSwap(int* nums1, int nums1Size, int* nums2, int nums2Size){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinSwap(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums1\n * @param {number[]} nums2\n * @return {number}\n */\nvar minSwap = function(nums1, nums2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums1\n# @param {Integer[]} nums2\n# @return {Integer}\ndef min_swap(nums1, nums2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minSwap(_ nums1: [Int], _ nums2: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minSwap(nums1 []int, nums2 []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minSwap(nums1: Array[Int], nums2: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minSwap(nums1: IntArray, nums2: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_swap(nums1: Vec, nums2: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums1\n * @param Integer[] $nums2\n * @return Integer\n */\n function minSwap($nums1, $nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minSwap(nums1: number[], nums2: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-swap nums1 nums2)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0801](https://leetcode-cn.com/problems/minimum-swaps-to-make-sequences-increasing)", "[\u4f7f\u5e8f\u5217\u9012\u589e\u7684\u6700\u5c0f\u4ea4\u6362\u6b21\u6570](/solution/0800-0899/0801.Minimum%20Swaps%20To%20Make%20Sequences%20Increasing/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0801](https://leetcode.com/problems/minimum-swaps-to-make-sequences-increasing)", "[Minimum Swaps To Make Sequences Increasing](/solution/0800-0899/0801.Minimum%20Swaps%20To%20Make%20Sequences%20Increasing/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0818", "frontend_question_id": "0800", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/similar-rgb-color", "url_en": "https://leetcode.com/problems/similar-rgb-color", "relative_path_cn": "/solution/0800-0899/0800.Similar%20RGB%20Color/README.md", "relative_path_en": "/solution/0800-0899/0800.Similar%20RGB%20Color/README_EN.md", "title_cn": "\u76f8\u4f3c RGB \u989c\u8272", "title_en": "Similar RGB Color", "question_title_slug": "similar-rgb-color", "content_en": "

In the following, every capital letter represents some hexadecimal digit from 0 to f.

\r\n\r\n

The red-green-blue color "#AABBCC" can be written as "#ABC" in shorthand.  For example, "#15c" is shorthand for the color "#1155cc".

\r\n\r\n

Now, say the similarity between two colors "#ABCDEF" and "#UVWXYZ" is -(AB - UV)^2 - (CD - WX)^2 - (EF - YZ)^2.

\r\n\r\n

Given the color "#ABCDEF", return a 7 character color that is most similar to #ABCDEF, and has a shorthand (that is, it can be represented as some "#XYZ"

\r\n\r\n
\r\nExample 1:\r\nInput: color = "#09f166"\r\nOutput: "#11ee66"\r\nExplanation:  \r\nThe similarity is -(0x09 - 0x11)^2 -(0xf1 - 0xee)^2 - (0x66 - 0x66)^2 = -64 -9 -0 = -73.\r\nThis is the highest among any shorthand color.\r\n
\r\n\r\n

Note:

\r\n\r\n
    \r\n\t
  • color is a string of length 7.
  • \r\n\t
  • color is a valid RGB color: for i > 0, color[i] is a hexadecimal digit from 0 to f
  • \r\n\t
  • Any answer which has the same (highest) similarity as the best answer will be accepted.
  • \r\n\t
  • All inputs and outputs should use lowercase letters, and the output is 7 characters.
  • \r\n
\r\n", "content_cn": "

RGB \u989c\u8272\u7528\u5341\u516d\u8fdb\u5236\u6765\u8868\u793a\u7684\u8bdd\uff0c\u6bcf\u4e2a\u5927\u5199\u5b57\u6bcd\u90fd\u4ee3\u8868\u4e86\u67d0\u4e2a\u4ece 0 \u5230 f \u7684 16 \u8fdb\u5236\u6570\u3002

\n\n

RGB \u989c\u8272 "#AABBCC" \u53ef\u4ee5\u7b80\u5199\u6210 "#ABC" \u3002\u4f8b\u5982\uff0c"#15c" \u5176\u5b9e\u662f "#1155cc" \u7684\u7b80\u5199\u3002

\n\n

\u73b0\u5728\uff0c\u5047\u5982\u6211\u4eec\u5206\u522b\u5b9a\u4e49\u4e24\u4e2a\u989c\u8272 "#ABCDEF" \u548c "#UVWXYZ"\uff0c\u5219\u4ed6\u4eec\u7684\u76f8\u4f3c\u5ea6\u53ef\u4ee5\u901a\u8fc7\u8fd9\u4e2a\u8868\u8fbe\u5f0f -(AB - UV)^2 - (CD - WX)^2 - (EF - YZ)^2 \u6765\u8ba1\u7b97\u3002

\n\n

\u90a3\u4e48\u7ed9\u5b9a\u989c\u8272 "#ABCDEF"\uff0c\u8bf7\u4f60\u8fd4\u56de\u4e00\u4e2a\u4e0e #ABCDEF \u6700\u76f8\u4f3c\u7684 7 \u4e2a\u5b57\u7b26\u4ee3\u8868\u7684\u989c\u8272\uff0c\u5e76\u4e14\u5b83\u662f\u53ef\u4ee5\u88ab\u7b80\u5199\u5f62\u5f0f\u8868\u8fbe\u7684\u3002\uff08\u6bd4\u5982\uff0c\u53ef\u4ee5\u8868\u793a\u6210\u7c7b\u4f3c "#XYZ" \u7684\u5f62\u5f0f\uff09

\n\n
\u793a\u4f8b 1\uff1a\n\u8f93\u5165\uff1acolor = "#09f166"\n\u8f93\u51fa\uff1a"#11ee66"\n\u89e3\u91ca\uff1a \n\u56e0\u4e3a\u76f8\u4f3c\u5ea6\u8ba1\u7b97\u5f97\u51fa -(0x09 - 0x11)^2 -(0xf1 - 0xee)^2 - (0x66 - 0x66)^2 = -64 -9 -0 = -73\n\u8fd9\u5df2\u7ecf\u662f\u6240\u6709\u53ef\u4ee5\u7b80\u5199\u7684\u989c\u8272\u4e2d\u6700\u76f8\u4f3c\u7684\u4e86\n
\n\n

\u6ce8\u610f\uff1a

\n\n
    \n\t
  • color \u662f\u4e00\u4e2a\u957f\u5ea6\u4e3a 7 \u7684\u5b57\u7b26\u4e32
  • \n\t
  • color \u662f\u4e00\u4e2a\u6709\u6548\u7684 RGB \u989c\u8272\uff1a\u5bf9\u4e8e\u4ecd\u548c i > 0\uff0ccolor[i] \u90fd\u662f\u4e00\u4e2a\u5728 0 \u5230 f \u8303\u56f4\u7684 16 \u8fdb\u5236\u6570
  • \n\t
  • \u5047\u5982\u7b54\u6848\u5177\u6709\u76f8\u540c\u7684\uff08\u6700\u5927\uff09\u76f8\u4f3c\u5ea6\u7684\u8bdd\uff0c\u90fd\u662f\u53ef\u4ee5\u88ab\u63a5\u53d7\u7684
  • \n\t
  • \u6240\u6709\u8f93\u5165\u3001\u8f93\u51fa\u90fd\u5fc5\u987b\u4f7f\u7528\u5c0f\u5199\u5b57\u6bcd\uff0c\u5e76\u4e14\u8f93\u51fa\u4e3a 7 \u4e2a\u5b57\u7b26
  • \n
\n", "tags_en": ["Math", "String"], "tags_cn": ["\u6570\u5b66", "\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string similarRGB(string color) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String similarRGB(String color) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def similarRGB(self, color):\n \"\"\"\n :type color: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def similarRGB(self, color: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * similarRGB(char * color){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string SimilarRGB(string color) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} color\n * @return {string}\n */\nvar similarRGB = function(color) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} color\n# @return {String}\ndef similar_rgb(color)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func similarRGB(_ color: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func similarRGB(color string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def similarRGB(color: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun similarRGB(color: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn similar_rgb(color: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $color\n * @return String\n */\n function similarRGB($color) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function similarRGB(color: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (similar-rgb color)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0800](https://leetcode-cn.com/problems/similar-rgb-color)", "[\u76f8\u4f3c RGB \u989c\u8272](/solution/0800-0899/0800.Similar%20RGB%20Color/README.md)", "`\u6570\u5b66`,`\u5b57\u7b26\u4e32`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0800](https://leetcode.com/problems/similar-rgb-color)", "[Similar RGB Color](/solution/0800-0899/0800.Similar%20RGB%20Color/README_EN.md)", "`Math`,`String`", "Easy", "\ud83d\udd12"]}, {"question_id": "0817", "frontend_question_id": "0706", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/design-hashmap", "url_en": "https://leetcode.com/problems/design-hashmap", "relative_path_cn": "/solution/0700-0799/0706.Design%20HashMap/README.md", "relative_path_en": "/solution/0700-0799/0706.Design%20HashMap/README_EN.md", "title_cn": "\u8bbe\u8ba1\u54c8\u5e0c\u6620\u5c04", "title_en": "Design HashMap", "question_title_slug": "design-hashmap", "content_en": "

Design a HashMap without using any built-in hash table libraries.

\n\n

Implement the MyHashMap class:

\n\n
    \n\t
  • MyHashMap() initializes the object with an empty map.
  • \n\t
  • void put(int key, int value) inserts a (key, value) pair into the HashMap. If the key already exists in the map, update the corresponding value.
  • \n\t
  • int get(int key) returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key.
  • \n\t
  • void remove(key) removes the key and its corresponding value if the map contains the mapping for the key.
  • \n
\n\n

 

\n

Example 1:

\n\n
\nInput\n["MyHashMap", "put", "put", "get", "get", "put", "get", "remove", "get"]\n[[], [1, 1], [2, 2], [1], [3], [2, 1], [2], [2], [2]]\nOutput\n[null, null, null, 1, -1, null, 1, null, -1]\n\nExplanation\nMyHashMap myHashMap = new MyHashMap();\nmyHashMap.put(1, 1); // The map is now [[1,1]]\nmyHashMap.put(2, 2); // The map is now [[1,1], [2,2]]\nmyHashMap.get(1);    // return 1, The map is now [[1,1], [2,2]]\nmyHashMap.get(3);    // return -1 (i.e., not found), The map is now [[1,1], [2,2]]\nmyHashMap.put(2, 1); // The map is now [[1,1], [2,1]] (i.e., update the existing value)\nmyHashMap.get(2);    // return 1, The map is now [[1,1], [2,1]]\nmyHashMap.remove(2); // remove the mapping for 2, The map is now [[1,1]]\nmyHashMap.get(2);    // return -1 (i.e., not found), The map is now [[1,1]]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 0 <= key, value <= 106
  • \n\t
  • At most 104 calls will be made to put, get, and remove.
  • \n
\n", "content_cn": "

\u4e0d\u4f7f\u7528\u4efb\u4f55\u5185\u5efa\u7684\u54c8\u5e0c\u8868\u5e93\u8bbe\u8ba1\u4e00\u4e2a\u54c8\u5e0c\u6620\u5c04\uff08HashMap\uff09\u3002

\n\n

\u5b9e\u73b0 MyHashMap \u7c7b\uff1a

\n\n
    \n\t
  • MyHashMap() \u7528\u7a7a\u6620\u5c04\u521d\u59cb\u5316\u5bf9\u8c61
  • \n\t
  • void put(int key, int value) \u5411 HashMap \u63d2\u5165\u4e00\u4e2a\u952e\u503c\u5bf9 (key, value) \u3002\u5982\u679c key \u5df2\u7ecf\u5b58\u5728\u4e8e\u6620\u5c04\u4e2d\uff0c\u5219\u66f4\u65b0\u5176\u5bf9\u5e94\u7684\u503c value \u3002
  • \n\t
  • int get(int key) \u8fd4\u56de\u7279\u5b9a\u7684 key \u6240\u6620\u5c04\u7684 value \uff1b\u5982\u679c\u6620\u5c04\u4e2d\u4e0d\u5305\u542b key \u7684\u6620\u5c04\uff0c\u8fd4\u56de -1 \u3002
  • \n\t
  • void remove(key) \u5982\u679c\u6620\u5c04\u4e2d\u5b58\u5728 key \u7684\u6620\u5c04\uff0c\u5219\u79fb\u9664 key \u548c\u5b83\u6240\u5bf9\u5e94\u7684 value \u3002
  • \n
\n\n

\u00a0

\n\n

\u793a\u4f8b\uff1a

\n\n
\n\u8f93\u5165\uff1a\n[\"MyHashMap\", \"put\", \"put\", \"get\", \"get\", \"put\", \"get\", \"remove\", \"get\"]\n[[], [1, 1], [2, 2], [1], [3], [2, 1], [2], [2], [2]]\n\u8f93\u51fa\uff1a\n[null, null, null, 1, -1, null, 1, null, -1]\n\n\u89e3\u91ca\uff1a\nMyHashMap myHashMap = new MyHashMap();\nmyHashMap.put(1, 1); // myHashMap \u73b0\u5728\u4e3a [[1,1]]\nmyHashMap.put(2, 2); // myHashMap \u73b0\u5728\u4e3a [[1,1], [2,2]]\nmyHashMap.get(1);    // \u8fd4\u56de 1 \uff0cmyHashMap \u73b0\u5728\u4e3a [[1,1], [2,2]]\nmyHashMap.get(3);    // \u8fd4\u56de -1\uff08\u672a\u627e\u5230\uff09\uff0cmyHashMap \u73b0\u5728\u4e3a [[1,1], [2,2]]\nmyHashMap.put(2, 1); // myHashMap \u73b0\u5728\u4e3a [[1,1], [2,1]]\uff08\u66f4\u65b0\u5df2\u6709\u7684\u503c\uff09\nmyHashMap.get(2);    // \u8fd4\u56de 1 \uff0cmyHashMap \u73b0\u5728\u4e3a [[1,1], [2,1]]\nmyHashMap.remove(2); // \u5220\u9664\u952e\u4e3a 2 \u7684\u6570\u636e\uff0cmyHashMap \u73b0\u5728\u4e3a [[1,1]]\nmyHashMap.get(2);    // \u8fd4\u56de -1\uff08\u672a\u627e\u5230\uff09\uff0cmyHashMap \u73b0\u5728\u4e3a [[1,1]]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 0 <= key, value <= 106
  • \n\t
  • \u6700\u591a\u8c03\u7528 104 \u6b21 put\u3001get \u548c remove \u65b9\u6cd5
  • \n
\n\n

\u00a0

\n\n

\u8fdb\u9636\uff1a\u4f60\u80fd\u5426\u4e0d\u4f7f\u7528\u5185\u7f6e\u7684 HashMap \u5e93\u89e3\u51b3\u6b64\u95ee\u9898\uff1f

\n", "tags_en": ["Design", "Hash Table"], "tags_cn": ["\u8bbe\u8ba1", "\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class MyHashMap {\npublic:\n /** Initialize your data structure here. */\n MyHashMap() {\n\n }\n \n /** value will always be non-negative. */\n void put(int key, int value) {\n\n }\n \n /** Returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key */\n int get(int key) {\n\n }\n \n /** Removes the mapping of the specified value key if this map contains a mapping for the key */\n void remove(int key) {\n\n }\n};\n\n/**\n * Your MyHashMap object will be instantiated and called as such:\n * MyHashMap* obj = new MyHashMap();\n * obj->put(key,value);\n * int param_2 = obj->get(key);\n * obj->remove(key);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class MyHashMap {\n\n /** Initialize your data structure here. */\n public MyHashMap() {\n\n }\n \n /** value will always be non-negative. */\n public void put(int key, int value) {\n\n }\n \n /** Returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key */\n public int get(int key) {\n\n }\n \n /** Removes the mapping of the specified value key if this map contains a mapping for the key */\n public void remove(int key) {\n\n }\n}\n\n/**\n * Your MyHashMap object will be instantiated and called as such:\n * MyHashMap obj = new MyHashMap();\n * obj.put(key,value);\n * int param_2 = obj.get(key);\n * obj.remove(key);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class MyHashMap(object):\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def put(self, key, value):\n \"\"\"\n value will always be non-negative.\n :type key: int\n :type value: int\n :rtype: None\n \"\"\"\n\n\n def get(self, key):\n \"\"\"\n Returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key\n :type key: int\n :rtype: int\n \"\"\"\n\n\n def remove(self, key):\n \"\"\"\n Removes the mapping of the specified value key if this map contains a mapping for the key\n :type key: int\n :rtype: None\n \"\"\"\n\n\n\n# Your MyHashMap object will be instantiated and called as such:\n# obj = MyHashMap()\n# obj.put(key,value)\n# param_2 = obj.get(key)\n# obj.remove(key)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class MyHashMap:\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def put(self, key: int, value: int) -> None:\n \"\"\"\n value will always be non-negative.\n \"\"\"\n\n\n def get(self, key: int) -> int:\n \"\"\"\n Returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key\n \"\"\"\n\n\n def remove(self, key: int) -> None:\n \"\"\"\n Removes the mapping of the specified value key if this map contains a mapping for the key\n \"\"\"\n\n\n\n# Your MyHashMap object will be instantiated and called as such:\n# obj = MyHashMap()\n# obj.put(key,value)\n# param_2 = obj.get(key)\n# obj.remove(key)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} MyHashMap;\n\n/** Initialize your data structure here. */\n\nMyHashMap* myHashMapCreate() {\n\n}\n\n/** value will always be non-negative. */\nvoid myHashMapPut(MyHashMap* obj, int key, int value) {\n\n}\n\n/** Returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key */\nint myHashMapGet(MyHashMap* obj, int key) {\n\n}\n\n/** Removes the mapping of the specified value key if this map contains a mapping for the key */\nvoid myHashMapRemove(MyHashMap* obj, int key) {\n\n}\n\nvoid myHashMapFree(MyHashMap* obj) {\n\n}\n\n/**\n * Your MyHashMap struct will be instantiated and called as such:\n * MyHashMap* obj = myHashMapCreate();\n * myHashMapPut(obj, key, value);\n \n * int param_2 = myHashMapGet(obj, key);\n \n * myHashMapRemove(obj, key);\n \n * myHashMapFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class MyHashMap {\n\n /** Initialize your data structure here. */\n public MyHashMap() {\n\n }\n \n /** value will always be non-negative. */\n public void Put(int key, int value) {\n\n }\n \n /** Returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key */\n public int Get(int key) {\n\n }\n \n /** Removes the mapping of the specified value key if this map contains a mapping for the key */\n public void Remove(int key) {\n\n }\n}\n\n/**\n * Your MyHashMap object will be instantiated and called as such:\n * MyHashMap obj = new MyHashMap();\n * obj.Put(key,value);\n * int param_2 = obj.Get(key);\n * obj.Remove(key);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Initialize your data structure here.\n */\nvar MyHashMap = function() {\n\n};\n\n/**\n * value will always be non-negative. \n * @param {number} key \n * @param {number} value\n * @return {void}\n */\nMyHashMap.prototype.put = function(key, value) {\n\n};\n\n/**\n * Returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key \n * @param {number} key\n * @return {number}\n */\nMyHashMap.prototype.get = function(key) {\n\n};\n\n/**\n * Removes the mapping of the specified value key if this map contains a mapping for the key \n * @param {number} key\n * @return {void}\n */\nMyHashMap.prototype.remove = function(key) {\n\n};\n\n/**\n * Your MyHashMap object will be instantiated and called as such:\n * var obj = new MyHashMap()\n * obj.put(key,value)\n * var param_2 = obj.get(key)\n * obj.remove(key)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class MyHashMap\n\n=begin\n Initialize your data structure here.\n=end\n def initialize()\n\n end\n\n\n=begin\n value will always be non-negative.\n :type key: Integer\n :type value: Integer\n :rtype: Void\n=end\n def put(key, value)\n\n end\n\n\n=begin\n Returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key\n :type key: Integer\n :rtype: Integer\n=end\n def get(key)\n\n end\n\n\n=begin\n Removes the mapping of the specified value key if this map contains a mapping for the key\n :type key: Integer\n :rtype: Void\n=end\n def remove(key)\n\n end\n\n\nend\n\n# Your MyHashMap object will be instantiated and called as such:\n# obj = MyHashMap.new()\n# obj.put(key, value)\n# param_2 = obj.get(key)\n# obj.remove(key)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass MyHashMap {\n\n /** Initialize your data structure here. */\n init() {\n\n }\n \n /** value will always be non-negative. */\n func put(_ key: Int, _ value: Int) {\n\n }\n \n /** Returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key */\n func get(_ key: Int) -> Int {\n\n }\n \n /** Removes the mapping of the specified value key if this map contains a mapping for the key */\n func remove(_ key: Int) {\n\n }\n}\n\n/**\n * Your MyHashMap object will be instantiated and called as such:\n * let obj = MyHashMap()\n * obj.put(key, value)\n * let ret_2: Int = obj.get(key)\n * obj.remove(key)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type MyHashMap struct {\n\n}\n\n\n/** Initialize your data structure here. */\nfunc Constructor() MyHashMap {\n\n}\n\n\n/** value will always be non-negative. */\nfunc (this *MyHashMap) Put(key int, value int) {\n\n}\n\n\n/** Returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key */\nfunc (this *MyHashMap) Get(key int) int {\n\n}\n\n\n/** Removes the mapping of the specified value key if this map contains a mapping for the key */\nfunc (this *MyHashMap) Remove(key int) {\n\n}\n\n\n/**\n * Your MyHashMap object will be instantiated and called as such:\n * obj := Constructor();\n * obj.Put(key,value);\n * param_2 := obj.Get(key);\n * obj.Remove(key);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class MyHashMap() {\n\n /** Initialize your data structure here. */\n\n\n /** value will always be non-negative. */\n def put(key: Int, value: Int) {\n\n }\n\n /** Returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key */\n def get(key: Int): Int = {\n\n }\n\n /** Removes the mapping of the specified value key if this map contains a mapping for the key */\n def remove(key: Int) {\n\n }\n\n}\n\n/**\n * Your MyHashMap object will be instantiated and called as such:\n * var obj = new MyHashMap()\n * obj.put(key,value)\n * var param_2 = obj.get(key)\n * obj.remove(key)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class MyHashMap() {\n\n /** Initialize your data structure here. */\n\n\n /** value will always be non-negative. */\n fun put(key: Int, value: Int) {\n\n }\n\n /** Returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key */\n fun get(key: Int): Int {\n\n }\n\n /** Removes the mapping of the specified value key if this map contains a mapping for the key */\n fun remove(key: Int) {\n\n }\n\n}\n\n/**\n * Your MyHashMap object will be instantiated and called as such:\n * var obj = MyHashMap()\n * obj.put(key,value)\n * var param_2 = obj.get(key)\n * obj.remove(key)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct MyHashMap {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl MyHashMap {\n\n /** Initialize your data structure here. */\n fn new() -> Self {\n\n }\n \n /** value will always be non-negative. */\n fn put(&self, key: i32, value: i32) {\n\n }\n \n /** Returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key */\n fn get(&self, key: i32) -> i32 {\n\n }\n \n /** Removes the mapping of the specified value key if this map contains a mapping for the key */\n fn remove(&self, key: i32) {\n\n }\n}\n\n/**\n * Your MyHashMap object will be instantiated and called as such:\n * let obj = MyHashMap::new();\n * obj.put(key, value);\n * let ret_2: i32 = obj.get(key);\n * obj.remove(key);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class MyHashMap {\n /**\n * Initialize your data structure here.\n */\n function __construct() {\n\n }\n\n /**\n * value will always be non-negative.\n * @param Integer $key\n * @param Integer $value\n * @return NULL\n */\n function put($key, $value) {\n\n }\n\n /**\n * Returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key\n * @param Integer $key\n * @return Integer\n */\n function get($key) {\n\n }\n\n /**\n * Removes the mapping of the specified value key if this map contains a mapping for the key\n * @param Integer $key\n * @return NULL\n */\n function remove($key) {\n\n }\n}\n\n/**\n * Your MyHashMap object will be instantiated and called as such:\n * $obj = MyHashMap();\n * $obj->put($key, $value);\n * $ret_2 = $obj->get($key);\n * $obj->remove($key);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class MyHashMap {\n constructor() {\n\n }\n\n put(key: number, value: number): void {\n\n }\n\n get(key: number): number {\n\n }\n\n remove(key: number): void {\n\n }\n}\n\n/**\n * Your MyHashMap object will be instantiated and called as such:\n * var obj = new MyHashMap()\n * obj.put(key,value)\n * var param_2 = obj.get(key)\n * obj.remove(key)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define my-hash-map%\n (class object%\n (super-new)\n (init-field)\n \n ; put : exact-integer? exact-integer? -> void?\n (define/public (put key value)\n\n )\n ; get : exact-integer? -> exact-integer?\n (define/public (get key)\n\n )\n ; remove : exact-integer? -> void?\n (define/public (remove key)\n\n )))\n\n;; Your my-hash-map% object will be instantiated and called as such:\n;; (define obj (new my-hash-map%))\n;; (send obj put key value)\n;; (define param_2 (send obj get key))\n;; (send obj remove key)", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0706](https://leetcode-cn.com/problems/design-hashmap)", "[\u8bbe\u8ba1\u54c8\u5e0c\u6620\u5c04](/solution/0700-0799/0706.Design%20HashMap/README.md)", "`\u8bbe\u8ba1`,`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0706](https://leetcode.com/problems/design-hashmap)", "[Design HashMap](/solution/0700-0799/0706.Design%20HashMap/README_EN.md)", "`Design`,`Hash Table`", "Easy", ""]}, {"question_id": "0816", "frontend_question_id": "0705", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/design-hashset", "url_en": "https://leetcode.com/problems/design-hashset", "relative_path_cn": "/solution/0700-0799/0705.Design%20HashSet/README.md", "relative_path_en": "/solution/0700-0799/0705.Design%20HashSet/README_EN.md", "title_cn": "\u8bbe\u8ba1\u54c8\u5e0c\u96c6\u5408", "title_en": "Design HashSet", "question_title_slug": "design-hashset", "content_en": "

Design a HashSet without using any built-in hash table libraries.

\n\n

Implement MyHashSet class:

\n\n
    \n\t
  • void add(key) Inserts the value key into the HashSet.
  • \n\t
  • bool contains(key) Returns whether the value key exists in the HashSet or not.
  • \n\t
  • void remove(key) Removes the value key in the HashSet. If key does not exist in the HashSet, do nothing.
  • \n
\n\n

 

\n

Example 1:

\n\n
\nInput\n["MyHashSet", "add", "add", "contains", "contains", "add", "contains", "remove", "contains"]\n[[], [1], [2], [1], [3], [2], [2], [2], [2]]\nOutput\n[null, null, null, true, false, null, true, null, false]\n\nExplanation\nMyHashSet myHashSet = new MyHashSet();\nmyHashSet.add(1);      // set = [1]\nmyHashSet.add(2);      // set = [1, 2]\nmyHashSet.contains(1); // return True\nmyHashSet.contains(3); // return False, (not found)\nmyHashSet.add(2);      // set = [1, 2]\nmyHashSet.contains(2); // return True\nmyHashSet.remove(2);   // set = [1]\nmyHashSet.contains(2); // return False, (already removed)
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 0 <= key <= 106
  • \n\t
  • At most 104 calls will be made to add, remove, and contains.
  • \n
\n", "content_cn": "

\u4e0d\u4f7f\u7528\u4efb\u4f55\u5185\u5efa\u7684\u54c8\u5e0c\u8868\u5e93\u8bbe\u8ba1\u4e00\u4e2a\u54c8\u5e0c\u96c6\u5408\uff08HashSet\uff09\u3002

\n\n

\u5b9e\u73b0 MyHashSet \u7c7b\uff1a

\n\n
    \n\t
  • void add(key) \u5411\u54c8\u5e0c\u96c6\u5408\u4e2d\u63d2\u5165\u503c key \u3002
  • \n\t
  • bool contains(key) \u8fd4\u56de\u54c8\u5e0c\u96c6\u5408\u4e2d\u662f\u5426\u5b58\u5728\u8fd9\u4e2a\u503c key \u3002
  • \n\t
  • void remove(key) \u5c06\u7ed9\u5b9a\u503c key \u4ece\u54c8\u5e0c\u96c6\u5408\u4e2d\u5220\u9664\u3002\u5982\u679c\u54c8\u5e0c\u96c6\u5408\u4e2d\u6ca1\u6709\u8fd9\u4e2a\u503c\uff0c\u4ec0\u4e48\u4e5f\u4e0d\u505a\u3002
  • \n
\n\u00a0\n\n

\u793a\u4f8b\uff1a

\n\n
\n\u8f93\u5165\uff1a\n[\"MyHashSet\", \"add\", \"add\", \"contains\", \"contains\", \"add\", \"contains\", \"remove\", \"contains\"]\n[[], [1], [2], [1], [3], [2], [2], [2], [2]]\n\u8f93\u51fa\uff1a\n[null, null, null, true, false, null, true, null, false]\n\n\u89e3\u91ca\uff1a\nMyHashSet myHashSet = new MyHashSet();\nmyHashSet.add(1);      // set = [1]\nmyHashSet.add(2);      // set = [1, 2]\nmyHashSet.contains(1); // \u8fd4\u56de True\nmyHashSet.contains(3); // \u8fd4\u56de False \uff0c\uff08\u672a\u627e\u5230\uff09\nmyHashSet.add(2);      // set = [1, 2]\nmyHashSet.contains(2); // \u8fd4\u56de True\nmyHashSet.remove(2);   // set = [1]\nmyHashSet.contains(2); // \u8fd4\u56de False \uff0c\uff08\u5df2\u79fb\u9664\uff09
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 0 <= key <= 106
  • \n\t
  • \u6700\u591a\u8c03\u7528 104 \u6b21 add\u3001remove \u548c contains \u3002
  • \n
\n\n

\u00a0

\n\n

\u8fdb\u9636\uff1a\u4f60\u53ef\u4ee5\u4e0d\u4f7f\u7528\u5185\u5efa\u7684\u54c8\u5e0c\u96c6\u5408\u5e93\u89e3\u51b3\u6b64\u95ee\u9898\u5417\uff1f

\n", "tags_en": ["Design", "Hash Table"], "tags_cn": ["\u8bbe\u8ba1", "\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class MyHashSet {\npublic:\n /** Initialize your data structure here. */\n MyHashSet() {\n\n }\n \n void add(int key) {\n\n }\n \n void remove(int key) {\n\n }\n \n /** Returns true if this set contains the specified element */\n bool contains(int key) {\n\n }\n};\n\n/**\n * Your MyHashSet object will be instantiated and called as such:\n * MyHashSet* obj = new MyHashSet();\n * obj->add(key);\n * obj->remove(key);\n * bool param_3 = obj->contains(key);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class MyHashSet {\n\n /** Initialize your data structure here. */\n public MyHashSet() {\n\n }\n \n public void add(int key) {\n\n }\n \n public void remove(int key) {\n\n }\n \n /** Returns true if this set contains the specified element */\n public boolean contains(int key) {\n\n }\n}\n\n/**\n * Your MyHashSet object will be instantiated and called as such:\n * MyHashSet obj = new MyHashSet();\n * obj.add(key);\n * obj.remove(key);\n * boolean param_3 = obj.contains(key);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class MyHashSet(object):\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def add(self, key):\n \"\"\"\n :type key: int\n :rtype: None\n \"\"\"\n\n\n def remove(self, key):\n \"\"\"\n :type key: int\n :rtype: None\n \"\"\"\n\n\n def contains(self, key):\n \"\"\"\n Returns true if this set contains the specified element\n :type key: int\n :rtype: bool\n \"\"\"\n\n\n\n# Your MyHashSet object will be instantiated and called as such:\n# obj = MyHashSet()\n# obj.add(key)\n# obj.remove(key)\n# param_3 = obj.contains(key)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class MyHashSet:\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def add(self, key: int) -> None:\n\n\n def remove(self, key: int) -> None:\n\n\n def contains(self, key: int) -> bool:\n \"\"\"\n Returns true if this set contains the specified element\n \"\"\"\n\n\n\n# Your MyHashSet object will be instantiated and called as such:\n# obj = MyHashSet()\n# obj.add(key)\n# obj.remove(key)\n# param_3 = obj.contains(key)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} MyHashSet;\n\n/** Initialize your data structure here. */\n\nMyHashSet* myHashSetCreate() {\n\n}\n\nvoid myHashSetAdd(MyHashSet* obj, int key) {\n\n}\n\nvoid myHashSetRemove(MyHashSet* obj, int key) {\n\n}\n\n/** Returns true if this set contains the specified element */\nbool myHashSetContains(MyHashSet* obj, int key) {\n\n}\n\nvoid myHashSetFree(MyHashSet* obj) {\n\n}\n\n/**\n * Your MyHashSet struct will be instantiated and called as such:\n * MyHashSet* obj = myHashSetCreate();\n * myHashSetAdd(obj, key);\n \n * myHashSetRemove(obj, key);\n \n * bool param_3 = myHashSetContains(obj, key);\n \n * myHashSetFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class MyHashSet {\n\n /** Initialize your data structure here. */\n public MyHashSet() {\n\n }\n \n public void Add(int key) {\n\n }\n \n public void Remove(int key) {\n\n }\n \n /** Returns true if this set contains the specified element */\n public bool Contains(int key) {\n\n }\n}\n\n/**\n * Your MyHashSet object will be instantiated and called as such:\n * MyHashSet obj = new MyHashSet();\n * obj.Add(key);\n * obj.Remove(key);\n * bool param_3 = obj.Contains(key);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Initialize your data structure here.\n */\nvar MyHashSet = function() {\n\n};\n\n/** \n * @param {number} key\n * @return {void}\n */\nMyHashSet.prototype.add = function(key) {\n\n};\n\n/** \n * @param {number} key\n * @return {void}\n */\nMyHashSet.prototype.remove = function(key) {\n\n};\n\n/**\n * Returns true if this set contains the specified element \n * @param {number} key\n * @return {boolean}\n */\nMyHashSet.prototype.contains = function(key) {\n\n};\n\n/**\n * Your MyHashSet object will be instantiated and called as such:\n * var obj = new MyHashSet()\n * obj.add(key)\n * obj.remove(key)\n * var param_3 = obj.contains(key)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class MyHashSet\n\n=begin\n Initialize your data structure here.\n=end\n def initialize()\n\n end\n\n\n=begin\n :type key: Integer\n :rtype: Void\n=end\n def add(key)\n\n end\n\n\n=begin\n :type key: Integer\n :rtype: Void\n=end\n def remove(key)\n\n end\n\n\n=begin\n Returns true if this set contains the specified element\n :type key: Integer\n :rtype: Boolean\n=end\n def contains(key)\n\n end\n\n\nend\n\n# Your MyHashSet object will be instantiated and called as such:\n# obj = MyHashSet.new()\n# obj.add(key)\n# obj.remove(key)\n# param_3 = obj.contains(key)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass MyHashSet {\n\n /** Initialize your data structure here. */\n init() {\n\n }\n \n func add(_ key: Int) {\n\n }\n \n func remove(_ key: Int) {\n\n }\n \n /** Returns true if this set contains the specified element */\n func contains(_ key: Int) -> Bool {\n\n }\n}\n\n/**\n * Your MyHashSet object will be instantiated and called as such:\n * let obj = MyHashSet()\n * obj.add(key)\n * obj.remove(key)\n * let ret_3: Bool = obj.contains(key)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type MyHashSet struct {\n\n}\n\n\n/** Initialize your data structure here. */\nfunc Constructor() MyHashSet {\n\n}\n\n\nfunc (this *MyHashSet) Add(key int) {\n\n}\n\n\nfunc (this *MyHashSet) Remove(key int) {\n\n}\n\n\n/** Returns true if this set contains the specified element */\nfunc (this *MyHashSet) Contains(key int) bool {\n\n}\n\n\n/**\n * Your MyHashSet object will be instantiated and called as such:\n * obj := Constructor();\n * obj.Add(key);\n * obj.Remove(key);\n * param_3 := obj.Contains(key);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class MyHashSet() {\n\n /** Initialize your data structure here. */\n\n\n def add(key: Int) {\n\n }\n\n def remove(key: Int) {\n\n }\n\n /** Returns true if this set contains the specified element */\n def contains(key: Int): Boolean = {\n\n }\n\n}\n\n/**\n * Your MyHashSet object will be instantiated and called as such:\n * var obj = new MyHashSet()\n * obj.add(key)\n * obj.remove(key)\n * var param_3 = obj.contains(key)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class MyHashSet() {\n\n /** Initialize your data structure here. */\n\n\n fun add(key: Int) {\n\n }\n\n fun remove(key: Int) {\n\n }\n\n /** Returns true if this set contains the specified element */\n fun contains(key: Int): Boolean {\n\n }\n\n}\n\n/**\n * Your MyHashSet object will be instantiated and called as such:\n * var obj = MyHashSet()\n * obj.add(key)\n * obj.remove(key)\n * var param_3 = obj.contains(key)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct MyHashSet {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl MyHashSet {\n\n /** Initialize your data structure here. */\n fn new() -> Self {\n\n }\n \n fn add(&self, key: i32) {\n\n }\n \n fn remove(&self, key: i32) {\n\n }\n \n /** Returns true if this set contains the specified element */\n fn contains(&self, key: i32) -> bool {\n\n }\n}\n\n/**\n * Your MyHashSet object will be instantiated and called as such:\n * let obj = MyHashSet::new();\n * obj.add(key);\n * obj.remove(key);\n * let ret_3: bool = obj.contains(key);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class MyHashSet {\n /**\n * Initialize your data structure here.\n */\n function __construct() {\n\n }\n\n /**\n * @param Integer $key\n * @return NULL\n */\n function add($key) {\n\n }\n\n /**\n * @param Integer $key\n * @return NULL\n */\n function remove($key) {\n\n }\n\n /**\n * Returns true if this set contains the specified element\n * @param Integer $key\n * @return Boolean\n */\n function contains($key) {\n\n }\n}\n\n/**\n * Your MyHashSet object will be instantiated and called as such:\n * $obj = MyHashSet();\n * $obj->add($key);\n * $obj->remove($key);\n * $ret_3 = $obj->contains($key);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class MyHashSet {\n constructor() {\n\n }\n\n add(key: number): void {\n\n }\n\n remove(key: number): void {\n\n }\n\n contains(key: number): boolean {\n\n }\n}\n\n/**\n * Your MyHashSet object will be instantiated and called as such:\n * var obj = new MyHashSet()\n * obj.add(key)\n * obj.remove(key)\n * var param_3 = obj.contains(key)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define my-hash-set%\n (class object%\n (super-new)\n (init-field)\n \n ; add : exact-integer? -> void?\n (define/public (add key)\n\n )\n ; remove : exact-integer? -> void?\n (define/public (remove key)\n\n )\n ; contains : exact-integer? -> boolean?\n (define/public (contains key)\n\n )))\n\n;; Your my-hash-set% object will be instantiated and called as such:\n;; (define obj (new my-hash-set%))\n;; (send obj add key)\n;; (send obj remove key)\n;; (define param_3 (send obj contains key))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0705](https://leetcode-cn.com/problems/design-hashset)", "[\u8bbe\u8ba1\u54c8\u5e0c\u96c6\u5408](/solution/0700-0799/0705.Design%20HashSet/README.md)", "`\u8bbe\u8ba1`,`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0705](https://leetcode.com/problems/design-hashset)", "[Design HashSet](/solution/0700-0799/0705.Design%20HashSet/README_EN.md)", "`Design`,`Hash Table`", "Easy", ""]}, {"question_id": "0815", "frontend_question_id": "0799", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/champagne-tower", "url_en": "https://leetcode.com/problems/champagne-tower", "relative_path_cn": "/solution/0700-0799/0799.Champagne%20Tower/README.md", "relative_path_en": "/solution/0700-0799/0799.Champagne%20Tower/README_EN.md", "title_cn": "\u9999\u69df\u5854", "title_en": "Champagne Tower", "question_title_slug": "champagne-tower", "content_en": "

We stack glasses in a pyramid, where the first row has 1 glass, the second row has 2 glasses, and so on until the 100th row.  Each glass holds one cup of champagne.

\r\n\r\n

Then, some champagne is poured into the first glass at the top.  When the topmost glass is full, any excess liquid poured will fall equally to the glass immediately to the left and right of it.  When those glasses become full, any excess champagne will fall equally to the left and right of those glasses, and so on.  (A glass at the bottom row has its excess champagne fall on the floor.)

\r\n\r\n

For example, after one cup of champagne is poured, the top most glass is full.  After two cups of champagne are poured, the two glasses on the second row are half full.  After three cups of champagne are poured, those two cups become full - there are 3 full glasses total now.  After four cups of champagne are poured, the third row has the middle glass half full, and the two outside glasses are a quarter full, as pictured below.

\r\n\r\n

\"\"

\r\n\r\n

Now after pouring some non-negative integer cups of champagne, return how full the jth glass in the ith row is (both i and j are 0-indexed.)

\r\n\r\n

 

\r\n

Example 1:

\r\n\r\n
\r\nInput: poured = 1, query_row = 1, query_glass = 1\r\nOutput: 0.00000\r\nExplanation: We poured 1 cup of champange to the top glass of the tower (which is indexed as (0, 0)). There will be no excess liquid so all the glasses under the top glass will remain empty.\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: poured = 2, query_row = 1, query_glass = 1\r\nOutput: 0.50000\r\nExplanation: We poured 2 cups of champange to the top glass of the tower (which is indexed as (0, 0)). There is one cup of excess liquid. The glass indexed as (1, 0) and the glass indexed as (1, 1) will share the excess liquid equally, and each will get half cup of champange.\r\n
\r\n\r\n

Example 3:

\r\n\r\n
\r\nInput: poured = 100000009, query_row = 33, query_glass = 17\r\nOutput: 1.00000\r\n
\r\n\r\n

 

\r\n

Constraints:

\r\n\r\n
    \r\n\t
  • 0 <= poured <= 109
  • \r\n\t
  • 0 <= query_glass <= query_row < 100
  • \r\n
", "content_cn": "

\u6211\u4eec\u628a\u73bb\u7483\u676f\u6446\u6210\u91d1\u5b57\u5854\u7684\u5f62\u72b6\uff0c\u5176\u4e2d\u7b2c\u4e00\u5c42\u67091\u4e2a\u73bb\u7483\u676f\uff0c\u7b2c\u4e8c\u5c42\u67092\u4e2a\uff0c\u4f9d\u6b21\u7c7b\u63a8\u5230\u7b2c100\u5c42\uff0c\u6bcf\u4e2a\u73bb\u7483\u676f(250ml)\u5c06\u76db\u6709\u9999\u69df\u3002

\n\n

\u4ece\u9876\u5c42\u7684\u7b2c\u4e00\u4e2a\u73bb\u7483\u676f\u5f00\u59cb\u503e\u5012\u4e00\u4e9b\u9999\u69df\uff0c\u5f53\u9876\u5c42\u7684\u676f\u5b50\u6ee1\u4e86\uff0c\u4efb\u4f55\u6ea2\u51fa\u7684\u9999\u69df\u90fd\u4f1a\u7acb\u523b\u7b49\u6d41\u91cf\u7684\u6d41\u5411\u5de6\u53f3\u4e24\u4fa7\u7684\u73bb\u7483\u676f\u3002\u5f53\u5de6\u53f3\u4e24\u8fb9\u7684\u676f\u5b50\u4e5f\u6ee1\u4e86\uff0c\u5c31\u4f1a\u7b49\u6d41\u91cf\u7684\u6d41\u5411\u5b83\u4eec\u5de6\u53f3\u4e24\u8fb9\u7684\u676f\u5b50\uff0c\u4f9d\u6b21\u7c7b\u63a8\u3002\uff08\u5f53\u6700\u5e95\u5c42\u7684\u73bb\u7483\u676f\u6ee1\u4e86\uff0c\u9999\u69df\u4f1a\u6d41\u5230\u5730\u677f\u4e0a\uff09

\n\n

\u4f8b\u5982\uff0c\u5728\u503e\u5012\u4e00\u676f\u9999\u69df\u540e\uff0c\u6700\u9876\u5c42\u7684\u73bb\u7483\u676f\u6ee1\u4e86\u3002\u503e\u5012\u4e86\u4e24\u676f\u9999\u69df\u540e\uff0c\u7b2c\u4e8c\u5c42\u7684\u4e24\u4e2a\u73bb\u7483\u676f\u5404\u81ea\u76db\u653e\u4e00\u534a\u7684\u9999\u69df\u3002\u5728\u5012\u4e09\u676f\u9999\u69df\u540e\uff0c\u7b2c\u4e8c\u5c42\u7684\u9999\u69df\u6ee1\u4e86 - \u6b64\u65f6\u603b\u5171\u6709\u4e09\u4e2a\u6ee1\u7684\u73bb\u7483\u676f\u3002\u5728\u5012\u7b2c\u56db\u676f\u540e\uff0c\u7b2c\u4e09\u5c42\u4e2d\u95f4\u7684\u73bb\u7483\u676f\u76db\u653e\u4e86\u4e00\u534a\u7684\u9999\u69df\uff0c\u4ed6\u4e24\u8fb9\u7684\u73bb\u7483\u676f\u5404\u81ea\u76db\u653e\u4e86\u56db\u5206\u4e4b\u4e00\u7684\u9999\u69df\uff0c\u5982\u4e0b\u56fe\u6240\u793a\u3002

\n\n

\"\"

\n\n

\u73b0\u5728\u5f53\u503e\u5012\u4e86\u975e\u8d1f\u6574\u6570\u676f\u9999\u69df\u540e\uff0c\u8fd4\u56de\u7b2c i \u884c j \u4e2a\u73bb\u7483\u676f\u6240\u76db\u653e\u7684\u9999\u69df\u5360\u73bb\u7483\u676f\u5bb9\u79ef\u7684\u6bd4\u4f8b\uff08i \u548c j\u90fd\u4ece0\u5f00\u59cb\uff09\u3002

\n\n

 

\n\n
\n\u793a\u4f8b 1:\n\u8f93\u5165: poured(\u503e\u5012\u9999\u69df\u603b\u676f\u6570) = 1, query_glass(\u676f\u5b50\u7684\u4f4d\u7f6e\u6570) = 1, query_row(\u884c\u6570) = 1\n\u8f93\u51fa: 0.0\n\u89e3\u91ca: \u6211\u4eec\u5728\u9876\u5c42\uff08\u4e0b\u6807\u662f\uff080\uff0c0\uff09\uff09\u5012\u4e86\u4e00\u676f\u9999\u69df\u540e\uff0c\u6ca1\u6709\u6ea2\u51fa\uff0c\u56e0\u6b64\u6240\u6709\u5728\u9876\u5c42\u4ee5\u4e0b\u7684\u73bb\u7483\u676f\u90fd\u662f\u7a7a\u7684\u3002\n\n\u793a\u4f8b 2:\n\u8f93\u5165: poured(\u503e\u5012\u9999\u69df\u603b\u676f\u6570) = 2, query_glass(\u676f\u5b50\u7684\u4f4d\u7f6e\u6570) = 1, query_row(\u884c\u6570) = 1\n\u8f93\u51fa: 0.5\n\u89e3\u91ca: \u6211\u4eec\u5728\u9876\u5c42\uff08\u4e0b\u6807\u662f\uff080\uff0c0\uff09\u5012\u4e86\u4e24\u676f\u9999\u69df\u540e\uff0c\u6709\u4e00\u676f\u91cf\u7684\u9999\u69df\u5c06\u4ece\u9876\u5c42\u6ea2\u51fa\uff0c\u4f4d\u4e8e\uff081\uff0c0\uff09\u7684\u73bb\u7483\u676f\u548c\uff081\uff0c1\uff09\u7684\u73bb\u7483\u676f\u5e73\u5206\u4e86\u8fd9\u4e00\u676f\u9999\u69df\uff0c\u6240\u4ee5\u6bcf\u4e2a\u73bb\u7483\u676f\u6709\u4e00\u534a\u7684\u9999\u69df\u3002\n
\n\n

\u6ce8\u610f:

\n\n
    \n\t
  • poured \u7684\u8303\u56f4[0, 10 ^ 9]\u3002
  • \n\t
  • query_glass \u548cquery_row \u7684\u8303\u56f4 [0, 99]\u3002
  • \n
\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n double champagneTower(int poured, int query_row, int query_glass) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double champagneTower(int poured, int query_row, int query_glass) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def champagneTower(self, poured, query_row, query_glass):\n \"\"\"\n :type poured: int\n :type query_row: int\n :type query_glass: int\n :rtype: float\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def champagneTower(self, poured: int, query_row: int, query_glass: int) -> float:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\ndouble champagneTower(int poured, int query_row, int query_glass){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double ChampagneTower(int poured, int query_row, int query_glass) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} poured\n * @param {number} query_row\n * @param {number} query_glass\n * @return {number}\n */\nvar champagneTower = function(poured, query_row, query_glass) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} poured\n# @param {Integer} query_row\n# @param {Integer} query_glass\n# @return {Float}\ndef champagne_tower(poured, query_row, query_glass)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func champagneTower(_ poured: Int, _ query_row: Int, _ query_glass: Int) -> Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func champagneTower(poured int, query_row int, query_glass int) float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def champagneTower(poured: Int, query_row: Int, query_glass: Int): Double = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun champagneTower(poured: Int, query_row: Int, query_glass: Int): Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn champagne_tower(poured: i32, query_row: i32, query_glass: i32) -> f64 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $poured\n * @param Integer $query_row\n * @param Integer $query_glass\n * @return Float\n */\n function champagneTower($poured, $query_row, $query_glass) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function champagneTower(poured: number, query_row: number, query_glass: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (champagne-tower poured query_row query_glass)\n (-> exact-integer? exact-integer? exact-integer? flonum?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0799](https://leetcode-cn.com/problems/champagne-tower)", "[\u9999\u69df\u5854](/solution/0700-0799/0799.Champagne%20Tower/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0799](https://leetcode.com/problems/champagne-tower)", "[Champagne Tower](/solution/0700-0799/0799.Champagne%20Tower/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0814", "frontend_question_id": "0798", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/smallest-rotation-with-highest-score", "url_en": "https://leetcode.com/problems/smallest-rotation-with-highest-score", "relative_path_cn": "/solution/0700-0799/0798.Smallest%20Rotation%20with%20Highest%20Score/README.md", "relative_path_en": "/solution/0700-0799/0798.Smallest%20Rotation%20with%20Highest%20Score/README_EN.md", "title_cn": "\u5f97\u5206\u6700\u9ad8\u7684\u6700\u5c0f\u8f6e\u8c03", "title_en": "Smallest Rotation with Highest Score", "question_title_slug": "smallest-rotation-with-highest-score", "content_en": "

Given an array nums, we may rotate it by a non-negative integer k so that the array becomes nums[k], nums[k+1], nums[k+2], ... nums[nums.length - 1], nums[0], nums[1], ..., nums[k-1].  Afterward, any entries that are less than or equal to their index are worth 1 point.

\n\n

For example, if we have [2, 4, 1, 3, 0], and we rotate by k = 2, it becomes [1, 3, 0, 2, 4]. This is worth 3 points because 1 > 0 [no points], 3 > 1 [no points], 0 <= 2 [one point], 2 <= 3 [one point], 4 <= 4 [one point].

\n\n

Over all possible rotations, return the rotation index k that corresponds to the highest score we could receive. If there are multiple answers, return the smallest such index k.

\n\n
\nExample 1:\nInput: [2, 3, 1, 4, 0]\nOutput: 3\nExplanation:  \nScores for each k are listed below: \nk = 0,  nums = [2,3,1,4,0],    score 2\nk = 1,  nums = [3,1,4,0,2],    score 3\nk = 2,  nums = [1,4,0,2,3],    score 3\nk = 3,  nums = [4,0,2,3,1],    score 4\nk = 4,  nums = [0,2,3,1,4],    score 3\n
\n\n

So we should choose k = 3, which has the highest score.

\n\n

 

\n\n
\nExample 2:\nInput: [1, 3, 0, 2, 4]\nOutput: 0\nExplanation: nums will always have 3 points no matter how it shifts.\nSo we will choose the smallest k, which is 0.\n
\n\n

Note:

\n\n
    \n\t
  • nums will have length at most 20000.
  • \n\t
  • nums[i] will be in the range [0, nums.length].
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u6570\u7ec4 A\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u5b83\u6309\u4e00\u4e2a\u975e\u8d1f\u6574\u6570 K \u8fdb\u884c\u8f6e\u8c03\uff0c\u8fd9\u6837\u53ef\u4ee5\u4f7f\u6570\u7ec4\u53d8\u4e3a A[K], A[K+1], A{K+2], ... A[A.length - 1], A[0], A[1], ..., A[K-1] \u7684\u5f62\u5f0f\u3002\u6b64\u540e\uff0c\u4efb\u4f55\u503c\u5c0f\u4e8e\u6216\u7b49\u4e8e\u5176\u7d22\u5f15\u7684\u9879\u90fd\u53ef\u4ee5\u8bb0\u4f5c\u4e00\u5206\u3002

\n\n

\u4f8b\u5982\uff0c\u5982\u679c\u6570\u7ec4\u4e3a [2, 4, 1, 3, 0]\uff0c\u6211\u4eec\u6309 K = 2 \u8fdb\u884c\u8f6e\u8c03\u540e\uff0c\u5b83\u5c06\u53d8\u6210 [1, 3, 0, 2, 4]\u3002\u8fd9\u5c06\u8bb0\u4f5c 3 \u5206\uff0c\u56e0\u4e3a 1 > 0 [no points], 3 > 1 [no points], 0 <= 2 [one point], 2 <= 3 [one point], 4 <= 4 [one point]\u3002

\n\n

\u5728\u6240\u6709\u53ef\u80fd\u7684\u8f6e\u8c03\u4e2d\uff0c\u8fd4\u56de\u6211\u4eec\u6240\u80fd\u5f97\u5230\u7684\u6700\u9ad8\u5206\u6570\u5bf9\u5e94\u7684\u8f6e\u8c03\u7d22\u5f15 K\u3002\u5982\u679c\u6709\u591a\u4e2a\u7b54\u6848\uff0c\u8fd4\u56de\u6ee1\u8db3\u6761\u4ef6\u7684\u6700\u5c0f\u7684\u7d22\u5f15 K\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1a[2, 3, 1, 4, 0]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\n\u4e0b\u9762\u5217\u51fa\u4e86\u6bcf\u4e2a K \u7684\u5f97\u5206\uff1a\nK = 0,  A = [2,3,1,4,0],    score 2\nK = 1,  A = [3,1,4,0,2],    score 3\nK = 2,  A = [1,4,0,2,3],    score 3\nK = 3,  A = [4,0,2,3,1],    score 4\nK = 4,  A = [0,2,3,1,4],    score 3\n\u6240\u4ee5\u6211\u4eec\u5e94\u5f53\u9009\u62e9 K = 3\uff0c\u5f97\u5206\u6700\u9ad8\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1a[1, 3, 0, 2, 4]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\nA \u65e0\u8bba\u600e\u4e48\u53d8\u5316\u603b\u662f\u6709 3 \u5206\u3002\n\u6240\u4ee5\u6211\u4eec\u5c06\u9009\u62e9\u6700\u5c0f\u7684 K\uff0c\u5373 0\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • A \u7684\u957f\u5ea6\u6700\u5927\u4e3a 20000\u3002
  • \n\t
  • A[i] \u7684\u53d6\u503c\u8303\u56f4\u662f [0, A.length]\u3002
  • \n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int bestRotation(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int bestRotation(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def bestRotation(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def bestRotation(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint bestRotation(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int BestRotation(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar bestRotation = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef best_rotation(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func bestRotation(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func bestRotation(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def bestRotation(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun bestRotation(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn best_rotation(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function bestRotation($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function bestRotation(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (best-rotation nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0798](https://leetcode-cn.com/problems/smallest-rotation-with-highest-score)", "[\u5f97\u5206\u6700\u9ad8\u7684\u6700\u5c0f\u8f6e\u8c03](/solution/0700-0799/0798.Smallest%20Rotation%20with%20Highest%20Score/README.md)", "", "\u56f0\u96be", ""], "md_table_row_en": ["[0798](https://leetcode.com/problems/smallest-rotation-with-highest-score)", "[Smallest Rotation with Highest Score](/solution/0700-0799/0798.Smallest%20Rotation%20with%20Highest%20Score/README_EN.md)", "", "Hard", ""]}, {"question_id": "0813", "frontend_question_id": "0797", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/all-paths-from-source-to-target", "url_en": "https://leetcode.com/problems/all-paths-from-source-to-target", "relative_path_cn": "/solution/0700-0799/0797.All%20Paths%20From%20Source%20to%20Target/README.md", "relative_path_en": "/solution/0700-0799/0797.All%20Paths%20From%20Source%20to%20Target/README_EN.md", "title_cn": "\u6240\u6709\u53ef\u80fd\u7684\u8def\u5f84", "title_en": "All Paths From Source to Target", "question_title_slug": "all-paths-from-source-to-target", "content_en": "

Given a directed acyclic graph (DAG) of n nodes labeled from 0 to n - 1, find all possible paths from node 0 to node n - 1, and return them in any order.

\n\n

The graph is given as follows: graph[i] is a list of all nodes you can visit from node i (i.e., there is a directed edge from node i to node graph[i][j]).

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: graph = [[1,2],[3],[3],[]]\nOutput: [[0,1,3],[0,2,3]]\nExplanation: There are two paths: 0 -> 1 -> 3 and 0 -> 2 -> 3.\n
\n\n

Example 2:

\n\"\"\n
\nInput: graph = [[4,3,1],[3,2,4],[3],[4],[]]\nOutput: [[0,4],[0,3,4],[0,1,3,4],[0,1,2,3,4],[0,1,4]]\n
\n\n

Example 3:

\n\n
\nInput: graph = [[1],[]]\nOutput: [[0,1]]\n
\n\n

Example 4:

\n\n
\nInput: graph = [[1,2,3],[2],[3],[]]\nOutput: [[0,1,2,3],[0,2,3],[0,3]]\n
\n\n

Example 5:

\n\n
\nInput: graph = [[1,3],[2],[3],[]]\nOutput: [[0,1,2,3],[0,3]]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == graph.length
  • \n\t
  • 2 <= n <= 15
  • \n\t
  • 0 <= graph[i][j] < n
  • \n\t
  • graph[i][j] != i (i.e., there will be no self-loops).
  • \n\t
  • The input graph is guaranteed to be a DAG.
  • \n
\n", "content_cn": "

\u7ed9\u4e00\u4e2a\u6709 n \u4e2a\u7ed3\u70b9\u7684\u6709\u5411\u65e0\u73af\u56fe\uff0c\u627e\u5230\u6240\u6709\u4ece 0 \u5230 n-1 \u7684\u8def\u5f84\u5e76\u8f93\u51fa\uff08\u4e0d\u8981\u6c42\u6309\u987a\u5e8f\uff09

\n\n

\u4e8c\u7ef4\u6570\u7ec4\u7684\u7b2c i \u4e2a\u6570\u7ec4\u4e2d\u7684\u5355\u5143\u90fd\u8868\u793a\u6709\u5411\u56fe\u4e2d i \u53f7\u7ed3\u70b9\u6240\u80fd\u5230\u8fbe\u7684\u4e0b\u4e00\u4e9b\u7ed3\u70b9\uff08\u8bd1\u8005\u6ce8\uff1a\u6709\u5411\u56fe\u662f\u6709\u65b9\u5411\u7684\uff0c\u5373\u89c4\u5b9a\u4e86 a→b \u4f60\u5c31\u4e0d\u80fd\u4ece b→a \uff09\u7a7a\u5c31\u662f\u6ca1\u6709\u4e0b\u4e00\u4e2a\u7ed3\u70b9\u4e86\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1agraph = [[1,2],[3],[3],[]]\n\u8f93\u51fa\uff1a[[0,1,3],[0,2,3]]\n\u89e3\u91ca\uff1a\u6709\u4e24\u6761\u8def\u5f84 0 -> 1 -> 3 \u548c 0 -> 2 -> 3\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1agraph = [[4,3,1],[3,2,4],[3],[4],[]]\n\u8f93\u51fa\uff1a[[0,4],[0,3,4],[0,1,3,4],[0,1,2,3,4],[0,1,4]]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1agraph = [[1],[]]\n\u8f93\u51fa\uff1a[[0,1]]\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1agraph = [[1,2,3],[2],[3],[]]\n\u8f93\u51fa\uff1a[[0,1,2,3],[0,2,3],[0,3]]\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1agraph = [[1,3],[2],[3],[]]\n\u8f93\u51fa\uff1a[[0,1,2,3],[0,3]]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u7ed3\u70b9\u7684\u6570\u91cf\u4f1a\u5728\u8303\u56f4 [2, 15] \u5185\u3002
  • \n\t
  • \u4f60\u53ef\u4ee5\u628a\u8def\u5f84\u4ee5\u4efb\u610f\u987a\u5e8f\u8f93\u51fa\uff0c\u4f46\u5728\u8def\u5f84\u5185\u7684\u7ed3\u70b9\u7684\u987a\u5e8f\u5fc5\u987b\u4fdd\u8bc1\u3002
  • \n
\n", "tags_en": ["Depth-first Search", "Graph", "Backtracking"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u56fe", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> allPathsSourceTarget(vector>& graph) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> allPathsSourceTarget(int[][] graph) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def allPathsSourceTarget(self, graph):\n \"\"\"\n :type graph: List[List[int]]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def allPathsSourceTarget(self, graph: List[List[int]]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** allPathsSourceTarget(int** graph, int graphSize, int* graphColSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> AllPathsSourceTarget(int[][] graph) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} graph\n * @return {number[][]}\n */\nvar allPathsSourceTarget = function(graph) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} graph\n# @return {Integer[][]}\ndef all_paths_source_target(graph)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func allPathsSourceTarget(_ graph: [[Int]]) -> [[Int]] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func allPathsSourceTarget(graph [][]int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def allPathsSourceTarget(graph: Array[Array[Int]]): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun allPathsSourceTarget(graph: Array): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn all_paths_source_target(graph: Vec>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $graph\n * @return Integer[][]\n */\n function allPathsSourceTarget($graph) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function allPathsSourceTarget(graph: number[][]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (all-paths-source-target graph)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0797](https://leetcode-cn.com/problems/all-paths-from-source-to-target)", "[\u6240\u6709\u53ef\u80fd\u7684\u8def\u5f84](/solution/0700-0799/0797.All%20Paths%20From%20Source%20to%20Target/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u56fe`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0797](https://leetcode.com/problems/all-paths-from-source-to-target)", "[All Paths From Source to Target](/solution/0700-0799/0797.All%20Paths%20From%20Source%20to%20Target/README_EN.md)", "`Depth-first Search`,`Graph`,`Backtracking`", "Medium", ""]}, {"question_id": "0812", "frontend_question_id": "0796", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/rotate-string", "url_en": "https://leetcode.com/problems/rotate-string", "relative_path_cn": "/solution/0700-0799/0796.Rotate%20String/README.md", "relative_path_en": "/solution/0700-0799/0796.Rotate%20String/README_EN.md", "title_cn": "\u65cb\u8f6c\u5b57\u7b26\u4e32", "title_en": "Rotate String", "question_title_slug": "rotate-string", "content_en": "

We are given two strings, s and goal.

\n\n

A shift on s consists of taking string s and moving the leftmost character to the rightmost position. For example, if s = 'abcde', then it will be 'bcdea' after one shift on s. Return true if and only if s can become goal after some number of shifts on s.

\n\n
\nExample 1:\nInput: s = 'abcde', goal = 'cdeab'\nOutput: true\n\nExample 2:\nInput: s = 'abcde', goal = 'abced'\nOutput: false\n
\n\n

Note:

\n\n
    \n\t
  • s and goal will have length at most 100.
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e24\u4e2a\u5b57\u7b26\u4e32, A \u548c B\u3002

\n\n

A \u7684\u65cb\u8f6c\u64cd\u4f5c\u5c31\u662f\u5c06 A \u6700\u5de6\u8fb9\u7684\u5b57\u7b26\u79fb\u52a8\u5230\u6700\u53f3\u8fb9\u3002 \u4f8b\u5982, \u82e5 A = 'abcde'\uff0c\u5728\u79fb\u52a8\u4e00\u6b21\u4e4b\u540e\u7ed3\u679c\u5c31\u662f'bcdea' \u3002\u5982\u679c\u5728\u82e5\u5e72\u6b21\u65cb\u8f6c\u64cd\u4f5c\u4e4b\u540e\uff0cA \u80fd\u53d8\u6210B\uff0c\u90a3\u4e48\u8fd4\u56deTrue\u3002

\n\n
\n\u793a\u4f8b 1:\n\u8f93\u5165: A = 'abcde', B = 'cdeab'\n\u8f93\u51fa: true\n\n\u793a\u4f8b 2:\n\u8f93\u5165: A = 'abcde', B = 'abced'\n\u8f93\u51fa: false
\n\n

\u6ce8\u610f\uff1a

\n\n
    \n\t
  • A \u548c B \u957f\u5ea6\u4e0d\u8d85\u8fc7 100\u3002
  • \n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool rotateString(string s, string goal) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean rotateString(String s, String goal) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def rotateString(self, s, goal):\n \"\"\"\n :type s: str\n :type goal: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def rotateString(self, s: str, goal: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool rotateString(char * s, char * goal){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool RotateString(string s, string goal) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string} goal\n * @return {boolean}\n */\nvar rotateString = function(s, goal) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String} goal\n# @return {Boolean}\ndef rotate_string(s, goal)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func rotateString(_ s: String, _ goal: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func rotateString(s string, goal string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def rotateString(s: String, goal: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun rotateString(s: String, goal: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn rotate_string(s: String, goal: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String $goal\n * @return Boolean\n */\n function rotateString($s, $goal) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function rotateString(s: string, goal: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (rotate-string s goal)\n (-> string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0796](https://leetcode-cn.com/problems/rotate-string)", "[\u65cb\u8f6c\u5b57\u7b26\u4e32](/solution/0700-0799/0796.Rotate%20String/README.md)", "", "\u7b80\u5355", ""], "md_table_row_en": ["[0796](https://leetcode.com/problems/rotate-string)", "[Rotate String](/solution/0700-0799/0796.Rotate%20String/README_EN.md)", "", "Easy", ""]}, {"question_id": "0811", "frontend_question_id": "0795", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-subarrays-with-bounded-maximum", "url_en": "https://leetcode.com/problems/number-of-subarrays-with-bounded-maximum", "relative_path_cn": "/solution/0700-0799/0795.Number%20of%20Subarrays%20with%20Bounded%20Maximum/README.md", "relative_path_en": "/solution/0700-0799/0795.Number%20of%20Subarrays%20with%20Bounded%20Maximum/README_EN.md", "title_cn": "\u533a\u95f4\u5b50\u6570\u7ec4\u4e2a\u6570", "title_en": "Number of Subarrays with Bounded Maximum", "question_title_slug": "number-of-subarrays-with-bounded-maximum", "content_en": "

We are given an array nums of positive integers, and two positive integers left and right (left <= right).

\n\n

Return the number of (contiguous, non-empty) subarrays such that the value of the maximum array element in that subarray is at least left and at most right.

\n\n
\nExample:\nInput: \nnums = [2, 1, 4, 3]\nleft = 2\nright = 3\nOutput: 3\nExplanation: There are three subarrays that meet the requirements: [2], [2, 1], [3].\n
\n\n

Note:

\n\n
    \n\t
  • left, right, and nums[i] will be an integer in the range [0, 109].
  • \n\t
  • The length of nums will be in the range of [1, 50000].
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u5143\u7d20\u90fd\u662f\u6b63\u6574\u6570\u7684\u6570\u7ec4A \uff0c\u6b63\u6574\u6570 L \u4ee5\u53ca R (L <= R)\u3002

\n\n

\u6c42\u8fde\u7eed\u3001\u975e\u7a7a\u4e14\u5176\u4e2d\u6700\u5927\u5143\u7d20\u6ee1\u8db3\u5927\u4e8e\u7b49\u4e8eL \u5c0f\u4e8e\u7b49\u4e8eR\u7684\u5b50\u6570\u7ec4\u4e2a\u6570\u3002

\n\n
\u4f8b\u5982 :\n\u8f93\u5165: \nA = [2, 1, 4, 3]\nL = 2\nR = 3\n\u8f93\u51fa: 3\n\u89e3\u91ca: \u6ee1\u8db3\u6761\u4ef6\u7684\u5b50\u6570\u7ec4: [2], [2, 1], [3].\n
\n\n

\u6ce8\u610f:

\n\n
    \n\t
  • L, R  \u548c A[i] \u90fd\u662f\u6574\u6570\uff0c\u8303\u56f4\u5728 [0, 10^9]\u3002
  • \n\t
  • \u6570\u7ec4 A \u7684\u957f\u5ea6\u8303\u56f4\u5728[1, 50000]\u3002
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numSubarrayBoundedMax(vector& nums, int left, int right) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numSubarrayBoundedMax(int[] nums, int left, int right) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numSubarrayBoundedMax(self, nums, left, right):\n \"\"\"\n :type nums: List[int]\n :type left: int\n :type right: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numSubarrayBoundedMax(self, nums: List[int], left: int, right: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numSubarrayBoundedMax(int* nums, int numsSize, int left, int right){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumSubarrayBoundedMax(int[] nums, int left, int right) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} left\n * @param {number} right\n * @return {number}\n */\nvar numSubarrayBoundedMax = function(nums, left, right) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} left\n# @param {Integer} right\n# @return {Integer}\ndef num_subarray_bounded_max(nums, left, right)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numSubarrayBoundedMax(_ nums: [Int], _ left: Int, _ right: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numSubarrayBoundedMax(nums []int, left int, right int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numSubarrayBoundedMax(nums: Array[Int], left: Int, right: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numSubarrayBoundedMax(nums: IntArray, left: Int, right: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_subarray_bounded_max(nums: Vec, left: i32, right: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $left\n * @param Integer $right\n * @return Integer\n */\n function numSubarrayBoundedMax($nums, $left, $right) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numSubarrayBoundedMax(nums: number[], left: number, right: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-subarray-bounded-max nums left right)\n (-> (listof exact-integer?) exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0795](https://leetcode-cn.com/problems/number-of-subarrays-with-bounded-maximum)", "[\u533a\u95f4\u5b50\u6570\u7ec4\u4e2a\u6570](/solution/0700-0799/0795.Number%20of%20Subarrays%20with%20Bounded%20Maximum/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0795](https://leetcode.com/problems/number-of-subarrays-with-bounded-maximum)", "[Number of Subarrays with Bounded Maximum](/solution/0700-0799/0795.Number%20of%20Subarrays%20with%20Bounded%20Maximum/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0810", "frontend_question_id": "0794", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/valid-tic-tac-toe-state", "url_en": "https://leetcode.com/problems/valid-tic-tac-toe-state", "relative_path_cn": "/solution/0700-0799/0794.Valid%20Tic-Tac-Toe%20State/README.md", "relative_path_en": "/solution/0700-0799/0794.Valid%20Tic-Tac-Toe%20State/README_EN.md", "title_cn": "\u6709\u6548\u7684\u4e95\u5b57\u6e38\u620f", "title_en": "Valid Tic-Tac-Toe State", "question_title_slug": "valid-tic-tac-toe-state", "content_en": "

Given a Tic-Tac-Toe board as a string array board, return true if and only if it is possible to reach this board position during the course of a valid tic-tac-toe game.

\n\n

The board is a 3 x 3 array that consists of characters ' ', 'X', and 'O'. The ' ' character represents an empty square.

\n\n

Here are the rules of Tic-Tac-Toe:

\n\n
    \n\t
  • Players take turns placing characters into empty squares ' '.
  • \n\t
  • The first player always places 'X' characters, while the second player always places 'O' characters.
  • \n\t
  • 'X' and 'O' characters are always placed into empty squares, never filled ones.
  • \n\t
  • The game ends when there are three of the same (non-empty) character filling any row, column, or diagonal.
  • \n\t
  • The game also ends if all squares are non-empty.
  • \n\t
  • No more moves can be played if the game is over.
  • \n
\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: board = ["O  ","   ","   "]\nOutput: false\nExplanation: The first player always plays "X".\n
\n\n

Example 2:

\n\"\"\n
\nInput: board = ["XOX"," X ","   "]\nOutput: false\nExplanation: Players take turns making moves.\n
\n\n

Example 3:

\n\"\"\n
\nInput: board = ["XXX","   ","OOO"]\nOutput: false\n
\n\n

Example 4:

\n\"\"\n
\nInput: board = ["XOX","O O","XOX"]\nOutput: true\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • board.length == 3
  • \n\t
  • board[i].length == 3
  • \n\t
  • board[i][j] is either 'X', 'O', or ' '.
  • \n
\n", "content_cn": "

\u7528\u5b57\u7b26\u4e32\u6570\u7ec4\u4f5c\u4e3a\u4e95\u5b57\u6e38\u620f\u7684\u6e38\u620f\u677f board\u3002\u5f53\u4e14\u4ec5\u5f53\u5728\u4e95\u5b57\u6e38\u620f\u8fc7\u7a0b\u4e2d\uff0c\u73a9\u5bb6\u6709\u53ef\u80fd\u5c06\u5b57\u7b26\u653e\u7f6e\u6210\u6e38\u620f\u677f\u6240\u663e\u793a\u7684\u72b6\u6001\u65f6\uff0c\u624d\u8fd4\u56de true\u3002

\n\n

\u8be5\u6e38\u620f\u677f\u662f\u4e00\u4e2a 3 x 3 \u6570\u7ec4\uff0c\u7531\u5b57\u7b26 " "\uff0c"X" \u548c "O" \u7ec4\u6210\u3002\u5b57\u7b26 " " \u4ee3\u8868\u4e00\u4e2a\u7a7a\u4f4d\u3002

\n\n

\u4ee5\u4e0b\u662f\u4e95\u5b57\u6e38\u620f\u7684\u89c4\u5219\uff1a

\n\n
    \n\t
  • \u73a9\u5bb6\u8f6e\u6d41\u5c06\u5b57\u7b26\u653e\u5165\u7a7a\u4f4d\uff08" "\uff09\u4e2d\u3002
  • \n\t
  • \u7b2c\u4e00\u4e2a\u73a9\u5bb6\u603b\u662f\u653e\u5b57\u7b26 “X”\uff0c\u4e14\u7b2c\u4e8c\u4e2a\u73a9\u5bb6\u603b\u662f\u653e\u5b57\u7b26 “O”\u3002
  • \n\t
  • “X” \u548c “O” \u53ea\u5141\u8bb8\u653e\u7f6e\u5728\u7a7a\u4f4d\u4e2d\uff0c\u4e0d\u5141\u8bb8\u5bf9\u5df2\u653e\u6709\u5b57\u7b26\u7684\u4f4d\u7f6e\u8fdb\u884c\u586b\u5145\u3002
  • \n\t
  • \u5f53\u6709 3 \u4e2a\u76f8\u540c\uff08\u4e14\u975e\u7a7a\uff09\u7684\u5b57\u7b26\u586b\u5145\u4efb\u4f55\u884c\u3001\u5217\u6216\u5bf9\u89d2\u7ebf\u65f6\uff0c\u6e38\u620f\u7ed3\u675f\u3002
  • \n\t
  • \u5f53\u6240\u6709\u4f4d\u7f6e\u975e\u7a7a\u65f6\uff0c\u4e5f\u7b97\u4e3a\u6e38\u620f\u7ed3\u675f\u3002
  • \n\t
  • \u5982\u679c\u6e38\u620f\u7ed3\u675f\uff0c\u73a9\u5bb6\u4e0d\u5141\u8bb8\u518d\u653e\u7f6e\u5b57\u7b26\u3002
  • \n
\n\n
\n\u793a\u4f8b 1:\n\u8f93\u5165: board = ["O  ", "   ", "   "]\n\u8f93\u51fa: false\n\u89e3\u91ca: \u7b2c\u4e00\u4e2a\u73a9\u5bb6\u603b\u662f\u653e\u7f6e“X”\u3002\n\n\u793a\u4f8b 2:\n\u8f93\u5165: board = ["XOX", " X ", "   "]\n\u8f93\u51fa: false\n\u89e3\u91ca: \u73a9\u5bb6\u5e94\u8be5\u662f\u8f6e\u6d41\u653e\u7f6e\u7684\u3002\n\n\u793a\u4f8b 3:\n\u8f93\u5165: board = ["XXX", "   ", "OOO"]\n\u8f93\u51fa: false\n\n\u793a\u4f8b 4:\n\u8f93\u5165: board = ["XOX", "O O", "XOX"]\n\u8f93\u51fa: true\n
\n\n

\u8bf4\u660e:

\n\n
    \n\t
  • \u6e38\u620f\u677f board \u662f\u957f\u5ea6\u4e3a 3 \u7684\u5b57\u7b26\u4e32\u6570\u7ec4\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5b57\u7b26\u4e32 board[i] \u7684\u957f\u5ea6\u4e3a 3\u3002
  • \n\t
  •  board[i][j] \u662f\u96c6\u5408 {" ", "X", "O"} \u4e2d\u7684\u4e00\u4e2a\u5b57\u7b26\u3002
  • \n
\n", "tags_en": ["Recursion", "Math"], "tags_cn": ["\u9012\u5f52", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool validTicTacToe(vector& board) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean validTicTacToe(String[] board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def validTicTacToe(self, board):\n \"\"\"\n :type board: List[str]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def validTicTacToe(self, board: List[str]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool validTicTacToe(char ** board, int boardSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool ValidTicTacToe(string[] board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} board\n * @return {boolean}\n */\nvar validTicTacToe = function(board) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} board\n# @return {Boolean}\ndef valid_tic_tac_toe(board)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func validTicTacToe(_ board: [String]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func validTicTacToe(board []string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def validTicTacToe(board: Array[String]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun validTicTacToe(board: Array): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn valid_tic_tac_toe(board: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $board\n * @return Boolean\n */\n function validTicTacToe($board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function validTicTacToe(board: string[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (valid-tic-tac-toe board)\n (-> (listof string?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0794](https://leetcode-cn.com/problems/valid-tic-tac-toe-state)", "[\u6709\u6548\u7684\u4e95\u5b57\u6e38\u620f](/solution/0700-0799/0794.Valid%20Tic-Tac-Toe%20State/README.md)", "`\u9012\u5f52`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0794](https://leetcode.com/problems/valid-tic-tac-toe-state)", "[Valid Tic-Tac-Toe State](/solution/0700-0799/0794.Valid%20Tic-Tac-Toe%20State/README_EN.md)", "`Recursion`,`Math`", "Medium", ""]}, {"question_id": "0809", "frontend_question_id": "0793", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/preimage-size-of-factorial-zeroes-function", "url_en": "https://leetcode.com/problems/preimage-size-of-factorial-zeroes-function", "relative_path_cn": "/solution/0700-0799/0793.Preimage%20Size%20of%20Factorial%20Zeroes%20Function/README.md", "relative_path_en": "/solution/0700-0799/0793.Preimage%20Size%20of%20Factorial%20Zeroes%20Function/README_EN.md", "title_cn": "\u9636\u4e58\u51fd\u6570\u540e K \u4e2a\u96f6", "title_en": "Preimage Size of Factorial Zeroes Function", "question_title_slug": "preimage-size-of-factorial-zeroes-function", "content_en": "

Let f(x) be the number of zeroes at the end of x!. (Recall that x! = 1 * 2 * 3 * ... * x, and by convention, 0! = 1.)

\n\n

For example, f(3) = 0 because 3! = 6 has no zeroes at the end, while f(11) = 2 because 11! = 39916800 has 2 zeroes at the end. Given k, find how many non-negative integers x have the property that f(x) = k.

\n\n
\nExample 1:\nInput: k = 0\nOutput: 5\nExplanation: 0!, 1!, 2!, 3!, and 4! end with k = 0 zeroes.\n\nExample 2:\nInput: k = 5\nOutput: 0\nExplanation: There is no x such that x! ends in k = 5 zeroes.\n
\n\n

Note:

\n\n
    \n\t
  • k will be an integer in the range [0, 109].
  • \n
\n", "content_cn": "

\u00a0f(x)\u00a0\u662f\u00a0x!\u00a0\u672b\u5c3e\u662f 0 \u7684\u6570\u91cf\u3002\uff08\u56de\u60f3\u4e00\u4e0b\u00a0x! = 1 * 2 * 3 * ... * x\uff0c\u4e14 0! = 1 \uff09

\n\n

\u4f8b\u5982\uff0c\u00a0f(3) = 0\u00a0\uff0c\u56e0\u4e3a 3! = 6 \u7684\u672b\u5c3e\u6ca1\u6709 0 \uff1b\u800c f(11) = 2\u00a0\uff0c\u56e0\u4e3a 11!= 39916800 \u672b\u7aef\u6709 2 \u4e2a 0 \u3002\u7ed9\u5b9a\u00a0K\uff0c\u627e\u51fa\u591a\u5c11\u4e2a\u975e\u8d1f\u6574\u6570 x\u00a0\uff0c\u80fd\u6ee1\u8db3 f(x) = K \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aK = 0\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a0!, 1!, 2!, 3!, and 4!\u00a0\u5747\u7b26\u5408 K = 0 \u7684\u6761\u4ef6\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aK = 5\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6ca1\u6709\u5339\u914d\u5230\u8fd9\u6837\u7684 x!\uff0c\u7b26\u5408 K = 5 \u7684\u6761\u4ef6\u3002
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \n\t

    K \u662f\u8303\u56f4\u5728\u00a0[0, 10^9]\u00a0\u7684\u6574\u6570\u3002

    \n\t
  • \n
\n", "tags_en": ["Binary Search"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int preimageSizeFZF(int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int preimageSizeFZF(int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def preimageSizeFZF(self, k):\n \"\"\"\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def preimageSizeFZF(self, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint preimageSizeFZF(int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int PreimageSizeFZF(int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} k\n * @return {number}\n */\nvar preimageSizeFZF = function(k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} k\n# @return {Integer}\ndef preimage_size_fzf(k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func preimageSizeFZF(_ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func preimageSizeFZF(k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def preimageSizeFZF(k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun preimageSizeFZF(k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn preimage_size_fzf(k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $k\n * @return Integer\n */\n function preimageSizeFZF($k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function preimageSizeFZF(k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (preimage-size-fzf k)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0793](https://leetcode-cn.com/problems/preimage-size-of-factorial-zeroes-function)", "[\u9636\u4e58\u51fd\u6570\u540e K \u4e2a\u96f6](/solution/0700-0799/0793.Preimage%20Size%20of%20Factorial%20Zeroes%20Function/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u56f0\u96be", ""], "md_table_row_en": ["[0793](https://leetcode.com/problems/preimage-size-of-factorial-zeroes-function)", "[Preimage Size of Factorial Zeroes Function](/solution/0700-0799/0793.Preimage%20Size%20of%20Factorial%20Zeroes%20Function/README_EN.md)", "`Binary Search`", "Hard", ""]}, {"question_id": "0808", "frontend_question_id": "0792", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-matching-subsequences", "url_en": "https://leetcode.com/problems/number-of-matching-subsequences", "relative_path_cn": "/solution/0700-0799/0792.Number%20of%20Matching%20Subsequences/README.md", "relative_path_en": "/solution/0700-0799/0792.Number%20of%20Matching%20Subsequences/README_EN.md", "title_cn": "\u5339\u914d\u5b50\u5e8f\u5217\u7684\u5355\u8bcd\u6570", "title_en": "Number of Matching Subsequences", "question_title_slug": "number-of-matching-subsequences", "content_en": "

Given a string s and an array of strings words, return the number of words[i] that is a subsequence of s.

\n\n

A subsequence of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters.

\n\n
    \n\t
  • For example, "ace" is a subsequence of "abcde".
  • \n
\n\n

 

\n

Example 1:

\n\n
\nInput: s = "abcde", words = ["a","bb","acd","ace"]\nOutput: 3\nExplanation: There are three strings in words that are a subsequence of s: "a", "acd", "ace".\n
\n\n

Example 2:

\n\n
\nInput: s = "dsahjpjauf", words = ["ahjpjau","ja","ahbwzgqnuk","tnmlanowax"]\nOutput: 2\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 5 * 104
  • \n\t
  • 1 <= words.length <= 5000
  • \n\t
  • 1 <= words[i].length <= 50
  • \n\t
  • s and words[i] consist of only lowercase English letters.
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u5b57\u7b26\u4e32 S \u548c\u5355\u8bcd\u5b57\u5178 words, \u6c42 words[i] \u4e2d\u662f S \u7684\u5b50\u5e8f\u5217\u7684\u5355\u8bcd\u4e2a\u6570\u3002

\n\n
\n\u793a\u4f8b:\n\u8f93\u5165: \nS = "abcde"\nwords = ["a", "bb", "acd", "ace"]\n\u8f93\u51fa: 3\n\u89e3\u91ca: \u6709\u4e09\u4e2a\u662f S \u7684\u5b50\u5e8f\u5217\u7684\u5355\u8bcd: "a", "acd", "ace"\u3002\n
\n\n

\u6ce8\u610f:

\n\n
    \n\t
  • \u6240\u6709\u5728words\u548c S \u91cc\u7684\u5355\u8bcd\u90fd\u53ea\u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210\u3002
  • \n\t
  • S \u7684\u957f\u5ea6\u5728 [1, 50000]\u3002
  • \n\t
  • words \u7684\u957f\u5ea6\u5728 [1, 5000]\u3002
  • \n\t
  • words[i]\u7684\u957f\u5ea6\u5728[1, 50]\u3002
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numMatchingSubseq(string s, vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numMatchingSubseq(String s, String[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numMatchingSubseq(self, s, words):\n \"\"\"\n :type s: str\n :type words: List[str]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numMatchingSubseq(self, s: str, words: List[str]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numMatchingSubseq(char * s, char ** words, int wordsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumMatchingSubseq(string s, string[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string[]} words\n * @return {number}\n */\nvar numMatchingSubseq = function(s, words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String[]} words\n# @return {Integer}\ndef num_matching_subseq(s, words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numMatchingSubseq(_ s: String, _ words: [String]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numMatchingSubseq(s string, words []string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numMatchingSubseq(s: String, words: Array[String]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numMatchingSubseq(s: String, words: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_matching_subseq(s: String, words: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String[] $words\n * @return Integer\n */\n function numMatchingSubseq($s, $words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numMatchingSubseq(s: string, words: string[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-matching-subseq s words)\n (-> string? (listof string?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0792](https://leetcode-cn.com/problems/number-of-matching-subsequences)", "[\u5339\u914d\u5b50\u5e8f\u5217\u7684\u5355\u8bcd\u6570](/solution/0700-0799/0792.Number%20of%20Matching%20Subsequences/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0792](https://leetcode.com/problems/number-of-matching-subsequences)", "[Number of Matching Subsequences](/solution/0700-0799/0792.Number%20of%20Matching%20Subsequences/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0807", "frontend_question_id": "0791", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/custom-sort-string", "url_en": "https://leetcode.com/problems/custom-sort-string", "relative_path_cn": "/solution/0700-0799/0791.Custom%20Sort%20String/README.md", "relative_path_en": "/solution/0700-0799/0791.Custom%20Sort%20String/README_EN.md", "title_cn": "\u81ea\u5b9a\u4e49\u5b57\u7b26\u4e32\u6392\u5e8f", "title_en": "Custom Sort String", "question_title_slug": "custom-sort-string", "content_en": "

order and str are strings composed of lowercase letters. In order, no letter occurs more than once.

\n\n

order was sorted in some custom order previously. We want to permute the characters of str so that they match the order that order was sorted. More specifically, if x occurs before y in order, then x should occur before y in the returned string.

\n\n

Return any permutation of str (as a string) that satisfies this property.

\n\n
\nExample:\nInput: \norder = "cba"\nstr = "abcd"\nOutput: "cbad"\nExplanation: \n"a", "b", "c" appear in order, so the order of "a", "b", "c" should be "c", "b", and "a". \nSince "d" does not appear in order, it can be at any position in the returned string. "dcba", "cdba", "cbda" are also valid outputs.\n
\n\n

 

\n\n

Note:

\n\n
    \n\t
  • order has length at most 26, and no character is repeated in order.
  • \n\t
  • str has length at most 200.
  • \n\t
  • order and str consist of lowercase letters only.
  • \n
\n", "content_cn": "

\u5b57\u7b26\u4e32S\u548c T \u53ea\u5305\u542b\u5c0f\u5199\u5b57\u7b26\u3002\u5728S\u4e2d\uff0c\u6240\u6709\u5b57\u7b26\u53ea\u4f1a\u51fa\u73b0\u4e00\u6b21\u3002

\n\n

S \u5df2\u7ecf\u6839\u636e\u67d0\u79cd\u89c4\u5219\u8fdb\u884c\u4e86\u6392\u5e8f\u3002\u6211\u4eec\u8981\u6839\u636eS\u4e2d\u7684\u5b57\u7b26\u987a\u5e8f\u5bf9T\u8fdb\u884c\u6392\u5e8f\u3002\u66f4\u5177\u4f53\u5730\u8bf4\uff0c\u5982\u679cS\u4e2dx\u5728y\u4e4b\u524d\u51fa\u73b0\uff0c\u90a3\u4e48\u8fd4\u56de\u7684\u5b57\u7b26\u4e32\u4e2dx\u4e5f\u5e94\u51fa\u73b0\u5728y\u4e4b\u524d\u3002

\n\n

\u8fd4\u56de\u4efb\u610f\u4e00\u79cd\u7b26\u5408\u6761\u4ef6\u7684\u5b57\u7b26\u4e32T\u3002

\n\n
\n\u793a\u4f8b:\n\u8f93\u5165:\nS = "cba"\nT = "abcd"\n\u8f93\u51fa: "cbad"\n\u89e3\u91ca: \nS\u4e2d\u51fa\u73b0\u4e86\u5b57\u7b26 "a", "b", "c", \u6240\u4ee5 "a", "b", "c" \u7684\u987a\u5e8f\u5e94\u8be5\u662f "c", "b", "a". \n\u7531\u4e8e "d" \u6ca1\u6709\u5728S\u4e2d\u51fa\u73b0, \u5b83\u53ef\u4ee5\u653e\u5728T\u7684\u4efb\u610f\u4f4d\u7f6e. "dcba", "cdba", "cbda" \u90fd\u662f\u5408\u6cd5\u7684\u8f93\u51fa\u3002\n
\n\n

\u6ce8\u610f:

\n\n
    \n\t
  • S\u7684\u6700\u5927\u957f\u5ea6\u4e3a26\uff0c\u5176\u4e2d\u6ca1\u6709\u91cd\u590d\u7684\u5b57\u7b26\u3002
  • \n\t
  • T\u7684\u6700\u5927\u957f\u5ea6\u4e3a200\u3002
  • \n\t
  • S\u548cT\u53ea\u5305\u542b\u5c0f\u5199\u5b57\u7b26\u3002
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string customSortString(string order, string str) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String customSortString(String order, String str) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def customSortString(self, order, str):\n \"\"\"\n :type order: str\n :type str: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def customSortString(self, order: str, str: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * customSortString(char * order, char * str){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string CustomSortString(string order, string str) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} order\n * @param {string} str\n * @return {string}\n */\nvar customSortString = function(order, str) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} order\n# @param {String} str\n# @return {String}\ndef custom_sort_string(order, str)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func customSortString(_ order: String, _ str: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func customSortString(order string, str string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def customSortString(order: String, str: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun customSortString(order: String, str: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn custom_sort_string(order: String, str: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $order\n * @param String $str\n * @return String\n */\n function customSortString($order, $str) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function customSortString(order: string, str: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (custom-sort-string order str)\n (-> string? string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0791](https://leetcode-cn.com/problems/custom-sort-string)", "[\u81ea\u5b9a\u4e49\u5b57\u7b26\u4e32\u6392\u5e8f](/solution/0700-0799/0791.Custom%20Sort%20String/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0791](https://leetcode.com/problems/custom-sort-string)", "[Custom Sort String](/solution/0700-0799/0791.Custom%20Sort%20String/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "0806", "frontend_question_id": "0790", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/domino-and-tromino-tiling", "url_en": "https://leetcode.com/problems/domino-and-tromino-tiling", "relative_path_cn": "/solution/0700-0799/0790.Domino%20and%20Tromino%20Tiling/README.md", "relative_path_en": "/solution/0700-0799/0790.Domino%20and%20Tromino%20Tiling/README_EN.md", "title_cn": "\u591a\u7c73\u8bfa\u548c\u6258\u7c73\u8bfa\u5e73\u94fa", "title_en": "Domino and Tromino Tiling", "question_title_slug": "domino-and-tromino-tiling", "content_en": "

We have two types of tiles: a 2x1 domino shape, and an "L" tromino shape. These shapes may be rotated.

\n\n
\nXX  <- domino\n\nXX  <- "L" tromino\nX\n
\n\n

Given n, how many ways are there to tile a 2 x n board? Return your answer modulo 109 + 7.

\n\n

(In a tiling, every square must be covered by a tile. Two tilings are different if and only if there are two 4-directionally adjacent cells on the board such that exactly one of the tilings has both squares occupied by a tile.)

\n\n
\nExample:\nInput: n = 3\nOutput: 5\nExplanation: \nThe five different ways are listed below, different letters indicates different tiles:\nXYZ XXZ XYY XXY XYY\nXYZ YYZ XZZ XYY XXY
\n\n

Note:

\n\n
    \n\t
  • n will be in range [1, 1000].
  • \n
\n\n

 

\n", "content_cn": "

\u6709\u4e24\u79cd\u5f62\u72b6\u7684\u74f7\u7816\uff1a\u4e00\u79cd\u662f 2x1 \u7684\u591a\u7c73\u8bfa\u5f62\uff0c\u53e6\u4e00\u79cd\u662f\u5f62\u5982 "L" \u7684\u6258\u7c73\u8bfa\u5f62\u3002\u4e24\u79cd\u5f62\u72b6\u90fd\u53ef\u4ee5\u65cb\u8f6c\u3002

\n\n
\nXX  <- \u591a\u7c73\u8bfa\n\nXX  <- "L" \u6258\u7c73\u8bfa\nX\n
\n\n

\u7ed9\u5b9a N \u7684\u503c\uff0c\u6709\u591a\u5c11\u79cd\u65b9\u6cd5\u53ef\u4ee5\u5e73\u94fa 2 x N \u7684\u9762\u677f\uff1f\u8fd4\u56de\u503c mod 10^9 + 7\u3002

\n\n

\uff08\u5e73\u94fa\u6307\u7684\u662f\u6bcf\u4e2a\u6b63\u65b9\u5f62\u90fd\u5fc5\u987b\u6709\u74f7\u7816\u8986\u76d6\u3002\u4e24\u4e2a\u5e73\u94fa\u4e0d\u540c\uff0c\u5f53\u4e14\u4ec5\u5f53\u9762\u677f\u4e0a\u6709\u56db\u4e2a\u65b9\u5411\u4e0a\u7684\u76f8\u90bb\u5355\u5143\u4e2d\u7684\u4e24\u4e2a\uff0c\u4f7f\u5f97\u6070\u597d\u6709\u4e00\u4e2a\u5e73\u94fa\u6709\u4e00\u4e2a\u74f7\u7816\u5360\u636e\u4e24\u4e2a\u6b63\u65b9\u5f62\u3002\uff09

\n\n
\n\u793a\u4f8b:\n\u8f93\u5165: 3\n\u8f93\u51fa: 5\n\u89e3\u91ca: \n\u4e0b\u9762\u5217\u51fa\u4e86\u4e94\u79cd\u4e0d\u540c\u7684\u65b9\u6cd5\uff0c\u4e0d\u540c\u5b57\u6bcd\u4ee3\u8868\u4e0d\u540c\u74f7\u7816\uff1a\nXYZ XXZ XYY XXY XYY\nXYZ YYZ XZZ XYY XXY
\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • N  \u7684\u8303\u56f4\u662f [1, 1000]
  • \n
\n\n

 

\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numTilings(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numTilings(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numTilings(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numTilings(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numTilings(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumTilings(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar numTilings = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef num_tilings(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numTilings(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numTilings(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numTilings(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numTilings(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_tilings(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function numTilings($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numTilings(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-tilings n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0790](https://leetcode-cn.com/problems/domino-and-tromino-tiling)", "[\u591a\u7c73\u8bfa\u548c\u6258\u7c73\u8bfa\u5e73\u94fa](/solution/0700-0799/0790.Domino%20and%20Tromino%20Tiling/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0790](https://leetcode.com/problems/domino-and-tromino-tiling)", "[Domino and Tromino Tiling](/solution/0700-0799/0790.Domino%20and%20Tromino%20Tiling/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0805", "frontend_question_id": "0789", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/escape-the-ghosts", "url_en": "https://leetcode.com/problems/escape-the-ghosts", "relative_path_cn": "/solution/0700-0799/0789.Escape%20The%20Ghosts/README.md", "relative_path_en": "/solution/0700-0799/0789.Escape%20The%20Ghosts/README_EN.md", "title_cn": "\u9003\u8131\u963b\u788d\u8005", "title_en": "Escape The Ghosts", "question_title_slug": "escape-the-ghosts", "content_en": "

You are playing a simplified PAC-MAN game on an infinite 2-D grid. You start at the point [0, 0], and you are given a destination point target = [xtarget, ytarget], which you are trying to get to. There are several ghosts on the map with their starting positions given as an array ghosts, where ghosts[i] = [xi, yi] represents the starting position of the ith ghost. All inputs are integral coordinates.

\n\n

Each turn, you and all the ghosts may independently choose to either move 1 unit in any of the four cardinal directions: north, east, south, or west or stay still. All actions happen simultaneously.

\n\n

You escape if and only if you can reach the target before any ghost reaches you. If you reach any square (including the target) at the same time as a ghost, it does not count as an escape.

\n\n

Return true if it is possible to escape, otherwise return false.

\n\n

 

\n

Example 1:

\n\n
\nInput: ghosts = [[1,0],[0,3]], target = [0,1]\nOutput: true\nExplanation: You can reach the destination (0, 1) after 1 turn, while the ghosts located at (1, 0) and (0, 3) cannot catch up with you.\n
\n\n

Example 2:

\n\n
\nInput: ghosts = [[1,0]], target = [2,0]\nOutput: false\nExplanation: You need to reach the destination (2, 0), but the ghost at (1, 0) lies between you and the destination.\n
\n\n

Example 3:

\n\n
\nInput: ghosts = [[2,0]], target = [1,0]\nOutput: false\nExplanation: The ghost can reach the target at the same time as you.\n
\n\n

Example 4:

\n\n
\nInput: ghosts = [[5,0],[-10,-2],[0,-5],[-2,-2],[-7,1]], target = [7,7]\nOutput: false\n
\n\n

Example 5:

\n\n
\nInput: ghosts = [[-1,0],[0,1],[-1,0],[0,1],[-1,0]], target = [0,0]\nOutput: true\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= ghosts.length <= 100
  • \n\t
  • ghosts[i].length == 2
  • \n\t
  • -104 <= xi, yi <= 104
  • \n\t
  • There can be multiple ghosts in the same location.
  • \n\t
  • target.length == 2
  • \n\t
  • -104 <= xtarget, ytarget <= 104
  • \n
\n", "content_cn": "

\u4f60\u5728\u8fdb\u884c\u4e00\u4e2a\u7b80\u5316\u7248\u7684\u5403\u8c46\u4eba\u6e38\u620f\u3002\u4f60\u4ece [0, 0] \u70b9\u5f00\u59cb\u51fa\u53d1\uff0c\u4f60\u7684\u76ee\u7684\u5730\u662f\u00a0target = [xtarget, ytarget] \u3002\u5730\u56fe\u4e0a\u6709\u4e00\u4e9b\u963b\u788d\u8005\uff0c\u4ee5\u6570\u7ec4 ghosts \u7ed9\u51fa\uff0c\u7b2c i \u4e2a\u963b\u788d\u8005\u4ece\u00a0ghosts[i] = [xi, yi]\u00a0\u51fa\u53d1\u3002\u6240\u6709\u8f93\u5165\u5747\u4e3a \u6574\u6570\u5750\u6807 \u3002

\n\n

\u6bcf\u4e00\u56de\u5408\uff0c\u4f60\u548c\u963b\u788d\u8005\u4eec\u53ef\u4ee5\u540c\u65f6\u5411\u4e1c\uff0c\u897f\uff0c\u5357\uff0c\u5317\u56db\u4e2a\u65b9\u5411\u79fb\u52a8\uff0c\u6bcf\u6b21\u53ef\u4ee5\u79fb\u52a8\u5230\u8ddd\u79bb\u539f\u4f4d\u7f6e 1 \u4e2a\u5355\u4f4d \u7684\u65b0\u4f4d\u7f6e\u3002\u5f53\u7136\uff0c\u4e5f\u53ef\u4ee5\u9009\u62e9 \u4e0d\u52a8 \u3002\u6240\u6709\u52a8\u4f5c \u540c\u65f6 \u53d1\u751f\u3002

\n\n

\u5982\u679c\u4f60\u53ef\u4ee5\u5728\u4efb\u4f55\u963b\u788d\u8005\u6293\u4f4f\u4f60 \u4e4b\u524d \u5230\u8fbe\u76ee\u7684\u5730\uff08\u963b\u788d\u8005\u53ef\u4ee5\u91c7\u53d6\u4efb\u610f\u884c\u52a8\u65b9\u5f0f\uff09\uff0c\u5219\u88ab\u89c6\u4e3a\u9003\u8131\u6210\u529f\u3002\u5982\u679c\u4f60\u548c\u963b\u788d\u8005\u540c\u65f6\u5230\u8fbe\u4e86\u4e00\u4e2a\u4f4d\u7f6e\uff08\u5305\u62ec\u76ee\u7684\u5730\uff09\u90fd\u4e0d\u7b97\u662f\u9003\u8131\u6210\u529f\u3002

\n\n

\u53ea\u6709\u5728\u4f60\u6709\u53ef\u80fd\u6210\u529f\u9003\u8131\u65f6\uff0c\u8f93\u51fa true \uff1b\u5426\u5219\uff0c\u8f93\u51fa false \u3002

\n\u00a0\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aghosts = [[1,0],[0,3]], target = [0,1]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u76f4\u63a5\u4e00\u6b65\u5230\u8fbe\u76ee\u7684\u5730 (0,1) \uff0c\u5728 (1, 0) \u6216\u8005 (0, 3) \u4f4d\u7f6e\u7684\u963b\u788d\u8005\u90fd\u4e0d\u53ef\u80fd\u6293\u4f4f\u4f60\u3002 \n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aghosts = [[1,0]], target = [2,0]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u4f60\u9700\u8981\u8d70\u5230\u4f4d\u4e8e (2, 0) \u7684\u76ee\u7684\u5730\uff0c\u4f46\u662f\u5728 (1, 0) \u7684\u963b\u788d\u8005\u4f4d\u4e8e\u4f60\u548c\u76ee\u7684\u5730\u4e4b\u95f4\u3002 \n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1aghosts = [[2,0]], target = [1,0]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u963b\u788d\u8005\u53ef\u4ee5\u548c\u4f60\u540c\u65f6\u8fbe\u5230\u76ee\u7684\u5730\u3002 \n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1aghosts = [[5,0],[-10,-2],[0,-5],[-2,-2],[-7,1]], target = [7,7]\n\u8f93\u51fa\uff1afalse\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\n\u8f93\u5165\uff1aghosts = [[-1,0],[0,1],[-1,0],[0,1],[-1,0]], target = [0,0]\n\u8f93\u51fa\uff1atrue\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= ghosts.length <= 100
  • \n\t
  • ghosts[i].length == 2
  • \n\t
  • -104 <= xi, yi <= 104
  • \n\t
  • \u540c\u4e00\u4f4d\u7f6e\u53ef\u80fd\u6709 \u591a\u4e2a\u963b\u788d\u8005 \u3002
  • \n\t
  • target.length == 2
  • \n\t
  • -104 <= xtarget, ytarget <= 104
  • \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool escapeGhosts(vector>& ghosts, vector& target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean escapeGhosts(int[][] ghosts, int[] target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def escapeGhosts(self, ghosts, target):\n \"\"\"\n :type ghosts: List[List[int]]\n :type target: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def escapeGhosts(self, ghosts: List[List[int]], target: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool escapeGhosts(int** ghosts, int ghostsSize, int* ghostsColSize, int* target, int targetSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool EscapeGhosts(int[][] ghosts, int[] target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} ghosts\n * @param {number[]} target\n * @return {boolean}\n */\nvar escapeGhosts = function(ghosts, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} ghosts\n# @param {Integer[]} target\n# @return {Boolean}\ndef escape_ghosts(ghosts, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func escapeGhosts(_ ghosts: [[Int]], _ target: [Int]) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func escapeGhosts(ghosts [][]int, target []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def escapeGhosts(ghosts: Array[Array[Int]], target: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun escapeGhosts(ghosts: Array, target: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn escape_ghosts(ghosts: Vec>, target: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $ghosts\n * @param Integer[] $target\n * @return Boolean\n */\n function escapeGhosts($ghosts, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function escapeGhosts(ghosts: number[][], target: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (escape-ghosts ghosts target)\n (-> (listof (listof exact-integer?)) (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0789](https://leetcode-cn.com/problems/escape-the-ghosts)", "[\u9003\u8131\u963b\u788d\u8005](/solution/0700-0799/0789.Escape%20The%20Ghosts/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0789](https://leetcode.com/problems/escape-the-ghosts)", "[Escape The Ghosts](/solution/0700-0799/0789.Escape%20The%20Ghosts/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "0804", "frontend_question_id": "0788", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/rotated-digits", "url_en": "https://leetcode.com/problems/rotated-digits", "relative_path_cn": "/solution/0700-0799/0788.Rotated%20Digits/README.md", "relative_path_en": "/solution/0700-0799/0788.Rotated%20Digits/README_EN.md", "title_cn": "\u65cb\u8f6c\u6570\u5b57", "title_en": "Rotated Digits", "question_title_slug": "rotated-digits", "content_en": "

x is a good number if after rotating each digit individually by 180 degrees, we get a valid number that is different from x. Each digit must be rotated - we cannot choose to leave it alone.

\n\n

A number is valid if each digit remains a digit after rotation. 0, 1, and 8 rotate to themselves; 2 and 5 rotate to each other (on this case they are rotated in a different direction, in other words 2 or 5 gets mirrored); 6 and 9 rotate to each other, and the rest of the numbers do not rotate to any other number and become invalid.

\n\n

Now given a positive number n, how many numbers x from 1 to n are good?

\n\n
\nExample:\nInput: 10\nOutput: 4\nExplanation: \nThere are four good numbers in the range [1, 10] : 2, 5, 6, 9.\nNote that 1 and 10 are not good numbers, since they remain unchanged after rotating.\n
\n\n

Note:

\n\n
    \n\t
  • n will be in range [1, 10000].
  • \n
\n", "content_cn": "

\u6211\u4eec\u79f0\u4e00\u4e2a\u6570 X \u4e3a\u597d\u6570, \u5982\u679c\u5b83\u7684\u6bcf\u4f4d\u6570\u5b57\u9010\u4e2a\u5730\u88ab\u65cb\u8f6c 180 \u5ea6\u540e\uff0c\u6211\u4eec\u4ecd\u53ef\u4ee5\u5f97\u5230\u4e00\u4e2a\u6709\u6548\u7684\uff0c\u4e14\u548c X \u4e0d\u540c\u7684\u6570\u3002\u8981\u6c42\u6bcf\u4f4d\u6570\u5b57\u90fd\u8981\u88ab\u65cb\u8f6c\u3002

\n\n

\u5982\u679c\u4e00\u4e2a\u6570\u7684\u6bcf\u4f4d\u6570\u5b57\u88ab\u65cb\u8f6c\u4ee5\u540e\u4ecd\u7136\u8fd8\u662f\u4e00\u4e2a\u6570\u5b57\uff0c \u5219\u8fd9\u4e2a\u6570\u662f\u6709\u6548\u7684\u30020, 1, \u548c 8 \u88ab\u65cb\u8f6c\u540e\u4ecd\u7136\u662f\u5b83\u4eec\u81ea\u5df1\uff1b2 \u548c 5 \u53ef\u4ee5\u4e92\u76f8\u65cb\u8f6c\u6210\u5bf9\u65b9\uff08\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u5b83\u4eec\u4ee5\u4e0d\u540c\u7684\u65b9\u5411\u65cb\u8f6c\uff0c\u6362\u53e5\u8bdd\u8bf4\uff0c2 \u548c 5 \u4e92\u4e3a\u955c\u50cf\uff09\uff1b6 \u548c 9 \u540c\u7406\uff0c\u9664\u4e86\u8fd9\u4e9b\u4ee5\u5916\u5176\u4ed6\u7684\u6570\u5b57\u65cb\u8f6c\u4ee5\u540e\u90fd\u4e0d\u518d\u662f\u6709\u6548\u7684\u6570\u5b57\u3002

\n\n

\u73b0\u5728\u6211\u4eec\u6709\u4e00\u4e2a\u6b63\u6574\u6570 N, \u8ba1\u7b97\u4ece 1 \u5230 N \u4e2d\u6709\u591a\u5c11\u4e2a\u6570 X \u662f\u597d\u6570\uff1f

\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165: 10\n\u8f93\u51fa: 4\n\u89e3\u91ca: \n\u5728[1, 10]\u4e2d\u6709\u56db\u4e2a\u597d\u6570\uff1a 2, 5, 6, 9\u3002\n\u6ce8\u610f 1 \u548c 10 \u4e0d\u662f\u597d\u6570, \u56e0\u4e3a\u4ed6\u4eec\u5728\u65cb\u8f6c\u4e4b\u540e\u4e0d\u53d8\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • N \u7684\u53d6\u503c\u8303\u56f4\u662f [1, 10000]\u3002
  • \n
\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int rotatedDigits(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int rotatedDigits(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def rotatedDigits(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def rotatedDigits(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint rotatedDigits(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int RotatedDigits(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar rotatedDigits = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef rotated_digits(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func rotatedDigits(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func rotatedDigits(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def rotatedDigits(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun rotatedDigits(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn rotated_digits(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function rotatedDigits($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function rotatedDigits(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (rotated-digits n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0788](https://leetcode-cn.com/problems/rotated-digits)", "[\u65cb\u8f6c\u6570\u5b57](/solution/0700-0799/0788.Rotated%20Digits/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0788](https://leetcode.com/problems/rotated-digits)", "[Rotated Digits](/solution/0700-0799/0788.Rotated%20Digits/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "0803", "frontend_question_id": "0787", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/cheapest-flights-within-k-stops", "url_en": "https://leetcode.com/problems/cheapest-flights-within-k-stops", "relative_path_cn": "/solution/0700-0799/0787.Cheapest%20Flights%20Within%20K%20Stops/README.md", "relative_path_en": "/solution/0700-0799/0787.Cheapest%20Flights%20Within%20K%20Stops/README_EN.md", "title_cn": "K \u7ad9\u4e2d\u8f6c\u5185\u6700\u4fbf\u5b9c\u7684\u822a\u73ed", "title_en": "Cheapest Flights Within K Stops", "question_title_slug": "cheapest-flights-within-k-stops", "content_en": "

There are n cities connected by some number of flights. You are given an array flights where flights[i] = [fromi, toi, pricei] indicates that there is a flight from city fromi to city toi with cost pricei.

\n\n

You are also given three integers src, dst, and k, return the cheapest price from src to dst with at most k stops. If there is no such route, return -1.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: n = 3, flights = [[0,1,100],[1,2,100],[0,2,500]], src = 0, dst = 2, k = 1\nOutput: 200\nExplanation: The graph is shown.\nThe cheapest price from city 0 to city 2 with at most 1 stop costs 200, as marked red in the picture.\n
\n\n

Example 2:

\n\"\"\n
\nInput: n = 3, flights = [[0,1,100],[1,2,100],[0,2,500]], src = 0, dst = 2, k = 0\nOutput: 500\nExplanation: The graph is shown.\nThe cheapest price from city 0 to city 2 with at most 0 stop costs 500, as marked blue in the picture.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 100
  • \n\t
  • 0 <= flights.length <= (n * (n - 1) / 2)
  • \n\t
  • flights[i].length == 3
  • \n\t
  • 0 <= fromi, toi < n
  • \n\t
  • fromi != toi
  • \n\t
  • 1 <= pricei <= 104
  • \n\t
  • There will not be any multiple flights between two cities.
  • \n\t
  • 0 <= src, dst, k < n
  • \n\t
  • src != dst
  • \n
\n", "content_cn": "

\u6709 n \u4e2a\u57ce\u5e02\u901a\u8fc7 m \u4e2a\u822a\u73ed\u8fde\u63a5\u3002\u6bcf\u4e2a\u822a\u73ed\u90fd\u4ece\u57ce\u5e02 u \u5f00\u59cb\uff0c\u4ee5\u4ef7\u683c w \u62b5\u8fbe v\u3002

\n\n

\u73b0\u5728\u7ed9\u5b9a\u6240\u6709\u7684\u57ce\u5e02\u548c\u822a\u73ed\uff0c\u4ee5\u53ca\u51fa\u53d1\u57ce\u5e02 src \u548c\u76ee\u7684\u5730 dst\uff0c\u4f60\u7684\u4efb\u52a1\u662f\u627e\u5230\u4ece src \u5230 dst \u6700\u591a\u7ecf\u8fc7 k\u00a0\u7ad9\u4e2d\u8f6c\u7684\u6700\u4fbf\u5b9c\u7684\u4ef7\u683c\u3002 \u5982\u679c\u6ca1\u6709\u8fd9\u6837\u7684\u8def\u7ebf\uff0c\u5219\u8f93\u51fa -1\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165: \nn = 3, edges = [[0,1,100],[1,2,100],[0,2,500]]\nsrc = 0, dst = 2, k = 1\n\u8f93\u51fa: 200\n\u89e3\u91ca: \n\u57ce\u5e02\u822a\u73ed\u56fe\u5982\u4e0b\n\"\"\n\n\u4ece\u57ce\u5e02 0 \u5230\u57ce\u5e02 2 \u5728 1 \u7ad9\u4e2d\u8f6c\u4ee5\u5185\u7684\u6700\u4fbf\u5b9c\u4ef7\u683c\u662f 200\uff0c\u5982\u56fe\u4e2d\u7ea2\u8272\u6240\u793a\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165: \nn = 3, edges = [[0,1,100],[1,2,100],[0,2,500]]\nsrc = 0, dst = 2, k = 0\n\u8f93\u51fa: 500\n\u89e3\u91ca: \n\u57ce\u5e02\u822a\u73ed\u56fe\u5982\u4e0b\n\"\"\n\n\u4ece\u57ce\u5e02 0 \u5230\u57ce\u5e02 2 \u5728 0 \u7ad9\u4e2d\u8f6c\u4ee5\u5185\u7684\u6700\u4fbf\u5b9c\u4ef7\u683c\u662f 500\uff0c\u5982\u56fe\u4e2d\u84dd\u8272\u6240\u793a\u3002
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • n \u8303\u56f4\u662f [1, 100]\uff0c\u57ce\u5e02\u6807\u7b7e\u4ece 0 \u5230 n - 1
  • \n\t
  • \u822a\u73ed\u6570\u91cf\u8303\u56f4\u662f [0, n * (n - 1) / 2]
  • \n\t
  • \u6bcf\u4e2a\u822a\u73ed\u7684\u683c\u5f0f (src, dst, price)
  • \n\t
  • \u6bcf\u4e2a\u822a\u73ed\u7684\u4ef7\u683c\u8303\u56f4\u662f [1, 10000]
  • \n\t
  • k \u8303\u56f4\u662f [0, n - 1]
  • \n\t
  • \u822a\u73ed\u6ca1\u6709\u91cd\u590d\uff0c\u4e14\u4e0d\u5b58\u5728\u81ea\u73af
  • \n
\n", "tags_en": ["Heap", "Breadth-first Search", "Dynamic Programming"], "tags_cn": ["\u5806", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findCheapestPrice(int n, vector>& flights, int src, int dst, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findCheapestPrice(int n, int[][] flights, int src, int dst, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findCheapestPrice(self, n, flights, src, dst, k):\n \"\"\"\n :type n: int\n :type flights: List[List[int]]\n :type src: int\n :type dst: int\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findCheapestPrice(self, n: int, flights: List[List[int]], src: int, dst: int, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findCheapestPrice(int n, int** flights, int flightsSize, int* flightsColSize, int src, int dst, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindCheapestPrice(int n, int[][] flights, int src, int dst, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} flights\n * @param {number} src\n * @param {number} dst\n * @param {number} k\n * @return {number}\n */\nvar findCheapestPrice = function(n, flights, src, dst, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} flights\n# @param {Integer} src\n# @param {Integer} dst\n# @param {Integer} k\n# @return {Integer}\ndef find_cheapest_price(n, flights, src, dst, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findCheapestPrice(_ n: Int, _ flights: [[Int]], _ src: Int, _ dst: Int, _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findCheapestPrice(n int, flights [][]int, src int, dst int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findCheapestPrice(n: Int, flights: Array[Array[Int]], src: Int, dst: Int, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findCheapestPrice(n: Int, flights: Array, src: Int, dst: Int, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_cheapest_price(n: i32, flights: Vec>, src: i32, dst: i32, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $flights\n * @param Integer $src\n * @param Integer $dst\n * @param Integer $k\n * @return Integer\n */\n function findCheapestPrice($n, $flights, $src, $dst, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findCheapestPrice(n: number, flights: number[][], src: number, dst: number, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-cheapest-price n flights src dst k)\n (-> exact-integer? (listof (listof exact-integer?)) exact-integer? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0787](https://leetcode-cn.com/problems/cheapest-flights-within-k-stops)", "[K \u7ad9\u4e2d\u8f6c\u5185\u6700\u4fbf\u5b9c\u7684\u822a\u73ed](/solution/0700-0799/0787.Cheapest%20Flights%20Within%20K%20Stops/README.md)", "`\u5806`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0787](https://leetcode.com/problems/cheapest-flights-within-k-stops)", "[Cheapest Flights Within K Stops](/solution/0700-0799/0787.Cheapest%20Flights%20Within%20K%20Stops/README_EN.md)", "`Heap`,`Breadth-first Search`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0802", "frontend_question_id": "0786", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/k-th-smallest-prime-fraction", "url_en": "https://leetcode.com/problems/k-th-smallest-prime-fraction", "relative_path_cn": "/solution/0700-0799/0786.K-th%20Smallest%20Prime%20Fraction/README.md", "relative_path_en": "/solution/0700-0799/0786.K-th%20Smallest%20Prime%20Fraction/README_EN.md", "title_cn": "\u7b2c K \u4e2a\u6700\u5c0f\u7684\u7d20\u6570\u5206\u6570", "title_en": "K-th Smallest Prime Fraction", "question_title_slug": "k-th-smallest-prime-fraction", "content_en": "

You are given a sorted integer array arr containing 1 and prime numbers, where all the integers of arr are unique. You are also given an integer k.

\n\n

For every i and j where 0 <= i < j < arr.length, we consider the fraction arr[i] / arr[j].

\n\n

Return the kth smallest fraction considered. Return your answer as an array of integers of size 2, where answer[0] == arr[i] and answer[1] == arr[j].

\n\n

 

\n

Example 1:

\n\n
\nInput: arr = [1,2,3,5], k = 3\nOutput: [2,5]\nExplanation: The fractions to be considered in sorted order are:\n1/5, 1/3, 2/5, 1/2, 3/5, and 2/3.\nThe third fraction is 2/5.\n
\n\n

Example 2:

\n\n
\nInput: arr = [1,7], k = 1\nOutput: [1,7]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= arr.length <= 1000
  • \n\t
  • 1 <= arr[i] <= 3 * 104
  • \n\t
  • arr[0] == 1
  • \n\t
  • arr[i] is a prime number for i > 0.
  • \n\t
  • All the numbers of arr are unique and sorted in strictly increasing order.
  • \n\t
  • 1 <= k <= arr.length * (arr.length - 1) / 2
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u6309\u9012\u589e\u987a\u5e8f\u6392\u5e8f\u7684\u6570\u7ec4 arr \u548c\u4e00\u4e2a\u6574\u6570 k \u3002\u6570\u7ec4 arr \u7531 1 \u548c\u82e5\u5e72 \u7d20\u6570\u00a0 \u7ec4\u6210\uff0c\u4e14\u5176\u4e2d\u6240\u6709\u6574\u6570\u4e92\u4e0d\u76f8\u540c\u3002

\n\n

\u5bf9\u4e8e\u6bcf\u5bf9\u6ee1\u8db3 0 < i < j < arr.length \u7684 i \u548c j \uff0c\u53ef\u4ee5\u5f97\u5230\u5206\u6570 arr[i] / arr[j] \u3002

\n\n

\u90a3\u4e48\u7b2c\u00a0k\u00a0\u4e2a\u6700\u5c0f\u7684\u5206\u6570\u662f\u591a\u5c11\u5462?\u00a0 \u4ee5\u957f\u5ea6\u4e3a 2 \u7684\u6574\u6570\u6570\u7ec4\u8fd4\u56de\u4f60\u7684\u7b54\u6848, \u8fd9\u91cc\u00a0answer[0] == arr[i]\u00a0\u4e14\u00a0answer[1] == arr[j] \u3002

\n\u00a0\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [1,2,3,5], k = 3\n\u8f93\u51fa\uff1a[2,5]\n\u89e3\u91ca\uff1a\u5df2\u6784\u9020\u597d\u7684\u5206\u6570,\u6392\u5e8f\u540e\u5982\u4e0b\u6240\u793a: \n1/5, 1/3, 2/5, 1/2, 3/5, 2/3\n\u5f88\u660e\u663e\u7b2c\u4e09\u4e2a\u6700\u5c0f\u7684\u5206\u6570\u662f 2/5\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aarr = [1,7], k = 1\n\u8f93\u51fa\uff1a[1,7]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 2 <= arr.length <= 1000
  • \n\t
  • 1 <= arr[i] <= 3 * 104
  • \n\t
  • arr[0] == 1
  • \n\t
  • arr[i] \u662f\u4e00\u4e2a \u7d20\u6570 \uff0ci > 0
  • \n\t
  • arr \u4e2d\u7684\u6240\u6709\u6570\u5b57 \u4e92\u4e0d\u76f8\u540c \uff0c\u4e14\u6309 \u4e25\u683c\u9012\u589e \u6392\u5e8f
  • \n\t
  • 1 <= k <= arr.length * (arr.length - 1) / 2
  • \n
\n", "tags_en": ["Heap", "Binary Search"], "tags_cn": ["\u5806", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector kthSmallestPrimeFraction(vector& arr, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] kthSmallestPrimeFraction(int[] arr, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def kthSmallestPrimeFraction(self, arr, k):\n \"\"\"\n :type arr: List[int]\n :type k: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def kthSmallestPrimeFraction(self, arr: List[int], k: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* kthSmallestPrimeFraction(int* arr, int arrSize, int k, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] KthSmallestPrimeFraction(int[] arr, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @param {number} k\n * @return {number[]}\n */\nvar kthSmallestPrimeFraction = function(arr, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @param {Integer} k\n# @return {Integer[]}\ndef kth_smallest_prime_fraction(arr, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func kthSmallestPrimeFraction(_ arr: [Int], _ k: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func kthSmallestPrimeFraction(arr []int, k int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def kthSmallestPrimeFraction(arr: Array[Int], k: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun kthSmallestPrimeFraction(arr: IntArray, k: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn kth_smallest_prime_fraction(arr: Vec, k: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @param Integer $k\n * @return Integer[]\n */\n function kthSmallestPrimeFraction($arr, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function kthSmallestPrimeFraction(arr: number[], k: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (kth-smallest-prime-fraction arr k)\n (-> (listof exact-integer?) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0786](https://leetcode-cn.com/problems/k-th-smallest-prime-fraction)", "[\u7b2c K \u4e2a\u6700\u5c0f\u7684\u7d20\u6570\u5206\u6570](/solution/0700-0799/0786.K-th%20Smallest%20Prime%20Fraction/README.md)", "`\u5806`,`\u4e8c\u5206\u67e5\u627e`", "\u56f0\u96be", ""], "md_table_row_en": ["[0786](https://leetcode.com/problems/k-th-smallest-prime-fraction)", "[K-th Smallest Prime Fraction](/solution/0700-0799/0786.K-th%20Smallest%20Prime%20Fraction/README_EN.md)", "`Heap`,`Binary Search`", "Hard", ""]}, {"question_id": "0801", "frontend_question_id": "0785", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/is-graph-bipartite", "url_en": "https://leetcode.com/problems/is-graph-bipartite", "relative_path_cn": "/solution/0700-0799/0785.Is%20Graph%20Bipartite/README.md", "relative_path_en": "/solution/0700-0799/0785.Is%20Graph%20Bipartite/README_EN.md", "title_cn": "\u5224\u65ad\u4e8c\u5206\u56fe", "title_en": "Is Graph Bipartite", "question_title_slug": "is-graph-bipartite", "content_en": "

There is an undirected graph with n nodes, where each node is numbered between 0 and n - 1. You are given a 2D array graph, where graph[u] is an array of nodes that node u is adjacent to. More formally, for each v in graph[u], there is an undirected edge between node u and node v. The graph has the following properties:

\n\n
    \n\t
  • There are no self-edges (graph[u] does not contain u).
  • \n\t
  • There are no parallel edges (graph[u] does not contain duplicate values).
  • \n\t
  • If v is in graph[u], then u is in graph[v] (the graph is undirected).
  • \n\t
  • The graph may not be connected, meaning there may be two nodes u and v such that there is no path between them.
  • \n
\n\n

A graph is bipartite if the nodes can be partitioned into two independent sets A and B such that every edge in the graph connects a node in set A and a node in set B.

\n\n

Return true if and only if it is bipartite.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: graph = [[1,2,3],[0,2],[0,1,3],[0,2]]\nOutput: false\nExplanation: There is no way to partition the nodes into two independent sets such that every edge connects a node in one and a node in the other.
\n\n

Example 2:

\n\"\"\n
\nInput: graph = [[1,3],[0,2],[1,3],[0,2]]\nOutput: true\nExplanation: We can partition the nodes into two sets: {0, 2} and {1, 3}.
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • graph.length == n
  • \n\t
  • 1 <= n <= 100
  • \n\t
  • 0 <= graph[u].length < n
  • \n\t
  • 0 <= graph[u][i] <= n - 1
  • \n\t
  • graph[u] does not contain u.
  • \n\t
  • All the values of graph[u] are unique.
  • \n\t
  • If graph[u] contains v, then graph[v] contains u.
  • \n
\n", "content_cn": "\u5b58\u5728\u4e00\u4e2a \u65e0\u5411\u56fe \uff0c\u56fe\u4e2d\u6709 n \u4e2a\u8282\u70b9\u3002\u5176\u4e2d\u6bcf\u4e2a\u8282\u70b9\u90fd\u6709\u4e00\u4e2a\u4ecb\u4e8e 0 \u5230 n - 1 \u4e4b\u95f4\u7684\u552f\u4e00\u7f16\u53f7\u3002\u7ed9\u4f60\u4e00\u4e2a\u4e8c\u7ef4\u6570\u7ec4 graph \uff0c\u5176\u4e2d graph[u] \u662f\u4e00\u4e2a\u8282\u70b9\u6570\u7ec4\uff0c\u7531\u8282\u70b9 u \u7684\u90bb\u63a5\u8282\u70b9\u7ec4\u6210\u3002\u5f62\u5f0f\u4e0a\uff0c\u5bf9\u4e8e\u00a0graph[u] \u4e2d\u7684\u6bcf\u4e2a v \uff0c\u90fd\u5b58\u5728\u4e00\u6761\u4f4d\u4e8e\u8282\u70b9 u \u548c\u8282\u70b9 v \u4e4b\u95f4\u7684\u65e0\u5411\u8fb9\u3002\u8be5\u65e0\u5411\u56fe\u540c\u65f6\u5177\u6709\u4ee5\u4e0b\u5c5e\u6027\uff1a\n
    \n\t
  • \u4e0d\u5b58\u5728\u81ea\u73af\uff08graph[u] \u4e0d\u5305\u542b u\uff09\u3002
  • \n\t
  • \u4e0d\u5b58\u5728\u5e73\u884c\u8fb9\uff08graph[u] \u4e0d\u5305\u542b\u91cd\u590d\u503c\uff09\u3002
  • \n\t
  • \u5982\u679c v \u5728 graph[u] \u5185\uff0c\u90a3\u4e48 u \u4e5f\u5e94\u8be5\u5728 graph[v] \u5185\uff08\u8be5\u56fe\u662f\u65e0\u5411\u56fe\uff09
  • \n\t
  • \u8fd9\u4e2a\u56fe\u53ef\u80fd\u4e0d\u662f\u8fde\u901a\u56fe\uff0c\u4e5f\u5c31\u662f\u8bf4\u4e24\u4e2a\u8282\u70b9 u \u548c v \u4e4b\u95f4\u53ef\u80fd\u4e0d\u5b58\u5728\u4e00\u6761\u8fde\u901a\u5f7c\u6b64\u7684\u8def\u5f84\u3002
  • \n
\n\n

\u4e8c\u5206\u56fe \u5b9a\u4e49\uff1a\u5982\u679c\u80fd\u5c06\u4e00\u4e2a\u56fe\u7684\u8282\u70b9\u96c6\u5408\u5206\u5272\u6210\u4e24\u4e2a\u72ec\u7acb\u7684\u5b50\u96c6 A \u548c B \uff0c\u5e76\u4f7f\u56fe\u4e2d\u7684\u6bcf\u4e00\u6761\u8fb9\u7684\u4e24\u4e2a\u8282\u70b9\u4e00\u4e2a\u6765\u81ea A \u96c6\u5408\uff0c\u4e00\u4e2a\u6765\u81ea B \u96c6\u5408\uff0c\u5c31\u5c06\u8fd9\u4e2a\u56fe\u79f0\u4e3a \u4e8c\u5206\u56fe \u3002

\n\n

\u5982\u679c\u56fe\u662f\u4e8c\u5206\u56fe\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1agraph = [[1,2,3],[0,2],[0,1,3],[0,2]]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u4e0d\u80fd\u5c06\u8282\u70b9\u5206\u5272\u6210\u4e24\u4e2a\u72ec\u7acb\u7684\u5b50\u96c6\uff0c\u4ee5\u4f7f\u6bcf\u6761\u8fb9\u90fd\u8fde\u901a\u4e00\u4e2a\u5b50\u96c6\u4e2d\u7684\u4e00\u4e2a\u8282\u70b9\u4e0e\u53e6\u4e00\u4e2a\u5b50\u96c6\u4e2d\u7684\u4e00\u4e2a\u8282\u70b9\u3002
\n\n

\u793a\u4f8b 2\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1agraph = [[1,3],[0,2],[1,3],[0,2]]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u53ef\u4ee5\u5c06\u8282\u70b9\u5206\u6210\u4e24\u7ec4: {0, 2} \u548c {1, 3} \u3002
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • graph.length == n
  • \n\t
  • 1 <= n <= 100
  • \n\t
  • 0 <= graph[u].length < n
  • \n\t
  • 0 <= graph[u][i] <= n - 1
  • \n\t
  • graph[u] \u4e0d\u4f1a\u5305\u542b u
  • \n\t
  • graph[u] \u7684\u6240\u6709\u503c \u4e92\u4e0d\u76f8\u540c
  • \n\t
  • \u5982\u679c graph[u] \u5305\u542b v\uff0c\u90a3\u4e48 graph[v] \u4e5f\u4f1a\u5305\u542b u
  • \n
\n", "tags_en": ["Depth-first Search", "Breadth-first Search", "Graph"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isBipartite(vector>& graph) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isBipartite(int[][] graph) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isBipartite(self, graph):\n \"\"\"\n :type graph: List[List[int]]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isBipartite(self, graph: List[List[int]]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isBipartite(int** graph, int graphSize, int* graphColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsBipartite(int[][] graph) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} graph\n * @return {boolean}\n */\nvar isBipartite = function(graph) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} graph\n# @return {Boolean}\ndef is_bipartite(graph)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isBipartite(_ graph: [[Int]]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isBipartite(graph [][]int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isBipartite(graph: Array[Array[Int]]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isBipartite(graph: Array): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_bipartite(graph: Vec>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $graph\n * @return Boolean\n */\n function isBipartite($graph) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isBipartite(graph: number[][]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-bipartite graph)\n (-> (listof (listof exact-integer?)) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0785](https://leetcode-cn.com/problems/is-graph-bipartite)", "[\u5224\u65ad\u4e8c\u5206\u56fe](/solution/0700-0799/0785.Is%20Graph%20Bipartite/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u56fe`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0785](https://leetcode.com/problems/is-graph-bipartite)", "[Is Graph Bipartite](/solution/0700-0799/0785.Is%20Graph%20Bipartite/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`,`Graph`", "Medium", ""]}, {"question_id": "0800", "frontend_question_id": "0784", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/letter-case-permutation", "url_en": "https://leetcode.com/problems/letter-case-permutation", "relative_path_cn": "/solution/0700-0799/0784.Letter%20Case%20Permutation/README.md", "relative_path_en": "/solution/0700-0799/0784.Letter%20Case%20Permutation/README_EN.md", "title_cn": "\u5b57\u6bcd\u5927\u5c0f\u5199\u5168\u6392\u5217", "title_en": "Letter Case Permutation", "question_title_slug": "letter-case-permutation", "content_en": "

Given a string s, we can transform every letter individually to be lowercase or uppercase to create another string.

\n\n

Return a list of all possible strings we could create. You can return the output in any order.

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "a1b2"\nOutput: ["a1b2","a1B2","A1b2","A1B2"]\n
\n\n

Example 2:

\n\n
\nInput: s = "3z4"\nOutput: ["3z4","3Z4"]\n
\n\n

Example 3:

\n\n
\nInput: s = "12345"\nOutput: ["12345"]\n
\n\n

Example 4:

\n\n
\nInput: s = "0"\nOutput: ["0"]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • s will be a string with length between 1 and 12.
  • \n\t
  • s will consist only of letters or digits.
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32S\uff0c\u901a\u8fc7\u5c06\u5b57\u7b26\u4e32S\u4e2d\u7684\u6bcf\u4e2a\u5b57\u6bcd\u8f6c\u53d8\u5927\u5c0f\u5199\uff0c\u6211\u4eec\u53ef\u4ee5\u83b7\u5f97\u4e00\u4e2a\u65b0\u7684\u5b57\u7b26\u4e32\u3002\u8fd4\u56de\u6240\u6709\u53ef\u80fd\u5f97\u5230\u7684\u5b57\u7b26\u4e32\u96c6\u5408\u3002

\n\n

 

\n\n
\u793a\u4f8b\uff1a\n\u8f93\u5165\uff1aS = "a1b2"\n\u8f93\u51fa\uff1a["a1b2", "a1B2", "A1b2", "A1B2"]\n\n\u8f93\u5165\uff1aS = "3z4"\n\u8f93\u51fa\uff1a["3z4", "3Z4"]\n\n\u8f93\u5165\uff1aS = "12345"\n\u8f93\u51fa\uff1a["12345"]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • S \u7684\u957f\u5ea6\u4e0d\u8d85\u8fc712\u3002
  • \n\t
  • S \u4ec5\u7531\u6570\u5b57\u548c\u5b57\u6bcd\u7ec4\u6210\u3002
  • \n
\n", "tags_en": ["Bit Manipulation", "Backtracking"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector letterCasePermutation(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List letterCasePermutation(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def letterCasePermutation(self, s):\n \"\"\"\n :type s: str\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def letterCasePermutation(self, s: str) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** letterCasePermutation(char * s, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList LetterCasePermutation(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string[]}\n */\nvar letterCasePermutation = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String[]}\ndef letter_case_permutation(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func letterCasePermutation(_ s: String) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func letterCasePermutation(s string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def letterCasePermutation(s: String): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun letterCasePermutation(s: String): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn letter_case_permutation(s: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String[]\n */\n function letterCasePermutation($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function letterCasePermutation(s: string): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (letter-case-permutation s)\n (-> string? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0784](https://leetcode-cn.com/problems/letter-case-permutation)", "[\u5b57\u6bcd\u5927\u5c0f\u5199\u5168\u6392\u5217](/solution/0700-0799/0784.Letter%20Case%20Permutation/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0784](https://leetcode.com/problems/letter-case-permutation)", "[Letter Case Permutation](/solution/0700-0799/0784.Letter%20Case%20Permutation/README_EN.md)", "`Bit Manipulation`,`Backtracking`", "Medium", ""]}, {"question_id": "0799", "frontend_question_id": "0783", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-distance-between-bst-nodes", "url_en": "https://leetcode.com/problems/minimum-distance-between-bst-nodes", "relative_path_cn": "/solution/0700-0799/0783.Minimum%20Distance%20Between%20BST%20Nodes/README.md", "relative_path_en": "/solution/0700-0799/0783.Minimum%20Distance%20Between%20BST%20Nodes/README_EN.md", "title_cn": "\u4e8c\u53c9\u641c\u7d22\u6811\u8282\u70b9\u6700\u5c0f\u8ddd\u79bb", "title_en": "Minimum Distance Between BST Nodes", "question_title_slug": "minimum-distance-between-bst-nodes", "content_en": "

Given the root of a Binary Search Tree (BST), return the minimum difference between the values of any two different nodes in the tree.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: root = [4,2,6,1,3]\nOutput: 1\n
\n\n

Example 2:

\n\"\"\n
\nInput: root = [1,0,48,null,null,12,49]\nOutput: 1\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The number of nodes in the tree is in the range [2, 100].
  • \n\t
  • 0 <= Node.val <= 105
  • \n
\n\n

 

\n

Note: This question is the same as 530: https://leetcode.com/problems/minimum-absolute-difference-in-bst/

\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6839\u8282\u70b9 root \uff0c\u8fd4\u56de \u6811\u4e2d\u4efb\u610f\u4e24\u4e0d\u540c\u8282\u70b9\u503c\u4e4b\u95f4\u7684\u6700\u5c0f\u5dee\u503c \u3002

\n\n

\u6ce8\u610f\uff1a\u672c\u9898\u4e0e 530\uff1ahttps://leetcode-cn.com/problems/minimum-absolute-difference-in-bst/ \u76f8\u540c

\n\n

\u00a0

\n\n
\n
\n

\u793a\u4f8b 1\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1aroot = [4,2,6,1,3]\n\u8f93\u51fa\uff1a1\n
\n\n

\u793a\u4f8b 2\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1aroot = [1,0,48,null,null,12,49]\n\u8f93\u51fa\uff1a1\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u6811\u4e2d\u8282\u70b9\u6570\u76ee\u5728\u8303\u56f4 [2, 100] \u5185
  • \n\t
  • 0 <= Node.val <= 105
  • \n\t
  • \u5dee\u503c\u662f\u4e00\u4e2a\u6b63\u6570\uff0c\u5176\u6570\u503c\u7b49\u4e8e\u4e24\u503c\u4e4b\u5dee\u7684\u7edd\u5bf9\u503c
  • \n
\n
\n
\n", "tags_en": ["Tree", "Depth-first Search", "Recursion"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u9012\u5f52"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int minDiffInBST(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int minDiffInBST(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def minDiffInBST(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def minDiffInBST(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint minDiffInBST(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int MinDiffInBST(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar minDiffInBST = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef min_diff_in_bst(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func minDiffInBST(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc minDiffInBST(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def minDiffInBST(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun minDiffInBST(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn min_diff_in_bst(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function minDiffInBST($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction minDiffInBST(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (min-diff-in-bst root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0783](https://leetcode-cn.com/problems/minimum-distance-between-bst-nodes)", "[\u4e8c\u53c9\u641c\u7d22\u6811\u8282\u70b9\u6700\u5c0f\u8ddd\u79bb](/solution/0700-0799/0783.Minimum%20Distance%20Between%20BST%20Nodes/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u9012\u5f52`", "\u7b80\u5355", ""], "md_table_row_en": ["[0783](https://leetcode.com/problems/minimum-distance-between-bst-nodes)", "[Minimum Distance Between BST Nodes](/solution/0700-0799/0783.Minimum%20Distance%20Between%20BST%20Nodes/README_EN.md)", "`Tree`,`Depth-first Search`,`Recursion`", "Easy", ""]}, {"question_id": "0798", "frontend_question_id": "0782", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/transform-to-chessboard", "url_en": "https://leetcode.com/problems/transform-to-chessboard", "relative_path_cn": "/solution/0700-0799/0782.Transform%20to%20Chessboard/README.md", "relative_path_en": "/solution/0700-0799/0782.Transform%20to%20Chessboard/README_EN.md", "title_cn": "\u53d8\u4e3a\u68cb\u76d8", "title_en": "Transform to Chessboard", "question_title_slug": "transform-to-chessboard", "content_en": "

An N x N board contains only 0s and 1s. In each move, you can swap any 2 rows with each other, or any 2 columns with each other.

\r\n\r\n

What is the minimum number of moves to transform the board into a "chessboard" - a board where no 0s and no 1s are 4-directionally adjacent? If the task is impossible, return -1.

\r\n\r\n
\r\nExamples:\r\nInput: board = [[0,1,1,0],[0,1,1,0],[1,0,0,1],[1,0,0,1]]\r\nOutput: 2\r\nExplanation:\r\nOne potential sequence of moves is shown below, from left to right:\r\n\r\n0110     1010     1010\r\n0110 --> 1010 --> 0101\r\n1001     0101     1010\r\n1001     0101     0101\r\n\r\nThe first move swaps the first and second column.\r\nThe second move swaps the second and third row.\r\n\r\n\r\nInput: board = [[0, 1], [1, 0]]\r\nOutput: 0\r\nExplanation:\r\nAlso note that the board with 0 in the top left corner,\r\n01\r\n10\r\n\r\nis also a valid chessboard.\r\n\r\nInput: board = [[1, 0], [1, 0]]\r\nOutput: -1\r\nExplanation:\r\nNo matter what sequence of moves you make, you cannot end with a valid chessboard.\r\n
\r\n\r\n

Note:

\r\n\r\n
    \r\n\t
  • board will have the same number of rows and columns, a number in the range [2, 30].
  • \r\n\t
  • board[i][j] will be only 0s or 1s.
  • \r\n
\r\n", "content_cn": "

\u4e00\u4e2a N x N\u7684 board \u4ec5\u7531 0 \u548c 1 \u7ec4\u6210 \u3002\u6bcf\u6b21\u79fb\u52a8\uff0c\u4f60\u80fd\u4efb\u610f\u4ea4\u6362\u4e24\u5217\u6216\u662f\u4e24\u884c\u7684\u4f4d\u7f6e\u3002

\n\n

\u8f93\u51fa\u5c06\u8fd9\u4e2a\u77e9\u9635\u53d8\u4e3a “\u68cb\u76d8” \u6240\u9700\u7684\u6700\u5c0f\u79fb\u52a8\u6b21\u6570\u3002“\u68cb\u76d8” \u662f\u6307\u4efb\u610f\u4e00\u683c\u7684\u4e0a\u4e0b\u5de6\u53f3\u56db\u4e2a\u65b9\u5411\u7684\u503c\u5747\u4e0e\u672c\u8eab\u4e0d\u540c\u7684\u77e9\u9635\u3002\u5982\u679c\u4e0d\u5b58\u5728\u53ef\u884c\u7684\u53d8\u6362\uff0c\u8f93\u51fa -1\u3002

\n\n
\u793a\u4f8b:\n\u8f93\u5165: board = [[0,1,1,0],[0,1,1,0],[1,0,0,1],[1,0,0,1]]\n\u8f93\u51fa: 2\n\u89e3\u91ca:\n\u4e00\u79cd\u53ef\u884c\u7684\u53d8\u6362\u65b9\u5f0f\u5982\u4e0b\uff0c\u4ece\u5de6\u5230\u53f3\uff1a\n\n0110     1010     1010\n0110 --> 1010 --> 0101\n1001     0101     1010\n1001     0101     0101\n\n\u7b2c\u4e00\u6b21\u79fb\u52a8\u4ea4\u6362\u4e86\u7b2c\u4e00\u5217\u548c\u7b2c\u4e8c\u5217\u3002\n\u7b2c\u4e8c\u6b21\u79fb\u52a8\u4ea4\u6362\u4e86\u7b2c\u4e8c\u884c\u548c\u7b2c\u4e09\u884c\u3002\n\n\n\u8f93\u5165: board = [[0, 1], [1, 0]]\n\u8f93\u51fa: 0\n\u89e3\u91ca:\n\u6ce8\u610f\u5de6\u4e0a\u89d2\u7684\u683c\u503c\u4e3a0\u65f6\u4e5f\u662f\u5408\u6cd5\u7684\u68cb\u76d8\uff0c\u5982\uff1a\n\n01\n10\n\n\u4e5f\u662f\u5408\u6cd5\u7684\u68cb\u76d8.\n\n\u8f93\u5165: board = [[1, 0], [1, 0]]\n\u8f93\u51fa: -1\n\u89e3\u91ca:\n\u4efb\u610f\u7684\u53d8\u6362\u90fd\u4e0d\u80fd\u4f7f\u8fd9\u4e2a\u8f93\u5165\u53d8\u4e3a\u5408\u6cd5\u7684\u68cb\u76d8\u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • board \u662f\u65b9\u9635\uff0c\u4e14\u884c\u5217\u6570\u7684\u8303\u56f4\u662f[2, 30]\u3002
  • \n\t
  • board[i][j] \u5c06\u53ea\u5305\u542b 0\u6216 1\u3002
  • \n
\n", "tags_en": ["Array", "Math"], "tags_cn": ["\u6570\u7ec4", "\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int movesToChessboard(vector>& board) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int movesToChessboard(int[][] board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def movesToChessboard(self, board):\n \"\"\"\n :type board: List[List[int]]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def movesToChessboard(self, board: List[List[int]]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint movesToChessboard(int** board, int boardSize, int* boardColSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MovesToChessboard(int[][] board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} board\n * @return {number}\n */\nvar movesToChessboard = function(board) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} board\n# @return {Integer}\ndef moves_to_chessboard(board)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func movesToChessboard(_ board: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func movesToChessboard(board [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def movesToChessboard(board: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun movesToChessboard(board: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn moves_to_chessboard(board: Vec>) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $board\n * @return Integer\n */\n function movesToChessboard($board) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function movesToChessboard(board: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (moves-to-chessboard board)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0782](https://leetcode-cn.com/problems/transform-to-chessboard)", "[\u53d8\u4e3a\u68cb\u76d8](/solution/0700-0799/0782.Transform%20to%20Chessboard/README.md)", "`\u6570\u7ec4`,`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[0782](https://leetcode.com/problems/transform-to-chessboard)", "[Transform to Chessboard](/solution/0700-0799/0782.Transform%20to%20Chessboard/README_EN.md)", "`Array`,`Math`", "Hard", ""]}, {"question_id": "0797", "frontend_question_id": "0781", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/rabbits-in-forest", "url_en": "https://leetcode.com/problems/rabbits-in-forest", "relative_path_cn": "/solution/0700-0799/0781.Rabbits%20in%20Forest/README.md", "relative_path_en": "/solution/0700-0799/0781.Rabbits%20in%20Forest/README_EN.md", "title_cn": "\u68ee\u6797\u4e2d\u7684\u5154\u5b50", "title_en": "Rabbits in Forest", "question_title_slug": "rabbits-in-forest", "content_en": "

In a forest, each rabbit has some color. Some subset of rabbits (possibly all of them) tell you how many other rabbits have the same color as them. Those answers are placed in an array.

\r\n\r\n

Return the minimum number of rabbits that could be in the forest.

\r\n\r\n
\r\nExamples:\r\nInput: answers = [1, 1, 2]\r\nOutput: 5\r\nExplanation:\r\nThe two rabbits that answered "1" could both be the same color, say red.\r\nThe rabbit than answered "2" can't be red or the answers would be inconsistent.\r\nSay the rabbit that answered "2" was blue.\r\nThen there should be 2 other blue rabbits in the forest that didn't answer into the array.\r\nThe smallest possible number of rabbits in the forest is therefore 5: 3 that answered plus 2 that didn't.\r\n\r\nInput: answers = [10, 10, 10]\r\nOutput: 11\r\n\r\nInput: answers = []\r\nOutput: 0\r\n
\r\n\r\n

Note:

\r\n\r\n
    \r\n\t
  1. answers will have length at most 1000.
  2. \r\n\t
  3. Each answers[i] will be an integer in the range [0, 999].
  4. \r\n
\r\n", "content_cn": "

\u68ee\u6797\u4e2d\uff0c\u6bcf\u4e2a\u5154\u5b50\u90fd\u6709\u989c\u8272\u3002\u5176\u4e2d\u4e00\u4e9b\u5154\u5b50\uff08\u53ef\u80fd\u662f\u5168\u90e8\uff09\u544a\u8bc9\u4f60\u8fd8\u6709\u591a\u5c11\u5176\u4ed6\u7684\u5154\u5b50\u548c\u81ea\u5df1\u6709\u76f8\u540c\u7684\u989c\u8272\u3002\u6211\u4eec\u5c06\u8fd9\u4e9b\u56de\u7b54\u653e\u5728 answers \u6570\u7ec4\u91cc\u3002

\n\n

\u8fd4\u56de\u68ee\u6797\u4e2d\u5154\u5b50\u7684\u6700\u5c11\u6570\u91cf\u3002

\n\n
\n\u793a\u4f8b:\n\u8f93\u5165: answers = [1, 1, 2]\n\u8f93\u51fa: 5\n\u89e3\u91ca:\n\u4e24\u53ea\u56de\u7b54\u4e86 "1" \u7684\u5154\u5b50\u53ef\u80fd\u6709\u76f8\u540c\u7684\u989c\u8272\uff0c\u8bbe\u4e3a\u7ea2\u8272\u3002\n\u4e4b\u540e\u56de\u7b54\u4e86 "2" \u7684\u5154\u5b50\u4e0d\u4f1a\u662f\u7ea2\u8272\uff0c\u5426\u5219\u4ed6\u4eec\u7684\u56de\u7b54\u4f1a\u76f8\u4e92\u77db\u76fe\u3002\n\u8bbe\u56de\u7b54\u4e86 "2" \u7684\u5154\u5b50\u4e3a\u84dd\u8272\u3002\n\u6b64\u5916\uff0c\u68ee\u6797\u4e2d\u8fd8\u5e94\u6709\u53e6\u5916 2 \u53ea\u84dd\u8272\u5154\u5b50\u7684\u56de\u7b54\u6ca1\u6709\u5305\u542b\u5728\u6570\u7ec4\u4e2d\u3002\n\u56e0\u6b64\u68ee\u6797\u4e2d\u5154\u5b50\u7684\u6700\u5c11\u6570\u91cf\u662f 5: 3 \u53ea\u56de\u7b54\u7684\u548c 2 \u53ea\u6ca1\u6709\u56de\u7b54\u7684\u3002\n\n\u8f93\u5165: answers = [10, 10, 10]\n\u8f93\u51fa: 11\n\n\u8f93\u5165: answers = []\n\u8f93\u51fa: 0\n
\n\n

\u8bf4\u660e:

\n\n
    \n\t
  1. answers \u7684\u957f\u5ea6\u6700\u5927\u4e3a1000\u3002
  2. \n\t
  3. answers[i] \u662f\u5728 [0, 999] \u8303\u56f4\u5185\u7684\u6574\u6570\u3002
  4. \n
\n", "tags_en": ["Hash Table", "Math"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numRabbits(vector& answers) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numRabbits(int[] answers) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numRabbits(self, answers):\n \"\"\"\n :type answers: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numRabbits(self, answers: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numRabbits(int* answers, int answersSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumRabbits(int[] answers) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} answers\n * @return {number}\n */\nvar numRabbits = function(answers) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} answers\n# @return {Integer}\ndef num_rabbits(answers)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numRabbits(_ answers: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numRabbits(answers []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numRabbits(answers: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numRabbits(answers: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_rabbits(answers: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $answers\n * @return Integer\n */\n function numRabbits($answers) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numRabbits(answers: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-rabbits answers)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0781](https://leetcode-cn.com/problems/rabbits-in-forest)", "[\u68ee\u6797\u4e2d\u7684\u5154\u5b50](/solution/0700-0799/0781.Rabbits%20in%20Forest/README.md)", "`\u54c8\u5e0c\u8868`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0781](https://leetcode.com/problems/rabbits-in-forest)", "[Rabbits in Forest](/solution/0700-0799/0781.Rabbits%20in%20Forest/README_EN.md)", "`Hash Table`,`Math`", "Medium", ""]}, {"question_id": "0796", "frontend_question_id": "0780", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reaching-points", "url_en": "https://leetcode.com/problems/reaching-points", "relative_path_cn": "/solution/0700-0799/0780.Reaching%20Points/README.md", "relative_path_en": "/solution/0700-0799/0780.Reaching%20Points/README_EN.md", "title_cn": "\u5230\u8fbe\u7ec8\u70b9", "title_en": "Reaching Points", "question_title_slug": "reaching-points", "content_en": "

A move consists of taking a point (x, y) and transforming it to either (x, x+y) or (x+y, y).

\r\n\r\n

Given a starting point (sx, sy) and a target point (tx, ty), return True if and only if a sequence of moves exists to transform the point (sx, sy) to (tx, ty). Otherwise, return False.

\r\n\r\n
\r\nExamples:\r\nInput: sx = 1, sy = 1, tx = 3, ty = 5\r\nOutput: True\r\nExplanation:\r\nOne series of moves that transforms the starting point to the target is:\r\n(1, 1) -> (1, 2)\r\n(1, 2) -> (3, 2)\r\n(3, 2) -> (3, 5)\r\n\r\nInput: sx = 1, sy = 1, tx = 2, ty = 2\r\nOutput: False\r\n\r\nInput: sx = 1, sy = 1, tx = 1, ty = 1\r\nOutput: True\r\n\r\n
\r\n\r\n

Note:

\r\n\r\n
    \r\n\t
  • sx, sy, tx, ty will all be integers in the range [1, 10^9].
  • \r\n
\r\n", "content_cn": "

\u4ece\u70b9 (x, y) \u53ef\u4ee5\u8f6c\u6362\u5230 (x, x+y)  \u6216\u8005 (x+y, y)\u3002

\n\n

\u7ed9\u5b9a\u4e00\u4e2a\u8d77\u70b9 (sx, sy) \u548c\u4e00\u4e2a\u7ec8\u70b9 (tx, ty)\uff0c\u5982\u679c\u901a\u8fc7\u4e00\u7cfb\u5217\u7684\u8f6c\u6362\u53ef\u4ee5\u4ece\u8d77\u70b9\u5230\u8fbe\u7ec8\u70b9\uff0c\u5219\u8fd4\u56de True \uff0c\u5426\u5219\u8fd4\u56de False\u3002

\n\n
\n\u793a\u4f8b:\n\u8f93\u5165: sx = 1, sy = 1, tx = 3, ty = 5\n\u8f93\u51fa: True\n\u89e3\u91ca:\n\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u4e00\u7cfb\u5217\u8f6c\u6362\u4ece\u8d77\u70b9\u8f6c\u6362\u5230\u7ec8\u70b9\uff1a\n(1, 1) -> (1, 2)\n(1, 2) -> (3, 2)\n(3, 2) -> (3, 5)\n\n\u8f93\u5165: sx = 1, sy = 1, tx = 2, ty = 2\n\u8f93\u51fa: False\n\n\u8f93\u5165: sx = 1, sy = 1, tx = 1, ty = 1\n\u8f93\u51fa: True\n\n
\n\n

\u6ce8\u610f:

\n\n
    \n\t
  • sx, sy, tx, ty \u662f\u8303\u56f4\u5728 [1, 10^9] \u7684\u6574\u6570\u3002
  • \n
\n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool reachingPoints(int sx, int sy, int tx, int ty) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean reachingPoints(int sx, int sy, int tx, int ty) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def reachingPoints(self, sx, sy, tx, ty):\n \"\"\"\n :type sx: int\n :type sy: int\n :type tx: int\n :type ty: int\n :rtype: bool\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def reachingPoints(self, sx: int, sy: int, tx: int, ty: int) -> bool:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool reachingPoints(int sx, int sy, int tx, int ty){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool ReachingPoints(int sx, int sy, int tx, int ty) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} sx\n * @param {number} sy\n * @param {number} tx\n * @param {number} ty\n * @return {boolean}\n */\nvar reachingPoints = function(sx, sy, tx, ty) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} sx\n# @param {Integer} sy\n# @param {Integer} tx\n# @param {Integer} ty\n# @return {Boolean}\ndef reaching_points(sx, sy, tx, ty)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func reachingPoints(_ sx: Int, _ sy: Int, _ tx: Int, _ ty: Int) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func reachingPoints(sx int, sy int, tx int, ty int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def reachingPoints(sx: Int, sy: Int, tx: Int, ty: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun reachingPoints(sx: Int, sy: Int, tx: Int, ty: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn reaching_points(sx: i32, sy: i32, tx: i32, ty: i32) -> bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $sx\n * @param Integer $sy\n * @param Integer $tx\n * @param Integer $ty\n * @return Boolean\n */\n function reachingPoints($sx, $sy, $tx, $ty) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function reachingPoints(sx: number, sy: number, tx: number, ty: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (reaching-points sx sy tx ty)\n (-> exact-integer? exact-integer? exact-integer? exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0780](https://leetcode-cn.com/problems/reaching-points)", "[\u5230\u8fbe\u7ec8\u70b9](/solution/0700-0799/0780.Reaching%20Points/README.md)", "`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[0780](https://leetcode.com/problems/reaching-points)", "[Reaching Points](/solution/0700-0799/0780.Reaching%20Points/README_EN.md)", "`Math`", "Hard", ""]}, {"question_id": "0795", "frontend_question_id": "0779", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/k-th-symbol-in-grammar", "url_en": "https://leetcode.com/problems/k-th-symbol-in-grammar", "relative_path_cn": "/solution/0700-0799/0779.K-th%20Symbol%20in%20Grammar/README.md", "relative_path_en": "/solution/0700-0799/0779.K-th%20Symbol%20in%20Grammar/README_EN.md", "title_cn": "\u7b2cK\u4e2a\u8bed\u6cd5\u7b26\u53f7", "title_en": "K-th Symbol in Grammar", "question_title_slug": "k-th-symbol-in-grammar", "content_en": "

We build a table of n rows (1-indexed). We start by writing 0 in the 1st row. Now in every subsequent row, we look at the previous row and replace each occurrence of 0 with 01, and each occurrence of 1 with 10.

\n\n
    \n\t
  • For example, for n = 3, the 1st row is 0, the 2nd row is 01, and the 3rd row is 0110.
  • \n
\n\n

Given two integer n and k, return the kth (1-indexed) symbol in the nth row of a table of n rows.

\n\n

 

\n

Example 1:

\n\n
\nInput: n = 1, k = 1\nOutput: 0\nExplanation: row 1: 0\n
\n\n

Example 2:

\n\n
\nInput: n = 2, k = 1\nOutput: 0\nExplanation:\nrow 1: 0\nrow 2: 01\n
\n\n

Example 3:

\n\n
\nInput: n = 2, k = 2\nOutput: 1\nExplanation:\nrow 1: 0\nrow 2: 01\n
\n\n

Example 4:

\n\n
\nInput: n = 3, k = 1\nOutput: 0\nExplanation:\nrow 1: 0\nrow 2: 01\nrow 3: 0110\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= n <= 30
  • \n\t
  • 1 <= k <= 2n - 1
  • \n
\n", "content_cn": "

\u5728\u7b2c\u4e00\u884c\u6211\u4eec\u5199\u4e0a\u4e00\u4e2a 0\u3002\u63a5\u4e0b\u6765\u7684\u6bcf\u4e00\u884c\uff0c\u5c06\u524d\u4e00\u884c\u4e2d\u76840\u66ff\u6362\u4e3a01\uff0c1\u66ff\u6362\u4e3a10\u3002

\n\n

\u7ed9\u5b9a\u884c\u6570 N \u548c\u5e8f\u6570 K\uff0c\u8fd4\u56de\u7b2c N \u884c\u4e2d\u7b2c K\u4e2a\u5b57\u7b26\u3002\uff08K\u4ece1\u5f00\u59cb\uff09

\n\n


\n\u4f8b\u5b50:

\n\n
\u8f93\u5165: N = 1, K = 1\n\u8f93\u51fa: 0\n\n\u8f93\u5165: N = 2, K = 1\n\u8f93\u51fa: 0\n\n\u8f93\u5165: N = 2, K = 2\n\u8f93\u51fa: 1\n\n\u8f93\u5165: N = 4, K = 5\n\u8f93\u51fa: 1\n\n\u89e3\u91ca:\n\u7b2c\u4e00\u884c: 0\n\u7b2c\u4e8c\u884c: 01\n\u7b2c\u4e09\u884c: 0110\n\u7b2c\u56db\u884c: 01101001\n
\n\n


\n\u6ce8\u610f\uff1a

\n\n
    \n\t
  1. N \u7684\u8303\u56f4 [1, 30].
  2. \n\t
  3. K \u7684\u8303\u56f4 [1, 2^(N-1)].
  4. \n
\n", "tags_en": ["Recursion"], "tags_cn": ["\u9012\u5f52"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int kthGrammar(int n, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int kthGrammar(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def kthGrammar(self, n, k):\n \"\"\"\n :type n: int\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def kthGrammar(self, n: int, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint kthGrammar(int n, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int KthGrammar(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} k\n * @return {number}\n */\nvar kthGrammar = function(n, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} k\n# @return {Integer}\ndef kth_grammar(n, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func kthGrammar(_ n: Int, _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func kthGrammar(n int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def kthGrammar(n: Int, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun kthGrammar(n: Int, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn kth_grammar(n: i32, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $k\n * @return Integer\n */\n function kthGrammar($n, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function kthGrammar(n: number, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (kth-grammar n k)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0779](https://leetcode-cn.com/problems/k-th-symbol-in-grammar)", "[\u7b2cK\u4e2a\u8bed\u6cd5\u7b26\u53f7](/solution/0700-0799/0779.K-th%20Symbol%20in%20Grammar/README.md)", "`\u9012\u5f52`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0779](https://leetcode.com/problems/k-th-symbol-in-grammar)", "[K-th Symbol in Grammar](/solution/0700-0799/0779.K-th%20Symbol%20in%20Grammar/README_EN.md)", "`Recursion`", "Medium", ""]}, {"question_id": "0794", "frontend_question_id": "0778", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/swim-in-rising-water", "url_en": "https://leetcode.com/problems/swim-in-rising-water", "relative_path_cn": "/solution/0700-0799/0778.Swim%20in%20Rising%20Water/README.md", "relative_path_en": "/solution/0700-0799/0778.Swim%20in%20Rising%20Water/README_EN.md", "title_cn": "\u6c34\u4f4d\u4e0a\u5347\u7684\u6cf3\u6c60\u4e2d\u6e38\u6cf3", "title_en": "Swim in Rising Water", "question_title_slug": "swim-in-rising-water", "content_en": "

On an N x N grid, each square grid[i][j] represents the elevation at that point (i,j).

\r\n\r\n

Now rain starts to fall. At time t, the depth of the water everywhere is t. You can swim from a square to another 4-directionally adjacent square if and only if the elevation of both squares individually are at most t. You can swim infinite distance in zero time. Of course, you must stay within the boundaries of the grid during your swim.

\r\n\r\n

You start at the top left square (0, 0). What is the least time until you can reach the bottom right square (N-1, N-1)?

\r\n\r\n

Example 1:

\r\n\r\n
\r\nInput: [[0,2],[1,3]]\r\nOutput: 3\r\nExplanation:\r\nAt time 0, you are in grid location (0, 0).\r\nYou cannot go anywhere else because 4-directionally adjacent neighbors have a higher elevation than t = 0.\r\n\r\nYou cannot reach point (1, 1) until time 3.\r\nWhen the depth of water is 3, we can swim anywhere inside the grid.\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: [[0,1,2,3,4],[24,23,22,21,5],[12,13,14,15,16],[11,17,18,19,20],[10,9,8,7,6]]\r\nOutput: 16\r\nExplanation:\r\n 0  1  2  3  4\r\n24 23 22 21  5\r\n12 13 14 15 16\r\n11 17 18 19 20\r\n10  9  8  7  6\r\n\r\nThe final route is marked in bold.\r\nWe need to wait until time 16 so that (0, 0) and (4, 4) are connected.\r\n
\r\n\r\n

Note:

\r\n\r\n
    \r\n\t
  1. 2 <= N <= 50.
  2. \r\n\t
  3. grid[i][j] is a permutation of [0, ..., N*N - 1].
  4. \r\n
\r\n", "content_cn": "

\u5728\u4e00\u4e2a N x N \u7684\u5750\u6807\u65b9\u683c\u00a0grid \u4e2d\uff0c\u6bcf\u4e00\u4e2a\u65b9\u683c\u7684\u503c grid[i][j] \u8868\u793a\u5728\u4f4d\u7f6e (i,j) \u7684\u5e73\u53f0\u9ad8\u5ea6\u3002

\n\n

\u73b0\u5728\u5f00\u59cb\u4e0b\u96e8\u4e86\u3002\u5f53\u65f6\u95f4\u4e3a\u00a0t\u00a0\u65f6\uff0c\u6b64\u65f6\u96e8\u6c34\u5bfc\u81f4\u6c34\u6c60\u4e2d\u4efb\u610f\u4f4d\u7f6e\u7684\u6c34\u4f4d\u4e3a\u00a0t\u00a0\u3002\u4f60\u53ef\u4ee5\u4ece\u4e00\u4e2a\u5e73\u53f0\u6e38\u5411\u56db\u5468\u76f8\u90bb\u7684\u4efb\u610f\u4e00\u4e2a\u5e73\u53f0\uff0c\u4f46\u662f\u524d\u63d0\u662f\u6b64\u65f6\u6c34\u4f4d\u5fc5\u987b\u540c\u65f6\u6df9\u6ca1\u8fd9\u4e24\u4e2a\u5e73\u53f0\u3002\u5047\u5b9a\u4f60\u53ef\u4ee5\u77ac\u95f4\u79fb\u52a8\u65e0\u9650\u8ddd\u79bb\uff0c\u4e5f\u5c31\u662f\u9ed8\u8ba4\u5728\u65b9\u683c\u5185\u90e8\u6e38\u52a8\u662f\u4e0d\u8017\u65f6\u7684\u3002\u5f53\u7136\uff0c\u5728\u4f60\u6e38\u6cf3\u7684\u65f6\u5019\u4f60\u5fc5\u987b\u5f85\u5728\u5750\u6807\u65b9\u683c\u91cc\u9762\u3002

\n\n

\u4f60\u4ece\u5750\u6807\u65b9\u683c\u7684\u5de6\u4e0a\u5e73\u53f0 (0\uff0c0) \u51fa\u53d1\u3002\u6700\u5c11\u8017\u65f6\u591a\u4e45\u4f60\u624d\u80fd\u5230\u8fbe\u5750\u6807\u65b9\u683c\u7684\u53f3\u4e0b\u5e73\u53f0\u00a0(N-1, N-1)\uff1f

\n\n

\u00a0

\n\n

\u793a\u4f8b 1:

\n\n
\n\u8f93\u5165: [[0,2],[1,3]]\n\u8f93\u51fa: 3\n\u89e3\u91ca:\n\u65f6\u95f4\u4e3a0\u65f6\uff0c\u4f60\u4f4d\u4e8e\u5750\u6807\u65b9\u683c\u7684\u4f4d\u7f6e\u4e3a (0, 0)\u3002\n\u6b64\u65f6\u4f60\u4e0d\u80fd\u6e38\u5411\u4efb\u610f\u65b9\u5411\uff0c\u56e0\u4e3a\u56db\u4e2a\u76f8\u90bb\u65b9\u5411\u5e73\u53f0\u7684\u9ad8\u5ea6\u90fd\u5927\u4e8e\u5f53\u524d\u65f6\u95f4\u4e3a 0 \u65f6\u7684\u6c34\u4f4d\u3002\n\n\u7b49\u65f6\u95f4\u5230\u8fbe 3 \u65f6\uff0c\u4f60\u624d\u53ef\u4ee5\u6e38\u5411\u5e73\u53f0 (1, 1). \u56e0\u4e3a\u6b64\u65f6\u7684\u6c34\u4f4d\u662f 3\uff0c\u5750\u6807\u65b9\u683c\u4e2d\u7684\u5e73\u53f0\u6ca1\u6709\u6bd4\u6c34\u4f4d 3 \u66f4\u9ad8\u7684\uff0c\u6240\u4ee5\u4f60\u53ef\u4ee5\u6e38\u5411\u5750\u6807\u65b9\u683c\u4e2d\u7684\u4efb\u610f\u4f4d\u7f6e\n
\n\n

\u793a\u4f8b2:

\n\n
\n\u8f93\u5165: [[0,1,2,3,4],[24,23,22,21,5],[12,13,14,15,16],[11,17,18,19,20],[10,9,8,7,6]]\n\u8f93\u51fa: 16\n\u89e3\u91ca:\n 0  1  2  3  4\n24 23 22 21  5\n12 13 14 15 16\n11 17 18 19 20\n10  9  8  7  6\n\n\u6700\u7ec8\u7684\u8def\u7ebf\u7528\u52a0\u7c97\u8fdb\u884c\u4e86\u6807\u8bb0\u3002\n\u6211\u4eec\u5fc5\u987b\u7b49\u5230\u65f6\u95f4\u4e3a 16\uff0c\u6b64\u65f6\u624d\u80fd\u4fdd\u8bc1\u5e73\u53f0 (0, 0) \u548c (4, 4) \u662f\u8fde\u901a\u7684\n
\n\n

\u00a0

\n\n

\u63d0\u793a:

\n\n
    \n\t
  1. 2 <= N <= 50.
  2. \n\t
  3. grid[i][j] \u662f [0, ..., N*N - 1] \u7684\u6392\u5217\u3002
  4. \n
\n", "tags_en": ["Heap", "Depth-first Search", "Union Find", "Binary Search"], "tags_cn": ["\u5806", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e76\u67e5\u96c6", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int swimInWater(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int swimInWater(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def swimInWater(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def swimInWater(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint swimInWater(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SwimInWater(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar swimInWater = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef swim_in_water(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func swimInWater(_ grid: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func swimInWater(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def swimInWater(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun swimInWater(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn swim_in_water(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function swimInWater($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function swimInWater(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (swim-in-water grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0778](https://leetcode-cn.com/problems/swim-in-rising-water)", "[\u6c34\u4f4d\u4e0a\u5347\u7684\u6cf3\u6c60\u4e2d\u6e38\u6cf3](/solution/0700-0799/0778.Swim%20in%20Rising%20Water/README.md)", "`\u5806`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e76\u67e5\u96c6`,`\u4e8c\u5206\u67e5\u627e`", "\u56f0\u96be", ""], "md_table_row_en": ["[0778](https://leetcode.com/problems/swim-in-rising-water)", "[Swim in Rising Water](/solution/0700-0799/0778.Swim%20in%20Rising%20Water/README_EN.md)", "`Heap`,`Depth-first Search`,`Union Find`,`Binary Search`", "Hard", ""]}, {"question_id": "0793", "frontend_question_id": "0777", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/swap-adjacent-in-lr-string", "url_en": "https://leetcode.com/problems/swap-adjacent-in-lr-string", "relative_path_cn": "/solution/0700-0799/0777.Swap%20Adjacent%20in%20LR%20String/README.md", "relative_path_en": "/solution/0700-0799/0777.Swap%20Adjacent%20in%20LR%20String/README_EN.md", "title_cn": "\u5728LR\u5b57\u7b26\u4e32\u4e2d\u4ea4\u6362\u76f8\u90bb\u5b57\u7b26", "title_en": "Swap Adjacent in LR String", "question_title_slug": "swap-adjacent-in-lr-string", "content_en": "

In a string composed of 'L', 'R', and 'X' characters, like "RXXLRXRXL", a move consists of either replacing one occurrence of "XL" with "LX", or replacing one occurrence of "RX" with "XR". Given the starting string start and the ending string end, return True if and only if there exists a sequence of moves to transform one string to the other.

\n\n

 

\n

Example 1:

\n\n
\nInput: start = "RXXLRXRXL", end = "XRLXXRRLX"\nOutput: true\nExplanation: We can transform start to end following these steps:\nRXXLRXRXL ->\nXRXLRXRXL ->\nXRLXRXRXL ->\nXRLXXRRXL ->\nXRLXXRRLX\n
\n\n

Example 2:

\n\n
\nInput: start = "X", end = "L"\nOutput: false\n
\n\n

Example 3:

\n\n
\nInput: start = "LLR", end = "RRL"\nOutput: false\n
\n\n

Example 4:

\n\n
\nInput: start = "XL", end = "LX"\nOutput: true\n
\n\n

Example 5:

\n\n
\nInput: start = "XLLR", end = "LXLX"\nOutput: false\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= start.length <= 104
  • \n\t
  • start.length == end.length
  • \n\t
  • Both start and end will only consist of characters in 'L', 'R', and 'X'.
  • \n
\n", "content_cn": "

\u5728\u4e00\u4e2a\u7531 'L' , 'R' \u548c 'X' \u4e09\u4e2a\u5b57\u7b26\u7ec4\u6210\u7684\u5b57\u7b26\u4e32\uff08\u4f8b\u5982"RXXLRXRXL"\uff09\u4e2d\u8fdb\u884c\u79fb\u52a8\u64cd\u4f5c\u3002\u4e00\u6b21\u79fb\u52a8\u64cd\u4f5c\u6307\u7528\u4e00\u4e2a"LX"\u66ff\u6362\u4e00\u4e2a"XL"\uff0c\u6216\u8005\u7528\u4e00\u4e2a"XR"\u66ff\u6362\u4e00\u4e2a"RX"\u3002\u73b0\u7ed9\u5b9a\u8d77\u59cb\u5b57\u7b26\u4e32start\u548c\u7ed3\u675f\u5b57\u7b26\u4e32end\uff0c\u8bf7\u7f16\u5199\u4ee3\u7801\uff0c\u5f53\u4e14\u4ec5\u5f53\u5b58\u5728\u4e00\u7cfb\u5217\u79fb\u52a8\u64cd\u4f5c\u4f7f\u5f97start\u53ef\u4ee5\u8f6c\u6362\u6210end\u65f6\uff0c \u8fd4\u56deTrue\u3002

\n\n

 

\n\n

\u793a\u4f8b :

\n\n
\u8f93\u5165: start = "RXXLRXRXL", end = "XRLXXRRLX"\n\u8f93\u51fa: True\n\u89e3\u91ca:\n\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u51e0\u6b65\u5c06start\u8f6c\u6362\u6210end:\nRXXLRXRXL ->\nXRXLRXRXL ->\nXRLXRXRXL ->\nXRLXXRRXL ->\nXRLXXRRLX\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= len(start) = len(end) <= 10000\u3002
  • \n\t
  • start\u548cend\u4e2d\u7684\u5b57\u7b26\u4e32\u4ec5\u9650\u4e8e'L', 'R'\u548c'X'\u3002
  • \n
\n", "tags_en": ["Brainteaser"], "tags_cn": ["\u8111\u7b4b\u6025\u8f6c\u5f2f"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canTransform(string start, string end) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canTransform(String start, String end) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canTransform(self, start, end):\n \"\"\"\n :type start: str\n :type end: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canTransform(self, start: str, end: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canTransform(char * start, char * end){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanTransform(string start, string end) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} start\n * @param {string} end\n * @return {boolean}\n */\nvar canTransform = function(start, end) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} start\n# @param {String} end\n# @return {Boolean}\ndef can_transform(start, end)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canTransform(_ start: String, _ end: String) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canTransform(start string, end string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canTransform(start: String, end: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canTransform(start: String, end: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_transform(start: String, end: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $start\n * @param String $end\n * @return Boolean\n */\n function canTransform($start, $end) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canTransform(start: string, end: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-transform start end)\n (-> string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0777](https://leetcode-cn.com/problems/swap-adjacent-in-lr-string)", "[\u5728LR\u5b57\u7b26\u4e32\u4e2d\u4ea4\u6362\u76f8\u90bb\u5b57\u7b26](/solution/0700-0799/0777.Swap%20Adjacent%20in%20LR%20String/README.md)", "`\u8111\u7b4b\u6025\u8f6c\u5f2f`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0777](https://leetcode.com/problems/swap-adjacent-in-lr-string)", "[Swap Adjacent in LR String](/solution/0700-0799/0777.Swap%20Adjacent%20in%20LR%20String/README_EN.md)", "`Brainteaser`", "Medium", ""]}, {"question_id": "0792", "frontend_question_id": "0704", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/binary-search", "url_en": "https://leetcode.com/problems/binary-search", "relative_path_cn": "/solution/0700-0799/0704.Binary%20Search/README.md", "relative_path_en": "/solution/0700-0799/0704.Binary%20Search/README_EN.md", "title_cn": "\u4e8c\u5206\u67e5\u627e", "title_en": "Binary Search", "question_title_slug": "binary-search", "content_en": "

Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists, then return its index. Otherwise, return -1.

\n\n

You must write an algorithm with O(log n) runtime complexity.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [-1,0,3,5,9,12], target = 9\nOutput: 4\nExplanation: 9 exists in nums and its index is 4\n
\n\n

Example 2:

\n\n
\nInput: nums = [-1,0,3,5,9,12], target = 2\nOutput: -1\nExplanation: 2 does not exist in nums so return -1\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= nums.length <= 104
  • \n\t
  • -9999 <= nums[i], target <= 9999
  • \n\t
  • All the integers in nums are unique.
  • \n\t
  • nums is sorted in an ascending order.
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a n \u4e2a\u5143\u7d20\u6709\u5e8f\u7684\uff08\u5347\u5e8f\uff09\u6574\u578b\u6570\u7ec4 nums \u548c\u4e00\u4e2a\u76ee\u6807\u503c target  \uff0c\u5199\u4e00\u4e2a\u51fd\u6570\u641c\u7d22 nums \u4e2d\u7684 target\uff0c\u5982\u679c\u76ee\u6807\u503c\u5b58\u5728\u8fd4\u56de\u4e0b\u6807\uff0c\u5426\u5219\u8fd4\u56de -1\u3002

\n\n


\n\u793a\u4f8b 1:

\n\n
\u8f93\u5165: nums = [-1,0,3,5,9,12], target = 9\n\u8f93\u51fa: 4\n\u89e3\u91ca: 9 \u51fa\u73b0\u5728 nums \u4e2d\u5e76\u4e14\u4e0b\u6807\u4e3a 4\n
\n\n

\u793a\u4f8b 2:

\n\n
\u8f93\u5165: nums = [-1,0,3,5,9,12], target = 2\n\u8f93\u51fa: -1\n\u89e3\u91ca: 2 \u4e0d\u5b58\u5728 nums \u4e2d\u56e0\u6b64\u8fd4\u56de -1\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. \u4f60\u53ef\u4ee5\u5047\u8bbe nums \u4e2d\u7684\u6240\u6709\u5143\u7d20\u662f\u4e0d\u91cd\u590d\u7684\u3002
  2. \n\t
  3. n \u5c06\u5728 [1, 10000]\u4e4b\u95f4\u3002
  4. \n\t
  5. nums \u7684\u6bcf\u4e2a\u5143\u7d20\u90fd\u5c06\u5728 [-9999, 9999]\u4e4b\u95f4\u3002
  6. \n
\n", "tags_en": ["Binary Search"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int search(vector& nums, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int search(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def search(self, nums, target):\n \"\"\"\n :type nums: List[int]\n :type target: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def search(self, nums: List[int], target: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint search(int* nums, int numsSize, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int Search(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} target\n * @return {number}\n */\nvar search = function(nums, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} target\n# @return {Integer}\ndef search(nums, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func search(_ nums: [Int], _ target: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func search(nums []int, target int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def search(nums: Array[Int], target: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun search(nums: IntArray, target: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn search(nums: Vec, target: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $target\n * @return Integer\n */\n function search($nums, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function search(nums: number[], target: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (search nums target)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0704](https://leetcode-cn.com/problems/binary-search)", "[\u4e8c\u5206\u67e5\u627e](/solution/0700-0799/0704.Binary%20Search/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u7b80\u5355", ""], "md_table_row_en": ["[0704](https://leetcode.com/problems/binary-search)", "[Binary Search](/solution/0700-0799/0704.Binary%20Search/README_EN.md)", "`Binary Search`", "Easy", ""]}, {"question_id": "0791", "frontend_question_id": "0776", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/split-bst", "url_en": "https://leetcode.com/problems/split-bst", "relative_path_cn": "/solution/0700-0799/0776.Split%20BST/README.md", "relative_path_en": "/solution/0700-0799/0776.Split%20BST/README_EN.md", "title_cn": "\u62c6\u5206\u4e8c\u53c9\u641c\u7d22\u6811", "title_en": "Split BST", "question_title_slug": "split-bst", "content_en": "

Given a Binary Search Tree (BST) with root node root, and a target value target, split the tree into two subtrees where one subtree has nodes that are all smaller or equal to the target value, while the other subtree has all nodes that are greater than the target value. It's not necessarily the case that the tree contains a node with value target.

\n\n

Additionally, most of the structure of the original tree should remain. Formally, for any child c with parent p in the original tree, if they are both in the same subtree after the split, then node c should still have the parent p.

\n\n

You should output the root TreeNode of both subtrees after splitting, in any order.

\n\n

Example 1:

\n\n
\nInput: root = [4,2,6,1,3,5,7], target = 2\nOutput: [[2,1],[4,3,6,null,null,5,7]]\nExplanation:\nNote that root, output[0], and output[1] are TreeNode objects, not arrays.\n\nThe given tree [4,2,6,1,3,5,7] is represented by the following diagram:\n\n          4\n        /   \\\n      2      6\n     / \\    / \\\n    1   3  5   7\n\nwhile the diagrams for the outputs are:\n\n          4\n        /   \\\n      3      6      and    2\n            / \\           /\n           5   7         1\n
\n\n

Note:

\n\n
    \n\t
  1. The size of the BST will not exceed 50.
  2. \n\t
  3. The BST is always valid and each node's value is different.
  4. \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u68f5\u4e8c\u53c9\u641c\u7d22\u6811\uff08BST\uff09\u3001\u5b83\u7684\u6839\u7ed3\u70b9 root\u00a0\u4ee5\u53ca\u76ee\u6807\u503c V\u3002

\n\n

\u8bf7\u5c06\u8be5\u6811\u6309\u8981\u6c42\u62c6\u5206\u4e3a\u4e24\u4e2a\u5b50\u6811\uff1a\u5176\u4e2d\u4e00\u4e2a\u5b50\u6811\u7ed3\u70b9\u7684\u503c\u90fd\u5fc5\u987b\u5c0f\u4e8e\u7b49\u4e8e\u7ed9\u5b9a\u7684\u76ee\u6807\u503c V\uff1b\u53e6\u4e00\u4e2a\u5b50\u6811\u7ed3\u70b9\u7684\u503c\u90fd\u5fc5\u987b\u5927\u4e8e\u76ee\u6807\u503c V\uff1b\u6811\u4e2d\u5e76\u975e\u4e00\u5b9a\u8981\u5b58\u5728\u503c\u4e3a V\u00a0\u7684\u7ed3\u70b9\u3002

\n\n

\u9664\u6b64\u4e4b\u5916\uff0c\u6811\u4e2d\u5927\u90e8\u5206\u7ed3\u6784\u90fd\u9700\u8981\u4fdd\u7559\uff0c\u4e5f\u5c31\u662f\u8bf4\u539f\u59cb\u6811\u4e2d\u7236\u8282\u70b9 P \u7684\u4efb\u610f\u5b50\u8282\u70b9 C\uff0c\u5047\u5982\u62c6\u5206\u540e\u5b83\u4eec\u4ecd\u5728\u540c\u4e00\u4e2a\u5b50\u6811\u4e2d\uff0c\u90a3\u4e48\u7ed3\u70b9 P \u5e94\u4ecd\u4e3a C \u7684\u7236\u7ed3\u70b9\u3002

\n\n

\u4f60\u9700\u8981\u8fd4\u56de\u62c6\u5206\u540e\u4e24\u4e2a\u5b50\u6811\u7684\u6839\u7ed3\u70b9 TreeNode\uff0c\u987a\u5e8f\u968f\u610f\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b\uff1a

\n\n
\n\u8f93\u5165\uff1aroot = [4,2,6,1,3,5,7], V = 2\n\u8f93\u51fa\uff1a[[2,1],[4,3,6,null,null,5,7]]\n\u89e3\u91ca\uff1a\n\u6ce8\u610f\u6839\u7ed3\u70b9 output[0] \u548c output[1] \u90fd\u662f TreeNode\u00a0\u5bf9\u8c61\uff0c\u4e0d\u662f\u6570\u7ec4\u3002\n\n\u7ed9\u5b9a\u7684\u6811 [4,2,6,1,3,5,7] \u53ef\u5316\u4e3a\u5982\u4e0b\u793a\u610f\u56fe\uff1a\n\n          4\n        /   \\\n      2      6\n     / \\    / \\\n    1   3  5   7\n\n\u8f93\u51fa\u7684\u793a\u610f\u56fe\u5982\u4e0b\uff1a\n\n          4\n        /   \\\n      3      6       \u548c    2\n            / \\           /\n           5   7         1
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. \u4e8c\u53c9\u641c\u7d22\u6811\u8282\u70b9\u4e2a\u6570\u4e0d\u8d85\u8fc7\u00a050\u00a0
  2. \n\t
  3. \u4e8c\u53c9\u641c\u7d22\u6811\u59cb\u7ec8\u662f\u6709\u6548\u7684\uff0c\u5e76\u4e14\u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u90fd\u4e0d\u76f8\u540c
  4. \n
\n", "tags_en": ["Tree", "Recursion"], "tags_cn": ["\u6811", "\u9012\u5f52"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector splitBST(TreeNode* root, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode[] splitBST(TreeNode root, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def splitBST(self, root, target):\n \"\"\"\n :type root: TreeNode\n :type target: int\n :rtype: List[TreeNode]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def splitBST(self, root: TreeNode, target: int) -> List[TreeNode]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nstruct TreeNode** splitBST(struct TreeNode* root, int target, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode[] SplitBST(TreeNode root, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number} target\n * @return {TreeNode[]}\n */\nvar splitBST = function(root, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @param {Integer} target\n# @return {TreeNode[]}\ndef split_bst(root, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func splitBST(_ root: TreeNode?, _ target: Int) -> [TreeNode?] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc splitBST(root *TreeNode, target int) []*TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def splitBST(root: TreeNode, target: Int): Array[TreeNode] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun splitBST(root: TreeNode?, target: Int): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn split_bst(root: Option>>, target: i32) -> Vec>>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param Integer $target\n * @return TreeNode[]\n */\n function splitBST($root, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction splitBST(root: TreeNode | null, target: number): Array {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (split-bst root target)\n (-> (or/c tree-node? #f) exact-integer? (listof (or/c tree-node? #f)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0776](https://leetcode-cn.com/problems/split-bst)", "[\u62c6\u5206\u4e8c\u53c9\u641c\u7d22\u6811](/solution/0700-0799/0776.Split%20BST/README.md)", "`\u6811`,`\u9012\u5f52`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0776](https://leetcode.com/problems/split-bst)", "[Split BST](/solution/0700-0799/0776.Split%20BST/README_EN.md)", "`Tree`,`Recursion`", "Medium", "\ud83d\udd12"]}, {"question_id": "0790", "frontend_question_id": "0775", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/global-and-local-inversions", "url_en": "https://leetcode.com/problems/global-and-local-inversions", "relative_path_cn": "/solution/0700-0799/0775.Global%20and%20Local%20Inversions/README.md", "relative_path_en": "/solution/0700-0799/0775.Global%20and%20Local%20Inversions/README_EN.md", "title_cn": "\u5168\u5c40\u5012\u7f6e\u4e0e\u5c40\u90e8\u5012\u7f6e", "title_en": "Global and Local Inversions", "question_title_slug": "global-and-local-inversions", "content_en": "

You are given an integer array nums of length n which represents a permutation of all the integers in the range [0, n - 1].

\n\n

The number of global inversions is the number of the different pairs (i, j) where:

\n\n
    \n\t
  • 0 <= i < j < n
  • \n\t
  • nums[i] > nums[j]
  • \n
\n\n

The number of local inversions is the number of indices i where:

\n\n
    \n\t
  • 0 <= i < n - 1
  • \n\t
  • nums[i] > nums[i + 1]
  • \n
\n\n

Return true if the number of global inversions is equal to the number of local inversions.

\n\n

 

\n

Example 1:

\n\n
\nInput: nums = [1,0,2]\nOutput: true\nExplanation: There is 1 global inversion and 1 local inversion.\n
\n\n

Example 2:

\n\n
\nInput: nums = [1,2,0]\nOutput: false\nExplanation: There are 2 global inversions and 1 local inversion.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == nums.length
  • \n\t
  • 1 <= n <= 105
  • \n\t
  • 0 <= nums[i] < n
  • \n\t
  • All the integers of nums are unique.
  • \n\t
  • nums is a permutation of all the numbers in the range [0, n - 1].
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u6574\u6570\u6570\u7ec4 nums \uff0c\u8868\u793a\u7531\u8303\u56f4 [0, n - 1] \u5185\u6240\u6709\u6574\u6570\u7ec4\u6210\u7684\u4e00\u4e2a\u6392\u5217\u3002

\n\n

\u5168\u5c40\u5012\u7f6e \u7684\u6570\u76ee\u7b49\u4e8e\u6ee1\u8db3\u4e0b\u8ff0\u6761\u4ef6\u4e0d\u540c\u4e0b\u6807\u5bf9 (i, j) \u7684\u6570\u76ee\uff1a

\n\n
    \n\t
  • 0 <= i < j < n
  • \n\t
  • nums[i] > nums[j]
  • \n
\n\n

\u5c40\u90e8\u5012\u7f6e \u7684\u6570\u76ee\u7b49\u4e8e\u6ee1\u8db3\u4e0b\u8ff0\u6761\u4ef6\u7684\u4e0b\u6807 i \u7684\u6570\u76ee\uff1a

\n\n
    \n\t
  • 0 <= i < n - 1
  • \n\t
  • nums[i] > nums[i + 1]
  • \n
\n\n

\u5f53\u6570\u7ec4 nums \u4e2d \u5168\u5c40\u5012\u7f6e \u7684\u6570\u91cf\u7b49\u4e8e \u5c40\u90e8\u5012\u7f6e \u7684\u6570\u91cf\u65f6\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [1,0,2]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u6709 1 \u4e2a\u5168\u5c40\u5012\u7f6e\uff0c\u548c 1 \u4e2a\u5c40\u90e8\u5012\u7f6e\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1anums = [1,2,0]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u6709 2 \u4e2a\u5168\u5c40\u5012\u7f6e\uff0c\u548c 1 \u4e2a\u5c40\u90e8\u5012\u7f6e\u3002\n
\n\u00a0\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • n == nums.length
  • \n\t
  • 1 <= n <= 5000
  • \n\t
  • 0 <= nums[i] < n
  • \n\t
  • nums \u4e2d\u7684\u6240\u6709\u6574\u6570 \u4e92\u4e0d\u76f8\u540c
  • \n\t
  • nums \u662f\u8303\u56f4 [0, n - 1] \u5185\u6240\u6709\u6570\u5b57\u7ec4\u6210\u7684\u4e00\u4e2a\u6392\u5217
  • \n
\n", "tags_en": ["Array", "Math"], "tags_cn": ["\u6570\u7ec4", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isIdealPermutation(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isIdealPermutation(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isIdealPermutation(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isIdealPermutation(self, nums: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isIdealPermutation(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsIdealPermutation(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {boolean}\n */\nvar isIdealPermutation = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Boolean}\ndef is_ideal_permutation(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isIdealPermutation(_ nums: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isIdealPermutation(nums []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isIdealPermutation(nums: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isIdealPermutation(nums: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_ideal_permutation(nums: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Boolean\n */\n function isIdealPermutation($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isIdealPermutation(nums: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-ideal-permutation nums)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0775](https://leetcode-cn.com/problems/global-and-local-inversions)", "[\u5168\u5c40\u5012\u7f6e\u4e0e\u5c40\u90e8\u5012\u7f6e](/solution/0700-0799/0775.Global%20and%20Local%20Inversions/README.md)", "`\u6570\u7ec4`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0775](https://leetcode.com/problems/global-and-local-inversions)", "[Global and Local Inversions](/solution/0700-0799/0775.Global%20and%20Local%20Inversions/README_EN.md)", "`Array`,`Math`", "Medium", ""]}, {"question_id": "0789", "frontend_question_id": "0703", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/kth-largest-element-in-a-stream", "url_en": "https://leetcode.com/problems/kth-largest-element-in-a-stream", "relative_path_cn": "/solution/0700-0799/0703.Kth%20Largest%20Element%20in%20a%20Stream/README.md", "relative_path_en": "/solution/0700-0799/0703.Kth%20Largest%20Element%20in%20a%20Stream/README_EN.md", "title_cn": "\u6570\u636e\u6d41\u4e2d\u7684\u7b2c K \u5927\u5143\u7d20", "title_en": "Kth Largest Element in a Stream", "question_title_slug": "kth-largest-element-in-a-stream", "content_en": "

Design a class to find the kth largest element in a stream. Note that it is the kth largest element in the sorted order, not the kth distinct element.

\n\n

Implement KthLargest class:

\n\n
    \n\t
  • KthLargest(int k, int[] nums) Initializes the object with the integer k and the stream of integers nums.
  • \n\t
  • int add(int val) Returns the element representing the kth largest element in the stream.
  • \n
\n\n

 

\n

Example 1:

\n\n
\nInput\n["KthLargest", "add", "add", "add", "add", "add"]\n[[3, [4, 5, 8, 2]], [3], [5], [10], [9], [4]]\nOutput\n[null, 4, 5, 5, 8, 8]\n\nExplanation\nKthLargest kthLargest = new KthLargest(3, [4, 5, 8, 2]);\nkthLargest.add(3);   // return 4\nkthLargest.add(5);   // return 5\nkthLargest.add(10);  // return 5\nkthLargest.add(9);   // return 8\nkthLargest.add(4);   // return 8\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= k <= 104
  • \n\t
  • 0 <= nums.length <= 104
  • \n\t
  • -104 <= nums[i] <= 104
  • \n\t
  • -104 <= val <= 104
  • \n\t
  • At most 104 calls will be made to add.
  • \n\t
  • It is guaranteed that there will be at least k elements in the array when you search for the kth element.
  • \n
\n", "content_cn": "

\u8bbe\u8ba1\u4e00\u4e2a\u627e\u5230\u6570\u636e\u6d41\u4e2d\u7b2c k \u5927\u5143\u7d20\u7684\u7c7b\uff08class\uff09\u3002\u6ce8\u610f\u662f\u6392\u5e8f\u540e\u7684\u7b2c k \u5927\u5143\u7d20\uff0c\u4e0d\u662f\u7b2c k \u4e2a\u4e0d\u540c\u7684\u5143\u7d20\u3002

\n\n

\u8bf7\u5b9e\u73b0 KthLargest\u00a0\u7c7b\uff1a

\n\n
    \n\t
  • KthLargest(int k, int[] nums) \u4f7f\u7528\u6574\u6570 k \u548c\u6574\u6570\u6d41 nums \u521d\u59cb\u5316\u5bf9\u8c61\u3002
  • \n\t
  • int add(int val) \u5c06 val \u63d2\u5165\u6570\u636e\u6d41 nums \u540e\uff0c\u8fd4\u56de\u5f53\u524d\u6570\u636e\u6d41\u4e2d\u7b2c k \u5927\u7684\u5143\u7d20\u3002
  • \n
\n\n

\u00a0

\n\n

\u793a\u4f8b\uff1a

\n\n
\n\u8f93\u5165\uff1a\n[\"KthLargest\", \"add\", \"add\", \"add\", \"add\", \"add\"]\n[[3, [4, 5, 8, 2]], [3], [5], [10], [9], [4]]\n\u8f93\u51fa\uff1a\n[null, 4, 5, 5, 8, 8]\n\n\u89e3\u91ca\uff1a\nKthLargest kthLargest = new KthLargest(3, [4, 5, 8, 2]);\nkthLargest.add(3);   // return 4\nkthLargest.add(5);   // return 5\nkthLargest.add(10);  // return 5\nkthLargest.add(9);   // return 8\nkthLargest.add(4);   // return 8\n
\n\n

\u00a0

\n\u63d0\u793a\uff1a\n\n
    \n\t
  • 1 <= k <= 104
  • \n\t
  • 0 <= nums.length <= 104
  • \n\t
  • -104 <= nums[i] <= 104
  • \n\t
  • -104 <= val <= 104
  • \n\t
  • \u6700\u591a\u8c03\u7528 add \u65b9\u6cd5 104 \u6b21
  • \n\t
  • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\uff0c\u5728\u67e5\u627e\u7b2c k \u5927\u5143\u7d20\u65f6\uff0c\u6570\u7ec4\u4e2d\u81f3\u5c11\u6709 k \u4e2a\u5143\u7d20
  • \n
\n", "tags_en": ["Heap", "Design"], "tags_cn": ["\u5806", "\u8bbe\u8ba1"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class KthLargest {\npublic:\n KthLargest(int k, vector& nums) {\n\n }\n \n int add(int val) {\n\n }\n};\n\n/**\n * Your KthLargest object will be instantiated and called as such:\n * KthLargest* obj = new KthLargest(k, nums);\n * int param_1 = obj->add(val);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class KthLargest {\n\n public KthLargest(int k, int[] nums) {\n\n }\n \n public int add(int val) {\n\n }\n}\n\n/**\n * Your KthLargest object will be instantiated and called as such:\n * KthLargest obj = new KthLargest(k, nums);\n * int param_1 = obj.add(val);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class KthLargest(object):\n\n def __init__(self, k, nums):\n \"\"\"\n :type k: int\n :type nums: List[int]\n \"\"\"\n\n\n def add(self, val):\n \"\"\"\n :type val: int\n :rtype: int\n \"\"\"\n\n\n\n# Your KthLargest object will be instantiated and called as such:\n# obj = KthLargest(k, nums)\n# param_1 = obj.add(val)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class KthLargest:\n\n def __init__(self, k: int, nums: List[int]):\n\n\n def add(self, val: int) -> int:\n\n\n\n# Your KthLargest object will be instantiated and called as such:\n# obj = KthLargest(k, nums)\n# param_1 = obj.add(val)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} KthLargest;\n\n\nKthLargest* kthLargestCreate(int k, int* nums, int numsSize) {\n\n}\n\nint kthLargestAdd(KthLargest* obj, int val) {\n\n}\n\nvoid kthLargestFree(KthLargest* obj) {\n\n}\n\n/**\n * Your KthLargest struct will be instantiated and called as such:\n * KthLargest* obj = kthLargestCreate(k, nums, numsSize);\n * int param_1 = kthLargestAdd(obj, val);\n \n * kthLargestFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class KthLargest {\n\n public KthLargest(int k, int[] nums) {\n\n }\n \n public int Add(int val) {\n\n }\n}\n\n/**\n * Your KthLargest object will be instantiated and called as such:\n * KthLargest obj = new KthLargest(k, nums);\n * int param_1 = obj.Add(val);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} k\n * @param {number[]} nums\n */\nvar KthLargest = function(k, nums) {\n\n};\n\n/** \n * @param {number} val\n * @return {number}\n */\nKthLargest.prototype.add = function(val) {\n\n};\n\n/**\n * Your KthLargest object will be instantiated and called as such:\n * var obj = new KthLargest(k, nums)\n * var param_1 = obj.add(val)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class KthLargest\n\n=begin\n :type k: Integer\n :type nums: Integer[]\n=end\n def initialize(k, nums)\n\n end\n\n\n=begin\n :type val: Integer\n :rtype: Integer\n=end\n def add(val)\n\n end\n\n\nend\n\n# Your KthLargest object will be instantiated and called as such:\n# obj = KthLargest.new(k, nums)\n# param_1 = obj.add(val)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass KthLargest {\n\n init(_ k: Int, _ nums: [Int]) {\n\n }\n \n func add(_ val: Int) -> Int {\n\n }\n}\n\n/**\n * Your KthLargest object will be instantiated and called as such:\n * let obj = KthLargest(k, nums)\n * let ret_1: Int = obj.add(val)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type KthLargest struct {\n\n}\n\n\nfunc Constructor(k int, nums []int) KthLargest {\n\n}\n\n\nfunc (this *KthLargest) Add(val int) int {\n\n}\n\n\n/**\n * Your KthLargest object will be instantiated and called as such:\n * obj := Constructor(k, nums);\n * param_1 := obj.Add(val);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class KthLargest(_k: Int, _nums: Array[Int]) {\n\n def add(`val`: Int): Int = {\n\n }\n\n}\n\n/**\n * Your KthLargest object will be instantiated and called as such:\n * var obj = new KthLargest(k, nums)\n * var param_1 = obj.add(`val`)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class KthLargest(k: Int, nums: IntArray) {\n\n fun add(`val`: Int): Int {\n\n }\n\n}\n\n/**\n * Your KthLargest object will be instantiated and called as such:\n * var obj = KthLargest(k, nums)\n * var param_1 = obj.add(`val`)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct KthLargest {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl KthLargest {\n\n fn new(k: i32, nums: Vec) -> Self {\n\n }\n \n fn add(&self, val: i32) -> i32 {\n\n }\n}\n\n/**\n * Your KthLargest object will be instantiated and called as such:\n * let obj = KthLargest::new(k, nums);\n * let ret_1: i32 = obj.add(val);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class KthLargest {\n /**\n * @param Integer $k\n * @param Integer[] $nums\n */\n function __construct($k, $nums) {\n\n }\n\n /**\n * @param Integer $val\n * @return Integer\n */\n function add($val) {\n\n }\n}\n\n/**\n * Your KthLargest object will be instantiated and called as such:\n * $obj = KthLargest($k, $nums);\n * $ret_1 = $obj->add($val);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class KthLargest {\n constructor(k: number, nums: number[]) {\n\n }\n\n add(val: number): number {\n\n }\n}\n\n/**\n * Your KthLargest object will be instantiated and called as such:\n * var obj = new KthLargest(k, nums)\n * var param_1 = obj.add(val)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define kth-largest%\n (class object%\n (super-new)\n\n ; k : exact-integer?\n\n ; nums : (listof exact-integer?)\n (init-field\n k\n nums)\n \n ; add : exact-integer? -> exact-integer?\n (define/public (add val)\n\n )))\n\n;; Your kth-largest% object will be instantiated and called as such:\n;; (define obj (new kth-largest% [k k] [nums nums]))\n;; (define param_1 (send obj add val))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0703](https://leetcode-cn.com/problems/kth-largest-element-in-a-stream)", "[\u6570\u636e\u6d41\u4e2d\u7684\u7b2c K \u5927\u5143\u7d20](/solution/0700-0799/0703.Kth%20Largest%20Element%20in%20a%20Stream/README.md)", "`\u5806`,`\u8bbe\u8ba1`", "\u7b80\u5355", ""], "md_table_row_en": ["[0703](https://leetcode.com/problems/kth-largest-element-in-a-stream)", "[Kth Largest Element in a Stream](/solution/0700-0799/0703.Kth%20Largest%20Element%20in%20a%20Stream/README_EN.md)", "`Heap`,`Design`", "Easy", ""]}, {"question_id": "0788", "frontend_question_id": "0774", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/minimize-max-distance-to-gas-station", "url_en": "https://leetcode.com/problems/minimize-max-distance-to-gas-station", "relative_path_cn": "/solution/0700-0799/0774.Minimize%20Max%20Distance%20to%20Gas%20Station/README.md", "relative_path_en": "/solution/0700-0799/0774.Minimize%20Max%20Distance%20to%20Gas%20Station/README_EN.md", "title_cn": "\u6700\u5c0f\u5316\u53bb\u52a0\u6cb9\u7ad9\u7684\u6700\u5927\u8ddd\u79bb", "title_en": "Minimize Max Distance to Gas Station", "question_title_slug": "minimize-max-distance-to-gas-station", "content_en": "

You are given an integer array stations that represents the positions of the gas stations on the x-axis. You are also given an integer k.

\n\n

You should add k new gas stations. You can add the stations anywhere on the x-axis, and not necessarily on an integer position.

\n\n

Let penalty() be the maximum distance between adjacent gas stations after adding the k new stations.

\n\n

Return the smallest possible value of penalty(). Answers within 10-6 of the actual answer will be accepted.

\n\n

 

\n

Example 1:

\n
Input: stations = [1,2,3,4,5,6,7,8,9,10], k = 9\nOutput: 0.50000\n

Example 2:

\n
Input: stations = [23,24,36,39,46,56,57,65,84,98], k = 1\nOutput: 14.00000\n
\n

 

\n

Constraints:

\n\n
    \n\t
  • 10 <= stations.length <= 2000
  • \n\t
  • 0 <= stations[i] <= 108
  • \n\t
  • stations is sorted in a strictly increasing order.
  • \n\t
  • 1 <= k <= 106
  • \n
\n", "content_cn": "

\u6574\u6570\u6570\u7ec4 stations \u8868\u793a \u6c34\u5e73\u6570\u8f74 \u4e0a\u5404\u4e2a\u52a0\u6cb9\u7ad9\u7684\u4f4d\u7f6e\u3002\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 k \u3002

\n\n

\u8bf7\u4f60\u5728\u6570\u8f74\u4e0a\u589e\u8bbe k \u4e2a\u52a0\u6cb9\u7ad9\uff0c\u65b0\u589e\u52a0\u6cb9\u7ad9\u53ef\u4ee5\u4f4d\u4e8e \u6c34\u5e73\u6570\u8f74 \u4e0a\u7684\u4efb\u610f\u4f4d\u7f6e\uff0c\u800c\u4e0d\u5fc5\u653e\u5728\u6574\u6570\u4f4d\u7f6e\u4e0a\u3002

\n\n

\u8bbe penalty() \u662f\uff1a\u589e\u8bbe k \u4e2a\u65b0\u52a0\u6cb9\u7ad9\u540e\uff0c\u76f8\u90bb \u4e24\u4e2a\u52a0\u6cb9\u7ad9\u95f4\u7684\u6700\u5927\u8ddd\u79bb\u3002

\n\u8bf7\u4f60\u8fd4\u56de\u00a0penalty() \u53ef\u80fd\u7684\u6700\u5c0f\u503c\u3002\u4e0e\u5b9e\u9645\u7b54\u6848\u8bef\u5dee\u5728 10-6 \u8303\u56f4\u5185\u7684\u7b54\u6848\u5c06\u88ab\u89c6\u4f5c\u6b63\u786e\u7b54\u6848\u3002\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1astations = [1,2,3,4,5,6,7,8,9,10], k = 9\n\u8f93\u51fa\uff1a0.50000\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1astations = [23,24,36,39,46,56,57,65,84,98], k = 1\n\u8f93\u51fa\uff1a14.00000\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 10 <= stations.length <= 2000
  • \n\t
  • 0 <= stations[i] <= 108
  • \n\t
  • stations \u6309 \u4e25\u683c\u9012\u589e \u987a\u5e8f\u6392\u5217
  • \n\t
  • 1 <= k <= 106
  • \n
\n", "tags_en": ["Binary Search"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n double minmaxGasDist(vector& stations, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double minmaxGasDist(int[] stations, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minmaxGasDist(self, stations, k):\n \"\"\"\n :type stations: List[int]\n :type k: int\n :rtype: float\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minmaxGasDist(self, stations: List[int], k: int) -> float:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\ndouble minmaxGasDist(int* stations, int stationsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double MinmaxGasDist(int[] stations, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} stations\n * @param {number} k\n * @return {number}\n */\nvar minmaxGasDist = function(stations, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} stations\n# @param {Integer} k\n# @return {Float}\ndef minmax_gas_dist(stations, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minmaxGasDist(_ stations: [Int], _ k: Int) -> Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minmaxGasDist(stations []int, k int) float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minmaxGasDist(stations: Array[Int], k: Int): Double = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minmaxGasDist(stations: IntArray, k: Int): Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minmax_gas_dist(stations: Vec, k: i32) -> f64 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $stations\n * @param Integer $k\n * @return Float\n */\n function minmaxGasDist($stations, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minmaxGasDist(stations: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minmax-gas-dist stations k)\n (-> (listof exact-integer?) exact-integer? flonum?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0774](https://leetcode-cn.com/problems/minimize-max-distance-to-gas-station)", "[\u6700\u5c0f\u5316\u53bb\u52a0\u6cb9\u7ad9\u7684\u6700\u5927\u8ddd\u79bb](/solution/0700-0799/0774.Minimize%20Max%20Distance%20to%20Gas%20Station/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0774](https://leetcode.com/problems/minimize-max-distance-to-gas-station)", "[Minimize Max Distance to Gas Station](/solution/0700-0799/0774.Minimize%20Max%20Distance%20to%20Gas%20Station/README_EN.md)", "`Binary Search`", "Hard", "\ud83d\udd12"]}, {"question_id": "0787", "frontend_question_id": "0773", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sliding-puzzle", "url_en": "https://leetcode.com/problems/sliding-puzzle", "relative_path_cn": "/solution/0700-0799/0773.Sliding%20Puzzle/README.md", "relative_path_en": "/solution/0700-0799/0773.Sliding%20Puzzle/README_EN.md", "title_cn": "\u6ed1\u52a8\u8c1c\u9898", "title_en": "Sliding Puzzle", "question_title_slug": "sliding-puzzle", "content_en": "

On a 2x3 board, there are 5 tiles represented by the integers 1 through 5, and an empty square represented by 0.

\r\n\r\n

A move consists of choosing 0 and a 4-directionally adjacent number and swapping it.

\r\n\r\n

The state of the board is solved if and only if the board is [[1,2,3],[4,5,0]].

\r\n\r\n

Given a puzzle board, return the least number of moves required so that the state of the board is solved. If it is impossible for the state of the board to be solved, return -1.

\r\n\r\n

Examples:

\r\n\r\n
\r\nInput: board = [[1,2,3],[4,0,5]]\r\nOutput: 1\r\nExplanation: Swap the 0 and the 5 in one move.\r\n
\r\n\r\n
\r\nInput: board = [[1,2,3],[5,4,0]]\r\nOutput: -1\r\nExplanation: No number of moves will make the board solved.\r\n
\r\n\r\n
\r\nInput: board = [[4,1,2],[5,0,3]]\r\nOutput: 5\r\nExplanation: 5 is the smallest number of moves that solves the board.\r\nAn example path:\r\nAfter move 0: [[4,1,2],[5,0,3]]\r\nAfter move 1: [[4,1,2],[0,5,3]]\r\nAfter move 2: [[0,1,2],[4,5,3]]\r\nAfter move 3: [[1,0,2],[4,5,3]]\r\nAfter move 4: [[1,2,0],[4,5,3]]\r\nAfter move 5: [[1,2,3],[4,5,0]]\r\n
\r\n\r\n
\r\nInput: board = [[3,2,4],[1,5,0]]\r\nOutput: 14\r\n
\r\n\r\n

Note:

\r\n\r\n
    \r\n\t
  • board will be a 2 x 3 array as described above.
  • \r\n\t
  • board[i][j] will be a permutation of [0, 1, 2, 3, 4, 5].
  • \r\n
\r\n", "content_cn": "

\u5728\u4e00\u4e2a 2 x 3 \u7684\u677f\u4e0a\uff08board\uff09\u6709 5 \u5757\u7816\u74e6\uff0c\u7528\u6570\u5b57 1~5 \u6765\u8868\u793a, \u4ee5\u53ca\u4e00\u5757\u7a7a\u7f3a\u7528 0 \u6765\u8868\u793a.

\n\n

\u4e00\u6b21\u79fb\u52a8\u5b9a\u4e49\u4e3a\u9009\u62e9 0 \u4e0e\u4e00\u4e2a\u76f8\u90bb\u7684\u6570\u5b57\uff08\u4e0a\u4e0b\u5de6\u53f3\uff09\u8fdb\u884c\u4ea4\u6362.

\n\n

\u6700\u7ec8\u5f53\u677f board \u7684\u7ed3\u679c\u662f [[1,2,3],[4,5,0]] \u8c1c\u677f\u88ab\u89e3\u5f00\u3002

\n\n

\u7ed9\u51fa\u4e00\u4e2a\u8c1c\u677f\u7684\u521d\u59cb\u72b6\u6001\uff0c\u8fd4\u56de\u6700\u5c11\u53ef\u4ee5\u901a\u8fc7\u591a\u5c11\u6b21\u79fb\u52a8\u89e3\u5f00\u8c1c\u677f\uff0c\u5982\u679c\u4e0d\u80fd\u89e3\u5f00\u8c1c\u677f\uff0c\u5219\u8fd4\u56de -1 \u3002

\n\n

\u793a\u4f8b\uff1a

\n\n
\n\u8f93\u5165\uff1aboard = [[1,2,3],[4,0,5]]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u4ea4\u6362 0 \u548c 5 \uff0c1 \u6b65\u5b8c\u6210\n
\n\n
\n\u8f93\u5165\uff1aboard = [[1,2,3],[5,4,0]]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u6ca1\u6709\u529e\u6cd5\u5b8c\u6210\u8c1c\u677f\n
\n\n
\n\u8f93\u5165\uff1aboard = [[4,1,2],[5,0,3]]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\n\u6700\u5c11\u5b8c\u6210\u8c1c\u677f\u7684\u6700\u5c11\u79fb\u52a8\u6b21\u6570\u662f 5 \uff0c\n\u4e00\u79cd\u79fb\u52a8\u8def\u5f84:\n\u5c1a\u672a\u79fb\u52a8: [[4,1,2],[5,0,3]]\n\u79fb\u52a8 1 \u6b21: [[4,1,2],[0,5,3]]\n\u79fb\u52a8 2 \u6b21: [[0,1,2],[4,5,3]]\n\u79fb\u52a8 3 \u6b21: [[1,0,2],[4,5,3]]\n\u79fb\u52a8 4 \u6b21: [[1,2,0],[4,5,3]]\n\u79fb\u52a8 5 \u6b21: [[1,2,3],[4,5,0]]\n
\n\n
\n\u8f93\u5165\uff1aboard = [[3,2,4],[1,5,0]]\n\u8f93\u51fa\uff1a14\n
\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • board \u662f\u4e00\u4e2a\u5982\u4e0a\u6240\u8ff0\u7684 2 x 3 \u7684\u6570\u7ec4.
  • \n\t
  • board[i][j] \u662f\u4e00\u4e2a [0, 1, 2, 3, 4, 5] \u7684\u6392\u5217.
  • \n
\n", "tags_en": ["Breadth-first Search"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int slidingPuzzle(vector>& board) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int slidingPuzzle(int[][] board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def slidingPuzzle(self, board):\n \"\"\"\n :type board: List[List[int]]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def slidingPuzzle(self, board: List[List[int]]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint slidingPuzzle(int** board, int boardSize, int* boardColSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SlidingPuzzle(int[][] board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} board\n * @return {number}\n */\nvar slidingPuzzle = function(board) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} board\n# @return {Integer}\ndef sliding_puzzle(board)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func slidingPuzzle(_ board: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func slidingPuzzle(board [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def slidingPuzzle(board: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun slidingPuzzle(board: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sliding_puzzle(board: Vec>) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $board\n * @return Integer\n */\n function slidingPuzzle($board) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function slidingPuzzle(board: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (sliding-puzzle board)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0773](https://leetcode-cn.com/problems/sliding-puzzle)", "[\u6ed1\u52a8\u8c1c\u9898](/solution/0700-0799/0773.Sliding%20Puzzle/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[0773](https://leetcode.com/problems/sliding-puzzle)", "[Sliding Puzzle](/solution/0700-0799/0773.Sliding%20Puzzle/README_EN.md)", "`Breadth-first Search`", "Hard", ""]}, {"question_id": "0786", "frontend_question_id": "0702", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/search-in-a-sorted-array-of-unknown-size", "url_en": "https://leetcode.com/problems/search-in-a-sorted-array-of-unknown-size", "relative_path_cn": "/solution/0700-0799/0702.Search%20in%20a%20Sorted%20Array%20of%20Unknown%20Size/README.md", "relative_path_en": "/solution/0700-0799/0702.Search%20in%20a%20Sorted%20Array%20of%20Unknown%20Size/README_EN.md", "title_cn": "\u641c\u7d22\u957f\u5ea6\u672a\u77e5\u7684\u6709\u5e8f\u6570\u7ec4", "title_en": "Search in a Sorted Array of Unknown Size", "question_title_slug": "search-in-a-sorted-array-of-unknown-size", "content_en": "

Given an integer array sorted in ascending order, write a function to search target in nums.  If target exists, then return its index, otherwise return -1. However, the array size is unknown to you. You may only access the array using an ArrayReader interface, where ArrayReader.get(k) returns the element of the array at index k (0-indexed).

\n\n

You may assume all integers in the array are less than 10000, and if you access the array out of bounds, ArrayReader.get will return 2147483647.

\n\n

You must write an algorithm with O(log n) runtime complexity.

\n\n

 

\n\n

Example 1:

\n\n
\nInput: array = [-1,0,3,5,9,12], target = 9\nOutput: 4\nExplanation: 9 exists in nums and its index is 4\n
\n\n

Example 2:

\n\n
\nInput: array = [-1,0,3,5,9,12], target = 2\nOutput: -1\nExplanation: 2 does not exist in nums so return -1\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • You may assume that all elements in the array are unique.
  • \n\t
  • The value of each element in the array will be in the range [-9999, 9999].
  • \n\t
  • The length of the array will be in the range [1, 10^4].
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u5347\u5e8f\u6574\u6570\u6570\u7ec4\uff0c\u5199\u4e00\u4e2a\u51fd\u6570\u641c\u7d22 nums \u4e2d\u6570\u5b57 target\u3002\u5982\u679c target \u5b58\u5728\uff0c\u8fd4\u56de\u5b83\u7684\u4e0b\u6807\uff0c\u5426\u5219\u8fd4\u56de -1\u3002\u6ce8\u610f\uff0c\u8fd9\u4e2a\u6570\u7ec4\u7684\u5927\u5c0f\u662f\u672a\u77e5\u7684\u3002\u4f60\u53ea\u53ef\u4ee5\u901a\u8fc7 ArrayReader \u63a5\u53e3\u8bbf\u95ee\u8fd9\u4e2a\u6570\u7ec4\uff0cArrayReader.get(k) \u8fd4\u56de\u6570\u7ec4\u4e2d\u7b2c k \u4e2a\u5143\u7d20\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\u3002

\n\n

\u4f60\u53ef\u4ee5\u8ba4\u4e3a\u6570\u7ec4\u4e2d\u6240\u6709\u7684\u6574\u6570\u90fd\u5c0f\u4e8e 10000\u3002\u5982\u679c\u4f60\u8bbf\u95ee\u6570\u7ec4\u8d8a\u754c\uff0cArrayReader.get \u4f1a\u8fd4\u56de 2147483647\u3002

\n\n

 

\n\n

\u6837\u4f8b 1\uff1a

\n\n
\u8f93\u5165: array = [-1,0,3,5,9,12], target = 9\n\u8f93\u51fa: 4\n\u89e3\u91ca: 9 \u5b58\u5728\u5728 nums \u4e2d\uff0c\u4e0b\u6807\u4e3a 4\n
\n\n

\u6837\u4f8b 2\uff1a

\n\n
\u8f93\u5165: array = [-1,0,3,5,9,12], target = 2\n\u8f93\u51fa: -1\n\u89e3\u91ca: 2 \u4e0d\u5728\u6570\u7ec4\u4e2d\u6240\u4ee5\u8fd4\u56de -1
\n\n

 

\n\n

\u6ce8\u91ca \uff1a

\n\n
    \n\t
  1. \u4f60\u53ef\u4ee5\u8ba4\u4e3a\u6570\u7ec4\u4e2d\u6240\u6709\u5143\u7d20\u7684\u503c\u4e92\u4e0d\u76f8\u540c\u3002
  2. \n\t
  3. \u6570\u7ec4\u5143\u7d20\u7684\u503c\u57df\u662f [-9999, 9999]\u3002
  4. \n
\n", "tags_en": ["Binary Search"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * // This is the ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * class ArrayReader {\n * public:\n * int get(int index);\n * };\n */\n\nclass Solution {\npublic:\n int search(const ArrayReader& reader, int target) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * // This is ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * interface ArrayReader {\n * public int get(int index) {}\n * }\n */\n\nclass Solution {\n public int search(ArrayReader reader, int target) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# \"\"\"\n# This is ArrayReader's API interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class ArrayReader(object):\n# def get(self, index):\n# \"\"\"\n# :type index: int\n# :rtype int\n# \"\"\"\n\nclass Solution(object):\n def search(self, reader, target):\n \"\"\"\n :type reader: ArrayReader\n :type target: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# \"\"\"\n# This is ArrayReader's API interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class ArrayReader:\n# def get(self, index: int) -> int:\n\nclass Solution:\n def search(self, reader, target):\n \"\"\"\n :type reader: ArrayReader\n :type target: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * *********************************************************************\n * // This is the ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * *********************************************************************\n *\n * int getElement(ArrayReader *, int index);\n */\n\nint search(struct ArrayReader* reader, int target) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * // This is ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * class ArrayReader {\n * public int Get(int index) {}\n * }\n */\n\nclass Solution {\n public int Search(ArrayReader reader, int target) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // This is the ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * function ArrayReader() {\n *\n * @param {number} index\n * @return {number}\n * this.get = function(index) {\n * ...\n * };\n * };\n */\n\n/**\n * @param {ArrayReader} reader\n * @param {number} target\n * @return {number}\n */\nvar search = function (reader, target) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# This is ArrayReader's API interface.\n# You should not implement it, or speculate about its implementation\n# class ArrayReader\n# def get(index)\n#\t\t\n# end\n# end\n\n# @param {ArrayReader} reader\n# @param {int} target\n# @return {int}\ndef search(reader, target)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * // This is ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * public class ArrayReader {\n * public func get(_ index: Int) -> Int {}\n * }\n */\n\nclass Solution {\n func search(_ reader: ArrayReader, _ target: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * // This is the ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * type ArrayReader struct {\n * }\n *\n * func (this *ArrayReader) get(index int) int {}\n */\n\nfunc search(reader ArrayReader, target int) int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * // This is ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * class ArrayReader {\n * def get(index: Int): Int = {}\n * }\n */\n\nobject Solution {\n def search(reader: ArrayReader, target: Int): Int = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * // This is ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * class ArrayReader {\n * fun get(index: Int): Int {}\n * }\n */\n\nclass Solution {\n fun search(reader: ArrayReader, target: Int): Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * // This is ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * class ArrayReader {\n * function get($index) {}\n * }\n */\n\nclass Solution {\n /**\n * @param ArrayReader $reader\n * @param Integer $target\n * @return Integer\n */\n function search($reader, $target) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * class ArrayReader {\n *\t\t// This is the ArrayReader's API interface.\n *\t\t// You should not implement it, or speculate about its implementation\n *\t\tget(index: number): number {};\n * };\n */\n\nfunction search(reader: ArrayReader, target: number): number {\n\t\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0702](https://leetcode-cn.com/problems/search-in-a-sorted-array-of-unknown-size)", "[\u641c\u7d22\u957f\u5ea6\u672a\u77e5\u7684\u6709\u5e8f\u6570\u7ec4](/solution/0700-0799/0702.Search%20in%20a%20Sorted%20Array%20of%20Unknown%20Size/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0702](https://leetcode.com/problems/search-in-a-sorted-array-of-unknown-size)", "[Search in a Sorted Array of Unknown Size](/solution/0700-0799/0702.Search%20in%20a%20Sorted%20Array%20of%20Unknown%20Size/README_EN.md)", "`Binary Search`", "Medium", "\ud83d\udd12"]}, {"question_id": "0785", "frontend_question_id": "0772", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/basic-calculator-iii", "url_en": "https://leetcode.com/problems/basic-calculator-iii", "relative_path_cn": "/solution/0700-0799/0772.Basic%20Calculator%20III/README.md", "relative_path_en": "/solution/0700-0799/0772.Basic%20Calculator%20III/README_EN.md", "title_cn": "\u57fa\u672c\u8ba1\u7b97\u5668 III", "title_en": "Basic Calculator III", "question_title_slug": "basic-calculator-iii", "content_en": "

Implement a basic calculator to evaluate a simple expression string.

\n\n

The expression string contains only non-negative integers, '+', '-', '*', '/' operators, and open '(' and closing parentheses ')'. The integer division should truncate toward zero.

\n\n

You may assume that the given expression is always valid. All intermediate results will be in the range of [-231, 231 - 1].

\n\n

Note: You are not allowed to use any built-in function which evaluates strings as mathematical expressions, such as eval().

\n\n

 

\n

Example 1:

\n\n
\nInput: s = "1+1"\nOutput: 2\n
\n\n

Example 2:

\n\n
\nInput: s = "6-4/2"\nOutput: 4\n
\n\n

Example 3:

\n\n
\nInput: s = "2*(5+5*2)/3+(6/2+8)"\nOutput: 21\n
\n\n

Example 4:

\n\n
\nInput: s = "(2+6*3+5-(3*14/7+2)*5)+3"\nOutput: -12\n
\n\n

Example 5:

\n\n
\nInput: s = "0"\nOutput: 0\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s <= 104
  • \n\t
  • s consists of digits, '+', '-', '*', '/', '(', and ')'.
  • \n\t
  • s is a valid expression.
  • \n
\n", "content_cn": "

\u5b9e\u73b0\u4e00\u4e2a\u57fa\u672c\u7684\u8ba1\u7b97\u5668\u6765\u8ba1\u7b97\u7b80\u5355\u7684\u8868\u8fbe\u5f0f\u5b57\u7b26\u4e32\u3002

\n\n

\u8868\u8fbe\u5f0f\u5b57\u7b26\u4e32\u53ea\u5305\u542b\u975e\u8d1f\u6574\u6570\uff0c\u7b97\u7b26 +\u3001-\u3001*\u3001/ \uff0c\u5de6\u62ec\u53f7 ( \u548c\u53f3\u62ec\u53f7 ) \u3002\u6574\u6570\u9664\u6cd5\u9700\u8981 \u5411\u4e0b\u622a\u65ad \u3002

\n\n

\u4f60\u53ef\u4ee5\u5047\u5b9a\u7ed9\u5b9a\u7684\u8868\u8fbe\u5f0f\u603b\u662f\u6709\u6548\u7684\u3002\u6240\u6709\u7684\u4e2d\u95f4\u7ed3\u679c\u7684\u8303\u56f4\u4e3a [-231, 231 - 1] \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"1+1\"\n\u8f93\u51fa\uff1a2\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"6-4/2\"\n\u8f93\u51fa\uff1a4\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"2*(5+5*2)/3+(6/2+8)\"\n\u8f93\u51fa\uff1a21\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"(2+6*3+5-(3*14/7+2)*5)+3\"\n\u8f93\u51fa\uff1a-12\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\n\u8f93\u5165\uff1as = \"0\"\n\u8f93\u51fa\uff1a0\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • 1 <= s <= 104
  • \n\t
  • s \u7531\u6574\u6570\u3001'+'\u3001'-'\u3001'*'\u3001'/'\u3001'(' \u548c ')' \u7ec4\u6210
  • \n\t
  • s \u662f\u4e00\u4e2a \u6709\u6548\u7684 \u8868\u8fbe\u5f0f
  • \n
\n\n

\u00a0

\n\n

\u8fdb\u9636\uff1a\u4f60\u53ef\u4ee5\u5728\u4e0d\u4f7f\u7528\u5185\u7f6e\u5e93\u51fd\u6570\u7684\u60c5\u51b5\u4e0b\u89e3\u51b3\u6b64\u95ee\u9898\u5417\uff1f

\n", "tags_en": ["Stack", "String"], "tags_cn": ["\u6808", "\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int calculate(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int calculate(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def calculate(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def calculate(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint calculate(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int Calculate(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar calculate = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef calculate(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func calculate(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func calculate(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def calculate(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun calculate(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn calculate(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function calculate($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function calculate(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (calculate s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0772](https://leetcode-cn.com/problems/basic-calculator-iii)", "[\u57fa\u672c\u8ba1\u7b97\u5668 III](/solution/0700-0799/0772.Basic%20Calculator%20III/README.md)", "`\u6808`,`\u5b57\u7b26\u4e32`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0772](https://leetcode.com/problems/basic-calculator-iii)", "[Basic Calculator III](/solution/0700-0799/0772.Basic%20Calculator%20III/README_EN.md)", "`Stack`,`String`", "Hard", "\ud83d\udd12"]}, {"question_id": "0784", "frontend_question_id": "0701", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/insert-into-a-binary-search-tree", "url_en": "https://leetcode.com/problems/insert-into-a-binary-search-tree", "relative_path_cn": "/solution/0700-0799/0701.Insert%20into%20a%20Binary%20Search%20Tree/README.md", "relative_path_en": "/solution/0700-0799/0701.Insert%20into%20a%20Binary%20Search%20Tree/README_EN.md", "title_cn": "\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u7684\u63d2\u5165\u64cd\u4f5c", "title_en": "Insert into a Binary Search Tree", "question_title_slug": "insert-into-a-binary-search-tree", "content_en": "

You are given the root node of a binary search tree (BST) and a value to insert into the tree. Return the root node of the BST after the insertion. It is guaranteed that the new value does not exist in the original BST.

\n\n

Notice that there may exist multiple valid ways for the insertion, as long as the tree remains a BST after insertion. You can return any of them.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: root = [4,2,7,1,3], val = 5\nOutput: [4,2,7,1,3,5]\nExplanation: Another accepted tree is:\n\"\"\n
\n\n

Example 2:

\n\n
\nInput: root = [40,20,60,10,30,50,70], val = 25\nOutput: [40,20,60,10,30,50,70,null,null,25]\n
\n\n

Example 3:

\n\n
\nInput: root = [4,2,7,1,3,null,null,null,null,null,null], val = 5\nOutput: [4,2,7,1,3,5]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The number of nodes in the tree will be in the range [0, 104].
  • \n\t
  • -108 <= Node.val <= 108
  • \n\t
  • All the values Node.val are unique.
  • \n\t
  • -108 <= val <= 108
  • \n\t
  • It's guaranteed that val does not exist in the original BST.
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e8c\u53c9\u641c\u7d22\u6811\uff08BST\uff09\u7684\u6839\u8282\u70b9\u548c\u8981\u63d2\u5165\u6811\u4e2d\u7684\u503c\uff0c\u5c06\u503c\u63d2\u5165\u4e8c\u53c9\u641c\u7d22\u6811\u3002 \u8fd4\u56de\u63d2\u5165\u540e\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6839\u8282\u70b9\u3002 \u8f93\u5165\u6570\u636e \u4fdd\u8bc1 \uff0c\u65b0\u503c\u548c\u539f\u59cb\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u7684\u4efb\u610f\u8282\u70b9\u503c\u90fd\u4e0d\u540c\u3002

\n\n

\u6ce8\u610f\uff0c\u53ef\u80fd\u5b58\u5728\u591a\u79cd\u6709\u6548\u7684\u63d2\u5165\u65b9\u5f0f\uff0c\u53ea\u8981\u6811\u5728\u63d2\u5165\u540e\u4ecd\u4fdd\u6301\u4e3a\u4e8c\u53c9\u641c\u7d22\u6811\u5373\u53ef\u3002 \u4f60\u53ef\u4ee5\u8fd4\u56de \u4efb\u610f\u6709\u6548\u7684\u7ed3\u679c \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1aroot = [4,2,7,1,3], val = 5\n\u8f93\u51fa\uff1a[4,2,7,1,3,5]\n\u89e3\u91ca\uff1a\u53e6\u4e00\u4e2a\u6ee1\u8db3\u9898\u76ee\u8981\u6c42\u53ef\u4ee5\u901a\u8fc7\u7684\u6811\u662f\uff1a\n\"\"\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aroot = [40,20,60,10,30,50,70], val = 25\n\u8f93\u51fa\uff1a[40,20,60,10,30,50,70,null,null,25]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1aroot = [4,2,7,1,3,null,null,null,null,null,null], val = 5\n\u8f93\u51fa\uff1a[4,2,7,1,3,5]\n
\n\n

\u00a0

\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u7ed9\u5b9a\u7684\u6811\u4e0a\u7684\u8282\u70b9\u6570\u4ecb\u4e8e 0 \u548c 10^4 \u4e4b\u95f4
  • \n\t
  • \u6bcf\u4e2a\u8282\u70b9\u90fd\u6709\u4e00\u4e2a\u552f\u4e00\u6574\u6570\u503c\uff0c\u53d6\u503c\u8303\u56f4\u4ece 0 \u5230 10^8
  • \n\t
  • -10^8 <= val <= 10^8
  • \n\t
  • \u65b0\u503c\u548c\u539f\u59cb\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u7684\u4efb\u610f\u8282\u70b9\u503c\u90fd\u4e0d\u540c
  • \n
\n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* insertIntoBST(TreeNode* root, int val) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode insertIntoBST(TreeNode root, int val) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def insertIntoBST(self, root, val):\n \"\"\"\n :type root: TreeNode\n :type val: int\n :rtype: TreeNode\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def insertIntoBST(self, root: TreeNode, val: int) -> TreeNode:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* insertIntoBST(struct TreeNode* root, int val){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode InsertIntoBST(TreeNode root, int val) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number} val\n * @return {TreeNode}\n */\nvar insertIntoBST = function(root, val) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @param {Integer} val\n# @return {TreeNode}\ndef insert_into_bst(root, val)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func insertIntoBST(_ root: TreeNode?, _ val: Int) -> TreeNode? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc insertIntoBST(root *TreeNode, val int) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def insertIntoBST(root: TreeNode, `val`: Int): TreeNode = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun insertIntoBST(root: TreeNode?, `val`: Int): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn insert_into_bst(root: Option>>, val: i32) -> Option>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param Integer $val\n * @return TreeNode\n */\n function insertIntoBST($root, $val) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction insertIntoBST(root: TreeNode | null, val: number): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (insert-into-bst root val)\n (-> (or/c tree-node? #f) exact-integer? (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0701](https://leetcode-cn.com/problems/insert-into-a-binary-search-tree)", "[\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u7684\u63d2\u5165\u64cd\u4f5c](/solution/0700-0799/0701.Insert%20into%20a%20Binary%20Search%20Tree/README.md)", "`\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0701](https://leetcode.com/problems/insert-into-a-binary-search-tree)", "[Insert into a Binary Search Tree](/solution/0700-0799/0701.Insert%20into%20a%20Binary%20Search%20Tree/README_EN.md)", "`Tree`", "Medium", ""]}, {"question_id": "0783", "frontend_question_id": "0700", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/search-in-a-binary-search-tree", "url_en": "https://leetcode.com/problems/search-in-a-binary-search-tree", "relative_path_cn": "/solution/0700-0799/0700.Search%20in%20a%20Binary%20Search%20Tree/README.md", "relative_path_en": "/solution/0700-0799/0700.Search%20in%20a%20Binary%20Search%20Tree/README_EN.md", "title_cn": "\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u7684\u641c\u7d22", "title_en": "Search in a Binary Search Tree", "question_title_slug": "search-in-a-binary-search-tree", "content_en": "

You are given the root of a binary search tree (BST) and an integer val.

\n\n

Find the node in the BST that the node's value equals val and return the subtree rooted with that node. If such a node does not exist, return null.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: root = [4,2,7,1,3], val = 2\nOutput: [2,1,3]\n
\n\n

Example 2:

\n\"\"\n
\nInput: root = [4,2,7,1,3], val = 5\nOutput: []\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The number of nodes in the tree is in the range [1, 5000].
  • \n\t
  • 1 <= Node.val <= 107
  • \n\t
  • root is a binary search tree.
  • \n\t
  • 1 <= val <= 107
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e8c\u53c9\u641c\u7d22\u6811\uff08BST\uff09\u7684\u6839\u8282\u70b9\u548c\u4e00\u4e2a\u503c\u3002 \u4f60\u9700\u8981\u5728BST\u4e2d\u627e\u5230\u8282\u70b9\u503c\u7b49\u4e8e\u7ed9\u5b9a\u503c\u7684\u8282\u70b9\u3002 \u8fd4\u56de\u4ee5\u8be5\u8282\u70b9\u4e3a\u6839\u7684\u5b50\u6811\u3002 \u5982\u679c\u8282\u70b9\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de NULL\u3002

\n\n

\u4f8b\u5982\uff0c

\n\n
\n\u7ed9\u5b9a\u4e8c\u53c9\u641c\u7d22\u6811:\n\n        4\n       / \\\n      2   7\n     / \\\n    1   3\n\n\u548c\u503c: 2\n
\n\n

\u4f60\u5e94\u8be5\u8fd4\u56de\u5982\u4e0b\u5b50\u6811:

\n\n
\n      2     \n     / \\   \n    1   3\n
\n\n

\u5728\u4e0a\u8ff0\u793a\u4f8b\u4e2d\uff0c\u5982\u679c\u8981\u627e\u7684\u503c\u662f 5\uff0c\u4f46\u56e0\u4e3a\u6ca1\u6709\u8282\u70b9\u503c\u4e3a 5\uff0c\u6211\u4eec\u5e94\u8be5\u8fd4\u56de NULL\u3002

\n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* searchBST(TreeNode* root, int val) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode searchBST(TreeNode root, int val) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def searchBST(self, root, val):\n \"\"\"\n :type root: TreeNode\n :type val: int\n :rtype: TreeNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def searchBST(self, root: TreeNode, val: int) -> TreeNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* searchBST(struct TreeNode* root, int val){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode SearchBST(TreeNode root, int val) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number} val\n * @return {TreeNode}\n */\nvar searchBST = function(root, val) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @param {Integer} val\n# @return {TreeNode}\ndef search_bst(root, val)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func searchBST(_ root: TreeNode?, _ val: Int) -> TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc searchBST(root *TreeNode, val int) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def searchBST(root: TreeNode, `val`: Int): TreeNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun searchBST(root: TreeNode?, `val`: Int): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn search_bst(root: Option>>, val: i32) -> Option>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param Integer $val\n * @return TreeNode\n */\n function searchBST($root, $val) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction searchBST(root: TreeNode | null, val: number): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (search-bst root val)\n (-> (or/c tree-node? #f) exact-integer? (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0700](https://leetcode-cn.com/problems/search-in-a-binary-search-tree)", "[\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u7684\u641c\u7d22](/solution/0700-0799/0700.Search%20in%20a%20Binary%20Search%20Tree/README.md)", "`\u6811`", "\u7b80\u5355", ""], "md_table_row_en": ["[0700](https://leetcode.com/problems/search-in-a-binary-search-tree)", "[Search in a Binary Search Tree](/solution/0700-0799/0700.Search%20in%20a%20Binary%20Search%20Tree/README_EN.md)", "`Tree`", "Easy", ""]}, {"question_id": "0782", "frontend_question_id": "0771", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/jewels-and-stones", "url_en": "https://leetcode.com/problems/jewels-and-stones", "relative_path_cn": "/solution/0700-0799/0771.Jewels%20and%20Stones/README.md", "relative_path_en": "/solution/0700-0799/0771.Jewels%20and%20Stones/README_EN.md", "title_cn": "\u5b9d\u77f3\u4e0e\u77f3\u5934", "title_en": "Jewels and Stones", "question_title_slug": "jewels-and-stones", "content_en": "

You're given strings jewels representing the types of stones that are jewels, and stones representing the stones you have. Each character in stones is a type of stone you have. You want to know how many of the stones you have are also jewels.

\n\n

Letters are case sensitive, so "a" is considered a different type of stone from "A".

\n\n

 

\n

Example 1:

\n
Input: jewels = \"aA\", stones = \"aAAbbbb\"\nOutput: 3\n

Example 2:

\n
Input: jewels = \"z\", stones = \"ZZ\"\nOutput: 0\n
\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= jewels.length, stones.length <= 50
  • \n\t
  • jewels and stones consist of only English letters.
  • \n\t
  • All the characters of jewels are unique.
  • \n
\n", "content_cn": "

 \u7ed9\u5b9a\u5b57\u7b26\u4e32J \u4ee3\u8868\u77f3\u5934\u4e2d\u5b9d\u77f3\u7684\u7c7b\u578b\uff0c\u548c\u5b57\u7b26\u4e32 S\u4ee3\u8868\u4f60\u62e5\u6709\u7684\u77f3\u5934\u3002 S \u4e2d\u6bcf\u4e2a\u5b57\u7b26\u4ee3\u8868\u4e86\u4e00\u79cd\u4f60\u62e5\u6709\u7684\u77f3\u5934\u7684\u7c7b\u578b\uff0c\u4f60\u60f3\u77e5\u9053\u4f60\u62e5\u6709\u7684\u77f3\u5934\u4e2d\u6709\u591a\u5c11\u662f\u5b9d\u77f3\u3002

\n\n

J \u4e2d\u7684\u5b57\u6bcd\u4e0d\u91cd\u590d\uff0cJ \u548c S\u4e2d\u7684\u6240\u6709\u5b57\u7b26\u90fd\u662f\u5b57\u6bcd\u3002\u5b57\u6bcd\u533a\u5206\u5927\u5c0f\u5199\uff0c\u56e0\u6b64"a"\u548c"A"\u662f\u4e0d\u540c\u7c7b\u578b\u7684\u77f3\u5934\u3002

\n\n

\u793a\u4f8b 1:

\n\n
\u8f93\u5165: J = "aA", S = "aAAbbbb"\n\u8f93\u51fa: 3\n
\n\n

\u793a\u4f8b 2:

\n\n
\u8f93\u5165: J = "z", S = "ZZ"\n\u8f93\u51fa: 0\n
\n\n

\u6ce8\u610f:

\n\n
    \n\t
  • S \u548c J \u6700\u591a\u542b\u670950\u4e2a\u5b57\u6bcd\u3002
  • \n\t
  •  J \u4e2d\u7684\u5b57\u7b26\u4e0d\u91cd\u590d\u3002
  • \n
\n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numJewelsInStones(string jewels, string stones) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numJewelsInStones(String jewels, String stones) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numJewelsInStones(self, jewels, stones):\n \"\"\"\n :type jewels: str\n :type stones: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numJewelsInStones(self, jewels: str, stones: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numJewelsInStones(char * jewels, char * stones){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumJewelsInStones(string jewels, string stones) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} jewels\n * @param {string} stones\n * @return {number}\n */\nvar numJewelsInStones = function(jewels, stones) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} jewels\n# @param {String} stones\n# @return {Integer}\ndef num_jewels_in_stones(jewels, stones)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numJewelsInStones(_ jewels: String, _ stones: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numJewelsInStones(jewels string, stones string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numJewelsInStones(jewels: String, stones: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numJewelsInStones(jewels: String, stones: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_jewels_in_stones(jewels: String, stones: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $jewels\n * @param String $stones\n * @return Integer\n */\n function numJewelsInStones($jewels, $stones) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numJewelsInStones(jewels: string, stones: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-jewels-in-stones jewels stones)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0771](https://leetcode-cn.com/problems/jewels-and-stones)", "[\u5b9d\u77f3\u4e0e\u77f3\u5934](/solution/0700-0799/0771.Jewels%20and%20Stones/README.md)", "`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0771](https://leetcode.com/problems/jewels-and-stones)", "[Jewels and Stones](/solution/0700-0799/0771.Jewels%20and%20Stones/README_EN.md)", "`Hash Table`", "Easy", ""]}, {"question_id": "0781", "frontend_question_id": "0770", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/basic-calculator-iv", "url_en": "https://leetcode.com/problems/basic-calculator-iv", "relative_path_cn": "/solution/0700-0799/0770.Basic%20Calculator%20IV/README.md", "relative_path_en": "/solution/0700-0799/0770.Basic%20Calculator%20IV/README_EN.md", "title_cn": "\u57fa\u672c\u8ba1\u7b97\u5668 IV", "title_en": "Basic Calculator IV", "question_title_slug": "basic-calculator-iv", "content_en": "

Given an expression such as expression = "e + 8 - a + 5" and an evaluation map such as {"e": 1} (given in terms of evalvars = ["e"] and evalints = [1]), return a list of tokens representing the simplified expression, such as ["-1*a","14"]

\r\n\r\n
    \r\n\t
  • An expression alternates chunks and symbols, with a space separating each chunk and symbol.
  • \r\n\t
  • A chunk is either an expression in parentheses, a variable, or a non-negative integer.
  • \r\n\t
  • A variable is a string of lowercase letters (not including digits.) Note that variables can be multiple letters, and note that variables never have a leading coefficient or unary operator like "2x" or "-x".
  • \r\n
\r\n\r\n

Expressions are evaluated in the usual order: brackets first, then multiplication, then addition and subtraction. For example, expression = "1 + 2 * 3" has an answer of ["7"].

\r\n\r\n

The format of the output is as follows:

\r\n\r\n
    \r\n\t
  • For each term of free variables with non-zero coefficient, we write the free variables within a term in sorted order lexicographically. For example, we would never write a term like "b*a*c", only "a*b*c".
  • \r\n\t
  • Terms have degree equal to the number of free variables being multiplied, counting multiplicity. (For example, "a*a*b*c" has degree 4.) We write the largest degree terms of our answer first, breaking ties by lexicographic order ignoring the leading coefficient of the term.
  • \r\n\t
  • The leading coefficient of the term is placed directly to the left with an asterisk separating it from the variables (if they exist.)  A leading coefficient of 1 is still printed.
  • \r\n\t
  • An example of a well formatted answer is ["-2*a*a*a", "3*a*a*b", "3*b*b", "4*a", "5*c", "-6"] 
  • \r\n\t
  • Terms (including constant terms) with coefficient 0 are not included.  For example, an expression of "0" has an output of [].
  • \r\n
\r\n\r\n

Examples:

\r\n\r\n
\r\nInput: expression = "e + 8 - a + 5", evalvars = ["e"], evalints = [1]\r\nOutput: ["-1*a","14"]\r\n\r\nInput: expression = "e - 8 + temperature - pressure",\r\nevalvars = ["e", "temperature"], evalints = [1, 12]\r\nOutput: ["-1*pressure","5"]\r\n\r\nInput: expression = "(e + 8) * (e - 8)", evalvars = [], evalints = []\r\nOutput: ["1*e*e","-64"]\r\n\r\nInput: expression = "7 - 7", evalvars = [], evalints = []\r\nOutput: []\r\n\r\nInput: expression = "a * b * c + b * a * c * 4", evalvars = [], evalints = []\r\nOutput: ["5*a*b*c"]\r\n\r\nInput: expression = "((a - b) * (b - c) + (c - a)) * ((a - b) + (b - c) * (c - a))",\r\nevalvars = [], evalints = []\r\nOutput: ["-1*a*a*b*b","2*a*a*b*c","-1*a*a*c*c","1*a*b*b*b","-1*a*b*b*c","-1*a*b*c*c","1*a*c*c*c","-1*b*b*b*c","2*b*b*c*c","-1*b*c*c*c","2*a*a*b","-2*a*a*c","-2*a*b*b","2*a*c*c","1*b*b*b","-1*b*b*c","1*b*c*c","-1*c*c*c","-1*a*a","1*a*b","1*a*c","-1*b*c"]\r\n
\r\n\r\n

Note:

\r\n\r\n
    \r\n\t
  1. expression will have length in range [1, 250].
  2. \r\n\t
  3. evalvars, evalints will have equal lengths in range [0, 100].
  4. \r\n
\r\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u8868\u8fbe\u5f0f expression \u5982 expression = "e + 8 - a + 5" \u548c\u4e00\u4e2a\u6c42\u503c\u6620\u5c04\uff0c\u5982 {"e": 1}\uff08\u7ed9\u5b9a\u7684\u5f62\u5f0f\u4e3a evalvars = ["e"] \u548c evalints = [1]\uff09\uff0c\u8fd4\u56de\u8868\u793a\u7b80\u5316\u8868\u8fbe\u5f0f\u7684\u6807\u8bb0\u5217\u8868\uff0c\u4f8b\u5982 ["-1*a","14"]

\n\n
    \n\t
  • \u8868\u8fbe\u5f0f\u4ea4\u66ff\u4f7f\u7528\u5757\u548c\u7b26\u53f7\uff0c\u6bcf\u4e2a\u5757\u548c\u7b26\u53f7\u4e4b\u95f4\u6709\u4e00\u4e2a\u7a7a\u683c\u3002
  • \n\t
  • \u5757\u8981\u4e48\u662f\u62ec\u53f7\u4e2d\u7684\u8868\u8fbe\u5f0f\uff0c\u8981\u4e48\u662f\u53d8\u91cf\uff0c\u8981\u4e48\u662f\u975e\u8d1f\u6574\u6570\u3002
  • \n\t
  • \u5757\u662f\u62ec\u53f7\u4e2d\u7684\u8868\u8fbe\u5f0f\uff0c\u53d8\u91cf\u6216\u975e\u8d1f\u6574\u6570\u3002
  • \n\t
  • \u53d8\u91cf\u662f\u4e00\u4e2a\u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210\u7684\u5b57\u7b26\u4e32\uff08\u4e0d\u5305\u62ec\u6570\u5b57\uff09\u3002\u8bf7\u6ce8\u610f\uff0c\u53d8\u91cf\u53ef\u4ee5\u662f\u591a\u4e2a\u5b57\u6bcd\uff0c\u5e76\u6ce8\u610f\u53d8\u91cf\u4ece\u4e0d\u5177\u6709\u50cf "2x" \u6216 "-x" \u8fd9\u6837\u7684\u524d\u5bfc\u7cfb\u6570\u6216\u4e00\u5143\u8fd0\u7b97\u7b26 \u3002
  • \n
\n\n

\u8868\u8fbe\u5f0f\u6309\u901a\u5e38\u987a\u5e8f\u8fdb\u884c\u6c42\u503c\uff1a\u5148\u662f\u62ec\u53f7\uff0c\u7136\u540e\u6c42\u4e58\u6cd5\uff0c\u518d\u8ba1\u7b97\u52a0\u6cd5\u548c\u51cf\u6cd5\u3002\u4f8b\u5982\uff0cexpression = "1 + 2 * 3" \u7684\u7b54\u6848\u662f ["7"]\u3002

\n\n

\u8f93\u51fa\u683c\u5f0f\u5982\u4e0b\uff1a

\n\n
    \n\t
  • \u5bf9\u4e8e\u7cfb\u6570\u975e\u96f6\u7684\u6bcf\u4e2a\u81ea\u53d8\u91cf\u9879\uff0c\u6211\u4eec\u6309\u5b57\u5178\u6392\u5e8f\u7684\u987a\u5e8f\u5c06\u81ea\u53d8\u91cf\u5199\u5728\u4e00\u4e2a\u9879\u4e2d\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u6c38\u8fdc\u4e0d\u4f1a\u5199\u50cf “b*a*c” \u8fd9\u6837\u7684\u9879\uff0c\u53ea\u5199 “a*b*c”\u3002
  • \n\t
  • \u9879\u7684\u6b21\u6570\u7b49\u4e8e\u88ab\u4e58\u7684\u81ea\u53d8\u91cf\u7684\u6570\u76ee\uff0c\u5e76\u8ba1\u7b97\u91cd\u590d\u9879\u3002(\u4f8b\u5982\uff0c"a*a*b*c" \u7684\u6b21\u6570\u4e3a 4\u3002)\u3002\u6211\u4eec\u5148\u5199\u51fa\u7b54\u6848\u7684\u6700\u5927\u6b21\u6570\u9879\uff0c\u7528\u5b57\u5178\u987a\u5e8f\u6253\u7834\u5173\u7cfb\uff0c\u6b64\u65f6\u5ffd\u7565\u8bcd\u7684\u524d\u5bfc\u7cfb\u6570\u3002
  • \n\t
  • \u9879\u7684\u524d\u5bfc\u7cfb\u6570\u76f4\u63a5\u653e\u5728\u5de6\u8fb9\uff0c\u7528\u661f\u53f7\u5c06\u5b83\u4e0e\u53d8\u91cf\u5206\u9694\u5f00(\u5982\u679c\u5b58\u5728\u7684\u8bdd)\u3002\u524d\u5bfc\u7cfb\u6570 1 \u4ecd\u7136\u8981\u6253\u5370\u51fa\u6765\u3002
  • \n\t
  • \u683c\u5f0f\u826f\u597d\u7684\u4e00\u4e2a\u793a\u4f8b\u7b54\u6848\u662f ["-2*a*a*a", "3*a*a*b", "3*b*b", "4*a", "5*c", "-6"] \u3002
  • \n\t
  • \u7cfb\u6570\u4e3a 0 \u7684\u9879\uff08\u5305\u62ec\u5e38\u6570\u9879\uff09\u4e0d\u5305\u62ec\u5728\u5185\u3002\u4f8b\u5982\uff0c“0” \u7684\u8868\u8fbe\u5f0f\u8f93\u51fa\u4e3a []\u3002
  • \n
\n\n

 

\n\n

\u793a\u4f8b\uff1a

\n\n
\u8f93\u5165\uff1aexpression = "e + 8 - a + 5", evalvars = ["e"], evalints = [1]\n\u8f93\u51fa\uff1a["-1*a","14"]\n\n\u8f93\u5165\uff1aexpression = "e - 8 + temperature - pressure",\nevalvars = ["e", "temperature"], evalints = [1, 12]\n\u8f93\u51fa\uff1a["-1*pressure","5"]\n\n\u8f93\u5165\uff1aexpression = "(e + 8) * (e - 8)", evalvars = [], evalints = []\n\u8f93\u51fa\uff1a["1*e*e","-64"]\n\n\u8f93\u5165\uff1aexpression = "7 - 7", evalvars = [], evalints = []\n\u8f93\u51fa\uff1a[]\n\n\u8f93\u5165\uff1aexpression = "a * b * c + b * a * c * 4", evalvars = [], evalints = []\n\u8f93\u51fa\uff1a["5*a*b*c"]\n\n\u8f93\u5165\uff1aexpression = "((a - b) * (b - c) + (c - a)) * ((a - b) + (b - c) * (c - a))",\nevalvars = [], evalints = []\n\u8f93\u51fa\uff1a["-1*a*a*b*b","2*a*a*b*c","-1*a*a*c*c","1*a*b*b*b","-1*a*b*b*c","-1*a*b*c*c","1*a*c*c*c","-1*b*b*b*c","2*b*b*c*c","-1*b*c*c*c","2*a*a*b","-2*a*a*c","-2*a*b*b","2*a*c*c","1*b*b*b","-1*b*b*c","1*b*c*c","-1*c*c*c","-1*a*a","1*a*b","1*a*c","-1*b*c"]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. expression \u7684\u957f\u5ea6\u5728 [1, 250] \u8303\u56f4\u5185\u3002
  2. \n\t
  3. evalvars, evalints \u5728\u8303\u56f4 [0, 100] \u5185\uff0c\u4e14\u957f\u5ea6\u76f8\u540c\u3002
  4. \n
\n", "tags_en": ["Stack", "Hash Table", "String"], "tags_cn": ["\u6808", "\u54c8\u5e0c\u8868", "\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector basicCalculatorIV(string expression, vector& evalvars, vector& evalints) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List basicCalculatorIV(String expression, String[] evalvars, int[] evalints) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def basicCalculatorIV(self, expression, evalvars, evalints):\n \"\"\"\n :type expression: str\n :type evalvars: List[str]\n :type evalints: List[int]\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def basicCalculatorIV(self, expression: str, evalvars: List[str], evalints: List[int]) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** basicCalculatorIV(char * expression, char ** evalvars, int evalvarsSize, int* evalints, int evalintsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList BasicCalculatorIV(string expression, string[] evalvars, int[] evalints) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} expression\n * @param {string[]} evalvars\n * @param {number[]} evalints\n * @return {string[]}\n */\nvar basicCalculatorIV = function(expression, evalvars, evalints) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} expression\n# @param {String[]} evalvars\n# @param {Integer[]} evalints\n# @return {String[]}\ndef basic_calculator_iv(expression, evalvars, evalints)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func basicCalculatorIV(_ expression: String, _ evalvars: [String], _ evalints: [Int]) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func basicCalculatorIV(expression string, evalvars []string, evalints []int) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def basicCalculatorIV(expression: String, evalvars: Array[String], evalints: Array[Int]): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun basicCalculatorIV(expression: String, evalvars: Array, evalints: IntArray): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn basic_calculator_iv(expression: String, evalvars: Vec, evalints: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $expression\n * @param String[] $evalvars\n * @param Integer[] $evalints\n * @return String[]\n */\n function basicCalculatorIV($expression, $evalvars, $evalints) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function basicCalculatorIV(expression: string, evalvars: string[], evalints: number[]): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (basic-calculator-iv expression evalvars evalints)\n (-> string? (listof string?) (listof exact-integer?) (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0770](https://leetcode-cn.com/problems/basic-calculator-iv)", "[\u57fa\u672c\u8ba1\u7b97\u5668 IV](/solution/0700-0799/0770.Basic%20Calculator%20IV/README.md)", "`\u6808`,`\u54c8\u5e0c\u8868`,`\u5b57\u7b26\u4e32`", "\u56f0\u96be", ""], "md_table_row_en": ["[0770](https://leetcode.com/problems/basic-calculator-iv)", "[Basic Calculator IV](/solution/0700-0799/0770.Basic%20Calculator%20IV/README_EN.md)", "`Stack`,`Hash Table`,`String`", "Hard", ""]}, {"question_id": "0780", "frontend_question_id": "0769", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/max-chunks-to-make-sorted", "url_en": "https://leetcode.com/problems/max-chunks-to-make-sorted", "relative_path_cn": "/solution/0700-0799/0769.Max%20Chunks%20To%20Make%20Sorted/README.md", "relative_path_en": "/solution/0700-0799/0769.Max%20Chunks%20To%20Make%20Sorted/README_EN.md", "title_cn": "\u6700\u591a\u80fd\u5b8c\u6210\u6392\u5e8f\u7684\u5757", "title_en": "Max Chunks To Make Sorted", "question_title_slug": "max-chunks-to-make-sorted", "content_en": "

Given an array arr that is a permutation of [0, 1, ..., arr.length - 1], we split the array into some number of "chunks" (partitions), and individually sort each chunk.  After concatenating them, the result equals the sorted array.

\r\n\r\n

What is the most number of chunks we could have made?

\r\n\r\n

Example 1:

\r\n\r\n
\r\nInput: arr = [4,3,2,1,0]\r\nOutput: 1\r\nExplanation:\r\nSplitting into two or more chunks will not return the required result.\r\nFor example, splitting into [4, 3], [2, 1, 0] will result in [3, 4, 0, 1, 2], which isn't sorted.\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: arr = [1,0,2,3,4]\r\nOutput: 4\r\nExplanation:\r\nWe can split into two chunks, such as [1, 0], [2, 3, 4].\r\nHowever, splitting into [1, 0], [2], [3], [4] is the highest number of chunks possible.\r\n
\r\n\r\n

Note:

\r\n\r\n
    \r\n\t
  • arr will have length in range [1, 10].
  • \r\n\t
  • arr[i] will be a permutation of [0, 1, ..., arr.length - 1].
  • \r\n
\r\n\r\n

 

\r\n", "content_cn": "

\u6570\u7ec4arr\u662f[0, 1, ..., arr.length - 1]\u7684\u4e00\u79cd\u6392\u5217\uff0c\u6211\u4eec\u5c06\u8fd9\u4e2a\u6570\u7ec4\u5206\u5272\u6210\u51e0\u4e2a“\u5757”\uff0c\u5e76\u5c06\u8fd9\u4e9b\u5757\u5206\u522b\u8fdb\u884c\u6392\u5e8f\u3002\u4e4b\u540e\u518d\u8fde\u63a5\u8d77\u6765\uff0c\u4f7f\u5f97\u8fde\u63a5\u7684\u7ed3\u679c\u548c\u6309\u5347\u5e8f\u6392\u5e8f\u540e\u7684\u539f\u6570\u7ec4\u76f8\u540c\u3002

\n\n

\u6211\u4eec\u6700\u591a\u80fd\u5c06\u6570\u7ec4\u5206\u6210\u591a\u5c11\u5757\uff1f

\n\n

\u793a\u4f8b 1:

\n\n
\u8f93\u5165: arr = [4,3,2,1,0]\n\u8f93\u51fa: 1\n\u89e3\u91ca:\n\u5c06\u6570\u7ec4\u5206\u62102\u5757\u6216\u8005\u66f4\u591a\u5757\uff0c\u90fd\u65e0\u6cd5\u5f97\u5230\u6240\u9700\u7684\u7ed3\u679c\u3002\n\u4f8b\u5982\uff0c\u5206\u6210 [4, 3], [2, 1, 0] \u7684\u7ed3\u679c\u662f [3, 4, 0, 1, 2]\uff0c\u8fd9\u4e0d\u662f\u6709\u5e8f\u7684\u6570\u7ec4\u3002\n
\n\n

\u793a\u4f8b 2:

\n\n
\u8f93\u5165: arr = [1,0,2,3,4]\n\u8f93\u51fa: 4\n\u89e3\u91ca:\n\u6211\u4eec\u53ef\u4ee5\u628a\u5b83\u5206\u6210\u4e24\u5757\uff0c\u4f8b\u5982 [1, 0], [2, 3, 4]\u3002\n\u7136\u800c\uff0c\u5206\u6210 [1, 0], [2], [3], [4] \u53ef\u4ee5\u5f97\u5230\u6700\u591a\u7684\u5757\u6570\u3002\n
\n\n

\u6ce8\u610f:

\n\n
    \n\t
  • arr \u7684\u957f\u5ea6\u5728 [1, 10] \u4e4b\u95f4\u3002
  • \n\t
  • arr[i]\u662f [0, 1, ..., arr.length - 1]\u7684\u4e00\u79cd\u6392\u5217\u3002
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxChunksToSorted(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxChunksToSorted(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxChunksToSorted(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxChunksToSorted(self, arr: List[int]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxChunksToSorted(int* arr, int arrSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxChunksToSorted(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar maxChunksToSorted = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef max_chunks_to_sorted(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxChunksToSorted(_ arr: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxChunksToSorted(arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxChunksToSorted(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxChunksToSorted(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_chunks_to_sorted(arr: Vec) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function maxChunksToSorted($arr) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxChunksToSorted(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-chunks-to-sorted arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0769](https://leetcode-cn.com/problems/max-chunks-to-make-sorted)", "[\u6700\u591a\u80fd\u5b8c\u6210\u6392\u5e8f\u7684\u5757](/solution/0700-0799/0769.Max%20Chunks%20To%20Make%20Sorted/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0769](https://leetcode.com/problems/max-chunks-to-make-sorted)", "[Max Chunks To Make Sorted](/solution/0700-0799/0769.Max%20Chunks%20To%20Make%20Sorted/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0779", "frontend_question_id": "0768", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/max-chunks-to-make-sorted-ii", "url_en": "https://leetcode.com/problems/max-chunks-to-make-sorted-ii", "relative_path_cn": "/solution/0700-0799/0768.Max%20Chunks%20To%20Make%20Sorted%20II/README.md", "relative_path_en": "/solution/0700-0799/0768.Max%20Chunks%20To%20Make%20Sorted%20II/README_EN.md", "title_cn": "\u6700\u591a\u80fd\u5b8c\u6210\u6392\u5e8f\u7684\u5757 II", "title_en": "Max Chunks To Make Sorted II", "question_title_slug": "max-chunks-to-make-sorted-ii", "content_en": "

This question is the same as "Max Chunks to Make Sorted" except the integers of the given array are not necessarily distinct, the input array could be up to length 2000, and the elements could be up to 10**8.

\r\n\r\n
\r\n\r\n

Given an array arr of integers (not necessarily distinct), we split the array into some number of "chunks" (partitions), and individually sort each chunk.  After concatenating them, the result equals the sorted array.

\r\n\r\n

What is the most number of chunks we could have made?

\r\n\r\n

Example 1:

\r\n\r\n
\r\nInput: arr = [5,4,3,2,1]\r\nOutput: 1\r\nExplanation:\r\nSplitting into two or more chunks will not return the required result.\r\nFor example, splitting into [5, 4], [3, 2, 1] will result in [4, 5, 1, 2, 3], which isn't sorted.\r\n
\r\n\r\n

Example 2:

\r\n\r\n
\r\nInput: arr = [2,1,3,4,4]\r\nOutput: 4\r\nExplanation:\r\nWe can split into two chunks, such as [2, 1], [3, 4, 4].\r\nHowever, splitting into [2, 1], [3], [4], [4] is the highest number of chunks possible.\r\n
\r\n\r\n

Note:

\r\n\r\n
    \r\n\t
  • arr will have length in range [1, 2000].
  • \r\n\t
  • arr[i] will be an integer in range [0, 10**8].
  • \r\n
\r\n\r\n

 

\r\n", "content_cn": "

\u8fd9\u4e2a\u95ee\u9898\u548c“\u6700\u591a\u80fd\u5b8c\u6210\u6392\u5e8f\u7684\u5757”\u76f8\u4f3c\uff0c\u4f46\u7ed9\u5b9a\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u53ef\u4ee5\u91cd\u590d\uff0c\u8f93\u5165\u6570\u7ec4\u6700\u5927\u957f\u5ea6\u4e3a2000\uff0c\u5176\u4e2d\u7684\u5143\u7d20\u6700\u5927\u4e3a10**8\u3002

\n\n

arr\u662f\u4e00\u4e2a\u53ef\u80fd\u5305\u542b\u91cd\u590d\u5143\u7d20\u7684\u6574\u6570\u6570\u7ec4\uff0c\u6211\u4eec\u5c06\u8fd9\u4e2a\u6570\u7ec4\u5206\u5272\u6210\u51e0\u4e2a“\u5757”\uff0c\u5e76\u5c06\u8fd9\u4e9b\u5757\u5206\u522b\u8fdb\u884c\u6392\u5e8f\u3002\u4e4b\u540e\u518d\u8fde\u63a5\u8d77\u6765\uff0c\u4f7f\u5f97\u8fde\u63a5\u7684\u7ed3\u679c\u548c\u6309\u5347\u5e8f\u6392\u5e8f\u540e\u7684\u539f\u6570\u7ec4\u76f8\u540c\u3002

\n\n

\u6211\u4eec\u6700\u591a\u80fd\u5c06\u6570\u7ec4\u5206\u6210\u591a\u5c11\u5757\uff1f

\n\n

\u793a\u4f8b 1:

\n\n
\n\u8f93\u5165: arr = [5,4,3,2,1]\n\u8f93\u51fa: 1\n\u89e3\u91ca:\n\u5c06\u6570\u7ec4\u5206\u62102\u5757\u6216\u8005\u66f4\u591a\u5757\uff0c\u90fd\u65e0\u6cd5\u5f97\u5230\u6240\u9700\u7684\u7ed3\u679c\u3002\n\u4f8b\u5982\uff0c\u5206\u6210 [5, 4], [3, 2, 1] \u7684\u7ed3\u679c\u662f [4, 5, 1, 2, 3]\uff0c\u8fd9\u4e0d\u662f\u6709\u5e8f\u7684\u6570\u7ec4\u3002 \n
\n\n

\u793a\u4f8b 2:

\n\n
\n\u8f93\u5165: arr = [2,1,3,4,4]\n\u8f93\u51fa: 4\n\u89e3\u91ca:\n\u6211\u4eec\u53ef\u4ee5\u628a\u5b83\u5206\u6210\u4e24\u5757\uff0c\u4f8b\u5982 [2, 1], [3, 4, 4]\u3002\n\u7136\u800c\uff0c\u5206\u6210 [2, 1], [3], [4], [4] \u53ef\u4ee5\u5f97\u5230\u6700\u591a\u7684\u5757\u6570\u3002 \n
\n\n

\u6ce8\u610f:

\n\n
    \n\t
  • arr\u7684\u957f\u5ea6\u5728[1, 2000]\u4e4b\u95f4\u3002
  • \n\t
  • arr[i]\u7684\u5927\u5c0f\u5728[0, 10**8]\u4e4b\u95f4\u3002
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxChunksToSorted(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxChunksToSorted(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxChunksToSorted(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxChunksToSorted(self, arr: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxChunksToSorted(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxChunksToSorted(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar maxChunksToSorted = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef max_chunks_to_sorted(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxChunksToSorted(_ arr: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxChunksToSorted(arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxChunksToSorted(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxChunksToSorted(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_chunks_to_sorted(arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function maxChunksToSorted($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxChunksToSorted(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-chunks-to-sorted arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0768](https://leetcode-cn.com/problems/max-chunks-to-make-sorted-ii)", "[\u6700\u591a\u80fd\u5b8c\u6210\u6392\u5e8f\u7684\u5757 II](/solution/0700-0799/0768.Max%20Chunks%20To%20Make%20Sorted%20II/README.md)", "`\u6570\u7ec4`", "\u56f0\u96be", ""], "md_table_row_en": ["[0768](https://leetcode.com/problems/max-chunks-to-make-sorted-ii)", "[Max Chunks To Make Sorted II](/solution/0700-0799/0768.Max%20Chunks%20To%20Make%20Sorted%20II/README_EN.md)", "`Array`", "Hard", ""]}, {"question_id": "0778", "frontend_question_id": "0767", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reorganize-string", "url_en": "https://leetcode.com/problems/reorganize-string", "relative_path_cn": "/solution/0700-0799/0767.Reorganize%20String/README.md", "relative_path_en": "/solution/0700-0799/0767.Reorganize%20String/README_EN.md", "title_cn": "\u91cd\u6784\u5b57\u7b26\u4e32", "title_en": "Reorganize String", "question_title_slug": "reorganize-string", "content_en": "

Given a string s, check if the letters can be rearranged so that two characters that are adjacent to each other are not the same.

\n\n

If possible, output any possible result.  If not possible, return the empty string.

\n\n

Example 1:

\n\n
\nInput: s = "aab"\nOutput: "aba"\n
\n\n

Example 2:

\n\n
\nInput: s = "aaab"\nOutput: ""\n
\n\n

Note:

\n\n
    \n\t
  • s will consist of lowercase letters and have length in range [1, 500].
  • \n
\n\n

 

\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32S\uff0c\u68c0\u67e5\u662f\u5426\u80fd\u91cd\u65b0\u6392\u5e03\u5176\u4e2d\u7684\u5b57\u6bcd\uff0c\u4f7f\u5f97\u4e24\u76f8\u90bb\u7684\u5b57\u7b26\u4e0d\u540c\u3002

\n\n

\u82e5\u53ef\u884c\uff0c\u8f93\u51fa\u4efb\u610f\u53ef\u884c\u7684\u7ed3\u679c\u3002\u82e5\u4e0d\u53ef\u884c\uff0c\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32\u3002

\n\n

\u793a\u4f8b 1:

\n\n
\n\u8f93\u5165: S = "aab"\n\u8f93\u51fa: "aba"\n
\n\n

\u793a\u4f8b 2:

\n\n
\n\u8f93\u5165: S = "aaab"\n\u8f93\u51fa: ""\n
\n\n

\u6ce8\u610f:

\n\n
    \n\t
  • S \u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd\u5e76\u4e14\u957f\u5ea6\u5728[1, 500]\u533a\u95f4\u5185\u3002
  • \n
\n", "tags_en": ["Heap", "Greedy", "Sort", "String"], "tags_cn": ["\u5806", "\u8d2a\u5fc3\u7b97\u6cd5", "\u6392\u5e8f", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string reorganizeString(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String reorganizeString(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def reorganizeString(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def reorganizeString(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * reorganizeString(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ReorganizeString(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar reorganizeString = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef reorganize_string(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func reorganizeString(_ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func reorganizeString(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def reorganizeString(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun reorganizeString(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn reorganize_string(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function reorganizeString($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function reorganizeString(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (reorganize-string s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0767](https://leetcode-cn.com/problems/reorganize-string)", "[\u91cd\u6784\u5b57\u7b26\u4e32](/solution/0700-0799/0767.Reorganize%20String/README.md)", "`\u5806`,`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6392\u5e8f`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0767](https://leetcode.com/problems/reorganize-string)", "[Reorganize String](/solution/0700-0799/0767.Reorganize%20String/README_EN.md)", "`Heap`,`Greedy`,`Sort`,`String`", "Medium", ""]}, {"question_id": "0777", "frontend_question_id": "0766", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/toeplitz-matrix", "url_en": "https://leetcode.com/problems/toeplitz-matrix", "relative_path_cn": "/solution/0700-0799/0766.Toeplitz%20Matrix/README.md", "relative_path_en": "/solution/0700-0799/0766.Toeplitz%20Matrix/README_EN.md", "title_cn": "\u6258\u666e\u5229\u8328\u77e9\u9635", "title_en": "Toeplitz Matrix", "question_title_slug": "toeplitz-matrix", "content_en": "

Given an m x n matrix, return true if the matrix is Toeplitz. Otherwise, return false.

\n\n

A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same elements.

\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: matrix = [[1,2,3,4],[5,1,2,3],[9,5,1,2]]\nOutput: true\nExplanation:\nIn the above grid, the diagonals are:\n"[9]", "[5, 5]", "[1, 1, 1]", "[2, 2, 2]", "[3, 3]", "[4]".\nIn each diagonal all elements are the same, so the answer is True.\n
\n\n

Example 2:

\n\"\"\n
\nInput: matrix = [[1,2],[2,2]]\nOutput: false\nExplanation:\nThe diagonal "[1, 2]" has different elements.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • m == matrix.length
  • \n\t
  • n == matrix[i].length
  • \n\t
  • 1 <= m, n <= 20
  • \n\t
  • 0 <= matrix[i][j] <= 99
  • \n
\n\n

 

\n

Follow up:

\n\n
    \n\t
  • What if the matrix is stored on disk, and the memory is limited such that you can only load at most one row of the matrix into the memory at once?
  • \n\t
  • What if the matrix is so large that you can only load up a partial row into the memory at once?
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a m x n \u7684\u77e9\u9635 matrix \u3002\u5982\u679c\u8fd9\u4e2a\u77e9\u9635\u662f\u6258\u666e\u5229\u8328\u77e9\u9635\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

\n\n

\u5982\u679c\u77e9\u9635\u4e0a\u6bcf\u4e00\u6761\u7531\u5de6\u4e0a\u5230\u53f3\u4e0b\u7684\u5bf9\u89d2\u7ebf\u4e0a\u7684\u5143\u7d20\u90fd\u76f8\u540c\uff0c\u90a3\u4e48\u8fd9\u4e2a\u77e9\u9635\u662f \u6258\u666e\u5229\u8328\u77e9\u9635 \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1amatrix = [[1,2,3,4],[5,1,2,3],[9,5,1,2]]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\n\u5728\u4e0a\u8ff0\u77e9\u9635\u4e2d, \u5176\u5bf9\u89d2\u7ebf\u4e3a: \n\"[9]\", \"[5, 5]\", \"[1, 1, 1]\", \"[2, 2, 2]\", \"[3, 3]\", \"[4]\"\u3002 \n\u5404\u6761\u5bf9\u89d2\u7ebf\u4e0a\u7684\u6240\u6709\u5143\u7d20\u5747\u76f8\u540c, \u56e0\u6b64\u7b54\u6848\u662f True \u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\"\"\n
\n\u8f93\u5165\uff1amatrix = [[1,2],[2,2]]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\n\u5bf9\u89d2\u7ebf \"[1, 2]\" \u4e0a\u7684\u5143\u7d20\u4e0d\u540c\u3002
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • m == matrix.length
  • \n\t
  • n == matrix[i].length
  • \n\t
  • 1 <= m, n <= 20
  • \n\t
  • 0 <= matrix[i][j] <= 99
  • \n
\n\n

\u00a0

\n\n

\u8fdb\u9636\uff1a

\n\n
    \n\t
  • \u5982\u679c\u77e9\u9635\u5b58\u50a8\u5728\u78c1\u76d8\u4e0a\uff0c\u5e76\u4e14\u5185\u5b58\u6709\u9650\uff0c\u4ee5\u81f3\u4e8e\u4e00\u6b21\u6700\u591a\u53ea\u80fd\u5c06\u77e9\u9635\u7684\u4e00\u884c\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\uff0c\u8be5\u600e\u4e48\u529e\uff1f
  • \n\t
  • \u5982\u679c\u77e9\u9635\u592a\u5927\uff0c\u4ee5\u81f3\u4e8e\u4e00\u6b21\u53ea\u80fd\u5c06\u4e0d\u5b8c\u6574\u7684\u4e00\u884c\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\uff0c\u8be5\u600e\u4e48\u529e\uff1f
  • \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isToeplitzMatrix(vector>& matrix) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isToeplitzMatrix(int[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isToeplitzMatrix(self, matrix):\n \"\"\"\n :type matrix: List[List[int]]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isToeplitzMatrix(self, matrix: List[List[int]]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isToeplitzMatrix(int** matrix, int matrixSize, int* matrixColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsToeplitzMatrix(int[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} matrix\n * @return {boolean}\n */\nvar isToeplitzMatrix = function(matrix) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} matrix\n# @return {Boolean}\ndef is_toeplitz_matrix(matrix)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isToeplitzMatrix(_ matrix: [[Int]]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isToeplitzMatrix(matrix [][]int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isToeplitzMatrix(matrix: Array[Array[Int]]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isToeplitzMatrix(matrix: Array): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_toeplitz_matrix(matrix: Vec>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $matrix\n * @return Boolean\n */\n function isToeplitzMatrix($matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isToeplitzMatrix(matrix: number[][]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-toeplitz-matrix matrix)\n (-> (listof (listof exact-integer?)) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0766](https://leetcode-cn.com/problems/toeplitz-matrix)", "[\u6258\u666e\u5229\u8328\u77e9\u9635](/solution/0700-0799/0766.Toeplitz%20Matrix/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0766](https://leetcode.com/problems/toeplitz-matrix)", "[Toeplitz Matrix](/solution/0700-0799/0766.Toeplitz%20Matrix/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0776", "frontend_question_id": "0590", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/n-ary-tree-postorder-traversal", "url_en": "https://leetcode.com/problems/n-ary-tree-postorder-traversal", "relative_path_cn": "/solution/0500-0599/0590.N-ary%20Tree%20Postorder%20Traversal/README.md", "relative_path_en": "/solution/0500-0599/0590.N-ary%20Tree%20Postorder%20Traversal/README_EN.md", "title_cn": "N \u53c9\u6811\u7684\u540e\u5e8f\u904d\u5386", "title_en": "N-ary Tree Postorder Traversal", "question_title_slug": "n-ary-tree-postorder-traversal", "content_en": "

Given the root of an n-ary tree, return the postorder traversal of its nodes' values.

\n\n

Nary-Tree input serialization is represented in their level order traversal. Each group of children is separated by the null value (See examples)

\n\n

 

\n

Example 1:

\n\n
\nInput: root = [1,null,3,2,4,null,5,6]\nOutput: [5,6,3,2,4,1]\n
\n\n

Example 2:

\n\"\"\n
\nInput: root = [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]\nOutput: [2,6,14,11,7,3,12,8,4,13,9,10,5,1]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The number of nodes in the tree is in the range [0, 104].
  • \n\t
  • 0 <= Node.val <= 104
  • \n\t
  • The height of the n-ary tree is less than or equal to 1000.
  • \n
\n\n

 

\n

Follow up: Recursive solution is trivial, could you do it iteratively?

\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a N \u53c9\u6811\uff0c\u8fd4\u56de\u5176\u8282\u70b9\u503c\u7684 \u540e\u5e8f\u904d\u5386 \u3002

\n\n

N \u53c9\u6811 \u5728\u8f93\u5165\u4e2d\u6309\u5c42\u5e8f\u904d\u5386\u8fdb\u884c\u5e8f\u5217\u5316\u8868\u793a\uff0c\u6bcf\u7ec4\u5b50\u8282\u70b9\u7531\u7a7a\u503c null \u5206\u9694\uff08\u8bf7\u53c2\u89c1\u793a\u4f8b\uff09\u3002

\n\n
\n
\n

\u00a0

\n\n

\u8fdb\u9636\uff1a

\n\n

\u9012\u5f52\u6cd5\u5f88\u7b80\u5355\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u8fed\u4ee3\u6cd5\u5b8c\u6210\u6b64\u9898\u5417?

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\n\n
\n\u8f93\u5165\uff1aroot = [1,null,3,2,4,null,5,6]\n\u8f93\u51fa\uff1a[5,6,3,2,4,1]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1aroot = [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]\n\u8f93\u51fa\uff1a[2,6,14,11,7,3,12,8,4,13,9,10,5,1]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • N \u53c9\u6811\u7684\u9ad8\u5ea6\u5c0f\u4e8e\u6216\u7b49\u4e8e 1000
  • \n\t
  • \u8282\u70b9\u603b\u6570\u5728\u8303\u56f4 [0,\u00a010^4] \u5185
  • \n
\n
\n
\n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n vector children;\n\n Node() {}\n\n Node(int _val) {\n val = _val;\n }\n\n Node(int _val, vector _children) {\n val = _val;\n children = _children;\n }\n};\n*/\n\nclass Solution {\npublic:\n vector postorder(Node* root) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/*\n// Definition for a Node.\nclass Node {\n public int val;\n public List children;\n\n public Node() {}\n\n public Node(int _val) {\n val = _val;\n }\n\n public Node(int _val, List _children) {\n val = _val;\n children = _children;\n }\n};\n*/\n\nclass Solution {\n public List postorder(Node root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "\"\"\"\n# Definition for a Node.\nclass Node(object):\n def __init__(self, val=None, children=None):\n self.val = val\n self.children = children\n\"\"\"\n\nclass Solution(object):\n def postorder(self, root):\n \"\"\"\n :type root: Node\n :rtype: List[int]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "\"\"\"\n# Definition for a Node.\nclass Node:\n def __init__(self, val=None, children=None):\n self.val = val\n self.children = children\n\"\"\"\n\nclass Solution:\n def postorder(self, root: 'Node') -> List[int]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a Node.\n * struct Node {\n * int val;\n * int numChildren;\n * struct Node** children;\n * };\n */\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* postorder(struct Node* root, int* returnSize) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/*\n// Definition for a Node.\npublic class Node {\n public int val;\n public IList children;\n\n public Node() {}\n\n public Node(int _val) {\n val = _val;\n }\n\n public Node(int _val, IList _children) {\n val = _val;\n children = _children;\n }\n}\n*/\n\npublic class Solution {\n public IList Postorder(Node root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // Definition for a Node.\n * function Node(val,children) {\n * this.val = val;\n * this.children = children;\n * };\n */\n\n/**\n * @param {Node} root\n * @return {number[]}\n */\nvar postorder = function(root) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a Node.\n# class Node\n# attr_accessor :val, :children\n# def initialize(val)\n# @val = val\n# @children = []\n# end\n# end\n\n# @param {Node} root\n# @return {List[int]}\ndef postorder(root)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a Node.\n * public class Node {\n * public var val: Int\n * public var children: [Node]\n * public init(_ val: Int) {\n * self.val = val\n * self.children = []\n * }\n * }\n */\n\nclass Solution {\n func postorder(_ root: Node?) -> [Int] {\n \t\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a Node.\n * type Node struct {\n * Val int\n * Children []*Node\n * }\n */\n\nfunc postorder(root *Node) []int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a Node.\n * class Node(var _value: Int) {\n * var value: Int = _value\n * var children: List[Node] = List()\n * }\n */\n\nobject Solution {\n def postorder(root: Node): List[Int] = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a Node.\n * class Node(var `val`: Int) {\n * var children: List = listOf()\n * }\n */\n\nclass Solution {\n fun postorder(root: Node?): List {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a Node.\n * class Node {\n * public $val = null;\n * public $children = null;\n * function __construct($val = 0) {\n * $this->val = $val;\n * $this->children = array();\n * }\n * }\n */\n\nclass Solution {\n /**\n * @param Node $root\n * @return integer[]\n */\n function postorder($root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for node.\n * class Node {\n * val: number\n * children: Node[]\n * constructor(val?: number) {\n * this.val = (val===undefined ? 0 : val)\n * this.children = []\n * }\n * }\n */\n\nfunction postorder(root: Node | null): number[] {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0590](https://leetcode-cn.com/problems/n-ary-tree-postorder-traversal)", "[N \u53c9\u6811\u7684\u540e\u5e8f\u904d\u5386](/solution/0500-0599/0590.N-ary%20Tree%20Postorder%20Traversal/README.md)", "`\u6811`", "\u7b80\u5355", ""], "md_table_row_en": ["[0590](https://leetcode.com/problems/n-ary-tree-postorder-traversal)", "[N-ary Tree Postorder Traversal](/solution/0500-0599/0590.N-ary%20Tree%20Postorder%20Traversal/README_EN.md)", "`Tree`", "Easy", ""]}, {"question_id": "0775", "frontend_question_id": "0589", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/n-ary-tree-preorder-traversal", "url_en": "https://leetcode.com/problems/n-ary-tree-preorder-traversal", "relative_path_cn": "/solution/0500-0599/0589.N-ary%20Tree%20Preorder%20Traversal/README.md", "relative_path_en": "/solution/0500-0599/0589.N-ary%20Tree%20Preorder%20Traversal/README_EN.md", "title_cn": "N \u53c9\u6811\u7684\u524d\u5e8f\u904d\u5386", "title_en": "N-ary Tree Preorder Traversal", "question_title_slug": "n-ary-tree-preorder-traversal", "content_en": "

Given the root of an n-ary tree, return the preorder traversal of its nodes' values.

\n\n

Nary-Tree input serialization is represented in their level order traversal. Each group of children is separated by the null value (See examples)

\n\n

 

\n

Example 1:

\n\n

\n\n
\nInput: root = [1,null,3,2,4,null,5,6]\nOutput: [1,3,5,6,2,4]\n
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: root = [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]\nOutput: [1,2,3,6,7,11,14,4,8,12,5,9,13,10]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The number of nodes in the tree is in the range [0, 104].
  • \n\t
  • 0 <= Node.val <= 104
  • \n\t
  • The height of the n-ary tree is less than or equal to 1000.
  • \n
\n\n

 

\n

Follow up: Recursive solution is trivial, could you do it iteratively?

\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a N \u53c9\u6811\uff0c\u8fd4\u56de\u5176\u8282\u70b9\u503c\u7684 \u524d\u5e8f\u904d\u5386 \u3002

\n\n

N \u53c9\u6811 \u5728\u8f93\u5165\u4e2d\u6309\u5c42\u5e8f\u904d\u5386\u8fdb\u884c\u5e8f\u5217\u5316\u8868\u793a\uff0c\u6bcf\u7ec4\u5b50\u8282\u70b9\u7531\u7a7a\u503c null \u5206\u9694\uff08\u8bf7\u53c2\u89c1\u793a\u4f8b\uff09\u3002

\n\n
\n
\n

\u00a0

\n\n

\u8fdb\u9636\uff1a

\n\n

\u9012\u5f52\u6cd5\u5f88\u7b80\u5355\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u8fed\u4ee3\u6cd5\u5b8c\u6210\u6b64\u9898\u5417?

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\n\n
\n\u8f93\u5165\uff1aroot = [1,null,3,2,4,null,5,6]\n\u8f93\u51fa\uff1a[1,3,5,6,2,4]\n
\n\u793a\u4f8b 2\uff1a\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1aroot = [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]\n\u8f93\u51fa\uff1a[1,2,3,6,7,11,14,4,8,12,5,9,13,10]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • N \u53c9\u6811\u7684\u9ad8\u5ea6\u5c0f\u4e8e\u6216\u7b49\u4e8e 1000
  • \n\t
  • \u8282\u70b9\u603b\u6570\u5728\u8303\u56f4 [0,\u00a010^4] \u5185
  • \n
\n
\n
\n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n vector children;\n\n Node() {}\n\n Node(int _val) {\n val = _val;\n }\n\n Node(int _val, vector _children) {\n val = _val;\n children = _children;\n }\n};\n*/\n\nclass Solution {\npublic:\n vector preorder(Node* root) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/*\n// Definition for a Node.\nclass Node {\n public int val;\n public List children;\n\n public Node() {}\n\n public Node(int _val) {\n val = _val;\n }\n\n public Node(int _val, List _children) {\n val = _val;\n children = _children;\n }\n};\n*/\n\nclass Solution {\n public List preorder(Node root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "\"\"\"\n# Definition for a Node.\nclass Node(object):\n def __init__(self, val=None, children=None):\n self.val = val\n self.children = children\n\"\"\"\n\nclass Solution(object):\n def preorder(self, root):\n \"\"\"\n :type root: Node\n :rtype: List[int]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "\"\"\"\n# Definition for a Node.\nclass Node:\n def __init__(self, val=None, children=None):\n self.val = val\n self.children = children\n\"\"\"\n\nclass Solution:\n def preorder(self, root: 'Node') -> List[int]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a Node.\n * struct Node {\n * int val;\n * int numChildren;\n * struct Node** children;\n * };\n */\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* preorder(struct Node* root, int* returnSize) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/*\n// Definition for a Node.\npublic class Node {\n public int val;\n public IList children;\n\n public Node() {}\n\n public Node(int _val) {\n val = _val;\n }\n\n public Node(int _val,IList _children) {\n val = _val;\n children = _children;\n }\n}\n*/\n\npublic class Solution {\n public IList Preorder(Node root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // Definition for a Node.\n * function Node(val, children) {\n * this.val = val;\n * this.children = children;\n * };\n */\n\n/**\n * @param {Node} root\n * @return {number[]}\n */\nvar preorder = function(root) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a Node.\n# class Node\n# attr_accessor :val, :children\n# def initialize(val)\n# @val = val\n# @children = []\n# end\n# end\n\n# @param {Node} root\n# @return {List[int]}\ndef preorder(root)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a Node.\n * public class Node {\n * public var val: Int\n * public var children: [Node]\n * public init(_ val: Int) {\n * self.val = val\n * self.children = []\n * }\n * }\n */\n\nclass Solution {\n func preorder(_ root: Node?) -> [Int] {\n \t\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a Node.\n * type Node struct {\n * Val int\n * Children []*Node\n * }\n */\n\nfunc preorder(root *Node) []int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a Node.\n * class Node(var _value: Int) {\n * var value: Int = _value\n * var children: List[Node] = List()\n * }\n */\n\nobject Solution {\n def preorder(root: Node): List[Int] = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a Node.\n * class Node(var `val`: Int) {\n * var children: List = listOf()\n * }\n */\n\nclass Solution {\n fun preorder(root: Node?): List {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a Node.\n * class Node {\n * public $val = null;\n * public $children = null;\n * function __construct($val = 0) {\n * $this->val = $val;\n * $this->children = array();\n * }\n * }\n */\n\nclass Solution {\n /**\n * @param Node $root\n * @return integer[]\n */\n function preorder($root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for node.\n * class Node {\n * val: number\n * children: Node[]\n * constructor(val?: number) {\n * this.val = (val===undefined ? 0 : val)\n * this.children = []\n * }\n * }\n */\n\nfunction preorder(root: Node | null): number[] {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0589](https://leetcode-cn.com/problems/n-ary-tree-preorder-traversal)", "[N \u53c9\u6811\u7684\u524d\u5e8f\u904d\u5386](/solution/0500-0599/0589.N-ary%20Tree%20Preorder%20Traversal/README.md)", "`\u6811`", "\u7b80\u5355", ""], "md_table_row_en": ["[0589](https://leetcode.com/problems/n-ary-tree-preorder-traversal)", "[N-ary Tree Preorder Traversal](/solution/0500-0599/0589.N-ary%20Tree%20Preorder%20Traversal/README_EN.md)", "`Tree`", "Easy", ""]}, {"question_id": "0774", "frontend_question_id": "0559", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-depth-of-n-ary-tree", "url_en": "https://leetcode.com/problems/maximum-depth-of-n-ary-tree", "relative_path_cn": "/solution/0500-0599/0559.Maximum%20Depth%20of%20N-ary%20Tree/README.md", "relative_path_en": "/solution/0500-0599/0559.Maximum%20Depth%20of%20N-ary%20Tree/README_EN.md", "title_cn": "N \u53c9\u6811\u7684\u6700\u5927\u6df1\u5ea6", "title_en": "Maximum Depth of N-ary Tree", "question_title_slug": "maximum-depth-of-n-ary-tree", "content_en": "

Given a n-ary tree, find its maximum depth.

\n\n

The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.

\n\n

Nary-Tree input serialization is represented in their level order traversal, each group of children is separated by the null value (See examples).

\n\n

 

\n

Example 1:

\n\n

\n\n
\nInput: root = [1,null,3,2,4,null,5,6]\nOutput: 3\n
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: root = [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]\nOutput: 5\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The depth of the n-ary tree is less than or equal to 1000.
  • \n\t
  • The total number of nodes is between [0, 104].
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a N \u53c9\u6811\uff0c\u627e\u5230\u5176\u6700\u5927\u6df1\u5ea6\u3002

\n\n

\u6700\u5927\u6df1\u5ea6\u662f\u6307\u4ece\u6839\u8282\u70b9\u5230\u6700\u8fdc\u53f6\u5b50\u8282\u70b9\u7684\u6700\u957f\u8def\u5f84\u4e0a\u7684\u8282\u70b9\u603b\u6570\u3002

\n\n

N \u53c9\u6811\u8f93\u5165\u6309\u5c42\u5e8f\u904d\u5386\u5e8f\u5217\u5316\u8868\u793a\uff0c\u6bcf\u7ec4\u5b50\u8282\u70b9\u7531\u7a7a\u503c\u5206\u9694\uff08\u8bf7\u53c2\u89c1\u793a\u4f8b\uff09\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\n\n
\n\u8f93\u5165\uff1aroot = [1,null,3,2,4,null,5,6]\n\u8f93\u51fa\uff1a3\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1aroot = [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]\n\u8f93\u51fa\uff1a5\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u6811\u7684\u6df1\u5ea6\u4e0d\u4f1a\u8d85\u8fc7\u00a01000 \u3002
  • \n\t
  • \u6811\u7684\u8282\u70b9\u6570\u76ee\u4f4d\u4e8e [0,\u00a0104] \u4e4b\u95f4\u3002
  • \n
\n", "tags_en": ["Tree", "Depth-first Search", "Breadth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n vector children;\n\n Node() {}\n\n Node(int _val) {\n val = _val;\n }\n\n Node(int _val, vector _children) {\n val = _val;\n children = _children;\n }\n};\n*/\n\nclass Solution {\npublic:\n int maxDepth(Node* root) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/*\n// Definition for a Node.\nclass Node {\n public int val;\n public List children;\n\n public Node() {}\n\n public Node(int _val) {\n val = _val;\n }\n\n public Node(int _val, List _children) {\n val = _val;\n children = _children;\n }\n};\n*/\n\nclass Solution {\n public int maxDepth(Node root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "\"\"\"\n# Definition for a Node.\nclass Node(object):\n def __init__(self, val=None, children=None):\n self.val = val\n self.children = children\n\"\"\"\n\nclass Solution(object):\n def maxDepth(self, root):\n \"\"\"\n :type root: Node\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "\"\"\"\n# Definition for a Node.\nclass Node:\n def __init__(self, val=None, children=None):\n self.val = val\n self.children = children\n\"\"\"\n\nclass Solution:\n def maxDepth(self, root: 'Node') -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a Node.\n * struct Node {\n * int val;\n * int numChildren;\n * struct Node** children;\n * };\n */\n\nint maxDepth(struct Node* root) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/*\n// Definition for a Node.\npublic class Node {\n public int val;\n public IList children;\n\n public Node() {}\n\n public Node(int _val) {\n val = _val;\n }\n\n public Node(int _val, IList _children) {\n val = _val;\n children = _children;\n }\n}\n*/\n\npublic class Solution {\n public int MaxDepth(Node root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // Definition for a Node.\n * function Node(val,children) {\n * this.val = val;\n * this.children = children;\n * };\n */\n\n/**\n * @param {Node|null} root\n * @return {number}\n */\nvar maxDepth = function(root) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a Node.\n# class Node\n# attr_accessor :val, :children\n# def initialize(val)\n# @val = val\n# @children = []\n# end\n# end\n\n# @param {Node} root\n# @return {int}\ndef maxDepth(root)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a Node.\n * public class Node {\n * public var val: Int\n * public var children: [Node]\n * public init(_ val: Int) {\n * self.val = val\n * self.children = []\n * }\n * }\n */\n\nclass Solution {\n func maxDepth(_ root: Node?) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a Node.\n * type Node struct {\n * Val int\n * Children []*Node\n * }\n */\n\nfunc maxDepth(root *Node) int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a Node.\n * class Node(var _value: Int) {\n * var value: Int = _value\n * var children: List[Node] = List()\n * }\n */\n\nobject Solution {\n def maxDepth(root: Node): Int = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a Node.\n * class Node(var `val`: Int) {\n * var children: List = listOf()\n * }\n */\n\nclass Solution {\n fun maxDepth(root: Node?): Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a Node.\n * class Node {\n * public $val = null;\n * public $children = null;\n * function __construct($val = 0) {\n * $this->val = $val;\n * $this->children = array();\n * }\n * }\n */\n\nclass Solution {\n /**\n * @param Node $root\n * @return integer\n */\n function maxDepth($root) {\n \t\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for Node.\n * class Node {\n * val: number\n * children: Node[]\n * constructor(val?: number, children?: Node[]) {\n * this.val = (val===undefined ? 0 : val)\n * this.children = (children===undefined ? [] : children)\n * }\n * }\n */\n\nfunction maxDepth(root: Node): number {\n \n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0559](https://leetcode-cn.com/problems/maximum-depth-of-n-ary-tree)", "[N \u53c9\u6811\u7684\u6700\u5927\u6df1\u5ea6](/solution/0500-0599/0559.Maximum%20Depth%20of%20N-ary%20Tree/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u7b80\u5355", ""], "md_table_row_en": ["[0559](https://leetcode.com/problems/maximum-depth-of-n-ary-tree)", "[Maximum Depth of N-ary Tree](/solution/0500-0599/0559.Maximum%20Depth%20of%20N-ary%20Tree/README_EN.md)", "`Tree`,`Depth-first Search`,`Breadth-first Search`", "Easy", ""]}, {"question_id": "0773", "frontend_question_id": "0558", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/logical-or-of-two-binary-grids-represented-as-quad-trees", "url_en": "https://leetcode.com/problems/logical-or-of-two-binary-grids-represented-as-quad-trees", "relative_path_cn": "/solution/0500-0599/0558.Logical%20OR%20of%20Two%20Binary%20Grids%20Represented%20as%20Quad-Trees/README.md", "relative_path_en": "/solution/0500-0599/0558.Logical%20OR%20of%20Two%20Binary%20Grids%20Represented%20as%20Quad-Trees/README_EN.md", "title_cn": "\u56db\u53c9\u6811\u4ea4\u96c6", "title_en": "Logical OR of Two Binary Grids Represented as Quad-Trees", "question_title_slug": "logical-or-of-two-binary-grids-represented-as-quad-trees", "content_en": "

A Binary Matrix is a matrix in which all the elements are either 0 or 1.

\r\n\r\n

Given quadTree1 and quadTree2. quadTree1 represents a n * n binary matrix and quadTree2 represents another n * n binary matrix. 

\r\n\r\n

Return a Quad-Tree representing the n * n binary matrix which is the result of logical bitwise OR of the two binary matrixes represented by quadTree1 and quadTree2.

\r\n\r\n

Notice that you can assign the value of a node to True or False when isLeaf is False, and both are accepted in the answer.

\r\n\r\n

A Quad-Tree is a tree data structure in which each internal node has exactly four children. Besides, each node has two attributes:

\r\n\r\n
    \r\n\t
  • val: True if the node represents a grid of 1's or False if the node represents a grid of 0's. 
  • \r\n\t
  • isLeaf: True if the node is leaf node on the tree or False if the node has the four children.
  • \r\n
\r\n\r\n
\r\nclass Node {\r\n    public boolean val;\r\n    public boolean isLeaf;\r\n    public Node topLeft;\r\n    public Node topRight;\r\n    public Node bottomLeft;\r\n    public Node bottomRight;\r\n}
\r\n\r\n

We can construct a Quad-Tree from a two-dimensional area using the following steps:

\r\n\r\n
    \r\n\t
  1. If the current grid has the same value (i.e all 1's or all 0's) set isLeaf True and set val to the value of the grid and set the four children to Null and stop.
  2. \r\n\t
  3. If the current grid has different values, set isLeaf to False and set val to any value and divide the current grid into four sub-grids as shown in the photo.
  4. \r\n\t
  5. Recurse for each of the children with the proper sub-grid.
  6. \r\n
\r\n\"\"\r\n

If you want to know more about the Quad-Tree, you can refer to the wiki.

\r\n\r\n

Quad-Tree format:

\r\n\r\n

The input/output represents the serialized format of a Quad-Tree using level order traversal, where null signifies a path terminator where no node exists below.

\r\n\r\n

It is very similar to the serialization of the binary tree. The only difference is that the node is represented as a list [isLeaf, val].

\r\n\r\n

If the value of isLeaf or val is True we represent it as 1 in the list [isLeaf, val] and if the value of isLeaf or val is False we represent it as 0.

\r\n\n

 

\n

Example 1:

\n\"\" \"\"\n
\nInput: quadTree1 = [[0,1],[1,1],[1,1],[1,0],[1,0]]\n, quadTree2 = [[0,1],[1,1],[0,1],[1,1],[1,0],null,null,null,null,[1,0],[1,0],[1,1],[1,1]]\nOutput: [[0,0],[1,1],[1,1],[1,1],[1,0]]\nExplanation: quadTree1 and quadTree2 are shown above. You can see the binary matrix which is represented by each Quad-Tree.\nIf we apply logical bitwise OR on the two binary matrices we get the binary matrix below which is represented by the result Quad-Tree.\nNotice that the binary matrices shown are only for illustration, you don't have to construct the binary matrix to get the result tree.\n\"\"\n
\n\n

Example 2:

\n\n
\nInput: quadTree1 = [[1,0]]\n, quadTree2 = [[1,0]]\nOutput: [[1,0]]\nExplanation: Each tree represents a binary matrix of size 1*1. Each matrix contains only zero.\nThe resulting matrix is of size 1*1 with also zero.\n
\n\n

Example 3:

\n\n
\nInput: quadTree1 = [[0,0],[1,0],[1,0],[1,1],[1,1]]\n, quadTree2 = [[0,0],[1,1],[1,1],[1,0],[1,1]]\nOutput: [[1,1]]\n
\n\n

Example 4:

\n\n
\nInput: quadTree1 = [[0,0],[1,1],[1,0],[1,1],[1,1]]\n, quadTree2 = [[0,0],[1,1],[0,1],[1,1],[1,1],null,null,null,null,[1,1],[1,0],[1,0],[1,1]]\nOutput: [[0,0],[1,1],[0,1],[1,1],[1,1],null,null,null,null,[1,1],[1,0],[1,0],[1,1]]\n
\n\n

Example 5:

\n\n
\nInput: quadTree1 = [[0,1],[1,0],[0,1],[1,1],[1,0],null,null,null,null,[1,0],[1,0],[1,1],[1,1]]\n, quadTree2 = [[0,1],[0,1],[1,0],[1,1],[1,0],[1,0],[1,0],[1,1],[1,1]]\nOutput: [[0,0],[0,1],[0,1],[1,1],[1,0],[1,0],[1,0],[1,1],[1,1],[1,0],[1,0],[1,1],[1,1]]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • quadTree1 and quadTree2 are both valid Quad-Trees each representing a n * n grid.
  • \n\t
  • n == 2^x where 0 <= x <= 9.
  • \n
\n", "content_cn": "

\u4e8c\u8fdb\u5236\u77e9\u9635\u4e2d\u7684\u6240\u6709\u5143\u7d20\u4e0d\u662f 0 \u5c31\u662f 1 \u3002

\n\n

\u7ed9\u4f60\u4e24\u4e2a\u56db\u53c9\u6811\uff0cquadTree1 \u548c quadTree2\u3002\u5176\u4e2d quadTree1 \u8868\u793a\u4e00\u4e2a n * n \u4e8c\u8fdb\u5236\u77e9\u9635\uff0c\u800c quadTree2 \u8868\u793a\u53e6\u4e00\u4e2a n * n \u4e8c\u8fdb\u5236\u77e9\u9635\u3002

\n\n

\u8bf7\u4f60\u8fd4\u56de\u4e00\u4e2a\u8868\u793a n * n \u4e8c\u8fdb\u5236\u77e9\u9635\u7684\u56db\u53c9\u6811\uff0c\u5b83\u662f quadTree1 \u548c quadTree2 \u6240\u8868\u793a\u7684\u4e24\u4e2a\u4e8c\u8fdb\u5236\u77e9\u9635\u8fdb\u884c \u6309\u4f4d\u903b\u8f91\u6216\u8fd0\u7b97 \u7684\u7ed3\u679c\u3002

\n\n

\u6ce8\u610f\uff0c\u5f53 isLeaf \u4e3a False \u65f6\uff0c\u4f60\u53ef\u4ee5\u628a True \u6216\u8005 False \u8d4b\u503c\u7ed9\u8282\u70b9\uff0c\u4e24\u79cd\u503c\u90fd\u4f1a\u88ab\u5224\u9898\u673a\u5236 \u63a5\u53d7 \u3002

\n\n

\u56db\u53c9\u6811\u6570\u636e\u7ed3\u6784\u4e2d\uff0c\u6bcf\u4e2a\u5185\u90e8\u8282\u70b9\u53ea\u6709\u56db\u4e2a\u5b50\u8282\u70b9\u3002\u6b64\u5916\uff0c\u6bcf\u4e2a\u8282\u70b9\u90fd\u6709\u4e24\u4e2a\u5c5e\u6027\uff1a

\n\n
    \n\t
  • val\uff1a\u50a8\u5b58\u53f6\u5b50\u7ed3\u70b9\u6240\u4ee3\u8868\u7684\u533a\u57df\u7684\u503c\u30021 \u5bf9\u5e94 True\uff0c0 \u5bf9\u5e94 False\uff1b
  • \n\t
  • isLeaf: \u5f53\u8fd9\u4e2a\u8282\u70b9\u662f\u4e00\u4e2a\u53f6\u5b50\u7ed3\u70b9\u65f6\u4e3a True\uff0c\u5982\u679c\u5b83\u6709 4 \u4e2a\u5b50\u8282\u70b9\u5219\u4e3a False \u3002
  • \n
\n\n
\nclass Node {\n    public boolean val;\n\u00a0 \u00a0 public boolean isLeaf;\n\u00a0 \u00a0 public Node topLeft;\n\u00a0 \u00a0 public Node topRight;\n\u00a0 \u00a0 public Node bottomLeft;\n\u00a0 \u00a0 public Node bottomRight;\n}
\n\n

\u6211\u4eec\u53ef\u4ee5\u6309\u4ee5\u4e0b\u6b65\u9aa4\u4e3a\u4e8c\u7ef4\u533a\u57df\u6784\u5efa\u56db\u53c9\u6811\uff1a

\n\n
    \n\t
  1. \u5982\u679c\u5f53\u524d\u7f51\u683c\u7684\u503c\u76f8\u540c\uff08\u5373\uff0c\u5168\u4e3a 0 \u6216\u8005\u5168\u4e3a 1\uff09\uff0c\u5c06 isLeaf \u8bbe\u4e3a True \uff0c\u5c06 val \u8bbe\u4e3a\u7f51\u683c\u76f8\u5e94\u7684\u503c\uff0c\u5e76\u5c06\u56db\u4e2a\u5b50\u8282\u70b9\u90fd\u8bbe\u4e3a Null \u7136\u540e\u505c\u6b62\u3002
  2. \n\t
  3. \u5982\u679c\u5f53\u524d\u7f51\u683c\u7684\u503c\u4e0d\u540c\uff0c\u5c06 isLeaf \u8bbe\u4e3a False\uff0c \u5c06 val \u8bbe\u4e3a\u4efb\u610f\u503c\uff0c\u7136\u540e\u5982\u4e0b\u56fe\u6240\u793a\uff0c\u5c06\u5f53\u524d\u7f51\u683c\u5212\u5206\u4e3a\u56db\u4e2a\u5b50\u7f51\u683c\u3002
  4. \n\t
  5. \u4f7f\u7528\u9002\u5f53\u7684\u5b50\u7f51\u683c\u9012\u5f52\u6bcf\u4e2a\u5b50\u8282\u70b9\u3002
  6. \n
\n\n

\"\"

\n\n

\u5982\u679c\u4f60\u60f3\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u56db\u53c9\u6811\u7684\u5185\u5bb9\uff0c\u53ef\u4ee5\u53c2\u8003 wiki \u3002

\n\n

\u56db\u53c9\u6811\u683c\u5f0f\uff1a

\n\n

\u8f93\u51fa\u4e3a\u4f7f\u7528\u5c42\u5e8f\u904d\u5386\u540e\u56db\u53c9\u6811\u7684\u5e8f\u5217\u5316\u5f62\u5f0f\uff0c\u5176\u4e2d null \u8868\u793a\u8def\u5f84\u7ec8\u6b62\u7b26\uff0c\u5176\u4e0b\u9762\u4e0d\u5b58\u5728\u8282\u70b9\u3002

\n\n

\u5b83\u4e0e\u4e8c\u53c9\u6811\u7684\u5e8f\u5217\u5316\u975e\u5e38\u76f8\u4f3c\u3002\u552f\u4e00\u7684\u533a\u522b\u662f\u8282\u70b9\u4ee5\u5217\u8868\u5f62\u5f0f\u8868\u793a [isLeaf, val] \u3002

\n\n

\u5982\u679c isLeaf \u6216\u8005 val \u7684\u503c\u4e3a True \uff0c\u5219\u8868\u793a\u5b83\u5728\u5217\u8868\u00a0[isLeaf, val] \u4e2d\u7684\u503c\u4e3a 1 \uff1b\u5982\u679c isLeaf \u6216\u8005 val \u7684\u503c\u4e3a False \uff0c\u5219\u8868\u793a\u503c\u4e3a 0 \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\" \"\"

\n\n
\n\u8f93\u5165\uff1aquadTree1 = [[0,1],[1,1],[1,1],[1,0],[1,0]]\n, quadTree2 = [[0,1],[1,1],[0,1],[1,1],[1,0],null,null,null,null,[1,0],[1,0],[1,1],[1,1]]\n\u8f93\u51fa\uff1a[[0,0],[1,1],[1,1],[1,1],[1,0]]\n\u89e3\u91ca\uff1aquadTree1 \u548c quadTree2 \u5982\u4e0a\u6240\u793a\u3002\u7531\u56db\u53c9\u6811\u6240\u8868\u793a\u7684\u4e8c\u8fdb\u5236\u77e9\u9635\u4e5f\u5df2\u7ecf\u7ed9\u51fa\u3002\n\u5982\u679c\u6211\u4eec\u5bf9\u8fd9\u4e24\u4e2a\u77e9\u9635\u8fdb\u884c\u6309\u4f4d\u903b\u8f91\u6216\u8fd0\u7b97\uff0c\u5219\u53ef\u4ee5\u5f97\u5230\u4e0b\u9762\u7684\u4e8c\u8fdb\u5236\u77e9\u9635\uff0c\u7531\u4e00\u4e2a\u4f5c\u4e3a\u7ed3\u679c\u7684\u56db\u53c9\u6811\u8868\u793a\u3002\n\u6ce8\u610f\uff0c\u6211\u4eec\u5c55\u793a\u7684\u4e8c\u8fdb\u5236\u77e9\u9635\u4ec5\u4ec5\u662f\u4e3a\u4e86\u66f4\u597d\u5730\u8bf4\u660e\u9898\u610f\uff0c\u4f60\u65e0\u9700\u6784\u9020\u4e8c\u8fdb\u5236\u77e9\u9635\u6765\u83b7\u5f97\u7ed3\u679c\u56db\u53c9\u6811\u3002\n\"\"\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aquadTree1 = [[1,0]]\n, quadTree2 = [[1,0]]\n\u8f93\u51fa\uff1a[[1,0]]\n\u89e3\u91ca\uff1a\u4e24\u4e2a\u6570\u6240\u8868\u793a\u7684\u77e9\u9635\u5927\u5c0f\u90fd\u4e3a 1*1\uff0c\u503c\u5168\u4e3a 0 \n\u7ed3\u679c\u77e9\u9635\u5927\u5c0f\u4e3a 1*1\uff0c\u503c\u5168\u4e3a 0 \u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1aquadTree1 = [[0,0],[1,0],[1,0],[1,1],[1,1]]\n, quadTree2 = [[0,0],[1,1],[1,1],[1,0],[1,1]]\n\u8f93\u51fa\uff1a[[1,1]]\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1aquadTree1 = [[0,0],[1,1],[1,0],[1,1],[1,1]]\n, quadTree2 = [[0,0],[1,1],[0,1],[1,1],[1,1],null,null,null,null,[1,1],[1,0],[1,0],[1,1]]\n\u8f93\u51fa\uff1a[[0,0],[1,1],[0,1],[1,1],[1,1],null,null,null,null,[1,1],[1,0],[1,0],[1,1]]\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\n\u8f93\u5165\uff1aquadTree1 = [[0,1],[1,0],[0,1],[1,1],[1,0],null,null,null,null,[1,0],[1,0],[1,1],[1,1]]\n, quadTree2 = [[0,1],[0,1],[1,0],[1,1],[1,0],[1,0],[1,0],[1,1],[1,1]]\n\u8f93\u51fa\uff1a[[0,0],[0,1],[0,1],[1,1],[1,0],[1,0],[1,0],[1,1],[1,1],[1,0],[1,0],[1,1],[1,1]]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • quadTree1 \u548c quadTree2 \u90fd\u662f\u7b26\u5408\u9898\u76ee\u8981\u6c42\u7684\u56db\u53c9\u6811\uff0c\u6bcf\u4e2a\u90fd\u4ee3\u8868\u4e00\u4e2a n * n \u7684\u77e9\u9635\u3002
  • \n\t
  • n == 2^x \uff0c\u5176\u4e2d 0 <= x <= 9.
  • \n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n// Definition for a QuadTree node.\nclass Node {\npublic:\n bool val;\n bool isLeaf;\n Node* topLeft;\n Node* topRight;\n Node* bottomLeft;\n Node* bottomRight;\n \n Node() {\n val = false;\n isLeaf = false;\n topLeft = NULL;\n topRight = NULL;\n bottomLeft = NULL;\n bottomRight = NULL;\n }\n \n Node(bool _val, bool _isLeaf) {\n val = _val;\n isLeaf = _isLeaf;\n topLeft = NULL;\n topRight = NULL;\n bottomLeft = NULL;\n bottomRight = NULL;\n }\n \n Node(bool _val, bool _isLeaf, Node* _topLeft, Node* _topRight, Node* _bottomLeft, Node* _bottomRight) {\n val = _val;\n isLeaf = _isLeaf;\n topLeft = _topLeft;\n topRight = _topRight;\n bottomLeft = _bottomLeft;\n bottomRight = _bottomRight;\n }\n};\n*/\n\nclass Solution {\npublic:\n Node* intersect(Node* quadTree1, Node* quadTree2) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/*\n// Definition for a QuadTree node.\nclass Node {\n public boolean val;\n public boolean isLeaf;\n public Node topLeft;\n public Node topRight;\n public Node bottomLeft;\n public Node bottomRight;\n\n public Node() {}\n\n public Node(boolean _val,boolean _isLeaf,Node _topLeft,Node _topRight,Node _bottomLeft,Node _bottomRight) {\n val = _val;\n isLeaf = _isLeaf;\n topLeft = _topLeft;\n topRight = _topRight;\n bottomLeft = _bottomLeft;\n bottomRight = _bottomRight;\n }\n};\n*/\n\nclass Solution {\n public Node intersect(Node quadTree1, Node quadTree2) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "\"\"\"\n# Definition for a QuadTree node.\nclass Node(object):\n def __init__(self, val, isLeaf, topLeft, topRight, bottomLeft, bottomRight):\n self.val = val\n self.isLeaf = isLeaf\n self.topLeft = topLeft\n self.topRight = topRight\n self.bottomLeft = bottomLeft\n self.bottomRight = bottomRight\n\"\"\"\n\nclass Solution(object):\n def intersect(self, quadTree1, quadTree2):\n \"\"\"\n :type quadTree1: Node\n :type quadTree2: Node\n :rtype: Node\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "\"\"\"\n# Definition for a QuadTree node.\nclass Node:\n def __init__(self, val, isLeaf, topLeft, topRight, bottomLeft, bottomRight):\n self.val = val\n self.isLeaf = isLeaf\n self.topLeft = topLeft\n self.topRight = topRight\n self.bottomLeft = bottomLeft\n self.bottomRight = bottomRight\n\"\"\"\n\nclass Solution:\n def intersect(self, quadTree1: 'Node', quadTree2: 'Node') -> 'Node':\n ", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/*\n// Definition for a QuadTree node.\npublic class Node {\n public bool val;\n public bool isLeaf;\n public Node topLeft;\n public Node topRight;\n public Node bottomLeft;\n public Node bottomRight;\n\n public Node(){}\n public Node(bool _val,bool _isLeaf,Node _topLeft,Node _topRight,Node _bottomLeft,Node _bottomRight) {\n val = _val;\n isLeaf = _isLeaf;\n topLeft = _topLeft;\n topRight = _topRight;\n bottomLeft = _bottomLeft;\n bottomRight = _bottomRight;\n }\n}\n*/\n\npublic class Solution {\n public Node Intersect(Node quadTree1, Node quadTree2) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // Definition for a QuadTree node.\n * function Node(val,isLeaf,topLeft,topRight,bottomLeft,bottomRight) {\n * this.val = val;\n * this.isLeaf = isLeaf;\n * this.topLeft = topLeft;\n * this.topRight = topRight;\n * this.bottomLeft = bottomLeft;\n * this.bottomRight = bottomRight;\n * };\n */\n\n/**\n * @param {Node} quadTree1\n * @param {Node} quadTree2\n * @return {Node}\n */\nvar intersect = function(quadTree1, quadTree2) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a QuadTree node.\n# class Node\n# attr_accessor :val, :isLeaf, :topLeft, :topRight, :bottomLeft, :bottomRight\n# def initialize(val=false, isLeaf=false, topLeft=nil, topRight=nil, bottomLeft=nil, bottomRight=nil)\n# @val = val\n# @isLeaf = isLeaf\n# @topLeft = topLeft\n# @topRight = topRight\n# @bottomLeft = bottomLeft\n# @bottomRight = bottomRight\n# end\n# end\n\n# @param {Node} quadTree1\n# @param {Node} quadTree2\n# @return {Node}\ndef intersect(quadTree1, quadTree2)\n\t\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a Node.\n * public class Node {\n * public var val: Bool\n * public var isLeaf: Bool\n * public var topLeft: Node?\n * public var topRight: Node?\n * public var bottomLeft: Node?\n * public var bottomRight: Node?\n * public init(_ val: Bool, _ isLeaf: Bool) {\n * self.val = val\n * self.isLeaf = isLeaf\n * self.topLeft = nil\n * self.topRight = nil\n * self.bottomLeft = nil\n * self.bottomRight = nil\n * }\n * }\n */\n\nclass Solution {\n func intersect(_ quadTree1: Node?, _ quadTree2: Node?) -> Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a QuadTree node.\n * type Node struct {\n * Val bool\n * IsLeaf bool\n * TopLeft *Node\n * TopRight *Node\n * BottomLeft *Node\n * BottomRight *Node\n * }\n */\n\nfunc intersect(quadTree1 *Node, quadTree2 *Node) *Node {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a QuadTree node.\n * class Node(var _value: Boolean, var _isLeaf: Boolean) {\n * var value: Int = _value\n * var isLeaf: Boolean = _isLeaf\n * var topLeft: Node = null\n * var topRight: Node = null\n * var bottomLeft: Node = null\n * var bottomRight: Node = null\n * }\n */\n\nobject Solution {\n def intersect(quadTree1: Node, quadTree2: Node): Node = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a QuadTree node.\n * class Node(var `val`: Boolean, var isLeaf: Boolean) {\n * var topLeft: Node? = null\n * var topRight: Node? = null\n * var bottomLeft: Node? = null\n * var bottomRight: Node? = null\n * }\n */\n\nclass Solution {\n fun intersect(quadTree1: Node?, quadTree2: Node?): Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a QuadTree node.\n * class Node {\n * public $val = null;\n * public $isLeaf = null;\n * public $topLeft = null;\n * public $topRight = null;\n * public $bottomLeft = null;\n * public $bottomRight = null;\n * function __construct($val, $isLeaf) {\n * $this->val = $val;\n * $this->isLeaf = $isLeaf;\n * $this->topLeft = null;\n * $this->topRight = null;\n * $this->bottomLeft = null;\n * $this->bottomRight = null;\n * }\n * }\n */\n\nclass Solution {\n /**\n * @param Node $quadTree1\n * @param Node $quadTree2\n * @return Node\n */\n function intersect($quadTree1, $quadTree2) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for node.\n * class Node {\n * val: boolean\n * isLeaf: boolean\n * topLeft: Node | null\n * topRight: Node | null\n * bottomLeft: Node | null\n * bottomRight: Node | null\n * constructor(val?: boolean, isLeaf?: boolean, topLeft?: Node, topRight?: Node, bottomLeft?: Node, bottomRight?: Node) {\n * this.val = (val===undefined ? false : val)\n * this.isLeaf = (isLeaf===undefined ? false : isLeaf)\n * this.topLeft = (topLeft===undefined ? null : topLeft)\n * this.topRight = (topRight===undefined ? null : topRight)\n * this.bottomLeft = (bottomLeft===undefined ? null : bottomLeft)\n * this.bottomRight = (bottomRight===undefined ? null : bottomRight)\n * }\n * }\n */\n\nfunction intersect(quadTree1: Node | null, quadTree2: Node | null): Node | null {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0558](https://leetcode-cn.com/problems/logical-or-of-two-binary-grids-represented-as-quad-trees)", "[\u56db\u53c9\u6811\u4ea4\u96c6](/solution/0500-0599/0558.Logical%20OR%20of%20Two%20Binary%20Grids%20Represented%20as%20Quad-Trees/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0558](https://leetcode.com/problems/logical-or-of-two-binary-grids-represented-as-quad-trees)", "[Logical OR of Two Binary Grids Represented as Quad-Trees](/solution/0500-0599/0558.Logical%20OR%20of%20Two%20Binary%20Grids%20Represented%20as%20Quad-Trees/README_EN.md)", "", "Medium", ""]}, {"question_id": "0772", "frontend_question_id": "0427", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/construct-quad-tree", "url_en": "https://leetcode.com/problems/construct-quad-tree", "relative_path_cn": "/solution/0400-0499/0427.Construct%20Quad%20Tree/README.md", "relative_path_en": "/solution/0400-0499/0427.Construct%20Quad%20Tree/README_EN.md", "title_cn": "\u5efa\u7acb\u56db\u53c9\u6811", "title_en": "Construct Quad Tree", "question_title_slug": "construct-quad-tree", "content_en": "

Given a n * n matrix grid of 0's and 1's only. We want to represent the grid with a Quad-Tree.

\r\n\r\n

Return the root of the Quad-Tree representing the grid.

\r\n\r\n

Notice that you can assign the value of a node to True or False when isLeaf is False, and both are accepted in the answer.

\r\n\r\n

A Quad-Tree is a tree data structure in which each internal node has exactly four children. Besides, each node has two attributes:

\r\n\r\n
    \r\n\t
  • val: True if the node represents a grid of 1's or False if the node represents a grid of 0's. 
  • \r\n\t
  • isLeaf: True if the node is leaf node on the tree or False if the node has the four children.
  • \r\n
\r\n\r\n
\r\nclass Node {\r\n    public boolean val;\r\n    public boolean isLeaf;\r\n    public Node topLeft;\r\n    public Node topRight;\r\n    public Node bottomLeft;\r\n    public Node bottomRight;\r\n}
\r\n\r\n

We can construct a Quad-Tree from a two-dimensional area using the following steps:

\r\n\r\n
    \r\n\t
  1. If the current grid has the same value (i.e all 1's or all 0's) set isLeaf True and set val to the value of the grid and set the four children to Null and stop.
  2. \r\n\t
  3. If the current grid has different values, set isLeaf to False and set val to any value and divide the current grid into four sub-grids as shown in the photo.
  4. \r\n\t
  5. Recurse for each of the children with the proper sub-grid.
  6. \r\n
\r\n\"\"\r\n

If you want to know more about the Quad-Tree, you can refer to the wiki.

\r\n\r\n

Quad-Tree format:

\r\n\r\n

The output represents the serialized format of a Quad-Tree using level order traversal, where null signifies a path terminator where no node exists below.

\r\n\r\n

It is very similar to the serialization of the binary tree. The only difference is that the node is represented as a list [isLeaf, val].

\r\n\r\n

If the value of isLeaf or val is True we represent it as 1 in the list [isLeaf, val] and if the value of isLeaf or val is False we represent it as 0.

\r\n\n

 

\n

Example 1:

\n\"\"\n
\nInput: grid = [[0,1],[1,0]]\nOutput: [[0,1],[1,0],[1,1],[1,1],[1,0]]\nExplanation: The explanation of this example is shown below:\nNotice that 0 represnts False and 1 represents True in the photo representing the Quad-Tree.\n\"\"\n
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: grid = [[1,1,1,1,0,0,0,0],[1,1,1,1,0,0,0,0],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,0,0,0,0],[1,1,1,1,0,0,0,0],[1,1,1,1,0,0,0,0],[1,1,1,1,0,0,0,0]]\nOutput: [[0,1],[1,1],[0,1],[1,1],[1,0],null,null,null,null,[1,0],[1,0],[1,1],[1,1]]\nExplanation: All values in the grid are not the same. We divide the grid into four sub-grids.\nThe topLeft, bottomLeft and bottomRight each has the same value.\nThe topRight have different values so we divide it into 4 sub-grids where each has the same value.\nExplanation is shown in the photo below:\n\"\"\n
\n\n

Example 3:

\n\n
\nInput: grid = [[1,1],[1,1]]\nOutput: [[1,1]]\n
\n\n

Example 4:

\n\n
\nInput: grid = [[0]]\nOutput: [[1,0]]\n
\n\n

Example 5:

\n\n
\nInput: grid = [[1,1,0,0],[1,1,0,0],[0,0,1,1],[0,0,1,1]]\nOutput: [[0,1],[1,1],[1,0],[1,0],[1,1]]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • n == grid.length == grid[i].length
  • \n\t
  • n == 2^x where 0 <= x <= 6
  • \n
\n", "content_cn": "

\u7ed9\u4f60\u4e00\u4e2a n * n \u77e9\u9635 grid \uff0c\u77e9\u9635\u7531\u82e5\u5e72 0 \u548c 1 \u7ec4\u6210\u3002\u8bf7\u4f60\u7528\u56db\u53c9\u6811\u8868\u793a\u8be5\u77e9\u9635 grid \u3002

\n\n

\u4f60\u9700\u8981\u8fd4\u56de\u80fd\u8868\u793a\u77e9\u9635\u7684 \u56db\u53c9\u6811 \u7684\u6839\u7ed3\u70b9\u3002

\n\n

\u6ce8\u610f\uff0c\u5f53 isLeaf \u4e3a False \u65f6\uff0c\u4f60\u53ef\u4ee5\u628a True \u6216\u8005 False \u8d4b\u503c\u7ed9\u8282\u70b9\uff0c\u4e24\u79cd\u503c\u90fd\u4f1a\u88ab\u5224\u9898\u673a\u5236 \u63a5\u53d7 \u3002

\n\n

\u56db\u53c9\u6811\u6570\u636e\u7ed3\u6784\u4e2d\uff0c\u6bcf\u4e2a\u5185\u90e8\u8282\u70b9\u53ea\u6709\u56db\u4e2a\u5b50\u8282\u70b9\u3002\u6b64\u5916\uff0c\u6bcf\u4e2a\u8282\u70b9\u90fd\u6709\u4e24\u4e2a\u5c5e\u6027\uff1a

\n\n
    \n\t
  • val\uff1a\u50a8\u5b58\u53f6\u5b50\u7ed3\u70b9\u6240\u4ee3\u8868\u7684\u533a\u57df\u7684\u503c\u30021 \u5bf9\u5e94 True\uff0c0 \u5bf9\u5e94 False\uff1b
  • \n\t
  • isLeaf: \u5f53\u8fd9\u4e2a\u8282\u70b9\u662f\u4e00\u4e2a\u53f6\u5b50\u7ed3\u70b9\u65f6\u4e3a True\uff0c\u5982\u679c\u5b83\u6709 4 \u4e2a\u5b50\u8282\u70b9\u5219\u4e3a False \u3002
  • \n
\n\n
class Node {\n    public boolean val;\n    public boolean isLeaf;\n    public Node topLeft;\n    public Node topRight;\n    public Node bottomLeft;\n    public Node bottomRight;\n}
\n\n

\u6211\u4eec\u53ef\u4ee5\u6309\u4ee5\u4e0b\u6b65\u9aa4\u4e3a\u4e8c\u7ef4\u533a\u57df\u6784\u5efa\u56db\u53c9\u6811\uff1a

\n\n
    \n\t
  1. \u5982\u679c\u5f53\u524d\u7f51\u683c\u7684\u503c\u76f8\u540c\uff08\u5373\uff0c\u5168\u4e3a 0 \u6216\u8005\u5168\u4e3a 1\uff09\uff0c\u5c06 isLeaf \u8bbe\u4e3a True \uff0c\u5c06 val \u8bbe\u4e3a\u7f51\u683c\u76f8\u5e94\u7684\u503c\uff0c\u5e76\u5c06\u56db\u4e2a\u5b50\u8282\u70b9\u90fd\u8bbe\u4e3a Null \u7136\u540e\u505c\u6b62\u3002
  2. \n\t
  3. \u5982\u679c\u5f53\u524d\u7f51\u683c\u7684\u503c\u4e0d\u540c\uff0c\u5c06 isLeaf \u8bbe\u4e3a False\uff0c \u5c06 val \u8bbe\u4e3a\u4efb\u610f\u503c\uff0c\u7136\u540e\u5982\u4e0b\u56fe\u6240\u793a\uff0c\u5c06\u5f53\u524d\u7f51\u683c\u5212\u5206\u4e3a\u56db\u4e2a\u5b50\u7f51\u683c\u3002
  4. \n\t
  5. \u4f7f\u7528\u9002\u5f53\u7684\u5b50\u7f51\u683c\u9012\u5f52\u6bcf\u4e2a\u5b50\u8282\u70b9\u3002
  6. \n
\n\n

\"\"

\n\n

\u5982\u679c\u4f60\u60f3\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u56db\u53c9\u6811\u7684\u5185\u5bb9\uff0c\u53ef\u4ee5\u53c2\u8003 wiki \u3002

\n\n

\u56db\u53c9\u6811\u683c\u5f0f\uff1a

\n\n

\u8f93\u51fa\u4e3a\u4f7f\u7528\u5c42\u5e8f\u904d\u5386\u540e\u56db\u53c9\u6811\u7684\u5e8f\u5217\u5316\u5f62\u5f0f\uff0c\u5176\u4e2d null \u8868\u793a\u8def\u5f84\u7ec8\u6b62\u7b26\uff0c\u5176\u4e0b\u9762\u4e0d\u5b58\u5728\u8282\u70b9\u3002

\n\n

\u5b83\u4e0e\u4e8c\u53c9\u6811\u7684\u5e8f\u5217\u5316\u975e\u5e38\u76f8\u4f3c\u3002\u552f\u4e00\u7684\u533a\u522b\u662f\u8282\u70b9\u4ee5\u5217\u8868\u5f62\u5f0f\u8868\u793a [isLeaf, val] \u3002

\n\n

\u5982\u679c isLeaf \u6216\u8005 val \u7684\u503c\u4e3a True \uff0c\u5219\u8868\u793a\u5b83\u5728\u5217\u8868 [isLeaf, val] \u4e2d\u7684\u503c\u4e3a 1 \uff1b\u5982\u679c isLeaf \u6216\u8005 val \u7684\u503c\u4e3a False \uff0c\u5219\u8868\u793a\u503c\u4e3a 0 \u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1agrid = [[0,1],[1,0]]\n\u8f93\u51fa\uff1a[[0,1],[1,0],[1,1],[1,1],[1,0]]\n\u89e3\u91ca\uff1a\u6b64\u793a\u4f8b\u7684\u89e3\u91ca\u5982\u4e0b\uff1a\n\u8bf7\u6ce8\u610f\uff0c\u5728\u4e0b\u9762\u56db\u53c9\u6811\u7684\u56fe\u793a\u4e2d\uff0c0 \u8868\u793a false\uff0c1 \u8868\u793a True \u3002\n\"\"\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\u8f93\u5165\uff1agrid = [[1,1,1,1,0,0,0,0],[1,1,1,1,0,0,0,0],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,0,0,0,0],[1,1,1,1,0,0,0,0],[1,1,1,1,0,0,0,0],[1,1,1,1,0,0,0,0]]\n\u8f93\u51fa\uff1a[[0,1],[1,1],[0,1],[1,1],[1,0],null,null,null,null,[1,0],[1,0],[1,1],[1,1]]\n\u89e3\u91ca\uff1a\u7f51\u683c\u4e2d\u7684\u6240\u6709\u503c\u90fd\u4e0d\u76f8\u540c\u3002\u6211\u4eec\u5c06\u7f51\u683c\u5212\u5206\u4e3a\u56db\u4e2a\u5b50\u7f51\u683c\u3002\ntopLeft\uff0cbottomLeft \u548c bottomRight \u5747\u5177\u6709\u76f8\u540c\u7684\u503c\u3002\ntopRight \u5177\u6709\u4e0d\u540c\u7684\u503c\uff0c\u56e0\u6b64\u6211\u4eec\u5c06\u5176\u518d\u5206\u4e3a 4 \u4e2a\u5b50\u7f51\u683c\uff0c\u8fd9\u6837\u6bcf\u4e2a\u5b50\u7f51\u683c\u90fd\u5177\u6709\u76f8\u540c\u7684\u503c\u3002\n\u89e3\u91ca\u5982\u4e0b\u56fe\u6240\u793a\uff1a\n\"\"\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1agrid = [[1,1],[1,1]]\n\u8f93\u51fa\uff1a[[1,1]]\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\u8f93\u5165\uff1agrid = [[0]]\n\u8f93\u51fa\uff1a[[1,0]]\n
\n\n

\u793a\u4f8b 5\uff1a

\n\n
\u8f93\u5165\uff1agrid = [[1,1,0,0],[1,1,0,0],[0,0,1,1],[0,0,1,1]]\n\u8f93\u51fa\uff1a[[0,1],[1,1],[1,0],[1,0],[1,1]]\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. n == grid.length == grid[i].length
  2. \n\t
  3. n == 2^x \u5176\u4e2d 0 <= x <= 6
  4. \n
\n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n// Definition for a QuadTree node.\nclass Node {\npublic:\n bool val;\n bool isLeaf;\n Node* topLeft;\n Node* topRight;\n Node* bottomLeft;\n Node* bottomRight;\n \n Node() {\n val = false;\n isLeaf = false;\n topLeft = NULL;\n topRight = NULL;\n bottomLeft = NULL;\n bottomRight = NULL;\n }\n \n Node(bool _val, bool _isLeaf) {\n val = _val;\n isLeaf = _isLeaf;\n topLeft = NULL;\n topRight = NULL;\n bottomLeft = NULL;\n bottomRight = NULL;\n }\n \n Node(bool _val, bool _isLeaf, Node* _topLeft, Node* _topRight, Node* _bottomLeft, Node* _bottomRight) {\n val = _val;\n isLeaf = _isLeaf;\n topLeft = _topLeft;\n topRight = _topRight;\n bottomLeft = _bottomLeft;\n bottomRight = _bottomRight;\n }\n};\n*/\n\nclass Solution {\npublic:\n Node* construct(vector>& grid) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/*\n// Definition for a QuadTree node.\nclass Node {\n public boolean val;\n public boolean isLeaf;\n public Node topLeft;\n public Node topRight;\n public Node bottomLeft;\n public Node bottomRight;\n\n \n public Node() {\n this.val = false;\n this.isLeaf = false;\n this.topLeft = null;\n this.topRight = null;\n this.bottomLeft = null;\n this.bottomRight = null;\n }\n \n public Node(boolean val, boolean isLeaf) {\n this.val = val;\n this.isLeaf = isLeaf;\n this.topLeft = null;\n this.topRight = null;\n this.bottomLeft = null;\n this.bottomRight = null;\n }\n \n public Node(boolean val, boolean isLeaf, Node topLeft, Node topRight, Node bottomLeft, Node bottomRight) {\n this.val = val;\n this.isLeaf = isLeaf;\n this.topLeft = topLeft;\n this.topRight = topRight;\n this.bottomLeft = bottomLeft;\n this.bottomRight = bottomRight;\n }\n};\n*/\n\nclass Solution {\n public Node construct(int[][] grid) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "\"\"\"\n# Definition for a QuadTree node.\nclass Node(object):\n def __init__(self, val, isLeaf, topLeft, topRight, bottomLeft, bottomRight):\n self.val = val\n self.isLeaf = isLeaf\n self.topLeft = topLeft\n self.topRight = topRight\n self.bottomLeft = bottomLeft\n self.bottomRight = bottomRight\n\"\"\"\n\nclass Solution(object):\n def construct(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: Node\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "\"\"\"\n# Definition for a QuadTree node.\nclass Node:\n def __init__(self, val, isLeaf, topLeft, topRight, bottomLeft, bottomRight):\n self.val = val\n self.isLeaf = isLeaf\n self.topLeft = topLeft\n self.topRight = topRight\n self.bottomLeft = bottomLeft\n self.bottomRight = bottomRight\n\"\"\"\n\nclass Solution:\n def construct(self, grid: List[List[int]]) -> 'Node':\n ", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/*\n// Definition for a QuadTree node.\npublic class Node {\n public bool val;\n public bool isLeaf;\n public Node topLeft;\n public Node topRight;\n public Node bottomLeft;\n public Node bottomRight;\n\n public Node() {\n val = false;\n isLeaf = false;\n topLeft = null;\n topRight = null;\n bottomLeft = null;\n bottomRight = null;\n }\n \n public Node(bool _val, bool _isLeaf) {\n val = _val;\n isLeaf = _isLeaf;\n topLeft = null;\n topRight = null;\n bottomLeft = null;\n bottomRight = null;\n }\n \n public Node(bool _val,bool _isLeaf,Node _topLeft,Node _topRight,Node _bottomLeft,Node _bottomRight) {\n val = _val;\n isLeaf = _isLeaf;\n topLeft = _topLeft;\n topRight = _topRight;\n bottomLeft = _bottomLeft;\n bottomRight = _bottomRight;\n }\n}\n*/\n\npublic class Solution {\n public Node Construct(int[][] grid) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // Definition for a QuadTree node.\n * function Node(val,isLeaf,topLeft,topRight,bottomLeft,bottomRight) {\n * this.val = val;\n * this.isLeaf = isLeaf;\n * this.topLeft = topLeft;\n * this.topRight = topRight;\n * this.bottomLeft = bottomLeft;\n * this.bottomRight = bottomRight;\n * };\n */\n\n/**\n * @param {number[][]} grid\n * @return {Node}\n */\nvar construct = function(grid) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a QuadTree node.\n# class Node\n# attr_accessor :val, :isLeaf, :topLeft, :topRight, :bottomLeft, :bottomRight\n# def initialize(val=false, isLeaf=false, topLeft=nil, topRight=nil, bottomLeft=nil, bottomRight=nil)\n# @val = val\n# @isLeaf = isLeaf\n# @topLeft = topLeft\n# @topRight = topRight\n# @bottomLeft = bottomLeft\n# @bottomRight = bottomRight\n# end\n# end\n\n# @param {Integer[][]} grid\n# @return {Node}\ndef construct(grid)\n\t\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a QuadTree node.\n * public class Node {\n * public var val: Bool\n * public var isLeaf: Bool\n * public var topLeft: Node?\n * public var topRight: Node?\n * public var bottomLeft: Node?\n * public var bottomRight: Node?\n * public init(_ val: Bool, _ isLeaf: Bool) {\n * self.val = val\n * self.isLeaf = isLeaf\n * self.topLeft = nil\n * self.topRight = nil\n * self.bottomLeft = nil\n * self.bottomRight = nil\n * }\n * }\n */\n\nclass Solution {\n func construct(_ grid: [[Int]]) -> Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a QuadTree node.\n * type Node struct {\n * Val bool\n * IsLeaf bool\n * TopLeft *Node\n * TopRight *Node\n * BottomLeft *Node\n * BottomRight *Node\n * }\n */\n\nfunc construct(grid [][]int) *Node {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a QuadTree node.\n * class Node(var _value: Boolean, var _isLeaf: Boolean) {\n * var value: Int = _value\n * var isLeaf: Boolean = _isLeaf\n * var topLeft: Node = null\n * var topRight: Node = null\n * var bottomLeft: Node = null\n * var bottomRight: Node = null\n * }\n */\n\nobject Solution {\n def construct(grid: Array[Array[Int]]): Node = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a QuadTree node.\n * class Node(var `val`: Boolean, var isLeaf: Boolean) {\n * var topLeft: Node? = null\n * var topRight: Node? = null\n * var bottomLeft: Node? = null\n * var bottomRight: Node? = null\n * }\n */\n\nclass Solution {\n fun construct(grid: Array): Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a QuadTree node.\n * class Node {\n * public $val = null;\n * public $isLeaf = null;\n * public $topLeft = null;\n * public $topRight = null;\n * public $bottomLeft = null;\n * public $bottomRight = null;\n * function __construct($val, $isLeaf) {\n * $this->val = $val;\n * $this->isLeaf = $isLeaf;\n * $this->topLeft = null;\n * $this->topRight = null;\n * $this->bottomLeft = null;\n * $this->bottomRight = null;\n * }\n * }\n */\n\nclass Solution {\n /**\n * @param Integer[][] $grid\n * @return Node\n */\n function construct($grid) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for node.\n * class Node {\n * val: boolean\n * isLeaf: boolean\n * topLeft: Node | null\n * topRight: Node | null\n * bottomLeft: Node | null\n * bottomRight: Node | null\n * constructor(val?: boolean, isLeaf?: boolean, topLeft?: Node, topRight?: Node, bottomLeft?: Node, bottomRight?: Node) {\n * this.val = (val===undefined ? false : val)\n * this.isLeaf = (isLeaf===undefined ? false : isLeaf)\n * this.topLeft = (topLeft===undefined ? null : topLeft)\n * this.topRight = (topRight===undefined ? null : topRight)\n * this.bottomLeft = (bottomLeft===undefined ? null : bottomLeft)\n * this.bottomRight = (bottomRight===undefined ? null : bottomRight)\n * }\n * }\n */\n\nfunction construct(grid: number[][]): Node | null {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0427](https://leetcode-cn.com/problems/construct-quad-tree)", "[\u5efa\u7acb\u56db\u53c9\u6811](/solution/0400-0499/0427.Construct%20Quad%20Tree/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0427](https://leetcode.com/problems/construct-quad-tree)", "[Construct Quad Tree](/solution/0400-0499/0427.Construct%20Quad%20Tree/README_EN.md)", "", "Medium", ""]}, {"question_id": "0771", "frontend_question_id": "0431", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/encode-n-ary-tree-to-binary-tree", "url_en": "https://leetcode.com/problems/encode-n-ary-tree-to-binary-tree", "relative_path_cn": "/solution/0400-0499/0431.Encode%20N-ary%20Tree%20to%20Binary%20Tree/README.md", "relative_path_en": "/solution/0400-0499/0431.Encode%20N-ary%20Tree%20to%20Binary%20Tree/README_EN.md", "title_cn": "\u5c06 N \u53c9\u6811\u7f16\u7801\u4e3a\u4e8c\u53c9\u6811", "title_en": "Encode N-ary Tree to Binary Tree", "question_title_slug": "encode-n-ary-tree-to-binary-tree", "content_en": "

Design an algorithm to encode an N-ary tree into a binary tree and decode the binary tree to get the original N-ary tree. An N-ary tree is a rooted tree in which each node has no more than N children. Similarly, a binary tree is a rooted tree in which each node has no more than 2 children. There is no restriction on how your encode/decode algorithm should work. You just need to ensure that an N-ary tree can be encoded to a binary tree and this binary tree can be decoded to the original N-nary tree structure.

\n\n

Nary-Tree input serialization is represented in their level order traversal, each group of children is separated by the null value (See following example).

\n\n

For example, you may encode the following 3-ary tree to a binary tree in this way:

\n\n

\n\n
\nInput: root = [1,null,3,2,4,null,5,6]\n
\n\n

Note that the above is just an example which might or might not work. You do not necessarily need to follow this format, so please be creative and come up with different approaches yourself.

\n\n
    \n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The height of the n-ary tree is less than or equal to 1000
  • \n\t
  • The total number of nodes is between [0, 104]
  • \n\t
  • Do not use class member/global/static variables to store states. Your encode and decode algorithms should be stateless.
  • \n
\n", "content_cn": "

\u8bbe\u8ba1\u4e00\u4e2a\u7b97\u6cd5\uff0c\u53ef\u4ee5\u5c06 N \u53c9\u6811\u7f16\u7801\u4e3a\u4e8c\u53c9\u6811\uff0c\u5e76\u80fd\u5c06\u8be5\u4e8c\u53c9\u6811\u89e3\u7801\u4e3a\u539f N \u53c9\u6811\u3002\u4e00\u4e2a N \u53c9\u6811\u662f\u6307\u6bcf\u4e2a\u8282\u70b9\u90fd\u6709\u4e0d\u8d85\u8fc7 N \u4e2a\u5b69\u5b50\u8282\u70b9\u7684\u6709\u6839\u6811\u3002\u7c7b\u4f3c\u5730\uff0c\u4e00\u4e2a\u4e8c\u53c9\u6811\u662f\u6307\u6bcf\u4e2a\u8282\u70b9\u90fd\u6709\u4e0d\u8d85\u8fc7 2 \u4e2a\u5b69\u5b50\u8282\u70b9\u7684\u6709\u6839\u6811\u3002\u4f60\u7684\u7f16\u7801 / \u89e3\u7801\u7684\u7b97\u6cd5\u7684\u5b9e\u73b0\u6ca1\u6709\u9650\u5236\uff0c\u4f60\u53ea\u9700\u8981\u4fdd\u8bc1\u4e00\u4e2a N \u53c9\u6811\u53ef\u4ee5\u7f16\u7801\u4e3a\u4e8c\u53c9\u6811\u4e14\u8be5\u4e8c\u53c9\u6811\u53ef\u4ee5\u89e3\u7801\u56de\u539f\u59cb N \u53c9\u6811\u5373\u53ef\u3002

\n\n

\u4f8b\u5982\uff0c\u4f60\u53ef\u4ee5\u5c06\u4e0b\u9762\u7684 3-\u53c9 \u6811\u4ee5\u8be5\u79cd\u65b9\u5f0f\u7f16\u7801\uff1a

\n\n

 

\n\n

\n\n

 

\n\n

\u6ce8\u610f\uff0c\u4e0a\u9762\u7684\u65b9\u6cd5\u4ec5\u4ec5\u662f\u4e00\u4e2a\u4f8b\u5b50\uff0c\u53ef\u80fd\u53ef\u884c\u4e5f\u53ef\u80fd\u4e0d\u53ef\u884c\u3002\u4f60\u6ca1\u6709\u5fc5\u8981\u9075\u5faa\u8fd9\u79cd\u5f62\u5f0f\u8f6c\u5316\uff0c\u4f60\u53ef\u4ee5\u81ea\u5df1\u521b\u9020\u548c\u5b9e\u73b0\u4e0d\u540c\u7684\u65b9\u6cd5\u3002

\n\n

\u6ce8\u610f\uff1a

\n\n
    \n\t
  1. N \u7684\u8303\u56f4\u5728 [1, 1000]
  2. \n\t
  3. \u4e0d\u8981\u4f7f\u7528\u7c7b\u6210\u5458 / \u5168\u5c40\u53d8\u91cf / \u9759\u6001\u53d8\u91cf\u6765\u5b58\u50a8\u72b6\u6001\u3002\u4f60\u7684\u7f16\u7801\u548c\u89e3\u7801\u7b97\u6cd5\u5e94\u662f\u65e0\u72b6\u6001\u7684\u3002
  4. \n
\n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n vector children;\n\n Node() {}\n\n Node(int _val) {\n val = _val;\n }\n\n Node(int _val, vector _children) {\n val = _val;\n children = _children;\n }\n};\n*/\n\n/**\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\nclass Codec {\npublic:\n // Encodes an n-ary tree to a binary tree.\n TreeNode* encode(Node* root) {\n \n }\n\t\n // Decodes your binary tree to an n-ary tree.\n Node* decode(TreeNode* root) {\n \n }\n};\n\n// Your Codec object will be instantiated and called as such:\n// Codec codec;\n// codec.decode(codec.encode(root));", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/*\n// Definition for a Node.\nclass Node {\n public int val;\n public List children;\n\n public Node() {}\n\n public Node(int _val) {\n val = _val;\n }\n\n public Node(int _val, List _children) {\n val = _val;\n children = _children;\n }\n};\n*/\n\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode(int x) { val = x; }\n * }\n */\n\nclass Codec {\n // Encodes an n-ary tree to a binary tree.\n public TreeNode encode(Node root) {\n \n }\n\t\n // Decodes your binary tree to an n-ary tree.\n public Node decode(TreeNode root) {\n \n }\n}\n\n// Your Codec object will be instantiated and called as such:\n// Codec codec = new Codec();\n// codec.decode(codec.encode(root));", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "\"\"\"\n# Definition for a Node.\nclass Node(object):\n def __init__(self, val=None, children=None):\n self.val = val\n self.children = children\n\"\"\"\n\n\"\"\"\n# Definition for a binary tree node.\nclass TreeNode(object):\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\"\"\"\n\nclass Codec:\n def encode(self, root):\n \"\"\"Encodes an n-ary tree to a binary tree.\n :type root: Node\n :rtype: TreeNode\n \"\"\"\n \n\t\n def decode(self, data):\n \"\"\"Decodes your binary tree to an n-ary tree.\n :type data: TreeNode\n :rtype: Node\n \"\"\"\n \n\n# Your Codec object will be instantiated and called as such:\n# codec = Codec()\n# codec.decode(codec.encode(root))", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "\"\"\"\n# Definition for a Node.\nclass Node:\n def __init__(self, val=None, children=None):\n self.val = val\n self.children = children\n\"\"\"\n\n\"\"\"\n# Definition for a binary tree node.\nclass TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\"\"\"\n\nclass Codec:\n # Encodes an n-ary tree to a binary tree.\n def encode(self, root: 'Node') -> TreeNode:\n \n\t\n\t# Decodes your binary tree to an n-ary tree.\n def decode(self, data: TreeNode) -> 'Node':\n \n\n# Your Codec object will be instantiated and called as such:\n# codec = Codec()\n# codec.decode(codec.encode(root))", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/*\n// Definition for a Node.\npublic class Node {\n public int val;\n public IList children;\n\n public Node() {}\n\n public Node(int _val) {\n val = _val;\n }\n\n public Node(int _val, IList _children) {\n val = _val;\n children = _children;\n }\n}\n*/\n\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int x) { val = x; }\n * }\n */\n\npublic class Codec {\n // Encodes an n-ary tree to a binary tree.\n public TreeNode encode(Node root) {\n \n }\n \n // Decodes your binary tree to an n-ary tree.\n public Node decode(TreeNode root) {\n \n }\n}\n\n// Your Codec object will be instantiated and called as such:\n// Codec codec = new Codec();\n// codec.decode(codec.encode(root));", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // Definition for a Node.\n * function Node(val, children) {\n * this.val = val;\n * this.children = children;\n * };\n */\n\n/**\n * Definition for a binary tree node.\n * function TreeNode(val) {\n * this.val = val;\n * this.left = this.right = null;\n * }\n */\n\nclass Codec {\n \tconstructor() {\n }\n \n /** \n * @param {Node|null} root\n * @return {TreeNode|null}\n */\n // Encodes an n-ary tree to a binary tree.\n encode = function(root) {\n\t\t\n };\n\t\n /** \n * @param {TreeNode|null} root \n * @return {Node|null}\n */\n // Decodes your binary tree to an n-ary tree.\n decode = function(root) {\n\t\t\n };\n}\n\n/*\n* Your Codec object will be instantiated and called as such:\n* codec = Codec()\n* codec.decode(codec.encode(root))\n*/", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a Node.\n# class Node\n# attr_accessor :val, :children\n# def initialize(val=0, children=[])\n# @val = val\n# @children = children\n# end\n# end\n\n# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val)\n# @val = val\n# @left, @right = nil, nil\n# end\n# end\n\nclass Codec\n # Encodes an n-ary tree to a binary tree.\n # @param {Node} root\n\t# @return {TreeNode}\n def encode(root)\n \t\n end\n \n # Decodes your binary tree to an n-ary tree.\n # @param {TreeNode} root\n\t# @return {Node}\n def decode(root)\n \n end\nend\n\n# Your Codec object will be instantiated and called as such:\n# obj = Codec.new()\n# data = obj.encode(root)\n# ans = obj.decode(data)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a Node.\n * public class Node {\n * public var val: Int\n * public var children: [Node]\n * public init(_ val: Int) {\n * self.val = val\n * self.children = []\n * }\n * }\n */\n\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.left = nil\n * self.right = nil\n * }\n * }\n */\n\nclass Codec {\n func encode(_ root: Node?) -> TreeNode? {\n \n }\n \n func decode(_ root: TreeNode?) -> Node? {\n \n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * let obj = Codec()\n * let ret_1: TreeNode? = obj.encode(root)\n * let ret_2: Node? = obj.decode(root)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a Node.\n * type Node struct {\n * Val int\n * Children []*Node\n * }\n */\n\n/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\n\ntype Codec struct {\n \n}\n\nfunc Constructor() *Codec {\n \n}\n\nfunc (this *Codec) encode(root *Node) *TreeNode {\n \n}\n\nfunc (this *Codec) decode(root *TreeNode) *Node {\n \n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * obj := Constructor();\n * bst := obj.encode(root);\n * ans := obj.decode(bst);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a Node.\n * class Node(var _value: Int) {\n * var value: Int = _value\n * var children: List[Node] = List()\n * }\n */\n\n/**\n * Definition for a binary tree node.\n * class TreeNode(var _value: Int) {\n * var value: Int = _value\n * var left: TreeNode = null\n * var right: TreeNode = null\n * }\n */\n\nclass Codec {\n // Encodes an n-ary tree to a binary tree.\n def encode(root: Node): TreeNode = {\n \n }\n \n // Decodes your binary tree to an n-ary tree.\n def decode(root: TreeNode): Node = {\n \n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * var obj = new Codec()\n * var data = obj.encode(root)\n * var ans = obj.decode(data)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a Node.\n * class Node(var `val`: Int) {\n * var children: List = listOf()\n * }\n */\n\n/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\n\nclass Codec {\n // Encodes a tree to a single string.\n fun encode(root: Node?): TreeNode? {\n \n }\n \n // Decodes your encoded data to tree.\n fun decode(root: TreeNode?): Node? {\n \n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * var obj = Codec()\n * var data = obj.encode(root)\n * var ans = obj.decode(data)\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a Node.\n * class Node {\n * public $val = null;\n * public $children = null;\n * function __construct($val = 0) {\n * $this->val = $val;\n * $this->children = array();\n * }\n * }\n */\n\n/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\n\nclass Codec {\n /**\n * @param Node $root\n * @return TreeNode\n */\n function encode($root) {\n \t\n }\n \n /**\n * @param TreeNode $root\n * @return Node\n */\n function decode($root) {\n \n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * $obj = Codec();\n * $ret_1 = $obj->encode($root);\n * $ret_2 = $obj->decode($root);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for node.\n * class Node {\n * val: number\n * children: Node[]\n * constructor(val?: number) {\n * this.val = (val===undefined ? 0 : val)\n * this.children = []\n * }\n * }\n */\n\n/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nclass Codec {\n \tconstructor() {\n \n }\n \n // Encodes a tree to a binary tree.\n serialize(root: Node | null): TreeNode | null {\n \n };\n\t\n // Decodes your encoded data to tree.\n deserialize(root: TreeNode | null): Node | null {\n \n };\n}\n\n// Your Codec object will be instantiated and called as such:\n// Codec codec = new Codec();\n// codec.deserialize(codec.serialize(root));", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0431](https://leetcode-cn.com/problems/encode-n-ary-tree-to-binary-tree)", "[\u5c06 N \u53c9\u6811\u7f16\u7801\u4e3a\u4e8c\u53c9\u6811](/solution/0400-0499/0431.Encode%20N-ary%20Tree%20to%20Binary%20Tree/README.md)", "`\u6811`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0431](https://leetcode.com/problems/encode-n-ary-tree-to-binary-tree)", "[Encode N-ary Tree to Binary Tree](/solution/0400-0499/0431.Encode%20N-ary%20Tree%20to%20Binary%20Tree/README_EN.md)", "`Tree`", "Hard", "\ud83d\udd12"]}, {"question_id": "0770", "frontend_question_id": "0765", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/couples-holding-hands", "url_en": "https://leetcode.com/problems/couples-holding-hands", "relative_path_cn": "/solution/0700-0799/0765.Couples%20Holding%20Hands/README.md", "relative_path_en": "/solution/0700-0799/0765.Couples%20Holding%20Hands/README_EN.md", "title_cn": "\u60c5\u4fa3\u7275\u624b", "title_en": "Couples Holding Hands", "question_title_slug": "couples-holding-hands", "content_en": "

\r\nN couples sit in 2N seats arranged in a row and want to hold hands. We want to know the minimum number of swaps so that every couple is sitting side by side. A swap consists of choosing any two people, then they stand up and switch seats. \r\n

\r\nThe people and seats are represented by an integer from 0 to 2N-1, the couples are numbered in order, the first couple being (0, 1), the second couple being (2, 3), and so on with the last couple being (2N-2, 2N-1).\r\n

\r\nThe couples' initial seating is given by row[i] being the value of the person who is initially sitting in the i-th seat.\r\n\r\n

Example 1:

\r\nInput: row = [0, 2, 1, 3]\r\nOutput: 1\r\nExplanation: We only need to swap the second (row[1]) and third (row[2]) person.\r\n

\r\n\r\n

Example 2:

\r\nInput: row = [3, 2, 0, 1]\r\nOutput: 0\r\nExplanation: All couples are already seated side by side.\r\n

\r\n\r\n

\r\nNote:\r\n

    \r\n
  1. len(row) is even and in the range of [4, 60].
  2. \r\n
  3. row is guaranteed to be a permutation of 0...len(row)-1.
  4. \r\n
", "content_cn": "

N \u5bf9\u60c5\u4fa3\u5750\u5728\u8fde\u7eed\u6392\u5217\u7684 2N \u4e2a\u5ea7\u4f4d\u4e0a\uff0c\u60f3\u8981\u7275\u5230\u5bf9\u65b9\u7684\u624b\u3002 \u8ba1\u7b97\u6700\u5c11\u4ea4\u6362\u5ea7\u4f4d\u7684\u6b21\u6570\uff0c\u4ee5\u4fbf\u6bcf\u5bf9\u60c5\u4fa3\u53ef\u4ee5\u5e76\u80a9\u5750\u5728\u4e00\u8d77\u3002 \u4e00\u6b21\u4ea4\u6362\u53ef\u9009\u62e9\u4efb\u610f\u4e24\u4eba\uff0c\u8ba9\u4ed6\u4eec\u7ad9\u8d77\u6765\u4ea4\u6362\u5ea7\u4f4d\u3002

\n\n

\u4eba\u548c\u5ea7\u4f4d\u7528 0 \u5230 2N-1 \u7684\u6574\u6570\u8868\u793a\uff0c\u60c5\u4fa3\u4eec\u6309\u987a\u5e8f\u7f16\u53f7\uff0c\u7b2c\u4e00\u5bf9\u662f (0, 1)\uff0c\u7b2c\u4e8c\u5bf9\u662f (2, 3)\uff0c\u4ee5\u6b64\u7c7b\u63a8\uff0c\u6700\u540e\u4e00\u5bf9\u662f (2N-2, 2N-1)\u3002

\n\n

\u8fd9\u4e9b\u60c5\u4fa3\u7684\u521d\u59cb\u5ea7\u4f4d  row[i] \u662f\u7531\u6700\u521d\u59cb\u5750\u5728\u7b2c i \u4e2a\u5ea7\u4f4d\u4e0a\u7684\u4eba\u51b3\u5b9a\u7684\u3002

\n\n

\u793a\u4f8b 1:

\n\n
\n\u8f93\u5165: row = [0, 2, 1, 3]\n\u8f93\u51fa: 1\n\u89e3\u91ca: \u6211\u4eec\u53ea\u9700\u8981\u4ea4\u6362row[1]\u548crow[2]\u7684\u4f4d\u7f6e\u5373\u53ef\u3002\n
\n\n

\u793a\u4f8b 2:

\n\n
\n\u8f93\u5165: row = [3, 2, 0, 1]\n\u8f93\u51fa: 0\n\u89e3\u91ca: \u65e0\u9700\u4ea4\u6362\u5ea7\u4f4d\uff0c\u6240\u6709\u7684\u60c5\u4fa3\u90fd\u5df2\u7ecf\u53ef\u4ee5\u624b\u7275\u624b\u4e86\u3002\n
\n\n

\u8bf4\u660e:

\n\n
    \n\t
  1. len(row) \u662f\u5076\u6570\u4e14\u6570\u503c\u5728 [4, 60]\u8303\u56f4\u5185\u3002
  2. \n\t
  3. \u53ef\u4ee5\u4fdd\u8bc1row \u662f\u5e8f\u5217 0...len(row)-1 \u7684\u4e00\u4e2a\u5168\u6392\u5217\u3002
  4. \n
\n", "tags_en": ["Greedy", "Union Find", "Graph"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u5e76\u67e5\u96c6", "\u56fe"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minSwapsCouples(vector& row) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minSwapsCouples(int[] row) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minSwapsCouples(self, row):\n \"\"\"\n :type row: List[int]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minSwapsCouples(self, row: List[int]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minSwapsCouples(int* row, int rowSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinSwapsCouples(int[] row) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} row\n * @return {number}\n */\nvar minSwapsCouples = function(row) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} row\n# @return {Integer}\ndef min_swaps_couples(row)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minSwapsCouples(_ row: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minSwapsCouples(row []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minSwapsCouples(row: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minSwapsCouples(row: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_swaps_couples(row: Vec) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $row\n * @return Integer\n */\n function minSwapsCouples($row) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minSwapsCouples(row: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-swaps-couples row)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0765](https://leetcode-cn.com/problems/couples-holding-hands)", "[\u60c5\u4fa3\u7275\u624b](/solution/0700-0799/0765.Couples%20Holding%20Hands/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u5e76\u67e5\u96c6`,`\u56fe`", "\u56f0\u96be", ""], "md_table_row_en": ["[0765](https://leetcode.com/problems/couples-holding-hands)", "[Couples Holding Hands](/solution/0700-0799/0765.Couples%20Holding%20Hands/README_EN.md)", "`Greedy`,`Union Find`,`Graph`", "Hard", ""]}, {"question_id": "0769", "frontend_question_id": "0764", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/largest-plus-sign", "url_en": "https://leetcode.com/problems/largest-plus-sign", "relative_path_cn": "/solution/0700-0799/0764.Largest%20Plus%20Sign/README.md", "relative_path_en": "/solution/0700-0799/0764.Largest%20Plus%20Sign/README_EN.md", "title_cn": "\u6700\u5927\u52a0\u53f7\u6807\u5fd7", "title_en": "Largest Plus Sign", "question_title_slug": "largest-plus-sign", "content_en": "

In a 2D grid from (0, 0) to (n-1, n-1), every cell contains a 1, except those cells in the given list mines which are 0. What is the largest axis-aligned plus sign of 1s contained in the grid? Return the order of the plus sign. If there is none, return 0.

\n\n

An "axis-aligned plus sign of 1s of order k" has some center grid[x][y] = 1 along with 4 arms of length k-1 going up, down, left, and right, and made of 1s. This is demonstrated in the diagrams below. Note that there could be 0s or 1s beyond the arms of the plus sign, only the relevant area of the plus sign is checked for 1s.

\n\n

Examples of Axis-Aligned Plus Signs of Order k:

\n\n
\nOrder 1:\n000\n010\n000\n\nOrder 2:\n00000\n00100\n01110\n00100\n00000\n\nOrder 3:\n0000000\n0001000\n0001000\n0111110\n0001000\n0001000\n0000000\n
\n\n

Example 1:

\n\n
\nInput: n = 5, mines = [[4, 2]]\nOutput: 2\nExplanation:\n11111\n11111\n11111\n11111\n11011\nIn the above grid, the largest plus sign can only be order 2.  One of them is marked in bold.\n
\n\n

Example 2:

\n\n
\nInput: n = 2, mines = []\nOutput: 1\nExplanation:\nThere is no plus sign of order 2, but there is of order 1.\n
\n\n

Example 3:

\n\n
\nInput: n = 1, mines = [[0, 0]]\nOutput: 0\nExplanation:\nThere is no plus sign, so return 0.\n
\n\n

Note:

\n\n
    \n\t
  1. n will be an integer in the range [1, 500].
  2. \n\t
  3. mines will have length at most 5000.
  4. \n\t
  5. mines[i] will be length 2 and consist of integers in the range [0, n-1].
  6. \n\t
  7. (Additionally, programs submitted in C, C++, or C# will be judged with a slightly smaller time limit.)
  8. \n
\n\n

 

\n", "content_cn": "

\u5728\u4e00\u4e2a\u5927\u5c0f\u5728 (0, 0) \u5230 (N-1, N-1) \u76842D\u7f51\u683c grid \u4e2d\uff0c\u9664\u4e86\u5728 mines \u4e2d\u7ed9\u51fa\u7684\u5355\u5143\u4e3a 0\uff0c\u5176\u4ed6\u6bcf\u4e2a\u5355\u5143\u90fd\u662f 1\u3002\u7f51\u683c\u4e2d\u5305\u542b 1 \u7684\u6700\u5927\u7684\u8f74\u5bf9\u9f50\u52a0\u53f7\u6807\u5fd7\u662f\u591a\u5c11\u9636\uff1f\u8fd4\u56de\u52a0\u53f7\u6807\u5fd7\u7684\u9636\u6570\u3002\u5982\u679c\u672a\u627e\u5230\u52a0\u53f7\u6807\u5fd7\uff0c\u5219\u8fd4\u56de 0\u3002

\n\n

\u4e00\u4e2a k" \u9636\u7531 1 \u7ec4\u6210\u7684“\u8f74\u5bf9\u79f0”\u52a0\u53f7\u6807\u5fd7\u5177\u6709\u4e2d\u5fc3\u7f51\u683c  grid[x][y] = 1 \uff0c\u4ee5\u53ca4\u4e2a\u4ece\u4e2d\u5fc3\u5411\u4e0a\u3001\u5411\u4e0b\u3001\u5411\u5de6\u3001\u5411\u53f3\u5ef6\u4f38\uff0c\u957f\u5ea6\u4e3a k-1\uff0c\u7531 1 \u7ec4\u6210\u7684\u81c2\u3002\u4e0b\u9762\u7ed9\u51fa k" \u9636“\u8f74\u5bf9\u79f0”\u52a0\u53f7\u6807\u5fd7\u7684\u793a\u4f8b\u3002\u6ce8\u610f\uff0c\u53ea\u6709\u52a0\u53f7\u6807\u5fd7\u7684\u6240\u6709\u7f51\u683c\u8981\u6c42\u4e3a 1\uff0c\u522b\u7684\u7f51\u683c\u53ef\u80fd\u4e3a 0 \u4e5f\u53ef\u80fd\u4e3a 1\u3002

\n\n

 

\n\n

k \u9636\u8f74\u5bf9\u79f0\u52a0\u53f7\u6807\u5fd7\u793a\u4f8b:

\n\n
\n\u9636 1:\n000\n010\n000\n\n\u9636 2:\n00000\n00100\n01110\n00100\n00000\n\n\u9636 3:\n0000000\n0001000\n0001000\n0111110\n0001000\n0001000\n0000000\n
\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165: N = 5, mines = [[4, 2]]\n\u8f93\u51fa: 2\n\u89e3\u91ca:\n\n11111\n11111\n11111\n11111\n11011\n\n\u5728\u4e0a\u9762\u7684\u7f51\u683c\u4e2d\uff0c\u6700\u5927\u52a0\u53f7\u6807\u5fd7\u7684\u9636\u53ea\u80fd\u662f2\u3002\u4e00\u4e2a\u6807\u5fd7\u5df2\u5728\u56fe\u4e2d\u6807\u51fa\u3002\n
\n\n

 

\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165: N = 2, mines = []\n\u8f93\u51fa: 1\n\u89e3\u91ca:\n\n11\n11\n\n\u6ca1\u6709 2 \u9636\u52a0\u53f7\u6807\u5fd7\uff0c\u6709 1 \u9636\u52a0\u53f7\u6807\u5fd7\u3002\n
\n\n

 

\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165: N = 1, mines = [[0, 0]]\n\u8f93\u51fa: 0\n\u89e3\u91ca:\n\n0\n\n\u6ca1\u6709\u52a0\u53f7\u6807\u5fd7\uff0c\u8fd4\u56de 0 \u3002\n
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  1. \u6574\u6570N \u7684\u8303\u56f4\uff1a [1, 500].
  2. \n\t
  3. mines \u7684\u6700\u5927\u957f\u5ea6\u4e3a 5000.
  4. \n\t
  5. mines[i] \u662f\u957f\u5ea6\u4e3a2\u7684\u75312\u4e2a [0, N-1] \u4e2d\u7684\u6570\u7ec4\u6210.
  6. \n\t
  7. (\u53e6\u5916,\u4f7f\u7528 C, C++, \u6216\u8005 C# \u7f16\u7a0b\u5c06\u4ee5\u7a0d\u5c0f\u7684\u65f6\u95f4\u9650\u5236\u8fdb\u884c\u200b\u200b\u5224\u65ad.)
  8. \n
\n\n

 

\n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int orderOfLargestPlusSign(int n, vector>& mines) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int orderOfLargestPlusSign(int n, int[][] mines) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def orderOfLargestPlusSign(self, n, mines):\n \"\"\"\n :type n: int\n :type mines: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def orderOfLargestPlusSign(self, n: int, mines: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint orderOfLargestPlusSign(int n, int** mines, int minesSize, int* minesColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int OrderOfLargestPlusSign(int n, int[][] mines) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} mines\n * @return {number}\n */\nvar orderOfLargestPlusSign = function(n, mines) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} mines\n# @return {Integer}\ndef order_of_largest_plus_sign(n, mines)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func orderOfLargestPlusSign(_ n: Int, _ mines: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func orderOfLargestPlusSign(n int, mines [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def orderOfLargestPlusSign(n: Int, mines: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun orderOfLargestPlusSign(n: Int, mines: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn order_of_largest_plus_sign(n: i32, mines: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $mines\n * @return Integer\n */\n function orderOfLargestPlusSign($n, $mines) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function orderOfLargestPlusSign(n: number, mines: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (order-of-largest-plus-sign n mines)\n (-> exact-integer? (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0764](https://leetcode-cn.com/problems/largest-plus-sign)", "[\u6700\u5927\u52a0\u53f7\u6807\u5fd7](/solution/0700-0799/0764.Largest%20Plus%20Sign/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0764](https://leetcode.com/problems/largest-plus-sign)", "[Largest Plus Sign](/solution/0700-0799/0764.Largest%20Plus%20Sign/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0768", "frontend_question_id": "0763", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/partition-labels", "url_en": "https://leetcode.com/problems/partition-labels", "relative_path_cn": "/solution/0700-0799/0763.Partition%20Labels/README.md", "relative_path_en": "/solution/0700-0799/0763.Partition%20Labels/README_EN.md", "title_cn": "\u5212\u5206\u5b57\u6bcd\u533a\u95f4", "title_en": "Partition Labels", "question_title_slug": "partition-labels", "content_en": "

A string s of lowercase English letters is given. We want to partition this string into as many parts as possible so that each letter appears in at most one part, and return a list of integers representing the size of these parts.

\n\n

 

\n\n

Example 1:

\n\n
\nInput: s = "ababcbacadefegdehijhklij"\nOutput: [9,7,8]\nExplanation:\nThe partition is "ababcbaca", "defegde", "hijhklij".\nThis is a partition so that each letter appears in at most one part.\nA partition like "ababcbacadefegde", "hijhklij" is incorrect, because it splits s into less parts.\n
\n\n

 

\n\n

Note:

\n\n
    \n\t
  • s will have length in range [1, 500].
  • \n\t
  • s will consist of lowercase English letters ('a' to 'z') only.
  • \n
\n\n

 

\n", "content_cn": "

\u5b57\u7b26\u4e32 S \u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210\u3002\u6211\u4eec\u8981\u628a\u8fd9\u4e2a\u5b57\u7b26\u4e32\u5212\u5206\u4e3a\u5c3d\u53ef\u80fd\u591a\u7684\u7247\u6bb5\uff0c\u540c\u4e00\u5b57\u6bcd\u6700\u591a\u51fa\u73b0\u5728\u4e00\u4e2a\u7247\u6bb5\u4e2d\u3002\u8fd4\u56de\u4e00\u4e2a\u8868\u793a\u6bcf\u4e2a\u5b57\u7b26\u4e32\u7247\u6bb5\u7684\u957f\u5ea6\u7684\u5217\u8868\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b\uff1a

\n\n
\n\u8f93\u5165\uff1aS = \"ababcbacadefegdehijhklij\"\n\u8f93\u51fa\uff1a[9,7,8]\n\u89e3\u91ca\uff1a\n\u5212\u5206\u7ed3\u679c\u4e3a \"ababcbaca\", \"defegde\", \"hijhklij\"\u3002\n\u6bcf\u4e2a\u5b57\u6bcd\u6700\u591a\u51fa\u73b0\u5728\u4e00\u4e2a\u7247\u6bb5\u4e2d\u3002\n\u50cf \"ababcbacadefegde\", \"hijhklij\" \u7684\u5212\u5206\u662f\u9519\u8bef\u7684\uff0c\u56e0\u4e3a\u5212\u5206\u7684\u7247\u6bb5\u6570\u8f83\u5c11\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • S\u7684\u957f\u5ea6\u5728[1, 500]\u4e4b\u95f4\u3002
  • \n\t
  • S\u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd 'a' \u5230 'z' \u3002
  • \n
\n", "tags_en": ["Greedy", "Two Pointers"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector partitionLabels(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List partitionLabels(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def partitionLabels(self, s):\n \"\"\"\n :type s: str\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def partitionLabels(self, s: str) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* partitionLabels(char * s, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList PartitionLabels(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number[]}\n */\nvar partitionLabels = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer[]}\ndef partition_labels(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func partitionLabels(_ s: String) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func partitionLabels(s string) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def partitionLabels(s: String): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun partitionLabels(s: String): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn partition_labels(s: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer[]\n */\n function partitionLabels($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function partitionLabels(s: string): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (partition-labels s)\n (-> string? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0763](https://leetcode-cn.com/problems/partition-labels)", "[\u5212\u5206\u5b57\u6bcd\u533a\u95f4](/solution/0700-0799/0763.Partition%20Labels/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0763](https://leetcode.com/problems/partition-labels)", "[Partition Labels](/solution/0700-0799/0763.Partition%20Labels/README_EN.md)", "`Greedy`,`Two Pointers`", "Medium", ""]}, {"question_id": "0767", "frontend_question_id": "0762", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/prime-number-of-set-bits-in-binary-representation", "url_en": "https://leetcode.com/problems/prime-number-of-set-bits-in-binary-representation", "relative_path_cn": "/solution/0700-0799/0762.Prime%20Number%20of%20Set%20Bits%20in%20Binary%20Representation/README.md", "relative_path_en": "/solution/0700-0799/0762.Prime%20Number%20of%20Set%20Bits%20in%20Binary%20Representation/README_EN.md", "title_cn": "\u4e8c\u8fdb\u5236\u8868\u793a\u4e2d\u8d28\u6570\u4e2a\u8ba1\u7b97\u7f6e\u4f4d", "title_en": "Prime Number of Set Bits in Binary Representation", "question_title_slug": "prime-number-of-set-bits-in-binary-representation", "content_en": "

Given two integers left and right, find the count of numbers in the range [left, right] (inclusive) having a prime number of set bits in their binary representation.

\n\n

(Recall that the number of set bits an integer has is the number of 1s present when written in binary. For example, 21 written in binary is 10101 which has 3 set bits. Also, 1 is not a prime.)

\n\n

Example 1:

\n\n
\nInput: left = 6, right = 10\nOutput: 4\nExplanation:\n6 -> 110 (2 set bits, 2 is prime)\n7 -> 111 (3 set bits, 3 is prime)\n9 -> 1001 (2 set bits , 2 is prime)\n10->1010 (2 set bits , 2 is prime)\n
\n\n

Example 2:

\n\n
\nInput: left = 10, right = 15\nOutput: 5\nExplanation:\n10 -> 1010 (2 set bits, 2 is prime)\n11 -> 1011 (3 set bits, 3 is prime)\n12 -> 1100 (2 set bits, 2 is prime)\n13 -> 1101 (3 set bits, 3 is prime)\n14 -> 1110 (3 set bits, 3 is prime)\n15 -> 1111 (4 set bits, 4 is not prime)\n
\n\n

Note:

\n\n
    \n\t
  1. left, right will be integers left <= right in the range [1, 10^6].
  2. \n\t
  3. right - left will be at most 10000.
  4. \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e24\u4e2a\u6574\u6570 L \u548c R \uff0c\u627e\u5230\u95ed\u533a\u95f4 [L, R] \u8303\u56f4\u5185\uff0c\u8ba1\u7b97\u7f6e\u4f4d\u4f4d\u6570\u4e3a\u8d28\u6570\u7684\u6574\u6570\u4e2a\u6570\u3002

\n\n

\uff08\u6ce8\u610f\uff0c\u8ba1\u7b97\u7f6e\u4f4d\u4ee3\u8868\u4e8c\u8fdb\u5236\u8868\u793a\u4e2d1\u7684\u4e2a\u6570\u3002\u4f8b\u5982 21 \u7684\u4e8c\u8fdb\u5236\u8868\u793a 10101 \u6709 3 \u4e2a\u8ba1\u7b97\u7f6e\u4f4d\u3002\u8fd8\u6709\uff0c1 \u4e0d\u662f\u8d28\u6570\u3002\uff09

\n\n

\u793a\u4f8b 1:

\n\n
\n\u8f93\u5165: L = 6, R = 10\n\u8f93\u51fa: 4\n\u89e3\u91ca:\n6 -> 110 (2 \u4e2a\u8ba1\u7b97\u7f6e\u4f4d\uff0c2 \u662f\u8d28\u6570)\n7 -> 111 (3 \u4e2a\u8ba1\u7b97\u7f6e\u4f4d\uff0c3 \u662f\u8d28\u6570)\n9 -> 1001 (2 \u4e2a\u8ba1\u7b97\u7f6e\u4f4d\uff0c2 \u662f\u8d28\u6570)\n10-> 1010 (2 \u4e2a\u8ba1\u7b97\u7f6e\u4f4d\uff0c2 \u662f\u8d28\u6570)\n
\n\n

\u793a\u4f8b 2:

\n\n
\n\u8f93\u5165: L = 10, R = 15\n\u8f93\u51fa: 5\n\u89e3\u91ca:\n10 -> 1010 (2 \u4e2a\u8ba1\u7b97\u7f6e\u4f4d, 2 \u662f\u8d28\u6570)\n11 -> 1011 (3 \u4e2a\u8ba1\u7b97\u7f6e\u4f4d, 3 \u662f\u8d28\u6570)\n12 -> 1100 (2 \u4e2a\u8ba1\u7b97\u7f6e\u4f4d, 2 \u662f\u8d28\u6570)\n13 -> 1101 (3 \u4e2a\u8ba1\u7b97\u7f6e\u4f4d, 3 \u662f\u8d28\u6570)\n14 -> 1110 (3 \u4e2a\u8ba1\u7b97\u7f6e\u4f4d, 3 \u662f\u8d28\u6570)\n15 -> 1111 (4 \u4e2a\u8ba1\u7b97\u7f6e\u4f4d, 4 \u4e0d\u662f\u8d28\u6570)\n
\n\n

\u6ce8\u610f:

\n\n
    \n\t
  1. L, R \u662f L <= R \u4e14\u5728 [1, 10^6] \u4e2d\u7684\u6574\u6570\u3002
  2. \n\t
  3. R - L \u7684\u6700\u5927\u503c\u4e3a 10000\u3002
  4. \n
\n", "tags_en": ["Bit Manipulation"], "tags_cn": ["\u4f4d\u8fd0\u7b97"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countPrimeSetBits(int left, int right) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countPrimeSetBits(int left, int right) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countPrimeSetBits(self, left, right):\n \"\"\"\n :type left: int\n :type right: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countPrimeSetBits(self, left: int, right: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countPrimeSetBits(int left, int right){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountPrimeSetBits(int left, int right) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} left\n * @param {number} right\n * @return {number}\n */\nvar countPrimeSetBits = function(left, right) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} left\n# @param {Integer} right\n# @return {Integer}\ndef count_prime_set_bits(left, right)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countPrimeSetBits(_ left: Int, _ right: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countPrimeSetBits(left int, right int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countPrimeSetBits(left: Int, right: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countPrimeSetBits(left: Int, right: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_prime_set_bits(left: i32, right: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $left\n * @param Integer $right\n * @return Integer\n */\n function countPrimeSetBits($left, $right) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countPrimeSetBits(left: number, right: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-prime-set-bits left right)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0762](https://leetcode-cn.com/problems/prime-number-of-set-bits-in-binary-representation)", "[\u4e8c\u8fdb\u5236\u8868\u793a\u4e2d\u8d28\u6570\u4e2a\u8ba1\u7b97\u7f6e\u4f4d](/solution/0700-0799/0762.Prime%20Number%20of%20Set%20Bits%20in%20Binary%20Representation/README.md)", "`\u4f4d\u8fd0\u7b97`", "\u7b80\u5355", ""], "md_table_row_en": ["[0762](https://leetcode.com/problems/prime-number-of-set-bits-in-binary-representation)", "[Prime Number of Set Bits in Binary Representation](/solution/0700-0799/0762.Prime%20Number%20of%20Set%20Bits%20in%20Binary%20Representation/README_EN.md)", "`Bit Manipulation`", "Easy", ""]}, {"question_id": "0766", "frontend_question_id": "0430", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/flatten-a-multilevel-doubly-linked-list", "url_en": "https://leetcode.com/problems/flatten-a-multilevel-doubly-linked-list", "relative_path_cn": "/solution/0400-0499/0430.Flatten%20a%20Multilevel%20Doubly%20Linked%20List/README.md", "relative_path_en": "/solution/0400-0499/0430.Flatten%20a%20Multilevel%20Doubly%20Linked%20List/README_EN.md", "title_cn": "\u6241\u5e73\u5316\u591a\u7ea7\u53cc\u5411\u94fe\u8868", "title_en": "Flatten a Multilevel Doubly Linked List", "question_title_slug": "flatten-a-multilevel-doubly-linked-list", "content_en": "

You are given a doubly linked list which in addition to the next and previous pointers, it could have a child pointer, which may or may not point to a separate doubly linked list. These child lists may have one or more children of their own, and so on, to produce a multilevel data structure, as shown in the example below.

\r\n\r\n

Flatten the list so that all the nodes appear in a single-level, doubly linked list. You are given the head of the first level of the list.

\r\n\n

 

\n

Example 1:

\n\n
\nInput: head = [1,2,3,4,5,6,null,null,null,7,8,9,10,null,null,11,12]\nOutput: [1,2,3,7,8,11,12,9,10,4,5,6]\nExplanation:\n\nThe multilevel linked list in the input is as follows:\n\n\n\nAfter flattening the multilevel linked list it becomes:\n\n\n
\n\n

Example 2:

\n\n
\nInput: head = [1,2,null,3]\nOutput: [1,3,2]\nExplanation:\n\nThe input multilevel linked list is as follows:\n\n  1---2---NULL\n  |\n  3---NULL\n
\n\n

Example 3:

\n\n
\nInput: head = []\nOutput: []\n
\n\n

 

\n\n

How multilevel linked list is represented in test case:

\n\n

We use the multilevel linked list from Example 1 above:

\n\n
\n 1---2---3---4---5---6--NULL\n         |\n         7---8---9---10--NULL\n             |\n             11--12--NULL
\n\n

The serialization of each level is as follows:

\n\n
\n[1,2,3,4,5,6,null]\n[7,8,9,10,null]\n[11,12,null]\n
\n\n

To serialize all levels together we will add nulls in each level to signify no node connects to the upper node of the previous level. The serialization becomes:

\n\n
\n[1,2,3,4,5,6,null]\n[null,null,7,8,9,10,null]\n[null,11,12,null]\n
\n\n

Merging the serialization of each level and removing trailing nulls we obtain:

\n\n
\n[1,2,3,4,5,6,null,null,null,7,8,9,10,null,null,11,12]
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The number of Nodes will not exceed 1000.
  • \n\t
  • 1 <= Node.val <= 105
  • \n
\n", "content_cn": "

\u591a\u7ea7\u53cc\u5411\u94fe\u8868\u4e2d\uff0c\u9664\u4e86\u6307\u5411\u4e0b\u4e00\u4e2a\u8282\u70b9\u548c\u524d\u4e00\u4e2a\u8282\u70b9\u6307\u9488\u4e4b\u5916\uff0c\u5b83\u8fd8\u6709\u4e00\u4e2a\u5b50\u94fe\u8868\u6307\u9488\uff0c\u53ef\u80fd\u6307\u5411\u5355\u72ec\u7684\u53cc\u5411\u94fe\u8868\u3002\u8fd9\u4e9b\u5b50\u5217\u8868\u4e5f\u53ef\u80fd\u4f1a\u6709\u4e00\u4e2a\u6216\u591a\u4e2a\u81ea\u5df1\u7684\u5b50\u9879\uff0c\u4f9d\u6b64\u7c7b\u63a8\uff0c\u751f\u6210\u591a\u7ea7\u6570\u636e\u7ed3\u6784\uff0c\u5982\u4e0b\u9762\u7684\u793a\u4f8b\u6240\u793a\u3002

\n\n

\u7ed9\u4f60\u4f4d\u4e8e\u5217\u8868\u7b2c\u4e00\u7ea7\u7684\u5934\u8282\u70b9\uff0c\u8bf7\u4f60\u6241\u5e73\u5316\u5217\u8868\uff0c\u4f7f\u6240\u6709\u7ed3\u70b9\u51fa\u73b0\u5728\u5355\u7ea7\u53cc\u94fe\u8868\u4e2d\u3002

\n\n

 

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1ahead = [1,2,3,4,5,6,null,null,null,7,8,9,10,null,null,11,12]\n\u8f93\u51fa\uff1a[1,2,3,7,8,11,12,9,10,4,5,6]\n\u89e3\u91ca\uff1a\n\n\u8f93\u5165\u7684\u591a\u7ea7\u5217\u8868\u5982\u4e0b\u56fe\u6240\u793a\uff1a\n\n\n\n\u6241\u5e73\u5316\u540e\u7684\u94fe\u8868\u5982\u4e0b\u56fe\uff1a\n\n\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1ahead = [1,2,null,3]\n\u8f93\u51fa\uff1a[1,3,2]\n\u89e3\u91ca\uff1a\n\n\u8f93\u5165\u7684\u591a\u7ea7\u5217\u8868\u5982\u4e0b\u56fe\u6240\u793a\uff1a\n\n  1---2---NULL\n  |\n  3---NULL\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\u8f93\u5165\uff1ahead = []\n\u8f93\u51fa\uff1a[]\n
\n\n

 

\n\n

\u5982\u4f55\u8868\u793a\u6d4b\u8bd5\u7528\u4f8b\u4e2d\u7684\u591a\u7ea7\u94fe\u8868\uff1f

\n\n

\u4ee5 \u793a\u4f8b 1 \u4e3a\u4f8b\uff1a

\n\n
 1---2---3---4---5---6--NULL\n         |\n         7---8---9---10--NULL\n             |\n             11--12--NULL
\n\n

\u5e8f\u5217\u5316\u5176\u4e2d\u7684\u6bcf\u4e00\u7ea7\u4e4b\u540e\uff1a

\n\n
[1,2,3,4,5,6,null]\n[7,8,9,10,null]\n[11,12,null]\n
\n\n

\u4e3a\u4e86\u5c06\u6bcf\u4e00\u7ea7\u90fd\u5e8f\u5217\u5316\u5230\u4e00\u8d77\uff0c\u6211\u4eec\u9700\u8981\u6bcf\u4e00\u7ea7\u4e2d\u6dfb\u52a0\u503c\u4e3a null \u7684\u5143\u7d20\uff0c\u4ee5\u8868\u793a\u6ca1\u6709\u8282\u70b9\u8fde\u63a5\u5230\u4e0a\u4e00\u7ea7\u7684\u4e0a\u7ea7\u8282\u70b9\u3002

\n\n
[1,2,3,4,5,6,null]\n[null,null,7,8,9,10,null]\n[null,11,12,null]\n
\n\n

\u5408\u5e76\u6240\u6709\u5e8f\u5217\u5316\u7ed3\u679c\uff0c\u5e76\u53bb\u9664\u672b\u5c3e\u7684 null \u3002

\n\n
[1,2,3,4,5,6,null,null,null,7,8,9,10,null,null,11,12]
\n\n

 

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u8282\u70b9\u6570\u76ee\u4e0d\u8d85\u8fc7 1000
  • \n\t
  • 1 <= Node.val <= 10^5
  • \n
\n", "tags_en": ["Depth-first Search", "Linked List"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u94fe\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* prev;\n Node* next;\n Node* child;\n};\n*/\n\nclass Solution {\npublic:\n Node* flatten(Node* head) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/*\n// Definition for a Node.\nclass Node {\n public int val;\n public Node prev;\n public Node next;\n public Node child;\n};\n*/\n\nclass Solution {\n public Node flatten(Node head) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "\"\"\"\n# Definition for a Node.\nclass Node(object):\n def __init__(self, val, prev, next, child):\n self.val = val\n self.prev = prev\n self.next = next\n self.child = child\n\"\"\"\n\nclass Solution(object):\n def flatten(self, head):\n \"\"\"\n :type head: Node\n :rtype: Node\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "\"\"\"\n# Definition for a Node.\nclass Node:\n def __init__(self, val, prev, next, child):\n self.val = val\n self.prev = prev\n self.next = next\n self.child = child\n\"\"\"\n\nclass Solution:\n def flatten(self, head: 'Node') -> 'Node':\n ", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/*\n// Definition for a Node.\npublic class Node {\n public int val;\n public Node prev;\n public Node next;\n public Node child;\n}\n*/\n\npublic class Solution {\n public Node Flatten(Node head) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // Definition for a Node.\n * function Node(val,prev,next,child) {\n * this.val = val;\n * this.prev = prev;\n * this.next = next;\n * this.child = child;\n * };\n */\n\n/**\n * @param {Node} head\n * @return {Node}\n */\nvar flatten = function(head) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a Node.\n# class Node\n# attr_accessor :val, :prev, :next, :child\n# def initialize(val=nil, prev=nil, next_=nil, child=nil)\n# @val = val\n# @prev = prev\n# @next = next_\n# @child = child\n# end\n# end\n\n# @param {Node} root\n# @return {Node}\ndef flatten(root)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a Node.\n * public class Node {\n * public var val: Int\n * public var prev: Node?\n * public var next: Node?\n * public var child: Node?\n * public init(_ val: Int) {\n * self.val = val\n * self.prev = nil\n * self.next = nil\n * self.child = nil\n * }\n * }\n */\n\nclass Solution {\n func flatten(_ head: Node?) -> Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a Node.\n * type Node struct {\n * Val int\n * Prev *Node\n * Next *Node\n * Child *Node\n * }\n */\n\nfunc flatten(root *Node) *Node {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a Node.\n * class Node(var _value: Int) {\n * var value: Int = _value\n * var prev: Node = null\n * var next: Node = null\n * var child: Node = null\n * }\n */\n\nobject Solution {\n def flatten(head: Node): Node = {\n \t\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a Node.\n * class Node(var `val`: Int) {\n * var prev: Node? = null\n * var next: Node? = null\n * var child: Node? = null\n * }\n */\n\nclass Solution {\n fun flatten(root: Node?): Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a Node.\n * class Node {\n * public $val = null;\n * public $prev = null;\n * public $next = null;\n * public $child = null;\n * function __construct($val = 0) {\n * $this->val = $val;\n * $this->prev = null;\n * $this->next = null;\n * $this->child = null;\n * }\n * }\n */\n\nclass Solution {\n /**\n * @param Node $head\n * @return Node\n */\n function flatten($head) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for node.\n * class Node {\n * val: number\n * prev: Node | null\n * next: Node | null\n * child: Node | null\n * constructor(val?: number, prev? : Node, next? : Node, child? : Node) {\n * this.val = (val===undefined ? 0 : val);\n * this.prev = (prev===undefined ? null : prev);\n * this.next = (next===undefined ? null : next);\n * this.child = (child===undefined ? null : child);\n * }\n * }\n */\n\nfunction flatten(head: Node | null): Node | null {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0430](https://leetcode-cn.com/problems/flatten-a-multilevel-doubly-linked-list)", "[\u6241\u5e73\u5316\u591a\u7ea7\u53cc\u5411\u94fe\u8868](/solution/0400-0499/0430.Flatten%20a%20Multilevel%20Doubly%20Linked%20List/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u94fe\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0430](https://leetcode.com/problems/flatten-a-multilevel-doubly-linked-list)", "[Flatten a Multilevel Doubly Linked List](/solution/0400-0499/0430.Flatten%20a%20Multilevel%20Doubly%20Linked%20List/README_EN.md)", "`Depth-first Search`,`Linked List`", "Medium", ""]}, {"question_id": "0765", "frontend_question_id": "0428", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/serialize-and-deserialize-n-ary-tree", "url_en": "https://leetcode.com/problems/serialize-and-deserialize-n-ary-tree", "relative_path_cn": "/solution/0400-0499/0428.Serialize%20and%20Deserialize%20N-ary%20Tree/README.md", "relative_path_en": "/solution/0400-0499/0428.Serialize%20and%20Deserialize%20N-ary%20Tree/README_EN.md", "title_cn": "\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316 N \u53c9\u6811", "title_en": "Serialize and Deserialize N-ary Tree", "question_title_slug": "serialize-and-deserialize-n-ary-tree", "content_en": "

Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be reconstructed later in the same or another computer environment.

\n\n

Design an algorithm to serialize and deserialize an N-ary tree. An N-ary tree is a rooted tree in which each node has no more than N children. There is no restriction on how your serialization/deserialization algorithm should work. You just need to ensure that an N-ary tree can be serialized to a string and this string can be deserialized to the original tree structure.

\n\n

For example, you may serialize the following 3-ary tree

\n\n

\n\n

as [1 [3[5 6] 2 4]]. Note that this is just an example, you do not necessarily need to follow this format.

\n\n

Or you can follow LeetCode's level order traversal serialization format, where each group of children is separated by the null value.

\n\n

\"\"

\n\n

For example, the above tree may be serialized as [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14].

\n\n

You do not necessarily need to follow the above suggested formats, there are many more different formats that work so please be creative and come up with different approaches yourself.

\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The number of nodes in the tree is in the range [0, 104].
  • \n\t
  • 0 <= Node.val <= 104
  • \n\t
  • The height of the n-ary tree is less than or equal to 1000
  • \n\t
  • Do not use class member/global/static variables to store states. Your encode and decode algorithms should be stateless.
  • \n
\n", "content_cn": "

\u5e8f\u5217\u5316\u662f\u6307\u5c06\u4e00\u4e2a\u6570\u636e\u7ed3\u6784\u8f6c\u5316\u4e3a\u4f4d\u5e8f\u5217\u7684\u8fc7\u7a0b\uff0c\u56e0\u6b64\u53ef\u4ee5\u5c06\u5176\u5b58\u50a8\u5728\u6587\u4ef6\u4e2d\u6216\u5185\u5b58\u7f13\u51b2\u533a\u4e2d\uff0c\u4ee5\u4fbf\u7a0d\u540e\u5728\u76f8\u540c\u6216\u4e0d\u540c\u7684\u8ba1\u7b97\u673a\u73af\u5883\u4e2d\u6062\u590d\u7ed3\u6784\u3002

\n\n

\u8bbe\u8ba1\u4e00\u4e2a\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316 N \u53c9\u6811\u7684\u7b97\u6cd5\u3002\u4e00\u4e2a N \u53c9\u6811\u662f\u6307\u6bcf\u4e2a\u8282\u70b9\u90fd\u6709\u4e0d\u8d85\u8fc7 N \u4e2a\u5b69\u5b50\u8282\u70b9\u7684\u6709\u6839\u6811\u3002\u5e8f\u5217\u5316 / \u53cd\u5e8f\u5217\u5316\u7b97\u6cd5\u7684\u7b97\u6cd5\u5b9e\u73b0\u6ca1\u6709\u9650\u5236\u3002\u4f60\u53ea\u9700\u8981\u4fdd\u8bc1 N \u53c9\u6811\u53ef\u4ee5\u88ab\u5e8f\u5217\u5316\u4e3a\u4e00\u4e2a\u5b57\u7b26\u4e32\u5e76\u4e14\u8be5\u5b57\u7b26\u4e32\u53ef\u4ee5\u88ab\u53cd\u5e8f\u5217\u5316\u6210\u539f\u6811\u7ed3\u6784\u5373\u53ef\u3002

\n\n

\u4f8b\u5982\uff0c\u4f60\u9700\u8981\u5e8f\u5217\u5316\u4e0b\u9762\u7684 3-\u53c9 \u6811\u3002

\n\n

\u00a0

\n\n

\n\n

\u00a0

\n\n

\u4e3a\u00a0[1 [3[5 6] 2 4]]\u3002\u4f60\u4e0d\u9700\u8981\u4ee5\u8fd9\u79cd\u5f62\u5f0f\u5b8c\u6210\uff0c\u4f60\u53ef\u4ee5\u81ea\u5df1\u521b\u9020\u548c\u5b9e\u73b0\u4e0d\u540c\u7684\u65b9\u6cd5\u3002

\n\n

\u6216\u8005\uff0c\u60a8\u53ef\u4ee5\u9075\u5faa LeetCode \u7684\u5c42\u5e8f\u904d\u5386\u5e8f\u5217\u5316\u683c\u5f0f\uff0c\u5176\u4e2d\u6bcf\u7ec4\u5b69\u5b50\u8282\u70b9\u7531\u7a7a\u503c\u5206\u9694\u3002

\n\n

\"\"

\n\n

\u4f8b\u5982\uff0c\u4e0a\u9762\u7684\u6811\u53ef\u4ee5\u5e8f\u5217\u5316\u4e3a [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]

\n\n

\u4f60\u4e0d\u4e00\u5b9a\u8981\u9075\u5faa\u4ee5\u4e0a\u5efa\u8bae\u7684\u683c\u5f0f\uff0c\u6709\u5f88\u591a\u4e0d\u540c\u7684\u683c\u5f0f\uff0c\u6240\u4ee5\u8bf7\u53d1\u6325\u521b\u9020\u529b\uff0c\u60f3\u51fa\u4e0d\u540c\u7684\u65b9\u6cd5\u6765\u5b8c\u6210\u672c\u9898\u3002

\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u6811\u4e2d\u8282\u70b9\u6570\u76ee\u7684\u8303\u56f4\u662f [0,\u00a0104].
  • \n\t
  • 0 <= Node.val <= 104
  • \n\t
  • N \u53c9\u6811\u7684\u9ad8\u5ea6\u5c0f\u4e8e\u7b49\u4e8e 1000
  • \n\t
  • \u4e0d\u8981\u4f7f\u7528\u7c7b\u6210\u5458 / \u5168\u5c40\u53d8\u91cf / \u9759\u6001\u53d8\u91cf\u6765\u5b58\u50a8\u72b6\u6001\u3002\u4f60\u7684\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316\u7b97\u6cd5\u5e94\u662f\u65e0\u72b6\u6001\u7684\u3002
  • \n
\n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n vector children;\n\n Node() {}\n\n Node(int _val) {\n val = _val;\n }\n\n Node(int _val, vector _children) {\n val = _val;\n children = _children;\n }\n};\n*/\n\nclass Codec {\npublic:\n // Encodes a tree to a single string.\n string serialize(Node* root) {\n \n }\n\t\n // Decodes your encoded data to tree.\n Node* deserialize(string data) {\n \n }\n};\n\n// Your Codec object will be instantiated and called as such:\n// Codec codec;\n// codec.deserialize(codec.serialize(root));", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/*\n// Definition for a Node.\nclass Node {\n public int val;\n public List children;\n\n public Node() {}\n\n public Node(int _val) {\n val = _val;\n }\n\n public Node(int _val, List _children) {\n val = _val;\n children = _children;\n }\n};\n*/\n\nclass Codec {\n // Encodes a tree to a single string.\n public String serialize(Node root) {\n \n }\n\t\n // Decodes your encoded data to tree.\n public Node deserialize(String data) {\n \n }\n}\n\n// Your Codec object will be instantiated and called as such:\n// Codec codec = new Codec();\n// codec.deserialize(codec.serialize(root));", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "\"\"\"\n# Definition for a Node.\nclass Node(object):\n def __init__(self, val=None, children=None):\n self.val = val\n self.children = children\n\"\"\"\n\nclass Codec:\n def serialize(self, root):\n \"\"\"Encodes a tree to a single string.\n \n :type root: Node\n :rtype: str\n \"\"\"\n\t\t\n \n def deserialize(self, data):\n \"\"\"Decodes your encoded data to tree.\n \n :type data: str\n :rtype: Node\n \"\"\"\n \n\n# Your Codec object will be instantiated and called as such:\n# codec = Codec()\n# codec.deserialize(codec.serialize(root))", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "\"\"\"\n# Definition for a Node.\nclass Node(object):\n def __init__(self, val=None, children=None):\n self.val = val\n self.children = children\n\"\"\"\n\nclass Codec:\n def serialize(self, root: 'Node') -> str:\n \"\"\"Encodes a tree to a single string.\n \n :type root: Node\n :rtype: str\n \"\"\"\n \n\t\n def deserialize(self, data: str) -> 'Node':\n \"\"\"Decodes your encoded data to tree.\n \n :type data: str\n :rtype: Node\n \"\"\"\n \n\n# Your Codec object will be instantiated and called as such:\n# codec = Codec()\n# codec.deserialize(codec.serialize(root))", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/*\n// Definition for a Node.\npublic class Node {\n public int val;\n public IList children;\n\n public Node() {}\n\n public Node(int _val) {\n val = _val;\n }\n\n public Node(int _val, IList _children) {\n val = _val;\n children = _children;\n }\n}\n*/\n\npublic class Codec {\n // Encodes a tree to a single string.\n public string serialize(Node root) {\n \n }\n\t\n // Decodes your encoded data to tree.\n public Node deserialize(string data) {\n \n }\n}\n\n// Your Codec object will be instantiated and called as such:\n// Codec codec = new Codec();\n// codec.deserialize(codec.serialize(root));", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // Definition for a Node.\n * function Node(val, children) {\n * this.val = val;\n * this.children = children;\n * };\n */\n\nclass Codec {\n \tconstructor() {\n \n }\n \n /** \n * @param {Node|null} root\n * @return {string}\n */\n // Encodes a tree to a single string.\n serialize = function(root) {\n \n };\n\t\n /** \n * @param {string} data \n * @return {Node|null}\n */\n // Decodes your encoded data to tree.\n deserialize = function(data) {\n \n };\n}\n\n// Your Codec object will be instantiated and called as such:\n// Codec codec = new Codec();\n// codec.deserialize(codec.serialize(root));", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a Node.\n# class Node\n# attr_accessor :val, :children\n# def initialize(val=0, children=[])\n# @val = val\n# @children = children\n# end\n# end\n\nclass Codec\n # Encodes a tree to a single string.\n # @param {Node} root\n\t# @return {String}\n def serialize(root)\n \t\n end\n \n # Decodes your encoded data to tree.\n # @param {String} data\n\t# @return {Node}\n def deserialize(data)\n \n end\nend\n\n# Your Codec object will be instantiated and called as such:\n# obj = Codec.new()\n# data = obj.seralize(root)\n# ans = obj.desrialize(data)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a Node.\n * public class Node {\n * public var val: Int\n * public var children: [Node]\n * public init(_ val: Int) {\n * self.val = val\n * self.children = []\n * }\n * }\n */\n\nclass Codec {\n func serialize(_ root: Node?) -> String {\n \t\n }\n \n func deserialize(_ data: String) -> Node? {\n \t\n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * let obj = Codec()\n * let ret_1: TreeNode? = obj.serialize(root)\n * let ret_2: Node? = obj.decode(data)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a Node.\n * type Node struct {\n * Val int\n * Children []*Node\n * }\n */\n\ntype Codec struct {\n \n}\n\nfunc Constructor() *Codec {\n \n}\n\nfunc (this *Codec) serialize(root *Node) string {\n \n}\n\nfunc (this *Codec) deserialize(data string) *Node {\n \n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * obj := Constructor();\n * data := obj.serialize(root);\n * ans := obj.deserialize(data);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a Node.\n * class Node(var _value: Int) {\n * var value: Int = _value\n * var children: List[Node] = List()\n * }\n */\n\nclass Codec {\n // Encodes a tree to a single string.\n def serialize(root: Node): String = {\n \n }\n \n // Decodes your encoded data to tree.\n def deserialize(data: String): Node = {\n \n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * var obj = new Codec()\n * var data = obj.serialize(root)\n * var ans = obj.deserialize(data)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a Node.\n * class Node(var `val`: Int) {\n * var children: List = listOf()\n * }\n */\n\nclass Codec {\n // Encodes a tree to a single string.\n fun serialize(root: Node?): String {\n \n }\n \n // Decodes your encoded data to tree.\n fun deserialize(data: String): Node? {\n \n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * var obj = Codec()\n * var data = obj.serialize(root)\n * var ans = obj.deserialize(data)\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a Node.\n * class Node {\n * public $val = null;\n * public $children = null;\n * function __construct($val = 0) {\n * $this->val = $val;\n * $this->children = array();\n * }\n * }\n */\n\nclass Codec {\n /**\n * Encodes a tree to a single string.\n * @param Node $root\n * @return String\n */\n function serialize($root) {\n\t\t\n }\n \t\n /**\n * Decodes your encoded data to tree.\n * @param String $data\n * @return Node\n */\n function deserialize($data) {\n \t\n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * $obj = Codec();\n * $ret_1 = $obj->serialize($root);\n * $ret_2 = $obj->deserialize($data);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for node.\n * class Node {\n * val: number\n * children: Node[]\n * constructor(val?: number) {\n * this.val = (val===undefined ? 0 : val)\n * this.children = []\n * }\n * }\n */\n\nclass Codec {\n \tconstructor() {\n \n }\n \n // Encodes a tree to a single string.\n serialize(root: Node | null): string {\n \n };\n\t\n // Decodes your encoded data to tree.\n deserialize(data: string): Node | null {\n \n };\n}\n\n// Your Codec object will be instantiated and called as such:\n// Codec codec = new Codec();\n// codec.deserialize(codec.serialize(root));", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0428](https://leetcode-cn.com/problems/serialize-and-deserialize-n-ary-tree)", "[\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316 N \u53c9\u6811](/solution/0400-0499/0428.Serialize%20and%20Deserialize%20N-ary%20Tree/README.md)", "`\u6811`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0428](https://leetcode.com/problems/serialize-and-deserialize-n-ary-tree)", "[Serialize and Deserialize N-ary Tree](/solution/0400-0499/0428.Serialize%20and%20Deserialize%20N-ary%20Tree/README_EN.md)", "`Tree`", "Hard", "\ud83d\udd12"]}, {"question_id": "0764", "frontend_question_id": "0429", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/n-ary-tree-level-order-traversal", "url_en": "https://leetcode.com/problems/n-ary-tree-level-order-traversal", "relative_path_cn": "/solution/0400-0499/0429.N-ary%20Tree%20Level%20Order%20Traversal/README.md", "relative_path_en": "/solution/0400-0499/0429.N-ary%20Tree%20Level%20Order%20Traversal/README_EN.md", "title_cn": "N \u53c9\u6811\u7684\u5c42\u5e8f\u904d\u5386", "title_en": "N-ary Tree Level Order Traversal", "question_title_slug": "n-ary-tree-level-order-traversal", "content_en": "

Given an n-ary tree, return the level order traversal of its nodes' values.

\n\n

Nary-Tree input serialization is represented in their level order traversal, each group of children is separated by the null value (See examples).

\n\n

 

\n

Example 1:

\n\n

\n\n
\nInput: root = [1,null,3,2,4,null,5,6]\nOutput: [[1],[3,2,4],[5,6]]\n
\n\n

Example 2:

\n\n

\"\"

\n\n
\nInput: root = [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]\nOutput: [[1],[2,3,4,5],[6,7,8,9,10],[11,12,13],[14]]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The height of the n-ary tree is less than or equal to 1000
  • \n\t
  • The total number of nodes is between [0, 104]
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a N \u53c9\u6811\uff0c\u8fd4\u56de\u5176\u8282\u70b9\u503c\u7684\u5c42\u5e8f\u904d\u5386\u3002\uff08\u5373\u4ece\u5de6\u5230\u53f3\uff0c\u9010\u5c42\u904d\u5386\uff09\u3002

\n\n

\u6811\u7684\u5e8f\u5217\u5316\u8f93\u5165\u662f\u7528\u5c42\u5e8f\u904d\u5386\uff0c\u6bcf\u7ec4\u5b50\u8282\u70b9\u90fd\u7531 null \u503c\u5206\u9694\uff08\u53c2\u89c1\u793a\u4f8b\uff09\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n

\n\n
\n\u8f93\u5165\uff1aroot = [1,null,3,2,4,null,5,6]\n\u8f93\u51fa\uff1a[[1],[3,2,4],[5,6]]\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n

\"\"

\n\n
\n\u8f93\u5165\uff1aroot = [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]\n\u8f93\u51fa\uff1a[[1],[2,3,4,5],[6,7,8,9,10],[11,12,13],[14]]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • \u6811\u7684\u9ad8\u5ea6\u4e0d\u4f1a\u8d85\u8fc7\u00a01000
  • \n\t
  • \u6811\u7684\u8282\u70b9\u603b\u6570\u5728 [0,\u00a010^4] \u4e4b\u95f4
  • \n
\n", "tags_en": ["Tree", "Breadth-first Search"], "tags_cn": ["\u6811", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n vector children;\n\n Node() {}\n\n Node(int _val) {\n val = _val;\n }\n\n Node(int _val, vector _children) {\n val = _val;\n children = _children;\n }\n};\n*/\n\nclass Solution {\npublic:\n vector> levelOrder(Node* root) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/*\n// Definition for a Node.\nclass Node {\n public int val;\n public List children;\n\n public Node() {}\n\n public Node(int _val) {\n val = _val;\n }\n\n public Node(int _val, List _children) {\n val = _val;\n children = _children;\n }\n};\n*/\n\nclass Solution {\n public List> levelOrder(Node root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "\"\"\"\n# Definition for a Node.\nclass Node(object):\n def __init__(self, val=None, children=None):\n self.val = val\n self.children = children\n\"\"\"\n\nclass Solution(object):\n def levelOrder(self, root):\n \"\"\"\n :type root: Node\n :rtype: List[List[int]]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "\"\"\"\n# Definition for a Node.\nclass Node:\n def __init__(self, val=None, children=None):\n self.val = val\n self.children = children\n\"\"\"\n\nclass Solution:\n def levelOrder(self, root: 'Node') -> List[List[int]]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a Node.\n * struct Node {\n * int val;\n * int numChildren;\n * struct Node** children;\n * };\n */\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** levelOrder(struct Node* root, int* returnSize, int** returnColumnSizes) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/*\n// Definition for a Node.\npublic class Node {\n public int val;\n public IList children;\n\n public Node() {}\n\n public Node(int _val) {\n val = _val;\n }\n\n public Node(int _val, IList _children) {\n val = _val;\n children = _children;\n }\n}\n*/\n\npublic class Solution {\n public IList> LevelOrder(Node root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // Definition for a Node.\n * function Node(val,children) {\n * this.val = val;\n * this.children = children;\n * };\n */\n\n/**\n * @param {Node|null} root\n * @return {number[][]}\n */\nvar levelOrder = function(root) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a Node.\n# class Node\n# attr_accessor :val, :children\n# def initialize(val)\n# @val = val\n# @children = []\n# end\n# end\n\n# @param {Node} root\n# @return {List[List[int]]}\ndef level_order(root)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a Node.\n * public class Node {\n * public var val: Int\n * public var children: [Node]\n * public init(_ val: Int) {\n * self.val = val\n * self.children = []\n * }\n * }\n */\n\nclass Solution {\n func levelOrder(_ root: Node?) -> [[Int]] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a Node.\n * type Node struct {\n * Val int\n * Children []*Node\n * }\n */\n\nfunc levelOrder(root *Node) [][]int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a Node.\n * class Node(var _value: Int) {\n * var value: Int = _value\n * var children: List[Node] = List()\n * }\n */\n\nobject Solution {\n def levelOrder(root: Node): List[List[Int]] = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a Node.\n * class Node(var `val`: Int) {\n * var children: List = listOf()\n * }\n */\n\nclass Solution {\n fun levelOrder(root: Node?): List> {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a Node.\n * class Node {\n * public $val = null;\n * public $children = null;\n * function __construct($val = 0) {\n * $this->val = $val;\n * $this->children = array();\n * }\n * }\n */\n\nclass Solution {\n /**\n * @param Node $root\n * @return integer[][]\n */\n function levelOrder($root) {\n\t\t\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for node.\n * class Node {\n * val: number\n * children: Node[]\n * constructor(val?: number) {\n * this.val = (val===undefined ? 0 : val)\n * this.children = []\n * }\n * }\n */\n\nfunction levelOrder(root: Node | null): number[][] {\n\t\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0429](https://leetcode-cn.com/problems/n-ary-tree-level-order-traversal)", "[N \u53c9\u6811\u7684\u5c42\u5e8f\u904d\u5386](/solution/0400-0499/0429.N-ary%20Tree%20Level%20Order%20Traversal/README.md)", "`\u6811`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0429](https://leetcode.com/problems/n-ary-tree-level-order-traversal)", "[N-ary Tree Level Order Traversal](/solution/0400-0499/0429.N-ary%20Tree%20Level%20Order%20Traversal/README_EN.md)", "`Tree`,`Breadth-first Search`", "Medium", ""]}, {"question_id": "0763", "frontend_question_id": "0761", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/special-binary-string", "url_en": "https://leetcode.com/problems/special-binary-string", "relative_path_cn": "/solution/0700-0799/0761.Special%20Binary%20String/README.md", "relative_path_en": "/solution/0700-0799/0761.Special%20Binary%20String/README_EN.md", "title_cn": "\u7279\u6b8a\u7684\u4e8c\u8fdb\u5236\u5e8f\u5217", "title_en": "Special Binary String", "question_title_slug": "special-binary-string", "content_en": "

Special binary strings are binary strings with the following two properties:

\n\n
    \n\t
  • The number of 0's is equal to the number of 1's.
  • \n\t
  • Every prefix of the binary string has at least as many 1's as 0's.
  • \n
\n\n

Given a special string s, a move consists of choosing two consecutive, non-empty, special substrings of s, and swapping them. (Two strings are consecutive if the last character of the first string is exactly one index before the first character of the second string.)

\n\n

At the end of any number of moves, what is the lexicographically largest resulting string possible?

\n\n

Example 1:

\n\n
\nInput: s = "11011000"\nOutput: "11100100"\nExplanation:\nThe strings "10" [occuring at s[1]] and "1100" [at s[3]] are swapped.\nThis is the lexicographically largest string possible after some number of swaps.\n
\n\n

Note:

\n\n
    \n\t
  1. s has length at most 50.
  2. \n\t
  3. s is guaranteed to be a special binary string as defined above.
  4. \n
\n", "content_cn": "

\u7279\u6b8a\u7684\u4e8c\u8fdb\u5236\u5e8f\u5217\u662f\u5177\u6709\u4ee5\u4e0b\u4e24\u4e2a\u6027\u8d28\u7684\u4e8c\u8fdb\u5236\u5e8f\u5217\uff1a

\n\n
    \n\t
  • 0 \u7684\u6570\u91cf\u4e0e 1 \u7684\u6570\u91cf\u76f8\u7b49\u3002
  • \n\t
  • \u4e8c\u8fdb\u5236\u5e8f\u5217\u7684\u6bcf\u4e00\u4e2a\u524d\u7f00\u7801\u4e2d 1 \u7684\u6570\u91cf\u8981\u5927\u4e8e\u7b49\u4e8e 0 \u7684\u6570\u91cf\u3002
  • \n
\n\n

\u7ed9\u5b9a\u4e00\u4e2a\u7279\u6b8a\u7684\u4e8c\u8fdb\u5236\u5e8f\u5217 S\uff0c\u4ee5\u5b57\u7b26\u4e32\u5f62\u5f0f\u8868\u793a\u3002\u5b9a\u4e49\u4e00\u4e2a\u64cd\u4f5c \u4e3a\u9996\u5148\u9009\u62e9 S \u7684\u4e24\u4e2a\u8fde\u7eed\u4e14\u975e\u7a7a\u7684\u7279\u6b8a\u7684\u5b50\u4e32\uff0c\u7136\u540e\u5c06\u5b83\u4eec\u4ea4\u6362\u3002\uff08\u4e24\u4e2a\u5b50\u4e32\u4e3a\u8fde\u7eed\u7684\u5f53\u4e14\u4ec5\u5f53\u7b2c\u4e00\u4e2a\u5b50\u4e32\u7684\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\u6070\u597d\u4e3a\u7b2c\u4e8c\u4e2a\u5b50\u4e32\u7684\u7b2c\u4e00\u4e2a\u5b57\u7b26\u7684\u524d\u4e00\u4e2a\u5b57\u7b26\u3002)

\n\n

\u5728\u4efb\u610f\u6b21\u6570\u7684\u64cd\u4f5c\u4e4b\u540e\uff0c\u4ea4\u6362\u540e\u7684\u5b57\u7b26\u4e32\u6309\u7167\u5b57\u5178\u5e8f\u6392\u5217\u7684\u6700\u5927\u7684\u7ed3\u679c\u662f\u4ec0\u4e48\uff1f

\n\n

\u793a\u4f8b 1:

\n\n
\n\u8f93\u5165: S = "11011000"\n\u8f93\u51fa: "11100100"\n\u89e3\u91ca:\n\u5c06\u5b50\u4e32 "10" \uff08\u5728S[1]\u51fa\u73b0\uff09 \u548c "1100" \uff08\u5728S[3]\u51fa\u73b0\uff09\u8fdb\u884c\u4ea4\u6362\u3002\n\u8fd9\u662f\u5728\u8fdb\u884c\u82e5\u5e72\u6b21\u64cd\u4f5c\u540e\u6309\u5b57\u5178\u5e8f\u6392\u5217\u6700\u5927\u7684\u7ed3\u679c\u3002\n
\n\n

\u8bf4\u660e:

\n\n
    \n\t
  1. S \u7684\u957f\u5ea6\u4e0d\u8d85\u8fc7 50\u3002
  2. \n\t
  3. S \u4fdd\u8bc1\u4e3a\u4e00\u4e2a\u6ee1\u8db3\u4e0a\u8ff0\u5b9a\u4e49\u7684\u7279\u6b8a \u7684\u4e8c\u8fdb\u5236\u5e8f\u5217\u3002
  4. \n
\n", "tags_en": ["Recursion", "String"], "tags_cn": ["\u9012\u5f52", "\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string makeLargestSpecial(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String makeLargestSpecial(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def makeLargestSpecial(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def makeLargestSpecial(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * makeLargestSpecial(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string MakeLargestSpecial(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar makeLargestSpecial = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef make_largest_special(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func makeLargestSpecial(_ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func makeLargestSpecial(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def makeLargestSpecial(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun makeLargestSpecial(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn make_largest_special(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function makeLargestSpecial($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function makeLargestSpecial(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (make-largest-special s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0761](https://leetcode-cn.com/problems/special-binary-string)", "[\u7279\u6b8a\u7684\u4e8c\u8fdb\u5236\u5e8f\u5217](/solution/0700-0799/0761.Special%20Binary%20String/README.md)", "`\u9012\u5f52`,`\u5b57\u7b26\u4e32`", "\u56f0\u96be", ""], "md_table_row_en": ["[0761](https://leetcode.com/problems/special-binary-string)", "[Special Binary String](/solution/0700-0799/0761.Special%20Binary%20String/README_EN.md)", "`Recursion`,`String`", "Hard", ""]}, {"question_id": "0762", "frontend_question_id": "0760", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/find-anagram-mappings", "url_en": "https://leetcode.com/problems/find-anagram-mappings", "relative_path_cn": "/solution/0700-0799/0760.Find%20Anagram%20Mappings/README.md", "relative_path_en": "/solution/0700-0799/0760.Find%20Anagram%20Mappings/README_EN.md", "title_cn": "\u627e\u51fa\u53d8\u4f4d\u6620\u5c04", "title_en": "Find Anagram Mappings", "question_title_slug": "find-anagram-mappings", "content_en": "

Given two lists nums1 and nums2, and nums2 is an anagram of nums1. nums2 is an anagram of nums1 means nums2 is made by randomizing the order of the elements in nums1.

\n\n

We want to find an index mapping mapping, from nums1 to nums2. A mapping mapping[i] = j means the ith element in nums1 appears in nums2 at index j.

\n\n

These lists nums1 and nums2 may contain duplicates. If there are multiple answers, output any of them.

\n\n

For example, given

\n\n
\nnums1 = [12, 28, 46, 32, 50]\nnums2 = [50, 12, 32, 46, 28]\n
\n\n

We should return

\n\n
\n[1, 4, 3, 2, 0]\n
\n\n

as mapping[0] = 1 because the 0th element of nums1 appears at nums2[1], and mapping[1] = 4 because the 1st element of nums1 appears at nums2[4], and so on.

\n\n

Note:

\n\n
    \n\t
  1. nums1, nums2 have equal lengths in range [1, 100].
  2. \n\t
  3. nums1[i], nums2[i] are integers in range [0, 10^5].
  4. \n
\n", "content_cn": "

\u7ed9\u5b9a\u4e24\u4e2a\u5217\u8868 Aand B\uff0c\u5e76\u4e14 B \u662f A \u7684\u53d8\u4f4d\uff08\u5373 B \u662f\u7531 A \u4e2d\u7684\u5143\u7d20\u968f\u673a\u6392\u5217\u540e\u7ec4\u6210\u7684\u65b0\u5217\u8868\uff09\u3002

\n\n

\u6211\u4eec\u5e0c\u671b\u627e\u51fa\u4e00\u4e2a\u4ece A \u5230 B \u7684\u7d22\u5f15\u6620\u5c04 P \u3002\u4e00\u4e2a\u6620\u5c04 P[i] = j \u6307\u7684\u662f\u5217\u8868 A \u4e2d\u7684\u7b2c i \u4e2a\u5143\u7d20\u51fa\u73b0\u4e8e\u5217\u8868 B \u4e2d\u7684\u7b2c j \u4e2a\u5143\u7d20\u4e0a\u3002

\n\n

\u5217\u8868 A \u548c B \u53ef\u80fd\u51fa\u73b0\u91cd\u590d\u5143\u7d20\u3002\u5982\u679c\u6709\u591a\u4e8e\u4e00\u79cd\u7b54\u6848\uff0c\u8f93\u51fa\u4efb\u610f\u4e00\u79cd\u3002

\n\n

\u4f8b\u5982\uff0c\u7ed9\u5b9a

\n\n
A = [12, 28, 46, 32, 50]\nB = [50, 12, 32, 46, 28]\n
\n\n

 

\n\n

\u9700\u8981\u8fd4\u56de

\n\n
[1, 4, 3, 2, 0]\n
\n\n

P[0] = 1 \uff0c\u56e0\u4e3a A \u4e2d\u7684\u7b2c 0 \u4e2a\u5143\u7d20\u51fa\u73b0\u4e8e B[1]\uff0c\u800c\u4e14 P[1] = 4 \u56e0\u4e3a A \u4e2d\u7b2c 1 \u4e2a\u5143\u7d20\u51fa\u73b0\u4e8e B[4]\uff0c\u4ee5\u6b64\u7c7b\u63a8\u3002

\n\n

 

\n\n

\u6ce8\uff1a

\n\n
    \n\t
  1. A, B \u6709\u76f8\u540c\u7684\u957f\u5ea6\uff0c\u8303\u56f4\u4e3a [1, 100]\u3002
  2. \n\t
  3. A[i], B[i] \u90fd\u662f\u8303\u56f4\u5728 [0, 10^5] \u7684\u6574\u6570\u3002
  4. \n
\n\n

 

\n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector anagramMappings(vector& nums1, vector& nums2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] anagramMappings(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def anagramMappings(self, nums1, nums2):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def anagramMappings(self, nums1: List[int], nums2: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* anagramMappings(int* nums1, int nums1Size, int* nums2, int nums2Size, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] AnagramMappings(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums1\n * @param {number[]} nums2\n * @return {number[]}\n */\nvar anagramMappings = function(nums1, nums2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums1\n# @param {Integer[]} nums2\n# @return {Integer[]}\ndef anagram_mappings(nums1, nums2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func anagramMappings(_ nums1: [Int], _ nums2: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func anagramMappings(nums1 []int, nums2 []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def anagramMappings(nums1: Array[Int], nums2: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun anagramMappings(nums1: IntArray, nums2: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn anagram_mappings(nums1: Vec, nums2: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums1\n * @param Integer[] $nums2\n * @return Integer[]\n */\n function anagramMappings($nums1, $nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function anagramMappings(nums1: number[], nums2: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (anagram-mappings nums1 nums2)\n (-> (listof exact-integer?) (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0760](https://leetcode-cn.com/problems/find-anagram-mappings)", "[\u627e\u51fa\u53d8\u4f4d\u6620\u5c04](/solution/0700-0799/0760.Find%20Anagram%20Mappings/README.md)", "`\u54c8\u5e0c\u8868`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0760](https://leetcode.com/problems/find-anagram-mappings)", "[Find Anagram Mappings](/solution/0700-0799/0760.Find%20Anagram%20Mappings/README_EN.md)", "`Hash Table`", "Easy", "\ud83d\udd12"]}, {"question_id": "0761", "frontend_question_id": "0759", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/employee-free-time", "url_en": "https://leetcode.com/problems/employee-free-time", "relative_path_cn": "/solution/0700-0799/0759.Employee%20Free%20Time/README.md", "relative_path_en": "/solution/0700-0799/0759.Employee%20Free%20Time/README_EN.md", "title_cn": "\u5458\u5de5\u7a7a\u95f2\u65f6\u95f4", "title_en": "Employee Free Time", "question_title_slug": "employee-free-time", "content_en": "

We are given a list schedule of employees, which represents the working time for each employee.

\r\n\r\n

Each employee has a list of non-overlapping Intervals, and these intervals are in sorted order.

\r\n\r\n

Return the list of finite intervals representing common, positive-length free time for all employees, also in sorted order.

\r\n\r\n

(Even though we are representing Intervals in the form [x, y], the objects inside are Intervals, not lists or arrays. For example, schedule[0][0].start = 1, schedule[0][0].end = 2, and schedule[0][0][0] is not defined).  Also, we wouldn't include intervals like [5, 5] in our answer, as they have zero length.

\r\n\n

 

\n

Example 1:

\n\n
\nInput: schedule = [[[1,2],[5,6]],[[1,3]],[[4,10]]]\nOutput: [[3,4]]\nExplanation: There are a total of three employees, and all common\nfree time intervals would be [-inf, 1], [3, 4], [10, inf].\nWe discard any intervals that contain inf as they aren't finite.\n
\n\n

Example 2:

\n\n
\nInput: schedule = [[[1,3],[6,7]],[[2,4]],[[2,5],[9,12]]]\nOutput: [[5,6],[7,9]]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= schedule.length , schedule[i].length <= 50
  • \n\t
  • 0 <= schedule[i].start < schedule[i].end <= 10^8
  • \n
\n", "content_cn": "

\u7ed9\u5b9a\u5458\u5de5\u7684 schedule \u5217\u8868\uff0c\u8868\u793a\u6bcf\u4e2a\u5458\u5de5\u7684\u5de5\u4f5c\u65f6\u95f4\u3002

\n\n

\u6bcf\u4e2a\u5458\u5de5\u90fd\u6709\u4e00\u4e2a\u975e\u91cd\u53e0\u7684\u65f6\u95f4\u6bb5  Intervals \u5217\u8868\uff0c\u8fd9\u4e9b\u65f6\u95f4\u6bb5\u5df2\u7ecf\u6392\u597d\u5e8f\u3002

\n\n

\u8fd4\u56de\u8868\u793a \u6240\u6709 \u5458\u5de5\u7684 \u5171\u540c\uff0c\u6b63\u6570\u957f\u5ea6\u7684\u7a7a\u95f2\u65f6\u95f4 \u7684\u6709\u9650\u65f6\u95f4\u6bb5\u7684\u5217\u8868\uff0c\u540c\u6837\u9700\u8981\u6392\u597d\u5e8f\u3002

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\u8f93\u5165\uff1aschedule = [[[1,2],[5,6]],[[1,3]],[[4,10]]]\n\u8f93\u51fa\uff1a[[3,4]]\n\u89e3\u91ca\uff1a\n\u5171\u6709 3 \u4e2a\u5458\u5de5\uff0c\u5e76\u4e14\u6240\u6709\u5171\u540c\u7684\n\u7a7a\u95f4\u65f6\u95f4\u6bb5\u662f [-inf, 1], [3, 4], [10, inf]\u3002\n\u6211\u4eec\u53bb\u9664\u6240\u6709\u5305\u542b inf \u7684\u65f6\u95f4\u6bb5\uff0c\u56e0\u4e3a\u5b83\u4eec\u4e0d\u662f\u6709\u9650\u7684\u65f6\u95f4\u6bb5\u3002\n
\n\n

 

\n\n

\u793a\u4f8b 2\uff1a

\n\n
\u8f93\u5165\uff1aschedule = [[[1,3],[6,7]],[[2,4]],[[2,5],[9,12]]]\n\u8f93\u51fa\uff1a[[5,6],[7,9]]\n
\n\n

 

\n\n

\uff08\u5c3d\u7ba1\u6211\u4eec\u7528 [x, y] \u7684\u5f62\u5f0f\u8868\u793a Intervals \uff0c\u5185\u90e8\u7684\u5bf9\u8c61\u662f Intervals \u800c\u4e0d\u662f\u5217\u8868\u6216\u6570\u7ec4\u3002\u4f8b\u5982\uff0cschedule[0][0].start = 1, schedule[0][0].end = 2\uff0c\u5e76\u4e14 schedule[0][0][0] \u662f\u672a\u5b9a\u4e49\u7684\uff09

\n\n

\u800c\u4e14\uff0c\u7b54\u6848\u4e2d\u4e0d\u5305\u542b [5, 5] \uff0c\u56e0\u4e3a\u957f\u5ea6\u4e3a 0\u3002

\n\n

 

\n\n

\u6ce8\uff1a

\n\n
    \n\t
  1. schedule \u548c schedule[i] \u4e3a\u957f\u5ea6\u8303\u56f4\u5728 [1, 50]\u7684\u5217\u8868\u3002
  2. \n\t
  3. 0 <= schedule[i].start < schedule[i].end <= 10^8\u3002
  4. \n
\n\n

\u6ce8\uff1a\u8f93\u5165\u7c7b\u578b\u4e8e 2019 \u5e74 4 \u6708 15 \u65e5 \u6539\u53d8\u3002\u8bf7\u91cd\u7f6e\u4e3a\u9ed8\u8ba4\u4ee3\u7801\u7684\u5b9a\u4e49\u4ee5\u83b7\u53d6\u65b0\u65b9\u6cd5\u3002

\n\n

 

\n", "tags_en": ["Heap", "Greedy"], "tags_cn": ["\u5806", "\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n// Definition for an Interval.\nclass Interval {\npublic:\n int start;\n int end;\n\n Interval() {}\n\n Interval(int _start, int _end) {\n start = _start;\n end = _end;\n }\n};\n*/\n\nclass Solution {\npublic:\n vector employeeFreeTime(vector> schedule) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/*\n// Definition for an Interval.\nclass Interval {\n public int start;\n public int end;\n\n public Interval() {}\n\n public Interval(int _start, int _end) {\n start = _start;\n end = _end;\n }\n};\n*/\n\nclass Solution {\n public List employeeFreeTime(List> schedule) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "\"\"\"\n# Definition for an Interval.\nclass Interval(object):\n def __init__(self, start=None, end=None):\n self.start = start\n self.end = end\n\"\"\"\n\nclass Solution(object):\n def employeeFreeTime(self, schedule):\n \"\"\"\n :type schedule: [[Interval]]\n :rtype: [Interval]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "\"\"\"\n# Definition for an Interval.\nclass Interval:\n def __init__(self, start: int = None, end: int = None):\n self.start = start\n self.end = end\n\"\"\"\n\nclass Solution:\n def employeeFreeTime(self, schedule: '[[Interval]]') -> '[Interval]':\n ", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/*\n// Definition for an Interval.\npublic class Interval {\n public int start;\n public int end;\n\n public Interval(){}\n public Interval(int _start, int _end) {\n start = _start;\n end = _end;\n }\n}\n*/\n\npublic class Solution {\n public IList EmployeeFreeTime(IList> schedule) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // Definition for an Interval.\n * function Interval(start, end) {\n * this.start = start;\n * this.end = end;\n * };\n */\n\n/**\n * @param {Interval[][]} schedule\n * @return {Interval[]}\n */\nvar employeeFreeTime = function(schedule) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for an Interval.\n# class Interval\n# def initialize(start_, end_)\n# @start = start_\n# @end = end_\n# end\n# end\n\n# @param {List[List[Interval]]} schedule\n# @return {List[List[Interval]]}\ndef employeeFreeTime(schedule)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for an Interval.\n * public class Interval {\n * public var start: Int\n * public var end: Int\n * public init(_ start: Int, _ end: Int) {\n * self.start = start\n * self.end = end\n * }\n * }\n */\n\nclass Solution {\n func employeeFreeTime(_ schedule: [[Interval]]) -> [Interval] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for an Interval.\n * type Interval struct {\n * Start int\n * End int\n * }\n */\n\nfunc employeeFreeTime(schedule [][]*Interval) []*Interval {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for an Interval.\n * class Interval(var _start: Int, var _end: Int) {\n * var start: Int = _start\n * var end: Int = _end\n * }\n */\n\nobject Solution {\n def employeeFreeTime(schedule: List[List[Interval]]): List[Interval] = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/*\n *\t// Definition for an Interval.\n *\tclass Interval {\n *\t\tvar start:Int = 0\n *\t\tvar end:Int = 0\n *\t\n *\t\tconstructor(_start:Int, _end:Int) {\n *\t\t\tstart = _start\n *\t\t\tend = _end\n *\t\t}\n *\t}\n */\n\nclass Solution {\n fun employeeFreeTime(schedule: ArrayList>): ArrayList {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "/*\n// Definition for an Interval.\n#[derive(PartialEq, Eq, Clone, Debug)]\nstruct Interval {\n pub start:i32,\n pub end:i32\n}\n\nimpl Interval {\n #[inline]\n fn new(start:i32, end:i32) -> Self{\n Interval {\n start,\n end\n }\n }\n}\n*/\n\nimpl Solution {\n pub fn employee_free_time(schedule: Vec>) -> Vec {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for an Interval.\n * class Interval {\n * public $start = null;\n * public $end = null;\n * function __construct($start, $end) {\n * $this->start = $start;\n * $this->end = $end;\n * }\n * }\n */\n\nclass Solution {\n /**\n * @param Interval[][] $schedule\n * @return Interval[]\n */\n function employeeFreeTime($schedule) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * // Definition for an Interval.\n * class Interval {\n * start: number;\n * end: number;\n * constructor(strat: number, end: number) {\n * this.start = start;\n * this.end = end;\n * }\n * }\n */\n\nfunction employeeFreeTime(schedule: Interval[][]): Interval[] {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0759](https://leetcode-cn.com/problems/employee-free-time)", "[\u5458\u5de5\u7a7a\u95f2\u65f6\u95f4](/solution/0700-0799/0759.Employee%20Free%20Time/README.md)", "`\u5806`,`\u8d2a\u5fc3\u7b97\u6cd5`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0759](https://leetcode.com/problems/employee-free-time)", "[Employee Free Time](/solution/0700-0799/0759.Employee%20Free%20Time/README_EN.md)", "`Heap`,`Greedy`", "Hard", "\ud83d\udd12"]}, {"question_id": "0760", "frontend_question_id": "0758", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/bold-words-in-string", "url_en": "https://leetcode.com/problems/bold-words-in-string", "relative_path_cn": "/solution/0700-0799/0758.Bold%20Words%20in%20String/README.md", "relative_path_en": "/solution/0700-0799/0758.Bold%20Words%20in%20String/README_EN.md", "title_cn": "\u5b57\u7b26\u4e32\u4e2d\u7684\u52a0\u7c97\u5355\u8bcd", "title_en": "Bold Words in String", "question_title_slug": "bold-words-in-string", "content_en": "

Given an array of keywords words and a string s, make all appearances of all keywords words[i] in s bold. Any letters between <b> and </b> tags become bold.

\n\n

Return s after adding the bold tags. The returned string should use the least number of tags possible, and the tags should form a valid combination.

\n\n

 

\n

Example 1:

\n\n
\nInput: words = ["ab","bc"], s = "aabcd"\nOutput: "a<b>abc</b>d"\nExplanation: Note that returning "a<b>a<b>b</b>c</b>d" would use more tags, so it is incorrect.\n
\n\n

Example 2:

\n\n
\nInput: words = ["ab","cb"], s = "aabcd"\nOutput: "a<b>ab</b>cd"\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s.length <= 500
  • \n\t
  • 0 <= words.length <= 50
  • \n\t
  • 1 <= words[i].length <= 10
  • \n\t
  • s and words[i] consist of lowercase English letters.
  • \n
\n\n

 

\n

Note: This question is the same as 616: https://leetcode.com/problems/add-bold-tag-in-string/

\n", "content_cn": "

\u7ed9\u5b9a\u4e00\u4e2a\u5173\u952e\u8bcd\u96c6\u5408\u00a0words \u548c\u4e00\u4e2a\u5b57\u7b26\u4e32\u00a0S\uff0c\u5c06\u6240\u6709 S \u4e2d\u51fa\u73b0\u7684\u5173\u952e\u8bcd\u52a0\u7c97\u3002\u6240\u6709\u5728\u6807\u7b7e \u548c\u00a0\u00a0\u4e2d\u7684\u5b57\u6bcd\u90fd\u4f1a\u52a0\u7c97\u3002

\n\n

\u8fd4\u56de\u7684\u5b57\u7b26\u4e32\u9700\u8981\u4f7f\u7528\u5c3d\u53ef\u80fd\u5c11\u7684\u6807\u7b7e\uff0c\u5f53\u7136\u6807\u7b7e\u5e94\u5f62\u6210\u6709\u6548\u7684\u7ec4\u5408\u3002

\n\n

\u4f8b\u5982\uff0c\u7ed9\u5b9a\u00a0words = [\"ab\", \"bc\"] \u548c\u00a0S = \"aabcd\"\uff0c\u9700\u8981\u8fd4\u56de\u00a0\"aabcd\"\u3002\u6ce8\u610f\u8fd4\u56de\u00a0\"aabcd\"\u00a0\u4f1a\u4f7f\u7528\u66f4\u591a\u7684\u6807\u7b7e\uff0c\u56e0\u6b64\u662f\u9519\u8bef\u7684\u3002

\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • words \u957f\u5ea6\u7684\u8303\u56f4\u4e3a\u00a0[0, 50]\u3002
  • \n\t
  • words[i] \u957f\u5ea6\u7684\u8303\u56f4\u4e3a\u00a0[1, 10]\u3002
  • \n\t
  • S \u957f\u5ea6\u7684\u8303\u56f4\u4e3a\u00a0[0, 500]\u3002
  • \n\t
  • \u6240\u6709\u00a0words[i]\u00a0\u548c\u00a0S\u00a0\u4e2d\u7684\u5b57\u7b26\u90fd\u4e3a\u5c0f\u5199\u5b57\u6bcd\u3002
  • \n
\n\n

\u00a0

\n\n

\u6ce8\uff1a\u6b64\u9898\u4e0e\u300c616 - \u7ed9\u5b57\u7b26\u4e32\u6dfb\u52a0\u52a0\u7c97\u6807\u7b7e\u300d\u76f8\u540c - https://leetcode-cn.com/problems/add-bold-tag-in-string/

\n\n

\u00a0

\n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string boldWords(vector& words, string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String boldWords(String[] words, String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def boldWords(self, words, s):\n \"\"\"\n :type words: List[str]\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def boldWords(self, words: List[str], s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * boldWords(char ** words, int wordsSize, char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string BoldWords(string[] words, string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @param {string} s\n * @return {string}\n */\nvar boldWords = function(words, s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @param {String} s\n# @return {String}\ndef bold_words(words, s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func boldWords(_ words: [String], _ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func boldWords(words []string, s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def boldWords(words: Array[String], s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun boldWords(words: Array, s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn bold_words(words: Vec, s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @param String $s\n * @return String\n */\n function boldWords($words, $s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function boldWords(words: string[], s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (bold-words words s)\n (-> (listof string?) string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0758](https://leetcode-cn.com/problems/bold-words-in-string)", "[\u5b57\u7b26\u4e32\u4e2d\u7684\u52a0\u7c97\u5355\u8bcd](/solution/0700-0799/0758.Bold%20Words%20in%20String/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0758](https://leetcode.com/problems/bold-words-in-string)", "[Bold Words in String](/solution/0700-0799/0758.Bold%20Words%20in%20String/README_EN.md)", "`String`", "Medium", "\ud83d\udd12"]}, {"question_id": "0759", "frontend_question_id": "0757", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/set-intersection-size-at-least-two", "url_en": "https://leetcode.com/problems/set-intersection-size-at-least-two", "relative_path_cn": "/solution/0700-0799/0757.Set%20Intersection%20Size%20At%20Least%20Two/README.md", "relative_path_en": "/solution/0700-0799/0757.Set%20Intersection%20Size%20At%20Least%20Two/README_EN.md", "title_cn": "\u8bbe\u7f6e\u4ea4\u96c6\u5927\u5c0f\u81f3\u5c11\u4e3a2", "title_en": "Set Intersection Size At Least Two", "question_title_slug": "set-intersection-size-at-least-two", "content_en": "

An integer interval [a, b] (for integers a < b) is a set of all consecutive integers from a to b, including a and b.

\n\n

Find the minimum size of a set S such that for every integer interval A in intervals, the intersection of S with A has a size of at least two.

\n\n

 

\n

Example 1:

\n\n
\nInput: intervals = [[1,3],[1,4],[2,5],[3,5]]\nOutput: 3\nExplanation: Consider the set S = {2, 3, 4}.  For each interval, there are at least 2 elements from S in the interval.\nAlso, there isn't a smaller size set that fulfills the above condition.\nThus, we output the size of this set, which is 3.\n
\n\n

Example 2:

\n\n
\nInput: intervals = [[1,2],[2,3],[2,4],[4,5]]\nOutput: 5\nExplanation: An example of a minimum sized set is {1, 2, 3, 4, 5}.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= intervals.length <= 3000
  • \n\t
  • intervals[i].length == 2
  • \n\t
  • 0 <= ai < bi <= 108
  • \n
\n", "content_cn": "

\u4e00\u4e2a\u6574\u6570\u533a\u95f4 [a, b]  ( a < b ) \u4ee3\u8868\u7740\u4ece a \u5230 b \u7684\u6240\u6709\u8fde\u7eed\u6574\u6570\uff0c\u5305\u62ec a \u548c b\u3002

\n\n

\u7ed9\u4f60\u4e00\u7ec4\u6574\u6570\u533a\u95f4intervals\uff0c\u8bf7\u627e\u5230\u4e00\u4e2a\u6700\u5c0f\u7684\u96c6\u5408 S\uff0c\u4f7f\u5f97 S \u91cc\u7684\u5143\u7d20\u4e0e\u533a\u95f4intervals\u4e2d\u7684\u6bcf\u4e00\u4e2a\u6574\u6570\u533a\u95f4\u90fd\u81f3\u5c11\u67092\u4e2a\u5143\u7d20\u76f8\u4ea4\u3002

\n\n

\u8f93\u51fa\u8fd9\u4e2a\u6700\u5c0f\u96c6\u5408S\u7684\u5927\u5c0f\u3002

\n\n

\u793a\u4f8b 1:

\n\n
\u8f93\u5165: intervals = [[1, 3], [1, 4], [2, 5], [3, 5]]\n\u8f93\u51fa: 3\n\u89e3\u91ca:\n\u8003\u8651\u96c6\u5408 S = {2, 3, 4}. S\u4e0eintervals\u4e2d\u7684\u56db\u4e2a\u533a\u95f4\u90fd\u6709\u81f3\u5c112\u4e2a\u76f8\u4ea4\u7684\u5143\u7d20\u3002\n\u4e14\u8fd9\u662fS\u6700\u5c0f\u7684\u60c5\u51b5\uff0c\u6545\u6211\u4eec\u8f93\u51fa3\u3002\n
\n\n

\u793a\u4f8b 2:

\n\n
\u8f93\u5165: intervals = [[1, 2], [2, 3], [2, 4], [4, 5]]\n\u8f93\u51fa: 5\n\u89e3\u91ca:\n\u6700\u5c0f\u7684\u96c6\u5408S = {1, 2, 3, 4, 5}.\n
\n\n

\u6ce8\u610f:

\n\n
    \n\t
  1. intervals \u7684\u957f\u5ea6\u8303\u56f4\u4e3a[1, 3000]\u3002
  2. \n\t
  3. intervals[i] \u957f\u5ea6\u4e3a 2\uff0c\u5206\u522b\u4ee3\u8868\u5de6\u3001\u53f3\u8fb9\u754c\u3002
  4. \n\t
  5. intervals[i][j] \u7684\u503c\u662f [0, 10^8]\u8303\u56f4\u5185\u7684\u6574\u6570\u3002
  6. \n
\n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int intersectionSizeTwo(vector>& intervals) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int intersectionSizeTwo(int[][] intervals) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def intersectionSizeTwo(self, intervals):\n \"\"\"\n :type intervals: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def intersectionSizeTwo(self, intervals: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint intersectionSizeTwo(int** intervals, int intervalsSize, int* intervalsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int IntersectionSizeTwo(int[][] intervals) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} intervals\n * @return {number}\n */\nvar intersectionSizeTwo = function(intervals) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} intervals\n# @return {Integer}\ndef intersection_size_two(intervals)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func intersectionSizeTwo(_ intervals: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func intersectionSizeTwo(intervals [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def intersectionSizeTwo(intervals: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun intersectionSizeTwo(intervals: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn intersection_size_two(intervals: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $intervals\n * @return Integer\n */\n function intersectionSizeTwo($intervals) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function intersectionSizeTwo(intervals: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (intersection-size-two intervals)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0757](https://leetcode-cn.com/problems/set-intersection-size-at-least-two)", "[\u8bbe\u7f6e\u4ea4\u96c6\u5927\u5c0f\u81f3\u5c11\u4e3a2](/solution/0700-0799/0757.Set%20Intersection%20Size%20At%20Least%20Two/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[0757](https://leetcode.com/problems/set-intersection-size-at-least-two)", "[Set Intersection Size At Least Two](/solution/0700-0799/0757.Set%20Intersection%20Size%20At%20Least%20Two/README_EN.md)", "`Greedy`", "Hard", ""]}, {"question_id": "0758", "frontend_question_id": "0426", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/convert-binary-search-tree-to-sorted-doubly-linked-list", "url_en": "https://leetcode.com/problems/convert-binary-search-tree-to-sorted-doubly-linked-list", "relative_path_cn": "/solution/0400-0499/0426.Convert%20Binary%20Search%20Tree%20to%20Sorted%20Doubly%20Linked%20List/README.md", "relative_path_en": "/solution/0400-0499/0426.Convert%20Binary%20Search%20Tree%20to%20Sorted%20Doubly%20Linked%20List/README_EN.md", "title_cn": "\u5c06\u4e8c\u53c9\u641c\u7d22\u6811\u8f6c\u5316\u4e3a\u6392\u5e8f\u7684\u53cc\u5411\u94fe\u8868", "title_en": "Convert Binary Search Tree to Sorted Doubly Linked List", "question_title_slug": "convert-binary-search-tree-to-sorted-doubly-linked-list", "content_en": "

Convert a Binary Search Tree to a sorted Circular Doubly-Linked List in place.

\n\n

You can think of the left and right pointers as synonymous to the predecessor and successor pointers in a doubly-linked list. For a circular doubly linked list, the predecessor of the first element is the last element, and the successor of the last element is the first element.

\n\n

We want to do the transformation in place. After the transformation, the left pointer of the tree node should point to its predecessor, and the right pointer should point to its successor. You should return the pointer to the smallest element of the linked list.

\n\n

 

\n

Example 1:

\n\n

\n\n
\nInput: root = [4,2,5,1,3]\n\n\nOutput: [1,2,3,4,5]\n\nExplanation: The figure below shows the transformed BST. The solid line indicates the successor relationship, while the dashed line means the predecessor relationship.\n\n
\n\n

Example 2:

\n\n
\nInput: root = [2,1,3]\nOutput: [1,2,3]\n
\n\n

Example 3:

\n\n
\nInput: root = []\nOutput: []\nExplanation: Input is an empty tree. Output is also an empty Linked List.\n
\n\n

Example 4:

\n\n
\nInput: root = [1]\nOutput: [1]\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • The number of nodes in the tree is in the range [0, 2000].
  • \n\t
  • -1000 <= Node.val <= 1000
  • \n\t
  • All the values of the tree are unique.
  • \n
\n", "content_cn": "

\u5c06\u4e00\u4e2a \u4e8c\u53c9\u641c\u7d22\u6811 \u5c31\u5730\u8f6c\u5316\u4e3a\u4e00\u4e2a \u5df2\u6392\u5e8f\u7684\u53cc\u5411\u5faa\u73af\u94fe\u8868 \u3002

\n\n

\u5bf9\u4e8e\u53cc\u5411\u5faa\u73af\u5217\u8868\uff0c\u4f60\u53ef\u4ee5\u5c06\u5de6\u53f3\u5b69\u5b50\u6307\u9488\u4f5c\u4e3a\u53cc\u5411\u5faa\u73af\u94fe\u8868\u7684\u524d\u9a71\u548c\u540e\u7ee7\u6307\u9488\uff0c\u7b2c\u4e00\u4e2a\u8282\u70b9\u7684\u524d\u9a71\u662f\u6700\u540e\u4e00\u4e2a\u8282\u70b9\uff0c\u6700\u540e\u4e00\u4e2a\u8282\u70b9\u7684\u540e\u7ee7\u662f\u7b2c\u4e00\u4e2a\u8282\u70b9\u3002

\n\n

\u7279\u522b\u5730\uff0c\u6211\u4eec\u5e0c\u671b\u53ef\u4ee5 \u5c31\u5730 \u5b8c\u6210\u8f6c\u6362\u64cd\u4f5c\u3002\u5f53\u8f6c\u5316\u5b8c\u6210\u4ee5\u540e\uff0c\u6811\u4e2d\u8282\u70b9\u7684\u5de6\u6307\u9488\u9700\u8981\u6307\u5411\u524d\u9a71\uff0c\u6811\u4e2d\u8282\u70b9\u7684\u53f3\u6307\u9488\u9700\u8981\u6307\u5411\u540e\u7ee7\u3002\u8fd8\u9700\u8981\u8fd4\u56de\u94fe\u8868\u4e2d\u6700\u5c0f\u5143\u7d20\u7684\u6307\u9488\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aroot = [4,2,5,1,3] \n\n\n\u8f93\u51fa\uff1a[1,2,3,4,5]\n\n\u89e3\u91ca\uff1a\u4e0b\u56fe\u663e\u793a\u4e86\u8f6c\u5316\u540e\u7684\u4e8c\u53c9\u641c\u7d22\u6811\uff0c\u5b9e\u7ebf\u8868\u793a\u540e\u7ee7\u5173\u7cfb\uff0c\u865a\u7ebf\u8868\u793a\u524d\u9a71\u5173\u7cfb\u3002\n\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aroot = [2,1,3]\n\u8f93\u51fa\uff1a[1,2,3]\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1aroot = []\n\u8f93\u51fa\uff1a[]\n\u89e3\u91ca\uff1a\u8f93\u5165\u662f\u7a7a\u6811\uff0c\u6240\u4ee5\u8f93\u51fa\u4e5f\u662f\u7a7a\u94fe\u8868\u3002\n
\n\n

\u793a\u4f8b 4\uff1a

\n\n
\n\u8f93\u5165\uff1aroot = [1]\n\u8f93\u51fa\uff1a[1]\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • -1000 <= Node.val <= 1000
  • \n\t
  • Node.left.val < Node.val < Node.right.val
  • \n\t
  • Node.val \u7684\u6240\u6709\u503c\u90fd\u662f\u72ec\u4e00\u65e0\u4e8c\u7684
  • \n\t
  • 0 <= Number of Nodes <= 2000
  • \n
\n", "tags_en": ["Tree", "Linked List", "Divide and Conquer"], "tags_cn": ["\u6811", "\u94fe\u8868", "\u5206\u6cbb\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n\n Node() {}\n\n Node(int _val) {\n val = _val;\n left = NULL;\n right = NULL;\n }\n\n Node(int _val, Node* _left, Node* _right) {\n val = _val;\n left = _left;\n right = _right;\n }\n};\n*/\n\nclass Solution {\npublic:\n Node* treeToDoublyList(Node* root) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/*\n// Definition for a Node.\nclass Node {\n public int val;\n public Node left;\n public Node right;\n\n public Node() {}\n\n public Node(int _val) {\n val = _val;\n }\n\n public Node(int _val,Node _left,Node _right) {\n val = _val;\n left = _left;\n right = _right;\n }\n};\n*/\n\nclass Solution {\n public Node treeToDoublyList(Node root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "\"\"\"\n# Definition for a Node.\nclass Node(object):\n def __init__(self, val, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\"\"\"\n\nclass Solution(object):\n def treeToDoublyList(self, root):\n \"\"\"\n :type root: Node\n :rtype: Node\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "\"\"\"\n# Definition for a Node.\nclass Node:\n def __init__(self, val, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\"\"\"\n\nclass Solution:\n def treeToDoublyList(self, root: 'Node') -> 'Node':\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/*\n// Definition for a Node.\nstruct Node {\n int val;\n struct Node* left;\n struct Node* right;\n};\n*/\n\nstruct Node* treeToDoublyList(struct Node *root) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/*\n// Definition for a Node.\npublic class Node {\n public int val;\n public Node left;\n public Node right;\n\n public Node() {}\n\n public Node(int _val) {\n val = _val;\n left = null;\n right = null;\n }\n\n public Node(int _val,Node _left,Node _right) {\n val = _val;\n left = _left;\n right = _right;\n }\n}\n*/\n\npublic class Solution {\n public Node TreeToDoublyList(Node root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // Definition for a Node.\n * function Node(val, left, right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * };\n */\n\n/**\n * @param {Node} root\n * @return {Node}\n */\nvar treeToDoublyList = function(root) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a Node.\n# class Node\n# attr_accessor :val, :left, :right\n# def initialize(val=0)\n# @val = val\n# @left, @right = nil, nil\n# end\n# end\n\n# @param {Node} root\n# @return {Node}\ndef treeToDoublyList(root)\n\t\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a Node.\n * public class Node {\n * public var val: Int\n * public var left: Node?\n * public var right: Node?\n * public init(_ val: Int) {\n * self.val = val\n * self.left = nil\n * self.right = nil\n * }\n * }\n */\n\nclass Solution {\n func treeToDoublyList(_ root: Node?) -> Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a Node.\n * type Node struct {\n * Val int\n * Left *Node\n * Right *Node\n * }\n */\n\nfunc treeToDoublyList(root *Node) *Node {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a Node.\n * class Node(var _value: Int) {\n * var value: Int = _value\n * var left: Node = null\n * var right: Node = null\n * }\n */\n\nobject Solution {\n def treeToDoublyList(root: Node): Node = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a Node.\n * class Node(var `val`: Int) {\n * var left: Node? = null\n * var right: Node? = null\n * }\n */\n\nclass Solution {\n fun treeToDoublyList(root:Node?): Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a Node.\n * class Node {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0) {\n * $this->val = $val;\n * $this->left = null;\n * $this->right = null;\n * }\n * }\n */\n\nclass Solution {\n /**\n * @param Node $root\n * @return Node\n */\n function treeToDoublyList($root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class Node {\n * val: number\n * left: Node | null\n * right: Node | null\n * constructor(val?: number, left?: Node | null, right?: Node | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction treeToDoublyList(root: Node | null): Node | null {\n\t\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0426](https://leetcode-cn.com/problems/convert-binary-search-tree-to-sorted-doubly-linked-list)", "[\u5c06\u4e8c\u53c9\u641c\u7d22\u6811\u8f6c\u5316\u4e3a\u6392\u5e8f\u7684\u53cc\u5411\u94fe\u8868](/solution/0400-0499/0426.Convert%20Binary%20Search%20Tree%20to%20Sorted%20Doubly%20Linked%20List/README.md)", "`\u6811`,`\u94fe\u8868`,`\u5206\u6cbb\u7b97\u6cd5`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0426](https://leetcode.com/problems/convert-binary-search-tree-to-sorted-doubly-linked-list)", "[Convert Binary Search Tree to Sorted Doubly Linked List](/solution/0400-0499/0426.Convert%20Binary%20Search%20Tree%20to%20Sorted%20Doubly%20Linked%20List/README_EN.md)", "`Tree`,`Linked List`,`Divide and Conquer`", "Medium", "\ud83d\udd12"]}, {"question_id": "0757", "frontend_question_id": "0756", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/pyramid-transition-matrix", "url_en": "https://leetcode.com/problems/pyramid-transition-matrix", "relative_path_cn": "/solution/0700-0799/0756.Pyramid%20Transition%20Matrix/README.md", "relative_path_en": "/solution/0700-0799/0756.Pyramid%20Transition%20Matrix/README_EN.md", "title_cn": "\u91d1\u5b57\u5854\u8f6c\u6362\u77e9\u9635", "title_en": "Pyramid Transition Matrix", "question_title_slug": "pyramid-transition-matrix", "content_en": "

We are stacking blocks to form a pyramid. Each block has a color which is a one-letter string.

\n\n

We are allowed to place any color block C on top of two adjacent blocks of colors A and B, if and only if ABC is an allowed triple.

\n\n

We start with a bottom row of bottom, represented as a single string. We also start with a list of allowed triples allowed. Each allowed triple is represented as a string of length 3.

\n\n

Return true if we can build the pyramid all the way to the top, otherwise false.

\n\n

 

\n

Example 1:

\n\n
\nInput: bottom = "BCD", allowed = ["BCG","CDE","GEA","FFF"]\nOutput: true\nExplanation:\nWe can stack the pyramid like this:\n    A\n   / \\\n  G   E\n / \\ / \\\nB   C   D\n\nWe are allowed to place G on top of B and C because BCG is an allowed triple.  Similarly, we can place E on top of C and D, then A on top of G and E.\n
\n\n

Example 2:

\n\n
\nInput: bottom = "AABA", allowed = ["AAA","AAB","ABA","ABB","BAC"]\nOutput: false\nExplanation:\nWe cannot stack the pyramid to the top.\nNote that there could be allowed triples (A, B, C) and (A, B, D) with C != D.\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 2 <= bottom.length <= 8
  • \n\t
  • 0 <= allowed.length <= 200
  • \n\t
  • allowed[i].length == 3
  • \n\t
  • The letters in all input strings are from the set {'A', 'B', 'C', 'D', 'E', 'F', 'G'}.
  • \n
\n", "content_cn": "

\u73b0\u5728\uff0c\u6211\u4eec\u7528\u4e00\u4e9b\u65b9\u5757\u6765\u5806\u780c\u4e00\u4e2a\u91d1\u5b57\u5854\u3002 \u6bcf\u4e2a\u65b9\u5757\u7528\u4ec5\u5305\u542b\u4e00\u4e2a\u5b57\u6bcd\u7684\u5b57\u7b26\u4e32\u8868\u793a\u3002

\n\n

\u4f7f\u7528\u4e09\u5143\u7ec4\u8868\u793a\u91d1\u5b57\u5854\u7684\u5806\u780c\u89c4\u5219\u5982\u4e0b\uff1a

\n\n

\u5bf9\u4e8e\u4e09\u5143\u7ec4 ABC \uff0cC \u4e3a\u9876\u5c42\u65b9\u5757\uff0c\u65b9\u5757 A \u3001B \u5206\u522b\u4f5c\u4e3a\u65b9\u5757 C \u4e0b\u4e00\u5c42\u7684\u7684\u5de6\u3001\u53f3\u5b50\u5757\u3002\u5f53\u4e14\u4ec5\u5f53 ABC \u662f\u88ab\u5141\u8bb8\u7684\u4e09\u5143\u7ec4\uff0c\u6211\u4eec\u624d\u53ef\u4ee5\u5c06\u5176\u5806\u780c\u4e0a\u3002

\n\n

\u521d\u59cb\u65f6\uff0c\u7ed9\u5b9a\u91d1\u5b57\u5854\u7684\u57fa\u5c42\u00a0bottom\uff0c\u7528\u4e00\u4e2a\u5b57\u7b26\u4e32\u8868\u793a\u3002\u4e00\u4e2a\u5141\u8bb8\u7684\u4e09\u5143\u7ec4\u5217\u8868\u00a0allowed\uff0c\u6bcf\u4e2a\u4e09\u5143\u7ec4\u7528\u4e00\u4e2a\u957f\u5ea6\u4e3a 3 \u7684\u5b57\u7b26\u4e32\u8868\u793a\u3002

\n\n

\u5982\u679c\u53ef\u4ee5\u7531\u57fa\u5c42\u4e00\u76f4\u5806\u5230\u5854\u5c16\u5c31\u8fd4\u56de true \uff0c\u5426\u5219\u8fd4\u56de false \u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1abottom = \"BCD\", allowed = [\"BCG\", \"CDE\", \"GEA\", \"FFF\"]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\n\u53ef\u4ee5\u5806\u780c\u6210\u8fd9\u6837\u7684\u91d1\u5b57\u5854:\n    A\n   / \\\n  G   E\n / \\ / \\\nB   C   D\n\n\u56e0\u4e3a\u7b26\u5408 BCG\u3001CDE \u548c GEA \u4e09\u79cd\u89c4\u5219\u3002\n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1abottom = \"AABA\", allowed = [\"AAA\", \"AAB\", \"ABA\", \"ABB\", \"BAC\"]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\n\u65e0\u6cd5\u4e00\u76f4\u5806\u5230\u5854\u5c16\u3002\n\u6ce8\u610f, \u5141\u8bb8\u5b58\u5728\u50cf ABC \u548c ABD \u8fd9\u6837\u7684\u4e09\u5143\u7ec4\uff0c\u5176\u4e2d C != D\u3002\n
\n\n

\u00a0

\n\n

\u63d0\u793a\uff1a

\n\n
    \n\t
  • bottom \u7684\u957f\u5ea6\u8303\u56f4\u5728\u00a0[2, 8]\u3002
  • \n\t
  • allowed \u7684\u957f\u5ea6\u8303\u56f4\u5728[0, 200]\u3002
  • \n\t
  • \u65b9\u5757\u7684\u6807\u8bb0\u5b57\u6bcd\u8303\u56f4\u4e3a{'A', 'B', 'C', 'D', 'E', 'F', 'G'}\u3002
  • \n
\n", "tags_en": ["Bit Manipulation", "Depth-first Search"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool pyramidTransition(string bottom, vector& allowed) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean pyramidTransition(String bottom, List allowed) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def pyramidTransition(self, bottom, allowed):\n \"\"\"\n :type bottom: str\n :type allowed: List[str]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def pyramidTransition(self, bottom: str, allowed: List[str]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool pyramidTransition(char * bottom, char ** allowed, int allowedSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool PyramidTransition(string bottom, IList allowed) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} bottom\n * @param {string[]} allowed\n * @return {boolean}\n */\nvar pyramidTransition = function(bottom, allowed) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} bottom\n# @param {String[]} allowed\n# @return {Boolean}\ndef pyramid_transition(bottom, allowed)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func pyramidTransition(_ bottom: String, _ allowed: [String]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func pyramidTransition(bottom string, allowed []string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def pyramidTransition(bottom: String, allowed: List[String]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun pyramidTransition(bottom: String, allowed: List): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn pyramid_transition(bottom: String, allowed: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $bottom\n * @param String[] $allowed\n * @return Boolean\n */\n function pyramidTransition($bottom, $allowed) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function pyramidTransition(bottom: string, allowed: string[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (pyramid-transition bottom allowed)\n (-> string? (listof string?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0756](https://leetcode-cn.com/problems/pyramid-transition-matrix)", "[\u91d1\u5b57\u5854\u8f6c\u6362\u77e9\u9635](/solution/0700-0799/0756.Pyramid%20Transition%20Matrix/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0756](https://leetcode.com/problems/pyramid-transition-matrix)", "[Pyramid Transition Matrix](/solution/0700-0799/0756.Pyramid%20Transition%20Matrix/README_EN.md)", "`Bit Manipulation`,`Depth-first Search`", "Medium", ""]}, {"question_id": "0756", "frontend_question_id": "0755", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/pour-water", "url_en": "https://leetcode.com/problems/pour-water", "relative_path_cn": "/solution/0700-0799/0755.Pour%20Water/README.md", "relative_path_en": "/solution/0700-0799/0755.Pour%20Water/README_EN.md", "title_cn": "\u5012\u6c34", "title_en": "Pour Water", "question_title_slug": "pour-water", "content_en": "

We are given an elevation map, heights[i] representing the height of the terrain at that index. The width at each index is 1. After volume units of water fall at index k, how much water is at each index?

\n\n

Water first drops at index k and rests on top of the highest terrain or water at that index. Then, it flows according to the following rules:

\n\n
    \n\t
  • If the droplet would eventually fall by moving left, then move left.
  • \n\t
  • Otherwise, if the droplet would eventually fall by moving right, then move right.
  • \n\t
  • Otherwise, rise at it's current position.
  • \n
\n\n

Here, "eventually fall" means that the droplet will eventually be at a lower level if it moves in that direction. Also, "level" means the height of the terrain plus any water in that column.

\n\n

We can assume there's infinitely high terrain on the two sides out of bounds of the array. Also, there could not be partial water being spread out evenly on more than 1 grid block - each unit of water has to be in exactly one block.

\n\n

Example 1:

\n\n
\nInput: heights = [2,1,1,2,1,2,2], volume = 4, k = 3\nOutput: [2,2,2,3,2,2,2]\nExplanation:\n#       #\n#       #\n##  # ###\n#########\n 0123456    <- index\n\nThe first drop of water lands at index k = 3:\n\n#       #\n#   w   #\n##  # ###\n#########\n 0123456    \n\nWhen moving left or right, the water can only move to the same level or a lower level.\n(By level, we mean the total height of the terrain plus any water in that column.)\nSince moving left will eventually make it fall, it moves left.\n(A droplet "made to fall" means go to a lower height than it was at previously.)\n\n#       #\n#       #\n## w# ###\n#########\n 0123456    \n\nSince moving left will not make it fall, it stays in place.  The next droplet falls:\n\n#       #\n#   w   #\n## w# ###\n#########\n 0123456  \n\nSince the new droplet moving left will eventually make it fall, it moves left.\nNotice that the droplet still preferred to move left,\neven though it could move right (and moving right makes it fall quicker.)\n\n#       #\n#  w    #\n## w# ###\n#########\n 0123456  \n\n#       #\n#       #\n##ww# ###\n#########\n 0123456  \n\nAfter those steps, the third droplet falls.\nSince moving left would not eventually make it fall, it tries to move right.\nSince moving right would eventually make it fall, it moves right.\n\n#       #\n#   w   #\n##ww# ###\n#########\n 0123456  \n\n#       #\n#       #\n##ww#w###\n#########\n 0123456  \n\nFinally, the fourth droplet falls.\nSince moving left would not eventually make it fall, it tries to move right.\nSince moving right would not eventually make it fall, it stays in place:\n\n#       #\n#   w   #\n##ww#w###\n#########\n 0123456  \n\nThe final answer is [2,2,2,3,2,2,2]:\n\n    #    \n ####### \n ####### \n 0123456 \n
\n\n

Example 2:

\n\n
\nInput: heights = [1,2,3,4], volume = 2, k = 2\nOutput: [2,3,3,4]\nExplanation:\nThe last droplet settles at index 1, since moving further left would not cause it to eventually fall to a lower height.\n
\n\n

Example 3:

\n\n
\nInput: heights = [3,1,3], volume = 5, k = 1\nOutput: [4,4,4]\n
\n\n

Note:

\n\n
    \n\t
  1. heights will have length in [1, 100] and contain integers in [0, 99].
  2. \n\t
  3. volume will be in range [0, 2000].
  4. \n\t
  5. k will be in range [0, heights.length - 1].
  6. \n
\n\n

 

\n", "content_cn": "

\u7ed9\u51fa\u4e00\u4e2a\u5730\u5f62\u9ad8\u5ea6\u56fe\uff0c heights[i] \u8868\u793a\u8be5\u7d22\u5f15\u5904\u7684\u9ad8\u5ea6\u3002\u6bcf\u4e2a\u7d22\u5f15\u7684\u5bbd\u5ea6\u4e3a 1\u3002\u5728 V \u4e2a\u5355\u4f4d\u7684\u6c34\u843d\u5728\u7d22\u5f15 K \u5904\u4ee5\u540e\uff0c\u6bcf\u4e2a\u7d22\u5f15\u4f4d\u7f6e\u6709\u591a\u5c11\u6c34\uff1f

\n\n

\u6c34\u6700\u5148\u4f1a\u5728\u7d22\u5f15 K \u5904\u4e0b\u964d\u5e76\u4e14\u843d\u5728\u8be5\u7d22\u5f15\u4f4d\u7f6e\u7684\u6700\u9ad8\u5730\u5f62\u6216\u6c34\u9762\u4e4b\u4e0a\u3002\u7136\u540e\u6309\u5982\u4e0b\u65b9\u5f0f\u6d41\u52a8\uff1a

\n\n
    \n\t
  • \u5982\u679c\u6db2\u6ef4\u6700\u7ec8\u53ef\u4ee5\u901a\u8fc7\u5411\u5de6\u6d41\u52a8\u800c\u4e0b\u964d\uff0c\u5219\u5411\u5de6\u6d41\u52a8\u3002
  • \n\t
  • \u5426\u5219\uff0c\u5982\u679c\u6db2\u6ef4\u6700\u7ec8\u53ef\u4ee5\u901a\u8fc7\u5411\u53f3\u6d41\u52a8\u800c\u4e0b\u964d\uff0c\u5219\u5411\u53f3\u6d41\u52a8\u3002
  • \n\t
  • \u5426\u5219\uff0c\u5728\u5f53\u524d\u7684\u4f4d\u7f6e\u4e0a\u5347\u3002
  • \n\t
  • \u8fd9\u91cc\uff0c\u201c\u6700\u7ec8\u4e0b\u964d\u201d \u7684\u610f\u601d\u662f\u6db2\u6ef4\u5982\u679c\u6309\u6b64\u65b9\u5411\u79fb\u52a8\u7684\u8bdd\uff0c\u6700\u7ec8\u53ef\u4ee5\u4e0b\u964d\u5230\u4e00\u4e2a\u8f83\u4f4e\u7684\u6c34\u5e73\u3002\u800c\u4e14\uff0c\u201c\u6c34\u5e73\u201d\u7684\u610f\u601d\u662f\u5f53\u524d\u5217\u7684\u5730\u5f62\u7684\u9ad8\u5ea6\u52a0\u4e0a\u6c34\u7684\u9ad8\u5ea6\u3002
  • \n
\n\n

\u6211\u4eec\u53ef\u4ee5\u5047\u5b9a\u5728\u6570\u7ec4\u4e24\u4fa7\u7684\u8fb9\u754c\u5916\u6709\u65e0\u9650\u9ad8\u7684\u5730\u5f62\u3002\u800c\u4e14\uff0c\u4e0d\u80fd\u6709\u90e8\u5206\u6c34\u5728\u591a\u4e8e 1 \u4e2a\u7684\u7f51\u683c\u5757\u4e0a\u5747\u5300\u5206\u5e03 - \u6bcf\u4e2a\u5355\u4f4d\u7684\u6c34\u5fc5\u987b\u8981\u4f4d\u4e8e\u4e00\u4e2a\u5757\u4e2d\u3002

\n\n

\u00a0

\n\n

\u793a\u4f8b 1\uff1a

\n\n
\n\u8f93\u5165\uff1aheights = [2,1,1,2,1,2,2], V = 4, K = 3\n\u8f93\u51fa\uff1a[2,2,2,3,2,2,2]\n\u89e3\u91ca\uff1a\n#       #\n#       #\n##  # ###\n#########\n 0123456    <- \u7d22\u5f15\n\n\u7b2c\u4e00\u4e2a\u6c34\u6ef4\u964d\u843d\u5728\u7d22\u5f15 K = 3 \u4e0a\uff1a\n\n#       #\n#   w   #\n##  # ###\n#########\n 0123456    \n\n\u5f53\u5411\u5de6\u6216\u5411\u53f3\u79fb\u52a8\u65f6\uff0c\u6c34\u53ef\u4ee5\u79fb\u52a8\u5230\u76f8\u540c\u6216\u66f4\u4f4e\u7684\u9ad8\u5ea6\u3002When moving left or right, the water can only move to the same level or a lower level.\n\uff08\u4ece\u6c34\u5e73\u4e0a\u770b\uff0c\u610f\u601d\u662f\u8be5\u5217\u7684\u5730\u5f62\u9ad8\u5ea6\u52a0\u4e0a\u6c34\u7684\u9ad8\u5ea6\uff09\n\u7531\u4e8e\u5411\u5de6\u79fb\u52a8\u53ef\u4ee5\u6700\u7ec8\u4e0b\u843d\uff0c\u56e0\u6b64\u5411\u5de6\u79fb\u52a8\u3002\n\uff08\u4e00\u4e2a\u6c34\u6ef4 \u201c\u4e0b\u843d\u201d \u7684\u610f\u601d\u662f\u53ef\u4ee5\u76f8\u6bd4\u4e4b\u524d\u53ef\u4ee5\u8fdb\u5165\u66f4\u4f4e\u7684\u9ad8\u5ea6\uff09\n\n#       #\n#       #\n## w# ###\n#########\n 0123456    \n\n\u7531\u4e8e\u5411\u5de6\u79fb\u52a8\u4e0d\u4f1a\u4f7f\u5176\u964d\u843d\uff0c\u6240\u4ee5\u505c\u5728\u8be5\u4f4d\u7f6e\u4e0a\u3002\u4e0b\u4e00\u4e2a\u6c34\u6ef4\u4e0b\u843d\uff1a\n\n#       #\n#   w   #\n## w# ###\n#########\n 0123456  \n\n\n\u7531\u4e8e\u65b0\u6c34\u6ef4\u5411\u5de6\u79fb\u52a8\u53ef\u4ee5\u6700\u7ec8\u4e0b\u843d\uff0c\u56e0\u6b64\u5411\u5de6\u79fb\u52a8\u3002\n\u6ce8\u610f\u6c34\u6ef4\u4ecd\u7136\u662f\u4f18\u5148\u9009\u62e9\u5411\u5de6\u79fb\u52a8\uff0c\n\u5c3d\u7ba1\u53ef\u4ee5\u5411\u53f3\u79fb\u52a8\uff08\u800c\u4e14\u5411\u53f3\u79fb\u52a8\u53ef\u4ee5\u4e0b\u843d\u66f4\u5feb\uff09\n\n\n#       #\n#  w    #\n## w# ###\n#########\n 0123456  \n\n#       #\n#       #\n##ww# ###\n#########\n 0123456  \n\n\u7ecf\u8fc7\u521a\u624d\u7684\u9636\u6bb5\u540e\uff0c\u7b2c\u4e09\u4e2a\u6c34\u6ef4\u4e0b\u843d\u3002\n\u7531\u4e8e\u5411\u5de6\u79fb\u52a8\u4e0d\u4f1a\u6700\u7ec8\u4e0b\u843d\uff0c\u56e0\u6b64\u5c1d\u8bd5\u5411\u53f3\u79fb\u52a8\u3002\n\u7531\u4e8e\u5411\u53f3\u79fb\u52a8\u53ef\u4ee5\u6700\u7ec8\u4e0b\u843d\uff0c\u56e0\u6b64\u5411\u53f3\u79fb\u52a8\u3002\n\n\n#       #\n#   w   #\n##ww# ###\n#########\n 0123456  \n\n#       #\n#       #\n##ww#w###\n#########\n 0123456  \n\n\u6700\u7ec8\uff0c\u7b2c\u56db\u4e2a\u6c34\u6ef4\u4e0b\u843d\u3002\n\u7531\u4e8e\u5411\u5de6\u79fb\u52a8\u4e0d\u4f1a\u6700\u7ec8\u4e0b\u843d\uff0c\u56e0\u6b64\u5c1d\u8bd5\u5411\u53f3\u79fb\u52a8\u3002\n\u7531\u4e8e\u5411\u53f3\u79fb\u52a8\u4e0d\u4f1a\u6700\u7ec8\u4e0b\u843d\uff0c\u56e0\u6b64\u505c\u5728\u5f53\u524d\u4f4d\u7f6e\uff1a\n\n#       #\n#   w   #\n##ww#w###\n#########\n 0123456  \n\n\u6700\u7ec8\u7684\u7b54\u6848\u4e3a [2,2,2,3,2,2,2]:\n\n    #    \n ####### \n ####### \n 0123456 \n
\n\n

\u793a\u4f8b 2\uff1a

\n\n
\n\u8f93\u5165\uff1aheights = [1,2,3,4], V = 2, K = 2\n\u8f93\u51fa\uff1a[2,3,3,4]\n\u89e3\u91ca\uff1a\n\u6700\u540e\u7684\u6c34\u6ef4\u843d\u5728\u7d22\u5f15 1 \u4f4d\u7f6e\uff0c\u56e0\u4e3a\u7ee7\u7eed\u5411\u5de6\u79fb\u52a8\u4e0d\u4f1a\u4f7f\u5176\u4e0b\u964d\u5230\u66f4\u4f4e\u7684\u9ad8\u5ea6\u3002\n
\n\n

\u793a\u4f8b 3\uff1a

\n\n
\n\u8f93\u5165\uff1aheights = [3,1,3], V = 5, K = 1\n\u8f93\u51fa\uff1a[4,4,4]\n
\n\n

\u00a0

\n\n

\u6ce8\uff1a

\n\n
    \n\t
  1. heights \u7684\u957f\u5ea6\u4e3a\u00a0[1, 100]\u00a0\uff0c\u5e76\u4e14\u6bcf\u4e2a\u6570\u7684\u8303\u56f4\u4e3a[0, 99]\u3002
  2. \n\t
  3. V \u7684\u8303\u56f4\u00a0[0, 2000]\u3002
  4. \n\t
  5. K\u00a0\u7684\u8303\u56f4\u00a0[0, heights.length - 1]\u3002
  6. \n
\n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector pourWater(vector& heights, int volume, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] pourWater(int[] heights, int volume, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def pourWater(self, heights, volume, k):\n \"\"\"\n :type heights: List[int]\n :type volume: int\n :type k: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def pourWater(self, heights: List[int], volume: int, k: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* pourWater(int* heights, int heightsSize, int volume, int k, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] PourWater(int[] heights, int volume, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} heights\n * @param {number} volume\n * @param {number} k\n * @return {number[]}\n */\nvar pourWater = function(heights, volume, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} heights\n# @param {Integer} volume\n# @param {Integer} k\n# @return {Integer[]}\ndef pour_water(heights, volume, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func pourWater(_ heights: [Int], _ volume: Int, _ k: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func pourWater(heights []int, volume int, k int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def pourWater(heights: Array[Int], volume: Int, k: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun pourWater(heights: IntArray, volume: Int, k: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn pour_water(heights: Vec, volume: i32, k: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $heights\n * @param Integer $volume\n * @param Integer $k\n * @return Integer[]\n */\n function pourWater($heights, $volume, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function pourWater(heights: number[], volume: number, k: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (pour-water heights volume k)\n (-> (listof exact-integer?) exact-integer? exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0755](https://leetcode-cn.com/problems/pour-water)", "[\u5012\u6c34](/solution/0700-0799/0755.Pour%20Water/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0755](https://leetcode.com/problems/pour-water)", "[Pour Water](/solution/0700-0799/0755.Pour%20Water/README_EN.md)", "`Array`", "Medium", "\ud83d\udd12"]}, {"question_id": "0755", "frontend_question_id": "0754", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reach-a-number", "url_en": "https://leetcode.com/problems/reach-a-number", "relative_path_cn": "/solution/0700-0799/0754.Reach%20a%20Number/README.md", "relative_path_en": "/solution/0700-0799/0754.Reach%20a%20Number/README_EN.md", "title_cn": "\u5230\u8fbe\u7ec8\u70b9\u6570\u5b57", "title_en": "Reach a Number", "question_title_slug": "reach-a-number", "content_en": "

\r\nYou are standing at position 0 on an infinite number line. There is a goal at position target.\r\n

\r\nOn each move, you can either go left or right. During the n-th move (starting from 1), you take n steps.\r\n

\r\nReturn the minimum number of steps required to reach the destination.\r\n

\r\n\r\n

Example 1:
\r\n

\r\nInput: target = 3\r\nOutput: 2\r\nExplanation:\r\nOn the first move we step from 0 to 1.\r\nOn the second step we step from 1 to 3.\r\n
\r\n

\r\n\r\n

Example 2:
\r\n

\r\nInput: target = 2\r\nOutput: 3\r\nExplanation:\r\nOn the first move we step from 0 to 1.\r\nOn the second move we step  from 1 to -1.\r\nOn the third move we step from -1 to 2.\r\n
\r\n

\r\n\r\n

Note:
\r\n

  • target will be a non-zero integer in the range [-10^9, 10^9].
  • \r\n

    ", "content_cn": "

    \u5728\u4e00\u6839\u65e0\u9650\u957f\u7684\u6570\u8f74\u4e0a\uff0c\u4f60\u7ad9\u57280\u7684\u4f4d\u7f6e\u3002\u7ec8\u70b9\u5728target\u7684\u4f4d\u7f6e\u3002

    \n\n

    \u6bcf\u6b21\u4f60\u53ef\u4ee5\u9009\u62e9\u5411\u5de6\u6216\u5411\u53f3\u79fb\u52a8\u3002\u7b2c n \u6b21\u79fb\u52a8\uff08\u4ece 1 \u5f00\u59cb\uff09\uff0c\u53ef\u4ee5\u8d70 n \u6b65\u3002

    \n\n

    \u8fd4\u56de\u5230\u8fbe\u7ec8\u70b9\u9700\u8981\u7684\u6700\u5c0f\u79fb\u52a8\u6b21\u6570\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: target = 3\n\u8f93\u51fa: 2\n\u89e3\u91ca:\n\u7b2c\u4e00\u6b21\u79fb\u52a8\uff0c\u4ece 0 \u5230 1 \u3002\n\u7b2c\u4e8c\u6b21\u79fb\u52a8\uff0c\u4ece 1 \u5230 3 \u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: target = 2\n\u8f93\u51fa: 3\n\u89e3\u91ca:\n\u7b2c\u4e00\u6b21\u79fb\u52a8\uff0c\u4ece 0 \u5230 1 \u3002\n\u7b2c\u4e8c\u6b21\u79fb\u52a8\uff0c\u4ece 1 \u5230 -1 \u3002\n\u7b2c\u4e09\u6b21\u79fb\u52a8\uff0c\u4ece -1 \u5230 2 \u3002\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    • target\u662f\u5728[-10^9, 10^9]\u8303\u56f4\u4e2d\u7684\u975e\u96f6\u6574\u6570\u3002
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int reachNumber(int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int reachNumber(int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def reachNumber(self, target):\n \"\"\"\n :type target: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def reachNumber(self, target: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint reachNumber(int target){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ReachNumber(int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} target\n * @return {number}\n */\nvar reachNumber = function(target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} target\n# @return {Integer}\ndef reach_number(target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func reachNumber(_ target: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func reachNumber(target int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def reachNumber(target: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun reachNumber(target: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn reach_number(target: i32) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $target\n * @return Integer\n */\n function reachNumber($target) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function reachNumber(target: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (reach-number target)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0754](https://leetcode-cn.com/problems/reach-a-number)", "[\u5230\u8fbe\u7ec8\u70b9\u6570\u5b57](/solution/0700-0799/0754.Reach%20a%20Number/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0754](https://leetcode.com/problems/reach-a-number)", "[Reach a Number](/solution/0700-0799/0754.Reach%20a%20Number/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "0754", "frontend_question_id": "0753", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/cracking-the-safe", "url_en": "https://leetcode.com/problems/cracking-the-safe", "relative_path_cn": "/solution/0700-0799/0753.Cracking%20the%20Safe/README.md", "relative_path_en": "/solution/0700-0799/0753.Cracking%20the%20Safe/README_EN.md", "title_cn": "\u7834\u89e3\u4fdd\u9669\u7bb1", "title_en": "Cracking the Safe", "question_title_slug": "cracking-the-safe", "content_en": "

    There is a box protected by a password. The password is a sequence of n digits where each digit can be one of the first k digits 0, 1, ..., k-1.

    \n\n

    While entering a password, the last n digits entered will automatically be matched against the correct password.

    \n\n

    For example, assuming the correct password is "345", if you type "012345", the box will open because the correct password matches the suffix of the entered password.

    \n\n

    Return any password of minimum length that is guaranteed to open the box at some point of entering it.

    \n\n

     

    \n\n

    Example 1:

    \n\n
    \nInput: n = 1, k = 2\nOutput: "01"\nNote: "10" will be accepted too.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 2, k = 2\nOutput: "00110"\nNote: "01100", "10011", "11001" will be accepted too.\n
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    1. n will be in the range [1, 4].
    2. \n\t
    3. k will be in the range [1, 10].
    4. \n\t
    5. k^n will be at most 4096.
    6. \n
    \n\n

     

    \n", "content_cn": "

    \u6709\u4e00\u4e2a\u9700\u8981\u5bc6\u7801\u624d\u80fd\u6253\u5f00\u7684\u4fdd\u9669\u7bb1\u3002\u5bc6\u7801\u662f n \u4f4d\u6570, \u5bc6\u7801\u7684\u6bcf\u4e00\u4f4d\u662f k \u4f4d\u5e8f\u5217 0, 1, ..., k-1 \u4e2d\u7684\u4e00\u4e2a \u3002

    \n\n

    \u4f60\u53ef\u4ee5\u968f\u610f\u8f93\u5165\u5bc6\u7801\uff0c\u4fdd\u9669\u7bb1\u4f1a\u81ea\u52a8\u8bb0\u4f4f\u6700\u540e n \u4f4d\u8f93\u5165\uff0c\u5982\u679c\u5339\u914d\uff0c\u5219\u80fd\u591f\u6253\u5f00\u4fdd\u9669\u7bb1\u3002

    \n\n

    \u4e3e\u4e2a\u4f8b\u5b50\uff0c\u5047\u8bbe\u5bc6\u7801\u662f "345"\uff0c\u4f60\u53ef\u4ee5\u8f93\u5165 "012345" \u6765\u6253\u5f00\u5b83\uff0c\u53ea\u662f\u4f60\u8f93\u5165\u4e86 6 \u4e2a\u5b57\u7b26.

    \n\n

    \u8bf7\u8fd4\u56de\u4e00\u4e2a\u80fd\u6253\u5f00\u4fdd\u9669\u7bb1\u7684\u6700\u77ed\u5b57\u7b26\u4e32\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b1:

    \n\n
    \u8f93\u5165: n = 1, k = 2\n\u8f93\u51fa: "01"\n\u8bf4\u660e: "10"\u4e5f\u53ef\u4ee5\u6253\u5f00\u4fdd\u9669\u7bb1\u3002\n
    \n\n

     

    \n\n

    \u793a\u4f8b2:

    \n\n
    \u8f93\u5165: n = 2, k = 2\n\u8f93\u51fa: "00110"\n\u8bf4\u660e: "01100", "10011", "11001" \u4e5f\u80fd\u6253\u5f00\u4fdd\u9669\u7bb1\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. n \u7684\u8303\u56f4\u662f [1, 4]\u3002
    2. \n\t
    3. k \u7684\u8303\u56f4\u662f [1, 10]\u3002
    4. \n\t
    5. k^n \u6700\u5927\u53ef\u80fd\u4e3a 4096\u3002
    6. \n
    \n\n

     

    \n", "tags_en": ["Depth-first Search", "Math"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string crackSafe(int n, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String crackSafe(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def crackSafe(self, n, k):\n \"\"\"\n :type n: int\n :type k: int\n :rtype: str\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def crackSafe(self, n: int, k: int) -> str:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * crackSafe(int n, int k){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string CrackSafe(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} k\n * @return {string}\n */\nvar crackSafe = function(n, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} k\n# @return {String}\ndef crack_safe(n, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func crackSafe(_ n: Int, _ k: Int) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func crackSafe(n int, k int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def crackSafe(n: Int, k: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun crackSafe(n: Int, k: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn crack_safe(n: i32, k: i32) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $k\n * @return String\n */\n function crackSafe($n, $k) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function crackSafe(n: number, k: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (crack-safe n k)\n (-> exact-integer? exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0753](https://leetcode-cn.com/problems/cracking-the-safe)", "[\u7834\u89e3\u4fdd\u9669\u7bb1](/solution/0700-0799/0753.Cracking%20the%20Safe/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[0753](https://leetcode.com/problems/cracking-the-safe)", "[Cracking the Safe](/solution/0700-0799/0753.Cracking%20the%20Safe/README_EN.md)", "`Depth-first Search`,`Math`", "Hard", ""]}, {"question_id": "0753", "frontend_question_id": "0752", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/open-the-lock", "url_en": "https://leetcode.com/problems/open-the-lock", "relative_path_cn": "/solution/0700-0799/0752.Open%20the%20Lock/README.md", "relative_path_en": "/solution/0700-0799/0752.Open%20the%20Lock/README_EN.md", "title_cn": "\u6253\u5f00\u8f6c\u76d8\u9501", "title_en": "Open the Lock", "question_title_slug": "open-the-lock", "content_en": "

    You have a lock in front of you with 4 circular wheels. Each wheel has 10 slots: '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'. The wheels can rotate freely and wrap around: for example we can turn '9' to be '0', or '0' to be '9'. Each move consists of turning one wheel one slot.

    \n\n

    The lock initially starts at '0000', a string representing the state of the 4 wheels.

    \n\n

    You are given a list of deadends dead ends, meaning if the lock displays any of these codes, the wheels of the lock will stop turning and you will be unable to open it.

    \n\n

    Given a target representing the value of the wheels that will unlock the lock, return the minimum total number of turns required to open the lock, or -1 if it is impossible.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: deadends = ["0201","0101","0102","1212","2002"], target = "0202"\nOutput: 6\nExplanation:\nA sequence of valid moves would be "0000" -> "1000" -> "1100" -> "1200" -> "1201" -> "1202" -> "0202".\nNote that a sequence like "0000" -> "0001" -> "0002" -> "0102" -> "0202" would be invalid,\nbecause the wheels of the lock become stuck after the display becomes the dead end "0102".\n
    \n\n

    Example 2:

    \n\n
    \nInput: deadends = ["8888"], target = "0009"\nOutput: 1\nExplanation:\nWe can turn the last wheel in reverse to move from "0000" -> "0009".\n
    \n\n

    Example 3:

    \n\n
    \nInput: deadends = ["8887","8889","8878","8898","8788","8988","7888","9888"], target = "8888"\nOutput: -1\nExplanation:\nWe can't reach the target without getting stuck.\n
    \n\n

    Example 4:

    \n\n
    \nInput: deadends = ["0000"], target = "8888"\nOutput: -1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= deadends.length <= 500
    • \n\t
    • deadends[i].length == 4
    • \n\t
    • target.length == 4
    • \n\t
    • target will not be in the list deadends.
    • \n\t
    • target and deadends[i] consist of digits only.
    • \n
    \n", "content_cn": "

    \u4f60\u6709\u4e00\u4e2a\u5e26\u6709\u56db\u4e2a\u5706\u5f62\u62e8\u8f6e\u7684\u8f6c\u76d8\u9501\u3002\u6bcf\u4e2a\u62e8\u8f6e\u90fd\u670910\u4e2a\u6570\u5b57\uff1a '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' \u3002\u6bcf\u4e2a\u62e8\u8f6e\u53ef\u4ee5\u81ea\u7531\u65cb\u8f6c\uff1a\u4f8b\u5982\u628a '9' \u53d8\u4e3a  '0'\uff0c'0' \u53d8\u4e3a '9' \u3002\u6bcf\u6b21\u65cb\u8f6c\u90fd\u53ea\u80fd\u65cb\u8f6c\u4e00\u4e2a\u62e8\u8f6e\u7684\u4e00\u4f4d\u6570\u5b57\u3002

    \n\n

    \u9501\u7684\u521d\u59cb\u6570\u5b57\u4e3a '0000' \uff0c\u4e00\u4e2a\u4ee3\u8868\u56db\u4e2a\u62e8\u8f6e\u7684\u6570\u5b57\u7684\u5b57\u7b26\u4e32\u3002

    \n\n

    \u5217\u8868 deadends \u5305\u542b\u4e86\u4e00\u7ec4\u6b7b\u4ea1\u6570\u5b57\uff0c\u4e00\u65e6\u62e8\u8f6e\u7684\u6570\u5b57\u548c\u5217\u8868\u91cc\u7684\u4efb\u4f55\u4e00\u4e2a\u5143\u7d20\u76f8\u540c\uff0c\u8fd9\u4e2a\u9501\u5c06\u4f1a\u88ab\u6c38\u4e45\u9501\u5b9a\uff0c\u65e0\u6cd5\u518d\u88ab\u65cb\u8f6c\u3002

    \n\n

    \u5b57\u7b26\u4e32 target \u4ee3\u8868\u53ef\u4ee5\u89e3\u9501\u7684\u6570\u5b57\uff0c\u4f60\u9700\u8981\u7ed9\u51fa\u6700\u5c0f\u7684\u65cb\u8f6c\u6b21\u6570\uff0c\u5982\u679c\u65e0\u8bba\u5982\u4f55\u4e0d\u80fd\u89e3\u9501\uff0c\u8fd4\u56de -1\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165\uff1adeadends = ["0201","0101","0102","1212","2002"], target = "0202"\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\n\u53ef\u80fd\u7684\u79fb\u52a8\u5e8f\u5217\u4e3a "0000" -> "1000" -> "1100" -> "1200" -> "1201" -> "1202" -> "0202"\u3002\n\u6ce8\u610f "0000" -> "0001" -> "0002" -> "0102" -> "0202" \u8fd9\u6837\u7684\u5e8f\u5217\u662f\u4e0d\u80fd\u89e3\u9501\u7684\uff0c\n\u56e0\u4e3a\u5f53\u62e8\u52a8\u5230 "0102" \u65f6\u8fd9\u4e2a\u9501\u5c31\u4f1a\u88ab\u9501\u5b9a\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: deadends = ["8888"], target = "0009"\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\n\u628a\u6700\u540e\u4e00\u4f4d\u53cd\u5411\u65cb\u8f6c\u4e00\u6b21\u5373\u53ef "0000" -> "0009"\u3002\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \n\u8f93\u5165: deadends = ["8887","8889","8878","8898","8788","8988","7888","9888"], target = "8888"\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\n\u65e0\u6cd5\u65cb\u8f6c\u5230\u76ee\u6807\u6570\u5b57\u4e14\u4e0d\u88ab\u9501\u5b9a\u3002\n
    \n\n

    \u793a\u4f8b 4:

    \n\n
    \n\u8f93\u5165: deadends = ["0000"], target = "8888"\n\u8f93\u51fa\uff1a-1\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. \u6b7b\u4ea1\u5217\u8868 deadends \u7684\u957f\u5ea6\u8303\u56f4\u4e3a [1, 500]\u3002
    2. \n\t
    3. \u76ee\u6807\u6570\u5b57 target \u4e0d\u4f1a\u5728 deadends \u4e4b\u4e2d\u3002
    4. \n\t
    5. \u6bcf\u4e2a deadends \u548c target \u4e2d\u7684\u5b57\u7b26\u4e32\u7684\u6570\u5b57\u4f1a\u5728 10,000 \u4e2a\u53ef\u80fd\u7684\u60c5\u51b5 '0000' \u5230 '9999' \u4e2d\u4ea7\u751f\u3002
    6. \n
    \n", "tags_en": ["Breadth-first Search"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int openLock(vector& deadends, string target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int openLock(String[] deadends, String target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def openLock(self, deadends, target):\n \"\"\"\n :type deadends: List[str]\n :type target: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def openLock(self, deadends: List[str], target: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint openLock(char ** deadends, int deadendsSize, char * target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int OpenLock(string[] deadends, string target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} deadends\n * @param {string} target\n * @return {number}\n */\nvar openLock = function(deadends, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} deadends\n# @param {String} target\n# @return {Integer}\ndef open_lock(deadends, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func openLock(_ deadends: [String], _ target: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func openLock(deadends []string, target string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def openLock(deadends: Array[String], target: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun openLock(deadends: Array, target: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn open_lock(deadends: Vec, target: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $deadends\n * @param String $target\n * @return Integer\n */\n function openLock($deadends, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function openLock(deadends: string[], target: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (open-lock deadends target)\n (-> (listof string?) string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0752](https://leetcode-cn.com/problems/open-the-lock)", "[\u6253\u5f00\u8f6c\u76d8\u9501](/solution/0700-0799/0752.Open%20the%20Lock/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0752](https://leetcode.com/problems/open-the-lock)", "[Open the Lock](/solution/0700-0799/0752.Open%20the%20Lock/README_EN.md)", "`Breadth-first Search`", "Medium", ""]}, {"question_id": "0752", "frontend_question_id": "0751", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/ip-to-cidr", "url_en": "https://leetcode.com/problems/ip-to-cidr", "relative_path_cn": "/solution/0700-0799/0751.IP%20to%20CIDR/README.md", "relative_path_en": "/solution/0700-0799/0751.IP%20to%20CIDR/README_EN.md", "title_cn": "IP \u5230 CIDR", "title_en": "IP to CIDR", "question_title_slug": "ip-to-cidr", "content_en": "

    An IP address is a formatted 32-bit unsigned integer where each group of 8 bits is printed as a decimal number and the dot character '.' splits the groups.

    \n\n
      \n\t
    • For example, the binary number 00001111 10001000 11111111 01101011 (spaces added for clarity) formatted as an IP address would be "15.136.255.107".
    • \n
    \n\n

    A CIDR block is a format used to denote a specific set of IP addresses. It is a string consisting of a base IP address, followed by a slash, followed by a prefix length k. The addresses it covers are all the IPs whose first k bits are the same as the base IP address.

    \n\n
      \n\t
    • For example, "123.45.67.89/20" is a CIDR block with a prefix length of 20. Any IP address whose binary representation matches 01111011 00101101 0100xxxx xxxxxxxx, where x can be either 0 or 1, is in the set covered by the CIDR block.
    • \n
    \n\n

    You are given a start IP address ip and the number of IP addresses we need to cover n. Your goal is to use as few CIDR blocks as possible to cover all the IP addresses in the inclusive range [ip, ip + n - 1] exactly. No other IP addresses outside of the range should be covered.

    \n\n

    Return the shortest list of CIDR blocks that covers the range of IP addresses. If there are multiple answers, return any of them.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: ip = "255.0.0.7", n = 10\nOutput: ["255.0.0.7/32","255.0.0.8/29","255.0.0.16/32"]\nExplanation:\nThe IP addresses that need to be covered are:\n- 255.0.0.7  -> 11111111 00000000 00000000 00000111\n- 255.0.0.8  -> 11111111 00000000 00000000 00001000\n- 255.0.0.9  -> 11111111 00000000 00000000 00001001\n- 255.0.0.10 -> 11111111 00000000 00000000 00001010\n- 255.0.0.11 -> 11111111 00000000 00000000 00001011\n- 255.0.0.12 -> 11111111 00000000 00000000 00001100\n- 255.0.0.13 -> 11111111 00000000 00000000 00001101\n- 255.0.0.14 -> 11111111 00000000 00000000 00001110\n- 255.0.0.15 -> 11111111 00000000 00000000 00001111\n- 255.0.0.16 -> 11111111 00000000 00000000 00010000\nThe CIDR block "255.0.0.7/32" covers the first address.\nThe CIDR block "255.0.0.8/29" covers the middle 8 addresses (binary format of 11111111 00000000 00000000 00001xxx).\nThe CIDR block "255.0.0.16/32" covers the last address.\nNote that while the CIDR block "255.0.0.0/28" does cover all the addresses, it also includes addresses outside of the range, so we cannot use it.\n
    \n\n

    Example 2:

    \n\n
    \nInput: ip = "117.145.102.62", n = 8\nOutput: ["117.145.102.62/31","117.145.102.64/30","117.145.102.68/31"]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 7 <= ip.length <= 15
    • \n\t
    • ip is a valid IPv4 on the form "a.b.c.d" where a, b, c, and d are integers in the range [0, 255].
    • \n\t
    • 1 <= n <= 1000
    • \n\t
    • Every implied address ip + x (for x < n) will be a valid IPv4 address.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u8d77\u59cb IP \u5730\u5740 ip \u548c\u4e00\u4e2a\u6211\u4eec\u9700\u8981\u5305\u542b\u7684 IP \u7684\u6570\u91cf n\uff0c\u8fd4\u56de\u7528\u5217\u8868\uff08\u6700\u5c0f\u53ef\u80fd\u7684\u957f\u5ea6\uff09\u8868\u793a\u7684 CIDR\u5757\u7684\u8303\u56f4\u3002 

    \n\n

    CIDR \u5757\u662f\u5305\u542b IP \u7684\u5b57\u7b26\u4e32\uff0c\u540e\u63a5\u659c\u6760\u548c\u56fa\u5b9a\u957f\u5ea6\u3002\u4f8b\u5982\uff1a“123.45.67.89/20”\u3002\u56fa\u5b9a\u957f\u5ea6 “20” \u8868\u793a\u5728\u7279\u5b9a\u7684\u8303\u56f4\u4e2d\u516c\u5171\u524d\u7f00\u4f4d\u7684\u957f\u5ea6\u3002

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aip = "255.0.0.7", n = 10\n\u8f93\u51fa\uff1a["255.0.0.7/32","255.0.0.8/29","255.0.0.16/32"]\n\u89e3\u91ca\uff1a\n\u8f6c\u6362\u4e3a\u4e8c\u8fdb\u5236\u65f6\uff0c\u521d\u59cbIP\u5730\u5740\u5982\u4e0b\u6240\u793a\uff08\u4e3a\u6e05\u6670\u8d77\u89c1\u6dfb\u52a0\u4e86\u7a7a\u683c\uff09\uff1a\n255.0.0.7 -> 11111111 00000000 00000000 00000111\n\u5730\u5740 "255.0.0.7/32" \u8868\u793a\u4e0e\u7ed9\u5b9a\u5730\u5740\u6709\u76f8\u540c\u7684 32 \u4f4d\u524d\u7f00\u7684\u6240\u6709\u5730\u5740\uff0c\n\u5728\u8fd9\u91cc\u53ea\u6709\u8fd9\u4e00\u4e2a\u5730\u5740\u3002\n\n\u5730\u5740 "255.0.0.8/29" \u8868\u793a\u4e0e\u7ed9\u5b9a\u5730\u5740\u6709\u76f8\u540c\u7684 29 \u4f4d\u524d\u7f00\u7684\u6240\u6709\u5730\u5740\uff1a\n255.0.0.8 -> 11111111 00000000 00000000 00001000\n\u6709\u76f8\u540c\u7684 29 \u4f4d\u524d\u7f00\u7684\u5730\u5740\u5982\u4e0b\uff1a\n11111111 00000000 00000000 00001000\n11111111 00000000 00000000 00001001\n11111111 00000000 00000000 00001010\n11111111 00000000 00000000 00001011\n11111111 00000000 00000000 00001100\n11111111 00000000 00000000 00001101\n11111111 00000000 00000000 00001110\n11111111 00000000 00000000 00001111\n\n\u5730\u5740 "255.0.0.16/32" \u8868\u793a\u4e0e\u7ed9\u5b9a\u5730\u5740\u6709\u76f8\u540c\u7684 32 \u4f4d\u524d\u7f00\u7684\u6240\u6709\u5730\u5740\uff0c\n\u8fd9\u91cc\u53ea\u6709 11111111 00000000 00000000 00010000\u3002\n\n\u603b\u4e4b\uff0c\u7b54\u6848\u6307\u5b9a\u4e86\u4ece 255.0.0.7 \u5f00\u59cb\u7684 10 \u4e2a IP \u7684\u8303\u56f4\u3002\n\n\u6709\u4e00\u4e9b\u5176\u4ed6\u7684\u8868\u793a\u65b9\u6cd5\uff0c\u4f8b\u5982\uff1a\n["255.0.0.7/32","255.0.0.8/30", "255.0.0.12/30", "255.0.0.16/32"],\n\u4f46\u662f\u6211\u4eec\u7684\u7b54\u6848\u662f\u6700\u77ed\u53ef\u80fd\u7684\u7b54\u6848\u3002\n\n\u53e6\u5916\u8bf7\u6ce8\u610f\u4ee5 "255.0.0.7/30" \u5f00\u59cb\u7684\u8868\u793a\u4e0d\u6b63\u786e\uff0c\n\u56e0\u4e3a\u5176\u5305\u62ec\u4e86 255.0.0.4 = 11111111 00000000 00000000 00000100 \u8fd9\u6837\u7684\u5730\u5740\uff0c\n\u8d85\u51fa\u4e86\u9700\u8981\u8868\u793a\u7684\u8303\u56f4\u3002\n
    \n\n

     

    \n\n

    \u6ce8\uff1a

    \n\n
      \n\t
    1. ip \u662f\u6709\u6548\u7684 IPv4 \u5730\u5740\u3002
    2. \n\t
    3. \u6bcf\u4e00\u4e2a\u9690\u542b\u5730\u5740 ip + x (\u5176\u4e2d x < n) \u90fd\u662f\u6709\u6548\u7684 IPv4 \u5730\u5740\u3002
    4. \n\t
    5. n \u4e3a\u6574\u6570\uff0c\u8303\u56f4\u4e3a [1, 1000]\u3002
    6. \n
    \n\n

     

    \n", "tags_en": ["Bit Manipulation"], "tags_cn": ["\u4f4d\u8fd0\u7b97"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector ipToCIDR(string ip, int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List ipToCIDR(String ip, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def ipToCIDR(self, ip, n):\n \"\"\"\n :type ip: str\n :type n: int\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def ipToCIDR(self, ip: str, n: int) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** ipToCIDR(char * ip, int n, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList IpToCIDR(string ip, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} ip\n * @param {number} n\n * @return {string[]}\n */\nvar ipToCIDR = function(ip, n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} ip\n# @param {Integer} n\n# @return {String[]}\ndef ip_to_cidr(ip, n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func ipToCIDR(_ ip: String, _ n: Int) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func ipToCIDR(ip string, n int) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def ipToCIDR(ip: String, n: Int): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun ipToCIDR(ip: String, n: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn ip_to_cidr(ip: String, n: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $ip\n * @param Integer $n\n * @return String[]\n */\n function ipToCIDR($ip, $n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function ipToCIDR(ip: string, n: number): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (ip-to-cidr ip n)\n (-> string? exact-integer? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0751](https://leetcode-cn.com/problems/ip-to-cidr)", "[IP \u5230 CIDR](/solution/0700-0799/0751.IP%20to%20CIDR/README.md)", "`\u4f4d\u8fd0\u7b97`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0751](https://leetcode.com/problems/ip-to-cidr)", "[IP to CIDR](/solution/0700-0799/0751.IP%20to%20CIDR/README_EN.md)", "`Bit Manipulation`", "Medium", "\ud83d\udd12"]}, {"question_id": "0751", "frontend_question_id": "0750", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/number-of-corner-rectangles", "url_en": "https://leetcode.com/problems/number-of-corner-rectangles", "relative_path_cn": "/solution/0700-0799/0750.Number%20Of%20Corner%20Rectangles/README.md", "relative_path_en": "/solution/0700-0799/0750.Number%20Of%20Corner%20Rectangles/README_EN.md", "title_cn": "\u89d2\u77e9\u5f62\u7684\u6570\u91cf", "title_en": "Number Of Corner Rectangles", "question_title_slug": "number-of-corner-rectangles", "content_en": "

    Given a grid where each entry is only 0 or 1, find the number of corner rectangles.

    \r\n\r\n

    A corner rectangle is 4 distinct 1s on the grid that form an axis-aligned rectangle. Note that only the corners need to have the value 1. Also, all four 1s used must be distinct.

    \r\n\r\n

     

    \r\n\r\n

    Example 1:

    \r\n\r\n
    \r\nInput: grid = \r\n[[1, 0, 0, 1, 0],\r\n [0, 0, 1, 0, 1],\r\n [0, 0, 0, 1, 0],\r\n [1, 0, 1, 0, 1]]\r\nOutput: 1\r\nExplanation: There is only one corner rectangle, with corners grid[1][2], grid[1][4], grid[3][2], grid[3][4].\r\n
    \r\n\r\n

     

    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: grid = \r\n[[1, 1, 1],\r\n [1, 1, 1],\r\n [1, 1, 1]]\r\nOutput: 9\r\nExplanation: There are four 2x2 rectangles, four 2x3 and 3x2 rectangles, and one 3x3 rectangle.\r\n
    \r\n\r\n

     

    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: grid = \r\n[[1, 1, 1, 1]]\r\nOutput: 0\r\nExplanation: Rectangles must have four distinct corners.\r\n
    \r\n\r\n

     

    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    1. The number of rows and columns of grid will each be in the range [1, 200].
    2. \r\n\t
    3. Each grid[i][j] will be either 0 or 1.
    4. \r\n\t
    5. The number of 1s in the grid will be at most 6000.
    6. \r\n
    \r\n\r\n

     

    \r\n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u53ea\u5305\u542b 0 \u548c 1 \u7684\u7f51\u683c\uff0c\u627e\u51fa\u5176\u4e2d\u89d2\u77e9\u5f62\u7684\u6570\u91cf\u3002

    \n\n

    \u4e00\u4e2a\u300c\u89d2\u77e9\u5f62\u300d\u662f\u7531\u56db\u4e2a\u4e0d\u540c\u7684\u5728\u7f51\u683c\u4e0a\u7684 1 \u5f62\u6210\u7684\u8f74\u5bf9\u79f0\u7684\u77e9\u5f62\u3002\u6ce8\u610f\u53ea\u6709\u89d2\u7684\u4f4d\u7f6e\u624d\u9700\u8981\u4e3a 1\u3002\u5e76\u4e14\uff0c4 \u4e2a 1 \u9700\u8981\u662f\u4e0d\u540c\u7684\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1agrid = \n[[1, 0, 0, 1, 0],\n [0, 0, 1, 0, 1],\n [0, 0, 0, 1, 0],\n [1, 0, 1, 0, 1]]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u53ea\u6709\u4e00\u4e2a\u89d2\u77e9\u5f62\uff0c\u89d2\u7684\u4f4d\u7f6e\u4e3a grid[1][2], grid[1][4], grid[3][2], grid[3][4]\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1agrid = \n[[1, 1, 1],\n [1, 1, 1],\n [1, 1, 1]]\n\u8f93\u51fa\uff1a9\n\u89e3\u91ca\uff1a\u8fd9\u91cc\u6709 4 \u4e2a 2x2 \u7684\u77e9\u5f62\uff0c4 \u4e2a 2x3 \u548c 3x2 \u7684\u77e9\u5f62\u548c 1 \u4e2a 3x3 \u7684\u77e9\u5f62\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1agrid = \n[[1, 1, 1, 1]]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u77e9\u5f62\u5fc5\u987b\u6709 4 \u4e2a\u4e0d\u540c\u7684\u89d2\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. \u7f51\u683c grid \u4e2d\u884c\u548c\u5217\u7684\u6570\u76ee\u8303\u56f4\u4e3a [1, 200]\u3002
    2. \n\t
    3. \u6bcf\u4e2a\u7f51\u683c grid[i][j] \u4e2d\u7684\u503c\u4e0d\u662f 0 \u5c31\u662f 1 \u3002
    4. \n\t
    5. \u7f51\u683c\u4e2d 1 \u7684\u4e2a\u6570\u4e0d\u4f1a\u8d85\u8fc7 6000\u3002
    6. \n
    \n\n

     

    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countCornerRectangles(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countCornerRectangles(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countCornerRectangles(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countCornerRectangles(self, grid: List[List[int]]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countCornerRectangles(int** grid, int gridSize, int* gridColSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountCornerRectangles(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar countCornerRectangles = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef count_corner_rectangles(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countCornerRectangles(_ grid: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countCornerRectangles(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countCornerRectangles(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countCornerRectangles(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_corner_rectangles(grid: Vec>) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function countCornerRectangles($grid) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countCornerRectangles(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-corner-rectangles grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0750](https://leetcode-cn.com/problems/number-of-corner-rectangles)", "[\u89d2\u77e9\u5f62\u7684\u6570\u91cf](/solution/0700-0799/0750.Number%20Of%20Corner%20Rectangles/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0750](https://leetcode.com/problems/number-of-corner-rectangles)", "[Number Of Corner Rectangles](/solution/0700-0799/0750.Number%20Of%20Corner%20Rectangles/README_EN.md)", "`Dynamic Programming`", "Medium", "\ud83d\udd12"]}, {"question_id": "0750", "frontend_question_id": "0749", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/contain-virus", "url_en": "https://leetcode.com/problems/contain-virus", "relative_path_cn": "/solution/0700-0799/0749.Contain%20Virus/README.md", "relative_path_en": "/solution/0700-0799/0749.Contain%20Virus/README_EN.md", "title_cn": "\u9694\u79bb\u75c5\u6bd2", "title_en": "Contain Virus", "question_title_slug": "contain-virus", "content_en": "

    A virus is spreading rapidly, and your task is to quarantine the infected area by installing walls.

    \n\n

    The world is modeled as an m x n binary grid isInfected, where isInfected[i][j] == 0 represents uninfected cells, and isInfected[i][j] == 1 represents cells contaminated with the virus. A wall (and only one wall) can be installed between any two 4-directionally adjacent cells, on the shared boundary.

    \n\n

    Every night, the virus spreads to all neighboring cells in all four directions unless blocked by a wall. Resources are limited. Each day, you can install walls around only one region (i.e., the affected area (continuous block of infected cells) that threatens the most uninfected cells the following night). There will never be a tie.

    \n\n

    Return the number of walls used to quarantine all the infected regions. If the world will become fully infected, return the number of walls used.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: isInfected = [[0,1,0,0,0,0,0,1],[0,1,0,0,0,0,0,1],[0,0,0,0,0,0,0,1],[0,0,0,0,0,0,0,0]]\nOutput: 10\nExplanation: There are 2 contaminated regions.\nOn the first day, add 5 walls to quarantine the viral region on the left. The board after the virus spreads is:\n\"\"\nOn the second day, add 5 walls to quarantine the viral region on the right. The virus is fully contained.\n\"\"\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: isInfected = [[1,1,1],[1,0,1],[1,1,1]]\nOutput: 4\nExplanation: Even though there is only one cell saved, there are 4 walls built.\nNotice that walls are only built on the shared boundary of two different cells.\n
    \n\n

    Example 3:

    \n\n
    \nInput: isInfected = [[1,1,1,0,0,0,0,0,0],[1,0,1,0,1,1,1,1,1],[1,1,1,0,0,0,0,0,0]]\nOutput: 13\nExplanation: The region on the left only builds two new walls.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == isInfected.length
    • \n\t
    • n == isInfected[i].length
    • \n\t
    • 1 <= m, n <= 50
    • \n\t
    • isInfected[i][j] is either 0 or 1.
    • \n\t
    • There is always a contiguous viral region throughout the described process that will infect strictly more uncontaminated squares in the next round.
    • \n
    \n", "content_cn": "

    \u75c5\u6bd2\u6269\u6563\u5f97\u5f88\u5feb\uff0c\u73b0\u5728\u4f60\u7684\u4efb\u52a1\u662f\u5c3d\u53ef\u80fd\u5730\u901a\u8fc7\u5b89\u88c5\u9632\u706b\u5899\u6765\u9694\u79bb\u75c5\u6bd2\u3002

    \n\n

    \u5047\u8bbe\u4e16\u754c\u7531\u4e8c\u7ef4\u77e9\u9635\u7ec4\u6210\uff0c0 \u8868\u793a\u8be5\u533a\u57df\u672a\u611f\u67d3\u75c5\u6bd2\uff0c\u800c 1 \u8868\u793a\u8be5\u533a\u57df\u5df2\u611f\u67d3\u75c5\u6bd2\u3002\u53ef\u4ee5\u5728\u4efb\u610f 2 \u4e2a\u56db\u65b9\u5411\u76f8\u90bb\u5355\u5143\u4e4b\u95f4\u7684\u5171\u4eab\u8fb9\u754c\u4e0a\u5b89\u88c5\u4e00\u4e2a\u9632\u706b\u5899\uff08\u5e76\u4e14\u53ea\u6709\u4e00\u4e2a\u9632\u706b\u5899\uff09\u3002

    \n\n

    \u6bcf\u5929\u665a\u4e0a\uff0c\u75c5\u6bd2\u4f1a\u4ece\u88ab\u611f\u67d3\u533a\u57df\u5411\u76f8\u90bb\u672a\u611f\u67d3\u533a\u57df\u6269\u6563\uff0c\u9664\u975e\u88ab\u9632\u706b\u5899\u9694\u79bb\u3002\u73b0\u7531\u4e8e\u8d44\u6e90\u6709\u9650\uff0c\u6bcf\u5929\u4f60\u53ea\u80fd\u5b89\u88c5\u4e00\u7cfb\u5217\u9632\u706b\u5899\u6765\u9694\u79bb\u5176\u4e2d\u4e00\u4e2a\u88ab\u75c5\u6bd2\u611f\u67d3\u7684\u533a\u57df\uff08\u4e00\u4e2a\u533a\u57df\u6216\u8fde\u7eed\u7684\u4e00\u7247\u533a\u57df\uff09\uff0c\u4e14\u8be5\u611f\u67d3\u533a\u57df\u5bf9\u672a\u611f\u67d3\u533a\u57df\u7684\u5a01\u80c1\u6700\u5927\u4e14\u4fdd\u8bc1\u552f\u4e00\u3002

    \n\n

    \u4f60\u9700\u8981\u52aa\u529b\u4f7f\u5f97\u6700\u540e\u6709\u90e8\u5206\u533a\u57df\u4e0d\u88ab\u75c5\u6bd2\u611f\u67d3\uff0c\u5982\u679c\u53ef\u4ee5\u6210\u529f\uff0c\u90a3\u4e48\u8fd4\u56de\u9700\u8981\u4f7f\u7528\u7684\u9632\u706b\u5899\u4e2a\u6570; \u5982\u679c\u65e0\u6cd5\u5b9e\u73b0\uff0c\u5219\u8fd4\u56de\u5728\u4e16\u754c\u88ab\u75c5\u6bd2\u5168\u90e8\u611f\u67d3\u65f6\u5df2\u5b89\u88c5\u7684\u9632\u706b\u5899\u4e2a\u6570\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165: grid = \n[[0,1,0,0,0,0,0,1],\n [0,1,0,0,0,0,0,1],\n [0,0,0,0,0,0,0,1],\n [0,0,0,0,0,0,0,0]]\n\u8f93\u51fa: 10\n\u8bf4\u660e:\n\u4e00\u5171\u6709\u4e24\u5757\u88ab\u75c5\u6bd2\u611f\u67d3\u7684\u533a\u57df: \u4ece\u5de6\u5f80\u53f3\u7b2c\u4e00\u5757\u9700\u8981 5 \u4e2a\u9632\u706b\u5899\uff0c\u540c\u65f6\u82e5\u8be5\u533a\u57df\u4e0d\u9694\u79bb\uff0c\u665a\u4e0a\u5c06\u611f\u67d3 5 \u4e2a\u672a\u611f\u67d3\u533a\u57df\uff08\u5373\u88ab\u5a01\u80c1\u7684\u672a\u611f\u67d3\u533a\u57df\u4e2a\u6570\u4e3a 5\uff09;\n\u7b2c\u4e8c\u5757\u9700\u8981 4 \u4e2a\u9632\u706b\u5899\uff0c\u540c\u7406\u88ab\u5a01\u80c1\u7684\u672a\u611f\u67d3\u533a\u57df\u4e2a\u6570\u662f 4\u3002\u56e0\u6b64\uff0c\u7b2c\u4e00\u5929\u5148\u9694\u79bb\u5de6\u8fb9\u7684\u611f\u67d3\u533a\u57df\uff0c\u7ecf\u8fc7\u4e00\u665a\u540e\uff0c\u75c5\u6bd2\u4f20\u64ad\u540e\u4e16\u754c\u5982\u4e0b:\n[[0,1,0,0,0,0,1,1],\n [0,1,0,0,0,0,1,1],\n [0,0,0,0,0,0,1,1],\n [0,0,0,0,0,0,0,1]]\n\u7b2c\u4e8c\u9898\uff0c\u53ea\u5269\u4e0b\u4e00\u5757\u672a\u9694\u79bb\u7684\u88ab\u611f\u67d3\u7684\u8fde\u7eed\u533a\u57df\uff0c\u6b64\u65f6\u9700\u8981\u5b89\u88c5 5 \u4e2a\u9632\u706b\u5899\uff0c\u4e14\u5b89\u88c5\u5b8c\u6bd5\u540e\u75c5\u6bd2\u9694\u79bb\u4efb\u52a1\u5b8c\u6210\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165: grid = \n[[1,1,1],\n [1,0,1],\n [1,1,1]]\n\u8f93\u51fa: 4\n\u8bf4\u660e: \n\u6b64\u65f6\u53ea\u9700\u8981\u5b89\u88c5 4 \u9762\u9632\u706b\u5899\uff0c\u5c31\u6709\u4e00\u5c0f\u533a\u57df\u53ef\u4ee5\u5e78\u5b58\uff0c\u4e0d\u88ab\u75c5\u6bd2\u611f\u67d3\u3002\n\u6ce8\u610f\u4e0d\u9700\u8981\u5728\u4e16\u754c\u8fb9\u754c\u5efa\u7acb\u9632\u706b\u5899\u3002
    \n\n

     

    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u8f93\u5165: grid = \n[[1,1,1,0,0,0,0,0,0],\n [1,0,1,0,1,1,1,1,1],\n [1,1,1,0,0,0,0,0,0]]\n\u8f93\u51fa: 13\n\u8bf4\u660e: \n\u5728\u9694\u79bb\u53f3\u8fb9\u611f\u67d3\u533a\u57df\u540e\uff0c\u9694\u79bb\u5de6\u8fb9\u75c5\u6bd2\u533a\u57df\u53ea\u9700\u8981 2 \u4e2a\u9632\u706b\u5899\u4e86\u3002\n
    \n\n

     

    \n\n

    \u8bf4\u660e:

    \n\n
      \n\t
    1. grid \u7684\u884c\u6570\u548c\u5217\u6570\u8303\u56f4\u662f [1, 50]\u3002
    2. \n\t
    3.  grid[i][j] \u53ea\u5305\u542b 0 \u6216 1 \u3002
    4. \n\t
    5. \u9898\u76ee\u4fdd\u8bc1\u6bcf\u6b21\u9009\u53d6\u611f\u67d3\u533a\u57df\u8fdb\u884c\u9694\u79bb\u65f6\uff0c\u4e00\u5b9a\u5b58\u5728\u552f\u4e00\u4e00\u4e2a\u5bf9\u672a\u611f\u67d3\u533a\u57df\u7684\u5a01\u80c1\u6700\u5927\u7684\u533a\u57df\u3002
    6. \n
    \n\n

     

    \n", "tags_en": ["Depth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int containVirus(vector>& isInfected) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int containVirus(int[][] isInfected) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def containVirus(self, isInfected):\n \"\"\"\n :type isInfected: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def containVirus(self, isInfected: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint containVirus(int** isInfected, int isInfectedSize, int* isInfectedColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ContainVirus(int[][] isInfected) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} isInfected\n * @return {number}\n */\nvar containVirus = function(isInfected) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} is_infected\n# @return {Integer}\ndef contain_virus(is_infected)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func containVirus(_ isInfected: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func containVirus(isInfected [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def containVirus(isInfected: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun containVirus(isInfected: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn contain_virus(is_infected: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $isInfected\n * @return Integer\n */\n function containVirus($isInfected) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function containVirus(isInfected: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (contain-virus isInfected)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0749](https://leetcode-cn.com/problems/contain-virus)", "[\u9694\u79bb\u75c5\u6bd2](/solution/0700-0799/0749.Contain%20Virus/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[0749](https://leetcode.com/problems/contain-virus)", "[Contain Virus](/solution/0700-0799/0749.Contain%20Virus/README_EN.md)", "`Depth-first Search`", "Hard", ""]}, {"question_id": "0749", "frontend_question_id": "0748", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/shortest-completing-word", "url_en": "https://leetcode.com/problems/shortest-completing-word", "relative_path_cn": "/solution/0700-0799/0748.Shortest%20Completing%20Word/README.md", "relative_path_en": "/solution/0700-0799/0748.Shortest%20Completing%20Word/README_EN.md", "title_cn": "\u6700\u77ed\u8865\u5168\u8bcd", "title_en": "Shortest Completing Word", "question_title_slug": "shortest-completing-word", "content_en": "

    Given a string licensePlate and an array of strings words, find the shortest completing word in words.

    \n\n

    A completing word is a word that contains all the letters in licensePlate. Ignore numbers and spaces in licensePlate, and treat letters as case insensitive. If a letter appears more than once in licensePlate, then it must appear in the word the same number of times or more.

    \n\n

    For example, if licensePlate = "aBc 12c", then it contains letters 'a', 'b' (ignoring case), and 'c' twice. Possible completing words are "abccdef", "caaacab", and "cbca".

    \n\n

    Return the shortest completing word in words. It is guaranteed an answer exists. If there are multiple shortest completing words, return the first one that occurs in words.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: licensePlate = "1s3 PSt", words = ["step","steps","stripe","stepple"]\nOutput: "steps"\nExplanation: licensePlate contains letters 's', 'p', 's' (ignoring case), and 't'.\n"step" contains 't' and 'p', but only contains 1 's'.\n"steps" contains 't', 'p', and both 's' characters.\n"stripe" is missing an 's'.\n"stepple" is missing an 's'.\nSince "steps" is the only word containing all the letters, that is the answer.\n
    \n\n

    Example 2:

    \n\n
    \nInput: licensePlate = "1s3 456", words = ["looks","pest","stew","show"]\nOutput: "pest"\nExplanation: licensePlate only contains the letter 's'. All the words contain 's', but among these "pest", "stew", and "show" are shortest. The answer is "pest" because it is the word that appears earliest of the 3.\n
    \n\n

    Example 3:

    \n\n
    \nInput: licensePlate = "Ah71752", words = ["suggest","letter","of","husband","easy","education","drug","prevent","writer","old"]\nOutput: "husband"\n
    \n\n

    Example 4:

    \n\n
    \nInput: licensePlate = "OgEu755", words = ["enough","these","play","wide","wonder","box","arrive","money","tax","thus"]\nOutput: "enough"\n
    \n\n

    Example 5:

    \n\n
    \nInput: licensePlate = "iMSlpe4", words = ["claim","consumer","student","camera","public","never","wonder","simple","thought","use"]\nOutput: "simple"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= licensePlate.length <= 7
    • \n\t
    • licensePlate contains digits, letters (uppercase or lowercase), or space ' '.
    • \n\t
    • 1 <= words.length <= 1000
    • \n\t
    • 1 <= words[i].length <= 15
    • \n\t
    • words[i] consists of lower case English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\u724c\u7167 licensePlate \u548c\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4 words \uff0c\u8bf7\u4f60\u627e\u51fa\u5e76\u8fd4\u56de words \u4e2d\u7684 \u6700\u77ed\u8865\u5168\u8bcd \u3002

    \n\n

    \u5982\u679c\u5355\u8bcd\u5217\u8868\uff08words\uff09\u4e2d\u7684\u4e00\u4e2a\u5355\u8bcd\u5305\u542b\u724c\u7167\uff08licensePlate\uff09\u4e2d\u6240\u6709\u7684\u5b57\u6bcd\uff0c\u90a3\u4e48\u6211\u4eec\u79f0\u4e4b\u4e3a \u8865\u5168\u8bcd \u3002\u5728\u6240\u6709\u5b8c\u6574\u8bcd\u4e2d\uff0c\u6700\u77ed\u7684\u5355\u8bcd\u6211\u4eec\u79f0\u4e4b\u4e3a \u6700\u77ed\u8865\u5168\u8bcd \u3002

    \n\n

    \u5355\u8bcd\u5728\u5339\u914d\u724c\u7167\u4e2d\u7684\u5b57\u6bcd\u65f6\u8981\uff1a

    \n\n
      \n\t
    • \u5ffd\u7565\u724c\u7167\u4e2d\u7684\u6570\u5b57\u548c\u7a7a\u683c\u3002
    • \n\t
    • \u4e0d\u533a\u5206\u5927\u5c0f\u5199\uff0c\u6bd4\u5982\u724c\u7167\u4e2d\u7684 "P" \u4f9d\u7136\u53ef\u4ee5\u5339\u914d\u5355\u8bcd\u4e2d\u7684 "p" \u5b57\u6bcd\u3002
    • \n\t
    • \u5982\u679c\u67d0\u4e2a\u5b57\u6bcd\u5728\u724c\u7167\u4e2d\u51fa\u73b0\u4e0d\u6b62\u4e00\u6b21\uff0c\u90a3\u4e48\u8be5\u5b57\u6bcd\u5728\u8865\u5168\u8bcd\u4e2d\u7684\u51fa\u73b0\u6b21\u6570\u5e94\u5f53\u4e00\u81f4\u6216\u8005\u66f4\u591a\u3002
    • \n
    \n\n

    \u4f8b\u5982\uff1alicensePlate = "aBc 12c"\uff0c\u90a3\u4e48\u5b83\u7531\u5b57\u6bcd 'a'\u3001'b' \uff08\u5ffd\u7565\u5927\u5199\uff09\u548c\u4e24\u4e2a 'c' \u3002\u53ef\u80fd\u7684 \u8865\u5168\u8bcd \u662f "abccdef"\u3001"caaacab" \u4ee5\u53ca "cbca" \u3002

    \n\n

    \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u4e00\u5b9a\u5b58\u5728\u4e00\u4e2a\u6700\u77ed\u8865\u5168\u8bcd\u3002\u5f53\u6709\u591a\u4e2a\u5355\u8bcd\u90fd\u7b26\u5408\u6700\u77ed\u8865\u5168\u8bcd\u7684\u5339\u914d\u6761\u4ef6\u65f6\u53d6\u5355\u8bcd\u5217\u8868\u4e2d\u6700\u9760\u524d\u7684\u4e00\u4e2a\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1alicensePlate = "1s3 PSt", words = ["step", "steps", "stripe", "stepple"]\n\u8f93\u51fa\uff1a"steps"\n\u8bf4\u660e\uff1a\u6700\u77ed\u8865\u5168\u8bcd\u5e94\u8be5\u5305\u62ec "s"\u3001"p"\u3001"s" \u4ee5\u53ca "t"\u3002\u5728\u5339\u914d\u8fc7\u7a0b\u4e2d\u6211\u4eec\u5ffd\u7565\u724c\u7167\u4e2d\u7684\u5927\u5c0f\u5199\u3002\n"step" \u5305\u542b "t"\u3001"p"\uff0c\u4f46\u53ea\u5305\u542b\u4e00\u4e2a "s"\uff0c\u6240\u4ee5\u5b83\u4e0d\u7b26\u5408\u6761\u4ef6\u3002\n"steps" \u5305\u542b "t"\u3001"p" \u548c\u4e24\u4e2a "s"\u3002\n"stripe" \u7f3a\u4e00\u4e2a "s"\u3002\n"stepple" \u7f3a\u4e00\u4e2a "s"\u3002\n\u56e0\u6b64\uff0c"steps" \u662f\u552f\u4e00\u4e00\u4e2a\u5305\u542b\u6240\u6709\u5b57\u6bcd\u7684\u5355\u8bcd\uff0c\u4e5f\u662f\u672c\u6837\u4f8b\u7684\u7b54\u6848\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1alicensePlate = "1s3 456", words = ["looks", "pest", "stew", "show"]\n\u8f93\u51fa\uff1a"pest"\n\u8bf4\u660e\uff1a\u5b58\u5728 3 \u4e2a\u5305\u542b\u5b57\u6bcd "s" \u4e14\u6709\u7740\u6700\u77ed\u957f\u5ea6\u7684\u8865\u5168\u8bcd\uff0c"pest"\u3001"stew"\u3001\u548c "show" \u4e09\u8005\u957f\u5ea6\u76f8\u540c\uff0c\u4f46\u6211\u4eec\u8fd4\u56de\u6700\u5148\u51fa\u73b0\u7684\u8865\u5168\u8bcd "pest" \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1alicensePlate = "Ah71752", words = ["suggest","letter","of","husband","easy","education","drug","prevent","writer","old"]\n\u8f93\u51fa\uff1a"husband"\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1alicensePlate = "OgEu755", words = ["enough","these","play","wide","wonder","box","arrive","money","tax","thus"]\n\u8f93\u51fa\uff1a"enough"\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1alicensePlate = "iMSlpe4", words = ["claim","consumer","student","camera","public","never","wonder","simple","thought","use"]\n\u8f93\u51fa\uff1a"simple"\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= licensePlate.length <= 7
    • \n\t
    • licensePlate \u7531\u6570\u5b57\u3001\u5927\u5c0f\u5199\u5b57\u6bcd\u6216\u7a7a\u683c ' ' \u7ec4\u6210
    • \n\t
    • 1 <= words.length <= 1000
    • \n\t
    • 1 <= words[i].length <= 15
    • \n\t
    • words[i] \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string shortestCompletingWord(string licensePlate, vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String shortestCompletingWord(String licensePlate, String[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def shortestCompletingWord(self, licensePlate, words):\n \"\"\"\n :type licensePlate: str\n :type words: List[str]\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def shortestCompletingWord(self, licensePlate: str, words: List[str]) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * shortestCompletingWord(char * licensePlate, char ** words, int wordsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ShortestCompletingWord(string licensePlate, string[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} licensePlate\n * @param {string[]} words\n * @return {string}\n */\nvar shortestCompletingWord = function(licensePlate, words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} license_plate\n# @param {String[]} words\n# @return {String}\ndef shortest_completing_word(license_plate, words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func shortestCompletingWord(_ licensePlate: String, _ words: [String]) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func shortestCompletingWord(licensePlate string, words []string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def shortestCompletingWord(licensePlate: String, words: Array[String]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun shortestCompletingWord(licensePlate: String, words: Array): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn shortest_completing_word(license_plate: String, words: Vec) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $licensePlate\n * @param String[] $words\n * @return String\n */\n function shortestCompletingWord($licensePlate, $words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function shortestCompletingWord(licensePlate: string, words: string[]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (shortest-completing-word licensePlate words)\n (-> string? (listof string?) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0748](https://leetcode-cn.com/problems/shortest-completing-word)", "[\u6700\u77ed\u8865\u5168\u8bcd](/solution/0700-0799/0748.Shortest%20Completing%20Word/README.md)", "`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0748](https://leetcode.com/problems/shortest-completing-word)", "[Shortest Completing Word](/solution/0700-0799/0748.Shortest%20Completing%20Word/README_EN.md)", "`Hash Table`", "Easy", ""]}, {"question_id": "0748", "frontend_question_id": "0747", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/largest-number-at-least-twice-of-others", "url_en": "https://leetcode.com/problems/largest-number-at-least-twice-of-others", "relative_path_cn": "/solution/0700-0799/0747.Largest%20Number%20At%20Least%20Twice%20of%20Others/README.md", "relative_path_en": "/solution/0700-0799/0747.Largest%20Number%20At%20Least%20Twice%20of%20Others/README_EN.md", "title_cn": "\u81f3\u5c11\u662f\u5176\u4ed6\u6570\u5b57\u4e24\u500d\u7684\u6700\u5927\u6570", "title_en": "Largest Number At Least Twice of Others", "question_title_slug": "largest-number-at-least-twice-of-others", "content_en": "

    You are given an integer array nums where the largest integer is unique.

    \n\n

    Determine whether the largest element in the array is at least twice as much as every other number in the array. If it is, return the index of the largest element, or return -1 otherwise.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [3,6,1,0]\nOutput: 1\nExplanation: 6 is the largest integer.\nFor every other number in the array x, 6 is at least twice as big as x.\nThe index of value 6 is 1, so we return 1.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,2,3,4]\nOutput: -1\nExplanation: 4 is less than twice the value of 3, so we return -1.
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [1]\nOutput: 0\nExplanation: 1 is trivially at least twice the value as any other number because there are no other numbers.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 50
    • \n\t
    • 0 <= nums[i] <= 100
    • \n\t
    • The largest element in nums is unique.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \uff0c\u5176\u4e2d\u603b\u662f\u5b58\u5728 \u552f\u4e00\u7684 \u4e00\u4e2a\u6700\u5927\u6574\u6570 \u3002

    \n\n

    \u8bf7\u4f60\u627e\u51fa\u6570\u7ec4\u4e2d\u7684\u6700\u5927\u5143\u7d20\u5e76\u68c0\u67e5\u5b83\u662f\u5426 \u81f3\u5c11\u662f\u6570\u7ec4\u4e2d\u6bcf\u4e2a\u5176\u4ed6\u6570\u5b57\u7684\u4e24\u500d \u3002\u5982\u679c\u662f\uff0c\u5219\u8fd4\u56de \u6700\u5927\u5143\u7d20\u7684\u4e0b\u6807 \uff0c\u5426\u5219\u8fd4\u56de -1 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [3,6,1,0]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a6 \u662f\u6700\u5927\u7684\u6574\u6570\uff0c\u5bf9\u4e8e\u6570\u7ec4\u4e2d\u7684\u5176\u4ed6\u6574\u6570\uff0c6 \u5927\u4e8e\u6570\u7ec4\u4e2d\u5176\u4ed6\u5143\u7d20\u7684\u4e24\u500d\u30026 \u7684\u4e0b\u6807\u662f 1 \uff0c\u6240\u4ee5\u8fd4\u56de 1 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,3,4]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a4 \u6ca1\u6709\u8d85\u8fc7 3 \u7684\u4e24\u500d\u5927\uff0c\u6240\u4ee5\u8fd4\u56de -1 \u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u56e0\u4e3a\u4e0d\u5b58\u5728\u5176\u4ed6\u6570\u5b57\uff0c\u6240\u4ee5\u8ba4\u4e3a\u73b0\u6709\u6570\u5b57 1 \u81f3\u5c11\u662f\u5176\u4ed6\u6570\u5b57\u7684\u4e24\u500d\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 50
    • \n\t
    • 0 <= nums[i] <= 100
    • \n\t
    • nums \u4e2d\u7684\u6700\u5927\u5143\u7d20\u662f\u552f\u4e00\u7684
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int dominantIndex(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int dominantIndex(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def dominantIndex(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def dominantIndex(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint dominantIndex(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int DominantIndex(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar dominantIndex = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef dominant_index(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func dominantIndex(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func dominantIndex(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def dominantIndex(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun dominantIndex(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn dominant_index(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function dominantIndex($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function dominantIndex(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (dominant-index nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0747](https://leetcode-cn.com/problems/largest-number-at-least-twice-of-others)", "[\u81f3\u5c11\u662f\u5176\u4ed6\u6570\u5b57\u4e24\u500d\u7684\u6700\u5927\u6570](/solution/0700-0799/0747.Largest%20Number%20At%20Least%20Twice%20of%20Others/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0747](https://leetcode.com/problems/largest-number-at-least-twice-of-others)", "[Largest Number At Least Twice of Others](/solution/0700-0799/0747.Largest%20Number%20At%20Least%20Twice%20of%20Others/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0747", "frontend_question_id": "0746", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/min-cost-climbing-stairs", "url_en": "https://leetcode.com/problems/min-cost-climbing-stairs", "relative_path_cn": "/solution/0700-0799/0746.Min%20Cost%20Climbing%20Stairs/README.md", "relative_path_en": "/solution/0700-0799/0746.Min%20Cost%20Climbing%20Stairs/README_EN.md", "title_cn": "\u4f7f\u7528\u6700\u5c0f\u82b1\u8d39\u722c\u697c\u68af", "title_en": "Min Cost Climbing Stairs", "question_title_slug": "min-cost-climbing-stairs", "content_en": "

    You are given an integer array cost where cost[i] is the cost of ith step on a staircase. Once you pay the cost, you can either climb one or two steps.

    \n\n

    You can either start from the step with index 0, or the step with index 1.

    \n\n

    Return the minimum cost to reach the top of the floor.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: cost = [10,15,20]\nOutput: 15\nExplanation: Cheapest is: start on cost[1], pay that cost, and go to the top.\n
    \n\n

    Example 2:

    \n\n
    \nInput: cost = [1,100,1,1,1,100,1,1,100,1]\nOutput: 6\nExplanation: Cheapest is: start on cost[0], and only step on 1s, skipping cost[3].\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= cost.length <= 1000
    • \n\t
    • 0 <= cost[i] <= 999
    • \n
    \n", "content_cn": "

    \u6570\u7ec4\u7684\u6bcf\u4e2a\u4e0b\u6807\u4f5c\u4e3a\u4e00\u4e2a\u9636\u68af\uff0c\u7b2c i \u4e2a\u9636\u68af\u5bf9\u5e94\u7740\u4e00\u4e2a\u975e\u8d1f\u6570\u7684\u4f53\u529b\u82b1\u8d39\u503c\u00a0cost[i]\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\u3002

    \n\n

    \u6bcf\u5f53\u4f60\u722c\u4e0a\u4e00\u4e2a\u9636\u68af\u4f60\u90fd\u8981\u82b1\u8d39\u5bf9\u5e94\u7684\u4f53\u529b\u503c\uff0c\u4e00\u65e6\u652f\u4ed8\u4e86\u76f8\u5e94\u7684\u4f53\u529b\u503c\uff0c\u4f60\u5c31\u53ef\u4ee5\u9009\u62e9\u5411\u4e0a\u722c\u4e00\u4e2a\u9636\u68af\u6216\u8005\u722c\u4e24\u4e2a\u9636\u68af\u3002

    \n\n

    \u8bf7\u4f60\u627e\u51fa\u8fbe\u5230\u697c\u5c42\u9876\u90e8\u7684\u6700\u4f4e\u82b1\u8d39\u3002\u5728\u5f00\u59cb\u65f6\uff0c\u4f60\u53ef\u4ee5\u9009\u62e9\u4ece\u4e0b\u6807\u4e3a 0 \u6216 1 \u7684\u5143\u7d20\u4f5c\u4e3a\u521d\u59cb\u9636\u68af\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\u00a01\uff1a

    \n\n
    \n\u8f93\u5165\uff1acost = [10, 15, 20]\n\u8f93\u51fa\uff1a15\n\u89e3\u91ca\uff1a\u6700\u4f4e\u82b1\u8d39\u662f\u4ece cost[1] \u5f00\u59cb\uff0c\u7136\u540e\u8d70\u4e24\u6b65\u5373\u53ef\u5230\u9636\u68af\u9876\uff0c\u4e00\u5171\u82b1\u8d39 15 \u3002\n
    \n\n

    \u00a0\u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1acost = [1, 100, 1, 1, 1, 100, 1, 1, 100, 1]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u6700\u4f4e\u82b1\u8d39\u65b9\u5f0f\u662f\u4ece cost[0] \u5f00\u59cb\uff0c\u9010\u4e2a\u7ecf\u8fc7\u90a3\u4e9b 1 \uff0c\u8df3\u8fc7 cost[3] \uff0c\u4e00\u5171\u82b1\u8d39 6 \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • cost\u00a0\u7684\u957f\u5ea6\u8303\u56f4\u662f [2, 1000]\u3002
    • \n\t
    • cost[i] \u5c06\u4f1a\u662f\u4e00\u4e2a\u6574\u578b\u6570\u636e\uff0c\u8303\u56f4\u4e3a\u00a0[0, 999] \u3002
    • \n
    \n", "tags_en": ["Array", "Dynamic Programming"], "tags_cn": ["\u6570\u7ec4", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minCostClimbingStairs(vector& cost) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minCostClimbingStairs(int[] cost) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minCostClimbingStairs(self, cost):\n \"\"\"\n :type cost: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minCostClimbingStairs(self, cost: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minCostClimbingStairs(int* cost, int costSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinCostClimbingStairs(int[] cost) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} cost\n * @return {number}\n */\nvar minCostClimbingStairs = function(cost) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} cost\n# @return {Integer}\ndef min_cost_climbing_stairs(cost)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minCostClimbingStairs(_ cost: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minCostClimbingStairs(cost []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minCostClimbingStairs(cost: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minCostClimbingStairs(cost: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_cost_climbing_stairs(cost: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $cost\n * @return Integer\n */\n function minCostClimbingStairs($cost) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minCostClimbingStairs(cost: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-cost-climbing-stairs cost)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0746](https://leetcode-cn.com/problems/min-cost-climbing-stairs)", "[\u4f7f\u7528\u6700\u5c0f\u82b1\u8d39\u722c\u697c\u68af](/solution/0700-0799/0746.Min%20Cost%20Climbing%20Stairs/README.md)", "`\u6570\u7ec4`,`\u52a8\u6001\u89c4\u5212`", "\u7b80\u5355", ""], "md_table_row_en": ["[0746](https://leetcode.com/problems/min-cost-climbing-stairs)", "[Min Cost Climbing Stairs](/solution/0700-0799/0746.Min%20Cost%20Climbing%20Stairs/README_EN.md)", "`Array`,`Dynamic Programming`", "Easy", ""]}, {"question_id": "0746", "frontend_question_id": "0745", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/prefix-and-suffix-search", "url_en": "https://leetcode.com/problems/prefix-and-suffix-search", "relative_path_cn": "/solution/0700-0799/0745.Prefix%20and%20Suffix%20Search/README.md", "relative_path_en": "/solution/0700-0799/0745.Prefix%20and%20Suffix%20Search/README_EN.md", "title_cn": "\u524d\u7f00\u548c\u540e\u7f00\u641c\u7d22", "title_en": "Prefix and Suffix Search", "question_title_slug": "prefix-and-suffix-search", "content_en": "

    Design a special dictionary with some words that searchs the words in it by a prefix and a suffix.

    \n\n

    Implement the WordFilter class:

    \n\n
      \n\t
    • WordFilter(string[] words) Initializes the object with the words in the dictionary.
    • \n\t
    • f(string prefix, string suffix) Returns the index of the word in the dictionary, which has the prefix prefix and the suffix suffix. If there is more than one valid index, return the largest of them. If there is no such word in the dictionary, return -1.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["WordFilter", "f"]\n[[["apple"]], ["a", "e"]]\nOutput\n[null, 0]\n\nExplanation\nWordFilter wordFilter = new WordFilter(["apple"]);\nwordFilter.f("a", "e"); // return 0, because the word at index 0 has prefix = "a" and suffix = 'e".\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= words.length <= 15000
    • \n\t
    • 1 <= words[i].length <= 10
    • \n\t
    • 1 <= prefix.length, suffix.length <= 10
    • \n\t
    • words[i], prefix and suffix consist of lower-case English letters only.
    • \n\t
    • At most 15000 calls will be made to the function f.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u591a\u4e2a words\uff0cwords[i] \u7684\u6743\u91cd\u4e3a i \u3002

    \n\n

    \u8bbe\u8ba1\u4e00\u4e2a\u7c7b WordFilter \u5b9e\u73b0\u51fd\u6570WordFilter.f(String prefix, String suffix)\u3002\u8fd9\u4e2a\u51fd\u6570\u5c06\u8fd4\u56de\u5177\u6709\u524d\u7f00 prefix \u548c\u540e\u7f00suffix \u7684\u8bcd\u7684\u6700\u5927\u6743\u91cd\u3002\u5982\u679c\u6ca1\u6709\u8fd9\u6837\u7684\u8bcd\uff0c\u8fd4\u56de -1\u3002

    \n\n

    \u4f8b\u5b50:

    \n\n
    \n\u8f93\u5165:\nWordFilter(["apple"])\nWordFilter.f("a", "e") // \u8fd4\u56de 0\nWordFilter.f("b", "") // \u8fd4\u56de -1\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. words\u7684\u957f\u5ea6\u5728[1, 15000]\u4e4b\u95f4\u3002
    2. \n\t
    3. \u5bf9\u4e8e\u6bcf\u4e2a\u6d4b\u8bd5\u7528\u4f8b\uff0c\u6700\u591a\u4f1a\u6709words.length\u6b21\u5bf9WordFilter.f\u7684\u8c03\u7528\u3002
    4. \n\t
    5. words[i]\u7684\u957f\u5ea6\u5728[1, 10]\u4e4b\u95f4\u3002
    6. \n\t
    7. prefix, suffix\u7684\u957f\u5ea6\u5728[0, 10]\u4e4b\u524d\u3002
    8. \n\t
    9. words[i]\u548cprefix, suffix\u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd\u3002
    10. \n
    \n", "tags_en": ["Trie"], "tags_cn": ["\u5b57\u5178\u6811"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class WordFilter {\npublic:\n WordFilter(vector& words) {\n\n }\n \n int f(string prefix, string suffix) {\n\n }\n};\n\n/**\n * Your WordFilter object will be instantiated and called as such:\n * WordFilter* obj = new WordFilter(words);\n * int param_1 = obj->f(prefix,suffix);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class WordFilter {\n\n public WordFilter(String[] words) {\n\n }\n \n public int f(String prefix, String suffix) {\n\n }\n}\n\n/**\n * Your WordFilter object will be instantiated and called as such:\n * WordFilter obj = new WordFilter(words);\n * int param_1 = obj.f(prefix,suffix);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class WordFilter(object):\n\n def __init__(self, words):\n \"\"\"\n :type words: List[str]\n \"\"\"\n\n\n def f(self, prefix, suffix):\n \"\"\"\n :type prefix: str\n :type suffix: str\n :rtype: int\n \"\"\"\n\n\n\n# Your WordFilter object will be instantiated and called as such:\n# obj = WordFilter(words)\n# param_1 = obj.f(prefix,suffix)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class WordFilter:\n\n def __init__(self, words: List[str]):\n\n\n def f(self, prefix: str, suffix: str) -> int:\n\n\n\n# Your WordFilter object will be instantiated and called as such:\n# obj = WordFilter(words)\n# param_1 = obj.f(prefix,suffix)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} WordFilter;\n\n\nWordFilter* wordFilterCreate(char ** words, int wordsSize) {\n \n}\n\nint wordFilterF(WordFilter* obj, char * prefix, char * suffix) {\n \n}\n\nvoid wordFilterFree(WordFilter* obj) {\n \n}\n\n/**\n * Your WordFilter struct will be instantiated and called as such:\n * WordFilter* obj = wordFilterCreate(words, wordsSize);\n * int param_1 = wordFilterF(obj, prefix, suffix);\n \n * wordFilterFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class WordFilter {\n\n public WordFilter(string[] words) {\n\n }\n \n public int F(string prefix, string suffix) {\n\n }\n}\n\n/**\n * Your WordFilter object will be instantiated and called as such:\n * WordFilter obj = new WordFilter(words);\n * int param_1 = obj.F(prefix,suffix);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n */\nvar WordFilter = function(words) {\n\n};\n\n/** \n * @param {string} prefix \n * @param {string} suffix\n * @return {number}\n */\nWordFilter.prototype.f = function(prefix, suffix) {\n\n};\n\n/**\n * Your WordFilter object will be instantiated and called as such:\n * var obj = new WordFilter(words)\n * var param_1 = obj.f(prefix,suffix)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class WordFilter\n\n=begin\n :type words: String[]\n=end\n def initialize(words)\n\n end\n\n\n=begin\n :type prefix: String\n :type suffix: String\n :rtype: Integer\n=end\n def f(prefix, suffix)\n\n end\n\n\nend\n\n# Your WordFilter object will be instantiated and called as such:\n# obj = WordFilter.new(words)\n# param_1 = obj.f(prefix, suffix)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass WordFilter {\n\n init(_ words: [String]) {\n\n }\n \n func f(_ prefix: String, _ suffix: String) -> Int {\n\n }\n}\n\n/**\n * Your WordFilter object will be instantiated and called as such:\n * let obj = WordFilter(words)\n * let ret_1: Int = obj.f(prefix, suffix)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type WordFilter struct {\n\n}\n\n\nfunc Constructor(words []string) WordFilter {\n\n}\n\n\nfunc (this *WordFilter) F(prefix string, suffix string) int {\n\n}\n\n\n/**\n * Your WordFilter object will be instantiated and called as such:\n * obj := Constructor(words);\n * param_1 := obj.F(prefix,suffix);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class WordFilter(_words: Array[String]) {\n\n def f(prefix: String, suffix: String): Int = {\n\n }\n\n}\n\n/**\n * Your WordFilter object will be instantiated and called as such:\n * var obj = new WordFilter(words)\n * var param_1 = obj.f(prefix,suffix)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class WordFilter(words: Array) {\n\n fun f(prefix: String, suffix: String): Int {\n\n }\n\n}\n\n/**\n * Your WordFilter object will be instantiated and called as such:\n * var obj = WordFilter(words)\n * var param_1 = obj.f(prefix,suffix)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct WordFilter {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl WordFilter {\n\n fn new(words: Vec) -> Self {\n\n }\n \n fn f(&self, prefix: String, suffix: String) -> i32 {\n\n }\n}\n\n/**\n * Your WordFilter object will be instantiated and called as such:\n * let obj = WordFilter::new(words);\n * let ret_1: i32 = obj.f(prefix, suffix);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class WordFilter {\n /**\n * @param String[] $words\n */\n function __construct($words) {\n\n }\n\n /**\n * @param String $prefix\n * @param String $suffix\n * @return Integer\n */\n function f($prefix, $suffix) {\n\n }\n}\n\n/**\n * Your WordFilter object will be instantiated and called as such:\n * $obj = WordFilter($words);\n * $ret_1 = $obj->f($prefix, $suffix);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class WordFilter {\n constructor(words: string[]) {\n\n }\n\n f(prefix: string, suffix: string): number {\n\n }\n}\n\n/**\n * Your WordFilter object will be instantiated and called as such:\n * var obj = new WordFilter(words)\n * var param_1 = obj.f(prefix,suffix)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define word-filter%\n (class object%\n (super-new)\n\n ; words : (listof string?)\n (init-field\n words)\n \n ; f : string? string? -> exact-integer?\n (define/public (f prefix suffix)\n\n )))\n\n;; Your word-filter% object will be instantiated and called as such:\n;; (define obj (new word-filter% [words words]))\n;; (define param_1 (send obj f prefix suffix))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0745](https://leetcode-cn.com/problems/prefix-and-suffix-search)", "[\u524d\u7f00\u548c\u540e\u7f00\u641c\u7d22](/solution/0700-0799/0745.Prefix%20and%20Suffix%20Search/README.md)", "`\u5b57\u5178\u6811`", "\u56f0\u96be", ""], "md_table_row_en": ["[0745](https://leetcode.com/problems/prefix-and-suffix-search)", "[Prefix and Suffix Search](/solution/0700-0799/0745.Prefix%20and%20Suffix%20Search/README_EN.md)", "`Trie`", "Hard", ""]}, {"question_id": "0745", "frontend_question_id": "0744", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-smallest-letter-greater-than-target", "url_en": "https://leetcode.com/problems/find-smallest-letter-greater-than-target", "relative_path_cn": "/solution/0700-0799/0744.Find%20Smallest%20Letter%20Greater%20Than%20Target/README.md", "relative_path_en": "/solution/0700-0799/0744.Find%20Smallest%20Letter%20Greater%20Than%20Target/README_EN.md", "title_cn": "\u5bfb\u627e\u6bd4\u76ee\u6807\u5b57\u6bcd\u5927\u7684\u6700\u5c0f\u5b57\u6bcd", "title_en": "Find Smallest Letter Greater Than Target", "question_title_slug": "find-smallest-letter-greater-than-target", "content_en": "

    Given a characters array letters that is sorted in non-decreasing order and a character target, return the smallest character in the array that is larger than target.

    \n\n

    Note that the letters wrap around.

    \n\n
      \n\t
    • For example, if target == 'z' and letters == ['a', 'b'], the answer is 'a'.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: letters = ["c","f","j"], target = "a"\nOutput: "c"\n
    \n\n

    Example 2:

    \n\n
    \nInput: letters = ["c","f","j"], target = "c"\nOutput: "f"\n
    \n\n

    Example 3:

    \n\n
    \nInput: letters = ["c","f","j"], target = "d"\nOutput: "f"\n
    \n\n

    Example 4:

    \n\n
    \nInput: letters = ["c","f","j"], target = "g"\nOutput: "j"\n
    \n\n

    Example 5:

    \n\n
    \nInput: letters = ["c","f","j"], target = "j"\nOutput: "c"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= letters.length <= 104
    • \n\t
    • letters[i] is a lowercase English letter.
    • \n\t
    • letters is sorted in non-decreasing order.
    • \n\t
    • letters contains at least two different characters.
    • \n\t
    • target is a lowercase English letter.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6392\u5e8f\u540e\u7684\u5b57\u7b26\u5217\u8868 letters \uff0c\u5217\u8868\u4e2d\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002\u53e6\u7ed9\u51fa\u4e00\u4e2a\u76ee\u6807\u5b57\u6bcd target\uff0c\u8bf7\u4f60\u5bfb\u627e\u5728\u8fd9\u4e00\u6709\u5e8f\u5217\u8868\u91cc\u6bd4\u76ee\u6807\u5b57\u6bcd\u5927\u7684\u6700\u5c0f\u5b57\u6bcd\u3002

    \n\n

    \u5728\u6bd4\u8f83\u65f6\uff0c\u5b57\u6bcd\u662f\u4f9d\u5e8f\u5faa\u73af\u51fa\u73b0\u7684\u3002\u4e3e\u4e2a\u4f8b\u5b50\uff1a

    \n\n
      \n\t
    • \u5982\u679c\u76ee\u6807\u5b57\u6bcd target = 'z' \u5e76\u4e14\u5b57\u7b26\u5217\u8868\u4e3a letters = ['a', 'b']\uff0c\u5219\u7b54\u6848\u8fd4\u56de 'a'
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165:\nletters = ["c", "f", "j"]\ntarget = "a"\n\u8f93\u51fa: "c"\n\n\u8f93\u5165:\nletters = ["c", "f", "j"]\ntarget = "c"\n\u8f93\u51fa: "f"\n\n\u8f93\u5165:\nletters = ["c", "f", "j"]\ntarget = "d"\n\u8f93\u51fa: "f"\n\n\u8f93\u5165:\nletters = ["c", "f", "j"]\ntarget = "g"\n\u8f93\u51fa: "j"\n\n\u8f93\u5165:\nletters = ["c", "f", "j"]\ntarget = "j"\n\u8f93\u51fa: "c"\n\n\u8f93\u5165:\nletters = ["c", "f", "j"]\ntarget = "k"\n\u8f93\u51fa: "c"\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. letters\u957f\u5ea6\u8303\u56f4\u5728[2, 10000]\u533a\u95f4\u5185\u3002
    2. \n\t
    3. letters \u4ec5\u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210\uff0c\u6700\u5c11\u5305\u542b\u4e24\u4e2a\u4e0d\u540c\u7684\u5b57\u6bcd\u3002
    4. \n\t
    5. \u76ee\u6807\u5b57\u6bcdtarget \u662f\u4e00\u4e2a\u5c0f\u5199\u5b57\u6bcd\u3002
    6. \n
    \n", "tags_en": ["Binary Search"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n char nextGreatestLetter(vector& letters, char target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public char nextGreatestLetter(char[] letters, char target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def nextGreatestLetter(self, letters, target):\n \"\"\"\n :type letters: List[str]\n :type target: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def nextGreatestLetter(self, letters: List[str], target: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar nextGreatestLetter(char* letters, int lettersSize, char target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public char NextGreatestLetter(char[] letters, char target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {character[]} letters\n * @param {character} target\n * @return {character}\n */\nvar nextGreatestLetter = function(letters, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Character[]} letters\n# @param {Character} target\n# @return {Character}\ndef next_greatest_letter(letters, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func nextGreatestLetter(_ letters: [Character], _ target: Character) -> Character {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func nextGreatestLetter(letters []byte, target byte) byte {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def nextGreatestLetter(letters: Array[Char], target: Char): Char = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun nextGreatestLetter(letters: CharArray, target: Char): Char {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn next_greatest_letter(letters: Vec, target: char) -> char {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $letters\n * @param String $target\n * @return String\n */\n function nextGreatestLetter($letters, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function nextGreatestLetter(letters: string[], target: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (next-greatest-letter letters target)\n (-> (listof char?) char? char?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0744](https://leetcode-cn.com/problems/find-smallest-letter-greater-than-target)", "[\u5bfb\u627e\u6bd4\u76ee\u6807\u5b57\u6bcd\u5927\u7684\u6700\u5c0f\u5b57\u6bcd](/solution/0700-0799/0744.Find%20Smallest%20Letter%20Greater%20Than%20Target/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u7b80\u5355", ""], "md_table_row_en": ["[0744](https://leetcode.com/problems/find-smallest-letter-greater-than-target)", "[Find Smallest Letter Greater Than Target](/solution/0700-0799/0744.Find%20Smallest%20Letter%20Greater%20Than%20Target/README_EN.md)", "`Binary Search`", "Easy", ""]}, {"question_id": "0744", "frontend_question_id": "0743", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/network-delay-time", "url_en": "https://leetcode.com/problems/network-delay-time", "relative_path_cn": "/solution/0700-0799/0743.Network%20Delay%20Time/README.md", "relative_path_en": "/solution/0700-0799/0743.Network%20Delay%20Time/README_EN.md", "title_cn": "\u7f51\u7edc\u5ef6\u8fdf\u65f6\u95f4", "title_en": "Network Delay Time", "question_title_slug": "network-delay-time", "content_en": "

    You are given a network of n nodes, labeled from 1 to n. You are also given times, a list of travel times as directed edges times[i] = (ui, vi, wi), where ui is the source node, vi is the target node, and wi is the time it takes for a signal to travel from source to target.

    \n\n

    We will send a signal from a given node k. Return the time it takes for all the n nodes to receive the signal. If it is impossible for all the n nodes to receive the signal, return -1.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: times = [[2,1,1],[2,3,1],[3,4,1]], n = 4, k = 2\nOutput: 2\n
    \n\n

    Example 2:

    \n\n
    \nInput: times = [[1,2,1]], n = 2, k = 1\nOutput: 1\n
    \n\n

    Example 3:

    \n\n
    \nInput: times = [[1,2,1]], n = 2, k = 2\nOutput: -1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= k <= n <= 100
    • \n\t
    • 1 <= times.length <= 6000
    • \n\t
    • times[i].length == 3
    • \n\t
    • 1 <= ui, vi <= n
    • \n\t
    • ui != vi
    • \n\t
    • 0 <= wi <= 100
    • \n\t
    • All the pairs (ui, vi) are unique. (i.e., no multiple edges.)
    • \n
    \n", "content_cn": "

    \u6709 n \u4e2a\u7f51\u7edc\u8282\u70b9\uff0c\u6807\u8bb0\u4e3a\u00a01\u00a0\u5230 n\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u5217\u8868\u00a0times\uff0c\u8868\u793a\u4fe1\u53f7\u7ecf\u8fc7 \u6709\u5411 \u8fb9\u7684\u4f20\u9012\u65f6\u95f4\u3002\u00a0times[i] = (ui, vi, wi)\uff0c\u5176\u4e2d\u00a0ui\u00a0\u662f\u6e90\u8282\u70b9\uff0cvi\u00a0\u662f\u76ee\u6807\u8282\u70b9\uff0c wi\u00a0\u662f\u4e00\u4e2a\u4fe1\u53f7\u4ece\u6e90\u8282\u70b9\u4f20\u9012\u5230\u76ee\u6807\u8282\u70b9\u7684\u65f6\u95f4\u3002

    \n\n

    \u73b0\u5728\uff0c\u4ece\u67d0\u4e2a\u8282\u70b9\u00a0K\u00a0\u53d1\u51fa\u4e00\u4e2a\u4fe1\u53f7\u3002\u9700\u8981\u591a\u4e45\u624d\u80fd\u4f7f\u6240\u6709\u8282\u70b9\u90fd\u6536\u5230\u4fe1\u53f7\uff1f\u5982\u679c\u4e0d\u80fd\u4f7f\u6240\u6709\u8282\u70b9\u6536\u5230\u4fe1\u53f7\uff0c\u8fd4\u56de\u00a0-1 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1atimes = [[2,1,1],[2,3,1],[3,4,1]], n = 4, k = 2\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1atimes = [[1,2,1]], n = 2, k = 1\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1atimes = [[1,2,1]], n = 2, k = 2\n\u8f93\u51fa\uff1a-1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= k <= n <= 100
    • \n\t
    • 1 <= times.length <= 6000
    • \n\t
    • times[i].length == 3
    • \n\t
    • 1 <= ui, vi <= n
    • \n\t
    • ui != vi
    • \n\t
    • 0 <= wi <= 100
    • \n\t
    • \u6240\u6709 (ui, vi) \u5bf9\u90fd \u4e92\u4e0d\u76f8\u540c\uff08\u5373\uff0c\u4e0d\u542b\u91cd\u590d\u8fb9\uff09
    • \n
    \n", "tags_en": ["Heap", "Depth-first Search", "Breadth-first Search", "Graph"], "tags_cn": ["\u5806", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int networkDelayTime(vector>& times, int n, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int networkDelayTime(int[][] times, int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def networkDelayTime(self, times, n, k):\n \"\"\"\n :type times: List[List[int]]\n :type n: int\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def networkDelayTime(self, times: List[List[int]], n: int, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint networkDelayTime(int** times, int timesSize, int* timesColSize, int n, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NetworkDelayTime(int[][] times, int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} times\n * @param {number} n\n * @param {number} k\n * @return {number}\n */\nvar networkDelayTime = function(times, n, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} times\n# @param {Integer} n\n# @param {Integer} k\n# @return {Integer}\ndef network_delay_time(times, n, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func networkDelayTime(_ times: [[Int]], _ n: Int, _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func networkDelayTime(times [][]int, n int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def networkDelayTime(times: Array[Array[Int]], n: Int, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun networkDelayTime(times: Array, n: Int, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn network_delay_time(times: Vec>, n: i32, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $times\n * @param Integer $n\n * @param Integer $k\n * @return Integer\n */\n function networkDelayTime($times, $n, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function networkDelayTime(times: number[][], n: number, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (network-delay-time times n k)\n (-> (listof (listof exact-integer?)) exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0743](https://leetcode-cn.com/problems/network-delay-time)", "[\u7f51\u7edc\u5ef6\u8fdf\u65f6\u95f4](/solution/0700-0799/0743.Network%20Delay%20Time/README.md)", "`\u5806`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u56fe`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0743](https://leetcode.com/problems/network-delay-time)", "[Network Delay Time](/solution/0700-0799/0743.Network%20Delay%20Time/README_EN.md)", "`Heap`,`Depth-first Search`,`Breadth-first Search`,`Graph`", "Medium", ""]}, {"question_id": "0743", "frontend_question_id": "0742", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/closest-leaf-in-a-binary-tree", "url_en": "https://leetcode.com/problems/closest-leaf-in-a-binary-tree", "relative_path_cn": "/solution/0700-0799/0742.Closest%20Leaf%20in%20a%20Binary%20Tree/README.md", "relative_path_en": "/solution/0700-0799/0742.Closest%20Leaf%20in%20a%20Binary%20Tree/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u6700\u8fd1\u7684\u53f6\u8282\u70b9", "title_en": "Closest Leaf in a Binary Tree", "question_title_slug": "closest-leaf-in-a-binary-tree", "content_en": "

    Given a binary tree where every node has a unique value, and a target key k, find the value of the nearest leaf node to target k in the tree.\r\n

    \r\nHere, nearest to a leaf means the least number of edges travelled on the binary tree to reach any leaf of the tree. Also, a node is called a leaf if it has no children.\r\n

    \r\nIn the following examples, the input tree is represented in flattened form row by row.\r\nThe actual root tree given will be a TreeNode object.\r\n

    \r\nExample 1:\r\n

    \r\nInput:\r\nroot = [1, 3, 2], k = 1\r\nDiagram of binary tree:\r\n          1\r\n         / \\\r\n        3   2\r\n\r\nOutput: 2 (or 3)\r\n\r\nExplanation: Either 2 or 3 is the nearest leaf node to the target of 1.\r\n
    \r\n

    \r\nExample 2:\r\n

    \r\nInput:\r\nroot = [1], k = 1\r\nOutput: 1\r\n\r\nExplanation: The nearest leaf node is the root node itself.\r\n
    \r\n

    \r\n\r\n

    \r\nExample 3:\r\n

    \r\nInput:\r\nroot = [1,2,3,4,null,null,null,5,null,6], k = 2\r\nDiagram of binary tree:\r\n             1\r\n            / \\\r\n           2   3\r\n          /\r\n         4\r\n        /\r\n       5\r\n      /\r\n     6\r\n\r\nOutput: 3\r\nExplanation: The leaf node with value 3 (and not the leaf node with value 6) is nearest to the node with value 2.\r\n
    \r\n

    \r\n\r\n

    Note:
    \r\n

      \r\n
    1. root represents a binary tree with at least 1 node and at most 1000 nodes.
    2. \r\n
    3. Every node has a unique node.val in range [1, 1000].
    4. \r\n
    5. There exists some node in the given binary tree for which node.val == k.
    6. \r\n
    \r\n

    ", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a \u6bcf\u4e2a\u7ed3\u70b9\u7684\u503c\u4e92\u4e0d\u76f8\u540c \u7684\u4e8c\u53c9\u6811\uff0c\u548c\u4e00\u4e2a\u76ee\u6807\u503c k\uff0c\u627e\u51fa\u6811\u4e2d\u4e0e\u76ee\u6807\u503c k \u6700\u8fd1\u7684\u53f6\u7ed3\u70b9\u3002 

    \n\n

    \u8fd9\u91cc\uff0c\u4e0e\u53f6\u7ed3\u70b9 \u6700\u8fd1 \u8868\u793a\u5728\u4e8c\u53c9\u6811\u4e2d\u5230\u8fbe\u8be5\u53f6\u8282\u70b9\u9700\u8981\u884c\u8fdb\u7684\u8fb9\u6570\u4e0e\u5230\u8fbe\u5176\u5b83\u53f6\u7ed3\u70b9\u76f8\u6bd4\u6700\u5c11\u3002\u800c\u4e14\uff0c\u5f53\u4e00\u4e2a\u7ed3\u70b9\u6ca1\u6709\u5b69\u5b50\u7ed3\u70b9\u65f6\u79f0\u5176\u4e3a\u53f6\u7ed3\u70b9\u3002

    \n\n

    \u5728\u4e0b\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c\u8f93\u5165\u7684\u6811\u4ee5\u9010\u884c\u7684\u5e73\u94fa\u5f62\u5f0f\u8868\u793a\u3002\u5b9e\u9645\u4e0a\u7684\u6709\u6839\u6811 root \u5c06\u4ee5TreeNode\u5bf9\u8c61\u7684\u5f62\u5f0f\u7ed9\u51fa\u3002

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a\nroot = [1, 3, 2], k = 1\n\u4e8c\u53c9\u6811\u56fe\u793a\uff1a\n          1\n         / \\\n        3   2\n\n\u8f93\u51fa\uff1a 2 (\u6216 3)\n\n\u89e3\u91ca\uff1a 2 \u548c 3 \u90fd\u662f\u8ddd\u79bb\u76ee\u6807 1 \u6700\u8fd1\u7684\u53f6\u8282\u70b9\u3002\n
    \n\n

     

    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a\nroot = [1], k = 1\n\u8f93\u51fa\uff1a1\n\n\u89e3\u91ca\uff1a \u6700\u8fd1\u7684\u53f6\u8282\u70b9\u662f\u6839\u7ed3\u70b9\u81ea\u8eab\u3002\n
    \n\n

     

    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1a\nroot = [1,2,3,4,null,null,null,5,null,6], k = 2\n\u4e8c\u53c9\u6811\u56fe\u793a\uff1a\n             1\n            / \\\n           2   3\n          /\n         4\n        /\n       5\n      /\n     6\n\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a \u503c\u4e3a 3\uff08\u800c\u4e0d\u662f\u503c\u4e3a 6\uff09\u7684\u53f6\u8282\u70b9\u662f\u8ddd\u79bb\u7ed3\u70b9 2 \u7684\u6700\u8fd1\u7ed3\u70b9\u3002\n
    \n\n

     

    \n\n

    \u6ce8\uff1a

    \n\n
      \n\t
    1. root \u8868\u793a\u7684\u4e8c\u53c9\u6811\u6700\u5c11\u6709 1 \u4e2a\u7ed3\u70b9\u4e14\u6700\u591a\u6709 1000 \u4e2a\u7ed3\u70b9\u3002
    2. \n\t
    3. \u6bcf\u4e2a\u7ed3\u70b9\u90fd\u6709\u4e00\u4e2a\u552f\u4e00\u7684 node.val \uff0c\u8303\u56f4\u4e3a [1, 1000]\u3002
    4. \n\t
    5. \u7ed9\u5b9a\u7684\u4e8c\u53c9\u6811\u4e2d\u6709\u67d0\u4e2a\u7ed3\u70b9\u4f7f\u5f97 node.val == k\u3002
    6. \n
    \n\n

     

    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int findClosestLeaf(TreeNode* root, int k) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int findClosestLeaf(TreeNode root, int k) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def findClosestLeaf(self, root, k):\n \"\"\"\n :type root: TreeNode\n :type k: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def findClosestLeaf(self, root: TreeNode, k: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint findClosestLeaf(struct TreeNode* root, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int FindClosestLeaf(TreeNode root, int k) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number} k\n * @return {number}\n */\nvar findClosestLeaf = function(root, k) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @param {Integer} k\n# @return {Integer}\ndef find_closest_leaf(root, k)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func findClosestLeaf(_ root: TreeNode?, _ k: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc findClosestLeaf(root *TreeNode, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def findClosestLeaf(root: TreeNode, k: Int): Int = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun findClosestLeaf(root: TreeNode?, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn find_closest_leaf(root: Option>>, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param Integer $k\n * @return Integer\n */\n function findClosestLeaf($root, $k) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction findClosestLeaf(root: TreeNode | null, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (find-closest-leaf root k)\n (-> (or/c tree-node? #f) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0742](https://leetcode-cn.com/problems/closest-leaf-in-a-binary-tree)", "[\u4e8c\u53c9\u6811\u6700\u8fd1\u7684\u53f6\u8282\u70b9](/solution/0700-0799/0742.Closest%20Leaf%20in%20a%20Binary%20Tree/README.md)", "`\u6811`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0742](https://leetcode.com/problems/closest-leaf-in-a-binary-tree)", "[Closest Leaf in a Binary Tree](/solution/0700-0799/0742.Closest%20Leaf%20in%20a%20Binary%20Tree/README_EN.md)", "`Tree`", "Medium", "\ud83d\udd12"]}, {"question_id": "0742", "frontend_question_id": "0709", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/to-lower-case", "url_en": "https://leetcode.com/problems/to-lower-case", "relative_path_cn": "/solution/0700-0799/0709.To%20Lower%20Case/README.md", "relative_path_en": "/solution/0700-0799/0709.To%20Lower%20Case/README_EN.md", "title_cn": "\u8f6c\u6362\u6210\u5c0f\u5199\u5b57\u6bcd", "title_en": "To Lower Case", "question_title_slug": "to-lower-case", "content_en": "

    Given a string s, return the string after replacing every uppercase letter with the same lowercase letter.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "Hello"\nOutput: "hello"\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "here"\nOutput: "here"\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "LOVELY"\nOutput: "lovely"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 100
    • \n\t
    • s consists of printable ASCII characters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \uff0c\u5c06\u8be5\u5b57\u7b26\u4e32\u4e2d\u7684\u5927\u5199\u5b57\u6bcd\u8f6c\u6362\u6210\u76f8\u540c\u7684\u5c0f\u5199\u5b57\u6bcd\uff0c\u8fd4\u56de\u65b0\u7684\u5b57\u7b26\u4e32\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"Hello\"\n\u8f93\u51fa\uff1a\"hello\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"here\"\n\u8f93\u51fa\uff1a\"here\"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"LOVELY\"\n\u8f93\u51fa\uff1a\"lovely\"\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 100
    • \n\t
    • s \u7531 ASCII \u5b57\u7b26\u96c6\u4e2d\u7684\u53ef\u6253\u5370\u5b57\u7b26\u7ec4\u6210
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string toLowerCase(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String toLowerCase(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def toLowerCase(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def toLowerCase(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * toLowerCase(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ToLowerCase(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar toLowerCase = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef to_lower_case(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func toLowerCase(_ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func toLowerCase(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def toLowerCase(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun toLowerCase(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn to_lower_case(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function toLowerCase($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function toLowerCase(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (to-lower-case s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0709](https://leetcode-cn.com/problems/to-lower-case)", "[\u8f6c\u6362\u6210\u5c0f\u5199\u5b57\u6bcd](/solution/0700-0799/0709.To%20Lower%20Case/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0709](https://leetcode.com/problems/to-lower-case)", "[To Lower Case](/solution/0700-0799/0709.To%20Lower%20Case/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "0741", "frontend_question_id": "0741", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/cherry-pickup", "url_en": "https://leetcode.com/problems/cherry-pickup", "relative_path_cn": "/solution/0700-0799/0741.Cherry%20Pickup/README.md", "relative_path_en": "/solution/0700-0799/0741.Cherry%20Pickup/README_EN.md", "title_cn": "\u6458\u6a31\u6843", "title_en": "Cherry Pickup", "question_title_slug": "cherry-pickup", "content_en": "

    You are given an n x n grid representing a field of cherries, each cell is one of three possible integers.

    \n\n
      \n\t
    • 0 means the cell is empty, so you can pass through,
    • \n\t
    • 1 means the cell contains a cherry that you can pick up and pass through, or
    • \n\t
    • -1 means the cell contains a thorn that blocks your way.
    • \n
    \n\n

    Return the maximum number of cherries you can collect by following the rules below:

    \n\n
      \n\t
    • Starting at the position (0, 0) and reaching (n - 1, n - 1) by moving right or down through valid path cells (cells with value 0 or 1).
    • \n\t
    • After reaching (n - 1, n - 1), returning to (0, 0) by moving left or up through valid path cells.
    • \n\t
    • When passing through a path cell containing a cherry, you pick it up, and the cell becomes an empty cell 0.
    • \n\t
    • If there is no valid path between (0, 0) and (n - 1, n - 1), then no cherries can be collected.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: grid = [[0,1,-1],[1,0,-1],[1,1,1]]\nOutput: 5\nExplanation: The player started at (0, 0) and went down, down, right right to reach (2, 2).\n4 cherries were picked up during this single trip, and the matrix becomes [[0,1,-1],[0,0,-1],[0,0,0]].\nThen, the player went left, up, up, left to return home, picking up one more cherry.\nThe total number of cherries picked up is 5, and this is the maximum possible.\n
    \n\n

    Example 2:

    \n\n
    \nInput: grid = [[1,1,-1],[1,-1,1],[-1,1,1]]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= n <= 50
    • \n\t
    • grid[i][j] is -1, 0, or 1.
    • \n\t
    • grid[0][0] != -1
    • \n\t
    • grid[n - 1][n - 1] != -1
    • \n
    \n", "content_cn": "

    \u4e00\u4e2aN x N\u7684\u7f51\u683c(grid) \u4ee3\u8868\u4e86\u4e00\u5757\u6a31\u6843\u5730\uff0c\u6bcf\u4e2a\u683c\u5b50\u7531\u4ee5\u4e0b\u4e09\u79cd\u6570\u5b57\u7684\u4e00\u79cd\u6765\u8868\u793a\uff1a

    \n\n
      \n\t
    • 0 \u8868\u793a\u8fd9\u4e2a\u683c\u5b50\u662f\u7a7a\u7684\uff0c\u6240\u4ee5\u4f60\u53ef\u4ee5\u7a7f\u8fc7\u5b83\u3002
    • \n\t
    • 1 \u8868\u793a\u8fd9\u4e2a\u683c\u5b50\u91cc\u88c5\u7740\u4e00\u4e2a\u6a31\u6843\uff0c\u4f60\u53ef\u4ee5\u6458\u5230\u6a31\u6843\u7136\u540e\u7a7f\u8fc7\u5b83\u3002
    • \n\t
    • -1 \u8868\u793a\u8fd9\u4e2a\u683c\u5b50\u91cc\u6709\u8346\u68d8\uff0c\u6321\u7740\u4f60\u7684\u8def\u3002
    • \n
    \n\n

    \u4f60\u7684\u4efb\u52a1\u662f\u5728\u9075\u5b88\u4e0b\u5217\u89c4\u5219\u7684\u60c5\u51b5\u4e0b\uff0c\u5c3d\u53ef\u80fd\u7684\u6458\u5230\u6700\u591a\u6a31\u6843\uff1a

    \n\n
      \n\t
    • \u4ece\u4f4d\u7f6e (0, 0) \u51fa\u53d1\uff0c\u6700\u540e\u5230\u8fbe (N-1, N-1) \uff0c\u53ea\u80fd\u5411\u4e0b\u6216\u5411\u53f3\u8d70\uff0c\u5e76\u4e14\u53ea\u80fd\u7a7f\u8d8a\u6709\u6548\u7684\u683c\u5b50\uff08\u5373\u53ea\u53ef\u4ee5\u7a7f\u8fc7\u503c\u4e3a0\u6216\u80051\u7684\u683c\u5b50\uff09\uff1b
    • \n\t
    • \u5f53\u5230\u8fbe (N-1, N-1) \u540e\uff0c\u4f60\u8981\u7ee7\u7eed\u8d70\uff0c\u76f4\u5230\u8fd4\u56de\u5230 (0, 0) \uff0c\u53ea\u80fd\u5411\u4e0a\u6216\u5411\u5de6\u8d70\uff0c\u5e76\u4e14\u53ea\u80fd\u7a7f\u8d8a\u6709\u6548\u7684\u683c\u5b50\uff1b
    • \n\t
    • \u5f53\u4f60\u7ecf\u8fc7\u4e00\u4e2a\u683c\u5b50\u4e14\u8fd9\u4e2a\u683c\u5b50\u5305\u542b\u4e00\u4e2a\u6a31\u6843\u65f6\uff0c\u4f60\u5c06\u6458\u5230\u6a31\u6843\u5e76\u4e14\u8fd9\u4e2a\u683c\u5b50\u4f1a\u53d8\u6210\u7a7a\u7684\uff08\u503c\u53d8\u4e3a0\uff09\uff1b
    • \n\t
    • \u5982\u679c\u5728 (0, 0) \u548c (N-1, N-1) \u4e4b\u95f4\u4e0d\u5b58\u5728\u4e00\u6761\u53ef\u7ecf\u8fc7\u7684\u8def\u5f84\uff0c\u5219\u6ca1\u6709\u4efb\u4f55\u4e00\u4e2a\u6a31\u6843\u80fd\u88ab\u6458\u5230\u3002
    • \n
    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: grid =\n[[0, 1, -1],\n [1, 0, -1],\n [1, 1,  1]]\n\u8f93\u51fa: 5\n\u89e3\u91ca\uff1a \n\u73a9\u5bb6\u4ece\uff080,0\uff09\u70b9\u51fa\u53d1\uff0c\u7ecf\u8fc7\u4e86\u5411\u4e0b\u8d70\uff0c\u5411\u4e0b\u8d70\uff0c\u5411\u53f3\u8d70\uff0c\u5411\u53f3\u8d70\uff0c\u5230\u8fbe\u4e86\u70b9(2, 2)\u3002\n\u5728\u8fd9\u8d9f\u5355\u7a0b\u4e2d\uff0c\u603b\u5171\u6458\u5230\u4e864\u9897\u6a31\u6843\uff0c\u77e9\u9635\u53d8\u6210\u4e86[[0,1,-1],[0,0,-1],[0,0,0]]\u3002\n\u63a5\u7740\uff0c\u8fd9\u540d\u73a9\u5bb6\u5411\u5de6\u8d70\uff0c\u5411\u4e0a\u8d70\uff0c\u5411\u4e0a\u8d70\uff0c\u5411\u5de6\u8d70\uff0c\u8fd4\u56de\u4e86\u8d77\u59cb\u70b9\uff0c\u53c8\u6458\u5230\u4e861\u9897\u6a31\u6843\u3002\n\u5728\u65c5\u7a0b\u4e2d\uff0c\u603b\u5171\u6458\u5230\u4e865\u9897\u6a31\u6843\uff0c\u8fd9\u662f\u53ef\u4ee5\u6458\u5230\u7684\u6700\u5927\u503c\u4e86\u3002\n
    \n\n

    \u8bf4\u660e:

    \n\n
      \n\t
    • grid \u662f\u4e00\u4e2a N * N \u7684\u4e8c\u7ef4\u6570\u7ec4\uff0cN\u7684\u53d6\u503c\u8303\u56f4\u662f1 <= N <= 50\u3002
    • \n\t
    • \u6bcf\u4e00\u4e2a grid[i][j] \u90fd\u662f\u96c6\u5408 {-1, 0, 1}\u5176\u4e2d\u7684\u4e00\u4e2a\u6570\u3002
    • \n\t
    • \u53ef\u4ee5\u4fdd\u8bc1\u8d77\u70b9 grid[0][0] \u548c\u7ec8\u70b9 grid[N-1][N-1] \u7684\u503c\u90fd\u4e0d\u4f1a\u662f -1\u3002
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int cherryPickup(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int cherryPickup(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def cherryPickup(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def cherryPickup(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint cherryPickup(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CherryPickup(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar cherryPickup = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef cherry_pickup(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func cherryPickup(_ grid: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func cherryPickup(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def cherryPickup(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun cherryPickup(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn cherry_pickup(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function cherryPickup($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function cherryPickup(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (cherry-pickup grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0741](https://leetcode-cn.com/problems/cherry-pickup)", "[\u6458\u6a31\u6843](/solution/0700-0799/0741.Cherry%20Pickup/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0741](https://leetcode.com/problems/cherry-pickup)", "[Cherry Pickup](/solution/0700-0799/0741.Cherry%20Pickup/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "0740", "frontend_question_id": "0740", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/delete-and-earn", "url_en": "https://leetcode.com/problems/delete-and-earn", "relative_path_cn": "/solution/0700-0799/0740.Delete%20and%20Earn/README.md", "relative_path_en": "/solution/0700-0799/0740.Delete%20and%20Earn/README_EN.md", "title_cn": "\u5220\u9664\u5e76\u83b7\u5f97\u70b9\u6570", "title_en": "Delete and Earn", "question_title_slug": "delete-and-earn", "content_en": "

    Given an array nums of integers, you can perform operations on the array.

    \n\n

    In each operation, you pick any nums[i] and delete it to earn nums[i] points. After, you must delete every element equal to nums[i] - 1 or nums[i] + 1.

    \n\n

    You start with 0 points. Return the maximum number of points you can earn by applying such operations.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [3,4,2]\nOutput: 6\nExplanation: Delete 4 to earn 4 points, consequently 3 is also deleted.\nThen, delete 2 to earn 2 points.\n6 total points are earned.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [2,2,3,3,3,4]\nOutput: 9\nExplanation: Delete 3 to earn 3 points, deleting both 2's and the 4.\nThen, delete 3 again to earn 3 points, and 3 again to earn 3 points.\n9 total points are earned.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 2 * 104
    • \n\t
    • 1 <= nums[i] <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0nums\u00a0\uff0c\u4f60\u53ef\u4ee5\u5bf9\u5b83\u8fdb\u884c\u4e00\u4e9b\u64cd\u4f5c\u3002

    \n\n

    \u6bcf\u6b21\u64cd\u4f5c\u4e2d\uff0c\u9009\u62e9\u4efb\u610f\u4e00\u4e2a\u00a0nums[i]\u00a0\uff0c\u5220\u9664\u5b83\u5e76\u83b7\u5f97\u00a0nums[i]\u00a0\u7684\u70b9\u6570\u3002\u4e4b\u540e\uff0c\u4f60\u5fc5\u987b\u5220\u9664 \u6240\u6709 \u7b49\u4e8e\u00a0nums[i] - 1 \u548c nums[i] + 1\u00a0\u7684\u5143\u7d20\u3002

    \n\n

    \u5f00\u59cb\u4f60\u62e5\u6709 0 \u4e2a\u70b9\u6570\u3002\u8fd4\u56de\u4f60\u80fd\u901a\u8fc7\u8fd9\u4e9b\u64cd\u4f5c\u83b7\u5f97\u7684\u6700\u5927\u70b9\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [3,4,2]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\n\u5220\u9664 4 \u83b7\u5f97 4 \u4e2a\u70b9\u6570\uff0c\u56e0\u6b64 3 \u4e5f\u88ab\u5220\u9664\u3002\n\u4e4b\u540e\uff0c\u5220\u9664 2 \u83b7\u5f97 2 \u4e2a\u70b9\u6570\u3002\u603b\u5171\u83b7\u5f97 6 \u4e2a\u70b9\u6570\u3002\n
    \n\n

    \u793a\u4f8b\u00a02\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [2,2,3,3,3,4]\n\u8f93\u51fa\uff1a9\n\u89e3\u91ca\uff1a\n\u5220\u9664 3 \u83b7\u5f97 3 \u4e2a\u70b9\u6570\uff0c\u63a5\u7740\u8981\u5220\u9664\u4e24\u4e2a 2 \u548c 4 \u3002\n\u4e4b\u540e\uff0c\u518d\u6b21\u5220\u9664 3 \u83b7\u5f97 3 \u4e2a\u70b9\u6570\uff0c\u518d\u6b21\u5220\u9664 3 \u83b7\u5f97 3 \u4e2a\u70b9\u6570\u3002\n\u603b\u5171\u83b7\u5f97 9 \u4e2a\u70b9\u6570\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 2 * 104
    • \n\t
    • 1 <= nums[i] <= 104
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int deleteAndEarn(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int deleteAndEarn(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def deleteAndEarn(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def deleteAndEarn(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint deleteAndEarn(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int DeleteAndEarn(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar deleteAndEarn = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef delete_and_earn(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func deleteAndEarn(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func deleteAndEarn(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def deleteAndEarn(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun deleteAndEarn(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn delete_and_earn(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function deleteAndEarn($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function deleteAndEarn(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (delete-and-earn nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0740](https://leetcode-cn.com/problems/delete-and-earn)", "[\u5220\u9664\u5e76\u83b7\u5f97\u70b9\u6570](/solution/0700-0799/0740.Delete%20and%20Earn/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0740](https://leetcode.com/problems/delete-and-earn)", "[Delete and Earn](/solution/0700-0799/0740.Delete%20and%20Earn/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0739", "frontend_question_id": "0739", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/daily-temperatures", "url_en": "https://leetcode.com/problems/daily-temperatures", "relative_path_cn": "/solution/0700-0799/0739.Daily%20Temperatures/README.md", "relative_path_en": "/solution/0700-0799/0739.Daily%20Temperatures/README_EN.md", "title_cn": "\u6bcf\u65e5\u6e29\u5ea6", "title_en": "Daily Temperatures", "question_title_slug": "daily-temperatures", "content_en": "

    Given an array of integers temperatures represents the daily temperatures, return an array answer such that answer[i] is the number of days you have to wait after the ith day to get a warmer temperature. If there is no future day for which this is possible, keep answer[i] == 0 instead.

    \n\n

     

    \n

    Example 1:

    \n
    Input: temperatures = [73,74,75,71,69,72,76,73]\nOutput: [1,1,4,2,1,1,0,0]\n

    Example 2:

    \n
    Input: temperatures = [30,40,50,60]\nOutput: [1,1,1,0]\n

    Example 3:

    \n
    Input: temperatures = [30,60,90]\nOutput: [1,1,0]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= temperatures.length <= 105
    • \n\t
    • 30 <= temperatures[i] <= 100
    • \n
    \n", "content_cn": "

    \u8bf7\u6839\u636e\u6bcf\u65e5 \u6c14\u6e29 \u5217\u8868\uff0c\u91cd\u65b0\u751f\u6210\u4e00\u4e2a\u5217\u8868\u3002\u5bf9\u5e94\u4f4d\u7f6e\u7684\u8f93\u51fa\u4e3a\uff1a\u8981\u60f3\u89c2\u6d4b\u5230\u66f4\u9ad8\u7684\u6c14\u6e29\uff0c\u81f3\u5c11\u9700\u8981\u7b49\u5f85\u7684\u5929\u6570\u3002\u5982\u679c\u6c14\u6e29\u5728\u8fd9\u4e4b\u540e\u90fd\u4e0d\u4f1a\u5347\u9ad8\uff0c\u8bf7\u5728\u8be5\u4f4d\u7f6e\u7528 0 \u6765\u4ee3\u66ff\u3002

    \n\n

    \u4f8b\u5982\uff0c\u7ed9\u5b9a\u4e00\u4e2a\u5217\u8868 temperatures = [73, 74, 75, 71, 69, 72, 76, 73]\uff0c\u4f60\u7684\u8f93\u51fa\u5e94\u8be5\u662f [1, 1, 4, 2, 1, 1, 0, 0]\u3002

    \n\n

    \u63d0\u793a\uff1a\u6c14\u6e29 \u5217\u8868\u957f\u5ea6\u7684\u8303\u56f4\u662f [1, 30000]\u3002\u6bcf\u4e2a\u6c14\u6e29\u7684\u503c\u7684\u5747\u4e3a\u534e\u6c0f\u5ea6\uff0c\u90fd\u662f\u5728 [30, 100] \u8303\u56f4\u5185\u7684\u6574\u6570\u3002

    \n", "tags_en": ["Stack", "Hash Table"], "tags_cn": ["\u6808", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector dailyTemperatures(vector& temperatures) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] dailyTemperatures(int[] temperatures) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def dailyTemperatures(self, temperatures):\n \"\"\"\n :type temperatures: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def dailyTemperatures(self, temperatures: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* dailyTemperatures(int* temperatures, int temperaturesSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] DailyTemperatures(int[] temperatures) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} temperatures\n * @return {number[]}\n */\nvar dailyTemperatures = function(temperatures) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} temperatures\n# @return {Integer[]}\ndef daily_temperatures(temperatures)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func dailyTemperatures(_ temperatures: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func dailyTemperatures(temperatures []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def dailyTemperatures(temperatures: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun dailyTemperatures(temperatures: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn daily_temperatures(temperatures: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $temperatures\n * @return Integer[]\n */\n function dailyTemperatures($temperatures) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function dailyTemperatures(temperatures: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (daily-temperatures temperatures)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0739](https://leetcode-cn.com/problems/daily-temperatures)", "[\u6bcf\u65e5\u6e29\u5ea6](/solution/0700-0799/0739.Daily%20Temperatures/README.md)", "`\u6808`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0739](https://leetcode.com/problems/daily-temperatures)", "[Daily Temperatures](/solution/0700-0799/0739.Daily%20Temperatures/README_EN.md)", "`Stack`,`Hash Table`", "Medium", ""]}, {"question_id": "0738", "frontend_question_id": "0738", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/monotone-increasing-digits", "url_en": "https://leetcode.com/problems/monotone-increasing-digits", "relative_path_cn": "/solution/0700-0799/0738.Monotone%20Increasing%20Digits/README.md", "relative_path_en": "/solution/0700-0799/0738.Monotone%20Increasing%20Digits/README_EN.md", "title_cn": "\u5355\u8c03\u9012\u589e\u7684\u6570\u5b57", "title_en": "Monotone Increasing Digits", "question_title_slug": "monotone-increasing-digits", "content_en": "

    An integer has monotone increasing digits if and only if each pair of adjacent digits x and y satisfy x <= y.

    \n\n

    Given an integer n, return the largest number that is less than or equal to n with monotone increasing digits.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 10\nOutput: 9\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 1234\nOutput: 1234\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 332\nOutput: 299\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= n <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u8d1f\u6574\u6570 N\uff0c\u627e\u51fa\u5c0f\u4e8e\u6216\u7b49\u4e8e N \u7684\u6700\u5927\u7684\u6574\u6570\uff0c\u540c\u65f6\u8fd9\u4e2a\u6574\u6570\u9700\u8981\u6ee1\u8db3\u5176\u5404\u4e2a\u4f4d\u6570\u4e0a\u7684\u6570\u5b57\u662f\u5355\u8c03\u9012\u589e\u3002

    \n\n

    \uff08\u5f53\u4e14\u4ec5\u5f53\u6bcf\u4e2a\u76f8\u90bb\u4f4d\u6570\u4e0a\u7684\u6570\u5b57 x \u548c y \u6ee1\u8db3 x <= y \u65f6\uff0c\u6211\u4eec\u79f0\u8fd9\u4e2a\u6574\u6570\u662f\u5355\u8c03\u9012\u589e\u7684\u3002\uff09

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: N = 10\n\u8f93\u51fa: 9\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: N = 1234\n\u8f93\u51fa: 1234\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u8f93\u5165: N = 332\n\u8f93\u51fa: 299\n
    \n\n

    \u8bf4\u660e: N \u662f\u5728 [0, 10^9] \u8303\u56f4\u5185\u7684\u4e00\u4e2a\u6574\u6570\u3002

    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int monotoneIncreasingDigits(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int monotoneIncreasingDigits(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def monotoneIncreasingDigits(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def monotoneIncreasingDigits(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint monotoneIncreasingDigits(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MonotoneIncreasingDigits(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar monotoneIncreasingDigits = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef monotone_increasing_digits(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func monotoneIncreasingDigits(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func monotoneIncreasingDigits(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def monotoneIncreasingDigits(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun monotoneIncreasingDigits(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn monotone_increasing_digits(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function monotoneIncreasingDigits($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function monotoneIncreasingDigits(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (monotone-increasing-digits n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0738](https://leetcode-cn.com/problems/monotone-increasing-digits)", "[\u5355\u8c03\u9012\u589e\u7684\u6570\u5b57](/solution/0700-0799/0738.Monotone%20Increasing%20Digits/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0738](https://leetcode.com/problems/monotone-increasing-digits)", "[Monotone Increasing Digits](/solution/0700-0799/0738.Monotone%20Increasing%20Digits/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "0737", "frontend_question_id": "0737", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/sentence-similarity-ii", "url_en": "https://leetcode.com/problems/sentence-similarity-ii", "relative_path_cn": "/solution/0700-0799/0737.Sentence%20Similarity%20II/README.md", "relative_path_en": "/solution/0700-0799/0737.Sentence%20Similarity%20II/README_EN.md", "title_cn": "\u53e5\u5b50\u76f8\u4f3c\u6027 II", "title_en": "Sentence Similarity II", "question_title_slug": "sentence-similarity-ii", "content_en": "

    We can represent a sentence as an array of words, for example, the sentence "I am happy with leetcode" can be represented as arr = ["I","am",happy","with","leetcode"].

    \n\n

    Given two sentences sentence1 and sentence2 each represented as a string array and given an array of string pairs similarPairs where similarPairs[i] = [xi, yi] indicates that the two words xi and yi are similar.

    \n\n

    Return true if sentence1 and sentence2 are similar, or false if they are not similar.

    \n\n

    Two sentences are similar if:

    \n\n
      \n\t
    • They have the same length (i.e., the same number of words)
    • \n\t
    • sentence1[i] and sentence2[i] are similar.
    • \n
    \n\n

    Notice that a word is always similar to itself, also notice that the similarity relation is transitive. For example, if the words a and b are similar, and the words b and c are similar, then a and c are similar.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: sentence1 = ["great","acting","skills"], sentence2 = ["fine","drama","talent"], similarPairs = [["great","good"],["fine","good"],["drama","acting"],["skills","talent"]]\nOutput: true\nExplanation: The two sentences have the same length and each word i of sentence1 is also similar to the corresponding word in sentence2.\n
    \n\n

    Example 2:

    \n\n
    \nInput: sentence1 = ["I","love","leetcode"], sentence2 = ["I","love","onepiece"], similarPairs = [["manga","onepiece"],["platform","anime"],["leetcode","platform"],["anime","manga"]]\nOutput: true\nExplanation: "leetcode" --> "platform" --> "anime" --> "manga" --> "onepiece".\nSince "leetcode is similar to "onepiece" and the first two words are the same, the two sentences are similar.
    \n\n

    Example 3:

    \n\n
    \nInput: sentence1 = ["I","love","leetcode"], sentence2 = ["I","love","onepiece"], similarPairs = [["manga","hunterXhunter"],["platform","anime"],["leetcode","platform"],["anime","manga"]]\nOutput: false\nExplanation: "leetcode" is not similar to "onepiece".\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= sentence1.length, sentence2.length <= 1000
    • \n\t
    • 1 <= sentence1[i].length, sentence2[i].length <= 20
    • \n\t
    • sentence1[i] and sentence2[i] consist of lower-case and upper-case English letters.
    • \n\t
    • 0 <= similarPairs.length <= 2000
    • \n\t
    • similarPairs[i].length == 2
    • \n\t
    • 1 <= xi.length, yi.length <= 20
    • \n\t
    • xi and yi consist of English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u53e5\u5b50 words1, words2 \uff08\u6bcf\u4e2a\u7528\u5b57\u7b26\u4e32\u6570\u7ec4\u8868\u793a\uff09\uff0c\u548c\u4e00\u4e2a\u76f8\u4f3c\u5355\u8bcd\u5bf9\u7684\u5217\u8868 pairs \uff0c\u5224\u65ad\u662f\u5426\u4e24\u4e2a\u53e5\u5b50\u662f\u76f8\u4f3c\u7684\u3002

    \n\n

    \u4f8b\u5982\uff0c\u5f53\u76f8\u4f3c\u5355\u8bcd\u5bf9\u662f pairs = [["great", "fine"], ["acting","drama"], ["skills","talent"]]\u7684\u65f6\u5019\uff0cwords1 = ["great", "acting", "skills"] \u548c words2 = ["fine", "drama", "talent"] \u662f\u76f8\u4f3c\u7684\u3002

    \n\n

    \u6ce8\u610f\u76f8\u4f3c\u5173\u7cfb\u662f \u5177\u6709 \u4f20\u9012\u6027\u7684\u3002\u4f8b\u5982\uff0c\u5982\u679c "great" \u548c "fine" \u662f\u76f8\u4f3c\u7684\uff0c"fine" \u548c "good" \u662f\u76f8\u4f3c\u7684\uff0c\u5219 "great" \u548c "good" \u662f\u76f8\u4f3c\u7684\u3002

    \n\n

    \u800c\u4e14\uff0c\u76f8\u4f3c\u5173\u7cfb\u662f\u5177\u6709\u5bf9\u79f0\u6027\u7684\u3002\u4f8b\u5982\uff0c"great" \u548c "fine" \u662f\u76f8\u4f3c\u7684\u76f8\u5f53\u4e8e "fine" \u548c "great" \u662f\u76f8\u4f3c\u7684\u3002

    \n\n

    \u5e76\u4e14\uff0c\u4e00\u4e2a\u5355\u8bcd\u603b\u662f\u4e0e\u5176\u81ea\u8eab\u76f8\u4f3c\u3002\u4f8b\u5982\uff0c\u53e5\u5b50 words1 = ["great"], words2 = ["great"], pairs = [] \u662f\u76f8\u4f3c\u7684\uff0c\u5c3d\u7ba1\u6ca1\u6709\u8f93\u5165\u7279\u5b9a\u7684\u76f8\u4f3c\u5355\u8bcd\u5bf9\u3002

    \n\n

    \u6700\u540e\uff0c\u53e5\u5b50\u53ea\u4f1a\u5728\u5177\u6709\u76f8\u540c\u5355\u8bcd\u4e2a\u6570\u7684\u524d\u63d0\u4e0b\u624d\u4f1a\u76f8\u4f3c\u3002\u6240\u4ee5\u4e00\u4e2a\u53e5\u5b50 words1 = ["great"] \u6c38\u8fdc\u4e0d\u53ef\u80fd\u548c\u53e5\u5b50 words2 = ["doubleplus","good"] \u76f8\u4f3c\u3002

    \n\n

    \u6ce8\uff1a

    \n\n
      \n\t
    • words1 and words2 \u7684\u957f\u5ea6\u4e0d\u4f1a\u8d85\u8fc7 1000\u3002
    • \n\t
    • pairs \u7684\u957f\u5ea6\u4e0d\u4f1a\u8d85\u8fc7 2000\u3002
    • \n\t
    • \u6bcf\u4e2apairs[i] \u7684\u957f\u5ea6\u4e3a 2\u3002
    • \n\t
    • \u6bcf\u4e2a words[i] \u548c pairs[i][j] \u7684\u957f\u5ea6\u8303\u56f4\u4e3a [1, 20]\u3002
    • \n
    \n", "tags_en": ["Depth-first Search", "Union Find"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e76\u67e5\u96c6"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool areSentencesSimilarTwo(vector& sentence1, vector& sentence2, vector>& similarPairs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean areSentencesSimilarTwo(String[] sentence1, String[] sentence2, List> similarPairs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def areSentencesSimilarTwo(self, sentence1, sentence2, similarPairs):\n \"\"\"\n :type sentence1: List[str]\n :type sentence2: List[str]\n :type similarPairs: List[List[str]]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def areSentencesSimilarTwo(self, sentence1: List[str], sentence2: List[str], similarPairs: List[List[str]]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool areSentencesSimilarTwo(char ** sentence1, int sentence1Size, char ** sentence2, int sentence2Size, char *** similarPairs, int similarPairsSize, int* similarPairsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool AreSentencesSimilarTwo(string[] sentence1, string[] sentence2, IList> similarPairs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} sentence1\n * @param {string[]} sentence2\n * @param {string[][]} similarPairs\n * @return {boolean}\n */\nvar areSentencesSimilarTwo = function(sentence1, sentence2, similarPairs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} sentence1\n# @param {String[]} sentence2\n# @param {String[][]} similar_pairs\n# @return {Boolean}\ndef are_sentences_similar_two(sentence1, sentence2, similar_pairs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func areSentencesSimilarTwo(_ sentence1: [String], _ sentence2: [String], _ similarPairs: [[String]]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func areSentencesSimilarTwo(sentence1 []string, sentence2 []string, similarPairs [][]string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def areSentencesSimilarTwo(sentence1: Array[String], sentence2: Array[String], similarPairs: List[List[String]]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun areSentencesSimilarTwo(sentence1: Array, sentence2: Array, similarPairs: List>): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn are_sentences_similar_two(sentence1: Vec, sentence2: Vec, similar_pairs: Vec>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $sentence1\n * @param String[] $sentence2\n * @param String[][] $similarPairs\n * @return Boolean\n */\n function areSentencesSimilarTwo($sentence1, $sentence2, $similarPairs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function areSentencesSimilarTwo(sentence1: string[], sentence2: string[], similarPairs: string[][]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (are-sentences-similar-two sentence1 sentence2 similarPairs)\n (-> (listof string?) (listof string?) (listof (listof string?)) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0737](https://leetcode-cn.com/problems/sentence-similarity-ii)", "[\u53e5\u5b50\u76f8\u4f3c\u6027 II](/solution/0700-0799/0737.Sentence%20Similarity%20II/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e76\u67e5\u96c6`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0737](https://leetcode.com/problems/sentence-similarity-ii)", "[Sentence Similarity II](/solution/0700-0799/0737.Sentence%20Similarity%20II/README_EN.md)", "`Depth-first Search`,`Union Find`", "Medium", "\ud83d\udd12"]}, {"question_id": "0736", "frontend_question_id": "0736", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/parse-lisp-expression", "url_en": "https://leetcode.com/problems/parse-lisp-expression", "relative_path_cn": "/solution/0700-0799/0736.Parse%20Lisp%20Expression/README.md", "relative_path_en": "/solution/0700-0799/0736.Parse%20Lisp%20Expression/README_EN.md", "title_cn": "Lisp \u8bed\u6cd5\u89e3\u6790", "title_en": "Parse Lisp Expression", "question_title_slug": "parse-lisp-expression", "content_en": "

    \r\nYou are given a string expression representing a Lisp-like expression to return the integer value of.\r\n

    \r\nThe syntax for these expressions is given as follows.\r\n

    \r\n

  • An expression is either an integer, a let-expression, an add-expression, a mult-expression, or an assigned variable. Expressions always evaluate to a single integer.
  • \r\n

    \r\n

  • (An integer could be positive or negative.)
  • \r\n

    \r\n

  • A let-expression takes the form (let v1 e1 v2 e2 ... vn en expr), where let is always the string \"let\", then there are 1 or more pairs of alternating variables and expressions, meaning that the first variable v1 is assigned the value of the expression e1, the second variable v2 is assigned the value of the expression e2, and so on sequentially; and then the value of this let-expression is the value of the expression expr.
  • \r\n

    \r\n

  • An add-expression takes the form (add e1 e2) where add is always the string \"add\", there are always two expressions e1, e2, and this expression evaluates to the addition of the evaluation of e1 and the evaluation of e2.
  • \r\n

    \r\n

  • A mult-expression takes the form (mult e1 e2) where mult is always the string \"mult\", there are always two expressions e1, e2, and this expression evaluates to the multiplication of the evaluation of e1 and the evaluation of e2.
  • \r\n

    \r\n

  • For the purposes of this question, we will use a smaller subset of variable names. A variable starts with a lowercase letter, then zero or more lowercase letters or digits. Additionally for your convenience, the names \"add\", \"let\", or \"mult\" are protected and will never be used as variable names.
  • \r\n

    \r\n

  • Finally, there is the concept of scope. When an expression of a variable name is evaluated, within the context of that evaluation, the innermost scope (in terms of parentheses) is checked first for the value of that variable, and then outer scopes are checked sequentially. It is guaranteed that every expression is legal. Please see the examples for more details on scope.
  • \r\n

    \r\n\r\n

    Evaluation Examples:
    \r\n

    \r\nInput: (add 1 2)\r\nOutput: 3\r\n\r\nInput: (mult 3 (add 2 3))\r\nOutput: 15\r\n\r\nInput: (let x 2 (mult x 5))\r\nOutput: 10\r\n\r\nInput: (let x 2 (mult x (let x 3 y 4 (add x y))))\r\nOutput: 14\r\nExplanation: In the expression (add x y), when checking for the value of the variable x,\r\nwe check from the innermost scope to the outermost in the context of the variable we are trying to evaluate.\r\nSince x = 3 is found first, the value of x is 3.\r\n\r\nInput: (let x 3 x 2 x)\r\nOutput: 2\r\nExplanation: Assignment in let statements is processed sequentially.\r\n\r\nInput: (let x 1 y 2 x (add x y) (add x y))\r\nOutput: 5\r\nExplanation: The first (add x y) evaluates as 3, and is assigned to x.\r\nThe second (add x y) evaluates as 3+2 = 5.\r\n\r\nInput: (let x 2 (add (let x 3 (let x 4 x)) x))\r\nOutput: 6\r\nExplanation: Even though (let x 4 x) has a deeper scope, it is outside the context\r\nof the final x in the add-expression.  That final x will equal 2.\r\n\r\nInput: (let a1 3 b2 (add a1 1) b2) \r\nOutput 4\r\nExplanation: Variable names can contain digits after the first character.\r\n\r\n
    \r\n\r\n

    Note:\r\n

  • The given string expression is well formatted: There are no leading or trailing spaces, there is only a single space separating different components of the string, and no space between adjacent parentheses. The expression is guaranteed to be legal and evaluate to an integer.
  • \r\n
  • The length of expression is at most 2000. (It is also non-empty, as that would not be a legal expression.)
  • \r\n
  • The answer and all intermediate calculations of that answer are guaranteed to fit in a 32-bit integer.
  • \r\n

    ", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u7c7b\u4f3c Lisp \u8bed\u53e5\u7684\u8868\u8fbe\u5f0f expression\uff0c\u6c42\u51fa\u5176\u8ba1\u7b97\u7ed3\u679c\u3002

    \n\n

    \u8868\u8fbe\u5f0f\u8bed\u6cd5\u5982\u4e0b\u6240\u793a:

    \n\n
      \n\t
    • \u8868\u8fbe\u5f0f\u53ef\u4ee5\u4e3a\u6574\u6570\uff0clet \u8bed\u6cd5\uff0cadd \u8bed\u6cd5\uff0cmult \u8bed\u6cd5\uff0c\u6216\u8d4b\u503c\u7684\u53d8\u91cf\u3002\u8868\u8fbe\u5f0f\u7684\u7ed3\u679c\u603b\u662f\u4e00\u4e2a\u6574\u6570\u3002
    • \n\t
    • (\u6574\u6570\u53ef\u4ee5\u662f\u6b63\u6574\u6570\u3001\u8d1f\u6574\u6570\u30010)
    • \n\t
    • let \u8bed\u6cd5\u8868\u793a\u4e3a (let v1 e1 v2 e2 ... vn en expr), \u5176\u4e2d let\u8bed\u6cd5\u603b\u662f\u4ee5\u5b57\u7b26\u4e32 "let"\u6765\u8868\u793a\uff0c\u63a5\u4e0b\u6765\u4f1a\u8ddf\u968f\u4e00\u4e2a\u6216\u591a\u4e2a\u4ea4\u66ff\u53d8\u91cf\u6216\u8868\u8fbe\u5f0f\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u7b2c\u4e00\u4e2a\u53d8\u91cf v1\u88ab\u5206\u914d\u4e3a\u8868\u8fbe\u5f0f e1 \u7684\u503c\uff0c\u7b2c\u4e8c\u4e2a\u53d8\u91cf v2 \u88ab\u5206\u914d\u4e3a\u8868\u8fbe\u5f0f e2 \u7684\u503c\uff0c\u4ee5\u6b64\u7c7b\u63a8\uff1b\u6700\u7ec8 let \u8bed\u6cd5\u7684\u503c\u4e3a expr\u8868\u8fbe\u5f0f\u7684\u503c\u3002
    • \n\t
    • add \u8bed\u6cd5\u8868\u793a\u4e3a (add e1 e2)\uff0c\u5176\u4e2d add \u8bed\u6cd5\u603b\u662f\u4ee5\u5b57\u7b26\u4e32 "add"\u6765\u8868\u793a\uff0c\u8be5\u8bed\u6cd5\u603b\u662f\u6709\u4e24\u4e2a\u8868\u8fbe\u5f0fe1\u3001e2, \u8be5\u8bed\u6cd5\u7684\u6700\u7ec8\u7ed3\u679c\u662f e1 \u8868\u8fbe\u5f0f\u7684\u503c\u4e0e e2 \u8868\u8fbe\u5f0f\u7684\u503c\u4e4b\u548c\u3002
    • \n\t
    • mult \u8bed\u6cd5\u8868\u793a\u4e3a (mult e1 e2) \uff0c\u5176\u4e2d mult \u8bed\u6cd5\u603b\u662f\u4ee5\u5b57\u7b26\u4e32"mult"\u8868\u793a\uff0c \u8be5\u8bed\u6cd5\u603b\u662f\u6709\u4e24\u4e2a\u8868\u8fbe\u5f0f e1\u3001e2\uff0c\u8be5\u8bed\u6cd5\u7684\u6700\u7ec8\u7ed3\u679c\u662f e1 \u8868\u8fbe\u5f0f\u7684\u503c\u4e0e e2 \u8868\u8fbe\u5f0f\u7684\u503c\u4e4b\u79ef\u3002
    • \n\t
    • \u5728\u8be5\u9898\u76ee\u4e2d\uff0c\u53d8\u91cf\u7684\u547d\u540d\u4ee5\u5c0f\u5199\u5b57\u7b26\u5f00\u59cb\uff0c\u4e4b\u540e\u8ddf\u968f0\u4e2a\u6216\u591a\u4e2a\u5c0f\u5199\u5b57\u7b26\u6216\u6570\u5b57\u3002\u4e3a\u4e86\u65b9\u4fbf\uff0c"add"\uff0c"let"\uff0c"mult"\u4f1a\u88ab\u5b9a\u4e49\u4e3a"\u5173\u952e\u5b57"\uff0c\u4e0d\u4f1a\u5728\u8868\u8fbe\u5f0f\u7684\u53d8\u91cf\u547d\u540d\u4e2d\u51fa\u73b0\u3002
    • \n\t
    • \u6700\u540e\uff0c\u8981\u8bf4\u4e00\u4e0b\u4f5c\u7528\u57df\u7684\u6982\u5ff5\u3002\u8ba1\u7b97\u53d8\u91cf\u540d\u6240\u5bf9\u5e94\u7684\u8868\u8fbe\u5f0f\u65f6\uff0c\u5728\u8ba1\u7b97\u4e0a\u4e0b\u6587\u4e2d\uff0c\u9996\u5148\u68c0\u67e5\u6700\u5185\u5c42\u4f5c\u7528\u57df\uff08\u6309\u62ec\u53f7\u8ba1\uff09\uff0c\u7136\u540e\u6309\u987a\u5e8f\u4f9d\u6b21\u68c0\u67e5\u5916\u90e8\u4f5c\u7528\u57df\u3002\u6211\u4eec\u5c06\u4fdd\u8bc1\u6bcf\u4e00\u4e2a\u6d4b\u8bd5\u7684\u8868\u8fbe\u5f0f\u90fd\u662f\u5408\u6cd5\u7684\u3002\u6709\u5173\u4f5c\u7528\u57df\u7684\u66f4\u591a\u8be6\u7ec6\u4fe1\u606f\uff0c\u8bf7\u53c2\u9605\u793a\u4f8b\u3002
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165: (add 1 2)\n\u8f93\u51fa: 3\n\n\u8f93\u5165: (mult 3 (add 2 3))\n\u8f93\u51fa: 15\n\n\u8f93\u5165: (let x 2 (mult x 5))\n\u8f93\u51fa: 10\n\n\u8f93\u5165: (let x 2 (mult x (let x 3 y 4 (add x y))))\n\u8f93\u51fa: 14\n\u89e3\u91ca: \n\u8868\u8fbe\u5f0f (add x y), \u5728\u83b7\u53d6 x \u503c\u65f6, \u6211\u4eec\u5e94\u5f53\u7531\u6700\u5185\u5c42\u4f9d\u6b21\u5411\u5916\u8ba1\u7b97, \u9996\u5148\u9047\u5230\u4e86 x=3, \u6240\u4ee5\u6b64\u5904\u7684 x \u503c\u662f 3.\n\n\n\u8f93\u5165: (let x 3 x 2 x)\n\u8f93\u51fa: 2\n\u89e3\u91ca: let \u8bed\u53e5\u4e2d\u7684\u8d4b\u503c\u8fd0\u7b97\u6309\u987a\u5e8f\u5904\u7406\u5373\u53ef\n\n\u8f93\u5165: (let x 1 y 2 x (add x y) (add x y))\n\u8f93\u51fa: 5\n\u89e3\u91ca: \n\u7b2c\u4e00\u4e2a (add x y) \u8ba1\u7b97\u7ed3\u679c\u662f 3\uff0c\u5e76\u4e14\u5c06\u6b64\u503c\u8d4b\u7ed9\u4e86 x \u3002\n\u7b2c\u4e8c\u4e2a (add x y) \u8ba1\u7b97\u7ed3\u679c\u5c31\u662f 3+2 = 5 \u3002\n\n\u8f93\u5165: (let x 2 (add (let x 3 (let x 4 x)) x))\n\u8f93\u51fa: 6\n\u89e3\u91ca: \n(let x 4 x) \u4e2d\u7684 x \u7684\u4f5c\u7528\u57df\u4ec5\u5728()\u4e4b\u5185\u3002\u6240\u4ee5\u6700\u7ec8\u505a\u52a0\u6cd5\u64cd\u4f5c\u65f6\uff0cx \u7684\u503c\u662f 2 \u3002\n\n\u8f93\u5165: (let a1 3 b2 (add a1 1) b2) \n\u8f93\u51fa: 4\n\u89e3\u91ca: \n\u53d8\u91cf\u547d\u540d\u65f6\u53ef\u4ee5\u5728\u7b2c\u4e00\u4e2a\u5c0f\u5199\u5b57\u6bcd\u540e\u8ddf\u968f\u6570\u5b57.\n
    \n\n

     

    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    • \u6211\u4eec\u7ed9\u5b9a\u7684 expression \u8868\u8fbe\u5f0f\u90fd\u662f\u683c\u5f0f\u5316\u540e\u7684\uff1a\u8868\u8fbe\u5f0f\u524d\u540e\u6ca1\u6709\u591a\u4f59\u7684\u7a7a\u683c\uff0c\u8868\u8fbe\u5f0f\u7684\u4e0d\u540c\u90e8\u5206(\u5173\u952e\u5b57\u3001\u53d8\u91cf\u3001\u8868\u8fbe\u5f0f)\u4e4b\u95f4\u4ec5\u4f7f\u7528\u4e00\u4e2a\u7a7a\u683c\u5206\u5272\uff0c\u5e76\u4e14\u5728\u76f8\u90bb\u62ec\u53f7\u4e4b\u95f4\u4e5f\u6ca1\u6709\u7a7a\u683c\u3002\u6211\u4eec\u7ed9\u5b9a\u7684\u8868\u8fbe\u5f0f\u5747\u4e3a\u5408\u6cd5\u7684\u4e14\u6700\u7ec8\u7ed3\u679c\u4e3a\u6574\u6570\u3002
    • \n\t
    • \u6211\u4eec\u7ed9\u5b9a\u7684\u8868\u8fbe\u5f0f\u957f\u5ea6\u6700\u591a\u4e3a 2000 (\u8868\u8fbe\u5f0f\u4e5f\u4e0d\u4f1a\u4e3a\u7a7a\uff0c\u56e0\u4e3a\u90a3\u4e0d\u662f\u4e00\u4e2a\u5408\u6cd5\u7684\u8868\u8fbe\u5f0f)\u3002
    • \n\t
    • \u6700\u7ec8\u7684\u7ed3\u679c\u548c\u4e2d\u95f4\u7684\u8ba1\u7b97\u7ed3\u679c\u90fd\u5c06\u662f\u4e00\u4e2a 32 \u4f4d\u6574\u6570\u3002
    • \n
    \n\n

     

    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int evaluate(string expression) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int evaluate(String expression) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def evaluate(self, expression):\n \"\"\"\n :type expression: str\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def evaluate(self, expression: str) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint evaluate(char * expression){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int Evaluate(string expression) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} expression\n * @return {number}\n */\nvar evaluate = function(expression) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} expression\n# @return {Integer}\ndef evaluate(expression)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func evaluate(_ expression: String) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func evaluate(expression string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def evaluate(expression: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun evaluate(expression: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn evaluate(expression: String) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $expression\n * @return Integer\n */\n function evaluate($expression) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function evaluate(expression: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (evaluate expression)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0736](https://leetcode-cn.com/problems/parse-lisp-expression)", "[Lisp \u8bed\u6cd5\u89e3\u6790](/solution/0700-0799/0736.Parse%20Lisp%20Expression/README.md)", "`\u5b57\u7b26\u4e32`", "\u56f0\u96be", ""], "md_table_row_en": ["[0736](https://leetcode.com/problems/parse-lisp-expression)", "[Parse Lisp Expression](/solution/0700-0799/0736.Parse%20Lisp%20Expression/README_EN.md)", "`String`", "Hard", ""]}, {"question_id": "0735", "frontend_question_id": "0735", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/asteroid-collision", "url_en": "https://leetcode.com/problems/asteroid-collision", "relative_path_cn": "/solution/0700-0799/0735.Asteroid%20Collision/README.md", "relative_path_en": "/solution/0700-0799/0735.Asteroid%20Collision/README_EN.md", "title_cn": "\u884c\u661f\u78b0\u649e", "title_en": "Asteroid Collision", "question_title_slug": "asteroid-collision", "content_en": "

    We are given an array asteroids of integers representing asteroids in a row.

    \n\n

    For each asteroid, the absolute value represents its size, and the sign represents its direction (positive meaning right, negative meaning left). Each asteroid moves at the same speed.

    \n\n

    Find out the state of the asteroids after all collisions. If two asteroids meet, the smaller one will explode. If both are the same size, both will explode. Two asteroids moving in the same direction will never meet.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: asteroids = [5,10,-5]\nOutput: [5,10]\nExplanation: The 10 and -5 collide resulting in 10. The 5 and 10 never collide.\n
    \n\n

    Example 2:

    \n\n
    \nInput: asteroids = [8,-8]\nOutput: []\nExplanation: The 8 and -8 collide exploding each other.\n
    \n\n

    Example 3:

    \n\n
    \nInput: asteroids = [10,2,-5]\nOutput: [10]\nExplanation: The 2 and -5 collide resulting in -5. The 10 and -5 collide resulting in 10.\n
    \n\n

    Example 4:

    \n\n
    \nInput: asteroids = [-2,-1,1,2]\nOutput: [-2,-1,1,2]\nExplanation: The -2 and -1 are moving left, while the 1 and 2 are moving right. Asteroids moving the same direction never meet, so no asteroids will meet each other.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= asteroids.length <= 104
    • \n\t
    • -1000 <= asteroids[i] <= 1000
    • \n\t
    • asteroids[i] != 0
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 asteroids\uff0c\u8868\u793a\u5728\u540c\u4e00\u884c\u7684\u884c\u661f\u3002

    \n\n

    \u5bf9\u4e8e\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e00\u4e2a\u5143\u7d20\uff0c\u5176\u7edd\u5bf9\u503c\u8868\u793a\u884c\u661f\u7684\u5927\u5c0f\uff0c\u6b63\u8d1f\u8868\u793a\u884c\u661f\u7684\u79fb\u52a8\u65b9\u5411\uff08\u6b63\u8868\u793a\u5411\u53f3\u79fb\u52a8\uff0c\u8d1f\u8868\u793a\u5411\u5de6\u79fb\u52a8\uff09\u3002\u6bcf\u4e00\u9897\u884c\u661f\u4ee5\u76f8\u540c\u7684\u901f\u5ea6\u79fb\u52a8\u3002

    \n\n

    \u627e\u51fa\u78b0\u649e\u540e\u5269\u4e0b\u7684\u6240\u6709\u884c\u661f\u3002\u78b0\u649e\u89c4\u5219\uff1a\u4e24\u4e2a\u884c\u661f\u76f8\u4e92\u78b0\u649e\uff0c\u8f83\u5c0f\u7684\u884c\u661f\u4f1a\u7206\u70b8\u3002\u5982\u679c\u4e24\u9897\u884c\u661f\u5927\u5c0f\u76f8\u540c\uff0c\u5219\u4e24\u9897\u884c\u661f\u90fd\u4f1a\u7206\u70b8\u3002\u4e24\u9897\u79fb\u52a8\u65b9\u5411\u76f8\u540c\u7684\u884c\u661f\uff0c\u6c38\u8fdc\u4e0d\u4f1a\u53d1\u751f\u78b0\u649e\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aasteroids = [5,10,-5]\n\u8f93\u51fa\uff1a[5,10]\n\u89e3\u91ca\uff1a10 \u548c -5 \u78b0\u649e\u540e\u53ea\u5269\u4e0b 10 \u3002 5 \u548c 10 \u6c38\u8fdc\u4e0d\u4f1a\u53d1\u751f\u78b0\u649e\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aasteroids = [8,-8]\n\u8f93\u51fa\uff1a[]\n\u89e3\u91ca\uff1a8 \u548c -8 \u78b0\u649e\u540e\uff0c\u4e24\u8005\u90fd\u53d1\u751f\u7206\u70b8\u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aasteroids = [10,2,-5]\n\u8f93\u51fa\uff1a[10]\n\u89e3\u91ca\uff1a2 \u548c -5 \u53d1\u751f\u78b0\u649e\u540e\u5269\u4e0b -5 \u300210 \u548c -5 \u53d1\u751f\u78b0\u649e\u540e\u5269\u4e0b 10 \u3002
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1aasteroids = [-2,-1,1,2]\n\u8f93\u51fa\uff1a[-2,-1,1,2]\n\u89e3\u91ca\uff1a-2 \u548c -1 \u5411\u5de6\u79fb\u52a8\uff0c\u800c 1 \u548c 2 \u5411\u53f3\u79fb\u52a8\u3002 \u7531\u4e8e\u79fb\u52a8\u65b9\u5411\u76f8\u540c\u7684\u884c\u661f\u4e0d\u4f1a\u53d1\u751f\u78b0\u649e\uff0c\u6240\u4ee5\u6700\u7ec8\u6ca1\u6709\u884c\u661f\u53d1\u751f\u78b0\u649e\u3002 
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= asteroids.length\u00a0<= 104
    • \n\t
    • -1000 <= asteroids[i] <= 1000
    • \n\t
    • asteroids[i] != 0
    • \n
    \n", "tags_en": ["Stack"], "tags_cn": ["\u6808"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector asteroidCollision(vector& asteroids) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] asteroidCollision(int[] asteroids) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def asteroidCollision(self, asteroids):\n \"\"\"\n :type asteroids: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def asteroidCollision(self, asteroids: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* asteroidCollision(int* asteroids, int asteroidsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] AsteroidCollision(int[] asteroids) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} asteroids\n * @return {number[]}\n */\nvar asteroidCollision = function(asteroids) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} asteroids\n# @return {Integer[]}\ndef asteroid_collision(asteroids)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func asteroidCollision(_ asteroids: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func asteroidCollision(asteroids []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def asteroidCollision(asteroids: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun asteroidCollision(asteroids: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn asteroid_collision(asteroids: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $asteroids\n * @return Integer[]\n */\n function asteroidCollision($asteroids) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function asteroidCollision(asteroids: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (asteroid-collision asteroids)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0735](https://leetcode-cn.com/problems/asteroid-collision)", "[\u884c\u661f\u78b0\u649e](/solution/0700-0799/0735.Asteroid%20Collision/README.md)", "`\u6808`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0735](https://leetcode.com/problems/asteroid-collision)", "[Asteroid Collision](/solution/0700-0799/0735.Asteroid%20Collision/README_EN.md)", "`Stack`", "Medium", ""]}, {"question_id": "0734", "frontend_question_id": "0734", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/sentence-similarity", "url_en": "https://leetcode.com/problems/sentence-similarity", "relative_path_cn": "/solution/0700-0799/0734.Sentence%20Similarity/README.md", "relative_path_en": "/solution/0700-0799/0734.Sentence%20Similarity/README_EN.md", "title_cn": "\u53e5\u5b50\u76f8\u4f3c\u6027", "title_en": "Sentence Similarity", "question_title_slug": "sentence-similarity", "content_en": "

    We can represent a sentence as an array of words, for example, the sentence "I am happy with leetcode" can be represented as arr = ["I","am",happy","with","leetcode"].

    \n\n

    Given two sentences sentence1 and sentence2 each represented as a string array and given an array of string pairs similarPairs where similarPairs[i] = [xi, yi] indicates that the two words xi and yi are similar.

    \n\n

    Return true if sentence1 and sentence2 are similar, or false if they are not similar.

    \n\n

    Two sentences are similar if:

    \n\n
      \n\t
    • They have the same length (i.e., the same number of words)
    • \n\t
    • sentence1[i] and sentence2[i] are similar.
    • \n
    \n\n

    Notice that a word is always similar to itself, also notice that the similarity relation is not transitive. For example, if the words a and b are similar, and the words b and c are similar, a and c are not necessarily similar.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: sentence1 = ["great","acting","skills"], sentence2 = ["fine","drama","talent"], similarPairs = [["great","fine"],["drama","acting"],["skills","talent"]]\nOutput: true\nExplanation: The two sentences have the same length and each word i of sentence1 is also similar to the corresponding word in sentence2.\n
    \n\n

    Example 2:

    \n\n
    \nInput: sentence1 = ["great"], sentence2 = ["great"], similarPairs = []\nOutput: true\nExplanation: A word is similar to itself.\n
    \n\n

    Example 3:

    \n\n
    \nInput: sentence1 = ["great"], sentence2 = ["doubleplus","good"], similarPairs = [["great","doubleplus"]]\nOutput: false\nExplanation: As they don't have the same length, we return false.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= sentence1.length, sentence2.length <= 1000
    • \n\t
    • 1 <= sentence1[i].length, sentence2[i].length <= 20
    • \n\t
    • sentence1[i] and sentence2[i] consist of English letters.
    • \n\t
    • 0 <= similarPairs.length <= 1000
    • \n\t
    • similarPairs[i].length == 2
    • \n\t
    • 1 <= xi.length, yi.length <= 20
    • \n\t
    • xi and yi consist of lower-case and upper-case English letters.
    • \n\t
    • All the pairs (xi, yi) are distinct.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u53e5\u5b50 words1, words2 \uff08\u6bcf\u4e2a\u7528\u5b57\u7b26\u4e32\u6570\u7ec4\u8868\u793a\uff09\uff0c\u548c\u4e00\u4e2a\u76f8\u4f3c\u5355\u8bcd\u5bf9\u7684\u5217\u8868 pairs \uff0c\u5224\u65ad\u662f\u5426\u4e24\u4e2a\u53e5\u5b50\u662f\u76f8\u4f3c\u7684\u3002

    \n\n

    \u4f8b\u5982\uff0c\u5f53\u76f8\u4f3c\u5355\u8bcd\u5bf9\u662f pairs = [["great", "fine"], ["acting","drama"], ["skills","talent"]]\u7684\u65f6\u5019\uff0c"great acting skills" \u548c "fine drama talent" \u662f\u76f8\u4f3c\u7684\u3002

    \n\n

    \u6ce8\u610f\u76f8\u4f3c\u5173\u7cfb\u662f\u4e0d\u5177\u6709\u4f20\u9012\u6027\u7684\u3002\u4f8b\u5982\uff0c\u5982\u679c "great" \u548c "fine" \u662f\u76f8\u4f3c\u7684\uff0c"fine" \u548c "good" \u662f\u76f8\u4f3c\u7684\uff0c\u4f46\u662f "great" \u548c "good" \u672a\u5fc5\u662f\u76f8\u4f3c\u7684\u3002

    \n\n

    \u4f46\u662f\uff0c\u76f8\u4f3c\u5173\u7cfb\u662f\u5177\u6709\u5bf9\u79f0\u6027\u7684\u3002\u4f8b\u5982\uff0c"great" \u548c "fine" \u662f\u76f8\u4f3c\u7684\u76f8\u5f53\u4e8e "fine" \u548c "great" \u662f\u76f8\u4f3c\u7684\u3002

    \n\n

    \u800c\u4e14\uff0c\u4e00\u4e2a\u5355\u8bcd\u603b\u662f\u4e0e\u5176\u81ea\u8eab\u76f8\u4f3c\u3002\u4f8b\u5982\uff0c\u53e5\u5b50 words1 = ["great"], words2 = ["great"], pairs = [] \u662f\u76f8\u4f3c\u7684\uff0c\u5c3d\u7ba1\u6ca1\u6709\u8f93\u5165\u7279\u5b9a\u7684\u76f8\u4f3c\u5355\u8bcd\u5bf9\u3002

    \n\n

    \u6700\u540e\uff0c\u53e5\u5b50\u53ea\u4f1a\u5728\u5177\u6709\u76f8\u540c\u5355\u8bcd\u4e2a\u6570\u7684\u524d\u63d0\u4e0b\u624d\u4f1a\u76f8\u4f3c\u3002\u6240\u4ee5\u4e00\u4e2a\u53e5\u5b50 words1 = ["great"] \u6c38\u8fdc\u4e0d\u53ef\u80fd\u548c\u53e5\u5b50 words2 = ["doubleplus","good"] \u76f8\u4f3c\u3002

    \n\n

     

    \n\n

    \u6ce8\uff1a

    \n\n
      \n\t
    • words1 and words2 \u7684\u957f\u5ea6\u4e0d\u4f1a\u8d85\u8fc7 1000\u3002
    • \n\t
    • pairs \u7684\u957f\u5ea6\u4e0d\u4f1a\u8d85\u8fc7 2000\u3002
    • \n\t
    • \u6bcf\u4e2apairs[i] \u7684\u957f\u5ea6\u4e3a 2\u3002
    • \n\t
    • \u6bcf\u4e2a words[i] \u548c pairs[i][j] \u7684\u957f\u5ea6\u8303\u56f4\u4e3a [1, 20]\u3002
    • \n
    \n\n

     

    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool areSentencesSimilar(vector& sentence1, vector& sentence2, vector>& similarPairs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean areSentencesSimilar(String[] sentence1, String[] sentence2, List> similarPairs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def areSentencesSimilar(self, sentence1, sentence2, similarPairs):\n \"\"\"\n :type sentence1: List[str]\n :type sentence2: List[str]\n :type similarPairs: List[List[str]]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def areSentencesSimilar(self, sentence1: List[str], sentence2: List[str], similarPairs: List[List[str]]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool areSentencesSimilar(char ** sentence1, int sentence1Size, char ** sentence2, int sentence2Size, char *** similarPairs, int similarPairsSize, int* similarPairsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool AreSentencesSimilar(string[] sentence1, string[] sentence2, IList> similarPairs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} sentence1\n * @param {string[]} sentence2\n * @param {string[][]} similarPairs\n * @return {boolean}\n */\nvar areSentencesSimilar = function(sentence1, sentence2, similarPairs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} sentence1\n# @param {String[]} sentence2\n# @param {String[][]} similar_pairs\n# @return {Boolean}\ndef are_sentences_similar(sentence1, sentence2, similar_pairs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func areSentencesSimilar(_ sentence1: [String], _ sentence2: [String], _ similarPairs: [[String]]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func areSentencesSimilar(sentence1 []string, sentence2 []string, similarPairs [][]string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def areSentencesSimilar(sentence1: Array[String], sentence2: Array[String], similarPairs: List[List[String]]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun areSentencesSimilar(sentence1: Array, sentence2: Array, similarPairs: List>): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn are_sentences_similar(sentence1: Vec, sentence2: Vec, similar_pairs: Vec>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $sentence1\n * @param String[] $sentence2\n * @param String[][] $similarPairs\n * @return Boolean\n */\n function areSentencesSimilar($sentence1, $sentence2, $similarPairs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function areSentencesSimilar(sentence1: string[], sentence2: string[], similarPairs: string[][]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (are-sentences-similar sentence1 sentence2 similarPairs)\n (-> (listof string?) (listof string?) (listof (listof string?)) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0734](https://leetcode-cn.com/problems/sentence-similarity)", "[\u53e5\u5b50\u76f8\u4f3c\u6027](/solution/0700-0799/0734.Sentence%20Similarity/README.md)", "`\u54c8\u5e0c\u8868`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0734](https://leetcode.com/problems/sentence-similarity)", "[Sentence Similarity](/solution/0700-0799/0734.Sentence%20Similarity/README_EN.md)", "`Hash Table`", "Easy", "\ud83d\udd12"]}, {"question_id": "0733", "frontend_question_id": "0733", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/flood-fill", "url_en": "https://leetcode.com/problems/flood-fill", "relative_path_cn": "/solution/0700-0799/0733.Flood%20Fill/README.md", "relative_path_en": "/solution/0700-0799/0733.Flood%20Fill/README_EN.md", "title_cn": "\u56fe\u50cf\u6e32\u67d3", "title_en": "Flood Fill", "question_title_slug": "flood-fill", "content_en": "

    An image is represented by an m x n integer grid image where image[i][j] represents the pixel value of the image.

    \n\n

    You are also given three integers sr, sc, and newColor. You should perform a flood fill on the image starting from the pixel image[sr][sc].

    \n\n

    To perform a flood fill, consider the starting pixel, plus any pixels connected 4-directionally to the starting pixel of the same color as the starting pixel, plus any pixels connected 4-directionally to those pixels (also with the same color), and so on. Replace the color of all of the aforementioned pixels with newColor.

    \n\n

    Return the modified image after performing the flood fill.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: image = [[1,1,1],[1,1,0],[1,0,1]], sr = 1, sc = 1, newColor = 2\nOutput: [[2,2,2],[2,2,0],[2,0,1]]\nExplanation: From the center of the image with position (sr, sc) = (1, 1) (i.e., the red pixel), all pixels connected by a path of the same color as the starting pixel (i.e., the blue pixels) are colored with the new color.\nNote the bottom corner is not colored 2, because it is not 4-directionally connected to the starting pixel.\n
    \n\n

    Example 2:

    \n\n
    \nInput: image = [[0,0,0],[0,0,0]], sr = 0, sc = 0, newColor = 2\nOutput: [[2,2,2],[2,2,2]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == image.length
    • \n\t
    • n == image[i].length
    • \n\t
    • 1 <= m, n <= 50
    • \n\t
    • 0 <= image[i][j], newColor < 216
    • \n\t
    • 0 <= sr <= m
    • \n\t
    • 0 <= sc <= n
    • \n
    \n", "content_cn": "

    \u6709\u4e00\u5e45\u4ee5\u4e8c\u7ef4\u6574\u6570\u6570\u7ec4\u8868\u793a\u7684\u56fe\u753b\uff0c\u6bcf\u4e00\u4e2a\u6574\u6570\u8868\u793a\u8be5\u56fe\u753b\u7684\u50cf\u7d20\u503c\u5927\u5c0f\uff0c\u6570\u503c\u5728 0 \u5230 65535 \u4e4b\u95f4\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u5750\u6807 (sr, sc) \u8868\u793a\u56fe\u50cf\u6e32\u67d3\u5f00\u59cb\u7684\u50cf\u7d20\u503c\uff08\u884c \uff0c\u5217\uff09\u548c\u4e00\u4e2a\u65b0\u7684\u989c\u8272\u503c newColor\uff0c\u8ba9\u4f60\u91cd\u65b0\u4e0a\u8272\u8fd9\u5e45\u56fe\u50cf\u3002

    \n\n

    \u4e3a\u4e86\u5b8c\u6210\u4e0a\u8272\u5de5\u4f5c\uff0c\u4ece\u521d\u59cb\u5750\u6807\u5f00\u59cb\uff0c\u8bb0\u5f55\u521d\u59cb\u5750\u6807\u7684\u4e0a\u4e0b\u5de6\u53f3\u56db\u4e2a\u65b9\u5411\u4e0a\u50cf\u7d20\u503c\u4e0e\u521d\u59cb\u5750\u6807\u76f8\u540c\u7684\u76f8\u8fde\u50cf\u7d20\u70b9\uff0c\u63a5\u7740\u518d\u8bb0\u5f55\u8fd9\u56db\u4e2a\u65b9\u5411\u4e0a\u7b26\u5408\u6761\u4ef6\u7684\u50cf\u7d20\u70b9\u4e0e\u4ed6\u4eec\u5bf9\u5e94\u56db\u4e2a\u65b9\u5411\u4e0a\u50cf\u7d20\u503c\u4e0e\u521d\u59cb\u5750\u6807\u76f8\u540c\u7684\u76f8\u8fde\u50cf\u7d20\u70b9\uff0c……\uff0c\u91cd\u590d\u8be5\u8fc7\u7a0b\u3002\u5c06\u6240\u6709\u6709\u8bb0\u5f55\u7684\u50cf\u7d20\u70b9\u7684\u989c\u8272\u503c\u6539\u4e3a\u65b0\u7684\u989c\u8272\u503c\u3002

    \n\n

    \u6700\u540e\u8fd4\u56de\u7ecf\u8fc7\u4e0a\u8272\u6e32\u67d3\u540e\u7684\u56fe\u50cf\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: \nimage = [[1,1,1],[1,1,0],[1,0,1]]\nsr = 1, sc = 1, newColor = 2\n\u8f93\u51fa: [[2,2,2],[2,2,0],[2,0,1]]\n\u89e3\u6790: \n\u5728\u56fe\u50cf\u7684\u6b63\u4e2d\u95f4\uff0c(\u5750\u6807(sr,sc)=(1,1)),\n\u5728\u8def\u5f84\u4e0a\u6240\u6709\u7b26\u5408\u6761\u4ef6\u7684\u50cf\u7d20\u70b9\u7684\u989c\u8272\u90fd\u88ab\u66f4\u6539\u62102\u3002\n\u6ce8\u610f\uff0c\u53f3\u4e0b\u89d2\u7684\u50cf\u7d20\u6ca1\u6709\u66f4\u6539\u4e3a2\uff0c\n\u56e0\u4e3a\u5b83\u4e0d\u662f\u5728\u4e0a\u4e0b\u5de6\u53f3\u56db\u4e2a\u65b9\u5411\u4e0a\u4e0e\u521d\u59cb\u70b9\u76f8\u8fde\u7684\u50cf\u7d20\u70b9\u3002\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    • image \u548c image[0] \u7684\u957f\u5ea6\u5728\u8303\u56f4 [1, 50] \u5185\u3002
    • \n\t
    • \u7ed9\u51fa\u7684\u521d\u59cb\u70b9\u5c06\u6ee1\u8db3 0 <= sr < image.length \u548c 0 <= sc < image[0].length\u3002
    • \n\t
    • image[i][j] \u548c newColor \u8868\u793a\u7684\u989c\u8272\u503c\u5728\u8303\u56f4 [0, 65535]\u5185\u3002
    • \n
    \n", "tags_en": ["Depth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> floodFill(vector>& image, int sr, int sc, int newColor) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[][] floodFill(int[][] image, int sr, int sc, int newColor) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def floodFill(self, image, sr, sc, newColor):\n \"\"\"\n :type image: List[List[int]]\n :type sr: int\n :type sc: int\n :type newColor: int\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def floodFill(self, image: List[List[int]], sr: int, sc: int, newColor: int) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** floodFill(int** image, int imageSize, int* imageColSize, int sr, int sc, int newColor, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[][] FloodFill(int[][] image, int sr, int sc, int newColor) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} image\n * @param {number} sr\n * @param {number} sc\n * @param {number} newColor\n * @return {number[][]}\n */\nvar floodFill = function(image, sr, sc, newColor) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} image\n# @param {Integer} sr\n# @param {Integer} sc\n# @param {Integer} new_color\n# @return {Integer[][]}\ndef flood_fill(image, sr, sc, new_color)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func floodFill(_ image: [[Int]], _ sr: Int, _ sc: Int, _ newColor: Int) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func floodFill(image [][]int, sr int, sc int, newColor int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def floodFill(image: Array[Array[Int]], sr: Int, sc: Int, newColor: Int): Array[Array[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun floodFill(image: Array, sr: Int, sc: Int, newColor: Int): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn flood_fill(image: Vec>, sr: i32, sc: i32, new_color: i32) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $image\n * @param Integer $sr\n * @param Integer $sc\n * @param Integer $newColor\n * @return Integer[][]\n */\n function floodFill($image, $sr, $sc, $newColor) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function floodFill(image: number[][], sr: number, sc: number, newColor: number): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (flood-fill image sr sc newColor)\n (-> (listof (listof exact-integer?)) exact-integer? exact-integer? exact-integer? (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0733](https://leetcode-cn.com/problems/flood-fill)", "[\u56fe\u50cf\u6e32\u67d3](/solution/0700-0799/0733.Flood%20Fill/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u7b80\u5355", ""], "md_table_row_en": ["[0733](https://leetcode.com/problems/flood-fill)", "[Flood Fill](/solution/0700-0799/0733.Flood%20Fill/README_EN.md)", "`Depth-first Search`", "Easy", ""]}, {"question_id": "0732", "frontend_question_id": "0732", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/my-calendar-iii", "url_en": "https://leetcode.com/problems/my-calendar-iii", "relative_path_cn": "/solution/0700-0799/0732.My%20Calendar%20III/README.md", "relative_path_en": "/solution/0700-0799/0732.My%20Calendar%20III/README_EN.md", "title_cn": "\u6211\u7684\u65e5\u7a0b\u5b89\u6392\u8868 III", "title_en": "My Calendar III", "question_title_slug": "my-calendar-iii", "content_en": "

    A k-booking happens when k events have some non-empty intersection (i.e., there is some time that is common to all k events.)

    \n\n

    You are given some events [start, end), after each given event, return an integer k representing the maximum k-booking between all the previous events.

    \n\n

    Implement the MyCalendarThree class:

    \n\n
      \n\t
    • MyCalendarThree() Initializes the object.
    • \n\t
    • int book(int start, int end) Returns an integer k representing the largest integer such that there exists a k-booking in the calendar.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["MyCalendarThree", "book", "book", "book", "book", "book", "book"]\n[[], [10, 20], [50, 60], [10, 40], [5, 15], [5, 10], [25, 55]]\nOutput\n[null, 1, 1, 2, 3, 3, 3]\n\nExplanation\nMyCalendarThree myCalendarThree = new MyCalendarThree();\nmyCalendarThree.book(10, 20); // return 1, The first event can be booked and is disjoint, so the maximum k-booking is a 1-booking.\nmyCalendarThree.book(50, 60); // return 1, The second event can be booked and is disjoint, so the maximum k-booking is a 1-booking.\nmyCalendarThree.book(10, 40); // return 2, The third event [10, 40) intersects the first event, and the maximum k-booking is a 2-booking.\nmyCalendarThree.book(5, 15); // return 3, The remaining events cause the maximum K-booking to be only a 3-booking.\nmyCalendarThree.book(5, 10); // return 3\nmyCalendarThree.book(25, 55); // return 3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= start < end <= 109
    • \n\t
    • At most 400 calls will be made to book.
    • \n
    \n", "content_cn": "

    \u5f53 k \u4e2a\u65e5\u7a0b\u5b89\u6392\u6709\u4e00\u4e9b\u65f6\u95f4\u4e0a\u7684\u4ea4\u53c9\u65f6\uff08\u4f8b\u5982 k \u4e2a\u65e5\u7a0b\u5b89\u6392\u90fd\u5728\u540c\u4e00\u65f6\u95f4\u5185\uff09\uff0c\u5c31\u4f1a\u4ea7\u751f k \u6b21\u9884\u8ba2\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e9b\u65e5\u7a0b\u5b89\u6392 [start, end) \uff0c\u8bf7\u4f60\u5728\u6bcf\u4e2a\u65e5\u7a0b\u5b89\u6392\u6dfb\u52a0\u540e\uff0c\u8fd4\u56de\u4e00\u4e2a\u6574\u6570 k \uff0c\u8868\u793a\u6240\u6709\u5148\u524d\u65e5\u7a0b\u5b89\u6392\u4f1a\u4ea7\u751f\u7684\u6700\u5927 k \u6b21\u9884\u8ba2\u3002

    \n\n

    \u5b9e\u73b0\u4e00\u4e2a MyCalendarThree \u7c7b\u6765\u5b58\u653e\u4f60\u7684\u65e5\u7a0b\u5b89\u6392\uff0c\u4f60\u53ef\u4ee5\u4e00\u76f4\u6dfb\u52a0\u65b0\u7684\u65e5\u7a0b\u5b89\u6392\u3002

    \n\n
      \n\t
    • MyCalendarThree() \u521d\u59cb\u5316\u5bf9\u8c61\u3002
    • \n\t
    • int book(int start, int end) \u8fd4\u56de\u4e00\u4e2a\u6574\u6570 k \uff0c\u8868\u793a\u65e5\u5386\u4e2d\u5b58\u5728\u7684 k \u6b21\u9884\u8ba2\u7684\u6700\u5927\u503c\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\n[\"MyCalendarThree\", \"book\", \"book\", \"book\", \"book\", \"book\", \"book\"]\n[[], [10, 20], [50, 60], [10, 40], [5, 15], [5, 10], [25, 55]]\n\u8f93\u51fa\uff1a\n[null, 1, 1, 2, 3, 3, 3]\n\n\u89e3\u91ca\uff1a\nMyCalendarThree myCalendarThree = new MyCalendarThree();\nmyCalendarThree.book(10, 20); // \u8fd4\u56de 1 \uff0c\u7b2c\u4e00\u4e2a\u65e5\u7a0b\u5b89\u6392\u53ef\u4ee5\u9884\u8ba2\u5e76\u4e14\u4e0d\u5b58\u5728\u76f8\u4ea4\uff0c\u6240\u4ee5\u6700\u5927 k \u6b21\u9884\u8ba2\u662f 1 \u6b21\u9884\u8ba2\u3002\nmyCalendarThree.book(50, 60); // \u8fd4\u56de 1 \uff0c\u7b2c\u4e8c\u4e2a\u65e5\u7a0b\u5b89\u6392\u53ef\u4ee5\u9884\u8ba2\u5e76\u4e14\u4e0d\u5b58\u5728\u76f8\u4ea4\uff0c\u6240\u4ee5\u6700\u5927 k \u6b21\u9884\u8ba2\u662f 1 \u6b21\u9884\u8ba2\u3002\nmyCalendarThree.book(10, 40); // \u8fd4\u56de 2 \uff0c\u7b2c\u4e09\u4e2a\u65e5\u7a0b\u5b89\u6392 [10, 40) \u4e0e\u7b2c\u4e00\u4e2a\u65e5\u7a0b\u5b89\u6392\u76f8\u4ea4\uff0c\u6240\u4ee5\u6700\u5927 k \u6b21\u9884\u8ba2\u662f 2 \u6b21\u9884\u8ba2\u3002\nmyCalendarThree.book(5, 15); // \u8fd4\u56de 3 \uff0c\u5269\u4e0b\u7684\u65e5\u7a0b\u5b89\u6392\u7684\u6700\u5927 k \u6b21\u9884\u8ba2\u662f 3 \u6b21\u9884\u8ba2\u3002\nmyCalendarThree.book(5, 10); // \u8fd4\u56de 3\nmyCalendarThree.book(25, 55); // \u8fd4\u56de 3\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= start < end <= 109
    • \n\t
    • \u6bcf\u4e2a\u6d4b\u8bd5\u7528\u4f8b\uff0c\u8c03\u7528 book\u00a0\u51fd\u6570\u6700\u591a\u4e0d\u8d85\u8fc7\u00a0400\u6b21
    • \n
    \n", "tags_en": ["Segment Tree", "Ordered Map"], "tags_cn": ["\u7ebf\u6bb5\u6811"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class MyCalendarThree {\npublic:\n MyCalendarThree() {\n\n }\n \n int book(int start, int end) {\n\n }\n};\n\n/**\n * Your MyCalendarThree object will be instantiated and called as such:\n * MyCalendarThree* obj = new MyCalendarThree();\n * int param_1 = obj->book(start,end);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class MyCalendarThree {\n\n public MyCalendarThree() {\n\n }\n \n public int book(int start, int end) {\n\n }\n}\n\n/**\n * Your MyCalendarThree object will be instantiated and called as such:\n * MyCalendarThree obj = new MyCalendarThree();\n * int param_1 = obj.book(start,end);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class MyCalendarThree(object):\n\n def __init__(self):\n\n\n def book(self, start, end):\n \"\"\"\n :type start: int\n :type end: int\n :rtype: int\n \"\"\"\n\n\n\n# Your MyCalendarThree object will be instantiated and called as such:\n# obj = MyCalendarThree()\n# param_1 = obj.book(start,end)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class MyCalendarThree:\n\n def __init__(self):\n\n\n def book(self, start: int, end: int) -> int:\n\n\n\n# Your MyCalendarThree object will be instantiated and called as such:\n# obj = MyCalendarThree()\n# param_1 = obj.book(start,end)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} MyCalendarThree;\n\n\nMyCalendarThree* myCalendarThreeCreate() {\n\n}\n\nint myCalendarThreeBook(MyCalendarThree* obj, int start, int end) {\n\n}\n\nvoid myCalendarThreeFree(MyCalendarThree* obj) {\n\n}\n\n/**\n * Your MyCalendarThree struct will be instantiated and called as such:\n * MyCalendarThree* obj = myCalendarThreeCreate();\n * int param_1 = myCalendarThreeBook(obj, start, end);\n \n * myCalendarThreeFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class MyCalendarThree {\n\n public MyCalendarThree() {\n\n }\n \n public int Book(int start, int end) {\n\n }\n}\n\n/**\n * Your MyCalendarThree object will be instantiated and called as such:\n * MyCalendarThree obj = new MyCalendarThree();\n * int param_1 = obj.Book(start,end);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "\nvar MyCalendarThree = function() {\n\n};\n\n/** \n * @param {number} start \n * @param {number} end\n * @return {number}\n */\nMyCalendarThree.prototype.book = function(start, end) {\n\n};\n\n/**\n * Your MyCalendarThree object will be instantiated and called as such:\n * var obj = new MyCalendarThree()\n * var param_1 = obj.book(start,end)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class MyCalendarThree\n def initialize()\n\n end\n\n\n=begin\n :type start: Integer\n :type end: Integer\n :rtype: Integer\n=end\n def book(start, end)\n\n end\n\n\nend\n\n# Your MyCalendarThree object will be instantiated and called as such:\n# obj = MyCalendarThree.new()\n# param_1 = obj.book(start, end)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass MyCalendarThree {\n\n init() {\n\n }\n \n func book(_ start: Int, _ end: Int) -> Int {\n\n }\n}\n\n/**\n * Your MyCalendarThree object will be instantiated and called as such:\n * let obj = MyCalendarThree()\n * let ret_1: Int = obj.book(start, end)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type MyCalendarThree struct {\n\n}\n\n\nfunc Constructor() MyCalendarThree {\n\n}\n\n\nfunc (this *MyCalendarThree) Book(start int, end int) int {\n\n}\n\n\n/**\n * Your MyCalendarThree object will be instantiated and called as such:\n * obj := Constructor();\n * param_1 := obj.Book(start,end);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class MyCalendarThree() {\n\n def book(start: Int, end: Int): Int = {\n\n }\n\n}\n\n/**\n * Your MyCalendarThree object will be instantiated and called as such:\n * var obj = new MyCalendarThree()\n * var param_1 = obj.book(start,end)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class MyCalendarThree() {\n\n fun book(start: Int, end: Int): Int {\n\n }\n\n}\n\n/**\n * Your MyCalendarThree object will be instantiated and called as such:\n * var obj = MyCalendarThree()\n * var param_1 = obj.book(start,end)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct MyCalendarThree {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl MyCalendarThree {\n\n fn new() -> Self {\n\n }\n \n fn book(&self, start: i32, end: i32) -> i32 {\n\n }\n}\n\n/**\n * Your MyCalendarThree object will be instantiated and called as such:\n * let obj = MyCalendarThree::new();\n * let ret_1: i32 = obj.book(start, end);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class MyCalendarThree {\n /**\n */\n function __construct() {\n\n }\n\n /**\n * @param Integer $start\n * @param Integer $end\n * @return Integer\n */\n function book($start, $end) {\n\n }\n}\n\n/**\n * Your MyCalendarThree object will be instantiated and called as such:\n * $obj = MyCalendarThree();\n * $ret_1 = $obj->book($start, $end);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class MyCalendarThree {\n constructor() {\n\n }\n\n book(start: number, end: number): number {\n\n }\n}\n\n/**\n * Your MyCalendarThree object will be instantiated and called as such:\n * var obj = new MyCalendarThree()\n * var param_1 = obj.book(start,end)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define my-calendar-three%\n (class object%\n (super-new)\n (init-field)\n \n ; book : exact-integer? exact-integer? -> exact-integer?\n (define/public (book start end)\n\n )))\n\n;; Your my-calendar-three% object will be instantiated and called as such:\n;; (define obj (new my-calendar-three%))\n;; (define param_1 (send obj book start end))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0732](https://leetcode-cn.com/problems/my-calendar-iii)", "[\u6211\u7684\u65e5\u7a0b\u5b89\u6392\u8868 III](/solution/0700-0799/0732.My%20Calendar%20III/README.md)", "`\u7ebf\u6bb5\u6811`", "\u56f0\u96be", ""], "md_table_row_en": ["[0732](https://leetcode.com/problems/my-calendar-iii)", "[My Calendar III](/solution/0700-0799/0732.My%20Calendar%20III/README_EN.md)", "`Segment Tree`,`Ordered Map`", "Hard", ""]}, {"question_id": "0731", "frontend_question_id": "0731", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/my-calendar-ii", "url_en": "https://leetcode.com/problems/my-calendar-ii", "relative_path_cn": "/solution/0700-0799/0731.My%20Calendar%20II/README.md", "relative_path_en": "/solution/0700-0799/0731.My%20Calendar%20II/README_EN.md", "title_cn": "\u6211\u7684\u65e5\u7a0b\u5b89\u6392\u8868 II", "title_en": "My Calendar II", "question_title_slug": "my-calendar-ii", "content_en": "

    Implement a MyCalendarTwo class to store your events. A new event can be added if adding the event will not cause a triple booking.

    \r\n\r\n

    Your class will have one method, book(int start, int end). Formally, this represents a booking on the half open interval [start, end), the range of real numbers x such that start <= x < end.

    \r\n\r\n

    A triple booking happens when three events have some non-empty intersection (ie., there is some time that is common to all 3 events.)

    \r\n\r\n

    For each call to the method MyCalendar.book, return true if the event can be added to the calendar successfully without causing a triple booking. Otherwise, return false and do not add the event to the calendar.

    \r\nYour class will be called like this: MyCalendar cal = new MyCalendar(); MyCalendar.book(start, end)\r\n\r\n

    Example 1:

    \r\n\r\n
    \r\nMyCalendar();\r\nMyCalendar.book(10, 20); // returns true\r\nMyCalendar.book(50, 60); // returns true\r\nMyCalendar.book(10, 40); // returns true\r\nMyCalendar.book(5, 15); // returns false\r\nMyCalendar.book(5, 10); // returns true\r\nMyCalendar.book(25, 55); // returns true\r\nExplanation: \r\nThe first two events can be booked.  The third event can be double booked.\r\nThe fourth event (5, 15) can't be booked, because it would result in a triple booking.\r\nThe fifth event (5, 10) can be booked, as it does not use time 10 which is already double booked.\r\nThe sixth event (25, 55) can be booked, as the time in [25, 40) will be double booked with the third event;\r\nthe time [40, 50) will be single booked, and the time [50, 55) will be double booked with the second event.\r\n
    \r\n\r\n

     

    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    • The number of calls to MyCalendar.book per test case will be at most 1000.
    • \r\n\t
    • In calls to MyCalendar.book(start, end), start and end are integers in the range [0, 10^9].
    • \r\n
    \r\n\r\n

     

    ", "content_cn": "

    \u5b9e\u73b0\u4e00\u4e2a MyCalendar \u7c7b\u6765\u5b58\u653e\u4f60\u7684\u65e5\u7a0b\u5b89\u6392\u3002\u5982\u679c\u8981\u6dfb\u52a0\u7684\u65f6\u95f4\u5185\u4e0d\u4f1a\u5bfc\u81f4\u4e09\u91cd\u9884\u8ba2\u65f6\uff0c\u5219\u53ef\u4ee5\u5b58\u50a8\u8fd9\u4e2a\u65b0\u7684\u65e5\u7a0b\u5b89\u6392\u3002

    \n\n

    MyCalendar \u6709\u4e00\u4e2a book(int start, int end)\u65b9\u6cd5\u3002\u5b83\u610f\u5473\u7740\u5728 start \u5230 end \u65f6\u95f4\u5185\u589e\u52a0\u4e00\u4e2a\u65e5\u7a0b\u5b89\u6392\uff0c\u6ce8\u610f\uff0c\u8fd9\u91cc\u7684\u65f6\u95f4\u662f\u534a\u5f00\u533a\u95f4\uff0c\u5373 [start, end), \u5b9e\u6570 x \u7684\u8303\u56f4\u4e3a\uff0c  start <= x < end\u3002

    \n\n

    \u5f53\u4e09\u4e2a\u65e5\u7a0b\u5b89\u6392\u6709\u4e00\u4e9b\u65f6\u95f4\u4e0a\u7684\u4ea4\u53c9\u65f6\uff08\u4f8b\u5982\u4e09\u4e2a\u65e5\u7a0b\u5b89\u6392\u90fd\u5728\u540c\u4e00\u65f6\u95f4\u5185\uff09\uff0c\u5c31\u4f1a\u4ea7\u751f\u4e09\u91cd\u9884\u8ba2\u3002

    \n\n

    \u6bcf\u6b21\u8c03\u7528 MyCalendar.book\u65b9\u6cd5\u65f6\uff0c\u5982\u679c\u53ef\u4ee5\u5c06\u65e5\u7a0b\u5b89\u6392\u6210\u529f\u6dfb\u52a0\u5230\u65e5\u5386\u4e2d\u800c\u4e0d\u4f1a\u5bfc\u81f4\u4e09\u91cd\u9884\u8ba2\uff0c\u8fd4\u56de true\u3002\u5426\u5219\uff0c\u8fd4\u56de false \u5e76\u4e14\u4e0d\u8981\u5c06\u8be5\u65e5\u7a0b\u5b89\u6392\u6dfb\u52a0\u5230\u65e5\u5386\u4e2d\u3002

    \n\n

    \u8bf7\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u8c03\u7528MyCalendar \u7c7b: MyCalendar cal = new MyCalendar(); MyCalendar.book(start, end)

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    MyCalendar();\nMyCalendar.book(10, 20); // returns true\nMyCalendar.book(50, 60); // returns true\nMyCalendar.book(10, 40); // returns true\nMyCalendar.book(5, 15); // returns false\nMyCalendar.book(5, 10); // returns true\nMyCalendar.book(25, 55); // returns true\n\u89e3\u91ca\uff1a \n\u524d\u4e24\u4e2a\u65e5\u7a0b\u5b89\u6392\u53ef\u4ee5\u6dfb\u52a0\u81f3\u65e5\u5386\u4e2d\u3002 \u7b2c\u4e09\u4e2a\u65e5\u7a0b\u5b89\u6392\u4f1a\u5bfc\u81f4\u53cc\u91cd\u9884\u8ba2\uff0c\u4f46\u53ef\u4ee5\u6dfb\u52a0\u81f3\u65e5\u5386\u4e2d\u3002\n\u7b2c\u56db\u4e2a\u65e5\u7a0b\u5b89\u6392\u6d3b\u52a8\uff085,15\uff09\u4e0d\u80fd\u6dfb\u52a0\u81f3\u65e5\u5386\u4e2d\uff0c\u56e0\u4e3a\u5b83\u4f1a\u5bfc\u81f4\u4e09\u91cd\u9884\u8ba2\u3002\n\u7b2c\u4e94\u4e2a\u65e5\u7a0b\u5b89\u6392\uff085,10\uff09\u53ef\u4ee5\u6dfb\u52a0\u81f3\u65e5\u5386\u4e2d\uff0c\u56e0\u4e3a\u5b83\u672a\u4f7f\u7528\u5df2\u7ecf\u53cc\u91cd\u9884\u8ba2\u7684\u65f6\u95f410\u3002\n\u7b2c\u516d\u4e2a\u65e5\u7a0b\u5b89\u6392\uff0825,55\uff09\u53ef\u4ee5\u6dfb\u52a0\u81f3\u65e5\u5386\u4e2d\uff0c\u56e0\u4e3a\u65f6\u95f4 [25,40] \u5c06\u548c\u7b2c\u4e09\u4e2a\u65e5\u7a0b\u5b89\u6392\u53cc\u91cd\u9884\u8ba2\uff1b\n\u65f6\u95f4 [40,50] \u5c06\u5355\u72ec\u9884\u8ba2\uff0c\u65f6\u95f4 [50,55\uff09\u5c06\u548c\u7b2c\u4e8c\u4e2a\u65e5\u7a0b\u5b89\u6392\u53cc\u91cd\u9884\u8ba2\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6bcf\u4e2a\u6d4b\u8bd5\u7528\u4f8b\uff0c\u8c03\u7528 MyCalendar.book \u51fd\u6570\u6700\u591a\u4e0d\u8d85\u8fc7 1000\u6b21\u3002
    • \n\t
    • \u8c03\u7528\u51fd\u6570 MyCalendar.book(start, end)\u65f6\uff0c start \u548c end \u7684\u53d6\u503c\u8303\u56f4\u4e3a [0, 10^9]\u3002
    • \n
    \n", "tags_en": ["Ordered Map"], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class MyCalendarTwo {\npublic:\n MyCalendarTwo() {\n\n }\n \n bool book(int start, int end) {\n\n }\n};\n\n/**\n * Your MyCalendarTwo object will be instantiated and called as such:\n * MyCalendarTwo* obj = new MyCalendarTwo();\n * bool param_1 = obj->book(start,end);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class MyCalendarTwo {\n\n public MyCalendarTwo() {\n\n }\n \n public boolean book(int start, int end) {\n\n }\n}\n\n/**\n * Your MyCalendarTwo object will be instantiated and called as such:\n * MyCalendarTwo obj = new MyCalendarTwo();\n * boolean param_1 = obj.book(start,end);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class MyCalendarTwo(object):\n\n def __init__(self):\n \n\n def book(self, start, end):\n \"\"\"\n :type start: int\n :type end: int\n :rtype: bool\n \"\"\"\n \n\n\n# Your MyCalendarTwo object will be instantiated and called as such:\n# obj = MyCalendarTwo()\n# param_1 = obj.book(start,end)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class MyCalendarTwo:\n\n def __init__(self):\n \n\n def book(self, start: int, end: int) -> bool:\n \n\n\n# Your MyCalendarTwo object will be instantiated and called as such:\n# obj = MyCalendarTwo()\n# param_1 = obj.book(start,end)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} MyCalendarTwo;\n\n\nMyCalendarTwo* myCalendarTwoCreate() {\n \n}\n\nbool myCalendarTwoBook(MyCalendarTwo* obj, int start, int end) {\n \n}\n\nvoid myCalendarTwoFree(MyCalendarTwo* obj) {\n \n}\n\n/**\n * Your MyCalendarTwo struct will be instantiated and called as such:\n * MyCalendarTwo* obj = myCalendarTwoCreate();\n * bool param_1 = myCalendarTwoBook(obj, start, end);\n \n * myCalendarTwoFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class MyCalendarTwo {\n\n public MyCalendarTwo() {\n\n }\n \n public bool Book(int start, int end) {\n\n }\n}\n\n/**\n * Your MyCalendarTwo object will be instantiated and called as such:\n * MyCalendarTwo obj = new MyCalendarTwo();\n * bool param_1 = obj.Book(start,end);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "\nvar MyCalendarTwo = function() {\n\n};\n\n/** \n * @param {number} start \n * @param {number} end\n * @return {boolean}\n */\nMyCalendarTwo.prototype.book = function(start, end) {\n\n};\n\n/**\n * Your MyCalendarTwo object will be instantiated and called as such:\n * var obj = new MyCalendarTwo()\n * var param_1 = obj.book(start,end)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class MyCalendarTwo\n def initialize()\n\n end\n\n\n=begin\n :type start: Integer\n :type end: Integer\n :rtype: Boolean\n=end\n def book(start, end)\n\n end\n\n\nend\n\n# Your MyCalendarTwo object will be instantiated and called as such:\n# obj = MyCalendarTwo.new()\n# param_1 = obj.book(start, end)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass MyCalendarTwo {\n\n init() {\n \n }\n \n func book(_ start: Int, _ end: Int) -> Bool {\n \n }\n}\n\n/**\n * Your MyCalendarTwo object will be instantiated and called as such:\n * let obj = MyCalendarTwo()\n * let ret_1: Bool = obj.book(start, end)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type MyCalendarTwo struct {\n\n}\n\n\nfunc Constructor() MyCalendarTwo {\n\n}\n\n\nfunc (this *MyCalendarTwo) Book(start int, end int) bool {\n\n}\n\n\n/**\n * Your MyCalendarTwo object will be instantiated and called as such:\n * obj := Constructor();\n * param_1 := obj.Book(start,end);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class MyCalendarTwo() {\n\n def book(start: Int, end: Int): Boolean = {\n\n }\n\n}\n\n/**\n * Your MyCalendarTwo object will be instantiated and called as such:\n * var obj = new MyCalendarTwo()\n * var param_1 = obj.book(start,end)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class MyCalendarTwo() {\n\n fun book(start: Int, end: Int): Boolean {\n\n }\n\n}\n\n/**\n * Your MyCalendarTwo object will be instantiated and called as such:\n * var obj = MyCalendarTwo()\n * var param_1 = obj.book(start,end)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct MyCalendarTwo {\n\n}\n\n\n/** \n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl MyCalendarTwo {\n\n fn new() -> Self {\n \n }\n \n fn book(&self, start: i32, end: i32) -> bool {\n \n }\n}\n\n/**\n * Your MyCalendarTwo object will be instantiated and called as such:\n * let obj = MyCalendarTwo::new();\n * let ret_1: bool = obj.book(start, end);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class MyCalendarTwo {\n /**\n */\n function __construct() {\n \n }\n \n /**\n * @param Integer $start\n * @param Integer $end\n * @return Boolean\n */\n function book($start, $end) {\n \n }\n}\n\n/**\n * Your MyCalendarTwo object will be instantiated and called as such:\n * $obj = MyCalendarTwo();\n * $ret_1 = $obj->book($start, $end);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class MyCalendarTwo {\n constructor() {\n\n }\n\n book(start: number, end: number): boolean {\n\n }\n}\n\n/**\n * Your MyCalendarTwo object will be instantiated and called as such:\n * var obj = new MyCalendarTwo()\n * var param_1 = obj.book(start,end)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define my-calendar-two%\n (class object%\n (super-new)\n (init-field)\n \n ; book : exact-integer? exact-integer? -> boolean?\n (define/public (book start end)\n\n )))\n\n;; Your my-calendar-two% object will be instantiated and called as such:\n;; (define obj (new my-calendar-two%))\n;; (define param_1 (send obj book start end))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0731](https://leetcode-cn.com/problems/my-calendar-ii)", "[\u6211\u7684\u65e5\u7a0b\u5b89\u6392\u8868 II](/solution/0700-0799/0731.My%20Calendar%20II/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0731](https://leetcode.com/problems/my-calendar-ii)", "[My Calendar II](/solution/0700-0799/0731.My%20Calendar%20II/README_EN.md)", "`Ordered Map`", "Medium", ""]}, {"question_id": "0730", "frontend_question_id": "0730", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-different-palindromic-subsequences", "url_en": "https://leetcode.com/problems/count-different-palindromic-subsequences", "relative_path_cn": "/solution/0700-0799/0730.Count%20Different%20Palindromic%20Subsequences/README.md", "relative_path_en": "/solution/0700-0799/0730.Count%20Different%20Palindromic%20Subsequences/README_EN.md", "title_cn": "\u7edf\u8ba1\u4e0d\u540c\u56de\u6587\u5b50\u5e8f\u5217", "title_en": "Count Different Palindromic Subsequences", "question_title_slug": "count-different-palindromic-subsequences", "content_en": "

    Given a string s, return the number of different non-empty palindromic subsequences in s. Since the answer may be very large, return it modulo 109 + 7.

    \n\n

    A subsequence of a string is obtained by deleting zero or more characters from the string.

    \n\n

    A sequence is palindromic if it is equal to the sequence reversed.

    \n\n

    Two sequences a1, a2, ... and b1, b2, ... are different if there is some i for which ai != bi.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "bccb"\nOutput: 6\nExplanation: The 6 different non-empty palindromic subsequences are 'b', 'c', 'bb', 'cc', 'bcb', 'bccb'.\nNote that 'bcb' is counted only once, even though it occurs twice.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "abcdabcdabcdabcdabcdabcdabcdabcddcbadcbadcbadcbadcbadcbadcbadcba"\nOutput: 104860361\nExplanation: There are 3104860382 different non-empty palindromic subsequences, which is 104860361 modulo 109 + 7.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 1000
    • \n\t
    • s[i] is either 'a', 'b', 'c', or 'd'.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32 S\uff0c\u627e\u51fa S \u4e2d\u4e0d\u540c\u7684\u975e\u7a7a\u56de\u6587\u5b50\u5e8f\u5217\u4e2a\u6570\uff0c\u5e76\u8fd4\u56de\u8be5\u6570\u5b57\u4e0e 10^9 + 7 \u7684\u6a21\u3002

    \n\n

    \u901a\u8fc7\u4ece S \u4e2d\u5220\u9664 0 \u4e2a\u6216\u591a\u4e2a\u5b57\u7b26\u6765\u83b7\u5f97\u5b50\u5e8f\u5217\u3002

    \n\n

    \u5982\u679c\u4e00\u4e2a\u5b57\u7b26\u5e8f\u5217\u4e0e\u5b83\u53cd\u8f6c\u540e\u7684\u5b57\u7b26\u5e8f\u5217\u4e00\u81f4\uff0c\u90a3\u4e48\u5b83\u662f\u56de\u6587\u5b57\u7b26\u5e8f\u5217\u3002

    \n\n

    \u5982\u679c\u5bf9\u4e8e\u67d0\u4e2a  i\uff0cA_i != B_i\uff0c\u90a3\u4e48 A_1, A_2, ... \u548c B_1, B_2, ... \u8fd9\u4e24\u4e2a\u5b57\u7b26\u5e8f\u5217\u662f\u4e0d\u540c\u7684\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a\nS = 'bccb'\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\n6 \u4e2a\u4e0d\u540c\u7684\u975e\u7a7a\u56de\u6587\u5b50\u5b57\u7b26\u5e8f\u5217\u5206\u522b\u4e3a\uff1a'b', 'c', 'bb', 'cc', 'bcb', 'bccb'\u3002\n\u6ce8\u610f\uff1a'bcb' \u867d\u7136\u51fa\u73b0\u4e24\u6b21\u4f46\u4ec5\u8ba1\u6570\u4e00\u6b21\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a\nS = 'abcdabcdabcdabcdabcdabcdabcdabcddcbadcbadcbadcbadcbadcbadcbadcba'\n\u8f93\u51fa\uff1a104860361\n\u89e3\u91ca\uff1a\n\u5171\u6709 3104860382 \u4e2a\u4e0d\u540c\u7684\u975e\u7a7a\u56de\u6587\u5b50\u5e8f\u5217\uff0c\u5bf9 10^9 + 7 \u53d6\u6a21\u4e3a 104860361\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u5b57\u7b26\u4e32 S \u7684\u957f\u5ea6\u5c06\u5728[1, 1000]\u8303\u56f4\u5185\u3002
    • \n\t
    • \u6bcf\u4e2a\u5b57\u7b26 S[i] \u5c06\u4f1a\u662f\u96c6\u5408 {'a', 'b', 'c', 'd'} \u4e2d\u7684\u67d0\u4e00\u4e2a\u3002
    • \n
    \n\n

     

    \n", "tags_en": ["String", "Dynamic Programming"], "tags_cn": ["\u5b57\u7b26\u4e32", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countPalindromicSubsequences(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countPalindromicSubsequences(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countPalindromicSubsequences(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countPalindromicSubsequences(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countPalindromicSubsequences(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountPalindromicSubsequences(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar countPalindromicSubsequences = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef count_palindromic_subsequences(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countPalindromicSubsequences(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countPalindromicSubsequences(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countPalindromicSubsequences(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countPalindromicSubsequences(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_palindromic_subsequences(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function countPalindromicSubsequences($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countPalindromicSubsequences(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-palindromic-subsequences s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0730](https://leetcode-cn.com/problems/count-different-palindromic-subsequences)", "[\u7edf\u8ba1\u4e0d\u540c\u56de\u6587\u5b50\u5e8f\u5217](/solution/0700-0799/0730.Count%20Different%20Palindromic%20Subsequences/README.md)", "`\u5b57\u7b26\u4e32`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0730](https://leetcode.com/problems/count-different-palindromic-subsequences)", "[Count Different Palindromic Subsequences](/solution/0700-0799/0730.Count%20Different%20Palindromic%20Subsequences/README_EN.md)", "`String`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0729", "frontend_question_id": "0729", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/my-calendar-i", "url_en": "https://leetcode.com/problems/my-calendar-i", "relative_path_cn": "/solution/0700-0799/0729.My%20Calendar%20I/README.md", "relative_path_en": "/solution/0700-0799/0729.My%20Calendar%20I/README_EN.md", "title_cn": "\u6211\u7684\u65e5\u7a0b\u5b89\u6392\u8868 I", "title_en": "My Calendar I", "question_title_slug": "my-calendar-i", "content_en": "

    Implement a MyCalendar class to store your events. A new event can be added if adding the event will not cause a double booking.

    \r\n\r\n

    Your class will have the method, book(int start, int end). Formally, this represents a booking on the half open interval [start, end), the range of real numbers x such that start <= x < end.

    \r\n\r\n

    A double booking happens when two events have some non-empty intersection (ie., there is some time that is common to both events.)

    \r\n\r\n

    For each call to the method MyCalendar.book, return true if the event can be added to the calendar successfully without causing a double booking. Otherwise, return false and do not add the event to the calendar.

    \r\nYour class will be called like this: MyCalendar cal = new MyCalendar(); MyCalendar.book(start, end)\r\n\r\n

    Example 1:

    \r\n\r\n
    \r\nMyCalendar();\r\nMyCalendar.book(10, 20); // returns true\r\nMyCalendar.book(15, 25); // returns false\r\nMyCalendar.book(20, 30); // returns true\r\nExplanation: \r\nThe first event can be booked.  The second can't because time 15 is already booked by another event.\r\nThe third event can be booked, as the first event takes every time less than 20, but not including 20.\r\n
    \r\n\r\n

     

    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    • The number of calls to MyCalendar.book per test case will be at most 1000.
    • \r\n\t
    • In calls to MyCalendar.book(start, end), start and end are integers in the range [0, 10^9].
    • \r\n
    \r\n\r\n

     

    \r\n", "content_cn": "

    \u5b9e\u73b0\u4e00\u4e2a MyCalendar \u7c7b\u6765\u5b58\u653e\u4f60\u7684\u65e5\u7a0b\u5b89\u6392\u3002\u5982\u679c\u8981\u6dfb\u52a0\u7684\u65f6\u95f4\u5185\u6ca1\u6709\u5176\u4ed6\u5b89\u6392\uff0c\u5219\u53ef\u4ee5\u5b58\u50a8\u8fd9\u4e2a\u65b0\u7684\u65e5\u7a0b\u5b89\u6392\u3002

    \n\n

    MyCalendar \u6709\u4e00\u4e2a book(int start, int end)\u65b9\u6cd5\u3002\u5b83\u610f\u5473\u7740\u5728 start \u5230 end \u65f6\u95f4\u5185\u589e\u52a0\u4e00\u4e2a\u65e5\u7a0b\u5b89\u6392\uff0c\u6ce8\u610f\uff0c\u8fd9\u91cc\u7684\u65f6\u95f4\u662f\u534a\u5f00\u533a\u95f4\uff0c\u5373 [start, end), \u5b9e\u6570\u00a0x \u7684\u8303\u56f4\u4e3a\uff0c \u00a0start <= x < end\u3002

    \n\n

    \u5f53\u4e24\u4e2a\u65e5\u7a0b\u5b89\u6392\u6709\u4e00\u4e9b\u65f6\u95f4\u4e0a\u7684\u4ea4\u53c9\u65f6\uff08\u4f8b\u5982\u4e24\u4e2a\u65e5\u7a0b\u5b89\u6392\u90fd\u5728\u540c\u4e00\u65f6\u95f4\u5185\uff09\uff0c\u5c31\u4f1a\u4ea7\u751f\u91cd\u590d\u9884\u8ba2\u3002

    \n\n

    \u6bcf\u6b21\u8c03\u7528 MyCalendar.book\u65b9\u6cd5\u65f6\uff0c\u5982\u679c\u53ef\u4ee5\u5c06\u65e5\u7a0b\u5b89\u6392\u6210\u529f\u6dfb\u52a0\u5230\u65e5\u5386\u4e2d\u800c\u4e0d\u4f1a\u5bfc\u81f4\u91cd\u590d\u9884\u8ba2\uff0c\u8fd4\u56de true\u3002\u5426\u5219\uff0c\u8fd4\u56de false\u00a0\u5e76\u4e14\u4e0d\u8981\u5c06\u8be5\u65e5\u7a0b\u5b89\u6392\u6dfb\u52a0\u5230\u65e5\u5386\u4e2d\u3002

    \n\n

    \u8bf7\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u8c03\u7528 MyCalendar \u7c7b: MyCalendar cal = new MyCalendar(); MyCalendar.book(start, end)

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \nMyCalendar();\nMyCalendar.book(10, 20); // returns true\nMyCalendar.book(15, 25); // returns false\nMyCalendar.book(20, 30); // returns true\n\u89e3\u91ca: \n\u7b2c\u4e00\u4e2a\u65e5\u7a0b\u5b89\u6392\u53ef\u4ee5\u6dfb\u52a0\u5230\u65e5\u5386\u4e2d.  \u7b2c\u4e8c\u4e2a\u65e5\u7a0b\u5b89\u6392\u4e0d\u80fd\u6dfb\u52a0\u5230\u65e5\u5386\u4e2d\uff0c\u56e0\u4e3a\u65f6\u95f4 15 \u5df2\u7ecf\u88ab\u7b2c\u4e00\u4e2a\u65e5\u7a0b\u5b89\u6392\u9884\u5b9a\u4e86\u3002\n\u7b2c\u4e09\u4e2a\u65e5\u7a0b\u5b89\u6392\u53ef\u4ee5\u6dfb\u52a0\u5230\u65e5\u5386\u4e2d\uff0c\u56e0\u4e3a\u7b2c\u4e00\u4e2a\u65e5\u7a0b\u5b89\u6392\u5e76\u4e0d\u5305\u542b\u65f6\u95f4 20 \u3002\n
    \n\n

    \u8bf4\u660e:

    \n\n
      \n\t
    • \u6bcf\u4e2a\u6d4b\u8bd5\u7528\u4f8b\uff0c\u8c03\u7528\u00a0MyCalendar.book\u00a0\u51fd\u6570\u6700\u591a\u4e0d\u8d85\u8fc7\u00a01000\u6b21\u3002
    • \n\t
    • \u8c03\u7528\u51fd\u6570\u00a0MyCalendar.book(start, end)\u65f6\uff0c\u00a0start \u548c\u00a0end \u7684\u53d6\u503c\u8303\u56f4\u4e3a\u00a0[0, 10^9]\u3002
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class MyCalendar {\npublic:\n MyCalendar() {\n\n }\n \n bool book(int start, int end) {\n\n }\n};\n\n/**\n * Your MyCalendar object will be instantiated and called as such:\n * MyCalendar* obj = new MyCalendar();\n * bool param_1 = obj->book(start,end);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class MyCalendar {\n\n public MyCalendar() {\n\n }\n \n public boolean book(int start, int end) {\n\n }\n}\n\n/**\n * Your MyCalendar object will be instantiated and called as such:\n * MyCalendar obj = new MyCalendar();\n * boolean param_1 = obj.book(start,end);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class MyCalendar(object):\n\n def __init__(self):\n \n\n def book(self, start, end):\n \"\"\"\n :type start: int\n :type end: int\n :rtype: bool\n \"\"\"\n \n\n\n# Your MyCalendar object will be instantiated and called as such:\n# obj = MyCalendar()\n# param_1 = obj.book(start,end)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class MyCalendar:\n\n def __init__(self):\n \n\n def book(self, start: int, end: int) -> bool:\n \n\n\n# Your MyCalendar object will be instantiated and called as such:\n# obj = MyCalendar()\n# param_1 = obj.book(start,end)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} MyCalendar;\n\n\nMyCalendar* myCalendarCreate() {\n \n}\n\nbool myCalendarBook(MyCalendar* obj, int start, int end) {\n \n}\n\nvoid myCalendarFree(MyCalendar* obj) {\n \n}\n\n/**\n * Your MyCalendar struct will be instantiated and called as such:\n * MyCalendar* obj = myCalendarCreate();\n * bool param_1 = myCalendarBook(obj, start, end);\n \n * myCalendarFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class MyCalendar {\n\n public MyCalendar() {\n\n }\n \n public bool Book(int start, int end) {\n\n }\n}\n\n/**\n * Your MyCalendar object will be instantiated and called as such:\n * MyCalendar obj = new MyCalendar();\n * bool param_1 = obj.Book(start,end);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "\nvar MyCalendar = function() {\n\n};\n\n/** \n * @param {number} start \n * @param {number} end\n * @return {boolean}\n */\nMyCalendar.prototype.book = function(start, end) {\n\n};\n\n/**\n * Your MyCalendar object will be instantiated and called as such:\n * var obj = new MyCalendar()\n * var param_1 = obj.book(start,end)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class MyCalendar\n def initialize()\n\n end\n\n\n=begin\n :type start: Integer\n :type end: Integer\n :rtype: Boolean\n=end\n def book(start, end)\n\n end\n\n\nend\n\n# Your MyCalendar object will be instantiated and called as such:\n# obj = MyCalendar.new()\n# param_1 = obj.book(start, end)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass MyCalendar {\n\n init() {\n \n }\n \n func book(_ start: Int, _ end: Int) -> Bool {\n \n }\n}\n\n/**\n * Your MyCalendar object will be instantiated and called as such:\n * let obj = MyCalendar()\n * let ret_1: Bool = obj.book(start, end)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type MyCalendar struct {\n\n}\n\n\nfunc Constructor() MyCalendar {\n\n}\n\n\nfunc (this *MyCalendar) Book(start int, end int) bool {\n\n}\n\n\n/**\n * Your MyCalendar object will be instantiated and called as such:\n * obj := Constructor();\n * param_1 := obj.Book(start,end);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class MyCalendar() {\n\n def book(start: Int, end: Int): Boolean = {\n\n }\n\n}\n\n/**\n * Your MyCalendar object will be instantiated and called as such:\n * var obj = new MyCalendar()\n * var param_1 = obj.book(start,end)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class MyCalendar() {\n\n fun book(start: Int, end: Int): Boolean {\n\n }\n\n}\n\n/**\n * Your MyCalendar object will be instantiated and called as such:\n * var obj = MyCalendar()\n * var param_1 = obj.book(start,end)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct MyCalendar {\n\n}\n\n\n/** \n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl MyCalendar {\n\n fn new() -> Self {\n \n }\n \n fn book(&self, start: i32, end: i32) -> bool {\n \n }\n}\n\n/**\n * Your MyCalendar object will be instantiated and called as such:\n * let obj = MyCalendar::new();\n * let ret_1: bool = obj.book(start, end);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class MyCalendar {\n /**\n */\n function __construct() {\n \n }\n \n /**\n * @param Integer $start\n * @param Integer $end\n * @return Boolean\n */\n function book($start, $end) {\n \n }\n}\n\n/**\n * Your MyCalendar object will be instantiated and called as such:\n * $obj = MyCalendar();\n * $ret_1 = $obj->book($start, $end);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class MyCalendar {\n constructor() {\n\n }\n\n book(start: number, end: number): boolean {\n\n }\n}\n\n/**\n * Your MyCalendar object will be instantiated and called as such:\n * var obj = new MyCalendar()\n * var param_1 = obj.book(start,end)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define my-calendar%\n (class object%\n (super-new)\n (init-field)\n \n ; book : exact-integer? exact-integer? -> boolean?\n (define/public (book start end)\n\n )))\n\n;; Your my-calendar% object will be instantiated and called as such:\n;; (define obj (new my-calendar%))\n;; (define param_1 (send obj book start end))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0729](https://leetcode-cn.com/problems/my-calendar-i)", "[\u6211\u7684\u65e5\u7a0b\u5b89\u6392\u8868 I](/solution/0700-0799/0729.My%20Calendar%20I/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0729](https://leetcode.com/problems/my-calendar-i)", "[My Calendar I](/solution/0700-0799/0729.My%20Calendar%20I/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0728", "frontend_question_id": "0728", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/self-dividing-numbers", "url_en": "https://leetcode.com/problems/self-dividing-numbers", "relative_path_cn": "/solution/0700-0799/0728.Self%20Dividing%20Numbers/README.md", "relative_path_en": "/solution/0700-0799/0728.Self%20Dividing%20Numbers/README_EN.md", "title_cn": "\u81ea\u9664\u6570", "title_en": "Self Dividing Numbers", "question_title_slug": "self-dividing-numbers", "content_en": "

    A self-dividing number is a number that is divisible by every digit it contains.

    \n\n
      \n\t
    • For example, 128 is a self-dividing number because 128 % 1 == 0, 128 % 2 == 0, and 128 % 8 == 0.
    • \n
    \n\n

    A self-dividing number is not allowed to contain the digit zero.

    \n\n

    Given two integers left and right, return a list of all the self-dividing numbers in the range [left, right].

    \n\n

     

    \n

    Example 1:

    \n
    Input: left = 1, right = 22\nOutput: [1,2,3,4,5,6,7,8,9,11,12,15,22]\n

    Example 2:

    \n
    Input: left = 47, right = 85\nOutput: [48,55,66,77]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= left <= right <= 104
    • \n
    \n", "content_cn": "

    \u81ea\u9664\u6570 \u662f\u6307\u53ef\u4ee5\u88ab\u5b83\u5305\u542b\u7684\u6bcf\u4e00\u4f4d\u6570\u9664\u5c3d\u7684\u6570\u3002

    \n\n

    \u4f8b\u5982\uff0c128 \u662f\u4e00\u4e2a\u81ea\u9664\u6570\uff0c\u56e0\u4e3a 128 % 1 == 0\uff0c128 % 2 == 0\uff0c128 % 8 == 0\u3002

    \n\n

    \u8fd8\u6709\uff0c\u81ea\u9664\u6570\u4e0d\u5141\u8bb8\u5305\u542b 0 \u3002

    \n\n

    \u7ed9\u5b9a\u4e0a\u8fb9\u754c\u548c\u4e0b\u8fb9\u754c\u6570\u5b57\uff0c\u8f93\u51fa\u4e00\u4e2a\u5217\u8868\uff0c\u5217\u8868\u7684\u5143\u7d20\u662f\u8fb9\u754c\uff08\u542b\u8fb9\u754c\uff09\u5185\u6240\u6709\u7684\u81ea\u9664\u6570\u3002

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1a \n\u4e0a\u8fb9\u754cleft = 1, \u4e0b\u8fb9\u754cright = 22\n\u8f93\u51fa\uff1a [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 15, 22]\n
    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    • \u6bcf\u4e2a\u8f93\u5165\u53c2\u6570\u7684\u8fb9\u754c\u6ee1\u8db3 1 <= left <= right <= 10000\u3002
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector selfDividingNumbers(int left, int right) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List selfDividingNumbers(int left, int right) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def selfDividingNumbers(self, left, right):\n \"\"\"\n :type left: int\n :type right: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def selfDividingNumbers(self, left: int, right: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* selfDividingNumbers(int left, int right, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList SelfDividingNumbers(int left, int right) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} left\n * @param {number} right\n * @return {number[]}\n */\nvar selfDividingNumbers = function(left, right) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} left\n# @param {Integer} right\n# @return {Integer[]}\ndef self_dividing_numbers(left, right)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func selfDividingNumbers(_ left: Int, _ right: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func selfDividingNumbers(left int, right int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def selfDividingNumbers(left: Int, right: Int): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun selfDividingNumbers(left: Int, right: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn self_dividing_numbers(left: i32, right: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $left\n * @param Integer $right\n * @return Integer[]\n */\n function selfDividingNumbers($left, $right) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function selfDividingNumbers(left: number, right: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (self-dividing-numbers left right)\n (-> exact-integer? exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0728](https://leetcode-cn.com/problems/self-dividing-numbers)", "[\u81ea\u9664\u6570](/solution/0700-0799/0728.Self%20Dividing%20Numbers/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0728](https://leetcode.com/problems/self-dividing-numbers)", "[Self Dividing Numbers](/solution/0700-0799/0728.Self%20Dividing%20Numbers/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "0727", "frontend_question_id": "0727", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/minimum-window-subsequence", "url_en": "https://leetcode.com/problems/minimum-window-subsequence", "relative_path_cn": "/solution/0700-0799/0727.Minimum%20Window%20Subsequence/README.md", "relative_path_en": "/solution/0700-0799/0727.Minimum%20Window%20Subsequence/README_EN.md", "title_cn": "\u6700\u5c0f\u7a97\u53e3\u5b50\u5e8f\u5217", "title_en": "Minimum Window Subsequence", "question_title_slug": "minimum-window-subsequence", "content_en": "

    Given strings s1 and s2, return the minimum contiguous substring part of s1, so that s2 is a subsequence of the part.

    \n\n

    If there is no such window in s1 that covers all characters in s2, return the empty string "". If there are multiple such minimum-length windows, return the one with the left-most starting index.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s1 = "abcdebdde", s2 = "bde"\nOutput: "bcde"\nExplanation: \n"bcde" is the answer because it occurs before "bdde" which has the same length.\n"deb" is not a smaller window because the elements of s2 in the window must occur in order.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s1 = "jmeqksfrsdcmsiwvaovztaqenprpvnbstl", s2 = "u"\nOutput: ""\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s1.length <= 2 * 104
    • \n\t
    • 1 <= s2.length <= 100
    • \n\t
    • s1 and s2 consist of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u5b57\u7b26\u4e32 S and T\uff0c\u627e\u51fa S \u4e2d\u6700\u77ed\u7684\uff08\u8fde\u7eed\uff09\u5b50\u4e32 W \uff0c\u4f7f\u5f97 T \u662f W \u7684 \u5b50\u5e8f\u5217 \u3002

    \n\n

    \u5982\u679c S \u4e2d\u6ca1\u6709\u7a97\u53e3\u53ef\u4ee5\u5305\u542b T \u4e2d\u7684\u6240\u6709\u5b57\u7b26\uff0c\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32 ""\u3002\u5982\u679c\u6709\u4e0d\u6b62\u4e00\u4e2a\u6700\u77ed\u957f\u5ea6\u7684\u7a97\u53e3\uff0c\u8fd4\u56de\u5f00\u59cb\u4f4d\u7f6e\u6700\u9760\u5de6\u7684\u90a3\u4e2a\u3002

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a\nS = "abcdebdde", T = "bde"\n\u8f93\u51fa\uff1a"bcde"\n\u89e3\u91ca\uff1a\n"bcde" \u662f\u7b54\u6848\uff0c\u56e0\u4e3a\u5b83\u5728\u76f8\u540c\u957f\u5ea6\u7684\u5b57\u7b26\u4e32 "bdde" \u51fa\u73b0\u4e4b\u524d\u3002\n"deb" \u4e0d\u662f\u4e00\u4e2a\u66f4\u77ed\u7684\u7b54\u6848\uff0c\u56e0\u4e3a\u5728\u7a97\u53e3\u4e2d\u5fc5\u987b\u6309\u987a\u5e8f\u51fa\u73b0 T \u4e2d\u7684\u5143\u7d20\u3002
    \n\n

     

    \n\n

    \u6ce8\uff1a

    \n\n
      \n\t
    • \u6240\u6709\u8f93\u5165\u7684\u5b57\u7b26\u4e32\u90fd\u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd\u3002All the strings in the input will only contain lowercase letters.
    • \n\t
    • S \u957f\u5ea6\u7684\u8303\u56f4\u4e3a [1, 20000]\u3002
    • \n\t
    • T \u957f\u5ea6\u7684\u8303\u56f4\u4e3a [1, 100]\u3002
    • \n
    \n\n

     

    \n", "tags_en": ["Dynamic Programming", "Sliding Window"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string minWindow(string s1, string s2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String minWindow(String s1, String s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minWindow(self, s1, s2):\n \"\"\"\n :type s1: str\n :type s2: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minWindow(self, s1: str, s2: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * minWindow(char * s1, char * s2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string MinWindow(string s1, string s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s1\n * @param {string} s2\n * @return {string}\n */\nvar minWindow = function(s1, s2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s1\n# @param {String} s2\n# @return {String}\ndef min_window(s1, s2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minWindow(_ s1: String, _ s2: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minWindow(s1 string, s2 string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minWindow(s1: String, s2: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minWindow(s1: String, s2: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_window(s1: String, s2: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s1\n * @param String $s2\n * @return String\n */\n function minWindow($s1, $s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minWindow(s1: string, s2: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-window s1 s2)\n (-> string? string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0727](https://leetcode-cn.com/problems/minimum-window-subsequence)", "[\u6700\u5c0f\u7a97\u53e3\u5b50\u5e8f\u5217](/solution/0700-0799/0727.Minimum%20Window%20Subsequence/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0727](https://leetcode.com/problems/minimum-window-subsequence)", "[Minimum Window Subsequence](/solution/0700-0799/0727.Minimum%20Window%20Subsequence/README_EN.md)", "`Dynamic Programming`,`Sliding Window`", "Hard", "\ud83d\udd12"]}, {"question_id": "0726", "frontend_question_id": "0726", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-atoms", "url_en": "https://leetcode.com/problems/number-of-atoms", "relative_path_cn": "/solution/0700-0799/0726.Number%20of%20Atoms/README.md", "relative_path_en": "/solution/0700-0799/0726.Number%20of%20Atoms/README_EN.md", "title_cn": "\u539f\u5b50\u7684\u6570\u91cf", "title_en": "Number of Atoms", "question_title_slug": "number-of-atoms", "content_en": "

    Given a chemical formula (given as a string), return the count of each atom.

    \n\n

    The atomic element always starts with an uppercase character, then zero or more lowercase letters, representing the name.

    \n\n

    One or more digits representing that element's count may follow if the count is greater than 1. If the count is 1, no digits will follow. For example, H2O and H2O2 are possible, but H1O2 is impossible.

    \n\n

    Two formulas concatenated together to produce another formula. For example, H2O2He3Mg4 is also a formula.

    \n\n

    A formula placed in parentheses, and a count (optionally added) is also a formula. For example, (H2O2) and (H2O2)3 are formulas.

    \n\n

    Given a formula, return the count of all elements as a string in the following form: the first name (in sorted order), followed by its count (if that count is more than 1), followed by the second name (in sorted order), followed by its count (if that count is more than 1), and so on.

    \n\n

     

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: formula = "H2O"\nOutput: "H2O"\nExplanation: The count of elements are {'H': 2, 'O': 1}.\n
    \n\n

    Example 2:

    \n\n
    \nInput: formula = "Mg(OH)2"\nOutput: "H2MgO2"\nExplanation: The count of elements are {'H': 2, 'Mg': 1, 'O': 2}.\n
    \n\n

    Example 3:

    \n\n
    \nInput: formula = "K4(ON(SO3)2)2"\nOutput: "K4N2O14S4"\nExplanation: The count of elements are {'K': 4, 'N': 2, 'O': 14, 'S': 4}.\n
    \n\n

    Example 4:

    \n\n
    \nInput: formula = "Be32"\nOutput: "Be32"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= formula.length <= 1000
    • \n\t
    • formula consists of English letters, digits, '(', and ')'.
    • \n\t
    • formula is always valid.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5316\u5b66\u5f0fformula\uff08\u4f5c\u4e3a\u5b57\u7b26\u4e32\uff09\uff0c\u8fd4\u56de\u6bcf\u79cd\u539f\u5b50\u7684\u6570\u91cf\u3002

    \n\n

    \u539f\u5b50\u603b\u662f\u4ee5\u4e00\u4e2a\u5927\u5199\u5b57\u6bcd\u5f00\u59cb\uff0c\u63a5\u7740\u8ddf\u968f0\u4e2a\u6216\u4efb\u610f\u4e2a\u5c0f\u5199\u5b57\u6bcd\uff0c\u8868\u793a\u539f\u5b50\u7684\u540d\u5b57\u3002

    \n\n

    \u5982\u679c\u6570\u91cf\u5927\u4e8e 1\uff0c\u539f\u5b50\u540e\u4f1a\u8ddf\u7740\u6570\u5b57\u8868\u793a\u539f\u5b50\u7684\u6570\u91cf\u3002\u5982\u679c\u6570\u91cf\u7b49\u4e8e 1 \u5219\u4e0d\u4f1a\u8ddf\u6570\u5b57\u3002\u4f8b\u5982\uff0cH2O \u548c H2O2 \u662f\u53ef\u884c\u7684\uff0c\u4f46 H1O2 \u8fd9\u4e2a\u8868\u8fbe\u662f\u4e0d\u53ef\u884c\u7684\u3002

    \n\n

    \u4e24\u4e2a\u5316\u5b66\u5f0f\u8fde\u5728\u4e00\u8d77\u662f\u65b0\u7684\u5316\u5b66\u5f0f\u3002\u4f8b\u5982 H2O2He3Mg4 \u4e5f\u662f\u5316\u5b66\u5f0f\u3002

    \n\n

    \u4e00\u4e2a\u62ec\u53f7\u4e2d\u7684\u5316\u5b66\u5f0f\u548c\u6570\u5b57\uff08\u53ef\u9009\u62e9\u6027\u6dfb\u52a0\uff09\u4e5f\u662f\u5316\u5b66\u5f0f\u3002\u4f8b\u5982 (H2O2) \u548c (H2O2)3 \u662f\u5316\u5b66\u5f0f\u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u5316\u5b66\u5f0f\uff0c\u8f93\u51fa\u6240\u6709\u539f\u5b50\u7684\u6570\u91cf\u3002\u683c\u5f0f\u4e3a\uff1a\u7b2c\u4e00\u4e2a\uff08\u6309\u5b57\u5178\u5e8f\uff09\u539f\u5b50\u7684\u540d\u5b50\uff0c\u8ddf\u7740\u5b83\u7684\u6570\u91cf\uff08\u5982\u679c\u6570\u91cf\u5927\u4e8e 1\uff09\uff0c\u7136\u540e\u662f\u7b2c\u4e8c\u4e2a\u539f\u5b50\u7684\u540d\u5b57\uff08\u6309\u5b57\u5178\u5e8f\uff09\uff0c\u8ddf\u7740\u5b83\u7684\u6570\u91cf\uff08\u5982\u679c\u6570\u91cf\u5927\u4e8e 1\uff09\uff0c\u4ee5\u6b64\u7c7b\u63a8\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: \nformula = "H2O"\n\u8f93\u51fa: "H2O"\n\u89e3\u91ca: \n\u539f\u5b50\u7684\u6570\u91cf\u662f {'H': 2, 'O': 1}\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: \nformula = "Mg(OH)2"\n\u8f93\u51fa: "H2MgO2"\n\u89e3\u91ca: \n\u539f\u5b50\u7684\u6570\u91cf\u662f {'H': 2, 'Mg': 1, 'O': 2}\u3002\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \n\u8f93\u5165: \nformula = "K4(ON(SO3)2)2"\n\u8f93\u51fa: "K4N2O14S4"\n\u89e3\u91ca: \n\u539f\u5b50\u7684\u6570\u91cf\u662f {'K': 4, 'N': 2, 'O': 14, 'S': 4}\u3002\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    • \u6240\u6709\u539f\u5b50\u7684\u7b2c\u4e00\u4e2a\u5b57\u6bcd\u4e3a\u5927\u5199\uff0c\u5269\u4f59\u5b57\u6bcd\u90fd\u662f\u5c0f\u5199\u3002
    • \n\t
    • formula\u7684\u957f\u5ea6\u5728[1, 1000]\u4e4b\u95f4\u3002
    • \n\t
    • formula\u53ea\u5305\u542b\u5b57\u6bcd\u3001\u6570\u5b57\u548c\u5706\u62ec\u53f7\uff0c\u5e76\u4e14\u9898\u76ee\u4e2d\u7ed9\u5b9a\u7684\u662f\u5408\u6cd5\u7684\u5316\u5b66\u5f0f\u3002
    • \n
    \n", "tags_en": ["Stack", "Recursion", "Hash Table"], "tags_cn": ["\u6808", "\u9012\u5f52", "\u54c8\u5e0c\u8868"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string countOfAtoms(string formula) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String countOfAtoms(String formula) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countOfAtoms(self, formula):\n \"\"\"\n :type formula: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countOfAtoms(self, formula: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * countOfAtoms(char * formula){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string CountOfAtoms(string formula) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} formula\n * @return {string}\n */\nvar countOfAtoms = function(formula) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} formula\n# @return {String}\ndef count_of_atoms(formula)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countOfAtoms(_ formula: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countOfAtoms(formula string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countOfAtoms(formula: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countOfAtoms(formula: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_of_atoms(formula: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $formula\n * @return String\n */\n function countOfAtoms($formula) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countOfAtoms(formula: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-of-atoms formula)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0726](https://leetcode-cn.com/problems/number-of-atoms)", "[\u539f\u5b50\u7684\u6570\u91cf](/solution/0700-0799/0726.Number%20of%20Atoms/README.md)", "`\u6808`,`\u9012\u5f52`,`\u54c8\u5e0c\u8868`", "\u56f0\u96be", ""], "md_table_row_en": ["[0726](https://leetcode.com/problems/number-of-atoms)", "[Number of Atoms](/solution/0700-0799/0726.Number%20of%20Atoms/README_EN.md)", "`Stack`,`Recursion`,`Hash Table`", "Hard", ""]}, {"question_id": "0725", "frontend_question_id": "0725", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/split-linked-list-in-parts", "url_en": "https://leetcode.com/problems/split-linked-list-in-parts", "relative_path_cn": "/solution/0700-0799/0725.Split%20Linked%20List%20in%20Parts/README.md", "relative_path_en": "/solution/0700-0799/0725.Split%20Linked%20List%20in%20Parts/README_EN.md", "title_cn": "\u5206\u9694\u94fe\u8868", "title_en": "Split Linked List in Parts", "question_title_slug": "split-linked-list-in-parts", "content_en": "

    Given a (singly) linked list with head node root, write a function to split the linked list into k consecutive linked list \"parts\".\r\n

    \r\nThe length of each part should be as equal as possible: no two parts should have a size differing by more than 1. This may lead to some parts being null.\r\n

    \r\nThe parts should be in order of occurrence in the input list, and parts occurring earlier should always have a size greater than or equal parts occurring later.\r\n

    \r\nReturn a List of ListNode's representing the linked list parts that are formed.\r\n

    \r\n\r\nExamples\r\n1->2->3->4, k = 5 // 5 equal parts\r\n[ [1], \r\n[2],\r\n[3],\r\n[4],\r\nnull ]\r\n\r\n

    Example 1:
    \r\n

    \r\nInput: \r\nroot = [1, 2, 3], k = 5\r\nOutput: [[1],[2],[3],[],[]]\r\nExplanation:\r\nThe input and each element of the output are ListNodes, not arrays.\r\nFor example, the input root has root.val = 1, root.next.val = 2, \\root.next.next.val = 3, and root.next.next.next = null.\r\nThe first element output[0] has output[0].val = 1, output[0].next = null.\r\nThe last element output[4] is null, but it's string representation as a ListNode is [].\r\n
    \r\n

    \r\n\r\n

    Example 2:
    \r\n

    \r\nInput: \r\nroot = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], k = 3\r\nOutput: [[1, 2, 3, 4], [5, 6, 7], [8, 9, 10]]\r\nExplanation:\r\nThe input has been split into consecutive parts with size difference at most 1, and earlier parts are a larger size than the later parts.\r\n
    \r\n

    \r\n\r\n

    Note:\r\n

  • The length of root will be in the range [0, 1000].
  • \r\n
  • Each value of a node in the input will be an integer in the range [0, 999].
  • \r\n
  • k will be an integer in the range [1, 50].
  • \r\n

    ", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5934\u7ed3\u70b9\u4e3a root \u7684\u94fe\u8868, \u7f16\u5199\u4e00\u4e2a\u51fd\u6570\u4ee5\u5c06\u94fe\u8868\u5206\u9694\u4e3a k \u4e2a\u8fde\u7eed\u7684\u90e8\u5206\u3002

    \n\n

    \u6bcf\u90e8\u5206\u7684\u957f\u5ea6\u5e94\u8be5\u5c3d\u53ef\u80fd\u7684\u76f8\u7b49: \u4efb\u610f\u4e24\u90e8\u5206\u7684\u957f\u5ea6\u5dee\u8ddd\u4e0d\u80fd\u8d85\u8fc7 1\uff0c\u4e5f\u5c31\u662f\u8bf4\u53ef\u80fd\u6709\u4e9b\u90e8\u5206\u4e3a null\u3002

    \n\n

    \u8fd9k\u4e2a\u90e8\u5206\u5e94\u8be5\u6309\u7167\u5728\u94fe\u8868\u4e2d\u51fa\u73b0\u7684\u987a\u5e8f\u8fdb\u884c\u8f93\u51fa\uff0c\u5e76\u4e14\u6392\u5728\u524d\u9762\u7684\u90e8\u5206\u7684\u957f\u5ea6\u5e94\u8be5\u5927\u4e8e\u6216\u7b49\u4e8e\u540e\u9762\u7684\u957f\u5ea6\u3002

    \n\n

    \u8fd4\u56de\u4e00\u4e2a\u7b26\u5408\u4e0a\u8ff0\u89c4\u5219\u7684\u94fe\u8868\u7684\u5217\u8868\u3002

    \n\n

    \u4e3e\u4f8b\uff1a 1->2->3->4, k = 5 // 5 \u7ed3\u679c [ [1], [2], [3], [4], null ]

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165: \nroot = [1, 2, 3], k = 5\n\u8f93\u51fa: [[1],[2],[3],[],[]]\n\u89e3\u91ca:\n\u8f93\u5165\u8f93\u51fa\u5404\u90e8\u5206\u90fd\u5e94\u8be5\u662f\u94fe\u8868\uff0c\u800c\u4e0d\u662f\u6570\u7ec4\u3002\n\u4f8b\u5982, \u8f93\u5165\u7684\u7ed3\u70b9 root \u7684 val= 1, root.next.val = 2, \\root.next.next.val = 3, \u4e14 root.next.next.next = null\u3002\n\u7b2c\u4e00\u4e2a\u8f93\u51fa output[0] \u662f output[0].val = 1, output[0].next = null\u3002\n\u6700\u540e\u4e00\u4e2a\u5143\u7d20 output[4] \u4e3a null, \u5b83\u4ee3\u8868\u4e86\u6700\u540e\u4e00\u4e2a\u90e8\u5206\u4e3a\u7a7a\u94fe\u8868\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165: \nroot = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], k = 3\n\u8f93\u51fa: [[1, 2, 3, 4], [5, 6, 7], [8, 9, 10]]\n\u89e3\u91ca:\n\u8f93\u5165\u88ab\u5206\u6210\u4e86\u51e0\u4e2a\u8fde\u7eed\u7684\u90e8\u5206\uff0c\u5e76\u4e14\u6bcf\u90e8\u5206\u7684\u957f\u5ea6\u76f8\u5dee\u4e0d\u8d85\u8fc71.\u524d\u9762\u90e8\u5206\u7684\u957f\u5ea6\u5927\u4e8e\u7b49\u4e8e\u540e\u9762\u90e8\u5206\u7684\u957f\u5ea6\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a:

    \n\n
      \n\t
    • root \u7684\u957f\u5ea6\u8303\u56f4\uff1a [0, 1000].
    • \n\t
    • \u8f93\u5165\u7684\u6bcf\u4e2a\u8282\u70b9\u7684\u5927\u5c0f\u8303\u56f4\uff1a[0, 999].
    • \n\t
    • k \u7684\u53d6\u503c\u8303\u56f4\uff1a [1, 50].
    • \n
    \n\n

     

    \n", "tags_en": ["Linked List"], "tags_cn": ["\u94fe\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\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 splitListToParts(ListNode* root, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode(int x) { val = x; }\n * }\n */\nclass Solution {\n public ListNode[] splitListToParts(ListNode root, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.next = None\n\nclass Solution(object):\n def splitListToParts(self, root, k):\n \"\"\"\n :type root: ListNode\n :type k: int\n :rtype: List[ListNode]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, x):\n# self.val = x\n# self.next = None\n\nclass Solution:\n def splitListToParts(self, root: ListNode, k: int) -> List[ListNode]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nstruct ListNode** splitListToParts(struct ListNode* root, int k, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int x) { val = x; }\n * }\n */\npublic class Solution {\n public ListNode[] SplitListToParts(ListNode root, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val) {\n * this.val = val;\n * this.next = null;\n * }\n */\n/**\n * @param {ListNode} root\n * @param {number} k\n * @return {ListNode[]}\n */\nvar splitListToParts = function(root, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val)\n# @val = val\n# @next = nil\n# end\n# end\n\n# @param {ListNode} root\n# @param {Integer} k\n# @return {ListNode[]}\ndef split_list_to_parts(root, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.next = nil\n * }\n * }\n */\nclass Solution {\n func splitListToParts(_ root: ListNode?, _ k: Int) -> [ListNode?] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc splitListToParts(root *ListNode, k int) []*ListNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(var _x: Int = 0) {\n * var next: ListNode = null\n * var x: Int = _x\n * }\n */\nobject Solution {\n def splitListToParts(root: ListNode, k: Int): Array[ListNode] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun splitListToParts(root: ListNode?, k: Int): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n// \n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn split_list_to_parts(root: Option>, k: i32) -> Vec>> {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val) { $this->val = $val; }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $root\n * @param Integer $k\n * @return ListNode[]\n */\n function splitListToParts($root, $k) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction splitListToParts(root: ListNode | null, k: number): Array {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (split-list-to-parts root k)\n (-> (or/c list-node? #f) exact-integer? (listof (or/c list-node? #f)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0725](https://leetcode-cn.com/problems/split-linked-list-in-parts)", "[\u5206\u9694\u94fe\u8868](/solution/0700-0799/0725.Split%20Linked%20List%20in%20Parts/README.md)", "`\u94fe\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0725](https://leetcode.com/problems/split-linked-list-in-parts)", "[Split Linked List in Parts](/solution/0700-0799/0725.Split%20Linked%20List%20in%20Parts/README_EN.md)", "`Linked List`", "Medium", ""]}, {"question_id": "0724", "frontend_question_id": "0724", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-pivot-index", "url_en": "https://leetcode.com/problems/find-pivot-index", "relative_path_cn": "/solution/0700-0799/0724.Find%20Pivot%20Index/README.md", "relative_path_en": "/solution/0700-0799/0724.Find%20Pivot%20Index/README_EN.md", "title_cn": "\u5bfb\u627e\u6570\u7ec4\u7684\u4e2d\u5fc3\u4e0b\u6807", "title_en": "Find Pivot Index", "question_title_slug": "find-pivot-index", "content_en": "

    Given an array of integers nums, calculate the pivot index of this array.

    \n\n

    The pivot index is the index where the sum of all the numbers strictly to the left of the index is equal to the sum of all the numbers strictly to the index's right.

    \n\n

    If the index is on the left edge of the array, then the left sum is 0 because there are no elements to the left. This also applies to the right edge of the array.

    \n\n

    Return the leftmost pivot index. If no such index exists, return -1.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,7,3,6,5,6]\nOutput: 3\nExplanation:\nThe pivot index is 3.\nLeft sum = nums[0] + nums[1] + nums[2] = 1 + 7 + 3 = 11\nRight sum = nums[4] + nums[5] = 5 + 6 = 11\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,2,3]\nOutput: -1\nExplanation:\nThere is no index that satisfies the conditions in the problem statement.
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [2,1,-1]\nOutput: 0\nExplanation:\nThe pivot index is 0.\nLeft sum = 0 (no elements to the left of index 0)\nRight sum = nums[1] + nums[2] = 1 + -1 = 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 104
    • \n\t
    • -1000 <= nums[i] <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0nums\uff0c\u8bf7\u7f16\u5199\u4e00\u4e2a\u80fd\u591f\u8fd4\u56de\u6570\u7ec4 \u201c\u4e2d\u5fc3\u4e0b\u6807\u201d \u7684\u65b9\u6cd5\u3002

    \n\n

    \u6570\u7ec4 \u4e2d\u5fc3\u4e0b\u6807 \u662f\u6570\u7ec4\u7684\u4e00\u4e2a\u4e0b\u6807\uff0c\u5176\u5de6\u4fa7\u6240\u6709\u5143\u7d20\u76f8\u52a0\u7684\u548c\u7b49\u4e8e\u53f3\u4fa7\u6240\u6709\u5143\u7d20\u76f8\u52a0\u7684\u548c\u3002

    \n\n

    \u5982\u679c\u6570\u7ec4\u4e0d\u5b58\u5728\u4e2d\u5fc3\u4e0b\u6807\uff0c\u8fd4\u56de -1 \u3002\u5982\u679c\u6570\u7ec4\u6709\u591a\u4e2a\u4e2d\u5fc3\u4e0b\u6807\uff0c\u5e94\u8be5\u8fd4\u56de\u6700\u9760\u8fd1\u5de6\u8fb9\u7684\u90a3\u4e00\u4e2a\u3002

    \n\n

    \u6ce8\u610f\uff1a\u4e2d\u5fc3\u4e0b\u6807\u53ef\u80fd\u51fa\u73b0\u5728\u6570\u7ec4\u7684\u4e24\u7aef\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1, 7, 3, 6, 5, 6]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\n\u4e2d\u5fc3\u4e0b\u6807\u662f 3 \u3002\n\u5de6\u4fa7\u6570\u4e4b\u548c (1 + 7 + 3 = 11)\uff0c\n\u53f3\u4fa7\u6570\u4e4b\u548c (5 + 6 = 11) \uff0c\u4e8c\u8005\u76f8\u7b49\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1, 2, 3]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\n\u6570\u7ec4\u4e2d\u4e0d\u5b58\u5728\u6ee1\u8db3\u6b64\u6761\u4ef6\u7684\u4e2d\u5fc3\u4e0b\u6807\u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [2, 1, -1]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\n\u4e2d\u5fc3\u4e0b\u6807\u662f 0 \u3002\n\u4e0b\u6807 0 \u5de6\u4fa7\u4e0d\u5b58\u5728\u5143\u7d20\uff0c\u89c6\u4f5c\u548c\u4e3a 0 \uff1b\n\u53f3\u4fa7\u6570\u4e4b\u548c\u4e3a 1 + (-1) = 0 \uff0c\u4e8c\u8005\u76f8\u7b49\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • nums \u7684\u957f\u5ea6\u8303\u56f4\u4e3a\u00a0[0, 10000]\u3002
    • \n\t
    • \u4efb\u4f55\u4e00\u4e2a\u00a0nums[i] \u5c06\u4f1a\u662f\u4e00\u4e2a\u8303\u56f4\u5728\u00a0[-1000, 1000]\u7684\u6574\u6570\u3002
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int pivotIndex(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int pivotIndex(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def pivotIndex(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def pivotIndex(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint pivotIndex(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int PivotIndex(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar pivotIndex = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef pivot_index(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func pivotIndex(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func pivotIndex(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def pivotIndex(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun pivotIndex(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn pivot_index(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function pivotIndex($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function pivotIndex(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (pivot-index nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0724](https://leetcode-cn.com/problems/find-pivot-index)", "[\u5bfb\u627e\u6570\u7ec4\u7684\u4e2d\u5fc3\u4e0b\u6807](/solution/0700-0799/0724.Find%20Pivot%20Index/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0724](https://leetcode.com/problems/find-pivot-index)", "[Find Pivot Index](/solution/0700-0799/0724.Find%20Pivot%20Index/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0723", "frontend_question_id": "0723", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/candy-crush", "url_en": "https://leetcode.com/problems/candy-crush", "relative_path_cn": "/solution/0700-0799/0723.Candy%20Crush/README.md", "relative_path_en": "/solution/0700-0799/0723.Candy%20Crush/README_EN.md", "title_cn": "\u7c89\u788e\u7cd6\u679c", "title_en": "Candy Crush", "question_title_slug": "candy-crush", "content_en": "

    This question is about implementing a basic elimination algorithm for Candy Crush.

    \n\n

    Given an m x n integer array board representing the grid of candy where board[i][j] represents the type of candy. A value of board[i][j] == 0 represents that the cell is empty.

    \n\n

    The given board represents the state of the game following the player's move. Now, you need to restore the board to a stable state by crushing candies according to the following rules:

    \n\n
      \n\t
    • If three or more candies of the same type are adjacent vertically or horizontally, crush them all at the same time - these positions become empty.
    • \n\t
    • After crushing all candies simultaneously, if an empty space on the board has candies on top of itself, then these candies will drop until they hit a candy or bottom at the same time. No new candies will drop outside the top boundary.
    • \n\t
    • After the above steps, there may exist more candies that can be crushed. If so, you need to repeat the above steps.
    • \n\t
    • If there does not exist more candies that can be crushed (i.e., the board is stable), then return the current board.
    • \n
    \n\n

    You need to perform the above rules until the board becomes stable, then return the stable board.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: board = [[110,5,112,113,114],[210,211,5,213,214],[310,311,3,313,314],[410,411,412,5,414],[5,1,512,3,3],[610,4,1,613,614],[710,1,2,713,714],[810,1,2,1,1],[1,1,2,2,2],[4,1,4,4,1014]]\nOutput: [[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[110,0,0,0,114],[210,0,0,0,214],[310,0,0,113,314],[410,0,0,213,414],[610,211,112,313,614],[710,311,412,613,714],[810,411,512,713,1014]]\n
    \n\n

    Example 2:

    \n\n
    \nInput: board = [[1,3,5,5,2],[3,4,3,3,1],[3,2,4,5,2],[2,4,4,5,5],[1,4,4,1,1]]\nOutput: [[1,3,0,0,0],[3,4,0,5,2],[3,2,0,3,1],[2,4,0,5,2],[1,4,3,1,1]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == board.length
    • \n\t
    • n == board[i].length
    • \n\t
    • 3 <= m, n <= 50
    • \n\t
    • 1 <= board[i][j] <= 2000
    • \n
    \n", "content_cn": "

    \u8fd9\u4e2a\u95ee\u9898\u662f\u5b9e\u73b0\u4e00\u4e2a\u7b80\u5355\u7684\u6d88\u9664\u7b97\u6cd5\u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u7ef4\u6574\u6570\u6570\u7ec4 board \u4ee3\u8868\u7cd6\u679c\u6240\u5728\u7684\u65b9\u683c\uff0c\u4e0d\u540c\u7684\u6b63\u6574\u6570 board[i][j] \u4ee3\u8868\u4e0d\u540c\u79cd\u7c7b\u7684\u7cd6\u679c\uff0c\u5982\u679c board[i][j] = 0 \u4ee3\u8868 (i, j) \u8fd9\u4e2a\u4f4d\u7f6e\u662f\u7a7a\u7684\u3002\u7ed9\u5b9a\u7684\u65b9\u683c\u662f\u73a9\u5bb6\u79fb\u52a8\u540e\u7684\u6e38\u620f\u72b6\u6001\uff0c\u73b0\u5728\u9700\u8981\u4f60\u6839\u636e\u4ee5\u4e0b\u89c4\u5219\u7c89\u788e\u7cd6\u679c\uff0c\u4f7f\u5f97\u6574\u4e2a\u65b9\u683c\u5904\u4e8e\u7a33\u5b9a\u72b6\u6001\u5e76\u6700\u7ec8\u8f93\u51fa\u3002

    \n\n
      \n\t
    1. \u5982\u679c\u6709\u4e09\u4e2a\u53ca\u4ee5\u4e0a\u6c34\u5e73\u6216\u8005\u5782\u76f4\u76f8\u8fde\u7684\u540c\u79cd\u7cd6\u679c\uff0c\u540c\u4e00\u65f6\u95f4\u5c06\u5b83\u4eec\u7c89\u788e\uff0c\u5373\u5c06\u8fd9\u4e9b\u4f4d\u7f6e\u53d8\u6210\u7a7a\u7684\u3002
    2. \n\t
    3. \u5728\u540c\u65f6\u7c89\u788e\u6389\u8fd9\u4e9b\u7cd6\u679c\u4e4b\u540e\uff0c\u5982\u679c\u6709\u4e00\u4e2a\u7a7a\u7684\u4f4d\u7f6e\u4e0a\u65b9\u8fd8\u6709\u7cd6\u679c\uff0c\u90a3\u4e48\u4e0a\u65b9\u7684\u7cd6\u679c\u5c31\u4f1a\u4e0b\u843d\u76f4\u5230\u78b0\u5230\u4e0b\u65b9\u7684\u7cd6\u679c\u6216\u8005\u5e95\u90e8\uff0c\u8fd9\u4e9b\u7cd6\u679c\u90fd\u662f\u540c\u65f6\u4e0b\u843d\uff0c\u4e5f\u4e0d\u4f1a\u6709\u65b0\u7684\u7cd6\u679c\u4ece\u9876\u90e8\u51fa\u73b0\u5e76\u843d\u4e0b\u6765\u3002
    4. \n\t
    5. \u901a\u8fc7\u524d\u4e24\u6b65\u7684\u64cd\u4f5c\uff0c\u53ef\u80fd\u53c8\u4f1a\u51fa\u73b0\u53ef\u4ee5\u7c89\u788e\u7684\u7cd6\u679c\uff0c\u8bf7\u7ee7\u7eed\u91cd\u590d\u524d\u9762\u7684\u64cd\u4f5c\u3002
    6. \n\t
    7. \u5f53\u4e0d\u5b58\u5728\u53ef\u4ee5\u7c89\u788e\u7684\u7cd6\u679c\uff0c\u4e5f\u5c31\u662f\u72b6\u6001\u7a33\u5b9a\u4e4b\u540e\uff0c\u8bf7\u8f93\u51fa\u6700\u7ec8\u7684\u72b6\u6001\u3002
    8. \n
    \n\n

    \u4f60\u9700\u8981\u6a21\u62df\u4e0a\u8ff0\u89c4\u5219\u5e76\u4f7f\u6574\u4e2a\u65b9\u683c\u8fbe\u5230\u7a33\u5b9a\u72b6\u6001\uff0c\u5e76\u8f93\u51fa\u3002

    \n\n

     

    \n\n

    \u6837\u4f8b :

    \n\n
    \u8f93\u5165:\nboard = \n[[110,5,112,113,114],[210,211,5,213,214],[310,311,3,313,314],[410,411,412,5,414],[5,1,512,3,3],[610,4,1,613,614],[710,1,2,713,714],[810,1,2,1,1],[1,1,2,2,2],[4,1,4,4,1014]]\n\n\u8f93\u51fa:\n[[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[110,0,0,0,114],[210,0,0,0,214],[310,0,0,113,314],[410,0,0,213,414],[610,211,112,313,614],[710,311,412,613,714],[810,411,512,713,1014]]\n\n\u89e3\u91ca: \n\n
    \n\n

     

    \n\n

    \u6ce8\u91ca :

    \n\n
      \n\t
    1. board \u6570\u7ec4\u7684\u884c\u6570\u533a\u95f4\u662f [3, 50]\u3002
    2. \n\t
    3. board[i] \u6570\u7ec4\u7684\u957f\u5ea6\u533a\u95f4\uff08\u5373 board \u6570\u7ec4\u7684\u5217\u6570\u533a\u95f4\uff09\u662f [3, 50]\u3002
    4. \n\t
    5. \u6bcf\u4e2a board[i][j] \u521d\u59cb\u6574\u6570\u8303\u56f4\u662f [1, 2000]\u3002
    6. \n
    \n", "tags_en": ["Array", "Two Pointers"], "tags_cn": ["\u6570\u7ec4", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> candyCrush(vector>& board) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[][] candyCrush(int[][] board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def candyCrush(self, board):\n \"\"\"\n :type board: List[List[int]]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def candyCrush(self, board: List[List[int]]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** candyCrush(int** board, int boardSize, int* boardColSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[][] CandyCrush(int[][] board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} board\n * @return {number[][]}\n */\nvar candyCrush = function(board) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} board\n# @return {Integer[][]}\ndef candy_crush(board)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func candyCrush(_ board: [[Int]]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func candyCrush(board [][]int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def candyCrush(board: Array[Array[Int]]): Array[Array[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun candyCrush(board: Array): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn candy_crush(board: Vec>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $board\n * @return Integer[][]\n */\n function candyCrush($board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function candyCrush(board: number[][]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (candy-crush board)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0723](https://leetcode-cn.com/problems/candy-crush)", "[\u7c89\u788e\u7cd6\u679c](/solution/0700-0799/0723.Candy%20Crush/README.md)", "`\u6570\u7ec4`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0723](https://leetcode.com/problems/candy-crush)", "[Candy Crush](/solution/0700-0799/0723.Candy%20Crush/README_EN.md)", "`Array`,`Two Pointers`", "Medium", "\ud83d\udd12"]}, {"question_id": "0722", "frontend_question_id": "0722", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/remove-comments", "url_en": "https://leetcode.com/problems/remove-comments", "relative_path_cn": "/solution/0700-0799/0722.Remove%20Comments/README.md", "relative_path_en": "/solution/0700-0799/0722.Remove%20Comments/README_EN.md", "title_cn": "\u5220\u9664\u6ce8\u91ca", "title_en": "Remove Comments", "question_title_slug": "remove-comments", "content_en": "

    Given a C++ program, remove comments from it. The program source is an array where source[i] is the i-th line of the source code. This represents the result of splitting the original source code string by the newline character \\n.

    \r\n\r\n

    In C++, there are two types of comments, line comments, and block comments.

    \r\n

    \r\nThe string // denotes a line comment, which represents that it and rest of the characters to the right of it in the same line should be ignored.\r\n

    \r\nThe string /* denotes a block comment, which represents that all characters until the next (non-overlapping) occurrence of */ should be ignored. (Here, occurrences happen in reading order: line by line from left to right.) To be clear, the string /*/ does not yet end the block comment, as the ending would be overlapping the beginning.\r\n

    \r\nThe first effective comment takes precedence over others: if the string // occurs in a block comment, it is ignored. Similarly, if the string /* occurs in a line or block comment, it is also ignored.\r\n

    \r\nIf a certain line of code is empty after removing comments, you must not output that line: each string in the answer list will be non-empty.\r\n

    \r\nThere will be no control characters, single quote, or double quote characters. For example, source = \"string s = \"/* Not a comment. */\";\" will not be a test case. (Also, nothing else such as defines or macros will interfere with the comments.)\r\n

    \r\nIt is guaranteed that every open block comment will eventually be closed, so /* outside of a line or block comment always starts a new comment.\r\n

    \r\nFinally, implicit newline characters can be deleted by block comments. Please see the examples below for details.\r\n

    \r\n\r\n

    After removing the comments from the source code, return the source code in the same format.

    \r\n\r\n

    Example 1:
    \r\n

    \r\nInput: \r\nsource = [\"/*Test program */\", \"int main()\", \"{ \", \"  // variable declaration \", \"int a, b, c;\", \"/* This is a test\", \"   multiline  \", \"   comment for \", \"   testing */\", \"a = b + c;\", \"}\"]\r\n\r\nThe line by line code is visualized as below:\r\n/*Test program */\r\nint main()\r\n{ \r\n  // variable declaration \r\nint a, b, c;\r\n/* This is a test\r\n   multiline  \r\n   comment for \r\n   testing */\r\na = b + c;\r\n}\r\n\r\nOutput: [\"int main()\",\"{ \",\"  \",\"int a, b, c;\",\"a = b + c;\",\"}\"]\r\n\r\nThe line by line code is visualized as below:\r\nint main()\r\n{ \r\n  \r\nint a, b, c;\r\na = b + c;\r\n}\r\n\r\nExplanation: \r\nThe string /* denotes a block comment, including line 1 and lines 6-9. The string // denotes line 4 as comments.\r\n
    \r\n

    \r\n\r\n

    Example 2:
    \r\n

    \r\nInput: \r\nsource = [\"a/*comment\", \"line\", \"more_comment*/b\"]\r\nOutput: [\"ab\"]\r\nExplanation: The original source string is \"a/*comment\\nline\\nmore_comment*/b\", where we have bolded the newline characters.  After deletion, the implicit newline characters are deleted, leaving the string \"ab\", which when delimited by newline characters becomes [\"ab\"].\r\n
    \r\n

    \r\n\r\n

    Note:\r\n

  • The length of source is in the range [1, 100].
  • \r\n
  • The length of source[i] is in the range [0, 80].
  • \r\n
  • Every open block comment is eventually closed.
  • \r\n
  • There are no single-quote, double-quote, or control characters in the source code.
  • \r\n

    ", "content_cn": "

    \u7ed9\u4e00\u4e2a C++ \u7a0b\u5e8f\uff0c\u5220\u9664\u7a0b\u5e8f\u4e2d\u7684\u6ce8\u91ca\u3002\u8fd9\u4e2a\u7a0b\u5e8fsource\u662f\u4e00\u4e2a\u6570\u7ec4\uff0c\u5176\u4e2dsource[i]\u8868\u793a\u7b2ci\u884c\u6e90\u7801\u3002 \u8fd9\u8868\u793a\u6bcf\u884c\u6e90\u7801\u7531\\n\u5206\u9694\u3002

    \n\n

    \u5728 C++ \u4e2d\u6709\u4e24\u79cd\u6ce8\u91ca\u98ce\u683c\uff0c\u884c\u5185\u6ce8\u91ca\u548c\u5757\u6ce8\u91ca\u3002

    \n\n

    \u5b57\u7b26\u4e32// \u8868\u793a\u884c\u6ce8\u91ca\uff0c\u8868\u793a//\u548c\u5176\u53f3\u4fa7\u7684\u5176\u4f59\u5b57\u7b26\u5e94\u8be5\u88ab\u5ffd\u7565\u3002

    \n\n

    \u5b57\u7b26\u4e32/* \u8868\u793a\u4e00\u4e2a\u5757\u6ce8\u91ca\uff0c\u5b83\u8868\u793a\u76f4\u5230*/\u7684\u4e0b\u4e00\u4e2a\uff08\u975e\u91cd\u53e0\uff09\u51fa\u73b0\u7684\u6240\u6709\u5b57\u7b26\u90fd\u5e94\u8be5\u88ab\u5ffd\u7565\u3002\uff08\u9605\u8bfb\u987a\u5e8f\u4e3a\u4ece\u5de6\u5230\u53f3\uff09\u975e\u91cd\u53e0\u662f\u6307\uff0c\u5b57\u7b26\u4e32/*/\u5e76\u6ca1\u6709\u7ed3\u675f\u5757\u6ce8\u91ca\uff0c\u56e0\u4e3a\u6ce8\u91ca\u7684\u7ed3\u5c3e\u4e0e\u5f00\u5934\u76f8\u91cd\u53e0\u3002

    \n\n

    \u7b2c\u4e00\u4e2a\u6709\u6548\u6ce8\u91ca\u4f18\u5148\u4e8e\u5176\u4ed6\u6ce8\u91ca\uff1a\u5982\u679c\u5b57\u7b26\u4e32//\u51fa\u73b0\u5728\u5757\u6ce8\u91ca\u4e2d\u4f1a\u88ab\u5ffd\u7565\u3002 \u540c\u6837\uff0c\u5982\u679c\u5b57\u7b26\u4e32/*\u51fa\u73b0\u5728\u884c\u6216\u5757\u6ce8\u91ca\u4e2d\u4e5f\u4f1a\u88ab\u5ffd\u7565\u3002

    \n\n

    \u5982\u679c\u4e00\u884c\u5728\u5220\u9664\u6ce8\u91ca\u4e4b\u540e\u53d8\u4e3a\u7a7a\u5b57\u7b26\u4e32\uff0c\u90a3\u4e48\u4e0d\u8981\u8f93\u51fa\u8be5\u884c\u3002\u5373\uff0c\u7b54\u6848\u5217\u8868\u4e2d\u7684\u6bcf\u4e2a\u5b57\u7b26\u4e32\u90fd\u662f\u975e\u7a7a\u7684\u3002

    \n\n

    \u6837\u4f8b\u4e2d\u6ca1\u6709\u63a7\u5236\u5b57\u7b26\uff0c\u5355\u5f15\u53f7\u6216\u53cc\u5f15\u53f7\u5b57\u7b26\u3002\u6bd4\u5982\uff0csource = "string s = "/* Not a comment. */";" \u4e0d\u4f1a\u51fa\u73b0\u5728\u6d4b\u8bd5\u6837\u4f8b\u91cc\u3002\uff08\u6b64\u5916\uff0c\u6ca1\u6709\u5176\u4ed6\u5185\u5bb9\uff08\u5982\u5b9a\u4e49\u6216\u5b8f\uff09\u4f1a\u5e72\u6270\u6ce8\u91ca\u3002\uff09

    \n\n

    \u6211\u4eec\u4fdd\u8bc1\u6bcf\u4e00\u4e2a\u5757\u6ce8\u91ca\u6700\u7ec8\u90fd\u4f1a\u88ab\u95ed\u5408\uff0c \u6240\u4ee5\u5728\u884c\u6216\u5757\u6ce8\u91ca\u4e4b\u5916\u7684/*\u603b\u662f\u5f00\u59cb\u65b0\u7684\u6ce8\u91ca\u3002

    \n\n

    \u6700\u540e\uff0c\u9690\u5f0f\u6362\u884c\u7b26\u53ef\u4ee5\u901a\u8fc7\u5757\u6ce8\u91ca\u5220\u9664\u3002 \u6709\u5173\u8be6\u7ec6\u4fe1\u606f\uff0c\u8bf7\u53c2\u9605\u4e0b\u9762\u7684\u793a\u4f8b\u3002

    \n\n

    \u4ece\u6e90\u4ee3\u7801\u4e2d\u5220\u9664\u6ce8\u91ca\u540e\uff0c\u9700\u8981\u4ee5\u76f8\u540c\u7684\u683c\u5f0f\u8fd4\u56de\u6e90\u4ee3\u7801\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: \nsource = ["/*Test program */", "int main()", "{ ", "  // variable declaration ", "int a, b, c;", "/* This is a test", "   multiline  ", "   comment for ", "   testing */", "a = b + c;", "}"]\n\n\u793a\u4f8b\u4ee3\u7801\u53ef\u4ee5\u7f16\u6392\u6210\u8fd9\u6837:\n/*Test program */\nint main()\n{ \n  // variable declaration \nint a, b, c;\n/* This is a test\n   multiline  \n   comment for \n   testing */\na = b + c;\n}\n\n\u8f93\u51fa: ["int main()","{ ","  ","int a, b, c;","a = b + c;","}"]\n\n\u7f16\u6392\u540e:\nint main()\n{ \n  \nint a, b, c;\na = b + c;\n}\n\n\u89e3\u91ca: \n\u7b2c 1 \u884c\u548c\u7b2c 6-9 \u884c\u7684\u5b57\u7b26\u4e32 /* \u8868\u793a\u5757\u6ce8\u91ca\u3002\u7b2c 4 \u884c\u7684\u5b57\u7b26\u4e32 // \u8868\u793a\u884c\u6ce8\u91ca\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: \nsource = ["a/*comment", "line", "more_comment*/b"]\n\u8f93\u51fa: ["ab"]\n\u89e3\u91ca: \u539f\u59cb\u7684 source \u5b57\u7b26\u4e32\u662f "a/*comment\\nline\\nmore_comment*/b", \u5176\u4e2d\u6211\u4eec\u7528\u7c97\u4f53\u663e\u793a\u4e86\u6362\u884c\u7b26\u3002\u5220\u9664\u6ce8\u91ca\u540e\uff0c\u9690\u542b\u7684\u6362\u884c\u7b26\u88ab\u5220\u9664\uff0c\u7559\u4e0b\u5b57\u7b26\u4e32 "ab" \u7528\u6362\u884c\u7b26\u5206\u9694\u6210\u6570\u7ec4\u65f6\u5c31\u662f ["ab"].\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    • source\u7684\u957f\u5ea6\u8303\u56f4\u4e3a[1, 100].
    • \n\t
    • source[i]\u7684\u957f\u5ea6\u8303\u56f4\u4e3a[0, 80].
    • \n\t
    • \u6bcf\u4e2a\u5757\u6ce8\u91ca\u90fd\u4f1a\u88ab\u95ed\u5408\u3002
    • \n\t
    • \u7ed9\u5b9a\u7684\u6e90\u7801\u4e2d\u4e0d\u4f1a\u6709\u5355\u5f15\u53f7\u3001\u53cc\u5f15\u53f7\u6216\u5176\u4ed6\u63a7\u5236\u5b57\u7b26\u3002
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector removeComments(vector& source) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List removeComments(String[] source) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def removeComments(self, source):\n \"\"\"\n :type source: List[str]\n :rtype: List[str]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def removeComments(self, source: List[str]) -> List[str]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** removeComments(char ** source, int sourceSize, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList RemoveComments(string[] source) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} source\n * @return {string[]}\n */\nvar removeComments = function(source) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} source\n# @return {String[]}\ndef remove_comments(source)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func removeComments(_ source: [String]) -> [String] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func removeComments(source []string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def removeComments(source: Array[String]): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun removeComments(source: Array): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn remove_comments(source: Vec) -> Vec {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $source\n * @return String[]\n */\n function removeComments($source) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function removeComments(source: string[]): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (remove-comments source)\n (-> (listof string?) (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0722](https://leetcode-cn.com/problems/remove-comments)", "[\u5220\u9664\u6ce8\u91ca](/solution/0700-0799/0722.Remove%20Comments/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0722](https://leetcode.com/problems/remove-comments)", "[Remove Comments](/solution/0700-0799/0722.Remove%20Comments/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "0721", "frontend_question_id": "0721", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/accounts-merge", "url_en": "https://leetcode.com/problems/accounts-merge", "relative_path_cn": "/solution/0700-0799/0721.Accounts%20Merge/README.md", "relative_path_en": "/solution/0700-0799/0721.Accounts%20Merge/README_EN.md", "title_cn": "\u8d26\u6237\u5408\u5e76", "title_en": "Accounts Merge", "question_title_slug": "accounts-merge", "content_en": "

    Given a list of accounts where each element accounts[i] is a list of strings, where the first element accounts[i][0] is a name, and the rest of the elements are emails representing emails of the account.

    \n\n

    Now, we would like to merge these accounts. Two accounts definitely belong to the same person if there is some common email to both accounts. Note that even if two accounts have the same name, they may belong to different people as people could have the same name. A person can have any number of accounts initially, but all of their accounts definitely have the same name.

    \n\n

    After merging the accounts, return the accounts in the following format: the first element of each account is the name, and the rest of the elements are emails in sorted order. The accounts themselves can be returned in any order.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: accounts = [["John","johnsmith@mail.com","john_newyork@mail.com"],["John","johnsmith@mail.com","john00@mail.com"],["Mary","mary@mail.com"],["John","johnnybravo@mail.com"]]\nOutput: [["John","john00@mail.com","john_newyork@mail.com","johnsmith@mail.com"],["Mary","mary@mail.com"],["John","johnnybravo@mail.com"]]\nExplanation:\nThe first and third John's are the same person as they have the common email "johnsmith@mail.com".\nThe second John and Mary are different people as none of their email addresses are used by other accounts.\nWe could return these lists in any order, for example the answer [['Mary', 'mary@mail.com'], ['John', 'johnnybravo@mail.com'], \n['John', 'john00@mail.com', 'john_newyork@mail.com', 'johnsmith@mail.com']] would still be accepted.\n
    \n\n

    Example 2:

    \n\n
    \nInput: accounts = [["Gabe","Gabe0@m.co","Gabe3@m.co","Gabe1@m.co"],["Kevin","Kevin3@m.co","Kevin5@m.co","Kevin0@m.co"],["Ethan","Ethan5@m.co","Ethan4@m.co","Ethan0@m.co"],["Hanzo","Hanzo3@m.co","Hanzo1@m.co","Hanzo0@m.co"],["Fern","Fern5@m.co","Fern1@m.co","Fern0@m.co"]]\nOutput: [["Ethan","Ethan0@m.co","Ethan4@m.co","Ethan5@m.co"],["Gabe","Gabe0@m.co","Gabe1@m.co","Gabe3@m.co"],["Hanzo","Hanzo0@m.co","Hanzo1@m.co","Hanzo3@m.co"],["Kevin","Kevin0@m.co","Kevin3@m.co","Kevin5@m.co"],["Fern","Fern0@m.co","Fern1@m.co","Fern5@m.co"]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= accounts.length <= 1000
    • \n\t
    • 2 <= accounts[i].length <= 10
    • \n\t
    • 1 <= accounts[i][j] <= 30
    • \n\t
    • accounts[i][0] consists of English letters.
    • \n\t
    • accounts[i][j] (for j > 0) is a valid email.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5217\u8868 accounts\uff0c\u6bcf\u4e2a\u5143\u7d20 accounts[i]\u00a0\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\u5217\u8868\uff0c\u5176\u4e2d\u7b2c\u4e00\u4e2a\u5143\u7d20 accounts[i][0]\u00a0\u662f\u00a0\u540d\u79f0 (name)\uff0c\u5176\u4f59\u5143\u7d20\u662f emails \u8868\u793a\u8be5\u8d26\u6237\u7684\u90ae\u7bb1\u5730\u5740\u3002

    \n\n

    \u73b0\u5728\uff0c\u6211\u4eec\u60f3\u5408\u5e76\u8fd9\u4e9b\u8d26\u6237\u3002\u5982\u679c\u4e24\u4e2a\u8d26\u6237\u90fd\u6709\u4e00\u4e9b\u5171\u540c\u7684\u90ae\u7bb1\u5730\u5740\uff0c\u5219\u4e24\u4e2a\u8d26\u6237\u5fc5\u5b9a\u5c5e\u4e8e\u540c\u4e00\u4e2a\u4eba\u3002\u8bf7\u6ce8\u610f\uff0c\u5373\u4f7f\u4e24\u4e2a\u8d26\u6237\u5177\u6709\u76f8\u540c\u7684\u540d\u79f0\uff0c\u5b83\u4eec\u4e5f\u53ef\u80fd\u5c5e\u4e8e\u4e0d\u540c\u7684\u4eba\uff0c\u56e0\u4e3a\u4eba\u4eec\u53ef\u80fd\u5177\u6709\u76f8\u540c\u7684\u540d\u79f0\u3002\u4e00\u4e2a\u4eba\u6700\u521d\u53ef\u4ee5\u62e5\u6709\u4efb\u610f\u6570\u91cf\u7684\u8d26\u6237\uff0c\u4f46\u5176\u6240\u6709\u8d26\u6237\u90fd\u5177\u6709\u76f8\u540c\u7684\u540d\u79f0\u3002

    \n\n

    \u5408\u5e76\u8d26\u6237\u540e\uff0c\u6309\u4ee5\u4e0b\u683c\u5f0f\u8fd4\u56de\u8d26\u6237\uff1a\u6bcf\u4e2a\u8d26\u6237\u7684\u7b2c\u4e00\u4e2a\u5143\u7d20\u662f\u540d\u79f0\uff0c\u5176\u4f59\u5143\u7d20\u662f\u6309\u5b57\u7b26 ASCII \u987a\u5e8f\u6392\u5217\u7684\u90ae\u7bb1\u5730\u5740\u3002\u8d26\u6237\u672c\u8eab\u53ef\u4ee5\u4ee5\u4efb\u610f\u987a\u5e8f\u8fd4\u56de\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\naccounts = [[\"John\", \"johnsmith@mail.com\", \"john00@mail.com\"], [\"John\", \"johnnybravo@mail.com\"], [\"John\", \"johnsmith@mail.com\", \"john_newyork@mail.com\"], [\"Mary\", \"mary@mail.com\"]]\n\u8f93\u51fa\uff1a\n[[\"John\", 'john00@mail.com', 'john_newyork@mail.com', 'johnsmith@mail.com'],  [\"John\", \"johnnybravo@mail.com\"], [\"Mary\", \"mary@mail.com\"]]\n\u89e3\u91ca\uff1a\n\u7b2c\u4e00\u4e2a\u548c\u7b2c\u4e09\u4e2a John \u662f\u540c\u4e00\u4e2a\u4eba\uff0c\u56e0\u4e3a\u4ed6\u4eec\u6709\u5171\u540c\u7684\u90ae\u7bb1\u5730\u5740 \"johnsmith@mail.com\"\u3002 \n\u7b2c\u4e8c\u4e2a John \u548c Mary \u662f\u4e0d\u540c\u7684\u4eba\uff0c\u56e0\u4e3a\u4ed6\u4eec\u7684\u90ae\u7bb1\u5730\u5740\u6ca1\u6709\u88ab\u5176\u4ed6\u5e10\u6237\u4f7f\u7528\u3002\n\u53ef\u4ee5\u4ee5\u4efb\u4f55\u987a\u5e8f\u8fd4\u56de\u8fd9\u4e9b\u5217\u8868\uff0c\u4f8b\u5982\u7b54\u6848 [['Mary'\uff0c'mary@mail.com']\uff0c['John'\uff0c'johnnybravo@mail.com']\uff0c\n['John'\uff0c'john00@mail.com'\uff0c'john_newyork@mail.com'\uff0c'johnsmith@mail.com']] \u4e5f\u662f\u6b63\u786e\u7684\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • accounts\u7684\u957f\u5ea6\u5c06\u5728[1\uff0c1000]\u7684\u8303\u56f4\u5185\u3002
    • \n\t
    • accounts[i]\u7684\u957f\u5ea6\u5c06\u5728[1\uff0c10]\u7684\u8303\u56f4\u5185\u3002
    • \n\t
    • accounts[i][j]\u7684\u957f\u5ea6\u5c06\u5728[1\uff0c30]\u7684\u8303\u56f4\u5185\u3002
    • \n
    \n", "tags_en": ["Depth-first Search", "Union Find"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e76\u67e5\u96c6"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> accountsMerge(vector>& accounts) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> accountsMerge(List> accounts) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def accountsMerge(self, accounts):\n \"\"\"\n :type accounts: List[List[str]]\n :rtype: List[List[str]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def accountsMerge(self, accounts: List[List[str]]) -> List[List[str]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nchar *** accountsMerge(char *** accounts, int accountsSize, int* accountsColSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> AccountsMerge(IList> accounts) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[][]} accounts\n * @return {string[][]}\n */\nvar accountsMerge = function(accounts) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[][]} accounts\n# @return {String[][]}\ndef accounts_merge(accounts)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func accountsMerge(_ accounts: [[String]]) -> [[String]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func accountsMerge(accounts [][]string) [][]string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def accountsMerge(accounts: List[List[String]]): List[List[String]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun accountsMerge(accounts: List>): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn accounts_merge(accounts: Vec>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $accounts\n * @return String[][]\n */\n function accountsMerge($accounts) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function accountsMerge(accounts: string[][]): string[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (accounts-merge accounts)\n (-> (listof (listof string?)) (listof (listof string?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0721](https://leetcode-cn.com/problems/accounts-merge)", "[\u8d26\u6237\u5408\u5e76](/solution/0700-0799/0721.Accounts%20Merge/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e76\u67e5\u96c6`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0721](https://leetcode.com/problems/accounts-merge)", "[Accounts Merge](/solution/0700-0799/0721.Accounts%20Merge/README_EN.md)", "`Depth-first Search`,`Union Find`", "Medium", ""]}, {"question_id": "0720", "frontend_question_id": "0720", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-word-in-dictionary", "url_en": "https://leetcode.com/problems/longest-word-in-dictionary", "relative_path_cn": "/solution/0700-0799/0720.Longest%20Word%20in%20Dictionary/README.md", "relative_path_en": "/solution/0700-0799/0720.Longest%20Word%20in%20Dictionary/README_EN.md", "title_cn": "\u8bcd\u5178\u4e2d\u6700\u957f\u7684\u5355\u8bcd", "title_en": "Longest Word in Dictionary", "question_title_slug": "longest-word-in-dictionary", "content_en": "

    Given an array of strings words representing an English Dictionary, return the longest word in words that can be built one character at a time by other words in words.

    \n\n

    If there is more than one possible answer, return the longest word with the smallest lexicographical order. If there is no answer, return the empty string.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: words = ["w","wo","wor","worl","world"]\nOutput: "world"\nExplanation: The word "world" can be built one character at a time by "w", "wo", "wor", and "worl".\n
    \n\n

    Example 2:

    \n\n
    \nInput: words = ["a","banana","app","appl","ap","apply","apple"]\nOutput: "apple"\nExplanation: Both "apply" and "apple" can be built from other words in the dictionary. However, "apple" is lexicographically smaller than "apply".\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= words.length <= 1000
    • \n\t
    • 1 <= words[i].length <= 30
    • \n\t
    • words[i] consists of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u51fa\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4words\u7ec4\u6210\u7684\u4e00\u672c\u82f1\u8bed\u8bcd\u5178\u3002\u4ece\u4e2d\u627e\u51fa\u6700\u957f\u7684\u4e00\u4e2a\u5355\u8bcd\uff0c\u8be5\u5355\u8bcd\u662f\u7531words\u8bcd\u5178\u4e2d\u5176\u4ed6\u5355\u8bcd\u9010\u6b65\u6dfb\u52a0\u4e00\u4e2a\u5b57\u6bcd\u7ec4\u6210\u3002\u82e5\u5176\u4e2d\u6709\u591a\u4e2a\u53ef\u884c\u7684\u7b54\u6848\uff0c\u5219\u8fd4\u56de\u7b54\u6848\u4e2d\u5b57\u5178\u5e8f\u6700\u5c0f\u7684\u5355\u8bcd\u3002

    \n\n

    \u82e5\u65e0\u7b54\u6848\uff0c\u5219\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a\nwords = ["w","wo","wor","worl", "world"]\n\u8f93\u51fa\uff1a"world"\n\u89e3\u91ca\uff1a \n\u5355\u8bcd"world"\u53ef\u7531"w", "wo", "wor", \u548c "worl"\u6dfb\u52a0\u4e00\u4e2a\u5b57\u6bcd\u7ec4\u6210\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a\nwords = ["a", "banana", "app", "appl", "ap", "apply", "apple"]\n\u8f93\u51fa\uff1a"apple"\n\u89e3\u91ca\uff1a\n"apply"\u548c"apple"\u90fd\u80fd\u7531\u8bcd\u5178\u4e2d\u7684\u5355\u8bcd\u7ec4\u6210\u3002\u4f46\u662f"apple"\u7684\u5b57\u5178\u5e8f\u5c0f\u4e8e"apply"\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6240\u6709\u8f93\u5165\u7684\u5b57\u7b26\u4e32\u90fd\u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd\u3002
    • \n\t
    • words\u6570\u7ec4\u957f\u5ea6\u8303\u56f4\u4e3a[1,1000]\u3002
    • \n\t
    • words[i]\u7684\u957f\u5ea6\u8303\u56f4\u4e3a[1,30]\u3002
    • \n
    \n", "tags_en": ["Trie", "Hash Table"], "tags_cn": ["\u5b57\u5178\u6811", "\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string longestWord(vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String longestWord(String[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestWord(self, words):\n \"\"\"\n :type words: List[str]\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestWord(self, words: List[str]) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * longestWord(char ** words, int wordsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string LongestWord(string[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @return {string}\n */\nvar longestWord = function(words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @return {String}\ndef longest_word(words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestWord(_ words: [String]) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestWord(words []string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestWord(words: Array[String]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestWord(words: Array): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_word(words: Vec) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @return String\n */\n function longestWord($words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestWord(words: string[]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-word words)\n (-> (listof string?) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0720](https://leetcode-cn.com/problems/longest-word-in-dictionary)", "[\u8bcd\u5178\u4e2d\u6700\u957f\u7684\u5355\u8bcd](/solution/0700-0799/0720.Longest%20Word%20in%20Dictionary/README.md)", "`\u5b57\u5178\u6811`,`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0720](https://leetcode.com/problems/longest-word-in-dictionary)", "[Longest Word in Dictionary](/solution/0700-0799/0720.Longest%20Word%20in%20Dictionary/README_EN.md)", "`Trie`,`Hash Table`", "Easy", ""]}, {"question_id": "0719", "frontend_question_id": "0719", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-k-th-smallest-pair-distance", "url_en": "https://leetcode.com/problems/find-k-th-smallest-pair-distance", "relative_path_cn": "/solution/0700-0799/0719.Find%20K-th%20Smallest%20Pair%20Distance/README.md", "relative_path_en": "/solution/0700-0799/0719.Find%20K-th%20Smallest%20Pair%20Distance/README_EN.md", "title_cn": "\u627e\u51fa\u7b2c k \u5c0f\u7684\u8ddd\u79bb\u5bf9", "title_en": "Find K-th Smallest Pair Distance", "question_title_slug": "find-k-th-smallest-pair-distance", "content_en": "

    The distance of a pair of integers a and b is defined as the absolute difference between a and b.

    \n\n

    Given an integer array nums and an integer k, return the kth smallest distance among all the pairs nums[i] and nums[j] where 0 <= i < j < nums.length.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,3,1], k = 1\nOutput: 0\nExplanation: Here are all the pairs:\n(1,3) -> 2\n(1,1) -> 0\n(3,1) -> 2\nThen the 1st smallest distance pair is (1,1), and its distance is 0.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,1,1], k = 2\nOutput: 0\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [1,6,1], k = 3\nOutput: 5\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 2 <= n <= 104
    • \n\t
    • 0 <= nums[i] <= 106
    • \n\t
    • 1 <= k <= n * (n - 1) / 2
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\uff0c\u8fd4\u56de\u6240\u6709\u6570\u5bf9\u4e4b\u95f4\u7684\u7b2c k \u4e2a\u6700\u5c0f\u8ddd\u79bb\u3002\u4e00\u5bf9 (A, B) \u7684\u8ddd\u79bb\u88ab\u5b9a\u4e49\u4e3a A \u548c B \u4e4b\u95f4\u7684\u7edd\u5bf9\u5dee\u503c\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165\uff1a\nnums = [1,3,1]\nk = 1\n\u8f93\u51fa\uff1a0 \n\u89e3\u91ca\uff1a\n\u6240\u6709\u6570\u5bf9\u5982\u4e0b\uff1a\n(1,3) -> 2\n(1,1) -> 0\n(3,1) -> 2\n\u56e0\u6b64\u7b2c 1 \u4e2a\u6700\u5c0f\u8ddd\u79bb\u7684\u6570\u5bf9\u662f (1,1)\uff0c\u5b83\u4eec\u4e4b\u95f4\u7684\u8ddd\u79bb\u4e3a 0\u3002\n
    \n\n

    \u63d0\u793a:

    \n\n
      \n\t
    1. 2 <= len(nums) <= 10000.
    2. \n\t
    3. 0 <= nums[i] < 1000000.
    4. \n\t
    5. 1 <= k <= len(nums) * (len(nums) - 1) / 2.
    6. \n
    \n", "tags_en": ["Heap", "Array", "Binary Search"], "tags_cn": ["\u5806", "\u6570\u7ec4", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int smallestDistancePair(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int smallestDistancePair(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def smallestDistancePair(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def smallestDistancePair(self, nums: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint smallestDistancePair(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SmallestDistancePair(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar smallestDistancePair = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef smallest_distance_pair(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func smallestDistancePair(_ nums: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func smallestDistancePair(nums []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def smallestDistancePair(nums: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun smallestDistancePair(nums: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn smallest_distance_pair(nums: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer\n */\n function smallestDistancePair($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function smallestDistancePair(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (smallest-distance-pair nums k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0719](https://leetcode-cn.com/problems/find-k-th-smallest-pair-distance)", "[\u627e\u51fa\u7b2c k \u5c0f\u7684\u8ddd\u79bb\u5bf9](/solution/0700-0799/0719.Find%20K-th%20Smallest%20Pair%20Distance/README.md)", "`\u5806`,`\u6570\u7ec4`,`\u4e8c\u5206\u67e5\u627e`", "\u56f0\u96be", ""], "md_table_row_en": ["[0719](https://leetcode.com/problems/find-k-th-smallest-pair-distance)", "[Find K-th Smallest Pair Distance](/solution/0700-0799/0719.Find%20K-th%20Smallest%20Pair%20Distance/README_EN.md)", "`Heap`,`Array`,`Binary Search`", "Hard", ""]}, {"question_id": "0718", "frontend_question_id": "0718", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-length-of-repeated-subarray", "url_en": "https://leetcode.com/problems/maximum-length-of-repeated-subarray", "relative_path_cn": "/solution/0700-0799/0718.Maximum%20Length%20of%20Repeated%20Subarray/README.md", "relative_path_en": "/solution/0700-0799/0718.Maximum%20Length%20of%20Repeated%20Subarray/README_EN.md", "title_cn": "\u6700\u957f\u91cd\u590d\u5b50\u6570\u7ec4", "title_en": "Maximum Length of Repeated Subarray", "question_title_slug": "maximum-length-of-repeated-subarray", "content_en": "

    Given two integer arrays nums1 and nums2, return the maximum length of a subarray that appears in both arrays.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums1 = [1,2,3,2,1], nums2 = [3,2,1,4,7]\nOutput: 3\nExplanation: The repeated subarray with maximum length is [3,2,1].\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums1 = [0,0,0,0,0], nums2 = [0,0,0,0,0]\nOutput: 5\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums1.length, nums2.length <= 1000
    • \n\t
    • 0 <= nums1[i], nums2[i] <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u4e24\u4e2a\u6574\u6570\u6570\u7ec4 A \u548c B \uff0c\u8fd4\u56de\u4e24\u4e2a\u6570\u7ec4\u4e2d\u516c\u5171\u7684\u3001\u957f\u5ea6\u6700\u957f\u7684\u5b50\u6570\u7ec4\u7684\u957f\u5ea6\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1a\nA: [1,2,3,2,1]\nB: [3,2,1,4,7]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\n\u957f\u5ea6\u6700\u957f\u7684\u516c\u5171\u5b50\u6570\u7ec4\u662f [3, 2, 1] \u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= len(A), len(B) <= 1000
    • \n\t
    • 0 <= A[i], B[i] < 100
    • \n
    \n", "tags_en": ["Array", "Hash Table", "Binary Search", "Dynamic Programming"], "tags_cn": ["\u6570\u7ec4", "\u54c8\u5e0c\u8868", "\u4e8c\u5206\u67e5\u627e", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findLength(vector& nums1, vector& nums2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findLength(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findLength(self, nums1, nums2):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findLength(self, nums1: List[int], nums2: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findLength(int* nums1, int nums1Size, int* nums2, int nums2Size){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindLength(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums1\n * @param {number[]} nums2\n * @return {number}\n */\nvar findLength = function(nums1, nums2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums1\n# @param {Integer[]} nums2\n# @return {Integer}\ndef find_length(nums1, nums2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findLength(_ nums1: [Int], _ nums2: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findLength(nums1 []int, nums2 []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findLength(nums1: Array[Int], nums2: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findLength(nums1: IntArray, nums2: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_length(nums1: Vec, nums2: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums1\n * @param Integer[] $nums2\n * @return Integer\n */\n function findLength($nums1, $nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findLength(nums1: number[], nums2: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-length nums1 nums2)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0718](https://leetcode-cn.com/problems/maximum-length-of-repeated-subarray)", "[\u6700\u957f\u91cd\u590d\u5b50\u6570\u7ec4](/solution/0700-0799/0718.Maximum%20Length%20of%20Repeated%20Subarray/README.md)", "`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`,`\u4e8c\u5206\u67e5\u627e`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0718](https://leetcode.com/problems/maximum-length-of-repeated-subarray)", "[Maximum Length of Repeated Subarray](/solution/0700-0799/0718.Maximum%20Length%20of%20Repeated%20Subarray/README_EN.md)", "`Array`,`Hash Table`,`Binary Search`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0717", "frontend_question_id": "0717", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/1-bit-and-2-bit-characters", "url_en": "https://leetcode.com/problems/1-bit-and-2-bit-characters", "relative_path_cn": "/solution/0700-0799/0717.1-bit%20and%202-bit%20Characters/README.md", "relative_path_en": "/solution/0700-0799/0717.1-bit%20and%202-bit%20Characters/README_EN.md", "title_cn": "1\u6bd4\u7279\u4e0e2\u6bd4\u7279\u5b57\u7b26", "title_en": "1-bit and 2-bit Characters", "question_title_slug": "1-bit-and-2-bit-characters", "content_en": "

    We have two special characters:

    \n\n
      \n\t
    • The first character can be represented by one bit 0.
    • \n\t
    • The second character can be represented by two bits (10 or 11).
    • \n
    \n\n

    Given a binary array bits that ends with 0, return true if the last character must be a one-bit character.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: bits = [1,0,0]\nOutput: true\nExplanation: The only way to decode it is two-bit character and one-bit character.\nSo the last character is one-bit character.\n
    \n\n

    Example 2:

    \n\n
    \nInput: bits = [1,1,1,0]\nOutput: false\nExplanation: The only way to decode it is two-bit character and two-bit character.\nSo the last character is not one-bit character.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= bits.length <= 1000
    • \n\t
    • bits[i] is either 0 or 1.
    • \n
    \n", "content_cn": "

    \u6709\u4e24\u79cd\u7279\u6b8a\u5b57\u7b26\u3002\u7b2c\u4e00\u79cd\u5b57\u7b26\u53ef\u4ee5\u7528\u4e00\u6bd4\u72790\u6765\u8868\u793a\u3002\u7b2c\u4e8c\u79cd\u5b57\u7b26\u53ef\u4ee5\u7528\u4e24\u6bd4\u7279(10 \u6216 11)\u6765\u8868\u793a\u3002

    \n\n

    \u73b0\u7ed9\u4e00\u4e2a\u7531\u82e5\u5e72\u6bd4\u7279\u7ec4\u6210\u7684\u5b57\u7b26\u4e32\u3002\u95ee\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\u662f\u5426\u5fc5\u5b9a\u4e3a\u4e00\u4e2a\u4e00\u6bd4\u7279\u5b57\u7b26\u3002\u7ed9\u5b9a\u7684\u5b57\u7b26\u4e32\u603b\u662f\u75310\u7ed3\u675f\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: \nbits = [1, 0, 0]\n\u8f93\u51fa: True\n\u89e3\u91ca: \n\u552f\u4e00\u7684\u7f16\u7801\u65b9\u5f0f\u662f\u4e00\u4e2a\u4e24\u6bd4\u7279\u5b57\u7b26\u548c\u4e00\u4e2a\u4e00\u6bd4\u7279\u5b57\u7b26\u3002\u6240\u4ee5\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\u662f\u4e00\u6bd4\u7279\u5b57\u7b26\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: \nbits = [1, 1, 1, 0]\n\u8f93\u51fa: False\n\u89e3\u91ca: \n\u552f\u4e00\u7684\u7f16\u7801\u65b9\u5f0f\u662f\u4e24\u6bd4\u7279\u5b57\u7b26\u548c\u4e24\u6bd4\u7279\u5b57\u7b26\u3002\u6240\u4ee5\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\u4e0d\u662f\u4e00\u6bd4\u7279\u5b57\u7b26\u3002\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    • 1 <= len(bits) <= 1000.
    • \n\t
    • bits[i] \u603b\u662f0 \u6216 1.
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isOneBitCharacter(vector& bits) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isOneBitCharacter(int[] bits) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isOneBitCharacter(self, bits):\n \"\"\"\n :type bits: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isOneBitCharacter(self, bits: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isOneBitCharacter(int* bits, int bitsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsOneBitCharacter(int[] bits) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} bits\n * @return {boolean}\n */\nvar isOneBitCharacter = function(bits) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} bits\n# @return {Boolean}\ndef is_one_bit_character(bits)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isOneBitCharacter(_ bits: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isOneBitCharacter(bits []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isOneBitCharacter(bits: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isOneBitCharacter(bits: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_one_bit_character(bits: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $bits\n * @return Boolean\n */\n function isOneBitCharacter($bits) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isOneBitCharacter(bits: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-one-bit-character bits)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0717](https://leetcode-cn.com/problems/1-bit-and-2-bit-characters)", "[1\u6bd4\u7279\u4e0e2\u6bd4\u7279\u5b57\u7b26](/solution/0700-0799/0717.1-bit%20and%202-bit%20Characters/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0717](https://leetcode.com/problems/1-bit-and-2-bit-characters)", "[1-bit and 2-bit Characters](/solution/0700-0799/0717.1-bit%20and%202-bit%20Characters/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0716", "frontend_question_id": "0716", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/max-stack", "url_en": "https://leetcode.com/problems/max-stack", "relative_path_cn": "/solution/0700-0799/0716.Max%20Stack/README.md", "relative_path_en": "/solution/0700-0799/0716.Max%20Stack/README_EN.md", "title_cn": "\u6700\u5927\u6808", "title_en": "Max Stack", "question_title_slug": "max-stack", "content_en": "

    Design a max stack data structure that supports the stack operations and supports finding the stack's maximum element.

    \n\n

    Implement the MaxStack class:

    \n\n
      \n\t
    • MaxStack() Initializes the stack object.
    • \n\t
    • void push(int x) Pushes element x onto the stack.
    • \n\t
    • int pop() Removes the element on top of the stack and returns it.
    • \n\t
    • int top() Gets the element on the top of the stack without removing it.
    • \n\t
    • int peekMax() Retrieves the maximum element in the stack without removing it.
    • \n\t
    • int popMax() Retrieves the maximum element in the stack and removes it. If there is more than one maximum element, only remove the top-most one.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["MaxStack", "push", "push", "push", "top", "popMax", "top", "peekMax", "pop", "top"]\n[[], [5], [1], [5], [], [], [], [], [], []]\nOutput\n[null, null, null, null, 5, 5, 1, 5, 1, 5]\n\nExplanation\nMaxStack stk = new MaxStack();\nstk.push(5);   // [5] the top of the stack and the maximum number is 5.\nstk.push(1);   // [5, 1] the top of the stack is 1, but the maximum is 5.\nstk.push(5);   // [5, 1, 5] the top of the stack is 5, which is also the maximum, because it is the top most one.\nstk.top();     // return 5, [5, 1, 5] the stack did not change.\nstk.popMax();  // return 5, [5, 1] the stack is changed now, and the top is different from the max.\nstk.top();     // return 1, [5, 1] the stack did not change.\nstk.peekMax(); // return 5, [5, 1] the stack did not change.\nstk.pop();     // return 1, [5] the top of the stack and the max element is now 5.\nstk.top();     // return 5, [5] the stack did not change.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • -107 <= x <= 107
    • \n\t
    • At most 104 calls will be made to push, pop, top, peekMax, and popMax.
    • \n\t
    • There will be at least one element in the stack when pop, top, peekMax, or popMax is called.
    • \n
    \n\n

     

    \nFollow up: Could you come up with a solution that supports O(1) for each top call and O(logn) for each other call? ", "content_cn": "

    \u8bbe\u8ba1\u4e00\u4e2a\u6700\u5927\u6808\u6570\u636e\u7ed3\u6784\uff0c\u65e2\u652f\u6301\u6808\u64cd\u4f5c\uff0c\u53c8\u652f\u6301\u67e5\u627e\u6808\u4e2d\u6700\u5927\u5143\u7d20\u3002

    \n\n

    \u5b9e\u73b0\u00a0MaxStack\u00a0\u7c7b\uff1a

    \n\n
      \n\t
    • MaxStack()\u00a0\u521d\u59cb\u5316\u6808\u5bf9\u8c61
    • \n\t
    • void push(int x)\u00a0\u5c06\u5143\u7d20 x \u538b\u5165\u6808\u4e2d\u3002
    • \n\t
    • int pop()\u00a0\u79fb\u9664\u6808\u9876\u5143\u7d20\u5e76\u8fd4\u56de\u8fd9\u4e2a\u5143\u7d20\u3002
    • \n\t
    • int top()\u00a0\u8fd4\u56de\u6808\u9876\u5143\u7d20\uff0c\u65e0\u9700\u79fb\u9664\u3002
    • \n\t
    • int peekMax()\u00a0\u68c0\u7d22\u5e76\u8fd4\u56de\u6808\u4e2d\u6700\u5927\u5143\u7d20\uff0c\u65e0\u9700\u79fb\u9664\u3002
    • \n\t
    • int popMax()\u00a0\u68c0\u7d22\u5e76\u8fd4\u56de\u6808\u4e2d\u6700\u5927\u5143\u7d20\uff0c\u5e76\u5c06\u5176\u79fb\u9664\u3002\u5982\u679c\u6709\u591a\u4e2a\u6700\u5927\u5143\u7d20\uff0c\u53ea\u8981\u79fb\u9664 \u6700\u9760\u8fd1\u6808\u9876 \u7684\u90a3\u4e2a\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\n[\"MaxStack\", \"push\", \"push\", \"push\", \"top\", \"popMax\", \"top\", \"peekMax\", \"pop\", \"top\"]\n[[], [5], [1], [5], [], [], [], [], [], []]\n\u8f93\u51fa\n[null, null, null, null, 5, 5, 1, 5, 1, 5]\n\n\u89e3\u91ca\nMaxStack stk = new MaxStack();\nstk.push(5);   // [5] - 5 \u65e2\u662f\u6808\u9876\u5143\u7d20\uff0c\u4e5f\u662f\u6700\u5927\u5143\u7d20\nstk.push(1);   // [5, 1] - \u6808\u9876\u5143\u7d20\u662f 1\uff0c\u6700\u5927\u5143\u7d20\u662f 5\nstk.push(5);   // [5, 1, 5] - 5 \u65e2\u662f\u6808\u9876\u5143\u7d20\uff0c\u4e5f\u662f\u6700\u5927\u5143\u7d20\nstk.top();     // \u8fd4\u56de 5\uff0c[5, 1, 5] - \u6808\u6ca1\u6709\u6539\u53d8\nstk.popMax();  // \u8fd4\u56de 5\uff0c[5, 1] - \u6808\u53d1\u751f\u6539\u53d8\uff0c\u6808\u9876\u5143\u7d20\u4e0d\u518d\u662f\u6700\u5927\u5143\u7d20\nstk.top();     // \u8fd4\u56de 1\uff0c[5, 1] - \u6808\u6ca1\u6709\u6539\u53d8\nstk.peekMax(); // \u8fd4\u56de 5\uff0c[5, 1] - \u6808\u6ca1\u6709\u6539\u53d8\nstk.pop();     // \u8fd4\u56de 1\uff0c[5] - \u6b64\u64cd\u4f5c\u540e\uff0c5 \u65e2\u662f\u6808\u9876\u5143\u7d20\uff0c\u4e5f\u662f\u6700\u5927\u5143\u7d20\nstk.top();     // \u8fd4\u56de 5\uff0c[5] - \u6808\u6ca1\u6709\u6539\u53d8\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • -107\u00a0<= x <= 107
    • \n\t
    • \u6700\u591a\u8c03\u7528\u00a0104\u00a0\u6b21\u00a0push\u3001pop\u3001top\u3001peekMax\u00a0\u548c\u00a0popMax
    • \n\t
    • \u8c03\u7528\u00a0pop\u3001top\u3001peekMax\u00a0\u6216\u00a0popMax\u00a0\u65f6\uff0c\u6808\u4e2d \u81f3\u5c11\u5b58\u5728\u4e00\u4e2a\u5143\u7d20
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u00a0

    \n\n
      \n\t
    • \u8bd5\u7740\u8bbe\u8ba1\u89e3\u51b3\u65b9\u6848\uff1a\u8c03\u7528 top \u65b9\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a\u00a0O(1)\u00a0\uff0c\u8c03\u7528\u5176\u4ed6\u65b9\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a\u00a0O(logn)\u00a0\u3002\u00a0
    • \n
    \n", "tags_en": ["Design"], "tags_cn": ["\u8bbe\u8ba1"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class MaxStack {\npublic:\n /** initialize your data structure here. */\n MaxStack() {\n\n }\n \n void push(int x) {\n\n }\n \n int pop() {\n\n }\n \n int top() {\n\n }\n \n int peekMax() {\n\n }\n \n int popMax() {\n\n }\n};\n\n/**\n * Your MaxStack object will be instantiated and called as such:\n * MaxStack* obj = new MaxStack();\n * obj->push(x);\n * int param_2 = obj->pop();\n * int param_3 = obj->top();\n * int param_4 = obj->peekMax();\n * int param_5 = obj->popMax();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class MaxStack {\n\n /** initialize your data structure here. */\n public MaxStack() {\n\n }\n \n public void push(int x) {\n\n }\n \n public int pop() {\n\n }\n \n public int top() {\n\n }\n \n public int peekMax() {\n\n }\n \n public int popMax() {\n\n }\n}\n\n/**\n * Your MaxStack object will be instantiated and called as such:\n * MaxStack obj = new MaxStack();\n * obj.push(x);\n * int param_2 = obj.pop();\n * int param_3 = obj.top();\n * int param_4 = obj.peekMax();\n * int param_5 = obj.popMax();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class MaxStack(object):\n\n def __init__(self):\n \"\"\"\n initialize your data structure here.\n \"\"\"\n\n\n def push(self, x):\n \"\"\"\n :type x: int\n :rtype: None\n \"\"\"\n\n\n def pop(self):\n \"\"\"\n :rtype: int\n \"\"\"\n\n\n def top(self):\n \"\"\"\n :rtype: int\n \"\"\"\n\n\n def peekMax(self):\n \"\"\"\n :rtype: int\n \"\"\"\n\n\n def popMax(self):\n \"\"\"\n :rtype: int\n \"\"\"\n\n\n\n# Your MaxStack object will be instantiated and called as such:\n# obj = MaxStack()\n# obj.push(x)\n# param_2 = obj.pop()\n# param_3 = obj.top()\n# param_4 = obj.peekMax()\n# param_5 = obj.popMax()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class MaxStack:\n\n def __init__(self):\n \"\"\"\n initialize your data structure here.\n \"\"\"\n\n\n def push(self, x: int) -> None:\n\n\n def pop(self) -> int:\n\n\n def top(self) -> int:\n\n\n def peekMax(self) -> int:\n\n\n def popMax(self) -> int:\n\n\n\n# Your MaxStack object will be instantiated and called as such:\n# obj = MaxStack()\n# obj.push(x)\n# param_2 = obj.pop()\n# param_3 = obj.top()\n# param_4 = obj.peekMax()\n# param_5 = obj.popMax()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} MaxStack;\n\n/** initialize your data structure here. */\n\nMaxStack* maxStackCreate() {\n\n}\n\nvoid maxStackPush(MaxStack* obj, int x) {\n\n}\n\nint maxStackPop(MaxStack* obj) {\n\n}\n\nint maxStackTop(MaxStack* obj) {\n\n}\n\nint maxStackPeekMax(MaxStack* obj) {\n\n}\n\nint maxStackPopMax(MaxStack* obj) {\n\n}\n\nvoid maxStackFree(MaxStack* obj) {\n\n}\n\n/**\n * Your MaxStack struct will be instantiated and called as such:\n * MaxStack* obj = maxStackCreate();\n * maxStackPush(obj, x);\n \n * int param_2 = maxStackPop(obj);\n \n * int param_3 = maxStackTop(obj);\n \n * int param_4 = maxStackPeekMax(obj);\n \n * int param_5 = maxStackPopMax(obj);\n \n * maxStackFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class MaxStack {\n\n /** initialize your data structure here. */\n public MaxStack() {\n\n }\n \n public void Push(int x) {\n\n }\n \n public int Pop() {\n\n }\n \n public int Top() {\n\n }\n \n public int PeekMax() {\n\n }\n \n public int PopMax() {\n\n }\n}\n\n/**\n * Your MaxStack object will be instantiated and called as such:\n * MaxStack obj = new MaxStack();\n * obj.Push(x);\n * int param_2 = obj.Pop();\n * int param_3 = obj.Top();\n * int param_4 = obj.PeekMax();\n * int param_5 = obj.PopMax();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * initialize your data structure here.\n */\nvar MaxStack = function() {\n\n};\n\n/** \n * @param {number} x\n * @return {void}\n */\nMaxStack.prototype.push = function(x) {\n\n};\n\n/**\n * @return {number}\n */\nMaxStack.prototype.pop = function() {\n\n};\n\n/**\n * @return {number}\n */\nMaxStack.prototype.top = function() {\n\n};\n\n/**\n * @return {number}\n */\nMaxStack.prototype.peekMax = function() {\n\n};\n\n/**\n * @return {number}\n */\nMaxStack.prototype.popMax = function() {\n\n};\n\n/**\n * Your MaxStack object will be instantiated and called as such:\n * var obj = new MaxStack()\n * obj.push(x)\n * var param_2 = obj.pop()\n * var param_3 = obj.top()\n * var param_4 = obj.peekMax()\n * var param_5 = obj.popMax()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class MaxStack\n\n=begin\n initialize your data structure here.\n=end\n def initialize()\n\n end\n\n\n=begin\n :type x: Integer\n :rtype: Void\n=end\n def push(x)\n\n end\n\n\n=begin\n :rtype: Integer\n=end\n def pop()\n\n end\n\n\n=begin\n :rtype: Integer\n=end\n def top()\n\n end\n\n\n=begin\n :rtype: Integer\n=end\n def peek_max()\n\n end\n\n\n=begin\n :rtype: Integer\n=end\n def pop_max()\n\n end\n\n\nend\n\n# Your MaxStack object will be instantiated and called as such:\n# obj = MaxStack.new()\n# obj.push(x)\n# param_2 = obj.pop()\n# param_3 = obj.top()\n# param_4 = obj.peek_max()\n# param_5 = obj.pop_max()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass MaxStack {\n\n /** initialize your data structure here. */\n init() {\n\n }\n \n func push(_ x: Int) {\n\n }\n \n func pop() -> Int {\n\n }\n \n func top() -> Int {\n\n }\n \n func peekMax() -> Int {\n\n }\n \n func popMax() -> Int {\n\n }\n}\n\n/**\n * Your MaxStack object will be instantiated and called as such:\n * let obj = MaxStack()\n * obj.push(x)\n * let ret_2: Int = obj.pop()\n * let ret_3: Int = obj.top()\n * let ret_4: Int = obj.peekMax()\n * let ret_5: Int = obj.popMax()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type MaxStack struct {\n\n}\n\n\n/** initialize your data structure here. */\nfunc Constructor() MaxStack {\n\n}\n\n\nfunc (this *MaxStack) Push(x int) {\n\n}\n\n\nfunc (this *MaxStack) Pop() int {\n\n}\n\n\nfunc (this *MaxStack) Top() int {\n\n}\n\n\nfunc (this *MaxStack) PeekMax() int {\n\n}\n\n\nfunc (this *MaxStack) PopMax() int {\n\n}\n\n\n/**\n * Your MaxStack object will be instantiated and called as such:\n * obj := Constructor();\n * obj.Push(x);\n * param_2 := obj.Pop();\n * param_3 := obj.Top();\n * param_4 := obj.PeekMax();\n * param_5 := obj.PopMax();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class MaxStack() {\n\n /** initialize your data structure here. */\n\n\n def push(x: Int) {\n\n }\n\n def pop(): Int = {\n\n }\n\n def top(): Int = {\n\n }\n\n def peekMax(): Int = {\n\n }\n\n def popMax(): Int = {\n\n }\n\n}\n\n/**\n * Your MaxStack object will be instantiated and called as such:\n * var obj = new MaxStack()\n * obj.push(x)\n * var param_2 = obj.pop()\n * var param_3 = obj.top()\n * var param_4 = obj.peekMax()\n * var param_5 = obj.popMax()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class MaxStack() {\n\n /** initialize your data structure here. */\n\n\n fun push(x: Int) {\n\n }\n\n fun pop(): Int {\n\n }\n\n fun top(): Int {\n\n }\n\n fun peekMax(): Int {\n\n }\n\n fun popMax(): Int {\n\n }\n\n}\n\n/**\n * Your MaxStack object will be instantiated and called as such:\n * var obj = MaxStack()\n * obj.push(x)\n * var param_2 = obj.pop()\n * var param_3 = obj.top()\n * var param_4 = obj.peekMax()\n * var param_5 = obj.popMax()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct MaxStack {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl MaxStack {\n\n /** initialize your data structure here. */\n fn new() -> Self {\n\n }\n \n fn push(&self, x: i32) {\n\n }\n \n fn pop(&self) -> i32 {\n\n }\n \n fn top(&self) -> i32 {\n\n }\n \n fn peek_max(&self) -> i32 {\n\n }\n \n fn pop_max(&self) -> i32 {\n\n }\n}\n\n/**\n * Your MaxStack object will be instantiated and called as such:\n * let obj = MaxStack::new();\n * obj.push(x);\n * let ret_2: i32 = obj.pop();\n * let ret_3: i32 = obj.top();\n * let ret_4: i32 = obj.peek_max();\n * let ret_5: i32 = obj.pop_max();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class MaxStack {\n /**\n * initialize your data structure here.\n */\n function __construct() {\n\n }\n\n /**\n * @param Integer $x\n * @return NULL\n */\n function push($x) {\n\n }\n\n /**\n * @return Integer\n */\n function pop() {\n\n }\n\n /**\n * @return Integer\n */\n function top() {\n\n }\n\n /**\n * @return Integer\n */\n function peekMax() {\n\n }\n\n /**\n * @return Integer\n */\n function popMax() {\n\n }\n}\n\n/**\n * Your MaxStack object will be instantiated and called as such:\n * $obj = MaxStack();\n * $obj->push($x);\n * $ret_2 = $obj->pop();\n * $ret_3 = $obj->top();\n * $ret_4 = $obj->peekMax();\n * $ret_5 = $obj->popMax();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class MaxStack {\n constructor() {\n\n }\n\n push(x: number): void {\n\n }\n\n pop(): number {\n\n }\n\n top(): number {\n\n }\n\n peekMax(): number {\n\n }\n\n popMax(): number {\n\n }\n}\n\n/**\n * Your MaxStack object will be instantiated and called as such:\n * var obj = new MaxStack()\n * obj.push(x)\n * var param_2 = obj.pop()\n * var param_3 = obj.top()\n * var param_4 = obj.peekMax()\n * var param_5 = obj.popMax()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define max-stack%\n (class object%\n (super-new)\n (init-field)\n \n ; push : exact-integer? -> void?\n (define/public (push x)\n\n )\n ; pop : -> exact-integer?\n (define/public (pop)\n\n )\n ; top : -> exact-integer?\n (define/public (top)\n\n )\n ; peek-max : -> exact-integer?\n (define/public (peek-max)\n\n )\n ; pop-max : -> exact-integer?\n (define/public (pop-max)\n\n )))\n\n;; Your max-stack% object will be instantiated and called as such:\n;; (define obj (new max-stack%))\n;; (send obj push x)\n;; (define param_2 (send obj pop))\n;; (define param_3 (send obj top))\n;; (define param_4 (send obj peek-max))\n;; (define param_5 (send obj pop-max))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0716](https://leetcode-cn.com/problems/max-stack)", "[\u6700\u5927\u6808](/solution/0700-0799/0716.Max%20Stack/README.md)", "`\u8bbe\u8ba1`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0716](https://leetcode.com/problems/max-stack)", "[Max Stack](/solution/0700-0799/0716.Max%20Stack/README_EN.md)", "`Design`", "Easy", "\ud83d\udd12"]}, {"question_id": "0715", "frontend_question_id": "0715", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/range-module", "url_en": "https://leetcode.com/problems/range-module", "relative_path_cn": "/solution/0700-0799/0715.Range%20Module/README.md", "relative_path_en": "/solution/0700-0799/0715.Range%20Module/README_EN.md", "title_cn": "Range \u6a21\u5757", "title_en": "Range Module", "question_title_slug": "range-module", "content_en": "

    A Range Module is a module that tracks ranges of numbers. Your task is to design and implement the following interfaces in an efficient manner.

    \r\n\r\n

  • addRange(int left, int right) Adds the half-open interval [left, right), tracking every real number in that interval. Adding an interval that partially overlaps with currently tracked numbers should add any numbers in the interval [left, right) that are not already tracked.
  • \r\n\r\n

  • queryRange(int left, int right) Returns true if and only if every real number in the interval [left, right)\r\n is currently being tracked.
  • \r\n\r\n

  • removeRange(int left, int right) Stops tracking every real number currently being tracked in the interval [left, right).
  • \r\n\r\n

    Example 1:
    \r\n

    \r\naddRange(10, 20): null\r\nremoveRange(14, 16): null\r\nqueryRange(10, 14): true (Every number in [10, 14) is being tracked)\r\nqueryRange(13, 15): false (Numbers like 14, 14.03, 14.17 in [13, 15) are not being tracked)\r\nqueryRange(16, 17): true (The number 16 in [16, 17) is still being tracked, despite the remove operation)\r\n
    \r\n

    \r\n\r\n

    Note:\r\n

  • A half open interval [left, right) denotes all real numbers left <= x < right.
  • \r\n\r\n
  • 0 < left < right < 10^9 in all calls to addRange, queryRange, removeRange.
  • \r\n
  • The total number of calls to addRange in a single test case is at most 1000.
  • \r\n
  • The total number of calls to queryRange in a single test case is at most 5000.
  • \r\n
  • The total number of calls to removeRange in a single test case is at most 1000.
  • \r\n

    ", "content_cn": "

    Range \u6a21\u5757\u662f\u8ddf\u8e2a\u6570\u5b57\u8303\u56f4\u7684\u6a21\u5757\u3002\u4f60\u7684\u4efb\u52a1\u662f\u4ee5\u4e00\u79cd\u6709\u6548\u7684\u65b9\u5f0f\u8bbe\u8ba1\u548c\u5b9e\u73b0\u4ee5\u4e0b\u63a5\u53e3\u3002

    \n\n
      \n\t
    • addRange(int left, int right) \u6dfb\u52a0\u534a\u5f00\u533a\u95f4 [left, right)\uff0c\u8ddf\u8e2a\u8be5\u533a\u95f4\u4e2d\u7684\u6bcf\u4e2a\u5b9e\u6570\u3002\u6dfb\u52a0\u4e0e\u5f53\u524d\u8ddf\u8e2a\u7684\u6570\u5b57\u90e8\u5206\u91cd\u53e0\u7684\u533a\u95f4\u65f6\uff0c\u5e94\u5f53\u6dfb\u52a0\u5728\u533a\u95f4 [left, right) \u4e2d\u5c1a\u672a\u8ddf\u8e2a\u7684\u4efb\u4f55\u6570\u5b57\u5230\u8be5\u533a\u95f4\u4e2d\u3002
    • \n\t
    • queryRange(int left, int right) \u53ea\u6709\u5728\u5f53\u524d\u6b63\u5728\u8ddf\u8e2a\u533a\u95f4 [left, right) \u4e2d\u7684\u6bcf\u4e00\u4e2a\u5b9e\u6570\u65f6\uff0c\u624d\u8fd4\u56de true\u3002
    • \n\t
    • removeRange(int left, int right) \u505c\u6b62\u8ddf\u8e2a\u533a\u95f4 [left, right) \u4e2d\u5f53\u524d\u6b63\u5728\u8ddf\u8e2a\u7684\u6bcf\u4e2a\u5b9e\u6570\u3002
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    addRange(10, 20): null\nremoveRange(14, 16): null\nqueryRange(10, 14): true \uff08\u533a\u95f4 [10, 14) \u4e2d\u7684\u6bcf\u4e2a\u6570\u90fd\u6b63\u5728\u88ab\u8ddf\u8e2a\uff09\nqueryRange(13, 15): false \uff08\u672a\u8ddf\u8e2a\u533a\u95f4 [13, 15) \u4e2d\u50cf 14, 14.03, 14.17 \u8fd9\u6837\u7684\u6570\u5b57\uff09\nqueryRange(16, 17): true \uff08\u5c3d\u7ba1\u6267\u884c\u4e86\u5220\u9664\u64cd\u4f5c\uff0c\u533a\u95f4 [16, 17) \u4e2d\u7684\u6570\u5b57 16 \u4ecd\u7136\u4f1a\u88ab\u8ddf\u8e2a\uff09\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u534a\u5f00\u533a\u95f4 [left, right) \u8868\u793a\u6240\u6709\u6ee1\u8db3 left <= x < right \u7684\u5b9e\u6570\u3002
    • \n\t
    • \u5bf9 addRange, queryRange, removeRange \u7684\u6240\u6709\u8c03\u7528\u4e2d 0 < left < right < 10^9\u3002
    • \n\t
    • \u5728\u5355\u4e2a\u6d4b\u8bd5\u7528\u4f8b\u4e2d\uff0c\u5bf9 addRange \u7684\u8c03\u7528\u603b\u6570\u4e0d\u8d85\u8fc7 1000 \u6b21\u3002
    • \n\t
    • \u5728\u5355\u4e2a\u6d4b\u8bd5\u7528\u4f8b\u4e2d\uff0c\u5bf9  queryRange \u7684\u8c03\u7528\u603b\u6570\u4e0d\u8d85\u8fc7 5000 \u6b21\u3002
    • \n\t
    • \u5728\u5355\u4e2a\u6d4b\u8bd5\u7528\u4f8b\u4e2d\uff0c\u5bf9 removeRange \u7684\u8c03\u7528\u603b\u6570\u4e0d\u8d85\u8fc7 1000 \u6b21\u3002
    • \n
    \n\n

     

    \n", "tags_en": ["Segment Tree", "Ordered Map"], "tags_cn": ["\u7ebf\u6bb5\u6811"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class RangeModule {\npublic:\n RangeModule() {\n\n }\n \n void addRange(int left, int right) {\n\n }\n \n bool queryRange(int left, int right) {\n\n }\n \n void removeRange(int left, int right) {\n\n }\n};\n\n/**\n * Your RangeModule object will be instantiated and called as such:\n * RangeModule* obj = new RangeModule();\n * obj->addRange(left,right);\n * bool param_2 = obj->queryRange(left,right);\n * obj->removeRange(left,right);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class RangeModule {\n\n public RangeModule() {\n\n }\n \n public void addRange(int left, int right) {\n\n }\n \n public boolean queryRange(int left, int right) {\n\n }\n \n public void removeRange(int left, int right) {\n\n }\n}\n\n/**\n * Your RangeModule object will be instantiated and called as such:\n * RangeModule obj = new RangeModule();\n * obj.addRange(left,right);\n * boolean param_2 = obj.queryRange(left,right);\n * obj.removeRange(left,right);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class RangeModule(object):\n\n def __init__(self):\n \n\n def addRange(self, left, right):\n \"\"\"\n :type left: int\n :type right: int\n :rtype: None\n \"\"\"\n \n\n def queryRange(self, left, right):\n \"\"\"\n :type left: int\n :type right: int\n :rtype: bool\n \"\"\"\n \n\n def removeRange(self, left, right):\n \"\"\"\n :type left: int\n :type right: int\n :rtype: None\n \"\"\"\n \n\n\n# Your RangeModule object will be instantiated and called as such:\n# obj = RangeModule()\n# obj.addRange(left,right)\n# param_2 = obj.queryRange(left,right)\n# obj.removeRange(left,right)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class RangeModule:\n\n def __init__(self):\n \n\n def addRange(self, left: int, right: int) -> None:\n \n\n def queryRange(self, left: int, right: int) -> bool:\n \n\n def removeRange(self, left: int, right: int) -> None:\n \n\n\n# Your RangeModule object will be instantiated and called as such:\n# obj = RangeModule()\n# obj.addRange(left,right)\n# param_2 = obj.queryRange(left,right)\n# obj.removeRange(left,right)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} RangeModule;\n\n\nRangeModule* rangeModuleCreate() {\n \n}\n\nvoid rangeModuleAddRange(RangeModule* obj, int left, int right) {\n \n}\n\nbool rangeModuleQueryRange(RangeModule* obj, int left, int right) {\n \n}\n\nvoid rangeModuleRemoveRange(RangeModule* obj, int left, int right) {\n \n}\n\nvoid rangeModuleFree(RangeModule* obj) {\n \n}\n\n/**\n * Your RangeModule struct will be instantiated and called as such:\n * RangeModule* obj = rangeModuleCreate();\n * rangeModuleAddRange(obj, left, right);\n \n * bool param_2 = rangeModuleQueryRange(obj, left, right);\n \n * rangeModuleRemoveRange(obj, left, right);\n \n * rangeModuleFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class RangeModule {\n\n public RangeModule() {\n\n }\n \n public void AddRange(int left, int right) {\n\n }\n \n public bool QueryRange(int left, int right) {\n\n }\n \n public void RemoveRange(int left, int right) {\n\n }\n}\n\n/**\n * Your RangeModule object will be instantiated and called as such:\n * RangeModule obj = new RangeModule();\n * obj.AddRange(left,right);\n * bool param_2 = obj.QueryRange(left,right);\n * obj.RemoveRange(left,right);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "\nvar RangeModule = function() {\n\n};\n\n/** \n * @param {number} left \n * @param {number} right\n * @return {void}\n */\nRangeModule.prototype.addRange = function(left, right) {\n\n};\n\n/** \n * @param {number} left \n * @param {number} right\n * @return {boolean}\n */\nRangeModule.prototype.queryRange = function(left, right) {\n\n};\n\n/** \n * @param {number} left \n * @param {number} right\n * @return {void}\n */\nRangeModule.prototype.removeRange = function(left, right) {\n\n};\n\n/**\n * Your RangeModule object will be instantiated and called as such:\n * var obj = new RangeModule()\n * obj.addRange(left,right)\n * var param_2 = obj.queryRange(left,right)\n * obj.removeRange(left,right)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class RangeModule\n def initialize()\n\n end\n\n\n=begin\n :type left: Integer\n :type right: Integer\n :rtype: Void\n=end\n def add_range(left, right)\n\n end\n\n\n=begin\n :type left: Integer\n :type right: Integer\n :rtype: Boolean\n=end\n def query_range(left, right)\n\n end\n\n\n=begin\n :type left: Integer\n :type right: Integer\n :rtype: Void\n=end\n def remove_range(left, right)\n\n end\n\n\nend\n\n# Your RangeModule object will be instantiated and called as such:\n# obj = RangeModule.new()\n# obj.add_range(left, right)\n# param_2 = obj.query_range(left, right)\n# obj.remove_range(left, right)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass RangeModule {\n\n init() {\n \n }\n \n func addRange(_ left: Int, _ right: Int) {\n \n }\n \n func queryRange(_ left: Int, _ right: Int) -> Bool {\n \n }\n \n func removeRange(_ left: Int, _ right: Int) {\n \n }\n}\n\n/**\n * Your RangeModule object will be instantiated and called as such:\n * let obj = RangeModule()\n * obj.addRange(left, right)\n * let ret_2: Bool = obj.queryRange(left, right)\n * obj.removeRange(left, right)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type RangeModule struct {\n\n}\n\n\nfunc Constructor() RangeModule {\n\n}\n\n\nfunc (this *RangeModule) AddRange(left int, right int) {\n\n}\n\n\nfunc (this *RangeModule) QueryRange(left int, right int) bool {\n\n}\n\n\nfunc (this *RangeModule) RemoveRange(left int, right int) {\n\n}\n\n\n/**\n * Your RangeModule object will be instantiated and called as such:\n * obj := Constructor();\n * obj.AddRange(left,right);\n * param_2 := obj.QueryRange(left,right);\n * obj.RemoveRange(left,right);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class RangeModule() {\n\n def addRange(left: Int, right: Int) {\n\n }\n\n def queryRange(left: Int, right: Int): Boolean = {\n\n }\n\n def removeRange(left: Int, right: Int) {\n\n }\n\n}\n\n/**\n * Your RangeModule object will be instantiated and called as such:\n * var obj = new RangeModule()\n * obj.addRange(left,right)\n * var param_2 = obj.queryRange(left,right)\n * obj.removeRange(left,right)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class RangeModule() {\n\n fun addRange(left: Int, right: Int) {\n\n }\n\n fun queryRange(left: Int, right: Int): Boolean {\n\n }\n\n fun removeRange(left: Int, right: Int) {\n\n }\n\n}\n\n/**\n * Your RangeModule object will be instantiated and called as such:\n * var obj = RangeModule()\n * obj.addRange(left,right)\n * var param_2 = obj.queryRange(left,right)\n * obj.removeRange(left,right)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct RangeModule {\n\n}\n\n\n/** \n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl RangeModule {\n\n fn new() -> Self {\n \n }\n \n fn add_range(&self, left: i32, right: i32) {\n \n }\n \n fn query_range(&self, left: i32, right: i32) -> bool {\n \n }\n \n fn remove_range(&self, left: i32, right: i32) {\n \n }\n}\n\n/**\n * Your RangeModule object will be instantiated and called as such:\n * let obj = RangeModule::new();\n * obj.add_range(left, right);\n * let ret_2: bool = obj.query_range(left, right);\n * obj.remove_range(left, right);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class RangeModule {\n /**\n */\n function __construct() {\n \n }\n \n /**\n * @param Integer $left\n * @param Integer $right\n * @return NULL\n */\n function addRange($left, $right) {\n \n }\n \n /**\n * @param Integer $left\n * @param Integer $right\n * @return Boolean\n */\n function queryRange($left, $right) {\n \n }\n \n /**\n * @param Integer $left\n * @param Integer $right\n * @return NULL\n */\n function removeRange($left, $right) {\n \n }\n}\n\n/**\n * Your RangeModule object will be instantiated and called as such:\n * $obj = RangeModule();\n * $obj->addRange($left, $right);\n * $ret_2 = $obj->queryRange($left, $right);\n * $obj->removeRange($left, $right);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class RangeModule {\n constructor() {\n\n }\n\n addRange(left: number, right: number): void {\n\n }\n\n queryRange(left: number, right: number): boolean {\n\n }\n\n removeRange(left: number, right: number): void {\n\n }\n}\n\n/**\n * Your RangeModule object will be instantiated and called as such:\n * var obj = new RangeModule()\n * obj.addRange(left,right)\n * var param_2 = obj.queryRange(left,right)\n * obj.removeRange(left,right)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define range-module%\n (class object%\n (super-new)\n (init-field)\n \n ; add-range : exact-integer? exact-integer? -> void?\n (define/public (add-range left right)\n\n )\n ; query-range : exact-integer? exact-integer? -> boolean?\n (define/public (query-range left right)\n\n )\n ; remove-range : exact-integer? exact-integer? -> void?\n (define/public (remove-range left right)\n\n )))\n\n;; Your range-module% object will be instantiated and called as such:\n;; (define obj (new range-module%))\n;; (send obj add-range left right)\n;; (define param_2 (send obj query-range left right))\n;; (send obj remove-range left right)", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0715](https://leetcode-cn.com/problems/range-module)", "[Range \u6a21\u5757](/solution/0700-0799/0715.Range%20Module/README.md)", "`\u7ebf\u6bb5\u6811`", "\u56f0\u96be", ""], "md_table_row_en": ["[0715](https://leetcode.com/problems/range-module)", "[Range Module](/solution/0700-0799/0715.Range%20Module/README_EN.md)", "`Segment Tree`,`Ordered Map`", "Hard", ""]}, {"question_id": "0714", "frontend_question_id": "0714", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-with-transaction-fee", "url_en": "https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-transaction-fee", "relative_path_cn": "/solution/0700-0799/0714.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20with%20Transaction%20Fee/README.md", "relative_path_en": "/solution/0700-0799/0714.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20with%20Transaction%20Fee/README_EN.md", "title_cn": "\u4e70\u5356\u80a1\u7968\u7684\u6700\u4f73\u65f6\u673a\u542b\u624b\u7eed\u8d39", "title_en": "Best Time to Buy and Sell Stock with Transaction Fee", "question_title_slug": "best-time-to-buy-and-sell-stock-with-transaction-fee", "content_en": "

    You are given an array prices where prices[i] is the price of a given stock on the ith day, and an integer fee representing a transaction fee.

    \n\n

    Find the maximum profit you can achieve. You may complete as many transactions as you like, but you need to pay the transaction fee for each transaction.

    \n\n

    Note: You may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again).

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: prices = [1,3,2,8,4,9], fee = 2\nOutput: 8\nExplanation: The maximum profit can be achieved by:\n- Buying at prices[0] = 1\n- Selling at prices[3] = 8\n- Buying at prices[4] = 4\n- Selling at prices[5] = 9\nThe total profit is ((8 - 1) - 2) + ((9 - 4) - 2) = 8.\n
    \n\n

    Example 2:

    \n\n
    \nInput: prices = [1,3,7,5,10,3], fee = 3\nOutput: 6\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= prices.length <= 5 * 104
    • \n\t
    • 1 <= prices[i] < 5 * 104
    • \n\t
    • 0 <= fee < 5 * 104
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 prices\uff0c\u5176\u4e2d\u7b2c i \u4e2a\u5143\u7d20\u4ee3\u8868\u4e86\u7b2c i \u5929\u7684\u80a1\u7968\u4ef7\u683c \uff1b\u975e\u8d1f\u6574\u6570 fee \u4ee3\u8868\u4e86\u4ea4\u6613\u80a1\u7968\u7684\u624b\u7eed\u8d39\u7528\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u65e0\u9650\u6b21\u5730\u5b8c\u6210\u4ea4\u6613\uff0c\u4f46\u662f\u4f60\u6bcf\u7b14\u4ea4\u6613\u90fd\u9700\u8981\u4ed8\u624b\u7eed\u8d39\u3002\u5982\u679c\u4f60\u5df2\u7ecf\u8d2d\u4e70\u4e86\u4e00\u4e2a\u80a1\u7968\uff0c\u5728\u5356\u51fa\u5b83\u4e4b\u524d\u4f60\u5c31\u4e0d\u80fd\u518d\u7ee7\u7eed\u8d2d\u4e70\u80a1\u7968\u4e86\u3002

    \n\n

    \u8fd4\u56de\u83b7\u5f97\u5229\u6da6\u7684\u6700\u5927\u503c\u3002

    \n\n

    \u6ce8\u610f\uff1a\u8fd9\u91cc\u7684\u4e00\u7b14\u4ea4\u6613\u6307\u4e70\u5165\u6301\u6709\u5e76\u5356\u51fa\u80a1\u7968\u7684\u6574\u4e2a\u8fc7\u7a0b\uff0c\u6bcf\u7b14\u4ea4\u6613\u4f60\u53ea\u9700\u8981\u4e3a\u652f\u4ed8\u4e00\u6b21\u624b\u7eed\u8d39\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: prices = [1, 3, 2, 8, 4, 9], fee = 2\n\u8f93\u51fa: 8\n\u89e3\u91ca: \u80fd\u591f\u8fbe\u5230\u7684\u6700\u5927\u5229\u6da6:  \n\u5728\u6b64\u5904\u4e70\u5165 prices[0] = 1\n\u5728\u6b64\u5904\u5356\u51fa prices[3] = 8\n\u5728\u6b64\u5904\u4e70\u5165 prices[4] = 4\n\u5728\u6b64\u5904\u5356\u51fa prices[5] = 9\n\u603b\u5229\u6da6: ((8 - 1) - 2) + ((9 - 4) - 2) = 8.
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    • 0 < prices.length <= 50000.
    • \n\t
    • 0 < prices[i] < 50000.
    • \n\t
    • 0 <= fee < 50000.
    • \n
    \n", "tags_en": ["Greedy", "Array", "Dynamic Programming"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u7ec4", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxProfit(vector& prices, int fee) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxProfit(int[] prices, int fee) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxProfit(self, prices, fee):\n \"\"\"\n :type prices: List[int]\n :type fee: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxProfit(self, prices: List[int], fee: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxProfit(int* prices, int pricesSize, int fee){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxProfit(int[] prices, int fee) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} prices\n * @param {number} fee\n * @return {number}\n */\nvar maxProfit = function(prices, fee) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} prices\n# @param {Integer} fee\n# @return {Integer}\ndef max_profit(prices, fee)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxProfit(_ prices: [Int], _ fee: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxProfit(prices []int, fee int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxProfit(prices: Array[Int], fee: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxProfit(prices: IntArray, fee: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_profit(prices: Vec, fee: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $prices\n * @param Integer $fee\n * @return Integer\n */\n function maxProfit($prices, $fee) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxProfit(prices: number[], fee: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-profit prices fee)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0714](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-with-transaction-fee)", "[\u4e70\u5356\u80a1\u7968\u7684\u6700\u4f73\u65f6\u673a\u542b\u624b\u7eed\u8d39](/solution/0700-0799/0714.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20with%20Transaction%20Fee/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u7ec4`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0714](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-transaction-fee)", "[Best Time to Buy and Sell Stock with Transaction Fee](/solution/0700-0799/0714.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20with%20Transaction%20Fee/README_EN.md)", "`Greedy`,`Array`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0713", "frontend_question_id": "0713", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/subarray-product-less-than-k", "url_en": "https://leetcode.com/problems/subarray-product-less-than-k", "relative_path_cn": "/solution/0700-0799/0713.Subarray%20Product%20Less%20Than%20K/README.md", "relative_path_en": "/solution/0700-0799/0713.Subarray%20Product%20Less%20Than%20K/README_EN.md", "title_cn": "\u4e58\u79ef\u5c0f\u4e8eK\u7684\u5b50\u6570\u7ec4", "title_en": "Subarray Product Less Than K", "question_title_slug": "subarray-product-less-than-k", "content_en": "

    Given an array of integers nums and an integer k, return the number of contiguous subarrays where the product of all the elements in the subarray is strictly less than k.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [10,5,2,6], k = 100\nOutput: 8\nExplanation: The 8 subarrays that have product less than 100 are:\n[10], [5], [2], [6], [10, 5], [5, 2], [2, 6], [5, 2, 6]\nNote that [10, 5, 2] is not included as the product of 100 is not strictly less than k.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,2,3], k = 0\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • 0 <= nums[i] < 1000
    • \n\t
    • 0 <= k < 106
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6b63\u6574\u6570\u6570\u7ec4 nums\u3002

    \n\n

    \u627e\u51fa\u8be5\u6570\u7ec4\u5185\u4e58\u79ef\u5c0f\u4e8e k \u7684\u8fde\u7eed\u7684\u5b50\u6570\u7ec4\u7684\u4e2a\u6570\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: nums = [10,5,2,6], k = 100\n\u8f93\u51fa: 8\n\u89e3\u91ca: 8\u4e2a\u4e58\u79ef\u5c0f\u4e8e100\u7684\u5b50\u6570\u7ec4\u5206\u522b\u4e3a: [10], [5], [2], [6], [10,5], [5,2], [2,6], [5,2,6]\u3002\n\u9700\u8981\u6ce8\u610f\u7684\u662f [10,5,2] \u5e76\u4e0d\u662f\u4e58\u79ef\u5c0f\u4e8e100\u7684\u5b50\u6570\u7ec4\u3002\n
    \n\n

    \u8bf4\u660e:

    \n\n
      \n\t
    • 0 < nums.length <= 50000
    • \n\t
    • 0 < nums[i] < 1000
    • \n\t
    • 0 <= k < 10^6
    • \n
    \n", "tags_en": ["Array", "Two Pointers"], "tags_cn": ["\u6570\u7ec4", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numSubarrayProductLessThanK(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numSubarrayProductLessThanK(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numSubarrayProductLessThanK(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numSubarrayProductLessThanK(self, nums: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numSubarrayProductLessThanK(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumSubarrayProductLessThanK(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar numSubarrayProductLessThanK = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef num_subarray_product_less_than_k(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numSubarrayProductLessThanK(_ nums: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numSubarrayProductLessThanK(nums []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numSubarrayProductLessThanK(nums: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numSubarrayProductLessThanK(nums: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_subarray_product_less_than_k(nums: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer\n */\n function numSubarrayProductLessThanK($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numSubarrayProductLessThanK(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-subarray-product-less-than-k nums k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0713](https://leetcode-cn.com/problems/subarray-product-less-than-k)", "[\u4e58\u79ef\u5c0f\u4e8eK\u7684\u5b50\u6570\u7ec4](/solution/0700-0799/0713.Subarray%20Product%20Less%20Than%20K/README.md)", "`\u6570\u7ec4`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0713](https://leetcode.com/problems/subarray-product-less-than-k)", "[Subarray Product Less Than K](/solution/0700-0799/0713.Subarray%20Product%20Less%20Than%20K/README_EN.md)", "`Array`,`Two Pointers`", "Medium", ""]}, {"question_id": "0712", "frontend_question_id": "0712", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-ascii-delete-sum-for-two-strings", "url_en": "https://leetcode.com/problems/minimum-ascii-delete-sum-for-two-strings", "relative_path_cn": "/solution/0700-0799/0712.Minimum%20ASCII%20Delete%20Sum%20for%20Two%20Strings/README.md", "relative_path_en": "/solution/0700-0799/0712.Minimum%20ASCII%20Delete%20Sum%20for%20Two%20Strings/README_EN.md", "title_cn": "\u4e24\u4e2a\u5b57\u7b26\u4e32\u7684\u6700\u5c0fASCII\u5220\u9664\u548c", "title_en": "Minimum ASCII Delete Sum for Two Strings", "question_title_slug": "minimum-ascii-delete-sum-for-two-strings", "content_en": "

    Given two strings s1 and s2, return the lowest ASCII sum of deleted characters to make two strings equal.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s1 = "sea", s2 = "eat"\nOutput: 231\nExplanation: Deleting "s" from "sea" adds the ASCII value of "s" (115) to the sum.\nDeleting "t" from "eat" adds 116 to the sum.\nAt the end, both strings are equal, and 115 + 116 = 231 is the minimum sum possible to achieve this.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s1 = "delete", s2 = "leet"\nOutput: 403\nExplanation: Deleting "dee" from "delete" to turn the string into "let",\nadds 100[d] + 101[e] + 101[e] to the sum.\nDeleting "e" from "leet" adds 101[e] to the sum.\nAt the end, both strings are equal to "let", and the answer is 100+101+101+101 = 403.\nIf instead we turned both strings into "lee" or "eet", we would get answers of 433 or 417, which are higher.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s1.length, s2.length <= 1000
    • \n\t
    • s1 and s2 consist of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u5b57\u7b26\u4e32s1, s2\uff0c\u627e\u5230\u4f7f\u4e24\u4e2a\u5b57\u7b26\u4e32\u76f8\u7b49\u6240\u9700\u5220\u9664\u5b57\u7b26\u7684ASCII\u503c\u7684\u6700\u5c0f\u548c\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: s1 = "sea", s2 = "eat"\n\u8f93\u51fa: 231\n\u89e3\u91ca: \u5728 "sea" \u4e2d\u5220\u9664 "s" \u5e76\u5c06 "s" \u7684\u503c(115)\u52a0\u5165\u603b\u548c\u3002\n\u5728 "eat" \u4e2d\u5220\u9664 "t" \u5e76\u5c06 116 \u52a0\u5165\u603b\u548c\u3002\n\u7ed3\u675f\u65f6\uff0c\u4e24\u4e2a\u5b57\u7b26\u4e32\u76f8\u7b49\uff0c115 + 116 = 231 \u5c31\u662f\u7b26\u5408\u6761\u4ef6\u7684\u6700\u5c0f\u548c\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: s1 = "delete", s2 = "leet"\n\u8f93\u51fa: 403\n\u89e3\u91ca: \u5728 "delete" \u4e2d\u5220\u9664 "dee" \u5b57\u7b26\u4e32\u53d8\u6210 "let"\uff0c\n\u5c06 100[d]+101[e]+101[e] \u52a0\u5165\u603b\u548c\u3002\u5728 "leet" \u4e2d\u5220\u9664 "e" \u5c06 101[e] \u52a0\u5165\u603b\u548c\u3002\n\u7ed3\u675f\u65f6\uff0c\u4e24\u4e2a\u5b57\u7b26\u4e32\u90fd\u7b49\u4e8e "let"\uff0c\u7ed3\u679c\u5373\u4e3a 100+101+101+101 = 403 \u3002\n\u5982\u679c\u6539\u4e3a\u5c06\u4e24\u4e2a\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a "lee" \u6216 "eet"\uff0c\u6211\u4eec\u4f1a\u5f97\u5230 433 \u6216 417 \u7684\u7ed3\u679c\uff0c\u6bd4\u7b54\u6848\u66f4\u5927\u3002\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    • 0 < s1.length, s2.length <= 1000\u3002
    • \n\t
    • \u6240\u6709\u5b57\u7b26\u4e32\u4e2d\u7684\u5b57\u7b26ASCII\u503c\u5728[97, 122]\u4e4b\u95f4\u3002
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minimumDeleteSum(string s1, string s2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minimumDeleteSum(String s1, String s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimumDeleteSum(self, s1, s2):\n \"\"\"\n :type s1: str\n :type s2: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimumDeleteSum(self, s1: str, s2: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minimumDeleteSum(char * s1, char * s2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinimumDeleteSum(string s1, string s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s1\n * @param {string} s2\n * @return {number}\n */\nvar minimumDeleteSum = function(s1, s2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s1\n# @param {String} s2\n# @return {Integer}\ndef minimum_delete_sum(s1, s2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimumDeleteSum(_ s1: String, _ s2: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimumDeleteSum(s1 string, s2 string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimumDeleteSum(s1: String, s2: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimumDeleteSum(s1: String, s2: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimum_delete_sum(s1: String, s2: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s1\n * @param String $s2\n * @return Integer\n */\n function minimumDeleteSum($s1, $s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimumDeleteSum(s1: string, s2: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimum-delete-sum s1 s2)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0712](https://leetcode-cn.com/problems/minimum-ascii-delete-sum-for-two-strings)", "[\u4e24\u4e2a\u5b57\u7b26\u4e32\u7684\u6700\u5c0fASCII\u5220\u9664\u548c](/solution/0700-0799/0712.Minimum%20ASCII%20Delete%20Sum%20for%20Two%20Strings/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0712](https://leetcode.com/problems/minimum-ascii-delete-sum-for-two-strings)", "[Minimum ASCII Delete Sum for Two Strings](/solution/0700-0799/0712.Minimum%20ASCII%20Delete%20Sum%20for%20Two%20Strings/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0711", "frontend_question_id": "0711", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/number-of-distinct-islands-ii", "url_en": "https://leetcode.com/problems/number-of-distinct-islands-ii", "relative_path_cn": "/solution/0700-0799/0711.Number%20of%20Distinct%20Islands%20II/README.md", "relative_path_en": "/solution/0700-0799/0711.Number%20of%20Distinct%20Islands%20II/README_EN.md", "title_cn": "\u4e0d\u540c\u5c9b\u5c7f\u7684\u6570\u91cf II", "title_en": "Number of Distinct Islands II", "question_title_slug": "number-of-distinct-islands-ii", "content_en": "

    You are given an m x n binary matrix grid. An island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrounded by water.

    \n\n

    An island is considered to be the same as another if they have the same shape, or have the same shape after rotation (90, 180, or 270 degrees only) or reflection (left/right direction or up/down direction).

    \n\n

    Return the number of distinct islands.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: grid = [[1,1,0,0,0],[1,0,0,0,0],[0,0,0,0,1],[0,0,0,1,1]]\nOutput: 1\nExplanation: The two islands are considered the same because if we make a 180 degrees clockwise rotation on the first island, then two islands will have the same shapes.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: grid = [[1,1,0,0,0],[1,1,0,0,0],[0,0,0,1,1],[0,0,0,1,1]]\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= m, n <= 50
    • \n\t
    • grid[i][j] is either 0 or 1.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u7a7a01\u4e8c\u7ef4\u6570\u7ec4\u8868\u793a\u7684\u7f51\u683c\uff0c\u4e00\u4e2a\u5c9b\u5c7f\u7531\u56db\u8fde\u901a\uff08\u4e0a\u3001\u4e0b\u3001\u5de6\u3001\u53f3\u56db\u4e2a\u65b9\u5411\uff09\u7684 1 \u7ec4\u6210\uff0c\u4f60\u53ef\u4ee5\u8ba4\u4e3a\u7f51\u683c\u7684\u56db\u5468\u88ab\u6d77\u6c34\u5305\u56f4\u3002

    \n\n

    \u8bf7\u4f60\u8ba1\u7b97\u8fd9\u4e2a\u7f51\u683c\u4e2d\u5171\u6709\u591a\u5c11\u4e2a\u5f62\u72b6\u4e0d\u540c\u7684\u5c9b\u5c7f\u3002\u5982\u679c\u4e24\u4e2a\u5c9b\u5c7f\u7684\u5f62\u72b6\u76f8\u540c\uff0c\u6216\u8005\u901a\u8fc7\u65cb\u8f6c\uff08\u987a\u65f6\u9488\u65cb\u8f6c 90°\uff0c180°\uff0c270°\uff09\u3001\u7ffb\u8f6c\uff08\u5de6\u53f3\u7ffb\u8f6c\u3001\u4e0a\u4e0b\u7ffb\u8f6c\uff09\u540e\u5f62\u72b6\u76f8\u540c\uff0c\u90a3\u4e48\u5c31\u8ba4\u4e3a\u8fd9\u4e24\u4e2a\u5c9b\u5c7f\u662f\u76f8\u540c\u7684\u3002

    \n\n

     

    \n\n

    \u6837\u4f8b 1:

    \n\n
    11000\n10000\n00001\n00011\n
    \n\n

    \u7ed9\u5b9a\u4e0a\u56fe\uff0c\u8fd4\u56de\u7ed3\u679c 1\u3002
    \n
    \n\u6ce8\u610f \uff1a

    \n\n
    11\n1\n
    \n\n

    \u548c

    \n\n
     1\n11
    \n\n

    \u662f\u76f8\u540c\u7684\u5c9b\u5c7f\u3002\u56e0\u4e3a\u6211\u4eec\u901a\u8fc7 180° \u65cb\u8f6c\u7b2c\u4e00\u4e2a\u5c9b\u5c7f\uff0c\u4e24\u4e2a\u5c9b\u5c7f\u7684\u5f62\u72b6\u76f8\u540c\u3002

    \n\n

     

    \n\n

    \u6837\u4f8b 2:

    \n\n
    11100\n10001\n01001\n01110
    \n\n

    \u7ed9\u5b9a\u4e0a\u56fe\uff0c\u8fd4\u56de\u7ed3\u679c 2\u3002
    \n
    \n\u4e0b\u9762\u662f\u4e24\u4e2a\u4e0d\u540c\u7684\u5c9b\u5c7f\uff1a

    \n\n
    111\n1
    \n\n

    \u548c

    \n\n
    1\n1\n
    \n\n

     

    \n\n

    \u6ce8\u610f \uff1a

    \n\n
    111\n1
    \n\n

    \u548c

    \n\n
    1\n111\n
    \n\n

    \u76f8\u540c\u7684\u5c9b\u5c7f\u3002\u56e0\u4e3a\u6211\u4eec\u901a\u8fc7\u4e0a\u4e0b\u7ffb\u8f6c\u7b2c\u4e00\u4e2a\u5c9b\u5c7f\uff0c\u4e24\u4e2a\u5c9b\u5c7f\u7684\u5f62\u72b6\u76f8\u540c\u3002

    \n\n

     

    \n\n

    \u6ce8\u91ca :  \u4e8c\u7ef4\u6570\u7ec4\u6bcf\u7ef4\u7684\u5927\u5c0f\u90fd\u4e0d\u4f1a\u8d85\u8fc750\u3002

    \n", "tags_en": ["Depth-first Search", "Hash Table"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u54c8\u5e0c\u8868"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numDistinctIslands2(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numDistinctIslands2(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numDistinctIslands2(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numDistinctIslands2(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numDistinctIslands2(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumDistinctIslands2(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar numDistinctIslands2 = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef num_distinct_islands2(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numDistinctIslands2(_ grid: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numDistinctIslands2(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numDistinctIslands2(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numDistinctIslands2(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_distinct_islands2(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function numDistinctIslands2($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numDistinctIslands2(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-distinct-islands2 grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0711](https://leetcode-cn.com/problems/number-of-distinct-islands-ii)", "[\u4e0d\u540c\u5c9b\u5c7f\u7684\u6570\u91cf II](/solution/0700-0799/0711.Number%20of%20Distinct%20Islands%20II/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u54c8\u5e0c\u8868`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0711](https://leetcode.com/problems/number-of-distinct-islands-ii)", "[Number of Distinct Islands II](/solution/0700-0799/0711.Number%20of%20Distinct%20Islands%20II/README_EN.md)", "`Depth-first Search`,`Hash Table`", "Hard", "\ud83d\udd12"]}, {"question_id": "0699", "frontend_question_id": "0699", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/falling-squares", "url_en": "https://leetcode.com/problems/falling-squares", "relative_path_cn": "/solution/0600-0699/0699.Falling%20Squares/README.md", "relative_path_en": "/solution/0600-0699/0699.Falling%20Squares/README_EN.md", "title_cn": "\u6389\u843d\u7684\u65b9\u5757", "title_en": "Falling Squares", "question_title_slug": "falling-squares", "content_en": "

    There are several squares being dropped onto the X-axis of a 2D plane.

    \n\n

    You are given a 2D integer array positions where positions[i] = [lefti, sideLengthi] represents the ith square with a side length of sideLengthi that is dropped with its left edge aligned with X-coordinate lefti.

    \n\n

    Each square is dropped one at a time from a height above any landed squares. It then falls downward (negative Y direction) until it either lands on the top side of another square or on the X-axis. A square brushing the left/right side of another square does not count as landing on it. Once it lands, it freezes in place and cannot be moved.

    \n\n

    After each square is dropped, you must record the height of the current tallest stack of squares.

    \n\n

    Return an integer array ans where ans[i] represents the height described above after dropping the ith square.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: positions = [[1,2],[2,3],[6,1]]\nOutput: [2,5,5]\nExplanation:\nAfter the first drop, the tallest stack is square 1 with a height of 2.\nAfter the second drop, the tallest stack is squares 1 and 2 with a height of 5.\nAfter the third drop, the tallest stack is still squares 1 and 2 with a height of 5.\nThus, we return an answer of [2, 5, 5].\n
    \n\n

    Example 2:

    \n\n
    \nInput: positions = [[100,100],[200,100]]\nOutput: [100,100]\nExplanation:\nAfter the first drop, the tallest stack is square 1 with a height of 100.\nAfter the second drop, the tallest stack is either square 1 or square 2, both with heights of 100.\nThus, we return an answer of [100, 100].\nNote that square 2 only brushes the right side of square 1, which does not count as landing on it.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= positions.length <= 1000
    • \n\t
    • 1 <= lefti <= 108
    • \n\t
    • 1 <= sideLengthi <= 106
    • \n
    \n", "content_cn": "

    \u5728\u65e0\u9650\u957f\u7684\u6570\u8f74\uff08\u5373 x \u8f74\uff09\u4e0a\uff0c\u6211\u4eec\u6839\u636e\u7ed9\u5b9a\u7684\u987a\u5e8f\u653e\u7f6e\u5bf9\u5e94\u7684\u6b63\u65b9\u5f62\u65b9\u5757\u3002

    \n\n

    \u7b2c i \u4e2a\u6389\u843d\u7684\u65b9\u5757\uff08positions[i] = (left, side_length)\uff09\u662f\u6b63\u65b9\u5f62\uff0c\u5176\u4e2d left \u8868\u793a\u8be5\u65b9\u5757\u6700\u5de6\u8fb9\u7684\u70b9\u4f4d\u7f6e(positions[i][0])\uff0cside_length \u8868\u793a\u8be5\u65b9\u5757\u7684\u8fb9\u957f(positions[i][1])\u3002

    \n\n

    \u6bcf\u4e2a\u65b9\u5757\u7684\u5e95\u90e8\u8fb9\u7f18\u5e73\u884c\u4e8e\u6570\u8f74\uff08\u5373 x \u8f74\uff09\uff0c\u5e76\u4e14\u4ece\u4e00\u4e2a\u6bd4\u76ee\u524d\u6240\u6709\u7684\u843d\u5730\u65b9\u5757\u66f4\u9ad8\u7684\u9ad8\u5ea6\u6389\u843d\u800c\u4e0b\u3002\u5728\u4e0a\u4e00\u4e2a\u65b9\u5757\u7ed3\u675f\u6389\u843d\uff0c\u5e76\u4fdd\u6301\u9759\u6b62\u540e\uff0c\u624d\u5f00\u59cb\u6389\u843d\u65b0\u65b9\u5757\u3002

    \n\n

    \u65b9\u5757\u7684\u5e95\u8fb9\u5177\u6709\u975e\u5e38\u5927\u7684\u7c98\u6027\uff0c\u5e76\u5c06\u4fdd\u6301\u56fa\u5b9a\u5728\u5b83\u4eec\u6240\u63a5\u89e6\u7684\u4efb\u4f55\u957f\u5ea6\u8868\u9762\u4e0a\uff08\u65e0\u8bba\u662f\u6570\u8f74\u8fd8\u662f\u5176\u4ed6\u65b9\u5757\uff09\u3002\u90bb\u63a5\u6389\u843d\u7684\u8fb9\u4e0d\u4f1a\u8fc7\u65e9\u5730\u7c98\u5408\u5728\u4e00\u8d77\uff0c\u56e0\u4e3a\u53ea\u6709\u5e95\u8fb9\u624d\u5177\u6709\u7c98\u6027\u3002

    \n\n

     

    \n\n

    \u8fd4\u56de\u4e00\u4e2a\u5806\u53e0\u9ad8\u5ea6\u5217\u8868 ans \u3002\u6bcf\u4e00\u4e2a\u5806\u53e0\u9ad8\u5ea6 ans[i] \u8868\u793a\u5728\u901a\u8fc7 positions[0], positions[1], ..., positions[i] \u8868\u793a\u7684\u65b9\u5757\u6389\u843d\u7ed3\u675f\u540e\uff0c\u76ee\u524d\u6240\u6709\u5df2\u7ecf\u843d\u7a33\u7684\u65b9\u5757\u5806\u53e0\u7684\u6700\u9ad8\u9ad8\u5ea6\u3002

    \n\n

     

    \n\n

     

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: [[1, 2], [2, 3], [6, 1]]\n\u8f93\u51fa: [2, 5, 5]\n\u89e3\u91ca:\n\n\u7b2c\u4e00\u4e2a\u65b9\u5757 positions[0] = [1, 2] \u6389\u843d\uff1a\n_aa\n_aa\n-------\n\u65b9\u5757\u6700\u5927\u9ad8\u5ea6\u4e3a 2 \u3002\n\n\u7b2c\u4e8c\u4e2a\u65b9\u5757 positions[1] = [2, 3] \u6389\u843d\uff1a\n__aaa\n__aaa\n__aaa\n_aa__\n_aa__\n--------------\n\u65b9\u5757\u6700\u5927\u9ad8\u5ea6\u4e3a5\u3002\n\u5927\u7684\u65b9\u5757\u4fdd\u6301\u5728\u8f83\u5c0f\u7684\u65b9\u5757\u7684\u9876\u90e8\uff0c\u4e0d\u8bba\u5b83\u7684\u91cd\u5fc3\u5728\u54ea\u91cc\uff0c\u56e0\u4e3a\u65b9\u5757\u7684\u5e95\u90e8\u8fb9\u7f18\u6709\u975e\u5e38\u5927\u7684\u7c98\u6027\u3002\n\n\u7b2c\u4e09\u4e2a\u65b9\u5757 positions[1] = [6, 1] \u6389\u843d\uff1a\n__aaa\n__aaa\n__aaa\n_aa\n_aa___a\n-------------- \n\u65b9\u5757\u6700\u5927\u9ad8\u5ea6\u4e3a5\u3002\n\n\u56e0\u6b64\uff0c\u6211\u4eec\u8fd4\u56de\u7ed3\u679c[2, 5, 5]\u3002\n
    \n\n

     

    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: [[100, 100], [200, 100]]\n\u8f93\u51fa: [100, 100]\n\u89e3\u91ca: \u76f8\u90bb\u7684\u65b9\u5757\u4e0d\u4f1a\u8fc7\u65e9\u5730\u5361\u4f4f\uff0c\u53ea\u6709\u5b83\u4eec\u7684\u5e95\u90e8\u8fb9\u7f18\u624d\u80fd\u7c98\u5728\u8868\u9762\u4e0a\u3002\n
    \n\n

     

    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    • 1 <= positions.length <= 1000.
    • \n\t
    • 1 <= positions[i][0] <= 10^8.
    • \n\t
    • 1 <= positions[i][1] <= 10^6.
    • \n
    \n\n

     

    \n", "tags_en": ["Segment Tree", "Ordered Map"], "tags_cn": ["\u7ebf\u6bb5\u6811"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector fallingSquares(vector>& positions) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List fallingSquares(int[][] positions) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def fallingSquares(self, positions):\n \"\"\"\n :type positions: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def fallingSquares(self, positions: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* fallingSquares(int** positions, int positionsSize, int* positionsColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList FallingSquares(int[][] positions) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} positions\n * @return {number[]}\n */\nvar fallingSquares = function(positions) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} positions\n# @return {Integer[]}\ndef falling_squares(positions)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func fallingSquares(_ positions: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func fallingSquares(positions [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def fallingSquares(positions: Array[Array[Int]]): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun fallingSquares(positions: Array): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn falling_squares(positions: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $positions\n * @return Integer[]\n */\n function fallingSquares($positions) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function fallingSquares(positions: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (falling-squares positions)\n (-> (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0699](https://leetcode-cn.com/problems/falling-squares)", "[\u6389\u843d\u7684\u65b9\u5757](/solution/0600-0699/0699.Falling%20Squares/README.md)", "`\u7ebf\u6bb5\u6811`", "\u56f0\u96be", ""], "md_table_row_en": ["[0699](https://leetcode.com/problems/falling-squares)", "[Falling Squares](/solution/0600-0699/0699.Falling%20Squares/README_EN.md)", "`Segment Tree`,`Ordered Map`", "Hard", ""]}, {"question_id": "0698", "frontend_question_id": "0698", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/partition-to-k-equal-sum-subsets", "url_en": "https://leetcode.com/problems/partition-to-k-equal-sum-subsets", "relative_path_cn": "/solution/0600-0699/0698.Partition%20to%20K%20Equal%20Sum%20Subsets/README.md", "relative_path_en": "/solution/0600-0699/0698.Partition%20to%20K%20Equal%20Sum%20Subsets/README_EN.md", "title_cn": "\u5212\u5206\u4e3ak\u4e2a\u76f8\u7b49\u7684\u5b50\u96c6", "title_en": "Partition to K Equal Sum Subsets", "question_title_slug": "partition-to-k-equal-sum-subsets", "content_en": "

    Given an integer array nums and an integer k, return true if it is possible to divide this array into k non-empty subsets whose sums are all equal.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [4,3,2,3,5,2,1], k = 4\nOutput: true\nExplanation: It's possible to divide it into 4 subsets (5), (1, 4), (2,3), (2,3) with equal sums.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,2,3,4], k = 3\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= k <= nums.length <= 16
    • \n\t
    • 1 <= nums[i] <= 104
    • \n\t
    • The frequency of each element is in the range [1, 4].
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4  nums \u548c\u4e00\u4e2a\u6b63\u6574\u6570 k\uff0c\u627e\u51fa\u662f\u5426\u6709\u53ef\u80fd\u628a\u8fd9\u4e2a\u6570\u7ec4\u5206\u6210 k \u4e2a\u975e\u7a7a\u5b50\u96c6\uff0c\u5176\u603b\u548c\u90fd\u76f8\u7b49\u3002

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a nums = [4, 3, 2, 3, 5, 2, 1], k = 4\n\u8f93\u51fa\uff1a True\n\u8bf4\u660e\uff1a \u6709\u53ef\u80fd\u5c06\u5176\u5206\u6210 4 \u4e2a\u5b50\u96c6\uff085\uff09\uff0c\uff081,4\uff09\uff0c\uff082,3\uff09\uff0c\uff082,3\uff09\u7b49\u4e8e\u603b\u548c\u3002
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= k <= len(nums) <= 16
    • \n\t
    • 0 < nums[i] < 10000
    • \n
    \n", "tags_en": ["Recursion", "Dynamic Programming"], "tags_cn": ["\u9012\u5f52", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canPartitionKSubsets(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canPartitionKSubsets(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canPartitionKSubsets(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canPartitionKSubsets(self, nums: List[int], k: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canPartitionKSubsets(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanPartitionKSubsets(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {boolean}\n */\nvar canPartitionKSubsets = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Boolean}\ndef can_partition_k_subsets(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canPartitionKSubsets(_ nums: [Int], _ k: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canPartitionKSubsets(nums []int, k int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canPartitionKSubsets(nums: Array[Int], k: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canPartitionKSubsets(nums: IntArray, k: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_partition_k_subsets(nums: Vec, k: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Boolean\n */\n function canPartitionKSubsets($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canPartitionKSubsets(nums: number[], k: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-partition-k-subsets nums k)\n (-> (listof exact-integer?) exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0698](https://leetcode-cn.com/problems/partition-to-k-equal-sum-subsets)", "[\u5212\u5206\u4e3ak\u4e2a\u76f8\u7b49\u7684\u5b50\u96c6](/solution/0600-0699/0698.Partition%20to%20K%20Equal%20Sum%20Subsets/README.md)", "`\u9012\u5f52`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0698](https://leetcode.com/problems/partition-to-k-equal-sum-subsets)", "[Partition to K Equal Sum Subsets](/solution/0600-0699/0698.Partition%20to%20K%20Equal%20Sum%20Subsets/README_EN.md)", "`Recursion`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0697", "frontend_question_id": "0697", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/degree-of-an-array", "url_en": "https://leetcode.com/problems/degree-of-an-array", "relative_path_cn": "/solution/0600-0699/0697.Degree%20of%20an%20Array/README.md", "relative_path_en": "/solution/0600-0699/0697.Degree%20of%20an%20Array/README_EN.md", "title_cn": "\u6570\u7ec4\u7684\u5ea6", "title_en": "Degree of an Array", "question_title_slug": "degree-of-an-array", "content_en": "

    Given a non-empty array of non-negative integers nums, the degree of this array is defined as the maximum frequency of any one of its elements.

    \n\n

    Your task is to find the smallest possible length of a (contiguous) subarray of nums, that has the same degree as nums.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,2,3,1]\nOutput: 2\nExplanation: \nThe input array has a degree of 2 because both elements 1 and 2 appear twice.\nOf the subarrays that have the same degree:\n[1, 2, 2, 3, 1], [1, 2, 2, 3], [2, 2, 3, 1], [1, 2, 2], [2, 2, 3], [2, 2]\nThe shortest length is 2. So return 2.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,2,2,3,1,4,2]\nOutput: 6\nExplanation: \nThe degree is 3 because the element 2 is repeated 3 times.\nSo [2,2,3,1,4,2] is the shortest subarray, therefore returning 6.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • nums.length will be between 1 and 50,000.
    • \n\t
    • nums[i] will be an integer between 0 and 49,999.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u7a7a\u4e14\u53ea\u5305\u542b\u975e\u8d1f\u6570\u7684\u6574\u6570\u6570\u7ec4\u00a0nums\uff0c\u6570\u7ec4\u7684\u5ea6\u7684\u5b9a\u4e49\u662f\u6307\u6570\u7ec4\u91cc\u4efb\u4e00\u5143\u7d20\u51fa\u73b0\u9891\u6570\u7684\u6700\u5927\u503c\u3002

    \n\n

    \u4f60\u7684\u4efb\u52a1\u662f\u5728 nums \u4e2d\u627e\u5230\u4e0e\u00a0nums\u00a0\u62e5\u6709\u76f8\u540c\u5927\u5c0f\u7684\u5ea6\u7684\u6700\u77ed\u8fde\u7eed\u5b50\u6570\u7ec4\uff0c\u8fd4\u56de\u5176\u957f\u5ea6\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[1, 2, 2, 3, 1]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n\u8f93\u5165\u6570\u7ec4\u7684\u5ea6\u662f2\uff0c\u56e0\u4e3a\u5143\u7d201\u548c2\u7684\u51fa\u73b0\u9891\u6570\u6700\u5927\uff0c\u5747\u4e3a2.\n\u8fde\u7eed\u5b50\u6570\u7ec4\u91cc\u9762\u62e5\u6709\u76f8\u540c\u5ea6\u7684\u6709\u5982\u4e0b\u6240\u793a:\n[1, 2, 2, 3, 1], [1, 2, 2, 3], [2, 2, 3, 1], [1, 2, 2], [2, 2, 3], [2, 2]\n\u6700\u77ed\u8fde\u7eed\u5b50\u6570\u7ec4[2, 2]\u7684\u957f\u5ea6\u4e3a2\uff0c\u6240\u4ee5\u8fd4\u56de2.\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[1,2,2,3,1,4,2]\n\u8f93\u51fa\uff1a6\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • nums.length\u00a0\u57281\u5230 50,000 \u533a\u95f4\u8303\u56f4\u5185\u3002
    • \n\t
    • nums[i]\u00a0\u662f\u4e00\u4e2a\u5728 0 \u5230 49,999 \u8303\u56f4\u5185\u7684\u6574\u6570\u3002
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findShortestSubArray(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findShortestSubArray(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findShortestSubArray(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findShortestSubArray(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findShortestSubArray(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindShortestSubArray(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar findShortestSubArray = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef find_shortest_sub_array(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findShortestSubArray(_ nums: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findShortestSubArray(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findShortestSubArray(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findShortestSubArray(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_shortest_sub_array(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function findShortestSubArray($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findShortestSubArray(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-shortest-sub-array nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0697](https://leetcode-cn.com/problems/degree-of-an-array)", "[\u6570\u7ec4\u7684\u5ea6](/solution/0600-0699/0697.Degree%20of%20an%20Array/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0697](https://leetcode.com/problems/degree-of-an-array)", "[Degree of an Array](/solution/0600-0699/0697.Degree%20of%20an%20Array/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0696", "frontend_question_id": "0696", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-binary-substrings", "url_en": "https://leetcode.com/problems/count-binary-substrings", "relative_path_cn": "/solution/0600-0699/0696.Count%20Binary%20Substrings/README.md", "relative_path_en": "/solution/0600-0699/0696.Count%20Binary%20Substrings/README_EN.md", "title_cn": "\u8ba1\u6570\u4e8c\u8fdb\u5236\u5b50\u4e32", "title_en": "Count Binary Substrings", "question_title_slug": "count-binary-substrings", "content_en": "

    Give a binary string s, return the number of non-empty substrings that have the same number of 0's and 1's, and all the 0's and all the 1's in these substrings are grouped consecutively.

    \n\n

    Substrings that occur multiple times are counted the number of times they occur.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "00110011"\nOutput: 6\nExplanation: There are 6 substrings that have equal number of consecutive 1's and 0's: "0011", "01", "1100", "10", "0011", and "01".\nNotice that some of these substrings repeat and are counted the number of times they occur.\nAlso, "00110011" is not a valid substring because all the 0's (and 1's) are not grouped together.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "10101"\nOutput: 4\nExplanation: There are 4 substrings: "10", "01", "10", "01" that have equal number of consecutive 1's and 0's.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 105
    • \n\t
    • s[i] is either '0' or '1'.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\u00a0s\uff0c\u8ba1\u7b97\u5177\u6709\u76f8\u540c\u6570\u91cf 0 \u548c 1 \u7684\u975e\u7a7a\uff08\u8fde\u7eed\uff09\u5b50\u5b57\u7b26\u4e32\u7684\u6570\u91cf\uff0c\u5e76\u4e14\u8fd9\u4e9b\u5b50\u5b57\u7b26\u4e32\u4e2d\u7684\u6240\u6709 0 \u548c\u6240\u6709 1 \u90fd\u662f\u8fde\u7eed\u7684\u3002

    \n\n

    \u91cd\u590d\u51fa\u73b0\u7684\u5b50\u4e32\u8981\u8ba1\u7b97\u5b83\u4eec\u51fa\u73b0\u7684\u6b21\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1 :

    \n\n
    \n\u8f93\u5165: \"00110011\"\n\u8f93\u51fa: 6\n\u89e3\u91ca: \u67096\u4e2a\u5b50\u4e32\u5177\u6709\u76f8\u540c\u6570\u91cf\u7684\u8fde\u7eed1\u548c0\uff1a\u201c0011\u201d\uff0c\u201c01\u201d\uff0c\u201c1100\u201d\uff0c\u201c10\u201d\uff0c\u201c0011\u201d \u548c \u201c01\u201d\u3002\n\n\u8bf7\u6ce8\u610f\uff0c\u4e00\u4e9b\u91cd\u590d\u51fa\u73b0\u7684\u5b50\u4e32\u8981\u8ba1\u7b97\u5b83\u4eec\u51fa\u73b0\u7684\u6b21\u6570\u3002\n\n\u53e6\u5916\uff0c\u201c00110011\u201d\u4e0d\u662f\u6709\u6548\u7684\u5b50\u4e32\uff0c\u56e0\u4e3a\u6240\u6709\u76840\uff08\u548c1\uff09\u6ca1\u6709\u7ec4\u5408\u5728\u4e00\u8d77\u3002\n
    \n\n

    \u793a\u4f8b 2 :

    \n\n
    \n\u8f93\u5165: \"10101\"\n\u8f93\u51fa: 4\n\u89e3\u91ca: \u67094\u4e2a\u5b50\u4e32\uff1a\u201c10\u201d\uff0c\u201c01\u201d\uff0c\u201c10\u201d\uff0c\u201c01\u201d\uff0c\u5b83\u4eec\u5177\u6709\u76f8\u540c\u6570\u91cf\u7684\u8fde\u7eed1\u548c0\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • s.length\u00a0\u57281\u523050,000\u4e4b\u95f4\u3002
    • \n\t
    • s\u00a0\u53ea\u5305\u542b\u201c0\u201d\u6216\u201c1\u201d\u5b57\u7b26\u3002
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countBinarySubstrings(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countBinarySubstrings(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countBinarySubstrings(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countBinarySubstrings(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countBinarySubstrings(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountBinarySubstrings(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar countBinarySubstrings = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef count_binary_substrings(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countBinarySubstrings(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countBinarySubstrings(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countBinarySubstrings(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countBinarySubstrings(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_binary_substrings(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function countBinarySubstrings($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countBinarySubstrings(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-binary-substrings s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0696](https://leetcode-cn.com/problems/count-binary-substrings)", "[\u8ba1\u6570\u4e8c\u8fdb\u5236\u5b50\u4e32](/solution/0600-0699/0696.Count%20Binary%20Substrings/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0696](https://leetcode.com/problems/count-binary-substrings)", "[Count Binary Substrings](/solution/0600-0699/0696.Count%20Binary%20Substrings/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "0695", "frontend_question_id": "0695", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/max-area-of-island", "url_en": "https://leetcode.com/problems/max-area-of-island", "relative_path_cn": "/solution/0600-0699/0695.Max%20Area%20of%20Island/README.md", "relative_path_en": "/solution/0600-0699/0695.Max%20Area%20of%20Island/README_EN.md", "title_cn": "\u5c9b\u5c7f\u7684\u6700\u5927\u9762\u79ef", "title_en": "Max Area of Island", "question_title_slug": "max-area-of-island", "content_en": "

    You are given an m x n binary matrix grid. An island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrounded by water.

    \n\n

    The area of an island is the number of cells with a value 1 in the island.

    \n\n

    Return the maximum area of an island in grid. If there is no island, return 0.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: grid = [[0,0,1,0,0,0,0,1,0,0,0,0,0],[0,0,0,0,0,0,0,1,1,1,0,0,0],[0,1,1,0,1,0,0,0,0,0,0,0,0],[0,1,0,0,1,1,0,0,1,0,1,0,0],[0,1,0,0,1,1,0,0,1,1,1,0,0],[0,0,0,0,0,0,0,0,0,0,1,0,0],[0,0,0,0,0,0,0,1,1,1,0,0,0],[0,0,0,0,0,0,0,1,1,0,0,0,0]]\nOutput: 6\nExplanation: The answer is not 11, because the island must be connected 4-directionally.\n
    \n\n

    Example 2:

    \n\n
    \nInput: grid = [[0,0,0,0,0,0,0,0]]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= m, n <= 50
    • \n\t
    • grid[i][j] is either 0 or 1.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5305\u542b\u4e86\u4e00\u4e9b 0 \u548c 1 \u7684\u975e\u7a7a\u4e8c\u7ef4\u6570\u7ec4 grid \u3002

    \n\n

    \u4e00\u4e2a \u5c9b\u5c7f \u662f\u7531\u4e00\u4e9b\u76f8\u90bb\u7684 1 (\u4ee3\u8868\u571f\u5730) \u6784\u6210\u7684\u7ec4\u5408\uff0c\u8fd9\u91cc\u7684\u300c\u76f8\u90bb\u300d\u8981\u6c42\u4e24\u4e2a 1 \u5fc5\u987b\u5728\u6c34\u5e73\u6216\u8005\u7ad6\u76f4\u65b9\u5411\u4e0a\u76f8\u90bb\u3002\u4f60\u53ef\u4ee5\u5047\u8bbe grid \u7684\u56db\u4e2a\u8fb9\u7f18\u90fd\u88ab 0\uff08\u4ee3\u8868\u6c34\uff09\u5305\u56f4\u7740\u3002

    \n\n

    \u627e\u5230\u7ed9\u5b9a\u7684\u4e8c\u7ef4\u6570\u7ec4\u4e2d\u6700\u5927\u7684\u5c9b\u5c7f\u9762\u79ef\u3002(\u5982\u679c\u6ca1\u6709\u5c9b\u5c7f\uff0c\u5219\u8fd4\u56de\u9762\u79ef\u4e3a 0 \u3002)

    \n\n

     

    \n\n

    \u793a\u4f8b 1:

    \n\n
    [[0,0,1,0,0,0,0,1,0,0,0,0,0],\n [0,0,0,0,0,0,0,1,1,1,0,0,0],\n [0,1,1,0,1,0,0,0,0,0,0,0,0],\n [0,1,0,0,1,1,0,0,1,0,1,0,0],\n [0,1,0,0,1,1,0,0,1,1,1,0,0],\n [0,0,0,0,0,0,0,0,0,0,1,0,0],\n [0,0,0,0,0,0,0,1,1,1,0,0,0],\n [0,0,0,0,0,0,0,1,1,0,0,0,0]]\n
    \n\n

    \u5bf9\u4e8e\u4e0a\u9762\u8fd9\u4e2a\u7ed9\u5b9a\u77e9\u9635\u5e94\u8fd4\u56de 6\u3002\u6ce8\u610f\u7b54\u6848\u4e0d\u5e94\u8be5\u662f 11 \uff0c\u56e0\u4e3a\u5c9b\u5c7f\u53ea\u80fd\u5305\u542b\u6c34\u5e73\u6216\u5782\u76f4\u7684\u56db\u4e2a\u65b9\u5411\u7684 1 \u3002

    \n\n

    \u793a\u4f8b 2:

    \n\n
    [[0,0,0,0,0,0,0,0]]
    \n\n

    \u5bf9\u4e8e\u4e0a\u9762\u8fd9\u4e2a\u7ed9\u5b9a\u7684\u77e9\u9635, \u8fd4\u56de 0\u3002

    \n\n

     

    \n\n

    \u6ce8\u610f: \u7ed9\u5b9a\u7684\u77e9\u9635grid \u7684\u957f\u5ea6\u548c\u5bbd\u5ea6\u90fd\u4e0d\u8d85\u8fc7 50\u3002

    \n", "tags_en": ["Depth-first Search", "Array"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxAreaOfIsland(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxAreaOfIsland(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxAreaOfIsland(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxAreaOfIsland(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxAreaOfIsland(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxAreaOfIsland(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar maxAreaOfIsland = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef max_area_of_island(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxAreaOfIsland(_ grid: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxAreaOfIsland(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxAreaOfIsland(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxAreaOfIsland(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_area_of_island(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function maxAreaOfIsland($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxAreaOfIsland(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-area-of-island grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0695](https://leetcode-cn.com/problems/max-area-of-island)", "[\u5c9b\u5c7f\u7684\u6700\u5927\u9762\u79ef](/solution/0600-0699/0695.Max%20Area%20of%20Island/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0695](https://leetcode.com/problems/max-area-of-island)", "[Max Area of Island](/solution/0600-0699/0695.Max%20Area%20of%20Island/README_EN.md)", "`Depth-first Search`,`Array`", "Medium", ""]}, {"question_id": "0694", "frontend_question_id": "0694", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/number-of-distinct-islands", "url_en": "https://leetcode.com/problems/number-of-distinct-islands", "relative_path_cn": "/solution/0600-0699/0694.Number%20of%20Distinct%20Islands/README.md", "relative_path_en": "/solution/0600-0699/0694.Number%20of%20Distinct%20Islands/README_EN.md", "title_cn": "\u4e0d\u540c\u5c9b\u5c7f\u7684\u6570\u91cf", "title_en": "Number of Distinct Islands", "question_title_slug": "number-of-distinct-islands", "content_en": "

    You are given an m x n binary matrix grid. An island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrounded by water.

    \n\n

    An island is considered to be the same as another if and only if one island can be translated (and not rotated or reflected) to equal the other.

    \n\n

    Return the number of distinct islands.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: grid = [[1,1,0,0,0],[1,1,0,0,0],[0,0,0,1,1],[0,0,0,1,1]]\nOutput: 1\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: grid = [[1,1,0,1,1],[1,0,0,0,0],[0,0,0,0,1],[1,1,0,1,1]]\nOutput: 3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= m, n <= 50
    • \n\t
    • grid[i][j] is either 0 or 1.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u7a7a 01 \u4e8c\u7ef4\u6570\u7ec4\u8868\u793a\u7684\u7f51\u683c\uff0c\u4e00\u4e2a\u5c9b\u5c7f\u7531\u56db\u8fde\u901a\uff08\u4e0a\u3001\u4e0b\u3001\u5de6\u3001\u53f3\u56db\u4e2a\u65b9\u5411\uff09\u7684 1 \u7ec4\u6210\uff0c\u4f60\u53ef\u4ee5\u8ba4\u4e3a\u7f51\u683c\u7684\u56db\u5468\u88ab\u6d77\u6c34\u5305\u56f4\u3002

    \n\n

    \u8bf7\u4f60\u8ba1\u7b97\u8fd9\u4e2a\u7f51\u683c\u4e2d\u5171\u6709\u591a\u5c11\u4e2a\u5f62\u72b6\u4e0d\u540c\u7684\u5c9b\u5c7f\u3002\u4e24\u4e2a\u5c9b\u5c7f\u88ab\u8ba4\u4e3a\u662f\u76f8\u540c\u7684\uff0c\u5f53\u4e14\u4ec5\u5f53\u4e00\u4e2a\u5c9b\u5c7f\u53ef\u4ee5\u901a\u8fc7\u5e73\u79fb\u53d8\u6362\uff08\u4e0d\u53ef\u4ee5\u65cb\u8f6c\u3001\u7ffb\u8f6c\uff09\u548c\u53e6\u4e00\u4e2a\u5c9b\u5c7f\u91cd\u5408\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    11000\n11000\n00011\n00011\n
    \n\n

    \u7ed9\u5b9a\u4e0a\u56fe\uff0c\u8fd4\u56de\u7ed3\u679c 1 \u3002

    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    11011\n10000\n00001\n11011
    \n\n

    \u7ed9\u5b9a\u4e0a\u56fe\uff0c\u8fd4\u56de\u7ed3\u679c 3 \u3002
    \n
    \n\u6ce8\u610f\uff1a

    \n\n
    11\n1\n
    \n\n

    \u548c

    \n\n
     1\n11\n
    \n\n

    \u662f\u4e0d\u540c\u7684\u5c9b\u5c7f\uff0c\u56e0\u4e3a\u6211\u4eec\u4e0d\u8003\u8651\u65cb\u8f6c\u3001\u7ffb\u8f6c\u64cd\u4f5c\u3002

    \n\n

     

    \n\n

    \u63d0\u793a\uff1a\u4e8c\u7ef4\u6570\u7ec4\u6bcf\u7ef4\u7684\u5927\u5c0f\u90fd\u4e0d\u4f1a\u8d85\u8fc7 50 \u3002

    \n", "tags_en": ["Depth-first Search", "Breadth-first Search", "Hash Table"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numDistinctIslands(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numDistinctIslands(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numDistinctIslands(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numDistinctIslands(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numDistinctIslands(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumDistinctIslands(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar numDistinctIslands = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef num_distinct_islands(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numDistinctIslands(_ grid: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numDistinctIslands(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numDistinctIslands(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numDistinctIslands(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_distinct_islands(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function numDistinctIslands($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numDistinctIslands(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-distinct-islands grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0694](https://leetcode-cn.com/problems/number-of-distinct-islands)", "[\u4e0d\u540c\u5c9b\u5c7f\u7684\u6570\u91cf](/solution/0600-0699/0694.Number%20of%20Distinct%20Islands/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0694](https://leetcode.com/problems/number-of-distinct-islands)", "[Number of Distinct Islands](/solution/0600-0699/0694.Number%20of%20Distinct%20Islands/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`,`Hash Table`", "Medium", "\ud83d\udd12"]}, {"question_id": "0693", "frontend_question_id": "0693", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/binary-number-with-alternating-bits", "url_en": "https://leetcode.com/problems/binary-number-with-alternating-bits", "relative_path_cn": "/solution/0600-0699/0693.Binary%20Number%20with%20Alternating%20Bits/README.md", "relative_path_en": "/solution/0600-0699/0693.Binary%20Number%20with%20Alternating%20Bits/README_EN.md", "title_cn": "\u4ea4\u66ff\u4f4d\u4e8c\u8fdb\u5236\u6570", "title_en": "Binary Number with Alternating Bits", "question_title_slug": "binary-number-with-alternating-bits", "content_en": "

    Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will always have different values.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 5\nOutput: true\nExplanation: The binary representation of 5 is: 101\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 7\nOutput: false\nExplanation: The binary representation of 7 is: 111.
    \n\n

    Example 3:

    \n\n
    \nInput: n = 11\nOutput: false\nExplanation: The binary representation of 11 is: 1011.
    \n\n

    Example 4:

    \n\n
    \nInput: n = 10\nOutput: true\nExplanation: The binary representation of 10 is: 1010.
    \n\n

    Example 5:

    \n\n
    \nInput: n = 3\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 231 - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6b63\u6574\u6570\uff0c\u68c0\u67e5\u5b83\u7684\u4e8c\u8fdb\u5236\u8868\u793a\u662f\u5426\u603b\u662f 0\u30011 \u4ea4\u66ff\u51fa\u73b0\uff1a\u6362\u53e5\u8bdd\u8bf4\uff0c\u5c31\u662f\u4e8c\u8fdb\u5236\u8868\u793a\u4e2d\u76f8\u90bb\u4e24\u4f4d\u7684\u6570\u5b57\u6c38\u4e0d\u76f8\u540c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 5\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a5 \u7684\u4e8c\u8fdb\u5236\u8868\u793a\u662f\uff1a101\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 7\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a7 \u7684\u4e8c\u8fdb\u5236\u8868\u793a\u662f\uff1a111.
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 11\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a11 \u7684\u4e8c\u8fdb\u5236\u8868\u793a\u662f\uff1a1011.
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 10\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a10 \u7684\u4e8c\u8fdb\u5236\u8868\u793a\u662f\uff1a1010.
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 3\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 231 - 1
    • \n
    \n", "tags_en": ["Bit Manipulation"], "tags_cn": ["\u4f4d\u8fd0\u7b97"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool hasAlternatingBits(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean hasAlternatingBits(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def hasAlternatingBits(self, n):\n \"\"\"\n :type n: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def hasAlternatingBits(self, n: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool hasAlternatingBits(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool HasAlternatingBits(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {boolean}\n */\nvar hasAlternatingBits = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Boolean}\ndef has_alternating_bits(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func hasAlternatingBits(_ n: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func hasAlternatingBits(n int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def hasAlternatingBits(n: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun hasAlternatingBits(n: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn has_alternating_bits(n: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Boolean\n */\n function hasAlternatingBits($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function hasAlternatingBits(n: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (has-alternating-bits n)\n (-> exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0693](https://leetcode-cn.com/problems/binary-number-with-alternating-bits)", "[\u4ea4\u66ff\u4f4d\u4e8c\u8fdb\u5236\u6570](/solution/0600-0699/0693.Binary%20Number%20with%20Alternating%20Bits/README.md)", "`\u4f4d\u8fd0\u7b97`", "\u7b80\u5355", ""], "md_table_row_en": ["[0693](https://leetcode.com/problems/binary-number-with-alternating-bits)", "[Binary Number with Alternating Bits](/solution/0600-0699/0693.Binary%20Number%20with%20Alternating%20Bits/README_EN.md)", "`Bit Manipulation`", "Easy", ""]}, {"question_id": "0692", "frontend_question_id": "0692", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/top-k-frequent-words", "url_en": "https://leetcode.com/problems/top-k-frequent-words", "relative_path_cn": "/solution/0600-0699/0692.Top%20K%20Frequent%20Words/README.md", "relative_path_en": "/solution/0600-0699/0692.Top%20K%20Frequent%20Words/README_EN.md", "title_cn": "\u524dK\u4e2a\u9ad8\u9891\u5355\u8bcd", "title_en": "Top K Frequent Words", "question_title_slug": "top-k-frequent-words", "content_en": "

    Given a non-empty list of words, return the k most frequent elements.

    \r\n

    Your answer should be sorted by frequency from highest to lowest. If two words have the same frequency, then the word with the lower alphabetical order comes first.

    \r\n\r\n

    Example 1:
    \r\n

    \r\nInput: [\"i\", \"love\", \"leetcode\", \"i\", \"love\", \"coding\"], k = 2\r\nOutput: [\"i\", \"love\"]\r\nExplanation: \"i\" and \"love\" are the two most frequent words.\r\n    Note that \"i\" comes before \"love\" due to a lower alphabetical order.\r\n
    \r\n

    \r\n\r\n

    Example 2:
    \r\n

    \r\nInput: [\"the\", \"day\", \"is\", \"sunny\", \"the\", \"the\", \"the\", \"sunny\", \"is\", \"is\"], k = 4\r\nOutput: [\"the\", \"is\", \"sunny\", \"day\"]\r\nExplanation: \"the\", \"is\", \"sunny\" and \"day\" are the four most frequent words,\r\n    with the number of occurrence being 4, 3, 2 and 1 respectively.\r\n
    \r\n

    \r\n\r\n

    Note:
    \r\n

      \r\n
    1. You may assume k is always valid, 1 ≤ k ≤ number of unique elements.
    2. \r\n
    3. Input words contain only lowercase letters.
    4. \r\n
    \r\n

    \r\n\r\n

    Follow up:
    \r\n

      \r\n
    1. Try to solve it in O(n log k) time and O(n) extra space.
    2. \r\n
    \r\n

    ", "content_cn": "

    \u7ed9\u4e00\u975e\u7a7a\u7684\u5355\u8bcd\u5217\u8868\uff0c\u8fd4\u56de\u524d \u4e2a\u51fa\u73b0\u6b21\u6570\u6700\u591a\u7684\u5355\u8bcd\u3002

    \n\n

    \u8fd4\u56de\u7684\u7b54\u6848\u5e94\u8be5\u6309\u5355\u8bcd\u51fa\u73b0\u9891\u7387\u7531\u9ad8\u5230\u4f4e\u6392\u5e8f\u3002\u5982\u679c\u4e0d\u540c\u7684\u5355\u8bcd\u6709\u76f8\u540c\u51fa\u73b0\u9891\u7387\uff0c\u6309\u5b57\u6bcd\u987a\u5e8f\u6392\u5e8f\u3002

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165: ["i", "love", "leetcode", "i", "love", "coding"], k = 2\n\u8f93\u51fa: ["i", "love"]\n\u89e3\u6790: "i" \u548c "love" \u4e3a\u51fa\u73b0\u6b21\u6570\u6700\u591a\u7684\u4e24\u4e2a\u5355\u8bcd\uff0c\u5747\u4e3a2\u6b21\u3002\n    \u6ce8\u610f\uff0c\u6309\u5b57\u6bcd\u987a\u5e8f "i" \u5728 "love" \u4e4b\u524d\u3002\n
    \n\n

     

    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165: ["the", "day", "is", "sunny", "the", "the", "the", "sunny", "is", "is"], k = 4\n\u8f93\u51fa: ["the", "is", "sunny", "day"]\n\u89e3\u6790: "the", "is", "sunny" \u548c "day" \u662f\u51fa\u73b0\u6b21\u6570\u6700\u591a\u7684\u56db\u4e2a\u5355\u8bcd\uff0c\n    \u51fa\u73b0\u6b21\u6570\u4f9d\u6b21\u4e3a 4, 3, 2 \u548c 1 \u6b21\u3002\n
    \n\n

     

    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    1. \u5047\u5b9a k \u603b\u4e3a\u6709\u6548\u503c\uff0c 1 ≤ k ≤ \u96c6\u5408\u5143\u7d20\u6570\u3002
    2. \n\t
    3. \u8f93\u5165\u7684\u5355\u8bcd\u5747\u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210\u3002
    4. \n
    \n\n

     

    \n\n

    \u6269\u5c55\u7ec3\u4e60\uff1a

    \n\n
      \n\t
    1. \u5c1d\u8bd5\u4ee5 O(n log k) \u65f6\u95f4\u590d\u6742\u5ea6\u548c O(n) \u7a7a\u95f4\u590d\u6742\u5ea6\u89e3\u51b3\u3002
    2. \n
    \n", "tags_en": ["Heap", "Trie", "Hash Table"], "tags_cn": ["\u5806", "\u5b57\u5178\u6811", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector topKFrequent(vector& words, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List topKFrequent(String[] words, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def topKFrequent(self, words, k):\n \"\"\"\n :type words: List[str]\n :type k: int\n :rtype: List[str]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def topKFrequent(self, words: List[str], k: int) -> List[str]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** topKFrequent(char ** words, int wordsSize, int k, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList TopKFrequent(string[] words, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @param {number} k\n * @return {string[]}\n */\nvar topKFrequent = function(words, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @param {Integer} k\n# @return {String[]}\ndef top_k_frequent(words, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func topKFrequent(_ words: [String], _ k: Int) -> [String] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func topKFrequent(words []string, k int) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def topKFrequent(words: Array[String], k: Int): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun topKFrequent(words: Array, k: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn top_k_frequent(words: Vec, k: i32) -> Vec {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @param Integer $k\n * @return String[]\n */\n function topKFrequent($words, $k) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function topKFrequent(words: string[], k: number): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (top-k-frequent words k)\n (-> (listof string?) exact-integer? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0692](https://leetcode-cn.com/problems/top-k-frequent-words)", "[\u524dK\u4e2a\u9ad8\u9891\u5355\u8bcd](/solution/0600-0699/0692.Top%20K%20Frequent%20Words/README.md)", "`\u5806`,`\u5b57\u5178\u6811`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0692](https://leetcode.com/problems/top-k-frequent-words)", "[Top K Frequent Words](/solution/0600-0699/0692.Top%20K%20Frequent%20Words/README_EN.md)", "`Heap`,`Trie`,`Hash Table`", "Medium", ""]}, {"question_id": "0691", "frontend_question_id": "0691", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/stickers-to-spell-word", "url_en": "https://leetcode.com/problems/stickers-to-spell-word", "relative_path_cn": "/solution/0600-0699/0691.Stickers%20to%20Spell%20Word/README.md", "relative_path_en": "/solution/0600-0699/0691.Stickers%20to%20Spell%20Word/README_EN.md", "title_cn": "\u8d34\u7eb8\u62fc\u8bcd", "title_en": "Stickers to Spell Word", "question_title_slug": "stickers-to-spell-word", "content_en": "

    We are given n different types of stickers. Each sticker has a lowercase English word on it.

    \n\n

    You would like to spell out the given string target by cutting individual letters from your collection of stickers and rearranging them. You can use each sticker more than once if you want, and you have infinite quantities of each sticker.

    \n\n

    Return the minimum number of stickers that you need to spell out target. If the task is impossible, return -1.

    \n\n

    Note: In all test cases, all words were chosen randomly from the 1000 most common US English words, and target was chosen as a concatenation of two random words.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: stickers = ["with","example","science"], target = "thehat"\nOutput: 3\nExplanation:\nWe can use 2 "with" stickers, and 1 "example" sticker.\nAfter cutting and rearrange the letters of those stickers, we can form the target "thehat".\nAlso, this is the minimum number of stickers necessary to form the target string.\n
    \n\n

    Example 2:

    \n\n
    \nInput: stickers = ["notice","possible"], target = "basicbasic"\nOutput: -1\nExplanation:\nWe cannot form the target "basicbasic" from cutting letters from the given stickers.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == stickers.length
    • \n\t
    • 1 <= n <= 50
    • \n\t
    • 1 <= stickers[i].length <= 10
    • \n\t
    • 1 <= target <= 15
    • \n\t
    • stickers[i] and target consist of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u6211\u4eec\u7ed9\u51fa\u4e86 N \u79cd\u4e0d\u540c\u7c7b\u578b\u7684\u8d34\u7eb8\u3002\u6bcf\u4e2a\u8d34\u7eb8\u4e0a\u90fd\u6709\u4e00\u4e2a\u5c0f\u5199\u7684\u82f1\u6587\u5355\u8bcd\u3002

    \n\n

    \u4f60\u5e0c\u671b\u4ece\u81ea\u5df1\u7684\u8d34\u7eb8\u96c6\u5408\u4e2d\u88c1\u526a\u5355\u4e2a\u5b57\u6bcd\u5e76\u91cd\u65b0\u6392\u5217\u5b83\u4eec\uff0c\u4ece\u800c\u62fc\u5199\u51fa\u7ed9\u5b9a\u7684\u76ee\u6807\u5b57\u7b26\u4e32 target\u3002

    \n\n

    \u5982\u679c\u4f60\u613f\u610f\u7684\u8bdd\uff0c\u4f60\u53ef\u4ee5\u4e0d\u6b62\u4e00\u6b21\u5730\u4f7f\u7528\u6bcf\u4e00\u5f20\u8d34\u7eb8\uff0c\u800c\u4e14\u6bcf\u4e00\u5f20\u8d34\u7eb8\u7684\u6570\u91cf\u90fd\u662f\u65e0\u9650\u7684\u3002

    \n\n

    \u62fc\u51fa\u76ee\u6807 target \u6240\u9700\u7684\u6700\u5c0f\u8d34\u7eb8\u6570\u91cf\u662f\u591a\u5c11\uff1f\u5982\u679c\u4efb\u52a1\u4e0d\u53ef\u80fd\uff0c\u5219\u8fd4\u56de -1\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \u8f93\u5165\uff1a

    \n\n
    ["with", "example", "science"], "thehat"\n
    \n\n

    \u8f93\u51fa\uff1a

    \n\n
    3\n
    \n\n

    \u89e3\u91ca\uff1a

    \n\n
    \u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 2 \u4e2a "with" \u8d34\u7eb8\uff0c\u548c 1 \u4e2a "example" \u8d34\u7eb8\u3002\n\u628a\u8d34\u7eb8\u4e0a\u7684\u5b57\u6bcd\u526a\u4e0b\u6765\u5e76\u91cd\u65b0\u6392\u5217\u540e\uff0c\u5c31\u53ef\u4ee5\u5f62\u6210\u76ee\u6807 “thehat“ \u4e86\u3002\n\u6b64\u5916\uff0c\u8fd9\u662f\u5f62\u6210\u76ee\u6807\u5b57\u7b26\u4e32\u6240\u9700\u7684\u6700\u5c0f\u8d34\u7eb8\u6570\u91cf\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \u8f93\u5165\uff1a

    \n\n
    ["notice", "possible"], "basicbasic"\n
    \n\n

    \u8f93\u51fa\uff1a

    \n\n
    -1\n
    \n\n

    \u89e3\u91ca\uff1a

    \n\n
    \u6211\u4eec\u4e0d\u80fd\u901a\u8fc7\u526a\u5207\u7ed9\u5b9a\u8d34\u7eb8\u7684\u5b57\u6bcd\u6765\u5f62\u6210\u76ee\u6807“basicbasic”\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • stickers \u957f\u5ea6\u8303\u56f4\u662f [1, 50]\u3002
    • \n\t
    • stickers \u7531\u5c0f\u5199\u82f1\u6587\u5355\u8bcd\u7ec4\u6210\uff08\u4e0d\u5e26\u6487\u53f7\uff09\u3002
    • \n\t
    • target \u7684\u957f\u5ea6\u5728 [1, 15] \u8303\u56f4\u5185\uff0c\u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210\u3002
    • \n\t
    • \u5728\u6240\u6709\u7684\u6d4b\u8bd5\u6848\u4f8b\u4e2d\uff0c\u6240\u6709\u7684\u5355\u8bcd\u90fd\u662f\u4ece 1000 \u4e2a\u6700\u5e38\u89c1\u7684\u7f8e\u56fd\u82f1\u8bed\u5355\u8bcd\u4e2d\u968f\u673a\u9009\u53d6\u7684\uff0c\u76ee\u6807\u662f\u4e24\u4e2a\u968f\u673a\u5355\u8bcd\u7684\u4e32\u8054\u3002
    • \n\t
    • \u65f6\u95f4\u9650\u5236\u53ef\u80fd\u6bd4\u5e73\u65f6\u66f4\u5177\u6311\u6218\u6027\u3002\u9884\u8ba1 50 \u4e2a\u8d34\u7eb8\u7684\u6d4b\u8bd5\u6848\u4f8b\u5e73\u5747\u53ef\u572835ms\u5185\u89e3\u51b3\u3002
    • \n
    \n\n

     

    \n", "tags_en": ["Dynamic Programming", "Backtracking"], "tags_cn": ["\u52a8\u6001\u89c4\u5212", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minStickers(vector& stickers, string target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minStickers(String[] stickers, String target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minStickers(self, stickers, target):\n \"\"\"\n :type stickers: List[str]\n :type target: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minStickers(self, stickers: List[str], target: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minStickers(char ** stickers, int stickersSize, char * target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinStickers(string[] stickers, string target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} stickers\n * @param {string} target\n * @return {number}\n */\nvar minStickers = function(stickers, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} stickers\n# @param {String} target\n# @return {Integer}\ndef min_stickers(stickers, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minStickers(_ stickers: [String], _ target: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minStickers(stickers []string, target string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minStickers(stickers: Array[String], target: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minStickers(stickers: Array, target: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_stickers(stickers: Vec, target: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $stickers\n * @param String $target\n * @return Integer\n */\n function minStickers($stickers, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minStickers(stickers: string[], target: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-stickers stickers target)\n (-> (listof string?) string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0691](https://leetcode-cn.com/problems/stickers-to-spell-word)", "[\u8d34\u7eb8\u62fc\u8bcd](/solution/0600-0699/0691.Stickers%20to%20Spell%20Word/README.md)", "`\u52a8\u6001\u89c4\u5212`,`\u56de\u6eaf\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[0691](https://leetcode.com/problems/stickers-to-spell-word)", "[Stickers to Spell Word](/solution/0600-0699/0691.Stickers%20to%20Spell%20Word/README_EN.md)", "`Dynamic Programming`,`Backtracking`", "Hard", ""]}, {"question_id": "0690", "frontend_question_id": "0690", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/employee-importance", "url_en": "https://leetcode.com/problems/employee-importance", "relative_path_cn": "/solution/0600-0699/0690.Employee%20Importance/README.md", "relative_path_en": "/solution/0600-0699/0690.Employee%20Importance/README_EN.md", "title_cn": "\u5458\u5de5\u7684\u91cd\u8981\u6027", "title_en": "Employee Importance", "question_title_slug": "employee-importance", "content_en": "

    You have a data structure of employee information, which includes the employee's unique id, their importance value, and their direct subordinates' id.

    \n\n

    You are given an array of employees employees where:

    \n\n
      \n\t
    • employees[i].id is the ID of the ith employee.
    • \n\t
    • employees[i].importance is the importance value of the ith employee.
    • \n\t
    • employees[i].subordinates is a list of the IDs of the subordinates of the ith employee.
    • \n
    \n\n

    Given an integer id that represents the ID of an employee, return the total importance value of this employee and all their subordinates.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: employees = [[1,5,[2,3]],[2,3,[]],[3,3,[]]], id = 1\nOutput: 11\nExplanation: Employee 1 has importance value 5, and he has two direct subordinates: employee 2 and employee 3.\nThey both have importance value 3.\nSo the total importance value of employee 1 is 5 + 3 + 3 = 11.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: employees = [[1,2,[5]],[5,-3,[]]], id = 5\nOutput: -3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= employees.length <= 2000
    • \n\t
    • 1 <= employees[i].id <= 2000
    • \n\t
    • All employees[i].id are unique.
    • \n\t
    • -100 <= employees[i].importance <= 100
    • \n\t
    • One employee has at most one direct leader and may have several subordinates.
    • \n\t
    • id is guaranteed to be a valid employee id.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4fdd\u5b58\u5458\u5de5\u4fe1\u606f\u7684\u6570\u636e\u7ed3\u6784\uff0c\u5b83\u5305\u542b\u4e86\u5458\u5de5 \u552f\u4e00\u7684 id \uff0c\u91cd\u8981\u5ea6\u00a0\u548c \u76f4\u7cfb\u4e0b\u5c5e\u7684 id \u3002

    \n\n

    \u6bd4\u5982\uff0c\u5458\u5de5 1 \u662f\u5458\u5de5 2 \u7684\u9886\u5bfc\uff0c\u5458\u5de5 2 \u662f\u5458\u5de5 3 \u7684\u9886\u5bfc\u3002\u4ed6\u4eec\u76f8\u5e94\u7684\u91cd\u8981\u5ea6\u4e3a 15 , 10 , 5 \u3002\u90a3\u4e48\u5458\u5de5 1 \u7684\u6570\u636e\u7ed3\u6784\u662f [1, 15, [2]] \uff0c\u5458\u5de5 2\u7684 \u6570\u636e\u7ed3\u6784\u662f [2, 10, [3]] \uff0c\u5458\u5de5 3 \u7684\u6570\u636e\u7ed3\u6784\u662f [3, 5, []] \u3002\u6ce8\u610f\u867d\u7136\u5458\u5de5 3 \u4e5f\u662f\u5458\u5de5 1 \u7684\u4e00\u4e2a\u4e0b\u5c5e\uff0c\u4f46\u662f\u7531\u4e8e \u5e76\u4e0d\u662f\u76f4\u7cfb \u4e0b\u5c5e\uff0c\u56e0\u6b64\u6ca1\u6709\u4f53\u73b0\u5728\u5458\u5de5 1 \u7684\u6570\u636e\u7ed3\u6784\u4e2d\u3002

    \n\n

    \u73b0\u5728\u8f93\u5165\u4e00\u4e2a\u516c\u53f8\u7684\u6240\u6709\u5458\u5de5\u4fe1\u606f\uff0c\u4ee5\u53ca\u5355\u4e2a\u5458\u5de5 id \uff0c\u8fd4\u56de\u8fd9\u4e2a\u5458\u5de5\u548c\u4ed6\u6240\u6709\u4e0b\u5c5e\u7684\u91cd\u8981\u5ea6\u4e4b\u548c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[[1, 5, [2, 3]], [2, 3, []], [3, 3, []]], 1\n\u8f93\u51fa\uff1a11\n\u89e3\u91ca\uff1a\n\u5458\u5de5 1 \u81ea\u8eab\u7684\u91cd\u8981\u5ea6\u662f 5 \uff0c\u4ed6\u6709\u4e24\u4e2a\u76f4\u7cfb\u4e0b\u5c5e 2 \u548c 3 \uff0c\u800c\u4e14 2 \u548c 3 \u7684\u91cd\u8981\u5ea6\u5747\u4e3a 3 \u3002\u56e0\u6b64\u5458\u5de5 1 \u7684\u603b\u91cd\u8981\u5ea6\u662f 5 + 3 + 3 = 11 \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u4e00\u4e2a\u5458\u5de5\u6700\u591a\u6709\u4e00\u4e2a \u76f4\u7cfb \u9886\u5bfc\uff0c\u4f46\u662f\u53ef\u4ee5\u6709\u591a\u4e2a \u76f4\u7cfb \u4e0b\u5c5e
    • \n\t
    • \u5458\u5de5\u6570\u91cf\u4e0d\u8d85\u8fc7 2000 \u3002
    • \n
    \n", "tags_en": ["Depth-first Search", "Breadth-first Search", "Hash Table"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n// Definition for Employee.\nclass Employee {\npublic:\n int id;\n int importance;\n vector subordinates;\n};\n*/\n\nclass Solution {\npublic:\n int getImportance(vector 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 subordinates;\n};\n*/\n\nclass Solution {\n public int getImportance(List 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 subordinates;\n}\n*/\n\nclass Solution {\n public int GetImportance(IList 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"}, {"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": "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}", "__typename": "CodeSnippetNode"}, {"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}", "__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}", "__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 = listOf()\n *\t}\n */\n\nclass Solution {\n fun getImportance(employees: List, id: Int): Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"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}", "__typename": "CodeSnippetNode"}, {"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};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0690](https://leetcode-cn.com/problems/employee-importance)", "[\u5458\u5de5\u7684\u91cd\u8981\u6027](/solution/0600-0699/0690.Employee%20Importance/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0690](https://leetcode.com/problems/employee-importance)", "[Employee Importance](/solution/0600-0699/0690.Employee%20Importance/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`,`Hash Table`", "Easy", ""]}, {"question_id": "0689", "frontend_question_id": "0689", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-sum-of-3-non-overlapping-subarrays", "url_en": "https://leetcode.com/problems/maximum-sum-of-3-non-overlapping-subarrays", "relative_path_cn": "/solution/0600-0699/0689.Maximum%20Sum%20of%203%20Non-Overlapping%20Subarrays/README.md", "relative_path_en": "/solution/0600-0699/0689.Maximum%20Sum%20of%203%20Non-Overlapping%20Subarrays/README_EN.md", "title_cn": "\u4e09\u4e2a\u65e0\u91cd\u53e0\u5b50\u6570\u7ec4\u7684\u6700\u5927\u548c", "title_en": "Maximum Sum of 3 Non-Overlapping Subarrays", "question_title_slug": "maximum-sum-of-3-non-overlapping-subarrays", "content_en": "

    Given an integer array nums and an integer k, find three non-overlapping subarrays of length k with maximum sum and return them.

    \n\n

    Return the result as a list of indices representing the starting position of each interval (0-indexed). If there are multiple answers, return the lexicographically smallest one.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,1,2,6,7,5,1], k = 2\nOutput: [0,3,5]\nExplanation: Subarrays [1, 2], [2, 6], [7, 5] correspond to the starting indices [0, 3, 5].\nWe could have also taken [2, 1], but an answer of [1, 3, 5] would be lexicographically larger.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,2,1,2,1,2,1,2,1], k = 2\nOutput: [0,2,4]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 2 * 104
    • \n\t
    • 1 <= nums[i] < 216
    • \n\t
    • 1 <= k <= floor(nums.length / 3)
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u6570\u7ec4 nums \u7531\u6b63\u6574\u6570\u7ec4\u6210\uff0c\u627e\u5230\u4e09\u4e2a\u4e92\u4e0d\u91cd\u53e0\u7684\u5b50\u6570\u7ec4\u7684\u6700\u5927\u548c\u3002

    \n\n

    \u6bcf\u4e2a\u5b50\u6570\u7ec4\u7684\u957f\u5ea6\u4e3ak\uff0c\u6211\u4eec\u8981\u4f7f\u8fd93*k\u4e2a\u9879\u7684\u548c\u6700\u5927\u5316\u3002

    \n\n

    \u8fd4\u56de\u6bcf\u4e2a\u533a\u95f4\u8d77\u59cb\u7d22\u5f15\u7684\u5217\u8868\uff08\u7d22\u5f15\u4ece 0 \u5f00\u59cb\uff09\u3002\u5982\u679c\u6709\u591a\u4e2a\u7ed3\u679c\uff0c\u8fd4\u56de\u5b57\u5178\u5e8f\u6700\u5c0f\u7684\u4e00\u4e2a\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \n\u8f93\u5165: [1,2,1,2,6,7,5,1], 2\n\u8f93\u51fa: [0, 3, 5]\n\u89e3\u91ca: \u5b50\u6570\u7ec4 [1, 2], [2, 6], [7, 5] \u5bf9\u5e94\u7684\u8d77\u59cb\u7d22\u5f15\u4e3a [0, 3, 5]\u3002\n\u6211\u4eec\u4e5f\u53ef\u4ee5\u53d6 [2, 1], \u4f46\u662f\u7ed3\u679c [1, 3, 5] \u5728\u5b57\u5178\u5e8f\u4e0a\u66f4\u5927\u3002\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    • nums.length\u7684\u8303\u56f4\u5728[1, 20000]\u4e4b\u95f4\u3002
    • \n\t
    • nums[i]\u7684\u8303\u56f4\u5728[1, 65535]\u4e4b\u95f4\u3002
    • \n\t
    • k\u7684\u8303\u56f4\u5728[1, floor(nums.length / 3)]\u4e4b\u95f4\u3002
    • \n
    \n", "tags_en": ["Array", "Dynamic Programming"], "tags_cn": ["\u6570\u7ec4", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector maxSumOfThreeSubarrays(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] maxSumOfThreeSubarrays(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxSumOfThreeSubarrays(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxSumOfThreeSubarrays(self, nums: List[int], k: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* maxSumOfThreeSubarrays(int* nums, int numsSize, int k, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] MaxSumOfThreeSubarrays(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number[]}\n */\nvar maxSumOfThreeSubarrays = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer[]}\ndef max_sum_of_three_subarrays(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxSumOfThreeSubarrays(_ nums: [Int], _ k: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxSumOfThreeSubarrays(nums []int, k int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxSumOfThreeSubarrays(nums: Array[Int], k: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxSumOfThreeSubarrays(nums: IntArray, k: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_sum_of_three_subarrays(nums: Vec, k: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer[]\n */\n function maxSumOfThreeSubarrays($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxSumOfThreeSubarrays(nums: number[], k: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-sum-of-three-subarrays nums k)\n (-> (listof exact-integer?) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0689](https://leetcode-cn.com/problems/maximum-sum-of-3-non-overlapping-subarrays)", "[\u4e09\u4e2a\u65e0\u91cd\u53e0\u5b50\u6570\u7ec4\u7684\u6700\u5927\u548c](/solution/0600-0699/0689.Maximum%20Sum%20of%203%20Non-Overlapping%20Subarrays/README.md)", "`\u6570\u7ec4`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0689](https://leetcode.com/problems/maximum-sum-of-3-non-overlapping-subarrays)", "[Maximum Sum of 3 Non-Overlapping Subarrays](/solution/0600-0699/0689.Maximum%20Sum%20of%203%20Non-Overlapping%20Subarrays/README_EN.md)", "`Array`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0688", "frontend_question_id": "0688", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/knight-probability-in-chessboard", "url_en": "https://leetcode.com/problems/knight-probability-in-chessboard", "relative_path_cn": "/solution/0600-0699/0688.Knight%20Probability%20in%20Chessboard/README.md", "relative_path_en": "/solution/0600-0699/0688.Knight%20Probability%20in%20Chessboard/README_EN.md", "title_cn": "\u201c\u9a6c\u201d\u5728\u68cb\u76d8\u4e0a\u7684\u6982\u7387", "title_en": "Knight Probability in Chessboard", "question_title_slug": "knight-probability-in-chessboard", "content_en": "

    On an n x n chessboard, a knight starts at the cell (row, column) and attempts to make exactly k moves. The rows and columns are 0-indexed, so the top-left cell is (0, 0), and the bottom-right cell is (n - 1, n - 1).

    \n\n

    A chess knight has eight possible moves it can make, as illustrated below. Each move is two cells in a cardinal direction, then one cell in an orthogonal direction.

    \n\n

    Each time the knight is to move, it chooses one of eight possible moves uniformly at random (even if the piece would go off the chessboard) and moves there.

    \n\n

    The knight continues moving until it has made exactly k moves or has moved off the chessboard.

    \n\n

    Return the probability that the knight remains on the board after it has stopped moving.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 3, k = 2, row = 0, column = 0\nOutput: 0.06250\nExplanation: There are two moves (to (1,2), (2,1)) that will keep the knight on the board.\nFrom each of those positions, there are also two moves that will keep the knight on the board.\nThe total probability the knight stays on the board is 0.0625.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 1, k = 0, row = 0, column = 0\nOutput: 1.00000\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 25
    • \n\t
    • 0 <= k <= 100
    • \n\t
    • 0 <= row, column <= n
    • \n
    \n", "content_cn": "

    \u5df2\u77e5\u4e00\u4e2a NxN \u7684\u56fd\u9645\u8c61\u68cb\u68cb\u76d8\uff0c\u68cb\u76d8\u7684\u884c\u53f7\u548c\u5217\u53f7\u90fd\u662f\u4ece 0 \u5f00\u59cb\u3002\u5373\u6700\u5de6\u4e0a\u89d2\u7684\u683c\u5b50\u8bb0\u4e3a (0, 0)\uff0c\u6700\u53f3\u4e0b\u89d2\u7684\u8bb0\u4e3a (N-1, N-1)\u3002 

    \n\n

    \u73b0\u6709\u4e00\u4e2a “\u9a6c”\uff08\u4e5f\u8bd1\u4f5c “\u9a91\u58eb”\uff09\u4f4d\u4e8e (r, c) \uff0c\u5e76\u6253\u7b97\u8fdb\u884c K \u6b21\u79fb\u52a8\u3002 

    \n\n

    \u5982\u4e0b\u56fe\u6240\u793a\uff0c\u56fd\u9645\u8c61\u68cb\u7684 “\u9a6c” \u6bcf\u4e00\u6b65\u5148\u6cbf\u6c34\u5e73\u6216\u5782\u76f4\u65b9\u5411\u79fb\u52a8 2 \u4e2a\u683c\u5b50\uff0c\u7136\u540e\u5411\u4e0e\u4e4b\u76f8\u5782\u76f4\u7684\u65b9\u5411\u518d\u79fb\u52a8 1 \u4e2a\u683c\u5b50\uff0c\u5171\u6709 8 \u4e2a\u53ef\u9009\u7684\u4f4d\u7f6e\u3002

    \n\n

     

    \n\n

    \n\n

     

    \n\n

    \u73b0\u5728 “\u9a6c” \u6bcf\u4e00\u6b65\u90fd\u4ece\u53ef\u9009\u7684\u4f4d\u7f6e\uff08\u5305\u62ec\u68cb\u76d8\u5916\u90e8\u7684\uff09\u4e2d\u72ec\u7acb\u968f\u673a\u5730\u9009\u62e9\u4e00\u4e2a\u8fdb\u884c\u79fb\u52a8\uff0c\u76f4\u5230\u79fb\u52a8\u4e86 K \u6b21\u6216\u8df3\u5230\u4e86\u68cb\u76d8\u5916\u9762\u3002

    \n\n

    \u6c42\u79fb\u52a8\u7ed3\u675f\u540e\uff0c“\u9a6c” \u4ecd\u7559\u5728\u68cb\u76d8\u4e0a\u7684\u6982\u7387\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165: 3, 2, 0, 0\n\u8f93\u51fa: 0.0625\n\u89e3\u91ca: \n\u8f93\u5165\u7684\u6570\u636e\u4f9d\u6b21\u4e3a N, K, r, c\n\u7b2c 1 \u6b65\u65f6\uff0c\u6709\u4e14\u53ea\u6709 2 \u79cd\u8d70\u6cd5\u4ee4 “\u9a6c” \u53ef\u4ee5\u7559\u5728\u68cb\u76d8\u4e0a\uff08\u8df3\u5230\uff081,2\uff09\u6216\uff082,1\uff09\uff09\u3002\u5bf9\u4e8e\u4ee5\u4e0a\u7684\u4e24\u79cd\u60c5\u51b5\uff0c\u5404\u81ea\u5728\u7b2c2\u6b65\u5747\u6709\u4e14\u53ea\u67092\u79cd\u8d70\u6cd5\u4ee4 “\u9a6c” \u4ecd\u7136\u7559\u5728\u68cb\u76d8\u4e0a\u3002\n\u6240\u4ee5 “\u9a6c” \u5728\u7ed3\u675f\u540e\u4ecd\u5728\u68cb\u76d8\u4e0a\u7684\u6982\u7387\u4e3a 0.0625\u3002\n
    \n\n

     

    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    • N \u7684\u53d6\u503c\u8303\u56f4\u4e3a [1, 25]
    • \n\t
    • K \u7684\u53d6\u503c\u8303\u56f4\u4e3a [0, 100]
    • \n\t
    • \u5f00\u59cb\u65f6\uff0c“\u9a6c” \u603b\u662f\u4f4d\u4e8e\u68cb\u76d8\u4e0a
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n double knightProbability(int n, int k, int row, int column) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double knightProbability(int n, int k, int row, int column) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def knightProbability(self, n, k, row, column):\n \"\"\"\n :type n: int\n :type k: int\n :type row: int\n :type column: int\n :rtype: float\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def knightProbability(self, n: int, k: int, row: int, column: int) -> float:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\ndouble knightProbability(int n, int k, int row, int column){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double KnightProbability(int n, int k, int row, int column) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} k\n * @param {number} row\n * @param {number} column\n * @return {number}\n */\nvar knightProbability = function(n, k, row, column) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} k\n# @param {Integer} row\n# @param {Integer} column\n# @return {Float}\ndef knight_probability(n, k, row, column)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func knightProbability(_ n: Int, _ k: Int, _ row: Int, _ column: Int) -> Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func knightProbability(n int, k int, row int, column int) float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def knightProbability(n: Int, k: Int, row: Int, column: Int): Double = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun knightProbability(n: Int, k: Int, row: Int, column: Int): Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn knight_probability(n: i32, k: i32, row: i32, column: i32) -> f64 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $k\n * @param Integer $row\n * @param Integer $column\n * @return Float\n */\n function knightProbability($n, $k, $row, $column) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function knightProbability(n: number, k: number, row: number, column: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (knight-probability n k row column)\n (-> exact-integer? exact-integer? exact-integer? exact-integer? flonum?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0688](https://leetcode-cn.com/problems/knight-probability-in-chessboard)", "[\u201c\u9a6c\u201d\u5728\u68cb\u76d8\u4e0a\u7684\u6982\u7387](/solution/0600-0699/0688.Knight%20Probability%20in%20Chessboard/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0688](https://leetcode.com/problems/knight-probability-in-chessboard)", "[Knight Probability in Chessboard](/solution/0600-0699/0688.Knight%20Probability%20in%20Chessboard/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0687", "frontend_question_id": "0687", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-univalue-path", "url_en": "https://leetcode.com/problems/longest-univalue-path", "relative_path_cn": "/solution/0600-0699/0687.Longest%20Univalue%20Path/README.md", "relative_path_en": "/solution/0600-0699/0687.Longest%20Univalue%20Path/README_EN.md", "title_cn": "\u6700\u957f\u540c\u503c\u8def\u5f84", "title_en": "Longest Univalue Path", "question_title_slug": "longest-univalue-path", "content_en": "

    Given the root of a binary tree, return the length of the longest path, where each node in the path has the same value. This path may or may not pass through the root.

    \n\n

    The length of the path between two nodes is represented by the number of edges between them.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [5,4,5,1,1,5]\nOutput: 2\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [1,4,5,4,4,5]\nOutput: 2\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [0, 104].
    • \n\t
    • -1000 <= Node.val <= 1000
    • \n\t
    • The depth of the tree will not exceed 1000.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811\uff0c\u627e\u5230\u6700\u957f\u7684\u8def\u5f84\uff0c\u8fd9\u4e2a\u8def\u5f84\u4e2d\u7684\u6bcf\u4e2a\u8282\u70b9\u5177\u6709\u76f8\u540c\u503c\u3002 \u8fd9\u6761\u8def\u5f84\u53ef\u4ee5\u7ecf\u8fc7\u4e5f\u53ef\u4ee5\u4e0d\u7ecf\u8fc7\u6839\u8282\u70b9\u3002

    \n\n

    \u6ce8\u610f\uff1a\u4e24\u4e2a\u8282\u70b9\u4e4b\u95f4\u7684\u8def\u5f84\u957f\u5ea6\u7531\u5b83\u4eec\u4e4b\u95f4\u7684\u8fb9\u6570\u8868\u793a\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n

    \u8f93\u5165:

    \n\n
    \n              5\n             / \\\n            4   5\n           / \\   \\\n          1   1   5\n
    \n\n

    \u8f93\u51fa:

    \n\n
    \n2\n
    \n\n

    \u793a\u4f8b 2:

    \n\n

    \u8f93\u5165:

    \n\n
    \n              1\n             / \\\n            4   5\n           / \\   \\\n          4   4   5\n
    \n\n

    \u8f93\u51fa:

    \n\n
    \n2\n
    \n\n

    \u6ce8\u610f: \u7ed9\u5b9a\u7684\u4e8c\u53c9\u6811\u4e0d\u8d85\u8fc710000\u4e2a\u7ed3\u70b9\u3002 \u6811\u7684\u9ad8\u5ea6\u4e0d\u8d85\u8fc71000\u3002

    \n", "tags_en": ["Tree", "Recursion"], "tags_cn": ["\u6811", "\u9012\u5f52"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int longestUnivaluePath(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int longestUnivaluePath(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def longestUnivaluePath(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def longestUnivaluePath(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint longestUnivaluePath(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int LongestUnivaluePath(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar longestUnivaluePath = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef longest_univalue_path(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func longestUnivaluePath(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc longestUnivaluePath(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def longestUnivaluePath(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun longestUnivaluePath(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn longest_univalue_path(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function longestUnivaluePath($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction longestUnivaluePath(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (longest-univalue-path root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0687](https://leetcode-cn.com/problems/longest-univalue-path)", "[\u6700\u957f\u540c\u503c\u8def\u5f84](/solution/0600-0699/0687.Longest%20Univalue%20Path/README.md)", "`\u6811`,`\u9012\u5f52`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0687](https://leetcode.com/problems/longest-univalue-path)", "[Longest Univalue Path](/solution/0600-0699/0687.Longest%20Univalue%20Path/README_EN.md)", "`Tree`,`Recursion`", "Medium", ""]}, {"question_id": "0686", "frontend_question_id": "0686", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/repeated-string-match", "url_en": "https://leetcode.com/problems/repeated-string-match", "relative_path_cn": "/solution/0600-0699/0686.Repeated%20String%20Match/README.md", "relative_path_en": "/solution/0600-0699/0686.Repeated%20String%20Match/README_EN.md", "title_cn": "\u91cd\u590d\u53e0\u52a0\u5b57\u7b26\u4e32\u5339\u914d", "title_en": "Repeated String Match", "question_title_slug": "repeated-string-match", "content_en": "

    Given two strings a and b, return the minimum number of times you should repeat string a so that string b is a substring of it. If it is impossible for b\u200b\u200b\u200b\u200b\u200b\u200b to be a substring of a after repeating it, return -1.

    \n\n

    Notice: string "abc" repeated 0 times is "",  repeated 1 time is "abc" and repeated 2 times is "abcabc".

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: a = "abcd", b = "cdabcdab"\nOutput: 3\nExplanation: We return 3 because by repeating a three times "abcdabcdabcd", b is a substring of it.\n
    \n\n

    Example 2:

    \n\n
    \nInput: a = "a", b = "aa"\nOutput: 2\n
    \n\n

    Example 3:

    \n\n
    \nInput: a = "a", b = "a"\nOutput: 1\n
    \n\n

    Example 4:

    \n\n
    \nInput: a = "abc", b = "wxyz"\nOutput: -1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= a.length <= 104
    • \n\t
    • 1 <= b.length <= 104
    • \n\t
    • a and b consist of lower-case English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u5b57\u7b26\u4e32 a \u548c b\uff0c\u5bfb\u627e\u91cd\u590d\u53e0\u52a0\u5b57\u7b26\u4e32 a \u7684\u6700\u5c0f\u6b21\u6570\uff0c\u4f7f\u5f97\u5b57\u7b26\u4e32 b \u6210\u4e3a\u53e0\u52a0\u540e\u7684\u5b57\u7b26\u4e32 a \u7684\u5b50\u4e32\uff0c\u5982\u679c\u4e0d\u5b58\u5728\u5219\u8fd4\u56de -1\u3002

    \n\n

    \u6ce8\u610f\uff1a\u5b57\u7b26\u4e32 "abc" \u91cd\u590d\u53e0\u52a0 0 \u6b21\u662f ""\uff0c\u91cd\u590d\u53e0\u52a0 1 \u6b21\u662f "abc"\uff0c\u91cd\u590d\u53e0\u52a0 2 \u6b21\u662f "abcabc"\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aa = "abcd", b = "cdabcdab"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1aa \u91cd\u590d\u53e0\u52a0\u4e09\u904d\u540e\u4e3a "abcdabcdabcd", \u6b64\u65f6 b \u662f\u5176\u5b50\u4e32\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aa = "a", b = "aa"\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aa = "a", b = "a"\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1aa = "abc", b = "wxyz"\n\u8f93\u51fa\uff1a-1\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= a.length <= 104
    • \n\t
    • 1 <= b.length <= 104
    • \n\t
    • a \u548c b \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int repeatedStringMatch(string a, string b) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int repeatedStringMatch(String a, String b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def repeatedStringMatch(self, a, b):\n \"\"\"\n :type a: str\n :type b: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def repeatedStringMatch(self, a: str, b: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint repeatedStringMatch(char * a, char * b){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int RepeatedStringMatch(string a, string b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} a\n * @param {string} b\n * @return {number}\n */\nvar repeatedStringMatch = function(a, b) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} a\n# @param {String} b\n# @return {Integer}\ndef repeated_string_match(a, b)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func repeatedStringMatch(_ a: String, _ b: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func repeatedStringMatch(a string, b string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def repeatedStringMatch(a: String, b: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun repeatedStringMatch(a: String, b: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn repeated_string_match(a: String, b: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $a\n * @param String $b\n * @return Integer\n */\n function repeatedStringMatch($a, $b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function repeatedStringMatch(a: string, b: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (repeated-string-match a b)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0686](https://leetcode-cn.com/problems/repeated-string-match)", "[\u91cd\u590d\u53e0\u52a0\u5b57\u7b26\u4e32\u5339\u914d](/solution/0600-0699/0686.Repeated%20String%20Match/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0686](https://leetcode.com/problems/repeated-string-match)", "[Repeated String Match](/solution/0600-0699/0686.Repeated%20String%20Match/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "0685", "frontend_question_id": "0685", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/redundant-connection-ii", "url_en": "https://leetcode.com/problems/redundant-connection-ii", "relative_path_cn": "/solution/0600-0699/0685.Redundant%20Connection%20II/README.md", "relative_path_en": "/solution/0600-0699/0685.Redundant%20Connection%20II/README_EN.md", "title_cn": "\u5197\u4f59\u8fde\u63a5 II", "title_en": "Redundant Connection II", "question_title_slug": "redundant-connection-ii", "content_en": "

    In this problem, a rooted tree is a directed graph such that, there is exactly one node (the root) for which all other nodes are descendants of this node, plus every node has exactly one parent, except for the root node which has no parents.

    \n\n

    The given input is a directed graph that started as a rooted tree with n nodes (with distinct values from 1 to n), with one additional directed edge added. The added edge has two different vertices chosen from 1 to n, and was not an edge that already existed.

    \n\n

    The resulting graph is given as a 2D-array of edges. Each element of edges is a pair [ui, vi] that represents a directed edge connecting nodes ui and vi, where ui is a parent of child vi.

    \n\n

    Return an edge that can be removed so that the resulting graph is a rooted tree of n nodes. If there are multiple answers, return the answer that occurs last in the given 2D-array.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: edges = [[1,2],[1,3],[2,3]]\nOutput: [2,3]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: edges = [[1,2],[2,3],[3,4],[4,1],[1,5]]\nOutput: [4,1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == edges.length
    • \n\t
    • 3 <= n <= 1000
    • \n\t
    • edges[i].length == 2
    • \n\t
    • 1 <= ui, vi <= n
    • \n\t
    • ui != vi
    • \n
    \n", "content_cn": "

    \u5728\u672c\u95ee\u9898\u4e2d\uff0c\u6709\u6839\u6811\u6307\u6ee1\u8db3\u4ee5\u4e0b\u6761\u4ef6\u7684 \u6709\u5411 \u56fe\u3002\u8be5\u6811\u53ea\u6709\u4e00\u4e2a\u6839\u8282\u70b9\uff0c\u6240\u6709\u5176\u4ed6\u8282\u70b9\u90fd\u662f\u8be5\u6839\u8282\u70b9\u7684\u540e\u7ee7\u3002\u8be5\u6811\u9664\u4e86\u6839\u8282\u70b9\u4e4b\u5916\u7684\u6bcf\u4e00\u4e2a\u8282\u70b9\u90fd\u6709\u4e14\u53ea\u6709\u4e00\u4e2a\u7236\u8282\u70b9\uff0c\u800c\u6839\u8282\u70b9\u6ca1\u6709\u7236\u8282\u70b9\u3002

    \n\n

    \u8f93\u5165\u4e00\u4e2a\u6709\u5411\u56fe\uff0c\u8be5\u56fe\u7531\u4e00\u4e2a\u6709\u7740 n \u4e2a\u8282\u70b9\uff08\u8282\u70b9\u503c\u4e0d\u91cd\u590d\uff0c\u4ece 1 \u5230 n\uff09\u7684\u6811\u53ca\u4e00\u6761\u9644\u52a0\u7684\u6709\u5411\u8fb9\u6784\u6210\u3002\u9644\u52a0\u7684\u8fb9\u5305\u542b\u5728 1 \u5230 n \u4e2d\u7684\u4e24\u4e2a\u4e0d\u540c\u9876\u70b9\u95f4\uff0c\u8fd9\u6761\u9644\u52a0\u7684\u8fb9\u4e0d\u5c5e\u4e8e\u6811\u4e2d\u5df2\u5b58\u5728\u7684\u8fb9\u3002

    \n\n

    \u7ed3\u679c\u56fe\u662f\u4e00\u4e2a\u4ee5\u8fb9\u7ec4\u6210\u7684\u4e8c\u7ef4\u6570\u7ec4\u00a0edges \u3002 \u6bcf\u4e2a\u5143\u7d20\u662f\u4e00\u5bf9 [ui, vi]\uff0c\u7528\u4ee5\u8868\u793a \u6709\u5411 \u56fe\u4e2d\u8fde\u63a5\u9876\u70b9 ui \u548c\u9876\u70b9 vi \u7684\u8fb9\uff0c\u5176\u4e2d ui \u662f vi \u7684\u4e00\u4e2a\u7236\u8282\u70b9\u3002

    \n\n

    \u8fd4\u56de\u4e00\u6761\u80fd\u5220\u9664\u7684\u8fb9\uff0c\u4f7f\u5f97\u5269\u4e0b\u7684\u56fe\u662f\u6709 n \u4e2a\u8282\u70b9\u7684\u6709\u6839\u6811\u3002\u82e5\u6709\u591a\u4e2a\u7b54\u6848\uff0c\u8fd4\u56de\u6700\u540e\u51fa\u73b0\u5728\u7ed9\u5b9a\u4e8c\u7ef4\u6570\u7ec4\u7684\u7b54\u6848\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aedges = [[1,2],[1,3],[2,3]]\n\u8f93\u51fa\uff1a[2,3]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aedges = [[1,2],[2,3],[3,4],[4,1],[1,5]]\n\u8f93\u51fa\uff1a[4,1]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == edges.length
    • \n\t
    • 3 <= n <= 1000
    • \n\t
    • edges[i].length == 2
    • \n\t
    • 1 <= ui, vi <= n
    • \n
    \n", "tags_en": ["Tree", "Depth-first Search", "Union Find", "Graph"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e76\u67e5\u96c6", "\u56fe"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findRedundantDirectedConnection(vector>& edges) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] findRedundantDirectedConnection(int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findRedundantDirectedConnection(self, edges):\n \"\"\"\n :type edges: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findRedundantDirectedConnection(self, edges: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* findRedundantDirectedConnection(int** edges, int edgesSize, int* edgesColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] FindRedundantDirectedConnection(int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} edges\n * @return {number[]}\n */\nvar findRedundantDirectedConnection = function(edges) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} edges\n# @return {Integer[]}\ndef find_redundant_directed_connection(edges)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findRedundantDirectedConnection(_ edges: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findRedundantDirectedConnection(edges [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findRedundantDirectedConnection(edges: Array[Array[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findRedundantDirectedConnection(edges: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_redundant_directed_connection(edges: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $edges\n * @return Integer[]\n */\n function findRedundantDirectedConnection($edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findRedundantDirectedConnection(edges: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-redundant-directed-connection edges)\n (-> (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0685](https://leetcode-cn.com/problems/redundant-connection-ii)", "[\u5197\u4f59\u8fde\u63a5 II](/solution/0600-0699/0685.Redundant%20Connection%20II/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e76\u67e5\u96c6`,`\u56fe`", "\u56f0\u96be", ""], "md_table_row_en": ["[0685](https://leetcode.com/problems/redundant-connection-ii)", "[Redundant Connection II](/solution/0600-0699/0685.Redundant%20Connection%20II/README_EN.md)", "`Tree`,`Depth-first Search`,`Union Find`,`Graph`", "Hard", ""]}, {"question_id": "0684", "frontend_question_id": "0684", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/redundant-connection", "url_en": "https://leetcode.com/problems/redundant-connection", "relative_path_cn": "/solution/0600-0699/0684.Redundant%20Connection/README.md", "relative_path_en": "/solution/0600-0699/0684.Redundant%20Connection/README_EN.md", "title_cn": "\u5197\u4f59\u8fde\u63a5", "title_en": "Redundant Connection", "question_title_slug": "redundant-connection", "content_en": "

    In this problem, a tree is an undirected graph that is connected and has no cycles.

    \n\n

    You are given a graph that started as a tree with n nodes labeled from 1 to n, with one additional edge added. The added edge has two different vertices chosen from 1 to n, and was not an edge that already existed. The graph is represented as an array edges of length n where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the graph.

    \n\n

    Return an edge that can be removed so that the resulting graph is a tree of n nodes. If there are multiple answers, return the answer that occurs last in the input.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: edges = [[1,2],[1,3],[2,3]]\nOutput: [2,3]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: edges = [[1,2],[2,3],[3,4],[1,4],[1,5]]\nOutput: [1,4]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == edges.length
    • \n\t
    • 3 <= n <= 1000
    • \n\t
    • edges[i].length == 2
    • \n\t
    • 1 <= ai < bi <= edges.length
    • \n\t
    • ai != bi
    • \n\t
    • There are no repeated edges.
    • \n\t
    • The given graph is connected.
    • \n
    \n", "content_cn": "

    \u5728\u672c\u95ee\u9898\u4e2d, \u6811\u6307\u7684\u662f\u4e00\u4e2a\u8fde\u901a\u4e14\u65e0\u73af\u7684\u65e0\u5411\u56fe\u3002

    \n\n

    \u8f93\u5165\u4e00\u4e2a\u56fe\uff0c\u8be5\u56fe\u7531\u4e00\u4e2a\u6709\u7740N\u4e2a\u8282\u70b9 (\u8282\u70b9\u503c\u4e0d\u91cd\u590d1, 2, ..., N) \u7684\u6811\u53ca\u4e00\u6761\u9644\u52a0\u7684\u8fb9\u6784\u6210\u3002\u9644\u52a0\u7684\u8fb9\u7684\u4e24\u4e2a\u9876\u70b9\u5305\u542b\u57281\u5230N\u4e2d\u95f4\uff0c\u8fd9\u6761\u9644\u52a0\u7684\u8fb9\u4e0d\u5c5e\u4e8e\u6811\u4e2d\u5df2\u5b58\u5728\u7684\u8fb9\u3002

    \n\n

    \u7ed3\u679c\u56fe\u662f\u4e00\u4e2a\u4ee5\u8fb9\u7ec4\u6210\u7684\u4e8c\u7ef4\u6570\u7ec4\u3002\u6bcf\u4e00\u4e2a\u8fb9\u7684\u5143\u7d20\u662f\u4e00\u5bf9[u, v] \uff0c\u6ee1\u8db3 u < v\uff0c\u8868\u793a\u8fde\u63a5\u9876\u70b9u \u548cv\u7684\u65e0\u5411\u56fe\u7684\u8fb9\u3002

    \n\n

    \u8fd4\u56de\u4e00\u6761\u53ef\u4ee5\u5220\u53bb\u7684\u8fb9\uff0c\u4f7f\u5f97\u7ed3\u679c\u56fe\u662f\u4e00\u4e2a\u6709\u7740N\u4e2a\u8282\u70b9\u7684\u6811\u3002\u5982\u679c\u6709\u591a\u4e2a\u7b54\u6848\uff0c\u5219\u8fd4\u56de\u4e8c\u7ef4\u6570\u7ec4\u4e2d\u6700\u540e\u51fa\u73b0\u7684\u8fb9\u3002\u7b54\u6848\u8fb9 [u, v] \u5e94\u6ee1\u8db3\u76f8\u540c\u7684\u683c\u5f0f u < v\u3002

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165: [[1,2], [1,3], [2,3]]\n\u8f93\u51fa: [2,3]\n\u89e3\u91ca: \u7ed9\u5b9a\u7684\u65e0\u5411\u56fe\u4e3a:\n  1\n / \\\n2 - 3\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165: [[1,2], [2,3], [3,4], [1,4], [1,5]]\n\u8f93\u51fa: [1,4]\n\u89e3\u91ca: \u7ed9\u5b9a\u7684\u65e0\u5411\u56fe\u4e3a:\n5 - 1 - 2\n    |   |\n    4 - 3\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    • \u8f93\u5165\u7684\u4e8c\u7ef4\u6570\u7ec4\u5927\u5c0f\u5728 3 \u5230 1000\u3002
    • \n\t
    • \u4e8c\u7ef4\u6570\u7ec4\u4e2d\u7684\u6574\u6570\u57281\u5230N\u4e4b\u95f4\uff0c\u5176\u4e2dN\u662f\u8f93\u5165\u6570\u7ec4\u7684\u5927\u5c0f\u3002
    • \n
    \n\n

    \u66f4\u65b0(2017-09-26):
    \n\u6211\u4eec\u5df2\u7ecf\u91cd\u65b0\u68c0\u67e5\u4e86\u95ee\u9898\u63cf\u8ff0\u53ca\u6d4b\u8bd5\u7528\u4f8b\uff0c\u660e\u786e\u56fe\u662f\u65e0\u5411 \u56fe\u3002\u5bf9\u4e8e\u6709\u5411\u56fe\u8be6\u89c1\u5197\u4f59\u8fde\u63a5II\u3002\u5bf9\u4e8e\u9020\u6210\u4efb\u4f55\u4e0d\u4fbf\uff0c\u6211\u4eec\u6df1\u611f\u6b49\u610f\u3002

    \n", "tags_en": ["Tree", "Union Find", "Graph"], "tags_cn": ["\u6811", "\u5e76\u67e5\u96c6", "\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findRedundantConnection(vector>& edges) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] findRedundantConnection(int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findRedundantConnection(self, edges):\n \"\"\"\n :type edges: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findRedundantConnection(self, edges: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* findRedundantConnection(int** edges, int edgesSize, int* edgesColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] FindRedundantConnection(int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} edges\n * @return {number[]}\n */\nvar findRedundantConnection = function(edges) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} edges\n# @return {Integer[]}\ndef find_redundant_connection(edges)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findRedundantConnection(_ edges: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findRedundantConnection(edges [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findRedundantConnection(edges: Array[Array[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findRedundantConnection(edges: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_redundant_connection(edges: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $edges\n * @return Integer[]\n */\n function findRedundantConnection($edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findRedundantConnection(edges: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-redundant-connection edges)\n (-> (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0684](https://leetcode-cn.com/problems/redundant-connection)", "[\u5197\u4f59\u8fde\u63a5](/solution/0600-0699/0684.Redundant%20Connection/README.md)", "`\u6811`,`\u5e76\u67e5\u96c6`,`\u56fe`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0684](https://leetcode.com/problems/redundant-connection)", "[Redundant Connection](/solution/0600-0699/0684.Redundant%20Connection/README_EN.md)", "`Tree`,`Union Find`,`Graph`", "Medium", ""]}, {"question_id": "0683", "frontend_question_id": "0683", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/k-empty-slots", "url_en": "https://leetcode.com/problems/k-empty-slots", "relative_path_cn": "/solution/0600-0699/0683.K%20Empty%20Slots/README.md", "relative_path_en": "/solution/0600-0699/0683.K%20Empty%20Slots/README_EN.md", "title_cn": "K \u4e2a\u5173\u95ed\u7684\u706f\u6ce1", "title_en": "K Empty Slots", "question_title_slug": "k-empty-slots", "content_en": "

    You have n bulbs in a row numbered from 1 to n. Initially, all the bulbs are turned off. We turn on exactly one bulb every day until all bulbs are on after n days.

    \n\n

    You are given an array bulbs of length n where bulbs[i] = x means that on the (i+1)th day, we will turn on the bulb at position x where i is 0-indexed and x is 1-indexed.

    \n\n

    Given an integer k, return the minimum day number such that there exists two turned on bulbs that have exactly k bulbs between them that are all turned off. If there isn't such day, return -1.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: bulbs = [1,3,2], k = 1\nOutput: 2\nExplanation:\nOn the first day: bulbs[0] = 1, first bulb is turned on: [1,0,0]\nOn the second day: bulbs[1] = 3, third bulb is turned on: [1,0,1]\nOn the third day: bulbs[2] = 2, second bulb is turned on: [1,1,1]\nWe return 2 because on the second day, there were two on bulbs with one off bulb between them.
    \n\n

    Example 2:

    \n\n
    \nInput: bulbs = [1,2,3], k = 1\nOutput: -1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == bulbs.length
    • \n\t
    • 1 <= n <= 2 * 104
    • \n\t
    • 1 <= bulbs[i] <= n
    • \n\t
    • bulbs is a permutation of numbers from 1 to n.
    • \n\t
    • 0 <= k <= 2 * 104
    • \n
    \n", "content_cn": "

    N \u4e2a\u706f\u6ce1\u6392\u6210\u4e00\u884c\uff0c\u7f16\u53f7\u4ece 1 \u5230 N \u3002\u6700\u521d\uff0c\u6240\u6709\u706f\u6ce1\u90fd\u5173\u95ed\u3002\u6bcf\u5929\u53ea\u6253\u5f00\u4e00\u4e2a\u706f\u6ce1\uff0c\u76f4\u5230 N \u5929\u540e\u6240\u6709\u706f\u6ce1\u90fd\u6253\u5f00\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u4e3a N \u7684\u706f\u6ce1\u6570\u7ec4 blubs \uff0c\u5176\u4e2d bulls[i] = x \u610f\u5473\u7740\u5728\u7b2c (i+1) \u5929\uff0c\u6211\u4eec\u4f1a\u628a\u5728\u4f4d\u7f6e x \u7684\u706f\u6ce1\u6253\u5f00\uff0c\u5176\u4e2d i \u4ece 0 \u5f00\u59cb\uff0cx \u4ece 1 \u5f00\u59cb\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 K \uff0c\u8bf7\u4f60\u8f93\u51fa\u5728\u7b2c\u51e0\u5929\u6070\u597d\u6709\u4e24\u4e2a\u6253\u5f00\u7684\u706f\u6ce1\uff0c\u4f7f\u5f97\u5b83\u4eec\u4e2d\u95f4 \u6b63\u597d \u6709 K \u4e2a\u706f\u6ce1\u4e14\u8fd9\u4e9b\u706f\u6ce1 \u5168\u90e8\u662f\u5173\u95ed\u7684 \u3002

    \n\n

    \u5982\u679c\u4e0d\u5b58\u5728\u8fd9\u79cd\u60c5\u51b5\uff0c\u8fd4\u56de -1 \u3002\u5982\u679c\u6709\u591a\u5929\u90fd\u51fa\u73b0\u8fd9\u79cd\u60c5\u51b5\uff0c\u8bf7\u8fd4\u56de \u6700\u5c0f\u7684\u5929\u6570 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\nbulbs: [1,3,2]\nK: 1\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n\u7b2c\u4e00\u5929 bulbs[0] = 1\uff0c\u6253\u5f00\u7b2c\u4e00\u4e2a\u706f\u6ce1 [1,0,0]\n\u7b2c\u4e8c\u5929 bulbs[1] = 3\uff0c\u6253\u5f00\u7b2c\u4e09\u4e2a\u706f\u6ce1 [1,0,1]\n\u7b2c\u4e09\u5929 bulbs[2] = 2\uff0c\u6253\u5f00\u7b2c\u4e8c\u4e2a\u706f\u6ce1 [1,1,1]\n\u8fd4\u56de2\uff0c\u56e0\u4e3a\u5728\u7b2c\u4e8c\u5929\uff0c\u4e24\u4e2a\u6253\u5f00\u7684\u706f\u6ce1\u4e4b\u95f4\u6070\u597d\u6709\u4e00\u4e2a\u5173\u95ed\u7684\u706f\u6ce1\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\nbulbs: [1,2,3]\nk: 1\n\u8f93\u51fa\uff1a-1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= N <= 20000
    • \n\t
    • 1 <= bulbs[i] <= N
    • \n\t
    • bulbs \u662f\u4e00\u4e2a\u7531\u4ece 1 \u5230 N \u7684\u6570\u5b57\u6784\u6210\u7684\u6392\u5217
    • \n\t
    • 0 <= K <= 20000
    • \n
    \n", "tags_en": ["Ordered Map"], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int kEmptySlots(vector& bulbs, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int kEmptySlots(int[] bulbs, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def kEmptySlots(self, bulbs, k):\n \"\"\"\n :type bulbs: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def kEmptySlots(self, bulbs: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint kEmptySlots(int* bulbs, int bulbsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int KEmptySlots(int[] bulbs, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} bulbs\n * @param {number} k\n * @return {number}\n */\nvar kEmptySlots = function(bulbs, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} bulbs\n# @param {Integer} k\n# @return {Integer}\ndef k_empty_slots(bulbs, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func kEmptySlots(_ bulbs: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func kEmptySlots(bulbs []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def kEmptySlots(bulbs: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun kEmptySlots(bulbs: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn k_empty_slots(bulbs: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $bulbs\n * @param Integer $k\n * @return Integer\n */\n function kEmptySlots($bulbs, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function kEmptySlots(bulbs: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (k-empty-slots bulbs k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0683](https://leetcode-cn.com/problems/k-empty-slots)", "[K \u4e2a\u5173\u95ed\u7684\u706f\u6ce1](/solution/0600-0699/0683.K%20Empty%20Slots/README.md)", "", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0683](https://leetcode.com/problems/k-empty-slots)", "[K Empty Slots](/solution/0600-0699/0683.K%20Empty%20Slots/README_EN.md)", "`Ordered Map`", "Hard", "\ud83d\udd12"]}, {"question_id": "0682", "frontend_question_id": "0682", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/baseball-game", "url_en": "https://leetcode.com/problems/baseball-game", "relative_path_cn": "/solution/0600-0699/0682.Baseball%20Game/README.md", "relative_path_en": "/solution/0600-0699/0682.Baseball%20Game/README_EN.md", "title_cn": "\u68d2\u7403\u6bd4\u8d5b", "title_en": "Baseball Game", "question_title_slug": "baseball-game", "content_en": "

    You are keeping score for a baseball game with strange rules. The game consists of several rounds, where the scores of past rounds may affect future rounds' scores.

    \n\n

    At the beginning of the game, you start with an empty record. You are given a list of strings ops, where ops[i] is the ith operation you must apply to the record and is one of the following:

    \n\n
      \n\t
    1. An integer x - Record a new score of x.
    2. \n\t
    3. "+" - Record a new score that is the sum of the previous two scores. It is guaranteed there will always be two previous scores.
    4. \n\t
    5. "D" - Record a new score that is double the previous score. It is guaranteed there will always be a previous score.
    6. \n\t
    7. "C" - Invalidate the previous score, removing it from the record. It is guaranteed there will always be a previous score.
    8. \n
    \n\n

    Return the sum of all the scores on the record.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: ops = ["5","2","C","D","+"]\nOutput: 30\nExplanation:\n"5" - Add 5 to the record, record is now [5].\n"2" - Add 2 to the record, record is now [5, 2].\n"C" - Invalidate and remove the previous score, record is now [5].\n"D" - Add 2 * 5 = 10 to the record, record is now [5, 10].\n"+" - Add 5 + 10 = 15 to the record, record is now [5, 10, 15].\nThe total sum is 5 + 10 + 15 = 30.\n
    \n\n

    Example 2:

    \n\n
    \nInput: ops = ["5","-2","4","C","D","9","+","+"]\nOutput: 27\nExplanation:\n"5" - Add 5 to the record, record is now [5].\n"-2" - Add -2 to the record, record is now [5, -2].\n"4" - Add 4 to the record, record is now [5, -2, 4].\n"C" - Invalidate and remove the previous score, record is now [5, -2].\n"D" - Add 2 * -2 = -4 to the record, record is now [5, -2, -4].\n"9" - Add 9 to the record, record is now [5, -2, -4, 9].\n"+" - Add -4 + 9 = 5 to the record, record is now [5, -2, -4, 9, 5].\n"+" - Add 9 + 5 = 14 to the record, record is now [5, -2, -4, 9, 5, 14].\nThe total sum is 5 + -2 + -4 + 9 + 5 + 14 = 27.\n
    \n\n

    Example 3:

    \n\n
    \nInput: ops = ["1"]\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= ops.length <= 1000
    • \n\t
    • ops[i] is "C", "D", "+", or a string representing an integer in the range [-3 * 104, 3 * 104].
    • \n\t
    • For operation "+", there will always be at least two previous scores on the record.
    • \n\t
    • For operations "C" and "D", there will always be at least one previous score on the record.
    • \n
    \n", "content_cn": "

    \u4f60\u73b0\u5728\u662f\u4e00\u573a\u91c7\u7528\u7279\u6b8a\u8d5b\u5236\u68d2\u7403\u6bd4\u8d5b\u7684\u8bb0\u5f55\u5458\u3002\u8fd9\u573a\u6bd4\u8d5b\u7531\u82e5\u5e72\u56de\u5408\u7ec4\u6210\uff0c\u8fc7\u53bb\u51e0\u56de\u5408\u7684\u5f97\u5206\u53ef\u80fd\u4f1a\u5f71\u54cd\u4ee5\u540e\u51e0\u56de\u5408\u7684\u5f97\u5206\u3002

    \n\n

    \u6bd4\u8d5b\u5f00\u59cb\u65f6\uff0c\u8bb0\u5f55\u662f\u7a7a\u767d\u7684\u3002\u4f60\u4f1a\u5f97\u5230\u4e00\u4e2a\u8bb0\u5f55\u64cd\u4f5c\u7684\u5b57\u7b26\u4e32\u5217\u8868 ops\uff0c\u5176\u4e2d ops[i] \u662f\u4f60\u9700\u8981\u8bb0\u5f55\u7684\u7b2c i \u9879\u64cd\u4f5c\uff0cops \u9075\u5faa\u4e0b\u8ff0\u89c4\u5219\uff1a

    \n\n
      \n\t
    1. \u6574\u6570 x - \u8868\u793a\u672c\u56de\u5408\u65b0\u83b7\u5f97\u5206\u6570 x
    2. \n\t
    3. \"+\" - \u8868\u793a\u672c\u56de\u5408\u65b0\u83b7\u5f97\u7684\u5f97\u5206\u662f\u524d\u4e24\u6b21\u5f97\u5206\u7684\u603b\u548c\u3002\u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u8bb0\u5f55\u6b64\u64cd\u4f5c\u65f6\u524d\u9762\u603b\u662f\u5b58\u5728\u4e24\u4e2a\u6709\u6548\u7684\u5206\u6570\u3002
    4. \n\t
    5. \"D\" - \u8868\u793a\u672c\u56de\u5408\u65b0\u83b7\u5f97\u7684\u5f97\u5206\u662f\u524d\u4e00\u6b21\u5f97\u5206\u7684\u4e24\u500d\u3002\u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u8bb0\u5f55\u6b64\u64cd\u4f5c\u65f6\u524d\u9762\u603b\u662f\u5b58\u5728\u4e00\u4e2a\u6709\u6548\u7684\u5206\u6570\u3002
    6. \n\t
    7. \"C\" - \u8868\u793a\u524d\u4e00\u6b21\u5f97\u5206\u65e0\u6548\uff0c\u5c06\u5176\u4ece\u8bb0\u5f55\u4e2d\u79fb\u9664\u3002\u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u8bb0\u5f55\u6b64\u64cd\u4f5c\u65f6\u524d\u9762\u603b\u662f\u5b58\u5728\u4e00\u4e2a\u6709\u6548\u7684\u5206\u6570\u3002
    8. \n
    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u8bb0\u5f55\u4e2d\u6240\u6709\u5f97\u5206\u7684\u603b\u548c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aops = [\"5\",\"2\",\"C\",\"D\",\"+\"]\n\u8f93\u51fa\uff1a30\n\u89e3\u91ca\uff1a\n\"5\" - \u8bb0\u5f55\u52a0 5 \uff0c\u8bb0\u5f55\u73b0\u5728\u662f [5]\n\"2\" - \u8bb0\u5f55\u52a0 2 \uff0c\u8bb0\u5f55\u73b0\u5728\u662f [5, 2]\n\"C\" - \u4f7f\u524d\u4e00\u6b21\u5f97\u5206\u7684\u8bb0\u5f55\u65e0\u6548\u5e76\u5c06\u5176\u79fb\u9664\uff0c\u8bb0\u5f55\u73b0\u5728\u662f [5].\n\"D\" - \u8bb0\u5f55\u52a0 2 * 5 = 10 \uff0c\u8bb0\u5f55\u73b0\u5728\u662f [5, 10].\n\"+\" - \u8bb0\u5f55\u52a0 5 + 10 = 15 \uff0c\u8bb0\u5f55\u73b0\u5728\u662f [5, 10, 15].\n\u6240\u6709\u5f97\u5206\u7684\u603b\u548c 5 + 10 + 15 = 30\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aops = [\"5\",\"-2\",\"4\",\"C\",\"D\",\"9\",\"+\",\"+\"]\n\u8f93\u51fa\uff1a27\n\u89e3\u91ca\uff1a\n\"5\" - \u8bb0\u5f55\u52a0 5 \uff0c\u8bb0\u5f55\u73b0\u5728\u662f [5]\n\"-2\" - \u8bb0\u5f55\u52a0 -2 \uff0c\u8bb0\u5f55\u73b0\u5728\u662f [5, -2]\n\"4\" - \u8bb0\u5f55\u52a0 4 \uff0c\u8bb0\u5f55\u73b0\u5728\u662f [5, -2, 4]\n\"C\" - \u4f7f\u524d\u4e00\u6b21\u5f97\u5206\u7684\u8bb0\u5f55\u65e0\u6548\u5e76\u5c06\u5176\u79fb\u9664\uff0c\u8bb0\u5f55\u73b0\u5728\u662f [5, -2]\n\"D\" - \u8bb0\u5f55\u52a0 2 * -2 = -4 \uff0c\u8bb0\u5f55\u73b0\u5728\u662f [5, -2, -4]\n\"9\" - \u8bb0\u5f55\u52a0 9 \uff0c\u8bb0\u5f55\u73b0\u5728\u662f [5, -2, -4, 9]\n\"+\" - \u8bb0\u5f55\u52a0 -4 + 9 = 5 \uff0c\u8bb0\u5f55\u73b0\u5728\u662f [5, -2, -4, 9, 5]\n\"+\" - \u8bb0\u5f55\u52a0 9 + 5 = 14 \uff0c\u8bb0\u5f55\u73b0\u5728\u662f [5, -2, -4, 9, 5, 14]\n\u6240\u6709\u5f97\u5206\u7684\u603b\u548c 5 + -2 + -4 + 9 + 5 + 14 = 27\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aops = [\"1\"]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= ops.length <= 1000
    • \n\t
    • ops[i] \u4e3a \"C\"\u3001\"D\"\u3001\"+\"\uff0c\u6216\u8005\u4e00\u4e2a\u8868\u793a\u6574\u6570\u7684\u5b57\u7b26\u4e32\u3002\u6574\u6570\u8303\u56f4\u662f [-3 * 104, 3 * 104]
    • \n\t
    • \u5bf9\u4e8e \"+\" \u64cd\u4f5c\uff0c\u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u8bb0\u5f55\u6b64\u64cd\u4f5c\u65f6\u524d\u9762\u603b\u662f\u5b58\u5728\u4e24\u4e2a\u6709\u6548\u7684\u5206\u6570
    • \n\t
    • \u5bf9\u4e8e \"C\" \u548c \"D\" \u64cd\u4f5c\uff0c\u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u8bb0\u5f55\u6b64\u64cd\u4f5c\u65f6\u524d\u9762\u603b\u662f\u5b58\u5728\u4e00\u4e2a\u6709\u6548\u7684\u5206\u6570
    • \n
    \n", "tags_en": ["Stack"], "tags_cn": ["\u6808"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int calPoints(vector& ops) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int calPoints(String[] ops) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def calPoints(self, ops):\n \"\"\"\n :type ops: List[str]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def calPoints(self, ops: List[str]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint calPoints(char ** ops, int opsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CalPoints(string[] ops) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} ops\n * @return {number}\n */\nvar calPoints = function(ops) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} ops\n# @return {Integer}\ndef cal_points(ops)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func calPoints(_ ops: [String]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func calPoints(ops []string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def calPoints(ops: Array[String]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun calPoints(ops: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn cal_points(ops: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $ops\n * @return Integer\n */\n function calPoints($ops) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function calPoints(ops: string[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (cal-points ops)\n (-> (listof string?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0682](https://leetcode-cn.com/problems/baseball-game)", "[\u68d2\u7403\u6bd4\u8d5b](/solution/0600-0699/0682.Baseball%20Game/README.md)", "`\u6808`", "\u7b80\u5355", ""], "md_table_row_en": ["[0682](https://leetcode.com/problems/baseball-game)", "[Baseball Game](/solution/0600-0699/0682.Baseball%20Game/README_EN.md)", "`Stack`", "Easy", ""]}, {"question_id": "0681", "frontend_question_id": "0681", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/next-closest-time", "url_en": "https://leetcode.com/problems/next-closest-time", "relative_path_cn": "/solution/0600-0699/0681.Next%20Closest%20Time/README.md", "relative_path_en": "/solution/0600-0699/0681.Next%20Closest%20Time/README_EN.md", "title_cn": "\u6700\u8fd1\u65f6\u523b", "title_en": "Next Closest Time", "question_title_slug": "next-closest-time", "content_en": "

    Given a time represented in the format "HH:MM", form the next closest time by reusing the current digits. There is no limit on how many times a digit can be reused.

    \n\n

    You may assume the given input string is always valid. For example, "01:34", "12:09" are all valid. "1:34", "12:9" are all invalid.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: time = "19:34"\nOutput: "19:39"\nExplanation: The next closest time choosing from digits 1, 9, 3, 4, is 19:39, which occurs 5 minutes later.\nIt is not 19:33, because this occurs 23 hours and 59 minutes later.\n
    \n\n

    Example 2:

    \n\n
    \nInput: time = "23:59"\nOutput: "22:22"\nExplanation: The next closest time choosing from digits 2, 3, 5, 9, is 22:22.\nIt may be assumed that the returned time is next day's time since it is smaller than the input time numerically.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • time.length == 5
    • \n\t
    • time is a valid time in the form "HH:MM".
    • \n\t
    • 0 <= HH < 24
    • \n\t
    • 0 <= MM < 60
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5f62\u5982 “HH:MM” \u8868\u793a\u7684\u65f6\u523b\uff0c\u5229\u7528\u5f53\u524d\u51fa\u73b0\u8fc7\u7684\u6570\u5b57\u6784\u9020\u4e0b\u4e00\u4e2a\u8ddd\u79bb\u5f53\u524d\u65f6\u95f4\u6700\u8fd1\u7684\u65f6\u523b\u3002\u6bcf\u4e2a\u51fa\u73b0\u6570\u5b57\u90fd\u53ef\u4ee5\u88ab\u65e0\u9650\u6b21\u4f7f\u7528\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u8ba4\u4e3a\u7ed9\u5b9a\u7684\u5b57\u7b26\u4e32\u4e00\u5b9a\u662f\u5408\u6cd5\u7684\u3002\u4f8b\u5982\uff0c“01:34” \u548c “12:09” \u662f\u5408\u6cd5\u7684\uff0c“1:34” \u548c “12:9” \u662f\u4e0d\u5408\u6cd5\u7684\u3002

    \n\n

     

    \n\n

    \u6837\u4f8b 1:

    \n\n
    \u8f93\u5165: "19:34"\n\u8f93\u51fa: "19:39"\n\u89e3\u91ca: \u5229\u7528\u6570\u5b57 1, 9, 3, 4 \u6784\u9020\u51fa\u6765\u7684\u6700\u8fd1\u65f6\u523b\u662f 19:39\uff0c\u662f 5 \u5206\u949f\u4e4b\u540e\u3002\u7ed3\u679c\u4e0d\u662f 19:33 \u56e0\u4e3a\u8fd9\u4e2a\u65f6\u523b\u662f 23 \u5c0f\u65f6 59 \u5206\u949f\u4e4b\u540e\u3002\n
    \n\n

     

    \n\n

    \u6837\u4f8b 2:

    \n\n
    \u8f93\u5165: "23:59"\n\u8f93\u51fa: "22:22"\n\u89e3\u91ca: \u5229\u7528\u6570\u5b57 2, 3, 5, 9 \u6784\u9020\u51fa\u6765\u7684\u6700\u8fd1\u65f6\u523b\u662f 22:22\u3002 \u7b54\u6848\u4e00\u5b9a\u662f\u7b2c\u4e8c\u5929\u7684\u67d0\u4e00\u65f6\u523b\uff0c\u6240\u4ee5\u9009\u62e9\u53ef\u6784\u9020\u7684\u6700\u5c0f\u65f6\u523b\u3002\n
    \n\n

     

    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string nextClosestTime(string time) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String nextClosestTime(String time) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def nextClosestTime(self, time):\n \"\"\"\n :type time: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def nextClosestTime(self, time: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * nextClosestTime(char * time){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string NextClosestTime(string time) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} time\n * @return {string}\n */\nvar nextClosestTime = function(time) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} time\n# @return {String}\ndef next_closest_time(time)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func nextClosestTime(_ time: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func nextClosestTime(time string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def nextClosestTime(time: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun nextClosestTime(time: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn next_closest_time(time: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $time\n * @return String\n */\n function nextClosestTime($time) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function nextClosestTime(time: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (next-closest-time time)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0681](https://leetcode-cn.com/problems/next-closest-time)", "[\u6700\u8fd1\u65f6\u523b](/solution/0600-0699/0681.Next%20Closest%20Time/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0681](https://leetcode.com/problems/next-closest-time)", "[Next Closest Time](/solution/0600-0699/0681.Next%20Closest%20Time/README_EN.md)", "`String`", "Medium", "\ud83d\udd12"]}, {"question_id": "0680", "frontend_question_id": "0680", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/valid-palindrome-ii", "url_en": "https://leetcode.com/problems/valid-palindrome-ii", "relative_path_cn": "/solution/0600-0699/0680.Valid%20Palindrome%20II/README.md", "relative_path_en": "/solution/0600-0699/0680.Valid%20Palindrome%20II/README_EN.md", "title_cn": "\u9a8c\u8bc1\u56de\u6587\u5b57\u7b26\u4e32 \u2161", "title_en": "Valid Palindrome II", "question_title_slug": "valid-palindrome-ii", "content_en": "

    Given a string s, return true if the s can be palindrome after deleting at most one character from it.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "aba"\nOutput: true\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "abca"\nOutput: true\nExplanation: You could delete the character 'c'.\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "abc"\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 105
    • \n\t
    • s consists of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u7a7a\u5b57\u7b26\u4e32 s\uff0c\u6700\u591a\u5220\u9664\u4e00\u4e2a\u5b57\u7b26\u3002\u5224\u65ad\u662f\u5426\u80fd\u6210\u4e3a\u56de\u6587\u5b57\u7b26\u4e32\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: "aba"\n\u8f93\u51fa: True\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: "abca"\n\u8f93\u51fa: True\n\u89e3\u91ca: \u4f60\u53ef\u4ee5\u5220\u9664c\u5b57\u7b26\u3002\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u5b57\u7b26\u4e32\u53ea\u5305\u542b\u4ece a-z \u7684\u5c0f\u5199\u5b57\u6bcd\u3002\u5b57\u7b26\u4e32\u7684\u6700\u5927\u957f\u5ea6\u662f50000\u3002
    2. \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool validPalindrome(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean validPalindrome(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def validPalindrome(self, s):\n \"\"\"\n :type s: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def validPalindrome(self, s: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool validPalindrome(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool ValidPalindrome(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {boolean}\n */\nvar validPalindrome = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Boolean}\ndef valid_palindrome(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func validPalindrome(_ s: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func validPalindrome(s string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def validPalindrome(s: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun validPalindrome(s: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn valid_palindrome(s: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Boolean\n */\n function validPalindrome($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function validPalindrome(s: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (valid-palindrome s)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0680](https://leetcode-cn.com/problems/valid-palindrome-ii)", "[\u9a8c\u8bc1\u56de\u6587\u5b57\u7b26\u4e32 \u2161](/solution/0600-0699/0680.Valid%20Palindrome%20II/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0680](https://leetcode.com/problems/valid-palindrome-ii)", "[Valid Palindrome II](/solution/0600-0699/0680.Valid%20Palindrome%20II/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "0679", "frontend_question_id": "0679", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/24-game", "url_en": "https://leetcode.com/problems/24-game", "relative_path_cn": "/solution/0600-0699/0679.24%20Game/README.md", "relative_path_en": "/solution/0600-0699/0679.24%20Game/README_EN.md", "title_cn": "24 \u70b9\u6e38\u620f", "title_en": "24 Game", "question_title_slug": "24-game", "content_en": "

    You are given an integer array cards of length 4. You have four cards, each containing a number in the range [1, 9]. You should arrange the numbers on these cards in a mathematical expression using the operators ['+', '-', '*', '/'] and the parentheses '(' and ')' to get the value 24.

    \n\n

    You are restricted with the following rules:

    \n\n
      \n\t
    • The division operator '/' represents real division, not integer division.\n\n\t
        \n\t\t
      • For example, 4 / (1 - 2 / 3) = 4 / (1 / 3) = 12.
      • \n\t
      \n\t
    • \n\t
    • Every operation done is between two numbers. In particular, we cannot use '-' as a unary operator.\n\t
        \n\t\t
      • For example, if cards = [1, 1, 1, 1], the expression "-1 - 1 - 1 - 1" is not allowed.
      • \n\t
      \n\t
    • \n\t
    • You cannot concatenate numbers together\n\t
        \n\t\t
      • For example, if cards = [1, 2, 1, 2], the expression "12 + 12" is not valid.
      • \n\t
      \n\t
    • \n
    \n\n

    Return true if you can get such expression that evaluates to 24, and false otherwise.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: cards = [4,1,8,7]\nOutput: true\nExplanation: (8-4) * (7-1) = 24\n
    \n\n

    Example 2:

    \n\n
    \nInput: cards = [1,2,1,2]\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • cards.length == 4
    • \n\t
    • 1 <= cards[i] <= 9
    • \n
    \n", "content_cn": "

    \u4f60\u6709 4 \u5f20\u5199\u6709 1 \u5230 9 \u6570\u5b57\u7684\u724c\u3002\u4f60\u9700\u8981\u5224\u65ad\u662f\u5426\u80fd\u901a\u8fc7 *\uff0c/\uff0c+\uff0c-\uff0c(\uff0c) \u7684\u8fd0\u7b97\u5f97\u5230 24\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: [4, 1, 8, 7]\n\u8f93\u51fa: True\n\u89e3\u91ca: (8-4) * (7-1) = 24\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: [1, 2, 1, 2]\n\u8f93\u51fa: False\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u9664\u6cd5\u8fd0\u7b97\u7b26 / \u8868\u793a\u5b9e\u6570\u9664\u6cd5\uff0c\u800c\u4e0d\u662f\u6574\u6570\u9664\u6cd5\u3002\u4f8b\u5982 4 / (1 - 2/3) = 12 \u3002
    2. \n\t
    3. \u6bcf\u4e2a\u8fd0\u7b97\u7b26\u5bf9\u4e24\u4e2a\u6570\u8fdb\u884c\u8fd0\u7b97\u3002\u7279\u522b\u662f\u6211\u4eec\u4e0d\u80fd\u7528 - \u4f5c\u4e3a\u4e00\u5143\u8fd0\u7b97\u7b26\u3002\u4f8b\u5982\uff0c[1, 1, 1, 1] \u4f5c\u4e3a\u8f93\u5165\u65f6\uff0c\u8868\u8fbe\u5f0f -1 - 1 - 1 - 1 \u662f\u4e0d\u5141\u8bb8\u7684\u3002
    4. \n\t
    5. \u4f60\u4e0d\u80fd\u5c06\u6570\u5b57\u8fde\u63a5\u5728\u4e00\u8d77\u3002\u4f8b\u5982\uff0c\u8f93\u5165\u4e3a [1, 2, 1, 2] \u65f6\uff0c\u4e0d\u80fd\u5199\u6210 12 + 12 \u3002
    6. \n
    \n", "tags_en": ["Depth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool judgePoint24(vector& cards) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean judgePoint24(int[] cards) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def judgePoint24(self, cards):\n \"\"\"\n :type cards: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def judgePoint24(self, cards: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool judgePoint24(int* cards, int cardsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool JudgePoint24(int[] cards) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} cards\n * @return {boolean}\n */\nvar judgePoint24 = function(cards) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} cards\n# @return {Boolean}\ndef judge_point24(cards)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func judgePoint24(_ cards: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func judgePoint24(cards []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def judgePoint24(cards: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun judgePoint24(cards: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn judge_point24(cards: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $cards\n * @return Boolean\n */\n function judgePoint24($cards) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function judgePoint24(cards: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (judge-point24 cards)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0679](https://leetcode-cn.com/problems/24-game)", "[24 \u70b9\u6e38\u620f](/solution/0600-0699/0679.24%20Game/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[0679](https://leetcode.com/problems/24-game)", "[24 Game](/solution/0600-0699/0679.24%20Game/README_EN.md)", "`Depth-first Search`", "Hard", ""]}, {"question_id": "0678", "frontend_question_id": "0678", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/valid-parenthesis-string", "url_en": "https://leetcode.com/problems/valid-parenthesis-string", "relative_path_cn": "/solution/0600-0699/0678.Valid%20Parenthesis%20String/README.md", "relative_path_en": "/solution/0600-0699/0678.Valid%20Parenthesis%20String/README_EN.md", "title_cn": "\u6709\u6548\u7684\u62ec\u53f7\u5b57\u7b26\u4e32", "title_en": "Valid Parenthesis String", "question_title_slug": "valid-parenthesis-string", "content_en": "

    Given a string s containing only three types of characters: '(', ')' and '*', return true if s is valid.

    \n\n

    The following rules define a valid string:

    \n\n
      \n\t
    • Any left parenthesis '(' must have a corresponding right parenthesis ')'.
    • \n\t
    • Any right parenthesis ')' must have a corresponding left parenthesis '('.
    • \n\t
    • Left parenthesis '(' must go before the corresponding right parenthesis ')'.
    • \n\t
    • '*' could be treated as a single right parenthesis ')' or a single left parenthesis '(' or an empty string "".
    • \n
    \n\n

     

    \n

    Example 1:

    \n
    Input: s = \"()\"\nOutput: true\n

    Example 2:

    \n
    Input: s = \"(*)\"\nOutput: true\n

    Example 3:

    \n
    Input: s = \"(*))\"\nOutput: true\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 100
    • \n\t
    • s[i] is '(', ')' or '*'.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u53ea\u5305\u542b\u4e09\u79cd\u5b57\u7b26\u7684\u5b57\u7b26\u4e32\uff1a\uff08 \uff0c\uff09 \u548c *\uff0c\u5199\u4e00\u4e2a\u51fd\u6570\u6765\u68c0\u9a8c\u8fd9\u4e2a\u5b57\u7b26\u4e32\u662f\u5426\u4e3a\u6709\u6548\u5b57\u7b26\u4e32\u3002\u6709\u6548\u5b57\u7b26\u4e32\u5177\u6709\u5982\u4e0b\u89c4\u5219\uff1a

    \n\n
      \n\t
    1. \u4efb\u4f55\u5de6\u62ec\u53f7 ( \u5fc5\u987b\u6709\u76f8\u5e94\u7684\u53f3\u62ec\u53f7 )\u3002
    2. \n\t
    3. \u4efb\u4f55\u53f3\u62ec\u53f7 ) \u5fc5\u987b\u6709\u76f8\u5e94\u7684\u5de6\u62ec\u53f7 ( \u3002
    4. \n\t
    5. \u5de6\u62ec\u53f7 ( \u5fc5\u987b\u5728\u5bf9\u5e94\u7684\u53f3\u62ec\u53f7\u4e4b\u524d )\u3002
    6. \n\t
    7. * \u53ef\u4ee5\u88ab\u89c6\u4e3a\u5355\u4e2a\u53f3\u62ec\u53f7 ) \uff0c\u6216\u5355\u4e2a\u5de6\u62ec\u53f7 ( \uff0c\u6216\u4e00\u4e2a\u7a7a\u5b57\u7b26\u4e32\u3002
    8. \n\t
    9. \u4e00\u4e2a\u7a7a\u5b57\u7b26\u4e32\u4e5f\u88ab\u89c6\u4e3a\u6709\u6548\u5b57\u7b26\u4e32\u3002
    10. \n
    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: "()"\n\u8f93\u51fa: True\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: "(*)"\n\u8f93\u51fa: True\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \n\u8f93\u5165: "(*))"\n\u8f93\u51fa: True\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u5b57\u7b26\u4e32\u5927\u5c0f\u5c06\u5728 [1\uff0c100] \u8303\u56f4\u5185\u3002
    2. \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool checkValidString(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean checkValidString(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def checkValidString(self, s):\n \"\"\"\n :type s: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def checkValidString(self, s: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool checkValidString(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CheckValidString(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {boolean}\n */\nvar checkValidString = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Boolean}\ndef check_valid_string(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func checkValidString(_ s: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func checkValidString(s string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def checkValidString(s: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun checkValidString(s: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn check_valid_string(s: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Boolean\n */\n function checkValidString($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function checkValidString(s: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (check-valid-string s)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0678](https://leetcode-cn.com/problems/valid-parenthesis-string)", "[\u6709\u6548\u7684\u62ec\u53f7\u5b57\u7b26\u4e32](/solution/0600-0699/0678.Valid%20Parenthesis%20String/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0678](https://leetcode.com/problems/valid-parenthesis-string)", "[Valid Parenthesis String](/solution/0600-0699/0678.Valid%20Parenthesis%20String/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "0677", "frontend_question_id": "0677", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/map-sum-pairs", "url_en": "https://leetcode.com/problems/map-sum-pairs", "relative_path_cn": "/solution/0600-0699/0677.Map%20Sum%20Pairs/README.md", "relative_path_en": "/solution/0600-0699/0677.Map%20Sum%20Pairs/README_EN.md", "title_cn": "\u952e\u503c\u6620\u5c04", "title_en": "Map Sum Pairs", "question_title_slug": "map-sum-pairs", "content_en": "

    Implement the MapSum class:

    \n\n
      \n\t
    • MapSum() Initializes the MapSum object.
    • \n\t
    • void insert(String key, int val) Inserts the key-val pair into the map. If the key already existed, the original key-value pair will be overridden to the new one.
    • \n\t
    • int sum(string prefix) Returns the sum of all the pairs' value whose key starts with the prefix.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["MapSum", "insert", "sum", "insert", "sum"]\n[[], ["apple", 3], ["ap"], ["app", 2], ["ap"]]\nOutput\n[null, null, 3, null, 5]\n\nExplanation\nMapSum mapSum = new MapSum();\nmapSum.insert("apple", 3);  \nmapSum.sum("ap");           // return 3 (apple = 3)\nmapSum.insert("app", 2);    \nmapSum.sum("ap");           // return 5 (apple + app = 3 + 2 = 5)\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= key.length, prefix.length <= 50
    • \n\t
    • key and prefix consist of only lowercase English letters.
    • \n\t
    • 1 <= val <= 1000
    • \n\t
    • At most 50 calls will be made to insert and sum.
    • \n
    \n", "content_cn": "

    \u5b9e\u73b0\u4e00\u4e2a MapSum \u7c7b\uff0c\u652f\u6301\u4e24\u4e2a\u65b9\u6cd5\uff0cinsert\u00a0\u548c\u00a0sum\uff1a

    \n\n
      \n\t
    • MapSum() \u521d\u59cb\u5316 MapSum \u5bf9\u8c61
    • \n\t
    • void insert(String key, int val) \u63d2\u5165 key-val \u952e\u503c\u5bf9\uff0c\u5b57\u7b26\u4e32\u8868\u793a\u952e key \uff0c\u6574\u6570\u8868\u793a\u503c val \u3002\u5982\u679c\u952e key \u5df2\u7ecf\u5b58\u5728\uff0c\u90a3\u4e48\u539f\u6765\u7684\u952e\u503c\u5bf9\u5c06\u88ab\u66ff\u4ee3\u6210\u65b0\u7684\u952e\u503c\u5bf9\u3002
    • \n\t
    • int sum(string prefix) \u8fd4\u56de\u6240\u6709\u4ee5\u8be5\u524d\u7f00 prefix \u5f00\u5934\u7684\u952e key \u7684\u503c\u7684\u603b\u548c\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\n[\"MapSum\", \"insert\", \"sum\", \"insert\", \"sum\"]\n[[], [\"apple\", 3], [\"ap\"], [\"app\", 2], [\"ap\"]]\n\u8f93\u51fa\uff1a\n[null, null, 3, null, 5]\n\n\u89e3\u91ca\uff1a\nMapSum mapSum = new MapSum();\nmapSum.insert(\"apple\", 3);  \nmapSum.sum(\"ap\");           // return 3 (apple = 3)\nmapSum.insert(\"app\", 2);    \nmapSum.sum(\"ap\");           // return 5 (apple + app = 3 + 2 = 5)\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= key.length, prefix.length <= 50
    • \n\t
    • key \u548c prefix \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n\t
    • 1 <= val <= 1000
    • \n\t
    • \u6700\u591a\u8c03\u7528 50 \u6b21 insert \u548c sum
    • \n
    \n", "tags_en": ["Trie"], "tags_cn": ["\u5b57\u5178\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class MapSum {\npublic:\n /** Initialize your data structure here. */\n MapSum() {\n\n }\n \n void insert(string key, int val) {\n\n }\n \n int sum(string prefix) {\n\n }\n};\n\n/**\n * Your MapSum object will be instantiated and called as such:\n * MapSum* obj = new MapSum();\n * obj->insert(key,val);\n * int param_2 = obj->sum(prefix);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class MapSum {\n\n /** Initialize your data structure here. */\n public MapSum() {\n\n }\n \n public void insert(String key, int val) {\n\n }\n \n public int sum(String prefix) {\n\n }\n}\n\n/**\n * Your MapSum object will be instantiated and called as such:\n * MapSum obj = new MapSum();\n * obj.insert(key,val);\n * int param_2 = obj.sum(prefix);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class MapSum(object):\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def insert(self, key, val):\n \"\"\"\n :type key: str\n :type val: int\n :rtype: None\n \"\"\"\n\n\n def sum(self, prefix):\n \"\"\"\n :type prefix: str\n :rtype: int\n \"\"\"\n\n\n\n# Your MapSum object will be instantiated and called as such:\n# obj = MapSum()\n# obj.insert(key,val)\n# param_2 = obj.sum(prefix)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class MapSum:\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def insert(self, key: str, val: int) -> None:\n\n\n def sum(self, prefix: str) -> int:\n\n\n\n# Your MapSum object will be instantiated and called as such:\n# obj = MapSum()\n# obj.insert(key,val)\n# param_2 = obj.sum(prefix)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} MapSum;\n\n/** Initialize your data structure here. */\n\nMapSum* mapSumCreate() {\n \n}\n\nvoid mapSumInsert(MapSum* obj, char * key, int val) {\n \n}\n\nint mapSumSum(MapSum* obj, char * prefix) {\n \n}\n\nvoid mapSumFree(MapSum* obj) {\n \n}\n\n/**\n * Your MapSum struct will be instantiated and called as such:\n * MapSum* obj = mapSumCreate();\n * mapSumInsert(obj, key, val);\n \n * int param_2 = mapSumSum(obj, prefix);\n \n * mapSumFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class MapSum {\n\n /** Initialize your data structure here. */\n public MapSum() {\n\n }\n \n public void Insert(string key, int val) {\n\n }\n \n public int Sum(string prefix) {\n\n }\n}\n\n/**\n * Your MapSum object will be instantiated and called as such:\n * MapSum obj = new MapSum();\n * obj.Insert(key,val);\n * int param_2 = obj.Sum(prefix);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Initialize your data structure here.\n */\nvar MapSum = function() {\n\n};\n\n/** \n * @param {string} key \n * @param {number} val\n * @return {void}\n */\nMapSum.prototype.insert = function(key, val) {\n\n};\n\n/** \n * @param {string} prefix\n * @return {number}\n */\nMapSum.prototype.sum = function(prefix) {\n\n};\n\n/**\n * Your MapSum object will be instantiated and called as such:\n * var obj = new MapSum()\n * obj.insert(key,val)\n * var param_2 = obj.sum(prefix)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class MapSum\n\n=begin\n Initialize your data structure here.\n=end\n def initialize()\n\n end\n\n\n=begin\n :type key: String\n :type val: Integer\n :rtype: Void\n=end\n def insert(key, val)\n\n end\n\n\n=begin\n :type prefix: String\n :rtype: Integer\n=end\n def sum(prefix)\n\n end\n\n\nend\n\n# Your MapSum object will be instantiated and called as such:\n# obj = MapSum.new()\n# obj.insert(key, val)\n# param_2 = obj.sum(prefix)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass MapSum {\n\n /** Initialize your data structure here. */\n init() {\n\n }\n \n func insert(_ key: String, _ val: Int) {\n\n }\n \n func sum(_ prefix: String) -> Int {\n\n }\n}\n\n/**\n * Your MapSum object will be instantiated and called as such:\n * let obj = MapSum()\n * obj.insert(key, val)\n * let ret_2: Int = obj.sum(prefix)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type MapSum struct {\n\n}\n\n\n/** Initialize your data structure here. */\nfunc Constructor() MapSum {\n\n}\n\n\nfunc (this *MapSum) Insert(key string, val int) {\n\n}\n\n\nfunc (this *MapSum) Sum(prefix string) int {\n\n}\n\n\n/**\n * Your MapSum object will be instantiated and called as such:\n * obj := Constructor();\n * obj.Insert(key,val);\n * param_2 := obj.Sum(prefix);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class MapSum() {\n\n /** Initialize your data structure here. */\n\n\n def insert(key: String, `val`: Int) {\n\n }\n\n def sum(prefix: String): Int = {\n\n }\n\n}\n\n/**\n * Your MapSum object will be instantiated and called as such:\n * var obj = new MapSum()\n * obj.insert(key,`val`)\n * var param_2 = obj.sum(prefix)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class MapSum() {\n\n /** Initialize your data structure here. */\n\n\n fun insert(key: String, `val`: Int) {\n\n }\n\n fun sum(prefix: String): Int {\n\n }\n\n}\n\n/**\n * Your MapSum object will be instantiated and called as such:\n * var obj = MapSum()\n * obj.insert(key,`val`)\n * var param_2 = obj.sum(prefix)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct MapSum {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl MapSum {\n\n /** Initialize your data structure here. */\n fn new() -> Self {\n\n }\n \n fn insert(&self, key: String, val: i32) {\n\n }\n \n fn sum(&self, prefix: String) -> i32 {\n\n }\n}\n\n/**\n * Your MapSum object will be instantiated and called as such:\n * let obj = MapSum::new();\n * obj.insert(key, val);\n * let ret_2: i32 = obj.sum(prefix);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class MapSum {\n /**\n * Initialize your data structure here.\n */\n function __construct() {\n\n }\n\n /**\n * @param String $key\n * @param Integer $val\n * @return NULL\n */\n function insert($key, $val) {\n\n }\n\n /**\n * @param String $prefix\n * @return Integer\n */\n function sum($prefix) {\n\n }\n}\n\n/**\n * Your MapSum object will be instantiated and called as such:\n * $obj = MapSum();\n * $obj->insert($key, $val);\n * $ret_2 = $obj->sum($prefix);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class MapSum {\n constructor() {\n\n }\n\n insert(key: string, val: number): void {\n\n }\n\n sum(prefix: string): number {\n\n }\n}\n\n/**\n * Your MapSum object will be instantiated and called as such:\n * var obj = new MapSum()\n * obj.insert(key,val)\n * var param_2 = obj.sum(prefix)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define map-sum%\n (class object%\n (super-new)\n (init-field)\n \n ; insert : string? exact-integer? -> void?\n (define/public (insert key val)\n\n )\n ; sum : string? -> exact-integer?\n (define/public (sum prefix)\n\n )))\n\n;; Your map-sum% object will be instantiated and called as such:\n;; (define obj (new map-sum%))\n;; (send obj insert key val)\n;; (define param_2 (send obj sum prefix))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0677](https://leetcode-cn.com/problems/map-sum-pairs)", "[\u952e\u503c\u6620\u5c04](/solution/0600-0699/0677.Map%20Sum%20Pairs/README.md)", "`\u5b57\u5178\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0677](https://leetcode.com/problems/map-sum-pairs)", "[Map Sum Pairs](/solution/0600-0699/0677.Map%20Sum%20Pairs/README_EN.md)", "`Trie`", "Medium", ""]}, {"question_id": "0676", "frontend_question_id": "0676", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/implement-magic-dictionary", "url_en": "https://leetcode.com/problems/implement-magic-dictionary", "relative_path_cn": "/solution/0600-0699/0676.Implement%20Magic%20Dictionary/README.md", "relative_path_en": "/solution/0600-0699/0676.Implement%20Magic%20Dictionary/README_EN.md", "title_cn": "\u5b9e\u73b0\u4e00\u4e2a\u9b54\u6cd5\u5b57\u5178", "title_en": "Implement Magic Dictionary", "question_title_slug": "implement-magic-dictionary", "content_en": "

    Design a data structure that is initialized with a list of different words. Provided a string, you should determine if you can change exactly one character in this string to match any word in the data structure.

    \n\n

    Implement the MagicDictionary class:

    \n\n
      \n\t
    • MagicDictionary() Initializes the object.
    • \n\t
    • void buildDict(String[] dictionary) Sets the data structure with an array of distinct strings dictionary.
    • \n\t
    • bool search(String searchWord) Returns true if you can change exactly one character in searchWord to match any string in the data structure, otherwise returns false.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["MagicDictionary", "buildDict", "search", "search", "search", "search"]\n[[], [["hello", "leetcode"]], ["hello"], ["hhllo"], ["hell"], ["leetcoded"]]\nOutput\n[null, null, false, true, false, false]\n\nExplanation\nMagicDictionary magicDictionary = new MagicDictionary();\nmagicDictionary.buildDict(["hello", "leetcode"]);\nmagicDictionary.search("hello"); // return False\nmagicDictionary.search("hhllo"); // We can change the second 'h' to 'e' to match "hello" so we return True\nmagicDictionary.search("hell"); // return False\nmagicDictionary.search("leetcoded"); // return False\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= dictionary.length <= 100
    • \n\t
    • 1 <= dictionary[i].length <= 100
    • \n\t
    • dictionary[i] consists of only lower-case English letters.
    • \n\t
    • All the strings in dictionary are distinct.
    • \n\t
    • 1 <= searchWord.length <= 100
    • \n\t
    • searchWord consists of only lower-case English letters.
    • \n\t
    • buildDict will be called only once before search.
    • \n\t
    • At most 100 calls will be made to search.
    • \n
    \n", "content_cn": "

    \u8bbe\u8ba1\u4e00\u4e2a\u4f7f\u7528\u5355\u8bcd\u5217\u8868\u8fdb\u884c\u521d\u59cb\u5316\u7684\u6570\u636e\u7ed3\u6784\uff0c\u5355\u8bcd\u5217\u8868\u4e2d\u7684\u5355\u8bcd \u4e92\u4e0d\u76f8\u540c \u3002 \u5982\u679c\u7ed9\u51fa\u4e00\u4e2a\u5355\u8bcd\uff0c\u8bf7\u5224\u5b9a\u80fd\u5426\u53ea\u5c06\u8fd9\u4e2a\u5355\u8bcd\u4e2d\u4e00\u4e2a\u5b57\u6bcd\u6362\u6210\u53e6\u4e00\u4e2a\u5b57\u6bcd\uff0c\u4f7f\u5f97\u6240\u5f62\u6210\u7684\u65b0\u5355\u8bcd\u5b58\u5728\u4e8e\u4f60\u6784\u5efa\u7684\u5b57\u5178\u4e2d\u3002

    \n\n

    \u5b9e\u73b0 MagicDictionary \u7c7b\uff1a

    \n\n
      \n\t
    • MagicDictionary() \u521d\u59cb\u5316\u5bf9\u8c61
    • \n\t
    • void buildDict(String[]\u00a0dictionary) \u4f7f\u7528\u5b57\u7b26\u4e32\u6570\u7ec4\u00a0dictionary \u8bbe\u5b9a\u8be5\u6570\u636e\u7ed3\u6784\uff0cdictionary \u4e2d\u7684\u5b57\u7b26\u4e32\u4e92\u4e0d\u76f8\u540c
    • \n\t
    • bool search(String searchWord) \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32 searchWord \uff0c\u5224\u5b9a\u80fd\u5426\u53ea\u5c06\u5b57\u7b26\u4e32\u4e2d \u4e00\u4e2a \u5b57\u6bcd\u6362\u6210\u53e6\u4e00\u4e2a\u5b57\u6bcd\uff0c\u4f7f\u5f97\u6240\u5f62\u6210\u7684\u65b0\u5b57\u7b26\u4e32\u80fd\u591f\u4e0e\u5b57\u5178\u4e2d\u7684\u4efb\u4e00\u5b57\u7b26\u4e32\u5339\u914d\u3002\u5982\u679c\u53ef\u4ee5\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002
    • \n
    \n\n

    \u00a0

    \n\n
    \n
    \n
    \n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\n[\"MagicDictionary\", \"buildDict\", \"search\", \"search\", \"search\", \"search\"]\n[[], [[\"hello\", \"leetcode\"]], [\"hello\"], [\"hhllo\"], [\"hell\"], [\"leetcoded\"]]\n\u8f93\u51fa\n[null, null, false, true, false, false]\n\n\u89e3\u91ca\nMagicDictionary magicDictionary = new MagicDictionary();\nmagicDictionary.buildDict([\"hello\", \"leetcode\"]);\nmagicDictionary.search(\"hello\"); // \u8fd4\u56de False\nmagicDictionary.search(\"hhllo\"); // \u5c06\u7b2c\u4e8c\u4e2a 'h' \u66ff\u6362\u4e3a 'e' \u53ef\u4ee5\u5339\u914d \"hello\" \uff0c\u6240\u4ee5\u8fd4\u56de True\nmagicDictionary.search(\"hell\"); // \u8fd4\u56de False\nmagicDictionary.search(\"leetcoded\"); // \u8fd4\u56de False\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <=\u00a0dictionary.length <= 100
    • \n\t
    • 1 <=\u00a0dictionary[i].length <= 100
    • \n\t
    • dictionary[i] \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n\t
    • dictionary \u4e2d\u7684\u6240\u6709\u5b57\u7b26\u4e32 \u4e92\u4e0d\u76f8\u540c
    • \n\t
    • 1 <=\u00a0searchWord.length <= 100
    • \n\t
    • searchWord \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n\t
    • buildDict \u4ec5\u5728 search \u4e4b\u524d\u8c03\u7528\u4e00\u6b21
    • \n\t
    • \u6700\u591a\u8c03\u7528 100 \u6b21 search
    • \n
    \n
    \n
    \n
    \n", "tags_en": ["Trie", "Hash Table"], "tags_cn": ["\u5b57\u5178\u6811", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class MagicDictionary {\npublic:\n /** Initialize your data structure here. */\n MagicDictionary() {\n\n }\n \n void buildDict(vector dictionary) {\n\n }\n \n bool search(string searchWord) {\n\n }\n};\n\n/**\n * Your MagicDictionary object will be instantiated and called as such:\n * MagicDictionary* obj = new MagicDictionary();\n * obj->buildDict(dictionary);\n * bool param_2 = obj->search(searchWord);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class MagicDictionary {\n\n /** Initialize your data structure here. */\n public MagicDictionary() {\n\n }\n \n public void buildDict(String[] dictionary) {\n\n }\n \n public boolean search(String searchWord) {\n\n }\n}\n\n/**\n * Your MagicDictionary object will be instantiated and called as such:\n * MagicDictionary obj = new MagicDictionary();\n * obj.buildDict(dictionary);\n * boolean param_2 = obj.search(searchWord);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class MagicDictionary(object):\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def buildDict(self, dictionary):\n \"\"\"\n :type dictionary: List[str]\n :rtype: None\n \"\"\"\n\n\n def search(self, searchWord):\n \"\"\"\n :type searchWord: str\n :rtype: bool\n \"\"\"\n\n\n\n# Your MagicDictionary object will be instantiated and called as such:\n# obj = MagicDictionary()\n# obj.buildDict(dictionary)\n# param_2 = obj.search(searchWord)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class MagicDictionary:\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def buildDict(self, dictionary: List[str]) -> None:\n\n\n def search(self, searchWord: str) -> bool:\n\n\n\n# Your MagicDictionary object will be instantiated and called as such:\n# obj = MagicDictionary()\n# obj.buildDict(dictionary)\n# param_2 = obj.search(searchWord)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} MagicDictionary;\n\n/** Initialize your data structure here. */\n\nMagicDictionary* magicDictionaryCreate() {\n \n}\n\nvoid magicDictionaryBuildDict(MagicDictionary* obj, char ** dictionary, int dictionarySize) {\n \n}\n\nbool magicDictionarySearch(MagicDictionary* obj, char * searchWord) {\n \n}\n\nvoid magicDictionaryFree(MagicDictionary* obj) {\n \n}\n\n/**\n * Your MagicDictionary struct will be instantiated and called as such:\n * MagicDictionary* obj = magicDictionaryCreate();\n * magicDictionaryBuildDict(obj, dictionary, dictionarySize);\n \n * bool param_2 = magicDictionarySearch(obj, searchWord);\n \n * magicDictionaryFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class MagicDictionary {\n\n /** Initialize your data structure here. */\n public MagicDictionary() {\n\n }\n \n public void BuildDict(string[] dictionary) {\n\n }\n \n public bool Search(string searchWord) {\n\n }\n}\n\n/**\n * Your MagicDictionary object will be instantiated and called as such:\n * MagicDictionary obj = new MagicDictionary();\n * obj.BuildDict(dictionary);\n * bool param_2 = obj.Search(searchWord);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Initialize your data structure here.\n */\nvar MagicDictionary = function() {\n\n};\n\n/** \n * @param {string[]} dictionary\n * @return {void}\n */\nMagicDictionary.prototype.buildDict = function(dictionary) {\n\n};\n\n/** \n * @param {string} searchWord\n * @return {boolean}\n */\nMagicDictionary.prototype.search = function(searchWord) {\n\n};\n\n/**\n * Your MagicDictionary object will be instantiated and called as such:\n * var obj = new MagicDictionary()\n * obj.buildDict(dictionary)\n * var param_2 = obj.search(searchWord)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class MagicDictionary\n\n=begin\n Initialize your data structure here.\n=end\n def initialize()\n\n end\n\n\n=begin\n :type dictionary: String[]\n :rtype: Void\n=end\n def build_dict(dictionary)\n\n end\n\n\n=begin\n :type search_word: String\n :rtype: Boolean\n=end\n def search(search_word)\n\n end\n\n\nend\n\n# Your MagicDictionary object will be instantiated and called as such:\n# obj = MagicDictionary.new()\n# obj.build_dict(dictionary)\n# param_2 = obj.search(search_word)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass MagicDictionary {\n\n /** Initialize your data structure here. */\n init() {\n \n }\n \n func buildDict(_ dictionary: [String]) {\n \n }\n \n func search(_ searchWord: String) -> Bool {\n \n }\n}\n\n/**\n * Your MagicDictionary object will be instantiated and called as such:\n * let obj = MagicDictionary()\n * obj.buildDict(dictionary)\n * let ret_2: Bool = obj.search(searchWord)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type MagicDictionary struct {\n\n}\n\n\n/** Initialize your data structure here. */\nfunc Constructor() MagicDictionary {\n\n}\n\n\nfunc (this *MagicDictionary) BuildDict(dictionary []string) {\n\n}\n\n\nfunc (this *MagicDictionary) Search(searchWord string) bool {\n\n}\n\n\n/**\n * Your MagicDictionary object will be instantiated and called as such:\n * obj := Constructor();\n * obj.BuildDict(dictionary);\n * param_2 := obj.Search(searchWord);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class MagicDictionary() {\n\n /** Initialize your data structure here. */\n\n\n def buildDict(dictionary: Array[String]) {\n\n }\n\n def search(searchWord: String): Boolean = {\n\n }\n\n}\n\n/**\n * Your MagicDictionary object will be instantiated and called as such:\n * var obj = new MagicDictionary()\n * obj.buildDict(dictionary)\n * var param_2 = obj.search(searchWord)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class MagicDictionary() {\n\n /** Initialize your data structure here. */\n\n\n fun buildDict(dictionary: Array) {\n\n }\n\n fun search(searchWord: String): Boolean {\n\n }\n\n}\n\n/**\n * Your MagicDictionary object will be instantiated and called as such:\n * var obj = MagicDictionary()\n * obj.buildDict(dictionary)\n * var param_2 = obj.search(searchWord)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct MagicDictionary {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl MagicDictionary {\n\n /** Initialize your data structure here. */\n fn new() -> Self {\n\n }\n \n fn build_dict(&self, dictionary: Vec) {\n\n }\n \n fn search(&self, search_word: String) -> bool {\n\n }\n}\n\n/**\n * Your MagicDictionary object will be instantiated and called as such:\n * let obj = MagicDictionary::new();\n * obj.build_dict(dictionary);\n * let ret_2: bool = obj.search(searchWord);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class MagicDictionary {\n /**\n * Initialize your data structure here.\n */\n function __construct() {\n\n }\n\n /**\n * @param String[] $dictionary\n * @return NULL\n */\n function buildDict($dictionary) {\n\n }\n\n /**\n * @param String $searchWord\n * @return Boolean\n */\n function search($searchWord) {\n\n }\n}\n\n/**\n * Your MagicDictionary object will be instantiated and called as such:\n * $obj = MagicDictionary();\n * $obj->buildDict($dictionary);\n * $ret_2 = $obj->search($searchWord);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class MagicDictionary {\n constructor() {\n\n }\n\n buildDict(dictionary: string[]): void {\n\n }\n\n search(searchWord: string): boolean {\n\n }\n}\n\n/**\n * Your MagicDictionary object will be instantiated and called as such:\n * var obj = new MagicDictionary()\n * obj.buildDict(dictionary)\n * var param_2 = obj.search(searchWord)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define magic-dictionary%\n (class object%\n (super-new)\n (init-field)\n \n ; build-dict : (listof string?) -> void?\n (define/public (build-dict dictionary)\n\n )\n ; search : string? -> boolean?\n (define/public (search searchWord)\n\n )))\n\n;; Your magic-dictionary% object will be instantiated and called as such:\n;; (define obj (new magic-dictionary%))\n;; (send obj build-dict dictionary)\n;; (define param_2 (send obj search search-word))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0676](https://leetcode-cn.com/problems/implement-magic-dictionary)", "[\u5b9e\u73b0\u4e00\u4e2a\u9b54\u6cd5\u5b57\u5178](/solution/0600-0699/0676.Implement%20Magic%20Dictionary/README.md)", "`\u5b57\u5178\u6811`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0676](https://leetcode.com/problems/implement-magic-dictionary)", "[Implement Magic Dictionary](/solution/0600-0699/0676.Implement%20Magic%20Dictionary/README_EN.md)", "`Trie`,`Hash Table`", "Medium", ""]}, {"question_id": "0675", "frontend_question_id": "0675", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/cut-off-trees-for-golf-event", "url_en": "https://leetcode.com/problems/cut-off-trees-for-golf-event", "relative_path_cn": "/solution/0600-0699/0675.Cut%20Off%20Trees%20for%20Golf%20Event/README.md", "relative_path_en": "/solution/0600-0699/0675.Cut%20Off%20Trees%20for%20Golf%20Event/README_EN.md", "title_cn": "\u4e3a\u9ad8\u5c14\u592b\u6bd4\u8d5b\u780d\u6811", "title_en": "Cut Off Trees for Golf Event", "question_title_slug": "cut-off-trees-for-golf-event", "content_en": "

    You are asked to cut off all the trees in a forest for a golf event. The forest is represented as an m x n matrix. In this matrix:

    \n\n
      \n\t
    • 0 means the cell cannot be walked through.
    • \n\t
    • 1 represents an empty cell that can be walked through.
    • \n\t
    • A number greater than 1 represents a tree in a cell that can be walked through, and this number is the tree's height.
    • \n
    \n\n

    In one step, you can walk in any of the four directions: north, east, south, and west. If you are standing in a cell with a tree, you can choose whether to cut it off.

    \n\n

    You must cut off the trees in order from shortest to tallest. When you cut off a tree, the value at its cell becomes 1 (an empty cell).

    \n\n

    Starting from the point (0, 0), return the minimum steps you need to walk to cut off all the trees. If you cannot cut off all the trees, return -1.

    \n\n

    You are guaranteed that no two trees have the same height, and there is at least one tree needs to be cut off.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: forest = [[1,2,3],[0,0,4],[7,6,5]]\nOutput: 6\nExplanation: Following the path above allows you to cut off the trees from shortest to tallest in 6 steps.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: forest = [[1,2,3],[0,0,0],[7,6,5]]\nOutput: -1\nExplanation: The trees in the bottom row cannot be accessed as the middle row is blocked.\n
    \n\n

    Example 3:

    \n\n
    \nInput: forest = [[2,3,4],[0,0,5],[8,7,6]]\nOutput: 6\nExplanation: You can follow the same path as Example 1 to cut off all the trees.\nNote that you can cut off the first tree at (0, 0) before making any steps.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == forest.length
    • \n\t
    • n == forest[i].length
    • \n\t
    • 1 <= m, n <= 50
    • \n\t
    • 0 <= forest[i][j] <= 109
    • \n
    \n", "content_cn": "

    \u4f60\u88ab\u8bf7\u6765\u7ed9\u4e00\u4e2a\u8981\u4e3e\u529e\u9ad8\u5c14\u592b\u6bd4\u8d5b\u7684\u6811\u6797\u780d\u6811\u3002\u6811\u6797\u7531\u4e00\u4e2a\u00a0m x n \u7684\u77e9\u9635\u8868\u793a\uff0c \u5728\u8fd9\u4e2a\u77e9\u9635\u4e2d\uff1a

    \n\n
      \n\t
    • 0 \u8868\u793a\u969c\u788d\uff0c\u65e0\u6cd5\u89e6\u78b0
    • \n\t
    • 1\u00a0\u8868\u793a\u5730\u9762\uff0c\u53ef\u4ee5\u884c\u8d70
    • \n\t
    • \u6bd4 1 \u5927\u7684\u6570\u00a0\u8868\u793a\u6709\u6811\u7684\u5355\u5143\u683c\uff0c\u53ef\u4ee5\u884c\u8d70\uff0c\u6570\u503c\u8868\u793a\u6811\u7684\u9ad8\u5ea6
    • \n
    \n\n

    \u6bcf\u4e00\u6b65\uff0c\u4f60\u90fd\u53ef\u4ee5\u5411\u4e0a\u3001\u4e0b\u3001\u5de6\u3001\u53f3\u56db\u4e2a\u65b9\u5411\u4e4b\u4e00\u79fb\u52a8\u4e00\u4e2a\u5355\u4f4d\uff0c\u5982\u679c\u4f60\u7ad9\u7684\u5730\u65b9\u6709\u4e00\u68f5\u6811\uff0c\u90a3\u4e48\u4f60\u53ef\u4ee5\u51b3\u5b9a\u662f\u5426\u8981\u780d\u5012\u5b83\u3002

    \n\n

    \u4f60\u9700\u8981\u6309\u7167\u6811\u7684\u9ad8\u5ea6\u4ece\u4f4e\u5411\u9ad8\u780d\u6389\u6240\u6709\u7684\u6811\uff0c\u6bcf\u780d\u8fc7\u4e00\u9897\u6811\uff0c\u8be5\u5355\u5143\u683c\u7684\u503c\u53d8\u4e3a 1\uff08\u5373\u53d8\u4e3a\u5730\u9762\uff09\u3002

    \n\n

    \u4f60\u5c06\u4ece (0, 0) \u70b9\u5f00\u59cb\u5de5\u4f5c\uff0c\u8fd4\u56de\u4f60\u780d\u5b8c\u6240\u6709\u6811\u9700\u8981\u8d70\u7684\u6700\u5c0f\u6b65\u6570\u3002 \u5982\u679c\u4f60\u65e0\u6cd5\u780d\u5b8c\u6240\u6709\u7684\u6811\uff0c\u8fd4\u56de -1 \u3002

    \n\n

    \u53ef\u4ee5\u4fdd\u8bc1\u7684\u662f\uff0c\u6ca1\u6709\u4e24\u68f5\u6811\u7684\u9ad8\u5ea6\u662f\u76f8\u540c\u7684\uff0c\u5e76\u4e14\u4f60\u81f3\u5c11\u9700\u8981\u780d\u5012\u4e00\u68f5\u6811\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aforest = [[1,2,3],[0,0,4],[7,6,5]]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u6cbf\u7740\u4e0a\u9762\u7684\u8def\u5f84\uff0c\u4f60\u53ef\u4ee5\u7528 6 \u6b65\uff0c\u6309\u4ece\u6700\u77ee\u5230\u6700\u9ad8\u7684\u987a\u5e8f\u780d\u6389\u8fd9\u4e9b\u6811\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aforest = [[1,2,3],[0,0,0],[7,6,5]]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u7531\u4e8e\u4e2d\u95f4\u4e00\u884c\u88ab\u969c\u788d\u963b\u585e\uff0c\u65e0\u6cd5\u8bbf\u95ee\u6700\u4e0b\u9762\u4e00\u884c\u4e2d\u7684\u6811\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aforest = [[2,3,4],[0,0,5],[8,7,6]]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u53ef\u4ee5\u6309\u4e0e\u793a\u4f8b 1 \u76f8\u540c\u7684\u8def\u5f84\u6765\u780d\u6389\u6240\u6709\u7684\u6811\u3002\n(0,0) \u4f4d\u7f6e\u7684\u6811\uff0c\u53ef\u4ee5\u76f4\u63a5\u780d\u53bb\uff0c\u4e0d\u7528\u7b97\u6b65\u6570\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == forest.length
    • \n\t
    • n == forest[i].length
    • \n\t
    • 1 <= m, n <= 50
    • \n\t
    • 0 <= forest[i][j] <= 109
    • \n
    \n", "tags_en": ["Breadth-first Search"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int cutOffTree(vector>& forest) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int cutOffTree(List> forest) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def cutOffTree(self, forest):\n \"\"\"\n :type forest: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def cutOffTree(self, forest: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint cutOffTree(int** forest, int forestSize, int* forestColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CutOffTree(IList> forest) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} forest\n * @return {number}\n */\nvar cutOffTree = function(forest) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} forest\n# @return {Integer}\ndef cut_off_tree(forest)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func cutOffTree(_ forest: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func cutOffTree(forest [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def cutOffTree(forest: List[List[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun cutOffTree(forest: List>): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn cut_off_tree(forest: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $forest\n * @return Integer\n */\n function cutOffTree($forest) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function cutOffTree(forest: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (cut-off-tree forest)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0675](https://leetcode-cn.com/problems/cut-off-trees-for-golf-event)", "[\u4e3a\u9ad8\u5c14\u592b\u6bd4\u8d5b\u780d\u6811](/solution/0600-0699/0675.Cut%20Off%20Trees%20for%20Golf%20Event/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[0675](https://leetcode.com/problems/cut-off-trees-for-golf-event)", "[Cut Off Trees for Golf Event](/solution/0600-0699/0675.Cut%20Off%20Trees%20for%20Golf%20Event/README_EN.md)", "`Breadth-first Search`", "Hard", ""]}, {"question_id": "0674", "frontend_question_id": "0674", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-continuous-increasing-subsequence", "url_en": "https://leetcode.com/problems/longest-continuous-increasing-subsequence", "relative_path_cn": "/solution/0600-0699/0674.Longest%20Continuous%20Increasing%20Subsequence/README.md", "relative_path_en": "/solution/0600-0699/0674.Longest%20Continuous%20Increasing%20Subsequence/README_EN.md", "title_cn": "\u6700\u957f\u8fde\u7eed\u9012\u589e\u5e8f\u5217", "title_en": "Longest Continuous Increasing Subsequence", "question_title_slug": "longest-continuous-increasing-subsequence", "content_en": "

    Given an unsorted array of integers nums, return the length of the longest continuous increasing subsequence (i.e. subarray). The subsequence must be strictly increasing.

    \n\n

    A continuous increasing subsequence is defined by two indices l and r (l < r) such that it is [nums[l], nums[l + 1], ..., nums[r - 1], nums[r]] and for each l <= i < r, nums[i] < nums[i + 1].

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,3,5,4,7]\nOutput: 3\nExplanation: The longest continuous increasing subsequence is [1,3,5] with length 3.\nEven though [1,3,5,7] is an increasing subsequence, it is not continuous as elements 5 and 7 are separated by element\n4.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [2,2,2,2,2]\nOutput: 1\nExplanation: The longest continuous increasing subsequence is [2] with length 1. Note that it must be strictly\nincreasing.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 104
    • \n\t
    • -109 <= nums[i] <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u672a\u7ecf\u6392\u5e8f\u7684\u6574\u6570\u6570\u7ec4\uff0c\u627e\u5230\u6700\u957f\u4e14 \u8fde\u7eed\u9012\u589e\u7684\u5b50\u5e8f\u5217\uff0c\u5e76\u8fd4\u56de\u8be5\u5e8f\u5217\u7684\u957f\u5ea6\u3002

    \n\n

    \u8fde\u7eed\u9012\u589e\u7684\u5b50\u5e8f\u5217 \u53ef\u4ee5\u7531\u4e24\u4e2a\u4e0b\u6807 l \u548c r\uff08l < r\uff09\u786e\u5b9a\uff0c\u5982\u679c\u5bf9\u4e8e\u6bcf\u4e2a l <= i < r\uff0c\u90fd\u6709 nums[i] < nums[i + 1] \uff0c\u90a3\u4e48\u5b50\u5e8f\u5217 [nums[l], nums[l + 1], ..., nums[r - 1], nums[r]] \u5c31\u662f\u8fde\u7eed\u9012\u589e\u5b50\u5e8f\u5217\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,3,5,4,7]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6700\u957f\u8fde\u7eed\u9012\u589e\u5e8f\u5217\u662f [1,3,5], \u957f\u5ea6\u4e3a3\u3002\n\u5c3d\u7ba1 [1,3,5,7] \u4e5f\u662f\u5347\u5e8f\u7684\u5b50\u5e8f\u5217, \u4f46\u5b83\u4e0d\u662f\u8fde\u7eed\u7684\uff0c\u56e0\u4e3a 5 \u548c 7 \u5728\u539f\u6570\u7ec4\u91cc\u88ab 4 \u9694\u5f00\u3002 \n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [2,2,2,2,2]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u6700\u957f\u8fde\u7eed\u9012\u589e\u5e8f\u5217\u662f [2], \u957f\u5ea6\u4e3a1\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 104
    • \n\t
    • -109 <= nums[i] <= 109
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findLengthOfLCIS(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findLengthOfLCIS(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findLengthOfLCIS(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findLengthOfLCIS(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findLengthOfLCIS(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindLengthOfLCIS(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar findLengthOfLCIS = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef find_length_of_lcis(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findLengthOfLCIS(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findLengthOfLCIS(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findLengthOfLCIS(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findLengthOfLCIS(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_length_of_lcis(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function findLengthOfLCIS($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findLengthOfLCIS(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-length-of-lcis nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0674](https://leetcode-cn.com/problems/longest-continuous-increasing-subsequence)", "[\u6700\u957f\u8fde\u7eed\u9012\u589e\u5e8f\u5217](/solution/0600-0699/0674.Longest%20Continuous%20Increasing%20Subsequence/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0674](https://leetcode.com/problems/longest-continuous-increasing-subsequence)", "[Longest Continuous Increasing Subsequence](/solution/0600-0699/0674.Longest%20Continuous%20Increasing%20Subsequence/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0673", "frontend_question_id": "0673", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-longest-increasing-subsequence", "url_en": "https://leetcode.com/problems/number-of-longest-increasing-subsequence", "relative_path_cn": "/solution/0600-0699/0673.Number%20of%20Longest%20Increasing%20Subsequence/README.md", "relative_path_en": "/solution/0600-0699/0673.Number%20of%20Longest%20Increasing%20Subsequence/README_EN.md", "title_cn": "\u6700\u957f\u9012\u589e\u5b50\u5e8f\u5217\u7684\u4e2a\u6570", "title_en": "Number of Longest Increasing Subsequence", "question_title_slug": "number-of-longest-increasing-subsequence", "content_en": "

    Given an integer array nums, return the number of longest increasing subsequences.

    \n\n

    Notice that the sequence has to be strictly increasing.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,3,5,4,7]\nOutput: 2\nExplanation: The two longest increasing subsequences are [1, 3, 4, 7] and [1, 3, 5, 7].\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [2,2,2,2,2]\nOutput: 5\nExplanation: The length of longest continuous increasing subsequence is 1, and there are 5 subsequences' length is 1, so output 5.\n\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 2000
    • \n\t
    • -106 <= nums[i] <= 106
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u672a\u6392\u5e8f\u7684\u6574\u6570\u6570\u7ec4\uff0c\u627e\u5230\u6700\u957f\u9012\u589e\u5b50\u5e8f\u5217\u7684\u4e2a\u6570\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: [1,3,5,4,7]\n\u8f93\u51fa: 2\n\u89e3\u91ca: \u6709\u4e24\u4e2a\u6700\u957f\u9012\u589e\u5b50\u5e8f\u5217\uff0c\u5206\u522b\u662f [1, 3, 4, 7] \u548c[1, 3, 5, 7]\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: [2,2,2,2,2]\n\u8f93\u51fa: 5\n\u89e3\u91ca: \u6700\u957f\u9012\u589e\u5b50\u5e8f\u5217\u7684\u957f\u5ea6\u662f1\uff0c\u5e76\u4e14\u5b58\u57285\u4e2a\u5b50\u5e8f\u5217\u7684\u957f\u5ea6\u4e3a1\uff0c\u56e0\u6b64\u8f93\u51fa5\u3002\n
    \n\n

    \u6ce8\u610f: \u7ed9\u5b9a\u7684\u6570\u7ec4\u957f\u5ea6\u4e0d\u8d85\u8fc7 2000 \u5e76\u4e14\u7ed3\u679c\u4e00\u5b9a\u662f32\u4f4d\u6709\u7b26\u53f7\u6574\u6570\u3002

    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findNumberOfLIS(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findNumberOfLIS(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findNumberOfLIS(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findNumberOfLIS(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findNumberOfLIS(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindNumberOfLIS(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar findNumberOfLIS = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef find_number_of_lis(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findNumberOfLIS(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findNumberOfLIS(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findNumberOfLIS(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findNumberOfLIS(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_number_of_lis(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function findNumberOfLIS($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findNumberOfLIS(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-number-of-lis nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0673](https://leetcode-cn.com/problems/number-of-longest-increasing-subsequence)", "[\u6700\u957f\u9012\u589e\u5b50\u5e8f\u5217\u7684\u4e2a\u6570](/solution/0600-0699/0673.Number%20of%20Longest%20Increasing%20Subsequence/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0673](https://leetcode.com/problems/number-of-longest-increasing-subsequence)", "[Number of Longest Increasing Subsequence](/solution/0600-0699/0673.Number%20of%20Longest%20Increasing%20Subsequence/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0672", "frontend_question_id": "0672", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/bulb-switcher-ii", "url_en": "https://leetcode.com/problems/bulb-switcher-ii", "relative_path_cn": "/solution/0600-0699/0672.Bulb%20Switcher%20II/README.md", "relative_path_en": "/solution/0600-0699/0672.Bulb%20Switcher%20II/README_EN.md", "title_cn": "\u706f\u6ce1\u5f00\u5173 \u2161", "title_en": "Bulb Switcher II", "question_title_slug": "bulb-switcher-ii", "content_en": "

    There is a room with n bulbs labeled from 1 to n that all are turned on initially, and four buttons on the wall. Each of the four buttons has a different functionality where:

    \n\n
      \n\t
    • Button 1: Flips the status of all the bulbs.
    • \n\t
    • Button 2: Flips the status of all the bulbs with even labels (i.e., 2, 4, ...).
    • \n\t
    • Button 3: Flips the status of all the bulbs with odd labels (i.e., 1, 3, ...).
    • \n\t
    • Button 4: Flips the status of all the bulbs with a label j = 3k + 1 where k = 0, 1, 2, ... (i.e., 1, 4, 7, 10, ...).
    • \n
    \n\n

    You will press one of the four mentioned buttons exactly presses times.

    \n\n

    Given the two integers n and presses, return the number of different statuses after pressing the four buttons exactly presses times.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 1, presses = 1\nOutput: 2\nExplanation: Status can be: [on], [off].\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 2, presses = 1\nOutput: 3\nExplanation: Status can be: [on, off], [off, on], [off, off].\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 3, presses = 1\nOutput: 4\nExplanation: Status can be: [off, on, off], [on, off, on], [off, off, off], [off, on, on].\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 1000
    • \n\t
    • 0 <= presses <= 1000
    • \n
    \n", "content_cn": "

    \u73b0\u6709\u4e00\u4e2a\u623f\u95f4\uff0c\u5899\u4e0a\u6302\u6709 n \u53ea\u5df2\u7ecf\u6253\u5f00\u7684\u706f\u6ce1\u548c 4 \u4e2a\u6309\u94ae\u3002\u5728\u8fdb\u884c\u4e86 m \u6b21\u672a\u77e5\u64cd\u4f5c\u540e\uff0c\u4f60\u9700\u8981\u8fd4\u56de\u8fd9 n \u53ea\u706f\u6ce1\u53ef\u80fd\u6709\u591a\u5c11\u79cd\u4e0d\u540c\u7684\u72b6\u6001\u3002

    \n\n

    \u5047\u8bbe\u8fd9 n \u53ea\u706f\u6ce1\u88ab\u7f16\u53f7\u4e3a [1, 2, 3 ..., n]\uff0c\u8fd9 4 \u4e2a\u6309\u94ae\u7684\u529f\u80fd\u5982\u4e0b\uff1a

    \n\n
      \n\t
    1. \u5c06\u6240\u6709\u706f\u6ce1\u7684\u72b6\u6001\u53cd\u8f6c\uff08\u5373\u5f00\u53d8\u4e3a\u5173\uff0c\u5173\u53d8\u4e3a\u5f00\uff09
    2. \n\t
    3. \u5c06\u7f16\u53f7\u4e3a\u5076\u6570\u7684\u706f\u6ce1\u7684\u72b6\u6001\u53cd\u8f6c
    4. \n\t
    5. \u5c06\u7f16\u53f7\u4e3a\u5947\u6570\u7684\u706f\u6ce1\u7684\u72b6\u6001\u53cd\u8f6c
    6. \n\t
    7. \u5c06\u7f16\u53f7\u4e3a 3k+1 \u7684\u706f\u6ce1\u7684\u72b6\u6001\u53cd\u8f6c\uff08k = 0, 1, 2, ...)
    8. \n
    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: n = 1, m = 1.\n\u8f93\u51fa: 2\n\u8bf4\u660e: \u72b6\u6001\u4e3a: [\u5f00], [\u5173]\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: n = 2, m = 1.\n\u8f93\u51fa: 3\n\u8bf4\u660e: \u72b6\u6001\u4e3a: [\u5f00, \u5173], [\u5173, \u5f00], [\u5173, \u5173]\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u8f93\u5165: n = 3, m = 1.\n\u8f93\u51fa: 4\n\u8bf4\u660e: \u72b6\u6001\u4e3a: [\u5173, \u5f00, \u5173], [\u5f00, \u5173, \u5f00], [\u5173, \u5173, \u5173], [\u5173, \u5f00, \u5f00].\n
    \n\n

    \u6ce8\u610f\uff1a n \u548c m \u90fd\u5c5e\u4e8e [0, 1000].

    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int flipLights(int n, int presses) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int flipLights(int n, int presses) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def flipLights(self, n, presses):\n \"\"\"\n :type n: int\n :type presses: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def flipLights(self, n: int, presses: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint flipLights(int n, int presses){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FlipLights(int n, int presses) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} presses\n * @return {number}\n */\nvar flipLights = function(n, presses) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} presses\n# @return {Integer}\ndef flip_lights(n, presses)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func flipLights(_ n: Int, _ presses: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func flipLights(n int, presses int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def flipLights(n: Int, presses: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun flipLights(n: Int, presses: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn flip_lights(n: i32, presses: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $presses\n * @return Integer\n */\n function flipLights($n, $presses) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function flipLights(n: number, presses: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (flip-lights n presses)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0672](https://leetcode-cn.com/problems/bulb-switcher-ii)", "[\u706f\u6ce1\u5f00\u5173 \u2161](/solution/0600-0699/0672.Bulb%20Switcher%20II/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0672](https://leetcode.com/problems/bulb-switcher-ii)", "[Bulb Switcher II](/solution/0600-0699/0672.Bulb%20Switcher%20II/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "0671", "frontend_question_id": "0671", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/second-minimum-node-in-a-binary-tree", "url_en": "https://leetcode.com/problems/second-minimum-node-in-a-binary-tree", "relative_path_cn": "/solution/0600-0699/0671.Second%20Minimum%20Node%20In%20a%20Binary%20Tree/README.md", "relative_path_en": "/solution/0600-0699/0671.Second%20Minimum%20Node%20In%20a%20Binary%20Tree/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u4e2d\u7b2c\u4e8c\u5c0f\u7684\u8282\u70b9", "title_en": "Second Minimum Node In a Binary Tree", "question_title_slug": "second-minimum-node-in-a-binary-tree", "content_en": "

    Given a non-empty special binary tree consisting of nodes with the non-negative value, where each node in this tree has exactly two or zero sub-node. If the node has two sub-nodes, then this node's value is the smaller value among its two sub-nodes. More formally, the property root.val = min(root.left.val, root.right.val) always holds.

    \n\n

    Given such a binary tree, you need to output the second minimum value in the set made of all the nodes' value in the whole tree.

    \n\n

    If no such second minimum value exists, output -1 instead.

    \n\n

     

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [2,2,5,null,null,5,7]\nOutput: 5\nExplanation: The smallest value is 2, the second smallest value is 5.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [2,2,2]\nOutput: -1\nExplanation: The smallest value is 2, but there isn't any second smallest value.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 25].
    • \n\t
    • 1 <= Node.val <= 231 - 1
    • \n\t
    • root.val == min(root.left.val, root.right.val) for each internal node of the tree.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u7a7a\u7279\u6b8a\u7684\u4e8c\u53c9\u6811\uff0c\u6bcf\u4e2a\u8282\u70b9\u90fd\u662f\u6b63\u6570\uff0c\u5e76\u4e14\u6bcf\u4e2a\u8282\u70b9\u7684\u5b50\u8282\u70b9\u6570\u91cf\u53ea\u80fd\u4e3a\u00a02\u00a0\u6216\u00a00\u3002\u5982\u679c\u4e00\u4e2a\u8282\u70b9\u6709\u4e24\u4e2a\u5b50\u8282\u70b9\u7684\u8bdd\uff0c\u90a3\u4e48\u8be5\u8282\u70b9\u7684\u503c\u7b49\u4e8e\u4e24\u4e2a\u5b50\u8282\u70b9\u4e2d\u8f83\u5c0f\u7684\u4e00\u4e2a\u3002

    \n\n

    \u66f4\u6b63\u5f0f\u5730\u8bf4\uff0croot.val = min(root.left.val, root.right.val) \u603b\u6210\u7acb\u3002

    \n\n

    \u7ed9\u51fa\u8fd9\u6837\u7684\u4e00\u4e2a\u4e8c\u53c9\u6811\uff0c\u4f60\u9700\u8981\u8f93\u51fa\u6240\u6709\u8282\u70b9\u4e2d\u7684\u7b2c\u4e8c\u5c0f\u7684\u503c\u3002\u5982\u679c\u7b2c\u4e8c\u5c0f\u7684\u503c\u4e0d\u5b58\u5728\u7684\u8bdd\uff0c\u8f93\u51fa -1 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [2,2,5,null,null,5,7]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u6700\u5c0f\u7684\u503c\u662f 2 \uff0c\u7b2c\u4e8c\u5c0f\u7684\u503c\u662f 5 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [2,2,2]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u6700\u5c0f\u7684\u503c\u662f 2, \u4f46\u662f\u4e0d\u5b58\u5728\u7b2c\u4e8c\u5c0f\u7684\u503c\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u6570\u76ee\u5728\u8303\u56f4 [1, 25] \u5185
    • \n\t
    • 1 <= Node.val <= 231 - 1
    • \n\t
    • \u5bf9\u4e8e\u6811\u4e2d\u6bcf\u4e2a\u8282\u70b9 root.val == min(root.left.val, root.right.val)
    • \n
    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int findSecondMinimumValue(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int findSecondMinimumValue(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def findSecondMinimumValue(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def findSecondMinimumValue(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint findSecondMinimumValue(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int FindSecondMinimumValue(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar findSecondMinimumValue = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef find_second_minimum_value(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func findSecondMinimumValue(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc findSecondMinimumValue(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def findSecondMinimumValue(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun findSecondMinimumValue(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn find_second_minimum_value(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function findSecondMinimumValue($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction findSecondMinimumValue(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (find-second-minimum-value root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0671](https://leetcode-cn.com/problems/second-minimum-node-in-a-binary-tree)", "[\u4e8c\u53c9\u6811\u4e2d\u7b2c\u4e8c\u5c0f\u7684\u8282\u70b9](/solution/0600-0699/0671.Second%20Minimum%20Node%20In%20a%20Binary%20Tree/README.md)", "`\u6811`", "\u7b80\u5355", ""], "md_table_row_en": ["[0671](https://leetcode.com/problems/second-minimum-node-in-a-binary-tree)", "[Second Minimum Node In a Binary Tree](/solution/0600-0699/0671.Second%20Minimum%20Node%20In%20a%20Binary%20Tree/README_EN.md)", "`Tree`", "Easy", ""]}, {"question_id": "0670", "frontend_question_id": "0670", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-swap", "url_en": "https://leetcode.com/problems/maximum-swap", "relative_path_cn": "/solution/0600-0699/0670.Maximum%20Swap/README.md", "relative_path_en": "/solution/0600-0699/0670.Maximum%20Swap/README_EN.md", "title_cn": "\u6700\u5927\u4ea4\u6362", "title_en": "Maximum Swap", "question_title_slug": "maximum-swap", "content_en": "

    You are given an integer num. You can swap two digits at most once to get the maximum valued number.

    \n\n

    Return the maximum valued number you can get.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: num = 2736\nOutput: 7236\nExplanation: Swap the number 2 and the number 7.\n
    \n\n

    Example 2:

    \n\n
    \nInput: num = 9973\nOutput: 9973\nExplanation: No swap.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= num <= 108
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\uff0c\u4f60\u81f3\u591a\u53ef\u4ee5\u4ea4\u6362\u4e00\u6b21\u6570\u5b57\u4e2d\u7684\u4efb\u610f\u4e24\u4f4d\u3002\u8fd4\u56de\u4f60\u80fd\u5f97\u5230\u7684\u6700\u5927\u503c\u3002

    \n\n

    \u793a\u4f8b 1 :

    \n\n
    \n\u8f93\u5165: 2736\n\u8f93\u51fa: 7236\n\u89e3\u91ca: \u4ea4\u6362\u6570\u5b572\u548c\u6570\u5b577\u3002\n
    \n\n

    \u793a\u4f8b 2 :

    \n\n
    \n\u8f93\u5165: 9973\n\u8f93\u51fa: 9973\n\u89e3\u91ca: \u4e0d\u9700\u8981\u4ea4\u6362\u3002\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u7ed9\u5b9a\u6570\u5b57\u7684\u8303\u56f4\u662f [0, 108]
    2. \n
    \n", "tags_en": ["Array", "Math"], "tags_cn": ["\u6570\u7ec4", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maximumSwap(int num) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maximumSwap(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximumSwap(self, num):\n \"\"\"\n :type num: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximumSwap(self, num: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maximumSwap(int num){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaximumSwap(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} num\n * @return {number}\n */\nvar maximumSwap = function(num) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} num\n# @return {Integer}\ndef maximum_swap(num)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximumSwap(_ num: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximumSwap(num int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximumSwap(num: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximumSwap(num: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximum_swap(num: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $num\n * @return Integer\n */\n function maximumSwap($num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximumSwap(num: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximum-swap num)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0670](https://leetcode-cn.com/problems/maximum-swap)", "[\u6700\u5927\u4ea4\u6362](/solution/0600-0699/0670.Maximum%20Swap/README.md)", "`\u6570\u7ec4`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0670](https://leetcode.com/problems/maximum-swap)", "[Maximum Swap](/solution/0600-0699/0670.Maximum%20Swap/README_EN.md)", "`Array`,`Math`", "Medium", ""]}, {"question_id": "0669", "frontend_question_id": "0669", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/trim-a-binary-search-tree", "url_en": "https://leetcode.com/problems/trim-a-binary-search-tree", "relative_path_cn": "/solution/0600-0699/0669.Trim%20a%20Binary%20Search%20Tree/README.md", "relative_path_en": "/solution/0600-0699/0669.Trim%20a%20Binary%20Search%20Tree/README_EN.md", "title_cn": "\u4fee\u526a\u4e8c\u53c9\u641c\u7d22\u6811", "title_en": "Trim a Binary Search Tree", "question_title_slug": "trim-a-binary-search-tree", "content_en": "

    Given the root of a binary search tree and the lowest and highest boundaries as low and high, trim the tree so that all its elements lies in [low, high]. Trimming the tree should not change the relative structure of the elements that will remain in the tree (i.e., any node's descendant should remain a descendant). It can be proven that there is a unique answer.

    \n\n

    Return the root of the trimmed binary search tree. Note that the root may change depending on the given bounds.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,0,2], low = 1, high = 2\nOutput: [1,null,2]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [3,0,4,null,2,null,null,1], low = 1, high = 3\nOutput: [3,2,null,1]\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = [1], low = 1, high = 2\nOutput: [1]\n
    \n\n

    Example 4:

    \n\n
    \nInput: root = [1,null,2], low = 1, high = 3\nOutput: [1,null,2]\n
    \n\n

    Example 5:

    \n\n
    \nInput: root = [1,null,2], low = 2, high = 4\nOutput: [2]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree in the range [1, 104].
    • \n\t
    • 0 <= Node.val <= 104
    • \n\t
    • The value of each node in the tree is unique.
    • \n\t
    • root is guaranteed to be a valid binary search tree.
    • \n\t
    • 0 <= low <= high <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6839\u8282\u70b9 root \uff0c\u540c\u65f6\u7ed9\u5b9a\u6700\u5c0f\u8fb9\u754clow \u548c\u6700\u5927\u8fb9\u754c high\u3002\u901a\u8fc7\u4fee\u526a\u4e8c\u53c9\u641c\u7d22\u6811\uff0c\u4f7f\u5f97\u6240\u6709\u8282\u70b9\u7684\u503c\u5728[low, high]\u4e2d\u3002\u4fee\u526a\u6811\u4e0d\u5e94\u8be5\u6539\u53d8\u4fdd\u7559\u5728\u6811\u4e2d\u7684\u5143\u7d20\u7684\u76f8\u5bf9\u7ed3\u6784\uff08\u5373\uff0c\u5982\u679c\u6ca1\u6709\u88ab\u79fb\u9664\uff0c\u539f\u6709\u7684\u7236\u4ee3\u5b50\u4ee3\u5173\u7cfb\u90fd\u5e94\u5f53\u4fdd\u7559\uff09\u3002 \u53ef\u4ee5\u8bc1\u660e\uff0c\u5b58\u5728\u552f\u4e00\u7684\u7b54\u6848\u3002

    \n\n

    \u6240\u4ee5\u7ed3\u679c\u5e94\u5f53\u8fd4\u56de\u4fee\u526a\u597d\u7684\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u65b0\u7684\u6839\u8282\u70b9\u3002\u6ce8\u610f\uff0c\u6839\u8282\u70b9\u53ef\u80fd\u4f1a\u6839\u636e\u7ed9\u5b9a\u7684\u8fb9\u754c\u53d1\u751f\u6539\u53d8\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [1,0,2], low = 1, high = 2\n\u8f93\u51fa\uff1a[1,null,2]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [3,0,4,null,2,null,null,1], low = 1, high = 3\n\u8f93\u51fa\uff1a[3,2,null,1]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [1], low = 1, high = 2\n\u8f93\u51fa\uff1a[1]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [1,null,2], low = 1, high = 3\n\u8f93\u51fa\uff1a[1,null,2]\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [1,null,2], low = 2, high = 4\n\u8f93\u51fa\uff1a[2]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u6570\u5728\u8303\u56f4 [1, 104] \u5185
    • \n\t
    • 0 <= Node.val <= 104
    • \n\t
    • \u6811\u4e2d\u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u90fd\u662f\u552f\u4e00\u7684
    • \n\t
    • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u8f93\u5165\u662f\u4e00\u68f5\u6709\u6548\u7684\u4e8c\u53c9\u641c\u7d22\u6811
    • \n\t
    • 0 <= low <= high <= 104
    • \n
    \n", "tags_en": ["Tree", "Recursion"], "tags_cn": ["\u6811", "\u9012\u5f52"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* trimBST(TreeNode* root, int low, int high) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode trimBST(TreeNode root, int low, int high) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def trimBST(self, root, low, high):\n \"\"\"\n :type root: TreeNode\n :type low: int\n :type high: int\n :rtype: TreeNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def trimBST(self, root: TreeNode, low: int, high: int) -> TreeNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* trimBST(struct TreeNode* root, int low, int high){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode TrimBST(TreeNode root, int low, int high) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number} low\n * @param {number} high\n * @return {TreeNode}\n */\nvar trimBST = function(root, low, high) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @param {Integer} low\n# @param {Integer} high\n# @return {TreeNode}\ndef trim_bst(root, low, high)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func trimBST(_ root: TreeNode?, _ low: Int, _ high: Int) -> TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc trimBST(root *TreeNode, low int, high int) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def trimBST(root: TreeNode, low: Int, high: Int): TreeNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun trimBST(root: TreeNode?, low: Int, high: Int): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn trim_bst(root: Option>>, low: i32, high: i32) -> Option>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param Integer $low\n * @param Integer $high\n * @return TreeNode\n */\n function trimBST($root, $low, $high) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction trimBST(root: TreeNode | null, low: number, high: number): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (trim-bst root low high)\n (-> (or/c tree-node? #f) exact-integer? exact-integer? (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0669](https://leetcode-cn.com/problems/trim-a-binary-search-tree)", "[\u4fee\u526a\u4e8c\u53c9\u641c\u7d22\u6811](/solution/0600-0699/0669.Trim%20a%20Binary%20Search%20Tree/README.md)", "`\u6811`,`\u9012\u5f52`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0669](https://leetcode.com/problems/trim-a-binary-search-tree)", "[Trim a Binary Search Tree](/solution/0600-0699/0669.Trim%20a%20Binary%20Search%20Tree/README_EN.md)", "`Tree`,`Recursion`", "Medium", ""]}, {"question_id": "0668", "frontend_question_id": "0668", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/kth-smallest-number-in-multiplication-table", "url_en": "https://leetcode.com/problems/kth-smallest-number-in-multiplication-table", "relative_path_cn": "/solution/0600-0699/0668.Kth%20Smallest%20Number%20in%20Multiplication%20Table/README.md", "relative_path_en": "/solution/0600-0699/0668.Kth%20Smallest%20Number%20in%20Multiplication%20Table/README_EN.md", "title_cn": "\u4e58\u6cd5\u8868\u4e2d\u7b2ck\u5c0f\u7684\u6570", "title_en": "Kth Smallest Number in Multiplication Table", "question_title_slug": "kth-smallest-number-in-multiplication-table", "content_en": "

    Nearly everyone has used the Multiplication Table. The multiplication table of size m x n is an integer matrix mat where mat[i][j] == i * j (1-indexed).

    \n\n

    Given three integers m, n, and k, return the kth smallest element in the m x n multiplication table.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: m = 3, n = 3, k = 5\nOutput: 3\nExplanation: The 5th smallest number is 3.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: m = 2, n = 3, k = 6\nOutput: 6\nExplanation: The 6th smallest number is 6.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= m, n <= 3 * 104
    • \n\t
    • 1 <= k <= m * n
    • \n
    \n", "content_cn": "

    \u51e0\u4e4e\u6bcf\u4e00\u4e2a\u4eba\u90fd\u7528 \u4e58\u6cd5\u8868\u3002\u4f46\u662f\u4f60\u80fd\u5728\u4e58\u6cd5\u8868\u4e2d\u5feb\u901f\u627e\u5230\u7b2ck\u5c0f\u7684\u6570\u5b57\u5417\uff1f

    \n\n

    \u7ed9\u5b9a\u9ad8\u5ea6m \u3001\u5bbd\u5ea6n \u7684\u4e00\u5f20 m * n\u7684\u4e58\u6cd5\u8868\uff0c\u4ee5\u53ca\u6b63\u6574\u6570k\uff0c\u4f60\u9700\u8981\u8fd4\u56de\u8868\u4e2d\u7b2ck \u5c0f\u7684\u6570\u5b57\u3002

    \n\n

    \u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165: m = 3, n = 3, k = 5\n\u8f93\u51fa: 3\n\u89e3\u91ca: \n\u4e58\u6cd5\u8868:\n1\t2\t3\n2\t4\t6\n3\t6\t9\n\n\u7b2c5\u5c0f\u7684\u6570\u5b57\u662f 3 (1, 2, 2, 3, 3).\n
    \n\n

    \u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165: m = 2, n = 3, k = 6\n\u8f93\u51fa: 6\n\u89e3\u91ca: \n\u4e58\u6cd5\u8868:\n1\t2\t3\n2\t4\t6\n\n\u7b2c6\u5c0f\u7684\u6570\u5b57\u662f 6 (1, 2, 2, 3, 4, 6).\n
    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    1. m \u548c n \u7684\u8303\u56f4\u5728 [1, 30000] \u4e4b\u95f4\u3002
    2. \n\t
    3. k \u7684\u8303\u56f4\u5728 [1, m * n] \u4e4b\u95f4\u3002
    4. \n
    \n", "tags_en": ["Binary Search"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findKthNumber(int m, int n, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findKthNumber(int m, int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findKthNumber(self, m, n, k):\n \"\"\"\n :type m: int\n :type n: int\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findKthNumber(self, m: int, n: int, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findKthNumber(int m, int n, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindKthNumber(int m, int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} m\n * @param {number} n\n * @param {number} k\n * @return {number}\n */\nvar findKthNumber = function(m, n, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} m\n# @param {Integer} n\n# @param {Integer} k\n# @return {Integer}\ndef find_kth_number(m, n, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findKthNumber(_ m: Int, _ n: Int, _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findKthNumber(m int, n int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findKthNumber(m: Int, n: Int, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findKthNumber(m: Int, n: Int, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_kth_number(m: i32, n: i32, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $m\n * @param Integer $n\n * @param Integer $k\n * @return Integer\n */\n function findKthNumber($m, $n, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findKthNumber(m: number, n: number, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-kth-number m n k)\n (-> exact-integer? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0668](https://leetcode-cn.com/problems/kth-smallest-number-in-multiplication-table)", "[\u4e58\u6cd5\u8868\u4e2d\u7b2ck\u5c0f\u7684\u6570](/solution/0600-0699/0668.Kth%20Smallest%20Number%20in%20Multiplication%20Table/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u56f0\u96be", ""], "md_table_row_en": ["[0668](https://leetcode.com/problems/kth-smallest-number-in-multiplication-table)", "[Kth Smallest Number in Multiplication Table](/solution/0600-0699/0668.Kth%20Smallest%20Number%20in%20Multiplication%20Table/README_EN.md)", "`Binary Search`", "Hard", ""]}, {"question_id": "0667", "frontend_question_id": "0667", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/beautiful-arrangement-ii", "url_en": "https://leetcode.com/problems/beautiful-arrangement-ii", "relative_path_cn": "/solution/0600-0699/0667.Beautiful%20Arrangement%20II/README.md", "relative_path_en": "/solution/0600-0699/0667.Beautiful%20Arrangement%20II/README_EN.md", "title_cn": "\u4f18\u7f8e\u7684\u6392\u5217 II", "title_en": "Beautiful Arrangement II", "question_title_slug": "beautiful-arrangement-ii", "content_en": "

    Given two integers n and k, construct a list answer that contains n different positive integers ranging from 1 to n and obeys the following requirement:

    \n\n
      \n\t
    • Suppose this list is answer = [a1, a2, a3, ... , an], then the list [|a1 - a2|, |a2 - a3|, |a3 - a4|, ... , |an-1 - an|] has exactly k distinct integers.
    • \n
    \n\n

    Return the list answer. If there multiple valid answers, return any of them.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 3, k = 1\nOutput: [1,2,3]\nExplanation: The [1,2,3] has three different positive integers ranging from 1 to 3, and the [1,1] has exactly 1 distinct integer: 1\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 3, k = 2\nOutput: [1,3,2]\nExplanation: The [1,3,2] has three different positive integers ranging from 1 to 3, and the [2,1] has exactly 2 distinct integers: 1 and 2.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= k < n <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u6574\u6570 n \u548c k \uff0c\u8bf7\u4f60\u6784\u9020\u4e00\u4e2a\u7b54\u6848\u5217\u8868 answer \uff0c\u8be5\u5217\u8868\u5e94\u5f53\u5305\u542b\u4ece 1 \u5230 n \u7684 n \u4e2a\u4e0d\u540c\u6b63\u6574\u6570\uff0c\u5e76\u540c\u65f6\u6ee1\u8db3\u4e0b\u8ff0\u6761\u4ef6\uff1a

    \n\n
      \n\t
    • \u5047\u8bbe\u8be5\u5217\u8868\u662f answer =\u00a0[a1, a2, a3, ... , an] \uff0c\u90a3\u4e48\u5217\u8868 [|a1 - a2|, |a2 - a3|, |a3 - a4|, ... , |an-1 - an|] \u4e2d\u5e94\u8be5\u6709\u4e14\u4ec5\u6709 k \u4e2a\u4e0d\u540c\u6574\u6570\u3002
    • \n
    \n\n

    \u8fd4\u56de\u5217\u8868 answer \u3002\u5982\u679c\u5b58\u5728\u591a\u79cd\u7b54\u6848\uff0c\u53ea\u9700\u8fd4\u56de\u5176\u4e2d \u4efb\u610f\u4e00\u79cd \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 3, k = 1\n\u8f93\u51fa\uff1a[1, 2, 3]\n\u89e3\u91ca\uff1a[1, 2, 3] \u5305\u542b 3 \u4e2a\u8303\u56f4\u5728 1-3 \u7684\u4e0d\u540c\u6574\u6570\uff0c\u5e76\u4e14 [1, 1] \u4e2d\u6709\u4e14\u4ec5\u6709 1 \u4e2a\u4e0d\u540c\u6574\u6570\uff1a1\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 3, k = 2\n\u8f93\u51fa\uff1a[1, 3, 2]\n\u89e3\u91ca\uff1a[1, 3, 2] \u5305\u542b 3 \u4e2a\u8303\u56f4\u5728 1-3 \u7684\u4e0d\u540c\u6574\u6570\uff0c\u5e76\u4e14 [2, 1] \u4e2d\u6709\u4e14\u4ec5\u6709 2 \u4e2a\u4e0d\u540c\u6574\u6570\uff1a1 \u548c 2\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= k < n <= 104
    • \n
    \n\n

    \u00a0

    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector constructArray(int n, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] constructArray(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def constructArray(self, n, k):\n \"\"\"\n :type n: int\n :type k: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def constructArray(self, n: int, k: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* constructArray(int n, int k, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] ConstructArray(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} k\n * @return {number[]}\n */\nvar constructArray = function(n, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} k\n# @return {Integer[]}\ndef construct_array(n, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func constructArray(_ n: Int, _ k: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func constructArray(n int, k int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def constructArray(n: Int, k: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun constructArray(n: Int, k: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn construct_array(n: i32, k: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $k\n * @return Integer[]\n */\n function constructArray($n, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function constructArray(n: number, k: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (construct-array n k)\n (-> exact-integer? exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0667](https://leetcode-cn.com/problems/beautiful-arrangement-ii)", "[\u4f18\u7f8e\u7684\u6392\u5217 II](/solution/0600-0699/0667.Beautiful%20Arrangement%20II/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0667](https://leetcode.com/problems/beautiful-arrangement-ii)", "[Beautiful Arrangement II](/solution/0600-0699/0667.Beautiful%20Arrangement%20II/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0666", "frontend_question_id": "0666", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/path-sum-iv", "url_en": "https://leetcode.com/problems/path-sum-iv", "relative_path_cn": "/solution/0600-0699/0666.Path%20Sum%20IV/README.md", "relative_path_en": "/solution/0600-0699/0666.Path%20Sum%20IV/README_EN.md", "title_cn": "\u8def\u5f84\u603b\u548c IV", "title_en": "Path Sum IV", "question_title_slug": "path-sum-iv", "content_en": "

    If the depth of a tree is smaller than 5, then this tree can be represented by an array of three-digit integers. For each integer in this array:

    \n\n
      \n\t
    • The hundreds digit represents the depth d of this node where 1 <= d <= 4.
    • \n\t
    • The tens digit represents the position p of this node in the level it belongs to where 1 <= p <= 8. The position is the same as that in a full binary tree.
    • \n\t
    • The units digit represents the value v of this node where 0 <= v <= 9.
    • \n
    \n\n

    Given an array of ascending three-digit integers nums representing a binary tree with a depth smaller than 5, return the sum of all paths from the root towards the leaves.

    \n\n

    It is guaranteed that the given array represents a valid connected binary tree.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: nums = [113,215,221]\nOutput: 12\nExplanation: The tree that the list represents is shown.\nThe path sum is (3 + 5) + (3 + 1) = 12.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: nums = [113,221]\nOutput: 4\nExplanation: The tree that the list represents is shown. \nThe path sum is (3 + 1) = 4.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 15
    • \n\t
    • 110 <= nums[i] <= 489
    • \n\t
    • nums represents a valid binary tree with depth less than 5.
    • \n
    \n", "content_cn": "

    \u5bf9\u4e8e\u4e00\u68f5\u6df1\u5ea6\u5c0f\u4e8e\u00a05\u00a0\u7684\u6811\uff0c\u53ef\u4ee5\u7528\u4e00\u7ec4\u4e09\u4f4d\u5341\u8fdb\u5236\u6574\u6570\u6765\u8868\u793a\u3002

    \n\n

    \u5bf9\u4e8e\u6bcf\u4e2a\u6574\u6570\uff1a

    \n\n
      \n\t
    1. \u767e\u4f4d\u4e0a\u7684\u6570\u5b57\u8868\u793a\u8fd9\u4e2a\u8282\u70b9\u7684\u6df1\u5ea6 D\uff0c1 <= D <= 4\u3002
    2. \n\t
    3. \u5341\u4f4d\u4e0a\u7684\u6570\u5b57\u8868\u793a\u8fd9\u4e2a\u8282\u70b9\u5728\u5f53\u524d\u5c42\u6240\u5728\u7684\u4f4d\u7f6e P\uff0c 1 <= P <= 8\u3002\u4f4d\u7f6e\u7f16\u53f7\u4e0e\u4e00\u68f5\u6ee1\u4e8c\u53c9\u6811\u7684\u4f4d\u7f6e\u7f16\u53f7\u76f8\u540c\u3002
    4. \n\t
    5. \u4e2a\u4f4d\u4e0a\u7684\u6570\u5b57\u8868\u793a\u8fd9\u4e2a\u8282\u70b9\u7684\u6743\u503c V\uff0c0 <= V <= 9\u3002
    6. \n
    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u5305\u542b\u4e09\u4f4d\u6574\u6570\u7684\u5347\u5e8f\u6570\u7ec4\uff0c\u8868\u793a\u4e00\u68f5\u6df1\u5ea6\u5c0f\u4e8e 5 \u7684\u4e8c\u53c9\u6811\uff0c\u8bf7\u4f60\u8fd4\u56de\u4ece\u6839\u5230\u6240\u6709\u53f6\u5b50\u7ed3\u70b9\u7684\u8def\u5f84\u4e4b\u548c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165: [113, 215, 221]\n\u8f93\u51fa: 12\n\u89e3\u91ca: \n\u8fd9\u68f5\u6811\u5f62\u72b6\u5982\u4e0b:\n    3\n   / \\\n  5   1\n\n\u8def\u5f84\u548c = (3 + 5) + (3 + 1) = 12.\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165: [113, 221]\n\u8f93\u51fa: 4\n\u89e3\u91ca: \n\u8fd9\u68f5\u6811\u5f62\u72b6\u5982\u4e0b: \n    3\n     \\\n      1\n\n\u8def\u5f84\u548c = (3 + 1) = 4.\n
    \n\n

    \u00a0

    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int pathSum(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int pathSum(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def pathSum(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def pathSum(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint pathSum(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int PathSum(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar pathSum = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef path_sum(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func pathSum(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func pathSum(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def pathSum(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun pathSum(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn path_sum(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function pathSum($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function pathSum(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (path-sum nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0666](https://leetcode-cn.com/problems/path-sum-iv)", "[\u8def\u5f84\u603b\u548c IV](/solution/0600-0699/0666.Path%20Sum%20IV/README.md)", "`\u6811`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0666](https://leetcode.com/problems/path-sum-iv)", "[Path Sum IV](/solution/0600-0699/0666.Path%20Sum%20IV/README_EN.md)", "`Tree`", "Medium", "\ud83d\udd12"]}, {"question_id": "0665", "frontend_question_id": "0665", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/non-decreasing-array", "url_en": "https://leetcode.com/problems/non-decreasing-array", "relative_path_cn": "/solution/0600-0699/0665.Non-decreasing%20Array/README.md", "relative_path_en": "/solution/0600-0699/0665.Non-decreasing%20Array/README_EN.md", "title_cn": "\u975e\u9012\u51cf\u6570\u5217", "title_en": "Non-decreasing Array", "question_title_slug": "non-decreasing-array", "content_en": "

    Given an array nums with n integers, your task is to check if it could become non-decreasing by modifying at most one element.

    \n\n

    We define an array is non-decreasing if nums[i] <= nums[i + 1] holds for every i (0-based) such that (0 <= i <= n - 2).

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [4,2,3]\nOutput: true\nExplanation: You could modify the first 4 to 1 to get a non-decreasing array.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [4,2,1]\nOutput: false\nExplanation: You can't get a non-decreasing array by modify at most one element.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= n <= 104
    • \n\t
    • -105 <= nums[i] <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u4e3a\u00a0n\u00a0\u7684\u6574\u6570\u6570\u7ec4\uff0c\u8bf7\u4f60\u5224\u65ad\u5728 \u6700\u591a \u6539\u53d8\u00a01 \u4e2a\u5143\u7d20\u7684\u60c5\u51b5\u4e0b\uff0c\u8be5\u6570\u7ec4\u80fd\u5426\u53d8\u6210\u4e00\u4e2a\u975e\u9012\u51cf\u6570\u5217\u3002

    \n\n

    \u6211\u4eec\u662f\u8fd9\u6837\u5b9a\u4e49\u4e00\u4e2a\u975e\u9012\u51cf\u6570\u5217\u7684\uff1a\u00a0\u5bf9\u4e8e\u6570\u7ec4\u4e2d\u4efb\u610f\u7684\u00a0i (0 <= i <= n-2)\uff0c\u603b\u6ee1\u8db3 nums[i] <= nums[i + 1]\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: nums = [4,2,3]\n\u8f93\u51fa: true\n\u89e3\u91ca: \u4f60\u53ef\u4ee5\u901a\u8fc7\u628a\u7b2c\u4e00\u4e2a4\u53d8\u62101\u6765\u4f7f\u5f97\u5b83\u6210\u4e3a\u4e00\u4e2a\u975e\u9012\u51cf\u6570\u5217\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: nums = [4,2,1]\n\u8f93\u51fa: false\n\u89e3\u91ca: \u4f60\u4e0d\u80fd\u5728\u53ea\u6539\u53d8\u4e00\u4e2a\u5143\u7d20\u7684\u60c5\u51b5\u4e0b\u5c06\u5176\u53d8\u4e3a\u975e\u9012\u51cf\u6570\u5217\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 10 ^ 4
    • \n\t
    • - 10 ^ 5\u00a0<= nums[i] <= 10 ^ 5
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool checkPossibility(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean checkPossibility(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def checkPossibility(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def checkPossibility(self, nums: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool checkPossibility(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CheckPossibility(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {boolean}\n */\nvar checkPossibility = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Boolean}\ndef check_possibility(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func checkPossibility(_ nums: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func checkPossibility(nums []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def checkPossibility(nums: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun checkPossibility(nums: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn check_possibility(nums: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Boolean\n */\n function checkPossibility($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function checkPossibility(nums: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (check-possibility nums)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0665](https://leetcode-cn.com/problems/non-decreasing-array)", "[\u975e\u9012\u51cf\u6570\u5217](/solution/0600-0699/0665.Non-decreasing%20Array/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0665](https://leetcode.com/problems/non-decreasing-array)", "[Non-decreasing Array](/solution/0600-0699/0665.Non-decreasing%20Array/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0664", "frontend_question_id": "0664", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/strange-printer", "url_en": "https://leetcode.com/problems/strange-printer", "relative_path_cn": "/solution/0600-0699/0664.Strange%20Printer/README.md", "relative_path_en": "/solution/0600-0699/0664.Strange%20Printer/README_EN.md", "title_cn": "\u5947\u602a\u7684\u6253\u5370\u673a", "title_en": "Strange Printer", "question_title_slug": "strange-printer", "content_en": "

    There is a strange printer with the following two special properties:

    \n\n
      \n\t
    • The printer can only print a sequence of the same character each time.
    • \n\t
    • At each turn, the printer can print new characters starting from and ending at any place and will cover the original existing characters.
    • \n
    \n\n

    Given a string s, return the minimum number of turns the printer needed to print it.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "aaabbb"\nOutput: 2\nExplanation: Print "aaa" first and then print "bbb".\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "aba"\nOutput: 2\nExplanation: Print "aaa" first and then print "b" from the second place of the string, which will cover the existing character 'a'.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 100
    • \n\t
    • s consists of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u6709\u53f0\u5947\u602a\u7684\u6253\u5370\u673a\u6709\u4ee5\u4e0b\u4e24\u4e2a\u7279\u6b8a\u8981\u6c42\uff1a

    \n\n
      \n\t
    • \u6253\u5370\u673a\u6bcf\u6b21\u53ea\u80fd\u6253\u5370\u7531 \u540c\u4e00\u4e2a\u5b57\u7b26 \u7ec4\u6210\u7684\u5e8f\u5217\u3002
    • \n\t
    • \u6bcf\u6b21\u53ef\u4ee5\u5728\u4efb\u610f\u8d77\u59cb\u548c\u7ed3\u675f\u4f4d\u7f6e\u6253\u5370\u65b0\u5b57\u7b26\uff0c\u5e76\u4e14\u4f1a\u8986\u76d6\u6389\u539f\u6765\u5df2\u6709\u7684\u5b57\u7b26\u3002
    • \n
    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \uff0c\u4f60\u7684\u4efb\u52a1\u662f\u8ba1\u7b97\u8fd9\u4e2a\u6253\u5370\u673a\u6253\u5370\u5b83\u9700\u8981\u7684\u6700\u5c11\u6253\u5370\u6b21\u6570\u3002

    \n\u00a0\n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"aaabbb\"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u9996\u5148\u6253\u5370 \"aaa\" \u7136\u540e\u6253\u5370 \"bbb\"\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"aba\"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u9996\u5148\u6253\u5370 \"aaa\" \u7136\u540e\u5728\u7b2c\u4e8c\u4e2a\u4f4d\u7f6e\u6253\u5370 \"b\" \u8986\u76d6\u6389\u539f\u6765\u7684\u5b57\u7b26 'a'\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 100
    • \n\t
    • s \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n", "tags_en": ["Depth-first Search", "Dynamic Programming"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int strangePrinter(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int strangePrinter(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def strangePrinter(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def strangePrinter(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint strangePrinter(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int StrangePrinter(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar strangePrinter = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef strange_printer(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func strangePrinter(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func strangePrinter(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def strangePrinter(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun strangePrinter(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn strange_printer(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function strangePrinter($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function strangePrinter(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (strange-printer s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0664](https://leetcode-cn.com/problems/strange-printer)", "[\u5947\u602a\u7684\u6253\u5370\u673a](/solution/0600-0699/0664.Strange%20Printer/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0664](https://leetcode.com/problems/strange-printer)", "[Strange Printer](/solution/0600-0699/0664.Strange%20Printer/README_EN.md)", "`Depth-first Search`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0663", "frontend_question_id": "0663", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/equal-tree-partition", "url_en": "https://leetcode.com/problems/equal-tree-partition", "relative_path_cn": "/solution/0600-0699/0663.Equal%20Tree%20Partition/README.md", "relative_path_en": "/solution/0600-0699/0663.Equal%20Tree%20Partition/README_EN.md", "title_cn": "\u5747\u5300\u6811\u5212\u5206", "title_en": "Equal Tree Partition", "question_title_slug": "equal-tree-partition", "content_en": "

    Given the root of a binary tree, return true if you can partition the tree into two trees with equal sums of values after removing exactly one edge on the original tree.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [5,10,10,null,null,2,3]\nOutput: true\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [1,2,10,null,null,2,20]\nOutput: false\nExplanation: You cannot split the tree into two trees with equal sums after removing exactly one edge on the tree.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 104].
    • \n\t
    • -105 <= Node.val <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u68f5\u6709 n \u4e2a\u7ed3\u70b9\u7684\u4e8c\u53c9\u6811\uff0c\u4f60\u7684\u4efb\u52a1\u662f\u68c0\u67e5\u662f\u5426\u53ef\u4ee5\u901a\u8fc7\u53bb\u6389\u6811\u4e0a\u7684\u4e00\u6761\u8fb9\u5c06\u6811\u5206\u6210\u4e24\u68f5\uff0c\u4e14\u8fd9\u4e24\u68f5\u6811\u7ed3\u70b9\u4e4b\u548c\u76f8\u7b49\u3002

    \n\n

    \u6837\u4f8b 1:

    \n\n
    \u8f93\u5165:     \n    5\n   / \\\n  10 10\n    /  \\\n   2   3\n\n\u8f93\u51fa: True\n\u89e3\u91ca: \n    5\n   / \n  10\n      \n\u548c: 15\n\n   10\n  /  \\\n 2    3\n\n\u548c: 15\n
    \n\n

     

    \n\n

    \u6837\u4f8b 2:

    \n\n
    \u8f93\u5165:     \n    1\n   / \\\n  2  10\n    /  \\\n   2   20\n\n\u8f93\u51fa: False\n\u89e3\u91ca: \u65e0\u6cd5\u901a\u8fc7\u79fb\u9664\u4e00\u6761\u6811\u8fb9\u5c06\u8fd9\u68f5\u6811\u5212\u5206\u6210\u7ed3\u70b9\u4e4b\u548c\u76f8\u7b49\u7684\u4e24\u68f5\u5b50\u6811\u3002\n
    \n\n

     

    \n\n

    \u6ce8\u91ca :

    \n\n
      \n\t
    1. \u6811\u4e0a\u7ed3\u70b9\u7684\u6743\u503c\u8303\u56f4 [-100000, 100000]\u3002
    2. \n\t
    3. 1 <= n <= 10000
    4. \n
    \n\n

     

    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n bool checkEqualTree(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public boolean checkEqualTree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def checkEqualTree(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def checkEqualTree(self, root: TreeNode) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nbool checkEqualTree(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public bool CheckEqualTree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {boolean}\n */\nvar checkEqualTree = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Boolean}\ndef check_equal_tree(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func checkEqualTree(_ root: TreeNode?) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc checkEqualTree(root *TreeNode) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def checkEqualTree(root: TreeNode): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun checkEqualTree(root: TreeNode?): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn check_equal_tree(root: Option>>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Boolean\n */\n function checkEqualTree($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction checkEqualTree(root: TreeNode | null): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (check-equal-tree root)\n (-> (or/c tree-node? #f) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0663](https://leetcode-cn.com/problems/equal-tree-partition)", "[\u5747\u5300\u6811\u5212\u5206](/solution/0600-0699/0663.Equal%20Tree%20Partition/README.md)", "`\u6811`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0663](https://leetcode.com/problems/equal-tree-partition)", "[Equal Tree Partition](/solution/0600-0699/0663.Equal%20Tree%20Partition/README_EN.md)", "`Tree`", "Medium", "\ud83d\udd12"]}, {"question_id": "0662", "frontend_question_id": "0662", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-width-of-binary-tree", "url_en": "https://leetcode.com/problems/maximum-width-of-binary-tree", "relative_path_cn": "/solution/0600-0699/0662.Maximum%20Width%20of%20Binary%20Tree/README.md", "relative_path_en": "/solution/0600-0699/0662.Maximum%20Width%20of%20Binary%20Tree/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u6700\u5927\u5bbd\u5ea6", "title_en": "Maximum Width of Binary Tree", "question_title_slug": "maximum-width-of-binary-tree", "content_en": "

    Given the root of a binary tree, return the maximum width of the given tree.

    \n\n

    The maximum width of a tree is the maximum width among all levels.

    \n\n

    The width of one level is defined as the length between the end-nodes (the leftmost and rightmost non-null nodes), where the null nodes between the end-nodes are also counted into the length calculation.

    \n\n

    It is guaranteed that the answer will in the range of 32-bit signed integer.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,3,2,5,3,null,9]\nOutput: 4\nExplanation: The maximum width existing in the third level with the length 4 (5,3,null,9).\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [1,3,null,5,3]\nOutput: 2\nExplanation: The maximum width existing in the third level with the length 2 (5,3).\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: root = [1,3,2,5]\nOutput: 2\nExplanation: The maximum width existing in the second level with the length 2 (3,2).\n
    \n\n

    Example 4:

    \n\"\"\n
    \nInput: root = [1,3,2,5,null,null,9,6,null,null,7]\nOutput: 8\nExplanation: The maximum width existing in the fourth level with the length 8 (6,null,null,null,null,null,null,7).\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 3000].
    • \n\t
    • -100 <= Node.val <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811\uff0c\u7f16\u5199\u4e00\u4e2a\u51fd\u6570\u6765\u83b7\u53d6\u8fd9\u4e2a\u6811\u7684\u6700\u5927\u5bbd\u5ea6\u3002\u6811\u7684\u5bbd\u5ea6\u662f\u6240\u6709\u5c42\u4e2d\u7684\u6700\u5927\u5bbd\u5ea6\u3002\u8fd9\u4e2a\u4e8c\u53c9\u6811\u4e0e\u6ee1\u4e8c\u53c9\u6811\uff08full binary tree\uff09\u7ed3\u6784\u76f8\u540c\uff0c\u4f46\u4e00\u4e9b\u8282\u70b9\u4e3a\u7a7a\u3002

    \n\n

    \u6bcf\u4e00\u5c42\u7684\u5bbd\u5ea6\u88ab\u5b9a\u4e49\u4e3a\u4e24\u4e2a\u7aef\u70b9\uff08\u8be5\u5c42\u6700\u5de6\u548c\u6700\u53f3\u7684\u975e\u7a7a\u8282\u70b9\uff0c\u4e24\u7aef\u70b9\u95f4\u7684null\u8282\u70b9\u4e5f\u8ba1\u5165\u957f\u5ea6\uff09\u4e4b\u95f4\u7684\u957f\u5ea6\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: \n\n           1\n         /   \\\n        3     2\n       / \\     \\  \n      5   3     9 \n\n\u8f93\u51fa: 4\n\u89e3\u91ca: \u6700\u5927\u503c\u51fa\u73b0\u5728\u6811\u7684\u7b2c 3 \u5c42\uff0c\u5bbd\u5ea6\u4e3a 4 (5,3,null,9)\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: \n\n          1\n         /  \n        3    \n       / \\       \n      5   3     \n\n\u8f93\u51fa: 2\n\u89e3\u91ca: \u6700\u5927\u503c\u51fa\u73b0\u5728\u6811\u7684\u7b2c 3 \u5c42\uff0c\u5bbd\u5ea6\u4e3a 2 (5,3)\u3002\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \n\u8f93\u5165: \n\n          1\n         / \\\n        3   2 \n       /        \n      5      \n\n\u8f93\u51fa: 2\n\u89e3\u91ca: \u6700\u5927\u503c\u51fa\u73b0\u5728\u6811\u7684\u7b2c 2 \u5c42\uff0c\u5bbd\u5ea6\u4e3a 2 (3,2)\u3002\n
    \n\n

    \u793a\u4f8b 4:

    \n\n
    \n\u8f93\u5165: \n\n          1\n         / \\\n        3   2\n       /     \\  \n      5       9 \n     /         \\\n    6           7\n\u8f93\u51fa: 8\n\u89e3\u91ca: \u6700\u5927\u503c\u51fa\u73b0\u5728\u6811\u7684\u7b2c 4 \u5c42\uff0c\u5bbd\u5ea6\u4e3a 8 (6,null,null,null,null,null,null,7)\u3002\n
    \n\n

    \u6ce8\u610f: \u7b54\u6848\u572832\u4f4d\u6709\u7b26\u53f7\u6574\u6570\u7684\u8868\u793a\u8303\u56f4\u5185\u3002

    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int widthOfBinaryTree(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int widthOfBinaryTree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def widthOfBinaryTree(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def widthOfBinaryTree(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint widthOfBinaryTree(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int WidthOfBinaryTree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar widthOfBinaryTree = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef width_of_binary_tree(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func widthOfBinaryTree(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc widthOfBinaryTree(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def widthOfBinaryTree(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun widthOfBinaryTree(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn width_of_binary_tree(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function widthOfBinaryTree($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction widthOfBinaryTree(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (width-of-binary-tree root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0662](https://leetcode-cn.com/problems/maximum-width-of-binary-tree)", "[\u4e8c\u53c9\u6811\u6700\u5927\u5bbd\u5ea6](/solution/0600-0699/0662.Maximum%20Width%20of%20Binary%20Tree/README.md)", "`\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0662](https://leetcode.com/problems/maximum-width-of-binary-tree)", "[Maximum Width of Binary Tree](/solution/0600-0699/0662.Maximum%20Width%20of%20Binary%20Tree/README_EN.md)", "`Tree`", "Medium", ""]}, {"question_id": "0661", "frontend_question_id": "0661", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/image-smoother", "url_en": "https://leetcode.com/problems/image-smoother", "relative_path_cn": "/solution/0600-0699/0661.Image%20Smoother/README.md", "relative_path_en": "/solution/0600-0699/0661.Image%20Smoother/README_EN.md", "title_cn": "\u56fe\u7247\u5e73\u6ed1\u5668", "title_en": "Image Smoother", "question_title_slug": "image-smoother", "content_en": "

    An image smoother is a filter of the size 3 x 3 that can be applied to each cell of an image by rounding down the average of the cell and the eight surrounding cells (i.e., the average of the nine cells in the blue smoother). If one or more of the surrounding cells of a cell is not present, we do not consider it in the average (i.e., the average of the four cells in the red smoother).

    \n\"\"\n

    Given an m x n integer matrix img representing the grayscale of an image, return the image after applying the smoother on each cell of it.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: img = [[1,1,1],[1,0,1],[1,1,1]]\nOutput: [[0,0,0],[0,0,0],[0,0,0]]\nExplanation:\nFor the points (0,0), (0,2), (2,0), (2,2): floor(3/4) = floor(0.75) = 0\nFor the points (0,1), (1,0), (1,2), (2,1): floor(5/6) = floor(0.83333333) = 0\nFor the point (1,1): floor(8/9) = floor(0.88888889) = 0\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: img = [[100,200,100],[200,50,200],[100,200,100]]\nOutput: [[137,141,137],[141,138,141],[137,141,137]]\nExplanation:\nFor the points (0,0), (0,2), (2,0), (2,2): floor((100+200+200+50)/4) = floor(137.5) = 137\nFor the points (0,1), (1,0), (1,2), (2,1): floor((200+200+50+200+100+100)/6) = floor(141.666667) = 141\nFor the point (1,1): floor((50+200+200+200+200+100+100+100+100)/9) = floor(138.888889) = 138\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == img.length
    • \n\t
    • n == img[i].length
    • \n\t
    • 1 <= m, n <= 200
    • \n\t
    • 0 <= img[i][j] <= 255
    • \n
    \n", "content_cn": "

    \u5305\u542b\u6574\u6570\u7684\u4e8c\u7ef4\u77e9\u9635 M \u8868\u793a\u4e00\u4e2a\u56fe\u7247\u7684\u7070\u5ea6\u3002\u4f60\u9700\u8981\u8bbe\u8ba1\u4e00\u4e2a\u5e73\u6ed1\u5668\u6765\u8ba9\u6bcf\u4e00\u4e2a\u5355\u5143\u7684\u7070\u5ea6\u6210\u4e3a\u5e73\u5747\u7070\u5ea6 (\u5411\u4e0b\u820d\u5165) \uff0c\u5e73\u5747\u7070\u5ea6\u7684\u8ba1\u7b97\u662f\u5468\u56f4\u76848\u4e2a\u5355\u5143\u548c\u5b83\u672c\u8eab\u7684\u503c\u6c42\u5e73\u5747\uff0c\u5982\u679c\u5468\u56f4\u7684\u5355\u5143\u683c\u4e0d\u8db3\u516b\u4e2a\uff0c\u5219\u5c3d\u53ef\u80fd\u591a\u7684\u5229\u7528\u5b83\u4eec\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165:\n[[1,1,1],\n [1,0,1],\n [1,1,1]]\n\u8f93\u51fa:\n[[0, 0, 0],\n [0, 0, 0],\n [0, 0, 0]]\n\u89e3\u91ca:\n\u5bf9\u4e8e\u70b9 (0,0), (0,2), (2,0), (2,2): \u5e73\u5747(3/4) = \u5e73\u5747(0.75) = 0\n\u5bf9\u4e8e\u70b9 (0,1), (1,0), (1,2), (2,1): \u5e73\u5747(5/6) = \u5e73\u5747(0.83333333) = 0\n\u5bf9\u4e8e\u70b9 (1,1): \u5e73\u5747(8/9) = \u5e73\u5747(0.88888889) = 0\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u7ed9\u5b9a\u77e9\u9635\u4e2d\u7684\u6574\u6570\u8303\u56f4\u4e3a [0, 255]\u3002
    2. \n\t
    3. \u77e9\u9635\u7684\u957f\u548c\u5bbd\u7684\u8303\u56f4\u5747\u4e3a [1, 150]\u3002
    4. \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> imageSmoother(vector>& img) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[][] imageSmoother(int[][] img) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def imageSmoother(self, img):\n \"\"\"\n :type img: List[List[int]]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def imageSmoother(self, img: List[List[int]]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** imageSmoother(int** img, int imgSize, int* imgColSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[][] ImageSmoother(int[][] img) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} img\n * @return {number[][]}\n */\nvar imageSmoother = function(img) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} img\n# @return {Integer[][]}\ndef image_smoother(img)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func imageSmoother(_ img: [[Int]]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func imageSmoother(img [][]int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def imageSmoother(img: Array[Array[Int]]): Array[Array[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun imageSmoother(img: Array): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn image_smoother(img: Vec>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $img\n * @return Integer[][]\n */\n function imageSmoother($img) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function imageSmoother(img: number[][]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (image-smoother img)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0661](https://leetcode-cn.com/problems/image-smoother)", "[\u56fe\u7247\u5e73\u6ed1\u5668](/solution/0600-0699/0661.Image%20Smoother/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0661](https://leetcode.com/problems/image-smoother)", "[Image Smoother](/solution/0600-0699/0661.Image%20Smoother/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0660", "frontend_question_id": "0660", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/remove-9", "url_en": "https://leetcode.com/problems/remove-9", "relative_path_cn": "/solution/0600-0699/0660.Remove%209/README.md", "relative_path_en": "/solution/0600-0699/0660.Remove%209/README_EN.md", "title_cn": "\u79fb\u9664 9", "title_en": "Remove 9", "question_title_slug": "remove-9", "content_en": "

    Start from integer 1, remove any integer that contains 9 such as 9, 19, 29...

    \n\n

    So now, you will have a new integer sequence: 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, ...

    \n\n

    Given a positive integer n, you need to return the n-th integer after removing. Note that 1 will be the first integer.

    \n\n

     

    \n

    Example 1:

    \n
    Input: n = 9\nOutput: 10\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 8 x 10^8
    • \n
    \n", "content_cn": "

    \u4ece 1 \u5f00\u59cb\uff0c\u79fb\u9664\u6240\u6709\u5305\u542b\u6570\u5b57 9 \u7684\u6240\u6709\u6574\u6570\uff0c\u4f8b\u5982 9\uff0c19\uff0c29\uff0c……

    \n\n

    \u8fd9\u6837\u5c31\u83b7\u5f97\u4e86\u4e00\u4e2a\u65b0\u7684\u6574\u6570\u6570\u5217\uff1a1\uff0c2\uff0c3\uff0c4\uff0c5\uff0c6\uff0c7\uff0c8\uff0c10\uff0c11\uff0c……

    \n\n

    \u7ed9\u5b9a\u6b63\u6574\u6570 n\uff0c\u8bf7\u4f60\u8fd4\u56de\u65b0\u6570\u5217\u4e2d\u7b2c n \u4e2a\u6570\u5b57\u662f\u591a\u5c11\u30021 \u662f\u65b0\u6570\u5217\u4e2d\u7684\u7b2c\u4e00\u4e2a\u6570\u5b57\u3002

    \n\n

     

    \n\n

    \u6837\u4f8b 1:

    \n\n
    \u8f93\u5165: 9\n\u8f93\u51fa: 10\n
    \n\n

     

    \n\n

    \u6ce8\u91ca \uff1an \u4e0d\u4f1a\u8d85\u8fc7 9 x 10^8\u3002

    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int newInteger(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int newInteger(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def newInteger(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def newInteger(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint newInteger(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NewInteger(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar newInteger = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef new_integer(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func newInteger(_ n: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func newInteger(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def newInteger(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun newInteger(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn new_integer(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function newInteger($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function newInteger(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (new-integer n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0660](https://leetcode-cn.com/problems/remove-9)", "[\u79fb\u9664 9](/solution/0600-0699/0660.Remove%209/README.md)", "`\u6570\u5b66`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0660](https://leetcode.com/problems/remove-9)", "[Remove 9](/solution/0600-0699/0660.Remove%209/README_EN.md)", "`Math`", "Hard", "\ud83d\udd12"]}, {"question_id": "0659", "frontend_question_id": "0659", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/split-array-into-consecutive-subsequences", "url_en": "https://leetcode.com/problems/split-array-into-consecutive-subsequences", "relative_path_cn": "/solution/0600-0699/0659.Split%20Array%20into%20Consecutive%20Subsequences/README.md", "relative_path_en": "/solution/0600-0699/0659.Split%20Array%20into%20Consecutive%20Subsequences/README_EN.md", "title_cn": "\u5206\u5272\u6570\u7ec4\u4e3a\u8fde\u7eed\u5b50\u5e8f\u5217", "title_en": "Split Array into Consecutive Subsequences", "question_title_slug": "split-array-into-consecutive-subsequences", "content_en": "

    You are given an integer array nums that is sorted in non-decreasing order.

    \n\n

    Determine if it is possible to split nums into one or more subsequences such that both of the following conditions are true:

    \n\n
      \n\t
    • Each subsequence is a consecutive increasing sequence (i.e. each integer is exactly one more than the previous integer).
    • \n\t
    • All subsequences have a length of 3 or more.
    • \n
    \n\n

    Return true if you can split nums according to the above conditions, or false otherwise.

    \n\n

    A subsequence of an array is a new array that is formed from the original array by deleting some (can be none) of the elements without disturbing the relative positions of the remaining elements. (i.e., [1,3,5] is a subsequence of [1,2,3,4,5] while [1,3,2] is not).

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,3,3,4,5]\nOutput: true\nExplanation: nums can be split into the following subsequences:\n[1,2,3,3,4,5] --> 1, 2, 3\n[1,2,3,3,4,5] --> 3, 4, 5\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,2,3,3,4,4,5,5]\nOutput: true\nExplanation: nums can be split into the following subsequences:\n[1,2,3,3,4,4,5,5] --> 1, 2, 3, 4, 5\n[1,2,3,3,4,4,5,5] --> 3, 4, 5\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [1,2,3,4,4,5]\nOutput: false\nExplanation: It is impossible to split nums into consecutive increasing subsequences of length 3 or more.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 104
    • \n\t
    • -1000 <= nums[i] <= 1000
    • \n\t
    • nums is sorted in non-decreasing order.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6309\u5347\u5e8f\u6392\u5e8f\u7684\u6574\u6570\u6570\u7ec4 num\uff08\u53ef\u80fd\u5305\u542b\u91cd\u590d\u6570\u5b57\uff09\uff0c\u8bf7\u4f60\u5c06\u5b83\u4eec\u5206\u5272\u6210\u4e00\u4e2a\u6216\u591a\u4e2a\u957f\u5ea6\u81f3\u5c11\u4e3a 3 \u7684\u5b50\u5e8f\u5217\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5b50\u5e8f\u5217\u90fd\u7531\u8fde\u7eed\u6574\u6570\u7ec4\u6210\u3002

    \n\n

    \u5982\u679c\u53ef\u4ee5\u5b8c\u6210\u4e0a\u8ff0\u5206\u5272\uff0c\u5219\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165: [1,2,3,3,4,5]\n\u8f93\u51fa: True\n\u89e3\u91ca:\n\u4f60\u53ef\u4ee5\u5206\u5272\u51fa\u8fd9\u6837\u4e24\u4e2a\u8fde\u7eed\u5b50\u5e8f\u5217 : \n1, 2, 3\n3, 4, 5\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165: [1,2,3,3,4,4,5,5]\n\u8f93\u51fa: True\n\u89e3\u91ca:\n\u4f60\u53ef\u4ee5\u5206\u5272\u51fa\u8fd9\u6837\u4e24\u4e2a\u8fde\u7eed\u5b50\u5e8f\u5217 : \n1, 2, 3, 4, 5\n3, 4, 5\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165: [1,2,3,4,4,5]\n\u8f93\u51fa: False\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 10000
    • \n
    \n", "tags_en": ["Heap", "Greedy"], "tags_cn": ["\u5806", "\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isPossible(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isPossible(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isPossible(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isPossible(self, nums: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isPossible(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsPossible(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {boolean}\n */\nvar isPossible = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Boolean}\ndef is_possible(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isPossible(_ nums: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isPossible(nums []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isPossible(nums: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isPossible(nums: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_possible(nums: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Boolean\n */\n function isPossible($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isPossible(nums: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-possible nums)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0659](https://leetcode-cn.com/problems/split-array-into-consecutive-subsequences)", "[\u5206\u5272\u6570\u7ec4\u4e3a\u8fde\u7eed\u5b50\u5e8f\u5217](/solution/0600-0699/0659.Split%20Array%20into%20Consecutive%20Subsequences/README.md)", "`\u5806`,`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0659](https://leetcode.com/problems/split-array-into-consecutive-subsequences)", "[Split Array into Consecutive Subsequences](/solution/0600-0699/0659.Split%20Array%20into%20Consecutive%20Subsequences/README_EN.md)", "`Heap`,`Greedy`", "Medium", ""]}, {"question_id": "0658", "frontend_question_id": "0658", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-k-closest-elements", "url_en": "https://leetcode.com/problems/find-k-closest-elements", "relative_path_cn": "/solution/0600-0699/0658.Find%20K%20Closest%20Elements/README.md", "relative_path_en": "/solution/0600-0699/0658.Find%20K%20Closest%20Elements/README_EN.md", "title_cn": "\u627e\u5230 K \u4e2a\u6700\u63a5\u8fd1\u7684\u5143\u7d20", "title_en": "Find K Closest Elements", "question_title_slug": "find-k-closest-elements", "content_en": "

    Given a sorted integer array arr, two integers k and x, return the k closest integers to x in the array. The result should also be sorted in ascending order.

    \n\n

    An integer a is closer to x than an integer b if:

    \n\n
      \n\t
    • |a - x| < |b - x|, or
    • \n\t
    • |a - x| == |b - x| and a < b
    • \n
    \n\n

     

    \n

    Example 1:

    \n
    Input: arr = [1,2,3,4,5], k = 4, x = 3\nOutput: [1,2,3,4]\n

    Example 2:

    \n
    Input: arr = [1,2,3,4,5], k = 4, x = -1\nOutput: [1,2,3,4]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= k <= arr.length
    • \n\t
    • 1 <= arr.length <= 104
    • \n\t
    • arr is sorted in ascending order.
    • \n\t
    • -104 <= arr[i], x <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6392\u5e8f\u597d\u7684\u6570\u7ec4\u00a0arr \uff0c\u4e24\u4e2a\u6574\u6570 k \u548c x \uff0c\u4ece\u6570\u7ec4\u4e2d\u627e\u5230\u6700\u9760\u8fd1 x\uff08\u4e24\u6570\u4e4b\u5dee\u6700\u5c0f\uff09\u7684 k \u4e2a\u6570\u3002\u8fd4\u56de\u7684\u7ed3\u679c\u5fc5\u987b\u8981\u662f\u6309\u5347\u5e8f\u6392\u597d\u7684\u3002

    \n\n

    \u6574\u6570 a \u6bd4\u6574\u6570 b \u66f4\u63a5\u8fd1 x \u9700\u8981\u6ee1\u8db3\uff1a

    \n\n
      \n\t
    • |a - x| < |b - x| \u6216\u8005
    • \n\t
    • |a - x| == |b - x| \u4e14 a < b
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [1,2,3,4,5], k = 4, x = 3\n\u8f93\u51fa\uff1a[1,2,3,4]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [1,2,3,4,5], k = 4, x = -1\n\u8f93\u51fa\uff1a[1,2,3,4]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= k <= arr.length
    • \n\t
    • 1 <= arr.length\u00a0<= 104
    • \n\t
    • \u6570\u7ec4\u91cc\u7684\u6bcf\u4e2a\u5143\u7d20\u4e0e\u00a0x \u7684\u7edd\u5bf9\u503c\u4e0d\u8d85\u8fc7 104
    • \n
    \n", "tags_en": ["Binary Search"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findClosestElements(vector& arr, int k, int x) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List findClosestElements(int[] arr, int k, int x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findClosestElements(self, arr, k, x):\n \"\"\"\n :type arr: List[int]\n :type k: int\n :type x: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findClosestElements(self, arr: List[int], k: int, x: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* findClosestElements(int* arr, int arrSize, int k, int x, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList FindClosestElements(int[] arr, int k, int x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @param {number} k\n * @param {number} x\n * @return {number[]}\n */\nvar findClosestElements = function(arr, k, x) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @param {Integer} k\n# @param {Integer} x\n# @return {Integer[]}\ndef find_closest_elements(arr, k, x)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findClosestElements(_ arr: [Int], _ k: Int, _ x: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findClosestElements(arr []int, k int, x int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findClosestElements(arr: Array[Int], k: Int, x: Int): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findClosestElements(arr: IntArray, k: Int, x: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_closest_elements(arr: Vec, k: i32, x: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @param Integer $k\n * @param Integer $x\n * @return Integer[]\n */\n function findClosestElements($arr, $k, $x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findClosestElements(arr: number[], k: number, x: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-closest-elements arr k x)\n (-> (listof exact-integer?) exact-integer? exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0658](https://leetcode-cn.com/problems/find-k-closest-elements)", "[\u627e\u5230 K \u4e2a\u6700\u63a5\u8fd1\u7684\u5143\u7d20](/solution/0600-0699/0658.Find%20K%20Closest%20Elements/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0658](https://leetcode.com/problems/find-k-closest-elements)", "[Find K Closest Elements](/solution/0600-0699/0658.Find%20K%20Closest%20Elements/README_EN.md)", "`Binary Search`", "Medium", ""]}, {"question_id": "0657", "frontend_question_id": "0657", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/robot-return-to-origin", "url_en": "https://leetcode.com/problems/robot-return-to-origin", "relative_path_cn": "/solution/0600-0699/0657.Robot%20Return%20to%20Origin/README.md", "relative_path_en": "/solution/0600-0699/0657.Robot%20Return%20to%20Origin/README_EN.md", "title_cn": "\u673a\u5668\u4eba\u80fd\u5426\u8fd4\u56de\u539f\u70b9", "title_en": "Robot Return to Origin", "question_title_slug": "robot-return-to-origin", "content_en": "

    There is a robot starting at position (0, 0), the origin, on a 2D plane. Given a sequence of its moves, judge if this robot ends up at (0, 0) after it completes its moves.

    \n\n

    The move sequence is represented by a string, and the character moves[i] represents its ith move. Valid moves are R (right), L (left), U (up), and D (down). If the robot returns to the origin after it finishes all of its moves, return true. Otherwise, return false.

    \n\n

    Note: The way that the robot is "facing" is irrelevant. "R" will always make the robot move to the right once, "L" will always make it move left, etc. Also, assume that the magnitude of the robot's movement is the same for each move.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: moves = "UD"\nOutput: true\nExplanation: The robot moves up once, and then down once. All moves have the same magnitude, so it ended up at the origin where it started. Therefore, we return true.\n
    \n\n

    Example 2:

    \n\n
    \nInput: moves = "LL"\nOutput: false\nExplanation: The robot moves left twice. It ends up two "moves" to the left of the origin. We return false because it is not at the origin at the end of its moves.\n
    \n\n

    Example 3:

    \n\n
    \nInput: moves = "RRDD"\nOutput: false\n
    \n\n

    Example 4:

    \n\n
    \nInput: moves = "LDRRLRUULR"\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= moves.length <= 2 * 104
    • \n\t
    • moves only contains the characters 'U', 'D', 'L' and 'R'.
    • \n
    \n", "content_cn": "

    \u5728\u4e8c\u7ef4\u5e73\u9762\u4e0a\uff0c\u6709\u4e00\u4e2a\u673a\u5668\u4eba\u4ece\u539f\u70b9 (0, 0) \u5f00\u59cb\u3002\u7ed9\u51fa\u5b83\u7684\u79fb\u52a8\u987a\u5e8f\uff0c\u5224\u65ad\u8fd9\u4e2a\u673a\u5668\u4eba\u5728\u5b8c\u6210\u79fb\u52a8\u540e\u662f\u5426\u5728 (0, 0) \u5904\u7ed3\u675f\u3002

    \n\n

    \u79fb\u52a8\u987a\u5e8f\u7531\u5b57\u7b26\u4e32\u8868\u793a\u3002\u5b57\u7b26 move[i] \u8868\u793a\u5176\u7b2c i \u6b21\u79fb\u52a8\u3002\u673a\u5668\u4eba\u7684\u6709\u6548\u52a8\u4f5c\u6709 R\uff08\u53f3\uff09\uff0cL\uff08\u5de6\uff09\uff0cU\uff08\u4e0a\uff09\u548c D\uff08\u4e0b\uff09\u3002\u5982\u679c\u673a\u5668\u4eba\u5728\u5b8c\u6210\u6240\u6709\u52a8\u4f5c\u540e\u8fd4\u56de\u539f\u70b9\uff0c\u5219\u8fd4\u56de true\u3002\u5426\u5219\uff0c\u8fd4\u56de false\u3002

    \n\n

    \u6ce8\u610f\uff1a\u673a\u5668\u4eba“\u9762\u671d”\u7684\u65b9\u5411\u65e0\u5173\u7d27\u8981\u3002 “R” \u5c06\u59cb\u7ec8\u4f7f\u673a\u5668\u4eba\u5411\u53f3\u79fb\u52a8\u4e00\u6b21\uff0c“L” \u5c06\u59cb\u7ec8\u5411\u5de6\u79fb\u52a8\u7b49\u3002\u6b64\u5916\uff0c\u5047\u8bbe\u6bcf\u6b21\u79fb\u52a8\u673a\u5668\u4eba\u7684\u79fb\u52a8\u5e45\u5ea6\u76f8\u540c\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: "UD"\n\u8f93\u51fa: true\n\u89e3\u91ca\uff1a\u673a\u5668\u4eba\u5411\u4e0a\u79fb\u52a8\u4e00\u6b21\uff0c\u7136\u540e\u5411\u4e0b\u79fb\u52a8\u4e00\u6b21\u3002\u6240\u6709\u52a8\u4f5c\u90fd\u5177\u6709\u76f8\u540c\u7684\u5e45\u5ea6\uff0c\u56e0\u6b64\u5b83\u6700\u7ec8\u56de\u5230\u5b83\u5f00\u59cb\u7684\u539f\u70b9\u3002\u56e0\u6b64\uff0c\u6211\u4eec\u8fd4\u56de true\u3002
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: "LL"\n\u8f93\u51fa: false\n\u89e3\u91ca\uff1a\u673a\u5668\u4eba\u5411\u5de6\u79fb\u52a8\u4e24\u6b21\u3002\u5b83\u6700\u7ec8\u4f4d\u4e8e\u539f\u70b9\u7684\u5de6\u4fa7\uff0c\u8ddd\u539f\u70b9\u6709\u4e24\u6b21 “\u79fb\u52a8” \u7684\u8ddd\u79bb\u3002\u6211\u4eec\u8fd4\u56de false\uff0c\u56e0\u4e3a\u5b83\u5728\u79fb\u52a8\u7ed3\u675f\u65f6\u6ca1\u6709\u8fd4\u56de\u539f\u70b9\u3002
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool judgeCircle(string moves) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean judgeCircle(String moves) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def judgeCircle(self, moves):\n \"\"\"\n :type moves: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def judgeCircle(self, moves: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool judgeCircle(char * moves){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool JudgeCircle(string moves) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} moves\n * @return {boolean}\n */\nvar judgeCircle = function(moves) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} moves\n# @return {Boolean}\ndef judge_circle(moves)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func judgeCircle(_ moves: String) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func judgeCircle(moves string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def judgeCircle(moves: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun judgeCircle(moves: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn judge_circle(moves: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $moves\n * @return Boolean\n */\n function judgeCircle($moves) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function judgeCircle(moves: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (judge-circle moves)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0657](https://leetcode-cn.com/problems/robot-return-to-origin)", "[\u673a\u5668\u4eba\u80fd\u5426\u8fd4\u56de\u539f\u70b9](/solution/0600-0699/0657.Robot%20Return%20to%20Origin/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0657](https://leetcode.com/problems/robot-return-to-origin)", "[Robot Return to Origin](/solution/0600-0699/0657.Robot%20Return%20to%20Origin/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "0656", "frontend_question_id": "0656", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/coin-path", "url_en": "https://leetcode.com/problems/coin-path", "relative_path_cn": "/solution/0600-0699/0656.Coin%20Path/README.md", "relative_path_en": "/solution/0600-0699/0656.Coin%20Path/README_EN.md", "title_cn": "\u91d1\u5e01\u8def\u5f84", "title_en": "Coin Path", "question_title_slug": "coin-path", "content_en": "

    You are given an integer array coins (1-indexed) of length n and an integer maxJump. You can jump to any index i of the array coins if coins[i] != -1 and you have to pay coins[i] when you visit index i. In addition to that, if you are currently at index i, you can only jump to any index i + k where i + k <= n and k is a value in the range [1, maxJump].

    \n\n

    You are initially positioned at index 1 (coins[1] is not -1). You want to find the path that reaches index n with the minimum cost.

    \n\n

    Return an integer array of the indices that you will visit in order so that you can reach index n with the minimum cost. If there are multiple paths with the same cost, return the lexicographically smallest such path. If it is not possible to reach index n, return an empty array.

    \n\n

    A path p1 = [Pa1, Pa2, ..., Pax] of length x is lexicographically smaller than p2 = [Pb1, Pb2, ..., Pbx] of length y, if and only if at the first j where Paj and Pbj differ, Paj < Pbj; when no such j exists, then x < y.

    \n\n

     

    \n

    Example 1:

    \n
    Input: coins = [1,2,4,-1,2], maxJump = 2\nOutput: [1,3,5]\n

    Example 2:

    \n
    Input: coins = [1,2,4,-1,2], maxJump = 1\nOutput: []\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= coins.length <= 1000
    • \n\t
    • -1 <= coins[i] <= 100
    • \n\t
    • coins[1] != -1
    • \n\t
    • 1 <= maxJump <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6570\u7ec4 A\uff08\u4e0b\u6807\u4ece 1 \u5f00\u59cb\uff09\u5305\u542b N \u4e2a\u6574\u6570\uff1aA1\uff0cA2\uff0c……\uff0cAN \u548c\u4e00\u4e2a\u6574\u6570 B\u3002\u4f60\u53ef\u4ee5\u4ece\u6570\u7ec4 A \u4e2d\u7684\u4efb\u4f55\u4e00\u4e2a\u4f4d\u7f6e\uff08\u4e0b\u6807\u4e3a i\uff09\u8df3\u5230\u4e0b\u6807 i+1\uff0ci+2\uff0c……\uff0ci+B \u7684\u4efb\u610f\u4e00\u4e2a\u53ef\u4ee5\u8df3\u5230\u7684\u4f4d\u7f6e\u4e0a\u3002\u5982\u679c\u4f60\u5728\u4e0b\u6807\u4e3a i \u7684\u4f4d\u7f6e\u4e0a\uff0c\u4f60\u9700\u8981\u652f\u4ed8 Ai \u4e2a\u91d1\u5e01\u3002\u5982\u679c Ai \u662f -1\uff0c\u610f\u5473\u7740\u4e0b\u6807\u4e3a i \u7684\u4f4d\u7f6e\u662f\u4e0d\u53ef\u4ee5\u8df3\u5230\u7684\u3002

    \n\n

    \u73b0\u5728\uff0c\u4f60\u5e0c\u671b\u82b1\u8d39\u6700\u5c11\u7684\u91d1\u5e01\u4ece\u6570\u7ec4 A \u7684 1 \u4f4d\u7f6e\u8df3\u5230 N \u4f4d\u7f6e\uff0c\u4f60\u9700\u8981\u8f93\u51fa\u82b1\u8d39\u6700\u5c11\u7684\u8def\u5f84\uff0c\u4f9d\u6b21\u8f93\u51fa\u6240\u6709\u7ecf\u8fc7\u7684\u4e0b\u6807\uff08\u4ece 1 \u5230 N\uff09\u3002

    \n\n

    \u5982\u679c\u6709\u591a\u79cd\u82b1\u8d39\u6700\u5c11\u7684\u65b9\u6848\uff0c\u8f93\u51fa\u5b57\u5178\u987a\u5e8f\u6700\u5c0f\u7684\u8def\u5f84\u3002

    \n\n

    \u5982\u679c\u65e0\u6cd5\u5230\u8fbe N \u4f4d\u7f6e\uff0c\u8bf7\u8fd4\u56de\u4e00\u4e2a\u7a7a\u6570\u7ec4\u3002

    \n\n

     

    \n\n

    \u6837\u4f8b 1 :

    \n\n
    \u8f93\u5165: [1,2,4,-1,2], 2\n\u8f93\u51fa: [1,3,5]\n
    \n\n

     

    \n\n

    \u6837\u4f8b 2 :

    \n\n
    \u8f93\u5165: [1,2,4,-1,2], 1\n\u8f93\u51fa: []\n
    \n\n

     

    \n\n

    \u6ce8\u91ca :

    \n\n
      \n\t
    1. \u8def\u5f84 Pa1\uff0cPa2\uff0c……\uff0cPa\u662f\u5b57\u5178\u5e8f\u5c0f\u4e8e Pb1\uff0cPb2\uff0c……\uff0cPb\u7684\uff0c\u5f53\u4e14\u4ec5\u5f53\u7b2c\u4e00\u4e2a Pai \u548c Pbi \u4e0d\u540c\u7684 i \u6ee1\u8db3 Pai < Pbi\uff0c\u5982\u679c\u4e0d\u5b58\u5728\u8fd9\u6837\u7684 i \u90a3\u4e48\u6ee1\u8db3 n < m\u3002
    2. \n\t
    3. A1 >= 0\u3002 A2, ..., AN \uff08\u5982\u679c\u5b58\u5728\uff09 \u7684\u8303\u56f4\u662f [-1, 100]\u3002
    4. \n\t
    5. A \u6570\u7ec4\u7684\u957f\u5ea6\u8303\u56f4 [1, 1000].
    6. \n\t
    7. B \u7684\u8303\u56f4 [1, 100].
    8. \n
    \n\n

     

    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector cheapestJump(vector& coins, int maxJump) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List cheapestJump(int[] coins, int maxJump) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def cheapestJump(self, coins, maxJump):\n \"\"\"\n :type coins: List[int]\n :type maxJump: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def cheapestJump(self, coins: List[int], maxJump: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* cheapestJump(int* coins, int coinsSize, int maxJump, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList CheapestJump(int[] coins, int maxJump) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} coins\n * @param {number} maxJump\n * @return {number[]}\n */\nvar cheapestJump = function(coins, maxJump) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} coins\n# @param {Integer} max_jump\n# @return {Integer[]}\ndef cheapest_jump(coins, max_jump)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func cheapestJump(_ coins: [Int], _ maxJump: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func cheapestJump(coins []int, maxJump int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def cheapestJump(coins: Array[Int], maxJump: Int): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun cheapestJump(coins: IntArray, maxJump: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn cheapest_jump(coins: Vec, max_jump: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $coins\n * @param Integer $maxJump\n * @return Integer[]\n */\n function cheapestJump($coins, $maxJump) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function cheapestJump(coins: number[], maxJump: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (cheapest-jump coins maxJump)\n (-> (listof exact-integer?) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0656](https://leetcode-cn.com/problems/coin-path)", "[\u91d1\u5e01\u8def\u5f84](/solution/0600-0699/0656.Coin%20Path/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0656](https://leetcode.com/problems/coin-path)", "[Coin Path](/solution/0600-0699/0656.Coin%20Path/README_EN.md)", "`Dynamic Programming`", "Hard", "\ud83d\udd12"]}, {"question_id": "0655", "frontend_question_id": "0655", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/print-binary-tree", "url_en": "https://leetcode.com/problems/print-binary-tree", "relative_path_cn": "/solution/0600-0699/0655.Print%20Binary%20Tree/README.md", "relative_path_en": "/solution/0600-0699/0655.Print%20Binary%20Tree/README_EN.md", "title_cn": "\u8f93\u51fa\u4e8c\u53c9\u6811", "title_en": "Print Binary Tree", "question_title_slug": "print-binary-tree", "content_en": "

    Given the root of a binary tree, construct a 0-indexed m x n string matrix res that represents a formatted layout of the tree. The formatted layout matrix should be constructed using the following rules:

    \n\n
      \n\t
    • The height of the tree is height and the number of rows m should be equal to height + 1.
    • \n\t
    • The number of columns n should be equal to 2height+1 - 1.
    • \n\t
    • Place the root node in the middle of the top row (more formally, at location res[0][(n-1)/2]).
    • \n\t
    • For each node that has been placed in the matrix at position res[r][c], place its left child at res[r+1][c-2height-r-1] and its right child at res[r+1][c+2height-r-1].
    • \n\t
    • Continue this process until all the nodes in the tree have been placed.
    • \n\t
    • Any empty cells should contain the empty string "".
    • \n
    \n\n

    Return the constructed matrix res.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,2]\nOutput: \n[["","1",""],\n ["2","",""]]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [1,2,3,null,4]\nOutput: \n[["","","","1","","",""],\n ["","2","","","","3",""],\n ["","","4","","","",""]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 210].
    • \n\t
    • -99 <= Node.val <= 99
    • \n\t
    • The depth of the tree will be in the range [1, 10].
    • \n
    \n", "content_cn": "

    \u5728\u4e00\u4e2a m*n \u7684\u4e8c\u7ef4\u5b57\u7b26\u4e32\u6570\u7ec4\u4e2d\u8f93\u51fa\u4e8c\u53c9\u6811\uff0c\u5e76\u9075\u5b88\u4ee5\u4e0b\u89c4\u5219\uff1a

    \n\n
      \n\t
    1. \u884c\u6570 m \u5e94\u5f53\u7b49\u4e8e\u7ed9\u5b9a\u4e8c\u53c9\u6811\u7684\u9ad8\u5ea6\u3002
    2. \n\t
    3. \u5217\u6570 n \u5e94\u5f53\u603b\u662f\u5947\u6570\u3002
    4. \n\t
    5. \u6839\u8282\u70b9\u7684\u503c\uff08\u4ee5\u5b57\u7b26\u4e32\u683c\u5f0f\u7ed9\u51fa\uff09\u5e94\u5f53\u653e\u5728\u53ef\u653e\u7f6e\u7684\u7b2c\u4e00\u884c\u6b63\u4e2d\u95f4\u3002\u6839\u8282\u70b9\u6240\u5728\u7684\u884c\u4e0e\u5217\u4f1a\u5c06\u5269\u4f59\u7a7a\u95f4\u5212\u5206\u4e3a\u4e24\u90e8\u5206\uff08\u5de6\u4e0b\u90e8\u5206\u548c\u53f3\u4e0b\u90e8\u5206\uff09\u3002\u4f60\u5e94\u8be5\u5c06\u5de6\u5b50\u6811\u8f93\u51fa\u5728\u5de6\u4e0b\u90e8\u5206\uff0c\u53f3\u5b50\u6811\u8f93\u51fa\u5728\u53f3\u4e0b\u90e8\u5206\u3002\u5de6\u4e0b\u548c\u53f3\u4e0b\u90e8\u5206\u5e94\u5f53\u6709\u76f8\u540c\u7684\u5927\u5c0f\u3002\u5373\u4f7f\u4e00\u4e2a\u5b50\u6811\u4e3a\u7a7a\u800c\u53e6\u4e00\u4e2a\u975e\u7a7a\uff0c\u4f60\u4e0d\u9700\u8981\u4e3a\u7a7a\u7684\u5b50\u6811\u8f93\u51fa\u4efb\u4f55\u4e1c\u897f\uff0c\u4f46\u4ecd\u9700\u8981\u4e3a\u53e6\u4e00\u4e2a\u5b50\u6811\u7559\u51fa\u8db3\u591f\u7684\u7a7a\u95f4\u3002\u7136\u800c\uff0c\u5982\u679c\u4e24\u4e2a\u5b50\u6811\u90fd\u4e3a\u7a7a\u5219\u4e0d\u9700\u8981\u4e3a\u5b83\u4eec\u7559\u51fa\u4efb\u4f55\u7a7a\u95f4\u3002
    6. \n\t
    7. \u6bcf\u4e2a\u672a\u4f7f\u7528\u7684\u7a7a\u95f4\u5e94\u5305\u542b\u4e00\u4e2a\u7a7a\u7684\u5b57\u7b26\u4e32""\u3002
    8. \n\t
    9. \u4f7f\u7528\u76f8\u540c\u7684\u89c4\u5219\u8f93\u51fa\u5b50\u6811\u3002
    10. \n
    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165:\n     1\n    /\n   2\n\u8f93\u51fa:\n[["", "1", ""],\n ["2", "", ""]]\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165:\n     1\n    / \\\n   2   3\n    \\\n     4\n\u8f93\u51fa:\n[["", "", "", "1", "", "", ""],\n ["", "2", "", "", "", "3", ""],\n ["", "", "4", "", "", "", ""]]\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \n\u8f93\u5165:\n      1\n     / \\\n    2   5\n   / \n  3 \n / \n4 \n\u8f93\u51fa:\n[["",  "",  "", "",  "", "", "", "1", "",  "",  "",  "",  "", "", ""]\n ["",  "",  "", "2", "", "", "", "",  "",  "",  "",  "5", "", "", ""]\n ["",  "3", "", "",  "", "", "", "",  "",  "",  "",  "",  "", "", ""]\n ["4", "",  "", "",  "", "", "", "",  "",  "",  "",  "",  "", "", ""]]\n
    \n\n

    \u6ce8\u610f: \u4e8c\u53c9\u6811\u7684\u9ad8\u5ea6\u5728\u8303\u56f4 [1, 10] \u4e2d\u3002

    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector> printTree(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public List> printTree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def printTree(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: List[List[str]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def printTree(self, root: TreeNode) -> List[List[str]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nchar *** printTree(struct TreeNode* root, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public IList> PrintTree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {string[][]}\n */\nvar printTree = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {String[][]}\ndef print_tree(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func printTree(_ root: TreeNode?) -> [[String]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc printTree(root *TreeNode) [][]string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def printTree(root: TreeNode): List[List[String]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun printTree(root: TreeNode?): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn print_tree(root: Option>>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return String[][]\n */\n function printTree($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction printTree(root: TreeNode | null): string[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (print-tree root)\n (-> (or/c tree-node? #f) (listof (listof string?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0655](https://leetcode-cn.com/problems/print-binary-tree)", "[\u8f93\u51fa\u4e8c\u53c9\u6811](/solution/0600-0699/0655.Print%20Binary%20Tree/README.md)", "`\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0655](https://leetcode.com/problems/print-binary-tree)", "[Print Binary Tree](/solution/0600-0699/0655.Print%20Binary%20Tree/README_EN.md)", "`Tree`", "Medium", ""]}, {"question_id": "0654", "frontend_question_id": "0654", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-binary-tree", "url_en": "https://leetcode.com/problems/maximum-binary-tree", "relative_path_cn": "/solution/0600-0699/0654.Maximum%20Binary%20Tree/README.md", "relative_path_en": "/solution/0600-0699/0654.Maximum%20Binary%20Tree/README_EN.md", "title_cn": "\u6700\u5927\u4e8c\u53c9\u6811", "title_en": "Maximum Binary Tree", "question_title_slug": "maximum-binary-tree", "content_en": "

    You are given an integer array nums with no duplicates. A maximum binary tree can be built recursively from nums using the following algorithm:

    \n\n
      \n\t
    1. Create a root node whose value is the maximum value in nums.
    2. \n\t
    3. Recursively build the left subtree on the subarray prefix to the left of the maximum value.
    4. \n\t
    5. Recursively build the right subtree on the subarray suffix to the right of the maximum value.
    6. \n
    \n\n

    Return the maximum binary tree built from nums.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: nums = [3,2,1,6,0,5]\nOutput: [6,3,5,null,2,0,null,null,1]\nExplanation: The recursive calls are as follow:\n- The largest value in [3,2,1,6,0,5] is 6. Left prefix is [3,2,1] and right suffix is [0,5].\n    - The largest value in [3,2,1] is 3. Left prefix is [] and right suffix is [2,1].\n        - Empty array, so no child.\n        - The largest value in [2,1] is 2. Left prefix is [] and right suffix is [1].\n            - Empty array, so no child.\n            - Only one element, so child is a node with value 1.\n    - The largest value in [0,5] is 5. Left prefix is [0] and right suffix is [].\n        - Only one element, so child is a node with value 0.\n        - Empty array, so no child.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: nums = [3,2,1]\nOutput: [3,null,2,null,1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 1000
    • \n\t
    • 0 <= nums[i] <= 1000
    • \n\t
    • All integers in nums are unique.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e0d\u542b\u91cd\u590d\u5143\u7d20\u7684\u6574\u6570\u6570\u7ec4 nums \u3002\u4e00\u4e2a\u4ee5\u6b64\u6570\u7ec4\u76f4\u63a5\u9012\u5f52\u6784\u5efa\u7684 \u6700\u5927\u4e8c\u53c9\u6811 \u5b9a\u4e49\u5982\u4e0b\uff1a

    \n\n
      \n\t
    1. \u4e8c\u53c9\u6811\u7684\u6839\u662f\u6570\u7ec4 nums \u4e2d\u7684\u6700\u5927\u5143\u7d20\u3002
    2. \n\t
    3. \u5de6\u5b50\u6811\u662f\u901a\u8fc7\u6570\u7ec4\u4e2d \u6700\u5927\u503c\u5de6\u8fb9\u90e8\u5206 \u9012\u5f52\u6784\u9020\u51fa\u7684\u6700\u5927\u4e8c\u53c9\u6811\u3002
    4. \n\t
    5. \u53f3\u5b50\u6811\u662f\u901a\u8fc7\u6570\u7ec4\u4e2d \u6700\u5927\u503c\u53f3\u8fb9\u90e8\u5206 \u9012\u5f52\u6784\u9020\u51fa\u7684\u6700\u5927\u4e8c\u53c9\u6811\u3002
    6. \n
    \n\n

    \u8fd4\u56de\u6709\u7ed9\u5b9a\u6570\u7ec4 nums \u6784\u5efa\u7684 \u6700\u5927\u4e8c\u53c9\u6811 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1anums = [3,2,1,6,0,5]\n\u8f93\u51fa\uff1a[6,3,5,null,2,0,null,null,1]\n\u89e3\u91ca\uff1a\u9012\u5f52\u8c03\u7528\u5982\u4e0b\u6240\u793a\uff1a\n- [3,2,1,6,0,5] \u4e2d\u7684\u6700\u5927\u503c\u662f 6 \uff0c\u5de6\u8fb9\u90e8\u5206\u662f [3,2,1] \uff0c\u53f3\u8fb9\u90e8\u5206\u662f [0,5] \u3002\n    - [3,2,1] \u4e2d\u7684\u6700\u5927\u503c\u662f 3 \uff0c\u5de6\u8fb9\u90e8\u5206\u662f [] \uff0c\u53f3\u8fb9\u90e8\u5206\u662f [2,1] \u3002\n        - \u7a7a\u6570\u7ec4\uff0c\u65e0\u5b50\u8282\u70b9\u3002\n        - [2,1] \u4e2d\u7684\u6700\u5927\u503c\u662f 2 \uff0c\u5de6\u8fb9\u90e8\u5206\u662f [] \uff0c\u53f3\u8fb9\u90e8\u5206\u662f [1] \u3002\n            - \u7a7a\u6570\u7ec4\uff0c\u65e0\u5b50\u8282\u70b9\u3002\n            - \u53ea\u6709\u4e00\u4e2a\u5143\u7d20\uff0c\u6240\u4ee5\u5b50\u8282\u70b9\u662f\u4e00\u4e2a\u503c\u4e3a 1 \u7684\u8282\u70b9\u3002\n    - [0,5] \u4e2d\u7684\u6700\u5927\u503c\u662f 5 \uff0c\u5de6\u8fb9\u90e8\u5206\u662f [0] \uff0c\u53f3\u8fb9\u90e8\u5206\u662f [] \u3002\n        - \u53ea\u6709\u4e00\u4e2a\u5143\u7d20\uff0c\u6240\u4ee5\u5b50\u8282\u70b9\u662f\u4e00\u4e2a\u503c\u4e3a 0 \u7684\u8282\u70b9\u3002\n        - \u7a7a\u6570\u7ec4\uff0c\u65e0\u5b50\u8282\u70b9\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1anums = [3,2,1]\n\u8f93\u51fa\uff1a[3,null,2,null,1]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 1000
    • \n\t
    • 0 <= nums[i] <= 1000
    • \n\t
    • nums \u4e2d\u7684\u6240\u6709\u6574\u6570 \u4e92\u4e0d\u76f8\u540c
    • \n
    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* constructMaximumBinaryTree(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode constructMaximumBinaryTree(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def constructMaximumBinaryTree(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: TreeNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def constructMaximumBinaryTree(self, nums: List[int]) -> TreeNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* constructMaximumBinaryTree(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode ConstructMaximumBinaryTree(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {number[]} nums\n * @return {TreeNode}\n */\nvar constructMaximumBinaryTree = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {Integer[]} nums\n# @return {TreeNode}\ndef construct_maximum_binary_tree(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func constructMaximumBinaryTree(_ nums: [Int]) -> TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc constructMaximumBinaryTree(nums []int) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def constructMaximumBinaryTree(nums: Array[Int]): TreeNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun constructMaximumBinaryTree(nums: IntArray): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn construct_maximum_binary_tree(nums: Vec) -> Option>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param Integer[] $nums\n * @return TreeNode\n */\n function constructMaximumBinaryTree($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction constructMaximumBinaryTree(nums: number[]): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (construct-maximum-binary-tree nums)\n (-> (listof exact-integer?) (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0654](https://leetcode-cn.com/problems/maximum-binary-tree)", "[\u6700\u5927\u4e8c\u53c9\u6811](/solution/0600-0699/0654.Maximum%20Binary%20Tree/README.md)", "`\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0654](https://leetcode.com/problems/maximum-binary-tree)", "[Maximum Binary Tree](/solution/0600-0699/0654.Maximum%20Binary%20Tree/README_EN.md)", "`Tree`", "Medium", ""]}, {"question_id": "0653", "frontend_question_id": "0653", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/two-sum-iv-input-is-a-bst", "url_en": "https://leetcode.com/problems/two-sum-iv-input-is-a-bst", "relative_path_cn": "/solution/0600-0699/0653.Two%20Sum%20IV%20-%20Input%20is%20a%20BST/README.md", "relative_path_en": "/solution/0600-0699/0653.Two%20Sum%20IV%20-%20Input%20is%20a%20BST/README_EN.md", "title_cn": "\u4e24\u6570\u4e4b\u548c IV - \u8f93\u5165 BST", "title_en": "Two Sum IV - Input is a BST", "question_title_slug": "two-sum-iv-input-is-a-bst", "content_en": "

    Given the root of a Binary Search Tree and a target number k, return true if there exist two elements in the BST such that their sum is equal to the given target.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [5,3,6,2,4,null,7], k = 9\nOutput: true\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [5,3,6,2,4,null,7], k = 28\nOutput: false\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = [2,1,3], k = 4\nOutput: true\n
    \n\n

    Example 4:

    \n\n
    \nInput: root = [2,1,3], k = 1\nOutput: false\n
    \n\n

    Example 5:

    \n\n
    \nInput: root = [2,1,3], k = 3\nOutput: true\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 104].
    • \n\t
    • -104 <= Node.val <= 104
    • \n\t
    • root is guaranteed to be a valid binary search tree.
    • \n\t
    • -105 <= k <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u641c\u7d22\u6811\u548c\u4e00\u4e2a\u76ee\u6807\u7ed3\u679c\uff0c\u5982\u679c BST \u4e2d\u5b58\u5728\u4e24\u4e2a\u5143\u7d20\u4e14\u5b83\u4eec\u7684\u548c\u7b49\u4e8e\u7ed9\u5b9a\u7684\u76ee\u6807\u7ed3\u679c\uff0c\u5219\u8fd4\u56de true\u3002

    \n\n

    \u6848\u4f8b 1:

    \n\n
    \n\u8f93\u5165: \n    5\n   / \\\n  3   6\n / \\   \\\n2   4   7\n\nTarget = 9\n\n\u8f93\u51fa: True\n
    \n\n

     

    \n\n

    \u6848\u4f8b 2:

    \n\n
    \n\u8f93\u5165: \n    5\n   / \\\n  3   6\n / \\   \\\n2   4   7\n\nTarget = 28\n\n\u8f93\u51fa: False\n
    \n\n

     

    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n bool findTarget(TreeNode* root, int k) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public boolean findTarget(TreeNode root, int k) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def findTarget(self, root, k):\n \"\"\"\n :type root: TreeNode\n :type k: int\n :rtype: bool\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def findTarget(self, root: TreeNode, k: int) -> bool:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nbool findTarget(struct TreeNode* root, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public bool FindTarget(TreeNode root, int k) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number} k\n * @return {boolean}\n */\nvar findTarget = function(root, k) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @param {Integer} k\n# @return {Boolean}\ndef find_target(root, k)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func findTarget(_ root: TreeNode?, _ k: Int) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc findTarget(root *TreeNode, k int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def findTarget(root: TreeNode, k: Int): Boolean = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun findTarget(root: TreeNode?, k: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn find_target(root: Option>>, k: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param Integer $k\n * @return Boolean\n */\n function findTarget($root, $k) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction findTarget(root: TreeNode | null, k: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (find-target root k)\n (-> (or/c tree-node? #f) exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0653](https://leetcode-cn.com/problems/two-sum-iv-input-is-a-bst)", "[\u4e24\u6570\u4e4b\u548c IV - \u8f93\u5165 BST](/solution/0600-0699/0653.Two%20Sum%20IV%20-%20Input%20is%20a%20BST/README.md)", "`\u6811`", "\u7b80\u5355", ""], "md_table_row_en": ["[0653](https://leetcode.com/problems/two-sum-iv-input-is-a-bst)", "[Two Sum IV - Input is a BST](/solution/0600-0699/0653.Two%20Sum%20IV%20-%20Input%20is%20a%20BST/README_EN.md)", "`Tree`", "Easy", ""]}, {"question_id": "0652", "frontend_question_id": "0652", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-duplicate-subtrees", "url_en": "https://leetcode.com/problems/find-duplicate-subtrees", "relative_path_cn": "/solution/0600-0699/0652.Find%20Duplicate%20Subtrees/README.md", "relative_path_en": "/solution/0600-0699/0652.Find%20Duplicate%20Subtrees/README_EN.md", "title_cn": "\u5bfb\u627e\u91cd\u590d\u7684\u5b50\u6811", "title_en": "Find Duplicate Subtrees", "question_title_slug": "find-duplicate-subtrees", "content_en": "

    Given the root of a binary tree, return all duplicate subtrees.

    \n\n

    For each kind of duplicate subtrees, you only need to return the root node of any one of them.

    \n\n

    Two trees are duplicate if they have the same structure with the same node values.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,2,3,4,null,2,4,null,null,4]\nOutput: [[2,4],[4]]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [2,1,1]\nOutput: [[1]]\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: root = [2,2,2,3,null,3,null]\nOutput: [[2,3],[3]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of the nodes in the tree will be in the range [1, 10^4]
    • \n\t
    • -200 <= Node.val <= 200
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u68f5\u4e8c\u53c9\u6811\uff0c\u8fd4\u56de\u6240\u6709\u91cd\u590d\u7684\u5b50\u6811\u3002\u5bf9\u4e8e\u540c\u4e00\u7c7b\u7684\u91cd\u590d\u5b50\u6811\uff0c\u4f60\u53ea\u9700\u8981\u8fd4\u56de\u5176\u4e2d\u4efb\u610f\u4e00\u68f5\u7684\u6839\u7ed3\u70b9\u5373\u53ef\u3002

    \n\n

    \u4e24\u68f5\u6811\u91cd\u590d\u662f\u6307\u5b83\u4eec\u5177\u6709\u76f8\u540c\u7684\u7ed3\u6784\u4ee5\u53ca\u76f8\u540c\u7684\u7ed3\u70b9\u503c\u3002

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
            1\n       / \\\n      2   3\n     /   / \\\n    4   2   4\n       /\n      4\n
    \n\n

    \u4e0b\u9762\u662f\u4e24\u4e2a\u91cd\u590d\u7684\u5b50\u6811\uff1a

    \n\n
          2\n     /\n    4\n
    \n\n

    \u548c

    \n\n
        4\n
    \n\n

    \u56e0\u6b64\uff0c\u4f60\u9700\u8981\u4ee5\u5217\u8868\u7684\u5f62\u5f0f\u8fd4\u56de\u4e0a\u8ff0\u91cd\u590d\u5b50\u6811\u7684\u6839\u7ed3\u70b9\u3002

    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector findDuplicateSubtrees(TreeNode* root) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public List findDuplicateSubtrees(TreeNode root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def findDuplicateSubtrees(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: List[TreeNode]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def findDuplicateSubtrees(self, root: TreeNode) -> List[TreeNode]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nstruct TreeNode** findDuplicateSubtrees(struct TreeNode* root, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public IList FindDuplicateSubtrees(TreeNode root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {TreeNode[]}\n */\nvar findDuplicateSubtrees = function(root) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {TreeNode[]}\ndef find_duplicate_subtrees(root)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func findDuplicateSubtrees(_ root: TreeNode?) -> [TreeNode?] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc findDuplicateSubtrees(root *TreeNode) []*TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def findDuplicateSubtrees(root: TreeNode): List[TreeNode] = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun findDuplicateSubtrees(root: TreeNode?): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn find_duplicate_subtrees(root: Option>>) -> Vec>>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return TreeNode[]\n */\n function findDuplicateSubtrees($root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction findDuplicateSubtrees(root: TreeNode | null): Array {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (find-duplicate-subtrees root)\n (-> (or/c tree-node? #f) (listof (or/c tree-node? #f)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0652](https://leetcode-cn.com/problems/find-duplicate-subtrees)", "[\u5bfb\u627e\u91cd\u590d\u7684\u5b50\u6811](/solution/0600-0699/0652.Find%20Duplicate%20Subtrees/README.md)", "`\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0652](https://leetcode.com/problems/find-duplicate-subtrees)", "[Find Duplicate Subtrees](/solution/0600-0699/0652.Find%20Duplicate%20Subtrees/README_EN.md)", "`Tree`", "Medium", ""]}, {"question_id": "0651", "frontend_question_id": "0651", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/4-keys-keyboard", "url_en": "https://leetcode.com/problems/4-keys-keyboard", "relative_path_cn": "/solution/0600-0699/0651.4%20Keys%20Keyboard/README.md", "relative_path_en": "/solution/0600-0699/0651.4%20Keys%20Keyboard/README_EN.md", "title_cn": "4\u952e\u952e\u76d8", "title_en": "4 Keys Keyboard", "question_title_slug": "4-keys-keyboard", "content_en": "

    Imagine you have a special keyboard with the following keys:

    \n\n
      \n\t
    • A: Print one 'A' on the screen.
    • \n\t
    • Ctrl-A: Select the whole screen.
    • \n\t
    • Ctrl-C: Copy selection to buffer.
    • \n\t
    • Ctrl-V: Print buffer on screen appending it after what has already been printed.
    • \n
    \n\n

    Given an integer n, return the maximum number of 'A' you can print on the screen with at most n presses on the keys.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 3\nOutput: 3\nExplanation: We can at most get 3 A's on screen by pressing the following key sequence:\nA, A, A\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 7\nOutput: 9\nExplanation: We can at most get 9 A's on screen by pressing following key sequence:\nA, A, A, Ctrl A, Ctrl C, Ctrl V, Ctrl V\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 50
    • \n
    \n", "content_cn": "

    \u5047\u8bbe\u4f60\u6709\u4e00\u4e2a\u7279\u6b8a\u7684\u952e\u76d8\u5305\u542b\u4e0b\u9762\u7684\u6309\u952e\uff1a

    \n\n

    Key 1: (A)\uff1a\u5728\u5c4f\u5e55\u4e0a\u6253\u5370\u4e00\u4e2a 'A'\u3002

    \n\n

    Key 2: (Ctrl-A)\uff1a\u9009\u4e2d\u6574\u4e2a\u5c4f\u5e55\u3002

    \n\n

    Key 3: (Ctrl-C)\uff1a\u590d\u5236\u9009\u4e2d\u533a\u57df\u5230\u7f13\u51b2\u533a\u3002

    \n\n

    Key 4: (Ctrl-V)\uff1a\u5c06\u7f13\u51b2\u533a\u5185\u5bb9\u8f93\u51fa\u5230\u4e0a\u6b21\u8f93\u5165\u7684\u7ed3\u675f\u4f4d\u7f6e\uff0c\u5e76\u663e\u793a\u5728\u5c4f\u5e55\u4e0a\u3002

    \n\n

    \u73b0\u5728\uff0c\u4f60\u53ea\u53ef\u4ee5\u6309\u952e N \u6b21\uff08\u4f7f\u7528\u4e0a\u8ff0\u56db\u79cd\u6309\u952e\uff09\uff0c\u8bf7\u95ee\u5c4f\u5e55\u4e0a\u6700\u591a\u53ef\u4ee5\u663e\u793a\u51e0\u4e2a 'A'\u5462\uff1f

    \n\n

    \u6837\u4f8b 1:

    \n\n
    \u8f93\u5165: N = 3\n\u8f93\u51fa: 3\n\u89e3\u91ca: \n\u6211\u4eec\u6700\u591a\u53ef\u4ee5\u5728\u5c4f\u5e55\u4e0a\u663e\u793a\u4e09\u4e2a'A'\u901a\u8fc7\u5982\u4e0b\u987a\u5e8f\u6309\u952e\uff1a\nA, A, A\n
    \n\n

     

    \n\n

    \u6837\u4f8b 2:

    \n\n
    \u8f93\u5165: N = 7\n\u8f93\u51fa: 9\n\u89e3\u91ca: \n\u6211\u4eec\u6700\u591a\u53ef\u4ee5\u5728\u5c4f\u5e55\u4e0a\u663e\u793a\u4e5d\u4e2a'A'\u901a\u8fc7\u5982\u4e0b\u987a\u5e8f\u6309\u952e\uff1a\nA, A, A, Ctrl A, Ctrl C, Ctrl V, Ctrl V\n
    \n\n

     

    \n\n

    \u6ce8\u91ca:

    \n\n
      \n\t
    1. 1 <= N <= 50
    2. \n\t
    3. \u7ed3\u679c\u4e0d\u4f1a\u8d85\u8fc7 32 \u4f4d\u6709\u7b26\u53f7\u6574\u6570\u8303\u56f4\u3002
    4. \n
    \n\n

     

    \n", "tags_en": ["Greedy", "Math", "Dynamic Programming"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u5b66", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxA(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxA(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxA(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxA(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxA(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxA(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar maxA = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef max_a(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxA(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxA(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxA(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxA(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_a(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function maxA($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxA(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-a n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0651](https://leetcode-cn.com/problems/4-keys-keyboard)", "[4\u952e\u952e\u76d8](/solution/0600-0699/0651.4%20Keys%20Keyboard/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u5b66`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0651](https://leetcode.com/problems/4-keys-keyboard)", "[4 Keys Keyboard](/solution/0600-0699/0651.4%20Keys%20Keyboard/README_EN.md)", "`Greedy`,`Math`,`Dynamic Programming`", "Medium", "\ud83d\udd12"]}, {"question_id": "0650", "frontend_question_id": "0650", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/2-keys-keyboard", "url_en": "https://leetcode.com/problems/2-keys-keyboard", "relative_path_cn": "/solution/0600-0699/0650.2%20Keys%20Keyboard/README.md", "relative_path_en": "/solution/0600-0699/0650.2%20Keys%20Keyboard/README_EN.md", "title_cn": "\u53ea\u6709\u4e24\u4e2a\u952e\u7684\u952e\u76d8", "title_en": "2 Keys Keyboard", "question_title_slug": "2-keys-keyboard", "content_en": "

    There is only one character 'A' on the screen of a notepad. You can perform two operations on this notepad for each step:

    \n\n
      \n\t
    • Copy All: You can copy all the characters present on the screen (a partial copy is not allowed).
    • \n\t
    • Paste: You can paste the characters which are copied last time.
    • \n
    \n\n

    Given an integer n, return the minimum number of operations to get the character 'A' exactly n times on the screen.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 3\nOutput: 3\nExplanation: Intitally, we have one character 'A'.\nIn step 1, we use Copy All operation.\nIn step 2, we use Paste operation to get 'AA'.\nIn step 3, we use Paste operation to get 'AAA'.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 1\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 1000
    • \n
    \n", "content_cn": "

    \u6700\u521d\u5728\u4e00\u4e2a\u8bb0\u4e8b\u672c\u4e0a\u53ea\u6709\u4e00\u4e2a\u5b57\u7b26 'A'\u3002\u4f60\u6bcf\u6b21\u53ef\u4ee5\u5bf9\u8fd9\u4e2a\u8bb0\u4e8b\u672c\u8fdb\u884c\u4e24\u79cd\u64cd\u4f5c\uff1a

    \n\n
      \n\t
    1. Copy All (\u590d\u5236\u5168\u90e8) : \u4f60\u53ef\u4ee5\u590d\u5236\u8fd9\u4e2a\u8bb0\u4e8b\u672c\u4e2d\u7684\u6240\u6709\u5b57\u7b26(\u90e8\u5206\u7684\u590d\u5236\u662f\u4e0d\u5141\u8bb8\u7684)\u3002
    2. \n\t
    3. Paste (\u7c98\u8d34) : \u4f60\u53ef\u4ee5\u7c98\u8d34\u4f60\u4e0a\u4e00\u6b21\u590d\u5236\u7684\u5b57\u7b26\u3002
    4. \n
    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u6570\u5b57 n \u3002\u4f60\u9700\u8981\u4f7f\u7528\u6700\u5c11\u7684\u64cd\u4f5c\u6b21\u6570\uff0c\u5728\u8bb0\u4e8b\u672c\u4e2d\u6253\u5370\u51fa\u6070\u597d n \u4e2a 'A'\u3002\u8f93\u51fa\u80fd\u591f\u6253\u5370\u51fa n \u4e2a 'A' \u7684\u6700\u5c11\u64cd\u4f5c\u6b21\u6570\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: 3\n\u8f93\u51fa: 3\n\u89e3\u91ca:\n\u6700\u521d, \u6211\u4eec\u53ea\u6709\u4e00\u4e2a\u5b57\u7b26 'A'\u3002\n\u7b2c 1 \u6b65, \u6211\u4eec\u4f7f\u7528 Copy All \u64cd\u4f5c\u3002\n\u7b2c 2 \u6b65, \u6211\u4eec\u4f7f\u7528 Paste \u64cd\u4f5c\u6765\u83b7\u5f97 'AA'\u3002\n\u7b2c 3 \u6b65, \u6211\u4eec\u4f7f\u7528 Paste \u64cd\u4f5c\u6765\u83b7\u5f97 'AAA'\u3002\n
    \n\n

    \u8bf4\u660e:

    \n\n
      \n\t
    1. n \u7684\u53d6\u503c\u8303\u56f4\u662f [1, 1000] \u3002
    2. \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minSteps(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minSteps(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minSteps(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minSteps(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minSteps(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinSteps(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar minSteps = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef min_steps(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minSteps(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minSteps(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minSteps(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minSteps(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_steps(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function minSteps($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minSteps(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-steps n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0650](https://leetcode-cn.com/problems/2-keys-keyboard)", "[\u53ea\u6709\u4e24\u4e2a\u952e\u7684\u952e\u76d8](/solution/0600-0699/0650.2%20Keys%20Keyboard/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0650](https://leetcode.com/problems/2-keys-keyboard)", "[2 Keys Keyboard](/solution/0600-0699/0650.2%20Keys%20Keyboard/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0649", "frontend_question_id": "0649", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/dota2-senate", "url_en": "https://leetcode.com/problems/dota2-senate", "relative_path_cn": "/solution/0600-0699/0649.Dota2%20Senate/README.md", "relative_path_en": "/solution/0600-0699/0649.Dota2%20Senate/README_EN.md", "title_cn": "Dota2 \u53c2\u8bae\u9662", "title_en": "Dota2 Senate", "question_title_slug": "dota2-senate", "content_en": "

    In the world of Dota2, there are two parties: the Radiant and the Dire.

    \n\n

    The Dota2 senate consists of senators coming from two parties. Now the Senate wants to decide on a change in the Dota2 game. The voting for this change is a round-based procedure. In each round, each senator can exercise one of the two rights:

    \n\n
      \n\t
    • Ban one senator's right: A senator can make another senator lose all his rights in this and all the following rounds.
    • \n\t
    • Announce the victory: If this senator found the senators who still have rights to vote are all from the same party, he can announce the victory and decide on the change in the game.
    • \n
    \n\n

    Given a string senate representing each senator's party belonging. The character 'R' and 'D' represent the Radiant party and the Dire party. Then if there are n senators, the size of the given string will be n.

    \n\n

    The round-based procedure starts from the first senator to the last senator in the given order. This procedure will last until the end of voting. All the senators who have lost their rights will be skipped during the procedure.

    \n\n

    Suppose every senator is smart enough and will play the best strategy for his own party. Predict which party will finally announce the victory and change the Dota2 game. The output should be "Radiant" or "Dire".

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: senate = "RD"\nOutput: "Radiant"\nExplanation: \nThe first senator comes from Radiant and he can just ban the next senator's right in round 1. \nAnd the second senator can't exercise any rights anymore since his right has been banned. \nAnd in round 2, the first senator can just announce the victory since he is the only guy in the senate who can vote.\n
    \n\n

    Example 2:

    \n\n
    \nInput: senate = "RDD"\nOutput: "Dire"\nExplanation: \nThe first senator comes from Radiant and he can just ban the next senator's right in round 1. \nAnd the second senator can't exercise any rights anymore since his right has been banned. \nAnd the third senator comes from Dire and he can ban the first senator's right in round 1. \nAnd in round 2, the third senator can just announce the victory since he is the only guy in the senate who can vote.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == senate.length
    • \n\t
    • 1 <= n <= 104
    • \n\t
    • senate[i] is either 'R' or 'D'.
    • \n
    \n", "content_cn": "

    Dota2 \u7684\u4e16\u754c\u91cc\u6709\u4e24\u4e2a\u9635\u8425\uff1aRadiant(\u5929\u8f89)\u548c\u00a0Dire(\u591c\u9b47)

    \n\n

    Dota2 \u53c2\u8bae\u9662\u7531\u6765\u81ea\u4e24\u6d3e\u7684\u53c2\u8bae\u5458\u7ec4\u6210\u3002\u73b0\u5728\u53c2\u8bae\u9662\u5e0c\u671b\u5bf9\u4e00\u4e2a Dota2 \u6e38\u620f\u91cc\u7684\u6539\u53d8\u4f5c\u51fa\u51b3\u5b9a\u3002\u4ed6\u4eec\u4ee5\u4e00\u4e2a\u57fa\u4e8e\u8f6e\u4e3a\u8fc7\u7a0b\u7684\u6295\u7968\u8fdb\u884c\u3002\u5728\u6bcf\u4e00\u8f6e\u4e2d\uff0c\u6bcf\u4e00\u4f4d\u53c2\u8bae\u5458\u90fd\u53ef\u4ee5\u884c\u4f7f\u4e24\u9879\u6743\u5229\u4e2d\u7684\u4e00\u9879\uff1a

    \n\n
      \n\t
    1. \n\t

      \u7981\u6b62\u4e00\u540d\u53c2\u8bae\u5458\u7684\u6743\u5229\uff1a

      \n\n\t

      \u53c2\u8bae\u5458\u53ef\u4ee5\u8ba9\u53e6\u4e00\u4f4d\u53c2\u8bae\u5458\u5728\u8fd9\u4e00\u8f6e\u548c\u968f\u540e\u7684\u51e0\u8f6e\u4e2d\u4e27\u5931\u6240\u6709\u7684\u6743\u5229\u3002

      \n\t
    2. \n\t
    3. \n\t

      \u5ba3\u5e03\u80dc\u5229\uff1a

      \n\t
    4. \n
    \n\n

    \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u5982\u679c\u53c2\u8bae\u5458\u53d1\u73b0\u6709\u6743\u5229\u6295\u7968\u7684\u53c2\u8bae\u5458\u90fd\u662f\u540c\u4e00\u4e2a\u9635\u8425\u7684\uff0c\u4ed6\u53ef\u4ee5\u5ba3\u5e03\u80dc\u5229\u5e76\u51b3\u5b9a\u5728\u6e38\u620f\u4e2d\u7684\u6709\u5173\u53d8\u5316\u3002

    \n\n

    \u00a0

    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\u4ee3\u8868\u6bcf\u4e2a\u53c2\u8bae\u5458\u7684\u9635\u8425\u3002\u5b57\u6bcd \u201cR\u201d \u548c \u201cD\u201d \u5206\u522b\u4ee3\u8868\u4e86\u00a0Radiant\uff08\u5929\u8f89\uff09\u548c\u00a0Dire\uff08\u591c\u9b47\uff09\u3002\u7136\u540e\uff0c\u5982\u679c\u6709 n \u4e2a\u53c2\u8bae\u5458\uff0c\u7ed9\u5b9a\u5b57\u7b26\u4e32\u7684\u5927\u5c0f\u5c06\u662f\u00a0n\u3002

    \n\n

    \u4ee5\u8f6e\u4e3a\u57fa\u7840\u7684\u8fc7\u7a0b\u4ece\u7ed9\u5b9a\u987a\u5e8f\u7684\u7b2c\u4e00\u4e2a\u53c2\u8bae\u5458\u5f00\u59cb\u5230\u6700\u540e\u4e00\u4e2a\u53c2\u8bae\u5458\u7ed3\u675f\u3002\u8fd9\u4e00\u8fc7\u7a0b\u5c06\u6301\u7eed\u5230\u6295\u7968\u7ed3\u675f\u3002\u6240\u6709\u5931\u53bb\u6743\u5229\u7684\u53c2\u8bae\u5458\u5c06\u5728\u8fc7\u7a0b\u4e2d\u88ab\u8df3\u8fc7\u3002

    \n\n

    \u5047\u8bbe\u6bcf\u4e00\u4f4d\u53c2\u8bae\u5458\u90fd\u8db3\u591f\u806a\u660e\uff0c\u4f1a\u4e3a\u81ea\u5df1\u7684\u653f\u515a\u505a\u51fa\u6700\u597d\u7684\u7b56\u7565\uff0c\u4f60\u9700\u8981\u9884\u6d4b\u54ea\u4e00\u65b9\u6700\u7ec8\u4f1a\u5ba3\u5e03\u80dc\u5229\u5e76\u5728 Dota2 \u6e38\u620f\u4e2d\u51b3\u5b9a\u6539\u53d8\u3002\u8f93\u51fa\u5e94\u8be5\u662f\u00a0Radiant\u00a0\u6216\u00a0Dire\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\"RD\"\n\u8f93\u51fa\uff1a\"Radiant\"\n\u89e3\u91ca\uff1a\u7b2c\u4e00\u4e2a\u53c2\u8bae\u5458\u6765\u81ea Radiant \u9635\u8425\u5e76\u4e14\u4ed6\u53ef\u4ee5\u4f7f\u7528\u7b2c\u4e00\u9879\u6743\u5229\u8ba9\u7b2c\u4e8c\u4e2a\u53c2\u8bae\u5458\u5931\u53bb\u6743\u529b\uff0c\u56e0\u6b64\u7b2c\u4e8c\u4e2a\u53c2\u8bae\u5458\u5c06\u88ab\u8df3\u8fc7\u56e0\u4e3a\u4ed6\u6ca1\u6709\u4efb\u4f55\u6743\u5229\u3002\u7136\u540e\u5728\u7b2c\u4e8c\u8f6e\u7684\u65f6\u5019\uff0c\u7b2c\u4e00\u4e2a\u53c2\u8bae\u5458\u53ef\u4ee5\u5ba3\u5e03\u80dc\u5229\uff0c\u56e0\u4e3a\u4ed6\u662f\u552f\u4e00\u4e00\u4e2a\u6709\u6295\u7968\u6743\u7684\u4eba\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\"RDD\"\n\u8f93\u51fa\uff1a\"Dire\"\n\u89e3\u91ca\uff1a\n\u7b2c\u4e00\u8f6e\u4e2d,\u7b2c\u4e00\u4e2a\u6765\u81ea Radiant \u9635\u8425\u7684\u53c2\u8bae\u5458\u53ef\u4ee5\u4f7f\u7528\u7b2c\u4e00\u9879\u6743\u5229\u7981\u6b62\u7b2c\u4e8c\u4e2a\u53c2\u8bae\u5458\u7684\u6743\u5229\n\u7b2c\u4e8c\u4e2a\u6765\u81ea Dire \u9635\u8425\u7684\u53c2\u8bae\u5458\u4f1a\u88ab\u8df3\u8fc7\u56e0\u4e3a\u4ed6\u7684\u6743\u5229\u88ab\u7981\u6b62\n\u7b2c\u4e09\u4e2a\u6765\u81ea Dire \u9635\u8425\u7684\u53c2\u8bae\u5458\u53ef\u4ee5\u4f7f\u7528\u4ed6\u7684\u7b2c\u4e00\u9879\u6743\u5229\u7981\u6b62\u7b2c\u4e00\u4e2a\u53c2\u8bae\u5458\u7684\u6743\u5229\n\u56e0\u6b64\u5728\u7b2c\u4e8c\u8f6e\u53ea\u5269\u4e0b\u7b2c\u4e09\u4e2a\u53c2\u8bae\u5458\u62e5\u6709\u6295\u7968\u7684\u6743\u5229,\u4e8e\u662f\u4ed6\u53ef\u4ee5\u5ba3\u5e03\u80dc\u5229\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u7ed9\u5b9a\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u5728 [1, 10,000] \u4e4b\u95f4.
    • \n
    \n\n

    \u00a0

    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string predictPartyVictory(string senate) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String predictPartyVictory(String senate) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def predictPartyVictory(self, senate):\n \"\"\"\n :type senate: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def predictPartyVictory(self, senate: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * predictPartyVictory(char * senate){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string PredictPartyVictory(string senate) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} senate\n * @return {string}\n */\nvar predictPartyVictory = function(senate) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} senate\n# @return {String}\ndef predict_party_victory(senate)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func predictPartyVictory(_ senate: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func predictPartyVictory(senate string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def predictPartyVictory(senate: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun predictPartyVictory(senate: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn predict_party_victory(senate: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $senate\n * @return String\n */\n function predictPartyVictory($senate) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function predictPartyVictory(senate: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (predict-party-victory senate)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0649](https://leetcode-cn.com/problems/dota2-senate)", "[Dota2 \u53c2\u8bae\u9662](/solution/0600-0699/0649.Dota2%20Senate/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0649](https://leetcode.com/problems/dota2-senate)", "[Dota2 Senate](/solution/0600-0699/0649.Dota2%20Senate/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "0648", "frontend_question_id": "0648", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/replace-words", "url_en": "https://leetcode.com/problems/replace-words", "relative_path_cn": "/solution/0600-0699/0648.Replace%20Words/README.md", "relative_path_en": "/solution/0600-0699/0648.Replace%20Words/README_EN.md", "title_cn": "\u5355\u8bcd\u66ff\u6362", "title_en": "Replace Words", "question_title_slug": "replace-words", "content_en": "

    In English, we have a concept called root, which can be followed by some other word to form another longer word - let's call this word successor. For example, when the root "an" is followed by the successor word "other", we can form a new word "another".

    \n\n

    Given a dictionary consisting of many roots and a sentence consisting of words separated by spaces, replace all the successors in the sentence with the root forming it. If a successor can be replaced by more than one root, replace it with the root that has the shortest length.

    \n\n

    Return the sentence after the replacement.

    \n\n

     

    \n

    Example 1:

    \n
    Input: dictionary = [\"cat\",\"bat\",\"rat\"], sentence = \"the cattle was rattled by the battery\"\nOutput: \"the cat was rat by the bat\"\n

    Example 2:

    \n
    Input: dictionary = [\"a\",\"b\",\"c\"], sentence = \"aadsfasf absbs bbab cadsfafs\"\nOutput: \"a a b c\"\n

    Example 3:

    \n
    Input: dictionary = [\"a\", \"aa\", \"aaa\", \"aaaa\"], sentence = \"a aa a aaaa aaa aaa aaa aaaaaa bbb baba ababa\"\nOutput: \"a a a a a a a a bbb baba a\"\n

    Example 4:

    \n
    Input: dictionary = [\"catt\",\"cat\",\"bat\",\"rat\"], sentence = \"the cattle was rattled by the battery\"\nOutput: \"the cat was rat by the bat\"\n

    Example 5:

    \n
    Input: dictionary = [\"ac\",\"ab\"], sentence = \"it is abnormal that this solution is accepted\"\nOutput: \"it is ab that this solution is ac\"\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= dictionary.length <= 1000
    • \n\t
    • 1 <= dictionary[i].length <= 100
    • \n\t
    • dictionary[i] consists of only lower-case letters.
    • \n\t
    • 1 <= sentence.length <= 10^6
    • \n\t
    • sentence consists of only lower-case letters and spaces.
    • \n\t
    • The number of words in sentence is in the range [1, 1000]
    • \n\t
    • The length of each word in sentence is in the range [1, 1000]
    • \n\t
    • Each two consecutive words in sentence will be separated by exactly one space.
    • \n\t
    • sentence does not have leading or trailing spaces.
    • \n
    \n", "content_cn": "

    \u5728\u82f1\u8bed\u4e2d\uff0c\u6211\u4eec\u6709\u4e00\u4e2a\u53eb\u505a \u8bcd\u6839(root)\u7684\u6982\u5ff5\uff0c\u5b83\u53ef\u4ee5\u8ddf\u7740\u5176\u4ed6\u4e00\u4e9b\u8bcd\u7ec4\u6210\u53e6\u4e00\u4e2a\u8f83\u957f\u7684\u5355\u8bcd——\u6211\u4eec\u79f0\u8fd9\u4e2a\u8bcd\u4e3a \u7ee7\u627f\u8bcd(successor)\u3002\u4f8b\u5982\uff0c\u8bcd\u6839an\uff0c\u8ddf\u968f\u7740\u5355\u8bcd other(\u5176\u4ed6)\uff0c\u53ef\u4ee5\u5f62\u6210\u65b0\u7684\u5355\u8bcd another(\u53e6\u4e00\u4e2a)\u3002

    \n\n

    \u73b0\u5728\uff0c\u7ed9\u5b9a\u4e00\u4e2a\u7531\u8bb8\u591a\u8bcd\u6839\u7ec4\u6210\u7684\u8bcd\u5178\u548c\u4e00\u4e2a\u53e5\u5b50\u3002\u4f60\u9700\u8981\u5c06\u53e5\u5b50\u4e2d\u7684\u6240\u6709\u7ee7\u627f\u8bcd\u7528\u8bcd\u6839\u66ff\u6362\u6389\u3002\u5982\u679c\u7ee7\u627f\u8bcd\u6709\u8bb8\u591a\u53ef\u4ee5\u5f62\u6210\u5b83\u7684\u8bcd\u6839\uff0c\u5219\u7528\u6700\u77ed\u7684\u8bcd\u6839\u66ff\u6362\u5b83\u3002

    \n\n

    \u4f60\u9700\u8981\u8f93\u51fa\u66ff\u6362\u4e4b\u540e\u7684\u53e5\u5b50\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1adictionary = ["cat","bat","rat"], sentence = "the cattle was rattled by the battery"\n\u8f93\u51fa\uff1a"the cat was rat by the bat"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1adictionary = ["a","b","c"], sentence = "aadsfasf absbs bbab cadsfafs"\n\u8f93\u51fa\uff1a"a a b c"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1adictionary = ["a", "aa", "aaa", "aaaa"], sentence = "a aa a aaaa aaa aaa aaa aaaaaa bbb baba ababa"\n\u8f93\u51fa\uff1a"a a a a a a a a bbb baba a"\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1adictionary = ["catt","cat","bat","rat"], sentence = "the cattle was rattled by the battery"\n\u8f93\u51fa\uff1a"the cat was rat by the bat"\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1adictionary = ["ac","ab"], sentence = "it is abnormal that this solution is accepted"\n\u8f93\u51fa\uff1a"it is ab that this solution is ac"\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= dictionary.length <= 1000
    • \n\t
    • 1 <= dictionary[i].length <= 100
    • \n\t
    • dictionary[i] \u4ec5\u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210\u3002
    • \n\t
    • 1 <= sentence.length <= 10^6
    • \n\t
    • sentence \u4ec5\u7531\u5c0f\u5199\u5b57\u6bcd\u548c\u7a7a\u683c\u7ec4\u6210\u3002
    • \n\t
    • sentence \u4e2d\u5355\u8bcd\u7684\u603b\u91cf\u5728\u8303\u56f4 [1, 1000] \u5185\u3002
    • \n\t
    • sentence \u4e2d\u6bcf\u4e2a\u5355\u8bcd\u7684\u957f\u5ea6\u5728\u8303\u56f4 [1, 1000] \u5185\u3002
    • \n\t
    • sentence \u4e2d\u5355\u8bcd\u4e4b\u95f4\u7531\u4e00\u4e2a\u7a7a\u683c\u9694\u5f00\u3002
    • \n\t
    • sentence \u6ca1\u6709\u524d\u5bfc\u6216\u5c3e\u968f\u7a7a\u683c\u3002
    • \n
    \n", "tags_en": ["Trie", "Hash Table"], "tags_cn": ["\u5b57\u5178\u6811", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string replaceWords(vector& dictionary, string sentence) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String replaceWords(List dictionary, String sentence) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def replaceWords(self, dictionary, sentence):\n \"\"\"\n :type dictionary: List[str]\n :type sentence: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def replaceWords(self, dictionary: List[str], sentence: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * replaceWords(char ** dictionary, int dictionarySize, char * sentence){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ReplaceWords(IList dictionary, string sentence) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} dictionary\n * @param {string} sentence\n * @return {string}\n */\nvar replaceWords = function(dictionary, sentence) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} dictionary\n# @param {String} sentence\n# @return {String}\ndef replace_words(dictionary, sentence)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func replaceWords(_ dictionary: [String], _ sentence: String) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func replaceWords(dictionary []string, sentence string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def replaceWords(dictionary: List[String], sentence: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun replaceWords(dictionary: List, sentence: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn replace_words(dictionary: Vec, sentence: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $dictionary\n * @param String $sentence\n * @return String\n */\n function replaceWords($dictionary, $sentence) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function replaceWords(dictionary: string[], sentence: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (replace-words dictionary sentence)\n (-> (listof string?) string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0648](https://leetcode-cn.com/problems/replace-words)", "[\u5355\u8bcd\u66ff\u6362](/solution/0600-0699/0648.Replace%20Words/README.md)", "`\u5b57\u5178\u6811`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0648](https://leetcode.com/problems/replace-words)", "[Replace Words](/solution/0600-0699/0648.Replace%20Words/README_EN.md)", "`Trie`,`Hash Table`", "Medium", ""]}, {"question_id": "0647", "frontend_question_id": "0647", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/palindromic-substrings", "url_en": "https://leetcode.com/problems/palindromic-substrings", "relative_path_cn": "/solution/0600-0699/0647.Palindromic%20Substrings/README.md", "relative_path_en": "/solution/0600-0699/0647.Palindromic%20Substrings/README_EN.md", "title_cn": "\u56de\u6587\u5b50\u4e32", "title_en": "Palindromic Substrings", "question_title_slug": "palindromic-substrings", "content_en": "

    Given a string s, return the number of palindromic substrings in it.

    \n\n

    A string is a palindrome when it reads the same backward as forward.

    \n\n

    A substring is a contiguous sequence of characters within the string.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "abc"\nOutput: 3\nExplanation: Three palindromic strings: "a", "b", "c".\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "aaa"\nOutput: 6\nExplanation: Six palindromic strings: "a", "a", "a", "aa", "aa", "aaa".\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 1000
    • \n\t
    • s consists of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u4f60\u7684\u4efb\u52a1\u662f\u8ba1\u7b97\u8fd9\u4e2a\u5b57\u7b26\u4e32\u4e2d\u6709\u591a\u5c11\u4e2a\u56de\u6587\u5b50\u4e32\u3002

    \n\n

    \u5177\u6709\u4e0d\u540c\u5f00\u59cb\u4f4d\u7f6e\u6216\u7ed3\u675f\u4f4d\u7f6e\u7684\u5b50\u4e32\uff0c\u5373\u4f7f\u662f\u7531\u76f8\u540c\u7684\u5b57\u7b26\u7ec4\u6210\uff0c\u4e5f\u4f1a\u88ab\u89c6\u4f5c\u4e0d\u540c\u7684\u5b50\u4e32\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a"abc"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u4e09\u4e2a\u56de\u6587\u5b50\u4e32: "a", "b", "c"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a"aaa"\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a6\u4e2a\u56de\u6587\u5b50\u4e32: "a", "a", "a", "aa", "aa", "aaa"
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u8f93\u5165\u7684\u5b57\u7b26\u4e32\u957f\u5ea6\u4e0d\u4f1a\u8d85\u8fc7 1000 \u3002
    • \n
    \n", "tags_en": ["String", "Dynamic Programming"], "tags_cn": ["\u5b57\u7b26\u4e32", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countSubstrings(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countSubstrings(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countSubstrings(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countSubstrings(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countSubstrings(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountSubstrings(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar countSubstrings = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef count_substrings(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countSubstrings(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countSubstrings(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countSubstrings(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countSubstrings(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_substrings(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function countSubstrings($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countSubstrings(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-substrings s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0647](https://leetcode-cn.com/problems/palindromic-substrings)", "[\u56de\u6587\u5b50\u4e32](/solution/0600-0699/0647.Palindromic%20Substrings/README.md)", "`\u5b57\u7b26\u4e32`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0647](https://leetcode.com/problems/palindromic-substrings)", "[Palindromic Substrings](/solution/0600-0699/0647.Palindromic%20Substrings/README_EN.md)", "`String`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0646", "frontend_question_id": "0646", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-length-of-pair-chain", "url_en": "https://leetcode.com/problems/maximum-length-of-pair-chain", "relative_path_cn": "/solution/0600-0699/0646.Maximum%20Length%20of%20Pair%20Chain/README.md", "relative_path_en": "/solution/0600-0699/0646.Maximum%20Length%20of%20Pair%20Chain/README_EN.md", "title_cn": "\u6700\u957f\u6570\u5bf9\u94fe", "title_en": "Maximum Length of Pair Chain", "question_title_slug": "maximum-length-of-pair-chain", "content_en": "

    You are given an array of n pairs pairs where pairs[i] = [lefti, righti] and lefti < righti.

    \n\n

    A pair p2 = [c, d] follows a pair p1 = [a, b] if b < c. A chain of pairs can be formed in this fashion.

    \n\n

    Return the length longest chain which can be formed.

    \n\n

    You do not need to use up all the given intervals. You can select pairs in any order.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: pairs = [[1,2],[2,3],[3,4]]\nOutput: 2\nExplanation: The longest chain is [1,2] -> [3,4].\n
    \n\n

    Example 2:

    \n\n
    \nInput: pairs = [[1,2],[7,8],[4,5]]\nOutput: 3\nExplanation: The longest chain is [1,2] -> [4,5] -> [7,8].\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == pairs.length
    • \n\t
    • 1 <= n <= 1000
    • \n\t
    • -1000 <= lefti < righti < 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u51fa\u00a0n\u00a0\u4e2a\u6570\u5bf9\u3002\u00a0\u5728\u6bcf\u4e00\u4e2a\u6570\u5bf9\u4e2d\uff0c\u7b2c\u4e00\u4e2a\u6570\u5b57\u603b\u662f\u6bd4\u7b2c\u4e8c\u4e2a\u6570\u5b57\u5c0f\u3002

    \n\n

    \u73b0\u5728\uff0c\u6211\u4eec\u5b9a\u4e49\u4e00\u79cd\u8ddf\u968f\u5173\u7cfb\uff0c\u5f53\u4e14\u4ec5\u5f53\u00a0b < c\u00a0\u65f6\uff0c\u6570\u5bf9(c, d)\u00a0\u624d\u53ef\u4ee5\u8ddf\u5728\u00a0(a, b)\u00a0\u540e\u9762\u3002\u6211\u4eec\u7528\u8fd9\u79cd\u5f62\u5f0f\u6765\u6784\u9020\u4e00\u4e2a\u6570\u5bf9\u94fe\u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u6570\u5bf9\u96c6\u5408\uff0c\u627e\u51fa\u80fd\u591f\u5f62\u6210\u7684\u6700\u957f\u6570\u5bf9\u94fe\u7684\u957f\u5ea6\u3002\u4f60\u4e0d\u9700\u8981\u7528\u5230\u6240\u6709\u7684\u6570\u5bf9\uff0c\u4f60\u53ef\u4ee5\u4ee5\u4efb\u4f55\u987a\u5e8f\u9009\u62e9\u5176\u4e2d\u7684\u4e00\u4e9b\u6570\u5bf9\u6765\u6784\u9020\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[[1,2], [2,3], [3,4]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6700\u957f\u7684\u6570\u5bf9\u94fe\u662f [1,2] -> [3,4]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u7ed9\u51fa\u6570\u5bf9\u7684\u4e2a\u6570\u5728\u00a0[1, 1000] \u8303\u56f4\u5185\u3002
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findLongestChain(vector>& pairs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findLongestChain(int[][] pairs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findLongestChain(self, pairs):\n \"\"\"\n :type pairs: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findLongestChain(self, pairs: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findLongestChain(int** pairs, int pairsSize, int* pairsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindLongestChain(int[][] pairs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} pairs\n * @return {number}\n */\nvar findLongestChain = function(pairs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} pairs\n# @return {Integer}\ndef find_longest_chain(pairs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findLongestChain(_ pairs: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findLongestChain(pairs [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findLongestChain(pairs: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findLongestChain(pairs: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_longest_chain(pairs: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $pairs\n * @return Integer\n */\n function findLongestChain($pairs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findLongestChain(pairs: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-longest-chain pairs)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0646](https://leetcode-cn.com/problems/maximum-length-of-pair-chain)", "[\u6700\u957f\u6570\u5bf9\u94fe](/solution/0600-0699/0646.Maximum%20Length%20of%20Pair%20Chain/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0646](https://leetcode.com/problems/maximum-length-of-pair-chain)", "[Maximum Length of Pair Chain](/solution/0600-0699/0646.Maximum%20Length%20of%20Pair%20Chain/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0645", "frontend_question_id": "0645", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/set-mismatch", "url_en": "https://leetcode.com/problems/set-mismatch", "relative_path_cn": "/solution/0600-0699/0645.Set%20Mismatch/README.md", "relative_path_en": "/solution/0600-0699/0645.Set%20Mismatch/README_EN.md", "title_cn": "\u9519\u8bef\u7684\u96c6\u5408", "title_en": "Set Mismatch", "question_title_slug": "set-mismatch", "content_en": "

    You have a set of integers s, which originally contains all the numbers from 1 to n. Unfortunately, due to some error, one of the numbers in s got duplicated to another number in the set, which results in repetition of one number and loss of another number.

    \n\n

    You are given an integer array nums representing the data status of this set after the error.

    \n\n

    Find the number that occurs twice and the number that is missing and return them in the form of an array.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [1,2,2,4]\nOutput: [2,3]\n

    Example 2:

    \n
    Input: nums = [1,1]\nOutput: [1,2]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= nums.length <= 104
    • \n\t
    • 1 <= nums[i] <= 104
    • \n
    \n", "content_cn": "

    \u96c6\u5408 s \u5305\u542b\u4ece 1 \u5230\u00a0n\u00a0\u7684\u6574\u6570\u3002\u4e0d\u5e78\u7684\u662f\uff0c\u56e0\u4e3a\u6570\u636e\u9519\u8bef\uff0c\u5bfc\u81f4\u96c6\u5408\u91cc\u9762\u67d0\u4e00\u4e2a\u6570\u5b57\u590d\u5236\u4e86\u6210\u4e86\u96c6\u5408\u91cc\u9762\u7684\u53e6\u5916\u4e00\u4e2a\u6570\u5b57\u7684\u503c\uff0c\u5bfc\u81f4\u96c6\u5408 \u4e22\u5931\u4e86\u4e00\u4e2a\u6570\u5b57 \u5e76\u4e14 \u6709\u4e00\u4e2a\u6570\u5b57\u91cd\u590d \u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u6570\u7ec4 nums \u4ee3\u8868\u4e86\u96c6\u5408 S \u53d1\u751f\u9519\u8bef\u540e\u7684\u7ed3\u679c\u3002

    \n\n

    \u8bf7\u4f60\u627e\u51fa\u91cd\u590d\u51fa\u73b0\u7684\u6574\u6570\uff0c\u518d\u627e\u5230\u4e22\u5931\u7684\u6574\u6570\uff0c\u5c06\u5b83\u4eec\u4ee5\u6570\u7ec4\u7684\u5f62\u5f0f\u8fd4\u56de\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,2,4]\n\u8f93\u51fa\uff1a[2,3]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,1]\n\u8f93\u51fa\uff1a[1,2]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= nums.length <= 104
    • \n\t
    • 1 <= nums[i] <= 104
    • \n
    \n", "tags_en": ["Hash Table", "Math"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findErrorNums(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] findErrorNums(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findErrorNums(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findErrorNums(self, nums: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* findErrorNums(int* nums, int numsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] FindErrorNums(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar findErrorNums = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer[]}\ndef find_error_nums(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findErrorNums(_ nums: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findErrorNums(nums []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findErrorNums(nums: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findErrorNums(nums: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_error_nums(nums: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer[]\n */\n function findErrorNums($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findErrorNums(nums: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-error-nums nums)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0645](https://leetcode-cn.com/problems/set-mismatch)", "[\u9519\u8bef\u7684\u96c6\u5408](/solution/0600-0699/0645.Set%20Mismatch/README.md)", "`\u54c8\u5e0c\u8868`,`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0645](https://leetcode.com/problems/set-mismatch)", "[Set Mismatch](/solution/0600-0699/0645.Set%20Mismatch/README_EN.md)", "`Hash Table`,`Math`", "Easy", ""]}, {"question_id": "0644", "frontend_question_id": "0644", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/maximum-average-subarray-ii", "url_en": "https://leetcode.com/problems/maximum-average-subarray-ii", "relative_path_cn": "/solution/0600-0699/0644.Maximum%20Average%20Subarray%20II/README.md", "relative_path_en": "/solution/0600-0699/0644.Maximum%20Average%20Subarray%20II/README_EN.md", "title_cn": "\u5b50\u6570\u7ec4\u6700\u5927\u5e73\u5747\u6570 II", "title_en": "Maximum Average Subarray II", "question_title_slug": "maximum-average-subarray-ii", "content_en": "

    You are given an integer array nums consisting of n elements, and an integer k.

    \n\n

    Find a contiguous subarray whose length is greater than or equal to k that has the maximum average value and return this value. Any answer with a calculation error less than 10-5 will be accepted.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,12,-5,-6,50,3], k = 4\nOutput: 12.75000\nExplanation:\n- When the length is 4, averages are [0.5, 12.75, 10.5] and the maximum average is 12.75\n- When the length is 5, averages are [10.4, 10.8] and the maximum average is 10.8\n- When the length is 6, averages are [9.16667] and the maximum average is 9.16667\nThe maximum average is when we choose a subarray of length 4 (i.e., the sub array [12, -5, -6, 50]) which has the max average 12.75, so we return 12.75\nNote that we do not consider the subarrays of length < 4.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [5], k = 1\nOutput: 5.00000\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= k <= n <= 104
    • \n\t
    • -104 <= nums[i] <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5305\u542b n \u4e2a\u6574\u6570\u7684\u6570\u7ec4 nums \uff0c\u548c\u4e00\u4e2a\u6574\u6570 k \u3002

    \n\n

    \u8bf7\u4f60\u627e\u51fa \u957f\u5ea6\u5927\u4e8e\u7b49\u4e8e k \u4e14\u542b\u6700\u5927\u5e73\u5747\u503c\u7684\u8fde\u7eed\u5b50\u6570\u7ec4\u3002\u5e76\u8f93\u51fa\u8fd9\u4e2a\u6700\u5927\u5e73\u5747\u503c\u3002\u4efb\u4f55\u8ba1\u7b97\u8bef\u5dee\u5c0f\u4e8e\u00a010-5 \u7684\u7ed3\u679c\u90fd\u5c06\u88ab\u89c6\u4e3a\u6b63\u786e\u7b54\u6848\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,12,-5,-6,50,3], k = 4\n\u8f93\u51fa\uff1a12.75000\n\u89e3\u91ca\uff1a\n- \u5f53\u957f\u5ea6\u4e3a 4 \u7684\u65f6\u5019\uff0c\u8fde\u7eed\u5b50\u6570\u7ec4\u5e73\u5747\u503c\u5206\u522b\u4e3a [0.5, 12.75, 10.5] \uff0c\u5176\u4e2d\u6700\u5927\u5e73\u5747\u503c\u662f 12.75 \u3002\n- \u5f53\u957f\u5ea6\u4e3a 5 \u7684\u65f6\u5019\uff0c\u8fde\u7eed\u5b50\u6570\u7ec4\u5e73\u5747\u503c\u5206\u522b\u4e3a [10.4, 10.8] \uff0c\u5176\u4e2d\u6700\u5927\u5e73\u5747\u503c\u662f 10.8 \u3002\n- \u5f53\u957f\u5ea6\u4e3a 6 \u7684\u65f6\u5019\uff0c\u8fde\u7eed\u5b50\u6570\u7ec4\u5e73\u5747\u503c\u5206\u522b\u4e3a [9.16667] \uff0c\u5176\u4e2d\u6700\u5927\u5e73\u5747\u503c\u662f 9.16667 \u3002\n\u5f53\u53d6\u957f\u5ea6\u4e3a 4 \u7684\u5b50\u6570\u7ec4\uff08\u5373\uff0c\u5b50\u6570\u7ec4 [12, -5, -6, 50]\uff09\u7684\u65f6\u5019\uff0c\u53ef\u4ee5\u5f97\u5230\u6700\u5927\u7684\u8fde\u7eed\u5b50\u6570\u7ec4\u5e73\u5747\u503c 12.75 \uff0c\u6240\u4ee5\u8fd4\u56de 12.75 \u3002\n\u6839\u636e\u9898\u76ee\u8981\u6c42\uff0c\u65e0\u9700\u8003\u8651\u957f\u5ea6\u5c0f\u4e8e 4 \u7684\u5b50\u6570\u7ec4\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [5], k = 1\n\u8f93\u51fa\uff1a5.00000\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= k <= n <= 104
    • \n\t
    • -104 <= nums[i] <= 104
    • \n
    \n", "tags_en": ["Array", "Binary Search"], "tags_cn": ["\u6570\u7ec4", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n double findMaxAverage(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double findMaxAverage(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findMaxAverage(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: float\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findMaxAverage(self, nums: List[int], k: int) -> float:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\ndouble findMaxAverage(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double FindMaxAverage(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar findMaxAverage = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Float}\ndef find_max_average(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findMaxAverage(_ nums: [Int], _ k: Int) -> Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findMaxAverage(nums []int, k int) float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findMaxAverage(nums: Array[Int], k: Int): Double = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findMaxAverage(nums: IntArray, k: Int): Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_max_average(nums: Vec, k: i32) -> f64 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Float\n */\n function findMaxAverage($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findMaxAverage(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-max-average nums k)\n (-> (listof exact-integer?) exact-integer? flonum?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0644](https://leetcode-cn.com/problems/maximum-average-subarray-ii)", "[\u5b50\u6570\u7ec4\u6700\u5927\u5e73\u5747\u6570 II](/solution/0600-0699/0644.Maximum%20Average%20Subarray%20II/README.md)", "`\u6570\u7ec4`,`\u4e8c\u5206\u67e5\u627e`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0644](https://leetcode.com/problems/maximum-average-subarray-ii)", "[Maximum Average Subarray II](/solution/0600-0699/0644.Maximum%20Average%20Subarray%20II/README_EN.md)", "`Array`,`Binary Search`", "Hard", "\ud83d\udd12"]}, {"question_id": "0643", "frontend_question_id": "0643", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-average-subarray-i", "url_en": "https://leetcode.com/problems/maximum-average-subarray-i", "relative_path_cn": "/solution/0600-0699/0643.Maximum%20Average%20Subarray%20I/README.md", "relative_path_en": "/solution/0600-0699/0643.Maximum%20Average%20Subarray%20I/README_EN.md", "title_cn": "\u5b50\u6570\u7ec4\u6700\u5927\u5e73\u5747\u6570 I", "title_en": "Maximum Average Subarray I", "question_title_slug": "maximum-average-subarray-i", "content_en": "

    You are given an integer array nums consisting of n elements, and an integer k.

    \n\n

    Find a contiguous subarray whose length is equal to k that has the maximum average value and return this value. Any answer with a calculation error less than 10-5 will be accepted.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,12,-5,-6,50,3], k = 4\nOutput: 12.75000\nExplanation: Maximum average is (12 - 5 - 6 + 50) / 4 = 51 / 4 = 12.75\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [5], k = 1\nOutput: 5.00000\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= k <= n <= 105
    • \n\t
    • -104 <= nums[i] <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a n \u4e2a\u6574\u6570\uff0c\u627e\u51fa\u5e73\u5747\u6570\u6700\u5927\u4e14\u957f\u5ea6\u4e3a k \u7684\u8fde\u7eed\u5b50\u6570\u7ec4\uff0c\u5e76\u8f93\u51fa\u8be5\u6700\u5927\u5e73\u5747\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[1,12,-5,-6,50,3], k = 4\n\u8f93\u51fa\uff1a12.75\n\u89e3\u91ca\uff1a\u6700\u5927\u5e73\u5747\u6570 (12-5-6+50)/4 = 51/4 = 12.75\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= k <= n <= 30,000\u3002
    • \n\t
    • \u6240\u7ed9\u6570\u636e\u8303\u56f4 [-10,000\uff0c10,000]\u3002
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n double findMaxAverage(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double findMaxAverage(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findMaxAverage(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: float\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findMaxAverage(self, nums: List[int], k: int) -> float:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\ndouble findMaxAverage(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double FindMaxAverage(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar findMaxAverage = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Float}\ndef find_max_average(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findMaxAverage(_ nums: [Int], _ k: Int) -> Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findMaxAverage(nums []int, k int) float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findMaxAverage(nums: Array[Int], k: Int): Double = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findMaxAverage(nums: IntArray, k: Int): Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_max_average(nums: Vec, k: i32) -> f64 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Float\n */\n function findMaxAverage($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findMaxAverage(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-max-average nums k)\n (-> (listof exact-integer?) exact-integer? flonum?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0643](https://leetcode-cn.com/problems/maximum-average-subarray-i)", "[\u5b50\u6570\u7ec4\u6700\u5927\u5e73\u5747\u6570 I](/solution/0600-0699/0643.Maximum%20Average%20Subarray%20I/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0643](https://leetcode.com/problems/maximum-average-subarray-i)", "[Maximum Average Subarray I](/solution/0600-0699/0643.Maximum%20Average%20Subarray%20I/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0642", "frontend_question_id": "0642", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/design-search-autocomplete-system", "url_en": "https://leetcode.com/problems/design-search-autocomplete-system", "relative_path_cn": "/solution/0600-0699/0642.Design%20Search%20Autocomplete%20System/README.md", "relative_path_en": "/solution/0600-0699/0642.Design%20Search%20Autocomplete%20System/README_EN.md", "title_cn": "\u8bbe\u8ba1\u641c\u7d22\u81ea\u52a8\u8865\u5168\u7cfb\u7edf", "title_en": "Design Search Autocomplete System", "question_title_slug": "design-search-autocomplete-system", "content_en": "

    Design a search autocomplete system for a search engine. Users may input a sentence (at least one word and end with a special character '#').

    \n\n

    You are given a string array sentences and an integer array times both of length n where sentences[i] is a previously typed sentence and times[i] is the corresponding number of times the sentence was typed. For each input character except '#', return the top 3 historical hot sentences that have the same prefix as the part of the sentence already typed.

    \n\n

    Here are the specific rules:

    \n\n
      \n\t
    • The hot degree for a sentence is defined as the number of times a user typed the exactly same sentence before.
    • \n\t
    • The returned top 3 hot sentences should be sorted by hot degree (The first is the hottest one). If several sentences have the same hot degree, use ASCII-code order (smaller one appears first).
    • \n\t
    • If less than 3 hot sentences exist, return as many as you can.
    • \n\t
    • When the input is a special character, it means the sentence ends, and in this case, you need to return an empty list.
    • \n
    \n\n

    Implement the AutocompleteSystem class:

    \n\n
      \n\t
    • AutocompleteSystem(String[] sentences, int[] times) Initializes the object with the sentences and times arrays.
    • \n\t
    • List<String> input(char c) This indicates that the user typed the character c.\n\t
        \n\t\t
      • Returns an empty array [] if c == '#' and stores the inputted sentence in the system.
      • \n\t\t
      • Returns the top 3 historical hot sentences that have the same prefix as the part of the sentence already typed. If there are fewer than 3 matches, return them all.
      • \n\t
      \n\t
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["AutocompleteSystem", "input", "input", "input", "input"]\n[[["i love you", "island", "iroman", "i love leetcode"], [5, 3, 2, 2]], ["i"], [" "], ["a"], ["#"]]\nOutput\n[null, ["i love you", "island", "i love leetcode"], ["i love you", "i love leetcode"], [], []]\n\nExplanation\nAutocompleteSystem obj = new AutocompleteSystem(["i love you", "island", "iroman", "i love leetcode"], [5, 3, 2, 2]);\nobj.input("i"); // return ["i love you", "island", "i love leetcode"]. There are four sentences that have prefix "i". Among them, "ironman" and "i love leetcode" have same hot degree. Since ' ' has ASCII code 32 and 'r' has ASCII code 114, "i love leetcode" should be in front of "ironman". Also we only need to output top 3 hot sentences, so "ironman" will be ignored.\nobj.input(" "); // return ["i love you", "i love leetcode"]. There are only two sentences that have prefix "i ".\nobj.input("a"); // return []. There are no sentences that have prefix "i a".\nobj.input("#"); // return []. The user finished the input, the sentence "i a" should be saved as a historical sentence in system. And the following input will be counted as a new search.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == sentences.length
    • \n\t
    • n == times.length
    • \n\t
    • 1 <= n <= 100
    • \n\t
    • 1 <= sentences[i].length <= 100
    • \n\t
    • 1 <= times[i] <= 50
    • \n\t
    • c is a lowercase English letter, a hash '#', or space ' '.
    • \n\t
    • Each tested sentence will be a sequence of characters c that end with the character '#'.
    • \n\t
    • Each tested sentence will have a length in the range [1, 200].
    • \n\t
    • The words in each input sentence are separated by single spaces.
    • \n\t
    • At most 5000 calls will be made to input.
    • \n
    \n", "content_cn": "

    \u4e3a\u641c\u7d22\u5f15\u64ce\u8bbe\u8ba1\u4e00\u4e2a\u641c\u7d22\u81ea\u52a8\u8865\u5168\u7cfb\u7edf\u3002\u7528\u6237\u4f1a\u8f93\u5165\u4e00\u6761\u8bed\u53e5\uff08\u6700\u5c11\u5305\u542b\u4e00\u4e2a\u5b57\u6bcd\uff0c\u4ee5\u7279\u6b8a\u5b57\u7b26 '#' \u7ed3\u5c3e\uff09\u3002\u9664 '#' \u4ee5\u5916\u7528\u6237\u8f93\u5165\u7684\u6bcf\u4e2a\u5b57\u7b26\uff0c\u8fd4\u56de\u5386\u53f2\u4e2d\u70ed\u5ea6\u524d\u4e09\u5e76\u4ee5\u5f53\u524d\u8f93\u5165\u90e8\u5206\u4e3a\u524d\u7f00\u7684\u53e5\u5b50\u3002\u4e0b\u9762\u662f\u8be6\u7ec6\u89c4\u5219\uff1a

    \n\n
      \n\t
    1. \u4e00\u6761\u53e5\u5b50\u7684\u70ed\u5ea6\u5b9a\u4e49\u4e3a\u5386\u53f2\u4e0a\u7528\u6237\u8f93\u5165\u8fd9\u4e2a\u53e5\u5b50\u7684\u603b\u6b21\u6570\u3002
    2. \n\t
    3. \u8fd4\u56de\u524d\u4e09\u7684\u53e5\u5b50\u9700\u8981\u6309\u7167\u70ed\u5ea6\u4ece\u9ad8\u5230\u4f4e\u6392\u5e8f\uff08\u7b2c\u4e00\u4e2a\u662f\u6700\u70ed\u95e8\u7684\uff09\u3002\u5982\u679c\u6709\u591a\u6761\u70ed\u5ea6\u76f8\u540c\u7684\u53e5\u5b50\uff0c\u8bf7\u6309\u7167 ASCII \u7801\u7684\u987a\u5e8f\u8f93\u51fa\uff08ASCII \u7801\u8d8a\u5c0f\u6392\u540d\u8d8a\u524d\uff09\u3002
    4. \n\t
    5. \u5982\u679c\u6ee1\u8db3\u6761\u4ef6\u7684\u53e5\u5b50\u4e2a\u6570\u5c11\u4e8e 3\uff0c\u5c06\u5b83\u4eec\u5168\u90e8\u8f93\u51fa\u3002
    6. \n\t
    7. \u5982\u679c\u8f93\u5165\u4e86\u7279\u6b8a\u5b57\u7b26\uff0c\u610f\u5473\u7740\u53e5\u5b50\u7ed3\u675f\u4e86\uff0c\u8bf7\u8fd4\u56de\u4e00\u4e2a\u7a7a\u96c6\u5408\u3002
    8. \n
    \n\n

    \u4f60\u7684\u5de5\u4f5c\u662f\u5b9e\u73b0\u4ee5\u4e0b\u529f\u80fd\uff1a

    \n\n

    \u6784\u9020\u51fd\u6570\uff1a

    \n\n

    AutocompleteSystem(String[] sentences, int[] times): \u8fd9\u662f\u6784\u9020\u51fd\u6570\uff0c\u8f93\u5165\u7684\u662f\u5386\u53f2\u6570\u636e\u3002 Sentences \u662f\u4e4b\u524d\u8f93\u5165\u8fc7\u7684\u6240\u6709\u53e5\u5b50\uff0cTimes \u662f\u6bcf\u6761\u53e5\u5b50\u8f93\u5165\u7684\u6b21\u6570\uff0c\u4f60\u7684\u7cfb\u7edf\u9700\u8981\u8bb0\u5f55\u8fd9\u4e9b\u5386\u53f2\u4fe1\u606f\u3002

    \n\n

    \u73b0\u5728\uff0c\u7528\u6237\u8f93\u5165\u4e00\u6761\u65b0\u7684\u53e5\u5b50\uff0c\u4e0b\u9762\u7684\u51fd\u6570\u4f1a\u63d0\u4f9b\u7528\u6237\u8f93\u5165\u7684\u4e0b\u4e00\u4e2a\u5b57\u7b26\uff1a

    \n\n

    List<String> input(char c): \u5176\u4e2d c \u662f\u7528\u6237\u8f93\u5165\u7684\u4e0b\u4e00\u4e2a\u5b57\u7b26\u3002\u5b57\u7b26\u53ea\u4f1a\u662f\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\uff08'a' \u5230 'z' \uff09\uff0c\u7a7a\u683c\uff08' '\uff09\u548c\u7279\u6b8a\u5b57\u7b26\uff08'#'\uff09\u3002\u8f93\u51fa\u5386\u53f2\u70ed\u5ea6\u524d\u4e09\u7684\u5177\u6709\u76f8\u540c\u524d\u7f00\u7684\u53e5\u5b50\u3002

    \n\n

     

    \n\n

    \u6837\u4f8b \uff1a
    \n\u64cd\u4f5c \uff1a AutocompleteSystem(["i love you", "island","ironman", "i love leetcode"], [5,3,2,2])
    \n\u7cfb\u7edf\u8bb0\u5f55\u4e0b\u6240\u6709\u7684\u53e5\u5b50\u548c\u51fa\u73b0\u7684\u6b21\u6570\uff1a
    \n"i love you" : 5 \u6b21
    \n"island" : 3 \u6b21
    \n"ironman" : 2 \u6b21
    \n"i love leetcode" : 2 \u6b21
    \n\u73b0\u5728\uff0c\u7528\u6237\u5f00\u59cb\u65b0\u7684\u952e\u5165\uff1a

    \n\n


    \n\u8f93\u5165 \uff1a input('i')
    \n\u8f93\u51fa \uff1a ["i love you", "island","i love leetcode"]
    \n\u89e3\u91ca \uff1a
    \n\u6709\u56db\u4e2a\u53e5\u5b50\u542b\u6709\u524d\u7f00 "i"\u3002\u5176\u4e2d "ironman" \u548c "i love leetcode" \u6709\u76f8\u540c\u7684\u70ed\u5ea6\uff0c\u7531\u4e8e ' ' \u7684 ASCII \u7801\u662f 32 \u800c 'r' \u7684 ASCII \u7801\u662f 114\uff0c\u6240\u4ee5 "i love leetcode" \u5728 "ironman" \u524d\u9762\u3002\u540c\u65f6\u6211\u4eec\u53ea\u8f93\u51fa\u524d\u4e09\u7684\u53e5\u5b50\uff0c\u6240\u4ee5 "ironman" \u88ab\u820d\u5f03\u3002
    \n
    \n\u8f93\u5165 \uff1a input(' ')
    \n\u8f93\u51fa \uff1a ["i love you","i love leetcode"]
    \n\u89e3\u91ca:
    \n\u53ea\u6709\u4e24\u4e2a\u53e5\u5b50\u542b\u6709\u524d\u7f00 "i "\u3002
    \n
    \n\u8f93\u5165 \uff1a input('a')
    \n\u8f93\u51fa \uff1a []
    \n\u89e3\u91ca \uff1a
    \n\u6ca1\u6709\u53e5\u5b50\u6709\u524d\u7f00 "i a"\u3002
    \n
    \n\u8f93\u5165 \uff1a input('#')
    \n\u8f93\u51fa \uff1a []
    \n\u89e3\u91ca \uff1a

    \n\n

    \u7528\u6237\u8f93\u5165\u7ed3\u675f\uff0c"i a" \u88ab\u5b58\u5230\u7cfb\u7edf\u4e2d\uff0c\u540e\u9762\u7684\u8f93\u5165\u88ab\u8ba4\u4e3a\u662f\u4e0b\u4e00\u6b21\u641c\u7d22\u3002

    \n\n

     

    \n\n

    \u6ce8\u91ca \uff1a

    \n\n
      \n\t
    1. \u8f93\u5165\u7684\u53e5\u5b50\u4ee5\u5b57\u6bcd\u5f00\u5934\uff0c\u4ee5 '#' \u7ed3\u5c3e\uff0c\u4e24\u4e2a\u5b57\u6bcd\u4e4b\u95f4\u6700\u591a\u53ea\u4f1a\u51fa\u73b0\u4e00\u4e2a\u7a7a\u683c\u3002
    2. \n\t
    3. \u5373\u5c06\u641c\u7d22\u7684\u53e5\u5b50\u603b\u6570\u4e0d\u4f1a\u8d85\u8fc7 100\u3002\u6bcf\u6761\u53e5\u5b50\u7684\u957f\u5ea6\uff08\u5305\u62ec\u5df2\u7ecf\u641c\u7d22\u7684\u548c\u5373\u5c06\u641c\u7d22\u7684\uff09\u4e5f\u4e0d\u4f1a\u8d85\u8fc7 100\u3002
    4. \n\t
    5. \u5373\u4f7f\u53ea\u6709\u4e00\u4e2a\u5b57\u6bcd\uff0c\u8f93\u51fa\u7684\u65f6\u5019\u8bf7\u4f7f\u7528\u53cc\u5f15\u53f7\u800c\u4e0d\u662f\u5355\u5f15\u53f7\u3002
    6. \n\t
    7. \u8bf7\u8bb0\u4f4f\u6e05\u96f6 AutocompleteSystem \u7c7b\u4e2d\u7684\u53d8\u91cf\uff0c\u56e0\u4e3a\u9759\u6001\u53d8\u91cf\u3001\u7c7b\u53d8\u91cf\u4f1a\u5728\u591a\u7ec4\u6d4b\u8bd5\u6570\u636e\u4e2d\u4fdd\u5b58\u4e4b\u524d\u7ed3\u679c\u3002\u8be6\u60c5\u8bf7\u770b\u8fd9\u91cc\u3002
    8. \n
    \n\n

     

    \n", "tags_en": ["Design", "Trie"], "tags_cn": ["\u8bbe\u8ba1", "\u5b57\u5178\u6811"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class AutocompleteSystem {\npublic:\n AutocompleteSystem(vector& sentences, vector& times) {\n\n }\n \n vector input(char c) {\n\n }\n};\n\n/**\n * Your AutocompleteSystem object will be instantiated and called as such:\n * AutocompleteSystem* obj = new AutocompleteSystem(sentences, times);\n * vector param_1 = obj->input(c);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class AutocompleteSystem {\n\n public AutocompleteSystem(String[] sentences, int[] times) {\n\n }\n \n public List input(char c) {\n\n }\n}\n\n/**\n * Your AutocompleteSystem object will be instantiated and called as such:\n * AutocompleteSystem obj = new AutocompleteSystem(sentences, times);\n * List param_1 = obj.input(c);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class AutocompleteSystem(object):\n\n def __init__(self, sentences, times):\n \"\"\"\n :type sentences: List[str]\n :type times: List[int]\n \"\"\"\n\n\n def input(self, c):\n \"\"\"\n :type c: str\n :rtype: List[str]\n \"\"\"\n\n\n\n# Your AutocompleteSystem object will be instantiated and called as such:\n# obj = AutocompleteSystem(sentences, times)\n# param_1 = obj.input(c)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class AutocompleteSystem:\n\n def __init__(self, sentences: List[str], times: List[int]):\n\n\n def input(self, c: str) -> List[str]:\n\n\n\n# Your AutocompleteSystem object will be instantiated and called as such:\n# obj = AutocompleteSystem(sentences, times)\n# param_1 = obj.input(c)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} AutocompleteSystem;\n\n\nAutocompleteSystem* autocompleteSystemCreate(char ** sentences, int sentencesSize, int* times, int timesSize) {\n \n}\n\nchar ** autocompleteSystemInput(AutocompleteSystem* obj, char c, int* retSize) {\n \n}\n\nvoid autocompleteSystemFree(AutocompleteSystem* obj) {\n \n}\n\n/**\n * Your AutocompleteSystem struct will be instantiated and called as such:\n * AutocompleteSystem* obj = autocompleteSystemCreate(sentences, sentencesSize, times, timesSize);\n * char ** param_1 = autocompleteSystemInput(obj, c, retSize);\n \n * autocompleteSystemFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class AutocompleteSystem {\n\n public AutocompleteSystem(string[] sentences, int[] times) {\n\n }\n \n public IList Input(char c) {\n\n }\n}\n\n/**\n * Your AutocompleteSystem object will be instantiated and called as such:\n * AutocompleteSystem obj = new AutocompleteSystem(sentences, times);\n * IList param_1 = obj.Input(c);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} sentences\n * @param {number[]} times\n */\nvar AutocompleteSystem = function(sentences, times) {\n\n};\n\n/** \n * @param {character} c\n * @return {string[]}\n */\nAutocompleteSystem.prototype.input = function(c) {\n\n};\n\n/**\n * Your AutocompleteSystem object will be instantiated and called as such:\n * var obj = new AutocompleteSystem(sentences, times)\n * var param_1 = obj.input(c)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class AutocompleteSystem\n\n=begin\n :type sentences: String[]\n :type times: Integer[]\n=end\n def initialize(sentences, times)\n\n end\n\n\n=begin\n :type c: Character\n :rtype: String[]\n=end\n def input(c)\n\n end\n\n\nend\n\n# Your AutocompleteSystem object will be instantiated and called as such:\n# obj = AutocompleteSystem.new(sentences, times)\n# param_1 = obj.input(c)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass AutocompleteSystem {\n\n init(_ sentences: [String], _ times: [Int]) {\n\n }\n \n func input(_ c: Character) -> [String] {\n\n }\n}\n\n/**\n * Your AutocompleteSystem object will be instantiated and called as such:\n * let obj = AutocompleteSystem(sentences, times)\n * let ret_1: [String] = obj.input(c)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type AutocompleteSystem struct {\n\n}\n\n\nfunc Constructor(sentences []string, times []int) AutocompleteSystem {\n\n}\n\n\nfunc (this *AutocompleteSystem) Input(c byte) []string {\n\n}\n\n\n/**\n * Your AutocompleteSystem object will be instantiated and called as such:\n * obj := Constructor(sentences, times);\n * param_1 := obj.Input(c);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class AutocompleteSystem(_sentences: Array[String], _times: Array[Int]) {\n\n def input(c: Char): List[String] = {\n\n }\n\n}\n\n/**\n * Your AutocompleteSystem object will be instantiated and called as such:\n * var obj = new AutocompleteSystem(sentences, times)\n * var param_1 = obj.input(c)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class AutocompleteSystem(sentences: Array, times: IntArray) {\n\n fun input(c: Char): List {\n\n }\n\n}\n\n/**\n * Your AutocompleteSystem object will be instantiated and called as such:\n * var obj = AutocompleteSystem(sentences, times)\n * var param_1 = obj.input(c)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct AutocompleteSystem {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl AutocompleteSystem {\n\n fn new(sentences: Vec, times: Vec) -> Self {\n\n }\n \n fn input(&self, c: char) -> Vec {\n\n }\n}\n\n/**\n * Your AutocompleteSystem object will be instantiated and called as such:\n * let obj = AutocompleteSystem::new(sentences, times);\n * let ret_1: Vec = obj.input(c);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class AutocompleteSystem {\n /**\n * @param String[] $sentences\n * @param Integer[] $times\n */\n function __construct($sentences, $times) {\n\n }\n\n /**\n * @param String $c\n * @return String[]\n */\n function input($c) {\n\n }\n}\n\n/**\n * Your AutocompleteSystem object will be instantiated and called as such:\n * $obj = AutocompleteSystem($sentences, $times);\n * $ret_1 = $obj->input($c);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class AutocompleteSystem {\n constructor(sentences: string[], times: number[]) {\n\n }\n\n input(c: string): string[] {\n\n }\n}\n\n/**\n * Your AutocompleteSystem object will be instantiated and called as such:\n * var obj = new AutocompleteSystem(sentences, times)\n * var param_1 = obj.input(c)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define autocomplete-system%\n (class object%\n (super-new)\n\n ; sentences : (listof string?)\n\n ; times : (listof exact-integer?)\n (init-field\n sentences\n times)\n \n ; input : char? -> (listof string?)\n (define/public (input c)\n\n )))\n\n;; Your autocomplete-system% object will be instantiated and called as such:\n;; (define obj (new autocomplete-system% [sentences sentences] [times times]))\n;; (define param_1 (send obj input c))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0642](https://leetcode-cn.com/problems/design-search-autocomplete-system)", "[\u8bbe\u8ba1\u641c\u7d22\u81ea\u52a8\u8865\u5168\u7cfb\u7edf](/solution/0600-0699/0642.Design%20Search%20Autocomplete%20System/README.md)", "`\u8bbe\u8ba1`,`\u5b57\u5178\u6811`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0642](https://leetcode.com/problems/design-search-autocomplete-system)", "[Design Search Autocomplete System](/solution/0600-0699/0642.Design%20Search%20Autocomplete%20System/README_EN.md)", "`Design`,`Trie`", "Hard", "\ud83d\udd12"]}, {"question_id": "0640", "frontend_question_id": "0640", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/solve-the-equation", "url_en": "https://leetcode.com/problems/solve-the-equation", "relative_path_cn": "/solution/0600-0699/0640.Solve%20the%20Equation/README.md", "relative_path_en": "/solution/0600-0699/0640.Solve%20the%20Equation/README_EN.md", "title_cn": "\u6c42\u89e3\u65b9\u7a0b", "title_en": "Solve the Equation", "question_title_slug": "solve-the-equation", "content_en": "

    Solve a given equation and return the value of 'x' in the form of a string "x=#value". The equation contains only '+', '-' operation, the variable 'x' and its coefficient. You should return "No solution" if there is no solution for the equation, or "Infinite solutions" if there are infinite solutions for the equation.

    \n\n

    If there is exactly one solution for the equation, we ensure that the value of 'x' is an integer.

    \n\n

     

    \n

    Example 1:

    \n
    Input: equation = \"x+5-3+x=6+x-2\"\nOutput: \"x=2\"\n

    Example 2:

    \n
    Input: equation = \"x=x\"\nOutput: \"Infinite solutions\"\n

    Example 3:

    \n
    Input: equation = \"2x=x\"\nOutput: \"x=0\"\n

    Example 4:

    \n
    Input: equation = \"2x+3x-6x=x+2\"\nOutput: \"x=-1\"\n

    Example 5:

    \n
    Input: equation = \"x=x+2\"\nOutput: \"No solution\"\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 3 <= equation.length <= 1000
    • \n\t
    • equation has exactly one '='.
    • \n\t
    • equation consists of integers with an absolute value in the range [0, 100] without any leading zeros, and the variable 'x'.
    • \n
    \n", "content_cn": "

    \u6c42\u89e3\u4e00\u4e2a\u7ed9\u5b9a\u7684\u65b9\u7a0b\uff0c\u5c06x\u4ee5\u5b57\u7b26\u4e32"x=#value"\u7684\u5f62\u5f0f\u8fd4\u56de\u3002\u8be5\u65b9\u7a0b\u4ec5\u5305\u542b'+'\uff0c' - '\u64cd\u4f5c\uff0c\u53d8\u91cf x \u548c\u5176\u5bf9\u5e94\u7cfb\u6570\u3002

    \n\n

    \u5982\u679c\u65b9\u7a0b\u6ca1\u6709\u89e3\uff0c\u8bf7\u8fd4\u56de“No solution”\u3002

    \n\n

    \u5982\u679c\u65b9\u7a0b\u6709\u65e0\u9650\u89e3\uff0c\u5219\u8fd4\u56de“Infinite solutions”\u3002

    \n\n

    \u5982\u679c\u65b9\u7a0b\u4e2d\u53ea\u6709\u4e00\u4e2a\u89e3\uff0c\u8981\u4fdd\u8bc1\u8fd4\u56de\u503c x \u662f\u4e00\u4e2a\u6574\u6570\u3002

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165: "x+5-3+x=6+x-2"\n\u8f93\u51fa: "x=2"\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: "x=x"\n\u8f93\u51fa: "Infinite solutions"\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u8f93\u5165: "2x=x"\n\u8f93\u51fa: "x=0"\n
    \n\n

    \u793a\u4f8b 4:

    \n\n
    \u8f93\u5165: "2x+3x-6x=x+2"\n\u8f93\u51fa: "x=-1"\n
    \n\n

    \u793a\u4f8b 5:

    \n\n
    \u8f93\u5165: "x=x+2"\n\u8f93\u51fa: "No solution"\n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string solveEquation(string equation) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String solveEquation(String equation) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def solveEquation(self, equation):\n \"\"\"\n :type equation: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def solveEquation(self, equation: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * solveEquation(char * equation){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string SolveEquation(string equation) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} equation\n * @return {string}\n */\nvar solveEquation = function(equation) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} equation\n# @return {String}\ndef solve_equation(equation)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func solveEquation(_ equation: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func solveEquation(equation string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def solveEquation(equation: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun solveEquation(equation: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn solve_equation(equation: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $equation\n * @return String\n */\n function solveEquation($equation) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function solveEquation(equation: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (solve-equation equation)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0640](https://leetcode-cn.com/problems/solve-the-equation)", "[\u6c42\u89e3\u65b9\u7a0b](/solution/0600-0699/0640.Solve%20the%20Equation/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0640](https://leetcode.com/problems/solve-the-equation)", "[Solve the Equation](/solution/0600-0699/0640.Solve%20the%20Equation/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "0639", "frontend_question_id": "0639", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/decode-ways-ii", "url_en": "https://leetcode.com/problems/decode-ways-ii", "relative_path_cn": "/solution/0600-0699/0639.Decode%20Ways%20II/README.md", "relative_path_en": "/solution/0600-0699/0639.Decode%20Ways%20II/README_EN.md", "title_cn": "\u89e3\u7801\u65b9\u6cd5 II", "title_en": "Decode Ways II", "question_title_slug": "decode-ways-ii", "content_en": "

    A message containing letters from A-Z can be encoded into numbers using the following mapping:

    \n\n
    \n'A' -> "1"\n'B' -> "2"\n...\n'Z' -> "26"\n
    \n\n

    To decode an encoded message, all the digits must be grouped then mapped back into letters using the reverse of the mapping above (there may be multiple ways). For example, "11106" can be mapped into:

    \n\n
      \n\t
    • "AAJF" with the grouping (1 1 10 6)
    • \n\t
    • "KJF" with the grouping (11 10 6)
    • \n
    \n\n

    Note that the grouping (1 11 06) is invalid because "06" cannot be mapped into 'F' since "6" is different from "06".

    \n\n

    In addition to the mapping above, an encoded message may contain the '*' character, which can represent any digit from '1' to '9' ('0' is excluded). For example, the encoded message "1*" may represent any of the encoded messages "11", "12", "13", "14", "15", "16", "17", "18", or "19". Decoding "1*" is equivalent to decoding any of the encoded messages it can represent.

    \n\n

    Given a string s containing digits and the '*' character, return the number of ways to decode it.

    \n\n

    Since the answer may be very large, return it modulo 109 + 7.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "*"\nOutput: 9\nExplanation: The encoded message can represent any of the encoded messages "1", "2", "3", "4", "5", "6", "7", "8", or "9".\nEach of these can be decoded to the strings "A", "B", "C", "D", "E", "F", "G", "H", and "I" respectively.\nHence, there are a total of 9 ways to decode "*".\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "1*"\nOutput: 18\nExplanation: The encoded message can represent any of the encoded messages "11", "12", "13", "14", "15", "16", "17", "18", or "19".\nEach of these encoded messages have 2 ways to be decoded (e.g. "11" can be decoded to "AA" or "K").\nHence, there are a total of 9 * 2 = 18 ways to decode "1*".\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "2*"\nOutput: 15\nExplanation: The encoded message can represent any of the encoded messages "21", "22", "23", "24", "25", "26", "27", "28", or "29".\n"21", "22", "23", "24", "25", and "26" have 2 ways of being decoded, but "27", "28", and "29" only have 1 way.\nHence, there are a total of (6 * 2) + (3 * 1) = 12 + 3 = 15 ways to decode "2*".\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 105
    • \n\t
    • s[i] is a digit or '*'.
    • \n
    \n", "content_cn": "

    \u4e00\u6761\u5305\u542b\u5b57\u6bcd A-Z \u7684\u6d88\u606f\u901a\u8fc7\u4ee5\u4e0b\u7684\u65b9\u5f0f\u8fdb\u884c\u4e86\u7f16\u7801\uff1a

    \n\n
    'A' -> 1\n'B' -> 2\n...\n'Z' -> 26\n
    \n\n

    \u9664\u4e86\u4e0a\u8ff0\u7684\u6761\u4ef6\u4ee5\u5916\uff0c\u73b0\u5728\u52a0\u5bc6\u5b57\u7b26\u4e32\u53ef\u4ee5\u5305\u542b\u5b57\u7b26 '*'\u4e86\uff0c\u5b57\u7b26'*'\u53ef\u4ee5\u88ab\u5f53\u505a1\u52309\u5f53\u4e2d\u7684\u4efb\u610f\u4e00\u4e2a\u6570\u5b57\u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u6761\u5305\u542b\u6570\u5b57\u548c\u5b57\u7b26'*'\u7684\u52a0\u5bc6\u4fe1\u606f\uff0c\u8bf7\u786e\u5b9a\u89e3\u7801\u65b9\u6cd5\u7684\u603b\u6570\u3002

    \n\n

    \u540c\u65f6\uff0c\u7531\u4e8e\u7ed3\u679c\u503c\u53ef\u80fd\u4f1a\u76f8\u5f53\u7684\u5927\uff0c\u6240\u4ee5\u4f60\u5e94\u5f53\u5bf9109 + 7\u53d6\u6a21\u3002\uff08\u7ffb\u8bd1\u8005\u6807\u6ce8\uff1a\u6b64\u5904\u53d6\u6a21\u4e3b\u8981\u662f\u4e3a\u4e86\u9632\u6b62\u6ea2\u51fa\uff09

    \n\n

    \u793a\u4f8b 1 :

    \n\n
    \u8f93\u5165: "*"\n\u8f93\u51fa: 9\n\u89e3\u91ca: \u52a0\u5bc6\u7684\u4fe1\u606f\u53ef\u4ee5\u88ab\u89e3\u5bc6\u4e3a: "A", "B", "C", "D", "E", "F", "G", "H", "I".\n
    \n\n

    \u793a\u4f8b 2 :

    \n\n
    \u8f93\u5165: "1*"\n\u8f93\u51fa: 9 + 9 = 18\uff08\u7ffb\u8bd1\u8005\u6807\u6ce8\uff1a\u8fd9\u91cc1*\u53ef\u4ee5\u5206\u89e3\u4e3a1,* \u6216\u8005\u5f53\u505a1*\u6765\u5904\u7406\uff0c\u6240\u4ee5\u7ed3\u679c\u662f9+9=18\uff09\n
    \n\n

    \u8bf4\u660e :

    \n\n
      \n\t
    1. \u8f93\u5165\u7684\u5b57\u7b26\u4e32\u957f\u5ea6\u8303\u56f4\u662f [1, 105]\u3002
    2. \n\t
    3. \u8f93\u5165\u7684\u5b57\u7b26\u4e32\u53ea\u4f1a\u5305\u542b\u5b57\u7b26 '*' \u548c \u6570\u5b57'0' - '9'\u3002
    4. \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numDecodings(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numDecodings(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numDecodings(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numDecodings(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numDecodings(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumDecodings(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar numDecodings = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef num_decodings(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numDecodings(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numDecodings(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numDecodings(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numDecodings(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_decodings(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function numDecodings($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numDecodings(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-decodings s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0639](https://leetcode-cn.com/problems/decode-ways-ii)", "[\u89e3\u7801\u65b9\u6cd5 II](/solution/0600-0699/0639.Decode%20Ways%20II/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0639](https://leetcode.com/problems/decode-ways-ii)", "[Decode Ways II](/solution/0600-0699/0639.Decode%20Ways%20II/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "0638", "frontend_question_id": "0638", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/shopping-offers", "url_en": "https://leetcode.com/problems/shopping-offers", "relative_path_cn": "/solution/0600-0699/0638.Shopping%20Offers/README.md", "relative_path_en": "/solution/0600-0699/0638.Shopping%20Offers/README_EN.md", "title_cn": "\u5927\u793c\u5305", "title_en": "Shopping Offers", "question_title_slug": "shopping-offers", "content_en": "

    In LeetCode Store, there are n items to sell. Each item has a price. However, there are some special offers, and a special offer consists of one or more different kinds of items with a sale price.

    \n\n

    You are given an integer array price where price[i] is the price of the ith item, and an integer array needs where needs[i] is the number of pieces of the ith item you want to buy.

    \n\n

    You are also given an array special where special[i] is of size n + 1 where special[i][j] is the number of pieces of the jth item in the ith offer and special[i][n] (i.e., the last integer in the array) is the price of the ith offer.

    \n\n

    Return the lowest price you have to pay for exactly certain items as given, where you could make optimal use of the special offers. You are not allowed to buy more items than you want, even if that would lower the overall price. You could use any of the special offers as many times as you want.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: price = [2,5], special = [[3,0,5],[1,2,10]], needs = [3,2]\nOutput: 14\nExplanation: There are two kinds of items, A and B. Their prices are $2 and $5 respectively. \nIn special offer 1, you can pay $5 for 3A and 0B\nIn special offer 2, you can pay $10 for 1A and 2B. \nYou need to buy 3A and 2B, so you may pay $10 for 1A and 2B (special offer #2), and $4 for 2A.\n
    \n\n

    Example 2:

    \n\n
    \nInput: price = [2,3,4], special = [[1,1,0,4],[2,2,1,9]], needs = [1,2,1]\nOutput: 11\nExplanation: The price of A is $2, and $3 for B, $4 for C. \nYou may pay $4 for 1A and 1B, and $9 for 2A ,2B and 1C. \nYou need to buy 1A ,2B and 1C, so you may pay $4 for 1A and 1B (special offer #1), and $3 for 1B, $4 for 1C. \nYou cannot add more items, though only $9 for 2A ,2B and 1C.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == price.length
    • \n\t
    • n == needs.length
    • \n\t
    • 1 <= n <= 6
    • \n\t
    • 0 <= price[i] <= 10
    • \n\t
    • 0 <= needs[i] <= 10
    • \n\t
    • 1 <= special.length <= 100
    • \n\t
    • special[i].length == n + 1
    • \n\t
    • 0 <= special[i][j] <= 50
    • \n
    \n", "content_cn": "

    \u5728 LeetCode \u5546\u5e97\u4e2d\uff0c \u6709 n \u4ef6\u5728\u552e\u7684\u7269\u54c1\u3002\u6bcf\u4ef6\u7269\u54c1\u90fd\u6709\u5bf9\u5e94\u7684\u4ef7\u683c\u3002\u7136\u800c\uff0c\u4e5f\u6709\u4e00\u4e9b\u5927\u793c\u5305\uff0c\u6bcf\u4e2a\u5927\u793c\u5305\u4ee5\u4f18\u60e0\u7684\u4ef7\u683c\u6346\u7ed1\u9500\u552e\u4e00\u7ec4\u7269\u54c1\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 price \u8868\u793a\u7269\u54c1\u4ef7\u683c\uff0c\u5176\u4e2d price[i] \u662f\u7b2c i \u4ef6\u7269\u54c1\u7684\u4ef7\u683c\u3002\u53e6\u6709\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 needs \u8868\u793a\u8d2d\u7269\u6e05\u5355\uff0c\u5176\u4e2d needs[i] \u662f\u9700\u8981\u8d2d\u4e70\u7b2c i \u4ef6\u7269\u54c1\u7684\u6570\u91cf\u3002

    \n\n

    \u8fd8\u6709\u4e00\u4e2a\u6570\u7ec4 special \u8868\u793a\u5927\u793c\u5305\uff0cspecial[i] \u7684\u957f\u5ea6\u4e3a n + 1 \uff0c\u5176\u4e2d special[i][j] \u8868\u793a\u7b2c i \u4e2a\u5927\u793c\u5305\u4e2d\u5185\u542b\u7b2c j \u4ef6\u7269\u54c1\u7684\u6570\u91cf\uff0c\u4e14 special[i][n] \uff08\u4e5f\u5c31\u662f\u6570\u7ec4\u4e2d\u7684\u6700\u540e\u4e00\u4e2a\u6574\u6570\uff09\u4e3a\u7b2c i \u4e2a\u5927\u793c\u5305\u7684\u4ef7\u683c\u3002

    \n\n

    \u8fd4\u56de \u786e\u5207 \u6ee1\u8db3\u8d2d\u7269\u6e05\u5355\u6240\u9700\u82b1\u8d39\u7684\u6700\u4f4e\u4ef7\u683c\uff0c\u4f60\u53ef\u4ee5\u5145\u5206\u5229\u7528\u5927\u793c\u5305\u7684\u4f18\u60e0\u6d3b\u52a8\u3002\u4f60\u4e0d\u80fd\u8d2d\u4e70\u8d85\u51fa\u8d2d\u7269\u6e05\u5355\u6307\u5b9a\u6570\u91cf\u7684\u7269\u54c1\uff0c\u5373\u4f7f\u90a3\u6837\u4f1a\u964d\u4f4e\u6574\u4f53\u4ef7\u683c\u3002\u4efb\u610f\u5927\u793c\u5305\u53ef\u65e0\u9650\u6b21\u8d2d\u4e70\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aprice = [2,5], special = [[3,0,5],[1,2,10]], needs = [3,2]\n\u8f93\u51fa\uff1a14\n\u89e3\u91ca\uff1a\u6709 A \u548c B \u4e24\u79cd\u7269\u54c1\uff0c\u4ef7\u683c\u5206\u522b\u4e3a \u00a52 \u548c \u00a55 \u3002 \n\u5927\u793c\u5305 1 \uff0c\u4f60\u53ef\u4ee5\u4ee5 \u00a55 \u7684\u4ef7\u683c\u8d2d\u4e70 3A \u548c 0B \u3002 \n\u5927\u793c\u5305 2 \uff0c\u4f60\u53ef\u4ee5\u4ee5 \u00a510 \u7684\u4ef7\u683c\u8d2d\u4e70 1A \u548c 2B \u3002 \n\u9700\u8981\u8d2d\u4e70 3 \u4e2a A \u548c 2 \u4e2a B \uff0c \u6240\u4ee5\u4ed8 \u00a510 \u8d2d\u4e70 1A \u548c 2B\uff08\u5927\u793c\u5305 2\uff09\uff0c\u4ee5\u53ca \u00a54 \u8d2d\u4e70 2A \u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aprice = [2,3,4], special = [[1,1,0,4],[2,2,1,9]], needs = [1,2,1]\n\u8f93\u51fa\uff1a11\n\u89e3\u91ca\uff1aA \uff0cB \uff0cC \u7684\u4ef7\u683c\u5206\u522b\u4e3a \u00a52 \uff0c\u00a53 \uff0c\u00a54 \u3002\n\u53ef\u4ee5\u7528 \u00a54 \u8d2d\u4e70 1A \u548c 1B \uff0c\u4e5f\u53ef\u4ee5\u7528 \u00a59 \u8d2d\u4e70 2A \uff0c2B \u548c 1C \u3002 \n\u9700\u8981\u4e70 1A \uff0c2B \u548c 1C \uff0c\u6240\u4ee5\u4ed8 \u00a54 \u4e70 1A \u548c 1B\uff08\u5927\u793c\u5305 1\uff09\uff0c\u4ee5\u53ca \u00a53 \u8d2d\u4e70 1B \uff0c \u00a54 \u8d2d\u4e70 1C \u3002 \n\u4e0d\u53ef\u4ee5\u8d2d\u4e70\u8d85\u51fa\u5f85\u8d2d\u6e05\u5355\u7684\u7269\u54c1\uff0c\u5c3d\u7ba1\u8d2d\u4e70\u5927\u793c\u5305 2 \u66f4\u52a0\u4fbf\u5b9c\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == price.length
    • \n\t
    • n == needs.length
    • \n\t
    • 1 <= n <= 6
    • \n\t
    • 0 <= price[i] <= 10
    • \n\t
    • 0 <= needs[i] <= 10
    • \n\t
    • 1 <= special.length <= 100
    • \n\t
    • special[i].length == n + 1
    • \n\t
    • 0 <= special[i][j] <= 50
    • \n
    \n", "tags_en": ["Depth-first Search", "Dynamic Programming"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int shoppingOffers(vector& price, vector>& special, vector& needs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int shoppingOffers(List price, List> special, List needs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def shoppingOffers(self, price, special, needs):\n \"\"\"\n :type price: List[int]\n :type special: List[List[int]]\n :type needs: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def shoppingOffers(self, price: List[int], special: List[List[int]], needs: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint shoppingOffers(int* price, int priceSize, int** special, int specialSize, int* specialColSize, int* needs, int needsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ShoppingOffers(IList price, IList> special, IList needs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} price\n * @param {number[][]} special\n * @param {number[]} needs\n * @return {number}\n */\nvar shoppingOffers = function(price, special, needs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} price\n# @param {Integer[][]} special\n# @param {Integer[]} needs\n# @return {Integer}\ndef shopping_offers(price, special, needs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func shoppingOffers(_ price: [Int], _ special: [[Int]], _ needs: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func shoppingOffers(price []int, special [][]int, needs []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def shoppingOffers(price: List[Int], special: List[List[Int]], needs: List[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun shoppingOffers(price: List, special: List>, needs: List): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn shopping_offers(price: Vec, special: Vec>, needs: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $price\n * @param Integer[][] $special\n * @param Integer[] $needs\n * @return Integer\n */\n function shoppingOffers($price, $special, $needs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function shoppingOffers(price: number[], special: number[][], needs: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (shopping-offers price special needs)\n (-> (listof exact-integer?) (listof (listof exact-integer?)) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0638](https://leetcode-cn.com/problems/shopping-offers)", "[\u5927\u793c\u5305](/solution/0600-0699/0638.Shopping%20Offers/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0638](https://leetcode.com/problems/shopping-offers)", "[Shopping Offers](/solution/0600-0699/0638.Shopping%20Offers/README_EN.md)", "`Depth-first Search`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0637", "frontend_question_id": "0637", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/average-of-levels-in-binary-tree", "url_en": "https://leetcode.com/problems/average-of-levels-in-binary-tree", "relative_path_cn": "/solution/0600-0699/0637.Average%20of%20Levels%20in%20Binary%20Tree/README.md", "relative_path_en": "/solution/0600-0699/0637.Average%20of%20Levels%20in%20Binary%20Tree/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u7684\u5c42\u5e73\u5747\u503c", "title_en": "Average of Levels in Binary Tree", "question_title_slug": "average-of-levels-in-binary-tree", "content_en": "Given the root of a binary tree, return the average value of the nodes on each level in the form of an array. Answers within 10-5 of the actual answer will be accepted.\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [3,9,20,null,15,7]\nOutput: [3.00000,14.50000,11.00000]\nExplanation: The average value of nodes on level 0 is 3, on level 1 is 14.5, and on level 2 is 11.\nHence return [3, 14.5, 11].\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [3,9,20,15,7]\nOutput: [3.00000,14.50000,11.00000]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 104].
    • \n\t
    • -231 <= Node.val <= 231 - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u7a7a\u4e8c\u53c9\u6811, \u8fd4\u56de\u4e00\u4e2a\u7531\u6bcf\u5c42\u8282\u70b9\u5e73\u5747\u503c\u7ec4\u6210\u7684\u6570\u7ec4\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a\n    3\n   / \\\n  9  20\n    /  \\\n   15   7\n\u8f93\u51fa\uff1a[3, 14.5, 11]\n\u89e3\u91ca\uff1a\n\u7b2c 0 \u5c42\u7684\u5e73\u5747\u503c\u662f 3 ,  \u7b2c1\u5c42\u662f 14.5 , \u7b2c2\u5c42\u662f 11 \u3002\u56e0\u6b64\u8fd4\u56de [3, 14.5, 11] \u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u8282\u70b9\u503c\u7684\u8303\u56f4\u572832\u4f4d\u6709\u7b26\u53f7\u6574\u6570\u8303\u56f4\u5185\u3002
    • \n
    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector averageOfLevels(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public List averageOfLevels(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def averageOfLevels(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: List[float]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def averageOfLevels(self, root: TreeNode) -> List[float]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\ndouble* averageOfLevels(struct TreeNode* root, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public IList AverageOfLevels(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number[]}\n */\nvar averageOfLevels = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Float[]}\ndef average_of_levels(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func averageOfLevels(_ root: TreeNode?) -> [Double] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc averageOfLevels(root *TreeNode) []float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def averageOfLevels(root: TreeNode): Array[Double] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun averageOfLevels(root: TreeNode?): DoubleArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn average_of_levels(root: Option>>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Float[]\n */\n function averageOfLevels($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction averageOfLevels(root: TreeNode | null): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (average-of-levels root)\n (-> (or/c tree-node? #f) (listof flonum?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0637](https://leetcode-cn.com/problems/average-of-levels-in-binary-tree)", "[\u4e8c\u53c9\u6811\u7684\u5c42\u5e73\u5747\u503c](/solution/0600-0699/0637.Average%20of%20Levels%20in%20Binary%20Tree/README.md)", "`\u6811`", "\u7b80\u5355", ""], "md_table_row_en": ["[0637](https://leetcode.com/problems/average-of-levels-in-binary-tree)", "[Average of Levels in Binary Tree](/solution/0600-0699/0637.Average%20of%20Levels%20in%20Binary%20Tree/README_EN.md)", "`Tree`", "Easy", ""]}, {"question_id": "0636", "frontend_question_id": "0636", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/exclusive-time-of-functions", "url_en": "https://leetcode.com/problems/exclusive-time-of-functions", "relative_path_cn": "/solution/0600-0699/0636.Exclusive%20Time%20of%20Functions/README.md", "relative_path_en": "/solution/0600-0699/0636.Exclusive%20Time%20of%20Functions/README_EN.md", "title_cn": "\u51fd\u6570\u7684\u72ec\u5360\u65f6\u95f4", "title_en": "Exclusive Time of Functions", "question_title_slug": "exclusive-time-of-functions", "content_en": "

    On a single-threaded CPU, we execute a program containing n functions. Each function has a unique ID between 0 and n-1.

    \n\n

    Function calls are stored in a call stack: when a function call starts, its ID is pushed onto the stack, and when a function call ends, its ID is popped off the stack. The function whose ID is at the top of the stack is the current function being executed. Each time a function starts or ends, we write a log with the ID, whether it started or ended, and the timestamp.

    \n\n

    You are given a list logs, where logs[i] represents the ith log message formatted as a string "{function_id}:{"start" | "end"}:{timestamp}". For example, "0:start:3" means a function call with function ID 0 started at the beginning of timestamp 3, and "1:end:2" means a function call with function ID 1 ended at the end of timestamp 2. Note that a function can be called multiple times, possibly recursively.

    \n\n

    A function's exclusive time is the sum of execution times for all function calls in the program. For example, if a function is called twice, one call executing for 2 time units and another call executing for 1 time unit, the exclusive time is 2 + 1 = 3.

    \n\n

    Return the exclusive time of each function in an array, where the value at the ith index represents the exclusive time for the function with ID i.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: n = 2, logs = ["0:start:0","1:start:2","1:end:5","0:end:6"]\nOutput: [3,4]\nExplanation:\nFunction 0 starts at the beginning of time 0, then it executes 2 for units of time and reaches the end of time 1.\nFunction 1 starts at the beginning of time 2, executes for 4 units of time, and ends at the end of time 5.\nFunction 0 resumes execution at the beginning of time 6 and executes for 1 unit of time.\nSo function 0 spends 2 + 1 = 3 units of total time executing, and function 1 spends 4 units of total time executing.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 1, logs = ["0:start:0","0:start:2","0:end:5","0:start:6","0:end:6","0:end:7"]\nOutput: [8]\nExplanation:\nFunction 0 starts at the beginning of time 0, executes for 2 units of time, and recursively calls itself.\nFunction 0 (recursive call) starts at the beginning of time 2 and executes for 4 units of time.\nFunction 0 (initial call) resumes execution then immediately calls itself again.\nFunction 0 (2nd recursive call) starts at the beginning of time 6 and executes for 1 unit of time.\nFunction 0 (initial call) resumes execution at the beginning of time 7 and executes for 1 unit of time.\nSo function 0 spends 2 + 4 + 1 + 1 = 8 units of total time executing.\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 2, logs = ["0:start:0","0:start:2","0:end:5","1:start:6","1:end:6","0:end:7"]\nOutput: [7,1]\nExplanation:\nFunction 0 starts at the beginning of time 0, executes for 2 units of time, and recursively calls itself.\nFunction 0 (recursive call) starts at the beginning of time 2 and executes for 4 units of time.\nFunction 0 (initial call) resumes execution then immediately calls function 1.\nFunction 1 starts at the beginning of time 6, executes 1 units of time, and ends at the end of time 6.\nFunction 0 resumes execution at the beginning of time 6 and executes for 2 units of time.\nSo function 0 spends 2 + 4 + 1 = 7 units of total time executing, and function 1 spends 1 unit of total time executing.\n
    \n\n

    Example 4:

    \n\n
    \nInput: n = 2, logs = ["0:start:0","0:start:2","0:end:5","1:start:7","1:end:7","0:end:8"]\nOutput: [8,1]\n
    \n\n

    Example 5:

    \n\n
    \nInput: n = 1, logs = ["0:start:0","0:end:0"]\nOutput: [1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 100
    • \n\t
    • 1 <= logs.length <= 500
    • \n\t
    • 0 <= function_id < n
    • \n\t
    • 0 <= timestamp <= 109
    • \n\t
    • No two start events will happen at the same timestamp.
    • \n\t
    • No two end events will happen at the same timestamp.
    • \n\t
    • Each function has an "end" log for each "start" log.
    • \n
    \n", "content_cn": "

    \u6709\u4e00\u4e2a \u5355\u7ebf\u7a0b CPU \u6b63\u5728\u8fd0\u884c\u4e00\u4e2a\u542b\u6709 n \u9053\u51fd\u6570\u7684\u7a0b\u5e8f\u3002\u6bcf\u9053\u51fd\u6570\u90fd\u6709\u4e00\u4e2a\u4f4d\u4e8e\u00a0 0 \u548c n-1 \u4e4b\u95f4\u7684\u552f\u4e00\u6807\u8bc6\u7b26\u3002

    \n\n

    \u51fd\u6570\u8c03\u7528 \u5b58\u50a8\u5728\u4e00\u4e2a \u8c03\u7528\u6808 \u4e0a \uff1a\u5f53\u4e00\u4e2a\u51fd\u6570\u8c03\u7528\u5f00\u59cb\u65f6\uff0c\u5b83\u7684\u6807\u8bc6\u7b26\u5c06\u4f1a\u63a8\u5165\u6808\u4e2d\u3002\u800c\u5f53\u4e00\u4e2a\u51fd\u6570\u8c03\u7528\u7ed3\u675f\u65f6\uff0c\u5b83\u7684\u6807\u8bc6\u7b26\u5c06\u4f1a\u4ece\u6808\u4e2d\u5f39\u51fa\u3002\u6807\u8bc6\u7b26\u4f4d\u4e8e\u6808\u9876\u7684\u51fd\u6570\u662f \u5f53\u524d\u6b63\u5728\u6267\u884c\u7684\u51fd\u6570 \u3002\u6bcf\u5f53\u4e00\u4e2a\u51fd\u6570\u5f00\u59cb\u6216\u8005\u7ed3\u675f\u65f6\uff0c\u5c06\u4f1a\u8bb0\u5f55\u4e00\u6761\u65e5\u5fd7\uff0c\u5305\u62ec\u51fd\u6570\u6807\u8bc6\u7b26\u3001\u662f\u5f00\u59cb\u8fd8\u662f\u7ed3\u675f\u3001\u4ee5\u53ca\u76f8\u5e94\u7684\u65f6\u95f4\u6233\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u7531\u65e5\u5fd7\u7ec4\u6210\u7684\u5217\u8868 logs \uff0c\u5176\u4e2d logs[i] \u8868\u793a\u7b2c i \u6761\u65e5\u5fd7\u6d88\u606f\uff0c\u8be5\u6d88\u606f\u662f\u4e00\u4e2a\u6309 \"{function_id}:{\"start\" | \"end\"}:{timestamp}\" \u8fdb\u884c\u683c\u5f0f\u5316\u7684\u5b57\u7b26\u4e32\u3002\u4f8b\u5982\uff0c\"0:start:3\" \u610f\u5473\u7740\u6807\u8bc6\u7b26\u4e3a 0 \u7684\u51fd\u6570\u8c03\u7528\u5728\u65f6\u95f4\u6233 3 \u7684 \u8d77\u59cb\u5f00\u59cb\u6267\u884c \uff1b\u800c \"1:end:2\" \u610f\u5473\u7740\u6807\u8bc6\u7b26\u4e3a 1 \u7684\u51fd\u6570\u8c03\u7528\u5728\u65f6\u95f4\u6233 2 \u7684 \u672b\u5c3e\u7ed3\u675f\u6267\u884c\u3002\u6ce8\u610f\uff0c\u51fd\u6570\u53ef\u4ee5 \u8c03\u7528\u591a\u6b21\uff0c\u53ef\u80fd\u5b58\u5728\u9012\u5f52\u8c03\u7528 \u3002

    \n\n

    \u51fd\u6570\u7684 \u72ec\u5360\u65f6\u95f4 \u5b9a\u4e49\u662f\u5728\u8fd9\u4e2a\u51fd\u6570\u5728\u7a0b\u5e8f\u6240\u6709\u51fd\u6570\u8c03\u7528\u4e2d\u6267\u884c\u65f6\u95f4\u7684\u603b\u548c\uff0c\u8c03\u7528\u5176\u4ed6\u51fd\u6570\u82b1\u8d39\u7684\u65f6\u95f4\u4e0d\u7b97\u8be5\u51fd\u6570\u7684\u72ec\u5360\u65f6\u95f4\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4e00\u4e2a\u51fd\u6570\u88ab\u8c03\u7528\u4e24\u6b21\uff0c\u4e00\u6b21\u8c03\u7528\u6267\u884c 2 \u5355\u4f4d\u65f6\u95f4\uff0c\u53e6\u4e00\u6b21\u8c03\u7528\u6267\u884c 1 \u5355\u4f4d\u65f6\u95f4\uff0c\u90a3\u4e48\u8be5\u51fd\u6570\u7684 \u72ec\u5360\u65f6\u95f4 \u4e3a 2 + 1 = 3 \u3002

    \n\n

    \u4ee5\u6570\u7ec4\u5f62\u5f0f\u8fd4\u56de\u6bcf\u4e2a\u51fd\u6570\u7684 \u72ec\u5360\u65f6\u95f4 \uff0c\u5176\u4e2d\u7b2c i \u4e2a\u4e0b\u6807\u5bf9\u5e94\u7684\u503c\u8868\u793a\u6807\u8bc6\u7b26 i \u7684\u51fd\u6570\u7684\u72ec\u5360\u65f6\u95f4\u3002

    \n\u00a0\n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1an = 2, logs = [\"0:start:0\",\"1:start:2\",\"1:end:5\",\"0:end:6\"]\n\u8f93\u51fa\uff1a[3,4]\n\u89e3\u91ca\uff1a\n\u51fd\u6570 0 \u5728\u65f6\u95f4\u6233 0 \u7684\u8d77\u59cb\u5f00\u59cb\u6267\u884c\uff0c\u6267\u884c 2 \u4e2a\u5355\u4f4d\u65f6\u95f4\uff0c\u4e8e\u65f6\u95f4\u6233 1 \u7684\u672b\u5c3e\u7ed3\u675f\u6267\u884c\u3002 \n\u51fd\u6570 1 \u5728\u65f6\u95f4\u6233 2 \u7684\u8d77\u59cb\u5f00\u59cb\u6267\u884c\uff0c\u6267\u884c 4 \u4e2a\u5355\u4f4d\u65f6\u95f4\uff0c\u4e8e\u65f6\u95f4\u6233 5 \u7684\u672b\u5c3e\u7ed3\u675f\u6267\u884c\u3002 \n\u51fd\u6570 0 \u5728\u65f6\u95f4\u6233 6 \u7684\u5f00\u59cb\u6062\u590d\u6267\u884c\uff0c\u6267\u884c 1 \u4e2a\u5355\u4f4d\u65f6\u95f4\u3002 \n\u6240\u4ee5\u51fd\u6570 0 \u603b\u5171\u6267\u884c 2 + 1 = 3 \u4e2a\u5355\u4f4d\u65f6\u95f4\uff0c\u51fd\u6570 1 \u603b\u5171\u6267\u884c 4 \u4e2a\u5355\u4f4d\u65f6\u95f4\u3002 \n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 1, logs = [\"0:start:0\",\"0:start:2\",\"0:end:5\",\"0:start:6\",\"0:end:6\",\"0:end:7\"]\n\u8f93\u51fa\uff1a[8]\n\u89e3\u91ca\uff1a\n\u51fd\u6570 0 \u5728\u65f6\u95f4\u6233 0 \u7684\u8d77\u59cb\u5f00\u59cb\u6267\u884c\uff0c\u6267\u884c 2 \u4e2a\u5355\u4f4d\u65f6\u95f4\uff0c\u5e76\u9012\u5f52\u8c03\u7528\u5b83\u81ea\u8eab\u3002\n\u51fd\u6570 0\uff08\u9012\u5f52\u8c03\u7528\uff09\u5728\u65f6\u95f4\u6233 2 \u7684\u8d77\u59cb\u5f00\u59cb\u6267\u884c\uff0c\u6267\u884c 4 \u4e2a\u5355\u4f4d\u65f6\u95f4\u3002\n\u51fd\u6570 0\uff08\u521d\u59cb\u8c03\u7528\uff09\u6062\u590d\u6267\u884c\uff0c\u5e76\u7acb\u523b\u518d\u6b21\u8c03\u7528\u5b83\u81ea\u8eab\u3002\n\u51fd\u6570 0\uff08\u7b2c\u4e8c\u6b21\u9012\u5f52\u8c03\u7528\uff09\u5728\u65f6\u95f4\u6233 6 \u7684\u8d77\u59cb\u5f00\u59cb\u6267\u884c\uff0c\u6267\u884c 1 \u4e2a\u5355\u4f4d\u65f6\u95f4\u3002\n\u51fd\u6570 0\uff08\u521d\u59cb\u8c03\u7528\uff09\u5728\u65f6\u95f4\u6233 7 \u7684\u8d77\u59cb\u6062\u590d\u6267\u884c\uff0c\u6267\u884c 1 \u4e2a\u5355\u4f4d\u65f6\u95f4\u3002\n\u6240\u4ee5\u51fd\u6570 0 \u603b\u5171\u6267\u884c 2 + 4 + 1 + 1 = 8 \u4e2a\u5355\u4f4d\u65f6\u95f4\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 2, logs = [\"0:start:0\",\"0:start:2\",\"0:end:5\",\"1:start:6\",\"1:end:6\",\"0:end:7\"]\n\u8f93\u51fa\uff1a[7,1]\n\u89e3\u91ca\uff1a\n\u51fd\u6570 0 \u5728\u65f6\u95f4\u6233 0 \u7684\u8d77\u59cb\u5f00\u59cb\u6267\u884c\uff0c\u6267\u884c 2 \u4e2a\u5355\u4f4d\u65f6\u95f4\uff0c\u5e76\u9012\u5f52\u8c03\u7528\u5b83\u81ea\u8eab\u3002\n\u51fd\u6570 0\uff08\u9012\u5f52\u8c03\u7528\uff09\u5728\u65f6\u95f4\u6233 2 \u7684\u8d77\u59cb\u5f00\u59cb\u6267\u884c\uff0c\u6267\u884c 4 \u4e2a\u5355\u4f4d\u65f6\u95f4\u3002\n\u51fd\u6570 0\uff08\u521d\u59cb\u8c03\u7528\uff09\u6062\u590d\u6267\u884c\uff0c\u5e76\u7acb\u523b\u8c03\u7528\u51fd\u6570 1 \u3002\n\u51fd\u6570 1\u5728\u65f6\u95f4\u6233 6 \u7684\u8d77\u59cb\u5f00\u59cb\u6267\u884c\uff0c\u6267\u884c 1 \u4e2a\u5355\u4f4d\u65f6\u95f4\uff0c\u4e8e\u65f6\u95f4\u6233 6 \u7684\u672b\u5c3e\u7ed3\u675f\u6267\u884c\u3002\n\u51fd\u6570 0\uff08\u521d\u59cb\u8c03\u7528\uff09\u5728\u65f6\u95f4\u6233 7 \u7684\u8d77\u59cb\u6062\u590d\u6267\u884c\uff0c\u6267\u884c 1 \u4e2a\u5355\u4f4d\u65f6\u95f4\uff0c\u4e8e\u65f6\u95f4\u6233 7 \u7684\u672b\u5c3e\u7ed3\u675f\u6267\u884c\u3002\n\u6240\u4ee5\u51fd\u6570 0 \u603b\u5171\u6267\u884c 2 + 4 + 1 = 7 \u4e2a\u5355\u4f4d\u65f6\u95f4\uff0c\u51fd\u6570 1 \u603b\u5171\u6267\u884c 1 \u4e2a\u5355\u4f4d\u65f6\u95f4\u3002 
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 2, logs = [\"0:start:0\",\"0:start:2\",\"0:end:5\",\"1:start:7\",\"1:end:7\",\"0:end:8\"]\n\u8f93\u51fa\uff1a[8,1]\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 1, logs = [\"0:start:0\",\"0:end:0\"]\n\u8f93\u51fa\uff1a[1]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 100
    • \n\t
    • 1 <= logs.length <= 500
    • \n\t
    • 0 <= function_id < n
    • \n\t
    • 0 <= timestamp <= 109
    • \n\t
    • \u4e24\u4e2a\u5f00\u59cb\u4e8b\u4ef6\u4e0d\u4f1a\u5728\u540c\u4e00\u65f6\u95f4\u6233\u53d1\u751f
    • \n\t
    • \u4e24\u4e2a\u7ed3\u675f\u4e8b\u4ef6\u4e0d\u4f1a\u5728\u540c\u4e00\u65f6\u95f4\u6233\u53d1\u751f
    • \n\t
    • \u6bcf\u9053\u51fd\u6570\u90fd\u6709\u4e00\u4e2a\u5bf9\u5e94\u00a0\"start\" \u65e5\u5fd7\u7684 \"end\" \u65e5\u5fd7
    • \n
    \n", "tags_en": ["Stack"], "tags_cn": ["\u6808"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector exclusiveTime(int n, vector& logs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] exclusiveTime(int n, List logs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def exclusiveTime(self, n, logs):\n \"\"\"\n :type n: int\n :type logs: List[str]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def exclusiveTime(self, n: int, logs: List[str]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* exclusiveTime(int n, char ** logs, int logsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] ExclusiveTime(int n, IList logs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {string[]} logs\n * @return {number[]}\n */\nvar exclusiveTime = function(n, logs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {String[]} logs\n# @return {Integer[]}\ndef exclusive_time(n, logs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func exclusiveTime(_ n: Int, _ logs: [String]) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func exclusiveTime(n int, logs []string) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def exclusiveTime(n: Int, logs: List[String]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun exclusiveTime(n: Int, logs: List): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn exclusive_time(n: i32, logs: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param String[] $logs\n * @return Integer[]\n */\n function exclusiveTime($n, $logs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function exclusiveTime(n: number, logs: string[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (exclusive-time n logs)\n (-> exact-integer? (listof string?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0636](https://leetcode-cn.com/problems/exclusive-time-of-functions)", "[\u51fd\u6570\u7684\u72ec\u5360\u65f6\u95f4](/solution/0600-0699/0636.Exclusive%20Time%20of%20Functions/README.md)", "`\u6808`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0636](https://leetcode.com/problems/exclusive-time-of-functions)", "[Exclusive Time of Functions](/solution/0600-0699/0636.Exclusive%20Time%20of%20Functions/README_EN.md)", "`Stack`", "Medium", ""]}, {"question_id": "0635", "frontend_question_id": "0635", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/design-log-storage-system", "url_en": "https://leetcode.com/problems/design-log-storage-system", "relative_path_cn": "/solution/0600-0699/0635.Design%20Log%20Storage%20System/README.md", "relative_path_en": "/solution/0600-0699/0635.Design%20Log%20Storage%20System/README_EN.md", "title_cn": "\u8bbe\u8ba1\u65e5\u5fd7\u5b58\u50a8\u7cfb\u7edf", "title_en": "Design Log Storage System", "question_title_slug": "design-log-storage-system", "content_en": "

    You are given several logs, where each log contains a unique ID and timestamp. Timestamp is a string that has the following format: Year:Month:Day:Hour:Minute:Second, for example, 2017:01:01:23:59:59. All domains are zero-padded decimal numbers.

    \n\n

    Implement the LogSystem class:

    \n\n
      \n\t
    • LogSystem() Initializes the LogSystem object.
    • \n\t
    • void put(int id, string timestamp) Stores the given log (id, timestamp) in your storage system.
    • \n\t
    • int[] retrieve(string start, string end, string granularity) Returns the IDs of the logs whose timestamps are within the range from start to end inclusive. start and end all have the same format as timestamp, and granularity means how precise the range should be (i.e. to the exact Day, Minute, etc.). For example, start = "2017:01:01:23:59:59", end = "2017:01:02:23:59:59", and granularity = "Day" means that we need to find the logs within the inclusive range from Jan. 1st 2017 to Jan. 2nd 2017, and the Hour, Minute, and Second for each log entry can be ignored.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["LogSystem", "put", "put", "put", "retrieve", "retrieve"]\n[[], [1, "2017:01:01:23:59:59"], [2, "2017:01:01:22:59:59"], [3, "2016:01:01:00:00:00"], ["2016:01:01:01:01:01", "2017:01:01:23:00:00", "Year"], ["2016:01:01:01:01:01", "2017:01:01:23:00:00", "Hour"]]\nOutput\n[null, null, null, null, [3, 2, 1], [2, 1]]\n\nExplanation\nLogSystem logSystem = new LogSystem();\nlogSystem.put(1, "2017:01:01:23:59:59");\nlogSystem.put(2, "2017:01:01:22:59:59");\nlogSystem.put(3, "2016:01:01:00:00:00");\n\n// return [3,2,1], because you need to return all logs between 2016 and 2017.\nlogSystem.retrieve("2016:01:01:01:01:01", "2017:01:01:23:00:00", "Year");\n\n// return [2,1], because you need to return all logs between Jan. 1, 2016 01:XX:XX and Jan. 1, 2017 23:XX:XX.\n// Log 3 is not returned because Jan. 1, 2016 00:00:00 comes before the start of the range.\nlogSystem.retrieve("2016:01:01:01:01:01", "2017:01:01:23:00:00", "Hour");\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= id <= 500
    • \n\t
    • 2000 <= Year <= 2017
    • \n\t
    • 1 <= Month <= 12
    • \n\t
    • 1 <= Day <= 31
    • \n\t
    • 0 <= Hour <= 23
    • \n\t
    • 0 <= Minute, Second <= 59
    • \n\t
    • granularity is one of the values ["Year", "Month", "Day", "Hour", "Minute", "Second"].
    • \n\t
    • At most 500 calls will be made to put and retrieve.
    • \n
    \n", "content_cn": "

    \u4f60\u5c06\u83b7\u5f97\u591a\u6761\u65e5\u5fd7\uff0c\u6bcf\u6761\u65e5\u5fd7\u90fd\u6709\u552f\u4e00\u7684 id \u548c timestamp \uff0ctimestamp \u662f\u5f62\u5982 Year:Month:Day:Hour:Minute:Second \u7684\u5b57\u7b26\u4e32\uff0c2017:01:01:23:59:59 \uff0c\u6240\u6709\u503c\u57df\u90fd\u662f\u96f6\u586b\u5145\u7684\u5341\u8fdb\u5236\u6570\u3002

    \n\n

    \u5b9e\u73b0 LogSystem \u7c7b\uff1a

    \n\n
      \n\t
    • LogSystem() \u521d\u59cb\u5316 LogSystem \u5bf9\u8c61
    • \n\t
    • void put(int id, string timestamp) \u7ed9\u5b9a\u65e5\u5fd7\u7684 id \u548c timestamp \uff0c\u5c06\u8fd9\u4e2a\u65e5\u5fd7\u5b58\u5165\u4f60\u7684\u5b58\u50a8\u7cfb\u7edf\u4e2d\u3002
    • \n\t
    • int[] retrieve(string start, string end, string granularity) \u8fd4\u56de\u5728\u7ed9\u5b9a\u65f6\u95f4\u533a\u95f4 [start, end] \uff08\u5305\u542b\u4e24\u7aef\uff09\u5185\u7684\u6240\u6709\u65e5\u5fd7\u7684 id \u3002start \u3001end \u548c timestamp \u7684\u683c\u5f0f\u76f8\u540c\uff0cgranularity \u8868\u793a\u8003\u8651\u7684\u65f6\u95f4\u7c92\u5ea6\uff08\u4f8b\u5982\uff0c\u7cbe\u786e\u5230 Day\u3001Minute \u7b49\uff09\u3002\u4f8b\u5982 start = \"2017:01:01:23:59:59\"\u3001end = \"2017:01:02:23:59:59\" \u4e14 granularity = \"Day\" \u610f\u5473\u7740\u9700\u8981\u67e5\u627e\u4ece Jan. 1st 2017 \u5230 Jan. 2nd 2017 \u8303\u56f4\u5185\u7684\u65e5\u5fd7\uff0c\u53ef\u4ee5\u5ffd\u7565\u65e5\u5fd7\u7684 Hour\u3001Minute \u548c Second \u3002
    • \n
    \n\u00a0\n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\n[\"LogSystem\", \"put\", \"put\", \"put\", \"retrieve\", \"retrieve\"]\n[[], [1, \"2017:01:01:23:59:59\"], [2, \"2017:01:01:22:59:59\"], [3, \"2016:01:01:00:00:00\"], [\"2016:01:01:01:01:01\", \"2017:01:01:23:00:00\", \"Year\"], [\"2016:01:01:01:01:01\", \"2017:01:01:23:00:00\", \"Hour\"]]\n\u8f93\u51fa\uff1a\n[null, null, null, null, [3, 2, 1], [2, 1]]\n\n\u89e3\u91ca\uff1a\nLogSystem logSystem = new LogSystem();\nlogSystem.put(1, \"2017:01:01:23:59:59\");\nlogSystem.put(2, \"2017:01:01:22:59:59\");\nlogSystem.put(3, \"2016:01:01:00:00:00\");\n\n// \u8fd4\u56de [3,2,1]\uff0c\u8fd4\u56de\u4ece 2016 \u5e74\u5230 2017 \u5e74\u6240\u6709\u7684\u65e5\u5fd7\u3002\nlogSystem.retrieve(\"2016:01:01:01:01:01\", \"2017:01:01:23:00:00\", \"Year\");\n\n// \u8fd4\u56de [2,1]\uff0c\u8fd4\u56de\u4ece Jan. 1, 2016 01:XX:XX \u5230 Jan. 1, 2017 23:XX:XX \u4e4b\u95f4\u7684\u6240\u6709\u65e5\u5fd7\n// \u4e0d\u8fd4\u56de\u65e5\u5fd7 3 \u56e0\u4e3a\u8bb0\u5f55\u65f6\u95f4 Jan. 1, 2016 00:00:00 \u8d85\u8fc7\u8303\u56f4\u7684\u8d77\u59cb\u65f6\u95f4\nlogSystem.retrieve(\"2016:01:01:01:01:01\", \"2017:01:01:23:00:00\", \"Hour\");\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= id <= 500
    • \n\t
    • 2000 <= Year <= 2017
    • \n\t
    • 1 <= Month <= 12
    • \n\t
    • 1 <= Day <= 31
    • \n\t
    • 0 <= Hour <= 23
    • \n\t
    • 0 <= Minute, Second <= 59
    • \n\t
    • granularity \u662f\u8fd9\u4e9b\u503c [\"Year\", \"Month\", \"Day\", \"Hour\", \"Minute\", \"Second\"] \u4e4b\u4e00
    • \n\t
    • \u6700\u591a\u8c03\u7528 500 \u6b21 put \u548c retrieve
    • \n
    \n", "tags_en": ["Design", "String"], "tags_cn": ["\u8bbe\u8ba1", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class LogSystem {\npublic:\n LogSystem() {\n\n }\n \n void put(int id, string timestamp) {\n\n }\n \n vector retrieve(string start, string end, string granularity) {\n\n }\n};\n\n/**\n * Your LogSystem object will be instantiated and called as such:\n * LogSystem* obj = new LogSystem();\n * obj->put(id,timestamp);\n * vector param_2 = obj->retrieve(start,end,granularity);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class LogSystem {\n\n public LogSystem() {\n\n }\n \n public void put(int id, String timestamp) {\n\n }\n \n public List retrieve(String start, String end, String granularity) {\n\n }\n}\n\n/**\n * Your LogSystem object will be instantiated and called as such:\n * LogSystem obj = new LogSystem();\n * obj.put(id,timestamp);\n * List param_2 = obj.retrieve(start,end,granularity);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class LogSystem(object):\n\n def __init__(self):\n\n\n def put(self, id, timestamp):\n \"\"\"\n :type id: int\n :type timestamp: str\n :rtype: None\n \"\"\"\n\n\n def retrieve(self, start, end, granularity):\n \"\"\"\n :type start: str\n :type end: str\n :type granularity: str\n :rtype: List[int]\n \"\"\"\n\n\n\n# Your LogSystem object will be instantiated and called as such:\n# obj = LogSystem()\n# obj.put(id,timestamp)\n# param_2 = obj.retrieve(start,end,granularity)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class LogSystem:\n\n def __init__(self):\n\n\n def put(self, id: int, timestamp: str) -> None:\n\n\n def retrieve(self, start: str, end: str, granularity: str) -> List[int]:\n\n\n\n# Your LogSystem object will be instantiated and called as such:\n# obj = LogSystem()\n# obj.put(id,timestamp)\n# param_2 = obj.retrieve(start,end,granularity)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} LogSystem;\n\n\nLogSystem* logSystemCreate() {\n \n}\n\nvoid logSystemPut(LogSystem* obj, int id, char * timestamp) {\n \n}\n\nint* logSystemRetrieve(LogSystem* obj, char * start, char * end, char * granularity, int* retSize) {\n \n}\n\nvoid logSystemFree(LogSystem* obj) {\n \n}\n\n/**\n * Your LogSystem struct will be instantiated and called as such:\n * LogSystem* obj = logSystemCreate();\n * logSystemPut(obj, id, timestamp);\n \n * int* param_2 = logSystemRetrieve(obj, start, end, granularity, retSize);\n \n * logSystemFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class LogSystem {\n\n public LogSystem() {\n\n }\n \n public void Put(int id, string timestamp) {\n\n }\n \n public IList Retrieve(string start, string end, string granularity) {\n\n }\n}\n\n/**\n * Your LogSystem object will be instantiated and called as such:\n * LogSystem obj = new LogSystem();\n * obj.Put(id,timestamp);\n * IList param_2 = obj.Retrieve(start,end,granularity);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "\nvar LogSystem = function() {\n\n};\n\n/** \n * @param {number} id \n * @param {string} timestamp\n * @return {void}\n */\nLogSystem.prototype.put = function(id, timestamp) {\n\n};\n\n/** \n * @param {string} start \n * @param {string} end \n * @param {string} granularity\n * @return {number[]}\n */\nLogSystem.prototype.retrieve = function(start, end, granularity) {\n\n};\n\n/**\n * Your LogSystem object will be instantiated and called as such:\n * var obj = new LogSystem()\n * obj.put(id,timestamp)\n * var param_2 = obj.retrieve(start,end,granularity)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class LogSystem\n def initialize()\n\n end\n\n\n=begin\n :type id: Integer\n :type timestamp: String\n :rtype: Void\n=end\n def put(id, timestamp)\n\n end\n\n\n=begin\n :type start: String\n :type end: String\n :type granularity: String\n :rtype: Integer[]\n=end\n def retrieve(start, end, granularity)\n\n end\n\n\nend\n\n# Your LogSystem object will be instantiated and called as such:\n# obj = LogSystem.new()\n# obj.put(id, timestamp)\n# param_2 = obj.retrieve(start, end, granularity)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass LogSystem {\n\n init() {\n \n }\n \n func put(_ id: Int, _ timestamp: String) {\n \n }\n \n func retrieve(_ start: String, _ end: String, _ granularity: String) -> [Int] {\n \n }\n}\n\n/**\n * Your LogSystem object will be instantiated and called as such:\n * let obj = LogSystem()\n * obj.put(id, timestamp)\n * let ret_2: [Int] = obj.retrieve(start, end, granularity)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type LogSystem struct {\n\n}\n\n\nfunc Constructor() LogSystem {\n\n}\n\n\nfunc (this *LogSystem) Put(id int, timestamp string) {\n\n}\n\n\nfunc (this *LogSystem) Retrieve(start string, end string, granularity string) []int {\n\n}\n\n\n/**\n * Your LogSystem object will be instantiated and called as such:\n * obj := Constructor();\n * obj.Put(id,timestamp);\n * param_2 := obj.Retrieve(start,end,granularity);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class LogSystem() {\n\n def put(id: Int, timestamp: String) {\n\n }\n\n def retrieve(start: String, end: String, granularity: String): List[Int] = {\n\n }\n\n}\n\n/**\n * Your LogSystem object will be instantiated and called as such:\n * var obj = new LogSystem()\n * obj.put(id,timestamp)\n * var param_2 = obj.retrieve(start,end,granularity)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class LogSystem() {\n\n fun put(id: Int, timestamp: String) {\n\n }\n\n fun retrieve(start: String, end: String, granularity: String): List {\n\n }\n\n}\n\n/**\n * Your LogSystem object will be instantiated and called as such:\n * var obj = LogSystem()\n * obj.put(id,timestamp)\n * var param_2 = obj.retrieve(start,end,granularity)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct LogSystem {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl LogSystem {\n\n fn new() -> Self {\n\n }\n \n fn put(&self, id: i32, timestamp: String) {\n\n }\n \n fn retrieve(&self, start: String, end: String, granularity: String) -> Vec {\n\n }\n}\n\n/**\n * Your LogSystem object will be instantiated and called as such:\n * let obj = LogSystem::new();\n * obj.put(id, timestamp);\n * let ret_2: Vec = obj.retrieve(start, end, granularity);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class LogSystem {\n /**\n */\n function __construct() {\n\n }\n\n /**\n * @param Integer $id\n * @param String $timestamp\n * @return NULL\n */\n function put($id, $timestamp) {\n\n }\n\n /**\n * @param String $start\n * @param String $end\n * @param String $granularity\n * @return Integer[]\n */\n function retrieve($start, $end, $granularity) {\n\n }\n}\n\n/**\n * Your LogSystem object will be instantiated and called as such:\n * $obj = LogSystem();\n * $obj->put($id, $timestamp);\n * $ret_2 = $obj->retrieve($start, $end, $granularity);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class LogSystem {\n constructor() {\n\n }\n\n put(id: number, timestamp: string): void {\n\n }\n\n retrieve(start: string, end: string, granularity: string): number[] {\n\n }\n}\n\n/**\n * Your LogSystem object will be instantiated and called as such:\n * var obj = new LogSystem()\n * obj.put(id,timestamp)\n * var param_2 = obj.retrieve(start,end,granularity)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define log-system%\n (class object%\n (super-new)\n (init-field)\n \n ; put : exact-integer? string? -> void?\n (define/public (put id timestamp)\n\n )\n ; retrieve : string? string? string? -> (listof exact-integer?)\n (define/public (retrieve start end granularity)\n\n )))\n\n;; Your log-system% object will be instantiated and called as such:\n;; (define obj (new log-system%))\n;; (send obj put id timestamp)\n;; (define param_2 (send obj retrieve start end granularity))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0635](https://leetcode-cn.com/problems/design-log-storage-system)", "[\u8bbe\u8ba1\u65e5\u5fd7\u5b58\u50a8\u7cfb\u7edf](/solution/0600-0699/0635.Design%20Log%20Storage%20System/README.md)", "`\u8bbe\u8ba1`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0635](https://leetcode.com/problems/design-log-storage-system)", "[Design Log Storage System](/solution/0600-0699/0635.Design%20Log%20Storage%20System/README_EN.md)", "`Design`,`String`", "Medium", "\ud83d\udd12"]}, {"question_id": "0634", "frontend_question_id": "0634", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/find-the-derangement-of-an-array", "url_en": "https://leetcode.com/problems/find-the-derangement-of-an-array", "relative_path_cn": "/solution/0600-0699/0634.Find%20the%20Derangement%20of%20An%20Array/README.md", "relative_path_en": "/solution/0600-0699/0634.Find%20the%20Derangement%20of%20An%20Array/README_EN.md", "title_cn": "\u5bfb\u627e\u6570\u7ec4\u7684\u9519\u4f4d\u6392\u5217", "title_en": "Find the Derangement of An Array", "question_title_slug": "find-the-derangement-of-an-array", "content_en": "

    In combinatorial mathematics, a derangement is a permutation of the elements of a set, such that no element appears in its original position.

    \n\n

    You are given an integer n. There is originally an array consisting of n integers from 1 to n in ascending order, return the number of derangements it can generate. Since the answer may be huge, return it modulo 109 + 7.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 3\nOutput: 2\nExplanation: The original array is [1,2,3]. The two derangements are [2,3,1] and [3,1,2].\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 2\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 106
    • \n
    \n", "content_cn": "

    \u5728\u7ec4\u5408\u6570\u5b66\u4e2d\uff0c\u5982\u679c\u4e00\u4e2a\u6392\u5217\u4e2d\u6240\u6709\u5143\u7d20\u90fd\u4e0d\u5728\u539f\u5148\u7684\u4f4d\u7f6e\u4e0a\uff0c\u90a3\u4e48\u8fd9\u4e2a\u6392\u5217\u5c31\u88ab\u79f0\u4e3a\u9519\u4f4d\u6392\u5217\u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u4ece 1 \u5230 n \u5347\u5e8f\u6392\u5217\u7684\u6570\u7ec4\uff0c\u4f60\u53ef\u4ee5\u8ba1\u7b97\u51fa\u603b\u5171\u6709\u591a\u5c11\u4e2a\u4e0d\u540c\u7684\u9519\u4f4d\u6392\u5217\u5417\uff1f

    \n\n

    \u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u975e\u5e38\u5927\uff0c\u4f60\u53ea\u9700\u8981\u5c06\u7b54\u6848\u5bf9 109+7 \u53d6\u4f59\u8f93\u51fa\u5373\u53ef\u3002

    \n\n

     

    \n\n

    \u6837\u4f8b 1:

    \n\n
    \u8f93\u5165: 3\n\u8f93\u51fa: 2\n\u89e3\u91ca: \u539f\u59cb\u7684\u6570\u7ec4\u4e3a [1,2,3]\u3002\u4e24\u4e2a\u9519\u4f4d\u6392\u5217\u7684\u6570\u7ec4\u4e3a [2,3,1] \u548c [3,1,2]\u3002\n
    \n\n

     

    \n\n

    \u6ce8\u91ca:
    \nn \u7684\u8303\u56f4\u662f [1, 106]\u3002

    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findDerangement(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findDerangement(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findDerangement(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findDerangement(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findDerangement(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindDerangement(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar findDerangement = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef find_derangement(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findDerangement(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findDerangement(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findDerangement(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findDerangement(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_derangement(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function findDerangement($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findDerangement(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-derangement n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0634](https://leetcode-cn.com/problems/find-the-derangement-of-an-array)", "[\u5bfb\u627e\u6570\u7ec4\u7684\u9519\u4f4d\u6392\u5217](/solution/0600-0699/0634.Find%20the%20Derangement%20of%20An%20Array/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0634](https://leetcode.com/problems/find-the-derangement-of-an-array)", "[Find the Derangement of An Array](/solution/0600-0699/0634.Find%20the%20Derangement%20of%20An%20Array/README_EN.md)", "`Math`", "Medium", "\ud83d\udd12"]}, {"question_id": "0633", "frontend_question_id": "0633", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sum-of-square-numbers", "url_en": "https://leetcode.com/problems/sum-of-square-numbers", "relative_path_cn": "/solution/0600-0699/0633.Sum%20of%20Square%20Numbers/README.md", "relative_path_en": "/solution/0600-0699/0633.Sum%20of%20Square%20Numbers/README_EN.md", "title_cn": "\u5e73\u65b9\u6570\u4e4b\u548c", "title_en": "Sum of Square Numbers", "question_title_slug": "sum-of-square-numbers", "content_en": "

    Given a non-negative integer c, decide whether there're two integers a and b such that a2 + b2 = c.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: c = 5\nOutput: true\nExplanation: 1 * 1 + 2 * 2 = 5\n
    \n\n

    Example 2:

    \n\n
    \nInput: c = 3\nOutput: false\n
    \n\n

    Example 3:

    \n\n
    \nInput: c = 4\nOutput: true\n
    \n\n

    Example 4:

    \n\n
    \nInput: c = 2\nOutput: true\n
    \n\n

    Example 5:

    \n\n
    \nInput: c = 1\nOutput: true\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= c <= 231 - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u8d1f\u6574\u6570 c \uff0c\u4f60\u8981\u5224\u65ad\u662f\u5426\u5b58\u5728\u4e24\u4e2a\u6574\u6570 a \u548c b\uff0c\u4f7f\u5f97 a2 + b2 = c \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1ac = 5\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a1 * 1 + 2 * 2 = 5\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1ac = 3\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1ac = 4\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1ac = 2\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1ac = 1\n\u8f93\u51fa\uff1atrue
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= c <= 231 - 1
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool judgeSquareSum(int c) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean judgeSquareSum(int c) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def judgeSquareSum(self, c):\n \"\"\"\n :type c: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def judgeSquareSum(self, c: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool judgeSquareSum(int c){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool JudgeSquareSum(int c) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} c\n * @return {boolean}\n */\nvar judgeSquareSum = function(c) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} c\n# @return {Boolean}\ndef judge_square_sum(c)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func judgeSquareSum(_ c: Int) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func judgeSquareSum(c int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def judgeSquareSum(c: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun judgeSquareSum(c: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn judge_square_sum(c: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $c\n * @return Boolean\n */\n function judgeSquareSum($c) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function judgeSquareSum(c: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (judge-square-sum c)\n (-> exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0633](https://leetcode-cn.com/problems/sum-of-square-numbers)", "[\u5e73\u65b9\u6570\u4e4b\u548c](/solution/0600-0699/0633.Sum%20of%20Square%20Numbers/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0633](https://leetcode.com/problems/sum-of-square-numbers)", "[Sum of Square Numbers](/solution/0600-0699/0633.Sum%20of%20Square%20Numbers/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "0632", "frontend_question_id": "0632", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/smallest-range-covering-elements-from-k-lists", "url_en": "https://leetcode.com/problems/smallest-range-covering-elements-from-k-lists", "relative_path_cn": "/solution/0600-0699/0632.Smallest%20Range%20Covering%20Elements%20from%20K%20Lists/README.md", "relative_path_en": "/solution/0600-0699/0632.Smallest%20Range%20Covering%20Elements%20from%20K%20Lists/README_EN.md", "title_cn": "\u6700\u5c0f\u533a\u95f4", "title_en": "Smallest Range Covering Elements from K Lists", "question_title_slug": "smallest-range-covering-elements-from-k-lists", "content_en": "

    You have k lists of sorted integers in non-decreasing order. Find the smallest range that includes at least one number from each of the k lists.

    \n\n

    We define the range [a, b] is smaller than range [c, d] if b - a < d - c or a < c if b - a == d - c.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [[4,10,15,24,26],[0,9,12,20],[5,18,22,30]]\nOutput: [20,24]\nExplanation: \nList 1: [4, 10, 15, 24,26], 24 is in range [20,24].\nList 2: [0, 9, 12, 20], 20 is in range [20,24].\nList 3: [5, 18, 22, 30], 22 is in range [20,24].\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [[1,2,3],[1,2,3],[1,2,3]]\nOutput: [1,1]\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [[10,10],[11,11]]\nOutput: [10,11]\n
    \n\n

    Example 4:

    \n\n
    \nInput: nums = [[10],[11]]\nOutput: [10,11]\n
    \n\n

    Example 5:

    \n\n
    \nInput: nums = [[1],[2],[3],[4],[5],[6],[7]]\nOutput: [1,7]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • nums.length == k
    • \n\t
    • 1 <= k <= 3500
    • \n\t
    • 1 <= nums[i].length <= 50
    • \n\t
    • -105 <= nums[i][j] <= 105
    • \n\t
    • nums[i] is sorted in non-decreasing order.
    • \n
    \n", "content_cn": "

    \u4f60\u6709\u00a0k\u00a0\u4e2a \u975e\u9012\u51cf\u6392\u5217 \u7684\u6574\u6570\u5217\u8868\u3002\u627e\u5230\u4e00\u4e2a \u6700\u5c0f \u533a\u95f4\uff0c\u4f7f\u5f97\u00a0k\u00a0\u4e2a\u5217\u8868\u4e2d\u7684\u6bcf\u4e2a\u5217\u8868\u81f3\u5c11\u6709\u4e00\u4e2a\u6570\u5305\u542b\u5728\u5176\u4e2d\u3002

    \n\n

    \u6211\u4eec\u5b9a\u4e49\u5982\u679c\u00a0b-a < d-c\u00a0\u6216\u8005\u5728\u00a0b-a == d-c\u00a0\u65f6\u00a0a < c\uff0c\u5219\u533a\u95f4 [a,b] \u6bd4 [c,d] \u5c0f\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [[4,10,15,24,26], [0,9,12,20], [5,18,22,30]]\n\u8f93\u51fa\uff1a[20,24]\n\u89e3\u91ca\uff1a \n\u5217\u8868 1\uff1a[4, 10, 15, 24, 26]\uff0c24 \u5728\u533a\u95f4 [20,24] \u4e2d\u3002\n\u5217\u8868 2\uff1a[0, 9, 12, 20]\uff0c20 \u5728\u533a\u95f4 [20,24] \u4e2d\u3002\n\u5217\u8868 3\uff1a[5, 18, 22, 30]\uff0c22 \u5728\u533a\u95f4 [20,24] \u4e2d\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [[1,2,3],[1,2,3],[1,2,3]]\n\u8f93\u51fa\uff1a[1,1]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [[10,10],[11,11]]\n\u8f93\u51fa\uff1a[10,11]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [[10],[11]]\n\u8f93\u51fa\uff1a[10,11]\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [[1],[2],[3],[4],[5],[6],[7]]\n\u8f93\u51fa\uff1a[1,7]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • nums.length == k
    • \n\t
    • 1 <= k <= 3500
    • \n\t
    • 1 <= nums[i].length <= 50
    • \n\t
    • -105 <= nums[i][j] <= 105
    • \n\t
    • nums[i] \u6309\u975e\u9012\u51cf\u987a\u5e8f\u6392\u5217
    • \n
    \n", "tags_en": ["Hash Table", "Two Pointers", "String"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u53cc\u6307\u9488", "\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector smallestRange(vector>& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] smallestRange(List> nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def smallestRange(self, nums):\n \"\"\"\n :type nums: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def smallestRange(self, nums: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* smallestRange(int** nums, int numsSize, int* numsColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] SmallestRange(IList> nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} nums\n * @return {number[]}\n */\nvar smallestRange = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} nums\n# @return {Integer[]}\ndef smallest_range(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func smallestRange(_ nums: [[Int]]) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func smallestRange(nums [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def smallestRange(nums: List[List[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun smallestRange(nums: List>): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn smallest_range(nums: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $nums\n * @return Integer[]\n */\n function smallestRange($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function smallestRange(nums: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (smallest-range nums)\n (-> (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0632](https://leetcode-cn.com/problems/smallest-range-covering-elements-from-k-lists)", "[\u6700\u5c0f\u533a\u95f4](/solution/0600-0699/0632.Smallest%20Range%20Covering%20Elements%20from%20K%20Lists/README.md)", "`\u54c8\u5e0c\u8868`,`\u53cc\u6307\u9488`,`\u5b57\u7b26\u4e32`", "\u56f0\u96be", ""], "md_table_row_en": ["[0632](https://leetcode.com/problems/smallest-range-covering-elements-from-k-lists)", "[Smallest Range Covering Elements from K Lists](/solution/0600-0699/0632.Smallest%20Range%20Covering%20Elements%20from%20K%20Lists/README_EN.md)", "`Hash Table`,`Two Pointers`,`String`", "Hard", ""]}, {"question_id": "0631", "frontend_question_id": "0631", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/design-excel-sum-formula", "url_en": "https://leetcode.com/problems/design-excel-sum-formula", "relative_path_cn": "/solution/0600-0699/0631.Design%20Excel%20Sum%20Formula/README.md", "relative_path_en": "/solution/0600-0699/0631.Design%20Excel%20Sum%20Formula/README_EN.md", "title_cn": "\u8bbe\u8ba1 Excel \u6c42\u548c\u516c\u5f0f", "title_en": "Design Excel Sum Formula", "question_title_slug": "design-excel-sum-formula", "content_en": "

    Design the basic function of Excel and implement the function of the sum formula.

    \n\n

    Implement the Excel class:

    \n\n
      \n\t
    • Excel(int height, char width) Initializes the object with the height and the width of the sheet. The sheet is an integer matrix mat of size height x width with the row index in the range [1, height] and the column index in the range ['A', width]. All the values should be zero initially.
    • \n\t
    • void set(int row, char column, int val) Changes the value at mat[row][column] to be val.
    • \n\t
    • int get(int row, char column) Returns the value at mat[row][column].
    • \n\t
    • int sum(int row, char column, List<String> numbers) Sets the value at mat[row][column] to be the sum of cells represented by numbers and returns the value at mat[row][column]. This sum formula should exist until this cell is overlapped by another value or another sum formula. numbers[i] could be on the format:\n\t
        \n\t\t
      • "ColRow" that represents a single cell.\n\t\t
          \n\t\t\t
        • For example, "F7" represents the cell mat[7]['F'].
        • \n\t\t
        \n\t\t
      • \n\t\t
      • "ColRow1:ColRow2" that represents a range of cells. The range will always be a rectangle where "ColRow1" represent the position of the top-left cell, and "ColRow2" represents the position of the bottom-right cell.\n\t\t
          \n\t\t\t
        • For example, "B3:F7" represents the cells mat[i][j] for 3 <= i <= 7 and 'B' <= j <= 'F'.
        • \n\t\t
        \n\t\t
      • \n\t
      \n\t
    • \n
    \n\n

    Note: You could assume that there will not be any circular sum reference.

    \n\n
      \n\t
    • For example, mat[1]['A'] == sum(1, "B") and mat[1]['B'] == sum(1, "A").
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["Excel", "set", "sum", "set", "get"]\n[[3, "C"], [1, "A", 2], [3, "C", ["A1", "A1:B2"]], [2, "B", 2], [3, "C"]]\nOutput\n[null, null, 4, null, 6]\n\nExplanation\nExcel excel = new Excel(3, "C");\n // construct a 3*3 2D array with all zero.\n //   A B C\n // 1 0 0 0\n // 2 0 0 0\n // 3 0 0 0\nexcel.set(1, "A", 2);\n // set mat[2]["B"] to be 2.\n //   A B C\n // 1 2 0 0\n // 2 0 0 0\n // 3 0 0 0\nexcel.sum(3, "C", ["A1", "A1:B2"]); // return 4\n // set mat[3]["C"] to be the sum of value at mat[1]["A"] and the values sum of the rectangle range whose top-left cell is mat[1]["A"] and bottom-right cell is mat[2]["B"].\n //   A B C\n // 1 2 0 0\n // 2 0 0 0\n // 3 0 0 4\nexcel.set(2, "B", 2);\n // set mat[2]["B"] to be 2. Note mat[3]["C"] should also be changed.\n //   A B C\n // 1 2 0 0\n // 2 0 2 0\n // 3 0 0 6\nexcel.get(3, "C"); // return 6\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= height <= 26
    • \n\t
    • 'A' <= width <= 'Z'
    • \n\t
    • 1 <= row <= height
    • \n\t
    • 'A' <= column <= width
    • \n\t
    • -100 <= val <= 100
    • \n\t
    • 1 <= numbers.length <= 5
    • \n\t
    • numbers[i] has the format "ColRow" or "ColRow1:ColRow2".
    • \n\t
    • At most 100 calls will be made to set, get, and sum.
    • \n
    \n", "content_cn": "

    \u4f60\u7684\u4efb\u52a1\u662f\u5b9e\u73b0 Excel \u7684\u6c42\u548c\u529f\u80fd\uff0c\u5177\u4f53\u7684\u64cd\u4f5c\u5982\u4e0b\uff1a

    \n\n

    Excel(int H, char W): \u8fd9\u662f\u4e00\u4e2a\u6784\u9020\u51fd\u6570\uff0c\u8f93\u5165\u8868\u660e\u4e86 Excel \u7684\u9ad8\u5ea6\u548c\u5bbd\u5ea6\u3002H \u662f\u4e00\u4e2a\u6b63\u6574\u6570\uff0c\u8303\u56f4\u4ece 1 \u5230 26\uff0c\u4ee3\u8868\u9ad8\u5ea6\u3002W \u662f\u4e00\u4e2a\u5b57\u7b26\uff0c\u8303\u56f4\u4ece 'A' \u5230 'Z'\uff0c\u5bbd\u5ea6\u7b49\u4e8e\u4ece 'A' \u5230 W \u7684\u5b57\u6bcd\u4e2a\u6570\u3002Excel \u8868\u683c\u662f\u4e00\u4e2a\u9ad8\u5ea6 * \u5bbd\u5ea6\u7684\u4e8c\u7ef4\u6574\u6570\u6570\u7ec4\uff0c\u6570\u7ec4\u4e2d\u5143\u7d20\u521d\u59cb\u5316\u4e3a 0\u3002\u7b2c\u4e00\u884c\u4e0b\u6807\u4ece 1 \u5f00\u59cb\uff0c\u7b2c\u4e00\u5217\u4e0b\u6807\u4ece 'A' \u5f00\u59cb\u3002

    \n\n

     

    \n\n

    void Set(int row, char column, int val): \u8bbe\u7f6e C(row, column) \u4e2d\u7684\u503c\u4e3a val\u3002

    \n\n

     

    \n\n

    int Get(int row, char column): \u8fd4\u56de C(row, column) \u4e2d\u7684\u503c\u3002

    \n\n

     

    \n\n

    int Sum(int row, char column, List of Strings : numbers): \u8fd9\u4e2a\u51fd\u6570\u4f1a\u5c06\u8ba1\u7b97\u7684\u7ed3\u679c\u653e\u5165 C(row, column) \u4e2d\uff0c\u8ba1\u7b97\u7684\u7ed3\u679c\u7b49\u4e8e\u5728 numbers \u4e2d\u4ee3\u8868\u7684\u6240\u6709\u5143\u7d20\u4e4b\u548c\uff0c\u8fd9\u4e2a\u51fd\u6570\u540c\u65f6\u4e5f\u4f1a\u5c06\u8fd9\u4e2a\u7ed3\u679c\u8fd4\u56de\u3002\u6c42\u548c\u516c\u5f0f\u4f1a\u4e00\u76f4\u8ba1\u7b97\u66f4\u65b0\u7ed3\u679c\u76f4\u5230\u8fd9\u4e2a\u516c\u5f0f\u88ab\u5176\u4ed6\u7684\u503c\u6216\u8005\u516c\u5f0f\u8986\u76d6\u3002

    \n\n

    numbers \u662f\u82e5\u5e72\u5b57\u7b26\u4e32\u7684\u96c6\u5408\uff0c\u6bcf\u4e2a\u5b57\u7b26\u4e32\u4ee3\u8868\u5355\u4e2a\u4f4d\u7f6e\u6216\u4e00\u4e2a\u533a\u95f4\u3002\u5982\u679c\u8fd9\u4e2a\u5b57\u7b26\u4e32\u8868\u793a\u5355\u4e2a\u4f4d\u7f6e\uff0c\u5b83\u7684\u683c\u5f0f\u5982\u4e0b\uff1aColRow\uff0c\u4f8b\u5982 "F7" \u8868\u793a\u4f4d\u7f6e (7, F) \u3002\u5982\u679c\u8fd9\u4e2a\u5b57\u7b26\u4e32\u8868\u793a\u4e00\u4e2a\u533a\u95f4\uff0c\u5b83\u7684\u683c\u5f0f\u5982\u4e0b\uff1aColRow1:ColRow2\u3002\u533a\u95f4\u5c31\u662f\u5de6\u4e0a\u89d2\u4e3a ColRow1 \u53f3\u4e0b\u89d2\u4e3a ColRow2 \u7684\u957f\u65b9\u5f62\u3002

    \n\n

     

    \n\n

    \u6837\u4f8b 1 \uff1a

    \n\n

     

    \n\n
    Excel(3,"C"); \n// \u6784\u9020\u4e00\u4e2a 3*3 \u7684\u4e8c\u7ef4\u6570\u7ec4\uff0c\u521d\u59cb\u5316\u5168\u662f 0\u3002\n//   A B C\n// 1 0 0 0\n// 2 0 0 0\n// 3 0 0 0\n\nSet(1, "A", 2);\n// \u8bbe\u7f6e C(1,"A") \u4e3a 2\u3002\n//   A B C\n// 1 2 0 0\n// 2 0 0 0\n// 3 0 0 0\n\nSum(3, "C", ["A1", "A1:B2"]);\n// \u5c06 C(3,"C") \u7684\u503c\u8bbe\u4e3a C(1,"A") \u5355\u70b9\uff0c\u5de6\u4e0a\u89d2\u4e3a C(1,"A") \u53f3\u4e0b\u89d2\u4e3a C(2,"B") \u7684\u957f\u65b9\u5f62\uff0c\u6240\u6709\u5143\u7d20\u4e4b\u548c\u3002\u8fd4\u56de\u503c 4\u3002 \n//   A B C\n// 1 2 0 0\n// 2 0 0 0\n// 3 0 0 4\n\nSet(2, "B", 2);\n// \u5c06 C(2,"B") \u8bbe\u4e3a 2\u3002 \u6ce8\u610f C(3, "C") \u7684\u503c\u4e5f\u540c\u65f6\u6539\u53d8\u3002\n//   A B C\n// 1 2 0 0\n// 2 0 2 0\n// 3 0 0 6\n
    \n\n

     

    \n\n

    \u6ce8\u91ca \uff1a

    \n\n
      \n\t
    1. \u4f60\u53ef\u4ee5\u8ba4\u4e3a\u4e0d\u4f1a\u51fa\u73b0\u5faa\u73af\u6c42\u548c\u7684\u5b9a\u4e49\uff0c\u6bd4\u5982\u8bf4\uff1a A1 = sum(B1) \uff0cB1 = sum(A1)\u3002
    2. \n\t
    3. \u6d4b\u8bd5\u6570\u636e\u4e2d\uff0c\u5b57\u6bcd\u8868\u793a\u7528\u53cc\u5f15\u53f7\u3002
    4. \n\t
    5. \u8bf7\u8bb0\u4f4f\u6e05\u96f6 Excel \u7c7b\u4e2d\u7684\u53d8\u91cf\uff0c\u56e0\u4e3a\u9759\u6001\u53d8\u91cf\u3001\u7c7b\u53d8\u91cf\u4f1a\u5728\u591a\u7ec4\u6d4b\u8bd5\u6570\u636e\u4e2d\u4fdd\u5b58\u4e4b\u524d\u7ed3\u679c\u3002\u8be6\u60c5\u8bf7\u770b\u8fd9\u91cc\u3002
    6. \n
    \n\n

     

    \n", "tags_en": ["Design"], "tags_cn": ["\u8bbe\u8ba1"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Excel {\npublic:\n Excel(int height, char width) {\n\n }\n \n void set(int row, char column, int val) {\n\n }\n \n int get(int row, char column) {\n\n }\n \n int sum(int row, char column, vector numbers) {\n\n }\n};\n\n/**\n * Your Excel object will be instantiated and called as such:\n * Excel* obj = new Excel(height, width);\n * obj->set(row,column,val);\n * int param_2 = obj->get(row,column);\n * int param_3 = obj->sum(row,column,numbers);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Excel {\n\n public Excel(int height, char width) {\n\n }\n \n public void set(int row, char column, int val) {\n\n }\n \n public int get(int row, char column) {\n\n }\n \n public int sum(int row, char column, String[] numbers) {\n\n }\n}\n\n/**\n * Your Excel object will be instantiated and called as such:\n * Excel obj = new Excel(height, width);\n * obj.set(row,column,val);\n * int param_2 = obj.get(row,column);\n * int param_3 = obj.sum(row,column,numbers);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Excel(object):\n\n def __init__(self, height, width):\n \"\"\"\n :type height: int\n :type width: str\n \"\"\"\n\n\n def set(self, row, column, val):\n \"\"\"\n :type row: int\n :type column: str\n :type val: int\n :rtype: None\n \"\"\"\n\n\n def get(self, row, column):\n \"\"\"\n :type row: int\n :type column: str\n :rtype: int\n \"\"\"\n\n\n def sum(self, row, column, numbers):\n \"\"\"\n :type row: int\n :type column: str\n :type numbers: List[str]\n :rtype: int\n \"\"\"\n\n\n\n# Your Excel object will be instantiated and called as such:\n# obj = Excel(height, width)\n# obj.set(row,column,val)\n# param_2 = obj.get(row,column)\n# param_3 = obj.sum(row,column,numbers)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Excel:\n\n def __init__(self, height: int, width: str):\n\n\n def set(self, row: int, column: str, val: int) -> None:\n\n\n def get(self, row: int, column: str) -> int:\n\n\n def sum(self, row: int, column: str, numbers: List[str]) -> int:\n\n\n\n# Your Excel object will be instantiated and called as such:\n# obj = Excel(height, width)\n# obj.set(row,column,val)\n# param_2 = obj.get(row,column)\n# param_3 = obj.sum(row,column,numbers)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} Excel;\n\n\nExcel* excelCreate(int height, char width) {\n \n}\n\nvoid excelSet(Excel* obj, int row, char column, int val) {\n \n}\n\nint excelGet(Excel* obj, int row, char column) {\n \n}\n\nint excelSum(Excel* obj, int row, char column, char ** numbers, int numbersSize) {\n \n}\n\nvoid excelFree(Excel* obj) {\n \n}\n\n/**\n * Your Excel struct will be instantiated and called as such:\n * Excel* obj = excelCreate(height, width);\n * excelSet(obj, row, column, val);\n \n * int param_2 = excelGet(obj, row, column);\n \n * int param_3 = excelSum(obj, row, column, numbers, numbersSize);\n \n * excelFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Excel {\n\n public Excel(int height, char width) {\n\n }\n \n public void Set(int row, char column, int val) {\n\n }\n \n public int Get(int row, char column) {\n\n }\n \n public int Sum(int row, char column, string[] numbers) {\n\n }\n}\n\n/**\n * Your Excel object will be instantiated and called as such:\n * Excel obj = new Excel(height, width);\n * obj.Set(row,column,val);\n * int param_2 = obj.Get(row,column);\n * int param_3 = obj.Sum(row,column,numbers);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} height\n * @param {character} width\n */\nvar Excel = function(height, width) {\n\n};\n\n/** \n * @param {number} row \n * @param {character} column \n * @param {number} val\n * @return {void}\n */\nExcel.prototype.set = function(row, column, val) {\n\n};\n\n/** \n * @param {number} row \n * @param {character} column\n * @return {number}\n */\nExcel.prototype.get = function(row, column) {\n\n};\n\n/** \n * @param {number} row \n * @param {character} column \n * @param {string[]} numbers\n * @return {number}\n */\nExcel.prototype.sum = function(row, column, numbers) {\n\n};\n\n/**\n * Your Excel object will be instantiated and called as such:\n * var obj = new Excel(height, width)\n * obj.set(row,column,val)\n * var param_2 = obj.get(row,column)\n * var param_3 = obj.sum(row,column,numbers)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class Excel\n\n=begin\n :type height: Integer\n :type width: Character\n=end\n def initialize(height, width)\n\n end\n\n\n=begin\n :type row: Integer\n :type column: Character\n :type val: Integer\n :rtype: Void\n=end\n def set(row, column, val)\n\n end\n\n\n=begin\n :type row: Integer\n :type column: Character\n :rtype: Integer\n=end\n def get(row, column)\n\n end\n\n\n=begin\n :type row: Integer\n :type column: Character\n :type numbers: String[]\n :rtype: Integer\n=end\n def sum(row, column, numbers)\n\n end\n\n\nend\n\n# Your Excel object will be instantiated and called as such:\n# obj = Excel.new(height, width)\n# obj.set(row, column, val)\n# param_2 = obj.get(row, column)\n# param_3 = obj.sum(row, column, numbers)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass Excel {\n\n init(_ height: Int, _ width: Character) {\n\n }\n \n func set(_ row: Int, _ column: Character, _ val: Int) {\n\n }\n \n func get(_ row: Int, _ column: Character) -> Int {\n\n }\n \n func sum(_ row: Int, _ column: Character, _ numbers: [String]) -> Int {\n\n }\n}\n\n/**\n * Your Excel object will be instantiated and called as such:\n * let obj = Excel(height, width)\n * obj.set(row, column, val)\n * let ret_2: Int = obj.get(row, column)\n * let ret_3: Int = obj.sum(row, column, numbers)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type Excel struct {\n\n}\n\n\nfunc Constructor(height int, width byte) Excel {\n\n}\n\n\nfunc (this *Excel) Set(row int, column byte, val int) {\n\n}\n\n\nfunc (this *Excel) Get(row int, column byte) int {\n\n}\n\n\nfunc (this *Excel) Sum(row int, column byte, numbers []string) int {\n\n}\n\n\n/**\n * Your Excel object will be instantiated and called as such:\n * obj := Constructor(height, width);\n * obj.Set(row,column,val);\n * param_2 := obj.Get(row,column);\n * param_3 := obj.Sum(row,column,numbers);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class Excel(_height: Int, _width: Char) {\n\n def set(row: Int, column: Char, `val`: Int) {\n\n }\n\n def get(row: Int, column: Char): Int = {\n\n }\n\n def sum(row: Int, column: Char, numbers: Array[String]): Int = {\n\n }\n\n}\n\n/**\n * Your Excel object will be instantiated and called as such:\n * var obj = new Excel(height, width)\n * obj.set(row,column,`val`)\n * var param_2 = obj.get(row,column)\n * var param_3 = obj.sum(row,column,numbers)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Excel(height: Int, width: Char) {\n\n fun set(row: Int, column: Char, `val`: Int) {\n\n }\n\n fun get(row: Int, column: Char): Int {\n\n }\n\n fun sum(row: Int, column: Char, numbers: Array): Int {\n\n }\n\n}\n\n/**\n * Your Excel object will be instantiated and called as such:\n * var obj = Excel(height, width)\n * obj.set(row,column,`val`)\n * var param_2 = obj.get(row,column)\n * var param_3 = obj.sum(row,column,numbers)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct Excel {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl Excel {\n\n fn new(height: i32, width: char) -> Self {\n\n }\n \n fn set(&self, row: i32, column: char, val: i32) {\n\n }\n \n fn get(&self, row: i32, column: char) -> i32 {\n\n }\n \n fn sum(&self, row: i32, column: char, numbers: Vec) -> i32 {\n\n }\n}\n\n/**\n * Your Excel object will be instantiated and called as such:\n * let obj = Excel::new(height, width);\n * obj.set(row, column, val);\n * let ret_2: i32 = obj.get(row, column);\n * let ret_3: i32 = obj.sum(row, column, numbers);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Excel {\n /**\n * @param Integer $height\n * @param String $width\n */\n function __construct($height, $width) {\n\n }\n\n /**\n * @param Integer $row\n * @param String $column\n * @param Integer $val\n * @return NULL\n */\n function set($row, $column, $val) {\n\n }\n\n /**\n * @param Integer $row\n * @param String $column\n * @return Integer\n */\n function get($row, $column) {\n\n }\n\n /**\n * @param Integer $row\n * @param String $column\n * @param String[] $numbers\n * @return Integer\n */\n function sum($row, $column, $numbers) {\n\n }\n}\n\n/**\n * Your Excel object will be instantiated and called as such:\n * $obj = Excel($height, $width);\n * $obj->set($row, $column, $val);\n * $ret_2 = $obj->get($row, $column);\n * $ret_3 = $obj->sum($row, $column, $numbers);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class Excel {\n constructor(height: number, width: string) {\n\n }\n\n set(row: number, column: string, val: number): void {\n\n }\n\n get(row: number, column: string): number {\n\n }\n\n sum(row: number, column: string, numbers: string[]): number {\n\n }\n}\n\n/**\n * Your Excel object will be instantiated and called as such:\n * var obj = new Excel(height, width)\n * obj.set(row,column,val)\n * var param_2 = obj.get(row,column)\n * var param_3 = obj.sum(row,column,numbers)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define excel%\n (class object%\n (super-new)\n\n ; height : exact-integer?\n\n ; width : char?\n (init-field\n height\n width)\n \n ; set : exact-integer? char? exact-integer? -> void?\n (define/public (set row column val)\n\n )\n ; get : exact-integer? char? -> exact-integer?\n (define/public (get row column)\n\n )\n ; sum : exact-integer? char? (listof string?) -> exact-integer?\n (define/public (sum row column numbers)\n\n )))\n\n;; Your excel% object will be instantiated and called as such:\n;; (define obj (new excel% [height height] [width width]))\n;; (send obj set row column val)\n;; (define param_2 (send obj get row column))\n;; (define param_3 (send obj sum row column numbers))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0631](https://leetcode-cn.com/problems/design-excel-sum-formula)", "[\u8bbe\u8ba1 Excel \u6c42\u548c\u516c\u5f0f](/solution/0600-0699/0631.Design%20Excel%20Sum%20Formula/README.md)", "`\u8bbe\u8ba1`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0631](https://leetcode.com/problems/design-excel-sum-formula)", "[Design Excel Sum Formula](/solution/0600-0699/0631.Design%20Excel%20Sum%20Formula/README_EN.md)", "`Design`", "Hard", "\ud83d\udd12"]}, {"question_id": "0630", "frontend_question_id": "0630", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/course-schedule-iii", "url_en": "https://leetcode.com/problems/course-schedule-iii", "relative_path_cn": "/solution/0600-0699/0630.Course%20Schedule%20III/README.md", "relative_path_en": "/solution/0600-0699/0630.Course%20Schedule%20III/README_EN.md", "title_cn": "\u8bfe\u7a0b\u8868 III", "title_en": "Course Schedule III", "question_title_slug": "course-schedule-iii", "content_en": "

    There are n different online courses numbered from 1 to n. You are given an array courses where courses[i] = [durationi, lastDayi] indicate that the ith course should be taken continuously for durationi days and must be finished before or on lastDayi.

    \n\n

    You will start on the 1st day and you cannot take two or more courses simultaneously.

    \n\n

    Return the maximum number of courses that you can take.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: courses = [[100,200],[200,1300],[1000,1250],[2000,3200]]\nOutput: 3\nExplanation: \nThere are totally 4 courses, but you can take 3 courses at most:\nFirst, take the 1st course, it costs 100 days so you will finish it on the 100th day, and ready to take the next course on the 101st day.\nSecond, take the 3rd course, it costs 1000 days so you will finish it on the 1100th day, and ready to take the next course on the 1101st day. \nThird, take the 2nd course, it costs 200 days so you will finish it on the 1300th day. \nThe 4th course cannot be taken now, since you will finish it on the 3300th day, which exceeds the closed date.\n
    \n\n

    Example 2:

    \n\n
    \nInput: courses = [[1,2]]\nOutput: 1\n
    \n\n

    Example 3:

    \n\n
    \nInput: courses = [[3,2],[4,3]]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= courses.length <= 104
    • \n\t
    • 1 <= durationi, lastDayi <= 104
    • \n
    \n", "content_cn": "

    \u8fd9\u91cc\u6709 n \u95e8\u4e0d\u540c\u7684\u5728\u7ebf\u8bfe\u7a0b\uff0c\u4ed6\u4eec\u6309\u4ece 1 \u5230 n \u7f16\u53f7\u3002\u6bcf\u4e00\u95e8\u8bfe\u7a0b\u6709\u4e00\u5b9a\u7684\u6301\u7eed\u4e0a\u8bfe\u65f6\u95f4\uff08\u8bfe\u7a0b\u65f6\u95f4\uff09t \u4ee5\u53ca\u5173\u95ed\u65f6\u95f4\u7b2c d \u5929\u3002\u4e00\u95e8\u8bfe\u8981\u6301\u7eed\u5b66\u4e60 t \u5929\u76f4\u5230\u7b2c d \u5929\u65f6\u8981\u5b8c\u6210\uff0c\u4f60\u5c06\u4f1a\u4ece\u7b2c 1 \u5929\u5f00\u59cb\u3002

    \n\n

    \u7ed9\u51fa n \u4e2a\u5728\u7ebf\u8bfe\u7a0b\u7528 (t, d) \u5bf9\u8868\u793a\u3002\u4f60\u7684\u4efb\u52a1\u662f\u627e\u51fa\u6700\u591a\u53ef\u4ee5\u4fee\u51e0\u95e8\u8bfe\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165: [[100, 200], [200, 1300], [1000, 1250], [2000, 3200]]\n\u8f93\u51fa: 3\n\u89e3\u91ca: \n\u8fd9\u91cc\u4e00\u5171\u6709 4 \u95e8\u8bfe\u7a0b, \u4f46\u662f\u4f60\u6700\u591a\u53ef\u4ee5\u4fee 3 \u95e8:\n\u9996\u5148, \u4fee\u7b2c\u4e00\u95e8\u8bfe\u65f6, \u5b83\u8981\u8017\u8d39 100 \u5929\uff0c\u4f60\u4f1a\u5728\u7b2c 100 \u5929\u5b8c\u6210, \u5728\u7b2c 101 \u5929\u51c6\u5907\u4e0b\u95e8\u8bfe\u3002\n\u7b2c\u4e8c, \u4fee\u7b2c\u4e09\u95e8\u8bfe\u65f6, \u5b83\u4f1a\u8017\u8d39 1000 \u5929\uff0c\u6240\u4ee5\u4f60\u5c06\u5728\u7b2c 1100 \u5929\u7684\u65f6\u5019\u5b8c\u6210\u5b83, \u4ee5\u53ca\u5728\u7b2c 1101 \u5929\u5f00\u59cb\u51c6\u5907\u4e0b\u95e8\u8bfe\u7a0b\u3002\n\u7b2c\u4e09, \u4fee\u7b2c\u4e8c\u95e8\u8bfe\u65f6, \u5b83\u4f1a\u8017\u65f6 200 \u5929\uff0c\u6240\u4ee5\u4f60\u5c06\u4f1a\u5728\u7b2c 1300 \u5929\u65f6\u5b8c\u6210\u5b83\u3002\n\u7b2c\u56db\u95e8\u8bfe\u73b0\u5728\u4e0d\u80fd\u4fee\uff0c\u56e0\u4e3a\u4f60\u5c06\u4f1a\u5728\u7b2c 3300 \u5929\u5b8c\u6210\u5b83\uff0c\u8fd9\u5df2\u7ecf\u8d85\u51fa\u4e86\u5173\u95ed\u65e5\u671f\u3002
    \n\n

     

    \n\n

    \u63d0\u793a:

    \n\n
      \n\t
    1. \u6574\u6570 1 <= d, t, n <= 10,000 \u3002
    2. \n\t
    3. \u4f60\u4e0d\u80fd\u540c\u65f6\u4fee\u4e24\u95e8\u8bfe\u7a0b\u3002
    4. \n
    \n\n

     

    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int scheduleCourse(vector>& courses) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int scheduleCourse(int[][] courses) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def scheduleCourse(self, courses):\n \"\"\"\n :type courses: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def scheduleCourse(self, courses: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint scheduleCourse(int** courses, int coursesSize, int* coursesColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ScheduleCourse(int[][] courses) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} courses\n * @return {number}\n */\nvar scheduleCourse = function(courses) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} courses\n# @return {Integer}\ndef schedule_course(courses)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func scheduleCourse(_ courses: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func scheduleCourse(courses [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def scheduleCourse(courses: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun scheduleCourse(courses: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn schedule_course(courses: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $courses\n * @return Integer\n */\n function scheduleCourse($courses) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function scheduleCourse(courses: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (schedule-course courses)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0630](https://leetcode-cn.com/problems/course-schedule-iii)", "[\u8bfe\u7a0b\u8868 III](/solution/0600-0699/0630.Course%20Schedule%20III/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[0630](https://leetcode.com/problems/course-schedule-iii)", "[Course Schedule III](/solution/0600-0699/0630.Course%20Schedule%20III/README_EN.md)", "`Greedy`", "Hard", ""]}, {"question_id": "0629", "frontend_question_id": "0629", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/k-inverse-pairs-array", "url_en": "https://leetcode.com/problems/k-inverse-pairs-array", "relative_path_cn": "/solution/0600-0699/0629.K%20Inverse%20Pairs%20Array/README.md", "relative_path_en": "/solution/0600-0699/0629.K%20Inverse%20Pairs%20Array/README_EN.md", "title_cn": "K\u4e2a\u9006\u5e8f\u5bf9\u6570\u7ec4", "title_en": "K Inverse Pairs Array", "question_title_slug": "k-inverse-pairs-array", "content_en": "

    For an integer array nums, an inverse pair is a pair of integers [i, j] where 0 <= i < j < nums.length and nums[i] > nums[j].

    \n\n

    Given two integers n and k, return the number of different arrays consist of numbers from 1 to n such that there are exactly k inverse pairs. Since the answer can be huge, return it modulo 109 + 7.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 3, k = 0\nOutput: 1\nExplanation: Only the array [1,2,3] which consists of numbers from 1 to 3 has exactly 0 inverse pairs.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 3, k = 1\nOutput: 2\nExplanation: The array [1,3,2] and [2,1,3] have exactly 1 inverse pair.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 1000
    • \n\t
    • 0 <= k <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u51fa\u4e24\u4e2a\u6574\u6570 n \u548c k\uff0c\u627e\u51fa\u6240\u6709\u5305\u542b\u4ece 1 \u5230 n \u7684\u6570\u5b57\uff0c\u4e14\u6070\u597d\u62e5\u6709 k \u4e2a\u9006\u5e8f\u5bf9\u7684\u4e0d\u540c\u7684\u6570\u7ec4\u7684\u4e2a\u6570\u3002

    \n\n

    \u9006\u5e8f\u5bf9\u7684\u5b9a\u4e49\u5982\u4e0b\uff1a\u5bf9\u4e8e\u6570\u7ec4\u7684\u7b2ci\u4e2a\u548c\u7b2c j\u4e2a\u5143\u7d20\uff0c\u5982\u679c\u6ee1i < j\u4e14 a[i] > a[j]\uff0c\u5219\u5176\u4e3a\u4e00\u4e2a\u9006\u5e8f\u5bf9\uff1b\u5426\u5219\u4e0d\u662f\u3002

    \n\n

    \u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u5f88\u5927\uff0c\u53ea\u9700\u8981\u8fd4\u56de \u7b54\u6848 mod 109 + 7 \u7684\u503c\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: n = 3, k = 0\n\u8f93\u51fa: 1\n\u89e3\u91ca: \n\u53ea\u6709\u6570\u7ec4 [1,2,3] \u5305\u542b\u4e86\u4ece1\u52303\u7684\u6574\u6570\u5e76\u4e14\u6b63\u597d\u62e5\u6709 0 \u4e2a\u9006\u5e8f\u5bf9\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: n = 3, k = 1\n\u8f93\u51fa: 2\n\u89e3\u91ca: \n\u6570\u7ec4 [1,3,2] \u548c [2,1,3] \u90fd\u6709 1 \u4e2a\u9006\u5e8f\u5bf9\u3002\n
    \n\n

    \u8bf4\u660e:

    \n\n
      \n\t
    1.  n \u7684\u8303\u56f4\u662f [1, 1000] \u5e76\u4e14 k \u7684\u8303\u56f4\u662f [0, 1000]\u3002
    2. \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int kInversePairs(int n, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int kInversePairs(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def kInversePairs(self, n, k):\n \"\"\"\n :type n: int\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def kInversePairs(self, n: int, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint kInversePairs(int n, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int KInversePairs(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} k\n * @return {number}\n */\nvar kInversePairs = function(n, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} k\n# @return {Integer}\ndef k_inverse_pairs(n, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func kInversePairs(_ n: Int, _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func kInversePairs(n int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def kInversePairs(n: Int, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun kInversePairs(n: Int, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn k_inverse_pairs(n: i32, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $k\n * @return Integer\n */\n function kInversePairs($n, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function kInversePairs(n: number, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (k-inverse-pairs n k)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0629](https://leetcode-cn.com/problems/k-inverse-pairs-array)", "[K\u4e2a\u9006\u5e8f\u5bf9\u6570\u7ec4](/solution/0600-0699/0629.K%20Inverse%20Pairs%20Array/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0629](https://leetcode.com/problems/k-inverse-pairs-array)", "[K Inverse Pairs Array](/solution/0600-0699/0629.K%20Inverse%20Pairs%20Array/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "0628", "frontend_question_id": "0628", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-product-of-three-numbers", "url_en": "https://leetcode.com/problems/maximum-product-of-three-numbers", "relative_path_cn": "/solution/0600-0699/0628.Maximum%20Product%20of%20Three%20Numbers/README.md", "relative_path_en": "/solution/0600-0699/0628.Maximum%20Product%20of%20Three%20Numbers/README_EN.md", "title_cn": "\u4e09\u4e2a\u6570\u7684\u6700\u5927\u4e58\u79ef", "title_en": "Maximum Product of Three Numbers", "question_title_slug": "maximum-product-of-three-numbers", "content_en": "

    Given an integer array nums, find three numbers whose product is maximum and return the maximum product.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [1,2,3]\nOutput: 6\n

    Example 2:

    \n
    Input: nums = [1,2,3,4]\nOutput: 24\n

    Example 3:

    \n
    Input: nums = [-1,-2,-3]\nOutput: -6\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 3 <= nums.length <= 104
    • \n\t
    • -1000 <= nums[i] <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u578b\u6570\u7ec4 nums \uff0c\u5728\u6570\u7ec4\u4e2d\u627e\u51fa\u7531\u4e09\u4e2a\u6570\u7ec4\u6210\u7684\u6700\u5927\u4e58\u79ef\uff0c\u5e76\u8f93\u51fa\u8fd9\u4e2a\u4e58\u79ef\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,3]\n\u8f93\u51fa\uff1a6\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,3,4]\n\u8f93\u51fa\uff1a24\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [-1,-2,-3]\n\u8f93\u51fa\uff1a-6\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 3 <= nums.length <=\u00a0104
    • \n\t
    • -1000 <= nums[i] <= 1000
    • \n
    \n", "tags_en": ["Array", "Math"], "tags_cn": ["\u6570\u7ec4", "\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maximumProduct(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maximumProduct(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximumProduct(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximumProduct(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maximumProduct(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaximumProduct(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar maximumProduct = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef maximum_product(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximumProduct(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximumProduct(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximumProduct(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximumProduct(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximum_product(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function maximumProduct($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximumProduct(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximum-product nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0628](https://leetcode-cn.com/problems/maximum-product-of-three-numbers)", "[\u4e09\u4e2a\u6570\u7684\u6700\u5927\u4e58\u79ef](/solution/0600-0699/0628.Maximum%20Product%20of%20Three%20Numbers/README.md)", "`\u6570\u7ec4`,`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0628](https://leetcode.com/problems/maximum-product-of-three-numbers)", "[Maximum Product of Three Numbers](/solution/0600-0699/0628.Maximum%20Product%20of%20Three%20Numbers/README_EN.md)", "`Array`,`Math`", "Easy", ""]}, {"question_id": "0627", "frontend_question_id": "0627", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/swap-salary", "url_en": "https://leetcode.com/problems/swap-salary", "relative_path_cn": "/solution/0600-0699/0627.Swap%20Salary/README.md", "relative_path_en": "/solution/0600-0699/0627.Swap%20Salary/README_EN.md", "title_cn": "\u53d8\u66f4\u6027\u522b", "title_en": "Swap Salary", "question_title_slug": "swap-salary", "content_en": "

    Table: Salary

    \n\n
    \n+-------------+----------+\n| Column Name | Type     |\n+-------------+----------+\n| id          | int      |\n| name        | varchar  |\n| sex         | ENUM     |\n| salary      | int      |\n+-------------+----------+\nid is the primary key for this table.\nThe sex column is ENUM value of type ('m', 'f').\nThe table contains information about an employee.\n
    \n\n

     

    \n\n

    Write an SQL query to swap all 'f' and 'm' values (i.e., change all 'f' values to 'm' and vice versa) with a single update statement and no intermediate temp table(s).

    \n\n

    Note that you must write a single update statement, DO NOT write any select statement for this problem.

    \n\n

    The query result format is in the following example:

    \n\n

     

    \n\n
    \nSalary table:\n+----+------+-----+--------+\n| id | name | sex | salary |\n+----+------+-----+--------+\n| 1  | A    | m   | 2500   |\n| 2  | B    | f   | 1500   |\n| 3  | C    | m   | 5500   |\n| 4  | D    | f   | 500    |\n+----+------+-----+--------+\n\nResult table:\n+----+------+-----+--------+\n| id | name | sex | salary |\n+----+------+-----+--------+\n| 1  | A    | f   | 2500   |\n| 2  | B    | m   | 1500   |\n| 3  | C    | f   | 5500   |\n| 4  | D    | m   | 500    |\n+----+------+-----+--------+\n(1, A) and (3, C) were changed from 'm' to 'f'.\n(2, B) and (4, D) were changed from 'f' to 'm'.\n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a salary \u8868\uff0c\u5982\u4e0b\u6240\u793a\uff0c\u6709 m = \u7537\u6027 \u548c f = \u5973\u6027 \u7684\u503c\u3002\u4ea4\u6362\u6240\u6709\u7684 f \u548c m \u503c\uff08\u4f8b\u5982\uff0c\u5c06\u6240\u6709 f \u503c\u66f4\u6539\u4e3a m\uff0c\u53cd\u4e4b\u4ea6\u7136\uff09\u3002\u8981\u6c42\u53ea\u4f7f\u7528\u4e00\u4e2a\u66f4\u65b0\uff08Update\uff09\u8bed\u53e5\uff0c\u5e76\u4e14\u6ca1\u6709\u4e2d\u95f4\u7684\u4e34\u65f6\u8868\u3002

    \n\n

    \u6ce8\u610f\uff0c\u60a8\u5fc5\u53ea\u80fd\u5199\u4e00\u4e2a Update \u8bed\u53e5\uff0c\u8bf7\u4e0d\u8981\u7f16\u5199\u4efb\u4f55 Select \u8bed\u53e5\u3002

    \n\n

    \u4f8b\u5982\uff1a

    \n\n
    | id | name | sex | salary |\n|----|------|-----|--------|\n| 1  | A    | m   | 2500   |\n| 2  | B    | f   | 1500   |\n| 3  | C    | m   | 5500   |\n| 4  | D    | f   | 500    |\n
    \n\n

    \u8fd0\u884c\u4f60\u6240\u7f16\u5199\u7684\u66f4\u65b0\u8bed\u53e5\u4e4b\u540e\uff0c\u5c06\u4f1a\u5f97\u5230\u4ee5\u4e0b\u8868:

    \n\n
    | id | name | sex | salary |\n|----|------|-----|--------|\n| 1  | A    | f   | 2500   |\n| 2  | B    | m   | 1500   |\n| 3  | C    | f   | 5500   |\n| 4  | D    | m   | 500    |\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0627](https://leetcode-cn.com/problems/swap-salary)", "[\u53d8\u66f4\u6027\u522b](/solution/0600-0699/0627.Swap%20Salary/README.md)", "", "\u7b80\u5355", ""], "md_table_row_en": ["[0627](https://leetcode.com/problems/swap-salary)", "[Swap Salary](/solution/0600-0699/0627.Swap%20Salary/README_EN.md)", "", "Easy", ""]}, {"question_id": "0626", "frontend_question_id": "0626", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/exchange-seats", "url_en": "https://leetcode.com/problems/exchange-seats", "relative_path_cn": "/solution/0600-0699/0626.Exchange%20Seats/README.md", "relative_path_en": "/solution/0600-0699/0626.Exchange%20Seats/README_EN.md", "title_cn": "\u6362\u5ea7\u4f4d", "title_en": "Exchange Seats", "question_title_slug": "exchange-seats", "content_en": "

    Mary is a teacher in a middle school and she has a table seat storing students' names and their corresponding seat ids.

    \n\n

    The column id is continuous increment.

    \n\n

    Mary wants to change seats for the adjacent students.

    \n\n

    Can you write a SQL query to output the result for Mary?

    \n\n

     

    \n\n
    \n+---------+---------+\n|    id   | student |\n+---------+---------+\n|    1    | Abbot   |\n|    2    | Doris   |\n|    3    | Emerson |\n|    4    | Green   |\n|    5    | Jeames  |\n+---------+---------+\n
    \n\n

    For the sample input, the output is:

    \n\n
    \n+---------+---------+\n|    id   | student |\n+---------+---------+\n|    1    | Doris   |\n|    2    | Abbot   |\n|    3    | Green   |\n|    4    | Emerson |\n|    5    | Jeames  |\n+---------+---------+\n
    \n\n

    Note:

    \n\n

    If the number of students is odd, there is no need to change the last one's seat.

    \n", "content_cn": "

    \u5c0f\u7f8e\u662f\u4e00\u6240\u4e2d\u5b66\u7684\u4fe1\u606f\u79d1\u6280\u8001\u5e08\uff0c\u5979\u6709\u4e00\u5f20 seat \u5ea7\u4f4d\u8868\uff0c\u5e73\u65f6\u7528\u6765\u50a8\u5b58\u5b66\u751f\u540d\u5b57\u548c\u4e0e\u4ed6\u4eec\u76f8\u5bf9\u5e94\u7684\u5ea7\u4f4d id\u3002

    \n\n

    \u5176\u4e2d\u7eb5\u5217\u7684 id \u662f\u8fde\u7eed\u9012\u589e\u7684

    \n\n

    \u5c0f\u7f8e\u60f3\u6539\u53d8\u76f8\u90bb\u4fe9\u5b66\u751f\u7684\u5ea7\u4f4d\u3002

    \n\n

    \u4f60\u80fd\u4e0d\u80fd\u5e2e\u5979\u5199\u4e00\u4e2a SQL query \u6765\u8f93\u51fa\u5c0f\u7f8e\u60f3\u8981\u7684\u7ed3\u679c\u5462\uff1f

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n+---------+---------+\n|    id   | student |\n+---------+---------+\n|    1    | Abbot   |\n|    2    | Doris   |\n|    3    | Emerson |\n|    4    | Green   |\n|    5    | Jeames  |\n+---------+---------+\n
    \n\n

    \u5047\u5982\u6570\u636e\u8f93\u5165\u7684\u662f\u4e0a\u8868\uff0c\u5219\u8f93\u51fa\u7ed3\u679c\u5982\u4e0b\uff1a

    \n\n
    \n+---------+---------+\n|    id   | student |\n+---------+---------+\n|    1    | Doris   |\n|    2    | Abbot   |\n|    3    | Green   |\n|    4    | Emerson |\n|    5    | Jeames  |\n+---------+---------+
    \n\n

    \u6ce8\u610f\uff1a

    \n\n

    \u5982\u679c\u5b66\u751f\u4eba\u6570\u662f\u5947\u6570\uff0c\u5219\u4e0d\u9700\u8981\u6539\u53d8\u6700\u540e\u4e00\u4e2a\u540c\u5b66\u7684\u5ea7\u4f4d\u3002

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0626](https://leetcode-cn.com/problems/exchange-seats)", "[\u6362\u5ea7\u4f4d](/solution/0600-0699/0626.Exchange%20Seats/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0626](https://leetcode.com/problems/exchange-seats)", "[Exchange Seats](/solution/0600-0699/0626.Exchange%20Seats/README_EN.md)", "", "Medium", ""]}, {"question_id": "0625", "frontend_question_id": "0625", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/minimum-factorization", "url_en": "https://leetcode.com/problems/minimum-factorization", "relative_path_cn": "/solution/0600-0699/0625.Minimum%20Factorization/README.md", "relative_path_en": "/solution/0600-0699/0625.Minimum%20Factorization/README_EN.md", "title_cn": "\u6700\u5c0f\u56e0\u5f0f\u5206\u89e3", "title_en": "Minimum Factorization", "question_title_slug": "minimum-factorization", "content_en": "

    Given a positive integer num, return the smallest positive integer x whose multiplication of each digit equals num. If there is no answer or the answer is not fit in 32-bit signed integer, return 0.

    \n\n

     

    \n

    Example 1:

    \n
    Input: num = 48\nOutput: 68\n

    Example 2:

    \n
    Input: num = 15\nOutput: 35\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= num <= 231 - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6b63\u6574\u6570 a\uff0c\u627e\u51fa\u6700\u5c0f\u7684\u6b63\u6574\u6570 b \u4f7f\u5f97 b \u7684\u6240\u6709\u6570\u4f4d\u76f8\u4e58\u6070\u597d\u7b49\u4e8e a\u3002

    \n\n

    \u5982\u679c\u4e0d\u5b58\u5728\u8fd9\u6837\u7684\u7ed3\u679c\u6216\u8005\u7ed3\u679c\u4e0d\u662f 32 \u4f4d\u6709\u7b26\u53f7\u6574\u6570\uff0c\u8fd4\u56de 0\u3002

    \n\n

     

    \n\n

    \u6837\u4f8b 1

    \n\n

    \u8f93\u5165\uff1a

    \n\n
    48 \n
    \n\n

    \u8f93\u51fa\uff1a

    \n\n
    68
    \n\n

     

    \n\n

    \u6837\u4f8b 2

    \n\n

    \u8f93\u5165\uff1a

    \n\n
    15\n
    \n\n

    \u8f93\u51fa\uff1a

    \n\n
    35
    \n\n

     

    \n", "tags_en": ["Recursion", "Math"], "tags_cn": ["\u9012\u5f52", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int smallestFactorization(int num) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int smallestFactorization(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def smallestFactorization(self, num):\n \"\"\"\n :type num: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def smallestFactorization(self, num: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint smallestFactorization(int num){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SmallestFactorization(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} num\n * @return {number}\n */\nvar smallestFactorization = function(num) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} num\n# @return {Integer}\ndef smallest_factorization(num)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func smallestFactorization(_ num: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func smallestFactorization(num int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def smallestFactorization(num: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun smallestFactorization(num: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn smallest_factorization(num: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $num\n * @return Integer\n */\n function smallestFactorization($num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function smallestFactorization(num: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (smallest-factorization num)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0625](https://leetcode-cn.com/problems/minimum-factorization)", "[\u6700\u5c0f\u56e0\u5f0f\u5206\u89e3](/solution/0600-0699/0625.Minimum%20Factorization/README.md)", "`\u9012\u5f52`,`\u6570\u5b66`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0625](https://leetcode.com/problems/minimum-factorization)", "[Minimum Factorization](/solution/0600-0699/0625.Minimum%20Factorization/README_EN.md)", "`Recursion`,`Math`", "Medium", "\ud83d\udd12"]}, {"question_id": "0624", "frontend_question_id": "0624", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/maximum-distance-in-arrays", "url_en": "https://leetcode.com/problems/maximum-distance-in-arrays", "relative_path_cn": "/solution/0600-0699/0624.Maximum%20Distance%20in%20Arrays/README.md", "relative_path_en": "/solution/0600-0699/0624.Maximum%20Distance%20in%20Arrays/README_EN.md", "title_cn": "\u6570\u7ec4\u5217\u8868\u4e2d\u7684\u6700\u5927\u8ddd\u79bb", "title_en": "Maximum Distance in Arrays", "question_title_slug": "maximum-distance-in-arrays", "content_en": "

    You are given m arrays, where each array is sorted in ascending order.

    \n\n

    You can pick up two integers from two different arrays (each array picks one) and calculate the distance. We define the distance between two integers a and b to be their absolute difference |a - b|.

    \n\n

    Return the maximum distance.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arrays = [[1,2,3],[4,5],[1,2,3]]\nOutput: 4\nExplanation: One way to reach the maximum distance 4 is to pick 1 in the first or third array and pick 5 in the second array.\n
    \n\n

    Example 2:

    \n\n
    \nInput: arrays = [[1],[1]]\nOutput: 0\n
    \n\n

    Example 3:

    \n\n
    \nInput: arrays = [[1],[2]]\nOutput: 1\n
    \n\n

    Example 4:

    \n\n
    \nInput: arrays = [[1,4],[0,5]]\nOutput: 4\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == arrays.length
    • \n\t
    • 2 <= m <= 105
    • \n\t
    • 1 <= arrays[i].length <= 500
    • \n\t
    • -104 <= arrays[i][j] <= 104
    • \n\t
    • arrays[i] is sorted in ascending order.
    • \n\t
    • There will be at most 105 integers in all the arrays.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a m \u4e2a\u6570\u7ec4\uff0c\u6bcf\u4e2a\u6570\u7ec4\u90fd\u5df2\u7ecf\u6309\u7167\u5347\u5e8f\u6392\u597d\u5e8f\u4e86\u3002\u73b0\u5728\u4f60\u9700\u8981\u4ece\u4e24\u4e2a\u4e0d\u540c\u7684\u6570\u7ec4\u4e2d\u9009\u62e9\u4e24\u4e2a\u6574\u6570\uff08\u6bcf\u4e2a\u6570\u7ec4\u9009\u4e00\u4e2a\uff09\u5e76\u4e14\u8ba1\u7b97\u5b83\u4eec\u7684\u8ddd\u79bb\u3002\u4e24\u4e2a\u6574\u6570 a \u548c b \u4e4b\u95f4\u7684\u8ddd\u79bb\u5b9a\u4e49\u4e3a\u5b83\u4eec\u5dee\u7684\u7edd\u5bf9\u503c |a-b| \u3002\u4f60\u7684\u4efb\u52a1\u5c31\u662f\u53bb\u627e\u5230\u6700\u5927\u8ddd\u79bb

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a \n[[1,2,3],\n [4,5],\n [1,2,3]]\n\u8f93\u51fa\uff1a 4\n\u89e3\u91ca\uff1a\n\u4e00\u79cd\u5f97\u5230\u7b54\u6848 4 \u7684\u65b9\u6cd5\u662f\u4ece\u7b2c\u4e00\u4e2a\u6570\u7ec4\u6216\u8005\u7b2c\u4e09\u4e2a\u6570\u7ec4\u4e2d\u9009\u62e9 1\uff0c\u540c\u65f6\u4ece\u7b2c\u4e8c\u4e2a\u6570\u7ec4\u4e2d\u9009\u62e9 5 \u3002\n
    \n\n

     

    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    1. \u6bcf\u4e2a\u7ed9\u5b9a\u6570\u7ec4\u81f3\u5c11\u4f1a\u6709 1 \u4e2a\u6570\u5b57\u3002\u5217\u8868\u4e2d\u81f3\u5c11\u6709\u4e24\u4e2a\u975e\u7a7a\u6570\u7ec4\u3002
    2. \n\t
    3. \u6240\u6709 m \u4e2a\u6570\u7ec4\u4e2d\u7684\u6570\u5b57\u603b\u6570\u76ee\u5728\u8303\u56f4 [2, 10000] \u5185\u3002
    4. \n\t
    5. m \u4e2a\u6570\u7ec4\u4e2d\u6240\u6709\u6574\u6570\u7684\u8303\u56f4\u5728 [-10000, 10000] \u5185\u3002
    6. \n
    \n\n

     

    \n", "tags_en": ["Array", "Hash Table"], "tags_cn": ["\u6570\u7ec4", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxDistance(vector>& arrays) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxDistance(List> arrays) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxDistance(self, arrays):\n \"\"\"\n :type arrays: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxDistance(self, arrays: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxDistance(int** arrays, int arraysSize, int* arraysColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxDistance(IList> arrays) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} arrays\n * @return {number}\n */\nvar maxDistance = function(arrays) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} arrays\n# @return {Integer}\ndef max_distance(arrays)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxDistance(_ arrays: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxDistance(arrays [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxDistance(arrays: List[List[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxDistance(arrays: List>): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_distance(arrays: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $arrays\n * @return Integer\n */\n function maxDistance($arrays) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxDistance(arrays: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-distance arrays)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0624](https://leetcode-cn.com/problems/maximum-distance-in-arrays)", "[\u6570\u7ec4\u5217\u8868\u4e2d\u7684\u6700\u5927\u8ddd\u79bb](/solution/0600-0699/0624.Maximum%20Distance%20in%20Arrays/README.md)", "`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0624](https://leetcode.com/problems/maximum-distance-in-arrays)", "[Maximum Distance in Arrays](/solution/0600-0699/0624.Maximum%20Distance%20in%20Arrays/README_EN.md)", "`Array`,`Hash Table`", "Medium", "\ud83d\udd12"]}, {"question_id": "0623", "frontend_question_id": "0623", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/add-one-row-to-tree", "url_en": "https://leetcode.com/problems/add-one-row-to-tree", "relative_path_cn": "/solution/0600-0699/0623.Add%20One%20Row%20to%20Tree/README.md", "relative_path_en": "/solution/0600-0699/0623.Add%20One%20Row%20to%20Tree/README_EN.md", "title_cn": "\u5728\u4e8c\u53c9\u6811\u4e2d\u589e\u52a0\u4e00\u884c", "title_en": "Add One Row to Tree", "question_title_slug": "add-one-row-to-tree", "content_en": "

    Given the root of a binary tree and two integers val and depth, add a row of nodes with value val at the given depth depth.

    \n\n

    Note that the root node is at depth 1.

    \n\n

    The adding rule is:

    \n\n
      \n\t
    • Given the integer depth, for each not null tree node cur at the depth depth - 1, create two tree nodes with value val as cur's left subtree root and right subtree root.
    • \n\t
    • cur's original left subtree should be the left subtree of the new left subtree root.
    • \n\t
    • cur's original right subtree should be the right subtree of the new right subtree root.
    • \n\t
    • If depth == 1 that means there is no depth depth - 1 at all, then create a tree node with value val as the new root of the whole original tree, and the original tree is the new root's left subtree.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [4,2,6,3,1,5], val = 1, depth = 2\nOutput: [4,1,1,2,null,null,6,3,1,5]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [4,2,null,3,1], val = 1, depth = 3\nOutput: [4,2,null,1,1,3,null,null,1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 104].
    • \n\t
    • The depth of the tree is in the range [1, 104].
    • \n\t
    • -100 <= Node.val <= 100
    • \n\t
    • -105 <= val <= 105
    • \n\t
    • 1 <= depth <= the depth of tree + 1
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811\uff0c\u6839\u8282\u70b9\u4e3a\u7b2c1\u5c42\uff0c\u6df1\u5ea6\u4e3a 1\u3002\u5728\u5176\u7b2c d \u5c42\u8ffd\u52a0\u4e00\u884c\u503c\u4e3a v \u7684\u8282\u70b9\u3002

    \n\n

    \u6dfb\u52a0\u89c4\u5219\uff1a\u7ed9\u5b9a\u4e00\u4e2a\u6df1\u5ea6\u503c d \uff08\u6b63\u6574\u6570\uff09\uff0c\u9488\u5bf9\u6df1\u5ea6\u4e3a d-1 \u5c42\u7684\u6bcf\u4e00\u975e\u7a7a\u8282\u70b9 N\uff0c\u4e3a N \u521b\u5efa\u4e24\u4e2a\u503c\u4e3a v \u7684\u5de6\u5b50\u6811\u548c\u53f3\u5b50\u6811\u3002

    \n\n

    \u5c06 N \u539f\u5148\u7684\u5de6\u5b50\u6811\uff0c\u8fde\u63a5\u4e3a\u65b0\u8282\u70b9 v \u7684\u5de6\u5b50\u6811\uff1b\u5c06 N \u539f\u5148\u7684\u53f3\u5b50\u6811\uff0c\u8fde\u63a5\u4e3a\u65b0\u8282\u70b9 v \u7684\u53f3\u5b50\u6811\u3002

    \n\n

    \u5982\u679c d \u7684\u503c\u4e3a 1\uff0c\u6df1\u5ea6 d - 1 \u4e0d\u5b58\u5728\uff0c\u5219\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6839\u8282\u70b9 v\uff0c\u539f\u5148\u7684\u6574\u68f5\u6811\u5c06\u4f5c\u4e3a v \u7684\u5de6\u5b50\u6811\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: \n\u4e8c\u53c9\u6811\u5982\u4e0b\u6240\u793a:\n       4\n     /   \\\n    2     6\n   / \\   / \n  3   1 5   \n\nv = 1\n\nd = 2\n\n\u8f93\u51fa: \n       4\n      / \\\n     1   1\n    /     \\\n   2       6\n  / \\     / \n 3   1   5   \n\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: \n\u4e8c\u53c9\u6811\u5982\u4e0b\u6240\u793a:\n      4\n     /   \n    2    \n   / \\   \n  3   1    \n\nv = 1\n\nd = 3\n\n\u8f93\u51fa: \n      4\n     /   \n    2\n   / \\    \n  1   1\n /     \\  \n3       1\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u8f93\u5165\u7684\u6df1\u5ea6\u503c d \u7684\u8303\u56f4\u662f\uff1a[1\uff0c\u4e8c\u53c9\u6811\u6700\u5927\u6df1\u5ea6 + 1]\u3002
    2. \n\t
    3. \u8f93\u5165\u7684\u4e8c\u53c9\u6811\u81f3\u5c11\u6709\u4e00\u4e2a\u8282\u70b9\u3002
    4. \n
    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* addOneRow(TreeNode* root, int val, int depth) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode addOneRow(TreeNode root, int val, int depth) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def addOneRow(self, root, val, depth):\n \"\"\"\n :type root: TreeNode\n :type val: int\n :type depth: int\n :rtype: TreeNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def addOneRow(self, root: TreeNode, val: int, depth: int) -> TreeNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* addOneRow(struct TreeNode* root, int val, int depth){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode AddOneRow(TreeNode root, int val, int depth) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number} val\n * @param {number} depth\n * @return {TreeNode}\n */\nvar addOneRow = function(root, val, depth) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @param {Integer} val\n# @param {Integer} depth\n# @return {TreeNode}\ndef add_one_row(root, val, depth)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func addOneRow(_ root: TreeNode?, _ val: Int, _ depth: Int) -> TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc addOneRow(root *TreeNode, val int, depth int) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def addOneRow(root: TreeNode, `val`: Int, depth: Int): TreeNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun addOneRow(root: TreeNode?, `val`: Int, depth: Int): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn add_one_row(root: Option>>, val: i32, depth: i32) -> Option>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param Integer $val\n * @param Integer $depth\n * @return TreeNode\n */\n function addOneRow($root, $val, $depth) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction addOneRow(root: TreeNode | null, val: number, depth: number): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (add-one-row root val depth)\n (-> (or/c tree-node? #f) exact-integer? exact-integer? (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0623](https://leetcode-cn.com/problems/add-one-row-to-tree)", "[\u5728\u4e8c\u53c9\u6811\u4e2d\u589e\u52a0\u4e00\u884c](/solution/0600-0699/0623.Add%20One%20Row%20to%20Tree/README.md)", "`\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0623](https://leetcode.com/problems/add-one-row-to-tree)", "[Add One Row to Tree](/solution/0600-0699/0623.Add%20One%20Row%20to%20Tree/README_EN.md)", "`Tree`", "Medium", ""]}, {"question_id": "0621", "frontend_question_id": "0621", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/task-scheduler", "url_en": "https://leetcode.com/problems/task-scheduler", "relative_path_cn": "/solution/0600-0699/0621.Task%20Scheduler/README.md", "relative_path_en": "/solution/0600-0699/0621.Task%20Scheduler/README_EN.md", "title_cn": "\u4efb\u52a1\u8c03\u5ea6\u5668", "title_en": "Task Scheduler", "question_title_slug": "task-scheduler", "content_en": "

    Given a characters array tasks, representing the tasks a CPU needs to do, where each letter represents a different task. Tasks could be done in any order. Each task is done in one unit of time. For each unit of time, the CPU could complete either one task or just be idle.

    \n\n

    However, there is a non-negative integer n that represents the cooldown period between two same tasks (the same letter in the array), that is that there must be at least n units of time between any two same tasks.

    \n\n

    Return the least number of units of times that the CPU will take to finish all the given tasks.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: tasks = ["A","A","A","B","B","B"], n = 2\nOutput: 8\nExplanation: \nA -> B -> idle -> A -> B -> idle -> A -> B\nThere is at least 2 units of time between any two same tasks.\n
    \n\n

    Example 2:

    \n\n
    \nInput: tasks = ["A","A","A","B","B","B"], n = 0\nOutput: 6\nExplanation: On this case any permutation of size 6 would work since n = 0.\n["A","A","A","B","B","B"]\n["A","B","A","B","A","B"]\n["B","B","B","A","A","A"]\n...\nAnd so on.\n
    \n\n

    Example 3:

    \n\n
    \nInput: tasks = ["A","A","A","A","A","A","B","C","D","E","F","G"], n = 2\nOutput: 16\nExplanation: \nOne possible solution is\nA -> B -> C -> A -> D -> E -> A -> F -> G -> A -> idle -> idle -> A -> idle -> idle -> A\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= task.length <= 104
    • \n\t
    • tasks[i] is upper-case English letter.
    • \n\t
    • The integer n is in the range [0, 100].
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u7528\u5b57\u7b26\u6570\u7ec4\u00a0tasks \u8868\u793a\u7684 CPU \u9700\u8981\u6267\u884c\u7684\u4efb\u52a1\u5217\u8868\u3002\u5176\u4e2d\u6bcf\u4e2a\u5b57\u6bcd\u8868\u793a\u4e00\u79cd\u4e0d\u540c\u79cd\u7c7b\u7684\u4efb\u52a1\u3002\u4efb\u52a1\u53ef\u4ee5\u4ee5\u4efb\u610f\u987a\u5e8f\u6267\u884c\uff0c\u5e76\u4e14\u6bcf\u4e2a\u4efb\u52a1\u90fd\u53ef\u4ee5\u5728 1 \u4e2a\u5355\u4f4d\u65f6\u95f4\u5185\u6267\u884c\u5b8c\u3002\u5728\u4efb\u4f55\u4e00\u4e2a\u5355\u4f4d\u65f6\u95f4\uff0cCPU \u53ef\u4ee5\u5b8c\u6210\u4e00\u4e2a\u4efb\u52a1\uff0c\u6216\u8005\u5904\u4e8e\u5f85\u547d\u72b6\u6001\u3002

    \n\n

    \u7136\u800c\uff0c\u4e24\u4e2a \u76f8\u540c\u79cd\u7c7b \u7684\u4efb\u52a1\u4e4b\u95f4\u5fc5\u987b\u6709\u957f\u5ea6\u4e3a\u6574\u6570 n \u7684\u51b7\u5374\u65f6\u95f4\uff0c\u56e0\u6b64\u81f3\u5c11\u6709\u8fde\u7eed n \u4e2a\u5355\u4f4d\u65f6\u95f4\u5185 CPU \u5728\u6267\u884c\u4e0d\u540c\u7684\u4efb\u52a1\uff0c\u6216\u8005\u5728\u5f85\u547d\u72b6\u6001\u3002

    \n\n

    \u4f60\u9700\u8981\u8ba1\u7b97\u5b8c\u6210\u6240\u6709\u4efb\u52a1\u6240\u9700\u8981\u7684 \u6700\u77ed\u65f6\u95f4 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1atasks = [\"A\",\"A\",\"A\",\"B\",\"B\",\"B\"], n = 2\n\u8f93\u51fa\uff1a8\n\u89e3\u91ca\uff1aA -> B -> (\u5f85\u547d) -> A -> B -> (\u5f85\u547d) -> A -> B\n     \u5728\u672c\u793a\u4f8b\u4e2d\uff0c\u4e24\u4e2a\u76f8\u540c\u7c7b\u578b\u4efb\u52a1\u4e4b\u95f4\u5fc5\u987b\u95f4\u9694\u957f\u5ea6\u4e3a n = 2 \u7684\u51b7\u5374\u65f6\u95f4\uff0c\u800c\u6267\u884c\u4e00\u4e2a\u4efb\u52a1\u53ea\u9700\u8981\u4e00\u4e2a\u5355\u4f4d\u65f6\u95f4\uff0c\u6240\u4ee5\u4e2d\u95f4\u51fa\u73b0\u4e86\uff08\u5f85\u547d\uff09\u72b6\u6001\u3002 
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1atasks = [\"A\",\"A\",\"A\",\"B\",\"B\",\"B\"], n = 0\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u4efb\u4f55\u5927\u5c0f\u4e3a 6 \u7684\u6392\u5217\u90fd\u53ef\u4ee5\u6ee1\u8db3\u8981\u6c42\uff0c\u56e0\u4e3a n = 0\n[\"A\",\"A\",\"A\",\"B\",\"B\",\"B\"]\n[\"A\",\"B\",\"A\",\"B\",\"A\",\"B\"]\n[\"B\",\"B\",\"B\",\"A\",\"A\",\"A\"]\n...\n\u8bf8\u5982\u6b64\u7c7b\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1atasks = [\"A\",\"A\",\"A\",\"A\",\"A\",\"A\",\"B\",\"C\",\"D\",\"E\",\"F\",\"G\"], n = 2\n\u8f93\u51fa\uff1a16\n\u89e3\u91ca\uff1a\u4e00\u79cd\u53ef\u80fd\u7684\u89e3\u51b3\u65b9\u6848\u662f\uff1a\n     A -> B -> C -> A -> D -> E -> A -> F -> G -> A -> (\u5f85\u547d) -> (\u5f85\u547d) -> A -> (\u5f85\u547d) -> (\u5f85\u547d) -> A\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= task.length <= 104
    • \n\t
    • tasks[i] \u662f\u5927\u5199\u82f1\u6587\u5b57\u6bcd
    • \n\t
    • n \u7684\u53d6\u503c\u8303\u56f4\u4e3a [0, 100]
    • \n
    \n", "tags_en": ["Greedy", "Queue", "Array"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u961f\u5217", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int leastInterval(vector& tasks, int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int leastInterval(char[] tasks, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def leastInterval(self, tasks, n):\n \"\"\"\n :type tasks: List[str]\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def leastInterval(self, tasks: List[str], n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint leastInterval(char* tasks, int tasksSize, int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LeastInterval(char[] tasks, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {character[]} tasks\n * @param {number} n\n * @return {number}\n */\nvar leastInterval = function(tasks, n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Character[]} tasks\n# @param {Integer} n\n# @return {Integer}\ndef least_interval(tasks, n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func leastInterval(_ tasks: [Character], _ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func leastInterval(tasks []byte, n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def leastInterval(tasks: Array[Char], n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun leastInterval(tasks: CharArray, n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn least_interval(tasks: Vec, n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $tasks\n * @param Integer $n\n * @return Integer\n */\n function leastInterval($tasks, $n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function leastInterval(tasks: string[], n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (least-interval tasks n)\n (-> (listof char?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0621](https://leetcode-cn.com/problems/task-scheduler)", "[\u4efb\u52a1\u8c03\u5ea6\u5668](/solution/0600-0699/0621.Task%20Scheduler/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u961f\u5217`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0621](https://leetcode.com/problems/task-scheduler)", "[Task Scheduler](/solution/0600-0699/0621.Task%20Scheduler/README_EN.md)", "`Greedy`,`Queue`,`Array`", "Medium", ""]}, {"question_id": "0620", "frontend_question_id": "0620", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/not-boring-movies", "url_en": "https://leetcode.com/problems/not-boring-movies", "relative_path_cn": "/solution/0600-0699/0620.Not%20Boring%20Movies/README.md", "relative_path_en": "/solution/0600-0699/0620.Not%20Boring%20Movies/README_EN.md", "title_cn": "\u6709\u8da3\u7684\u7535\u5f71", "title_en": "Not Boring Movies", "question_title_slug": "not-boring-movies", "content_en": "

    Table: Cinema

    \n\n
    \n+----------------+----------+\n| Column Name    | Type     |\n+----------------+----------+\n| id             | int      |\n| movie          | varchar  |\n| description    | varchar  |\n| rating         | float    |\n+----------------+----------+\nid is the primary key for this table.\nEach row contains information about the name of a movie, its genre, and its rating.\nrating is a 2 decimal places float in the range [0, 10]\n
    \n\n

     

    \n\n

    Write an SQL query to report the movies with an odd-numbered ID and a description that is not "boring".

    \n\n

    Return the result table in descending order by rating.

    \n\n

    The query result format is in the following example:

    \n\n

     

    \n\n
    \nCinema table:\n+----+------------+-------------+--------+\n| id | movie      | description | rating |\n+----+------------+-------------+--------+\n| 1  | War        | great 3D    | 8.9    |\n| 2  | Science    | fiction     | 8.5    |\n| 3  | irish      | boring      | 6.2    |\n| 4  | Ice song   | Fantacy     | 8.6    |\n| 5  | House card | Interesting | 9.1    |\n+----+------------+-------------+--------+\n\nResult table:\n+----+------------+-------------+--------+\n| id | movie      | description | rating |\n+----+------------+-------------+--------+\n| 5  | House card | Interesting | 9.1    |\n| 1  | War        | great 3D    | 8.9    |\n+----+------------+-------------+--------+\n\nWe have three movies with odd-numbered ID: 1, 3, and 5. The movie with ID = 3 is boring so we don't include it in the answer.
    \n", "content_cn": "

    \u67d0\u57ce\u5e02\u5f00\u4e86\u4e00\u5bb6\u65b0\u7684\u7535\u5f71\u9662\uff0c\u5438\u5f15\u4e86\u5f88\u591a\u4eba\u8fc7\u6765\u770b\u7535\u5f71\u3002\u8be5\u7535\u5f71\u9662\u7279\u522b\u6ce8\u610f\u7528\u6237\u4f53\u9a8c\uff0c\u4e13\u95e8\u6709\u4e2a LED\u663e\u793a\u677f\u505a\u7535\u5f71\u63a8\u8350\uff0c\u4e0a\u9762\u516c\u5e03\u7740\u5f71\u8bc4\u548c\u76f8\u5173\u7535\u5f71\u63cf\u8ff0\u3002

    \n\n

    \u4f5c\u4e3a\u8be5\u7535\u5f71\u9662\u7684\u4fe1\u606f\u90e8\u4e3b\u7ba1\uff0c\u60a8\u9700\u8981\u7f16\u5199\u4e00\u4e2a SQL\u67e5\u8be2\uff0c\u627e\u51fa\u6240\u6709\u5f71\u7247\u63cf\u8ff0\u4e3a\u975e boring (\u4e0d\u65e0\u804a) \u7684\u5e76\u4e14 id \u4e3a\u5947\u6570 \u7684\u5f71\u7247\uff0c\u7ed3\u679c\u8bf7\u6309\u7b49\u7ea7 rating \u6392\u5217\u3002

    \n\n

     

    \n\n

    \u4f8b\u5982\uff0c\u4e0b\u8868 cinema:

    \n\n
    \n+---------+-----------+--------------+-----------+\n|   id    | movie     |  description |  rating   |\n+---------+-----------+--------------+-----------+\n|   1     | War       |   great 3D   |   8.9     |\n|   2     | Science   |   fiction    |   8.5     |\n|   3     | irish     |   boring     |   6.2     |\n|   4     | Ice song  |   Fantacy    |   8.6     |\n|   5     | House card|   Interesting|   9.1     |\n+---------+-----------+--------------+-----------+\n
    \n\n

    \u5bf9\u4e8e\u4e0a\u9762\u7684\u4f8b\u5b50\uff0c\u5219\u6b63\u786e\u7684\u8f93\u51fa\u662f\u4e3a\uff1a

    \n\n
    \n+---------+-----------+--------------+-----------+\n|   id    | movie     |  description |  rating   |\n+---------+-----------+--------------+-----------+\n|   5     | House card|   Interesting|   9.1     |\n|   1     | War       |   great 3D   |   8.9     |\n+---------+-----------+--------------+-----------+\n
    \n\n

     

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0620](https://leetcode-cn.com/problems/not-boring-movies)", "[\u6709\u8da3\u7684\u7535\u5f71](/solution/0600-0699/0620.Not%20Boring%20Movies/README.md)", "", "\u7b80\u5355", ""], "md_table_row_en": ["[0620](https://leetcode.com/problems/not-boring-movies)", "[Not Boring Movies](/solution/0600-0699/0620.Not%20Boring%20Movies/README_EN.md)", "", "Easy", ""]}, {"question_id": "0619", "frontend_question_id": "0619", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/biggest-single-number", "url_en": "https://leetcode.com/problems/biggest-single-number", "relative_path_cn": "/solution/0600-0699/0619.Biggest%20Single%20Number/README.md", "relative_path_en": "/solution/0600-0699/0619.Biggest%20Single%20Number/README_EN.md", "title_cn": "\u53ea\u51fa\u73b0\u4e00\u6b21\u7684\u6700\u5927\u6570\u5b57", "title_en": "Biggest Single Number", "question_title_slug": "biggest-single-number", "content_en": "

    Table my_numbers contains many numbers in column num including duplicated ones.
    \r\nCan you write a SQL query to find the biggest number, which only appears once.

    \r\n\r\n
    \r\n+---+\r\n|num|\r\n+---+\r\n| 8 |\r\n| 8 |\r\n| 3 |\r\n| 3 |\r\n| 1 |\r\n| 4 |\r\n| 5 |\r\n| 6 | \r\n
    \r\nFor the sample data above, your query should return the following result:\r\n\r\n
    \r\n+---+\r\n|num|\r\n+---+\r\n| 6 |\r\n
    \r\nNote:
    \r\nIf there is no such number, just output null.\r\n\r\n

     

    \r\n", "content_cn": "

    \u8868 my_numbers \u7684 num \u5b57\u6bb5\u5305\u542b\u5f88\u591a\u6570\u5b57\uff0c\u5176\u4e2d\u5305\u62ec\u5f88\u591a\u91cd\u590d\u7684\u6570\u5b57\u3002

    \n\n

    \u4f60\u80fd\u5199\u4e00\u4e2a SQL \u67e5\u8be2\u8bed\u53e5\uff0c\u627e\u5230\u53ea\u51fa\u73b0\u8fc7\u4e00\u6b21\u7684\u6570\u5b57\u4e2d\uff0c\u6700\u5927\u7684\u4e00\u4e2a\u6570\u5b57\u5417\uff1f

    \n\n
    +---+\n|num|\n+---+\n| 8 |\n| 8 |\n| 3 |\n| 3 |\n| 1 |\n| 4 |\n| 5 |\n| 6 | \n
    \n\n

    \u5bf9\u4e8e\u4e0a\u9762\u7ed9\u51fa\u7684\u6837\u4f8b\u6570\u636e\uff0c\u4f60\u7684\u67e5\u8be2\u8bed\u53e5\u5e94\u8be5\u8fd4\u56de\u5982\u4e0b\u7ed3\u679c\uff1a

    \n\n
    +---+\n|num|\n+---+\n| 6 |\n
    \n\n

    \u6ce8\u610f\uff1a

    \n\n

    \u5982\u679c\u6ca1\u6709\u53ea\u51fa\u73b0\u4e00\u6b21\u7684\u6570\u5b57\uff0c\u8f93\u51fa null \u3002

    \n\n

     

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0619](https://leetcode-cn.com/problems/biggest-single-number)", "[\u53ea\u51fa\u73b0\u4e00\u6b21\u7684\u6700\u5927\u6570\u5b57](/solution/0600-0699/0619.Biggest%20Single%20Number/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0619](https://leetcode.com/problems/biggest-single-number)", "[Biggest Single Number](/solution/0600-0699/0619.Biggest%20Single%20Number/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "0618", "frontend_question_id": "0618", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/students-report-by-geography", "url_en": "https://leetcode.com/problems/students-report-by-geography", "relative_path_cn": "/solution/0600-0699/0618.Students%20Report%20By%20Geography/README.md", "relative_path_en": "/solution/0600-0699/0618.Students%20Report%20By%20Geography/README_EN.md", "title_cn": "\u5b66\u751f\u5730\u7406\u4fe1\u606f\u62a5\u544a", "title_en": "Students Report By Geography", "question_title_slug": "students-report-by-geography", "content_en": "A U.S graduate school has students from Asia, Europe and America. The students' location information are stored in table student as below.\r\n

     

    \r\n\r\n
    \r\n| name   | continent |\r\n|--------|-----------|\r\n| Jack   | America   |\r\n| Pascal | Europe    |\r\n| Xi     | Asia      |\r\n| Jane   | America   |\r\n
    \r\n\r\n

     

    \r\n Pivot the continent column in this table so that each name is sorted alphabetically and displayed underneath its corresponding continent. The output headers should be America, Asia and Europe respectively. It is guaranteed that the student number from America is no less than either Asia or Europe.\r\n\r\n

     

    \r\nFor the sample input, the output is:\r\n\r\n

     

    \r\n\r\n
    \r\n| America | Asia | Europe |\r\n|---------|------|--------|\r\n| Jack    | Xi   | Pascal |\r\n| Jane    |      |        |\r\n
    \r\n\r\n

     

    \r\nFollow-up: If it is unknown which continent has the most students, can you write a query to generate the student report?\r\n\r\n

     

    \r\n", "content_cn": "

    \u4e00\u6240\u7f8e\u56fd\u5927\u5b66\u6709\u6765\u81ea\u4e9a\u6d32\u3001\u6b27\u6d32\u548c\u7f8e\u6d32\u7684\u5b66\u751f\uff0c\u4ed6\u4eec\u7684\u5730\u7406\u4fe1\u606f\u5b58\u653e\u5728\u5982\u4e0b\u00a0student \u8868\u4e2d\u3002

    \n\n

    \u00a0

    \n\n
    \n| name   | continent |\n|--------|-----------|\n| Jack   | America   |\n| Pascal | Europe    |\n| Xi     | Asia      |\n| Jane   | America   |\n
    \n\n

    \u00a0

    \n\n

    \u5199\u4e00\u4e2a\u67e5\u8be2\u8bed\u53e5\u5b9e\u73b0\u5bf9\u5927\u6d32\uff08continent\uff09\u5217\u7684\u00a0\u900f\u89c6\u8868 \u64cd\u4f5c\uff0c\u4f7f\u5f97\u6bcf\u4e2a\u5b66\u751f\u6309\u7167\u59d3\u540d\u7684\u5b57\u6bcd\u987a\u5e8f\u4f9d\u6b21\u6392\u5217\u5728\u5bf9\u5e94\u7684\u5927\u6d32\u4e0b\u9762\u3002\u8f93\u51fa\u7684\u6807\u9898\u5e94\u4f9d\u6b21\u4e3a\u7f8e\u6d32\uff08America\uff09\u3001\u4e9a\u6d32\uff08Asia\uff09\u548c\u6b27\u6d32\uff08Europe\uff09\u3002

    \n\n

    \u00a0

    \n\n

    \u5bf9\u4e8e\u6837\u4f8b\u8f93\u5165\uff0c\u5b83\u7684\u5bf9\u5e94\u8f93\u51fa\u662f\uff1a

    \n\n

    \u00a0

    \n\n
    \n| America | Asia | Europe |\n|---------|------|--------|\n| Jack    | Xi   | Pascal |\n| Jane    |      |        |\n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u5982\u679c\u4e0d\u80fd\u786e\u5b9a\u54ea\u4e2a\u5927\u6d32\u7684\u5b66\u751f\u6570\u6700\u591a\uff0c\u4f60\u53ef\u4ee5\u5199\u51fa\u4e00\u4e2a\u67e5\u8be2\u53bb\u751f\u6210\u4e0a\u8ff0\u5b66\u751f\u62a5\u544a\u5417\uff1f

    \n\n

    \u00a0

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0618](https://leetcode-cn.com/problems/students-report-by-geography)", "[\u5b66\u751f\u5730\u7406\u4fe1\u606f\u62a5\u544a](/solution/0600-0699/0618.Students%20Report%20By%20Geography/README.md)", "", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0618](https://leetcode.com/problems/students-report-by-geography)", "[Students Report By Geography](/solution/0600-0699/0618.Students%20Report%20By%20Geography/README_EN.md)", "", "Hard", "\ud83d\udd12"]}, {"question_id": "0617", "frontend_question_id": "0617", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/merge-two-binary-trees", "url_en": "https://leetcode.com/problems/merge-two-binary-trees", "relative_path_cn": "/solution/0600-0699/0617.Merge%20Two%20Binary%20Trees/README.md", "relative_path_en": "/solution/0600-0699/0617.Merge%20Two%20Binary%20Trees/README_EN.md", "title_cn": "\u5408\u5e76\u4e8c\u53c9\u6811", "title_en": "Merge Two Binary Trees", "question_title_slug": "merge-two-binary-trees", "content_en": "

    You are given two binary trees root1 and root2.

    \n\n

    Imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not. You need to merge the two trees into a new binary tree. The merge rule is that if two nodes overlap, then sum node values up as the new value of the merged node. Otherwise, the NOT null node will be used as the node of the new tree.

    \n\n

    Return the merged tree.

    \n\n

    Note: The merging process must start from the root nodes of both trees.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root1 = [1,3,2,5], root2 = [2,1,3,null,4,null,7]\nOutput: [3,4,5,5,4,null,7]\n
    \n\n

    Example 2:

    \n\n
    \nInput: root1 = [1], root2 = [1,2]\nOutput: [2,2]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in both trees is in the range [0, 2000].
    • \n\t
    • -104 <= Node.val <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u4e8c\u53c9\u6811\uff0c\u60f3\u8c61\u5f53\u4f60\u5c06\u5b83\u4eec\u4e2d\u7684\u4e00\u4e2a\u8986\u76d6\u5230\u53e6\u4e00\u4e2a\u4e0a\u65f6\uff0c\u4e24\u4e2a\u4e8c\u53c9\u6811\u7684\u4e00\u4e9b\u8282\u70b9\u4fbf\u4f1a\u91cd\u53e0\u3002

    \n\n

    \u4f60\u9700\u8981\u5c06\u4ed6\u4eec\u5408\u5e76\u4e3a\u4e00\u4e2a\u65b0\u7684\u4e8c\u53c9\u6811\u3002\u5408\u5e76\u7684\u89c4\u5219\u662f\u5982\u679c\u4e24\u4e2a\u8282\u70b9\u91cd\u53e0\uff0c\u90a3\u4e48\u5c06\u4ed6\u4eec\u7684\u503c\u76f8\u52a0\u4f5c\u4e3a\u8282\u70b9\u5408\u5e76\u540e\u7684\u65b0\u503c\uff0c\u5426\u5219\u4e0d\u4e3a NULL \u7684\u8282\u70b9\u5c06\u76f4\u63a5\u4f5c\u4e3a\u65b0\u4e8c\u53c9\u6811\u7684\u8282\u70b9\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: \n\tTree 1                     Tree 2                  \n          1                         2                             \n         / \\                       / \\                            \n        3   2                     1   3                        \n       /                           \\   \\                      \n      5                             4   7                  \n\u8f93\u51fa: \n\u5408\u5e76\u540e\u7684\u6811:\n\t     3\n\t    / \\\n\t   4   5\n\t  / \\   \\ \n\t 5   4   7\n
    \n\n

    \u6ce8\u610f: \u5408\u5e76\u5fc5\u987b\u4ece\u4e24\u4e2a\u6811\u7684\u6839\u8282\u70b9\u5f00\u59cb\u3002

    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* mergeTrees(TreeNode* root1, TreeNode* root2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode mergeTrees(TreeNode root1, TreeNode root2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def mergeTrees(self, root1, root2):\n \"\"\"\n :type root1: TreeNode\n :type root2: TreeNode\n :rtype: TreeNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def mergeTrees(self, root1: TreeNode, root2: TreeNode) -> TreeNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* mergeTrees(struct TreeNode* root1, struct TreeNode* root2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode MergeTrees(TreeNode root1, TreeNode root2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root1\n * @param {TreeNode} root2\n * @return {TreeNode}\n */\nvar mergeTrees = function(root1, root2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root1\n# @param {TreeNode} root2\n# @return {TreeNode}\ndef merge_trees(root1, root2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func mergeTrees(_ root1: TreeNode?, _ root2: TreeNode?) -> TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc mergeTrees(root1 *TreeNode, root2 *TreeNode) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def mergeTrees(root1: TreeNode, root2: TreeNode): TreeNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun mergeTrees(root1: TreeNode?, root2: TreeNode?): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn merge_trees(root1: Option>>, root2: Option>>) -> Option>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root1\n * @param TreeNode $root2\n * @return TreeNode\n */\n function mergeTrees($root1, $root2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction mergeTrees(root1: TreeNode | null, root2: TreeNode | null): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (merge-trees root1 root2)\n (-> (or/c tree-node? #f) (or/c tree-node? #f) (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0617](https://leetcode-cn.com/problems/merge-two-binary-trees)", "[\u5408\u5e76\u4e8c\u53c9\u6811](/solution/0600-0699/0617.Merge%20Two%20Binary%20Trees/README.md)", "`\u6811`", "\u7b80\u5355", ""], "md_table_row_en": ["[0617](https://leetcode.com/problems/merge-two-binary-trees)", "[Merge Two Binary Trees](/solution/0600-0699/0617.Merge%20Two%20Binary%20Trees/README_EN.md)", "`Tree`", "Easy", ""]}, {"question_id": "0616", "frontend_question_id": "0616", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/add-bold-tag-in-string", "url_en": "https://leetcode.com/problems/add-bold-tag-in-string", "relative_path_cn": "/solution/0600-0699/0616.Add%20Bold%20Tag%20in%20String/README.md", "relative_path_en": "/solution/0600-0699/0616.Add%20Bold%20Tag%20in%20String/README_EN.md", "title_cn": "\u7ed9\u5b57\u7b26\u4e32\u6dfb\u52a0\u52a0\u7c97\u6807\u7b7e", "title_en": "Add Bold Tag in String", "question_title_slug": "add-bold-tag-in-string", "content_en": "

    You are given a string s and an array of strings words. You should add a closed pair of bold tag <b> and </b> to wrap the substrings in s that exist in words. If two such substrings overlap, you should wrap them together with only one pair of closed bold-tag. If two substrings wrapped by bold tags are consecutive, you should combine them.

    \n\n

    Return s after adding the bold tags.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "abcxyz123", words = ["abc","123"]\nOutput: "<b>abc</b>xyz<b>123</b>"\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "aaabbcc", words = ["aaa","aab","bc"]\nOutput: "<b>aaabbc</b>c"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 1000
    • \n\t
    • 0 <= words.length <= 100
    • \n\t
    • 1 <= words[i].length <= 1000
    • \n\t
    • s and words[i] consist of English letters and digits.
    • \n\t
    • All the values of words are unique.
    • \n
    \n\n

     

    \n

    Note: This question is the same as 758: https://leetcode.com/problems/bold-words-in-string/

    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32\u00a0s\u00a0\u548c\u4e00\u4e2a\u5b57\u7b26\u4e32\u5217\u8868\u00a0dict\u00a0\uff0c\u4f60\u9700\u8981\u5c06\u5728\u5b57\u7b26\u4e32\u5217\u8868\u4e2d\u51fa\u73b0\u8fc7\u7684 s \u7684\u5b50\u4e32\u6dfb\u52a0\u52a0\u7c97\u95ed\u5408\u6807\u7b7e\u00a0\u00a0\u548c\u00a0\u00a0\u3002

    \n\n

    \u5982\u679c\u4e24\u4e2a\u5b50\u4e32\u6709\u91cd\u53e0\u90e8\u5206\uff0c\u4f60\u9700\u8981\u628a\u5b83\u4eec\u4e00\u8d77\u7528\u4e00\u4e2a\u95ed\u5408\u6807\u7b7e\u5305\u56f4\u8d77\u6765\u3002\u540c\u7406\uff0c\u5982\u679c\u4e24\u4e2a\u5b50\u5b57\u7b26\u4e32\u8fde\u7eed\u88ab\u52a0\u7c97\uff0c\u90a3\u4e48\u4f60\u4e5f\u9700\u8981\u628a\u5b83\u4eec\u5408\u8d77\u6765\u7528\u4e00\u4e2a\u52a0\u7c97\u6807\u7b7e\u5305\u56f4\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\ns = \"abcxyz123\"\ndict = [\"abc\",\"123\"]\n\u8f93\u51fa\uff1a\n\"abcxyz123\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\ns = \"aaabbcc\"\ndict = [\"aaa\",\"aab\",\"bc\"]\n\u8f93\u51fa\uff1a\n\"aaabbcc\"\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u7ed9\u5b9a\u7684 dict \u4e2d\u4e0d\u4f1a\u6709\u91cd\u590d\u7684\u5b57\u7b26\u4e32\uff0c\u4e14\u5b57\u7b26\u4e32\u6570\u76ee\u4e0d\u4f1a\u8d85\u8fc7 100 \u3002
    • \n\t
    • \u8f93\u5165\u4e2d\u7684\u6240\u6709\u5b57\u7b26\u4e32\u957f\u5ea6\u90fd\u5728\u8303\u56f4 [1,1000] \u5185\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u6ce8\uff1a\u6b64\u9898\u4e0e\u300c758 - \u5b57\u7b26\u4e32\u4e2d\u7684\u52a0\u7c97\u5355\u8bcd\u300d\u76f8\u540c - https://leetcode-cn.com/problems/bold-words-in-string

    \n\n

    \u00a0

    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string addBoldTag(string s, vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String addBoldTag(String s, String[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def addBoldTag(self, s, words):\n \"\"\"\n :type s: str\n :type words: List[str]\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def addBoldTag(self, s: str, words: List[str]) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * addBoldTag(char * s, char ** words, int wordsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string AddBoldTag(string s, string[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string[]} words\n * @return {string}\n */\nvar addBoldTag = function(s, words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String[]} words\n# @return {String}\ndef add_bold_tag(s, words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func addBoldTag(_ s: String, _ words: [String]) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func addBoldTag(s string, words []string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def addBoldTag(s: String, words: Array[String]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun addBoldTag(s: String, words: Array): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn add_bold_tag(s: String, words: Vec) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String[] $words\n * @return String\n */\n function addBoldTag($s, $words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function addBoldTag(s: string, words: string[]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (add-bold-tag s words)\n (-> string? (listof string?) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0616](https://leetcode-cn.com/problems/add-bold-tag-in-string)", "[\u7ed9\u5b57\u7b26\u4e32\u6dfb\u52a0\u52a0\u7c97\u6807\u7b7e](/solution/0600-0699/0616.Add%20Bold%20Tag%20in%20String/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0616](https://leetcode.com/problems/add-bold-tag-in-string)", "[Add Bold Tag in String](/solution/0600-0699/0616.Add%20Bold%20Tag%20in%20String/README_EN.md)", "`String`", "Medium", "\ud83d\udd12"]}, {"question_id": "0615", "frontend_question_id": "0615", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/average-salary-departments-vs-company", "url_en": "https://leetcode.com/problems/average-salary-departments-vs-company", "relative_path_cn": "/solution/0600-0699/0615.Average%20Salary%20Departments%20VS%20Company/README.md", "relative_path_en": "/solution/0600-0699/0615.Average%20Salary%20Departments%20VS%20Company/README_EN.md", "title_cn": "\u5e73\u5747\u5de5\u8d44\uff1a\u90e8\u95e8\u4e0e\u516c\u53f8\u6bd4\u8f83", "title_en": "Average Salary Departments VS Company", "question_title_slug": "average-salary-departments-vs-company", "content_en": "Given two tables as below, write a query to display the comparison result (higher/lower/same) of the average salary of employees in a department to the company's average salary.\r\n

     

    \r\nTable: salary\r\n\r\n
    \r\n| id | employee_id | amount | pay_date   |\r\n|----|-------------|--------|------------|\r\n| 1  | 1           | 9000   | 2017-03-31 |\r\n| 2  | 2           | 6000   | 2017-03-31 |\r\n| 3  | 3           | 10000  | 2017-03-31 |\r\n| 4  | 1           | 7000   | 2017-02-28 |\r\n| 5  | 2           | 6000   | 2017-02-28 |\r\n| 6  | 3           | 8000   | 2017-02-28 |\r\n
    \r\n\r\n

     

    \r\nThe employee_id column refers to the employee_id in the following table employee.\r\n\r\n

     

    \r\n\r\n
    \r\n| employee_id | department_id |\r\n|-------------|---------------|\r\n| 1           | 1             |\r\n| 2           | 2             |\r\n| 3           | 2             |\r\n
    \r\n\r\n

     

    \r\nSo for the sample data above, the result is:\r\n\r\n

     

    \r\n\r\n
    \r\n| pay_month | department_id | comparison  |\r\n|-----------|---------------|-------------|\r\n| 2017-03   | 1             | higher      |\r\n| 2017-03   | 2             | lower       |\r\n| 2017-02   | 1             | same        |\r\n| 2017-02   | 2             | same        |\r\n
    \r\n\r\n

     

    \r\nExplanation\r\n\r\n

     

    \r\nIn March, the company's average salary is (9000+6000+10000)/3 = 8333.33...\r\n\r\n

     

    \r\nThe average salary for department '1' is 9000, which is the salary of employee_id '1' since there is only one employee in this department. So the comparison result is 'higher' since 9000 > 8333.33 obviously.\r\n\r\n

     

    \r\nThe average salary of department '2' is (6000 + 10000)/2 = 8000, which is the average of employee_id '2' and '3'. So the comparison result is 'lower' since 8000 < 8333.33.\r\n\r\n

     

    \r\nWith he same formula for the average salary comparison in February, the result is 'same' since both the department '1' and '2' have the same average salary with the company, which is 7000.\r\n\r\n

     

    \r\n", "content_cn": "

    \u7ed9\u5982\u4e0b\u4e24\u4e2a\u8868\uff0c\u5199\u4e00\u4e2a\u67e5\u8be2\u8bed\u53e5\uff0c\u6c42\u51fa\u5728\u6bcf\u4e00\u4e2a\u5de5\u8d44\u53d1\u653e\u65e5\uff0c\u6bcf\u4e2a\u90e8\u95e8\u7684\u5e73\u5747\u5de5\u8d44\u4e0e\u516c\u53f8\u7684\u5e73\u5747\u5de5\u8d44\u7684\u6bd4\u8f83\u7ed3\u679c \uff08\u9ad8 / \u4f4e / \u76f8\u540c\uff09\u3002

    \n\n

     

    \n\n

    \u8868\uff1a salary

    \n\n
    | id | employee_id | amount | pay_date   |\n|----|-------------|--------|------------|\n| 1  | 1           | 9000   | 2017-03-31 |\n| 2  | 2           | 6000   | 2017-03-31 |\n| 3  | 3           | 10000  | 2017-03-31 |\n| 4  | 1           | 7000   | 2017-02-28 |\n| 5  | 2           | 6000   | 2017-02-28 |\n| 6  | 3           | 8000   | 2017-02-28 |\n
    \n\n

     

    \n\n

    employee_id \u5b57\u6bb5\u662f\u8868 employee \u4e2d employee_id \u5b57\u6bb5\u7684\u5916\u952e\u3002

    \n\n

     

    \n\n
    | employee_id | department_id |\n|-------------|---------------|\n| 1           | 1             |\n| 2           | 2             |\n| 3           | 2             |\n
    \n\n

     

    \n\n

    \u5bf9\u4e8e\u5982\u4e0a\u6837\u4f8b\u6570\u636e\uff0c\u7ed3\u679c\u4e3a\uff1a

    \n\n

     

    \n\n
    | pay_month | department_id | comparison  |\n|-----------|---------------|-------------|\n| 2017-03   | 1             | higher      |\n| 2017-03   | 2             | lower       |\n| 2017-02   | 1             | same        |\n| 2017-02   | 2             | same        |\n
    \n\n

     

    \n\n

    \u89e3\u91ca

    \n\n

     

    \n\n

    \u5728\u4e09\u6708\uff0c\u516c\u53f8\u7684\u5e73\u5747\u5de5\u8d44\u662f (9000+6000+10000)/3 = 8333.33...

    \n\n

     

    \n\n

    \u7531\u4e8e\u90e8\u95e8 '1' \u91cc\u53ea\u6709\u4e00\u4e2a employee_id \u4e3a '1' \u7684\u5458\u5de5\uff0c\u6240\u4ee5\u90e8\u95e8 '1' \u7684\u5e73\u5747\u5de5\u8d44\u5c31\u662f\u6b64\u4eba\u7684\u5de5\u8d44 9000 \u3002\u56e0\u4e3a 9000 > 8333.33 \uff0c\u6240\u4ee5\u6bd4\u8f83\u7ed3\u679c\u662f 'higher'\u3002

    \n\n

     

    \n\n

    \u7b2c\u4e8c\u4e2a\u90e8\u95e8\u7684\u5e73\u5747\u5de5\u8d44\u4e3a employee_id \u4e3a '2' \u548c '3' \u4e24\u4e2a\u4eba\u7684\u5e73\u5747\u5de5\u8d44\uff0c\u4e3a (6000+10000)/2=8000 \u3002\u56e0\u4e3a 8000 < 8333.33 \uff0c\u6240\u4ee5\u6bd4\u8f83\u7ed3\u679c\u662f 'lower' \u3002

    \n\n

     

    \n\n

    \u5728\u4e8c\u6708\u7528\u540c\u6837\u7684\u516c\u5f0f\u6c42\u5e73\u5747\u5de5\u8d44\u5e76\u6bd4\u8f83\uff0c\u6bd4\u8f83\u7ed3\u679c\u4e3a 'same' \uff0c\u56e0\u4e3a\u90e8\u95e8 '1' \u548c\u90e8\u95e8 '2' \u7684\u5e73\u5747\u5de5\u8d44\u4e0e\u516c\u53f8\u7684\u5e73\u5747\u5de5\u8d44\u76f8\u540c\uff0c\u90fd\u662f 7000 \u3002

    \n\n

     

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0615](https://leetcode-cn.com/problems/average-salary-departments-vs-company)", "[\u5e73\u5747\u5de5\u8d44\uff1a\u90e8\u95e8\u4e0e\u516c\u53f8\u6bd4\u8f83](/solution/0600-0699/0615.Average%20Salary%20Departments%20VS%20Company/README.md)", "", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0615](https://leetcode.com/problems/average-salary-departments-vs-company)", "[Average Salary Departments VS Company](/solution/0600-0699/0615.Average%20Salary%20Departments%20VS%20Company/README_EN.md)", "", "Hard", "\ud83d\udd12"]}, {"question_id": "0614", "frontend_question_id": "0614", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/second-degree-follower", "url_en": "https://leetcode.com/problems/second-degree-follower", "relative_path_cn": "/solution/0600-0699/0614.Second%20Degree%20Follower/README.md", "relative_path_en": "/solution/0600-0699/0614.Second%20Degree%20Follower/README_EN.md", "title_cn": "\u4e8c\u7ea7\u5173\u6ce8\u8005", "title_en": "Second Degree Follower", "question_title_slug": "second-degree-follower", "content_en": "

    In facebook, there is a follow table with two columns: followee, follower.

    \r\n\r\n

    Please write a sql query to get the amount of each follower’s follower if he/she has one.

    \r\n\r\n

    For example:

    \r\n\r\n
    \r\n+-------------+------------+\r\n| followee    | follower   |\r\n+-------------+------------+\r\n|     A       |     B      |\r\n|     B       |     C      |\r\n|     B       |     D      |\r\n|     D       |     E      |\r\n+-------------+------------+\r\n
    \r\nshould output:\r\n\r\n
    \r\n+-------------+------------+\r\n| follower    | num        |\r\n+-------------+------------+\r\n|     B       |  2         |\r\n|     D       |  1         |\r\n+-------------+------------+\r\n
    \r\nExplaination:
    \r\nBoth B and D exist in the follower list, when as a followee, B's follower is C and D, and D's follower is E. A does not exist in follower list.\r\n

     

    \r\n\r\n

     

    \r\nNote:
    \r\nFollowee would not follow himself/herself in all cases.
    \r\nPlease display the result in follower's alphabet order.\r\n

     

    \r\n", "content_cn": "

    \u5728 facebook \u4e2d\uff0c\u8868 follow \u4f1a\u6709 2 \u4e2a\u5b57\u6bb5\uff1a followee, follower \uff0c\u5206\u522b\u8868\u793a\u88ab\u5173\u6ce8\u8005\u548c\u5173\u6ce8\u8005\u3002

    \n\n

    \u8bf7\u5199\u4e00\u4e2a sql \u67e5\u8be2\u8bed\u53e5\uff0c\u5bf9\u6bcf\u4e00\u4e2a\u5173\u6ce8\u8005\uff0c\u67e5\u8be2\u5173\u6ce8\u4ed6\u7684\u5173\u6ce8\u8005\u7684\u6570\u76ee\u3002

    \n\n

    \u6bd4\u65b9\u8bf4\uff1a

    \n\n
    +-------------+------------+\n| followee    | follower   |\n+-------------+------------+\n|     A       |     B      |\n|     B       |     C      |\n|     B       |     D      |\n|     D       |     E      |\n+-------------+------------+\n
    \n\n

    \u5e94\u8be5\u8f93\u51fa\uff1a

    \n\n
    +-------------+------------+\n| follower    | num        |\n+-------------+------------+\n|     B       |  2         |\n|     D       |  1         |\n+-------------+------------+\n
    \n\n

    \u89e3\u91ca\uff1a

    \n\n

    B \u548c D \u90fd\u5728\u5728 follower \u5b57\u6bb5\u4e2d\u51fa\u73b0\uff0c\u4f5c\u4e3a\u88ab\u5173\u6ce8\u8005\uff0cB \u88ab C \u548c D \u5173\u6ce8\uff0cD \u88ab E \u5173\u6ce8\u3002A \u4e0d\u5728 follower \u5b57\u6bb5\u5185\uff0c\u6240\u4ee5A\u4e0d\u5728\u8f93\u51fa\u5217\u8868\u4e2d\u3002

    \n\n

     

    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    • \u88ab\u5173\u6ce8\u8005\u6c38\u8fdc\u4e0d\u4f1a\u88ab\u4ed6 / \u5979\u81ea\u5df1\u5173\u6ce8\u3002
    • \n\t
    • \u5c06\u7ed3\u679c\u6309\u7167\u5b57\u5178\u5e8f\u8fd4\u56de\u3002
    • \n
    \n\n

     

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0614](https://leetcode-cn.com/problems/second-degree-follower)", "[\u4e8c\u7ea7\u5173\u6ce8\u8005](/solution/0600-0699/0614.Second%20Degree%20Follower/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0614](https://leetcode.com/problems/second-degree-follower)", "[Second Degree Follower](/solution/0600-0699/0614.Second%20Degree%20Follower/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "0613", "frontend_question_id": "0613", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/shortest-distance-in-a-line", "url_en": "https://leetcode.com/problems/shortest-distance-in-a-line", "relative_path_cn": "/solution/0600-0699/0613.Shortest%20Distance%20in%20a%20Line/README.md", "relative_path_en": "/solution/0600-0699/0613.Shortest%20Distance%20in%20a%20Line/README_EN.md", "title_cn": "\u76f4\u7ebf\u4e0a\u7684\u6700\u8fd1\u8ddd\u79bb", "title_en": "Shortest Distance in a Line", "question_title_slug": "shortest-distance-in-a-line", "content_en": "Table point holds the x coordinate of some points on x-axis in a plane, which are all integers.\r\n

     

    \r\nWrite a query to find the shortest distance between two points in these points.\r\n\r\n

     

    \r\n\r\n
    \r\n| x   |\r\n|-----|\r\n| -1  |\r\n| 0   |\r\n| 2   |\r\n
    \r\n\r\n

     

    \r\nThe shortest distance is '1' obviously, which is from point '-1' to '0'. So the output is as below:\r\n\r\n

     

    \r\n\r\n
    \r\n| shortest|\r\n|---------|\r\n| 1       |\r\n
    \r\n\r\n

     

    \r\nNote: Every point is unique, which means there is no duplicates in table point.\r\n\r\n

     

    \r\nFollow-up: What if all these points have an id and are arranged from the left most to the right most of x axis?\r\n\r\n

     

    \r\n", "content_cn": "

    \u8868 point \u4fdd\u5b58\u4e86\u4e00\u4e9b\u70b9\u5728 x \u8f74\u4e0a\u7684\u5750\u6807\uff0c\u8fd9\u4e9b\u5750\u6807\u90fd\u662f\u6574\u6570\u3002

    \n\n

     

    \n\n

    \u5199\u4e00\u4e2a\u67e5\u8be2\u8bed\u53e5\uff0c\u627e\u5230\u8fd9\u4e9b\u70b9\u4e2d\u6700\u8fd1\u4e24\u4e2a\u70b9\u4e4b\u95f4\u7684\u8ddd\u79bb\u3002

    \n\n

     

    \n\n
    | x   |\n|-----|\n| -1  |\n| 0   |\n| 2   |\n
    \n\n

     

    \n\n

    \u6700\u8fd1\u8ddd\u79bb\u663e\u7136\u662f '1' \uff0c\u662f\u70b9 '-1' \u548c '0' \u4e4b\u95f4\u7684\u8ddd\u79bb\u3002\u6240\u4ee5\u8f93\u51fa\u5e94\u8be5\u5982\u4e0b\uff1a

    \n\n

     

    \n\n
    | shortest|\n|---------|\n| 1       |\n
    \n\n

     

    \n\n

    \u6ce8\u610f\uff1a\u6bcf\u4e2a\u70b9\u90fd\u4e0e\u5176\u4ed6\u70b9\u5750\u6807\u4e0d\u540c\uff0c\u8868 table \u4e0d\u4f1a\u6709\u91cd\u590d\u5750\u6807\u51fa\u73b0\u3002

    \n\n

     

    \n\n

    \u8fdb\u9636\uff1a\u5982\u679c\u8fd9\u4e9b\u70b9\u5728 x \u8f74\u4e0a\u4ece\u5de6\u5230\u53f3\u90fd\u6709\u4e00\u4e2a\u7f16\u53f7\uff0c\u8f93\u51fa\u7ed3\u679c\u65f6\u9700\u8981\u8f93\u51fa\u6700\u8fd1\u70b9\u5bf9\u7684\u7f16\u53f7\u5462\uff1f

    \n\n

     

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0613](https://leetcode-cn.com/problems/shortest-distance-in-a-line)", "[\u76f4\u7ebf\u4e0a\u7684\u6700\u8fd1\u8ddd\u79bb](/solution/0600-0699/0613.Shortest%20Distance%20in%20a%20Line/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0613](https://leetcode.com/problems/shortest-distance-in-a-line)", "[Shortest Distance in a Line](/solution/0600-0699/0613.Shortest%20Distance%20in%20a%20Line/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "0612", "frontend_question_id": "0612", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/shortest-distance-in-a-plane", "url_en": "https://leetcode.com/problems/shortest-distance-in-a-plane", "relative_path_cn": "/solution/0600-0699/0612.Shortest%20Distance%20in%20a%20Plane/README.md", "relative_path_en": "/solution/0600-0699/0612.Shortest%20Distance%20in%20a%20Plane/README_EN.md", "title_cn": "\u5e73\u9762\u4e0a\u7684\u6700\u8fd1\u8ddd\u79bb", "title_en": "Shortest Distance in a Plane", "question_title_slug": "shortest-distance-in-a-plane", "content_en": "Table point_2d holds the coordinates (x,y) of some unique points (more than two) in a plane.\r\n

     

    \r\nWrite a query to find the shortest distance between these points rounded to 2 decimals.\r\n\r\n

     

    \r\n\r\n
    \r\n| x  | y  |\r\n|----|----|\r\n| -1 | -1 |\r\n| 0  | 0  |\r\n| -1 | -2 |\r\n
    \r\n\r\n

     

    \r\nThe shortest distance is 1.00 from point (-1,-1) to (-1,2). So the output should be:\r\n\r\n

     

    \r\n\r\n
    \r\n| shortest |\r\n|----------|\r\n| 1.00     |\r\n
    \r\n\r\n

     

    \r\nNote: The longest distance among all the points are less than 10000.\r\n\r\n

     

    \r\n", "content_cn": "

    \u8868 point_2d \u4fdd\u5b58\u4e86\u6240\u6709\u70b9\uff08\u591a\u4e8e 2 \u4e2a\u70b9\uff09\u7684\u5750\u6807 (x,y) \uff0c\u8fd9\u4e9b\u70b9\u5728\u5e73\u9762\u4e0a\u4e24\u4e24\u4e0d\u91cd\u5408\u3002

    \n\n

     

    \n\n

    \u5199\u4e00\u4e2a\u67e5\u8be2\u8bed\u53e5\u627e\u5230\u4e24\u70b9\u4e4b\u95f4\u7684\u6700\u8fd1\u8ddd\u79bb\uff0c\u4fdd\u7559 2 \u4f4d\u5c0f\u6570\u3002

    \n\n

     

    \n\n
    | x  | y  |\n|----|----|\n| -1 | -1 |\n| 0  | 0  |\n| -1 | -2 |\n
    \n\n

     

    \n\n

    \u6700\u8fd1\u8ddd\u79bb\u5728\u70b9 (-1,-1) \u548c(-1,2) \u4e4b\u95f4\uff0c\u8ddd\u79bb\u4e3a 1.00 \u3002\u6240\u4ee5\u8f93\u51fa\u5e94\u8be5\u4e3a\uff1a

    \n\n

     

    \n\n
    | shortest |\n|----------|\n| 1.00     |\n
    \n\n

     

    \n\n

    \u6ce8\u610f\uff1a\u4efb\u610f\u70b9\u4e4b\u95f4\u7684\u6700\u8fdc\u8ddd\u79bb\u5c0f\u4e8e 10000 \u3002

    \n\n

     

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0612](https://leetcode-cn.com/problems/shortest-distance-in-a-plane)", "[\u5e73\u9762\u4e0a\u7684\u6700\u8fd1\u8ddd\u79bb](/solution/0600-0699/0612.Shortest%20Distance%20in%20a%20Plane/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0612](https://leetcode.com/problems/shortest-distance-in-a-plane)", "[Shortest Distance in a Plane](/solution/0600-0699/0612.Shortest%20Distance%20in%20a%20Plane/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "0611", "frontend_question_id": "0611", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/valid-triangle-number", "url_en": "https://leetcode.com/problems/valid-triangle-number", "relative_path_cn": "/solution/0600-0699/0611.Valid%20Triangle%20Number/README.md", "relative_path_en": "/solution/0600-0699/0611.Valid%20Triangle%20Number/README_EN.md", "title_cn": "\u6709\u6548\u4e09\u89d2\u5f62\u7684\u4e2a\u6570", "title_en": "Valid Triangle Number", "question_title_slug": "valid-triangle-number", "content_en": "

    Given an integer array nums, return the number of triplets chosen from the array that can make triangles if we take them as side lengths of a triangle.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [2,2,3,4]\nOutput: 3\nExplanation: Valid combinations are: \n2,3,4 (using the first 2)\n2,3,4 (using the second 2)\n2,2,3\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [4,2,3,4]\nOutput: 4\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 1000
    • \n\t
    • 0 <= nums[i] <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5305\u542b\u975e\u8d1f\u6574\u6570\u7684\u6570\u7ec4\uff0c\u4f60\u7684\u4efb\u52a1\u662f\u7edf\u8ba1\u5176\u4e2d\u53ef\u4ee5\u7ec4\u6210\u4e09\u89d2\u5f62\u4e09\u6761\u8fb9\u7684\u4e09\u5143\u7ec4\u4e2a\u6570\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: [2,2,3,4]\n\u8f93\u51fa: 3\n\u89e3\u91ca:\n\u6709\u6548\u7684\u7ec4\u5408\u662f: \n2,3,4 (\u4f7f\u7528\u7b2c\u4e00\u4e2a 2)\n2,3,4 (\u4f7f\u7528\u7b2c\u4e8c\u4e2a 2)\n2,2,3\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u6570\u7ec4\u957f\u5ea6\u4e0d\u8d85\u8fc71000\u3002
    2. \n\t
    3. \u6570\u7ec4\u91cc\u6574\u6570\u7684\u8303\u56f4\u4e3a [0, 1000]\u3002
    4. \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int triangleNumber(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int triangleNumber(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def triangleNumber(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def triangleNumber(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint triangleNumber(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int TriangleNumber(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar triangleNumber = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef triangle_number(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func triangleNumber(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func triangleNumber(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def triangleNumber(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun triangleNumber(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn triangle_number(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function triangleNumber($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function triangleNumber(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (triangle-number nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0611](https://leetcode-cn.com/problems/valid-triangle-number)", "[\u6709\u6548\u4e09\u89d2\u5f62\u7684\u4e2a\u6570](/solution/0600-0699/0611.Valid%20Triangle%20Number/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0611](https://leetcode.com/problems/valid-triangle-number)", "[Valid Triangle Number](/solution/0600-0699/0611.Valid%20Triangle%20Number/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0610", "frontend_question_id": "0610", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/triangle-judgement", "url_en": "https://leetcode.com/problems/triangle-judgement", "relative_path_cn": "/solution/0600-0699/0610.Triangle%20Judgement/README.md", "relative_path_en": "/solution/0600-0699/0610.Triangle%20Judgement/README_EN.md", "title_cn": "\u5224\u65ad\u4e09\u89d2\u5f62", "title_en": "Triangle Judgement", "question_title_slug": "triangle-judgement", "content_en": "A pupil Tim gets homework to identify whether three line segments could possibly form a triangle.\r\n

     

    \r\nHowever, this assignment is very heavy because there are hundreds of records to calculate.\r\n\r\n

     

    \r\nCould you help Tim by writing a query to judge whether these three sides can form a triangle, assuming table triangle holds the length of the three sides x, y and z.\r\n\r\n

     

    \r\n\r\n
    \r\n| x  | y  | z  |\r\n|----|----|----|\r\n| 13 | 15 | 30 |\r\n| 10 | 20 | 15 |\r\n
    \r\nFor the sample data above, your query should return the follow result:\r\n\r\n
    \r\n| x  | y  | z  | triangle |\r\n|----|----|----|----------|\r\n| 13 | 15 | 30 | No       |\r\n| 10 | 20 | 15 | Yes      |\r\n
    \r\n", "content_cn": "

    \u4e00\u4e2a\u5c0f\u5b66\u751f Tim \u7684\u4f5c\u4e1a\u662f\u5224\u65ad\u4e09\u6761\u7ebf\u6bb5\u662f\u5426\u80fd\u5f62\u6210\u4e00\u4e2a\u4e09\u89d2\u5f62\u3002

    \n\n

    \u7136\u800c\uff0c\u8fd9\u4e2a\u4f5c\u4e1a\u975e\u5e38\u7e41\u91cd\uff0c\u56e0\u4e3a\u6709\u51e0\u767e\u7ec4\u7ebf\u6bb5\u9700\u8981\u5224\u65ad\u3002

    \n\n

    \u5047\u8bbe\u8868 triangle\u00a0\u4fdd\u5b58\u4e86\u6240\u6709\u4e09\u6761\u7ebf\u6bb5\u7684\u957f\u5ea6 x\u3001y\u3001z \uff0c\u8bf7\u4f60\u5e2e Tim \u5199\u4e00\u4e2a\u67e5\u8be2\u8bed\u53e5\uff0c\u6765\u5224\u65ad\u6bcf\u7ec4 x\u3001y\u3001z \u662f\u5426\u53ef\u4ee5\u7ec4\u6210\u4e00\u4e2a\u4e09\u89d2\u5f62\uff1f

    \n\n

    \u00a0

    \n\n
    \n| x  | y  | z  |\n|----|----|----|\n| 13 | 15 | 30 |\n| 10 | 20 | 15 |\n
    \n\n

    \u5bf9\u4e8e\u5982\u4e0a\u6837\u4f8b\u6570\u636e\uff0c\u4f60\u7684\u67e5\u8be2\u8bed\u53e5\u5e94\u8be5\u8fd4\u56de\u5982\u4e0b\u7ed3\u679c\uff1a

    \n\n
    \n| x  | y  | z  | triangle |\n|----|----|----|----------|\n| 13 | 15 | 30 | No       |\n| 10 | 20 | 15 | Yes      |\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0610](https://leetcode-cn.com/problems/triangle-judgement)", "[\u5224\u65ad\u4e09\u89d2\u5f62](/solution/0600-0699/0610.Triangle%20Judgement/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0610](https://leetcode.com/problems/triangle-judgement)", "[Triangle Judgement](/solution/0600-0699/0610.Triangle%20Judgement/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "0609", "frontend_question_id": "0609", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-duplicate-file-in-system", "url_en": "https://leetcode.com/problems/find-duplicate-file-in-system", "relative_path_cn": "/solution/0600-0699/0609.Find%20Duplicate%20File%20in%20System/README.md", "relative_path_en": "/solution/0600-0699/0609.Find%20Duplicate%20File%20in%20System/README_EN.md", "title_cn": "\u5728\u7cfb\u7edf\u4e2d\u67e5\u627e\u91cd\u590d\u6587\u4ef6", "title_en": "Find Duplicate File in System", "question_title_slug": "find-duplicate-file-in-system", "content_en": "

    Given a list paths of directory info, including the directory path, and all the files with contents in this directory, return all the duplicate files in the file system in terms of their paths. You may return the answer in any order.

    \n\n

    A group of duplicate files consists of at least two files that have the same content.

    \n\n

    A single directory info string in the input list has the following format:

    \n\n
      \n\t
    • "root/d1/d2/.../dm f1.txt(f1_content) f2.txt(f2_content) ... fn.txt(fn_content)"
    • \n
    \n\n

    It means there are n files (f1.txt, f2.txt ... fn.txt) with content (f1_content, f2_content ... fn_content) respectively in the directory "root/d1/d2/.../dm". Note that n >= 1 and m >= 0. If m = 0, it means the directory is just the root directory.

    \n\n

    The output is a list of groups of duplicate file paths. For each group, it contains all the file paths of the files that have the same content. A file path is a string that has the following format:

    \n\n
      \n\t
    • "directory_path/file_name.txt"
    • \n
    \n\n

     

    \n

    Example 1:

    \n
    Input: paths = [\"root/a 1.txt(abcd) 2.txt(efgh)\",\"root/c 3.txt(abcd)\",\"root/c/d 4.txt(efgh)\",\"root 4.txt(efgh)\"]\nOutput: [[\"root/a/2.txt\",\"root/c/d/4.txt\",\"root/4.txt\"],[\"root/a/1.txt\",\"root/c/3.txt\"]]\n

    Example 2:

    \n
    Input: paths = [\"root/a 1.txt(abcd) 2.txt(efgh)\",\"root/c 3.txt(abcd)\",\"root/c/d 4.txt(efgh)\"]\nOutput: [[\"root/a/2.txt\",\"root/c/d/4.txt\"],[\"root/a/1.txt\",\"root/c/3.txt\"]]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= paths.length <= 2 * 104
    • \n\t
    • 1 <= paths[i].length <= 3000
    • \n\t
    • 1 <= sum(paths[i].length) <= 5 * 105
    • \n\t
    • paths[i] consist of English letters, digits, '/', '.', '(', ')', and ' '.
    • \n\t
    • You may assume no files or directories share the same name in the same directory.
    • \n\t
    • You may assume each given directory info represents a unique directory. A single blank space separates the directory path and file info.
    • \n
    \n\n

     

    \n

    Follow up:

    \n\n
      \n\t
    • Imagine you are given a real file system, how will you search files? DFS or BFS?
    • \n\t
    • If the file content is very large (GB level), how will you modify your solution?
    • \n\t
    • If you can only read the file by 1kb each time, how will you modify your solution?
    • \n\t
    • What is the time complexity of your modified solution? What is the most time-consuming part and memory-consuming part of it? How to optimize?
    • \n\t
    • How to make sure the duplicated files you find are not false positive?
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u76ee\u5f55\u4fe1\u606f\u5217\u8868\uff0c\u5305\u62ec\u76ee\u5f55\u8def\u5f84\uff0c\u4ee5\u53ca\u8be5\u76ee\u5f55\u4e2d\u7684\u6240\u6709\u5305\u542b\u5185\u5bb9\u7684\u6587\u4ef6\uff0c\u60a8\u9700\u8981\u627e\u5230\u6587\u4ef6\u7cfb\u7edf\u4e2d\u7684\u6240\u6709\u91cd\u590d\u6587\u4ef6\u7ec4\u7684\u8def\u5f84\u3002\u4e00\u7ec4\u91cd\u590d\u7684\u6587\u4ef6\u81f3\u5c11\u5305\u62ec\u4e8c\u4e2a\u5177\u6709\u5b8c\u5168\u76f8\u540c\u5185\u5bb9\u7684\u6587\u4ef6\u3002

    \n\n

    \u8f93\u5165\u5217\u8868\u4e2d\u7684\u5355\u4e2a\u76ee\u5f55\u4fe1\u606f\u5b57\u7b26\u4e32\u7684\u683c\u5f0f\u5982\u4e0b\uff1a

    \n\n

    "root/d1/d2/.../dm f1.txt(f1_content) f2.txt(f2_content) ... fn.txt(fn_content)"

    \n\n

    \u8fd9\u610f\u5473\u7740\u6709 n \u4e2a\u6587\u4ef6\uff08f1.txtf2.txt ... fn.txt \u7684\u5185\u5bb9\u5206\u522b\u662f f1_contentf2_content ... fn_content\uff09\u5728\u76ee\u5f55 root/d1/d2/.../dm \u4e0b\u3002\u6ce8\u610f\uff1an>=1 \u4e14 m>=0\u3002\u5982\u679c m=0\uff0c\u5219\u8868\u793a\u8be5\u76ee\u5f55\u662f\u6839\u76ee\u5f55\u3002

    \n\n

    \u8be5\u8f93\u51fa\u662f\u91cd\u590d\u6587\u4ef6\u8def\u5f84\u7ec4\u7684\u5217\u8868\u3002\u5bf9\u4e8e\u6bcf\u4e2a\u7ec4\uff0c\u5b83\u5305\u542b\u5177\u6709\u76f8\u540c\u5185\u5bb9\u7684\u6587\u4ef6\u7684\u6240\u6709\u6587\u4ef6\u8def\u5f84\u3002\u6587\u4ef6\u8def\u5f84\u662f\u5177\u6709\u4e0b\u5217\u683c\u5f0f\u7684\u5b57\u7b26\u4e32\uff1a

    \n\n

    "directory_path/file_name.txt"

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a\n["root/a 1.txt(abcd) 2.txt(efgh)", "root/c 3.txt(abcd)", "root/c/d 4.txt(efgh)", "root 4.txt(efgh)"]\n\u8f93\u51fa\uff1a  \n[["root/a/2.txt","root/c/d/4.txt","root/4.txt"],["root/a/1.txt","root/c/3.txt"]]\n
    \n\n

     

    \n\n

    \u6ce8\uff1a

    \n\n
      \n\t
    1. \u6700\u7ec8\u8f93\u51fa\u4e0d\u9700\u8981\u987a\u5e8f\u3002
    2. \n\t
    3. \u60a8\u53ef\u4ee5\u5047\u8bbe\u76ee\u5f55\u540d\u3001\u6587\u4ef6\u540d\u548c\u6587\u4ef6\u5185\u5bb9\u53ea\u6709\u5b57\u6bcd\u548c\u6570\u5b57\uff0c\u5e76\u4e14\u6587\u4ef6\u5185\u5bb9\u7684\u957f\u5ea6\u5728 [1\uff0c50] \u7684\u8303\u56f4\u5185\u3002
    4. \n\t
    5. \u7ed9\u5b9a\u7684\u6587\u4ef6\u6570\u91cf\u5728 [1\uff0c20000] \u4e2a\u8303\u56f4\u5185\u3002
    6. \n\t
    7. \u60a8\u53ef\u4ee5\u5047\u8bbe\u5728\u540c\u4e00\u76ee\u5f55\u4e2d\u6ca1\u6709\u4efb\u4f55\u6587\u4ef6\u6216\u76ee\u5f55\u5171\u4eab\u76f8\u540c\u7684\u540d\u79f0\u3002
    8. \n\t
    9. \u60a8\u53ef\u4ee5\u5047\u8bbe\u6bcf\u4e2a\u7ed9\u5b9a\u7684\u76ee\u5f55\u4fe1\u606f\u4ee3\u8868\u4e00\u4e2a\u552f\u4e00\u7684\u76ee\u5f55\u3002\u76ee\u5f55\u8def\u5f84\u548c\u6587\u4ef6\u4fe1\u606f\u7528\u4e00\u4e2a\u7a7a\u683c\u5206\u9694\u3002
    10. \n
    \n\n

     

    \n\n

    \u8d85\u8d8a\u7ade\u8d5b\u7684\u540e\u7eed\u884c\u52a8\uff1a

    \n\n
      \n\t
    1. \u5047\u8bbe\u60a8\u6709\u4e00\u4e2a\u771f\u6b63\u7684\u6587\u4ef6\u7cfb\u7edf\uff0c\u60a8\u5c06\u5982\u4f55\u641c\u7d22\u6587\u4ef6\uff1f\u5e7f\u5ea6\u641c\u7d22\u8fd8\u662f\u5bbd\u5ea6\u641c\u7d22\uff1f
    2. \n\t
    3. \u5982\u679c\u6587\u4ef6\u5185\u5bb9\u975e\u5e38\u5927\uff08GB\u7ea7\u522b\uff09\uff0c\u60a8\u5c06\u5982\u4f55\u4fee\u6539\u60a8\u7684\u89e3\u51b3\u65b9\u6848\uff1f
    4. \n\t
    5. \u5982\u679c\u6bcf\u6b21\u53ea\u80fd\u8bfb\u53d6 1 kb \u7684\u6587\u4ef6\uff0c\u60a8\u5c06\u5982\u4f55\u4fee\u6539\u89e3\u51b3\u65b9\u6848\uff1f
    6. \n\t
    7. \u4fee\u6539\u540e\u7684\u89e3\u51b3\u65b9\u6848\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u662f\u591a\u5c11\uff1f\u5176\u4e2d\u6700\u8017\u65f6\u7684\u90e8\u5206\u548c\u6d88\u8017\u5185\u5b58\u7684\u90e8\u5206\u662f\u4ec0\u4e48\uff1f\u5982\u4f55\u4f18\u5316\uff1f
    8. \n\t
    9. \u5982\u4f55\u786e\u4fdd\u60a8\u53d1\u73b0\u7684\u91cd\u590d\u6587\u4ef6\u4e0d\u662f\u8bef\u62a5\uff1f
    10. \n
    \n", "tags_en": ["Hash Table", "String"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> findDuplicate(vector& paths) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> findDuplicate(String[] paths) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findDuplicate(self, paths):\n \"\"\"\n :type paths: List[str]\n :rtype: List[List[str]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findDuplicate(self, paths: List[str]) -> List[List[str]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nchar *** findDuplicate(char ** paths, int pathsSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> FindDuplicate(string[] paths) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} paths\n * @return {string[][]}\n */\nvar findDuplicate = function(paths) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} paths\n# @return {String[][]}\ndef find_duplicate(paths)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findDuplicate(_ paths: [String]) -> [[String]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findDuplicate(paths []string) [][]string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findDuplicate(paths: Array[String]): List[List[String]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findDuplicate(paths: Array): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_duplicate(paths: Vec) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $paths\n * @return String[][]\n */\n function findDuplicate($paths) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findDuplicate(paths: string[]): string[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-duplicate paths)\n (-> (listof string?) (listof (listof string?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0609](https://leetcode-cn.com/problems/find-duplicate-file-in-system)", "[\u5728\u7cfb\u7edf\u4e2d\u67e5\u627e\u91cd\u590d\u6587\u4ef6](/solution/0600-0699/0609.Find%20Duplicate%20File%20in%20System/README.md)", "`\u54c8\u5e0c\u8868`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0609](https://leetcode.com/problems/find-duplicate-file-in-system)", "[Find Duplicate File in System](/solution/0600-0699/0609.Find%20Duplicate%20File%20in%20System/README_EN.md)", "`Hash Table`,`String`", "Medium", ""]}, {"question_id": "0608", "frontend_question_id": "0608", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/tree-node", "url_en": "https://leetcode.com/problems/tree-node", "relative_path_cn": "/solution/0600-0699/0608.Tree%20Node/README.md", "relative_path_en": "/solution/0600-0699/0608.Tree%20Node/README_EN.md", "title_cn": "\u6811\u8282\u70b9", "title_en": "Tree Node", "question_title_slug": "tree-node", "content_en": "

    Given a table tree, id is identifier of the tree node and p_id is its parent node's id.

    \r\n\r\n
    \r\n+----+------+\r\n| id | p_id |\r\n+----+------+\r\n| 1  | null |\r\n| 2  | 1    |\r\n| 3  | 1    |\r\n| 4  | 2    |\r\n| 5  | 2    |\r\n+----+------+\r\n
    \r\nEach node in the tree can be one of three types:\r\n\r\n
      \r\n\t
    • Leaf: if the node is a leaf node.
    • \r\n\t
    • Root: if the node is the root of the tree.
    • \r\n\t
    • Inner: If the node is neither a leaf node nor a root node.
    • \r\n
    \r\n\r\n

     

    \r\nWrite a query to print the node id and the type of the node. Sort your output by the node id. The result for the above sample is:\r\n\r\n

     

    \r\n\r\n
    \r\n+----+------+\r\n| id | Type |\r\n+----+------+\r\n| 1  | Root |\r\n| 2  | Inner|\r\n| 3  | Leaf |\r\n| 4  | Leaf |\r\n| 5  | Leaf |\r\n+----+------+\r\n
    \r\n\r\n

     

    \r\n\r\n

    Explanation

    \r\n\r\n

     

    \r\n\r\n
      \r\n\t
    • Node '1' is root node, because its parent node is NULL and it has child node '2' and '3'.
    • \r\n\t
    • Node '2' is inner node, because it has parent node '1' and child node '4' and '5'.
    • \r\n\t
    • Node '3', '4' and '5' is Leaf node, because they have parent node and they don't have child node.
    • \r\n\t
      \r\n\t
    • And here is the image of the sample tree as below:\r\n\t

       

      \r\n\r\n\t
      \r\n\t\t\t  1\r\n\t\t\t/   \\\r\n                      2       3\r\n                    /   \\\r\n                  4       5\r\n
      \r\n\r\n\t

      Note

      \r\n\r\n\t

      If there is only one node on the tree, you only need to output its root attributes.

      \r\n\t
    • \r\n
    \r\n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u8868 tree\uff0cid \u662f\u6811\u8282\u70b9\u7684\u7f16\u53f7\uff0c p_id \u662f\u5b83\u7236\u8282\u70b9\u7684 id \u3002

    \n\n
    +----+------+\n| id | p_id |\n+----+------+\n| 1  | null |\n| 2  | 1    |\n| 3  | 1    |\n| 4  | 2    |\n| 5  | 2    |\n+----+------+
    \n\n

    \u6811\u4e2d\u6bcf\u4e2a\u8282\u70b9\u5c5e\u4e8e\u4ee5\u4e0b\u4e09\u79cd\u7c7b\u578b\u4e4b\u4e00\uff1a

    \n\n
      \n\t
    • \u53f6\u5b50\uff1a\u5982\u679c\u8fd9\u4e2a\u8282\u70b9\u6ca1\u6709\u4efb\u4f55\u5b69\u5b50\u8282\u70b9\u3002
    • \n\t
    • \u6839\uff1a\u5982\u679c\u8fd9\u4e2a\u8282\u70b9\u662f\u6574\u68f5\u6811\u7684\u6839\uff0c\u5373\u6ca1\u6709\u7236\u8282\u70b9\u3002
    • \n\t
    • \u5185\u90e8\u8282\u70b9\uff1a\u5982\u679c\u8fd9\u4e2a\u8282\u70b9\u65e2\u4e0d\u662f\u53f6\u5b50\u8282\u70b9\u4e5f\u4e0d\u662f\u6839\u8282\u70b9\u3002
    • \n
    \n\n

     

    \n\n

    \u5199\u4e00\u4e2a\u67e5\u8be2\u8bed\u53e5\uff0c\u8f93\u51fa\u6240\u6709\u8282\u70b9\u7684\u7f16\u53f7\u548c\u8282\u70b9\u7684\u7c7b\u578b\uff0c\u5e76\u5c06\u7ed3\u679c\u6309\u7167\u8282\u70b9\u7f16\u53f7\u6392\u5e8f\u3002\u4e0a\u9762\u6837\u4f8b\u7684\u7ed3\u679c\u4e3a\uff1a

    \n\n

     

    \n\n
    +----+------+\n| id | Type |\n+----+------+\n| 1  | Root |\n| 2  | Inner|\n| 3  | Leaf |\n| 4  | Leaf |\n| 5  | Leaf |\n+----+------+\n
    \n\n

     

    \n\n

    \u89e3\u91ca

    \n\n
      \n\t
    • \u8282\u70b9 '1' \u662f\u6839\u8282\u70b9\uff0c\u56e0\u4e3a\u5b83\u7684\u7236\u8282\u70b9\u662f NULL \uff0c\u540c\u65f6\u5b83\u6709\u5b69\u5b50\u8282\u70b9 '2' \u548c '3' \u3002
    • \n\t
    • \u8282\u70b9 '2' \u662f\u5185\u90e8\u8282\u70b9\uff0c\u56e0\u4e3a\u5b83\u6709\u7236\u8282\u70b9 '1' \uff0c\u4e5f\u6709\u5b69\u5b50\u8282\u70b9 '4' \u548c '5' \u3002
    • \n\t
    • \u8282\u70b9 '3', '4' \u548c '5' \u90fd\u662f\u53f6\u5b50\u8282\u70b9\uff0c\u56e0\u4e3a\u5b83\u4eec\u90fd\u6709\u7236\u8282\u70b9\u540c\u65f6\u6ca1\u6709\u5b69\u5b50\u8282\u70b9\u3002
    • \n\t
    • \u6837\u4f8b\u4e2d\u6811\u7684\u5f62\u6001\u5982\u4e0b\uff1a\n\t

       

      \n\n\t
      \t\t\t  1\n\t\t\t/   \\\n                      2       3\n                    /   \\\n                  4       5\n
      \n\n\t

       

      \n\t
    • \n
    \n\n

    \u6ce8\u610f

    \n\n

    \u5982\u679c\u6811\u4e2d\u53ea\u6709\u4e00\u4e2a\u8282\u70b9\uff0c\u4f60\u53ea\u9700\u8981\u8f93\u51fa\u5b83\u7684\u6839\u5c5e\u6027\u3002

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0608](https://leetcode-cn.com/problems/tree-node)", "[\u6811\u8282\u70b9](/solution/0600-0699/0608.Tree%20Node/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0608](https://leetcode.com/problems/tree-node)", "[Tree Node](/solution/0600-0699/0608.Tree%20Node/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "0607", "frontend_question_id": "0607", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/sales-person", "url_en": "https://leetcode.com/problems/sales-person", "relative_path_cn": "/solution/0600-0699/0607.Sales%20Person/README.md", "relative_path_en": "/solution/0600-0699/0607.Sales%20Person/README_EN.md", "title_cn": "\u9500\u552e\u5458", "title_en": "Sales Person", "question_title_slug": "sales-person", "content_en": "

    Description

    \n\n

    Given three tables: salesperson, company, orders.
    \nOutput all the names in the table salesperson, who didn’t have sales to company 'RED'.

    \n\n

    Example
    \nInput

    \n\n

    Table: salesperson

    \n\n
    \n+----------+------+--------+-----------------+-----------+\n| sales_id | name | salary | commission_rate | hire_date |\n+----------+------+--------+-----------------+-----------+\n|   1      | John | 100000 |     6           | 4/1/2006  |\n|   2      | Amy  | 120000 |     5           | 5/1/2010  |\n|   3      | Mark | 65000  |     12          | 12/25/2008|\n|   4      | Pam  | 25000  |     25          | 1/1/2005  |\n|   5      | Alex | 50000  |     10          | 2/3/2007  |\n+----------+------+--------+-----------------+-----------+\n
    \nThe table salesperson holds the salesperson information. Every salesperson has a sales_id and a name.\n\n

    Table: company

    \n\n
    \n+---------+--------+------------+\n| com_id  |  name  |    city    |\n+---------+--------+------------+\n|   1     |  RED   |   Boston   |\n|   2     | ORANGE |   New York |\n|   3     | YELLOW |   Boston   |\n|   4     | GREEN  |   Austin   |\n+---------+--------+------------+\n
    \nThe table company holds the company information. Every company has a com_id and a name.\n\n

    Table: orders

    \n\n
    \n+----------+------------+---------+----------+--------+\n| order_id | order_date | com_id  | sales_id | amount |\n+----------+------------+---------+----------+--------+\n| 1        |   1/1/2014 |    3    |    4     | 100000 |\n| 2        |   2/1/2014 |    4    |    5     | 5000   |\n| 3        |   3/1/2014 |    1    |    1     | 50000  |\n| 4        |   4/1/2014 |    1    |    4     | 25000  |\n+----------+----------+---------+----------+--------+\n
    \nThe table orders holds the sales record information, salesperson and customer company are represented by sales_id and com_id.\n\n

    output

    \n\n
    \n+------+\n| name | \n+------+\n| Amy  | \n| Mark | \n| Alex |\n+------+\n
    \n\n

    Explanation

    \n\n

    According to order '3' and '4' in table orders, it is easy to tell only salesperson 'John' and 'Pam' have sales to company 'RED',
    \nso we need to output all the other names in the table salesperson.

    \n", "content_cn": "

    \u63cf\u8ff0

    \n\n

    \u7ed9\u5b9a 3 \u4e2a\u8868\uff1a salesperson\uff0c company\uff0c orders\u3002
    \n\u8f93\u51fa\u6240\u6709\u8868 salesperson \u4e2d\uff0c\u6ca1\u6709\u5411\u516c\u53f8 'RED' \u9500\u552e\u4efb\u4f55\u4e1c\u897f\u7684\u9500\u552e\u5458\u3002

    \n\n

    \u793a\u4f8b\uff1a
    \n\u8f93\u5165

    \n\n

    \u8868\uff1a salesperson

    \n\n
    +----------+------+--------+-----------------+-----------+\n| sales_id | name | salary | commission_rate | hire_date |\n+----------+------+--------+-----------------+-----------+\n|   1      | John | 100000 |     6           | 4/1/2006  |\n|   2      | Amy  | 120000 |     5           | 5/1/2010  |\n|   3      | Mark | 65000  |     12          | 12/25/2008|\n|   4      | Pam  | 25000  |     25          | 1/1/2005  |\n|   5      | Alex | 50000  |     10          | 2/3/2007  |\n+----------+------+--------+-----------------+-----------+\n
    \n\n

    \u8868 salesperson \u5b58\u50a8\u4e86\u6240\u6709\u9500\u552e\u5458\u7684\u4fe1\u606f\u3002\u6bcf\u4e2a\u9500\u552e\u5458\u90fd\u6709\u4e00\u4e2a\u9500\u552e\u5458\u7f16\u53f7 sales_id \u548c\u4ed6\u7684\u540d\u5b57 name \u3002

    \n\n

    \u8868\uff1a company

    \n\n
    +---------+--------+------------+\n| com_id  |  name  |    city    |\n+---------+--------+------------+\n|   1     |  RED   |   Boston   |\n|   2     | ORANGE |   New York |\n|   3     | YELLOW |   Boston   |\n|   4     | GREEN  |   Austin   |\n+---------+--------+------------+\n
    \n\n

    \u8868 company \u5b58\u50a8\u4e86\u6240\u6709\u516c\u53f8\u7684\u4fe1\u606f\u3002\u6bcf\u4e2a\u516c\u53f8\u90fd\u6709\u4e00\u4e2a\u516c\u53f8\u7f16\u53f7 com_id \u548c\u5b83\u7684\u540d\u5b57 name \u3002

    \n\n

    \u8868\uff1a orders

    \n\n
    +----------+------------+---------+----------+--------+\n| order_id | order_date | com_id  | sales_id | amount |\n+----------+------------+---------+----------+--------+\n| 1        |   1/1/2014 |    3    |    4     | 100000 |\n| 2        |   2/1/2014 |    4    |    5     | 5000   |\n| 3        |   3/1/2014 |    1    |    1     | 50000  |\n| 4        |   4/1/2014 |    1    |    4     | 25000  |\n+----------+----------+---------+----------+--------+\n
    \n\n

    \u8868 orders \u5b58\u50a8\u4e86\u6240\u6709\u7684\u9500\u552e\u6570\u636e\uff0c\u5305\u62ec\u9500\u552e\u5458\u7f16\u53f7 sales_id \u548c\u516c\u53f8\u7f16\u53f7 com_id \u3002

    \n\n

    \u8f93\u51fa

    \n\n
    +------+\n| name | \n+------+\n| Amy  | \n| Mark | \n| Alex |\n+------+\n
    \n\n

    \u89e3\u91ca

    \n\n

    \u6839\u636e\u8868 orders \u4e2d\u7684\u8ba2\u5355 '3' \u548c '4' \uff0c\u5bb9\u6613\u770b\u51fa\u53ea\u6709 'John' \u548c 'Pam' \u4e24\u4e2a\u9500\u552e\u5458\u66fe\u7ecf\u5411\u516c\u53f8 'RED' \u9500\u552e\u8fc7\u3002

    \n\n

    \u6240\u4ee5\u6211\u4eec\u9700\u8981\u8f93\u51fa\u8868 salesperson \u4e2d\u6240\u6709\u5176\u4ed6\u4eba\u7684\u540d\u5b57\u3002

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0607](https://leetcode-cn.com/problems/sales-person)", "[\u9500\u552e\u5458](/solution/0600-0699/0607.Sales%20Person/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0607](https://leetcode.com/problems/sales-person)", "[Sales Person](/solution/0600-0699/0607.Sales%20Person/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "0606", "frontend_question_id": "0606", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/construct-string-from-binary-tree", "url_en": "https://leetcode.com/problems/construct-string-from-binary-tree", "relative_path_cn": "/solution/0600-0699/0606.Construct%20String%20from%20Binary%20Tree/README.md", "relative_path_en": "/solution/0600-0699/0606.Construct%20String%20from%20Binary%20Tree/README_EN.md", "title_cn": "\u6839\u636e\u4e8c\u53c9\u6811\u521b\u5efa\u5b57\u7b26\u4e32", "title_en": "Construct String from Binary Tree", "question_title_slug": "construct-string-from-binary-tree", "content_en": "

    Given the root of a binary tree, construct a string consists of parenthesis and integers from a binary tree with the preorder traversing way, and return it.

    \n\n

    Omit all the empty parenthesis pairs that do not affect the one-to-one mapping relationship between the string and the original binary tree.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,2,3,4]\nOutput: "1(2(4))(3)"\nExplanation: Originallay it needs to be "1(2(4)())(3()())", but you need to omit all the unnecessary empty parenthesis pairs. And it will be "1(2(4))(3)"\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [1,2,3,null,4]\nOutput: "1(2()(4))(3)"\nExplanation: Almost the same as the first example, except we cannot omit the first parenthesis pair to break the one-to-one mapping relationship between the input and the output.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 104].
    • \n\t
    • -1000 <= Node.val <= 1000
    • \n
    \n", "content_cn": "

    \u4f60\u9700\u8981\u91c7\u7528\u524d\u5e8f\u904d\u5386\u7684\u65b9\u5f0f\uff0c\u5c06\u4e00\u4e2a\u4e8c\u53c9\u6811\u8f6c\u6362\u6210\u4e00\u4e2a\u7531\u62ec\u53f7\u548c\u6574\u6570\u7ec4\u6210\u7684\u5b57\u7b26\u4e32\u3002

    \n\n

    \u7a7a\u8282\u70b9\u5219\u7528\u4e00\u5bf9\u7a7a\u62ec\u53f7 "()" \u8868\u793a\u3002\u800c\u4e14\u4f60\u9700\u8981\u7701\u7565\u6240\u6709\u4e0d\u5f71\u54cd\u5b57\u7b26\u4e32\u4e0e\u539f\u59cb\u4e8c\u53c9\u6811\u4e4b\u95f4\u7684\u4e00\u5bf9\u4e00\u6620\u5c04\u5173\u7cfb\u7684\u7a7a\u62ec\u53f7\u5bf9\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: \u4e8c\u53c9\u6811: [1,2,3,4]\n       1\n     /   \\\n    2     3\n   /    \n  4     \n\n\u8f93\u51fa: "1(2(4))(3)"\n\n\u89e3\u91ca: \u539f\u672c\u5c06\u662f“1(2(4)())(3())”\uff0c\n\u5728\u4f60\u7701\u7565\u6240\u6709\u4e0d\u5fc5\u8981\u7684\u7a7a\u62ec\u53f7\u5bf9\u4e4b\u540e\uff0c\n\u5b83\u5c06\u662f“1(2(4))(3)”\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: \u4e8c\u53c9\u6811: [1,2,3,null,4]\n       1\n     /   \\\n    2     3\n     \\  \n      4 \n\n\u8f93\u51fa: "1(2()(4))(3)"\n\n\u89e3\u91ca: \u548c\u7b2c\u4e00\u4e2a\u793a\u4f8b\u76f8\u4f3c\uff0c\n\u9664\u4e86\u6211\u4eec\u4e0d\u80fd\u7701\u7565\u7b2c\u4e00\u4e2a\u5bf9\u62ec\u53f7\u6765\u4e2d\u65ad\u8f93\u5165\u548c\u8f93\u51fa\u4e4b\u95f4\u7684\u4e00\u5bf9\u4e00\u6620\u5c04\u5173\u7cfb\u3002\n
    \n", "tags_en": ["Tree", "String"], "tags_cn": ["\u6811", "\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n string tree2str(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public String tree2str(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def tree2str(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def tree2str(self, root: TreeNode) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nchar * tree2str(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public string Tree2str(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {string}\n */\nvar tree2str = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {String}\ndef tree2str(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func tree2str(_ root: TreeNode?) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc tree2str(root *TreeNode) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def tree2str(root: TreeNode): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun tree2str(root: TreeNode?): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn tree2str(root: Option>>) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return String\n */\n function tree2str($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction tree2str(root: TreeNode | null): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (tree2str root)\n (-> (or/c tree-node? #f) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0606](https://leetcode-cn.com/problems/construct-string-from-binary-tree)", "[\u6839\u636e\u4e8c\u53c9\u6811\u521b\u5efa\u5b57\u7b26\u4e32](/solution/0600-0699/0606.Construct%20String%20from%20Binary%20Tree/README.md)", "`\u6811`,`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0606](https://leetcode.com/problems/construct-string-from-binary-tree)", "[Construct String from Binary Tree](/solution/0600-0699/0606.Construct%20String%20from%20Binary%20Tree/README_EN.md)", "`Tree`,`String`", "Easy", ""]}, {"question_id": "0605", "frontend_question_id": "0605", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/can-place-flowers", "url_en": "https://leetcode.com/problems/can-place-flowers", "relative_path_cn": "/solution/0600-0699/0605.Can%20Place%20Flowers/README.md", "relative_path_en": "/solution/0600-0699/0605.Can%20Place%20Flowers/README_EN.md", "title_cn": "\u79cd\u82b1\u95ee\u9898", "title_en": "Can Place Flowers", "question_title_slug": "can-place-flowers", "content_en": "

    You have a long flowerbed in which some of the plots are planted, and some are not. However, flowers cannot be planted in adjacent plots.

    \n\n

    Given an integer array flowerbed containing 0's and 1's, where 0 means empty and 1 means not empty, and an integer n, return if n new flowers can be planted in the flowerbed without violating the no-adjacent-flowers rule.

    \n\n

     

    \n

    Example 1:

    \n
    Input: flowerbed = [1,0,0,0,1], n = 1\nOutput: true\n

    Example 2:

    \n
    Input: flowerbed = [1,0,0,0,1], n = 2\nOutput: false\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= flowerbed.length <= 2 * 104
    • \n\t
    • flowerbed[i] is 0 or 1.
    • \n\t
    • There are no two adjacent flowers in flowerbed.
    • \n\t
    • 0 <= n <= flowerbed.length
    • \n
    \n", "content_cn": "

    \u5047\u8bbe\u6709\u4e00\u4e2a\u5f88\u957f\u7684\u82b1\u575b\uff0c\u4e00\u90e8\u5206\u5730\u5757\u79cd\u690d\u4e86\u82b1\uff0c\u53e6\u4e00\u90e8\u5206\u5374\u6ca1\u6709\u3002\u53ef\u662f\uff0c\u82b1\u4e0d\u80fd\u79cd\u690d\u5728\u76f8\u90bb\u7684\u5730\u5757\u4e0a\uff0c\u5b83\u4eec\u4f1a\u4e89\u593a\u6c34\u6e90\uff0c\u4e24\u8005\u90fd\u4f1a\u6b7b\u53bb\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0\u00a0flowerbed \u8868\u793a\u82b1\u575b\uff0c\u7531\u82e5\u5e72 0 \u548c 1 \u7ec4\u6210\uff0c\u5176\u4e2d 0 \u8868\u793a\u6ca1\u79cd\u690d\u82b1\uff0c1 \u8868\u793a\u79cd\u690d\u4e86\u82b1\u3002\u53e6\u6709\u4e00\u4e2a\u6570\u00a0n \uff0c\u80fd\u5426\u5728\u4e0d\u6253\u7834\u79cd\u690d\u89c4\u5219\u7684\u60c5\u51b5\u4e0b\u79cd\u5165\u00a0n\u00a0\u6735\u82b1\uff1f\u80fd\u5219\u8fd4\u56de true \uff0c\u4e0d\u80fd\u5219\u8fd4\u56de false\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aflowerbed = [1,0,0,0,1], n = 1\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aflowerbed = [1,0,0,0,1], n = 2\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= flowerbed.length <= 2 * 104
    • \n\t
    • flowerbed[i] \u4e3a 0 \u6216 1
    • \n\t
    • flowerbed \u4e2d\u4e0d\u5b58\u5728\u76f8\u90bb\u7684\u4e24\u6735\u82b1
    • \n\t
    • 0 <= n <= flowerbed.length
    • \n
    \n", "tags_en": ["Greedy", "Array"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canPlaceFlowers(vector& flowerbed, int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canPlaceFlowers(int[] flowerbed, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canPlaceFlowers(self, flowerbed, n):\n \"\"\"\n :type flowerbed: List[int]\n :type n: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canPlaceFlowers(self, flowerbed: List[int], n: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canPlaceFlowers(int* flowerbed, int flowerbedSize, int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanPlaceFlowers(int[] flowerbed, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} flowerbed\n * @param {number} n\n * @return {boolean}\n */\nvar canPlaceFlowers = function(flowerbed, n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} flowerbed\n# @param {Integer} n\n# @return {Boolean}\ndef can_place_flowers(flowerbed, n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canPlaceFlowers(_ flowerbed: [Int], _ n: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canPlaceFlowers(flowerbed []int, n int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canPlaceFlowers(flowerbed: Array[Int], n: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canPlaceFlowers(flowerbed: IntArray, n: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_place_flowers(flowerbed: Vec, n: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $flowerbed\n * @param Integer $n\n * @return Boolean\n */\n function canPlaceFlowers($flowerbed, $n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canPlaceFlowers(flowerbed: number[], n: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-place-flowers flowerbed n)\n (-> (listof exact-integer?) exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0605](https://leetcode-cn.com/problems/can-place-flowers)", "[\u79cd\u82b1\u95ee\u9898](/solution/0600-0699/0605.Can%20Place%20Flowers/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0605](https://leetcode.com/problems/can-place-flowers)", "[Can Place Flowers](/solution/0600-0699/0605.Can%20Place%20Flowers/README_EN.md)", "`Greedy`,`Array`", "Easy", ""]}, {"question_id": "0604", "frontend_question_id": "0604", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/design-compressed-string-iterator", "url_en": "https://leetcode.com/problems/design-compressed-string-iterator", "relative_path_cn": "/solution/0600-0699/0604.Design%20Compressed%20String%20Iterator/README.md", "relative_path_en": "/solution/0600-0699/0604.Design%20Compressed%20String%20Iterator/README_EN.md", "title_cn": "\u8fed\u4ee3\u538b\u7f29\u5b57\u7b26\u4e32", "title_en": "Design Compressed String Iterator", "question_title_slug": "design-compressed-string-iterator", "content_en": "

    Design and implement a data structure for a compressed string iterator. The given compressed string will be in the form of each letter followed by a positive integer representing the number of this letter existing in the original uncompressed string.

    \n\n

    Implement the StringIterator class:

    \n\n
      \n\t
    • next() Returns the next character if the original string still has uncompressed characters, otherwise returns a white space.
    • \n\t
    • hasNext() Returns true if there is any letter needs to be uncompressed in the original string, otherwise returns false.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["StringIterator", "next", "next", "next", "next", "next", "next", "hasNext", "next", "hasNext"]\n[["L1e2t1C1o1d1e1"], [], [], [], [], [], [], [], [], []]\nOutput\n[null, "L", "e", "e", "t", "C", "o", true, "d", true]\n\nExplanation\nStringIterator stringIterator = new StringIterator("L1e2t1C1o1d1e1");\nstringIterator.next(); // return "L"\nstringIterator.next(); // return "e"\nstringIterator.next(); // return "e"\nstringIterator.next(); // return "t"\nstringIterator.next(); // return "C"\nstringIterator.next(); // return "o"\nstringIterator.hasNext(); // return True\nstringIterator.next(); // return "d"\nstringIterator.hasNext(); // return True\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= compressedString.length <= 1000
    • \n\t
    • compressedString consists of lower-case an upper-case English letters and digits.
    • \n\t
    • The number of a single character repetitions in compressedString is in the range [1, 10^9]
    • \n\t
    • At most 100 calls will be made to next and hasNext.
    • \n
    \n", "content_cn": "

    \u5bf9\u4e8e\u4e00\u4e2a\u538b\u7f29\u5b57\u7b26\u4e32\uff0c\u8bbe\u8ba1\u4e00\u4e2a\u6570\u636e\u7ed3\u6784\uff0c\u5b83\u652f\u6301\u5982\u4e0b\u4e24\u79cd\u64cd\u4f5c\uff1a next \u548c hasNext\u3002

    \n\n

    \u7ed9\u5b9a\u7684\u538b\u7f29\u5b57\u7b26\u4e32\u683c\u5f0f\u4e3a\uff1a\u6bcf\u4e2a\u5b57\u6bcd\u540e\u9762\u7d27\u8ddf\u4e00\u4e2a\u6b63\u6574\u6570\uff0c\u8fd9\u4e2a\u6574\u6570\u8868\u793a\u8be5\u5b57\u6bcd\u5728\u89e3\u538b\u540e\u7684\u5b57\u7b26\u4e32\u91cc\u8fde\u7eed\u51fa\u73b0\u7684\u6b21\u6570\u3002

    \n\n

    next() - \u5982\u679c\u538b\u7f29\u5b57\u7b26\u4e32\u4ecd\u7136\u6709\u5b57\u6bcd\u672a\u88ab\u89e3\u538b\uff0c\u5219\u8fd4\u56de\u4e0b\u4e00\u4e2a\u5b57\u6bcd\uff0c\u5426\u5219\u8fd4\u56de\u4e00\u4e2a\u7a7a\u683c\u3002
    \nhasNext() - \u5224\u65ad\u662f\u5426\u8fd8\u6709\u5b57\u6bcd\u4ecd\u7136\u6ca1\u88ab\u89e3\u538b\u3002

    \n\n

    \u6ce8\u610f\uff1a

    \n\n

    \u8bf7\u8bb0\u5f97\u5c06\u4f60\u7684\u7c7b\u5728 StringIterator \u4e2d \u521d\u59cb\u5316 \uff0c\u56e0\u4e3a\u9759\u6001\u53d8\u91cf\u6216\u7c7b\u53d8\u91cf\u5728\u591a\u7ec4\u6d4b\u8bd5\u6570\u636e\u4e2d\u4e0d\u4f1a\u88ab\u81ea\u52a8\u6e05\u7a7a\u3002\u66f4\u591a\u7ec6\u8282\u8bf7\u8bbf\u95ee \u8fd9\u91cc \u3002

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    StringIterator iterator = new StringIterator("L1e2t1C1o1d1e1");\n\niterator.next(); // \u8fd4\u56de 'L'\niterator.next(); // \u8fd4\u56de 'e'\niterator.next(); // \u8fd4\u56de 'e'\niterator.next(); // \u8fd4\u56de 't'\niterator.next(); // \u8fd4\u56de 'C'\niterator.next(); // \u8fd4\u56de 'o'\niterator.next(); // \u8fd4\u56de 'd'\niterator.hasNext(); // \u8fd4\u56de true\niterator.next(); // \u8fd4\u56de 'e'\niterator.hasNext(); // \u8fd4\u56de false\niterator.next(); // \u8fd4\u56de ' '\n
    \n\n

     

    \n", "tags_en": ["Design"], "tags_cn": ["\u8bbe\u8ba1"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class StringIterator {\npublic:\n StringIterator(string compressedString) {\n\n }\n \n char next() {\n\n }\n \n bool hasNext() {\n\n }\n};\n\n/**\n * Your StringIterator object will be instantiated and called as such:\n * StringIterator* obj = new StringIterator(compressedString);\n * char param_1 = obj->next();\n * bool param_2 = obj->hasNext();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class StringIterator {\n\n public StringIterator(String compressedString) {\n\n }\n \n public char next() {\n\n }\n \n public boolean hasNext() {\n\n }\n}\n\n/**\n * Your StringIterator object will be instantiated and called as such:\n * StringIterator obj = new StringIterator(compressedString);\n * char param_1 = obj.next();\n * boolean param_2 = obj.hasNext();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class StringIterator(object):\n\n def __init__(self, compressedString):\n \"\"\"\n :type compressedString: str\n \"\"\"\n\n\n def next(self):\n \"\"\"\n :rtype: str\n \"\"\"\n\n\n def hasNext(self):\n \"\"\"\n :rtype: bool\n \"\"\"\n\n\n\n# Your StringIterator object will be instantiated and called as such:\n# obj = StringIterator(compressedString)\n# param_1 = obj.next()\n# param_2 = obj.hasNext()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class StringIterator:\n\n def __init__(self, compressedString: str):\n\n\n def next(self) -> str:\n\n\n def hasNext(self) -> bool:\n\n\n\n# Your StringIterator object will be instantiated and called as such:\n# obj = StringIterator(compressedString)\n# param_1 = obj.next()\n# param_2 = obj.hasNext()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} StringIterator;\n\n\nStringIterator* stringIteratorCreate(char * compressedString) {\n \n}\n\nchar stringIteratorNext(StringIterator* obj) {\n \n}\n\nbool stringIteratorHasNext(StringIterator* obj) {\n \n}\n\nvoid stringIteratorFree(StringIterator* obj) {\n \n}\n\n/**\n * Your StringIterator struct will be instantiated and called as such:\n * StringIterator* obj = stringIteratorCreate(compressedString);\n * char param_1 = stringIteratorNext(obj);\n \n * bool param_2 = stringIteratorHasNext(obj);\n \n * stringIteratorFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class StringIterator {\n\n public StringIterator(string compressedString) {\n\n }\n \n public char Next() {\n\n }\n \n public bool HasNext() {\n\n }\n}\n\n/**\n * Your StringIterator object will be instantiated and called as such:\n * StringIterator obj = new StringIterator(compressedString);\n * char param_1 = obj.Next();\n * bool param_2 = obj.HasNext();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} compressedString\n */\nvar StringIterator = function(compressedString) {\n\n};\n\n/**\n * @return {character}\n */\nStringIterator.prototype.next = function() {\n\n};\n\n/**\n * @return {boolean}\n */\nStringIterator.prototype.hasNext = function() {\n\n};\n\n/**\n * Your StringIterator object will be instantiated and called as such:\n * var obj = new StringIterator(compressedString)\n * var param_1 = obj.next()\n * var param_2 = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class StringIterator\n\n=begin\n :type compressed_string: String\n=end\n def initialize(compressed_string)\n\n end\n\n\n=begin\n :rtype: Character\n=end\n def next()\n\n end\n\n\n=begin\n :rtype: Boolean\n=end\n def has_next()\n\n end\n\n\nend\n\n# Your StringIterator object will be instantiated and called as such:\n# obj = StringIterator.new(compressed_string)\n# param_1 = obj.next()\n# param_2 = obj.has_next()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass StringIterator {\n\n init(_ compressedString: String) {\n\n }\n \n func next() -> Character {\n\n }\n \n func hasNext() -> Bool {\n\n }\n}\n\n/**\n * Your StringIterator object will be instantiated and called as such:\n * let obj = StringIterator(compressedString)\n * let ret_1: Character = obj.next()\n * let ret_2: Bool = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type StringIterator struct {\n\n}\n\n\nfunc Constructor(compressedString string) StringIterator {\n\n}\n\n\nfunc (this *StringIterator) Next() byte {\n\n}\n\n\nfunc (this *StringIterator) HasNext() bool {\n\n}\n\n\n/**\n * Your StringIterator object will be instantiated and called as such:\n * obj := Constructor(compressedString);\n * param_1 := obj.Next();\n * param_2 := obj.HasNext();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class StringIterator(_compressedString: String) {\n\n def next(): Char = {\n\n }\n\n def hasNext(): Boolean = {\n\n }\n\n}\n\n/**\n * Your StringIterator object will be instantiated and called as such:\n * var obj = new StringIterator(compressedString)\n * var param_1 = obj.next()\n * var param_2 = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class StringIterator(compressedString: String) {\n\n fun next(): Char {\n\n }\n\n fun hasNext(): Boolean {\n\n }\n\n}\n\n/**\n * Your StringIterator object will be instantiated and called as such:\n * var obj = StringIterator(compressedString)\n * var param_1 = obj.next()\n * var param_2 = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct StringIterator {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl StringIterator {\n\n fn new(compressedString: String) -> Self {\n\n }\n \n fn next(&self) -> char {\n\n }\n \n fn has_next(&self) -> bool {\n\n }\n}\n\n/**\n * Your StringIterator object will be instantiated and called as such:\n * let obj = StringIterator::new(compressedString);\n * let ret_1: char = obj.next();\n * let ret_2: bool = obj.has_next();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class StringIterator {\n /**\n * @param String $compressedString\n */\n function __construct($compressedString) {\n\n }\n\n /**\n * @return String\n */\n function next() {\n\n }\n\n /**\n * @return Boolean\n */\n function hasNext() {\n\n }\n}\n\n/**\n * Your StringIterator object will be instantiated and called as such:\n * $obj = StringIterator($compressedString);\n * $ret_1 = $obj->next();\n * $ret_2 = $obj->hasNext();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class StringIterator {\n constructor(compressedString: string) {\n\n }\n\n next(): string {\n\n }\n\n hasNext(): boolean {\n\n }\n}\n\n/**\n * Your StringIterator object will be instantiated and called as such:\n * var obj = new StringIterator(compressedString)\n * var param_1 = obj.next()\n * var param_2 = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define string-iterator%\n (class object%\n (super-new)\n\n ; compressed-string : string?\n (init-field\n compressed-string)\n \n ; next : -> char?\n (define/public (next)\n\n )\n ; has-next : -> boolean?\n (define/public (has-next)\n\n )))\n\n;; Your string-iterator% object will be instantiated and called as such:\n;; (define obj (new string-iterator% [compressedString compressedString]))\n;; (define param_1 (send obj next))\n;; (define param_2 (send obj has-next))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0604](https://leetcode-cn.com/problems/design-compressed-string-iterator)", "[\u8fed\u4ee3\u538b\u7f29\u5b57\u7b26\u4e32](/solution/0600-0699/0604.Design%20Compressed%20String%20Iterator/README.md)", "`\u8bbe\u8ba1`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0604](https://leetcode.com/problems/design-compressed-string-iterator)", "[Design Compressed String Iterator](/solution/0600-0699/0604.Design%20Compressed%20String%20Iterator/README_EN.md)", "`Design`", "Easy", "\ud83d\udd12"]}, {"question_id": "0603", "frontend_question_id": "0603", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/consecutive-available-seats", "url_en": "https://leetcode.com/problems/consecutive-available-seats", "relative_path_cn": "/solution/0600-0699/0603.Consecutive%20Available%20Seats/README.md", "relative_path_en": "/solution/0600-0699/0603.Consecutive%20Available%20Seats/README_EN.md", "title_cn": "\u8fde\u7eed\u7a7a\u4f59\u5ea7\u4f4d", "title_en": "Consecutive Available Seats", "question_title_slug": "consecutive-available-seats", "content_en": "Several friends at a cinema ticket office would like to reserve consecutive available seats.
    \r\nCan you help to query all the consecutive available seats order by the seat_id using the following cinema table?\r\n
    \r\n| seat_id | free |\r\n|---------|------|\r\n| 1       | 1    |\r\n| 2       | 0    |\r\n| 3       | 1    |\r\n| 4       | 1    |\r\n| 5       | 1    |\r\n
    \r\n\r\n

     

    \r\nYour query should return the following result for the sample case above.\r\n\r\n

     

    \r\n\r\n
    \r\n| seat_id |\r\n|---------|\r\n| 3       |\r\n| 4       |\r\n| 5       |\r\n
    \r\nNote:\r\n\r\n
      \r\n\t
    • The seat_id is an auto increment int, and free is bool ('1' means free, and '0' means occupied.).
    • \r\n\t
    • Consecutive available seats are more than 2(inclusive) seats consecutively available.
    • \r\n
    \r\n", "content_cn": "

    \u51e0\u4e2a\u670b\u53cb\u6765\u5230\u7535\u5f71\u9662\u7684\u552e\u7968\u5904\uff0c\u51c6\u5907\u9884\u7ea6\u8fde\u7eed\u7a7a\u4f59\u5ea7\u4f4d\u3002

    \n\n

    \u4f60\u80fd\u5229\u7528\u8868 cinema \uff0c\u5e2e\u4ed6\u4eec\u5199\u4e00\u4e2a\u67e5\u8be2\u8bed\u53e5\uff0c\u83b7\u53d6\u6240\u6709\u7a7a\u4f59\u5ea7\u4f4d\uff0c\u5e76\u5c06\u5b83\u4eec\u6309\u7167 seat_id \u6392\u5e8f\u540e\u8fd4\u56de\u5417\uff1f

    \n\n
    | seat_id | free |\n|---------|------|\n| 1       | 1    |\n| 2       | 0    |\n| 3       | 1    |\n| 4       | 1    |\n| 5       | 1    |\n
    \n\n

     

    \n\n

    \u5bf9\u4e8e\u5982\u4e0a\u6837\u4f8b\uff0c\u4f60\u7684\u67e5\u8be2\u8bed\u53e5\u5e94\u8be5\u8fd4\u56de\u5982\u4e0b\u7ed3\u679c\u3002

    \n\n

     

    \n\n
    | seat_id |\n|---------|\n| 3       |\n| 4       |\n| 5       |\n
    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    • seat_id \u5b57\u6bb5\u662f\u4e00\u4e2a\u81ea\u589e\u7684\u6574\u6570\uff0cfree \u5b57\u6bb5\u662f\u5e03\u5c14\u7c7b\u578b\uff08'1' \u8868\u793a\u7a7a\u4f59\uff0c '0' \u8868\u793a\u5df2\u88ab\u5360\u636e\uff09\u3002
    • \n\t
    • \u8fde\u7eed\u7a7a\u4f59\u5ea7\u4f4d\u7684\u5b9a\u4e49\u662f\u5927\u4e8e\u7b49\u4e8e 2 \u4e2a\u8fde\u7eed\u7a7a\u4f59\u7684\u5ea7\u4f4d\u3002
    • \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0603](https://leetcode-cn.com/problems/consecutive-available-seats)", "[\u8fde\u7eed\u7a7a\u4f59\u5ea7\u4f4d](/solution/0600-0699/0603.Consecutive%20Available%20Seats/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0603](https://leetcode.com/problems/consecutive-available-seats)", "[Consecutive Available Seats](/solution/0600-0699/0603.Consecutive%20Available%20Seats/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "0602", "frontend_question_id": "0602", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/friend-requests-ii-who-has-the-most-friends", "url_en": "https://leetcode.com/problems/friend-requests-ii-who-has-the-most-friends", "relative_path_cn": "/solution/0600-0699/0602.Friend%20Requests%20II%20Who%20Has%20the%20Most%20Friends/README.md", "relative_path_en": "/solution/0600-0699/0602.Friend%20Requests%20II%20Who%20Has%20the%20Most%20Friends/README_EN.md", "title_cn": "\u597d\u53cb\u7533\u8bf7 II \uff1a\u8c01\u6709\u6700\u591a\u7684\u597d\u53cb", "title_en": "Friend Requests II Who Has the Most Friends", "question_title_slug": "friend-requests-ii-who-has-the-most-friends", "content_en": "

    In social network like Facebook or Twitter, people send friend requests and accept others' requests as well.

    \n\n

     

    \n\n

    Table request_accepted

    \n\n
    \n+--------------+-------------+------------+\n| requester_id | accepter_id | accept_date|\n|--------------|-------------|------------|\n| 1            | 2           | 2016_06-03 |\n| 1            | 3           | 2016-06-08 |\n| 2            | 3           | 2016-06-08 |\n| 3            | 4           | 2016-06-09 |\n+--------------+-------------+------------+\nThis table holds the data of friend acceptance, while requester_id and accepter_id both are the id of a person.\n
    \n\n

     

    \n\n

    Write a query to find the the people who has most friends and the most friends number under the following rules:

    \n\n
      \n\t
    • It is guaranteed there is only 1 people having the most friends.
    • \n\t
    • The friend request could only been accepted once, which mean there is no multiple records with the same requester_id and accepter_id value.
    • \n
    \n\n

    For the sample data above, the result is:

    \n\n
    \nResult table:\n+------+------+\n| id   | num  |\n|------|------|\n| 3    | 3    |\n+------+------+\nThe person with id '3' is a friend of people '1', '2' and '4', so he has 3 friends in total, which is the most number than any others.\n
    \n\n

    Follow-up:
    \nIn the real world, multiple people could have the same most number of friends, can you find all these people in this case?

    \n", "content_cn": "

    \u5728 Facebook \u6216\u8005 Twitter \u8fd9\u6837\u7684\u793e\u4ea4\u5e94\u7528\u4e2d\uff0c\u4eba\u4eec\u7ecf\u5e38\u4f1a\u53d1\u597d\u53cb\u7533\u8bf7\u4e5f\u4f1a\u6536\u5230\u5176\u4ed6\u4eba\u7684\u597d\u53cb\u7533\u8bf7\u3002

    \n\n

     

    \n\n

    \u8868 request_accepted \u5b58\u50a8\u4e86\u6240\u6709\u597d\u53cb\u7533\u8bf7\u901a\u8fc7\u7684\u6570\u636e\u8bb0\u5f55\uff0c\u5176\u4e2d\uff0c requester_id \u548c accepter_id \u90fd\u662f\u7528\u6237\u7684\u7f16\u53f7\u3002

    \n\n

     

    \n\n
    | requester_id | accepter_id | accept_date|\n|--------------|-------------|------------|\n| 1            | 2           | 2016_06-03 |\n| 1            | 3           | 2016-06-08 |\n| 2            | 3           | 2016-06-08 |\n| 3            | 4           | 2016-06-09 |\n
    \n\n

    \u5199\u4e00\u4e2a\u67e5\u8be2\u8bed\u53e5\uff0c\u6c42\u51fa\u8c01\u62e5\u6709\u6700\u591a\u7684\u597d\u53cb\u548c\u4ed6\u62e5\u6709\u7684\u597d\u53cb\u6570\u76ee\u3002\u5bf9\u4e8e\u4e0a\u9762\u7684\u6837\u4f8b\u6570\u636e\uff0c\u7ed3\u679c\u4e3a\uff1a

    \n\n
    | id | num |\n|----|-----|\n| 3  | 3   |\n
    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    • \u4fdd\u8bc1\u62e5\u6709\u6700\u591a\u597d\u53cb\u6570\u76ee\u7684\u53ea\u6709 1 \u4e2a\u4eba\u3002
    • \n\t
    • \u597d\u53cb\u7533\u8bf7\u53ea\u4f1a\u88ab\u63a5\u53d7\u4e00\u6b21\uff0c\u6240\u4ee5\u4e0d\u4f1a\u6709 requester_id \u548c accepter_id \u503c\u90fd\u76f8\u540c\u7684\u91cd\u590d\u8bb0\u5f55\u3002
    • \n
    \n\n

     

    \n\n

    \u89e3\u91ca\uff1a

    \n\n

    \u7f16\u53f7\u4e3a '3' \u7684\u4eba\u662f\u7f16\u53f7\u4e3a '1'\uff0c'2' \u548c '4' \u7684\u597d\u53cb\uff0c\u6240\u4ee5\u4ed6\u603b\u5171\u6709 3 \u4e2a\u597d\u53cb\uff0c\u6bd4\u5176\u4ed6\u4eba\u90fd\u591a\u3002

    \n\n

     

    \n\n

    \u8fdb\u9636\uff1a

    \n\n

    \u5728\u771f\u5b9e\u4e16\u754c\u91cc\uff0c\u53ef\u80fd\u4f1a\u6709\u591a\u4e2a\u4eba\u62e5\u6709\u597d\u53cb\u6570\u76f8\u540c\u4e14\u6700\u591a\uff0c\u4f60\u80fd\u627e\u5230\u6240\u6709\u8fd9\u4e9b\u4eba\u5417\uff1f

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0602](https://leetcode-cn.com/problems/friend-requests-ii-who-has-the-most-friends)", "[\u597d\u53cb\u7533\u8bf7 II \uff1a\u8c01\u6709\u6700\u591a\u7684\u597d\u53cb](/solution/0600-0699/0602.Friend%20Requests%20II%20Who%20Has%20the%20Most%20Friends/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0602](https://leetcode.com/problems/friend-requests-ii-who-has-the-most-friends)", "[Friend Requests II Who Has the Most Friends](/solution/0600-0699/0602.Friend%20Requests%20II%20Who%20Has%20the%20Most%20Friends/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "0601", "frontend_question_id": "0601", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/human-traffic-of-stadium", "url_en": "https://leetcode.com/problems/human-traffic-of-stadium", "relative_path_cn": "/solution/0600-0699/0601.Human%20Traffic%20of%20Stadium/README.md", "relative_path_en": "/solution/0600-0699/0601.Human%20Traffic%20of%20Stadium/README_EN.md", "title_cn": "\u4f53\u80b2\u9986\u7684\u4eba\u6d41\u91cf", "title_en": "Human Traffic of Stadium", "question_title_slug": "human-traffic-of-stadium", "content_en": "

    Table: Stadium

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| visit_date    | date    |\n| people        | int     |\n+---------------+---------+\nvisit_date is the primary key for this table.\nEach row of this table contains the visit date and visit id to the stadium with the number of people during the visit.\nNo two rows will have the same visit_date, and as the id increases, the dates increase as well.\n
    \n\n

     

    \n\n

    Write an SQL query to display the records with three or more rows with consecutive id's, and the number of people is greater than or equal to 100 for each.

    \n\n

    Return the result table ordered by visit_date in ascending order.

    \n\n

    The query result format is in the following example.

    \n\n

     

    \n\n
    \nStadium table:\n+------+------------+-----------+\n| id   | visit_date | people    |\n+------+------------+-----------+\n| 1    | 2017-01-01 | 10        |\n| 2    | 2017-01-02 | 109       |\n| 3    | 2017-01-03 | 150       |\n| 4    | 2017-01-04 | 99        |\n| 5    | 2017-01-05 | 145       |\n| 6    | 2017-01-06 | 1455      |\n| 7    | 2017-01-07 | 199       |\n| 8    | 2017-01-09 | 188       |\n+------+------------+-----------+\n\nResult table:\n+------+------------+-----------+\n| id   | visit_date | people    |\n+------+------------+-----------+\n| 5    | 2017-01-05 | 145       |\n| 6    | 2017-01-06 | 1455      |\n| 7    | 2017-01-07 | 199       |\n| 8    | 2017-01-09 | 188       |\n+------+------------+-----------+\nThe four rows with ids 5, 6, 7, and 8 have consecutive ids and each of them has >= 100 people attended. Note that row 8 was included even though the visit_date was not the next day after row 7.\nThe rows with ids 2 and 3 are not included because we need at least three consecutive ids.
    \n", "content_cn": "\u8868\uff1aStadium\n
    \n
    \n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| visit_date    | date    |\n| people        | int     |\n+---------------+---------+\nvisit_date \u662f\u8868\u7684\u4e3b\u952e\n\u6bcf\u65e5\u4eba\u6d41\u91cf\u4fe1\u606f\u88ab\u8bb0\u5f55\u5728\u8fd9\u4e09\u5217\u4fe1\u606f\u4e2d\uff1a\u5e8f\u53f7 (id)\u3001\u65e5\u671f (visit_date)\u3001\u00a0\u4eba\u6d41\u91cf (people)\n\u6bcf\u5929\u53ea\u6709\u4e00\u884c\u8bb0\u5f55\uff0c\u65e5\u671f\u968f\u7740 id \u7684\u589e\u52a0\u800c\u589e\u52a0\n
    \n\n

    \u00a0

    \n\n

    \u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\u4ee5\u627e\u51fa\u6bcf\u884c\u7684\u4eba\u6570\u5927\u4e8e\u6216\u7b49\u4e8e 100 \u4e14 id \u8fde\u7eed\u7684\u4e09\u884c\u6216\u66f4\u591a\u884c\u8bb0\u5f55\u3002

    \n\n

    \u8fd4\u56de\u6309 visit_date \u5347\u5e8f\u6392\u5217\u7684\u7ed3\u679c\u8868\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u6240\u793a\u3002

    \n\n
    \nStadium table:\n+------+------------+-----------+\n| id   | visit_date | people    |\n+------+------------+-----------+\n| 1    | 2017-01-01 | 10        |\n| 2    | 2017-01-02 | 109       |\n| 3    | 2017-01-03 | 150       |\n| 4    | 2017-01-04 | 99        |\n| 5    | 2017-01-05 | 145       |\n| 6    | 2017-01-06 | 1455      |\n| 7    | 2017-01-07 | 199       |\n| 8    | 2017-01-09 | 188       |\n+------+------------+-----------+\n\nResult table:\n+------+------------+-----------+\n| id   | visit_date | people    |\n+------+------------+-----------+\n| 5    | 2017-01-05 | 145       |\n| 6    | 2017-01-06 | 1455      |\n| 7    | 2017-01-07 | 199       |\n| 8    | 2017-01-09 | 188       |\n+------+------------+-----------+\nid \u4e3a 5\u30016\u30017\u30018 \u7684\u56db\u884c id \u8fde\u7eed\uff0c\u5e76\u4e14\u6bcf\u884c\u90fd\u6709 >= 100 \u7684\u4eba\u6570\u8bb0\u5f55\u3002\n\u8bf7\u6ce8\u610f\uff0c\u5373\u4f7f\u7b2c 7 \u884c\u548c\u7b2c 8 \u884c\u7684 visit_date \u4e0d\u662f\u8fde\u7eed\u7684\uff0c\u8f93\u51fa\u4e5f\u5e94\u5f53\u5305\u542b\u7b2c 8 \u884c\uff0c\u56e0\u4e3a\u6211\u4eec\u53ea\u9700\u8981\u8003\u8651 id \u8fde\u7eed\u7684\u8bb0\u5f55\u3002\n\u4e0d\u8f93\u51fa id \u4e3a 2 \u548c 3 \u7684\u884c\uff0c\u56e0\u4e3a\u81f3\u5c11\u9700\u8981\u4e09\u6761 id \u8fde\u7eed\u7684\u8bb0\u5f55\u3002\n
    \n
    \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0601](https://leetcode-cn.com/problems/human-traffic-of-stadium)", "[\u4f53\u80b2\u9986\u7684\u4eba\u6d41\u91cf](/solution/0600-0699/0601.Human%20Traffic%20of%20Stadium/README.md)", "", "\u56f0\u96be", ""], "md_table_row_en": ["[0601](https://leetcode.com/problems/human-traffic-of-stadium)", "[Human Traffic of Stadium](/solution/0600-0699/0601.Human%20Traffic%20of%20Stadium/README_EN.md)", "", "Hard", ""]}, {"question_id": "0600", "frontend_question_id": "0600", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/non-negative-integers-without-consecutive-ones", "url_en": "https://leetcode.com/problems/non-negative-integers-without-consecutive-ones", "relative_path_cn": "/solution/0600-0699/0600.Non-negative%20Integers%20without%20Consecutive%20Ones/README.md", "relative_path_en": "/solution/0600-0699/0600.Non-negative%20Integers%20without%20Consecutive%20Ones/README_EN.md", "title_cn": "\u4e0d\u542b\u8fde\u7eed1\u7684\u975e\u8d1f\u6574\u6570", "title_en": "Non-negative Integers without Consecutive Ones", "question_title_slug": "non-negative-integers-without-consecutive-ones", "content_en": "

    Given a positive integer n, return the number of the integers in the range [0, n] whose binary representations do not contain consecutive ones.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 5\nOutput: 5\nExplanation:\nHere are the non-negative integers <= 5 with their corresponding binary representations:\n0 : 0\n1 : 1\n2 : 10\n3 : 11\n4 : 100\n5 : 101\nAmong them, only integer 3 disobeys the rule (two consecutive ones) and the other 5 satisfy the rule. \n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 1\nOutput: 2\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 2\nOutput: 3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6b63\u6574\u6570 n\uff0c\u627e\u51fa\u5c0f\u4e8e\u6216\u7b49\u4e8e n \u7684\u975e\u8d1f\u6574\u6570\u4e2d\uff0c\u5176\u4e8c\u8fdb\u5236\u8868\u793a\u4e0d\u5305\u542b \u8fde\u7eed\u76841 \u7684\u4e2a\u6570\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: 5\n\u8f93\u51fa: 5\n\u89e3\u91ca: \n\u4e0b\u9762\u662f\u5e26\u6709\u76f8\u5e94\u4e8c\u8fdb\u5236\u8868\u793a\u7684\u975e\u8d1f\u6574\u6570<= 5\uff1a\n0 : 0\n1 : 1\n2 : 10\n3 : 11\n4 : 100\n5 : 101\n\u5176\u4e2d\uff0c\u53ea\u6709\u6574\u65703\u8fdd\u53cd\u89c4\u5219\uff08\u6709\u4e24\u4e2a\u8fde\u7eed\u76841\uff09\uff0c\u5176\u4ed65\u4e2a\u6ee1\u8db3\u89c4\u5219\u3002
    \n\n

    \u8bf4\u660e: 1 <= n <= 109

    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findIntegers(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findIntegers(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findIntegers(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findIntegers(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findIntegers(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindIntegers(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar findIntegers = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef find_integers(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findIntegers(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findIntegers(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findIntegers(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findIntegers(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_integers(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function findIntegers($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findIntegers(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-integers n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0600](https://leetcode-cn.com/problems/non-negative-integers-without-consecutive-ones)", "[\u4e0d\u542b\u8fde\u7eed1\u7684\u975e\u8d1f\u6574\u6570](/solution/0600-0699/0600.Non-negative%20Integers%20without%20Consecutive%20Ones/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0600](https://leetcode.com/problems/non-negative-integers-without-consecutive-ones)", "[Non-negative Integers without Consecutive Ones](/solution/0600-0699/0600.Non-negative%20Integers%20without%20Consecutive%20Ones/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "0599", "frontend_question_id": "0599", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-index-sum-of-two-lists", "url_en": "https://leetcode.com/problems/minimum-index-sum-of-two-lists", "relative_path_cn": "/solution/0500-0599/0599.Minimum%20Index%20Sum%20of%20Two%20Lists/README.md", "relative_path_en": "/solution/0500-0599/0599.Minimum%20Index%20Sum%20of%20Two%20Lists/README_EN.md", "title_cn": "\u4e24\u4e2a\u5217\u8868\u7684\u6700\u5c0f\u7d22\u5f15\u603b\u548c", "title_en": "Minimum Index Sum of Two Lists", "question_title_slug": "minimum-index-sum-of-two-lists", "content_en": "

    Suppose Andy and Doris want to choose a restaurant for dinner, and they both have a list of favorite restaurants represented by strings.

    \n\n

    You need to help them find out their common interest with the least list index sum. If there is a choice tie between answers, output all of them with no order requirement. You could assume there always exists an answer.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: list1 = ["Shogun","Tapioca Express","Burger King","KFC"], list2 = ["Piatti","The Grill at Torrey Pines","Hungry Hunter Steakhouse","Shogun"]\nOutput: ["Shogun"]\nExplanation: The only restaurant they both like is "Shogun".\n
    \n\n

    Example 2:

    \n\n
    \nInput: list1 = ["Shogun","Tapioca Express","Burger King","KFC"], list2 = ["KFC","Shogun","Burger King"]\nOutput: ["Shogun"]\nExplanation: The restaurant they both like and have the least index sum is "Shogun" with index sum 1 (0+1).\n
    \n\n

    Example 3:

    \n\n
    \nInput: list1 = ["Shogun","Tapioca Express","Burger King","KFC"], list2 = ["KFC","Burger King","Tapioca Express","Shogun"]\nOutput: ["KFC","Burger King","Tapioca Express","Shogun"]\n
    \n\n

    Example 4:

    \n\n
    \nInput: list1 = ["Shogun","Tapioca Express","Burger King","KFC"], list2 = ["KNN","KFC","Burger King","Tapioca Express","Shogun"]\nOutput: ["KFC","Burger King","Tapioca Express","Shogun"]\n
    \n\n

    Example 5:

    \n\n
    \nInput: list1 = ["KFC"], list2 = ["KFC"]\nOutput: ["KFC"]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= list1.length, list2.length <= 1000
    • \n\t
    • 1 <= list1[i].length, list2[i].length <= 30
    • \n\t
    • list1[i] and list2[i] consist of spaces ' ' and English letters.
    • \n\t
    • All the stings of list1 are unique.
    • \n\t
    • All the stings of list2 are unique.
    • \n
    \n", "content_cn": "

    \u5047\u8bbeAndy\u548cDoris\u60f3\u5728\u665a\u9910\u65f6\u9009\u62e9\u4e00\u5bb6\u9910\u5385\uff0c\u5e76\u4e14\u4ed6\u4eec\u90fd\u6709\u4e00\u4e2a\u8868\u793a\u6700\u559c\u7231\u9910\u5385\u7684\u5217\u8868\uff0c\u6bcf\u4e2a\u9910\u5385\u7684\u540d\u5b57\u7528\u5b57\u7b26\u4e32\u8868\u793a\u3002

    \n\n

    \u4f60\u9700\u8981\u5e2e\u52a9\u4ed6\u4eec\u7528\u6700\u5c11\u7684\u7d22\u5f15\u548c\u627e\u51fa\u4ed6\u4eec\u5171\u540c\u559c\u7231\u7684\u9910\u5385\u3002 \u5982\u679c\u7b54\u6848\u4e0d\u6b62\u4e00\u4e2a\uff0c\u5219\u8f93\u51fa\u6240\u6709\u7b54\u6848\u5e76\u4e14\u4e0d\u8003\u8651\u987a\u5e8f\u3002 \u4f60\u53ef\u4ee5\u5047\u8bbe\u603b\u662f\u5b58\u5728\u4e00\u4e2a\u7b54\u6848\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165:\n["Shogun", "Tapioca Express", "Burger King", "KFC"]\n["Piatti", "The Grill at Torrey Pines", "Hungry Hunter Steakhouse", "Shogun"]\n\u8f93\u51fa: ["Shogun"]\n\u89e3\u91ca: \u4ed6\u4eec\u552f\u4e00\u5171\u540c\u559c\u7231\u7684\u9910\u5385\u662f“Shogun”\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165:\n["Shogun", "Tapioca Express", "Burger King", "KFC"]\n["KFC", "Shogun", "Burger King"]\n\u8f93\u51fa: ["Shogun"]\n\u89e3\u91ca: \u4ed6\u4eec\u5171\u540c\u559c\u7231\u4e14\u5177\u6709\u6700\u5c0f\u7d22\u5f15\u548c\u7684\u9910\u5385\u662f“Shogun”\uff0c\u5b83\u6709\u6700\u5c0f\u7684\u7d22\u5f15\u548c1(0+1)\u3002\n
    \n\n

    \u63d0\u793a:

    \n\n
      \n\t
    1. \u4e24\u4e2a\u5217\u8868\u7684\u957f\u5ea6\u8303\u56f4\u90fd\u5728 [1, 1000]\u5185\u3002
    2. \n\t
    3. \u4e24\u4e2a\u5217\u8868\u4e2d\u7684\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u5c06\u5728[1\uff0c30]\u7684\u8303\u56f4\u5185\u3002
    4. \n\t
    5. \u4e0b\u6807\u4ece0\u5f00\u59cb\uff0c\u5230\u5217\u8868\u7684\u957f\u5ea6\u51cf1\u3002
    6. \n\t
    7. \u4e24\u4e2a\u5217\u8868\u90fd\u6ca1\u6709\u91cd\u590d\u7684\u5143\u7d20\u3002
    8. \n
    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findRestaurant(vector& list1, vector& list2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String[] findRestaurant(String[] list1, String[] list2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findRestaurant(self, list1, list2):\n \"\"\"\n :type list1: List[str]\n :type list2: List[str]\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findRestaurant(self, list1: List[str], list2: List[str]) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** findRestaurant(char ** list1, int list1Size, char ** list2, int list2Size, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string[] FindRestaurant(string[] list1, string[] list2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} list1\n * @param {string[]} list2\n * @return {string[]}\n */\nvar findRestaurant = function(list1, list2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} list1\n# @param {String[]} list2\n# @return {String[]}\ndef find_restaurant(list1, list2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findRestaurant(_ list1: [String], _ list2: [String]) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findRestaurant(list1 []string, list2 []string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findRestaurant(list1: Array[String], list2: Array[String]): Array[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findRestaurant(list1: Array, list2: Array): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_restaurant(list1: Vec, list2: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $list1\n * @param String[] $list2\n * @return String[]\n */\n function findRestaurant($list1, $list2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findRestaurant(list1: string[], list2: string[]): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-restaurant list1 list2)\n (-> (listof string?) (listof string?) (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0599](https://leetcode-cn.com/problems/minimum-index-sum-of-two-lists)", "[\u4e24\u4e2a\u5217\u8868\u7684\u6700\u5c0f\u7d22\u5f15\u603b\u548c](/solution/0500-0599/0599.Minimum%20Index%20Sum%20of%20Two%20Lists/README.md)", "`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0599](https://leetcode.com/problems/minimum-index-sum-of-two-lists)", "[Minimum Index Sum of Two Lists](/solution/0500-0599/0599.Minimum%20Index%20Sum%20of%20Two%20Lists/README_EN.md)", "`Hash Table`", "Easy", ""]}, {"question_id": "0598", "frontend_question_id": "0598", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/range-addition-ii", "url_en": "https://leetcode.com/problems/range-addition-ii", "relative_path_cn": "/solution/0500-0599/0598.Range%20Addition%20II/README.md", "relative_path_en": "/solution/0500-0599/0598.Range%20Addition%20II/README_EN.md", "title_cn": "\u8303\u56f4\u6c42\u548c II", "title_en": "Range Addition II", "question_title_slug": "range-addition-ii", "content_en": "

    You are given an m x n matrix M initialized with all 0's and an array of operations ops, where ops[i] = [ai, bi] means M[x][y] should be incremented by one for all 0 <= x < ai and 0 <= y < bi.

    \n\n

    Count and return the number of maximum integers in the matrix after performing all the operations.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: m = 3, n = 3, ops = [[2,2],[3,3]]\nOutput: 4\nExplanation: The maximum integer in M is 2, and there are four of it in M. So return 4.\n
    \n\n

    Example 2:

    \n\n
    \nInput: m = 3, n = 3, ops = [[2,2],[3,3],[3,3],[3,3],[2,2],[3,3],[3,3],[3,3],[2,2],[3,3],[3,3],[3,3]]\nOutput: 4\n
    \n\n

    Example 3:

    \n\n
    \nInput: m = 3, n = 3, ops = []\nOutput: 9\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= m, n <= 4 * 104
    • \n\t
    • 1 <= ops.length <= 104
    • \n\t
    • ops[i].length == 2
    • \n\t
    • 1 <= ai <= m
    • \n\t
    • 1 <= bi <= n
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u521d\u59cb\u5143\u7d20\u5168\u90e8\u4e3a 0\uff0c\u5927\u5c0f\u4e3a m*n \u7684\u77e9\u9635 \u4ee5\u53ca\u5728 \u4e0a\u7684\u4e00\u7cfb\u5217\u66f4\u65b0\u64cd\u4f5c\u3002

    \n\n

    \u64cd\u4f5c\u7528\u4e8c\u7ef4\u6570\u7ec4\u8868\u793a\uff0c\u5176\u4e2d\u7684\u6bcf\u4e2a\u64cd\u4f5c\u7528\u4e00\u4e2a\u542b\u6709\u4e24\u4e2a\u6b63\u6574\u6570 a \u548c b \u7684\u6570\u7ec4\u8868\u793a\uff0c\u542b\u4e49\u662f\u5c06\u6240\u6709\u7b26\u5408 0 <= i < a \u4ee5\u53ca 0 <= j < b \u7684\u5143\u7d20 M[i][j] \u7684\u503c\u90fd\u589e\u52a0 1\u3002

    \n\n

    \u5728\u6267\u884c\u7ed9\u5b9a\u7684\u4e00\u7cfb\u5217\u64cd\u4f5c\u540e\uff0c\u4f60\u9700\u8981\u8fd4\u56de\u77e9\u9635\u4e2d\u542b\u6709\u6700\u5927\u6574\u6570\u7684\u5143\u7d20\u4e2a\u6570\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: \nm = 3, n = 3\noperations = [[2,2],[3,3]]\n\u8f93\u51fa: 4\n\u89e3\u91ca: \n\u521d\u59cb\u72b6\u6001, M = \n[[0, 0, 0],\n [0, 0, 0],\n [0, 0, 0]]\n\n\u6267\u884c\u5b8c\u64cd\u4f5c [2,2] \u540e, M = \n[[1, 1, 0],\n [1, 1, 0],\n [0, 0, 0]]\n\n\u6267\u884c\u5b8c\u64cd\u4f5c [3,3] \u540e, M = \n[[2, 2, 1],\n [2, 2, 1],\n [1, 1, 1]]\n\nM \u4e2d\u6700\u5927\u7684\u6574\u6570\u662f 2, \u800c\u4e14 M \u4e2d\u67094\u4e2a\u503c\u4e3a2\u7684\u5143\u7d20\u3002\u56e0\u6b64\u8fd4\u56de 4\u3002\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. m \u548c n \u7684\u8303\u56f4\u662f [1,40000]\u3002
    2. \n\t
    3. a \u7684\u8303\u56f4\u662f [1,m]\uff0cb \u7684\u8303\u56f4\u662f [1,n]\u3002
    4. \n\t
    5. \u64cd\u4f5c\u6570\u76ee\u4e0d\u8d85\u8fc7 10000\u3002
    6. \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxCount(int m, int n, vector>& ops) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxCount(int m, int n, int[][] ops) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxCount(self, m, n, ops):\n \"\"\"\n :type m: int\n :type n: int\n :type ops: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxCount(int m, int n, int** ops, int opsSize, int* opsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxCount(int m, int n, int[][] ops) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} m\n * @param {number} n\n * @param {number[][]} ops\n * @return {number}\n */\nvar maxCount = function(m, n, ops) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} m\n# @param {Integer} n\n# @param {Integer[][]} ops\n# @return {Integer}\ndef max_count(m, n, ops)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxCount(_ m: Int, _ n: Int, _ ops: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxCount(m int, n int, ops [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxCount(m: Int, n: Int, ops: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxCount(m: Int, n: Int, ops: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_count(m: i32, n: i32, ops: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $m\n * @param Integer $n\n * @param Integer[][] $ops\n * @return Integer\n */\n function maxCount($m, $n, $ops) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxCount(m: number, n: number, ops: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-count m n ops)\n (-> exact-integer? exact-integer? (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0598](https://leetcode-cn.com/problems/range-addition-ii)", "[\u8303\u56f4\u6c42\u548c II](/solution/0500-0599/0598.Range%20Addition%20II/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0598](https://leetcode.com/problems/range-addition-ii)", "[Range Addition II](/solution/0500-0599/0598.Range%20Addition%20II/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "0597", "frontend_question_id": "0597", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/friend-requests-i-overall-acceptance-rate", "url_en": "https://leetcode.com/problems/friend-requests-i-overall-acceptance-rate", "relative_path_cn": "/solution/0500-0599/0597.Friend%20Requests%20I%20Overall%20Acceptance%20Rate/README.md", "relative_path_en": "/solution/0500-0599/0597.Friend%20Requests%20I%20Overall%20Acceptance%20Rate/README_EN.md", "title_cn": "\u597d\u53cb\u7533\u8bf7 I\uff1a\u603b\u4f53\u901a\u8fc7\u7387", "title_en": "Friend Requests I Overall Acceptance Rate", "question_title_slug": "friend-requests-i-overall-acceptance-rate", "content_en": "

    Table: FriendRequest

    \n\n
    \n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| sender_id      | int     |\n| send_to_id     | int     |\n| request_date   | date    |\n+----------------+---------+\nThere is no primary key for this table, it may contain duplicates.\nThis table contains the ID of the user who sent the request, the ID of the user who received the request, and the date of the request.\n
    \n\n

     

    \n\n

    Table: RequestAccepted

    \n\n
    \n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| requester_id   | int     |\n| accepter_id    | int     |\n| accept_date    | date    |\n+----------------+---------+\nThere is no primary key for this table, it may contain duplicates.\nThis table contains the ID of the user who sent the request, the ID of the user who received the request, and the date when the request was accepted.\n
    \n\n

     

    \n\n

    Write an SQL query to find the overall acceptance rate of requests, which is the number of acceptance divided by the number of requests. Return the answer rounded to 2 decimals places.

    \n\n

    Note that:

    \n\n
      \n\t
    • The accepted requests are not necessarily from the table friend_request. In this case, you just need to simply count the total accepted requests (no matter whether they are in the original requests), and divide it by the number of requests to get the acceptance rate.
    • \n\t
    • It is possible that a sender sends multiple requests to the same receiver, and a request could be accepted more than once. In this case, the ‘duplicated’ requests or acceptances are only counted once.
    • \n\t
    • If there are no requests at all, you should return 0.00 as the accept_rate.
    • \n
    \n\n

    The query result format is in the following example:

    \n\n

     

    \n\n
    \nFriendRequest table:\n+-----------+------------+--------------+\n| sender_id | send_to_id | request_date |\n+-----------+------------+--------------+\n| 1         | 2          | 2016/06/01   |\n| 1         | 3          | 2016/06/01   |\n| 1         | 4          | 2016/06/01   |\n| 2         | 3          | 2016/06/02   |\n| 3         | 4          | 2016/06/09   |\n+-----------+------------+--------------+\n\nRequestAccepted table:\n+--------------+-------------+-------------+\n| requester_id | accepter_id | accept_date |\n+--------------+-------------+-------------+\n| 1            | 2           | 2016/06/03  |\n| 1            | 3           | 2016/06/08  |\n| 2            | 3           | 2016/06/08  |\n| 3            | 4           | 2016/06/09  |\n| 3            | 4           | 2016/06/10  |\n+--------------+-------------+-------------+\n\nResult table:\n+-------------+\n| accept_rate |\n+-------------+\n| 0.8         |\n+-------------+\nThere are 4 unique accepted requests, and there are 5 requests in total. So the rate is 0.80.\n
    \n\n

     

    \nFollow up:\n
      \n\t
    • Could you write a query to return the acceptance rate for every month?
    • \n\t
    • Could you write a query to return the cumulative acceptance rate for every day?
    • \n
    \n", "content_cn": "

    \u5728 Facebook \u6216\u8005 Twitter \u8fd9\u6837\u7684\u793e\u4ea4\u5e94\u7528\u4e2d\uff0c\u4eba\u4eec\u7ecf\u5e38\u4f1a\u53d1\u597d\u53cb\u7533\u8bf7\u4e5f\u4f1a\u6536\u5230\u5176\u4ed6\u4eba\u7684\u597d\u53cb\u7533\u8bf7\u3002

    \n\n

    \u00a0

    \n\n

    \u8868\uff1aFriendRequest

    \n\n
    \n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| sender_id      | int     |\n| send_to_id     | int     |\n| request_date   | date    |\n+----------------+---------+\n\u6b64\u8868\u6ca1\u6709\u4e3b\u952e\uff0c\u5b83\u53ef\u80fd\u5305\u542b\u91cd\u590d\u9879\u3002\n\u8be5\u8868\u5305\u542b\u53d1\u9001\u8bf7\u6c42\u7684\u7528\u6237\u7684 ID \uff0c\u63a5\u53d7\u8bf7\u6c42\u7684\u7528\u6237\u7684 ID \u4ee5\u53ca\u8bf7\u6c42\u7684\u65e5\u671f\u3002\n
    \n\n

    \u8868\uff1aRequestAccepted

    \n\n
    \n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| requester_id   | int     |\n| accepter_id    | int     |\n| accept_date    | date    |\n+----------------+---------+\n\u6b64\u8868\u6ca1\u6709\u4e3b\u952e\uff0c\u5b83\u53ef\u80fd\u5305\u542b\u91cd\u590d\u9879\u3002\n\u8be5\u8868\u5305\u542b\u53d1\u9001\u8bf7\u6c42\u7684\u7528\u6237\u7684 ID \uff0c\u63a5\u53d7\u8bf7\u6c42\u7684\u7528\u6237\u7684 ID \u4ee5\u53ca\u8bf7\u6c42\u901a\u8fc7\u7684\u65e5\u671f\u3002
    \n\n

    \u00a0

    \n\n

    \u5199\u4e00\u4e2a\u67e5\u8be2\u8bed\u53e5\uff0c\u6c42\u51fa\u597d\u53cb\u7533\u8bf7\u7684\u901a\u8fc7\u7387\uff0c\u7528 2 \u4f4d\u5c0f\u6570\u8868\u793a\u3002\u901a\u8fc7\u7387\u7531\u63a5\u53d7\u597d\u53cb\u7533\u8bf7\u7684\u6570\u76ee\u9664\u4ee5\u7533\u8bf7\u603b\u6570\u3002

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u901a\u8fc7\u7684\u597d\u53cb\u7533\u8bf7\u4e0d\u4e00\u5b9a\u90fd\u5728\u8868\u00a0friend_request\u00a0\u4e2d\u3002\u4f60\u53ea\u9700\u8981\u7edf\u8ba1\u603b\u7684\u88ab\u901a\u8fc7\u7684\u7533\u8bf7\u6570\uff08\u4e0d\u7ba1\u5b83\u4eec\u5728\u4e0d\u5728\u8868\u00a0FriendRequest\u00a0\u4e2d\uff09\uff0c\u5e76\u5c06\u5b83\u9664\u4ee5\u7533\u8bf7\u603b\u6570\uff0c\u5f97\u5230\u901a\u8fc7\u7387
    • \n\t
    • \u4e00\u4e2a\u597d\u53cb\u7533\u8bf7\u53d1\u9001\u8005\u6709\u53ef\u80fd\u4f1a\u7ed9\u63a5\u53d7\u8005\u53d1\u51e0\u6761\u597d\u53cb\u7533\u8bf7\uff0c\u4e5f\u6709\u53ef\u80fd\u4e00\u4e2a\u597d\u53cb\u7533\u8bf7\u4f1a\u88ab\u901a\u8fc7\u597d\u51e0\u6b21\u3002\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u91cd\u590d\u7684\u597d\u53cb\u7533\u8bf7\u53ea\u7edf\u8ba1\u4e00\u6b21\u3002
    • \n\t
    • \u5982\u679c\u4e00\u4e2a\u597d\u53cb\u7533\u8bf7\u90fd\u6ca1\u6709\uff0c\u901a\u8fc7\u7387\u4e3a 0.00 \u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u5e94\u8be5\u5982\u4e0b\u4f8b\u6240\u793a\uff1a

    \n\n
    \nFriendRequest \u8868\uff1a\n+-----------+------------+--------------+\n| sender_id | send_to_id | request_date |\n+-----------+------------+--------------+\n| 1         | 2          | 2016/06/01   |\n| 1         | 3          | 2016/06/01   |\n| 1         | 4          | 2016/06/01   |\n| 2         | 3          | 2016/06/02   |\n| 3         | 4          | 2016/06/09   |\n+-----------+------------+--------------+\n\nRequestAccepted \u8868\uff1a\n+--------------+-------------+-------------+\n| requester_id | accepter_id | accept_date |\n+--------------+-------------+-------------+\n| 1            | 2           | 2016/06/03  |\n| 1            | 3           | 2016/06/08  |\n| 2            | 3           | 2016/06/08  |\n| 3            | 4           | 2016/06/09  |\n| 3            | 4           | 2016/06/10  |\n+--------------+-------------+-------------+\n\nResult \u8868\uff1a\n+-------------+\n| accept_rate |\n+-------------+\n| 0.8         |\n+-------------+\n\u603b\u5171\u6709 5 \u4e2a\u8bf7\u6c42\uff0c\u6709 4 \u4e2a\u4e0d\u540c\u7684\u901a\u8fc7\u8bf7\u6c42\uff0c\u6240\u4ee5\u901a\u8fc7\u7387\u662f 0.80
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636:

    \n\n
      \n\t
    • \u4f60\u80fd\u5199\u4e00\u4e2a\u67e5\u8be2\u8bed\u53e5\u5f97\u5230\u6bcf\u4e2a\u6708\u7684\u901a\u8fc7\u7387\u5417\uff1f
    • \n\t
    • \u4f60\u80fd\u6c42\u51fa\u6bcf\u4e00\u5929\u7684\u7d2f\u8ba1\u901a\u8fc7\u7387\u5417\uff1f
    • \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0597](https://leetcode-cn.com/problems/friend-requests-i-overall-acceptance-rate)", "[\u597d\u53cb\u7533\u8bf7 I\uff1a\u603b\u4f53\u901a\u8fc7\u7387](/solution/0500-0599/0597.Friend%20Requests%20I%20Overall%20Acceptance%20Rate/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0597](https://leetcode.com/problems/friend-requests-i-overall-acceptance-rate)", "[Friend Requests I Overall Acceptance Rate](/solution/0500-0599/0597.Friend%20Requests%20I%20Overall%20Acceptance%20Rate/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "0596", "frontend_question_id": "0596", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/classes-more-than-5-students", "url_en": "https://leetcode.com/problems/classes-more-than-5-students", "relative_path_cn": "/solution/0500-0599/0596.Classes%20More%20Than%205%20Students/README.md", "relative_path_en": "/solution/0500-0599/0596.Classes%20More%20Than%205%20Students/README_EN.md", "title_cn": "\u8d85\u8fc75\u540d\u5b66\u751f\u7684\u8bfe", "title_en": "Classes More Than 5 Students", "question_title_slug": "classes-more-than-5-students", "content_en": "

    There is a table courses with columns: student and class

    \r\n\r\n

    Please list out all classes which have more than or equal to 5 students.

    \r\n\r\n

    For example, the table:

    \r\n\r\n
    \r\n+---------+------------+\r\n| student | class      |\r\n+---------+------------+\r\n| A       | Math       |\r\n| B       | English    |\r\n| C       | Math       |\r\n| D       | Biology    |\r\n| E       | Math       |\r\n| F       | Computer   |\r\n| G       | Math       |\r\n| H       | Math       |\r\n| I       | Math       |\r\n+---------+------------+\r\n
    \r\n\r\n

    Should output:

    \r\n\r\n
    \r\n+---------+\r\n| class   |\r\n+---------+\r\n| Math    |\r\n+---------+\r\n
    \r\n\r\n

     

    \r\n\r\n

    Note:
    \r\nThe students should not be counted duplicate in each course.

    \r\n", "content_cn": "

    \u6709\u4e00\u4e2acourses \u8868 \uff0c\u6709: student (\u5b66\u751f) \u548c class (\u8bfe\u7a0b)\u3002

    \n\n

    \u8bf7\u5217\u51fa\u6240\u6709\u8d85\u8fc7\u6216\u7b49\u4e8e5\u540d\u5b66\u751f\u7684\u8bfe\u3002

    \n\n

    \u4f8b\u5982\uff0c\u8868\uff1a

    \n\n
    +---------+------------+\n| student | class      |\n+---------+------------+\n| A       | Math       |\n| B       | English    |\n| C       | Math       |\n| D       | Biology    |\n| E       | Math       |\n| F       | Computer   |\n| G       | Math       |\n| H       | Math       |\n| I       | Math       |\n+---------+------------+\n
    \n\n

    \u5e94\u8be5\u8f93\u51fa:

    \n\n
    +---------+\n| class   |\n+---------+\n| Math    |\n+---------+\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u5b66\u751f\u5728\u6bcf\u4e2a\u8bfe\u4e2d\u4e0d\u5e94\u88ab\u91cd\u590d\u8ba1\u7b97\u3002
    • \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0596](https://leetcode-cn.com/problems/classes-more-than-5-students)", "[\u8d85\u8fc75\u540d\u5b66\u751f\u7684\u8bfe](/solution/0500-0599/0596.Classes%20More%20Than%205%20Students/README.md)", "", "\u7b80\u5355", ""], "md_table_row_en": ["[0596](https://leetcode.com/problems/classes-more-than-5-students)", "[Classes More Than 5 Students](/solution/0500-0599/0596.Classes%20More%20Than%205%20Students/README_EN.md)", "", "Easy", ""]}, {"question_id": "0595", "frontend_question_id": "0595", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/big-countries", "url_en": "https://leetcode.com/problems/big-countries", "relative_path_cn": "/solution/0500-0599/0595.Big%20Countries/README.md", "relative_path_en": "/solution/0500-0599/0595.Big%20Countries/README_EN.md", "title_cn": "\u5927\u7684\u56fd\u5bb6", "title_en": "Big Countries", "question_title_slug": "big-countries", "content_en": "

    There is a table World

    \r\n\r\n
    \r\n+-----------------+------------+------------+--------------+---------------+\r\n| name            | continent  | area       | population   | gdp           |\r\n+-----------------+------------+------------+--------------+---------------+\r\n| Afghanistan     | Asia       | 652230     | 25500100     | 20343000      |\r\n| Albania         | Europe     | 28748      | 2831741      | 12960000      |\r\n| Algeria         | Africa     | 2381741    | 37100000     | 188681000     |\r\n| Andorra         | Europe     | 468        | 78115        | 3712000       |\r\n| Angola          | Africa     | 1246700    | 20609294     | 100990000     |\r\n+-----------------+------------+------------+--------------+---------------+\r\n
    \r\n\r\n

    A country is big if it has an area of bigger than 3 million square km or a population of more than 25 million.

    \r\n\r\n

    Write a SQL solution to output big countries' name, population and area.

    \r\n\r\n

    For example, according to the above table, we should output:

    \r\n\r\n
    \r\n+--------------+-------------+--------------+\r\n| name         | population  | area         |\r\n+--------------+-------------+--------------+\r\n| Afghanistan  | 25500100    | 652230       |\r\n| Algeria      | 37100000    | 2381741      |\r\n+--------------+-------------+--------------+\r\n
    \r\n\r\n

     

    \r\n", "content_cn": "

    \u8fd9\u91cc\u6709\u5f20\u00a0World \u8868

    \n\n
    \n+-----------------+------------+------------+--------------+---------------+\n| name            | continent  | area       | population   | gdp           |\n+-----------------+------------+------------+--------------+---------------+\n| Afghanistan     | Asia       | 652230     | 25500100     | 20343000      |\n| Albania         | Europe     | 28748      | 2831741      | 12960000      |\n| Algeria         | Africa     | 2381741    | 37100000     | 188681000     |\n| Andorra         | Europe     | 468        | 78115        | 3712000       |\n| Angola          | Africa     | 1246700    | 20609294     | 100990000     |\n+-----------------+------------+------------+--------------+---------------+\n
    \n\n

    \u5982\u679c\u4e00\u4e2a\u56fd\u5bb6\u7684\u9762\u79ef\u8d85\u8fc7 300 \u4e07\u5e73\u65b9\u516c\u91cc\uff0c\u6216\u8005\u4eba\u53e3\u8d85\u8fc7 2500 \u4e07\uff0c\u90a3\u4e48\u8fd9\u4e2a\u56fd\u5bb6\u5c31\u662f\u5927\u56fd\u5bb6\u3002

    \n\n

    \u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\uff0c\u8f93\u51fa\u8868\u4e2d\u6240\u6709\u5927\u56fd\u5bb6\u7684\u540d\u79f0\u3001\u4eba\u53e3\u548c\u9762\u79ef\u3002

    \n\n

    \u4f8b\u5982\uff0c\u6839\u636e\u4e0a\u8868\uff0c\u6211\u4eec\u5e94\u8be5\u8f93\u51fa:

    \n\n
    \n+--------------+-------------+--------------+\n| name         | population  | area         |\n+--------------+-------------+--------------+\n| Afghanistan  | 25500100    | 652230       |\n| Algeria      | 37100000    | 2381741      |\n+--------------+-------------+--------------+\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0595](https://leetcode-cn.com/problems/big-countries)", "[\u5927\u7684\u56fd\u5bb6](/solution/0500-0599/0595.Big%20Countries/README.md)", "", "\u7b80\u5355", ""], "md_table_row_en": ["[0595](https://leetcode.com/problems/big-countries)", "[Big Countries](/solution/0500-0599/0595.Big%20Countries/README_EN.md)", "", "Easy", ""]}, {"question_id": "0594", "frontend_question_id": "0594", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-harmonious-subsequence", "url_en": "https://leetcode.com/problems/longest-harmonious-subsequence", "relative_path_cn": "/solution/0500-0599/0594.Longest%20Harmonious%20Subsequence/README.md", "relative_path_en": "/solution/0500-0599/0594.Longest%20Harmonious%20Subsequence/README_EN.md", "title_cn": "\u6700\u957f\u548c\u8c10\u5b50\u5e8f\u5217", "title_en": "Longest Harmonious Subsequence", "question_title_slug": "longest-harmonious-subsequence", "content_en": "

    We define a harmonious array as an array where the difference between its maximum value and its minimum value is exactly 1.

    \n\n

    Given an integer array nums, return the length of its longest harmonious subsequence among all its possible subsequences.

    \n\n

    A subsequence of array is a sequence that can be derived from the array by deleting some or no elements without changing the order of the remaining elements.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,3,2,2,5,2,3,7]\nOutput: 5\nExplanation: The longest harmonious subsequence is [3,2,2,2,3].\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,2,3,4]\nOutput: 2\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [1,1,1,1]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 2 * 104
    • \n\t
    • -109 <= nums[i] <= 109
    • \n
    \n", "content_cn": "

    \u548c\u8c10\u6570\u7ec4\u662f\u6307\u4e00\u4e2a\u6570\u7ec4\u91cc\u5143\u7d20\u7684\u6700\u5927\u503c\u548c\u6700\u5c0f\u503c\u4e4b\u95f4\u7684\u5dee\u522b \u6b63\u597d\u662f 1 \u3002

    \n\n

    \u73b0\u5728\uff0c\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \uff0c\u8bf7\u4f60\u5728\u6240\u6709\u53ef\u80fd\u7684\u5b50\u5e8f\u5217\u4e2d\u627e\u5230\u6700\u957f\u7684\u548c\u8c10\u5b50\u5e8f\u5217\u7684\u957f\u5ea6\u3002

    \n\n

    \u6570\u7ec4\u7684\u5b50\u5e8f\u5217\u662f\u4e00\u4e2a\u7531\u6570\u7ec4\u6d3e\u751f\u51fa\u6765\u7684\u5e8f\u5217\uff0c\u5b83\u53ef\u4ee5\u901a\u8fc7\u5220\u9664\u4e00\u4e9b\u5143\u7d20\u6216\u4e0d\u5220\u9664\u5143\u7d20\u3001\u4e14\u4e0d\u6539\u53d8\u5176\u4f59\u5143\u7d20\u7684\u987a\u5e8f\u800c\u5f97\u5230\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,3,2,2,5,2,3,7]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u6700\u957f\u7684\u548c\u8c10\u5b50\u5e8f\u5217\u662f [3,2,2,2,3]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,3,4]\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,1,1,1]\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 2 * 104
    • \n\t
    • -109 <= nums[i] <= 109
    • \n
    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findLHS(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findLHS(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findLHS(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findLHS(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findLHS(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindLHS(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar findLHS = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef find_lhs(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findLHS(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findLHS(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findLHS(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findLHS(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_lhs(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function findLHS($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findLHS(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-lhs nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0594](https://leetcode-cn.com/problems/longest-harmonious-subsequence)", "[\u6700\u957f\u548c\u8c10\u5b50\u5e8f\u5217](/solution/0500-0599/0594.Longest%20Harmonious%20Subsequence/README.md)", "`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0594](https://leetcode.com/problems/longest-harmonious-subsequence)", "[Longest Harmonious Subsequence](/solution/0500-0599/0594.Longest%20Harmonious%20Subsequence/README_EN.md)", "`Hash Table`", "Easy", ""]}, {"question_id": "0593", "frontend_question_id": "0593", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/valid-square", "url_en": "https://leetcode.com/problems/valid-square", "relative_path_cn": "/solution/0500-0599/0593.Valid%20Square/README.md", "relative_path_en": "/solution/0500-0599/0593.Valid%20Square/README_EN.md", "title_cn": "\u6709\u6548\u7684\u6b63\u65b9\u5f62", "title_en": "Valid Square", "question_title_slug": "valid-square", "content_en": "

    Given the coordinates of four points in 2D space p1, p2, p3 and p4, return true if the four points construct a square.

    \n\n

    The coordinate of a point pi is represented as [xi, yi]. The input is not given in any order.

    \n\n

    A valid square has four equal sides with positive length and four equal angles (90-degree angles).

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: p1 = [0,0], p2 = [1,1], p3 = [1,0], p4 = [0,1]\nOutput: true\n
    \n\n

    Example 2:

    \n\n
    \nInput: p1 = [0,0], p2 = [1,1], p3 = [1,0], p4 = [0,12]\nOutput: false\n
    \n\n

    Example 3:

    \n\n
    \nInput: p1 = [1,0], p2 = [-1,0], p3 = [0,1], p4 = [0,-1]\nOutput: true\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • p1.length == p2.length == p3.length == p4.length == 2
    • \n\t
    • -104 <= xi, yi <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e8c\u7ef4\u7a7a\u95f4\u4e2d\u56db\u70b9\u7684\u5750\u6807\uff0c\u8fd4\u56de\u56db\u70b9\u662f\u5426\u53ef\u4ee5\u6784\u9020\u4e00\u4e2a\u6b63\u65b9\u5f62\u3002

    \n\n

    \u4e00\u4e2a\u70b9\u7684\u5750\u6807\uff08x\uff0cy\uff09\u7531\u4e00\u4e2a\u6709\u4e24\u4e2a\u6574\u6570\u7684\u6574\u6570\u6570\u7ec4\u8868\u793a\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \n\u8f93\u5165: p1 = [0,0], p2 = [1,1], p3 = [1,0], p4 = [0,1]\n\u8f93\u51fa: True\n
    \n\n

     

    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u6240\u6709\u8f93\u5165\u6574\u6570\u90fd\u5728 [-10000\uff0c10000] \u8303\u56f4\u5185\u3002
    2. \n\t
    3. \u4e00\u4e2a\u6709\u6548\u7684\u6b63\u65b9\u5f62\u6709\u56db\u4e2a\u7b49\u957f\u7684\u6b63\u957f\u548c\u56db\u4e2a\u7b49\u89d2\uff0890\u5ea6\u89d2\uff09\u3002
    4. \n\t
    5. \u8f93\u5165\u70b9\u6ca1\u6709\u987a\u5e8f\u3002
    6. \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool validSquare(vector& p1, vector& p2, vector& p3, vector& p4) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean validSquare(int[] p1, int[] p2, int[] p3, int[] p4) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def validSquare(self, p1, p2, p3, p4):\n \"\"\"\n :type p1: List[int]\n :type p2: List[int]\n :type p3: List[int]\n :type p4: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def validSquare(self, p1: List[int], p2: List[int], p3: List[int], p4: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool validSquare(int* p1, int p1Size, int* p2, int p2Size, int* p3, int p3Size, int* p4, int p4Size){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool ValidSquare(int[] p1, int[] p2, int[] p3, int[] p4) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} p1\n * @param {number[]} p2\n * @param {number[]} p3\n * @param {number[]} p4\n * @return {boolean}\n */\nvar validSquare = function(p1, p2, p3, p4) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} p1\n# @param {Integer[]} p2\n# @param {Integer[]} p3\n# @param {Integer[]} p4\n# @return {Boolean}\ndef valid_square(p1, p2, p3, p4)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func validSquare(_ p1: [Int], _ p2: [Int], _ p3: [Int], _ p4: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func validSquare(p1 []int, p2 []int, p3 []int, p4 []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def validSquare(p1: Array[Int], p2: Array[Int], p3: Array[Int], p4: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun validSquare(p1: IntArray, p2: IntArray, p3: IntArray, p4: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn valid_square(p1: Vec, p2: Vec, p3: Vec, p4: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $p1\n * @param Integer[] $p2\n * @param Integer[] $p3\n * @param Integer[] $p4\n * @return Boolean\n */\n function validSquare($p1, $p2, $p3, $p4) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function validSquare(p1: number[], p2: number[], p3: number[], p4: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (valid-square p1 p2 p3 p4)\n (-> (listof exact-integer?) (listof exact-integer?) (listof exact-integer?) (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0593](https://leetcode-cn.com/problems/valid-square)", "[\u6709\u6548\u7684\u6b63\u65b9\u5f62](/solution/0500-0599/0593.Valid%20Square/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0593](https://leetcode.com/problems/valid-square)", "[Valid Square](/solution/0500-0599/0593.Valid%20Square/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "0592", "frontend_question_id": "0592", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/fraction-addition-and-subtraction", "url_en": "https://leetcode.com/problems/fraction-addition-and-subtraction", "relative_path_cn": "/solution/0500-0599/0592.Fraction%20Addition%20and%20Subtraction/README.md", "relative_path_en": "/solution/0500-0599/0592.Fraction%20Addition%20and%20Subtraction/README_EN.md", "title_cn": "\u5206\u6570\u52a0\u51cf\u8fd0\u7b97", "title_en": "Fraction Addition and Subtraction", "question_title_slug": "fraction-addition-and-subtraction", "content_en": "

    Given a string expression representing an expression of fraction addition and subtraction, return the calculation result in string format.

    \n\n

    The final result should be an irreducible fraction. If your final result is an integer, say 2, you need to change it to the format of a fraction that has a denominator 1. So in this case, 2 should be converted to 2/1.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: expression = "-1/2+1/2"\nOutput: "0/1"\n
    \n\n

    Example 2:

    \n\n
    \nInput: expression = "-1/2+1/2+1/3"\nOutput: "1/3"\n
    \n\n

    Example 3:

    \n\n
    \nInput: expression = "1/3-1/2"\nOutput: "-1/6"\n
    \n\n

    Example 4:

    \n\n
    \nInput: expression = "5/3+1/3"\nOutput: "2/1"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The input string only contains '0' to '9', '/', '+' and '-'. So does the output.
    • \n\t
    • Each fraction (input and output) has the format ±numerator/denominator. If the first input fraction or the output is positive, then '+' will be omitted.
    • \n\t
    • The input only contains valid irreducible fractions, where the numerator and denominator of each fraction will always be in the range [1, 10]. If the denominator is 1, it means this fraction is actually an integer in a fraction format defined above.
    • \n\t
    • The number of given fractions will be in the range [1, 10].
    • \n\t
    • The numerator and denominator of the final result are guaranteed to be valid and in the range of 32-bit int.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u8868\u793a\u5206\u6570\u52a0\u51cf\u8fd0\u7b97\u8868\u8fbe\u5f0f\u7684\u5b57\u7b26\u4e32\uff0c\u4f60\u9700\u8981\u8fd4\u56de\u4e00\u4e2a\u5b57\u7b26\u4e32\u5f62\u5f0f\u7684\u8ba1\u7b97\u7ed3\u679c\u3002 \u8fd9\u4e2a\u7ed3\u679c\u5e94\u8be5\u662f\u4e0d\u53ef\u7ea6\u5206\u7684\u5206\u6570\uff0c\u5373\u6700\u7b80\u5206\u6570\u3002 \u5982\u679c\u6700\u7ec8\u7ed3\u679c\u662f\u4e00\u4e2a\u6574\u6570\uff0c\u4f8b\u5982 2\uff0c\u4f60\u9700\u8981\u5c06\u5b83\u8f6c\u6362\u6210\u5206\u6570\u5f62\u5f0f\uff0c\u5176\u5206\u6bcd\u4e3a 1\u3002\u6240\u4ee5\u5728\u4e0a\u8ff0\u4f8b\u5b50\u4e2d, 2 \u5e94\u8be5\u88ab\u8f6c\u6362\u4e3a 2/1\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165:"-1/2+1/2"\n\u8f93\u51fa: "0/1"\n
    \n\n

     \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165:"-1/2+1/2+1/3"\n\u8f93\u51fa: "1/3"\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \n\u8f93\u5165:"1/3-1/2"\n\u8f93\u51fa: "-1/6"\n
    \n\n

    \u793a\u4f8b 4:

    \n\n
    \n\u8f93\u5165:"5/3+1/3"\n\u8f93\u51fa: "2/1"\n
    \n\n

    \u8bf4\u660e:

    \n\n
      \n\t
    1. \u8f93\u5165\u548c\u8f93\u51fa\u5b57\u7b26\u4e32\u53ea\u5305\u542b '0' \u5230 '9' \u7684\u6570\u5b57\uff0c\u4ee5\u53ca '/', '+' \u548c '-'\u3002 
    2. \n\t
    3. \u8f93\u5165\u548c\u8f93\u51fa\u5206\u6570\u683c\u5f0f\u5747\u4e3a ±\u5206\u5b50/\u5206\u6bcd\u3002\u5982\u679c\u8f93\u5165\u7684\u7b2c\u4e00\u4e2a\u5206\u6570\u6216\u8005\u8f93\u51fa\u7684\u5206\u6570\u662f\u6b63\u6570\uff0c\u5219 '+' \u4f1a\u88ab\u7701\u7565\u6389\u3002
    4. \n\t
    5. \u8f93\u5165\u53ea\u5305\u542b\u5408\u6cd5\u7684\u6700\u7b80\u5206\u6570\uff0c\u6bcf\u4e2a\u5206\u6570\u7684\u5206\u5b50\u4e0e\u5206\u6bcd\u7684\u8303\u56f4\u662f  [1,10]\u3002 \u5982\u679c\u5206\u6bcd\u662f1\uff0c\u610f\u5473\u7740\u8fd9\u4e2a\u5206\u6570\u5b9e\u9645\u4e0a\u662f\u4e00\u4e2a\u6574\u6570\u3002
    6. \n\t
    7. \u8f93\u5165\u7684\u5206\u6570\u4e2a\u6570\u8303\u56f4\u662f [1,10]\u3002
    8. \n\t
    9. \u6700\u7ec8\u7ed3\u679c\u7684\u5206\u5b50\u4e0e\u5206\u6bcd\u4fdd\u8bc1\u662f 32 \u4f4d\u6574\u6570\u8303\u56f4\u5185\u7684\u6709\u6548\u6574\u6570\u3002
    10. \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string fractionAddition(string expression) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String fractionAddition(String expression) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def fractionAddition(self, expression):\n \"\"\"\n :type expression: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def fractionAddition(self, expression: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * fractionAddition(char * expression){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string FractionAddition(string expression) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} expression\n * @return {string}\n */\nvar fractionAddition = function(expression) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} expression\n# @return {String}\ndef fraction_addition(expression)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func fractionAddition(_ expression: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func fractionAddition(expression string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def fractionAddition(expression: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun fractionAddition(expression: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn fraction_addition(expression: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $expression\n * @return String\n */\n function fractionAddition($expression) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function fractionAddition(expression: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (fraction-addition expression)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0592](https://leetcode-cn.com/problems/fraction-addition-and-subtraction)", "[\u5206\u6570\u52a0\u51cf\u8fd0\u7b97](/solution/0500-0599/0592.Fraction%20Addition%20and%20Subtraction/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0592](https://leetcode.com/problems/fraction-addition-and-subtraction)", "[Fraction Addition and Subtraction](/solution/0500-0599/0592.Fraction%20Addition%20and%20Subtraction/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "0591", "frontend_question_id": "0591", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/tag-validator", "url_en": "https://leetcode.com/problems/tag-validator", "relative_path_cn": "/solution/0500-0599/0591.Tag%20Validator/README.md", "relative_path_en": "/solution/0500-0599/0591.Tag%20Validator/README_EN.md", "title_cn": "\u6807\u7b7e\u9a8c\u8bc1\u5668", "title_en": "Tag Validator", "question_title_slug": "tag-validator", "content_en": "

    Given a string representing a code snippet, implement a tag validator to parse the code and return whether it is valid.

    \n\n

    A code snippet is valid if all the following rules hold:

    \n\n
      \n\t
    1. The code must be wrapped in a valid closed tag. Otherwise, the code is invalid.
    2. \n\t
    3. A closed tag (not necessarily valid) has exactly the following format : <TAG_NAME>TAG_CONTENT</TAG_NAME>. Among them, <TAG_NAME> is the start tag, and </TAG_NAME> is the end tag. The TAG_NAME in start and end tags should be the same. A closed tag is valid if and only if the TAG_NAME and TAG_CONTENT are valid.
    4. \n\t
    5. A valid TAG_NAME only contain upper-case letters, and has length in range [1,9]. Otherwise, the TAG_NAME is invalid.
    6. \n\t
    7. A valid TAG_CONTENT may contain other valid closed tags, cdata and any characters (see note1) EXCEPT unmatched <, unmatched start and end tag, and unmatched or closed tags with invalid TAG_NAME. Otherwise, the TAG_CONTENT is invalid.
    8. \n\t
    9. A start tag is unmatched if no end tag exists with the same TAG_NAME, and vice versa. However, you also need to consider the issue of unbalanced when tags are nested.
    10. \n\t
    11. A < is unmatched if you cannot find a subsequent >. And when you find a < or </, all the subsequent characters until the next > should be parsed as TAG_NAME (not necessarily valid).
    12. \n\t
    13. The cdata has the following format : <![CDATA[CDATA_CONTENT]]>. The range of CDATA_CONTENT is defined as the characters between <![CDATA[ and the first subsequent ]]>.
    14. \n\t
    15. CDATA_CONTENT may contain any characters. The function of cdata is to forbid the validator to parse CDATA_CONTENT, so even it has some characters that can be parsed as tag (no matter valid or invalid), you should treat it as regular characters.
    16. \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: code = "<DIV>This is the first line <![CDATA[<div>]]></DIV>"\nOutput: true\nExplanation: \nThe code is wrapped in a closed tag : <DIV> and </DIV>. \nThe TAG_NAME is valid, the TAG_CONTENT consists of some characters and cdata. \nAlthough CDATA_CONTENT has an unmatched start tag with invalid TAG_NAME, it should be considered as plain text, not parsed as a tag.\nSo TAG_CONTENT is valid, and then the code is valid. Thus return true.\n
    \n\n

    Example 2:

    \n\n
    \nInput: code = "<DIV>>>  ![cdata[]] <![CDATA[<div>]>]]>]]>>]</DIV>"\nOutput: true\nExplanation:\nWe first separate the code into : start_tag|tag_content|end_tag.\nstart_tag -> "<DIV>"\nend_tag -> "</DIV>"\ntag_content could also be separated into : text1|cdata|text2.\ntext1 -> ">>  ![cdata[]] "\ncdata -> "<![CDATA[<div>]>]]>", where the CDATA_CONTENT is "<div>]>"\ntext2 -> "]]>>]"\nThe reason why start_tag is NOT "<DIV>>>" is because of the rule 6.\nThe reason why cdata is NOT "<![CDATA[<div>]>]]>]]>" is because of the rule 7.\n
    \n\n

    Example 3:

    \n\n
    \nInput: code = "<A>  <B> </A>   </B>"\nOutput: false\nExplanation: Unbalanced. If "<A>" is closed, then "<B>" must be unmatched, and vice versa.\n
    \n\n

    Example 4:

    \n\n
    \nInput: code = "<DIV>  div tag is not closed  <DIV>"\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= code.length <= 500
    • \n\t
    • code consists of English letters, digits, '<', '>', '/', '!', '[', ']', '.', and ' '.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u8868\u793a\u4ee3\u7801\u7247\u6bb5\u7684\u5b57\u7b26\u4e32\uff0c\u4f60\u9700\u8981\u5b9e\u73b0\u4e00\u4e2a\u9a8c\u8bc1\u5668\u6765\u89e3\u6790\u8fd9\u6bb5\u4ee3\u7801\uff0c\u5e76\u8fd4\u56de\u5b83\u662f\u5426\u5408\u6cd5\u3002\u5408\u6cd5\u7684\u4ee3\u7801\u7247\u6bb5\u9700\u8981\u9075\u5b88\u4ee5\u4e0b\u7684\u6240\u6709\u89c4\u5219\uff1a

    \n\n
      \n\t
    1. \u4ee3\u7801\u5fc5\u987b\u88ab\u5408\u6cd5\u7684\u95ed\u5408\u6807\u7b7e\u5305\u56f4\u3002\u5426\u5219\uff0c\u4ee3\u7801\u662f\u65e0\u6548\u7684\u3002
    2. \n\t
    3. \u95ed\u5408\u6807\u7b7e\uff08\u4e0d\u4e00\u5b9a\u5408\u6cd5\uff09\u8981\u4e25\u683c\u7b26\u5408\u683c\u5f0f\uff1a<TAG_NAME>TAG_CONTENT</TAG_NAME>\u3002\u5176\u4e2d\uff0c<TAG_NAME>\u662f\u8d77\u59cb\u6807\u7b7e\uff0c</TAG_NAME>\u662f\u7ed3\u675f\u6807\u7b7e\u3002\u8d77\u59cb\u548c\u7ed3\u675f\u6807\u7b7e\u4e2d\u7684 TAG_NAME \u5e94\u5f53\u76f8\u540c\u3002\u5f53\u4e14\u4ec5\u5f53 TAG_NAME \u548c TAG_CONTENT \u90fd\u662f\u5408\u6cd5\u7684\uff0c\u95ed\u5408\u6807\u7b7e\u624d\u662f\u5408\u6cd5\u7684\u3002
    4. \n\t
    5. \u5408\u6cd5\u7684 TAG_NAME \u4ec5\u542b\u6709\u5927\u5199\u5b57\u6bcd\uff0c\u957f\u5ea6\u5728\u8303\u56f4 [1,9] \u4e4b\u95f4\u3002\u5426\u5219\uff0c\u8be5 TAG_NAME \u662f\u4e0d\u5408\u6cd5\u7684\u3002
    6. \n\t
    7. \u5408\u6cd5\u7684 TAG_CONTENT \u53ef\u4ee5\u5305\u542b\u5176\u4ed6\u5408\u6cd5\u7684\u95ed\u5408\u6807\u7b7e\uff0ccdata \uff08\u8bf7\u53c2\u8003\u89c4\u52197\uff09\u548c\u4efb\u610f\u5b57\u7b26\uff08\u6ce8\u610f\u53c2\u8003\u89c4\u52191\uff09\u9664\u4e86\u4e0d\u5339\u914d\u7684<\u3001\u4e0d\u5339\u914d\u7684\u8d77\u59cb\u548c\u7ed3\u675f\u6807\u7b7e\u3001\u4e0d\u5339\u914d\u7684\u6216\u5e26\u6709\u4e0d\u5408\u6cd5 TAG_NAME \u7684\u95ed\u5408\u6807\u7b7e\u3002\u5426\u5219\uff0cTAG_CONTENT \u662f\u4e0d\u5408\u6cd5\u7684\u3002
    8. \n\t
    9. \u4e00\u4e2a\u8d77\u59cb\u6807\u7b7e\uff0c\u5982\u679c\u6ca1\u6709\u5177\u6709\u76f8\u540c TAG_NAME \u7684\u7ed3\u675f\u6807\u7b7e\u4e0e\u4e4b\u5339\u914d\uff0c\u662f\u4e0d\u5408\u6cd5\u7684\u3002\u53cd\u4e4b\u4ea6\u7136\u3002\u4e0d\u8fc7\uff0c\u4f60\u4e5f\u9700\u8981\u8003\u8651\u6807\u7b7e\u5d4c\u5957\u7684\u95ee\u9898\u3002
    10. \n\t
    11. \u4e00\u4e2a<\uff0c\u5982\u679c\u4f60\u627e\u4e0d\u5230\u4e00\u4e2a\u540e\u7eed\u7684>\u4e0e\u4e4b\u5339\u914d\uff0c\u662f\u4e0d\u5408\u6cd5\u7684\u3002\u5e76\u4e14\u5f53\u4f60\u627e\u5230\u4e00\u4e2a<\u6216</\u65f6\uff0c\u6240\u6709\u76f4\u5230\u4e0b\u4e00\u4e2a>\u7684\u524d\u7684\u5b57\u7b26\uff0c\u90fd\u5e94\u5f53\u88ab\u89e3\u6790\u4e3a TAG_NAME\uff08\u4e0d\u4e00\u5b9a\u5408\u6cd5\uff09\u3002
    12. \n\t
    13. cdata \u6709\u5982\u4e0b\u683c\u5f0f\uff1a<![CDATA[CDATA_CONTENT]]>\u3002CDATA_CONTENT \u7684\u8303\u56f4\u88ab\u5b9a\u4e49\u6210 <![CDATA[ \u548c\u540e\u7eed\u7684\u7b2c\u4e00\u4e2a ]]>\u4e4b\u95f4\u7684\u5b57\u7b26\u3002
    14. \n\t
    15. CDATA_CONTENT \u53ef\u4ee5\u5305\u542b\u4efb\u610f\u5b57\u7b26\u3002cdata \u7684\u529f\u80fd\u662f\u963b\u6b62\u9a8c\u8bc1\u5668\u89e3\u6790CDATA_CONTENT\uff0c\u6240\u4ee5\u5373\u4f7f\u5176\u4e2d\u6709\u4e00\u4e9b\u5b57\u7b26\u53ef\u4ee5\u88ab\u89e3\u6790\u4e3a\u6807\u7b7e\uff08\u65e0\u8bba\u5408\u6cd5\u8fd8\u662f\u4e0d\u5408\u6cd5\uff09\uff0c\u4e5f\u5e94\u8be5\u5c06\u5b83\u4eec\u89c6\u4e3a\u5e38\u89c4\u5b57\u7b26\u3002
    16. \n
    \n\n

    \u5408\u6cd5\u4ee3\u7801\u7684\u4f8b\u5b50:

    \n\n
    \n\u8f93\u5165: "<DIV>This is the first line <![CDATA[<div>]]></DIV>"\n\n\u8f93\u51fa: True\n\n\u89e3\u91ca: \n\n\u4ee3\u7801\u88ab\u5305\u542b\u5728\u4e86\u95ed\u5408\u7684\u6807\u7b7e\u5185\uff1a <DIV> \u548c </DIV> \u3002\n\nTAG_NAME \u662f\u5408\u6cd5\u7684\uff0cTAG_CONTENT \u5305\u542b\u4e86\u4e00\u4e9b\u5b57\u7b26\u548c cdata \u3002 \n\n\u5373\u4f7f CDATA_CONTENT \u542b\u6709\u4e0d\u5339\u914d\u7684\u8d77\u59cb\u6807\u7b7e\u548c\u4e0d\u5408\u6cd5\u7684 TAG_NAME\uff0c\u5b83\u5e94\u8be5\u88ab\u89c6\u4e3a\u666e\u901a\u7684\u6587\u672c\uff0c\u800c\u4e0d\u662f\u6807\u7b7e\u3002\n\n\u6240\u4ee5 TAG_CONTENT \u662f\u5408\u6cd5\u7684\uff0c\u56e0\u6b64\u4ee3\u7801\u662f\u5408\u6cd5\u7684\u3002\u6700\u7ec8\u8fd4\u56deTrue\u3002\n\n\n\u8f93\u5165: "<DIV>>>  ![cdata[]] <![CDATA[<div>]>]]>]]>>]</DIV>"\n\n\u8f93\u51fa: True\n\n\u89e3\u91ca:\n\n\u6211\u4eec\u9996\u5148\u5c06\u4ee3\u7801\u5206\u5272\u4e3a\uff1a start_tag|tag_content|end_tag \u3002\n\nstart_tag -> "<DIV>"\n\nend_tag -> "</DIV>"\n\ntag_content \u4e5f\u53ef\u88ab\u5206\u5272\u4e3a\uff1a text1|cdata|text2 \u3002\n\ntext1 -> ">>  ![cdata[]] "\n\ncdata -> "<![CDATA[<div>]>]]>" \uff0c\u5176\u4e2d CDATA_CONTENT \u4e3a "<div>]>"\n\ntext2 -> "]]>>]"\n\n\nstart_tag \u4e0d\u662f "<DIV>>>" \u7684\u539f\u56e0\u53c2\u7167\u89c4\u5219 6 \u3002\ncdata \u4e0d\u662f "<![CDATA[<div>]>]]>]]>" \u7684\u539f\u56e0\u53c2\u7167\u89c4\u5219 7 \u3002\n
    \n\n

    \u4e0d\u5408\u6cd5\u4ee3\u7801\u7684\u4f8b\u5b50:

    \n\n
    \n\u8f93\u5165: "<A>  <B> </A>   </B>"\n\u8f93\u51fa: False\n\u89e3\u91ca: \u4e0d\u5408\u6cd5\u3002\u5982\u679c "<A>" \u662f\u95ed\u5408\u7684\uff0c\u90a3\u4e48 "<B>" \u4e00\u5b9a\u662f\u4e0d\u5339\u914d\u7684\uff0c\u53cd\u4e4b\u4ea6\u7136\u3002\n\n\u8f93\u5165: "<DIV>  div tag is not closed  <DIV>"\n\u8f93\u51fa: False\n\n\u8f93\u5165: "<DIV>  unmatched <  </DIV>"\n\u8f93\u51fa: False\n\n\u8f93\u5165: "<DIV> closed tags with invalid tag name  <b>123</b> </DIV>"\n\u8f93\u51fa: False\n\n\u8f93\u5165: "<DIV> unmatched tags with invalid tag name  </1234567890> and <CDATA[[]]>  </DIV>"\n\u8f93\u51fa: False\n\n\u8f93\u5165: "<DIV>  unmatched start tag <B>  and unmatched end tag </C>  </DIV>"\n\u8f93\u51fa: False\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u4e3a\u7b80\u660e\u8d77\u89c1\uff0c\u4f60\u53ef\u4ee5\u5047\u8bbe\u8f93\u5165\u7684\u4ee3\u7801\uff08\u5305\u62ec\u63d0\u5230\u7684\u4efb\u610f\u5b57\u7b26\uff09\u53ea\u5305\u542b\u6570\u5b57, \u5b57\u6bcd, '<','>','/','!','[',']'\u548c' '\u3002
    2. \n
    \n", "tags_en": ["Stack", "String"], "tags_cn": ["\u6808", "\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isValid(string code) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isValid(String code) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isValid(self, code):\n \"\"\"\n :type code: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isValid(self, code: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isValid(char * code){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsValid(string code) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} code\n * @return {boolean}\n */\nvar isValid = function(code) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} code\n# @return {Boolean}\ndef is_valid(code)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isValid(_ code: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isValid(code string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isValid(code: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isValid(code: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_valid(code: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $code\n * @return Boolean\n */\n function isValid($code) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isValid(code: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-valid code)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0591](https://leetcode-cn.com/problems/tag-validator)", "[\u6807\u7b7e\u9a8c\u8bc1\u5668](/solution/0500-0599/0591.Tag%20Validator/README.md)", "`\u6808`,`\u5b57\u7b26\u4e32`", "\u56f0\u96be", ""], "md_table_row_en": ["[0591](https://leetcode.com/problems/tag-validator)", "[Tag Validator](/solution/0500-0599/0591.Tag%20Validator/README_EN.md)", "`Stack`,`String`", "Hard", ""]}, {"question_id": "0588", "frontend_question_id": "0588", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/design-in-memory-file-system", "url_en": "https://leetcode.com/problems/design-in-memory-file-system", "relative_path_cn": "/solution/0500-0599/0588.Design%20In-Memory%20File%20System/README.md", "relative_path_en": "/solution/0500-0599/0588.Design%20In-Memory%20File%20System/README_EN.md", "title_cn": "\u8bbe\u8ba1\u5185\u5b58\u6587\u4ef6\u7cfb\u7edf", "title_en": "Design In-Memory File System", "question_title_slug": "design-in-memory-file-system", "content_en": "

    Design a data structure that simulates an in-memory file system.

    \n\n

    Implement the FileSystem class:

    \n\n
      \n\t
    • FileSystem() Initializes the object of the system.
    • \n\t
    • List<String> ls(String path)\n\t
        \n\t\t
      • If path is a file path, returns a list that only contains this file's name.
      • \n\t\t
      • If path is a directory path, returns the list of file and directory names in this directory.
      • \n\t
      \n\tThe answer should in lexicographic order.
    • \n\t
    • void mkdir(String path) Makes a new directory according to the given path. The given directory path does not exist. If the middle directories in the path do not exist, you should create them as well.
    • \n\t
    • void addContentToFile(String filePath, String content)\n\t
        \n\t\t
      • If filePath does not exist, creates that file containing given content.
      • \n\t\t
      • If filePath already exists, appends the given content to original content.
      • \n\t
      \n\t
    • \n\t
    • String readContentFromFile(String filePath) Returns the content in the file at filePath.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput\n["FileSystem", "ls", "mkdir", "addContentToFile", "ls", "readContentFromFile"]\n[[], ["/"], ["/a/b/c"], ["/a/b/c/d", "hello"], ["/"], ["/a/b/c/d"]]\nOutput\n[null, [], null, null, ["a"], "hello"]\n\nExplanation\nFileSystem fileSystem = new FileSystem();\nfileSystem.ls("/");                         // return []\nfileSystem.mkdir("/a/b/c");\nfileSystem.addContentToFile("/a/b/c/d", "hello");\nfileSystem.ls("/");                         // return ["a"]\nfileSystem.readContentFromFile("/a/b/c/d"); // return "hello"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= path.length, filePath.length <= 100
    • \n\t
    • path and filePath are absolute paths which begin with '/' and do not end with '/' except that the path is just "/".
    • \n\t
    • You can assume that all directory names and file names only contain lowercase letters, and the same names will not exist in the same directory.
    • \n\t
    • You can assume that all operations will be passed valid parameters, and users will not attempt to retrieve file content or list a directory or file that does not exist.
    • \n\t
    • 1 <= content.length <= 50
    • \n\t
    • At most 300 calls will be made to ls, mkdiraddContentToFile, and readContentFromFile.
    • \n
    \n", "content_cn": "

    \u8bbe\u8ba1\u4e00\u4e2a\u5185\u5b58\u6587\u4ef6\u7cfb\u7edf\uff0c\u6a21\u62df\u4ee5\u4e0b\u529f\u80fd\uff1a

    \n\n

    ls\uff1a \u4ee5\u5b57\u7b26\u4e32\u7684\u683c\u5f0f\u8f93\u5165\u4e00\u4e2a\u8def\u5f84\u3002\u5982\u679c\u5b83\u662f\u4e00\u4e2a\u6587\u4ef6\u7684\u8def\u5f84\uff0c\u90a3\u4e48\u51fd\u6570\u8fd4\u56de\u4e00\u4e2a\u5217\u8868\uff0c\u4ec5\u5305\u542b\u8fd9\u4e2a\u6587\u4ef6\u7684\u540d\u5b57\u3002\u5982\u679c\u5b83\u662f\u4e00\u4e2a\u6587\u4ef6\u5939\u7684\u7684\u8def\u5f84\uff0c\u90a3\u4e48\u8fd4\u56de\u8be5 \u6587\u4ef6\u5939\u5185 \u7684\u6240\u6709\u6587\u4ef6\u548c\u5b50\u6587\u4ef6\u5939\u7684\u540d\u5b57\u3002\u4f60\u7684\u8fd4\u56de\u7ed3\u679c\uff08\u5305\u62ec\u6587\u4ef6\u548c\u5b50\u6587\u4ef6\u5939\uff09\u5e94\u8be5\u6309\u5b57\u5178\u5e8f\u6392\u5217\u3002

    \n\n

    mkdir\uff1a\u8f93\u5165\u4e00\u4e2a\u5f53\u524d\u4e0d\u5b58\u5728\u7684 \u6587\u4ef6\u5939\u8def\u5f84 \uff0c\u4f60\u9700\u8981\u6839\u636e\u8def\u5f84\u540d\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6587\u4ef6\u5939\u3002\u5982\u679c\u6709\u4e0a\u5c42\u6587\u4ef6\u5939\u8def\u5f84\u4e0d\u5b58\u5728\uff0c\u90a3\u4e48\u4f60\u4e5f\u5e94\u8be5\u5c06\u5b83\u4eec\u5168\u90e8\u521b\u5efa\u3002\u8fd9\u4e2a\u51fd\u6570\u7684\u8fd4\u56de\u7c7b\u578b\u4e3a void \u3002

    \n\n

    addContentToFile\uff1a \u8f93\u5165\u5b57\u7b26\u4e32\u5f62\u5f0f\u7684 \u6587\u4ef6\u8def\u5f84 \u548c \u6587\u4ef6\u5185\u5bb9 \u3002\u5982\u679c\u6587\u4ef6\u4e0d\u5b58\u5728\uff0c\u4f60\u9700\u8981\u521b\u5efa\u5305\u542b\u7ed9\u5b9a\u6587\u4ef6\u5185\u5bb9\u7684\u6587\u4ef6\u3002\u5982\u679c\u6587\u4ef6\u5df2\u7ecf\u5b58\u5728\uff0c\u90a3\u4e48\u4f60\u9700\u8981\u5c06\u7ed9\u5b9a\u7684\u6587\u4ef6\u5185\u5bb9 \u8ffd\u52a0 \u5728\u539f\u672c\u5185\u5bb9\u7684\u540e\u9762\u3002\u8fd9\u4e2a\u51fd\u6570\u7684\u8fd4\u56de\u7c7b\u578b\u4e3a void \u3002

    \n\n

    readContentFromFile\uff1a \u8f93\u5165 \u6587\u4ef6\u8def\u5f84 \uff0c\u4ee5\u5b57\u7b26\u4e32\u5f62\u5f0f\u8fd4\u56de\u8be5\u6587\u4ef6\u7684 \u5185\u5bb9 \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: \n["FileSystem","ls","mkdir","addContentToFile","ls","readContentFromFile"]\n[[],["/"],["/a/b/c"],["/a/b/c/d","hello"],["/"],["/a/b/c/d"]]\n\n\u8f93\u51fa:\n[null,[],null,null,["a"],"hello"]\n\n\u89e3\u91ca:\n\"filesystem\"\n
    \n\n

     

    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u4f60\u53ef\u4ee5\u5047\u5b9a\u6240\u6709\u6587\u4ef6\u548c\u6587\u4ef6\u5939\u7684\u8def\u5f84\u90fd\u662f\u7edd\u5bf9\u8def\u5f84\uff0c\u9664\u975e\u662f\u6839\u76ee\u5f55 / \u81ea\u8eab\uff0c\u5176\u4ed6\u8def\u5f84\u90fd\u662f\u4ee5 / \u5f00\u5934\u4e14 \u4e0d \u4ee5 / \u7ed3\u675f\u3002
    2. \n\t
    3. \u4f60\u53ef\u4ee5\u5047\u5b9a\u6240\u6709\u64cd\u4f5c\u7684\u53c2\u6570\u90fd\u662f\u6709\u6548\u7684\uff0c\u5373\u7528\u6237\u4e0d\u4f1a\u83b7\u53d6\u4e0d\u5b58\u5728\u6587\u4ef6\u7684\u5185\u5bb9\uff0c\u6216\u8005\u83b7\u53d6\u4e0d\u5b58\u5728\u6587\u4ef6\u5939\u548c\u6587\u4ef6\u7684\u5217\u8868\u3002
    4. \n\t
    5. \u4f60\u53ef\u4ee5\u5047\u5b9a\u6240\u6709\u6587\u4ef6\u5939\u540d\u5b57\u548c\u6587\u4ef6\u540d\u5b57\u90fd\u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd\uff0c\u4e14\u540c\u4e00\u6587\u4ef6\u5939\u4e0b\u4e0d\u4f1a\u6709\u76f8\u540c\u540d\u5b57\u7684\u6587\u4ef6\u5939\u6216\u6587\u4ef6\u3002
    6. \n
    \n", "tags_en": ["Design"], "tags_cn": ["\u8bbe\u8ba1"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class FileSystem {\npublic:\n FileSystem() {\n\n }\n \n vector ls(string path) {\n\n }\n \n void mkdir(string path) {\n\n }\n \n void addContentToFile(string filePath, string content) {\n\n }\n \n string readContentFromFile(string filePath) {\n\n }\n};\n\n/**\n * Your FileSystem object will be instantiated and called as such:\n * FileSystem* obj = new FileSystem();\n * vector param_1 = obj->ls(path);\n * obj->mkdir(path);\n * obj->addContentToFile(filePath,content);\n * string param_4 = obj->readContentFromFile(filePath);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class FileSystem {\n\n public FileSystem() {\n\n }\n \n public List ls(String path) {\n\n }\n \n public void mkdir(String path) {\n\n }\n \n public void addContentToFile(String filePath, String content) {\n\n }\n \n public String readContentFromFile(String filePath) {\n\n }\n}\n\n/**\n * Your FileSystem object will be instantiated and called as such:\n * FileSystem obj = new FileSystem();\n * List param_1 = obj.ls(path);\n * obj.mkdir(path);\n * obj.addContentToFile(filePath,content);\n * String param_4 = obj.readContentFromFile(filePath);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class FileSystem(object):\n\n def __init__(self):\n\n\n def ls(self, path):\n \"\"\"\n :type path: str\n :rtype: List[str]\n \"\"\"\n\n\n def mkdir(self, path):\n \"\"\"\n :type path: str\n :rtype: None\n \"\"\"\n\n\n def addContentToFile(self, filePath, content):\n \"\"\"\n :type filePath: str\n :type content: str\n :rtype: None\n \"\"\"\n\n\n def readContentFromFile(self, filePath):\n \"\"\"\n :type filePath: str\n :rtype: str\n \"\"\"\n\n\n\n# Your FileSystem object will be instantiated and called as such:\n# obj = FileSystem()\n# param_1 = obj.ls(path)\n# obj.mkdir(path)\n# obj.addContentToFile(filePath,content)\n# param_4 = obj.readContentFromFile(filePath)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class FileSystem:\n\n def __init__(self):\n\n\n def ls(self, path: str) -> List[str]:\n\n\n def mkdir(self, path: str) -> None:\n\n\n def addContentToFile(self, filePath: str, content: str) -> None:\n\n\n def readContentFromFile(self, filePath: str) -> str:\n\n\n\n# Your FileSystem object will be instantiated and called as such:\n# obj = FileSystem()\n# param_1 = obj.ls(path)\n# obj.mkdir(path)\n# obj.addContentToFile(filePath,content)\n# param_4 = obj.readContentFromFile(filePath)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} FileSystem;\n\n\nFileSystem* fileSystemCreate() {\n \n}\n\nchar ** fileSystemLs(FileSystem* obj, char * path, int* retSize) {\n \n}\n\nvoid fileSystemMkdir(FileSystem* obj, char * path) {\n \n}\n\nvoid fileSystemAddContentToFile(FileSystem* obj, char * filePath, char * content) {\n \n}\n\nchar * fileSystemReadContentFromFile(FileSystem* obj, char * filePath) {\n \n}\n\nvoid fileSystemFree(FileSystem* obj) {\n \n}\n\n/**\n * Your FileSystem struct will be instantiated and called as such:\n * FileSystem* obj = fileSystemCreate();\n * char ** param_1 = fileSystemLs(obj, path, retSize);\n \n * fileSystemMkdir(obj, path);\n \n * fileSystemAddContentToFile(obj, filePath, content);\n \n * char * param_4 = fileSystemReadContentFromFile(obj, filePath);\n \n * fileSystemFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class FileSystem {\n\n public FileSystem() {\n\n }\n \n public IList Ls(string path) {\n\n }\n \n public void Mkdir(string path) {\n\n }\n \n public void AddContentToFile(string filePath, string content) {\n\n }\n \n public string ReadContentFromFile(string filePath) {\n\n }\n}\n\n/**\n * Your FileSystem object will be instantiated and called as such:\n * FileSystem obj = new FileSystem();\n * IList param_1 = obj.Ls(path);\n * obj.Mkdir(path);\n * obj.AddContentToFile(filePath,content);\n * string param_4 = obj.ReadContentFromFile(filePath);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "\nvar FileSystem = function() {\n\n};\n\n/** \n * @param {string} path\n * @return {string[]}\n */\nFileSystem.prototype.ls = function(path) {\n\n};\n\n/** \n * @param {string} path\n * @return {void}\n */\nFileSystem.prototype.mkdir = function(path) {\n\n};\n\n/** \n * @param {string} filePath \n * @param {string} content\n * @return {void}\n */\nFileSystem.prototype.addContentToFile = function(filePath, content) {\n\n};\n\n/** \n * @param {string} filePath\n * @return {string}\n */\nFileSystem.prototype.readContentFromFile = function(filePath) {\n\n};\n\n/**\n * Your FileSystem object will be instantiated and called as such:\n * var obj = new FileSystem()\n * var param_1 = obj.ls(path)\n * obj.mkdir(path)\n * obj.addContentToFile(filePath,content)\n * var param_4 = obj.readContentFromFile(filePath)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class FileSystem\n def initialize()\n\n end\n\n\n=begin\n :type path: String\n :rtype: String[]\n=end\n def ls(path)\n\n end\n\n\n=begin\n :type path: String\n :rtype: Void\n=end\n def mkdir(path)\n\n end\n\n\n=begin\n :type file_path: String\n :type content: String\n :rtype: Void\n=end\n def add_content_to_file(file_path, content)\n\n end\n\n\n=begin\n :type file_path: String\n :rtype: String\n=end\n def read_content_from_file(file_path)\n\n end\n\n\nend\n\n# Your FileSystem object will be instantiated and called as such:\n# obj = FileSystem.new()\n# param_1 = obj.ls(path)\n# obj.mkdir(path)\n# obj.add_content_to_file(file_path, content)\n# param_4 = obj.read_content_from_file(file_path)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass FileSystem {\n\n init() {\n\n }\n \n func ls(_ path: String) -> [String] {\n\n }\n \n func mkdir(_ path: String) {\n\n }\n \n func addContentToFile(_ filePath: String, _ content: String) {\n\n }\n \n func readContentFromFile(_ filePath: String) -> String {\n\n }\n}\n\n/**\n * Your FileSystem object will be instantiated and called as such:\n * let obj = FileSystem()\n * let ret_1: [String] = obj.ls(path)\n * obj.mkdir(path)\n * obj.addContentToFile(filePath, content)\n * let ret_4: String = obj.readContentFromFile(filePath)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type FileSystem struct {\n\n}\n\n\nfunc Constructor() FileSystem {\n\n}\n\n\nfunc (this *FileSystem) Ls(path string) []string {\n\n}\n\n\nfunc (this *FileSystem) Mkdir(path string) {\n\n}\n\n\nfunc (this *FileSystem) AddContentToFile(filePath string, content string) {\n\n}\n\n\nfunc (this *FileSystem) ReadContentFromFile(filePath string) string {\n\n}\n\n\n/**\n * Your FileSystem object will be instantiated and called as such:\n * obj := Constructor();\n * param_1 := obj.Ls(path);\n * obj.Mkdir(path);\n * obj.AddContentToFile(filePath,content);\n * param_4 := obj.ReadContentFromFile(filePath);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class FileSystem() {\n\n def ls(path: String): List[String] = {\n\n }\n\n def mkdir(path: String) {\n\n }\n\n def addContentToFile(filePath: String, content: String) {\n\n }\n\n def readContentFromFile(filePath: String): String = {\n\n }\n\n}\n\n/**\n * Your FileSystem object will be instantiated and called as such:\n * var obj = new FileSystem()\n * var param_1 = obj.ls(path)\n * obj.mkdir(path)\n * obj.addContentToFile(filePath,content)\n * var param_4 = obj.readContentFromFile(filePath)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class FileSystem() {\n\n fun ls(path: String): List {\n\n }\n\n fun mkdir(path: String) {\n\n }\n\n fun addContentToFile(filePath: String, content: String) {\n\n }\n\n fun readContentFromFile(filePath: String): String {\n\n }\n\n}\n\n/**\n * Your FileSystem object will be instantiated and called as such:\n * var obj = FileSystem()\n * var param_1 = obj.ls(path)\n * obj.mkdir(path)\n * obj.addContentToFile(filePath,content)\n * var param_4 = obj.readContentFromFile(filePath)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct FileSystem {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl FileSystem {\n\n fn new() -> Self {\n\n }\n \n fn ls(&self, path: String) -> Vec {\n\n }\n \n fn mkdir(&self, path: String) {\n\n }\n \n fn add_content_to_file(&self, file_path: String, content: String) {\n\n }\n \n fn read_content_from_file(&self, file_path: String) -> String {\n\n }\n}\n\n/**\n * Your FileSystem object will be instantiated and called as such:\n * let obj = FileSystem::new();\n * let ret_1: Vec = obj.ls(path);\n * obj.mkdir(path);\n * obj.add_content_to_file(filePath, content);\n * let ret_4: String = obj.read_content_from_file(filePath);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class FileSystem {\n /**\n */\n function __construct() {\n\n }\n\n /**\n * @param String $path\n * @return String[]\n */\n function ls($path) {\n\n }\n\n /**\n * @param String $path\n * @return NULL\n */\n function mkdir($path) {\n\n }\n\n /**\n * @param String $filePath\n * @param String $content\n * @return NULL\n */\n function addContentToFile($filePath, $content) {\n\n }\n\n /**\n * @param String $filePath\n * @return String\n */\n function readContentFromFile($filePath) {\n\n }\n}\n\n/**\n * Your FileSystem object will be instantiated and called as such:\n * $obj = FileSystem();\n * $ret_1 = $obj->ls($path);\n * $obj->mkdir($path);\n * $obj->addContentToFile($filePath, $content);\n * $ret_4 = $obj->readContentFromFile($filePath);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class FileSystem {\n constructor() {\n\n }\n\n ls(path: string): string[] {\n\n }\n\n mkdir(path: string): void {\n\n }\n\n addContentToFile(filePath: string, content: string): void {\n\n }\n\n readContentFromFile(filePath: string): string {\n\n }\n}\n\n/**\n * Your FileSystem object will be instantiated and called as such:\n * var obj = new FileSystem()\n * var param_1 = obj.ls(path)\n * obj.mkdir(path)\n * obj.addContentToFile(filePath,content)\n * var param_4 = obj.readContentFromFile(filePath)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define file-system%\n (class object%\n (super-new)\n (init-field)\n \n ; ls : string? -> (listof string?)\n (define/public (ls path)\n\n )\n ; mkdir : string? -> void?\n (define/public (mkdir path)\n\n )\n ; add-content-to-file : string? string? -> void?\n (define/public (add-content-to-file filePath content)\n\n )\n ; read-content-from-file : string? -> string?\n (define/public (read-content-from-file filePath)\n\n )))\n\n;; Your file-system% object will be instantiated and called as such:\n;; (define obj (new file-system%))\n;; (define param_1 (send obj ls path))\n;; (send obj mkdir path)\n;; (send obj add-content-to-file file-path content)\n;; (define param_4 (send obj read-content-from-file file-path))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0588](https://leetcode-cn.com/problems/design-in-memory-file-system)", "[\u8bbe\u8ba1\u5185\u5b58\u6587\u4ef6\u7cfb\u7edf](/solution/0500-0599/0588.Design%20In-Memory%20File%20System/README.md)", "`\u8bbe\u8ba1`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0588](https://leetcode.com/problems/design-in-memory-file-system)", "[Design In-Memory File System](/solution/0500-0599/0588.Design%20In-Memory%20File%20System/README_EN.md)", "`Design`", "Hard", "\ud83d\udd12"]}, {"question_id": "0587", "frontend_question_id": "0587", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/erect-the-fence", "url_en": "https://leetcode.com/problems/erect-the-fence", "relative_path_cn": "/solution/0500-0599/0587.Erect%20the%20Fence/README.md", "relative_path_en": "/solution/0500-0599/0587.Erect%20the%20Fence/README_EN.md", "title_cn": "\u5b89\u88c5\u6805\u680f", "title_en": "Erect the Fence", "question_title_slug": "erect-the-fence", "content_en": "

    You are given an array trees where trees[i] = [xi, yi] represents the location of a tree in the garden.

    \n\n

    You are asked to fence the entire garden using the minimum length of rope as it is expensive. The garden is well fenced only if all the trees are enclosed.

    \n\n

    Return the coordinates of trees that are exactly located on the fence perimeter.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: points = [[1,1],[2,2],[2,0],[2,4],[3,3],[4,2]]\nOutput: [[1,1],[2,0],[3,3],[2,4],[4,2]]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: points = [[1,2],[2,2],[4,2]]\nOutput: [[4,2],[2,2],[1,2]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= points.length <= 3000
    • \n\t
    • points[i].length == 2
    • \n\t
    • 0 <= xi, yi <= 100
    • \n\t
    • All the given points are unique.
    • \n
    \n", "content_cn": "

    \u5728\u4e00\u4e2a\u4e8c\u7ef4\u7684\u82b1\u56ed\u4e2d\uff0c\u6709\u4e00\u4e9b\u7528 (x, y) \u5750\u6807\u8868\u793a\u7684\u6811\u3002\u7531\u4e8e\u5b89\u88c5\u8d39\u7528\u5341\u5206\u6602\u8d35\uff0c\u4f60\u7684\u4efb\u52a1\u662f\u5148\u7528\u6700\u77ed\u7684\u7ef3\u5b50\u56f4\u8d77\u6240\u6709\u7684\u6811\u3002\u53ea\u6709\u5f53\u6240\u6709\u7684\u6811\u90fd\u88ab\u7ef3\u5b50\u5305\u56f4\u65f6\uff0c\u82b1\u56ed\u624d\u80fd\u56f4\u597d\u6805\u680f\u3002\u4f60\u9700\u8981\u627e\u5230\u6b63\u597d\u4f4d\u4e8e\u6805\u680f\u8fb9\u754c\u4e0a\u7684\u6811\u7684\u5750\u6807\u3002

    \r\n\r\n

     

    \r\n\r\n

    \u793a\u4f8b 1:

    \r\n\r\n
    \u8f93\u5165: [[1,1],[2,2],[2,0],[2,4],[3,3],[4,2]]\r\n\u8f93\u51fa: [[1,1],[2,0],[4,2],[3,3],[2,4]]\r\n\u89e3\u91ca:\r\n\r\n
    \r\n\r\n

    \u793a\u4f8b 2:

    \r\n\r\n
    \u8f93\u5165: [[1,2],[2,2],[4,2]]\r\n\u8f93\u51fa: [[1,2],[2,2],[4,2]]\r\n\u89e3\u91ca:\r\n\r\n\u5373\u4f7f\u6811\u90fd\u5728\u4e00\u6761\u76f4\u7ebf\u4e0a\uff0c\u4f60\u4e5f\u9700\u8981\u5148\u7528\u7ef3\u5b50\u5305\u56f4\u5b83\u4eec\u3002\r\n
    \r\n\r\n

     

    \r\n\r\n

    \u6ce8\u610f:

    \r\n\r\n
      \r\n\t
    1. \u6240\u6709\u7684\u6811\u5e94\u5f53\u88ab\u56f4\u5728\u4e00\u8d77\u3002\u4f60\u4e0d\u80fd\u526a\u65ad\u7ef3\u5b50\u6765\u5305\u56f4\u6811\u6216\u8005\u628a\u6811\u5206\u6210\u4e00\u7ec4\u4ee5\u4e0a\u3002
    2. \r\n\t
    3. \u8f93\u5165\u7684\u6574\u6570\u5728 0 \u5230 100 \u4e4b\u95f4\u3002
    4. \r\n\t
    5. \u82b1\u56ed\u81f3\u5c11\u6709\u4e00\u68f5\u6811\u3002
    6. \r\n\t
    7. \u6240\u6709\u6811\u7684\u5750\u6807\u90fd\u662f\u4e0d\u540c\u7684\u3002
    8. \r\n\t
    9. \u8f93\u5165\u7684\u70b9\u6ca1\u6709\u987a\u5e8f\u3002\u8f93\u51fa\u987a\u5e8f\u4e5f\u6ca1\u6709\u8981\u6c42\u3002
    10. \r\n
    ", "tags_en": ["Geometry"], "tags_cn": ["\u51e0\u4f55"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> outerTrees(vector>& trees) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[][] outerTrees(int[][] trees) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def outerTrees(self, trees):\n \"\"\"\n :type trees: List[List[int]]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def outerTrees(self, trees: List[List[int]]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** outerTrees(int** trees, int treesSize, int* treesColSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[][] OuterTrees(int[][] trees) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} trees\n * @return {number[][]}\n */\nvar outerTrees = function(trees) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} trees\n# @return {Integer[][]}\ndef outer_trees(trees)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func outerTrees(_ trees: [[Int]]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func outerTrees(trees [][]int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def outerTrees(trees: Array[Array[Int]]): Array[Array[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun outerTrees(trees: Array): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn outer_trees(trees: Vec>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $trees\n * @return Integer[][]\n */\n function outerTrees($trees) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function outerTrees(trees: number[][]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (outer-trees trees)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0587](https://leetcode-cn.com/problems/erect-the-fence)", "[\u5b89\u88c5\u6805\u680f](/solution/0500-0599/0587.Erect%20the%20Fence/README.md)", "`\u51e0\u4f55`", "\u56f0\u96be", ""], "md_table_row_en": ["[0587](https://leetcode.com/problems/erect-the-fence)", "[Erect the Fence](/solution/0500-0599/0587.Erect%20the%20Fence/README_EN.md)", "`Geometry`", "Hard", ""]}, {"question_id": "0586", "frontend_question_id": "0586", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/customer-placing-the-largest-number-of-orders", "url_en": "https://leetcode.com/problems/customer-placing-the-largest-number-of-orders", "relative_path_cn": "/solution/0500-0599/0586.Customer%20Placing%20the%20Largest%20Number%20of%20Orders/README.md", "relative_path_en": "/solution/0500-0599/0586.Customer%20Placing%20the%20Largest%20Number%20of%20Orders/README_EN.md", "title_cn": "\u8ba2\u5355\u6700\u591a\u7684\u5ba2\u6237", "title_en": "Customer Placing the Largest Number of Orders", "question_title_slug": "customer-placing-the-largest-number-of-orders", "content_en": "

    Table: Orders

    \n\n
    \n+-----------------+----------+\n| Column Name     | Type     |\n+-----------------+----------+\n| order_number    | int      |\n| customer_number | int      |\n+-----------------+----------+\norder_number is the primary key for this table.\nThis table contains information about the order ID and the customer ID.\n
    \n\n

     

    \n\n

    Write an SQL query to find the customer_number for the customer who has placed the largest number of orders.

    \n\n

    It is guaranteed that exactly one customer will have placed more orders than any other customer.

    \n\n

    The query result format is in the following example:

    \n\n

     

    \n\n
    \nOrders table:\n+--------------+-----------------+\n| order_number | customer_number |\n+--------------+-----------------+\n| 1            | 1               |\n| 2            | 2               |\n| 3            | 3               |\n| 4            | 3               |\n+--------------+-----------------+\n\nResult table:\n+-----------------+\n| customer_number |\n+-----------------+\n| 3               |\n+-----------------+\nThe customer with number 3 has two orders, which is greater than either customer 1 or 2 because each of them only has one order. \nSo the result is customer_number 3.\n
    \n\n

     

    \nFollow up: What if more than one customer have the largest number of orders, can you find all the customer_number in this case?", "content_cn": "

    \u5728\u8868 orders \u4e2d\u627e\u5230\u8ba2\u5355\u6570\u6700\u591a\u5ba2\u6237\u5bf9\u5e94\u7684 customer_number \u3002

    \n\n

    \u6570\u636e\u4fdd\u8bc1\u8ba2\u5355\u6570\u6700\u591a\u7684\u987e\u5ba2\u6070\u597d\u53ea\u6709\u4e00\u4f4d\u3002

    \n\n

    \u8868 orders \u5b9a\u4e49\u5982\u4e0b\uff1a

    \n\n
    | Column            | Type      |\n|-------------------|-----------|\n| order_number (PK) | int       |\n| customer_number   | int       |\n| order_date        | date      |\n| required_date     | date      |\n| shipped_date      | date      |\n| status            | char(15)  |\n| comment           | char(200) |\n
    \n\n

    \u6837\u4f8b\u8f93\u5165

    \n\n
    | order_number | customer_number | order_date | required_date | shipped_date | status | comment |\n|--------------|-----------------|------------|---------------|--------------|--------|---------|\n| 1            | 1               | 2017-04-09 | 2017-04-13    | 2017-04-12   | Closed |         |\n| 2            | 2               | 2017-04-15 | 2017-04-20    | 2017-04-18   | Closed |         |\n| 3            | 3               | 2017-04-16 | 2017-04-25    | 2017-04-20   | Closed |         |\n| 4            | 3               | 2017-04-18 | 2017-04-28    | 2017-04-25   | Closed |         |\n
    \n\n

    \u6837\u4f8b\u8f93\u51fa

    \n\n
    | customer_number |\n|-----------------|\n| 3               |\n
    \n\n

    \u89e3\u91ca

    \n\n
    customer_number \u4e3a '3' \u7684\u987e\u5ba2\u6709\u4e24\u4e2a\u8ba2\u5355\uff0c\u6bd4\u987e\u5ba2 '1' \u6216\u8005 '2' \u90fd\u8981\u591a\uff0c\u56e0\u4e3a\u4ed6\u4eec\u53ea\u6709\u4e00\u4e2a\u8ba2\u5355\n\u6240\u4ee5\u7ed3\u679c\u662f\u8be5\u987e\u5ba2\u7684 customer_number \uff0c\u4e5f\u5c31\u662f 3 \u3002\n
    \n\n

    \u8fdb\u9636\uff1a \u5982\u679c\u6709\u591a\u4f4d\u987e\u5ba2\u8ba2\u5355\u6570\u5e76\u5217\u6700\u591a\uff0c\u4f60\u80fd\u627e\u5230\u4ed6\u4eec\u6240\u6709\u7684 customer_number \u5417\uff1f

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0586](https://leetcode-cn.com/problems/customer-placing-the-largest-number-of-orders)", "[\u8ba2\u5355\u6700\u591a\u7684\u5ba2\u6237](/solution/0500-0599/0586.Customer%20Placing%20the%20Largest%20Number%20of%20Orders/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0586](https://leetcode.com/problems/customer-placing-the-largest-number-of-orders)", "[Customer Placing the Largest Number of Orders](/solution/0500-0599/0586.Customer%20Placing%20the%20Largest%20Number%20of%20Orders/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "0585", "frontend_question_id": "0585", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/investments-in-2016", "url_en": "https://leetcode.com/problems/investments-in-2016", "relative_path_cn": "/solution/0500-0599/0585.Investments%20in%202016/README.md", "relative_path_en": "/solution/0500-0599/0585.Investments%20in%202016/README_EN.md", "title_cn": "2016\u5e74\u7684\u6295\u8d44", "title_en": "Investments in 2016", "question_title_slug": "investments-in-2016", "content_en": "

    Write a query to print the sum of all total investment values in 2016 (TIV_2016), to a scale of 2 decimal places, for all policy holders who meet the following criteria:

    \r\n\r\n
      \r\n\t
    1. Have the same TIV_2015 value as one or more other policyholders.
    2. \r\n\t
    3. Are not located in the same city as any other policyholder (i.e.: the (latitude, longitude) attribute pairs must be unique).
    4. \r\n
    \r\n\r\n

    Input Format:
    \r\nThe insurance table is described as follows:

    \r\n\r\n
    \r\n| Column Name | Type          |\r\n|-------------|---------------|\r\n| PID         | INTEGER(11)   |\r\n| TIV_2015    | NUMERIC(15,2) |\r\n| TIV_2016    | NUMERIC(15,2) |\r\n| LAT         | NUMERIC(5,2)  |\r\n| LON         | NUMERIC(5,2)  |\r\n
    \r\n\r\n

    where PID is the policyholder's policy ID, TIV_2015 is the total investment value in 2015, TIV_2016 is the total investment value in 2016, LAT is the latitude of the policy holder's city, and LON is the longitude of the policy holder's city.

    \r\n\r\n

    Sample Input

    \r\n\r\n
    \r\n| PID | TIV_2015 | TIV_2016 | LAT | LON |\r\n|-----|----------|----------|-----|-----|\r\n| 1   | 10       | 5        | 10  | 10  |\r\n| 2   | 20       | 20       | 20  | 20  |\r\n| 3   | 10       | 30       | 20  | 20  |\r\n| 4   | 10       | 40       | 40  | 40  |\r\n
    \r\n\r\n

    Sample Output

    \r\n\r\n
    \r\n| TIV_2016 |\r\n|----------|\r\n| 45.00    |\r\n
    \r\n\r\n

    Explanation

    \r\n\r\n
    \r\nThe first record in the table, like the last record, meets both of the two criteria.\r\nThe TIV_2015 value '10' is as the same as the third and forth record, and its location unique.\r\n\r\nThe second record does not meet any of the two criteria. Its TIV_2015 is not like any other policyholders.\r\n\r\nAnd its location is the same with the third record, which makes the third record fail, too.\r\n\r\nSo, the result is the sum of TIV_2016 of the first and last record, which is 45.
    \r\n", "content_cn": "

    \u5199\u4e00\u4e2a\u67e5\u8be2\u8bed\u53e5\uff0c\u5c06 2016 \u5e74 (TIV_2016) \u6240\u6709\u6210\u529f\u6295\u8d44\u7684\u91d1\u989d\u52a0\u8d77\u6765\uff0c\u4fdd\u7559 2 \u4f4d\u5c0f\u6570\u3002

    \n\n

    \u5bf9\u4e8e\u4e00\u4e2a\u6295\u4fdd\u4eba\uff0c\u4ed6\u5728 2016 \u5e74\u6210\u529f\u6295\u8d44\u7684\u6761\u4ef6\u662f\uff1a

    \n\n
      \n\t
    1. \u4ed6\u5728 2015 \u5e74\u7684\u6295\u4fdd\u989d (TIV_2015) \u81f3\u5c11\u8ddf\u4e00\u4e2a\u5176\u4ed6\u6295\u4fdd\u4eba\u5728 2015 \u5e74\u7684\u6295\u4fdd\u989d\u76f8\u540c\u3002
    2. \n\t
    3. \u4ed6\u6240\u5728\u7684\u57ce\u5e02\u5fc5\u987b\u4e0e\u5176\u4ed6\u6295\u4fdd\u4eba\u90fd\u4e0d\u540c\uff08\u4e5f\u5c31\u662f\u8bf4\u7ef4\u5ea6\u548c\u7ecf\u5ea6\u4e0d\u80fd\u8ddf\u5176\u4ed6\u4efb\u4f55\u4e00\u4e2a\u6295\u4fdd\u4eba\u5b8c\u5168\u76f8\u540c\uff09\u3002
    4. \n
    \n\n

    \u8f93\u5165\u683c\u5f0f:
    \n\u8868 insurance \u683c\u5f0f\u5982\u4e0b\uff1a

    \n\n
    | Column Name | Type          |\n|-------------|---------------|\n| PID         | INTEGER(11)   |\n| TIV_2015    | NUMERIC(15,2) |\n| TIV_2016    | NUMERIC(15,2) |\n| LAT         | NUMERIC(5,2)  |\n| LON         | NUMERIC(5,2)  |\n
    \n\n

    PID \u5b57\u6bb5\u662f\u6295\u4fdd\u4eba\u7684\u6295\u4fdd\u7f16\u53f7\uff0c TIV_2015 \u662f\u8be5\u6295\u4fdd\u4eba\u57282015\u5e74\u7684\u603b\u6295\u4fdd\u91d1\u989d\uff0c TIV_2016 \u662f\u8be5\u6295\u4fdd\u4eba\u57282016\u5e74\u7684\u6295\u4fdd\u91d1\u989d\uff0c LAT \u662f\u6295\u4fdd\u4eba\u6240\u5728\u57ce\u5e02\u7684\u7ef4\u5ea6\uff0c LON \u662f\u6295\u4fdd\u4eba\u6240\u5728\u57ce\u5e02\u7684\u7ecf\u5ea6\u3002

    \n\n

    \u6837\u4f8b\u8f93\u5165

    \n\n
    | PID | TIV_2015 | TIV_2016 | LAT | LON |\n|-----|----------|----------|-----|-----|\n| 1   | 10       | 5        | 10  | 10  |\n| 2   | 20       | 20       | 20  | 20  |\n| 3   | 10       | 30       | 20  | 20  |\n| 4   | 10       | 40       | 40  | 40  |\n
    \n\n

    \u6837\u4f8b\u8f93\u51fa

    \n\n
    | TIV_2016 |\n|----------|\n| 45.00    |\n
    \n\n

    \u89e3\u91ca

    \n\n
    \u5c31\u5982\u6700\u540e\u4e00\u4e2a\u6295\u4fdd\u4eba\uff0c\u7b2c\u4e00\u4e2a\u6295\u4fdd\u4eba\u540c\u65f6\u6ee1\u8db3\u4e24\u4e2a\u6761\u4ef6\uff1a\n1. \u4ed6\u5728 2015 \u5e74\u7684\u6295\u4fdd\u91d1\u989d TIV_2015 \u4e3a '10' \uff0c\u4e0e\u7b2c\u4e09\u4e2a\u548c\u7b2c\u56db\u4e2a\u6295\u4fdd\u4eba\u5728 2015 \u5e74\u7684\u6295\u4fdd\u91d1\u989d\u76f8\u540c\u3002\n2. \u4ed6\u6240\u5728\u57ce\u5e02\u7684\u7ecf\u7eac\u5ea6\u662f\u72ec\u4e00\u65e0\u4e8c\u7684\u3002\n\n\u7b2c\u4e8c\u4e2a\u6295\u4fdd\u4eba\u4e24\u4e2a\u6761\u4ef6\u90fd\u4e0d\u6ee1\u8db3\u3002\u4ed6\u5728 2015 \u5e74\u7684\u6295\u8d44 TIV_2015 \u4e0e\u5176\u4ed6\u4efb\u4f55\u6295\u4fdd\u4eba\u90fd\u4e0d\u76f8\u540c\u3002\n\u4e14\u4ed6\u6240\u5728\u57ce\u5e02\u7684\u7ecf\u7eac\u5ea6\u4e0e\u7b2c\u4e09\u4e2a\u6295\u4fdd\u4eba\u76f8\u540c\u3002\u57fa\u4e8e\u540c\u6837\u7684\u539f\u56e0\uff0c\u7b2c\u4e09\u4e2a\u6295\u4fdd\u4eba\u6295\u8d44\u5931\u8d25\u3002\n\n\u6240\u4ee5\u8fd4\u56de\u7684\u7ed3\u679c\u662f\u7b2c\u4e00\u4e2a\u6295\u4fdd\u4eba\u548c\u6700\u540e\u4e00\u4e2a\u6295\u4fdd\u4eba\u7684 TIV_2016 \u4e4b\u548c\uff0c\u7ed3\u679c\u662f 45 \u3002
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0585](https://leetcode-cn.com/problems/investments-in-2016)", "[2016\u5e74\u7684\u6295\u8d44](/solution/0500-0599/0585.Investments%20in%202016/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0585](https://leetcode.com/problems/investments-in-2016)", "[Investments in 2016](/solution/0500-0599/0585.Investments%20in%202016/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "0584", "frontend_question_id": "0584", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/find-customer-referee", "url_en": "https://leetcode.com/problems/find-customer-referee", "relative_path_cn": "/solution/0500-0599/0584.Find%20Customer%20Referee/README.md", "relative_path_en": "/solution/0500-0599/0584.Find%20Customer%20Referee/README_EN.md", "title_cn": "\u5bfb\u627e\u7528\u6237\u63a8\u8350\u4eba", "title_en": "Find Customer Referee", "question_title_slug": "find-customer-referee", "content_en": "

    Given a table customer holding customers information and the referee.

    \r\n\r\n
    \r\n+------+------+-----------+\r\n| id   | name | referee_id|\r\n+------+------+-----------+\r\n|    1 | Will |      NULL |\r\n|    2 | Jane |      NULL |\r\n|    3 | Alex |         2 |\r\n|    4 | Bill |      NULL |\r\n|    5 | Zack |         1 |\r\n|    6 | Mark |         2 |\r\n+------+------+-----------+\r\n
    \r\n\r\n

    Write a query to return the list of customers NOT referred by the person with id '2'.

    \r\n\r\n

    For the sample data above, the result is:

    \r\n\r\n
    \r\n+------+\r\n| name |\r\n+------+\r\n| Will |\r\n| Jane |\r\n| Bill |\r\n| Zack |\r\n+------+\r\n
    \r\n", "content_cn": "

    \u7ed9\u5b9a\u8868\u00a0customer\u00a0\uff0c\u91cc\u9762\u4fdd\u5b58\u4e86\u6240\u6709\u5ba2\u6237\u4fe1\u606f\u548c\u4ed6\u4eec\u7684\u63a8\u8350\u4eba\u3002

    \n\n
    \n+------+------+-----------+\n| id   | name | referee_id|\n+------+------+-----------+\n|    1 | Will |      NULL |\n|    2 | Jane |      NULL |\n|    3 | Alex |         2 |\n|    4 | Bill |      NULL |\n|    5 | Zack |         1 |\n|    6 | Mark |         2 |\n+------+------+-----------+\n
    \n\n

    \u5199\u4e00\u4e2a\u67e5\u8be2\u8bed\u53e5\uff0c\u8fd4\u56de\u4e00\u4e2a\u5ba2\u6237\u5217\u8868\uff0c\u5217\u8868\u4e2d\u5ba2\u6237\u7684\u63a8\u8350\u4eba\u7684\u7f16\u53f7\u90fd\u00a0\u4e0d\u662f 2\u3002

    \n\n

    \u5bf9\u4e8e\u4e0a\u9762\u7684\u793a\u4f8b\u6570\u636e\uff0c\u7ed3\u679c\u4e3a\uff1a

    \n\n
    \n+------+\n| name |\n+------+\n| Will |\n| Jane |\n| Bill |\n| Zack |\n+------+\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0584](https://leetcode-cn.com/problems/find-customer-referee)", "[\u5bfb\u627e\u7528\u6237\u63a8\u8350\u4eba](/solution/0500-0599/0584.Find%20Customer%20Referee/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0584](https://leetcode.com/problems/find-customer-referee)", "[Find Customer Referee](/solution/0500-0599/0584.Find%20Customer%20Referee/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "0583", "frontend_question_id": "0583", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/delete-operation-for-two-strings", "url_en": "https://leetcode.com/problems/delete-operation-for-two-strings", "relative_path_cn": "/solution/0500-0599/0583.Delete%20Operation%20for%20Two%20Strings/README.md", "relative_path_en": "/solution/0500-0599/0583.Delete%20Operation%20for%20Two%20Strings/README_EN.md", "title_cn": "\u4e24\u4e2a\u5b57\u7b26\u4e32\u7684\u5220\u9664\u64cd\u4f5c", "title_en": "Delete Operation for Two Strings", "question_title_slug": "delete-operation-for-two-strings", "content_en": "

    Given two strings word1 and word2, return the minimum number of steps required to make word1 and word2 the same.

    \n\n

    In one step, you can delete exactly one character in either string.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: word1 = "sea", word2 = "eat"\nOutput: 2\nExplanation: You need one step to make "sea" to "ea" and another step to make "eat" to "ea".\n
    \n\n

    Example 2:

    \n\n
    \nInput: word1 = "leetcode", word2 = "etco"\nOutput: 4\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= word1.length, word2.length <= 500
    • \n\t
    • word1 and word2 consist of only lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u5355\u8bcd word1 \u548c word2\uff0c\u627e\u5230\u4f7f\u5f97 word1 \u548c word2 \u76f8\u540c\u6240\u9700\u7684\u6700\u5c0f\u6b65\u6570\uff0c\u6bcf\u6b65\u53ef\u4ee5\u5220\u9664\u4efb\u610f\u4e00\u4e2a\u5b57\u7b26\u4e32\u4e2d\u7684\u4e00\u4e2a\u5b57\u7b26\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165: "sea", "eat"\n\u8f93\u51fa: 2\n\u89e3\u91ca: \u7b2c\u4e00\u6b65\u5c06"sea"\u53d8\u4e3a"ea"\uff0c\u7b2c\u4e8c\u6b65\u5c06"eat"\u53d8\u4e3a"ea"\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. \u7ed9\u5b9a\u5355\u8bcd\u7684\u957f\u5ea6\u4e0d\u8d85\u8fc7500\u3002
    2. \n\t
    3. \u7ed9\u5b9a\u5355\u8bcd\u4e2d\u7684\u5b57\u7b26\u53ea\u542b\u6709\u5c0f\u5199\u5b57\u6bcd\u3002
    4. \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minDistance(string word1, string word2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minDistance(String word1, String word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minDistance(self, word1, word2):\n \"\"\"\n :type word1: str\n :type word2: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minDistance(self, word1: str, word2: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minDistance(char * word1, char * word2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinDistance(string word1, string word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} word1\n * @param {string} word2\n * @return {number}\n */\nvar minDistance = function(word1, word2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} word1\n# @param {String} word2\n# @return {Integer}\ndef min_distance(word1, word2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minDistance(_ word1: String, _ word2: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minDistance(word1 string, word2 string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minDistance(word1: String, word2: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minDistance(word1: String, word2: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_distance(word1: String, word2: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $word1\n * @param String $word2\n * @return Integer\n */\n function minDistance($word1, $word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minDistance(word1: string, word2: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-distance word1 word2)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0583](https://leetcode-cn.com/problems/delete-operation-for-two-strings)", "[\u4e24\u4e2a\u5b57\u7b26\u4e32\u7684\u5220\u9664\u64cd\u4f5c](/solution/0500-0599/0583.Delete%20Operation%20for%20Two%20Strings/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0583](https://leetcode.com/problems/delete-operation-for-two-strings)", "[Delete Operation for Two Strings](/solution/0500-0599/0583.Delete%20Operation%20for%20Two%20Strings/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "0582", "frontend_question_id": "0582", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/kill-process", "url_en": "https://leetcode.com/problems/kill-process", "relative_path_cn": "/solution/0500-0599/0582.Kill%20Process/README.md", "relative_path_en": "/solution/0500-0599/0582.Kill%20Process/README_EN.md", "title_cn": "\u6740\u6389\u8fdb\u7a0b", "title_en": "Kill Process", "question_title_slug": "kill-process", "content_en": "

    You have n processes forming a rooted tree structure. You are given two integer arrays pid and ppid, where pid[i] is the ID of the ith process and ppid[i] is the ID of the ith process's parent process.

    \n\n

    Each process has only one parent process but may have multiple children processes. Only one process has ppid[i] = 0, which means this process has no parent process (the root of the tree).

    \n\n

    When a process is killed, all of its children processes will also be killed.

    \n\n

    Given an integer kill representing the ID of a process you want to kill, return a list of the IDs of the processes that will be killed. You may return the answer in any order.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: pid = [1,3,10,5], ppid = [3,0,5,3], kill = 5\nOutput: [5,10]\nExplanation: The processes colored in red are the processes that should be killed.\n
    \n\n

    Example 2:

    \n\n
    \nInput: pid = [1], ppid = [0], kill = 1\nOutput: [1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == pid.length
    • \n\t
    • n == ppid.length
    • \n\t
    • 1 <= n <= 5 * 104
    • \n\t
    • 1 <= pid[i] <= 5 * 104
    • \n\t
    • 0 <= ppid[i] <= 5 * 104
    • \n\t
    • Only one process has no parent.
    • \n\t
    • All the values of pid are unique.
    • \n\t
    • kill is guaranteed to be in pid.
    • \n
    \n", "content_cn": "

    \u7cfb\u7edf\u4e2d\u5b58\u5728 n\u00a0\u4e2a\u8fdb\u7a0b\uff0c\u5f62\u6210\u4e00\u4e2a\u6709\u6839\u6811\u7ed3\u6784\u3002\u7ed9\u4f60\u4e24\u4e2a\u6574\u6570\u6570\u7ec4\u00a0pid \u548c ppid \uff0c\u5176\u4e2d pid[i] \u662f\u7b2c i \u4e2a\u8fdb\u7a0b\u7684 ID \uff0cppid[i] \u662f\u7b2c i \u4e2a\u8fdb\u7a0b\u7684\u7236\u8fdb\u7a0b ID \u3002

    \n\n

    \u6bcf\u4e00\u4e2a\u8fdb\u7a0b\u53ea\u6709 \u4e00\u4e2a\u7236\u8fdb\u7a0b \uff0c\u4f46\u662f\u53ef\u80fd\u4f1a\u6709 \u4e00\u4e2a\u6216\u8005\u591a\u4e2a\u5b50\u8fdb\u7a0b \u3002\u53ea\u6709\u4e00\u4e2a\u8fdb\u7a0b\u7684 ppid[i] = 0 \uff0c\u610f\u5473\u7740\u8fd9\u4e2a\u8fdb\u7a0b \u6ca1\u6709\u7236\u8fdb\u7a0b \u3002

    \n\n

    \u5f53\u4e00\u4e2a\u8fdb\u7a0b \u88ab\u6740\u6389 \u7684\u65f6\u5019\uff0c\u5b83\u6240\u6709\u7684\u5b50\u8fdb\u7a0b\u548c\u540e\u4ee3\u8fdb\u7a0b\u90fd\u8981\u88ab\u6740\u6389\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 kill \u8868\u793a\u8981\u6740\u6389\u200b\u200b\u8fdb\u7a0b\u7684 ID \uff0c\u8fd4\u56de\u6740\u6389\u8be5\u8fdb\u7a0b\u540e\u7684\u6240\u6709\u8fdb\u7a0b ID \u7684\u5217\u8868\u3002\u53ef\u4ee5\u6309 \u4efb\u610f\u987a\u5e8f \u8fd4\u56de\u7b54\u6848\u3002

    \n\u00a0\n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1apid = [1,3,10,5], ppid = [3,0,5,3], kill = 5\n\u8f93\u51fa\uff1a[5,10]\n\u89e3\u91ca\uff1a\u6d82\u4e3a\u7ea2\u8272\u7684\u8fdb\u7a0b\u662f\u5e94\u8be5\u88ab\u6740\u6389\u7684\u8fdb\u7a0b\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1apid = [1], ppid = [0], kill = 1\n\u8f93\u51fa\uff1a[1]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == pid.length
    • \n\t
    • n == ppid.length
    • \n\t
    • 1 <= n <= 5 * 104
    • \n\t
    • 1 <= pid[i] <= 5 * 104
    • \n\t
    • 0 <= ppid[i] <= 5 * 104
    • \n\t
    • \u4ec5\u6709\u4e00\u4e2a\u8fdb\u7a0b\u6ca1\u6709\u7236\u8fdb\u7a0b
    • \n\t
    • pid \u4e2d\u7684\u6240\u6709\u503c \u4e92\u4e0d\u76f8\u540c
    • \n\t
    • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1 kill \u5728 pid \u4e2d
    • \n
    \n", "tags_en": ["Tree", "Queue"], "tags_cn": ["\u6811", "\u961f\u5217"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector killProcess(vector& pid, vector& ppid, int kill) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List killProcess(List pid, List ppid, int kill) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def killProcess(self, pid, ppid, kill):\n \"\"\"\n :type pid: List[int]\n :type ppid: List[int]\n :type kill: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def killProcess(self, pid: List[int], ppid: List[int], kill: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* killProcess(int* pid, int pidSize, int* ppid, int ppidSize, int kill, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList KillProcess(IList pid, IList ppid, int kill) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} pid\n * @param {number[]} ppid\n * @param {number} kill\n * @return {number[]}\n */\nvar killProcess = function(pid, ppid, kill) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} pid\n# @param {Integer[]} ppid\n# @param {Integer} kill\n# @return {Integer[]}\ndef kill_process(pid, ppid, kill)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func killProcess(_ pid: [Int], _ ppid: [Int], _ kill: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func killProcess(pid []int, ppid []int, kill int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def killProcess(pid: List[Int], ppid: List[Int], kill: Int): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun killProcess(pid: List, ppid: List, kill: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn kill_process(pid: Vec, ppid: Vec, kill: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $pid\n * @param Integer[] $ppid\n * @param Integer $kill\n * @return Integer[]\n */\n function killProcess($pid, $ppid, $kill) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function killProcess(pid: number[], ppid: number[], kill: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (kill-process pid ppid kill)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0582](https://leetcode-cn.com/problems/kill-process)", "[\u6740\u6389\u8fdb\u7a0b](/solution/0500-0599/0582.Kill%20Process/README.md)", "`\u6811`,`\u961f\u5217`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0582](https://leetcode.com/problems/kill-process)", "[Kill Process](/solution/0500-0599/0582.Kill%20Process/README_EN.md)", "`Tree`,`Queue`", "Medium", "\ud83d\udd12"]}, {"question_id": "0581", "frontend_question_id": "0581", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/shortest-unsorted-continuous-subarray", "url_en": "https://leetcode.com/problems/shortest-unsorted-continuous-subarray", "relative_path_cn": "/solution/0500-0599/0581.Shortest%20Unsorted%20Continuous%20Subarray/README.md", "relative_path_en": "/solution/0500-0599/0581.Shortest%20Unsorted%20Continuous%20Subarray/README_EN.md", "title_cn": "\u6700\u77ed\u65e0\u5e8f\u8fde\u7eed\u5b50\u6570\u7ec4", "title_en": "Shortest Unsorted Continuous Subarray", "question_title_slug": "shortest-unsorted-continuous-subarray", "content_en": "

    Given an integer array nums, you need to find one continuous subarray that if you only sort this subarray in ascending order, then the whole array will be sorted in ascending order.

    \n\n

    Return the shortest such subarray and output its length.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [2,6,4,8,10,9,15]\nOutput: 5\nExplanation: You need to sort [6, 4, 8, 10, 9] in ascending order to make the whole array sorted in ascending order.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,2,3,4]\nOutput: 0\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [1]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 104
    • \n\t
    • -105 <= nums[i] <= 105
    • \n
    \n\n

     

    \nFollow up: Can you solve it in O(n) time complexity?", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \uff0c\u4f60\u9700\u8981\u627e\u51fa\u4e00\u4e2a \u8fde\u7eed\u5b50\u6570\u7ec4 \uff0c\u5982\u679c\u5bf9\u8fd9\u4e2a\u5b50\u6570\u7ec4\u8fdb\u884c\u5347\u5e8f\u6392\u5e8f\uff0c\u90a3\u4e48\u6574\u4e2a\u6570\u7ec4\u90fd\u4f1a\u53d8\u4e3a\u5347\u5e8f\u6392\u5e8f\u3002

    \n\n

    \u8bf7\u4f60\u627e\u51fa\u7b26\u5408\u9898\u610f\u7684 \u6700\u77ed \u5b50\u6570\u7ec4\uff0c\u5e76\u8f93\u51fa\u5b83\u7684\u957f\u5ea6\u3002

    \n\n

    \u00a0

    \n\n
    \n
    \n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [2,6,4,8,10,9,15]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u4f60\u53ea\u9700\u8981\u5bf9 [6, 4, 8, 10, 9] \u8fdb\u884c\u5347\u5e8f\u6392\u5e8f\uff0c\u90a3\u4e48\u6574\u4e2a\u8868\u90fd\u4f1a\u53d8\u4e3a\u5347\u5e8f\u6392\u5e8f\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,3,4]\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1]\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 104
    • \n\t
    • -105 <= nums[i] <= 105
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u53ef\u4ee5\u8bbe\u8ba1\u4e00\u4e2a\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n) \u7684\u89e3\u51b3\u65b9\u6848\u5417\uff1f

    \n
    \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findUnsortedSubarray(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findUnsortedSubarray(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findUnsortedSubarray(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findUnsortedSubarray(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findUnsortedSubarray(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindUnsortedSubarray(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar findUnsortedSubarray = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef find_unsorted_subarray(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findUnsortedSubarray(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findUnsortedSubarray(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findUnsortedSubarray(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findUnsortedSubarray(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_unsorted_subarray(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function findUnsortedSubarray($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findUnsortedSubarray(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-unsorted-subarray nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0581](https://leetcode-cn.com/problems/shortest-unsorted-continuous-subarray)", "[\u6700\u77ed\u65e0\u5e8f\u8fde\u7eed\u5b50\u6570\u7ec4](/solution/0500-0599/0581.Shortest%20Unsorted%20Continuous%20Subarray/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0581](https://leetcode.com/problems/shortest-unsorted-continuous-subarray)", "[Shortest Unsorted Continuous Subarray](/solution/0500-0599/0581.Shortest%20Unsorted%20Continuous%20Subarray/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0580", "frontend_question_id": "0580", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/count-student-number-in-departments", "url_en": "https://leetcode.com/problems/count-student-number-in-departments", "relative_path_cn": "/solution/0500-0599/0580.Count%20Student%20Number%20in%20Departments/README.md", "relative_path_en": "/solution/0500-0599/0580.Count%20Student%20Number%20in%20Departments/README_EN.md", "title_cn": "\u7edf\u8ba1\u5404\u4e13\u4e1a\u5b66\u751f\u4eba\u6570", "title_en": "Count Student Number in Departments", "question_title_slug": "count-student-number-in-departments", "content_en": "

    A university uses 2 data tables, student and department, to store data about its students and the departments associated with each major.

    \r\n\r\n

    Write a query to print the respective department name and number of students majoring in each department for all departments in the department table (even ones with no current students).

    \r\n\r\n

    Sort your results by descending number of students; if two or more departments have the same number of students, then sort those departments alphabetically by department name.

    \r\n\r\n

    The student is described as follow:

    \r\n\r\n
    \r\n| Column Name  | Type      |\r\n|--------------|-----------|\r\n| student_id   | Integer   |\r\n| student_name | String    |\r\n| gender       | Character |\r\n| dept_id      | Integer   |\r\n
    \r\n\r\n

    where student_id is the student's ID number, student_name is the student's name, gender is their gender, and dept_id is the department ID associated with their declared major.

    \r\n\r\n

    And the department table is described as below:

    \r\n\r\n
    \r\n| Column Name | Type    |\r\n|-------------|---------|\r\n| dept_id     | Integer |\r\n| dept_name   | String  |\r\n
    \r\n\r\n

    where dept_id is the department's ID number and dept_name is the department name.

    \r\n\r\n

    Here is an example input:
    \r\nstudent table:

    \r\n\r\n
    \r\n| student_id | student_name | gender | dept_id |\r\n|------------|--------------|--------|---------|\r\n| 1          | Jack         | M      | 1       |\r\n| 2          | Jane         | F      | 1       |\r\n| 3          | Mark         | M      | 2       |\r\n
    \r\n\r\n

    department table:

    \r\n\r\n
    \r\n| dept_id | dept_name   |\r\n|---------|-------------|\r\n| 1       | Engineering |\r\n| 2       | Science     |\r\n| 3       | Law         |\r\n
    \r\n\r\n

    The Output should be:

    \r\n\r\n
    \r\n| dept_name   | student_number |\r\n|-------------|----------------|\r\n| Engineering | 2              |\r\n| Science     | 1              |\r\n| Law         | 0              |\r\n
    \r\n", "content_cn": "

    \u4e00\u6240\u5927\u5b66\u6709 2 \u4e2a\u6570\u636e\u8868\uff0c\u5206\u522b\u662f student \u548c department \uff0c\u8fd9\u4e24\u4e2a\u8868\u4fdd\u5b58\u7740\u6bcf\u4e2a\u4e13\u4e1a\u7684\u5b66\u751f\u6570\u636e\u548c\u9662\u7cfb\u6570\u636e\u3002

    \n\n

    \u5199\u4e00\u4e2a\u67e5\u8be2\u8bed\u53e5\uff0c\u67e5\u8be2 department \u8868\u4e2d\u6bcf\u4e2a\u4e13\u4e1a\u7684\u5b66\u751f\u4eba\u6570 \uff08\u5373\u4f7f\u6ca1\u6709\u5b66\u751f\u7684\u4e13\u4e1a\u4e5f\u9700\u5217\u51fa\uff09\u3002

    \n\n

    \u5c06\u4f60\u7684\u67e5\u8be2\u7ed3\u679c\u6309\u7167\u5b66\u751f\u4eba\u6570\u964d\u5e8f\u6392\u5217\u3002 \u5982\u679c\u6709\u4e24\u4e2a\u6216\u4e24\u4e2a\u4ee5\u4e0a\u4e13\u4e1a\u6709\u76f8\u540c\u7684\u5b66\u751f\u6570\u76ee\uff0c\u5c06\u8fd9\u4e9b\u90e8\u95e8\u6309\u7167\u90e8\u95e8\u540d\u5b57\u7684\u5b57\u5178\u5e8f\u4ece\u5c0f\u5230\u5927\u6392\u5217\u3002

    \n\n

    student \u8868\u683c\u5982\u4e0b\uff1a

    \n\n
    | Column Name  | Type      |\n|--------------|-----------|\n| student_id   | Integer   |\n| student_name | String    |\n| gender       | Character |\n| dept_id      | Integer   |\n
    \n\n

    \u5176\u4e2d\uff0c student_id \u662f\u5b66\u751f\u7684\u5b66\u53f7\uff0c student_name \u662f\u5b66\u751f\u7684\u59d3\u540d\uff0c gender \u662f\u5b66\u751f\u7684\u6027\u522b\uff0c dept_id \u662f\u5b66\u751f\u6240\u5c5e\u4e13\u4e1a\u7684\u4e13\u4e1a\u7f16\u53f7\u3002

    \n\n

    department \u8868\u683c\u5982\u4e0b\uff1a

    \n\n
    | Column Name | Type    |\n|-------------|---------|\n| dept_id     | Integer |\n| dept_name   | String  |\n
    \n\n

    dept_id \u662f\u4e13\u4e1a\u7f16\u53f7\uff0c dept_name \u662f\u4e13\u4e1a\u540d\u5b57\u3002

    \n\n

    \u8fd9\u91cc\u662f\u4e00\u4e2a\u793a\u4f8b\u8f93\u5165\uff1a
    \nstudent \u8868\u683c\uff1a

    \n\n
    | student_id | student_name | gender | dept_id |\n|------------|--------------|--------|---------|\n| 1          | Jack         | M      | 1       |\n| 2          | Jane         | F      | 1       |\n| 3          | Mark         | M      | 2       |\n
    \n\n

    department \u8868\u683c\uff1a

    \n\n
    | dept_id | dept_name   |\n|---------|-------------|\n| 1       | Engineering |\n| 2       | Science     |\n| 3       | Law         |\n
    \n\n

    \u793a\u4f8b\u8f93\u51fa\u4e3a\uff1a

    \n\n
    | dept_name   | student_number |\n|-------------|----------------|\n| Engineering | 2              |\n| Science     | 1              |\n| Law         | 0              |\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0580](https://leetcode-cn.com/problems/count-student-number-in-departments)", "[\u7edf\u8ba1\u5404\u4e13\u4e1a\u5b66\u751f\u4eba\u6570](/solution/0500-0599/0580.Count%20Student%20Number%20in%20Departments/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0580](https://leetcode.com/problems/count-student-number-in-departments)", "[Count Student Number in Departments](/solution/0500-0599/0580.Count%20Student%20Number%20in%20Departments/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "0579", "frontend_question_id": "0579", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/find-cumulative-salary-of-an-employee", "url_en": "https://leetcode.com/problems/find-cumulative-salary-of-an-employee", "relative_path_cn": "/solution/0500-0599/0579.Find%20Cumulative%20Salary%20of%20an%20Employee/README.md", "relative_path_en": "/solution/0500-0599/0579.Find%20Cumulative%20Salary%20of%20an%20Employee/README_EN.md", "title_cn": "\u67e5\u8be2\u5458\u5de5\u7684\u7d2f\u8ba1\u85aa\u6c34", "title_en": "Find Cumulative Salary of an Employee", "question_title_slug": "find-cumulative-salary-of-an-employee", "content_en": "

    The Employee table holds the salary information in a year.

    \r\n\r\n

    Write a SQL to get the cumulative sum of an employee's salary over a period of 3 months but exclude the most recent month.

    \r\n\r\n

    The result should be displayed by 'Id' ascending, and then by 'Month' descending.

    \r\n\r\n

    Example
    \r\nInput

    \r\n\r\n
    \r\n| Id | Month | Salary |\r\n|----|-------|--------|\r\n| 1  | 1     | 20     |\r\n| 2  | 1     | 20     |\r\n| 1  | 2     | 30     |\r\n| 2  | 2     | 30     |\r\n| 3  | 2     | 40     |\r\n| 1  | 3     | 40     |\r\n| 3  | 3     | 60     |\r\n| 1  | 4     | 60     |\r\n| 3  | 4     | 70     |\r\n
    \r\nOutput\r\n\r\n
    \r\n\r\n| Id | Month | Salary |\r\n|----|-------|--------|\r\n| 1  | 3     | 90     |\r\n| 1  | 2     | 50     |\r\n| 1  | 1     | 20     |\r\n| 2  | 1     | 20     |\r\n| 3  | 3     | 100    |\r\n| 3  | 2     | 40     |\r\n
    \r\n\r\n

     

    \r\nExplanation\r\n\r\n

    Employee '1' has 3 salary records for the following 3 months except the most recent month '4': salary 40 for month '3', 30 for month '2' and 20 for month '1'
    \r\nSo the cumulative sum of salary of this employee over 3 months is 90(40+30+20), 50(30+20) and 20 respectively.

    \r\n\r\n
    \r\n| Id | Month | Salary |\r\n|----|-------|--------|\r\n| 1  | 3     | 90     |\r\n| 1  | 2     | 50     |\r\n| 1  | 1     | 20     |\r\n
    \r\nEmployee '2' only has one salary record (month '1') except its most recent month '2'.\r\n\r\n
    \r\n| Id | Month | Salary |\r\n|----|-------|--------|\r\n| 2  | 1     | 20     |\r\n
    \r\n\r\n

     

    \r\nEmploy '3' has two salary records except its most recent pay month '4': month '3' with 60 and month '2' with 40. So the cumulative salary is as following.\r\n\r\n
    \r\n| Id | Month | Salary |\r\n|----|-------|--------|\r\n| 3  | 3     | 100    |\r\n| 3  | 2     | 40     |\r\n
    \r\n\r\n

     

    \r\n", "content_cn": "

    Employee \u8868\u4fdd\u5b58\u4e86\u4e00\u5e74\u5185\u7684\u85aa\u6c34\u4fe1\u606f\u3002

    \n\n

    \u8bf7\u4f60\u7f16\u5199 SQL \u8bed\u53e5\uff0c\u5bf9\u4e8e\u6bcf\u4e2a\u5458\u5de5\uff0c\u67e5\u8be2\u4ed6\u9664\u6700\u8fd1\u4e00\u4e2a\u6708\uff08\u5373\u6700\u5927\u6708\uff09\u4e4b\u5916\uff0c\u5269\u4e0b\u6bcf\u4e2a\u6708\u7684\u8fd1\u4e09\u4e2a\u6708\u7684\u7d2f\u8ba1\u85aa\u6c34\uff08\u4e0d\u8db3\u4e09\u4e2a\u6708\u4e5f\u8981\u8ba1\u7b97\uff09\u3002

    \n\n

    \u7ed3\u679c\u8bf7\u6309 Id \u5347\u5e8f\uff0c\u7136\u540e\u6309 Month \u964d\u5e8f\u663e\u793a\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a
    \n\u8f93\u5165\uff1a

    \n\n
    \n| Id | Month | Salary |\n|----|-------|--------|\n| 1  | 1     | 20     |\n| 2  | 1     | 20     |\n| 1  | 2     | 30     |\n| 2  | 2     | 30     |\n| 3  | 2     | 40     |\n| 1  | 3     | 40     |\n| 3  | 3     | 60     |\n| 1  | 4     | 60     |\n| 3  | 4     | 70     |\n
    \n\n

    \u8f93\u51fa\uff1a

    \n\n
    \n| Id | Month | Salary |\n|----|-------|--------|\n| 1  | 3     | 90     |\n| 1  | 2     | 50     |\n| 1  | 1     | 20     |\n| 2  | 1     | 20     |\n| 3  | 3     | 100    |\n| 3  | 2     | 40     |\n
    \n\n

    \u00a0

    \n\n

    \u89e3\u91ca\uff1a

    \n\n

    \u5458\u5de5 '1'\u00a0\u9664\u53bb\u6700\u8fd1\u4e00\u4e2a\u6708\uff08\u6708\u4efd '4'\uff09\uff0c\u6709\u4e09\u4e2a\u6708\u7684\u85aa\u6c34\u8bb0\u5f55\uff1a\u6708\u4efd '3'\u00a0\u85aa\u6c34\u4e3a\u00a040\uff0c\u6708\u4efd '2'\u00a0\u85aa\u6c34\u4e3a 30\uff0c\u6708\u4efd '1'\u00a0\u85aa\u6c34\u4e3a 20\u3002

    \n\n

    \u6240\u4ee5\u8fd1 3 \u4e2a\u6708\u7684\u85aa\u6c34\u7d2f\u8ba1\u5206\u522b\u4e3a\u00a0(40 + 30 + 20) =\u00a090\uff0c(30 + 20) = 50 \u548c 20\u3002

    \n\n
    \n| Id | Month | Salary |\n|----|-------|--------|\n| 1  | 3     | 90     |\n| 1  | 2     | 50     |\n| 1  | 1     | 20     |\n
    \n\n

    \u5458\u5de5 '2' \u9664\u53bb\u6700\u8fd1\u7684\u4e00\u4e2a\u6708\uff08\u6708\u4efd '2'\uff09\u7684\u8bdd\uff0c\u53ea\u6709\u6708\u4efd '1' \u8fd9\u4e00\u4e2a\u6708\u7684\u85aa\u6c34\u8bb0\u5f55\u3002

    \n\n
    \n| Id | Month | Salary |\n|----|-------|--------|\n| 2  | 1     | 20     |\n
    \n\n

    \u5458\u5de5 '3' \u9664\u53bb\u6700\u8fd1\u4e00\u4e2a\u6708\uff08\u6708\u4efd '4'\uff09\u540e\u6709\u4e24\u4e2a\u6708\uff0c\u5206\u522b\u4e3a\uff1a\u6708\u4efd '3' \u85aa\u6c34\u4e3a 60 \u548c \u6708\u4efd '2' \u85aa\u6c34\u4e3a 40\u3002\u6240\u4ee5\u5404\u6708\u7684\u7d2f\u8ba1\u60c5\u51b5\u5982\u4e0b\uff1a

    \n\n
    \n| Id | Month | Salary |\n|----|-------|--------|\n| 3  | 3     | 100    |\n| 3  | 2     | 40     |\n
    \n\n

    \u00a0

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0579](https://leetcode-cn.com/problems/find-cumulative-salary-of-an-employee)", "[\u67e5\u8be2\u5458\u5de5\u7684\u7d2f\u8ba1\u85aa\u6c34](/solution/0500-0599/0579.Find%20Cumulative%20Salary%20of%20an%20Employee/README.md)", "", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0579](https://leetcode.com/problems/find-cumulative-salary-of-an-employee)", "[Find Cumulative Salary of an Employee](/solution/0500-0599/0579.Find%20Cumulative%20Salary%20of%20an%20Employee/README_EN.md)", "", "Hard", "\ud83d\udd12"]}, {"question_id": "0578", "frontend_question_id": "0578", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/get-highest-answer-rate-question", "url_en": "https://leetcode.com/problems/get-highest-answer-rate-question", "relative_path_cn": "/solution/0500-0599/0578.Get%20Highest%20Answer%20Rate%20Question/README.md", "relative_path_en": "/solution/0500-0599/0578.Get%20Highest%20Answer%20Rate%20Question/README_EN.md", "title_cn": "\u67e5\u8be2\u56de\u7b54\u7387\u6700\u9ad8\u7684\u95ee\u9898", "title_en": "Get Highest Answer Rate Question", "question_title_slug": "get-highest-answer-rate-question", "content_en": "

    Get the highest answer rate question from a table survey_log with these columns: id, action, question_id, answer_id, q_num, timestamp.

    \n\n

    id means user id; action has these kind of values: "show", "answer", "skip"; answer_id is not null when action column is "answer", while is null for "show" and "skip"; q_num is the numeral order of the question in current session.

    \n\n

    Write a sql query to identify the question which has the highest answer rate.

    \n\n

    Example:

    \n\n
    \nInput:\n+------+-----------+--------------+------------+-----------+------------+\n| id   | action    | question_id  | answer_id  | q_num     | timestamp  |\n+------+-----------+--------------+------------+-----------+------------+\n| 5    | show      | 285          | null       | 1         | 123        |\n| 5    | answer    | 285          | 124124     | 1         | 124        |\n| 5    | show      | 369          | null       | 2         | 125        |\n| 5    | skip      | 369          | null       | 2         | 126        |\n+------+-----------+--------------+------------+-----------+------------+\nOutput:\n+-------------+\n| survey_log  |\n+-------------+\n|    285      |\n+-------------+\nExplanation:\nquestion 285 has answer rate 1/1, while question 369 has 0/1 answer rate, so output 285.\n
    \n\n

     

    \n\n

    Note: The highest answer rate meaning is: answer number's ratio in show number in the same question.

    \n", "content_cn": "

    \u4ece survey_log \u8868\u4e2d\u83b7\u5f97\u56de\u7b54\u7387\u6700\u9ad8\u7684\u95ee\u9898\uff0csurvey_log \u8868\u5305\u542b\u8fd9\u4e9b\u5217\uff1aid, action, question_id, answer_id, q_num, timestamp\u3002

    \n\n

    id \u8868\u793a\u7528\u6237 id\uff1baction \u6709\u4ee5\u4e0b\u51e0\u79cd\u503c\uff1a"show"\uff0c"answer"\uff0c"skip"\uff1b\u5f53 action \u503c\u4e3a "answer" \u65f6 answer_id \u975e\u7a7a\uff0c\u800c action \u503c\u4e3a "show" \u6216\u8005 "skip" \u65f6 answer_id \u4e3a\u7a7a\uff1bq_num \u8868\u793a\u5f53\u524d\u4f1a\u8bdd\u4e2d\u95ee\u9898\u7684\u7f16\u53f7\u3002

    \n\n

    \u8bf7\u7f16\u5199 SQL \u67e5\u8be2\u6765\u627e\u5230\u5177\u6709\u6700\u9ad8\u56de\u7b54\u7387\u7684\u95ee\u9898\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1a\n+------+-----------+--------------+------------+-----------+------------+\n| id   | action    | question_id  | answer_id  | q_num     | timestamp  |\n+------+-----------+--------------+------------+-----------+------------+\n| 5    | show      | 285          | null       | 1         | 123        |\n| 5    | answer    | 285          | 124124     | 1         | 124        |\n| 5    | show      | 369          | null       | 2         | 125        |\n| 5    | skip      | 369          | null       | 2         | 126        |\n+------+-----------+--------------+------------+-----------+------------+\n\u8f93\u51fa\uff1a\n+-------------+\n| survey_log  |\n+-------------+\n|    285      |\n+-------------+\n\u89e3\u91ca\uff1a\n\u95ee\u9898 285 \u7684\u56de\u7b54\u7387\u4e3a 1/1\uff0c\u800c\u95ee\u9898 369 \u56de\u7b54\u7387\u4e3a 0/1\uff0c\u56e0\u6b64\u8f93\u51fa 285 \u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a\u56de\u7b54\u7387\u6700\u9ad8\u7684\u542b\u4e49\u662f\uff1a\u540c\u4e00\u95ee\u9898\u7f16\u53f7\u4e2d\u56de\u7b54\u6570\u5360\u663e\u793a\u6570\u7684\u6bd4\u4f8b\u6700\u9ad8\u3002

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0578](https://leetcode-cn.com/problems/get-highest-answer-rate-question)", "[\u67e5\u8be2\u56de\u7b54\u7387\u6700\u9ad8\u7684\u95ee\u9898](/solution/0500-0599/0578.Get%20Highest%20Answer%20Rate%20Question/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0578](https://leetcode.com/problems/get-highest-answer-rate-question)", "[Get Highest Answer Rate Question](/solution/0500-0599/0578.Get%20Highest%20Answer%20Rate%20Question/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "0577", "frontend_question_id": "0577", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/employee-bonus", "url_en": "https://leetcode.com/problems/employee-bonus", "relative_path_cn": "/solution/0500-0599/0577.Employee%20Bonus/README.md", "relative_path_en": "/solution/0500-0599/0577.Employee%20Bonus/README_EN.md", "title_cn": "\u5458\u5de5\u5956\u91d1", "title_en": "Employee Bonus", "question_title_slug": "employee-bonus", "content_en": "

    Select all employee's name and bonus whose bonus is < 1000.

    \r\n\r\n

    Table:Employee

    \r\n\r\n
    \r\n+-------+--------+-----------+--------+\r\n| empId |  name  | supervisor| salary |\r\n+-------+--------+-----------+--------+\r\n|   1   | John   |  3        | 1000   |\r\n|   2   | Dan    |  3        | 2000   |\r\n|   3   | Brad   |  null     | 4000   |\r\n|   4   | Thomas |  3        | 4000   |\r\n+-------+--------+-----------+--------+\r\nempId is the primary key column for this table.\r\n
    \r\n\r\n

    Table: Bonus

    \r\n\r\n
    \r\n+-------+-------+\r\n| empId | bonus |\r\n+-------+-------+\r\n| 2     | 500   |\r\n| 4     | 2000  |\r\n+-------+-------+\r\nempId is the primary key column for this table.\r\n
    \r\n\r\n

    Example ouput:

    \r\n\r\n
    \r\n+-------+-------+\r\n| name  | bonus |\r\n+-------+-------+\r\n| John  | null  |\r\n| Dan   | 500   |\r\n| Brad  | null  |\r\n+-------+-------+\r\n
    \r\n", "content_cn": "

    \u9009\u51fa\u6240\u6709 bonus < 1000 \u7684\u5458\u5de5\u7684 name \u53ca\u5176 bonus\u3002

    \n\n

    Employee \u8868\u5355

    \n\n
    +-------+--------+-----------+--------+\n| empId |  name  | supervisor| salary |\n+-------+--------+-----------+--------+\n|   1   | John   |  3        | 1000   |\n|   2   | Dan    |  3        | 2000   |\n|   3   | Brad   |  null     | 4000   |\n|   4   | Thomas |  3        | 4000   |\n+-------+--------+-----------+--------+\nempId \u662f\u8fd9\u5f20\u8868\u5355\u7684\u4e3b\u5173\u952e\u5b57\n
    \n\n

    Bonus \u8868\u5355

    \n\n
    +-------+-------+\n| empId | bonus |\n+-------+-------+\n| 2     | 500   |\n| 4     | 2000  |\n+-------+-------+\nempId \u662f\u8fd9\u5f20\u8868\u5355\u7684\u4e3b\u5173\u952e\u5b57\n
    \n\n

    \u8f93\u51fa\u793a\u4f8b\uff1a

    \n\n
    +-------+-------+\n| name  | bonus |\n+-------+-------+\n| John  | null  |\n| Dan   | 500   |\n| Brad  | null  |\n+-------+-------+\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0577](https://leetcode-cn.com/problems/employee-bonus)", "[\u5458\u5de5\u5956\u91d1](/solution/0500-0599/0577.Employee%20Bonus/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0577](https://leetcode.com/problems/employee-bonus)", "[Employee Bonus](/solution/0500-0599/0577.Employee%20Bonus/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "0576", "frontend_question_id": "0576", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/out-of-boundary-paths", "url_en": "https://leetcode.com/problems/out-of-boundary-paths", "relative_path_cn": "/solution/0500-0599/0576.Out%20of%20Boundary%20Paths/README.md", "relative_path_en": "/solution/0500-0599/0576.Out%20of%20Boundary%20Paths/README_EN.md", "title_cn": "\u51fa\u754c\u7684\u8def\u5f84\u6570", "title_en": "Out of Boundary Paths", "question_title_slug": "out-of-boundary-paths", "content_en": "

    There is an m x n grid with a ball. The ball is initially at the position [startRow, startColumn]. You are allowed to move the ball to one of the four adjacent four cells in the grid (possibly out of the grid crossing the grid boundary). You can apply at most maxMove moves to the ball.

    \n\n

    Given the five integers m, n, maxMove, startRow, startColumn, return the number of paths to move the ball out of the grid boundary. Since the answer can be very large, return it modulo 109 + 7.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: m = 2, n = 2, maxMove = 2, startRow = 0, startColumn = 0\nOutput: 6\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: m = 1, n = 3, maxMove = 3, startRow = 0, startColumn = 1\nOutput: 12\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= m, n <= 50
    • \n\t
    • 0 <= maxMove <= 50
    • \n\t
    • 0 <= startRow <= m
    • \n\t
    • 0 <= startColumn <= n
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a m × n \u7684\u7f51\u683c\u548c\u4e00\u4e2a\u7403\u3002\u7403\u7684\u8d77\u59cb\u5750\u6807\u4e3a (i,j) \uff0c\u4f60\u53ef\u4ee5\u5c06\u7403\u79fb\u5230\u76f8\u90bb\u7684\u5355\u5143\u683c\u5185\uff0c\u6216\u8005\u5f80\u4e0a\u3001\u4e0b\u3001\u5de6\u3001\u53f3\u56db\u4e2a\u65b9\u5411\u4e0a\u79fb\u52a8\u4f7f\u7403\u7a7f\u8fc7\u7f51\u683c\u8fb9\u754c\u3002\u4f46\u662f\uff0c\u4f60\u6700\u591a\u53ef\u4ee5\u79fb\u52a8 \u6b21\u3002\u627e\u51fa\u53ef\u4ee5\u5c06\u7403\u79fb\u51fa\u8fb9\u754c\u7684\u8def\u5f84\u6570\u91cf\u3002\u7b54\u6848\u53ef\u80fd\u975e\u5e38\u5927\uff0c\u8fd4\u56de \u7ed3\u679c mod 109 + 7 \u7684\u503c\u3002

    \r\n\r\n

     

    \r\n\r\n

    \u793a\u4f8b 1\uff1a

    \r\n\r\n
    \u8f93\u5165: m = 2, n = 2, N = 2, i = 0, j = 0\r\n\u8f93\u51fa: 6\r\n\u89e3\u91ca:\r\n\r\n
    \r\n\r\n

    \u793a\u4f8b 2\uff1a

    \r\n\r\n
    \u8f93\u5165: m = 1, n = 3, N = 3, i = 0, j = 1\r\n\u8f93\u51fa: 12\r\n\u89e3\u91ca:\r\n\r\n
    \r\n\r\n

     

    \r\n\r\n

    \u8bf4\u660e:

    \r\n\r\n
      \r\n\t
    1. \u7403\u4e00\u65e6\u51fa\u754c\uff0c\u5c31\u4e0d\u80fd\u518d\u88ab\u79fb\u52a8\u56de\u7f51\u683c\u5185\u3002
    2. \r\n\t
    3. \u7f51\u683c\u7684\u957f\u5ea6\u548c\u9ad8\u5ea6\u5728 [1,50] \u7684\u8303\u56f4\u5185\u3002
    4. \r\n\t
    5. N \u5728 [0,50] \u7684\u8303\u56f4\u5185\u3002
    6. \r\n
    ", "tags_en": ["Depth-first Search", "Dynamic Programming"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findPaths(int m, int n, int maxMove, int startRow, int startColumn) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findPaths(int m, int n, int maxMove, int startRow, int startColumn) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findPaths(self, m, n, maxMove, startRow, startColumn):\n \"\"\"\n :type m: int\n :type n: int\n :type maxMove: int\n :type startRow: int\n :type startColumn: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findPaths(self, m: int, n: int, maxMove: int, startRow: int, startColumn: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findPaths(int m, int n, int maxMove, int startRow, int startColumn){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindPaths(int m, int n, int maxMove, int startRow, int startColumn) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} m\n * @param {number} n\n * @param {number} maxMove\n * @param {number} startRow\n * @param {number} startColumn\n * @return {number}\n */\nvar findPaths = function(m, n, maxMove, startRow, startColumn) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} m\n# @param {Integer} n\n# @param {Integer} max_move\n# @param {Integer} start_row\n# @param {Integer} start_column\n# @return {Integer}\ndef find_paths(m, n, max_move, start_row, start_column)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findPaths(_ m: Int, _ n: Int, _ maxMove: Int, _ startRow: Int, _ startColumn: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findPaths(m int, n int, maxMove int, startRow int, startColumn int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findPaths(m: Int, n: Int, maxMove: Int, startRow: Int, startColumn: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findPaths(m: Int, n: Int, maxMove: Int, startRow: Int, startColumn: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_paths(m: i32, n: i32, max_move: i32, start_row: i32, start_column: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $m\n * @param Integer $n\n * @param Integer $maxMove\n * @param Integer $startRow\n * @param Integer $startColumn\n * @return Integer\n */\n function findPaths($m, $n, $maxMove, $startRow, $startColumn) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findPaths(m: number, n: number, maxMove: number, startRow: number, startColumn: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-paths m n maxMove startRow startColumn)\n (-> exact-integer? exact-integer? exact-integer? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0576](https://leetcode-cn.com/problems/out-of-boundary-paths)", "[\u51fa\u754c\u7684\u8def\u5f84\u6570](/solution/0500-0599/0576.Out%20of%20Boundary%20Paths/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0576](https://leetcode.com/problems/out-of-boundary-paths)", "[Out of Boundary Paths](/solution/0500-0599/0576.Out%20of%20Boundary%20Paths/README_EN.md)", "`Depth-first Search`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0575", "frontend_question_id": "0575", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/distribute-candies", "url_en": "https://leetcode.com/problems/distribute-candies", "relative_path_cn": "/solution/0500-0599/0575.Distribute%20Candies/README.md", "relative_path_en": "/solution/0500-0599/0575.Distribute%20Candies/README_EN.md", "title_cn": "\u5206\u7cd6\u679c", "title_en": "Distribute Candies", "question_title_slug": "distribute-candies", "content_en": "

    Alice has n candies, where the ith candy is of type candyType[i]. Alice noticed that she started to gain weight, so she visited a doctor.

    \n\n

    The doctor advised Alice to only eat n / 2 of the candies she has (n is always even). Alice likes her candies very much, and she wants to eat the maximum number of different types of candies while still following the doctor's advice.

    \n\n

    Given the integer array candyType of length n, return the maximum number of different types of candies she can eat if she only eats n / 2 of them.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: candyType = [1,1,2,2,3,3]\nOutput: 3\nExplanation: Alice can only eat 6 / 2 = 3 candies. Since there are only 3 types, she can eat one of each type.\n
    \n\n

    Example 2:

    \n\n
    \nInput: candyType = [1,1,2,3]\nOutput: 2\nExplanation: Alice can only eat 4 / 2 = 2 candies. Whether she eats types [1,2], [1,3], or [2,3], she still can only eat 2 different types.\n
    \n\n

    Example 3:

    \n\n
    \nInput: candyType = [6,6,6,6]\nOutput: 1\nExplanation: Alice can only eat 4 / 2 = 2 candies. Even though she can eat 2 candies, she only has 1 type.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == candyType.length
    • \n\t
    • 2 <= n <= 104
    • \n\t
    • n is even.
    • \n\t
    • -105 <= candyType[i] <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5076\u6570\u957f\u5ea6\u7684\u6570\u7ec4\uff0c\u5176\u4e2d\u4e0d\u540c\u7684\u6570\u5b57\u4ee3\u8868\u7740\u4e0d\u540c\u79cd\u7c7b\u7684\u7cd6\u679c\uff0c\u6bcf\u4e00\u4e2a\u6570\u5b57\u4ee3\u8868\u4e00\u4e2a\u7cd6\u679c\u3002\u4f60\u9700\u8981\u628a\u8fd9\u4e9b\u7cd6\u679c\u5e73\u5747\u5206\u7ed9\u4e00\u4e2a\u5f1f\u5f1f\u548c\u4e00\u4e2a\u59b9\u59b9\u3002\u8fd4\u56de\u59b9\u59b9\u53ef\u4ee5\u83b7\u5f97\u7684\u6700\u5927\u7cd6\u679c\u7684\u79cd\u7c7b\u6570\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: candies = [1,1,2,2,3,3]\n\u8f93\u51fa: 3\n\u89e3\u6790: \u4e00\u5171\u6709\u4e09\u79cd\u79cd\u7c7b\u7684\u7cd6\u679c\uff0c\u6bcf\u4e00\u79cd\u90fd\u6709\u4e24\u4e2a\u3002\n     \u6700\u4f18\u5206\u914d\u65b9\u6848\uff1a\u59b9\u59b9\u83b7\u5f97[1,2,3],\u5f1f\u5f1f\u4e5f\u83b7\u5f97[1,2,3]\u3002\u8fd9\u6837\u4f7f\u59b9\u59b9\u83b7\u5f97\u7cd6\u679c\u7684\u79cd\u7c7b\u6570\u6700\u591a\u3002\n
    \n\n

    \u793a\u4f8b 2 :

    \n\n
    \n\u8f93\u5165: candies = [1,1,2,3]\n\u8f93\u51fa: 2\n\u89e3\u6790: \u59b9\u59b9\u83b7\u5f97\u7cd6\u679c[2,3],\u5f1f\u5f1f\u83b7\u5f97\u7cd6\u679c[1,1]\uff0c\u59b9\u59b9\u6709\u4e24\u79cd\u4e0d\u540c\u7684\u7cd6\u679c\uff0c\u5f1f\u5f1f\u53ea\u6709\u4e00\u79cd\u3002\u8fd9\u6837\u4f7f\u5f97\u59b9\u59b9\u53ef\u4ee5\u83b7\u5f97\u7684\u7cd6\u679c\u79cd\u7c7b\u6570\u6700\u591a\u3002\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u6570\u7ec4\u7684\u957f\u5ea6\u4e3a[2, 10,000]\uff0c\u5e76\u4e14\u786e\u5b9a\u4e3a\u5076\u6570\u3002
    2. \n\t
    3. \u6570\u7ec4\u4e2d\u6570\u5b57\u7684\u5927\u5c0f\u5728\u8303\u56f4[-100,000, 100,000]\u5185\u3002\n\t
        \n\t
      \n\t
    4. \n
    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int distributeCandies(vector& candyType) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int distributeCandies(int[] candyType) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def distributeCandies(self, candyType):\n \"\"\"\n :type candyType: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def distributeCandies(self, candyType: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint distributeCandies(int* candyType, int candyTypeSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int DistributeCandies(int[] candyType) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} candyType\n * @return {number}\n */\nvar distributeCandies = function(candyType) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} candy_type\n# @return {Integer}\ndef distribute_candies(candy_type)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func distributeCandies(_ candyType: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func distributeCandies(candyType []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def distributeCandies(candyType: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun distributeCandies(candyType: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn distribute_candies(candy_type: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $candyType\n * @return Integer\n */\n function distributeCandies($candyType) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function distributeCandies(candyType: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (distribute-candies candyType)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0575](https://leetcode-cn.com/problems/distribute-candies)", "[\u5206\u7cd6\u679c](/solution/0500-0599/0575.Distribute%20Candies/README.md)", "`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0575](https://leetcode.com/problems/distribute-candies)", "[Distribute Candies](/solution/0500-0599/0575.Distribute%20Candies/README_EN.md)", "`Hash Table`", "Easy", ""]}, {"question_id": "0574", "frontend_question_id": "0574", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/winning-candidate", "url_en": "https://leetcode.com/problems/winning-candidate", "relative_path_cn": "/solution/0500-0599/0574.Winning%20Candidate/README.md", "relative_path_en": "/solution/0500-0599/0574.Winning%20Candidate/README_EN.md", "title_cn": "\u5f53\u9009\u8005", "title_en": "Winning Candidate", "question_title_slug": "winning-candidate", "content_en": "

    Table: Candidate

    \n\n
    \n+-----+---------+\n| id  | Name    |\n+-----+---------+\n| 1   | A       |\n| 2   | B       |\n| 3   | C       |\n| 4   | D       |\n| 5   | E       |\n+-----+---------+  \n
    \n\n

    Table: Vote

    \n\n
    \n+-----+--------------+\n| id  | CandidateId  |\n+-----+--------------+\n| 1   |     2        |\n| 2   |     4        |\n| 3   |     3        |\n| 4   |     2        |\n| 5   |     5        |\n+-----+--------------+\nid is the auto-increment primary key,\nCandidateId is the id appeared in Candidate table.\n
    \n\n

    Write a sql to find the name of the winning candidate, the above example will return the winner B.

    \n\n
    \n+------+\n| Name |\n+------+\n| B    |\n+------+\n
    \n\n

    Notes:

    \n\n
      \n\t
    1. You may assume there is no tie, in other words there will be only one winning candidate.
    2. \n
    \n\n

     

    \n", "content_cn": "

    \u8868: Candidate

    \n\n
    +-----+---------+\n| id  | Name    |\n+-----+---------+\n| 1   | A       |\n| 2   | B       |\n| 3   | C       |\n| 4   | D       |\n| 5   | E       |\n+-----+---------+  \n
    \n\n

    \u8868: Vote

    \n\n
    +-----+--------------+\n| id  | CandidateId  |\n+-----+--------------+\n| 1   |     2        |\n| 2   |     4        |\n| 3   |     3        |\n| 4   |     2        |\n| 5   |     5        |\n+-----+--------------+\nid \u662f\u81ea\u52a8\u9012\u589e\u7684\u4e3b\u952e\uff0c\nCandidateId \u662f Candidate \u8868\u4e2d\u7684 id.\n
    \n\n

    \u8bf7\u7f16\u5199 sql \u8bed\u53e5\u6765\u627e\u5230\u5f53\u9009\u8005\u7684\u540d\u5b57\uff0c\u4e0a\u9762\u7684\u4f8b\u5b50\u5c06\u8fd4\u56de\u5f53\u9009\u8005 B.

    \n\n
    +------+\n| Name |\n+------+\n| B    |\n+------+\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u4f60\u53ef\u4ee5\u5047\u8bbe\u6ca1\u6709\u5e73\u5c40\uff0c\u6362\u8a00\u4e4b\uff0c\u6700\u591a\u53ea\u6709\u4e00\u4f4d\u5f53\u9009\u8005\u3002
    2. \n
    \n\n

     

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0574](https://leetcode-cn.com/problems/winning-candidate)", "[\u5f53\u9009\u8005](/solution/0500-0599/0574.Winning%20Candidate/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0574](https://leetcode.com/problems/winning-candidate)", "[Winning Candidate](/solution/0500-0599/0574.Winning%20Candidate/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "0573", "frontend_question_id": "0573", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/squirrel-simulation", "url_en": "https://leetcode.com/problems/squirrel-simulation", "relative_path_cn": "/solution/0500-0599/0573.Squirrel%20Simulation/README.md", "relative_path_en": "/solution/0500-0599/0573.Squirrel%20Simulation/README_EN.md", "title_cn": "\u677e\u9f20\u6a21\u62df", "title_en": "Squirrel Simulation", "question_title_slug": "squirrel-simulation", "content_en": "

    You are given two integers height and width representing a garden of size height x width. You are also given:

    \n\n
      \n\t
    • an array tree where tree = [treer, treec] is the position of the tree in the garden,
    • \n\t
    • an array squirrel where squirrel = [squirrelr, squirrelc] is the position of the squirrel in the garden,
    • \n\t
    • and an array nuts where nuts[i] = [nutir, nutic] is the position of the ith nut in the garden.
    • \n
    \n\n

    The squirrel can only take at most one nut at one time and can move in four directions: up, down, left, and right, to the adjacent cell.

    \n\n

    Return the minimal distance for the squirrel to collect all the nuts and put them under the tree one by one.

    \n\n

    The distance is the number of moves.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: height = 5, width = 7, tree = [2,2], squirrel = [4,4], nuts = [[3,0], [2,5]]\nOutput: 12\nExplanation: The squirrel should go to the nut at [2, 5] first to achieve a minimal distance.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: height = 1, width = 3, tree = [0,1], squirrel = [0,0], nuts = [[0,2]]\nOutput: 3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= height, width <= 100
    • \n\t
    • tree.length == 2
    • \n\t
    • squirrel.length == 2
    • \n\t
    • 1 <= nuts.length <= 5000
    • \n\t
    • nuts[i].length == 2
    • \n\t
    • 0 <= treer, squirrelr, nutir <= height
    • \n\t
    • 0 <= treec, squirrelc, nutic <= width
    • \n
    \n", "content_cn": "

    \u73b0\u5728\u6709\u4e00\u68f5\u6811\uff0c\u4e00\u53ea\u677e\u9f20\u548c\u4e00\u4e9b\u575a\u679c\u3002\u4f4d\u7f6e\u7531\u4e8c\u7ef4\u7f51\u683c\u7684\u5355\u5143\u683c\u8868\u793a\u3002\u4f60\u7684\u76ee\u6807\u662f\u627e\u5230\u677e\u9f20\u6536\u96c6\u6240\u6709\u575a\u679c\u7684\u6700\u5c0f\u8def\u7a0b\uff0c\u4e14\u575a\u679c\u662f\u4e00\u9897\u63a5\u4e00\u9897\u5730\u88ab\u653e\u5728\u6811\u4e0b\u3002\u677e\u9f20\u4e00\u6b21\u6700\u591a\u53ea\u80fd\u643a\u5e26\u4e00\u9897\u575a\u679c\uff0c\u677e\u9f20\u53ef\u4ee5\u5411\u4e0a\uff0c\u5411\u4e0b\uff0c\u5411\u5de6\u548c\u5411\u53f3\u56db\u4e2a\u65b9\u5411\u79fb\u52a8\u5230\u76f8\u90bb\u7684\u5355\u5143\u683c\u3002\u79fb\u52a8\u6b21\u6570\u8868\u793a\u8def\u7a0b\u3002

    \n\n

    \u8f93\u5165 1:

    \n\n
    \u8f93\u5165: \n\u9ad8\u5ea6 : 5\n\u5bbd\u5ea6 : 7\n\u6811\u7684\u4f4d\u7f6e : [2,2]\n\u677e\u9f20 : [4,4]\n\u575a\u679c : [[3,0], [2,5]]\n\u8f93\u51fa: 12\n\u89e3\u91ca:\n\u200b\u200b\u200b\u200b\u200b\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u6240\u6709\u7ed9\u5b9a\u7684\u4f4d\u7f6e\u4e0d\u4f1a\u91cd\u53e0\u3002
    2. \n\t
    3. \u677e\u9f20\u4e00\u6b21\u6700\u591a\u53ea\u80fd\u643a\u5e26\u4e00\u9897\u575a\u679c\u3002
    4. \n\t
    5. \u7ed9\u5b9a\u7684\u575a\u679c\u4f4d\u7f6e\u6ca1\u6709\u987a\u5e8f\u3002
    6. \n\t
    7. \u9ad8\u5ea6\u548c\u5bbd\u5ea6\u662f\u6b63\u6574\u6570\u3002 3 <= \u9ad8\u5ea6 * \u5bbd\u5ea6 <= 10,000\u3002
    8. \n\t
    9. \u7ed9\u5b9a\u7684\u7f51\u683c\u81f3\u5c11\u5305\u542b\u4e00\u9897\u575a\u679c\uff0c\u552f\u4e00\u7684\u4e00\u68f5\u6811\u548c\u4e00\u53ea\u677e\u9f20\u3002
    10. \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minDistance(int height, int width, vector& tree, vector& squirrel, vector>& nuts) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minDistance(int height, int width, int[] tree, int[] squirrel, int[][] nuts) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minDistance(self, height, width, tree, squirrel, nuts):\n \"\"\"\n :type height: int\n :type width: int\n :type tree: List[int]\n :type squirrel: List[int]\n :type nuts: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minDistance(self, height: int, width: int, tree: List[int], squirrel: List[int], nuts: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minDistance(int height, int width, int* tree, int treeSize, int* squirrel, int squirrelSize, int** nuts, int nutsSize, int* nutsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinDistance(int height, int width, int[] tree, int[] squirrel, int[][] nuts) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} height\n * @param {number} width\n * @param {number[]} tree\n * @param {number[]} squirrel\n * @param {number[][]} nuts\n * @return {number}\n */\nvar minDistance = function(height, width, tree, squirrel, nuts) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} height\n# @param {Integer} width\n# @param {Integer[]} tree\n# @param {Integer[]} squirrel\n# @param {Integer[][]} nuts\n# @return {Integer}\ndef min_distance(height, width, tree, squirrel, nuts)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minDistance(_ height: Int, _ width: Int, _ tree: [Int], _ squirrel: [Int], _ nuts: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minDistance(height int, width int, tree []int, squirrel []int, nuts [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minDistance(height: Int, width: Int, tree: Array[Int], squirrel: Array[Int], nuts: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minDistance(height: Int, width: Int, tree: IntArray, squirrel: IntArray, nuts: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_distance(height: i32, width: i32, tree: Vec, squirrel: Vec, nuts: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $height\n * @param Integer $width\n * @param Integer[] $tree\n * @param Integer[] $squirrel\n * @param Integer[][] $nuts\n * @return Integer\n */\n function minDistance($height, $width, $tree, $squirrel, $nuts) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minDistance(height: number, width: number, tree: number[], squirrel: number[], nuts: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-distance height width tree squirrel nuts)\n (-> exact-integer? exact-integer? (listof exact-integer?) (listof exact-integer?) (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0573](https://leetcode-cn.com/problems/squirrel-simulation)", "[\u677e\u9f20\u6a21\u62df](/solution/0500-0599/0573.Squirrel%20Simulation/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0573](https://leetcode.com/problems/squirrel-simulation)", "[Squirrel Simulation](/solution/0500-0599/0573.Squirrel%20Simulation/README_EN.md)", "`Math`", "Medium", "\ud83d\udd12"]}, {"question_id": "0572", "frontend_question_id": "0572", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/subtree-of-another-tree", "url_en": "https://leetcode.com/problems/subtree-of-another-tree", "relative_path_cn": "/solution/0500-0599/0572.Subtree%20of%20Another%20Tree/README.md", "relative_path_en": "/solution/0500-0599/0572.Subtree%20of%20Another%20Tree/README_EN.md", "title_cn": "\u53e6\u4e00\u4e2a\u6811\u7684\u5b50\u6811", "title_en": "Subtree of Another Tree", "question_title_slug": "subtree-of-another-tree", "content_en": "

    Given the roots of two binary trees root and subRoot, return true if there is a subtree of root with the same structure and node values of subRoot and false otherwise.

    \n\n

    A subtree of a binary tree tree is a tree that consists of a node in tree and all of this node's descendants. The tree tree could also be considered as a subtree of itself.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [3,4,5,1,2], subRoot = [4,1,2]\nOutput: true\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [3,4,5,1,2,null,null,null,null,0], subRoot = [4,1,2]\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the root tree is in the range [1, 2000].
    • \n\t
    • The number of nodes in the subRoot tree is in the range [1, 1000].
    • \n\t
    • -104 <= root.val <= 104
    • \n\t
    • -104 <= subRoot.val <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u975e\u7a7a\u4e8c\u53c9\u6811 s \u548c t\uff0c\u68c0\u9a8c s \u4e2d\u662f\u5426\u5305\u542b\u548c t \u5177\u6709\u76f8\u540c\u7ed3\u6784\u548c\u8282\u70b9\u503c\u7684\u5b50\u6811\u3002s \u7684\u4e00\u4e2a\u5b50\u6811\u5305\u62ec s \u7684\u4e00\u4e2a\u8282\u70b9\u548c\u8fd9\u4e2a\u8282\u70b9\u7684\u6240\u6709\u5b50\u5b59\u3002s \u4e5f\u53ef\u4ee5\u770b\u505a\u5b83\u81ea\u8eab\u7684\u4e00\u68f5\u5b50\u6811\u3002

    \n\n

    \u793a\u4f8b 1:
    \n\u7ed9\u5b9a\u7684\u6811 s:

    \n\n
    \n     3\n    / \\\n   4   5\n  / \\\n 1   2\n
    \n\n

    \u7ed9\u5b9a\u7684\u6811 t\uff1a

    \n\n
    \n   4 \n  / \\\n 1   2\n
    \n\n

    \u8fd4\u56de true\uff0c\u56e0\u4e3a t \u4e0e s \u7684\u4e00\u4e2a\u5b50\u6811\u62e5\u6709\u76f8\u540c\u7684\u7ed3\u6784\u548c\u8282\u70b9\u503c\u3002

    \n\n

    \u793a\u4f8b 2:
    \n\u7ed9\u5b9a\u7684\u6811 s\uff1a

    \n\n
    \n     3\n    / \\\n   4   5\n  / \\\n 1   2\n    /\n   0\n
    \n\n

    \u7ed9\u5b9a\u7684\u6811 t\uff1a

    \n\n
    \n   4\n  / \\\n 1   2\n
    \n\n

    \u8fd4\u56de false\u3002

    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n bool isSubtree(TreeNode* root, TreeNode* subRoot) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public boolean isSubtree(TreeNode root, TreeNode subRoot) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def isSubtree(self, root, subRoot):\n \"\"\"\n :type root: TreeNode\n :type subRoot: TreeNode\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def isSubtree(self, root: TreeNode, subRoot: TreeNode) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nbool isSubtree(struct TreeNode* root, struct TreeNode* subRoot){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public bool IsSubtree(TreeNode root, TreeNode subRoot) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {TreeNode} subRoot\n * @return {boolean}\n */\nvar isSubtree = function(root, subRoot) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @param {TreeNode} sub_root\n# @return {Boolean}\ndef is_subtree(root, sub_root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func isSubtree(_ root: TreeNode?, _ subRoot: TreeNode?) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc isSubtree(root *TreeNode, subRoot *TreeNode) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def isSubtree(root: TreeNode, subRoot: TreeNode): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun isSubtree(root: TreeNode?, subRoot: TreeNode?): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn is_subtree(root: Option>>, sub_root: Option>>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param TreeNode $subRoot\n * @return Boolean\n */\n function isSubtree($root, $subRoot) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction isSubtree(root: TreeNode | null, subRoot: TreeNode | null): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (is-subtree root subRoot)\n (-> (or/c tree-node? #f) (or/c tree-node? #f) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0572](https://leetcode-cn.com/problems/subtree-of-another-tree)", "[\u53e6\u4e00\u4e2a\u6811\u7684\u5b50\u6811](/solution/0500-0599/0572.Subtree%20of%20Another%20Tree/README.md)", "`\u6811`", "\u7b80\u5355", ""], "md_table_row_en": ["[0572](https://leetcode.com/problems/subtree-of-another-tree)", "[Subtree of Another Tree](/solution/0500-0599/0572.Subtree%20of%20Another%20Tree/README_EN.md)", "`Tree`", "Easy", ""]}, {"question_id": "0571", "frontend_question_id": "0571", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/find-median-given-frequency-of-numbers", "url_en": "https://leetcode.com/problems/find-median-given-frequency-of-numbers", "relative_path_cn": "/solution/0500-0599/0571.Find%20Median%20Given%20Frequency%20of%20Numbers/README.md", "relative_path_en": "/solution/0500-0599/0571.Find%20Median%20Given%20Frequency%20of%20Numbers/README_EN.md", "title_cn": "\u7ed9\u5b9a\u6570\u5b57\u7684\u9891\u7387\u67e5\u8be2\u4e2d\u4f4d\u6570", "title_en": "Find Median Given Frequency of Numbers", "question_title_slug": "find-median-given-frequency-of-numbers", "content_en": "

    The Numbers table keeps the value of number and its frequency.

    \r\n\r\n
    \r\n+----------+-------------+\r\n|  Number  |  Frequency  |\r\n+----------+-------------|\r\n|  0       |  7          |\r\n|  1       |  1          |\r\n|  2       |  3          |\r\n|  3       |  1          |\r\n+----------+-------------+\r\n
    \r\n\r\n

    In this table, the numbers are 0, 0, 0, 0, 0, 0, 0, 1, 2, 2, 2, 3, so the median is (0 + 0) / 2 = 0.

    \r\n\r\n
    \r\n+--------+\r\n| median |\r\n+--------|\r\n| 0.0000 |\r\n+--------+\r\n
    \r\n\r\n

    Write a query to find the median of all numbers and name the result as median.

    \r\n", "content_cn": "

    Numbers \u8868\u4fdd\u5b58\u6570\u5b57\u7684\u503c\u53ca\u5176\u9891\u7387\u3002

    \n\n
    +----------+-------------+\n|  Number  |  Frequency  |\n+----------+-------------|\n|  0       |  7          |\n|  1       |  1          |\n|  2       |  3          |\n|  3       |  1          |\n+----------+-------------+\n
    \n\n

    \u5728\u6b64\u8868\u4e2d\uff0c\u6570\u5b57\u4e3a 0, 0, 0, 0, 0, 0, 0, 1, 2, 2, 2, 3\uff0c\u6240\u4ee5\u4e2d\u4f4d\u6570\u662f (0 + 0) / 2 = 0\u3002

    \n\n
    +--------+\n| median |\n+--------|\n| 0.0000 |\n+--------+\n
    \n\n

    \u8bf7\u7f16\u5199\u4e00\u4e2a\u67e5\u8be2\u6765\u67e5\u627e\u6240\u6709\u6570\u5b57\u7684\u4e2d\u4f4d\u6570\u5e76\u5c06\u7ed3\u679c\u547d\u540d\u4e3a median \u3002

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0571](https://leetcode-cn.com/problems/find-median-given-frequency-of-numbers)", "[\u7ed9\u5b9a\u6570\u5b57\u7684\u9891\u7387\u67e5\u8be2\u4e2d\u4f4d\u6570](/solution/0500-0599/0571.Find%20Median%20Given%20Frequency%20of%20Numbers/README.md)", "", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0571](https://leetcode.com/problems/find-median-given-frequency-of-numbers)", "[Find Median Given Frequency of Numbers](/solution/0500-0599/0571.Find%20Median%20Given%20Frequency%20of%20Numbers/README_EN.md)", "", "Hard", "\ud83d\udd12"]}, {"question_id": "0570", "frontend_question_id": "0570", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/managers-with-at-least-5-direct-reports", "url_en": "https://leetcode.com/problems/managers-with-at-least-5-direct-reports", "relative_path_cn": "/solution/0500-0599/0570.Managers%20with%20at%20Least%205%20Direct%20Reports/README.md", "relative_path_en": "/solution/0500-0599/0570.Managers%20with%20at%20Least%205%20Direct%20Reports/README_EN.md", "title_cn": "\u81f3\u5c11\u67095\u540d\u76f4\u63a5\u4e0b\u5c5e\u7684\u7ecf\u7406", "title_en": "Managers with at Least 5 Direct Reports", "question_title_slug": "managers-with-at-least-5-direct-reports", "content_en": "

    The Employee table holds all employees including their managers. Every employee has an Id, and there is also a column for the manager Id.

    \r\n\r\n
    \r\n+------+----------+-----------+----------+\r\n|Id    |Name \t  |Department |ManagerId |\r\n+------+----------+-----------+----------+\r\n|101   |John \t  |A \t      |null      |\r\n|102   |Dan \t  |A \t      |101       |\r\n|103   |James \t  |A \t      |101       |\r\n|104   |Amy \t  |A \t      |101       |\r\n|105   |Anne \t  |A \t      |101       |\r\n|106   |Ron \t  |B \t      |101       |\r\n+------+----------+-----------+----------+\r\n
    \r\n\r\n

    Given the Employee table, write a SQL query that finds out managers with at least 5 direct report. For the above table, your SQL query should return:

    \r\n\r\n
    \r\n+-------+\r\n| Name  |\r\n+-------+\r\n| John  |\r\n+-------+\r\n
    \r\n\r\n

    Note:
    \r\nNo one would report to himself.

    \r\n", "content_cn": "

    Employee \u8868\u5305\u542b\u6240\u6709\u5458\u5de5\u548c\u4ed6\u4eec\u7684\u7ecf\u7406\u3002\u6bcf\u4e2a\u5458\u5de5\u90fd\u6709\u4e00\u4e2a Id\uff0c\u5e76\u4e14\u8fd8\u6709\u4e00\u5217\u662f\u7ecf\u7406\u7684 Id\u3002

    \n\n
    +------+----------+-----------+----------+\n|Id    |Name \t  |Department |ManagerId |\n+------+----------+-----------+----------+\n|101   |John \t  |A \t      |null      |\n|102   |Dan \t  |A \t      |101       |\n|103   |James \t  |A \t      |101       |\n|104   |Amy \t  |A \t      |101       |\n|105   |Anne \t  |A \t      |101       |\n|106   |Ron \t  |B \t      |101       |\n+------+----------+-----------+----------+\n
    \n\n

    \u7ed9\u5b9a Employee \u8868\uff0c\u8bf7\u7f16\u5199\u4e00\u4e2aSQL\u67e5\u8be2\u6765\u67e5\u627e\u81f3\u5c11\u67095\u540d\u76f4\u63a5\u4e0b\u5c5e\u7684\u7ecf\u7406\u3002\u5bf9\u4e8e\u4e0a\u8868\uff0c\u60a8\u7684SQL\u67e5\u8be2\u5e94\u8be5\u8fd4\u56de\uff1a

    \n\n
    +-------+\n| Name  |\n+-------+\n| John  |\n+-------+\n
    \n\n

    \u6ce8\u610f:
    \n\u6ca1\u6709\u4eba\u662f\u81ea\u5df1\u7684\u4e0b\u5c5e\u3002

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0570](https://leetcode-cn.com/problems/managers-with-at-least-5-direct-reports)", "[\u81f3\u5c11\u67095\u540d\u76f4\u63a5\u4e0b\u5c5e\u7684\u7ecf\u7406](/solution/0500-0599/0570.Managers%20with%20at%20Least%205%20Direct%20Reports/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0570](https://leetcode.com/problems/managers-with-at-least-5-direct-reports)", "[Managers with at Least 5 Direct Reports](/solution/0500-0599/0570.Managers%20with%20at%20Least%205%20Direct%20Reports/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "0569", "frontend_question_id": "0569", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/median-employee-salary", "url_en": "https://leetcode.com/problems/median-employee-salary", "relative_path_cn": "/solution/0500-0599/0569.Median%20Employee%20Salary/README.md", "relative_path_en": "/solution/0500-0599/0569.Median%20Employee%20Salary/README_EN.md", "title_cn": "\u5458\u5de5\u85aa\u6c34\u4e2d\u4f4d\u6570", "title_en": "Median Employee Salary", "question_title_slug": "median-employee-salary", "content_en": "

    The Employee table holds all employees. The employee table has three columns: Employee Id, Company Name, and Salary.

    \r\n\r\n
    \r\n+-----+------------+--------+\r\n|Id   | Company    | Salary |\r\n+-----+------------+--------+\r\n|1    | A          | 2341   |\r\n|2    | A          | 341    |\r\n|3    | A          | 15     |\r\n|4    | A          | 15314  |\r\n|5    | A          | 451    |\r\n|6    | A          | 513    |\r\n|7    | B          | 15     |\r\n|8    | B          | 13     |\r\n|9    | B          | 1154   |\r\n|10   | B          | 1345   |\r\n|11   | B          | 1221   |\r\n|12   | B          | 234    |\r\n|13   | C          | 2345   |\r\n|14   | C          | 2645   |\r\n|15   | C          | 2645   |\r\n|16   | C          | 2652   |\r\n|17   | C          | 65     |\r\n+-----+------------+--------+\r\n
    \r\n\r\n

    Write a SQL query to find the median salary of each company. Bonus points if you can solve it without using any built-in SQL functions.

    \r\n\r\n
    \r\n+-----+------------+--------+\r\n|Id   | Company    | Salary |\r\n+-----+------------+--------+\r\n|5    | A          | 451    |\r\n|6    | A          | 513    |\r\n|12   | B          | 234    |\r\n|9    | B          | 1154   |\r\n|14   | C          | 2645   |\r\n+-----+------------+--------+\r\n
    \r\n", "content_cn": "

    Employee \u8868\u5305\u542b\u6240\u6709\u5458\u5de5\u3002Employee \u8868\u6709\u4e09\u5217\uff1a\u5458\u5de5Id\uff0c\u516c\u53f8\u540d\u548c\u85aa\u6c34\u3002

    \n\n
    +-----+------------+--------+\n|Id   | Company    | Salary |\n+-----+------------+--------+\n|1    | A          | 2341   |\n|2    | A          | 341    |\n|3    | A          | 15     |\n|4    | A          | 15314  |\n|5    | A          | 451    |\n|6    | A          | 513    |\n|7    | B          | 15     |\n|8    | B          | 13     |\n|9    | B          | 1154   |\n|10   | B          | 1345   |\n|11   | B          | 1221   |\n|12   | B          | 234    |\n|13   | C          | 2345   |\n|14   | C          | 2645   |\n|15   | C          | 2645   |\n|16   | C          | 2652   |\n|17   | C          | 65     |\n+-----+------------+--------+\n
    \n\n

    \u8bf7\u7f16\u5199SQL\u67e5\u8be2\u6765\u67e5\u627e\u6bcf\u4e2a\u516c\u53f8\u7684\u85aa\u6c34\u4e2d\u4f4d\u6570\u3002\u6311\u6218\u70b9\uff1a\u4f60\u662f\u5426\u53ef\u4ee5\u5728\u4e0d\u4f7f\u7528\u4efb\u4f55\u5185\u7f6e\u7684SQL\u51fd\u6570\u7684\u60c5\u51b5\u4e0b\u89e3\u51b3\u6b64\u95ee\u9898\u3002

    \n\n
    +-----+------------+--------+\n|Id   | Company    | Salary |\n+-----+------------+--------+\n|5    | A          | 451    |\n|6    | A          | 513    |\n|12   | B          | 234    |\n|9    | B          | 1154   |\n|14   | C          | 2645   |\n+-----+------------+--------+\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0569](https://leetcode-cn.com/problems/median-employee-salary)", "[\u5458\u5de5\u85aa\u6c34\u4e2d\u4f4d\u6570](/solution/0500-0599/0569.Median%20Employee%20Salary/README.md)", "", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0569](https://leetcode.com/problems/median-employee-salary)", "[Median Employee Salary](/solution/0500-0599/0569.Median%20Employee%20Salary/README_EN.md)", "", "Hard", "\ud83d\udd12"]}, {"question_id": "0568", "frontend_question_id": "0568", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/maximum-vacation-days", "url_en": "https://leetcode.com/problems/maximum-vacation-days", "relative_path_cn": "/solution/0500-0599/0568.Maximum%20Vacation%20Days/README.md", "relative_path_en": "/solution/0500-0599/0568.Maximum%20Vacation%20Days/README_EN.md", "title_cn": "\u6700\u5927\u4f11\u5047\u5929\u6570", "title_en": "Maximum Vacation Days", "question_title_slug": "maximum-vacation-days", "content_en": "

    LeetCode wants to give one of its best employees the option to travel among n cities to collect algorithm problems. But all work and no play makes Jack a dull boy, you could take vacations in some particular cities and weeks. Your job is to schedule the traveling to maximize the number of vacation days you could take, but there are certain rules and restrictions you need to follow.

    \n\n

    Rules and restrictions:

    \n\n
      \n\t
    1. You can only travel among n cities, represented by indexes from 0 to n - 1. Initially, you are in the city indexed 0 on Monday.
    2. \n\t
    3. The cities are connected by flights. The flights are represented as an n x n matrix (not necessarily symmetrical), called flights representing the airline status from the city i to the city j. If there is no flight from the city i to the city j, flights[i][j] == 0; Otherwise, flights[i][j] == 1. Also, flights[i][i] == 0 for all i.
    4. \n\t
    5. You totally have k weeks (each week has seven days) to travel. You can only take flights at most once per day and can only take flights on each week's Monday morning. Since flight time is so short, we do not consider the impact of flight time.
    6. \n\t
    7. For each city, you can only have restricted vacation days in different weeks, given an n x k matrix called days representing this relationship. For the value of days[i][j], it represents the maximum days you could take a vacation in the city i in the week j.
    8. \n\t
    9. You could stay in a city beyond the number of vacation days, but you should work on the extra days, which will not be counted as vacation days.
    10. \n\t
    11. If you fly from city A to city B and take the vacation on that day, the deduction towards vacation days will count towards the vacation days of city B in that week.
    12. \n\t
    13. We do not consider the impact of flight hours on the calculation of vacation days.
    14. \n
    \n\n

    Given the two matrices flights and days, return the maximum vacation days you could take during k weeks.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: flights = [[0,1,1],[1,0,1],[1,1,0]], days = [[1,3,1],[6,0,3],[3,3,3]]\nOutput: 12\nExplanation:\nOne of the best strategies is:\n1st week : fly from city 0 to city 1 on Monday, and play 6 days and work 1 day.\n(Although you start at city 0, we could also fly to and start at other cities since it is Monday.)\n2nd week : fly from city 1 to city 2 on Monday, and play 3 days and work 4 days.\n3rd week : stay at city 2, and play 3 days and work 4 days.\nAns = 6 + 3 + 3 = 12.\n
    \n\n

    Example 2:

    \n\n
    \nInput: flights = [[0,0,0],[0,0,0],[0,0,0]], days = [[1,1,1],[7,7,7],[7,7,7]]\nOutput: 3\nExplanation:\nSince there are no flights that enable you to move to another city, you have to stay at city 0 for the whole 3 weeks. \nFor each week, you only have one day to play and six days to work.\nSo the maximum number of vacation days is 3.\nAns = 1 + 1 + 1 = 3.\n
    \n\n

    Example 3:

    \n\n
    \nInput: flights = [[0,1,1],[1,0,1],[1,1,0]], days = [[7,0,0],[0,7,0],[0,0,7]]\nOutput: 21\nExplanation:\nOne of the best strategies is:\n1st week : stay at city 0, and play 7 days.\n2nd week : fly from city 0 to city 1 on Monday, and play 7 days.\n3rd week : fly from city 1 to city 2 on Monday, and play 7 days.\nAns = 7 + 7 + 7 = 21\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == flights.length
    • \n\t
    • n == flights[i].length
    • \n\t
    • n == days.length
    • \n\t
    • k == days[i].length
    • \n\t
    • 1 <= n, k <= 100
    • \n\t
    • flights[i][j] is either 0 or 1.
    • \n\t
    • 0 <= days[i] <= 7
    • \n
    \n", "content_cn": "

    \u529b\u6263\u60f3\u8ba9\u4e00\u4e2a\u6700\u4f18\u79c0\u7684\u5458\u5de5\u5728 N \u4e2a\u57ce\u5e02\u95f4\u65c5\u884c\u6765\u6536\u96c6\u7b97\u6cd5\u95ee\u9898\u3002 \u4f46\u53ea\u5de5\u4f5c\u4e0d\u73a9\u800d\uff0c\u806a\u660e\u7684\u5b69\u5b50\u4e5f\u4f1a\u53d8\u50bb\uff0c\u6240\u4ee5\u60a8\u53ef\u4ee5\u5728\u67d0\u4e9b\u7279\u5b9a\u7684\u57ce\u5e02\u548c\u661f\u671f\u4f11\u5047\u3002\u60a8\u7684\u5de5\u4f5c\u5c31\u662f\u5b89\u6392\u65c5\u884c\u4f7f\u5f97\u6700\u5927\u5316\u4f60\u53ef\u4ee5\u4f11\u5047\u7684\u5929\u6570\uff0c\u4f46\u662f\u60a8\u9700\u8981\u9075\u5b88\u4e00\u4e9b\u89c4\u5219\u548c\u9650\u5236\u3002

    \n\n

    \u89c4\u5219\u548c\u9650\u5236\uff1a

    \n\n
      \n\t
    1. \u60a8\u53ea\u80fd\u5728 N \u4e2a\u57ce\u5e02\u4e4b\u95f4\u65c5\u884c\uff0c\u7528 0 \u5230 N-1 \u7684\u7d22\u5f15\u8868\u793a\u3002\u4e00\u5f00\u59cb\uff0c\u60a8\u5728\u7d22\u5f15\u4e3a0\u7684\u57ce\u5e02\uff0c\u5e76\u4e14\u90a3\u5929\u662f\u661f\u671f\u4e00\u3002
    2. \n\t
    3. \u8fd9\u4e9b\u57ce\u5e02\u901a\u8fc7\u822a\u73ed\u76f8\u8fde\u3002\u8fd9\u4e9b\u822a\u73ed\u7528 N*N \u77e9\u9635 flights\uff08\u4e0d\u4e00\u5b9a\u662f\u5bf9\u79f0\u7684\uff09\u8868\u793a\uff0cflights[i][j] \u4ee3\u8868\u57ce\u5e02i\u5230\u57ce\u5e02j\u7684\u822a\u7a7a\u72b6\u6001\u3002\u5982\u679c\u6ca1\u6709\u57ce\u5e02i\u5230\u57ce\u5e02j\u7684\u822a\u73ed\uff0cflights[i][j] = 0\uff1b\u5426\u5219\uff0cflights[i][j] = 1\u3002\u540c\u65f6\uff0c\u5bf9\u4e8e\u6240\u6709\u7684i\uff0cflights[i][i] = 0\u3002
    4. \n\t
    5. \u60a8\u603b\u5171\u6709 K \u5468\uff08\u6bcf\u54687\u5929\uff09\u7684\u65f6\u95f4\u65c5\u884c\u3002\u60a8\u6bcf\u5929\u6700\u591a\u53ea\u80fd\u4e58\u5750\u4e00\u6b21\u822a\u73ed\uff0c\u5e76\u4e14\u53ea\u80fd\u5728\u6bcf\u5468\u7684\u661f\u671f\u4e00\u4e0a\u5348\u4e58\u5750\u822a\u73ed\u3002\u7531\u4e8e\u98de\u884c\u65f6\u95f4\u5f88\u77ed\uff0c\u6211\u4eec\u4e0d\u8003\u8651\u98de\u884c\u65f6\u95f4\u7684\u5f71\u54cd\u3002
    6. \n\t
    7. \u5bf9\u4e8e\u6bcf\u4e2a\u57ce\u5e02\uff0c\u4e0d\u540c\u7684\u661f\u671f\u60a8\u4f11\u5047\u5929\u6570\u662f\u4e0d\u540c\u7684\uff0c\u7ed9\u5b9a\u4e00\u4e2a N*K \u77e9\u9635 days \u4ee3\u8868\u8fd9\u79cd\u9650\u5236\uff0cdays[i][j] \u4ee3\u8868\u60a8\u5728\u7b2cj\u4e2a\u661f\u671f\u5728\u57ce\u5e02i\u80fd\u4f11\u5047\u7684\u6700\u957f\u5929\u6570\u3002
    8. \n
    \n\n

    \u7ed9\u5b9a flights \u77e9\u9635\u548c days \u77e9\u9635\uff0c\u60a8\u9700\u8981\u8f93\u51fa K \u5468\u5185\u53ef\u4ee5\u4f11\u5047\u7684\u6700\u957f\u5929\u6570\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165:flights = [[0,1,1],[1,0,1],[1,1,0]], days = [[1,3,1],[6,0,3],[3,3,3]]\n\u8f93\u51fa: 12\n\u89e3\u91ca: \nAns = 6 + 3 + 3 = 12. \n\n\u6700\u597d\u7684\u7b56\u7565\u4e4b\u4e00\uff1a\n\u7b2c\u4e00\u4e2a\u661f\u671f : \u661f\u671f\u4e00\u4ece\u57ce\u5e020\u98de\u5230\u57ce\u5e021\uff0c\u73a96\u5929\uff0c\u5de5\u4f5c1\u5929\u3002 \n\uff08\u867d\u7136\u4f60\u662f\u4ece\u57ce\u5e020\u5f00\u59cb\uff0c\u4f46\u56e0\u4e3a\u662f\u661f\u671f\u4e00\uff0c\u6211\u4eec\u4e5f\u53ef\u4ee5\u98de\u5230\u5176\u4ed6\u57ce\u5e02\u3002\uff09 \n\u7b2c\u4e8c\u4e2a\u661f\u671f : \u661f\u671f\u4e00\u4ece\u57ce\u5e021\u98de\u5230\u57ce\u5e022\uff0c\u73a93\u5929\uff0c\u5de5\u4f5c4\u5929\u3002\n\u7b2c\u4e09\u4e2a\u661f\u671f : \u5446\u5728\u57ce\u5e022\uff0c\u73a93\u5929\uff0c\u5de5\u4f5c4\u5929\u3002\n
    \n\n

     

    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165:flights = [[0,0,0],[0,0,0],[0,0,0]], days = [[1,1,1],[7,7,7],[7,7,7]]\n\u8f93\u51fa: 3\n\u89e3\u91ca: \nAns = 1 + 1 + 1 = 3. \n\n\u7531\u4e8e\u6ca1\u6709\u822a\u73ed\u53ef\u4ee5\u8ba9\u60a8\u98de\u5230\u5176\u4ed6\u57ce\u5e02\uff0c\u4f60\u5fc5\u987b\u5728\u57ce\u5e020\u5446\u6574\u65743\u4e2a\u661f\u671f\u3002 \n\u5bf9\u4e8e\u6bcf\u4e00\u4e2a\u661f\u671f\uff0c\u4f60\u53ea\u6709\u4e00\u5929\u65f6\u95f4\u73a9\uff0c\u5269\u4e0b\u516d\u5929\u90fd\u8981\u5de5\u4f5c\u3002 \n\u6240\u4ee5\u6700\u5927\u4f11\u5047\u5929\u6570\u4e3a3.\n
    \n\n

     

    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u8f93\u5165:flights = [[0,1,1],[1,0,1],[1,1,0]], days = [[7,0,0],[0,7,0],[0,0,7]]\n\u8f93\u51fa: 21\n\u89e3\u91ca:\nAns = 7 + 7 + 7 = 21\n\n\u6700\u597d\u7684\u7b56\u7565\u4e4b\u4e00\u662f\uff1a\n\u7b2c\u4e00\u4e2a\u661f\u671f : \u5446\u5728\u57ce\u5e020\uff0c\u73a97\u5929\u3002 \n\u7b2c\u4e8c\u4e2a\u661f\u671f : \u661f\u671f\u4e00\u4ece\u57ce\u5e020\u98de\u5230\u57ce\u5e021\uff0c\u73a97\u5929\u3002\n\u7b2c\u4e09\u4e2a\u661f\u671f : \u661f\u671f\u4e00\u4ece\u57ce\u5e021\u98de\u5230\u57ce\u5e022\uff0c\u73a97\u5929\u3002\n
    \n\n

     

    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. N \u548c K \u90fd\u662f\u6b63\u6574\u6570\uff0c\u5728 [1, 100] \u8303\u56f4\u5185\u3002
    2. \n\t
    3. \u77e9\u9635 flights \u7684\u6240\u6709\u503c\u90fd\u662f [0, 1] \u8303\u56f4\u5185\u7684\u6574\u6570\u3002
    4. \n\t
    5. \u77e9\u9635 days \u7684\u6240\u6709\u503c\u90fd\u662f [0, 7] \u8303\u56f4\u5185\u7684\u6574\u6570\u3002
    6. \n\t
    7. \u8d85\u8fc7\u4f11\u5047\u5929\u6570\u60a8\u4ecd\u53ef\u4ee5\u5446\u5728\u90a3\u4e2a\u57ce\u5e02\uff0c\u4f46\u662f\u5728\u989d\u5916\u7684\u65e5\u5b50\u60a8\u9700\u8981 \u5de5\u4f5c \uff0c\u8fd9\u4e9b\u65e5\u5b50\u4e0d\u4f1a\u7b97\u505a\u4f11\u5047\u65e5\u3002
    8. \n\t
    9. \u5982\u679c\u60a8\u4ece\u57ce\u5e02A\u98de\u5f80\u57ce\u5e02B\u5e76\u5728\u5f53\u5929\u4f11\u5047\u65e5\uff0c\u8fd9\u4e2a\u4f11\u5047\u4f1a\u88ab\u7b97\u4f5c\u662f\u57ce\u5e02B\u7684\u4f11\u5047\u65e5\u3002
    10. \n\t
    11. \u6211\u4eec\u4e0d\u8003\u8651\u98de\u884c\u65f6\u95f4\u5bf9\u8ba1\u7b97\u4f11\u5047\u65e5\u7684\u5f71\u54cd\u3002
    12. \n
    \n\n

     

    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxVacationDays(vector>& flights, vector>& days) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxVacationDays(int[][] flights, int[][] days) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxVacationDays(self, flights, days):\n \"\"\"\n :type flights: List[List[int]]\n :type days: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxVacationDays(self, flights: List[List[int]], days: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxVacationDays(int** flights, int flightsSize, int* flightsColSize, int** days, int daysSize, int* daysColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxVacationDays(int[][] flights, int[][] days) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} flights\n * @param {number[][]} days\n * @return {number}\n */\nvar maxVacationDays = function(flights, days) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} flights\n# @param {Integer[][]} days\n# @return {Integer}\ndef max_vacation_days(flights, days)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxVacationDays(_ flights: [[Int]], _ days: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxVacationDays(flights [][]int, days [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxVacationDays(flights: Array[Array[Int]], days: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxVacationDays(flights: Array, days: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_vacation_days(flights: Vec>, days: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $flights\n * @param Integer[][] $days\n * @return Integer\n */\n function maxVacationDays($flights, $days) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxVacationDays(flights: number[][], days: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-vacation-days flights days)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0568](https://leetcode-cn.com/problems/maximum-vacation-days)", "[\u6700\u5927\u4f11\u5047\u5929\u6570](/solution/0500-0599/0568.Maximum%20Vacation%20Days/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0568](https://leetcode.com/problems/maximum-vacation-days)", "[Maximum Vacation Days](/solution/0500-0599/0568.Maximum%20Vacation%20Days/README_EN.md)", "`Dynamic Programming`", "Hard", "\ud83d\udd12"]}, {"question_id": "0567", "frontend_question_id": "0567", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/permutation-in-string", "url_en": "https://leetcode.com/problems/permutation-in-string", "relative_path_cn": "/solution/0500-0599/0567.Permutation%20in%20String/README.md", "relative_path_en": "/solution/0500-0599/0567.Permutation%20in%20String/README_EN.md", "title_cn": "\u5b57\u7b26\u4e32\u7684\u6392\u5217", "title_en": "Permutation in String", "question_title_slug": "permutation-in-string", "content_en": "

    Given two strings s1 and s2, return true if s2 contains the permutation of s1.

    \n\n

    In other words, one of s1's permutations is the substring of s2.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s1 = "ab", s2 = "eidbaooo"\nOutput: true\nExplanation: s2 contains one permutation of s1 ("ba").\n
    \n\n

    Example 2:

    \n\n
    \nInput: s1 = "ab", s2 = "eidboaoo"\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s1.length, s2.length <= 104
    • \n\t
    • s1 and s2 consist of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u5b57\u7b26\u4e32\u00a0s1\u00a0\u548c\u00a0s2\uff0c\u5199\u4e00\u4e2a\u51fd\u6570\u6765\u5224\u65ad s2 \u662f\u5426\u5305\u542b s1\u00a0\u7684\u6392\u5217\u3002

    \n\n

    \u6362\u53e5\u8bdd\u8bf4\uff0c\u7b2c\u4e00\u4e2a\u5b57\u7b26\u4e32\u7684\u6392\u5217\u4e4b\u4e00\u662f\u7b2c\u4e8c\u4e2a\u5b57\u7b26\u4e32\u7684 \u5b50\u4e32 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165: s1 = \"ab\" s2 = \"eidbaooo\"\n\u8f93\u51fa: True\n\u89e3\u91ca: s2 \u5305\u542b s1 \u7684\u6392\u5217\u4e4b\u4e00 (\"ba\").\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165: s1= \"ab\" s2 = \"eidboaoo\"\n\u8f93\u51fa: False\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u8f93\u5165\u7684\u5b57\u7b26\u4e32\u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd
    • \n\t
    • \u4e24\u4e2a\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u90fd\u5728 [1, 10,000] \u4e4b\u95f4
    • \n
    \n", "tags_en": ["Two Pointers", "Sliding Window"], "tags_cn": ["\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool checkInclusion(string s1, string s2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean checkInclusion(String s1, String s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def checkInclusion(self, s1, s2):\n \"\"\"\n :type s1: str\n :type s2: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def checkInclusion(self, s1: str, s2: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool checkInclusion(char * s1, char * s2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CheckInclusion(string s1, string s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s1\n * @param {string} s2\n * @return {boolean}\n */\nvar checkInclusion = function(s1, s2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s1\n# @param {String} s2\n# @return {Boolean}\ndef check_inclusion(s1, s2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func checkInclusion(_ s1: String, _ s2: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func checkInclusion(s1 string, s2 string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def checkInclusion(s1: String, s2: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun checkInclusion(s1: String, s2: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn check_inclusion(s1: String, s2: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s1\n * @param String $s2\n * @return Boolean\n */\n function checkInclusion($s1, $s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function checkInclusion(s1: string, s2: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (check-inclusion s1 s2)\n (-> string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0567](https://leetcode-cn.com/problems/permutation-in-string)", "[\u5b57\u7b26\u4e32\u7684\u6392\u5217](/solution/0500-0599/0567.Permutation%20in%20String/README.md)", "`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0567](https://leetcode.com/problems/permutation-in-string)", "[Permutation in String](/solution/0500-0599/0567.Permutation%20in%20String/README_EN.md)", "`Two Pointers`,`Sliding Window`", "Medium", ""]}, {"question_id": "0566", "frontend_question_id": "0566", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reshape-the-matrix", "url_en": "https://leetcode.com/problems/reshape-the-matrix", "relative_path_cn": "/solution/0500-0599/0566.Reshape%20the%20Matrix/README.md", "relative_path_en": "/solution/0500-0599/0566.Reshape%20the%20Matrix/README_EN.md", "title_cn": "\u91cd\u5851\u77e9\u9635", "title_en": "Reshape the Matrix", "question_title_slug": "reshape-the-matrix", "content_en": "

    In MATLAB, there is a handy function called reshape which can reshape an m x n matrix into a new one with a different size r x c keeping its original data.

    \n\n

    You are given an m x n matrix mat and two integers r and c representing the row number and column number of the wanted reshaped matrix.

    \n\n

    The reshaped matrix should be filled with all the elements of the original matrix in the same row-traversing order as they were.

    \n\n

    If the reshape operation with given parameters is possible and legal, output the new reshaped matrix; Otherwise, output the original matrix.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: mat = [[1,2],[3,4]], r = 1, c = 4\nOutput: [[1,2,3,4]]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: mat = [[1,2],[3,4]], r = 2, c = 4\nOutput: [[1,2],[3,4]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == mat.length
    • \n\t
    • n == mat[i].length
    • \n\t
    • 1 <= m, n <= 100
    • \n\t
    • -1000 <= mat[i][j] <= 1000
    • \n\t
    • 1 <= r, c <= 300
    • \n
    \n", "content_cn": "

    \u5728MATLAB\u4e2d\uff0c\u6709\u4e00\u4e2a\u975e\u5e38\u6709\u7528\u7684\u51fd\u6570 reshape\uff0c\u5b83\u53ef\u4ee5\u5c06\u4e00\u4e2a\u77e9\u9635\u91cd\u5851\u4e3a\u53e6\u4e00\u4e2a\u5927\u5c0f\u4e0d\u540c\u7684\u65b0\u77e9\u9635\uff0c\u4f46\u4fdd\u7559\u5176\u539f\u59cb\u6570\u636e\u3002

    \n\n

    \u7ed9\u51fa\u4e00\u4e2a\u7531\u4e8c\u7ef4\u6570\u7ec4\u8868\u793a\u7684\u77e9\u9635\uff0c\u4ee5\u53ca\u4e24\u4e2a\u6b63\u6574\u6570r\u548cc\uff0c\u5206\u522b\u8868\u793a\u60f3\u8981\u7684\u91cd\u6784\u7684\u77e9\u9635\u7684\u884c\u6570\u548c\u5217\u6570\u3002

    \n\n

    \u91cd\u6784\u540e\u7684\u77e9\u9635\u9700\u8981\u5c06\u539f\u59cb\u77e9\u9635\u7684\u6240\u6709\u5143\u7d20\u4ee5\u76f8\u540c\u7684\u884c\u904d\u5386\u987a\u5e8f\u586b\u5145\u3002

    \n\n

    \u5982\u679c\u5177\u6709\u7ed9\u5b9a\u53c2\u6570\u7684reshape\u64cd\u4f5c\u662f\u53ef\u884c\u4e14\u5408\u7406\u7684\uff0c\u5219\u8f93\u51fa\u65b0\u7684\u91cd\u5851\u77e9\u9635\uff1b\u5426\u5219\uff0c\u8f93\u51fa\u539f\u59cb\u77e9\u9635\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: \nnums = \n[[1,2],\n [3,4]]\nr = 1, c = 4\n\u8f93\u51fa: \n[[1,2,3,4]]\n\u89e3\u91ca:\n\u884c\u904d\u5386nums\u7684\u7ed3\u679c\u662f [1,2,3,4]\u3002\u65b0\u7684\u77e9\u9635\u662f 1 * 4 \u77e9\u9635, \u7528\u4e4b\u524d\u7684\u5143\u7d20\u503c\u4e00\u884c\u4e00\u884c\u586b\u5145\u65b0\u77e9\u9635\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: \nnums = \n[[1,2],\n [3,4]]\nr = 2, c = 4\n\u8f93\u51fa: \n[[1,2],\n [3,4]]\n\u89e3\u91ca:\n\u6ca1\u6709\u529e\u6cd5\u5c06 2 * 2 \u77e9\u9635\u8f6c\u5316\u4e3a 2 * 4 \u77e9\u9635\u3002 \u6240\u4ee5\u8f93\u51fa\u539f\u77e9\u9635\u3002\n
    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    1. \u7ed9\u5b9a\u77e9\u9635\u7684\u5bbd\u548c\u9ad8\u8303\u56f4\u5728 [1, 100]\u3002
    2. \n\t
    3. \u7ed9\u5b9a\u7684 r \u548c c \u90fd\u662f\u6b63\u6570\u3002
    4. \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> matrixReshape(vector>& mat, int r, int c) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[][] matrixReshape(int[][] mat, int r, int c) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def matrixReshape(self, mat, r, c):\n \"\"\"\n :type mat: List[List[int]]\n :type r: int\n :type c: int\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def matrixReshape(self, mat: List[List[int]], r: int, c: int) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** matrixReshape(int** mat, int matSize, int* matColSize, int r, int c, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[][] MatrixReshape(int[][] mat, int r, int c) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} mat\n * @param {number} r\n * @param {number} c\n * @return {number[][]}\n */\nvar matrixReshape = function(mat, r, c) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} mat\n# @param {Integer} r\n# @param {Integer} c\n# @return {Integer[][]}\ndef matrix_reshape(mat, r, c)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func matrixReshape(_ mat: [[Int]], _ r: Int, _ c: Int) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func matrixReshape(mat [][]int, r int, c int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def matrixReshape(mat: Array[Array[Int]], r: Int, c: Int): Array[Array[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun matrixReshape(mat: Array, r: Int, c: Int): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn matrix_reshape(mat: Vec>, r: i32, c: i32) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $mat\n * @param Integer $r\n * @param Integer $c\n * @return Integer[][]\n */\n function matrixReshape($mat, $r, $c) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function matrixReshape(mat: number[][], r: number, c: number): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (matrix-reshape mat r c)\n (-> (listof (listof exact-integer?)) exact-integer? exact-integer? (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0566](https://leetcode-cn.com/problems/reshape-the-matrix)", "[\u91cd\u5851\u77e9\u9635](/solution/0500-0599/0566.Reshape%20the%20Matrix/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0566](https://leetcode.com/problems/reshape-the-matrix)", "[Reshape the Matrix](/solution/0500-0599/0566.Reshape%20the%20Matrix/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0565", "frontend_question_id": "0565", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/array-nesting", "url_en": "https://leetcode.com/problems/array-nesting", "relative_path_cn": "/solution/0500-0599/0565.Array%20Nesting/README.md", "relative_path_en": "/solution/0500-0599/0565.Array%20Nesting/README_EN.md", "title_cn": "\u6570\u7ec4\u5d4c\u5957", "title_en": "Array Nesting", "question_title_slug": "array-nesting", "content_en": "

    You are given an integer array nums of length n where nums is a permutation of the numbers in the range [0, n - 1].

    \n\n

    You should build a set s[k] = {nums[k], nums[nums[k]], nums[nums[nums[k]]], ... } subjected to the following rule:

    \n\n
      \n\t
    • The first element in s[k] starts with the selection of the element nums[k] of index = k.
    • \n\t
    • The next element in s[k] should be nums[nums[k]], and then nums[nums[nums[k]]], and so on.
    • \n\t
    • We stop adding right before a duplicate element occurs in s[k].
    • \n
    \n\n

    Return the longest length of a set s[k].

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [5,4,0,3,1,6,2]\nOutput: 4\nExplanation: \nnums[0] = 5, nums[1] = 4, nums[2] = 0, nums[3] = 3, nums[4] = 1, nums[5] = 6, nums[6] = 2.\nOne of the longest sets s[k]:\ns[0] = {nums[0], nums[5], nums[6], nums[2]} = {5, 6, 2, 0}\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [0,1,2]\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • 0 <= nums[i] < nums.length
    • \n\t
    • All the values of nums are unique.
    • \n
    \n", "content_cn": "

    \u7d22\u5f15\u4ece0\u5f00\u59cb\u957f\u5ea6\u4e3aN\u7684\u6570\u7ec4A\uff0c\u5305\u542b0\u5230N - 1\u7684\u6240\u6709\u6574\u6570\u3002\u627e\u5230\u6700\u5927\u7684\u96c6\u5408S\u5e76\u8fd4\u56de\u5176\u5927\u5c0f\uff0c\u5176\u4e2d S[i] = {A[i], A[A[i]], A[A[A[i]]], ... }\u4e14\u9075\u5b88\u4ee5\u4e0b\u7684\u89c4\u5219\u3002

    \n\n

    \u5047\u8bbe\u9009\u62e9\u7d22\u5f15\u4e3ai\u7684\u5143\u7d20A[i]\u4e3aS\u7684\u7b2c\u4e00\u4e2a\u5143\u7d20\uff0cS\u7684\u4e0b\u4e00\u4e2a\u5143\u7d20\u5e94\u8be5\u662fA[A[i]]\uff0c\u4e4b\u540e\u662fA[A[A[i]]]... \u4ee5\u6b64\u7c7b\u63a8\uff0c\u4e0d\u65ad\u6dfb\u52a0\u76f4\u5230S\u51fa\u73b0\u91cd\u590d\u7684\u5143\u7d20\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: A = [5,4,0,3,1,6,2]\n\u8f93\u51fa: 4\n\u89e3\u91ca: \nA[0] = 5, A[1] = 4, A[2] = 0, A[3] = 3, A[4] = 1, A[5] = 6, A[6] = 2.\n\n\u5176\u4e2d\u4e00\u79cd\u6700\u957f\u7684 S[K]:\nS[0] = {A[0], A[5], A[6], A[2]} = {5, 6, 2, 0}\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. N\u662f[1, 20,000]\u4e4b\u95f4\u7684\u6574\u6570\u3002
    2. \n\t
    3. A\u4e2d\u4e0d\u542b\u6709\u91cd\u590d\u7684\u5143\u7d20\u3002
    4. \n\t
    5. A\u4e2d\u7684\u5143\u7d20\u5927\u5c0f\u5728[0, N-1]\u4e4b\u95f4\u3002
    6. \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int arrayNesting(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int arrayNesting(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def arrayNesting(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def arrayNesting(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint arrayNesting(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ArrayNesting(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar arrayNesting = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef array_nesting(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func arrayNesting(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func arrayNesting(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def arrayNesting(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun arrayNesting(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn array_nesting(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function arrayNesting($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function arrayNesting(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (array-nesting nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0565](https://leetcode-cn.com/problems/array-nesting)", "[\u6570\u7ec4\u5d4c\u5957](/solution/0500-0599/0565.Array%20Nesting/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0565](https://leetcode.com/problems/array-nesting)", "[Array Nesting](/solution/0500-0599/0565.Array%20Nesting/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0564", "frontend_question_id": "0564", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-the-closest-palindrome", "url_en": "https://leetcode.com/problems/find-the-closest-palindrome", "relative_path_cn": "/solution/0500-0599/0564.Find%20the%20Closest%20Palindrome/README.md", "relative_path_en": "/solution/0500-0599/0564.Find%20the%20Closest%20Palindrome/README_EN.md", "title_cn": "\u5bfb\u627e\u6700\u8fd1\u7684\u56de\u6587\u6570", "title_en": "Find the Closest Palindrome", "question_title_slug": "find-the-closest-palindrome", "content_en": "

    Given a string n representing an integer, return the closest integer (not including itself), which is a palindrome. If there is a tie, return the smaller one.

    \n\n

    The closest is defined as the absolute difference minimized between two integers.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = "123"\nOutput: "121"\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = "1"\nOutput: "0"\nExplanation: 0 and 2 are the closest palindromes but we return the smallest which is 0.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n.length <= 18
    • \n\t
    • n consists of only digits.
    • \n\t
    • n does not have leading zeros.
    • \n\t
    • n is representing an integer in the range [1, 1018 - 1].
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570 n \uff0c\u4f60\u9700\u8981\u627e\u5230\u4e0e\u5b83\u6700\u8fd1\u7684\u56de\u6587\u6570\uff08\u4e0d\u5305\u62ec\u81ea\u8eab\uff09\u3002

    \n\n

    “\u6700\u8fd1\u7684”\u5b9a\u4e49\u4e3a\u4e24\u4e2a\u6574\u6570\u5dee\u7684\u7edd\u5bf9\u503c\u6700\u5c0f\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: "123"\n\u8f93\u51fa: "121"\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. n \u662f\u7531\u5b57\u7b26\u4e32\u8868\u793a\u7684\u6b63\u6574\u6570\uff0c\u5176\u957f\u5ea6\u4e0d\u8d85\u8fc718\u3002
    2. \n\t
    3. \u5982\u679c\u6709\u591a\u4e2a\u7ed3\u679c\uff0c\u8fd4\u56de\u6700\u5c0f\u7684\u90a3\u4e2a\u3002
    4. \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string nearestPalindromic(string n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String nearestPalindromic(String n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def nearestPalindromic(self, n):\n \"\"\"\n :type n: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def nearestPalindromic(self, n: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * nearestPalindromic(char * n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string NearestPalindromic(string n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} n\n * @return {string}\n */\nvar nearestPalindromic = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} n\n# @return {String}\ndef nearest_palindromic(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func nearestPalindromic(_ n: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func nearestPalindromic(n string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def nearestPalindromic(n: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun nearestPalindromic(n: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn nearest_palindromic(n: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $n\n * @return String\n */\n function nearestPalindromic($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function nearestPalindromic(n: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (nearest-palindromic n)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0564](https://leetcode-cn.com/problems/find-the-closest-palindrome)", "[\u5bfb\u627e\u6700\u8fd1\u7684\u56de\u6587\u6570](/solution/0500-0599/0564.Find%20the%20Closest%20Palindrome/README.md)", "`\u5b57\u7b26\u4e32`", "\u56f0\u96be", ""], "md_table_row_en": ["[0564](https://leetcode.com/problems/find-the-closest-palindrome)", "[Find the Closest Palindrome](/solution/0500-0599/0564.Find%20the%20Closest%20Palindrome/README_EN.md)", "`String`", "Hard", ""]}, {"question_id": "0563", "frontend_question_id": "0563", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/binary-tree-tilt", "url_en": "https://leetcode.com/problems/binary-tree-tilt", "relative_path_cn": "/solution/0500-0599/0563.Binary%20Tree%20Tilt/README.md", "relative_path_en": "/solution/0500-0599/0563.Binary%20Tree%20Tilt/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u7684\u5761\u5ea6", "title_en": "Binary Tree Tilt", "question_title_slug": "binary-tree-tilt", "content_en": "

    Given the root of a binary tree, return the sum of every tree node's tilt.

    \n\n

    The tilt of a tree node is the absolute difference between the sum of all left subtree node values and all right subtree node values. If a node does not have a left child, then the sum of the left subtree node values is treated as 0. The rule is similar if there the node does not have a right child.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,2,3]\nOutput: 1\nExplanation: \nTilt of node 2 : |0-0| = 0 (no children)\nTilt of node 3 : |0-0| = 0 (no children)\nTilt of node 1 : |2-3| = 1 (left subtree is just left child, so sum is 2; right subtree is just right child, so sum is 3)\nSum of every tilt : 0 + 0 + 1 = 1\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [4,2,9,3,5,null,7]\nOutput: 15\nExplanation: \nTilt of node 3 : |0-0| = 0 (no children)\nTilt of node 5 : |0-0| = 0 (no children)\nTilt of node 7 : |0-0| = 0 (no children)\nTilt of node 2 : |3-5| = 2 (left subtree is just left child, so sum is 3; right subtree is just right child, so sum is 5)\nTilt of node 9 : |0-7| = 7 (no left child, so sum is 0; right subtree is just right child, so sum is 7)\nTilt of node 4 : |(3+5+2)-(9+7)| = |10-16| = 6 (left subtree values are 3, 5, and 2, which sums to 10; right subtree values are 9 and 7, which sums to 16)\nSum of every tilt : 0 + 0 + 0 + 2 + 7 + 6 = 15\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: root = [21,7,14,1,1,2,2,3,3]\nOutput: 9\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [0, 104].
    • \n\t
    • -1000 <= Node.val <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811\uff0c\u8ba1\u7b97 \u6574\u4e2a\u6811 \u7684\u5761\u5ea6 \u3002

    \n\n

    \u4e00\u4e2a\u6811\u7684 \u8282\u70b9\u7684\u5761\u5ea6 \u5b9a\u4e49\u5373\u4e3a\uff0c\u8be5\u8282\u70b9\u5de6\u5b50\u6811\u7684\u8282\u70b9\u4e4b\u548c\u548c\u53f3\u5b50\u6811\u8282\u70b9\u4e4b\u548c\u7684 \u5dee\u7684\u7edd\u5bf9\u503c \u3002\u5982\u679c\u6ca1\u6709\u5de6\u5b50\u6811\u7684\u8bdd\uff0c\u5de6\u5b50\u6811\u7684\u8282\u70b9\u4e4b\u548c\u4e3a 0 \uff1b\u6ca1\u6709\u53f3\u5b50\u6811\u7684\u8bdd\u4e5f\u662f\u4e00\u6837\u3002\u7a7a\u7ed3\u70b9\u7684\u5761\u5ea6\u662f 0 \u3002

    \n\n

    \u6574\u4e2a\u6811 \u7684\u5761\u5ea6\u5c31\u662f\u5176\u6240\u6709\u8282\u70b9\u7684\u5761\u5ea6\u4e4b\u548c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [1,2,3]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\n\u8282\u70b9 2 \u7684\u5761\u5ea6\uff1a|0-0| = 0\uff08\u6ca1\u6709\u5b50\u8282\u70b9\uff09\n\u8282\u70b9 3 \u7684\u5761\u5ea6\uff1a|0-0| = 0\uff08\u6ca1\u6709\u5b50\u8282\u70b9\uff09\n\u8282\u70b9 1 \u7684\u5761\u5ea6\uff1a|2-3| = 1\uff08\u5de6\u5b50\u6811\u5c31\u662f\u5de6\u5b50\u8282\u70b9\uff0c\u6240\u4ee5\u548c\u662f 2 \uff1b\u53f3\u5b50\u6811\u5c31\u662f\u53f3\u5b50\u8282\u70b9\uff0c\u6240\u4ee5\u548c\u662f 3 \uff09\n\u5761\u5ea6\u603b\u548c\uff1a0 + 0 + 1 = 1\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [4,2,9,3,5,null,7]\n\u8f93\u51fa\uff1a15\n\u89e3\u91ca\uff1a\n\u8282\u70b9 3 \u7684\u5761\u5ea6\uff1a|0-0| = 0\uff08\u6ca1\u6709\u5b50\u8282\u70b9\uff09\n\u8282\u70b9 5 \u7684\u5761\u5ea6\uff1a|0-0| = 0\uff08\u6ca1\u6709\u5b50\u8282\u70b9\uff09\n\u8282\u70b9 7 \u7684\u5761\u5ea6\uff1a|0-0| = 0\uff08\u6ca1\u6709\u5b50\u8282\u70b9\uff09\n\u8282\u70b9 2 \u7684\u5761\u5ea6\uff1a|3-5| = 2\uff08\u5de6\u5b50\u6811\u5c31\u662f\u5de6\u5b50\u8282\u70b9\uff0c\u6240\u4ee5\u548c\u662f 3 \uff1b\u53f3\u5b50\u6811\u5c31\u662f\u53f3\u5b50\u8282\u70b9\uff0c\u6240\u4ee5\u548c\u662f 5 \uff09\n\u8282\u70b9 9 \u7684\u5761\u5ea6\uff1a|0-7| = 7\uff08\u6ca1\u6709\u5de6\u5b50\u6811\uff0c\u6240\u4ee5\u548c\u662f 0 \uff1b\u53f3\u5b50\u6811\u6b63\u597d\u662f\u53f3\u5b50\u8282\u70b9\uff0c\u6240\u4ee5\u548c\u662f 7 \uff09\n\u8282\u70b9 4 \u7684\u5761\u5ea6\uff1a|(3+5+2)-(9+7)| = |10-16| = 6\uff08\u5de6\u5b50\u6811\u503c\u4e3a 3\u30015 \u548c 2 \uff0c\u548c\u662f 10 \uff1b\u53f3\u5b50\u6811\u503c\u4e3a 9 \u548c 7 \uff0c\u548c\u662f 16 \uff09\n\u5761\u5ea6\u603b\u548c\uff1a0 + 0 + 0 + 2 + 7 + 6 = 15\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [21,7,14,1,1,2,2,3,3]\n\u8f93\u51fa\uff1a9\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u6570\u76ee\u7684\u8303\u56f4\u5728 [0, 104] \u5185
    • \n\t
    • -1000 <= Node.val <= 1000
    • \n
    \n", "tags_en": ["Tree", "Depth-first Search", "Recursion"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u9012\u5f52"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int findTilt(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int findTilt(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def findTilt(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def findTilt(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint findTilt(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int FindTilt(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar findTilt = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef find_tilt(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func findTilt(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc findTilt(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def findTilt(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun findTilt(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn find_tilt(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function findTilt($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction findTilt(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (find-tilt root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0563](https://leetcode-cn.com/problems/binary-tree-tilt)", "[\u4e8c\u53c9\u6811\u7684\u5761\u5ea6](/solution/0500-0599/0563.Binary%20Tree%20Tilt/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u9012\u5f52`", "\u7b80\u5355", ""], "md_table_row_en": ["[0563](https://leetcode.com/problems/binary-tree-tilt)", "[Binary Tree Tilt](/solution/0500-0599/0563.Binary%20Tree%20Tilt/README_EN.md)", "`Tree`,`Depth-first Search`,`Recursion`", "Easy", ""]}, {"question_id": "0562", "frontend_question_id": "0562", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/longest-line-of-consecutive-one-in-matrix", "url_en": "https://leetcode.com/problems/longest-line-of-consecutive-one-in-matrix", "relative_path_cn": "/solution/0500-0599/0562.Longest%20Line%20of%20Consecutive%20One%20in%20Matrix/README.md", "relative_path_en": "/solution/0500-0599/0562.Longest%20Line%20of%20Consecutive%20One%20in%20Matrix/README_EN.md", "title_cn": "\u77e9\u9635\u4e2d\u6700\u957f\u7684\u8fde\u7eed1\u7ebf\u6bb5", "title_en": "Longest Line of Consecutive One in Matrix", "question_title_slug": "longest-line-of-consecutive-one-in-matrix", "content_en": "

    Given an m x n binary matrix mat, return the length of the longest line of consecutive one in the matrix.

    \r\n\r\n

    The line could be horizontal, vertical, diagonal, or anti-diagonal.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\"\"\r\n
    \r\nInput: mat = [[0,1,1,0],[0,1,1,0],[0,0,0,1]]\r\nOutput: 3\r\n
    \r\n\r\n

    Example 2:

    \r\n\"\"\r\n
    \r\nInput: mat = [[1,1,1,1],[0,1,1,0],[0,0,0,1]]\r\nOutput: 4\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • m == mat.length
    • \r\n\t
    • n == mat[i].length
    • \r\n\t
    • 1 <= m, n <= 104
    • \r\n\t
    • 1 <= m * n <= 104
    • \r\n\t
    • mat[i][j] is either 0 or 1.
    • \r\n
    ", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a01\u77e9\u9635 M\uff0c\u627e\u5230\u77e9\u9635\u4e2d\u6700\u957f\u7684\u8fde\u7eed1\u7ebf\u6bb5\u3002\u8fd9\u6761\u7ebf\u6bb5\u53ef\u4ee5\u662f\u6c34\u5e73\u7684\u3001\u5782\u76f4\u7684\u3001\u5bf9\u89d2\u7ebf\u7684\u6216\u8005\u53cd\u5bf9\u89d2\u7ebf\u7684\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165:\n[[0,1,1,0],\n [0,1,1,0],\n [0,0,0,1]]\n\u8f93\u51fa: 3\n
    \n\n

    \u63d0\u793a: \u7ed9\u5b9a\u77e9\u9635\u4e2d\u7684\u5143\u7d20\u6570\u91cf\u4e0d\u4f1a\u8d85\u8fc7 10,000\u3002

    \n", "tags_en": ["Array", "Dynamic Programming"], "tags_cn": ["\u6570\u7ec4", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int longestLine(vector>& mat) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int longestLine(int[][] mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestLine(self, mat):\n \"\"\"\n :type mat: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestLine(self, mat: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint longestLine(int** mat, int matSize, int* matColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LongestLine(int[][] mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} mat\n * @return {number}\n */\nvar longestLine = function(mat) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} mat\n# @return {Integer}\ndef longest_line(mat)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestLine(_ mat: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestLine(mat [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestLine(mat: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestLine(mat: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_line(mat: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $mat\n * @return Integer\n */\n function longestLine($mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestLine(mat: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-line mat)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0562](https://leetcode-cn.com/problems/longest-line-of-consecutive-one-in-matrix)", "[\u77e9\u9635\u4e2d\u6700\u957f\u7684\u8fde\u7eed1\u7ebf\u6bb5](/solution/0500-0599/0562.Longest%20Line%20of%20Consecutive%20One%20in%20Matrix/README.md)", "`\u6570\u7ec4`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0562](https://leetcode.com/problems/longest-line-of-consecutive-one-in-matrix)", "[Longest Line of Consecutive One in Matrix](/solution/0500-0599/0562.Longest%20Line%20of%20Consecutive%20One%20in%20Matrix/README_EN.md)", "`Array`,`Dynamic Programming`", "Medium", "\ud83d\udd12"]}, {"question_id": "0561", "frontend_question_id": "0561", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/array-partition-i", "url_en": "https://leetcode.com/problems/array-partition-i", "relative_path_cn": "/solution/0500-0599/0561.Array%20Partition%20I/README.md", "relative_path_en": "/solution/0500-0599/0561.Array%20Partition%20I/README_EN.md", "title_cn": "\u6570\u7ec4\u62c6\u5206 I", "title_en": "Array Partition I", "question_title_slug": "array-partition-i", "content_en": "

    Given an integer array nums of 2n integers, group these integers into n pairs (a1, b1), (a2, b2), ..., (an, bn) such that the sum of min(ai, bi) for all i is maximized. Return the maximized sum.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,4,3,2]\nOutput: 4\nExplanation: All possible pairings (ignoring the ordering of elements) are:\n1. (1, 4), (2, 3) -> min(1, 4) + min(2, 3) = 1 + 2 = 3\n2. (1, 3), (2, 4) -> min(1, 3) + min(2, 4) = 1 + 2 = 3\n3. (1, 2), (3, 4) -> min(1, 2) + min(3, 4) = 1 + 3 = 4\nSo the maximum possible sum is 4.
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [6,2,6,5,1,2]\nOutput: 9\nExplanation: The optimal pairing is (2, 1), (2, 5), (6, 6). min(2, 1) + min(2, 5) + min(6, 6) = 1 + 2 + 6 = 9.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 104
    • \n\t
    • nums.length == 2 * n
    • \n\t
    • -104 <= nums[i] <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u957f\u5ea6\u4e3a\u00a02n\u00a0\u7684\u6574\u6570\u6570\u7ec4 nums \uff0c\u4f60\u7684\u4efb\u52a1\u662f\u5c06\u8fd9\u4e9b\u6570\u5206\u6210\u00a0n \u5bf9, \u4f8b\u5982 (a1, b1), (a2, b2), ..., (an, bn) \uff0c\u4f7f\u5f97\u4ece 1 \u5230\u00a0n \u7684 min(ai, bi) \u603b\u548c\u6700\u5927\u3002

    \n\n

    \u8fd4\u56de\u8be5 \u6700\u5927\u603b\u548c \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,4,3,2]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u6240\u6709\u53ef\u80fd\u7684\u5206\u6cd5\uff08\u5ffd\u7565\u5143\u7d20\u987a\u5e8f\uff09\u4e3a\uff1a\n1. (1, 4), (2, 3) -> min(1, 4) + min(2, 3) = 1 + 2 = 3\n2. (1, 3), (2, 4) -> min(1, 3) + min(2, 4) = 1 + 2 = 3\n3. (1, 2), (3, 4) -> min(1, 2) + min(3, 4) = 1 + 3 = 4\n\u6240\u4ee5\u6700\u5927\u603b\u548c\u4e3a 4
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [6,2,6,5,1,2]\n\u8f93\u51fa\uff1a9\n\u89e3\u91ca\uff1a\u6700\u4f18\u7684\u5206\u6cd5\u4e3a (2, 1), (2, 5), (6, 6). min(2, 1) + min(2, 5) + min(6, 6) = 1 + 2 + 6 = 9\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 104
    • \n\t
    • nums.length == 2 * n
    • \n\t
    • -104 <= nums[i] <= 104
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int arrayPairSum(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int arrayPairSum(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def arrayPairSum(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def arrayPairSum(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint arrayPairSum(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ArrayPairSum(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar arrayPairSum = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef array_pair_sum(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func arrayPairSum(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func arrayPairSum(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def arrayPairSum(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun arrayPairSum(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn array_pair_sum(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function arrayPairSum($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function arrayPairSum(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (array-pair-sum nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0561](https://leetcode-cn.com/problems/array-partition-i)", "[\u6570\u7ec4\u62c6\u5206 I](/solution/0500-0599/0561.Array%20Partition%20I/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0561](https://leetcode.com/problems/array-partition-i)", "[Array Partition I](/solution/0500-0599/0561.Array%20Partition%20I/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0560", "frontend_question_id": "0560", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/subarray-sum-equals-k", "url_en": "https://leetcode.com/problems/subarray-sum-equals-k", "relative_path_cn": "/solution/0500-0599/0560.Subarray%20Sum%20Equals%20K/README.md", "relative_path_en": "/solution/0500-0599/0560.Subarray%20Sum%20Equals%20K/README_EN.md", "title_cn": "\u548c\u4e3aK\u7684\u5b50\u6570\u7ec4", "title_en": "Subarray Sum Equals K", "question_title_slug": "subarray-sum-equals-k", "content_en": "

    Given an array of integers nums and an integer k, return the total number of continuous subarrays whose sum equals to k.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [1,1,1], k = 2\nOutput: 2\n

    Example 2:

    \n
    Input: nums = [1,2,3], k = 3\nOutput: 2\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 2 * 104
    • \n\t
    • -1000 <= nums[i] <= 1000
    • \n\t
    • -107 <= k <= 107
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u548c\u4e00\u4e2a\u6574\u6570 k\uff0c\u4f60\u9700\u8981\u627e\u5230\u8be5\u6570\u7ec4\u4e2d\u548c\u4e3a \u7684\u8fde\u7eed\u7684\u5b50\u6570\u7ec4\u7684\u4e2a\u6570\u3002

    \n\n

    \u793a\u4f8b 1 :

    \n\n
    \n\u8f93\u5165:nums = [1,1,1], k = 2\n\u8f93\u51fa: 2 , [1,1] \u4e0e [1,1] \u4e3a\u4e24\u79cd\u4e0d\u540c\u7684\u60c5\u51b5\u3002\n
    \n\n

    \u8bf4\u660e :

    \n\n
      \n\t
    1. \u6570\u7ec4\u7684\u957f\u5ea6\u4e3a [1, 20,000]\u3002
    2. \n\t
    3. \u6570\u7ec4\u4e2d\u5143\u7d20\u7684\u8303\u56f4\u662f [-1000, 1000] \uff0c\u4e14\u6574\u6570 \u7684\u8303\u56f4\u662f [-1e7, 1e7]\u3002
    4. \n
    \n", "tags_en": ["Array", "Hash Table"], "tags_cn": ["\u6570\u7ec4", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int subarraySum(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int subarraySum(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def subarraySum(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def subarraySum(self, nums: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint subarraySum(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SubarraySum(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar subarraySum = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef subarray_sum(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func subarraySum(_ nums: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func subarraySum(nums []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def subarraySum(nums: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun subarraySum(nums: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn subarray_sum(nums: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer\n */\n function subarraySum($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function subarraySum(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (subarray-sum nums k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0560](https://leetcode-cn.com/problems/subarray-sum-equals-k)", "[\u548c\u4e3aK\u7684\u5b50\u6570\u7ec4](/solution/0500-0599/0560.Subarray%20Sum%20Equals%20K/README.md)", "`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0560](https://leetcode.com/problems/subarray-sum-equals-k)", "[Subarray Sum Equals K](/solution/0500-0599/0560.Subarray%20Sum%20Equals%20K/README_EN.md)", "`Array`,`Hash Table`", "Medium", ""]}, {"question_id": "0557", "frontend_question_id": "0557", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reverse-words-in-a-string-iii", "url_en": "https://leetcode.com/problems/reverse-words-in-a-string-iii", "relative_path_cn": "/solution/0500-0599/0557.Reverse%20Words%20in%20a%20String%20III/README.md", "relative_path_en": "/solution/0500-0599/0557.Reverse%20Words%20in%20a%20String%20III/README_EN.md", "title_cn": "\u53cd\u8f6c\u5b57\u7b26\u4e32\u4e2d\u7684\u5355\u8bcd III", "title_en": "Reverse Words in a String III", "question_title_slug": "reverse-words-in-a-string-iii", "content_en": "

    Given a string s, reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.

    \n\n

     

    \n

    Example 1:

    \n
    Input: s = \"Let's take LeetCode contest\"\nOutput: \"s'teL ekat edoCteeL tsetnoc\"\n

    Example 2:

    \n
    Input: s = \"God Ding\"\nOutput: \"doG gniD\"\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 5 * 104
    • \n\t
    • s contains printable ASCII characters.
    • \n\t
    • s does not contain any leading or trailing spaces.
    • \n\t
    • There is at least one word in s.
    • \n\t
    • All the words in s are separated by a single space.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u4f60\u9700\u8981\u53cd\u8f6c\u5b57\u7b26\u4e32\u4e2d\u6bcf\u4e2a\u5355\u8bcd\u7684\u5b57\u7b26\u987a\u5e8f\uff0c\u540c\u65f6\u4ecd\u4fdd\u7559\u7a7a\u683c\u548c\u5355\u8bcd\u7684\u521d\u59cb\u987a\u5e8f\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1a"Let's take LeetCode contest"\n\u8f93\u51fa\uff1a"s'teL ekat edoCteeL tsetnoc"\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u5728\u5b57\u7b26\u4e32\u4e2d\uff0c\u6bcf\u4e2a\u5355\u8bcd\u7531\u5355\u4e2a\u7a7a\u683c\u5206\u9694\uff0c\u5e76\u4e14\u5b57\u7b26\u4e32\u4e2d\u4e0d\u4f1a\u6709\u4efb\u4f55\u989d\u5916\u7684\u7a7a\u683c\u3002
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string reverseWords(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String reverseWords(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def reverseWords(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def reverseWords(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * reverseWords(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ReverseWords(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar reverseWords = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef reverse_words(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func reverseWords(_ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func reverseWords(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def reverseWords(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun reverseWords(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn reverse_words(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function reverseWords($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function reverseWords(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (reverse-words s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0557](https://leetcode-cn.com/problems/reverse-words-in-a-string-iii)", "[\u53cd\u8f6c\u5b57\u7b26\u4e32\u4e2d\u7684\u5355\u8bcd III](/solution/0500-0599/0557.Reverse%20Words%20in%20a%20String%20III/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0557](https://leetcode.com/problems/reverse-words-in-a-string-iii)", "[Reverse Words in a String III](/solution/0500-0599/0557.Reverse%20Words%20in%20a%20String%20III/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "0556", "frontend_question_id": "0556", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/next-greater-element-iii", "url_en": "https://leetcode.com/problems/next-greater-element-iii", "relative_path_cn": "/solution/0500-0599/0556.Next%20Greater%20Element%20III/README.md", "relative_path_en": "/solution/0500-0599/0556.Next%20Greater%20Element%20III/README_EN.md", "title_cn": "\u4e0b\u4e00\u4e2a\u66f4\u5927\u5143\u7d20 III", "title_en": "Next Greater Element III", "question_title_slug": "next-greater-element-iii", "content_en": "

    Given a positive integer n, find the smallest integer which has exactly the same digits existing in the integer n and is greater in value than n. If no such positive integer exists, return -1.

    \n\n

    Note that the returned integer should fit in 32-bit integer, if there is a valid answer but it does not fit in 32-bit integer, return -1.

    \n\n

     

    \n

    Example 1:

    \n
    Input: n = 12\nOutput: 21\n

    Example 2:

    \n
    Input: n = 21\nOutput: -1\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 231 - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6b63\u6574\u6570\u00a0n \uff0c\u8bf7\u4f60\u627e\u51fa\u7b26\u5408\u6761\u4ef6\u7684\u6700\u5c0f\u6574\u6570\uff0c\u5176\u7531\u91cd\u65b0\u6392\u5217 n\u00a0\u4e2d\u5b58\u5728\u7684\u6bcf\u4f4d\u6570\u5b57\u7ec4\u6210\uff0c\u5e76\u4e14\u5176\u503c\u5927\u4e8e n \u3002\u5982\u679c\u4e0d\u5b58\u5728\u8fd9\u6837\u7684\u6b63\u6574\u6570\uff0c\u5219\u8fd4\u56de -1 \u3002

    \n\n

    \u6ce8\u610f \uff0c\u8fd4\u56de\u7684\u6574\u6570\u5e94\u5f53\u662f\u4e00\u4e2a 32 \u4f4d\u6574\u6570 \uff0c\u5982\u679c\u5b58\u5728\u6ee1\u8db3\u9898\u610f\u7684\u7b54\u6848\uff0c\u4f46\u4e0d\u662f 32 \u4f4d\u6574\u6570 \uff0c\u540c\u6837\u8fd4\u56de -1 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 12\n\u8f93\u51fa\uff1a21\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 21\n\u8f93\u51fa\uff1a-1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 231 - 1
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int nextGreaterElement(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int nextGreaterElement(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def nextGreaterElement(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def nextGreaterElement(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint nextGreaterElement(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NextGreaterElement(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar nextGreaterElement = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef next_greater_element(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func nextGreaterElement(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func nextGreaterElement(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def nextGreaterElement(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun nextGreaterElement(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn next_greater_element(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function nextGreaterElement($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function nextGreaterElement(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (next-greater-element n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0556](https://leetcode-cn.com/problems/next-greater-element-iii)", "[\u4e0b\u4e00\u4e2a\u66f4\u5927\u5143\u7d20 III](/solution/0500-0599/0556.Next%20Greater%20Element%20III/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0556](https://leetcode.com/problems/next-greater-element-iii)", "[Next Greater Element III](/solution/0500-0599/0556.Next%20Greater%20Element%20III/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "0555", "frontend_question_id": "0555", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/split-concatenated-strings", "url_en": "https://leetcode.com/problems/split-concatenated-strings", "relative_path_cn": "/solution/0500-0599/0555.Split%20Concatenated%20Strings/README.md", "relative_path_en": "/solution/0500-0599/0555.Split%20Concatenated%20Strings/README_EN.md", "title_cn": "\u5206\u5272\u8fde\u63a5\u5b57\u7b26\u4e32", "title_en": "Split Concatenated Strings", "question_title_slug": "split-concatenated-strings", "content_en": "

    You are given an array of strings strs. You could concatenate these strings together into a loop, where for each string, you could choose to reverse it or not. Among all the possible loops

    \n\n

    Return the lexicographically largest string after cutting the loop, which will make the looped string into a regular one.

    \n\n

    Specifically, to find the lexicographically largest string, you need to experience two phases:

    \n\n
      \n\t
    1. Concatenate all the strings into a loop, where you can reverse some strings or not and connect them in the same order as given.
    2. \n\t
    3. Cut and make one breakpoint in any place of the loop, which will make the looped string into a regular one starting from the character at the cutpoint.
    4. \n
    \n\n

    And your job is to find the lexicographically largest one among all the possible regular strings.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: strs = ["abc","xyz"]\nOutput: "zyxcba"\nExplanation: You can get the looped string "-abcxyz-", "-abczyx-", "-cbaxyz-", "-cbazyx-", where '-' represents the looped status. \nThe answer string came from the fourth looped one, where you could cut from the middle character 'a' and get "zyxcba".\n
    \n\n

    Example 2:

    \n\n
    \nInput: strs = ["abc"]\nOutput: "cba"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= strs.length <= 1000
    • \n\t
    • 1 <= strs[i].length <= 1000
    • \n\t
    • 1 <= sum(strs[i].length) <= 1000
    • \n\t
    • strs[i] consists of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\u5217\u8868\uff0c\u4f60\u53ef\u4ee5\u5c06\u8fd9\u4e9b\u5b57\u7b26\u4e32\u8fde\u63a5\u6210\u4e00\u4e2a\u5faa\u73af\u5b57\u7b26\u4e32\uff0c\u5bf9\u4e8e\u6bcf\u4e2a\u5b57\u7b26\u4e32\uff0c\u4f60\u53ef\u4ee5\u9009\u62e9\u662f\u5426\u7ffb\u8f6c\u5b83\u3002\u5728\u6240\u6709\u53ef\u80fd\u7684\u5faa\u73af\u5b57\u7b26\u4e32\u4e2d\uff0c\u4f60\u9700\u8981\u5206\u5272\u5faa\u73af\u5b57\u7b26\u4e32\uff08\u8fd9\u5c06\u4f7f\u5faa\u73af\u5b57\u7b26\u4e32\u53d8\u6210\u4e00\u4e2a\u5e38\u89c4\u7684\u5b57\u7b26\u4e32\uff09\uff0c\u7136\u540e\u627e\u5230\u5b57\u5178\u5e8f\u6700\u5927\u7684\u5b57\u7b26\u4e32\u3002

    \n\n

    \u5177\u4f53\u6765\u8bf4\uff0c\u8981\u627e\u5230\u5b57\u5178\u5e8f\u6700\u5927\u7684\u5b57\u7b26\u4e32\uff0c\u4f60\u9700\u8981\u7ecf\u5386\u4e24\u4e2a\u9636\u6bb5\uff1a

    \n\n
      \n\t
    1. \u5c06\u6240\u6709\u5b57\u7b26\u4e32\u8fde\u63a5\u6210\u4e00\u4e2a\u5faa\u73af\u5b57\u7b26\u4e32\uff0c\u4f60\u53ef\u4ee5\u9009\u62e9\u662f\u5426\u7ffb\u8f6c\u67d0\u4e9b\u5b57\u7b26\u4e32\uff0c\u5e76\u6309\u7167\u7ed9\u5b9a\u7684\u987a\u5e8f\u8fde\u63a5\u5b83\u4eec\u3002
    2. \n\t
    3. \u5728\u5faa\u73af\u5b57\u7b26\u4e32\u7684\u67d0\u4e2a\u4f4d\u7f6e\u5206\u5272\u5b83\uff0c\u8fd9\u5c06\u4f7f\u5faa\u73af\u5b57\u7b26\u4e32\u4ece\u5206\u5272\u70b9\u53d8\u6210\u4e00\u4e2a\u5e38\u89c4\u7684\u5b57\u7b26\u4e32\u3002
    4. \n
    \n\n

    \u4f60\u7684\u5de5\u4f5c\u662f\u5728\u6240\u6709\u53ef\u80fd\u7684\u5e38\u89c4\u5b57\u7b26\u4e32\u4e2d\u627e\u5230\u5b57\u5178\u5e8f\u6700\u5927\u7684\u4e00\u4e2a\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: "abc", "xyz"\n\u8f93\u51fa: "zyxcba"\n\u89e3\u91ca: \u4f60\u53ef\u4ee5\u5f97\u5230\u5faa\u73af\u5b57\u7b26\u4e32 "-abcxyz-", "-abczyx-", "-cbaxyz-", "-cbazyx-"\uff0c\n\u5176\u4e2d '-' \u4ee3\u8868\u5faa\u73af\u72b6\u6001\u3002 \n\u7b54\u6848\u5b57\u7b26\u4e32\u6765\u81ea\u7b2c\u56db\u4e2a\u5faa\u73af\u5b57\u7b26\u4e32\uff0c \n\u4f60\u53ef\u4ee5\u4ece\u4e2d\u95f4\u5b57\u7b26 'a' \u5206\u5272\u5f00\u7136\u540e\u5f97\u5230 "zyxcba"\u3002\n
    \n\n

     

    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u8f93\u5165\u5b57\u7b26\u4e32\u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd\u3002
    2. \n\t
    3. \u6240\u6709\u5b57\u7b26\u4e32\u7684\u603b\u957f\u5ea6\u4e0d\u4f1a\u8d85\u8fc7 1,000\u3002
    4. \n
    \n\n

     

    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string splitLoopedString(vector& strs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String splitLoopedString(String[] strs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def splitLoopedString(self, strs):\n \"\"\"\n :type strs: List[str]\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def splitLoopedString(self, strs: List[str]) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * splitLoopedString(char ** strs, int strsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string SplitLoopedString(string[] strs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} strs\n * @return {string}\n */\nvar splitLoopedString = function(strs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} strs\n# @return {String}\ndef split_looped_string(strs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func splitLoopedString(_ strs: [String]) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func splitLoopedString(strs []string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def splitLoopedString(strs: Array[String]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun splitLoopedString(strs: Array): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn split_looped_string(strs: Vec) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $strs\n * @return String\n */\n function splitLoopedString($strs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function splitLoopedString(strs: string[]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (split-looped-string strs)\n (-> (listof string?) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0555](https://leetcode-cn.com/problems/split-concatenated-strings)", "[\u5206\u5272\u8fde\u63a5\u5b57\u7b26\u4e32](/solution/0500-0599/0555.Split%20Concatenated%20Strings/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0555](https://leetcode.com/problems/split-concatenated-strings)", "[Split Concatenated Strings](/solution/0500-0599/0555.Split%20Concatenated%20Strings/README_EN.md)", "`String`", "Medium", "\ud83d\udd12"]}, {"question_id": "0554", "frontend_question_id": "0554", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/brick-wall", "url_en": "https://leetcode.com/problems/brick-wall", "relative_path_cn": "/solution/0500-0599/0554.Brick%20Wall/README.md", "relative_path_en": "/solution/0500-0599/0554.Brick%20Wall/README_EN.md", "title_cn": "\u7816\u5899", "title_en": "Brick Wall", "question_title_slug": "brick-wall", "content_en": "

    There is a rectangular brick wall in front of you with n rows of bricks. The ith row has some number of bricks each of the same height (i.e., one unit) but they can be of different widths. The total width of each row is the same.

    \n\n

    Draw a vertical line from the top to the bottom and cross the least bricks. If your line goes through the edge of a brick, then the brick is not considered as crossed. You cannot draw a line just along one of the two vertical edges of the wall, in which case the line will obviously cross no bricks.

    \n\n

    Given the 2D array wall that contains the information about the wall, return the minimum number of crossed bricks after drawing such a vertical line.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: wall = [[1,2,2,1],[3,1,2],[1,3,2],[2,4],[3,1,2],[1,3,1,1]]\nOutput: 2\n
    \n\n

    Example 2:

    \n\n
    \nInput: wall = [[1],[1],[1]]\nOutput: 3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == wall.length
    • \n\t
    • 1 <= n <= 104
    • \n\t
    • 1 <= wall[i].length <= 104
    • \n\t
    • 1 <= sum(wall[i].length) <= 2 * 104
    • \n\t
    • sum(wall[i]) is the same for each row i.
    • \n\t
    • 1 <= wall[i][j] <= 231 - 1
    • \n
    \n", "content_cn": "

    \u4f60\u7684\u9762\u524d\u6709\u4e00\u5835\u77e9\u5f62\u7684\u3001\u7531 n \u884c\u7816\u5757\u7ec4\u6210\u7684\u7816\u5899\u3002\u8fd9\u4e9b\u7816\u5757\u9ad8\u5ea6\u76f8\u540c\uff08\u4e5f\u5c31\u662f\u4e00\u4e2a\u5355\u4f4d\u9ad8\uff09\u4f46\u662f\u5bbd\u5ea6\u4e0d\u540c\u3002\u6bcf\u4e00\u884c\u7816\u5757\u7684\u5bbd\u5ea6\u4e4b\u548c\u76f8\u7b49\u3002

    \n\n

    \u4f60\u73b0\u5728\u8981\u753b\u4e00\u6761 \u81ea\u9876\u5411\u4e0b \u7684\u3001\u7a7f\u8fc7 \u6700\u5c11 \u7816\u5757\u7684\u5782\u7ebf\u3002\u5982\u679c\u4f60\u753b\u7684\u7ebf\u53ea\u662f\u4ece\u7816\u5757\u7684\u8fb9\u7f18\u7ecf\u8fc7\uff0c\u5c31\u4e0d\u7b97\u7a7f\u8fc7\u8fd9\u5757\u7816\u3002\u4f60\u4e0d\u80fd\u6cbf\u7740\u5899\u7684\u4e24\u4e2a\u5782\u76f4\u8fb9\u7f18\u4e4b\u4e00\u753b\u7ebf\uff0c\u8fd9\u6837\u663e\u7136\u662f\u6ca1\u6709\u7a7f\u8fc7\u4e00\u5757\u7816\u7684\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u4e8c\u7ef4\u6570\u7ec4 wall \uff0c\u8be5\u6570\u7ec4\u5305\u542b\u8fd9\u5835\u5899\u7684\u76f8\u5173\u4fe1\u606f\u3002\u5176\u4e2d\uff0cwall[i] \u662f\u4e00\u4e2a\u4ee3\u8868\u4ece\u5de6\u81f3\u53f3\u6bcf\u5757\u7816\u7684\u5bbd\u5ea6\u7684\u6570\u7ec4\u3002\u4f60\u9700\u8981\u627e\u51fa\u600e\u6837\u753b\u624d\u80fd\u4f7f\u8fd9\u6761\u7ebf \u7a7f\u8fc7\u7684\u7816\u5757\u6570\u91cf\u6700\u5c11 \uff0c\u5e76\u4e14\u8fd4\u56de \u7a7f\u8fc7\u7684\u7816\u5757\u6570\u91cf \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1awall = [[1,2,2,1],[3,1,2],[1,3,2],[2,4],[3,1,2],[1,3,1,1]]\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1awall = [[1],[1],[1]]\n\u8f93\u51fa\uff1a3\n
    \n\u00a0\n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == wall.length
    • \n\t
    • 1 <= n <= 104
    • \n\t
    • 1 <= wall[i].length <= 104
    • \n\t
    • 1 <= sum(wall[i].length) <= 2 * 104
    • \n\t
    • \u5bf9\u4e8e\u6bcf\u4e00\u884c i \uff0csum(wall[i]) \u662f\u76f8\u540c\u7684
    • \n\t
    • 1 <= wall[i][j] <= 231 - 1
    • \n
    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int leastBricks(vector>& wall) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int leastBricks(List> wall) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def leastBricks(self, wall):\n \"\"\"\n :type wall: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def leastBricks(self, wall: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint leastBricks(int** wall, int wallSize, int* wallColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LeastBricks(IList> wall) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} wall\n * @return {number}\n */\nvar leastBricks = function(wall) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} wall\n# @return {Integer}\ndef least_bricks(wall)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func leastBricks(_ wall: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func leastBricks(wall [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def leastBricks(wall: List[List[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun leastBricks(wall: List>): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn least_bricks(wall: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $wall\n * @return Integer\n */\n function leastBricks($wall) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function leastBricks(wall: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (least-bricks wall)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0554](https://leetcode-cn.com/problems/brick-wall)", "[\u7816\u5899](/solution/0500-0599/0554.Brick%20Wall/README.md)", "`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0554](https://leetcode.com/problems/brick-wall)", "[Brick Wall](/solution/0500-0599/0554.Brick%20Wall/README_EN.md)", "`Hash Table`", "Medium", ""]}, {"question_id": "0553", "frontend_question_id": "0553", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/optimal-division", "url_en": "https://leetcode.com/problems/optimal-division", "relative_path_cn": "/solution/0500-0599/0553.Optimal%20Division/README.md", "relative_path_en": "/solution/0500-0599/0553.Optimal%20Division/README_EN.md", "title_cn": "\u6700\u4f18\u9664\u6cd5", "title_en": "Optimal Division", "question_title_slug": "optimal-division", "content_en": "

    You are given an integer array nums. The adjacent integers in nums will perform the float division.

    \n\n
      \n\t
    • For example, for nums = [2,3,4], we will evaluate the expression "2/3/4".
    • \n
    \n\n

    However, you can add any number of parenthesis at any position to change the priority of operations. You want to add these parentheses such the value of the expression after the evaluation is maximum.

    \n\n

    Return the corresponding expression that has the maximum value in string format.

    \n\n

    Note: your expression should not contain redundant parenthesis.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1000,100,10,2]\nOutput: "1000/(100/10/2)"\nExplanation:\n1000/(100/10/2) = 1000/((100/10)/2) = 200\nHowever, the bold parenthesis in "1000/((100/10)/2)" are redundant, since they don't influence the operation priority. So you should return "1000/(100/10/2)".\nOther cases:\n1000/(100/10)/2 = 50\n1000/(100/(10/2)) = 50\n1000/100/10/2 = 0.5\n1000/100/(10/2) = 2\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [2,3,4]\nOutput: "2/(3/4)"\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [2]\nOutput: "2"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 10
    • \n\t
    • 2 <= nums[i] <= 1000
    • \n\t
    • There is only one optimal division for the given iput.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u7ec4\u6b63\u6574\u6570\uff0c\u76f8\u90bb\u7684\u6574\u6570\u4e4b\u95f4\u5c06\u4f1a\u8fdb\u884c\u6d6e\u70b9\u9664\u6cd5\u64cd\u4f5c\u3002\u4f8b\u5982\uff0c [2,3,4] -> 2 / 3 / 4 \u3002

    \n\n

    \u4f46\u662f\uff0c\u4f60\u53ef\u4ee5\u5728\u4efb\u610f\u4f4d\u7f6e\u6dfb\u52a0\u4efb\u610f\u6570\u76ee\u7684\u62ec\u53f7\uff0c\u6765\u6539\u53d8\u7b97\u6570\u7684\u4f18\u5148\u7ea7\u3002\u4f60\u9700\u8981\u627e\u51fa\u600e\u4e48\u6dfb\u52a0\u62ec\u53f7\uff0c\u624d\u80fd\u5f97\u5230\u6700\u5927\u7684\u7ed3\u679c\uff0c\u5e76\u4e14\u8fd4\u56de\u76f8\u5e94\u7684\u5b57\u7b26\u4e32\u683c\u5f0f\u7684\u8868\u8fbe\u5f0f\u3002\u4f60\u7684\u8868\u8fbe\u5f0f\u4e0d\u5e94\u8be5\u542b\u6709\u5197\u4f59\u7684\u62ec\u53f7\u3002

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165: [1000,100,10,2]\n\u8f93\u51fa: "1000/(100/10/2)"\n\u89e3\u91ca:\n1000/(100/10/2) = 1000/((100/10)/2) = 200\n\u4f46\u662f\uff0c\u4ee5\u4e0b\u52a0\u7c97\u7684\u62ec\u53f7 "1000/((100/10)/2)" \u662f\u5197\u4f59\u7684\uff0c\n\u56e0\u4e3a\u4ed6\u4eec\u5e76\u4e0d\u5f71\u54cd\u64cd\u4f5c\u7684\u4f18\u5148\u7ea7\uff0c\u6240\u4ee5\u4f60\u9700\u8981\u8fd4\u56de "1000/(100/10/2)"\u3002\n\n\u5176\u4ed6\u7528\u4f8b:\n1000/(100/10)/2 = 50\n1000/(100/(10/2)) = 50\n1000/100/10/2 = 0.5\n1000/100/(10/2) = 2\n
    \n\n

    \u8bf4\u660e:

    \n\n
      \n\t
    1. \u8f93\u5165\u6570\u7ec4\u7684\u957f\u5ea6\u5728 [1, 10] \u4e4b\u95f4\u3002
    2. \n\t
    3. \u6570\u7ec4\u4e2d\u6bcf\u4e2a\u5143\u7d20\u7684\u5927\u5c0f\u90fd\u5728 [2, 1000] \u4e4b\u95f4\u3002
    4. \n\t
    5. \u6bcf\u4e2a\u6d4b\u8bd5\u7528\u4f8b\u53ea\u6709\u4e00\u4e2a\u6700\u4f18\u9664\u6cd5\u89e3\u3002
    6. \n
    \n", "tags_en": ["Math", "String"], "tags_cn": ["\u6570\u5b66", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string optimalDivision(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String optimalDivision(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def optimalDivision(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def optimalDivision(self, nums: List[int]) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * optimalDivision(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string OptimalDivision(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {string}\n */\nvar optimalDivision = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {String}\ndef optimal_division(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func optimalDivision(_ nums: [Int]) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func optimalDivision(nums []int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def optimalDivision(nums: Array[Int]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun optimalDivision(nums: IntArray): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn optimal_division(nums: Vec) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return String\n */\n function optimalDivision($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function optimalDivision(nums: number[]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (optimal-division nums)\n (-> (listof exact-integer?) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0553](https://leetcode-cn.com/problems/optimal-division)", "[\u6700\u4f18\u9664\u6cd5](/solution/0500-0599/0553.Optimal%20Division/README.md)", "`\u6570\u5b66`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0553](https://leetcode.com/problems/optimal-division)", "[Optimal Division](/solution/0500-0599/0553.Optimal%20Division/README_EN.md)", "`Math`,`String`", "Medium", ""]}, {"question_id": "0552", "frontend_question_id": "0552", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/student-attendance-record-ii", "url_en": "https://leetcode.com/problems/student-attendance-record-ii", "relative_path_cn": "/solution/0500-0599/0552.Student%20Attendance%20Record%20II/README.md", "relative_path_en": "/solution/0500-0599/0552.Student%20Attendance%20Record%20II/README_EN.md", "title_cn": "\u5b66\u751f\u51fa\u52e4\u8bb0\u5f55 II", "title_en": "Student Attendance Record II", "question_title_slug": "student-attendance-record-ii", "content_en": "

    An attendance record for a student can be represented as a string where each character signifies whether the student was absent, late, or present on that day. The record only contains the following three characters:

    \n\n
      \n\t
    • 'A': Absent.
    • \n\t
    • 'L': Late.
    • \n\t
    • 'P': Present.
    • \n
    \n\n

    Any student is eligible for an attendance award if they meet both of the following criteria:

    \n\n
      \n\t
    • The student was absent ('A') for strictly fewer than 2 days total.
    • \n\t
    • The student was never late ('L') for 3 or more consecutive days.
    • \n
    \n\n

    Given an integer n, return the number of possible attendance records of length n that make a student eligible for an attendance award. The answer may be very large, so return it modulo 109 + 7.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 2\nOutput: 8\nExplanation: There are 8 records with length 2 that are eligible for an award:\n"PP", "AP", "PA", "LP", "PL", "AL", "LA", "LL"\nOnly "AA" is not eligible because there are 2 absences (there need to be fewer than 2).\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 1\nOutput: 3\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 10101\nOutput: 183236316\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6b63\u6574\u6570 n\uff0c\u8fd4\u56de\u957f\u5ea6\u4e3a n \u7684\u6240\u6709\u53ef\u88ab\u89c6\u4e3a\u53ef\u5956\u52b1\u7684\u51fa\u52e4\u8bb0\u5f55\u7684\u6570\u91cf\u3002 \u7b54\u6848\u53ef\u80fd\u975e\u5e38\u5927\uff0c\u4f60\u53ea\u9700\u8fd4\u56de\u7ed3\u679cmod 109 + 7\u7684\u503c\u3002

    \n\n

    \u5b66\u751f\u51fa\u52e4\u8bb0\u5f55\u662f\u53ea\u5305\u542b\u4ee5\u4e0b\u4e09\u4e2a\u5b57\u7b26\u7684\u5b57\u7b26\u4e32\uff1a

    \n\n
      \n\t
    1. 'A' : Absent\uff0c\u7f3a\u52e4
    2. \n\t
    3. 'L' : Late\uff0c\u8fdf\u5230
    4. \n\t
    5. 'P' : Present\uff0c\u5230\u573a
    6. \n
    \n\n

    \u5982\u679c\u8bb0\u5f55\u4e0d\u5305\u542b\u591a\u4e8e\u4e00\u4e2a'A'\uff08\u7f3a\u52e4\uff09\u6216\u8d85\u8fc7\u4e24\u4e2a\u8fde\u7eed\u7684'L'\uff08\u8fdf\u5230\uff09\uff0c\u5219\u8be5\u8bb0\u5f55\u88ab\u89c6\u4e3a\u53ef\u5956\u52b1\u7684\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: n = 2\n\u8f93\u51fa: 8 \n\u89e3\u91ca\uff1a\n\u67098\u4e2a\u957f\u5ea6\u4e3a2\u7684\u8bb0\u5f55\u5c06\u88ab\u89c6\u4e3a\u53ef\u5956\u52b1\uff1a\n"PP" , "AP", "PA", "LP", "PL", "AL", "LA", "LL"\n\u53ea\u6709"AA"\u4e0d\u4f1a\u88ab\u89c6\u4e3a\u53ef\u5956\u52b1\uff0c\u56e0\u4e3a\u7f3a\u52e4\u6b21\u6570\u8d85\u8fc7\u4e00\u6b21\u3002
    \n\n

    \u6ce8\u610f\uff1an \u7684\u503c\u4e0d\u4f1a\u8d85\u8fc7100000\u3002

    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int checkRecord(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int checkRecord(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def checkRecord(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def checkRecord(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint checkRecord(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CheckRecord(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar checkRecord = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef check_record(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func checkRecord(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func checkRecord(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def checkRecord(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun checkRecord(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn check_record(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function checkRecord($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function checkRecord(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (check-record n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0552](https://leetcode-cn.com/problems/student-attendance-record-ii)", "[\u5b66\u751f\u51fa\u52e4\u8bb0\u5f55 II](/solution/0500-0599/0552.Student%20Attendance%20Record%20II/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0552](https://leetcode.com/problems/student-attendance-record-ii)", "[Student Attendance Record II](/solution/0500-0599/0552.Student%20Attendance%20Record%20II/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "0551", "frontend_question_id": "0551", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/student-attendance-record-i", "url_en": "https://leetcode.com/problems/student-attendance-record-i", "relative_path_cn": "/solution/0500-0599/0551.Student%20Attendance%20Record%20I/README.md", "relative_path_en": "/solution/0500-0599/0551.Student%20Attendance%20Record%20I/README_EN.md", "title_cn": "\u5b66\u751f\u51fa\u52e4\u8bb0\u5f55 I", "title_en": "Student Attendance Record I", "question_title_slug": "student-attendance-record-i", "content_en": "

    You are given a string s representing an attendance record for a student where each character signifies whether the student was absent, late, or present on that day. The record only contains the following three characters:

    \n\n
      \n\t
    • 'A': Absent.
    • \n\t
    • 'L': Late.
    • \n\t
    • 'P': Present.
    • \n
    \n\n

    The student is eligible for an attendance award if they meet both of the following criteria:

    \n\n
      \n\t
    • The student was absent ('A') for strictly fewer than 2 days total.
    • \n\t
    • The student was never late ('L') for 3 or more consecutive days.
    • \n
    \n\n

    Return true if the student is eligible for an attendance award, or false otherwise.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "PPALLP"\nOutput: true\nExplanation: The student has fewer than 2 absences and was never late 3 or more consecutive days.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "PPALLL"\nOutput: false\nExplanation: The student was late 3 consecutive days in the last 3 days, so is not eligible for the award.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 1000
    • \n\t
    • s[i] is either 'A', 'L', or 'P'.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\u6765\u4ee3\u8868\u4e00\u4e2a\u5b66\u751f\u7684\u51fa\u52e4\u8bb0\u5f55\uff0c\u8fd9\u4e2a\u8bb0\u5f55\u4ec5\u5305\u542b\u4ee5\u4e0b\u4e09\u4e2a\u5b57\u7b26\uff1a

    \n\n
      \n\t
    1. 'A' : Absent\uff0c\u7f3a\u52e4
    2. \n\t
    3. 'L' : Late\uff0c\u8fdf\u5230
    4. \n\t
    5. 'P' : Present\uff0c\u5230\u573a
    6. \n
    \n\n

    \u5982\u679c\u4e00\u4e2a\u5b66\u751f\u7684\u51fa\u52e4\u8bb0\u5f55\u4e2d\u4e0d\u8d85\u8fc7\u4e00\u4e2a'A'(\u7f3a\u52e4)\u5e76\u4e14\u4e0d\u8d85\u8fc7\u4e24\u4e2a\u8fde\u7eed\u7684'L'(\u8fdf\u5230),\u90a3\u4e48\u8fd9\u4e2a\u5b66\u751f\u4f1a\u88ab\u5956\u8d4f\u3002

    \n\n

    \u4f60\u9700\u8981\u6839\u636e\u8fd9\u4e2a\u5b66\u751f\u7684\u51fa\u52e4\u8bb0\u5f55\u5224\u65ad\u4ed6\u662f\u5426\u4f1a\u88ab\u5956\u8d4f\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: "PPALLP"\n\u8f93\u51fa: True\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: "PPALLL"\n\u8f93\u51fa: False\n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool checkRecord(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean checkRecord(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def checkRecord(self, s):\n \"\"\"\n :type s: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def checkRecord(self, s: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool checkRecord(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CheckRecord(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {boolean}\n */\nvar checkRecord = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Boolean}\ndef check_record(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func checkRecord(_ s: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func checkRecord(s string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def checkRecord(s: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun checkRecord(s: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn check_record(s: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Boolean\n */\n function checkRecord($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function checkRecord(s: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (check-record s)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0551](https://leetcode-cn.com/problems/student-attendance-record-i)", "[\u5b66\u751f\u51fa\u52e4\u8bb0\u5f55 I](/solution/0500-0599/0551.Student%20Attendance%20Record%20I/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0551](https://leetcode.com/problems/student-attendance-record-i)", "[Student Attendance Record I](/solution/0500-0599/0551.Student%20Attendance%20Record%20I/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "0550", "frontend_question_id": "1730", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/shortest-path-to-get-food", "url_en": "https://leetcode.com/problems/shortest-path-to-get-food", "relative_path_cn": "/solution/1700-1799/1730.Shortest%20Path%20to%20Get%20Food/README.md", "relative_path_en": "/solution/1700-1799/1730.Shortest%20Path%20to%20Get%20Food/README_EN.md", "title_cn": "\u83b7\u53d6\u98df\u7269\u7684\u6700\u77ed\u8def\u5f84", "title_en": "Shortest Path to Get Food", "question_title_slug": "shortest-path-to-get-food", "content_en": "

    You are starving and you want to eat food as quickly as possible. You want to find the shortest path to arrive at any food cell.

    \n\n

    You are given an m x n character matrix, grid, of these different types of cells:

    \n\n
      \n\t
    • '*' is your location. There is exactly one '*' cell.
    • \n\t
    • '#' is a food cell. There may be multiple food cells.
    • \n\t
    • 'O' is free space, and you can travel through these cells.
    • \n\t
    • 'X' is an obstacle, and you cannot travel through these cells.
    • \n
    \n\n

    You can travel to any adjacent cell north, east, south, or west of your current location if there is not an obstacle.

    \n\n

    Return the length of the shortest path for you to reach any food cell. If there is no path for you to reach food, return -1.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: grid = [["X","X","X","X","X","X"],["X","*","O","O","O","X"],["X","O","O","#","O","X"],["X","X","X","X","X","X"]]\nOutput: 3\nExplanation: It takes 3 steps to reach the food.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: grid = [["X","X","X","X","X"],["X","*","X","O","X"],["X","O","X","#","X"],["X","X","X","X","X"]]\nOutput: -1\nExplanation: It is not possible to reach the food.\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: grid = [["X","X","X","X","X","X","X","X"],["X","*","O","X","O","#","O","X"],["X","O","O","X","O","O","X","X"],["X","O","O","O","O","#","O","X"],["X","X","X","X","X","X","X","X"]]\nOutput: 6\nExplanation: There can be multiple food cells. It only takes 6 steps to reach the bottom food.
    \n\n

    Example 4:

    \n\n
    \nInput: grid = [["O","*"],["#","O"]]\nOutput: 2\n
    \n\n

    Example 5:

    \n\n
    \nInput: grid = [["X","*"],["#","X"]]\nOutput: -1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= m, n <= 200
    • \n\t
    • grid[row][col] is '*', 'X', 'O', or '#'.
    • \n\t
    • The grid contains exactly one '*'.
    • \n
    \n", "content_cn": "

    \u4f60\u73b0\u5728\u5f88\u997f\uff0c\u60f3\u8981\u5c3d\u5feb\u627e\u4e1c\u897f\u5403\u3002\u4f60\u9700\u8981\u627e\u5230\u6700\u77ed\u7684\u8def\u5f84\u5230\u8fbe\u4e00\u4e2a\u98df\u7269\u6240\u5728\u7684\u683c\u5b50\u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u00a0m x n\u00a0\u7684\u5b57\u7b26\u77e9\u9635\u00a0grid\u00a0\uff0c\u5305\u542b\u4e0b\u5217\u4e0d\u540c\u7c7b\u578b\u7684\u683c\u5b50\uff1a

    \n\n
      \n\t
    • '*'\u00a0\u662f\u4f60\u7684\u4f4d\u7f6e\u3002\u77e9\u9635\u4e2d\u6709\u4e14\u53ea\u6709\u4e00\u4e2a\u00a0'*'\u00a0\u683c\u5b50\u3002
    • \n\t
    • '#' \u662f\u98df\u7269\u3002\u77e9\u9635\u4e2d\u53ef\u80fd\u5b58\u5728\u591a\u4e2a\u98df\u7269\u3002
    • \n\t
    • 'O'\u00a0\u662f\u7a7a\u5730\uff0c\u4f60\u53ef\u4ee5\u7a7f\u8fc7\u8fd9\u4e9b\u683c\u5b50\u3002
    • \n\t
    • 'X'\u00a0\u662f\u969c\u788d\uff0c\u4f60\u4e0d\u53ef\u4ee5\u7a7f\u8fc7\u8fd9\u4e9b\u683c\u5b50\u3002
    • \n
    \n\n

    \u8fd4\u56de\u4f60\u5230\u4efb\u610f\u98df\u7269\u7684\u6700\u77ed\u8def\u5f84\u7684\u957f\u5ea6\u3002\u5982\u679c\u4e0d\u5b58\u5728\u4f60\u5230\u4efb\u610f\u98df\u7269\u7684\u8def\u5f84\uff0c\u8fd4\u56de\u00a0-1\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1:

    \n\"\"\n
    \u8f93\u5165\uff1a grid = [[\"X\",\"X\",\"X\",\"X\",\"X\",\"X\"],[\"X\",\"*\",\"O\",\"O\",\"O\",\"X\"],[\"X\",\"O\",\"O\",\"#\",\"O\",\"X\"],[\"X\",\"X\",\"X\",\"X\",\"X\",\"X\"]]\n\u8f93\u51fa\uff1a 3\n\u89e3\u91ca\uff1a \u8981\u62ff\u5230\u98df\u7269\uff0c\u4f60\u9700\u8981\u8d70 3 \u6b65\u3002
    \n\n

    Example 2:

    \n\"\"\n
    \u8f93\u5165\uff1a grid = [[\"X\",\"X\",\"X\",\"X\",\"X\"],[\"X\",\"*\",\"X\",\"O\",\"X\"],[\"X\",\"O\",\"X\",\"#\",\"X\"],[\"X\",\"X\",\"X\",\"X\",\"X\"]]\n\u8f93\u51fa\uff1a -1\n\u89e3\u91ca\uff1a \u4f60\u4e0d\u53ef\u80fd\u62ff\u5230\u98df\u7269\u3002\n
    \n\n

    \u793a\u4f8b\u00a03:

    \n\"\"\n
    \u8f93\u5165: grid = [[\"X\",\"X\",\"X\",\"X\",\"X\",\"X\",\"X\",\"X\"],[\"X\",\"*\",\"O\",\"X\",\"O\",\"#\",\"O\",\"X\"],[\"X\",\"O\",\"O\",\"X\",\"O\",\"O\",\"X\",\"X\"],[\"X\",\"O\",\"O\",\"O\",\"O\",\"#\",\"O\",\"X\"],[\"X\",\"X\",\"X\",\"X\",\"X\",\"X\",\"X\",\"X\"]]\n\u8f93\u51fa: 6\n\u89e3\u91ca: \u8fd9\u91cc\u6709\u591a\u4e2a\u98df\u7269\u3002\u62ff\u5230\u4e0b\u8fb9\u7684\u98df\u7269\u4ec5\u9700\u8d70 6 \u6b65\u3002
    \n\n

    \u793a\u4f8b 4:

    \n\n
    \u8f93\u5165: grid = [[\"O\",\"*\"],[\"#\",\"O\"]]\n\u8f93\u51fa: 2\n
    \n\n

    \u793a\u4f8b 5:

    \n\n
    \u8f93\u5165: grid = [[\"X\",\"*\"],[\"#\",\"X\"]]\n\u8f93\u51fa:\u00a0-1
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= m, n <= 200
    • \n\t
    • grid[row][col]\u00a0\u662f\u00a0'*'\u3001\u00a0'X'\u3001\u00a0'O'\u00a0\u6216\u00a0'#'\u00a0\u3002
    • \n\t
    • grid\u00a0\u4e2d\u6709\u4e14\u53ea\u6709\u4e00\u4e2a\u00a0'*'\u00a0\u3002
    • \n
    \n", "tags_en": ["Depth-first Search", "Breadth-first Search", "Graph"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int getFood(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int getFood(char[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getFood(self, grid):\n \"\"\"\n :type grid: List[List[str]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getFood(self, grid: List[List[str]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint getFood(char** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int GetFood(char[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {character[][]} grid\n * @return {number}\n */\nvar getFood = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Character[][]} grid\n# @return {Integer}\ndef get_food(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getFood(_ grid: [[Character]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getFood(grid [][]byte) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getFood(grid: Array[Array[Char]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getFood(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_food(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $grid\n * @return Integer\n */\n function getFood($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getFood(grid: string[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-food grid)\n (-> (listof (listof char?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1730](https://leetcode-cn.com/problems/shortest-path-to-get-food)", "[\u83b7\u53d6\u98df\u7269\u7684\u6700\u77ed\u8def\u5f84](/solution/1700-1799/1730.Shortest%20Path%20to%20Get%20Food/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u56fe`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1730](https://leetcode.com/problems/shortest-path-to-get-food)", "[Shortest Path to Get Food](/solution/1700-1799/1730.Shortest%20Path%20to%20Get%20Food/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`,`Graph`", "Medium", "\ud83d\udd12"]}, {"question_id": "0549", "frontend_question_id": "0549", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/binary-tree-longest-consecutive-sequence-ii", "url_en": "https://leetcode.com/problems/binary-tree-longest-consecutive-sequence-ii", "relative_path_cn": "/solution/0500-0599/0549.Binary%20Tree%20Longest%20Consecutive%20Sequence%20II/README.md", "relative_path_en": "/solution/0500-0599/0549.Binary%20Tree%20Longest%20Consecutive%20Sequence%20II/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u4e2d\u6700\u957f\u7684\u8fde\u7eed\u5e8f\u5217", "title_en": "Binary Tree Longest Consecutive Sequence II", "question_title_slug": "binary-tree-longest-consecutive-sequence-ii", "content_en": "

    Given the root of a binary tree, return the length of the longest consecutive path in the tree.

    \n\n

    This path can be either increasing or decreasing.

    \n\n
      \n\t
    • For example, [1,2,3,4] and [4,3,2,1] are both considered valid, but the path [1,2,4,3] is not valid.
    • \n
    \n\n

    On the other hand, the path can be in the child-Parent-child order, where not necessarily be parent-child order.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,2,3]\nOutput: 2\nExplanation: The longest consecutive path is [1, 2] or [2, 1].\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [2,1,3]\nOutput: 3\nExplanation: The longest consecutive path is [1, 2, 3] or [3, 2, 1].\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 3 * 104].
    • \n\t
    • -3 * 104 <= Node.val <= 3 * 104
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811\uff0c\u4f60\u9700\u8981\u627e\u51fa\u4e8c\u53c9\u6811\u4e2d\u6700\u957f\u7684\u8fde\u7eed\u5e8f\u5217\u8def\u5f84\u7684\u957f\u5ea6\u3002

    \n\n

    \u8bf7\u6ce8\u610f\uff0c\u8be5\u8def\u5f84\u53ef\u4ee5\u662f\u9012\u589e\u7684\u6216\u8005\u662f\u9012\u51cf\u3002\u4f8b\u5982\uff0c[1,2,3,4] \u548c [4,3,2,1] \u90fd\u88ab\u8ba4\u4e3a\u662f\u5408\u6cd5\u7684\uff0c\u800c\u8def\u5f84 [1,2,4,3] \u5219\u4e0d\u5408\u6cd5\u3002\u53e6\u4e00\u65b9\u9762\uff0c\u8def\u5f84\u53ef\u4ee5\u662f \u5b50-\u7236-\u5b50 \u987a\u5e8f\uff0c\u5e76\u4e0d\u4e00\u5b9a\u662f \u7236-\u5b50 \u987a\u5e8f\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165:\n        1\n       / \\\n      2   3\n\u8f93\u51fa: 2\n\u89e3\u91ca: \u6700\u957f\u7684\u8fde\u7eed\u8def\u5f84\u662f [1, 2] \u6216\u8005 [2, 1]\u3002\n
    \n\n

     

    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165:\n        2\n       / \\\n      1   3\n\u8f93\u51fa: 3\n\u89e3\u91ca: \u6700\u957f\u7684\u8fde\u7eed\u8def\u5f84\u662f [1, 2, 3] \u6216\u8005 [3, 2, 1]\u3002\n
    \n\n

     

    \n\n

    \u6ce8\u610f: \u6811\u4e0a\u6240\u6709\u8282\u70b9\u7684\u503c\u90fd\u5728 [-1e7, 1e7] \u8303\u56f4\u5185\u3002

    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int longestConsecutive(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int longestConsecutive(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def longestConsecutive(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def longestConsecutive(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint longestConsecutive(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int LongestConsecutive(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar longestConsecutive = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef longest_consecutive(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func longestConsecutive(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc longestConsecutive(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def longestConsecutive(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun longestConsecutive(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn longest_consecutive(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function longestConsecutive($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction longestConsecutive(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (longest-consecutive root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0549](https://leetcode-cn.com/problems/binary-tree-longest-consecutive-sequence-ii)", "[\u4e8c\u53c9\u6811\u4e2d\u6700\u957f\u7684\u8fde\u7eed\u5e8f\u5217](/solution/0500-0599/0549.Binary%20Tree%20Longest%20Consecutive%20Sequence%20II/README.md)", "`\u6811`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0549](https://leetcode.com/problems/binary-tree-longest-consecutive-sequence-ii)", "[Binary Tree Longest Consecutive Sequence II](/solution/0500-0599/0549.Binary%20Tree%20Longest%20Consecutive%20Sequence%20II/README_EN.md)", "`Tree`", "Medium", "\ud83d\udd12"]}, {"question_id": "0548", "frontend_question_id": "0548", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/split-array-with-equal-sum", "url_en": "https://leetcode.com/problems/split-array-with-equal-sum", "relative_path_cn": "/solution/0500-0599/0548.Split%20Array%20with%20Equal%20Sum/README.md", "relative_path_en": "/solution/0500-0599/0548.Split%20Array%20with%20Equal%20Sum/README_EN.md", "title_cn": "\u5c06\u6570\u7ec4\u5206\u5272\u6210\u548c\u76f8\u7b49\u7684\u5b50\u6570\u7ec4", "title_en": "Split Array with Equal Sum", "question_title_slug": "split-array-with-equal-sum", "content_en": "

    Given an integer array nums of length n, return true if there is a triplet (i, j, k) which satisfies the following conditions:

    \n\n
      \n\t
    • 0 < i, i + 1 < j, j + 1 < k < n - 1
    • \n\t
    • The sum of subarrays (0, i - 1), (i + 1, j - 1), (j + 1, k - 1) and (k + 1, n - 1) is equal.
    • \n
    \nA subarray (l, r) represents a slice of the original array starting from the element indexed l to the element indexed r.\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,1,2,1,2,1]\nOutput: true\nExplanation:\ni = 1, j = 3, k = 5. \nsum(0, i - 1) = sum(0, 0) = 1\nsum(i + 1, j - 1) = sum(2, 2) = 1\nsum(j + 1, k - 1) = sum(4, 4) = 1\nsum(k + 1, n - 1) = sum(6, 6) = 1\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,2,1,2,1,2,1,2]\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= n <= 2000
    • \n\t
    • -106 <= nums[i] <= 106
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6709 n \u4e2a\u6574\u6570\u7684\u6570\u7ec4\uff0c\u4f60\u9700\u8981\u627e\u5230\u6ee1\u8db3\u4ee5\u4e0b\u6761\u4ef6\u7684\u4e09\u5143\u7ec4 (i, j, k) \uff1a

    \n\n
      \n\t
    1. 0 < i, i + 1 < j, j + 1 < k < n - 1
    2. \n\t
    3. \u5b50\u6570\u7ec4 (0, i - 1)\uff0c(i + 1, j - 1)\uff0c(j + 1, k - 1)\uff0c(k + 1, n - 1) \u7684\u548c\u5e94\u8be5\u76f8\u7b49\u3002
    4. \n
    \n\n

    \u8fd9\u91cc\u6211\u4eec\u5b9a\u4e49\u5b50\u6570\u7ec4 (L, R) \u8868\u793a\u539f\u6570\u7ec4\u4ece\u7d22\u5f15\u4e3aL\u7684\u5143\u7d20\u5f00\u59cb\u81f3\u7d22\u5f15\u4e3aR\u7684\u5143\u7d20\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: [1,2,1,2,1,2,1]\n\u8f93\u51fa: True\n\u89e3\u91ca:\ni = 1, j = 3, k = 5. \nsum(0, i - 1) = sum(0, 0) = 1\nsum(i + 1, j - 1) = sum(2, 2) = 1\nsum(j + 1, k - 1) = sum(4, 4) = 1\nsum(k + 1, n - 1) = sum(6, 6) = 1\n
    \n\n

     

    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. 1 <= n <= 2000\u3002
    2. \n\t
    3. \u7ed9\u5b9a\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u4f1a\u5728 [-1,000,000, 1,000,000] \u8303\u56f4\u5185\u3002
    4. \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool splitArray(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean splitArray(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def splitArray(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def splitArray(self, nums: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool splitArray(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool SplitArray(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {boolean}\n */\nvar splitArray = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Boolean}\ndef split_array(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func splitArray(_ nums: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func splitArray(nums []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def splitArray(nums: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun splitArray(nums: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn split_array(nums: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Boolean\n */\n function splitArray($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function splitArray(nums: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (split-array nums)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0548](https://leetcode-cn.com/problems/split-array-with-equal-sum)", "[\u5c06\u6570\u7ec4\u5206\u5272\u6210\u548c\u76f8\u7b49\u7684\u5b50\u6570\u7ec4](/solution/0500-0599/0548.Split%20Array%20with%20Equal%20Sum/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0548](https://leetcode.com/problems/split-array-with-equal-sum)", "[Split Array with Equal Sum](/solution/0500-0599/0548.Split%20Array%20with%20Equal%20Sum/README_EN.md)", "`Array`", "Medium", "\ud83d\udd12"]}, {"question_id": "0547", "frontend_question_id": "0547", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-provinces", "url_en": "https://leetcode.com/problems/number-of-provinces", "relative_path_cn": "/solution/0500-0599/0547.Number%20of%20Provinces/README.md", "relative_path_en": "/solution/0500-0599/0547.Number%20of%20Provinces/README_EN.md", "title_cn": "\u7701\u4efd\u6570\u91cf", "title_en": "Number of Provinces", "question_title_slug": "number-of-provinces", "content_en": "

    There are n cities. Some of them are connected, while some are not. If city a is connected directly with city b, and city b is connected directly with city c, then city a is connected indirectly with city c.

    \n\n

    A province is a group of directly or indirectly connected cities and no other cities outside of the group.

    \n\n

    You are given an n x n matrix isConnected where isConnected[i][j] = 1 if the ith city and the jth city are directly connected, and isConnected[i][j] = 0 otherwise.

    \n\n

    Return the total number of provinces.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: isConnected = [[1,1,0],[1,1,0],[0,0,1]]\nOutput: 2\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: isConnected = [[1,0,0],[0,1,0],[0,0,1]]\nOutput: 3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 200
    • \n\t
    • n == isConnected.length
    • \n\t
    • n == isConnected[i].length
    • \n\t
    • isConnected[i][j] is 1 or 0.
    • \n\t
    • isConnected[i][i] == 1
    • \n\t
    • isConnected[i][j] == isConnected[j][i]
    • \n
    \n", "content_cn": "
    \n
    \n

    \u6709 n \u4e2a\u57ce\u5e02\uff0c\u5176\u4e2d\u4e00\u4e9b\u5f7c\u6b64\u76f8\u8fde\uff0c\u53e6\u4e00\u4e9b\u6ca1\u6709\u76f8\u8fde\u3002\u5982\u679c\u57ce\u5e02 a \u4e0e\u57ce\u5e02 b \u76f4\u63a5\u76f8\u8fde\uff0c\u4e14\u57ce\u5e02 b \u4e0e\u57ce\u5e02 c \u76f4\u63a5\u76f8\u8fde\uff0c\u90a3\u4e48\u57ce\u5e02 a \u4e0e\u57ce\u5e02 c \u95f4\u63a5\u76f8\u8fde\u3002

    \n\n

    \u7701\u4efd \u662f\u4e00\u7ec4\u76f4\u63a5\u6216\u95f4\u63a5\u76f8\u8fde\u7684\u57ce\u5e02\uff0c\u7ec4\u5185\u4e0d\u542b\u5176\u4ed6\u6ca1\u6709\u76f8\u8fde\u7684\u57ce\u5e02\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a n x n \u7684\u77e9\u9635 isConnected \uff0c\u5176\u4e2d isConnected[i][j] = 1 \u8868\u793a\u7b2c i \u4e2a\u57ce\u5e02\u548c\u7b2c j \u4e2a\u57ce\u5e02\u76f4\u63a5\u76f8\u8fde\uff0c\u800c isConnected[i][j] = 0 \u8868\u793a\u4e8c\u8005\u4e0d\u76f4\u63a5\u76f8\u8fde\u3002

    \n\n

    \u8fd4\u56de\u77e9\u9635\u4e2d \u7701\u4efd \u7684\u6570\u91cf\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aisConnected = [[1,1,0],[1,1,0],[0,0,1]]\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aisConnected = [[1,0,0],[0,1,0],[0,0,1]]\n\u8f93\u51fa\uff1a3\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 200
    • \n\t
    • n == isConnected.length
    • \n\t
    • n == isConnected[i].length
    • \n\t
    • isConnected[i][j] \u4e3a 1 \u6216 0
    • \n\t
    • isConnected[i][i] == 1
    • \n\t
    • isConnected[i][j] == isConnected[j][i]
    • \n
    \n
    \n
    \n", "tags_en": ["Depth-first Search", "Union Find"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e76\u67e5\u96c6"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findCircleNum(vector>& isConnected) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findCircleNum(int[][] isConnected) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findCircleNum(self, isConnected):\n \"\"\"\n :type isConnected: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findCircleNum(self, isConnected: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findCircleNum(int** isConnected, int isConnectedSize, int* isConnectedColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindCircleNum(int[][] isConnected) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} isConnected\n * @return {number}\n */\nvar findCircleNum = function(isConnected) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} is_connected\n# @return {Integer}\ndef find_circle_num(is_connected)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findCircleNum(_ isConnected: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findCircleNum(isConnected [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findCircleNum(isConnected: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findCircleNum(isConnected: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_circle_num(is_connected: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $isConnected\n * @return Integer\n */\n function findCircleNum($isConnected) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findCircleNum(isConnected: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-circle-num isConnected)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0547](https://leetcode-cn.com/problems/number-of-provinces)", "[\u7701\u4efd\u6570\u91cf](/solution/0500-0599/0547.Number%20of%20Provinces/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e76\u67e5\u96c6`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0547](https://leetcode.com/problems/number-of-provinces)", "[Number of Provinces](/solution/0500-0599/0547.Number%20of%20Provinces/README_EN.md)", "`Depth-first Search`,`Union Find`", "Medium", ""]}, {"question_id": "0546", "frontend_question_id": "0546", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/remove-boxes", "url_en": "https://leetcode.com/problems/remove-boxes", "relative_path_cn": "/solution/0500-0599/0546.Remove%20Boxes/README.md", "relative_path_en": "/solution/0500-0599/0546.Remove%20Boxes/README_EN.md", "title_cn": "\u79fb\u9664\u76d2\u5b50", "title_en": "Remove Boxes", "question_title_slug": "remove-boxes", "content_en": "

    You are given several boxes with different colors represented by different positive numbers.

    \n\n

    You may experience several rounds to remove boxes until there is no box left. Each time you can choose some continuous boxes with the same color (i.e., composed of k boxes, k >= 1), remove them and get k * k points.

    \n\n

    Return the maximum points you can get.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: boxes = [1,3,2,2,2,3,4,3,1]\nOutput: 23\nExplanation:\n[1, 3, 2, 2, 2, 3, 4, 3, 1] \n----> [1, 3, 3, 4, 3, 1] (3*3=9 points) \n----> [1, 3, 3, 3, 1] (1*1=1 points) \n----> [1, 1] (3*3=9 points) \n----> [] (2*2=4 points)\n
    \n\n

    Example 2:

    \n\n
    \nInput: boxes = [1,1,1]\nOutput: 9\n
    \n\n

    Example 3:

    \n\n
    \nInput: boxes = [1]\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= boxes.length <= 100
    • \n\t
    • 1 <= boxes[i] <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u51fa\u4e00\u4e9b\u4e0d\u540c\u989c\u8272\u7684\u76d2\u5b50\uff0c\u76d2\u5b50\u7684\u989c\u8272\u7531\u6570\u5b57\u8868\u793a\uff0c\u5373\u4e0d\u540c\u7684\u6570\u5b57\u8868\u793a\u4e0d\u540c\u7684\u989c\u8272\u3002

    \n\n

    \u4f60\u5c06\u7ecf\u8fc7\u82e5\u5e72\u8f6e\u64cd\u4f5c\u53bb\u53bb\u6389\u76d2\u5b50\uff0c\u76f4\u5230\u6240\u6709\u7684\u76d2\u5b50\u90fd\u53bb\u6389\u4e3a\u6b62\u3002\u6bcf\u4e00\u8f6e\u4f60\u53ef\u4ee5\u79fb\u9664\u5177\u6709\u76f8\u540c\u989c\u8272\u7684\u8fde\u7eed k \u4e2a\u76d2\u5b50\uff08k\u00a0>= 1\uff09\uff0c\u8fd9\u6837\u4e00\u8f6e\u4e4b\u540e\u4f60\u5c06\u5f97\u5230 k * k \u4e2a\u79ef\u5206\u3002

    \n\n

    \u5f53\u4f60\u5c06\u6240\u6709\u76d2\u5b50\u90fd\u53bb\u6389\u4e4b\u540e\uff0c\u6c42\u4f60\u80fd\u83b7\u5f97\u7684\u6700\u5927\u79ef\u5206\u548c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aboxes = [1,3,2,2,2,3,4,3,1]\n\u8f93\u51fa\uff1a23\n\u89e3\u91ca\uff1a\n[1, 3, 2, 2, 2, 3, 4, 3, 1] \n----> [1, 3, 3, 4, 3, 1] (3*3=9 \u5206) \n----> [1, 3, 3, 3, 1] (1*1=1 \u5206) \n----> [1, 1] (3*3=9 \u5206) \n----> [] (2*2=4 \u5206)\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aboxes = [1,1,1]\n\u8f93\u51fa\uff1a9\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aboxes = [1]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= boxes.length <= 100
    • \n\t
    • 1 <= boxes[i]\u00a0<= 100
    • \n
    \n", "tags_en": ["Depth-first Search", "Dynamic Programming"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int removeBoxes(vector& boxes) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int removeBoxes(int[] boxes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def removeBoxes(self, boxes):\n \"\"\"\n :type boxes: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def removeBoxes(self, boxes: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint removeBoxes(int* boxes, int boxesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int RemoveBoxes(int[] boxes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} boxes\n * @return {number}\n */\nvar removeBoxes = function(boxes) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} boxes\n# @return {Integer}\ndef remove_boxes(boxes)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func removeBoxes(_ boxes: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func removeBoxes(boxes []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def removeBoxes(boxes: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun removeBoxes(boxes: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn remove_boxes(boxes: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $boxes\n * @return Integer\n */\n function removeBoxes($boxes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function removeBoxes(boxes: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (remove-boxes boxes)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0546](https://leetcode-cn.com/problems/remove-boxes)", "[\u79fb\u9664\u76d2\u5b50](/solution/0500-0599/0546.Remove%20Boxes/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0546](https://leetcode.com/problems/remove-boxes)", "[Remove Boxes](/solution/0500-0599/0546.Remove%20Boxes/README_EN.md)", "`Depth-first Search`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0545", "frontend_question_id": "0545", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/boundary-of-binary-tree", "url_en": "https://leetcode.com/problems/boundary-of-binary-tree", "relative_path_cn": "/solution/0500-0599/0545.Boundary%20of%20Binary%20Tree/README.md", "relative_path_en": "/solution/0500-0599/0545.Boundary%20of%20Binary%20Tree/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u7684\u8fb9\u754c", "title_en": "Boundary of Binary Tree", "question_title_slug": "boundary-of-binary-tree", "content_en": "

    The boundary of a binary tree is the concatenation of the root, the left boundary, the leaves ordered from left-to-right, and the reverse order of the right boundary.

    \n\n

    The left boundary is the set of nodes defined by the following:

    \n\n
      \n\t
    • The root node's left child is in the left boundary. If the root does not have a left child, then the left boundary is empty.
    • \n\t
    • If a node in the left boundary and has a left child, then the left child is in the left boundary.
    • \n\t
    • If a node is in the left boundary, has no left child, but has a right child, then the right child is in the left boundary.
    • \n\t
    • The leftmost leaf is not in the left boundary.
    • \n
    \n\n

    The right boundary is similar to the left boundary, except it is the right side of the root's right subtree. Again, the leaf is not part of the right boundary, and the right boundary is empty if the root does not have a right child.

    \n\n

    The leaves are nodes that do not have any children. For this problem, the root is not a leaf.

    \n\n

    Given the root of a binary tree, return the values of its boundary.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,null,2,3,4]\nOutput: [1,3,4,2]\nExplanation:\n- The left boundary is empty because the root does not have a left child.\n- The right boundary follows the path starting from the root's right child 2 -> 4.\n  4 is a leaf, so the right boundary is [2].\n- The leaves from left to right are [3,4].\nConcatenating everything results in [1] + [] + [3,4] + [2] = [1,3,4,2].\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [1,2,3,4,5,6,null,null,null,7,8,9,10]\nOutput: [1,2,4,7,8,9,10,6,3]\nExplanation:\n- The left boundary follows the path starting from the root's left child 2 -> 4.\n  4 is a leaf, so the left boundary is [2].\n- The right boundary follows the path starting from the root's right child 3 -> 6 -> 10.\n  10 is a leaf, so the right boundary is [3,6], and in reverse order is [6,3].\n- The leaves from left to right are [4,7,8,9,10].\nConcatenating everything results in [1] + [2] + [4,7,8,9,10] + [6,3] = [1,2,4,7,8,9,10,6,3].\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 104].
    • \n\t
    • -1000 <= Node.val <= 1000
    • \n
    \n", "content_cn": "

    \u4e8c\u53c9\u6811\u7684 \u8fb9\u754c \u662f\u7531 \u6839\u8282\u70b9 \u3001\u5de6\u8fb9\u754c \u3001\u6309\u4ece\u5de6\u5230\u53f3\u987a\u5e8f\u7684 \u53f6\u8282\u70b9 \u548c \u9006\u5e8f\u7684\u53f3\u8fb9\u754c \uff0c\u6309\u987a\u5e8f\u4f9d\u6b21\u8fde\u63a5\u7ec4\u6210\u3002

    \n\n

    \u5de6\u8fb9\u754c \u662f\u6ee1\u8db3\u4e0b\u8ff0\u5b9a\u4e49\u7684\u8282\u70b9\u96c6\u5408\uff1a

    \n\n
      \n\t
    • \u6839\u8282\u70b9\u7684\u5de6\u5b50\u8282\u70b9\u5728\u5de6\u8fb9\u754c\u4e2d\u3002\u5982\u679c\u6839\u8282\u70b9\u4e0d\u542b\u5de6\u5b50\u8282\u70b9\uff0c\u90a3\u4e48\u5de6\u8fb9\u754c\u5c31\u4e3a \u7a7a \u3002
    • \n\t
    • \u5982\u679c\u4e00\u4e2a\u8282\u70b9\u5728\u5de6\u8fb9\u754c\u4e2d\uff0c\u5e76\u4e14\u8be5\u8282\u70b9\u6709\u5de6\u5b50\u8282\u70b9\uff0c\u90a3\u4e48\u5b83\u7684\u5de6\u5b50\u8282\u70b9\u4e5f\u5728\u5de6\u8fb9\u754c\u4e2d\u3002
    • \n\t
    • \u5982\u679c\u4e00\u4e2a\u8282\u70b9\u5728\u5de6\u8fb9\u754c\u4e2d\uff0c\u5e76\u4e14\u8be5\u8282\u70b9 \u4e0d\u542b \u5de6\u5b50\u8282\u70b9\uff0c\u90a3\u4e48\u5b83\u7684\u53f3\u5b50\u8282\u70b9\u5c31\u5728\u5de6\u8fb9\u754c\u4e2d\u3002
    • \n\t
    • \u6700\u5de6\u4fa7\u7684\u53f6\u8282\u70b9 \u4e0d\u5728 \u5de6\u8fb9\u754c\u4e2d\u3002
    • \n
    \n\n

    \u53f3\u8fb9\u754c \u5b9a\u4e49\u65b9\u5f0f\u4e0e \u5de6\u8fb9\u754c \u76f8\u540c\uff0c\u53ea\u662f\u5c06\u5de6\u66ff\u6362\u6210\u53f3\u3002\u5373\uff0c\u53f3\u8fb9\u754c\u662f\u6839\u8282\u70b9\u53f3\u5b50\u6811\u7684\u53f3\u4fa7\u90e8\u5206\uff1b\u53f6\u8282\u70b9 \u4e0d\u662f \u53f3\u8fb9\u754c\u7684\u7ec4\u6210\u90e8\u5206\uff1b\u5982\u679c\u6839\u8282\u70b9\u4e0d\u542b\u53f3\u5b50\u8282\u70b9\uff0c\u90a3\u4e48\u53f3\u8fb9\u754c\u4e3a \u7a7a \u3002

    \n\n

    \u53f6\u8282\u70b9 \u662f\u6ca1\u6709\u4efb\u4f55\u5b50\u8282\u70b9\u7684\u8282\u70b9\u3002\u5bf9\u4e8e\u6b64\u95ee\u9898\uff0c\u6839\u8282\u70b9 \u4e0d\u662f \u53f6\u8282\u70b9\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u68f5\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9 root \uff0c\u6309\u987a\u5e8f\u8fd4\u56de\u7ec4\u6210\u4e8c\u53c9\u6811 \u8fb9\u754c \u7684\u8fd9\u4e9b\u503c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [1,null,2,3,4]\n\u8f93\u51fa\uff1a[1,3,4,2]\n\u89e3\u91ca\uff1a\n- \u5de6\u8fb9\u754c\u4e3a\u7a7a\uff0c\u56e0\u4e3a\u4e8c\u53c9\u6811\u4e0d\u542b\u5de6\u5b50\u8282\u70b9\u3002\n- \u53f3\u8fb9\u754c\u662f [2] \u3002\u4ece\u6839\u8282\u70b9\u7684\u53f3\u5b50\u8282\u70b9\u5f00\u59cb\u7684\u8def\u5f84\u4e3a 2 -> 4 \uff0c\u4f46 4 \u662f\u53f6\u8282\u70b9\uff0c\u6240\u4ee5\u53f3\u8fb9\u754c\u53ea\u6709 2 \u3002\n- \u53f6\u8282\u70b9\u4ece\u5de6\u5230\u53f3\u662f [3,4] \u3002\n\u6309\u9898\u76ee\u8981\u6c42\u4f9d\u5e8f\u8fde\u63a5\u5f97\u5230\u7ed3\u679c [1] + [] + [3,4] + [2] = [1,3,4,2] \u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [1,2,3,4,5,6,null,null,null,7,8,9,10]\n\u8f93\u51fa\uff1a[1,2,4,7,8,9,10,6,3]\n\u89e3\u91ca\uff1a\n- \u5de6\u8fb9\u754c\u4e3a [2] \u3002\u4ece\u6839\u8282\u70b9\u7684\u5de6\u5b50\u8282\u70b9\u5f00\u59cb\u7684\u8def\u5f84\u4e3a 2 -> 4 \uff0c\u4f46 4 \u662f\u53f6\u8282\u70b9\uff0c\u6240\u4ee5\u5de6\u8fb9\u754c\u53ea\u6709 2 \u3002\n- \u53f3\u8fb9\u754c\u662f [3,6] \uff0c\u9006\u5e8f\u4e3a [6,3] \u3002\u4ece\u6839\u8282\u70b9\u7684\u53f3\u5b50\u8282\u70b9\u5f00\u59cb\u7684\u8def\u5f84\u4e3a 3 -> 6 -> 10 \uff0c\u4f46 10 \u662f\u53f6\u8282\u70b9\u3002\n- \u53f6\u8282\u70b9\u4ece\u5de6\u5230\u53f3\u662f [4,7,8,9,10]\n\u6309\u9898\u76ee\u8981\u6c42\u4f9d\u5e8f\u8fde\u63a5\u5f97\u5230\u7ed3\u679c [1] + [2] + [4,7,8,9,10] + [6,3] = [1,2,4,7,8,9,10,6,3] \u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u7684\u6570\u76ee\u5728\u8303\u56f4 [1, 104] \u5185
    • \n\t
    • -1000 <= Node.val <= 1000
    • \n
    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector boundaryOfBinaryTree(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public List boundaryOfBinaryTree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def boundaryOfBinaryTree(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def boundaryOfBinaryTree(self, root: TreeNode) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* boundaryOfBinaryTree(struct TreeNode* root, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public IList BoundaryOfBinaryTree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number[]}\n */\nvar boundaryOfBinaryTree = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer[]}\ndef boundary_of_binary_tree(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func boundaryOfBinaryTree(_ root: TreeNode?) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc boundaryOfBinaryTree(root *TreeNode) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def boundaryOfBinaryTree(root: TreeNode): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun boundaryOfBinaryTree(root: TreeNode?): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn boundary_of_binary_tree(root: Option>>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer[]\n */\n function boundaryOfBinaryTree($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction boundaryOfBinaryTree(root: TreeNode | null): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (boundary-of-binary-tree root)\n (-> (or/c tree-node? #f) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0545](https://leetcode-cn.com/problems/boundary-of-binary-tree)", "[\u4e8c\u53c9\u6811\u7684\u8fb9\u754c](/solution/0500-0599/0545.Boundary%20of%20Binary%20Tree/README.md)", "`\u6811`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0545](https://leetcode.com/problems/boundary-of-binary-tree)", "[Boundary of Binary Tree](/solution/0500-0599/0545.Boundary%20of%20Binary%20Tree/README_EN.md)", "`Tree`", "Medium", "\ud83d\udd12"]}, {"question_id": "0544", "frontend_question_id": "0544", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/output-contest-matches", "url_en": "https://leetcode.com/problems/output-contest-matches", "relative_path_cn": "/solution/0500-0599/0544.Output%20Contest%20Matches/README.md", "relative_path_en": "/solution/0500-0599/0544.Output%20Contest%20Matches/README_EN.md", "title_cn": "\u8f93\u51fa\u6bd4\u8d5b\u5339\u914d\u5bf9", "title_en": "Output Contest Matches", "question_title_slug": "output-contest-matches", "content_en": "

    During the NBA playoffs, we always set the rather strong team to play with the rather weak team, like make the rank 1 team play with the rank nth team, which is a good strategy to make the contest more interesting.

    \n\n

    Given n teams, return their final contest matches in the form of a string.

    \n\n

    The n teams are labeled from 1 to n, which represents their initial rank (i.e., Rank 1 is the strongest team and Rank n is the weakest team).

    \n\n

    We will use parentheses '(', and ')' and commas ',' to represent the contest team pairing. We use the parentheses for pairing and the commas for partition. During the pairing process in each round, you always need to follow the strategy of making the rather strong one pair with the rather weak one.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 4\nOutput: "((1,4),(2,3))"\nExplanation:\nIn the first round, we pair the team 1 and 4, the teams 2 and 3 together, as we need to make the strong team and weak team together.\nAnd we got (1, 4),(2, 3).\nIn the second round, the winners of (1, 4) and (2, 3) need to play again to generate the final winner, so you need to add the paratheses outside them.\nAnd we got the final answer ((1,4),(2,3)).\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 8\nOutput: "(((1,8),(4,5)),((2,7),(3,6)))"\nExplanation:\nFirst round: (1, 8),(2, 7),(3, 6),(4, 5)\nSecond round: ((1, 8),(4, 5)),((2, 7),(3, 6))\nThird round: (((1, 8),(4, 5)),((2, 7),(3, 6)))\nSince the third round will generate the final winner, you need to output the answer (((1,8),(4,5)),((2,7),(3,6))).\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == 2x where x in in the range [1, 12].
    • \n
    \n", "content_cn": "

    \u5728 NBA \u5b63\u540e\u8d5b\u4e2d\uff0c\u6211\u4eec\u603b\u662f\u5b89\u6392\u8f83\u5f3a\u7684\u961f\u4f0d\u5bf9\u6218\u8f83\u5f31\u7684\u961f\u4f0d\uff0c\u4f8b\u5982\u7528\u6392\u540d\u7b2c 1 \u7684\u961f\u4f0d\u548c\u7b2c n \u7684\u961f\u4f0d\u5bf9\u51b3\uff0c\u8fd9\u662f\u4e00\u4e2a\u53ef\u4ee5\u8ba9\u6bd4\u8d5b\u66f4\u52a0\u6709\u8da3\u7684\u597d\u7b56\u7565\u3002\u73b0\u5728\uff0c\u7ed9\u4f60 \u652f\u961f\u4f0d\uff0c\u4f60\u9700\u8981\u4ee5\u5b57\u7b26\u4e32\u683c\u5f0f\u8f93\u51fa\u5b83\u4eec\u7684 \u6700\u7ec8 \u6bd4\u8d5b\u914d\u5bf9\u3002

    \n\n

    n \u652f\u961f\u4f0d\u6309\u4ece 1 \u5230 n \u7684\u6b63\u6574\u6570\u683c\u5f0f\u7ed9\u51fa\uff0c\u5206\u522b\u4ee3\u8868\u5b83\u4eec\u7684\u521d\u59cb\u6392\u540d\uff08\u6392\u540d 1 \u6700\u5f3a\uff0c\u6392\u540d n \u6700\u5f31\uff09\u3002\u6211\u4eec\u7528\u62ec\u53f7\uff08'(', ')'\uff09\u548c\u9017\u53f7\uff08','\uff09\u6765\u8868\u793a\u5339\u914d\u5bf9——\u62ec\u53f7\uff08'(', ')'\uff09\u8868\u793a\u5339\u914d\uff0c\u9017\u53f7\uff08','\uff09\u6765\u7528\u4e8e\u5206\u5272\u3002 \u5728\u6bcf\u4e00\u8f6e\u7684\u5339\u914d\u8fc7\u7a0b\u4e2d\uff0c\u4f60\u90fd\u9700\u8981\u9075\u5faa\u5c06\u5f3a\u961f\u4e0e\u5f31\u961f\u914d\u5bf9\u7684\u539f\u5219\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165: 2\n\u8f93\u51fa: (1,2)\n\u89e3\u6790: \n\u521d\u59cb\u5730\uff0c\u6211\u4eec\u6709\u961f1\u548c\u961f2\u4e24\u652f\u961f\u4f0d\uff0c\u6309\u71671\uff0c2\u6392\u5217\u3002\n\u56e0\u6b64 \u7528 '(', ')' \u548c ','\u6765\u5c06\u961f1\u548c\u961f2\u8fdb\u884c\u914d\u5bf9\uff0c\u5f97\u5230\u6700\u7ec8\u7b54\u6848\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165: 4\n\u8f93\u51fa: ((1,4),(2,3))\n\u89e3\u6790: \n\u5728\u7b2c\u4e00\u8f6e\uff0c\u6211\u4eec\u5c06\u961f\u4f0d1\u548c4\u914d\u5bf9\uff0c2\u548c3\u914d\u5bf9\uff0c\u4ee5\u6ee1\u8db3\u5c06\u5f3a\u961f\u548c\u5f31\u961f\u642d\u914d\u7684\u6548\u679c\u3002\u5f97\u5230(1,4),(2,3).\n\u5728\u7b2c\u4e8c\u8f6e\uff0c(1,4) \u548c (2,3) \u7684\u8d62\u5bb6\u9700\u8981\u8fdb\u884c\u6bd4\u8d5b\u4ee5\u786e\u5b9a\u6700\u7ec8\u8d62\u5bb6\uff0c\u56e0\u6b64\u9700\u8981\u518d\u5728\u5916\u9762\u52a0\u4e00\u5c42\u62ec\u53f7\u3002\n\u4e8e\u662f\u6700\u7ec8\u7b54\u6848\u662f((1,4),(2,3))\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165: 8\n\u8f93\u51fa: (((1,8),(4,5)),((2,7),(3,6)))\n\u89e3\u6790: \n\u7b2c\u4e00\u8f6e: (1,8),(2,7),(3,6),(4,5)\n\u7b2c\u4e8c\u8f6e: ((1,8),(4,5)),((2,7),(3,6))\n\u7b2c\u4e09\u8f6e (((1,8),(4,5)),((2,7),(3,6)))\n\u7531\u4e8e\u7b2c\u4e09\u8f6e\u4f1a\u51b3\u51fa\u6700\u7ec8\u80dc\u8005\uff0c\u6545\u8f93\u51fa\u7b54\u6848\u4e3a(((1,8),(4,5)),((2,7),(3,6)))\u3002\n
    \n\n

     

    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u7684\u8303\u56f4\u662f [2, 212].
    2. \n\t
    3. \u4fdd\u8bc1 n \u53ef\u4ee5\u5199\u6210 2k \u7684\u5f62\u5f0f\uff0c\u5176\u4e2d k \u662f\u6b63\u6574\u6570\u3002
    4. \n
    \n\n

     

    \n", "tags_en": ["Recursion", "String"], "tags_cn": ["\u9012\u5f52", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string findContestMatch(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String findContestMatch(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findContestMatch(self, n):\n \"\"\"\n :type n: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findContestMatch(self, n: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * findContestMatch(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string FindContestMatch(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {string}\n */\nvar findContestMatch = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {String}\ndef find_contest_match(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findContestMatch(_ n: Int) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findContestMatch(n int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findContestMatch(n: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findContestMatch(n: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_contest_match(n: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return String\n */\n function findContestMatch($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findContestMatch(n: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-contest-match n)\n (-> exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0544](https://leetcode-cn.com/problems/output-contest-matches)", "[\u8f93\u51fa\u6bd4\u8d5b\u5339\u914d\u5bf9](/solution/0500-0599/0544.Output%20Contest%20Matches/README.md)", "`\u9012\u5f52`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0544](https://leetcode.com/problems/output-contest-matches)", "[Output Contest Matches](/solution/0500-0599/0544.Output%20Contest%20Matches/README_EN.md)", "`Recursion`,`String`", "Medium", "\ud83d\udd12"]}, {"question_id": "0543", "frontend_question_id": "0543", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/diameter-of-binary-tree", "url_en": "https://leetcode.com/problems/diameter-of-binary-tree", "relative_path_cn": "/solution/0500-0599/0543.Diameter%20of%20Binary%20Tree/README.md", "relative_path_en": "/solution/0500-0599/0543.Diameter%20of%20Binary%20Tree/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u7684\u76f4\u5f84", "title_en": "Diameter of Binary Tree", "question_title_slug": "diameter-of-binary-tree", "content_en": "

    Given the root of a binary tree, return the length of the diameter of the tree.

    \n\n

    The diameter of a binary tree is the length of the longest path between any two nodes in a tree. This path may or may not pass through the root.

    \n\n

    The length of a path between two nodes is represented by the number of edges between them.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,2,3,4,5]\nOutput: 3\nExplanation: 3is the length of the path [4,2,1,3] or [5,2,1,3].\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = [1,2]\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 104].
    • \n\t
    • -100 <= Node.val <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u68f5\u4e8c\u53c9\u6811\uff0c\u4f60\u9700\u8981\u8ba1\u7b97\u5b83\u7684\u76f4\u5f84\u957f\u5ea6\u3002\u4e00\u68f5\u4e8c\u53c9\u6811\u7684\u76f4\u5f84\u957f\u5ea6\u662f\u4efb\u610f\u4e24\u4e2a\u7ed3\u70b9\u8def\u5f84\u957f\u5ea6\u4e2d\u7684\u6700\u5927\u503c\u3002\u8fd9\u6761\u8def\u5f84\u53ef\u80fd\u7a7f\u8fc7\u4e5f\u53ef\u80fd\u4e0d\u7a7f\u8fc7\u6839\u7ed3\u70b9\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b :
    \n\u7ed9\u5b9a\u4e8c\u53c9\u6811

    \n\n
              1\n         / \\\n        2   3\n       / \\     \n      4   5    \n
    \n\n

    \u8fd4\u56de 3, \u5b83\u7684\u957f\u5ea6\u662f\u8def\u5f84 [4,2,1,3] \u6216\u8005 [5,2,1,3]\u3002

    \n\n

     

    \n\n

    \u6ce8\u610f\uff1a\u4e24\u7ed3\u70b9\u4e4b\u95f4\u7684\u8def\u5f84\u957f\u5ea6\u662f\u4ee5\u5b83\u4eec\u4e4b\u95f4\u8fb9\u7684\u6570\u76ee\u8868\u793a\u3002

    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int diameterOfBinaryTree(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int diameterOfBinaryTree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def diameterOfBinaryTree(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def diameterOfBinaryTree(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint diameterOfBinaryTree(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int DiameterOfBinaryTree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar diameterOfBinaryTree = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef diameter_of_binary_tree(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func diameterOfBinaryTree(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc diameterOfBinaryTree(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def diameterOfBinaryTree(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun diameterOfBinaryTree(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn diameter_of_binary_tree(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function diameterOfBinaryTree($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction diameterOfBinaryTree(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (diameter-of-binary-tree root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0543](https://leetcode-cn.com/problems/diameter-of-binary-tree)", "[\u4e8c\u53c9\u6811\u7684\u76f4\u5f84](/solution/0500-0599/0543.Diameter%20of%20Binary%20Tree/README.md)", "`\u6811`", "\u7b80\u5355", ""], "md_table_row_en": ["[0543](https://leetcode.com/problems/diameter-of-binary-tree)", "[Diameter of Binary Tree](/solution/0500-0599/0543.Diameter%20of%20Binary%20Tree/README_EN.md)", "`Tree`", "Easy", ""]}, {"question_id": "0542", "frontend_question_id": "0542", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/01-matrix", "url_en": "https://leetcode.com/problems/01-matrix", "relative_path_cn": "/solution/0500-0599/0542.01%20Matrix/README.md", "relative_path_en": "/solution/0500-0599/0542.01%20Matrix/README_EN.md", "title_cn": "01 \u77e9\u9635", "title_en": "01 Matrix", "question_title_slug": "01-matrix", "content_en": "

    Given an m x n binary matrix mat, return the distance of the nearest 0 for each cell.

    \n\n

    The distance between two adjacent cells is 1.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: mat = [[0,0,0],[0,1,0],[0,0,0]]\nOutput: [[0,0,0],[0,1,0],[0,0,0]]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: mat = [[0,0,0],[0,1,0],[1,1,1]]\nOutput: [[0,0,0],[0,1,0],[1,2,1]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == mat.length
    • \n\t
    • n == mat[i].length
    • \n\t
    • 1 <= m, n <= 104
    • \n\t
    • 1 <= m * n <= 104
    • \n\t
    • mat[i][j] is either 0 or 1.
    • \n\t
    • There is at least one 0 in mat.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u7531 0 \u548c 1 \u7ec4\u6210\u7684\u77e9\u9635\uff0c\u627e\u51fa\u6bcf\u4e2a\u5143\u7d20\u5230\u6700\u8fd1\u7684 0 \u7684\u8ddd\u79bb\u3002

    \n\n

    \u4e24\u4e2a\u76f8\u90bb\u5143\u7d20\u95f4\u7684\u8ddd\u79bb\u4e3a 1 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\n[[0,0,0],\n [0,1,0],\n [0,0,0]]\n\n\u8f93\u51fa\uff1a\n[[0,0,0],\n\u00a0[0,1,0],\n\u00a0[0,0,0]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\n[[0,0,0],\n [0,1,0],\n [1,1,1]]\n\n\u8f93\u51fa\uff1a\n[[0,0,0],\n [0,1,0],\n [1,2,1]]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u7ed9\u5b9a\u77e9\u9635\u7684\u5143\u7d20\u4e2a\u6570\u4e0d\u8d85\u8fc7 10000\u3002
    • \n\t
    • \u7ed9\u5b9a\u77e9\u9635\u4e2d\u81f3\u5c11\u6709\u4e00\u4e2a\u5143\u7d20\u662f 0\u3002
    • \n\t
    • \u77e9\u9635\u4e2d\u7684\u5143\u7d20\u53ea\u5728\u56db\u4e2a\u65b9\u5411\u4e0a\u76f8\u90bb: \u4e0a\u3001\u4e0b\u3001\u5de6\u3001\u53f3\u3002
    • \n
    \n", "tags_en": ["Depth-first Search", "Breadth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> updateMatrix(vector>& mat) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[][] updateMatrix(int[][] mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def updateMatrix(self, mat):\n \"\"\"\n :type mat: List[List[int]]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def updateMatrix(self, mat: List[List[int]]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** updateMatrix(int** mat, int matSize, int* matColSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[][] UpdateMatrix(int[][] mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} mat\n * @return {number[][]}\n */\nvar updateMatrix = function(mat) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} mat\n# @return {Integer[][]}\ndef update_matrix(mat)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func updateMatrix(_ mat: [[Int]]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func updateMatrix(mat [][]int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def updateMatrix(mat: Array[Array[Int]]): Array[Array[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun updateMatrix(mat: Array): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn update_matrix(mat: Vec>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $mat\n * @return Integer[][]\n */\n function updateMatrix($mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function updateMatrix(mat: number[][]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (update-matrix mat)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0542](https://leetcode-cn.com/problems/01-matrix)", "[01 \u77e9\u9635](/solution/0500-0599/0542.01%20Matrix/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0542](https://leetcode.com/problems/01-matrix)", "[01 Matrix](/solution/0500-0599/0542.01%20Matrix/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`", "Medium", ""]}, {"question_id": "0541", "frontend_question_id": "0541", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reverse-string-ii", "url_en": "https://leetcode.com/problems/reverse-string-ii", "relative_path_cn": "/solution/0500-0599/0541.Reverse%20String%20II/README.md", "relative_path_en": "/solution/0500-0599/0541.Reverse%20String%20II/README_EN.md", "title_cn": "\u53cd\u8f6c\u5b57\u7b26\u4e32 II", "title_en": "Reverse String II", "question_title_slug": "reverse-string-ii", "content_en": "

    Given a string s and an integer k, reverse the first k characters for every 2k characters counting from the start of the string.

    \n\n

    If there are fewer than k characters left, reverse all of them. If there are less than 2k but greater than or equal to k characters, then reverse the first k characters and left the other as original.

    \n\n

     

    \n

    Example 1:

    \n
    Input: s = \"abcdefg\", k = 2\nOutput: \"bacdfeg\"\n

    Example 2:

    \n
    Input: s = \"abcd\", k = 2\nOutput: \"bacd\"\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 104
    • \n\t
    • s consists of only lowercase English letters.
    • \n\t
    • 1 <= k <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32 s \u548c\u4e00\u4e2a\u6574\u6570 k\uff0c\u4f60\u9700\u8981\u5bf9\u4ece\u5b57\u7b26\u4e32\u5f00\u5934\u7b97\u8d77\u7684\u6bcf\u9694 2k \u4e2a\u5b57\u7b26\u7684\u524d k \u4e2a\u5b57\u7b26\u8fdb\u884c\u53cd\u8f6c\u3002

    \n\n
      \n\t
    • \u5982\u679c\u5269\u4f59\u5b57\u7b26\u5c11\u4e8e k \u4e2a\uff0c\u5219\u5c06\u5269\u4f59\u5b57\u7b26\u5168\u90e8\u53cd\u8f6c\u3002
    • \n\t
    • \u5982\u679c\u5269\u4f59\u5b57\u7b26\u5c0f\u4e8e 2k \u4f46\u5927\u4e8e\u6216\u7b49\u4e8e k \u4e2a\uff0c\u5219\u53cd\u8f6c\u524d k \u4e2a\u5b57\u7b26\uff0c\u5176\u4f59\u5b57\u7b26\u4fdd\u6301\u539f\u6837\u3002
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: s = "abcdefg", k = 2\n\u8f93\u51fa: "bacdfeg"\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. \u8be5\u5b57\u7b26\u4e32\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    2. \n\t
    3. \u7ed9\u5b9a\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u548c k \u5728 [1, 10000] \u8303\u56f4\u5185\u3002
    4. \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string reverseStr(string s, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String reverseStr(String s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def reverseStr(self, s, k):\n \"\"\"\n :type s: str\n :type k: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def reverseStr(self, s: str, k: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * reverseStr(char * s, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ReverseStr(string s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number} k\n * @return {string}\n */\nvar reverseStr = function(s, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer} k\n# @return {String}\ndef reverse_str(s, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func reverseStr(_ s: String, _ k: Int) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func reverseStr(s string, k int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def reverseStr(s: String, k: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun reverseStr(s: String, k: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn reverse_str(s: String, k: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer $k\n * @return String\n */\n function reverseStr($s, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function reverseStr(s: string, k: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (reverse-str s k)\n (-> string? exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0541](https://leetcode-cn.com/problems/reverse-string-ii)", "[\u53cd\u8f6c\u5b57\u7b26\u4e32 II](/solution/0500-0599/0541.Reverse%20String%20II/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0541](https://leetcode.com/problems/reverse-string-ii)", "[Reverse String II](/solution/0500-0599/0541.Reverse%20String%20II/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "0540", "frontend_question_id": "0540", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/single-element-in-a-sorted-array", "url_en": "https://leetcode.com/problems/single-element-in-a-sorted-array", "relative_path_cn": "/solution/0500-0599/0540.Single%20Element%20in%20a%20Sorted%20Array/README.md", "relative_path_en": "/solution/0500-0599/0540.Single%20Element%20in%20a%20Sorted%20Array/README_EN.md", "title_cn": "\u6709\u5e8f\u6570\u7ec4\u4e2d\u7684\u5355\u4e00\u5143\u7d20", "title_en": "Single Element in a Sorted Array", "question_title_slug": "single-element-in-a-sorted-array", "content_en": "

    You are given a sorted array consisting of only integers where every element appears exactly twice, except for one element which appears exactly once. Find this single element that appears only once.

    \r\n\r\n

    Follow up: Your solution should run in O(log n) time and O(1) space.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n
    Input: nums = [1,1,2,3,3,4,4,8,8]\r\nOutput: 2\r\n

    Example 2:

    \r\n
    Input: nums = [3,3,7,7,10,11,11]\r\nOutput: 10\r\n
    \r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= nums.length <= 10^5
    • \r\n\t
    • 0 <= nums[i] <= 10^5
    • \r\n
    ", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u53ea\u5305\u542b\u6574\u6570\u7684\u6709\u5e8f\u6570\u7ec4\uff0c\u6bcf\u4e2a\u5143\u7d20\u90fd\u4f1a\u51fa\u73b0\u4e24\u6b21\uff0c\u552f\u6709\u4e00\u4e2a\u6570\u53ea\u4f1a\u51fa\u73b0\u4e00\u6b21\uff0c\u627e\u51fa\u8fd9\u4e2a\u6570\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: [1,1,2,3,3,4,4,8,8]\n\u8f93\u51fa: 2\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: [3,3,7,7,10,11,11]\n\u8f93\u51fa: 10\n
    \n\n

    \u6ce8\u610f: \u60a8\u7684\u65b9\u6848\u5e94\u8be5\u5728 O(log n)\u65f6\u95f4\u590d\u6742\u5ea6\u548c O(1)\u7a7a\u95f4\u590d\u6742\u5ea6\u4e2d\u8fd0\u884c\u3002

    \n", "tags_en": ["Binary Search"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int singleNonDuplicate(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int singleNonDuplicate(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def singleNonDuplicate(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def singleNonDuplicate(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint singleNonDuplicate(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SingleNonDuplicate(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar singleNonDuplicate = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef single_non_duplicate(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func singleNonDuplicate(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func singleNonDuplicate(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def singleNonDuplicate(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun singleNonDuplicate(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn single_non_duplicate(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function singleNonDuplicate($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function singleNonDuplicate(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (single-non-duplicate nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0540](https://leetcode-cn.com/problems/single-element-in-a-sorted-array)", "[\u6709\u5e8f\u6570\u7ec4\u4e2d\u7684\u5355\u4e00\u5143\u7d20](/solution/0500-0599/0540.Single%20Element%20in%20a%20Sorted%20Array/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0540](https://leetcode.com/problems/single-element-in-a-sorted-array)", "[Single Element in a Sorted Array](/solution/0500-0599/0540.Single%20Element%20in%20a%20Sorted%20Array/README_EN.md)", "`Binary Search`", "Medium", ""]}, {"question_id": "0539", "frontend_question_id": "0539", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-time-difference", "url_en": "https://leetcode.com/problems/minimum-time-difference", "relative_path_cn": "/solution/0500-0599/0539.Minimum%20Time%20Difference/README.md", "relative_path_en": "/solution/0500-0599/0539.Minimum%20Time%20Difference/README_EN.md", "title_cn": "\u6700\u5c0f\u65f6\u95f4\u5dee", "title_en": "Minimum Time Difference", "question_title_slug": "minimum-time-difference", "content_en": "Given a list of 24-hour clock time points in "HH:MM" format, return the minimum minutes difference between any two time-points in the list.\n

     

    \n

    Example 1:

    \n
    Input: timePoints = [\"23:59\",\"00:00\"]\nOutput: 1\n

    Example 2:

    \n
    Input: timePoints = [\"00:00\",\"23:59\",\"00:00\"]\nOutput: 0\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= timePoints <= 2 * 104
    • \n\t
    • timePoints[i] is in the format "HH:MM".
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a 24 \u5c0f\u65f6\u5236\uff08\u5c0f\u65f6:\u5206\u949f \"HH:MM\"\uff09\u7684\u65f6\u95f4\u5217\u8868\uff0c\u627e\u51fa\u5217\u8868\u4e2d\u4efb\u610f\u4e24\u4e2a\u65f6\u95f4\u7684\u6700\u5c0f\u65f6\u95f4\u5dee\u5e76\u4ee5\u5206\u949f\u6570\u8868\u793a\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1atimePoints = [\"23:59\",\"00:00\"]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1atimePoints = [\"00:00\",\"23:59\",\"00:00\"]\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= timePoints <= 2 * 104
    • \n\t
    • timePoints[i] \u683c\u5f0f\u4e3a \"HH:MM\"
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findMinDifference(vector& timePoints) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findMinDifference(List timePoints) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findMinDifference(self, timePoints):\n \"\"\"\n :type timePoints: List[str]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findMinDifference(self, timePoints: List[str]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findMinDifference(char ** timePoints, int timePointsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindMinDifference(IList timePoints) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} timePoints\n * @return {number}\n */\nvar findMinDifference = function(timePoints) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} time_points\n# @return {Integer}\ndef find_min_difference(time_points)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findMinDifference(_ timePoints: [String]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findMinDifference(timePoints []string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findMinDifference(timePoints: List[String]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findMinDifference(timePoints: List): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_min_difference(time_points: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $timePoints\n * @return Integer\n */\n function findMinDifference($timePoints) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findMinDifference(timePoints: string[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-min-difference timePoints)\n (-> (listof string?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0539](https://leetcode-cn.com/problems/minimum-time-difference)", "[\u6700\u5c0f\u65f6\u95f4\u5dee](/solution/0500-0599/0539.Minimum%20Time%20Difference/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0539](https://leetcode.com/problems/minimum-time-difference)", "[Minimum Time Difference](/solution/0500-0599/0539.Minimum%20Time%20Difference/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "0538", "frontend_question_id": "0538", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/convert-bst-to-greater-tree", "url_en": "https://leetcode.com/problems/convert-bst-to-greater-tree", "relative_path_cn": "/solution/0500-0599/0538.Convert%20BST%20to%20Greater%20Tree/README.md", "relative_path_en": "/solution/0500-0599/0538.Convert%20BST%20to%20Greater%20Tree/README_EN.md", "title_cn": "\u628a\u4e8c\u53c9\u641c\u7d22\u6811\u8f6c\u6362\u4e3a\u7d2f\u52a0\u6811", "title_en": "Convert BST to Greater Tree", "question_title_slug": "convert-bst-to-greater-tree", "content_en": "

    Given the root of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus sum of all keys greater than the original key in BST.

    \r\n\r\n

    As a reminder, a binary search tree is a tree that satisfies these constraints:

    \r\n\r\n
      \r\n\t
    • The left subtree of a node contains only nodes with keys less than the node's key.
    • \r\n\t
    • The right subtree of a node contains only nodes with keys greater than the node's key.
    • \r\n\t
    • Both the left and right subtrees must also be binary search trees.
    • \r\n
    \r\n\r\n

    Note: This question is the same as 1038: https://leetcode.com/problems/binary-search-tree-to-greater-sum-tree/

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\"\"\r\n
    \r\nInput: root = [4,1,6,0,2,5,7,null,null,null,3,null,null,null,8]\r\nOutput: [30,36,21,36,35,26,15,null,null,null,33,null,null,null,8]\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: root = [0,null,1]\r\nOutput: [1,null,1]\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: root = [1,0,2]\r\nOutput: [3,3,2]\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: root = [3,2,4,1]\r\nOutput: [7,9,4,10]\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • The number of nodes in the tree is in the range [0, 104].
    • \r\n\t
    • -104 <= Node.val <= 104
    • \r\n\t
    • All the values in the tree are unique.
    • \r\n\t
    • root is guaranteed to be a valid binary search tree.
    • \r\n
    ", "content_cn": "

    \u7ed9\u51fa\u4e8c\u53c9 \u641c\u7d22 \u6811\u7684\u6839\u8282\u70b9\uff0c\u8be5\u6811\u7684\u8282\u70b9\u503c\u5404\u4e0d\u76f8\u540c\uff0c\u8bf7\u4f60\u5c06\u5176\u8f6c\u6362\u4e3a\u7d2f\u52a0\u6811\uff08Greater Sum Tree\uff09\uff0c\u4f7f\u6bcf\u4e2a\u8282\u70b9 node \u7684\u65b0\u503c\u7b49\u4e8e\u539f\u6811\u4e2d\u5927\u4e8e\u6216\u7b49\u4e8e node.val \u7684\u503c\u4e4b\u548c\u3002

    \n\n

    \u63d0\u9192\u4e00\u4e0b\uff0c\u4e8c\u53c9\u641c\u7d22\u6811\u6ee1\u8db3\u4e0b\u5217\u7ea6\u675f\u6761\u4ef6\uff1a

    \n\n
      \n\t
    • \u8282\u70b9\u7684\u5de6\u5b50\u6811\u4ec5\u5305\u542b\u952e \u5c0f\u4e8e \u8282\u70b9\u952e\u7684\u8282\u70b9\u3002
    • \n\t
    • \u8282\u70b9\u7684\u53f3\u5b50\u6811\u4ec5\u5305\u542b\u952e \u5927\u4e8e \u8282\u70b9\u952e\u7684\u8282\u70b9\u3002
    • \n\t
    • \u5de6\u53f3\u5b50\u6811\u4e5f\u5fc5\u987b\u662f\u4e8c\u53c9\u641c\u7d22\u6811\u3002
    • \n
    \n\n

    \u6ce8\u610f\uff1a\u672c\u9898\u548c 1038: https://leetcode-cn.com/problems/binary-search-tree-to-greater-sum-tree/ \u76f8\u540c

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1a[4,1,6,0,2,5,7,null,null,null,3,null,null,null,8]\n\u8f93\u51fa\uff1a[30,36,21,36,35,26,15,null,null,null,33,null,null,null,8]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aroot = [0,null,1]\n\u8f93\u51fa\uff1a[1,null,1]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aroot = [1,0,2]\n\u8f93\u51fa\uff1a[3,3,2]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1aroot = [3,2,4,1]\n\u8f93\u51fa\uff1a[7,9,4,10]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u7684\u8282\u70b9\u6570\u4ecb\u4e8e 0 \u548c 104 \u4e4b\u95f4\u3002
    • \n\t
    • \u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u4ecb\u4e8e -104 \u548c 104 \u4e4b\u95f4\u3002
    • \n\t
    • \u6811\u4e2d\u7684\u6240\u6709\u503c \u4e92\u4e0d\u76f8\u540c \u3002
    • \n\t
    • \u7ed9\u5b9a\u7684\u6811\u4e3a\u4e8c\u53c9\u641c\u7d22\u6811\u3002
    • \n
    \n", "tags_en": ["Tree", "Depth-first Search", "Binary Search Tree", "Recursion"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u4e8c\u53c9\u641c\u7d22\u6811", "\u9012\u5f52"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* convertBST(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode convertBST(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def convertBST(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: TreeNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def convertBST(self, root: TreeNode) -> TreeNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* convertBST(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode ConvertBST(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {TreeNode}\n */\nvar convertBST = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {TreeNode}\ndef convert_bst(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func convertBST(_ root: TreeNode?) -> TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc convertBST(root *TreeNode) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def convertBST(root: TreeNode): TreeNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun convertBST(root: TreeNode?): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn convert_bst(root: Option>>) -> Option>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return TreeNode\n */\n function convertBST($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction convertBST(root: TreeNode | null): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (convert-bst root)\n (-> (or/c tree-node? #f) (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0538](https://leetcode-cn.com/problems/convert-bst-to-greater-tree)", "[\u628a\u4e8c\u53c9\u641c\u7d22\u6811\u8f6c\u6362\u4e3a\u7d2f\u52a0\u6811](/solution/0500-0599/0538.Convert%20BST%20to%20Greater%20Tree/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u4e8c\u53c9\u641c\u7d22\u6811`,`\u9012\u5f52`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0538](https://leetcode.com/problems/convert-bst-to-greater-tree)", "[Convert BST to Greater Tree](/solution/0500-0599/0538.Convert%20BST%20to%20Greater%20Tree/README_EN.md)", "`Tree`,`Depth-first Search`,`Binary Search Tree`,`Recursion`", "Medium", ""]}, {"question_id": "0537", "frontend_question_id": "0537", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/complex-number-multiplication", "url_en": "https://leetcode.com/problems/complex-number-multiplication", "relative_path_cn": "/solution/0500-0599/0537.Complex%20Number%20Multiplication/README.md", "relative_path_en": "/solution/0500-0599/0537.Complex%20Number%20Multiplication/README_EN.md", "title_cn": "\u590d\u6570\u4e58\u6cd5", "title_en": "Complex Number Multiplication", "question_title_slug": "complex-number-multiplication", "content_en": "

    A complex number can be represented as a string on the form "real+imaginaryi" where:

    \n\n
      \n\t
    • real is the real part and is an integer in the range [-100, 100].
    • \n\t
    • imaginary is the imaginary part and is an integer in the range [-100, 100].
    • \n\t
    • i2 == -1.
    • \n
    \n\n

    Given two complex numbers num1 and num2 as strings, return a string of the complex number that represents their multiplications.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: num1 = "1+1i", num2 = "1+1i"\nOutput: "0+2i"\nExplanation: (1 + i) * (1 + i) = 1 + i2 + 2 * i = 2i, and you need convert it to the form of 0+2i.\n
    \n\n

    Example 2:

    \n\n
    \nInput: num1 = "1+-1i", num2 = "1+-1i"\nOutput: "0+-2i"\nExplanation: (1 - i) * (1 - i) = 1 + i2 - 2 * i = -2i, and you need convert it to the form of 0+-2i.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • num1 and num2 are valid complex numbers.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u8868\u793a\u590d\u6570\u7684\u5b57\u7b26\u4e32\u3002

    \n\n

    \u8fd4\u56de\u8868\u793a\u5b83\u4eec\u4e58\u79ef\u7684\u5b57\u7b26\u4e32\u3002\u6ce8\u610f\uff0c\u6839\u636e\u5b9a\u4e49 i2 = -1 \u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: "1+1i", "1+1i"\n\u8f93\u51fa: "0+2i"\n\u89e3\u91ca: (1 + i) * (1 + i) = 1 + i2 + 2 * i = 2i \uff0c\u4f60\u9700\u8981\u5c06\u5b83\u8f6c\u6362\u4e3a 0+2i \u7684\u5f62\u5f0f\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: "1+-1i", "1+-1i"\n\u8f93\u51fa: "0+-2i"\n\u89e3\u91ca: (1 - i) * (1 - i) = 1 + i2 - 2 * i = -2i \uff0c\u4f60\u9700\u8981\u5c06\u5b83\u8f6c\u6362\u4e3a 0+-2i \u7684\u5f62\u5f0f\u3002 \n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u8f93\u5165\u5b57\u7b26\u4e32\u4e0d\u5305\u542b\u989d\u5916\u7684\u7a7a\u683c\u3002
    2. \n\t
    3. \u8f93\u5165\u5b57\u7b26\u4e32\u5c06\u4ee5 a+bi \u7684\u5f62\u5f0f\u7ed9\u51fa\uff0c\u5176\u4e2d\u6574\u6570 a \u548c b \u7684\u8303\u56f4\u5747\u5728 [-100, 100] \u4e4b\u95f4\u3002\u8f93\u51fa\u4e5f\u5e94\u5f53\u7b26\u5408\u8fd9\u79cd\u5f62\u5f0f\u3002
    4. \n
    \n", "tags_en": ["Math", "String"], "tags_cn": ["\u6570\u5b66", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string complexNumberMultiply(string num1, string num2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String complexNumberMultiply(String num1, String num2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def complexNumberMultiply(self, num1, num2):\n \"\"\"\n :type num1: str\n :type num2: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def complexNumberMultiply(self, num1: str, num2: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * complexNumberMultiply(char * num1, char * num2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ComplexNumberMultiply(string num1, string num2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} num1\n * @param {string} num2\n * @return {string}\n */\nvar complexNumberMultiply = function(num1, num2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} num1\n# @param {String} num2\n# @return {String}\ndef complex_number_multiply(num1, num2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func complexNumberMultiply(_ num1: String, _ num2: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func complexNumberMultiply(num1 string, num2 string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def complexNumberMultiply(num1: String, num2: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun complexNumberMultiply(num1: String, num2: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn complex_number_multiply(num1: String, num2: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $num1\n * @param String $num2\n * @return String\n */\n function complexNumberMultiply($num1, $num2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function complexNumberMultiply(num1: string, num2: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (complex-number-multiply num1 num2)\n (-> string? string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0537](https://leetcode-cn.com/problems/complex-number-multiplication)", "[\u590d\u6570\u4e58\u6cd5](/solution/0500-0599/0537.Complex%20Number%20Multiplication/README.md)", "`\u6570\u5b66`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0537](https://leetcode.com/problems/complex-number-multiplication)", "[Complex Number Multiplication](/solution/0500-0599/0537.Complex%20Number%20Multiplication/README_EN.md)", "`Math`,`String`", "Medium", ""]}, {"question_id": "0536", "frontend_question_id": "0536", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/construct-binary-tree-from-string", "url_en": "https://leetcode.com/problems/construct-binary-tree-from-string", "relative_path_cn": "/solution/0500-0599/0536.Construct%20Binary%20Tree%20from%20String/README.md", "relative_path_en": "/solution/0500-0599/0536.Construct%20Binary%20Tree%20from%20String/README_EN.md", "title_cn": "\u4ece\u5b57\u7b26\u4e32\u751f\u6210\u4e8c\u53c9\u6811", "title_en": "Construct Binary Tree from String", "question_title_slug": "construct-binary-tree-from-string", "content_en": "

    You need to construct a binary tree from a string consisting of parenthesis and integers.

    \n\n

    The whole input represents a binary tree. It contains an integer followed by zero, one or two pairs of parenthesis. The integer represents the root's value and a pair of parenthesis contains a child binary tree with the same structure.

    \n\n

    You always start to construct the left child node of the parent first if it exists.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: s = "4(2(3)(1))(6(5))"\nOutput: [4,2,6,3,1,5]\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "4(2(3)(1))(6(5)(7))"\nOutput: [4,2,6,3,1,5,7]\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "-4(2(3)(1))(6(5)(7))"\nOutput: [-4,2,6,3,1,5,7]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= s.length <= 3 * 104
    • \n\t
    • s consists of digits, '(', ')', and '-' only.
    • \n
    \n", "content_cn": "

    \u4f60\u9700\u8981\u4ece\u4e00\u4e2a\u5305\u62ec\u62ec\u53f7\u548c\u6574\u6570\u7684\u5b57\u7b26\u4e32\u6784\u5efa\u4e00\u68f5\u4e8c\u53c9\u6811\u3002

    \n\n

    \u8f93\u5165\u7684\u5b57\u7b26\u4e32\u4ee3\u8868\u4e00\u68f5\u4e8c\u53c9\u6811\u3002\u5b83\u5305\u62ec\u6574\u6570\u548c\u968f\u540e\u7684 0 \uff0c1 \u6216 2 \u5bf9\u62ec\u53f7\u3002\u6574\u6570\u4ee3\u8868\u6839\u7684\u503c\uff0c\u4e00\u5bf9\u62ec\u53f7\u5185\u8868\u793a\u540c\u6837\u7ed3\u6784\u7684\u5b50\u6811\u3002

    \n\n

    \u82e5\u5b58\u5728\u5de6\u5b50\u7ed3\u70b9\uff0c\u5219\u4ece\u5de6\u5b50\u7ed3\u70b9\u5f00\u59cb\u6784\u5efa\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1a"4(2(3)(1))(6(5))"\n\u8f93\u51fa\uff1a\u8fd4\u56de\u4ee3\u8868\u4e0b\u5217\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9:\n\n       4\n     /   \\\n    2     6\n   / \\   / \n  3   1 5   \n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u8f93\u5165\u5b57\u7b26\u4e32\u4e2d\u53ea\u5305\u542b '(', ')', '-' \u548c '0' ~ '9' 
    • \n\t
    • \u7a7a\u6811\u7531 "" \u800c\u975e"()"\u8868\u793a\u3002
    • \n
    \n\n

     

    \n", "tags_en": ["Tree", "String"], "tags_cn": ["\u6811", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* str2tree(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode str2tree(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def str2tree(self, s):\n \"\"\"\n :type s: str\n :rtype: TreeNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def str2tree(self, s: str) -> TreeNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* str2tree(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode Str2tree(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {string} s\n * @return {TreeNode}\n */\nvar str2tree = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {String} s\n# @return {TreeNode}\ndef str2tree(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func str2tree(_ s: String) -> TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc str2tree(s string) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def str2tree(s: String): TreeNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun str2tree(s: String): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn str2tree(s: String) -> Option>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param String $s\n * @return TreeNode\n */\n function str2tree($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction str2tree(s: string): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (str2tree s)\n (-> string? (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0536](https://leetcode-cn.com/problems/construct-binary-tree-from-string)", "[\u4ece\u5b57\u7b26\u4e32\u751f\u6210\u4e8c\u53c9\u6811](/solution/0500-0599/0536.Construct%20Binary%20Tree%20from%20String/README.md)", "`\u6811`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0536](https://leetcode.com/problems/construct-binary-tree-from-string)", "[Construct Binary Tree from String](/solution/0500-0599/0536.Construct%20Binary%20Tree%20from%20String/README_EN.md)", "`Tree`,`String`", "Medium", "\ud83d\udd12"]}, {"question_id": "0535", "frontend_question_id": "0535", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/encode-and-decode-tinyurl", "url_en": "https://leetcode.com/problems/encode-and-decode-tinyurl", "relative_path_cn": "/solution/0500-0599/0535.Encode%20and%20Decode%20TinyURL/README.md", "relative_path_en": "/solution/0500-0599/0535.Encode%20and%20Decode%20TinyURL/README_EN.md", "title_cn": "TinyURL \u7684\u52a0\u5bc6\u4e0e\u89e3\u5bc6", "title_en": "Encode and Decode TinyURL", "question_title_slug": "encode-and-decode-tinyurl", "content_en": "
    Note: This is a companion problem to the System Design problem: Design TinyURL.
    \n\n

    TinyURL is a URL shortening service where you enter a URL such as https://leetcode.com/problems/design-tinyurl and it returns a short URL such as http://tinyurl.com/4e9iAk. Design a class to encode a URL and decode a tiny URL.

    \n\n

    There is no restriction on how your encode/decode algorithm should work. You just need to ensure that a URL can be encoded to a tiny URL and the tiny URL can be decoded to the original URL.

    \n\n

    Implement the Solution class:

    \n\n
      \n\t
    • Solution() Initializes the object of the system.
    • \n\t
    • String encode(String longUrl) Returns a tiny URL for the given longUrl.
    • \n\t
    • String decode(String shortUrl) Returns the original long URL for the given shortUrl. It is guaranteed that the given shortUrl was encoded by the same object.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: url = "https://leetcode.com/problems/design-tinyurl"\nOutput: "https://leetcode.com/problems/design-tinyurl"\n\nExplanation:\nSolution obj = new Solution();\nstring tiny = obj.encode(url); // returns the encoded tiny url.\nstring ans = obj.decode(tiny); // returns the original url after deconding it.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= url.length <= 104
    • \n\t
    • url is guranteed to be a valid URL.
    • \n
    \n", "content_cn": "

    TinyURL\u662f\u4e00\u79cdURL\u7b80\u5316\u670d\u52a1\uff0c \u6bd4\u5982\uff1a\u5f53\u4f60\u8f93\u5165\u4e00\u4e2aURL https://leetcode.com/problems/design-tinyurl \u65f6\uff0c\u5b83\u5c06\u8fd4\u56de\u4e00\u4e2a\u7b80\u5316\u7684URL http://tinyurl.com/4e9iAk.

    \n\n

    \u8981\u6c42\uff1a\u8bbe\u8ba1\u4e00\u4e2a TinyURL \u7684\u52a0\u5bc6 encode \u548c\u89e3\u5bc6 decode \u7684\u65b9\u6cd5\u3002\u4f60\u7684\u52a0\u5bc6\u548c\u89e3\u5bc6\u7b97\u6cd5\u5982\u4f55\u8bbe\u8ba1\u548c\u8fd0\u4f5c\u662f\u6ca1\u6709\u9650\u5236\u7684\uff0c\u4f60\u53ea\u9700\u8981\u4fdd\u8bc1\u4e00\u4e2aURL\u53ef\u4ee5\u88ab\u52a0\u5bc6\u6210\u4e00\u4e2aTinyURL\uff0c\u5e76\u4e14\u8fd9\u4e2aTinyURL\u53ef\u4ee5\u7528\u89e3\u5bc6\u65b9\u6cd5\u6062\u590d\u6210\u539f\u672c\u7684URL\u3002

    \n", "tags_en": ["Hash Table", "Math"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n\n // Encodes a URL to a shortened URL.\n string encode(string longUrl) {\n \n }\n\n // Decodes a shortened URL to its original URL.\n string decode(string shortUrl) {\n \n }\n};\n\n// Your Solution object will be instantiated and called as such:\n// Solution solution;\n// solution.decode(solution.encode(url));", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "public class Codec {\n\n // Encodes a URL to a shortened URL.\n public String encode(String longUrl) {\n \n }\n\n // Decodes a shortened URL to its original URL.\n public String decode(String shortUrl) {\n \n }\n}\n\n// Your Codec object will be instantiated and called as such:\n// Codec codec = new Codec();\n// codec.decode(codec.encode(url));", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Codec:\n\n def encode(self, longUrl):\n \"\"\"Encodes a URL to a shortened URL.\n \n :type longUrl: str\n :rtype: str\n \"\"\"\n \n\n def decode(self, shortUrl):\n \"\"\"Decodes a shortened URL to its original URL.\n \n :type shortUrl: str\n :rtype: str\n \"\"\"\n \n\n# Your Codec object will be instantiated and called as such:\n# codec = Codec()\n# codec.decode(codec.encode(url))", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Codec:\n\n def encode(self, longUrl: str) -> str:\n \"\"\"Encodes a URL to a shortened URL.\n \"\"\"\n \n\n def decode(self, shortUrl: str) -> str:\n \"\"\"Decodes a shortened URL to its original URL.\n \"\"\"\n \n\n# Your Codec object will be instantiated and called as such:\n# codec = Codec()\n# codec.decode(codec.encode(url))", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/** Encodes a URL to a shortened URL. */\nchar* encode(char* longUrl) {\n \n}\n\n/** Decodes a shortened URL to its original URL. */\nchar* decode(char* shortUrl) {\n \n}\n\n// Your functions will be called as such:\n// char* s = encode(s);\n// decode(s);", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Codec {\n\n // Encodes a URL to a shortened URL\n public string encode(string longUrl) {\n \n }\n\n // Decodes a shortened URL to its original URL.\n public string decode(string shortUrl) {\n \n }\n}\n\n// Your Codec object will be instantiated and called as such:\n// Codec codec = new Codec();\n// codec.decode(codec.encode(url));", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Encodes a URL to a shortened URL.\n *\n * @param {string} longUrl\n * @return {string}\n */\nvar encode = function(longUrl) {\n \n};\n\n/**\n * Decodes a shortened URL to its original URL.\n *\n * @param {string} shortUrl\n * @return {string}\n */\nvar decode = function(shortUrl) {\n \n};\n\n/**\n * Your functions will be called as such:\n * decode(encode(url));\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Encodes a URL to a shortened URL.\n#\n# @param {string} longUrl\n# @return {string}\ndef encode(longUrl)\n \nend\n\n# Decodes a shortened URL to its original URL.\n#\n# @param {string} shortUrl\n# @return {string}\ndef decode(shortUrl)\n \nend\n\n\n# Your functions will be called as such:\n# decode(encode(url))", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Codec {\n // Encodes a URL to a shortened URL.\n func encode(_ longUrl: String) -> String {\n \n }\n \n // Decodes a shortened URL to its original URL.\n func decode(_ shortUrl: String) -> String {\n \n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * let obj = Codec()\n * val s = obj.encode(longUrl)\n * let ans = obj.decode(s)\n*/", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type Codec struct {\n \n}\n\n\nfunc Constructor() Codec {\n \n}\n\n// Encodes a URL to a shortened URL.\nfunc (this *Codec) encode(longUrl string) string {\n\t\n}\n\n// Decodes a shortened URL to its original URL.\nfunc (this *Codec) decode(shortUrl string) string {\n \n}\n\n\n/**\n * Your Codec object will be instantiated and called as such:\n * obj := Constructor();\n * url := obj.encode(longUrl);\n * ans := obj.decode(url);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class Codec {\n // Encodes a URL to a shortened URL.\n def encode(longURL: String): String = {\n \n }\n \n // Decodes a shortened URL to its original URL.\n def decode(shortURL: String): String = {\n \n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * var obj = new Codec()\n * val s = obj.encode(longURL)\n * val ans = obj.decode(s)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Codec() {\n // Encodes a URL to a shortened URL.\n fun encode(longUrl: String): String {\n \n }\n\n // Decodes a shortened URL to its original URL.\n fun decode(shortUrl: String): String {\n \n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * var obj = Codec()\n * var url = obj.encode(longUrl)\n * var ans = obj.decode(url)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct Codec {\n\t\n}\n\n/** \n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl Codec {\n fn new() -> Self {\n \n }\n\t\n // Encodes a URL to a shortened URL.\n fn encode(&self, longURL: String) -> String {\n \n }\n\t\n // Decodes a shortened URL to its original URL.\n fn decode(&self, shortURL: String) -> String {\n \n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * let obj = Codec::new();\n * let s: String = obj.encode(strs);\n * let ans: VecVec = obj.decode(s);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Codec {\n /**\n * Encodes a URL to a shortened URL.\n * @param String $longUrl\n * @return String\n */\n function encode($longUrl) {\n \n }\n \n /**\n * Decodes a shortened URL to its original URL.\n * @param String $shortUrl\n * @return String\n */\n function decode($shortUrl) {\n \n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * $obj = Codec();\n * $s = $obj->encode($longUrl);\n * $ans = $obj->decode($s);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Encodes a URL to a shortened URL.\n */\nfunction encode(longUrl: string): string {\n\t\n};\n\n/**\n * Decodes a shortened URL to its original URL.\n */\nfunction decode(shortUrl: string): string {\n\t\n};\n\n/**\n * Your functions will be called as such:\n * decode(encode(strs));\n */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0535](https://leetcode-cn.com/problems/encode-and-decode-tinyurl)", "[TinyURL \u7684\u52a0\u5bc6\u4e0e\u89e3\u5bc6](/solution/0500-0599/0535.Encode%20and%20Decode%20TinyURL/README.md)", "`\u54c8\u5e0c\u8868`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0535](https://leetcode.com/problems/encode-and-decode-tinyurl)", "[Encode and Decode TinyURL](/solution/0500-0599/0535.Encode%20and%20Decode%20TinyURL/README_EN.md)", "`Hash Table`,`Math`", "Medium", ""]}, {"question_id": "0533", "frontend_question_id": "0533", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/lonely-pixel-ii", "url_en": "https://leetcode.com/problems/lonely-pixel-ii", "relative_path_cn": "/solution/0500-0599/0533.Lonely%20Pixel%20II/README.md", "relative_path_en": "/solution/0500-0599/0533.Lonely%20Pixel%20II/README_EN.md", "title_cn": "\u5b64\u72ec\u50cf\u7d20 II", "title_en": "Lonely Pixel II", "question_title_slug": "lonely-pixel-ii", "content_en": "

    Given an m x n picture consisting of black 'B' and white 'W' pixels and an integer target, return the number of black lonely pixels.

    \n\n

    A black lonely pixel is a character 'B' that located at a specific position (r, c) where:

    \n\n
      \n\t
    • Row r and column c both contain exactly target black pixels.
    • \n\t
    • For all rows that have a black pixel at column c, they should be exactly the same as row r.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: picture = [["W","B","W","B","B","W"],["W","B","W","B","B","W"],["W","B","W","B","B","W"],["W","W","B","W","B","W"]], target = 3\nOutput: 6\nExplanation: All the green 'B' are the black pixels we need (all 'B's at column 1 and 3).\nTake 'B' at row r = 0 and column c = 1 as an example:\n - Rule 1, row r = 0 and column c = 1 both have exactly target = 3 black pixels. \n - Rule 2, the rows have black pixel at column c = 1 are row 0, row 1 and row 2. They are exactly the same as row r = 0.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: picture = [["W","W","B"],["W","W","B"],["W","W","B"]], target = 1\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == picture.length
    • \n\t
    • n == picture[i].length
    • \n\t
    • 1 <= m, n <= 200
    • \n\t
    • picture[i][j] is 'W' or 'B'.
    • \n\t
    • 1 <= target <= min(m, n)
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u5e45\u7531\u9ed1\u8272\u50cf\u7d20\u548c\u767d\u8272\u50cf\u7d20\u7ec4\u6210\u7684\u56fe\u50cf\uff0c \u4e0e\u4e00\u4e2a\u6b63\u6574\u6570N, \u627e\u5230\u4f4d\u4e8e\u67d0\u884c R \u548c\u67d0\u5217 C \u4e2d\u4e14\u7b26\u5408\u4e0b\u5217\u89c4\u5219\u7684\u9ed1\u8272\u50cf\u7d20\u7684\u6570\u91cf:

    \n\n
      \n\t
    1. \u884cR \u548c\u5217C\u90fd\u6070\u597d\u5305\u62ecN\u4e2a\u9ed1\u8272\u50cf\u7d20\u3002
    2. \n\t
    3. \u5217C\u4e2d\u6240\u6709\u9ed1\u8272\u50cf\u7d20\u6240\u5728\u7684\u884c\u5fc5\u987b\u548c\u884cR\u5b8c\u5168\u76f8\u540c\u3002
    4. \n
    \n\n

    \u56fe\u50cf\u7531\u4e00\u4e2a\u7531‘B’\u548c‘W’\u7ec4\u6210\u4e8c\u7ef4\u5b57\u7b26\u6570\u7ec4\u8868\u793a, ‘B’\u548c‘W’\u5206\u522b\u4ee3\u8868\u9ed1\u8272\u50cf\u7d20\u548c\u767d\u8272\u50cf\u7d20\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165:                                            \n[['W', 'B', 'W', 'B', 'B', 'W'],    \n ['W', 'B', 'W', 'B', 'B', 'W'],    \n ['W', 'B', 'W', 'B', 'B', 'W'],    \n ['W', 'W', 'B', 'W', 'B', 'W']] \n\nN = 3\n\u8f93\u51fa: 6\n\u89e3\u6790: \u6240\u6709\u7c97\u4f53\u7684'B'\u90fd\u662f\u6211\u4eec\u6240\u6c42\u7684\u50cf\u7d20(\u7b2c1\u5217\u548c\u7b2c3\u5217\u7684\u6240\u6709'B').\n        0    1    2    3    4    5         \u5217\u53f7                                          \n0    [['W', 'B', 'W', 'B', 'B', 'W'],    \n1     ['W', 'B', 'W', 'B', 'B', 'W'],    \n2     ['W', 'B', 'W', 'B', 'B', 'W'],    \n3     ['W', 'W', 'B', 'W', 'B', 'W']]    \n\u884c\u53f7\n\n\u4ee5R = 0\u884c\u548cC = 1\u5217\u7684'B'\u4e3a\u4f8b:\n\u89c4\u5219 1\uff0cR = 0\u884c\u548cC = 1\u5217\u90fd\u6070\u597d\u6709N = 3\u4e2a\u9ed1\u8272\u50cf\u7d20. \n\u89c4\u5219 2\uff0c\u5728C = 1\u5217\u7684\u9ed1\u8272\u50cf\u7d20\u5206\u522b\u4f4d\u4e8e0\uff0c1\u548c2\u884c\u3002\u5b83\u4eec\u90fd\u548cR = 0\u884c\u5b8c\u5168\u76f8\u540c\u3002\n\n
    \n\n

     

    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u8f93\u5165\u4e8c\u7ef4\u6570\u7ec4\u884c\u548c\u5217\u7684\u8303\u56f4\u662f [1,200]\u3002
    2. \n
    \n\n

     

    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findBlackPixel(vector>& picture, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findBlackPixel(char[][] picture, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findBlackPixel(self, picture, target):\n \"\"\"\n :type picture: List[List[str]]\n :type target: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findBlackPixel(self, picture: List[List[str]], target: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findBlackPixel(char** picture, int pictureSize, int* pictureColSize, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindBlackPixel(char[][] picture, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {character[][]} picture\n * @param {number} target\n * @return {number}\n */\nvar findBlackPixel = function(picture, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Character[][]} picture\n# @param {Integer} target\n# @return {Integer}\ndef find_black_pixel(picture, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findBlackPixel(_ picture: [[Character]], _ target: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findBlackPixel(picture [][]byte, target int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findBlackPixel(picture: Array[Array[Char]], target: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findBlackPixel(picture: Array, target: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_black_pixel(picture: Vec>, target: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $picture\n * @param Integer $target\n * @return Integer\n */\n function findBlackPixel($picture, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findBlackPixel(picture: string[][], target: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-black-pixel picture target)\n (-> (listof (listof char?)) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0533](https://leetcode-cn.com/problems/lonely-pixel-ii)", "[\u5b64\u72ec\u50cf\u7d20 II](/solution/0500-0599/0533.Lonely%20Pixel%20II/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0533](https://leetcode.com/problems/lonely-pixel-ii)", "[Lonely Pixel II](/solution/0500-0599/0533.Lonely%20Pixel%20II/README_EN.md)", "`Array`", "Medium", "\ud83d\udd12"]}, {"question_id": "0532", "frontend_question_id": "0532", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/k-diff-pairs-in-an-array", "url_en": "https://leetcode.com/problems/k-diff-pairs-in-an-array", "relative_path_cn": "/solution/0500-0599/0532.K-diff%20Pairs%20in%20an%20Array/README.md", "relative_path_en": "/solution/0500-0599/0532.K-diff%20Pairs%20in%20an%20Array/README_EN.md", "title_cn": "\u6570\u7ec4\u4e2d\u7684 k-diff \u6570\u5bf9", "title_en": "K-diff Pairs in an Array", "question_title_slug": "k-diff-pairs-in-an-array", "content_en": "

    Given an array of integers nums and an integer k, return the number of unique k-diff pairs in the array.

    \n\n

    A k-diff pair is an integer pair (nums[i], nums[j]), where the following are true:

    \n\n
      \n\t
    • 0 <= i < j < nums.length
    • \n\t
    • |nums[i] - nums[j]| == k
    • \n
    \n\n

    Notice that |val| denotes the absolute value of val.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [3,1,4,1,5], k = 2\nOutput: 2\nExplanation: There are two 2-diff pairs in the array, (1, 3) and (3, 5).\nAlthough we have two 1s in the input, we should only return the number of unique pairs.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,2,3,4,5], k = 1\nOutput: 4\nExplanation: There are four 1-diff pairs in the array, (1, 2), (2, 3), (3, 4) and (4, 5).\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [1,3,1,5,4], k = 0\nOutput: 1\nExplanation: There is one 0-diff pair in the array, (1, 1).\n
    \n\n

    Example 4:

    \n\n
    \nInput: nums = [1,2,4,4,3,3,0,9,2,3], k = 3\nOutput: 2\n
    \n\n

    Example 5:

    \n\n
    \nInput: nums = [-1,-2,-3], k = 1\nOutput: 2\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 104
    • \n\t
    • -107 <= nums[i] <= 107
    • \n\t
    • 0 <= k <= 107
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u548c\u4e00\u4e2a\u6574\u6570\u00a0k\uff0c\u4f60\u9700\u8981\u5728\u6570\u7ec4\u91cc\u627e\u5230 \u4e0d\u540c\u7684\u00a0k-diff \u6570\u5bf9\uff0c\u5e76\u8fd4\u56de\u4e0d\u540c\u7684 k-diff \u6570\u5bf9 \u7684\u6570\u76ee\u3002

    \n\n

    \u8fd9\u91cc\u5c06\u00a0k-diff\u00a0\u6570\u5bf9\u5b9a\u4e49\u4e3a\u4e00\u4e2a\u6574\u6570\u5bf9 (nums[i], nums[j])\uff0c\u5e76\u6ee1\u8db3\u4e0b\u8ff0\u5168\u90e8\u6761\u4ef6\uff1a

    \n\n
      \n\t
    • 0 <= i < j < nums.length
    • \n\t
    • |nums[i] - nums[j]| == k
    • \n
    \n\n

    \u6ce8\u610f\uff0c|val| \u8868\u793a val \u7684\u7edd\u5bf9\u503c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [3, 1, 4, 1, 5], k = 2\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6570\u7ec4\u4e2d\u6709\u4e24\u4e2a 2-diff \u6570\u5bf9, (1, 3) \u548c (3, 5)\u3002\n\u5c3d\u7ba1\u6570\u7ec4\u4e2d\u6709\u4e24\u4e2a1\uff0c\u4f46\u6211\u4eec\u53ea\u5e94\u8fd4\u56de\u4e0d\u540c\u7684\u6570\u5bf9\u7684\u6570\u91cf\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1, 2, 3, 4, 5], k = 1\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u6570\u7ec4\u4e2d\u6709\u56db\u4e2a 1-diff \u6570\u5bf9, (1, 2), (2, 3), (3, 4) \u548c (4, 5)\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1, 3, 1, 5, 4], k = 0\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u6570\u7ec4\u4e2d\u53ea\u6709\u4e00\u4e2a 0-diff \u6570\u5bf9\uff0c(1, 1)\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,4,4,3,3,0,9,2,3], k = 3\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [-1,-2,-3], k = 1\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 104
    • \n\t
    • -107 <= nums[i] <= 107
    • \n\t
    • 0 <= k <= 107
    • \n
    \n", "tags_en": ["Array", "Two Pointers"], "tags_cn": ["\u6570\u7ec4", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findPairs(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findPairs(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findPairs(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findPairs(self, nums: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findPairs(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindPairs(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar findPairs = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef find_pairs(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findPairs(_ nums: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findPairs(nums []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findPairs(nums: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findPairs(nums: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_pairs(nums: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer\n */\n function findPairs($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findPairs(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-pairs nums k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0532](https://leetcode-cn.com/problems/k-diff-pairs-in-an-array)", "[\u6570\u7ec4\u4e2d\u7684 k-diff \u6570\u5bf9](/solution/0500-0599/0532.K-diff%20Pairs%20in%20an%20Array/README.md)", "`\u6570\u7ec4`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0532](https://leetcode.com/problems/k-diff-pairs-in-an-array)", "[K-diff Pairs in an Array](/solution/0500-0599/0532.K-diff%20Pairs%20in%20an%20Array/README_EN.md)", "`Array`,`Two Pointers`", "Medium", ""]}, {"question_id": "0531", "frontend_question_id": "0531", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/lonely-pixel-i", "url_en": "https://leetcode.com/problems/lonely-pixel-i", "relative_path_cn": "/solution/0500-0599/0531.Lonely%20Pixel%20I/README.md", "relative_path_en": "/solution/0500-0599/0531.Lonely%20Pixel%20I/README_EN.md", "title_cn": "\u5b64\u72ec\u50cf\u7d20 I", "title_en": "Lonely Pixel I", "question_title_slug": "lonely-pixel-i", "content_en": "

    Given an m x n picture consisting of black 'B' and white 'W' pixels, return the number of black lonely pixels.

    \n\n

    A black lonely pixel is a character 'B' that located at a specific position where the same row and same column don't have any other black pixels.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: picture = [["W","W","B"],["W","B","W"],["B","W","W"]]\nOutput: 3\nExplanation: All the three 'B's are black lonely pixels.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: picture = [["B","B","B"],["B","B","B"],["B","B","B"]]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == picture.length
    • \n\t
    • n == picture[i].length
    • \n\t
    • 1 <= m, n <= 500
    • \n\t
    • picture[i][j] is 'W' or 'B'.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u5e45\u9ed1\u767d\u50cf\u7d20\u7ec4\u6210\u7684\u56fe\u50cf, \u8ba1\u7b97\u9ed1\u8272\u5b64\u72ec\u50cf\u7d20\u7684\u6570\u91cf\u3002

    \n\n

    \u56fe\u50cf\u7531\u4e00\u4e2a\u7531‘B’\u548c‘W’\u7ec4\u6210\u4e8c\u7ef4\u5b57\u7b26\u6570\u7ec4\u8868\u793a, ‘B’\u548c‘W’\u5206\u522b\u4ee3\u8868\u9ed1\u8272\u50cf\u7d20\u548c\u767d\u8272\u50cf\u7d20\u3002

    \n\n

    \u9ed1\u8272\u5b64\u72ec\u50cf\u7d20\u6307\u7684\u662f\u5728\u540c\u4e00\u884c\u548c\u540c\u4e00\u5217\u4e0d\u5b58\u5728\u5176\u4ed6\u9ed1\u8272\u50cf\u7d20\u7684\u9ed1\u8272\u50cf\u7d20\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: \n[['W', 'W', 'B'],\n ['W', 'B', 'W'],\n ['B', 'W', 'W']]\n\n\u8f93\u51fa: 3\n\u89e3\u6790: \u5168\u90e8\u4e09\u4e2a'B'\u90fd\u662f\u9ed1\u8272\u5b64\u72ec\u50cf\u7d20\u3002\n
    \n\n

     

    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u8f93\u5165\u4e8c\u7ef4\u6570\u7ec4\u884c\u548c\u5217\u7684\u8303\u56f4\u662f [1,500]\u3002
    2. \n
    \n\n

     

    \n", "tags_en": ["Depth-first Search", "Array"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findLonelyPixel(vector>& picture) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findLonelyPixel(char[][] picture) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findLonelyPixel(self, picture):\n \"\"\"\n :type picture: List[List[str]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findLonelyPixel(self, picture: List[List[str]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findLonelyPixel(char** picture, int pictureSize, int* pictureColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindLonelyPixel(char[][] picture) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {character[][]} picture\n * @return {number}\n */\nvar findLonelyPixel = function(picture) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Character[][]} picture\n# @return {Integer}\ndef find_lonely_pixel(picture)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findLonelyPixel(_ picture: [[Character]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findLonelyPixel(picture [][]byte) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findLonelyPixel(picture: Array[Array[Char]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findLonelyPixel(picture: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_lonely_pixel(picture: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $picture\n * @return Integer\n */\n function findLonelyPixel($picture) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findLonelyPixel(picture: string[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-lonely-pixel picture)\n (-> (listof (listof char?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0531](https://leetcode-cn.com/problems/lonely-pixel-i)", "[\u5b64\u72ec\u50cf\u7d20 I](/solution/0500-0599/0531.Lonely%20Pixel%20I/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u6570\u7ec4`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0531](https://leetcode.com/problems/lonely-pixel-i)", "[Lonely Pixel I](/solution/0500-0599/0531.Lonely%20Pixel%20I/README_EN.md)", "`Depth-first Search`,`Array`", "Medium", "\ud83d\udd12"]}, {"question_id": "0530", "frontend_question_id": "0530", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-absolute-difference-in-bst", "url_en": "https://leetcode.com/problems/minimum-absolute-difference-in-bst", "relative_path_cn": "/solution/0500-0599/0530.Minimum%20Absolute%20Difference%20in%20BST/README.md", "relative_path_en": "/solution/0500-0599/0530.Minimum%20Absolute%20Difference%20in%20BST/README_EN.md", "title_cn": "\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6700\u5c0f\u7edd\u5bf9\u5dee", "title_en": "Minimum Absolute Difference in BST", "question_title_slug": "minimum-absolute-difference-in-bst", "content_en": "

    Given the root of a Binary Search Tree (BST), return the minimum absolute difference between the values of any two different nodes in the tree.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [4,2,6,1,3]\nOutput: 1\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [1,0,48,null,null,12,49]\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [2, 104].
    • \n\t
    • 0 <= Node.val <= 105
    • \n
    \n\n

     

    \n

    Note: This question is the same as 783: https://leetcode.com/problems/minimum-distance-between-bst-nodes/

    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u68f5\u6240\u6709\u8282\u70b9\u4e3a\u975e\u8d1f\u503c\u7684\u4e8c\u53c9\u641c\u7d22\u6811\uff0c\u8bf7\u4f60\u8ba1\u7b97\u6811\u4e2d\u4efb\u610f\u4e24\u8282\u70b9\u7684\u5dee\u7684\u7edd\u5bf9\u503c\u7684\u6700\u5c0f\u503c\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1a\n\n   1\n    \\\n     3\n    /\n   2\n\n\u8f93\u51fa\uff1a\n1\n\n\u89e3\u91ca\uff1a\n\u6700\u5c0f\u7edd\u5bf9\u5dee\u4e3a 1\uff0c\u5176\u4e2d 2 \u548c 1 \u7684\u5dee\u7684\u7edd\u5bf9\u503c\u4e3a 1\uff08\u6216\u8005 2 \u548c 3\uff09\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n\n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int getMinimumDifference(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int getMinimumDifference(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def getMinimumDifference(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def getMinimumDifference(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint getMinimumDifference(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int GetMinimumDifference(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar getMinimumDifference = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef get_minimum_difference(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func getMinimumDifference(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc getMinimumDifference(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def getMinimumDifference(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun getMinimumDifference(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn get_minimum_difference(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function getMinimumDifference($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction getMinimumDifference(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (get-minimum-difference root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0530](https://leetcode-cn.com/problems/minimum-absolute-difference-in-bst)", "[\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6700\u5c0f\u7edd\u5bf9\u5dee](/solution/0500-0599/0530.Minimum%20Absolute%20Difference%20in%20BST/README.md)", "`\u6811`", "\u7b80\u5355", ""], "md_table_row_en": ["[0530](https://leetcode.com/problems/minimum-absolute-difference-in-bst)", "[Minimum Absolute Difference in BST](/solution/0500-0599/0530.Minimum%20Absolute%20Difference%20in%20BST/README_EN.md)", "`Tree`", "Easy", ""]}, {"question_id": "0529", "frontend_question_id": "0529", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minesweeper", "url_en": "https://leetcode.com/problems/minesweeper", "relative_path_cn": "/solution/0500-0599/0529.Minesweeper/README.md", "relative_path_en": "/solution/0500-0599/0529.Minesweeper/README_EN.md", "title_cn": "\u626b\u96f7\u6e38\u620f", "title_en": "Minesweeper", "question_title_slug": "minesweeper", "content_en": "

    Let's play the minesweeper game (Wikipedia, online game)!

    \n\n

    You are given an m x n char matrix board representing the game board where:

    \n\n
      \n\t
    • 'M' represents an unrevealed mine,
    • \n\t
    • 'E' represents an unrevealed empty square,
    • \n\t
    • 'B' represents a revealed blank square that has no adjacent mines (i.e., above, below, left, right, and all 4 diagonals),
    • \n\t
    • digit ('1' to '8') represents how many mines are adjacent to this revealed square, and
    • \n\t
    • 'X' represents a revealed mine.
    • \n
    \n\n

    You are also given an integer array click where click = [clickr, clickc] represents the next click position among all the unrevealed squares ('M' or 'E').

    \n\n

    Return the board after revealing this position according to the following rules:

    \n\n
      \n\t
    1. If a mine 'M' is revealed, then the game is over. You should change it to 'X'.
    2. \n\t
    3. If an empty square 'E' with no adjacent mines is revealed, then change it to a revealed blank 'B' and all of its adjacent unrevealed squares should be revealed recursively.
    4. \n\t
    5. If an empty square 'E' with at least one adjacent mine is revealed, then change it to a digit ('1' to '8') representing the number of adjacent mines.
    6. \n\t
    7. Return the board when no more squares will be revealed.
    8. \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: board = [["E","E","E","E","E"],["E","E","M","E","E"],["E","E","E","E","E"],["E","E","E","E","E"]], click = [3,0]\nOutput: [["B","1","E","1","B"],["B","1","M","1","B"],["B","1","1","1","B"],["B","B","B","B","B"]]\n
    \n\n

    Example 2:

    \n\n
    \nInput: board = [["B","1","E","1","B"],["B","1","M","1","B"],["B","1","1","1","B"],["B","B","B","B","B"]], click = [1,2]\nOutput: [["B","1","E","1","B"],["B","1","X","1","B"],["B","1","1","1","B"],["B","B","B","B","B"]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == board.length
    • \n\t
    • n == board[i].length
    • \n\t
    • 1 <= m, n <= 50
    • \n\t
    • board[i][j] is either 'M', 'E', 'B', or a digit from '1' to '8'.
    • \n\t
    • click.length == 2
    • \n\t
    • 0 <= clickr <= m
    • \n\t
    • 0 <= clickc <= n
    • \n\t
    • board[clickr][clickc] is either 'M' or 'E'.
    • \n
    \n", "content_cn": "

    \u8ba9\u6211\u4eec\u4e00\u8d77\u6765\u73a9\u626b\u96f7\u6e38\u620f\uff01

    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u4ee3\u8868\u6e38\u620f\u677f\u7684\u4e8c\u7ef4\u5b57\u7b26\u77e9\u9635\u3002 'M' \u4ee3\u8868\u4e00\u4e2a\u672a\u6316\u51fa\u7684\u5730\u96f7\uff0c'E' \u4ee3\u8868\u4e00\u4e2a\u672a\u6316\u51fa\u7684\u7a7a\u65b9\u5757\uff0c'B' \u4ee3\u8868\u6ca1\u6709\u76f8\u90bb\uff08\u4e0a\uff0c\u4e0b\uff0c\u5de6\uff0c\u53f3\uff0c\u548c\u6240\u67094\u4e2a\u5bf9\u89d2\u7ebf\uff09\u5730\u96f7\u7684\u5df2\u6316\u51fa\u7684\u7a7a\u767d\u65b9\u5757\uff0c\u6570\u5b57\uff08'1' \u5230 '8'\uff09\u8868\u793a\u6709\u591a\u5c11\u5730\u96f7\u4e0e\u8fd9\u5757\u5df2\u6316\u51fa\u7684\u65b9\u5757\u76f8\u90bb\uff0c'X' \u5219\u8868\u793a\u4e00\u4e2a\u5df2\u6316\u51fa\u7684\u5730\u96f7\u3002

    \n\n

    \u73b0\u5728\u7ed9\u51fa\u5728\u6240\u6709\u672a\u6316\u51fa\u7684\u65b9\u5757\u4e2d\uff08'M'\u6216\u8005'E'\uff09\u7684\u4e0b\u4e00\u4e2a\u70b9\u51fb\u4f4d\u7f6e\uff08\u884c\u548c\u5217\u7d22\u5f15\uff09\uff0c\u6839\u636e\u4ee5\u4e0b\u89c4\u5219\uff0c\u8fd4\u56de\u76f8\u5e94\u4f4d\u7f6e\u88ab\u70b9\u51fb\u540e\u5bf9\u5e94\u7684\u9762\u677f\uff1a

    \n\n
      \n\t
    1. \u5982\u679c\u4e00\u4e2a\u5730\u96f7\uff08'M'\uff09\u88ab\u6316\u51fa\uff0c\u6e38\u620f\u5c31\u7ed3\u675f\u4e86- \u628a\u5b83\u6539\u4e3a 'X'\u3002
    2. \n\t
    3. \u5982\u679c\u4e00\u4e2a\u6ca1\u6709\u76f8\u90bb\u5730\u96f7\u7684\u7a7a\u65b9\u5757\uff08'E'\uff09\u88ab\u6316\u51fa\uff0c\u4fee\u6539\u5b83\u4e3a\uff08'B'\uff09\uff0c\u5e76\u4e14\u6240\u6709\u548c\u5176\u76f8\u90bb\u7684\u672a\u6316\u51fa\u65b9\u5757\u90fd\u5e94\u8be5\u88ab\u9012\u5f52\u5730\u63ed\u9732\u3002
    4. \n\t
    5. \u5982\u679c\u4e00\u4e2a\u81f3\u5c11\u4e0e\u4e00\u4e2a\u5730\u96f7\u76f8\u90bb\u7684\u7a7a\u65b9\u5757\uff08'E'\uff09\u88ab\u6316\u51fa\uff0c\u4fee\u6539\u5b83\u4e3a\u6570\u5b57\uff08'1'\u5230'8'\uff09\uff0c\u8868\u793a\u76f8\u90bb\u5730\u96f7\u7684\u6570\u91cf\u3002
    6. \n\t
    7. \u5982\u679c\u5728\u6b64\u6b21\u70b9\u51fb\u4e2d\uff0c\u82e5\u65e0\u66f4\u591a\u65b9\u5757\u53ef\u88ab\u63ed\u9732\uff0c\u5219\u8fd4\u56de\u9762\u677f\u3002
    8. \n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165: \n\n[['E', 'E', 'E', 'E', 'E'],\n ['E', 'E', 'M', 'E', 'E'],\n ['E', 'E', 'E', 'E', 'E'],\n ['E', 'E', 'E', 'E', 'E']]\n\nClick : [3,0]\n\n\u8f93\u51fa: \n\n[['B', '1', 'E', '1', 'B'],\n ['B', '1', 'M', '1', 'B'],\n ['B', '1', '1', '1', 'B'],\n ['B', 'B', 'B', 'B', 'B']]\n\n\u89e3\u91ca:\n\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165: \n\n[['B', '1', 'E', '1', 'B'],\n ['B', '1', 'M', '1', 'B'],\n ['B', '1', '1', '1', 'B'],\n ['B', 'B', 'B', 'B', 'B']]\n\nClick : [1,2]\n\n\u8f93\u51fa: \n\n[['B', '1', 'E', '1', 'B'],\n ['B', '1', 'X', '1', 'B'],\n ['B', '1', '1', '1', 'B'],\n ['B', 'B', 'B', 'B', 'B']]\n\n\u89e3\u91ca:\n\n
    \n\n

     

    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    1. \u8f93\u5165\u77e9\u9635\u7684\u5bbd\u548c\u9ad8\u7684\u8303\u56f4\u4e3a [1,50]\u3002
    2. \n\t
    3. \u70b9\u51fb\u7684\u4f4d\u7f6e\u53ea\u80fd\u662f\u672a\u88ab\u6316\u51fa\u7684\u65b9\u5757 ('M' \u6216\u8005 'E')\uff0c\u8fd9\u4e5f\u610f\u5473\u7740\u9762\u677f\u81f3\u5c11\u5305\u542b\u4e00\u4e2a\u53ef\u70b9\u51fb\u7684\u65b9\u5757\u3002
    4. \n\t
    5. \u8f93\u5165\u9762\u677f\u4e0d\u4f1a\u662f\u6e38\u620f\u7ed3\u675f\u7684\u72b6\u6001\uff08\u5373\u6709\u5730\u96f7\u5df2\u88ab\u6316\u51fa\uff09\u3002
    6. \n\t
    7. \u7b80\u5355\u8d77\u89c1\uff0c\u672a\u63d0\u53ca\u7684\u89c4\u5219\u5728\u8fd9\u4e2a\u95ee\u9898\u4e2d\u53ef\u88ab\u5ffd\u7565\u3002\u4f8b\u5982\uff0c\u5f53\u6e38\u620f\u7ed3\u675f\u65f6\u4f60\u4e0d\u9700\u8981\u6316\u51fa\u6240\u6709\u5730\u96f7\uff0c\u8003\u8651\u6240\u6709\u4f60\u53ef\u80fd\u8d62\u5f97\u6e38\u620f\u6216\u6807\u8bb0\u65b9\u5757\u7684\u60c5\u51b5\u3002
    8. \n
    \n", "tags_en": ["Depth-first Search", "Breadth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> updateBoard(vector>& board, vector& click) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public char[][] updateBoard(char[][] board, int[] click) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def updateBoard(self, board, click):\n \"\"\"\n :type board: List[List[str]]\n :type click: List[int]\n :rtype: List[List[str]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def updateBoard(self, board: List[List[str]], click: List[int]) -> List[List[str]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nchar** updateBoard(char** board, int boardSize, int* boardColSize, int* click, int clickSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public char[][] UpdateBoard(char[][] board, int[] click) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {character[][]} board\n * @param {number[]} click\n * @return {character[][]}\n */\nvar updateBoard = function(board, click) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Character[][]} board\n# @param {Integer[]} click\n# @return {Character[][]}\ndef update_board(board, click)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func updateBoard(_ board: [[Character]], _ click: [Int]) -> [[Character]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func updateBoard(board [][]byte, click []int) [][]byte {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def updateBoard(board: Array[Array[Char]], click: Array[Int]): Array[Array[Char]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun updateBoard(board: Array, click: IntArray): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn update_board(board: Vec>, click: Vec) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $board\n * @param Integer[] $click\n * @return String[][]\n */\n function updateBoard($board, $click) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function updateBoard(board: string[][], click: number[]): string[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (update-board board click)\n (-> (listof (listof char?)) (listof exact-integer?) (listof (listof char?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0529](https://leetcode-cn.com/problems/minesweeper)", "[\u626b\u96f7\u6e38\u620f](/solution/0500-0599/0529.Minesweeper/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0529](https://leetcode.com/problems/minesweeper)", "[Minesweeper](/solution/0500-0599/0529.Minesweeper/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`", "Medium", ""]}, {"question_id": "0528", "frontend_question_id": "1721", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/swapping-nodes-in-a-linked-list", "url_en": "https://leetcode.com/problems/swapping-nodes-in-a-linked-list", "relative_path_cn": "/solution/1700-1799/1721.Swapping%20Nodes%20in%20a%20Linked%20List/README.md", "relative_path_en": "/solution/1700-1799/1721.Swapping%20Nodes%20in%20a%20Linked%20List/README_EN.md", "title_cn": "\u4ea4\u6362\u94fe\u8868\u4e2d\u7684\u8282\u70b9", "title_en": "Swapping Nodes in a Linked List", "question_title_slug": "swapping-nodes-in-a-linked-list", "content_en": "

    You are given the head of a linked list, and an integer k.

    \n\n

    Return the head of the linked list after swapping the values of the kth node from the beginning and the kth node from the end (the list is 1-indexed).

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: head = [1,2,3,4,5], k = 2\nOutput: [1,4,3,2,5]\n
    \n\n

    Example 2:

    \n\n
    \nInput: head = [7,9,6,6,7,8,3,0,9,5], k = 5\nOutput: [7,9,6,6,8,7,3,0,9,5]\n
    \n\n

    Example 3:

    \n\n
    \nInput: head = [1], k = 1\nOutput: [1]\n
    \n\n

    Example 4:

    \n\n
    \nInput: head = [1,2], k = 1\nOutput: [2,1]\n
    \n\n

    Example 5:

    \n\n
    \nInput: head = [1,2,3], k = 2\nOutput: [1,2,3]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the list is n.
    • \n\t
    • 1 <= k <= n <= 105
    • \n\t
    • 0 <= Node.val <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u94fe\u8868\u7684\u5934\u8282\u70b9 head \u548c\u4e00\u4e2a\u6574\u6570 k \u3002

    \n\n

    \u4ea4\u6362 \u94fe\u8868\u6b63\u6570\u7b2c k \u4e2a\u8282\u70b9\u548c\u5012\u6570\u7b2c k \u4e2a\u8282\u70b9\u7684\u503c\u540e\uff0c\u8fd4\u56de\u94fe\u8868\u7684\u5934\u8282\u70b9\uff08\u94fe\u8868 \u4ece 1 \u5f00\u59cb\u7d22\u5f15\uff09\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1ahead = [1,2,3,4,5], k = 2\n\u8f93\u51fa\uff1a[1,4,3,2,5]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahead = [7,9,6,6,7,8,3,0,9,5], k = 5\n\u8f93\u51fa\uff1a[7,9,6,6,8,7,3,0,9,5]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahead = [1], k = 1\n\u8f93\u51fa\uff1a[1]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahead = [1,2], k = 1\n\u8f93\u51fa\uff1a[2,1]\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahead = [1,2,3], k = 2\n\u8f93\u51fa\uff1a[1,2,3]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u94fe\u8868\u4e2d\u8282\u70b9\u7684\u6570\u76ee\u662f n
    • \n\t
    • 1 <= k <= n <= 105
    • \n\t
    • 0 <= Node.val <= 100
    • \n
    \n", "tags_en": ["Linked List"], "tags_cn": ["\u94fe\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n ListNode* swapNodes(ListNode* head, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public ListNode swapNodes(ListNode head, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def swapNodes(self, head, k):\n \"\"\"\n :type head: ListNode\n :type k: int\n :rtype: ListNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def swapNodes(self, head: ListNode, k: int) -> ListNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nstruct ListNode* swapNodes(struct ListNode* head, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public ListNode SwapNodes(ListNode head, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} head\n * @param {number} k\n * @return {ListNode}\n */\nvar swapNodes = function(head, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode} head\n# @param {Integer} k\n# @return {ListNode}\ndef swap_nodes(head, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func swapNodes(_ head: ListNode?, _ k: Int) -> ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc swapNodes(head *ListNode, k int) *ListNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def swapNodes(head: ListNode, k: Int): ListNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun swapNodes(head: ListNode?, k: Int): ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn swap_nodes(head: Option>, k: i32) -> Option> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @param Integer $k\n * @return ListNode\n */\n function swapNodes($head, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction swapNodes(head: ListNode | null, k: number): ListNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (swap-nodes head k)\n (-> (or/c list-node? #f) exact-integer? (or/c list-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1721](https://leetcode-cn.com/problems/swapping-nodes-in-a-linked-list)", "[\u4ea4\u6362\u94fe\u8868\u4e2d\u7684\u8282\u70b9](/solution/1700-1799/1721.Swapping%20Nodes%20in%20a%20Linked%20List/README.md)", "`\u94fe\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1721](https://leetcode.com/problems/swapping-nodes-in-a-linked-list)", "[Swapping Nodes in a Linked List](/solution/1700-1799/1721.Swapping%20Nodes%20in%20a%20Linked%20List/README_EN.md)", "`Linked List`", "Medium", ""]}, {"question_id": "0527", "frontend_question_id": "0527", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/word-abbreviation", "url_en": "https://leetcode.com/problems/word-abbreviation", "relative_path_cn": "/solution/0500-0599/0527.Word%20Abbreviation/README.md", "relative_path_en": "/solution/0500-0599/0527.Word%20Abbreviation/README_EN.md", "title_cn": "\u5355\u8bcd\u7f29\u5199", "title_en": "Word Abbreviation", "question_title_slug": "word-abbreviation", "content_en": "

    Given an array of distinct strings words, return the minimal possible abbreviations for every word.

    \n\n

    The following are the rules for a string abbreviation:

    \n\n
      \n\t
    1. Begin with the first character, and then the number of characters abbreviated, followed by the last character.
    2. \n\t
    3. If there is any conflict and more than one word shares the same abbreviation, a longer prefix is used instead of only the first character until making the map from word to abbreviation become unique. In other words, a final abbreviation cannot map to more than one original word.
    4. \n\t
    5. If the abbreviation does not make the word shorter, then keep it as the original.
    6. \n
    \n\n

     

    \n

    Example 1:

    \n
    Input: words = [\"like\",\"god\",\"internal\",\"me\",\"internet\",\"interval\",\"intension\",\"face\",\"intrusion\"]\nOutput: [\"l2e\",\"god\",\"internal\",\"me\",\"i6t\",\"interval\",\"inte4n\",\"f2e\",\"intr4n\"]\n

    Example 2:

    \n
    Input: words = [\"aa\",\"aaa\"]\nOutput: [\"aa\",\"aaa\"]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= words.length <= 400
    • \n\t
    • 2 <= words[i].length <= 400
    • \n\t
    • words[i] consists of lowercase English letters.
    • \n\t
    • All the strings of words are unique.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u7531n\u4e2a\u4e0d\u91cd\u590d\u975e\u7a7a\u5b57\u7b26\u4e32\u7ec4\u6210\u7684\u6570\u7ec4\uff0c\u4f60\u9700\u8981\u6309\u7167\u4ee5\u4e0b\u89c4\u5219\u4e3a\u6bcf\u4e2a\u5355\u8bcd\u751f\u6210\u6700\u5c0f\u7684\u7f29\u5199\u3002

    \n\n
      \n\t
    1. \u521d\u59cb\u7f29\u5199\u7531\u8d77\u59cb\u5b57\u6bcd+\u7701\u7565\u5b57\u6bcd\u7684\u6570\u91cf+\u7ed3\u5c3e\u5b57\u6bcd\u7ec4\u6210\u3002
    2. \n\t
    3. \u82e5\u5b58\u5728\u51b2\u7a81\uff0c\u4ea6\u5373\u591a\u4e8e\u4e00\u4e2a\u5355\u8bcd\u6709\u540c\u6837\u7684\u7f29\u5199\uff0c\u5219\u4f7f\u7528\u66f4\u957f\u7684\u524d\u7f00\u4ee3\u66ff\u9996\u5b57\u6bcd\uff0c\u76f4\u5230\u4ece\u5355\u8bcd\u5230\u7f29\u5199\u7684\u6620\u5c04\u552f\u4e00\u3002\u6362\u800c\u8a00\u4e4b\uff0c\u6700\u7ec8\u7684\u7f29\u5199\u5fc5\u987b\u53ea\u80fd\u6620\u5c04\u5230\u4e00\u4e2a\u5355\u8bcd\u3002
    4. \n\t
    5. \u82e5\u7f29\u5199\u5e76\u4e0d\u6bd4\u539f\u5355\u8bcd\u66f4\u77ed\uff0c\u5219\u4fdd\u7559\u539f\u6837\u3002
    6. \n
    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: ["like", "god", "internal", "me", "internet", "interval", "intension", "face", "intrusion"]\n\u8f93\u51fa: ["l2e","god","internal","me","i6t","interval","inte4n","f2e","intr4n"]\n
    \n\n

     

    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. n\u548c\u6bcf\u4e2a\u5355\u8bcd\u7684\u957f\u5ea6\u5747\u4e0d\u8d85\u8fc7 400\u3002
    2. \n\t
    3. \u6bcf\u4e2a\u5355\u8bcd\u7684\u957f\u5ea6\u5927\u4e8e 1\u3002
    4. \n\t
    5. \u5355\u8bcd\u53ea\u7531\u82f1\u6587\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210\u3002
    6. \n\t
    7. \u8fd4\u56de\u7684\u7b54\u6848\u9700\u8981\u548c\u539f\u6570\u7ec4\u4fdd\u6301\u540c\u4e00\u987a\u5e8f\u3002
    8. \n
    \n", "tags_en": ["Sort", "String"], "tags_cn": ["\u6392\u5e8f", "\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector wordsAbbreviation(vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List wordsAbbreviation(List words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def wordsAbbreviation(self, words):\n \"\"\"\n :type words: List[str]\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def wordsAbbreviation(self, words: List[str]) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** wordsAbbreviation(char ** words, int wordsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList WordsAbbreviation(IList words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @return {string[]}\n */\nvar wordsAbbreviation = function(words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @return {String[]}\ndef words_abbreviation(words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func wordsAbbreviation(_ words: [String]) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func wordsAbbreviation(words []string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def wordsAbbreviation(words: List[String]): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun wordsAbbreviation(words: List): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn words_abbreviation(words: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @return String[]\n */\n function wordsAbbreviation($words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function wordsAbbreviation(words: string[]): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (words-abbreviation words)\n (-> (listof string?) (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0527](https://leetcode-cn.com/problems/word-abbreviation)", "[\u5355\u8bcd\u7f29\u5199](/solution/0500-0599/0527.Word%20Abbreviation/README.md)", "`\u6392\u5e8f`,`\u5b57\u7b26\u4e32`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0527](https://leetcode.com/problems/word-abbreviation)", "[Word Abbreviation](/solution/0500-0599/0527.Word%20Abbreviation/README_EN.md)", "`Sort`,`String`", "Hard", "\ud83d\udd12"]}, {"question_id": "0526", "frontend_question_id": "0526", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/beautiful-arrangement", "url_en": "https://leetcode.com/problems/beautiful-arrangement", "relative_path_cn": "/solution/0500-0599/0526.Beautiful%20Arrangement/README.md", "relative_path_en": "/solution/0500-0599/0526.Beautiful%20Arrangement/README_EN.md", "title_cn": "\u4f18\u7f8e\u7684\u6392\u5217", "title_en": "Beautiful Arrangement", "question_title_slug": "beautiful-arrangement", "content_en": "

    Suppose you have n integers labeled 1 through n. A permutation of those n integers perm (1-indexed) is considered a beautiful arrangement if for every i (1 <= i <= n), either of the following is true:

    \n\n
      \n\t
    • perm[i] is divisible by i.
    • \n\t
    • i is divisible by perm[i].
    • \n
    \n\n

    Given an integer n, return the number of the beautiful arrangements that you can construct.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 2\nOutput: 2\nExplanation: \nThe first beautiful arrangement is [1,2]:\n    - perm[1] = 1 is divisible by i = 1\n    - perm[2] = 2 is divisible by i = 2\nThe second beautiful arrangement is [2,1]:\n    - perm[1] = 2 is divisible by i = 1\n    - i = 2 is divisible by perm[2] = 1\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 1\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 15
    • \n
    \n", "content_cn": "

    \u5047\u8bbe\u6709\u4ece 1 \u5230 N \u7684 \u4e2a\u6574\u6570\uff0c\u5982\u679c\u4ece\u8fd9 \u4e2a\u6570\u5b57\u4e2d\u6210\u529f\u6784\u9020\u51fa\u4e00\u4e2a\u6570\u7ec4\uff0c\u4f7f\u5f97\u6570\u7ec4\u7684\u7b2c i \u4f4d (1 <= i <= N) \u6ee1\u8db3\u5982\u4e0b\u4e24\u4e2a\u6761\u4ef6\u4e2d\u7684\u4e00\u4e2a\uff0c\u6211\u4eec\u5c31\u79f0\u8fd9\u4e2a\u6570\u7ec4\u4e3a\u4e00\u4e2a\u4f18\u7f8e\u7684\u6392\u5217\u3002\u6761\u4ef6\uff1a

    \n\n
      \n\t
    1. \u7b2c \u4f4d\u7684\u6570\u5b57\u80fd\u88ab \u6574\u9664
    2. \n\t
    3. i \u80fd\u88ab\u7b2c i \u4f4d\u4e0a\u7684\u6570\u5b57\u6574\u9664
    4. \n
    \n\n

    \u73b0\u5728\u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570 N\uff0c\u8bf7\u95ee\u53ef\u4ee5\u6784\u9020\u591a\u5c11\u4e2a\u4f18\u7f8e\u7684\u6392\u5217\uff1f

    \n\n

    \u793a\u4f8b1:

    \n\n
    \n\u8f93\u5165: 2\n\u8f93\u51fa: 2\n\u89e3\u91ca: \n\n\u7b2c 1 \u4e2a\u4f18\u7f8e\u7684\u6392\u5217\u662f [1, 2]:\n  \u7b2c 1 \u4e2a\u4f4d\u7f6e\uff08i=1\uff09\u4e0a\u7684\u6570\u5b57\u662f1\uff0c1\u80fd\u88ab i\uff08i=1\uff09\u6574\u9664\n  \u7b2c 2 \u4e2a\u4f4d\u7f6e\uff08i=2\uff09\u4e0a\u7684\u6570\u5b57\u662f2\uff0c2\u80fd\u88ab i\uff08i=2\uff09\u6574\u9664\n\n\u7b2c 2 \u4e2a\u4f18\u7f8e\u7684\u6392\u5217\u662f [2, 1]:\n  \u7b2c 1 \u4e2a\u4f4d\u7f6e\uff08i=1\uff09\u4e0a\u7684\u6570\u5b57\u662f2\uff0c2\u80fd\u88ab i\uff08i=1\uff09\u6574\u9664\n  \u7b2c 2 \u4e2a\u4f4d\u7f6e\uff08i=2\uff09\u4e0a\u7684\u6570\u5b57\u662f1\uff0ci\uff08i=2\uff09\u80fd\u88ab 1 \u6574\u9664\n
    \n\n

    \u8bf4\u660e:

    \n\n
      \n\t
    1. N \u662f\u4e00\u4e2a\u6b63\u6574\u6570\uff0c\u5e76\u4e14\u4e0d\u4f1a\u8d85\u8fc715\u3002
    2. \n
    \n", "tags_en": ["Depth-first Search", "Backtracking"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countArrangement(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countArrangement(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countArrangement(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countArrangement(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countArrangement(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountArrangement(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar countArrangement = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef count_arrangement(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countArrangement(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countArrangement(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countArrangement(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countArrangement(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_arrangement(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function countArrangement($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countArrangement(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-arrangement n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0526](https://leetcode-cn.com/problems/beautiful-arrangement)", "[\u4f18\u7f8e\u7684\u6392\u5217](/solution/0500-0599/0526.Beautiful%20Arrangement/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0526](https://leetcode.com/problems/beautiful-arrangement)", "[Beautiful Arrangement](/solution/0500-0599/0526.Beautiful%20Arrangement/README_EN.md)", "`Depth-first Search`,`Backtracking`", "Medium", ""]}, {"question_id": "0525", "frontend_question_id": "0525", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/contiguous-array", "url_en": "https://leetcode.com/problems/contiguous-array", "relative_path_cn": "/solution/0500-0599/0525.Contiguous%20Array/README.md", "relative_path_en": "/solution/0500-0599/0525.Contiguous%20Array/README_EN.md", "title_cn": "\u8fde\u7eed\u6570\u7ec4", "title_en": "Contiguous Array", "question_title_slug": "contiguous-array", "content_en": "

    Given a binary array nums, return the maximum length of a contiguous subarray with an equal number of 0 and 1.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [0,1]\nOutput: 2\nExplanation: [0, 1] is the longest contiguous subarray with an equal number of 0 and 1.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [0,1,0]\nOutput: 2\nExplanation: [0, 1] (or [1, 0]) is a longest contiguous subarray with equal number of 0 and 1.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • nums[i] is either 0 or 1.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u8fdb\u5236\u6570\u7ec4 nums , \u627e\u5230\u542b\u6709\u76f8\u540c\u6570\u91cf\u7684 0 \u548c 1 \u7684\u6700\u957f\u8fde\u7eed\u5b50\u6570\u7ec4\uff0c\u5e76\u8fd4\u56de\u8be5\u5b50\u6570\u7ec4\u7684\u957f\u5ea6\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: nums = [0,1]\n\u8f93\u51fa: 2\n\u8bf4\u660e: [0, 1] \u662f\u5177\u6709\u76f8\u540c\u6570\u91cf0\u548c1\u7684\u6700\u957f\u8fde\u7eed\u5b50\u6570\u7ec4\u3002
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: nums = [0,1,0]\n\u8f93\u51fa: 2\n\u8bf4\u660e: [0, 1] (\u6216 [1, 0]) \u662f\u5177\u6709\u76f8\u540c\u6570\u91cf0\u548c1\u7684\u6700\u957f\u8fde\u7eed\u5b50\u6570\u7ec4\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • nums[i] \u4e0d\u662f 0 \u5c31\u662f 1
    • \n
    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findMaxLength(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findMaxLength(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findMaxLength(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findMaxLength(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findMaxLength(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindMaxLength(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar findMaxLength = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef find_max_length(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findMaxLength(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findMaxLength(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findMaxLength(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findMaxLength(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_max_length(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function findMaxLength($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findMaxLength(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-max-length nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0525](https://leetcode-cn.com/problems/contiguous-array)", "[\u8fde\u7eed\u6570\u7ec4](/solution/0500-0599/0525.Contiguous%20Array/README.md)", "`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0525](https://leetcode.com/problems/contiguous-array)", "[Contiguous Array](/solution/0500-0599/0525.Contiguous%20Array/README_EN.md)", "`Hash Table`", "Medium", ""]}, {"question_id": "0524", "frontend_question_id": "0524", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-word-in-dictionary-through-deleting", "url_en": "https://leetcode.com/problems/longest-word-in-dictionary-through-deleting", "relative_path_cn": "/solution/0500-0599/0524.Longest%20Word%20in%20Dictionary%20through%20Deleting/README.md", "relative_path_en": "/solution/0500-0599/0524.Longest%20Word%20in%20Dictionary%20through%20Deleting/README_EN.md", "title_cn": "\u901a\u8fc7\u5220\u9664\u5b57\u6bcd\u5339\u914d\u5230\u5b57\u5178\u91cc\u6700\u957f\u5355\u8bcd", "title_en": "Longest Word in Dictionary through Deleting", "question_title_slug": "longest-word-in-dictionary-through-deleting", "content_en": "

    Given a string s and a string array dictionary, return the longest string in the dictionary that can be formed by deleting some of the given string characters. If there is more than one possible result, return the longest word with the smallest lexicographical order. If there is no possible result, return the empty string.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "abpcplea", dictionary = ["ale","apple","monkey","plea"]\nOutput: "apple"\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "abpcplea", dictionary = ["a","b","c"]\nOutput: "a"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 1000
    • \n\t
    • 1 <= dictionary.length <= 1000
    • \n\t
    • 1 <= dictionary[i].length <= 1000
    • \n\t
    • s and dictionary[i] consist of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \u548c\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4 dictionary \u4f5c\u4e3a\u5b57\u5178\uff0c\u627e\u51fa\u5e76\u8fd4\u56de\u5b57\u5178\u4e2d\u6700\u957f\u7684\u5b57\u7b26\u4e32\uff0c\u8be5\u5b57\u7b26\u4e32\u53ef\u4ee5\u901a\u8fc7\u5220\u9664 s \u4e2d\u7684\u67d0\u4e9b\u5b57\u7b26\u5f97\u5230\u3002

    \n\n

    \u5982\u679c\u7b54\u6848\u4e0d\u6b62\u4e00\u4e2a\uff0c\u8fd4\u56de\u957f\u5ea6\u6700\u957f\u4e14\u5b57\u5178\u5e8f\u6700\u5c0f\u7684\u5b57\u7b26\u4e32\u3002\u5982\u679c\u7b54\u6848\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"abpcplea\", dictionary = [\"ale\",\"apple\",\"monkey\",\"plea\"]\n\u8f93\u51fa\uff1a\"apple\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"abpcplea\", dictionary = [\"a\",\"b\",\"c\"]\n\u8f93\u51fa\uff1a\"a\"\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 1000
    • \n\t
    • 1 <= dictionary.length <= 1000
    • \n\t
    • 1 <= dictionary[i].length <= 1000
    • \n\t
    • s \u548c dictionary[i] \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n", "tags_en": ["Sort", "Two Pointers"], "tags_cn": ["\u6392\u5e8f", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string findLongestWord(string s, vector& dictionary) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String findLongestWord(String s, List dictionary) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findLongestWord(self, s, dictionary):\n \"\"\"\n :type s: str\n :type dictionary: List[str]\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findLongestWord(self, s: str, dictionary: List[str]) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * findLongestWord(char * s, char ** dictionary, int dictionarySize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string FindLongestWord(string s, IList dictionary) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string[]} dictionary\n * @return {string}\n */\nvar findLongestWord = function(s, dictionary) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String[]} dictionary\n# @return {String}\ndef find_longest_word(s, dictionary)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findLongestWord(_ s: String, _ dictionary: [String]) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findLongestWord(s string, dictionary []string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findLongestWord(s: String, dictionary: List[String]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findLongestWord(s: String, dictionary: List): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_longest_word(s: String, dictionary: Vec) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String[] $dictionary\n * @return String\n */\n function findLongestWord($s, $dictionary) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findLongestWord(s: string, dictionary: string[]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-longest-word s dictionary)\n (-> string? (listof string?) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0524](https://leetcode-cn.com/problems/longest-word-in-dictionary-through-deleting)", "[\u901a\u8fc7\u5220\u9664\u5b57\u6bcd\u5339\u914d\u5230\u5b57\u5178\u91cc\u6700\u957f\u5355\u8bcd](/solution/0500-0599/0524.Longest%20Word%20in%20Dictionary%20through%20Deleting/README.md)", "`\u6392\u5e8f`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0524](https://leetcode.com/problems/longest-word-in-dictionary-through-deleting)", "[Longest Word in Dictionary through Deleting](/solution/0500-0599/0524.Longest%20Word%20in%20Dictionary%20through%20Deleting/README_EN.md)", "`Sort`,`Two Pointers`", "Medium", ""]}, {"question_id": "0523", "frontend_question_id": "0523", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/continuous-subarray-sum", "url_en": "https://leetcode.com/problems/continuous-subarray-sum", "relative_path_cn": "/solution/0500-0599/0523.Continuous%20Subarray%20Sum/README.md", "relative_path_en": "/solution/0500-0599/0523.Continuous%20Subarray%20Sum/README_EN.md", "title_cn": "\u8fde\u7eed\u7684\u5b50\u6570\u7ec4\u548c", "title_en": "Continuous Subarray Sum", "question_title_slug": "continuous-subarray-sum", "content_en": "

    Given an integer array nums and an integer k, return true if nums has a continuous subarray of size at least two whose elements sum up to a multiple of k, or false otherwise.

    \n\n

    An integer x is a multiple of k if there exists an integer n such that x = n * k. 0 is always a multiple of k.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [23,2,4,6,7], k = 6\nOutput: true\nExplanation: [2, 4] is a continuous subarray of size 2 whose elements sum up to 6.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [23,2,6,4,7], k = 6\nOutput: true\nExplanation: [23, 2, 6, 4, 7] is an continuous subarray of size 5 whose elements sum up to 42.\n42 is a multiple of 6 because 42 = 7 * 6 and 7 is an integer.\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [23,2,6,4,7], k = 13\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • 0 <= nums[i] <= 109
    • \n\t
    • 0 <= sum(nums[i]) <= 231 - 1
    • \n\t
    • 1 <= k <= 231 - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \u548c\u4e00\u4e2a\u6574\u6570\u00a0k \uff0c\u7f16\u5199\u4e00\u4e2a\u51fd\u6570\u6765\u5224\u65ad\u8be5\u6570\u7ec4\u662f\u5426\u542b\u6709\u540c\u65f6\u6ee1\u8db3\u4e0b\u8ff0\u6761\u4ef6\u7684\u8fde\u7eed\u5b50\u6570\u7ec4\uff1a

    \n\n
      \n\t
    • \u5b50\u6570\u7ec4\u5927\u5c0f \u81f3\u5c11\u4e3a 2 \uff0c\u4e14
    • \n\t
    • \u5b50\u6570\u7ec4\u5143\u7d20\u603b\u548c\u4e3a k \u7684\u500d\u6570\u3002
    • \n
    \n\n

    \u5982\u679c\u5b58\u5728\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n

    \u5982\u679c\u5b58\u5728\u4e00\u4e2a\u6574\u6570 n \uff0c\u4ee4\u6574\u6570 x \u7b26\u5408 x = n * k \uff0c\u5219\u79f0 x \u662f k \u7684\u4e00\u4e2a\u500d\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [23,2,4,6,7], k = 6\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a[2,4] \u662f\u4e00\u4e2a\u5927\u5c0f\u4e3a 2 \u7684\u5b50\u6570\u7ec4\uff0c\u5e76\u4e14\u548c\u4e3a 6 \u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [23,2,6,4,7], k = 6\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a[23, 2, 6, 4, 7] \u662f\u5927\u5c0f\u4e3a 5 \u7684\u5b50\u6570\u7ec4\uff0c\u5e76\u4e14\u548c\u4e3a 42 \u3002 \n42 \u662f 6 \u7684\u500d\u6570\uff0c\u56e0\u4e3a 42 = 7 * 6 \u4e14 7 \u662f\u4e00\u4e2a\u6574\u6570\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [23,2,6,4,7], k = 13\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • 0 <= nums[i] <= 109
    • \n\t
    • 0 <= sum(nums[i]) <= 231 - 1
    • \n\t
    • 1 <= k <= 231 - 1
    • \n
    \n", "tags_en": ["Math", "Dynamic Programming"], "tags_cn": ["\u6570\u5b66", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool checkSubarraySum(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean checkSubarraySum(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def checkSubarraySum(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def checkSubarraySum(self, nums: List[int], k: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool checkSubarraySum(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CheckSubarraySum(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {boolean}\n */\nvar checkSubarraySum = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Boolean}\ndef check_subarray_sum(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func checkSubarraySum(_ nums: [Int], _ k: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func checkSubarraySum(nums []int, k int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def checkSubarraySum(nums: Array[Int], k: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun checkSubarraySum(nums: IntArray, k: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn check_subarray_sum(nums: Vec, k: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Boolean\n */\n function checkSubarraySum($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function checkSubarraySum(nums: number[], k: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (check-subarray-sum nums k)\n (-> (listof exact-integer?) exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0523](https://leetcode-cn.com/problems/continuous-subarray-sum)", "[\u8fde\u7eed\u7684\u5b50\u6570\u7ec4\u548c](/solution/0500-0599/0523.Continuous%20Subarray%20Sum/README.md)", "`\u6570\u5b66`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0523](https://leetcode.com/problems/continuous-subarray-sum)", "[Continuous Subarray Sum](/solution/0500-0599/0523.Continuous%20Subarray%20Sum/README_EN.md)", "`Math`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0522", "frontend_question_id": "0522", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-uncommon-subsequence-ii", "url_en": "https://leetcode.com/problems/longest-uncommon-subsequence-ii", "relative_path_cn": "/solution/0500-0599/0522.Longest%20Uncommon%20Subsequence%20II/README.md", "relative_path_en": "/solution/0500-0599/0522.Longest%20Uncommon%20Subsequence%20II/README_EN.md", "title_cn": "\u6700\u957f\u7279\u6b8a\u5e8f\u5217 II", "title_en": "Longest Uncommon Subsequence II", "question_title_slug": "longest-uncommon-subsequence-ii", "content_en": "

    Given an array of strings strs, return the length of the longest uncommon subsequence between them. If the longest uncommon subsequence does not exist, return -1.

    \n\n

    An uncommon subsequence between an array of strings is a string that is a subsequence of one string but not the others.

    \n\n

    A subsequence of a string s is a string that can be obtained after deleting any number of characters from s.

    \n\n
      \n\t
    • For example, "abc" is a subsequence of "aebdc" because you can delete the underlined characters in "aebdc" to get "abc". Other subsequences of "aebdc" include "aebdc", "aeb", and "" (empty string).
    • \n
    \n\n

     

    \n

    Example 1:

    \n
    Input: strs = [\"aba\",\"cdc\",\"eae\"]\nOutput: 3\n

    Example 2:

    \n
    Input: strs = [\"aaa\",\"aaa\",\"aa\"]\nOutput: -1\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= strs.length <= 50
    • \n\t
    • 1 <= strs[i].length <= 10
    • \n\t
    • strs[i] consists of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u5b57\u7b26\u4e32\u5217\u8868\uff0c\u4f60\u9700\u8981\u4ece\u5b83\u4eec\u4e2d\u627e\u51fa\u6700\u957f\u7684\u7279\u6b8a\u5e8f\u5217\u3002\u6700\u957f\u7279\u6b8a\u5e8f\u5217\u5b9a\u4e49\u5982\u4e0b\uff1a\u8be5\u5e8f\u5217\u4e3a\u67d0\u5b57\u7b26\u4e32\u72ec\u6709\u7684\u6700\u957f\u5b50\u5e8f\u5217\uff08\u5373\u4e0d\u80fd\u662f\u5176\u4ed6\u5b57\u7b26\u4e32\u7684\u5b50\u5e8f\u5217\uff09\u3002

    \n\n

    \u5b50\u5e8f\u5217\u53ef\u4ee5\u901a\u8fc7\u5220\u53bb\u5b57\u7b26\u4e32\u4e2d\u7684\u67d0\u4e9b\u5b57\u7b26\u5b9e\u73b0\uff0c\u4f46\u4e0d\u80fd\u6539\u53d8\u5269\u4f59\u5b57\u7b26\u7684\u76f8\u5bf9\u987a\u5e8f\u3002\u7a7a\u5e8f\u5217\u4e3a\u6240\u6709\u5b57\u7b26\u4e32\u7684\u5b50\u5e8f\u5217\uff0c\u4efb\u4f55\u5b57\u7b26\u4e32\u4e3a\u5176\u81ea\u8eab\u7684\u5b50\u5e8f\u5217\u3002

    \n\n

    \u8f93\u5165\u5c06\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\u5217\u8868\uff0c\u8f93\u51fa\u662f\u6700\u957f\u7279\u6b8a\u5e8f\u5217\u7684\u957f\u5ea6\u3002\u5982\u679c\u6700\u957f\u7279\u6b8a\u5e8f\u5217\u4e0d\u5b58\u5728\uff0c\u8fd4\u56de -1 \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165: "aba", "cdc", "eae"\n\u8f93\u51fa: 3\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. \u6240\u6709\u7ed9\u5b9a\u7684\u5b57\u7b26\u4e32\u957f\u5ea6\u4e0d\u4f1a\u8d85\u8fc7 10 \u3002
    2. \n\t
    3. \u7ed9\u5b9a\u5b57\u7b26\u4e32\u5217\u8868\u7684\u957f\u5ea6\u5c06\u5728 [2, 50 ] \u4e4b\u95f4\u3002
    4. \n
    \n\n

     

    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findLUSlength(vector& strs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findLUSlength(String[] strs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findLUSlength(self, strs):\n \"\"\"\n :type strs: List[str]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findLUSlength(self, strs: List[str]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findLUSlength(char ** strs, int strsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindLUSlength(string[] strs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} strs\n * @return {number}\n */\nvar findLUSlength = function(strs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} strs\n# @return {Integer}\ndef find_lu_slength(strs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findLUSlength(_ strs: [String]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findLUSlength(strs []string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findLUSlength(strs: Array[String]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findLUSlength(strs: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_lu_slength(strs: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $strs\n * @return Integer\n */\n function findLUSlength($strs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findLUSlength(strs: string[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-lu-slength strs)\n (-> (listof string?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0522](https://leetcode-cn.com/problems/longest-uncommon-subsequence-ii)", "[\u6700\u957f\u7279\u6b8a\u5e8f\u5217 II](/solution/0500-0599/0522.Longest%20Uncommon%20Subsequence%20II/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0522](https://leetcode.com/problems/longest-uncommon-subsequence-ii)", "[Longest Uncommon Subsequence II](/solution/0500-0599/0522.Longest%20Uncommon%20Subsequence%20II/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "0521", "frontend_question_id": "0521", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-uncommon-subsequence-i", "url_en": "https://leetcode.com/problems/longest-uncommon-subsequence-i", "relative_path_cn": "/solution/0500-0599/0521.Longest%20Uncommon%20Subsequence%20I/README.md", "relative_path_en": "/solution/0500-0599/0521.Longest%20Uncommon%20Subsequence%20I/README_EN.md", "title_cn": "\u6700\u957f\u7279\u6b8a\u5e8f\u5217 \u2160", "title_en": "Longest Uncommon Subsequence I", "question_title_slug": "longest-uncommon-subsequence-i", "content_en": "

    Given two strings a and b, return the length of the longest uncommon subsequence between a and b. If the longest uncommon subsequence does not exist, return -1.

    \n\n

    An uncommon subsequence between two strings is a string that is a subsequence of one but not the other.

    \n\n

    A subsequence of a string s is a string that can be obtained after deleting any number of characters from s.

    \n\n
      \n\t
    • For example, "abc" is a subsequence of "aebdc" because you can delete the underlined characters in "aebdc" to get "abc". Other subsequences of "aebdc" include "aebdc", "aeb", and "" (empty string).
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: a = "aba", b = "cdc"\nOutput: 3\nExplanation: One longest uncommon subsequence is "aba" because "aba" is a subsequence of "aba" but not "cdc".\nNote that "cdc" is also a longest uncommon subsequence.\n
    \n\n

    Example 2:

    \n\n
    \nInput: a = "aaa", b = "bbb"\nOutput: 3\nExplanation: The longest uncommon subsequences are "aaa" and "bbb".\n
    \n\n

    Example 3:

    \n\n
    \nInput: a = "aaa", b = "aaa"\nOutput: -1\nExplanation: Every subsequence of string a is also a subsequence of string b. Similarly, every subsequence of string b is also a subsequence of string a.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= a.length, b.length <= 100
    • \n\t
    • a and b consist of lower-case English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u5b57\u7b26\u4e32\uff0c\u8bf7\u4f60\u4ece\u8fd9\u4e24\u4e2a\u5b57\u7b26\u4e32\u4e2d\u627e\u51fa\u6700\u957f\u7684\u7279\u6b8a\u5e8f\u5217\u3002

    \n\n

    \u300c\u6700\u957f\u7279\u6b8a\u5e8f\u5217\u300d\u5b9a\u4e49\u5982\u4e0b\uff1a\u8be5\u5e8f\u5217\u4e3a\u67d0\u5b57\u7b26\u4e32\u72ec\u6709\u7684\u6700\u957f\u5b50\u5e8f\u5217\uff08\u5373\u4e0d\u80fd\u662f\u5176\u4ed6\u5b57\u7b26\u4e32\u7684\u5b50\u5e8f\u5217\uff09\u3002

    \n\n

    \u5b50\u5e8f\u5217 \u53ef\u4ee5\u901a\u8fc7\u5220\u53bb\u5b57\u7b26\u4e32\u4e2d\u7684\u67d0\u4e9b\u5b57\u7b26\u5b9e\u73b0\uff0c\u4f46\u4e0d\u80fd\u6539\u53d8\u5269\u4f59\u5b57\u7b26\u7684\u76f8\u5bf9\u987a\u5e8f\u3002\u7a7a\u5e8f\u5217\u4e3a\u6240\u6709\u5b57\u7b26\u4e32\u7684\u5b50\u5e8f\u5217\uff0c\u4efb\u4f55\u5b57\u7b26\u4e32\u4e3a\u5176\u81ea\u8eab\u7684\u5b50\u5e8f\u5217\u3002

    \n\n

    \u8f93\u5165\u4e3a\u4e24\u4e2a\u5b57\u7b26\u4e32\uff0c\u8f93\u51fa\u6700\u957f\u7279\u6b8a\u5e8f\u5217\u7684\u957f\u5ea6\u3002\u5982\u679c\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de -1\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165: "aba", "cdc"\n\u8f93\u51fa: 3\n\u89e3\u91ca: \u6700\u957f\u7279\u6b8a\u5e8f\u5217\u53ef\u4e3a "aba" (\u6216 "cdc")\uff0c\u4e24\u8005\u5747\u4e3a\u81ea\u8eab\u7684\u5b50\u5e8f\u5217\u4e14\u4e0d\u662f\u5bf9\u65b9\u7684\u5b50\u5e8f\u5217\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aa = "aaa", b = "bbb"\n\u8f93\u51fa\uff1a3\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aa = "aaa", b = "aaa"\n\u8f93\u51fa\uff1a-1\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. \u4e24\u4e2a\u5b57\u7b26\u4e32\u957f\u5ea6\u5747\u5904\u4e8e\u533a\u95f4 [1 - 100] \u3002
    2. \n\t
    3. \u5b57\u7b26\u4e32\u4e2d\u7684\u5b57\u7b26\u4ec5\u542b\u6709 'a'~'z' \u3002
    4. \n
    \n", "tags_en": ["Brainteaser", "String"], "tags_cn": ["\u8111\u7b4b\u6025\u8f6c\u5f2f", "\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findLUSlength(string a, string b) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findLUSlength(String a, String b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findLUSlength(self, a, b):\n \"\"\"\n :type a: str\n :type b: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findLUSlength(self, a: str, b: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findLUSlength(char * a, char * b){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindLUSlength(string a, string b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} a\n * @param {string} b\n * @return {number}\n */\nvar findLUSlength = function(a, b) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} a\n# @param {String} b\n# @return {Integer}\ndef find_lu_slength(a, b)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findLUSlength(_ a: String, _ b: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findLUSlength(a string, b string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findLUSlength(a: String, b: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findLUSlength(a: String, b: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_lu_slength(a: String, b: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $a\n * @param String $b\n * @return Integer\n */\n function findLUSlength($a, $b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findLUSlength(a: string, b: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-lu-slength a b)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0521](https://leetcode-cn.com/problems/longest-uncommon-subsequence-i)", "[\u6700\u957f\u7279\u6b8a\u5e8f\u5217 \u2160](/solution/0500-0599/0521.Longest%20Uncommon%20Subsequence%20I/README.md)", "`\u8111\u7b4b\u6025\u8f6c\u5f2f`,`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0521](https://leetcode.com/problems/longest-uncommon-subsequence-i)", "[Longest Uncommon Subsequence I](/solution/0500-0599/0521.Longest%20Uncommon%20Subsequence%20I/README_EN.md)", "`Brainteaser`,`String`", "Easy", ""]}, {"question_id": "0520", "frontend_question_id": "0520", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/detect-capital", "url_en": "https://leetcode.com/problems/detect-capital", "relative_path_cn": "/solution/0500-0599/0520.Detect%20Capital/README.md", "relative_path_en": "/solution/0500-0599/0520.Detect%20Capital/README_EN.md", "title_cn": "\u68c0\u6d4b\u5927\u5199\u5b57\u6bcd", "title_en": "Detect Capital", "question_title_slug": "detect-capital", "content_en": "

    We define the usage of capitals in a word to be right when one of the following cases holds:

    \n\n
      \n\t
    • All letters in this word are capitals, like "USA".
    • \n\t
    • All letters in this word are not capitals, like "leetcode".
    • \n\t
    • Only the first letter in this word is capital, like "Google".
    • \n
    \n\n

    Given a string word, return true if the usage of capitals in it is right.

    \n\n

     

    \n

    Example 1:

    \n
    Input: word = \"USA\"\nOutput: true\n

    Example 2:

    \n
    Input: word = \"FlaG\"\nOutput: false\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= word.length <= 100
    • \n\t
    • word consists of lowercase and uppercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5355\u8bcd\uff0c\u4f60\u9700\u8981\u5224\u65ad\u5355\u8bcd\u7684\u5927\u5199\u4f7f\u7528\u662f\u5426\u6b63\u786e\u3002

    \n\n

    \u6211\u4eec\u5b9a\u4e49\uff0c\u5728\u4ee5\u4e0b\u60c5\u51b5\u65f6\uff0c\u5355\u8bcd\u7684\u5927\u5199\u7528\u6cd5\u662f\u6b63\u786e\u7684\uff1a

    \n\n
      \n\t
    1. \u5168\u90e8\u5b57\u6bcd\u90fd\u662f\u5927\u5199\uff0c\u6bd4\u5982"USA"\u3002
    2. \n\t
    3. \u5355\u8bcd\u4e2d\u6240\u6709\u5b57\u6bcd\u90fd\u4e0d\u662f\u5927\u5199\uff0c\u6bd4\u5982"leetcode"\u3002
    4. \n\t
    5. \u5982\u679c\u5355\u8bcd\u4e0d\u53ea\u542b\u6709\u4e00\u4e2a\u5b57\u6bcd\uff0c\u53ea\u6709\u9996\u5b57\u6bcd\u5927\u5199\uff0c \u6bd4\u5982 "Google"\u3002
    6. \n
    \n\n

    \u5426\u5219\uff0c\u6211\u4eec\u5b9a\u4e49\u8fd9\u4e2a\u5355\u8bcd\u6ca1\u6709\u6b63\u786e\u4f7f\u7528\u5927\u5199\u5b57\u6bcd\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: "USA"\n\u8f93\u51fa: True\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: "FlaG"\n\u8f93\u51fa: False\n
    \n\n

    \u6ce8\u610f: \u8f93\u5165\u662f\u7531\u5927\u5199\u548c\u5c0f\u5199\u62c9\u4e01\u5b57\u6bcd\u7ec4\u6210\u7684\u975e\u7a7a\u5355\u8bcd\u3002

    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool detectCapitalUse(string word) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean detectCapitalUse(String word) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def detectCapitalUse(self, word):\n \"\"\"\n :type word: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def detectCapitalUse(self, word: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool detectCapitalUse(char * word){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool DetectCapitalUse(string word) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} word\n * @return {boolean}\n */\nvar detectCapitalUse = function(word) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} word\n# @return {Boolean}\ndef detect_capital_use(word)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func detectCapitalUse(_ word: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func detectCapitalUse(word string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def detectCapitalUse(word: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun detectCapitalUse(word: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn detect_capital_use(word: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $word\n * @return Boolean\n */\n function detectCapitalUse($word) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function detectCapitalUse(word: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (detect-capital-use word)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0520](https://leetcode-cn.com/problems/detect-capital)", "[\u68c0\u6d4b\u5927\u5199\u5b57\u6bcd](/solution/0500-0599/0520.Detect%20Capital/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0520](https://leetcode.com/problems/detect-capital)", "[Detect Capital](/solution/0500-0599/0520.Detect%20Capital/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "0518", "frontend_question_id": "0518", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/coin-change-2", "url_en": "https://leetcode.com/problems/coin-change-2", "relative_path_cn": "/solution/0500-0599/0518.Coin%20Change%202/README.md", "relative_path_en": "/solution/0500-0599/0518.Coin%20Change%202/README_EN.md", "title_cn": "\u96f6\u94b1\u5151\u6362 II", "title_en": "Coin Change 2", "question_title_slug": "coin-change-2", "content_en": "

    You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money.

    \n\n

    Return the number of combinations that make up that amount. If that amount of money cannot be made up by any combination of the coins, return 0.

    \n\n

    You may assume that you have an infinite number of each kind of coin.

    \n\n

    The answer is guaranteed to fit into a signed 32-bit integer.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: amount = 5, coins = [1,2,5]\nOutput: 4\nExplanation: there are four ways to make up the amount:\n5=5\n5=2+2+1\n5=2+1+1+1\n5=1+1+1+1+1\n
    \n\n

    Example 2:

    \n\n
    \nInput: amount = 3, coins = [2]\nOutput: 0\nExplanation: the amount of 3 cannot be made up just with coins of 2.\n
    \n\n

    Example 3:

    \n\n
    \nInput: amount = 10, coins = [10]\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= coins.length <= 300
    • \n\t
    • 1 <= coins[i] <= 5000
    • \n\t
    • All the values of coins are unique.
    • \n\t
    • 0 <= amount <= 5000
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e0d\u540c\u9762\u989d\u7684\u786c\u5e01\u548c\u4e00\u4e2a\u603b\u91d1\u989d\u3002\u5199\u51fa\u51fd\u6570\u6765\u8ba1\u7b97\u53ef\u4ee5\u51d1\u6210\u603b\u91d1\u989d\u7684\u786c\u5e01\u7ec4\u5408\u6570\u3002\u5047\u8bbe\u6bcf\u4e00\u79cd\u9762\u989d\u7684\u786c\u5e01\u6709\u65e0\u9650\u4e2a\u3002 

    \n\n

     

    \n\n
      \n
    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: amount = 5, coins = [1, 2, 5]\n\u8f93\u51fa: 4\n\u89e3\u91ca: \u6709\u56db\u79cd\u65b9\u5f0f\u53ef\u4ee5\u51d1\u6210\u603b\u91d1\u989d:\n5=5\n5=2+2+1\n5=2+1+1+1\n5=1+1+1+1+1\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: amount = 3, coins = [2]\n\u8f93\u51fa: 0\n\u89e3\u91ca: \u53ea\u7528\u9762\u989d2\u7684\u786c\u5e01\u4e0d\u80fd\u51d1\u6210\u603b\u91d1\u989d3\u3002\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u8f93\u5165: amount = 10, coins = [10] \n\u8f93\u51fa: 1\n
    \n\n

     

    \n\n

    \u6ce8\u610f:

    \n\n

    \u4f60\u53ef\u4ee5\u5047\u8bbe\uff1a

    \n\n
      \n\t
    • 0 <= amount (\u603b\u91d1\u989d) <= 5000
    • \n\t
    • 1 <= coin (\u786c\u5e01\u9762\u989d) <= 5000
    • \n\t
    • \u786c\u5e01\u79cd\u7c7b\u4e0d\u8d85\u8fc7 500 \u79cd
    • \n\t
    • \u7ed3\u679c\u7b26\u5408 32 \u4f4d\u7b26\u53f7\u6574\u6570
    • \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int change(int amount, vector& coins) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int change(int amount, int[] coins) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def change(self, amount, coins):\n \"\"\"\n :type amount: int\n :type coins: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def change(self, amount: int, coins: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint change(int amount, int* coins, int coinsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int Change(int amount, int[] coins) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} amount\n * @param {number[]} coins\n * @return {number}\n */\nvar change = function(amount, coins) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} amount\n# @param {Integer[]} coins\n# @return {Integer}\ndef change(amount, coins)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func change(_ amount: Int, _ coins: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func change(amount int, coins []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def change(amount: Int, coins: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun change(amount: Int, coins: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn change(amount: i32, coins: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $amount\n * @param Integer[] $coins\n * @return Integer\n */\n function change($amount, $coins) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function change(amount: number, coins: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (change amount coins)\n (-> exact-integer? (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0518](https://leetcode-cn.com/problems/coin-change-2)", "[\u96f6\u94b1\u5151\u6362 II](/solution/0500-0599/0518.Coin%20Change%202/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0518](https://leetcode.com/problems/coin-change-2)", "[Coin Change 2](/solution/0500-0599/0518.Coin%20Change%202/README_EN.md)", "", "Medium", ""]}, {"question_id": "0517", "frontend_question_id": "0517", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/super-washing-machines", "url_en": "https://leetcode.com/problems/super-washing-machines", "relative_path_cn": "/solution/0500-0599/0517.Super%20Washing%20Machines/README.md", "relative_path_en": "/solution/0500-0599/0517.Super%20Washing%20Machines/README_EN.md", "title_cn": "\u8d85\u7ea7\u6d17\u8863\u673a", "title_en": "Super Washing Machines", "question_title_slug": "super-washing-machines", "content_en": "

    You have n super washing machines on a line. Initially, each washing machine has some dresses or is empty.

    \n\n

    For each move, you could choose any m (1 <= m <= n) washing machines, and pass one dress of each washing machine to one of its adjacent washing machines at the same time.

    \n\n

    Given an integer array machines representing the number of dresses in each washing machine from left to right on the line, return the minimum number of moves to make all the washing machines have the same number of dresses. If it is not possible to do it, return -1.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: machines = [1,0,5]\nOutput: 3\nExplanation:\n1st move:    1     0 <-- 5    =>    1     1     4\n2nd move:    1 <-- 1 <-- 4    =>    2     1     3\n3rd move:    2     1 <-- 3    =>    2     2     2\n
    \n\n

    Example 2:

    \n\n
    \nInput: machines = [0,3,0]\nOutput: 2\nExplanation:\n1st move:    0 <-- 3     0    =>    1     2     0\n2nd move:    1     2 --> 0    =>    1     1     1\n
    \n\n

    Example 3:

    \n\n
    \nInput: machines = [0,2,0]\nOutput: -1\nExplanation:\nIt's impossible to make all three washing machines have the same number of dresses.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == machines.length
    • \n\t
    • 1 <= n <= 104
    • \n\t
    • 0 <= machines[i] <= 105
    • \n
    \n", "content_cn": "

    \u5047\u8bbe\u6709 \u53f0\u8d85\u7ea7\u6d17\u8863\u673a\u653e\u5728\u540c\u4e00\u6392\u4e0a\u3002\u5f00\u59cb\u7684\u65f6\u5019\uff0c\u6bcf\u53f0\u6d17\u8863\u673a\u5185\u53ef\u80fd\u6709\u4e00\u5b9a\u91cf\u7684\u8863\u670d\uff0c\u4e5f\u53ef\u80fd\u662f\u7a7a\u7684\u3002

    \n\n

    \u5728\u6bcf\u4e00\u6b65\u64cd\u4f5c\u4e2d\uff0c\u4f60\u53ef\u4ee5\u9009\u62e9\u4efb\u610f m \uff081 ≤ m ≤ n\uff09 \u53f0\u6d17\u8863\u673a\uff0c\u4e0e\u6b64\u540c\u65f6\u5c06\u6bcf\u53f0\u6d17\u8863\u673a\u7684\u4e00\u4ef6\u8863\u670d\u9001\u5230\u76f8\u90bb\u7684\u4e00\u53f0\u6d17\u8863\u673a\u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\u6570\u7ec4\u4ee3\u8868\u4ece\u5de6\u81f3\u53f3\u6bcf\u53f0\u6d17\u8863\u673a\u4e2d\u7684\u8863\u7269\u6570\u91cf\uff0c\u8bf7\u7ed9\u51fa\u80fd\u8ba9\u6240\u6709\u6d17\u8863\u673a\u4e2d\u5269\u4e0b\u7684\u8863\u7269\u7684\u6570\u91cf\u76f8\u7b49\u7684\u6700\u5c11\u7684\u64cd\u4f5c\u6b65\u6570\u3002\u5982\u679c\u4e0d\u80fd\u4f7f\u6bcf\u53f0\u6d17\u8863\u673a\u4e2d\u8863\u7269\u7684\u6570\u91cf\u76f8\u7b49\uff0c\u5219\u8fd4\u56de -1\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165: [1,0,5]\n\n\u8f93\u51fa: 3\n\n\u89e3\u91ca: \n\u7b2c\u4e00\u6b65:    1     0 <-- 5    =>    1     1     4\n\u7b2c\u4e8c\u6b65:    1 <-- 1 <-- 4    =>    2     1     3    \n\u7b2c\u4e09\u6b65:    2     1 <-- 3    =>    2     2     2   \n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165: [0,3,0]\n\n\u8f93\u51fa: 2\n\n\u89e3\u91ca: \n\u7b2c\u4e00\u6b65:    0 <-- 3     0    =>    1     2     0    \n\u7b2c\u4e8c\u6b65:    1     2 --> 0    =>    1     1     1     \n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u8f93\u5165: [0,2,0]\n\n\u8f93\u51fa: -1\n\n\u89e3\u91ca: \n\u4e0d\u53ef\u80fd\u8ba9\u6240\u6709\u4e09\u4e2a\u6d17\u8863\u673a\u540c\u65f6\u5269\u4e0b\u76f8\u540c\u6570\u91cf\u7684\u8863\u7269\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. n \u7684\u8303\u56f4\u662f [1, 10000]\u3002
    2. \n\t
    3. \u5728\u6bcf\u53f0\u8d85\u7ea7\u6d17\u8863\u673a\u4e2d\uff0c\u8863\u7269\u6570\u91cf\u7684\u8303\u56f4\u662f [0, 1e5]\u3002
    4. \n
    \n\n

     

    \n", "tags_en": ["Math", "Dynamic Programming"], "tags_cn": ["\u6570\u5b66", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findMinMoves(vector& machines) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findMinMoves(int[] machines) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findMinMoves(self, machines):\n \"\"\"\n :type machines: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findMinMoves(self, machines: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findMinMoves(int* machines, int machinesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindMinMoves(int[] machines) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} machines\n * @return {number}\n */\nvar findMinMoves = function(machines) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} machines\n# @return {Integer}\ndef find_min_moves(machines)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findMinMoves(_ machines: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findMinMoves(machines []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findMinMoves(machines: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findMinMoves(machines: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_min_moves(machines: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $machines\n * @return Integer\n */\n function findMinMoves($machines) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findMinMoves(machines: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-min-moves machines)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0517](https://leetcode-cn.com/problems/super-washing-machines)", "[\u8d85\u7ea7\u6d17\u8863\u673a](/solution/0500-0599/0517.Super%20Washing%20Machines/README.md)", "`\u6570\u5b66`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0517](https://leetcode.com/problems/super-washing-machines)", "[Super Washing Machines](/solution/0500-0599/0517.Super%20Washing%20Machines/README_EN.md)", "`Math`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0516", "frontend_question_id": "0516", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-palindromic-subsequence", "url_en": "https://leetcode.com/problems/longest-palindromic-subsequence", "relative_path_cn": "/solution/0500-0599/0516.Longest%20Palindromic%20Subsequence/README.md", "relative_path_en": "/solution/0500-0599/0516.Longest%20Palindromic%20Subsequence/README_EN.md", "title_cn": "\u6700\u957f\u56de\u6587\u5b50\u5e8f\u5217", "title_en": "Longest Palindromic Subsequence", "question_title_slug": "longest-palindromic-subsequence", "content_en": "

    Given a string s, find the longest palindromic subsequence's length in s.

    \n\n

    A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "bbbab"\nOutput: 4\nExplanation: One possible longest palindromic subsequence is "bbbb".\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "cbbd"\nOutput: 2\nExplanation: One possible longest palindromic subsequence is "bb".\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 1000
    • \n\t
    • s consists only of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32 s \uff0c\u627e\u5230\u5176\u4e2d\u6700\u957f\u7684\u56de\u6587\u5b50\u5e8f\u5217\uff0c\u5e76\u8fd4\u56de\u8be5\u5e8f\u5217\u7684\u957f\u5ea6\u3002\u53ef\u4ee5\u5047\u8bbe s \u7684\u6700\u5927\u957f\u5ea6\u4e3a 1000 \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1:
    \n\u8f93\u5165:

    \n\n
    "bbbab"\n
    \n\n

    \u8f93\u51fa:

    \n\n
    4\n
    \n\n

    \u4e00\u4e2a\u53ef\u80fd\u7684\u6700\u957f\u56de\u6587\u5b50\u5e8f\u5217\u4e3a "bbbb"\u3002

    \n\n

    \u793a\u4f8b 2:
    \n\u8f93\u5165:

    \n\n
    "cbbd"\n
    \n\n

    \u8f93\u51fa:

    \n\n
    2\n
    \n\n

    \u4e00\u4e2a\u53ef\u80fd\u7684\u6700\u957f\u56de\u6587\u5b50\u5e8f\u5217\u4e3a "bb"\u3002

    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 1000
    • \n\t
    • s \u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int longestPalindromeSubseq(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int longestPalindromeSubseq(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestPalindromeSubseq(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestPalindromeSubseq(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint longestPalindromeSubseq(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LongestPalindromeSubseq(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar longestPalindromeSubseq = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef longest_palindrome_subseq(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestPalindromeSubseq(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestPalindromeSubseq(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestPalindromeSubseq(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestPalindromeSubseq(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_palindrome_subseq(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function longestPalindromeSubseq($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestPalindromeSubseq(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-palindrome-subseq s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0516](https://leetcode-cn.com/problems/longest-palindromic-subsequence)", "[\u6700\u957f\u56de\u6587\u5b50\u5e8f\u5217](/solution/0500-0599/0516.Longest%20Palindromic%20Subsequence/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0516](https://leetcode.com/problems/longest-palindromic-subsequence)", "[Longest Palindromic Subsequence](/solution/0500-0599/0516.Longest%20Palindromic%20Subsequence/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0515", "frontend_question_id": "0515", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-largest-value-in-each-tree-row", "url_en": "https://leetcode.com/problems/find-largest-value-in-each-tree-row", "relative_path_cn": "/solution/0500-0599/0515.Find%20Largest%20Value%20in%20Each%20Tree%20Row/README.md", "relative_path_en": "/solution/0500-0599/0515.Find%20Largest%20Value%20in%20Each%20Tree%20Row/README_EN.md", "title_cn": "\u5728\u6bcf\u4e2a\u6811\u884c\u4e2d\u627e\u6700\u5927\u503c", "title_en": "Find Largest Value in Each Tree Row", "question_title_slug": "find-largest-value-in-each-tree-row", "content_en": "

    Given the root of a binary tree, return an array of the largest value in each row of the tree (0-indexed).

    \n\n

     

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,3,2,5,3,null,9]\nOutput: [1,3,9]\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = [1,2,3]\nOutput: [1,3]\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = [1]\nOutput: [1]\n
    \n\n

    Example 4:

    \n\n
    \nInput: root = [1,null,2]\nOutput: [1,2]\n
    \n\n

    Example 5:

    \n\n
    \nInput: root = []\nOutput: []\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree will be in the range [0, 104].
    • \n\t
    • -231 <= Node.val <= 231 - 1
    • \n
    \n", "content_cn": "

    \u60a8\u9700\u8981\u5728\u4e8c\u53c9\u6811\u7684\u6bcf\u4e00\u884c\u4e2d\u627e\u5230\u6700\u5927\u7684\u503c\u3002

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165: \n\n          1\n         / \\\n        3   2\n       / \\   \\  \n      5   3   9 \n\n\u8f93\u51fa: [1, 3, 9]\n
    \n", "tags_en": ["Tree", "Depth-first Search", "Breadth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector largestValues(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public List largestValues(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def largestValues(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def largestValues(self, root: TreeNode) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* largestValues(struct TreeNode* root, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public IList LargestValues(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number[]}\n */\nvar largestValues = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer[]}\ndef largest_values(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func largestValues(_ root: TreeNode?) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc largestValues(root *TreeNode) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def largestValues(root: TreeNode): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun largestValues(root: TreeNode?): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn largest_values(root: Option>>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer[]\n */\n function largestValues($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction largestValues(root: TreeNode | null): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (largest-values root)\n (-> (or/c tree-node? #f) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0515](https://leetcode-cn.com/problems/find-largest-value-in-each-tree-row)", "[\u5728\u6bcf\u4e2a\u6811\u884c\u4e2d\u627e\u6700\u5927\u503c](/solution/0500-0599/0515.Find%20Largest%20Value%20in%20Each%20Tree%20Row/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0515](https://leetcode.com/problems/find-largest-value-in-each-tree-row)", "[Find Largest Value in Each Tree Row](/solution/0500-0599/0515.Find%20Largest%20Value%20in%20Each%20Tree%20Row/README_EN.md)", "`Tree`,`Depth-first Search`,`Breadth-first Search`", "Medium", ""]}, {"question_id": "0514", "frontend_question_id": "0514", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/freedom-trail", "url_en": "https://leetcode.com/problems/freedom-trail", "relative_path_cn": "/solution/0500-0599/0514.Freedom%20Trail/README.md", "relative_path_en": "/solution/0500-0599/0514.Freedom%20Trail/README_EN.md", "title_cn": "\u81ea\u7531\u4e4b\u8def", "title_en": "Freedom Trail", "question_title_slug": "freedom-trail", "content_en": "

    In the video game Fallout 4, the quest "Road to Freedom" requires players to reach a metal dial called the "Freedom Trail Ring" and use the dial to spell a specific keyword to open the door.

    \n\n

    Given a string ring that represents the code engraved on the outer ring and another string key that represents the keyword that needs to be spelled, return the minimum number of steps to spell all the characters in the keyword.

    \n\n

    Initially, the first character of the ring is aligned at the "12:00" direction. You should spell all the characters in key one by one by rotating ring clockwise or anticlockwise to make each character of the string key aligned at the "12:00" direction and then by pressing the center button.

    \n\n

    At the stage of rotating the ring to spell the key character key[i]:

    \n\n
      \n\t
    1. You can rotate the ring clockwise or anticlockwise by one place, which counts as one step. The final purpose of the rotation is to align one of ring's characters at the "12:00" direction, where this character must equal key[i].
    2. \n\t
    3. If the character key[i] has been aligned at the "12:00" direction, press the center button to spell, which also counts as one step. After the pressing, you could begin to spell the next character in the key (next stage). Otherwise, you have finished all the spelling.
    4. \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: ring = "godding", key = "gd"\nOutput: 4\nExplanation:\nFor the first key character 'g', since it is already in place, we just need 1 step to spell this character. \nFor the second key character 'd', we need to rotate the ring "godding" anticlockwise by two steps to make it become "ddinggo".\nAlso, we need 1 more step for spelling.\nSo the final output is 4.\n
    \n\n

    Example 2:

    \n\n
    \nInput: ring = "godding", key = "godding"\nOutput: 13\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= ring.length, key.length <= 100
    • \n\t
    • ring and key consist of only lower case English letters.
    • \n\t
    • It is guaranteed that key could always be spelled by rotating ring.
    • \n
    \n", "content_cn": "

    \u7535\u5b50\u6e38\u620f\u201c\u8f90\u5c044\u201d\u4e2d\uff0c\u4efb\u52a1\u201c\u901a\u5411\u81ea\u7531\u201d\u8981\u6c42\u73a9\u5bb6\u5230\u8fbe\u540d\u4e3a\u201cFreedom Trail Ring\u201d\u7684\u91d1\u5c5e\u8868\u76d8\uff0c\u5e76\u4f7f\u7528\u8868\u76d8\u62fc\u5199\u7279\u5b9a\u5173\u952e\u8bcd\u624d\u80fd\u5f00\u95e8\u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\u00a0ring\uff0c\u8868\u793a\u523b\u5728\u5916\u73af\u4e0a\u7684\u7f16\u7801\uff1b\u7ed9\u5b9a\u53e6\u4e00\u4e2a\u5b57\u7b26\u4e32\u00a0key\uff0c\u8868\u793a\u9700\u8981\u62fc\u5199\u7684\u5173\u952e\u8bcd\u3002\u60a8\u9700\u8981\u7b97\u51fa\u80fd\u591f\u62fc\u5199\u5173\u952e\u8bcd\u4e2d\u6240\u6709\u5b57\u7b26\u7684\u6700\u5c11\u6b65\u6570\u3002

    \n\n

    \u6700\u521d\uff0cring\u00a0\u7684\u7b2c\u4e00\u4e2a\u5b57\u7b26\u4e0e12:00\u65b9\u5411\u5bf9\u9f50\u3002\u60a8\u9700\u8981\u987a\u65f6\u9488\u6216\u9006\u65f6\u9488\u65cb\u8f6c ring \u4ee5\u4f7f\u00a0key\u00a0\u7684\u4e00\u4e2a\u5b57\u7b26\u5728 12:00 \u65b9\u5411\u5bf9\u9f50\uff0c\u7136\u540e\u6309\u4e0b\u4e2d\u5fc3\u6309\u94ae\uff0c\u4ee5\u6b64\u9010\u4e2a\u62fc\u5199\u5b8c\u00a0key\u00a0\u4e2d\u7684\u6240\u6709\u5b57\u7b26\u3002

    \n\n

    \u65cb\u8f6c\u00a0ring\u00a0\u62fc\u51fa key \u5b57\u7b26\u00a0key[i]\u00a0\u7684\u9636\u6bb5\u4e2d\uff1a

    \n\n
      \n\t
    1. \u60a8\u53ef\u4ee5\u5c06\u00a0ring\u00a0\u987a\u65f6\u9488\u6216\u9006\u65f6\u9488\u65cb\u8f6c\u4e00\u4e2a\u4f4d\u7f6e\uff0c\u8ba1\u4e3a1\u6b65\u3002\u65cb\u8f6c\u7684\u6700\u7ec8\u76ee\u7684\u662f\u5c06\u5b57\u7b26\u4e32\u00a0ring\u00a0\u7684\u4e00\u4e2a\u5b57\u7b26\u4e0e 12:00 \u65b9\u5411\u5bf9\u9f50\uff0c\u5e76\u4e14\u8fd9\u4e2a\u5b57\u7b26\u5fc5\u987b\u7b49\u4e8e\u5b57\u7b26\u00a0key[i] \u3002
    2. \n\t
    3. \u5982\u679c\u5b57\u7b26\u00a0key[i]\u00a0\u5df2\u7ecf\u5bf9\u9f50\u523012:00\u65b9\u5411\uff0c\u60a8\u9700\u8981\u6309\u4e0b\u4e2d\u5fc3\u6309\u94ae\u8fdb\u884c\u62fc\u5199\uff0c\u8fd9\u4e5f\u5c06\u7b97\u4f5c\u00a01 \u6b65\u3002\u6309\u5b8c\u4e4b\u540e\uff0c\u60a8\u53ef\u4ee5\u5f00\u59cb\u62fc\u5199\u00a0key\u00a0\u7684\u4e0b\u4e00\u4e2a\u5b57\u7b26\uff08\u4e0b\u4e00\u9636\u6bb5\uff09, \u76f4\u81f3\u5b8c\u6210\u6240\u6709\u62fc\u5199\u3002
    4. \n
    \n\n

    \u793a\u4f8b\uff1a

    \n\n

    \u00a0

    \n\n
    \n\u00a0\n\n
    \n\u8f93\u5165: ring = \"godding\", key = \"gd\"\n\u8f93\u51fa: 4\n\u89e3\u91ca:\n \u5bf9\u4e8e key \u7684\u7b2c\u4e00\u4e2a\u5b57\u7b26 'g'\uff0c\u5df2\u7ecf\u5728\u6b63\u786e\u7684\u4f4d\u7f6e, \u6211\u4eec\u53ea\u9700\u89811\u6b65\u6765\u62fc\u5199\u8fd9\u4e2a\u5b57\u7b26\u3002 \n \u5bf9\u4e8e key \u7684\u7b2c\u4e8c\u4e2a\u5b57\u7b26 'd'\uff0c\u6211\u4eec\u9700\u8981\u9006\u65f6\u9488\u65cb\u8f6c ring \"godding\" 2\u6b65\u4f7f\u5b83\u53d8\u6210 \"ddinggo\"\u3002\n \u5f53\u7136, \u6211\u4eec\u8fd8\u9700\u89811\u6b65\u8fdb\u884c\u62fc\u5199\u3002\n \u56e0\u6b64\u6700\u7ec8\u7684\u8f93\u51fa\u662f 4\u3002\n
    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. ring \u548c\u00a0key\u00a0\u7684\u5b57\u7b26\u4e32\u957f\u5ea6\u53d6\u503c\u8303\u56f4\u5747\u4e3a\u00a01 \u81f3\u00a0100\uff1b
    2. \n\t
    3. \u4e24\u4e2a\u5b57\u7b26\u4e32\u4e2d\u90fd\u53ea\u6709\u5c0f\u5199\u5b57\u7b26\uff0c\u5e76\u4e14\u5747\u53ef\u80fd\u5b58\u5728\u91cd\u590d\u5b57\u7b26\uff1b
    4. \n\t
    5. \u5b57\u7b26\u4e32\u00a0key\u00a0\u4e00\u5b9a\u53ef\u4ee5\u7531\u5b57\u7b26\u4e32 ring\u00a0\u65cb\u8f6c\u62fc\u51fa\u3002
    6. \n
    \n", "tags_en": ["Depth-first Search", "Divide and Conquer", "Dynamic Programming"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5206\u6cbb\u7b97\u6cd5", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findRotateSteps(string ring, string key) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findRotateSteps(String ring, String key) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findRotateSteps(self, ring, key):\n \"\"\"\n :type ring: str\n :type key: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findRotateSteps(self, ring: str, key: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findRotateSteps(char * ring, char * key){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindRotateSteps(string ring, string key) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} ring\n * @param {string} key\n * @return {number}\n */\nvar findRotateSteps = function(ring, key) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} ring\n# @param {String} key\n# @return {Integer}\ndef find_rotate_steps(ring, key)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findRotateSteps(_ ring: String, _ key: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findRotateSteps(ring string, key string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findRotateSteps(ring: String, key: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findRotateSteps(ring: String, key: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_rotate_steps(ring: String, key: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $ring\n * @param String $key\n * @return Integer\n */\n function findRotateSteps($ring, $key) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findRotateSteps(ring: string, key: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-rotate-steps ring key)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0514](https://leetcode-cn.com/problems/freedom-trail)", "[\u81ea\u7531\u4e4b\u8def](/solution/0500-0599/0514.Freedom%20Trail/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5206\u6cbb\u7b97\u6cd5`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0514](https://leetcode.com/problems/freedom-trail)", "[Freedom Trail](/solution/0500-0599/0514.Freedom%20Trail/README_EN.md)", "`Depth-first Search`,`Divide and Conquer`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0513", "frontend_question_id": "0513", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-bottom-left-tree-value", "url_en": "https://leetcode.com/problems/find-bottom-left-tree-value", "relative_path_cn": "/solution/0500-0599/0513.Find%20Bottom%20Left%20Tree%20Value/README.md", "relative_path_en": "/solution/0500-0599/0513.Find%20Bottom%20Left%20Tree%20Value/README_EN.md", "title_cn": "\u627e\u6811\u5de6\u4e0b\u89d2\u7684\u503c", "title_en": "Find Bottom Left Tree Value", "question_title_slug": "find-bottom-left-tree-value", "content_en": "

    Given the root of a binary tree, return the leftmost value in the last row of the tree.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [2,1,3]\nOutput: 1\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [1,2,3,4,null,5,6,null,null,7]\nOutput: 7\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 104].
    • \n\t
    • -231 <= Node.val <= 231 - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811\uff0c\u5728\u6811\u7684\u6700\u540e\u4e00\u884c\u627e\u5230\u6700\u5de6\u8fb9\u7684\u503c\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165:\n\n    2\n   / \\\n  1   3\n\n\u8f93\u51fa:\n1\n
    \n\n

     

    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165:\n\n        1\n       / \\\n      2   3\n     /   / \\\n    4   5   6\n       /\n      7\n\n\u8f93\u51fa:\n7\n
    \n\n

     

    \n\n

    \u6ce8\u610f: \u60a8\u53ef\u4ee5\u5047\u8bbe\u6811\uff08\u5373\u7ed9\u5b9a\u7684\u6839\u8282\u70b9\uff09\u4e0d\u4e3a NULL\u3002

    \n", "tags_en": ["Tree", "Depth-first Search", "Breadth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int findBottomLeftValue(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int findBottomLeftValue(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def findBottomLeftValue(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def findBottomLeftValue(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint findBottomLeftValue(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int FindBottomLeftValue(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar findBottomLeftValue = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef find_bottom_left_value(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func findBottomLeftValue(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc findBottomLeftValue(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def findBottomLeftValue(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun findBottomLeftValue(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn find_bottom_left_value(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function findBottomLeftValue($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction findBottomLeftValue(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (find-bottom-left-value root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0513](https://leetcode-cn.com/problems/find-bottom-left-tree-value)", "[\u627e\u6811\u5de6\u4e0b\u89d2\u7684\u503c](/solution/0500-0599/0513.Find%20Bottom%20Left%20Tree%20Value/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0513](https://leetcode.com/problems/find-bottom-left-tree-value)", "[Find Bottom Left Tree Value](/solution/0500-0599/0513.Find%20Bottom%20Left%20Tree%20Value/README_EN.md)", "`Tree`,`Depth-first Search`,`Breadth-first Search`", "Medium", ""]}, {"question_id": "0511", "frontend_question_id": "1059", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/all-paths-from-source-lead-to-destination", "url_en": "https://leetcode.com/problems/all-paths-from-source-lead-to-destination", "relative_path_cn": "/solution/1000-1099/1059.All%20Paths%20from%20Source%20Lead%20to%20Destination/README.md", "relative_path_en": "/solution/1000-1099/1059.All%20Paths%20from%20Source%20Lead%20to%20Destination/README_EN.md", "title_cn": "\u4ece\u59cb\u70b9\u5230\u7ec8\u70b9\u7684\u6240\u6709\u8def\u5f84", "title_en": "All Paths from Source Lead to Destination", "question_title_slug": "all-paths-from-source-lead-to-destination", "content_en": "

    Given the edges of a directed graph where edges[i] = [ai, bi] indicates there is an edge between nodes ai and bi, and two nodes source and destination of this graph, determine whether or not all paths starting from source eventually, end at destination, that is:

    \n\n
      \n\t
    • At least one path exists from the source node to the destination node
    • \n\t
    • If a path exists from the source node to a node with no outgoing edges, then that node is equal to destination.
    • \n\t
    • The number of possible paths from source to destination is a finite number.
    • \n
    \n\n

    Return true if and only if all roads from source lead to destination.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: n = 3, edges = [[0,1],[0,2]], source = 0, destination = 2\nOutput: false\nExplanation: It is possible to reach and get stuck on both node 1 and node 2.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: n = 4, edges = [[0,1],[0,3],[1,2],[2,1]], source = 0, destination = 3\nOutput: false\nExplanation: We have two possibilities: to end at node 3, or to loop over node 1 and node 2 indefinitely.\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: n = 4, edges = [[0,1],[0,2],[1,3],[2,3]], source = 0, destination = 3\nOutput: true\n
    \n\n

    Example 4:

    \n\"\"\n
    \nInput: n = 3, edges = [[0,1],[1,1],[1,2]], source = 0, destination = 2\nOutput: false\nExplanation: All paths from the source node end at the destination node, but there are an infinite number of paths, such as 0-1-2, 0-1-1-2, 0-1-1-1-2, 0-1-1-1-1-2, and so on.\n
    \n\n

    Example 5:

    \n\"\"\n
    \nInput: n = 2, edges = [[0,1],[1,1]], source = 0, destination = 1\nOutput: false\nExplanation: There is infinite self-loop at destination node.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 104
    • \n\t
    • 0 <= edges.length <= 104
    • \n\t
    • edges.length == 2
    • \n\t
    • 0 <= ai, bi <= n - 1
    • \n\t
    • 0 <= source <= n - 1
    • \n\t
    • 0 <= destination <= n - 1
    • \n\t
    • The given graph may have self-loops and parallel edges.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u6709\u5411\u56fe\u7684\u8fb9 edges\uff0c\u4ee5\u53ca\u8be5\u56fe\u7684\u59cb\u70b9 source \u548c\u76ee\u6807\u7ec8\u70b9 destination\uff0c\u786e\u5b9a\u4ece\u59cb\u70b9 source \u51fa\u53d1\u7684\u6240\u6709\u8def\u5f84\u662f\u5426\u6700\u7ec8\u7ed3\u675f\u4e8e\u76ee\u6807\u7ec8\u70b9 destination\uff0c\u5373\uff1a

    \n\n
      \n\t
    • \u4ece\u59cb\u70b9 source \u5230\u76ee\u6807\u7ec8\u70b9 destination \u5b58\u5728\u81f3\u5c11\u4e00\u6761\u8def\u5f84
    • \n\t
    • \u5982\u679c\u5b58\u5728\u4ece\u59cb\u70b9 source \u5230\u6ca1\u6709\u51fa\u8fb9\u7684\u8282\u70b9\u7684\u8def\u5f84\uff0c\u5219\u8be5\u8282\u70b9\u5c31\u662f\u8def\u5f84\u7ec8\u70b9\u3002
    • \n\t
    • \u4ece\u59cb\u70b9source\u5230\u76ee\u6807\u7ec8\u70b9 destination \u53ef\u80fd\u8def\u5f84\u6570\u662f\u6709\u9650\u6570\u5b57
    • \n
    \n\n

    \u5f53\u4ece\u59cb\u70b9 source \u51fa\u53d1\u7684\u6240\u6709\u8def\u5f84\u90fd\u53ef\u4ee5\u5230\u8fbe\u76ee\u6807\u7ec8\u70b9 destination \u65f6\u8fd4\u56de true\uff0c\u5426\u5219\u8fd4\u56de false\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 3, edges = [[0,1],[0,2]], source = 0, destination = 2\n\u8f93\u51fa\uff1afalse\n\u8bf4\u660e\uff1a\u8282\u70b9 1 \u548c\u8282\u70b9 2 \u90fd\u53ef\u4ee5\u5230\u8fbe\uff0c\u4f46\u4e5f\u4f1a\u5361\u5728\u90a3\u91cc\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 4, edges = [[0,1],[0,3],[1,2],[2,1]], source = 0, destination = 3\n\u8f93\u51fa\uff1afalse\n\u8bf4\u660e\uff1a\u6709\u4e24\u79cd\u53ef\u80fd\uff1a\u5728\u8282\u70b9 3 \u5904\u7ed3\u675f\uff0c\u6216\u662f\u5728\u8282\u70b9 1 \u548c\u8282\u70b9 2 \u4e4b\u95f4\u65e0\u9650\u5faa\u73af\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 4, edges = [[0,1],[0,2],[1,3],[2,3]], source = 0, destination = 3\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 3, edges = [[0,1],[1,1],[1,2]], source = 0, destination = 2\n\u8f93\u51fa\uff1afalse\n\u8bf4\u660e\uff1a\u4ece\u59cb\u70b9\u51fa\u53d1\u7684\u6240\u6709\u8def\u5f84\u90fd\u5728\u76ee\u6807\u7ec8\u70b9\u7ed3\u675f\uff0c\u4f46\u5b58\u5728\u65e0\u9650\u591a\u7684\u8def\u5f84\uff0c\u5982 0-1-2\uff0c0-1-1-2\uff0c0-1-1-1-2\uff0c0-1-1-1-1-2 \u7b49\u3002\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 2, edges = [[0,1],[1,1]], source = 0, destination = 1\n\u8f93\u51fa\uff1afalse\n\u8bf4\u660e\uff1a\u5728\u76ee\u6807\u8282\u70b9\u4e0a\u5b58\u5728\u65e0\u9650\u7684\u81ea\u73af\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. \u7ed9\u5b9a\u7684\u56fe\u4e2d\u53ef\u80fd\u5e26\u6709\u81ea\u73af\u548c\u5e73\u884c\u8fb9\u3002
    2. \n\t
    3. \u56fe\u4e2d\u7684\u8282\u70b9\u6570 n \u4ecb\u4e8e 1 \u548c 10000 \u4e4b\u95f4\u3002
    4. \n\t
    5. \u56fe\u4e2d\u7684\u8fb9\u6570\u5728 0 \u5230 10000 \u4e4b\u95f4\u3002
    6. \n\t
    7. 0 <= edges.length <= 10000
    8. \n\t
    9. edges[i].length == 2
    10. \n\t
    11. 0 <= source <= n - 1
    12. \n\t
    13. 0 <= destination <= n - 1
    14. \n
    \n", "tags_en": ["Depth-first Search", "Graph"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool leadsToDestination(int n, vector>& edges, int source, int destination) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean leadsToDestination(int n, int[][] edges, int source, int destination) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def leadsToDestination(self, n, edges, source, destination):\n \"\"\"\n :type n: int\n :type edges: List[List[int]]\n :type source: int\n :type destination: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def leadsToDestination(self, n: int, edges: List[List[int]], source: int, destination: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool leadsToDestination(int n, int** edges, int edgesSize, int* edgesColSize, int source, int destination){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool LeadsToDestination(int n, int[][] edges, int source, int destination) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} edges\n * @param {number} source\n * @param {number} destination\n * @return {boolean}\n */\nvar leadsToDestination = function(n, edges, source, destination) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} edges\n# @param {Integer} source\n# @param {Integer} destination\n# @return {Boolean}\ndef leads_to_destination(n, edges, source, destination)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func leadsToDestination(_ n: Int, _ edges: [[Int]], _ source: Int, _ destination: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func leadsToDestination(n int, edges [][]int, source int, destination int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def leadsToDestination(n: Int, edges: Array[Array[Int]], source: Int, destination: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun leadsToDestination(n: Int, edges: Array, source: Int, destination: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn leads_to_destination(n: i32, edges: Vec>, source: i32, destination: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $edges\n * @param Integer $source\n * @param Integer $destination\n * @return Boolean\n */\n function leadsToDestination($n, $edges, $source, $destination) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function leadsToDestination(n: number, edges: number[][], source: number, destination: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (leads-to-destination n edges source destination)\n (-> exact-integer? (listof (listof exact-integer?)) exact-integer? exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1059](https://leetcode-cn.com/problems/all-paths-from-source-lead-to-destination)", "[\u4ece\u59cb\u70b9\u5230\u7ec8\u70b9\u7684\u6240\u6709\u8def\u5f84](/solution/1000-1099/1059.All%20Paths%20from%20Source%20Lead%20to%20Destination/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u56fe`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1059](https://leetcode.com/problems/all-paths-from-source-lead-to-destination)", "[All Paths from Source Lead to Destination](/solution/1000-1099/1059.All%20Paths%20from%20Source%20Lead%20to%20Destination/README_EN.md)", "`Depth-first Search`,`Graph`", "Medium", "\ud83d\udd12"]}, {"question_id": "0509", "frontend_question_id": "0510", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/inorder-successor-in-bst-ii", "url_en": "https://leetcode.com/problems/inorder-successor-in-bst-ii", "relative_path_cn": "/solution/0500-0599/0510.Inorder%20Successor%20in%20BST%20II/README.md", "relative_path_en": "/solution/0500-0599/0510.Inorder%20Successor%20in%20BST%20II/README_EN.md", "title_cn": "\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u7684\u4e2d\u5e8f\u540e\u7ee7 II", "title_en": "Inorder Successor in BST II", "question_title_slug": "inorder-successor-in-bst-ii", "content_en": "

    Given a node in a binary search tree, return the in-order successor of that node in the BST. If that node has no in-order successor, return null.

    \n\n

    The successor of a node is the node with the smallest key greater than node.val.

    \n\n

    You will have direct access to the node but not to the root of the tree. Each node will have a reference to its parent node. Below is the definition for Node:

    \n\n
    \nclass Node {\n    public int val;\n    public Node left;\n    public Node right;\n    public Node parent;\n}\n
    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: tree = [2,1,3], node = 1\nOutput: 2\nExplanation: 1's in-order successor node is 2. Note that both the node and the return value is of Node type.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: tree = [5,3,6,2,4,null,null,1], node = 6\nOutput: null\nExplanation: There is no in-order successor of the current node, so the answer is null.\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: tree = [15,6,18,3,7,17,20,2,4,null,13,null,null,null,null,null,null,null,null,9], node = 15\nOutput: 17\n
    \n\n

    Example 4:

    \n\"\"\n
    \nInput: tree = [15,6,18,3,7,17,20,2,4,null,13,null,null,null,null,null,null,null,null,9], node = 13\nOutput: 15\n
    \n\n

    Example 5:

    \n\n
    \nInput: tree = [0], node = 0\nOutput: null\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 104].
    • \n\t
    • -105 <= Node.val <= 105
    • \n\t
    • All Nodes will have unique values.
    • \n
    \n\n

     

    \n

    Follow up: Could you solve it without looking up any of the node's values?

    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u68f5\u4e8c\u53c9\u641c\u7d22\u6811\u548c\u5176\u4e2d\u7684\u4e00\u4e2a\u8282\u70b9 node \uff0c\u627e\u5230\u8be5\u8282\u70b9\u5728\u6811\u4e2d\u7684\u4e2d\u5e8f\u540e\u7ee7\u3002\u5982\u679c\u8282\u70b9\u6ca1\u6709\u4e2d\u5e8f\u540e\u7ee7\uff0c\u8bf7\u8fd4\u56de null \u3002

    \n\n

    \u4e00\u4e2a\u8282\u70b9 node \u7684\u4e2d\u5e8f\u540e\u7ee7\u662f\u952e\u503c\u6bd4 node.val \u5927\u6240\u6709\u7684\u8282\u70b9\u4e2d\u952e\u503c\u6700\u5c0f\u7684\u90a3\u4e2a\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u76f4\u63a5\u8bbf\u95ee\u7ed3\u70b9\uff0c\u4f46\u65e0\u6cd5\u76f4\u63a5\u8bbf\u95ee\u6811\u3002\u6bcf\u4e2a\u8282\u70b9\u90fd\u4f1a\u6709\u5176\u7236\u8282\u70b9\u7684\u5f15\u7528\u3002\u8282\u70b9\u00a0Node \u5b9a\u4e49\u5982\u4e0b\uff1a

    \n\n
    \nclass Node {\n    public int val;\n    public Node left;\n    public Node right;\n    public Node parent;\n}
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1atree = [2,1,3], node = 1\n\u8f93\u51fa\uff1a2\n\u89e3\u6790\uff1a1 \u7684\u4e2d\u5e8f\u540e\u7ee7\u7ed3\u70b9\u662f 2 \u3002\u6ce8\u610f\u8282\u70b9\u548c\u8fd4\u56de\u503c\u90fd\u662f Node \u7c7b\u578b\u7684\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1atree = [5,3,6,2,4,null,null,1], node = 6\n\u8f93\u51fa\uff1anull\n\u89e3\u6790\uff1a\u8be5\u7ed3\u70b9\u6ca1\u6709\u4e2d\u5e8f\u540e\u7ee7\uff0c\u56e0\u6b64\u8fd4\u56de null \u3002\n
    \n\n

    \u793a\u4f8b\u00a03\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1atree = [15,6,18,3,7,17,20,2,4,null,13,null,null,null,null,null,null,null,null,9], node = 15\n\u8f93\u51fa\uff1a17\n
    \n\n

    \u793a\u4f8b\u00a04\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1atree = [15,6,18,3,7,17,20,2,4,null,13,null,null,null,null,null,null,null,null,9], node = 13\n\u8f93\u51fa\uff1a15\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1atree = [0], node = 0\n\u8f93\u51fa\uff1anull\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u7684\u6570\u76ee\u5728\u8303\u56f4 [1, 104] \u5185\u3002
    • \n\t
    • -105 <= Node.val <= 105
    • \n\t
    • \u6811\u4e2d\u5404\u7ed3\u70b9\u7684\u503c\u5747\u4fdd\u8bc1\u552f\u4e00\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u80fd\u5426\u5728\u4e0d\u8bbf\u95ee\u4efb\u4f55\u7ed3\u70b9\u7684\u503c\u7684\u60c5\u51b5\u4e0b\u89e3\u51b3\u95ee\u9898?

    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* parent;\n};\n*/\n\nclass Solution {\npublic:\n Node* inorderSuccessor(Node* node) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/*\n// Definition for a Node.\nclass Node {\n public int val;\n public Node left;\n public Node right;\n public Node parent;\n};\n*/\n\nclass Solution {\n public Node inorderSuccessor(Node node) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "\"\"\"\n# Definition for a Node.\nclass Node:\n def __init__(self, val):\n self.val = val\n self.left = None\n self.right = None\n self.parent = None\n\"\"\"\n\nclass Solution(object):\n def inorderSuccessor(self, node):\n \"\"\"\n :type node: Node\n :rtype: Node\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "\"\"\"\n# Definition for a Node.\nclass Node:\n def __init__(self, val):\n self.val = val\n self.left = None\n self.right = None\n self.parent = None\n\"\"\"\n\nclass Solution:\n def inorderSuccessor(self, node: 'Node') -> 'Node':\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/*\n// Definition for a Node.\nstruct Node {\n int val;\n struct Node* left;\n struct Node* right;\n struct Node* parent;\n};\n*/\n\nstruct Node* inorderSuccessor(struct Node* node) {\n\t\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/*\n// Definition for a Node.\npublic class Node {\n public int val;\n public Node left;\n public Node right;\n public Node parent;\n}\n*/\n\npublic class Solution {\n public Node InorderSuccessor(Node x) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // Definition for a Node.\n * function Node(val) {\n * this.val = val;\n * this.left = null;\n * this.right = null;\n * this.parent = null;\n * };\n */\n\n/**\n * @param {Node} node\n * @return {Node}\n */\nvar inorderSuccessor = function(node) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a Node.\n# class Node\n# attr_accessor :val, :left, :right, :parent\n# def initialize(val=0)\n# @val = val\n# @left, @right, parent = nil, nil, nil\n# end\n# end\n\n# @param {Node} root\n# @return {Node}\ndef inorderSuccessor(node)\n\t\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a Node.\n * public class Node {\n * public var val: Int\n * public var left: Node?\n * public var right: Node?\n * public var parent: Node?\n * public init(_ val: Int) {\n * self.val = val\n * self.left = nil\n * self.right = nil\n * self.parent = nil\n * }\n * }\n */\n\nclass Solution {\n func inorderSuccessor(_ node: Node?) -> Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for Node.\n * type Node struct {\n * Val int\n * Left *Node\n * Right *Node\n * Parent *Node\n * }\n */\n\nfunc inorderSuccessor(node *Node) *Node {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a Node.\n * class Node(var _value: Int) {\n * var value: Int = _value\n * var left: Node = null\n * var right: Node = null\n * var parent: Node = null\n * }\n */\n\nobject Solution {\n def inorderSuccessor(node: Node): Node = {\n\t\t\n\t}\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a Node.\n * class Node(var `val`: Int) {\n *\t\tvar left: TreeNode? = null\n *\t\tvar right: TreeNode? = null\n *\t\tvar parent: Node? = null\n * }\n */\n\nclass Solution {\n fun inorderSuccessor(node: Node?): Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a Node.\n * class Node {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * public $parent = null;\n * function __construct($val = 0) {\n * $this->val = $val;\n * $this->left = null;\n * $this->right = null;\n * $this->parent = null;\n * }\n * }\n */\n\nclass Solution {\n /**\n * @param Node $node\n * @return Node\n */\n function inorderSuccessor($node) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class Node {\n * val: number\n * left: Node | null\n * right: Node | null\n * parent: Node | null\n * constructor(val?: number, left?: Node | null, right?: Node | null, parent?: Node | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * this.parent = (parent===undefined ? null : parent)\n * }\n * }\n */\n\nfunction inorderSuccessor(node: Node | null): Node | null {\n\t\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0510](https://leetcode-cn.com/problems/inorder-successor-in-bst-ii)", "[\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u7684\u4e2d\u5e8f\u540e\u7ee7 II](/solution/0500-0599/0510.Inorder%20Successor%20in%20BST%20II/README.md)", "`\u6811`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0510](https://leetcode.com/problems/inorder-successor-in-bst-ii)", "[Inorder Successor in BST II](/solution/0500-0599/0510.Inorder%20Successor%20in%20BST%20II/README_EN.md)", "`Tree`", "Medium", "\ud83d\udd12"]}, {"question_id": "0508", "frontend_question_id": "0508", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/most-frequent-subtree-sum", "url_en": "https://leetcode.com/problems/most-frequent-subtree-sum", "relative_path_cn": "/solution/0500-0599/0508.Most%20Frequent%20Subtree%20Sum/README.md", "relative_path_en": "/solution/0500-0599/0508.Most%20Frequent%20Subtree%20Sum/README_EN.md", "title_cn": "\u51fa\u73b0\u6b21\u6570\u6700\u591a\u7684\u5b50\u6811\u5143\u7d20\u548c", "title_en": "Most Frequent Subtree Sum", "question_title_slug": "most-frequent-subtree-sum", "content_en": "

    Given the root of a binary tree, return the most frequent subtree sum. If there is a tie, return all the values with the highest frequency in any order.

    \n\n

    The subtree sum of a node is defined as the sum of all the node values formed by the subtree rooted at that node (including the node itself).

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [5,2,-3]\nOutput: [2,-3,4]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [5,2,-5]\nOutput: [2]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 104].
    • \n\t
    • -105 <= Node.val <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u4e8c\u53c9\u6811\u7684\u6839\u7ed3\u70b9\uff0c\u8bf7\u4f60\u627e\u51fa\u51fa\u73b0\u6b21\u6570\u6700\u591a\u7684\u5b50\u6811\u5143\u7d20\u548c\u3002\u4e00\u4e2a\u7ed3\u70b9\u7684\u300c\u5b50\u6811\u5143\u7d20\u548c\u300d\u5b9a\u4e49\u4e3a\u4ee5\u8be5\u7ed3\u70b9\u4e3a\u6839\u7684\u4e8c\u53c9\u6811\u4e0a\u6240\u6709\u7ed3\u70b9\u7684\u5143\u7d20\u4e4b\u548c\uff08\u5305\u62ec\u7ed3\u70b9\u672c\u8eab\uff09\u3002

    \n\n

    \u4f60\u9700\u8981\u8fd4\u56de\u51fa\u73b0\u6b21\u6570\u6700\u591a\u7684\u5b50\u6811\u5143\u7d20\u548c\u3002\u5982\u679c\u6709\u591a\u4e2a\u5143\u7d20\u51fa\u73b0\u7684\u6b21\u6570\u76f8\u540c\uff0c\u8fd4\u56de\u6240\u6709\u51fa\u73b0\u6b21\u6570\u6700\u591a\u7684\u5b50\u6811\u5143\u7d20\u548c\uff08\u4e0d\u9650\u987a\u5e8f\uff09\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a
    \n\u8f93\u5165:

    \n\n
      5\n /  \\\n2   -3\n
    \n\n

    \u8fd4\u56de [2, -3, 4]\uff0c\u6240\u6709\u7684\u503c\u5747\u53ea\u51fa\u73b0\u4e00\u6b21\uff0c\u4ee5\u4efb\u610f\u987a\u5e8f\u8fd4\u56de\u6240\u6709\u503c\u3002

    \n\n

    \u793a\u4f8b 2\uff1a
    \n\u8f93\u5165\uff1a

    \n\n
      5\n /  \\\n2   -5\n
    \n\n

    \u8fd4\u56de [2]\uff0c\u53ea\u6709 2 \u51fa\u73b0\u4e24\u6b21\uff0c-5 \u53ea\u51fa\u73b0 1 \u6b21\u3002

    \n\n

     

    \n\n

    \u63d0\u793a\uff1a \u5047\u8bbe\u4efb\u610f\u5b50\u6811\u5143\u7d20\u548c\u5747\u53ef\u4ee5\u7528 32 \u4f4d\u6709\u7b26\u53f7\u6574\u6570\u8868\u793a\u3002

    \n", "tags_en": ["Tree", "Hash Table"], "tags_cn": ["\u6811", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector findFrequentTreeSum(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int[] findFrequentTreeSum(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def findFrequentTreeSum(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def findFrequentTreeSum(self, root: TreeNode) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* findFrequentTreeSum(struct TreeNode* root, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int[] FindFrequentTreeSum(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number[]}\n */\nvar findFrequentTreeSum = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer[]}\ndef find_frequent_tree_sum(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func findFrequentTreeSum(_ root: TreeNode?) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc findFrequentTreeSum(root *TreeNode) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def findFrequentTreeSum(root: TreeNode): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun findFrequentTreeSum(root: TreeNode?): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn find_frequent_tree_sum(root: Option>>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer[]\n */\n function findFrequentTreeSum($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction findFrequentTreeSum(root: TreeNode | null): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (find-frequent-tree-sum root)\n (-> (or/c tree-node? #f) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0508](https://leetcode-cn.com/problems/most-frequent-subtree-sum)", "[\u51fa\u73b0\u6b21\u6570\u6700\u591a\u7684\u5b50\u6811\u5143\u7d20\u548c](/solution/0500-0599/0508.Most%20Frequent%20Subtree%20Sum/README.md)", "`\u6811`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0508](https://leetcode.com/problems/most-frequent-subtree-sum)", "[Most Frequent Subtree Sum](/solution/0500-0599/0508.Most%20Frequent%20Subtree%20Sum/README_EN.md)", "`Tree`,`Hash Table`", "Medium", ""]}, {"question_id": "0507", "frontend_question_id": "0507", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/perfect-number", "url_en": "https://leetcode.com/problems/perfect-number", "relative_path_cn": "/solution/0500-0599/0507.Perfect%20Number/README.md", "relative_path_en": "/solution/0500-0599/0507.Perfect%20Number/README_EN.md", "title_cn": "\u5b8c\u7f8e\u6570", "title_en": "Perfect Number", "question_title_slug": "perfect-number", "content_en": "

    A perfect number is a positive integer that is equal to the sum of its positive divisors, excluding the number itself. A divisor of an integer x is an integer that can divide x evenly.

    \n\n

    Given an integer n, return true if n is a perfect number, otherwise return false.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: num = 28\nOutput: true\nExplanation: 28 = 1 + 2 + 4 + 7 + 14\n1, 2, 4, 7, and 14 are all divisors of 28.\n
    \n\n

    Example 2:

    \n\n
    \nInput: num = 6\nOutput: true\n
    \n\n

    Example 3:

    \n\n
    \nInput: num = 496\nOutput: true\n
    \n\n

    Example 4:

    \n\n
    \nInput: num = 8128\nOutput: true\n
    \n\n

    Example 5:

    \n\n
    \nInput: num = 2\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= num <= 108
    • \n
    \n", "content_cn": "

    \u5bf9\u4e8e\u4e00\u4e2a \u6b63\u6574\u6570\uff0c\u5982\u679c\u5b83\u548c\u9664\u4e86\u5b83\u81ea\u8eab\u4ee5\u5916\u7684\u6240\u6709 \u6b63\u56e0\u5b50 \u4e4b\u548c\u76f8\u7b49\uff0c\u6211\u4eec\u79f0\u5b83\u4e3a \u300c\u5b8c\u7f8e\u6570\u300d\u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a \u6574\u6570 n\uff0c \u5982\u679c\u662f\u5b8c\u7f8e\u6570\uff0c\u8fd4\u56de true\uff0c\u5426\u5219\u8fd4\u56de false

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a28\n\u8f93\u51fa\uff1aTrue\n\u89e3\u91ca\uff1a28 = 1 + 2 + 4 + 7 + 14\n1, 2, 4, 7, \u548c 14 \u662f 28 \u7684\u6240\u6709\u6b63\u56e0\u5b50\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anum = 6\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1anum = 496\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1anum = 8128\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1anum = 2\n\u8f93\u51fa\uff1afalse\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= num <= 108
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool checkPerfectNumber(int num) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean checkPerfectNumber(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def checkPerfectNumber(self, num):\n \"\"\"\n :type num: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def checkPerfectNumber(self, num: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool checkPerfectNumber(int num){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CheckPerfectNumber(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} num\n * @return {boolean}\n */\nvar checkPerfectNumber = function(num) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} num\n# @return {Boolean}\ndef check_perfect_number(num)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func checkPerfectNumber(_ num: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func checkPerfectNumber(num int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def checkPerfectNumber(num: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun checkPerfectNumber(num: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn check_perfect_number(num: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $num\n * @return Boolean\n */\n function checkPerfectNumber($num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function checkPerfectNumber(num: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (check-perfect-number num)\n (-> exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0507](https://leetcode-cn.com/problems/perfect-number)", "[\u5b8c\u7f8e\u6570](/solution/0500-0599/0507.Perfect%20Number/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0507](https://leetcode.com/problems/perfect-number)", "[Perfect Number](/solution/0500-0599/0507.Perfect%20Number/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "0506", "frontend_question_id": "0506", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/relative-ranks", "url_en": "https://leetcode.com/problems/relative-ranks", "relative_path_cn": "/solution/0500-0599/0506.Relative%20Ranks/README.md", "relative_path_en": "/solution/0500-0599/0506.Relative%20Ranks/README_EN.md", "title_cn": "\u76f8\u5bf9\u540d\u6b21", "title_en": "Relative Ranks", "question_title_slug": "relative-ranks", "content_en": "

    You are given an integer array score of size n, where score[i] is the score of the ith athlete in a competition. All the scores are guaranteed to be unique.

    \n\n

    The athletes are placed based on their scores, where the 1st place athlete has the highest score, the 2nd place athlete has the 2nd highest score, and so on. The placement of each athlete determines their rank:

    \n\n
      \n\t
    • The 1st place athlete's rank is "Gold Medal".
    • \n\t
    • The 2nd place athlete's rank is "Silver Medal".
    • \n\t
    • The 3rd place athlete's rank is "Bronze Medal".
    • \n\t
    • For the 4th place to the nth place athlete, their rank is their placement number (i.e., the xth place athlete's rank is "x").
    • \n
    \n\n

    Return an array answer of size n where answer[i] is the rank of the ith athlete.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: score = [5,4,3,2,1]\nOutput: ["Gold Medal","Silver Medal","Bronze Medal","4","5"]\nExplanation: The placements are [1st, 2nd, 3rd, 4th, 5th].
    \n\n

    Example 2:

    \n\n
    \nInput: score = [10,3,8,9,4]\nOutput: ["Gold Medal","5","Bronze Medal","Silver Medal","4"]\nExplanation: The placements are [1st, 5th, 3rd, 2nd, 4th].\n\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == score.length
    • \n\t
    • 1 <= n <= 104
    • \n\t
    • 0 <= score[i] <= 106
    • \n\t
    • All the values in score are unique.
    • \n
    \n", "content_cn": "

    \u7ed9\u51fa N \u540d\u8fd0\u52a8\u5458\u7684\u6210\u7ee9\uff0c\u627e\u51fa\u4ed6\u4eec\u7684\u76f8\u5bf9\u540d\u6b21\u5e76\u6388\u4e88\u524d\u4e09\u540d\u5bf9\u5e94\u7684\u5956\u724c\u3002\u524d\u4e09\u540d\u8fd0\u52a8\u5458\u5c06\u4f1a\u88ab\u5206\u522b\u6388\u4e88 “\u91d1\u724c”\uff0c“\u94f6\u724c” \u548c“ \u94dc\u724c”\uff08"Gold Medal", "Silver Medal", "Bronze Medal"\uff09\u3002

    \n\n

    (\u6ce8\uff1a\u5206\u6570\u8d8a\u9ad8\u7684\u9009\u624b\uff0c\u6392\u540d\u8d8a\u9760\u524d\u3002)

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: [5, 4, 3, 2, 1]\n\u8f93\u51fa: ["Gold Medal", "Silver Medal", "Bronze Medal", "4", "5"]\n\u89e3\u91ca: \u524d\u4e09\u540d\u8fd0\u52a8\u5458\u7684\u6210\u7ee9\u4e3a\u524d\u4e09\u9ad8\u7684\uff0c\u56e0\u6b64\u5c06\u4f1a\u5206\u522b\u88ab\u6388\u4e88 “\u91d1\u724c”\uff0c“\u94f6\u724c”\u548c“\u94dc\u724c” ("Gold Medal", "Silver Medal" and "Bronze Medal").\n\u4f59\u4e0b\u7684\u4e24\u540d\u8fd0\u52a8\u5458\uff0c\u6211\u4eec\u53ea\u9700\u8981\u901a\u8fc7\u4ed6\u4eec\u7684\u6210\u7ee9\u8ba1\u7b97\u5c06\u5176\u76f8\u5bf9\u540d\u6b21\u5373\u53ef\u3002
    \n\n

    \u63d0\u793a:

    \n\n
      \n\t
    1. N \u662f\u4e00\u4e2a\u6b63\u6574\u6570\u5e76\u4e14\u4e0d\u4f1a\u8d85\u8fc7 10000\u3002
    2. \n\t
    3. \u6240\u6709\u8fd0\u52a8\u5458\u7684\u6210\u7ee9\u90fd\u4e0d\u76f8\u540c\u3002
    4. \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findRelativeRanks(vector& score) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String[] findRelativeRanks(int[] score) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findRelativeRanks(self, score):\n \"\"\"\n :type score: List[int]\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findRelativeRanks(self, score: List[int]) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** findRelativeRanks(int* score, int scoreSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string[] FindRelativeRanks(int[] score) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} score\n * @return {string[]}\n */\nvar findRelativeRanks = function(score) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} score\n# @return {String[]}\ndef find_relative_ranks(score)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findRelativeRanks(_ score: [Int]) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findRelativeRanks(score []int) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findRelativeRanks(score: Array[Int]): Array[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findRelativeRanks(score: IntArray): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_relative_ranks(score: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $score\n * @return String[]\n */\n function findRelativeRanks($score) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findRelativeRanks(score: number[]): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-relative-ranks score)\n (-> (listof exact-integer?) (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0506](https://leetcode-cn.com/problems/relative-ranks)", "[\u76f8\u5bf9\u540d\u6b21](/solution/0500-0599/0506.Relative%20Ranks/README.md)", "", "\u7b80\u5355", ""], "md_table_row_en": ["[0506](https://leetcode.com/problems/relative-ranks)", "[Relative Ranks](/solution/0500-0599/0506.Relative%20Ranks/README_EN.md)", "", "Easy", ""]}, {"question_id": "0505", "frontend_question_id": "0505", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/the-maze-ii", "url_en": "https://leetcode.com/problems/the-maze-ii", "relative_path_cn": "/solution/0500-0599/0505.The%20Maze%20II/README.md", "relative_path_en": "/solution/0500-0599/0505.The%20Maze%20II/README_EN.md", "title_cn": "\u8ff7\u5bab II", "title_en": "The Maze II", "question_title_slug": "the-maze-ii", "content_en": "

    There is a ball in a maze with empty spaces (represented as 0) and walls (represented as 1). The ball can go through the empty spaces by rolling up, down, left or right, but it won't stop rolling until hitting a wall. When the ball stops, it could choose the next direction.

    \n\n

    Given the m x n maze, the ball's start position and the destination, where start = [startrow, startcol] and destination = [destinationrow, destinationcol], return the shortest distance for the ball to stop at the destination. If the ball cannot stop at destination, return -1.

    \n\n

    The distance is the number of empty spaces traveled by the ball from the start position (excluded) to the destination (included).

    \n\n

    You may assume that the borders of the maze are all walls (see examples).

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: maze = [[0,0,1,0,0],[0,0,0,0,0],[0,0,0,1,0],[1,1,0,1,1],[0,0,0,0,0]], start = [0,4], destination = [4,4]\nOutput: 12\nExplanation: One possible way is : left -> down -> left -> down -> right -> down -> right.\nThe length of the path is 1 + 1 + 3 + 1 + 2 + 2 + 2 = 12.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: maze = [[0,0,1,0,0],[0,0,0,0,0],[0,0,0,1,0],[1,1,0,1,1],[0,0,0,0,0]], start = [0,4], destination = [3,2]\nOutput: -1\nExplanation: There is no way for the ball to stop at the destination. Notice that you can pass through the destination but you cannot stop there.\n
    \n\n

    Example 3:

    \n\n
    \nInput: maze = [[0,0,0,0,0],[1,1,0,0,1],[0,0,0,0,0],[0,1,0,0,1],[0,1,0,0,0]], start = [4,3], destination = [0,1]\nOutput: -1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == maze.length
    • \n\t
    • n == maze[i].length
    • \n\t
    • 1 <= m, n <= 100
    • \n\t
    • maze[i][j] is 0 or 1.
    • \n\t
    • start.length == 2
    • \n\t
    • destination.length == 2
    • \n\t
    • 0 <= startrow, destinationrow <= m
    • \n\t
    • 0 <= startcol, destinationcol <= n
    • \n\t
    • Both the ball and the destination exist in an empty space, and they will not be in the same position initially.
    • \n\t
    • The maze contains at least 2 empty spaces.
    • \n
    \n", "content_cn": "

    \u7531\u7a7a\u5730\u548c\u5899\u7ec4\u6210\u7684\u8ff7\u5bab\u4e2d\u6709\u4e00\u4e2a\u7403\u3002\u7403\u53ef\u4ee5\u5411\u4e0a\u4e0b\u5de6\u53f3\u56db\u4e2a\u65b9\u5411\u6eda\u52a8\uff0c\u4f46\u5728\u9047\u5230\u5899\u58c1\u524d\u4e0d\u4f1a\u505c\u6b62\u6eda\u52a8\u3002\u5f53\u7403\u505c\u4e0b\u65f6\uff0c\u53ef\u4ee5\u9009\u62e9\u4e0b\u4e00\u4e2a\u65b9\u5411\u3002

    \n\n

    \u7ed9\u5b9a\u7403\u7684\u8d77\u59cb\u4f4d\u7f6e\uff0c\u76ee\u7684\u5730\u548c\u8ff7\u5bab\uff0c\u627e\u51fa\u8ba9\u7403\u505c\u5728\u76ee\u7684\u5730\u7684\u6700\u77ed\u8ddd\u79bb\u3002\u8ddd\u79bb\u7684\u5b9a\u4e49\u662f\u7403\u4ece\u8d77\u59cb\u4f4d\u7f6e\uff08\u4e0d\u5305\u62ec\uff09\u5230\u76ee\u7684\u5730\uff08\u5305\u62ec\uff09\u7ecf\u8fc7\u7684\u7a7a\u5730\u4e2a\u6570\u3002\u5982\u679c\u7403\u65e0\u6cd5\u505c\u5728\u76ee\u7684\u5730\uff0c\u8fd4\u56de -1\u3002

    \n\n

    \u8ff7\u5bab\u7531\u4e00\u4e2a0\u548c1\u7684\u4e8c\u7ef4\u6570\u7ec4\u8868\u793a\u3002 1\u8868\u793a\u5899\u58c1\uff0c0\u8868\u793a\u7a7a\u5730\u3002\u4f60\u53ef\u4ee5\u5047\u5b9a\u8ff7\u5bab\u7684\u8fb9\u7f18\u90fd\u662f\u5899\u58c1\u3002\u8d77\u59cb\u4f4d\u7f6e\u548c\u76ee\u7684\u5730\u7684\u5750\u6807\u901a\u8fc7\u884c\u53f7\u548c\u5217\u53f7\u7ed9\u51fa\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165 1: \u8ff7\u5bab\u7531\u4ee5\u4e0b\u4e8c\u7ef4\u6570\u7ec4\u8868\u793a\n\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 1 0\n1 1 0 1 1\n0 0 0 0 0\n\n\u8f93\u5165 2: \u8d77\u59cb\u4f4d\u7f6e\u5750\u6807 (rowStart, colStart) = (0, 4)\n\u8f93\u5165 3: \u76ee\u7684\u5730\u5750\u6807 (rowDest, colDest) = (4, 4)\n\n\u8f93\u51fa: 12\n\n\u89e3\u6790: \u4e00\u6761\u6700\u77ed\u8def\u5f84 : left -> down -> left -> down -> right -> down -> right\u3002\n             \u603b\u8ddd\u79bb\u4e3a 1 + 1 + 3 + 1 + 2 + 2 + 2 = 12\u3002\n\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165 1: \u8ff7\u5bab\u7531\u4ee5\u4e0b\u4e8c\u7ef4\u6570\u7ec4\u8868\u793a\n\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 1 0\n1 1 0 1 1\n0 0 0 0 0\n\n\u8f93\u5165 2: \u8d77\u59cb\u4f4d\u7f6e\u5750\u6807 (rowStart, colStart) = (0, 4)\n\u8f93\u5165 3: \u76ee\u7684\u5730\u5750\u6807 (rowDest, colDest) = (3, 2)\n\n\u8f93\u51fa: -1\n\n\u89e3\u6790: \u6ca1\u6709\u80fd\u591f\u4f7f\u7403\u505c\u5728\u76ee\u7684\u5730\u7684\u8def\u5f84\u3002\n\n
    \n\n

     

    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u8ff7\u5bab\u4e2d\u53ea\u6709\u4e00\u4e2a\u7403\u548c\u4e00\u4e2a\u76ee\u7684\u5730\u3002
    2. \n\t
    3. \u7403\u548c\u76ee\u7684\u5730\u90fd\u5728\u7a7a\u5730\u4e0a\uff0c\u4e14\u521d\u59cb\u65f6\u5b83\u4eec\u4e0d\u5728\u540c\u4e00\u4f4d\u7f6e\u3002
    4. \n\t
    5. \u7ed9\u5b9a\u7684\u8ff7\u5bab\u4e0d\u5305\u62ec\u8fb9\u754c (\u5982\u56fe\u4e2d\u7684\u7ea2\u8272\u77e9\u5f62), \u4f46\u4f60\u53ef\u4ee5\u5047\u8bbe\u8ff7\u5bab\u7684\u8fb9\u7f18\u90fd\u662f\u5899\u58c1\u3002
    6. \n\t
    7. \u8ff7\u5bab\u81f3\u5c11\u5305\u62ec2\u5757\u7a7a\u5730\uff0c\u884c\u6570\u548c\u5217\u6570\u5747\u4e0d\u8d85\u8fc7100\u3002
    8. \n
    \n", "tags_en": ["Depth-first Search", "Breadth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int shortestDistance(vector>& maze, vector& start, vector& destination) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int shortestDistance(int[][] maze, int[] start, int[] destination) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def shortestDistance(self, maze, start, destination):\n \"\"\"\n :type maze: List[List[int]]\n :type start: List[int]\n :type destination: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def shortestDistance(self, maze: List[List[int]], start: List[int], destination: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint shortestDistance(int** maze, int mazeSize, int* mazeColSize, int* start, int startSize, int* destination, int destinationSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ShortestDistance(int[][] maze, int[] start, int[] destination) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} maze\n * @param {number[]} start\n * @param {number[]} destination\n * @return {number}\n */\nvar shortestDistance = function(maze, start, destination) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} maze\n# @param {Integer[]} start\n# @param {Integer[]} destination\n# @return {Integer}\ndef shortest_distance(maze, start, destination)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func shortestDistance(_ maze: [[Int]], _ start: [Int], _ destination: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func shortestDistance(maze [][]int, start []int, destination []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def shortestDistance(maze: Array[Array[Int]], start: Array[Int], destination: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun shortestDistance(maze: Array, start: IntArray, destination: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn shortest_distance(maze: Vec>, start: Vec, destination: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $maze\n * @param Integer[] $start\n * @param Integer[] $destination\n * @return Integer\n */\n function shortestDistance($maze, $start, $destination) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function shortestDistance(maze: number[][], start: number[], destination: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (shortest-distance maze start destination)\n (-> (listof (listof exact-integer?)) (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0505](https://leetcode-cn.com/problems/the-maze-ii)", "[\u8ff7\u5bab II](/solution/0500-0599/0505.The%20Maze%20II/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0505](https://leetcode.com/problems/the-maze-ii)", "[The Maze II](/solution/0500-0599/0505.The%20Maze%20II/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`", "Medium", "\ud83d\udd12"]}, {"question_id": "0504", "frontend_question_id": "0504", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/base-7", "url_en": "https://leetcode.com/problems/base-7", "relative_path_cn": "/solution/0500-0599/0504.Base%207/README.md", "relative_path_en": "/solution/0500-0599/0504.Base%207/README_EN.md", "title_cn": "\u4e03\u8fdb\u5236\u6570", "title_en": "Base 7", "question_title_slug": "base-7", "content_en": "

    Given an integer num, return a string of its base 7 representation.

    \n\n

     

    \n

    Example 1:

    \n
    Input: num = 100\nOutput: \"202\"\n

    Example 2:

    \n
    Input: num = -7\nOutput: \"-10\"\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • -107 <= num <= 107
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\uff0c\u5c06\u5176\u8f6c\u5316\u4e3a7\u8fdb\u5236\uff0c\u5e76\u4ee5\u5b57\u7b26\u4e32\u5f62\u5f0f\u8f93\u51fa\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: 100\n\u8f93\u51fa: "202"\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: -7\n\u8f93\u51fa: "-10"\n
    \n\n

    \u6ce8\u610f: \u8f93\u5165\u8303\u56f4\u662f [-1e7, 1e7] \u3002

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string convertToBase7(int num) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String convertToBase7(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def convertToBase7(self, num):\n \"\"\"\n :type num: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def convertToBase7(self, num: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * convertToBase7(int num){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ConvertToBase7(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} num\n * @return {string}\n */\nvar convertToBase7 = function(num) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} num\n# @return {String}\ndef convert_to_base7(num)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func convertToBase7(_ num: Int) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func convertToBase7(num int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def convertToBase7(num: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun convertToBase7(num: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn convert_to_base7(num: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $num\n * @return String\n */\n function convertToBase7($num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function convertToBase7(num: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (convert-to-base7 num)\n (-> exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0504](https://leetcode-cn.com/problems/base-7)", "[\u4e03\u8fdb\u5236\u6570](/solution/0500-0599/0504.Base%207/README.md)", "", "\u7b80\u5355", ""], "md_table_row_en": ["[0504](https://leetcode.com/problems/base-7)", "[Base 7](/solution/0500-0599/0504.Base%207/README_EN.md)", "", "Easy", ""]}, {"question_id": "0503", "frontend_question_id": "0503", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/next-greater-element-ii", "url_en": "https://leetcode.com/problems/next-greater-element-ii", "relative_path_cn": "/solution/0500-0599/0503.Next%20Greater%20Element%20II/README.md", "relative_path_en": "/solution/0500-0599/0503.Next%20Greater%20Element%20II/README_EN.md", "title_cn": "\u4e0b\u4e00\u4e2a\u66f4\u5927\u5143\u7d20 II", "title_en": "Next Greater Element II", "question_title_slug": "next-greater-element-ii", "content_en": "

    Given a circular integer array nums (i.e., the next element of nums[nums.length - 1] is nums[0]), return the next greater number for every element in nums.

    \n\n

    The next greater number of a number x is the first greater number to its traversing-order next in the array, which means you could search circularly to find its next greater number. If it doesn't exist, return -1 for this number.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,1]\nOutput: [2,-1,2]\nExplanation: The first 1's next greater number is 2; \nThe number 2 can't find next greater number. \nThe second 1's next greater number needs to search circularly, which is also 2.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,2,3,4,3]\nOutput: [2,3,4,-1,4]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 104
    • \n\t
    • -109 <= nums[i] <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5faa\u73af\u6570\u7ec4\uff08\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u7684\u4e0b\u4e00\u4e2a\u5143\u7d20\u662f\u6570\u7ec4\u7684\u7b2c\u4e00\u4e2a\u5143\u7d20\uff09\uff0c\u8f93\u51fa\u6bcf\u4e2a\u5143\u7d20\u7684\u4e0b\u4e00\u4e2a\u66f4\u5927\u5143\u7d20\u3002\u6570\u5b57 x \u7684\u4e0b\u4e00\u4e2a\u66f4\u5927\u7684\u5143\u7d20\u662f\u6309\u6570\u7ec4\u904d\u5386\u987a\u5e8f\uff0c\u8fd9\u4e2a\u6570\u5b57\u4e4b\u540e\u7684\u7b2c\u4e00\u4e2a\u6bd4\u5b83\u66f4\u5927\u7684\u6570\uff0c\u8fd9\u610f\u5473\u7740\u4f60\u5e94\u8be5\u5faa\u73af\u5730\u641c\u7d22\u5b83\u7684\u4e0b\u4e00\u4e2a\u66f4\u5927\u7684\u6570\u3002\u5982\u679c\u4e0d\u5b58\u5728\uff0c\u5219\u8f93\u51fa -1\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: [1,2,1]\n\u8f93\u51fa: [2,-1,2]\n\u89e3\u91ca: \u7b2c\u4e00\u4e2a 1 \u7684\u4e0b\u4e00\u4e2a\u66f4\u5927\u7684\u6570\u662f 2\uff1b\n\u6570\u5b57 2 \u627e\u4e0d\u5230\u4e0b\u4e00\u4e2a\u66f4\u5927\u7684\u6570\uff1b \n\u7b2c\u4e8c\u4e2a 1 \u7684\u4e0b\u4e00\u4e2a\u6700\u5927\u7684\u6570\u9700\u8981\u5faa\u73af\u641c\u7d22\uff0c\u7ed3\u679c\u4e5f\u662f 2\u3002\n
    \n\n

    \u6ce8\u610f: \u8f93\u5165\u6570\u7ec4\u7684\u957f\u5ea6\u4e0d\u4f1a\u8d85\u8fc7 10000\u3002

    \n", "tags_en": ["Stack"], "tags_cn": ["\u6808"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector nextGreaterElements(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] nextGreaterElements(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def nextGreaterElements(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def nextGreaterElements(self, nums: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* nextGreaterElements(int* nums, int numsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] NextGreaterElements(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar nextGreaterElements = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer[]}\ndef next_greater_elements(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func nextGreaterElements(_ nums: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func nextGreaterElements(nums []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def nextGreaterElements(nums: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun nextGreaterElements(nums: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn next_greater_elements(nums: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer[]\n */\n function nextGreaterElements($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function nextGreaterElements(nums: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (next-greater-elements nums)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0503](https://leetcode-cn.com/problems/next-greater-element-ii)", "[\u4e0b\u4e00\u4e2a\u66f4\u5927\u5143\u7d20 II](/solution/0500-0599/0503.Next%20Greater%20Element%20II/README.md)", "`\u6808`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0503](https://leetcode.com/problems/next-greater-element-ii)", "[Next Greater Element II](/solution/0500-0599/0503.Next%20Greater%20Element%20II/README_EN.md)", "`Stack`", "Medium", ""]}, {"question_id": "0502", "frontend_question_id": "0502", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/ipo", "url_en": "https://leetcode.com/problems/ipo", "relative_path_cn": "/solution/0500-0599/0502.IPO/README.md", "relative_path_en": "/solution/0500-0599/0502.IPO/README_EN.md", "title_cn": "IPO", "title_en": "IPO", "question_title_slug": "ipo", "content_en": "

    Suppose LeetCode will start its IPO soon. In order to sell a good price of its shares to Venture Capital, LeetCode would like to work on some projects to increase its capital before the IPO. Since it has limited resources, it can only finish at most k distinct projects before the IPO. Help LeetCode design the best way to maximize its total capital after finishing at most k distinct projects.

    \n\n

    You are given n projects where the ith project has a pure profit profits[i] and a minimum capital of capital[i] is needed to start it.

    \n\n

    Initially, you have w capital. When you finish a project, you will obtain its pure profit and the profit will be added to your total capital.

    \n\n

    Pick a list of at most k distinct projects from given projects to maximize your final capital, and return the final maximized capital.

    \n\n

    The answer is guaranteed to fit in a 32-bit signed integer.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: k = 2, w = 0, profits = [1,2,3], capital = [0,1,1]\nOutput: 4\nExplanation: Since your initial capital is 0, you can only start the project indexed 0.\nAfter finishing it you will obtain profit 1 and your capital becomes 1.\nWith capital 1, you can either start the project indexed 1 or the project indexed 2.\nSince you can choose at most 2 projects, you need to finish the project indexed 2 to get the maximum capital.\nTherefore, output the final maximized capital, which is 0 + 1 + 3 = 4.\n
    \n\n

    Example 2:

    \n\n
    \nInput: k = 3, w = 0, profits = [1,2,3], capital = [0,1,2]\nOutput: 6\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= k <= 105
    • \n\t
    • 0 <= w <= 109
    • \n\t
    • n == profits.length
    • \n\t
    • n == capital.length
    • \n\t
    • 1 <= n <= 105
    • \n\t
    • 0 <= profits[i] <= 104
    • \n\t
    • 0 <= capital[i] <= 109
    • \n
    \n", "content_cn": "

    \u5047\u8bbe \u529b\u6263\uff08LeetCode\uff09\u5373\u5c06\u5f00\u59cb\u5176 IPO\u3002\u4e3a\u4e86\u4ee5\u66f4\u9ad8\u7684\u4ef7\u683c\u5c06\u80a1\u7968\u5356\u7ed9\u98ce\u9669\u6295\u8d44\u516c\u53f8\uff0c\u529b\u6263 \u5e0c\u671b\u5728 IPO \u4e4b\u524d\u5f00\u5c55\u4e00\u4e9b\u9879\u76ee\u4ee5\u589e\u52a0\u5176\u8d44\u672c\u3002 \u7531\u4e8e\u8d44\u6e90\u6709\u9650\uff0c\u5b83\u53ea\u80fd\u5728 IPO \u4e4b\u524d\u5b8c\u6210\u6700\u591a k \u4e2a\u4e0d\u540c\u7684\u9879\u76ee\u3002\u5e2e\u52a9 \u529b\u6263 \u8bbe\u8ba1\u5b8c\u6210\u6700\u591a k \u4e2a\u4e0d\u540c\u9879\u76ee\u540e\u5f97\u5230\u6700\u5927\u603b\u8d44\u672c\u7684\u65b9\u5f0f\u3002

    \n\n

    \u7ed9\u5b9a\u82e5\u5e72\u4e2a\u9879\u76ee\u3002\u5bf9\u4e8e\u6bcf\u4e2a\u9879\u76ee i\uff0c\u5b83\u90fd\u6709\u4e00\u4e2a\u7eaf\u5229\u6da6 Pi\uff0c\u5e76\u4e14\u9700\u8981\u6700\u5c0f\u7684\u8d44\u672c Ci \u6765\u542f\u52a8\u76f8\u5e94\u7684\u9879\u76ee\u3002\u6700\u521d\uff0c\u4f60\u6709 W \u8d44\u672c\u3002\u5f53\u4f60\u5b8c\u6210\u4e00\u4e2a\u9879\u76ee\u65f6\uff0c\u4f60\u5c06\u83b7\u5f97\u7eaf\u5229\u6da6\uff0c\u4e14\u5229\u6da6\u5c06\u88ab\u6dfb\u52a0\u5230\u4f60\u7684\u603b\u8d44\u672c\u4e2d\u3002

    \n\n

    \u603b\u800c\u8a00\u4e4b\uff0c\u4ece\u7ed9\u5b9a\u9879\u76ee\u4e2d\u9009\u62e9\u6700\u591a k \u4e2a\u4e0d\u540c\u9879\u76ee\u7684\u5217\u8868\uff0c\u4ee5\u6700\u5927\u5316\u6700\u7ec8\u8d44\u672c\uff0c\u5e76\u8f93\u51fa\u6700\u7ec8\u53ef\u83b7\u5f97\u7684\u6700\u591a\u8d44\u672c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1ak=2, W=0, Profits=[1,2,3], Capital=[0,1,1].\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\n\u7531\u4e8e\u4f60\u7684\u521d\u59cb\u8d44\u672c\u4e3a 0\uff0c\u4f60\u4ec5\u53ef\u4ee5\u4ece 0 \u53f7\u9879\u76ee\u5f00\u59cb\u3002\n\u5728\u5b8c\u6210\u540e\uff0c\u4f60\u5c06\u83b7\u5f97 1 \u7684\u5229\u6da6\uff0c\u4f60\u7684\u603b\u8d44\u672c\u5c06\u53d8\u4e3a 1\u3002\n\u6b64\u65f6\u4f60\u53ef\u4ee5\u9009\u62e9\u5f00\u59cb 1 \u53f7\u6216 2 \u53f7\u9879\u76ee\u3002\n\u7531\u4e8e\u4f60\u6700\u591a\u53ef\u4ee5\u9009\u62e9\u4e24\u4e2a\u9879\u76ee\uff0c\u6240\u4ee5\u4f60\u9700\u8981\u5b8c\u6210 2 \u53f7\u9879\u76ee\u4ee5\u83b7\u5f97\u6700\u5927\u7684\u8d44\u672c\u3002\n\u56e0\u6b64\uff0c\u8f93\u51fa\u6700\u540e\u6700\u5927\u5316\u7684\u8d44\u672c\uff0c\u4e3a 0 + 1 + 3 = 4\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u5047\u8bbe\u6240\u6709\u8f93\u5165\u6570\u5b57\u90fd\u662f\u975e\u8d1f\u6574\u6570\u3002
    • \n\t
    • \u8868\u793a\u5229\u6da6\u548c\u8d44\u672c\u7684\u6570\u7ec4\u7684\u957f\u5ea6\u4e0d\u8d85\u8fc7 50000\u3002
    • \n\t
    • \u7b54\u6848\u4fdd\u8bc1\u5728 32 \u4f4d\u6709\u7b26\u53f7\u6574\u6570\u8303\u56f4\u5185\u3002
    • \n
    \n", "tags_en": ["Heap", "Greedy"], "tags_cn": ["\u5806", "\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findMaximizedCapital(int k, int w, vector& profits, vector& capital) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findMaximizedCapital(int k, int w, int[] profits, int[] capital) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findMaximizedCapital(self, k, w, profits, capital):\n \"\"\"\n :type k: int\n :type w: int\n :type profits: List[int]\n :type capital: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findMaximizedCapital(self, k: int, w: int, profits: List[int], capital: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findMaximizedCapital(int k, int w, int* profits, int profitsSize, int* capital, int capitalSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindMaximizedCapital(int k, int w, int[] profits, int[] capital) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} k\n * @param {number} w\n * @param {number[]} profits\n * @param {number[]} capital\n * @return {number}\n */\nvar findMaximizedCapital = function(k, w, profits, capital) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} k\n# @param {Integer} w\n# @param {Integer[]} profits\n# @param {Integer[]} capital\n# @return {Integer}\ndef find_maximized_capital(k, w, profits, capital)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findMaximizedCapital(_ k: Int, _ w: Int, _ profits: [Int], _ capital: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findMaximizedCapital(k int, w int, profits []int, capital []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findMaximizedCapital(k: Int, w: Int, profits: Array[Int], capital: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findMaximizedCapital(k: Int, w: Int, profits: IntArray, capital: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_maximized_capital(k: i32, w: i32, profits: Vec, capital: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $k\n * @param Integer $w\n * @param Integer[] $profits\n * @param Integer[] $capital\n * @return Integer\n */\n function findMaximizedCapital($k, $w, $profits, $capital) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findMaximizedCapital(k: number, w: number, profits: number[], capital: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-maximized-capital k w profits capital)\n (-> exact-integer? exact-integer? (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0502](https://leetcode-cn.com/problems/ipo)", "[IPO](/solution/0500-0599/0502.IPO/README.md)", "`\u5806`,`\u8d2a\u5fc3\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[0502](https://leetcode.com/problems/ipo)", "[IPO](/solution/0500-0599/0502.IPO/README_EN.md)", "`Heap`,`Greedy`", "Hard", ""]}, {"question_id": "0501", "frontend_question_id": "0501", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-mode-in-binary-search-tree", "url_en": "https://leetcode.com/problems/find-mode-in-binary-search-tree", "relative_path_cn": "/solution/0500-0599/0501.Find%20Mode%20in%20Binary%20Search%20Tree/README.md", "relative_path_en": "/solution/0500-0599/0501.Find%20Mode%20in%20Binary%20Search%20Tree/README_EN.md", "title_cn": "\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u7684\u4f17\u6570", "title_en": "Find Mode in Binary Search Tree", "question_title_slug": "find-mode-in-binary-search-tree", "content_en": "

    Given the root of a binary search tree (BST) with duplicates, return all the mode(s) (i.e., the most frequently occurred element) in it.

    \n\n

    If the tree has more than one mode, return them in any order.

    \n\n

    Assume a BST is defined as follows:

    \n\n
      \n\t
    • The left subtree of a node contains only nodes with keys less than or equal to the node's key.
    • \n\t
    • The right subtree of a node contains only nodes with keys greater than or equal to the node's key.
    • \n\t
    • Both the left and right subtrees must also be binary search trees.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,null,2,2]\nOutput: [2]\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = [0]\nOutput: [0]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 104].
    • \n\t
    • -105 <= Node.val <= 105
    • \n
    \n\n

     

    \nFollow up: Could you do that without using any extra space? (Assume that the implicit stack space incurred due to recursion does not count).", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6709\u76f8\u540c\u503c\u7684\u4e8c\u53c9\u641c\u7d22\u6811\uff08BST\uff09\uff0c\u627e\u51fa BST \u4e2d\u7684\u6240\u6709\u4f17\u6570\uff08\u51fa\u73b0\u9891\u7387\u6700\u9ad8\u7684\u5143\u7d20\uff09\u3002

    \n\n

    \u5047\u5b9a BST \u6709\u5982\u4e0b\u5b9a\u4e49\uff1a

    \n\n
      \n\t
    • \u7ed3\u70b9\u5de6\u5b50\u6811\u4e2d\u6240\u542b\u7ed3\u70b9\u7684\u503c\u5c0f\u4e8e\u7b49\u4e8e\u5f53\u524d\u7ed3\u70b9\u7684\u503c
    • \n\t
    • \u7ed3\u70b9\u53f3\u5b50\u6811\u4e2d\u6240\u542b\u7ed3\u70b9\u7684\u503c\u5927\u4e8e\u7b49\u4e8e\u5f53\u524d\u7ed3\u70b9\u7684\u503c
    • \n\t
    • \u5de6\u5b50\u6811\u548c\u53f3\u5b50\u6811\u90fd\u662f\u4e8c\u53c9\u641c\u7d22\u6811
    • \n
    \n\n

    \u4f8b\u5982\uff1a
    \n\u7ed9\u5b9a BST [1,null,2,2],

    \n\n
       1\n    \\\n     2\n    /\n   2\n
    \n\n

    \u8fd4\u56de[2].

    \n\n

    \u63d0\u793a\uff1a\u5982\u679c\u4f17\u6570\u8d85\u8fc71\u4e2a\uff0c\u4e0d\u9700\u8003\u8651\u8f93\u51fa\u987a\u5e8f

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u53ef\u4ee5\u4e0d\u4f7f\u7528\u989d\u5916\u7684\u7a7a\u95f4\u5417\uff1f\uff08\u5047\u8bbe\u7531\u9012\u5f52\u4ea7\u751f\u7684\u9690\u5f0f\u8c03\u7528\u6808\u7684\u5f00\u9500\u4e0d\u88ab\u8ba1\u7b97\u5728\u5185\uff09

    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector findMode(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int[] findMode(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def findMode(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def findMode(self, root: TreeNode) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* findMode(struct TreeNode* root, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int[] FindMode(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number[]}\n */\nvar findMode = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer[]}\ndef find_mode(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func findMode(_ root: TreeNode?) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc findMode(root *TreeNode) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def findMode(root: TreeNode): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun findMode(root: TreeNode?): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn find_mode(root: Option>>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer[]\n */\n function findMode($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction findMode(root: TreeNode | null): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (find-mode root)\n (-> (or/c tree-node? #f) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0501](https://leetcode-cn.com/problems/find-mode-in-binary-search-tree)", "[\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u7684\u4f17\u6570](/solution/0500-0599/0501.Find%20Mode%20in%20Binary%20Search%20Tree/README.md)", "`\u6811`", "\u7b80\u5355", ""], "md_table_row_en": ["[0501](https://leetcode.com/problems/find-mode-in-binary-search-tree)", "[Find Mode in Binary Search Tree](/solution/0500-0599/0501.Find%20Mode%20in%20Binary%20Search%20Tree/README_EN.md)", "`Tree`", "Easy", ""]}, {"question_id": "0500", "frontend_question_id": "0500", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/keyboard-row", "url_en": "https://leetcode.com/problems/keyboard-row", "relative_path_cn": "/solution/0500-0599/0500.Keyboard%20Row/README.md", "relative_path_en": "/solution/0500-0599/0500.Keyboard%20Row/README_EN.md", "title_cn": "\u952e\u76d8\u884c", "title_en": "Keyboard Row", "question_title_slug": "keyboard-row", "content_en": "

    Given an array of strings words, return the words that can be typed using letters of the alphabet on only one row of American keyboard like the image below.

    \n\n

    In the American keyboard:

    \n\n
      \n\t
    • the first row consists of the characters "qwertyuiop",
    • \n\t
    • the second row consists of the characters "asdfghjkl", and
    • \n\t
    • the third row consists of the characters "zxcvbnm".
    • \n
    \n\"\"\n

     

    \n

    Example 1:

    \n\n
    \nInput: words = ["Hello","Alaska","Dad","Peace"]\nOutput: ["Alaska","Dad"]\n
    \n\n

    Example 2:

    \n\n
    \nInput: words = ["omk"]\nOutput: []\n
    \n\n

    Example 3:

    \n\n
    \nInput: words = ["adsdf","sfd"]\nOutput: ["adsdf","sfd"]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= words.length <= 20
    • \n\t
    • 1 <= words[i].length <= 100
    • \n\t
    • words[i] consists of English letters (both lowercase and uppercase). 
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4 words \uff0c\u53ea\u8fd4\u56de\u53ef\u4ee5\u4f7f\u7528\u5728 \u7f8e\u5f0f\u952e\u76d8 \u540c\u4e00\u884c\u7684\u5b57\u6bcd\u6253\u5370\u51fa\u6765\u7684\u5355\u8bcd\u3002\u952e\u76d8\u5982\u4e0b\u56fe\u6240\u793a\u3002

    \n\n

    \u7f8e\u5f0f\u952e\u76d8 \u4e2d\uff1a

    \n\n
      \n\t
    • \u7b2c\u4e00\u884c\u7531\u5b57\u7b26 \"qwertyuiop\" \u7ec4\u6210\u3002
    • \n\t
    • \u7b2c\u4e8c\u884c\u7531\u5b57\u7b26 \"asdfghjkl\" \u7ec4\u6210\u3002
    • \n\t
    • \u7b2c\u4e09\u884c\u7531\u5b57\u7b26 \"zxcvbnm\" \u7ec4\u6210\u3002
    • \n
    \n\n

    \"American

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1awords = [\"Hello\",\"Alaska\",\"Dad\",\"Peace\"]\n\u8f93\u51fa\uff1a[\"Alaska\",\"Dad\"]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1awords = [\"omk\"]\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1awords = [\"adsdf\",\"sfd\"]\n\u8f93\u51fa\uff1a[\"adsdf\",\"sfd\"]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= words.length <= 20
    • \n\t
    • 1 <= words[i].length <= 100
    • \n\t
    • words[i] \u7531\u82f1\u6587\u5b57\u6bcd\uff08\u5c0f\u5199\u548c\u5927\u5199\u5b57\u6bcd\uff09\u7ec4\u6210
    • \n
    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findWords(vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String[] findWords(String[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findWords(self, words):\n \"\"\"\n :type words: List[str]\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findWords(self, words: List[str]) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** findWords(char ** words, int wordsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string[] FindWords(string[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @return {string[]}\n */\nvar findWords = function(words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @return {String[]}\ndef find_words(words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findWords(_ words: [String]) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findWords(words []string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findWords(words: Array[String]): Array[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findWords(words: Array): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_words(words: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @return String[]\n */\n function findWords($words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findWords(words: string[]): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-words words)\n (-> (listof string?) (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0500](https://leetcode-cn.com/problems/keyboard-row)", "[\u952e\u76d8\u884c](/solution/0500-0599/0500.Keyboard%20Row/README.md)", "`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0500](https://leetcode.com/problems/keyboard-row)", "[Keyboard Row](/solution/0500-0599/0500.Keyboard%20Row/README_EN.md)", "`Hash Table`", "Easy", ""]}, {"question_id": "0499", "frontend_question_id": "0499", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/the-maze-iii", "url_en": "https://leetcode.com/problems/the-maze-iii", "relative_path_cn": "/solution/0400-0499/0499.The%20Maze%20III/README.md", "relative_path_en": "/solution/0400-0499/0499.The%20Maze%20III/README_EN.md", "title_cn": "\u8ff7\u5bab III", "title_en": "The Maze III", "question_title_slug": "the-maze-iii", "content_en": "

    There is a ball in a maze with empty spaces (represented as 0) and walls (represented as 1). The ball can go through the empty spaces by rolling up, down, left or right, but it won't stop rolling until hitting a wall. When the ball stops, it could choose the next direction. There is also a hole in this maze. The ball will drop into the hole if it rolls onto the hole.

    \n\n

    Given the m x n maze, the ball's position ball and the hole's position hole, where ball = [ballrow, ballcol] and hole = [holerow, holecol], return a string instructions of all the instructions that the ball should follow to drop in the hole with the shortest distance possible. If there are multiple valid instructions, return the lexicographically minimum one. If the ball can't drop in the hole, return "impossible".

    \n\n

    If there is a way for the ball to drop in the hole, the answer instructions should contain the characters 'u' (i.e., up), 'd' (i.e., down), 'l' (i.e., left), and 'r' (i.e., right).

    \n\n

    The distance is the number of empty spaces traveled by the ball from the start position (excluded) to the destination (included).

    \n\n

    You may assume that the borders of the maze are all walls (see examples).

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: maze = [[0,0,0,0,0],[1,1,0,0,1],[0,0,0,0,0],[0,1,0,0,1],[0,1,0,0,0]], ball = [4,3], hole = [0,1]\nOutput: "lul"\nExplanation: There are two shortest ways for the ball to drop into the hole.\nThe first way is left -> up -> left, represented by "lul".\nThe second way is up -> left, represented by 'ul'.\nBoth ways have shortest distance 6, but the first way is lexicographically smaller because 'l' < 'u'. So the output is "lul".\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: maze = [[0,0,0,0,0],[1,1,0,0,1],[0,0,0,0,0],[0,1,0,0,1],[0,1,0,0,0]], ball = [4,3], hole = [3,0]\nOutput: "impossible"\nExplanation: The ball cannot reach the hole.\n
    \n\n

    Example 3:

    \n\n
    \nInput: maze = [[0,0,0,0,0,0,0],[0,0,1,0,0,1,0],[0,0,0,0,1,0,0],[0,0,0,0,0,0,1]], ball = [0,4], hole = [3,5]\nOutput: "dldr"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == maze.length
    • \n\t
    • n == maze[i].length
    • \n\t
    • 1 <= m, n <= 100
    • \n\t
    • maze[i][j] is 0 or 1.
    • \n\t
    • ball.length == 2
    • \n\t
    • hole.length == 2
    • \n\t
    • 0 <= ballrow, holerow <= m
    • \n\t
    • 0 <= ballcol, holecol <= n
    • \n\t
    • Both the ball and the hole exist in an empty space, and they will not be in the same position initially.
    • \n\t
    • The maze contains at least 2 empty spaces.
    • \n
    \n", "content_cn": "

    \u7531\u7a7a\u5730\u548c\u5899\u7ec4\u6210\u7684\u8ff7\u5bab\u4e2d\u6709\u4e00\u4e2a\u7403\u3002\u7403\u53ef\u4ee5\u5411\u4e0a\uff08u\uff09\u4e0b\uff08d\uff09\u5de6\uff08l\uff09\u53f3\uff08r\uff09\u56db\u4e2a\u65b9\u5411\u6eda\u52a8\uff0c\u4f46\u5728\u9047\u5230\u5899\u58c1\u524d\u4e0d\u4f1a\u505c\u6b62\u6eda\u52a8\u3002\u5f53\u7403\u505c\u4e0b\u65f6\uff0c\u53ef\u4ee5\u9009\u62e9\u4e0b\u4e00\u4e2a\u65b9\u5411\u3002\u8ff7\u5bab\u4e2d\u8fd8\u6709\u4e00\u4e2a\u6d1e\uff0c\u5f53\u7403\u8fd0\u52a8\u7ecf\u8fc7\u6d1e\u65f6\uff0c\u5c31\u4f1a\u6389\u8fdb\u6d1e\u91cc\u3002

    \n\n

    \u7ed9\u5b9a\u7403\u7684\u8d77\u59cb\u4f4d\u7f6e\uff0c\u76ee\u7684\u5730\u548c\u8ff7\u5bab\uff0c\u627e\u51fa\u8ba9\u7403\u4ee5\u6700\u77ed\u8ddd\u79bb\u6389\u8fdb\u6d1e\u91cc\u7684\u8def\u5f84\u3002 \u8ddd\u79bb\u7684\u5b9a\u4e49\u662f\u7403\u4ece\u8d77\u59cb\u4f4d\u7f6e\uff08\u4e0d\u5305\u62ec\uff09\u5230\u76ee\u7684\u5730\uff08\u5305\u62ec\uff09\u7ecf\u8fc7\u7684\u7a7a\u5730\u4e2a\u6570\u3002\u901a\u8fc7'u', 'd', 'l' \u548c 'r'\u8f93\u51fa\u7403\u7684\u79fb\u52a8\u65b9\u5411\u3002 \u7531\u4e8e\u53ef\u80fd\u6709\u591a\u6761\u6700\u77ed\u8def\u5f84\uff0c \u8bf7\u8f93\u51fa\u5b57\u5178\u5e8f\u6700\u5c0f\u7684\u8def\u5f84\u3002\u5982\u679c\u7403\u65e0\u6cd5\u8fdb\u5165\u6d1e\uff0c\u8f93\u51fa"impossible"\u3002

    \n\n

    \u8ff7\u5bab\u7531\u4e00\u4e2a0\u548c1\u7684\u4e8c\u7ef4\u6570\u7ec4\u8868\u793a\u3002 1\u8868\u793a\u5899\u58c1\uff0c0\u8868\u793a\u7a7a\u5730\u3002\u4f60\u53ef\u4ee5\u5047\u5b9a\u8ff7\u5bab\u7684\u8fb9\u7f18\u90fd\u662f\u5899\u58c1\u3002\u8d77\u59cb\u4f4d\u7f6e\u548c\u76ee\u7684\u5730\u7684\u5750\u6807\u901a\u8fc7\u884c\u53f7\u548c\u5217\u53f7\u7ed9\u51fa\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b1:

    \n\n
    \u8f93\u5165 1: \u8ff7\u5bab\u7531\u4ee5\u4e0b\u4e8c\u7ef4\u6570\u7ec4\u8868\u793a\n\n0 0 0 0 0\n1 1 0 0 1\n0 0 0 0 0\n0 1 0 0 1\n0 1 0 0 0\n\n\u8f93\u5165 2: \u7403\u7684\u521d\u59cb\u4f4d\u7f6e (rowBall, colBall) = (4, 3)\n\u8f93\u5165 3: \u6d1e\u7684\u4f4d\u7f6e (rowHole, colHole) = (0, 1)\n\n\u8f93\u51fa: "lul"\n\n\u89e3\u6790: \u6709\u4e24\u6761\u8ba9\u7403\u8fdb\u6d1e\u7684\u6700\u77ed\u8def\u5f84\u3002\n\u7b2c\u4e00\u6761\u8def\u5f84\u662f \u5de6 -> \u4e0a -> \u5de6, \u8bb0\u4e3a "lul".\n\u7b2c\u4e8c\u6761\u8def\u5f84\u662f \u4e0a -> \u5de6, \u8bb0\u4e3a 'ul'.\n\u4e24\u6761\u8def\u5f84\u90fd\u5177\u6709\u6700\u77ed\u8ddd\u79bb6, \u4f46'l' < 'u'\uff0c\u6545\u7b2c\u4e00\u6761\u8def\u5f84\u5b57\u5178\u5e8f\u66f4\u5c0f\u3002\u56e0\u6b64\u8f93\u51fa"lul"\u3002\n\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165 1: \u8ff7\u5bab\u7531\u4ee5\u4e0b\u4e8c\u7ef4\u6570\u7ec4\u8868\u793a\n\n0 0 0 0 0\n1 1 0 0 1\n0 0 0 0 0\n0 1 0 0 1\n0 1 0 0 0\n\n\u8f93\u5165 2: \u7403\u7684\u521d\u59cb\u4f4d\u7f6e (rowBall, colBall) = (4, 3)\n\u8f93\u5165 3: \u6d1e\u7684\u4f4d\u7f6e (rowHole, colHole) = (3, 0)\n\n\u8f93\u51fa: "impossible"\n\n\u793a\u4f8b: \u7403\u65e0\u6cd5\u5230\u8fbe\u6d1e\u3002\n\n
    \n\n

     

    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u8ff7\u5bab\u4e2d\u53ea\u6709\u4e00\u4e2a\u7403\u548c\u4e00\u4e2a\u76ee\u7684\u5730\u3002
    2. \n\t
    3. \u7403\u548c\u6d1e\u90fd\u5728\u7a7a\u5730\u4e0a\uff0c\u4e14\u521d\u59cb\u65f6\u5b83\u4eec\u4e0d\u5728\u540c\u4e00\u4f4d\u7f6e\u3002
    4. \n\t
    5. \u7ed9\u5b9a\u7684\u8ff7\u5bab\u4e0d\u5305\u62ec\u8fb9\u754c (\u5982\u56fe\u4e2d\u7684\u7ea2\u8272\u77e9\u5f62), \u4f46\u4f60\u53ef\u4ee5\u5047\u8bbe\u8ff7\u5bab\u7684\u8fb9\u7f18\u90fd\u662f\u5899\u58c1\u3002
    6. \n\t
    7. \u8ff7\u5bab\u81f3\u5c11\u5305\u62ec2\u5757\u7a7a\u5730\uff0c\u884c\u6570\u548c\u5217\u6570\u5747\u4e0d\u8d85\u8fc730\u3002
    8. \n
    \n", "tags_en": ["Depth-first Search", "Breadth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string findShortestWay(vector>& maze, vector& ball, vector& hole) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String findShortestWay(int[][] maze, int[] ball, int[] hole) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findShortestWay(self, maze, ball, hole):\n \"\"\"\n :type maze: List[List[int]]\n :type ball: List[int]\n :type hole: List[int]\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findShortestWay(self, maze: List[List[int]], ball: List[int], hole: List[int]) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * findShortestWay(int** maze, int mazeSize, int* mazeColSize, int* ball, int ballSize, int* hole, int holeSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string FindShortestWay(int[][] maze, int[] ball, int[] hole) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} maze\n * @param {number[]} ball\n * @param {number[]} hole\n * @return {string}\n */\nvar findShortestWay = function(maze, ball, hole) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} maze\n# @param {Integer[]} ball\n# @param {Integer[]} hole\n# @return {String}\ndef find_shortest_way(maze, ball, hole)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findShortestWay(_ maze: [[Int]], _ ball: [Int], _ hole: [Int]) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findShortestWay(maze [][]int, ball []int, hole []int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findShortestWay(maze: Array[Array[Int]], ball: Array[Int], hole: Array[Int]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findShortestWay(maze: Array, ball: IntArray, hole: IntArray): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_shortest_way(maze: Vec>, ball: Vec, hole: Vec) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $maze\n * @param Integer[] $ball\n * @param Integer[] $hole\n * @return String\n */\n function findShortestWay($maze, $ball, $hole) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findShortestWay(maze: number[][], ball: number[], hole: number[]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-shortest-way maze ball hole)\n (-> (listof (listof exact-integer?)) (listof exact-integer?) (listof exact-integer?) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0499](https://leetcode-cn.com/problems/the-maze-iii)", "[\u8ff7\u5bab III](/solution/0400-0499/0499.The%20Maze%20III/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0499](https://leetcode.com/problems/the-maze-iii)", "[The Maze III](/solution/0400-0499/0499.The%20Maze%20III/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`", "Hard", "\ud83d\udd12"]}, {"question_id": "0498", "frontend_question_id": "0498", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/diagonal-traverse", "url_en": "https://leetcode.com/problems/diagonal-traverse", "relative_path_cn": "/solution/0400-0499/0498.Diagonal%20Traverse/README.md", "relative_path_en": "/solution/0400-0499/0498.Diagonal%20Traverse/README_EN.md", "title_cn": "\u5bf9\u89d2\u7ebf\u904d\u5386", "title_en": "Diagonal Traverse", "question_title_slug": "diagonal-traverse", "content_en": "

    Given an m x n matrix mat, return an array of all the elements of the array in a diagonal order.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: mat = [[1,2,3],[4,5,6],[7,8,9]]\nOutput: [1,2,4,7,5,3,6,8,9]\n
    \n\n

    Example 2:

    \n\n
    \nInput: mat = [[1,2],[3,4]]\nOutput: [1,2,3,4]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == mat.length
    • \n\t
    • n == mat[i].length
    • \n\t
    • 1 <= m, n <= 104
    • \n\t
    • 1 <= m * n <= 104
    • \n\t
    • -105 <= mat[i][j] <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u542b\u6709 M x N \u4e2a\u5143\u7d20\u7684\u77e9\u9635\uff08M \u884c\uff0cN \u5217\uff09\uff0c\u8bf7\u4ee5\u5bf9\u89d2\u7ebf\u904d\u5386\u7684\u987a\u5e8f\u8fd4\u56de\u8fd9\u4e2a\u77e9\u9635\u4e2d\u7684\u6240\u6709\u5143\u7d20\uff0c\u5bf9\u89d2\u7ebf\u904d\u5386\u5982\u4e0b\u56fe\u6240\u793a\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165:\n[\n [ 1, 2, 3 ],\n [ 4, 5, 6 ],\n [ 7, 8, 9 ]\n]\n\n\u8f93\u51fa:  [1,2,4,7,5,3,6,8,9]\n\n\u89e3\u91ca:\n\n
    \n\n

     

    \n\n

    \u8bf4\u660e:

    \n\n
      \n\t
    1. \u7ed9\u5b9a\u77e9\u9635\u4e2d\u7684\u5143\u7d20\u603b\u6570\u4e0d\u4f1a\u8d85\u8fc7 100000 \u3002
    2. \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findDiagonalOrder(vector>& mat) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] findDiagonalOrder(int[][] mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findDiagonalOrder(self, mat):\n \"\"\"\n :type mat: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findDiagonalOrder(self, mat: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* findDiagonalOrder(int** mat, int matSize, int* matColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] FindDiagonalOrder(int[][] mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} mat\n * @return {number[]}\n */\nvar findDiagonalOrder = function(mat) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} mat\n# @return {Integer[]}\ndef find_diagonal_order(mat)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findDiagonalOrder(_ mat: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findDiagonalOrder(mat [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findDiagonalOrder(mat: Array[Array[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findDiagonalOrder(mat: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_diagonal_order(mat: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $mat\n * @return Integer[]\n */\n function findDiagonalOrder($mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findDiagonalOrder(mat: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-diagonal-order mat)\n (-> (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0498](https://leetcode-cn.com/problems/diagonal-traverse)", "[\u5bf9\u89d2\u7ebf\u904d\u5386](/solution/0400-0499/0498.Diagonal%20Traverse/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0498](https://leetcode.com/problems/diagonal-traverse)", "[Diagonal Traverse](/solution/0400-0499/0498.Diagonal%20Traverse/README_EN.md)", "", "Medium", ""]}, {"question_id": "0496", "frontend_question_id": "0496", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/next-greater-element-i", "url_en": "https://leetcode.com/problems/next-greater-element-i", "relative_path_cn": "/solution/0400-0499/0496.Next%20Greater%20Element%20I/README.md", "relative_path_en": "/solution/0400-0499/0496.Next%20Greater%20Element%20I/README_EN.md", "title_cn": "\u4e0b\u4e00\u4e2a\u66f4\u5927\u5143\u7d20 I", "title_en": "Next Greater Element I", "question_title_slug": "next-greater-element-i", "content_en": "

    You are given two integer arrays nums1 and nums2 both of unique elements, where nums1 is a subset of nums2.

    \n\n

    Find all the next greater numbers for nums1's elements in the corresponding places of nums2.

    \n\n

    The Next Greater Number of a number x in nums1 is the first greater number to its right in nums2. If it does not exist, return -1 for this number.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums1 = [4,1,2], nums2 = [1,3,4,2]\nOutput: [-1,3,-1]\nExplanation:\nFor number 4 in the first array, you cannot find the next greater number for it in the second array, so output -1.\nFor number 1 in the first array, the next greater number for it in the second array is 3.\nFor number 2 in the first array, there is no next greater number for it in the second array, so output -1.
    \n\n

    Example 2:

    \n\n
    \nInput: nums1 = [2,4], nums2 = [1,2,3,4]\nOutput: [3,-1]\nExplanation:\nFor number 2 in the first array, the next greater number for it in the second array is 3.\nFor number 4 in the first array, there is no next greater number for it in the second array, so output -1.
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums1.length <= nums2.length <= 1000
    • \n\t
    • 0 <= nums1[i], nums2[i] <= 104
    • \n\t
    • All integers in nums1 and nums2 are unique.
    • \n\t
    • All the integers of nums1 also appear in nums2.
    • \n
    \n\n

     

    \nFollow up: Could you find an O(nums1.length + nums2.length) solution?", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a \u6ca1\u6709\u91cd\u590d\u5143\u7d20 \u7684\u6570\u7ec4\u00a0nums1 \u548c\u00a0nums2\u00a0\uff0c\u5176\u4e2dnums1\u00a0\u662f\u00a0nums2\u00a0\u7684\u5b50\u96c6\u3002

    \n\n

    \u8bf7\u4f60\u627e\u51fa nums1\u00a0\u4e2d\u6bcf\u4e2a\u5143\u7d20\u5728\u00a0nums2\u00a0\u4e2d\u7684\u4e0b\u4e00\u4e2a\u6bd4\u5176\u5927\u7684\u503c\u3002

    \n\n

    nums1\u00a0\u4e2d\u6570\u5b57\u00a0x\u00a0\u7684\u4e0b\u4e00\u4e2a\u66f4\u5927\u5143\u7d20\u662f\u6307\u00a0x\u00a0\u5728\u00a0nums2\u00a0\u4e2d\u5bf9\u5e94\u4f4d\u7f6e\u7684\u53f3\u8fb9\u7684\u7b2c\u4e00\u4e2a\u6bd4\u00a0x\u00a0\u5927\u7684\u5143\u7d20\u3002\u5982\u679c\u4e0d\u5b58\u5728\uff0c\u5bf9\u5e94\u4f4d\u7f6e\u8f93\u51fa -1 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: nums1 = [4,1,2], nums2 = [1,3,4,2].\n\u8f93\u51fa: [-1,3,-1]\n\u89e3\u91ca:\n    \u5bf9\u4e8e num1 \u4e2d\u7684\u6570\u5b57 4 \uff0c\u4f60\u65e0\u6cd5\u5728\u7b2c\u4e8c\u4e2a\u6570\u7ec4\u4e2d\u627e\u5230\u4e0b\u4e00\u4e2a\u66f4\u5927\u7684\u6570\u5b57\uff0c\u56e0\u6b64\u8f93\u51fa -1 \u3002\n    \u5bf9\u4e8e num1 \u4e2d\u7684\u6570\u5b57 1 \uff0c\u7b2c\u4e8c\u4e2a\u6570\u7ec4\u4e2d\u6570\u5b571\u53f3\u8fb9\u7684\u4e0b\u4e00\u4e2a\u8f83\u5927\u6570\u5b57\u662f 3 \u3002\n    \u5bf9\u4e8e num1 \u4e2d\u7684\u6570\u5b57 2 \uff0c\u7b2c\u4e8c\u4e2a\u6570\u7ec4\u4e2d\u6ca1\u6709\u4e0b\u4e00\u4e2a\u66f4\u5927\u7684\u6570\u5b57\uff0c\u56e0\u6b64\u8f93\u51fa -1 \u3002
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: nums1 = [2,4], nums2 = [1,2,3,4].\n\u8f93\u51fa: [3,-1]\n\u89e3\u91ca:\n\u00a0   \u5bf9\u4e8e num1 \u4e2d\u7684\u6570\u5b57 2 \uff0c\u7b2c\u4e8c\u4e2a\u6570\u7ec4\u4e2d\u7684\u4e0b\u4e00\u4e2a\u8f83\u5927\u6570\u5b57\u662f 3 \u3002\n    \u5bf9\u4e8e num1 \u4e2d\u7684\u6570\u5b57 4 \uff0c\u7b2c\u4e8c\u4e2a\u6570\u7ec4\u4e2d\u6ca1\u6709\u4e0b\u4e00\u4e2a\u66f4\u5927\u7684\u6570\u5b57\uff0c\u56e0\u6b64\u8f93\u51fa -1 \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums1.length <= nums2.length <= 1000
    • \n\t
    • 0 <= nums1[i], nums2[i] <= 104
    • \n\t
    • nums1\u548cnums2\u4e2d\u6240\u6709\u6574\u6570 \u4e92\u4e0d\u76f8\u540c
    • \n\t
    • nums1 \u4e2d\u7684\u6240\u6709\u6574\u6570\u540c\u6837\u51fa\u73b0\u5728 nums2 \u4e2d
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u53ef\u4ee5\u8bbe\u8ba1\u4e00\u4e2a\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(nums1.length + nums2.length) \u7684\u89e3\u51b3\u65b9\u6848\u5417\uff1f

    \n", "tags_en": ["Stack"], "tags_cn": ["\u6808"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector nextGreaterElement(vector& nums1, vector& nums2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] nextGreaterElement(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def nextGreaterElement(self, nums1, nums2):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def nextGreaterElement(self, nums1: List[int], nums2: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* nextGreaterElement(int* nums1, int nums1Size, int* nums2, int nums2Size, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] NextGreaterElement(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums1\n * @param {number[]} nums2\n * @return {number[]}\n */\nvar nextGreaterElement = function(nums1, nums2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums1\n# @param {Integer[]} nums2\n# @return {Integer[]}\ndef next_greater_element(nums1, nums2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func nextGreaterElement(_ nums1: [Int], _ nums2: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func nextGreaterElement(nums1 []int, nums2 []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def nextGreaterElement(nums1: Array[Int], nums2: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun nextGreaterElement(nums1: IntArray, nums2: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn next_greater_element(nums1: Vec, nums2: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums1\n * @param Integer[] $nums2\n * @return Integer[]\n */\n function nextGreaterElement($nums1, $nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function nextGreaterElement(nums1: number[], nums2: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (next-greater-element nums1 nums2)\n (-> (listof exact-integer?) (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0496](https://leetcode-cn.com/problems/next-greater-element-i)", "[\u4e0b\u4e00\u4e2a\u66f4\u5927\u5143\u7d20 I](/solution/0400-0499/0496.Next%20Greater%20Element%20I/README.md)", "`\u6808`", "\u7b80\u5355", ""], "md_table_row_en": ["[0496](https://leetcode.com/problems/next-greater-element-i)", "[Next Greater Element I](/solution/0400-0499/0496.Next%20Greater%20Element%20I/README_EN.md)", "`Stack`", "Easy", ""]}, {"question_id": "0495", "frontend_question_id": "0495", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/teemo-attacking", "url_en": "https://leetcode.com/problems/teemo-attacking", "relative_path_cn": "/solution/0400-0499/0495.Teemo%20Attacking/README.md", "relative_path_en": "/solution/0400-0499/0495.Teemo%20Attacking/README_EN.md", "title_cn": "\u63d0\u83ab\u653b\u51fb", "title_en": "Teemo Attacking", "question_title_slug": "teemo-attacking", "content_en": "

    Our hero Teemo is attacking an enemy Ashe with poison attacks! When Teemo attacks Ashe, Ashe gets poisoned for a exactly duration seconds. More formally, an attack at second t will mean Ashe is poisoned during the inclusive time interval [t, t + duration - 1]. If Teemo attacks again before the poison effect ends, the timer for it is reset, and the poison effect will end duration seconds after the new attack.

    \n\n

    You are given a non-decreasing integer array timeSeries, where timeSeries[i] denotes that Teemo attacks Ashe at second timeSeries[i], and an integer duration.

    \n\n

    Return the total number of seconds that Ashe is poisoned.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: timeSeries = [1,4], duration = 2\nOutput: 4\nExplanation: Teemo's attacks on Ashe go as follows:\n- At second 1, Teemo attacks, and Ashe is poisoned for seconds 1 and 2.\n- At second 4, Teemo attacks, and Ashe is poisoned for seconds 4 and 5.\nAshe is poisoned for seconds 1, 2, 4, and 5, which is 4 seconds in total.\n
    \n\n

    Example 2:

    \n\n
    \nInput: timeSeries = [1,2], duration = 2\nOutput: 3\nExplanation: Teemo's attacks on Ashe go as follows:\n- At second 1, Teemo attacks, and Ashe is poisoned for seconds 1 and 2.\n- At second 2 however, Teemo attacks again and resets the poison timer. Ashe is poisoned for seconds 2 and 3.\nAshe is poisoned for seconds 1, 2, and 3, which is 3 seconds in total.
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= timeSeries.length <= 104
    • \n\t
    • 0 <= timeSeries[i], duration <= 107
    • \n\t
    • timeSeries is sorted in non-decreasing order.
    • \n
    \n", "content_cn": "

    \u5728\u300a\u82f1\u96c4\u8054\u76df\u300b\u7684\u4e16\u754c\u4e2d\uff0c\u6709\u4e00\u4e2a\u53eb “\u63d0\u83ab” \u7684\u82f1\u96c4\uff0c\u4ed6\u7684\u653b\u51fb\u53ef\u4ee5\u8ba9\u654c\u65b9\u82f1\u96c4\u827e\u5e0c\uff08\u7f16\u8005\u6ce8\uff1a\u5bd2\u51b0\u5c04\u624b\uff09\u8fdb\u5165\u4e2d\u6bd2\u72b6\u6001\u3002\u73b0\u5728\uff0c\u7ed9\u51fa\u63d0\u83ab\u5bf9\u827e\u5e0c\u7684\u653b\u51fb\u65f6\u95f4\u5e8f\u5217\u548c\u63d0\u83ab\u653b\u51fb\u7684\u4e2d\u6bd2\u6301\u7eed\u65f6\u95f4\uff0c\u4f60\u9700\u8981\u8f93\u51fa\u827e\u5e0c\u7684\u4e2d\u6bd2\u72b6\u6001\u603b\u65f6\u957f\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u8ba4\u4e3a\u63d0\u83ab\u5728\u7ed9\u5b9a\u7684\u65f6\u95f4\u70b9\u8fdb\u884c\u653b\u51fb\uff0c\u5e76\u7acb\u5373\u4f7f\u827e\u5e0c\u5904\u4e8e\u4e2d\u6bd2\u72b6\u6001\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b1:

    \n\n
    \u8f93\u5165: [1,4], 2\n\u8f93\u51fa: 4\n\u539f\u56e0: \u7b2c 1 \u79d2\u521d\uff0c\u63d0\u83ab\u5f00\u59cb\u5bf9\u827e\u5e0c\u8fdb\u884c\u653b\u51fb\u5e76\u4f7f\u5176\u7acb\u5373\u4e2d\u6bd2\u3002\u4e2d\u6bd2\u72b6\u6001\u4f1a\u7ef4\u6301 2 \u79d2\u949f\uff0c\u76f4\u5230\u7b2c 2 \u79d2\u672b\u7ed3\u675f\u3002\n\u7b2c 4 \u79d2\u521d\uff0c\u63d0\u83ab\u518d\u6b21\u653b\u51fb\u827e\u5e0c\uff0c\u4f7f\u5f97\u827e\u5e0c\u83b7\u5f97\u53e6\u5916 2 \u79d2\u4e2d\u6bd2\u65f6\u95f4\u3002\n\u6240\u4ee5\u6700\u7ec8\u8f93\u51fa 4 \u79d2\u3002\n
    \n\n

    \u793a\u4f8b2:

    \n\n
    \u8f93\u5165: [1,2], 2\n\u8f93\u51fa: 3\n\u539f\u56e0: \u7b2c 1 \u79d2\u521d\uff0c\u63d0\u83ab\u5f00\u59cb\u5bf9\u827e\u5e0c\u8fdb\u884c\u653b\u51fb\u5e76\u4f7f\u5176\u7acb\u5373\u4e2d\u6bd2\u3002\u4e2d\u6bd2\u72b6\u6001\u4f1a\u7ef4\u6301 2 \u79d2\u949f\uff0c\u76f4\u5230\u7b2c 2 \u79d2\u672b\u7ed3\u675f\u3002\n\u4f46\u662f\u7b2c 2 \u79d2\u521d\uff0c\u63d0\u83ab\u518d\u6b21\u653b\u51fb\u4e86\u5df2\u7ecf\u5904\u4e8e\u4e2d\u6bd2\u72b6\u6001\u7684\u827e\u5e0c\u3002\n\u7531\u4e8e\u4e2d\u6bd2\u72b6\u6001\u4e0d\u53ef\u53e0\u52a0\uff0c\u63d0\u83ab\u5728\u7b2c 2 \u79d2\u521d\u7684\u8fd9\u6b21\u653b\u51fb\u4f1a\u5728\u7b2c 3 \u79d2\u672b\u7ed3\u675f\u3002\n\u6240\u4ee5\u6700\u7ec8\u8f93\u51fa 3 \u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. \u4f60\u53ef\u4ee5\u5047\u5b9a\u65f6\u95f4\u5e8f\u5217\u6570\u7ec4\u7684\u603b\u957f\u5ea6\u4e0d\u8d85\u8fc7 10000\u3002
    2. \n\t
    3. \u4f60\u53ef\u4ee5\u5047\u5b9a\u63d0\u83ab\u653b\u51fb\u65f6\u95f4\u5e8f\u5217\u4e2d\u7684\u6570\u5b57\u548c\u63d0\u83ab\u653b\u51fb\u7684\u4e2d\u6bd2\u6301\u7eed\u65f6\u95f4\u90fd\u662f\u975e\u8d1f\u6574\u6570\uff0c\u5e76\u4e14\u4e0d\u8d85\u8fc7 10,000,000\u3002
    4. \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findPoisonedDuration(vector& timeSeries, int duration) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findPoisonedDuration(int[] timeSeries, int duration) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findPoisonedDuration(self, timeSeries, duration):\n \"\"\"\n :type timeSeries: List[int]\n :type duration: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findPoisonedDuration(self, timeSeries: List[int], duration: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findPoisonedDuration(int* timeSeries, int timeSeriesSize, int duration){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindPoisonedDuration(int[] timeSeries, int duration) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} timeSeries\n * @param {number} duration\n * @return {number}\n */\nvar findPoisonedDuration = function(timeSeries, duration) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} time_series\n# @param {Integer} duration\n# @return {Integer}\ndef find_poisoned_duration(time_series, duration)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findPoisonedDuration(_ timeSeries: [Int], _ duration: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findPoisonedDuration(timeSeries []int, duration int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findPoisonedDuration(timeSeries: Array[Int], duration: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findPoisonedDuration(timeSeries: IntArray, duration: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_poisoned_duration(time_series: Vec, duration: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $timeSeries\n * @param Integer $duration\n * @return Integer\n */\n function findPoisonedDuration($timeSeries, $duration) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findPoisonedDuration(timeSeries: number[], duration: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-poisoned-duration timeSeries duration)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0495](https://leetcode-cn.com/problems/teemo-attacking)", "[\u63d0\u83ab\u653b\u51fb](/solution/0400-0499/0495.Teemo%20Attacking/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0495](https://leetcode.com/problems/teemo-attacking)", "[Teemo Attacking](/solution/0400-0499/0495.Teemo%20Attacking/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0494", "frontend_question_id": "0494", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/target-sum", "url_en": "https://leetcode.com/problems/target-sum", "relative_path_cn": "/solution/0400-0499/0494.Target%20Sum/README.md", "relative_path_en": "/solution/0400-0499/0494.Target%20Sum/README_EN.md", "title_cn": "\u76ee\u6807\u548c", "title_en": "Target Sum", "question_title_slug": "target-sum", "content_en": "

    You are given an integer array nums and an integer target.

    \n\n

    You want to build an expression out of nums by adding one of the symbols '+' and '-' before each integer in nums and then concatenate all the integers.

    \n\n
      \n\t
    • For example, if nums = [2, 1], you can add a '+' before 2 and a '-' before 1 and concatenate them to build the expression "+2-1".
    • \n
    \n\n

    Return the number of different expressions that you can build, which evaluates to target.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,1,1,1,1], target = 3\nOutput: 5\nExplanation: There are 5 ways to assign symbols to make the sum of nums be target 3.\n-1 + 1 + 1 + 1 + 1 = 3\n+1 - 1 + 1 + 1 + 1 = 3\n+1 + 1 - 1 + 1 + 1 = 3\n+1 + 1 + 1 - 1 + 1 = 3\n+1 + 1 + 1 + 1 - 1 = 3\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1], target = 1\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 20
    • \n\t
    • 0 <= nums[i] <= 1000
    • \n\t
    • 0 <= sum(nums[i]) <= 1000
    • \n\t
    • -1000 <= target <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \u548c\u4e00\u4e2a\u6574\u6570 target \u3002

    \n\n

    \u5411\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u6574\u6570\u524d\u6dfb\u52a0\u00a0'+' \u6216 '-' \uff0c\u7136\u540e\u4e32\u8054\u8d77\u6240\u6709\u6574\u6570\uff0c\u53ef\u4ee5\u6784\u9020\u4e00\u4e2a \u8868\u8fbe\u5f0f \uff1a

    \n\n
      \n\t
    • \u4f8b\u5982\uff0cnums = [2, 1] \uff0c\u53ef\u4ee5\u5728 2 \u4e4b\u524d\u6dfb\u52a0 '+' \uff0c\u5728 1 \u4e4b\u524d\u6dfb\u52a0 '-' \uff0c\u7136\u540e\u4e32\u8054\u8d77\u6765\u5f97\u5230\u8868\u8fbe\u5f0f \"+2-1\" \u3002
    • \n
    \n\n

    \u8fd4\u56de\u53ef\u4ee5\u901a\u8fc7\u4e0a\u8ff0\u65b9\u6cd5\u6784\u9020\u7684\u3001\u8fd0\u7b97\u7ed3\u679c\u7b49\u4e8e target \u7684\u4e0d\u540c \u8868\u8fbe\u5f0f \u7684\u6570\u76ee\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,1,1,1,1], target = 3\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u4e00\u5171\u6709 5 \u79cd\u65b9\u6cd5\u8ba9\u6700\u7ec8\u76ee\u6807\u548c\u4e3a 3 \u3002\n-1 + 1 + 1 + 1 + 1 = 3\n+1 - 1 + 1 + 1 + 1 = 3\n+1 + 1 - 1 + 1 + 1 = 3\n+1 + 1 + 1 - 1 + 1 = 3\n+1 + 1 + 1 + 1 - 1 = 3\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1], target = 1\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 20
    • \n\t
    • 0 <= nums[i] <= 1000
    • \n\t
    • 0 <= sum(nums[i]) <= 1000
    • \n\t
    • -1000 <= target <= 100
    • \n
    \n", "tags_en": ["Depth-first Search", "Dynamic Programming"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findTargetSumWays(vector& nums, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findTargetSumWays(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findTargetSumWays(self, nums, target):\n \"\"\"\n :type nums: List[int]\n :type target: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findTargetSumWays(self, nums: List[int], target: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findTargetSumWays(int* nums, int numsSize, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindTargetSumWays(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} target\n * @return {number}\n */\nvar findTargetSumWays = function(nums, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} target\n# @return {Integer}\ndef find_target_sum_ways(nums, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findTargetSumWays(_ nums: [Int], _ target: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findTargetSumWays(nums []int, target int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findTargetSumWays(nums: Array[Int], target: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findTargetSumWays(nums: IntArray, target: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_target_sum_ways(nums: Vec, target: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $target\n * @return Integer\n */\n function findTargetSumWays($nums, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findTargetSumWays(nums: number[], target: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-target-sum-ways nums target)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0494](https://leetcode-cn.com/problems/target-sum)", "[\u76ee\u6807\u548c](/solution/0400-0499/0494.Target%20Sum/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0494](https://leetcode.com/problems/target-sum)", "[Target Sum](/solution/0400-0499/0494.Target%20Sum/README_EN.md)", "`Depth-first Search`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0493", "frontend_question_id": "0493", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reverse-pairs", "url_en": "https://leetcode.com/problems/reverse-pairs", "relative_path_cn": "/solution/0400-0499/0493.Reverse%20Pairs/README.md", "relative_path_en": "/solution/0400-0499/0493.Reverse%20Pairs/README_EN.md", "title_cn": "\u7ffb\u8f6c\u5bf9", "title_en": "Reverse Pairs", "question_title_slug": "reverse-pairs", "content_en": "

    Given an integer array nums, return the number of reverse pairs in the array.

    \n\n

    A reverse pair is a pair (i, j) where 0 <= i < j < nums.length and nums[i] > 2 * nums[j].

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [1,3,2,3,1]\nOutput: 2\n

    Example 2:

    \n
    Input: nums = [2,4,3,5,1]\nOutput: 3\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 5 * 104
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6570\u7ec4 nums \uff0c\u5982\u679c i < j \u4e14 nums[i] > 2*nums[j] \u6211\u4eec\u5c31\u5c06 (i, j) \u79f0\u4f5c\u4e00\u4e2a\u91cd\u8981\u7ffb\u8f6c\u5bf9\u3002

    \n\n

    \u4f60\u9700\u8981\u8fd4\u56de\u7ed9\u5b9a\u6570\u7ec4\u4e2d\u7684\u91cd\u8981\u7ffb\u8f6c\u5bf9\u7684\u6570\u91cf\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: [1,3,2,3,1]\n\u8f93\u51fa: 2\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: [2,4,3,5,1]\n\u8f93\u51fa: 3\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u7ed9\u5b9a\u6570\u7ec4\u7684\u957f\u5ea6\u4e0d\u4f1a\u8d85\u8fc750000\u3002
    2. \n\t
    3. \u8f93\u5165\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u6570\u5b57\u90fd\u572832\u4f4d\u6574\u6570\u7684\u8868\u793a\u8303\u56f4\u5185\u3002
    4. \n
    \n", "tags_en": ["Sort", "Binary Indexed Tree", "Segment Tree", "Binary Search", "Divide and Conquer"], "tags_cn": ["\u6392\u5e8f", "\u6811\u72b6\u6570\u7ec4", "\u7ebf\u6bb5\u6811", "\u4e8c\u5206\u67e5\u627e", "\u5206\u6cbb\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int reversePairs(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int reversePairs(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def reversePairs(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def reversePairs(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint reversePairs(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ReversePairs(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar reversePairs = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef reverse_pairs(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func reversePairs(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func reversePairs(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def reversePairs(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun reversePairs(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn reverse_pairs(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function reversePairs($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function reversePairs(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (reverse-pairs nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0493](https://leetcode-cn.com/problems/reverse-pairs)", "[\u7ffb\u8f6c\u5bf9](/solution/0400-0499/0493.Reverse%20Pairs/README.md)", "`\u6392\u5e8f`,`\u6811\u72b6\u6570\u7ec4`,`\u7ebf\u6bb5\u6811`,`\u4e8c\u5206\u67e5\u627e`,`\u5206\u6cbb\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[0493](https://leetcode.com/problems/reverse-pairs)", "[Reverse Pairs](/solution/0400-0499/0493.Reverse%20Pairs/README_EN.md)", "`Sort`,`Binary Indexed Tree`,`Segment Tree`,`Binary Search`,`Divide and Conquer`", "Hard", ""]}, {"question_id": "0492", "frontend_question_id": "0492", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/construct-the-rectangle", "url_en": "https://leetcode.com/problems/construct-the-rectangle", "relative_path_cn": "/solution/0400-0499/0492.Construct%20the%20Rectangle/README.md", "relative_path_en": "/solution/0400-0499/0492.Construct%20the%20Rectangle/README_EN.md", "title_cn": "\u6784\u9020\u77e9\u5f62", "title_en": "Construct the Rectangle", "question_title_slug": "construct-the-rectangle", "content_en": "

    A web developer needs to know how to design a web page's size. So, given a specific rectangular web page’s area, your job by now is to design a rectangular web page, whose length L and width W satisfy the following requirements:

    \n\n
      \n\t
    1. The area of the rectangular web page you designed must equal to the given target area.
    2. \n\t
    3. The width W should not be larger than the length L, which means L >= W.
    4. \n\t
    5. The difference between length L and width W should be as small as possible.
    6. \n
    \n\n

    Return an array [L, W] where L and W are the length and width of the web page you designed in sequence.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: area = 4\nOutput: [2,2]\nExplanation: The target area is 4, and all the possible ways to construct it are [1,4], [2,2], [4,1]. \nBut according to requirement 2, [1,4] is illegal; according to requirement 3,  [4,1] is not optimal compared to [2,2]. So the length L is 2, and the width W is 2.\n
    \n\n

    Example 2:

    \n\n
    \nInput: area = 37\nOutput: [37,1]\n
    \n\n

    Example 3:

    \n\n
    \nInput: area = 122122\nOutput: [427,286]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= area <= 107
    • \n
    \n", "content_cn": "

    \u4f5c\u4e3a\u4e00\u4f4dweb\u5f00\u53d1\u8005\uff0c \u61c2\u5f97\u600e\u6837\u53bb\u89c4\u5212\u4e00\u4e2a\u9875\u9762\u7684\u5c3a\u5bf8\u662f\u5f88\u91cd\u8981\u7684\u3002 \u73b0\u7ed9\u5b9a\u4e00\u4e2a\u5177\u4f53\u7684\u77e9\u5f62\u9875\u9762\u9762\u79ef\uff0c\u4f60\u7684\u4efb\u52a1\u662f\u8bbe\u8ba1\u4e00\u4e2a\u957f\u5ea6\u4e3a L \u548c\u5bbd\u5ea6\u4e3a W \u4e14\u6ee1\u8db3\u4ee5\u4e0b\u8981\u6c42\u7684\u77e9\u5f62\u7684\u9875\u9762\u3002\u8981\u6c42\uff1a

    \n\n
    \n1. \u4f60\u8bbe\u8ba1\u7684\u77e9\u5f62\u9875\u9762\u5fc5\u987b\u7b49\u4e8e\u7ed9\u5b9a\u7684\u76ee\u6807\u9762\u79ef\u3002\n\n2. \u5bbd\u5ea6 W \u4e0d\u5e94\u5927\u4e8e\u957f\u5ea6 L\uff0c\u6362\u8a00\u4e4b\uff0c\u8981\u6c42 L >= W \u3002\n\n3. \u957f\u5ea6 L \u548c\u5bbd\u5ea6 W \u4e4b\u95f4\u7684\u5dee\u8ddd\u5e94\u5f53\u5c3d\u53ef\u80fd\u5c0f\u3002\n
    \n\n

    \u4f60\u9700\u8981\u6309\u987a\u5e8f\u8f93\u51fa\u4f60\u8bbe\u8ba1\u7684\u9875\u9762\u7684\u957f\u5ea6 L \u548c\u5bbd\u5ea6 W\u3002

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165: 4\n\u8f93\u51fa: [2, 2]\n\u89e3\u91ca: \u76ee\u6807\u9762\u79ef\u662f 4\uff0c \u6240\u6709\u53ef\u80fd\u7684\u6784\u9020\u65b9\u6848\u6709 [1,4], [2,2], [4,1]\u3002\n\u4f46\u662f\u6839\u636e\u8981\u6c422\uff0c[1,4] \u4e0d\u7b26\u5408\u8981\u6c42; \u6839\u636e\u8981\u6c423\uff0c[2,2] \u6bd4 [4,1] \u66f4\u80fd\u7b26\u5408\u8981\u6c42. \u6240\u4ee5\u8f93\u51fa\u957f\u5ea6 L \u4e3a 2\uff0c \u5bbd\u5ea6 W \u4e3a 2\u3002\n
    \n\n

    \u8bf4\u660e:

    \n\n
      \n\t
    1. \u7ed9\u5b9a\u7684\u9762\u79ef\u4e0d\u5927\u4e8e 10,000,000 \u4e14\u4e3a\u6b63\u6574\u6570\u3002
    2. \n\t
    3. \u4f60\u8bbe\u8ba1\u7684\u9875\u9762\u7684\u957f\u5ea6\u548c\u5bbd\u5ea6\u5fc5\u987b\u90fd\u662f\u6b63\u6574\u6570\u3002
    4. \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector constructRectangle(int area) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] constructRectangle(int area) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def constructRectangle(self, area):\n \"\"\"\n :type area: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def constructRectangle(self, area: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* constructRectangle(int area, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] ConstructRectangle(int area) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} area\n * @return {number[]}\n */\nvar constructRectangle = function(area) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} area\n# @return {Integer[]}\ndef construct_rectangle(area)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func constructRectangle(_ area: Int) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func constructRectangle(area int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def constructRectangle(area: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun constructRectangle(area: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn construct_rectangle(area: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $area\n * @return Integer[]\n */\n function constructRectangle($area) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function constructRectangle(area: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (construct-rectangle area)\n (-> exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0492](https://leetcode-cn.com/problems/construct-the-rectangle)", "[\u6784\u9020\u77e9\u5f62](/solution/0400-0499/0492.Construct%20the%20Rectangle/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0492](https://leetcode.com/problems/construct-the-rectangle)", "[Construct the Rectangle](/solution/0400-0499/0492.Construct%20the%20Rectangle/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "0491", "frontend_question_id": "0491", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/increasing-subsequences", "url_en": "https://leetcode.com/problems/increasing-subsequences", "relative_path_cn": "/solution/0400-0499/0491.Increasing%20Subsequences/README.md", "relative_path_en": "/solution/0400-0499/0491.Increasing%20Subsequences/README_EN.md", "title_cn": "\u9012\u589e\u5b50\u5e8f\u5217", "title_en": "Increasing Subsequences", "question_title_slug": "increasing-subsequences", "content_en": "

    Given an integer array nums, return all the different possible increasing subsequences of the given array with at least two elements. You may return the answer in any order.

    \n\n

    The given array may contain duplicates, and two equal integers should also be considered a special case of increasing sequence.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [4,6,7,7]\nOutput: [[4,6],[4,6,7],[4,6,7,7],[4,7],[4,7,7],[6,7],[6,7,7],[7,7]]\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [4,4,3,2,1]\nOutput: [[4,4]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 15
    • \n\t
    • -100 <= nums[i] <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u578b\u6570\u7ec4, \u4f60\u7684\u4efb\u52a1\u662f\u627e\u5230\u6240\u6709\u8be5\u6570\u7ec4\u7684\u9012\u589e\u5b50\u5e8f\u5217\uff0c\u9012\u589e\u5b50\u5e8f\u5217\u7684\u957f\u5ea6\u81f3\u5c11\u662f 2 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[4, 6, 7, 7]\n\u8f93\u51fa\uff1a[[4, 6], [4, 7], [4, 6, 7], [4, 6, 7, 7], [6, 7], [6, 7, 7], [7,7], [4,7,7]]
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u7ed9\u5b9a\u6570\u7ec4\u7684\u957f\u5ea6\u4e0d\u4f1a\u8d85\u8fc715\u3002
    • \n\t
    • \u6570\u7ec4\u4e2d\u7684\u6574\u6570\u8303\u56f4\u662f\u00a0[-100,100]\u3002
    • \n\t
    • \u7ed9\u5b9a\u6570\u7ec4\u4e2d\u53ef\u80fd\u5305\u542b\u91cd\u590d\u6570\u5b57\uff0c\u76f8\u7b49\u7684\u6570\u5b57\u5e94\u8be5\u88ab\u89c6\u4e3a\u9012\u589e\u7684\u4e00\u79cd\u60c5\u51b5\u3002
    • \n
    \n", "tags_en": ["Depth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> findSubsequences(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> findSubsequences(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findSubsequences(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findSubsequences(self, nums: List[int]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** findSubsequences(int* nums, int numsSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> FindSubsequences(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number[][]}\n */\nvar findSubsequences = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer[][]}\ndef find_subsequences(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findSubsequences(_ nums: [Int]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findSubsequences(nums []int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findSubsequences(nums: Array[Int]): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findSubsequences(nums: IntArray): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_subsequences(nums: Vec) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer[][]\n */\n function findSubsequences($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findSubsequences(nums: number[]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-subsequences nums)\n (-> (listof exact-integer?) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0491](https://leetcode-cn.com/problems/increasing-subsequences)", "[\u9012\u589e\u5b50\u5e8f\u5217](/solution/0400-0499/0491.Increasing%20Subsequences/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0491](https://leetcode.com/problems/increasing-subsequences)", "[Increasing Subsequences](/solution/0400-0499/0491.Increasing%20Subsequences/README_EN.md)", "`Depth-first Search`", "Medium", ""]}, {"question_id": "0490", "frontend_question_id": "0490", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/the-maze", "url_en": "https://leetcode.com/problems/the-maze", "relative_path_cn": "/solution/0400-0499/0490.The%20Maze/README.md", "relative_path_en": "/solution/0400-0499/0490.The%20Maze/README_EN.md", "title_cn": "\u8ff7\u5bab", "title_en": "The Maze", "question_title_slug": "the-maze", "content_en": "

    There is a ball in a maze with empty spaces (represented as 0) and walls (represented as 1). The ball can go through the empty spaces by rolling up, down, left or right, but it won't stop rolling until hitting a wall. When the ball stops, it could choose the next direction.

    \n\n

    Given the m x n maze, the ball's start position and the destination, where start = [startrow, startcol] and destination = [destinationrow, destinationcol], return true if the ball can stop at the destination, otherwise return false.

    \n\n

    You may assume that the borders of the maze are all walls (see examples).

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: maze = [[0,0,1,0,0],[0,0,0,0,0],[0,0,0,1,0],[1,1,0,1,1],[0,0,0,0,0]], start = [0,4], destination = [4,4]\nOutput: true\nExplanation: One possible way is : left -> down -> left -> down -> right -> down -> right.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: maze = [[0,0,1,0,0],[0,0,0,0,0],[0,0,0,1,0],[1,1,0,1,1],[0,0,0,0,0]], start = [0,4], destination = [3,2]\nOutput: false\nExplanation: There is no way for the ball to stop at the destination. Notice that you can pass through the destination but you cannot stop there.\n
    \n\n

    Example 3:

    \n\n
    \nInput: maze = [[0,0,0,0,0],[1,1,0,0,1],[0,0,0,0,0],[0,1,0,0,1],[0,1,0,0,0]], start = [4,3], destination = [0,1]\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == maze.length
    • \n\t
    • n == maze[i].length
    • \n\t
    • 1 <= m, n <= 100
    • \n\t
    • maze[i][j] is 0 or 1.
    • \n\t
    • start.length == 2
    • \n\t
    • destination.length == 2
    • \n\t
    • 0 <= startrow, destinationrow <= m
    • \n\t
    • 0 <= startcol, destinationcol <= n
    • \n\t
    • Both the ball and the destination exist in an empty space, and they will not be in the same position initially.
    • \n\t
    • The maze contains at least 2 empty spaces.
    • \n
    \n", "content_cn": "\u7531\u7a7a\u5730\uff08\u7528 0 \u8868\u793a\uff09\u548c\u5899\uff08\u7528 1 \u8868\u793a\uff09\u7ec4\u6210\u7684\u8ff7\u5bab maze \u4e2d\u6709\u4e00\u4e2a\u7403\u3002\u7403\u53ef\u4ee5\u9014\u7ecf\u7a7a\u5730\u5411 \u4e0a\u3001\u4e0b\u3001\u5de6\u3001\u53f3 \u56db\u4e2a\u65b9\u5411\u6eda\u52a8\uff0c\u4e14\u5728\u9047\u5230\u5899\u58c1\u524d\u4e0d\u4f1a\u505c\u6b62\u6eda\u52a8\u3002\u5f53\u7403\u505c\u4e0b\u65f6\uff0c\u53ef\u4ee5\u9009\u62e9\u5411\u4e0b\u4e00\u4e2a\u65b9\u5411\u6eda\u52a8\u3002\n
    \n
    \n
    \n

    \u7ed9\u4f60\u4e00\u4e2a\u5927\u5c0f\u4e3a m x n \u7684\u8ff7\u5bab maze \uff0c\u4ee5\u53ca\u7403\u7684\u521d\u59cb\u4f4d\u7f6e start \u548c\u76ee\u7684\u5730 destination \uff0c\u5176\u4e2d start = [startrow, startcol] \u4e14 destination = [destinationrow, destinationcol] \u3002\u8bf7\u4f60\u5224\u65ad\u7403\u80fd\u5426\u5728\u76ee\u7684\u5730\u505c\u4e0b\uff1a\u5982\u679c\u53ef\u4ee5\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n

    \u4f60\u53ef\u4ee5 \u5047\u5b9a\u8ff7\u5bab\u7684\u8fb9\u7f18\u90fd\u662f\u5899\u58c1\uff08\u53c2\u8003\u793a\u4f8b\uff09\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1amaze = [[0,0,1,0,0],[0,0,0,0,0],[0,0,0,1,0],[1,1,0,1,1],[0,0,0,0,0]], start = [0,4], destination = [4,4]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u4e00\u79cd\u53ef\u80fd\u7684\u8def\u5f84\u662f : \u5de6 -> \u4e0b -> \u5de6 -> \u4e0b -> \u53f3 -> \u4e0b -> \u53f3\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1amaze = [[0,0,1,0,0],[0,0,0,0,0],[0,0,0,1,0],[1,1,0,1,1],[0,0,0,0,0]], start = [0,4], destination = [3,2]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u4e0d\u5b58\u5728\u80fd\u591f\u4f7f\u7403\u505c\u5728\u76ee\u7684\u5730\u7684\u8def\u5f84\u3002\u6ce8\u610f\uff0c\u7403\u53ef\u4ee5\u7ecf\u8fc7\u76ee\u7684\u5730\uff0c\u4f46\u65e0\u6cd5\u5728\u90a3\u91cc\u505c\u9a7b\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1amaze = [[0,0,0,0,0],[1,1,0,0,1],[0,0,0,0,0],[0,1,0,0,1],[0,1,0,0,0]], start = [4,3], destination = [0,1]\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == maze.length
    • \n\t
    • n == maze[i].length
    • \n\t
    • 1 <= m, n <= 100
    • \n\t
    • maze[i][j] is 0 or 1.
    • \n\t
    • start.length == 2
    • \n\t
    • destination.length == 2
    • \n\t
    • 0 <= startrow, destinationrow <= m
    • \n\t
    • 0 <= startcol, destinationcol <= n
    • \n\t
    • \u7403\u548c\u76ee\u7684\u5730\u90fd\u5728\u7a7a\u5730\u4e0a\uff0c\u4e14\u521d\u59cb\u65f6\u5b83\u4eec\u4e0d\u5728\u540c\u4e00\u4f4d\u7f6e
    • \n\t
    • \u8ff7\u5bab \u81f3\u5c11\u5305\u62ec 2 \u5757\u7a7a\u5730
    • \n
    \n
    \n
    \n
    \n", "tags_en": ["Depth-first Search", "Breadth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool hasPath(vector>& maze, vector& start, vector& destination) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean hasPath(int[][] maze, int[] start, int[] destination) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def hasPath(self, maze, start, destination):\n \"\"\"\n :type maze: List[List[int]]\n :type start: List[int]\n :type destination: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def hasPath(self, maze: List[List[int]], start: List[int], destination: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool hasPath(int** maze, int mazeSize, int* mazeColSize, int* start, int startSize, int* destination, int destinationSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool HasPath(int[][] maze, int[] start, int[] destination) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} maze\n * @param {number[]} start\n * @param {number[]} destination\n * @return {boolean}\n */\nvar hasPath = function(maze, start, destination) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} maze\n# @param {Integer[]} start\n# @param {Integer[]} destination\n# @return {Boolean}\ndef has_path(maze, start, destination)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func hasPath(_ maze: [[Int]], _ start: [Int], _ destination: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func hasPath(maze [][]int, start []int, destination []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def hasPath(maze: Array[Array[Int]], start: Array[Int], destination: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun hasPath(maze: Array, start: IntArray, destination: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn has_path(maze: Vec>, start: Vec, destination: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $maze\n * @param Integer[] $start\n * @param Integer[] $destination\n * @return Boolean\n */\n function hasPath($maze, $start, $destination) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function hasPath(maze: number[][], start: number[], destination: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (has-path maze start destination)\n (-> (listof (listof exact-integer?)) (listof exact-integer?) (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0490](https://leetcode-cn.com/problems/the-maze)", "[\u8ff7\u5bab](/solution/0400-0499/0490.The%20Maze/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0490](https://leetcode.com/problems/the-maze)", "[The Maze](/solution/0400-0499/0490.The%20Maze/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`", "Medium", "\ud83d\udd12"]}, {"question_id": "0489", "frontend_question_id": "1643", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/kth-smallest-instructions", "url_en": "https://leetcode.com/problems/kth-smallest-instructions", "relative_path_cn": "/solution/1600-1699/1643.Kth%20Smallest%20Instructions/README.md", "relative_path_en": "/solution/1600-1699/1643.Kth%20Smallest%20Instructions/README_EN.md", "title_cn": "\u7b2c K \u6761\u6700\u5c0f\u6307\u4ee4", "title_en": "Kth Smallest Instructions", "question_title_slug": "kth-smallest-instructions", "content_en": "

    Bob is standing at cell (0, 0), and he wants to reach destination: (row, column). He can only travel right and down. You are going to help Bob by providing instructions for him to reach destination.

    \n\n

    The instructions are represented as a string, where each character is either:

    \n\n
      \n\t
    • 'H', meaning move horizontally (go right), or
    • \n\t
    • 'V', meaning move vertically (go down).
    • \n
    \n\n

    Multiple instructions will lead Bob to destination. For example, if destination is (2, 3), both "HHHVV" and "HVHVH" are valid instructions.

    \n\n

    However, Bob is very picky. Bob has a lucky number k, and he wants the kth lexicographically smallest instructions that will lead him to destination. k is 1-indexed.

    \n\n

    Given an integer array destination and an integer k, return the kth lexicographically smallest instructions that will take Bob to destination.

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: destination = [2,3], k = 1\nOutput: "HHHVV"\nExplanation: All the instructions that reach (2, 3) in lexicographic order are as follows:\n["HHHVV", "HHVHV", "HHVVH", "HVHHV", "HVHVH", "HVVHH", "VHHHV", "VHHVH", "VHVHH", "VVHHH"].\n
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: destination = [2,3], k = 2\nOutput: "HHVHV"\n
    \n\n

    Example 3:

    \n\n

    \"\"

    \n\n
    \nInput: destination = [2,3], k = 3\nOutput: "HHVVH"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • destination.length == 2
    • \n\t
    • 1 <= row, column <= 15
    • \n\t
    • 1 <= k <= nCr(row + column, row), where nCr(a, b) denotes a choose b\u200b\u200b\u200b\u200b\u200b.
    • \n
    \n", "content_cn": "

    Bob \u7ad9\u5728\u5355\u5143\u683c (0, 0) \uff0c\u60f3\u8981\u524d\u5f80\u76ee\u7684\u5730 destination \uff1a(row, column) \u3002\u4ed6\u53ea\u80fd\u5411 \u53f3 \u6216\u5411 \u4e0b \u8d70\u3002\u4f60\u53ef\u4ee5\u4e3a Bob \u63d0\u4f9b\u5bfc\u822a \u6307\u4ee4 \u6765\u5e2e\u52a9\u4ed6\u5230\u8fbe\u76ee\u7684\u5730 destination \u3002

    \n\n

    \u6307\u4ee4 \u7528\u5b57\u7b26\u4e32\u8868\u793a\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5b57\u7b26\uff1a

    \n\n
      \n\t
    • 'H' \uff0c\u610f\u5473\u7740\u6c34\u5e73\u5411\u53f3\u79fb\u52a8
    • \n\t
    • 'V' \uff0c\u610f\u5473\u7740\u7ad6\u76f4\u5411\u4e0b\u79fb\u52a8
    • \n
    \n\n

    \u80fd\u591f\u4e3a Bob \u5bfc\u822a\u5230\u76ee\u7684\u5730 destination \u7684\u6307\u4ee4\u53ef\u4ee5\u6709\u591a\u79cd\uff0c\u4f8b\u5982\uff0c\u5982\u679c\u76ee\u7684\u5730 destination \u662f (2, 3)\uff0c\"HHHVV\" \u548c \"HVHVH\" \u90fd\u662f\u6709\u6548 \u6307\u4ee4 \u3002

    \n\n
      \n
    \n\n

    \u7136\u800c\uff0cBob \u5f88\u6311\u5254\u3002\u56e0\u4e3a\u4ed6\u7684\u5e78\u8fd0\u6570\u5b57\u662f k\uff0c\u4ed6\u60f3\u8981\u9075\u5faa \u6309\u5b57\u5178\u5e8f\u6392\u5217\u540e\u7684\u7b2c k \u6761\u6700\u5c0f\u6307\u4ee4 \u7684\u5bfc\u822a\u524d\u5f80\u76ee\u7684\u5730 destination \u3002k\u00a0 \u7684\u7f16\u53f7 \u4ece 1 \u5f00\u59cb \u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 destination \u548c\u4e00\u4e2a\u6574\u6570 k \uff0c\u8bf7\u4f60\u8fd4\u56de\u53ef\u4ee5\u4e3a Bob \u63d0\u4f9b\u524d\u5f80\u76ee\u7684\u5730\u00a0destination \u5bfc\u822a\u7684 \u6309\u5b57\u5178\u5e8f\u6392\u5217\u540e\u7684\u7b2c k \u6761\u6700\u5c0f\u6307\u4ee4 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1adestination = [2,3], k = 1\n\u8f93\u51fa\uff1a\"HHHVV\"\n\u89e3\u91ca\uff1a\u80fd\u524d\u5f80 (2, 3) \u7684\u6240\u6709\u5bfc\u822a\u6307\u4ee4 \u6309\u5b57\u5178\u5e8f\u6392\u5217\u540e \u5982\u4e0b\u6240\u793a\uff1a\n[\"HHHVV\", \"HHVHV\", \"HHVVH\", \"HVHHV\", \"HVHVH\", \"HVVHH\", \"VHHHV\", \"VHHVH\", \"VHVHH\", \"VVHHH\"].\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1adestination = [2,3], k = 2\n\u8f93\u51fa\uff1a\"HHVHV\"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1adestination = [2,3], k = 3\n\u8f93\u51fa\uff1a\"HHVVH\"\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • destination.length == 2
    • \n\t
    • 1 <= row, column <= 15
    • \n\t
    • 1 <= k <= nCr(row + column, row)\uff0c\u5176\u4e2d nCr(a, b) \u8868\u793a\u7ec4\u5408\u6570\uff0c\u5373\u4ece a \u4e2a\u7269\u54c1\u4e2d\u9009 b \u4e2a\u7269\u54c1\u7684\u4e0d\u540c\u65b9\u6848\u6570\u3002
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string kthSmallestPath(vector& destination, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String kthSmallestPath(int[] destination, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def kthSmallestPath(self, destination, k):\n \"\"\"\n :type destination: List[int]\n :type k: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def kthSmallestPath(self, destination: List[int], k: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * kthSmallestPath(int* destination, int destinationSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string KthSmallestPath(int[] destination, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} destination\n * @param {number} k\n * @return {string}\n */\nvar kthSmallestPath = function(destination, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} destination\n# @param {Integer} k\n# @return {String}\ndef kth_smallest_path(destination, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func kthSmallestPath(_ destination: [Int], _ k: Int) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func kthSmallestPath(destination []int, k int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def kthSmallestPath(destination: Array[Int], k: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun kthSmallestPath(destination: IntArray, k: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn kth_smallest_path(destination: Vec, k: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $destination\n * @param Integer $k\n * @return String\n */\n function kthSmallestPath($destination, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function kthSmallestPath(destination: number[], k: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (kth-smallest-path destination k)\n (-> (listof exact-integer?) exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1643](https://leetcode-cn.com/problems/kth-smallest-instructions)", "[\u7b2c K \u6761\u6700\u5c0f\u6307\u4ee4](/solution/1600-1699/1643.Kth%20Smallest%20Instructions/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1643](https://leetcode.com/problems/kth-smallest-instructions)", "[Kth Smallest Instructions](/solution/1600-1699/1643.Kth%20Smallest%20Instructions/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "0488", "frontend_question_id": "0488", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/zuma-game", "url_en": "https://leetcode.com/problems/zuma-game", "relative_path_cn": "/solution/0400-0499/0488.Zuma%20Game/README.md", "relative_path_en": "/solution/0400-0499/0488.Zuma%20Game/README_EN.md", "title_cn": "\u7956\u739b\u6e38\u620f", "title_en": "Zuma Game", "question_title_slug": "zuma-game", "content_en": "

    Think about Zuma Game. You have a row of balls on the table, colored red(R), yellow(Y), blue(B), green(G), and white(W). You also have several balls in your hand.

    \n\n

    Each time, you may choose a ball in your hand, and insert it into the row (including the leftmost place and rightmost place). Then, if there is a group of 3 or more balls in the same color touching, remove these balls. Keep doing this until no more balls can be removed.

    \n\n

    Find the minimal balls you have to insert to remove all the balls on the table. If you cannot remove all the balls, output -1.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: board = "WRRBBW", hand = "RB"\nOutput: -1\nExplanation: WRRBBW -> WRR[R]BBW -> WBBW -> WBB[B]W -> WW\n
    \n\n

    Example 2:

    \n\n
    \nInput: board = "WWRRBBWW", hand = "WRBRW"\nOutput: 2\nExplanation: WWRRBBWW -> WWRR[R]BBWW -> WWBBWW -> WWBB[B]WW -> WWWW -> empty\n
    \n\n

    Example 3:

    \n\n
    \nInput: board = "G", hand = "GGGGG"\nOutput: 2\nExplanation: G -> G[G] -> GG[G] -> empty \n
    \n\n

    Example 4:

    \n\n
    \nInput: board = "RBYYBBRRB", hand = "YRBGB"\nOutput: 3\nExplanation: RBYYBBRRB -> RBYY[Y]BBRRB -> RBBBRRB -> RRRB -> B -> B[B] -> BB[B] -> empty \n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • You may assume that the initial row of balls on the table won’t have any 3 or more consecutive balls with the same color.
    • \n\t
    • 1 <= board.length <= 16
    • \n\t
    • 1 <= hand.length <= 5
    • \n\t
    • Both input strings will be non-empty and only contain characters 'R','Y','B','G','W'.
    • \n
    \n", "content_cn": "

    \u56de\u5fc6\u4e00\u4e0b\u7956\u739b\u6e38\u620f\u3002\u73b0\u5728\u684c\u4e0a\u6709\u4e00\u4e32\u7403\uff0c\u989c\u8272\u6709\u7ea2\u8272(R)\uff0c\u9ec4\u8272(Y)\uff0c\u84dd\u8272(B)\uff0c\u7eff\u8272(G)\uff0c\u8fd8\u6709\u767d\u8272(W)\u3002 \u73b0\u5728\u4f60\u624b\u91cc\u4e5f\u6709\u51e0\u4e2a\u7403\u3002

    \n\n

    \u6bcf\u4e00\u6b21\uff0c\u4f60\u53ef\u4ee5\u4ece\u624b\u91cc\u7684\u7403\u9009\u4e00\u4e2a\uff0c\u7136\u540e\u628a\u8fd9\u4e2a\u7403\u63d2\u5165\u5230\u4e00\u4e32\u7403\u4e2d\u7684\u67d0\u4e2a\u4f4d\u7f6e\u4e0a\uff08\u5305\u62ec\u6700\u5de6\u7aef\uff0c\u6700\u53f3\u7aef\uff09\u3002\u63a5\u7740\uff0c\u5982\u679c\u6709\u51fa\u73b0\u4e09\u4e2a\u6216\u8005\u4e09\u4e2a\u4ee5\u4e0a\u989c\u8272\u76f8\u540c\u7684\u7403\u76f8\u8fde\u7684\u8bdd\uff0c\u5c31\u628a\u5b83\u4eec\u79fb\u9664\u6389\u3002\u91cd\u590d\u8fd9\u4e00\u6b65\u9aa4\u76f4\u5230\u684c\u4e0a\u6240\u6709\u7684\u7403\u90fd\u88ab\u79fb\u9664\u3002

    \n\n

    \u627e\u5230\u63d2\u5165\u5e76\u53ef\u4ee5\u79fb\u9664\u6389\u684c\u4e0a\u6240\u6709\u7403\u6240\u9700\u7684\u6700\u5c11\u7684\u7403\u6570\u3002\u5982\u679c\u4e0d\u80fd\u79fb\u9664\u684c\u4e0a\u6240\u6709\u7684\u7403\uff0c\u8f93\u51fa -1 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aboard = \"WRRBBW\", hand = \"RB\"\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1aWRRBBW -> WRR[R]BBW -> WBBW -> WBB[B]W -> WW\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aboard = \"WWRRBBWW\", hand = \"WRBRW\"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1aWWRRBBWW -> WWRR[R]BBWW -> WWBBWW -> WWBB[B]WW -> WWWW -> empty\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aboard = \"G\", hand = \"GGGGG\"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1aG -> G[G] -> GG[G] -> empty \n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1aboard = \"RBYYBBRRB\", hand = \"YRBGB\"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1aRBYYBBRRB -> RBYY[Y]BBRRB -> RBBBRRB -> RRRB -> B -> B[B] -> BB[B] -> empty \n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u4f60\u53ef\u4ee5\u5047\u8bbe\u684c\u4e0a\u4e00\u5f00\u59cb\u7684\u7403\u4e2d\uff0c\u4e0d\u4f1a\u6709\u4e09\u4e2a\u53ca\u4e09\u4e2a\u4ee5\u4e0a\u989c\u8272\u76f8\u540c\u4e14\u8fde\u7740\u7684\u7403\u3002
    • \n\t
    • 1 <= board.length <= 16
    • \n\t
    • 1 <= hand.length <= 5
    • \n\t
    • \u8f93\u5165\u7684\u4e24\u4e2a\u5b57\u7b26\u4e32\u5747\u4e3a\u975e\u7a7a\u5b57\u7b26\u4e32\uff0c\u4e14\u53ea\u5305\u542b\u5b57\u7b26 'R','Y','B','G','W'\u3002
    • \n
    \n", "tags_en": ["Depth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findMinStep(string board, string hand) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findMinStep(String board, String hand) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findMinStep(self, board, hand):\n \"\"\"\n :type board: str\n :type hand: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findMinStep(self, board: str, hand: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findMinStep(char * board, char * hand){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindMinStep(string board, string hand) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} board\n * @param {string} hand\n * @return {number}\n */\nvar findMinStep = function(board, hand) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} board\n# @param {String} hand\n# @return {Integer}\ndef find_min_step(board, hand)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findMinStep(_ board: String, _ hand: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findMinStep(board string, hand string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findMinStep(board: String, hand: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findMinStep(board: String, hand: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_min_step(board: String, hand: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $board\n * @param String $hand\n * @return Integer\n */\n function findMinStep($board, $hand) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findMinStep(board: string, hand: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-min-step board hand)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0488](https://leetcode-cn.com/problems/zuma-game)", "[\u7956\u739b\u6e38\u620f](/solution/0400-0499/0488.Zuma%20Game/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[0488](https://leetcode.com/problems/zuma-game)", "[Zuma Game](/solution/0400-0499/0488.Zuma%20Game/README_EN.md)", "`Depth-first Search`", "Hard", ""]}, {"question_id": "0487", "frontend_question_id": "0487", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/max-consecutive-ones-ii", "url_en": "https://leetcode.com/problems/max-consecutive-ones-ii", "relative_path_cn": "/solution/0400-0499/0487.Max%20Consecutive%20Ones%20II/README.md", "relative_path_en": "/solution/0400-0499/0487.Max%20Consecutive%20Ones%20II/README_EN.md", "title_cn": "\u6700\u5927\u8fde\u7eed1\u7684\u4e2a\u6570 II", "title_en": "Max Consecutive Ones II", "question_title_slug": "max-consecutive-ones-ii", "content_en": "

    Given a binary array nums, return the maximum number of consecutive 1's in the array if you can flip at most one 0.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,0,1,1,0]\nOutput: 4\nExplanation: Flip the first zero will get the maximum number of consecutive 1s. After flipping, the maximum number of consecutive 1s is 4.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,0,1,1,0,1]\nOutput: 4\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • nums[i] is either 0 or 1.
    • \n
    \n\n

     

    \n

    Follow up: What if the input numbers come in one by one as an infinite stream? In other words, you can't store all numbers coming from the stream as it's too large to hold in memory. Could you solve it efficiently?

    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u8fdb\u5236\u6570\u7ec4\uff0c\u4f60\u53ef\u4ee5\u6700\u591a\u5c06 1 \u4e2a 0 \u7ffb\u8f6c\u4e3a 1\uff0c\u627e\u51fa\u5176\u4e2d\u6700\u5927\u8fde\u7eed 1 \u7684\u4e2a\u6570\u3002

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a[1,0,1,1,0]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u7ffb\u8f6c\u7b2c\u4e00\u4e2a 0 \u53ef\u4ee5\u5f97\u5230\u6700\u957f\u7684\u8fde\u7eed 1\u3002\n     \u5f53\u7ffb\u8f6c\u4ee5\u540e\uff0c\u6700\u5927\u8fde\u7eed 1 \u7684\u4e2a\u6570\u4e3a 4\u3002\n
    \n\n

     

    \n\n

    \u6ce8\uff1a

    \n\n
      \n\t
    • \u8f93\u5165\u6570\u7ec4\u53ea\u5305\u542b 0 \u548c 1.
    • \n\t
    • \u8f93\u5165\u6570\u7ec4\u7684\u957f\u5ea6\u4e3a\u6b63\u6574\u6570\uff0c\u4e14\u4e0d\u8d85\u8fc7 10,000
    • \n
    \n\n

     

    \n\n

    \u8fdb\u9636\uff1a
    \n\u5982\u679c\u8f93\u5165\u7684\u6570\u5b57\u662f\u4f5c\u4e3a \u65e0\u9650\u6d41 \u9010\u4e2a\u8f93\u5165\u5982\u4f55\u5904\u7406\uff1f\u6362\u53e5\u8bdd\u8bf4\uff0c\u5185\u5b58\u4e0d\u80fd\u5b58\u50a8\u4e0b\u6240\u6709\u4ece\u6d41\u4e2d\u8f93\u5165\u7684\u6570\u5b57\u3002\u60a8\u53ef\u4ee5\u6709\u6548\u5730\u89e3\u51b3\u5417\uff1f

    \n", "tags_en": ["Two Pointers"], "tags_cn": ["\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findMaxConsecutiveOnes(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findMaxConsecutiveOnes(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findMaxConsecutiveOnes(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findMaxConsecutiveOnes(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindMaxConsecutiveOnes(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar findMaxConsecutiveOnes = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef find_max_consecutive_ones(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findMaxConsecutiveOnes(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findMaxConsecutiveOnes(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findMaxConsecutiveOnes(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findMaxConsecutiveOnes(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_max_consecutive_ones(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function findMaxConsecutiveOnes($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findMaxConsecutiveOnes(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-max-consecutive-ones nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0487](https://leetcode-cn.com/problems/max-consecutive-ones-ii)", "[\u6700\u5927\u8fde\u7eed1\u7684\u4e2a\u6570 II](/solution/0400-0499/0487.Max%20Consecutive%20Ones%20II/README.md)", "`\u53cc\u6307\u9488`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0487](https://leetcode.com/problems/max-consecutive-ones-ii)", "[Max Consecutive Ones II](/solution/0400-0499/0487.Max%20Consecutive%20Ones%20II/README_EN.md)", "`Two Pointers`", "Medium", "\ud83d\udd12"]}, {"question_id": "0486", "frontend_question_id": "0486", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/predict-the-winner", "url_en": "https://leetcode.com/problems/predict-the-winner", "relative_path_cn": "/solution/0400-0499/0486.Predict%20the%20Winner/README.md", "relative_path_en": "/solution/0400-0499/0486.Predict%20the%20Winner/README_EN.md", "title_cn": "\u9884\u6d4b\u8d62\u5bb6", "title_en": "Predict the Winner", "question_title_slug": "predict-the-winner", "content_en": "

    You are given an integer array nums. Two players are playing a game with this array: player 1 and player 2.

    \n\n

    Player 1 and player 2 take turns, with player 1 starting first. Both players start the game with a score of 0. At each turn, the player takes one of the numbers from either end of the array (i.e., nums[0] or nums[nums.length - 1]) which reduces the size of the array by 1. The player adds the chosen number to their score. The game ends when there are no more elements in the array.

    \n\n

    Return true if Player 1 can win the game. If the scores of both players are equal, then player 1 is still the winner, and you should also return true. You may assume that both players are playing optimally.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,5,2]\nOutput: false\nExplanation: Initially, player 1 can choose between 1 and 2. \nIf he chooses 2 (or 1), then player 2 can choose from 1 (or 2) and 5. If player 2 chooses 5, then player 1 will be left with 1 (or 2). \nSo, final score of player 1 is 1 + 2 = 3, and player 2 is 5. \nHence, player 1 will never be the winner and you need to return false.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,5,233,7]\nOutput: true\nExplanation: Player 1 first chooses 1. Then player 2 has to choose between 5 and 7. No matter which number player 2 choose, player 1 can choose 233.\nFinally, player 1 has more score (234) than player 2 (12), so you need to return True representing player1 can win.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 20
    • \n\t
    • 0 <= nums[i] <= 107
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u8868\u793a\u5206\u6570\u7684\u975e\u8d1f\u6574\u6570\u6570\u7ec4\u3002 \u73a9\u5bb6 1 \u4ece\u6570\u7ec4\u4efb\u610f\u4e00\u7aef\u62ff\u53d6\u4e00\u4e2a\u5206\u6570\uff0c\u968f\u540e\u73a9\u5bb6 2 \u7ee7\u7eed\u4ece\u5269\u4f59\u6570\u7ec4\u4efb\u610f\u4e00\u7aef\u62ff\u53d6\u5206\u6570\uff0c\u7136\u540e\u73a9\u5bb6 1 \u62ff\uff0c…… \u3002\u6bcf\u6b21\u4e00\u4e2a\u73a9\u5bb6\u53ea\u80fd\u62ff\u53d6\u4e00\u4e2a\u5206\u6570\uff0c\u5206\u6570\u88ab\u62ff\u53d6\u4e4b\u540e\u4e0d\u518d\u53ef\u53d6\u3002\u76f4\u5230\u6ca1\u6709\u5269\u4f59\u5206\u6570\u53ef\u53d6\u65f6\u6e38\u620f\u7ed3\u675f\u3002\u6700\u7ec8\u83b7\u5f97\u5206\u6570\u603b\u548c\u6700\u591a\u7684\u73a9\u5bb6\u83b7\u80dc\u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u8868\u793a\u5206\u6570\u7684\u6570\u7ec4\uff0c\u9884\u6d4b\u73a9\u5bb61\u662f\u5426\u4f1a\u6210\u4e3a\u8d62\u5bb6\u3002\u4f60\u53ef\u4ee5\u5047\u8bbe\u6bcf\u4e2a\u73a9\u5bb6\u7684\u73a9\u6cd5\u90fd\u4f1a\u4f7f\u4ed6\u7684\u5206\u6570\u6700\u5927\u5316\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a[1, 5, 2]\n\u8f93\u51fa\uff1aFalse\n\u89e3\u91ca\uff1a\u4e00\u5f00\u59cb\uff0c\u73a9\u5bb61\u53ef\u4ee5\u4ece1\u548c2\u4e2d\u8fdb\u884c\u9009\u62e9\u3002\n\u5982\u679c\u4ed6\u9009\u62e9 2\uff08\u6216\u8005 1 \uff09\uff0c\u90a3\u4e48\u73a9\u5bb6 2 \u53ef\u4ee5\u4ece 1\uff08\u6216\u8005 2 \uff09\u548c 5 \u4e2d\u8fdb\u884c\u9009\u62e9\u3002\u5982\u679c\u73a9\u5bb6 2 \u9009\u62e9\u4e86 5 \uff0c\u90a3\u4e48\u73a9\u5bb6 1 \u5219\u53ea\u5269\u4e0b 1\uff08\u6216\u8005 2 \uff09\u53ef\u9009\u3002\n\u6240\u4ee5\uff0c\u73a9\u5bb6 1 \u7684\u6700\u7ec8\u5206\u6570\u4e3a 1 + 2 = 3\uff0c\u800c\u73a9\u5bb6 2 \u4e3a 5 \u3002\n\u56e0\u6b64\uff0c\u73a9\u5bb6 1 \u6c38\u8fdc\u4e0d\u4f1a\u6210\u4e3a\u8d62\u5bb6\uff0c\u8fd4\u56de False \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a[1, 5, 233, 7]\n\u8f93\u51fa\uff1aTrue\n\u89e3\u91ca\uff1a\u73a9\u5bb6 1 \u4e00\u5f00\u59cb\u9009\u62e9 1 \u3002\u7136\u540e\u73a9\u5bb6 2 \u5fc5\u987b\u4ece 5 \u548c 7 \u4e2d\u8fdb\u884c\u9009\u62e9\u3002\u65e0\u8bba\u73a9\u5bb6 2 \u9009\u62e9\u4e86\u54ea\u4e2a\uff0c\u73a9\u5bb6 1 \u90fd\u53ef\u4ee5\u9009\u62e9 233 \u3002\n     \u6700\u7ec8\uff0c\u73a9\u5bb6 1\uff08234 \u5206\uff09\u6bd4\u73a9\u5bb6 2\uff0812 \u5206\uff09\u83b7\u5f97\u66f4\u591a\u7684\u5206\u6570\uff0c\u6240\u4ee5\u8fd4\u56de True\uff0c\u8868\u793a\u73a9\u5bb6 1 \u53ef\u4ee5\u6210\u4e3a\u8d62\u5bb6\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= \u7ed9\u5b9a\u7684\u6570\u7ec4\u957f\u5ea6 <= 20.
    • \n\t
    • \u6570\u7ec4\u91cc\u6240\u6709\u5206\u6570\u90fd\u4e3a\u975e\u8d1f\u6570\u4e14\u4e0d\u4f1a\u5927\u4e8e 10000000 \u3002
    • \n\t
    • \u5982\u679c\u6700\u7ec8\u4e24\u4e2a\u73a9\u5bb6\u7684\u5206\u6570\u76f8\u7b49\uff0c\u90a3\u4e48\u73a9\u5bb6 1 \u4ecd\u4e3a\u8d62\u5bb6\u3002
    • \n
    \n", "tags_en": ["Minimax", "Dynamic Programming"], "tags_cn": ["\u6781\u5c0f\u5316\u6781\u5927", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool PredictTheWinner(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean PredictTheWinner(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def PredictTheWinner(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def PredictTheWinner(self, nums: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool PredictTheWinner(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool PredictTheWinner(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {boolean}\n */\nvar PredictTheWinner = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Boolean}\ndef predict_the_winner(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func PredictTheWinner(_ nums: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func PredictTheWinner(nums []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def PredictTheWinner(nums: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun PredictTheWinner(nums: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn predict_the_winner(nums: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Boolean\n */\n function PredictTheWinner($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function PredictTheWinner(nums: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (predict-the-winner nums)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0486](https://leetcode-cn.com/problems/predict-the-winner)", "[\u9884\u6d4b\u8d62\u5bb6](/solution/0400-0499/0486.Predict%20the%20Winner/README.md)", "`\u6781\u5c0f\u5316\u6781\u5927`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0486](https://leetcode.com/problems/predict-the-winner)", "[Predict the Winner](/solution/0400-0499/0486.Predict%20the%20Winner/README_EN.md)", "`Minimax`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0485", "frontend_question_id": "0485", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/max-consecutive-ones", "url_en": "https://leetcode.com/problems/max-consecutive-ones", "relative_path_cn": "/solution/0400-0499/0485.Max%20Consecutive%20Ones/README.md", "relative_path_en": "/solution/0400-0499/0485.Max%20Consecutive%20Ones/README_EN.md", "title_cn": "\u6700\u5927\u8fde\u7eed 1 \u7684\u4e2a\u6570", "title_en": "Max Consecutive Ones", "question_title_slug": "max-consecutive-ones", "content_en": "

    Given a binary array nums, return the maximum number of consecutive 1's in the array.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,1,0,1,1,1]\nOutput: 3\nExplanation: The first two digits or the last three digits are consecutive 1s. The maximum number of consecutive 1s is 3.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,0,1,1,0,1]\nOutput: 2\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • nums[i] is either 0 or 1.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u8fdb\u5236\u6570\u7ec4\uff0c \u8ba1\u7b97\u5176\u4e2d\u6700\u5927\u8fde\u7eed 1 \u7684\u4e2a\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[1,1,0,1,1,1]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u5f00\u5934\u7684\u4e24\u4f4d\u548c\u6700\u540e\u7684\u4e09\u4f4d\u90fd\u662f\u8fde\u7eed 1 \uff0c\u6240\u4ee5\u6700\u5927\u8fde\u7eed 1 \u7684\u4e2a\u6570\u662f 3.\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u8f93\u5165\u7684\u6570\u7ec4\u53ea\u5305\u542b\u00a00 \u548c 1 \u3002
    • \n\t
    • \u8f93\u5165\u6570\u7ec4\u7684\u957f\u5ea6\u662f\u6b63\u6574\u6570\uff0c\u4e14\u4e0d\u8d85\u8fc7 10,000\u3002
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findMaxConsecutiveOnes(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findMaxConsecutiveOnes(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findMaxConsecutiveOnes(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findMaxConsecutiveOnes(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindMaxConsecutiveOnes(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar findMaxConsecutiveOnes = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef find_max_consecutive_ones(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findMaxConsecutiveOnes(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findMaxConsecutiveOnes(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findMaxConsecutiveOnes(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findMaxConsecutiveOnes(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_max_consecutive_ones(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function findMaxConsecutiveOnes($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findMaxConsecutiveOnes(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-max-consecutive-ones nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0485](https://leetcode-cn.com/problems/max-consecutive-ones)", "[\u6700\u5927\u8fde\u7eed 1 \u7684\u4e2a\u6570](/solution/0400-0499/0485.Max%20Consecutive%20Ones/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0485](https://leetcode.com/problems/max-consecutive-ones)", "[Max Consecutive Ones](/solution/0400-0499/0485.Max%20Consecutive%20Ones/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0484", "frontend_question_id": "0484", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/find-permutation", "url_en": "https://leetcode.com/problems/find-permutation", "relative_path_cn": "/solution/0400-0499/0484.Find%20Permutation/README.md", "relative_path_en": "/solution/0400-0499/0484.Find%20Permutation/README_EN.md", "title_cn": "\u5bfb\u627e\u6392\u5217", "title_en": "Find Permutation", "question_title_slug": "find-permutation", "content_en": "

    A permutation perm of n integers of all the integers in the range [1, n] can be represented as a string s of length n - 1 where:

    \n\n
      \n\t
    • s[i] == 'I' if perm[i] < perm[i + 1], and
    • \n\t
    • s[i] == 'D' if perm[i] > perm[i + 1].
    • \n
    \n\n

    Given a string s, reconstruct the lexicographically smallest permutation perm and return it.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "I"\nOutput: [1,2]\nExplanation: [1,2] is the only legal permutation that can represented by s, where the number 1 and 2 construct an increasing relationship.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "DI"\nOutput: [2,1,3]\nExplanation: Both [2,1,3] and [3,1,2] can be represented as "DI", but since we want to find the smallest lexicographical permutation, you should return [2,1,3]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 105
    • \n\t
    • s[i] is either 'I' or 'D'.
    • \n
    \n", "content_cn": "

    \u73b0\u5728\u7ed9\u5b9a\u4e00\u4e2a\u53ea\u7531\u5b57\u7b26 'D' \u548c 'I' \u7ec4\u6210\u7684 \u79d8\u5bc6\u7b7e\u540d\u3002'D' \u8868\u793a\u4e24\u4e2a\u6570\u5b57\u95f4\u7684\u9012\u51cf\u5173\u7cfb\uff0c'I' \u8868\u793a\u4e24\u4e2a\u6570\u5b57\u95f4\u7684\u9012\u589e\u5173\u7cfb\u3002\u5e76\u4e14 \u79d8\u5bc6\u7b7e\u540d \u662f\u7531\u4e00\u4e2a\u7279\u5b9a\u7684\u6574\u6570\u6570\u7ec4\u751f\u6210\u7684\uff0c\u8be5\u6570\u7ec4\u552f\u4e00\u5730\u5305\u542b 1 \u5230 n \u4e2d\u6240\u6709\u4e0d\u540c\u7684\u6570\u5b57\uff08\u79d8\u5bc6\u7b7e\u540d\u7684\u957f\u5ea6\u52a0 1 \u7b49\u4e8e n\uff09\u3002\u4f8b\u5982\uff0c\u79d8\u5bc6\u7b7e\u540d "DI" \u53ef\u4ee5\u7531\u6570\u7ec4 [2,1,3] \u6216 [3,1,2] \u751f\u6210\uff0c\u4f46\u662f\u4e0d\u80fd\u7531\u6570\u7ec4 [3,2,4] \u6216 [2,1,3,4] \u751f\u6210\uff0c\u56e0\u4e3a\u5b83\u4eec\u90fd\u4e0d\u662f\u5408\u6cd5\u7684\u80fd\u4ee3\u8868 "DI" \u79d8\u5bc6\u7b7e\u540d \u7684\u7279\u5b9a\u4e32\u3002

    \n\n

    \u73b0\u5728\u4f60\u7684\u4efb\u52a1\u662f\u627e\u5230\u5177\u6709\u6700\u5c0f\u5b57\u5178\u5e8f\u7684 [1, 2, ... n] \u7684\u6392\u5217\uff0c\u4f7f\u5176\u80fd\u4ee3\u8868\u8f93\u5165\u7684 \u79d8\u5bc6\u7b7e\u540d\u3002

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a "I"\n\u8f93\u51fa\uff1a [1,2]\n\u89e3\u91ca\uff1a [1,2] \u662f\u552f\u4e00\u5408\u6cd5\u7684\u53ef\u4ee5\u751f\u6210\u79d8\u5bc6\u7b7e\u540d "I" \u7684\u7279\u5b9a\u4e32\uff0c\u6570\u5b57 1 \u548c 2 \u6784\u6210\u9012\u589e\u5173\u7cfb\u3002\n
    \n\n

     

    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a "DI"\n\u8f93\u51fa\uff1a [2,1,3]\n\u89e3\u91ca\uff1a [2,1,3] \u548c [3,1,2] \u53ef\u4ee5\u751f\u6210\u79d8\u5bc6\u7b7e\u540d "DI"\uff0c\n\u4f46\u662f\u7531\u4e8e\u6211\u4eec\u8981\u627e\u5b57\u5178\u5e8f\u6700\u5c0f\u7684\u6392\u5217\uff0c\u56e0\u6b64\u4f60\u9700\u8981\u8f93\u51fa [2,1,3]\u3002\n
    \n\n

     

    \n\n

    \u6ce8\uff1a

    \n\n
      \n\t
    • \u8f93\u51fa\u5b57\u7b26\u4e32\u53ea\u4f1a\u5305\u542b\u5b57\u7b26 'D' \u548c 'I'\u3002
    • \n\t
    • \u8f93\u5165\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u662f\u4e00\u4e2a\u6b63\u6574\u6570\u4e14\u4e0d\u4f1a\u8d85\u8fc7 10,000\u3002
    • \n
    \n\n

     

    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findPermutation(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] findPermutation(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findPermutation(self, s):\n \"\"\"\n :type s: str\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findPermutation(self, s: str) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* findPermutation(char * s, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] FindPermutation(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number[]}\n */\nvar findPermutation = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer[]}\ndef find_permutation(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findPermutation(_ s: String) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findPermutation(s string) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findPermutation(s: String): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findPermutation(s: String): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_permutation(s: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer[]\n */\n function findPermutation($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findPermutation(s: string): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-permutation s)\n (-> string? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0484](https://leetcode-cn.com/problems/find-permutation)", "[\u5bfb\u627e\u6392\u5217](/solution/0400-0499/0484.Find%20Permutation/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0484](https://leetcode.com/problems/find-permutation)", "[Find Permutation](/solution/0400-0499/0484.Find%20Permutation/README_EN.md)", "`Greedy`", "Medium", "\ud83d\udd12"]}, {"question_id": "0483", "frontend_question_id": "0483", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/smallest-good-base", "url_en": "https://leetcode.com/problems/smallest-good-base", "relative_path_cn": "/solution/0400-0499/0483.Smallest%20Good%20Base/README.md", "relative_path_en": "/solution/0400-0499/0483.Smallest%20Good%20Base/README_EN.md", "title_cn": "\u6700\u5c0f\u597d\u8fdb\u5236", "title_en": "Smallest Good Base", "question_title_slug": "smallest-good-base", "content_en": "

    Given an integer n represented as a string, return the smallest good base of n.

    \n\n

    We call k >= 2 a good base of n, if all digits of n base k are 1's.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = "13"\nOutput: "3"\nExplanation: 13 base 3 is 111.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = "4681"\nOutput: "8"\nExplanation: 4681 base 8 is 11111.\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = "1000000000000000000"\nOutput: "999999999999999999"\nExplanation: 1000000000000000000 base 999999999999999999 is 11.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n is an integer in the range [3, 1018].
    • \n\t
    • n does not contain any leading zeros.
    • \n
    \n", "content_cn": "

    \u5bf9\u4e8e\u7ed9\u5b9a\u7684\u6574\u6570 n, \u5982\u679cn\u7684k\uff08k>=2\uff09\u8fdb\u5236\u6570\u7684\u6240\u6709\u6570\u4f4d\u5168\u4e3a1\uff0c\u5219\u79f0 k\uff08k>=2\uff09\u662f n \u7684\u4e00\u4e2a\u597d\u8fdb\u5236\u3002

    \n\n

    \u4ee5\u5b57\u7b26\u4e32\u7684\u5f62\u5f0f\u7ed9\u51fa n, \u4ee5\u5b57\u7b26\u4e32\u7684\u5f62\u5f0f\u8fd4\u56de n \u7684\u6700\u5c0f\u597d\u8fdb\u5236\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1a"13"\n\u8f93\u51fa\uff1a"3"\n\u89e3\u91ca\uff1a13 \u7684 3 \u8fdb\u5236\u662f 111\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1a"4681"\n\u8f93\u51fa\uff1a"8"\n\u89e3\u91ca\uff1a4681 \u7684 8 \u8fdb\u5236\u662f 11111\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1a"1000000000000000000"\n\u8f93\u51fa\uff1a"999999999999999999"\n\u89e3\u91ca\uff1a1000000000000000000 \u7684 999999999999999999 \u8fdb\u5236\u662f 11\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. n\u7684\u53d6\u503c\u8303\u56f4\u662f [3, 10^18]\u3002
    2. \n\t
    3. \u8f93\u5165\u603b\u662f\u6709\u6548\u4e14\u6ca1\u6709\u524d\u5bfc 0\u3002
    4. \n
    \n\n

     

    \n", "tags_en": ["Math", "Binary Search"], "tags_cn": ["\u6570\u5b66", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string smallestGoodBase(string n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String smallestGoodBase(String n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def smallestGoodBase(self, n):\n \"\"\"\n :type n: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def smallestGoodBase(self, n: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * smallestGoodBase(char * n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string SmallestGoodBase(string n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} n\n * @return {string}\n */\nvar smallestGoodBase = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} n\n# @return {String}\ndef smallest_good_base(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func smallestGoodBase(_ n: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func smallestGoodBase(n string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def smallestGoodBase(n: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun smallestGoodBase(n: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn smallest_good_base(n: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $n\n * @return String\n */\n function smallestGoodBase($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function smallestGoodBase(n: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (smallest-good-base n)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0483](https://leetcode-cn.com/problems/smallest-good-base)", "[\u6700\u5c0f\u597d\u8fdb\u5236](/solution/0400-0499/0483.Smallest%20Good%20Base/README.md)", "`\u6570\u5b66`,`\u4e8c\u5206\u67e5\u627e`", "\u56f0\u96be", ""], "md_table_row_en": ["[0483](https://leetcode.com/problems/smallest-good-base)", "[Smallest Good Base](/solution/0400-0499/0483.Smallest%20Good%20Base/README_EN.md)", "`Math`,`Binary Search`", "Hard", ""]}, {"question_id": "0482", "frontend_question_id": "0482", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/license-key-formatting", "url_en": "https://leetcode.com/problems/license-key-formatting", "relative_path_cn": "/solution/0400-0499/0482.License%20Key%20Formatting/README.md", "relative_path_en": "/solution/0400-0499/0482.License%20Key%20Formatting/README_EN.md", "title_cn": "\u5bc6\u94a5\u683c\u5f0f\u5316", "title_en": "License Key Formatting", "question_title_slug": "license-key-formatting", "content_en": "

    You are given a license key represented as a string s that consists of only alphanumeric characters and dashes. The string is separated into n + 1 groups by n dashes. You are also given an integer k.

    \n\n

    We want to reformat the string s such that each group contains exactly k characters, except for the first group, which could be shorter than k but still must contain at least one character. Furthermore, there must be a dash inserted between two groups, and you should convert all lowercase letters to uppercase.

    \n\n

    Return the reformatted license key.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "5F3Z-2e-9-w", k = 4\nOutput: "5F3Z-2E9W"\nExplanation: The string s has been split into two parts, each part has 4 characters.\nNote that the two extra dashes are not needed and can be removed.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "2-5g-3-J", k = 2\nOutput: "2-5G-3J"\nExplanation: The string s has been split into three parts, each part has 2 characters except the first part as it could be shorter as mentioned above.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 105
    • \n\t
    • s consists of English letters, digits, and dashes '-'.
    • \n\t
    • 1 <= k <= 104
    • \n
    \n", "content_cn": "

    \u6709\u4e00\u4e2a\u5bc6\u94a5\u5b57\u7b26\u4e32 S \uff0c\u53ea\u5305\u542b\u5b57\u6bcd\uff0c\u6570\u5b57\u4ee5\u53ca '-'\uff08\u7834\u6298\u53f7\uff09\u3002\u5176\u4e2d\uff0c N \u4e2a '-' \u5c06\u5b57\u7b26\u4e32\u5206\u6210\u4e86 N+1 \u7ec4\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6570\u5b57 K\uff0c\u8bf7\u4f60\u91cd\u65b0\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\uff0c\u4f7f\u6bcf\u4e2a\u5206\u7ec4\u6070\u597d\u5305\u542b K \u4e2a\u5b57\u7b26\u3002\u7279\u522b\u5730\uff0c\u7b2c\u4e00\u4e2a\u5206\u7ec4\u5305\u542b\u7684\u5b57\u7b26\u4e2a\u6570\u5fc5\u987b\u5c0f\u4e8e\u7b49\u4e8e K\uff0c\u4f46\u81f3\u5c11\u8981\u5305\u542b 1 \u4e2a\u5b57\u7b26\u3002\u4e24\u4e2a\u5206\u7ec4\u4e4b\u95f4\u9700\u8981\u7528 '-'\uff08\u7834\u6298\u53f7\uff09\u9694\u5f00\uff0c\u5e76\u4e14\u5c06\u6240\u6709\u7684\u5c0f\u5199\u5b57\u6bcd\u8f6c\u6362\u4e3a\u5927\u5199\u5b57\u6bcd\u3002

    \n\n

    \u7ed9\u5b9a\u975e\u7a7a\u5b57\u7b26\u4e32 S \u548c\u6570\u5b57 K\uff0c\u6309\u7167\u4e0a\u9762\u63cf\u8ff0\u7684\u89c4\u5219\u8fdb\u884c\u683c\u5f0f\u5316\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aS = "5F3Z-2e-9-w", K = 4\n\u8f93\u51fa\uff1a"5F3Z-2E9W"\n\u89e3\u91ca\uff1a\u5b57\u7b26\u4e32 S \u88ab\u5206\u6210\u4e86\u4e24\u4e2a\u90e8\u5206\uff0c\u6bcf\u90e8\u5206 4 \u4e2a\u5b57\u7b26\uff1b\n     \u6ce8\u610f\uff0c\u4e24\u4e2a\u989d\u5916\u7684\u7834\u6298\u53f7\u9700\u8981\u5220\u6389\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aS = "2-5g-3-J", K = 2\n\u8f93\u51fa\uff1a"2-5G-3J"\n\u89e3\u91ca\uff1a\u5b57\u7b26\u4e32 S \u88ab\u5206\u6210\u4e86 3 \u4e2a\u90e8\u5206\uff0c\u6309\u7167\u524d\u9762\u7684\u89c4\u5219\u63cf\u8ff0\uff0c\u7b2c\u4e00\u90e8\u5206\u7684\u5b57\u7b26\u53ef\u4ee5\u5c11\u4e8e\u7ed9\u5b9a\u7684\u6570\u91cf\uff0c\u5176\u4f59\u90e8\u5206\u7686\u4e3a 2 \u4e2a\u5b57\u7b26\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a:

    \n\n
      \n\t
    1. S \u7684\u957f\u5ea6\u53ef\u80fd\u5f88\u957f\uff0c\u8bf7\u6309\u9700\u5206\u914d\u5927\u5c0f\u3002K \u4e3a\u6b63\u6574\u6570\u3002
    2. \n\t
    3. S \u53ea\u5305\u542b\u5b57\u6bcd\u6570\u5b57\uff08a-z\uff0cA-Z\uff0c0-9\uff09\u4ee5\u53ca\u7834\u6298\u53f7'-'
    4. \n\t
    5. S \u975e\u7a7a
    6. \n
    \n\n

     

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string licenseKeyFormatting(string s, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String licenseKeyFormatting(String s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def licenseKeyFormatting(self, s, k):\n \"\"\"\n :type s: str\n :type k: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def licenseKeyFormatting(self, s: str, k: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * licenseKeyFormatting(char * s, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string LicenseKeyFormatting(string s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number} k\n * @return {string}\n */\nvar licenseKeyFormatting = function(s, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer} k\n# @return {String}\ndef license_key_formatting(s, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func licenseKeyFormatting(_ s: String, _ k: Int) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func licenseKeyFormatting(s string, k int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def licenseKeyFormatting(s: String, k: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun licenseKeyFormatting(s: String, k: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn license_key_formatting(s: String, k: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer $k\n * @return String\n */\n function licenseKeyFormatting($s, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function licenseKeyFormatting(s: string, k: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (license-key-formatting s k)\n (-> string? exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0482](https://leetcode-cn.com/problems/license-key-formatting)", "[\u5bc6\u94a5\u683c\u5f0f\u5316](/solution/0400-0499/0482.License%20Key%20Formatting/README.md)", "", "\u7b80\u5355", ""], "md_table_row_en": ["[0482](https://leetcode.com/problems/license-key-formatting)", "[License Key Formatting](/solution/0400-0499/0482.License%20Key%20Formatting/README_EN.md)", "", "Easy", ""]}, {"question_id": "0481", "frontend_question_id": "0481", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/magical-string", "url_en": "https://leetcode.com/problems/magical-string", "relative_path_cn": "/solution/0400-0499/0481.Magical%20String/README.md", "relative_path_en": "/solution/0400-0499/0481.Magical%20String/README_EN.md", "title_cn": "\u795e\u5947\u5b57\u7b26\u4e32", "title_en": "Magical String", "question_title_slug": "magical-string", "content_en": "

    A magical string s consists of only '1' and '2' and obeys the following rules:

    \n\n
      \n\t
    • The string s is magical because concatenating the number of contiguous occurrences of characters '1' and '2' generates the string s itself.
    • \n
    \n\n

    The first few elements of s is s = "1221121221221121122……". If we group the consecutive 1's and 2's in s, it will be "1 22 11 2 1 22 1 22 11 2 11 22 ......" and the occurrences of 1's or 2's in each group are "1 2 2 1 1 2 1 2 2 1 2 2 ......". You can see that the occurrence sequence is s itself.

    \n\n

    Given an integer n, return the number of 1's in the first n number in the magical string s.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 6\nOutput: 3\nExplanation: The first 6 elements of magical string s is "12211" and it contains three 1's, so return 3.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 1\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 105
    • \n
    \n", "content_cn": "

    \u795e\u5947\u7684\u5b57\u7b26\u4e32 \u53ea\u5305\u542b '1' \u548c '2'\uff0c\u5e76\u9075\u5b88\u4ee5\u4e0b\u89c4\u5219\uff1a

    \n\n

    \u5b57\u7b26\u4e32 S \u662f\u795e\u5947\u7684\uff0c\u56e0\u4e3a\u4e32\u8054\u5b57\u7b26 '1' \u548c '2' \u7684\u8fde\u7eed\u51fa\u73b0\u6b21\u6570\u4f1a\u751f\u6210\u5b57\u7b26\u4e32 S \u672c\u8eab\u3002

    \n\n

    \u5b57\u7b26\u4e32 \u7684\u524d\u51e0\u4e2a\u5143\u7d20\u5982\u4e0b\uff1aS = “1221121221221121122 ......”

    \n\n

    \u5982\u679c\u6211\u4eec\u5c06 S \u4e2d\u8fde\u7eed\u7684 1 \u548c 2 \u8fdb\u884c\u5206\u7ec4\uff0c\u5b83\u5c06\u53d8\u6210\uff1a

    \n\n

    1 22 11 2 1 22 1 22 11 2 11 22 ......

    \n\n

    \u5e76\u4e14\u6bcf\u4e2a\u7ec4\u4e2d '1' \u6216 '2' \u7684\u51fa\u73b0\u6b21\u6570\u5206\u522b\u662f\uff1a

    \n\n

    1 2 2 1 1 2 1 2 2 1 2 2 ......

    \n\n

    \u4f60\u53ef\u4ee5\u770b\u5230\u4e0a\u9762\u7684\u51fa\u73b0\u6b21\u6570\u5c31\u662f S \u672c\u8eab\u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570 N \u4f5c\u4e3a\u8f93\u5165\uff0c\u8fd4\u56de\u795e\u5947\u5b57\u7b26\u4e32 \u4e2d\u524d N \u4e2a\u6570\u5b57\u4e2d\u7684 '1' \u7684\u6570\u76ee\u3002

    \n\n

    \u6ce8\u610f\uff1aN \u4e0d\u4f1a\u8d85\u8fc7 100,000\u3002

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1a6\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u795e\u5947\u5b57\u7b26\u4e32 S \u7684\u524d 6 \u4e2a\u5143\u7d20\u662f “12211”\uff0c\u5b83\u5305\u542b\u4e09\u4e2a 1\uff0c\u56e0\u6b64\u8fd4\u56de 3\u3002\n
    \n\n

     

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int magicalString(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int magicalString(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def magicalString(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def magicalString(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint magicalString(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MagicalString(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar magicalString = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef magical_string(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func magicalString(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func magicalString(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def magicalString(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun magicalString(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn magical_string(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function magicalString($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function magicalString(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (magical-string n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0481](https://leetcode-cn.com/problems/magical-string)", "[\u795e\u5947\u5b57\u7b26\u4e32](/solution/0400-0499/0481.Magical%20String/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0481](https://leetcode.com/problems/magical-string)", "[Magical String](/solution/0400-0499/0481.Magical%20String/README_EN.md)", "", "Medium", ""]}, {"question_id": "0480", "frontend_question_id": "0480", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sliding-window-median", "url_en": "https://leetcode.com/problems/sliding-window-median", "relative_path_cn": "/solution/0400-0499/0480.Sliding%20Window%20Median/README.md", "relative_path_en": "/solution/0400-0499/0480.Sliding%20Window%20Median/README_EN.md", "title_cn": "\u6ed1\u52a8\u7a97\u53e3\u4e2d\u4f4d\u6570", "title_en": "Sliding Window Median", "question_title_slug": "sliding-window-median", "content_en": "

    The median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.

    \n\n
      \n\t
    • For examples, if arr = [2,3,4], the median is 3.
    • \n\t
    • For examples, if arr = [1,2,3,4], the median is (2 + 3) / 2 = 2.5.
    • \n
    \n\n

    You are given an integer array nums and an integer k. There is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window moves right by one position.

    \n\n

    Return the median array for each window in the original array. Answers within 10-5 of the actual value will be accepted.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,3,-1,-3,5,3,6,7], k = 3\nOutput: [1.00000,-1.00000,-1.00000,3.00000,5.00000,6.00000]\nExplanation: \nWindow position                Median\n---------------                -----\n[1  3  -1] -3  5  3  6  7        1\n 1 [3  -1  -3] 5  3  6  7       -1\n 1  3 [-1  -3  5] 3  6  7       -1\n 1  3  -1 [-3  5  3] 6  7        3\n 1  3  -1  -3 [5  3  6] 7        5\n 1  3  -1  -3  5 [3  6  7]       6\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,2,3,4,2,3,1,4,2], k = 3\nOutput: [2.00000,3.00000,3.00000,3.00000,2.00000,3.00000,2.00000]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= k <= nums.length <= 105
    • \n\t
    • 231 <= nums[i] <= 231 - 1
    • \n
    \n", "content_cn": "

    \u4e2d\u4f4d\u6570\u662f\u6709\u5e8f\u5e8f\u5217\u6700\u4e2d\u95f4\u7684\u90a3\u4e2a\u6570\u3002\u5982\u679c\u5e8f\u5217\u7684\u957f\u5ea6\u662f\u5076\u6570\uff0c\u5219\u6ca1\u6709\u6700\u4e2d\u95f4\u7684\u6570\uff1b\u6b64\u65f6\u4e2d\u4f4d\u6570\u662f\u6700\u4e2d\u95f4\u7684\u4e24\u4e2a\u6570\u7684\u5e73\u5747\u6570\u3002

    \n\n

    \u4f8b\u5982\uff1a

    \n\n
      \n\t
    • [2,3,4]\uff0c\u4e2d\u4f4d\u6570\u662f\u00a03
    • \n\t
    • [2,3]\uff0c\u4e2d\u4f4d\u6570\u662f (2 + 3) / 2 = 2.5
    • \n
    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 nums\uff0c\u6709\u4e00\u4e2a\u957f\u5ea6\u4e3a k \u7684\u7a97\u53e3\u4ece\u6700\u5de6\u7aef\u6ed1\u52a8\u5230\u6700\u53f3\u7aef\u3002\u7a97\u53e3\u4e2d\u6709 k \u4e2a\u6570\uff0c\u6bcf\u6b21\u7a97\u53e3\u5411\u53f3\u79fb\u52a8 1 \u4f4d\u3002\u4f60\u7684\u4efb\u52a1\u662f\u627e\u51fa\u6bcf\u6b21\u7a97\u53e3\u79fb\u52a8\u540e\u5f97\u5230\u7684\u65b0\u7a97\u53e3\u4e2d\u5143\u7d20\u7684\u4e2d\u4f4d\u6570\uff0c\u5e76\u8f93\u51fa\u7531\u5b83\u4eec\u7ec4\u6210\u7684\u6570\u7ec4\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n

    \u7ed9\u51fa\u00a0nums = [1,3,-1,-3,5,3,6,7]\uff0c\u4ee5\u53ca\u00a0k = 3\u3002

    \n\n
    \n\u7a97\u53e3\u4f4d\u7f6e                      \u4e2d\u4f4d\u6570\n---------------               -----\n[1  3  -1] -3  5  3  6  7       1\n 1 [3  -1  -3] 5  3  6  7      -1\n 1  3 [-1  -3  5] 3  6  7      -1\n 1  3  -1 [-3  5  3] 6  7       3\n 1  3  -1  -3 [5  3  6] 7       5\n 1  3  -1  -3  5 [3  6  7]      6\n
    \n\n

    \u00a0\u56e0\u6b64\uff0c\u8fd4\u56de\u8be5\u6ed1\u52a8\u7a97\u53e3\u7684\u4e2d\u4f4d\u6570\u6570\u7ec4\u00a0[1,-1,-1,3,5,6]\u3002

    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u4f60\u53ef\u4ee5\u5047\u8bbe\u00a0k\u00a0\u59cb\u7ec8\u6709\u6548\uff0c\u5373\uff1ak \u59cb\u7ec8\u5c0f\u4e8e\u7b49\u4e8e\u8f93\u5165\u7684\u975e\u7a7a\u6570\u7ec4\u7684\u5143\u7d20\u4e2a\u6570\u3002
    • \n\t
    • \u4e0e\u771f\u5b9e\u503c\u8bef\u5dee\u5728 10 ^ -5 \u4ee5\u5185\u7684\u7b54\u6848\u5c06\u88ab\u89c6\u4f5c\u6b63\u786e\u7b54\u6848\u3002
    • \n
    \n", "tags_en": ["Sliding Window"], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector medianSlidingWindow(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double[] medianSlidingWindow(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def medianSlidingWindow(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: List[float]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def medianSlidingWindow(self, nums: List[int], k: int) -> List[float]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\ndouble* medianSlidingWindow(int* nums, int numsSize, int k, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double[] MedianSlidingWindow(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number[]}\n */\nvar medianSlidingWindow = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Float[]}\ndef median_sliding_window(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func medianSlidingWindow(_ nums: [Int], _ k: Int) -> [Double] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func medianSlidingWindow(nums []int, k int) []float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def medianSlidingWindow(nums: Array[Int], k: Int): Array[Double] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun medianSlidingWindow(nums: IntArray, k: Int): DoubleArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn median_sliding_window(nums: Vec, k: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Float[]\n */\n function medianSlidingWindow($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function medianSlidingWindow(nums: number[], k: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (median-sliding-window nums k)\n (-> (listof exact-integer?) exact-integer? (listof flonum?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0480](https://leetcode-cn.com/problems/sliding-window-median)", "[\u6ed1\u52a8\u7a97\u53e3\u4e2d\u4f4d\u6570](/solution/0400-0499/0480.Sliding%20Window%20Median/README.md)", "", "\u56f0\u96be", ""], "md_table_row_en": ["[0480](https://leetcode.com/problems/sliding-window-median)", "[Sliding Window Median](/solution/0400-0499/0480.Sliding%20Window%20Median/README_EN.md)", "`Sliding Window`", "Hard", ""]}, {"question_id": "0479", "frontend_question_id": "0479", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/largest-palindrome-product", "url_en": "https://leetcode.com/problems/largest-palindrome-product", "relative_path_cn": "/solution/0400-0499/0479.Largest%20Palindrome%20Product/README.md", "relative_path_en": "/solution/0400-0499/0479.Largest%20Palindrome%20Product/README_EN.md", "title_cn": "\u6700\u5927\u56de\u6587\u6570\u4e58\u79ef", "title_en": "Largest Palindrome Product", "question_title_slug": "largest-palindrome-product", "content_en": "

    Given an integer n, return the largest palindromic integer that can be represented as the product of two n-digits integers. Since the answer can be very large, return it modulo 1337.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 2\nOutput: 987\nExplanation: 99 x 91 = 9009, 9009 % 1337 = 987\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 1\nOutput: 9\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 8
    • \n
    \n", "content_cn": "

    \u4f60\u9700\u8981\u627e\u5230\u7531\u4e24\u4e2a n \u4f4d\u6570\u7684\u4e58\u79ef\u7ec4\u6210\u7684\u6700\u5927\u56de\u6587\u6570\u3002

    \n\n

    \u7531\u4e8e\u7ed3\u679c\u4f1a\u5f88\u5927\uff0c\u4f60\u53ea\u9700\u8fd4\u56de\u6700\u5927\u56de\u6587\u6570 mod 1337\u5f97\u5230\u7684\u7ed3\u679c\u3002

    \n\n

    \u793a\u4f8b:

    \n\n

    \u8f93\u5165: 2

    \n\n

    \u8f93\u51fa: 987

    \n\n

    \u89e3\u91ca: 99 x 91 = 9009, 9009 % 1337 = 987

    \n\n

    \u8bf4\u660e:

    \n\n

    n \u7684\u53d6\u503c\u8303\u56f4\u4e3a [1,8]\u3002

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int largestPalindrome(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int largestPalindrome(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def largestPalindrome(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def largestPalindrome(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint largestPalindrome(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LargestPalindrome(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar largestPalindrome = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef largest_palindrome(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func largestPalindrome(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func largestPalindrome(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def largestPalindrome(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun largestPalindrome(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn largest_palindrome(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function largestPalindrome($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function largestPalindrome(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (largest-palindrome n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0479](https://leetcode-cn.com/problems/largest-palindrome-product)", "[\u6700\u5927\u56de\u6587\u6570\u4e58\u79ef](/solution/0400-0499/0479.Largest%20Palindrome%20Product/README.md)", "", "\u56f0\u96be", ""], "md_table_row_en": ["[0479](https://leetcode.com/problems/largest-palindrome-product)", "[Largest Palindrome Product](/solution/0400-0499/0479.Largest%20Palindrome%20Product/README_EN.md)", "", "Hard", ""]}, {"question_id": "0477", "frontend_question_id": "0477", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/total-hamming-distance", "url_en": "https://leetcode.com/problems/total-hamming-distance", "relative_path_cn": "/solution/0400-0499/0477.Total%20Hamming%20Distance/README.md", "relative_path_en": "/solution/0400-0499/0477.Total%20Hamming%20Distance/README_EN.md", "title_cn": "\u6c49\u660e\u8ddd\u79bb\u603b\u548c", "title_en": "Total Hamming Distance", "question_title_slug": "total-hamming-distance", "content_en": "

    The Hamming distance between two integers is the number of positions at which the corresponding bits are different.

    \n\n

    Given an integer array nums, return the sum of Hamming distances between all the pairs of the integers in nums.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [4,14,2]\nOutput: 6\nExplanation: In binary representation, the 4 is 0100, 14 is 1110, and 2 is 0010 (just\nshowing the four bits relevant in this case).\nThe answer will be:\nHammingDistance(4, 14) + HammingDistance(4, 2) + HammingDistance(14, 2) = 2 + 2 + 2 = 6.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [4,14,4]\nOutput: 4\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • 0 <= nums[i] <= 109
    • \n
    \n", "content_cn": "

    \u4e24\u4e2a\u6574\u6570\u7684\u00a0\u6c49\u660e\u8ddd\u79bb \u6307\u7684\u662f\u8fd9\u4e24\u4e2a\u6570\u5b57\u7684\u4e8c\u8fdb\u5236\u6570\u5bf9\u5e94\u4f4d\u4e0d\u540c\u7684\u6570\u91cf\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums\uff0c\u8bf7\u4f60\u8ba1\u7b97\u5e76\u8fd4\u56de nums \u4e2d\u4efb\u610f\u4e24\u4e2a\u6570\u4e4b\u95f4\u6c49\u660e\u8ddd\u79bb\u7684\u603b\u548c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [4,14,2]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u5728\u4e8c\u8fdb\u5236\u8868\u793a\u4e2d\uff0c4 \u8868\u793a\u4e3a 0100 \uff0c14 \u8868\u793a\u4e3a 1110 \uff0c2\u8868\u793a\u4e3a 0010 \u3002\uff08\u8fd9\u6837\u8868\u793a\u662f\u4e3a\u4e86\u4f53\u73b0\u540e\u56db\u4f4d\u4e4b\u95f4\u5173\u7cfb\uff09\n\u6240\u4ee5\u7b54\u6848\u4e3a\uff1a\nHammingDistance(4, 14) + HammingDistance(4, 2) + HammingDistance(14, 2) = 2 + 2 + 2 = 6\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [4,14,4]\n\u8f93\u51fa\uff1a4\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • 0 <= nums[i] <= 109
    • \n
    \n", "tags_en": ["Bit Manipulation"], "tags_cn": ["\u4f4d\u8fd0\u7b97"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int totalHammingDistance(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int totalHammingDistance(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def totalHammingDistance(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def totalHammingDistance(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint totalHammingDistance(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int TotalHammingDistance(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar totalHammingDistance = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef total_hamming_distance(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func totalHammingDistance(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func totalHammingDistance(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def totalHammingDistance(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun totalHammingDistance(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn total_hamming_distance(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function totalHammingDistance($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function totalHammingDistance(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (total-hamming-distance nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0477](https://leetcode-cn.com/problems/total-hamming-distance)", "[\u6c49\u660e\u8ddd\u79bb\u603b\u548c](/solution/0400-0499/0477.Total%20Hamming%20Distance/README.md)", "`\u4f4d\u8fd0\u7b97`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0477](https://leetcode.com/problems/total-hamming-distance)", "[Total Hamming Distance](/solution/0400-0499/0477.Total%20Hamming%20Distance/README_EN.md)", "`Bit Manipulation`", "Medium", ""]}, {"question_id": "0476", "frontend_question_id": "0476", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-complement", "url_en": "https://leetcode.com/problems/number-complement", "relative_path_cn": "/solution/0400-0499/0476.Number%20Complement/README.md", "relative_path_en": "/solution/0400-0499/0476.Number%20Complement/README_EN.md", "title_cn": "\u6570\u5b57\u7684\u8865\u6570", "title_en": "Number Complement", "question_title_slug": "number-complement", "content_en": "

    Given a positive integer num, output its complement number. The complement strategy is to flip the bits of its binary representation.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: num = 5\nOutput: 2\nExplanation: The binary representation of 5 is 101 (no leading zero bits), and its complement is 010. So you need to output 2.\n
    \n\n

    Example 2:

    \n\n
    \nInput: num = 1\nOutput: 0\nExplanation: The binary representation of 1 is 1 (no leading zero bits), and its complement is 0. So you need to output 0.\n
    \n\n

     

    \n

    Constraints:

    \n\n\n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a \u6b63 \u6574\u6570 num \uff0c\u8f93\u51fa\u5b83\u7684\u8865\u6570\u3002\u8865\u6570\u662f\u5bf9\u8be5\u6570\u7684\u4e8c\u8fdb\u5236\u8868\u793a\u53d6\u53cd\u3002

    \n\n

    \u00a0

    \n\n
      \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anum = 5\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a5 \u7684\u4e8c\u8fdb\u5236\u8868\u793a\u4e3a 101\uff08\u6ca1\u6709\u524d\u5bfc\u96f6\u4f4d\uff09\uff0c\u5176\u8865\u6570\u4e3a 010\u3002\u6240\u4ee5\u4f60\u9700\u8981\u8f93\u51fa 2 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anum = 1\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a1 \u7684\u4e8c\u8fdb\u5236\u8868\u793a\u4e3a 1\uff08\u6ca1\u6709\u524d\u5bfc\u96f6\u4f4d\uff09\uff0c\u5176\u8865\u6570\u4e3a 0\u3002\u6240\u4ee5\u4f60\u9700\u8981\u8f93\u51fa 0 \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u7ed9\u5b9a\u7684\u6574\u6570 num \u4fdd\u8bc1\u5728 32 \u4f4d\u5e26\u7b26\u53f7\u6574\u6570\u7684\u8303\u56f4\u5185\u3002
    • \n\t
    • num >= 1
    • \n\t
    • \u4f60\u53ef\u4ee5\u5047\u5b9a\u4e8c\u8fdb\u5236\u6570\u4e0d\u5305\u542b\u524d\u5bfc\u96f6\u4f4d\u3002
    • \n\t
    • \u672c\u9898\u4e0e 1009 https://leetcode-cn.com/problems/complement-of-base-10-integer/ \u76f8\u540c
    • \n
    \n", "tags_en": ["Bit Manipulation"], "tags_cn": ["\u4f4d\u8fd0\u7b97"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findComplement(int num) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findComplement(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findComplement(self, num):\n \"\"\"\n :type num: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findComplement(self, num: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findComplement(int num){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindComplement(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} num\n * @return {number}\n */\nvar findComplement = function(num) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} num\n# @return {Integer}\ndef find_complement(num)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findComplement(_ num: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findComplement(num int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findComplement(num: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findComplement(num: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_complement(num: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $num\n * @return Integer\n */\n function findComplement($num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findComplement(num: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-complement num)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0476](https://leetcode-cn.com/problems/number-complement)", "[\u6570\u5b57\u7684\u8865\u6570](/solution/0400-0499/0476.Number%20Complement/README.md)", "`\u4f4d\u8fd0\u7b97`", "\u7b80\u5355", ""], "md_table_row_en": ["[0476](https://leetcode.com/problems/number-complement)", "[Number Complement](/solution/0400-0499/0476.Number%20Complement/README_EN.md)", "`Bit Manipulation`", "Easy", ""]}, {"question_id": "0475", "frontend_question_id": "0475", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/heaters", "url_en": "https://leetcode.com/problems/heaters", "relative_path_cn": "/solution/0400-0499/0475.Heaters/README.md", "relative_path_en": "/solution/0400-0499/0475.Heaters/README_EN.md", "title_cn": "\u4f9b\u6696\u5668", "title_en": "Heaters", "question_title_slug": "heaters", "content_en": "

    Winter is coming! During the contest, your first job is to design a standard heater with a fixed warm radius to warm all the houses.

    \n\n

    Every house can be warmed, as long as the house is within the heater's warm radius range. 

    \n\n

    Given the positions of houses and heaters on a horizontal line, return the minimum radius standard of heaters so that those heaters could cover all houses.

    \n\n

    Notice that all the heaters follow your radius standard, and the warm radius will the same.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: houses = [1,2,3], heaters = [2]\nOutput: 1\nExplanation: The only heater was placed in the position 2, and if we use the radius 1 standard, then all the houses can be warmed.\n
    \n\n

    Example 2:

    \n\n
    \nInput: houses = [1,2,3,4], heaters = [1,4]\nOutput: 1\nExplanation: The two heater was placed in the position 1 and 4. We need to use radius 1 standard, then all the houses can be warmed.\n
    \n\n

    Example 3:

    \n\n
    \nInput: houses = [1,5], heaters = [2]\nOutput: 3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= houses.length, heaters.length <= 3 * 104
    • \n\t
    • 1 <= houses[i], heaters[i] <= 109
    • \n
    \n", "content_cn": "

    \u51ac\u5b63\u5df2\u7ecf\u6765\u4e34\u3002\u00a0\u4f60\u7684\u4efb\u52a1\u662f\u8bbe\u8ba1\u4e00\u4e2a\u6709\u56fa\u5b9a\u52a0\u70ed\u534a\u5f84\u7684\u4f9b\u6696\u5668\u5411\u6240\u6709\u623f\u5c4b\u4f9b\u6696\u3002

    \n\n

    \u5728\u52a0\u70ed\u5668\u7684\u52a0\u70ed\u534a\u5f84\u8303\u56f4\u5185\u7684\u6bcf\u4e2a\u623f\u5c4b\u90fd\u53ef\u4ee5\u83b7\u5f97\u4f9b\u6696\u3002

    \n\n

    \u73b0\u5728\uff0c\u7ed9\u51fa\u4f4d\u4e8e\u4e00\u6761\u6c34\u5e73\u7ebf\u4e0a\u7684\u623f\u5c4b\u00a0houses \u548c\u4f9b\u6696\u5668\u00a0heaters \u7684\u4f4d\u7f6e\uff0c\u8bf7\u4f60\u627e\u51fa\u5e76\u8fd4\u56de\u53ef\u4ee5\u8986\u76d6\u6240\u6709\u623f\u5c4b\u7684\u6700\u5c0f\u52a0\u70ed\u534a\u5f84\u3002

    \n\n

    \u8bf4\u660e\uff1a\u6240\u6709\u4f9b\u6696\u5668\u90fd\u9075\u5faa\u4f60\u7684\u534a\u5f84\u6807\u51c6\uff0c\u52a0\u70ed\u7684\u534a\u5f84\u4e5f\u4e00\u6837\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: houses = [1,2,3], heaters = [2]\n\u8f93\u51fa: 1\n\u89e3\u91ca: \u4ec5\u5728\u4f4d\u7f6e2\u4e0a\u6709\u4e00\u4e2a\u4f9b\u6696\u5668\u3002\u5982\u679c\u6211\u4eec\u5c06\u52a0\u70ed\u534a\u5f84\u8bbe\u4e3a1\uff0c\u90a3\u4e48\u6240\u6709\u623f\u5c4b\u5c31\u90fd\u80fd\u5f97\u5230\u4f9b\u6696\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: houses = [1,2,3,4], heaters = [1,4]\n\u8f93\u51fa: 1\n\u89e3\u91ca: \u5728\u4f4d\u7f6e1, 4\u4e0a\u6709\u4e24\u4e2a\u4f9b\u6696\u5668\u3002\u6211\u4eec\u9700\u8981\u5c06\u52a0\u70ed\u534a\u5f84\u8bbe\u4e3a1\uff0c\u8fd9\u6837\u6240\u6709\u623f\u5c4b\u5c31\u90fd\u80fd\u5f97\u5230\u4f9b\u6696\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahouses = [1,5], heaters = [2]\n\u8f93\u51fa\uff1a3\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= houses.length, heaters.length <= 3 * 104
    • \n\t
    • 1 <= houses[i], heaters[i] <= 109
    • \n
    \n", "tags_en": ["Binary Search"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findRadius(vector& houses, vector& heaters) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findRadius(int[] houses, int[] heaters) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findRadius(self, houses, heaters):\n \"\"\"\n :type houses: List[int]\n :type heaters: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findRadius(self, houses: List[int], heaters: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findRadius(int* houses, int housesSize, int* heaters, int heatersSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindRadius(int[] houses, int[] heaters) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} houses\n * @param {number[]} heaters\n * @return {number}\n */\nvar findRadius = function(houses, heaters) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} houses\n# @param {Integer[]} heaters\n# @return {Integer}\ndef find_radius(houses, heaters)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findRadius(_ houses: [Int], _ heaters: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findRadius(houses []int, heaters []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findRadius(houses: Array[Int], heaters: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findRadius(houses: IntArray, heaters: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_radius(houses: Vec, heaters: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $houses\n * @param Integer[] $heaters\n * @return Integer\n */\n function findRadius($houses, $heaters) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findRadius(houses: number[], heaters: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-radius houses heaters)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0475](https://leetcode-cn.com/problems/heaters)", "[\u4f9b\u6696\u5668](/solution/0400-0499/0475.Heaters/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0475](https://leetcode.com/problems/heaters)", "[Heaters](/solution/0400-0499/0475.Heaters/README_EN.md)", "`Binary Search`", "Medium", ""]}, {"question_id": "0474", "frontend_question_id": "0474", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/ones-and-zeroes", "url_en": "https://leetcode.com/problems/ones-and-zeroes", "relative_path_cn": "/solution/0400-0499/0474.Ones%20and%20Zeroes/README.md", "relative_path_en": "/solution/0400-0499/0474.Ones%20and%20Zeroes/README_EN.md", "title_cn": "\u4e00\u548c\u96f6", "title_en": "Ones and Zeroes", "question_title_slug": "ones-and-zeroes", "content_en": "

    You are given an array of binary strings strs and two integers m and n.

    \n\n

    Return the size of the largest subset of strs such that there are at most m 0's and n 1's in the subset.

    \n\n

    A set x is a subset of a set y if all elements of x are also elements of y.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: strs = ["10","0001","111001","1","0"], m = 5, n = 3\nOutput: 4\nExplanation: The largest subset with at most 5 0's and 3 1's is {"10", "0001", "1", "0"}, so the answer is 4.\nOther valid but smaller subsets include {"0001", "1"} and {"10", "1", "0"}.\n{"111001"} is an invalid subset because it contains 4 1's, greater than the maximum of 3.\n
    \n\n

    Example 2:

    \n\n
    \nInput: strs = ["10","0","1"], m = 1, n = 1\nOutput: 2\nExplanation: The largest subset is {"0", "1"}, so the answer is 2.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= strs.length <= 600
    • \n\t
    • 1 <= strs[i].length <= 100
    • \n\t
    • strs[i] consists only of digits '0' and '1'.
    • \n\t
    • 1 <= m, n <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32\u6570\u7ec4 strs \u548c\u4e24\u4e2a\u6574\u6570 m \u548c n \u3002

    \n\n
    \n

    \u8bf7\u4f60\u627e\u51fa\u5e76\u8fd4\u56de strs \u7684\u6700\u5927\u5b50\u96c6\u7684\u5927\u5c0f\uff0c\u8be5\u5b50\u96c6\u4e2d \u6700\u591a \u6709 m \u4e2a 0 \u548c n \u4e2a 1 \u3002

    \n\n

    \u5982\u679c x \u7684\u6240\u6709\u5143\u7d20\u4e5f\u662f y \u7684\u5143\u7d20\uff0c\u96c6\u5408 x \u662f\u96c6\u5408 y \u7684 \u5b50\u96c6 \u3002

    \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1astrs = [\"10\", \"0001\", \"111001\", \"1\", \"0\"], m = 5, n = 3\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u6700\u591a\u6709 5 \u4e2a 0 \u548c 3 \u4e2a 1 \u7684\u6700\u5927\u5b50\u96c6\u662f {\"10\",\"0001\",\"1\",\"0\"} \uff0c\u56e0\u6b64\u7b54\u6848\u662f 4 \u3002\n\u5176\u4ed6\u6ee1\u8db3\u9898\u610f\u4f46\u8f83\u5c0f\u7684\u5b50\u96c6\u5305\u62ec {\"0001\",\"1\"} \u548c {\"10\",\"1\",\"0\"} \u3002{\"111001\"} \u4e0d\u6ee1\u8db3\u9898\u610f\uff0c\u56e0\u4e3a\u5b83\u542b 4 \u4e2a 1 \uff0c\u5927\u4e8e n \u7684\u503c 3 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1astrs = [\"10\", \"0\", \"1\"], m = 1, n = 1\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6700\u5927\u7684\u5b50\u96c6\u662f {\"0\", \"1\"} \uff0c\u6240\u4ee5\u7b54\u6848\u662f 2 \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= strs.length <= 600
    • \n\t
    • 1 <= strs[i].length <= 100
    • \n\t
    • strs[i]\u00a0\u4ec5\u7531\u00a0'0' \u548c\u00a0'1' \u7ec4\u6210
    • \n\t
    • 1 <= m, n <= 100
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findMaxForm(vector& strs, int m, int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findMaxForm(String[] strs, int m, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findMaxForm(self, strs, m, n):\n \"\"\"\n :type strs: List[str]\n :type m: int\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findMaxForm(self, strs: List[str], m: int, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findMaxForm(char ** strs, int strsSize, int m, int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindMaxForm(string[] strs, int m, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} strs\n * @param {number} m\n * @param {number} n\n * @return {number}\n */\nvar findMaxForm = function(strs, m, n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} strs\n# @param {Integer} m\n# @param {Integer} n\n# @return {Integer}\ndef find_max_form(strs, m, n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findMaxForm(_ strs: [String], _ m: Int, _ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findMaxForm(strs []string, m int, n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findMaxForm(strs: Array[String], m: Int, n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findMaxForm(strs: Array, m: Int, n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_max_form(strs: Vec, m: i32, n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $strs\n * @param Integer $m\n * @param Integer $n\n * @return Integer\n */\n function findMaxForm($strs, $m, $n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findMaxForm(strs: string[], m: number, n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-max-form strs m n)\n (-> (listof string?) exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0474](https://leetcode-cn.com/problems/ones-and-zeroes)", "[\u4e00\u548c\u96f6](/solution/0400-0499/0474.Ones%20and%20Zeroes/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0474](https://leetcode.com/problems/ones-and-zeroes)", "[Ones and Zeroes](/solution/0400-0499/0474.Ones%20and%20Zeroes/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0473", "frontend_question_id": "0473", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/matchsticks-to-square", "url_en": "https://leetcode.com/problems/matchsticks-to-square", "relative_path_cn": "/solution/0400-0499/0473.Matchsticks%20to%20Square/README.md", "relative_path_en": "/solution/0400-0499/0473.Matchsticks%20to%20Square/README_EN.md", "title_cn": "\u706b\u67f4\u62fc\u6b63\u65b9\u5f62", "title_en": "Matchsticks to Square", "question_title_slug": "matchsticks-to-square", "content_en": "

    You are given an integer array matchsticks where matchsticks[i] is the length of the ith matchstick. You want to use all the matchsticks to make one square. You should not break any stick, but you can link them up, and each matchstick must be used exactly one time.

    \n\n

    Return true if you can make this square and false otherwise.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: matchsticks = [1,1,2,2,2]\nOutput: true\nExplanation: You can form a square with length 2, one side of the square came two sticks with length 1.\n
    \n\n

    Example 2:

    \n\n
    \nInput: matchsticks = [3,3,3,3,4]\nOutput: false\nExplanation: You cannot find a way to form a square with all the matchsticks.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= matchsticks.length <= 15
    • \n\t
    • 0 <= matchsticks[i] <= 109
    • \n
    \n", "content_cn": "

    \u8fd8\u8bb0\u5f97\u7ae5\u8bdd\u300a\u5356\u706b\u67f4\u7684\u5c0f\u5973\u5b69\u300b\u5417\uff1f\u73b0\u5728\uff0c\u4f60\u77e5\u9053\u5c0f\u5973\u5b69\u6709\u591a\u5c11\u6839\u706b\u67f4\uff0c\u8bf7\u627e\u51fa\u4e00\u79cd\u80fd\u4f7f\u7528\u6240\u6709\u706b\u67f4\u62fc\u6210\u4e00\u4e2a\u6b63\u65b9\u5f62\u7684\u65b9\u6cd5\u3002\u4e0d\u80fd\u6298\u65ad\u706b\u67f4\uff0c\u53ef\u4ee5\u628a\u706b\u67f4\u8fde\u63a5\u8d77\u6765\uff0c\u5e76\u4e14\u6bcf\u6839\u706b\u67f4\u90fd\u8981\u7528\u5230\u3002

    \n\n

    \u8f93\u5165\u4e3a\u5c0f\u5973\u5b69\u62e5\u6709\u706b\u67f4\u7684\u6570\u76ee\uff0c\u6bcf\u6839\u706b\u67f4\u7528\u5176\u957f\u5ea6\u8868\u793a\u3002\u8f93\u51fa\u5373\u4e3a\u662f\u5426\u80fd\u7528\u6240\u6709\u7684\u706b\u67f4\u62fc\u6210\u6b63\u65b9\u5f62\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: [1,1,2,2,2]\n\u8f93\u51fa: true\n\n\u89e3\u91ca: \u80fd\u62fc\u6210\u4e00\u4e2a\u8fb9\u957f\u4e3a2\u7684\u6b63\u65b9\u5f62\uff0c\u6bcf\u8fb9\u4e24\u6839\u706b\u67f4\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: [3,3,3,3,4]\n\u8f93\u51fa: false\n\n\u89e3\u91ca: \u4e0d\u80fd\u7528\u6240\u6709\u706b\u67f4\u62fc\u6210\u4e00\u4e2a\u6b63\u65b9\u5f62\u3002\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u7ed9\u5b9a\u7684\u706b\u67f4\u957f\u5ea6\u548c\u5728 0 \u5230 10^9\u4e4b\u95f4\u3002
    2. \n\t
    3. \u706b\u67f4\u6570\u7ec4\u7684\u957f\u5ea6\u4e0d\u8d85\u8fc715\u3002
    4. \n
    \n", "tags_en": ["Depth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool makesquare(vector& matchsticks) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean makesquare(int[] matchsticks) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def makesquare(self, matchsticks):\n \"\"\"\n :type matchsticks: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def makesquare(self, matchsticks: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool makesquare(int* matchsticks, int matchsticksSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool Makesquare(int[] matchsticks) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} matchsticks\n * @return {boolean}\n */\nvar makesquare = function(matchsticks) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} matchsticks\n# @return {Boolean}\ndef makesquare(matchsticks)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func makesquare(_ matchsticks: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func makesquare(matchsticks []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def makesquare(matchsticks: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun makesquare(matchsticks: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn makesquare(matchsticks: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $matchsticks\n * @return Boolean\n */\n function makesquare($matchsticks) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function makesquare(matchsticks: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (makesquare matchsticks)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0473](https://leetcode-cn.com/problems/matchsticks-to-square)", "[\u706b\u67f4\u62fc\u6b63\u65b9\u5f62](/solution/0400-0499/0473.Matchsticks%20to%20Square/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0473](https://leetcode.com/problems/matchsticks-to-square)", "[Matchsticks to Square](/solution/0400-0499/0473.Matchsticks%20to%20Square/README_EN.md)", "`Depth-first Search`", "Medium", ""]}, {"question_id": "0472", "frontend_question_id": "0472", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/concatenated-words", "url_en": "https://leetcode.com/problems/concatenated-words", "relative_path_cn": "/solution/0400-0499/0472.Concatenated%20Words/README.md", "relative_path_en": "/solution/0400-0499/0472.Concatenated%20Words/README_EN.md", "title_cn": "\u8fde\u63a5\u8bcd", "title_en": "Concatenated Words", "question_title_slug": "concatenated-words", "content_en": "

    Given an array of strings words (without duplicates), return all the concatenated words in the given list of words.

    \n\n

    A concatenated word is defined as a string that is comprised entirely of at least two shorter words in the given array.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: words = ["cat","cats","catsdogcats","dog","dogcatsdog","hippopotamuses","rat","ratcatdogcat"]\nOutput: ["catsdogcats","dogcatsdog","ratcatdogcat"]\nExplanation: "catsdogcats" can be concatenated by "cats", "dog" and "cats"; \n"dogcatsdog" can be concatenated by "dog", "cats" and "dog"; \n"ratcatdogcat" can be concatenated by "rat", "cat", "dog" and "cat".
    \n\n

    Example 2:

    \n\n
    \nInput: words = ["cat","dog","catdog"]\nOutput: ["catdog"]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= words.length <= 104
    • \n\t
    • 0 <= words[i].length <= 1000
    • \n\t
    • words[i] consists of only lowercase English letters.
    • \n\t
    • 0 <= sum(words[i].length) <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a \u4e0d\u542b\u91cd\u590d \u5355\u8bcd\u7684\u5b57\u7b26\u4e32\u6570\u7ec4 words \uff0c\u7f16\u5199\u4e00\u4e2a\u7a0b\u5e8f\uff0c\u8fd4\u56de\u00a0words \u4e2d\u7684\u6240\u6709 \u8fde\u63a5\u8bcd \u3002

    \n\n

    \u8fde\u63a5\u8bcd \u7684\u5b9a\u4e49\u4e3a\uff1a\u4e00\u4e2a\u5b57\u7b26\u4e32\u5b8c\u5168\u662f\u7531\u81f3\u5c11\u4e24\u4e2a\u7ed9\u5b9a\u6570\u7ec4\u4e2d\u7684\u5355\u8bcd\u7ec4\u6210\u7684\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1awords = [\"cat\",\"cats\",\"catsdogcats\",\"dog\",\"dogcatsdog\",\"hippopotamuses\",\"rat\",\"ratcatdogcat\"]\n\u8f93\u51fa\uff1a[\"catsdogcats\",\"dogcatsdog\",\"ratcatdogcat\"]\n\u89e3\u91ca\uff1a\"catsdogcats\"\u7531\"cats\", \"dog\" \u548c \"cats\"\u7ec4\u6210; \n     \"dogcatsdog\"\u7531\"dog\", \"cats\"\u548c\"dog\"\u7ec4\u6210; \n     \"ratcatdogcat\"\u7531\"rat\", \"cat\", \"dog\"\u548c\"cat\"\u7ec4\u6210\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1awords = [\"cat\",\"dog\",\"catdog\"]\n\u8f93\u51fa\uff1a[\"catdog\"]
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= words.length <= 104
    • \n\t
    • 0 <= words[i].length <= 1000
    • \n\t
    • words[i] \u4ec5\u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210
    • \n\t
    • 0 <= sum(words[i].length) <= 6 * 105
    • \n
    \n", "tags_en": ["Depth-first Search", "Trie", "Dynamic Programming"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5b57\u5178\u6811", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findAllConcatenatedWordsInADict(vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List findAllConcatenatedWordsInADict(String[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findAllConcatenatedWordsInADict(self, words):\n \"\"\"\n :type words: List[str]\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findAllConcatenatedWordsInADict(self, words: List[str]) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** findAllConcatenatedWordsInADict(char ** words, int wordsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList FindAllConcatenatedWordsInADict(string[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @return {string[]}\n */\nvar findAllConcatenatedWordsInADict = function(words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @return {String[]}\ndef find_all_concatenated_words_in_a_dict(words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findAllConcatenatedWordsInADict(_ words: [String]) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findAllConcatenatedWordsInADict(words []string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findAllConcatenatedWordsInADict(words: Array[String]): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findAllConcatenatedWordsInADict(words: Array): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_all_concatenated_words_in_a_dict(words: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @return String[]\n */\n function findAllConcatenatedWordsInADict($words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findAllConcatenatedWordsInADict(words: string[]): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-all-concatenated-words-in-a-dict words)\n (-> (listof string?) (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0472](https://leetcode-cn.com/problems/concatenated-words)", "[\u8fde\u63a5\u8bcd](/solution/0400-0499/0472.Concatenated%20Words/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5b57\u5178\u6811`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0472](https://leetcode.com/problems/concatenated-words)", "[Concatenated Words](/solution/0400-0499/0472.Concatenated%20Words/README_EN.md)", "`Depth-first Search`,`Trie`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0471", "frontend_question_id": "0471", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/encode-string-with-shortest-length", "url_en": "https://leetcode.com/problems/encode-string-with-shortest-length", "relative_path_cn": "/solution/0400-0499/0471.Encode%20String%20with%20Shortest%20Length/README.md", "relative_path_en": "/solution/0400-0499/0471.Encode%20String%20with%20Shortest%20Length/README_EN.md", "title_cn": "\u7f16\u7801\u6700\u77ed\u957f\u5ea6\u7684\u5b57\u7b26\u4e32", "title_en": "Encode String with Shortest Length", "question_title_slug": "encode-string-with-shortest-length", "content_en": "

    Given a string s, encode the string such that its encoded length is the shortest.

    \n\n

    The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. k should be a positive integer.

    \n\n

    If an encoding process does not make the string shorter, then do not encode it. If there are several solutions, return any of them.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "aaa"\nOutput: "aaa"\nExplanation: There is no way to encode it such that it is shorter than the input string, so we do not encode it.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "aaaaa"\nOutput: "5[a]"\nExplanation: "5[a]" is shorter than "aaaaa" by 1 character.\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "aaaaaaaaaa"\nOutput: "10[a]"\nExplanation: "a9[a]" or "9[a]a" are also valid solutions, both of them have the same length = 5, which is the same as "10[a]".\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "aabcaabcd"\nOutput: "2[aabc]d"\nExplanation: "aabc" occurs twice, so one answer can be "2[aabc]d".\n
    \n\n

    Example 5:

    \n\n
    \nInput: s = "abbbabbbcabbbabbbc"\nOutput: "2[2[abbb]c]"\nExplanation: "abbbabbbc" occurs twice, but "abbbabbbc" can also be encoded to "2[abbb]c", so one answer can be "2[2[abbb]c]".\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 150
    • \n\t
    • s consists of only lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a \u975e\u7a7a\u00a0\u5b57\u7b26\u4e32\uff0c\u5c06\u5176\u7f16\u7801\u4e3a\u5177\u6709\u6700\u77ed\u957f\u5ea6\u7684\u5b57\u7b26\u4e32\u3002

    \n\n

    \u7f16\u7801\u89c4\u5219\u662f\uff1ak[encoded_string]\uff0c\u5176\u4e2d\u5728\u65b9\u62ec\u53f7\u00a0encoded_string \u4e2d\u7684\u5185\u5bb9\u91cd\u590d k \u6b21\u3002

    \n\n

    \u6ce8\uff1a

    \n\n
      \n\t
    • k\u00a0\u4e3a\u6b63\u6574\u6570
    • \n\t
    • \u5982\u679c\u7f16\u7801\u7684\u8fc7\u7a0b\u4e0d\u80fd\u4f7f\u5b57\u7b26\u4e32\u7f29\u77ed\uff0c\u5219\u4e0d\u8981\u5bf9\u5176\u8fdb\u884c\u7f16\u7801\u3002\u5982\u679c\u6709\u591a\u79cd\u7f16\u7801\u65b9\u5f0f\uff0c\u8fd4\u56de \u4efb\u610f\u4e00\u79cd \u5373\u53ef
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"aaa\"\n\u8f93\u51fa\uff1a\"aaa\"\n\u89e3\u91ca\uff1a\u65e0\u6cd5\u5c06\u5176\u7f16\u7801\u4e3a\u66f4\u77ed\u7684\u5b57\u7b26\u4e32\uff0c\u56e0\u6b64\u4e0d\u8fdb\u884c\u7f16\u7801\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"aaaaa\"\n\u8f93\u51fa\uff1a\"5[a]\"\n\u89e3\u91ca\uff1a\"5[a]\" \u6bd4 \"aaaaa\" \u77ed 1 \u4e2a\u5b57\u7b26\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"aaaaaaaaaa\"\n\u8f93\u51fa\uff1a\"10[a]\"\n\u89e3\u91ca\uff1a\"a9[a]\" \u6216 \"9[a]a\" \u90fd\u662f\u5408\u6cd5\u7684\u7f16\u7801\uff0c\u548c \"10[a]\" \u4e00\u6837\u957f\u5ea6\u90fd\u4e3a 5\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"aabcaabcd\"\n\u8f93\u51fa\uff1a\"2[aabc]d\"\n\u89e3\u91ca\uff1a\"aabc\" \u51fa\u73b0\u4e24\u6b21\uff0c\u56e0\u6b64\u4e00\u79cd\u7b54\u6848\u53ef\u4ee5\u662f \"2[aabc]d\"\u3002\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"abbbabbbcabbbabbbc\"\n\u8f93\u51fa\uff1a\"2[2[abbb]c]\"\n\u89e3\u91ca\uff1a\"abbbabbbc\" \u51fa\u73b0\u4e24\u6b21\uff0c\u4f46\u662f \"abbbabbbc\" \u53ef\u4ee5\u7f16\u7801\u4e3a \"2[abbb]c\"\uff0c\u56e0\u6b64\u4e00\u79cd\u7b54\u6848\u53ef\u4ee5\u662f \"2[2[abbb]c]\"\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 150
    • \n\t
    • s \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string encode(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String encode(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def encode(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def encode(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * encode(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string Encode(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar encode = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef encode(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func encode(_ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func encode(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def encode(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun encode(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn encode(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function encode($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function encode(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (encode s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0471](https://leetcode-cn.com/problems/encode-string-with-shortest-length)", "[\u7f16\u7801\u6700\u77ed\u957f\u5ea6\u7684\u5b57\u7b26\u4e32](/solution/0400-0499/0471.Encode%20String%20with%20Shortest%20Length/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0471](https://leetcode.com/problems/encode-string-with-shortest-length)", "[Encode String with Shortest Length](/solution/0400-0499/0471.Encode%20String%20with%20Shortest%20Length/README_EN.md)", "`Dynamic Programming`", "Hard", "\ud83d\udd12"]}, {"question_id": "0469", "frontend_question_id": "0469", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/convex-polygon", "url_en": "https://leetcode.com/problems/convex-polygon", "relative_path_cn": "/solution/0400-0499/0469.Convex%20Polygon/README.md", "relative_path_en": "/solution/0400-0499/0469.Convex%20Polygon/README_EN.md", "title_cn": "\u51f8\u591a\u8fb9\u5f62", "title_en": "Convex Polygon", "question_title_slug": "convex-polygon", "content_en": "

    You are given an array of points on the X-Y plane points where points[i] = [xi, yi]. The points form a polygon when joined sequentially.

    \n\n

    Return true if this polygon is convex and false otherwise.

    \n\n

    You may assume the polygon formed by given points is always a simple polygon. In other words, we ensure that exactly two edges intersect at each vertex and that edges otherwise don't intersect each other.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: points = [[0,0],[0,5],[5,5],[5,0]]\nOutput: true\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: points = [[0,0],[0,10],[10,10],[10,0],[5,5]]\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 3 <= points.length <= 104
    • \n\t
    • points[i].length == 2
    • \n\t
    • -104 <= xi, yi <= 104
    • \n\t
    • All the given points are unique.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6309\u987a\u5e8f\u8fde\u63a5\u7684\u591a\u8fb9\u5f62\u7684\u9876\u70b9\uff0c\u5224\u65ad\u8be5\u591a\u8fb9\u5f62\u662f\u5426\u4e3a\u51f8\u591a\u8fb9\u5f62\u3002\uff08\u51f8\u591a\u8fb9\u5f62\u7684\u5b9a\u4e49\uff09

    \n\n

    \u6ce8\uff1a

    \n\n
      \n\t
    1. \u9876\u70b9\u4e2a\u6570\u81f3\u5c11\u4e3a 3 \u4e2a\u4e14\u4e0d\u8d85\u8fc7 10,000\u3002
    2. \n\t
    3. \u5750\u6807\u8303\u56f4\u4e3a -10,000 \u5230 10,000\u3002
    4. \n\t
    5. \u4f60\u53ef\u4ee5\u5047\u5b9a\u7ed9\u5b9a\u7684\u70b9\u5f62\u6210\u7684\u591a\u8fb9\u5f62\u5747\u4e3a\u7b80\u5355\u591a\u8fb9\u5f62\uff08\u7b80\u5355\u591a\u8fb9\u5f62\u7684\u5b9a\u4e49\uff09\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u4fdd\u8bc1\u6bcf\u4e2a\u9876\u70b9\u5904\u6070\u597d\u662f\u4e24\u6761\u8fb9\u7684\u6c47\u5408\u70b9\uff0c\u5e76\u4e14\u8fd9\u4e9b\u8fb9 \u4e92\u4e0d\u76f8\u4ea4 \u3002
    6. \n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    [[0,0],[0,1],[1,1],[1,0]]\n\n\u8f93\u51fa\uff1a True\n\n\u89e3\u91ca\uff1a\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    [[0,0],[0,10],[10,10],[10,0],[5,5]]\n\n\u8f93\u51fa\uff1a False\n\n\u89e3\u91ca\uff1a\n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isConvex(vector>& points) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isConvex(List> points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isConvex(self, points):\n \"\"\"\n :type points: List[List[int]]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isConvex(self, points: List[List[int]]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isConvex(int** points, int pointsSize, int* pointsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsConvex(IList> points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} points\n * @return {boolean}\n */\nvar isConvex = function(points) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} points\n# @return {Boolean}\ndef is_convex(points)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isConvex(_ points: [[Int]]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isConvex(points [][]int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isConvex(points: List[List[Int]]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isConvex(points: List>): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_convex(points: Vec>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $points\n * @return Boolean\n */\n function isConvex($points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isConvex(points: number[][]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-convex points)\n (-> (listof (listof exact-integer?)) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0469](https://leetcode-cn.com/problems/convex-polygon)", "[\u51f8\u591a\u8fb9\u5f62](/solution/0400-0499/0469.Convex%20Polygon/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0469](https://leetcode.com/problems/convex-polygon)", "[Convex Polygon](/solution/0400-0499/0469.Convex%20Polygon/README_EN.md)", "`Math`", "Medium", "\ud83d\udd12"]}, {"question_id": "0468", "frontend_question_id": "0468", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/validate-ip-address", "url_en": "https://leetcode.com/problems/validate-ip-address", "relative_path_cn": "/solution/0400-0499/0468.Validate%20IP%20Address/README.md", "relative_path_en": "/solution/0400-0499/0468.Validate%20IP%20Address/README_EN.md", "title_cn": "\u9a8c\u8bc1IP\u5730\u5740", "title_en": "Validate IP Address", "question_title_slug": "validate-ip-address", "content_en": "

    Given a string IP, return "IPv4" if IP is a valid IPv4 address, "IPv6" if IP is a valid IPv6 address or "Neither" if IP is not a correct IP of any type.

    \n\n

    A valid IPv4 address is an IP in the form "x1.x2.x3.x4" where 0 <= xi <= 255 and xi cannot contain leading zeros. For example, "192.168.1.1" and "192.168.1.0" are valid IPv4 addresses but "192.168.01.1", while "192.168.1.00" and "192.168@1.1" are invalid IPv4 addresses.

    \n\n

    A valid IPv6 address is an IP in the form "x1:x2:x3:x4:x5:x6:x7:x8" where:

    \n\n
      \n\t
    • 1 <= xi.length <= 4
    • \n\t
    • xi is a hexadecimal string which may contain digits, lower-case English letter ('a' to 'f') and upper-case English letters ('A' to 'F').
    • \n\t
    • Leading zeros are allowed in xi.
    • \n
    \n\n

    For example, "2001:0db8:85a3:0000:0000:8a2e:0370:7334" and "2001:db8:85a3:0:0:8A2E:0370:7334" are valid IPv6 addresses, while "2001:0db8:85a3::8A2E:037j:7334" and "02001:0db8:85a3:0000:0000:8a2e:0370:7334" are invalid IPv6 addresses.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: IP = "172.16.254.1"\nOutput: "IPv4"\nExplanation: This is a valid IPv4 address, return "IPv4".\n
    \n\n

    Example 2:

    \n\n
    \nInput: IP = "2001:0db8:85a3:0:0:8A2E:0370:7334"\nOutput: "IPv6"\nExplanation: This is a valid IPv6 address, return "IPv6".\n
    \n\n

    Example 3:

    \n\n
    \nInput: IP = "256.256.256.256"\nOutput: "Neither"\nExplanation: This is neither a IPv4 address nor a IPv6 address.\n
    \n\n

    Example 4:

    \n\n
    \nInput: IP = "2001:0db8:85a3:0:0:8A2E:0370:7334:"\nOutput: "Neither"\n
    \n\n

    Example 5:

    \n\n
    \nInput: IP = "1e1.4.5.6"\nOutput: "Neither"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • IP consists only of English letters, digits and the characters '.' and ':'.
    • \n
    \n", "content_cn": "

    \u7f16\u5199\u4e00\u4e2a\u51fd\u6570\u6765\u9a8c\u8bc1\u8f93\u5165\u7684\u5b57\u7b26\u4e32\u662f\u5426\u662f\u6709\u6548\u7684 IPv4 \u6216 IPv6 \u5730\u5740\u3002

    \n\n
      \n\t
    • \u5982\u679c\u662f\u6709\u6548\u7684 IPv4 \u5730\u5740\uff0c\u8fd4\u56de "IPv4" \uff1b
    • \n\t
    • \u5982\u679c\u662f\u6709\u6548\u7684 IPv6 \u5730\u5740\uff0c\u8fd4\u56de "IPv6" \uff1b
    • \n\t
    • \u5982\u679c\u4e0d\u662f\u4e0a\u8ff0\u7c7b\u578b\u7684 IP \u5730\u5740\uff0c\u8fd4\u56de "Neither" \u3002
    • \n
    \n\n

    IPv4 \u5730\u5740\u7531\u5341\u8fdb\u5236\u6570\u548c\u70b9\u6765\u8868\u793a\uff0c\u6bcf\u4e2a\u5730\u5740\u5305\u542b 4 \u4e2a\u5341\u8fdb\u5236\u6570\uff0c\u5176\u8303\u56f4\u4e3a 0 - 255\uff0c \u7528(".")\u5206\u5272\u3002\u6bd4\u5982\uff0c172.16.254.1\uff1b

    \n\n

    \u540c\u65f6\uff0cIPv4 \u5730\u5740\u5185\u7684\u6570\u4e0d\u4f1a\u4ee5 0 \u5f00\u5934\u3002\u6bd4\u5982\uff0c\u5730\u5740 172.16.254.01 \u662f\u4e0d\u5408\u6cd5\u7684\u3002

    \n\n

    IPv6 \u5730\u5740\u7531 8 \u7ec4 16 \u8fdb\u5236\u7684\u6570\u5b57\u6765\u8868\u793a\uff0c\u6bcf\u7ec4\u8868\u793a 16 \u6bd4\u7279\u3002\u8fd9\u4e9b\u7ec4\u6570\u5b57\u901a\u8fc7 (":")\u5206\u5272\u3002\u6bd4\u5982,  2001:0db8:85a3:0000:0000:8a2e:0370:7334 \u662f\u4e00\u4e2a\u6709\u6548\u7684\u5730\u5740\u3002\u800c\u4e14\uff0c\u6211\u4eec\u53ef\u4ee5\u52a0\u5165\u4e00\u4e9b\u4ee5 0 \u5f00\u5934\u7684\u6570\u5b57\uff0c\u5b57\u6bcd\u53ef\u4ee5\u4f7f\u7528\u5927\u5199\uff0c\u4e5f\u53ef\u4ee5\u662f\u5c0f\u5199\u3002\u6240\u4ee5\uff0c 2001:db8:85a3:0:0:8A2E:0370:7334 \u4e5f\u662f\u4e00\u4e2a\u6709\u6548\u7684 IPv6 address\u5730\u5740 (\u5373\uff0c\u5ffd\u7565 0 \u5f00\u5934\uff0c\u5ffd\u7565\u5927\u5c0f\u5199)\u3002

    \n\n

    \u7136\u800c\uff0c\u6211\u4eec\u4e0d\u80fd\u56e0\u4e3a\u67d0\u4e2a\u7ec4\u7684\u503c\u4e3a 0\uff0c\u800c\u4f7f\u7528\u4e00\u4e2a\u7a7a\u7684\u7ec4\uff0c\u4ee5\u81f3\u4e8e\u51fa\u73b0 (::) \u7684\u60c5\u51b5\u3002 \u6bd4\u5982\uff0c 2001:0db8:85a3::8A2E:0370:7334 \u662f\u65e0\u6548\u7684 IPv6 \u5730\u5740\u3002

    \n\n

    \u540c\u65f6\uff0c\u5728 IPv6 \u5730\u5740\u4e2d\uff0c\u591a\u4f59\u7684 0 \u4e5f\u662f\u4e0d\u88ab\u5141\u8bb8\u7684\u3002\u6bd4\u5982\uff0c 02001:0db8:85a3:0000:0000:8a2e:0370:7334 \u662f\u65e0\u6548\u7684\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aIP = "172.16.254.1"\n\u8f93\u51fa\uff1a"IPv4"\n\u89e3\u91ca\uff1a\u6709\u6548\u7684 IPv4 \u5730\u5740\uff0c\u8fd4\u56de "IPv4"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aIP = "2001:0db8:85a3:0:0:8A2E:0370:7334"\n\u8f93\u51fa\uff1a"IPv6"\n\u89e3\u91ca\uff1a\u6709\u6548\u7684 IPv6 \u5730\u5740\uff0c\u8fd4\u56de "IPv6"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aIP = "256.256.256.256"\n\u8f93\u51fa\uff1a"Neither"\n\u89e3\u91ca\uff1a\u65e2\u4e0d\u662f IPv4 \u5730\u5740\uff0c\u53c8\u4e0d\u662f IPv6 \u5730\u5740\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1aIP = "2001:0db8:85a3:0:0:8A2E:0370:7334:"\n\u8f93\u51fa\uff1a"Neither"\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1aIP = "1e1.4.5.6"\n\u8f93\u51fa\uff1a"Neither"\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • IP \u4ec5\u7531\u82f1\u6587\u5b57\u6bcd\uff0c\u6570\u5b57\uff0c\u5b57\u7b26 '.' \u548c ':' \u7ec4\u6210\u3002
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string validIPAddress(string IP) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String validIPAddress(String IP) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def validIPAddress(self, IP):\n \"\"\"\n :type IP: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def validIPAddress(self, IP: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * validIPAddress(char * IP){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ValidIPAddress(string IP) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} IP\n * @return {string}\n */\nvar validIPAddress = function(IP) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} ip\n# @return {String}\ndef valid_ip_address(ip)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func validIPAddress(_ IP: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func validIPAddress(IP string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def validIPAddress(IP: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun validIPAddress(IP: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn valid_ip_address(ip: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $IP\n * @return String\n */\n function validIPAddress($IP) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function validIPAddress(IP: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (valid-ip-address IP)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0468](https://leetcode-cn.com/problems/validate-ip-address)", "[\u9a8c\u8bc1IP\u5730\u5740](/solution/0400-0499/0468.Validate%20IP%20Address/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0468](https://leetcode.com/problems/validate-ip-address)", "[Validate IP Address](/solution/0400-0499/0468.Validate%20IP%20Address/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "0467", "frontend_question_id": "0467", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/unique-substrings-in-wraparound-string", "url_en": "https://leetcode.com/problems/unique-substrings-in-wraparound-string", "relative_path_cn": "/solution/0400-0499/0467.Unique%20Substrings%20in%20Wraparound%20String/README.md", "relative_path_en": "/solution/0400-0499/0467.Unique%20Substrings%20in%20Wraparound%20String/README_EN.md", "title_cn": "\u73af\u7ed5\u5b57\u7b26\u4e32\u4e2d\u552f\u4e00\u7684\u5b50\u5b57\u7b26\u4e32", "title_en": "Unique Substrings in Wraparound String", "question_title_slug": "unique-substrings-in-wraparound-string", "content_en": "

    We define the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz", so s will look like this:

    \n\n
      \n\t
    • "...zabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcd....".
    • \n
    \n\n

    Given a string p, return the number of unique non-empty substrings of p are present in s.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: p = "a"\nOutput: 1\nExplanation: Only the substring "a" of p is in s.\n
    \n\n

    Example 2:

    \n\n
    \nInput: p = "cac"\nOutput: 2\nExplanation: There are two substrings ("a", "c") of p in s.\n
    \n\n

    Example 3:

    \n\n
    \nInput: p = "zab"\nOutput: 6\nExplanation: There are six substrings ("z", "a", "b", "za", "ab", and "zab") of p in s.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= p.length <= 105
    • \n\t
    • p consists of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u628a\u5b57\u7b26\u4e32 s \u770b\u4f5c\u662f“abcdefghijklmnopqrstuvwxyz”\u7684\u65e0\u9650\u73af\u7ed5\u5b57\u7b26\u4e32\uff0c\u6240\u4ee5 s \u770b\u8d77\u6765\u662f\u8fd9\u6837\u7684\uff1a"...zabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcd....". 

    \n\n

    \u73b0\u5728\u6211\u4eec\u6709\u4e86\u53e6\u4e00\u4e2a\u5b57\u7b26\u4e32 p \u3002\u4f60\u9700\u8981\u7684\u662f\u627e\u51fa s \u4e2d\u6709\u591a\u5c11\u4e2a\u552f\u4e00\u7684 p \u7684\u975e\u7a7a\u5b50\u4e32\uff0c\u5c24\u5176\u662f\u5f53\u4f60\u7684\u8f93\u5165\u662f\u5b57\u7b26\u4e32 p \uff0c\u4f60\u9700\u8981\u8f93\u51fa\u5b57\u7b26\u4e32 s \u4e2d p \u7684\u4e0d\u540c\u7684\u975e\u7a7a\u5b50\u4e32\u7684\u6570\u76ee\u3002 

    \n\n

    \u6ce8\u610f: p \u4ec5\u7531\u5c0f\u5199\u7684\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\uff0cp \u7684\u5927\u5c0f\u53ef\u80fd\u8d85\u8fc7 10000\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: "a"\n\u8f93\u51fa: 1\n\u89e3\u91ca: \u5b57\u7b26\u4e32 S \u4e2d\u53ea\u6709\u4e00\u4e2a"a"\u5b50\u5b57\u7b26\u3002\n
    \n\n

     

    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: "cac"\n\u8f93\u51fa: 2\n\u89e3\u91ca: \u5b57\u7b26\u4e32 S \u4e2d\u7684\u5b57\u7b26\u4e32“cac”\u53ea\u6709\u4e24\u4e2a\u5b50\u4e32“a”\u3001“c”\u3002.\n
    \n\n

     

    \n\n

    \u793a\u4f8b 3:

    \n\n
    \n\u8f93\u5165: "zab"\n\u8f93\u51fa: 6\n\u89e3\u91ca: \u5728\u5b57\u7b26\u4e32 S \u4e2d\u6709\u516d\u4e2a\u5b50\u4e32“z”\u3001“a”\u3001“b”\u3001“za”\u3001“ab”\u3001“zab”\u3002.\n
    \n\n

     

    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findSubstringInWraproundString(string p) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findSubstringInWraproundString(String p) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findSubstringInWraproundString(self, p):\n \"\"\"\n :type p: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findSubstringInWraproundString(self, p: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findSubstringInWraproundString(char * p){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindSubstringInWraproundString(string p) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} p\n * @return {number}\n */\nvar findSubstringInWraproundString = function(p) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} p\n# @return {Integer}\ndef find_substring_in_wrapround_string(p)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findSubstringInWraproundString(_ p: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findSubstringInWraproundString(p string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findSubstringInWraproundString(p: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findSubstringInWraproundString(p: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_substring_in_wrapround_string(p: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $p\n * @return Integer\n */\n function findSubstringInWraproundString($p) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findSubstringInWraproundString(p: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-substring-in-wrapround-string p)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0467](https://leetcode-cn.com/problems/unique-substrings-in-wraparound-string)", "[\u73af\u7ed5\u5b57\u7b26\u4e32\u4e2d\u552f\u4e00\u7684\u5b50\u5b57\u7b26\u4e32](/solution/0400-0499/0467.Unique%20Substrings%20in%20Wraparound%20String/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0467](https://leetcode.com/problems/unique-substrings-in-wraparound-string)", "[Unique Substrings in Wraparound String](/solution/0400-0499/0467.Unique%20Substrings%20in%20Wraparound%20String/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0466", "frontend_question_id": "0466", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-the-repetitions", "url_en": "https://leetcode.com/problems/count-the-repetitions", "relative_path_cn": "/solution/0400-0499/0466.Count%20The%20Repetitions/README.md", "relative_path_en": "/solution/0400-0499/0466.Count%20The%20Repetitions/README_EN.md", "title_cn": "\u7edf\u8ba1\u91cd\u590d\u4e2a\u6570", "title_en": "Count The Repetitions", "question_title_slug": "count-the-repetitions", "content_en": "

    We define str = [s, n] as the string str which consists of the string s concatenated n times.

    \n\n
      \n\t
    • For example, str == ["abc", 3] =="abcabcabc".
    • \n
    \n\n

    We define that string s1 can be obtained from string s2 if we can remove some characters from s2 such that it becomes s1.

    \n\n
      \n\t
    • For example, s1 = "abc" can be obtained from s2 = "abdbec" based on our definition by removing the bolded underlined characters.
    • \n
    \n\n

    You are given two strings s1 and s2 and two integers n1 and n2. You have the two strings str1 = [s1, n1] and str2 = [s2, n2].

    \n\n

    Return the maximum integer m such that str = [str2, m] can be obtained from str1.

    \n\n

     

    \n

    Example 1:

    \n
    Input: s1 = \"acb\", n1 = 4, s2 = \"ab\", n2 = 2\nOutput: 2\n

    Example 2:

    \n
    Input: s1 = \"acb\", n1 = 1, s2 = \"acb\", n2 = 1\nOutput: 1\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s1.length, s2.length <= 100
    • \n\t
    • s1 and s2 consist of lowercase English letters.
    • \n\t
    • 1 <= n1, n2 <= 106
    • \n
    \n", "content_cn": "

    \u5b9a\u4e49 str = [s, n] \u8868\u793a str \u7531 n \u4e2a\u5b57\u7b26\u4e32 s \u8fde\u63a5\u6784\u6210\u3002

    \n\n
      \n\t
    • \u4f8b\u5982\uff0cstr == [\"abc\", 3] ==\"abcabcabc\" \u3002
    • \n
    \n\n

    \u5982\u679c\u53ef\u4ee5\u4ece s2\u00a0\u4e2d\u5220\u9664\u67d0\u4e9b\u5b57\u7b26\u4f7f\u5176\u53d8\u4e3a s1\uff0c\u5219\u79f0\u5b57\u7b26\u4e32 s1\u00a0\u53ef\u4ee5\u4ece\u5b57\u7b26\u4e32 s2 \u83b7\u5f97\u3002

    \n\n
      \n\t
    • \u4f8b\u5982\uff0c\u6839\u636e\u5b9a\u4e49\uff0cs1 = \"abc\" \u53ef\u4ee5\u4ece s2 = \"abdbec\" \u83b7\u5f97\uff0c\u4ec5\u9700\u8981\u5220\u9664\u52a0\u7c97\u4e14\u7528\u659c\u4f53\u6807\u8bc6\u7684\u5b57\u7b26\u3002
    • \n
    \n\n

    \u73b0\u5728\u7ed9\u4f60\u4e24\u4e2a\u5b57\u7b26\u4e32 s1\u00a0\u548c s2 \u548c\u4e24\u4e2a\u6574\u6570 n1 \u548c n2 \u3002\u7531\u6b64\u6784\u9020\u5f97\u5230\u4e24\u4e2a\u5b57\u7b26\u4e32\uff0c\u5176\u4e2d str1 = [s1, n1]\u3001str2 = [s2, n2] \u3002

    \n\n

    \u8bf7\u4f60\u627e\u51fa\u4e00\u4e2a\u6700\u5927\u6574\u6570 m \uff0c\u4ee5\u6ee1\u8db3 str = [str2, m] \u53ef\u4ee5\u4ece str1\u00a0\u83b7\u5f97\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as1 = \"acb\", n1 = 4, s2 = \"ab\", n2 = 2\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as1 = \"acb\", n1 = 1, s2 = \"acb\", n2 = 1\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s1.length, s2.length <= 100
    • \n\t
    • s1 \u548c s2 \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n\t
    • 1 <= n1, n2 <= 106
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int getMaxRepetitions(string s1, int n1, string s2, int n2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int getMaxRepetitions(String s1, int n1, String s2, int n2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getMaxRepetitions(self, s1, n1, s2, n2):\n \"\"\"\n :type s1: str\n :type n1: int\n :type s2: str\n :type n2: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getMaxRepetitions(self, s1: str, n1: int, s2: str, n2: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint getMaxRepetitions(char * s1, int n1, char * s2, int n2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int GetMaxRepetitions(string s1, int n1, string s2, int n2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s1\n * @param {number} n1\n * @param {string} s2\n * @param {number} n2\n * @return {number}\n */\nvar getMaxRepetitions = function(s1, n1, s2, n2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s1\n# @param {Integer} n1\n# @param {String} s2\n# @param {Integer} n2\n# @return {Integer}\ndef get_max_repetitions(s1, n1, s2, n2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getMaxRepetitions(_ s1: String, _ n1: Int, _ s2: String, _ n2: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getMaxRepetitions(s1 string, n1 int, s2 string, n2 int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getMaxRepetitions(s1: String, n1: Int, s2: String, n2: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getMaxRepetitions(s1: String, n1: Int, s2: String, n2: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_max_repetitions(s1: String, n1: i32, s2: String, n2: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s1\n * @param Integer $n1\n * @param String $s2\n * @param Integer $n2\n * @return Integer\n */\n function getMaxRepetitions($s1, $n1, $s2, $n2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getMaxRepetitions(s1: string, n1: number, s2: string, n2: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-max-repetitions s1 n1 s2 n2)\n (-> string? exact-integer? string? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0466](https://leetcode-cn.com/problems/count-the-repetitions)", "[\u7edf\u8ba1\u91cd\u590d\u4e2a\u6570](/solution/0400-0499/0466.Count%20The%20Repetitions/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0466](https://leetcode.com/problems/count-the-repetitions)", "[Count The Repetitions](/solution/0400-0499/0466.Count%20The%20Repetitions/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "0465", "frontend_question_id": "0465", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/optimal-account-balancing", "url_en": "https://leetcode.com/problems/optimal-account-balancing", "relative_path_cn": "/solution/0400-0499/0465.Optimal%20Account%20Balancing/README.md", "relative_path_en": "/solution/0400-0499/0465.Optimal%20Account%20Balancing/README_EN.md", "title_cn": "\u6700\u4f18\u8d26\u5355\u5e73\u8861", "title_en": "Optimal Account Balancing", "question_title_slug": "optimal-account-balancing", "content_en": "

    You are given an array of transactions transactions where transactions[i] = [fromi, toi, amounti] indicates that the person with ID = fromi gave amounti $ to the person with ID = toi.

    \n\n

    Return the minimum number of transactions required to settle the debt.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: transactions = [[0,1,10],[2,0,5]]\nOutput: 2\nExplanation:\nPerson #0 gave person #1 $10.\nPerson #2 gave person #0 $5.\nTwo transactions are needed. One way to settle the debt is person #1 pays person #0 and #2 $5 each.\n
    \n\n

    Example 2:

    \n\n
    \nInput: transactions = [[0,1,10],[1,0,1],[1,2,5],[2,0,5]]\nOutput: 1\nExplanation:\nPerson #0 gave person #1 $10.\nPerson #1 gave person #0 $1.\nPerson #1 gave person #2 $5.\nPerson #2 gave person #0 $5.\nTherefore, person #1 only need to give person #0 $4, and all debt is settled.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= transactions.length <= 8
    • \n\t
    • transactions[i].length == 3
    • \n\t
    • 0 <= fromi, toi <= 20
    • \n\t
    • fromi != toi
    • \n\t
    • 1 <= amounti <= 100
    • \n
    \n", "content_cn": "

    \u4e00\u7fa4\u670b\u53cb\u5728\u5ea6\u5047\u671f\u95f4\u4f1a\u76f8\u4e92\u501f\u94b1\u3002\u6bd4\u5982\u8bf4\uff0c\u5c0f\u7231\u540c\u5b66\u652f\u4ed8\u4e86\u5c0f\u65b0\u540c\u5b66\u7684\u5348\u9910\u5171\u8ba1 10 \u7f8e\u5143\u3002\u5982\u679c\u5c0f\u660e\u540c\u5b66\u652f\u4ed8\u4e86\u5c0f\u7231\u540c\u5b66\u7684\u51fa\u79df\u8f66\u94b1\u5171\u8ba1 5 \u7f8e\u5143\u3002\u6211\u4eec\u53ef\u4ee5\u7528\u4e00\u4e2a\u4e09\u5143\u7ec4 (x, y, z) \u8868\u793a\u4e00\u6b21\u4ea4\u6613\uff0c\u8868\u793a x \u501f\u7ed9 y \u5171\u8ba1 z \u7f8e\u5143\u3002\u7528 0, 1, 2 \u8868\u793a\u5c0f\u7231\u540c\u5b66\u3001\u5c0f\u65b0\u540c\u5b66\u548c\u5c0f\u660e\u540c\u5b66\uff080, 1, 2 \u4e3a\u4eba\u7684\u6807\u53f7\uff09\uff0c\u4e0a\u8ff0\u4ea4\u6613\u53ef\u4ee5\u8868\u793a\u4e3a [[0, 1, 10], [2, 0, 5]]\u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u7fa4\u4eba\u4e4b\u95f4\u7684\u4ea4\u6613\u4fe1\u606f\u5217\u8868\uff0c\u8ba1\u7b97\u80fd\u591f\u8fd8\u6e05\u6240\u6709\u503a\u52a1\u7684\u6700\u5c0f\u6b21\u6570\u3002

    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    1. \u4e00\u6b21\u4ea4\u6613\u4f1a\u4ee5\u4e09\u5143\u7ec4 (x, y, z) \u8868\u793a\uff0c\u5e76\u6709 x ≠ y \u4e14 z > 0\u3002
    2. \n\t
    3. \u4eba\u7684\u6807\u53f7\u53ef\u80fd\u4e0d\u662f\u6309\u987a\u5e8f\u7684\uff0c\u4f8b\u5982\u6807\u53f7\u53ef\u80fd\u4e3a 0, 1, 2 \u4e5f\u53ef\u80fd\u4e3a 0, 2, 6\u3002
    4. \n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a\n[[0,1,10], [2,0,5]]\n\n\u8f93\u51fa\uff1a\n2\n\n\u89e3\u91ca\uff1a\n\u4eba #0 \u7ed9\u4eba #1 \u5171\u8ba1 10 \u7f8e\u5143\u3002\n\u4eba #2 \u7ed9\u4eba #0 \u5171\u8ba1 5 \u7f8e\u5143\u3002\n\n\u9700\u8981\u4e24\u6b21\u4ea4\u6613\u3002\u4e00\u79cd\u65b9\u5f0f\u662f\u4eba #1 \u5206\u522b\u7ed9\u4eba #0 \u548c\u4eba #2 \u5404 5 \u7f8e\u5143\u3002\n
    \n\n

     

    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a\n[[0,1,10], [1,0,1], [1,2,5], [2,0,5]]\n\n\u8f93\u51fa\uff1a\n1\n\n\u89e3\u91ca\uff1a\n\u4eba #0 \u7ed9\u4eba #1 \u5171\u8ba1 10 \u7f8e\u5143\u3002Person #0 gave person #1 $10.\n\u4eba #1 \u7ed9\u4eba #0 \u5171\u8ba1 1 \u7f8e\u5143\u3002Person #1 gave person #0 $1.\n\u4eba #1 \u7ed9\u4eba #2 \u5171\u8ba1 5 \u7f8e\u5143\u3002Person #1 gave person #2 $5.\n\u4eba #2 \u7ed9\u4eba #0 \u5171\u8ba1 5 \u7f8e\u5143\u3002Person #2 gave person #0 $5.\n\n\u56e0\u6b64\uff0c\u4eba #1 \u9700\u8981\u7ed9\u4eba #0 \u5171\u8ba1 4 \u7f8e\u5143\uff0c\u6240\u6709\u7684\u503a\u52a1\u5373\u53ef\u8fd8\u6e05\u3002\n
    \n\n

     

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minTransfers(vector>& transactions) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minTransfers(int[][] transactions) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minTransfers(self, transactions):\n \"\"\"\n :type transactions: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minTransfers(self, transactions: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minTransfers(int** transactions, int transactionsSize, int* transactionsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinTransfers(int[][] transactions) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} transactions\n * @return {number}\n */\nvar minTransfers = function(transactions) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} transactions\n# @return {Integer}\ndef min_transfers(transactions)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minTransfers(_ transactions: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minTransfers(transactions [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minTransfers(transactions: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minTransfers(transactions: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_transfers(transactions: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $transactions\n * @return Integer\n */\n function minTransfers($transactions) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minTransfers(transactions: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-transfers transactions)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0465](https://leetcode-cn.com/problems/optimal-account-balancing)", "[\u6700\u4f18\u8d26\u5355\u5e73\u8861](/solution/0400-0499/0465.Optimal%20Account%20Balancing/README.md)", "", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0465](https://leetcode.com/problems/optimal-account-balancing)", "[Optimal Account Balancing](/solution/0400-0499/0465.Optimal%20Account%20Balancing/README_EN.md)", "", "Hard", "\ud83d\udd12"]}, {"question_id": "0464", "frontend_question_id": "0464", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/can-i-win", "url_en": "https://leetcode.com/problems/can-i-win", "relative_path_cn": "/solution/0400-0499/0464.Can%20I%20Win/README.md", "relative_path_en": "/solution/0400-0499/0464.Can%20I%20Win/README_EN.md", "title_cn": "\u6211\u80fd\u8d62\u5417", "title_en": "Can I Win", "question_title_slug": "can-i-win", "content_en": "

    In the "100 game" two players take turns adding, to a running total, any integer from 1 to 10. The player who first causes the running total to reach or exceed 100 wins.

    \n\n

    What if we change the game so that players cannot re-use integers?

    \n\n

    For example, two players might take turns drawing from a common pool of numbers from 1 to 15 without replacement until they reach a total >= 100.

    \n\n

    Given two integers maxChoosableInteger and desiredTotal, return true if the first player to move can force a win, otherwise, return false. Assume both players play optimally.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: maxChoosableInteger = 10, desiredTotal = 11\nOutput: false\nExplanation:\nNo matter which integer the first player choose, the first player will lose.\nThe first player can choose an integer from 1 up to 10.\nIf the first player choose 1, the second player can only choose integers from 2 up to 10.\nThe second player will win by choosing 10 and get a total = 11, which is >= desiredTotal.\nSame with other integers chosen by the first player, the second player will always win.\n
    \n\n

    Example 2:

    \n\n
    \nInput: maxChoosableInteger = 10, desiredTotal = 0\nOutput: true\n
    \n\n

    Example 3:

    \n\n
    \nInput: maxChoosableInteger = 10, desiredTotal = 1\nOutput: true\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= maxChoosableInteger <= 20
    • \n\t
    • 0 <= desiredTotal <= 300
    • \n
    \n", "content_cn": "

    \u5728 "100 game" \u8fd9\u4e2a\u6e38\u620f\u4e2d\uff0c\u4e24\u540d\u73a9\u5bb6\u8f6e\u6d41\u9009\u62e9\u4ece 1 \u5230 10 \u7684\u4efb\u610f\u6574\u6570\uff0c\u7d2f\u8ba1\u6574\u6570\u548c\uff0c\u5148\u4f7f\u5f97\u7d2f\u8ba1\u6574\u6570\u548c\u8fbe\u5230\u6216\u8d85\u8fc7 100 \u7684\u73a9\u5bb6\uff0c\u5373\u4e3a\u80dc\u8005\u3002

    \n\n

    \u5982\u679c\u6211\u4eec\u5c06\u6e38\u620f\u89c4\u5219\u6539\u4e3a “\u73a9\u5bb6\u4e0d\u80fd\u91cd\u590d\u4f7f\u7528\u6574\u6570” \u5462\uff1f

    \n\n

    \u4f8b\u5982\uff0c\u4e24\u4e2a\u73a9\u5bb6\u53ef\u4ee5\u8f6e\u6d41\u4ece\u516c\u5171\u6574\u6570\u6c60\u4e2d\u62bd\u53d6\u4ece 1 \u5230 15 \u7684\u6574\u6570\uff08\u4e0d\u653e\u56de\uff09\uff0c\u76f4\u5230\u7d2f\u8ba1\u6574\u6570\u548c >= 100\u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570 maxChoosableInteger \uff08\u6574\u6570\u6c60\u4e2d\u53ef\u9009\u62e9\u7684\u6700\u5927\u6570\uff09\u548c\u53e6\u4e00\u4e2a\u6574\u6570 desiredTotal\uff08\u7d2f\u8ba1\u548c\uff09\uff0c\u5224\u65ad\u5148\u51fa\u624b\u7684\u73a9\u5bb6\u662f\u5426\u80fd\u7a33\u8d62\uff08\u5047\u8bbe\u4e24\u4f4d\u73a9\u5bb6\u6e38\u620f\u65f6\u90fd\u8868\u73b0\u6700\u4f73\uff09\uff1f

    \n\n

    \u4f60\u53ef\u4ee5\u5047\u8bbe maxChoosableInteger \u4e0d\u4f1a\u5927\u4e8e 20\uff0c desiredTotal \u4e0d\u4f1a\u5927\u4e8e 300\u3002

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1a\nmaxChoosableInteger = 10\ndesiredTotal = 11\n\n\u8f93\u51fa\uff1a\nfalse\n\n\u89e3\u91ca\uff1a\n\u65e0\u8bba\u7b2c\u4e00\u4e2a\u73a9\u5bb6\u9009\u62e9\u54ea\u4e2a\u6574\u6570\uff0c\u4ed6\u90fd\u4f1a\u5931\u8d25\u3002\n\u7b2c\u4e00\u4e2a\u73a9\u5bb6\u53ef\u4ee5\u9009\u62e9\u4ece 1 \u5230 10 \u7684\u6574\u6570\u3002\n\u5982\u679c\u7b2c\u4e00\u4e2a\u73a9\u5bb6\u9009\u62e9 1\uff0c\u90a3\u4e48\u7b2c\u4e8c\u4e2a\u73a9\u5bb6\u53ea\u80fd\u9009\u62e9\u4ece 2 \u5230 10 \u7684\u6574\u6570\u3002\n\u7b2c\u4e8c\u4e2a\u73a9\u5bb6\u53ef\u4ee5\u901a\u8fc7\u9009\u62e9\u6574\u6570 10\uff08\u90a3\u4e48\u7d2f\u79ef\u548c\u4e3a 11 >= desiredTotal\uff09\uff0c\u4ece\u800c\u53d6\u5f97\u80dc\u5229.\n\u540c\u6837\u5730\uff0c\u7b2c\u4e00\u4e2a\u73a9\u5bb6\u9009\u62e9\u4efb\u610f\u5176\u4ed6\u6574\u6570\uff0c\u7b2c\u4e8c\u4e2a\u73a9\u5bb6\u90fd\u4f1a\u8d62\u3002\n
    \n", "tags_en": ["Minimax", "Dynamic Programming"], "tags_cn": ["\u6781\u5c0f\u5316\u6781\u5927", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canIWin(int maxChoosableInteger, int desiredTotal) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canIWin(int maxChoosableInteger, int desiredTotal) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canIWin(self, maxChoosableInteger, desiredTotal):\n \"\"\"\n :type maxChoosableInteger: int\n :type desiredTotal: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canIWin(self, maxChoosableInteger: int, desiredTotal: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canIWin(int maxChoosableInteger, int desiredTotal){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanIWin(int maxChoosableInteger, int desiredTotal) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} maxChoosableInteger\n * @param {number} desiredTotal\n * @return {boolean}\n */\nvar canIWin = function(maxChoosableInteger, desiredTotal) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} max_choosable_integer\n# @param {Integer} desired_total\n# @return {Boolean}\ndef can_i_win(max_choosable_integer, desired_total)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canIWin(_ maxChoosableInteger: Int, _ desiredTotal: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canIWin(maxChoosableInteger int, desiredTotal int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canIWin(maxChoosableInteger: Int, desiredTotal: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canIWin(maxChoosableInteger: Int, desiredTotal: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_i_win(max_choosable_integer: i32, desired_total: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $maxChoosableInteger\n * @param Integer $desiredTotal\n * @return Boolean\n */\n function canIWin($maxChoosableInteger, $desiredTotal) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canIWin(maxChoosableInteger: number, desiredTotal: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-i-win maxChoosableInteger desiredTotal)\n (-> exact-integer? exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0464](https://leetcode-cn.com/problems/can-i-win)", "[\u6211\u80fd\u8d62\u5417](/solution/0400-0499/0464.Can%20I%20Win/README.md)", "`\u6781\u5c0f\u5316\u6781\u5927`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0464](https://leetcode.com/problems/can-i-win)", "[Can I Win](/solution/0400-0499/0464.Can%20I%20Win/README_EN.md)", "`Minimax`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0463", "frontend_question_id": "0463", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/island-perimeter", "url_en": "https://leetcode.com/problems/island-perimeter", "relative_path_cn": "/solution/0400-0499/0463.Island%20Perimeter/README.md", "relative_path_en": "/solution/0400-0499/0463.Island%20Perimeter/README_EN.md", "title_cn": "\u5c9b\u5c7f\u7684\u5468\u957f", "title_en": "Island Perimeter", "question_title_slug": "island-perimeter", "content_en": "

    You are given row x col grid representing a map where grid[i][j] = 1 represents land and grid[i][j] = 0 represents water.

    \n\n

    Grid cells are connected horizontally/vertically (not diagonally). The grid is completely surrounded by water, and there is exactly one island (i.e., one or more connected land cells).

    \n\n

    The island doesn't have "lakes", meaning the water inside isn't connected to the water around the island. One cell is a square with side length 1. The grid is rectangular, width and height don't exceed 100. Determine the perimeter of the island.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: grid = [[0,1,0,0],[1,1,1,0],[0,1,0,0],[1,1,0,0]]\nOutput: 16\nExplanation: The perimeter is the 16 yellow stripes in the image above.\n
    \n\n

    Example 2:

    \n\n
    \nInput: grid = [[1]]\nOutput: 4\n
    \n\n

    Example 3:

    \n\n
    \nInput: grid = [[1,0]]\nOutput: 4\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • row == grid.length
    • \n\t
    • col == grid[i].length
    • \n\t
    • 1 <= row, col <= 100
    • \n\t
    • grid[i][j] is 0 or 1.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a row x col \u7684\u4e8c\u7ef4\u7f51\u683c\u5730\u56fe grid \uff0c\u5176\u4e2d\uff1agrid[i][j] = 1 \u8868\u793a\u9646\u5730\uff0c grid[i][j] = 0 \u8868\u793a\u6c34\u57df\u3002

    \n\n

    \u7f51\u683c\u4e2d\u7684\u683c\u5b50 \u6c34\u5e73\u548c\u5782\u76f4 \u65b9\u5411\u76f8\u8fde\uff08\u5bf9\u89d2\u7ebf\u65b9\u5411\u4e0d\u76f8\u8fde\uff09\u3002\u6574\u4e2a\u7f51\u683c\u88ab\u6c34\u5b8c\u5168\u5305\u56f4\uff0c\u4f46\u5176\u4e2d\u6070\u597d\u6709\u4e00\u4e2a\u5c9b\u5c7f\uff08\u6216\u8005\u8bf4\uff0c\u4e00\u4e2a\u6216\u591a\u4e2a\u8868\u793a\u9646\u5730\u7684\u683c\u5b50\u76f8\u8fde\u7ec4\u6210\u7684\u5c9b\u5c7f\uff09\u3002

    \n\n

    \u5c9b\u5c7f\u4e2d\u6ca1\u6709\u201c\u6e56\u201d\uff08\u201c\u6e56\u201d \u6307\u6c34\u57df\u5728\u5c9b\u5c7f\u5185\u90e8\u4e14\u4e0d\u548c\u5c9b\u5c7f\u5468\u56f4\u7684\u6c34\u76f8\u8fde\uff09\u3002\u683c\u5b50\u662f\u8fb9\u957f\u4e3a 1 \u7684\u6b63\u65b9\u5f62\u3002\u7f51\u683c\u4e3a\u957f\u65b9\u5f62\uff0c\u4e14\u5bbd\u5ea6\u548c\u9ad8\u5ea6\u5747\u4e0d\u8d85\u8fc7 100 \u3002\u8ba1\u7b97\u8fd9\u4e2a\u5c9b\u5c7f\u7684\u5468\u957f\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \n\n
    \n\u8f93\u5165\uff1agrid = [[0,1,0,0],[1,1,1,0],[0,1,0,0],[1,1,0,0]]\n\u8f93\u51fa\uff1a16\n\u89e3\u91ca\uff1a\u5b83\u7684\u5468\u957f\u662f\u4e0a\u9762\u56fe\u7247\u4e2d\u7684 16 \u4e2a\u9ec4\u8272\u7684\u8fb9
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1agrid = [[1]]\n\u8f93\u51fa\uff1a4\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1agrid = [[1,0]]\n\u8f93\u51fa\uff1a4\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • row == grid.length
    • \n\t
    • col == grid[i].length
    • \n\t
    • 1 <= row, col <= 100
    • \n\t
    • grid[i][j] \u4e3a 0 \u6216 1
    • \n
    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int islandPerimeter(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int islandPerimeter(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def islandPerimeter(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def islandPerimeter(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint islandPerimeter(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int IslandPerimeter(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar islandPerimeter = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef island_perimeter(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func islandPerimeter(_ grid: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func islandPerimeter(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def islandPerimeter(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun islandPerimeter(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn island_perimeter(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function islandPerimeter($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function islandPerimeter(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (island-perimeter grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0463](https://leetcode-cn.com/problems/island-perimeter)", "[\u5c9b\u5c7f\u7684\u5468\u957f](/solution/0400-0499/0463.Island%20Perimeter/README.md)", "`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0463](https://leetcode.com/problems/island-perimeter)", "[Island Perimeter](/solution/0400-0499/0463.Island%20Perimeter/README_EN.md)", "`Hash Table`", "Easy", ""]}, {"question_id": "0462", "frontend_question_id": "0462", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-moves-to-equal-array-elements-ii", "url_en": "https://leetcode.com/problems/minimum-moves-to-equal-array-elements-ii", "relative_path_cn": "/solution/0400-0499/0462.Minimum%20Moves%20to%20Equal%20Array%20Elements%20II/README.md", "relative_path_en": "/solution/0400-0499/0462.Minimum%20Moves%20to%20Equal%20Array%20Elements%20II/README_EN.md", "title_cn": "\u6700\u5c11\u79fb\u52a8\u6b21\u6570\u4f7f\u6570\u7ec4\u5143\u7d20\u76f8\u7b49 II", "title_en": "Minimum Moves to Equal Array Elements II", "question_title_slug": "minimum-moves-to-equal-array-elements-ii", "content_en": "

    Given an integer array nums of size n, return the minimum number of moves required to make all array elements equal.

    \n\n

    In one move, you can increment or decrement an element of the array by 1.

    \n\n

    Test cases are designed so that the answer will fit in a 32-bit integer.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,3]\nOutput: 2\nExplanation:\nOnly two moves are needed (remember each move increments or decrements one element):\n[1,2,3]  =>  [2,2,3]  =>  [2,2,2]\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,10,2,9]\nOutput: 16\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • -109 <= nums[i] <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u7a7a\u6574\u6570\u6570\u7ec4\uff0c\u627e\u5230\u4f7f\u6240\u6709\u6570\u7ec4\u5143\u7d20\u76f8\u7b49\u6240\u9700\u7684\u6700\u5c0f\u79fb\u52a8\u6570\uff0c\u5176\u4e2d\u6bcf\u6b21\u79fb\u52a8\u53ef\u5c06\u9009\u5b9a\u7684\u4e00\u4e2a\u5143\u7d20\u52a01\u6216\u51cf1\u3002 \u60a8\u53ef\u4ee5\u5047\u8bbe\u6570\u7ec4\u7684\u957f\u5ea6\u6700\u591a\u4e3a10000\u3002

    \n\n

    \u4f8b\u5982:

    \n\n
    \n\u8f93\u5165:\n[1,2,3]\n\n\u8f93\u51fa:\n2\n\n\u8bf4\u660e\uff1a\n\u53ea\u6709\u4e24\u4e2a\u52a8\u4f5c\u662f\u5fc5\u8981\u7684\uff08\u8bb0\u5f97\u6bcf\u4e00\u6b65\u4ec5\u53ef\u4f7f\u5176\u4e2d\u4e00\u4e2a\u5143\u7d20\u52a01\u6216\u51cf1\uff09\uff1a \n\n[1,2,3]  =>  [2,2,3]  =>  [2,2,2]\n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minMoves2(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minMoves2(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minMoves2(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minMoves2(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minMoves2(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinMoves2(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar minMoves2 = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef min_moves2(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minMoves2(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minMoves2(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minMoves2(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minMoves2(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_moves2(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function minMoves2($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minMoves2(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-moves2 nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0462](https://leetcode-cn.com/problems/minimum-moves-to-equal-array-elements-ii)", "[\u6700\u5c11\u79fb\u52a8\u6b21\u6570\u4f7f\u6570\u7ec4\u5143\u7d20\u76f8\u7b49 II](/solution/0400-0499/0462.Minimum%20Moves%20to%20Equal%20Array%20Elements%20II/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0462](https://leetcode.com/problems/minimum-moves-to-equal-array-elements-ii)", "[Minimum Moves to Equal Array Elements II](/solution/0400-0499/0462.Minimum%20Moves%20to%20Equal%20Array%20Elements%20II/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "0461", "frontend_question_id": "0461", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/hamming-distance", "url_en": "https://leetcode.com/problems/hamming-distance", "relative_path_cn": "/solution/0400-0499/0461.Hamming%20Distance/README.md", "relative_path_en": "/solution/0400-0499/0461.Hamming%20Distance/README_EN.md", "title_cn": "\u6c49\u660e\u8ddd\u79bb", "title_en": "Hamming Distance", "question_title_slug": "hamming-distance", "content_en": "

    The Hamming distance between two integers is the number of positions at which the corresponding bits are different.

    \n\n

    Given two integers x and y, return the Hamming distance between them.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: x = 1, y = 4\nOutput: 2\nExplanation:\n1   (0 0 0 1)\n4   (0 1 0 0)\n       ↑   ↑\nThe above arrows point to positions where the corresponding bits are different.\n
    \n\n

    Example 2:

    \n\n
    \nInput: x = 3, y = 1\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= x, y <= 231 - 1
    • \n
    \n", "content_cn": "

    \u4e24\u4e2a\u6574\u6570\u4e4b\u95f4\u7684 \u6c49\u660e\u8ddd\u79bb \u6307\u7684\u662f\u8fd9\u4e24\u4e2a\u6570\u5b57\u5bf9\u5e94\u4e8c\u8fdb\u5236\u4f4d\u4e0d\u540c\u7684\u4f4d\u7f6e\u7684\u6570\u76ee\u3002

    \n\n

    \u7ed9\u4f60\u4e24\u4e2a\u6574\u6570 x \u548c y\uff0c\u8ba1\u7b97\u5e76\u8fd4\u56de\u5b83\u4eec\u4e4b\u95f4\u7684\u6c49\u660e\u8ddd\u79bb\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1ax = 1, y = 4\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n1   (0 0 0 1)\n4   (0 1 0 0)\n       \u2191   \u2191\n\u4e0a\u9762\u7684\u7bad\u5934\u6307\u51fa\u4e86\u5bf9\u5e94\u4e8c\u8fdb\u5236\u4f4d\u4e0d\u540c\u7684\u4f4d\u7f6e\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1ax = 3, y = 1\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <=\u00a0x, y <= 231 - 1
    • \n
    \n", "tags_en": ["Bit Manipulation"], "tags_cn": ["\u4f4d\u8fd0\u7b97"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int hammingDistance(int x, int y) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int hammingDistance(int x, int y) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def hammingDistance(self, x, y):\n \"\"\"\n :type x: int\n :type y: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def hammingDistance(self, x: int, y: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint hammingDistance(int x, int y){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int HammingDistance(int x, int y) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} x\n * @param {number} y\n * @return {number}\n */\nvar hammingDistance = function(x, y) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} x\n# @param {Integer} y\n# @return {Integer}\ndef hamming_distance(x, y)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func hammingDistance(_ x: Int, _ y: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func hammingDistance(x int, y int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def hammingDistance(x: Int, y: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun hammingDistance(x: Int, y: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn hamming_distance(x: i32, y: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $x\n * @param Integer $y\n * @return Integer\n */\n function hammingDistance($x, $y) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function hammingDistance(x: number, y: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (hamming-distance x y)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0461](https://leetcode-cn.com/problems/hamming-distance)", "[\u6c49\u660e\u8ddd\u79bb](/solution/0400-0499/0461.Hamming%20Distance/README.md)", "`\u4f4d\u8fd0\u7b97`", "\u7b80\u5355", ""], "md_table_row_en": ["[0461](https://leetcode.com/problems/hamming-distance)", "[Hamming Distance](/solution/0400-0499/0461.Hamming%20Distance/README_EN.md)", "`Bit Manipulation`", "Easy", ""]}, {"question_id": "0460", "frontend_question_id": "0460", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/lfu-cache", "url_en": "https://leetcode.com/problems/lfu-cache", "relative_path_cn": "/solution/0400-0499/0460.LFU%20Cache/README.md", "relative_path_en": "/solution/0400-0499/0460.LFU%20Cache/README_EN.md", "title_cn": "LFU \u7f13\u5b58", "title_en": "LFU Cache", "question_title_slug": "lfu-cache", "content_en": "

    Design and implement a data structure for a Least Frequently Used (LFU) cache.

    \n\n

    Implement the LFUCache class:

    \n\n
      \n\t
    • LFUCache(int capacity) Initializes the object with the capacity of the data structure.
    • \n\t
    • int get(int key) Gets the value of the key if the key exists in the cache. Otherwise, returns -1.
    • \n\t
    • void put(int key, int value) Update the value of the key if present, or inserts the key if not already present. When the cache reaches its capacity, it should invalidate and remove the least frequently used key before inserting a new item. For this problem, when there is a tie (i.e., two or more keys with the same frequency), the least recently used key would be invalidated.
    • \n
    \n\n

    To determine the least frequently used key, a use counter is maintained for each key in the cache. The key with the smallest use counter is the least frequently used key.

    \n\n

    When a key is first inserted into the cache, its use counter is set to 1 (due to the put operation). The use counter for a key in the cache is incremented either a get or put operation is called on it.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["LFUCache", "put", "put", "get", "put", "get", "get", "put", "get", "get", "get"]\n[[2], [1, 1], [2, 2], [1], [3, 3], [2], [3], [4, 4], [1], [3], [4]]\nOutput\n[null, null, null, 1, null, -1, 3, null, -1, 3, 4]\n\nExplanation\n// cnt(x) = the use counter for key x\n// cache=[] will show the last used order for tiebreakers (leftmost element is  most recent)\nLFUCache lfu = new LFUCache(2);\nlfu.put(1, 1);   // cache=[1,_], cnt(1)=1\nlfu.put(2, 2);   // cache=[2,1], cnt(2)=1, cnt(1)=1\nlfu.get(1);      // return 1\n                 // cache=[1,2], cnt(2)=1, cnt(1)=2\nlfu.put(3, 3);   // 2 is the LFU key because cnt(2)=1 is the smallest, invalidate 2.\n                 // cache=[3,1], cnt(3)=1, cnt(1)=2\nlfu.get(2);      // return -1 (not found)\nlfu.get(3);      // return 3\n                 // cache=[3,1], cnt(3)=2, cnt(1)=2\nlfu.put(4, 4);   // Both 1 and 3 have the same cnt, but 1 is LRU, invalidate 1.\n                 // cache=[4,3], cnt(4)=1, cnt(3)=2\nlfu.get(1);      // return -1 (not found)\nlfu.get(3);      // return 3\n                 // cache=[3,4], cnt(4)=1, cnt(3)=3\nlfu.get(4);      // return 4\n                 // cache=[3,4], cnt(4)=2, cnt(3)=3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= capacity, key, value <= 104
    • \n\t
    • At most 105 calls will be made to get and put.
    • \n
    \n\n

     

    \nFollow up: Could you do both operations in O(1) time complexity? ", "content_cn": "

    \u8bf7\u4f60\u4e3a \u6700\u4e0d\u7ecf\u5e38\u4f7f\u7528\uff08LFU\uff09\u7f13\u5b58\u7b97\u6cd5\u8bbe\u8ba1\u5e76\u5b9e\u73b0\u6570\u636e\u7ed3\u6784\u3002

    \n\n

    \u5b9e\u73b0 LFUCache \u7c7b\uff1a

    \n\n
      \n\t
    • LFUCache(int capacity) - \u7528\u6570\u636e\u7ed3\u6784\u7684\u5bb9\u91cf\u00a0capacity \u521d\u59cb\u5316\u5bf9\u8c61
    • \n\t
    • int get(int key)\u00a0- \u5982\u679c\u952e\u5b58\u5728\u4e8e\u7f13\u5b58\u4e2d\uff0c\u5219\u83b7\u53d6\u952e\u7684\u503c\uff0c\u5426\u5219\u8fd4\u56de -1\u3002
    • \n\t
    • void put(int key, int value)\u00a0- \u5982\u679c\u952e\u5df2\u5b58\u5728\uff0c\u5219\u53d8\u66f4\u5176\u503c\uff1b\u5982\u679c\u952e\u4e0d\u5b58\u5728\uff0c\u8bf7\u63d2\u5165\u952e\u503c\u5bf9\u3002\u5f53\u7f13\u5b58\u8fbe\u5230\u5176\u5bb9\u91cf\u65f6\uff0c\u5219\u5e94\u8be5\u5728\u63d2\u5165\u65b0\u9879\u4e4b\u524d\uff0c\u4f7f\u6700\u4e0d\u7ecf\u5e38\u4f7f\u7528\u7684\u9879\u65e0\u6548\u3002\u5728\u6b64\u95ee\u9898\u4e2d\uff0c\u5f53\u5b58\u5728\u5e73\u5c40\uff08\u5373\u4e24\u4e2a\u6216\u66f4\u591a\u4e2a\u952e\u5177\u6709\u76f8\u540c\u4f7f\u7528\u9891\u7387\uff09\u65f6\uff0c\u5e94\u8be5\u53bb\u9664 \u6700\u8fd1\u6700\u4e45\u672a\u4f7f\u7528 \u7684\u952e\u3002
    • \n
    \n\n

    \u6ce8\u610f\u300c\u9879\u7684\u4f7f\u7528\u6b21\u6570\u300d\u5c31\u662f\u81ea\u63d2\u5165\u8be5\u9879\u4ee5\u6765\u5bf9\u5176\u8c03\u7528 get \u548c put \u51fd\u6570\u7684\u6b21\u6570\u4e4b\u548c\u3002\u4f7f\u7528\u6b21\u6570\u4f1a\u5728\u5bf9\u5e94\u9879\u88ab\u79fb\u9664\u540e\u7f6e\u4e3a 0 \u3002

    \n\n

    \u4e3a\u4e86\u786e\u5b9a\u6700\u4e0d\u5e38\u4f7f\u7528\u7684\u952e\uff0c\u53ef\u4ee5\u4e3a\u7f13\u5b58\u4e2d\u7684\u6bcf\u4e2a\u952e\u7ef4\u62a4\u4e00\u4e2a \u4f7f\u7528\u8ba1\u6570\u5668 \u3002\u4f7f\u7528\u8ba1\u6570\u6700\u5c0f\u7684\u952e\u662f\u6700\u4e45\u672a\u4f7f\u7528\u7684\u952e\u3002

    \n\n

    \u5f53\u4e00\u4e2a\u952e\u9996\u6b21\u63d2\u5165\u5230\u7f13\u5b58\u4e2d\u65f6\uff0c\u5b83\u7684\u4f7f\u7528\u8ba1\u6570\u5668\u88ab\u8bbe\u7f6e\u4e3a 1 (\u7531\u4e8e put \u64cd\u4f5c)\u3002\u5bf9\u7f13\u5b58\u4e2d\u7684\u952e\u6267\u884c get \u6216 put \u64cd\u4f5c\uff0c\u4f7f\u7528\u8ba1\u6570\u5668\u7684\u503c\u5c06\u4f1a\u9012\u589e\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\n[\"LFUCache\", \"put\", \"put\", \"get\", \"put\", \"get\", \"get\", \"put\", \"get\", \"get\", \"get\"]\n[[2], [1, 1], [2, 2], [1], [3, 3], [2], [3], [4, 4], [1], [3], [4]]\n\u8f93\u51fa\uff1a\n[null, null, null, 1, null, -1, 3, null, -1, 3, 4]\n\n\u89e3\u91ca\uff1a\n// cnt(x) = \u952e x \u7684\u4f7f\u7528\u8ba1\u6570\n// cache=[] \u5c06\u663e\u793a\u6700\u540e\u4e00\u6b21\u4f7f\u7528\u7684\u987a\u5e8f\uff08\u6700\u5de6\u8fb9\u7684\u5143\u7d20\u662f\u6700\u8fd1\u7684\uff09\nLFUCache lFUCache = new LFUCache(2);\nlFUCache.put(1, 1);   // cache=[1,_], cnt(1)=1\nlFUCache.put(2, 2);   // cache=[2,1], cnt(2)=1, cnt(1)=1\nlFUCache.get(1);      // \u8fd4\u56de 1\n                      // cache=[1,2], cnt(2)=1, cnt(1)=2\nlFUCache.put(3, 3);   // \u53bb\u9664\u952e 2 \uff0c\u56e0\u4e3a cnt(2)=1 \uff0c\u4f7f\u7528\u8ba1\u6570\u6700\u5c0f\n                      // cache=[3,1], cnt(3)=1, cnt(1)=2\nlFUCache.get(2);      // \u8fd4\u56de -1\uff08\u672a\u627e\u5230\uff09\nlFUCache.get(3);      // \u8fd4\u56de 3\n                      // cache=[3,1], cnt(3)=2, cnt(1)=2\nlFUCache.put(4, 4);   // \u53bb\u9664\u952e 1 \uff0c1 \u548c 3 \u7684 cnt \u76f8\u540c\uff0c\u4f46 1 \u6700\u4e45\u672a\u4f7f\u7528\n                      // cache=[4,3], cnt(4)=1, cnt(3)=2\nlFUCache.get(1);      // \u8fd4\u56de -1\uff08\u672a\u627e\u5230\uff09\nlFUCache.get(3);      // \u8fd4\u56de 3\n                      // cache=[3,4], cnt(4)=1, cnt(3)=3\nlFUCache.get(4);      // \u8fd4\u56de 4\n                      // cache=[3,4], cnt(4)=2, cnt(3)=3
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <=\u00a0capacity, key, value <= 104
    • \n\t
    • \u6700\u591a\u8c03\u7528 105 \u6b21 get \u548c put \u65b9\u6cd5
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u53ef\u4ee5\u4e3a\u8fd9\u4e24\u79cd\u64cd\u4f5c\u8bbe\u8ba1\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(1) \u7684\u5b9e\u73b0\u5417\uff1f

    \n", "tags_en": ["Design"], "tags_cn": ["\u8bbe\u8ba1"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class LFUCache {\npublic:\n LFUCache(int capacity) {\n\n }\n \n int get(int key) {\n\n }\n \n void put(int key, int value) {\n\n }\n};\n\n/**\n * Your LFUCache object will be instantiated and called as such:\n * LFUCache* obj = new LFUCache(capacity);\n * int param_1 = obj->get(key);\n * obj->put(key,value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class LFUCache {\n\n public LFUCache(int capacity) {\n\n }\n \n public int get(int key) {\n\n }\n \n public void put(int key, int value) {\n\n }\n}\n\n/**\n * Your LFUCache object will be instantiated and called as such:\n * LFUCache obj = new LFUCache(capacity);\n * int param_1 = obj.get(key);\n * obj.put(key,value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class LFUCache(object):\n\n def __init__(self, capacity):\n \"\"\"\n :type capacity: int\n \"\"\"\n\n\n def get(self, key):\n \"\"\"\n :type key: int\n :rtype: int\n \"\"\"\n\n\n def put(self, key, value):\n \"\"\"\n :type key: int\n :type value: int\n :rtype: None\n \"\"\"\n\n\n\n# Your LFUCache object will be instantiated and called as such:\n# obj = LFUCache(capacity)\n# param_1 = obj.get(key)\n# obj.put(key,value)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class LFUCache:\n\n def __init__(self, capacity: int):\n\n\n def get(self, key: int) -> int:\n\n\n def put(self, key: int, value: int) -> None:\n\n\n\n# Your LFUCache object will be instantiated and called as such:\n# obj = LFUCache(capacity)\n# param_1 = obj.get(key)\n# obj.put(key,value)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} LFUCache;\n\n\nLFUCache* lFUCacheCreate(int capacity) {\n\n}\n\nint lFUCacheGet(LFUCache* obj, int key) {\n\n}\n\nvoid lFUCachePut(LFUCache* obj, int key, int value) {\n\n}\n\nvoid lFUCacheFree(LFUCache* obj) {\n\n}\n\n/**\n * Your LFUCache struct will be instantiated and called as such:\n * LFUCache* obj = lFUCacheCreate(capacity);\n * int param_1 = lFUCacheGet(obj, key);\n \n * lFUCachePut(obj, key, value);\n \n * lFUCacheFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class LFUCache {\n\n public LFUCache(int capacity) {\n\n }\n \n public int Get(int key) {\n\n }\n \n public void Put(int key, int value) {\n\n }\n}\n\n/**\n * Your LFUCache object will be instantiated and called as such:\n * LFUCache obj = new LFUCache(capacity);\n * int param_1 = obj.Get(key);\n * obj.Put(key,value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} capacity\n */\nvar LFUCache = function(capacity) {\n\n};\n\n/** \n * @param {number} key\n * @return {number}\n */\nLFUCache.prototype.get = function(key) {\n\n};\n\n/** \n * @param {number} key \n * @param {number} value\n * @return {void}\n */\nLFUCache.prototype.put = function(key, value) {\n\n};\n\n/**\n * Your LFUCache object will be instantiated and called as such:\n * var obj = new LFUCache(capacity)\n * var param_1 = obj.get(key)\n * obj.put(key,value)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class LFUCache\n\n=begin\n :type capacity: Integer\n=end\n def initialize(capacity)\n\n end\n\n\n=begin\n :type key: Integer\n :rtype: Integer\n=end\n def get(key)\n\n end\n\n\n=begin\n :type key: Integer\n :type value: Integer\n :rtype: Void\n=end\n def put(key, value)\n\n end\n\n\nend\n\n# Your LFUCache object will be instantiated and called as such:\n# obj = LFUCache.new(capacity)\n# param_1 = obj.get(key)\n# obj.put(key, value)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass LFUCache {\n\n init(_ capacity: Int) {\n\n }\n \n func get(_ key: Int) -> Int {\n\n }\n \n func put(_ key: Int, _ value: Int) {\n\n }\n}\n\n/**\n * Your LFUCache object will be instantiated and called as such:\n * let obj = LFUCache(capacity)\n * let ret_1: Int = obj.get(key)\n * obj.put(key, value)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type LFUCache struct {\n\n}\n\n\nfunc Constructor(capacity int) LFUCache {\n\n}\n\n\nfunc (this *LFUCache) Get(key int) int {\n\n}\n\n\nfunc (this *LFUCache) Put(key int, value int) {\n\n}\n\n\n/**\n * Your LFUCache object will be instantiated and called as such:\n * obj := Constructor(capacity);\n * param_1 := obj.Get(key);\n * obj.Put(key,value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class LFUCache(_capacity: Int) {\n\n def get(key: Int): Int = {\n\n }\n\n def put(key: Int, value: Int) {\n\n }\n\n}\n\n/**\n * Your LFUCache object will be instantiated and called as such:\n * var obj = new LFUCache(capacity)\n * var param_1 = obj.get(key)\n * obj.put(key,value)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class LFUCache(capacity: Int) {\n\n fun get(key: Int): Int {\n\n }\n\n fun put(key: Int, value: Int) {\n\n }\n\n}\n\n/**\n * Your LFUCache object will be instantiated and called as such:\n * var obj = LFUCache(capacity)\n * var param_1 = obj.get(key)\n * obj.put(key,value)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct LFUCache {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl LFUCache {\n\n fn new(capacity: i32) -> Self {\n\n }\n \n fn get(&self, key: i32) -> i32 {\n\n }\n \n fn put(&self, key: i32, value: i32) {\n\n }\n}\n\n/**\n * Your LFUCache object will be instantiated and called as such:\n * let obj = LFUCache::new(capacity);\n * let ret_1: i32 = obj.get(key);\n * obj.put(key, value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class LFUCache {\n /**\n * @param Integer $capacity\n */\n function __construct($capacity) {\n\n }\n\n /**\n * @param Integer $key\n * @return Integer\n */\n function get($key) {\n\n }\n\n /**\n * @param Integer $key\n * @param Integer $value\n * @return NULL\n */\n function put($key, $value) {\n\n }\n}\n\n/**\n * Your LFUCache object will be instantiated and called as such:\n * $obj = LFUCache($capacity);\n * $ret_1 = $obj->get($key);\n * $obj->put($key, $value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class LFUCache {\n constructor(capacity: number) {\n\n }\n\n get(key: number): number {\n\n }\n\n put(key: number, value: number): void {\n\n }\n}\n\n/**\n * Your LFUCache object will be instantiated and called as such:\n * var obj = new LFUCache(capacity)\n * var param_1 = obj.get(key)\n * obj.put(key,value)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define lfu-cache%\n (class object%\n (super-new)\n\n ; capacity : exact-integer?\n (init-field\n capacity)\n \n ; get : exact-integer? -> exact-integer?\n (define/public (get key)\n\n )\n ; put : exact-integer? exact-integer? -> void?\n (define/public (put key value)\n\n )))\n\n;; Your lfu-cache% object will be instantiated and called as such:\n;; (define obj (new lfu-cache% [capacity capacity]))\n;; (define param_1 (send obj get key))\n;; (send obj put key value)", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0460](https://leetcode-cn.com/problems/lfu-cache)", "[LFU \u7f13\u5b58](/solution/0400-0499/0460.LFU%20Cache/README.md)", "`\u8bbe\u8ba1`", "\u56f0\u96be", ""], "md_table_row_en": ["[0460](https://leetcode.com/problems/lfu-cache)", "[LFU Cache](/solution/0400-0499/0460.LFU%20Cache/README_EN.md)", "`Design`", "Hard", ""]}, {"question_id": "0459", "frontend_question_id": "0459", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/repeated-substring-pattern", "url_en": "https://leetcode.com/problems/repeated-substring-pattern", "relative_path_cn": "/solution/0400-0499/0459.Repeated%20Substring%20Pattern/README.md", "relative_path_en": "/solution/0400-0499/0459.Repeated%20Substring%20Pattern/README_EN.md", "title_cn": "\u91cd\u590d\u7684\u5b50\u5b57\u7b26\u4e32", "title_en": "Repeated Substring Pattern", "question_title_slug": "repeated-substring-pattern", "content_en": "

    Given a string s, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "abab"\nOutput: true\nExplanation: It is the substring "ab" twice.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "aba"\nOutput: false\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "abcabcabcabc"\nOutput: true\nExplanation: It is the substring "abc" four times or the substring "abcabc" twice.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 104
    • \n\t
    • s consists of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u7a7a\u7684\u5b57\u7b26\u4e32\uff0c\u5224\u65ad\u5b83\u662f\u5426\u53ef\u4ee5\u7531\u5b83\u7684\u4e00\u4e2a\u5b50\u4e32\u91cd\u590d\u591a\u6b21\u6784\u6210\u3002\u7ed9\u5b9a\u7684\u5b57\u7b26\u4e32\u53ea\u542b\u6709\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\uff0c\u5e76\u4e14\u957f\u5ea6\u4e0d\u8d85\u8fc710000\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: "abab"\n\n\u8f93\u51fa: True\n\n\u89e3\u91ca: \u53ef\u7531\u5b50\u5b57\u7b26\u4e32 "ab" \u91cd\u590d\u4e24\u6b21\u6784\u6210\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: "aba"\n\n\u8f93\u51fa: False\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \n\u8f93\u5165: "abcabcabcabc"\n\n\u8f93\u51fa: True\n\n\u89e3\u91ca: \u53ef\u7531\u5b50\u5b57\u7b26\u4e32 "abc" \u91cd\u590d\u56db\u6b21\u6784\u6210\u3002 (\u6216\u8005\u5b50\u5b57\u7b26\u4e32 "abcabc" \u91cd\u590d\u4e24\u6b21\u6784\u6210\u3002)\n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean repeatedSubstringPattern(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def repeatedSubstringPattern(self, s):\n \"\"\"\n :type s: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def repeatedSubstringPattern(self, s: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool repeatedSubstringPattern(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool RepeatedSubstringPattern(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {boolean}\n */\nvar repeatedSubstringPattern = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Boolean}\ndef repeated_substring_pattern(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func repeatedSubstringPattern(_ s: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func repeatedSubstringPattern(s string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def repeatedSubstringPattern(s: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun repeatedSubstringPattern(s: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn repeated_substring_pattern(s: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Boolean\n */\n function repeatedSubstringPattern($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function repeatedSubstringPattern(s: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (repeated-substring-pattern s)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0459](https://leetcode-cn.com/problems/repeated-substring-pattern)", "[\u91cd\u590d\u7684\u5b50\u5b57\u7b26\u4e32](/solution/0400-0499/0459.Repeated%20Substring%20Pattern/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0459](https://leetcode.com/problems/repeated-substring-pattern)", "[Repeated Substring Pattern](/solution/0400-0499/0459.Repeated%20Substring%20Pattern/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "0458", "frontend_question_id": "0458", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/poor-pigs", "url_en": "https://leetcode.com/problems/poor-pigs", "relative_path_cn": "/solution/0400-0499/0458.Poor%20Pigs/README.md", "relative_path_en": "/solution/0400-0499/0458.Poor%20Pigs/README_EN.md", "title_cn": "\u53ef\u601c\u7684\u5c0f\u732a", "title_en": "Poor Pigs", "question_title_slug": "poor-pigs", "content_en": "

    There are buckets buckets of liquid, where exactly one of the buckets is poisonous. To figure out which one is poisonous, you feed some number of (poor) pigs the liquid to see whether they will die or not. Unfortunately, you only have minutesToTest minutes to determine which bucket is poisonous.

    \n\n

    You can feed the pigs according to these steps:

    \n\n
      \n\t
    1. Choose some live pigs to feed.
    2. \n\t
    3. For each pig, choose which buckets to feed it. The pig will consume all the chosen buckets simultaneously and will take no time.
    4. \n\t
    5. Wait for minutesToDie minutes. You may not feed any other pigs during this time.
    6. \n\t
    7. After minutesToDie minutes have passed, any pigs that have been fed the poisonous bucket will die, and all others will survive.
    8. \n\t
    9. Repeat this process until you run out of time.
    10. \n
    \n\n

    Given buckets, minutesToDie, and minutesToTest, return the minimum number of pigs needed to figure out which bucket is poisonous within the allotted time.

    \n\n

     

    \n

    Example 1:

    \n
    Input: buckets = 1000, minutesToDie = 15, minutesToTest = 60\nOutput: 5\n

    Example 2:

    \n
    Input: buckets = 4, minutesToDie = 15, minutesToTest = 15\nOutput: 2\n

    Example 3:

    \n
    Input: buckets = 4, minutesToDie = 15, minutesToTest = 30\nOutput: 2\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= buckets <= 1000
    • \n\t
    • 1 <= minutesToDie <= minutesToTest <= 100
    • \n
    \n", "content_cn": "

    \u6709 buckets \u6876\u6db2\u4f53\uff0c\u5176\u4e2d \u6b63\u597d \u6709\u4e00\u6876\u542b\u6709\u6bd2\u836f\uff0c\u5176\u4f59\u88c5\u7684\u90fd\u662f\u6c34\u3002\u5b83\u4eec\u4ece\u5916\u89c2\u770b\u8d77\u6765\u90fd\u4e00\u6837\u3002\u4e3a\u4e86\u5f04\u6e05\u695a\u54ea\u53ea\u6c34\u6876\u542b\u6709\u6bd2\u836f\uff0c\u4f60\u53ef\u4ee5\u5582\u4e00\u4e9b\u732a\u559d\uff0c\u901a\u8fc7\u89c2\u5bdf\u732a\u662f\u5426\u4f1a\u6b7b\u8fdb\u884c\u5224\u65ad\u3002\u4e0d\u5e78\u7684\u662f\uff0c\u4f60\u53ea\u6709\u00a0minutesToTest \u5206\u949f\u65f6\u95f4\u6765\u786e\u5b9a\u54ea\u6876\u6db2\u4f53\u662f\u6709\u6bd2\u7684\u3002

    \n\n

    \u5582\u732a\u7684\u89c4\u5219\u5982\u4e0b\uff1a

    \n\n
      \n\t
    1. \u9009\u62e9\u82e5\u5e72\u6d3b\u732a\u8fdb\u884c\u5582\u517b
    2. \n\t
    3. \u53ef\u4ee5\u5141\u8bb8\u5c0f\u732a\u540c\u65f6\u996e\u7528\u4efb\u610f\u6570\u91cf\u7684\u6876\u4e2d\u7684\u6c34\uff0c\u5e76\u4e14\u8be5\u8fc7\u7a0b\u4e0d\u9700\u8981\u65f6\u95f4\u3002
    4. \n\t
    5. \u5c0f\u732a\u559d\u5b8c\u6c34\u540e\uff0c\u5fc5\u987b\u6709 minutesToDie \u5206\u949f\u7684\u51b7\u5374\u65f6\u95f4\u3002\u5728\u8fd9\u6bb5\u65f6\u95f4\u91cc\uff0c\u4f60\u53ea\u80fd\u89c2\u5bdf\uff0c\u800c\u4e0d\u5141\u8bb8\u7ee7\u7eed\u5582\u732a\u3002
    6. \n\t
    7. \u8fc7\u4e86 minutesToDie \u5206\u949f\u540e\uff0c\u6240\u6709\u559d\u5230\u6bd2\u836f\u7684\u732a\u90fd\u4f1a\u6b7b\u53bb\uff0c\u5176\u4ed6\u6240\u6709\u732a\u90fd\u4f1a\u6d3b\u4e0b\u6765\u3002
    8. \n\t
    9. \u91cd\u590d\u8fd9\u4e00\u8fc7\u7a0b\uff0c\u76f4\u5230\u65f6\u95f4\u7528\u5b8c\u3002
    10. \n
    \n\n

    \u7ed9\u4f60\u6876\u7684\u6570\u76ee buckets \uff0cminutesToDie \u548c minutesToTest \uff0c\u8fd4\u56de\u5728\u89c4\u5b9a\u65f6\u95f4\u5185\u5224\u65ad\u54ea\u4e2a\u6876\u6709\u6bd2\u6240\u9700\u7684 \u6700\u5c0f \u732a\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1abuckets = 1000, minutesToDie = 15, minutesToTest = 60\n\u8f93\u51fa\uff1a5\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1abuckets = 4, minutesToDie = 15, minutesToTest = 15\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1abuckets = 4, minutesToDie = 15, minutesToTest = 30\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= buckets <= 1000
    • \n\t
    • 1 <=\u00a0minutesToDie <=\u00a0minutesToTest <= 100
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int poorPigs(int buckets, int minutesToDie, int minutesToTest) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int poorPigs(int buckets, int minutesToDie, int minutesToTest) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def poorPigs(self, buckets, minutesToDie, minutesToTest):\n \"\"\"\n :type buckets: int\n :type minutesToDie: int\n :type minutesToTest: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def poorPigs(self, buckets: int, minutesToDie: int, minutesToTest: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint poorPigs(int buckets, int minutesToDie, int minutesToTest){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int PoorPigs(int buckets, int minutesToDie, int minutesToTest) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} buckets\n * @param {number} minutesToDie\n * @param {number} minutesToTest\n * @return {number}\n */\nvar poorPigs = function(buckets, minutesToDie, minutesToTest) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} buckets\n# @param {Integer} minutes_to_die\n# @param {Integer} minutes_to_test\n# @return {Integer}\ndef poor_pigs(buckets, minutes_to_die, minutes_to_test)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func poorPigs(_ buckets: Int, _ minutesToDie: Int, _ minutesToTest: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func poorPigs(buckets int, minutesToDie int, minutesToTest int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def poorPigs(buckets: Int, minutesToDie: Int, minutesToTest: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun poorPigs(buckets: Int, minutesToDie: Int, minutesToTest: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn poor_pigs(buckets: i32, minutes_to_die: i32, minutes_to_test: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $buckets\n * @param Integer $minutesToDie\n * @param Integer $minutesToTest\n * @return Integer\n */\n function poorPigs($buckets, $minutesToDie, $minutesToTest) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function poorPigs(buckets: number, minutesToDie: number, minutesToTest: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (poor-pigs buckets minutesToDie minutesToTest)\n (-> exact-integer? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0458](https://leetcode-cn.com/problems/poor-pigs)", "[\u53ef\u601c\u7684\u5c0f\u732a](/solution/0400-0499/0458.Poor%20Pigs/README.md)", "`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[0458](https://leetcode.com/problems/poor-pigs)", "[Poor Pigs](/solution/0400-0499/0458.Poor%20Pigs/README_EN.md)", "`Math`", "Hard", ""]}, {"question_id": "0457", "frontend_question_id": "0457", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/circular-array-loop", "url_en": "https://leetcode.com/problems/circular-array-loop", "relative_path_cn": "/solution/0400-0499/0457.Circular%20Array%20Loop/README.md", "relative_path_en": "/solution/0400-0499/0457.Circular%20Array%20Loop/README_EN.md", "title_cn": "\u73af\u5f62\u6570\u7ec4\u662f\u5426\u5b58\u5728\u5faa\u73af", "title_en": "Circular Array Loop", "question_title_slug": "circular-array-loop", "content_en": "

    You are playing a game involving a circular array of non-zero integers nums. Each nums[i] denotes the number of indices forward/backward you must move if you are located at index i:

    \n\n
      \n\t
    • If nums[i] is positive, move nums[i] steps forward, and
    • \n\t
    • If nums[i] is negative, move nums[i] steps backward.
    • \n
    \n\n

    Since the array is circular, you may assume that moving forward from the last element puts you on the first element, and moving backwards from the first element puts you on the last element.

    \n\n

    A cycle in the array consists of a sequence of indices seq of length k where:

    \n\n
      \n\t
    • Following the movement rules above results in the repeating index sequence seq[0] -> seq[1] -> ... -> seq[k - 1] -> seq[0] -> ...
    • \n\t
    • Every nums[seq[j]] is either all positive or all negative.
    • \n\t
    • k > 1
    • \n
    \n\n

    Return true if there is a cycle in nums, or false otherwise.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [2,-1,1,2,2]\nOutput: true\nExplanation:\nThere is a cycle from index 0 -> 2 -> 3 -> 0 -> ...\nThe cycle's length is 3.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [-1,2]\nOutput: false\nExplanation:\nThe sequence from index 1 -> 1 -> 1 -> ... is not a cycle because the sequence's length is 1.\nBy definition the sequence's length must be strictly greater than 1 to be a cycle.\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [-2,1,-1,-2,-2]\nOutput: false\nExplanation:\nThe sequence from index 1 -> 2 -> 1 -> ... is not a cycle because nums[1] is positive, but nums[2] is negative.\nEvery nums[seq[j]] must be either all positive or all negative.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 5000
    • \n\t
    • -1000 <= nums[i] <= 1000
    • \n\t
    • nums[i] != 0
    • \n
    \n\n

     

    \n

    Follow up: Could you solve it in O(n) time complexity and O(1) extra space complexity?

    \n", "content_cn": "

    \u5b58\u5728\u4e00\u4e2a\u4e0d\u542b 0 \u7684 \u73af\u5f62 \u6570\u7ec4\u00a0nums \uff0c\u6bcf\u4e2a nums[i] \u90fd\u8868\u793a\u4f4d\u4e8e\u4e0b\u6807 i \u7684\u89d2\u8272\u5e94\u8be5\u5411\u524d\u6216\u5411\u540e\u79fb\u52a8\u7684\u4e0b\u6807\u4e2a\u6570\uff1a

    \n\n
      \n\t
    • \u5982\u679c nums[i] \u662f\u6b63\u6570\uff0c\u5411\u524d \u79fb\u52a8 nums[i] \u6b65
    • \n\t
    • \u5982\u679c\u00a0nums[i] \u662f\u8d1f\u6570\uff0c\u5411\u540e \u79fb\u52a8 nums[i] \u6b65
    • \n
    \n\n

    \u56e0\u4e3a\u6570\u7ec4\u662f \u73af\u5f62 \u7684\uff0c\u6240\u4ee5\u53ef\u4ee5\u5047\u8bbe\u4ece\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u5411\u524d\u79fb\u52a8\u4e00\u6b65\u4f1a\u5230\u8fbe\u7b2c\u4e00\u4e2a\u5143\u7d20\uff0c\u800c\u7b2c\u4e00\u4e2a\u5143\u7d20\u5411\u540e\u79fb\u52a8\u4e00\u6b65\u4f1a\u5230\u8fbe\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u3002

    \n\n

    \u6570\u7ec4\u4e2d\u7684 \u5faa\u73af \u7531\u957f\u5ea6\u4e3a k \u7684\u4e0b\u6807\u5e8f\u5217 seq \uff1a

    \n\n
      \n\t
    • \u9075\u5faa\u4e0a\u8ff0\u79fb\u52a8\u89c4\u5219\u5c06\u5bfc\u81f4\u91cd\u590d\u4e0b\u6807\u5e8f\u5217 seq[0] -> seq[1] -> ... -> seq[k - 1] -> seq[0] -> ...
    • \n\t
    • \u6240\u6709 nums[seq[j]] \u5e94\u5f53\u4e0d\u662f \u5168\u6b63 \u5c31\u662f \u5168\u8d1f
    • \n\t
    • k > 1
    • \n
    \n\n

    \u5982\u679c nums \u4e2d\u5b58\u5728\u5faa\u73af\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [2,-1,1,2,2]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u5b58\u5728\u5faa\u73af\uff0c\u6309\u4e0b\u6807 0 -> 2 -> 3 -> 0 \u3002\u5faa\u73af\u957f\u5ea6\u4e3a 3 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [-1,2]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u6309\u4e0b\u6807 1 -> 1 -> 1 ... \u7684\u8fd0\u52a8\u65e0\u6cd5\u6784\u6210\u5faa\u73af\uff0c\u56e0\u4e3a\u5faa\u73af\u7684\u957f\u5ea6\u4e3a 1 \u3002\u6839\u636e\u5b9a\u4e49\uff0c\u5faa\u73af\u7684\u957f\u5ea6\u5fc5\u987b\u5927\u4e8e 1 \u3002\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \n\u8f93\u5165\uff1anums = [-2,1,-1,-2,-2]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u6309\u4e0b\u6807 1 -> 2 -> 1 -> ... \u7684\u8fd0\u52a8\u65e0\u6cd5\u6784\u6210\u5faa\u73af\uff0c\u56e0\u4e3a nums[1] \u662f\u6b63\u6570\uff0c\u800c nums[2] \u662f\u8d1f\u6570\u3002\n\u6240\u6709 nums[seq[j]] \u5e94\u5f53\u4e0d\u662f\u5168\u6b63\u5c31\u662f\u5168\u8d1f\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 5000
    • \n\t
    • -1000 <= nums[i] <= 1000
    • \n\t
    • nums[i] != 0
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u80fd\u8bbe\u8ba1\u4e00\u4e2a\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n) \u4e14\u989d\u5916\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a O(1) \u7684\u7b97\u6cd5\u5417\uff1f

    \n", "tags_en": ["Array", "Two Pointers"], "tags_cn": ["\u6570\u7ec4", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool circularArrayLoop(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean circularArrayLoop(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def circularArrayLoop(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def circularArrayLoop(self, nums: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool circularArrayLoop(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CircularArrayLoop(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {boolean}\n */\nvar circularArrayLoop = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Boolean}\ndef circular_array_loop(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func circularArrayLoop(_ nums: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func circularArrayLoop(nums []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def circularArrayLoop(nums: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun circularArrayLoop(nums: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn circular_array_loop(nums: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Boolean\n */\n function circularArrayLoop($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function circularArrayLoop(nums: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (circular-array-loop nums)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0457](https://leetcode-cn.com/problems/circular-array-loop)", "[\u73af\u5f62\u6570\u7ec4\u662f\u5426\u5b58\u5728\u5faa\u73af](/solution/0400-0499/0457.Circular%20Array%20Loop/README.md)", "`\u6570\u7ec4`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0457](https://leetcode.com/problems/circular-array-loop)", "[Circular Array Loop](/solution/0400-0499/0457.Circular%20Array%20Loop/README_EN.md)", "`Array`,`Two Pointers`", "Medium", ""]}, {"question_id": "0456", "frontend_question_id": "0456", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/132-pattern", "url_en": "https://leetcode.com/problems/132-pattern", "relative_path_cn": "/solution/0400-0499/0456.132%20Pattern/README.md", "relative_path_en": "/solution/0400-0499/0456.132%20Pattern/README_EN.md", "title_cn": "132 \u6a21\u5f0f", "title_en": "132 Pattern", "question_title_slug": "132-pattern", "content_en": "

    Given an array of n integers nums, a 132 pattern is a subsequence of three integers nums[i], nums[j] and nums[k] such that i < j < k and nums[i] < nums[k] < nums[j].

    \n\n

    Return true if there is a 132 pattern in nums, otherwise, return false.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,3,4]\nOutput: false\nExplanation: There is no 132 pattern in the sequence.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [3,1,4,2]\nOutput: true\nExplanation: There is a 132 pattern in the sequence: [1, 4, 2].\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [-1,3,2,0]\nOutput: true\nExplanation: There are three 132 patterns in the sequence: [-1, 3, 2], [-1, 3, 0] and [-1, 2, 0].\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= n <= 2 * 105
    • \n\t
    • -109 <= nums[i] <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \uff0c\u6570\u7ec4\u4e2d\u5171\u6709 n \u4e2a\u6574\u6570\u3002132 \u6a21\u5f0f\u7684\u5b50\u5e8f\u5217 \u7531\u4e09\u4e2a\u6574\u6570 nums[i]\u3001nums[j] \u548c nums[k] \u7ec4\u6210\uff0c\u5e76\u540c\u65f6\u6ee1\u8db3\uff1ai < j < k \u548c nums[i] < nums[k] < nums[j] \u3002

    \n\n

    \u5982\u679c nums \u4e2d\u5b58\u5728 132 \u6a21\u5f0f\u7684\u5b50\u5e8f\u5217 \uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u5f88\u5bb9\u6613\u60f3\u5230\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n^2) \u7684\u89e3\u51b3\u65b9\u6848\uff0c\u4f60\u53ef\u4ee5\u8bbe\u8ba1\u4e00\u4e2a\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n logn) \u6216 O(n) \u7684\u89e3\u51b3\u65b9\u6848\u5417\uff1f

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,3,4]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u5e8f\u5217\u4e2d\u4e0d\u5b58\u5728 132 \u6a21\u5f0f\u7684\u5b50\u5e8f\u5217\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [3,1,4,2]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u5e8f\u5217\u4e2d\u6709 1 \u4e2a 132 \u6a21\u5f0f\u7684\u5b50\u5e8f\u5217\uff1a [1, 4, 2] \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [-1,3,2,0]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u5e8f\u5217\u4e2d\u6709 3 \u4e2a 132 \u6a21\u5f0f\u7684\u7684\u5b50\u5e8f\u5217\uff1a[-1, 3, 2]\u3001[-1, 3, 0] \u548c [-1, 2, 0] \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= n <= 104
    • \n\t
    • -109 <= nums[i] <= 109
    • \n
    \n", "tags_en": ["Stack"], "tags_cn": ["\u6808"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool find132pattern(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean find132pattern(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def find132pattern(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def find132pattern(self, nums: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool find132pattern(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool Find132pattern(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {boolean}\n */\nvar find132pattern = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Boolean}\ndef find132pattern(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func find132pattern(_ nums: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func find132pattern(nums []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def find132pattern(nums: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun find132pattern(nums: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find132pattern(nums: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Boolean\n */\n function find132pattern($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function find132pattern(nums: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find132pattern nums)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0456](https://leetcode-cn.com/problems/132-pattern)", "[132 \u6a21\u5f0f](/solution/0400-0499/0456.132%20Pattern/README.md)", "`\u6808`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0456](https://leetcode.com/problems/132-pattern)", "[132 Pattern](/solution/0400-0499/0456.132%20Pattern/README_EN.md)", "`Stack`", "Medium", ""]}, {"question_id": "0455", "frontend_question_id": "0455", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/assign-cookies", "url_en": "https://leetcode.com/problems/assign-cookies", "relative_path_cn": "/solution/0400-0499/0455.Assign%20Cookies/README.md", "relative_path_en": "/solution/0400-0499/0455.Assign%20Cookies/README_EN.md", "title_cn": "\u5206\u53d1\u997c\u5e72", "title_en": "Assign Cookies", "question_title_slug": "assign-cookies", "content_en": "

    Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie.

    \n\n

    Each child i has a greed factor g[i], which is the minimum size of a cookie that the child will be content with; and each cookie j has a size s[j]. If s[j] >= g[i], we can assign the cookie j to the child i, and the child i will be content. Your goal is to maximize the number of your content children and output the maximum number.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: g = [1,2,3], s = [1,1]\nOutput: 1\nExplanation: You have 3 children and 2 cookies. The greed factors of 3 children are 1, 2, 3. \nAnd even though you have 2 cookies, since their size is both 1, you could only make the child whose greed factor is 1 content.\nYou need to output 1.\n
    \n\n

    Example 2:

    \n\n
    \nInput: g = [1,2], s = [1,2,3]\nOutput: 2\nExplanation: You have 2 children and 3 cookies. The greed factors of 2 children are 1, 2. \nYou have 3 cookies and their sizes are big enough to gratify all of the children, \nYou need to output 2.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= g.length <= 3 * 104
    • \n\t
    • 0 <= s.length <= 3 * 104
    • \n\t
    • 1 <= g[i], s[j] <= 231 - 1
    • \n
    \n", "content_cn": "

    \u5047\u8bbe\u4f60\u662f\u4e00\u4f4d\u5f88\u68d2\u7684\u5bb6\u957f\uff0c\u60f3\u8981\u7ed9\u4f60\u7684\u5b69\u5b50\u4eec\u4e00\u4e9b\u5c0f\u997c\u5e72\u3002\u4f46\u662f\uff0c\u6bcf\u4e2a\u5b69\u5b50\u6700\u591a\u53ea\u80fd\u7ed9\u4e00\u5757\u997c\u5e72\u3002

    \n\n

    \u5bf9\u6bcf\u4e2a\u5b69\u5b50 i\uff0c\u90fd\u6709\u4e00\u4e2a\u80c3\u53e3\u503c\u00a0g[i]\uff0c\u8fd9\u662f\u80fd\u8ba9\u5b69\u5b50\u4eec\u6ee1\u8db3\u80c3\u53e3\u7684\u997c\u5e72\u7684\u6700\u5c0f\u5c3a\u5bf8\uff1b\u5e76\u4e14\u6bcf\u5757\u997c\u5e72 j\uff0c\u90fd\u6709\u4e00\u4e2a\u5c3a\u5bf8 s[j]\u00a0\u3002\u5982\u679c s[j]\u00a0>= g[i]\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u8fd9\u4e2a\u997c\u5e72 j \u5206\u914d\u7ed9\u5b69\u5b50 i \uff0c\u8fd9\u4e2a\u5b69\u5b50\u4f1a\u5f97\u5230\u6ee1\u8db3\u3002\u4f60\u7684\u76ee\u6807\u662f\u5c3d\u53ef\u80fd\u6ee1\u8db3\u8d8a\u591a\u6570\u91cf\u7684\u5b69\u5b50\uff0c\u5e76\u8f93\u51fa\u8fd9\u4e2a\u6700\u5927\u6570\u503c\u3002

    \n\u00a0\n\n

    \u793a\u4f8b\u00a01:

    \n\n
    \n\u8f93\u5165: g = [1,2,3], s = [1,1]\n\u8f93\u51fa: 1\n\u89e3\u91ca: \n\u4f60\u6709\u4e09\u4e2a\u5b69\u5b50\u548c\u4e24\u5757\u5c0f\u997c\u5e72\uff0c3\u4e2a\u5b69\u5b50\u7684\u80c3\u53e3\u503c\u5206\u522b\u662f\uff1a1,2,3\u3002\n\u867d\u7136\u4f60\u6709\u4e24\u5757\u5c0f\u997c\u5e72\uff0c\u7531\u4e8e\u4ed6\u4eec\u7684\u5c3a\u5bf8\u90fd\u662f1\uff0c\u4f60\u53ea\u80fd\u8ba9\u80c3\u53e3\u503c\u662f1\u7684\u5b69\u5b50\u6ee1\u8db3\u3002\n\u6240\u4ee5\u4f60\u5e94\u8be5\u8f93\u51fa1\u3002\n
    \n\n

    \u793a\u4f8b\u00a02:

    \n\n
    \n\u8f93\u5165: g = [1,2], s = [1,2,3]\n\u8f93\u51fa: 2\n\u89e3\u91ca: \n\u4f60\u6709\u4e24\u4e2a\u5b69\u5b50\u548c\u4e09\u5757\u5c0f\u997c\u5e72\uff0c2\u4e2a\u5b69\u5b50\u7684\u80c3\u53e3\u503c\u5206\u522b\u662f1,2\u3002\n\u4f60\u62e5\u6709\u7684\u997c\u5e72\u6570\u91cf\u548c\u5c3a\u5bf8\u90fd\u8db3\u4ee5\u8ba9\u6240\u6709\u5b69\u5b50\u6ee1\u8db3\u3002\n\u6240\u4ee5\u4f60\u5e94\u8be5\u8f93\u51fa2.\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= g.length <= 3 * 104
    • \n\t
    • 0 <= s.length <= 3 * 104
    • \n\t
    • 1 <= g[i], s[j] <=\u00a0231 - 1
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findContentChildren(vector& g, vector& s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findContentChildren(int[] g, int[] s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findContentChildren(self, g, s):\n \"\"\"\n :type g: List[int]\n :type s: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findContentChildren(self, g: List[int], s: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findContentChildren(int* g, int gSize, int* s, int sSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindContentChildren(int[] g, int[] s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} g\n * @param {number[]} s\n * @return {number}\n */\nvar findContentChildren = function(g, s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} g\n# @param {Integer[]} s\n# @return {Integer}\ndef find_content_children(g, s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findContentChildren(_ g: [Int], _ s: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findContentChildren(g []int, s []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findContentChildren(g: Array[Int], s: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findContentChildren(g: IntArray, s: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_content_children(g: Vec, s: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $g\n * @param Integer[] $s\n * @return Integer\n */\n function findContentChildren($g, $s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findContentChildren(g: number[], s: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-content-children g s)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0455](https://leetcode-cn.com/problems/assign-cookies)", "[\u5206\u53d1\u997c\u5e72](/solution/0400-0499/0455.Assign%20Cookies/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u7b80\u5355", ""], "md_table_row_en": ["[0455](https://leetcode.com/problems/assign-cookies)", "[Assign Cookies](/solution/0400-0499/0455.Assign%20Cookies/README_EN.md)", "`Greedy`", "Easy", ""]}, {"question_id": "0454", "frontend_question_id": "0454", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/4sum-ii", "url_en": "https://leetcode.com/problems/4sum-ii", "relative_path_cn": "/solution/0400-0499/0454.4Sum%20II/README.md", "relative_path_en": "/solution/0400-0499/0454.4Sum%20II/README_EN.md", "title_cn": "\u56db\u6570\u76f8\u52a0 II", "title_en": "4Sum II", "question_title_slug": "4sum-ii", "content_en": "

    Given four integer arrays nums1, nums2, nums3, and nums4 all of length n, return the number of tuples (i, j, k, l) such that:

    \n\n
      \n\t
    • 0 <= i, j, k, l < n
    • \n\t
    • nums1[i] + nums2[j] + nums3[k] + nums4[l] == 0
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums1 = [1,2], nums2 = [-2,-1], nums3 = [-1,2], nums4 = [0,2]\nOutput: 2\nExplanation:\nThe two tuples are:\n1. (0, 0, 0, 1) -> nums1[0] + nums2[0] + nums3[0] + nums4[1] = 1 + (-2) + (-1) + 2 = 0\n2. (1, 1, 0, 0) -> nums1[1] + nums2[1] + nums3[0] + nums4[0] = 2 + (-1) + (-1) + 0 = 0\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums1 = [0], nums2 = [0], nums3 = [0], nums4 = [0]\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == nums1.length
    • \n\t
    • n == nums2.length
    • \n\t
    • n == nums3.length
    • \n\t
    • n == nums4.length
    • \n\t
    • 1 <= n <= 200
    • \n\t
    • -228 <= nums1[i], nums2[i], nums3[i], nums4[i] <= 228
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u56db\u4e2a\u5305\u542b\u6574\u6570\u7684\u6570\u7ec4\u5217\u8868 A , B , C , D ,\u8ba1\u7b97\u6709\u591a\u5c11\u4e2a\u5143\u7ec4 (i, j, k, l) \uff0c\u4f7f\u5f97 A[i] + B[j] + C[k] + D[l] = 0\u3002

    \n\n

    \u4e3a\u4e86\u4f7f\u95ee\u9898\u7b80\u5355\u5316\uff0c\u6240\u6709\u7684 A, B, C, D \u5177\u6709\u76f8\u540c\u7684\u957f\u5ea6 N\uff0c\u4e14 0 ≤ N ≤ 500 \u3002\u6240\u6709\u6574\u6570\u7684\u8303\u56f4\u5728 -228 \u5230 228 - 1 \u4e4b\u95f4\uff0c\u6700\u7ec8\u7ed3\u679c\u4e0d\u4f1a\u8d85\u8fc7 231 - 1 \u3002

    \n\n

    \u4f8b\u5982:

    \n\n
    \n\u8f93\u5165:\nA = [ 1, 2]\nB = [-2,-1]\nC = [-1, 2]\nD = [ 0, 2]\n\n\u8f93\u51fa:\n2\n\n\u89e3\u91ca:\n\u4e24\u4e2a\u5143\u7ec4\u5982\u4e0b:\n1. (0, 0, 0, 1) -> A[0] + B[0] + C[0] + D[1] = 1 + (-2) + (-1) + 2 = 0\n2. (1, 1, 0, 0) -> A[1] + B[1] + C[0] + D[0] = 2 + (-1) + (-1) + 0 = 0\n
    \n", "tags_en": ["Hash Table", "Binary Search"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int fourSumCount(vector& nums1, vector& nums2, vector& nums3, vector& nums4) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int fourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def fourSumCount(self, nums1, nums2, nums3, nums4):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n :type nums3: List[int]\n :type nums4: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def fourSumCount(self, nums1: List[int], nums2: List[int], nums3: List[int], nums4: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint fourSumCount(int* nums1, int nums1Size, int* nums2, int nums2Size, int* nums3, int nums3Size, int* nums4, int nums4Size){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums1\n * @param {number[]} nums2\n * @param {number[]} nums3\n * @param {number[]} nums4\n * @return {number}\n */\nvar fourSumCount = function(nums1, nums2, nums3, nums4) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums1\n# @param {Integer[]} nums2\n# @param {Integer[]} nums3\n# @param {Integer[]} nums4\n# @return {Integer}\ndef four_sum_count(nums1, nums2, nums3, nums4)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func fourSumCount(_ nums1: [Int], _ nums2: [Int], _ nums3: [Int], _ nums4: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func fourSumCount(nums1 []int, nums2 []int, nums3 []int, nums4 []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def fourSumCount(nums1: Array[Int], nums2: Array[Int], nums3: Array[Int], nums4: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun fourSumCount(nums1: IntArray, nums2: IntArray, nums3: IntArray, nums4: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn four_sum_count(nums1: Vec, nums2: Vec, nums3: Vec, nums4: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums1\n * @param Integer[] $nums2\n * @param Integer[] $nums3\n * @param Integer[] $nums4\n * @return Integer\n */\n function fourSumCount($nums1, $nums2, $nums3, $nums4) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function fourSumCount(nums1: number[], nums2: number[], nums3: number[], nums4: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (four-sum-count nums1 nums2 nums3 nums4)\n (-> (listof exact-integer?) (listof exact-integer?) (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0454](https://leetcode-cn.com/problems/4sum-ii)", "[\u56db\u6570\u76f8\u52a0 II](/solution/0400-0499/0454.4Sum%20II/README.md)", "`\u54c8\u5e0c\u8868`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0454](https://leetcode.com/problems/4sum-ii)", "[4Sum II](/solution/0400-0499/0454.4Sum%20II/README_EN.md)", "`Hash Table`,`Binary Search`", "Medium", ""]}, {"question_id": "0453", "frontend_question_id": "0453", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-moves-to-equal-array-elements", "url_en": "https://leetcode.com/problems/minimum-moves-to-equal-array-elements", "relative_path_cn": "/solution/0400-0499/0453.Minimum%20Moves%20to%20Equal%20Array%20Elements/README.md", "relative_path_en": "/solution/0400-0499/0453.Minimum%20Moves%20to%20Equal%20Array%20Elements/README_EN.md", "title_cn": "\u6700\u5c0f\u64cd\u4f5c\u6b21\u6570\u4f7f\u6570\u7ec4\u5143\u7d20\u76f8\u7b49", "title_en": "Minimum Moves to Equal Array Elements", "question_title_slug": "minimum-moves-to-equal-array-elements", "content_en": "

    Given an integer array nums of size n, return the minimum number of moves required to make all array elements equal.

    \n\n

    In one move, you can increment n - 1 elements of the array by 1.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,3]\nOutput: 3\nExplanation: Only three moves are needed (remember each move increments two elements):\n[1,2,3]  =>  [2,3,3]  =>  [3,4,3]  =>  [4,4,4]\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,1,1]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • -109 <= nums[i] <= 109
    • \n\t
    • The answer is guaranteed to fit in a 32-bit integer.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684 \u975e\u7a7a \u6574\u6570\u6570\u7ec4\uff0c\u6bcf\u6b21\u64cd\u4f5c\u5c06\u4f1a\u4f7f n - 1 \u4e2a\u5143\u7d20\u589e\u52a0 1\u3002\u627e\u51fa\u8ba9\u6570\u7ec4\u6240\u6709\u5143\u7d20\u76f8\u7b49\u7684\u6700\u5c0f\u64cd\u4f5c\u6b21\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\n[1,2,3]\n\u8f93\u51fa\uff1a\n3\n\u89e3\u91ca\uff1a\n\u53ea\u9700\u89813\u6b21\u64cd\u4f5c\uff08\u6ce8\u610f\u6bcf\u6b21\u64cd\u4f5c\u4f1a\u589e\u52a0\u4e24\u4e2a\u5143\u7d20\u7684\u503c\uff09\uff1a\n[1,2,3]  =>  [2,3,3]  =>  [3,4,3]  =>  [4,4,4]\n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minMoves(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minMoves(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minMoves(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minMoves(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minMoves(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinMoves(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar minMoves = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef min_moves(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minMoves(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minMoves(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minMoves(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minMoves(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_moves(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function minMoves($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minMoves(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-moves nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0453](https://leetcode-cn.com/problems/minimum-moves-to-equal-array-elements)", "[\u6700\u5c0f\u64cd\u4f5c\u6b21\u6570\u4f7f\u6570\u7ec4\u5143\u7d20\u76f8\u7b49](/solution/0400-0499/0453.Minimum%20Moves%20to%20Equal%20Array%20Elements/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0453](https://leetcode.com/problems/minimum-moves-to-equal-array-elements)", "[Minimum Moves to Equal Array Elements](/solution/0400-0499/0453.Minimum%20Moves%20to%20Equal%20Array%20Elements/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "0452", "frontend_question_id": "0452", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-number-of-arrows-to-burst-balloons", "url_en": "https://leetcode.com/problems/minimum-number-of-arrows-to-burst-balloons", "relative_path_cn": "/solution/0400-0499/0452.Minimum%20Number%20of%20Arrows%20to%20Burst%20Balloons/README.md", "relative_path_en": "/solution/0400-0499/0452.Minimum%20Number%20of%20Arrows%20to%20Burst%20Balloons/README_EN.md", "title_cn": "\u7528\u6700\u5c11\u6570\u91cf\u7684\u7bad\u5f15\u7206\u6c14\u7403", "title_en": "Minimum Number of Arrows to Burst Balloons", "question_title_slug": "minimum-number-of-arrows-to-burst-balloons", "content_en": "

    There are some spherical balloons spread in two-dimensional space. For each balloon, provided input is the start and end coordinates of the horizontal diameter. Since it's horizontal, y-coordinates don't matter, and hence the x-coordinates of start and end of the diameter suffice. The start is always smaller than the end.

    \n\n

    An arrow can be shot up exactly vertically from different points along the x-axis. A balloon with xstart and xend bursts by an arrow shot at x if xstart ≤ x ≤ xend. There is no limit to the number of arrows that can be shot. An arrow once shot keeps traveling up infinitely.

    \n\n

    Given an array points where points[i] = [xstart, xend], return the minimum number of arrows that must be shot to burst all balloons.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: points = [[10,16],[2,8],[1,6],[7,12]]\nOutput: 2\nExplanation: One way is to shoot one arrow for example at x = 6 (bursting the balloons [2,8] and [1,6]) and another arrow at x = 11 (bursting the other two balloons).\n
    \n\n

    Example 2:

    \n\n
    \nInput: points = [[1,2],[3,4],[5,6],[7,8]]\nOutput: 4\n
    \n\n

    Example 3:

    \n\n
    \nInput: points = [[1,2],[2,3],[3,4],[4,5]]\nOutput: 2\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= points.length <= 104
    • \n\t
    • points[i].length == 2
    • \n\t
    • -231 <= xstart < xend <= 231 - 1
    • \n
    \n", "content_cn": "

    \u5728\u4e8c\u7ef4\u7a7a\u95f4\u4e2d\u6709\u8bb8\u591a\u7403\u5f62\u7684\u6c14\u7403\u3002\u5bf9\u4e8e\u6bcf\u4e2a\u6c14\u7403\uff0c\u63d0\u4f9b\u7684\u8f93\u5165\u662f\u6c34\u5e73\u65b9\u5411\u4e0a\uff0c\u6c14\u7403\u76f4\u5f84\u7684\u5f00\u59cb\u548c\u7ed3\u675f\u5750\u6807\u3002\u7531\u4e8e\u5b83\u662f\u6c34\u5e73\u7684\uff0c\u6240\u4ee5\u7eb5\u5750\u6807\u5e76\u4e0d\u91cd\u8981\uff0c\u56e0\u6b64\u53ea\u8981\u77e5\u9053\u5f00\u59cb\u548c\u7ed3\u675f\u7684\u6a2a\u5750\u6807\u5c31\u8db3\u591f\u4e86\u3002\u5f00\u59cb\u5750\u6807\u603b\u662f\u5c0f\u4e8e\u7ed3\u675f\u5750\u6807\u3002

    \n\n

    \u4e00\u652f\u5f13\u7bad\u53ef\u4ee5\u6cbf\u7740 x \u8f74\u4ece\u4e0d\u540c\u70b9\u5b8c\u5168\u5782\u76f4\u5730\u5c04\u51fa\u3002\u5728\u5750\u6807 x \u5904\u5c04\u51fa\u4e00\u652f\u7bad\uff0c\u82e5\u6709\u4e00\u4e2a\u6c14\u7403\u7684\u76f4\u5f84\u7684\u5f00\u59cb\u548c\u7ed3\u675f\u5750\u6807\u4e3a xstart\uff0cxend\uff0c \u4e14\u6ee1\u8db3 \u00a0xstart\u00a0\u2264 x \u2264 xend\uff0c\u5219\u8be5\u6c14\u7403\u4f1a\u88ab\u5f15\u7206\u3002\u53ef\u4ee5\u5c04\u51fa\u7684\u5f13\u7bad\u7684\u6570\u91cf\u6ca1\u6709\u9650\u5236\u3002 \u5f13\u7bad\u4e00\u65e6\u88ab\u5c04\u51fa\u4e4b\u540e\uff0c\u53ef\u4ee5\u65e0\u9650\u5730\u524d\u8fdb\u3002\u6211\u4eec\u60f3\u627e\u5230\u4f7f\u5f97\u6240\u6709\u6c14\u7403\u5168\u90e8\u88ab\u5f15\u7206\uff0c\u6240\u9700\u7684\u5f13\u7bad\u7684\u6700\u5c0f\u6570\u91cf\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 points \uff0c\u5176\u4e2d points [i] = [xstart,xend] \uff0c\u8fd4\u56de\u5f15\u7206\u6240\u6709\u6c14\u7403\u6240\u5fc5\u987b\u5c04\u51fa\u7684\u6700\u5c0f\u5f13\u7bad\u6570\u3002

    \n\u00a0\n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1apoints = [[10,16],[2,8],[1,6],[7,12]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5bf9\u4e8e\u8be5\u6837\u4f8b\uff0cx = 6 \u53ef\u4ee5\u5c04\u7206 [2,8],[1,6] \u4e24\u4e2a\u6c14\u7403\uff0c\u4ee5\u53ca x = 11 \u5c04\u7206\u53e6\u5916\u4e24\u4e2a\u6c14\u7403
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1apoints = [[1,2],[3,4],[5,6],[7,8]]\n\u8f93\u51fa\uff1a4\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1apoints = [[1,2],[2,3],[3,4],[4,5]]\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1apoints = [[1,2]]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1apoints = [[2,3],[2,3]]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= points.length <= 104
    • \n\t
    • points[i].length == 2
    • \n\t
    • -231 <= xstart <\u00a0xend <= 231 - 1
    • \n
    \n", "tags_en": ["Greedy", "Sort"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6392\u5e8f"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findMinArrowShots(vector>& points) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findMinArrowShots(int[][] points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findMinArrowShots(self, points):\n \"\"\"\n :type points: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findMinArrowShots(self, points: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findMinArrowShots(int** points, int pointsSize, int* pointsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindMinArrowShots(int[][] points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} points\n * @return {number}\n */\nvar findMinArrowShots = function(points) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} points\n# @return {Integer}\ndef find_min_arrow_shots(points)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findMinArrowShots(_ points: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findMinArrowShots(points [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findMinArrowShots(points: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findMinArrowShots(points: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_min_arrow_shots(points: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $points\n * @return Integer\n */\n function findMinArrowShots($points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findMinArrowShots(points: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-min-arrow-shots points)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0452](https://leetcode-cn.com/problems/minimum-number-of-arrows-to-burst-balloons)", "[\u7528\u6700\u5c11\u6570\u91cf\u7684\u7bad\u5f15\u7206\u6c14\u7403](/solution/0400-0499/0452.Minimum%20Number%20of%20Arrows%20to%20Burst%20Balloons/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6392\u5e8f`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0452](https://leetcode.com/problems/minimum-number-of-arrows-to-burst-balloons)", "[Minimum Number of Arrows to Burst Balloons](/solution/0400-0499/0452.Minimum%20Number%20of%20Arrows%20to%20Burst%20Balloons/README_EN.md)", "`Greedy`,`Sort`", "Medium", ""]}, {"question_id": "0451", "frontend_question_id": "0451", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sort-characters-by-frequency", "url_en": "https://leetcode.com/problems/sort-characters-by-frequency", "relative_path_cn": "/solution/0400-0499/0451.Sort%20Characters%20By%20Frequency/README.md", "relative_path_en": "/solution/0400-0499/0451.Sort%20Characters%20By%20Frequency/README_EN.md", "title_cn": "\u6839\u636e\u5b57\u7b26\u51fa\u73b0\u9891\u7387\u6392\u5e8f", "title_en": "Sort Characters By Frequency", "question_title_slug": "sort-characters-by-frequency", "content_en": "

    Given a string s, sort it in decreasing order based on the frequency of characters, and return the sorted string.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "tree"\nOutput: "eert"\nExplanation: 'e' appears twice while 'r' and 't' both appear once.\nSo 'e' must appear before both 'r' and 't'. Therefore "eetr" is also a valid answer.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "cccaaa"\nOutput: "aaaccc"\nExplanation: Both 'c' and 'a' appear three times, so "aaaccc" is also a valid answer.\nNote that "cacaca" is incorrect, as the same characters must be together.\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "Aabb"\nOutput: "bbAa"\nExplanation: "bbaA" is also a valid answer, but "Aabb" is incorrect.\nNote that 'A' and 'a' are treated as two different characters.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 5 * 105
    • \n\t
    • s consists of English letters and digits.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u8bf7\u5c06\u5b57\u7b26\u4e32\u91cc\u7684\u5b57\u7b26\u6309\u7167\u51fa\u73b0\u7684\u9891\u7387\u964d\u5e8f\u6392\u5217\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165:\n"tree"\n\n\u8f93\u51fa:\n"eert"\n\n\u89e3\u91ca:\n'e'\u51fa\u73b0\u4e24\u6b21\uff0c'r'\u548c't'\u90fd\u53ea\u51fa\u73b0\u4e00\u6b21\u3002\n\u56e0\u6b64'e'\u5fc5\u987b\u51fa\u73b0\u5728'r'\u548c't'\u4e4b\u524d\u3002\u6b64\u5916\uff0c"eetr"\u4e5f\u662f\u4e00\u4e2a\u6709\u6548\u7684\u7b54\u6848\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165:\n"cccaaa"\n\n\u8f93\u51fa:\n"cccaaa"\n\n\u89e3\u91ca:\n'c'\u548c'a'\u90fd\u51fa\u73b0\u4e09\u6b21\u3002\u6b64\u5916\uff0c"aaaccc"\u4e5f\u662f\u6709\u6548\u7684\u7b54\u6848\u3002\n\u6ce8\u610f"cacaca"\u662f\u4e0d\u6b63\u786e\u7684\uff0c\u56e0\u4e3a\u76f8\u540c\u7684\u5b57\u6bcd\u5fc5\u987b\u653e\u5728\u4e00\u8d77\u3002\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \n\u8f93\u5165:\n"Aabb"\n\n\u8f93\u51fa:\n"bbAa"\n\n\u89e3\u91ca:\n\u6b64\u5916\uff0c"bbaA"\u4e5f\u662f\u4e00\u4e2a\u6709\u6548\u7684\u7b54\u6848\uff0c\u4f46"Aabb"\u662f\u4e0d\u6b63\u786e\u7684\u3002\n\u6ce8\u610f'A'\u548c'a'\u88ab\u8ba4\u4e3a\u662f\u4e24\u79cd\u4e0d\u540c\u7684\u5b57\u7b26\u3002\n
    \n", "tags_en": ["Heap", "Hash Table"], "tags_cn": ["\u5806", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string frequencySort(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String frequencySort(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def frequencySort(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def frequencySort(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * frequencySort(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string FrequencySort(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar frequencySort = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef frequency_sort(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func frequencySort(_ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func frequencySort(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def frequencySort(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun frequencySort(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn frequency_sort(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function frequencySort($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function frequencySort(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (frequency-sort s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0451](https://leetcode-cn.com/problems/sort-characters-by-frequency)", "[\u6839\u636e\u5b57\u7b26\u51fa\u73b0\u9891\u7387\u6392\u5e8f](/solution/0400-0499/0451.Sort%20Characters%20By%20Frequency/README.md)", "`\u5806`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0451](https://leetcode.com/problems/sort-characters-by-frequency)", "[Sort Characters By Frequency](/solution/0400-0499/0451.Sort%20Characters%20By%20Frequency/README_EN.md)", "`Heap`,`Hash Table`", "Medium", ""]}, {"question_id": "0450", "frontend_question_id": "0450", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/delete-node-in-a-bst", "url_en": "https://leetcode.com/problems/delete-node-in-a-bst", "relative_path_cn": "/solution/0400-0499/0450.Delete%20Node%20in%20a%20BST/README.md", "relative_path_en": "/solution/0400-0499/0450.Delete%20Node%20in%20a%20BST/README_EN.md", "title_cn": "\u5220\u9664\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u7684\u8282\u70b9", "title_en": "Delete Node in a BST", "question_title_slug": "delete-node-in-a-bst", "content_en": "

    Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return the root node reference (possibly updated) of the BST.

    \n\n

    Basically, the deletion can be divided into two stages:

    \n\n
      \n\t
    1. Search for a node to remove.
    2. \n\t
    3. If the node is found, delete the node.
    4. \n
    \n\n

    Follow up: Can you solve it with time complexity O(height of tree)?

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [5,3,6,2,4,null,7], key = 3\nOutput: [5,4,6,2,null,null,7]\nExplanation: Given key to delete is 3. So we find the node with value 3 and delete it.\nOne valid answer is [5,4,6,2,null,null,7], shown in the above BST.\nPlease notice that another valid answer is [5,2,6,null,4,null,7] and it's also accepted.\n\"\"\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = [5,3,6,2,4,null,7], key = 0\nOutput: [5,3,6,2,4,null,7]\nExplanation: The tree does not contain a node with value = 0.\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = [], key = 0\nOutput: []\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [0, 104].
    • \n\t
    • -105 <= Node.val <= 105
    • \n\t
    • Each node has a unique value.
    • \n\t
    • root is a valid binary search tree.
    • \n\t
    • -105 <= key <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6839\u8282\u70b9 root \u548c\u4e00\u4e2a\u503c key\uff0c\u5220\u9664\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u7684 key \u5bf9\u5e94\u7684\u8282\u70b9\uff0c\u5e76\u4fdd\u8bc1\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6027\u8d28\u4e0d\u53d8\u3002\u8fd4\u56de\u4e8c\u53c9\u641c\u7d22\u6811\uff08\u6709\u53ef\u80fd\u88ab\u66f4\u65b0\uff09\u7684\u6839\u8282\u70b9\u7684\u5f15\u7528\u3002

    \n\n

    \u4e00\u822c\u6765\u8bf4\uff0c\u5220\u9664\u8282\u70b9\u53ef\u5206\u4e3a\u4e24\u4e2a\u6b65\u9aa4\uff1a

    \n\n
      \n\t
    1. \u9996\u5148\u627e\u5230\u9700\u8981\u5220\u9664\u7684\u8282\u70b9\uff1b
    2. \n\t
    3. \u5982\u679c\u627e\u5230\u4e86\uff0c\u5220\u9664\u5b83\u3002
    4. \n
    \n\n

    \u8bf4\u660e\uff1a \u8981\u6c42\u7b97\u6cd5\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(h)\uff0ch \u4e3a\u6811\u7684\u9ad8\u5ea6\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \nroot = [5,3,6,2,4,null,7]\nkey = 3\n\n    5\n   / \\\n  3   6\n / \\   \\\n2   4   7\n\n\u7ed9\u5b9a\u9700\u8981\u5220\u9664\u7684\u8282\u70b9\u503c\u662f 3\uff0c\u6240\u4ee5\u6211\u4eec\u9996\u5148\u627e\u5230 3 \u8fd9\u4e2a\u8282\u70b9\uff0c\u7136\u540e\u5220\u9664\u5b83\u3002\n\n\u4e00\u4e2a\u6b63\u786e\u7684\u7b54\u6848\u662f [5,4,6,2,null,null,7], \u5982\u4e0b\u56fe\u6240\u793a\u3002\n\n    5\n   / \\\n  4   6\n /     \\\n2       7\n\n\u53e6\u4e00\u4e2a\u6b63\u786e\u7b54\u6848\u662f [5,2,6,null,4,null,7]\u3002\n\n    5\n   / \\\n  2   6\n   \\   \\\n    4   7\n
    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* deleteNode(TreeNode* root, int key) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode deleteNode(TreeNode root, int key) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def deleteNode(self, root, key):\n \"\"\"\n :type root: TreeNode\n :type key: int\n :rtype: TreeNode\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def deleteNode(self, root: TreeNode, key: int) -> TreeNode:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* deleteNode(struct TreeNode* root, int key){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode DeleteNode(TreeNode root, int key) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number} key\n * @return {TreeNode}\n */\nvar deleteNode = function(root, key) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @param {Integer} key\n# @return {TreeNode}\ndef delete_node(root, key)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func deleteNode(_ root: TreeNode?, _ key: Int) -> TreeNode? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc deleteNode(root *TreeNode, key int) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def deleteNode(root: TreeNode, key: Int): TreeNode = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun deleteNode(root: TreeNode?, key: Int): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn delete_node(root: Option>>, key: i32) -> Option>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param Integer $key\n * @return TreeNode\n */\n function deleteNode($root, $key) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction deleteNode(root: TreeNode | null, key: number): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (delete-node root key)\n (-> (or/c tree-node? #f) exact-integer? (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0450](https://leetcode-cn.com/problems/delete-node-in-a-bst)", "[\u5220\u9664\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u7684\u8282\u70b9](/solution/0400-0499/0450.Delete%20Node%20in%20a%20BST/README.md)", "`\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0450](https://leetcode.com/problems/delete-node-in-a-bst)", "[Delete Node in a BST](/solution/0400-0499/0450.Delete%20Node%20in%20a%20BST/README_EN.md)", "`Tree`", "Medium", ""]}, {"question_id": "0449", "frontend_question_id": "0449", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/serialize-and-deserialize-bst", "url_en": "https://leetcode.com/problems/serialize-and-deserialize-bst", "relative_path_cn": "/solution/0400-0499/0449.Serialize%20and%20Deserialize%20BST/README.md", "relative_path_en": "/solution/0400-0499/0449.Serialize%20and%20Deserialize%20BST/README_EN.md", "title_cn": "\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316\u4e8c\u53c9\u641c\u7d22\u6811", "title_en": "Serialize and Deserialize BST", "question_title_slug": "serialize-and-deserialize-bst", "content_en": "

    Serialization is converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be reconstructed later in the same or another computer environment.

    \n\n

    Design an algorithm to serialize and deserialize a binary search tree. There is no restriction on how your serialization/deserialization algorithm should work. You need to ensure that a binary search tree can be serialized to a string, and this string can be deserialized to the original tree structure.

    \n\n

    The encoded string should be as compact as possible.

    \n\n

     

    \n

    Example 1:

    \n
    Input: root = [2,1,3]\nOutput: [2,1,3]\n

    Example 2:

    \n
    Input: root = []\nOutput: []\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [0, 104].
    • \n\t
    • 0 <= Node.val <= 104
    • \n\t
    • The input tree is guaranteed to be a binary search tree.
    • \n
    \n", "content_cn": "

    \u5e8f\u5217\u5316\u662f\u5c06\u6570\u636e\u7ed3\u6784\u6216\u5bf9\u8c61\u8f6c\u6362\u4e3a\u4e00\u7cfb\u5217\u4f4d\u7684\u8fc7\u7a0b\uff0c\u4ee5\u4fbf\u5b83\u53ef\u4ee5\u5b58\u50a8\u5728\u6587\u4ef6\u6216\u5185\u5b58\u7f13\u51b2\u533a\u4e2d\uff0c\u6216\u901a\u8fc7\u7f51\u7edc\u8fde\u63a5\u94fe\u8def\u4f20\u8f93\uff0c\u4ee5\u4fbf\u7a0d\u540e\u5728\u540c\u4e00\u4e2a\u6216\u53e6\u4e00\u4e2a\u8ba1\u7b97\u673a\u73af\u5883\u4e2d\u91cd\u5efa\u3002

    \n\n

    \u8bbe\u8ba1\u4e00\u4e2a\u7b97\u6cd5\u6765\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316 \u4e8c\u53c9\u641c\u7d22\u6811 \u3002 \u5bf9\u5e8f\u5217\u5316/\u53cd\u5e8f\u5217\u5316\u7b97\u6cd5\u7684\u5de5\u4f5c\u65b9\u5f0f\u6ca1\u6709\u9650\u5236\u3002 \u60a8\u53ea\u9700\u786e\u4fdd\u4e8c\u53c9\u641c\u7d22\u6811\u53ef\u4ee5\u5e8f\u5217\u5316\u4e3a\u5b57\u7b26\u4e32\uff0c\u5e76\u4e14\u53ef\u4ee5\u5c06\u8be5\u5b57\u7b26\u4e32\u53cd\u5e8f\u5217\u5316\u4e3a\u6700\u521d\u7684\u4e8c\u53c9\u641c\u7d22\u6811\u3002

    \n\n

    \u7f16\u7801\u7684\u5b57\u7b26\u4e32\u5e94\u5c3d\u53ef\u80fd\u7d27\u51d1\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [2,1,3]\n\u8f93\u51fa\uff1a[2,1,3]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = []\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u6570\u8303\u56f4\u662f [0, 104]
    • \n\t
    • 0 <= Node.val <= 104
    • \n\t
    • \u9898\u76ee\u6570\u636e \u4fdd\u8bc1 \u8f93\u5165\u7684\u6811\u662f\u4e00\u68f5\u4e8c\u53c9\u641c\u7d22\u6811\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u6ce8\u610f\uff1a\u4e0d\u8981\u4f7f\u7528\u7c7b\u6210\u5458/\u5168\u5c40/\u9759\u6001\u53d8\u91cf\u6765\u5b58\u50a8\u72b6\u6001\u3002 \u4f60\u7684\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316\u7b97\u6cd5\u5e94\u8be5\u662f\u65e0\u72b6\u6001\u7684\u3002

    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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 */\nclass Codec {\npublic:\n\n // Encodes a tree to a single string.\n string serialize(TreeNode* root) {\n \n }\n\n // Decodes your encoded data to tree.\n TreeNode* deserialize(string data) {\n \n }\n};\n\n// Your Codec object will be instantiated and called as such:\n// Codec* ser = new Codec();\n// Codec* deser = new Codec();\n// string tree = ser->serialize(root);\n// TreeNode* ans = deser->deserialize(tree);\n// return ans;", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode(int x) { val = x; }\n * }\n */\npublic class Codec {\n\n // Encodes a tree to a single string.\n public String serialize(TreeNode root) {\n \n }\n\n // Decodes your encoded data to tree.\n public TreeNode deserialize(String data) {\n \n }\n}\n\n// Your Codec object will be instantiated and called as such:\n// Codec ser = new Codec();\n// Codec deser = new Codec();\n// String tree = ser.serialize(root);\n// TreeNode ans = deser.deserialize(tree);\n// return ans;", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Codec:\n\n def serialize(self, root):\n \"\"\"Encodes a tree to a single string.\n \n :type root: TreeNode\n :rtype: str\n \"\"\"\n \n\n def deserialize(self, data):\n \"\"\"Decodes your encoded data to tree.\n \n :type data: str\n :rtype: TreeNode\n \"\"\"\n \n\n# Your Codec object will be instantiated and called as such:\n# ser = Codec()\n# deser = Codec()\n# tree = ser.serialize(root)\n# ans = deser.deserialize(tree)\n# return ans", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Codec:\n\n def serialize(self, root: TreeNode) -> str:\n \"\"\"Encodes a tree to a single string.\n \"\"\"\n \n\n def deserialize(self, data: str) -> TreeNode:\n \"\"\"Decodes your encoded data to tree.\n \"\"\"\n \n\n# Your Codec object will be instantiated and called as such:\n# Your Codec object will be instantiated and called as such:\n# ser = Codec()\n# deser = Codec()\n# tree = ser.serialize(root)\n# ans = deser.deserialize(tree)\n# return ans", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n/** Encodes a tree to a single string. */\nchar* serialize(struct TreeNode* root) {\n \n}\n\n/** Decodes your encoded data to tree. */\nstruct TreeNode* deserialize(char* data) {\n \n}\n\n// Your functions will be called as such:\n// char* data = serialize(root);\n// deserialize(data);", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int x) { val = x; }\n * }\n */\npublic class Codec {\n\n // Encodes a tree to a single string.\n public string serialize(TreeNode root) {\n \n }\n\n // Decodes your encoded data to tree.\n public TreeNode deserialize(string data) {\n \n }\n}\n\n// Your Codec object will be instantiated and called as such:\n// Codec ser = new Codec();\n// Codec deser = new Codec();\n// String tree = ser.serialize(root);\n// TreeNode ans = deser.deserialize(tree);\n// return ans;", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val) {\n * this.val = val;\n * this.left = this.right = null;\n * }\n */\n\n/**\n * Encodes a tree to a single string.\n *\n * @param {TreeNode} root\n * @return {string}\n */\nvar serialize = function(root) {\n \n};\n\n/**\n * Decodes your encoded data to tree.\n *\n * @param {string} data\n * @return {TreeNode}\n */\nvar deserialize = function(data) {\n \n};\n\n/**\n * Your functions will be called as such:\n * deserialize(serialize(root));\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val)\n# @val = val\n# @left, @right = nil, nil\n# end\n# end\n\n# Encodes a tree to a single string.\n#\n# @param {TreeNode} root\n# @return {string}\ndef serialize(root)\n \nend\n\n# Decodes your encoded data to tree.\n#\n# @param {string} data\n# @return {TreeNode}\ndef deserialize(data)\n \nend\n\n\n# Your functions will be called as such:\n# deserialize(serialize(data))", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.left = nil\n * self.right = nil\n * }\n * }\n */\n\nclass Codec {\n // Encodes a tree to a single string.\n func serialize(_ root: TreeNode?) -> String {\n \n }\n \n // Decodes your encoded data to tree.\n func deserialize(_ data: String) -> TreeNode? {\n \n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * let ser = Codec()\n * let deser = Codec()\n * let tree: String = ser.serialize(root)\n * let ans = deser.deserialize(tree)\n * return ans\n*/", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\n\ntype Codec struct {\n \n}\n\nfunc Constructor() Codec {\n \n}\n\n// Serializes a tree to a single string.\nfunc (this *Codec) serialize(root *TreeNode) string {\n \n}\n\n// Deserializes your encoded data to tree.\nfunc (this *Codec) deserialize(data string) *TreeNode { \n \n}\n\n\n/**\n * Your Codec object will be instantiated and called as such:\n * ser := Constructor()\n * deser := Constructor()\n * tree := ser.serialize(root)\n * ans := deser.deserialize(tree)\n * return ans\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(var _value: Int) {\n * var value: Int = _value\n * var left: TreeNode = null\n * var right: TreeNode = null\n * }\n */\n\nclass Codec {\n // Encodes a list of strings to a single string.\n def serialize(root: TreeNode): String = {\n \n }\n \n // Decodes a single string to a list of strings.\n def deserialize(data: String): TreeNode = {\n \n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * val ser = new Codec()\n * val deser = new Codec()\n * val tree: String = ser.serialize(root)\n * val ans = deser.deserialize(tree)\n * return ans\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\n\nclass Codec() {\n\t// Encodes a URL to a shortened URL.\n fun serialize(root: TreeNode?): String {\n \n }\n\n // Decodes your encoded data to tree.\n fun deserialize(data: String): TreeNode? {\n \n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * val ser = Codec()\n * val deser = Codec()\n * val tree: String = ser.serialize(root)\n * val ans = deser.deserialize(tree)\n * return ans\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n// \n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nstruct Codec {\n\t\n}\n\n/** \n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl Codec {\n fn new() -> Self {\n \n }\n\n fn serialize(&self, root: Option>>) -> String {\n \n }\n\t\n fn deserialize(&self, data: String) -> Option>> {\n \n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * let obj = Codec::new();\n * let data: String = obj.serialize(strs);\n * let ans: Option>> = obj.deserialize(data);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($value) { $this->val = $value; }\n * }\n */\n\nclass Codec {\n function __construct() {\n \n }\n \n /**\n * @param TreeNode $root\n * @return String\n */\n function serialize($root) {\n \n }\n \n /**\n * @param String $data\n * @return TreeNode\n */\n function deserialize($data) {\n \n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * $ser = new Codec();\n * $tree = $ser->serialize($param_1);\n * $deser = new Codec();\n * $ret = $deser->deserialize($tree);\n * return $ret;\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\n/*\n * Encodes a tree to a single string.\n */\nfunction serialize(root: TreeNode | null): string {\n\n};\n\n/*\n * Decodes your encoded data to tree.\n */\nfunction deserialize(data: string): TreeNode | null {\n\n};\n\n\n/**\n * Your functions will be called as such:\n * deserialize(serialize(root));\n */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0449](https://leetcode-cn.com/problems/serialize-and-deserialize-bst)", "[\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316\u4e8c\u53c9\u641c\u7d22\u6811](/solution/0400-0499/0449.Serialize%20and%20Deserialize%20BST/README.md)", "`\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0449](https://leetcode.com/problems/serialize-and-deserialize-bst)", "[Serialize and Deserialize BST](/solution/0400-0499/0449.Serialize%20and%20Deserialize%20BST/README_EN.md)", "`Tree`", "Medium", ""]}, {"question_id": "0448", "frontend_question_id": "0448", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-all-numbers-disappeared-in-an-array", "url_en": "https://leetcode.com/problems/find-all-numbers-disappeared-in-an-array", "relative_path_cn": "/solution/0400-0499/0448.Find%20All%20Numbers%20Disappeared%20in%20an%20Array/README.md", "relative_path_en": "/solution/0400-0499/0448.Find%20All%20Numbers%20Disappeared%20in%20an%20Array/README_EN.md", "title_cn": "\u627e\u5230\u6240\u6709\u6570\u7ec4\u4e2d\u6d88\u5931\u7684\u6570\u5b57", "title_en": "Find All Numbers Disappeared in an Array", "question_title_slug": "find-all-numbers-disappeared-in-an-array", "content_en": "

    Given an array nums of n integers where nums[i] is in the range [1, n], return an array of all the integers in the range [1, n] that do not appear in nums.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [4,3,2,7,8,2,3,1]\nOutput: [5,6]\n

    Example 2:

    \n
    Input: nums = [1,1]\nOutput: [2]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= n <= 105
    • \n\t
    • 1 <= nums[i] <= n
    • \n
    \n\n

     

    \n

    Follow up: Could you do it without extra space and in O(n) runtime? You may assume the returned list does not count as extra space.

    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u542b n \u4e2a\u6574\u6570\u7684\u6570\u7ec4 nums \uff0c\u5176\u4e2d nums[i] \u5728\u533a\u95f4 [1, n] \u5185\u3002\u8bf7\u4f60\u627e\u51fa\u6240\u6709\u5728 [1, n] \u8303\u56f4\u5185\u4f46\u6ca1\u6709\u51fa\u73b0\u5728 nums \u4e2d\u7684\u6570\u5b57\uff0c\u5e76\u4ee5\u6570\u7ec4\u7684\u5f62\u5f0f\u8fd4\u56de\u7ed3\u679c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [4,3,2,7,8,2,3,1]\n\u8f93\u51fa\uff1a[5,6]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,1]\n\u8f93\u51fa\uff1a[2]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= n <= 105
    • \n\t
    • 1 <= nums[i] <= n
    • \n
    \n\n

    \u8fdb\u9636\uff1a\u4f60\u80fd\u5728\u4e0d\u4f7f\u7528\u989d\u5916\u7a7a\u95f4\u4e14\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n) \u7684\u60c5\u51b5\u4e0b\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u5417? \u4f60\u53ef\u4ee5\u5047\u5b9a\u8fd4\u56de\u7684\u6570\u7ec4\u4e0d\u7b97\u5728\u989d\u5916\u7a7a\u95f4\u5185\u3002

    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findDisappearedNumbers(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List findDisappearedNumbers(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findDisappearedNumbers(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findDisappearedNumbers(self, nums: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* findDisappearedNumbers(int* nums, int numsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList FindDisappearedNumbers(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar findDisappearedNumbers = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer[]}\ndef find_disappeared_numbers(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findDisappearedNumbers(_ nums: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findDisappearedNumbers(nums []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findDisappearedNumbers(nums: Array[Int]): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findDisappearedNumbers(nums: IntArray): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_disappeared_numbers(nums: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer[]\n */\n function findDisappearedNumbers($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findDisappearedNumbers(nums: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-disappeared-numbers nums)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0448](https://leetcode-cn.com/problems/find-all-numbers-disappeared-in-an-array)", "[\u627e\u5230\u6240\u6709\u6570\u7ec4\u4e2d\u6d88\u5931\u7684\u6570\u5b57](/solution/0400-0499/0448.Find%20All%20Numbers%20Disappeared%20in%20an%20Array/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0448](https://leetcode.com/problems/find-all-numbers-disappeared-in-an-array)", "[Find All Numbers Disappeared in an Array](/solution/0400-0499/0448.Find%20All%20Numbers%20Disappeared%20in%20an%20Array/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0447", "frontend_question_id": "0447", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-boomerangs", "url_en": "https://leetcode.com/problems/number-of-boomerangs", "relative_path_cn": "/solution/0400-0499/0447.Number%20of%20Boomerangs/README.md", "relative_path_en": "/solution/0400-0499/0447.Number%20of%20Boomerangs/README_EN.md", "title_cn": "\u56de\u65cb\u9556\u7684\u6570\u91cf", "title_en": "Number of Boomerangs", "question_title_slug": "number-of-boomerangs", "content_en": "

    You are given n points in the plane that are all distinct, where points[i] = [xi, yi]. A boomerang is a tuple of points (i, j, k) such that the distance between i and j equals the distance between i and k (the order of the tuple matters).

    \n\n

    Return the number of boomerangs.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: points = [[0,0],[1,0],[2,0]]\nOutput: 2\nExplanation: The two boomerangs are [[1,0],[0,0],[2,0]] and [[1,0],[2,0],[0,0]].\n
    \n\n

    Example 2:

    \n\n
    \nInput: points = [[1,1],[2,2],[3,3]]\nOutput: 2\n
    \n\n

    Example 3:

    \n\n
    \nInput: points = [[1,1]]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == points.length
    • \n\t
    • 1 <= n <= 500
    • \n\t
    • points[i].length == 2
    • \n\t
    • -104 <= xi, yi <= 104
    • \n\t
    • All the points are unique.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u5e73\u9762\u4e0a\u00a0n \u5bf9 \u4e92\u4e0d\u76f8\u540c \u7684\u70b9\u00a0points \uff0c\u5176\u4e2d points[i] = [xi, yi] \u3002\u56de\u65cb\u9556 \u662f\u7531\u70b9\u00a0(i, j, k) \u8868\u793a\u7684\u5143\u7ec4 \uff0c\u5176\u4e2d\u00a0i\u00a0\u548c\u00a0j\u00a0\u4e4b\u95f4\u7684\u8ddd\u79bb\u548c\u00a0i\u00a0\u548c\u00a0k\u00a0\u4e4b\u95f4\u7684\u8ddd\u79bb\u76f8\u7b49\uff08\u9700\u8981\u8003\u8651\u5143\u7ec4\u7684\u987a\u5e8f\uff09\u3002

    \n\n

    \u8fd4\u56de\u5e73\u9762\u4e0a\u6240\u6709\u56de\u65cb\u9556\u7684\u6570\u91cf\u3002

    \n\u00a0\n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1apoints = [[0,0],[1,0],[2,0]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u4e24\u4e2a\u56de\u65cb\u9556\u4e3a [[1,0],[0,0],[2,0]] \u548c [[1,0],[2,0],[0,0]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1apoints = [[1,1],[2,2],[3,3]]\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1apoints = [[1,1]]\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n ==\u00a0points.length
    • \n\t
    • 1 <= n <= 500
    • \n\t
    • points[i].length == 2
    • \n\t
    • -104 <= xi, yi <= 104
    • \n\t
    • \u6240\u6709\u70b9\u90fd \u4e92\u4e0d\u76f8\u540c
    • \n
    \n", "tags_en": ["Hash Table", "Math"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numberOfBoomerangs(vector>& points) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numberOfBoomerangs(int[][] points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numberOfBoomerangs(self, points):\n \"\"\"\n :type points: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numberOfBoomerangs(self, points: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numberOfBoomerangs(int** points, int pointsSize, int* pointsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumberOfBoomerangs(int[][] points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} points\n * @return {number}\n */\nvar numberOfBoomerangs = function(points) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} points\n# @return {Integer}\ndef number_of_boomerangs(points)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numberOfBoomerangs(_ points: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numberOfBoomerangs(points [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numberOfBoomerangs(points: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numberOfBoomerangs(points: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn number_of_boomerangs(points: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $points\n * @return Integer\n */\n function numberOfBoomerangs($points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numberOfBoomerangs(points: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (number-of-boomerangs points)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0447](https://leetcode-cn.com/problems/number-of-boomerangs)", "[\u56de\u65cb\u9556\u7684\u6570\u91cf](/solution/0400-0499/0447.Number%20of%20Boomerangs/README.md)", "`\u54c8\u5e0c\u8868`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0447](https://leetcode.com/problems/number-of-boomerangs)", "[Number of Boomerangs](/solution/0400-0499/0447.Number%20of%20Boomerangs/README_EN.md)", "`Hash Table`,`Math`", "Medium", ""]}, {"question_id": "0446", "frontend_question_id": "0446", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/arithmetic-slices-ii-subsequence", "url_en": "https://leetcode.com/problems/arithmetic-slices-ii-subsequence", "relative_path_cn": "/solution/0400-0499/0446.Arithmetic%20Slices%20II%20-%20Subsequence/README.md", "relative_path_en": "/solution/0400-0499/0446.Arithmetic%20Slices%20II%20-%20Subsequence/README_EN.md", "title_cn": "\u7b49\u5dee\u6570\u5217\u5212\u5206 II - \u5b50\u5e8f\u5217", "title_en": "Arithmetic Slices II - Subsequence", "question_title_slug": "arithmetic-slices-ii-subsequence", "content_en": "

    Given an integer array nums, return the number of all the arithmetic subsequences of nums.

    \n\n

    A sequence of numbers is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.

    \n\n
      \n\t
    • For example, [1, 3, 5, 7, 9], [7, 7, 7, 7], and [3, -1, -5, -9] are arithmetic sequences.
    • \n\t
    • For example, [1, 1, 2, 5, 7] is not an arithmetic sequence.
    • \n
    \n\n

    A subsequence of an array is a sequence that can be formed by removing some elements (possibly none) of the array.

    \n\n
      \n\t
    • For example, [2,5,10] is a subsequence of [1,2,1,2,4,1,5,10].
    • \n
    \n\n

    The answer is guaranteed to fit in 32-bit integer.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [2,4,6,8,10]\nOutput: 7\nExplanation: All arithmetic subsequence slices are:\n[2,4,6]\n[4,6,8]\n[6,8,10]\n[2,4,6,8]\n[4,6,8,10]\n[2,4,6,8,10]\n[2,6,10]\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [7,7,7,7,7]\nOutput: 16\nExplanation: Any subsequence of this array is arithmetic.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1  <= nums.length <= 1000
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n
    \n", "content_cn": "

    \u5982\u679c\u4e00\u4e2a\u6570\u5217\u81f3\u5c11\u6709\u4e09\u4e2a\u5143\u7d20\uff0c\u5e76\u4e14\u4efb\u610f\u4e24\u4e2a\u76f8\u90bb\u5143\u7d20\u4e4b\u5dee\u76f8\u540c\uff0c\u5219\u79f0\u8be5\u6570\u5217\u4e3a\u7b49\u5dee\u6570\u5217\u3002

    \n\n

    \u4f8b\u5982\uff0c\u4ee5\u4e0b\u6570\u5217\u4e3a\u7b49\u5dee\u6570\u5217:

    \n\n
    \n1, 3, 5, 7, 9\n7, 7, 7, 7\n3, -1, -5, -9
    \n\n

    \u4ee5\u4e0b\u6570\u5217\u4e0d\u662f\u7b49\u5dee\u6570\u5217\u3002

    \n\n
    \n1, 1, 2, 5, 7
    \n\n

    \u00a0

    \n\n

    \u6570\u7ec4 A \u5305\u542b N \u4e2a\u6570\uff0c\u4e14\u7d22\u5f15\u4ece 0 \u5f00\u59cb\u3002\u8be5\u6570\u7ec4\u5b50\u5e8f\u5217\u5c06\u5212\u5206\u4e3a\u6574\u6570\u5e8f\u5217\u00a0(P0, P1, ..., Pk)\uff0c\u6ee1\u8db3 0 \u2264 P0 < P1 < ... < Pk < N\u3002

    \n\n

    \u00a0

    \n\n

    \u5982\u679c\u5e8f\u5217 A[P0]\uff0cA[P1]\uff0c...\uff0cA[Pk-1]\uff0cA[Pk] \u662f\u7b49\u5dee\u7684\uff0c\u90a3\u4e48\u6570\u7ec4 A \u7684\u5b50\u5e8f\u5217 (P0\uff0cP1\uff0c\u2026\uff0cPK) \u79f0\u4e3a\u7b49\u5dee\u5e8f\u5217\u3002\u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0c\u8fd9\u610f\u5473\u7740 k \u2265 2\u3002

    \n\n

    \u51fd\u6570\u8981\u8fd4\u56de\u6570\u7ec4 A \u4e2d\u6240\u6709\u7b49\u5dee\u5b50\u5e8f\u5217\u7684\u4e2a\u6570\u3002

    \n\n

    \u8f93\u5165\u5305\u542b N \u4e2a\u6574\u6570\u3002\u6bcf\u4e2a\u6574\u6570\u90fd\u5728 -231 \u548c 231-1 \u4e4b\u95f4\uff0c\u53e6\u5916 0 \u2264 N \u2264 1000\u3002\u4fdd\u8bc1\u8f93\u51fa\u5c0f\u4e8e 231-1\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[2, 4, 6, 8, 10]\n\n\u8f93\u51fa\uff1a7\n\n\u89e3\u91ca\uff1a\n\u6240\u6709\u7684\u7b49\u5dee\u5b50\u5e8f\u5217\u4e3a\uff1a\n[2,4,6]\n[4,6,8]\n[6,8,10]\n[2,4,6,8]\n[4,6,8,10]\n[2,4,6,8,10]\n[2,6,10]\n
    \n\n

    \u00a0

    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numberOfArithmeticSlices(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numberOfArithmeticSlices(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numberOfArithmeticSlices(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numberOfArithmeticSlices(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numberOfArithmeticSlices(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumberOfArithmeticSlices(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar numberOfArithmeticSlices = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef number_of_arithmetic_slices(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numberOfArithmeticSlices(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numberOfArithmeticSlices(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numberOfArithmeticSlices(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numberOfArithmeticSlices(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn number_of_arithmetic_slices(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function numberOfArithmeticSlices($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numberOfArithmeticSlices(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (number-of-arithmetic-slices nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0446](https://leetcode-cn.com/problems/arithmetic-slices-ii-subsequence)", "[\u7b49\u5dee\u6570\u5217\u5212\u5206 II - \u5b50\u5e8f\u5217](/solution/0400-0499/0446.Arithmetic%20Slices%20II%20-%20Subsequence/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0446](https://leetcode.com/problems/arithmetic-slices-ii-subsequence)", "[Arithmetic Slices II - Subsequence](/solution/0400-0499/0446.Arithmetic%20Slices%20II%20-%20Subsequence/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "0445", "frontend_question_id": "0445", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/add-two-numbers-ii", "url_en": "https://leetcode.com/problems/add-two-numbers-ii", "relative_path_cn": "/solution/0400-0499/0445.Add%20Two%20Numbers%20II/README.md", "relative_path_en": "/solution/0400-0499/0445.Add%20Two%20Numbers%20II/README_EN.md", "title_cn": "\u4e24\u6570\u76f8\u52a0 II", "title_en": "Add Two Numbers II", "question_title_slug": "add-two-numbers-ii", "content_en": "

    You are given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list.

    \n\n

    You may assume the two numbers do not contain any leading zero, except the number 0 itself.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: l1 = [7,2,4,3], l2 = [5,6,4]\nOutput: [7,8,0,7]\n
    \n\n

    Example 2:

    \n\n
    \nInput: l1 = [2,4,3], l2 = [5,6,4]\nOutput: [8,0,7]\n
    \n\n

    Example 3:

    \n\n
    \nInput: l1 = [0], l2 = [0]\nOutput: [0]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in each linked list is in the range [1, 100].
    • \n\t
    • 0 <= Node.val <= 9
    • \n\t
    • It is guaranteed that the list represents a number that does not have leading zeros.
    • \n
    \n\n

     

    \n

    Follow up: Could you solve it without reversing the input lists?

    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a \u975e\u7a7a \u94fe\u8868\u6765\u4ee3\u8868\u4e24\u4e2a\u975e\u8d1f\u6574\u6570\u3002\u6570\u5b57\u6700\u9ad8\u4f4d\u4f4d\u4e8e\u94fe\u8868\u5f00\u59cb\u4f4d\u7f6e\u3002\u5b83\u4eec\u7684\u6bcf\u4e2a\u8282\u70b9\u53ea\u5b58\u50a8\u4e00\u4f4d\u6570\u5b57\u3002\u5c06\u8fd9\u4e24\u6570\u76f8\u52a0\u4f1a\u8fd4\u56de\u4e00\u4e2a\u65b0\u7684\u94fe\u8868\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u5047\u8bbe\u9664\u4e86\u6570\u5b57 0 \u4e4b\u5916\uff0c\u8fd9\u4e24\u4e2a\u6570\u5b57\u90fd\u4e0d\u4f1a\u4ee5\u96f6\u5f00\u5934\u3002

    \n\n

     

    \n\n

    \u8fdb\u9636\uff1a

    \n\n

    \u5982\u679c\u8f93\u5165\u94fe\u8868\u4e0d\u80fd\u4fee\u6539\u8be5\u5982\u4f55\u5904\u7406\uff1f\u6362\u53e5\u8bdd\u8bf4\uff0c\u4f60\u4e0d\u80fd\u5bf9\u5217\u8868\u4e2d\u7684\u8282\u70b9\u8fdb\u884c\u7ffb\u8f6c\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1a(7 -> 2 -> 4 -> 3) + (5 -> 6 -> 4)\n\u8f93\u51fa\uff1a7 -> 8 -> 0 -> 7\n
    \n", "tags_en": ["Linked List"], "tags_cn": ["\u94fe\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public ListNode addTwoNumbers(ListNode l1, ListNode l2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def addTwoNumbers(self, l1, l2):\n \"\"\"\n :type l1: ListNode\n :type l2: ListNode\n :rtype: ListNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nstruct ListNode* addTwoNumbers(struct ListNode* l1, struct ListNode* l2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public ListNode AddTwoNumbers(ListNode l1, ListNode l2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} l1\n * @param {ListNode} l2\n * @return {ListNode}\n */\nvar addTwoNumbers = function(l1, l2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode} l1\n# @param {ListNode} l2\n# @return {ListNode}\ndef add_two_numbers(l1, l2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func addTwoNumbers(_ l1: ListNode?, _ l2: ListNode?) -> ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc addTwoNumbers(l1 *ListNode, l2 *ListNode) *ListNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def addTwoNumbers(l1: ListNode, l2: ListNode): ListNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun addTwoNumbers(l1: ListNode?, l2: ListNode?): ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn add_two_numbers(l1: Option>, l2: Option>) -> Option> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $l1\n * @param ListNode $l2\n * @return ListNode\n */\n function addTwoNumbers($l1, $l2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction addTwoNumbers(l1: ListNode | null, l2: ListNode | null): ListNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (add-two-numbers l1 l2)\n (-> (or/c list-node? #f) (or/c list-node? #f) (or/c list-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0445](https://leetcode-cn.com/problems/add-two-numbers-ii)", "[\u4e24\u6570\u76f8\u52a0 II](/solution/0400-0499/0445.Add%20Two%20Numbers%20II/README.md)", "`\u94fe\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0445](https://leetcode.com/problems/add-two-numbers-ii)", "[Add Two Numbers II](/solution/0400-0499/0445.Add%20Two%20Numbers%20II/README_EN.md)", "`Linked List`", "Medium", ""]}, {"question_id": "0444", "frontend_question_id": "0444", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/sequence-reconstruction", "url_en": "https://leetcode.com/problems/sequence-reconstruction", "relative_path_cn": "/solution/0400-0499/0444.Sequence%20Reconstruction/README.md", "relative_path_en": "/solution/0400-0499/0444.Sequence%20Reconstruction/README_EN.md", "title_cn": "\u5e8f\u5217\u91cd\u5efa", "title_en": "Sequence Reconstruction", "question_title_slug": "sequence-reconstruction", "content_en": "

    Check whether the original sequence org can be uniquely reconstructed from the sequences in seqs. The org sequence is a permutation of the integers from 1 to n, with 1 ≤ n ≤ 104. Reconstruction means building a shortest common supersequence of the sequences in seqs (i.e., a shortest sequence so that all sequences in seqs are subsequences of it). Determine whether there is only one sequence that can be reconstructed from seqs and it is the org sequence.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: org = [1,2,3], seqs = [[1,2],[1,3]]\nOutput: false\nExplanation: [1,2,3] is not the only one sequence that can be reconstructed, because [1,3,2] is also a valid sequence that can be reconstructed.\n
    \n\n

    Example 2:

    \n\n
    \nInput: org = [1,2,3], seqs = [[1,2]]\nOutput: false\nExplanation: The reconstructed sequence can only be [1,2].\n
    \n\n

    Example 3:

    \n\n
    \nInput: org = [1,2,3], seqs = [[1,2],[1,3],[2,3]]\nOutput: true\nExplanation: The sequences [1,2], [1,3], and [2,3] can uniquely reconstruct the original sequence [1,2,3].\n
    \n\n

    Example 4:

    \n\n
    \nInput: org = [4,1,5,2,6,3], seqs = [[5,2,6,3],[4,1,5,2]]\nOutput: true\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 10^4
    • \n\t
    • org is a permutation of {1,2,...,n}.
    • \n\t
    • 1 <= segs[i].length <= 10^5
    • \n\t
    • seqs[i][j] fits in a 32-bit signed integer.
    • \n
    \n\n

     

    \n\n

    UPDATE (2017/1/8):
    \nThe seqs parameter had been changed to a list of list of strings (instead of a 2d array of strings). Please reload the code definition to get the latest changes.

    \n", "content_cn": "

    \u9a8c\u8bc1\u539f\u59cb\u7684\u5e8f\u5217 org \u662f\u5426\u53ef\u4ee5\u4ece\u5e8f\u5217\u96c6 seqs \u4e2d\u552f\u4e00\u5730\u91cd\u5efa\u3002\u5e8f\u5217 org \u662f 1 \u5230 n \u6574\u6570\u7684\u6392\u5217\uff0c\u5176\u4e2d 1 ≤ n ≤ 104\u3002\u91cd\u5efa\u662f\u6307\u5728\u5e8f\u5217\u96c6 seqs \u4e2d\u6784\u5efa\u6700\u77ed\u7684\u516c\u5171\u8d85\u5e8f\u5217\u3002\uff08\u5373\u4f7f\u5f97\u6240\u6709  seqs \u4e2d\u7684\u5e8f\u5217\u90fd\u662f\u8be5\u6700\u77ed\u5e8f\u5217\u7684\u5b50\u5e8f\u5217\uff09\u3002\u786e\u5b9a\u662f\u5426\u53ea\u53ef\u4ee5\u4ece seqs \u91cd\u5efa\u552f\u4e00\u7684\u5e8f\u5217\uff0c\u4e14\u8be5\u5e8f\u5217\u5c31\u662f org \u3002

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a\norg: [1,2,3], seqs: [[1,2],[1,3]]\n\n\u8f93\u51fa\uff1a\nfalse\n\n\u89e3\u91ca\uff1a\n[1,2,3] \u4e0d\u662f\u53ef\u4ee5\u88ab\u91cd\u5efa\u7684\u552f\u4e00\u7684\u5e8f\u5217\uff0c\u56e0\u4e3a [1,3,2] \u4e5f\u662f\u4e00\u4e2a\u5408\u6cd5\u7684\u5e8f\u5217\u3002\n
    \n\n

     

    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a\norg: [1,2,3], seqs: [[1,2]]\n\n\u8f93\u51fa\uff1a\nfalse\n\n\u89e3\u91ca\uff1a\n\u53ef\u4ee5\u91cd\u5efa\u7684\u5e8f\u5217\u53ea\u6709 [1,2]\u3002\n
    \n\n

     

    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1a\norg: [1,2,3], seqs: [[1,2],[1,3],[2,3]]\n\n\u8f93\u51fa\uff1a\ntrue\n\n\u89e3\u91ca\uff1a\n\u5e8f\u5217 [1,2], [1,3] \u548c [2,3] \u53ef\u4ee5\u88ab\u552f\u4e00\u5730\u91cd\u5efa\u4e3a\u539f\u59cb\u7684\u5e8f\u5217 [1,2,3]\u3002\n
    \n\n

     

    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1a\norg: [4,1,5,2,6,3], seqs: [[5,2,6,3],[4,1,5,2]]\n\n\u8f93\u51fa\uff1a\ntrue\n
    \n", "tags_en": ["Graph", "Topological Sort"], "tags_cn": ["\u56fe", "\u62d3\u6251\u6392\u5e8f"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool sequenceReconstruction(vector& org, vector>& seqs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean sequenceReconstruction(int[] org, List> seqs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def sequenceReconstruction(self, org, seqs):\n \"\"\"\n :type org: List[int]\n :type seqs: List[List[int]]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def sequenceReconstruction(self, org: List[int], seqs: List[List[int]]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool sequenceReconstruction(int* org, int orgSize, int** seqs, int seqsSize, int* seqsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool SequenceReconstruction(int[] org, IList> seqs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} org\n * @param {number[][]} seqs\n * @return {boolean}\n */\nvar sequenceReconstruction = function(org, seqs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} org\n# @param {Integer[][]} seqs\n# @return {Boolean}\ndef sequence_reconstruction(org, seqs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func sequenceReconstruction(_ org: [Int], _ seqs: [[Int]]) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func sequenceReconstruction(org []int, seqs [][]int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def sequenceReconstruction(org: Array[Int], seqs: List[List[Int]]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun sequenceReconstruction(org: IntArray, seqs: List>): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sequence_reconstruction(org: Vec, seqs: Vec>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $org\n * @param Integer[][] $seqs\n * @return Boolean\n */\n function sequenceReconstruction($org, $seqs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function sequenceReconstruction(org: number[], seqs: number[][]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (sequence-reconstruction org seqs)\n (-> (listof exact-integer?) (listof (listof exact-integer?)) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0444](https://leetcode-cn.com/problems/sequence-reconstruction)", "[\u5e8f\u5217\u91cd\u5efa](/solution/0400-0499/0444.Sequence%20Reconstruction/README.md)", "`\u56fe`,`\u62d3\u6251\u6392\u5e8f`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0444](https://leetcode.com/problems/sequence-reconstruction)", "[Sequence Reconstruction](/solution/0400-0499/0444.Sequence%20Reconstruction/README_EN.md)", "`Graph`,`Topological Sort`", "Medium", "\ud83d\udd12"]}, {"question_id": "0443", "frontend_question_id": "0443", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/string-compression", "url_en": "https://leetcode.com/problems/string-compression", "relative_path_cn": "/solution/0400-0499/0443.String%20Compression/README.md", "relative_path_en": "/solution/0400-0499/0443.String%20Compression/README_EN.md", "title_cn": "\u538b\u7f29\u5b57\u7b26\u4e32", "title_en": "String Compression", "question_title_slug": "string-compression", "content_en": "

    Given an array of characters chars, compress it using the following algorithm:

    \n\n

    Begin with an empty string s. For each group of consecutive repeating characters in chars:

    \n\n
      \n\t
    • If the group's length is 1, append the character to s.
    • \n\t
    • Otherwise, append the character followed by the group's length.
    • \n
    \n\n

    The compressed string s should not be returned separately, but instead be stored in the input character array chars. Note that group lengths that are 10 or longer will be split into multiple characters in chars.

    \n\n

    After you are done modifying the input array, return the new length of the array.

    \nYou must write an algorithm that uses only constant extra space.\n

     

    \n

    Example 1:

    \n\n
    \nInput: chars = ["a","a","b","b","c","c","c"]\nOutput: Return 6, and the first 6 characters of the input array should be: ["a","2","b","2","c","3"]\nExplanation: The groups are "aa", "bb", and "ccc". This compresses to "a2b2c3".\n
    \n\n

    Example 2:

    \n\n
    \nInput: chars = ["a"]\nOutput: Return 1, and the first character of the input array should be: ["a"]\nExplanation: The only group is "a", which remains uncompressed since it's a single character.\n
    \n\n

    Example 3:

    \n\n
    \nInput: chars = ["a","b","b","b","b","b","b","b","b","b","b","b","b"]\nOutput: Return 4, and the first 4 characters of the input array should be: ["a","b","1","2"].\nExplanation: The groups are "a" and "bbbbbbbbbbbb". This compresses to "ab12".
    \n\n

    Example 4:

    \n\n
    \nInput: chars = ["a","a","a","b","b","a","a"]\nOutput: Return 6, and the first 6 characters of the input array should be: ["a","3","b","2","a","2"].\nExplanation: The groups are "aaa", "bb", and "aa". This compresses to "a3b2a2". Note that each group is independent even if two groups have the same character.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= chars.length <= 2000
    • \n\t
    • chars[i] is a lower-case English letter, upper-case English letter, digit, or symbol.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u7ec4\u5b57\u7b26\uff0c\u4f7f\u7528\u539f\u5730\u7b97\u6cd5\u5c06\u5176\u538b\u7f29\u3002

    \n\n

    \u538b\u7f29\u540e\u7684\u957f\u5ea6\u5fc5\u987b\u59cb\u7ec8\u5c0f\u4e8e\u6216\u7b49\u4e8e\u539f\u6570\u7ec4\u957f\u5ea6\u3002

    \n\n

    \u6570\u7ec4\u7684\u6bcf\u4e2a\u5143\u7d20\u5e94\u8be5\u662f\u957f\u5ea6\u4e3a1 \u7684\u5b57\u7b26\uff08\u4e0d\u662f int \u6574\u6570\u7c7b\u578b\uff09\u3002

    \n\n

    \u5728\u5b8c\u6210\u539f\u5730\u4fee\u6539\u8f93\u5165\u6570\u7ec4\u540e\uff0c\u8fd4\u56de\u6570\u7ec4\u7684\u65b0\u957f\u5ea6\u3002

    \n\n

     

    \n\n

    \u8fdb\u9636\uff1a
    \n\u4f60\u80fd\u5426\u4ec5\u4f7f\u7528O(1) \u7a7a\u95f4\u89e3\u51b3\u95ee\u9898\uff1f

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a\n["a","a","b","b","c","c","c"]\n\n\u8f93\u51fa\uff1a\n\u8fd4\u56de 6 \uff0c\u8f93\u5165\u6570\u7ec4\u7684\u524d 6 \u4e2a\u5b57\u7b26\u5e94\u8be5\u662f\uff1a["a","2","b","2","c","3"]\n\n\u8bf4\u660e\uff1a\n"aa" \u88ab "a2" \u66ff\u4ee3\u3002"bb" \u88ab "b2" \u66ff\u4ee3\u3002"ccc" \u88ab "c3" \u66ff\u4ee3\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a\n["a"]\n\n\u8f93\u51fa\uff1a\n\u8fd4\u56de 1 \uff0c\u8f93\u5165\u6570\u7ec4\u7684\u524d 1 \u4e2a\u5b57\u7b26\u5e94\u8be5\u662f\uff1a["a"]\n\n\u89e3\u91ca\uff1a\n\u6ca1\u6709\u4efb\u4f55\u5b57\u7b26\u4e32\u88ab\u66ff\u4ee3\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1a\n["a","b","b","b","b","b","b","b","b","b","b","b","b"]\n\n\u8f93\u51fa\uff1a\n\u8fd4\u56de 4 \uff0c\u8f93\u5165\u6570\u7ec4\u7684\u524d4\u4e2a\u5b57\u7b26\u5e94\u8be5\u662f\uff1a["a","b","1","2"]\u3002\n\n\u89e3\u91ca\uff1a\n\u7531\u4e8e\u5b57\u7b26 "a" \u4e0d\u91cd\u590d\uff0c\u6240\u4ee5\u4e0d\u4f1a\u88ab\u538b\u7f29\u3002"bbbbbbbbbbbb" \u88ab “b12” \u66ff\u4ee3\u3002\n\u6ce8\u610f\u6bcf\u4e2a\u6570\u5b57\u5728\u6570\u7ec4\u4e2d\u90fd\u6709\u5b83\u81ea\u5df1\u7684\u4f4d\u7f6e\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6240\u6709\u5b57\u7b26\u90fd\u6709\u4e00\u4e2aASCII\u503c\u5728[35, 126]\u533a\u95f4\u5185\u3002
    • \n\t
    • 1 <= len(chars) <= 1000\u3002
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int compress(vector& chars) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int compress(char[] chars) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def compress(self, chars):\n \"\"\"\n :type chars: List[str]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def compress(self, chars: List[str]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint compress(char* chars, int charsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int Compress(char[] chars) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {character[]} chars\n * @return {number}\n */\nvar compress = function(chars) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Character[]} chars\n# @return {Integer}\ndef compress(chars)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func compress(_ chars: inout [Character]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func compress(chars []byte) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def compress(chars: Array[Char]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun compress(chars: CharArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn compress(chars: &mut Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $chars\n * @return Integer\n */\n function compress(&$chars) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function compress(chars: string[]): number {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0443](https://leetcode-cn.com/problems/string-compression)", "[\u538b\u7f29\u5b57\u7b26\u4e32](/solution/0400-0499/0443.String%20Compression/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0443](https://leetcode.com/problems/string-compression)", "[String Compression](/solution/0400-0499/0443.String%20Compression/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "0442", "frontend_question_id": "0442", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-all-duplicates-in-an-array", "url_en": "https://leetcode.com/problems/find-all-duplicates-in-an-array", "relative_path_cn": "/solution/0400-0499/0442.Find%20All%20Duplicates%20in%20an%20Array/README.md", "relative_path_en": "/solution/0400-0499/0442.Find%20All%20Duplicates%20in%20an%20Array/README_EN.md", "title_cn": "\u6570\u7ec4\u4e2d\u91cd\u590d\u7684\u6570\u636e", "title_en": "Find All Duplicates in an Array", "question_title_slug": "find-all-duplicates-in-an-array", "content_en": "

    Given an integer array nums of length n where all the integers of nums are in the range [1, n] and each integer appears once or twice, return an array of all the integers that appears twice.

    \n\n

    You must write an algorithm that runs in O(n) time and uses only constant extra space.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [4,3,2,7,8,2,3,1]\nOutput: [2,3]\n

    Example 2:

    \n
    Input: nums = [1,1,2]\nOutput: [1]\n

    Example 3:

    \n
    Input: nums = [1]\nOutput: []\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= n <= 105
    • \n\t
    • 1 <= nums[i] <= n
    • \n\t
    • Each element in nums appears once or twice.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 a\uff0c\u5176\u4e2d1 ≤ a[i] ≤ n \uff08n\u4e3a\u6570\u7ec4\u957f\u5ea6\uff09, \u5176\u4e2d\u6709\u4e9b\u5143\u7d20\u51fa\u73b0\u4e24\u6b21\u800c\u5176\u4ed6\u5143\u7d20\u51fa\u73b0\u4e00\u6b21\u3002

    \n\n

    \u627e\u5230\u6240\u6709\u51fa\u73b0\u4e24\u6b21\u7684\u5143\u7d20\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u4e0d\u7528\u5230\u4efb\u4f55\u989d\u5916\u7a7a\u95f4\u5e76\u5728O(n)\u65f6\u95f4\u590d\u6742\u5ea6\u5185\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u5417\uff1f

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165:\n[4,3,2,7,8,2,3,1]\n\n\u8f93\u51fa:\n[2,3]\n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findDuplicates(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List findDuplicates(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findDuplicates(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findDuplicates(self, nums: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* findDuplicates(int* nums, int numsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList FindDuplicates(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar findDuplicates = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer[]}\ndef find_duplicates(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findDuplicates(_ nums: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findDuplicates(nums []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findDuplicates(nums: Array[Int]): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findDuplicates(nums: IntArray): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_duplicates(nums: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer[]\n */\n function findDuplicates($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findDuplicates(nums: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-duplicates nums)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0442](https://leetcode-cn.com/problems/find-all-duplicates-in-an-array)", "[\u6570\u7ec4\u4e2d\u91cd\u590d\u7684\u6570\u636e](/solution/0400-0499/0442.Find%20All%20Duplicates%20in%20an%20Array/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0442](https://leetcode.com/problems/find-all-duplicates-in-an-array)", "[Find All Duplicates in an Array](/solution/0400-0499/0442.Find%20All%20Duplicates%20in%20an%20Array/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0441", "frontend_question_id": "0441", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/arranging-coins", "url_en": "https://leetcode.com/problems/arranging-coins", "relative_path_cn": "/solution/0400-0499/0441.Arranging%20Coins/README.md", "relative_path_en": "/solution/0400-0499/0441.Arranging%20Coins/README_EN.md", "title_cn": "\u6392\u5217\u786c\u5e01", "title_en": "Arranging Coins", "question_title_slug": "arranging-coins", "content_en": "

    You have n coins and you want to build a staircase with these coins. The staircase consists of k rows where the ith row has exactly i coins. The last row of the staircase may be incomplete.

    \n\n

    Given the integer n, return the number of complete rows of the staircase you will build.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: n = 5\nOutput: 2\nExplanation: Because the 3rd row is incomplete, we return 2.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: n = 8\nOutput: 3\nExplanation: Because the 4th row is incomplete, we return 3.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 231 - 1
    • \n
    \n", "content_cn": "

    \u4f60\u603b\u5171\u6709 \u679a\u786c\u5e01\uff0c\u4f60\u9700\u8981\u5c06\u5b83\u4eec\u6446\u6210\u4e00\u4e2a\u9636\u68af\u5f62\u72b6\uff0c\u7b2c \u884c\u5c31\u5fc5\u987b\u6b63\u597d\u6709 \u679a\u786c\u5e01\u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u6570\u5b57 n\uff0c\u627e\u51fa\u53ef\u5f62\u6210\u5b8c\u6574\u9636\u68af\u884c\u7684\u603b\u884c\u6570\u3002

    \n\n

    \u662f\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\uff0c\u5e76\u4e14\u572832\u4f4d\u6709\u7b26\u53f7\u6574\u578b\u7684\u8303\u56f4\u5185\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \nn = 5\n\n\u786c\u5e01\u53ef\u6392\u5217\u6210\u4ee5\u4e0b\u51e0\u884c:\n¤\n¤ ¤\n¤ ¤\n\n\u56e0\u4e3a\u7b2c\u4e09\u884c\u4e0d\u5b8c\u6574\uff0c\u6240\u4ee5\u8fd4\u56de2.\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \nn = 8\n\n\u786c\u5e01\u53ef\u6392\u5217\u6210\u4ee5\u4e0b\u51e0\u884c:\n¤\n¤ ¤\n¤ ¤ ¤\n¤ ¤\n\n\u56e0\u4e3a\u7b2c\u56db\u884c\u4e0d\u5b8c\u6574\uff0c\u6240\u4ee5\u8fd4\u56de3.\n
    \n", "tags_en": ["Math", "Binary Search"], "tags_cn": ["\u6570\u5b66", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int arrangeCoins(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int arrangeCoins(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def arrangeCoins(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def arrangeCoins(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint arrangeCoins(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ArrangeCoins(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar arrangeCoins = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef arrange_coins(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func arrangeCoins(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func arrangeCoins(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def arrangeCoins(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun arrangeCoins(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn arrange_coins(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function arrangeCoins($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function arrangeCoins(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (arrange-coins n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0441](https://leetcode-cn.com/problems/arranging-coins)", "[\u6392\u5217\u786c\u5e01](/solution/0400-0499/0441.Arranging%20Coins/README.md)", "`\u6570\u5b66`,`\u4e8c\u5206\u67e5\u627e`", "\u7b80\u5355", ""], "md_table_row_en": ["[0441](https://leetcode.com/problems/arranging-coins)", "[Arranging Coins](/solution/0400-0499/0441.Arranging%20Coins/README_EN.md)", "`Math`,`Binary Search`", "Easy", ""]}, {"question_id": "0440", "frontend_question_id": "0440", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/k-th-smallest-in-lexicographical-order", "url_en": "https://leetcode.com/problems/k-th-smallest-in-lexicographical-order", "relative_path_cn": "/solution/0400-0499/0440.K-th%20Smallest%20in%20Lexicographical%20Order/README.md", "relative_path_en": "/solution/0400-0499/0440.K-th%20Smallest%20in%20Lexicographical%20Order/README_EN.md", "title_cn": "\u5b57\u5178\u5e8f\u7684\u7b2cK\u5c0f\u6570\u5b57", "title_en": "K-th Smallest in Lexicographical Order", "question_title_slug": "k-th-smallest-in-lexicographical-order", "content_en": "

    Given two integers n and k, return the kth lexicographically smallest integer in the range [1, n].

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 13, k = 2\nOutput: 10\nExplanation: The lexicographical order is [1, 10, 11, 12, 13, 2, 3, 4, 5, 6, 7, 8, 9], so the second smallest number is 10.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 1, k = 1\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= k <= n <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u6574\u6570 n \u548c k\uff0c\u627e\u5230 1 \u5230 n \u4e2d\u5b57\u5178\u5e8f\u7b2c k \u5c0f\u7684\u6570\u5b57\u3002

    \n\n

    \u6ce8\u610f\uff1a1 ≤ k ≤ n ≤ 109\u3002

    \n\n

    \u793a\u4f8b :

    \n\n
    \n\u8f93\u5165:\nn: 13   k: 2\n\n\u8f93\u51fa:\n10\n\n\u89e3\u91ca:\n\u5b57\u5178\u5e8f\u7684\u6392\u5217\u662f [1, 10, 11, 12, 13, 2, 3, 4, 5, 6, 7, 8, 9]\uff0c\u6240\u4ee5\u7b2c\u4e8c\u5c0f\u7684\u6570\u5b57\u662f 10\u3002\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findKthNumber(int n, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findKthNumber(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findKthNumber(self, n, k):\n \"\"\"\n :type n: int\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findKthNumber(self, n: int, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findKthNumber(int n, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindKthNumber(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} k\n * @return {number}\n */\nvar findKthNumber = function(n, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} k\n# @return {Integer}\ndef find_kth_number(n, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findKthNumber(_ n: Int, _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findKthNumber(n int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findKthNumber(n: Int, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findKthNumber(n: Int, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_kth_number(n: i32, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $k\n * @return Integer\n */\n function findKthNumber($n, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findKthNumber(n: number, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-kth-number n k)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0440](https://leetcode-cn.com/problems/k-th-smallest-in-lexicographical-order)", "[\u5b57\u5178\u5e8f\u7684\u7b2cK\u5c0f\u6570\u5b57](/solution/0400-0499/0440.K-th%20Smallest%20in%20Lexicographical%20Order/README.md)", "", "\u56f0\u96be", ""], "md_table_row_en": ["[0440](https://leetcode.com/problems/k-th-smallest-in-lexicographical-order)", "[K-th Smallest in Lexicographical Order](/solution/0400-0499/0440.K-th%20Smallest%20in%20Lexicographical%20Order/README_EN.md)", "", "Hard", ""]}, {"question_id": "0439", "frontend_question_id": "0439", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/ternary-expression-parser", "url_en": "https://leetcode.com/problems/ternary-expression-parser", "relative_path_cn": "/solution/0400-0499/0439.Ternary%20Expression%20Parser/README.md", "relative_path_en": "/solution/0400-0499/0439.Ternary%20Expression%20Parser/README_EN.md", "title_cn": "\u4e09\u5143\u8868\u8fbe\u5f0f\u89e3\u6790\u5668", "title_en": "Ternary Expression Parser", "question_title_slug": "ternary-expression-parser", "content_en": "

    Given a string expression representing arbitrarily nested ternary expressions, evaluate the expression, and return the result of it.

    \n\n

    You can always assume that the given expression is valid and only contains digits, '?', ':', 'T', and 'F' where 'T' is true and 'F' is false. All the numbers in the expression are one-digit numbers (i.e., in the range [0, 9]).

    \n\n

    The conditional expressions group right-to-left (as usual in most languages), and the result of the expression will always evaluate to either a digit, 'T' or 'F'.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: expression = "T?2:3"\nOutput: "2"\nExplanation: If true, then result is 2; otherwise result is 3.\n
    \n\n

    Example 2:

    \n\n
    \nInput: expression = "F?1:T?4:5"\nOutput: "4"\nExplanation: The conditional expressions group right-to-left. Using parenthesis, it is read/evaluated as:\n"(F ? 1 : (T ? 4 : 5))" --> "(F ? 1 : 4)" --> "4"\nor "(F ? 1 : (T ? 4 : 5))" --> "(T ? 4 : 5)" --> "4"\n
    \n\n

    Example 3:

    \n\n
    \nInput: expression = "T?T?F:5:3"\nOutput: "F"\nExplanation: The conditional expressions group right-to-left. Using parenthesis, it is read/evaluated as:\n"(T ? (T ? F : 5) : 3)" --> "(T ? F : 3)" --> "F"\n"(T ? (T ? F : 5) : 3)" --> "(T ? F : 5)" --> "F"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 5 <= expression.length <= 104
    • \n\t
    • expression consists of digits, 'T', 'F', '?', and ':'.
    • \n\t
    • It is guaranteed that expression is a valid ternary expression and that each number is a one-digit number.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4ee5\u5b57\u7b26\u4e32\u8868\u793a\u7684\u4efb\u610f\u5d4c\u5957\u7684\u4e09\u5143\u8868\u8fbe\u5f0f\uff0c\u8ba1\u7b97\u8868\u8fbe\u5f0f\u7684\u503c\u3002\u4f60\u53ef\u4ee5\u5047\u5b9a\u7ed9\u5b9a\u7684\u8868\u8fbe\u5f0f\u59cb\u7ec8\u90fd\u662f\u6709\u6548\u7684\u5e76\u4e14\u53ea\u5305\u542b\u6570\u5b57 0-9, ?, :, T \u548c F (T \u548c F \u5206\u522b\u8868\u793a\u771f\u548c\u5047\uff09\u3002

    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    1. \u7ed9\u5b9a\u7684\u5b57\u7b26\u4e32\u957f\u5ea6 ≤ 10000\u3002
    2. \n\t
    3. \u6240\u5305\u542b\u7684\u6570\u5b57\u90fd\u53ea\u6709\u4e00\u4f4d\u6570\u3002
    4. \n\t
    5. \u6761\u4ef6\u8868\u8fbe\u5f0f\u4ece\u53f3\u81f3\u5de6\u7ed3\u5408\uff08\u548c\u5927\u591a\u6570\u7a0b\u5e8f\u8bbe\u8ba1\u8bed\u8a00\u7c7b\u4f3c\uff09\u3002
    6. \n\t
    7. \u6761\u4ef6\u662f T \u548c F\u5176\u4e00\uff0c\u5373\u6761\u4ef6\u6c38\u8fdc\u4e0d\u4f1a\u662f\u6570\u5b57\u3002
    8. \n\t
    9. \u8868\u8fbe\u5f0f\u7684\u7ed3\u679c\u662f\u6570\u5b57 0-9, T \u6216\u8005 F\u3002
    10. \n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a "T?2:3"\n\n\u8f93\u51fa\uff1a "2"\n\n\u89e3\u91ca\uff1a \u5982\u679c\u6761\u4ef6\u4e3a\u771f\uff0c\u7ed3\u679c\u4e3a 2\uff1b\u5426\u5219\uff0c\u7ed3\u679c\u4e3a 3\u3002\n
    \n\n

     

    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a "F?1:T?4:5"\n\n\u8f93\u51fa\uff1a "4"\n\n\u89e3\u91ca\uff1a \u6761\u4ef6\u8868\u8fbe\u5f0f\u81ea\u53f3\u5411\u5de6\u7ed3\u5408\u3002\u4f7f\u7528\u62ec\u53f7\u7684\u8bdd\uff0c\u76f8\u5f53\u4e8e\uff1a\n\n             "(F ? 1 : (T ? 4 : 5))"                   "(F ? 1 : (T ? 4 : 5))"\n          -> "(F ? 1 : 4)"                 \u6216\u8005     -> "(T ? 4 : 5)"\n          -> "4"                                    -> "4"\n
    \n\n

     

    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1a "T?T?F:5:3"\n\n\u8f93\u51fa\uff1a "F"\n\n\u89e3\u91ca\uff1a \u6761\u4ef6\u8868\u8fbe\u5f0f\u81ea\u53f3\u5411\u5de6\u7ed3\u5408\u3002\u4f7f\u7528\u62ec\u53f7\u7684\u8bdd\uff0c\u76f8\u5f53\u4e8e\uff1a\n\n             "(T ? (T ? F : 5) : 3)"                   "(T ? (T ? F : 5) : 3)"\n          -> "(T ? F : 3)"                 \u6216\u8005       -> "(T ? F : 5)"\n          -> "F"                                     -> "F"\n
    \n\n

     

    \n", "tags_en": ["Stack", "Depth-first Search"], "tags_cn": ["\u6808", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string parseTernary(string expression) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String parseTernary(String expression) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def parseTernary(self, expression):\n \"\"\"\n :type expression: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def parseTernary(self, expression: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * parseTernary(char * expression){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ParseTernary(string expression) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} expression\n * @return {string}\n */\nvar parseTernary = function(expression) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} expression\n# @return {String}\ndef parse_ternary(expression)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func parseTernary(_ expression: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func parseTernary(expression string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def parseTernary(expression: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun parseTernary(expression: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn parse_ternary(expression: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $expression\n * @return String\n */\n function parseTernary($expression) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function parseTernary(expression: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (parse-ternary expression)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0439](https://leetcode-cn.com/problems/ternary-expression-parser)", "[\u4e09\u5143\u8868\u8fbe\u5f0f\u89e3\u6790\u5668](/solution/0400-0499/0439.Ternary%20Expression%20Parser/README.md)", "`\u6808`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0439](https://leetcode.com/problems/ternary-expression-parser)", "[Ternary Expression Parser](/solution/0400-0499/0439.Ternary%20Expression%20Parser/README_EN.md)", "`Stack`,`Depth-first Search`", "Medium", "\ud83d\udd12"]}, {"question_id": "0438", "frontend_question_id": "0438", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-all-anagrams-in-a-string", "url_en": "https://leetcode.com/problems/find-all-anagrams-in-a-string", "relative_path_cn": "/solution/0400-0499/0438.Find%20All%20Anagrams%20in%20a%20String/README.md", "relative_path_en": "/solution/0400-0499/0438.Find%20All%20Anagrams%20in%20a%20String/README_EN.md", "title_cn": "\u627e\u5230\u5b57\u7b26\u4e32\u4e2d\u6240\u6709\u5b57\u6bcd\u5f02\u4f4d\u8bcd", "title_en": "Find All Anagrams in a String", "question_title_slug": "find-all-anagrams-in-a-string", "content_en": "

    Given two strings s and p, return an array of all the start indices of p's anagrams in s. You may return the answer in any order.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "cbaebabacd", p = "abc"\nOutput: [0,6]\nExplanation:\nThe substring with start index = 0 is "cba", which is an anagram of "abc".\nThe substring with start index = 6 is "bac", which is an anagram of "abc".\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "abab", p = "ab"\nOutput: [0,1,2]\nExplanation:\nThe substring with start index = 0 is "ab", which is an anagram of "ab".\nThe substring with start index = 1 is "ba", which is an anagram of "ab".\nThe substring with start index = 2 is "ab", which is an anagram of "ab".\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length, p.length <= 3 * 104
    • \n\t
    • s and p consist of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32 \u548c\u4e00\u4e2a\u975e\u7a7a\u5b57\u7b26\u4e32 p\uff0c\u627e\u5230 \u4e2d\u6240\u6709\u662f \u7684\u5b57\u6bcd\u5f02\u4f4d\u8bcd\u7684\u5b50\u4e32\uff0c\u8fd4\u56de\u8fd9\u4e9b\u5b50\u4e32\u7684\u8d77\u59cb\u7d22\u5f15\u3002

    \n\n

    \u5b57\u7b26\u4e32\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\uff0c\u5e76\u4e14\u5b57\u7b26\u4e32 \u548c \u7684\u957f\u5ea6\u90fd\u4e0d\u8d85\u8fc7 20100\u3002

    \n\n

    \u8bf4\u660e\uff1a

    \n\n
      \n\t
    • \u5b57\u6bcd\u5f02\u4f4d\u8bcd\u6307\u5b57\u6bcd\u76f8\u540c\uff0c\u4f46\u6392\u5217\u4e0d\u540c\u7684\u5b57\u7b26\u4e32\u3002
    • \n\t
    • \u4e0d\u8003\u8651\u7b54\u6848\u8f93\u51fa\u7684\u987a\u5e8f\u3002
    • \n
    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165:\ns: "cbaebabacd" p: "abc"\n\n\u8f93\u51fa:\n[0, 6]\n\n\u89e3\u91ca:\n\u8d77\u59cb\u7d22\u5f15\u7b49\u4e8e 0 \u7684\u5b50\u4e32\u662f "cba", \u5b83\u662f "abc" \u7684\u5b57\u6bcd\u5f02\u4f4d\u8bcd\u3002\n\u8d77\u59cb\u7d22\u5f15\u7b49\u4e8e 6 \u7684\u5b50\u4e32\u662f "bac", \u5b83\u662f "abc" \u7684\u5b57\u6bcd\u5f02\u4f4d\u8bcd\u3002\n
    \n\n

     \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165:\ns: "abab" p: "ab"\n\n\u8f93\u51fa:\n[0, 1, 2]\n\n\u89e3\u91ca:\n\u8d77\u59cb\u7d22\u5f15\u7b49\u4e8e 0 \u7684\u5b50\u4e32\u662f "ab", \u5b83\u662f "ab" \u7684\u5b57\u6bcd\u5f02\u4f4d\u8bcd\u3002\n\u8d77\u59cb\u7d22\u5f15\u7b49\u4e8e 1 \u7684\u5b50\u4e32\u662f "ba", \u5b83\u662f "ab" \u7684\u5b57\u6bcd\u5f02\u4f4d\u8bcd\u3002\n\u8d77\u59cb\u7d22\u5f15\u7b49\u4e8e 2 \u7684\u5b50\u4e32\u662f "ab", \u5b83\u662f "ab" \u7684\u5b57\u6bcd\u5f02\u4f4d\u8bcd\u3002\n
    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findAnagrams(string s, string p) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List findAnagrams(String s, String p) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findAnagrams(self, s, p):\n \"\"\"\n :type s: str\n :type p: str\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findAnagrams(self, s: str, p: str) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* findAnagrams(char * s, char * p, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList FindAnagrams(string s, string p) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string} p\n * @return {number[]}\n */\nvar findAnagrams = function(s, p) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String} p\n# @return {Integer[]}\ndef find_anagrams(s, p)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findAnagrams(_ s: String, _ p: String) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findAnagrams(s string, p string) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findAnagrams(s: String, p: String): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findAnagrams(s: String, p: String): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_anagrams(s: String, p: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String $p\n * @return Integer[]\n */\n function findAnagrams($s, $p) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findAnagrams(s: string, p: string): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-anagrams s p)\n (-> string? string? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0438](https://leetcode-cn.com/problems/find-all-anagrams-in-a-string)", "[\u627e\u5230\u5b57\u7b26\u4e32\u4e2d\u6240\u6709\u5b57\u6bcd\u5f02\u4f4d\u8bcd](/solution/0400-0499/0438.Find%20All%20Anagrams%20in%20a%20String/README.md)", "`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0438](https://leetcode.com/problems/find-all-anagrams-in-a-string)", "[Find All Anagrams in a String](/solution/0400-0499/0438.Find%20All%20Anagrams%20in%20a%20String/README_EN.md)", "`Hash Table`", "Medium", ""]}, {"question_id": "0437", "frontend_question_id": "0437", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/path-sum-iii", "url_en": "https://leetcode.com/problems/path-sum-iii", "relative_path_cn": "/solution/0400-0499/0437.Path%20Sum%20III/README.md", "relative_path_en": "/solution/0400-0499/0437.Path%20Sum%20III/README_EN.md", "title_cn": "\u8def\u5f84\u603b\u548c III", "title_en": "Path Sum III", "question_title_slug": "path-sum-iii", "content_en": "

    Given the root of a binary tree and an integer targetSum, return the number of paths where the sum of the values along the path equals targetSum.

    \n\n

    The path does not need to start or end at the root or a leaf, but it must go downwards (i.e., traveling only from parent nodes to child nodes).

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [10,5,-3,3,2,null,11,3,-2,null,1], targetSum = 8\nOutput: 3\nExplanation: The paths that sum to 8 are shown.\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = [5,4,8,11,null,13,4,7,2,null,null,5,1], targetSum = 22\nOutput: 3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [0, 1000].
    • \n\t
    • -109 <= Node.val <= 109
    • \n\t
    • -1000 <= targetSum <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811\uff0c\u5b83\u7684\u6bcf\u4e2a\u7ed3\u70b9\u90fd\u5b58\u653e\u7740\u4e00\u4e2a\u6574\u6570\u503c\u3002

    \n\n

    \u627e\u51fa\u8def\u5f84\u548c\u7b49\u4e8e\u7ed9\u5b9a\u6570\u503c\u7684\u8def\u5f84\u603b\u6570\u3002

    \n\n

    \u8def\u5f84\u4e0d\u9700\u8981\u4ece\u6839\u8282\u70b9\u5f00\u59cb\uff0c\u4e5f\u4e0d\u9700\u8981\u5728\u53f6\u5b50\u8282\u70b9\u7ed3\u675f\uff0c\u4f46\u662f\u8def\u5f84\u65b9\u5411\u5fc5\u987b\u662f\u5411\u4e0b\u7684\uff08\u53ea\u80fd\u4ece\u7236\u8282\u70b9\u5230\u5b50\u8282\u70b9\uff09\u3002

    \n\n

    \u4e8c\u53c9\u6811\u4e0d\u8d85\u8fc71000\u4e2a\u8282\u70b9\uff0c\u4e14\u8282\u70b9\u6570\u503c\u8303\u56f4\u662f [-1000000,1000000] \u7684\u6574\u6570\u3002

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    root = [10,5,-3,3,2,null,11,3,-2,null,1], sum = 8\n\n      10\n     /  \\\n    5   -3\n   / \\    \\\n  3   2   11\n / \\   \\\n3  -2   1\n\n\u8fd4\u56de 3\u3002\u548c\u7b49\u4e8e 8 \u7684\u8def\u5f84\u6709:\n\n1.  5 -> 3\n2.  5 -> 2 -> 1\n3.  -3 -> 11\n
    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int pathSum(TreeNode* root, int targetSum) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int pathSum(TreeNode root, int targetSum) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def pathSum(self, root, targetSum):\n \"\"\"\n :type root: TreeNode\n :type targetSum: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def pathSum(self, root: TreeNode, targetSum: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint pathSum(struct TreeNode* root, int targetSum){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int PathSum(TreeNode root, int targetSum) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number} targetSum\n * @return {number}\n */\nvar pathSum = function(root, targetSum) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @param {Integer} target_sum\n# @return {Integer}\ndef path_sum(root, target_sum)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func pathSum(_ root: TreeNode?, _ targetSum: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc pathSum(root *TreeNode, targetSum int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def pathSum(root: TreeNode, targetSum: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun pathSum(root: TreeNode?, targetSum: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn path_sum(root: Option>>, target_sum: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param Integer $targetSum\n * @return Integer\n */\n function pathSum($root, $targetSum) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction pathSum(root: TreeNode | null, targetSum: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (path-sum root targetSum)\n (-> (or/c tree-node? #f) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0437](https://leetcode-cn.com/problems/path-sum-iii)", "[\u8def\u5f84\u603b\u548c III](/solution/0400-0499/0437.Path%20Sum%20III/README.md)", "`\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0437](https://leetcode.com/problems/path-sum-iii)", "[Path Sum III](/solution/0400-0499/0437.Path%20Sum%20III/README_EN.md)", "`Tree`", "Medium", ""]}, {"question_id": "0436", "frontend_question_id": "0436", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-right-interval", "url_en": "https://leetcode.com/problems/find-right-interval", "relative_path_cn": "/solution/0400-0499/0436.Find%20Right%20Interval/README.md", "relative_path_en": "/solution/0400-0499/0436.Find%20Right%20Interval/README_EN.md", "title_cn": "\u5bfb\u627e\u53f3\u533a\u95f4", "title_en": "Find Right Interval", "question_title_slug": "find-right-interval", "content_en": "

    You are given an array of intervals, where intervals[i] = [starti, endi] and each starti is unique.

    \n\n

    The right interval for an interval i is an interval j such that startj >= endi and startj is minimized.

    \n\n

    Return an array of right interval indices for each interval i. If no right interval exists for interval i, then put -1 at index i.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: intervals = [[1,2]]\nOutput: [-1]\nExplanation: There is only one interval in the collection, so it outputs -1.\n
    \n\n

    Example 2:

    \n\n
    \nInput: intervals = [[3,4],[2,3],[1,2]]\nOutput: [-1,0,1]\nExplanation: There is no right interval for [3,4].\nThe right interval for [2,3] is [3,4] since start0 = 3 is the smallest start that is >= end1 = 3.\nThe right interval for [1,2] is [2,3] since start1 = 2 is the smallest start that is >= end2 = 2.\n
    \n\n

    Example 3:

    \n\n
    \nInput: intervals = [[1,4],[2,3],[3,4]]\nOutput: [-1,2,-1]\nExplanation: There is no right interval for [1,4] and [3,4].\nThe right interval for [2,3] is [3,4] since start2 = 3 is the smallest start that is >= end1 = 3.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= intervals.length <= 2 * 104
    • \n\t
    • intervals[i].length == 2
    • \n\t
    • -106 <= starti <= endi <= 106
    • \n\t
    • The start point of each interval is unique.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u533a\u95f4\u6570\u7ec4 intervals \uff0c\u5176\u4e2d\u00a0intervals[i] = [starti, endi] \uff0c\u4e14\u6bcf\u4e2a\u00a0starti \u90fd \u4e0d\u540c \u3002

    \n\n

    \u533a\u95f4 i \u7684 \u53f3\u4fa7\u533a\u95f4 \u53ef\u4ee5\u8bb0\u4f5c\u533a\u95f4 j \uff0c\u5e76\u6ee1\u8db3 startj\u00a0>= endi \uff0c\u4e14 startj \u6700\u5c0f\u5316 \u3002

    \n\n

    \u8fd4\u56de\u4e00\u4e2a\u7531\u6bcf\u4e2a\u533a\u95f4 i \u7684 \u53f3\u4fa7\u533a\u95f4 \u7684\u6700\u5c0f\u8d77\u59cb\u4f4d\u7f6e\u7ec4\u6210\u7684\u6570\u7ec4\u3002\u5982\u679c\u67d0\u4e2a\u533a\u95f4 i \u4e0d\u5b58\u5728\u5bf9\u5e94\u7684 \u53f3\u4fa7\u533a\u95f4 \uff0c\u5219\u4e0b\u6807 i \u5904\u7684\u503c\u8bbe\u4e3a -1 \u3002

    \n\u00a0\n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aintervals = [[1,2]]\n\u8f93\u51fa\uff1a[-1]\n\u89e3\u91ca\uff1a\u96c6\u5408\u4e2d\u53ea\u6709\u4e00\u4e2a\u533a\u95f4\uff0c\u6240\u4ee5\u8f93\u51fa-1\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aintervals = [[3,4],[2,3],[1,2]]\n\u8f93\u51fa\uff1a[-1, 0, 1]\n\u89e3\u91ca\uff1a\u5bf9\u4e8e [3,4] \uff0c\u6ca1\u6709\u6ee1\u8db3\u6761\u4ef6\u7684\u201c\u53f3\u4fa7\u201d\u533a\u95f4\u3002\n\u5bf9\u4e8e [2,3] \uff0c\u533a\u95f4[3,4]\u5177\u6709\u6700\u5c0f\u7684\u201c\u53f3\u201d\u8d77\u70b9;\n\u5bf9\u4e8e [1,2] \uff0c\u533a\u95f4[2,3]\u5177\u6709\u6700\u5c0f\u7684\u201c\u53f3\u201d\u8d77\u70b9\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aintervals = [[1,4],[2,3],[3,4]]\n\u8f93\u51fa\uff1a[-1, 2, -1]\n\u89e3\u91ca\uff1a\u5bf9\u4e8e\u533a\u95f4 [1,4] \u548c [3,4] \uff0c\u6ca1\u6709\u6ee1\u8db3\u6761\u4ef6\u7684\u201c\u53f3\u4fa7\u201d\u533a\u95f4\u3002\n\u5bf9\u4e8e [2,3] \uff0c\u533a\u95f4 [3,4] \u6709\u6700\u5c0f\u7684\u201c\u53f3\u201d\u8d77\u70b9\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <=\u00a0intervals.length <= 2 * 104
    • \n\t
    • intervals[i].length == 2
    • \n\t
    • -106 <= starti <= endi <= 106
    • \n\t
    • \u6bcf\u4e2a\u95f4\u9694\u7684\u8d77\u70b9\u90fd \u4e0d\u76f8\u540c
    • \n
    \n", "tags_en": ["Binary Search"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findRightInterval(vector>& intervals) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] findRightInterval(int[][] intervals) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findRightInterval(self, intervals):\n \"\"\"\n :type intervals: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findRightInterval(self, intervals: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* findRightInterval(int** intervals, int intervalsSize, int* intervalsColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] FindRightInterval(int[][] intervals) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} intervals\n * @return {number[]}\n */\nvar findRightInterval = function(intervals) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} intervals\n# @return {Integer[]}\ndef find_right_interval(intervals)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findRightInterval(_ intervals: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findRightInterval(intervals [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findRightInterval(intervals: Array[Array[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findRightInterval(intervals: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_right_interval(intervals: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $intervals\n * @return Integer[]\n */\n function findRightInterval($intervals) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findRightInterval(intervals: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-right-interval intervals)\n (-> (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0436](https://leetcode-cn.com/problems/find-right-interval)", "[\u5bfb\u627e\u53f3\u533a\u95f4](/solution/0400-0499/0436.Find%20Right%20Interval/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0436](https://leetcode.com/problems/find-right-interval)", "[Find Right Interval](/solution/0400-0499/0436.Find%20Right%20Interval/README_EN.md)", "`Binary Search`", "Medium", ""]}, {"question_id": "0435", "frontend_question_id": "0435", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/non-overlapping-intervals", "url_en": "https://leetcode.com/problems/non-overlapping-intervals", "relative_path_cn": "/solution/0400-0499/0435.Non-overlapping%20Intervals/README.md", "relative_path_en": "/solution/0400-0499/0435.Non-overlapping%20Intervals/README_EN.md", "title_cn": "\u65e0\u91cd\u53e0\u533a\u95f4", "title_en": "Non-overlapping Intervals", "question_title_slug": "non-overlapping-intervals", "content_en": "

    Given an array of intervals intervals where intervals[i] = [starti, endi], return the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: intervals = [[1,2],[2,3],[3,4],[1,3]]\nOutput: 1\nExplanation: [1,3] can be removed and the rest of the intervals are non-overlapping.\n
    \n\n

    Example 2:

    \n\n
    \nInput: intervals = [[1,2],[1,2],[1,2]]\nOutput: 2\nExplanation: You need to remove two [1,2] to make the rest of the intervals non-overlapping.\n
    \n\n

    Example 3:

    \n\n
    \nInput: intervals = [[1,2],[2,3]]\nOutput: 0\nExplanation: You don't need to remove any of the intervals since they're already non-overlapping.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= intervals.length <= 2 * 104
    • \n\t
    • intervals[i].length == 2
    • \n\t
    • -2 * 104 <= starti < endi <= 2 * 104
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u533a\u95f4\u7684\u96c6\u5408\uff0c\u627e\u5230\u9700\u8981\u79fb\u9664\u533a\u95f4\u7684\u6700\u5c0f\u6570\u91cf\uff0c\u4f7f\u5269\u4f59\u533a\u95f4\u4e92\u4e0d\u91cd\u53e0\u3002

    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u53ef\u4ee5\u8ba4\u4e3a\u533a\u95f4\u7684\u7ec8\u70b9\u603b\u662f\u5927\u4e8e\u5b83\u7684\u8d77\u70b9\u3002
    2. \n\t
    3. \u533a\u95f4 [1,2] \u548c [2,3] \u7684\u8fb9\u754c\u76f8\u4e92“\u63a5\u89e6”\uff0c\u4f46\u6ca1\u6709\u76f8\u4e92\u91cd\u53e0\u3002
    4. \n
    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: [ [1,2], [2,3], [3,4], [1,3] ]\n\n\u8f93\u51fa: 1\n\n\u89e3\u91ca: \u79fb\u9664 [1,3] \u540e\uff0c\u5269\u4e0b\u7684\u533a\u95f4\u6ca1\u6709\u91cd\u53e0\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: [ [1,2], [1,2], [1,2] ]\n\n\u8f93\u51fa: 2\n\n\u89e3\u91ca: \u4f60\u9700\u8981\u79fb\u9664\u4e24\u4e2a [1,2] \u6765\u4f7f\u5269\u4e0b\u7684\u533a\u95f4\u6ca1\u6709\u91cd\u53e0\u3002\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \n\u8f93\u5165: [ [1,2], [2,3] ]\n\n\u8f93\u51fa: 0\n\n\u89e3\u91ca: \u4f60\u4e0d\u9700\u8981\u79fb\u9664\u4efb\u4f55\u533a\u95f4\uff0c\u56e0\u4e3a\u5b83\u4eec\u5df2\u7ecf\u662f\u65e0\u91cd\u53e0\u7684\u4e86\u3002\n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int eraseOverlapIntervals(vector>& intervals) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int eraseOverlapIntervals(int[][] intervals) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def eraseOverlapIntervals(self, intervals):\n \"\"\"\n :type intervals: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def eraseOverlapIntervals(self, intervals: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint eraseOverlapIntervals(int** intervals, int intervalsSize, int* intervalsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int EraseOverlapIntervals(int[][] intervals) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} intervals\n * @return {number}\n */\nvar eraseOverlapIntervals = function(intervals) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} intervals\n# @return {Integer}\ndef erase_overlap_intervals(intervals)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func eraseOverlapIntervals(_ intervals: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func eraseOverlapIntervals(intervals [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def eraseOverlapIntervals(intervals: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun eraseOverlapIntervals(intervals: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn erase_overlap_intervals(intervals: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $intervals\n * @return Integer\n */\n function eraseOverlapIntervals($intervals) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function eraseOverlapIntervals(intervals: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (erase-overlap-intervals intervals)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0435](https://leetcode-cn.com/problems/non-overlapping-intervals)", "[\u65e0\u91cd\u53e0\u533a\u95f4](/solution/0400-0499/0435.Non-overlapping%20Intervals/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0435](https://leetcode.com/problems/non-overlapping-intervals)", "[Non-overlapping Intervals](/solution/0400-0499/0435.Non-overlapping%20Intervals/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "0434", "frontend_question_id": "0434", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-segments-in-a-string", "url_en": "https://leetcode.com/problems/number-of-segments-in-a-string", "relative_path_cn": "/solution/0400-0499/0434.Number%20of%20Segments%20in%20a%20String/README.md", "relative_path_en": "/solution/0400-0499/0434.Number%20of%20Segments%20in%20a%20String/README_EN.md", "title_cn": "\u5b57\u7b26\u4e32\u4e2d\u7684\u5355\u8bcd\u6570", "title_en": "Number of Segments in a String", "question_title_slug": "number-of-segments-in-a-string", "content_en": "

    You are given a string s, return the number of segments in the string

    \n\n

    A segment is defined to be a contiguous sequence of non-space characters.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "Hello, my name is John"\nOutput: 5\nExplanation: The five segments are ["Hello,", "my", "name", "is", "John"]\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "Hello"\nOutput: 1\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "love live! mu'sic forever"\nOutput: 4\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = ""\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= s.length <= 300
    • \n\t
    • s consists of lower-case and upper-case English letters, digits or one of the following characters "!@#$%^&*()_+-=',.:".
    • \n\t
    • The only space character in s is ' '.
    • \n
    \n", "content_cn": "

    \u7edf\u8ba1\u5b57\u7b26\u4e32\u4e2d\u7684\u5355\u8bcd\u4e2a\u6570\uff0c\u8fd9\u91cc\u7684\u5355\u8bcd\u6307\u7684\u662f\u8fde\u7eed\u7684\u4e0d\u662f\u7a7a\u683c\u7684\u5b57\u7b26\u3002

    \n\n

    \u8bf7\u6ce8\u610f\uff0c\u4f60\u53ef\u4ee5\u5047\u5b9a\u5b57\u7b26\u4e32\u91cc\u4e0d\u5305\u62ec\u4efb\u4f55\u4e0d\u53ef\u6253\u5370\u7684\u5b57\u7b26\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: "Hello, my name is John"\n\u8f93\u51fa: 5\n\u89e3\u91ca: \u8fd9\u91cc\u7684\u5355\u8bcd\u662f\u6307\u8fde\u7eed\u7684\u4e0d\u662f\u7a7a\u683c\u7684\u5b57\u7b26\uff0c\u6240\u4ee5 "Hello," \u7b97\u4f5c 1 \u4e2a\u5355\u8bcd\u3002\n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countSegments(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countSegments(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countSegments(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countSegments(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countSegments(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountSegments(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar countSegments = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef count_segments(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countSegments(_ s: String) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countSegments(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countSegments(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countSegments(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_segments(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function countSegments($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countSegments(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-segments s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0434](https://leetcode-cn.com/problems/number-of-segments-in-a-string)", "[\u5b57\u7b26\u4e32\u4e2d\u7684\u5355\u8bcd\u6570](/solution/0400-0499/0434.Number%20of%20Segments%20in%20a%20String/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0434](https://leetcode.com/problems/number-of-segments-in-a-string)", "[Number of Segments in a String](/solution/0400-0499/0434.Number%20of%20Segments%20in%20a%20String/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "0433", "frontend_question_id": "0433", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-genetic-mutation", "url_en": "https://leetcode.com/problems/minimum-genetic-mutation", "relative_path_cn": "/solution/0400-0499/0433.Minimum%20Genetic%20Mutation/README.md", "relative_path_en": "/solution/0400-0499/0433.Minimum%20Genetic%20Mutation/README_EN.md", "title_cn": "\u6700\u5c0f\u57fa\u56e0\u53d8\u5316", "title_en": "Minimum Genetic Mutation", "question_title_slug": "minimum-genetic-mutation", "content_en": "

    A gene string can be represented by an 8-character long string, with choices from 'A', 'C', 'G', and 'T'.

    \n\n

    Suppose we need to investigate a mutation from a gene string start to a gene string end where one mutation is defined as one single character changed in the gene string.

    \n\n
      \n\t
    • For example, "AACCGGTT" --> "AACCGGTA" is one mutation.
    • \n
    \n\n

    There is also a gene bank bank that records all the valid gene mutations. A gene must be in bank to make it a valid gene string.

    \n\n

    Given the two gene strings start and end and the gene bank bank, return the minimum number of mutations needed to mutate from start to end. If there is no such a mutation, return -1.

    \n\n

    Note that the starting point is assumed to be valid, so it might not be included in the bank.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: start = "AACCGGTT", end = "AACCGGTA", bank = ["AACCGGTA"]\nOutput: 1\n
    \n\n

    Example 2:

    \n\n
    \nInput: start = "AACCGGTT", end = "AAACGGTA", bank = ["AACCGGTA","AACCGCTA","AAACGGTA"]\nOutput: 2\n
    \n\n

    Example 3:

    \n\n
    \nInput: start = "AAAAACCC", end = "AACCCCCC", bank = ["AAAACCCC","AAACCCCC","AACCCCCC"]\nOutput: 3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • start.length == 8
    • \n\t
    • end.length == 8
    • \n\t
    • 0 <= bank.length <= 10
    • \n\t
    • bank[i].length == 8
    • \n\t
    • start, end, and bank[i] consist of only the characters ['A', 'C', 'G', 'T'].
    • \n
    \n", "content_cn": "

    \u4e00\u6761\u57fa\u56e0\u5e8f\u5217\u7531\u4e00\u4e2a\u5e26\u67098\u4e2a\u5b57\u7b26\u7684\u5b57\u7b26\u4e32\u8868\u793a\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5b57\u7b26\u90fd\u5c5e\u4e8e \"A\", \"C\", \"G\", \"T\"\u4e2d\u7684\u4efb\u610f\u4e00\u4e2a\u3002

    \n\n

    \u5047\u8bbe\u6211\u4eec\u8981\u8c03\u67e5\u4e00\u4e2a\u57fa\u56e0\u5e8f\u5217\u7684\u53d8\u5316\u3002\u4e00\u6b21\u57fa\u56e0\u53d8\u5316\u610f\u5473\u7740\u8fd9\u4e2a\u57fa\u56e0\u5e8f\u5217\u4e2d\u7684\u4e00\u4e2a\u5b57\u7b26\u53d1\u751f\u4e86\u53d8\u5316\u3002

    \n\n

    \u4f8b\u5982\uff0c\u57fa\u56e0\u5e8f\u5217\u7531\"AACCGGTT\"\u00a0\u53d8\u5316\u81f3\u00a0\"AACCGGTA\"\u00a0\u5373\u53d1\u751f\u4e86\u4e00\u6b21\u57fa\u56e0\u53d8\u5316\u3002

    \n\n

    \u4e0e\u6b64\u540c\u65f6\uff0c\u6bcf\u4e00\u6b21\u57fa\u56e0\u53d8\u5316\u7684\u7ed3\u679c\uff0c\u90fd\u9700\u8981\u662f\u4e00\u4e2a\u5408\u6cd5\u7684\u57fa\u56e0\u4e32\uff0c\u5373\u8be5\u7ed3\u679c\u5c5e\u4e8e\u4e00\u4e2a\u57fa\u56e0\u5e93\u3002

    \n\n

    \u73b0\u5728\u7ed9\u5b9a3\u4e2a\u53c2\u6570 \u2014 start, end, bank\uff0c\u5206\u522b\u4ee3\u8868\u8d77\u59cb\u57fa\u56e0\u5e8f\u5217\uff0c\u76ee\u6807\u57fa\u56e0\u5e8f\u5217\u53ca\u57fa\u56e0\u5e93\uff0c\u8bf7\u627e\u51fa\u80fd\u591f\u4f7f\u8d77\u59cb\u57fa\u56e0\u5e8f\u5217\u53d8\u5316\u4e3a\u76ee\u6807\u57fa\u56e0\u5e8f\u5217\u6240\u9700\u7684\u6700\u5c11\u53d8\u5316\u6b21\u6570\u3002\u5982\u679c\u65e0\u6cd5\u5b9e\u73b0\u76ee\u6807\u53d8\u5316\uff0c\u8bf7\u8fd4\u56de -1\u3002

    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    1. \u8d77\u59cb\u57fa\u56e0\u5e8f\u5217\u9ed8\u8ba4\u662f\u5408\u6cd5\u7684\uff0c\u4f46\u662f\u5b83\u5e76\u4e0d\u4e00\u5b9a\u4f1a\u51fa\u73b0\u5728\u57fa\u56e0\u5e93\u4e2d\u3002
    2. \n\t
    3. \u5982\u679c\u4e00\u4e2a\u8d77\u59cb\u57fa\u56e0\u5e8f\u5217\u9700\u8981\u591a\u6b21\u53d8\u5316\uff0c\u90a3\u4e48\u5b83\u6bcf\u4e00\u6b21\u53d8\u5316\u4e4b\u540e\u7684\u57fa\u56e0\u5e8f\u5217\u90fd\u5fc5\u987b\u662f\u5408\u6cd5\u7684\u3002
    4. \n\t
    5. \u5047\u5b9a\u8d77\u59cb\u57fa\u56e0\u5e8f\u5217\u4e0e\u76ee\u6807\u57fa\u56e0\u5e8f\u5217\u662f\u4e0d\u4e00\u6837\u7684\u3002
    6. \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \nstart: \"AACCGGTT\"\nend:   \"AACCGGTA\"\nbank: [\"AACCGGTA\"]\n\n\u8fd4\u56de\u503c: 1\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \nstart: \"AACCGGTT\"\nend:   \"AAACGGTA\"\nbank: [\"AACCGGTA\", \"AACCGCTA\", \"AAACGGTA\"]\n\n\u8fd4\u56de\u503c: 2\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \nstart: \"AAAAACCC\"\nend:   \"AACCCCCC\"\nbank: [\"AAAACCCC\", \"AAACCCCC\", \"AACCCCCC\"]\n\n\u8fd4\u56de\u503c: 3\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minMutation(string start, string end, vector& bank) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minMutation(String start, String end, String[] bank) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minMutation(self, start, end, bank):\n \"\"\"\n :type start: str\n :type end: str\n :type bank: List[str]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minMutation(self, start: str, end: str, bank: List[str]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minMutation(char * start, char * end, char ** bank, int bankSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinMutation(string start, string end, string[] bank) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} start\n * @param {string} end\n * @param {string[]} bank\n * @return {number}\n */\nvar minMutation = function(start, end, bank) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} start\n# @param {String} end\n# @param {String[]} bank\n# @return {Integer}\ndef min_mutation(start, end, bank)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minMutation(_ start: String, _ end: String, _ bank: [String]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minMutation(start string, end string, bank []string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minMutation(start: String, end: String, bank: Array[String]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minMutation(start: String, end: String, bank: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_mutation(start: String, end: String, bank: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $start\n * @param String $end\n * @param String[] $bank\n * @return Integer\n */\n function minMutation($start, $end, $bank) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minMutation(start: string, end: string, bank: string[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-mutation start end bank)\n (-> string? string? (listof string?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0433](https://leetcode-cn.com/problems/minimum-genetic-mutation)", "[\u6700\u5c0f\u57fa\u56e0\u53d8\u5316](/solution/0400-0499/0433.Minimum%20Genetic%20Mutation/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0433](https://leetcode.com/problems/minimum-genetic-mutation)", "[Minimum Genetic Mutation](/solution/0400-0499/0433.Minimum%20Genetic%20Mutation/README_EN.md)", "", "Medium", ""]}, {"question_id": "0432", "frontend_question_id": "0432", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/all-oone-data-structure", "url_en": "https://leetcode.com/problems/all-oone-data-structure", "relative_path_cn": "/solution/0400-0499/0432.All%20O%60one%20Data%20Structure/README.md", "relative_path_en": "/solution/0400-0499/0432.All%20O%60one%20Data%20Structure/README_EN.md", "title_cn": "\u5168 O(1) \u7684\u6570\u636e\u7ed3\u6784", "title_en": "All O`one Data Structure", "question_title_slug": "all-oone-data-structure", "content_en": "

    Design a data structure to store the strings' count with the ability to return the strings with minimum and maximum counts.

    \n\n

    Implement the AllOne class:

    \n\n
      \n\t
    • AllOne() Initializes the object of the data structure.
    • \n\t
    • inc(String key) Increments the count of the string key by 1. If key does not exist in the data structure, insert it with count 1.
    • \n\t
    • dec(String key) Decrements the count of the string key by 1. If the count of key is 0 after the decrement, remove it from the data structure. It is guaranteed that key exists in the data structure before the decrement.
    • \n\t
    • getMaxKey() Returns one of the keys with the maximal count. If no element exists, return an empty string "".
    • \n\t
    • getMinKey() Returns one of the keys with the minimum count. If no element exists, return an empty string "".
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["AllOne", "inc", "inc", "getMaxKey", "getMinKey", "inc", "getMaxKey", "getMinKey"]\n[[], ["hello"], ["hello"], [], [], ["leet"], [], []]\nOutput\n[null, null, null, "hello", "hello", null, "hello", "leet"]\n\nExplanation\nAllOne allOne = new AllOne();\nallOne.inc("hello");\nallOne.inc("hello");\nallOne.getMaxKey(); // return "hello"\nallOne.getMinKey(); // return "hello"\nallOne.inc("leet");\nallOne.getMaxKey(); // return "hello"\nallOne.getMinKey(); // return "leet"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= key.length <= 10
    • \n\t
    • key consists of lowercase English letters.
    • \n\t
    • It is guaranteed that for each call to dec, key is existing in the data structure.
    • \n\t
    • At most 3 * 104 calls will be made to inc, dec, getMaxKey, and getMinKey.
    • \n
    \n\n

     

    \n

    Follow up: Could you apply all the operations in O(1) time complexity?

    \n", "content_cn": "

    \u8bf7\u4f60\u5b9e\u73b0\u4e00\u4e2a\u6570\u636e\u7ed3\u6784\u652f\u6301\u4ee5\u4e0b\u64cd\u4f5c\uff1a

    \n\n
      \n\t
    1. Inc(key) - \u63d2\u5165\u4e00\u4e2a\u65b0\u7684\u503c\u4e3a 1 \u7684 key\u3002\u6216\u8005\u4f7f\u4e00\u4e2a\u5b58\u5728\u7684 key \u589e\u52a0\u4e00\uff0c\u4fdd\u8bc1 key \u4e0d\u4e3a\u7a7a\u5b57\u7b26\u4e32\u3002
    2. \n\t
    3. Dec(key) - \u5982\u679c\u8fd9\u4e2a key \u7684\u503c\u662f 1\uff0c\u90a3\u4e48\u628a\u4ed6\u4ece\u6570\u636e\u7ed3\u6784\u4e2d\u79fb\u9664\u6389\u3002\u5426\u5219\u4f7f\u4e00\u4e2a\u5b58\u5728\u7684 key \u503c\u51cf\u4e00\u3002\u5982\u679c\u8fd9\u4e2a key \u4e0d\u5b58\u5728\uff0c\u8fd9\u4e2a\u51fd\u6570\u4e0d\u505a\u4efb\u4f55\u4e8b\u60c5\u3002key \u4fdd\u8bc1\u4e0d\u4e3a\u7a7a\u5b57\u7b26\u4e32\u3002
    4. \n\t
    5. GetMaxKey() - \u8fd4\u56de key \u4e2d\u503c\u6700\u5927\u7684\u4efb\u610f\u4e00\u4e2a\u3002\u5982\u679c\u6ca1\u6709\u5143\u7d20\u5b58\u5728\uff0c\u8fd4\u56de\u4e00\u4e2a\u7a7a\u5b57\u7b26\u4e32"" \u3002
    6. \n\t
    7. GetMinKey() - \u8fd4\u56de key \u4e2d\u503c\u6700\u5c0f\u7684\u4efb\u610f\u4e00\u4e2a\u3002\u5982\u679c\u6ca1\u6709\u5143\u7d20\u5b58\u5728\uff0c\u8fd4\u56de\u4e00\u4e2a\u7a7a\u5b57\u7b26\u4e32""\u3002
    8. \n
    \n\n

     

    \n\n

    \u6311\u6218\uff1a

    \n\n

    \u4f60\u80fd\u591f\u4ee5 O(1) \u7684\u65f6\u95f4\u590d\u6742\u5ea6\u5b9e\u73b0\u6240\u6709\u64cd\u4f5c\u5417\uff1f

    \n", "tags_en": ["Design"], "tags_cn": ["\u8bbe\u8ba1"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class AllOne {\npublic:\n /** Initialize your data structure here. */\n AllOne() {\n\n }\n \n /** Inserts a new key with value 1. Or increments an existing key by 1. */\n void inc(string key) {\n\n }\n \n /** Decrements an existing key by 1. If Key's value is 1, remove it from the data structure. */\n void dec(string key) {\n\n }\n \n /** Returns one of the keys with maximal value. */\n string getMaxKey() {\n\n }\n \n /** Returns one of the keys with Minimal value. */\n string getMinKey() {\n\n }\n};\n\n/**\n * Your AllOne object will be instantiated and called as such:\n * AllOne* obj = new AllOne();\n * obj->inc(key);\n * obj->dec(key);\n * string param_3 = obj->getMaxKey();\n * string param_4 = obj->getMinKey();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class AllOne {\n\n /** Initialize your data structure here. */\n public AllOne() {\n\n }\n \n /** Inserts a new key with value 1. Or increments an existing key by 1. */\n public void inc(String key) {\n\n }\n \n /** Decrements an existing key by 1. If Key's value is 1, remove it from the data structure. */\n public void dec(String key) {\n\n }\n \n /** Returns one of the keys with maximal value. */\n public String getMaxKey() {\n\n }\n \n /** Returns one of the keys with Minimal value. */\n public String getMinKey() {\n\n }\n}\n\n/**\n * Your AllOne object will be instantiated and called as such:\n * AllOne obj = new AllOne();\n * obj.inc(key);\n * obj.dec(key);\n * String param_3 = obj.getMaxKey();\n * String param_4 = obj.getMinKey();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class AllOne(object):\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def inc(self, key):\n \"\"\"\n Inserts a new key with value 1. Or increments an existing key by 1.\n :type key: str\n :rtype: None\n \"\"\"\n\n\n def dec(self, key):\n \"\"\"\n Decrements an existing key by 1. If Key's value is 1, remove it from the data structure.\n :type key: str\n :rtype: None\n \"\"\"\n\n\n def getMaxKey(self):\n \"\"\"\n Returns one of the keys with maximal value.\n :rtype: str\n \"\"\"\n\n\n def getMinKey(self):\n \"\"\"\n Returns one of the keys with Minimal value.\n :rtype: str\n \"\"\"\n\n\n\n# Your AllOne object will be instantiated and called as such:\n# obj = AllOne()\n# obj.inc(key)\n# obj.dec(key)\n# param_3 = obj.getMaxKey()\n# param_4 = obj.getMinKey()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class AllOne:\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def inc(self, key: str) -> None:\n \"\"\"\n Inserts a new key with value 1. Or increments an existing key by 1.\n \"\"\"\n\n\n def dec(self, key: str) -> None:\n \"\"\"\n Decrements an existing key by 1. If Key's value is 1, remove it from the data structure.\n \"\"\"\n\n\n def getMaxKey(self) -> str:\n \"\"\"\n Returns one of the keys with maximal value.\n \"\"\"\n\n\n def getMinKey(self) -> str:\n \"\"\"\n Returns one of the keys with Minimal value.\n \"\"\"\n\n\n\n# Your AllOne object will be instantiated and called as such:\n# obj = AllOne()\n# obj.inc(key)\n# obj.dec(key)\n# param_3 = obj.getMaxKey()\n# param_4 = obj.getMinKey()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} AllOne;\n\n/** Initialize your data structure here. */\n\nAllOne* allOneCreate() {\n \n}\n\n/** Inserts a new key with value 1. Or increments an existing key by 1. */\nvoid allOneInc(AllOne* obj, char * key) {\n \n}\n\n/** Decrements an existing key by 1. If Key's value is 1, remove it from the data structure. */\nvoid allOneDec(AllOne* obj, char * key) {\n \n}\n\n/** Returns one of the keys with maximal value. */\nchar * allOneGetMaxKey(AllOne* obj) {\n \n}\n\n/** Returns one of the keys with Minimal value. */\nchar * allOneGetMinKey(AllOne* obj) {\n \n}\n\nvoid allOneFree(AllOne* obj) {\n \n}\n\n/**\n * Your AllOne struct will be instantiated and called as such:\n * AllOne* obj = allOneCreate();\n * allOneInc(obj, key);\n \n * allOneDec(obj, key);\n \n * char * param_3 = allOneGetMaxKey(obj);\n \n * char * param_4 = allOneGetMinKey(obj);\n \n * allOneFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class AllOne {\n\n /** Initialize your data structure here. */\n public AllOne() {\n\n }\n \n /** Inserts a new key with value 1. Or increments an existing key by 1. */\n public void Inc(string key) {\n\n }\n \n /** Decrements an existing key by 1. If Key's value is 1, remove it from the data structure. */\n public void Dec(string key) {\n\n }\n \n /** Returns one of the keys with maximal value. */\n public string GetMaxKey() {\n\n }\n \n /** Returns one of the keys with Minimal value. */\n public string GetMinKey() {\n\n }\n}\n\n/**\n * Your AllOne object will be instantiated and called as such:\n * AllOne obj = new AllOne();\n * obj.Inc(key);\n * obj.Dec(key);\n * string param_3 = obj.GetMaxKey();\n * string param_4 = obj.GetMinKey();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Initialize your data structure here.\n */\nvar AllOne = function() {\n\n};\n\n/**\n * Inserts a new key with value 1. Or increments an existing key by 1. \n * @param {string} key\n * @return {void}\n */\nAllOne.prototype.inc = function(key) {\n\n};\n\n/**\n * Decrements an existing key by 1. If Key's value is 1, remove it from the data structure. \n * @param {string} key\n * @return {void}\n */\nAllOne.prototype.dec = function(key) {\n\n};\n\n/**\n * Returns one of the keys with maximal value.\n * @return {string}\n */\nAllOne.prototype.getMaxKey = function() {\n\n};\n\n/**\n * Returns one of the keys with Minimal value.\n * @return {string}\n */\nAllOne.prototype.getMinKey = function() {\n\n};\n\n/**\n * Your AllOne object will be instantiated and called as such:\n * var obj = new AllOne()\n * obj.inc(key)\n * obj.dec(key)\n * var param_3 = obj.getMaxKey()\n * var param_4 = obj.getMinKey()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class AllOne\n\n=begin\n Initialize your data structure here.\n=end\n def initialize()\n\n end\n\n\n=begin\n Inserts a new key with value 1. Or increments an existing key by 1.\n :type key: String\n :rtype: Void\n=end\n def inc(key)\n\n end\n\n\n=begin\n Decrements an existing key by 1. If Key's value is 1, remove it from the data structure.\n :type key: String\n :rtype: Void\n=end\n def dec(key)\n\n end\n\n\n=begin\n Returns one of the keys with maximal value.\n :rtype: String\n=end\n def get_max_key()\n\n end\n\n\n=begin\n Returns one of the keys with Minimal value.\n :rtype: String\n=end\n def get_min_key()\n\n end\n\n\nend\n\n# Your AllOne object will be instantiated and called as such:\n# obj = AllOne.new()\n# obj.inc(key)\n# obj.dec(key)\n# param_3 = obj.get_max_key()\n# param_4 = obj.get_min_key()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass AllOne {\n\n /** Initialize your data structure here. */\n init() {\n\n }\n \n /** Inserts a new key with value 1. Or increments an existing key by 1. */\n func inc(_ key: String) {\n\n }\n \n /** Decrements an existing key by 1. If Key's value is 1, remove it from the data structure. */\n func dec(_ key: String) {\n\n }\n \n /** Returns one of the keys with maximal value. */\n func getMaxKey() -> String {\n\n }\n \n /** Returns one of the keys with Minimal value. */\n func getMinKey() -> String {\n\n }\n}\n\n/**\n * Your AllOne object will be instantiated and called as such:\n * let obj = AllOne()\n * obj.inc(key)\n * obj.dec(key)\n * let ret_3: String = obj.getMaxKey()\n * let ret_4: String = obj.getMinKey()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type AllOne struct {\n\n}\n\n\n/** Initialize your data structure here. */\nfunc Constructor() AllOne {\n\n}\n\n\n/** Inserts a new key with value 1. Or increments an existing key by 1. */\nfunc (this *AllOne) Inc(key string) {\n\n}\n\n\n/** Decrements an existing key by 1. If Key's value is 1, remove it from the data structure. */\nfunc (this *AllOne) Dec(key string) {\n\n}\n\n\n/** Returns one of the keys with maximal value. */\nfunc (this *AllOne) GetMaxKey() string {\n\n}\n\n\n/** Returns one of the keys with Minimal value. */\nfunc (this *AllOne) GetMinKey() string {\n\n}\n\n\n/**\n * Your AllOne object will be instantiated and called as such:\n * obj := Constructor();\n * obj.Inc(key);\n * obj.Dec(key);\n * param_3 := obj.GetMaxKey();\n * param_4 := obj.GetMinKey();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class AllOne() {\n\n /** Initialize your data structure here. */\n\n\n /** Inserts a new key with value 1. Or increments an existing key by 1. */\n def inc(key: String) {\n\n }\n\n /** Decrements an existing key by 1. If Key's value is 1, remove it from the data structure. */\n def dec(key: String) {\n\n }\n\n /** Returns one of the keys with maximal value. */\n def getMaxKey(): String = {\n\n }\n\n /** Returns one of the keys with Minimal value. */\n def getMinKey(): String = {\n\n }\n\n}\n\n/**\n * Your AllOne object will be instantiated and called as such:\n * var obj = new AllOne()\n * obj.inc(key)\n * obj.dec(key)\n * var param_3 = obj.getMaxKey()\n * var param_4 = obj.getMinKey()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class AllOne() {\n\n /** Initialize your data structure here. */\n\n\n /** Inserts a new key with value 1. Or increments an existing key by 1. */\n fun inc(key: String) {\n\n }\n\n /** Decrements an existing key by 1. If Key's value is 1, remove it from the data structure. */\n fun dec(key: String) {\n\n }\n\n /** Returns one of the keys with maximal value. */\n fun getMaxKey(): String {\n\n }\n\n /** Returns one of the keys with Minimal value. */\n fun getMinKey(): String {\n\n }\n\n}\n\n/**\n * Your AllOne object will be instantiated and called as such:\n * var obj = AllOne()\n * obj.inc(key)\n * obj.dec(key)\n * var param_3 = obj.getMaxKey()\n * var param_4 = obj.getMinKey()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct AllOne {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl AllOne {\n\n /** Initialize your data structure here. */\n fn new() -> Self {\n\n }\n \n /** Inserts a new key with value 1. Or increments an existing key by 1. */\n fn inc(&self, key: String) {\n\n }\n \n /** Decrements an existing key by 1. If Key's value is 1, remove it from the data structure. */\n fn dec(&self, key: String) {\n\n }\n \n /** Returns one of the keys with maximal value. */\n fn get_max_key(&self) -> String {\n\n }\n \n /** Returns one of the keys with Minimal value. */\n fn get_min_key(&self) -> String {\n\n }\n}\n\n/**\n * Your AllOne object will be instantiated and called as such:\n * let obj = AllOne::new();\n * obj.inc(key);\n * obj.dec(key);\n * let ret_3: String = obj.get_max_key();\n * let ret_4: String = obj.get_min_key();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class AllOne {\n /**\n * Initialize your data structure here.\n */\n function __construct() {\n\n }\n\n /**\n * Inserts a new key with value 1. Or increments an existing key by 1.\n * @param String $key\n * @return NULL\n */\n function inc($key) {\n\n }\n\n /**\n * Decrements an existing key by 1. If Key's value is 1, remove it from the data structure.\n * @param String $key\n * @return NULL\n */\n function dec($key) {\n\n }\n\n /**\n * Returns one of the keys with maximal value.\n * @return String\n */\n function getMaxKey() {\n\n }\n\n /**\n * Returns one of the keys with Minimal value.\n * @return String\n */\n function getMinKey() {\n\n }\n}\n\n/**\n * Your AllOne object will be instantiated and called as such:\n * $obj = AllOne();\n * $obj->inc($key);\n * $obj->dec($key);\n * $ret_3 = $obj->getMaxKey();\n * $ret_4 = $obj->getMinKey();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class AllOne {\n constructor() {\n\n }\n\n inc(key: string): void {\n\n }\n\n dec(key: string): void {\n\n }\n\n getMaxKey(): string {\n\n }\n\n getMinKey(): string {\n\n }\n}\n\n/**\n * Your AllOne object will be instantiated and called as such:\n * var obj = new AllOne()\n * obj.inc(key)\n * obj.dec(key)\n * var param_3 = obj.getMaxKey()\n * var param_4 = obj.getMinKey()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define all-one%\n (class object%\n (super-new)\n (init-field)\n \n ; inc : string? -> void?\n (define/public (inc key)\n\n )\n ; dec : string? -> void?\n (define/public (dec key)\n\n )\n ; get-max-key : -> string?\n (define/public (get-max-key)\n\n )\n ; get-min-key : -> string?\n (define/public (get-min-key)\n\n )))\n\n;; Your all-one% object will be instantiated and called as such:\n;; (define obj (new all-one%))\n;; (send obj inc key)\n;; (send obj dec key)\n;; (define param_3 (send obj get-max-key))\n;; (define param_4 (send obj get-min-key))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0432](https://leetcode-cn.com/problems/all-oone-data-structure)", "[\u5168 O(1) \u7684\u6570\u636e\u7ed3\u6784](/solution/0400-0499/0432.All%20O%60one%20Data%20Structure/README.md)", "`\u8bbe\u8ba1`", "\u56f0\u96be", ""], "md_table_row_en": ["[0432](https://leetcode.com/problems/all-oone-data-structure)", "[All O`one Data Structure](/solution/0400-0499/0432.All%20O%60one%20Data%20Structure/README_EN.md)", "`Design`", "Hard", ""]}, {"question_id": "0425", "frontend_question_id": "0425", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/word-squares", "url_en": "https://leetcode.com/problems/word-squares", "relative_path_cn": "/solution/0400-0499/0425.Word%20Squares/README.md", "relative_path_en": "/solution/0400-0499/0425.Word%20Squares/README_EN.md", "title_cn": "\u5355\u8bcd\u65b9\u5757", "title_en": "Word Squares", "question_title_slug": "word-squares", "content_en": "

    Given an array of unique strings words, return all the word squares you can build from words. The same word from words can be used multiple times. You can return the answer in any order.

    \n\n

    A sequence of strings forms a valid word square if the kth row and column read the same string, where 0 <= k < max(numRows, numColumns).

    \n\n
      \n\t
    • For example, the word sequence ["ball","area","lead","lady"] forms a word square because each word reads the same both horizontally and vertically.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: words = ["area","lead","wall","lady","ball"]\nOutput: [["ball","area","lead","lady"],["wall","area","lead","lady"]]\nExplanation:\nThe output consists of two word squares. The order of output does not matter (just the order of words in each word square matters).\n
    \n\n

    Example 2:

    \n\n
    \nInput: words = ["abat","baba","atan","atal"]\nOutput: [["baba","abat","baba","atal"],["baba","abat","baba","atan"]]\nExplanation:\nThe output consists of two word squares. The order of output does not matter (just the order of words in each word square matters).\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= words.length <= 1000
    • \n\t
    • 1 <= words[i].length <= 5
    • \n\t
    • All words[i] have the same length.
    • \n\t
    • words[i] consists of only lowercase English letters.
    • \n\t
    • All words[i] are unique.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5355\u8bcd\u96c6\u5408 \uff08\u6ca1\u6709\u91cd\u590d\uff09\uff0c\u627e\u51fa\u5176\u4e2d\u6240\u6709\u7684 \u5355\u8bcd\u65b9\u5757 \u3002

    \n\n

    \u4e00\u4e2a\u5355\u8bcd\u5e8f\u5217\u5f62\u6210\u4e86\u4e00\u4e2a\u6709\u6548\u7684\u5355\u8bcd\u65b9\u5757\u7684\u610f\u601d\u662f\u6307\u4ece\u7b2c k \u884c\u548c\u7b2c k \u5217 (0 ≤ k < max(\u884c\u6570, \u5217\u6570)) \u6765\u770b\u90fd\u662f\u76f8\u540c\u7684\u5b57\u7b26\u4e32\u3002

    \n\n

    \u4f8b\u5982\uff0c\u5355\u8bcd\u5e8f\u5217 ["ball","area","lead","lady"] \u5f62\u6210\u4e86\u4e00\u4e2a\u5355\u8bcd\u65b9\u5757\uff0c\u56e0\u4e3a\u6bcf\u4e2a\u5355\u8bcd\u4ece\u6c34\u5e73\u65b9\u5411\u770b\u548c\u4ece\u7ad6\u76f4\u65b9\u5411\u770b\u90fd\u662f\u76f8\u540c\u7684\u3002

    \n\n
    b a l l\na r e a\nl e a d\nl a d y\n
    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    1. \u5355\u8bcd\u4e2a\u6570\u5927\u4e8e\u7b49\u4e8e 1 \u4e14\u4e0d\u8d85\u8fc7 500\u3002
    2. \n\t
    3. \u6240\u6709\u7684\u5355\u8bcd\u957f\u5ea6\u90fd\u76f8\u540c\u3002
    4. \n\t
    5. \u5355\u8bcd\u957f\u5ea6\u5927\u4e8e\u7b49\u4e8e 1 \u4e14\u4e0d\u8d85\u8fc7 5\u3002
    6. \n\t
    7. \u6bcf\u4e2a\u5355\u8bcd\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd a-z\u3002
    8. \n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a\n["area","lead","wall","lady","ball"]\n\n\u8f93\u51fa\uff1a\n[\n  [ "wall",\n    "area",\n    "lead",\n    "lady"\n  ],\n  [ "ball",\n    "area",\n    "lead",\n    "lady"\n  ]\n]\n\n\u89e3\u91ca\uff1a\n\u8f93\u51fa\u5305\u542b\u4e24\u4e2a\u5355\u8bcd\u65b9\u5757\uff0c\u8f93\u51fa\u7684\u987a\u5e8f\u4e0d\u91cd\u8981\uff0c\u53ea\u9700\u8981\u4fdd\u8bc1\u6bcf\u4e2a\u5355\u8bcd\u65b9\u5757\u5185\u7684\u5355\u8bcd\u987a\u5e8f\u6b63\u786e\u5373\u53ef\u3002 \n
    \n\n

     

    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a\n["abat","baba","atan","atal"]\n\n\u8f93\u51fa\uff1a\n[\n  [ "baba",\n    "abat",\n    "baba",\n    "atan"\n  ],\n  [ "baba",\n    "abat",\n    "baba",\n    "atal"\n  ]\n]\n\n\u89e3\u91ca\uff1a\n\u8f93\u51fa\u5305\u542b\u4e24\u4e2a\u5355\u8bcd\u65b9\u5757\uff0c\u8f93\u51fa\u7684\u987a\u5e8f\u4e0d\u91cd\u8981\uff0c\u53ea\u9700\u8981\u4fdd\u8bc1\u6bcf\u4e2a\u5355\u8bcd\u65b9\u5757\u5185\u7684\u5355\u8bcd\u987a\u5e8f\u6b63\u786e\u5373\u53ef\u3002 \n
    \n\n

     

    \n", "tags_en": ["Trie", "Backtracking"], "tags_cn": ["\u5b57\u5178\u6811", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> wordSquares(vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> wordSquares(String[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def wordSquares(self, words):\n \"\"\"\n :type words: List[str]\n :rtype: List[List[str]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def wordSquares(self, words: List[str]) -> List[List[str]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nchar *** wordSquares(char ** words, int wordsSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> WordSquares(string[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @return {string[][]}\n */\nvar wordSquares = function(words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @return {String[][]}\ndef word_squares(words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func wordSquares(_ words: [String]) -> [[String]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func wordSquares(words []string) [][]string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def wordSquares(words: Array[String]): List[List[String]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun wordSquares(words: Array): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn word_squares(words: Vec) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @return String[][]\n */\n function wordSquares($words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function wordSquares(words: string[]): string[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (word-squares words)\n (-> (listof string?) (listof (listof string?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0425](https://leetcode-cn.com/problems/word-squares)", "[\u5355\u8bcd\u65b9\u5757](/solution/0400-0499/0425.Word%20Squares/README.md)", "`\u5b57\u5178\u6811`,`\u56de\u6eaf\u7b97\u6cd5`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0425](https://leetcode.com/problems/word-squares)", "[Word Squares](/solution/0400-0499/0425.Word%20Squares/README_EN.md)", "`Trie`,`Backtracking`", "Hard", "\ud83d\udd12"]}, {"question_id": "0424", "frontend_question_id": "0424", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-repeating-character-replacement", "url_en": "https://leetcode.com/problems/longest-repeating-character-replacement", "relative_path_cn": "/solution/0400-0499/0424.Longest%20Repeating%20Character%20Replacement/README.md", "relative_path_en": "/solution/0400-0499/0424.Longest%20Repeating%20Character%20Replacement/README_EN.md", "title_cn": "\u66ff\u6362\u540e\u7684\u6700\u957f\u91cd\u590d\u5b57\u7b26", "title_en": "Longest Repeating Character Replacement", "question_title_slug": "longest-repeating-character-replacement", "content_en": "

    You are given a string s and an integer k. You can choose any character of the string and change it to any other uppercase English character. You can perform this operation at most k times.

    \n\n

    Return the length of the longest substring containing the same letter you can get after performing the above operations.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "ABAB", k = 2\nOutput: 4\nExplanation: Replace the two 'A's with two 'B's or vice versa.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "AABABBA", k = 1\nOutput: 4\nExplanation: Replace the one 'A' in the middle with 'B' and form "AABBBBA".\nThe substring "BBBB" has the longest repeating letters, which is 4.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 105
    • \n\t
    • s consists of only uppercase English letters.
    • \n\t
    • 0 <= k <= s.length
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u4ec5\u7531\u5927\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\u7684\u5b57\u7b26\u4e32\uff0c\u4f60\u53ef\u4ee5\u5c06\u4efb\u610f\u4f4d\u7f6e\u4e0a\u7684\u5b57\u7b26\u66ff\u6362\u6210\u53e6\u5916\u7684\u5b57\u7b26\uff0c\u603b\u5171\u53ef\u6700\u591a\u66ff\u6362\u00a0k\u00a0\u6b21\u3002\u5728\u6267\u884c\u4e0a\u8ff0\u64cd\u4f5c\u540e\uff0c\u627e\u5230\u5305\u542b\u91cd\u590d\u5b57\u6bcd\u7684\u6700\u957f\u5b50\u4e32\u7684\u957f\u5ea6\u3002

    \n\n

    \u6ce8\u610f\uff1a\u5b57\u7b26\u4e32\u957f\u5ea6 \u548c k \u4e0d\u4f1a\u8d85\u8fc7\u00a0104\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"ABAB\", k = 2\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u7528\u4e24\u4e2a'A'\u66ff\u6362\u4e3a\u4e24\u4e2a'B',\u53cd\u4e4b\u4ea6\u7136\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"AABABBA\", k = 1\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\n\u5c06\u4e2d\u95f4\u7684\u4e00\u4e2a'A'\u66ff\u6362\u4e3a'B',\u5b57\u7b26\u4e32\u53d8\u4e3a \"AABBBBA\"\u3002\n\u5b50\u4e32 \"BBBB\" \u6709\u6700\u957f\u91cd\u590d\u5b57\u6bcd, \u7b54\u6848\u4e3a 4\u3002\n
    \n", "tags_en": ["Two Pointers", "Sliding Window"], "tags_cn": ["\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int characterReplacement(string s, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int characterReplacement(String s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def characterReplacement(self, s, k):\n \"\"\"\n :type s: str\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def characterReplacement(self, s: str, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint characterReplacement(char * s, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CharacterReplacement(string s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number} k\n * @return {number}\n */\nvar characterReplacement = function(s, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer} k\n# @return {Integer}\ndef character_replacement(s, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func characterReplacement(_ s: String, _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func characterReplacement(s string, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def characterReplacement(s: String, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun characterReplacement(s: String, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn character_replacement(s: String, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer $k\n * @return Integer\n */\n function characterReplacement($s, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function characterReplacement(s: string, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (character-replacement s k)\n (-> string? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0424](https://leetcode-cn.com/problems/longest-repeating-character-replacement)", "[\u66ff\u6362\u540e\u7684\u6700\u957f\u91cd\u590d\u5b57\u7b26](/solution/0400-0499/0424.Longest%20Repeating%20Character%20Replacement/README.md)", "`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0424](https://leetcode.com/problems/longest-repeating-character-replacement)", "[Longest Repeating Character Replacement](/solution/0400-0499/0424.Longest%20Repeating%20Character%20Replacement/README_EN.md)", "`Two Pointers`,`Sliding Window`", "Medium", ""]}, {"question_id": "0423", "frontend_question_id": "0423", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reconstruct-original-digits-from-english", "url_en": "https://leetcode.com/problems/reconstruct-original-digits-from-english", "relative_path_cn": "/solution/0400-0499/0423.Reconstruct%20Original%20Digits%20from%20English/README.md", "relative_path_en": "/solution/0400-0499/0423.Reconstruct%20Original%20Digits%20from%20English/README_EN.md", "title_cn": "\u4ece\u82f1\u6587\u4e2d\u91cd\u5efa\u6570\u5b57", "title_en": "Reconstruct Original Digits from English", "question_title_slug": "reconstruct-original-digits-from-english", "content_en": "

    Given a string s containing an out-of-order English representation of digits 0-9, return the digits in ascending order.

    \n\n

     

    \n

    Example 1:

    \n
    Input: s = \"owoztneoer\"\nOutput: \"012\"\n

    Example 2:

    \n
    Input: s = \"fviefuro\"\nOutput: \"45\"\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 105
    • \n\t
    • s[i] is one of the characters ["e","g","f","i","h","o","n","s","r","u","t","w","v","x","z"].
    • \n\t
    • s is guaranteed to be valid.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u7a7a\u5b57\u7b26\u4e32\uff0c\u5176\u4e2d\u5305\u542b\u5b57\u6bcd\u987a\u5e8f\u6253\u4e71\u7684\u82f1\u6587\u5355\u8bcd\u8868\u793a\u7684\u6570\u5b570-9\u3002\u6309\u5347\u5e8f\u8f93\u51fa\u539f\u59cb\u7684\u6570\u5b57\u3002

    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u8f93\u5165\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    2. \n\t
    3. \u8f93\u5165\u4fdd\u8bc1\u5408\u6cd5\u5e76\u53ef\u4ee5\u8f6c\u6362\u4e3a\u539f\u59cb\u7684\u6570\u5b57\uff0c\u8fd9\u610f\u5473\u7740\u50cf "abc" \u6216 "zerone" \u7684\u8f93\u5165\u662f\u4e0d\u5141\u8bb8\u7684\u3002
    4. \n\t
    5. \u8f93\u5165\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u5c0f\u4e8e 50,000\u3002
    6. \n
    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: "owoztneoer"\n\n\u8f93\u51fa: "012" (zeroonetwo)\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: "fviefuro"\n\n\u8f93\u51fa: "45" (fourfive)\n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string originalDigits(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String originalDigits(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def originalDigits(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def originalDigits(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * originalDigits(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string OriginalDigits(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar originalDigits = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef original_digits(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func originalDigits(_ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func originalDigits(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def originalDigits(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun originalDigits(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn original_digits(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function originalDigits($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function originalDigits(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (original-digits s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0423](https://leetcode-cn.com/problems/reconstruct-original-digits-from-english)", "[\u4ece\u82f1\u6587\u4e2d\u91cd\u5efa\u6570\u5b57](/solution/0400-0499/0423.Reconstruct%20Original%20Digits%20from%20English/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0423](https://leetcode.com/problems/reconstruct-original-digits-from-english)", "[Reconstruct Original Digits from English](/solution/0400-0499/0423.Reconstruct%20Original%20Digits%20from%20English/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "0422", "frontend_question_id": "0422", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/valid-word-square", "url_en": "https://leetcode.com/problems/valid-word-square", "relative_path_cn": "/solution/0400-0499/0422.Valid%20Word%20Square/README.md", "relative_path_en": "/solution/0400-0499/0422.Valid%20Word%20Square/README_EN.md", "title_cn": "\u6709\u6548\u7684\u5355\u8bcd\u65b9\u5757", "title_en": "Valid Word Square", "question_title_slug": "valid-word-square", "content_en": "

    Given an array of strings words, return true if it forms a valid word square.

    \n\n

    A sequence of strings forms a valid word square if the kth row and column read the same string, where 0 <= k < max(numRows, numColumns).

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: words = ["abcd","bnrt","crmy","dtye"]\nOutput: true\nExplanation:\nThe 1st row and 1st column both read "abcd".\nThe 2nd row and 2nd column both read "bnrt".\nThe 3rd row and 3rd column both read "crmy".\nThe 4th row and 4th column both read "dtye".\nTherefore, it is a valid word square.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: words = ["abcd","bnrt","crm","dt"]\nOutput: true\nExplanation:\nThe 1st row and 1st column both read "abcd".\nThe 2nd row and 2nd column both read "bnrt".\nThe 3rd row and 3rd column both read "crm".\nThe 4th row and 4th column both read "dt".\nTherefore, it is a valid word square.\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: words = ["ball","area","read","lady"]\nOutput: false\nExplanation:\nThe 3rd row reads "read" while the 3rd column reads "lead".\nTherefore, it is NOT a valid word square.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= words.length <= 500
    • \n\t
    • 1 <= words[i].length <= 500
    • \n\t
    • words[i] consists of only lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5355\u8bcd\u5e8f\u5217\uff0c\u5224\u65ad\u5176\u662f\u5426\u5f62\u6210\u4e86\u4e00\u4e2a\u6709\u6548\u7684\u5355\u8bcd\u65b9\u5757\u3002

    \n\n

    \u6709\u6548\u7684\u5355\u8bcd\u65b9\u5757\u662f\u6307\u6b64\u7531\u5355\u8bcd\u5e8f\u5217\u7ec4\u6210\u7684\u6587\u5b57\u65b9\u5757\u7684 \u7b2c k \u884c \u548c \u7b2c k \u5217 (0 ≤ k < max(\u884c\u6570, \u5217\u6570)) \u6240\u663e\u793a\u7684\u5b57\u7b26\u4e32\u5b8c\u5168\u76f8\u540c\u3002

    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    1. \u7ed9\u5b9a\u7684\u5355\u8bcd\u6570\u5927\u4e8e\u7b49\u4e8e 1 \u4e14\u4e0d\u8d85\u8fc7 500\u3002
    2. \n\t
    3. \u5355\u8bcd\u957f\u5ea6\u5927\u4e8e\u7b49\u4e8e 1 \u4e14\u4e0d\u8d85\u8fc7 500\u3002
    4. \n\t
    5. \u6bcf\u4e2a\u5355\u8bcd\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd a-z\u3002
    6. \n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a\n[\n  "abcd",\n  "bnrt",\n  "crmy",\n  "dtye"\n]\n\n\u8f93\u51fa\uff1a\ntrue\n\n\u89e3\u91ca\uff1a\n\u7b2c 1 \u884c\u548c\u7b2c 1 \u5217\u90fd\u662f "abcd"\u3002\n\u7b2c 2 \u884c\u548c\u7b2c 2 \u5217\u90fd\u662f "bnrt"\u3002\n\u7b2c 3 \u884c\u548c\u7b2c 3 \u5217\u90fd\u662f "crmy"\u3002\n\u7b2c 4 \u884c\u548c\u7b2c 4 \u5217\u90fd\u662f "dtye"\u3002\n\n\u56e0\u6b64\uff0c\u8fd9\u662f\u4e00\u4e2a\u6709\u6548\u7684\u5355\u8bcd\u65b9\u5757\u3002\n
    \n\n

     

    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a\n[\n  "abcd",\n  "bnrt",\n  "crm",\n  "dt"\n]\n\n\u8f93\u51fa\uff1a\ntrue\n\n\u89e3\u91ca\uff1a\n\u7b2c 1 \u884c\u548c\u7b2c 1 \u5217\u90fd\u662f "abcd"\u3002\n\u7b2c 2 \u884c\u548c\u7b2c 2 \u5217\u90fd\u662f "bnrt"\u3002\n\u7b2c 3 \u884c\u548c\u7b2c 3 \u5217\u90fd\u662f "crm"\u3002\n\u7b2c 4 \u884c\u548c\u7b2c 4 \u5217\u90fd\u662f "dt"\u3002\n\n\u56e0\u6b64\uff0c\u8fd9\u662f\u4e00\u4e2a\u6709\u6548\u7684\u5355\u8bcd\u65b9\u5757\u3002\n
    \n\n

     

    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1a\n[\n  "ball",\n  "area",\n  "read",\n  "lady"\n]\n\n\u8f93\u51fa\uff1a\nfalse\n\n\u89e3\u91ca\uff1a\n\u7b2c 3 \u884c\u662f "read" \uff0c\u7136\u800c\u7b2c 3 \u5217\u662f "lead"\u3002\n\n\u56e0\u6b64\uff0c\u8fd9 \u4e0d\u662f \u4e00\u4e2a\u6709\u6548\u7684\u5355\u8bcd\u65b9\u5757\u3002\n
    \n\n

     

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool validWordSquare(vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean validWordSquare(List words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def validWordSquare(self, words):\n \"\"\"\n :type words: List[str]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def validWordSquare(self, words: List[str]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool validWordSquare(char ** words, int wordsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool ValidWordSquare(IList words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @return {boolean}\n */\nvar validWordSquare = function(words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @return {Boolean}\ndef valid_word_square(words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func validWordSquare(_ words: [String]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func validWordSquare(words []string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def validWordSquare(words: List[String]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun validWordSquare(words: List): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn valid_word_square(words: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @return Boolean\n */\n function validWordSquare($words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function validWordSquare(words: string[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (valid-word-square words)\n (-> (listof string?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0422](https://leetcode-cn.com/problems/valid-word-square)", "[\u6709\u6548\u7684\u5355\u8bcd\u65b9\u5757](/solution/0400-0499/0422.Valid%20Word%20Square/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0422](https://leetcode.com/problems/valid-word-square)", "[Valid Word Square](/solution/0400-0499/0422.Valid%20Word%20Square/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "0421", "frontend_question_id": "0421", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-xor-of-two-numbers-in-an-array", "url_en": "https://leetcode.com/problems/maximum-xor-of-two-numbers-in-an-array", "relative_path_cn": "/solution/0400-0499/0421.Maximum%20XOR%20of%20Two%20Numbers%20in%20an%20Array/README.md", "relative_path_en": "/solution/0400-0499/0421.Maximum%20XOR%20of%20Two%20Numbers%20in%20an%20Array/README_EN.md", "title_cn": "\u6570\u7ec4\u4e2d\u4e24\u4e2a\u6570\u7684\u6700\u5927\u5f02\u6216\u503c", "title_en": "Maximum XOR of Two Numbers in an Array", "question_title_slug": "maximum-xor-of-two-numbers-in-an-array", "content_en": "

    Given an integer array nums, return the maximum result of nums[i] XOR nums[j], where 0 <= i <= j < n.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [3,10,5,25,2,8]\nOutput: 28\nExplanation: The maximum result is 5 XOR 25 = 28.
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [0]\nOutput: 0\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [2,4]\nOutput: 6\n
    \n\n

    Example 4:

    \n\n
    \nInput: nums = [8,10,2]\nOutput: 10\n
    \n\n

    Example 5:

    \n\n
    \nInput: nums = [14,70,53,83,49,91,36,80,92,51,66,70]\nOutput: 127\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 2 * 105
    • \n\t
    • 0 <= nums[i] <= 231 - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \uff0c\u8fd4\u56de nums[i] XOR nums[j] \u7684\u6700\u5927\u8fd0\u7b97\u7ed3\u679c\uff0c\u5176\u4e2d 0 \u2264 i \u2264 j < n \u3002

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u53ef\u4ee5\u5728 O(n) \u7684\u65f6\u95f4\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u5417\uff1f

    \n\n

    \u00a0

    \n\n
    \n
    \n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [3,10,5,25,2,8]\n\u8f93\u51fa\uff1a28\n\u89e3\u91ca\uff1a\u6700\u5927\u8fd0\u7b97\u7ed3\u679c\u662f 5 XOR 25 = 28.
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [0]\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [2,4]\n\u8f93\u51fa\uff1a6\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [8,10,2]\n\u8f93\u51fa\uff1a10\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [14,70,53,83,49,91,36,80,92,51,66,70]\n\u8f93\u51fa\uff1a127\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 2 * 104
    • \n\t
    • 0 <= nums[i] <= 231 - 1
    • \n
    \n
    \n
    \n", "tags_en": ["Bit Manipulation", "Trie"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u5b57\u5178\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findMaximumXOR(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findMaximumXOR(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findMaximumXOR(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findMaximumXOR(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findMaximumXOR(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindMaximumXOR(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar findMaximumXOR = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef find_maximum_xor(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findMaximumXOR(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findMaximumXOR(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findMaximumXOR(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findMaximumXOR(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_maximum_xor(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function findMaximumXOR($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findMaximumXOR(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-maximum-xor nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0421](https://leetcode-cn.com/problems/maximum-xor-of-two-numbers-in-an-array)", "[\u6570\u7ec4\u4e2d\u4e24\u4e2a\u6570\u7684\u6700\u5927\u5f02\u6216\u503c](/solution/0400-0499/0421.Maximum%20XOR%20of%20Two%20Numbers%20in%20an%20Array/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u5b57\u5178\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0421](https://leetcode.com/problems/maximum-xor-of-two-numbers-in-an-array)", "[Maximum XOR of Two Numbers in an Array](/solution/0400-0499/0421.Maximum%20XOR%20of%20Two%20Numbers%20in%20an%20Array/README_EN.md)", "`Bit Manipulation`,`Trie`", "Medium", ""]}, {"question_id": "0420", "frontend_question_id": "0420", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/strong-password-checker", "url_en": "https://leetcode.com/problems/strong-password-checker", "relative_path_cn": "/solution/0400-0499/0420.Strong%20Password%20Checker/README.md", "relative_path_en": "/solution/0400-0499/0420.Strong%20Password%20Checker/README_EN.md", "title_cn": "\u5f3a\u5bc6\u7801\u68c0\u9a8c\u5668", "title_en": "Strong Password Checker", "question_title_slug": "strong-password-checker", "content_en": "

    A password is considered strong if the below conditions are all met:

    \n\n
      \n\t
    • It has at least 6 characters and at most 20 characters.
    • \n\t
    • It contains at least one lowercase letter, at least one uppercase letter, and at least one digit.
    • \n\t
    • It does not contain three repeating characters in a row (i.e., "...aaa..." is weak, but "...aa...a..." is strong, assuming other conditions are met).
    • \n
    \n\n

    Given a string password, return the minimum number of steps required to make password strong. if password is already strong, return 0.

    \n\n

    In one step, you can:

    \n\n
      \n\t
    • Insert one character to password,
    • \n\t
    • Delete one character from password, or
    • \n\t
    • Replace one character of password with another character.
    • \n
    \n\n

     

    \n

    Example 1:

    \n
    Input: password = \"a\"\nOutput: 5\n

    Example 2:

    \n
    Input: password = \"aA1\"\nOutput: 3\n

    Example 3:

    \n
    Input: password = \"1337C0d3\"\nOutput: 0\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= password.length <= 50
    • \n\t
    • password consists of letters, digits, dot '.' or exclamation mark '!'.
    • \n
    \n", "content_cn": "

    \u4e00\u4e2a\u5f3a\u5bc6\u7801\u5e94\u6ee1\u8db3\u4ee5\u4e0b\u6240\u6709\u6761\u4ef6\uff1a

    \n\n
      \n\t
    1. \u7531\u81f3\u5c116\u4e2a\uff0c\u81f3\u591a20\u4e2a\u5b57\u7b26\u7ec4\u6210\u3002
    2. \n\t
    3. \u81f3\u5c11\u5305\u542b\u4e00\u4e2a\u5c0f\u5199\u5b57\u6bcd\uff0c\u4e00\u4e2a\u5927\u5199\u5b57\u6bcd\uff0c\u548c\u4e00\u4e2a\u6570\u5b57\u3002
    4. \n\t
    5. \u540c\u4e00\u5b57\u7b26\u4e0d\u80fd\u8fde\u7eed\u51fa\u73b0\u4e09\u6b21 (\u6bd4\u5982 "...aaa..." \u662f\u4e0d\u5141\u8bb8\u7684, \u4f46\u662f "...aa...a..." \u662f\u53ef\u4ee5\u7684)\u3002
    6. \n
    \n\n

    \u7f16\u5199\u51fd\u6570 strongPasswordChecker(s)\uff0cs \u4ee3\u8868\u8f93\u5165\u5b57\u7b26\u4e32\uff0c\u5982\u679c s \u5df2\u7ecf\u7b26\u5408\u5f3a\u5bc6\u7801\u6761\u4ef6\uff0c\u5219\u8fd4\u56de0\uff1b\u5426\u5219\u8fd4\u56de\u8981\u5c06 s \u4fee\u6539\u4e3a\u6ee1\u8db3\u5f3a\u5bc6\u7801\u6761\u4ef6\u7684\u5b57\u7b26\u4e32\u6240\u9700\u8981\u8fdb\u884c\u4fee\u6539\u7684\u6700\u5c0f\u6b65\u6570\u3002

    \n\n

    \u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\u4efb\u4e00\u5b57\u7b26\u90fd\u7b97\u4f5c\u4e00\u6b21\u4fee\u6539\u3002

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int strongPasswordChecker(string password) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int strongPasswordChecker(String password) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def strongPasswordChecker(self, password):\n \"\"\"\n :type password: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def strongPasswordChecker(self, password: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint strongPasswordChecker(char * password){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int StrongPasswordChecker(string password) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} password\n * @return {number}\n */\nvar strongPasswordChecker = function(password) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} password\n# @return {Integer}\ndef strong_password_checker(password)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func strongPasswordChecker(_ password: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func strongPasswordChecker(password string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def strongPasswordChecker(password: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun strongPasswordChecker(password: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn strong_password_checker(password: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $password\n * @return Integer\n */\n function strongPasswordChecker($password) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function strongPasswordChecker(password: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (strong-password-checker password)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0420](https://leetcode-cn.com/problems/strong-password-checker)", "[\u5f3a\u5bc6\u7801\u68c0\u9a8c\u5668](/solution/0400-0499/0420.Strong%20Password%20Checker/README.md)", "", "\u56f0\u96be", ""], "md_table_row_en": ["[0420](https://leetcode.com/problems/strong-password-checker)", "[Strong Password Checker](/solution/0400-0499/0420.Strong%20Password%20Checker/README_EN.md)", "", "Hard", ""]}, {"question_id": "0419", "frontend_question_id": "0419", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/battleships-in-a-board", "url_en": "https://leetcode.com/problems/battleships-in-a-board", "relative_path_cn": "/solution/0400-0499/0419.Battleships%20in%20a%20Board/README.md", "relative_path_en": "/solution/0400-0499/0419.Battleships%20in%20a%20Board/README_EN.md", "title_cn": "\u7532\u677f\u4e0a\u7684\u6218\u8230", "title_en": "Battleships in a Board", "question_title_slug": "battleships-in-a-board", "content_en": "

    Given an m x n matrix board where each cell is a battleship 'X' or empty '.', return the number of the battleships on board.

    \n\n

    Battleships can only be placed horizontally or vertically on board. In other words, they can only be made of the shape 1 x k (1 row, k columns) or k x 1 (k rows, 1 column), where k can be of any size. At least one horizontal or vertical cell separates between two battleships (i.e., there are no adjacent battleships).

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: board = [["X",".",".","X"],[".",".",".","X"],[".",".",".","X"]]\nOutput: 2\n
    \n\n

    Example 2:

    \n\n
    \nInput: board = [["."]]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == board.length
    • \n\t
    • n == board[i].length
    • \n\t
    • 1 <= m, n <= 200
    • \n\t
    • board[i][j] is either '.' or 'X'.
    • \n
    \n\n

     

    \n

    Follow up: Could you do it in one-pass, using only O(1) extra memory and without modifying the values board?

    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u7ef4\u7684\u7532\u677f\uff0c \u8bf7\u8ba1\u7b97\u5176\u4e2d\u6709\u591a\u5c11\u8258\u6218\u8230\u3002 \u6218\u8230\u7528 'X'\u8868\u793a\uff0c\u7a7a\u4f4d\u7528 '.'\u8868\u793a\u3002 \u4f60\u9700\u8981\u9075\u5b88\u4ee5\u4e0b\u89c4\u5219\uff1a

    \n\n
      \n\t
    • \u7ed9\u4f60\u4e00\u4e2a\u6709\u6548\u7684\u7532\u677f\uff0c\u4ec5\u7531\u6218\u8230\u6216\u8005\u7a7a\u4f4d\u7ec4\u6210\u3002
    • \n\t
    • \u6218\u8230\u53ea\u80fd\u6c34\u5e73\u6216\u8005\u5782\u76f4\u653e\u7f6e\u3002\u6362\u53e5\u8bdd\u8bf4,\u6218\u8230\u53ea\u80fd\u7531 1xN (1 \u884c, N \u5217)\u7ec4\u6210\uff0c\u6216\u8005 Nx1 (N \u884c, 1 \u5217)\u7ec4\u6210\uff0c\u5176\u4e2dN\u53ef\u4ee5\u662f\u4efb\u610f\u5927\u5c0f\u3002
    • \n\t
    • \u4e24\u8258\u6218\u8230\u4e4b\u95f4\u81f3\u5c11\u6709\u4e00\u4e2a\u6c34\u5e73\u6216\u5782\u76f4\u7684\u7a7a\u4f4d\u5206\u9694 - \u5373\u6ca1\u6709\u76f8\u90bb\u7684\u6218\u8230\u3002
    • \n
    \n\n

    \u793a\u4f8b :

    \n\n
    \nX..X\n...X\n...X\n
    \n\n

    \u5728\u4e0a\u9762\u7684\u7532\u677f\u4e2d\u67092\u8258\u6218\u8230\u3002

    \n\n

    \u65e0\u6548\u6837\u4f8b :

    \n\n
    \n...X\nXXXX\n...X\n
    \n\n

    \u4f60\u4e0d\u4f1a\u6536\u5230\u8fd9\u6837\u7684\u65e0\u6548\u7532\u677f - \u56e0\u4e3a\u6218\u8230\u4e4b\u95f4\u81f3\u5c11\u4f1a\u6709\u4e00\u4e2a\u7a7a\u4f4d\u5c06\u5b83\u4eec\u5206\u5f00\u3002

    \n\n

    \u8fdb\u9636:

    \n\n

    \u4f60\u53ef\u4ee5\u7528\u4e00\u6b21\u626b\u63cf\u7b97\u6cd5\uff0c\u53ea\u4f7f\u7528O(1)\u989d\u5916\u7a7a\u95f4\uff0c\u5e76\u4e14\u4e0d\u4fee\u6539\u7532\u677f\u7684\u503c\u6765\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u5417\uff1f

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countBattleships(vector>& board) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countBattleships(char[][] board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countBattleships(self, board):\n \"\"\"\n :type board: List[List[str]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countBattleships(self, board: List[List[str]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countBattleships(char** board, int boardSize, int* boardColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountBattleships(char[][] board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {character[][]} board\n * @return {number}\n */\nvar countBattleships = function(board) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Character[][]} board\n# @return {Integer}\ndef count_battleships(board)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countBattleships(_ board: [[Character]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countBattleships(board [][]byte) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countBattleships(board: Array[Array[Char]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countBattleships(board: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_battleships(board: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $board\n * @return Integer\n */\n function countBattleships($board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countBattleships(board: string[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-battleships board)\n (-> (listof (listof char?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0419](https://leetcode-cn.com/problems/battleships-in-a-board)", "[\u7532\u677f\u4e0a\u7684\u6218\u8230](/solution/0400-0499/0419.Battleships%20in%20a%20Board/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0419](https://leetcode.com/problems/battleships-in-a-board)", "[Battleships in a Board](/solution/0400-0499/0419.Battleships%20in%20a%20Board/README_EN.md)", "", "Medium", ""]}, {"question_id": "0418", "frontend_question_id": "0418", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/sentence-screen-fitting", "url_en": "https://leetcode.com/problems/sentence-screen-fitting", "relative_path_cn": "/solution/0400-0499/0418.Sentence%20Screen%20Fitting/README.md", "relative_path_en": "/solution/0400-0499/0418.Sentence%20Screen%20Fitting/README_EN.md", "title_cn": "\u5c4f\u5e55\u53ef\u663e\u793a\u53e5\u5b50\u7684\u6570\u91cf", "title_en": "Sentence Screen Fitting", "question_title_slug": "sentence-screen-fitting", "content_en": "

    Given a rows x cols screen and a sentence represented as a list of strings, return the number of times the given sentence can be fitted on the screen.

    \n\n

    The order of words in the sentence must remain unchanged, and a word cannot be split into two lines. A single space must separate two consecutive words in a line.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: sentence = ["hello","world"], rows = 2, cols = 8\nOutput: 1\nExplanation:\nhello---\nworld---\nThe character '-' signifies an empty space on the screen.\n
    \n\n

    Example 2:

    \n\n
    \nInput: sentence = ["a", "bcd", "e"], rows = 3, cols = 6\nOutput: 2\nExplanation:\na-bcd- \ne-a---\nbcd-e-\nThe character '-' signifies an empty space on the screen.\n
    \n\n

    Example 3:

    \n\n
    \nInput: sentence = ["i","had","apple","pie"], rows = 4, cols = 5\nOutput: 1\nExplanation:\ni-had\napple\npie-i\nhad--\nThe character '-' signifies an empty space on the screen.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= sentence.length <= 100
    • \n\t
    • 1 <= sentence[i].length <= 10
    • \n\t
    • sentence[i] consists of lowercase English letters.
    • \n\t
    • 1 <= rows, cols <= 2 * 104
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a rows x cols \u7684\u5c4f\u5e55\u548c\u4e00\u4e2a\u7528 \u975e\u7a7a \u7684\u5355\u8bcd\u5217\u8868\u7ec4\u6210\u7684\u53e5\u5b50\uff0c\u8bf7\u4f60\u8ba1\u7b97\u51fa\u7ed9\u5b9a\u53e5\u5b50\u53ef\u4ee5\u5728\u5c4f\u5e55\u4e0a\u5b8c\u6574\u663e\u793a\u7684\u6b21\u6570\u3002

    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    1. \u4e00\u4e2a\u5355\u8bcd\u4e0d\u80fd\u62c6\u5206\u6210\u4e24\u884c\u3002
    2. \n\t
    3. \u5355\u8bcd\u5728\u53e5\u5b50\u4e2d\u7684\u987a\u5e8f\u5fc5\u987b\u4fdd\u6301\u4e0d\u53d8\u3002
    4. \n\t
    5. \u5728\u4e00\u884c\u4e2d \u7684\u4e24\u4e2a\u8fde\u7eed\u5355\u8bcd\u5fc5\u987b\u7528\u4e00\u4e2a\u7a7a\u683c\u7b26\u5206\u9694\u3002
    6. \n\t
    7. \u53e5\u5b50\u4e2d\u7684\u5355\u8bcd\u603b\u91cf\u4e0d\u4f1a\u8d85\u8fc7 100\u3002
    8. \n\t
    9. \u6bcf\u4e2a\u5355\u8bcd\u7684\u957f\u5ea6\u5927\u4e8e 0 \u4e14\u4e0d\u4f1a\u8d85\u8fc7 10\u3002
    10. \n\t
    11. 1 ≤ rows, cols ≤ 20,000.
    12. \n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a\nrows = 2, cols = 8, \u53e5\u5b50 sentence = ["hello", "world"]\n\n\u8f93\u51fa\uff1a\n1\n\n\u89e3\u91ca\uff1a\nhello---\nworld---\n\n\u5b57\u7b26 '-' \u8868\u793a\u5c4f\u5e55\u4e0a\u7684\u4e00\u4e2a\u7a7a\u767d\u4f4d\u7f6e\u3002\n
    \n\n

     

    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a\nrows = 3, cols = 6, \u53e5\u5b50 sentence = ["a", "bcd", "e"]\n\n\u8f93\u51fa\uff1a\n2\n\n\u89e3\u91ca\uff1a\na-bcd- \ne-a---\nbcd-e-\n\n\u5b57\u7b26 '-' \u8868\u793a\u5c4f\u5e55\u4e0a\u7684\u4e00\u4e2a\u7a7a\u767d\u4f4d\u7f6e\u3002\n
    \n\n

     

    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1a\nrows = 4, cols = 5, \u53e5\u5b50 sentence = ["I", "had", "apple", "pie"]\n\n\u8f93\u51fa\uff1a\n1\n\n\u89e3\u91ca\uff1a\nI-had\napple\npie-I\nhad--\n\n\u5b57\u7b26 '-' \u8868\u793a\u5c4f\u5e55\u4e0a\u7684\u4e00\u4e2a\u7a7a\u767d\u4f4d\u7f6e\u3002\n
    \n\n

     

    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int wordsTyping(vector& sentence, int rows, int cols) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int wordsTyping(String[] sentence, int rows, int cols) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def wordsTyping(self, sentence, rows, cols):\n \"\"\"\n :type sentence: List[str]\n :type rows: int\n :type cols: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def wordsTyping(self, sentence: List[str], rows: int, cols: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint wordsTyping(char ** sentence, int sentenceSize, int rows, int cols){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int WordsTyping(string[] sentence, int rows, int cols) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} sentence\n * @param {number} rows\n * @param {number} cols\n * @return {number}\n */\nvar wordsTyping = function(sentence, rows, cols) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} sentence\n# @param {Integer} rows\n# @param {Integer} cols\n# @return {Integer}\ndef words_typing(sentence, rows, cols)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func wordsTyping(_ sentence: [String], _ rows: Int, _ cols: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func wordsTyping(sentence []string, rows int, cols int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def wordsTyping(sentence: Array[String], rows: Int, cols: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun wordsTyping(sentence: Array, rows: Int, cols: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn words_typing(sentence: Vec, rows: i32, cols: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $sentence\n * @param Integer $rows\n * @param Integer $cols\n * @return Integer\n */\n function wordsTyping($sentence, $rows, $cols) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function wordsTyping(sentence: string[], rows: number, cols: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (words-typing sentence rows cols)\n (-> (listof string?) exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0418](https://leetcode-cn.com/problems/sentence-screen-fitting)", "[\u5c4f\u5e55\u53ef\u663e\u793a\u53e5\u5b50\u7684\u6570\u91cf](/solution/0400-0499/0418.Sentence%20Screen%20Fitting/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0418](https://leetcode.com/problems/sentence-screen-fitting)", "[Sentence Screen Fitting](/solution/0400-0499/0418.Sentence%20Screen%20Fitting/README_EN.md)", "`Dynamic Programming`", "Medium", "\ud83d\udd12"]}, {"question_id": "0417", "frontend_question_id": "0417", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/pacific-atlantic-water-flow", "url_en": "https://leetcode.com/problems/pacific-atlantic-water-flow", "relative_path_cn": "/solution/0400-0499/0417.Pacific%20Atlantic%20Water%20Flow/README.md", "relative_path_en": "/solution/0400-0499/0417.Pacific%20Atlantic%20Water%20Flow/README_EN.md", "title_cn": "\u592a\u5e73\u6d0b\u5927\u897f\u6d0b\u6c34\u6d41\u95ee\u9898", "title_en": "Pacific Atlantic Water Flow", "question_title_slug": "pacific-atlantic-water-flow", "content_en": "

    You are given an m x n integer matrix heights representing the height of each unit cell in a continent. The Pacific ocean touches the continent's left and top edges, and the Atlantic ocean touches the continent's right and bottom edges.

    \n\n

    Water can only flow in four directions: up, down, left, and right. Water flows from a cell to an adjacent one with an equal or lower height.

    \n\n

    Return a list of grid coordinates where water can flow to both the Pacific and Atlantic oceans.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: heights = [[1,2,2,3,5],[3,2,3,4,4],[2,4,5,3,1],[6,7,1,4,5],[5,1,1,2,4]]\nOutput: [[0,4],[1,3],[1,4],[2,2],[3,0],[3,1],[4,0]]\n
    \n\n

    Example 2:

    \n\n
    \nInput: heights = [[2,1],[1,2]]\nOutput: [[0,0],[0,1],[1,0],[1,1]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == heights.length
    • \n\t
    • n == heights[i].length
    • \n\t
    • 1 <= m, n <= 200
    • \n\t
    • 0 <= heights[i][j] <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a m x n \u7684\u975e\u8d1f\u6574\u6570\u77e9\u9635\u6765\u8868\u793a\u4e00\u7247\u5927\u9646\u4e0a\u5404\u4e2a\u5355\u5143\u683c\u7684\u9ad8\u5ea6\u3002“\u592a\u5e73\u6d0b”\u5904\u4e8e\u5927\u9646\u7684\u5de6\u8fb9\u754c\u548c\u4e0a\u8fb9\u754c\uff0c\u800c“\u5927\u897f\u6d0b”\u5904\u4e8e\u5927\u9646\u7684\u53f3\u8fb9\u754c\u548c\u4e0b\u8fb9\u754c\u3002

    \n\n

    \u89c4\u5b9a\u6c34\u6d41\u53ea\u80fd\u6309\u7167\u4e0a\u3001\u4e0b\u3001\u5de6\u3001\u53f3\u56db\u4e2a\u65b9\u5411\u6d41\u52a8\uff0c\u4e14\u53ea\u80fd\u4ece\u9ad8\u5230\u4f4e\u6216\u8005\u5728\u540c\u7b49\u9ad8\u5ea6\u4e0a\u6d41\u52a8\u3002

    \n\n

    \u8bf7\u627e\u51fa\u90a3\u4e9b\u6c34\u6d41\u65e2\u53ef\u4ee5\u6d41\u52a8\u5230“\u592a\u5e73\u6d0b”\uff0c\u53c8\u80fd\u6d41\u52a8\u5230“\u5927\u897f\u6d0b”\u7684\u9646\u5730\u5355\u5143\u7684\u5750\u6807\u3002

    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. \u8f93\u51fa\u5750\u6807\u7684\u987a\u5e8f\u4e0d\u91cd\u8981
    2. \n\t
    3. m \u548c n \u90fd\u5c0f\u4e8e150
    4. \n
    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n

     

    \n\n
    \n\u7ed9\u5b9a\u4e0b\u9762\u7684 5x5 \u77e9\u9635:\n\n  \u592a\u5e73\u6d0b ~   ~   ~   ~   ~ \n       ~  1   2   2   3  (5) *\n       ~  3   2   3  (4) (4) *\n       ~  2   4  (5)  3   1  *\n       ~ (6) (7)  1   4   5  *\n       ~ (5)  1   1   2   4  *\n          *   *   *   *   * \u5927\u897f\u6d0b\n\n\u8fd4\u56de:\n\n[[0, 4], [1, 3], [1, 4], [2, 2], [3, 0], [3, 1], [4, 0]] (\u4e0a\u56fe\u4e2d\u5e26\u62ec\u53f7\u7684\u5355\u5143).\n
    \n\n

     

    \n", "tags_en": ["Depth-first Search", "Breadth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> pacificAtlantic(vector>& heights) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> pacificAtlantic(int[][] heights) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def pacificAtlantic(self, heights):\n \"\"\"\n :type heights: List[List[int]]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def pacificAtlantic(self, heights: List[List[int]]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** pacificAtlantic(int** heights, int heightsSize, int* heightsColSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> PacificAtlantic(int[][] heights) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} heights\n * @return {number[][]}\n */\nvar pacificAtlantic = function(heights) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} heights\n# @return {Integer[][]}\ndef pacific_atlantic(heights)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func pacificAtlantic(_ heights: [[Int]]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func pacificAtlantic(heights [][]int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def pacificAtlantic(heights: Array[Array[Int]]): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun pacificAtlantic(heights: Array): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn pacific_atlantic(heights: Vec>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $heights\n * @return Integer[][]\n */\n function pacificAtlantic($heights) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function pacificAtlantic(heights: number[][]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (pacific-atlantic heights)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0417](https://leetcode-cn.com/problems/pacific-atlantic-water-flow)", "[\u592a\u5e73\u6d0b\u5927\u897f\u6d0b\u6c34\u6d41\u95ee\u9898](/solution/0400-0499/0417.Pacific%20Atlantic%20Water%20Flow/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0417](https://leetcode.com/problems/pacific-atlantic-water-flow)", "[Pacific Atlantic Water Flow](/solution/0400-0499/0417.Pacific%20Atlantic%20Water%20Flow/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`", "Medium", ""]}, {"question_id": "0416", "frontend_question_id": "0416", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/partition-equal-subset-sum", "url_en": "https://leetcode.com/problems/partition-equal-subset-sum", "relative_path_cn": "/solution/0400-0499/0416.Partition%20Equal%20Subset%20Sum/README.md", "relative_path_en": "/solution/0400-0499/0416.Partition%20Equal%20Subset%20Sum/README_EN.md", "title_cn": "\u5206\u5272\u7b49\u548c\u5b50\u96c6", "title_en": "Partition Equal Subset Sum", "question_title_slug": "partition-equal-subset-sum", "content_en": "

    Given a non-empty array nums containing only positive integers, find if the array can be partitioned into two subsets such that the sum of elements in both subsets is equal.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,5,11,5]\nOutput: true\nExplanation: The array can be partitioned as [1, 5, 5] and [11].\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,2,3,5]\nOutput: false\nExplanation: The array cannot be partitioned into equal sum subsets.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 200
    • \n\t
    • 1 <= nums[i] <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a \u53ea\u5305\u542b\u6b63\u6574\u6570 \u7684 \u975e\u7a7a \u6570\u7ec4\u00a0nums \u3002\u8bf7\u4f60\u5224\u65ad\u662f\u5426\u53ef\u4ee5\u5c06\u8fd9\u4e2a\u6570\u7ec4\u5206\u5272\u6210\u4e24\u4e2a\u5b50\u96c6\uff0c\u4f7f\u5f97\u4e24\u4e2a\u5b50\u96c6\u7684\u5143\u7d20\u548c\u76f8\u7b49\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,5,11,5]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u6570\u7ec4\u53ef\u4ee5\u5206\u5272\u6210 [1, 5, 5] \u548c [11] \u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,3,5]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u6570\u7ec4\u4e0d\u80fd\u5206\u5272\u6210\u4e24\u4e2a\u5143\u7d20\u548c\u76f8\u7b49\u7684\u5b50\u96c6\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 200
    • \n\t
    • 1 <= nums[i] <= 100
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canPartition(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canPartition(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canPartition(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canPartition(self, nums: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canPartition(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanPartition(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {boolean}\n */\nvar canPartition = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Boolean}\ndef can_partition(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canPartition(_ nums: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canPartition(nums []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canPartition(nums: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canPartition(nums: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_partition(nums: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Boolean\n */\n function canPartition($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canPartition(nums: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-partition nums)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0416](https://leetcode-cn.com/problems/partition-equal-subset-sum)", "[\u5206\u5272\u7b49\u548c\u5b50\u96c6](/solution/0400-0499/0416.Partition%20Equal%20Subset%20Sum/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0416](https://leetcode.com/problems/partition-equal-subset-sum)", "[Partition Equal Subset Sum](/solution/0400-0499/0416.Partition%20Equal%20Subset%20Sum/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0415", "frontend_question_id": "0415", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/add-strings", "url_en": "https://leetcode.com/problems/add-strings", "relative_path_cn": "/solution/0400-0499/0415.Add%20Strings/README.md", "relative_path_en": "/solution/0400-0499/0415.Add%20Strings/README_EN.md", "title_cn": "\u5b57\u7b26\u4e32\u76f8\u52a0", "title_en": "Add Strings", "question_title_slug": "add-strings", "content_en": "

    Given two non-negative integers, num1 and num2 represented as string, return the sum of num1 and num2 as a string.

    \n\n

    You must solve the problem without using any built-in library for handling large integers (such as BigInteger). You must also not convert the inputs to integers directly.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: num1 = "11", num2 = "123"\nOutput: "134"\n
    \n\n

    Example 2:

    \n\n
    \nInput: num1 = "456", num2 = "77"\nOutput: "533"\n
    \n\n

    Example 3:

    \n\n
    \nInput: num1 = "0", num2 = "0"\nOutput: "0"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= num1.length, num2.length <= 104
    • \n\t
    • num1 and num2 consist of only digits.
    • \n\t
    • num1 and num2 don't have any leading zeros except for the zero itself.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u5b57\u7b26\u4e32\u5f62\u5f0f\u7684\u975e\u8d1f\u6574\u6570 num1 \u548cnum2 \uff0c\u8ba1\u7b97\u5b83\u4eec\u7684\u548c\u3002

    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. num1 \u548cnum2 \u7684\u957f\u5ea6\u90fd\u5c0f\u4e8e 5100
    2. \n\t
    3. num1 \u548cnum2 \u90fd\u53ea\u5305\u542b\u6570\u5b57 0-9
    4. \n\t
    5. num1 \u548cnum2 \u90fd\u4e0d\u5305\u542b\u4efb\u4f55\u524d\u5bfc\u96f6
    6. \n\t
    7. \u4f60\u4e0d\u80fd\u4f7f\u7528\u4efb\u4f55\u5167\u5efa BigInteger \u5e93\uff0c \u4e5f\u4e0d\u80fd\u76f4\u63a5\u5c06\u8f93\u5165\u7684\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u6574\u6570\u5f62\u5f0f
    8. \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string addStrings(string num1, string num2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String addStrings(String num1, String num2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def addStrings(self, num1, num2):\n \"\"\"\n :type num1: str\n :type num2: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def addStrings(self, num1: str, num2: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * addStrings(char * num1, char * num2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string AddStrings(string num1, string num2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} num1\n * @param {string} num2\n * @return {string}\n */\nvar addStrings = function(num1, num2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} num1\n# @param {String} num2\n# @return {String}\ndef add_strings(num1, num2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func addStrings(_ num1: String, _ num2: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func addStrings(num1 string, num2 string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def addStrings(num1: String, num2: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun addStrings(num1: String, num2: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn add_strings(num1: String, num2: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $num1\n * @param String $num2\n * @return String\n */\n function addStrings($num1, $num2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function addStrings(num1: string, num2: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (add-strings num1 num2)\n (-> string? string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0415](https://leetcode-cn.com/problems/add-strings)", "[\u5b57\u7b26\u4e32\u76f8\u52a0](/solution/0400-0499/0415.Add%20Strings/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0415](https://leetcode.com/problems/add-strings)", "[Add Strings](/solution/0400-0499/0415.Add%20Strings/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "0414", "frontend_question_id": "0414", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/third-maximum-number", "url_en": "https://leetcode.com/problems/third-maximum-number", "relative_path_cn": "/solution/0400-0499/0414.Third%20Maximum%20Number/README.md", "relative_path_en": "/solution/0400-0499/0414.Third%20Maximum%20Number/README_EN.md", "title_cn": "\u7b2c\u4e09\u5927\u7684\u6570", "title_en": "Third Maximum Number", "question_title_slug": "third-maximum-number", "content_en": "

    Given integer array nums, return the third maximum number in this array. If the third maximum does not exist, return the maximum number.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [3,2,1]\nOutput: 1\nExplanation: The third maximum is 1.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,2]\nOutput: 2\nExplanation: The third maximum does not exist, so the maximum (2) is returned instead.\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [2,2,3,1]\nOutput: 1\nExplanation: Note that the third maximum here means the third maximum distinct number.\nBoth numbers with value 2 are both considered as second maximum.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 104
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n
    \n\n

     

    \nFollow up: Can you find an O(n) solution?", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u975e\u7a7a\u6570\u7ec4\uff0c\u8fd4\u56de\u6b64\u6570\u7ec4\u4e2d \u7b2c\u4e09\u5927\u7684\u6570 \u3002\u5982\u679c\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u6570\u7ec4\u4e2d\u6700\u5927\u7684\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[3, 2, 1]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u7b2c\u4e09\u5927\u7684\u6570\u662f 1 \u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[1, 2]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u7b2c\u4e09\u5927\u7684\u6570\u4e0d\u5b58\u5728, \u6240\u4ee5\u8fd4\u56de\u6700\u5927\u7684\u6570 2 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[2, 2, 3, 1]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u6ce8\u610f\uff0c\u8981\u6c42\u8fd4\u56de\u7b2c\u4e09\u5927\u7684\u6570\uff0c\u662f\u6307\u5728\u6240\u6709\u4e0d\u540c\u6570\u5b57\u4e2d\u6392\u7b2c\u4e09\u5927\u7684\u6570\u3002\n\u6b64\u4f8b\u4e2d\u5b58\u5728\u4e24\u4e2a\u503c\u4e3a 2 \u7684\u6570\uff0c\u5b83\u4eec\u90fd\u6392\u7b2c\u4e8c\u3002\u5728\u6240\u6709\u4e0d\u540c\u6570\u5b57\u4e2d\u6392\u7b2c\u4e09\u5927\u7684\u6570\u4e3a 1 \u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 104
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u80fd\u8bbe\u8ba1\u4e00\u4e2a\u65f6\u95f4\u590d\u6742\u5ea6 O(n) \u7684\u89e3\u51b3\u65b9\u6848\u5417\uff1f

    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int thirdMax(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int thirdMax(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def thirdMax(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def thirdMax(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint thirdMax(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ThirdMax(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar thirdMax = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef third_max(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func thirdMax(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func thirdMax(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def thirdMax(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun thirdMax(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn third_max(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function thirdMax($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function thirdMax(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (third-max nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0414](https://leetcode-cn.com/problems/third-maximum-number)", "[\u7b2c\u4e09\u5927\u7684\u6570](/solution/0400-0499/0414.Third%20Maximum%20Number/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0414](https://leetcode.com/problems/third-maximum-number)", "[Third Maximum Number](/solution/0400-0499/0414.Third%20Maximum%20Number/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0413", "frontend_question_id": "0413", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/arithmetic-slices", "url_en": "https://leetcode.com/problems/arithmetic-slices", "relative_path_cn": "/solution/0400-0499/0413.Arithmetic%20Slices/README.md", "relative_path_en": "/solution/0400-0499/0413.Arithmetic%20Slices/README_EN.md", "title_cn": "\u7b49\u5dee\u6570\u5217\u5212\u5206", "title_en": "Arithmetic Slices", "question_title_slug": "arithmetic-slices", "content_en": "

    An integer array is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.

    \n\n
      \n\t
    • For example, [1,3,5,7,9], [7,7,7,7], and [3,-1,-5,-9] are arithmetic sequences.
    • \n
    \n\n

    Given an integer array nums, return the number of arithmetic subarrays of nums.

    \n\n

    A subarray is a contiguous subsequence of the array.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,3,4]\nOutput: 3\nExplanation: We have 3 arithmetic slices in nums: [1, 2, 3], [2, 3, 4] and [1,2,3,4] itself.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 5000
    • \n\t
    • -1000 <= nums[i] <= 1000
    • \n
    \n", "content_cn": "

    \u5982\u679c\u4e00\u4e2a\u6570\u5217\u81f3\u5c11\u6709\u4e09\u4e2a\u5143\u7d20\uff0c\u5e76\u4e14\u4efb\u610f\u4e24\u4e2a\u76f8\u90bb\u5143\u7d20\u4e4b\u5dee\u76f8\u540c\uff0c\u5219\u79f0\u8be5\u6570\u5217\u4e3a\u7b49\u5dee\u6570\u5217\u3002

    \n\n

    \u4f8b\u5982\uff0c\u4ee5\u4e0b\u6570\u5217\u4e3a\u7b49\u5dee\u6570\u5217:

    \n\n
    \n1, 3, 5, 7, 9\n7, 7, 7, 7\n3, -1, -5, -9
    \n\n

    \u4ee5\u4e0b\u6570\u5217\u4e0d\u662f\u7b49\u5dee\u6570\u5217\u3002

    \n\n
    \n1, 1, 2, 5, 7
    \n\n

     

    \n\n

    \u6570\u7ec4 A \u5305\u542b N \u4e2a\u6570\uff0c\u4e14\u7d22\u5f15\u4ece0\u5f00\u59cb\u3002\u6570\u7ec4 A \u7684\u4e00\u4e2a\u5b50\u6570\u7ec4\u5212\u5206\u4e3a\u6570\u7ec4 (P, Q)\uff0cP \u4e0e Q \u662f\u6574\u6570\u4e14\u6ee1\u8db3 0<=P<Q<N \u3002

    \n\n

    \u5982\u679c\u6ee1\u8db3\u4ee5\u4e0b\u6761\u4ef6\uff0c\u5219\u79f0\u5b50\u6570\u7ec4(P, Q)\u4e3a\u7b49\u5dee\u6570\u7ec4\uff1a

    \n\n

    \u5143\u7d20 A[P], A[p + 1], ..., A[Q - 1], A[Q] \u662f\u7b49\u5dee\u7684\u3002\u5e76\u4e14 P + 1 < Q \u3002

    \n\n

    \u51fd\u6570\u8981\u8fd4\u56de\u6570\u7ec4 A \u4e2d\u6240\u6709\u4e3a\u7b49\u5dee\u6570\u7ec4\u7684\u5b50\u6570\u7ec4\u4e2a\u6570\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b:

    \n\n
    \nA = [1, 2, 3, 4]\n\n\u8fd4\u56de: 3, A \u4e2d\u6709\u4e09\u4e2a\u5b50\u7b49\u5dee\u6570\u7ec4: [1, 2, 3], [2, 3, 4] \u4ee5\u53ca\u81ea\u8eab [1, 2, 3, 4]\u3002\n
    \n", "tags_en": ["Math", "Dynamic Programming"], "tags_cn": ["\u6570\u5b66", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numberOfArithmeticSlices(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numberOfArithmeticSlices(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numberOfArithmeticSlices(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numberOfArithmeticSlices(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numberOfArithmeticSlices(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumberOfArithmeticSlices(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar numberOfArithmeticSlices = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef number_of_arithmetic_slices(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numberOfArithmeticSlices(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numberOfArithmeticSlices(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numberOfArithmeticSlices(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numberOfArithmeticSlices(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn number_of_arithmetic_slices(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function numberOfArithmeticSlices($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numberOfArithmeticSlices(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (number-of-arithmetic-slices nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0413](https://leetcode-cn.com/problems/arithmetic-slices)", "[\u7b49\u5dee\u6570\u5217\u5212\u5206](/solution/0400-0499/0413.Arithmetic%20Slices/README.md)", "`\u6570\u5b66`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0413](https://leetcode.com/problems/arithmetic-slices)", "[Arithmetic Slices](/solution/0400-0499/0413.Arithmetic%20Slices/README_EN.md)", "`Math`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0412", "frontend_question_id": "0412", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/fizz-buzz", "url_en": "https://leetcode.com/problems/fizz-buzz", "relative_path_cn": "/solution/0400-0499/0412.Fizz%20Buzz/README.md", "relative_path_en": "/solution/0400-0499/0412.Fizz%20Buzz/README_EN.md", "title_cn": "Fizz Buzz", "title_en": "Fizz Buzz", "question_title_slug": "fizz-buzz", "content_en": "

    Given an integer n, return a string array answer (1-indexed) where:

    \n\n
      \n\t
    • answer[i] == "FizzBuzz" if i is divisible by 3 and 5.
    • \n\t
    • answer[i] == "Fizz" if i is divisible by 3.
    • \n\t
    • answer[i] == "Buzz" if i is divisible by 5.
    • \n\t
    • answer[i] == i if non of the above conditions are true.
    • \n
    \n\n

     

    \n

    Example 1:

    \n
    Input: n = 3\nOutput: [\"1\",\"2\",\"Fizz\"]\n

    Example 2:

    \n
    Input: n = 5\nOutput: [\"1\",\"2\",\"Fizz\",\"4\",\"Buzz\"]\n

    Example 3:

    \n
    Input: n = 15\nOutput: [\"1\",\"2\",\"Fizz\",\"4\",\"Buzz\",\"Fizz\",\"7\",\"8\",\"Fizz\",\"Buzz\",\"11\",\"Fizz\",\"13\",\"14\",\"FizzBuzz\"]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 104
    • \n
    \n", "content_cn": "

    \u5199\u4e00\u4e2a\u7a0b\u5e8f\uff0c\u8f93\u51fa\u4ece 1 \u5230 n \u6570\u5b57\u7684\u5b57\u7b26\u4e32\u8868\u793a\u3002

    \n\n

    1. \u5982\u679c \u662f3\u7684\u500d\u6570\uff0c\u8f93\u51fa“Fizz”\uff1b

    \n\n

    2. \u5982\u679c \u662f5\u7684\u500d\u6570\uff0c\u8f93\u51fa“Buzz”\uff1b

    \n\n

    3.\u5982\u679c \u540c\u65f6\u662f3\u548c5\u7684\u500d\u6570\uff0c\u8f93\u51fa “FizzBuzz”\u3002

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    n = 15,\n\n\u8fd4\u56de:\n[\n    "1",\n    "2",\n    "Fizz",\n    "4",\n    "Buzz",\n    "Fizz",\n    "7",\n    "8",\n    "Fizz",\n    "Buzz",\n    "11",\n    "Fizz",\n    "13",\n    "14",\n    "FizzBuzz"\n]\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector fizzBuzz(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List fizzBuzz(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def fizzBuzz(self, n):\n \"\"\"\n :type n: int\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def fizzBuzz(self, n: int) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** fizzBuzz(int n, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList FizzBuzz(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {string[]}\n */\nvar fizzBuzz = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {String[]}\ndef fizz_buzz(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func fizzBuzz(_ n: Int) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func fizzBuzz(n int) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def fizzBuzz(n: Int): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun fizzBuzz(n: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn fizz_buzz(n: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return String[]\n */\n function fizzBuzz($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function fizzBuzz(n: number): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (fizz-buzz n)\n (-> exact-integer? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0412](https://leetcode-cn.com/problems/fizz-buzz)", "[Fizz Buzz](/solution/0400-0499/0412.Fizz%20Buzz/README.md)", "", "\u7b80\u5355", ""], "md_table_row_en": ["[0412](https://leetcode.com/problems/fizz-buzz)", "[Fizz Buzz](/solution/0400-0499/0412.Fizz%20Buzz/README_EN.md)", "", "Easy", ""]}, {"question_id": "0411", "frontend_question_id": "0411", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/minimum-unique-word-abbreviation", "url_en": "https://leetcode.com/problems/minimum-unique-word-abbreviation", "relative_path_cn": "/solution/0400-0499/0411.Minimum%20Unique%20Word%20Abbreviation/README.md", "relative_path_en": "/solution/0400-0499/0411.Minimum%20Unique%20Word%20Abbreviation/README_EN.md", "title_cn": "\u6700\u77ed\u72ec\u5360\u5355\u8bcd\u7f29\u5199", "title_en": "Minimum Unique Word Abbreviation", "question_title_slug": "minimum-unique-word-abbreviation", "content_en": "

    A string can be abbreviated by replacing any number of non-adjacent substrings with their lengths. For example, a string such as "substitution" could be abbreviated as (but not limited to):

    \n\n
      \n\t
    • "s10n" ("s ubstitutio n")
    • \n\t
    • "sub4u4" ("sub stit u tion")
    • \n\t
    • "12" ("substitution")
    • \n\t
    • "su3i1u2on" ("su bst i t u ti on")
    • \n\t
    • "substitution" (no substrings replaced)
    • \n
    \n\n

    Note that "s55n" ("s ubsti tutio n") is not a valid abbreviation of "substitution" because the replaced substrings are adjacent.

    \n\n

    The length of an abbreviation is the number of letters that were not replaced plus the number of substrings that were replaced. For example, the abbreviation "s10n" has a length of 3 (2 letters + 1 substring) and "su3i1u2on" has a length of 9 (6 letters + 3 substrings).

    \n\n

    Given a target string target and an array of strings dictionary, return an abbreviation of target with the shortest possible length such that it is not an abbreviation of any string in dictionary. If there are multiple shortest abbreviations, return any of them.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: target = "apple", dictionary = ["blade"]\nOutput: "a4"\nExplanation: The shortest abbreviation of "apple" is "5", but this is also an abbreviation of "blade".\nThe next shortest abbreviations are "a4" and "4e". "4e" is an abbreviation of blade while "a4" is not.\nHence, return "a4".\n
    \n\n

    Example 2:

    \n\n
    \nInput: target = "apple", dictionary = ["blade","plain","amber"]\nOutput: "1p3"\nExplanation: "5" is an abbreviation of both "apple" but also every word in the dictionary.\n"a4" is an abbreviation of "apple" but also "amber".\n"4e" is an abbreviation of "apple" but also "blade".\n"1p3", "2p2", and "3l1" are the next shortest abbreviations of "apple".\nSince none of them are abbreviations of words in the dictionary, returning any of them is correct.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • target.length == m
    • \n\t
    • dictionary.length == n
    • \n\t
    • 1 <= m <= 21
    • \n\t
    • 0 <= n <= 1000
    • \n\t
    • 1 <= dictionary[i] <= 100
    • \n\t
    • log2(n) + m <= 21 if n > 0
    • \n
    \n", "content_cn": "

    \u901a\u8fc7\u5c06\u4efb\u610f\u6570\u91cf\u7684 \u4e0d\u76f8\u90bb \u5b50\u5b57\u7b26\u4e32\u66ff\u6362\u4e3a\u5b83\u4eec\u7684\u957f\u5ea6\uff0c\u53ef\u4ee5\u5b8c\u6210\u5bf9\u5b57\u7b26\u4e32\u7684 \u7f29\u5199 \u3002 \u4f8b\u5982\uff0c\u50cf \"substitution\" \u8fd9\u6837\u7684\u5b57\u7b26\u4e32\u53ef\u4ee5\u7f29\u5199\u4e3a\uff08\u4f46\u4e0d\u9650\u4e8e\uff09\uff1a

    \n\n
      \n\t
    • \"s10n\" (\"s ubstitutio n\")
    • \n\t
    • \"sub4u4\" (\"sub stit u tion\")
    • \n\t
    • \"12\" (\"substitution\")
    • \n\t
    • \"su3i1u2on\" (\"su bst i t u ti on\")
    • \n\t
    • \"substitution\" (\u4e0d\u66ff\u6362\u5b50\u5b57\u7b26\u4e32)
    • \n
    \n\n

    \u6ce8\u610f\uff1a\"s55n\" (\"s ubsti tutio n\") \u4e0d\u662f\u00a0\"substitution\" \u7684\u6709\u6548\u7f29\u5199\u5f62\u5f0f\uff0c\u56e0\u4e3a\u5b83\u8bd5\u56fe\u66ff\u6362\u4e24\u4e2a\u76f8\u90bb\u7684\u5b50\u5b57\u7b26\u4e32\u3002

    \n\n

    \u7f29\u5199\u7684 \u957f\u5ea6 \u662f\u672a\u88ab\u66ff\u6362\u7684\u5b57\u6bcd\u6570\u52a0\u4e0a\u88ab\u66ff\u6362\u7684\u5b57\u7b26\u4e32\u6570\u3002\u4f8b\u5982\uff0c\u7f29\u5199 \"s10n\" \u7684\u957f\u5ea6\u4e3a 3\uff082 \u4e2a\u5b57\u6bcd + 1 \u4e2a\u5b50\u5b57\u7b26\u4e32\uff09\uff0c\u800c \"su3i1u2on\" \u7684\u957f\u5ea6\u4e3a 9\uff086 \u4e2a\u5b57\u6bcd + 3 \u5b50\u5b57\u7b26\u4e32\uff09\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u76ee\u6807\u5b57\u7b26\u4e32 target \u548c\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4 dictionary \u4f5c\u4e3a\u5b57\u5178\uff0c\u4e3a target \u627e\u51fa\u5e76\u8fd4\u56de\u4e00\u4e2a\u00a0\u6700\u77ed \u957f\u5ea6\u7684\u7f29\u5199\u5b57\u7b26\u4e32\uff0c\u540c\u65f6\u8fd9\u4e2a\u7f29\u5199\u5b57\u7b26\u4e32 \u4e0d\u662f \u5b57\u5178\u00a0dictionary \u4e2d\u5176\u4ed6\u5b57\u7b26\u4e32\u7684\u7f29\u5199\u5f62\u5f0f\u3002\u5982\u679c\u6709\u591a\u4e2a\u6709\u6548\u7b54\u6848\uff0c\u53ef\u4ee5\u8fd4\u56de\u5176\u4e2d\u4efb\u610f\u4e00\u4e2a\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1atarget = \"apple\", dictionary = [\"blade\"]\n\u8f93\u51fa\uff1a\"a4\"\n\u89e3\u91ca\uff1a\"apple\" \u7684\u6700\u77ed\u7f29\u5199\u5f62\u5f0f\u4e3a \"5\" \uff0c\u4f46\u8fd9\u4e5f\u662f \"blade\" \u7684\u7f29\u5199\u5f62\u5f0f\u4e4b\u4e00\u3002\n\u4e0b\u4e00\u7ec4\u6700\u77ed\u7f29\u5199\u662f \"a4\" \u548c \"4e\" \uff0c\u5176\u4e2d \"4e\" \u4e5f\u662f \"blade\" \u7684\u7f29\u5199\u5f62\u5f0f\u4e4b\u4e00\uff0c\u800c \"a4\" \u4e0d\u662f\u3002\n\u56e0\u6b64\uff0c\u8fd4\u56de \"a4\" \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1atarget = \"apple\", dictionary = [\"blade\",\"plain\",\"amber\"]\n\u8f93\u51fa\uff1a\"1p3\"\n\u89e3\u91ca\uff1a\"5\" \u540c\u65f6\u662f \"apple\" \u548c\u5b57\u5178\u4e2d\u6240\u6709\u5355\u8bcd\u7684\u7f29\u5199\u5f62\u5f0f\u3002\n\"a4\" \u540c\u65f6\u662f \"apple\" \u548c \"amber\" \u7684\u7f29\u5199\u5f62\u5f0f\u3002\n\"4e\" \u540c\u65f6\u662f \"apple\" \u548c \"blade\" \u7684\u7f29\u5199\u5f62\u5f0f\u3002\n\"1p3\"\u3001\"2p2\" \u548c \"3l1\" \u662f \"apple\" \u7684\u4e0b\u4e00\u7ec4\u6700\u77ed\u7f29\u5199\u5f62\u5f0f\u3002\n\u56e0\u4e3a\u5b83\u4eec\u4e0d\u662f\u5b57\u5178\u4e2d\u5176\u4ed6\u5355\u8bcd\u7684\u7f29\u5199\u5f62\u5f0f\uff0c\u8fd4\u56de\u5176\u4e2d\u4efb\u610f\u4e00\u4e2a\u90fd\u662f\u6b63\u786e\u7684\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • target.length == m
    • \n\t
    • dictionary.length == n
    • \n\t
    • 1 <= m <= 21
    • \n\t
    • 0 <= n <= 1000
    • \n\t
    • 1 <= dictionary[i] <= 100
    • \n\t
    • \u5982\u679c n > 0 \uff0c\u90a3\u4e48 log2(n) + m <= 21
    • \n
    \n\n

    \u00a0

    \n", "tags_en": ["Bit Manipulation", "Backtracking"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string minAbbreviation(string target, vector& dictionary) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String minAbbreviation(String target, String[] dictionary) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minAbbreviation(self, target, dictionary):\n \"\"\"\n :type target: str\n :type dictionary: List[str]\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minAbbreviation(self, target: str, dictionary: List[str]) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * minAbbreviation(char * target, char ** dictionary, int dictionarySize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string MinAbbreviation(string target, string[] dictionary) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} target\n * @param {string[]} dictionary\n * @return {string}\n */\nvar minAbbreviation = function(target, dictionary) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} target\n# @param {String[]} dictionary\n# @return {String}\ndef min_abbreviation(target, dictionary)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minAbbreviation(_ target: String, _ dictionary: [String]) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minAbbreviation(target string, dictionary []string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minAbbreviation(target: String, dictionary: Array[String]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minAbbreviation(target: String, dictionary: Array): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_abbreviation(target: String, dictionary: Vec) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $target\n * @param String[] $dictionary\n * @return String\n */\n function minAbbreviation($target, $dictionary) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minAbbreviation(target: string, dictionary: string[]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-abbreviation target dictionary)\n (-> string? (listof string?) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0411](https://leetcode-cn.com/problems/minimum-unique-word-abbreviation)", "[\u6700\u77ed\u72ec\u5360\u5355\u8bcd\u7f29\u5199](/solution/0400-0499/0411.Minimum%20Unique%20Word%20Abbreviation/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u56de\u6eaf\u7b97\u6cd5`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0411](https://leetcode.com/problems/minimum-unique-word-abbreviation)", "[Minimum Unique Word Abbreviation](/solution/0400-0499/0411.Minimum%20Unique%20Word%20Abbreviation/README_EN.md)", "`Bit Manipulation`,`Backtracking`", "Hard", "\ud83d\udd12"]}, {"question_id": "0410", "frontend_question_id": "0410", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/split-array-largest-sum", "url_en": "https://leetcode.com/problems/split-array-largest-sum", "relative_path_cn": "/solution/0400-0499/0410.Split%20Array%20Largest%20Sum/README.md", "relative_path_en": "/solution/0400-0499/0410.Split%20Array%20Largest%20Sum/README_EN.md", "title_cn": "\u5206\u5272\u6570\u7ec4\u7684\u6700\u5927\u503c", "title_en": "Split Array Largest Sum", "question_title_slug": "split-array-largest-sum", "content_en": "

    Given an array nums which consists of non-negative integers and an integer m, you can split the array into m non-empty continuous subarrays.

    \n\n

    Write an algorithm to minimize the largest sum among these m subarrays.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [7,2,5,10,8], m = 2\nOutput: 18\nExplanation:\nThere are four ways to split nums into two subarrays.\nThe best way is to split it into [7,2,5] and [10,8],\nwhere the largest sum among the two subarrays is only 18.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,2,3,4,5], m = 2\nOutput: 9\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [1,4,4], m = 3\nOutput: 4\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 1000
    • \n\t
    • 0 <= nums[i] <= 106
    • \n\t
    • 1 <= m <= min(50, nums.length)
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\u6570\u7ec4 nums \u548c\u4e00\u4e2a\u6574\u6570\u00a0m \uff0c\u4f60\u9700\u8981\u5c06\u8fd9\u4e2a\u6570\u7ec4\u5206\u6210\u00a0m\u00a0\u4e2a\u975e\u7a7a\u7684\u8fde\u7eed\u5b50\u6570\u7ec4\u3002

    \n\n

    \u8bbe\u8ba1\u4e00\u4e2a\u7b97\u6cd5\u4f7f\u5f97\u8fd9\u00a0m\u00a0\u4e2a\u5b50\u6570\u7ec4\u5404\u81ea\u548c\u7684\u6700\u5927\u503c\u6700\u5c0f\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [7,2,5,10,8], m = 2\n\u8f93\u51fa\uff1a18\n\u89e3\u91ca\uff1a\n\u4e00\u5171\u6709\u56db\u79cd\u65b9\u6cd5\u5c06 nums \u5206\u5272\u4e3a 2 \u4e2a\u5b50\u6570\u7ec4\u3002 \u5176\u4e2d\u6700\u597d\u7684\u65b9\u5f0f\u662f\u5c06\u5176\u5206\u4e3a [7,2,5] \u548c [10,8] \u3002\n\u56e0\u4e3a\u6b64\u65f6\u8fd9\u4e24\u4e2a\u5b50\u6570\u7ec4\u5404\u81ea\u7684\u548c\u7684\u6700\u5927\u503c\u4e3a18\uff0c\u5728\u6240\u6709\u60c5\u51b5\u4e2d\u6700\u5c0f\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,3,4,5], m = 2\n\u8f93\u51fa\uff1a9\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,4,4], m = 3\n\u8f93\u51fa\uff1a4\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 1000
    • \n\t
    • 0 <= nums[i] <= 106
    • \n\t
    • 1 <= m <= min(50, nums.length)
    • \n
    \n", "tags_en": ["Binary Search", "Dynamic Programming"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int splitArray(vector& nums, int m) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int splitArray(int[] nums, int m) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def splitArray(self, nums, m):\n \"\"\"\n :type nums: List[int]\n :type m: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def splitArray(self, nums: List[int], m: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint splitArray(int* nums, int numsSize, int m){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SplitArray(int[] nums, int m) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} m\n * @return {number}\n */\nvar splitArray = function(nums, m) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} m\n# @return {Integer}\ndef split_array(nums, m)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func splitArray(_ nums: [Int], _ m: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func splitArray(nums []int, m int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def splitArray(nums: Array[Int], m: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun splitArray(nums: IntArray, m: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn split_array(nums: Vec, m: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $m\n * @return Integer\n */\n function splitArray($nums, $m) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function splitArray(nums: number[], m: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (split-array nums m)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0410](https://leetcode-cn.com/problems/split-array-largest-sum)", "[\u5206\u5272\u6570\u7ec4\u7684\u6700\u5927\u503c](/solution/0400-0499/0410.Split%20Array%20Largest%20Sum/README.md)", "`\u4e8c\u5206\u67e5\u627e`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0410](https://leetcode.com/problems/split-array-largest-sum)", "[Split Array Largest Sum](/solution/0400-0499/0410.Split%20Array%20Largest%20Sum/README_EN.md)", "`Binary Search`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0409", "frontend_question_id": "0409", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-palindrome", "url_en": "https://leetcode.com/problems/longest-palindrome", "relative_path_cn": "/solution/0400-0499/0409.Longest%20Palindrome/README.md", "relative_path_en": "/solution/0400-0499/0409.Longest%20Palindrome/README_EN.md", "title_cn": "\u6700\u957f\u56de\u6587\u4e32", "title_en": "Longest Palindrome", "question_title_slug": "longest-palindrome", "content_en": "

    Given a string s which consists of lowercase or uppercase letters, return the length of the longest palindrome that can be built with those letters.

    \n\n

    Letters are case sensitive, for example, "Aa" is not considered a palindrome here.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "abccccdd"\nOutput: 7\nExplanation:\nOne longest palindrome that can be built is "dccaccd", whose length is 7.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "a"\nOutput: 1\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "bb"\nOutput: 2\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 2000
    • \n\t
    • s consists of lowercase and/or uppercase English letters only.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5305\u542b\u5927\u5199\u5b57\u6bcd\u548c\u5c0f\u5199\u5b57\u6bcd\u7684\u5b57\u7b26\u4e32\uff0c\u627e\u5230\u901a\u8fc7\u8fd9\u4e9b\u5b57\u6bcd\u6784\u9020\u6210\u7684\u6700\u957f\u7684\u56de\u6587\u4e32\u3002

    \n\n

    \u5728\u6784\u9020\u8fc7\u7a0b\u4e2d\uff0c\u8bf7\u6ce8\u610f\u533a\u5206\u5927\u5c0f\u5199\u3002\u6bd4\u5982 "Aa" \u4e0d\u80fd\u5f53\u505a\u4e00\u4e2a\u56de\u6587\u5b57\u7b26\u4e32\u3002

    \n\n

    \u6ce8\u610f:
    \n\u5047\u8bbe\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u4e0d\u4f1a\u8d85\u8fc7 1010\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165:\n"abccccdd"\n\n\u8f93\u51fa:\n7\n\n\u89e3\u91ca:\n\u6211\u4eec\u53ef\u4ee5\u6784\u9020\u7684\u6700\u957f\u7684\u56de\u6587\u4e32\u662f"dccaccd", \u5b83\u7684\u957f\u5ea6\u662f 7\u3002\n
    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int longestPalindrome(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int longestPalindrome(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestPalindrome(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestPalindrome(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint longestPalindrome(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LongestPalindrome(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar longestPalindrome = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef longest_palindrome(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestPalindrome(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestPalindrome(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestPalindrome(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestPalindrome(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_palindrome(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function longestPalindrome($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestPalindrome(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-palindrome s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0409](https://leetcode-cn.com/problems/longest-palindrome)", "[\u6700\u957f\u56de\u6587\u4e32](/solution/0400-0499/0409.Longest%20Palindrome/README.md)", "`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0409](https://leetcode.com/problems/longest-palindrome)", "[Longest Palindrome](/solution/0400-0499/0409.Longest%20Palindrome/README_EN.md)", "`Hash Table`", "Easy", ""]}, {"question_id": "0408", "frontend_question_id": "0408", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/valid-word-abbreviation", "url_en": "https://leetcode.com/problems/valid-word-abbreviation", "relative_path_cn": "/solution/0400-0499/0408.Valid%20Word%20Abbreviation/README.md", "relative_path_en": "/solution/0400-0499/0408.Valid%20Word%20Abbreviation/README_EN.md", "title_cn": "\u6709\u6548\u5355\u8bcd\u7f29\u5199", "title_en": "Valid Word Abbreviation", "question_title_slug": "valid-word-abbreviation", "content_en": "

    A string can be abbreviated by replacing any number of non-adjacent substrings with their lengths. For example, a string such as "substitution" could be abbreviated as (but not limited to):

    \n\n
      \n\t
    • "s10n" ("s ubstitutio n")
    • \n\t
    • "sub4u4" ("sub stit u tion")
    • \n\t
    • "12" ("substitution")
    • \n\t
    • "su3i1u2on" ("su bst i t u ti on")
    • \n\t
    • "substitution" (no substrings replaced)
    • \n
    \n\n

    Note that "s55n" ("s ubsti tutio n") is not a valid abbreviation of "substitution" because the replaced substrings are adjacent.

    \n\n

    Given a string s and an abbreviation abbr, return whether the string matches with the given abbreviation.

    \n\n

     

    \n

    Example 1:

    \n
    Input: word = \"internationalization\", abbr = \"i12iz4n\"\nOutput: true\n

    Example 2:

    \n
    Input: word = \"apple\", abbr = \"a2e\"\nOutput: false\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= word.length, abbr.length <= 20
    • \n\t
    • word consists of only lowercase English letters.
    • \n\t
    • abbr consists of lowercase English letters and digits.
    • \n
    \n", "content_cn": "

    \u7ed9\u4e00\u4e2a \u975e\u7a7a \u5b57\u7b26\u4e32 s \u548c\u4e00\u4e2a\u5355\u8bcd\u7f29\u5199 abbr \uff0c\u5224\u65ad\u8fd9\u4e2a\u7f29\u5199\u662f\u5426\u53ef\u4ee5\u662f\u7ed9\u5b9a\u5355\u8bcd\u7684\u7f29\u5199\u3002

    \n\n

    \u5b57\u7b26\u4e32 "word" \u7684\u6240\u6709\u6709\u6548\u7f29\u5199\u4e3a\uff1a

    \n\n
    ["word", "1ord", "w1rd", "wo1d", "wor1", "2rd", "w2d", "wo2", "1o1d", "1or1", "w1r1", "1o2", "2r1", "3d", "w3", "4"]
    \n\n

    \u6ce8\u610f\u5355\u8bcd "word" \u7684\u6240\u6709\u6709\u6548\u7f29\u5199\u4ec5\u5305\u542b\u4ee5\u4e0a\u8fd9\u4e9b\u3002\u4efb\u4f55\u5176\u4ed6\u7684\u5b57\u7b26\u4e32\u90fd\u4e0d\u662f "word" \u7684\u6709\u6548\u7f29\u5199\u3002

    \n\n

    \u6ce8\u610f:
    \n\u5047\u8bbe\u5b57\u7b26\u4e32 s \u4ec5\u5305\u542b\u5c0f\u5199\u5b57\u6bcd\u4e14 abbr \u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd\u548c\u6570\u5b57\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u7ed9\u5b9a s = "internationalization", abbr = "i12iz4n":\n\n\u51fd\u6570\u8fd4\u56de true.\n
    \n\n

     

    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u7ed9\u5b9a s = "apple", abbr = "a2e":\n\n\u51fd\u6570\u8fd4\u56de false.\n
    \n\n

     

    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool validWordAbbreviation(string word, string abbr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean validWordAbbreviation(String word, String abbr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def validWordAbbreviation(self, word, abbr):\n \"\"\"\n :type word: str\n :type abbr: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def validWordAbbreviation(self, word: str, abbr: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool validWordAbbreviation(char * word, char * abbr){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool ValidWordAbbreviation(string word, string abbr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} word\n * @param {string} abbr\n * @return {boolean}\n */\nvar validWordAbbreviation = function(word, abbr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} word\n# @param {String} abbr\n# @return {Boolean}\ndef valid_word_abbreviation(word, abbr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func validWordAbbreviation(_ word: String, _ abbr: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func validWordAbbreviation(word string, abbr string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def validWordAbbreviation(word: String, abbr: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun validWordAbbreviation(word: String, abbr: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn valid_word_abbreviation(word: String, abbr: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $word\n * @param String $abbr\n * @return Boolean\n */\n function validWordAbbreviation($word, $abbr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function validWordAbbreviation(word: string, abbr: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (valid-word-abbreviation word abbr)\n (-> string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0408](https://leetcode-cn.com/problems/valid-word-abbreviation)", "[\u6709\u6548\u5355\u8bcd\u7f29\u5199](/solution/0400-0499/0408.Valid%20Word%20Abbreviation/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0408](https://leetcode.com/problems/valid-word-abbreviation)", "[Valid Word Abbreviation](/solution/0400-0499/0408.Valid%20Word%20Abbreviation/README_EN.md)", "`String`", "Easy", "\ud83d\udd12"]}, {"question_id": "0407", "frontend_question_id": "0407", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/trapping-rain-water-ii", "url_en": "https://leetcode.com/problems/trapping-rain-water-ii", "relative_path_cn": "/solution/0400-0499/0407.Trapping%20Rain%20Water%20II/README.md", "relative_path_en": "/solution/0400-0499/0407.Trapping%20Rain%20Water%20II/README_EN.md", "title_cn": "\u63a5\u96e8\u6c34 II", "title_en": "Trapping Rain Water II", "question_title_slug": "trapping-rain-water-ii", "content_en": "

    Given an m x n integer matrix heightMap representing the height of each unit cell in a 2D elevation map, return the volume of water it can trap after raining.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: heightMap = [[1,4,3,1,3,2],[3,2,1,3,2,4],[2,3,3,2,3,1]]\nOutput: 4\nExplanation: After the rain, water is trapped between the blocks.\nWe have two small pounds 1 and 3 units trapped.\nThe total volume of water trapped is 4.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: heightMap = [[3,3,3,3,3],[3,2,2,2,3],[3,2,1,2,3],[3,2,2,2,3],[3,3,3,3,3]]\nOutput: 10\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == heightMap.length
    • \n\t
    • n == heightMap[i].length
    • \n\t
    • 1 <= m, n <= 200
    • \n\t
    • 0 <= heightMap[i][j] <= 2 * 104
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a m x n \u7684\u77e9\u9635\uff0c\u5176\u4e2d\u7684\u503c\u5747\u4e3a\u975e\u8d1f\u6574\u6570\uff0c\u4ee3\u8868\u4e8c\u7ef4\u9ad8\u5ea6\u56fe\u6bcf\u4e2a\u5355\u5143\u7684\u9ad8\u5ea6\uff0c\u8bf7\u8ba1\u7b97\u56fe\u4e2d\u5f62\u72b6\u6700\u591a\u80fd\u63a5\u591a\u5c11\u4f53\u79ef\u7684\u96e8\u6c34\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u7ed9\u51fa\u5982\u4e0b 3x6 \u7684\u9ad8\u5ea6\u56fe:\n[\n  [1,4,3,1,3,2],\n  [3,2,1,3,2,4],\n  [2,3,3,2,3,1]\n]\n\n\u8fd4\u56de 4 \u3002\n
    \n\n

    \n\n

    \u5982\u4e0a\u56fe\u6240\u793a\uff0c\u8fd9\u662f\u4e0b\u96e8\u524d\u7684\u9ad8\u5ea6\u56fe[[1,4,3,1,3,2],[3,2,1,3,2,4],[2,3,3,2,3,1]] \u7684\u72b6\u6001\u3002

    \n\n

     

    \n\n

    \n\n

    \u4e0b\u96e8\u540e\uff0c\u96e8\u6c34\u5c06\u4f1a\u88ab\u5b58\u50a8\u5728\u8fd9\u4e9b\u65b9\u5757\u4e2d\u3002\u603b\u7684\u63a5\u96e8\u6c34\u91cf\u662f4\u3002

    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= m, n <= 110
    • \n\t
    • 0 <= heightMap[i][j] <= 20000
    • \n
    \n", "tags_en": ["Heap", "Breadth-first Search"], "tags_cn": ["\u5806", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int trapRainWater(vector>& heightMap) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int trapRainWater(int[][] heightMap) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def trapRainWater(self, heightMap):\n \"\"\"\n :type heightMap: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def trapRainWater(self, heightMap: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint trapRainWater(int** heightMap, int heightMapSize, int* heightMapColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int TrapRainWater(int[][] heightMap) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} heightMap\n * @return {number}\n */\nvar trapRainWater = function(heightMap) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} height_map\n# @return {Integer}\ndef trap_rain_water(height_map)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func trapRainWater(_ heightMap: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func trapRainWater(heightMap [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def trapRainWater(heightMap: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun trapRainWater(heightMap: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn trap_rain_water(height_map: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $heightMap\n * @return Integer\n */\n function trapRainWater($heightMap) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function trapRainWater(heightMap: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (trap-rain-water heightMap)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0407](https://leetcode-cn.com/problems/trapping-rain-water-ii)", "[\u63a5\u96e8\u6c34 II](/solution/0400-0499/0407.Trapping%20Rain%20Water%20II/README.md)", "`\u5806`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[0407](https://leetcode.com/problems/trapping-rain-water-ii)", "[Trapping Rain Water II](/solution/0400-0499/0407.Trapping%20Rain%20Water%20II/README_EN.md)", "`Heap`,`Breadth-first Search`", "Hard", ""]}, {"question_id": "0406", "frontend_question_id": "0406", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/queue-reconstruction-by-height", "url_en": "https://leetcode.com/problems/queue-reconstruction-by-height", "relative_path_cn": "/solution/0400-0499/0406.Queue%20Reconstruction%20by%20Height/README.md", "relative_path_en": "/solution/0400-0499/0406.Queue%20Reconstruction%20by%20Height/README_EN.md", "title_cn": "\u6839\u636e\u8eab\u9ad8\u91cd\u5efa\u961f\u5217", "title_en": "Queue Reconstruction by Height", "question_title_slug": "queue-reconstruction-by-height", "content_en": "

    You are given an array of people, people, which are the attributes of some people in a queue (not necessarily in order). Each people[i] = [hi, ki] represents the ith person of height hi with exactly ki other people in front who have a height greater than or equal to hi.

    \n\n

    Reconstruct and return the queue that is represented by the input array people. The returned queue should be formatted as an array queue, where queue[j] = [hj, kj] is the attributes of the jth person in the queue (queue[0] is the person at the front of the queue).

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: people = [[7,0],[4,4],[7,1],[5,0],[6,1],[5,2]]\nOutput: [[5,0],[7,0],[5,2],[6,1],[4,4],[7,1]]\nExplanation:\nPerson 0 has height 5 with no other people taller or the same height in front.\nPerson 1 has height 7 with no other people taller or the same height in front.\nPerson 2 has height 5 with two persons taller or the same height in front, which is person 0 and 1.\nPerson 3 has height 6 with one person taller or the same height in front, which is person 1.\nPerson 4 has height 4 with four people taller or the same height in front, which are people 0, 1, 2, and 3.\nPerson 5 has height 7 with one person taller or the same height in front, which is person 1.\nHence [[5,0],[7,0],[5,2],[6,1],[4,4],[7,1]] is the reconstructed queue.\n
    \n\n

    Example 2:

    \n\n
    \nInput: people = [[6,0],[5,0],[4,0],[3,2],[2,2],[1,4]]\nOutput: [[4,0],[5,0],[2,2],[3,2],[1,4],[6,0]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= people.length <= 2000
    • \n\t
    • 0 <= hi <= 106
    • \n\t
    • 0 <= ki < people.length
    • \n\t
    • It is guaranteed that the queue can be reconstructed.
    • \n
    \n", "content_cn": "

    \u5047\u8bbe\u6709\u6253\u4e71\u987a\u5e8f\u7684\u4e00\u7fa4\u4eba\u7ad9\u6210\u4e00\u4e2a\u961f\u5217\uff0c\u6570\u7ec4 people \u8868\u793a\u961f\u5217\u4e2d\u4e00\u4e9b\u4eba\u7684\u5c5e\u6027\uff08\u4e0d\u4e00\u5b9a\u6309\u987a\u5e8f\uff09\u3002\u6bcf\u4e2a people[i] = [hi, ki] \u8868\u793a\u7b2c i \u4e2a\u4eba\u7684\u8eab\u9ad8\u4e3a hi \uff0c\u524d\u9762 \u6b63\u597d \u6709 ki \u4e2a\u8eab\u9ad8\u5927\u4e8e\u6216\u7b49\u4e8e hi \u7684\u4eba\u3002

    \n\n

    \u8bf7\u4f60\u91cd\u65b0\u6784\u9020\u5e76\u8fd4\u56de\u8f93\u5165\u6570\u7ec4\u00a0people \u6240\u8868\u793a\u7684\u961f\u5217\u3002\u8fd4\u56de\u7684\u961f\u5217\u5e94\u8be5\u683c\u5f0f\u5316\u4e3a\u6570\u7ec4 queue \uff0c\u5176\u4e2d queue[j] = [hj, kj] \u662f\u961f\u5217\u4e2d\u7b2c j \u4e2a\u4eba\u7684\u5c5e\u6027\uff08queue[0] \u662f\u6392\u5728\u961f\u5217\u524d\u9762\u7684\u4eba\uff09\u3002

    \n\n

    \u00a0

    \n\n
      \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1apeople = [[7,0],[4,4],[7,1],[5,0],[6,1],[5,2]]\n\u8f93\u51fa\uff1a[[5,0],[7,0],[5,2],[6,1],[4,4],[7,1]]\n\u89e3\u91ca\uff1a\n\u7f16\u53f7\u4e3a 0 \u7684\u4eba\u8eab\u9ad8\u4e3a 5 \uff0c\u6ca1\u6709\u8eab\u9ad8\u66f4\u9ad8\u6216\u8005\u76f8\u540c\u7684\u4eba\u6392\u5728\u4ed6\u524d\u9762\u3002\n\u7f16\u53f7\u4e3a 1 \u7684\u4eba\u8eab\u9ad8\u4e3a 7 \uff0c\u6ca1\u6709\u8eab\u9ad8\u66f4\u9ad8\u6216\u8005\u76f8\u540c\u7684\u4eba\u6392\u5728\u4ed6\u524d\u9762\u3002\n\u7f16\u53f7\u4e3a 2 \u7684\u4eba\u8eab\u9ad8\u4e3a 5 \uff0c\u6709 2 \u4e2a\u8eab\u9ad8\u66f4\u9ad8\u6216\u8005\u76f8\u540c\u7684\u4eba\u6392\u5728\u4ed6\u524d\u9762\uff0c\u5373\u7f16\u53f7\u4e3a 0 \u548c 1 \u7684\u4eba\u3002\n\u7f16\u53f7\u4e3a 3 \u7684\u4eba\u8eab\u9ad8\u4e3a 6 \uff0c\u6709 1 \u4e2a\u8eab\u9ad8\u66f4\u9ad8\u6216\u8005\u76f8\u540c\u7684\u4eba\u6392\u5728\u4ed6\u524d\u9762\uff0c\u5373\u7f16\u53f7\u4e3a 1 \u7684\u4eba\u3002\n\u7f16\u53f7\u4e3a 4 \u7684\u4eba\u8eab\u9ad8\u4e3a 4 \uff0c\u6709 4 \u4e2a\u8eab\u9ad8\u66f4\u9ad8\u6216\u8005\u76f8\u540c\u7684\u4eba\u6392\u5728\u4ed6\u524d\u9762\uff0c\u5373\u7f16\u53f7\u4e3a 0\u30011\u30012\u30013 \u7684\u4eba\u3002\n\u7f16\u53f7\u4e3a 5 \u7684\u4eba\u8eab\u9ad8\u4e3a 7 \uff0c\u6709 1 \u4e2a\u8eab\u9ad8\u66f4\u9ad8\u6216\u8005\u76f8\u540c\u7684\u4eba\u6392\u5728\u4ed6\u524d\u9762\uff0c\u5373\u7f16\u53f7\u4e3a 1 \u7684\u4eba\u3002\n\u56e0\u6b64 [[5,0],[7,0],[5,2],[6,1],[4,4],[7,1]] \u662f\u91cd\u65b0\u6784\u9020\u540e\u7684\u961f\u5217\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1apeople = [[6,0],[5,0],[4,0],[3,2],[2,2],[1,4]]\n\u8f93\u51fa\uff1a[[4,0],[5,0],[2,2],[3,2],[1,4],[6,0]]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= people.length <= 2000
    • \n\t
    • 0 <= hi <= 106
    • \n\t
    • 0 <= ki < people.length
    • \n\t
    • \u9898\u76ee\u6570\u636e\u786e\u4fdd\u961f\u5217\u53ef\u4ee5\u88ab\u91cd\u5efa
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> reconstructQueue(vector>& people) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[][] reconstructQueue(int[][] people) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def reconstructQueue(self, people):\n \"\"\"\n :type people: List[List[int]]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def reconstructQueue(self, people: List[List[int]]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** reconstructQueue(int** people, int peopleSize, int* peopleColSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[][] ReconstructQueue(int[][] people) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} people\n * @return {number[][]}\n */\nvar reconstructQueue = function(people) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} people\n# @return {Integer[][]}\ndef reconstruct_queue(people)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func reconstructQueue(_ people: [[Int]]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func reconstructQueue(people [][]int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def reconstructQueue(people: Array[Array[Int]]): Array[Array[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun reconstructQueue(people: Array): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn reconstruct_queue(people: Vec>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $people\n * @return Integer[][]\n */\n function reconstructQueue($people) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function reconstructQueue(people: number[][]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (reconstruct-queue people)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0406](https://leetcode-cn.com/problems/queue-reconstruction-by-height)", "[\u6839\u636e\u8eab\u9ad8\u91cd\u5efa\u961f\u5217](/solution/0400-0499/0406.Queue%20Reconstruction%20by%20Height/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0406](https://leetcode.com/problems/queue-reconstruction-by-height)", "[Queue Reconstruction by Height](/solution/0400-0499/0406.Queue%20Reconstruction%20by%20Height/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "0405", "frontend_question_id": "0405", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/convert-a-number-to-hexadecimal", "url_en": "https://leetcode.com/problems/convert-a-number-to-hexadecimal", "relative_path_cn": "/solution/0400-0499/0405.Convert%20a%20Number%20to%20Hexadecimal/README.md", "relative_path_en": "/solution/0400-0499/0405.Convert%20a%20Number%20to%20Hexadecimal/README_EN.md", "title_cn": "\u6570\u5b57\u8f6c\u6362\u4e3a\u5341\u516d\u8fdb\u5236\u6570", "title_en": "Convert a Number to Hexadecimal", "question_title_slug": "convert-a-number-to-hexadecimal", "content_en": "

    Given an integer num, return a string representing its hexadecimal representation. For negative integers, two’s complement method is used.

    \n\n

    All the letters in the answer string should be lowercase characters, and there should not be any leading zeros in the answer except for the zero itself.

    \n\n

    Note: You are not allowed to use any built-in library method to directly solve this problem.

    \n\n

     

    \n

    Example 1:

    \n
    Input: num = 26\nOutput: \"1a\"\n

    Example 2:

    \n
    Input: num = -1\nOutput: \"ffffffff\"\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • -231 <= num <= 231 - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\uff0c\u7f16\u5199\u4e00\u4e2a\u7b97\u6cd5\u5c06\u8fd9\u4e2a\u6570\u8f6c\u6362\u4e3a\u5341\u516d\u8fdb\u5236\u6570\u3002\u5bf9\u4e8e\u8d1f\u6574\u6570\uff0c\u6211\u4eec\u901a\u5e38\u4f7f\u7528 \u8865\u7801\u8fd0\u7b97 \u65b9\u6cd5\u3002

    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u5341\u516d\u8fdb\u5236\u4e2d\u6240\u6709\u5b57\u6bcd(a-f)\u90fd\u5fc5\u987b\u662f\u5c0f\u5199\u3002
    2. \n\t
    3. \u5341\u516d\u8fdb\u5236\u5b57\u7b26\u4e32\u4e2d\u4e0d\u80fd\u5305\u542b\u591a\u4f59\u7684\u524d\u5bfc\u96f6\u3002\u5982\u679c\u8981\u8f6c\u5316\u7684\u6570\u4e3a0\uff0c\u90a3\u4e48\u4ee5\u5355\u4e2a\u5b57\u7b26'0'\u6765\u8868\u793a\uff1b\u5bf9\u4e8e\u5176\u4ed6\u60c5\u51b5\uff0c\u5341\u516d\u8fdb\u5236\u5b57\u7b26\u4e32\u4e2d\u7684\u7b2c\u4e00\u4e2a\u5b57\u7b26\u5c06\u4e0d\u4f1a\u662f0\u5b57\u7b26\u3002 
    4. \n\t
    5. \u7ed9\u5b9a\u7684\u6570\u786e\u4fdd\u572832\u4f4d\u6709\u7b26\u53f7\u6574\u6570\u8303\u56f4\u5185\u3002
    6. \n\t
    7. \u4e0d\u80fd\u4f7f\u7528\u4efb\u4f55\u7531\u5e93\u63d0\u4f9b\u7684\u5c06\u6570\u5b57\u76f4\u63a5\u8f6c\u6362\u6216\u683c\u5f0f\u5316\u4e3a\u5341\u516d\u8fdb\u5236\u7684\u65b9\u6cd5\u3002
    8. \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165:\n26\n\n\u8f93\u51fa:\n"1a"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165:\n-1\n\n\u8f93\u51fa:\n"ffffffff"\n
    \n", "tags_en": ["Bit Manipulation"], "tags_cn": ["\u4f4d\u8fd0\u7b97"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string toHex(int num) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String toHex(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def toHex(self, num):\n \"\"\"\n :type num: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def toHex(self, num: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * toHex(int num){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ToHex(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} num\n * @return {string}\n */\nvar toHex = function(num) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} num\n# @return {String}\ndef to_hex(num)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func toHex(_ num: Int) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func toHex(num int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def toHex(num: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun toHex(num: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn to_hex(num: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $num\n * @return String\n */\n function toHex($num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function toHex(num: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (to-hex num)\n (-> exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0405](https://leetcode-cn.com/problems/convert-a-number-to-hexadecimal)", "[\u6570\u5b57\u8f6c\u6362\u4e3a\u5341\u516d\u8fdb\u5236\u6570](/solution/0400-0499/0405.Convert%20a%20Number%20to%20Hexadecimal/README.md)", "`\u4f4d\u8fd0\u7b97`", "\u7b80\u5355", ""], "md_table_row_en": ["[0405](https://leetcode.com/problems/convert-a-number-to-hexadecimal)", "[Convert a Number to Hexadecimal](/solution/0400-0499/0405.Convert%20a%20Number%20to%20Hexadecimal/README_EN.md)", "`Bit Manipulation`", "Easy", ""]}, {"question_id": "0404", "frontend_question_id": "0404", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sum-of-left-leaves", "url_en": "https://leetcode.com/problems/sum-of-left-leaves", "relative_path_cn": "/solution/0400-0499/0404.Sum%20of%20Left%20Leaves/README.md", "relative_path_en": "/solution/0400-0499/0404.Sum%20of%20Left%20Leaves/README_EN.md", "title_cn": "\u5de6\u53f6\u5b50\u4e4b\u548c", "title_en": "Sum of Left Leaves", "question_title_slug": "sum-of-left-leaves", "content_en": "

    Given the root of a binary tree, return the sum of all left leaves.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [3,9,20,null,null,15,7]\nOutput: 24\nExplanation: There are two left leaves in the binary tree, with values 9 and 15 respectively.\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = [1]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 1000].
    • \n\t
    • -1000 <= Node.val <= 1000
    • \n
    \n", "content_cn": "

    \u8ba1\u7b97\u7ed9\u5b9a\u4e8c\u53c9\u6811\u7684\u6240\u6709\u5de6\u53f6\u5b50\u4e4b\u548c\u3002

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n    3\n   / \\\n  9  20\n    /  \\\n   15   7\n\n\u5728\u8fd9\u4e2a\u4e8c\u53c9\u6811\u4e2d\uff0c\u6709\u4e24\u4e2a\u5de6\u53f6\u5b50\uff0c\u5206\u522b\u662f 9 \u548c 15\uff0c\u6240\u4ee5\u8fd4\u56de 24
    \n\n

     

    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int sumOfLeftLeaves(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int sumOfLeftLeaves(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def sumOfLeftLeaves(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def sumOfLeftLeaves(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint sumOfLeftLeaves(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int SumOfLeftLeaves(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar sumOfLeftLeaves = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef sum_of_left_leaves(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func sumOfLeftLeaves(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc sumOfLeftLeaves(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def sumOfLeftLeaves(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun sumOfLeftLeaves(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn sum_of_left_leaves(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function sumOfLeftLeaves($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction sumOfLeftLeaves(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (sum-of-left-leaves root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0404](https://leetcode-cn.com/problems/sum-of-left-leaves)", "[\u5de6\u53f6\u5b50\u4e4b\u548c](/solution/0400-0499/0404.Sum%20of%20Left%20Leaves/README.md)", "`\u6811`", "\u7b80\u5355", ""], "md_table_row_en": ["[0404](https://leetcode.com/problems/sum-of-left-leaves)", "[Sum of Left Leaves](/solution/0400-0499/0404.Sum%20of%20Left%20Leaves/README_EN.md)", "`Tree`", "Easy", ""]}, {"question_id": "0403", "frontend_question_id": "0403", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/frog-jump", "url_en": "https://leetcode.com/problems/frog-jump", "relative_path_cn": "/solution/0400-0499/0403.Frog%20Jump/README.md", "relative_path_en": "/solution/0400-0499/0403.Frog%20Jump/README_EN.md", "title_cn": "\u9752\u86d9\u8fc7\u6cb3", "title_en": "Frog Jump", "question_title_slug": "frog-jump", "content_en": "

    A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.

    \n\n

    Given a list of stones' positions (in units) in sorted ascending order, determine if the frog can cross the river by landing on the last stone. Initially, the frog is on the first stone and assumes the first jump must be 1 unit.

    \n\n

    If the frog's last jump was k units, its next jump must be either k - 1, k, or k + 1 units. The frog can only jump in the forward direction.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: stones = [0,1,3,5,6,8,12,17]\nOutput: true\nExplanation: The frog can jump to the last stone by jumping 1 unit to the 2nd stone, then 2 units to the 3rd stone, then 2 units to the 4th stone, then 3 units to the 6th stone, 4 units to the 7th stone, and 5 units to the 8th stone.\n
    \n\n

    Example 2:

    \n\n
    \nInput: stones = [0,1,2,3,4,8,9,11]\nOutput: false\nExplanation: There is no way to jump to the last stone as the gap between the 5th and 6th stone is too large.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= stones.length <= 2000
    • \n\t
    • 0 <= stones[i] <= 231 - 1
    • \n\t
    • stones[0] == 0
    • \n
    \n", "content_cn": "

    \u4e00\u53ea\u9752\u86d9\u60f3\u8981\u8fc7\u6cb3\u3002 \u5047\u5b9a\u6cb3\u6d41\u88ab\u7b49\u5206\u4e3a\u82e5\u5e72\u4e2a\u5355\u5143\u683c\uff0c\u5e76\u4e14\u5728\u6bcf\u4e00\u4e2a\u5355\u5143\u683c\u5185\u90fd\u6709\u53ef\u80fd\u653e\u6709\u4e00\u5757\u77f3\u5b50\uff08\u4e5f\u6709\u53ef\u80fd\u6ca1\u6709\uff09\u3002 \u9752\u86d9\u53ef\u4ee5\u8df3\u4e0a\u77f3\u5b50\uff0c\u4f46\u662f\u4e0d\u53ef\u4ee5\u8df3\u5165\u6c34\u4e2d\u3002

    \n\n

    \u7ed9\u4f60\u77f3\u5b50\u7684\u4f4d\u7f6e\u5217\u8868 stones\uff08\u7528\u5355\u5143\u683c\u5e8f\u53f7 \u5347\u5e8f \u8868\u793a\uff09\uff0c\u00a0\u8bf7\u5224\u5b9a\u9752\u86d9\u80fd\u5426\u6210\u529f\u8fc7\u6cb3\uff08\u5373\u80fd\u5426\u5728\u6700\u540e\u4e00\u6b65\u8df3\u81f3\u6700\u540e\u4e00\u5757\u77f3\u5b50\u4e0a\uff09\u3002

    \n\n

    \u5f00\u59cb\u65f6\uff0c\u00a0\u9752\u86d9\u9ed8\u8ba4\u5df2\u7ad9\u5728\u7b2c\u4e00\u5757\u77f3\u5b50\u4e0a\uff0c\u5e76\u53ef\u4ee5\u5047\u5b9a\u5b83\u7b2c\u4e00\u6b65\u53ea\u80fd\u8df3\u8dc3\u4e00\u4e2a\u5355\u4f4d\uff08\u5373\u53ea\u80fd\u4ece\u5355\u5143\u683c 1 \u8df3\u81f3\u5355\u5143\u683c 2 \uff09\u3002

    \n\n

    \u5982\u679c\u9752\u86d9\u4e0a\u4e00\u6b65\u8df3\u8dc3\u4e86\u00a0k\u00a0\u4e2a\u5355\u4f4d\uff0c\u90a3\u4e48\u5b83\u63a5\u4e0b\u6765\u7684\u8df3\u8dc3\u8ddd\u79bb\u53ea\u80fd\u9009\u62e9\u4e3a\u00a0k - 1\u3001k\u00a0\u6216\u00a0k + 1 \u4e2a\u5355\u4f4d\u3002\u00a0\u53e6\u8bf7\u6ce8\u610f\uff0c\u9752\u86d9\u53ea\u80fd\u5411\u524d\u65b9\uff08\u7ec8\u70b9\u7684\u65b9\u5411\uff09\u8df3\u8dc3\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1astones = [0,1,3,5,6,8,12,17]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u9752\u86d9\u53ef\u4ee5\u6210\u529f\u8fc7\u6cb3\uff0c\u6309\u7167\u5982\u4e0b\u65b9\u6848\u8df3\u8dc3\uff1a\u8df3 1 \u4e2a\u5355\u4f4d\u5230\u7b2c 2 \u5757\u77f3\u5b50, \u7136\u540e\u8df3 2 \u4e2a\u5355\u4f4d\u5230\u7b2c 3 \u5757\u77f3\u5b50, \u63a5\u7740 \u8df3 2 \u4e2a\u5355\u4f4d\u5230\u7b2c 4 \u5757\u77f3\u5b50, \u7136\u540e\u8df3 3 \u4e2a\u5355\u4f4d\u5230\u7b2c 6 \u5757\u77f3\u5b50, \u8df3 4 \u4e2a\u5355\u4f4d\u5230\u7b2c 7 \u5757\u77f3\u5b50, \u6700\u540e\uff0c\u8df3 5 \u4e2a\u5355\u4f4d\u5230\u7b2c 8 \u4e2a\u77f3\u5b50\uff08\u5373\u6700\u540e\u4e00\u5757\u77f3\u5b50\uff09\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1astones = [0,1,2,3,4,8,9,11]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u8fd9\u662f\u56e0\u4e3a\u7b2c 5 \u548c\u7b2c 6 \u4e2a\u77f3\u5b50\u4e4b\u95f4\u7684\u95f4\u8ddd\u592a\u5927\uff0c\u6ca1\u6709\u53ef\u9009\u7684\u65b9\u6848\u4f9b\u9752\u86d9\u8df3\u8dc3\u8fc7\u53bb\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= stones.length <= 2000
    • \n\t
    • 0 <= stones[i] <= 231 - 1
    • \n\t
    • stones[0] == 0
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canCross(vector& stones) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canCross(int[] stones) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canCross(self, stones):\n \"\"\"\n :type stones: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canCross(self, stones: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canCross(int* stones, int stonesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanCross(int[] stones) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} stones\n * @return {boolean}\n */\nvar canCross = function(stones) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} stones\n# @return {Boolean}\ndef can_cross(stones)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canCross(_ stones: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canCross(stones []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canCross(stones: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canCross(stones: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_cross(stones: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $stones\n * @return Boolean\n */\n function canCross($stones) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canCross(stones: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-cross stones)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0403](https://leetcode-cn.com/problems/frog-jump)", "[\u9752\u86d9\u8fc7\u6cb3](/solution/0400-0499/0403.Frog%20Jump/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0403](https://leetcode.com/problems/frog-jump)", "[Frog Jump](/solution/0400-0499/0403.Frog%20Jump/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "0402", "frontend_question_id": "0402", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/remove-k-digits", "url_en": "https://leetcode.com/problems/remove-k-digits", "relative_path_cn": "/solution/0400-0499/0402.Remove%20K%20Digits/README.md", "relative_path_en": "/solution/0400-0499/0402.Remove%20K%20Digits/README_EN.md", "title_cn": "\u79fb\u6389K\u4f4d\u6570\u5b57", "title_en": "Remove K Digits", "question_title_slug": "remove-k-digits", "content_en": "

    Given string num representing a non-negative integer num, and an integer k, return the smallest possible integer after removing k digits from num.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: num = "1432219", k = 3\nOutput: "1219"\nExplanation: Remove the three digits 4, 3, and 2 to form the new number 1219 which is the smallest.\n
    \n\n

    Example 2:

    \n\n
    \nInput: num = "10200", k = 1\nOutput: "200"\nExplanation: Remove the leading 1 and the number is 200. Note that the output must not contain leading zeroes.\n
    \n\n

    Example 3:

    \n\n
    \nInput: num = "10", k = 2\nOutput: "0"\nExplanation: Remove all the digits from the number and it is left with nothing which is 0.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= k <= num.length <= 105
    • \n\t
    • num consists of only digits.
    • \n\t
    • num does not have any leading zeros except for the zero itself.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4ee5\u5b57\u7b26\u4e32\u8868\u793a\u7684\u975e\u8d1f\u6574\u6570 num\uff0c\u79fb\u9664\u8fd9\u4e2a\u6570\u4e2d\u7684 k \u4f4d\u6570\u5b57\uff0c\u4f7f\u5f97\u5269\u4e0b\u7684\u6570\u5b57\u6700\u5c0f\u3002

    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    • num \u7684\u957f\u5ea6\u5c0f\u4e8e 10002 \u4e14 ≥ k\u3002
    • \n\t
    • num \u4e0d\u4f1a\u5305\u542b\u4efb\u4f55\u524d\u5bfc\u96f6\u3002
    • \n
    \n\n

    \u793a\u4f8b 1 :

    \n\n
    \n\u8f93\u5165: num = "1432219", k = 3\n\u8f93\u51fa: "1219"\n\u89e3\u91ca: \u79fb\u9664\u6389\u4e09\u4e2a\u6570\u5b57 4, 3, \u548c 2 \u5f62\u6210\u4e00\u4e2a\u65b0\u7684\u6700\u5c0f\u7684\u6570\u5b57 1219\u3002\n
    \n\n

    \u793a\u4f8b 2 :

    \n\n
    \n\u8f93\u5165: num = "10200", k = 1\n\u8f93\u51fa: "200"\n\u89e3\u91ca: \u79fb\u6389\u9996\u4f4d\u7684 1 \u5269\u4e0b\u7684\u6570\u5b57\u4e3a 200. \u6ce8\u610f\u8f93\u51fa\u4e0d\u80fd\u6709\u4efb\u4f55\u524d\u5bfc\u96f6\u3002\n
    \n\n

    \u793a\u4f8b 3 :

    \n\n
    \n\u8f93\u5165: num = "10", k = 2\n\u8f93\u51fa: "0"\n\u89e3\u91ca: \u4ece\u539f\u6570\u5b57\u79fb\u9664\u6240\u6709\u7684\u6570\u5b57\uff0c\u5269\u4f59\u4e3a\u7a7a\u5c31\u662f0\u3002\n
    \n", "tags_en": ["Stack", "Greedy"], "tags_cn": ["\u6808", "\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string removeKdigits(string num, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String removeKdigits(String num, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def removeKdigits(self, num, k):\n \"\"\"\n :type num: str\n :type k: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def removeKdigits(self, num: str, k: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * removeKdigits(char * num, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string RemoveKdigits(string num, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} num\n * @param {number} k\n * @return {string}\n */\nvar removeKdigits = function(num, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} num\n# @param {Integer} k\n# @return {String}\ndef remove_kdigits(num, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func removeKdigits(_ num: String, _ k: Int) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func removeKdigits(num string, k int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def removeKdigits(num: String, k: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun removeKdigits(num: String, k: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn remove_kdigits(num: String, k: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $num\n * @param Integer $k\n * @return String\n */\n function removeKdigits($num, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function removeKdigits(num: string, k: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (remove-kdigits num k)\n (-> string? exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0402](https://leetcode-cn.com/problems/remove-k-digits)", "[\u79fb\u6389K\u4f4d\u6570\u5b57](/solution/0400-0499/0402.Remove%20K%20Digits/README.md)", "`\u6808`,`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0402](https://leetcode.com/problems/remove-k-digits)", "[Remove K Digits](/solution/0400-0499/0402.Remove%20K%20Digits/README_EN.md)", "`Stack`,`Greedy`", "Medium", ""]}, {"question_id": "0401", "frontend_question_id": "0401", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/binary-watch", "url_en": "https://leetcode.com/problems/binary-watch", "relative_path_cn": "/solution/0400-0499/0401.Binary%20Watch/README.md", "relative_path_en": "/solution/0400-0499/0401.Binary%20Watch/README_EN.md", "title_cn": "\u4e8c\u8fdb\u5236\u624b\u8868", "title_en": "Binary Watch", "question_title_slug": "binary-watch", "content_en": "

    A binary watch has 4 LEDs on the top which represent the hours (0-11), and the 6 LEDs on the bottom represent the minutes (0-59). Each LED represents a zero or one, with the least significant bit on the right.

    \n\n
      \n\t
    • For example, the below binary watch reads "4:51".
    • \n
    \n\n

    \"\"

    \n\n

    Given an integer turnedOn which represents the number of LEDs that are currently on, return all possible times the watch could represent. You may return the answer in any order.

    \n\n

    The hour must not contain a leading zero.

    \n\n
      \n\t
    • For example, "01:00" is not valid. It should be "1:00".
    • \n
    \n\n

    The minute must be consist of two digits and may contain a leading zero.

    \n\n
      \n\t
    • For example, "10:2" is not valid. It should be "10:02".
    • \n
    \n\n

     

    \n

    Example 1:

    \n
    Input: turnedOn = 1\nOutput: [\"0:01\",\"0:02\",\"0:04\",\"0:08\",\"0:16\",\"0:32\",\"1:00\",\"2:00\",\"4:00\",\"8:00\"]\n

    Example 2:

    \n
    Input: turnedOn = 9\nOutput: []\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= turnedOn <= 10
    • \n
    \n", "content_cn": "

    \u4e8c\u8fdb\u5236\u624b\u8868\u9876\u90e8\u6709 4 \u4e2a LED \u4ee3\u8868 \u5c0f\u65f6\uff080-11\uff09\uff0c\u5e95\u90e8\u7684 6 \u4e2a LED \u4ee3\u8868 \u5206\u949f\uff080-59\uff09\u3002\u6bcf\u4e2a LED \u4ee3\u8868\u4e00\u4e2a 0 \u6216 1\uff0c\u6700\u4f4e\u4f4d\u5728\u53f3\u4fa7\u3002

    \n\n
      \n\t
    • \u4f8b\u5982\uff0c\u4e0b\u9762\u7684\u4e8c\u8fdb\u5236\u624b\u8868\u8bfb\u53d6 \"3:25\" \u3002
    • \n
    \n\n

    \n\n

    \uff08\u56fe\u6e90\uff1aWikiMedia - Binary clock samui moon.jpg \uff0c\u8bb8\u53ef\u534f\u8bae\uff1aAttribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) \uff09

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 turnedOn \uff0c\u8868\u793a\u5f53\u524d\u4eae\u7740\u7684 LED \u7684\u6570\u91cf\uff0c\u8fd4\u56de\u4e8c\u8fdb\u5236\u624b\u8868\u53ef\u4ee5\u8868\u793a\u7684\u6240\u6709\u53ef\u80fd\u65f6\u95f4\u3002\u4f60\u53ef\u4ee5 \u6309\u4efb\u610f\u987a\u5e8f \u8fd4\u56de\u7b54\u6848\u3002

    \n\n

    \u5c0f\u65f6\u4e0d\u4f1a\u4ee5\u96f6\u5f00\u5934\uff1a

    \n\n
      \n\t
    • \u4f8b\u5982\uff0c\"01:00\" \u662f\u65e0\u6548\u7684\u65f6\u95f4\uff0c\u6b63\u786e\u7684\u5199\u6cd5\u5e94\u8be5\u662f \"1:00\" \u3002
    • \n
    \n\n

    \u5206\u949f\u5fc5\u987b\u7531\u4e24\u4f4d\u6570\u7ec4\u6210\uff0c\u53ef\u80fd\u4f1a\u4ee5\u96f6\u5f00\u5934\uff1a

    \n\n
      \n\t
    • \u4f8b\u5982\uff0c\"10:2\" \u662f\u65e0\u6548\u7684\u65f6\u95f4\uff0c\u6b63\u786e\u7684\u5199\u6cd5\u5e94\u8be5\u662f \"10:02\" \u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aturnedOn = 1\n\u8f93\u51fa\uff1a[\"0:01\",\"0:02\",\"0:04\",\"0:08\",\"0:16\",\"0:32\",\"1:00\",\"2:00\",\"4:00\",\"8:00\"]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aturnedOn = 9\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u00a0

    \n\n

    \u89e3\u91ca\uff1a

    \n\n
      \n\t
    • 0 <= turnedOn <= 10
    • \n
    \n", "tags_en": ["Bit Manipulation", "Backtracking"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector readBinaryWatch(int turnedOn) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List readBinaryWatch(int turnedOn) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def readBinaryWatch(self, turnedOn):\n \"\"\"\n :type turnedOn: int\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def readBinaryWatch(self, turnedOn: int) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** readBinaryWatch(int turnedOn, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList ReadBinaryWatch(int turnedOn) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} turnedOn\n * @return {string[]}\n */\nvar readBinaryWatch = function(turnedOn) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} turned_on\n# @return {String[]}\ndef read_binary_watch(turned_on)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func readBinaryWatch(_ turnedOn: Int) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func readBinaryWatch(turnedOn int) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def readBinaryWatch(turnedOn: Int): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun readBinaryWatch(turnedOn: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn read_binary_watch(turned_on: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $turnedOn\n * @return String[]\n */\n function readBinaryWatch($turnedOn) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function readBinaryWatch(turnedOn: number): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (read-binary-watch turnedOn)\n (-> exact-integer? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0401](https://leetcode-cn.com/problems/binary-watch)", "[\u4e8c\u8fdb\u5236\u624b\u8868](/solution/0400-0499/0401.Binary%20Watch/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u56de\u6eaf\u7b97\u6cd5`", "\u7b80\u5355", ""], "md_table_row_en": ["[0401](https://leetcode.com/problems/binary-watch)", "[Binary Watch](/solution/0400-0499/0401.Binary%20Watch/README_EN.md)", "`Bit Manipulation`,`Backtracking`", "Easy", ""]}, {"question_id": "0400", "frontend_question_id": "0400", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/nth-digit", "url_en": "https://leetcode.com/problems/nth-digit", "relative_path_cn": "/solution/0400-0499/0400.Nth%20Digit/README.md", "relative_path_en": "/solution/0400-0499/0400.Nth%20Digit/README_EN.md", "title_cn": "\u7b2c N \u4f4d\u6570\u5b57", "title_en": "Nth Digit", "question_title_slug": "nth-digit", "content_en": "

    Given an integer n, return the nth digit of the infinite integer sequence [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ...].

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 3\nOutput: 3\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 11\nOutput: 0\nExplanation: The 11th digit of the sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... is a 0, which is part of the number 10.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 231 - 1
    • \n
    \n", "content_cn": "

    \u5728\u65e0\u9650\u7684\u6574\u6570\u5e8f\u5217\u00a01, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ...\u4e2d\u627e\u5230\u7b2c\u00a0n \u4f4d\u6570\u5b57\u3002

    \n\n

    \u00a0

    \n\n

    \u6ce8\u610f\uff1an\u00a0\u662f\u6b63\u6570\u4e14\u5728 32 \u4f4d\u6574\u6570\u8303\u56f4\u5185\uff08n < 231\uff09\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1a3\n\u8f93\u51fa\uff1a3\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1a11\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u7b2c 11 \u4f4d\u6570\u5b57\u5728\u5e8f\u5217 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... \u91cc\u662f 0 \uff0c\u5b83\u662f 10 \u7684\u4e00\u90e8\u5206\u3002\n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findNthDigit(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findNthDigit(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findNthDigit(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findNthDigit(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findNthDigit(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindNthDigit(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar findNthDigit = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef find_nth_digit(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findNthDigit(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findNthDigit(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findNthDigit(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findNthDigit(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_nth_digit(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function findNthDigit($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findNthDigit(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-nth-digit n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0400](https://leetcode-cn.com/problems/nth-digit)", "[\u7b2c N \u4f4d\u6570\u5b57](/solution/0400-0499/0400.Nth%20Digit/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0400](https://leetcode.com/problems/nth-digit)", "[Nth Digit](/solution/0400-0499/0400.Nth%20Digit/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "0399", "frontend_question_id": "0399", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/evaluate-division", "url_en": "https://leetcode.com/problems/evaluate-division", "relative_path_cn": "/solution/0300-0399/0399.Evaluate%20Division/README.md", "relative_path_en": "/solution/0300-0399/0399.Evaluate%20Division/README_EN.md", "title_cn": "\u9664\u6cd5\u6c42\u503c", "title_en": "Evaluate Division", "question_title_slug": "evaluate-division", "content_en": "

    You are given an array of variable pairs equations and an array of real numbers values, where equations[i] = [Ai, Bi] and values[i] represent the equation Ai / Bi = values[i]. Each Ai or Bi is a string that represents a single variable.

    \n\n

    You are also given some queries, where queries[j] = [Cj, Dj] represents the jth query where you must find the answer for Cj / Dj = ?.

    \n\n

    Return the answers to all queries. If a single answer cannot be determined, return -1.0.

    \n\n

    Note: The input is always valid. You may assume that evaluating the queries will not result in division by zero and that there is no contradiction.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: equations = [["a","b"],["b","c"]], values = [2.0,3.0], queries = [["a","c"],["b","a"],["a","e"],["a","a"],["x","x"]]\nOutput: [6.00000,0.50000,-1.00000,1.00000,-1.00000]\nExplanation: \nGiven: a / b = 2.0, b / c = 3.0\nqueries are: a / c = ?, b / a = ?, a / e = ?, a / a = ?, x / x = ?\nreturn: [6.0, 0.5, -1.0, 1.0, -1.0 ]\n
    \n\n

    Example 2:

    \n\n
    \nInput: equations = [["a","b"],["b","c"],["bc","cd"]], values = [1.5,2.5,5.0], queries = [["a","c"],["c","b"],["bc","cd"],["cd","bc"]]\nOutput: [3.75000,0.40000,5.00000,0.20000]\n
    \n\n

    Example 3:

    \n\n
    \nInput: equations = [["a","b"]], values = [0.5], queries = [["a","b"],["b","a"],["a","c"],["x","y"]]\nOutput: [0.50000,2.00000,-1.00000,-1.00000]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= equations.length <= 20
    • \n\t
    • equations[i].length == 2
    • \n\t
    • 1 <= Ai.length, Bi.length <= 5
    • \n\t
    • values.length == equations.length
    • \n\t
    • 0.0 < values[i] <= 20.0
    • \n\t
    • 1 <= queries.length <= 20
    • \n\t
    • queries[i].length == 2
    • \n\t
    • 1 <= Cj.length, Dj.length <= 5
    • \n\t
    • Ai, Bi, Cj, Dj consist of lower case English letters and digits.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u53d8\u91cf\u5bf9\u6570\u7ec4 equations \u548c\u4e00\u4e2a\u5b9e\u6570\u503c\u6570\u7ec4 values \u4f5c\u4e3a\u5df2\u77e5\u6761\u4ef6\uff0c\u5176\u4e2d equations[i] = [Ai, Bi] \u548c values[i] \u5171\u540c\u8868\u793a\u7b49\u5f0f Ai / Bi = values[i] \u3002\u6bcf\u4e2a Ai \u6216 Bi \u662f\u4e00\u4e2a\u8868\u793a\u5355\u4e2a\u53d8\u91cf\u7684\u5b57\u7b26\u4e32\u3002

    \n\n

    \u53e6\u6709\u4e00\u4e9b\u4ee5\u6570\u7ec4 queries \u8868\u793a\u7684\u95ee\u9898\uff0c\u5176\u4e2d queries[j] = [Cj, Dj] \u8868\u793a\u7b2c j \u4e2a\u95ee\u9898\uff0c\u8bf7\u4f60\u6839\u636e\u5df2\u77e5\u6761\u4ef6\u627e\u51fa Cj / Dj = ? \u7684\u7ed3\u679c\u4f5c\u4e3a\u7b54\u6848\u3002

    \n\n

    \u8fd4\u56de \u6240\u6709\u95ee\u9898\u7684\u7b54\u6848 \u3002\u5982\u679c\u5b58\u5728\u67d0\u4e2a\u65e0\u6cd5\u786e\u5b9a\u7684\u7b54\u6848\uff0c\u5219\u7528 -1.0 \u66ff\u4ee3\u8fd9\u4e2a\u7b54\u6848\u3002\u5982\u679c\u95ee\u9898\u4e2d\u51fa\u73b0\u4e86\u7ed9\u5b9a\u7684\u5df2\u77e5\u6761\u4ef6\u4e2d\u6ca1\u6709\u51fa\u73b0\u7684\u5b57\u7b26\u4e32\uff0c\u4e5f\u9700\u8981\u7528 -1.0 \u66ff\u4ee3\u8fd9\u4e2a\u7b54\u6848\u3002

    \n\n

    \u6ce8\u610f\uff1a\u8f93\u5165\u603b\u662f\u6709\u6548\u7684\u3002\u4f60\u53ef\u4ee5\u5047\u8bbe\u9664\u6cd5\u8fd0\u7b97\u4e2d\u4e0d\u4f1a\u51fa\u73b0\u9664\u6570\u4e3a 0 \u7684\u60c5\u51b5\uff0c\u4e14\u4e0d\u5b58\u5728\u4efb\u4f55\u77db\u76fe\u7684\u7ed3\u679c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aequations = [[\"a\",\"b\"],[\"b\",\"c\"]], values = [2.0,3.0], queries = [[\"a\",\"c\"],[\"b\",\"a\"],[\"a\",\"e\"],[\"a\",\"a\"],[\"x\",\"x\"]]\n\u8f93\u51fa\uff1a[6.00000,0.50000,-1.00000,1.00000,-1.00000]\n\u89e3\u91ca\uff1a\n\u6761\u4ef6\uff1aa / b = 2.0, b / c = 3.0\n\u95ee\u9898\uff1aa / c = ?, b / a = ?, a / e = ?, a / a = ?, x / x = ?\n\u7ed3\u679c\uff1a[6.0, 0.5, -1.0, 1.0, -1.0 ]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aequations = [[\"a\",\"b\"],[\"b\",\"c\"],[\"bc\",\"cd\"]], values = [1.5,2.5,5.0], queries = [[\"a\",\"c\"],[\"c\",\"b\"],[\"bc\",\"cd\"],[\"cd\",\"bc\"]]\n\u8f93\u51fa\uff1a[3.75000,0.40000,5.00000,0.20000]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aequations = [[\"a\",\"b\"]], values = [0.5], queries = [[\"a\",\"b\"],[\"b\",\"a\"],[\"a\",\"c\"],[\"x\",\"y\"]]\n\u8f93\u51fa\uff1a[0.50000,2.00000,-1.00000,-1.00000]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= equations.length <= 20
    • \n\t
    • equations[i].length == 2
    • \n\t
    • 1 <= Ai.length, Bi.length <= 5
    • \n\t
    • values.length == equations.length
    • \n\t
    • 0.0 < values[i] <= 20.0
    • \n\t
    • 1 <= queries.length <= 20
    • \n\t
    • queries[i].length == 2
    • \n\t
    • 1 <= Cj.length, Dj.length <= 5
    • \n\t
    • Ai, Bi, Cj, Dj \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u4e0e\u6570\u5b57\u7ec4\u6210
    • \n
    \n", "tags_en": ["Union Find", "Graph"], "tags_cn": ["\u5e76\u67e5\u96c6", "\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector calcEquation(vector>& equations, vector& values, vector>& queries) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double[] calcEquation(List> equations, double[] values, List> queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def calcEquation(self, equations, values, queries):\n \"\"\"\n :type equations: List[List[str]]\n :type values: List[float]\n :type queries: List[List[str]]\n :rtype: List[float]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def calcEquation(self, equations: List[List[str]], values: List[float], queries: List[List[str]]) -> List[float]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\ndouble* calcEquation(char *** equations, int equationsSize, int* equationsColSize, double* values, int valuesSize, char *** queries, int queriesSize, int* queriesColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double[] CalcEquation(IList> equations, double[] values, IList> queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[][]} equations\n * @param {number[]} values\n * @param {string[][]} queries\n * @return {number[]}\n */\nvar calcEquation = function(equations, values, queries) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[][]} equations\n# @param {Float[]} values\n# @param {String[][]} queries\n# @return {Float[]}\ndef calc_equation(equations, values, queries)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func calcEquation(_ equations: [[String]], _ values: [Double], _ queries: [[String]]) -> [Double] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func calcEquation(equations [][]string, values []float64, queries [][]string) []float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def calcEquation(equations: List[List[String]], values: Array[Double], queries: List[List[String]]): Array[Double] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun calcEquation(equations: List>, values: DoubleArray, queries: List>): DoubleArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn calc_equation(equations: Vec>, values: Vec, queries: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $equations\n * @param Float[] $values\n * @param String[][] $queries\n * @return Float[]\n */\n function calcEquation($equations, $values, $queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function calcEquation(equations: string[][], values: number[], queries: string[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (calc-equation equations values queries)\n (-> (listof (listof string?)) (listof flonum?) (listof (listof string?)) (listof flonum?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0399](https://leetcode-cn.com/problems/evaluate-division)", "[\u9664\u6cd5\u6c42\u503c](/solution/0300-0399/0399.Evaluate%20Division/README.md)", "`\u5e76\u67e5\u96c6`,`\u56fe`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0399](https://leetcode.com/problems/evaluate-division)", "[Evaluate Division](/solution/0300-0399/0399.Evaluate%20Division/README_EN.md)", "`Union Find`,`Graph`", "Medium", ""]}, {"question_id": "0398", "frontend_question_id": "0398", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/random-pick-index", "url_en": "https://leetcode.com/problems/random-pick-index", "relative_path_cn": "/solution/0300-0399/0398.Random%20Pick%20Index/README.md", "relative_path_en": "/solution/0300-0399/0398.Random%20Pick%20Index/README_EN.md", "title_cn": "\u968f\u673a\u6570\u7d22\u5f15", "title_en": "Random Pick Index", "question_title_slug": "random-pick-index", "content_en": "

    Given an integer array nums with possible duplicates, randomly output the index of a given target number. You can assume that the given target number must exist in the array.

    \n\n

    Implement the Solution class:

    \n\n
      \n\t
    • Solution(int[] nums) Initializes the object with the array nums.
    • \n\t
    • int pick(int target) Picks a random index i from nums where nums[i] == target. If there are multiple valid i's, then each index should have an equal probability of returning.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["Solution", "pick", "pick", "pick"]\n[[[1, 2, 3, 3, 3]], [3], [1], [3]]\nOutput\n[null, 4, 0, 2]\n\nExplanation\nSolution solution = new Solution([1, 2, 3, 3, 3]);\nsolution.pick(3); // It should return either index 2, 3, or 4 randomly. Each index should have equal probability of returning.\nsolution.pick(1); // It should return 0. Since in the array only nums[0] is equal to 1.\nsolution.pick(3); // It should return either index 2, 3, or 4 randomly. Each index should have equal probability of returning.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 2 * 104
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n\t
    • target is an integer from nums.
    • \n\t
    • At most 104 calls will be made to pick.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u53ef\u80fd\u542b\u6709\u91cd\u590d\u5143\u7d20\u7684\u6574\u6570\u6570\u7ec4\uff0c\u8981\u6c42\u968f\u673a\u8f93\u51fa\u7ed9\u5b9a\u7684\u6570\u5b57\u7684\u7d22\u5f15\u3002 \u60a8\u53ef\u4ee5\u5047\u8bbe\u7ed9\u5b9a\u7684\u6570\u5b57\u4e00\u5b9a\u5b58\u5728\u4e8e\u6570\u7ec4\u4e2d\u3002

    \n\n

    \u6ce8\u610f\uff1a
    \n\u6570\u7ec4\u5927\u5c0f\u53ef\u80fd\u975e\u5e38\u5927\u3002 \u4f7f\u7528\u592a\u591a\u989d\u5916\u7a7a\u95f4\u7684\u89e3\u51b3\u65b9\u6848\u5c06\u4e0d\u4f1a\u901a\u8fc7\u6d4b\u8bd5\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \nint[] nums = new int[] {1,2,3,3,3};\nSolution solution = new Solution(nums);\n\n// pick(3) \u5e94\u8be5\u8fd4\u56de\u7d22\u5f15 2,3 \u6216\u8005 4\u3002\u6bcf\u4e2a\u7d22\u5f15\u7684\u8fd4\u56de\u6982\u7387\u5e94\u8be5\u76f8\u7b49\u3002\nsolution.pick(3);\n\n// pick(1) \u5e94\u8be5\u8fd4\u56de 0\u3002\u56e0\u4e3a\u53ea\u6709nums[0]\u7b49\u4e8e1\u3002\nsolution.pick(1);\n
    \n", "tags_en": ["Reservoir Sampling"], "tags_cn": ["\u84c4\u6c34\u6c60\u62bd\u6837"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n Solution(vector& nums) {\n\n }\n \n int pick(int target) {\n\n }\n};\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution* obj = new Solution(nums);\n * int param_1 = obj->pick(target);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n\n public Solution(int[] nums) {\n\n }\n \n public int pick(int target) {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution obj = new Solution(nums);\n * int param_1 = obj.pick(target);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n\n def __init__(self, nums):\n \"\"\"\n :type nums: List[int]\n \"\"\"\n\n\n def pick(self, target):\n \"\"\"\n :type target: int\n :rtype: int\n \"\"\"\n\n\n\n# Your Solution object will be instantiated and called as such:\n# obj = Solution(nums)\n# param_1 = obj.pick(target)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n\n def __init__(self, nums: List[int]):\n\n\n def pick(self, target: int) -> int:\n\n\n\n# Your Solution object will be instantiated and called as such:\n# obj = Solution(nums)\n# param_1 = obj.pick(target)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} Solution;\n\n\nSolution* solutionCreate(int* nums, int numsSize) {\n\n}\n\nint solutionPick(Solution* obj, int target) {\n\n}\n\nvoid solutionFree(Solution* obj) {\n\n}\n\n/**\n * Your Solution struct will be instantiated and called as such:\n * Solution* obj = solutionCreate(nums, numsSize);\n * int param_1 = solutionPick(obj, target);\n \n * solutionFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n\n public Solution(int[] nums) {\n\n }\n \n public int Pick(int target) {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution obj = new Solution(nums);\n * int param_1 = obj.Pick(target);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n */\nvar Solution = function(nums) {\n\n};\n\n/** \n * @param {number} target\n * @return {number}\n */\nSolution.prototype.pick = function(target) {\n\n};\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = new Solution(nums)\n * var param_1 = obj.pick(target)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class Solution\n\n=begin\n :type nums: Integer[]\n=end\n def initialize(nums)\n\n end\n\n\n=begin\n :type target: Integer\n :rtype: Integer\n=end\n def pick(target)\n\n end\n\n\nend\n\n# Your Solution object will be instantiated and called as such:\n# obj = Solution.new(nums)\n# param_1 = obj.pick(target)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass Solution {\n\n init(_ nums: [Int]) {\n\n }\n \n func pick(_ target: Int) -> Int {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * let obj = Solution(nums)\n * let ret_1: Int = obj.pick(target)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type Solution struct {\n\n}\n\n\nfunc Constructor(nums []int) Solution {\n\n}\n\n\nfunc (this *Solution) Pick(target int) int {\n\n}\n\n\n/**\n * Your Solution object will be instantiated and called as such:\n * obj := Constructor(nums);\n * param_1 := obj.Pick(target);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class Solution(_nums: Array[Int]) {\n\n def pick(target: Int): Int = {\n\n }\n\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = new Solution(nums)\n * var param_1 = obj.pick(target)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution(nums: IntArray) {\n\n fun pick(target: Int): Int {\n\n }\n\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = Solution(nums)\n * var param_1 = obj.pick(target)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct Solution {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl Solution {\n\n fn new(nums: Vec) -> Self {\n\n }\n \n fn pick(&self, target: i32) -> i32 {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * let obj = Solution::new(nums);\n * let ret_1: i32 = obj.pick(target);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n /**\n * @param Integer[] $nums\n */\n function __construct($nums) {\n\n }\n\n /**\n * @param Integer $target\n * @return Integer\n */\n function pick($target) {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * $obj = Solution($nums);\n * $ret_1 = $obj->pick($target);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class Solution {\n constructor(nums: number[]) {\n\n }\n\n pick(target: number): number {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = new Solution(nums)\n * var param_1 = obj.pick(target)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define solution%\n (class object%\n (super-new)\n\n ; nums : (listof exact-integer?)\n (init-field\n nums)\n \n ; pick : exact-integer? -> exact-integer?\n (define/public (pick target)\n\n )))\n\n;; Your solution% object will be instantiated and called as such:\n;; (define obj (new solution% [nums nums]))\n;; (define param_1 (send obj pick target))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0398](https://leetcode-cn.com/problems/random-pick-index)", "[\u968f\u673a\u6570\u7d22\u5f15](/solution/0300-0399/0398.Random%20Pick%20Index/README.md)", "`\u84c4\u6c34\u6c60\u62bd\u6837`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0398](https://leetcode.com/problems/random-pick-index)", "[Random Pick Index](/solution/0300-0399/0398.Random%20Pick%20Index/README_EN.md)", "`Reservoir Sampling`", "Medium", ""]}, {"question_id": "0397", "frontend_question_id": "0397", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/integer-replacement", "url_en": "https://leetcode.com/problems/integer-replacement", "relative_path_cn": "/solution/0300-0399/0397.Integer%20Replacement/README.md", "relative_path_en": "/solution/0300-0399/0397.Integer%20Replacement/README_EN.md", "title_cn": "\u6574\u6570\u66ff\u6362", "title_en": "Integer Replacement", "question_title_slug": "integer-replacement", "content_en": "

    Given a positive integer n, you can apply one of the following operations:

    \n\n
      \n\t
    1. If n is even, replace n with n / 2.
    2. \n\t
    3. If n is odd, replace n with either n + 1 or n - 1.
    4. \n
    \n\n

    Return the minimum number of operations needed for n to become 1.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 8\nOutput: 3\nExplanation: 8 -> 4 -> 2 -> 1\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 7\nOutput: 4\nExplanation: 7 -> 8 -> 4 -> 2 -> 1\nor 7 -> 6 -> 3 -> 2 -> 1\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 4\nOutput: 2\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 231 - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6b63\u6574\u6570\u00a0n \uff0c\u4f60\u53ef\u4ee5\u505a\u5982\u4e0b\u64cd\u4f5c\uff1a

    \n\n
      \n\t
    1. \u5982\u679c\u00a0n\u00a0\u662f\u5076\u6570\uff0c\u5219\u7528\u00a0n / 2\u66ff\u6362\u00a0n \u3002
    2. \n\t
    3. \u5982\u679c\u00a0n\u00a0\u662f\u5947\u6570\uff0c\u5219\u53ef\u4ee5\u7528\u00a0n + 1\u6216n - 1\u66ff\u6362\u00a0n \u3002
    4. \n
    \n\n

    n\u00a0\u53d8\u4e3a 1 \u6240\u9700\u7684\u6700\u5c0f\u66ff\u6362\u6b21\u6570\u662f\u591a\u5c11\uff1f

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 8\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a8 -> 4 -> 2 -> 1\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 7\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a7 -> 8 -> 4 -> 2 -> 1\n\u6216 7 -> 6 -> 3 -> 2 -> 1\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 4\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 231 - 1
    • \n
    \n", "tags_en": ["Bit Manipulation", "Math"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int integerReplacement(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int integerReplacement(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def integerReplacement(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def integerReplacement(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint integerReplacement(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int IntegerReplacement(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar integerReplacement = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef integer_replacement(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func integerReplacement(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func integerReplacement(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def integerReplacement(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun integerReplacement(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn integer_replacement(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function integerReplacement($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function integerReplacement(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (integer-replacement n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0397](https://leetcode-cn.com/problems/integer-replacement)", "[\u6574\u6570\u66ff\u6362](/solution/0300-0399/0397.Integer%20Replacement/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0397](https://leetcode.com/problems/integer-replacement)", "[Integer Replacement](/solution/0300-0399/0397.Integer%20Replacement/README_EN.md)", "`Bit Manipulation`,`Math`", "Medium", ""]}, {"question_id": "0396", "frontend_question_id": "0396", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/rotate-function", "url_en": "https://leetcode.com/problems/rotate-function", "relative_path_cn": "/solution/0300-0399/0396.Rotate%20Function/README.md", "relative_path_en": "/solution/0300-0399/0396.Rotate%20Function/README_EN.md", "title_cn": "\u65cb\u8f6c\u51fd\u6570", "title_en": "Rotate Function", "question_title_slug": "rotate-function", "content_en": "

    You are given an integer array nums of length n.

    \n\n

    Assume arrk to be an array obtained by rotating nums by k positions clock-wise. We define the rotation function F on nums as follow:

    \n\n
      \n\t
    • F(k) = 0 * arrk[0] + 1 * arrk[1] + ... + (n - 1) * arrk[n - 1].
    • \n
    \n\n

    Return the maximum value of F(0), F(1), ..., F(n-1).

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [4,3,2,6]\nOutput: 26\nExplanation:\nF(0) = (0 * 4) + (1 * 3) + (2 * 2) + (3 * 6) = 0 + 3 + 4 + 18 = 25\nF(1) = (0 * 6) + (1 * 4) + (2 * 3) + (3 * 2) = 0 + 4 + 6 + 6 = 16\nF(2) = (0 * 2) + (1 * 6) + (2 * 4) + (3 * 3) = 0 + 6 + 8 + 9 = 23\nF(3) = (0 * 3) + (1 * 2) + (2 * 6) + (3 * 4) = 0 + 2 + 12 + 12 = 26\nSo the maximum value of F(0), F(1), F(2), F(3) is F(3) = 26.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1000000007]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= n <= 3 * 104
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u6574\u6570\u6570\u7ec4 A \u3002

    \n\n

    \u5047\u8bbe Bk \u662f\u6570\u7ec4 A \u987a\u65f6\u9488\u65cb\u8f6c k \u4e2a\u4f4d\u7f6e\u540e\u7684\u6570\u7ec4\uff0c\u6211\u4eec\u5b9a\u4e49 A \u7684“\u65cb\u8f6c\u51fd\u6570” F \u4e3a\uff1a

    \n\n

    F(k) = 0 * Bk[0] + 1 * Bk[1] + ... + (n-1) * Bk[n-1]\u3002

    \n\n

    \u8ba1\u7b97F(0), F(1), ..., F(n-1)\u4e2d\u7684\u6700\u5927\u503c\u3002

    \n\n

    \u6ce8\u610f:
    \n\u53ef\u4ee5\u8ba4\u4e3a n \u7684\u503c\u5c0f\u4e8e 105\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \nA = [4, 3, 2, 6]\n\nF(0) = (0 * 4) + (1 * 3) + (2 * 2) + (3 * 6) = 0 + 3 + 4 + 18 = 25\nF(1) = (0 * 6) + (1 * 4) + (2 * 3) + (3 * 2) = 0 + 4 + 6 + 6 = 16\nF(2) = (0 * 2) + (1 * 6) + (2 * 4) + (3 * 3) = 0 + 6 + 8 + 9 = 23\nF(3) = (0 * 3) + (1 * 2) + (2 * 6) + (3 * 4) = 0 + 2 + 12 + 12 = 26\n\n\u6240\u4ee5 F(0), F(1), F(2), F(3) \u4e2d\u7684\u6700\u5927\u503c\u662f F(3) = 26 \u3002\n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxRotateFunction(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxRotateFunction(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxRotateFunction(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxRotateFunction(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxRotateFunction(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxRotateFunction(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar maxRotateFunction = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef max_rotate_function(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxRotateFunction(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxRotateFunction(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxRotateFunction(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxRotateFunction(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_rotate_function(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function maxRotateFunction($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxRotateFunction(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-rotate-function nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0396](https://leetcode-cn.com/problems/rotate-function)", "[\u65cb\u8f6c\u51fd\u6570](/solution/0300-0399/0396.Rotate%20Function/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0396](https://leetcode.com/problems/rotate-function)", "[Rotate Function](/solution/0300-0399/0396.Rotate%20Function/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "0395", "frontend_question_id": "0395", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-substring-with-at-least-k-repeating-characters", "url_en": "https://leetcode.com/problems/longest-substring-with-at-least-k-repeating-characters", "relative_path_cn": "/solution/0300-0399/0395.Longest%20Substring%20with%20At%20Least%20K%20Repeating%20Characters/README.md", "relative_path_en": "/solution/0300-0399/0395.Longest%20Substring%20with%20At%20Least%20K%20Repeating%20Characters/README_EN.md", "title_cn": "\u81f3\u5c11\u6709 K \u4e2a\u91cd\u590d\u5b57\u7b26\u7684\u6700\u957f\u5b50\u4e32", "title_en": "Longest Substring with At Least K Repeating Characters", "question_title_slug": "longest-substring-with-at-least-k-repeating-characters", "content_en": "

    Given a string s and an integer k, return the length of the longest substring of s such that the frequency of each character in this substring is greater than or equal to k.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "aaabb", k = 3\nOutput: 3\nExplanation: The longest substring is "aaa", as 'a' is repeated 3 times.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "ababbc", k = 2\nOutput: 5\nExplanation: The longest substring is "ababb", as 'a' is repeated 2 times and 'b' is repeated 3 times.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 104
    • \n\t
    • s consists of only lowercase English letters.
    • \n\t
    • 1 <= k <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \u548c\u4e00\u4e2a\u6574\u6570 k \uff0c\u8bf7\u4f60\u627e\u51fa s \u4e2d\u7684\u6700\u957f\u5b50\u4e32\uff0c\u00a0\u8981\u6c42\u8be5\u5b50\u4e32\u4e2d\u7684\u6bcf\u4e00\u5b57\u7b26\u51fa\u73b0\u6b21\u6570\u90fd\u4e0d\u5c11\u4e8e k \u3002\u8fd4\u56de\u8fd9\u4e00\u5b50\u4e32\u7684\u957f\u5ea6\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"aaabb\", k = 3\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6700\u957f\u5b50\u4e32\u4e3a \"aaa\" \uff0c\u5176\u4e2d 'a' \u91cd\u590d\u4e86 3 \u6b21\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"ababbc\", k = 2\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u6700\u957f\u5b50\u4e32\u4e3a \"ababb\" \uff0c\u5176\u4e2d 'a' \u91cd\u590d\u4e86 2 \u6b21\uff0c 'b' \u91cd\u590d\u4e86 3 \u6b21\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 104
    • \n\t
    • s \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n\t
    • 1 <= k <= 105
    • \n
    \n", "tags_en": ["Recursion", "Divide and Conquer", "Sliding Window"], "tags_cn": ["\u9012\u5f52", "\u5206\u6cbb\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int longestSubstring(string s, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int longestSubstring(String s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestSubstring(self, s, k):\n \"\"\"\n :type s: str\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestSubstring(self, s: str, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint longestSubstring(char * s, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LongestSubstring(string s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number} k\n * @return {number}\n */\nvar longestSubstring = function(s, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer} k\n# @return {Integer}\ndef longest_substring(s, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestSubstring(_ s: String, _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestSubstring(s string, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestSubstring(s: String, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestSubstring(s: String, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_substring(s: String, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer $k\n * @return Integer\n */\n function longestSubstring($s, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestSubstring(s: string, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-substring s k)\n (-> string? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0395](https://leetcode-cn.com/problems/longest-substring-with-at-least-k-repeating-characters)", "[\u81f3\u5c11\u6709 K \u4e2a\u91cd\u590d\u5b57\u7b26\u7684\u6700\u957f\u5b50\u4e32](/solution/0300-0399/0395.Longest%20Substring%20with%20At%20Least%20K%20Repeating%20Characters/README.md)", "`\u9012\u5f52`,`\u5206\u6cbb\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0395](https://leetcode.com/problems/longest-substring-with-at-least-k-repeating-characters)", "[Longest Substring with At Least K Repeating Characters](/solution/0300-0399/0395.Longest%20Substring%20with%20At%20Least%20K%20Repeating%20Characters/README_EN.md)", "`Recursion`,`Divide and Conquer`,`Sliding Window`", "Medium", ""]}, {"question_id": "0394", "frontend_question_id": "0394", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/decode-string", "url_en": "https://leetcode.com/problems/decode-string", "relative_path_cn": "/solution/0300-0399/0394.Decode%20String/README.md", "relative_path_en": "/solution/0300-0399/0394.Decode%20String/README_EN.md", "title_cn": "\u5b57\u7b26\u4e32\u89e3\u7801", "title_en": "Decode String", "question_title_slug": "decode-string", "content_en": "

    Given an encoded string, return its decoded string.

    \n\n

    The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note that k is guaranteed to be a positive integer.

    \n\n

    You may assume that the input string is always valid; No extra white spaces, square brackets are well-formed, etc.

    \n\n

    Furthermore, you may assume that the original data does not contain any digits and that digits are only for those repeat numbers, k. For example, there won't be input like 3a or 2[4].

    \n\n

     

    \n

    Example 1:

    \n
    Input: s = \"3[a]2[bc]\"\nOutput: \"aaabcbc\"\n

    Example 2:

    \n
    Input: s = \"3[a2[c]]\"\nOutput: \"accaccacc\"\n

    Example 3:

    \n
    Input: s = \"2[abc]3[cd]ef\"\nOutput: \"abcabccdcdcdef\"\n

    Example 4:

    \n
    Input: s = \"abc3[cd]xyz\"\nOutput: \"abccdcdcdxyz\"\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 30
    • \n\t
    • s consists of lowercase English letters, digits, and square brackets '[]'.
    • \n\t
    • s is guaranteed to be a valid input.
    • \n\t
    • All the integers in s are in the range [1, 300].
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u7ecf\u8fc7\u7f16\u7801\u7684\u5b57\u7b26\u4e32\uff0c\u8fd4\u56de\u5b83\u89e3\u7801\u540e\u7684\u5b57\u7b26\u4e32\u3002

    \n\n

    \u7f16\u7801\u89c4\u5219\u4e3a: k[encoded_string]\uff0c\u8868\u793a\u5176\u4e2d\u65b9\u62ec\u53f7\u5185\u90e8\u7684 encoded_string \u6b63\u597d\u91cd\u590d k \u6b21\u3002\u6ce8\u610f k \u4fdd\u8bc1\u4e3a\u6b63\u6574\u6570\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u8ba4\u4e3a\u8f93\u5165\u5b57\u7b26\u4e32\u603b\u662f\u6709\u6548\u7684\uff1b\u8f93\u5165\u5b57\u7b26\u4e32\u4e2d\u6ca1\u6709\u989d\u5916\u7684\u7a7a\u683c\uff0c\u4e14\u8f93\u5165\u7684\u65b9\u62ec\u53f7\u603b\u662f\u7b26\u5408\u683c\u5f0f\u8981\u6c42\u7684\u3002

    \n\n

    \u6b64\u5916\uff0c\u4f60\u53ef\u4ee5\u8ba4\u4e3a\u539f\u59cb\u6570\u636e\u4e0d\u5305\u542b\u6570\u5b57\uff0c\u6240\u6709\u7684\u6570\u5b57\u53ea\u8868\u793a\u91cd\u590d\u7684\u6b21\u6570 k \uff0c\u4f8b\u5982\u4e0d\u4f1a\u51fa\u73b0\u50cf 3a \u6216 2[4] \u7684\u8f93\u5165\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1as = "3[a]2[bc]"\n\u8f93\u51fa\uff1a"aaabcbc"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1as = "3[a2[c]]"\n\u8f93\u51fa\uff1a"accaccacc"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1as = "2[abc]3[cd]ef"\n\u8f93\u51fa\uff1a"abcabccdcdcdef"\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1as = "abc3[cd]xyz"\n\u8f93\u51fa\uff1a"abccdcdcdxyz"\n
    \n", "tags_en": ["Stack", "Depth-first Search"], "tags_cn": ["\u6808", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string decodeString(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String decodeString(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def decodeString(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def decodeString(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * decodeString(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string DecodeString(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar decodeString = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef decode_string(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func decodeString(_ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func decodeString(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def decodeString(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun decodeString(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn decode_string(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function decodeString($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function decodeString(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (decode-string s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0394](https://leetcode-cn.com/problems/decode-string)", "[\u5b57\u7b26\u4e32\u89e3\u7801](/solution/0300-0399/0394.Decode%20String/README.md)", "`\u6808`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0394](https://leetcode.com/problems/decode-string)", "[Decode String](/solution/0300-0399/0394.Decode%20String/README_EN.md)", "`Stack`,`Depth-first Search`", "Medium", ""]}, {"question_id": "0393", "frontend_question_id": "0393", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/utf-8-validation", "url_en": "https://leetcode.com/problems/utf-8-validation", "relative_path_cn": "/solution/0300-0399/0393.UTF-8%20Validation/README.md", "relative_path_en": "/solution/0300-0399/0393.UTF-8%20Validation/README_EN.md", "title_cn": "UTF-8 \u7f16\u7801\u9a8c\u8bc1", "title_en": "UTF-8 Validation", "question_title_slug": "utf-8-validation", "content_en": "

    Given an integer array data representing the data, return whether it is a valid UTF-8 encoding.

    \n\n

    A character in UTF8 can be from 1 to 4 bytes long, subjected to the following rules:

    \n\n
      \n\t
    1. For a 1-byte character, the first bit is a 0, followed by its Unicode code.
    2. \n\t
    3. For an n-bytes character, the first n bits are all one's, the n + 1 bit is 0, followed by n - 1 bytes with the most significant 2 bits being 10.
    4. \n
    \n\n

    This is how the UTF-8 encoding would work:

    \n\n
    \n   Char. number range  |        UTF-8 octet sequence\n      (hexadecimal)    |              (binary)\n   --------------------+---------------------------------------------\n   0000 0000-0000 007F | 0xxxxxxx\n   0000 0080-0000 07FF | 110xxxxx 10xxxxxx\n   0000 0800-0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx\n   0001 0000-0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx\n
    \n\n

    Note: The input is an array of integers. Only the least significant 8 bits of each integer is used to store the data. This means each integer represents only 1 byte of data.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: data = [197,130,1]\nOutput: true\nExplanation: data represents the octet sequence: 11000101 10000010 00000001.\nIt is a valid utf-8 encoding for a 2-bytes character followed by a 1-byte character.\n
    \n\n

    Example 2:

    \n\n
    \nInput: data = [235,140,4]\nOutput: false\nExplanation: data represented the octet sequence: 11101011 10001100 00000100.\nThe first 3 bits are all one's and the 4th bit is 0 means it is a 3-bytes character.\nThe next byte is a continuation byte which starts with 10 and that's correct.\nBut the second continuation byte does not start with 10, so it is invalid.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= data.length <= 2 * 104
    • \n\t
    • 0 <= data[i] <= 255
    • \n
    \n", "content_cn": "

    UTF-8 \u4e2d\u7684\u4e00\u4e2a\u5b57\u7b26\u53ef\u80fd\u7684\u957f\u5ea6\u4e3a 1 \u5230 4 \u5b57\u8282\uff0c\u9075\u5faa\u4ee5\u4e0b\u7684\u89c4\u5219\uff1a

    \n\n
      \n\t
    1. \u5bf9\u4e8e 1 \u5b57\u8282\u7684\u5b57\u7b26\uff0c\u5b57\u8282\u7684\u7b2c\u4e00\u4f4d\u8bbe\u4e3a 0 \uff0c\u540e\u9762 7 \u4f4d\u4e3a\u8fd9\u4e2a\u7b26\u53f7\u7684 unicode \u7801\u3002
    2. \n\t
    3. \u5bf9\u4e8e n \u5b57\u8282\u7684\u5b57\u7b26 (n > 1)\uff0c\u7b2c\u4e00\u4e2a\u5b57\u8282\u7684\u524d n \u4f4d\u90fd\u8bbe\u4e3a1\uff0c\u7b2c n+1 \u4f4d\u8bbe\u4e3a 0 \uff0c\u540e\u9762\u5b57\u8282\u7684\u524d\u4e24\u4f4d\u4e00\u5f8b\u8bbe\u4e3a 10 \u3002\u5269\u4e0b\u7684\u6ca1\u6709\u63d0\u53ca\u7684\u4e8c\u8fdb\u5236\u4f4d\uff0c\u5168\u90e8\u4e3a\u8fd9\u4e2a\u7b26\u53f7\u7684 unicode \u7801\u3002
    4. \n
    \n\n

    \u8fd9\u662f UTF-8 \u7f16\u7801\u7684\u5de5\u4f5c\u65b9\u5f0f\uff1a

    \n\n
    \n   Char. number range  |        UTF-8 octet sequence\n      (hexadecimal)    |              (binary)\n   --------------------+---------------------------------------------\n   0000 0000-0000 007F | 0xxxxxxx\n   0000 0080-0000 07FF | 110xxxxx 10xxxxxx\n   0000 0800-0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx\n   0001 0000-0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx\n
    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u8868\u793a\u6570\u636e\u7684\u6574\u6570\u6570\u7ec4\uff0c\u8fd4\u56de\u5b83\u662f\u5426\u4e3a\u6709\u6548\u7684 utf-8 \u7f16\u7801\u3002

    \n\n

    \u6ce8\u610f\uff1a
    \n\u8f93\u5165\u662f\u6574\u6570\u6570\u7ec4\u3002\u53ea\u6709\u6bcf\u4e2a\u6574\u6570\u7684 \u6700\u4f4e 8 \u4e2a\u6709\u6548\u4f4d \u7528\u6765\u5b58\u50a8\u6570\u636e\u3002\u8fd9\u610f\u5473\u7740\u6bcf\u4e2a\u6574\u6570\u53ea\u8868\u793a 1 \u5b57\u8282\u7684\u6570\u636e\u3002

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \ndata = [197, 130, 1], \u8868\u793a 8 \u4f4d\u7684\u5e8f\u5217: 11000101 10000010 00000001.\n\n\u8fd4\u56de true \u3002\n\u8fd9\u662f\u6709\u6548\u7684 utf-8 \u7f16\u7801\uff0c\u4e3a\u4e00\u4e2a2\u5b57\u8282\u5b57\u7b26\uff0c\u8ddf\u7740\u4e00\u4e2a1\u5b57\u8282\u5b57\u7b26\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \ndata = [235, 140, 4], \u8868\u793a 8 \u4f4d\u7684\u5e8f\u5217: 11101011 10001100 00000100.\n\n\u8fd4\u56de false \u3002\n\u524d 3 \u4f4d\u90fd\u662f 1 \uff0c\u7b2c 4 \u4f4d\u4e3a 0 \u8868\u793a\u5b83\u662f\u4e00\u4e2a3\u5b57\u8282\u5b57\u7b26\u3002\n\u4e0b\u4e00\u4e2a\u5b57\u8282\u662f\u5f00\u5934\u4e3a 10 \u7684\u5ef6\u7eed\u5b57\u8282\uff0c\u8fd9\u662f\u6b63\u786e\u7684\u3002\n\u4f46\u7b2c\u4e8c\u4e2a\u5ef6\u7eed\u5b57\u8282\u4e0d\u4ee5 10 \u5f00\u5934\uff0c\u6240\u4ee5\u662f\u4e0d\u7b26\u5408\u89c4\u5219\u7684\u3002\n
    \n", "tags_en": ["Bit Manipulation"], "tags_cn": ["\u4f4d\u8fd0\u7b97"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool validUtf8(vector& data) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean validUtf8(int[] data) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def validUtf8(self, data):\n \"\"\"\n :type data: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def validUtf8(self, data: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool validUtf8(int* data, int dataSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool ValidUtf8(int[] data) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} data\n * @return {boolean}\n */\nvar validUtf8 = function(data) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} data\n# @return {Boolean}\ndef valid_utf8(data)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func validUtf8(_ data: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func validUtf8(data []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def validUtf8(data: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun validUtf8(data: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn valid_utf8(data: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $data\n * @return Boolean\n */\n function validUtf8($data) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function validUtf8(data: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (valid-utf8 data)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0393](https://leetcode-cn.com/problems/utf-8-validation)", "[UTF-8 \u7f16\u7801\u9a8c\u8bc1](/solution/0300-0399/0393.UTF-8%20Validation/README.md)", "`\u4f4d\u8fd0\u7b97`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0393](https://leetcode.com/problems/utf-8-validation)", "[UTF-8 Validation](/solution/0300-0399/0393.UTF-8%20Validation/README_EN.md)", "`Bit Manipulation`", "Medium", ""]}, {"question_id": "0392", "frontend_question_id": "0392", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/is-subsequence", "url_en": "https://leetcode.com/problems/is-subsequence", "relative_path_cn": "/solution/0300-0399/0392.Is%20Subsequence/README.md", "relative_path_en": "/solution/0300-0399/0392.Is%20Subsequence/README_EN.md", "title_cn": "\u5224\u65ad\u5b50\u5e8f\u5217", "title_en": "Is Subsequence", "question_title_slug": "is-subsequence", "content_en": "

    Given two strings s and t, return true if s is a subsequence of t, or false otherwise.

    \n\n

    A subsequence of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., "ace" is a subsequence of "abcde" while "aec" is not).

    \n\n

     

    \n

    Example 1:

    \n
    Input: s = \"abc\", t = \"ahbgdc\"\nOutput: true\n

    Example 2:

    \n
    Input: s = \"axc\", t = \"ahbgdc\"\nOutput: false\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= s.length <= 100
    • \n\t
    • 0 <= t.length <= 104
    • \n\t
    • s and t consist only of lowercase English letters.
    • \n
    \n\n

     

    \nFollow up: Suppose there are lots of incoming s, say s1, s2, ..., sk where k >= 109, and you want to check one by one to see if t has its subsequence. In this scenario, how would you change your code?", "content_cn": "

    \u7ed9\u5b9a\u5b57\u7b26\u4e32 s \u548c t \uff0c\u5224\u65ad s \u662f\u5426\u4e3a t \u7684\u5b50\u5e8f\u5217\u3002

    \n\n

    \u5b57\u7b26\u4e32\u7684\u4e00\u4e2a\u5b50\u5e8f\u5217\u662f\u539f\u59cb\u5b57\u7b26\u4e32\u5220\u9664\u4e00\u4e9b\uff08\u4e5f\u53ef\u4ee5\u4e0d\u5220\u9664\uff09\u5b57\u7b26\u800c\u4e0d\u6539\u53d8\u5269\u4f59\u5b57\u7b26\u76f8\u5bf9\u4f4d\u7f6e\u5f62\u6210\u7684\u65b0\u5b57\u7b26\u4e32\u3002\uff08\u4f8b\u5982\uff0c\"ace\"\u662f\"abcde\"\u7684\u4e00\u4e2a\u5b50\u5e8f\u5217\uff0c\u800c\"aec\"\u4e0d\u662f\uff09\u3002

    \n\n

    \u8fdb\u9636\uff1a

    \n\n

    \u5982\u679c\u6709\u5927\u91cf\u8f93\u5165\u7684 S\uff0c\u79f0\u4f5c S1, S2, ... , Sk \u5176\u4e2d k >= 10\u4ebf\uff0c\u4f60\u9700\u8981\u4f9d\u6b21\u68c0\u67e5\u5b83\u4eec\u662f\u5426\u4e3a T \u7684\u5b50\u5e8f\u5217\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u4f60\u4f1a\u600e\u6837\u6539\u53d8\u4ee3\u7801\uff1f

    \n\n

    \u81f4\u8c22\uff1a

    \n\n

    \u7279\u522b\u611f\u8c22 @pbrother\u00a0\u6dfb\u52a0\u6b64\u95ee\u9898\u5e76\u4e14\u521b\u5efa\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"abc\", t = \"ahbgdc\"\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"axc\", t = \"ahbgdc\"\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= s.length <= 100
    • \n\t
    • 0 <= t.length <= 10^4
    • \n\t
    • \u4e24\u4e2a\u5b57\u7b26\u4e32\u90fd\u53ea\u7531\u5c0f\u5199\u5b57\u7b26\u7ec4\u6210\u3002
    • \n
    \n", "tags_en": ["Greedy", "Binary Search", "Dynamic Programming"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u4e8c\u5206\u67e5\u627e", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isSubsequence(string s, string t) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isSubsequence(String s, String t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isSubsequence(self, s, t):\n \"\"\"\n :type s: str\n :type t: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isSubsequence(self, s: str, t: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isSubsequence(char * s, char * t){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsSubsequence(string s, string t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string} t\n * @return {boolean}\n */\nvar isSubsequence = function(s, t) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String} t\n# @return {Boolean}\ndef is_subsequence(s, t)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isSubsequence(_ s: String, _ t: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isSubsequence(s string, t string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isSubsequence(s: String, t: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isSubsequence(s: String, t: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_subsequence(s: String, t: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String $t\n * @return Boolean\n */\n function isSubsequence($s, $t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isSubsequence(s: string, t: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-subsequence s t)\n (-> string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0392](https://leetcode-cn.com/problems/is-subsequence)", "[\u5224\u65ad\u5b50\u5e8f\u5217](/solution/0300-0399/0392.Is%20Subsequence/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u4e8c\u5206\u67e5\u627e`,`\u52a8\u6001\u89c4\u5212`", "\u7b80\u5355", ""], "md_table_row_en": ["[0392](https://leetcode.com/problems/is-subsequence)", "[Is Subsequence](/solution/0300-0399/0392.Is%20Subsequence/README_EN.md)", "`Greedy`,`Binary Search`,`Dynamic Programming`", "Easy", ""]}, {"question_id": "0391", "frontend_question_id": "0391", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/perfect-rectangle", "url_en": "https://leetcode.com/problems/perfect-rectangle", "relative_path_cn": "/solution/0300-0399/0391.Perfect%20Rectangle/README.md", "relative_path_en": "/solution/0300-0399/0391.Perfect%20Rectangle/README_EN.md", "title_cn": "\u5b8c\u7f8e\u77e9\u5f62", "title_en": "Perfect Rectangle", "question_title_slug": "perfect-rectangle", "content_en": "

    Given an array rectangles where rectangles[i] = [xi, yi, ai, bi] represents an axis-aligned rectangle. The bottom-left point of the rectangle is (xi, yi) and the top-right point of it is (ai, bi).

    \n\n

    Return true if all the rectangles together form an exact cover of a rectangular region.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: rectangles = [[1,1,3,3],[3,1,4,2],[3,2,4,4],[1,3,2,4],[2,3,3,4]]\nOutput: true\nExplanation: All 5 rectangles together form an exact cover of a rectangular region.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: rectangles = [[1,1,2,3],[1,3,2,4],[3,1,4,2],[3,2,4,4]]\nOutput: false\nExplanation: Because there is a gap between the two rectangular regions.\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: rectangles = [[1,1,3,3],[3,1,4,2],[1,3,2,4],[3,2,4,4]]\nOutput: false\nExplanation: Because there is a gap in the top center.\n
    \n\n

    Example 4:

    \n\"\"\n
    \nInput: rectangles = [[1,1,3,3],[3,1,4,2],[1,3,2,4],[2,2,4,4]]\nOutput: false\nExplanation: Because two of the rectangles overlap with each other.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= rectangles.length <= 2 * 104
    • \n\t
    • rectangles[i].length == 4
    • \n\t
    • -105 <= xi, yi, ai, bi <= 105
    • \n
    \n", "content_cn": "

    \u6211\u4eec\u6709 N \u4e2a\u4e0e\u5750\u6807\u8f74\u5bf9\u9f50\u7684\u77e9\u5f62, \u5176\u4e2d N > 0, \u5224\u65ad\u5b83\u4eec\u662f\u5426\u80fd\u7cbe\u786e\u5730\u8986\u76d6\u4e00\u4e2a\u77e9\u5f62\u533a\u57df\u3002

    \n\n

    \u6bcf\u4e2a\u77e9\u5f62\u7528\u5de6\u4e0b\u89d2\u7684\u70b9\u548c\u53f3\u4e0a\u89d2\u7684\u70b9\u7684\u5750\u6807\u6765\u8868\u793a\u3002\u4f8b\u5982\uff0c \u4e00\u4e2a\u5355\u4f4d\u6b63\u65b9\u5f62\u53ef\u4ee5\u8868\u793a\u4e3a [1,1,2,2]\u3002 ( \u5de6\u4e0b\u89d2\u7684\u70b9\u7684\u5750\u6807\u4e3a (1, 1) \u4ee5\u53ca\u53f3\u4e0a\u89d2\u7684\u70b9\u7684\u5750\u6807\u4e3a (2, 2) )\u3002

    \n\n

    \n\n

    \u793a\u4f8b 1:

    \n\n
    rectangles = [\n  [1,1,3,3],\n  [3,1,4,2],\n  [3,2,4,4],\n  [1,3,2,4],\n  [2,3,3,4]\n]\n\n\u8fd4\u56de true\u30025\u4e2a\u77e9\u5f62\u4e00\u8d77\u53ef\u4ee5\u7cbe\u786e\u5730\u8986\u76d6\u4e00\u4e2a\u77e9\u5f62\u533a\u57df\u3002\n
    \n\n

     

    \n\n

    \n\n

    \u793a\u4f8b 2:

    \n\n
    rectangles = [\n  [1,1,2,3],\n  [1,3,2,4],\n  [3,1,4,2],\n  [3,2,4,4]\n]\n\n\u8fd4\u56de false\u3002\u4e24\u4e2a\u77e9\u5f62\u4e4b\u95f4\u6709\u95f4\u9694\uff0c\u65e0\u6cd5\u8986\u76d6\u6210\u4e00\u4e2a\u77e9\u5f62\u3002\n
    \n\n

     

    \n\n

    \n\n

    \u793a\u4f8b 3:

    \n\n
    rectangles = [\n  [1,1,3,3],\n  [3,1,4,2],\n  [1,3,2,4],\n  [3,2,4,4]\n]\n\n\u8fd4\u56de false\u3002\u56fe\u5f62\u9876\u7aef\u7559\u6709\u95f4\u9694\uff0c\u65e0\u6cd5\u8986\u76d6\u6210\u4e00\u4e2a\u77e9\u5f62\u3002\n
    \n\n

     

    \n\n

    \n\n

    \u793a\u4f8b 4:

    \n\n
    rectangles = [\n  [1,1,3,3],\n  [3,1,4,2],\n  [1,3,2,4],\n  [2,2,4,4]\n]\n\n\u8fd4\u56de false\u3002\u56e0\u4e3a\u4e2d\u95f4\u6709\u76f8\u4ea4\u533a\u57df\uff0c\u867d\u7136\u5f62\u6210\u4e86\u77e9\u5f62\uff0c\u4f46\u4e0d\u662f\u7cbe\u786e\u8986\u76d6\u3002\n
    \n", "tags_en": ["Line Sweep"], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isRectangleCover(vector>& rectangles) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isRectangleCover(int[][] rectangles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isRectangleCover(self, rectangles):\n \"\"\"\n :type rectangles: List[List[int]]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isRectangleCover(self, rectangles: List[List[int]]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isRectangleCover(int** rectangles, int rectanglesSize, int* rectanglesColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsRectangleCover(int[][] rectangles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} rectangles\n * @return {boolean}\n */\nvar isRectangleCover = function(rectangles) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} rectangles\n# @return {Boolean}\ndef is_rectangle_cover(rectangles)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isRectangleCover(_ rectangles: [[Int]]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isRectangleCover(rectangles [][]int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isRectangleCover(rectangles: Array[Array[Int]]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isRectangleCover(rectangles: Array): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_rectangle_cover(rectangles: Vec>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $rectangles\n * @return Boolean\n */\n function isRectangleCover($rectangles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isRectangleCover(rectangles: number[][]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-rectangle-cover rectangles)\n (-> (listof (listof exact-integer?)) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0391](https://leetcode-cn.com/problems/perfect-rectangle)", "[\u5b8c\u7f8e\u77e9\u5f62](/solution/0300-0399/0391.Perfect%20Rectangle/README.md)", "", "\u56f0\u96be", ""], "md_table_row_en": ["[0391](https://leetcode.com/problems/perfect-rectangle)", "[Perfect Rectangle](/solution/0300-0399/0391.Perfect%20Rectangle/README_EN.md)", "`Line Sweep`", "Hard", ""]}, {"question_id": "0390", "frontend_question_id": "0390", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/elimination-game", "url_en": "https://leetcode.com/problems/elimination-game", "relative_path_cn": "/solution/0300-0399/0390.Elimination%20Game/README.md", "relative_path_en": "/solution/0300-0399/0390.Elimination%20Game/README_EN.md", "title_cn": "\u6d88\u9664\u6e38\u620f", "title_en": "Elimination Game", "question_title_slug": "elimination-game", "content_en": "

    You have a list arr of all integers in the range [1, n] sorted in a strictly increasing order. Apply the following algorithm on arr:

    \n\n
      \n\t
    • Starting from left to right, remove the first number and every other number afterward until you reach the end of the list.
    • \n\t
    • Repeat the previous step again, but this time from right to left, remove the rightmost number and every other number from the remaining numbers.
    • \n\t
    • Keep repeating the steps again, alternating left to right and right to left, until a single number remains.
    • \n
    \n\n

    Given the integer n, return the last number that remains in arr.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 9\nOutput: 6\nExplanation:\narr = [1, 2, 3, 4, 5, 6, 7, 8, 9]\narr = [2, 4, 6, 8]\narr = [2, 6]\narr = [6]\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 1\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4ece1 \u5230 n \u6392\u5e8f\u7684\u6574\u6570\u5217\u8868\u3002
    \n\u9996\u5148\uff0c\u4ece\u5de6\u5230\u53f3\uff0c\u4ece\u7b2c\u4e00\u4e2a\u6570\u5b57\u5f00\u59cb\uff0c\u6bcf\u9694\u4e00\u4e2a\u6570\u5b57\u8fdb\u884c\u5220\u9664\uff0c\u76f4\u5230\u5217\u8868\u7684\u672b\u5c3e\u3002
    \n\u7b2c\u4e8c\u6b65\uff0c\u5728\u5269\u4e0b\u7684\u6570\u5b57\u4e2d\uff0c\u4ece\u53f3\u5230\u5de6\uff0c\u4ece\u5012\u6570\u7b2c\u4e00\u4e2a\u6570\u5b57\u5f00\u59cb\uff0c\u6bcf\u9694\u4e00\u4e2a\u6570\u5b57\u8fdb\u884c\u5220\u9664\uff0c\u76f4\u5230\u5217\u8868\u5f00\u5934\u3002
    \n\u6211\u4eec\u4e0d\u65ad\u91cd\u590d\u8fd9\u4e24\u6b65\uff0c\u4ece\u5de6\u5230\u53f3\u548c\u4ece\u53f3\u5230\u5de6\u4ea4\u66ff\u8fdb\u884c\uff0c\u76f4\u5230\u53ea\u5269\u4e0b\u4e00\u4e2a\u6570\u5b57\u3002
    \n\u8fd4\u56de\u957f\u5ea6\u4e3a n \u7684\u5217\u8868\u4e2d\uff0c\u6700\u540e\u5269\u4e0b\u7684\u6570\u5b57\u3002

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165:\nn = 9,\n1 2 3 4 5 6 7 8 9\n2 4 6 8\n2 6\n6\n\n\u8f93\u51fa:\n6
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int lastRemaining(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int lastRemaining(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def lastRemaining(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def lastRemaining(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint lastRemaining(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LastRemaining(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar lastRemaining = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef last_remaining(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func lastRemaining(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func lastRemaining(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def lastRemaining(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun lastRemaining(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn last_remaining(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function lastRemaining($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function lastRemaining(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (last-remaining n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0390](https://leetcode-cn.com/problems/elimination-game)", "[\u6d88\u9664\u6e38\u620f](/solution/0300-0399/0390.Elimination%20Game/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0390](https://leetcode.com/problems/elimination-game)", "[Elimination Game](/solution/0300-0399/0390.Elimination%20Game/README_EN.md)", "", "Medium", ""]}, {"question_id": "0389", "frontend_question_id": "0389", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-the-difference", "url_en": "https://leetcode.com/problems/find-the-difference", "relative_path_cn": "/solution/0300-0399/0389.Find%20the%20Difference/README.md", "relative_path_en": "/solution/0300-0399/0389.Find%20the%20Difference/README_EN.md", "title_cn": "\u627e\u4e0d\u540c", "title_en": "Find the Difference", "question_title_slug": "find-the-difference", "content_en": "

    You are given two strings s and t.

    \n\n

    String t is generated by random shuffling string s and then add one more letter at a random position.

    \n\n

    Return the letter that was added to t.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "abcd", t = "abcde"\nOutput: "e"\nExplanation: 'e' is the letter that was added.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "", t = "y"\nOutput: "y"\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "a", t = "aa"\nOutput: "a"\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "ae", t = "aea"\nOutput: "a"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= s.length <= 1000
    • \n\t
    • t.length == s.length + 1
    • \n\t
    • s and t consist of lower-case English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u5b57\u7b26\u4e32 s \u548c t\uff0c\u5b83\u4eec\u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd\u3002

    \n\n

    \u5b57\u7b26\u4e32 t \u7531\u5b57\u7b26\u4e32 s \u968f\u673a\u91cd\u6392\uff0c\u7136\u540e\u5728\u968f\u673a\u4f4d\u7f6e\u6dfb\u52a0\u4e00\u4e2a\u5b57\u6bcd\u3002

    \n\n

    \u8bf7\u627e\u51fa\u5728 t \u4e2d\u88ab\u6dfb\u52a0\u7684\u5b57\u6bcd\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1as = "abcd", t = "abcde"\n\u8f93\u51fa\uff1a"e"\n\u89e3\u91ca\uff1a'e' \u662f\u90a3\u4e2a\u88ab\u6dfb\u52a0\u7684\u5b57\u6bcd\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1as = "", t = "y"\n\u8f93\u51fa\uff1a"y"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1as = "a", t = "aa"\n\u8f93\u51fa\uff1a"a"\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1as = "ae", t = "aea"\n\u8f93\u51fa\uff1a"a"\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= s.length <= 1000
    • \n\t
    • t.length == s.length + 1
    • \n\t
    • s \u548c t \u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd
    • \n
    \n", "tags_en": ["Bit Manipulation", "Hash Table"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n char findTheDifference(string s, string t) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public char findTheDifference(String s, String t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findTheDifference(self, s, t):\n \"\"\"\n :type s: str\n :type t: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findTheDifference(self, s: str, t: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar findTheDifference(char * s, char * t){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public char FindTheDifference(string s, string t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string} t\n * @return {character}\n */\nvar findTheDifference = function(s, t) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String} t\n# @return {Character}\ndef find_the_difference(s, t)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findTheDifference(_ s: String, _ t: String) -> Character {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findTheDifference(s string, t string) byte {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findTheDifference(s: String, t: String): Char = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findTheDifference(s: String, t: String): Char {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_the_difference(s: String, t: String) -> char {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String $t\n * @return String\n */\n function findTheDifference($s, $t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findTheDifference(s: string, t: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-the-difference s t)\n (-> string? string? char?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0389](https://leetcode-cn.com/problems/find-the-difference)", "[\u627e\u4e0d\u540c](/solution/0300-0399/0389.Find%20the%20Difference/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0389](https://leetcode.com/problems/find-the-difference)", "[Find the Difference](/solution/0300-0399/0389.Find%20the%20Difference/README_EN.md)", "`Bit Manipulation`,`Hash Table`", "Easy", ""]}, {"question_id": "0388", "frontend_question_id": "0388", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-absolute-file-path", "url_en": "https://leetcode.com/problems/longest-absolute-file-path", "relative_path_cn": "/solution/0300-0399/0388.Longest%20Absolute%20File%20Path/README.md", "relative_path_en": "/solution/0300-0399/0388.Longest%20Absolute%20File%20Path/README_EN.md", "title_cn": "\u6587\u4ef6\u7684\u6700\u957f\u7edd\u5bf9\u8def\u5f84", "title_en": "Longest Absolute File Path", "question_title_slug": "longest-absolute-file-path", "content_en": "

    Suppose we have a file system that stores both files and directories. An example of one system is represented in the following picture:

    \n\n

    \"\"

    \n\n

    Here, we have dir as the only directory in the root. dir contains two subdirectories, subdir1 and subdir2. subdir1 contains a file file1.ext and subdirectory subsubdir1. subdir2 contains a subdirectory subsubdir2, which contains a file file2.ext.

    \n\n

    In text form, it looks like this (with \u27f6 representing the tab character):

    \n\n
    \ndir\n\u27f6 subdir1\n\u27f6 \u27f6 file1.ext\n\u27f6 \u27f6 subsubdir1\n\u27f6 subdir2\n\u27f6 \u27f6 subsubdir2\n\u27f6 \u27f6 \u27f6 file2.ext\n
    \n\n

    If we were to write this representation in code, it will look like this: "dir\\n\\tsubdir1\\n\\t\\tfile1.ext\\n\\t\\tsubsubdir1\\n\\tsubdir2\\n\\t\\tsubsubdir2\\n\\t\\t\\tfile2.ext". Note that the '\\n' and '\\t' are the new-line and tab characters.

    \n\n

    Every file and directory has a unique absolute path in the file system, which is the order of directories that must be opened to reach the file/directory itself, all concatenated by '/'s. Using the above example, the absolute path to file2.ext is "dir/subdir2/subsubdir2/file2.ext". Each directory name consists of letters, digits, and/or spaces. Each file name is of the form name.extension, where name and extension consist of letters, digits, and/or spaces.

    \n\n

    Given a string input representing the file system in the explained format, return the length of the longest absolute path to a file in the abstracted file system. If there is no file in the system, return 0.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: input = "dir\\n\\tsubdir1\\n\\tsubdir2\\n\\t\\tfile.ext"\nOutput: 20\nExplanation: We have only one file, and the absolute path is "dir/subdir2/file.ext" of length 20.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: input = "dir\\n\\tsubdir1\\n\\t\\tfile1.ext\\n\\t\\tsubsubdir1\\n\\tsubdir2\\n\\t\\tsubsubdir2\\n\\t\\t\\tfile2.ext"\nOutput: 32\nExplanation: We have two files:\n"dir/subdir1/file1.ext" of length 21\n"dir/subdir2/subsubdir2/file2.ext" of length 32.\nWe return 32 since it is the longest absolute path to a file.\n
    \n\n

    Example 3:

    \n\n
    \nInput: input = "a"\nOutput: 0\nExplanation: We do not have any files, just a single directory named "a".\n
    \n\n

    Example 4:

    \n\n
    \nInput: input = "file1.txt\\nfile2.txt\\nlongfile.txt"\nOutput: 12\nExplanation: There are 3 files at the root directory.\nSince the absolute path for anything at the root directory is just the name itself, the answer is "longfile.txt" with length 12.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= input.length <= 104
    • \n\t
    • input may contain lowercase or uppercase English letters, a new line character '\\n', a tab character '\\t', a dot '.', a space ' ', and digits.
    • \n
    \n", "content_cn": "

    \u5047\u8bbe\u6587\u4ef6\u7cfb\u7edf\u5982\u4e0b\u56fe\u6240\u793a\uff1a

    \n\n

    \"\"

    \n\n

    \u8fd9\u91cc\u5c06 dir \u4f5c\u4e3a\u6839\u76ee\u5f55\u4e2d\u7684\u552f\u4e00\u76ee\u5f55\u3002dir \u5305\u542b\u4e24\u4e2a\u5b50\u76ee\u5f55 subdir1 \u548c subdir2 \u3002subdir1 \u5305\u542b\u6587\u4ef6 file1.ext \u548c\u5b50\u76ee\u5f55 subsubdir1\uff1bsubdir2 \u5305\u542b\u5b50\u76ee\u5f55 subsubdir2\uff0c\u8be5\u5b50\u76ee\u5f55\u4e0b\u5305\u542b\u6587\u4ef6 file2.ext \u3002

    \n\n

    \u5728\u6587\u672c\u683c\u5f0f\u4e2d\uff0c\u5982\u4e0b\u6240\u793a(\u27f6\u8868\u793a\u5236\u8868\u7b26)\uff1a

    \n\n
    \ndir\n\u27f6 subdir1\n\u27f6 \u27f6 file1.ext\n\u27f6 \u27f6 subsubdir1\n\u27f6 subdir2\n\u27f6 \u27f6 subsubdir2\n\u27f6 \u27f6 \u27f6 file2.ext\n
    \n\n

    \u5982\u679c\u662f\u4ee3\u7801\u8868\u793a\uff0c\u4e0a\u9762\u7684\u6587\u4ef6\u7cfb\u7edf\u53ef\u4ee5\u5199\u4e3a \"dir\\n\\tsubdir1\\n\\t\\tfile1.ext\\n\\t\\tsubsubdir1\\n\\tsubdir2\\n\\t\\tsubsubdir2\\n\\t\\t\\tfile2.ext\" \u3002'\\n' \u548c '\\t' \u5206\u522b\u662f\u6362\u884c\u7b26\u548c\u5236\u8868\u7b26\u3002

    \n\n

    \u6587\u4ef6\u7cfb\u7edf\u4e2d\u7684\u6bcf\u4e2a\u6587\u4ef6\u548c\u6587\u4ef6\u5939\u90fd\u6709\u4e00\u4e2a\u552f\u4e00\u7684 \u7edd\u5bf9\u8def\u5f84 \uff0c\u5373\u5fc5\u987b\u6253\u5f00\u624d\u80fd\u5230\u8fbe\u6587\u4ef6/\u76ee\u5f55\u6240\u5728\u4f4d\u7f6e\u7684\u76ee\u5f55\u987a\u5e8f\uff0c\u6240\u6709\u8def\u5f84\u7528 '/' \u8fde\u63a5\u3002\u4e0a\u9762\u4f8b\u5b50\u4e2d\uff0c\u6307\u5411 file2.ext \u7684\u7edd\u5bf9\u8def\u5f84\u662f \"dir/subdir2/subsubdir2/file2.ext\" \u3002\u6bcf\u4e2a\u76ee\u5f55\u540d\u7531\u5b57\u6bcd\u3001\u6570\u5b57\u548c/\u6216\u7a7a\u683c\u7ec4\u6210\uff0c\u6bcf\u4e2a\u6587\u4ef6\u540d\u9075\u5faa name.extension \u7684\u683c\u5f0f\uff0c\u5176\u4e2d\u540d\u79f0\u548c\u6269\u5c55\u540d\u7531\u5b57\u6bcd\u3001\u6570\u5b57\u548c/\u6216\u7a7a\u683c\u7ec4\u6210\u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u4ee5\u4e0a\u8ff0\u683c\u5f0f\u8868\u793a\u6587\u4ef6\u7cfb\u7edf\u7684\u5b57\u7b26\u4e32 input \uff0c\u8fd4\u56de\u6587\u4ef6\u7cfb\u7edf\u4e2d \u6307\u5411\u6587\u4ef6\u7684\u6700\u957f\u7edd\u5bf9\u8def\u5f84 \u7684\u957f\u5ea6\u3002 \u5982\u679c\u7cfb\u7edf\u4e2d\u6ca1\u6709\u6587\u4ef6\uff0c\u8fd4\u56de\u00a00\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1ainput = \"dir\\n\\tsubdir1\\n\\tsubdir2\\n\\t\\tfile.ext\"\n\u8f93\u51fa\uff1a20\n\u89e3\u91ca\uff1a\u53ea\u6709\u4e00\u4e2a\u6587\u4ef6\uff0c\u7edd\u5bf9\u8def\u5f84\u4e3a \"dir/subdir2/file.ext\" \uff0c\u8def\u5f84\u957f\u5ea6 20\n\u8def\u5f84 \"dir/subdir1\" \u4e0d\u542b\u4efb\u4f55\u6587\u4ef6\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1ainput = \"dir\\n\\tsubdir1\\n\\t\\tfile1.ext\\n\\t\\tsubsubdir1\\n\\tsubdir2\\n\\t\\tsubsubdir2\\n\\t\\t\\tfile2.ext\"\n\u8f93\u51fa\uff1a32\n\u89e3\u91ca\uff1a\u5b58\u5728\u4e24\u4e2a\u6587\u4ef6\uff1a\n\"dir/subdir1/file1.ext\" \uff0c\u8def\u5f84\u957f\u5ea6 21\n\"dir/subdir2/subsubdir2/file2.ext\" \uff0c\u8def\u5f84\u957f\u5ea6 32\n\u8fd4\u56de 32 \uff0c\u56e0\u4e3a\u8fd9\u662f\u6700\u957f\u7684\u8def\u5f84
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1ainput = \"a\"\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u4e0d\u5b58\u5728\u4efb\u4f55\u6587\u4ef6
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1ainput = \"file1.txt\\nfile2.txt\\nlongfile.txt\"\n\u8f93\u51fa\uff1a12\n\u89e3\u91ca\uff1a\u6839\u76ee\u5f55\u4e0b\u6709 3 \u4e2a\u6587\u4ef6\u3002\n\u56e0\u4e3a\u6839\u76ee\u5f55\u4e2d\u4efb\u4f55\u4e1c\u897f\u7684\u7edd\u5bf9\u8def\u5f84\u53ea\u662f\u540d\u79f0\u672c\u8eab\uff0c\u6240\u4ee5\u7b54\u6848\u662f \"longfile.txt\" \uff0c\u8def\u5f84\u957f\u5ea6\u4e3a 12\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= input.length <= 104
    • \n\t
    • input \u53ef\u80fd\u5305\u542b\u5c0f\u5199\u6216\u5927\u5199\u7684\u82f1\u6587\u5b57\u6bcd\uff0c\u4e00\u4e2a\u6362\u884c\u7b26 '\\n'\uff0c\u4e00\u4e2a\u6307\u8868\u7b26 '\\t'\uff0c\u4e00\u4e2a\u70b9 '.'\uff0c\u4e00\u4e2a\u7a7a\u683c ' '\uff0c\u548c\u6570\u5b57\u3002
    • \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int lengthLongestPath(string input) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int lengthLongestPath(String input) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def lengthLongestPath(self, input):\n \"\"\"\n :type input: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def lengthLongestPath(self, input: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint lengthLongestPath(char * input){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LengthLongestPath(string input) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} input\n * @return {number}\n */\nvar lengthLongestPath = function(input) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} input\n# @return {Integer}\ndef length_longest_path(input)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func lengthLongestPath(_ input: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func lengthLongestPath(input string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def lengthLongestPath(input: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun lengthLongestPath(input: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn length_longest_path(input: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $input\n * @return Integer\n */\n function lengthLongestPath($input) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function lengthLongestPath(input: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (length-longest-path input)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0388](https://leetcode-cn.com/problems/longest-absolute-file-path)", "[\u6587\u4ef6\u7684\u6700\u957f\u7edd\u5bf9\u8def\u5f84](/solution/0300-0399/0388.Longest%20Absolute%20File%20Path/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0388](https://leetcode.com/problems/longest-absolute-file-path)", "[Longest Absolute File Path](/solution/0300-0399/0388.Longest%20Absolute%20File%20Path/README_EN.md)", "", "Medium", ""]}, {"question_id": "0387", "frontend_question_id": "0387", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/first-unique-character-in-a-string", "url_en": "https://leetcode.com/problems/first-unique-character-in-a-string", "relative_path_cn": "/solution/0300-0399/0387.First%20Unique%20Character%20in%20a%20String/README.md", "relative_path_en": "/solution/0300-0399/0387.First%20Unique%20Character%20in%20a%20String/README_EN.md", "title_cn": "\u5b57\u7b26\u4e32\u4e2d\u7684\u7b2c\u4e00\u4e2a\u552f\u4e00\u5b57\u7b26", "title_en": "First Unique Character in a String", "question_title_slug": "first-unique-character-in-a-string", "content_en": "

    Given a string s, return the first non-repeating character in it and return its index. If it does not exist, return -1.

    \n\n

     

    \n

    Example 1:

    \n
    Input: s = \"leetcode\"\nOutput: 0\n

    Example 2:

    \n
    Input: s = \"loveleetcode\"\nOutput: 2\n

    Example 3:

    \n
    Input: s = \"aabb\"\nOutput: -1\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 105
    • \n\t
    • s consists of only lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u627e\u5230\u5b83\u7684\u7b2c\u4e00\u4e2a\u4e0d\u91cd\u590d\u7684\u5b57\u7b26\uff0c\u5e76\u8fd4\u56de\u5b83\u7684\u7d22\u5f15\u3002\u5982\u679c\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de -1\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    s = "leetcode"\n\u8fd4\u56de 0\n\ns = "loveleetcode"\n\u8fd4\u56de 2\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a\u4f60\u53ef\u4ee5\u5047\u5b9a\u8be5\u5b57\u7b26\u4e32\u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd\u3002

    \n", "tags_en": ["Hash Table", "String"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int firstUniqChar(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int firstUniqChar(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def firstUniqChar(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def firstUniqChar(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint firstUniqChar(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FirstUniqChar(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar firstUniqChar = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef first_uniq_char(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func firstUniqChar(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func firstUniqChar(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def firstUniqChar(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun firstUniqChar(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn first_uniq_char(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function firstUniqChar($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function firstUniqChar(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (first-uniq-char s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0387](https://leetcode-cn.com/problems/first-unique-character-in-a-string)", "[\u5b57\u7b26\u4e32\u4e2d\u7684\u7b2c\u4e00\u4e2a\u552f\u4e00\u5b57\u7b26](/solution/0300-0399/0387.First%20Unique%20Character%20in%20a%20String/README.md)", "`\u54c8\u5e0c\u8868`,`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0387](https://leetcode.com/problems/first-unique-character-in-a-string)", "[First Unique Character in a String](/solution/0300-0399/0387.First%20Unique%20Character%20in%20a%20String/README_EN.md)", "`Hash Table`,`String`", "Easy", ""]}, {"question_id": "0386", "frontend_question_id": "0386", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/lexicographical-numbers", "url_en": "https://leetcode.com/problems/lexicographical-numbers", "relative_path_cn": "/solution/0300-0399/0386.Lexicographical%20Numbers/README.md", "relative_path_en": "/solution/0300-0399/0386.Lexicographical%20Numbers/README_EN.md", "title_cn": "\u5b57\u5178\u5e8f\u6392\u6570", "title_en": "Lexicographical Numbers", "question_title_slug": "lexicographical-numbers", "content_en": "

    Given an integer n, return all the numbers in the range [1, n] sorted in lexicographical order.

    \n\n

    You must write an algorithm that runs in O(n) time and uses O(1) extra space. 

    \n\n

     

    \n

    Example 1:

    \n
    Input: n = 13\nOutput: [1,10,11,12,13,2,3,4,5,6,7,8,9]\n

    Example 2:

    \n
    Input: n = 2\nOutput: [1,2]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 5 * 104
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570 n, \u8fd4\u56de\u4ece \u5230 \u7684\u5b57\u5178\u987a\u5e8f\u3002

    \n\n

    \u4f8b\u5982\uff0c

    \n\n

    \u7ed9\u5b9a n =1 3\uff0c\u8fd4\u56de [1,10,11,12,13,2,3,4,5,6,7,8,9] \u3002

    \n\n

    \u8bf7\u5c3d\u53ef\u80fd\u7684\u4f18\u5316\u7b97\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u548c\u7a7a\u95f4\u590d\u6742\u5ea6\u3002 \u8f93\u5165\u7684\u6570\u636e \u5c0f\u4e8e\u7b49\u4e8e 5,000,000\u3002

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector lexicalOrder(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List lexicalOrder(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def lexicalOrder(self, n):\n \"\"\"\n :type n: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def lexicalOrder(self, n: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* lexicalOrder(int n, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList LexicalOrder(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number[]}\n */\nvar lexicalOrder = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer[]}\ndef lexical_order(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func lexicalOrder(_ n: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func lexicalOrder(n int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def lexicalOrder(n: Int): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun lexicalOrder(n: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn lexical_order(n: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer[]\n */\n function lexicalOrder($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function lexicalOrder(n: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (lexical-order n)\n (-> exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0386](https://leetcode-cn.com/problems/lexicographical-numbers)", "[\u5b57\u5178\u5e8f\u6392\u6570](/solution/0300-0399/0386.Lexicographical%20Numbers/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0386](https://leetcode.com/problems/lexicographical-numbers)", "[Lexicographical Numbers](/solution/0300-0399/0386.Lexicographical%20Numbers/README_EN.md)", "", "Medium", ""]}, {"question_id": "0385", "frontend_question_id": "0385", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/mini-parser", "url_en": "https://leetcode.com/problems/mini-parser", "relative_path_cn": "/solution/0300-0399/0385.Mini%20Parser/README.md", "relative_path_en": "/solution/0300-0399/0385.Mini%20Parser/README_EN.md", "title_cn": "\u8ff7\u4f60\u8bed\u6cd5\u5206\u6790\u5668", "title_en": "Mini Parser", "question_title_slug": "mini-parser", "content_en": "

    Given a string s represents the serialization of a nested list, implement a parser to deserialize it and return the deserialized NestedInteger.

    \n\n

    Each element is either an integer or a list whose elements may also be integers or other lists.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "324"\nOutput: 324\nExplanation: You should return a NestedInteger object which contains a single integer 324.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "[123,[456,[789]]]"\nOutput: [123,[456,[789]]]\nExplanation: Return a NestedInteger object containing a nested list with 2 elements:\n1. An integer containing value 123.\n2. A nested list containing two elements:\n    i.  An integer containing value 456.\n    ii. A nested list with one element:\n         a. An integer containing value 789\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 5 * 104
    • \n\t
    • s consists of digits, square brackets "[]", negative sign '-', and commas ','.
    • \n\t
    • s is the serialization of valid NestedInteger.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u7528\u5b57\u7b26\u4e32\u8868\u793a\u7684\u6574\u6570\u7684\u5d4c\u5957\u5217\u8868\uff0c\u5b9e\u73b0\u4e00\u4e2a\u89e3\u6790\u5b83\u7684\u8bed\u6cd5\u5206\u6790\u5668\u3002

    \n\n

    \u5217\u8868\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u53ea\u53ef\u80fd\u662f\u6574\u6570\u6216\u6574\u6570\u5d4c\u5957\u5217\u8868

    \n\n

    \u63d0\u793a\uff1a\u4f60\u53ef\u4ee5\u5047\u5b9a\u8fd9\u4e9b\u5b57\u7b26\u4e32\u90fd\u662f\u683c\u5f0f\u826f\u597d\u7684\uff1a

    \n\n
      \n\t
    • \u5b57\u7b26\u4e32\u975e\u7a7a
    • \n\t
    • \u5b57\u7b26\u4e32\u4e0d\u5305\u542b\u7a7a\u683c
    • \n\t
    • \u5b57\u7b26\u4e32\u53ea\u5305\u542b\u6570\u5b570-9\u3001[\u3001-\u3001,\u3001]
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u7ed9\u5b9a s = "324",\n\n\u4f60\u5e94\u8be5\u8fd4\u56de\u4e00\u4e2a NestedInteger \u5bf9\u8c61\uff0c\u5176\u4e2d\u53ea\u5305\u542b\u6574\u6570\u503c 324\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u7ed9\u5b9a s = "[123,[456,[789]]]",\n\n\u8fd4\u56de\u4e00\u4e2a NestedInteger \u5bf9\u8c61\u5305\u542b\u4e00\u4e2a\u6709\u4e24\u4e2a\u5143\u7d20\u7684\u5d4c\u5957\u5217\u8868\uff1a\n\n1. \u4e00\u4e2a integer \u5305\u542b\u503c 123\n2. \u4e00\u4e2a\u5305\u542b\u4e24\u4e2a\u5143\u7d20\u7684\u5d4c\u5957\u5217\u8868\uff1a\n    i.  \u4e00\u4e2a integer \u5305\u542b\u503c 456\n    ii. \u4e00\u4e2a\u5305\u542b\u4e00\u4e2a\u5143\u7d20\u7684\u5d4c\u5957\u5217\u8868\n         a. \u4e00\u4e2a integer \u5305\u542b\u503c 789\n
    \n", "tags_en": ["Stack", "String"], "tags_cn": ["\u6808", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * class NestedInteger {\n * public:\n * // Constructor initializes an empty nested list.\n * NestedInteger();\n *\n * // Constructor initializes a single integer.\n * NestedInteger(int value);\n *\n * // Return true if this NestedInteger holds a single integer, rather than a nested list.\n * bool isInteger() const;\n *\n * // Return the single integer that this NestedInteger holds, if it holds a single integer\n * // The result is undefined if this NestedInteger holds a nested list\n * int getInteger() const;\n *\n * // Set this NestedInteger to hold a single integer.\n * void setInteger(int value);\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * void add(const NestedInteger &ni);\n *\n * // Return the nested list that this NestedInteger holds, if it holds a nested list\n * // The result is undefined if this NestedInteger holds a single integer\n * const vector &getList() const;\n * };\n */\nclass Solution {\npublic:\n NestedInteger deserialize(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * public interface NestedInteger {\n * // Constructor initializes an empty nested list.\n * public NestedInteger();\n *\n * // Constructor initializes a single integer.\n * public NestedInteger(int value);\n *\n * // @return true if this NestedInteger holds a single integer, rather than a nested list.\n * public boolean isInteger();\n *\n * // @return the single integer that this NestedInteger holds, if it holds a single integer\n * // Return null if this NestedInteger holds a nested list\n * public Integer getInteger();\n *\n * // Set this NestedInteger to hold a single integer.\n * public void setInteger(int value);\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * public void add(NestedInteger ni);\n *\n * // @return the nested list that this NestedInteger holds, if it holds a nested list\n * // Return empty list if this NestedInteger holds a single integer\n * public List getList();\n * }\n */\nclass Solution {\n public NestedInteger deserialize(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# \"\"\"\n# This is the interface that allows for creating nested lists.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class NestedInteger(object):\n# def __init__(self, value=None):\n# \"\"\"\n# If value is not specified, initializes an empty list.\n# Otherwise initializes a single integer equal to value.\n# \"\"\"\n#\n# def isInteger(self):\n# \"\"\"\n# @return True if this NestedInteger holds a single integer, rather than a nested list.\n# :rtype bool\n# \"\"\"\n#\n# def add(self, elem):\n# \"\"\"\n# Set this NestedInteger to hold a nested list and adds a nested integer elem to it.\n# :rtype void\n# \"\"\"\n#\n# def setInteger(self, value):\n# \"\"\"\n# Set this NestedInteger to hold a single integer equal to value.\n# :rtype void\n# \"\"\"\n#\n# def getInteger(self):\n# \"\"\"\n# @return the single integer that this NestedInteger holds, if it holds a single integer\n# Return None if this NestedInteger holds a nested list\n# :rtype int\n# \"\"\"\n#\n# def getList(self):\n# \"\"\"\n# @return the nested list that this NestedInteger holds, if it holds a nested list\n# Return None if this NestedInteger holds a single integer\n# :rtype List[NestedInteger]\n# \"\"\"\nclass Solution(object):\n def deserialize(self, s):\n \"\"\"\n :type s: str\n :rtype: NestedInteger\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# \"\"\"\n# This is the interface that allows for creating nested lists.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class NestedInteger:\n# def __init__(self, value=None):\n# \"\"\"\n# If value is not specified, initializes an empty list.\n# Otherwise initializes a single integer equal to value.\n# \"\"\"\n#\n# def isInteger(self):\n# \"\"\"\n# @return True if this NestedInteger holds a single integer, rather than a nested list.\n# :rtype bool\n# \"\"\"\n#\n# def add(self, elem):\n# \"\"\"\n# Set this NestedInteger to hold a nested list and adds a nested integer elem to it.\n# :rtype void\n# \"\"\"\n#\n# def setInteger(self, value):\n# \"\"\"\n# Set this NestedInteger to hold a single integer equal to value.\n# :rtype void\n# \"\"\"\n#\n# def getInteger(self):\n# \"\"\"\n# @return the single integer that this NestedInteger holds, if it holds a single integer\n# Return None if this NestedInteger holds a nested list\n# :rtype int\n# \"\"\"\n#\n# def getList(self):\n# \"\"\"\n# @return the nested list that this NestedInteger holds, if it holds a nested list\n# Return None if this NestedInteger holds a single integer\n# :rtype List[NestedInteger]\n# \"\"\"\nclass Solution:\n def deserialize(self, s: str) -> NestedInteger:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * *********************************************************************\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * *********************************************************************\n *\n * // Initializes an empty nested list and return a reference to the nested integer.\n * struct NestedInteger *NestedIntegerInit();\n *\n * // Return true if this NestedInteger holds a single integer, rather than a nested list.\n * bool NestedIntegerIsInteger(struct NestedInteger *);\n *\n * // Return the single integer that this NestedInteger holds, if it holds a single integer\n * // The result is undefined if this NestedInteger holds a nested list\n * int NestedIntegerGetInteger(struct NestedInteger *);\n *\n * // Set this NestedInteger to hold a single integer.\n * void NestedIntegerSetInteger(struct NestedInteger *ni, int value);\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer elem to it.\n * void NestedIntegerAdd(struct NestedInteger *ni, struct NestedInteger *elem);\n *\n * // Return the nested list that this NestedInteger holds, if it holds a nested list\n * // The result is undefined if this NestedInteger holds a single integer\n * struct NestedInteger **NestedIntegerGetList(struct NestedInteger *);\n *\n * // Return the nested list's size that this NestedInteger holds, if it holds a nested list\n * // The result is undefined if this NestedInteger holds a single integer\n * int NestedIntegerGetListSize(struct NestedInteger *);\n * };\n */\n\n\nstruct NestedInteger* deserialize(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * interface NestedInteger {\n *\n * // Constructor initializes an empty nested list.\n * public NestedInteger();\n *\n * // Constructor initializes a single integer.\n * public NestedInteger(int value);\n *\n * // @return true if this NestedInteger holds a single integer, rather than a nested list.\n * bool IsInteger();\n *\n * // @return the single integer that this NestedInteger holds, if it holds a single integer\n * // Return null if this NestedInteger holds a nested list\n * int GetInteger();\n *\n * // Set this NestedInteger to hold a single integer.\n * public void SetInteger(int value);\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * public void Add(NestedInteger ni);\n *\n * // @return the nested list that this NestedInteger holds, if it holds a nested list\n * // Return null if this NestedInteger holds a single integer\n * IList GetList();\n * }\n */\npublic class Solution {\n public NestedInteger Deserialize(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * function NestedInteger() {\n *\n * Return true if this NestedInteger holds a single integer, rather than a nested list.\n * @return {boolean}\n * this.isInteger = function() {\n * ...\n * };\n *\n * Return the single integer that this NestedInteger holds, if it holds a single integer\n * Return null if this NestedInteger holds a nested list\n * @return {integer}\n * this.getInteger = function() {\n * ...\n * };\n *\n * Set this NestedInteger to hold a single integer equal to value.\n * @return {void}\n * this.setInteger = function(value) {\n * ...\n * };\n *\n * Set this NestedInteger to hold a nested list and adds a nested integer elem to it.\n * @return {void}\n * this.add = function(elem) {\n * ...\n * };\n *\n * Return the nested list that this NestedInteger holds, if it holds a nested list\n * Return null if this NestedInteger holds a single integer\n * @return {NestedInteger[]}\n * this.getList = function() {\n * ...\n * };\n * };\n */\n/**\n * @param {string} s\n * @return {NestedInteger}\n */\nvar deserialize = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# This is the interface that allows for creating nested lists.\n# You should not implement it, or speculate about its implementation\n#\n#class NestedInteger\n# def is_integer()\n# \"\"\"\n# Return true if this NestedInteger holds a single integer, rather than a nested list.\n# @return {Boolean}\n# \"\"\"\n#\n# def get_integer()\n# \"\"\"\n# Return the single integer that this NestedInteger holds, if it holds a single integer\n# Return nil if this NestedInteger holds a nested list\n# @return {Integer}\n# \"\"\"\n#\n# def set_integer(value)\n# \"\"\"\n# Set this NestedInteger to hold a single integer equal to value.\n# @return {Void}\n# \"\"\"\n#\n# def add(elem)\n# \"\"\"\n# Set this NestedInteger to hold a nested list and adds a nested integer elem to it.\n# @return {Void}\n# \"\"\"\n#\n# def get_list()\n# \"\"\"\n# Return the nested list that this NestedInteger holds, if it holds a nested list\n# Return nil if this NestedInteger holds a single integer\n# @return {NestedInteger[]}\n# \"\"\"\n# @param {String} s\n# @return {NestedInteger}\ndef deserialize(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * class NestedInteger {\n * // Return true if this NestedInteger holds a single integer, rather than a nested list.\n * public func isInteger() -> Bool\n *\n * // Return the single integer that this NestedInteger holds, if it holds a single integer\n * // The result is undefined if this NestedInteger holds a nested list\n * public func getInteger() -> Int\n *\n * // Set this NestedInteger to hold a single integer.\n * public func setInteger(value: Int)\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * public func add(elem: NestedInteger)\n *\n * // Return the nested list that this NestedInteger holds, if it holds a nested list\n * // The result is undefined if this NestedInteger holds a single integer\n * public func getList() -> [NestedInteger]\n * }\n */\nclass Solution {\n func deserialize(_ s: String) -> NestedInteger {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * type NestedInteger struct {\n * }\n *\n * // Return true if this NestedInteger holds a single integer, rather than a nested list.\n * func (n NestedInteger) IsInteger() bool {}\n *\n * // Return the single integer that this NestedInteger holds, if it holds a single integer\n * // The result is undefined if this NestedInteger holds a nested list\n * // So before calling this method, you should have a check\n * func (n NestedInteger) GetInteger() int {}\n *\n * // Set this NestedInteger to hold a single integer.\n * func (n *NestedInteger) SetInteger(value int) {}\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * func (n *NestedInteger) Add(elem NestedInteger) {}\n *\n * // Return the nested list that this NestedInteger holds, if it holds a nested list\n * // The list length is zero if this NestedInteger holds a single integer\n * // You can access NestedInteger's List element directly if you want to modify it\n * func (n NestedInteger) GetList() []*NestedInteger {}\n */\nfunc deserialize(s string) *NestedInteger {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * trait NestedInteger {\n *\n * // Return true if this NestedInteger holds a single integer, rather than a nested list.\n * def isInteger: Boolean\n *\n * // Return the single integer that this NestedInteger holds, if it holds a single integer.\n * def getInteger: Int\n *\n * // Set this NestedInteger to hold a single integer.\n * def setInteger(i: Int): Unit\n *\n * // Return the nested list that this NestedInteger holds, if it holds a nested list.\n * def getList: Array[NestedInteger]\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * def add(ni: NestedInteger): Unit\n * }\n */\nobject Solution {\n def deserialize(s: String): NestedInteger = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * class NestedInteger {\n * // Constructor initializes an empty nested list.\n * constructor()\n *\n * // Constructor initializes a single integer.\n * constructor(value: Int)\n *\n * // @return true if this NestedInteger holds a single integer, rather than a nested list.\n * fun isInteger(): Boolean\n *\n * // @return the single integer that this NestedInteger holds, if it holds a single integer\n * // Return null if this NestedInteger holds a nested list\n * fun getInteger(): Int?\n *\n * // Set this NestedInteger to hold a single integer.\n * fun setInteger(value: Int): Unit\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * fun add(ni: NestedInteger): Unit\n *\n * // @return the nested list that this NestedInteger holds, if it holds a nested list\n * // Return null if this NestedInteger holds a single integer\n * fun getList(): List?\n * }\n */\nclass Solution {\n fun deserialize(s: String): NestedInteger {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// #[derive(Debug, PartialEq, Eq)]\n// pub enum NestedInteger {\n// Int(i32),\n// List(Vec)\n// }\nimpl Solution {\n pub fn deserialize(s: String) -> NestedInteger {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * class NestedInteger {\n\n * // if value is not specified, initializes an empty list.\n * // Otherwise initializes a single integer equal to value.\n * function __construct($value = null)\n\n * // Return true if this NestedInteger holds a single integer, rather than a nested list.\n * function isInteger() : bool\n *\n * // Return the single integer that this NestedInteger holds, if it holds a single integer\n * // The result is undefined if this NestedInteger holds a nested list\n * function getInteger()\n *\n * // Set this NestedInteger to hold a single integer.\n * function setInteger($i) : void\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * function add($ni) : void\n *\n * // Return the nested list that this NestedInteger holds, if it holds a nested list\n * // The result is undefined if this NestedInteger holds a single integer\n * function getList() : array\n * }\n */\nclass Solution {\n\n /**\n * @param String $s\n * @return NestedInteger\n */\n function deserialize($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * class NestedInteger {\n * If value is provided, then it holds a single integer\n * Otherwise it holds an empty nested list\n * constructor(value?: number) {\n * ...\n * };\n *\n * Return true if this NestedInteger holds a single integer, rather than a nested list.\n * isInteger(): boolean {\n * ...\n * };\n *\n * Return the single integer that this NestedInteger holds, if it holds a single integer\n * Return null if this NestedInteger holds a nested list\n * getInteger(): number | null {\n * ...\n * };\n *\n * Set this NestedInteger to hold a single integer equal to value.\n * setInteger(value: number) {\n * ...\n * };\n *\n * Set this NestedInteger to hold a nested list and adds a nested integer elem to it.\n * add(elem: NestedInteger) {\n * ...\n * };\n *\n * Return the nested list that this NestedInteger holds,\n * or an empty list if this NestedInteger holds a single integer\n * getList(): NestedInteger[] {\n * ...\n * };\n * };\n */\n\nfunction deserialize(s: string): NestedInteger {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": ";; This is the interface that allows for creating nested lists.\n;; You should not implement it, or speculate about its implementation\n\n#|\n\n(define nested-integer%\n (class object%\n ...\n\n ; Return true if this nested-integer% holds a single integer, rather than a nested list.\n ; -> boolean?\n (define/public (is-integer)\n ...)\n\n ; Return the single integer that this nested-integer% holds, if it holds a single integer,\n ; or #f if this nested-integer% holds a nested list.\n ; -> integer?\n (define/public (get-integer)\n ...)\n\n ; Set this nested-integer% to hold a single integer equal to value.\n ; -> integer? void?\n (define/public (set-integer i)\n ...)\n\n ; Set this nested-integer% to hold a nested list and adds a nested integer elem to it.\n ; -> (is-a?/c nested-integer%) void?\n (define/public (add ni)\n ...)\n\n ; Return the nested list that this nested-integer% holds,\n ; or an empty list if this nested-integer% holds a single integer.\n ; -> gvector?\n (define/public (get-list)\n ...)))\n\n|#\n\n(define/contract (deserialize s)\n (-> string? (is-a?/c nested-integer%))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0385](https://leetcode-cn.com/problems/mini-parser)", "[\u8ff7\u4f60\u8bed\u6cd5\u5206\u6790\u5668](/solution/0300-0399/0385.Mini%20Parser/README.md)", "`\u6808`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0385](https://leetcode.com/problems/mini-parser)", "[Mini Parser](/solution/0300-0399/0385.Mini%20Parser/README_EN.md)", "`Stack`,`String`", "Medium", ""]}, {"question_id": "0384", "frontend_question_id": "0384", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/shuffle-an-array", "url_en": "https://leetcode.com/problems/shuffle-an-array", "relative_path_cn": "/solution/0300-0399/0384.Shuffle%20an%20Array/README.md", "relative_path_en": "/solution/0300-0399/0384.Shuffle%20an%20Array/README_EN.md", "title_cn": "\u6253\u4e71\u6570\u7ec4", "title_en": "Shuffle an Array", "question_title_slug": "shuffle-an-array", "content_en": "

    Given an integer array nums, design an algorithm to randomly shuffle the array.

    \n\n

    Implement the Solution class:

    \n\n
      \n\t
    • Solution(int[] nums) Initializes the object with the integer array nums.
    • \n\t
    • int[] reset() Resets the array to its original configuration and returns it.
    • \n\t
    • int[] shuffle() Returns a random shuffling of the array.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["Solution", "shuffle", "reset", "shuffle"]\n[[[1, 2, 3]], [], [], []]\nOutput\n[null, [3, 1, 2], [1, 2, 3], [1, 3, 2]]\n\nExplanation\nSolution solution = new Solution([1, 2, 3]);\nsolution.shuffle();    // Shuffle the array [1,2,3] and return its result. Any permutation of [1,2,3] must be equally likely to be returned. Example: return [3, 1, 2]\nsolution.reset();      // Resets the array back to its original configuration [1,2,3]. Return [1, 2, 3]\nsolution.shuffle();    // Returns the random shuffling of array [1,2,3]. Example: return [1, 3, 2]\n\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 200
    • \n\t
    • -106 <= nums[i] <= 106
    • \n\t
    • All the elements of nums are unique.
    • \n\t
    • At most 5 * 104 calls will be made to reset and shuffle.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \uff0c\u8bbe\u8ba1\u7b97\u6cd5\u6765\u6253\u4e71\u4e00\u4e2a\u6ca1\u6709\u91cd\u590d\u5143\u7d20\u7684\u6570\u7ec4\u3002

    \n\n

    \u5b9e\u73b0 Solution class:

    \n\n
      \n\t
    • Solution(int[] nums) \u4f7f\u7528\u6574\u6570\u6570\u7ec4 nums \u521d\u59cb\u5316\u5bf9\u8c61
    • \n\t
    • int[] reset() \u91cd\u8bbe\u6570\u7ec4\u5230\u5b83\u7684\u521d\u59cb\u72b6\u6001\u5e76\u8fd4\u56de
    • \n\t
    • int[] shuffle() \u8fd4\u56de\u6570\u7ec4\u968f\u673a\u6253\u4e71\u540e\u7684\u7ed3\u679c
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\n[\"Solution\", \"shuffle\", \"reset\", \"shuffle\"]\n[[[1, 2, 3]], [], [], []]\n\u8f93\u51fa\n[null, [3, 1, 2], [1, 2, 3], [1, 3, 2]]\n\n\u89e3\u91ca\nSolution solution = new Solution([1, 2, 3]);\nsolution.shuffle();    // \u6253\u4e71\u6570\u7ec4 [1,2,3] \u5e76\u8fd4\u56de\u7ed3\u679c\u3002\u4efb\u4f55 [1,2,3]\u7684\u6392\u5217\u8fd4\u56de\u7684\u6982\u7387\u5e94\u8be5\u76f8\u540c\u3002\u4f8b\u5982\uff0c\u8fd4\u56de [3, 1, 2]\nsolution.reset();      // \u91cd\u8bbe\u6570\u7ec4\u5230\u5b83\u7684\u521d\u59cb\u72b6\u6001 [1, 2, 3] \u3002\u8fd4\u56de [1, 2, 3]\nsolution.shuffle();    // \u968f\u673a\u8fd4\u56de\u6570\u7ec4 [1, 2, 3] \u6253\u4e71\u540e\u7684\u7ed3\u679c\u3002\u4f8b\u5982\uff0c\u8fd4\u56de [1, 3, 2]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 200
    • \n\t
    • -106 <= nums[i] <= 106
    • \n\t
    • nums \u4e2d\u7684\u6240\u6709\u5143\u7d20\u90fd\u662f \u552f\u4e00\u7684
    • \n\t
    • \u6700\u591a\u53ef\u4ee5\u8c03\u7528 5 * 104 \u6b21 reset \u548c shuffle
    • \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n Solution(vector& nums) {\n\n }\n \n /** Resets the array to its original configuration and return it. */\n vector reset() {\n\n }\n \n /** Returns a random shuffling of the array. */\n vector shuffle() {\n\n }\n};\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution* obj = new Solution(nums);\n * vector param_1 = obj->reset();\n * vector param_2 = obj->shuffle();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n\n public Solution(int[] nums) {\n\n }\n \n /** Resets the array to its original configuration and return it. */\n public int[] reset() {\n\n }\n \n /** Returns a random shuffling of the array. */\n public int[] shuffle() {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution obj = new Solution(nums);\n * int[] param_1 = obj.reset();\n * int[] param_2 = obj.shuffle();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n\n def __init__(self, nums):\n \"\"\"\n :type nums: List[int]\n \"\"\"\n\n\n def reset(self):\n \"\"\"\n Resets the array to its original configuration and return it.\n :rtype: List[int]\n \"\"\"\n\n\n def shuffle(self):\n \"\"\"\n Returns a random shuffling of the array.\n :rtype: List[int]\n \"\"\"\n\n\n\n# Your Solution object will be instantiated and called as such:\n# obj = Solution(nums)\n# param_1 = obj.reset()\n# param_2 = obj.shuffle()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n\n def __init__(self, nums: List[int]):\n\n\n def reset(self) -> List[int]:\n \"\"\"\n Resets the array to its original configuration and return it.\n \"\"\"\n\n\n def shuffle(self) -> List[int]:\n \"\"\"\n Returns a random shuffling of the array.\n \"\"\"\n\n\n\n# Your Solution object will be instantiated and called as such:\n# obj = Solution(nums)\n# param_1 = obj.reset()\n# param_2 = obj.shuffle()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} Solution;\n\n\nSolution* solutionCreate(int* nums, int numsSize) {\n\n}\n\n/** Resets the array to its original configuration and return it. */\nint* solutionReset(Solution* obj, int* retSize) {\n\n}\n\n/** Returns a random shuffling of the array. */\nint* solutionShuffle(Solution* obj, int* retSize) {\n\n}\n\nvoid solutionFree(Solution* obj) {\n\n}\n\n/**\n * Your Solution struct will be instantiated and called as such:\n * Solution* obj = solutionCreate(nums, numsSize);\n * int* param_1 = solutionReset(obj, retSize);\n \n * int* param_2 = solutionShuffle(obj, retSize);\n \n * solutionFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n\n public Solution(int[] nums) {\n\n }\n \n /** Resets the array to its original configuration and return it. */\n public int[] Reset() {\n\n }\n \n /** Returns a random shuffling of the array. */\n public int[] Shuffle() {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution obj = new Solution(nums);\n * int[] param_1 = obj.Reset();\n * int[] param_2 = obj.Shuffle();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n */\nvar Solution = function(nums) {\n\n};\n\n/**\n * Resets the array to its original configuration and return it.\n * @return {number[]}\n */\nSolution.prototype.reset = function() {\n\n};\n\n/**\n * Returns a random shuffling of the array.\n * @return {number[]}\n */\nSolution.prototype.shuffle = function() {\n\n};\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = new Solution(nums)\n * var param_1 = obj.reset()\n * var param_2 = obj.shuffle()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class Solution\n\n=begin\n :type nums: Integer[]\n=end\n def initialize(nums)\n\n end\n\n\n=begin\n Resets the array to its original configuration and return it.\n :rtype: Integer[]\n=end\n def reset()\n\n end\n\n\n=begin\n Returns a random shuffling of the array.\n :rtype: Integer[]\n=end\n def shuffle()\n\n end\n\n\nend\n\n# Your Solution object will be instantiated and called as such:\n# obj = Solution.new(nums)\n# param_1 = obj.reset()\n# param_2 = obj.shuffle()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass Solution {\n\n init(_ nums: [Int]) {\n\n }\n \n /** Resets the array to its original configuration and return it. */\n func reset() -> [Int] {\n\n }\n \n /** Returns a random shuffling of the array. */\n func shuffle() -> [Int] {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * let obj = Solution(nums)\n * let ret_1: [Int] = obj.reset()\n * let ret_2: [Int] = obj.shuffle()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type Solution struct {\n\n}\n\n\nfunc Constructor(nums []int) Solution {\n\n}\n\n\n/** Resets the array to its original configuration and return it. */\nfunc (this *Solution) Reset() []int {\n\n}\n\n\n/** Returns a random shuffling of the array. */\nfunc (this *Solution) Shuffle() []int {\n\n}\n\n\n/**\n * Your Solution object will be instantiated and called as such:\n * obj := Constructor(nums);\n * param_1 := obj.Reset();\n * param_2 := obj.Shuffle();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class Solution(_nums: Array[Int]) {\n\n /** Resets the array to its original configuration and return it. */\n def reset(): Array[Int] = {\n\n }\n\n /** Returns a random shuffling of the array. */\n def shuffle(): Array[Int] = {\n\n }\n\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = new Solution(nums)\n * var param_1 = obj.reset()\n * var param_2 = obj.shuffle()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution(nums: IntArray) {\n\n /** Resets the array to its original configuration and return it. */\n fun reset(): IntArray {\n\n }\n\n /** Returns a random shuffling of the array. */\n fun shuffle(): IntArray {\n\n }\n\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = Solution(nums)\n * var param_1 = obj.reset()\n * var param_2 = obj.shuffle()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct Solution {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl Solution {\n\n fn new(nums: Vec) -> Self {\n\n }\n \n /** Resets the array to its original configuration and return it. */\n fn reset(&self) -> Vec {\n\n }\n \n /** Returns a random shuffling of the array. */\n fn shuffle(&self) -> Vec {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * let obj = Solution::new(nums);\n * let ret_1: Vec = obj.reset();\n * let ret_2: Vec = obj.shuffle();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n /**\n * @param Integer[] $nums\n */\n function __construct($nums) {\n\n }\n\n /**\n * Resets the array to its original configuration and return it.\n * @return Integer[]\n */\n function reset() {\n\n }\n\n /**\n * Returns a random shuffling of the array.\n * @return Integer[]\n */\n function shuffle() {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * $obj = Solution($nums);\n * $ret_1 = $obj->reset();\n * $ret_2 = $obj->shuffle();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class Solution {\n constructor(nums: number[]) {\n\n }\n\n reset(): number[] {\n\n }\n\n shuffle(): number[] {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = new Solution(nums)\n * var param_1 = obj.reset()\n * var param_2 = obj.shuffle()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define solution%\n (class object%\n (super-new)\n\n ; nums : (listof exact-integer?)\n (init-field\n nums)\n \n ; reset : -> (listof exact-integer?)\n (define/public (reset)\n\n )\n ; shuffle : -> (listof exact-integer?)\n (define/public (shuffle)\n\n )))\n\n;; Your solution% object will be instantiated and called as such:\n;; (define obj (new solution% [nums nums]))\n;; (define param_1 (send obj reset))\n;; (define param_2 (send obj shuffle))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0384](https://leetcode-cn.com/problems/shuffle-an-array)", "[\u6253\u4e71\u6570\u7ec4](/solution/0300-0399/0384.Shuffle%20an%20Array/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0384](https://leetcode.com/problems/shuffle-an-array)", "[Shuffle an Array](/solution/0300-0399/0384.Shuffle%20an%20Array/README_EN.md)", "", "Medium", ""]}, {"question_id": "0383", "frontend_question_id": "0383", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/ransom-note", "url_en": "https://leetcode.com/problems/ransom-note", "relative_path_cn": "/solution/0300-0399/0383.Ransom%20Note/README.md", "relative_path_en": "/solution/0300-0399/0383.Ransom%20Note/README_EN.md", "title_cn": "\u8d4e\u91d1\u4fe1", "title_en": "Ransom Note", "question_title_slug": "ransom-note", "content_en": "

    Given two stings ransomNote and magazine, return true if ransomNote can be constructed from magazine and false otherwise.

    \n\n

    Each letter in magazine can only be used once in ransomNote.

    \n\n

     

    \n

    Example 1:

    \n
    Input: ransomNote = \"a\", magazine = \"b\"\nOutput: false\n

    Example 2:

    \n
    Input: ransomNote = \"aa\", magazine = \"ab\"\nOutput: false\n

    Example 3:

    \n
    Input: ransomNote = \"aa\", magazine = \"aab\"\nOutput: true\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= ransomNote.length, magazine.length <= 105
    • \n\t
    • ransomNote and magazine consist of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u8d4e\u91d1\u4fe1 (ransom) \u5b57\u7b26\u4e32\u548c\u4e00\u4e2a\u6742\u5fd7(magazine)\u5b57\u7b26\u4e32\uff0c\u5224\u65ad\u7b2c\u4e00\u4e2a\u5b57\u7b26\u4e32 ransom \u80fd\u4e0d\u80fd\u7531\u7b2c\u4e8c\u4e2a\u5b57\u7b26\u4e32 magazines \u91cc\u9762\u7684\u5b57\u7b26\u6784\u6210\u3002\u5982\u679c\u53ef\u4ee5\u6784\u6210\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\u8fd4\u56de false\u3002

    \n\n

    (\u9898\u76ee\u8bf4\u660e\uff1a\u4e3a\u4e86\u4e0d\u66b4\u9732\u8d4e\u91d1\u4fe1\u5b57\u8ff9\uff0c\u8981\u4ece\u6742\u5fd7\u4e0a\u641c\u7d22\u5404\u4e2a\u9700\u8981\u7684\u5b57\u6bcd\uff0c\u7ec4\u6210\u5355\u8bcd\u6765\u8868\u8fbe\u610f\u601d\u3002\u6742\u5fd7\u5b57\u7b26\u4e32\u4e2d\u7684\u6bcf\u4e2a\u5b57\u7b26\u53ea\u80fd\u5728\u8d4e\u91d1\u4fe1\u5b57\u7b26\u4e32\u4e2d\u4f7f\u7528\u4e00\u6b21\u3002)

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aransomNote = \"a\", magazine = \"b\"\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aransomNote = \"aa\", magazine = \"ab\"\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aransomNote = \"aa\", magazine = \"aab\"\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u4f60\u53ef\u4ee5\u5047\u8bbe\u4e24\u4e2a\u5b57\u7b26\u4e32\u5747\u53ea\u542b\u6709\u5c0f\u5199\u5b57\u6bcd\u3002
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canConstruct(string ransomNote, string magazine) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canConstruct(String ransomNote, String magazine) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canConstruct(self, ransomNote, magazine):\n \"\"\"\n :type ransomNote: str\n :type magazine: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canConstruct(self, ransomNote: str, magazine: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canConstruct(char * ransomNote, char * magazine){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanConstruct(string ransomNote, string magazine) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} ransomNote\n * @param {string} magazine\n * @return {boolean}\n */\nvar canConstruct = function(ransomNote, magazine) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} ransom_note\n# @param {String} magazine\n# @return {Boolean}\ndef can_construct(ransom_note, magazine)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canConstruct(_ ransomNote: String, _ magazine: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canConstruct(ransomNote string, magazine string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canConstruct(ransomNote: String, magazine: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canConstruct(ransomNote: String, magazine: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_construct(ransom_note: String, magazine: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $ransomNote\n * @param String $magazine\n * @return Boolean\n */\n function canConstruct($ransomNote, $magazine) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canConstruct(ransomNote: string, magazine: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-construct ransomNote magazine)\n (-> string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0383](https://leetcode-cn.com/problems/ransom-note)", "[\u8d4e\u91d1\u4fe1](/solution/0300-0399/0383.Ransom%20Note/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0383](https://leetcode.com/problems/ransom-note)", "[Ransom Note](/solution/0300-0399/0383.Ransom%20Note/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "0382", "frontend_question_id": "0382", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/linked-list-random-node", "url_en": "https://leetcode.com/problems/linked-list-random-node", "relative_path_cn": "/solution/0300-0399/0382.Linked%20List%20Random%20Node/README.md", "relative_path_en": "/solution/0300-0399/0382.Linked%20List%20Random%20Node/README_EN.md", "title_cn": "\u94fe\u8868\u968f\u673a\u8282\u70b9", "title_en": "Linked List Random Node", "question_title_slug": "linked-list-random-node", "content_en": "

    Given a singly linked list, return a random node's value from the linked list. Each node must have the same probability of being chosen.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput\n["Solution", "getRandom", "getRandom", "getRandom", "getRandom", "getRandom"]\n[[[1, 2, 3]], [], [], [], [], []]\nOutput\n[null, 1, 3, 2, 2, 3]\n\nExplanation\nSolution solution = new Solution([1, 2, 3]);\nsolution.getRandom(); // return 1\nsolution.getRandom(); // return 3\nsolution.getRandom(); // return 2\nsolution.getRandom(); // return 2\nsolution.getRandom(); // return 3\n// getRandom() should return either 1, 2, or 3 randomly. Each element should have equal probability of returning.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the linked list will be in the range [1, 104].
    • \n\t
    • -104 <= Node.val <= 104
    • \n\t
    • At most 104 calls will be made to getRandom.
    • \n
    \n\n

     

    \n

    Follow up:

    \n\n
      \n\t
    • What if the linked list is extremely large and its length is unknown to you?
    • \n\t
    • Could you solve this efficiently without using extra space?
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5355\u94fe\u8868\uff0c\u968f\u673a\u9009\u62e9\u94fe\u8868\u7684\u4e00\u4e2a\u8282\u70b9\uff0c\u5e76\u8fd4\u56de\u76f8\u5e94\u7684\u8282\u70b9\u503c\u3002\u4fdd\u8bc1\u6bcf\u4e2a\u8282\u70b9\u88ab\u9009\u7684\u6982\u7387\u4e00\u6837\u3002

    \n\n

    \u8fdb\u9636:
    \n\u5982\u679c\u94fe\u8868\u5341\u5206\u5927\u4e14\u957f\u5ea6\u672a\u77e5\uff0c\u5982\u4f55\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff1f\u4f60\u80fd\u5426\u4f7f\u7528\u5e38\u6570\u7ea7\u7a7a\u95f4\u590d\u6742\u5ea6\u5b9e\u73b0\uff1f

    \n\n

    \u793a\u4f8b:

    \n\n
    \n// \u521d\u59cb\u5316\u4e00\u4e2a\u5355\u94fe\u8868 [1,2,3].\nListNode head = new ListNode(1);\nhead.next = new ListNode(2);\nhead.next.next = new ListNode(3);\nSolution solution = new Solution(head);\n\n// getRandom()\u65b9\u6cd5\u5e94\u968f\u673a\u8fd4\u56de1,2,3\u4e2d\u7684\u4e00\u4e2a\uff0c\u4fdd\u8bc1\u6bcf\u4e2a\u5143\u7d20\u88ab\u8fd4\u56de\u7684\u6982\u7387\u76f8\u7b49\u3002\nsolution.getRandom();\n
    \n", "tags_en": ["Reservoir Sampling"], "tags_cn": ["\u84c4\u6c34\u6c60\u62bd\u6837"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n /** @param head The linked list's head.\n Note that the head is guaranteed to be not null, so it contains at least one node. */\n Solution(ListNode* head) {\n\n }\n \n /** Returns a random node's value. */\n int getRandom() {\n\n }\n};\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution* obj = new Solution(head);\n * int param_1 = obj->getRandom();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n\n /** @param head The linked list's head.\n Note that the head is guaranteed to be not null, so it contains at least one node. */\n public Solution(ListNode head) {\n\n }\n \n /** Returns a random node's value. */\n public int getRandom() {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution obj = new Solution(head);\n * int param_1 = obj.getRandom();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n\n def __init__(self, head):\n \"\"\"\n @param head The linked list's head.\n Note that the head is guaranteed to be not null, so it contains at least one node.\n :type head: ListNode\n \"\"\"\n\n\n def getRandom(self):\n \"\"\"\n Returns a random node's value.\n :rtype: int\n \"\"\"\n\n\n\n# Your Solution object will be instantiated and called as such:\n# obj = Solution(head)\n# param_1 = obj.getRandom()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n\n def __init__(self, head: ListNode):\n \"\"\"\n @param head The linked list's head.\n Note that the head is guaranteed to be not null, so it contains at least one node.\n \"\"\"\n\n\n def getRandom(self) -> int:\n \"\"\"\n Returns a random node's value.\n \"\"\"\n\n\n\n# Your Solution object will be instantiated and called as such:\n# obj = Solution(head)\n# param_1 = obj.getRandom()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\n\ntypedef struct {\n\n} Solution;\n\n/** @param head The linked list's head.\n Note that the head is guaranteed to be not null, so it contains at least one node. */\n\nSolution* solutionCreate(struct ListNode* head) {\n\n}\n\n/** Returns a random node's value. */\nint solutionGetRandom(Solution* obj) {\n\n}\n\nvoid solutionFree(Solution* obj) {\n\n}\n\n/**\n * Your Solution struct will be instantiated and called as such:\n * Solution* obj = solutionCreate(head);\n * int param_1 = solutionGetRandom(obj);\n \n * solutionFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n\n /** @param head The linked list's head.\n Note that the head is guaranteed to be not null, so it contains at least one node. */\n public Solution(ListNode head) {\n\n }\n \n /** Returns a random node's value. */\n public int GetRandom() {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution obj = new Solution(head);\n * int param_1 = obj.GetRandom();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param head The linked list's head.\n Note that the head is guaranteed to be not null, so it contains at least one node.\n * @param {ListNode} head\n */\nvar Solution = function(head) {\n\n};\n\n/**\n * Returns a random node's value.\n * @return {number}\n */\nSolution.prototype.getRandom = function() {\n\n};\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = new Solution(head)\n * var param_1 = obj.getRandom()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\nclass Solution\n\n=begin\n @param head The linked list's head.\n Note that the head is guaranteed to be not null, so it contains at least one node.\n :type head: ListNode\n=end\n def initialize(head)\n\n end\n\n\n=begin\n Returns a random node's value.\n :rtype: Integer\n=end\n def get_random()\n\n end\n\n\nend\n\n# Your Solution object will be instantiated and called as such:\n# obj = Solution.new(head)\n# param_1 = obj.get_random()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\n\nclass Solution {\n\n /** @param head The linked list's head.\n Note that the head is guaranteed to be not null, so it contains at least one node. */\n init(_ head: ListNode?) {\n\n }\n \n /** Returns a random node's value. */\n func getRandom() -> Int {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * let obj = Solution(head)\n * let ret_1: Int = obj.getRandom()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\ntype Solution struct {\n\n}\n\n\n/** @param head The linked list's head.\n Note that the head is guaranteed to be not null, so it contains at least one node. */\nfunc Constructor(head *ListNode) Solution {\n\n}\n\n\n/** Returns a random node's value. */\nfunc (this *Solution) GetRandom() int {\n\n}\n\n\n/**\n * Your Solution object will be instantiated and called as such:\n * obj := Constructor(head);\n * param_1 := obj.GetRandom();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nclass Solution(_head: ListNode) {\n\n /** @param head The linked list's head.\n Note that the head is guaranteed to be not null, so it contains at least one node. */\n\n\n /** Returns a random node's value. */\n def getRandom(): Int = {\n\n }\n\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = new Solution(head)\n * var param_1 = obj.getRandom()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution(head: ListNode?) {\n\n /** @param head The linked list's head.\n Note that the head is guaranteed to be not null, so it contains at least one node. */\n\n\n /** Returns a random node's value. */\n fun getRandom(): Int {\n\n }\n\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = Solution(head)\n * var param_1 = obj.getRandom()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nstruct Solution {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl Solution {\n\n /** @param head The linked list's head.\n Note that the head is guaranteed to be not null, so it contains at least one node. */\n fn new(head: Option>) -> Self {\n\n }\n \n /** Returns a random node's value. */\n fn get_random(&self) -> i32 {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * let obj = Solution::new(head);\n * let ret_1: i32 = obj.get_random();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n /**\n * @param head The linked list's head.\n Note that the head is guaranteed to be not null, so it contains at least one node.\n * @param ListNode $head\n */\n function __construct($head) {\n\n }\n\n /**\n * Returns a random node's value.\n * @return Integer\n */\n function getRandom() {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * $obj = Solution($head);\n * $ret_1 = $obj->getRandom();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nclass Solution {\n constructor(head: ListNode | null) {\n\n }\n\n getRandom(): number {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = new Solution(head)\n * var param_1 = obj.getRandom()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define solution%\n (class object%\n (super-new)\n\n ; head : (or/c list-node? #f)\n (init-field\n head)\n \n ; get-random : -> exact-integer?\n (define/public (get-random)\n\n )))\n\n;; Your solution% object will be instantiated and called as such:\n;; (define obj (new solution% [head head]))\n;; (define param_1 (send obj get-random))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0382](https://leetcode-cn.com/problems/linked-list-random-node)", "[\u94fe\u8868\u968f\u673a\u8282\u70b9](/solution/0300-0399/0382.Linked%20List%20Random%20Node/README.md)", "`\u84c4\u6c34\u6c60\u62bd\u6837`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0382](https://leetcode.com/problems/linked-list-random-node)", "[Linked List Random Node](/solution/0300-0399/0382.Linked%20List%20Random%20Node/README_EN.md)", "`Reservoir Sampling`", "Medium", ""]}, {"question_id": "0381", "frontend_question_id": "0381", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/insert-delete-getrandom-o1-duplicates-allowed", "url_en": "https://leetcode.com/problems/insert-delete-getrandom-o1-duplicates-allowed", "relative_path_cn": "/solution/0300-0399/0381.Insert%20Delete%20GetRandom%20O%281%29%20-%20Duplicates%20allowed/README.md", "relative_path_en": "/solution/0300-0399/0381.Insert%20Delete%20GetRandom%20O%281%29%20-%20Duplicates%20allowed/README_EN.md", "title_cn": "O(1) \u65f6\u95f4\u63d2\u5165\u3001\u5220\u9664\u548c\u83b7\u53d6\u968f\u673a\u5143\u7d20 - \u5141\u8bb8\u91cd\u590d", "title_en": "Insert Delete GetRandom O(1) - Duplicates allowed", "question_title_slug": "insert-delete-getrandom-o1-duplicates-allowed", "content_en": "

    Implement the RandomizedCollection class:

    \n\n
      \n\t
    • RandomizedCollection() Initializes the RandomizedCollection object.
    • \n\t
    • bool insert(int val) Inserts an item val into the multiset if not present. Returns true if the item was not present, false otherwise.
    • \n\t
    • bool remove(int val) Removes an item val from the multiset if present. Returns true if the item was present, false otherwise. Note that if val has multiple occurrences in the multiset, we only remove one of them.
    • \n\t
    • int getRandom() Returns a random element from the current multiset of elements (it's guaranteed that at least one element exists when this method is called). The probability of each element being returned is linearly related to the number of same values the multiset contains.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["RandomizedCollection", "insert", "insert", "insert", "getRandom", "remove", "getRandom"]\n[[], [1], [1], [2], [], [1], []]\nOutput\n[null, true, false, true, 2, true, 1]\n\nExplanation\nRandomizedCollection randomizedCollection = new RandomizedCollection();\nrandomizedCollection.insert(1);   // return True. Inserts 1 to the collection. Returns true as the collection did not contain 1.\nrandomizedCollection.insert(1);   // return False. Inserts another 1 to the collection. Returns false as the collection contained 1. Collection now contains [1,1].\nrandomizedCollection.insert(2);   // return True. Inserts 2 to the collection, returns true. Collection now contains [1,1,2].\nrandomizedCollection.getRandom(); // getRandom should return 1 with the probability 2/3, and returns 2 with the probability 1/3.\nrandomizedCollection.remove(1);   // return True. Removes 1 from the collection, returns true. Collection now contains [1,2].\nrandomizedCollection.getRandom(); // getRandom should return 1 and 2 both equally likely.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • -231 <= val <= 231 - 1
    • \n\t
    • At most 105 calls will be made to insert, remove, and getRandom.
    • \n\t
    • There will be at least one element in the data structure when getRandom is called.
    • \n
    \n\n

     

    \nFollow up: Could you implement the functions of the class with each function works in average O(1) time?", "content_cn": "

    \u8bbe\u8ba1\u4e00\u4e2a\u652f\u6301\u5728\u5e73\u5747 \u65f6\u95f4\u590d\u6742\u5ea6 O(1) \u4e0b\uff0c \u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\u7684\u6570\u636e\u7ed3\u6784\u3002

    \n\n

    \u6ce8\u610f: \u5141\u8bb8\u51fa\u73b0\u91cd\u590d\u5143\u7d20\u3002

    \n\n
      \n\t
    1. insert(val)\uff1a\u5411\u96c6\u5408\u4e2d\u63d2\u5165\u5143\u7d20 val\u3002
    2. \n\t
    3. remove(val)\uff1a\u5f53 val \u5b58\u5728\u65f6\uff0c\u4ece\u96c6\u5408\u4e2d\u79fb\u9664\u4e00\u4e2a val\u3002
    4. \n\t
    5. getRandom\uff1a\u4ece\u73b0\u6709\u96c6\u5408\u4e2d\u968f\u673a\u83b7\u53d6\u4e00\u4e2a\u5143\u7d20\u3002\u6bcf\u4e2a\u5143\u7d20\u88ab\u8fd4\u56de\u7684\u6982\u7387\u5e94\u8be5\u4e0e\u5176\u5728\u96c6\u5408\u4e2d\u7684\u6570\u91cf\u5448\u7ebf\u6027\u76f8\u5173\u3002
    6. \n
    \n\n

    \u793a\u4f8b:

    \n\n
    // \u521d\u59cb\u5316\u4e00\u4e2a\u7a7a\u7684\u96c6\u5408\u3002\nRandomizedCollection collection = new RandomizedCollection();\n\n// \u5411\u96c6\u5408\u4e2d\u63d2\u5165 1 \u3002\u8fd4\u56de true \u8868\u793a\u96c6\u5408\u4e0d\u5305\u542b 1 \u3002\ncollection.insert(1);\n\n// \u5411\u96c6\u5408\u4e2d\u63d2\u5165\u53e6\u4e00\u4e2a 1 \u3002\u8fd4\u56de false \u8868\u793a\u96c6\u5408\u5305\u542b 1 \u3002\u96c6\u5408\u73b0\u5728\u5305\u542b [1,1] \u3002\ncollection.insert(1);\n\n// \u5411\u96c6\u5408\u4e2d\u63d2\u5165 2 \uff0c\u8fd4\u56de true \u3002\u96c6\u5408\u73b0\u5728\u5305\u542b [1,1,2] \u3002\ncollection.insert(2);\n\n// getRandom \u5e94\u5f53\u6709 2/3 \u7684\u6982\u7387\u8fd4\u56de 1 \uff0c1/3 \u7684\u6982\u7387\u8fd4\u56de 2 \u3002\ncollection.getRandom();\n\n// \u4ece\u96c6\u5408\u4e2d\u5220\u9664 1 \uff0c\u8fd4\u56de true \u3002\u96c6\u5408\u73b0\u5728\u5305\u542b [1,2] \u3002\ncollection.remove(1);\n\n// getRandom \u5e94\u6709\u76f8\u540c\u6982\u7387\u8fd4\u56de 1 \u548c 2 \u3002\ncollection.getRandom();\n
    \n", "tags_en": ["Design", "Array", "Hash Table"], "tags_cn": ["\u8bbe\u8ba1", "\u6570\u7ec4", "\u54c8\u5e0c\u8868"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class RandomizedCollection {\npublic:\n /** Initialize your data structure here. */\n RandomizedCollection() {\n\n }\n \n /** Inserts a value to the collection. Returns true if the collection did not already contain the specified element. */\n bool insert(int val) {\n\n }\n \n /** Removes a value from the collection. Returns true if the collection contained the specified element. */\n bool remove(int val) {\n\n }\n \n /** Get a random element from the collection. */\n int getRandom() {\n\n }\n};\n\n/**\n * Your RandomizedCollection object will be instantiated and called as such:\n * RandomizedCollection* obj = new RandomizedCollection();\n * bool param_1 = obj->insert(val);\n * bool param_2 = obj->remove(val);\n * int param_3 = obj->getRandom();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class RandomizedCollection {\n\n /** Initialize your data structure here. */\n public RandomizedCollection() {\n\n }\n \n /** Inserts a value to the collection. Returns true if the collection did not already contain the specified element. */\n public boolean insert(int val) {\n\n }\n \n /** Removes a value from the collection. Returns true if the collection contained the specified element. */\n public boolean remove(int val) {\n\n }\n \n /** Get a random element from the collection. */\n public int getRandom() {\n\n }\n}\n\n/**\n * Your RandomizedCollection object will be instantiated and called as such:\n * RandomizedCollection obj = new RandomizedCollection();\n * boolean param_1 = obj.insert(val);\n * boolean param_2 = obj.remove(val);\n * int param_3 = obj.getRandom();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class RandomizedCollection(object):\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def insert(self, val):\n \"\"\"\n Inserts a value to the collection. Returns true if the collection did not already contain the specified element.\n :type val: int\n :rtype: bool\n \"\"\"\n\n\n def remove(self, val):\n \"\"\"\n Removes a value from the collection. Returns true if the collection contained the specified element.\n :type val: int\n :rtype: bool\n \"\"\"\n\n\n def getRandom(self):\n \"\"\"\n Get a random element from the collection.\n :rtype: int\n \"\"\"\n\n\n\n# Your RandomizedCollection object will be instantiated and called as such:\n# obj = RandomizedCollection()\n# param_1 = obj.insert(val)\n# param_2 = obj.remove(val)\n# param_3 = obj.getRandom()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class RandomizedCollection:\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def insert(self, val: int) -> bool:\n \"\"\"\n Inserts a value to the collection. Returns true if the collection did not already contain the specified element.\n \"\"\"\n\n\n def remove(self, val: int) -> bool:\n \"\"\"\n Removes a value from the collection. Returns true if the collection contained the specified element.\n \"\"\"\n\n\n def getRandom(self) -> int:\n \"\"\"\n Get a random element from the collection.\n \"\"\"\n\n\n\n# Your RandomizedCollection object will be instantiated and called as such:\n# obj = RandomizedCollection()\n# param_1 = obj.insert(val)\n# param_2 = obj.remove(val)\n# param_3 = obj.getRandom()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} RandomizedCollection;\n\n/** Initialize your data structure here. */\n\nRandomizedCollection* randomizedCollectionCreate() {\n\n}\n\n/** Inserts a value to the collection. Returns true if the collection did not already contain the specified element. */\nbool randomizedCollectionInsert(RandomizedCollection* obj, int val) {\n\n}\n\n/** Removes a value from the collection. Returns true if the collection contained the specified element. */\nbool randomizedCollectionRemove(RandomizedCollection* obj, int val) {\n\n}\n\n/** Get a random element from the collection. */\nint randomizedCollectionGetRandom(RandomizedCollection* obj) {\n\n}\n\nvoid randomizedCollectionFree(RandomizedCollection* obj) {\n\n}\n\n/**\n * Your RandomizedCollection struct will be instantiated and called as such:\n * RandomizedCollection* obj = randomizedCollectionCreate();\n * bool param_1 = randomizedCollectionInsert(obj, val);\n \n * bool param_2 = randomizedCollectionRemove(obj, val);\n \n * int param_3 = randomizedCollectionGetRandom(obj);\n \n * randomizedCollectionFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class RandomizedCollection {\n\n /** Initialize your data structure here. */\n public RandomizedCollection() {\n\n }\n \n /** Inserts a value to the collection. Returns true if the collection did not already contain the specified element. */\n public bool Insert(int val) {\n\n }\n \n /** Removes a value from the collection. Returns true if the collection contained the specified element. */\n public bool Remove(int val) {\n\n }\n \n /** Get a random element from the collection. */\n public int GetRandom() {\n\n }\n}\n\n/**\n * Your RandomizedCollection object will be instantiated and called as such:\n * RandomizedCollection obj = new RandomizedCollection();\n * bool param_1 = obj.Insert(val);\n * bool param_2 = obj.Remove(val);\n * int param_3 = obj.GetRandom();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Initialize your data structure here.\n */\nvar RandomizedCollection = function() {\n\n};\n\n/**\n * Inserts a value to the collection. Returns true if the collection did not already contain the specified element. \n * @param {number} val\n * @return {boolean}\n */\nRandomizedCollection.prototype.insert = function(val) {\n\n};\n\n/**\n * Removes a value from the collection. Returns true if the collection contained the specified element. \n * @param {number} val\n * @return {boolean}\n */\nRandomizedCollection.prototype.remove = function(val) {\n\n};\n\n/**\n * Get a random element from the collection.\n * @return {number}\n */\nRandomizedCollection.prototype.getRandom = function() {\n\n};\n\n/**\n * Your RandomizedCollection object will be instantiated and called as such:\n * var obj = new RandomizedCollection()\n * var param_1 = obj.insert(val)\n * var param_2 = obj.remove(val)\n * var param_3 = obj.getRandom()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class RandomizedCollection\n\n=begin\n Initialize your data structure here.\n=end\n def initialize()\n\n end\n\n\n=begin\n Inserts a value to the collection. Returns true if the collection did not already contain the specified element.\n :type val: Integer\n :rtype: Boolean\n=end\n def insert(val)\n\n end\n\n\n=begin\n Removes a value from the collection. Returns true if the collection contained the specified element.\n :type val: Integer\n :rtype: Boolean\n=end\n def remove(val)\n\n end\n\n\n=begin\n Get a random element from the collection.\n :rtype: Integer\n=end\n def get_random()\n\n end\n\n\nend\n\n# Your RandomizedCollection object will be instantiated and called as such:\n# obj = RandomizedCollection.new()\n# param_1 = obj.insert(val)\n# param_2 = obj.remove(val)\n# param_3 = obj.get_random()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass RandomizedCollection {\n\n /** Initialize your data structure here. */\n init() {\n\n }\n \n /** Inserts a value to the collection. Returns true if the collection did not already contain the specified element. */\n func insert(_ val: Int) -> Bool {\n\n }\n \n /** Removes a value from the collection. Returns true if the collection contained the specified element. */\n func remove(_ val: Int) -> Bool {\n\n }\n \n /** Get a random element from the collection. */\n func getRandom() -> Int {\n\n }\n}\n\n/**\n * Your RandomizedCollection object will be instantiated and called as such:\n * let obj = RandomizedCollection()\n * let ret_1: Bool = obj.insert(val)\n * let ret_2: Bool = obj.remove(val)\n * let ret_3: Int = obj.getRandom()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type RandomizedCollection struct {\n\n}\n\n\n/** Initialize your data structure here. */\nfunc Constructor() RandomizedCollection {\n\n}\n\n\n/** Inserts a value to the collection. Returns true if the collection did not already contain the specified element. */\nfunc (this *RandomizedCollection) Insert(val int) bool {\n\n}\n\n\n/** Removes a value from the collection. Returns true if the collection contained the specified element. */\nfunc (this *RandomizedCollection) Remove(val int) bool {\n\n}\n\n\n/** Get a random element from the collection. */\nfunc (this *RandomizedCollection) GetRandom() int {\n\n}\n\n\n/**\n * Your RandomizedCollection object will be instantiated and called as such:\n * obj := Constructor();\n * param_1 := obj.Insert(val);\n * param_2 := obj.Remove(val);\n * param_3 := obj.GetRandom();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class RandomizedCollection() {\n\n /** Initialize your data structure here. */\n\n\n /** Inserts a value to the collection. Returns true if the collection did not already contain the specified element. */\n def insert(`val`: Int): Boolean = {\n\n }\n\n /** Removes a value from the collection. Returns true if the collection contained the specified element. */\n def remove(`val`: Int): Boolean = {\n\n }\n\n /** Get a random element from the collection. */\n def getRandom(): Int = {\n\n }\n\n}\n\n/**\n * Your RandomizedCollection object will be instantiated and called as such:\n * var obj = new RandomizedCollection()\n * var param_1 = obj.insert(`val`)\n * var param_2 = obj.remove(`val`)\n * var param_3 = obj.getRandom()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class RandomizedCollection() {\n\n /** Initialize your data structure here. */\n\n\n /** Inserts a value to the collection. Returns true if the collection did not already contain the specified element. */\n fun insert(`val`: Int): Boolean {\n\n }\n\n /** Removes a value from the collection. Returns true if the collection contained the specified element. */\n fun remove(`val`: Int): Boolean {\n\n }\n\n /** Get a random element from the collection. */\n fun getRandom(): Int {\n\n }\n\n}\n\n/**\n * Your RandomizedCollection object will be instantiated and called as such:\n * var obj = RandomizedCollection()\n * var param_1 = obj.insert(`val`)\n * var param_2 = obj.remove(`val`)\n * var param_3 = obj.getRandom()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct RandomizedCollection {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl RandomizedCollection {\n\n /** Initialize your data structure here. */\n fn new() -> Self {\n\n }\n \n /** Inserts a value to the collection. Returns true if the collection did not already contain the specified element. */\n fn insert(&self, val: i32) -> bool {\n\n }\n \n /** Removes a value from the collection. Returns true if the collection contained the specified element. */\n fn remove(&self, val: i32) -> bool {\n\n }\n \n /** Get a random element from the collection. */\n fn get_random(&self) -> i32 {\n\n }\n}\n\n/**\n * Your RandomizedCollection object will be instantiated and called as such:\n * let obj = RandomizedCollection::new();\n * let ret_1: bool = obj.insert(val);\n * let ret_2: bool = obj.remove(val);\n * let ret_3: i32 = obj.get_random();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class RandomizedCollection {\n /**\n * Initialize your data structure here.\n */\n function __construct() {\n\n }\n\n /**\n * Inserts a value to the collection. Returns true if the collection did not already contain the specified element.\n * @param Integer $val\n * @return Boolean\n */\n function insert($val) {\n\n }\n\n /**\n * Removes a value from the collection. Returns true if the collection contained the specified element.\n * @param Integer $val\n * @return Boolean\n */\n function remove($val) {\n\n }\n\n /**\n * Get a random element from the collection.\n * @return Integer\n */\n function getRandom() {\n\n }\n}\n\n/**\n * Your RandomizedCollection object will be instantiated and called as such:\n * $obj = RandomizedCollection();\n * $ret_1 = $obj->insert($val);\n * $ret_2 = $obj->remove($val);\n * $ret_3 = $obj->getRandom();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class RandomizedCollection {\n constructor() {\n\n }\n\n insert(val: number): boolean {\n\n }\n\n remove(val: number): boolean {\n\n }\n\n getRandom(): number {\n\n }\n}\n\n/**\n * Your RandomizedCollection object will be instantiated and called as such:\n * var obj = new RandomizedCollection()\n * var param_1 = obj.insert(val)\n * var param_2 = obj.remove(val)\n * var param_3 = obj.getRandom()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define randomized-collection%\n (class object%\n (super-new)\n (init-field)\n \n ; insert : exact-integer? -> boolean?\n (define/public (insert val)\n\n )\n ; remove : exact-integer? -> boolean?\n (define/public (remove val)\n\n )\n ; get-random : -> exact-integer?\n (define/public (get-random)\n\n )))\n\n;; Your randomized-collection% object will be instantiated and called as such:\n;; (define obj (new randomized-collection%))\n;; (define param_1 (send obj insert val))\n;; (define param_2 (send obj remove val))\n;; (define param_3 (send obj get-random))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0381](https://leetcode-cn.com/problems/insert-delete-getrandom-o1-duplicates-allowed)", "[O(1) \u65f6\u95f4\u63d2\u5165\u3001\u5220\u9664\u548c\u83b7\u53d6\u968f\u673a\u5143\u7d20 - \u5141\u8bb8\u91cd\u590d](/solution/0300-0399/0381.Insert%20Delete%20GetRandom%20O%281%29%20-%20Duplicates%20allowed/README.md)", "`\u8bbe\u8ba1`,`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`", "\u56f0\u96be", ""], "md_table_row_en": ["[0381](https://leetcode.com/problems/insert-delete-getrandom-o1-duplicates-allowed)", "[Insert Delete GetRandom O(1) - Duplicates allowed](/solution/0300-0399/0381.Insert%20Delete%20GetRandom%20O%281%29%20-%20Duplicates%20allowed/README_EN.md)", "`Design`,`Array`,`Hash Table`", "Hard", ""]}, {"question_id": "0380", "frontend_question_id": "0380", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/insert-delete-getrandom-o1", "url_en": "https://leetcode.com/problems/insert-delete-getrandom-o1", "relative_path_cn": "/solution/0300-0399/0380.Insert%20Delete%20GetRandom%20O%281%29/README.md", "relative_path_en": "/solution/0300-0399/0380.Insert%20Delete%20GetRandom%20O%281%29/README_EN.md", "title_cn": "O(1) \u65f6\u95f4\u63d2\u5165\u3001\u5220\u9664\u548c\u83b7\u53d6\u968f\u673a\u5143\u7d20", "title_en": "Insert Delete GetRandom O(1)", "question_title_slug": "insert-delete-getrandom-o1", "content_en": "

    Implement the RandomizedSet class:

    \n\n
      \n\t
    • RandomizedSet() Initializes the RandomizedSet object.
    • \n\t
    • bool insert(int val) Inserts an item val into the set if not present. Returns true if the item was not present, false otherwise.
    • \n\t
    • bool remove(int val) Removes an item val from the set if present. Returns true if the item was present, false otherwise.
    • \n\t
    • int getRandom() Returns a random element from the current set of elements (it's guaranteed that at least one element exists when this method is called). Each element must have the same probability of being returned.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["RandomizedSet", "insert", "remove", "insert", "getRandom", "remove", "insert", "getRandom"]\n[[], [1], [2], [2], [], [1], [2], []]\nOutput\n[null, true, false, true, 2, true, false, 2]\n\nExplanation\nRandomizedSet randomizedSet = new RandomizedSet();\nrandomizedSet.insert(1); // Inserts 1 to the set. Returns true as 1 was inserted successfully.\nrandomizedSet.remove(2); // Returns false as 2 does not exist in the set.\nrandomizedSet.insert(2); // Inserts 2 to the set, returns true. Set now contains [1,2].\nrandomizedSet.getRandom(); // getRandom() should return either 1 or 2 randomly.\nrandomizedSet.remove(1); // Removes 1 from the set, returns true. Set now contains [2].\nrandomizedSet.insert(2); // 2 was already in the set, so return false.\nrandomizedSet.getRandom(); // Since 2 is the only number in the set, getRandom() will always return 2.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • -231 <= val <= 231 - 1
    • \n\t
    • At most 105 calls will be made to insert, remove, and getRandom.
    • \n\t
    • There will be at least one element in the data structure when getRandom is called.
    • \n
    \n\n

     

    \nFollow up: Could you implement the functions of the class with each function works in average O(1) time?", "content_cn": "

    \u8bbe\u8ba1\u4e00\u4e2a\u652f\u6301\u5728\u5e73\u5747 \u65f6\u95f4\u590d\u6742\u5ea6 O(1) \u4e0b\uff0c\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\u7684\u6570\u636e\u7ed3\u6784\u3002

    \n\n
      \n\t
    1. insert(val)\uff1a\u5f53\u5143\u7d20 val \u4e0d\u5b58\u5728\u65f6\uff0c\u5411\u96c6\u5408\u4e2d\u63d2\u5165\u8be5\u9879\u3002
    2. \n\t
    3. remove(val)\uff1a\u5143\u7d20 val \u5b58\u5728\u65f6\uff0c\u4ece\u96c6\u5408\u4e2d\u79fb\u9664\u8be5\u9879\u3002
    4. \n\t
    5. getRandom\uff1a\u968f\u673a\u8fd4\u56de\u73b0\u6709\u96c6\u5408\u4e2d\u7684\u4e00\u9879\u3002\u6bcf\u4e2a\u5143\u7d20\u5e94\u8be5\u6709\u76f8\u540c\u7684\u6982\u7387\u88ab\u8fd4\u56de\u3002
    6. \n
    \n\n

    \u793a\u4f8b :

    \n\n
    \n// \u521d\u59cb\u5316\u4e00\u4e2a\u7a7a\u7684\u96c6\u5408\u3002\nRandomizedSet randomSet = new RandomizedSet();\n\n// \u5411\u96c6\u5408\u4e2d\u63d2\u5165 1 \u3002\u8fd4\u56de true \u8868\u793a 1 \u88ab\u6210\u529f\u5730\u63d2\u5165\u3002\nrandomSet.insert(1);\n\n// \u8fd4\u56de false \uff0c\u8868\u793a\u96c6\u5408\u4e2d\u4e0d\u5b58\u5728 2 \u3002\nrandomSet.remove(2);\n\n// \u5411\u96c6\u5408\u4e2d\u63d2\u5165 2 \u3002\u8fd4\u56de true \u3002\u96c6\u5408\u73b0\u5728\u5305\u542b [1,2] \u3002\nrandomSet.insert(2);\n\n// getRandom \u5e94\u968f\u673a\u8fd4\u56de 1 \u6216 2 \u3002\nrandomSet.getRandom();\n\n// \u4ece\u96c6\u5408\u4e2d\u79fb\u9664 1 \uff0c\u8fd4\u56de true \u3002\u96c6\u5408\u73b0\u5728\u5305\u542b [2] \u3002\nrandomSet.remove(1);\n\n// 2 \u5df2\u5728\u96c6\u5408\u4e2d\uff0c\u6240\u4ee5\u8fd4\u56de false \u3002\nrandomSet.insert(2);\n\n// \u7531\u4e8e 2 \u662f\u96c6\u5408\u4e2d\u552f\u4e00\u7684\u6570\u5b57\uff0cgetRandom \u603b\u662f\u8fd4\u56de 2 \u3002\nrandomSet.getRandom();\n
    \n", "tags_en": ["Design", "Array", "Hash Table"], "tags_cn": ["\u8bbe\u8ba1", "\u6570\u7ec4", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class RandomizedSet {\npublic:\n /** Initialize your data structure here. */\n RandomizedSet() {\n\n }\n \n /** Inserts a value to the set. Returns true if the set did not already contain the specified element. */\n bool insert(int val) {\n\n }\n \n /** Removes a value from the set. Returns true if the set contained the specified element. */\n bool remove(int val) {\n\n }\n \n /** Get a random element from the set. */\n int getRandom() {\n\n }\n};\n\n/**\n * Your RandomizedSet object will be instantiated and called as such:\n * RandomizedSet* obj = new RandomizedSet();\n * bool param_1 = obj->insert(val);\n * bool param_2 = obj->remove(val);\n * int param_3 = obj->getRandom();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class RandomizedSet {\n\n /** Initialize your data structure here. */\n public RandomizedSet() {\n\n }\n \n /** Inserts a value to the set. Returns true if the set did not already contain the specified element. */\n public boolean insert(int val) {\n\n }\n \n /** Removes a value from the set. Returns true if the set contained the specified element. */\n public boolean remove(int val) {\n\n }\n \n /** Get a random element from the set. */\n public int getRandom() {\n\n }\n}\n\n/**\n * Your RandomizedSet object will be instantiated and called as such:\n * RandomizedSet obj = new RandomizedSet();\n * boolean param_1 = obj.insert(val);\n * boolean param_2 = obj.remove(val);\n * int param_3 = obj.getRandom();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class RandomizedSet(object):\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def insert(self, val):\n \"\"\"\n Inserts a value to the set. Returns true if the set did not already contain the specified element.\n :type val: int\n :rtype: bool\n \"\"\"\n\n\n def remove(self, val):\n \"\"\"\n Removes a value from the set. Returns true if the set contained the specified element.\n :type val: int\n :rtype: bool\n \"\"\"\n\n\n def getRandom(self):\n \"\"\"\n Get a random element from the set.\n :rtype: int\n \"\"\"\n\n\n\n# Your RandomizedSet object will be instantiated and called as such:\n# obj = RandomizedSet()\n# param_1 = obj.insert(val)\n# param_2 = obj.remove(val)\n# param_3 = obj.getRandom()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class RandomizedSet:\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def insert(self, val: int) -> bool:\n \"\"\"\n Inserts a value to the set. Returns true if the set did not already contain the specified element.\n \"\"\"\n\n\n def remove(self, val: int) -> bool:\n \"\"\"\n Removes a value from the set. Returns true if the set contained the specified element.\n \"\"\"\n\n\n def getRandom(self) -> int:\n \"\"\"\n Get a random element from the set.\n \"\"\"\n\n\n\n# Your RandomizedSet object will be instantiated and called as such:\n# obj = RandomizedSet()\n# param_1 = obj.insert(val)\n# param_2 = obj.remove(val)\n# param_3 = obj.getRandom()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} RandomizedSet;\n\n/** Initialize your data structure here. */\n\nRandomizedSet* randomizedSetCreate() {\n\n}\n\n/** Inserts a value to the set. Returns true if the set did not already contain the specified element. */\nbool randomizedSetInsert(RandomizedSet* obj, int val) {\n\n}\n\n/** Removes a value from the set. Returns true if the set contained the specified element. */\nbool randomizedSetRemove(RandomizedSet* obj, int val) {\n\n}\n\n/** Get a random element from the set. */\nint randomizedSetGetRandom(RandomizedSet* obj) {\n\n}\n\nvoid randomizedSetFree(RandomizedSet* obj) {\n\n}\n\n/**\n * Your RandomizedSet struct will be instantiated and called as such:\n * RandomizedSet* obj = randomizedSetCreate();\n * bool param_1 = randomizedSetInsert(obj, val);\n \n * bool param_2 = randomizedSetRemove(obj, val);\n \n * int param_3 = randomizedSetGetRandom(obj);\n \n * randomizedSetFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class RandomizedSet {\n\n /** Initialize your data structure here. */\n public RandomizedSet() {\n\n }\n \n /** Inserts a value to the set. Returns true if the set did not already contain the specified element. */\n public bool Insert(int val) {\n\n }\n \n /** Removes a value from the set. Returns true if the set contained the specified element. */\n public bool Remove(int val) {\n\n }\n \n /** Get a random element from the set. */\n public int GetRandom() {\n\n }\n}\n\n/**\n * Your RandomizedSet object will be instantiated and called as such:\n * RandomizedSet obj = new RandomizedSet();\n * bool param_1 = obj.Insert(val);\n * bool param_2 = obj.Remove(val);\n * int param_3 = obj.GetRandom();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Initialize your data structure here.\n */\nvar RandomizedSet = function() {\n\n};\n\n/**\n * Inserts a value to the set. Returns true if the set did not already contain the specified element. \n * @param {number} val\n * @return {boolean}\n */\nRandomizedSet.prototype.insert = function(val) {\n\n};\n\n/**\n * Removes a value from the set. Returns true if the set contained the specified element. \n * @param {number} val\n * @return {boolean}\n */\nRandomizedSet.prototype.remove = function(val) {\n\n};\n\n/**\n * Get a random element from the set.\n * @return {number}\n */\nRandomizedSet.prototype.getRandom = function() {\n\n};\n\n/**\n * Your RandomizedSet object will be instantiated and called as such:\n * var obj = new RandomizedSet()\n * var param_1 = obj.insert(val)\n * var param_2 = obj.remove(val)\n * var param_3 = obj.getRandom()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class RandomizedSet\n\n=begin\n Initialize your data structure here.\n=end\n def initialize()\n\n end\n\n\n=begin\n Inserts a value to the set. Returns true if the set did not already contain the specified element.\n :type val: Integer\n :rtype: Boolean\n=end\n def insert(val)\n\n end\n\n\n=begin\n Removes a value from the set. Returns true if the set contained the specified element.\n :type val: Integer\n :rtype: Boolean\n=end\n def remove(val)\n\n end\n\n\n=begin\n Get a random element from the set.\n :rtype: Integer\n=end\n def get_random()\n\n end\n\n\nend\n\n# Your RandomizedSet object will be instantiated and called as such:\n# obj = RandomizedSet.new()\n# param_1 = obj.insert(val)\n# param_2 = obj.remove(val)\n# param_3 = obj.get_random()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass RandomizedSet {\n\n /** Initialize your data structure here. */\n init() {\n\n }\n \n /** Inserts a value to the set. Returns true if the set did not already contain the specified element. */\n func insert(_ val: Int) -> Bool {\n\n }\n \n /** Removes a value from the set. Returns true if the set contained the specified element. */\n func remove(_ val: Int) -> Bool {\n\n }\n \n /** Get a random element from the set. */\n func getRandom() -> Int {\n\n }\n}\n\n/**\n * Your RandomizedSet object will be instantiated and called as such:\n * let obj = RandomizedSet()\n * let ret_1: Bool = obj.insert(val)\n * let ret_2: Bool = obj.remove(val)\n * let ret_3: Int = obj.getRandom()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type RandomizedSet struct {\n\n}\n\n\n/** Initialize your data structure here. */\nfunc Constructor() RandomizedSet {\n\n}\n\n\n/** Inserts a value to the set. Returns true if the set did not already contain the specified element. */\nfunc (this *RandomizedSet) Insert(val int) bool {\n\n}\n\n\n/** Removes a value from the set. Returns true if the set contained the specified element. */\nfunc (this *RandomizedSet) Remove(val int) bool {\n\n}\n\n\n/** Get a random element from the set. */\nfunc (this *RandomizedSet) GetRandom() int {\n\n}\n\n\n/**\n * Your RandomizedSet object will be instantiated and called as such:\n * obj := Constructor();\n * param_1 := obj.Insert(val);\n * param_2 := obj.Remove(val);\n * param_3 := obj.GetRandom();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class RandomizedSet() {\n\n /** Initialize your data structure here. */\n\n\n /** Inserts a value to the set. Returns true if the set did not already contain the specified element. */\n def insert(`val`: Int): Boolean = {\n\n }\n\n /** Removes a value from the set. Returns true if the set contained the specified element. */\n def remove(`val`: Int): Boolean = {\n\n }\n\n /** Get a random element from the set. */\n def getRandom(): Int = {\n\n }\n\n}\n\n/**\n * Your RandomizedSet object will be instantiated and called as such:\n * var obj = new RandomizedSet()\n * var param_1 = obj.insert(`val`)\n * var param_2 = obj.remove(`val`)\n * var param_3 = obj.getRandom()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class RandomizedSet() {\n\n /** Initialize your data structure here. */\n\n\n /** Inserts a value to the set. Returns true if the set did not already contain the specified element. */\n fun insert(`val`: Int): Boolean {\n\n }\n\n /** Removes a value from the set. Returns true if the set contained the specified element. */\n fun remove(`val`: Int): Boolean {\n\n }\n\n /** Get a random element from the set. */\n fun getRandom(): Int {\n\n }\n\n}\n\n/**\n * Your RandomizedSet object will be instantiated and called as such:\n * var obj = RandomizedSet()\n * var param_1 = obj.insert(`val`)\n * var param_2 = obj.remove(`val`)\n * var param_3 = obj.getRandom()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct RandomizedSet {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl RandomizedSet {\n\n /** Initialize your data structure here. */\n fn new() -> Self {\n\n }\n \n /** Inserts a value to the set. Returns true if the set did not already contain the specified element. */\n fn insert(&self, val: i32) -> bool {\n\n }\n \n /** Removes a value from the set. Returns true if the set contained the specified element. */\n fn remove(&self, val: i32) -> bool {\n\n }\n \n /** Get a random element from the set. */\n fn get_random(&self) -> i32 {\n\n }\n}\n\n/**\n * Your RandomizedSet object will be instantiated and called as such:\n * let obj = RandomizedSet::new();\n * let ret_1: bool = obj.insert(val);\n * let ret_2: bool = obj.remove(val);\n * let ret_3: i32 = obj.get_random();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class RandomizedSet {\n /**\n * Initialize your data structure here.\n */\n function __construct() {\n\n }\n\n /**\n * Inserts a value to the set. Returns true if the set did not already contain the specified element.\n * @param Integer $val\n * @return Boolean\n */\n function insert($val) {\n\n }\n\n /**\n * Removes a value from the set. Returns true if the set contained the specified element.\n * @param Integer $val\n * @return Boolean\n */\n function remove($val) {\n\n }\n\n /**\n * Get a random element from the set.\n * @return Integer\n */\n function getRandom() {\n\n }\n}\n\n/**\n * Your RandomizedSet object will be instantiated and called as such:\n * $obj = RandomizedSet();\n * $ret_1 = $obj->insert($val);\n * $ret_2 = $obj->remove($val);\n * $ret_3 = $obj->getRandom();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class RandomizedSet {\n constructor() {\n\n }\n\n insert(val: number): boolean {\n\n }\n\n remove(val: number): boolean {\n\n }\n\n getRandom(): number {\n\n }\n}\n\n/**\n * Your RandomizedSet object will be instantiated and called as such:\n * var obj = new RandomizedSet()\n * var param_1 = obj.insert(val)\n * var param_2 = obj.remove(val)\n * var param_3 = obj.getRandom()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define randomized-set%\n (class object%\n (super-new)\n (init-field)\n \n ; insert : exact-integer? -> boolean?\n (define/public (insert val)\n\n )\n ; remove : exact-integer? -> boolean?\n (define/public (remove val)\n\n )\n ; get-random : -> exact-integer?\n (define/public (get-random)\n\n )))\n\n;; Your randomized-set% object will be instantiated and called as such:\n;; (define obj (new randomized-set%))\n;; (define param_1 (send obj insert val))\n;; (define param_2 (send obj remove val))\n;; (define param_3 (send obj get-random))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0380](https://leetcode-cn.com/problems/insert-delete-getrandom-o1)", "[O(1) \u65f6\u95f4\u63d2\u5165\u3001\u5220\u9664\u548c\u83b7\u53d6\u968f\u673a\u5143\u7d20](/solution/0300-0399/0380.Insert%20Delete%20GetRandom%20O%281%29/README.md)", "`\u8bbe\u8ba1`,`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0380](https://leetcode.com/problems/insert-delete-getrandom-o1)", "[Insert Delete GetRandom O(1)](/solution/0300-0399/0380.Insert%20Delete%20GetRandom%20O%281%29/README_EN.md)", "`Design`,`Array`,`Hash Table`", "Medium", ""]}, {"question_id": "0379", "frontend_question_id": "0379", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/design-phone-directory", "url_en": "https://leetcode.com/problems/design-phone-directory", "relative_path_cn": "/solution/0300-0399/0379.Design%20Phone%20Directory/README.md", "relative_path_en": "/solution/0300-0399/0379.Design%20Phone%20Directory/README_EN.md", "title_cn": "\u7535\u8bdd\u76ee\u5f55\u7ba1\u7406\u7cfb\u7edf", "title_en": "Design Phone Directory", "question_title_slug": "design-phone-directory", "content_en": "

    Design a phone directory that initially has maxNumbers empty slots that can store numbers. The directory should store numbers, check if a certain slot is empty or not, and empty a given slot.

    \n\n

    Implement the PhoneDirectory class:

    \n\n
      \n\t
    • PhoneDirectory(int maxNumbers) Initializes the phone directory with the number of available slots maxNumbers.
    • \n\t
    • int get() Provides a number that is not assigned to anyone. Returns -1 if no number is available.
    • \n\t
    • bool check(int number) Returns true if the slot number is available and false otherwise.
    • \n\t
    • void release(int number) Recycles or releases the slot number.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["PhoneDirectory", "get", "get", "check", "get", "check", "release", "check"]\n[[3], [], [], [2], [], [2], [2], [2]]\nOutput\n[null, 0, 1, true, 2, false, null, true]\n\nExplanation\nPhoneDirectory phoneDirectory = new PhoneDirectory(3);\nphoneDirectory.get();      // It can return any available phone number. Here we assume it returns 0.\nphoneDirectory.get();      // Assume it returns 1.\nphoneDirectory.check(2);   // The number 2 is available, so return true.\nphoneDirectory.get();      // It returns 2, the only number that is left.\nphoneDirectory.check(2);   // The number 2 is no longer available, so return false.\nphoneDirectory.release(2); // Release number 2 back to the pool.\nphoneDirectory.check(2);   // Number 2 is available again, return true.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= maxNumbers <= 104
    • \n\t
    • 0 <= number < maxNumbers
    • \n\t
    • At most 2 * 104 calls will be made to get, check, and release.
    • \n
    \n", "content_cn": "

    \u8bbe\u8ba1\u4e00\u4e2a\u7535\u8bdd\u76ee\u5f55\u7ba1\u7406\u7cfb\u7edf\uff0c\u8ba9\u5b83\u652f\u6301\u4ee5\u4e0b\u529f\u80fd\uff1a

    \n\n
      \n\t
    1. get: \u5206\u914d\u7ed9\u7528\u6237\u4e00\u4e2a\u672a\u88ab\u4f7f\u7528\u7684\u7535\u8bdd\u53f7\u7801\uff0c\u83b7\u53d6\u5931\u8d25\u8bf7\u8fd4\u56de -1
    2. \n\t
    3. check: \u68c0\u67e5\u6307\u5b9a\u7684\u7535\u8bdd\u53f7\u7801\u662f\u5426\u88ab\u4f7f\u7528
    4. \n\t
    5. release: \u91ca\u653e\u6389\u4e00\u4e2a\u7535\u8bdd\u53f7\u7801\uff0c\u4f7f\u5176\u80fd\u591f\u91cd\u65b0\u88ab\u5206\u914d
    6. \n
    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    // \u521d\u59cb\u5316\u7535\u8bdd\u76ee\u5f55\uff0c\u5305\u62ec 3 \u4e2a\u7535\u8bdd\u53f7\u7801\uff1a0\uff0c1 \u548c 2\u3002\nPhoneDirectory directory = new PhoneDirectory(3);\n\n// \u53ef\u4ee5\u8fd4\u56de\u4efb\u610f\u672a\u5206\u914d\u7684\u53f7\u7801\uff0c\u8fd9\u91cc\u6211\u4eec\u5047\u8bbe\u5b83\u8fd4\u56de 0\u3002\ndirectory.get();\n\n// \u5047\u8bbe\uff0c\u51fd\u6570\u8fd4\u56de 1\u3002\ndirectory.get();\n\n// \u53f7\u7801 2 \u672a\u5206\u914d\uff0c\u6240\u4ee5\u8fd4\u56de\u4e3a true\u3002\ndirectory.check(2);\n\n// \u8fd4\u56de 2\uff0c\u5206\u914d\u540e\uff0c\u53ea\u5269\u4e00\u4e2a\u53f7\u7801\u672a\u88ab\u5206\u914d\u3002\ndirectory.get();\n\n// \u6b64\u65f6\uff0c\u53f7\u7801 2 \u5df2\u7ecf\u88ab\u5206\u914d\uff0c\u6240\u4ee5\u8fd4\u56de false\u3002\ndirectory.check(2);\n\n// \u91ca\u653e\u53f7\u7801 2\uff0c\u5c06\u8be5\u53f7\u7801\u53d8\u56de\u672a\u5206\u914d\u72b6\u6001\u3002\ndirectory.release(2);\n\n// \u53f7\u7801 2 \u73b0\u5728\u662f\u672a\u5206\u914d\u72b6\u6001\uff0c\u6240\u4ee5\u8fd4\u56de true\u3002\ndirectory.check(2);\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= maxNumbers <= 10^4
    • \n\t
    • 0 <= number < maxNumbers
    • \n\t
    • \u8c03\u7528\u65b9\u6cd5\u7684\u603b\u6570\u5904\u4e8e\u533a\u95f4 [0 - 20000] \u4e4b\u5185
    • \n
    \n", "tags_en": ["Design", "Linked List"], "tags_cn": ["\u8bbe\u8ba1", "\u94fe\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class PhoneDirectory {\npublic:\n /** Initialize your data structure here\n @param maxNumbers - The maximum numbers that can be stored in the phone directory. */\n PhoneDirectory(int maxNumbers) {\n\n }\n \n /** Provide a number which is not assigned to anyone.\n @return - Return an available number. Return -1 if none is available. */\n int get() {\n\n }\n \n /** Check if a number is available or not. */\n bool check(int number) {\n\n }\n \n /** Recycle or release a number. */\n void release(int number) {\n\n }\n};\n\n/**\n * Your PhoneDirectory object will be instantiated and called as such:\n * PhoneDirectory* obj = new PhoneDirectory(maxNumbers);\n * int param_1 = obj->get();\n * bool param_2 = obj->check(number);\n * obj->release(number);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class PhoneDirectory {\n\n /** Initialize your data structure here\n @param maxNumbers - The maximum numbers that can be stored in the phone directory. */\n public PhoneDirectory(int maxNumbers) {\n\n }\n \n /** Provide a number which is not assigned to anyone.\n @return - Return an available number. Return -1 if none is available. */\n public int get() {\n\n }\n \n /** Check if a number is available or not. */\n public boolean check(int number) {\n\n }\n \n /** Recycle or release a number. */\n public void release(int number) {\n\n }\n}\n\n/**\n * Your PhoneDirectory object will be instantiated and called as such:\n * PhoneDirectory obj = new PhoneDirectory(maxNumbers);\n * int param_1 = obj.get();\n * boolean param_2 = obj.check(number);\n * obj.release(number);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class PhoneDirectory(object):\n\n def __init__(self, maxNumbers):\n \"\"\"\n Initialize your data structure here\n @param maxNumbers - The maximum numbers that can be stored in the phone directory.\n :type maxNumbers: int\n \"\"\"\n\n\n def get(self):\n \"\"\"\n Provide a number which is not assigned to anyone.\n @return - Return an available number. Return -1 if none is available.\n :rtype: int\n \"\"\"\n\n\n def check(self, number):\n \"\"\"\n Check if a number is available or not.\n :type number: int\n :rtype: bool\n \"\"\"\n\n\n def release(self, number):\n \"\"\"\n Recycle or release a number.\n :type number: int\n :rtype: None\n \"\"\"\n\n\n\n# Your PhoneDirectory object will be instantiated and called as such:\n# obj = PhoneDirectory(maxNumbers)\n# param_1 = obj.get()\n# param_2 = obj.check(number)\n# obj.release(number)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class PhoneDirectory:\n\n def __init__(self, maxNumbers: int):\n \"\"\"\n Initialize your data structure here\n @param maxNumbers - The maximum numbers that can be stored in the phone directory.\n \"\"\"\n\n\n def get(self) -> int:\n \"\"\"\n Provide a number which is not assigned to anyone.\n @return - Return an available number. Return -1 if none is available.\n \"\"\"\n\n\n def check(self, number: int) -> bool:\n \"\"\"\n Check if a number is available or not.\n \"\"\"\n\n\n def release(self, number: int) -> None:\n \"\"\"\n Recycle or release a number.\n \"\"\"\n\n\n\n# Your PhoneDirectory object will be instantiated and called as such:\n# obj = PhoneDirectory(maxNumbers)\n# param_1 = obj.get()\n# param_2 = obj.check(number)\n# obj.release(number)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} PhoneDirectory;\n\n/** Initialize your data structure here\n @param maxNumbers - The maximum numbers that can be stored in the phone directory. */\n\nPhoneDirectory* phoneDirectoryCreate(int maxNumbers) {\n\n}\n\n/** Provide a number which is not assigned to anyone.\n @return - Return an available number. Return -1 if none is available. */\nint phoneDirectoryGet(PhoneDirectory* obj) {\n\n}\n\n/** Check if a number is available or not. */\nbool phoneDirectoryCheck(PhoneDirectory* obj, int number) {\n\n}\n\n/** Recycle or release a number. */\nvoid phoneDirectoryRelease(PhoneDirectory* obj, int number) {\n\n}\n\nvoid phoneDirectoryFree(PhoneDirectory* obj) {\n\n}\n\n/**\n * Your PhoneDirectory struct will be instantiated and called as such:\n * PhoneDirectory* obj = phoneDirectoryCreate(maxNumbers);\n * int param_1 = phoneDirectoryGet(obj);\n \n * bool param_2 = phoneDirectoryCheck(obj, number);\n \n * phoneDirectoryRelease(obj, number);\n \n * phoneDirectoryFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class PhoneDirectory {\n\n /** Initialize your data structure here\n @param maxNumbers - The maximum numbers that can be stored in the phone directory. */\n public PhoneDirectory(int maxNumbers) {\n\n }\n \n /** Provide a number which is not assigned to anyone.\n @return - Return an available number. Return -1 if none is available. */\n public int Get() {\n\n }\n \n /** Check if a number is available or not. */\n public bool Check(int number) {\n\n }\n \n /** Recycle or release a number. */\n public void Release(int number) {\n\n }\n}\n\n/**\n * Your PhoneDirectory object will be instantiated and called as such:\n * PhoneDirectory obj = new PhoneDirectory(maxNumbers);\n * int param_1 = obj.Get();\n * bool param_2 = obj.Check(number);\n * obj.Release(number);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Initialize your data structure here\n @param maxNumbers - The maximum numbers that can be stored in the phone directory.\n * @param {number} maxNumbers\n */\nvar PhoneDirectory = function(maxNumbers) {\n\n};\n\n/**\n * Provide a number which is not assigned to anyone.\n @return - Return an available number. Return -1 if none is available.\n * @return {number}\n */\nPhoneDirectory.prototype.get = function() {\n\n};\n\n/**\n * Check if a number is available or not. \n * @param {number} number\n * @return {boolean}\n */\nPhoneDirectory.prototype.check = function(number) {\n\n};\n\n/**\n * Recycle or release a number. \n * @param {number} number\n * @return {void}\n */\nPhoneDirectory.prototype.release = function(number) {\n\n};\n\n/**\n * Your PhoneDirectory object will be instantiated and called as such:\n * var obj = new PhoneDirectory(maxNumbers)\n * var param_1 = obj.get()\n * var param_2 = obj.check(number)\n * obj.release(number)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class PhoneDirectory\n\n=begin\n Initialize your data structure here\n @param maxNumbers - The maximum numbers that can be stored in the phone directory.\n :type max_numbers: Integer\n=end\n def initialize(max_numbers)\n\n end\n\n\n=begin\n Provide a number which is not assigned to anyone.\n @return - Return an available number. Return -1 if none is available.\n :rtype: Integer\n=end\n def get()\n\n end\n\n\n=begin\n Check if a number is available or not.\n :type number: Integer\n :rtype: Boolean\n=end\n def check(number)\n\n end\n\n\n=begin\n Recycle or release a number.\n :type number: Integer\n :rtype: Void\n=end\n def release(number)\n\n end\n\n\nend\n\n# Your PhoneDirectory object will be instantiated and called as such:\n# obj = PhoneDirectory.new(max_numbers)\n# param_1 = obj.get()\n# param_2 = obj.check(number)\n# obj.release(number)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass PhoneDirectory {\n\n /** Initialize your data structure here\n @param maxNumbers - The maximum numbers that can be stored in the phone directory. */\n init(_ maxNumbers: Int) {\n\n }\n \n /** Provide a number which is not assigned to anyone.\n @return - Return an available number. Return -1 if none is available. */\n func get() -> Int {\n\n }\n \n /** Check if a number is available or not. */\n func check(_ number: Int) -> Bool {\n\n }\n \n /** Recycle or release a number. */\n func release(_ number: Int) {\n\n }\n}\n\n/**\n * Your PhoneDirectory object will be instantiated and called as such:\n * let obj = PhoneDirectory(maxNumbers)\n * let ret_1: Int = obj.get()\n * let ret_2: Bool = obj.check(number)\n * obj.release(number)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type PhoneDirectory struct {\n\n}\n\n\n/** Initialize your data structure here\n @param maxNumbers - The maximum numbers that can be stored in the phone directory. */\nfunc Constructor(maxNumbers int) PhoneDirectory {\n\n}\n\n\n/** Provide a number which is not assigned to anyone.\n @return - Return an available number. Return -1 if none is available. */\nfunc (this *PhoneDirectory) Get() int {\n\n}\n\n\n/** Check if a number is available or not. */\nfunc (this *PhoneDirectory) Check(number int) bool {\n\n}\n\n\n/** Recycle or release a number. */\nfunc (this *PhoneDirectory) Release(number int) {\n\n}\n\n\n/**\n * Your PhoneDirectory object will be instantiated and called as such:\n * obj := Constructor(maxNumbers);\n * param_1 := obj.Get();\n * param_2 := obj.Check(number);\n * obj.Release(number);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class PhoneDirectory(_maxNumbers: Int) {\n\n /** Initialize your data structure here\n @param maxNumbers - The maximum numbers that can be stored in the phone directory. */\n\n\n /** Provide a number which is not assigned to anyone.\n @return - Return an available number. Return -1 if none is available. */\n def get(): Int = {\n\n }\n\n /** Check if a number is available or not. */\n def check(number: Int): Boolean = {\n\n }\n\n /** Recycle or release a number. */\n def release(number: Int) {\n\n }\n\n}\n\n/**\n * Your PhoneDirectory object will be instantiated and called as such:\n * var obj = new PhoneDirectory(maxNumbers)\n * var param_1 = obj.get()\n * var param_2 = obj.check(number)\n * obj.release(number)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class PhoneDirectory(maxNumbers: Int) {\n\n /** Initialize your data structure here\n @param maxNumbers - The maximum numbers that can be stored in the phone directory. */\n\n\n /** Provide a number which is not assigned to anyone.\n @return - Return an available number. Return -1 if none is available. */\n fun get(): Int {\n\n }\n\n /** Check if a number is available or not. */\n fun check(number: Int): Boolean {\n\n }\n\n /** Recycle or release a number. */\n fun release(number: Int) {\n\n }\n\n}\n\n/**\n * Your PhoneDirectory object will be instantiated and called as such:\n * var obj = PhoneDirectory(maxNumbers)\n * var param_1 = obj.get()\n * var param_2 = obj.check(number)\n * obj.release(number)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct PhoneDirectory {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl PhoneDirectory {\n\n /** Initialize your data structure here\n @param maxNumbers - The maximum numbers that can be stored in the phone directory. */\n fn new(maxNumbers: i32) -> Self {\n\n }\n \n /** Provide a number which is not assigned to anyone.\n @return - Return an available number. Return -1 if none is available. */\n fn get(&self) -> i32 {\n\n }\n \n /** Check if a number is available or not. */\n fn check(&self, number: i32) -> bool {\n\n }\n \n /** Recycle or release a number. */\n fn release(&self, number: i32) {\n\n }\n}\n\n/**\n * Your PhoneDirectory object will be instantiated and called as such:\n * let obj = PhoneDirectory::new(maxNumbers);\n * let ret_1: i32 = obj.get();\n * let ret_2: bool = obj.check(number);\n * obj.release(number);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class PhoneDirectory {\n /**\n * Initialize your data structure here\n @param maxNumbers - The maximum numbers that can be stored in the phone directory.\n * @param Integer $maxNumbers\n */\n function __construct($maxNumbers) {\n\n }\n\n /**\n * Provide a number which is not assigned to anyone.\n @return - Return an available number. Return -1 if none is available.\n * @return Integer\n */\n function get() {\n\n }\n\n /**\n * Check if a number is available or not.\n * @param Integer $number\n * @return Boolean\n */\n function check($number) {\n\n }\n\n /**\n * Recycle or release a number.\n * @param Integer $number\n * @return NULL\n */\n function release($number) {\n\n }\n}\n\n/**\n * Your PhoneDirectory object will be instantiated and called as such:\n * $obj = PhoneDirectory($maxNumbers);\n * $ret_1 = $obj->get();\n * $ret_2 = $obj->check($number);\n * $obj->release($number);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class PhoneDirectory {\n constructor(maxNumbers: number) {\n\n }\n\n get(): number {\n\n }\n\n check(number: number): boolean {\n\n }\n\n release(number: number): void {\n\n }\n}\n\n/**\n * Your PhoneDirectory object will be instantiated and called as such:\n * var obj = new PhoneDirectory(maxNumbers)\n * var param_1 = obj.get()\n * var param_2 = obj.check(number)\n * obj.release(number)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define phone-directory%\n (class object%\n (super-new)\n\n ; max-numbers : exact-integer?\n (init-field\n max-numbers)\n \n ; get : -> exact-integer?\n (define/public (get)\n\n )\n ; check : exact-integer? -> boolean?\n (define/public (check number)\n\n )\n ; release : exact-integer? -> void?\n (define/public (release number)\n\n )))\n\n;; Your phone-directory% object will be instantiated and called as such:\n;; (define obj (new phone-directory% [maxNumbers maxNumbers]))\n;; (define param_1 (send obj get))\n;; (define param_2 (send obj check number))\n;; (send obj release number)", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0379](https://leetcode-cn.com/problems/design-phone-directory)", "[\u7535\u8bdd\u76ee\u5f55\u7ba1\u7406\u7cfb\u7edf](/solution/0300-0399/0379.Design%20Phone%20Directory/README.md)", "`\u8bbe\u8ba1`,`\u94fe\u8868`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0379](https://leetcode.com/problems/design-phone-directory)", "[Design Phone Directory](/solution/0300-0399/0379.Design%20Phone%20Directory/README_EN.md)", "`Design`,`Linked List`", "Medium", "\ud83d\udd12"]}, {"question_id": "0378", "frontend_question_id": "0378", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/kth-smallest-element-in-a-sorted-matrix", "url_en": "https://leetcode.com/problems/kth-smallest-element-in-a-sorted-matrix", "relative_path_cn": "/solution/0300-0399/0378.Kth%20Smallest%20Element%20in%20a%20Sorted%20Matrix/README.md", "relative_path_en": "/solution/0300-0399/0378.Kth%20Smallest%20Element%20in%20a%20Sorted%20Matrix/README_EN.md", "title_cn": "\u6709\u5e8f\u77e9\u9635\u4e2d\u7b2c K \u5c0f\u7684\u5143\u7d20", "title_en": "Kth Smallest Element in a Sorted Matrix", "question_title_slug": "kth-smallest-element-in-a-sorted-matrix", "content_en": "

    Given an n x n matrix where each of the rows and columns are sorted in ascending order, return the kth smallest element in the matrix.

    \n\n

    Note that it is the kth smallest element in the sorted order, not the kth distinct element.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: matrix = [[1,5,9],[10,11,13],[12,13,15]], k = 8\nOutput: 13\nExplanation: The elements in the matrix are [1,5,9,10,11,12,13,13,15], and the 8th smallest number is 13\n
    \n\n

    Example 2:

    \n\n
    \nInput: matrix = [[-5]], k = 1\nOutput: -5\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == matrix.length
    • \n\t
    • n == matrix[i].length
    • \n\t
    • 1 <= n <= 300
    • \n\t
    • -109 <= matrix[i][j] <= 109
    • \n\t
    • All the rows and columns of matrix are guaranteed to be sorted in non-decreasing order.
    • \n\t
    • 1 <= k <= n2
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u00a0n x n\u00a0\u77e9\u9635\u00a0matrix \uff0c\u5176\u4e2d\u6bcf\u884c\u548c\u6bcf\u5217\u5143\u7d20\u5747\u6309\u5347\u5e8f\u6392\u5e8f\uff0c\u627e\u5230\u77e9\u9635\u4e2d\u7b2c k \u5c0f\u7684\u5143\u7d20\u3002
    \n\u8bf7\u6ce8\u610f\uff0c\u5b83\u662f \u6392\u5e8f\u540e \u7684\u7b2c k \u5c0f\u5143\u7d20\uff0c\u800c\u4e0d\u662f\u7b2c k \u4e2a \u4e0d\u540c \u7684\u5143\u7d20\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1amatrix = [[1,5,9],[10,11,13],[12,13,15]], k = 8\n\u8f93\u51fa\uff1a13\n\u89e3\u91ca\uff1a\u77e9\u9635\u4e2d\u7684\u5143\u7d20\u4e3a [1,5,9,10,11,12,13,13,15]\uff0c\u7b2c 8 \u5c0f\u5143\u7d20\u662f 13\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1amatrix = [[-5]], k = 1\n\u8f93\u51fa\uff1a-5\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == matrix.length
    • \n\t
    • n == matrix[i].length
    • \n\t
    • 1 <= n <= 300
    • \n\t
    • -109 <= matrix[i][j] <= 109
    • \n\t
    • \u9898\u76ee\u6570\u636e \u4fdd\u8bc1 matrix \u4e2d\u7684\u6240\u6709\u884c\u548c\u5217\u90fd\u6309 \u975e\u9012\u51cf\u987a\u5e8f \u6392\u5217
    • \n\t
    • 1 <= k <= n2
    • \n
    \n", "tags_en": ["Heap", "Binary Search"], "tags_cn": ["\u5806", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int kthSmallest(vector>& matrix, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int kthSmallest(int[][] matrix, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def kthSmallest(self, matrix, k):\n \"\"\"\n :type matrix: List[List[int]]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def kthSmallest(self, matrix: List[List[int]], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint kthSmallest(int** matrix, int matrixSize, int* matrixColSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int KthSmallest(int[][] matrix, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} matrix\n * @param {number} k\n * @return {number}\n */\nvar kthSmallest = function(matrix, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} matrix\n# @param {Integer} k\n# @return {Integer}\ndef kth_smallest(matrix, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func kthSmallest(_ matrix: [[Int]], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func kthSmallest(matrix [][]int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def kthSmallest(matrix: Array[Array[Int]], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun kthSmallest(matrix: Array, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn kth_smallest(matrix: Vec>, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $matrix\n * @param Integer $k\n * @return Integer\n */\n function kthSmallest($matrix, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function kthSmallest(matrix: number[][], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (kth-smallest matrix k)\n (-> (listof (listof exact-integer?)) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0378](https://leetcode-cn.com/problems/kth-smallest-element-in-a-sorted-matrix)", "[\u6709\u5e8f\u77e9\u9635\u4e2d\u7b2c K \u5c0f\u7684\u5143\u7d20](/solution/0300-0399/0378.Kth%20Smallest%20Element%20in%20a%20Sorted%20Matrix/README.md)", "`\u5806`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0378](https://leetcode.com/problems/kth-smallest-element-in-a-sorted-matrix)", "[Kth Smallest Element in a Sorted Matrix](/solution/0300-0399/0378.Kth%20Smallest%20Element%20in%20a%20Sorted%20Matrix/README_EN.md)", "`Heap`,`Binary Search`", "Medium", ""]}, {"question_id": "0377", "frontend_question_id": "0377", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/combination-sum-iv", "url_en": "https://leetcode.com/problems/combination-sum-iv", "relative_path_cn": "/solution/0300-0399/0377.Combination%20Sum%20IV/README.md", "relative_path_en": "/solution/0300-0399/0377.Combination%20Sum%20IV/README_EN.md", "title_cn": "\u7ec4\u5408\u603b\u548c \u2163", "title_en": "Combination Sum IV", "question_title_slug": "combination-sum-iv", "content_en": "

    Given an array of distinct integers nums and a target integer target, return the number of possible combinations that add up to target.

    \n\n

    The answer is guaranteed to fit in a 32-bit integer.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,3], target = 4\nOutput: 7\nExplanation:\nThe possible combination ways are:\n(1, 1, 1, 1)\n(1, 1, 2)\n(1, 2, 1)\n(1, 3)\n(2, 1, 1)\n(2, 2)\n(3, 1)\nNote that different sequences are counted as different combinations.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [9], target = 3\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 200
    • \n\t
    • 1 <= nums[i] <= 1000
    • \n\t
    • All the elements of nums are unique.
    • \n\t
    • 1 <= target <= 1000
    • \n
    \n\n

     

    \n

    Follow up: What if negative numbers are allowed in the given array? How does it change the problem? What limitation we need to add to the question to allow negative numbers?

    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u7531 \u4e0d\u540c \u6574\u6570\u7ec4\u6210\u7684\u6570\u7ec4 nums \uff0c\u548c\u4e00\u4e2a\u76ee\u6807\u6574\u6570 target \u3002\u8bf7\u4f60\u4ece nums \u4e2d\u627e\u51fa\u5e76\u8fd4\u56de\u603b\u548c\u4e3a target \u7684\u5143\u7d20\u7ec4\u5408\u7684\u4e2a\u6570\u3002

    \n\n

    \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u7b54\u6848\u7b26\u5408 32 \u4f4d\u6574\u6570\u8303\u56f4\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,3], target = 4\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\n\u6240\u6709\u53ef\u80fd\u7684\u7ec4\u5408\u4e3a\uff1a\n(1, 1, 1, 1)\n(1, 1, 2)\n(1, 2, 1)\n(1, 3)\n(2, 1, 1)\n(2, 2)\n(3, 1)\n\u8bf7\u6ce8\u610f\uff0c\u987a\u5e8f\u4e0d\u540c\u7684\u5e8f\u5217\u88ab\u89c6\u4f5c\u4e0d\u540c\u7684\u7ec4\u5408\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [9], target = 3\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 200
    • \n\t
    • 1 <= nums[i] <= 1000
    • \n\t
    • nums \u4e2d\u7684\u6240\u6709\u5143\u7d20 \u4e92\u4e0d\u76f8\u540c
    • \n\t
    • 1 <= target <= 1000
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u5982\u679c\u7ed9\u5b9a\u7684\u6570\u7ec4\u4e2d\u542b\u6709\u8d1f\u6570\u4f1a\u53d1\u751f\u4ec0\u4e48\uff1f\u95ee\u9898\u4f1a\u4ea7\u751f\u4f55\u79cd\u53d8\u5316\uff1f\u5982\u679c\u5141\u8bb8\u8d1f\u6570\u51fa\u73b0\uff0c\u9700\u8981\u5411\u9898\u76ee\u4e2d\u6dfb\u52a0\u54ea\u4e9b\u9650\u5236\u6761\u4ef6\uff1f

    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int combinationSum4(vector& nums, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int combinationSum4(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def combinationSum4(self, nums, target):\n \"\"\"\n :type nums: List[int]\n :type target: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def combinationSum4(self, nums: List[int], target: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint combinationSum4(int* nums, int numsSize, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CombinationSum4(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} target\n * @return {number}\n */\nvar combinationSum4 = function(nums, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} target\n# @return {Integer}\ndef combination_sum4(nums, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func combinationSum4(_ nums: [Int], _ target: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func combinationSum4(nums []int, target int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def combinationSum4(nums: Array[Int], target: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun combinationSum4(nums: IntArray, target: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn combination_sum4(nums: Vec, target: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $target\n * @return Integer\n */\n function combinationSum4($nums, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function combinationSum4(nums: number[], target: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (combination-sum4 nums target)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0377](https://leetcode-cn.com/problems/combination-sum-iv)", "[\u7ec4\u5408\u603b\u548c \u2163](/solution/0300-0399/0377.Combination%20Sum%20IV/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0377](https://leetcode.com/problems/combination-sum-iv)", "[Combination Sum IV](/solution/0300-0399/0377.Combination%20Sum%20IV/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0376", "frontend_question_id": "0376", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/wiggle-subsequence", "url_en": "https://leetcode.com/problems/wiggle-subsequence", "relative_path_cn": "/solution/0300-0399/0376.Wiggle%20Subsequence/README.md", "relative_path_en": "/solution/0300-0399/0376.Wiggle%20Subsequence/README_EN.md", "title_cn": "\u6446\u52a8\u5e8f\u5217", "title_en": "Wiggle Subsequence", "question_title_slug": "wiggle-subsequence", "content_en": "

    A wiggle sequence is a sequence where the differences between successive numbers strictly alternate between positive and negative. The first difference (if one exists) may be either positive or negative. A sequence with one element and a sequence with two non-equal elements are trivially wiggle sequences.

    \n\n
      \n\t
    • For example, [1, 7, 4, 9, 2, 5] is a wiggle sequence because the differences (6, -3, 5, -7, 3) alternate between positive and negative.
    • \n\t
    • In contrast, [1, 4, 7, 2, 5] and [1, 7, 4, 5, 5] are not wiggle sequences. The first is not because its first two differences are positive, and the second is not because its last difference is zero.
    • \n
    \n\n

    A subsequence is obtained by deleting some elements (possibly zero) from the original sequence, leaving the remaining elements in their original order.

    \n\n

    Given an integer array nums, return the length of the longest wiggle subsequence of nums.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,7,4,9,2,5]\nOutput: 6\nExplanation: The entire sequence is a wiggle sequence with differences (6, -3, 5, -7, 3).\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,17,5,10,13,15,10,5,16,8]\nOutput: 7\nExplanation: There are several subsequences that achieve this length.\nOne is [1, 17, 10, 13, 10, 16, 8] with differences (16, -7, 3, -3, 6, -8).\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [1,2,3,4,5,6,7,8,9]\nOutput: 2\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 1000
    • \n\t
    • 0 <= nums[i] <= 1000
    • \n
    \n\n

     

    \n

    Follow up: Could you solve this in O(n) time?

    \n", "content_cn": "

    \u5982\u679c\u8fde\u7eed\u6570\u5b57\u4e4b\u95f4\u7684\u5dee\u4e25\u683c\u5730\u5728\u6b63\u6570\u548c\u8d1f\u6570\u4e4b\u95f4\u4ea4\u66ff\uff0c\u5219\u6570\u5b57\u5e8f\u5217\u79f0\u4e3a \u6446\u52a8\u5e8f\u5217 \u3002\u7b2c\u4e00\u4e2a\u5dee\uff08\u5982\u679c\u5b58\u5728\u7684\u8bdd\uff09\u53ef\u80fd\u662f\u6b63\u6570\u6216\u8d1f\u6570\u3002\u4ec5\u6709\u4e00\u4e2a\u5143\u7d20\u6216\u8005\u542b\u4e24\u4e2a\u4e0d\u7b49\u5143\u7d20\u7684\u5e8f\u5217\u4e5f\u89c6\u4f5c\u6446\u52a8\u5e8f\u5217\u3002

    \n\n
      \n\t
    • \n\t

      \u4f8b\u5982\uff0c\u00a0[1, 7, 4, 9, 2, 5] \u662f\u4e00\u4e2a \u6446\u52a8\u5e8f\u5217 \uff0c\u56e0\u4e3a\u5dee\u503c (6, -3, 5, -7, 3)\u00a0\u662f\u6b63\u8d1f\u4ea4\u66ff\u51fa\u73b0\u7684\u3002

      \n\t
    • \n\t
    • \u76f8\u53cd\uff0c[1, 4, 7, 2, 5]\u00a0\u548c\u00a0[1, 7, 4, 5, 5] \u4e0d\u662f\u6446\u52a8\u5e8f\u5217\uff0c\u7b2c\u4e00\u4e2a\u5e8f\u5217\u662f\u56e0\u4e3a\u5b83\u7684\u524d\u4e24\u4e2a\u5dee\u503c\u90fd\u662f\u6b63\u6570\uff0c\u7b2c\u4e8c\u4e2a\u5e8f\u5217\u662f\u56e0\u4e3a\u5b83\u7684\u6700\u540e\u4e00\u4e2a\u5dee\u503c\u4e3a\u96f6\u3002
    • \n
    \n\n

    \u5b50\u5e8f\u5217 \u53ef\u4ee5\u901a\u8fc7\u4ece\u539f\u59cb\u5e8f\u5217\u4e2d\u5220\u9664\u4e00\u4e9b\uff08\u4e5f\u53ef\u4ee5\u4e0d\u5220\u9664\uff09\u5143\u7d20\u6765\u83b7\u5f97\uff0c\u5269\u4e0b\u7684\u5143\u7d20\u4fdd\u6301\u5176\u539f\u59cb\u987a\u5e8f\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \uff0c\u8fd4\u56de nums \u4e2d\u4f5c\u4e3a \u6446\u52a8\u5e8f\u5217 \u7684 \u6700\u957f\u5b50\u5e8f\u5217\u7684\u957f\u5ea6 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,7,4,9,2,5]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u6574\u4e2a\u5e8f\u5217\u5747\u4e3a\u6446\u52a8\u5e8f\u5217\uff0c\u5404\u5143\u7d20\u4e4b\u95f4\u7684\u5dee\u503c\u4e3a (6, -3, 5, -7, 3) \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,17,5,10,13,15,10,5,16,8]\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\u8fd9\u4e2a\u5e8f\u5217\u5305\u542b\u51e0\u4e2a\u957f\u5ea6\u4e3a 7 \u6446\u52a8\u5e8f\u5217\u3002\n\u5176\u4e2d\u4e00\u4e2a\u662f [1, 17, 10, 13, 10, 16, 8] \uff0c\u5404\u5143\u7d20\u4e4b\u95f4\u7684\u5dee\u503c\u4e3a (16, -7, 3, -3, 6, -8) \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,3,4,5,6,7,8,9]\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 1000
    • \n\t
    • 0 <= nums[i] <= 1000
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u80fd\u5426\u7528\u00a0O(n) \u65f6\u95f4\u590d\u6742\u5ea6\u5b8c\u6210\u6b64\u9898?

    \n", "tags_en": ["Greedy", "Dynamic Programming"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int wiggleMaxLength(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int wiggleMaxLength(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def wiggleMaxLength(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def wiggleMaxLength(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint wiggleMaxLength(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int WiggleMaxLength(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar wiggleMaxLength = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef wiggle_max_length(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func wiggleMaxLength(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func wiggleMaxLength(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def wiggleMaxLength(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun wiggleMaxLength(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn wiggle_max_length(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function wiggleMaxLength($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function wiggleMaxLength(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (wiggle-max-length nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0376](https://leetcode-cn.com/problems/wiggle-subsequence)", "[\u6446\u52a8\u5e8f\u5217](/solution/0300-0399/0376.Wiggle%20Subsequence/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0376](https://leetcode.com/problems/wiggle-subsequence)", "[Wiggle Subsequence](/solution/0300-0399/0376.Wiggle%20Subsequence/README_EN.md)", "`Greedy`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0375", "frontend_question_id": "0375", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/guess-number-higher-or-lower-ii", "url_en": "https://leetcode.com/problems/guess-number-higher-or-lower-ii", "relative_path_cn": "/solution/0300-0399/0375.Guess%20Number%20Higher%20or%20Lower%20II/README.md", "relative_path_en": "/solution/0300-0399/0375.Guess%20Number%20Higher%20or%20Lower%20II/README_EN.md", "title_cn": "\u731c\u6570\u5b57\u5927\u5c0f II", "title_en": "Guess Number Higher or Lower II", "question_title_slug": "guess-number-higher-or-lower-ii", "content_en": "

    We are playing the Guessing Game. The game will work as follows:

    \n\n
      \n\t
    1. I pick a number between 1 and n.
    2. \n\t
    3. You guess a number.
    4. \n\t
    5. If you guess the right number, you win the game.
    6. \n\t
    7. If you guess the wrong number, then I will tell you whether the number I picked is higher or lower, and you will continue guessing.
    8. \n\t
    9. Every time you guess a wrong number x, you will pay x dollars. If you run out of money, you lose the game.
    10. \n
    \n\n

    Given a particular n, return the minimum amount of money you need to guarantee a win regardless of what number I pick.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: n = 10\nOutput: 16\nExplanation: The winning strategy is as follows:\n- The range is [1,10]. Guess 7.\n    - If this is my number, your total is $0. Otherwise, you pay $7.\n    - If my number is higher, the range is [8,10]. Guess 9.\n        - If this is my number, your total is $7. Otherwise, you pay $9.\n        - If my number is higher, it must be 10. Guess 10. Your total is $7 + $9 = $16.\n        - If my number is lower, it must be 8. Guess 8. Your total is $7 + $9 = $16.\n    - If my number is lower, the range is [1,6]. Guess 3.\n        - If this is my number, your total is $7. Otherwise, you pay $3.\n        - If my number is higher, the range is [4,6]. Guess 5.\n            - If this is my number, your total is $7 + $3 = $10. Otherwise, you pay $5.\n            - If my number is higher, it must be 6. Guess 6. Your total is $7 + $3 + $5 = $15.\n            - If my number is lower, it must be 4. Guess 4. Your total is $7 + $3 + $5 = $15.\n        - If my number is lower, the range is [1,2]. Guess 1.\n            - If this is my number, your total is $7 + $3 = $10. Otherwise, you pay $1.\n            - If my number is higher, it must be 2. Guess 2. Your total is $7 + $3 + $1 = $11.\nThe worst case in all these scenarios is that you pay $16. Hence, you only need $16 to guarantee a win.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 1\nOutput: 0\nExplanation: There is only one possible number, so you can guess 1 and not have to pay anything.\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 2\nOutput: 1\nExplanation: There are two possible numbers, 1 and 2.\n- Guess 1.\n    - If this is my number, your total is $0. Otherwise, you pay $1.\n    - If my number is higher, it must be 2. Guess 2. Your total is $1.\nThe worst case is that you pay $1.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 200
    • \n
    \n", "content_cn": "

    \u6211\u4eec\u6b63\u5728\u73a9\u4e00\u4e2a\u731c\u6570\u6e38\u620f\uff0c\u6e38\u620f\u89c4\u5219\u5982\u4e0b\uff1a

    \n\n

    \u6211\u4ece \u5230 n \u4e4b\u95f4\u9009\u62e9\u4e00\u4e2a\u6570\u5b57\uff0c\u4f60\u6765\u731c\u6211\u9009\u4e86\u54ea\u4e2a\u6570\u5b57\u3002

    \n\n

    \u6bcf\u6b21\u4f60\u731c\u9519\u4e86\uff0c\u6211\u90fd\u4f1a\u544a\u8bc9\u4f60\uff0c\u6211\u9009\u7684\u6570\u5b57\u6bd4\u4f60\u7684\u5927\u4e86\u6216\u8005\u5c0f\u4e86\u3002

    \n\n

    \u7136\u800c\uff0c\u5f53\u4f60\u731c\u4e86\u6570\u5b57 x \u5e76\u4e14\u731c\u9519\u4e86\u7684\u65f6\u5019\uff0c\u4f60\u9700\u8981\u652f\u4ed8\u91d1\u989d\u4e3a x \u7684\u73b0\u91d1\u3002\u76f4\u5230\u4f60\u731c\u5230\u6211\u9009\u7684\u6570\u5b57\uff0c\u4f60\u624d\u7b97\u8d62\u5f97\u4e86\u8fd9\u4e2a\u6e38\u620f\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    n = 10, \u6211\u9009\u62e9\u4e868.\n\n\u7b2c\u4e00\u8f6e: \u4f60\u731c\u6211\u9009\u62e9\u7684\u6570\u5b57\u662f5\uff0c\u6211\u4f1a\u544a\u8bc9\u4f60\uff0c\u6211\u7684\u6570\u5b57\u66f4\u5927\u4e00\u4e9b\uff0c\u7136\u540e\u4f60\u9700\u8981\u652f\u4ed85\u5757\u3002\n\u7b2c\u4e8c\u8f6e: \u4f60\u731c\u662f7\uff0c\u6211\u544a\u8bc9\u4f60\uff0c\u6211\u7684\u6570\u5b57\u66f4\u5927\u4e00\u4e9b\uff0c\u4f60\u652f\u4ed87\u5757\u3002\n\u7b2c\u4e09\u8f6e: \u4f60\u731c\u662f9\uff0c\u6211\u544a\u8bc9\u4f60\uff0c\u6211\u7684\u6570\u5b57\u66f4\u5c0f\u4e00\u4e9b\uff0c\u4f60\u652f\u4ed89\u5757\u3002\n\n\u6e38\u620f\u7ed3\u675f\u30028 \u5c31\u662f\u6211\u9009\u7684\u6570\u5b57\u3002\n\n\u4f60\u6700\u7ec8\u8981\u652f\u4ed8 5 + 7 + 9 = 21 \u5757\u94b1\u3002\n
    \n\n

    \u7ed9\u5b9a n ≥ 1\uff0c\u8ba1\u7b97\u4f60\u81f3\u5c11\u9700\u8981\u62e5\u6709\u591a\u5c11\u73b0\u91d1\u624d\u80fd\u786e\u4fdd\u4f60\u80fd\u8d62\u5f97\u8fd9\u4e2a\u6e38\u620f\u3002

    \n", "tags_en": ["Minimax", "Dynamic Programming"], "tags_cn": ["\u6781\u5c0f\u5316\u6781\u5927", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int getMoneyAmount(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int getMoneyAmount(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getMoneyAmount(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getMoneyAmount(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint getMoneyAmount(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int GetMoneyAmount(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar getMoneyAmount = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef get_money_amount(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getMoneyAmount(_ n: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getMoneyAmount(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getMoneyAmount(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getMoneyAmount(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_money_amount(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function getMoneyAmount($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getMoneyAmount(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-money-amount n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0375](https://leetcode-cn.com/problems/guess-number-higher-or-lower-ii)", "[\u731c\u6570\u5b57\u5927\u5c0f II](/solution/0300-0399/0375.Guess%20Number%20Higher%20or%20Lower%20II/README.md)", "`\u6781\u5c0f\u5316\u6781\u5927`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0375](https://leetcode.com/problems/guess-number-higher-or-lower-ii)", "[Guess Number Higher or Lower II](/solution/0300-0399/0375.Guess%20Number%20Higher%20or%20Lower%20II/README_EN.md)", "`Minimax`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0374", "frontend_question_id": "0374", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/guess-number-higher-or-lower", "url_en": "https://leetcode.com/problems/guess-number-higher-or-lower", "relative_path_cn": "/solution/0300-0399/0374.Guess%20Number%20Higher%20or%20Lower/README.md", "relative_path_en": "/solution/0300-0399/0374.Guess%20Number%20Higher%20or%20Lower/README_EN.md", "title_cn": "\u731c\u6570\u5b57\u5927\u5c0f", "title_en": "Guess Number Higher or Lower", "question_title_slug": "guess-number-higher-or-lower", "content_en": "

    We are playing the Guess Game. The game is as follows:

    \n\n

    I pick a number from 1 to n. You have to guess which number I picked.

    \n\n

    Every time you guess wrong, I will tell you whether the number I picked is higher or lower than your guess.

    \n\n

    You call a pre-defined API int guess(int num), which returns 3 possible results:

    \n\n
      \n\t
    • -1: The number I picked is lower than your guess (i.e. pick < num).
    • \n\t
    • 1: The number I picked is higher than your guess (i.e. pick > num).
    • \n\t
    • 0: The number I picked is equal to your guess (i.e. pick == num).
    • \n
    \n\n

    Return the number that I picked.

    \n\n

     

    \n

    Example 1:

    \n
    Input: n = 10, pick = 6\nOutput: 6\n

    Example 2:

    \n
    Input: n = 1, pick = 1\nOutput: 1\n

    Example 3:

    \n
    Input: n = 2, pick = 1\nOutput: 1\n

    Example 4:

    \n
    Input: n = 2, pick = 2\nOutput: 2\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 231 - 1
    • \n\t
    • 1 <= pick <= n
    • \n
    \n", "content_cn": "

    \u731c\u6570\u5b57\u6e38\u620f\u7684\u89c4\u5219\u5982\u4e0b\uff1a

    \n\n
      \n\t
    • \u6bcf\u8f6e\u6e38\u620f\uff0c\u6211\u90fd\u4f1a\u4ece\u00a01\u00a0\u5230\u00a0n \u968f\u673a\u9009\u62e9\u4e00\u4e2a\u6570\u5b57\u3002 \u8bf7\u4f60\u731c\u9009\u51fa\u7684\u662f\u54ea\u4e2a\u6570\u5b57\u3002
    • \n\t
    • \u5982\u679c\u4f60\u731c\u9519\u4e86\uff0c\u6211\u4f1a\u544a\u8bc9\u4f60\uff0c\u4f60\u731c\u6d4b\u7684\u6570\u5b57\u6bd4\u6211\u9009\u51fa\u7684\u6570\u5b57\u662f\u5927\u4e86\u8fd8\u662f\u5c0f\u4e86\u3002
    • \n
    \n\n

    \u4f60\u53ef\u4ee5\u901a\u8fc7\u8c03\u7528\u4e00\u4e2a\u9884\u5148\u5b9a\u4e49\u597d\u7684\u63a5\u53e3 int guess(int num) \u6765\u83b7\u53d6\u731c\u6d4b\u7ed3\u679c\uff0c\u8fd4\u56de\u503c\u4e00\u5171\u6709 3 \u79cd\u53ef\u80fd\u7684\u60c5\u51b5\uff08-1\uff0c1\u00a0\u6216 0\uff09\uff1a

    \n\n
      \n\t
    • -1\uff1a\u6211\u9009\u51fa\u7684\u6570\u5b57\u6bd4\u4f60\u731c\u7684\u6570\u5b57\u5c0f pick < num
    • \n\t
    • 1\uff1a\u6211\u9009\u51fa\u7684\u6570\u5b57\u6bd4\u4f60\u731c\u7684\u6570\u5b57\u5927 pick > num
    • \n\t
    • 0\uff1a\u6211\u9009\u51fa\u7684\u6570\u5b57\u548c\u4f60\u731c\u7684\u6570\u5b57\u4e00\u6837\u3002\u606d\u559c\uff01\u4f60\u731c\u5bf9\u4e86\uff01pick == num
    • \n
    \n\n

    \u8fd4\u56de\u6211\u9009\u51fa\u7684\u6570\u5b57\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 10, pick = 6\n\u8f93\u51fa\uff1a6\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 1, pick = 1\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 2, pick = 1\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 2, pick = 2\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 231 - 1
    • \n\t
    • 1 <= pick <= n
    • \n
    \n", "tags_en": ["Binary Search"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/** \n * Forward declaration of guess API.\n * @param num your guess\n * @return \t -1 if num is lower than the guess number\n *\t\t\t 1 if num is higher than the guess number\n * otherwise return 0\n * int guess(int num);\n */\n\nclass Solution {\npublic:\n int guessNumber(int n) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/** \n * Forward declaration of guess API.\n * @param num your guess\n * @return \t -1 if num is lower than the guess number\n *\t\t\t 1 if num is higher than the guess number\n * otherwise return 0\n * int guess(int num);\n */\n\npublic class Solution extends GuessGame {\n public int guessNumber(int n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# The guess API is already defined for you.\n# @param num, your guess\n# @return -1 if my number is lower, 1 if my number is higher, otherwise return 0\n# def guess(num):\n\nclass Solution(object):\n def guessNumber(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# The guess API is already defined for you.\n# @param num, your guess\n# @return -1 if my number is lower, 1 if my number is higher, otherwise return 0\n# def guess(num: int) -> int:\n\nclass Solution:\n def guessNumber(self, n: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/** \n * Forward declaration of guess API.\n * @param num your guess\n * @return \t -1 if num is lower than the guess number\n *\t\t\t 1 if num is higher than the guess number\n * otherwise return 0\n * int guess(int num);\n */\n\nint guessNumber(int n){\n\t\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/** \n * Forward declaration of guess API.\n * @param num your guess\n * @return \t -1 if num is lower than the guess number\n *\t\t\t 1 if num is higher than the guess number\n * otherwise return 0\n * int guess(int num);\n */\n\npublic class Solution : GuessGame {\n public int GuessNumber(int n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/** \n * Forward declaration of guess API.\n * @param {number} num your guess\n * @return \t -1 if num is lower than the guess number\n *\t\t\t 1 if num is higher than the guess number\n * otherwise return 0\n * var guess = function(num) {}\n */\n\n/**\n * @param {number} n\n * @return {number}\n */\nvar guessNumber = function(n) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# The guess API is already defined for you.\n# @param num, your guess\n# @return -1 if my number is lower, 1 if my number is higher, otherwise return 0\n# def guess(num)\n\ndef guessNumber(n)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/** \n * Forward declaration of guess API.\n * @param num -> your guess number\n * @return \t -1 if the picked number is lower than your guess number\n *\t\t\t 1 if the picked number is higher than your guess number\n * otherwise return 0\n * func guess(_ num: Int) -> Int \n */\n\nclass Solution : GuessGame {\n func guessNumber(_ n: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/** \n * Forward declaration of guess API.\n * @param num your guess\n * @return \t -1 if num is lower than the guess number\n *\t\t\t 1 if num is higher than the guess number\n * otherwise return 0\n * func guess(num int) int;\n */\n\nfunc guessNumber(n int) int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/** \n * The API guess is defined in the parent class.\n * @param num your guess\n * @return \t -1 if num is lower than the guess number\n *\t\t\t 1 if num is higher than the guess number\n * otherwise return 0\n * def guess(num: Int): Int = {}\n */\n\nclass Solution extends GuessGame {\n def guessNumber(n: Int): Int = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/** \n * The API guess is defined in the parent class.\n * @param num your guess\n * @return \t -1 if num is lower than the guess number\n *\t\t\t 1 if num is higher than the guess number\n * otherwise return 0\n * fun guess(num:Int):Int {}\n */\n\nclass Solution:GuessGame() {\n override fun guessNumber(n:Int):Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "/** \n * Forward declaration of guess API.\n * @param num your guess\n * @return \t -1 if num is lower than the guess number\n *\t\t\t 1 if num is higher than the guess number\n * otherwise return 0\n * unsafe fn guess(num: i32) -> i32 {}\n */\n\nimpl Solution {\n unsafe fn guessNumber(n: i32) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/** \n * The API guess is defined in the parent class.\n * @param num your guess\n * @return \t -1 if num is lower than the guess number\n *\t\t\t 1 if num is higher than the guess number\n * otherwise return 0\n * public function guess($num){}\n */\n\nclass Solution extends GuessGame {\n /**\n * @param Integer $n\n * @return Integer\n */\n function guessNumber($n) {\n \n }\n}", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0374](https://leetcode-cn.com/problems/guess-number-higher-or-lower)", "[\u731c\u6570\u5b57\u5927\u5c0f](/solution/0300-0399/0374.Guess%20Number%20Higher%20or%20Lower/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u7b80\u5355", ""], "md_table_row_en": ["[0374](https://leetcode.com/problems/guess-number-higher-or-lower)", "[Guess Number Higher or Lower](/solution/0300-0399/0374.Guess%20Number%20Higher%20or%20Lower/README_EN.md)", "`Binary Search`", "Easy", ""]}, {"question_id": "0373", "frontend_question_id": "0373", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-k-pairs-with-smallest-sums", "url_en": "https://leetcode.com/problems/find-k-pairs-with-smallest-sums", "relative_path_cn": "/solution/0300-0399/0373.Find%20K%20Pairs%20with%20Smallest%20Sums/README.md", "relative_path_en": "/solution/0300-0399/0373.Find%20K%20Pairs%20with%20Smallest%20Sums/README_EN.md", "title_cn": "\u67e5\u627e\u548c\u6700\u5c0f\u7684K\u5bf9\u6570\u5b57", "title_en": "Find K Pairs with Smallest Sums", "question_title_slug": "find-k-pairs-with-smallest-sums", "content_en": "

    You are given two integer arrays nums1 and nums2 sorted in ascending order and an integer k.

    \n\n

    Define a pair (u, v) which consists of one element from the first array and one element from the second array.

    \n\n

    Return the k pairs (u1, v1), (u2, v2), ..., (uk, vk) with the smallest sums.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums1 = [1,7,11], nums2 = [2,4,6], k = 3\nOutput: [[1,2],[1,4],[1,6]]\nExplanation: The first 3 pairs are returned from the sequence: [1,2],[1,4],[1,6],[7,2],[7,4],[11,2],[7,6],[11,4],[11,6]\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums1 = [1,1,2], nums2 = [1,2,3], k = 2\nOutput: [[1,1],[1,1]]\nExplanation: The first 2 pairs are returned from the sequence: [1,1],[1,1],[1,2],[2,1],[1,2],[2,2],[1,3],[1,3],[2,3]\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums1 = [1,2], nums2 = [3], k = 3\nOutput: [[1,3],[2,3]]\nExplanation: All possible pairs are returned from the sequence: [1,3],[2,3]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums1.length, nums2.length <= 104
    • \n\t
    • -109 <= nums1[i], nums2[i] <= 109
    • \n\t
    • nums1 and nums2 both are sorted in ascending order.
    • \n\t
    • 1 <= k <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u4ee5\u5347\u5e8f\u6392\u5217\u7684\u6574\u5f62\u6570\u7ec4 nums1 \u548c nums2, \u4ee5\u53ca\u4e00\u4e2a\u6574\u6570 k\u3002

    \n\n

    \u5b9a\u4e49\u4e00\u5bf9\u503c (u,v)\uff0c\u5176\u4e2d\u7b2c\u4e00\u4e2a\u5143\u7d20\u6765\u81ea nums1\uff0c\u7b2c\u4e8c\u4e2a\u5143\u7d20\u6765\u81ea nums2\u3002

    \n\n

    \u627e\u5230\u548c\u6700\u5c0f\u7684 k \u5bf9\u6570\u5b57 (u1,v1), (u2,v2) ... (uk,vk)\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: nums1 = [1,7,11], nums2 = [2,4,6], k = 3\n\u8f93\u51fa: [1,2],[1,4],[1,6]\n\u89e3\u91ca: \u8fd4\u56de\u5e8f\u5217\u4e2d\u7684\u524d 3 \u5bf9\u6570\uff1a\n     [1,2],[1,4],[1,6],[7,2],[7,4],[11,2],[7,6],[11,4],[11,6]\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: nums1 = [1,1,2], nums2 = [1,2,3], k = 2\n\u8f93\u51fa: [1,1],[1,1]\n\u89e3\u91ca: \u8fd4\u56de\u5e8f\u5217\u4e2d\u7684\u524d 2 \u5bf9\u6570\uff1a\n     [1,1],[1,1],[1,2],[2,1],[1,2],[2,2],[1,3],[1,3],[2,3]\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u8f93\u5165: nums1 = [1,2], nums2 = [3], k = 3 \n\u8f93\u51fa: [1,3],[2,3]\n\u89e3\u91ca: \u4e5f\u53ef\u80fd\u5e8f\u5217\u4e2d\u6240\u6709\u7684\u6570\u5bf9\u90fd\u88ab\u8fd4\u56de:[1,3],[2,3]\n
    \n", "tags_en": ["Heap"], "tags_cn": ["\u5806"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> kSmallestPairs(vector& nums1, vector& nums2, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> kSmallestPairs(int[] nums1, int[] nums2, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def kSmallestPairs(self, nums1, nums2, k):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n :type k: int\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def kSmallestPairs(self, nums1: List[int], nums2: List[int], k: int) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** kSmallestPairs(int* nums1, int nums1Size, int* nums2, int nums2Size, int k, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> KSmallestPairs(int[] nums1, int[] nums2, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums1\n * @param {number[]} nums2\n * @param {number} k\n * @return {number[][]}\n */\nvar kSmallestPairs = function(nums1, nums2, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums1\n# @param {Integer[]} nums2\n# @param {Integer} k\n# @return {Integer[][]}\ndef k_smallest_pairs(nums1, nums2, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func kSmallestPairs(_ nums1: [Int], _ nums2: [Int], _ k: Int) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func kSmallestPairs(nums1 []int, nums2 []int, k int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def kSmallestPairs(nums1: Array[Int], nums2: Array[Int], k: Int): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun kSmallestPairs(nums1: IntArray, nums2: IntArray, k: Int): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn k_smallest_pairs(nums1: Vec, nums2: Vec, k: i32) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums1\n * @param Integer[] $nums2\n * @param Integer $k\n * @return Integer[][]\n */\n function kSmallestPairs($nums1, $nums2, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function kSmallestPairs(nums1: number[], nums2: number[], k: number): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (k-smallest-pairs nums1 nums2 k)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer? (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0373](https://leetcode-cn.com/problems/find-k-pairs-with-smallest-sums)", "[\u67e5\u627e\u548c\u6700\u5c0f\u7684K\u5bf9\u6570\u5b57](/solution/0300-0399/0373.Find%20K%20Pairs%20with%20Smallest%20Sums/README.md)", "`\u5806`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0373](https://leetcode.com/problems/find-k-pairs-with-smallest-sums)", "[Find K Pairs with Smallest Sums](/solution/0300-0399/0373.Find%20K%20Pairs%20with%20Smallest%20Sums/README_EN.md)", "`Heap`", "Medium", ""]}, {"question_id": "0372", "frontend_question_id": "0372", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/super-pow", "url_en": "https://leetcode.com/problems/super-pow", "relative_path_cn": "/solution/0300-0399/0372.Super%20Pow/README.md", "relative_path_en": "/solution/0300-0399/0372.Super%20Pow/README_EN.md", "title_cn": "\u8d85\u7ea7\u6b21\u65b9", "title_en": "Super Pow", "question_title_slug": "super-pow", "content_en": "

    Your task is to calculate ab mod 1337 where a is a positive integer and b is an extremely large positive integer given in the form of an array.

    \n\n

     

    \n

    Example 1:

    \n
    Input: a = 2, b = [3]\nOutput: 8\n

    Example 2:

    \n
    Input: a = 2, b = [1,0]\nOutput: 1024\n

    Example 3:

    \n
    Input: a = 1, b = [4,3,3,8,5,2]\nOutput: 1\n

    Example 4:

    \n
    Input: a = 2147483647, b = [2,0,0]\nOutput: 1198\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= a <= 231 - 1
    • \n\t
    • 1 <= b.length <= 2000
    • \n\t
    • 0 <= b[i] <= 9
    • \n\t
    • b doesn't contain leading zeros.
    • \n
    \n", "content_cn": "

    \u4f60\u7684\u4efb\u52a1\u662f\u8ba1\u7b97\u00a0ab\u00a0\u5bf9\u00a01337 \u53d6\u6a21\uff0ca \u662f\u4e00\u4e2a\u6b63\u6574\u6570\uff0cb \u662f\u4e00\u4e2a\u975e\u5e38\u5927\u7684\u6b63\u6574\u6570\u4e14\u4f1a\u4ee5\u6570\u7ec4\u5f62\u5f0f\u7ed9\u51fa\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aa = 2, b = [3]\n\u8f93\u51fa\uff1a8\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aa = 2, b = [1,0]\n\u8f93\u51fa\uff1a1024\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aa = 1, b = [4,3,3,8,5,2]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1aa = 2147483647, b = [2,0,0]\n\u8f93\u51fa\uff1a1198\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= a <= 231 - 1
    • \n\t
    • 1 <= b.length <= 2000
    • \n\t
    • 0 <= b[i] <= 9
    • \n\t
    • b \u4e0d\u542b\u524d\u5bfc 0
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int superPow(int a, vector& b) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int superPow(int a, int[] b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def superPow(self, a, b):\n \"\"\"\n :type a: int\n :type b: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def superPow(self, a: int, b: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint superPow(int a, int* b, int bSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SuperPow(int a, int[] b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} a\n * @param {number[]} b\n * @return {number}\n */\nvar superPow = function(a, b) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} a\n# @param {Integer[]} b\n# @return {Integer}\ndef super_pow(a, b)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func superPow(_ a: Int, _ b: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func superPow(a int, b []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def superPow(a: Int, b: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun superPow(a: Int, b: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn super_pow(a: i32, b: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $a\n * @param Integer[] $b\n * @return Integer\n */\n function superPow($a, $b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function superPow(a: number, b: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (super-pow a b)\n (-> exact-integer? (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0372](https://leetcode-cn.com/problems/super-pow)", "[\u8d85\u7ea7\u6b21\u65b9](/solution/0300-0399/0372.Super%20Pow/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0372](https://leetcode.com/problems/super-pow)", "[Super Pow](/solution/0300-0399/0372.Super%20Pow/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "0371", "frontend_question_id": "0371", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sum-of-two-integers", "url_en": "https://leetcode.com/problems/sum-of-two-integers", "relative_path_cn": "/solution/0300-0399/0371.Sum%20of%20Two%20Integers/README.md", "relative_path_en": "/solution/0300-0399/0371.Sum%20of%20Two%20Integers/README_EN.md", "title_cn": "\u4e24\u6574\u6570\u4e4b\u548c", "title_en": "Sum of Two Integers", "question_title_slug": "sum-of-two-integers", "content_en": "

    Given two integers a and b, return the sum of the two integers without using the operators + and -.

    \n\n

     

    \n

    Example 1:

    \n
    Input: a = 1, b = 2\nOutput: 3\n

    Example 2:

    \n
    Input: a = 2, b = 3\nOutput: 5\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • -1000 <= a, b <= 1000
    • \n
    \n", "content_cn": "

    \u4e0d\u4f7f\u7528\u8fd0\u7b97\u7b26 + \u548c - \u200b\u200b\u200b\u200b\u200b\u200b\u200b\uff0c\u8ba1\u7b97\u4e24\u6574\u6570 \u200b\u200b\u200b\u200b\u200b\u200b\u200ba \u3001b \u200b\u200b\u200b\u200b\u200b\u200b\u200b\u4e4b\u548c\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: a = 1, b = 2\n\u8f93\u51fa: 3\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: a = -2, b = 3\n\u8f93\u51fa: 1
    \n", "tags_en": ["Bit Manipulation"], "tags_cn": ["\u4f4d\u8fd0\u7b97"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int getSum(int a, int b) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int getSum(int a, int b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getSum(self, a, b):\n \"\"\"\n :type a: int\n :type b: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getSum(self, a: int, b: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint getSum(int a, int b){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int GetSum(int a, int b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} a\n * @param {number} b\n * @return {number}\n */\nvar getSum = function(a, b) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} a\n# @param {Integer} b\n# @return {Integer}\ndef get_sum(a, b)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getSum(_ a: Int, _ b: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getSum(a int, b int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getSum(a: Int, b: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getSum(a: Int, b: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_sum(a: i32, b: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $a\n * @param Integer $b\n * @return Integer\n */\n function getSum($a, $b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getSum(a: number, b: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-sum a b)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0371](https://leetcode-cn.com/problems/sum-of-two-integers)", "[\u4e24\u6574\u6570\u4e4b\u548c](/solution/0300-0399/0371.Sum%20of%20Two%20Integers/README.md)", "`\u4f4d\u8fd0\u7b97`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0371](https://leetcode.com/problems/sum-of-two-integers)", "[Sum of Two Integers](/solution/0300-0399/0371.Sum%20of%20Two%20Integers/README_EN.md)", "`Bit Manipulation`", "Medium", ""]}, {"question_id": "0370", "frontend_question_id": "0370", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/range-addition", "url_en": "https://leetcode.com/problems/range-addition", "relative_path_cn": "/solution/0300-0399/0370.Range%20Addition/README.md", "relative_path_en": "/solution/0300-0399/0370.Range%20Addition/README_EN.md", "title_cn": "\u533a\u95f4\u52a0\u6cd5", "title_en": "Range Addition", "question_title_slug": "range-addition", "content_en": "

    You are given an integer length and an array updates where updates[i] = [startIdxi, endIdxi, inci].

    \n\n

    You have an array arr of length length with all zeros, and you have some operation to apply on arr. In the ith operation, you should increment all the elements arr[startIdxi], arr[startIdxi + 1], ..., arr[endIdxi] by inci.

    \n\n

    Return arr after applying all the updates.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: length = 5, updates = [[1,3,2],[2,4,3],[0,2,-2]]\nOutput: [-2,0,3,5,3]\n
    \n\n

    Example 2:

    \n\n
    \nInput: length = 10, updates = [[2,4,6],[5,6,8],[1,9,-4]]\nOutput: [0,-4,2,2,2,4,4,-4,-4,-4]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= length <= 105
    • \n\t
    • 0 <= updates.length <= 104
    • \n\t
    • 0 <= startIdxi <= endIdxi < length
    • \n\t
    • -1000 <= inci <= 1000
    • \n
    \n", "content_cn": "

    \u5047\u8bbe\u4f60\u6709\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u6570\u7ec4\uff0c\u521d\u59cb\u60c5\u51b5\u4e0b\u6240\u6709\u7684\u6570\u5b57\u5747\u4e3a 0\uff0c\u4f60\u5c06\u4f1a\u88ab\u7ed9\u51fa k\u200b\u200b\u200b\u200b\u200b\u200b\u200b \u4e2a\u66f4\u65b0\u7684\u64cd\u4f5c\u3002

    \n\n

    \u5176\u4e2d\uff0c\u6bcf\u4e2a\u64cd\u4f5c\u4f1a\u88ab\u8868\u793a\u4e3a\u4e00\u4e2a\u4e09\u5143\u7ec4\uff1a[startIndex, endIndex, inc]\uff0c\u4f60\u9700\u8981\u5c06\u5b50\u6570\u7ec4 A[startIndex ... endIndex]\uff08\u5305\u62ec startIndex \u548c endIndex\uff09\u589e\u52a0 inc\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de k \u6b21\u64cd\u4f5c\u540e\u7684\u6570\u7ec4\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: length = 5, updates = [[1,3,2],[2,4,3],[0,2,-2]]\n\u8f93\u51fa: [-2,0,3,5,3]\n
    \n\n

    \u89e3\u91ca:

    \n\n
    \u521d\u59cb\u72b6\u6001:\n[0,0,0,0,0]\n\n\u8fdb\u884c\u4e86\u64cd\u4f5c [1,3,2] \u540e\u7684\u72b6\u6001:\n[0,2,2,2,0]\n\n\u8fdb\u884c\u4e86\u64cd\u4f5c [2,4,3] \u540e\u7684\u72b6\u6001:\n[0,2,5,5,3]\n\n\u8fdb\u884c\u4e86\u64cd\u4f5c [0,2,-2] \u540e\u7684\u72b6\u6001:\n[-2,0,3,5,3]\n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector getModifiedArray(int length, vector>& updates) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] getModifiedArray(int length, int[][] updates) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getModifiedArray(self, length, updates):\n \"\"\"\n :type length: int\n :type updates: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getModifiedArray(self, length: int, updates: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* getModifiedArray(int length, int** updates, int updatesSize, int* updatesColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] GetModifiedArray(int length, int[][] updates) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} length\n * @param {number[][]} updates\n * @return {number[]}\n */\nvar getModifiedArray = function(length, updates) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} length\n# @param {Integer[][]} updates\n# @return {Integer[]}\ndef get_modified_array(length, updates)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getModifiedArray(_ length: Int, _ updates: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getModifiedArray(length int, updates [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getModifiedArray(length: Int, updates: Array[Array[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getModifiedArray(length: Int, updates: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_modified_array(length: i32, updates: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $length\n * @param Integer[][] $updates\n * @return Integer[]\n */\n function getModifiedArray($length, $updates) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getModifiedArray(length: number, updates: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-modified-array length updates)\n (-> exact-integer? (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0370](https://leetcode-cn.com/problems/range-addition)", "[\u533a\u95f4\u52a0\u6cd5](/solution/0300-0399/0370.Range%20Addition/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0370](https://leetcode.com/problems/range-addition)", "[Range Addition](/solution/0300-0399/0370.Range%20Addition/README_EN.md)", "`Array`", "Medium", "\ud83d\udd12"]}, {"question_id": "0369", "frontend_question_id": "0369", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/plus-one-linked-list", "url_en": "https://leetcode.com/problems/plus-one-linked-list", "relative_path_cn": "/solution/0300-0399/0369.Plus%20One%20Linked%20List/README.md", "relative_path_en": "/solution/0300-0399/0369.Plus%20One%20Linked%20List/README_EN.md", "title_cn": "\u7ed9\u5355\u94fe\u8868\u52a0\u4e00", "title_en": "Plus One Linked List", "question_title_slug": "plus-one-linked-list", "content_en": "

    Given a non-negative integer represented as a linked list of digits, plus one to the integer.

    \n\n

    The digits are stored such that the most significant digit is at the head of the list.

    \n\n

     

    \n

    Example 1:

    \n
    Input: head = [1,2,3]\nOutput: [1,2,4]\n

    Example 2:

    \n
    Input: head = [0]\nOutput: [1]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the linked list is in the range [1, 100].
    • \n\t
    • 0 <= Node.val <= 9
    • \n\t
    • The number represented by the linked list does not contain leading zeros except for the zero itself. 
    • \n
    \n", "content_cn": "

    \u7528\u4e00\u4e2a \u975e\u7a7a \u5355\u94fe\u8868\u6765\u8868\u793a\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\uff0c\u7136\u540e\u5c06\u8fd9\u4e2a\u6574\u6570\u52a0\u4e00\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u5047\u8bbe\u8fd9\u4e2a\u6574\u6570\u9664\u4e86 0 \u672c\u8eab\uff0c\u6ca1\u6709\u4efb\u4f55\u524d\u5bfc\u7684 0\u3002

    \n\n

    \u8fd9\u4e2a\u6574\u6570\u7684\u5404\u4e2a\u6570\u4f4d\u6309\u7167 \u9ad8\u4f4d\u5728\u94fe\u8868\u5934\u90e8\u3001\u4f4e\u4f4d\u5728\u94fe\u8868\u5c3e\u90e8 \u7684\u987a\u5e8f\u6392\u5217\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: [1,2,3]\n\u8f93\u51fa: [1,2,4]\n
    \n", "tags_en": ["Recursion", "Linked List"], "tags_cn": ["\u9012\u5f52", "\u94fe\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n ListNode* plusOne(ListNode* head) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public ListNode plusOne(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def plusOne(self, head):\n \"\"\"\n :type head: ListNode\n :rtype: ListNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def plusOne(self, head: ListNode) -> ListNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nstruct ListNode* plusOne(struct ListNode* head){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public ListNode PlusOne(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} head\n * @return {ListNode}\n */\nvar plusOne = function(head) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode} head\n# @return {ListNode}\ndef plus_one(head)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func plusOne(_ head: ListNode?) -> ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc plusOne(head *ListNode) *ListNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def plusOne(head: ListNode): ListNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun plusOne(head: ListNode?): ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn plus_one(head: Option>) -> Option> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @return ListNode\n */\n function plusOne($head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction plusOne(head: ListNode | null): ListNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (plus-one head)\n (-> (or/c list-node? #f) (or/c list-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0369](https://leetcode-cn.com/problems/plus-one-linked-list)", "[\u7ed9\u5355\u94fe\u8868\u52a0\u4e00](/solution/0300-0399/0369.Plus%20One%20Linked%20List/README.md)", "`\u9012\u5f52`,`\u94fe\u8868`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0369](https://leetcode.com/problems/plus-one-linked-list)", "[Plus One Linked List](/solution/0300-0399/0369.Plus%20One%20Linked%20List/README_EN.md)", "`Recursion`,`Linked List`", "Medium", "\ud83d\udd12"]}, {"question_id": "0368", "frontend_question_id": "0368", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/largest-divisible-subset", "url_en": "https://leetcode.com/problems/largest-divisible-subset", "relative_path_cn": "/solution/0300-0399/0368.Largest%20Divisible%20Subset/README.md", "relative_path_en": "/solution/0300-0399/0368.Largest%20Divisible%20Subset/README_EN.md", "title_cn": "\u6700\u5927\u6574\u9664\u5b50\u96c6", "title_en": "Largest Divisible Subset", "question_title_slug": "largest-divisible-subset", "content_en": "

    Given a set of distinct positive integers nums, return the largest subset answer such that every pair (answer[i], answer[j]) of elements in this subset satisfies:

    \n\n
      \n\t
    • answer[i] % answer[j] == 0, or
    • \n\t
    • answer[j] % answer[i] == 0
    • \n
    \n\n

    If there are multiple solutions, return any of them.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,3]\nOutput: [1,2]\nExplanation: [1,3] is also accepted.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,2,4,8]\nOutput: [1,2,4,8]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 1000
    • \n\t
    • 1 <= nums[i] <= 2 * 109
    • \n\t
    • All the integers in nums are unique.
    • \n
    \n", "content_cn": "\u7ed9\u4f60\u4e00\u4e2a\u7531 \u65e0\u91cd\u590d \u6b63\u6574\u6570\u7ec4\u6210\u7684\u96c6\u5408 nums \uff0c\u8bf7\u4f60\u627e\u51fa\u5e76\u8fd4\u56de\u5176\u4e2d\u6700\u5927\u7684\u6574\u9664\u5b50\u96c6 answer \uff0c\u5b50\u96c6\u4e2d\u6bcf\u4e00\u5143\u7d20\u5bf9 (answer[i], answer[j]) \u90fd\u5e94\u5f53\u6ee1\u8db3\uff1a\n
      \n\t
    • answer[i] % answer[j] == 0 \uff0c\u6216
    • \n\t
    • answer[j] % answer[i] == 0
    • \n
    \n\n

    \u5982\u679c\u5b58\u5728\u591a\u4e2a\u6709\u6548\u89e3\u5b50\u96c6\uff0c\u8fd4\u56de\u5176\u4e2d\u4efb\u4f55\u4e00\u4e2a\u5747\u53ef\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,3]\n\u8f93\u51fa\uff1a[1,2]\n\u89e3\u91ca\uff1a[1,3] \u4e5f\u4f1a\u88ab\u89c6\u4e3a\u6b63\u786e\u7b54\u6848\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,4,8]\n\u8f93\u51fa\uff1a[1,2,4,8]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 1000
    • \n\t
    • 1 <= nums[i] <= 2 * 109
    • \n\t
    • nums \u4e2d\u7684\u6240\u6709\u6574\u6570 \u4e92\u4e0d\u76f8\u540c
    • \n
    \n", "tags_en": ["Math", "Dynamic Programming"], "tags_cn": ["\u6570\u5b66", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector largestDivisibleSubset(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List largestDivisibleSubset(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def largestDivisibleSubset(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def largestDivisibleSubset(self, nums: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* largestDivisibleSubset(int* nums, int numsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList LargestDivisibleSubset(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar largestDivisibleSubset = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer[]}\ndef largest_divisible_subset(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func largestDivisibleSubset(_ nums: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func largestDivisibleSubset(nums []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def largestDivisibleSubset(nums: Array[Int]): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun largestDivisibleSubset(nums: IntArray): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn largest_divisible_subset(nums: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer[]\n */\n function largestDivisibleSubset($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function largestDivisibleSubset(nums: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (largest-divisible-subset nums)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0368](https://leetcode-cn.com/problems/largest-divisible-subset)", "[\u6700\u5927\u6574\u9664\u5b50\u96c6](/solution/0300-0399/0368.Largest%20Divisible%20Subset/README.md)", "`\u6570\u5b66`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0368](https://leetcode.com/problems/largest-divisible-subset)", "[Largest Divisible Subset](/solution/0300-0399/0368.Largest%20Divisible%20Subset/README_EN.md)", "`Math`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0367", "frontend_question_id": "0367", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/valid-perfect-square", "url_en": "https://leetcode.com/problems/valid-perfect-square", "relative_path_cn": "/solution/0300-0399/0367.Valid%20Perfect%20Square/README.md", "relative_path_en": "/solution/0300-0399/0367.Valid%20Perfect%20Square/README_EN.md", "title_cn": "\u6709\u6548\u7684\u5b8c\u5168\u5e73\u65b9\u6570", "title_en": "Valid Perfect Square", "question_title_slug": "valid-perfect-square", "content_en": "

    Given a positive integer num, write a function which returns True if num is a perfect square else False.

    \n\n

    Follow up: Do not use any built-in library function such as sqrt.

    \n\n

     

    \n

    Example 1:

    \n
    Input: num = 16\nOutput: true\n

    Example 2:

    \n
    Input: num = 14\nOutput: false\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= num <= 2^31 - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a \u6b63\u6574\u6570 num \uff0c\u7f16\u5199\u4e00\u4e2a\u51fd\u6570\uff0c\u5982\u679c num \u662f\u4e00\u4e2a\u5b8c\u5168\u5e73\u65b9\u6570\uff0c\u5219\u8fd4\u56de true \uff0c\u5426\u5219\u8fd4\u56de false \u3002

    \n\n

    \u8fdb\u9636\uff1a\u4e0d\u8981 \u4f7f\u7528\u4efb\u4f55\u5185\u7f6e\u7684\u5e93\u51fd\u6570\uff0c\u5982\u00a0 sqrt \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anum = 16\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anum = 14\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= num <= 2^31 - 1
    • \n
    \n", "tags_en": ["Math", "Binary Search"], "tags_cn": ["\u6570\u5b66", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isPerfectSquare(int num) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isPerfectSquare(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isPerfectSquare(self, num):\n \"\"\"\n :type num: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isPerfectSquare(self, num: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isPerfectSquare(int num){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsPerfectSquare(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} num\n * @return {boolean}\n */\nvar isPerfectSquare = function(num) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} num\n# @return {Boolean}\ndef is_perfect_square(num)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isPerfectSquare(_ num: Int) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isPerfectSquare(num int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isPerfectSquare(num: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isPerfectSquare(num: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_perfect_square(num: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $num\n * @return Boolean\n */\n function isPerfectSquare($num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isPerfectSquare(num: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-perfect-square num)\n (-> exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0367](https://leetcode-cn.com/problems/valid-perfect-square)", "[\u6709\u6548\u7684\u5b8c\u5168\u5e73\u65b9\u6570](/solution/0300-0399/0367.Valid%20Perfect%20Square/README.md)", "`\u6570\u5b66`,`\u4e8c\u5206\u67e5\u627e`", "\u7b80\u5355", ""], "md_table_row_en": ["[0367](https://leetcode.com/problems/valid-perfect-square)", "[Valid Perfect Square](/solution/0300-0399/0367.Valid%20Perfect%20Square/README_EN.md)", "`Math`,`Binary Search`", "Easy", ""]}, {"question_id": "0366", "frontend_question_id": "0366", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/find-leaves-of-binary-tree", "url_en": "https://leetcode.com/problems/find-leaves-of-binary-tree", "relative_path_cn": "/solution/0300-0399/0366.Find%20Leaves%20of%20Binary%20Tree/README.md", "relative_path_en": "/solution/0300-0399/0366.Find%20Leaves%20of%20Binary%20Tree/README_EN.md", "title_cn": "\u5bfb\u627e\u4e8c\u53c9\u6811\u7684\u53f6\u5b50\u8282\u70b9", "title_en": "Find Leaves of Binary Tree", "question_title_slug": "find-leaves-of-binary-tree", "content_en": "

    Given the root of a binary tree, collect a tree's nodes as if you were doing this:

    \n\n
      \n\t
    • Collect all the leaf nodes.
    • \n\t
    • Remove all the leaf nodes.
    • \n\t
    • Repeat until the tree is empty.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,2,3,4,5]\nOutput: [[4,5,3],[2],[1]]\nExplanation:\n[[3,5,4],[2],[1]] and [[3,4,5],[2],[1]] are also considered correct answers since per each level it does not matter the order on which elements are returned.\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = [1]\nOutput: [[1]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 100].
    • \n\t
    • -100 <= Node.val <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u68f5\u4e8c\u53c9\u6811\uff0c\u8bf7\u6309\u4ee5\u4e0b\u8981\u6c42\u7684\u987a\u5e8f\u6536\u96c6\u5b83\u7684\u5168\u90e8\u8282\u70b9\uff1a

    \n\n
      \n\t
    1. \u4f9d\u6b21\u4ece\u5de6\u5230\u53f3\uff0c\u6bcf\u6b21\u6536\u96c6\u5e76\u5220\u9664\u6240\u6709\u7684\u53f6\u5b50\u8282\u70b9
    2. \n\t
    3. \u91cd\u590d\u5982\u4e0a\u8fc7\u7a0b\u76f4\u5230\u6574\u68f5\u6811\u4e3a\u7a7a
    4. \n
    \n\n

     

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: [1,2,3,4,5]\n  \n          1\n         / \\\n        2   3\n       / \\     \n      4   5    \n\n\u8f93\u51fa: [[4,5,3],[2],[1]]\n
    \n\n

     

    \n\n

    \u89e3\u91ca:

    \n\n

    1. \u5220\u9664\u53f6\u5b50\u8282\u70b9 [4,5,3] \uff0c\u5f97\u5230\u5982\u4e0b\u6811\u7ed3\u6784\uff1a

    \n\n
              1\n         / \n        2          \n
    \n\n

     

    \n\n

    2. \u73b0\u5728\u5220\u53bb\u53f6\u5b50\u8282\u70b9 [2] \uff0c\u5f97\u5230\u5982\u4e0b\u6811\u7ed3\u6784\uff1a

    \n\n
              1          \n
    \n\n

     

    \n\n

    3. \u73b0\u5728\u5220\u53bb\u53f6\u5b50\u8282\u70b9 [1] \uff0c\u5f97\u5230\u7a7a\u6811\uff1a

    \n\n
              []         \n
    \n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector> findLeaves(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public List> findLeaves(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def findLeaves(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def findLeaves(self, root: TreeNode) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** findLeaves(struct TreeNode* root, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public IList> FindLeaves(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number[][]}\n */\nvar findLeaves = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer[][]}\ndef find_leaves(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func findLeaves(_ root: TreeNode?) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc findLeaves(root *TreeNode) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def findLeaves(root: TreeNode): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun findLeaves(root: TreeNode?): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn find_leaves(root: Option>>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer[][]\n */\n function findLeaves($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction findLeaves(root: TreeNode | null): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (find-leaves root)\n (-> (or/c tree-node? #f) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0366](https://leetcode-cn.com/problems/find-leaves-of-binary-tree)", "[\u5bfb\u627e\u4e8c\u53c9\u6811\u7684\u53f6\u5b50\u8282\u70b9](/solution/0300-0399/0366.Find%20Leaves%20of%20Binary%20Tree/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0366](https://leetcode.com/problems/find-leaves-of-binary-tree)", "[Find Leaves of Binary Tree](/solution/0300-0399/0366.Find%20Leaves%20of%20Binary%20Tree/README_EN.md)", "`Tree`,`Depth-first Search`", "Medium", "\ud83d\udd12"]}, {"question_id": "0365", "frontend_question_id": "0365", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/water-and-jug-problem", "url_en": "https://leetcode.com/problems/water-and-jug-problem", "relative_path_cn": "/solution/0300-0399/0365.Water%20and%20Jug%20Problem/README.md", "relative_path_en": "/solution/0300-0399/0365.Water%20and%20Jug%20Problem/README_EN.md", "title_cn": "\u6c34\u58f6\u95ee\u9898", "title_en": "Water and Jug Problem", "question_title_slug": "water-and-jug-problem", "content_en": "

    You are given two jugs with capacities jug1Capacity and jug2Capacity liters. There is an infinite amount of water supply available. Determine whether it is possible to measure exactly targetCapacity liters using these two jugs.

    \n\n

    If targetCapacity liters of water are measurable, you must have targetCapacity liters of water contained within one or both buckets by the end.

    \n\n

    Operations allowed:

    \n\n
      \n\t
    • Fill any of the jugs with water.
    • \n\t
    • Empty any of the jugs.
    • \n\t
    • Pour water from one jug into another till the other jug is completely full, or the first jug itself is empty.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: jug1Capacity = 3, jug2Capacity = 5, targetCapacity = 4\nOutput: true\nExplanation: The famous Die Hard example \n
    \n\n

    Example 2:

    \n\n
    \nInput: jug1Capacity = 2, jug2Capacity = 6, targetCapacity = 5\nOutput: false\n
    \n\n

    Example 3:

    \n\n
    \nInput: jug1Capacity = 1, jug2Capacity = 2, targetCapacity = 3\nOutput: true\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= jug1Capacity, jug2Capacity, targetCapacity <= 106
    • \n
    \n", "content_cn": "

    \u6709\u4e24\u4e2a\u5bb9\u91cf\u5206\u522b\u4e3a x\u5347 \u548c y\u5347 \u7684\u6c34\u58f6\u4ee5\u53ca\u65e0\u9650\u591a\u7684\u6c34\u3002\u8bf7\u5224\u65ad\u80fd\u5426\u901a\u8fc7\u4f7f\u7528\u8fd9\u4e24\u4e2a\u6c34\u58f6\uff0c\u4ece\u800c\u53ef\u4ee5\u5f97\u5230\u6070\u597d z\u5347 \u7684\u6c34\uff1f

    \n\n

    \u5982\u679c\u53ef\u4ee5\uff0c\u6700\u540e\u8bf7\u7528\u4ee5\u4e0a\u6c34\u58f6\u4e2d\u7684\u4e00\u6216\u4e24\u4e2a\u6765\u76db\u653e\u53d6\u5f97\u7684 z\u5347 \u6c34\u3002

    \n\n

    \u4f60\u5141\u8bb8\uff1a

    \n\n
      \n\t
    • \u88c5\u6ee1\u4efb\u610f\u4e00\u4e2a\u6c34\u58f6
    • \n\t
    • \u6e05\u7a7a\u4efb\u610f\u4e00\u4e2a\u6c34\u58f6
    • \n\t
    • \u4ece\u4e00\u4e2a\u6c34\u58f6\u5411\u53e6\u5916\u4e00\u4e2a\u6c34\u58f6\u5012\u6c34\uff0c\u76f4\u5230\u88c5\u6ee1\u6216\u8005\u5012\u7a7a
    • \n
    \n\n

    \u793a\u4f8b 1: (From the famous "Die Hard" example)

    \n\n
    \u8f93\u5165: x = 3, y = 5, z = 4\n\u8f93\u51fa: True\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: x = 2, y = 6, z = 5\n\u8f93\u51fa: False\n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canMeasureWater(int jug1Capacity, int jug2Capacity, int targetCapacity) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canMeasureWater(int jug1Capacity, int jug2Capacity, int targetCapacity) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canMeasureWater(self, jug1Capacity, jug2Capacity, targetCapacity):\n \"\"\"\n :type jug1Capacity: int\n :type jug2Capacity: int\n :type targetCapacity: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canMeasureWater(self, jug1Capacity: int, jug2Capacity: int, targetCapacity: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canMeasureWater(int jug1Capacity, int jug2Capacity, int targetCapacity){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanMeasureWater(int jug1Capacity, int jug2Capacity, int targetCapacity) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} jug1Capacity\n * @param {number} jug2Capacity\n * @param {number} targetCapacity\n * @return {boolean}\n */\nvar canMeasureWater = function(jug1Capacity, jug2Capacity, targetCapacity) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} jug1_capacity\n# @param {Integer} jug2_capacity\n# @param {Integer} target_capacity\n# @return {Boolean}\ndef can_measure_water(jug1_capacity, jug2_capacity, target_capacity)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canMeasureWater(_ jug1Capacity: Int, _ jug2Capacity: Int, _ targetCapacity: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canMeasureWater(jug1Capacity int, jug2Capacity int, targetCapacity int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canMeasureWater(jug1Capacity: Int, jug2Capacity: Int, targetCapacity: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canMeasureWater(jug1Capacity: Int, jug2Capacity: Int, targetCapacity: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_measure_water(jug1_capacity: i32, jug2_capacity: i32, target_capacity: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $jug1Capacity\n * @param Integer $jug2Capacity\n * @param Integer $targetCapacity\n * @return Boolean\n */\n function canMeasureWater($jug1Capacity, $jug2Capacity, $targetCapacity) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canMeasureWater(jug1Capacity: number, jug2Capacity: number, targetCapacity: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-measure-water jug1Capacity jug2Capacity targetCapacity)\n (-> exact-integer? exact-integer? exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0365](https://leetcode-cn.com/problems/water-and-jug-problem)", "[\u6c34\u58f6\u95ee\u9898](/solution/0300-0399/0365.Water%20and%20Jug%20Problem/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0365](https://leetcode.com/problems/water-and-jug-problem)", "[Water and Jug Problem](/solution/0300-0399/0365.Water%20and%20Jug%20Problem/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "0364", "frontend_question_id": "0364", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/nested-list-weight-sum-ii", "url_en": "https://leetcode.com/problems/nested-list-weight-sum-ii", "relative_path_cn": "/solution/0300-0399/0364.Nested%20List%20Weight%20Sum%20II/README.md", "relative_path_en": "/solution/0300-0399/0364.Nested%20List%20Weight%20Sum%20II/README_EN.md", "title_cn": "\u52a0\u6743\u5d4c\u5957\u5e8f\u5217\u548c II", "title_en": "Nested List Weight Sum II", "question_title_slug": "nested-list-weight-sum-ii", "content_en": "

    You are given a nested list of integers nestedList. Each element is either an integer or a list whose elements may also be integers or other lists.

    \n\n

    The depth of an integer is the number of lists that it is inside of. For example, the nested list [1,[2,2],[[3],2],1] has each integer's value set to its depth. Let maxDepth be the maximum depth of any integer.

    \n\n

    The weight of an integer is maxDepth - (the depth of the integer) + 1.

    \n\n

    Return the sum of each integer in nestedList multiplied by its weight.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: nestedList = [[1,1],2,[1,1]]\nOutput: 8\nExplanation: Four 1's with a weight of 1, one 2 with a weight of 2.\n1*1 + 1*1 + 2*2 + 1*1 + 1*1 = 8\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: nestedList = [1,[4,[6]]]\nOutput: 17\nExplanation: One 1 at depth 3, one 4 at depth 2, and one 6 at depth 1.\n1*3 + 4*2 + 6*1 = 17\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nestedList.length <= 50
    • \n\t
    • The values of the integers in the nested list is in the range [-100, 100].
    • \n\t
    • The maximum depth of any integer is less than or equal to 50.
    • \n
    \n", "content_cn": "

    \u7ed9\u4e00\u4e2a\u5d4c\u5957\u6574\u6570\u5e8f\u5217\uff0c\u8bf7\u4f60\u8fd4\u56de\u6bcf\u4e2a\u6570\u5b57\u5728\u5e8f\u5217\u4e2d\u7684\u52a0\u6743\u548c\uff0c\u5b83\u4eec\u7684\u6743\u91cd\u7531\u5b83\u4eec\u7684\u6df1\u5ea6\u51b3\u5b9a\u3002

    \n\n

    \u5e8f\u5217\u4e2d\u7684\u6bcf\u4e00\u4e2a\u5143\u7d20\u8981\u4e48\u662f\u4e00\u4e2a\u6574\u6570\uff0c\u8981\u4e48\u662f\u4e00\u4e2a\u5e8f\u5217\uff08\u8fd9\u4e2a\u5e8f\u5217\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u4e5f\u540c\u6837\u662f\u6574\u6570\u6216\u5e8f\u5217\uff09\u3002

    \n\n

    \u4e0e \u524d\u4e00\u4e2a\u95ee\u9898 \u4e0d\u540c\u7684\u662f\uff0c\u524d\u4e00\u9898\u7684\u6743\u91cd\u6309\u7167\u4ece\u6839\u5230\u53f6\u9010\u4e00\u589e\u52a0\uff0c\u800c\u672c\u9898\u7684\u6743\u91cd\u4ece\u53f6\u5230\u6839\u9010\u4e00\u589e\u52a0\u3002

    \n\n

    \u4e5f\u5c31\u662f\u8bf4\uff0c\u5728\u672c\u9898\u4e2d\uff0c\u53f6\u5b50\u7684\u6743\u91cd\u4e3a1\uff0c\u800c\u6839\u62e5\u6709\u6700\u5927\u7684\u6743\u91cd\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: [[1,1],2,[1,1]]\n\u8f93\u51fa: 8 \n\u89e3\u91ca: \u56db\u4e2a 1 \u5728\u6df1\u5ea6\u4e3a 1 \u7684\u4f4d\u7f6e\uff0c \u4e00\u4e2a 2 \u5728\u6df1\u5ea6\u4e3a 2 \u7684\u4f4d\u7f6e\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: [1,[4,[6]]]\n\u8f93\u51fa: 17 \n\u89e3\u91ca: \u4e00\u4e2a 1 \u5728\u6df1\u5ea6\u4e3a 3 \u7684\u4f4d\u7f6e\uff0c \u4e00\u4e2a 4 \u5728\u6df1\u5ea6\u4e3a 2 \u7684\u4f4d\u7f6e\uff0c\u4e00\u4e2a 6 \u5728\u6df1\u5ea6\u4e3a 1 \u7684\u4f4d\u7f6e\u3002 1*3 + 4*2 + 6*1 = 17\u3002\n
    \n", "tags_en": ["Depth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * class NestedInteger {\n * public:\n * // Constructor initializes an empty nested list.\n * NestedInteger();\n *\n * // Constructor initializes a single integer.\n * NestedInteger(int value);\n *\n * // Return true if this NestedInteger holds a single integer, rather than a nested list.\n * bool isInteger() const;\n *\n * // Return the single integer that this NestedInteger holds, if it holds a single integer\n * // The result is undefined if this NestedInteger holds a nested list\n * int getInteger() const;\n *\n * // Set this NestedInteger to hold a single integer.\n * void setInteger(int value);\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * void add(const NestedInteger &ni);\n *\n * // Return the nested list that this NestedInteger holds, if it holds a nested list\n * // The result is undefined if this NestedInteger holds a single integer\n * const vector &getList() const;\n * };\n */\nclass Solution {\npublic:\n int depthSumInverse(vector& nestedList) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * public interface NestedInteger {\n * // Constructor initializes an empty nested list.\n * public NestedInteger();\n *\n * // Constructor initializes a single integer.\n * public NestedInteger(int value);\n *\n * // @return true if this NestedInteger holds a single integer, rather than a nested list.\n * public boolean isInteger();\n *\n * // @return the single integer that this NestedInteger holds, if it holds a single integer\n * // Return null if this NestedInteger holds a nested list\n * public Integer getInteger();\n *\n * // Set this NestedInteger to hold a single integer.\n * public void setInteger(int value);\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * public void add(NestedInteger ni);\n *\n * // @return the nested list that this NestedInteger holds, if it holds a nested list\n * // Return empty list if this NestedInteger holds a single integer\n * public List getList();\n * }\n */\nclass Solution {\n public int depthSumInverse(List nestedList) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# \"\"\"\n# This is the interface that allows for creating nested lists.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class NestedInteger(object):\n# def __init__(self, value=None):\n# \"\"\"\n# If value is not specified, initializes an empty list.\n# Otherwise initializes a single integer equal to value.\n# \"\"\"\n#\n# def isInteger(self):\n# \"\"\"\n# @return True if this NestedInteger holds a single integer, rather than a nested list.\n# :rtype bool\n# \"\"\"\n#\n# def add(self, elem):\n# \"\"\"\n# Set this NestedInteger to hold a nested list and adds a nested integer elem to it.\n# :rtype void\n# \"\"\"\n#\n# def setInteger(self, value):\n# \"\"\"\n# Set this NestedInteger to hold a single integer equal to value.\n# :rtype void\n# \"\"\"\n#\n# def getInteger(self):\n# \"\"\"\n# @return the single integer that this NestedInteger holds, if it holds a single integer\n# Return None if this NestedInteger holds a nested list\n# :rtype int\n# \"\"\"\n#\n# def getList(self):\n# \"\"\"\n# @return the nested list that this NestedInteger holds, if it holds a nested list\n# Return None if this NestedInteger holds a single integer\n# :rtype List[NestedInteger]\n# \"\"\"\nclass Solution(object):\n def depthSumInverse(self, nestedList):\n \"\"\"\n :type nestedList: List[NestedInteger]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# \"\"\"\n# This is the interface that allows for creating nested lists.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class NestedInteger:\n# def __init__(self, value=None):\n# \"\"\"\n# If value is not specified, initializes an empty list.\n# Otherwise initializes a single integer equal to value.\n# \"\"\"\n#\n# def isInteger(self):\n# \"\"\"\n# @return True if this NestedInteger holds a single integer, rather than a nested list.\n# :rtype bool\n# \"\"\"\n#\n# def add(self, elem):\n# \"\"\"\n# Set this NestedInteger to hold a nested list and adds a nested integer elem to it.\n# :rtype void\n# \"\"\"\n#\n# def setInteger(self, value):\n# \"\"\"\n# Set this NestedInteger to hold a single integer equal to value.\n# :rtype void\n# \"\"\"\n#\n# def getInteger(self):\n# \"\"\"\n# @return the single integer that this NestedInteger holds, if it holds a single integer\n# Return None if this NestedInteger holds a nested list\n# :rtype int\n# \"\"\"\n#\n# def getList(self):\n# \"\"\"\n# @return the nested list that this NestedInteger holds, if it holds a nested list\n# Return None if this NestedInteger holds a single integer\n# :rtype List[NestedInteger]\n# \"\"\"\nclass Solution:\n def depthSumInverse(self, nestedList: List[NestedInteger]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * *********************************************************************\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * *********************************************************************\n *\n * // Initializes an empty nested list and return a reference to the nested integer.\n * struct NestedInteger *NestedIntegerInit();\n *\n * // Return true if this NestedInteger holds a single integer, rather than a nested list.\n * bool NestedIntegerIsInteger(struct NestedInteger *);\n *\n * // Return the single integer that this NestedInteger holds, if it holds a single integer\n * // The result is undefined if this NestedInteger holds a nested list\n * int NestedIntegerGetInteger(struct NestedInteger *);\n *\n * // Set this NestedInteger to hold a single integer.\n * void NestedIntegerSetInteger(struct NestedInteger *ni, int value);\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer elem to it.\n * void NestedIntegerAdd(struct NestedInteger *ni, struct NestedInteger *elem);\n *\n * // Return the nested list that this NestedInteger holds, if it holds a nested list\n * // The result is undefined if this NestedInteger holds a single integer\n * struct NestedInteger **NestedIntegerGetList(struct NestedInteger *);\n *\n * // Return the nested list's size that this NestedInteger holds, if it holds a nested list\n * // The result is undefined if this NestedInteger holds a single integer\n * int NestedIntegerGetListSize(struct NestedInteger *);\n * };\n */\n\n\nint depthSumInverse(struct NestedInteger** nestedList, int nestedListSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * interface NestedInteger {\n *\n * // Constructor initializes an empty nested list.\n * public NestedInteger();\n *\n * // Constructor initializes a single integer.\n * public NestedInteger(int value);\n *\n * // @return true if this NestedInteger holds a single integer, rather than a nested list.\n * bool IsInteger();\n *\n * // @return the single integer that this NestedInteger holds, if it holds a single integer\n * // Return null if this NestedInteger holds a nested list\n * int GetInteger();\n *\n * // Set this NestedInteger to hold a single integer.\n * public void SetInteger(int value);\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * public void Add(NestedInteger ni);\n *\n * // @return the nested list that this NestedInteger holds, if it holds a nested list\n * // Return null if this NestedInteger holds a single integer\n * IList GetList();\n * }\n */\npublic class Solution {\n public int DepthSumInverse(IList nestedList) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * function NestedInteger() {\n *\n * Return true if this NestedInteger holds a single integer, rather than a nested list.\n * @return {boolean}\n * this.isInteger = function() {\n * ...\n * };\n *\n * Return the single integer that this NestedInteger holds, if it holds a single integer\n * Return null if this NestedInteger holds a nested list\n * @return {integer}\n * this.getInteger = function() {\n * ...\n * };\n *\n * Set this NestedInteger to hold a single integer equal to value.\n * @return {void}\n * this.setInteger = function(value) {\n * ...\n * };\n *\n * Set this NestedInteger to hold a nested list and adds a nested integer elem to it.\n * @return {void}\n * this.add = function(elem) {\n * ...\n * };\n *\n * Return the nested list that this NestedInteger holds, if it holds a nested list\n * Return null if this NestedInteger holds a single integer\n * @return {NestedInteger[]}\n * this.getList = function() {\n * ...\n * };\n * };\n */\n/**\n * @param {NestedInteger[]} nestedList\n * @return {number}\n */\nvar depthSumInverse = function(nestedList) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# This is the interface that allows for creating nested lists.\n# You should not implement it, or speculate about its implementation\n#\n#class NestedInteger\n# def is_integer()\n# \"\"\"\n# Return true if this NestedInteger holds a single integer, rather than a nested list.\n# @return {Boolean}\n# \"\"\"\n#\n# def get_integer()\n# \"\"\"\n# Return the single integer that this NestedInteger holds, if it holds a single integer\n# Return nil if this NestedInteger holds a nested list\n# @return {Integer}\n# \"\"\"\n#\n# def set_integer(value)\n# \"\"\"\n# Set this NestedInteger to hold a single integer equal to value.\n# @return {Void}\n# \"\"\"\n#\n# def add(elem)\n# \"\"\"\n# Set this NestedInteger to hold a nested list and adds a nested integer elem to it.\n# @return {Void}\n# \"\"\"\n#\n# def get_list()\n# \"\"\"\n# Return the nested list that this NestedInteger holds, if it holds a nested list\n# Return nil if this NestedInteger holds a single integer\n# @return {NestedInteger[]}\n# \"\"\"\n# @param {NestedInteger[]} nested_list\n# @return {Integer}\ndef depth_sum_inverse(nested_list)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * class NestedInteger {\n * // Return true if this NestedInteger holds a single integer, rather than a nested list.\n * public func isInteger() -> Bool\n *\n * // Return the single integer that this NestedInteger holds, if it holds a single integer\n * // The result is undefined if this NestedInteger holds a nested list\n * public func getInteger() -> Int\n *\n * // Set this NestedInteger to hold a single integer.\n * public func setInteger(value: Int)\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * public func add(elem: NestedInteger)\n *\n * // Return the nested list that this NestedInteger holds, if it holds a nested list\n * // The result is undefined if this NestedInteger holds a single integer\n * public func getList() -> [NestedInteger]\n * }\n */\nclass Solution {\n func depthSumInverse(_ nestedList: [NestedInteger]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * type NestedInteger struct {\n * }\n *\n * // Return true if this NestedInteger holds a single integer, rather than a nested list.\n * func (n NestedInteger) IsInteger() bool {}\n *\n * // Return the single integer that this NestedInteger holds, if it holds a single integer\n * // The result is undefined if this NestedInteger holds a nested list\n * // So before calling this method, you should have a check\n * func (n NestedInteger) GetInteger() int {}\n *\n * // Set this NestedInteger to hold a single integer.\n * func (n *NestedInteger) SetInteger(value int) {}\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * func (n *NestedInteger) Add(elem NestedInteger) {}\n *\n * // Return the nested list that this NestedInteger holds, if it holds a nested list\n * // The list length is zero if this NestedInteger holds a single integer\n * // You can access NestedInteger's List element directly if you want to modify it\n * func (n NestedInteger) GetList() []*NestedInteger {}\n */\nfunc depthSumInverse(nestedList []*NestedInteger) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * trait NestedInteger {\n *\n * // Return true if this NestedInteger holds a single integer, rather than a nested list.\n * def isInteger: Boolean\n *\n * // Return the single integer that this NestedInteger holds, if it holds a single integer.\n * def getInteger: Int\n *\n * // Set this NestedInteger to hold a single integer.\n * def setInteger(i: Int): Unit\n *\n * // Return the nested list that this NestedInteger holds, if it holds a nested list.\n * def getList: Array[NestedInteger]\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * def add(ni: NestedInteger): Unit\n * }\n */\nobject Solution {\n def depthSumInverse(nestedList: List[NestedInteger]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * class NestedInteger {\n * // Constructor initializes an empty nested list.\n * constructor()\n *\n * // Constructor initializes a single integer.\n * constructor(value: Int)\n *\n * // @return true if this NestedInteger holds a single integer, rather than a nested list.\n * fun isInteger(): Boolean\n *\n * // @return the single integer that this NestedInteger holds, if it holds a single integer\n * // Return null if this NestedInteger holds a nested list\n * fun getInteger(): Int?\n *\n * // Set this NestedInteger to hold a single integer.\n * fun setInteger(value: Int): Unit\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * fun add(ni: NestedInteger): Unit\n *\n * // @return the nested list that this NestedInteger holds, if it holds a nested list\n * // Return null if this NestedInteger holds a single integer\n * fun getList(): List?\n * }\n */\nclass Solution {\n fun depthSumInverse(nestedList: List): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// #[derive(Debug, PartialEq, Eq)]\n// pub enum NestedInteger {\n// Int(i32),\n// List(Vec)\n// }\nimpl Solution {\n pub fn depth_sum_inverse(nested_list: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * class NestedInteger {\n\n * // if value is not specified, initializes an empty list.\n * // Otherwise initializes a single integer equal to value.\n * function __construct($value = null)\n\n * // Return true if this NestedInteger holds a single integer, rather than a nested list.\n * function isInteger() : bool\n *\n * // Return the single integer that this NestedInteger holds, if it holds a single integer\n * // The result is undefined if this NestedInteger holds a nested list\n * function getInteger()\n *\n * // Set this NestedInteger to hold a single integer.\n * function setInteger($i) : void\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * function add($ni) : void\n *\n * // Return the nested list that this NestedInteger holds, if it holds a nested list\n * // The result is undefined if this NestedInteger holds a single integer\n * function getList() : array\n * }\n */\nclass Solution {\n\n /**\n * @param NestedInteger[] $nestedList\n * @return Integer\n */\n function depthSumInverse($nestedList) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * class NestedInteger {\n * If value is provided, then it holds a single integer\n * Otherwise it holds an empty nested list\n * constructor(value?: number) {\n * ...\n * };\n *\n * Return true if this NestedInteger holds a single integer, rather than a nested list.\n * isInteger(): boolean {\n * ...\n * };\n *\n * Return the single integer that this NestedInteger holds, if it holds a single integer\n * Return null if this NestedInteger holds a nested list\n * getInteger(): number | null {\n * ...\n * };\n *\n * Set this NestedInteger to hold a single integer equal to value.\n * setInteger(value: number) {\n * ...\n * };\n *\n * Set this NestedInteger to hold a nested list and adds a nested integer elem to it.\n * add(elem: NestedInteger) {\n * ...\n * };\n *\n * Return the nested list that this NestedInteger holds,\n * or an empty list if this NestedInteger holds a single integer\n * getList(): NestedInteger[] {\n * ...\n * };\n * };\n */\n\nfunction depthSumInverse(nestedList: NestedInteger[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": ";; This is the interface that allows for creating nested lists.\n;; You should not implement it, or speculate about its implementation\n\n#|\n\n(define nested-integer%\n (class object%\n ...\n\n ; Return true if this nested-integer% holds a single integer, rather than a nested list.\n ; -> boolean?\n (define/public (is-integer)\n ...)\n\n ; Return the single integer that this nested-integer% holds, if it holds a single integer,\n ; or #f if this nested-integer% holds a nested list.\n ; -> integer?\n (define/public (get-integer)\n ...)\n\n ; Set this nested-integer% to hold a single integer equal to value.\n ; -> integer? void?\n (define/public (set-integer i)\n ...)\n\n ; Set this nested-integer% to hold a nested list and adds a nested integer elem to it.\n ; -> (is-a?/c nested-integer%) void?\n (define/public (add ni)\n ...)\n\n ; Return the nested list that this nested-integer% holds,\n ; or an empty list if this nested-integer% holds a single integer.\n ; -> gvector?\n (define/public (get-list)\n ...)))\n\n|#\n\n(define/contract (depth-sum-inverse nestedList)\n (-> (listof (is-a?/c nested-integer%)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0364](https://leetcode-cn.com/problems/nested-list-weight-sum-ii)", "[\u52a0\u6743\u5d4c\u5957\u5e8f\u5217\u548c II](/solution/0300-0399/0364.Nested%20List%20Weight%20Sum%20II/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0364](https://leetcode.com/problems/nested-list-weight-sum-ii)", "[Nested List Weight Sum II](/solution/0300-0399/0364.Nested%20List%20Weight%20Sum%20II/README_EN.md)", "`Depth-first Search`", "Medium", "\ud83d\udd12"]}, {"question_id": "0363", "frontend_question_id": "0363", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/max-sum-of-rectangle-no-larger-than-k", "url_en": "https://leetcode.com/problems/max-sum-of-rectangle-no-larger-than-k", "relative_path_cn": "/solution/0300-0399/0363.Max%20Sum%20of%20Rectangle%20No%20Larger%20Than%20K/README.md", "relative_path_en": "/solution/0300-0399/0363.Max%20Sum%20of%20Rectangle%20No%20Larger%20Than%20K/README_EN.md", "title_cn": "\u77e9\u5f62\u533a\u57df\u4e0d\u8d85\u8fc7 K \u7684\u6700\u5927\u6570\u503c\u548c", "title_en": "Max Sum of Rectangle No Larger Than K", "question_title_slug": "max-sum-of-rectangle-no-larger-than-k", "content_en": "

    Given an m x n matrix matrix and an integer k, return the max sum of a rectangle in the matrix such that its sum is no larger than k.

    \n\n

    It is guaranteed that there will be a rectangle with a sum no larger than k.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: matrix = [[1,0,1],[0,-2,3]], k = 2\nOutput: 2\nExplanation: Because the sum of the blue rectangle [[0, 1], [-2, 3]] is 2, and 2 is the max number no larger than k (k = 2).\n
    \n\n

    Example 2:

    \n\n
    \nInput: matrix = [[2,2,-1]], k = 3\nOutput: 3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == matrix.length
    • \n\t
    • n == matrix[i].length
    • \n\t
    • 1 <= m, n <= 100
    • \n\t
    • -100 <= matrix[i][j] <= 100
    • \n\t
    • -105 <= k <= 105
    • \n
    \n\n

     

    \n

    Follow up: What if the number of rows is much larger than the number of columns?

    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a m x n \u7684\u77e9\u9635 matrix \u548c\u4e00\u4e2a\u6574\u6570 k \uff0c\u627e\u51fa\u5e76\u8fd4\u56de\u77e9\u9635\u5185\u90e8\u77e9\u5f62\u533a\u57df\u7684\u4e0d\u8d85\u8fc7 k \u7684\u6700\u5927\u6570\u503c\u548c\u3002

    \n\n

    \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u603b\u4f1a\u5b58\u5728\u4e00\u4e2a\u6570\u503c\u548c\u4e0d\u8d85\u8fc7 k \u7684\u77e9\u5f62\u533a\u57df\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1amatrix = [[1,0,1],[0,-2,3]], k = 2\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u84dd\u8272\u8fb9\u6846\u5708\u51fa\u6765\u7684\u77e9\u5f62\u533a\u57df\u00a0[[0, 1], [-2, 3]]\u00a0\u7684\u6570\u503c\u548c\u662f 2\uff0c\u4e14 2 \u662f\u4e0d\u8d85\u8fc7 k \u7684\u6700\u5927\u6570\u5b57\uff08k = 2\uff09\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1amatrix = [[2,2,-1]], k = 3\n\u8f93\u51fa\uff1a3\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == matrix.length
    • \n\t
    • n == matrix[i].length
    • \n\t
    • 1 <= m, n <= 100
    • \n\t
    • -100 <= matrix[i][j] <= 100
    • \n\t
    • -105 <= k <= 105
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u5982\u679c\u884c\u6570\u8fdc\u5927\u4e8e\u5217\u6570\uff0c\u8be5\u5982\u4f55\u8bbe\u8ba1\u89e3\u51b3\u65b9\u6848\uff1f

    \n", "tags_en": ["Queue", "Binary Search", "Dynamic Programming"], "tags_cn": ["\u961f\u5217", "\u4e8c\u5206\u67e5\u627e", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxSumSubmatrix(vector>& matrix, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxSumSubmatrix(int[][] matrix, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxSumSubmatrix(self, matrix, k):\n \"\"\"\n :type matrix: List[List[int]]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxSumSubmatrix(self, matrix: List[List[int]], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxSumSubmatrix(int** matrix, int matrixSize, int* matrixColSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxSumSubmatrix(int[][] matrix, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} matrix\n * @param {number} k\n * @return {number}\n */\nvar maxSumSubmatrix = function(matrix, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} matrix\n# @param {Integer} k\n# @return {Integer}\ndef max_sum_submatrix(matrix, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxSumSubmatrix(_ matrix: [[Int]], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxSumSubmatrix(matrix [][]int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxSumSubmatrix(matrix: Array[Array[Int]], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxSumSubmatrix(matrix: Array, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_sum_submatrix(matrix: Vec>, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $matrix\n * @param Integer $k\n * @return Integer\n */\n function maxSumSubmatrix($matrix, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxSumSubmatrix(matrix: number[][], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-sum-submatrix matrix k)\n (-> (listof (listof exact-integer?)) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0363](https://leetcode-cn.com/problems/max-sum-of-rectangle-no-larger-than-k)", "[\u77e9\u5f62\u533a\u57df\u4e0d\u8d85\u8fc7 K \u7684\u6700\u5927\u6570\u503c\u548c](/solution/0300-0399/0363.Max%20Sum%20of%20Rectangle%20No%20Larger%20Than%20K/README.md)", "`\u961f\u5217`,`\u4e8c\u5206\u67e5\u627e`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0363](https://leetcode.com/problems/max-sum-of-rectangle-no-larger-than-k)", "[Max Sum of Rectangle No Larger Than K](/solution/0300-0399/0363.Max%20Sum%20of%20Rectangle%20No%20Larger%20Than%20K/README_EN.md)", "`Queue`,`Binary Search`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0362", "frontend_question_id": "0362", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/design-hit-counter", "url_en": "https://leetcode.com/problems/design-hit-counter", "relative_path_cn": "/solution/0300-0399/0362.Design%20Hit%20Counter/README.md", "relative_path_en": "/solution/0300-0399/0362.Design%20Hit%20Counter/README_EN.md", "title_cn": "\u6572\u51fb\u8ba1\u6570\u5668", "title_en": "Design Hit Counter", "question_title_slug": "design-hit-counter", "content_en": "

    Design a hit counter which counts the number of hits received in the past 5 minutes (i.e., the past 300 seconds).

    \n\n

    Your system should accept a timestamp parameter (in seconds granularity), and you may assume that calls are being made to the system in chronological order (i.e., timestamp is monotonically increasing). Several hits may arrive roughly at the same time.

    \n\n

    Implement the HitCounter class:

    \n\n
      \n\t
    • HitCounter() Initializes the object of the hit counter system.
    • \n\t
    • void hit(int timestamp) Records a hit that happened at timestamp (in seconds). Several hits may happen at the same timestamp.
    • \n\t
    • int getHits(int timestamp) Returns the number of hits in the past 5 minutes from timestamp (i.e., the past 300 seconds).
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["HitCounter", "hit", "hit", "hit", "getHits", "hit", "getHits", "getHits"]\n[[], [1], [2], [3], [4], [300], [300], [301]]\nOutput\n[null, null, null, null, 3, null, 4, 3]\n\nExplanation\nHitCounter hitCounter = new HitCounter();\nhitCounter.hit(1);       // hit at timestamp 1.\nhitCounter.hit(2);       // hit at timestamp 2.\nhitCounter.hit(3);       // hit at timestamp 3.\nhitCounter.getHits(4);   // get hits at timestamp 4, return 3.\nhitCounter.hit(300);     // hit at timestamp 300.\nhitCounter.getHits(300); // get hits at timestamp 300, return 4.\nhitCounter.getHits(301); // get hits at timestamp 301, return 3.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= timestamp <= 2 * 109
    • \n\t
    • All the calls are being made to the system in chronological order (i.e., timestamp is monotonically increasing).
    • \n\t
    • At most 300 calls will be made to hit and getHits.
    • \n
    \n\n

     

    \n

    Follow up: What if the number of hits per second could be huge? Does your design scale?

    \n", "content_cn": "

    \u8bbe\u8ba1\u4e00\u4e2a\u6572\u51fb\u8ba1\u6570\u5668\uff0c\u4f7f\u5b83\u53ef\u4ee5\u7edf\u8ba1\u5728\u8fc7\u53bb5\u5206\u949f\u5185\u88ab\u6572\u51fb\u6b21\u6570\u3002

    \n\n

    \u6bcf\u4e2a\u51fd\u6570\u4f1a\u63a5\u6536\u4e00\u4e2a\u65f6\u95f4\u6233\u53c2\u6570\uff08\u4ee5\u79d2\u4e3a\u5355\u4f4d\uff09\uff0c\u4f60\u53ef\u4ee5\u5047\u8bbe\u6700\u65e9\u7684\u65f6\u95f4\u6233\u4ece1\u5f00\u59cb\uff0c\u4e14\u90fd\u662f\u6309\u7167\u65f6\u95f4\u987a\u5e8f\u5bf9\u7cfb\u7edf\u8fdb\u884c\u8c03\u7528\uff08\u5373\u65f6\u95f4\u6233\u662f\u5355\u8c03\u9012\u589e\uff09\u3002

    \n\n

    \u5728\u540c\u4e00\u65f6\u523b\u6709\u53ef\u80fd\u4f1a\u6709\u591a\u6b21\u6572\u51fb\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    HitCounter counter = new HitCounter();\n\n// \u5728\u65f6\u523b 1 \u6572\u51fb\u4e00\u6b21\u3002\ncounter.hit(1);\n\n// \u5728\u65f6\u523b 2 \u6572\u51fb\u4e00\u6b21\u3002\ncounter.hit(2);\n\n// \u5728\u65f6\u523b 3 \u6572\u51fb\u4e00\u6b21\u3002\ncounter.hit(3);\n\n// \u5728\u65f6\u523b 4 \u7edf\u8ba1\u8fc7\u53bb 5 \u5206\u949f\u5185\u7684\u6572\u51fb\u6b21\u6570, \u51fd\u6570\u8fd4\u56de 3 \u3002\ncounter.getHits(4);\n\n// \u5728\u65f6\u523b 300 \u6572\u51fb\u4e00\u6b21\u3002\ncounter.hit(300);\n\n// \u5728\u65f6\u523b 300 \u7edf\u8ba1\u8fc7\u53bb 5 \u5206\u949f\u5185\u7684\u6572\u51fb\u6b21\u6570\uff0c\u51fd\u6570\u8fd4\u56de 4 \u3002\ncounter.getHits(300);\n\n// \u5728\u65f6\u523b 301 \u7edf\u8ba1\u8fc7\u53bb 5 \u5206\u949f\u5185\u7684\u6572\u51fb\u6b21\u6570\uff0c\u51fd\u6570\u8fd4\u56de 3 \u3002\ncounter.getHits(301); \n
    \n\n

    \u8fdb\u9636:

    \n\n

    \u5982\u679c\u6bcf\u79d2\u7684\u6572\u51fb\u6b21\u6570\u662f\u4e00\u4e2a\u5f88\u5927\u7684\u6570\u5b57\uff0c\u4f60\u7684\u8ba1\u6570\u5668\u53ef\u4ee5\u5e94\u5bf9\u5417\uff1f

    \n", "tags_en": ["Design"], "tags_cn": ["\u8bbe\u8ba1"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class HitCounter {\npublic:\n /** Initialize your data structure here. */\n HitCounter() {\n\n }\n \n /** Record a hit.\n @param timestamp - The current timestamp (in seconds granularity). */\n void hit(int timestamp) {\n\n }\n \n /** Return the number of hits in the past 5 minutes.\n @param timestamp - The current timestamp (in seconds granularity). */\n int getHits(int timestamp) {\n\n }\n};\n\n/**\n * Your HitCounter object will be instantiated and called as such:\n * HitCounter* obj = new HitCounter();\n * obj->hit(timestamp);\n * int param_2 = obj->getHits(timestamp);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class HitCounter {\n\n /** Initialize your data structure here. */\n public HitCounter() {\n\n }\n \n /** Record a hit.\n @param timestamp - The current timestamp (in seconds granularity). */\n public void hit(int timestamp) {\n\n }\n \n /** Return the number of hits in the past 5 minutes.\n @param timestamp - The current timestamp (in seconds granularity). */\n public int getHits(int timestamp) {\n\n }\n}\n\n/**\n * Your HitCounter object will be instantiated and called as such:\n * HitCounter obj = new HitCounter();\n * obj.hit(timestamp);\n * int param_2 = obj.getHits(timestamp);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class HitCounter(object):\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def hit(self, timestamp):\n \"\"\"\n Record a hit.\n @param timestamp - The current timestamp (in seconds granularity).\n :type timestamp: int\n :rtype: None\n \"\"\"\n\n\n def getHits(self, timestamp):\n \"\"\"\n Return the number of hits in the past 5 minutes.\n @param timestamp - The current timestamp (in seconds granularity).\n :type timestamp: int\n :rtype: int\n \"\"\"\n\n\n\n# Your HitCounter object will be instantiated and called as such:\n# obj = HitCounter()\n# obj.hit(timestamp)\n# param_2 = obj.getHits(timestamp)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class HitCounter:\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def hit(self, timestamp: int) -> None:\n \"\"\"\n Record a hit.\n @param timestamp - The current timestamp (in seconds granularity).\n \"\"\"\n\n\n def getHits(self, timestamp: int) -> int:\n \"\"\"\n Return the number of hits in the past 5 minutes.\n @param timestamp - The current timestamp (in seconds granularity).\n \"\"\"\n\n\n\n# Your HitCounter object will be instantiated and called as such:\n# obj = HitCounter()\n# obj.hit(timestamp)\n# param_2 = obj.getHits(timestamp)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} HitCounter;\n\n/** Initialize your data structure here. */\n\nHitCounter* hitCounterCreate() {\n\n}\n\n/** Record a hit.\n @param timestamp - The current timestamp (in seconds granularity). */\nvoid hitCounterHit(HitCounter* obj, int timestamp) {\n\n}\n\n/** Return the number of hits in the past 5 minutes.\n @param timestamp - The current timestamp (in seconds granularity). */\nint hitCounterGetHits(HitCounter* obj, int timestamp) {\n\n}\n\nvoid hitCounterFree(HitCounter* obj) {\n\n}\n\n/**\n * Your HitCounter struct will be instantiated and called as such:\n * HitCounter* obj = hitCounterCreate();\n * hitCounterHit(obj, timestamp);\n \n * int param_2 = hitCounterGetHits(obj, timestamp);\n \n * hitCounterFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class HitCounter {\n\n /** Initialize your data structure here. */\n public HitCounter() {\n\n }\n \n /** Record a hit.\n @param timestamp - The current timestamp (in seconds granularity). */\n public void Hit(int timestamp) {\n\n }\n \n /** Return the number of hits in the past 5 minutes.\n @param timestamp - The current timestamp (in seconds granularity). */\n public int GetHits(int timestamp) {\n\n }\n}\n\n/**\n * Your HitCounter object will be instantiated and called as such:\n * HitCounter obj = new HitCounter();\n * obj.Hit(timestamp);\n * int param_2 = obj.GetHits(timestamp);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Initialize your data structure here.\n */\nvar HitCounter = function() {\n\n};\n\n/**\n * Record a hit.\n @param timestamp - The current timestamp (in seconds granularity). \n * @param {number} timestamp\n * @return {void}\n */\nHitCounter.prototype.hit = function(timestamp) {\n\n};\n\n/**\n * Return the number of hits in the past 5 minutes.\n @param timestamp - The current timestamp (in seconds granularity). \n * @param {number} timestamp\n * @return {number}\n */\nHitCounter.prototype.getHits = function(timestamp) {\n\n};\n\n/**\n * Your HitCounter object will be instantiated and called as such:\n * var obj = new HitCounter()\n * obj.hit(timestamp)\n * var param_2 = obj.getHits(timestamp)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class HitCounter\n\n=begin\n Initialize your data structure here.\n=end\n def initialize()\n\n end\n\n\n=begin\n Record a hit.\n @param timestamp - The current timestamp (in seconds granularity).\n :type timestamp: Integer\n :rtype: Void\n=end\n def hit(timestamp)\n\n end\n\n\n=begin\n Return the number of hits in the past 5 minutes.\n @param timestamp - The current timestamp (in seconds granularity).\n :type timestamp: Integer\n :rtype: Integer\n=end\n def get_hits(timestamp)\n\n end\n\n\nend\n\n# Your HitCounter object will be instantiated and called as such:\n# obj = HitCounter.new()\n# obj.hit(timestamp)\n# param_2 = obj.get_hits(timestamp)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass HitCounter {\n\n /** Initialize your data structure here. */\n init() {\n\n }\n \n /** Record a hit.\n @param timestamp - The current timestamp (in seconds granularity). */\n func hit(_ timestamp: Int) {\n\n }\n \n /** Return the number of hits in the past 5 minutes.\n @param timestamp - The current timestamp (in seconds granularity). */\n func getHits(_ timestamp: Int) -> Int {\n\n }\n}\n\n/**\n * Your HitCounter object will be instantiated and called as such:\n * let obj = HitCounter()\n * obj.hit(timestamp)\n * let ret_2: Int = obj.getHits(timestamp)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type HitCounter struct {\n\n}\n\n\n/** Initialize your data structure here. */\nfunc Constructor() HitCounter {\n\n}\n\n\n/** Record a hit.\n @param timestamp - The current timestamp (in seconds granularity). */\nfunc (this *HitCounter) Hit(timestamp int) {\n\n}\n\n\n/** Return the number of hits in the past 5 minutes.\n @param timestamp - The current timestamp (in seconds granularity). */\nfunc (this *HitCounter) GetHits(timestamp int) int {\n\n}\n\n\n/**\n * Your HitCounter object will be instantiated and called as such:\n * obj := Constructor();\n * obj.Hit(timestamp);\n * param_2 := obj.GetHits(timestamp);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class HitCounter() {\n\n /** Initialize your data structure here. */\n\n\n /** Record a hit.\n @param timestamp - The current timestamp (in seconds granularity). */\n def hit(timestamp: Int) {\n\n }\n\n /** Return the number of hits in the past 5 minutes.\n @param timestamp - The current timestamp (in seconds granularity). */\n def getHits(timestamp: Int): Int = {\n\n }\n\n}\n\n/**\n * Your HitCounter object will be instantiated and called as such:\n * var obj = new HitCounter()\n * obj.hit(timestamp)\n * var param_2 = obj.getHits(timestamp)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class HitCounter() {\n\n /** Initialize your data structure here. */\n\n\n /** Record a hit.\n @param timestamp - The current timestamp (in seconds granularity). */\n fun hit(timestamp: Int) {\n\n }\n\n /** Return the number of hits in the past 5 minutes.\n @param timestamp - The current timestamp (in seconds granularity). */\n fun getHits(timestamp: Int): Int {\n\n }\n\n}\n\n/**\n * Your HitCounter object will be instantiated and called as such:\n * var obj = HitCounter()\n * obj.hit(timestamp)\n * var param_2 = obj.getHits(timestamp)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct HitCounter {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl HitCounter {\n\n /** Initialize your data structure here. */\n fn new() -> Self {\n\n }\n \n /** Record a hit.\n @param timestamp - The current timestamp (in seconds granularity). */\n fn hit(&self, timestamp: i32) {\n\n }\n \n /** Return the number of hits in the past 5 minutes.\n @param timestamp - The current timestamp (in seconds granularity). */\n fn get_hits(&self, timestamp: i32) -> i32 {\n\n }\n}\n\n/**\n * Your HitCounter object will be instantiated and called as such:\n * let obj = HitCounter::new();\n * obj.hit(timestamp);\n * let ret_2: i32 = obj.get_hits(timestamp);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class HitCounter {\n /**\n * Initialize your data structure here.\n */\n function __construct() {\n\n }\n\n /**\n * Record a hit.\n @param timestamp - The current timestamp (in seconds granularity).\n * @param Integer $timestamp\n * @return NULL\n */\n function hit($timestamp) {\n\n }\n\n /**\n * Return the number of hits in the past 5 minutes.\n @param timestamp - The current timestamp (in seconds granularity).\n * @param Integer $timestamp\n * @return Integer\n */\n function getHits($timestamp) {\n\n }\n}\n\n/**\n * Your HitCounter object will be instantiated and called as such:\n * $obj = HitCounter();\n * $obj->hit($timestamp);\n * $ret_2 = $obj->getHits($timestamp);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class HitCounter {\n constructor() {\n\n }\n\n hit(timestamp: number): void {\n\n }\n\n getHits(timestamp: number): number {\n\n }\n}\n\n/**\n * Your HitCounter object will be instantiated and called as such:\n * var obj = new HitCounter()\n * obj.hit(timestamp)\n * var param_2 = obj.getHits(timestamp)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define hit-counter%\n (class object%\n (super-new)\n (init-field)\n \n ; hit : exact-integer? -> void?\n (define/public (hit timestamp)\n\n )\n ; get-hits : exact-integer? -> exact-integer?\n (define/public (get-hits timestamp)\n\n )))\n\n;; Your hit-counter% object will be instantiated and called as such:\n;; (define obj (new hit-counter%))\n;; (send obj hit timestamp)\n;; (define param_2 (send obj get-hits timestamp))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0362](https://leetcode-cn.com/problems/design-hit-counter)", "[\u6572\u51fb\u8ba1\u6570\u5668](/solution/0300-0399/0362.Design%20Hit%20Counter/README.md)", "`\u8bbe\u8ba1`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0362](https://leetcode.com/problems/design-hit-counter)", "[Design Hit Counter](/solution/0300-0399/0362.Design%20Hit%20Counter/README_EN.md)", "`Design`", "Medium", "\ud83d\udd12"]}, {"question_id": "0361", "frontend_question_id": "0361", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/bomb-enemy", "url_en": "https://leetcode.com/problems/bomb-enemy", "relative_path_cn": "/solution/0300-0399/0361.Bomb%20Enemy/README.md", "relative_path_en": "/solution/0300-0399/0361.Bomb%20Enemy/README_EN.md", "title_cn": "\u8f70\u70b8\u654c\u4eba", "title_en": "Bomb Enemy", "question_title_slug": "bomb-enemy", "content_en": "

    Given an m x n matrix grid where each cell is either a wall 'W', an enemy 'E' or empty '0', return the maximum enemies you can kill using one bomb. You can only place the bomb in an empty cell.

    \n\n

    The bomb kills all the enemies in the same row and column from the planted point until it hits the wall since it is too strong to be destroyed.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: grid = [["0","E","0","0"],["E","0","W","E"],["0","E","0","0"]]\nOutput: 3\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: grid = [["W","W","W"],["0","0","0"],["E","E","E"]]\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= m, n <= 500
    • \n\t
    • grid[i][j] is either 'W', 'E', or '0'.
    • \n
    \n", "content_cn": "

    \u60f3\u8c61\u4e00\u4e0b\u70b8\u5f39\u4eba\u6e38\u620f\uff0c\u5728\u4f60\u9762\u524d\u6709\u4e00\u4e2a\u4e8c\u7ef4\u7684\u7f51\u683c\u6765\u8868\u793a\u5730\u56fe\uff0c\u7f51\u683c\u4e2d\u7684\u683c\u5b50\u5206\u522b\u88ab\u4ee5\u4e0b\u4e09\u79cd\u7b26\u53f7\u5360\u636e\uff1a

    \n\n
      \n\t
    • 'W' \u8868\u793a\u4e00\u5835\u5899
    • \n\t
    • 'E' \u8868\u793a\u4e00\u4e2a\u654c\u4eba
    • \n\t
    • '0'\uff08\u6570\u5b57 0\uff09\u8868\u793a\u4e00\u4e2a\u7a7a\u4f4d
    • \n
    \n\n

    \n\n

    \u8bf7\u4f60\u8ba1\u7b97\u4e00\u4e2a\u70b8\u5f39\u6700\u591a\u80fd\u70b8\u591a\u5c11\u654c\u4eba\u3002

    \n\n

    \u7531\u4e8e\u70b8\u5f39\u7684\u5a01\u529b\u4e0d\u8db3\u4ee5\u7a7f\u900f\u5899\u4f53\uff0c\u70b8\u5f39\u53ea\u80fd\u70b8\u5230\u540c\u4e00\u884c\u548c\u540c\u4e00\u5217\u6ca1\u88ab\u5899\u4f53\u6321\u4f4f\u7684\u654c\u4eba\u3002

    \n\n

    \u6ce8\u610f\uff1a\u4f60\u53ea\u80fd\u628a\u70b8\u5f39\u653e\u5728\u4e00\u4e2a\u7a7a\u7684\u683c\u5b50\u91cc

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: [["0","E","0","0"],["E","0","W","E"],["0","E","0","0"]]\n\u8f93\u51fa: 3 \n\u89e3\u91ca: \u5bf9\u4e8e\u5982\u4e0b\u7f51\u683c\n\n0 E 0 0 \nE 0 W E \n0 E 0 0\n\n\u5047\u5982\u5728\u4f4d\u7f6e (1,1) \u653e\u7f6e\u70b8\u5f39\u7684\u8bdd\uff0c\u53ef\u4ee5\u70b8\u5230 3 \u4e2a\u654c\u4eba\n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxKilledEnemies(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxKilledEnemies(char[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxKilledEnemies(self, grid):\n \"\"\"\n :type grid: List[List[str]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxKilledEnemies(self, grid: List[List[str]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxKilledEnemies(char** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxKilledEnemies(char[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {character[][]} grid\n * @return {number}\n */\nvar maxKilledEnemies = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Character[][]} grid\n# @return {Integer}\ndef max_killed_enemies(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxKilledEnemies(_ grid: [[Character]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxKilledEnemies(grid [][]byte) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxKilledEnemies(grid: Array[Array[Char]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxKilledEnemies(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_killed_enemies(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $grid\n * @return Integer\n */\n function maxKilledEnemies($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxKilledEnemies(grid: string[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-killed-enemies grid)\n (-> (listof (listof char?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0361](https://leetcode-cn.com/problems/bomb-enemy)", "[\u8f70\u70b8\u654c\u4eba](/solution/0300-0399/0361.Bomb%20Enemy/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0361](https://leetcode.com/problems/bomb-enemy)", "[Bomb Enemy](/solution/0300-0399/0361.Bomb%20Enemy/README_EN.md)", "`Dynamic Programming`", "Medium", "\ud83d\udd12"]}, {"question_id": "0360", "frontend_question_id": "0360", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/sort-transformed-array", "url_en": "https://leetcode.com/problems/sort-transformed-array", "relative_path_cn": "/solution/0300-0399/0360.Sort%20Transformed%20Array/README.md", "relative_path_en": "/solution/0300-0399/0360.Sort%20Transformed%20Array/README_EN.md", "title_cn": "\u6709\u5e8f\u8f6c\u5316\u6570\u7ec4", "title_en": "Sort Transformed Array", "question_title_slug": "sort-transformed-array", "content_en": "

    Given a sorted integer array nums and three integers a, b and c, apply a quadratic function of the form f(x) = ax2 + bx + c to each element nums[i] in the array, and return the array in a sorted order.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [-4,-2,2,4], a = 1, b = 3, c = 5\nOutput: [3,9,15,33]\n

    Example 2:

    \n
    Input: nums = [-4,-2,2,4], a = -1, b = 3, c = 5\nOutput: [-23,-5,1,7]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 200
    • \n\t
    • -100 <= nums[i], a, b, c <= 100
    • \n\t
    • nums is sorted in ascending order.
    • \n
    \n\n

     

    \n

    Follow up: Could you solve it in O(n) time?

    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5df2\u7ecf \u6392\u597d\u5e8f \u7684\u6574\u6570\u6570\u7ec4 nums \u548c\u6574\u6570 a\u3001b\u3001c\u3002\u5bf9\u4e8e\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e00\u4e2a\u6570 x\uff0c\u8ba1\u7b97\u51fd\u6570\u503c f(x) = ax2 + bx + c\uff0c\u8bf7\u5c06\u51fd\u6570\u503c\u4ea7\u751f\u7684\u6570\u7ec4\u8fd4\u56de\u3002

    \n\n

    \u8981\u6ce8\u610f\uff0c\u8fd4\u56de\u7684\u8fd9\u4e2a\u6570\u7ec4\u5fc5\u987b\u6309\u7167 \u5347\u5e8f\u6392\u5217\uff0c\u5e76\u4e14\u6211\u4eec\u6240\u671f\u671b\u7684\u89e3\u6cd5\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\u3002

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165: nums = [-4,-2,2,4], a = 1, b = 3, c = 5\n\u8f93\u51fa: [3,9,15,33]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165: nums = [-4,-2,2,4], a = -1, b = 3, c = 5\n\u8f93\u51fa: [-23,-5,1,7]\n
    \n", "tags_en": ["Sort", "Math", "Two Pointers"], "tags_cn": ["\u6392\u5e8f", "\u6570\u5b66", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector sortTransformedArray(vector& nums, int a, int b, int c) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] sortTransformedArray(int[] nums, int a, int b, int c) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def sortTransformedArray(self, nums, a, b, c):\n \"\"\"\n :type nums: List[int]\n :type a: int\n :type b: int\n :type c: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def sortTransformedArray(self, nums: List[int], a: int, b: int, c: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* sortTransformedArray(int* nums, int numsSize, int a, int b, int c, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] SortTransformedArray(int[] nums, int a, int b, int c) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} a\n * @param {number} b\n * @param {number} c\n * @return {number[]}\n */\nvar sortTransformedArray = function(nums, a, b, c) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} a\n# @param {Integer} b\n# @param {Integer} c\n# @return {Integer[]}\ndef sort_transformed_array(nums, a, b, c)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func sortTransformedArray(_ nums: [Int], _ a: Int, _ b: Int, _ c: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func sortTransformedArray(nums []int, a int, b int, c int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def sortTransformedArray(nums: Array[Int], a: Int, b: Int, c: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun sortTransformedArray(nums: IntArray, a: Int, b: Int, c: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sort_transformed_array(nums: Vec, a: i32, b: i32, c: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $a\n * @param Integer $b\n * @param Integer $c\n * @return Integer[]\n */\n function sortTransformedArray($nums, $a, $b, $c) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function sortTransformedArray(nums: number[], a: number, b: number, c: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (sort-transformed-array nums a b c)\n (-> (listof exact-integer?) exact-integer? exact-integer? exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0360](https://leetcode-cn.com/problems/sort-transformed-array)", "[\u6709\u5e8f\u8f6c\u5316\u6570\u7ec4](/solution/0300-0399/0360.Sort%20Transformed%20Array/README.md)", "`\u6392\u5e8f`,`\u6570\u5b66`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0360](https://leetcode.com/problems/sort-transformed-array)", "[Sort Transformed Array](/solution/0300-0399/0360.Sort%20Transformed%20Array/README_EN.md)", "`Sort`,`Math`,`Two Pointers`", "Medium", "\ud83d\udd12"]}, {"question_id": "0359", "frontend_question_id": "0359", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/logger-rate-limiter", "url_en": "https://leetcode.com/problems/logger-rate-limiter", "relative_path_cn": "/solution/0300-0399/0359.Logger%20Rate%20Limiter/README.md", "relative_path_en": "/solution/0300-0399/0359.Logger%20Rate%20Limiter/README_EN.md", "title_cn": "\u65e5\u5fd7\u901f\u7387\u9650\u5236\u5668", "title_en": "Logger Rate Limiter", "question_title_slug": "logger-rate-limiter", "content_en": "

    Design a logger system that receives a stream of messages along with their timestamps. Each unique message should only be printed at most every 10 seconds (i.e. a message printed at timestamp t will prevent other identical messages from being printed until timestamp t + 10).

    \n\n

    All messages will come in chronological order. Several messages may arrive at the same timestamp.

    \n\n

    Implement the Logger class:

    \n\n
      \n\t
    • Logger() Initializes the logger object.
    • \n\t
    • bool shouldPrintMessage(int timestamp, string message) Returns true if the message should be printed in the given timestamp, otherwise returns false.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["Logger", "shouldPrintMessage", "shouldPrintMessage", "shouldPrintMessage", "shouldPrintMessage", "shouldPrintMessage", "shouldPrintMessage"]\n[[], [1, "foo"], [2, "bar"], [3, "foo"], [8, "bar"], [10, "foo"], [11, "foo"]]\nOutput\n[null, true, true, false, false, false, true]\n\nExplanation\nLogger logger = new Logger();\nlogger.shouldPrintMessage(1, "foo");  // return true, next allowed timestamp for "foo" is 1 + 10 = 11\nlogger.shouldPrintMessage(2, "bar");  // return true, next allowed timestamp for "bar" is 2 + 10 = 12\nlogger.shouldPrintMessage(3, "foo");  // 3 < 11, return false\nlogger.shouldPrintMessage(8, "bar");  // 8 < 12, return false\nlogger.shouldPrintMessage(10, "foo"); // 10 < 11, return false\nlogger.shouldPrintMessage(11, "foo"); // 11 >= 11, return true, next allowed timestamp for "foo" is\n                                      // 11 + 10 = 21\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= timestamp <= 109
    • \n\t
    • Every timestamp will be passed in non-decreasing order (chronological order).
    • \n\t
    • 1 <= message.length <= 30
    • \n\t
    • At most 104 calls will be made to shouldPrintMessage.
    • \n
    \n", "content_cn": "

    \u8bf7\u4f60\u8bbe\u8ba1\u4e00\u4e2a\u65e5\u5fd7\u7cfb\u7edf\uff0c\u53ef\u4ee5\u6d41\u5f0f\u63a5\u6536\u6d88\u606f\u4ee5\u53ca\u5b83\u7684\u65f6\u95f4\u6233\u3002\u6bcf\u6761 \u4e0d\u91cd\u590d \u7684\u6d88\u606f\u6700\u591a\u53ea\u80fd\u6bcf 10 \u79d2\u6253\u5370\u4e00\u6b21\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u5982\u679c\u5728\u65f6\u95f4\u6233 t \u6253\u5370\u67d0\u6761\u6d88\u606f\uff0c\u90a3\u4e48\u76f8\u540c\u5185\u5bb9\u7684\u6d88\u606f\u76f4\u5230\u65f6\u95f4\u6233\u53d8\u4e3a t + 10 \u4e4b\u524d\u90fd\u4e0d\u4f1a\u88ab\u6253\u5370\u3002

    \n\n

    \u6240\u6709\u6d88\u606f\u90fd\u6309\u65f6\u95f4\u987a\u5e8f\u53d1\u9001\u3002\u591a\u6761\u6d88\u606f\u53ef\u80fd\u5230\u8fbe\u540c\u4e00\u65f6\u95f4\u6233\u3002

    \n\n

    \u5b9e\u73b0 Logger \u7c7b\uff1a

    \n\n
      \n\t
    • Logger() \u521d\u59cb\u5316 logger \u5bf9\u8c61
    • \n\t
    • bool shouldPrintMessage(int timestamp, string message) \u5982\u679c\u8fd9\u6761\u6d88\u606f message \u5728\u7ed9\u5b9a\u7684\u65f6\u95f4\u6233 timestamp \u5e94\u8be5\u88ab\u6253\u5370\u51fa\u6765\uff0c\u5219\u8fd4\u56de\u00a0true \uff0c\u5426\u5219\u8bf7\u8fd4\u56de\u00a0false \u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\n[\"Logger\", \"shouldPrintMessage\", \"shouldPrintMessage\", \"shouldPrintMessage\", \"shouldPrintMessage\", \"shouldPrintMessage\", \"shouldPrintMessage\"]\n[[], [1, \"foo\"], [2, \"bar\"], [3, \"foo\"], [8, \"bar\"], [10, \"foo\"], [11, \"foo\"]]\n\u8f93\u51fa\uff1a\n[null, true, true, false, false, false, true]\n\n\u89e3\u91ca\uff1a\nLogger logger = new Logger();\nlogger.shouldPrintMessage(1, \"foo\");  // \u8fd4\u56de true \uff0c\u4e0b\u4e00\u6b21 \"foo\" \u53ef\u4ee5\u6253\u5370\u7684\u65f6\u95f4\u6233\u662f 1 + 10 = 11\nlogger.shouldPrintMessage(2, \"bar\");  // \u8fd4\u56de true \uff0c\u4e0b\u4e00\u6b21 \"bar\" \u53ef\u4ee5\u6253\u5370\u7684\u65f6\u95f4\u6233\u662f 2 + 10 = 12\nlogger.shouldPrintMessage(3, \"foo\");  // 3 < 11 \uff0c\u8fd4\u56de false\nlogger.shouldPrintMessage(8, \"bar\");  // 8 < 12 \uff0c\u8fd4\u56de false\nlogger.shouldPrintMessage(10, \"foo\"); // 10 < 11 \uff0c\u8fd4\u56de false\nlogger.shouldPrintMessage(11, \"foo\"); // 11 >= 11 \uff0c\u8fd4\u56de true \uff0c\u4e0b\u4e00\u6b21 \"foo\" \u53ef\u4ee5\u6253\u5370\u7684\u65f6\u95f4\u6233\u662f 11 + 10 = 21\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= timestamp <= 109
    • \n\t
    • \u6bcf\u4e2a timestamp \u90fd\u5c06\u6309\u975e\u9012\u51cf\u987a\u5e8f\uff08\u65f6\u95f4\u987a\u5e8f\uff09\u4f20\u9012
    • \n\t
    • 1 <= message.length <= 30
    • \n\t
    • \u6700\u591a\u8c03\u7528 104 \u6b21 shouldPrintMessage \u65b9\u6cd5
    • \n
    \n", "tags_en": ["Design", "Hash Table"], "tags_cn": ["\u8bbe\u8ba1", "\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Logger {\npublic:\n /** Initialize your data structure here. */\n Logger() {\n\n }\n \n /** Returns true if the message should be printed in the given timestamp, otherwise returns false.\n If this method returns false, the message will not be printed.\n The timestamp is in seconds granularity. */\n bool shouldPrintMessage(int timestamp, string message) {\n\n }\n};\n\n/**\n * Your Logger object will be instantiated and called as such:\n * Logger* obj = new Logger();\n * bool param_1 = obj->shouldPrintMessage(timestamp,message);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Logger {\n\n /** Initialize your data structure here. */\n public Logger() {\n\n }\n \n /** Returns true if the message should be printed in the given timestamp, otherwise returns false.\n If this method returns false, the message will not be printed.\n The timestamp is in seconds granularity. */\n public boolean shouldPrintMessage(int timestamp, String message) {\n\n }\n}\n\n/**\n * Your Logger object will be instantiated and called as such:\n * Logger obj = new Logger();\n * boolean param_1 = obj.shouldPrintMessage(timestamp,message);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Logger(object):\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def shouldPrintMessage(self, timestamp, message):\n \"\"\"\n Returns true if the message should be printed in the given timestamp, otherwise returns false.\n If this method returns false, the message will not be printed.\n The timestamp is in seconds granularity.\n :type timestamp: int\n :type message: str\n :rtype: bool\n \"\"\"\n\n\n\n# Your Logger object will be instantiated and called as such:\n# obj = Logger()\n# param_1 = obj.shouldPrintMessage(timestamp,message)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Logger:\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def shouldPrintMessage(self, timestamp: int, message: str) -> bool:\n \"\"\"\n Returns true if the message should be printed in the given timestamp, otherwise returns false.\n If this method returns false, the message will not be printed.\n The timestamp is in seconds granularity.\n \"\"\"\n\n\n\n# Your Logger object will be instantiated and called as such:\n# obj = Logger()\n# param_1 = obj.shouldPrintMessage(timestamp,message)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} Logger;\n\n/** Initialize your data structure here. */\n\nLogger* loggerCreate() {\n \n}\n\n/** Returns true if the message should be printed in the given timestamp, otherwise returns false.\n If this method returns false, the message will not be printed.\n The timestamp is in seconds granularity. */\nbool loggerShouldPrintMessage(Logger* obj, int timestamp, char * message) {\n \n}\n\nvoid loggerFree(Logger* obj) {\n \n}\n\n/**\n * Your Logger struct will be instantiated and called as such:\n * Logger* obj = loggerCreate();\n * bool param_1 = loggerShouldPrintMessage(obj, timestamp, message);\n \n * loggerFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Logger {\n\n /** Initialize your data structure here. */\n public Logger() {\n\n }\n \n /** Returns true if the message should be printed in the given timestamp, otherwise returns false.\n If this method returns false, the message will not be printed.\n The timestamp is in seconds granularity. */\n public bool ShouldPrintMessage(int timestamp, string message) {\n\n }\n}\n\n/**\n * Your Logger object will be instantiated and called as such:\n * Logger obj = new Logger();\n * bool param_1 = obj.ShouldPrintMessage(timestamp,message);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Initialize your data structure here.\n */\nvar Logger = function() {\n\n};\n\n/**\n * Returns true if the message should be printed in the given timestamp, otherwise returns false.\n If this method returns false, the message will not be printed.\n The timestamp is in seconds granularity. \n * @param {number} timestamp \n * @param {string} message\n * @return {boolean}\n */\nLogger.prototype.shouldPrintMessage = function(timestamp, message) {\n\n};\n\n/**\n * Your Logger object will be instantiated and called as such:\n * var obj = new Logger()\n * var param_1 = obj.shouldPrintMessage(timestamp,message)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class Logger\n\n=begin\n Initialize your data structure here.\n=end\n def initialize()\n\n end\n\n\n=begin\n Returns true if the message should be printed in the given timestamp, otherwise returns false.\n If this method returns false, the message will not be printed.\n The timestamp is in seconds granularity.\n :type timestamp: Integer\n :type message: String\n :rtype: Boolean\n=end\n def should_print_message(timestamp, message)\n\n end\n\n\nend\n\n# Your Logger object will be instantiated and called as such:\n# obj = Logger.new()\n# param_1 = obj.should_print_message(timestamp, message)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass Logger {\n\n /** Initialize your data structure here. */\n init() {\n\n }\n \n /** Returns true if the message should be printed in the given timestamp, otherwise returns false.\n If this method returns false, the message will not be printed.\n The timestamp is in seconds granularity. */\n func shouldPrintMessage(_ timestamp: Int, _ message: String) -> Bool {\n\n }\n}\n\n/**\n * Your Logger object will be instantiated and called as such:\n * let obj = Logger()\n * let ret_1: Bool = obj.shouldPrintMessage(timestamp, message)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type Logger struct {\n\n}\n\n\n/** Initialize your data structure here. */\nfunc Constructor() Logger {\n\n}\n\n\n/** Returns true if the message should be printed in the given timestamp, otherwise returns false.\n If this method returns false, the message will not be printed.\n The timestamp is in seconds granularity. */\nfunc (this *Logger) ShouldPrintMessage(timestamp int, message string) bool {\n\n}\n\n\n/**\n * Your Logger object will be instantiated and called as such:\n * obj := Constructor();\n * param_1 := obj.ShouldPrintMessage(timestamp,message);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class Logger() {\n\n /** Initialize your data structure here. */\n\n\n /** Returns true if the message should be printed in the given timestamp, otherwise returns false.\n If this method returns false, the message will not be printed.\n The timestamp is in seconds granularity. */\n def shouldPrintMessage(timestamp: Int, message: String): Boolean = {\n\n }\n\n}\n\n/**\n * Your Logger object will be instantiated and called as such:\n * var obj = new Logger()\n * var param_1 = obj.shouldPrintMessage(timestamp,message)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Logger() {\n\n /** Initialize your data structure here. */\n\n\n /** Returns true if the message should be printed in the given timestamp, otherwise returns false.\n If this method returns false, the message will not be printed.\n The timestamp is in seconds granularity. */\n fun shouldPrintMessage(timestamp: Int, message: String): Boolean {\n\n }\n\n}\n\n/**\n * Your Logger object will be instantiated and called as such:\n * var obj = Logger()\n * var param_1 = obj.shouldPrintMessage(timestamp,message)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct Logger {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl Logger {\n\n /** Initialize your data structure here. */\n fn new() -> Self {\n\n }\n \n /** Returns true if the message should be printed in the given timestamp, otherwise returns false.\n If this method returns false, the message will not be printed.\n The timestamp is in seconds granularity. */\n fn should_print_message(&self, timestamp: i32, message: String) -> bool {\n\n }\n}\n\n/**\n * Your Logger object will be instantiated and called as such:\n * let obj = Logger::new();\n * let ret_1: bool = obj.should_print_message(timestamp, message);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Logger {\n /**\n * Initialize your data structure here.\n */\n function __construct() {\n\n }\n\n /**\n * Returns true if the message should be printed in the given timestamp, otherwise returns false.\n If this method returns false, the message will not be printed.\n The timestamp is in seconds granularity.\n * @param Integer $timestamp\n * @param String $message\n * @return Boolean\n */\n function shouldPrintMessage($timestamp, $message) {\n\n }\n}\n\n/**\n * Your Logger object will be instantiated and called as such:\n * $obj = Logger();\n * $ret_1 = $obj->shouldPrintMessage($timestamp, $message);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class Logger {\n constructor() {\n\n }\n\n shouldPrintMessage(timestamp: number, message: string): boolean {\n\n }\n}\n\n/**\n * Your Logger object will be instantiated and called as such:\n * var obj = new Logger()\n * var param_1 = obj.shouldPrintMessage(timestamp,message)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define logger%\n (class object%\n (super-new)\n (init-field)\n \n ; should-print-message : exact-integer? string? -> boolean?\n (define/public (should-print-message timestamp message)\n\n )))\n\n;; Your logger% object will be instantiated and called as such:\n;; (define obj (new logger%))\n;; (define param_1 (send obj should-print-message timestamp message))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0359](https://leetcode-cn.com/problems/logger-rate-limiter)", "[\u65e5\u5fd7\u901f\u7387\u9650\u5236\u5668](/solution/0300-0399/0359.Logger%20Rate%20Limiter/README.md)", "`\u8bbe\u8ba1`,`\u54c8\u5e0c\u8868`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0359](https://leetcode.com/problems/logger-rate-limiter)", "[Logger Rate Limiter](/solution/0300-0399/0359.Logger%20Rate%20Limiter/README_EN.md)", "`Design`,`Hash Table`", "Easy", "\ud83d\udd12"]}, {"question_id": "0358", "frontend_question_id": "0358", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/rearrange-string-k-distance-apart", "url_en": "https://leetcode.com/problems/rearrange-string-k-distance-apart", "relative_path_cn": "/solution/0300-0399/0358.Rearrange%20String%20k%20Distance%20Apart/README.md", "relative_path_en": "/solution/0300-0399/0358.Rearrange%20String%20k%20Distance%20Apart/README_EN.md", "title_cn": "K \u8ddd\u79bb\u95f4\u9694\u91cd\u6392\u5b57\u7b26\u4e32", "title_en": "Rearrange String k Distance Apart", "question_title_slug": "rearrange-string-k-distance-apart", "content_en": "

    Given a string s and an integer k, rearrange s such that the same characters are at least distance k from each other. If it is not possible to rearrange the string, return an empty string "".

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "aabbcc", k = 3\nOutput: "abcabc"\nExplanation: The same letters are at least a distance of 3 from each other.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "aaabc", k = 3\nOutput: ""\nExplanation: It is not possible to rearrange the string.\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "aaadbbcc", k = 2\nOutput: "abacabcd"\nExplanation: The same letters are at least a distance of 2 from each other.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 3 * 105
    • \n\t
    • s consists of only lowercase English letters.
    • \n\t
    • 0 <= k <= s.length
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u975e\u7a7a\u7684\u5b57\u7b26\u4e32 s \u548c\u4e00\u4e2a\u6574\u6570 k\uff0c\u4f60\u8981\u5c06\u8fd9\u4e2a\u5b57\u7b26\u4e32\u4e2d\u7684\u5b57\u6bcd\u8fdb\u884c\u91cd\u65b0\u6392\u5217\uff0c\u4f7f\u5f97\u91cd\u6392\u540e\u7684\u5b57\u7b26\u4e32\u4e2d\u76f8\u540c\u5b57\u6bcd\u7684\u4f4d\u7f6e\u95f4\u9694\u8ddd\u79bb\u81f3\u5c11\u4e3a k\u3002

    \n\n

    \u6240\u6709\u8f93\u5165\u7684\u5b57\u7b26\u4e32\u90fd\u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210\uff0c\u5982\u679c\u627e\u4e0d\u5230\u8ddd\u79bb\u81f3\u5c11\u4e3a k \u7684\u91cd\u6392\u7ed3\u679c\uff0c\u8bf7\u8fd4\u56de\u4e00\u4e2a\u7a7a\u5b57\u7b26\u4e32 ""\u3002

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165: s = "aabbcc", k = 3\n\u8f93\u51fa: "abcabc" \n\u89e3\u91ca: \u76f8\u540c\u7684\u5b57\u6bcd\u5728\u65b0\u7684\u5b57\u7b26\u4e32\u4e2d\u95f4\u9694\u81f3\u5c11 3 \u4e2a\u5355\u4f4d\u8ddd\u79bb\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: s = "aaabc", k = 3\n\u8f93\u51fa: "" \n\u89e3\u91ca: \u6ca1\u6709\u529e\u6cd5\u627e\u5230\u53ef\u80fd\u7684\u91cd\u6392\u7ed3\u679c\u3002\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u8f93\u5165: s = "aaadbbcc", k = 2\n\u8f93\u51fa: "abacabcd"\n\u89e3\u91ca: \u76f8\u540c\u7684\u5b57\u6bcd\u5728\u65b0\u7684\u5b57\u7b26\u4e32\u4e2d\u95f4\u9694\u81f3\u5c11 2 \u4e2a\u5355\u4f4d\u8ddd\u79bb\u3002\n
    \n", "tags_en": ["Heap", "Greedy", "Hash Table"], "tags_cn": ["\u5806", "\u8d2a\u5fc3\u7b97\u6cd5", "\u54c8\u5e0c\u8868"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string rearrangeString(string s, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String rearrangeString(String s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def rearrangeString(self, s, k):\n \"\"\"\n :type s: str\n :type k: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def rearrangeString(self, s: str, k: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * rearrangeString(char * s, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string RearrangeString(string s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number} k\n * @return {string}\n */\nvar rearrangeString = function(s, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer} k\n# @return {String}\ndef rearrange_string(s, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func rearrangeString(_ s: String, _ k: Int) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func rearrangeString(s string, k int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def rearrangeString(s: String, k: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun rearrangeString(s: String, k: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn rearrange_string(s: String, k: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer $k\n * @return String\n */\n function rearrangeString($s, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function rearrangeString(s: string, k: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (rearrange-string s k)\n (-> string? exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0358](https://leetcode-cn.com/problems/rearrange-string-k-distance-apart)", "[K \u8ddd\u79bb\u95f4\u9694\u91cd\u6392\u5b57\u7b26\u4e32](/solution/0300-0399/0358.Rearrange%20String%20k%20Distance%20Apart/README.md)", "`\u5806`,`\u8d2a\u5fc3\u7b97\u6cd5`,`\u54c8\u5e0c\u8868`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0358](https://leetcode.com/problems/rearrange-string-k-distance-apart)", "[Rearrange String k Distance Apart](/solution/0300-0399/0358.Rearrange%20String%20k%20Distance%20Apart/README_EN.md)", "`Heap`,`Greedy`,`Hash Table`", "Hard", "\ud83d\udd12"]}, {"question_id": "0357", "frontend_question_id": "0357", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-numbers-with-unique-digits", "url_en": "https://leetcode.com/problems/count-numbers-with-unique-digits", "relative_path_cn": "/solution/0300-0399/0357.Count%20Numbers%20with%20Unique%20Digits/README.md", "relative_path_en": "/solution/0300-0399/0357.Count%20Numbers%20with%20Unique%20Digits/README_EN.md", "title_cn": "\u8ba1\u7b97\u5404\u4e2a\u4f4d\u6570\u4e0d\u540c\u7684\u6570\u5b57\u4e2a\u6570", "title_en": "Count Numbers with Unique Digits", "question_title_slug": "count-numbers-with-unique-digits", "content_en": "

    Given an integer n, return the count of all numbers with unique digits, x, where 0 <= x < 10n.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 2\nOutput: 91\nExplanation: The answer should be the total numbers in the range of 0 ≤ x < 100, excluding 11,22,33,44,55,66,77,88,99\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 0\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= n <= 8
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u8d1f\u6574\u6570 n\uff0c\u8ba1\u7b97\u5404\u4f4d\u6570\u5b57\u90fd\u4e0d\u540c\u7684\u6570\u5b57 x \u7684\u4e2a\u6570\uff0c\u5176\u4e2d 0 ≤ x < 10\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: 2\n\u8f93\u51fa: 91 \n\u89e3\u91ca: \u7b54\u6848\u5e94\u4e3a\u9664\u53bb 11,22,33,44,55,66,77,88,99 \u5916\uff0c\u5728 [0,100) \u533a\u95f4\u5185\u7684\u6240\u6709\u6570\u5b57\u3002\n
    \n", "tags_en": ["Math", "Dynamic Programming", "Backtracking"], "tags_cn": ["\u6570\u5b66", "\u52a8\u6001\u89c4\u5212", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countNumbersWithUniqueDigits(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countNumbersWithUniqueDigits(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countNumbersWithUniqueDigits(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countNumbersWithUniqueDigits(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countNumbersWithUniqueDigits(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountNumbersWithUniqueDigits(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar countNumbersWithUniqueDigits = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef count_numbers_with_unique_digits(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countNumbersWithUniqueDigits(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countNumbersWithUniqueDigits(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countNumbersWithUniqueDigits(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countNumbersWithUniqueDigits(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_numbers_with_unique_digits(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function countNumbersWithUniqueDigits($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countNumbersWithUniqueDigits(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-numbers-with-unique-digits n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0357](https://leetcode-cn.com/problems/count-numbers-with-unique-digits)", "[\u8ba1\u7b97\u5404\u4e2a\u4f4d\u6570\u4e0d\u540c\u7684\u6570\u5b57\u4e2a\u6570](/solution/0300-0399/0357.Count%20Numbers%20with%20Unique%20Digits/README.md)", "`\u6570\u5b66`,`\u52a8\u6001\u89c4\u5212`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0357](https://leetcode.com/problems/count-numbers-with-unique-digits)", "[Count Numbers with Unique Digits](/solution/0300-0399/0357.Count%20Numbers%20with%20Unique%20Digits/README_EN.md)", "`Math`,`Dynamic Programming`,`Backtracking`", "Medium", ""]}, {"question_id": "0356", "frontend_question_id": "0356", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/line-reflection", "url_en": "https://leetcode.com/problems/line-reflection", "relative_path_cn": "/solution/0300-0399/0356.Line%20Reflection/README.md", "relative_path_en": "/solution/0300-0399/0356.Line%20Reflection/README_EN.md", "title_cn": "\u76f4\u7ebf\u955c\u50cf", "title_en": "Line Reflection", "question_title_slug": "line-reflection", "content_en": "

    Given n points on a 2D plane, find if there is such a line parallel to y-axis that reflect the given points symmetrically, in other words, answer whether or not if there exists a line that after reflecting all points over the given line the set of the original points is the same that the reflected ones.

    \n\n

    Note that there can be repeated points.

    \n\n

    Follow up:
    \nCould you do better than O(n2) ?

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: points = [[1,1],[-1,1]]\nOutput: true\nExplanation: We can choose the line x = 0.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: points = [[1,1],[-1,-1]]\nOutput: false\nExplanation: We can't choose a line.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == points.length
    • \n\t
    • 1 <= n <= 10^4
    • \n\t
    • -10^8 <= points[i][j] <= 10^8
    • \n
    \n", "content_cn": "

    \u5728\u4e00\u4e2a\u4e8c\u7ef4\u5e73\u9762\u7a7a\u95f4\u4e2d\uff0c\u7ed9\u4f60 n\u00a0\u4e2a\u70b9\u7684\u5750\u6807\u3002\u95ee\uff0c\u662f\u5426\u80fd\u627e\u51fa\u4e00\u6761\u5e73\u884c\u4e8e y\u00a0\u8f74\u7684\u76f4\u7ebf\uff0c\u8ba9\u8fd9\u4e9b\u70b9\u5173\u4e8e\u8fd9\u6761\u76f4\u7ebf\u6210\u955c\u50cf\u6392\u5e03\uff1f

    \n\n

    \u6ce8\u610f\uff1a\u9898\u76ee\u6570\u636e\u4e2d\u53ef\u80fd\u6709\u91cd\u590d\u7684\u70b9\u3002

    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u80fd\u627e\u5230\u6bd4 O(n2) \u66f4\u4f18\u7684\u89e3\u6cd5\u5417?

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1apoints = [[1,1],[-1,1]]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u53ef\u4ee5\u627e\u51fa x = 0 \u8fd9\u6761\u7ebf\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1apoints = [[1,1],[-1,-1]]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u65e0\u6cd5\u627e\u51fa\u8fd9\u6837\u4e00\u6761\u7ebf\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == points.length
    • \n\t
    • 1 <= n <= 10^4
    • \n\t
    • -10^8\u00a0<= points[i][j] <=\u00a010^8
    • \n
    \n", "tags_en": ["Hash Table", "Math"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isReflected(vector>& points) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isReflected(int[][] points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isReflected(self, points):\n \"\"\"\n :type points: List[List[int]]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isReflected(self, points: List[List[int]]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isReflected(int** points, int pointsSize, int* pointsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsReflected(int[][] points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} points\n * @return {boolean}\n */\nvar isReflected = function(points) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} points\n# @return {Boolean}\ndef is_reflected(points)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isReflected(_ points: [[Int]]) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isReflected(points [][]int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isReflected(points: Array[Array[Int]]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isReflected(points: Array): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_reflected(points: Vec>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $points\n * @return Boolean\n */\n function isReflected($points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isReflected(points: number[][]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-reflected points)\n (-> (listof (listof exact-integer?)) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0356](https://leetcode-cn.com/problems/line-reflection)", "[\u76f4\u7ebf\u955c\u50cf](/solution/0300-0399/0356.Line%20Reflection/README.md)", "`\u54c8\u5e0c\u8868`,`\u6570\u5b66`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0356](https://leetcode.com/problems/line-reflection)", "[Line Reflection](/solution/0300-0399/0356.Line%20Reflection/README_EN.md)", "`Hash Table`,`Math`", "Medium", "\ud83d\udd12"]}, {"question_id": "0355", "frontend_question_id": "0355", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/design-twitter", "url_en": "https://leetcode.com/problems/design-twitter", "relative_path_cn": "/solution/0300-0399/0355.Design%20Twitter/README.md", "relative_path_en": "/solution/0300-0399/0355.Design%20Twitter/README_EN.md", "title_cn": "\u8bbe\u8ba1\u63a8\u7279", "title_en": "Design Twitter", "question_title_slug": "design-twitter", "content_en": "

    Design a simplified version of Twitter where users can post tweets, follow/unfollow another user, and is able to see the 10 most recent tweets in the user's news feed.

    \n\n

    Implement the Twitter class:

    \n\n
      \n\t
    • Twitter() Initializes your twitter object.
    • \n\t
    • void postTweet(int userId, int tweetId) Composes a new tweet with ID tweetId by the user userId. Each call to this function will be made with a unique tweetId.
    • \n\t
    • List<Integer> getNewsFeed(int userId) Retrieves the 10 most recent tweet IDs in the user's news feed. Each item in the news feed must be posted by users who the user followed or by the user themself. Tweets must be ordered from most recent to least recent.
    • \n\t
    • void follow(int followerId, int followeeId) The user with ID followerId started following the user with ID followeeId.
    • \n\t
    • void unfollow(int followerId, int followeeId) The user with ID followerId started unfollowing the user with ID followeeId.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["Twitter", "postTweet", "getNewsFeed", "follow", "postTweet", "getNewsFeed", "unfollow", "getNewsFeed"]\n[[], [1, 5], [1], [1, 2], [2, 6], [1], [1, 2], [1]]\nOutput\n[null, null, [5], null, null, [6, 5], null, [5]]\n\nExplanation\nTwitter twitter = new Twitter();\ntwitter.postTweet(1, 5); // User 1 posts a new tweet (id = 5).\ntwitter.getNewsFeed(1);  // User 1's news feed should return a list with 1 tweet id -> [5]. return [5]\ntwitter.follow(1, 2);    // User 1 follows user 2.\ntwitter.postTweet(2, 6); // User 2 posts a new tweet (id = 6).\ntwitter.getNewsFeed(1);  // User 1's news feed should return a list with 2 tweet ids -> [6, 5]. Tweet id 6 should precede tweet id 5 because it is posted after tweet id 5.\ntwitter.unfollow(1, 2);  // User 1 unfollows user 2.\ntwitter.getNewsFeed(1);  // User 1's news feed should return a list with 1 tweet id -> [5], since user 1 is no longer following user 2.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= userId, followerId, followeeId <= 500
    • \n\t
    • 0 <= tweetId <= 104
    • \n\t
    • All the tweets have unique IDs.
    • \n\t
    • At most 3 * 104 calls will be made to postTweet, getNewsFeed, follow, and unfollow.
    • \n
    \n", "content_cn": "

    \u8bbe\u8ba1\u4e00\u4e2a\u7b80\u5316\u7248\u7684\u63a8\u7279(Twitter)\uff0c\u53ef\u4ee5\u8ba9\u7528\u6237\u5b9e\u73b0\u53d1\u9001\u63a8\u6587\uff0c\u5173\u6ce8/\u53d6\u6d88\u5173\u6ce8\u5176\u4ed6\u7528\u6237\uff0c\u80fd\u591f\u770b\u89c1\u5173\u6ce8\u4eba\uff08\u5305\u62ec\u81ea\u5df1\uff09\u7684\u6700\u8fd1\u5341\u6761\u63a8\u6587\u3002\u4f60\u7684\u8bbe\u8ba1\u9700\u8981\u652f\u6301\u4ee5\u4e0b\u7684\u51e0\u4e2a\u529f\u80fd\uff1a

    \n\n
      \n\t
    1. postTweet(userId, tweetId): \u521b\u5efa\u4e00\u6761\u65b0\u7684\u63a8\u6587
    2. \n\t
    3. getNewsFeed(userId): \u68c0\u7d22\u6700\u8fd1\u7684\u5341\u6761\u63a8\u6587\u3002\u6bcf\u4e2a\u63a8\u6587\u90fd\u5fc5\u987b\u662f\u7531\u6b64\u7528\u6237\u5173\u6ce8\u7684\u4eba\u6216\u8005\u662f\u7528\u6237\u81ea\u5df1\u53d1\u51fa\u7684\u3002\u63a8\u6587\u5fc5\u987b\u6309\u7167\u65f6\u95f4\u987a\u5e8f\u7531\u6700\u8fd1\u7684\u5f00\u59cb\u6392\u5e8f\u3002
    4. \n\t
    5. follow(followerId, followeeId): \u5173\u6ce8\u4e00\u4e2a\u7528\u6237
    6. \n\t
    7. unfollow(followerId, followeeId): \u53d6\u6d88\u5173\u6ce8\u4e00\u4e2a\u7528\u6237
    8. \n
    \n\n

    \u793a\u4f8b:

    \n\n
    \nTwitter twitter = new Twitter();\n\n// \u7528\u62371\u53d1\u9001\u4e86\u4e00\u6761\u65b0\u63a8\u6587 (\u7528\u6237id = 1, \u63a8\u6587id = 5).\ntwitter.postTweet(1, 5);\n\n// \u7528\u62371\u7684\u83b7\u53d6\u63a8\u6587\u5e94\u5f53\u8fd4\u56de\u4e00\u4e2a\u5217\u8868\uff0c\u5176\u4e2d\u5305\u542b\u4e00\u4e2aid\u4e3a5\u7684\u63a8\u6587.\ntwitter.getNewsFeed(1);\n\n// \u7528\u62371\u5173\u6ce8\u4e86\u7528\u62372.\ntwitter.follow(1, 2);\n\n// \u7528\u62372\u53d1\u9001\u4e86\u4e00\u4e2a\u65b0\u63a8\u6587 (\u63a8\u6587id = 6).\ntwitter.postTweet(2, 6);\n\n// \u7528\u62371\u7684\u83b7\u53d6\u63a8\u6587\u5e94\u5f53\u8fd4\u56de\u4e00\u4e2a\u5217\u8868\uff0c\u5176\u4e2d\u5305\u542b\u4e24\u4e2a\u63a8\u6587\uff0cid\u5206\u522b\u4e3a -> [6, 5].\n// \u63a8\u6587id6\u5e94\u5f53\u5728\u63a8\u6587id5\u4e4b\u524d\uff0c\u56e0\u4e3a\u5b83\u662f\u57285\u4e4b\u540e\u53d1\u9001\u7684.\ntwitter.getNewsFeed(1);\n\n// \u7528\u62371\u53d6\u6d88\u5173\u6ce8\u4e86\u7528\u62372.\ntwitter.unfollow(1, 2);\n\n// \u7528\u62371\u7684\u83b7\u53d6\u63a8\u6587\u5e94\u5f53\u8fd4\u56de\u4e00\u4e2a\u5217\u8868\uff0c\u5176\u4e2d\u5305\u542b\u4e00\u4e2aid\u4e3a5\u7684\u63a8\u6587.\n// \u56e0\u4e3a\u7528\u62371\u5df2\u7ecf\u4e0d\u518d\u5173\u6ce8\u7528\u62372.\ntwitter.getNewsFeed(1);\n
    \n", "tags_en": ["Heap", "Design", "Hash Table"], "tags_cn": ["\u5806", "\u8bbe\u8ba1", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Twitter {\npublic:\n /** Initialize your data structure here. */\n Twitter() {\n\n }\n \n /** Compose a new tweet. */\n void postTweet(int userId, int tweetId) {\n\n }\n \n /** Retrieve the 10 most recent tweet ids in the user's news feed. Each item in the news feed must be posted by users who the user followed or by the user herself. Tweets must be ordered from most recent to least recent. */\n vector getNewsFeed(int userId) {\n\n }\n \n /** Follower follows a followee. If the operation is invalid, it should be a no-op. */\n void follow(int followerId, int followeeId) {\n\n }\n \n /** Follower unfollows a followee. If the operation is invalid, it should be a no-op. */\n void unfollow(int followerId, int followeeId) {\n\n }\n};\n\n/**\n * Your Twitter object will be instantiated and called as such:\n * Twitter* obj = new Twitter();\n * obj->postTweet(userId,tweetId);\n * vector param_2 = obj->getNewsFeed(userId);\n * obj->follow(followerId,followeeId);\n * obj->unfollow(followerId,followeeId);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Twitter {\n\n /** Initialize your data structure here. */\n public Twitter() {\n\n }\n \n /** Compose a new tweet. */\n public void postTweet(int userId, int tweetId) {\n\n }\n \n /** Retrieve the 10 most recent tweet ids in the user's news feed. Each item in the news feed must be posted by users who the user followed or by the user herself. Tweets must be ordered from most recent to least recent. */\n public List getNewsFeed(int userId) {\n\n }\n \n /** Follower follows a followee. If the operation is invalid, it should be a no-op. */\n public void follow(int followerId, int followeeId) {\n\n }\n \n /** Follower unfollows a followee. If the operation is invalid, it should be a no-op. */\n public void unfollow(int followerId, int followeeId) {\n\n }\n}\n\n/**\n * Your Twitter object will be instantiated and called as such:\n * Twitter obj = new Twitter();\n * obj.postTweet(userId,tweetId);\n * List param_2 = obj.getNewsFeed(userId);\n * obj.follow(followerId,followeeId);\n * obj.unfollow(followerId,followeeId);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Twitter(object):\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def postTweet(self, userId, tweetId):\n \"\"\"\n Compose a new tweet.\n :type userId: int\n :type tweetId: int\n :rtype: None\n \"\"\"\n\n\n def getNewsFeed(self, userId):\n \"\"\"\n Retrieve the 10 most recent tweet ids in the user's news feed. Each item in the news feed must be posted by users who the user followed or by the user herself. Tweets must be ordered from most recent to least recent.\n :type userId: int\n :rtype: List[int]\n \"\"\"\n\n\n def follow(self, followerId, followeeId):\n \"\"\"\n Follower follows a followee. If the operation is invalid, it should be a no-op.\n :type followerId: int\n :type followeeId: int\n :rtype: None\n \"\"\"\n\n\n def unfollow(self, followerId, followeeId):\n \"\"\"\n Follower unfollows a followee. If the operation is invalid, it should be a no-op.\n :type followerId: int\n :type followeeId: int\n :rtype: None\n \"\"\"\n\n\n\n# Your Twitter object will be instantiated and called as such:\n# obj = Twitter()\n# obj.postTweet(userId,tweetId)\n# param_2 = obj.getNewsFeed(userId)\n# obj.follow(followerId,followeeId)\n# obj.unfollow(followerId,followeeId)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Twitter:\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def postTweet(self, userId: int, tweetId: int) -> None:\n \"\"\"\n Compose a new tweet.\n \"\"\"\n\n\n def getNewsFeed(self, userId: int) -> List[int]:\n \"\"\"\n Retrieve the 10 most recent tweet ids in the user's news feed. Each item in the news feed must be posted by users who the user followed or by the user herself. Tweets must be ordered from most recent to least recent.\n \"\"\"\n\n\n def follow(self, followerId: int, followeeId: int) -> None:\n \"\"\"\n Follower follows a followee. If the operation is invalid, it should be a no-op.\n \"\"\"\n\n\n def unfollow(self, followerId: int, followeeId: int) -> None:\n \"\"\"\n Follower unfollows a followee. If the operation is invalid, it should be a no-op.\n \"\"\"\n\n\n\n# Your Twitter object will be instantiated and called as such:\n# obj = Twitter()\n# obj.postTweet(userId,tweetId)\n# param_2 = obj.getNewsFeed(userId)\n# obj.follow(followerId,followeeId)\n# obj.unfollow(followerId,followeeId)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} Twitter;\n\n/** Initialize your data structure here. */\n\nTwitter* twitterCreate() {\n\n}\n\n/** Compose a new tweet. */\nvoid twitterPostTweet(Twitter* obj, int userId, int tweetId) {\n\n}\n\n/** Retrieve the 10 most recent tweet ids in the user's news feed. Each item in the news feed must be posted by users who the user followed or by the user herself. Tweets must be ordered from most recent to least recent. */\nint* twitterGetNewsFeed(Twitter* obj, int userId, int* retSize) {\n\n}\n\n/** Follower follows a followee. If the operation is invalid, it should be a no-op. */\nvoid twitterFollow(Twitter* obj, int followerId, int followeeId) {\n\n}\n\n/** Follower unfollows a followee. If the operation is invalid, it should be a no-op. */\nvoid twitterUnfollow(Twitter* obj, int followerId, int followeeId) {\n\n}\n\nvoid twitterFree(Twitter* obj) {\n\n}\n\n/**\n * Your Twitter struct will be instantiated and called as such:\n * Twitter* obj = twitterCreate();\n * twitterPostTweet(obj, userId, tweetId);\n \n * int* param_2 = twitterGetNewsFeed(obj, userId, retSize);\n \n * twitterFollow(obj, followerId, followeeId);\n \n * twitterUnfollow(obj, followerId, followeeId);\n \n * twitterFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Twitter {\n\n /** Initialize your data structure here. */\n public Twitter() {\n\n }\n \n /** Compose a new tweet. */\n public void PostTweet(int userId, int tweetId) {\n\n }\n \n /** Retrieve the 10 most recent tweet ids in the user's news feed. Each item in the news feed must be posted by users who the user followed or by the user herself. Tweets must be ordered from most recent to least recent. */\n public IList GetNewsFeed(int userId) {\n\n }\n \n /** Follower follows a followee. If the operation is invalid, it should be a no-op. */\n public void Follow(int followerId, int followeeId) {\n\n }\n \n /** Follower unfollows a followee. If the operation is invalid, it should be a no-op. */\n public void Unfollow(int followerId, int followeeId) {\n\n }\n}\n\n/**\n * Your Twitter object will be instantiated and called as such:\n * Twitter obj = new Twitter();\n * obj.PostTweet(userId,tweetId);\n * IList param_2 = obj.GetNewsFeed(userId);\n * obj.Follow(followerId,followeeId);\n * obj.Unfollow(followerId,followeeId);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Initialize your data structure here.\n */\nvar Twitter = function() {\n\n};\n\n/**\n * Compose a new tweet. \n * @param {number} userId \n * @param {number} tweetId\n * @return {void}\n */\nTwitter.prototype.postTweet = function(userId, tweetId) {\n\n};\n\n/**\n * Retrieve the 10 most recent tweet ids in the user's news feed. Each item in the news feed must be posted by users who the user followed or by the user herself. Tweets must be ordered from most recent to least recent. \n * @param {number} userId\n * @return {number[]}\n */\nTwitter.prototype.getNewsFeed = function(userId) {\n\n};\n\n/**\n * Follower follows a followee. If the operation is invalid, it should be a no-op. \n * @param {number} followerId \n * @param {number} followeeId\n * @return {void}\n */\nTwitter.prototype.follow = function(followerId, followeeId) {\n\n};\n\n/**\n * Follower unfollows a followee. If the operation is invalid, it should be a no-op. \n * @param {number} followerId \n * @param {number} followeeId\n * @return {void}\n */\nTwitter.prototype.unfollow = function(followerId, followeeId) {\n\n};\n\n/**\n * Your Twitter object will be instantiated and called as such:\n * var obj = new Twitter()\n * obj.postTweet(userId,tweetId)\n * var param_2 = obj.getNewsFeed(userId)\n * obj.follow(followerId,followeeId)\n * obj.unfollow(followerId,followeeId)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class Twitter\n\n=begin\n Initialize your data structure here.\n=end\n def initialize()\n\n end\n\n\n=begin\n Compose a new tweet.\n :type user_id: Integer\n :type tweet_id: Integer\n :rtype: Void\n=end\n def post_tweet(user_id, tweet_id)\n\n end\n\n\n=begin\n Retrieve the 10 most recent tweet ids in the user's news feed. Each item in the news feed must be posted by users who the user followed or by the user herself. Tweets must be ordered from most recent to least recent.\n :type user_id: Integer\n :rtype: Integer[]\n=end\n def get_news_feed(user_id)\n\n end\n\n\n=begin\n Follower follows a followee. If the operation is invalid, it should be a no-op.\n :type follower_id: Integer\n :type followee_id: Integer\n :rtype: Void\n=end\n def follow(follower_id, followee_id)\n\n end\n\n\n=begin\n Follower unfollows a followee. If the operation is invalid, it should be a no-op.\n :type follower_id: Integer\n :type followee_id: Integer\n :rtype: Void\n=end\n def unfollow(follower_id, followee_id)\n\n end\n\n\nend\n\n# Your Twitter object will be instantiated and called as such:\n# obj = Twitter.new()\n# obj.post_tweet(user_id, tweet_id)\n# param_2 = obj.get_news_feed(user_id)\n# obj.follow(follower_id, followee_id)\n# obj.unfollow(follower_id, followee_id)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass Twitter {\n\n /** Initialize your data structure here. */\n init() {\n\n }\n \n /** Compose a new tweet. */\n func postTweet(_ userId: Int, _ tweetId: Int) {\n\n }\n \n /** Retrieve the 10 most recent tweet ids in the user's news feed. Each item in the news feed must be posted by users who the user followed or by the user herself. Tweets must be ordered from most recent to least recent. */\n func getNewsFeed(_ userId: Int) -> [Int] {\n\n }\n \n /** Follower follows a followee. If the operation is invalid, it should be a no-op. */\n func follow(_ followerId: Int, _ followeeId: Int) {\n\n }\n \n /** Follower unfollows a followee. If the operation is invalid, it should be a no-op. */\n func unfollow(_ followerId: Int, _ followeeId: Int) {\n\n }\n}\n\n/**\n * Your Twitter object will be instantiated and called as such:\n * let obj = Twitter()\n * obj.postTweet(userId, tweetId)\n * let ret_2: [Int] = obj.getNewsFeed(userId)\n * obj.follow(followerId, followeeId)\n * obj.unfollow(followerId, followeeId)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type Twitter struct {\n\n}\n\n\n/** Initialize your data structure here. */\nfunc Constructor() Twitter {\n\n}\n\n\n/** Compose a new tweet. */\nfunc (this *Twitter) PostTweet(userId int, tweetId int) {\n\n}\n\n\n/** Retrieve the 10 most recent tweet ids in the user's news feed. Each item in the news feed must be posted by users who the user followed or by the user herself. Tweets must be ordered from most recent to least recent. */\nfunc (this *Twitter) GetNewsFeed(userId int) []int {\n\n}\n\n\n/** Follower follows a followee. If the operation is invalid, it should be a no-op. */\nfunc (this *Twitter) Follow(followerId int, followeeId int) {\n\n}\n\n\n/** Follower unfollows a followee. If the operation is invalid, it should be a no-op. */\nfunc (this *Twitter) Unfollow(followerId int, followeeId int) {\n\n}\n\n\n/**\n * Your Twitter object will be instantiated and called as such:\n * obj := Constructor();\n * obj.PostTweet(userId,tweetId);\n * param_2 := obj.GetNewsFeed(userId);\n * obj.Follow(followerId,followeeId);\n * obj.Unfollow(followerId,followeeId);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class Twitter() {\n\n /** Initialize your data structure here. */\n\n\n /** Compose a new tweet. */\n def postTweet(userId: Int, tweetId: Int) {\n\n }\n\n /** Retrieve the 10 most recent tweet ids in the user's news feed. Each item in the news feed must be posted by users who the user followed or by the user herself. Tweets must be ordered from most recent to least recent. */\n def getNewsFeed(userId: Int): List[Int] = {\n\n }\n\n /** Follower follows a followee. If the operation is invalid, it should be a no-op. */\n def follow(followerId: Int, followeeId: Int) {\n\n }\n\n /** Follower unfollows a followee. If the operation is invalid, it should be a no-op. */\n def unfollow(followerId: Int, followeeId: Int) {\n\n }\n\n}\n\n/**\n * Your Twitter object will be instantiated and called as such:\n * var obj = new Twitter()\n * obj.postTweet(userId,tweetId)\n * var param_2 = obj.getNewsFeed(userId)\n * obj.follow(followerId,followeeId)\n * obj.unfollow(followerId,followeeId)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Twitter() {\n\n /** Initialize your data structure here. */\n\n\n /** Compose a new tweet. */\n fun postTweet(userId: Int, tweetId: Int) {\n\n }\n\n /** Retrieve the 10 most recent tweet ids in the user's news feed. Each item in the news feed must be posted by users who the user followed or by the user herself. Tweets must be ordered from most recent to least recent. */\n fun getNewsFeed(userId: Int): List {\n\n }\n\n /** Follower follows a followee. If the operation is invalid, it should be a no-op. */\n fun follow(followerId: Int, followeeId: Int) {\n\n }\n\n /** Follower unfollows a followee. If the operation is invalid, it should be a no-op. */\n fun unfollow(followerId: Int, followeeId: Int) {\n\n }\n\n}\n\n/**\n * Your Twitter object will be instantiated and called as such:\n * var obj = Twitter()\n * obj.postTweet(userId,tweetId)\n * var param_2 = obj.getNewsFeed(userId)\n * obj.follow(followerId,followeeId)\n * obj.unfollow(followerId,followeeId)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct Twitter {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl Twitter {\n\n /** Initialize your data structure here. */\n fn new() -> Self {\n\n }\n \n /** Compose a new tweet. */\n fn post_tweet(&self, user_id: i32, tweet_id: i32) {\n\n }\n \n /** Retrieve the 10 most recent tweet ids in the user's news feed. Each item in the news feed must be posted by users who the user followed or by the user herself. Tweets must be ordered from most recent to least recent. */\n fn get_news_feed(&self, user_id: i32) -> Vec {\n\n }\n \n /** Follower follows a followee. If the operation is invalid, it should be a no-op. */\n fn follow(&self, follower_id: i32, followee_id: i32) {\n\n }\n \n /** Follower unfollows a followee. If the operation is invalid, it should be a no-op. */\n fn unfollow(&self, follower_id: i32, followee_id: i32) {\n\n }\n}\n\n/**\n * Your Twitter object will be instantiated and called as such:\n * let obj = Twitter::new();\n * obj.post_tweet(userId, tweetId);\n * let ret_2: Vec = obj.get_news_feed(userId);\n * obj.follow(followerId, followeeId);\n * obj.unfollow(followerId, followeeId);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Twitter {\n /**\n * Initialize your data structure here.\n */\n function __construct() {\n\n }\n\n /**\n * Compose a new tweet.\n * @param Integer $userId\n * @param Integer $tweetId\n * @return NULL\n */\n function postTweet($userId, $tweetId) {\n\n }\n\n /**\n * Retrieve the 10 most recent tweet ids in the user's news feed. Each item in the news feed must be posted by users who the user followed or by the user herself. Tweets must be ordered from most recent to least recent.\n * @param Integer $userId\n * @return Integer[]\n */\n function getNewsFeed($userId) {\n\n }\n\n /**\n * Follower follows a followee. If the operation is invalid, it should be a no-op.\n * @param Integer $followerId\n * @param Integer $followeeId\n * @return NULL\n */\n function follow($followerId, $followeeId) {\n\n }\n\n /**\n * Follower unfollows a followee. If the operation is invalid, it should be a no-op.\n * @param Integer $followerId\n * @param Integer $followeeId\n * @return NULL\n */\n function unfollow($followerId, $followeeId) {\n\n }\n}\n\n/**\n * Your Twitter object will be instantiated and called as such:\n * $obj = Twitter();\n * $obj->postTweet($userId, $tweetId);\n * $ret_2 = $obj->getNewsFeed($userId);\n * $obj->follow($followerId, $followeeId);\n * $obj->unfollow($followerId, $followeeId);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class Twitter {\n constructor() {\n\n }\n\n postTweet(userId: number, tweetId: number): void {\n\n }\n\n getNewsFeed(userId: number): number[] {\n\n }\n\n follow(followerId: number, followeeId: number): void {\n\n }\n\n unfollow(followerId: number, followeeId: number): void {\n\n }\n}\n\n/**\n * Your Twitter object will be instantiated and called as such:\n * var obj = new Twitter()\n * obj.postTweet(userId,tweetId)\n * var param_2 = obj.getNewsFeed(userId)\n * obj.follow(followerId,followeeId)\n * obj.unfollow(followerId,followeeId)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define twitter%\n (class object%\n (super-new)\n (init-field)\n \n ; post-tweet : exact-integer? exact-integer? -> void?\n (define/public (post-tweet userId tweetId)\n\n )\n ; get-news-feed : exact-integer? -> (listof exact-integer?)\n (define/public (get-news-feed userId)\n\n )\n ; follow : exact-integer? exact-integer? -> void?\n (define/public (follow followerId followeeId)\n\n )\n ; unfollow : exact-integer? exact-integer? -> void?\n (define/public (unfollow followerId followeeId)\n\n )))\n\n;; Your twitter% object will be instantiated and called as such:\n;; (define obj (new twitter%))\n;; (send obj post-tweet user-id tweet-id)\n;; (define param_2 (send obj get-news-feed user-id))\n;; (send obj follow follower-id followee-id)\n;; (send obj unfollow follower-id followee-id)", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0355](https://leetcode-cn.com/problems/design-twitter)", "[\u8bbe\u8ba1\u63a8\u7279](/solution/0300-0399/0355.Design%20Twitter/README.md)", "`\u5806`,`\u8bbe\u8ba1`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0355](https://leetcode.com/problems/design-twitter)", "[Design Twitter](/solution/0300-0399/0355.Design%20Twitter/README_EN.md)", "`Heap`,`Design`,`Hash Table`", "Medium", ""]}, {"question_id": "0354", "frontend_question_id": "0354", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/russian-doll-envelopes", "url_en": "https://leetcode.com/problems/russian-doll-envelopes", "relative_path_cn": "/solution/0300-0399/0354.Russian%20Doll%20Envelopes/README.md", "relative_path_en": "/solution/0300-0399/0354.Russian%20Doll%20Envelopes/README_EN.md", "title_cn": "\u4fc4\u7f57\u65af\u5957\u5a03\u4fe1\u5c01\u95ee\u9898", "title_en": "Russian Doll Envelopes", "question_title_slug": "russian-doll-envelopes", "content_en": "

    You are given a 2D array of integers envelopes where envelopes[i] = [wi, hi] represents the width and the height of an envelope.

    \n\n

    One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope's width and height.

    \n\n

    Return the maximum number of envelopes you can Russian doll (i.e., put one inside the other).

    \n\n

    Note: You cannot rotate an envelope.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: envelopes = [[5,4],[6,4],[6,7],[2,3]]\nOutput: 3\nExplanation: The maximum number of envelopes you can Russian doll is 3 ([2,3] => [5,4] => [6,7]).\n
    \n\n

    Example 2:

    \n\n
    \nInput: envelopes = [[1,1],[1,1],[1,1]]\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= envelopes.length <= 5000
    • \n\t
    • envelopes[i].length == 2
    • \n\t
    • 1 <= wi, hi <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u4e8c\u7ef4\u6574\u6570\u6570\u7ec4 envelopes \uff0c\u5176\u4e2d envelopes[i] = [wi, hi] \uff0c\u8868\u793a\u7b2c i \u4e2a\u4fe1\u5c01\u7684\u5bbd\u5ea6\u548c\u9ad8\u5ea6\u3002

    \n\n

    \u5f53\u53e6\u4e00\u4e2a\u4fe1\u5c01\u7684\u5bbd\u5ea6\u548c\u9ad8\u5ea6\u90fd\u6bd4\u8fd9\u4e2a\u4fe1\u5c01\u5927\u7684\u65f6\u5019\uff0c\u8fd9\u4e2a\u4fe1\u5c01\u5c31\u53ef\u4ee5\u653e\u8fdb\u53e6\u4e00\u4e2a\u4fe1\u5c01\u91cc\uff0c\u5982\u540c\u4fc4\u7f57\u65af\u5957\u5a03\u4e00\u6837\u3002

    \n\n

    \u8bf7\u8ba1\u7b97 \u6700\u591a\u80fd\u6709\u591a\u5c11\u4e2a \u4fe1\u5c01\u80fd\u7ec4\u6210\u4e00\u7ec4\u201c\u4fc4\u7f57\u65af\u5957\u5a03\u201d\u4fe1\u5c01\uff08\u5373\u53ef\u4ee5\u628a\u4e00\u4e2a\u4fe1\u5c01\u653e\u5230\u53e6\u4e00\u4e2a\u4fe1\u5c01\u91cc\u9762\uff09\u3002

    \n\n

    \u6ce8\u610f\uff1a\u4e0d\u5141\u8bb8\u65cb\u8f6c\u4fe1\u5c01\u3002

    \n\u00a0\n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aenvelopes = [[5,4],[6,4],[6,7],[2,3]]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6700\u591a\u4fe1\u5c01\u7684\u4e2a\u6570\u4e3a 3, \u7ec4\u5408\u4e3a: [2,3] => [5,4] => [6,7]\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aenvelopes = [[1,1],[1,1],[1,1]]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= envelopes.length <= 5000
    • \n\t
    • envelopes[i].length == 2
    • \n\t
    • 1 <= wi, hi <= 104
    • \n
    \n", "tags_en": ["Binary Search", "Dynamic Programming"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxEnvelopes(vector>& envelopes) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxEnvelopes(int[][] envelopes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxEnvelopes(self, envelopes):\n \"\"\"\n :type envelopes: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxEnvelopes(self, envelopes: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxEnvelopes(int** envelopes, int envelopesSize, int* envelopesColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxEnvelopes(int[][] envelopes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} envelopes\n * @return {number}\n */\nvar maxEnvelopes = function(envelopes) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} envelopes\n# @return {Integer}\ndef max_envelopes(envelopes)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxEnvelopes(_ envelopes: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxEnvelopes(envelopes [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxEnvelopes(envelopes: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxEnvelopes(envelopes: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_envelopes(envelopes: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $envelopes\n * @return Integer\n */\n function maxEnvelopes($envelopes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxEnvelopes(envelopes: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-envelopes envelopes)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0354](https://leetcode-cn.com/problems/russian-doll-envelopes)", "[\u4fc4\u7f57\u65af\u5957\u5a03\u4fe1\u5c01\u95ee\u9898](/solution/0300-0399/0354.Russian%20Doll%20Envelopes/README.md)", "`\u4e8c\u5206\u67e5\u627e`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0354](https://leetcode.com/problems/russian-doll-envelopes)", "[Russian Doll Envelopes](/solution/0300-0399/0354.Russian%20Doll%20Envelopes/README_EN.md)", "`Binary Search`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0353", "frontend_question_id": "0353", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/design-snake-game", "url_en": "https://leetcode.com/problems/design-snake-game", "relative_path_cn": "/solution/0300-0399/0353.Design%20Snake%20Game/README.md", "relative_path_en": "/solution/0300-0399/0353.Design%20Snake%20Game/README_EN.md", "title_cn": "\u8d2a\u5403\u86c7", "title_en": "Design Snake Game", "question_title_slug": "design-snake-game", "content_en": "

    Design a Snake game that is played on a device with screen size height x width. Play the game online if you are not familiar with the game.

    \n\n

    The snake is initially positioned at the top left corner (0, 0) with a length of 1 unit.

    \n\n

    You are given an array food where food[i] = (ri, ci) is the row and column position of a piece of food that the snake can eat. When a snake eats a piece of food, its length and the game's score both increase by 1.

    \n\n

    Each piece of food appears one by one on the screen, meaning the second piece of food will not appear until the snake eats the first piece of food.

    \n\n

    When a piece of food appears on the screen, it is guaranteed that it will not appear on a block occupied by the snake.

    \n\n

    The game is over if the snake goes out of bounds (hits a wall) or if its head occupies a space that its body occupies after moving (i.e. a snake of length 4 cannot run into itself).

    \n\n

    Implement the SnakeGame class:

    \n\n
      \n\t
    • SnakeGame(int width, int height, int[][] food) Initializes the object with a screen of size height x width and the positions of the food.
    • \n\t
    • int move(String direction) Returns the score of the game after applying one direction move by the snake. If the game is over, return -1.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput\n["SnakeGame", "move", "move", "move", "move", "move", "move"]\n[[3, 2, [[1, 2], [0, 1]]], ["R"], ["D"], ["R"], ["U"], ["L"], ["U"]]\nOutput\n[null, 0, 0, 1, 1, 2, -1]\n\nExplanation\nSnakeGame snakeGame = new SnakeGame(3, 2, [[1, 2], [0, 1]]);\nsnakeGame.move("R"); // return 0\nsnakeGame.move("D"); // return 0\nsnakeGame.move("R"); // return 1, snake eats the first piece of food. The second piece of food appears\n                     // at (0, 1).\nsnakeGame.move("U"); // return 1\nsnakeGame.move("L"); // return 2, snake eats the second food. No more food appears.\nsnakeGame.move("U"); // return -1, game over because snake collides with border\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= width, height <= 104
    • \n\t
    • 1 <= food.length <= 50
    • \n\t
    • food[i].length == 2
    • \n\t
    • 0 <= ri < height
    • \n\t
    • 0 <= ci < width
    • \n\t
    • direction.length == 1
    • \n\t
    • direction is 'U', 'D', 'L', or 'R'.
    • \n\t
    • At most 104 calls will be made to move.
    • \n
    \n", "content_cn": "

    \u8bf7\u4f60\u8bbe\u8ba1\u4e00\u4e2a\u00a0\u8d2a\u5403\u86c7\u6e38\u620f\uff0c\u8be5\u6e38\u620f\u5c06\u4f1a\u5728\u4e00\u4e2a \u5c4f\u5e55\u5c3a\u5bf8 = \u5bbd\u5ea6 x \u9ad8\u5ea6\u00a0\u7684\u5c4f\u5e55\u4e0a\u8fd0\u884c\u3002\u5982\u679c\u4f60\u4e0d\u719f\u6089\u8fd9\u4e2a\u6e38\u620f\uff0c\u53ef\u4ee5\u00a0\u70b9\u51fb\u8fd9\u91cc\u00a0\u5728\u7ebf\u8bd5\u73a9\u3002

    \n\n

    \u8d77\u521d\u65f6\uff0c\u86c7\u5728\u5de6\u4e0a\u89d2\u7684 (0, 0) \u4f4d\u7f6e\uff0c\u8eab\u4f53\u957f\u5ea6\u4e3a 1 \u4e2a\u5355\u4f4d\u3002

    \n\n

    \u4f60\u5c06\u4f1a\u88ab\u7ed9\u51fa\u4e00\u4e2a\u6570\u7ec4\u5f62\u5f0f\u7684\u98df\u7269\u4f4d\u7f6e\u5e8f\u5217 food \uff0c\u5176\u4e2d\u00a0food[i] = (ri, ci) \u3002\u5f53\u86c7\u5403\u5230\u98df\u7269\u65f6\uff0c\u8eab\u5b50\u7684\u957f\u5ea6\u4f1a\u589e\u52a0 1 \u4e2a\u5355\u4f4d\uff0c\u5f97\u5206\u4e5f\u4f1a +1 \u3002

    \n\n

    \u98df\u7269\u4e0d\u4f1a\u540c\u65f6\u51fa\u73b0\uff0c\u4f1a\u6309\u5217\u8868\u7684\u987a\u5e8f\u9010\u4e00\u663e\u793a\u5728\u5c4f\u5e55\u4e0a\u3002\u6bd4\u65b9\u8bb2\uff0c\u7b2c\u4e00\u4e2a\u98df\u7269\u88ab\u86c7\u5403\u6389\u540e\uff0c\u7b2c\u4e8c\u4e2a\u98df\u7269\u624d\u4f1a\u51fa\u73b0\u3002

    \n\n

    \u5f53\u4e00\u4e2a\u98df\u7269\u5728\u5c4f\u5e55\u4e0a\u51fa\u73b0\u65f6\uff0c\u4fdd\u8bc1 \u4e0d\u4f1a \u51fa\u73b0\u5728\u88ab\u86c7\u8eab\u4f53\u5360\u636e\u7684\u683c\u5b50\u91cc\u3002

    \n\n

    \u5982\u679c\u86c7\u8d8a\u754c\uff08\u4e0e\u8fb9\u754c\u76f8\u649e\uff09\u6216\u8005\u5934\u4e0e \u79fb\u52a8\u540e \u7684\u8eab\u4f53\u76f8\u649e\uff08\u5373\uff0c\u8eab\u957f\u4e3a 4 \u7684\u86c7\u65e0\u6cd5\u4e0e\u81ea\u5df1\u76f8\u649e\uff09\uff0c\u6e38\u620f\u7ed3\u675f\u3002

    \n\n

    \u5b9e\u73b0 SnakeGame \u7c7b\uff1a

    \n\n
      \n\t
    • SnakeGame(int width, int height, int[][] food) \u521d\u59cb\u5316\u5bf9\u8c61\uff0c\u5c4f\u5e55\u5927\u5c0f\u4e3a height x width \uff0c\u98df\u7269\u4f4d\u7f6e\u5e8f\u5217\u4e3a food
    • \n\t
    • int move(String direction) \u8fd4\u56de\u86c7\u5728\u65b9\u5411 direction \u4e0a\u79fb\u52a8\u540e\u7684\u5f97\u5206\u3002\u5982\u679c\u6e38\u620f\u7ed3\u675f\uff0c\u8fd4\u56de -1 \u3002
    • \n
    \n\u00a0\n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1a\n[\"SnakeGame\", \"move\", \"move\", \"move\", \"move\", \"move\", \"move\"]\n[[3, 2, [[1, 2], [0, 1]]], [\"R\"], [\"D\"], [\"R\"], [\"U\"], [\"L\"], [\"U\"]]\n\u8f93\u51fa\uff1a\n[null, 0, 0, 1, 1, 2, -1]\n\n\u89e3\u91ca\uff1a\nSnakeGame snakeGame = new SnakeGame(3, 2, [[1, 2], [0, 1]]);\nsnakeGame.move(\"R\"); // \u8fd4\u56de 0\nsnakeGame.move(\"D\"); // \u8fd4\u56de 0\nsnakeGame.move(\"R\"); // \u8fd4\u56de 1 \uff0c\u86c7\u5403\u6389\u4e86\u7b2c\u4e00\u4e2a\u98df\u7269\uff0c\u540c\u65f6\u7b2c\u4e8c\u4e2a\u98df\u7269\u51fa\u73b0\u5728 (0, 1)\nsnakeGame.move(\"U\"); // \u8fd4\u56de 1\nsnakeGame.move(\"L\"); // \u8fd4\u56de 2 \uff0c\u86c7\u5403\u6389\u4e86\u7b2c\u4e8c\u4e2a\u98df\u7269\uff0c\u6ca1\u6709\u51fa\u73b0\u66f4\u591a\u98df\u7269\nsnakeGame.move(\"U\"); // \u8fd4\u56de -1 \uff0c\u86c7\u4e0e\u8fb9\u754c\u76f8\u649e\uff0c\u6e38\u620f\u7ed3\u675f\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= width, height <= 104
    • \n\t
    • 1 <= food.length <= 50
    • \n\t
    • food[i].length == 2
    • \n\t
    • 0 <= ri < height
    • \n\t
    • 0 <= ci < width
    • \n\t
    • direction.length == 1
    • \n\t
    • direction is 'U', 'D', 'L', or 'R'.
    • \n\t
    • \u6700\u591a\u8c03\u7528 104 \u6b21 move \u65b9\u6cd5
    • \n
    \n", "tags_en": ["Design", "Queue"], "tags_cn": ["\u8bbe\u8ba1", "\u961f\u5217"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class SnakeGame {\npublic:\n /** Initialize your data structure here.\n @param width - screen width\n @param height - screen height \n @param food - A list of food positions\n E.g food = [[1,1], [1,0]] means the first food is positioned at [1,1], the second is at [1,0]. */\n SnakeGame(int width, int height, vector>& food) {\n \n }\n \n /** Moves the snake.\n @param direction - 'U' = Up, 'L' = Left, 'R' = Right, 'D' = Down \n @return The game's score after the move. Return -1 if game over. \n Game over when snake crosses the screen boundary or bites its body. */\n int move(string direction) {\n \n }\n};\n\n/**\n * Your SnakeGame object will be instantiated and called as such:\n * SnakeGame* obj = new SnakeGame(width, height, food);\n * int param_1 = obj->move(direction);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class SnakeGame {\n\n /** Initialize your data structure here.\n @param width - screen width\n @param height - screen height \n @param food - A list of food positions\n E.g food = [[1,1], [1,0]] means the first food is positioned at [1,1], the second is at [1,0]. */\n public SnakeGame(int width, int height, int[][] food) {\n \n }\n \n /** Moves the snake.\n @param direction - 'U' = Up, 'L' = Left, 'R' = Right, 'D' = Down \n @return The game's score after the move. Return -1 if game over. \n Game over when snake crosses the screen boundary or bites its body. */\n public int move(String direction) {\n \n }\n}\n\n/**\n * Your SnakeGame object will be instantiated and called as such:\n * SnakeGame obj = new SnakeGame(width, height, food);\n * int param_1 = obj.move(direction);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class SnakeGame(object):\n\n def __init__(self, width, height, food):\n \"\"\"\n Initialize your data structure here.\n @param width - screen width\n @param height - screen height \n @param food - A list of food positions\n E.g food = [[1,1], [1,0]] means the first food is positioned at [1,1], the second is at [1,0].\n :type width: int\n :type height: int\n :type food: List[List[int]]\n \"\"\"\n \n\n def move(self, direction):\n \"\"\"\n Moves the snake.\n @param direction - 'U' = Up, 'L' = Left, 'R' = Right, 'D' = Down \n @return The game's score after the move. Return -1 if game over. \n Game over when snake crosses the screen boundary or bites its body.\n :type direction: str\n :rtype: int\n \"\"\"\n \n\n\n# Your SnakeGame object will be instantiated and called as such:\n# obj = SnakeGame(width, height, food)\n# param_1 = obj.move(direction)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class SnakeGame:\n\n def __init__(self, width: int, height: int, food: List[List[int]]):\n \"\"\"\n Initialize your data structure here.\n @param width - screen width\n @param height - screen height \n @param food - A list of food positions\n E.g food = [[1,1], [1,0]] means the first food is positioned at [1,1], the second is at [1,0].\n \"\"\"\n \n\n def move(self, direction: str) -> int:\n \"\"\"\n Moves the snake.\n @param direction - 'U' = Up, 'L' = Left, 'R' = Right, 'D' = Down \n @return The game's score after the move. Return -1 if game over. \n Game over when snake crosses the screen boundary or bites its body.\n \"\"\"\n \n\n\n# Your SnakeGame object will be instantiated and called as such:\n# obj = SnakeGame(width, height, food)\n# param_1 = obj.move(direction)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} SnakeGame;\n\n/** Initialize your data structure here.\n @param width - screen width\n @param height - screen height \n @param food - A list of food positions\n E.g food = [[1,1], [1,0]] means the first food is positioned at [1,1], the second is at [1,0]. */\n\nSnakeGame* snakeGameCreate(int width, int height, int** food, int foodSize, int* foodColSize) {\n \n}\n\n/** Moves the snake.\n @param direction - 'U' = Up, 'L' = Left, 'R' = Right, 'D' = Down \n @return The game's score after the move. Return -1 if game over. \n Game over when snake crosses the screen boundary or bites its body. */\nint snakeGameMove(SnakeGame* obj, char * direction) {\n \n}\n\nvoid snakeGameFree(SnakeGame* obj) {\n \n}\n\n/**\n * Your SnakeGame struct will be instantiated and called as such:\n * SnakeGame* obj = snakeGameCreate(width, height, food, foodSize, foodColSize);\n * int param_1 = snakeGameMove(obj, direction);\n \n * snakeGameFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class SnakeGame {\n\n /** Initialize your data structure here.\n @param width - screen width\n @param height - screen height \n @param food - A list of food positions\n E.g food = [[1,1], [1,0]] means the first food is positioned at [1,1], the second is at [1,0]. */\n public SnakeGame(int width, int height, int[][] food) {\n \n }\n \n /** Moves the snake.\n @param direction - 'U' = Up, 'L' = Left, 'R' = Right, 'D' = Down \n @return The game's score after the move. Return -1 if game over. \n Game over when snake crosses the screen boundary or bites its body. */\n public int Move(string direction) {\n \n }\n}\n\n/**\n * Your SnakeGame object will be instantiated and called as such:\n * SnakeGame obj = new SnakeGame(width, height, food);\n * int param_1 = obj.Move(direction);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Initialize your data structure here.\n @param width - screen width\n @param height - screen height \n @param food - A list of food positions\n E.g food = [[1,1], [1,0]] means the first food is positioned at [1,1], the second is at [1,0].\n * @param {number} width\n * @param {number} height\n * @param {number[][]} food\n */\nvar SnakeGame = function(width, height, food) {\n \n};\n\n/**\n * Moves the snake.\n @param direction - 'U' = Up, 'L' = Left, 'R' = Right, 'D' = Down \n @return The game's score after the move. Return -1 if game over. \n Game over when snake crosses the screen boundary or bites its body. \n * @param {string} direction\n * @return {number}\n */\nSnakeGame.prototype.move = function(direction) {\n \n};\n\n/** \n * Your SnakeGame object will be instantiated and called as such:\n * var obj = new SnakeGame(width, height, food)\n * var param_1 = obj.move(direction)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class SnakeGame\n\n=begin\n Initialize your data structure here.\n @param width - screen width\n @param height - screen height \n @param food - A list of food positions\n E.g food = [[1,1], [1,0]] means the first food is positioned at [1,1], the second is at [1,0].\n :type width: Integer\n :type height: Integer\n :type food: Integer[][]\n=end\n def initialize(width, height, food)\n \n end\n\n\n=begin\n Moves the snake.\n @param direction - 'U' = Up, 'L' = Left, 'R' = Right, 'D' = Down \n @return The game's score after the move. Return -1 if game over. \n Game over when snake crosses the screen boundary or bites its body.\n :type direction: String\n :rtype: Integer\n=end\n def move(direction)\n \n end\n\n\nend\n\n# Your SnakeGame object will be instantiated and called as such:\n# obj = SnakeGame.new(width, height, food)\n# param_1 = obj.move(direction)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass SnakeGame {\n\n /** Initialize your data structure here.\n @param width - screen width\n @param height - screen height \n @param food - A list of food positions\n E.g food = [[1,1], [1,0]] means the first food is positioned at [1,1], the second is at [1,0]. */\n init(_ width: Int, _ height: Int, _ food: [[Int]]) {\n \n }\n \n /** Moves the snake.\n @param direction - 'U' = Up, 'L' = Left, 'R' = Right, 'D' = Down \n @return The game's score after the move. Return -1 if game over. \n Game over when snake crosses the screen boundary or bites its body. */\n func move(_ direction: String) -> Int {\n \n }\n}\n\n/**\n * Your SnakeGame object will be instantiated and called as such:\n * let obj = SnakeGame(width, height, food)\n * let ret_1: Int = obj.move(direction)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type SnakeGame struct {\n \n}\n\n\n/** Initialize your data structure here.\n @param width - screen width\n @param height - screen height \n @param food - A list of food positions\n E.g food = [[1,1], [1,0]] means the first food is positioned at [1,1], the second is at [1,0]. */\nfunc Constructor(width int, height int, food [][]int) SnakeGame {\n \n}\n\n\n/** Moves the snake.\n @param direction - 'U' = Up, 'L' = Left, 'R' = Right, 'D' = Down \n @return The game's score after the move. Return -1 if game over. \n Game over when snake crosses the screen boundary or bites its body. */\nfunc (this *SnakeGame) Move(direction string) int {\n \n}\n\n\n/**\n * Your SnakeGame object will be instantiated and called as such:\n * obj := Constructor(width, height, food);\n * param_1 := obj.Move(direction);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class SnakeGame(_width: Int, _height: Int, _food: Array[Array[Int]]) {\n\n /** Initialize your data structure here.\n @param width - screen width\n @param height - screen height \n @param food - A list of food positions\n E.g food = [[1,1], [1,0]] means the first food is positioned at [1,1], the second is at [1,0]. */\n \n\n /** Moves the snake.\n @param direction - 'U' = Up, 'L' = Left, 'R' = Right, 'D' = Down \n @return The game's score after the move. Return -1 if game over. \n Game over when snake crosses the screen boundary or bites its body. */\n def move(direction: String): Int = {\n \n }\n\n}\n\n/**\n * Your SnakeGame object will be instantiated and called as such:\n * var obj = new SnakeGame(width, height, food)\n * var param_1 = obj.move(direction)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class SnakeGame(width: Int, height: Int, food: Array) {\n\n /** Initialize your data structure here.\n @param width - screen width\n @param height - screen height \n @param food - A list of food positions\n E.g food = [[1,1], [1,0]] means the first food is positioned at [1,1], the second is at [1,0]. */\n \n\n /** Moves the snake.\n @param direction - 'U' = Up, 'L' = Left, 'R' = Right, 'D' = Down \n @return The game's score after the move. Return -1 if game over. \n Game over when snake crosses the screen boundary or bites its body. */\n fun move(direction: String): Int {\n \n }\n\n}\n\n/**\n * Your SnakeGame object will be instantiated and called as such:\n * var obj = SnakeGame(width, height, food)\n * var param_1 = obj.move(direction)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct SnakeGame {\n\n}\n\n\n/** \n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl SnakeGame {\n\n /** Initialize your data structure here.\n @param width - screen width\n @param height - screen height \n @param food - A list of food positions\n E.g food = [[1,1], [1,0]] means the first food is positioned at [1,1], the second is at [1,0]. */\n fn new(width: i32, height: i32, food: Vec>) -> Self {\n \n }\n \n /** Moves the snake.\n @param direction - 'U' = Up, 'L' = Left, 'R' = Right, 'D' = Down \n @return The game's score after the move. Return -1 if game over. \n Game over when snake crosses the screen boundary or bites its body. */\n fn make_a_move(&self, direction: String) -> i32 {\n \n }\n}\n\n/**\n * Your SnakeGame object will be instantiated and called as such:\n * let obj = SnakeGame::new(width, height, food);\n * let ret_1: i32 = obj.make_a_move(direction);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class SnakeGame {\n /**\n * Initialize your data structure here.\n @param width - screen width\n @param height - screen height \n @param food - A list of food positions\n E.g food = [[1,1], [1,0]] means the first food is positioned at [1,1], the second is at [1,0].\n * @param Integer $width\n * @param Integer $height\n * @param Integer[][] $food\n */\n function __construct($width, $height, $food) {\n \n }\n \n /**\n * Moves the snake.\n @param direction - 'U' = Up, 'L' = Left, 'R' = Right, 'D' = Down \n @return The game's score after the move. Return -1 if game over. \n Game over when snake crosses the screen boundary or bites its body.\n * @param String $direction\n * @return Integer\n */\n function move($direction) {\n \n }\n}\n\n/**\n * Your SnakeGame object will be instantiated and called as such:\n * $obj = SnakeGame($width, $height, $food);\n * $ret_1 = $obj->move($direction);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class SnakeGame {\n /**\n * Initialize your data structure here.\n @param width - screen width\n @param height - screen height \n @param food - A list of food positions\n E.g food = [[1,1], [1,0]] means the first food is positioned at [1,1], the second is at [1,0].\n */\n constructor(width: number, height: number, food: number[][]) {\n\t\t\n }\n\n\t/**\n * Moves the snake.\n @param direction - 'U' = Up, 'L' = Left, 'R' = Right, 'D' = Down \n @return The game's score after the move. Return -1 if game over. \n Game over when snake crosses the screen boundary or bites its body. \n */\n move(direction: string): number {\n\n }\n}\n\n/**\n * Your SnakeGame object will be instantiated and called as such:\n * var obj = new SnakeGame(width, height, food)\n * var param_1 = obj.move(direction)\n */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0353](https://leetcode-cn.com/problems/design-snake-game)", "[\u8d2a\u5403\u86c7](/solution/0300-0399/0353.Design%20Snake%20Game/README.md)", "`\u8bbe\u8ba1`,`\u961f\u5217`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0353](https://leetcode.com/problems/design-snake-game)", "[Design Snake Game](/solution/0300-0399/0353.Design%20Snake%20Game/README_EN.md)", "`Design`,`Queue`", "Medium", "\ud83d\udd12"]}, {"question_id": "0352", "frontend_question_id": "0352", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/data-stream-as-disjoint-intervals", "url_en": "https://leetcode.com/problems/data-stream-as-disjoint-intervals", "relative_path_cn": "/solution/0300-0399/0352.Data%20Stream%20as%20Disjoint%20Intervals/README.md", "relative_path_en": "/solution/0300-0399/0352.Data%20Stream%20as%20Disjoint%20Intervals/README_EN.md", "title_cn": "\u5c06\u6570\u636e\u6d41\u53d8\u4e3a\u591a\u4e2a\u4e0d\u76f8\u4ea4\u533a\u95f4", "title_en": "Data Stream as Disjoint Intervals", "question_title_slug": "data-stream-as-disjoint-intervals", "content_en": "

    Given a data stream input of non-negative integers a1, a2, ..., an, summarize the numbers seen so far as a list of disjoint intervals.

    \n\n

    Implement the SummaryRanges class:

    \n\n
      \n\t
    • SummaryRanges() Initializes the object with an empty stream.
    • \n\t
    • void addNum(int val) Adds the integer val to the stream.
    • \n\t
    • int[][] getIntervals() Returns a summary of the integers in the stream currently as a list of disjoint intervals [starti, endi].
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["SummaryRanges", "addNum", "getIntervals", "addNum", "getIntervals", "addNum", "getIntervals", "addNum", "getIntervals", "addNum", "getIntervals"]\n[[], [1], [], [3], [], [7], [], [2], [], [6], []]\nOutput\n[null, null, [[1, 1]], null, [[1, 1], [3, 3]], null, [[1, 1], [3, 3], [7, 7]], null, [[1, 3], [7, 7]], null, [[1, 3], [6, 7]]]\n\nExplanation\nSummaryRanges summaryRanges = new SummaryRanges();\nsummaryRanges.addNum(1);      // arr = [1]\nsummaryRanges.getIntervals(); // return [[1, 1]]\nsummaryRanges.addNum(3);      // arr = [1, 3]\nsummaryRanges.getIntervals(); // return [[1, 1], [3, 3]]\nsummaryRanges.addNum(7);      // arr = [1, 3, 7]\nsummaryRanges.getIntervals(); // return [[1, 1], [3, 3], [7, 7]]\nsummaryRanges.addNum(2);      // arr = [1, 2, 3, 7]\nsummaryRanges.getIntervals(); // return [[1, 3], [7, 7]]\nsummaryRanges.addNum(6);      // arr = [1, 2, 3, 6, 7]\nsummaryRanges.getIntervals(); // return [[1, 3], [6, 7]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= val <= 104
    • \n\t
    • At most 3 * 104 calls will be made to addNum and getIntervals.
    • \n
    \n\n

     

    \n

    Follow up: What if there are lots of merges and the number of disjoint intervals is small compared to the size of the data stream?

    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\u7684\u6570\u636e\u6d41\u8f93\u5165 a1\uff0ca2\uff0c…\uff0can\uff0c…\uff0c\u5c06\u5230\u76ee\u524d\u4e3a\u6b62\u770b\u5230\u7684\u6570\u5b57\u603b\u7ed3\u4e3a\u4e0d\u76f8\u4ea4\u7684\u533a\u95f4\u5217\u8868\u3002

    \n\n

    \u4f8b\u5982\uff0c\u5047\u8bbe\u6570\u636e\u6d41\u4e2d\u7684\u6574\u6570\u4e3a 1\uff0c3\uff0c7\uff0c2\uff0c6\uff0c…\uff0c\u6bcf\u6b21\u7684\u603b\u7ed3\u4e3a\uff1a

    \n\n
    [1, 1]\n[1, 1], [3, 3]\n[1, 1], [3, 3], [7, 7]\n[1, 3], [7, 7]\n[1, 3], [6, 7]\n
    \n\n

     

    \n\n

    \u8fdb\u9636\uff1a
    \n\u5982\u679c\u6709\u5f88\u591a\u5408\u5e76\uff0c\u5e76\u4e14\u4e0e\u6570\u636e\u6d41\u7684\u5927\u5c0f\u76f8\u6bd4\uff0c\u4e0d\u76f8\u4ea4\u533a\u95f4\u7684\u6570\u91cf\u5f88\u5c0f\uff0c\u8be5\u600e\u4e48\u529e?

    \n\n

    \u63d0\u793a\uff1a
    \n\u7279\u522b\u611f\u8c22 @yunhong \u63d0\u4f9b\u4e86\u672c\u95ee\u9898\u548c\u5176\u6d4b\u8bd5\u7528\u4f8b\u3002

    \n", "tags_en": ["Binary Search", "Ordered Map"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class SummaryRanges {\npublic:\n /** Initialize your data structure here. */\n SummaryRanges() {\n\n }\n \n void addNum(int val) {\n\n }\n \n vector> getIntervals() {\n\n }\n};\n\n/**\n * Your SummaryRanges object will be instantiated and called as such:\n * SummaryRanges* obj = new SummaryRanges();\n * obj->addNum(val);\n * vector> param_2 = obj->getIntervals();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class SummaryRanges {\n\n /** Initialize your data structure here. */\n public SummaryRanges() {\n\n }\n \n public void addNum(int val) {\n\n }\n \n public int[][] getIntervals() {\n\n }\n}\n\n/**\n * Your SummaryRanges object will be instantiated and called as such:\n * SummaryRanges obj = new SummaryRanges();\n * obj.addNum(val);\n * int[][] param_2 = obj.getIntervals();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class SummaryRanges(object):\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def addNum(self, val):\n \"\"\"\n :type val: int\n :rtype: None\n \"\"\"\n\n\n def getIntervals(self):\n \"\"\"\n :rtype: List[List[int]]\n \"\"\"\n\n\n\n# Your SummaryRanges object will be instantiated and called as such:\n# obj = SummaryRanges()\n# obj.addNum(val)\n# param_2 = obj.getIntervals()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class SummaryRanges:\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def addNum(self, val: int) -> None:\n\n\n def getIntervals(self) -> List[List[int]]:\n\n\n\n# Your SummaryRanges object will be instantiated and called as such:\n# obj = SummaryRanges()\n# obj.addNum(val)\n# param_2 = obj.getIntervals()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} SummaryRanges;\n\n/** Initialize your data structure here. */\n\nSummaryRanges* summaryRangesCreate() {\n\n}\n\nvoid summaryRangesAddNum(SummaryRanges* obj, int val) {\n\n}\n\nint** summaryRangesGetIntervals(SummaryRanges* obj, int* retSize, int** retColSize) {\n\n}\n\nvoid summaryRangesFree(SummaryRanges* obj) {\n\n}\n\n/**\n * Your SummaryRanges struct will be instantiated and called as such:\n * SummaryRanges* obj = summaryRangesCreate();\n * summaryRangesAddNum(obj, val);\n \n * int** param_2 = summaryRangesGetIntervals(obj, retSize, retColSize);\n \n * summaryRangesFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class SummaryRanges {\n\n /** Initialize your data structure here. */\n public SummaryRanges() {\n\n }\n \n public void AddNum(int val) {\n\n }\n \n public int[][] GetIntervals() {\n\n }\n}\n\n/**\n * Your SummaryRanges object will be instantiated and called as such:\n * SummaryRanges obj = new SummaryRanges();\n * obj.AddNum(val);\n * int[][] param_2 = obj.GetIntervals();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Initialize your data structure here.\n */\nvar SummaryRanges = function() {\n\n};\n\n/** \n * @param {number} val\n * @return {void}\n */\nSummaryRanges.prototype.addNum = function(val) {\n\n};\n\n/**\n * @return {number[][]}\n */\nSummaryRanges.prototype.getIntervals = function() {\n\n};\n\n/**\n * Your SummaryRanges object will be instantiated and called as such:\n * var obj = new SummaryRanges()\n * obj.addNum(val)\n * var param_2 = obj.getIntervals()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class SummaryRanges\n\n=begin\n Initialize your data structure here.\n=end\n def initialize()\n\n end\n\n\n=begin\n :type val: Integer\n :rtype: Void\n=end\n def add_num(val)\n\n end\n\n\n=begin\n :rtype: Integer[][]\n=end\n def get_intervals()\n\n end\n\n\nend\n\n# Your SummaryRanges object will be instantiated and called as such:\n# obj = SummaryRanges.new()\n# obj.add_num(val)\n# param_2 = obj.get_intervals()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass SummaryRanges {\n\n /** Initialize your data structure here. */\n init() {\n\n }\n \n func addNum(_ val: Int) {\n\n }\n \n func getIntervals() -> [[Int]] {\n\n }\n}\n\n/**\n * Your SummaryRanges object will be instantiated and called as such:\n * let obj = SummaryRanges()\n * obj.addNum(val)\n * let ret_2: [[Int]] = obj.getIntervals()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type SummaryRanges struct {\n\n}\n\n\n/** Initialize your data structure here. */\nfunc Constructor() SummaryRanges {\n\n}\n\n\nfunc (this *SummaryRanges) AddNum(val int) {\n\n}\n\n\nfunc (this *SummaryRanges) GetIntervals() [][]int {\n\n}\n\n\n/**\n * Your SummaryRanges object will be instantiated and called as such:\n * obj := Constructor();\n * obj.AddNum(val);\n * param_2 := obj.GetIntervals();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class SummaryRanges() {\n\n /** Initialize your data structure here. */\n\n\n def addNum(`val`: Int) {\n\n }\n\n def getIntervals(): Array[Array[Int]] = {\n\n }\n\n}\n\n/**\n * Your SummaryRanges object will be instantiated and called as such:\n * var obj = new SummaryRanges()\n * obj.addNum(`val`)\n * var param_2 = obj.getIntervals()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class SummaryRanges() {\n\n /** Initialize your data structure here. */\n\n\n fun addNum(`val`: Int) {\n\n }\n\n fun getIntervals(): Array {\n\n }\n\n}\n\n/**\n * Your SummaryRanges object will be instantiated and called as such:\n * var obj = SummaryRanges()\n * obj.addNum(`val`)\n * var param_2 = obj.getIntervals()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct SummaryRanges {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl SummaryRanges {\n\n /** Initialize your data structure here. */\n fn new() -> Self {\n\n }\n \n fn add_num(&self, val: i32) {\n\n }\n \n fn get_intervals(&self) -> Vec> {\n\n }\n}\n\n/**\n * Your SummaryRanges object will be instantiated and called as such:\n * let obj = SummaryRanges::new();\n * obj.add_num(val);\n * let ret_2: Vec> = obj.get_intervals();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class SummaryRanges {\n /**\n * Initialize your data structure here.\n */\n function __construct() {\n\n }\n\n /**\n * @param Integer $val\n * @return NULL\n */\n function addNum($val) {\n\n }\n\n /**\n * @return Integer[][]\n */\n function getIntervals() {\n\n }\n}\n\n/**\n * Your SummaryRanges object will be instantiated and called as such:\n * $obj = SummaryRanges();\n * $obj->addNum($val);\n * $ret_2 = $obj->getIntervals();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class SummaryRanges {\n constructor() {\n\n }\n\n addNum(val: number): void {\n\n }\n\n getIntervals(): number[][] {\n\n }\n}\n\n/**\n * Your SummaryRanges object will be instantiated and called as such:\n * var obj = new SummaryRanges()\n * obj.addNum(val)\n * var param_2 = obj.getIntervals()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define summary-ranges%\n (class object%\n (super-new)\n (init-field)\n \n ; add-num : exact-integer? -> void?\n (define/public (add-num val)\n\n )\n ; get-intervals : -> (listof (listof exact-integer?))\n (define/public (get-intervals)\n\n )))\n\n;; Your summary-ranges% object will be instantiated and called as such:\n;; (define obj (new summary-ranges%))\n;; (send obj add-num val)\n;; (define param_2 (send obj get-intervals))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0352](https://leetcode-cn.com/problems/data-stream-as-disjoint-intervals)", "[\u5c06\u6570\u636e\u6d41\u53d8\u4e3a\u591a\u4e2a\u4e0d\u76f8\u4ea4\u533a\u95f4](/solution/0300-0399/0352.Data%20Stream%20as%20Disjoint%20Intervals/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u56f0\u96be", ""], "md_table_row_en": ["[0352](https://leetcode.com/problems/data-stream-as-disjoint-intervals)", "[Data Stream as Disjoint Intervals](/solution/0300-0399/0352.Data%20Stream%20as%20Disjoint%20Intervals/README_EN.md)", "`Binary Search`,`Ordered Map`", "Hard", ""]}, {"question_id": "0351", "frontend_question_id": "0351", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/android-unlock-patterns", "url_en": "https://leetcode.com/problems/android-unlock-patterns", "relative_path_cn": "/solution/0300-0399/0351.Android%20Unlock%20Patterns/README.md", "relative_path_en": "/solution/0300-0399/0351.Android%20Unlock%20Patterns/README_EN.md", "title_cn": "\u5b89\u5353\u7cfb\u7edf\u624b\u52bf\u89e3\u9501", "title_en": "Android Unlock Patterns", "question_title_slug": "android-unlock-patterns", "content_en": "

    Android devices have a special lock screen with a 3 x 3 grid of dots. Users can set an "unlock pattern" by connecting the dots in a specific sequence, forming a series of joined line segments where each segment's endpoints are two consecutive dots in the sequence. A sequence of k dots is a valid unlock pattern if both of the following are true:

    \n\n
      \n\t
    • All the dots in the sequence are distinct.
    • \n\t
    • If the line segment connecting two consecutive dots in the sequence passes through any other dot, the other dot must have previously appeared in the sequence. No jumps through non-selected dots are allowed.
    • \n
    \n\n

    Here are some example valid and invalid unlock patterns:

    \n\n

    \n\n
      \n\t
    • The 1st pattern [4,1,3,6] is invalid because the line connecting dots 1 and 3 pass through dot 2, but dot 2 did not previously appear in the sequence.
    • \n\t
    • The 2nd pattern [4,1,9,2] is invalid because the line connecting dots 1 and 9 pass through dot 5, but dot 5 did not previously appear in the sequence.
    • \n\t
    • The 3rd pattern [2,4,1,3,6] is valid because it follows the conditions. The line connecting dots 1 and 3 meets the condition because dot 2 previously appeared in the sequence.
    • \n\t
    • The 4th pattern [6,5,4,1,9,2] is valid because it follows the conditions. The line connecting dots 1 and 9 meets the condition because dot 5 previously appeared in the sequence.
    • \n
    \n\n

    Given two integers m and n, return the number of unique and valid unlock patterns of the Android grid lock screen that consist of at least m keys and at most n keys.

    \n\n

    Two unlock patterns are considered unique if there is a dot in one sequence that is not in the other, or the order of the dots is different.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: m = 1, n = 1\nOutput: 9\n
    \n\n

    Example 2:

    \n\n
    \nInput: m = 1, n = 2\nOutput: 65\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= m, n <= 9
    • \n
    \n", "content_cn": "

    \u6211\u4eec\u90fd\u77e5\u9053\u5b89\u5353\u6709\u4e2a\u624b\u52bf\u89e3\u9501\u7684\u754c\u9762\uff0c\u662f\u4e00\u4e2a\u00a03 x 3 \u7684\u70b9\u6240\u7ed8\u5236\u51fa\u6765\u7684\u7f51\u683c\u3002\u7528\u6237\u53ef\u4ee5\u8bbe\u7f6e\u4e00\u4e2a \u201c\u89e3\u9501\u6a21\u5f0f\u201d \uff0c\u901a\u8fc7\u8fde\u63a5\u7279\u5b9a\u5e8f\u5217\u4e2d\u7684\u70b9\uff0c\u5f62\u6210\u4e00\u7cfb\u5217\u5f7c\u6b64\u8fde\u63a5\u7684\u7ebf\u6bb5\uff0c\u6bcf\u4e2a\u7ebf\u6bb5\u7684\u7aef\u70b9\u90fd\u662f\u5e8f\u5217\u4e2d\u4e24\u4e2a\u8fde\u7eed\u7684\u70b9\u3002\u5982\u679c\u6ee1\u8db3\u4ee5\u4e0b\u4e24\u4e2a\u6761\u4ef6\uff0c\u5219 k \u70b9\u5e8f\u5217\u662f\u6709\u6548\u7684\u89e3\u9501\u6a21\u5f0f\uff1a

    \n\n
      \n\t
    • \u89e3\u9501\u6a21\u5f0f\u4e2d\u7684\u6240\u6709\u70b9 \u4e92\u4e0d\u76f8\u540c \u3002
    • \n\t
    • \u5047\u5982\u6a21\u5f0f\u4e2d\u4e24\u4e2a\u8fde\u7eed\u70b9\u7684\u7ebf\u6bb5\u9700\u8981\u7ecf\u8fc7\u5176\u4ed6\u70b9\uff0c\u90a3\u4e48\u8981\u7ecf\u8fc7\u7684\u70b9\u5fc5\u987b\u4e8b\u5148\u51fa\u73b0\u5728\u5e8f\u5217\u4e2d\uff08\u5df2\u7ecf\u7ecf\u8fc7\uff09\uff0c\u4e0d\u80fd\u8de8\u8fc7\u4efb\u4f55\u8fd8\u672a\u88ab\u7ecf\u8fc7\u7684\u70b9\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u4ee5\u4e0b\u662f\u4e00\u4e9b\u6709\u6548\u548c\u65e0\u6548\u89e3\u9501\u6a21\u5f0f\u7684\u793a\u4f8b\uff1a

    \n\n

    \n\u00a0\n\n
      \n\t
    • \u65e0\u6548\u624b\u52bf\uff1a[4,1,3,6] \uff0c\u8fde\u63a5\u70b9 1 \u548c\u70b9\u00a03 \u65f6\u7ecf\u8fc7\u4e86\u672a\u88ab\u8fde\u63a5\u8fc7\u7684\u00a02 \u53f7\u70b9\u3002
    • \n\t
    • \u65e0\u6548\u624b\u52bf\uff1a[4,1,9,2] \uff0c\u8fde\u63a5\u70b9 1 \u548c\u70b9 9 \u65f6\u7ecf\u8fc7\u4e86\u672a\u88ab\u8fde\u63a5\u8fc7\u7684 5\u00a0\u53f7\u70b9\u3002
    • \n\t
    • \u6709\u6548\u624b\u52bf\uff1a[2,4,1,3,6] \uff0c\u8fde\u63a5\u70b9 1 \u548c\u70b9\u00a03 \u662f\u6709\u6548\u7684\uff0c\u56e0\u4e3a\u867d\u7136\u5b83\u7ecf\u8fc7\u4e86\u70b9\u00a02 \uff0c\u4f46\u662f\u70b9 2 \u5728\u8be5\u624b\u52bf\u4e2d\u4e4b\u524d\u5df2\u7ecf\u88ab\u8fde\u8fc7\u4e86\u3002
    • \n\t
    • \u6709\u6548\u624b\u52bf\uff1a[6,5,4,1,9,2] \uff0c\u8fde\u63a5\u70b9 1 \u548c\u70b9\u00a09 \u662f\u6709\u6548\u7684\uff0c\u56e0\u4e3a\u867d\u7136\u5b83\u7ecf\u8fc7\u4e86\u6309\u952e 5 \uff0c\u4f46\u662f\u70b9\u00a05 \u5728\u8be5\u624b\u52bf\u4e2d\u4e4b\u524d\u5df2\u7ecf\u88ab\u8fde\u8fc7\u4e86\u3002
    • \n
    \n\n

    \u7ed9\u4f60\u4e24\u4e2a\u6574\u6570\uff0c\u5206\u522b\u4e3a \u200b\u200bm \u548c n \uff0c\u90a3\u4e48\u8bf7\u4f60\u7edf\u8ba1\u4e00\u4e0b\u6709\u591a\u5c11\u79cd \u4e0d\u540c\u4e14\u6709\u6548\u7684\u89e3\u9501\u6a21\u5f0f \uff0c\u662f \u81f3\u5c11 \u9700\u8981\u7ecf\u8fc7 m \u4e2a\u70b9\uff0c\u4f46\u662f \u4e0d\u8d85\u8fc7 n \u4e2a\u70b9\u7684\u3002

    \n\n

    \u4e24\u4e2a\u89e3\u9501\u6a21\u5f0f \u4e0d\u540c \u9700\u6ee1\u8db3\uff1a\u7ecf\u8fc7\u7684\u70b9\u4e0d\u540c\u6216\u8005\u7ecf\u8fc7\u70b9\u7684\u987a\u5e8f\u4e0d\u540c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1am = 1, n = 1\n\u8f93\u51fa\uff1a9\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1am = 1, n = 2\n\u8f93\u51fa\uff1a65\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= m, n <= 9
    • \n
    \n", "tags_en": ["Dynamic Programming", "Backtracking"], "tags_cn": ["\u52a8\u6001\u89c4\u5212", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numberOfPatterns(int m, int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numberOfPatterns(int m, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numberOfPatterns(self, m, n):\n \"\"\"\n :type m: int\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numberOfPatterns(self, m: int, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numberOfPatterns(int m, int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumberOfPatterns(int m, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} m\n * @param {number} n\n * @return {number}\n */\nvar numberOfPatterns = function(m, n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} m\n# @param {Integer} n\n# @return {Integer}\ndef number_of_patterns(m, n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numberOfPatterns(_ m: Int, _ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numberOfPatterns(m int, n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numberOfPatterns(m: Int, n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numberOfPatterns(m: Int, n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn number_of_patterns(m: i32, n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $m\n * @param Integer $n\n * @return Integer\n */\n function numberOfPatterns($m, $n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numberOfPatterns(m: number, n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (number-of-patterns m n)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0351](https://leetcode-cn.com/problems/android-unlock-patterns)", "[\u5b89\u5353\u7cfb\u7edf\u624b\u52bf\u89e3\u9501](/solution/0300-0399/0351.Android%20Unlock%20Patterns/README.md)", "`\u52a8\u6001\u89c4\u5212`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0351](https://leetcode.com/problems/android-unlock-patterns)", "[Android Unlock Patterns](/solution/0300-0399/0351.Android%20Unlock%20Patterns/README_EN.md)", "`Dynamic Programming`,`Backtracking`", "Medium", "\ud83d\udd12"]}, {"question_id": "0350", "frontend_question_id": "0350", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/intersection-of-two-arrays-ii", "url_en": "https://leetcode.com/problems/intersection-of-two-arrays-ii", "relative_path_cn": "/solution/0300-0399/0350.Intersection%20of%20Two%20Arrays%20II/README.md", "relative_path_en": "/solution/0300-0399/0350.Intersection%20of%20Two%20Arrays%20II/README_EN.md", "title_cn": "\u4e24\u4e2a\u6570\u7ec4\u7684\u4ea4\u96c6 II", "title_en": "Intersection of Two Arrays II", "question_title_slug": "intersection-of-two-arrays-ii", "content_en": "

    Given two integer arrays nums1 and nums2, return an array of their intersection. Each element in the result must appear as many times as it shows in both arrays and you may return the result in any order.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums1 = [1,2,2,1], nums2 = [2,2]\nOutput: [2,2]\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums1 = [4,9,5], nums2 = [9,4,9,8,4]\nOutput: [4,9]\nExplanation: [9,4] is also accepted.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums1.length, nums2.length <= 1000
    • \n\t
    • 0 <= nums1[i], nums2[i] <= 1000
    • \n
    \n\n

     

    \n

    Follow up:

    \n\n
      \n\t
    • What if the given array is already sorted? How would you optimize your algorithm?
    • \n\t
    • What if nums1's size is small compared to nums2's size? Which algorithm is better?
    • \n\t
    • What if elements of nums2 are stored on disk, and the memory is limited such that you cannot load all elements into the memory at once?
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u6570\u7ec4\uff0c\u7f16\u5199\u4e00\u4e2a\u51fd\u6570\u6765\u8ba1\u7b97\u5b83\u4eec\u7684\u4ea4\u96c6\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anums1 = [1,2,2,1], nums2 = [2,2]\n\u8f93\u51fa\uff1a[2,2]\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165\uff1anums1 = [4,9,5], nums2 = [9,4,9,8,4]\n\u8f93\u51fa\uff1a[4,9]
    \n\n

     

    \n\n

    \u8bf4\u660e\uff1a

    \n\n
      \n\t
    • \u8f93\u51fa\u7ed3\u679c\u4e2d\u6bcf\u4e2a\u5143\u7d20\u51fa\u73b0\u7684\u6b21\u6570\uff0c\u5e94\u4e0e\u5143\u7d20\u5728\u4e24\u4e2a\u6570\u7ec4\u4e2d\u51fa\u73b0\u6b21\u6570\u7684\u6700\u5c0f\u503c\u4e00\u81f4\u3002
    • \n\t
    • \u6211\u4eec\u53ef\u4ee5\u4e0d\u8003\u8651\u8f93\u51fa\u7ed3\u679c\u7684\u987a\u5e8f\u3002
    • \n
    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u5982\u679c\u7ed9\u5b9a\u7684\u6570\u7ec4\u5df2\u7ecf\u6392\u597d\u5e8f\u5462\uff1f\u4f60\u5c06\u5982\u4f55\u4f18\u5316\u4f60\u7684\u7b97\u6cd5\uff1f
    • \n\t
    • \u5982\u679c nums1 \u7684\u5927\u5c0f\u6bd4 nums2 \u5c0f\u5f88\u591a\uff0c\u54ea\u79cd\u65b9\u6cd5\u66f4\u4f18\uff1f
    • \n\t
    • \u5982\u679c nums2 \u7684\u5143\u7d20\u5b58\u50a8\u5728\u78c1\u76d8\u4e0a\uff0c\u5185\u5b58\u662f\u6709\u9650\u7684\uff0c\u5e76\u4e14\u4f60\u4e0d\u80fd\u4e00\u6b21\u52a0\u8f7d\u6240\u6709\u7684\u5143\u7d20\u5230\u5185\u5b58\u4e2d\uff0c\u4f60\u8be5\u600e\u4e48\u529e\uff1f
    • \n
    \n", "tags_en": ["Sort", "Hash Table", "Two Pointers", "Binary Search"], "tags_cn": ["\u6392\u5e8f", "\u54c8\u5e0c\u8868", "\u53cc\u6307\u9488", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector intersect(vector& nums1, vector& nums2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] intersect(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def intersect(self, nums1, nums2):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def intersect(self, nums1: List[int], nums2: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* intersect(int* nums1, int nums1Size, int* nums2, int nums2Size, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] Intersect(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums1\n * @param {number[]} nums2\n * @return {number[]}\n */\nvar intersect = function(nums1, nums2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums1\n# @param {Integer[]} nums2\n# @return {Integer[]}\ndef intersect(nums1, nums2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func intersect(_ nums1: [Int], _ nums2: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func intersect(nums1 []int, nums2 []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def intersect(nums1: Array[Int], nums2: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun intersect(nums1: IntArray, nums2: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn intersect(nums1: Vec, nums2: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums1\n * @param Integer[] $nums2\n * @return Integer[]\n */\n function intersect($nums1, $nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function intersect(nums1: number[], nums2: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (intersect nums1 nums2)\n (-> (listof exact-integer?) (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0350](https://leetcode-cn.com/problems/intersection-of-two-arrays-ii)", "[\u4e24\u4e2a\u6570\u7ec4\u7684\u4ea4\u96c6 II](/solution/0300-0399/0350.Intersection%20of%20Two%20Arrays%20II/README.md)", "`\u6392\u5e8f`,`\u54c8\u5e0c\u8868`,`\u53cc\u6307\u9488`,`\u4e8c\u5206\u67e5\u627e`", "\u7b80\u5355", ""], "md_table_row_en": ["[0350](https://leetcode.com/problems/intersection-of-two-arrays-ii)", "[Intersection of Two Arrays II](/solution/0300-0399/0350.Intersection%20of%20Two%20Arrays%20II/README_EN.md)", "`Sort`,`Hash Table`,`Two Pointers`,`Binary Search`", "Easy", ""]}, {"question_id": "0349", "frontend_question_id": "0349", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/intersection-of-two-arrays", "url_en": "https://leetcode.com/problems/intersection-of-two-arrays", "relative_path_cn": "/solution/0300-0399/0349.Intersection%20of%20Two%20Arrays/README.md", "relative_path_en": "/solution/0300-0399/0349.Intersection%20of%20Two%20Arrays/README_EN.md", "title_cn": "\u4e24\u4e2a\u6570\u7ec4\u7684\u4ea4\u96c6", "title_en": "Intersection of Two Arrays", "question_title_slug": "intersection-of-two-arrays", "content_en": "

    Given two integer arrays nums1 and nums2, return an array of their intersection. Each element in the result must be unique and you may return the result in any order.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums1 = [1,2,2,1], nums2 = [2,2]\nOutput: [2]\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums1 = [4,9,5], nums2 = [9,4,9,8,4]\nOutput: [9,4]\nExplanation: [4,9] is also accepted.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums1.length, nums2.length <= 1000
    • \n\t
    • 0 <= nums1[i], nums2[i] <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u6570\u7ec4\uff0c\u7f16\u5199\u4e00\u4e2a\u51fd\u6570\u6765\u8ba1\u7b97\u5b83\u4eec\u7684\u4ea4\u96c6\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anums1 = [1,2,2,1], nums2 = [2,2]\n\u8f93\u51fa\uff1a[2]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anums1 = [4,9,5], nums2 = [9,4,9,8,4]\n\u8f93\u51fa\uff1a[9,4]
    \n\n

     

    \n\n

    \u8bf4\u660e\uff1a

    \n\n
      \n\t
    • \u8f93\u51fa\u7ed3\u679c\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u4e00\u5b9a\u662f\u552f\u4e00\u7684\u3002
    • \n\t
    • \u6211\u4eec\u53ef\u4ee5\u4e0d\u8003\u8651\u8f93\u51fa\u7ed3\u679c\u7684\u987a\u5e8f\u3002
    • \n
    \n", "tags_en": ["Sort", "Hash Table", "Two Pointers", "Binary Search"], "tags_cn": ["\u6392\u5e8f", "\u54c8\u5e0c\u8868", "\u53cc\u6307\u9488", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector intersection(vector& nums1, vector& nums2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] intersection(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def intersection(self, nums1, nums2):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def intersection(self, nums1: List[int], nums2: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* intersection(int* nums1, int nums1Size, int* nums2, int nums2Size, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] Intersection(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums1\n * @param {number[]} nums2\n * @return {number[]}\n */\nvar intersection = function(nums1, nums2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums1\n# @param {Integer[]} nums2\n# @return {Integer[]}\ndef intersection(nums1, nums2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func intersection(_ nums1: [Int], _ nums2: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func intersection(nums1 []int, nums2 []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def intersection(nums1: Array[Int], nums2: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun intersection(nums1: IntArray, nums2: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn intersection(nums1: Vec, nums2: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums1\n * @param Integer[] $nums2\n * @return Integer[]\n */\n function intersection($nums1, $nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function intersection(nums1: number[], nums2: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (intersection nums1 nums2)\n (-> (listof exact-integer?) (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0349](https://leetcode-cn.com/problems/intersection-of-two-arrays)", "[\u4e24\u4e2a\u6570\u7ec4\u7684\u4ea4\u96c6](/solution/0300-0399/0349.Intersection%20of%20Two%20Arrays/README.md)", "`\u6392\u5e8f`,`\u54c8\u5e0c\u8868`,`\u53cc\u6307\u9488`,`\u4e8c\u5206\u67e5\u627e`", "\u7b80\u5355", ""], "md_table_row_en": ["[0349](https://leetcode.com/problems/intersection-of-two-arrays)", "[Intersection of Two Arrays](/solution/0300-0399/0349.Intersection%20of%20Two%20Arrays/README_EN.md)", "`Sort`,`Hash Table`,`Two Pointers`,`Binary Search`", "Easy", ""]}, {"question_id": "0348", "frontend_question_id": "0348", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/design-tic-tac-toe", "url_en": "https://leetcode.com/problems/design-tic-tac-toe", "relative_path_cn": "/solution/0300-0399/0348.Design%20Tic-Tac-Toe/README.md", "relative_path_en": "/solution/0300-0399/0348.Design%20Tic-Tac-Toe/README_EN.md", "title_cn": "\u8bbe\u8ba1\u4e95\u5b57\u68cb", "title_en": "Design Tic-Tac-Toe", "question_title_slug": "design-tic-tac-toe", "content_en": "

    Assume the following rules are for the tic-tac-toe game on an n x n board between two players:

    \n\n
      \n\t
    1. A move is guaranteed to be valid and is placed on an empty block.
    2. \n\t
    3. Once a winning condition is reached, no more moves are allowed.
    4. \n\t
    5. A player who succeeds in placing n of their marks in a horizontal, vertical, or diagonal row wins the game.
    6. \n
    \n\n

    Implement the TicTacToe class:

    \n\n
      \n\t
    • TicTacToe(int n) Initializes the object the size of the board n.
    • \n\t
    • int move(int row, int col, int player) Indicates that player with id player plays at the cell (row, col) of the board. The move is guaranteed to be a valid move.
    • \n
    \n\n

    Follow up:
    \nCould you do better than O(n2) per move() operation?

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["TicTacToe", "move", "move", "move", "move", "move", "move", "move"]\n[[3], [0, 0, 1], [0, 2, 2], [2, 2, 1], [1, 1, 2], [2, 0, 1], [1, 0, 2], [2, 1, 1]]\nOutput\n[null, 0, 0, 0, 0, 0, 0, 1]\n\nExplanation\nTicTacToe ticTacToe = new TicTacToe(3);\nAssume that player 1 is "X" and player 2 is "O" in the board.\nticTacToe.move(0, 0, 1); // return 0 (no one wins)\n|X| | |\n| | | |    // Player 1 makes a move at (0, 0).\n| | | |\n\nticTacToe.move(0, 2, 2); // return 0 (no one wins)\n|X| |O|\n| | | |    // Player 2 makes a move at (0, 2).\n| | | |\n\nticTacToe.move(2, 2, 1); // return 0 (no one wins)\n|X| |O|\n| | | |    // Player 1 makes a move at (2, 2).\n| | |X|\n\nticTacToe.move(1, 1, 2); // return 0 (no one wins)\n|X| |O|\n| |O| |    // Player 2 makes a move at (1, 1).\n| | |X|\n\nticTacToe.move(2, 0, 1); // return 0 (no one wins)\n|X| |O|\n| |O| |    // Player 1 makes a move at (2, 0).\n|X| |X|\n\nticTacToe.move(1, 0, 2); // return 0 (no one wins)\n|X| |O|\n|O|O| |    // Player 2 makes a move at (1, 0).\n|X| |X|\n\nticTacToe.move(2, 1, 1); // return 1 (player 1 wins)\n|X| |O|\n|O|O| |    // Player 1 makes a move at (2, 1).\n|X|X|X|\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= n <= 100
    • \n\t
    • player is 1 or 2.
    • \n\t
    • 0 <= row, col < n
    • \n\t
    • (row, col) are unique for each different call to move.
    • \n\t
    • At most n2 calls will be made to move.
    • \n
    \n", "content_cn": "

    \u8bf7\u5728 n × n \u7684\u68cb\u76d8\u4e0a\uff0c\u5b9e\u73b0\u4e00\u4e2a\u5224\u5b9a\u4e95\u5b57\u68cb\uff08Tic-Tac-Toe\uff09\u80dc\u8d1f\u7684\u795e\u5668\uff0c\u5224\u65ad\u6bcf\u4e00\u6b21\u73a9\u5bb6\u843d\u5b50\u540e\uff0c\u662f\u5426\u6709\u80dc\u51fa\u7684\u73a9\u5bb6\u3002

    \n\n

    \u5728\u8fd9\u4e2a\u4e95\u5b57\u68cb\u6e38\u620f\u4e2d\uff0c\u4f1a\u6709 2 \u540d\u73a9\u5bb6\uff0c\u4ed6\u4eec\u5c06\u8f6e\u6d41\u5728\u68cb\u76d8\u4e0a\u653e\u7f6e\u81ea\u5df1\u7684\u68cb\u5b50\u3002

    \n\n

    \u5728\u5b9e\u73b0\u8fd9\u4e2a\u5224\u5b9a\u5668\u7684\u8fc7\u7a0b\u4e2d\uff0c\u4f60\u53ef\u4ee5\u5047\u8bbe\u4ee5\u4e0b\u8fd9\u4e9b\u89c4\u5219\u4e00\u5b9a\u6210\u7acb\uff1a

    \n\n

          1. \u6bcf\u4e00\u6b65\u68cb\u90fd\u662f\u5728\u68cb\u76d8\u5185\u7684\uff0c\u5e76\u4e14\u53ea\u80fd\u88ab\u653e\u7f6e\u5728\u4e00\u4e2a\u7a7a\u7684\u683c\u5b50\u91cc\uff1b

    \n\n

          2. \u4e00\u65e6\u6e38\u620f\u4e2d\u6709\u4e00\u540d\u73a9\u5bb6\u80dc\u51fa\u7684\u8bdd\uff0c\u6e38\u620f\u5c06\u4e0d\u80fd\u518d\u7ee7\u7eed\uff1b

    \n\n

          3. \u4e00\u4e2a\u73a9\u5bb6\u5982\u679c\u5728\u540c\u4e00\u884c\u3001\u540c\u4e00\u5217\u6216\u8005\u540c\u4e00\u659c\u5bf9\u89d2\u7ebf\u4e0a\u90fd\u653e\u7f6e\u4e86\u81ea\u5df1\u7684\u68cb\u5b50\uff0c\u90a3\u4e48\u4ed6\u4fbf\u83b7\u5f97\u80dc\u5229\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u7ed9\u5b9a\u68cb\u76d8\u8fb9\u957f n = 3, \u73a9\u5bb6 1 \u7684\u68cb\u5b50\u7b26\u53f7\u662f "X"\uff0c\u73a9\u5bb6 2 \u7684\u68cb\u5b50\u7b26\u53f7\u662f "O"\u3002\n\nTicTacToe toe = new TicTacToe(3);\n\ntoe.move(0, 0, 1); -> \u51fd\u6570\u8fd4\u56de 0 (\u6b64\u65f6\uff0c\u6682\u65f6\u6ca1\u6709\u73a9\u5bb6\u8d62\u5f97\u8fd9\u573a\u5bf9\u51b3)\n|X| | |\n| | | |    // \u73a9\u5bb6 1 \u5728 (0, 0) \u843d\u5b50\u3002\n| | | |\n\ntoe.move(0, 2, 2); -> \u51fd\u6570\u8fd4\u56de 0 (\u6682\u65f6\u6ca1\u6709\u73a9\u5bb6\u8d62\u5f97\u672c\u573a\u6bd4\u8d5b)\n|X| |O|\n| | | |    // \u73a9\u5bb6 2 \u5728 (0, 2) \u843d\u5b50\u3002\n| | | |\n\ntoe.move(2, 2, 1); -> \u51fd\u6570\u8fd4\u56de 0 (\u6682\u65f6\u6ca1\u6709\u73a9\u5bb6\u8d62\u5f97\u6bd4\u8d5b)\n|X| |O|\n| | | |    // \u73a9\u5bb6 1 \u5728 (2, 2) \u843d\u5b50\u3002\n| | |X|\n\ntoe.move(1, 1, 2); -> \u51fd\u6570\u8fd4\u56de 0 (\u6682\u6ca1\u6709\u73a9\u5bb6\u8d62\u5f97\u6bd4\u8d5b)\n|X| |O|\n| |O| |    // \u73a9\u5bb6 2 \u5728 (1, 1) \u843d\u5b50\u3002\n| | |X|\n\ntoe.move(2, 0, 1); -> \u51fd\u6570\u8fd4\u56de 0 (\u6682\u65e0\u73a9\u5bb6\u8d62\u5f97\u6bd4\u8d5b)\n|X| |O|\n| |O| |    // \u73a9\u5bb6 1 \u5728 (2, 0) \u843d\u5b50\u3002\n|X| |X|\n\ntoe.move(1, 0, 2); -> \u51fd\u6570\u8fd4\u56de 0 (\u6ca1\u6709\u73a9\u5bb6\u8d62\u5f97\u6bd4\u8d5b)\n|X| |O|\n|O|O| |    // \u73a9\u5bb6 2 \u5728 (1, 0) \u843d\u5b50.\n|X| |X|\n\ntoe.move(2, 1, 1); -> \u51fd\u6570\u8fd4\u56de 1 (\u6b64\u65f6\uff0c\u73a9\u5bb6 1 \u8d62\u5f97\u4e86\u8be5\u573a\u6bd4\u8d5b)\n|X| |O|\n|O|O| |    // \u73a9\u5bb6 1 \u5728 (2, 1) \u843d\u5b50\u3002\n|X|X|X|\n
    \n\n

     

    \n\n

    \u8fdb\u9636:
    \n\u60a8\u6709\u6ca1\u6709\u53ef\u80fd\u5c06\u6bcf\u4e00\u6b65\u7684 move() \u64cd\u4f5c\u4f18\u5316\u5230\u6bd4 O(n2) \u66f4\u5feb\u5417?

    \n", "tags_en": ["Design"], "tags_cn": ["\u8bbe\u8ba1"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class TicTacToe {\npublic:\n /** Initialize your data structure here. */\n TicTacToe(int n) {\n \n }\n \n /** Player {player} makes a move at ({row}, {col}).\n @param row The row of the board.\n @param col The column of the board.\n @param player The player, can be either 1 or 2.\n @return The current winning condition, can be either:\n 0: No one wins.\n 1: Player 1 wins.\n 2: Player 2 wins. */\n int move(int row, int col, int player) {\n \n }\n};\n\n/**\n * Your TicTacToe object will be instantiated and called as such:\n * TicTacToe* obj = new TicTacToe(n);\n * int param_1 = obj->move(row,col,player);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class TicTacToe {\n\n /** Initialize your data structure here. */\n public TicTacToe(int n) {\n \n }\n \n /** Player {player} makes a move at ({row}, {col}).\n @param row The row of the board.\n @param col The column of the board.\n @param player The player, can be either 1 or 2.\n @return The current winning condition, can be either:\n 0: No one wins.\n 1: Player 1 wins.\n 2: Player 2 wins. */\n public int move(int row, int col, int player) {\n \n }\n}\n\n/**\n * Your TicTacToe object will be instantiated and called as such:\n * TicTacToe obj = new TicTacToe(n);\n * int param_1 = obj.move(row,col,player);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class TicTacToe(object):\n\n def __init__(self, n):\n \"\"\"\n Initialize your data structure here.\n :type n: int\n \"\"\"\n \n\n def move(self, row, col, player):\n \"\"\"\n Player {player} makes a move at ({row}, {col}).\n @param row The row of the board.\n @param col The column of the board.\n @param player The player, can be either 1 or 2.\n @return The current winning condition, can be either:\n 0: No one wins.\n 1: Player 1 wins.\n 2: Player 2 wins.\n :type row: int\n :type col: int\n :type player: int\n :rtype: int\n \"\"\"\n \n\n\n# Your TicTacToe object will be instantiated and called as such:\n# obj = TicTacToe(n)\n# param_1 = obj.move(row,col,player)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class TicTacToe:\n\n def __init__(self, n: int):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n \n\n def move(self, row: int, col: int, player: int) -> int:\n \"\"\"\n Player {player} makes a move at ({row}, {col}).\n @param row The row of the board.\n @param col The column of the board.\n @param player The player, can be either 1 or 2.\n @return The current winning condition, can be either:\n 0: No one wins.\n 1: Player 1 wins.\n 2: Player 2 wins.\n \"\"\"\n \n\n\n# Your TicTacToe object will be instantiated and called as such:\n# obj = TicTacToe(n)\n# param_1 = obj.move(row,col,player)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} TicTacToe;\n\n/** Initialize your data structure here. */\n\nTicTacToe* ticTacToeCreate(int n) {\n \n}\n\n/** Player {player} makes a move at ({row}, {col}).\n @param row The row of the board.\n @param col The column of the board.\n @param player The player, can be either 1 or 2.\n @return The current winning condition, can be either:\n 0: No one wins.\n 1: Player 1 wins.\n 2: Player 2 wins. */\nint ticTacToeMove(TicTacToe* obj, int row, int col, int player) {\n \n}\n\nvoid ticTacToeFree(TicTacToe* obj) {\n \n}\n\n/**\n * Your TicTacToe struct will be instantiated and called as such:\n * TicTacToe* obj = ticTacToeCreate(n);\n * int param_1 = ticTacToeMove(obj, row, col, player);\n \n * ticTacToeFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class TicTacToe {\n\n /** Initialize your data structure here. */\n public TicTacToe(int n) {\n \n }\n \n /** Player {player} makes a move at ({row}, {col}).\n @param row The row of the board.\n @param col The column of the board.\n @param player The player, can be either 1 or 2.\n @return The current winning condition, can be either:\n 0: No one wins.\n 1: Player 1 wins.\n 2: Player 2 wins. */\n public int Move(int row, int col, int player) {\n \n }\n}\n\n/**\n * Your TicTacToe object will be instantiated and called as such:\n * TicTacToe obj = new TicTacToe(n);\n * int param_1 = obj.Move(row,col,player);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Initialize your data structure here.\n * @param {number} n\n */\nvar TicTacToe = function(n) {\n \n};\n\n/**\n * Player {player} makes a move at ({row}, {col}).\n @param row The row of the board.\n @param col The column of the board.\n @param player The player, can be either 1 or 2.\n @return The current winning condition, can be either:\n 0: No one wins.\n 1: Player 1 wins.\n 2: Player 2 wins. \n * @param {number} row \n * @param {number} col \n * @param {number} player\n * @return {number}\n */\nTicTacToe.prototype.move = function(row, col, player) {\n \n};\n\n/** \n * Your TicTacToe object will be instantiated and called as such:\n * var obj = new TicTacToe(n)\n * var param_1 = obj.move(row,col,player)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class TicTacToe\n\n=begin\n Initialize your data structure here.\n :type n: Integer\n=end\n def initialize(n)\n \n end\n\n\n=begin\n Player {player} makes a move at ({row}, {col}).\n @param row The row of the board.\n @param col The column of the board.\n @param player The player, can be either 1 or 2.\n @return The current winning condition, can be either:\n 0: No one wins.\n 1: Player 1 wins.\n 2: Player 2 wins.\n :type row: Integer\n :type col: Integer\n :type player: Integer\n :rtype: Integer\n=end\n def move(row, col, player)\n \n end\n\n\nend\n\n# Your TicTacToe object will be instantiated and called as such:\n# obj = TicTacToe.new(n)\n# param_1 = obj.move(row, col, player)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass TicTacToe {\n\n /** Initialize your data structure here. */\n init(_ n: Int) {\n \n }\n \n /** Player {player} makes a move at ({row}, {col}).\n @param row The row of the board.\n @param col The column of the board.\n @param player The player, can be either 1 or 2.\n @return The current winning condition, can be either:\n 0: No one wins.\n 1: Player 1 wins.\n 2: Player 2 wins. */\n func move(_ row: Int, _ col: Int, _ player: Int) -> Int {\n \n }\n}\n\n/**\n * Your TicTacToe object will be instantiated and called as such:\n * let obj = TicTacToe(n)\n * let ret_1: Int = obj.move(row, col, player)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type TicTacToe struct {\n \n}\n\n\n/** Initialize your data structure here. */\nfunc Constructor(n int) TicTacToe {\n \n}\n\n\n/** Player {player} makes a move at ({row}, {col}).\n @param row The row of the board.\n @param col The column of the board.\n @param player The player, can be either 1 or 2.\n @return The current winning condition, can be either:\n 0: No one wins.\n 1: Player 1 wins.\n 2: Player 2 wins. */\nfunc (this *TicTacToe) Move(row int, col int, player int) int {\n \n}\n\n\n/**\n * Your TicTacToe object will be instantiated and called as such:\n * obj := Constructor(n);\n * param_1 := obj.Move(row,col,player);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class TicTacToe(_n: Int) {\n\n /** Initialize your data structure here. */\n \n\n /** Player {player} makes a move at ({row}, {col}).\n @param row The row of the board.\n @param col The column of the board.\n @param player The player, can be either 1 or 2.\n @return The current winning condition, can be either:\n 0: No one wins.\n 1: Player 1 wins.\n 2: Player 2 wins. */\n def move(row: Int, col: Int, player: Int): Int = {\n \n }\n\n}\n\n/**\n * Your TicTacToe object will be instantiated and called as such:\n * var obj = new TicTacToe(n)\n * var param_1 = obj.move(row,col,player)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class TicTacToe(n: Int) {\n\n /** Initialize your data structure here. */\n \n\n /** Player {player} makes a move at ({row}, {col}).\n @param row The row of the board.\n @param col The column of the board.\n @param player The player, can be either 1 or 2.\n @return The current winning condition, can be either:\n 0: No one wins.\n 1: Player 1 wins.\n 2: Player 2 wins. */\n fun move(row: Int, col: Int, player: Int): Int {\n \n }\n\n}\n\n/**\n * Your TicTacToe object will be instantiated and called as such:\n * var obj = TicTacToe(n)\n * var param_1 = obj.move(row,col,player)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct TicTacToe {\n\n}\n\n\n/** \n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl TicTacToe {\n\n /** Initialize your data structure here. */\n fn new(n: i32) -> Self {\n \n }\n \n /** Player {player} makes a move at ({row}, {col}).\n @param row The row of the board.\n @param col The column of the board.\n @param player The player, can be either 1 or 2.\n @return The current winning condition, can be either:\n 0: No one wins.\n 1: Player 1 wins.\n 2: Player 2 wins. */\n fn make_a_move(&self, row: i32, col: i32, player: i32) -> i32 {\n \n }\n}\n\n/**\n * Your TicTacToe object will be instantiated and called as such:\n * let obj = TicTacToe::new(n);\n * let ret_1: i32 = obj.make_a_move(row, col, player);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class TicTacToe {\n /**\n * Initialize your data structure here.\n * @param Integer $n\n */\n function __construct($n) {\n \n }\n \n /**\n * Player {player} makes a move at ({row}, {col}).\n @param row The row of the board.\n @param col The column of the board.\n @param player The player, can be either 1 or 2.\n @return The current winning condition, can be either:\n 0: No one wins.\n 1: Player 1 wins.\n 2: Player 2 wins.\n * @param Integer $row\n * @param Integer $col\n * @param Integer $player\n * @return Integer\n */\n function move($row, $col, $player) {\n \n }\n}\n\n/**\n * Your TicTacToe object will be instantiated and called as such:\n * $obj = TicTacToe($n);\n * $ret_1 = $obj->move($row, $col, $player);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class TicTacToe {\n /**\n * Initialize your data structure here.\n */\n constructor(n: number) {\n\t\t\n }\n\t\n /**\n * Player {player} makes a move at ({row}, {col}).\n @param row The row of the board.\n @param col The column of the board.\n @param player The player, can be either 1 or 2.\n @return The current winning condition, can be either:\n 0: No one wins.\n 1: Player 1 wins.\n 2: Player 2 wins. \n */\n move(row: number, col: number, player: number): number {\n\t\t\n }\n}\n\n/**\n * Your TicTacToe object will be instantiated and called as such:\n * var obj = new TicTacToe(n)\n * var param_1 = obj.move(row,col,player)\n */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0348](https://leetcode-cn.com/problems/design-tic-tac-toe)", "[\u8bbe\u8ba1\u4e95\u5b57\u68cb](/solution/0300-0399/0348.Design%20Tic-Tac-Toe/README.md)", "`\u8bbe\u8ba1`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0348](https://leetcode.com/problems/design-tic-tac-toe)", "[Design Tic-Tac-Toe](/solution/0300-0399/0348.Design%20Tic-Tac-Toe/README_EN.md)", "`Design`", "Medium", "\ud83d\udd12"]}, {"question_id": "0347", "frontend_question_id": "0347", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/top-k-frequent-elements", "url_en": "https://leetcode.com/problems/top-k-frequent-elements", "relative_path_cn": "/solution/0300-0399/0347.Top%20K%20Frequent%20Elements/README.md", "relative_path_en": "/solution/0300-0399/0347.Top%20K%20Frequent%20Elements/README_EN.md", "title_cn": "\u524d K \u4e2a\u9ad8\u9891\u5143\u7d20", "title_en": "Top K Frequent Elements", "question_title_slug": "top-k-frequent-elements", "content_en": "

    Given an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any order.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [1,1,1,2,2,3], k = 2\nOutput: [1,2]\n

    Example 2:

    \n
    Input: nums = [1], k = 1\nOutput: [1]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • k is in the range [1, the number of unique elements in the array].
    • \n\t
    • It is guaranteed that the answer is unique.
    • \n
    \n\n

     

    \n

    Follow up: Your algorithm's time complexity must be better than O(n log n), where n is the array's size.

    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \u548c\u4e00\u4e2a\u6574\u6570 k \uff0c\u8bf7\u4f60\u8fd4\u56de\u5176\u4e2d\u51fa\u73b0\u9891\u7387\u524d k \u9ad8\u7684\u5143\u7d20\u3002\u4f60\u53ef\u4ee5\u6309 \u4efb\u610f\u987a\u5e8f \u8fd4\u56de\u7b54\u6848\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: nums = [1,1,1,2,2,3], k = 2\n\u8f93\u51fa: [1,2]\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: nums = [1], k = 1\n\u8f93\u51fa: [1]
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • k \u7684\u53d6\u503c\u8303\u56f4\u662f [1, \u6570\u7ec4\u4e2d\u4e0d\u76f8\u540c\u7684\u5143\u7d20\u7684\u4e2a\u6570]
    • \n\t
    • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u7b54\u6848\u552f\u4e00\uff0c\u6362\u53e5\u8bdd\u8bf4\uff0c\u6570\u7ec4\u4e2d\u524d k \u4e2a\u9ad8\u9891\u5143\u7d20\u7684\u96c6\u5408\u662f\u552f\u4e00\u7684
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u6240\u8bbe\u8ba1\u7b97\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6 \u5fc5\u987b \u4f18\u4e8e O(n log n) \uff0c\u5176\u4e2d n\u00a0\u662f\u6570\u7ec4\u5927\u5c0f\u3002

    \n", "tags_en": ["Heap", "Hash Table"], "tags_cn": ["\u5806", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector topKFrequent(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] topKFrequent(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def topKFrequent(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def topKFrequent(self, nums: List[int], k: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* topKFrequent(int* nums, int numsSize, int k, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] TopKFrequent(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number[]}\n */\nvar topKFrequent = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer[]}\ndef top_k_frequent(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func topKFrequent(_ nums: [Int], _ k: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func topKFrequent(nums []int, k int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def topKFrequent(nums: Array[Int], k: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun topKFrequent(nums: IntArray, k: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn top_k_frequent(nums: Vec, k: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer[]\n */\n function topKFrequent($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function topKFrequent(nums: number[], k: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (top-k-frequent nums k)\n (-> (listof exact-integer?) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0347](https://leetcode-cn.com/problems/top-k-frequent-elements)", "[\u524d K \u4e2a\u9ad8\u9891\u5143\u7d20](/solution/0300-0399/0347.Top%20K%20Frequent%20Elements/README.md)", "`\u5806`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0347](https://leetcode.com/problems/top-k-frequent-elements)", "[Top K Frequent Elements](/solution/0300-0399/0347.Top%20K%20Frequent%20Elements/README_EN.md)", "`Heap`,`Hash Table`", "Medium", ""]}, {"question_id": "0346", "frontend_question_id": "0346", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/moving-average-from-data-stream", "url_en": "https://leetcode.com/problems/moving-average-from-data-stream", "relative_path_cn": "/solution/0300-0399/0346.Moving%20Average%20from%20Data%20Stream/README.md", "relative_path_en": "/solution/0300-0399/0346.Moving%20Average%20from%20Data%20Stream/README_EN.md", "title_cn": "\u6570\u636e\u6d41\u4e2d\u7684\u79fb\u52a8\u5e73\u5747\u503c", "title_en": "Moving Average from Data Stream", "question_title_slug": "moving-average-from-data-stream", "content_en": "

    Given a stream of integers and a window size, calculate the moving average of all integers in the sliding window.

    \n\n

    Implement the MovingAverage class:

    \n\n
      \n\t
    • MovingAverage(int size) Initializes the object with the size of the window size.
    • \n\t
    • double next(int val) Returns the moving average of the last size values of the stream.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["MovingAverage", "next", "next", "next", "next"]\n[[3], [1], [10], [3], [5]]\nOutput\n[null, 1.0, 5.5, 4.66667, 6.0]\n\nExplanation\nMovingAverage movingAverage = new MovingAverage(3);\nmovingAverage.next(1); // return 1.0 = 1 / 1\nmovingAverage.next(10); // return 5.5 = (1 + 10) / 2\nmovingAverage.next(3); // return 4.66667 = (1 + 10 + 3) / 3\nmovingAverage.next(5); // return 6.0 = (10 + 3 + 5) / 3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= size <= 1000
    • \n\t
    • -105 <= val <= 105
    • \n\t
    • At most 104 calls will be made to next.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u636e\u6d41\u548c\u4e00\u4e2a\u7a97\u53e3\u5927\u5c0f\uff0c\u6839\u636e\u8be5\u6ed1\u52a8\u7a97\u53e3\u7684\u5927\u5c0f\uff0c\u8ba1\u7b97\u5176\u6240\u6709\u6574\u6570\u7684\u79fb\u52a8\u5e73\u5747\u503c\u3002

    \n\n

    \u5b9e\u73b0 MovingAverage \u7c7b\uff1a

    \n\n
      \n\t
    • MovingAverage(int size) \u7528\u7a97\u53e3\u5927\u5c0f size \u521d\u59cb\u5316\u5bf9\u8c61\u3002
    • \n\t
    • double next(int val) \u8ba1\u7b97\u5e76\u8fd4\u56de\u6570\u636e\u6d41\u4e2d\u6700\u540e size \u4e2a\u503c\u7684\u79fb\u52a8\u5e73\u5747\u503c\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\n[\"MovingAverage\", \"next\", \"next\", \"next\", \"next\"]\n[[3], [1], [10], [3], [5]]\n\u8f93\u51fa\uff1a\n[null, 1.0, 5.5, 4.66667, 6.0]\n\n\u89e3\u91ca\uff1a\nMovingAverage movingAverage = new MovingAverage(3);\nmovingAverage.next(1); // \u8fd4\u56de 1.0 = 1 / 1\nmovingAverage.next(10); // \u8fd4\u56de 5.5 = (1 + 10) / 2\nmovingAverage.next(3); // \u8fd4\u56de 4.66667 = (1 + 10 + 3) / 3\nmovingAverage.next(5); // \u8fd4\u56de 6.0 = (10 + 3 + 5) / 3\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= size <= 1000
    • \n\t
    • -105 <= val <= 105
    • \n\t
    • \u6700\u591a\u8c03\u7528 next \u65b9\u6cd5 104 \u6b21
    • \n
    \n", "tags_en": ["Design", "Queue"], "tags_cn": ["\u8bbe\u8ba1", "\u961f\u5217"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class MovingAverage {\npublic:\n /** Initialize your data structure here. */\n MovingAverage(int size) {\n\n }\n \n double next(int val) {\n\n }\n};\n\n/**\n * Your MovingAverage object will be instantiated and called as such:\n * MovingAverage* obj = new MovingAverage(size);\n * double param_1 = obj->next(val);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class MovingAverage {\n\n /** Initialize your data structure here. */\n public MovingAverage(int size) {\n\n }\n \n public double next(int val) {\n\n }\n}\n\n/**\n * Your MovingAverage object will be instantiated and called as such:\n * MovingAverage obj = new MovingAverage(size);\n * double param_1 = obj.next(val);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class MovingAverage(object):\n\n def __init__(self, size):\n \"\"\"\n Initialize your data structure here.\n :type size: int\n \"\"\"\n\n\n def next(self, val):\n \"\"\"\n :type val: int\n :rtype: float\n \"\"\"\n\n\n\n# Your MovingAverage object will be instantiated and called as such:\n# obj = MovingAverage(size)\n# param_1 = obj.next(val)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class MovingAverage:\n\n def __init__(self, size: int):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def next(self, val: int) -> float:\n\n\n\n# Your MovingAverage object will be instantiated and called as such:\n# obj = MovingAverage(size)\n# param_1 = obj.next(val)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} MovingAverage;\n\n/** Initialize your data structure here. */\n\nMovingAverage* movingAverageCreate(int size) {\n\n}\n\ndouble movingAverageNext(MovingAverage* obj, int val) {\n\n}\n\nvoid movingAverageFree(MovingAverage* obj) {\n\n}\n\n/**\n * Your MovingAverage struct will be instantiated and called as such:\n * MovingAverage* obj = movingAverageCreate(size);\n * double param_1 = movingAverageNext(obj, val);\n \n * movingAverageFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class MovingAverage {\n\n /** Initialize your data structure here. */\n public MovingAverage(int size) {\n\n }\n \n public double Next(int val) {\n\n }\n}\n\n/**\n * Your MovingAverage object will be instantiated and called as such:\n * MovingAverage obj = new MovingAverage(size);\n * double param_1 = obj.Next(val);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Initialize your data structure here.\n * @param {number} size\n */\nvar MovingAverage = function(size) {\n\n};\n\n/** \n * @param {number} val\n * @return {number}\n */\nMovingAverage.prototype.next = function(val) {\n\n};\n\n/**\n * Your MovingAverage object will be instantiated and called as such:\n * var obj = new MovingAverage(size)\n * var param_1 = obj.next(val)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class MovingAverage\n\n=begin\n Initialize your data structure here.\n :type size: Integer\n=end\n def initialize(size)\n\n end\n\n\n=begin\n :type val: Integer\n :rtype: Float\n=end\n def next(val)\n\n end\n\n\nend\n\n# Your MovingAverage object will be instantiated and called as such:\n# obj = MovingAverage.new(size)\n# param_1 = obj.next(val)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass MovingAverage {\n\n /** Initialize your data structure here. */\n init(_ size: Int) {\n\n }\n \n func next(_ val: Int) -> Double {\n\n }\n}\n\n/**\n * Your MovingAverage object will be instantiated and called as such:\n * let obj = MovingAverage(size)\n * let ret_1: Double = obj.next(val)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type MovingAverage struct {\n\n}\n\n\n/** Initialize your data structure here. */\nfunc Constructor(size int) MovingAverage {\n\n}\n\n\nfunc (this *MovingAverage) Next(val int) float64 {\n\n}\n\n\n/**\n * Your MovingAverage object will be instantiated and called as such:\n * obj := Constructor(size);\n * param_1 := obj.Next(val);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class MovingAverage(_size: Int) {\n\n /** Initialize your data structure here. */\n\n\n def next(`val`: Int): Double = {\n\n }\n\n}\n\n/**\n * Your MovingAverage object will be instantiated and called as such:\n * var obj = new MovingAverage(size)\n * var param_1 = obj.next(`val`)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class MovingAverage(size: Int) {\n\n /** Initialize your data structure here. */\n\n\n fun next(`val`: Int): Double {\n\n }\n\n}\n\n/**\n * Your MovingAverage object will be instantiated and called as such:\n * var obj = MovingAverage(size)\n * var param_1 = obj.next(`val`)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct MovingAverage {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl MovingAverage {\n\n /** Initialize your data structure here. */\n fn new(size: i32) -> Self {\n\n }\n \n fn next(&self, val: i32) -> f64 {\n\n }\n}\n\n/**\n * Your MovingAverage object will be instantiated and called as such:\n * let obj = MovingAverage::new(size);\n * let ret_1: f64 = obj.next(val);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class MovingAverage {\n /**\n * Initialize your data structure here.\n * @param Integer $size\n */\n function __construct($size) {\n\n }\n\n /**\n * @param Integer $val\n * @return Float\n */\n function next($val) {\n\n }\n}\n\n/**\n * Your MovingAverage object will be instantiated and called as such:\n * $obj = MovingAverage($size);\n * $ret_1 = $obj->next($val);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class MovingAverage {\n constructor(size: number) {\n\n }\n\n next(val: number): number {\n\n }\n}\n\n/**\n * Your MovingAverage object will be instantiated and called as such:\n * var obj = new MovingAverage(size)\n * var param_1 = obj.next(val)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define moving-average%\n (class object%\n (super-new)\n\n ; size : exact-integer?\n (init-field\n size)\n \n ; next : exact-integer? -> flonum?\n (define/public (next val)\n\n )))\n\n;; Your moving-average% object will be instantiated and called as such:\n;; (define obj (new moving-average% [size size]))\n;; (define param_1 (send obj next val))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0346](https://leetcode-cn.com/problems/moving-average-from-data-stream)", "[\u6570\u636e\u6d41\u4e2d\u7684\u79fb\u52a8\u5e73\u5747\u503c](/solution/0300-0399/0346.Moving%20Average%20from%20Data%20Stream/README.md)", "`\u8bbe\u8ba1`,`\u961f\u5217`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0346](https://leetcode.com/problems/moving-average-from-data-stream)", "[Moving Average from Data Stream](/solution/0300-0399/0346.Moving%20Average%20from%20Data%20Stream/README_EN.md)", "`Design`,`Queue`", "Easy", "\ud83d\udd12"]}, {"question_id": "0345", "frontend_question_id": "0345", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reverse-vowels-of-a-string", "url_en": "https://leetcode.com/problems/reverse-vowels-of-a-string", "relative_path_cn": "/solution/0300-0399/0345.Reverse%20Vowels%20of%20a%20String/README.md", "relative_path_en": "/solution/0300-0399/0345.Reverse%20Vowels%20of%20a%20String/README_EN.md", "title_cn": "\u53cd\u8f6c\u5b57\u7b26\u4e32\u4e2d\u7684\u5143\u97f3\u5b57\u6bcd", "title_en": "Reverse Vowels of a String", "question_title_slug": "reverse-vowels-of-a-string", "content_en": "

    Given a string s, reverse only all the vowels in the string and return it.

    \n\n

    The vowels are 'a', 'e', 'i', 'o', and 'u', and they can appear in both cases.

    \n\n

     

    \n

    Example 1:

    \n
    Input: s = \"hello\"\nOutput: \"holle\"\n

    Example 2:

    \n
    Input: s = \"leetcode\"\nOutput: \"leotcede\"\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 3 * 105
    • \n\t
    • s consist of printable ASCII characters.
    • \n
    \n", "content_cn": "

    \u7f16\u5199\u4e00\u4e2a\u51fd\u6570\uff0c\u4ee5\u5b57\u7b26\u4e32\u4f5c\u4e3a\u8f93\u5165\uff0c\u53cd\u8f6c\u8be5\u5b57\u7b26\u4e32\u4e2d\u7684\u5143\u97f3\u5b57\u6bcd\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a"hello"\n\u8f93\u51fa\uff1a"holle"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a"leetcode"\n\u8f93\u51fa\uff1a"leotcede"
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u5143\u97f3\u5b57\u6bcd\u4e0d\u5305\u542b\u5b57\u6bcd "y" \u3002
    • \n
    \n", "tags_en": ["Two Pointers", "String"], "tags_cn": ["\u53cc\u6307\u9488", "\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string reverseVowels(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String reverseVowels(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def reverseVowels(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def reverseVowels(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * reverseVowels(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ReverseVowels(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar reverseVowels = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef reverse_vowels(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func reverseVowels(_ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func reverseVowels(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def reverseVowels(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun reverseVowels(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn reverse_vowels(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function reverseVowels($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function reverseVowels(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (reverse-vowels s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0345](https://leetcode-cn.com/problems/reverse-vowels-of-a-string)", "[\u53cd\u8f6c\u5b57\u7b26\u4e32\u4e2d\u7684\u5143\u97f3\u5b57\u6bcd](/solution/0300-0399/0345.Reverse%20Vowels%20of%20a%20String/README.md)", "`\u53cc\u6307\u9488`,`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0345](https://leetcode.com/problems/reverse-vowels-of-a-string)", "[Reverse Vowels of a String](/solution/0300-0399/0345.Reverse%20Vowels%20of%20a%20String/README_EN.md)", "`Two Pointers`,`String`", "Easy", ""]}, {"question_id": "0344", "frontend_question_id": "0344", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reverse-string", "url_en": "https://leetcode.com/problems/reverse-string", "relative_path_cn": "/solution/0300-0399/0344.Reverse%20String/README.md", "relative_path_en": "/solution/0300-0399/0344.Reverse%20String/README_EN.md", "title_cn": "\u53cd\u8f6c\u5b57\u7b26\u4e32", "title_en": "Reverse String", "question_title_slug": "reverse-string", "content_en": "

    Write a function that reverses a string. The input string is given as an array of characters s.

    \n\n

     

    \n

    Example 1:

    \n
    Input: s = [\"h\",\"e\",\"l\",\"l\",\"o\"]\nOutput: [\"o\",\"l\",\"l\",\"e\",\"h\"]\n

    Example 2:

    \n
    Input: s = [\"H\",\"a\",\"n\",\"n\",\"a\",\"h\"]\nOutput: [\"h\",\"a\",\"n\",\"n\",\"a\",\"H\"]\n
    \n

     

    \n

    Constraints:

    \n\n\n\n

     

    \n

    Follow up: Do not allocate extra space for another array. You must do this by modifying the input array in-place with O(1) extra memory.

    \n", "content_cn": "

    \u7f16\u5199\u4e00\u4e2a\u51fd\u6570\uff0c\u5176\u4f5c\u7528\u662f\u5c06\u8f93\u5165\u7684\u5b57\u7b26\u4e32\u53cd\u8f6c\u8fc7\u6765\u3002\u8f93\u5165\u5b57\u7b26\u4e32\u4ee5\u5b57\u7b26\u6570\u7ec4 char[] \u7684\u5f62\u5f0f\u7ed9\u51fa\u3002

    \n\n

    \u4e0d\u8981\u7ed9\u53e6\u5916\u7684\u6570\u7ec4\u5206\u914d\u989d\u5916\u7684\u7a7a\u95f4\uff0c\u4f60\u5fc5\u987b\u539f\u5730\u4fee\u6539\u8f93\u5165\u6570\u7ec4\u3001\u4f7f\u7528 O(1) \u7684\u989d\u5916\u7a7a\u95f4\u89e3\u51b3\u8fd9\u4e00\u95ee\u9898\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u5047\u8bbe\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5b57\u7b26\u90fd\u662f ASCII \u7801\u8868\u4e2d\u7684\u53ef\u6253\u5370\u5b57\u7b26\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a["h","e","l","l","o"]\n\u8f93\u51fa\uff1a["o","l","l","e","h"]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a["H","a","n","n","a","h"]\n\u8f93\u51fa\uff1a["h","a","n","n","a","H"]
    \n", "tags_en": ["Two Pointers", "String"], "tags_cn": ["\u53cc\u6307\u9488", "\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n void reverseString(vector& s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public void reverseString(char[] s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def reverseString(self, s):\n \"\"\"\n :type s: List[str]\n :rtype: None Do not return anything, modify s in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def reverseString(self, s: List[str]) -> None:\n \"\"\"\n Do not return anything, modify s in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nvoid reverseString(char* s, int sSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public void ReverseString(char[] s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {character[]} s\n * @return {void} Do not return anything, modify s in-place instead.\n */\nvar reverseString = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Character[]} s\n# @return {Void} Do not return anything, modify s in-place instead.\ndef reverse_string(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func reverseString(_ s: inout [Character]) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func reverseString(s []byte) {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def reverseString(s: Array[Char]): Unit = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun reverseString(s: CharArray): Unit {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn reverse_string(s: &mut Vec) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $s\n * @return NULL\n */\n function reverseString(&$s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n Do not return anything, modify s in-place instead.\n */\nfunction reverseString(s: string[]): void {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0344](https://leetcode-cn.com/problems/reverse-string)", "[\u53cd\u8f6c\u5b57\u7b26\u4e32](/solution/0300-0399/0344.Reverse%20String/README.md)", "`\u53cc\u6307\u9488`,`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0344](https://leetcode.com/problems/reverse-string)", "[Reverse String](/solution/0300-0399/0344.Reverse%20String/README_EN.md)", "`Two Pointers`,`String`", "Easy", ""]}, {"question_id": "0343", "frontend_question_id": "0343", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/integer-break", "url_en": "https://leetcode.com/problems/integer-break", "relative_path_cn": "/solution/0300-0399/0343.Integer%20Break/README.md", "relative_path_en": "/solution/0300-0399/0343.Integer%20Break/README_EN.md", "title_cn": "\u6574\u6570\u62c6\u5206", "title_en": "Integer Break", "question_title_slug": "integer-break", "content_en": "

    Given an integer n, break it into the sum of k positive integers, where k >= 2, and maximize the product of those integers.

    \n\n

    Return the maximum product you can get.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 2\nOutput: 1\nExplanation: 2 = 1 + 1, 1 × 1 = 1.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 10\nOutput: 36\nExplanation: 10 = 3 + 3 + 4, 3 × 3 × 4 = 36.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= n <= 58
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6b63\u6574\u6570 n\uff0c\u5c06\u5176\u62c6\u5206\u4e3a\u81f3\u5c11\u4e24\u4e2a\u6b63\u6574\u6570\u7684\u548c\uff0c\u5e76\u4f7f\u8fd9\u4e9b\u6574\u6570\u7684\u4e58\u79ef\u6700\u5927\u5316\u3002 \u8fd4\u56de\u4f60\u53ef\u4ee5\u83b7\u5f97\u7684\u6700\u5927\u4e58\u79ef\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: 2\n\u8f93\u51fa: 1\n\u89e3\u91ca: 2 = 1 + 1, 1 × 1 = 1\u3002
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: 10\n\u8f93\u51fa: 36\n\u89e3\u91ca: 10 = 3 + 3 + 4, 3 × 3 × 4 = 36\u3002
    \n\n

    \u8bf4\u660e: \u4f60\u53ef\u4ee5\u5047\u8bbe \u4e0d\u5c0f\u4e8e 2 \u4e14\u4e0d\u5927\u4e8e 58\u3002

    \n", "tags_en": ["Math", "Dynamic Programming"], "tags_cn": ["\u6570\u5b66", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int integerBreak(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int integerBreak(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def integerBreak(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def integerBreak(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint integerBreak(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int IntegerBreak(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar integerBreak = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef integer_break(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func integerBreak(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func integerBreak(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def integerBreak(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun integerBreak(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn integer_break(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function integerBreak($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function integerBreak(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (integer-break n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0343](https://leetcode-cn.com/problems/integer-break)", "[\u6574\u6570\u62c6\u5206](/solution/0300-0399/0343.Integer%20Break/README.md)", "`\u6570\u5b66`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0343](https://leetcode.com/problems/integer-break)", "[Integer Break](/solution/0300-0399/0343.Integer%20Break/README_EN.md)", "`Math`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0342", "frontend_question_id": "0342", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/power-of-four", "url_en": "https://leetcode.com/problems/power-of-four", "relative_path_cn": "/solution/0300-0399/0342.Power%20of%20Four/README.md", "relative_path_en": "/solution/0300-0399/0342.Power%20of%20Four/README_EN.md", "title_cn": "4\u7684\u5e42", "title_en": "Power of Four", "question_title_slug": "power-of-four", "content_en": "

    Given an integer n, return true if it is a power of four. Otherwise, return false.

    \n\n

    An integer n is a power of four, if there exists an integer x such that n == 4x.

    \n\n

     

    \n

    Example 1:

    \n
    Input: n = 16\nOutput: true\n

    Example 2:

    \n
    Input: n = 5\nOutput: false\n

    Example 3:

    \n
    Input: n = 1\nOutput: true\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • -231 <= n <= 231 - 1
    • \n
    \n\n

     

    \nFollow up: Could you solve it without loops/recursion?", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\uff0c\u5199\u4e00\u4e2a\u51fd\u6570\u6765\u5224\u65ad\u5b83\u662f\u5426\u662f 4 \u7684\u5e42\u6b21\u65b9\u3002\u5982\u679c\u662f\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n

    \u6574\u6570 n \u662f 4 \u7684\u5e42\u6b21\u65b9\u9700\u6ee1\u8db3\uff1a\u5b58\u5728\u6574\u6570 x \u4f7f\u5f97 n == 4x

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 16\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 5\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • -231 <= n <= 231 - 1
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u4f60\u80fd\u4e0d\u4f7f\u7528\u5faa\u73af\u6216\u8005\u9012\u5f52\u6765\u5b8c\u6210\u672c\u9898\u5417\uff1f
    • \n
    \n", "tags_en": ["Bit Manipulation"], "tags_cn": ["\u4f4d\u8fd0\u7b97"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isPowerOfFour(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isPowerOfFour(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isPowerOfFour(self, n):\n \"\"\"\n :type n: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isPowerOfFour(self, n: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isPowerOfFour(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsPowerOfFour(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {boolean}\n */\nvar isPowerOfFour = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Boolean}\ndef is_power_of_four(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isPowerOfFour(_ n: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isPowerOfFour(n int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isPowerOfFour(n: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isPowerOfFour(n: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_power_of_four(n: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Boolean\n */\n function isPowerOfFour($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isPowerOfFour(n: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-power-of-four n)\n (-> exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0342](https://leetcode-cn.com/problems/power-of-four)", "[4\u7684\u5e42](/solution/0300-0399/0342.Power%20of%20Four/README.md)", "`\u4f4d\u8fd0\u7b97`", "\u7b80\u5355", ""], "md_table_row_en": ["[0342](https://leetcode.com/problems/power-of-four)", "[Power of Four](/solution/0300-0399/0342.Power%20of%20Four/README_EN.md)", "`Bit Manipulation`", "Easy", ""]}, {"question_id": "0341", "frontend_question_id": "0341", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/flatten-nested-list-iterator", "url_en": "https://leetcode.com/problems/flatten-nested-list-iterator", "relative_path_cn": "/solution/0300-0399/0341.Flatten%20Nested%20List%20Iterator/README.md", "relative_path_en": "/solution/0300-0399/0341.Flatten%20Nested%20List%20Iterator/README_EN.md", "title_cn": "\u6241\u5e73\u5316\u5d4c\u5957\u5217\u8868\u8fed\u4ee3\u5668", "title_en": "Flatten Nested List Iterator", "question_title_slug": "flatten-nested-list-iterator", "content_en": "

    You are given a nested list of integers nestedList. Each element is either an integer or a list whose elements may also be integers or other lists. Implement an iterator to flatten it.

    \n\n

    Implement the NestedIterator class:

    \n\n
      \n\t
    • NestedIterator(List<NestedInteger> nestedList) Initializes the iterator with the nested list nestedList.
    • \n\t
    • int next() Returns the next integer in the nested list.
    • \n\t
    • boolean hasNext() Returns true if there are still some integers in the nested list and false otherwise.
    • \n
    \n\n

    Your code will be tested with the following pseudocode:

    \n\n
    \ninitialize iterator with nestedList\nres = []\nwhile iterator.hasNext()\n    append iterator.next() to the end of res\nreturn res\n
    \n\n

    If res matches the expected flattened list, then your code will be judged as correct.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nestedList = [[1,1],2,[1,1]]\nOutput: [1,1,2,1,1]\nExplanation: By calling next repeatedly until hasNext returns false, the order of elements returned by next should be: [1,1,2,1,1].\n
    \n\n

    Example 2:

    \n\n
    \nInput: nestedList = [1,[4,[6]]]\nOutput: [1,4,6]\nExplanation: By calling next repeatedly until hasNext returns false, the order of elements returned by next should be: [1,4,6].\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nestedList.length <= 500
    • \n\t
    • The values of the integers in the nested list is in the range [-106, 106].
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5d4c\u5957\u7684\u6574\u578b\u5217\u8868\u3002\u8bf7\u4f60\u8bbe\u8ba1\u4e00\u4e2a\u8fed\u4ee3\u5668\uff0c\u4f7f\u5176\u80fd\u591f\u904d\u5386\u8fd9\u4e2a\u6574\u578b\u5217\u8868\u4e2d\u7684\u6240\u6709\u6574\u6570\u3002

    \n\n

    \u5217\u8868\u4e2d\u7684\u6bcf\u4e00\u9879\u6216\u8005\u4e3a\u4e00\u4e2a\u6574\u6570\uff0c\u6216\u8005\u662f\u53e6\u4e00\u4e2a\u5217\u8868\u3002\u5176\u4e2d\u5217\u8868\u7684\u5143\u7d20\u4e5f\u53ef\u80fd\u662f\u6574\u6570\u6216\u662f\u5176\u4ed6\u5217\u8868\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: [[1,1],2,[1,1]]\n\u8f93\u51fa: [1,1,2,1,1]\n\u89e3\u91ca: \u901a\u8fc7\u91cd\u590d\u8c03\u7528 next \u76f4\u5230 hasNext \u8fd4\u56de false\uff0cnext \u8fd4\u56de\u7684\u5143\u7d20\u7684\u987a\u5e8f\u5e94\u8be5\u662f: [1,1,2,1,1]\u3002
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: [1,[4,[6]]]\n\u8f93\u51fa: [1,4,6]\n\u89e3\u91ca: \u901a\u8fc7\u91cd\u590d\u8c03\u7528 next \u76f4\u5230 hasNext \u8fd4\u56de false\uff0cnext \u8fd4\u56de\u7684\u5143\u7d20\u7684\u987a\u5e8f\u5e94\u8be5\u662f: [1,4,6]\u3002\n
    \n", "tags_en": ["Stack", "Design"], "tags_cn": ["\u6808", "\u8bbe\u8ba1"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * class NestedInteger {\n * public:\n * // Return true if this NestedInteger holds a single integer, rather than a nested list.\n * bool isInteger() const;\n *\n * // Return the single integer that this NestedInteger holds, if it holds a single integer\n * // The result is undefined if this NestedInteger holds a nested list\n * int getInteger() const;\n *\n * // Return the nested list that this NestedInteger holds, if it holds a nested list\n * // The result is undefined if this NestedInteger holds a single integer\n * const vector &getList() const;\n * };\n */\n\nclass NestedIterator {\npublic:\n NestedIterator(vector &nestedList) {\n \n }\n \n int next() {\n \n }\n \n bool hasNext() {\n \n }\n};\n\n/**\n * Your NestedIterator object will be instantiated and called as such:\n * NestedIterator i(nestedList);\n * while (i.hasNext()) cout << i.next();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * public interface NestedInteger {\n *\n * // @return true if this NestedInteger holds a single integer, rather than a nested list.\n * public boolean isInteger();\n *\n * // @return the single integer that this NestedInteger holds, if it holds a single integer\n * // Return null if this NestedInteger holds a nested list\n * public Integer getInteger();\n *\n * // @return the nested list that this NestedInteger holds, if it holds a nested list\n * // Return empty list if this NestedInteger holds a single integer\n * public List getList();\n * }\n */\npublic class NestedIterator implements Iterator {\n\n public NestedIterator(List nestedList) {\n \n }\n\n @Override\n public Integer next() {\n \n }\n\n @Override\n public boolean hasNext() {\n \n }\n}\n\n/**\n * Your NestedIterator object will be instantiated and called as such:\n * NestedIterator i = new NestedIterator(nestedList);\n * while (i.hasNext()) v[f()] = i.next();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# \"\"\"\n# This is the interface that allows for creating nested lists.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class NestedInteger(object):\n# def isInteger(self):\n# \"\"\"\n# @return True if this NestedInteger holds a single integer, rather than a nested list.\n# :rtype bool\n# \"\"\"\n#\n# def getInteger(self):\n# \"\"\"\n# @return the single integer that this NestedInteger holds, if it holds a single integer\n# Return None if this NestedInteger holds a nested list\n# :rtype int\n# \"\"\"\n#\n# def getList(self):\n# \"\"\"\n# @return the nested list that this NestedInteger holds, if it holds a nested list\n# Return None if this NestedInteger holds a single integer\n# :rtype List[NestedInteger]\n# \"\"\"\n\nclass NestedIterator(object):\n\n def __init__(self, nestedList):\n \"\"\"\n Initialize your data structure here.\n :type nestedList: List[NestedInteger]\n \"\"\"\n \n\n def next(self):\n \"\"\"\n :rtype: int\n \"\"\"\n \n\n def hasNext(self):\n \"\"\"\n :rtype: bool\n \"\"\"\n \n\n# Your NestedIterator object will be instantiated and called as such:\n# i, v = NestedIterator(nestedList), []\n# while i.hasNext(): v.append(i.next())", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# \"\"\"\n# This is the interface that allows for creating nested lists.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class NestedInteger:\n# def isInteger(self) -> bool:\n# \"\"\"\n# @return True if this NestedInteger holds a single integer, rather than a nested list.\n# \"\"\"\n#\n# def getInteger(self) -> int:\n# \"\"\"\n# @return the single integer that this NestedInteger holds, if it holds a single integer\n# Return None if this NestedInteger holds a nested list\n# \"\"\"\n#\n# def getList(self) -> [NestedInteger]:\n# \"\"\"\n# @return the nested list that this NestedInteger holds, if it holds a nested list\n# Return None if this NestedInteger holds a single integer\n# \"\"\"\n\nclass NestedIterator:\n def __init__(self, nestedList: [NestedInteger]):\n \n \n def next(self) -> int:\n \n \n def hasNext(self) -> bool:\n \n\n# Your NestedIterator object will be instantiated and called as such:\n# i, v = NestedIterator(nestedList), []\n# while i.hasNext(): v.append(i.next())", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * *********************************************************************\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * *********************************************************************\n *\n * // Return true if this NestedInteger holds a single integer, rather than a nested list.\n * bool NestedIntegerIsInteger(struct NestedInteger *);\n *\n * // Return the single integer that this NestedInteger holds, if it holds a single integer\n * // The result is undefined if this NestedInteger holds a nested list\n * int NestedIntegerGetInteger(struct NestedInteger *);\n *\n * // Return the nested list that this NestedInteger holds, if it holds a nested list\n * // The result is undefined if this NestedInteger holds a single integer\n * struct NestedInteger **NestedIntegerGetList(struct NestedInteger *);\n *\n * // Return the nested list's size that this NestedInteger holds, if it holds a nested list\n * // The result is undefined if this NestedInteger holds a single integer\n * int NestedIntegerGetListSize(struct NestedInteger *);\n * };\n */\nstruct NestedIterator {\n \n};\n\nstruct NestedIterator *nestedIterCreate(struct NestedInteger** nestedList, int nestedListSize) {\n \n}\n\nbool nestedIterHasNext(struct NestedIterator *iter) {\n \n}\n\nint nestedIterNext(struct NestedIterator *iter) {\n \n}\n\n/** Deallocates memory previously allocated for the iterator */\nvoid nestedIterFree(struct NestedIterator *iter) {\n \n}\n\n/**\n * Your NestedIterator will be called like this:\n * struct NestedIterator *i = nestedIterCreate(nestedList, nestedListSize);\n * while (nestedIterHasNext(i)) printf(\"%d\\n\", nestedIterNext(i));\n * nestedIterFree(i);\n */", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * interface NestedInteger {\n *\n * // @return true if this NestedInteger holds a single integer, rather than a nested list.\n * bool IsInteger();\n *\n * // @return the single integer that this NestedInteger holds, if it holds a single integer\n * // Return null if this NestedInteger holds a nested list\n * int GetInteger();\n *\n * // @return the nested list that this NestedInteger holds, if it holds a nested list\n * // Return null if this NestedInteger holds a single integer\n * IList GetList();\n * }\n */\npublic class NestedIterator {\n\n public NestedIterator(IList nestedList) {\n \n }\n\n public bool HasNext() {\n \n }\n\n public int Next() {\n \n }\n}\n\n/**\n * Your NestedIterator will be called like this:\n * NestedIterator i = new NestedIterator(nestedList);\n * while (i.HasNext()) v[f()] = i.Next();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * function NestedInteger() {\n *\n * Return true if this NestedInteger holds a single integer, rather than a nested list.\n * @return {boolean}\n * this.isInteger = function() {\n * ...\n * };\n *\n * Return the single integer that this NestedInteger holds, if it holds a single integer\n * Return null if this NestedInteger holds a nested list\n * @return {integer}\n * this.getInteger = function() {\n * ...\n * };\n *\n * Return the nested list that this NestedInteger holds, if it holds a nested list\n * Return null if this NestedInteger holds a single integer\n * @return {NestedInteger[]}\n * this.getList = function() {\n * ...\n * };\n * };\n */\n/**\n * @constructor\n * @param {NestedInteger[]} nestedList\n */\nvar NestedIterator = function(nestedList) {\n \n};\n\n\n/**\n * @this NestedIterator\n * @returns {boolean}\n */\nNestedIterator.prototype.hasNext = function() {\n \n};\n\n/**\n * @this NestedIterator\n * @returns {integer}\n */\nNestedIterator.prototype.next = function() {\n \n};\n\n/**\n * Your NestedIterator will be called like this:\n * var i = new NestedIterator(nestedList), a = [];\n * while (i.hasNext()) a.push(i.next());\n*/", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# This is the interface that allows for creating nested lists.\n# You should not implement it, or speculate about its implementation\n#\n#class NestedInteger\n# def is_integer()\n# \"\"\"\n# Return true if this NestedInteger holds a single integer, rather than a nested list.\n# @return {Boolean}\n# \"\"\"\n#\n# def get_integer()\n# \"\"\"\n# Return the single integer that this NestedInteger holds, if it holds a single integer\n# Return nil if this NestedInteger holds a nested list\n# @return {Integer}\n# \"\"\"\n#\n# def get_list()\n# \"\"\"\n# Return the nested list that this NestedInteger holds, if it holds a nested list\n# Return nil if this NestedInteger holds a single integer\n# @return {NestedInteger[]}\n# \"\"\"\n\nclass NestedIterator\n # @param {NestedInteger[]} nested_list\n def initialize(nested_list)\n \n end\n\n # @return {Boolean}\n def has_next\n \n end\n\n # @return {Integer}\n def next\n \n end\nend\n\n# Your NestedIterator will be called like this:\n# i, v = NestedIterator.new(nested_list), []\n# while i.has_next()\n# v << i.next\n# end", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * class NestedInteger {\n * // Return true if this NestedInteger holds a single integer, rather than a nested list.\n * public func isInteger() -> Bool\n *\n * // Return the single integer that this NestedInteger holds, if it holds a single integer\n * // The result is undefined if this NestedInteger holds a nested list\n * public func getInteger() -> Int\n *\n * // Set this NestedInteger to hold a single integer.\n * public func setInteger(value: Int)\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * public func add(elem: NestedInteger)\n *\n * // Return the nested list that this NestedInteger holds, if it holds a nested list\n * // The result is undefined if this NestedInteger holds a single integer\n * public func getList() -> [NestedInteger]\n * }\n */\n\nclass NestedIterator {\n\n init(_ nestedList: [NestedInteger]) {\n \n }\n \n func next() -> Int {\n \n }\n \n func hasNext() -> Bool {\n \n }\n}\n\n/**\n * Your NestedIterator object will be instantiated and called as such:\n * let obj = NestedIterator(nestedList)\n * let ret_1: Int = obj.next()\n * let ret_2: Bool = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * type NestedInteger struct {\n * }\n *\n * // Return true if this NestedInteger holds a single integer, rather than a nested list.\n * func (this NestedInteger) IsInteger() bool {}\n *\n * // Return the single integer that this NestedInteger holds, if it holds a single integer\n * // The result is undefined if this NestedInteger holds a nested list\n * // So before calling this method, you should have a check\n * func (this NestedInteger) GetInteger() int {}\n *\n * // Set this NestedInteger to hold a single integer.\n * func (n *NestedInteger) SetInteger(value int) {}\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * func (this *NestedInteger) Add(elem NestedInteger) {}\n *\n * // Return the nested list that this NestedInteger holds, if it holds a nested list\n * // The list length is zero if this NestedInteger holds a single integer\n * // You can access NestedInteger's List element directly if you want to modify it\n * func (this NestedInteger) GetList() []*NestedInteger {}\n */\n\ntype NestedIterator struct {\n \n}\n\nfunc Constructor(nestedList []*NestedInteger) *NestedIterator {\n \n}\n\nfunc (this *NestedIterator) Next() int {\n \n}\n\nfunc (this *NestedIterator) HasNext() bool {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * trait NestedInteger {\n *\n * // Return true if this NestedInteger holds a single integer, rather than a nested list.\n * def isInteger: Boolean\n *\n * // Return the single integer that this NestedInteger holds, if it holds a single integer.\n * def getInteger: Int\n *\n * // Set this NestedInteger to hold a single integer.\n * def setInteger(i: Int): Unit\n *\n * // Return the nested list that this NestedInteger holds, if it holds a nested list.\n * def getList: Array[NestedInteger]\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * def add(ni: NestedInteger): Unit\n * }\n */\n\nclass NestedIterator(_nestedList: List[NestedInteger]) {\n def next(): Int = {\n \n }\n \n def hasNext(): Boolean = {\n \n }\n}\n\n/**\n * Your NestedIterator object will be instantiated and called as such:\n * var obj = new NestedIterator(nestedList)\n * var param_1 = obj.next()\n * var param_2 = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * class NestedInteger {\n * // Constructor initializes an empty nested list.\n * constructor()\n *\n * // Constructor initializes a single integer.\n * constructor(value: Int)\n *\n * // @return true if this NestedInteger holds a single integer, rather than a nested list.\n * fun isInteger(): Boolean\n *\n * // @return the single integer that this NestedInteger holds, if it holds a single integer\n * // Return null if this NestedInteger holds a nested list\n * fun getInteger(): Int?\n *\n * // Set this NestedInteger to hold a single integer.\n * fun setInteger(value: Int): Unit\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * fun add(ni: NestedInteger): Unit\n *\n * // @return the nested list that this NestedInteger holds, if it holds a nested list\n * // Return null if this NestedInteger holds a single integer\n * fun getList(): List?\n * }\n */\n\nclass NestedIterator(nestedList: List) {\n fun next(): Int {\n \n }\n \n fun hasNext(): Boolean {\n \n }\n}\n\n/**\n * Your NestedIterator object will be instantiated and called as such:\n * var obj = NestedIterator(nestedList)\n * var param_1 = obj.next()\n * var param_2 = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// #[derive(Debug, PartialEq, Eq)]\n// pub enum NestedInteger {\n// Int(i32),\n// List(Vec)\n// }\nstruct NestedIterator {\n\n}\n\n\n/** \n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl NestedIterator {\n\n fn new(nestedList: Vec) -> Self {\n \n }\n \n fn next(&self) -> i32 {\n \n }\n \n fn has_next(&self) -> bool {\n \n }\n}\n\n/**\n * Your NestedIterator object will be instantiated and called as such:\n * let obj = NestedIterator::new(nestedList);\n * let ret_1: i32 = obj.next();\n * let ret_2: bool = obj.has_next();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * class NestedInteger {\n *\n * // if value is not specified, initializes an empty list.\n * // Otherwise initializes a single integer equal to value.\n * function __construct($value = null)\n *\n * // Return true if this NestedInteger holds a single integer, rather than a nested list.\n * function isInteger() : bool\n *\n * // Return the single integer that this NestedInteger holds, if it holds a single integer\n * // The result is undefined if this NestedInteger holds a nested list\n * function getInteger()\n *\n * // Set this NestedInteger to hold a single integer.\n * function setInteger($i) : void\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * function add($ni) : void\n *\n * // Return the nested list that this NestedInteger holds, if it holds a nested list\n * // The result is undefined if this NestedInteger holds a single integer\n * function getList() : array\n * }\n */\n\nclass NestedIterator {\n /**\n * @param NestedInteger[] $nestedList\n */\n function __construct($nestedList) {\n \n }\n \n /**\n * @return Integer\n */\n function next() {\n \n }\n \n /**\n * @return Boolean\n */\n function hasNext() {\n \n }\n}\n\n/**\n * Your NestedIterator object will be instantiated and called as such:\n * $obj = NestedIterator($nestedList);\n * $ret_1 = $obj->next();\n * $ret_2 = $obj->hasNext();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * class NestedInteger {\n * If value is provided, then it holds a single integer\n * Otherwise it holds an empty nested list\n * constructor(value?: number) {\n * ...\n * };\n *\n * Return true if this NestedInteger holds a single integer, rather than a nested list.\n * isInteger(): boolean {\n * ...\n * };\n *\n * Return the single integer that this NestedInteger holds, if it holds a single integer\n * Return null if this NestedInteger holds a nested list\n * getInteger(): number | null {\n * ...\n * };\n *\n * Set this NestedInteger to hold a single integer equal to value.\n * setInteger(value: number) {\n * ...\n * };\n *\n * Set this NestedInteger to hold a nested list and adds a nested integer elem to it.\n * add(elem: NestedInteger) {\n * ...\n * };\n *\n * Return the nested list that this NestedInteger holds,\n * or an empty list if this NestedInteger holds a single integer\n * getList(): NestedInteger[] {\n * ...\n * };\n * };\n */\n\nclass NestedIterator {\n constructor(nestedList: NestedInteger[]) {\n\t\t\n }\n\n hasNext(): boolean {\n\t\t\n }\n\n\tnext(): number {\n\t\t\n }\n}\n\n/**\n * Your ParkingSystem object will be instantiated and called as such:\n * var obj = new NestedIterator(nestedList)\n * var a: number[] = []\n * while (obj.hasNext()) a.push(obj.next());\n */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0341](https://leetcode-cn.com/problems/flatten-nested-list-iterator)", "[\u6241\u5e73\u5316\u5d4c\u5957\u5217\u8868\u8fed\u4ee3\u5668](/solution/0300-0399/0341.Flatten%20Nested%20List%20Iterator/README.md)", "`\u6808`,`\u8bbe\u8ba1`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0341](https://leetcode.com/problems/flatten-nested-list-iterator)", "[Flatten Nested List Iterator](/solution/0300-0399/0341.Flatten%20Nested%20List%20Iterator/README_EN.md)", "`Stack`,`Design`", "Medium", ""]}, {"question_id": "0340", "frontend_question_id": "0340", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/longest-substring-with-at-most-k-distinct-characters", "url_en": "https://leetcode.com/problems/longest-substring-with-at-most-k-distinct-characters", "relative_path_cn": "/solution/0300-0399/0340.Longest%20Substring%20with%20At%20Most%20K%20Distinct%20Characters/README.md", "relative_path_en": "/solution/0300-0399/0340.Longest%20Substring%20with%20At%20Most%20K%20Distinct%20Characters/README_EN.md", "title_cn": "\u81f3\u591a\u5305\u542b K \u4e2a\u4e0d\u540c\u5b57\u7b26\u7684\u6700\u957f\u5b50\u4e32", "title_en": "Longest Substring with At Most K Distinct Characters", "question_title_slug": "longest-substring-with-at-most-k-distinct-characters", "content_en": "

    Given a string s and an integer k, return the length of the longest substring of s that contains at most k distinct characters.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "eceba", k = 2\nOutput: 3\nExplanation: The substring is "ece" with length 3.
    \n\n

    Example 2:

    \n\n
    \nInput: s = "aa", k = 1\nOutput: 2\nExplanation: The substring is "aa" with length 2.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 5 * 104
    • \n\t
    • 0 <= k <= 50
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32 s \uff0c\u627e\u51fa \u81f3\u591a \u5305\u542b k \u4e2a\u4e0d\u540c\u5b57\u7b26\u7684\u6700\u957f\u5b50\u4e32 T\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: s = "eceba", k = 2\n\u8f93\u51fa: 3\n\u89e3\u91ca: \u5219 T \u4e3a "ece"\uff0c\u6240\u4ee5\u957f\u5ea6\u4e3a 3\u3002
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: s = "aa", k = 1\n\u8f93\u51fa: 2\n\u89e3\u91ca: \u5219 T \u4e3a "aa"\uff0c\u6240\u4ee5\u957f\u5ea6\u4e3a 2\u3002\n
    \n", "tags_en": ["Hash Table", "Two Pointers", "String", "Sliding Window"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u53cc\u6307\u9488", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int lengthOfLongestSubstringKDistinct(string s, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int lengthOfLongestSubstringKDistinct(String s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def lengthOfLongestSubstringKDistinct(self, s, k):\n \"\"\"\n :type s: str\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def lengthOfLongestSubstringKDistinct(self, s: str, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint lengthOfLongestSubstringKDistinct(char * s, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LengthOfLongestSubstringKDistinct(string s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number} k\n * @return {number}\n */\nvar lengthOfLongestSubstringKDistinct = function(s, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer} k\n# @return {Integer}\ndef length_of_longest_substring_k_distinct(s, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func lengthOfLongestSubstringKDistinct(_ s: String, _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func lengthOfLongestSubstringKDistinct(s string, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def lengthOfLongestSubstringKDistinct(s: String, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun lengthOfLongestSubstringKDistinct(s: String, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn length_of_longest_substring_k_distinct(s: String, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer $k\n * @return Integer\n */\n function lengthOfLongestSubstringKDistinct($s, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function lengthOfLongestSubstringKDistinct(s: string, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (length-of-longest-substring-k-distinct s k)\n (-> string? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0340](https://leetcode-cn.com/problems/longest-substring-with-at-most-k-distinct-characters)", "[\u81f3\u591a\u5305\u542b K \u4e2a\u4e0d\u540c\u5b57\u7b26\u7684\u6700\u957f\u5b50\u4e32](/solution/0300-0399/0340.Longest%20Substring%20with%20At%20Most%20K%20Distinct%20Characters/README.md)", "`\u54c8\u5e0c\u8868`,`\u53cc\u6307\u9488`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0340](https://leetcode.com/problems/longest-substring-with-at-most-k-distinct-characters)", "[Longest Substring with At Most K Distinct Characters](/solution/0300-0399/0340.Longest%20Substring%20with%20At%20Most%20K%20Distinct%20Characters/README_EN.md)", "`Hash Table`,`Two Pointers`,`String`,`Sliding Window`", "Medium", "\ud83d\udd12"]}, {"question_id": "0339", "frontend_question_id": "0339", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/nested-list-weight-sum", "url_en": "https://leetcode.com/problems/nested-list-weight-sum", "relative_path_cn": "/solution/0300-0399/0339.Nested%20List%20Weight%20Sum/README.md", "relative_path_en": "/solution/0300-0399/0339.Nested%20List%20Weight%20Sum/README_EN.md", "title_cn": "\u5d4c\u5957\u5217\u8868\u6743\u91cd\u548c", "title_en": "Nested List Weight Sum", "question_title_slug": "nested-list-weight-sum", "content_en": "

    You are given a nested list of integers nestedList. Each element is either an integer or a list whose elements may also be integers or other lists.

    \n\n

    The depth of an integer is the number of lists that it is inside of. For example, the nested list [1,[2,2],[[3],2],1] has each integer's value set to its depth.

    \n\n

    Return the sum of each integer in nestedList multiplied by its depth.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: nestedList = [[1,1],2,[1,1]]\nOutput: 10\nExplanation: Four 1's at depth 2, one 2 at depth 1. 1*2 + 1*2 + 2*1 + 1*2 + 1*2 = 10.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: nestedList = [1,[4,[6]]]\nOutput: 27\nExplanation: One 1 at depth 1, one 4 at depth 2, and one 6 at depth 3. 1*1 + 4*2 + 6*3 = 27.
    \n\n

    Example 3:

    \n\n
    \nInput: nestedList = [0]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nestedList.length <= 50
    • \n\t
    • The values of the integers in the nested list is in the range [-100, 100].
    • \n\t
    • The maximum depth of any integer is less than or equal to 50.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5d4c\u5957\u7684\u6574\u6570\u5217\u8868\u00a0nestedList \uff0c\u6bcf\u4e2a\u5143\u7d20\u8981\u4e48\u662f\u6574\u6570\uff0c\u8981\u4e48\u662f\u5217\u8868\u3002\u540c\u65f6\uff0c\u5217\u8868\u4e2d\u5143\u7d20\u540c\u6837\u4e5f\u53ef\u4ee5\u662f\u6574\u6570\u6216\u8005\u662f\u53e6\u4e00\u4e2a\u5217\u8868\u3002

    \n\n

    \u6574\u6570\u7684 \u6df1\u5ea6 \u662f\u5176\u5728\u5217\u8868\u5185\u90e8\u7684\u5d4c\u5957\u5c42\u6570\u3002\u4f8b\u5982\uff0c\u5d4c\u5957\u5217\u8868\u00a0[1,[2,2],[[3],2],1] \u4e2d\u6bcf\u4e2a\u6574\u6570\u7684\u503c\u5c31\u662f\u5176\u6df1\u5ea6\u3002

    \n\n

    \u8bf7\u8fd4\u56de\u8be5\u5217\u8868\u6309\u6df1\u5ea6\u52a0\u6743\u540e\u6240\u6709\u6574\u6570\u7684\u603b\u548c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1anestedList = [[1,1],2,[1,1]]\n\u8f93\u51fa\uff1a10 \n\u89e3\u91ca\uff1a\u56e0\u4e3a\u5217\u8868\u4e2d\u6709\u56db\u4e2a\u6df1\u5ea6\u4e3a 2 \u7684 1 \uff0c\u548c\u4e00\u4e2a\u6df1\u5ea6\u4e3a 1 \u7684 2\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1anestedList = [1,[4,[6]]]\n\u8f93\u51fa\uff1a27 \n\u89e3\u91ca\uff1a\u4e00\u4e2a\u6df1\u5ea6\u4e3a 1 \u7684 1\uff0c\u4e00\u4e2a\u6df1\u5ea6\u4e3a 2 \u7684 4\uff0c\u4e00\u4e2a\u6df1\u5ea6\u4e3a 3 \u7684 6\u3002\u6240\u4ee5\uff0c1 + 4*2 + 6*3 = 27\u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anestedList = [0]\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nestedList.length <= 50
    • \n\t
    • \u5d4c\u5957\u5217\u8868\u4e2d\u6574\u6570\u7684\u503c\u5728\u8303\u56f4 [-100, 100] \u5185
    • \n\t
    • \u4efb\u4f55\u6574\u6570\u7684\u6700\u5927 \u6df1\u5ea6 \u90fd\u5c0f\u4e8e\u6216\u7b49\u4e8e 50
    • \n
    \n", "tags_en": ["Depth-first Search", "Breadth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * class NestedInteger {\n * public:\n * // Constructor initializes an empty nested list.\n * NestedInteger();\n *\n * // Constructor initializes a single integer.\n * NestedInteger(int value);\n *\n * // Return true if this NestedInteger holds a single integer, rather than a nested list.\n * bool isInteger() const;\n *\n * // Return the single integer that this NestedInteger holds, if it holds a single integer\n * // The result is undefined if this NestedInteger holds a nested list\n * int getInteger() const;\n *\n * // Set this NestedInteger to hold a single integer.\n * void setInteger(int value);\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * void add(const NestedInteger &ni);\n *\n * // Return the nested list that this NestedInteger holds, if it holds a nested list\n * // The result is undefined if this NestedInteger holds a single integer\n * const vector &getList() const;\n * };\n */\nclass Solution {\npublic:\n int depthSum(vector& nestedList) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * public interface NestedInteger {\n * // Constructor initializes an empty nested list.\n * public NestedInteger();\n *\n * // Constructor initializes a single integer.\n * public NestedInteger(int value);\n *\n * // @return true if this NestedInteger holds a single integer, rather than a nested list.\n * public boolean isInteger();\n *\n * // @return the single integer that this NestedInteger holds, if it holds a single integer\n * // Return null if this NestedInteger holds a nested list\n * public Integer getInteger();\n *\n * // Set this NestedInteger to hold a single integer.\n * public void setInteger(int value);\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * public void add(NestedInteger ni);\n *\n * // @return the nested list that this NestedInteger holds, if it holds a nested list\n * // Return empty list if this NestedInteger holds a single integer\n * public List getList();\n * }\n */\nclass Solution {\n public int depthSum(List nestedList) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# \"\"\"\n# This is the interface that allows for creating nested lists.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class NestedInteger(object):\n# def __init__(self, value=None):\n# \"\"\"\n# If value is not specified, initializes an empty list.\n# Otherwise initializes a single integer equal to value.\n# \"\"\"\n#\n# def isInteger(self):\n# \"\"\"\n# @return True if this NestedInteger holds a single integer, rather than a nested list.\n# :rtype bool\n# \"\"\"\n#\n# def add(self, elem):\n# \"\"\"\n# Set this NestedInteger to hold a nested list and adds a nested integer elem to it.\n# :rtype void\n# \"\"\"\n#\n# def setInteger(self, value):\n# \"\"\"\n# Set this NestedInteger to hold a single integer equal to value.\n# :rtype void\n# \"\"\"\n#\n# def getInteger(self):\n# \"\"\"\n# @return the single integer that this NestedInteger holds, if it holds a single integer\n# Return None if this NestedInteger holds a nested list\n# :rtype int\n# \"\"\"\n#\n# def getList(self):\n# \"\"\"\n# @return the nested list that this NestedInteger holds, if it holds a nested list\n# Return None if this NestedInteger holds a single integer\n# :rtype List[NestedInteger]\n# \"\"\"\nclass Solution(object):\n def depthSum(self, nestedList):\n \"\"\"\n :type nestedList: List[NestedInteger]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# \"\"\"\n# This is the interface that allows for creating nested lists.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class NestedInteger:\n# def __init__(self, value=None):\n# \"\"\"\n# If value is not specified, initializes an empty list.\n# Otherwise initializes a single integer equal to value.\n# \"\"\"\n#\n# def isInteger(self):\n# \"\"\"\n# @return True if this NestedInteger holds a single integer, rather than a nested list.\n# :rtype bool\n# \"\"\"\n#\n# def add(self, elem):\n# \"\"\"\n# Set this NestedInteger to hold a nested list and adds a nested integer elem to it.\n# :rtype void\n# \"\"\"\n#\n# def setInteger(self, value):\n# \"\"\"\n# Set this NestedInteger to hold a single integer equal to value.\n# :rtype void\n# \"\"\"\n#\n# def getInteger(self):\n# \"\"\"\n# @return the single integer that this NestedInteger holds, if it holds a single integer\n# Return None if this NestedInteger holds a nested list\n# :rtype int\n# \"\"\"\n#\n# def getList(self):\n# \"\"\"\n# @return the nested list that this NestedInteger holds, if it holds a nested list\n# Return None if this NestedInteger holds a single integer\n# :rtype List[NestedInteger]\n# \"\"\"\nclass Solution:\n def depthSum(self, nestedList: List[NestedInteger]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * *********************************************************************\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * *********************************************************************\n *\n * // Initializes an empty nested list and return a reference to the nested integer.\n * struct NestedInteger *NestedIntegerInit();\n *\n * // Return true if this NestedInteger holds a single integer, rather than a nested list.\n * bool NestedIntegerIsInteger(struct NestedInteger *);\n *\n * // Return the single integer that this NestedInteger holds, if it holds a single integer\n * // The result is undefined if this NestedInteger holds a nested list\n * int NestedIntegerGetInteger(struct NestedInteger *);\n *\n * // Set this NestedInteger to hold a single integer.\n * void NestedIntegerSetInteger(struct NestedInteger *ni, int value);\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer elem to it.\n * void NestedIntegerAdd(struct NestedInteger *ni, struct NestedInteger *elem);\n *\n * // Return the nested list that this NestedInteger holds, if it holds a nested list\n * // The result is undefined if this NestedInteger holds a single integer\n * struct NestedInteger **NestedIntegerGetList(struct NestedInteger *);\n *\n * // Return the nested list's size that this NestedInteger holds, if it holds a nested list\n * // The result is undefined if this NestedInteger holds a single integer\n * int NestedIntegerGetListSize(struct NestedInteger *);\n * };\n */\n\n\nint depthSum(struct NestedInteger** nestedList, int nestedListSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * interface NestedInteger {\n *\n * // Constructor initializes an empty nested list.\n * public NestedInteger();\n *\n * // Constructor initializes a single integer.\n * public NestedInteger(int value);\n *\n * // @return true if this NestedInteger holds a single integer, rather than a nested list.\n * bool IsInteger();\n *\n * // @return the single integer that this NestedInteger holds, if it holds a single integer\n * // Return null if this NestedInteger holds a nested list\n * int GetInteger();\n *\n * // Set this NestedInteger to hold a single integer.\n * public void SetInteger(int value);\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * public void Add(NestedInteger ni);\n *\n * // @return the nested list that this NestedInteger holds, if it holds a nested list\n * // Return null if this NestedInteger holds a single integer\n * IList GetList();\n * }\n */\npublic class Solution {\n public int DepthSum(IList nestedList) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * function NestedInteger() {\n *\n * Return true if this NestedInteger holds a single integer, rather than a nested list.\n * @return {boolean}\n * this.isInteger = function() {\n * ...\n * };\n *\n * Return the single integer that this NestedInteger holds, if it holds a single integer\n * Return null if this NestedInteger holds a nested list\n * @return {integer}\n * this.getInteger = function() {\n * ...\n * };\n *\n * Set this NestedInteger to hold a single integer equal to value.\n * @return {void}\n * this.setInteger = function(value) {\n * ...\n * };\n *\n * Set this NestedInteger to hold a nested list and adds a nested integer elem to it.\n * @return {void}\n * this.add = function(elem) {\n * ...\n * };\n *\n * Return the nested list that this NestedInteger holds, if it holds a nested list\n * Return null if this NestedInteger holds a single integer\n * @return {NestedInteger[]}\n * this.getList = function() {\n * ...\n * };\n * };\n */\n/**\n * @param {NestedInteger[]} nestedList\n * @return {number}\n */\nvar depthSum = function(nestedList) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# This is the interface that allows for creating nested lists.\n# You should not implement it, or speculate about its implementation\n#\n#class NestedInteger\n# def is_integer()\n# \"\"\"\n# Return true if this NestedInteger holds a single integer, rather than a nested list.\n# @return {Boolean}\n# \"\"\"\n#\n# def get_integer()\n# \"\"\"\n# Return the single integer that this NestedInteger holds, if it holds a single integer\n# Return nil if this NestedInteger holds a nested list\n# @return {Integer}\n# \"\"\"\n#\n# def set_integer(value)\n# \"\"\"\n# Set this NestedInteger to hold a single integer equal to value.\n# @return {Void}\n# \"\"\"\n#\n# def add(elem)\n# \"\"\"\n# Set this NestedInteger to hold a nested list and adds a nested integer elem to it.\n# @return {Void}\n# \"\"\"\n#\n# def get_list()\n# \"\"\"\n# Return the nested list that this NestedInteger holds, if it holds a nested list\n# Return nil if this NestedInteger holds a single integer\n# @return {NestedInteger[]}\n# \"\"\"\n# @param {NestedInteger[]} nested_list\n# @return {Integer}\ndef depth_sum(nested_list)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * class NestedInteger {\n * // Return true if this NestedInteger holds a single integer, rather than a nested list.\n * public func isInteger() -> Bool\n *\n * // Return the single integer that this NestedInteger holds, if it holds a single integer\n * // The result is undefined if this NestedInteger holds a nested list\n * public func getInteger() -> Int\n *\n * // Set this NestedInteger to hold a single integer.\n * public func setInteger(value: Int)\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * public func add(elem: NestedInteger)\n *\n * // Return the nested list that this NestedInteger holds, if it holds a nested list\n * // The result is undefined if this NestedInteger holds a single integer\n * public func getList() -> [NestedInteger]\n * }\n */\nclass Solution {\n func depthSum(_ nestedList: [NestedInteger]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * type NestedInteger struct {\n * }\n *\n * // Return true if this NestedInteger holds a single integer, rather than a nested list.\n * func (n NestedInteger) IsInteger() bool {}\n *\n * // Return the single integer that this NestedInteger holds, if it holds a single integer\n * // The result is undefined if this NestedInteger holds a nested list\n * // So before calling this method, you should have a check\n * func (n NestedInteger) GetInteger() int {}\n *\n * // Set this NestedInteger to hold a single integer.\n * func (n *NestedInteger) SetInteger(value int) {}\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * func (n *NestedInteger) Add(elem NestedInteger) {}\n *\n * // Return the nested list that this NestedInteger holds, if it holds a nested list\n * // The list length is zero if this NestedInteger holds a single integer\n * // You can access NestedInteger's List element directly if you want to modify it\n * func (n NestedInteger) GetList() []*NestedInteger {}\n */\nfunc depthSum(nestedList []*NestedInteger) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * trait NestedInteger {\n *\n * // Return true if this NestedInteger holds a single integer, rather than a nested list.\n * def isInteger: Boolean\n *\n * // Return the single integer that this NestedInteger holds, if it holds a single integer.\n * def getInteger: Int\n *\n * // Set this NestedInteger to hold a single integer.\n * def setInteger(i: Int): Unit\n *\n * // Return the nested list that this NestedInteger holds, if it holds a nested list.\n * def getList: Array[NestedInteger]\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * def add(ni: NestedInteger): Unit\n * }\n */\nobject Solution {\n def depthSum(nestedList: List[NestedInteger]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * class NestedInteger {\n * // Constructor initializes an empty nested list.\n * constructor()\n *\n * // Constructor initializes a single integer.\n * constructor(value: Int)\n *\n * // @return true if this NestedInteger holds a single integer, rather than a nested list.\n * fun isInteger(): Boolean\n *\n * // @return the single integer that this NestedInteger holds, if it holds a single integer\n * // Return null if this NestedInteger holds a nested list\n * fun getInteger(): Int?\n *\n * // Set this NestedInteger to hold a single integer.\n * fun setInteger(value: Int): Unit\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * fun add(ni: NestedInteger): Unit\n *\n * // @return the nested list that this NestedInteger holds, if it holds a nested list\n * // Return null if this NestedInteger holds a single integer\n * fun getList(): List?\n * }\n */\nclass Solution {\n fun depthSum(nestedList: List): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// #[derive(Debug, PartialEq, Eq)]\n// pub enum NestedInteger {\n// Int(i32),\n// List(Vec)\n// }\nimpl Solution {\n pub fn depth_sum(nested_list: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * class NestedInteger {\n\n * // if value is not specified, initializes an empty list.\n * // Otherwise initializes a single integer equal to value.\n * function __construct($value = null)\n\n * // Return true if this NestedInteger holds a single integer, rather than a nested list.\n * function isInteger() : bool\n *\n * // Return the single integer that this NestedInteger holds, if it holds a single integer\n * // The result is undefined if this NestedInteger holds a nested list\n * function getInteger()\n *\n * // Set this NestedInteger to hold a single integer.\n * function setInteger($i) : void\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * function add($ni) : void\n *\n * // Return the nested list that this NestedInteger holds, if it holds a nested list\n * // The result is undefined if this NestedInteger holds a single integer\n * function getList() : array\n * }\n */\nclass Solution {\n\n /**\n * @param NestedInteger[] $nestedList\n * @return Integer\n */\n function depthSum($nestedList) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * class NestedInteger {\n * If value is provided, then it holds a single integer\n * Otherwise it holds an empty nested list\n * constructor(value?: number) {\n * ...\n * };\n *\n * Return true if this NestedInteger holds a single integer, rather than a nested list.\n * isInteger(): boolean {\n * ...\n * };\n *\n * Return the single integer that this NestedInteger holds, if it holds a single integer\n * Return null if this NestedInteger holds a nested list\n * getInteger(): number | null {\n * ...\n * };\n *\n * Set this NestedInteger to hold a single integer equal to value.\n * setInteger(value: number) {\n * ...\n * };\n *\n * Set this NestedInteger to hold a nested list and adds a nested integer elem to it.\n * add(elem: NestedInteger) {\n * ...\n * };\n *\n * Return the nested list that this NestedInteger holds,\n * or an empty list if this NestedInteger holds a single integer\n * getList(): NestedInteger[] {\n * ...\n * };\n * };\n */\n\nfunction depthSum(nestedList: NestedInteger[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": ";; This is the interface that allows for creating nested lists.\n;; You should not implement it, or speculate about its implementation\n\n#|\n\n(define nested-integer%\n (class object%\n ...\n\n ; Return true if this nested-integer% holds a single integer, rather than a nested list.\n ; -> boolean?\n (define/public (is-integer)\n ...)\n\n ; Return the single integer that this nested-integer% holds, if it holds a single integer,\n ; or #f if this nested-integer% holds a nested list.\n ; -> integer?\n (define/public (get-integer)\n ...)\n\n ; Set this nested-integer% to hold a single integer equal to value.\n ; -> integer? void?\n (define/public (set-integer i)\n ...)\n\n ; Set this nested-integer% to hold a nested list and adds a nested integer elem to it.\n ; -> (is-a?/c nested-integer%) void?\n (define/public (add ni)\n ...)\n\n ; Return the nested list that this nested-integer% holds,\n ; or an empty list if this nested-integer% holds a single integer.\n ; -> gvector?\n (define/public (get-list)\n ...)))\n\n|#\n\n(define/contract (depth-sum nestedList)\n (-> (listof (is-a?/c nested-integer%)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0339](https://leetcode-cn.com/problems/nested-list-weight-sum)", "[\u5d4c\u5957\u5217\u8868\u6743\u91cd\u548c](/solution/0300-0399/0339.Nested%20List%20Weight%20Sum/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0339](https://leetcode.com/problems/nested-list-weight-sum)", "[Nested List Weight Sum](/solution/0300-0399/0339.Nested%20List%20Weight%20Sum/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`", "Medium", "\ud83d\udd12"]}, {"question_id": "0338", "frontend_question_id": "0338", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/counting-bits", "url_en": "https://leetcode.com/problems/counting-bits", "relative_path_cn": "/solution/0300-0399/0338.Counting%20Bits/README.md", "relative_path_en": "/solution/0300-0399/0338.Counting%20Bits/README_EN.md", "title_cn": "\u6bd4\u7279\u4f4d\u8ba1\u6570", "title_en": "Counting Bits", "question_title_slug": "counting-bits", "content_en": "

    Given an integer n, return an array ans of length n + 1 such that for each i (0 <= i <= n), ans[i] is the number of 1's in the binary representation of i.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 2\nOutput: [0,1,1]\nExplanation:\n0 --> 0\n1 --> 1\n2 --> 10\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 5\nOutput: [0,1,1,2,1,2]\nExplanation:\n0 --> 0\n1 --> 1\n2 --> 10\n3 --> 11\n4 --> 100\n5 --> 101\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= n <= 105
    • \n
    \n\n

     

    \n

    Follow up:

    \n\n
      \n\t
    • It is very easy to come up with a solution with a runtime of O(n log n). Can you do it in linear time O(n) and possibly in a single pass?
    • \n\t
    • Can you do it without using any built-in function (i.e., like __builtin_popcount in C++)?
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u8d1f\u6574\u6570 num\u3002\u5bf9\u4e8e 0 ≤ i ≤ num \u8303\u56f4\u4e2d\u7684\u6bcf\u4e2a\u6570\u5b57 \uff0c\u8ba1\u7b97\u5176\u4e8c\u8fdb\u5236\u6570\u4e2d\u7684 1 \u7684\u6570\u76ee\u5e76\u5c06\u5b83\u4eec\u4f5c\u4e3a\u6570\u7ec4\u8fd4\u56de\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: 2\n\u8f93\u51fa: [0,1,1]
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: 5\n\u8f93\u51fa: [0,1,1,2,1,2]
    \n\n

    \u8fdb\u9636:

    \n\n
      \n\t
    • \u7ed9\u51fa\u65f6\u95f4\u590d\u6742\u5ea6\u4e3aO(n*sizeof(integer))\u7684\u89e3\u7b54\u975e\u5e38\u5bb9\u6613\u3002\u4f46\u4f60\u53ef\u4ee5\u5728\u7ebf\u6027\u65f6\u95f4O(n)\u5185\u7528\u4e00\u8d9f\u626b\u63cf\u505a\u5230\u5417\uff1f
    • \n\t
    • \u8981\u6c42\u7b97\u6cd5\u7684\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3aO(n)\u3002
    • \n\t
    • \u4f60\u80fd\u8fdb\u4e00\u6b65\u5b8c\u5584\u89e3\u6cd5\u5417\uff1f\u8981\u6c42\u5728C++\u6216\u4efb\u4f55\u5176\u4ed6\u8bed\u8a00\u4e2d\u4e0d\u4f7f\u7528\u4efb\u4f55\u5185\u7f6e\u51fd\u6570\uff08\u5982 C++ \u4e2d\u7684 __builtin_popcount\uff09\u6765\u6267\u884c\u6b64\u64cd\u4f5c\u3002
    • \n
    \n", "tags_en": ["Bit Manipulation", "Dynamic Programming"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector countBits(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] countBits(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countBits(self, n):\n \"\"\"\n :type n: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countBits(self, n: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* countBits(int n, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] CountBits(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number[]}\n */\nvar countBits = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer[]}\ndef count_bits(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countBits(_ n: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countBits(n int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countBits(n: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countBits(n: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_bits(n: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer[]\n */\n function countBits($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countBits(n: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-bits n)\n (-> exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0338](https://leetcode-cn.com/problems/counting-bits)", "[\u6bd4\u7279\u4f4d\u8ba1\u6570](/solution/0300-0399/0338.Counting%20Bits/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u52a8\u6001\u89c4\u5212`", "\u7b80\u5355", ""], "md_table_row_en": ["[0338](https://leetcode.com/problems/counting-bits)", "[Counting Bits](/solution/0300-0399/0338.Counting%20Bits/README_EN.md)", "`Bit Manipulation`,`Dynamic Programming`", "Easy", ""]}, {"question_id": "0337", "frontend_question_id": "0337", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/house-robber-iii", "url_en": "https://leetcode.com/problems/house-robber-iii", "relative_path_cn": "/solution/0300-0399/0337.House%20Robber%20III/README.md", "relative_path_en": "/solution/0300-0399/0337.House%20Robber%20III/README_EN.md", "title_cn": "\u6253\u5bb6\u52ab\u820d III", "title_en": "House Robber III", "question_title_slug": "house-robber-iii", "content_en": "

    The thief has found himself a new place for his thievery again. There is only one entrance to this area, called root.

    \n\n

    Besides the root, each house has one and only one parent house. After a tour, the smart thief realized that all houses in this place form a binary tree. It will automatically contact the police if two directly-linked houses were broken into on the same night.

    \n\n

    Given the root of the binary tree, return the maximum amount of money the thief can rob without alerting the police.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [3,2,3,null,3,null,1]\nOutput: 7\nExplanation: Maximum amount of money the thief can rob = 3 + 3 + 1 = 7.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [3,4,5,1,3,null,1]\nOutput: 9\nExplanation: Maximum amount of money the thief can rob = 4 + 5 = 9.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 104].
    • \n\t
    • 0 <= Node.val <= 104
    • \n
    \n", "content_cn": "

    \u5728\u4e0a\u6b21\u6253\u52ab\u5b8c\u4e00\u6761\u8857\u9053\u4e4b\u540e\u548c\u4e00\u5708\u623f\u5c4b\u540e\uff0c\u5c0f\u5077\u53c8\u53d1\u73b0\u4e86\u4e00\u4e2a\u65b0\u7684\u53ef\u884c\u7a83\u7684\u5730\u533a\u3002\u8fd9\u4e2a\u5730\u533a\u53ea\u6709\u4e00\u4e2a\u5165\u53e3\uff0c\u6211\u4eec\u79f0\u4e4b\u4e3a“\u6839”\u3002 \u9664\u4e86“\u6839”\u4e4b\u5916\uff0c\u6bcf\u680b\u623f\u5b50\u6709\u4e14\u53ea\u6709\u4e00\u4e2a“\u7236“\u623f\u5b50\u4e0e\u4e4b\u76f8\u8fde\u3002\u4e00\u756a\u4fa6\u5bdf\u4e4b\u540e\uff0c\u806a\u660e\u7684\u5c0f\u5077\u610f\u8bc6\u5230“\u8fd9\u4e2a\u5730\u65b9\u7684\u6240\u6709\u623f\u5c4b\u7684\u6392\u5217\u7c7b\u4f3c\u4e8e\u4e00\u68f5\u4e8c\u53c9\u6811”\u3002 \u5982\u679c\u4e24\u4e2a\u76f4\u63a5\u76f8\u8fde\u7684\u623f\u5b50\u5728\u540c\u4e00\u5929\u665a\u4e0a\u88ab\u6253\u52ab\uff0c\u623f\u5c4b\u5c06\u81ea\u52a8\u62a5\u8b66\u3002

    \n\n

    \u8ba1\u7b97\u5728\u4e0d\u89e6\u52a8\u8b66\u62a5\u7684\u60c5\u51b5\u4e0b\uff0c\u5c0f\u5077\u4e00\u665a\u80fd\u591f\u76d7\u53d6\u7684\u6700\u9ad8\u91d1\u989d\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: [3,2,3,null,3,null,1]\n\n     3\n    / \\\n   2   3\n    \\   \\ \n     3   1\n\n\u8f93\u51fa: 7 \n\u89e3\u91ca: \u5c0f\u5077\u4e00\u665a\u80fd\u591f\u76d7\u53d6\u7684\u6700\u9ad8\u91d1\u989d = 3 + 3 + 1 = 7.
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: [3,4,5,1,3,null,1]\n\n     3\n    / \\\n   4   5\n  / \\   \\ \n 1   3   1\n\n\u8f93\u51fa: 9\n\u89e3\u91ca: \u5c0f\u5077\u4e00\u665a\u80fd\u591f\u76d7\u53d6\u7684\u6700\u9ad8\u91d1\u989d = 4 + 5 = 9.\n
    \n", "tags_en": ["Tree", "Depth-first Search", "Dynamic Programming"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int rob(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int rob(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def rob(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def rob(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint rob(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int Rob(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar rob = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef rob(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func rob(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc rob(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def rob(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun rob(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn rob(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function rob($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction rob(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (rob root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0337](https://leetcode-cn.com/problems/house-robber-iii)", "[\u6253\u5bb6\u52ab\u820d III](/solution/0300-0399/0337.House%20Robber%20III/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0337](https://leetcode.com/problems/house-robber-iii)", "[House Robber III](/solution/0300-0399/0337.House%20Robber%20III/README_EN.md)", "`Tree`,`Depth-first Search`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0336", "frontend_question_id": "0336", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/palindrome-pairs", "url_en": "https://leetcode.com/problems/palindrome-pairs", "relative_path_cn": "/solution/0300-0399/0336.Palindrome%20Pairs/README.md", "relative_path_en": "/solution/0300-0399/0336.Palindrome%20Pairs/README_EN.md", "title_cn": "\u56de\u6587\u5bf9", "title_en": "Palindrome Pairs", "question_title_slug": "palindrome-pairs", "content_en": "

    Given a list of unique words, return all the pairs of the distinct indices (i, j) in the given list, so that the concatenation of the two words words[i] + words[j] is a palindrome.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: words = ["abcd","dcba","lls","s","sssll"]\nOutput: [[0,1],[1,0],[3,2],[2,4]]\nExplanation: The palindromes are ["dcbaabcd","abcddcba","slls","llssssll"]\n
    \n\n

    Example 2:

    \n\n
    \nInput: words = ["bat","tab","cat"]\nOutput: [[0,1],[1,0]]\nExplanation: The palindromes are ["battab","tabbat"]\n
    \n\n

    Example 3:

    \n\n
    \nInput: words = ["a",""]\nOutput: [[0,1],[1,0]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= words.length <= 5000
    • \n\t
    • 0 <= words[i].length <= 300
    • \n\t
    • words[i] consists of lower-case English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u7ec4 \u4e92\u4e0d\u76f8\u540c \u7684\u5355\u8bcd\uff0c \u627e\u51fa\u6240\u6709 \u4e0d\u540c\u00a0\u7684\u7d22\u5f15\u5bf9 (i, j)\uff0c\u4f7f\u5f97\u5217\u8868\u4e2d\u7684\u4e24\u4e2a\u5355\u8bcd\uff0c\u00a0words[i] + words[j]\u00a0\uff0c\u53ef\u62fc\u63a5\u6210\u56de\u6587\u4e32\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1awords = [\"abcd\",\"dcba\",\"lls\",\"s\",\"sssll\"]\n\u8f93\u51fa\uff1a[[0,1],[1,0],[3,2],[2,4]] \n\u89e3\u91ca\uff1a\u53ef\u62fc\u63a5\u6210\u7684\u56de\u6587\u4e32\u4e3a [\"dcbaabcd\",\"abcddcba\",\"slls\",\"llssssll\"]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1awords = [\"bat\",\"tab\",\"cat\"]\n\u8f93\u51fa\uff1a[[0,1],[1,0]] \n\u89e3\u91ca\uff1a\u53ef\u62fc\u63a5\u6210\u7684\u56de\u6587\u4e32\u4e3a [\"battab\",\"tabbat\"]
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1awords = [\"a\",\"\"]\n\u8f93\u51fa\uff1a[[0,1],[1,0]]\n
    \n\u00a0\n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= words.length <= 5000
    • \n\t
    • 0 <= words[i].length <= 300
    • \n\t
    • words[i] \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n", "tags_en": ["Trie", "Hash Table", "String"], "tags_cn": ["\u5b57\u5178\u6811", "\u54c8\u5e0c\u8868", "\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> palindromePairs(vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> palindromePairs(String[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def palindromePairs(self, words):\n \"\"\"\n :type words: List[str]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def palindromePairs(self, words: List[str]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** palindromePairs(char ** words, int wordsSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> PalindromePairs(string[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @return {number[][]}\n */\nvar palindromePairs = function(words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @return {Integer[][]}\ndef palindrome_pairs(words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func palindromePairs(_ words: [String]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func palindromePairs(words []string) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def palindromePairs(words: Array[String]): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun palindromePairs(words: Array): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn palindrome_pairs(words: Vec) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @return Integer[][]\n */\n function palindromePairs($words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function palindromePairs(words: string[]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (palindrome-pairs words)\n (-> (listof string?) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0336](https://leetcode-cn.com/problems/palindrome-pairs)", "[\u56de\u6587\u5bf9](/solution/0300-0399/0336.Palindrome%20Pairs/README.md)", "`\u5b57\u5178\u6811`,`\u54c8\u5e0c\u8868`,`\u5b57\u7b26\u4e32`", "\u56f0\u96be", ""], "md_table_row_en": ["[0336](https://leetcode.com/problems/palindrome-pairs)", "[Palindrome Pairs](/solution/0300-0399/0336.Palindrome%20Pairs/README_EN.md)", "`Trie`,`Hash Table`,`String`", "Hard", ""]}, {"question_id": "0335", "frontend_question_id": "0335", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/self-crossing", "url_en": "https://leetcode.com/problems/self-crossing", "relative_path_cn": "/solution/0300-0399/0335.Self%20Crossing/README.md", "relative_path_en": "/solution/0300-0399/0335.Self%20Crossing/README_EN.md", "title_cn": "\u8def\u5f84\u4ea4\u53c9", "title_en": "Self Crossing", "question_title_slug": "self-crossing", "content_en": "

    You are given an array of integers distance.

    \n\n

    You start at point (0,0) on an X-Y plane and you move distance[0] meters to the north, then distance[1] meters to the west, distance[2] meters to the south, distance[3] meters to the east, and so on. In other words, after each move, your direction changes counter-clockwise.

    \n\n

    Return true if your path crosses itself, and false if it does not.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: distance = [2,1,1,2]\nOutput: true\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: distance = [1,2,3,4]\nOutput: false\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: distance = [1,1,1,1]\nOutput: true\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= distance.length <= 105
    • \n\t
    • 1 <= distance[i] <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u542b\u6709 n \u4e2a\u6b63\u6570\u7684\u6570\u7ec4 x\u3002\u4ece\u70b9 (0,0) \u5f00\u59cb\uff0c\u5148\u5411\u5317\u79fb\u52a8 x[0] \u7c73\uff0c\u7136\u540e\u5411\u897f\u79fb\u52a8 x[1] \u7c73\uff0c\u5411\u5357\u79fb\u52a8 x[2] \u7c73\uff0c\u5411\u4e1c\u79fb\u52a8 x[3] \u7c73\uff0c\u6301\u7eed\u79fb\u52a8\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u6bcf\u6b21\u79fb\u52a8\u540e\u4f60\u7684\u65b9\u4f4d\u4f1a\u53d1\u751f\u9006\u65f6\u9488\u53d8\u5316\u3002

    \n\n

    \u7f16\u5199\u4e00\u4e2a O(1) \u7a7a\u95f4\u590d\u6742\u5ea6\u7684\u4e00\u8d9f\u626b\u63cf\u7b97\u6cd5\uff0c\u5224\u65ad\u4f60\u6240\u7ecf\u8fc7\u7684\u8def\u5f84\u662f\u5426\u76f8\u4ea4\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u250c\u2500\u2500\u2500\u2510\n\u2502   \u2502\n\u2514\u2500\u2500\u2500\u253c\u2500\u2500>\n    \u2502\n\n\u8f93\u5165: [2,1,1,2]\n\u8f93\u51fa: true \n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n\u2502      \u2502\n\u2502\n\u2502\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500>\n\n\u8f93\u5165: [1,2,3,4]\n\u8f93\u51fa: false \n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u250c\u2500\u2500\u2500\u2510\n\u2502   \u2502\n\u2514\u2500\u2500\u2500\u253c>\n\n\u8f93\u5165: [1,1,1,1]\n\u8f93\u51fa: true \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isSelfCrossing(vector& distance) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isSelfCrossing(int[] distance) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isSelfCrossing(self, distance):\n \"\"\"\n :type distance: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isSelfCrossing(self, distance: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isSelfCrossing(int* distance, int distanceSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsSelfCrossing(int[] distance) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} distance\n * @return {boolean}\n */\nvar isSelfCrossing = function(distance) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} distance\n# @return {Boolean}\ndef is_self_crossing(distance)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isSelfCrossing(_ distance: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isSelfCrossing(distance []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isSelfCrossing(distance: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isSelfCrossing(distance: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_self_crossing(distance: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $distance\n * @return Boolean\n */\n function isSelfCrossing($distance) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isSelfCrossing(distance: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-self-crossing distance)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0335](https://leetcode-cn.com/problems/self-crossing)", "[\u8def\u5f84\u4ea4\u53c9](/solution/0300-0399/0335.Self%20Crossing/README.md)", "`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[0335](https://leetcode.com/problems/self-crossing)", "[Self Crossing](/solution/0300-0399/0335.Self%20Crossing/README_EN.md)", "`Math`", "Hard", ""]}, {"question_id": "0334", "frontend_question_id": "0334", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/increasing-triplet-subsequence", "url_en": "https://leetcode.com/problems/increasing-triplet-subsequence", "relative_path_cn": "/solution/0300-0399/0334.Increasing%20Triplet%20Subsequence/README.md", "relative_path_en": "/solution/0300-0399/0334.Increasing%20Triplet%20Subsequence/README_EN.md", "title_cn": "\u9012\u589e\u7684\u4e09\u5143\u5b50\u5e8f\u5217", "title_en": "Increasing Triplet Subsequence", "question_title_slug": "increasing-triplet-subsequence", "content_en": "

    Given an integer array nums, return true if there exists a triple of indices (i, j, k) such that i < j < k and nums[i] < nums[j] < nums[k]. If no such indices exists, return false.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,3,4,5]\nOutput: true\nExplanation: Any triplet where i < j < k is valid.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [5,4,3,2,1]\nOutput: false\nExplanation: No triplet exists.\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [2,1,5,0,4,6]\nOutput: true\nExplanation: The triplet (3, 4, 5) is valid because nums[3] == 0 < nums[4] == 4 < nums[5] == 6.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 5 * 105
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n
    \n\n

     

    \nFollow up: Could you implement a solution that runs in O(n) time complexity and O(1) space complexity?", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0nums \uff0c\u5224\u65ad\u8fd9\u4e2a\u6570\u7ec4\u4e2d\u662f\u5426\u5b58\u5728\u957f\u5ea6\u4e3a 3 \u7684\u9012\u589e\u5b50\u5e8f\u5217\u3002

    \n\n

    \u5982\u679c\u5b58\u5728\u8fd9\u6837\u7684\u4e09\u5143\u7ec4\u4e0b\u6807 (i, j, k)\u00a0\u4e14\u6ee1\u8db3 i < j < k \uff0c\u4f7f\u5f97\u00a0nums[i] < nums[j] < nums[k] \uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,3,4,5]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u4efb\u4f55 i < j < k \u7684\u4e09\u5143\u7ec4\u90fd\u6ee1\u8db3\u9898\u610f\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [5,4,3,2,1]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u4e0d\u5b58\u5728\u6ee1\u8db3\u9898\u610f\u7684\u4e09\u5143\u7ec4
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [2,1,5,0,4,6]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u4e09\u5143\u7ec4 (3, 4, 5) \u6ee1\u8db3\u9898\u610f\uff0c\u56e0\u4e3a nums[3] == 0 < nums[4] == 4 < nums[5] == 6\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u80fd\u5b9e\u73b0\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n) \uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a O(1) \u7684\u89e3\u51b3\u65b9\u6848\u5417\uff1f

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool increasingTriplet(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean increasingTriplet(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def increasingTriplet(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def increasingTriplet(self, nums: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool increasingTriplet(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IncreasingTriplet(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {boolean}\n */\nvar increasingTriplet = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Boolean}\ndef increasing_triplet(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func increasingTriplet(_ nums: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func increasingTriplet(nums []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def increasingTriplet(nums: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun increasingTriplet(nums: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn increasing_triplet(nums: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Boolean\n */\n function increasingTriplet($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function increasingTriplet(nums: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (increasing-triplet nums)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0334](https://leetcode-cn.com/problems/increasing-triplet-subsequence)", "[\u9012\u589e\u7684\u4e09\u5143\u5b50\u5e8f\u5217](/solution/0300-0399/0334.Increasing%20Triplet%20Subsequence/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0334](https://leetcode.com/problems/increasing-triplet-subsequence)", "[Increasing Triplet Subsequence](/solution/0300-0399/0334.Increasing%20Triplet%20Subsequence/README_EN.md)", "", "Medium", ""]}, {"question_id": "0333", "frontend_question_id": "0333", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/largest-bst-subtree", "url_en": "https://leetcode.com/problems/largest-bst-subtree", "relative_path_cn": "/solution/0300-0399/0333.Largest%20BST%20Subtree/README.md", "relative_path_en": "/solution/0300-0399/0333.Largest%20BST%20Subtree/README_EN.md", "title_cn": "\u6700\u5927 BST \u5b50\u6811", "title_en": "Largest BST Subtree", "question_title_slug": "largest-bst-subtree", "content_en": "

    Given the root of a binary tree, find the largest subtree, which is also a Binary Search Tree (BST), where the largest means subtree has the largest number of nodes.

    \n\n

    A Binary Search Tree (BST) is a tree in which all the nodes follow the below-mentioned properties:

    \n\n
      \n\t
    • The left subtree values are less than the value of their parent (root) node's value.
    • \n\t
    • The right subtree values are greater than the value of their parent (root) node's value.
    • \n
    \n\n

    Note: A subtree must include all of its descendants.

    \n\n

    Follow up: Can you figure out ways to solve it with O(n) time complexity?

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: root = [10,5,15,1,8,null,7]\nOutput: 3\nExplanation: The Largest BST Subtree in this case is the highlighted one. The return value is the subtree's size, which is 3.
    \n\n

    Example 2:

    \n\n
    \nInput: root = [4,2,7,2,3,5,null,2,null,null,null,null,null,1]\nOutput: 2\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [0, 104].
    • \n\t
    • -104 <= Node.val <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811\uff0c\u627e\u5230\u5176\u4e2d\u6700\u5927\u7684\u4e8c\u53c9\u641c\u7d22\u6811\uff08BST\uff09\u5b50\u6811\uff0c\u5e76\u8fd4\u56de\u8be5\u5b50\u6811\u7684\u5927\u5c0f\u3002\u5176\u4e2d\uff0c\u6700\u5927\u6307\u7684\u662f\u5b50\u6811\u8282\u70b9\u6570\u6700\u591a\u7684\u3002

    \n\n

    \u4e8c\u53c9\u641c\u7d22\u6811\uff08BST\uff09\u4e2d\u7684\u6240\u6709\u8282\u70b9\u90fd\u5177\u5907\u4ee5\u4e0b\u5c5e\u6027\uff1a

    \n\n
      \n\t
    • \n\t

      \u5de6\u5b50\u6811\u7684\u503c\u5c0f\u4e8e\u5176\u7236\uff08\u6839\uff09\u8282\u70b9\u7684\u503c\u3002

      \n\t
    • \n\t
    • \n\t

      \u53f3\u5b50\u6811\u7684\u503c\u5927\u4e8e\u5176\u7236\uff08\u6839\uff09\u8282\u70b9\u7684\u503c\u3002

      \n\t
    • \n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    • \u5b50\u6811\u5fc5\u987b\u5305\u542b\u5176\u6240\u6709\u540e\u4ee3\u3002
    • \n
    \n\n

    \u8fdb\u9636:

    \n\n
      \n\t
    • \u4f60\u80fd\u60f3\u51fa O(n) \u65f6\u95f4\u590d\u6742\u5ea6\u7684\u89e3\u6cd5\u5417\uff1f
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aroot = [10,5,15,1,8,null,7]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u672c\u4f8b\u4e2d\u6700\u5927\u7684 BST \u5b50\u6811\u662f\u9ad8\u4eae\u663e\u793a\u7684\u5b50\u6811\u3002\u8fd4\u56de\u503c\u662f\u5b50\u6811\u7684\u5927\u5c0f\uff0c\u5373 3 \u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [4,2,7,2,3,5,null,2,null,null,null,null,null,1]\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e0a\u8282\u70b9\u6570\u76ee\u7684\u8303\u56f4\u662f [0, 104]
    • \n\t
    • -104 <= Node.val <= 104
    • \n
    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int largestBSTSubtree(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int largestBSTSubtree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def largestBSTSubtree(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def largestBSTSubtree(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint largestBSTSubtree(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int LargestBSTSubtree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar largestBSTSubtree = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef largest_bst_subtree(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func largestBSTSubtree(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc largestBSTSubtree(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def largestBSTSubtree(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun largestBSTSubtree(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn largest_bst_subtree(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function largestBSTSubtree($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction largestBSTSubtree(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (largest-bst-subtree root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0333](https://leetcode-cn.com/problems/largest-bst-subtree)", "[\u6700\u5927 BST \u5b50\u6811](/solution/0300-0399/0333.Largest%20BST%20Subtree/README.md)", "`\u6811`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0333](https://leetcode.com/problems/largest-bst-subtree)", "[Largest BST Subtree](/solution/0300-0399/0333.Largest%20BST%20Subtree/README_EN.md)", "`Tree`", "Medium", "\ud83d\udd12"]}, {"question_id": "0332", "frontend_question_id": "0332", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reconstruct-itinerary", "url_en": "https://leetcode.com/problems/reconstruct-itinerary", "relative_path_cn": "/solution/0300-0399/0332.Reconstruct%20Itinerary/README.md", "relative_path_en": "/solution/0300-0399/0332.Reconstruct%20Itinerary/README_EN.md", "title_cn": "\u91cd\u65b0\u5b89\u6392\u884c\u7a0b", "title_en": "Reconstruct Itinerary", "question_title_slug": "reconstruct-itinerary", "content_en": "

    You are given a list of airline tickets where tickets[i] = [fromi, toi] represent the departure and the arrival airports of one flight. Reconstruct the itinerary in order and return it.

    \n\n

    All of the tickets belong to a man who departs from "JFK", thus, the itinerary must begin with "JFK". If there are multiple valid itineraries, you should return the itinerary that has the smallest lexical order when read as a single string.

    \n\n
      \n\t
    • For example, the itinerary ["JFK", "LGA"] has a smaller lexical order than ["JFK", "LGB"].
    • \n
    \n\n

    You may assume all tickets form at least one valid itinerary. You must use all the tickets once and only once.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: tickets = [["MUC","LHR"],["JFK","MUC"],["SFO","SJC"],["LHR","SFO"]]\nOutput: ["JFK","MUC","LHR","SFO","SJC"]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: tickets = [["JFK","SFO"],["JFK","ATL"],["SFO","ATL"],["ATL","JFK"],["ATL","SFO"]]\nOutput: ["JFK","ATL","JFK","SFO","ATL","SFO"]\nExplanation: Another possible reconstruction is ["JFK","SFO","ATL","JFK","ATL","SFO"] but it is larger in lexical order.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= tickets.length <= 300
    • \n\t
    • tickets[i].length == 2
    • \n\t
    • fromi.length == 3
    • \n\t
    • toi.length == 3
    • \n\t
    • fromi and toi consist of uppercase English letters.
    • \n\t
    • fromi != toi
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u673a\u7968\u7684\u5b57\u7b26\u4e32\u4e8c\u7ef4\u6570\u7ec4 [from, to]\uff0c\u5b50\u6570\u7ec4\u4e2d\u7684\u4e24\u4e2a\u6210\u5458\u5206\u522b\u8868\u793a\u98de\u673a\u51fa\u53d1\u548c\u964d\u843d\u7684\u673a\u573a\u5730\u70b9\uff0c\u5bf9\u8be5\u884c\u7a0b\u8fdb\u884c\u91cd\u65b0\u89c4\u5212\u6392\u5e8f\u3002\u6240\u6709\u8fd9\u4e9b\u673a\u7968\u90fd\u5c5e\u4e8e\u4e00\u4e2a\u4ece JFK\uff08\u80af\u5c3c\u8fea\u56fd\u9645\u673a\u573a\uff09\u51fa\u53d1\u7684\u5148\u751f\uff0c\u6240\u4ee5\u8be5\u884c\u7a0b\u5fc5\u987b\u4ece JFK \u5f00\u59cb\u3002

    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. \u5982\u679c\u5b58\u5728\u591a\u79cd\u6709\u6548\u7684\u884c\u7a0b\uff0c\u8bf7\u4f60\u6309\u5b57\u7b26\u81ea\u7136\u6392\u5e8f\u8fd4\u56de\u6700\u5c0f\u7684\u884c\u7a0b\u7ec4\u5408\u3002\u4f8b\u5982\uff0c\u884c\u7a0b [\"JFK\", \"LGA\"] \u4e0e [\"JFK\", \"LGB\"] \u76f8\u6bd4\u5c31\u66f4\u5c0f\uff0c\u6392\u5e8f\u66f4\u9760\u524d
    2. \n\t
    3. \u6240\u6709\u7684\u673a\u573a\u90fd\u7528\u4e09\u4e2a\u5927\u5199\u5b57\u6bcd\u8868\u793a\uff08\u673a\u573a\u4ee3\u7801\uff09\u3002
    4. \n\t
    5. \u5047\u5b9a\u6240\u6709\u673a\u7968\u81f3\u5c11\u5b58\u5728\u4e00\u79cd\u5408\u7406\u7684\u884c\u7a0b\u3002
    6. \n\t
    7. \u6240\u6709\u7684\u673a\u7968\u5fc5\u987b\u90fd\u7528\u4e00\u6b21 \u4e14 \u53ea\u80fd\u7528\u4e00\u6b21\u3002
    8. \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[[\"MUC\", \"LHR\"], [\"JFK\", \"MUC\"], [\"SFO\", \"SJC\"], [\"LHR\", \"SFO\"]]\n\u8f93\u51fa\uff1a[\"JFK\", \"MUC\", \"LHR\", \"SFO\", \"SJC\"]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[[\"JFK\",\"SFO\"],[\"JFK\",\"ATL\"],[\"SFO\",\"ATL\"],[\"ATL\",\"JFK\"],[\"ATL\",\"SFO\"]]\n\u8f93\u51fa\uff1a[\"JFK\",\"ATL\",\"JFK\",\"SFO\",\"ATL\",\"SFO\"]\n\u89e3\u91ca\uff1a\u53e6\u4e00\u79cd\u6709\u6548\u7684\u884c\u7a0b\u662f\u00a0[\"JFK\",\"SFO\",\"ATL\",\"JFK\",\"ATL\",\"SFO\"]\u3002\u4f46\u662f\u5b83\u81ea\u7136\u6392\u5e8f\u66f4\u5927\u66f4\u9760\u540e\u3002
    \n", "tags_en": ["Depth-first Search", "Graph"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findItinerary(vector>& tickets) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List findItinerary(List> tickets) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findItinerary(self, tickets):\n \"\"\"\n :type tickets: List[List[str]]\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findItinerary(self, tickets: List[List[str]]) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** findItinerary(char *** tickets, int ticketsSize, int* ticketsColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList FindItinerary(IList> tickets) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[][]} tickets\n * @return {string[]}\n */\nvar findItinerary = function(tickets) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[][]} tickets\n# @return {String[]}\ndef find_itinerary(tickets)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findItinerary(_ tickets: [[String]]) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findItinerary(tickets [][]string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findItinerary(tickets: List[List[String]]): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findItinerary(tickets: List>): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_itinerary(tickets: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $tickets\n * @return String[]\n */\n function findItinerary($tickets) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findItinerary(tickets: string[][]): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-itinerary tickets)\n (-> (listof (listof string?)) (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0332](https://leetcode-cn.com/problems/reconstruct-itinerary)", "[\u91cd\u65b0\u5b89\u6392\u884c\u7a0b](/solution/0300-0399/0332.Reconstruct%20Itinerary/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u56fe`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0332](https://leetcode.com/problems/reconstruct-itinerary)", "[Reconstruct Itinerary](/solution/0300-0399/0332.Reconstruct%20Itinerary/README_EN.md)", "`Depth-first Search`,`Graph`", "Medium", ""]}, {"question_id": "0331", "frontend_question_id": "0331", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/verify-preorder-serialization-of-a-binary-tree", "url_en": "https://leetcode.com/problems/verify-preorder-serialization-of-a-binary-tree", "relative_path_cn": "/solution/0300-0399/0331.Verify%20Preorder%20Serialization%20of%20a%20Binary%20Tree/README.md", "relative_path_en": "/solution/0300-0399/0331.Verify%20Preorder%20Serialization%20of%20a%20Binary%20Tree/README_EN.md", "title_cn": "\u9a8c\u8bc1\u4e8c\u53c9\u6811\u7684\u524d\u5e8f\u5e8f\u5217\u5316", "title_en": "Verify Preorder Serialization of a Binary Tree", "question_title_slug": "verify-preorder-serialization-of-a-binary-tree", "content_en": "

    One way to serialize a binary tree is to use preorder traversal. When we encounter a non-null node, we record the node's value. If it is a null node, we record using a sentinel value such as '#'.

    \n\"\"\n

    For example, the above binary tree can be serialized to the string "9,3,4,#,#,1,#,#,2,#,6,#,#", where '#' represents a null node.

    \n\n

    Given a string of comma-separated values preorder, return true if it is a correct preorder traversal serialization of a binary tree.

    \n\n

    It is guaranteed that each comma-separated value in the string must be either an integer or a character '#' representing null pointer.

    \n\n

    You may assume that the input format is always valid.

    \n\n
      \n\t
    • For example, it could never contain two consecutive commas, such as "1,,3".
    • \n
    \n\n

    Note: You are not allowed to reconstruct the tree.

    \n\n

     

    \n

    Example 1:

    \n
    Input: preorder = \"9,3,4,#,#,1,#,#,2,#,6,#,#\"\nOutput: true\n

    Example 2:

    \n
    Input: preorder = \"1,#\"\nOutput: false\n

    Example 3:

    \n
    Input: preorder = \"9,#,#,1\"\nOutput: false\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= preorder.length <= 104
    • \n\t
    • preoder consist of integers in the range [0, 100] and '#' separated by commas ','.
    • \n
    \n", "content_cn": "

    \u5e8f\u5217\u5316\u4e8c\u53c9\u6811\u7684\u4e00\u79cd\u65b9\u6cd5\u662f\u4f7f\u7528\u524d\u5e8f\u904d\u5386\u3002\u5f53\u6211\u4eec\u9047\u5230\u4e00\u4e2a\u975e\u7a7a\u8282\u70b9\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u8bb0\u5f55\u4e0b\u8fd9\u4e2a\u8282\u70b9\u7684\u503c\u3002\u5982\u679c\u5b83\u662f\u4e00\u4e2a\u7a7a\u8282\u70b9\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e2a\u6807\u8bb0\u503c\u8bb0\u5f55\uff0c\u4f8b\u5982 #\u3002

    \n\n
         _9_\n    /   \\\n   3     2\n  / \\   / \\\n 4   1  #  6\n/ \\ / \\   / \\\n# # # #   # #\n
    \n\n

    \u4f8b\u5982\uff0c\u4e0a\u9762\u7684\u4e8c\u53c9\u6811\u53ef\u4ee5\u88ab\u5e8f\u5217\u5316\u4e3a\u5b57\u7b26\u4e32 "9,3,4,#,#,1,#,#,2,#,6,#,#"\uff0c\u5176\u4e2d # \u4ee3\u8868\u4e00\u4e2a\u7a7a\u8282\u70b9\u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u4e32\u4ee5\u9017\u53f7\u5206\u9694\u7684\u5e8f\u5217\uff0c\u9a8c\u8bc1\u5b83\u662f\u5426\u662f\u6b63\u786e\u7684\u4e8c\u53c9\u6811\u7684\u524d\u5e8f\u5e8f\u5217\u5316\u3002\u7f16\u5199\u4e00\u4e2a\u5728\u4e0d\u91cd\u6784\u6811\u7684\u6761\u4ef6\u4e0b\u7684\u53ef\u884c\u7b97\u6cd5\u3002

    \n\n

    \u6bcf\u4e2a\u4ee5\u9017\u53f7\u5206\u9694\u7684\u5b57\u7b26\u6216\u4e3a\u4e00\u4e2a\u6574\u6570\u6216\u4e3a\u4e00\u4e2a\u8868\u793a null \u6307\u9488\u7684 '#' \u3002

    \n\n

    \u4f60\u53ef\u4ee5\u8ba4\u4e3a\u8f93\u5165\u683c\u5f0f\u603b\u662f\u6709\u6548\u7684\uff0c\u4f8b\u5982\u5b83\u6c38\u8fdc\u4e0d\u4f1a\u5305\u542b\u4e24\u4e2a\u8fde\u7eed\u7684\u9017\u53f7\uff0c\u6bd4\u5982 "1,,3" \u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: "9,3,4,#,#,1,#,#,2,#,6,#,#"\n\u8f93\u51fa: true
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: "1,#"\n\u8f93\u51fa: false\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u8f93\u5165: "9,#,#,1"\n\u8f93\u51fa: false
    \n", "tags_en": ["Stack"], "tags_cn": ["\u6808"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isValidSerialization(string preorder) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isValidSerialization(String preorder) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isValidSerialization(self, preorder):\n \"\"\"\n :type preorder: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isValidSerialization(self, preorder: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isValidSerialization(char * preorder){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsValidSerialization(string preorder) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} preorder\n * @return {boolean}\n */\nvar isValidSerialization = function(preorder) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} preorder\n# @return {Boolean}\ndef is_valid_serialization(preorder)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isValidSerialization(_ preorder: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isValidSerialization(preorder string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isValidSerialization(preorder: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isValidSerialization(preorder: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_valid_serialization(preorder: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $preorder\n * @return Boolean\n */\n function isValidSerialization($preorder) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isValidSerialization(preorder: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-valid-serialization preorder)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0331](https://leetcode-cn.com/problems/verify-preorder-serialization-of-a-binary-tree)", "[\u9a8c\u8bc1\u4e8c\u53c9\u6811\u7684\u524d\u5e8f\u5e8f\u5217\u5316](/solution/0300-0399/0331.Verify%20Preorder%20Serialization%20of%20a%20Binary%20Tree/README.md)", "`\u6808`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0331](https://leetcode.com/problems/verify-preorder-serialization-of-a-binary-tree)", "[Verify Preorder Serialization of a Binary Tree](/solution/0300-0399/0331.Verify%20Preorder%20Serialization%20of%20a%20Binary%20Tree/README_EN.md)", "`Stack`", "Medium", ""]}, {"question_id": "0330", "frontend_question_id": "0330", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/patching-array", "url_en": "https://leetcode.com/problems/patching-array", "relative_path_cn": "/solution/0300-0399/0330.Patching%20Array/README.md", "relative_path_en": "/solution/0300-0399/0330.Patching%20Array/README_EN.md", "title_cn": "\u6309\u8981\u6c42\u8865\u9f50\u6570\u7ec4", "title_en": "Patching Array", "question_title_slug": "patching-array", "content_en": "

    Given a sorted integer array nums and an integer n, add/patch elements to the array such that any number in the range [1, n] inclusive can be formed by the sum of some elements in the array.

    \n\n

    Return the minimum number of patches required.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,3], n = 6\nOutput: 1\nExplanation:\nCombinations of nums are [1], [3], [1,3], which form possible sums of: 1, 3, 4.\nNow if we add/patch 2 to nums, the combinations are: [1], [2], [3], [1,3], [2,3], [1,2,3].\nPossible sums are 1, 2, 3, 4, 5, 6, which now covers the range [1, 6].\nSo we only need 1 patch.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,5,10], n = 20\nOutput: 2\nExplanation: The two patches can be [2, 4].\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [1,2,2], n = 5\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 1000
    • \n\t
    • 1 <= nums[i] <= 104
    • \n\t
    • nums is sorted in ascending order.
    • \n\t
    • 1 <= n <= 231 - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5df2\u6392\u5e8f\u7684\u6b63\u6574\u6570\u6570\u7ec4 nums\uff0c\u548c\u4e00\u4e2a\u6b63\u6574\u6570 n \u3002\u4ece [1, n] \u533a\u95f4\u5185\u9009\u53d6\u4efb\u610f\u4e2a\u6570\u5b57\u8865\u5145\u5230 nums \u4e2d\uff0c\u4f7f\u5f97 [1, n] \u533a\u95f4\u5185\u7684\u4efb\u4f55\u6570\u5b57\u90fd\u53ef\u4ee5\u7528 nums \u4e2d\u67d0\u51e0\u4e2a\u6570\u5b57\u7684\u548c\u6765\u8868\u793a\u3002\u8bf7\u8f93\u51fa\u6ee1\u8db3\u4e0a\u8ff0\u8981\u6c42\u7684\u6700\u5c11\u9700\u8981\u8865\u5145\u7684\u6570\u5b57\u4e2a\u6570\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: nums = [1,3], n = 6\n\u8f93\u51fa: 1 \n\u89e3\u91ca:\n\u6839\u636e nums \u91cc\u73b0\u6709\u7684\u7ec4\u5408 [1], [3], [1,3]\uff0c\u53ef\u4ee5\u5f97\u51fa 1, 3, 4\u3002\n\u73b0\u5728\u5982\u679c\u6211\u4eec\u5c06 2 \u6dfb\u52a0\u5230 nums \u4e2d\uff0c \u7ec4\u5408\u53d8\u4e3a: [1], [2], [3], [1,3], [2,3], [1,2,3]\u3002\n\u5176\u548c\u53ef\u4ee5\u8868\u793a\u6570\u5b57 1, 2, 3, 4, 5, 6\uff0c\u80fd\u591f\u8986\u76d6 [1, 6] \u533a\u95f4\u91cc\u6240\u6709\u7684\u6570\u3002\n\u6240\u4ee5\u6211\u4eec\u6700\u5c11\u9700\u8981\u6dfb\u52a0\u4e00\u4e2a\u6570\u5b57\u3002
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: nums = [1,5,10], n = 20\n\u8f93\u51fa: 2\n\u89e3\u91ca: \u6211\u4eec\u9700\u8981\u6dfb\u52a0 [2, 4]\u3002\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u8f93\u5165: nums = [1,2,2], n = 5\n\u8f93\u51fa: 0\n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minPatches(vector& nums, int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minPatches(int[] nums, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minPatches(self, nums, n):\n \"\"\"\n :type nums: List[int]\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minPatches(self, nums: List[int], n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minPatches(int* nums, int numsSize, int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinPatches(int[] nums, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} n\n * @return {number}\n */\nvar minPatches = function(nums, n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} n\n# @return {Integer}\ndef min_patches(nums, n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minPatches(_ nums: [Int], _ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minPatches(nums []int, n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minPatches(nums: Array[Int], n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minPatches(nums: IntArray, n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_patches(nums: Vec, n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $n\n * @return Integer\n */\n function minPatches($nums, $n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minPatches(nums: number[], n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-patches nums n)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0330](https://leetcode-cn.com/problems/patching-array)", "[\u6309\u8981\u6c42\u8865\u9f50\u6570\u7ec4](/solution/0300-0399/0330.Patching%20Array/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[0330](https://leetcode.com/problems/patching-array)", "[Patching Array](/solution/0300-0399/0330.Patching%20Array/README_EN.md)", "`Greedy`", "Hard", ""]}, {"question_id": "0329", "frontend_question_id": "0329", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-increasing-path-in-a-matrix", "url_en": "https://leetcode.com/problems/longest-increasing-path-in-a-matrix", "relative_path_cn": "/solution/0300-0399/0329.Longest%20Increasing%20Path%20in%20a%20Matrix/README.md", "relative_path_en": "/solution/0300-0399/0329.Longest%20Increasing%20Path%20in%20a%20Matrix/README_EN.md", "title_cn": "\u77e9\u9635\u4e2d\u7684\u6700\u957f\u9012\u589e\u8def\u5f84", "title_en": "Longest Increasing Path in a Matrix", "question_title_slug": "longest-increasing-path-in-a-matrix", "content_en": "

    Given an m x n integers matrix, return the length of the longest increasing path in matrix.

    \n\n

    From each cell, you can either move in four directions: left, right, up, or down. You may not move diagonally or move outside the boundary (i.e., wrap-around is not allowed).

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: matrix = [[9,9,4],[6,6,8],[2,1,1]]\nOutput: 4\nExplanation: The longest increasing path is [1, 2, 6, 9].\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: matrix = [[3,4,5],[3,2,6],[2,2,1]]\nOutput: 4\nExplanation: The longest increasing path is [3, 4, 5, 6]. Moving diagonally is not allowed.\n
    \n\n

    Example 3:

    \n\n
    \nInput: matrix = [[1]]\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == matrix.length
    • \n\t
    • n == matrix[i].length
    • \n\t
    • 1 <= m, n <= 200
    • \n\t
    • 0 <= matrix[i][j] <= 231 - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u00a0m x n \u6574\u6570\u77e9\u9635\u00a0matrix \uff0c\u627e\u51fa\u5176\u4e2d \u6700\u957f\u9012\u589e\u8def\u5f84 \u7684\u957f\u5ea6\u3002

    \n\n

    \u5bf9\u4e8e\u6bcf\u4e2a\u5355\u5143\u683c\uff0c\u4f60\u53ef\u4ee5\u5f80\u4e0a\uff0c\u4e0b\uff0c\u5de6\uff0c\u53f3\u56db\u4e2a\u65b9\u5411\u79fb\u52a8\u3002 \u4f60 \u4e0d\u80fd \u5728 \u5bf9\u89d2\u7ebf \u65b9\u5411\u4e0a\u79fb\u52a8\u6216\u79fb\u52a8\u5230 \u8fb9\u754c\u5916\uff08\u5373\u4e0d\u5141\u8bb8\u73af\u7ed5\uff09\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1amatrix = [[9,9,4],[6,6,8],[2,1,1]]\n\u8f93\u51fa\uff1a4 \n\u89e3\u91ca\uff1a\u6700\u957f\u9012\u589e\u8def\u5f84\u4e3a\u00a0[1, 2, 6, 9]\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1amatrix = [[3,4,5],[3,2,6],[2,2,1]]\n\u8f93\u51fa\uff1a4 \n\u89e3\u91ca\uff1a\u6700\u957f\u9012\u589e\u8def\u5f84\u662f\u00a0[3, 4, 5, 6]\u3002\u6ce8\u610f\u4e0d\u5141\u8bb8\u5728\u5bf9\u89d2\u7ebf\u65b9\u5411\u4e0a\u79fb\u52a8\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1amatrix = [[1]]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == matrix.length
    • \n\t
    • n == matrix[i].length
    • \n\t
    • 1 <= m, n <= 200
    • \n\t
    • 0 <= matrix[i][j] <= 231 - 1
    • \n
    \n", "tags_en": ["Depth-first Search", "Topological Sort", "Memoization"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u62d3\u6251\u6392\u5e8f", "\u8bb0\u5fc6\u5316"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int longestIncreasingPath(vector>& matrix) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int longestIncreasingPath(int[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestIncreasingPath(self, matrix):\n \"\"\"\n :type matrix: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestIncreasingPath(self, matrix: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint longestIncreasingPath(int** matrix, int matrixSize, int* matrixColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LongestIncreasingPath(int[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} matrix\n * @return {number}\n */\nvar longestIncreasingPath = function(matrix) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} matrix\n# @return {Integer}\ndef longest_increasing_path(matrix)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestIncreasingPath(_ matrix: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestIncreasingPath(matrix [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestIncreasingPath(matrix: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestIncreasingPath(matrix: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_increasing_path(matrix: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $matrix\n * @return Integer\n */\n function longestIncreasingPath($matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestIncreasingPath(matrix: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-increasing-path matrix)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0329](https://leetcode-cn.com/problems/longest-increasing-path-in-a-matrix)", "[\u77e9\u9635\u4e2d\u7684\u6700\u957f\u9012\u589e\u8def\u5f84](/solution/0300-0399/0329.Longest%20Increasing%20Path%20in%20a%20Matrix/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u62d3\u6251\u6392\u5e8f`,`\u8bb0\u5fc6\u5316`", "\u56f0\u96be", ""], "md_table_row_en": ["[0329](https://leetcode.com/problems/longest-increasing-path-in-a-matrix)", "[Longest Increasing Path in a Matrix](/solution/0300-0399/0329.Longest%20Increasing%20Path%20in%20a%20Matrix/README_EN.md)", "`Depth-first Search`,`Topological Sort`,`Memoization`", "Hard", ""]}, {"question_id": "0328", "frontend_question_id": "0328", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/odd-even-linked-list", "url_en": "https://leetcode.com/problems/odd-even-linked-list", "relative_path_cn": "/solution/0300-0399/0328.Odd%20Even%20Linked%20List/README.md", "relative_path_en": "/solution/0300-0399/0328.Odd%20Even%20Linked%20List/README_EN.md", "title_cn": "\u5947\u5076\u94fe\u8868", "title_en": "Odd Even Linked List", "question_title_slug": "odd-even-linked-list", "content_en": "

    Given the head of a singly linked list, group all the nodes with odd indices together followed by the nodes with even indices, and return the reordered list.

    \n\n

    The first node is considered odd, and the second node is even, and so on.

    \n\n

    Note that the relative order inside both the even and odd groups should remain as it was in the input.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: head = [1,2,3,4,5]\nOutput: [1,3,5,2,4]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: head = [2,1,3,5,6,4,7]\nOutput: [2,3,6,7,1,5,4]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the linked list is in the range [0, 104].
    • \n\t
    • -106 <= Node.val <= 106
    • \n
    \n\n

     

    \nFollow up: Could you solve it in O(1) space complexity and O(nodes) time complexity?", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5355\u94fe\u8868\uff0c\u628a\u6240\u6709\u7684\u5947\u6570\u8282\u70b9\u548c\u5076\u6570\u8282\u70b9\u5206\u522b\u6392\u5728\u4e00\u8d77\u3002\u8bf7\u6ce8\u610f\uff0c\u8fd9\u91cc\u7684\u5947\u6570\u8282\u70b9\u548c\u5076\u6570\u8282\u70b9\u6307\u7684\u662f\u8282\u70b9\u7f16\u53f7\u7684\u5947\u5076\u6027\uff0c\u800c\u4e0d\u662f\u8282\u70b9\u7684\u503c\u7684\u5947\u5076\u6027\u3002

    \n\n

    \u8bf7\u5c1d\u8bd5\u4f7f\u7528\u539f\u5730\u7b97\u6cd5\u5b8c\u6210\u3002\u4f60\u7684\u7b97\u6cd5\u7684\u7a7a\u95f4\u590d\u6742\u5ea6\u5e94\u4e3a O(1)\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u5e94\u4e3a O(nodes)\uff0cnodes \u4e3a\u8282\u70b9\u603b\u6570\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: 1->2->3->4->5->NULL\n\u8f93\u51fa: 1->3->5->2->4->NULL\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: 2->1->3->5->6->4->7->NULL \n\u8f93\u51fa: 2->3->6->7->1->5->4->NULL
    \n\n

    \u8bf4\u660e:

    \n\n
      \n\t
    • \u5e94\u5f53\u4fdd\u6301\u5947\u6570\u8282\u70b9\u548c\u5076\u6570\u8282\u70b9\u7684\u76f8\u5bf9\u987a\u5e8f\u3002
    • \n\t
    • \u94fe\u8868\u7684\u7b2c\u4e00\u4e2a\u8282\u70b9\u89c6\u4e3a\u5947\u6570\u8282\u70b9\uff0c\u7b2c\u4e8c\u4e2a\u8282\u70b9\u89c6\u4e3a\u5076\u6570\u8282\u70b9\uff0c\u4ee5\u6b64\u7c7b\u63a8\u3002
    • \n
    \n", "tags_en": ["Linked List"], "tags_cn": ["\u94fe\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n ListNode* oddEvenList(ListNode* head) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public ListNode oddEvenList(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def oddEvenList(self, head):\n \"\"\"\n :type head: ListNode\n :rtype: ListNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def oddEvenList(self, head: ListNode) -> ListNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nstruct ListNode* oddEvenList(struct ListNode* head){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public ListNode OddEvenList(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} head\n * @return {ListNode}\n */\nvar oddEvenList = function(head) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode} head\n# @return {ListNode}\ndef odd_even_list(head)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func oddEvenList(_ head: ListNode?) -> ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc oddEvenList(head *ListNode) *ListNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def oddEvenList(head: ListNode): ListNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun oddEvenList(head: ListNode?): ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn odd_even_list(head: Option>) -> Option> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @return ListNode\n */\n function oddEvenList($head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction oddEvenList(head: ListNode | null): ListNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (odd-even-list head)\n (-> (or/c list-node? #f) (or/c list-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0328](https://leetcode-cn.com/problems/odd-even-linked-list)", "[\u5947\u5076\u94fe\u8868](/solution/0300-0399/0328.Odd%20Even%20Linked%20List/README.md)", "`\u94fe\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0328](https://leetcode.com/problems/odd-even-linked-list)", "[Odd Even Linked List](/solution/0300-0399/0328.Odd%20Even%20Linked%20List/README_EN.md)", "`Linked List`", "Medium", ""]}, {"question_id": "0327", "frontend_question_id": "0327", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-of-range-sum", "url_en": "https://leetcode.com/problems/count-of-range-sum", "relative_path_cn": "/solution/0300-0399/0327.Count%20of%20Range%20Sum/README.md", "relative_path_en": "/solution/0300-0399/0327.Count%20of%20Range%20Sum/README_EN.md", "title_cn": "\u533a\u95f4\u548c\u7684\u4e2a\u6570", "title_en": "Count of Range Sum", "question_title_slug": "count-of-range-sum", "content_en": "

    Given an integer array nums and two integers lower and upper, return the number of range sums that lie in [lower, upper] inclusive.

    \n\n

    Range sum S(i, j) is defined as the sum of the elements in nums between indices i and j inclusive, where i <= j.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [-2,5,-1], lower = -2, upper = 2\nOutput: 3\nExplanation: The three ranges are: [0,0], [2,2], and [0,2] and their respective sums are: -2, -1, 2.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [0], lower = 0, upper = 0\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n\t
    • -105 <= lower <= upper <= 105
    • \n\t
    • The answer is guaranteed to fit in a 32-bit integer.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0nums \u4ee5\u53ca\u4e24\u4e2a\u6574\u6570\u00a0lower \u548c upper \u3002\u6c42\u6570\u7ec4\u4e2d\uff0c\u503c\u4f4d\u4e8e\u8303\u56f4 [lower, upper] \uff08\u5305\u542b\u00a0lower\u00a0\u548c\u00a0upper\uff09\u4e4b\u5185\u7684 \u533a\u95f4\u548c\u7684\u4e2a\u6570 \u3002

    \n\n

    \u533a\u95f4\u548c\u00a0S(i, j)\u00a0\u8868\u793a\u5728\u00a0nums\u00a0\u4e2d\uff0c\u4f4d\u7f6e\u4ece\u00a0i\u00a0\u5230\u00a0j\u00a0\u7684\u5143\u7d20\u4e4b\u548c\uff0c\u5305\u542b\u00a0i\u00a0\u548c\u00a0j\u00a0(i \u2264 j)\u3002

    \n\n

    \u00a0

    \n\u793a\u4f8b 1\uff1a\n\n
    \n\u8f93\u5165\uff1anums = [-2,5,-1], lower = -2, upper = 2\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u5b58\u5728\u4e09\u4e2a\u533a\u95f4\uff1a[0,0]\u3001[2,2] \u548c [0,2] \uff0c\u5bf9\u5e94\u7684\u533a\u95f4\u548c\u5206\u522b\u662f\uff1a-2 \u3001-1 \u30012 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [0], lower = 0, upper = 0\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n\t
    • -105 <= lower <= upper <= 105
    • \n\t
    • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u7b54\u6848\u662f\u4e00\u4e2a 32 \u4f4d \u7684\u6574\u6570
    • \n
    \n", "tags_en": ["Sort", "Binary Indexed Tree", "Segment Tree", "Binary Search", "Divide and Conquer"], "tags_cn": ["\u6392\u5e8f", "\u6811\u72b6\u6570\u7ec4", "\u7ebf\u6bb5\u6811", "\u4e8c\u5206\u67e5\u627e", "\u5206\u6cbb\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countRangeSum(vector& nums, int lower, int upper) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countRangeSum(int[] nums, int lower, int upper) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countRangeSum(self, nums, lower, upper):\n \"\"\"\n :type nums: List[int]\n :type lower: int\n :type upper: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countRangeSum(self, nums: List[int], lower: int, upper: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countRangeSum(int* nums, int numsSize, int lower, int upper){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountRangeSum(int[] nums, int lower, int upper) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} lower\n * @param {number} upper\n * @return {number}\n */\nvar countRangeSum = function(nums, lower, upper) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} lower\n# @param {Integer} upper\n# @return {Integer}\ndef count_range_sum(nums, lower, upper)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countRangeSum(_ nums: [Int], _ lower: Int, _ upper: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countRangeSum(nums []int, lower int, upper int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countRangeSum(nums: Array[Int], lower: Int, upper: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countRangeSum(nums: IntArray, lower: Int, upper: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_range_sum(nums: Vec, lower: i32, upper: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $lower\n * @param Integer $upper\n * @return Integer\n */\n function countRangeSum($nums, $lower, $upper) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countRangeSum(nums: number[], lower: number, upper: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-range-sum nums lower upper)\n (-> (listof exact-integer?) exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0327](https://leetcode-cn.com/problems/count-of-range-sum)", "[\u533a\u95f4\u548c\u7684\u4e2a\u6570](/solution/0300-0399/0327.Count%20of%20Range%20Sum/README.md)", "`\u6392\u5e8f`,`\u6811\u72b6\u6570\u7ec4`,`\u7ebf\u6bb5\u6811`,`\u4e8c\u5206\u67e5\u627e`,`\u5206\u6cbb\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[0327](https://leetcode.com/problems/count-of-range-sum)", "[Count of Range Sum](/solution/0300-0399/0327.Count%20of%20Range%20Sum/README_EN.md)", "`Sort`,`Binary Indexed Tree`,`Segment Tree`,`Binary Search`,`Divide and Conquer`", "Hard", ""]}, {"question_id": "0326", "frontend_question_id": "0326", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/power-of-three", "url_en": "https://leetcode.com/problems/power-of-three", "relative_path_cn": "/solution/0300-0399/0326.Power%20of%20Three/README.md", "relative_path_en": "/solution/0300-0399/0326.Power%20of%20Three/README_EN.md", "title_cn": "3\u7684\u5e42", "title_en": "Power of Three", "question_title_slug": "power-of-three", "content_en": "

    Given an integer n, return true if it is a power of three. Otherwise, return false.

    \n\n

    An integer n is a power of three, if there exists an integer x such that n == 3x.

    \n\n

     

    \n

    Example 1:

    \n
    Input: n = 27\nOutput: true\n

    Example 2:

    \n
    Input: n = 0\nOutput: false\n

    Example 3:

    \n
    Input: n = 9\nOutput: true\n

    Example 4:

    \n
    Input: n = 45\nOutput: false\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • -231 <= n <= 231 - 1
    • \n
    \n\n

     

    \nFollow up: Could you solve it without loops/recursion?", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\uff0c\u5199\u4e00\u4e2a\u51fd\u6570\u6765\u5224\u65ad\u5b83\u662f\u5426\u662f 3\u00a0\u7684\u5e42\u6b21\u65b9\u3002\u5982\u679c\u662f\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n

    \u6574\u6570 n \u662f 3 \u7684\u5e42\u6b21\u65b9\u9700\u6ee1\u8db3\uff1a\u5b58\u5728\u6574\u6570 x \u4f7f\u5f97 n == 3x

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 27\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 0\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 9\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 45\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • -231 <= n <= 231 - 1
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u4f60\u80fd\u4e0d\u4f7f\u7528\u5faa\u73af\u6216\u8005\u9012\u5f52\u6765\u5b8c\u6210\u672c\u9898\u5417\uff1f
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isPowerOfThree(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isPowerOfThree(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isPowerOfThree(self, n):\n \"\"\"\n :type n: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isPowerOfThree(self, n: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isPowerOfThree(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsPowerOfThree(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {boolean}\n */\nvar isPowerOfThree = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Boolean}\ndef is_power_of_three(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isPowerOfThree(_ n: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isPowerOfThree(n int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isPowerOfThree(n: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isPowerOfThree(n: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_power_of_three(n: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Boolean\n */\n function isPowerOfThree($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isPowerOfThree(n: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-power-of-three n)\n (-> exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0326](https://leetcode-cn.com/problems/power-of-three)", "[3\u7684\u5e42](/solution/0300-0399/0326.Power%20of%20Three/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0326](https://leetcode.com/problems/power-of-three)", "[Power of Three](/solution/0300-0399/0326.Power%20of%20Three/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "0325", "frontend_question_id": "0325", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/maximum-size-subarray-sum-equals-k", "url_en": "https://leetcode.com/problems/maximum-size-subarray-sum-equals-k", "relative_path_cn": "/solution/0300-0399/0325.Maximum%20Size%20Subarray%20Sum%20Equals%20k/README.md", "relative_path_en": "/solution/0300-0399/0325.Maximum%20Size%20Subarray%20Sum%20Equals%20k/README_EN.md", "title_cn": "\u548c\u7b49\u4e8e k \u7684\u6700\u957f\u5b50\u6570\u7ec4\u957f\u5ea6", "title_en": "Maximum Size Subarray Sum Equals k", "question_title_slug": "maximum-size-subarray-sum-equals-k", "content_en": "

    Given an integer array nums and an integer k, return the maximum length of a subarray that sums to k. If there isn't one, return 0 instead.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,-1,5,-2,3], k = 3\nOutput: 4\nExplanation: The subarray [1, -1, 5, -2] sums to 3 and is the longest.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [-2,-1,2,1], k = 1\nOutput: 2\nExplanation: The subarray [-1, 2] sums to 1 and is the longest.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 2 * 105
    • \n\t
    • -104 <= nums[i] <= 104
    • \n\t
    • -109 <= k <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6570\u7ec4 nums \u548c\u4e00\u4e2a\u76ee\u6807\u503c k\uff0c\u627e\u5230\u548c\u7b49\u4e8e k \u7684\u6700\u957f\u5b50\u6570\u7ec4\u957f\u5ea6\u3002\u5982\u679c\u4e0d\u5b58\u5728\u4efb\u610f\u4e00\u4e2a\u7b26\u5408\u8981\u6c42\u7684\u5b50\u6570\u7ec4\uff0c\u5219\u8fd4\u56de 0\u3002

    \n\n

    \u6ce8\u610f:
    \n nums \u6570\u7ec4\u7684\u603b\u548c\u662f\u4e00\u5b9a\u5728 32 \u4f4d\u6709\u7b26\u53f7\u6574\u6570\u8303\u56f4\u4e4b\u5185\u7684\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: nums = [1, -1, 5, -2, 3], k = 3\n\u8f93\u51fa: 4 \n\u89e3\u91ca: \u5b50\u6570\u7ec4 [1, -1, 5, -2] \u548c\u7b49\u4e8e 3\uff0c\u4e14\u957f\u5ea6\u6700\u957f\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: nums = [-2, -1, 2, 1], k = 1\n\u8f93\u51fa: 2 \n\u89e3\u91ca: \u5b50\u6570\u7ec4 [-1, 2] \u548c\u7b49\u4e8e 1\uff0c\u4e14\u957f\u5ea6\u6700\u957f\u3002
    \n\n

    \u8fdb\u9636:
    \n\u4f60\u80fd\u4f7f\u65f6\u95f4\u590d\u6742\u5ea6\u5728 O(n) \u5185\u5b8c\u6210\u6b64\u9898\u5417?

    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxSubArrayLen(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxSubArrayLen(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxSubArrayLen(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxSubArrayLen(self, nums: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxSubArrayLen(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxSubArrayLen(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar maxSubArrayLen = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef max_sub_array_len(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxSubArrayLen(_ nums: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxSubArrayLen(nums []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxSubArrayLen(nums: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxSubArrayLen(nums: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_sub_array_len(nums: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer\n */\n function maxSubArrayLen($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxSubArrayLen(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-sub-array-len nums k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0325](https://leetcode-cn.com/problems/maximum-size-subarray-sum-equals-k)", "[\u548c\u7b49\u4e8e k \u7684\u6700\u957f\u5b50\u6570\u7ec4\u957f\u5ea6](/solution/0300-0399/0325.Maximum%20Size%20Subarray%20Sum%20Equals%20k/README.md)", "`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0325](https://leetcode.com/problems/maximum-size-subarray-sum-equals-k)", "[Maximum Size Subarray Sum Equals k](/solution/0300-0399/0325.Maximum%20Size%20Subarray%20Sum%20Equals%20k/README_EN.md)", "`Hash Table`", "Medium", "\ud83d\udd12"]}, {"question_id": "0324", "frontend_question_id": "0324", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/wiggle-sort-ii", "url_en": "https://leetcode.com/problems/wiggle-sort-ii", "relative_path_cn": "/solution/0300-0399/0324.Wiggle%20Sort%20II/README.md", "relative_path_en": "/solution/0300-0399/0324.Wiggle%20Sort%20II/README_EN.md", "title_cn": "\u6446\u52a8\u6392\u5e8f II", "title_en": "Wiggle Sort II", "question_title_slug": "wiggle-sort-ii", "content_en": "

    Given an integer array nums, reorder it such that nums[0] < nums[1] > nums[2] < nums[3]....

    \n\n

    You may assume the input array always has a valid answer.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,5,1,1,6,4]\nOutput: [1,6,1,5,1,4]\nExplanation: [1,4,1,5,1,6] is also accepted.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,3,2,2,3,1]\nOutput: [2,3,1,3,1,2]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 5 * 104
    • \n\t
    • 0 <= nums[i] <= 5000
    • \n\t
    • It is guaranteed that there will be an answer for the given input nums.
    • \n
    \n\n

     

    \nFollow Up: Can you do it in O(n) time and/or in-place with O(1) extra space?", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0nums\uff0c\u5c06\u5b83\u91cd\u65b0\u6392\u5217\u6210\u00a0nums[0] < nums[1] > nums[2] < nums[3]...\u00a0\u7684\u987a\u5e8f\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u5047\u8bbe\u6240\u6709\u8f93\u5165\u6570\u7ec4\u90fd\u53ef\u4ee5\u5f97\u5230\u6ee1\u8db3\u9898\u76ee\u8981\u6c42\u7684\u7ed3\u679c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,5,1,1,6,4]\n\u8f93\u51fa\uff1a[1,6,1,5,1,4]\n\u89e3\u91ca\uff1a[1,4,1,5,1,6] \u540c\u6837\u662f\u7b26\u5408\u9898\u76ee\u8981\u6c42\u7684\u7ed3\u679c\uff0c\u53ef\u4ee5\u88ab\u5224\u9898\u7a0b\u5e8f\u63a5\u53d7\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,3,2,2,3,1]\n\u8f93\u51fa\uff1a[2,3,1,3,1,2]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 5 * 104
    • \n\t
    • 0 <= nums[i] <= 5000
    • \n\t
    • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\uff0c\u5bf9\u4e8e\u7ed9\u5b9a\u7684\u8f93\u5165 nums \uff0c\u603b\u80fd\u4ea7\u751f\u6ee1\u8db3\u9898\u76ee\u8981\u6c42\u7684\u7ed3\u679c
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u80fd\u7528\u00a0O(n) \u65f6\u95f4\u590d\u6742\u5ea6\u548c / \u6216\u539f\u5730 O(1) \u989d\u5916\u7a7a\u95f4\u6765\u5b9e\u73b0\u5417\uff1f

    \n", "tags_en": ["Sort"], "tags_cn": ["\u6392\u5e8f"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n void wiggleSort(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public void wiggleSort(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def wiggleSort(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: None Do not return anything, modify nums in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def wiggleSort(self, nums: List[int]) -> None:\n \"\"\"\n Do not return anything, modify nums in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nvoid wiggleSort(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public void WiggleSort(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {void} Do not return anything, modify nums in-place instead.\n */\nvar wiggleSort = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Void} Do not return anything, modify nums in-place instead.\ndef wiggle_sort(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func wiggleSort(_ nums: inout [Int]) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func wiggleSort(nums []int) {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def wiggleSort(nums: Array[Int]): Unit = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun wiggleSort(nums: IntArray): Unit {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn wiggle_sort(nums: &mut Vec) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return NULL\n */\n function wiggleSort(&$nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n Do not return anything, modify nums in-place instead.\n */\nfunction wiggleSort(nums: number[]): void {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0324](https://leetcode-cn.com/problems/wiggle-sort-ii)", "[\u6446\u52a8\u6392\u5e8f II](/solution/0300-0399/0324.Wiggle%20Sort%20II/README.md)", "`\u6392\u5e8f`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0324](https://leetcode.com/problems/wiggle-sort-ii)", "[Wiggle Sort II](/solution/0300-0399/0324.Wiggle%20Sort%20II/README_EN.md)", "`Sort`", "Medium", ""]}, {"question_id": "0323", "frontend_question_id": "0323", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/number-of-connected-components-in-an-undirected-graph", "url_en": "https://leetcode.com/problems/number-of-connected-components-in-an-undirected-graph", "relative_path_cn": "/solution/0300-0399/0323.Number%20of%20Connected%20Components%20in%20an%20Undirected%20Graph/README.md", "relative_path_en": "/solution/0300-0399/0323.Number%20of%20Connected%20Components%20in%20an%20Undirected%20Graph/README_EN.md", "title_cn": "\u65e0\u5411\u56fe\u4e2d\u8fde\u901a\u5206\u91cf\u7684\u6570\u76ee", "title_en": "Number of Connected Components in an Undirected Graph", "question_title_slug": "number-of-connected-components-in-an-undirected-graph", "content_en": "

    You have a graph of n nodes. You are given an integer n and an array edges where edges[i] = [ai, bi] indicates that there is an edge between ai and bi in the graph.

    \n\n

    Return the number of connected components in the graph.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: n = 5, edges = [[0,1],[1,2],[3,4]]\nOutput: 2\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: n = 5, edges = [[0,1],[1,2],[2,3],[3,4]]\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 2000
    • \n\t
    • 1 <= edges.length <= 5000
    • \n\t
    • edges[i].length == 2
    • \n\t
    • 0 <= ai <= bi < n
    • \n\t
    • ai != bi
    • \n\t
    • There are no repeated edges.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u7f16\u53f7\u4ece 0 \u5230 n-1 \u7684 n \u4e2a\u8282\u70b9\u548c\u4e00\u4e2a\u65e0\u5411\u8fb9\u5217\u8868\uff08\u6bcf\u6761\u8fb9\u90fd\u662f\u4e00\u5bf9\u8282\u70b9\uff09\uff0c\u8bf7\u7f16\u5199\u4e00\u4e2a\u51fd\u6570\u6765\u8ba1\u7b97\u65e0\u5411\u56fe\u4e2d\u8fde\u901a\u5206\u91cf\u7684\u6570\u76ee\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: n = 5 \u548c edges = [[0, 1], [1, 2], [3, 4]]\n\n     0          3\n     |          |\n     1 --- 2    4 \n\n\u8f93\u51fa: 2\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: n = 5 \u548c edges = [[0, 1], [1, 2], [2, 3], [3, 4]]\n\n     0           4\n     |           |\n     1 --- 2 --- 3\n\n\u8f93\u51fa:  1\n
    \n\n

    \u6ce8\u610f:
    \n\u4f60\u53ef\u4ee5\u5047\u8bbe\u5728 edges \u4e2d\u4e0d\u4f1a\u51fa\u73b0\u91cd\u590d\u7684\u8fb9\u3002\u800c\u4e14\u7531\u4e8e\u6240\u4ee5\u7684\u8fb9\u90fd\u662f\u65e0\u5411\u8fb9\uff0c[0, 1] \u4e0e [1, 0]  \u76f8\u540c\uff0c\u6240\u4ee5\u5b83\u4eec\u4e0d\u4f1a\u540c\u65f6\u5728 edges \u4e2d\u51fa\u73b0\u3002

    \n", "tags_en": ["Depth-first Search", "Breadth-first Search", "Union Find", "Graph"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e76\u67e5\u96c6", "\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countComponents(int n, vector>& edges) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countComponents(int n, int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countComponents(self, n, edges):\n \"\"\"\n :type n: int\n :type edges: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countComponents(self, n: int, edges: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countComponents(int n, int** edges, int edgesSize, int* edgesColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountComponents(int n, int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} edges\n * @return {number}\n */\nvar countComponents = function(n, edges) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} edges\n# @return {Integer}\ndef count_components(n, edges)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countComponents(_ n: Int, _ edges: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countComponents(n int, edges [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countComponents(n: Int, edges: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countComponents(n: Int, edges: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_components(n: i32, edges: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $edges\n * @return Integer\n */\n function countComponents($n, $edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countComponents(n: number, edges: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-components n edges)\n (-> exact-integer? (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0323](https://leetcode-cn.com/problems/number-of-connected-components-in-an-undirected-graph)", "[\u65e0\u5411\u56fe\u4e2d\u8fde\u901a\u5206\u91cf\u7684\u6570\u76ee](/solution/0300-0399/0323.Number%20of%20Connected%20Components%20in%20an%20Undirected%20Graph/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e76\u67e5\u96c6`,`\u56fe`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0323](https://leetcode.com/problems/number-of-connected-components-in-an-undirected-graph)", "[Number of Connected Components in an Undirected Graph](/solution/0300-0399/0323.Number%20of%20Connected%20Components%20in%20an%20Undirected%20Graph/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`,`Union Find`,`Graph`", "Medium", "\ud83d\udd12"]}, {"question_id": "0322", "frontend_question_id": "0322", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/coin-change", "url_en": "https://leetcode.com/problems/coin-change", "relative_path_cn": "/solution/0300-0399/0322.Coin%20Change/README.md", "relative_path_en": "/solution/0300-0399/0322.Coin%20Change/README_EN.md", "title_cn": "\u96f6\u94b1\u5151\u6362", "title_en": "Coin Change", "question_title_slug": "coin-change", "content_en": "

    You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money.

    \n\n

    Return the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination of the coins, return -1.

    \n\n

    You may assume that you have an infinite number of each kind of coin.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: coins = [1,2,5], amount = 11\nOutput: 3\nExplanation: 11 = 5 + 5 + 1\n
    \n\n

    Example 2:

    \n\n
    \nInput: coins = [2], amount = 3\nOutput: -1\n
    \n\n

    Example 3:

    \n\n
    \nInput: coins = [1], amount = 0\nOutput: 0\n
    \n\n

    Example 4:

    \n\n
    \nInput: coins = [1], amount = 1\nOutput: 1\n
    \n\n

    Example 5:

    \n\n
    \nInput: coins = [1], amount = 2\nOutput: 2\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= coins.length <= 12
    • \n\t
    • 1 <= coins[i] <= 231 - 1
    • \n\t
    • 0 <= amount <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e0d\u540c\u9762\u989d\u7684\u786c\u5e01 coins \u548c\u4e00\u4e2a\u603b\u91d1\u989d amount\u3002\u7f16\u5199\u4e00\u4e2a\u51fd\u6570\u6765\u8ba1\u7b97\u53ef\u4ee5\u51d1\u6210\u603b\u91d1\u989d\u6240\u9700\u7684\u6700\u5c11\u7684\u786c\u5e01\u4e2a\u6570\u3002\u5982\u679c\u6ca1\u6709\u4efb\u4f55\u4e00\u79cd\u786c\u5e01\u7ec4\u5408\u80fd\u7ec4\u6210\u603b\u91d1\u989d\uff0c\u8fd4\u56de\u00a0-1\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u8ba4\u4e3a\u6bcf\u79cd\u786c\u5e01\u7684\u6570\u91cf\u662f\u65e0\u9650\u7684\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\u00a01\uff1a

    \n\n
    \n\u8f93\u5165\uff1acoins = [1, 2, 5], amount = 11\n\u8f93\u51fa\uff1a3 \n\u89e3\u91ca\uff1a11 = 5 + 5 + 1
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1acoins = [2], amount = 3\n\u8f93\u51fa\uff1a-1
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1acoins = [1], amount = 0\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1acoins = [1], amount = 1\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1acoins = [1], amount = 2\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= coins.length <= 12
    • \n\t
    • 1 <= coins[i] <= 231 - 1
    • \n\t
    • 0 <= amount <= 104
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int coinChange(vector& coins, int amount) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int coinChange(int[] coins, int amount) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def coinChange(self, coins, amount):\n \"\"\"\n :type coins: List[int]\n :type amount: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def coinChange(self, coins: List[int], amount: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint coinChange(int* coins, int coinsSize, int amount){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CoinChange(int[] coins, int amount) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} coins\n * @param {number} amount\n * @return {number}\n */\nvar coinChange = function(coins, amount) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} coins\n# @param {Integer} amount\n# @return {Integer}\ndef coin_change(coins, amount)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func coinChange(_ coins: [Int], _ amount: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func coinChange(coins []int, amount int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def coinChange(coins: Array[Int], amount: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun coinChange(coins: IntArray, amount: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn coin_change(coins: Vec, amount: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $coins\n * @param Integer $amount\n * @return Integer\n */\n function coinChange($coins, $amount) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function coinChange(coins: number[], amount: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (coin-change coins amount)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0322](https://leetcode-cn.com/problems/coin-change)", "[\u96f6\u94b1\u5151\u6362](/solution/0300-0399/0322.Coin%20Change/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0322](https://leetcode.com/problems/coin-change)", "[Coin Change](/solution/0300-0399/0322.Coin%20Change/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0321", "frontend_question_id": "0321", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/create-maximum-number", "url_en": "https://leetcode.com/problems/create-maximum-number", "relative_path_cn": "/solution/0300-0399/0321.Create%20Maximum%20Number/README.md", "relative_path_en": "/solution/0300-0399/0321.Create%20Maximum%20Number/README_EN.md", "title_cn": "\u62fc\u63a5\u6700\u5927\u6570", "title_en": "Create Maximum Number", "question_title_slug": "create-maximum-number", "content_en": "

    You are given two integer arrays nums1 and nums2 of lengths m and n respectively. nums1 and nums2 represent the digits of two numbers. You are also given an integer k.

    \n\n

    Create the maximum number of length k <= m + n from digits of the two numbers. The relative order of the digits from the same array must be preserved.

    \n\n

    Return an array of the k digits representing the answer.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums1 = [3,4,6,5], nums2 = [9,1,2,5,8,3], k = 5\nOutput: [9,8,6,5,3]\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums1 = [6,7], nums2 = [6,0,4], k = 5\nOutput: [6,7,6,0,4]\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums1 = [3,9], nums2 = [8,9], k = 3\nOutput: [9,8,9]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == nums1.length
    • \n\t
    • n == nums2.length
    • \n\t
    • 1 <= m, n <= 500
    • \n\t
    • 0 <= nums1[i], nums2[i] <= 9
    • \n\t
    • 1 <= k <= m + n
    • \n
    \n\n

     

    \n

    Follow up: Try to optimize your time and space complexity.

    \n", "content_cn": "

    \u7ed9\u5b9a\u957f\u5ea6\u5206\u522b\u4e3a m \u548c n \u7684\u4e24\u4e2a\u6570\u7ec4\uff0c\u5176\u5143\u7d20\u7531 0-9 \u6784\u6210\uff0c\u8868\u793a\u4e24\u4e2a\u81ea\u7136\u6570\u5404\u4f4d\u4e0a\u7684\u6570\u5b57\u3002\u73b0\u5728\u4ece\u8fd9\u4e24\u4e2a\u6570\u7ec4\u4e2d\u9009\u51fa k (k <= m + n) \u4e2a\u6570\u5b57\u62fc\u63a5\u6210\u4e00\u4e2a\u65b0\u7684\u6570\uff0c\u8981\u6c42\u4ece\u540c\u4e00\u4e2a\u6570\u7ec4\u4e2d\u53d6\u51fa\u7684\u6570\u5b57\u4fdd\u6301\u5176\u5728\u539f\u6570\u7ec4\u4e2d\u7684\u76f8\u5bf9\u987a\u5e8f\u3002

    \n\n

    \u6c42\u6ee1\u8db3\u8be5\u6761\u4ef6\u7684\u6700\u5927\u6570\u3002\u7ed3\u679c\u8fd4\u56de\u4e00\u4e2a\u8868\u793a\u8be5\u6700\u5927\u6570\u7684\u957f\u5ea6\u4e3a k \u7684\u6570\u7ec4\u3002

    \n\n

    \u8bf4\u660e: \u8bf7\u5c3d\u53ef\u80fd\u5730\u4f18\u5316\u4f60\u7b97\u6cd5\u7684\u65f6\u95f4\u548c\u7a7a\u95f4\u590d\u6742\u5ea6\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165:\nnums1 = [3, 4, 6, 5]\nnums2 = [9, 1, 2, 5, 8, 3]\nk = 5\n\u8f93\u51fa:\n[9, 8, 6, 5, 3]
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165:\nnums1 = [6, 7]\nnums2 = [6, 0, 4]\nk = 5\n\u8f93\u51fa:\n[6, 7, 6, 0, 4]
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u8f93\u5165:\nnums1 = [3, 9]\nnums2 = [8, 9]\nk = 3\n\u8f93\u51fa:\n[9, 8, 9]
    \n", "tags_en": ["Greedy", "Dynamic Programming"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector maxNumber(vector& nums1, vector& nums2, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] maxNumber(int[] nums1, int[] nums2, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxNumber(self, nums1, nums2, k):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n :type k: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxNumber(self, nums1: List[int], nums2: List[int], k: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* maxNumber(int* nums1, int nums1Size, int* nums2, int nums2Size, int k, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] MaxNumber(int[] nums1, int[] nums2, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums1\n * @param {number[]} nums2\n * @param {number} k\n * @return {number[]}\n */\nvar maxNumber = function(nums1, nums2, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums1\n# @param {Integer[]} nums2\n# @param {Integer} k\n# @return {Integer[]}\ndef max_number(nums1, nums2, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxNumber(_ nums1: [Int], _ nums2: [Int], _ k: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxNumber(nums1 []int, nums2 []int, k int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxNumber(nums1: Array[Int], nums2: Array[Int], k: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxNumber(nums1: IntArray, nums2: IntArray, k: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_number(nums1: Vec, nums2: Vec, k: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums1\n * @param Integer[] $nums2\n * @param Integer $k\n * @return Integer[]\n */\n function maxNumber($nums1, $nums2, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxNumber(nums1: number[], nums2: number[], k: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-number nums1 nums2 k)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0321](https://leetcode-cn.com/problems/create-maximum-number)", "[\u62fc\u63a5\u6700\u5927\u6570](/solution/0300-0399/0321.Create%20Maximum%20Number/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0321](https://leetcode.com/problems/create-maximum-number)", "[Create Maximum Number](/solution/0300-0399/0321.Create%20Maximum%20Number/README_EN.md)", "`Greedy`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0320", "frontend_question_id": "0320", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/generalized-abbreviation", "url_en": "https://leetcode.com/problems/generalized-abbreviation", "relative_path_cn": "/solution/0300-0399/0320.Generalized%20Abbreviation/README.md", "relative_path_en": "/solution/0300-0399/0320.Generalized%20Abbreviation/README_EN.md", "title_cn": "\u5217\u4e3e\u5355\u8bcd\u7684\u5168\u90e8\u7f29\u5199", "title_en": "Generalized Abbreviation", "question_title_slug": "generalized-abbreviation", "content_en": "

    A word's generalized abbreviation can be constructed by taking any number of non-overlapping substrings and replacing them with their respective lengths. For example, "abcde" can be abbreviated into "a3e" ("bcd" turned into "3"), "1bcd1" ("a" and "e" both turned into "1"), and "23" ("ab" turned into "2" and "cde" turned into "3").

    \n\n

    Given a string word, return a list of all the possible generalized abbreviations of word. Return the answer in any order.

    \n\n

     

    \n

    Example 1:

    \n
    Input: word = \"word\"\nOutput: [\"4\",\"3d\",\"2r1\",\"2rd\",\"1o2\",\"1o1d\",\"1or1\",\"1ord\",\"w3\",\"w2d\",\"w1r1\",\"w1rd\",\"wo2\",\"wo1d\",\"wor1\",\"word\"]\n

    Example 2:

    \n
    Input: word = \"a\"\nOutput: [\"1\",\"a\"]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= word.length <= 15
    • \n\t
    • word consists of only lowercase English letters.
    • \n
    \n", "content_cn": "

    \u8bf7\u4f60\u5199\u51fa\u4e00\u4e2a\u80fd\u591f\u4e3e\u5355\u8bcd\u5168\u90e8\u7f29\u5199\u7684\u51fd\u6570\u3002

    \n\n

    \u6ce8\u610f\uff1a\u8f93\u51fa\u7684\u987a\u5e8f\u5e76\u4e0d\u91cd\u8981\u3002

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165: "word"\n\u8f93\u51fa:\n["word", "1ord", "w1rd", "wo1d", "wor1", "2rd", "w2d", "wo2", "1o1d", "1or1", "w1r1", "1o2", "2r1", "3d", "w3", "4"]\n
    \n\n

     

    \n", "tags_en": ["Bit Manipulation", "Backtracking"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector generateAbbreviations(string word) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List generateAbbreviations(String word) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def generateAbbreviations(self, word):\n \"\"\"\n :type word: str\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def generateAbbreviations(self, word: str) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** generateAbbreviations(char * word, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList GenerateAbbreviations(string word) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} word\n * @return {string[]}\n */\nvar generateAbbreviations = function(word) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} word\n# @return {String[]}\ndef generate_abbreviations(word)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func generateAbbreviations(_ word: String) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func generateAbbreviations(word string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def generateAbbreviations(word: String): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun generateAbbreviations(word: String): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn generate_abbreviations(word: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $word\n * @return String[]\n */\n function generateAbbreviations($word) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function generateAbbreviations(word: string): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (generate-abbreviations word)\n (-> string? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0320](https://leetcode-cn.com/problems/generalized-abbreviation)", "[\u5217\u4e3e\u5355\u8bcd\u7684\u5168\u90e8\u7f29\u5199](/solution/0300-0399/0320.Generalized%20Abbreviation/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0320](https://leetcode.com/problems/generalized-abbreviation)", "[Generalized Abbreviation](/solution/0300-0399/0320.Generalized%20Abbreviation/README_EN.md)", "`Bit Manipulation`,`Backtracking`", "Medium", "\ud83d\udd12"]}, {"question_id": "0319", "frontend_question_id": "0319", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/bulb-switcher", "url_en": "https://leetcode.com/problems/bulb-switcher", "relative_path_cn": "/solution/0300-0399/0319.Bulb%20Switcher/README.md", "relative_path_en": "/solution/0300-0399/0319.Bulb%20Switcher/README_EN.md", "title_cn": "\u706f\u6ce1\u5f00\u5173", "title_en": "Bulb Switcher", "question_title_slug": "bulb-switcher", "content_en": "

    There are n bulbs that are initially off. You first turn on all the bulbs, then you turn off every second bulb.

    \n\n

    On the third round, you toggle every third bulb (turning on if it's off or turning off if it's on). For the ith round, you toggle every i bulb. For the nth round, you only toggle the last bulb.

    \n\n

    Return the number of bulbs that are on after n rounds.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: n = 3\nOutput: 1\nExplanation: At first, the three bulbs are [off, off, off].\nAfter the first round, the three bulbs are [on, on, on].\nAfter the second round, the three bulbs are [on, off, on].\nAfter the third round, the three bulbs are [on, off, off]. \nSo you should return 1 because there is only one bulb is on.
    \n\n

    Example 2:

    \n\n
    \nInput: n = 0\nOutput: 0\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 1\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= n <= 109
    • \n
    \n", "content_cn": "

    \u521d\u59cb\u65f6\u6709\u00a0n\u00a0\u4e2a\u706f\u6ce1\u5904\u4e8e\u5173\u95ed\u72b6\u6001\u3002

    \n\n

    \u5bf9\u67d0\u4e2a\u706f\u6ce1\u5207\u6362\u5f00\u5173\u610f\u5473\u7740\uff1a\u5982\u679c\u706f\u6ce1\u72b6\u6001\u4e3a\u5173\u95ed\uff0c\u90a3\u8be5\u706f\u6ce1\u5c31\u4f1a\u88ab\u5f00\u542f\uff1b\u800c\u706f\u6ce1\u72b6\u6001\u4e3a\u5f00\u542f\uff0c\u90a3\u8be5\u706f\u6ce1\u5c31\u4f1a\u88ab\u5173\u95ed\u3002

    \n\n

    \u7b2c 1 \u8f6e\uff0c\u6bcf\u4e2a\u706f\u6ce1\u5207\u6362\u4e00\u6b21\u5f00\u5173\u3002\u5373\uff0c\u6253\u5f00\u6240\u6709\u7684\u706f\u6ce1\u3002

    \n\n

    \u7b2c 2 \u8f6e\uff0c\u6bcf\u4e24\u4e2a\u706f\u6ce1\u5207\u6362\u4e00\u6b21\u5f00\u5173\u3002 \u5373\uff0c\u6bcf\u4e24\u4e2a\u706f\u6ce1\u5173\u95ed\u4e00\u4e2a\u3002

    \n\n

    \u7b2c 3 \u8f6e\uff0c\u6bcf\u4e09\u4e2a\u706f\u6ce1\u5207\u6362\u4e00\u6b21\u5f00\u5173\u3002

    \n\n

    \u7b2c\u00a0i \u8f6e\uff0c\u6bcf\u00a0i\u00a0\u4e2a\u706f\u6ce1\u5207\u6362\u4e00\u6b21\u5f00\u5173\u3002 \u800c\u7b2c\u00a0n\u00a0\u8f6e\uff0c\u4f60\u53ea\u5207\u6362\u6700\u540e\u4e00\u4e2a\u706f\u6ce1\u7684\u5f00\u5173\u3002

    \n\n

    \u627e\u51fa\u00a0n\u00a0\u8f6e\u540e\u6709\u591a\u5c11\u4e2a\u4eae\u7740\u7684\u706f\u6ce1\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1an = 3\n\u8f93\u51fa\uff1a1 \n\u89e3\u91ca\uff1a\n\u521d\u59cb\u65f6, \u706f\u6ce1\u72b6\u6001 [\u5173\u95ed, \u5173\u95ed, \u5173\u95ed].\n\u7b2c\u4e00\u8f6e\u540e, \u706f\u6ce1\u72b6\u6001 [\u5f00\u542f, \u5f00\u542f, \u5f00\u542f].\n\u7b2c\u4e8c\u8f6e\u540e, \u706f\u6ce1\u72b6\u6001 [\u5f00\u542f, \u5173\u95ed, \u5f00\u542f].\n\u7b2c\u4e09\u8f6e\u540e, \u706f\u6ce1\u72b6\u6001 [\u5f00\u542f, \u5173\u95ed, \u5173\u95ed]. \n\n\u4f60\u5e94\u8be5\u8fd4\u56de 1\uff0c\u56e0\u4e3a\u53ea\u6709\u4e00\u4e2a\u706f\u6ce1\u8fd8\u4eae\u7740\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 0\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= n <= 109
    • \n
    \n", "tags_en": ["Brainteaser", "Math"], "tags_cn": ["\u8111\u7b4b\u6025\u8f6c\u5f2f", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int bulbSwitch(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int bulbSwitch(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def bulbSwitch(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def bulbSwitch(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint bulbSwitch(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int BulbSwitch(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar bulbSwitch = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef bulb_switch(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func bulbSwitch(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func bulbSwitch(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def bulbSwitch(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun bulbSwitch(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn bulb_switch(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function bulbSwitch($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function bulbSwitch(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (bulb-switch n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0319](https://leetcode-cn.com/problems/bulb-switcher)", "[\u706f\u6ce1\u5f00\u5173](/solution/0300-0399/0319.Bulb%20Switcher/README.md)", "`\u8111\u7b4b\u6025\u8f6c\u5f2f`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0319](https://leetcode.com/problems/bulb-switcher)", "[Bulb Switcher](/solution/0300-0399/0319.Bulb%20Switcher/README_EN.md)", "`Brainteaser`,`Math`", "Medium", ""]}, {"question_id": "0318", "frontend_question_id": "0318", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-product-of-word-lengths", "url_en": "https://leetcode.com/problems/maximum-product-of-word-lengths", "relative_path_cn": "/solution/0300-0399/0318.Maximum%20Product%20of%20Word%20Lengths/README.md", "relative_path_en": "/solution/0300-0399/0318.Maximum%20Product%20of%20Word%20Lengths/README_EN.md", "title_cn": "\u6700\u5927\u5355\u8bcd\u957f\u5ea6\u4e58\u79ef", "title_en": "Maximum Product of Word Lengths", "question_title_slug": "maximum-product-of-word-lengths", "content_en": "

    Given a string array words, return the maximum value of length(word[i]) * length(word[j]) where the two words do not share common letters. If no such two words exist, return 0.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: words = ["abcw","baz","foo","bar","xtfn","abcdef"]\nOutput: 16\nExplanation: The two words can be "abcw", "xtfn".\n
    \n\n

    Example 2:

    \n\n
    \nInput: words = ["a","ab","abc","d","cd","bcd","abcd"]\nOutput: 4\nExplanation: The two words can be "ab", "cd".\n
    \n\n

    Example 3:

    \n\n
    \nInput: words = ["a","aa","aaa","aaaa"]\nOutput: 0\nExplanation: No such pair of words.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= words.length <= 1000
    • \n\t
    • 1 <= words[i].length <= 1000
    • \n\t
    • words[i] consists only of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4 words\uff0c\u627e\u5230 length(word[i]) * length(word[j]) \u7684\u6700\u5927\u503c\uff0c\u5e76\u4e14\u8fd9\u4e24\u4e2a\u5355\u8bcd\u4e0d\u542b\u6709\u516c\u5171\u5b57\u6bcd\u3002\u4f60\u53ef\u4ee5\u8ba4\u4e3a\u6bcf\u4e2a\u5355\u8bcd\u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd\u3002\u5982\u679c\u4e0d\u5b58\u5728\u8fd9\u6837\u7684\u4e24\u4e2a\u5355\u8bcd\uff0c\u8fd4\u56de 0\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: ["abcw","baz","foo","bar","xtfn","abcdef"]\n\u8f93\u51fa: 16 \n\u89e3\u91ca: \u8fd9\u4e24\u4e2a\u5355\u8bcd\u4e3a "abcw", "xtfn"\u3002
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: ["a","ab","abc","d","cd","bcd","abcd"]\n\u8f93\u51fa: 4 \n\u89e3\u91ca: \u8fd9\u4e24\u4e2a\u5355\u8bcd\u4e3a "ab", "cd"\u3002
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u8f93\u5165: ["a","aa","aaa","aaaa"]\n\u8f93\u51fa: 0 \n\u89e3\u91ca: \u4e0d\u5b58\u5728\u8fd9\u6837\u7684\u4e24\u4e2a\u5355\u8bcd\u3002
    \n", "tags_en": ["Bit Manipulation"], "tags_cn": ["\u4f4d\u8fd0\u7b97"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxProduct(vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxProduct(String[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxProduct(self, words):\n \"\"\"\n :type words: List[str]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxProduct(self, words: List[str]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxProduct(char ** words, int wordsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxProduct(string[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @return {number}\n */\nvar maxProduct = function(words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @return {Integer}\ndef max_product(words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxProduct(_ words: [String]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxProduct(words []string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxProduct(words: Array[String]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxProduct(words: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_product(words: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @return Integer\n */\n function maxProduct($words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxProduct(words: string[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-product words)\n (-> (listof string?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0318](https://leetcode-cn.com/problems/maximum-product-of-word-lengths)", "[\u6700\u5927\u5355\u8bcd\u957f\u5ea6\u4e58\u79ef](/solution/0300-0399/0318.Maximum%20Product%20of%20Word%20Lengths/README.md)", "`\u4f4d\u8fd0\u7b97`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0318](https://leetcode.com/problems/maximum-product-of-word-lengths)", "[Maximum Product of Word Lengths](/solution/0300-0399/0318.Maximum%20Product%20of%20Word%20Lengths/README_EN.md)", "`Bit Manipulation`", "Medium", ""]}, {"question_id": "0317", "frontend_question_id": "0317", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/shortest-distance-from-all-buildings", "url_en": "https://leetcode.com/problems/shortest-distance-from-all-buildings", "relative_path_cn": "/solution/0300-0399/0317.Shortest%20Distance%20from%20All%20Buildings/README.md", "relative_path_en": "/solution/0300-0399/0317.Shortest%20Distance%20from%20All%20Buildings/README_EN.md", "title_cn": "\u79bb\u5efa\u7b51\u7269\u6700\u8fd1\u7684\u8ddd\u79bb", "title_en": "Shortest Distance from All Buildings", "question_title_slug": "shortest-distance-from-all-buildings", "content_en": "

    You are given an m x n grid grid of values 0, 1, or 2, where:

    \n\n
      \n\t
    • each 0 marks an empty land that you can pass by freely,
    • \n\t
    • each 1 marks a building that you cannot pass through, and
    • \n\t
    • each 2 marks an obstacle that you cannot pass through.
    • \n
    \n\n

    You want to build a house on an empty land that reaches all buildings in the shortest total travel distance. You can only move up, down, left, and right.

    \n\n

    Return the shortest travel distance for such a house. If it is not possible to build such a house according to the above rules, return -1.

    \n\n

    The total travel distance is the sum of the distances between the houses of the friends and the meeting point.

    \n\n

    The distance is calculated using Manhattan Distance, where distance(p1, p2) = |p2.x - p1.x| + |p2.y - p1.y|.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: grid = [[1,0,2,0,1],[0,0,0,0,0],[0,0,1,0,0]]\nOutput: 7\nExplanation: Given three buildings at (0,0), (0,4), (2,2), and an obstacle at (0,2).\nThe point (1,2) is an ideal empty land to build a house, as the total travel distance of 3+3+1=7 is minimal.\nSo return 7.\n
    \n\n

    Example 2:

    \n\n
    \nInput: grid = [[1,0]]\nOutput: 1\n
    \n\n

    Example 3:

    \n\n
    \nInput: grid = [[1]]\nOutput: -1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= m, n <= 100
    • \n\t
    • grid[i][j] is either 0, 1, or 2.
    • \n\t
    • There will be at least one building in the grid.
    • \n
    \n", "content_cn": "

    \u4f60\u662f\u4e2a\u623f\u5730\u4ea7\u5f00\u53d1\u5546\uff0c\u60f3\u8981\u9009\u62e9\u4e00\u7247\u7a7a\u5730 \u5efa\u4e00\u680b\u5927\u697c\u3002\u4f60\u60f3\u628a\u8fd9\u680b\u5927\u697c\u591f\u9020\u5728\u4e00\u4e2a\u8ddd\u79bb\u5468\u8fb9\u8bbe\u65bd\u90fd\u6bd4\u8f83\u65b9\u4fbf\u7684\u5730\u65b9\uff0c\u901a\u8fc7\u8c03\u7814\uff0c\u4f60\u5e0c\u671b\u4ece\u5b83\u51fa\u53d1\u80fd\u5728 \u6700\u77ed\u7684\u8ddd\u79bb\u548c \u5185\u62b5\u8fbe\u5468\u8fb9\u5168\u90e8\u7684\u5efa\u7b51\u7269\u3002\u8bf7\u4f60\u8ba1\u7b97\u51fa\u8fd9\u4e2a\u6700\u4f73\u7684\u9009\u5740\u5230\u5468\u8fb9\u5168\u90e8\u5efa\u7b51\u7269\u7684 \u6700\u77ed\u8ddd\u79bb\u548c\u3002

    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n

    \u4f60\u53ea\u80fd\u901a\u8fc7\u5411\u4e0a\u3001\u4e0b\u3001\u5de6\u3001\u53f3\u56db\u4e2a\u65b9\u5411\u4e0a\u79fb\u52a8\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u7531 0\u30011 \u548c 2 \u7ec4\u6210\u7684\u4e8c\u7ef4\u7f51\u683c\uff0c\u5176\u4e2d\uff1a

    \n\n
      \n\t
    • 0 \u4ee3\u8868\u4f60\u53ef\u4ee5\u81ea\u7531\u901a\u8fc7\u548c\u9009\u62e9\u5efa\u9020\u7684\u7a7a\u5730
    • \n\t
    • 1 \u4ee3\u8868\u4f60\u65e0\u6cd5\u901a\u884c\u7684\u5efa\u7b51\u7269
    • \n\t
    • 2 \u4ee3\u8868\u4f60\u65e0\u6cd5\u901a\u884c\u7684\u969c\u788d\u7269
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1a[[1,0,2,0,1],[0,0,0,0,0],[0,0,1,0,0]]\n\n1 - 0 - 2 - 0 - 1\n|   |   |   |   |\n0 - 0 - 0 - 0 - 0\n|   |   |   |   |\n0 - 0 - 1 - 0 - 0\n\u8f93\u51fa\uff1a7 \n\u89e3\u6790\uff1a\n\u7ed9\u5b9a\u4e09\u4e2a\u5efa\u7b51\u7269 (0,0)\u3001(0,4) \u548c (2,2) \u4ee5\u53ca\u4e00\u4e2a\u4f4d\u4e8e (0,2) \u7684\u969c\u788d\u7269\u3002\n\u7531\u4e8e\u603b\u8ddd\u79bb\u4e4b\u548c 3+3+1=7 \u6700\u4f18\uff0c\u6240\u4ee5\u4f4d\u7f6e (1,2) \u662f\u7b26\u5408\u8981\u6c42\u7684\u6700\u4f18\u5730\u70b9\uff0c\u6545\u8fd4\u56de7\u3002\n
    \n\n

     

    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u81f3\u5c11\u5b58\u5728\u4e00\u680b\u5efa\u7b51\u7269\uff0c\u5982\u679c\u65e0\u6cd5\u6309\u7167\u4e0a\u8ff0\u89c4\u5219\u8fd4\u56de\u5efa\u623f\u5730\u70b9\uff0c\u5219\u8bf7\u4f60\u8fd4\u56de -1\u3002
    • \n
    \n", "tags_en": ["Breadth-first Search"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int shortestDistance(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int shortestDistance(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def shortestDistance(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def shortestDistance(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint shortestDistance(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ShortestDistance(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar shortestDistance = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef shortest_distance(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func shortestDistance(_ grid: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func shortestDistance(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def shortestDistance(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun shortestDistance(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn shortest_distance(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function shortestDistance($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function shortestDistance(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (shortest-distance grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0317](https://leetcode-cn.com/problems/shortest-distance-from-all-buildings)", "[\u79bb\u5efa\u7b51\u7269\u6700\u8fd1\u7684\u8ddd\u79bb](/solution/0300-0399/0317.Shortest%20Distance%20from%20All%20Buildings/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0317](https://leetcode.com/problems/shortest-distance-from-all-buildings)", "[Shortest Distance from All Buildings](/solution/0300-0399/0317.Shortest%20Distance%20from%20All%20Buildings/README_EN.md)", "`Breadth-first Search`", "Hard", "\ud83d\udd12"]}, {"question_id": "0316", "frontend_question_id": "0316", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/remove-duplicate-letters", "url_en": "https://leetcode.com/problems/remove-duplicate-letters", "relative_path_cn": "/solution/0300-0399/0316.Remove%20Duplicate%20Letters/README.md", "relative_path_en": "/solution/0300-0399/0316.Remove%20Duplicate%20Letters/README_EN.md", "title_cn": "\u53bb\u9664\u91cd\u590d\u5b57\u6bcd", "title_en": "Remove Duplicate Letters", "question_title_slug": "remove-duplicate-letters", "content_en": "

    Given a string s, remove duplicate letters so that every letter appears once and only once. You must make sure your result is the smallest in lexicographical order among all possible results.

    \n\n

    Note: This question is the same as 1081: https://leetcode.com/problems/smallest-subsequence-of-distinct-characters/

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "bcabc"\nOutput: "abc"\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "cbacdcbc"\nOutput: "acdb"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 104
    • \n\t
    • s consists of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \uff0c\u8bf7\u4f60\u53bb\u9664\u5b57\u7b26\u4e32\u4e2d\u91cd\u590d\u7684\u5b57\u6bcd\uff0c\u4f7f\u5f97\u6bcf\u4e2a\u5b57\u6bcd\u53ea\u51fa\u73b0\u4e00\u6b21\u3002\u9700\u4fdd\u8bc1 \u8fd4\u56de\u7ed3\u679c\u7684\u5b57\u5178\u5e8f\u6700\u5c0f\uff08\u8981\u6c42\u4e0d\u80fd\u6253\u4e71\u5176\u4ed6\u5b57\u7b26\u7684\u76f8\u5bf9\u4f4d\u7f6e\uff09\u3002

    \n\n

    \u6ce8\u610f\uff1a\u8be5\u9898\u4e0e 1081 https://leetcode-cn.com/problems/smallest-subsequence-of-distinct-characters \u76f8\u540c

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"bcabc\"\n\u8f93\u51fa\uff1a\"abc\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"cbacdcbc\"\n\u8f93\u51fa\uff1a\"acdb\"
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 104
    • \n\t
    • s \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n", "tags_en": ["Stack", "Greedy", "String"], "tags_cn": ["\u6808", "\u8d2a\u5fc3\u7b97\u6cd5", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string removeDuplicateLetters(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String removeDuplicateLetters(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def removeDuplicateLetters(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def removeDuplicateLetters(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * removeDuplicateLetters(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string RemoveDuplicateLetters(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar removeDuplicateLetters = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef remove_duplicate_letters(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func removeDuplicateLetters(_ s: String) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func removeDuplicateLetters(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def removeDuplicateLetters(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun removeDuplicateLetters(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn remove_duplicate_letters(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function removeDuplicateLetters($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function removeDuplicateLetters(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (remove-duplicate-letters s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0316](https://leetcode-cn.com/problems/remove-duplicate-letters)", "[\u53bb\u9664\u91cd\u590d\u5b57\u6bcd](/solution/0300-0399/0316.Remove%20Duplicate%20Letters/README.md)", "`\u6808`,`\u8d2a\u5fc3\u7b97\u6cd5`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0316](https://leetcode.com/problems/remove-duplicate-letters)", "[Remove Duplicate Letters](/solution/0300-0399/0316.Remove%20Duplicate%20Letters/README_EN.md)", "`Stack`,`Greedy`,`String`", "Medium", ""]}, {"question_id": "0315", "frontend_question_id": "0315", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-of-smaller-numbers-after-self", "url_en": "https://leetcode.com/problems/count-of-smaller-numbers-after-self", "relative_path_cn": "/solution/0300-0399/0315.Count%20of%20Smaller%20Numbers%20After%20Self/README.md", "relative_path_en": "/solution/0300-0399/0315.Count%20of%20Smaller%20Numbers%20After%20Self/README_EN.md", "title_cn": "\u8ba1\u7b97\u53f3\u4fa7\u5c0f\u4e8e\u5f53\u524d\u5143\u7d20\u7684\u4e2a\u6570", "title_en": "Count of Smaller Numbers After Self", "question_title_slug": "count-of-smaller-numbers-after-self", "content_en": "

    You are given an integer array nums and you have to return a new counts array. The counts array has the property where counts[i] is the number of smaller elements to the right of nums[i].

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [5,2,6,1]\nOutput: [2,1,1,0]\nExplanation:\nTo the right of 5 there are 2 smaller elements (2 and 1).\nTo the right of 2 there is only 1 smaller element (1).\nTo the right of 6 there is 1 smaller element (1).\nTo the right of 1 there is 0 smaller element.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [-1]\nOutput: [0]\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [-1,-1]\nOutput: [0,0]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • -104 <= nums[i] <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums\uff0c\u6309\u8981\u6c42\u8fd4\u56de\u4e00\u4e2a\u65b0\u6570\u7ec4 counts\u3002\u6570\u7ec4 counts \u6709\u8be5\u6027\u8d28\uff1a counts[i] \u7684\u503c\u662f  nums[i] \u53f3\u4fa7\u5c0f\u4e8e nums[i] \u7684\u5143\u7d20\u7684\u6570\u91cf\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [5,2,6,1]\n\u8f93\u51fa\uff1a[2,1,1,0] \n\u89e3\u91ca\uff1a\n5 \u7684\u53f3\u4fa7\u6709 2 \u4e2a\u66f4\u5c0f\u7684\u5143\u7d20 (2 \u548c 1)\n2 \u7684\u53f3\u4fa7\u4ec5\u6709 1 \u4e2a\u66f4\u5c0f\u7684\u5143\u7d20 (1)\n6 \u7684\u53f3\u4fa7\u6709 1 \u4e2a\u66f4\u5c0f\u7684\u5143\u7d20 (1)\n1 \u7684\u53f3\u4fa7\u6709 0 \u4e2a\u66f4\u5c0f\u7684\u5143\u7d20\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= nums.length <= 10^5
    • \n\t
    • -10^4 <= nums[i] <= 10^4
    • \n
    \n", "tags_en": ["Sort", "Binary Indexed Tree", "Segment Tree", "Binary Search", "Divide and Conquer"], "tags_cn": ["\u6392\u5e8f", "\u6811\u72b6\u6570\u7ec4", "\u7ebf\u6bb5\u6811", "\u4e8c\u5206\u67e5\u627e", "\u5206\u6cbb\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector countSmaller(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List countSmaller(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countSmaller(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countSmaller(self, nums: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* countSmaller(int* nums, int numsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList CountSmaller(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar countSmaller = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer[]}\ndef count_smaller(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countSmaller(_ nums: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countSmaller(nums []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countSmaller(nums: Array[Int]): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countSmaller(nums: IntArray): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_smaller(nums: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer[]\n */\n function countSmaller($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countSmaller(nums: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-smaller nums)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0315](https://leetcode-cn.com/problems/count-of-smaller-numbers-after-self)", "[\u8ba1\u7b97\u53f3\u4fa7\u5c0f\u4e8e\u5f53\u524d\u5143\u7d20\u7684\u4e2a\u6570](/solution/0300-0399/0315.Count%20of%20Smaller%20Numbers%20After%20Self/README.md)", "`\u6392\u5e8f`,`\u6811\u72b6\u6570\u7ec4`,`\u7ebf\u6bb5\u6811`,`\u4e8c\u5206\u67e5\u627e`,`\u5206\u6cbb\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[0315](https://leetcode.com/problems/count-of-smaller-numbers-after-self)", "[Count of Smaller Numbers After Self](/solution/0300-0399/0315.Count%20of%20Smaller%20Numbers%20After%20Self/README_EN.md)", "`Sort`,`Binary Indexed Tree`,`Segment Tree`,`Binary Search`,`Divide and Conquer`", "Hard", ""]}, {"question_id": "0314", "frontend_question_id": "0314", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/binary-tree-vertical-order-traversal", "url_en": "https://leetcode.com/problems/binary-tree-vertical-order-traversal", "relative_path_cn": "/solution/0300-0399/0314.Binary%20Tree%20Vertical%20Order%20Traversal/README.md", "relative_path_en": "/solution/0300-0399/0314.Binary%20Tree%20Vertical%20Order%20Traversal/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u7684\u5782\u76f4\u904d\u5386", "title_en": "Binary Tree Vertical Order Traversal", "question_title_slug": "binary-tree-vertical-order-traversal", "content_en": "

    Given the root of a binary tree, return the vertical order traversal of its nodes' values. (i.e., from top to bottom, column by column).

    \n\n

    If two nodes are in the same row and column, the order should be from left to right.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [3,9,20,null,null,15,7]\nOutput: [[9],[3,15],[20],[7]]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [3,9,8,4,0,1,7]\nOutput: [[4],[9],[3,0,1],[8],[7]]\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: root = [3,9,8,4,0,1,7,null,null,null,2,5]\nOutput: [[4],[9,5],[3,0,1],[8,2],[7]]\n
    \n\n

    Example 4:

    \n\n
    \nInput: root = []\nOutput: []\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [0, 100].
    • \n\t
    • -100 <= Node.val <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u4e8c\u53c9\u6811\u7684\u6839\u7ed3\u70b9\uff0c\u8fd4\u56de\u5176\u7ed3\u70b9\u6309 \u5782\u76f4\u65b9\u5411\uff08\u4ece\u4e0a\u5230\u4e0b\uff0c\u9010\u5217\uff09\u904d\u5386\u7684\u7ed3\u679c\u3002

    \n\n

    \u5982\u679c\u4e24\u4e2a\u7ed3\u70b9\u5728\u540c\u4e00\u884c\u548c\u5217\uff0c\u90a3\u4e48\u987a\u5e8f\u5219\u4e3a\u00a0\u4ece\u5de6\u5230\u53f3\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [3,9,20,null,null,15,7]\n\u8f93\u51fa\uff1a[[9],[3,15],[20],[7]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [3,9,8,4,0,1,7]\n\u8f93\u51fa\uff1a[[4],[9],[3,0,1],[8],[7]]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [3,9,8,4,0,1,7,null,null,null,2,5]\n\u8f93\u51fa\uff1a[[4],[9,5],[3,0,1],[8,2],[7]]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = []\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u7ed3\u70b9\u7684\u6570\u76ee\u5728\u8303\u56f4 [0, 100] \u5185
    • \n\t
    • -100 <= Node.val <= 100
    • \n
    \n", "tags_en": ["Depth-first Search", "Breadth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector> verticalOrder(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public List> verticalOrder(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def verticalOrder(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def verticalOrder(self, root: TreeNode) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** verticalOrder(struct TreeNode* root, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public IList> VerticalOrder(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number[][]}\n */\nvar verticalOrder = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer[][]}\ndef vertical_order(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func verticalOrder(_ root: TreeNode?) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc verticalOrder(root *TreeNode) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def verticalOrder(root: TreeNode): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun verticalOrder(root: TreeNode?): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn vertical_order(root: Option>>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer[][]\n */\n function verticalOrder($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction verticalOrder(root: TreeNode | null): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (vertical-order root)\n (-> (or/c tree-node? #f) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0314](https://leetcode-cn.com/problems/binary-tree-vertical-order-traversal)", "[\u4e8c\u53c9\u6811\u7684\u5782\u76f4\u904d\u5386](/solution/0300-0399/0314.Binary%20Tree%20Vertical%20Order%20Traversal/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0314](https://leetcode.com/problems/binary-tree-vertical-order-traversal)", "[Binary Tree Vertical Order Traversal](/solution/0300-0399/0314.Binary%20Tree%20Vertical%20Order%20Traversal/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`", "Medium", "\ud83d\udd12"]}, {"question_id": "0313", "frontend_question_id": "0313", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/super-ugly-number", "url_en": "https://leetcode.com/problems/super-ugly-number", "relative_path_cn": "/solution/0300-0399/0313.Super%20Ugly%20Number/README.md", "relative_path_en": "/solution/0300-0399/0313.Super%20Ugly%20Number/README_EN.md", "title_cn": "\u8d85\u7ea7\u4e11\u6570", "title_en": "Super Ugly Number", "question_title_slug": "super-ugly-number", "content_en": "

    A super ugly number is a positive integer whose prime factors are in the array primes.

    \n\n

    Given an integer n and an array of integers primes, return the nth super ugly number.

    \n\n

    The nth super ugly number is guaranteed to fit in a 32-bit signed integer.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 12, primes = [2,7,13,19]\nOutput: 32\nExplanation: [1,2,4,7,8,13,14,16,19,26,28,32] is the sequence of the first 12 super ugly numbers given primes = [2,7,13,19].\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 1, primes = [2,3,5]\nOutput: 1\nExplanation: 1 has no prime factors, therefore all of its prime factors are in the array primes = [2,3,5].\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 106
    • \n\t
    • 1 <= primes.length <= 100
    • \n\t
    • 2 <= primes[i] <= 1000
    • \n\t
    • primes[i] is guaranteed to be a prime number.
    • \n\t
    • All the values of primes are unique and sorted in ascending order.
    • \n
    \n", "content_cn": "

    \u7f16\u5199\u4e00\u6bb5\u7a0b\u5e8f\u6765\u67e5\u627e\u7b2c n \u4e2a\u8d85\u7ea7\u4e11\u6570\u3002

    \n\n

    \u8d85\u7ea7\u4e11\u6570\u662f\u6307\u5176\u6240\u6709\u8d28\u56e0\u6570\u90fd\u662f\u957f\u5ea6\u4e3a k \u7684\u8d28\u6570\u5217\u8868 primes \u4e2d\u7684\u6b63\u6574\u6570\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: n = 12, primes = [2,7,13,19]\n\u8f93\u51fa: 32 \n\u89e3\u91ca: \u7ed9\u5b9a\u957f\u5ea6\u4e3a 4 \u7684\u8d28\u6570\u5217\u8868 primes = [2,7,13,19]\uff0c\u524d 12 \u4e2a\u8d85\u7ea7\u4e11\u6570\u5e8f\u5217\u4e3a\uff1a[1,2,4,7,8,13,14,16,19,26,28,32] \u3002
    \n\n

    \u8bf4\u660e:

    \n\n
      \n\t
    • 1 \u662f\u4efb\u4f55\u7ed9\u5b9a primes \u7684\u8d85\u7ea7\u4e11\u6570\u3002
    • \n\t
    •  \u7ed9\u5b9a primes \u4e2d\u7684\u6570\u5b57\u4ee5\u5347\u5e8f\u6392\u5217\u3002
    • \n\t
    • 0 < k ≤ 100, 0 < n ≤ 106, 0 < primes[i] < 1000 \u3002
    • \n\t
    • \u7b2c n \u4e2a\u8d85\u7ea7\u4e11\u6570\u786e\u4fdd\u5728 32 \u4f4d\u6709\u7b26\u6574\u6570\u8303\u56f4\u5185\u3002
    • \n
    \n", "tags_en": ["Heap", "Math"], "tags_cn": ["\u5806", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int nthSuperUglyNumber(int n, vector& primes) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int nthSuperUglyNumber(int n, int[] primes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def nthSuperUglyNumber(self, n, primes):\n \"\"\"\n :type n: int\n :type primes: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def nthSuperUglyNumber(self, n: int, primes: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint nthSuperUglyNumber(int n, int* primes, int primesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NthSuperUglyNumber(int n, int[] primes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[]} primes\n * @return {number}\n */\nvar nthSuperUglyNumber = function(n, primes) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[]} primes\n# @return {Integer}\ndef nth_super_ugly_number(n, primes)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func nthSuperUglyNumber(_ n: Int, _ primes: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func nthSuperUglyNumber(n int, primes []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def nthSuperUglyNumber(n: Int, primes: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun nthSuperUglyNumber(n: Int, primes: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn nth_super_ugly_number(n: i32, primes: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[] $primes\n * @return Integer\n */\n function nthSuperUglyNumber($n, $primes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function nthSuperUglyNumber(n: number, primes: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (nth-super-ugly-number n primes)\n (-> exact-integer? (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0313](https://leetcode-cn.com/problems/super-ugly-number)", "[\u8d85\u7ea7\u4e11\u6570](/solution/0300-0399/0313.Super%20Ugly%20Number/README.md)", "`\u5806`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0313](https://leetcode.com/problems/super-ugly-number)", "[Super Ugly Number](/solution/0300-0399/0313.Super%20Ugly%20Number/README_EN.md)", "`Heap`,`Math`", "Medium", ""]}, {"question_id": "0312", "frontend_question_id": "0312", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/burst-balloons", "url_en": "https://leetcode.com/problems/burst-balloons", "relative_path_cn": "/solution/0300-0399/0312.Burst%20Balloons/README.md", "relative_path_en": "/solution/0300-0399/0312.Burst%20Balloons/README_EN.md", "title_cn": "\u6233\u6c14\u7403", "title_en": "Burst Balloons", "question_title_slug": "burst-balloons", "content_en": "

    You are given n balloons, indexed from 0 to n - 1. Each balloon is painted with a number on it represented by an array nums. You are asked to burst all the balloons.

    \n\n

    If you burst the ith balloon, you will get nums[i - 1] * nums[i] * nums[i + 1] coins. If i - 1 or i + 1 goes out of bounds of the array, then treat it as if there is a balloon with a 1 painted on it.

    \n\n

    Return the maximum coins you can collect by bursting the balloons wisely.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [3,1,5,8]\nOutput: 167\nExplanation:\nnums = [3,1,5,8] --> [3,5,8] --> [3,8] --> [8] --> []\ncoins =  3*1*5    +   3*5*8   +  1*3*8  + 1*8*1 = 167
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,5]\nOutput: 10\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= n <= 500
    • \n\t
    • 0 <= nums[i] <= 100
    • \n
    \n", "content_cn": "

    \u6709 n \u4e2a\u6c14\u7403\uff0c\u7f16\u53f7\u4e3a0 \u5230 n - 1\uff0c\u6bcf\u4e2a\u6c14\u7403\u4e0a\u90fd\u6807\u6709\u4e00\u4e2a\u6570\u5b57\uff0c\u8fd9\u4e9b\u6570\u5b57\u5b58\u5728\u6570\u7ec4\u00a0nums\u00a0\u4e2d\u3002

    \n\n

    \u73b0\u5728\u8981\u6c42\u4f60\u6233\u7834\u6240\u6709\u7684\u6c14\u7403\u3002\u6233\u7834\u7b2c i \u4e2a\u6c14\u7403\uff0c\u4f60\u53ef\u4ee5\u83b7\u5f97\u00a0nums[i - 1] * nums[i] * nums[i + 1] \u679a\u786c\u5e01\u3002\u00a0\u8fd9\u91cc\u7684 i - 1 \u548c i + 1 \u4ee3\u8868\u548c\u00a0i\u00a0\u76f8\u90bb\u7684\u4e24\u4e2a\u6c14\u7403\u7684\u5e8f\u53f7\u3002\u5982\u679c i - 1\u6216 i + 1 \u8d85\u51fa\u4e86\u6570\u7ec4\u7684\u8fb9\u754c\uff0c\u90a3\u4e48\u5c31\u5f53\u5b83\u662f\u4e00\u4e2a\u6570\u5b57\u4e3a 1 \u7684\u6c14\u7403\u3002

    \n\n

    \u6c42\u6240\u80fd\u83b7\u5f97\u786c\u5e01\u7684\u6700\u5927\u6570\u91cf\u3002

    \n\n

    \u00a0

    \n\u793a\u4f8b 1\uff1a\n\n
    \n\u8f93\u5165\uff1anums = [3,1,5,8]\n\u8f93\u51fa\uff1a167\n\u89e3\u91ca\uff1a\nnums = [3,1,5,8] --> [3,5,8] --> [3,8] --> [8] --> []\ncoins =  3*1*5    +   3*5*8   +  1*3*8  + 1*8*1 = 167
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,5]\n\u8f93\u51fa\uff1a10\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= n <= 500
    • \n\t
    • 0 <= nums[i] <= 100
    • \n
    \n", "tags_en": ["Divide and Conquer", "Dynamic Programming"], "tags_cn": ["\u5206\u6cbb\u7b97\u6cd5", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxCoins(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxCoins(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxCoins(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxCoins(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxCoins(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxCoins(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar maxCoins = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef max_coins(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxCoins(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxCoins(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxCoins(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxCoins(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_coins(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function maxCoins($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxCoins(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-coins nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0312](https://leetcode-cn.com/problems/burst-balloons)", "[\u6233\u6c14\u7403](/solution/0300-0399/0312.Burst%20Balloons/README.md)", "`\u5206\u6cbb\u7b97\u6cd5`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0312](https://leetcode.com/problems/burst-balloons)", "[Burst Balloons](/solution/0300-0399/0312.Burst%20Balloons/README_EN.md)", "`Divide and Conquer`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0311", "frontend_question_id": "0311", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/sparse-matrix-multiplication", "url_en": "https://leetcode.com/problems/sparse-matrix-multiplication", "relative_path_cn": "/solution/0300-0399/0311.Sparse%20Matrix%20Multiplication/README.md", "relative_path_en": "/solution/0300-0399/0311.Sparse%20Matrix%20Multiplication/README_EN.md", "title_cn": "\u7a00\u758f\u77e9\u9635\u7684\u4e58\u6cd5", "title_en": "Sparse Matrix Multiplication", "question_title_slug": "sparse-matrix-multiplication", "content_en": "

    Given two sparse matrices mat1 of size m x k and mat2 of size k x n, return the result of mat1 x mat2. You may assume that multiplication is always possible.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: mat1 = [[1,0,0],[-1,0,3]], mat2 = [[7,0,0],[0,0,0],[0,0,1]]\nOutput: [[7,0,0],[-7,0,3]]\n
    \n\n

    Example 2:

    \n\n
    \nInput: mat1 = [[0]], mat2 = [[0]]\nOutput: [[0]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == mat1.length
    • \n\t
    • k == mat1[i].length == mat2.length
    • \n\t
    • n == mat2[i].length
    • \n\t
    • 1 <= m, n, k <= 100
    • \n\t
    • -100 <= mat1[i][j], mat2[i][j] <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a \u7a00\u758f\u77e9\u9635 A \u548c B\uff0c\u8bf7\u4f60\u8fd4\u56de AB \u7684\u7ed3\u679c\u3002\u4f60\u53ef\u4ee5\u9ed8\u8ba4 \u7684\u5217\u6570\u7b49\u4e8e \u7684\u884c\u6570\u3002

    \n\n

    \u8bf7\u4ed4\u7ec6\u9605\u8bfb\u4e0b\u9762\u7684\u793a\u4f8b\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1a\n\nA = [\n  [ 1, 0, 0],\n  [-1, 0, 3]\n]\n\nB = [\n  [ 7, 0, 0 ],\n  [ 0, 0, 0 ],\n  [ 0, 0, 1 ]\n]\n\n\u8f93\u51fa\uff1a\n\n     |  1 0 0 |   | 7 0 0 |   |  7 0 0 |\nAB = | -1 0 3 | x | 0 0 0 | = | -7 0 3 |\n                  | 0 0 1 |\n
    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> multiply(vector>& mat1, vector>& mat2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[][] multiply(int[][] mat1, int[][] mat2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def multiply(self, mat1, mat2):\n \"\"\"\n :type mat1: List[List[int]]\n :type mat2: List[List[int]]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def multiply(self, mat1: List[List[int]], mat2: List[List[int]]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** multiply(int** mat1, int mat1Size, int* mat1ColSize, int** mat2, int mat2Size, int* mat2ColSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[][] Multiply(int[][] mat1, int[][] mat2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} mat1\n * @param {number[][]} mat2\n * @return {number[][]}\n */\nvar multiply = function(mat1, mat2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} mat1\n# @param {Integer[][]} mat2\n# @return {Integer[][]}\ndef multiply(mat1, mat2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func multiply(_ mat1: [[Int]], _ mat2: [[Int]]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func multiply(mat1 [][]int, mat2 [][]int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def multiply(mat1: Array[Array[Int]], mat2: Array[Array[Int]]): Array[Array[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun multiply(mat1: Array, mat2: Array): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn multiply(mat1: Vec>, mat2: Vec>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $mat1\n * @param Integer[][] $mat2\n * @return Integer[][]\n */\n function multiply($mat1, $mat2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function multiply(mat1: number[][], mat2: number[][]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (multiply mat1 mat2)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0311](https://leetcode-cn.com/problems/sparse-matrix-multiplication)", "[\u7a00\u758f\u77e9\u9635\u7684\u4e58\u6cd5](/solution/0300-0399/0311.Sparse%20Matrix%20Multiplication/README.md)", "`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0311](https://leetcode.com/problems/sparse-matrix-multiplication)", "[Sparse Matrix Multiplication](/solution/0300-0399/0311.Sparse%20Matrix%20Multiplication/README_EN.md)", "`Hash Table`", "Medium", "\ud83d\udd12"]}, {"question_id": "0310", "frontend_question_id": "0310", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-height-trees", "url_en": "https://leetcode.com/problems/minimum-height-trees", "relative_path_cn": "/solution/0300-0399/0310.Minimum%20Height%20Trees/README.md", "relative_path_en": "/solution/0300-0399/0310.Minimum%20Height%20Trees/README_EN.md", "title_cn": "\u6700\u5c0f\u9ad8\u5ea6\u6811", "title_en": "Minimum Height Trees", "question_title_slug": "minimum-height-trees", "content_en": "

    A tree is an undirected graph in which any two vertices are connected by exactly one path. In other words, any connected graph without simple cycles is a tree.

    \n\n

    Given a tree of n nodes labelled from 0 to n - 1, and an array of n - 1 edges where edges[i] = [ai, bi] indicates that there is an undirected edge between the two nodes ai and bi in the tree, you can choose any node of the tree as the root. When you select a node x as the root, the result tree has height h. Among all possible rooted trees, those with minimum height (i.e. min(h))  are called minimum height trees (MHTs).

    \n\n

    Return a list of all MHTs' root labels. You can return the answer in any order.

    \n\n

    The height of a rooted tree is the number of edges on the longest downward path between the root and a leaf.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: n = 4, edges = [[1,0],[1,2],[1,3]]\nOutput: [1]\nExplanation: As shown, the height of the tree is 1 when the root is the node with label 1 which is the only MHT.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: n = 6, edges = [[3,0],[3,1],[3,2],[3,4],[5,4]]\nOutput: [3,4]\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 1, edges = []\nOutput: [0]\n
    \n\n

    Example 4:

    \n\n
    \nInput: n = 2, edges = [[0,1]]\nOutput: [0,1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 2 * 104
    • \n\t
    • edges.length == n - 1
    • \n\t
    • 0 <= ai, bi < n
    • \n\t
    • ai != bi
    • \n\t
    • All the pairs (ai, bi) are distinct.
    • \n\t
    • The given input is guaranteed to be a tree and there will be no repeated edges.
    • \n
    \n", "content_cn": "

    \u6811\u662f\u4e00\u4e2a\u65e0\u5411\u56fe\uff0c\u5176\u4e2d\u4efb\u4f55\u4e24\u4e2a\u9876\u70b9\u53ea\u901a\u8fc7\u4e00\u6761\u8def\u5f84\u8fde\u63a5\u3002 \u6362\u53e5\u8bdd\u8bf4\uff0c\u4e00\u4e2a\u4efb\u4f55\u6ca1\u6709\u7b80\u5355\u73af\u8def\u7684\u8fde\u901a\u56fe\u90fd\u662f\u4e00\u68f5\u6811\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u68f5\u5305\u542b\u00a0n\u00a0\u4e2a\u8282\u70b9\u7684\u6811\uff0c\u6807\u8bb0\u4e3a\u00a00\u00a0\u5230\u00a0n - 1 \u3002\u7ed9\u5b9a\u6570\u5b57\u00a0n\u00a0\u548c\u4e00\u4e2a\u6709 n - 1 \u6761\u65e0\u5411\u8fb9\u7684 edges\u00a0\u5217\u8868\uff08\u6bcf\u4e00\u4e2a\u8fb9\u90fd\u662f\u4e00\u5bf9\u6807\u7b7e\uff09\uff0c\u5176\u4e2d edges[i] = [ai, bi] \u8868\u793a\u6811\u4e2d\u8282\u70b9 ai \u548c bi \u4e4b\u95f4\u5b58\u5728\u4e00\u6761\u65e0\u5411\u8fb9\u3002

    \n\n

    \u53ef\u9009\u62e9\u6811\u4e2d\u4efb\u4f55\u4e00\u4e2a\u8282\u70b9\u4f5c\u4e3a\u6839\u3002\u5f53\u9009\u62e9\u8282\u70b9 x \u4f5c\u4e3a\u6839\u8282\u70b9\u65f6\uff0c\u8bbe\u7ed3\u679c\u6811\u7684\u9ad8\u5ea6\u4e3a h \u3002\u5728\u6240\u6709\u53ef\u80fd\u7684\u6811\u4e2d\uff0c\u5177\u6709\u6700\u5c0f\u9ad8\u5ea6\u7684\u6811\uff08\u5373\uff0cmin(h)\uff09\u88ab\u79f0\u4e3a \u6700\u5c0f\u9ad8\u5ea6\u6811 \u3002

    \n\n

    \u8bf7\u4f60\u627e\u5230\u6240\u6709\u7684 \u6700\u5c0f\u9ad8\u5ea6\u6811 \u5e76\u6309 \u4efb\u610f\u987a\u5e8f \u8fd4\u56de\u5b83\u4eec\u7684\u6839\u8282\u70b9\u6807\u7b7e\u5217\u8868\u3002

    \n\u6811\u7684 \u9ad8\u5ea6 \u662f\u6307\u6839\u8282\u70b9\u548c\u53f6\u5b50\u8282\u70b9\u4e4b\u95f4\u6700\u957f\u5411\u4e0b\u8def\u5f84\u4e0a\u8fb9\u7684\u6570\u91cf\u3002\n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1an = 4, edges = [[1,0],[1,2],[1,3]]\n\u8f93\u51fa\uff1a[1]\n\u89e3\u91ca\uff1a\u5982\u56fe\u6240\u793a\uff0c\u5f53\u6839\u662f\u6807\u7b7e\u4e3a 1 \u7684\u8282\u70b9\u65f6\uff0c\u6811\u7684\u9ad8\u5ea6\u662f 1 \uff0c\u8fd9\u662f\u552f\u4e00\u7684\u6700\u5c0f\u9ad8\u5ea6\u6811\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1an = 6, edges = [[3,0],[3,1],[3,2],[3,4],[5,4]]\n\u8f93\u51fa\uff1a[3,4]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 1, edges = []\n\u8f93\u51fa\uff1a[0]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 2, edges = [[0,1]]\n\u8f93\u51fa\uff1a[0,1]\n
    \n\n

    \u00a0

    \n\n
      \n
    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 2 * 104
    • \n\t
    • edges.length == n - 1
    • \n\t
    • 0 <= ai, bi < n
    • \n\t
    • ai != bi
    • \n\t
    • \u6240\u6709 (ai, bi) \u4e92\u4e0d\u76f8\u540c
    • \n\t
    • \u7ed9\u5b9a\u7684\u8f93\u5165 \u4fdd\u8bc1 \u662f\u4e00\u68f5\u6811\uff0c\u5e76\u4e14 \u4e0d\u4f1a\u6709\u91cd\u590d\u7684\u8fb9
    • \n
    \n", "tags_en": ["Breadth-first Search", "Graph"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findMinHeightTrees(int n, vector>& edges) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List findMinHeightTrees(int n, int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findMinHeightTrees(self, n, edges):\n \"\"\"\n :type n: int\n :type edges: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findMinHeightTrees(self, n: int, edges: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* findMinHeightTrees(int n, int** edges, int edgesSize, int* edgesColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList FindMinHeightTrees(int n, int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} edges\n * @return {number[]}\n */\nvar findMinHeightTrees = function(n, edges) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} edges\n# @return {Integer[]}\ndef find_min_height_trees(n, edges)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findMinHeightTrees(_ n: Int, _ edges: [[Int]]) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findMinHeightTrees(n int, edges [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findMinHeightTrees(n: Int, edges: Array[Array[Int]]): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findMinHeightTrees(n: Int, edges: Array): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_min_height_trees(n: i32, edges: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $edges\n * @return Integer[]\n */\n function findMinHeightTrees($n, $edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findMinHeightTrees(n: number, edges: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-min-height-trees n edges)\n (-> exact-integer? (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0310](https://leetcode-cn.com/problems/minimum-height-trees)", "[\u6700\u5c0f\u9ad8\u5ea6\u6811](/solution/0300-0399/0310.Minimum%20Height%20Trees/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u56fe`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0310](https://leetcode.com/problems/minimum-height-trees)", "[Minimum Height Trees](/solution/0300-0399/0310.Minimum%20Height%20Trees/README_EN.md)", "`Breadth-first Search`,`Graph`", "Medium", ""]}, {"question_id": "0309", "frontend_question_id": "0309", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-with-cooldown", "url_en": "https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-cooldown", "relative_path_cn": "/solution/0300-0399/0309.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20with%20Cooldown/README.md", "relative_path_en": "/solution/0300-0399/0309.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20with%20Cooldown/README_EN.md", "title_cn": "\u6700\u4f73\u4e70\u5356\u80a1\u7968\u65f6\u673a\u542b\u51b7\u51bb\u671f", "title_en": "Best Time to Buy and Sell Stock with Cooldown", "question_title_slug": "best-time-to-buy-and-sell-stock-with-cooldown", "content_en": "

    You are given an array prices where prices[i] is the price of a given stock on the ith day.

    \n\n

    Find the maximum profit you can achieve. You may complete as many transactions as you like (i.e., buy one and sell one share of the stock multiple times) with the following restrictions:

    \n\n
      \n\t
    • After you sell your stock, you cannot buy stock on the next day (i.e., cooldown one day).
    • \n
    \n\n

    Note: You may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again).

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: prices = [1,2,3,0,2]\nOutput: 3\nExplanation: transactions = [buy, sell, cooldown, buy, sell]\n
    \n\n

    Example 2:

    \n\n
    \nInput: prices = [1]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= prices.length <= 5000
    • \n\t
    • 0 <= prices[i] <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\uff0c\u5176\u4e2d\u7b2c i \u4e2a\u5143\u7d20\u4ee3\u8868\u4e86\u7b2c i \u5929\u7684\u80a1\u7968\u4ef7\u683c \u3002\u200b

    \n\n

    \u8bbe\u8ba1\u4e00\u4e2a\u7b97\u6cd5\u8ba1\u7b97\u51fa\u6700\u5927\u5229\u6da6\u3002\u5728\u6ee1\u8db3\u4ee5\u4e0b\u7ea6\u675f\u6761\u4ef6\u4e0b\uff0c\u4f60\u53ef\u4ee5\u5c3d\u53ef\u80fd\u5730\u5b8c\u6210\u66f4\u591a\u7684\u4ea4\u6613\uff08\u591a\u6b21\u4e70\u5356\u4e00\u652f\u80a1\u7968\uff09:

    \n\n
      \n\t
    • \u4f60\u4e0d\u80fd\u540c\u65f6\u53c2\u4e0e\u591a\u7b14\u4ea4\u6613\uff08\u4f60\u5fc5\u987b\u5728\u518d\u6b21\u8d2d\u4e70\u524d\u51fa\u552e\u6389\u4e4b\u524d\u7684\u80a1\u7968\uff09\u3002
    • \n\t
    • \u5356\u51fa\u80a1\u7968\u540e\uff0c\u4f60\u65e0\u6cd5\u5728\u7b2c\u4e8c\u5929\u4e70\u5165\u80a1\u7968 (\u5373\u51b7\u51bb\u671f\u4e3a 1 \u5929)\u3002
    • \n
    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: [1,2,3,0,2]\n\u8f93\u51fa: 3 \n\u89e3\u91ca: \u5bf9\u5e94\u7684\u4ea4\u6613\u72b6\u6001\u4e3a: [\u4e70\u5165, \u5356\u51fa, \u51b7\u51bb\u671f, \u4e70\u5165, \u5356\u51fa]
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxProfit(vector& prices) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxProfit(int[] prices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxProfit(self, prices):\n \"\"\"\n :type prices: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxProfit(self, prices: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxProfit(int* prices, int pricesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxProfit(int[] prices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} prices\n * @return {number}\n */\nvar maxProfit = function(prices) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} prices\n# @return {Integer}\ndef max_profit(prices)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxProfit(_ prices: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxProfit(prices []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxProfit(prices: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxProfit(prices: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_profit(prices: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $prices\n * @return Integer\n */\n function maxProfit($prices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxProfit(prices: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-profit prices)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0309](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-with-cooldown)", "[\u6700\u4f73\u4e70\u5356\u80a1\u7968\u65f6\u673a\u542b\u51b7\u51bb\u671f](/solution/0300-0399/0309.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20with%20Cooldown/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0309](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-cooldown)", "[Best Time to Buy and Sell Stock with Cooldown](/solution/0300-0399/0309.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20with%20Cooldown/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0308", "frontend_question_id": "0308", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/range-sum-query-2d-mutable", "url_en": "https://leetcode.com/problems/range-sum-query-2d-mutable", "relative_path_cn": "/solution/0300-0399/0308.Range%20Sum%20Query%202D%20-%20Mutable/README.md", "relative_path_en": "/solution/0300-0399/0308.Range%20Sum%20Query%202D%20-%20Mutable/README_EN.md", "title_cn": "\u4e8c\u7ef4\u533a\u57df\u548c\u68c0\u7d22 - \u53ef\u53d8", "title_en": "Range Sum Query 2D - Mutable", "question_title_slug": "range-sum-query-2d-mutable", "content_en": "

    Given a 2D matrix matrix, handle multiple queries of the following types:

    \n\n
      \n\t
    1. Update the value of a cell in matrix.
    2. \n\t
    3. Calculate the sum of the elements of matrix inside the rectangle defined by its upper left corner (row1, col1) and lower right corner (row2, col2).
    4. \n
    \n\n

    Implement the NumMatrix class:

    \n\n
      \n\t
    • NumMatrix(int[][] matrix) Initializes the object with the integer matrix matrix.
    • \n\t
    • void update(int row, int col, int val) Updates the value of matrix[row][col] to be val.
    • \n\t
    • int sumRegion(int row1, int col1, int row2, int col2) Returns the sum of the elements of matrix inside the rectangle defined by its upper left corner (row1, col1) and lower right corner (row2, col2).
    • \n
    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput\n["NumMatrix", "sumRegion", "update", "sumRegion"]\n[[[[3, 0, 1, 4, 2], [5, 6, 3, 2, 1], [1, 2, 0, 1, 5], [4, 1, 0, 1, 7], [1, 0, 3, 0, 5]]], [2, 1, 4, 3], [3, 2, 2], [2, 1, 4, 3]]\nOutput\n[null, 8, null, 10]\n\nExplanation\nNumMatrix numMatrix = new NumMatrix([[3, 0, 1, 4, 2], [5, 6, 3, 2, 1], [1, 2, 0, 1, 5], [4, 1, 0, 1, 7], [1, 0, 3, 0, 5]]);\nnumMatrix.sumRegion(2, 1, 4, 3); // return 8 (i.e. sum of the left red rectangle)\nnumMatrix.update(3, 2, 2);       // matrix changes from left image to right image\nnumMatrix.sumRegion(2, 1, 4, 3); // return 10 (i.e. sum of the right red rectangle)\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == matrix.length
    • \n\t
    • n == matrix[i].length
    • \n\t
    • 1 <= m, n <= 200
    • \n\t
    • -105 <= matrix[i][j] <= 105
    • \n\t
    • 0 <= row < m
    • \n\t
    • 0 <= col < n
    • \n\t
    • -105 <= val <= 105
    • \n\t
    • 0 <= row1 <= row2 < m
    • \n\t
    • 0 <= col1 <= col2 < n
    • \n\t
    • At most 104 calls will be made to sumRegion and update.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a 2D \u77e9\u9635 matrix\uff0c\u8bf7\u8ba1\u7b97\u51fa\u4ece\u5de6\u4e0a\u89d2 (row1, col1) \u5230\u53f3\u4e0b\u89d2 (row2, col2) \u7ec4\u6210\u7684\u77e9\u5f62\u4e2d\u6240\u6709\u5143\u7d20\u7684\u548c\u3002

    \n\n

    \"Range
    \n\u4e0a\u8ff0\u7c89\u8272\u77e9\u5f62\u6846\u5185\u7684\uff0c\u8be5\u77e9\u5f62\u7531\u5de6\u4e0a\u89d2 (row1, col1) = (2, 1) \u548c\u53f3\u4e0b\u89d2 (row2, col2) = (4, 3) \u786e\u5b9a\u3002\u5176\u4e2d\uff0c\u6240\u5305\u62ec\u7684\u5143\u7d20\u603b\u548c sum = 8\u3002

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u7ed9\u5b9a matrix = [\n  [3, 0, 1, 4, 2],\n  [5, 6, 3, 2, 1],\n  [1, 2, 0, 1, 5],\n  [4, 1, 0, 1, 7],\n  [1, 0, 3, 0, 5]\n]\n\nsumRegion(2, 1, 4, 3) -> 8\nupdate(3, 2, 2)\nsumRegion(2, 1, 4, 3) -> 10\n
    \n\n

     

    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u77e9\u9635 matrix \u7684\u503c\u53ea\u80fd\u901a\u8fc7 update \u51fd\u6570\u6765\u8fdb\u884c\u4fee\u6539
    2. \n\t
    3. \u4f60\u53ef\u4ee5\u9ed8\u8ba4 update \u51fd\u6570\u548c sumRegion \u51fd\u6570\u7684\u8c03\u7528\u6b21\u6570\u662f\u5747\u5300\u5206\u5e03\u7684
    4. \n\t
    5. \u4f60\u53ef\u4ee5\u9ed8\u8ba4 row1 ≤ row2\uff0ccol1 ≤ col2
    6. \n
    \n\n

     

    \n", "tags_en": ["Binary Indexed Tree", "Segment Tree"], "tags_cn": ["\u6811\u72b6\u6570\u7ec4", "\u7ebf\u6bb5\u6811"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class NumMatrix {\npublic:\n NumMatrix(vector>& matrix) {\n\n }\n \n void update(int row, int col, int val) {\n\n }\n \n int sumRegion(int row1, int col1, int row2, int col2) {\n\n }\n};\n\n/**\n * Your NumMatrix object will be instantiated and called as such:\n * NumMatrix* obj = new NumMatrix(matrix);\n * obj->update(row,col,val);\n * int param_2 = obj->sumRegion(row1,col1,row2,col2);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class NumMatrix {\n\n public NumMatrix(int[][] matrix) {\n\n }\n \n public void update(int row, int col, int val) {\n\n }\n \n public int sumRegion(int row1, int col1, int row2, int col2) {\n\n }\n}\n\n/**\n * Your NumMatrix object will be instantiated and called as such:\n * NumMatrix obj = new NumMatrix(matrix);\n * obj.update(row,col,val);\n * int param_2 = obj.sumRegion(row1,col1,row2,col2);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class NumMatrix(object):\n\n def __init__(self, matrix):\n \"\"\"\n :type matrix: List[List[int]]\n \"\"\"\n\n\n def update(self, row, col, val):\n \"\"\"\n :type row: int\n :type col: int\n :type val: int\n :rtype: None\n \"\"\"\n\n\n def sumRegion(self, row1, col1, row2, col2):\n \"\"\"\n :type row1: int\n :type col1: int\n :type row2: int\n :type col2: int\n :rtype: int\n \"\"\"\n\n\n\n# Your NumMatrix object will be instantiated and called as such:\n# obj = NumMatrix(matrix)\n# obj.update(row,col,val)\n# param_2 = obj.sumRegion(row1,col1,row2,col2)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class NumMatrix:\n\n def __init__(self, matrix: List[List[int]]):\n\n\n def update(self, row: int, col: int, val: int) -> None:\n\n\n def sumRegion(self, row1: int, col1: int, row2: int, col2: int) -> int:\n\n\n\n# Your NumMatrix object will be instantiated and called as such:\n# obj = NumMatrix(matrix)\n# obj.update(row,col,val)\n# param_2 = obj.sumRegion(row1,col1,row2,col2)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} NumMatrix;\n\n\nNumMatrix* numMatrixCreate(int** matrix, int matrixSize, int* matrixColSize) {\n\n}\n\nvoid numMatrixUpdate(NumMatrix* obj, int row, int col, int val) {\n\n}\n\nint numMatrixSumRegion(NumMatrix* obj, int row1, int col1, int row2, int col2) {\n\n}\n\nvoid numMatrixFree(NumMatrix* obj) {\n\n}\n\n/**\n * Your NumMatrix struct will be instantiated and called as such:\n * NumMatrix* obj = numMatrixCreate(matrix, matrixSize, matrixColSize);\n * numMatrixUpdate(obj, row, col, val);\n \n * int param_2 = numMatrixSumRegion(obj, row1, col1, row2, col2);\n \n * numMatrixFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class NumMatrix {\n\n public NumMatrix(int[][] matrix) {\n\n }\n \n public void Update(int row, int col, int val) {\n\n }\n \n public int SumRegion(int row1, int col1, int row2, int col2) {\n\n }\n}\n\n/**\n * Your NumMatrix object will be instantiated and called as such:\n * NumMatrix obj = new NumMatrix(matrix);\n * obj.Update(row,col,val);\n * int param_2 = obj.SumRegion(row1,col1,row2,col2);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} matrix\n */\nvar NumMatrix = function(matrix) {\n\n};\n\n/** \n * @param {number} row \n * @param {number} col \n * @param {number} val\n * @return {void}\n */\nNumMatrix.prototype.update = function(row, col, val) {\n\n};\n\n/** \n * @param {number} row1 \n * @param {number} col1 \n * @param {number} row2 \n * @param {number} col2\n * @return {number}\n */\nNumMatrix.prototype.sumRegion = function(row1, col1, row2, col2) {\n\n};\n\n/**\n * Your NumMatrix object will be instantiated and called as such:\n * var obj = new NumMatrix(matrix)\n * obj.update(row,col,val)\n * var param_2 = obj.sumRegion(row1,col1,row2,col2)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class NumMatrix\n\n=begin\n :type matrix: Integer[][]\n=end\n def initialize(matrix)\n\n end\n\n\n=begin\n :type row: Integer\n :type col: Integer\n :type val: Integer\n :rtype: Void\n=end\n def update(row, col, val)\n\n end\n\n\n=begin\n :type row1: Integer\n :type col1: Integer\n :type row2: Integer\n :type col2: Integer\n :rtype: Integer\n=end\n def sum_region(row1, col1, row2, col2)\n\n end\n\n\nend\n\n# Your NumMatrix object will be instantiated and called as such:\n# obj = NumMatrix.new(matrix)\n# obj.update(row, col, val)\n# param_2 = obj.sum_region(row1, col1, row2, col2)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass NumMatrix {\n\n init(_ matrix: [[Int]]) {\n\n }\n \n func update(_ row: Int, _ col: Int, _ val: Int) {\n\n }\n \n func sumRegion(_ row1: Int, _ col1: Int, _ row2: Int, _ col2: Int) -> Int {\n\n }\n}\n\n/**\n * Your NumMatrix object will be instantiated and called as such:\n * let obj = NumMatrix(matrix)\n * obj.update(row, col, val)\n * let ret_2: Int = obj.sumRegion(row1, col1, row2, col2)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type NumMatrix struct {\n\n}\n\n\nfunc Constructor(matrix [][]int) NumMatrix {\n\n}\n\n\nfunc (this *NumMatrix) Update(row int, col int, val int) {\n\n}\n\n\nfunc (this *NumMatrix) SumRegion(row1 int, col1 int, row2 int, col2 int) int {\n\n}\n\n\n/**\n * Your NumMatrix object will be instantiated and called as such:\n * obj := Constructor(matrix);\n * obj.Update(row,col,val);\n * param_2 := obj.SumRegion(row1,col1,row2,col2);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class NumMatrix(_matrix: Array[Array[Int]]) {\n\n def update(row: Int, col: Int, `val`: Int) {\n\n }\n\n def sumRegion(row1: Int, col1: Int, row2: Int, col2: Int): Int = {\n\n }\n\n}\n\n/**\n * Your NumMatrix object will be instantiated and called as such:\n * var obj = new NumMatrix(matrix)\n * obj.update(row,col,`val`)\n * var param_2 = obj.sumRegion(row1,col1,row2,col2)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class NumMatrix(matrix: Array) {\n\n fun update(row: Int, col: Int, `val`: Int) {\n\n }\n\n fun sumRegion(row1: Int, col1: Int, row2: Int, col2: Int): Int {\n\n }\n\n}\n\n/**\n * Your NumMatrix object will be instantiated and called as such:\n * var obj = NumMatrix(matrix)\n * obj.update(row,col,`val`)\n * var param_2 = obj.sumRegion(row1,col1,row2,col2)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct NumMatrix {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl NumMatrix {\n\n fn new(matrix: Vec>) -> Self {\n\n }\n \n fn update(&self, row: i32, col: i32, val: i32) {\n\n }\n \n fn sum_region(&self, row1: i32, col1: i32, row2: i32, col2: i32) -> i32 {\n\n }\n}\n\n/**\n * Your NumMatrix object will be instantiated and called as such:\n * let obj = NumMatrix::new(matrix);\n * obj.update(row, col, val);\n * let ret_2: i32 = obj.sum_region(row1, col1, row2, col2);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class NumMatrix {\n /**\n * @param Integer[][] $matrix\n */\n function __construct($matrix) {\n\n }\n\n /**\n * @param Integer $row\n * @param Integer $col\n * @param Integer $val\n * @return NULL\n */\n function update($row, $col, $val) {\n\n }\n\n /**\n * @param Integer $row1\n * @param Integer $col1\n * @param Integer $row2\n * @param Integer $col2\n * @return Integer\n */\n function sumRegion($row1, $col1, $row2, $col2) {\n\n }\n}\n\n/**\n * Your NumMatrix object will be instantiated and called as such:\n * $obj = NumMatrix($matrix);\n * $obj->update($row, $col, $val);\n * $ret_2 = $obj->sumRegion($row1, $col1, $row2, $col2);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class NumMatrix {\n constructor(matrix: number[][]) {\n\n }\n\n update(row: number, col: number, val: number): void {\n\n }\n\n sumRegion(row1: number, col1: number, row2: number, col2: number): number {\n\n }\n}\n\n/**\n * Your NumMatrix object will be instantiated and called as such:\n * var obj = new NumMatrix(matrix)\n * obj.update(row,col,val)\n * var param_2 = obj.sumRegion(row1,col1,row2,col2)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define num-matrix%\n (class object%\n (super-new)\n\n ; matrix : (listof (listof exact-integer?))\n (init-field\n matrix)\n \n ; update : exact-integer? exact-integer? exact-integer? -> void?\n (define/public (update row col val)\n\n )\n ; sum-region : exact-integer? exact-integer? exact-integer? exact-integer? -> exact-integer?\n (define/public (sum-region row1 col1 row2 col2)\n\n )))\n\n;; Your num-matrix% object will be instantiated and called as such:\n;; (define obj (new num-matrix% [matrix matrix]))\n;; (send obj update row col val)\n;; (define param_2 (send obj sum-region row1 col1 row2 col2))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0308](https://leetcode-cn.com/problems/range-sum-query-2d-mutable)", "[\u4e8c\u7ef4\u533a\u57df\u548c\u68c0\u7d22 - \u53ef\u53d8](/solution/0300-0399/0308.Range%20Sum%20Query%202D%20-%20Mutable/README.md)", "`\u6811\u72b6\u6570\u7ec4`,`\u7ebf\u6bb5\u6811`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0308](https://leetcode.com/problems/range-sum-query-2d-mutable)", "[Range Sum Query 2D - Mutable](/solution/0300-0399/0308.Range%20Sum%20Query%202D%20-%20Mutable/README_EN.md)", "`Binary Indexed Tree`,`Segment Tree`", "Hard", "\ud83d\udd12"]}, {"question_id": "0307", "frontend_question_id": "0307", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/range-sum-query-mutable", "url_en": "https://leetcode.com/problems/range-sum-query-mutable", "relative_path_cn": "/solution/0300-0399/0307.Range%20Sum%20Query%20-%20Mutable/README.md", "relative_path_en": "/solution/0300-0399/0307.Range%20Sum%20Query%20-%20Mutable/README_EN.md", "title_cn": "\u533a\u57df\u548c\u68c0\u7d22 - \u6570\u7ec4\u53ef\u4fee\u6539", "title_en": "Range Sum Query - Mutable", "question_title_slug": "range-sum-query-mutable", "content_en": "

    Given an integer array nums, handle multiple queries of the following types:

    \n\n
      \n\t
    1. Update the value of an element in nums.
    2. \n\t
    3. Calculate the sum of the elements of nums between indices left and right inclusive where left <= right.
    4. \n
    \n\n

    Implement the NumArray class:

    \n\n
      \n\t
    • NumArray(int[] nums) Initializes the object with the integer array nums.
    • \n\t
    • void update(int index, int val) Updates the value of nums[index] to be val.
    • \n\t
    • int sumRange(int left, int right) Returns the sum of the elements of nums between indices left and right inclusive (i.e. nums[left] + nums[left + 1] + ... + nums[right]).
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["NumArray", "sumRange", "update", "sumRange"]\n[[[1, 3, 5]], [0, 2], [1, 2], [0, 2]]\nOutput\n[null, 9, null, 8]\n\nExplanation\nNumArray numArray = new NumArray([1, 3, 5]);\nnumArray.sumRange(0, 2); // return 1 + 3 + 5 = 9\nnumArray.update(1, 2);   // nums = [1, 2, 5]\nnumArray.sumRange(0, 2); // return 1 + 2 + 5 = 8\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 3 * 104
    • \n\t
    • -100 <= nums[i] <= 100
    • \n\t
    • 0 <= index < nums.length
    • \n\t
    • -100 <= val <= 100
    • \n\t
    • 0 <= left <= right < nums.length
    • \n\t
    • At most 3 * 104 calls will be made to update and sumRange.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 nums \uff0c\u8bf7\u4f60\u5b8c\u6210\u4e24\u7c7b\u67e5\u8be2\uff0c\u5176\u4e2d\u4e00\u7c7b\u67e5\u8be2\u8981\u6c42\u66f4\u65b0\u6570\u7ec4\u4e0b\u6807\u5bf9\u5e94\u7684\u503c\uff0c\u53e6\u4e00\u7c7b\u67e5\u8be2\u8981\u6c42\u8fd4\u56de\u6570\u7ec4\u4e2d\u67d0\u4e2a\u8303\u56f4\u5185\u5143\u7d20\u7684\u603b\u548c\u3002

    \n\n

    \u5b9e\u73b0 NumArray \u7c7b\uff1a

    \n\n
    \n
    \n
      \n\t
    • NumArray(int[] nums) \u7528\u6574\u6570\u6570\u7ec4 nums \u521d\u59cb\u5316\u5bf9\u8c61
    • \n\t
    • void update(int index, int val) \u5c06 nums[index] \u7684\u503c\u66f4\u65b0\u4e3a val
    • \n\t
    • int sumRange(int left, int right) \u8fd4\u56de\u5b50\u6570\u7ec4 nums[left, right] \u7684\u603b\u548c\uff08\u5373\uff0cnums[left] + nums[left + 1], ..., nums[right]\uff09
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\n[\"NumArray\", \"sumRange\", \"update\", \"sumRange\"]\n[[[1, 3, 5]], [0, 2], [1, 2], [0, 2]]\n\u8f93\u51fa\uff1a\n[null, 9, null, 8]\n\n\u89e3\u91ca\uff1a\nNumArray numArray = new NumArray([1, 3, 5]);\nnumArray.sumRange(0, 2); // \u8fd4\u56de 9 \uff0csum([1,3,5]) = 9\nnumArray.update(1, 2);   // nums = [1,2,5]\nnumArray.sumRange(0, 2); // \u8fd4\u56de 8 \uff0csum([1,2,5]) = 8\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 3 * 104
    • \n\t
    • -100 <= nums[i] <= 100
    • \n\t
    • 0 <= index < nums.length
    • \n\t
    • -100 <= val <= 100
    • \n\t
    • 0 <= left <= right < nums.length
    • \n\t
    • \u6700\u591a\u8c03\u7528 3 * 104 \u6b21 update \u548c sumRange \u65b9\u6cd5
    • \n
    \n
    \n
    \n", "tags_en": ["Binary Indexed Tree", "Segment Tree"], "tags_cn": ["\u6811\u72b6\u6570\u7ec4", "\u7ebf\u6bb5\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class NumArray {\npublic:\n NumArray(vector& nums) {\n\n }\n \n void update(int index, int val) {\n\n }\n \n int sumRange(int left, int right) {\n\n }\n};\n\n/**\n * Your NumArray object will be instantiated and called as such:\n * NumArray* obj = new NumArray(nums);\n * obj->update(index,val);\n * int param_2 = obj->sumRange(left,right);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class NumArray {\n\n public NumArray(int[] nums) {\n\n }\n \n public void update(int index, int val) {\n\n }\n \n public int sumRange(int left, int right) {\n\n }\n}\n\n/**\n * Your NumArray object will be instantiated and called as such:\n * NumArray obj = new NumArray(nums);\n * obj.update(index,val);\n * int param_2 = obj.sumRange(left,right);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class NumArray(object):\n\n def __init__(self, nums):\n \"\"\"\n :type nums: List[int]\n \"\"\"\n\n\n def update(self, index, val):\n \"\"\"\n :type index: int\n :type val: int\n :rtype: None\n \"\"\"\n\n\n def sumRange(self, left, right):\n \"\"\"\n :type left: int\n :type right: int\n :rtype: int\n \"\"\"\n\n\n\n# Your NumArray object will be instantiated and called as such:\n# obj = NumArray(nums)\n# obj.update(index,val)\n# param_2 = obj.sumRange(left,right)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class NumArray:\n\n def __init__(self, nums: List[int]):\n\n\n def update(self, index: int, val: int) -> None:\n\n\n def sumRange(self, left: int, right: int) -> int:\n\n\n\n# Your NumArray object will be instantiated and called as such:\n# obj = NumArray(nums)\n# obj.update(index,val)\n# param_2 = obj.sumRange(left,right)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} NumArray;\n\n\nNumArray* numArrayCreate(int* nums, int numsSize) {\n\n}\n\nvoid numArrayUpdate(NumArray* obj, int index, int val) {\n\n}\n\nint numArraySumRange(NumArray* obj, int left, int right) {\n\n}\n\nvoid numArrayFree(NumArray* obj) {\n\n}\n\n/**\n * Your NumArray struct will be instantiated and called as such:\n * NumArray* obj = numArrayCreate(nums, numsSize);\n * numArrayUpdate(obj, index, val);\n \n * int param_2 = numArraySumRange(obj, left, right);\n \n * numArrayFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class NumArray {\n\n public NumArray(int[] nums) {\n\n }\n \n public void Update(int index, int val) {\n\n }\n \n public int SumRange(int left, int right) {\n\n }\n}\n\n/**\n * Your NumArray object will be instantiated and called as such:\n * NumArray obj = new NumArray(nums);\n * obj.Update(index,val);\n * int param_2 = obj.SumRange(left,right);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n */\nvar NumArray = function(nums) {\n\n};\n\n/** \n * @param {number} index \n * @param {number} val\n * @return {void}\n */\nNumArray.prototype.update = function(index, val) {\n\n};\n\n/** \n * @param {number} left \n * @param {number} right\n * @return {number}\n */\nNumArray.prototype.sumRange = function(left, right) {\n\n};\n\n/**\n * Your NumArray object will be instantiated and called as such:\n * var obj = new NumArray(nums)\n * obj.update(index,val)\n * var param_2 = obj.sumRange(left,right)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class NumArray\n\n=begin\n :type nums: Integer[]\n=end\n def initialize(nums)\n\n end\n\n\n=begin\n :type index: Integer\n :type val: Integer\n :rtype: Void\n=end\n def update(index, val)\n\n end\n\n\n=begin\n :type left: Integer\n :type right: Integer\n :rtype: Integer\n=end\n def sum_range(left, right)\n\n end\n\n\nend\n\n# Your NumArray object will be instantiated and called as such:\n# obj = NumArray.new(nums)\n# obj.update(index, val)\n# param_2 = obj.sum_range(left, right)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass NumArray {\n\n init(_ nums: [Int]) {\n\n }\n \n func update(_ index: Int, _ val: Int) {\n\n }\n \n func sumRange(_ left: Int, _ right: Int) -> Int {\n\n }\n}\n\n/**\n * Your NumArray object will be instantiated and called as such:\n * let obj = NumArray(nums)\n * obj.update(index, val)\n * let ret_2: Int = obj.sumRange(left, right)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type NumArray struct {\n\n}\n\n\nfunc Constructor(nums []int) NumArray {\n\n}\n\n\nfunc (this *NumArray) Update(index int, val int) {\n\n}\n\n\nfunc (this *NumArray) SumRange(left int, right int) int {\n\n}\n\n\n/**\n * Your NumArray object will be instantiated and called as such:\n * obj := Constructor(nums);\n * obj.Update(index,val);\n * param_2 := obj.SumRange(left,right);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class NumArray(_nums: Array[Int]) {\n\n def update(index: Int, `val`: Int) {\n\n }\n\n def sumRange(left: Int, right: Int): Int = {\n\n }\n\n}\n\n/**\n * Your NumArray object will be instantiated and called as such:\n * var obj = new NumArray(nums)\n * obj.update(index,`val`)\n * var param_2 = obj.sumRange(left,right)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class NumArray(nums: IntArray) {\n\n fun update(index: Int, `val`: Int) {\n\n }\n\n fun sumRange(left: Int, right: Int): Int {\n\n }\n\n}\n\n/**\n * Your NumArray object will be instantiated and called as such:\n * var obj = NumArray(nums)\n * obj.update(index,`val`)\n * var param_2 = obj.sumRange(left,right)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct NumArray {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl NumArray {\n\n fn new(nums: Vec) -> Self {\n\n }\n \n fn update(&self, index: i32, val: i32) {\n\n }\n \n fn sum_range(&self, left: i32, right: i32) -> i32 {\n\n }\n}\n\n/**\n * Your NumArray object will be instantiated and called as such:\n * let obj = NumArray::new(nums);\n * obj.update(index, val);\n * let ret_2: i32 = obj.sum_range(left, right);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class NumArray {\n /**\n * @param Integer[] $nums\n */\n function __construct($nums) {\n\n }\n\n /**\n * @param Integer $index\n * @param Integer $val\n * @return NULL\n */\n function update($index, $val) {\n\n }\n\n /**\n * @param Integer $left\n * @param Integer $right\n * @return Integer\n */\n function sumRange($left, $right) {\n\n }\n}\n\n/**\n * Your NumArray object will be instantiated and called as such:\n * $obj = NumArray($nums);\n * $obj->update($index, $val);\n * $ret_2 = $obj->sumRange($left, $right);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class NumArray {\n constructor(nums: number[]) {\n\n }\n\n update(index: number, val: number): void {\n\n }\n\n sumRange(left: number, right: number): number {\n\n }\n}\n\n/**\n * Your NumArray object will be instantiated and called as such:\n * var obj = new NumArray(nums)\n * obj.update(index,val)\n * var param_2 = obj.sumRange(left,right)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define num-array%\n (class object%\n (super-new)\n\n ; nums : (listof exact-integer?)\n (init-field\n nums)\n \n ; update : exact-integer? exact-integer? -> void?\n (define/public (update index val)\n\n )\n ; sum-range : exact-integer? exact-integer? -> exact-integer?\n (define/public (sum-range left right)\n\n )))\n\n;; Your num-array% object will be instantiated and called as such:\n;; (define obj (new num-array% [nums nums]))\n;; (send obj update index val)\n;; (define param_2 (send obj sum-range left right))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0307](https://leetcode-cn.com/problems/range-sum-query-mutable)", "[\u533a\u57df\u548c\u68c0\u7d22 - \u6570\u7ec4\u53ef\u4fee\u6539](/solution/0300-0399/0307.Range%20Sum%20Query%20-%20Mutable/README.md)", "`\u6811\u72b6\u6570\u7ec4`,`\u7ebf\u6bb5\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0307](https://leetcode.com/problems/range-sum-query-mutable)", "[Range Sum Query - Mutable](/solution/0300-0399/0307.Range%20Sum%20Query%20-%20Mutable/README_EN.md)", "`Binary Indexed Tree`,`Segment Tree`", "Medium", ""]}, {"question_id": "0306", "frontend_question_id": "0306", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/additive-number", "url_en": "https://leetcode.com/problems/additive-number", "relative_path_cn": "/solution/0300-0399/0306.Additive%20Number/README.md", "relative_path_en": "/solution/0300-0399/0306.Additive%20Number/README_EN.md", "title_cn": "\u7d2f\u52a0\u6570", "title_en": "Additive Number", "question_title_slug": "additive-number", "content_en": "

    Additive number is a string whose digits can form additive sequence.

    \n\n

    A valid additive sequence should contain at least three numbers. Except for the first two numbers, each subsequent number in the sequence must be the sum of the preceding two.

    \n\n

    Given a string containing only digits '0'-'9', write a function to determine if it's an additive number.

    \n\n

    Note: Numbers in the additive sequence cannot have leading zeros, so sequence 1, 2, 03 or 1, 02, 3 is invalid.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: "112358"\nOutput: true\nExplanation: The digits can form an additive sequence: 1, 1, 2, 3, 5, 8. \n             1 + 1 = 2, 1 + 2 = 3, 2 + 3 = 5, 3 + 5 = 8\n
    \n\n

    Example 2:

    \n\n
    \nInput: "199100199"\nOutput: true\nExplanation: The additive sequence is: 1, 99, 100, 199. \n             1 + 99 = 100, 99 + 100 = 199\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • num consists only of digits '0'-'9'.
    • \n\t
    • 1 <= num.length <= 35
    • \n
    \n\n

    Follow up:
    \nHow would you handle overflow for very large input integers?

    \n", "content_cn": "

    \u7d2f\u52a0\u6570\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u7ec4\u6210\u5b83\u7684\u6570\u5b57\u53ef\u4ee5\u5f62\u6210\u7d2f\u52a0\u5e8f\u5217\u3002

    \n\n

    \u4e00\u4e2a\u6709\u6548\u7684\u7d2f\u52a0\u5e8f\u5217\u5fc5\u987b\u81f3\u5c11\u5305\u542b 3 \u4e2a\u6570\u3002\u9664\u4e86\u6700\u5f00\u59cb\u7684\u4e24\u4e2a\u6570\u4ee5\u5916\uff0c\u5b57\u7b26\u4e32\u4e2d\u7684\u5176\u4ed6\u6570\u90fd\u7b49\u4e8e\u5b83\u4e4b\u524d\u4e24\u4e2a\u6570\u76f8\u52a0\u7684\u548c\u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u53ea\u5305\u542b\u6570\u5b57 '0'-'9' \u7684\u5b57\u7b26\u4e32\uff0c\u7f16\u5199\u4e00\u4e2a\u7b97\u6cd5\u6765\u5224\u65ad\u7ed9\u5b9a\u8f93\u5165\u662f\u5426\u662f\u7d2f\u52a0\u6570\u3002

    \n\n

    \u8bf4\u660e: \u7d2f\u52a0\u5e8f\u5217\u91cc\u7684\u6570\u4e0d\u4f1a\u4ee5 0 \u5f00\u5934\uff0c\u6240\u4ee5\u4e0d\u4f1a\u51fa\u73b0 1, 2, 03 \u6216\u8005 1, 02, 3 \u7684\u60c5\u51b5\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: "112358"\n\u8f93\u51fa: true \n\u89e3\u91ca: \u7d2f\u52a0\u5e8f\u5217\u4e3a: 1, 1, 2, 3, 5, 8 \u30021 + 1 = 2, 1 + 2 = 3, 2 + 3 = 5, 3 + 5 = 8\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: "199100199"\n\u8f93\u51fa: true \n\u89e3\u91ca: \u7d2f\u52a0\u5e8f\u5217\u4e3a: 1, 99, 100, 199\u30021 + 99 = 100, 99 + 100 = 199
    \n\n

    \u8fdb\u9636:
    \n\u4f60\u5982\u4f55\u5904\u7406\u4e00\u4e2a\u6ea2\u51fa\u7684\u8fc7\u5927\u7684\u6574\u6570\u8f93\u5165?

    \n", "tags_en": ["Backtracking"], "tags_cn": ["\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isAdditiveNumber(string num) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isAdditiveNumber(String num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isAdditiveNumber(self, num):\n \"\"\"\n :type num: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isAdditiveNumber(self, num: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isAdditiveNumber(char * num){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsAdditiveNumber(string num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} num\n * @return {boolean}\n */\nvar isAdditiveNumber = function(num) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} num\n# @return {Boolean}\ndef is_additive_number(num)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isAdditiveNumber(_ num: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isAdditiveNumber(num string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isAdditiveNumber(num: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isAdditiveNumber(num: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_additive_number(num: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $num\n * @return Boolean\n */\n function isAdditiveNumber($num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isAdditiveNumber(num: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-additive-number num)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0306](https://leetcode-cn.com/problems/additive-number)", "[\u7d2f\u52a0\u6570](/solution/0300-0399/0306.Additive%20Number/README.md)", "`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0306](https://leetcode.com/problems/additive-number)", "[Additive Number](/solution/0300-0399/0306.Additive%20Number/README_EN.md)", "`Backtracking`", "Medium", ""]}, {"question_id": "0305", "frontend_question_id": "0305", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/number-of-islands-ii", "url_en": "https://leetcode.com/problems/number-of-islands-ii", "relative_path_cn": "/solution/0300-0399/0305.Number%20of%20Islands%20II/README.md", "relative_path_en": "/solution/0300-0399/0305.Number%20of%20Islands%20II/README_EN.md", "title_cn": "\u5c9b\u5c7f\u6570\u91cf II", "title_en": "Number of Islands II", "question_title_slug": "number-of-islands-ii", "content_en": "

    You are given an empty 2D binary grid grid of size m x n. The grid represents a map where 0's represent water and 1's represent land. Initially, all the cells of grid are water cells (i.e., all the cells are 0's).

    \n\n

    We may perform an add land operation which turns the water at position into a land. You are given an array positions where positions[i] = [ri, ci] is the position (ri, ci) at which we should operate the ith operation.

    \n\n

    Return an array of integers answer where answer[i] is the number of islands after turning the cell (ri, ci) into a land.

    \n\n

    An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surrounded by water.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: m = 3, n = 3, positions = [[0,0],[0,1],[1,2],[2,1]]\nOutput: [1,1,2,3]\nExplanation:\nInitially, the 2d grid is filled with water.\n- Operation #1: addLand(0, 0) turns the water at grid[0][0] into a land. We have 1 island.\n- Operation #2: addLand(0, 1) turns the water at grid[0][1] into a land. We still have 1 island.\n- Operation #3: addLand(1, 2) turns the water at grid[1][2] into a land. We have 2 islands.\n- Operation #4: addLand(2, 1) turns the water at grid[2][1] into a land. We have 3 islands.\n
    \n\n

    Example 2:

    \n\n
    \nInput: m = 1, n = 1, positions = [[0,0]]\nOutput: [1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= m, n, positions.length <= 104
    • \n\t
    • 1 <= m * n <= 104
    • \n\t
    • positions[i].length == 2
    • \n\t
    • 0 <= ri < m
    • \n\t
    • 0 <= ci < n
    • \n
    \n\n

     

    \n

    Follow up: Could you solve it in time complexity O(k log(mn)), where k == positions.length?

    \n", "content_cn": "

    \u5047\u8bbe\u4f60\u8bbe\u8ba1\u4e00\u4e2a\u6e38\u620f\uff0c\u7528\u4e00\u4e2a m \u884c n \u5217\u7684 2D \u7f51\u683c\u6765\u5b58\u50a8\u4f60\u7684\u6e38\u620f\u5730\u56fe\u3002

    \n\n

    \u8d77\u59cb\u7684\u65f6\u5019\uff0c\u6bcf\u4e2a\u683c\u5b50\u7684\u5730\u5f62\u90fd\u88ab\u9ed8\u8ba4\u6807\u8bb0\u4e3a\u300c\u6c34\u300d\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528 addLand \u8fdb\u884c\u64cd\u4f5c\uff0c\u5c06\u4f4d\u7f6e (row, col) \u7684\u300c\u6c34\u300d\u53d8\u6210\u300c\u9646\u5730\u300d\u3002

    \n\n

    \u4f60\u5c06\u4f1a\u88ab\u7ed9\u5b9a\u4e00\u4e2a\u5217\u8868\uff0c\u6765\u8bb0\u5f55\u6240\u6709\u9700\u8981\u88ab\u64cd\u4f5c\u7684\u4f4d\u7f6e\uff0c\u7136\u540e\u4f60\u9700\u8981\u8fd4\u56de\u8ba1\u7b97\u51fa\u6765 \u6bcf\u6b21 addLand \u64cd\u4f5c\u540e\u5c9b\u5c7f\u7684\u6570\u91cf\u3002

    \n\n

    \u6ce8\u610f\uff1a\u4e00\u4e2a\u5c9b\u7684\u5b9a\u4e49\u662f\u88ab\u300c\u6c34\u300d\u5305\u56f4\u7684\u300c\u9646\u5730\u300d\uff0c\u901a\u8fc7\u6c34\u5e73\u65b9\u5411\u6216\u8005\u5782\u76f4\u65b9\u5411\u4e0a\u76f8\u90bb\u7684\u9646\u5730\u8fde\u63a5\u800c\u6210\u3002\u4f60\u53ef\u4ee5\u5047\u8bbe\u5730\u56fe\u7f51\u683c\u7684\u56db\u8fb9\u5747\u88ab\u65e0\u8fb9\u65e0\u9645\u7684\u300c\u6c34\u300d\u6240\u5305\u56f4\u3002

    \n\n

    \u8bf7\u4ed4\u7ec6\u9605\u8bfb\u4e0b\u65b9\u793a\u4f8b\u4e0e\u89e3\u6790\uff0c\u66f4\u52a0\u6df1\u5165\u4e86\u89e3\u5c9b\u5c7f\u7684\u5224\u5b9a\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: m = 3, n = 3, positions = [[0,0], [0,1], [1,2], [2,1]]\n\u8f93\u51fa: [1,1,2,3]\n
    \n\n

    \u89e3\u6790:

    \n\n

    \u8d77\u521d\uff0c\u4e8c\u7ef4\u7f51\u683c grid \u88ab\u5168\u90e8\u6ce8\u5165\u300c\u6c34\u300d\u3002\uff080 \u4ee3\u8868\u300c\u6c34\u300d\uff0c1 \u4ee3\u8868\u300c\u9646\u5730\u300d\uff09

    \n\n
    0 0 0\n0 0 0\n0 0 0\n
    \n\n

    \u64cd\u4f5c #1\uff1aaddLand(0, 0) \u5c06 grid[0][0] \u7684\u6c34\u53d8\u4e3a\u9646\u5730\u3002

    \n\n
    1 0 0\n0 0 0   Number of islands = 1\n0 0 0\n
    \n\n

    \u64cd\u4f5c #2\uff1aaddLand(0, 1) \u5c06 grid[0][1] \u7684\u6c34\u53d8\u4e3a\u9646\u5730\u3002

    \n\n
    1 1 0\n0 0 0   \u5c9b\u5c7f\u7684\u6570\u91cf\u4e3a 1\n0 0 0\n
    \n\n

    \u64cd\u4f5c #3\uff1aaddLand(1, 2) \u5c06 grid[1][2] \u7684\u6c34\u53d8\u4e3a\u9646\u5730\u3002

    \n\n
    1 1 0\n0 0 1   \u5c9b\u5c7f\u7684\u6570\u91cf\u4e3a 2\n0 0 0\n
    \n\n

    \u64cd\u4f5c #4\uff1aaddLand(2, 1) \u5c06 grid[2][1] \u7684\u6c34\u53d8\u4e3a\u9646\u5730\u3002

    \n\n
    1 1 0\n0 0 1   \u5c9b\u5c7f\u7684\u6570\u91cf\u4e3a 3\n0 1 0\n
    \n\n

    \u62d3\u5c55\uff1a

    \n\n

    \u4f60\u662f\u5426\u80fd\u5728 O(k log mn) \u7684\u65f6\u95f4\u590d\u6742\u5ea6\u7a0b\u5ea6\u5185\u5b8c\u6210\u6bcf\u6b21\u7684\u8ba1\u7b97\uff1f\uff08k \u8868\u793a positions \u7684\u957f\u5ea6\uff09

    \n", "tags_en": ["Union Find"], "tags_cn": ["\u5e76\u67e5\u96c6"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector numIslands2(int m, int n, vector>& positions) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List numIslands2(int m, int n, int[][] positions) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numIslands2(self, m, n, positions):\n \"\"\"\n :type m: int\n :type n: int\n :type positions: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numIslands2(self, m: int, n: int, positions: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* numIslands2(int m, int n, int** positions, int positionsSize, int* positionsColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList NumIslands2(int m, int n, int[][] positions) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} m\n * @param {number} n\n * @param {number[][]} positions\n * @return {number[]}\n */\nvar numIslands2 = function(m, n, positions) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} m\n# @param {Integer} n\n# @param {Integer[][]} positions\n# @return {Integer[]}\ndef num_islands2(m, n, positions)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numIslands2(_ m: Int, _ n: Int, _ positions: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numIslands2(m int, n int, positions [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numIslands2(m: Int, n: Int, positions: Array[Array[Int]]): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numIslands2(m: Int, n: Int, positions: Array): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_islands2(m: i32, n: i32, positions: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $m\n * @param Integer $n\n * @param Integer[][] $positions\n * @return Integer[]\n */\n function numIslands2($m, $n, $positions) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numIslands2(m: number, n: number, positions: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-islands2 m n positions)\n (-> exact-integer? exact-integer? (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0305](https://leetcode-cn.com/problems/number-of-islands-ii)", "[\u5c9b\u5c7f\u6570\u91cf II](/solution/0300-0399/0305.Number%20of%20Islands%20II/README.md)", "`\u5e76\u67e5\u96c6`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0305](https://leetcode.com/problems/number-of-islands-ii)", "[Number of Islands II](/solution/0300-0399/0305.Number%20of%20Islands%20II/README_EN.md)", "`Union Find`", "Hard", "\ud83d\udd12"]}, {"question_id": "0304", "frontend_question_id": "0304", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/range-sum-query-2d-immutable", "url_en": "https://leetcode.com/problems/range-sum-query-2d-immutable", "relative_path_cn": "/solution/0300-0399/0304.Range%20Sum%20Query%202D%20-%20Immutable/README.md", "relative_path_en": "/solution/0300-0399/0304.Range%20Sum%20Query%202D%20-%20Immutable/README_EN.md", "title_cn": "\u4e8c\u7ef4\u533a\u57df\u548c\u68c0\u7d22 - \u77e9\u9635\u4e0d\u53ef\u53d8", "title_en": "Range Sum Query 2D - Immutable", "question_title_slug": "range-sum-query-2d-immutable", "content_en": "

    Given a 2D matrix matrix, handle multiple queries of the following type:

    \n\n
      \n\t
    1. Calculate the sum of the elements of matrix inside the rectangle defined by its upper left corner (row1, col1) and lower right corner (row2, col2).
    2. \n
    \n\n

    Implement the NumMatrix class:

    \n\n
      \n\t
    • NumMatrix(int[][] matrix) Initializes the object with the integer matrix matrix.
    • \n\t
    • int sumRegion(int row1, int col1, int row2, int col2) Returns the sum of the elements of matrix inside the rectangle defined by its upper left corner (row1, col1) and lower right corner (row2, col2).
    • \n
    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput\n["NumMatrix", "sumRegion", "sumRegion", "sumRegion"]\n[[[[3, 0, 1, 4, 2], [5, 6, 3, 2, 1], [1, 2, 0, 1, 5], [4, 1, 0, 1, 7], [1, 0, 3, 0, 5]]], [2, 1, 4, 3], [1, 1, 2, 2], [1, 2, 2, 4]]\nOutput\n[null, 8, 11, 12]\n\nExplanation\nNumMatrix numMatrix = new NumMatrix([[3, 0, 1, 4, 2], [5, 6, 3, 2, 1], [1, 2, 0, 1, 5], [4, 1, 0, 1, 7], [1, 0, 3, 0, 5]]);\nnumMatrix.sumRegion(2, 1, 4, 3); // return 8 (i.e sum of the red rectangle)\nnumMatrix.sumRegion(1, 1, 2, 2); // return 11 (i.e sum of the green rectangle)\nnumMatrix.sumRegion(1, 2, 2, 4); // return 12 (i.e sum of the blue rectangle)\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == matrix.length
    • \n\t
    • n == matrix[i].length
    • \n\t
    • 1 <= m, n <= 200
    • \n\t
    • -105 <= matrix[i][j] <= 105
    • \n\t
    • 0 <= row1 <= row2 < m
    • \n\t
    • 0 <= col1 <= col2 < n
    • \n\t
    • At most 104 calls will be made to sumRegion.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u7ef4\u77e9\u9635\uff0c\u8ba1\u7b97\u5176\u5b50\u77e9\u5f62\u8303\u56f4\u5185\u5143\u7d20\u7684\u603b\u548c\uff0c\u8be5\u5b50\u77e9\u9635\u7684\u5de6\u4e0a\u89d2\u4e3a (row1,\u00a0col1) \uff0c\u53f3\u4e0b\u89d2\u4e3a (row2,\u00a0col2) \u3002

    \n\n

    \"Range
    \n\u4e0a\u56fe\u5b50\u77e9\u9635\u5de6\u4e0a\u89d2\u00a0(row1, col1) = (2, 1)\u00a0\uff0c\u53f3\u4e0b\u89d2(row2, col2) = (4, 3)\uff0c\u8be5\u5b50\u77e9\u5f62\u5185\u5143\u7d20\u7684\u603b\u548c\u4e3a 8\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u7ed9\u5b9a matrix = [\n  [3, 0, 1, 4, 2],\n  [5, 6, 3, 2, 1],\n  [1, 2, 0, 1, 5],\n  [4, 1, 0, 1, 7],\n  [1, 0, 3, 0, 5]\n]\n\nsumRegion(2, 1, 4, 3) -> 8\nsumRegion(1, 1, 2, 2) -> 11\nsumRegion(1, 2, 2, 4) -> 12\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u4f60\u53ef\u4ee5\u5047\u8bbe\u77e9\u9635\u4e0d\u53ef\u53d8\u3002
    • \n\t
    • \u4f1a\u591a\u6b21\u8c03\u7528\u00a0sumRegion\u00a0\u65b9\u6cd5\u3002
    • \n\t
    • \u4f60\u53ef\u4ee5\u5047\u8bbe\u00a0row1 \u2264 row2 \u4e14\u00a0col1 \u2264 col2 \u3002
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class NumMatrix {\npublic:\n NumMatrix(vector>& matrix) {\n\n }\n \n int sumRegion(int row1, int col1, int row2, int col2) {\n\n }\n};\n\n/**\n * Your NumMatrix object will be instantiated and called as such:\n * NumMatrix* obj = new NumMatrix(matrix);\n * int param_1 = obj->sumRegion(row1,col1,row2,col2);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class NumMatrix {\n\n public NumMatrix(int[][] matrix) {\n\n }\n \n public int sumRegion(int row1, int col1, int row2, int col2) {\n\n }\n}\n\n/**\n * Your NumMatrix object will be instantiated and called as such:\n * NumMatrix obj = new NumMatrix(matrix);\n * int param_1 = obj.sumRegion(row1,col1,row2,col2);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class NumMatrix(object):\n\n def __init__(self, matrix):\n \"\"\"\n :type matrix: List[List[int]]\n \"\"\"\n\n\n def sumRegion(self, row1, col1, row2, col2):\n \"\"\"\n :type row1: int\n :type col1: int\n :type row2: int\n :type col2: int\n :rtype: int\n \"\"\"\n\n\n\n# Your NumMatrix object will be instantiated and called as such:\n# obj = NumMatrix(matrix)\n# param_1 = obj.sumRegion(row1,col1,row2,col2)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class NumMatrix:\n\n def __init__(self, matrix: List[List[int]]):\n\n\n def sumRegion(self, row1: int, col1: int, row2: int, col2: int) -> int:\n\n\n\n# Your NumMatrix object will be instantiated and called as such:\n# obj = NumMatrix(matrix)\n# param_1 = obj.sumRegion(row1,col1,row2,col2)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} NumMatrix;\n\n\nNumMatrix* numMatrixCreate(int** matrix, int matrixSize, int* matrixColSize) {\n\n}\n\nint numMatrixSumRegion(NumMatrix* obj, int row1, int col1, int row2, int col2) {\n\n}\n\nvoid numMatrixFree(NumMatrix* obj) {\n\n}\n\n/**\n * Your NumMatrix struct will be instantiated and called as such:\n * NumMatrix* obj = numMatrixCreate(matrix, matrixSize, matrixColSize);\n * int param_1 = numMatrixSumRegion(obj, row1, col1, row2, col2);\n \n * numMatrixFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class NumMatrix {\n\n public NumMatrix(int[][] matrix) {\n\n }\n \n public int SumRegion(int row1, int col1, int row2, int col2) {\n\n }\n}\n\n/**\n * Your NumMatrix object will be instantiated and called as such:\n * NumMatrix obj = new NumMatrix(matrix);\n * int param_1 = obj.SumRegion(row1,col1,row2,col2);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} matrix\n */\nvar NumMatrix = function(matrix) {\n\n};\n\n/** \n * @param {number} row1 \n * @param {number} col1 \n * @param {number} row2 \n * @param {number} col2\n * @return {number}\n */\nNumMatrix.prototype.sumRegion = function(row1, col1, row2, col2) {\n\n};\n\n/**\n * Your NumMatrix object will be instantiated and called as such:\n * var obj = new NumMatrix(matrix)\n * var param_1 = obj.sumRegion(row1,col1,row2,col2)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class NumMatrix\n\n=begin\n :type matrix: Integer[][]\n=end\n def initialize(matrix)\n\n end\n\n\n=begin\n :type row1: Integer\n :type col1: Integer\n :type row2: Integer\n :type col2: Integer\n :rtype: Integer\n=end\n def sum_region(row1, col1, row2, col2)\n\n end\n\n\nend\n\n# Your NumMatrix object will be instantiated and called as such:\n# obj = NumMatrix.new(matrix)\n# param_1 = obj.sum_region(row1, col1, row2, col2)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass NumMatrix {\n\n init(_ matrix: [[Int]]) {\n\n }\n \n func sumRegion(_ row1: Int, _ col1: Int, _ row2: Int, _ col2: Int) -> Int {\n\n }\n}\n\n/**\n * Your NumMatrix object will be instantiated and called as such:\n * let obj = NumMatrix(matrix)\n * let ret_1: Int = obj.sumRegion(row1, col1, row2, col2)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type NumMatrix struct {\n\n}\n\n\nfunc Constructor(matrix [][]int) NumMatrix {\n\n}\n\n\nfunc (this *NumMatrix) SumRegion(row1 int, col1 int, row2 int, col2 int) int {\n\n}\n\n\n/**\n * Your NumMatrix object will be instantiated and called as such:\n * obj := Constructor(matrix);\n * param_1 := obj.SumRegion(row1,col1,row2,col2);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class NumMatrix(_matrix: Array[Array[Int]]) {\n\n def sumRegion(row1: Int, col1: Int, row2: Int, col2: Int): Int = {\n\n }\n\n}\n\n/**\n * Your NumMatrix object will be instantiated and called as such:\n * var obj = new NumMatrix(matrix)\n * var param_1 = obj.sumRegion(row1,col1,row2,col2)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class NumMatrix(matrix: Array) {\n\n fun sumRegion(row1: Int, col1: Int, row2: Int, col2: Int): Int {\n\n }\n\n}\n\n/**\n * Your NumMatrix object will be instantiated and called as such:\n * var obj = NumMatrix(matrix)\n * var param_1 = obj.sumRegion(row1,col1,row2,col2)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct NumMatrix {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl NumMatrix {\n\n fn new(matrix: Vec>) -> Self {\n\n }\n \n fn sum_region(&self, row1: i32, col1: i32, row2: i32, col2: i32) -> i32 {\n\n }\n}\n\n/**\n * Your NumMatrix object will be instantiated and called as such:\n * let obj = NumMatrix::new(matrix);\n * let ret_1: i32 = obj.sum_region(row1, col1, row2, col2);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class NumMatrix {\n /**\n * @param Integer[][] $matrix\n */\n function __construct($matrix) {\n\n }\n\n /**\n * @param Integer $row1\n * @param Integer $col1\n * @param Integer $row2\n * @param Integer $col2\n * @return Integer\n */\n function sumRegion($row1, $col1, $row2, $col2) {\n\n }\n}\n\n/**\n * Your NumMatrix object will be instantiated and called as such:\n * $obj = NumMatrix($matrix);\n * $ret_1 = $obj->sumRegion($row1, $col1, $row2, $col2);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class NumMatrix {\n constructor(matrix: number[][]) {\n\n }\n\n sumRegion(row1: number, col1: number, row2: number, col2: number): number {\n\n }\n}\n\n/**\n * Your NumMatrix object will be instantiated and called as such:\n * var obj = new NumMatrix(matrix)\n * var param_1 = obj.sumRegion(row1,col1,row2,col2)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define num-matrix%\n (class object%\n (super-new)\n\n ; matrix : (listof (listof exact-integer?))\n (init-field\n matrix)\n \n ; sum-region : exact-integer? exact-integer? exact-integer? exact-integer? -> exact-integer?\n (define/public (sum-region row1 col1 row2 col2)\n\n )))\n\n;; Your num-matrix% object will be instantiated and called as such:\n;; (define obj (new num-matrix% [matrix matrix]))\n;; (define param_1 (send obj sum-region row1 col1 row2 col2))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0304](https://leetcode-cn.com/problems/range-sum-query-2d-immutable)", "[\u4e8c\u7ef4\u533a\u57df\u548c\u68c0\u7d22 - \u77e9\u9635\u4e0d\u53ef\u53d8](/solution/0300-0399/0304.Range%20Sum%20Query%202D%20-%20Immutable/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0304](https://leetcode.com/problems/range-sum-query-2d-immutable)", "[Range Sum Query 2D - Immutable](/solution/0300-0399/0304.Range%20Sum%20Query%202D%20-%20Immutable/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0303", "frontend_question_id": "0303", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/range-sum-query-immutable", "url_en": "https://leetcode.com/problems/range-sum-query-immutable", "relative_path_cn": "/solution/0300-0399/0303.Range%20Sum%20Query%20-%20Immutable/README.md", "relative_path_en": "/solution/0300-0399/0303.Range%20Sum%20Query%20-%20Immutable/README_EN.md", "title_cn": "\u533a\u57df\u548c\u68c0\u7d22 - \u6570\u7ec4\u4e0d\u53ef\u53d8", "title_en": "Range Sum Query - Immutable", "question_title_slug": "range-sum-query-immutable", "content_en": "

    Given an integer array nums, handle multiple queries of the following type:

    \n\n
      \n\t
    1. Calculate the sum of the elements of nums between indices left and right inclusive where left <= right.
    2. \n
    \n\n

    Implement the NumArray class:

    \n\n
      \n\t
    • NumArray(int[] nums) Initializes the object with the integer array nums.
    • \n\t
    • int sumRange(int left, int right) Returns the sum of the elements of nums between indices left and right inclusive (i.e. nums[left] + nums[left + 1] + ... + nums[right]).
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["NumArray", "sumRange", "sumRange", "sumRange"]\n[[[-2, 0, 3, -5, 2, -1]], [0, 2], [2, 5], [0, 5]]\nOutput\n[null, 1, -1, -3]\n\nExplanation\nNumArray numArray = new NumArray([-2, 0, 3, -5, 2, -1]);\nnumArray.sumRange(0, 2); // return (-2) + 0 + 3 = 1\nnumArray.sumRange(2, 5); // return 3 + (-5) + 2 + (-1) = -1\nnumArray.sumRange(0, 5); // return (-2) + 0 + 3 + (-5) + 2 + (-1) = -3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 104
    • \n\t
    • -105 <= nums[i] <= 105
    • \n\t
    • 0 <= left <= right < nums.length
    • \n\t
    • At most 104 calls will be made to sumRange.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 \u00a0nums\uff0c\u6c42\u51fa\u6570\u7ec4\u4ece\u7d22\u5f15\u00a0i\u00a0\u5230\u00a0j\uff08i\u00a0\u2264\u00a0j\uff09\u8303\u56f4\u5185\u5143\u7d20\u7684\u603b\u548c\uff0c\u5305\u542b\u00a0i\u3001j\u00a0\u4e24\u70b9\u3002

    \n\n
    \n
    \n

    \u5b9e\u73b0 NumArray \u7c7b\uff1a

    \n\n
      \n\t
    • NumArray(int[] nums) \u4f7f\u7528\u6570\u7ec4 nums \u521d\u59cb\u5316\u5bf9\u8c61
    • \n\t
    • int sumRange(int i, int j) \u8fd4\u56de\u6570\u7ec4 nums \u4ece\u7d22\u5f15\u00a0i\u00a0\u5230\u00a0j\uff08i\u00a0\u2264\u00a0j\uff09\u8303\u56f4\u5185\u5143\u7d20\u7684\u603b\u548c\uff0c\u5305\u542b\u00a0i\u3001j\u00a0\u4e24\u70b9\uff08\u4e5f\u5c31\u662f sum(nums[i], nums[i + 1], ... , nums[j])\uff09
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\n[\"NumArray\", \"sumRange\", \"sumRange\", \"sumRange\"]\n[[[-2, 0, 3, -5, 2, -1]], [0, 2], [2, 5], [0, 5]]\n\u8f93\u51fa\uff1a\n[null, 1, -1, -3]\n\n\u89e3\u91ca\uff1a\nNumArray numArray = new NumArray([-2, 0, 3, -5, 2, -1]);\nnumArray.sumRange(0, 2); // return 1 ((-2) + 0 + 3)\nnumArray.sumRange(2, 5); // return -1 (3 + (-5) + 2 + (-1)) \nnumArray.sumRange(0, 5); // return -3 ((-2) + 0 + 3 + (-5) + 2 + (-1))\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= nums.length <= 104
    • \n\t
    • -105\u00a0<= nums[i] <=\u00a0105
    • \n\t
    • 0 <= i <= j < nums.length
    • \n\t
    • \u6700\u591a\u8c03\u7528 104 \u6b21 sumRange \u65b9\u6cd5
    • \n
    \n
    \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class NumArray {\npublic:\n NumArray(vector& nums) {\n\n }\n \n int sumRange(int left, int right) {\n\n }\n};\n\n/**\n * Your NumArray object will be instantiated and called as such:\n * NumArray* obj = new NumArray(nums);\n * int param_1 = obj->sumRange(left,right);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class NumArray {\n\n public NumArray(int[] nums) {\n\n }\n \n public int sumRange(int left, int right) {\n\n }\n}\n\n/**\n * Your NumArray object will be instantiated and called as such:\n * NumArray obj = new NumArray(nums);\n * int param_1 = obj.sumRange(left,right);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class NumArray(object):\n\n def __init__(self, nums):\n \"\"\"\n :type nums: List[int]\n \"\"\"\n\n\n def sumRange(self, left, right):\n \"\"\"\n :type left: int\n :type right: int\n :rtype: int\n \"\"\"\n\n\n\n# Your NumArray object will be instantiated and called as such:\n# obj = NumArray(nums)\n# param_1 = obj.sumRange(left,right)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class NumArray:\n\n def __init__(self, nums: List[int]):\n\n\n def sumRange(self, left: int, right: int) -> int:\n\n\n\n# Your NumArray object will be instantiated and called as such:\n# obj = NumArray(nums)\n# param_1 = obj.sumRange(left,right)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} NumArray;\n\n\nNumArray* numArrayCreate(int* nums, int numsSize) {\n\n}\n\nint numArraySumRange(NumArray* obj, int left, int right) {\n\n}\n\nvoid numArrayFree(NumArray* obj) {\n\n}\n\n/**\n * Your NumArray struct will be instantiated and called as such:\n * NumArray* obj = numArrayCreate(nums, numsSize);\n * int param_1 = numArraySumRange(obj, left, right);\n \n * numArrayFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class NumArray {\n\n public NumArray(int[] nums) {\n\n }\n \n public int SumRange(int left, int right) {\n\n }\n}\n\n/**\n * Your NumArray object will be instantiated and called as such:\n * NumArray obj = new NumArray(nums);\n * int param_1 = obj.SumRange(left,right);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n */\nvar NumArray = function(nums) {\n\n};\n\n/** \n * @param {number} left \n * @param {number} right\n * @return {number}\n */\nNumArray.prototype.sumRange = function(left, right) {\n\n};\n\n/**\n * Your NumArray object will be instantiated and called as such:\n * var obj = new NumArray(nums)\n * var param_1 = obj.sumRange(left,right)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class NumArray\n\n=begin\n :type nums: Integer[]\n=end\n def initialize(nums)\n\n end\n\n\n=begin\n :type left: Integer\n :type right: Integer\n :rtype: Integer\n=end\n def sum_range(left, right)\n\n end\n\n\nend\n\n# Your NumArray object will be instantiated and called as such:\n# obj = NumArray.new(nums)\n# param_1 = obj.sum_range(left, right)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass NumArray {\n\n init(_ nums: [Int]) {\n\n }\n \n func sumRange(_ left: Int, _ right: Int) -> Int {\n\n }\n}\n\n/**\n * Your NumArray object will be instantiated and called as such:\n * let obj = NumArray(nums)\n * let ret_1: Int = obj.sumRange(left, right)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type NumArray struct {\n\n}\n\n\nfunc Constructor(nums []int) NumArray {\n\n}\n\n\nfunc (this *NumArray) SumRange(left int, right int) int {\n\n}\n\n\n/**\n * Your NumArray object will be instantiated and called as such:\n * obj := Constructor(nums);\n * param_1 := obj.SumRange(left,right);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class NumArray(_nums: Array[Int]) {\n\n def sumRange(left: Int, right: Int): Int = {\n\n }\n\n}\n\n/**\n * Your NumArray object will be instantiated and called as such:\n * var obj = new NumArray(nums)\n * var param_1 = obj.sumRange(left,right)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class NumArray(nums: IntArray) {\n\n fun sumRange(left: Int, right: Int): Int {\n\n }\n\n}\n\n/**\n * Your NumArray object will be instantiated and called as such:\n * var obj = NumArray(nums)\n * var param_1 = obj.sumRange(left,right)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct NumArray {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl NumArray {\n\n fn new(nums: Vec) -> Self {\n\n }\n \n fn sum_range(&self, left: i32, right: i32) -> i32 {\n\n }\n}\n\n/**\n * Your NumArray object will be instantiated and called as such:\n * let obj = NumArray::new(nums);\n * let ret_1: i32 = obj.sum_range(left, right);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class NumArray {\n /**\n * @param Integer[] $nums\n */\n function __construct($nums) {\n\n }\n\n /**\n * @param Integer $left\n * @param Integer $right\n * @return Integer\n */\n function sumRange($left, $right) {\n\n }\n}\n\n/**\n * Your NumArray object will be instantiated and called as such:\n * $obj = NumArray($nums);\n * $ret_1 = $obj->sumRange($left, $right);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class NumArray {\n constructor(nums: number[]) {\n\n }\n\n sumRange(left: number, right: number): number {\n\n }\n}\n\n/**\n * Your NumArray object will be instantiated and called as such:\n * var obj = new NumArray(nums)\n * var param_1 = obj.sumRange(left,right)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define num-array%\n (class object%\n (super-new)\n\n ; nums : (listof exact-integer?)\n (init-field\n nums)\n \n ; sum-range : exact-integer? exact-integer? -> exact-integer?\n (define/public (sum-range left right)\n\n )))\n\n;; Your num-array% object will be instantiated and called as such:\n;; (define obj (new num-array% [nums nums]))\n;; (define param_1 (send obj sum-range left right))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0303](https://leetcode-cn.com/problems/range-sum-query-immutable)", "[\u533a\u57df\u548c\u68c0\u7d22 - \u6570\u7ec4\u4e0d\u53ef\u53d8](/solution/0300-0399/0303.Range%20Sum%20Query%20-%20Immutable/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u7b80\u5355", ""], "md_table_row_en": ["[0303](https://leetcode.com/problems/range-sum-query-immutable)", "[Range Sum Query - Immutable](/solution/0300-0399/0303.Range%20Sum%20Query%20-%20Immutable/README_EN.md)", "`Dynamic Programming`", "Easy", ""]}, {"question_id": "0302", "frontend_question_id": "0302", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/smallest-rectangle-enclosing-black-pixels", "url_en": "https://leetcode.com/problems/smallest-rectangle-enclosing-black-pixels", "relative_path_cn": "/solution/0300-0399/0302.Smallest%20Rectangle%20Enclosing%20Black%20Pixels/README.md", "relative_path_en": "/solution/0300-0399/0302.Smallest%20Rectangle%20Enclosing%20Black%20Pixels/README_EN.md", "title_cn": "\u5305\u542b\u5168\u90e8\u9ed1\u8272\u50cf\u7d20\u7684\u6700\u5c0f\u77e9\u5f62", "title_en": "Smallest Rectangle Enclosing Black Pixels", "question_title_slug": "smallest-rectangle-enclosing-black-pixels", "content_en": "

    You are given an image that is represented by a binary matrix with 0 as a white pixel and 1 as a black pixel.

    \n\n

    The black pixels are connected (i.e., there is only one black region). Pixels are connected horizontally and vertically.

    \n\n

    Given two integers x and y that represent the location of one of the black pixels, return the area of the smallest (axis-aligned) rectangle that encloses all black pixels.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: image = [["0","0","1","0"],["0","1","1","0"],["0","1","0","0"]], x = 0, y = 2\nOutput: 6\n
    \n\n

    Example 2:

    \n\n
    \nInput: image = [["1"]], x = 0, y = 0\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == image.length
    • \n\t
    • n == image[i].length
    • \n\t
    • 1 <= m, n <= 100
    • \n\t
    • image[i][j] is either '0' or '1'.
    • \n\t
    • 1 <= x < m
    • \n\t
    • 1 <= y < n
    • \n\t
    • image[x][y] == '1'.
    • \n\t
    • The black pixels in the image only form one component.
    • \n
    \n", "content_cn": "

    \u56fe\u7247\u5728\u8ba1\u7b97\u673a\u5904\u7406\u4e2d\u5f80\u5f80\u662f\u4f7f\u7528\u4e8c\u7ef4\u77e9\u9635\u6765\u8868\u793a\u7684\u3002

    \n\n

    \u5047\u8bbe\uff0c\u8fd9\u91cc\u6211\u4eec\u7528\u7684\u662f\u4e00\u5f20\u9ed1\u767d\u7684\u56fe\u7247\uff0c\u90a3\u4e48 0 \u4ee3\u8868\u767d\u8272\u50cf\u7d20\uff0c1 \u4ee3\u8868\u9ed1\u8272\u50cf\u7d20\u3002

    \n\n

    \u5176\u4e2d\u9ed1\u8272\u7684\u50cf\u7d20\u4ed6\u4eec\u76f8\u4e92\u8fde\u63a5\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u56fe\u7247\u4e2d\u53ea\u4f1a\u6709\u4e00\u7247\u8fde\u5728\u4e00\u5757\u513f\u7684\u9ed1\u8272\u50cf\u7d20\uff08\u50cf\u7d20\u70b9\u662f\u6c34\u5e73\u6216\u7ad6\u76f4\u65b9\u5411\u8fde\u63a5\u7684\uff09\u3002

    \n\n

    \u90a3\u4e48\uff0c\u7ed9\u51fa\u67d0\u4e00\u4e2a\u9ed1\u8272\u50cf\u7d20\u70b9 (x, y) \u7684\u4f4d\u7f6e\uff0c\u4f60\u662f\u5426\u53ef\u4ee5\u627e\u51fa\u5305\u542b\u5168\u90e8\u9ed1\u8272\u50cf\u7d20\u7684\u6700\u5c0f\u77e9\u5f62\uff08\u4e0e\u5750\u6807\u8f74\u5bf9\u9f50\uff09\u7684\u9762\u79ef\u5462\uff1f

    \n\n

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165:\n[\n  "0010",\n  "0110",\n  "0100"\n]\n\u548c x = 0, y = 2\n\n\u8f93\u51fa: 6\n
    \n\n

     

    \n", "tags_en": ["Binary Search"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minArea(vector>& image, int x, int y) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minArea(char[][] image, int x, int y) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minArea(self, image, x, y):\n \"\"\"\n :type image: List[List[str]]\n :type x: int\n :type y: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minArea(self, image: List[List[str]], x: int, y: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minArea(char** image, int imageSize, int* imageColSize, int x, int y){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinArea(char[][] image, int x, int y) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {character[][]} image\n * @param {number} x\n * @param {number} y\n * @return {number}\n */\nvar minArea = function(image, x, y) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Character[][]} image\n# @param {Integer} x\n# @param {Integer} y\n# @return {Integer}\ndef min_area(image, x, y)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minArea(_ image: [[Character]], _ x: Int, _ y: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minArea(image [][]byte, x int, y int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minArea(image: Array[Array[Char]], x: Int, y: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minArea(image: Array, x: Int, y: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_area(image: Vec>, x: i32, y: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $image\n * @param Integer $x\n * @param Integer $y\n * @return Integer\n */\n function minArea($image, $x, $y) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minArea(image: string[][], x: number, y: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-area image x y)\n (-> (listof (listof char?)) exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0302](https://leetcode-cn.com/problems/smallest-rectangle-enclosing-black-pixels)", "[\u5305\u542b\u5168\u90e8\u9ed1\u8272\u50cf\u7d20\u7684\u6700\u5c0f\u77e9\u5f62](/solution/0300-0399/0302.Smallest%20Rectangle%20Enclosing%20Black%20Pixels/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0302](https://leetcode.com/problems/smallest-rectangle-enclosing-black-pixels)", "[Smallest Rectangle Enclosing Black Pixels](/solution/0300-0399/0302.Smallest%20Rectangle%20Enclosing%20Black%20Pixels/README_EN.md)", "`Binary Search`", "Hard", "\ud83d\udd12"]}, {"question_id": "0301", "frontend_question_id": "0301", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/remove-invalid-parentheses", "url_en": "https://leetcode.com/problems/remove-invalid-parentheses", "relative_path_cn": "/solution/0300-0399/0301.Remove%20Invalid%20Parentheses/README.md", "relative_path_en": "/solution/0300-0399/0301.Remove%20Invalid%20Parentheses/README_EN.md", "title_cn": "\u5220\u9664\u65e0\u6548\u7684\u62ec\u53f7", "title_en": "Remove Invalid Parentheses", "question_title_slug": "remove-invalid-parentheses", "content_en": "

    Given a string s that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.

    \n\n

    Return all the possible results. You may return the answer in any order.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "()())()"\nOutput: ["(())()","()()()"]\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "(a)())()"\nOutput: ["(a())()","(a)()()"]\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = ")("\nOutput: [""]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 25
    • \n\t
    • s consists of lowercase English letters and parentheses '(' and ')'.
    • \n\t
    • There will be at most 20 parentheses in s.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u7531\u82e5\u5e72\u62ec\u53f7\u548c\u5b57\u6bcd\u7ec4\u6210\u7684\u5b57\u7b26\u4e32 s \uff0c\u5220\u9664\u6700\u5c0f\u6570\u91cf\u7684\u65e0\u6548\u62ec\u53f7\uff0c\u4f7f\u5f97\u8f93\u5165\u7684\u5b57\u7b26\u4e32\u6709\u6548\u3002

    \n\n

    \u8fd4\u56de\u6240\u6709\u53ef\u80fd\u7684\u7ed3\u679c\u3002\u7b54\u6848\u53ef\u4ee5\u6309 \u4efb\u610f\u987a\u5e8f \u8fd4\u56de\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"()())()\"\n\u8f93\u51fa\uff1a[\"(())()\",\"()()()\"]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"(a)())()\"\n\u8f93\u51fa\uff1a[\"(a())()\",\"(a)()()\"]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \")(\"\n\u8f93\u51fa\uff1a[\"\"]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 25
    • \n\t
    • s \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u4ee5\u53ca\u62ec\u53f7 '(' \u548c ')' \u7ec4\u6210
    • \n\t
    • s \u4e2d\u81f3\u591a\u542b 20 \u4e2a\u62ec\u53f7
    • \n
    \n", "tags_en": ["Depth-first Search", "Breadth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector removeInvalidParentheses(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List removeInvalidParentheses(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def removeInvalidParentheses(self, s):\n \"\"\"\n :type s: str\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def removeInvalidParentheses(self, s: str) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** removeInvalidParentheses(char * s, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList RemoveInvalidParentheses(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string[]}\n */\nvar removeInvalidParentheses = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String[]}\ndef remove_invalid_parentheses(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func removeInvalidParentheses(_ s: String) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func removeInvalidParentheses(s string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def removeInvalidParentheses(s: String): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun removeInvalidParentheses(s: String): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn remove_invalid_parentheses(s: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String[]\n */\n function removeInvalidParentheses($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function removeInvalidParentheses(s: string): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (remove-invalid-parentheses s)\n (-> string? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0301](https://leetcode-cn.com/problems/remove-invalid-parentheses)", "[\u5220\u9664\u65e0\u6548\u7684\u62ec\u53f7](/solution/0300-0399/0301.Remove%20Invalid%20Parentheses/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[0301](https://leetcode.com/problems/remove-invalid-parentheses)", "[Remove Invalid Parentheses](/solution/0300-0399/0301.Remove%20Invalid%20Parentheses/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`", "Hard", ""]}, {"question_id": "0300", "frontend_question_id": "0300", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-increasing-subsequence", "url_en": "https://leetcode.com/problems/longest-increasing-subsequence", "relative_path_cn": "/solution/0300-0399/0300.Longest%20Increasing%20Subsequence/README.md", "relative_path_en": "/solution/0300-0399/0300.Longest%20Increasing%20Subsequence/README_EN.md", "title_cn": "\u6700\u957f\u9012\u589e\u5b50\u5e8f\u5217", "title_en": "Longest Increasing Subsequence", "question_title_slug": "longest-increasing-subsequence", "content_en": "

    Given an integer array nums, return the length of the longest strictly increasing subsequence.

    \n\n

    A subsequence is a sequence that can be derived from an array by deleting some or no elements without changing the order of the remaining elements. For example, [3,6,2,7] is a subsequence of the array [0,3,1,6,2,2,7].

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [10,9,2,5,3,7,101,18]\nOutput: 4\nExplanation: The longest increasing subsequence is [2,3,7,101], therefore the length is 4.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [0,1,0,3,2,3]\nOutput: 4\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [7,7,7,7,7,7,7]\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 2500
    • \n\t
    • -104 <= nums[i] <= 104
    • \n
    \n\n

     

    \n

    Follow up: Can you come up with an algorithm that runs in O(n log(n)) time complexity?

    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \uff0c\u627e\u5230\u5176\u4e2d\u6700\u957f\u4e25\u683c\u9012\u589e\u5b50\u5e8f\u5217\u7684\u957f\u5ea6\u3002

    \n\n

    \u5b50\u5e8f\u5217\u662f\u7531\u6570\u7ec4\u6d3e\u751f\u800c\u6765\u7684\u5e8f\u5217\uff0c\u5220\u9664\uff08\u6216\u4e0d\u5220\u9664\uff09\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u800c\u4e0d\u6539\u53d8\u5176\u4f59\u5143\u7d20\u7684\u987a\u5e8f\u3002\u4f8b\u5982\uff0c[3,6,2,7] \u662f\u6570\u7ec4 [0,3,1,6,2,2,7] \u7684\u5b50\u5e8f\u5217\u3002

    \n\u00a0\n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [10,9,2,5,3,7,101,18]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u6700\u957f\u9012\u589e\u5b50\u5e8f\u5217\u662f [2,3,7,101]\uff0c\u56e0\u6b64\u957f\u5ea6\u4e3a 4 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [0,1,0,3,2,3]\n\u8f93\u51fa\uff1a4\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [7,7,7,7,7,7,7]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 2500
    • \n\t
    • -104 <= nums[i] <= 104
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u4f60\u53ef\u4ee5\u8bbe\u8ba1\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n2) \u7684\u89e3\u51b3\u65b9\u6848\u5417\uff1f
    • \n\t
    • \u4f60\u80fd\u5c06\u7b97\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u964d\u4f4e\u5230\u00a0O(n log(n)) \u5417?
    • \n
    \n", "tags_en": ["Binary Search", "Dynamic Programming"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int lengthOfLIS(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int lengthOfLIS(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def lengthOfLIS(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def lengthOfLIS(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint lengthOfLIS(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LengthOfLIS(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar lengthOfLIS = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef length_of_lis(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func lengthOfLIS(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func lengthOfLIS(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def lengthOfLIS(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun lengthOfLIS(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn length_of_lis(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function lengthOfLIS($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function lengthOfLIS(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (length-of-lis nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0300](https://leetcode-cn.com/problems/longest-increasing-subsequence)", "[\u6700\u957f\u9012\u589e\u5b50\u5e8f\u5217](/solution/0300-0399/0300.Longest%20Increasing%20Subsequence/README.md)", "`\u4e8c\u5206\u67e5\u627e`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0300](https://leetcode.com/problems/longest-increasing-subsequence)", "[Longest Increasing Subsequence](/solution/0300-0399/0300.Longest%20Increasing%20Subsequence/README_EN.md)", "`Binary Search`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0299", "frontend_question_id": "0299", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/bulls-and-cows", "url_en": "https://leetcode.com/problems/bulls-and-cows", "relative_path_cn": "/solution/0200-0299/0299.Bulls%20and%20Cows/README.md", "relative_path_en": "/solution/0200-0299/0299.Bulls%20and%20Cows/README_EN.md", "title_cn": "\u731c\u6570\u5b57\u6e38\u620f", "title_en": "Bulls and Cows", "question_title_slug": "bulls-and-cows", "content_en": "

    You are playing the Bulls and Cows game with your friend.

    \n\n

    You write down a secret number and ask your friend to guess what the number is. When your friend makes a guess, you provide a hint with the following info:

    \n\n
      \n\t
    • The number of "bulls", which are digits in the guess that are in the correct position.
    • \n\t
    • The number of "cows", which are digits in the guess that are in your secret number but are located in the wrong position. Specifically, the non-bull digits in the guess that could be rearranged such that they become bulls.
    • \n
    \n\n

    Given the secret number secret and your friend's guess guess, return the hint for your friend's guess.

    \n\n

    The hint should be formatted as "xAyB", where x is the number of bulls and y is the number of cows. Note that both secret and guess may contain duplicate digits.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: secret = "1807", guess = "7810"\nOutput: "1A3B"\nExplanation: Bulls are connected with a '|' and cows are underlined:\n"1807"\n  |\n"7810"
    \n\n

    Example 2:

    \n\n
    \nInput: secret = "1123", guess = "0111"\nOutput: "1A1B"\nExplanation: Bulls are connected with a '|' and cows are underlined:\n"1123"        "1123"\n  |      or     |\n"0111"        "0111"\nNote that only one of the two unmatched 1s is counted as a cow since the non-bull digits can only be rearranged to allow one 1 to be a bull.\n
    \n\n

    Example 3:

    \n\n
    \nInput: secret = "1", guess = "0"\nOutput: "0A0B"\n
    \n\n

    Example 4:

    \n\n
    \nInput: secret = "1", guess = "1"\nOutput: "1A0B"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= secret.length, guess.length <= 1000
    • \n\t
    • secret.length == guess.length
    • \n\t
    • secret and guess consist of digits only.
    • \n
    \n", "content_cn": "

    \u4f60\u5728\u548c\u670b\u53cb\u4e00\u8d77\u73a9 \u731c\u6570\u5b57\uff08Bulls and Cows\uff09\u6e38\u620f\uff0c\u8be5\u6e38\u620f\u89c4\u5219\u5982\u4e0b\uff1a

    \n\n
      \n\t
    1. \u4f60\u5199\u51fa\u4e00\u4e2a\u79d8\u5bc6\u6570\u5b57\uff0c\u5e76\u8bf7\u670b\u53cb\u731c\u8fd9\u4e2a\u6570\u5b57\u662f\u591a\u5c11\u3002
    2. \n\t
    3. \u670b\u53cb\u6bcf\u731c\u6d4b\u4e00\u6b21\uff0c\u4f60\u5c31\u4f1a\u7ed9\u4ed6\u4e00\u4e2a\u63d0\u793a\uff0c\u544a\u8bc9\u4ed6\u7684\u731c\u6d4b\u6570\u5b57\u4e2d\u6709\u591a\u5c11\u4f4d\u5c5e\u4e8e\u6570\u5b57\u548c\u786e\u5207\u4f4d\u7f6e\u90fd\u731c\u5bf9\u4e86\uff08\u79f0\u4e3a“Bulls”, \u516c\u725b\uff09\uff0c\u6709\u591a\u5c11\u4f4d\u5c5e\u4e8e\u6570\u5b57\u731c\u5bf9\u4e86\u4f46\u662f\u4f4d\u7f6e\u4e0d\u5bf9\uff08\u79f0\u4e3a“Cows”, \u5976\u725b\uff09\u3002
    4. \n\t
    5. \u670b\u53cb\u6839\u636e\u63d0\u793a\u7ee7\u7eed\u731c\uff0c\u76f4\u5230\u731c\u51fa\u79d8\u5bc6\u6570\u5b57\u3002
    6. \n
    \n\n

    \u8bf7\u5199\u51fa\u4e00\u4e2a\u6839\u636e\u79d8\u5bc6\u6570\u5b57\u548c\u670b\u53cb\u7684\u731c\u6d4b\u6570\u8fd4\u56de\u63d0\u793a\u7684\u51fd\u6570\uff0c\u8fd4\u56de\u5b57\u7b26\u4e32\u7684\u683c\u5f0f\u4e3a xAyB \uff0cx \u548c y \u90fd\u662f\u6570\u5b57\uff0cA \u8868\u793a\u516c\u725b\uff0c\u7528 B \u8868\u793a\u5976\u725b\u3002

    \n\n
      \n\t
    • xA \u8868\u793a\u6709 x \u4f4d\u6570\u5b57\u51fa\u73b0\u5728\u79d8\u5bc6\u6570\u5b57\u4e2d\uff0c\u4e14\u4f4d\u7f6e\u90fd\u4e0e\u79d8\u5bc6\u6570\u5b57\u4e00\u81f4\u3002
    • \n\t
    • yB \u8868\u793a\u6709 y \u4f4d\u6570\u5b57\u51fa\u73b0\u5728\u79d8\u5bc6\u6570\u5b57\u4e2d\uff0c\u4f46\u4f4d\u7f6e\u4e0e\u79d8\u5bc6\u6570\u5b57\u4e0d\u4e00\u81f4\u3002
    • \n
    \n\n

    \u8bf7\u6ce8\u610f\u79d8\u5bc6\u6570\u5b57\u548c\u670b\u53cb\u7684\u731c\u6d4b\u6570\u90fd\u53ef\u80fd\u542b\u6709\u91cd\u590d\u6570\u5b57\uff0c\u6bcf\u4f4d\u6570\u5b57\u53ea\u80fd\u7edf\u8ba1\u4e00\u6b21\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: secret = "1807", guess = "7810"\n\u8f93\u51fa: "1A3B"\n\u89e3\u91ca: 1 \u516c\u725b\u548c 3 \u5976\u725b\u3002\u516c\u725b\u662f 8\uff0c\u5976\u725b\u662f 0, 1 \u548c 7\u3002
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: secret = "1123", guess = "0111"\n\u8f93\u51fa: "1A1B"\n\u89e3\u91ca: \u670b\u53cb\u731c\u6d4b\u6570\u4e2d\u7684\u7b2c\u4e00\u4e2a 1 \u662f\u516c\u725b\uff0c\u7b2c\u4e8c\u4e2a\u6216\u7b2c\u4e09\u4e2a 1 \u53ef\u88ab\u89c6\u4e3a\u5976\u725b\u3002
    \n\n

     

    \n\n

    \u8bf4\u660e: \u4f60\u53ef\u4ee5\u5047\u8bbe\u79d8\u5bc6\u6570\u5b57\u548c\u670b\u53cb\u7684\u731c\u6d4b\u6570\u90fd\u53ea\u5305\u542b\u6570\u5b57\uff0c\u5e76\u4e14\u5b83\u4eec\u7684\u957f\u5ea6\u6c38\u8fdc\u76f8\u7b49\u3002

    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string getHint(string secret, string guess) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String getHint(String secret, String guess) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getHint(self, secret, guess):\n \"\"\"\n :type secret: str\n :type guess: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getHint(self, secret: str, guess: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * getHint(char * secret, char * guess){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string GetHint(string secret, string guess) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} secret\n * @param {string} guess\n * @return {string}\n */\nvar getHint = function(secret, guess) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} secret\n# @param {String} guess\n# @return {String}\ndef get_hint(secret, guess)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getHint(_ secret: String, _ guess: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getHint(secret string, guess string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getHint(secret: String, guess: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getHint(secret: String, guess: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_hint(secret: String, guess: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $secret\n * @param String $guess\n * @return String\n */\n function getHint($secret, $guess) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getHint(secret: string, guess: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-hint secret guess)\n (-> string? string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0299](https://leetcode-cn.com/problems/bulls-and-cows)", "[\u731c\u6570\u5b57\u6e38\u620f](/solution/0200-0299/0299.Bulls%20and%20Cows/README.md)", "`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0299](https://leetcode.com/problems/bulls-and-cows)", "[Bulls and Cows](/solution/0200-0299/0299.Bulls%20and%20Cows/README_EN.md)", "`Hash Table`", "Medium", ""]}, {"question_id": "0298", "frontend_question_id": "0298", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/binary-tree-longest-consecutive-sequence", "url_en": "https://leetcode.com/problems/binary-tree-longest-consecutive-sequence", "relative_path_cn": "/solution/0200-0299/0298.Binary%20Tree%20Longest%20Consecutive%20Sequence/README.md", "relative_path_en": "/solution/0200-0299/0298.Binary%20Tree%20Longest%20Consecutive%20Sequence/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u6700\u957f\u8fde\u7eed\u5e8f\u5217", "title_en": "Binary Tree Longest Consecutive Sequence", "question_title_slug": "binary-tree-longest-consecutive-sequence", "content_en": "

    Given the root of a binary tree, return the length of the longest consecutive sequence path.

    \n\n

    The path refers to any sequence of nodes from some starting node to any node in the tree along the parent-child connections. The longest consecutive path needs to be from parent to child (cannot be the reverse).

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,null,3,2,4,null,null,null,5]\nOutput: 3\nExplanation: Longest consecutive sequence path is 3-4-5, so return 3.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [2,null,3,2,null,1]\nOutput: 2\nExplanation: Longest consecutive sequence path is 2-3, not 3-2-1, so return 2.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 3 * 104].
    • \n\t
    • -3 * 104 <= Node.val <= 3 * 104
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u68f5\u6307\u5b9a\u7684\u4e8c\u53c9\u6811\uff0c\u8bf7\u4f60\u8ba1\u7b97\u5b83\u6700\u957f\u8fde\u7eed\u5e8f\u5217\u8def\u5f84\u7684\u957f\u5ea6\u3002

    \n\n

    \u8be5\u8def\u5f84\uff0c\u53ef\u4ee5\u662f\u4ece\u67d0\u4e2a\u521d\u59cb\u7ed3\u70b9\u5230\u6811\u4e2d\u4efb\u610f\u7ed3\u70b9\uff0c\u901a\u8fc7\u300c\u7236 - \u5b50\u300d\u5173\u7cfb\u8fde\u63a5\u800c\u4ea7\u751f\u7684\u4efb\u610f\u8def\u5f84\u3002

    \n\n

    \u8fd9\u4e2a\u6700\u957f\u8fde\u7eed\u7684\u8def\u5f84\uff0c\u5fc5\u987b\u4ece\u7236\u7ed3\u70b9\u5230\u5b50\u7ed3\u70b9\uff0c\u53cd\u8fc7\u6765\u662f\u4e0d\u53ef\u4ee5\u7684\u3002

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165:\n\n   1\n    \\\n     3\n    / \\\n   2   4\n        \\\n         5\n\n\u8f93\u51fa: 3\n\n\u89e3\u6790: \u5f53\u4e2d\uff0c\u6700\u957f\u8fde\u7eed\u5e8f\u5217\u662f 3-4-5\uff0c\u6240\u4ee5\u8fd4\u56de\u7ed3\u679c\u4e3a 3
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165:\n\n   2\n    \\\n     3\n    / \n   2    \n  / \n 1\n\n\u8f93\u51fa: 2 \n\n\u89e3\u6790: \u5f53\u4e2d\uff0c\u6700\u957f\u8fde\u7eed\u5e8f\u5217\u662f 2-3\u3002\u6ce8\u610f\uff0c\u4e0d\u662f 3-2-1\uff0c\u6240\u4ee5\u8fd4\u56de 2\u3002
    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int longestConsecutive(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int longestConsecutive(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def longestConsecutive(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def longestConsecutive(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint longestConsecutive(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int LongestConsecutive(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar longestConsecutive = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef longest_consecutive(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func longestConsecutive(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc longestConsecutive(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def longestConsecutive(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun longestConsecutive(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn longest_consecutive(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function longestConsecutive($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction longestConsecutive(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (longest-consecutive root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0298](https://leetcode-cn.com/problems/binary-tree-longest-consecutive-sequence)", "[\u4e8c\u53c9\u6811\u6700\u957f\u8fde\u7eed\u5e8f\u5217](/solution/0200-0299/0298.Binary%20Tree%20Longest%20Consecutive%20Sequence/README.md)", "`\u6811`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0298](https://leetcode.com/problems/binary-tree-longest-consecutive-sequence)", "[Binary Tree Longest Consecutive Sequence](/solution/0200-0299/0298.Binary%20Tree%20Longest%20Consecutive%20Sequence/README_EN.md)", "`Tree`", "Medium", "\ud83d\udd12"]}, {"question_id": "0297", "frontend_question_id": "0297", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/serialize-and-deserialize-binary-tree", "url_en": "https://leetcode.com/problems/serialize-and-deserialize-binary-tree", "relative_path_cn": "/solution/0200-0299/0297.Serialize%20and%20Deserialize%20Binary%20Tree/README.md", "relative_path_en": "/solution/0200-0299/0297.Serialize%20and%20Deserialize%20Binary%20Tree/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u7684\u5e8f\u5217\u5316\u4e0e\u53cd\u5e8f\u5217\u5316", "title_en": "Serialize and Deserialize Binary Tree", "question_title_slug": "serialize-and-deserialize-binary-tree", "content_en": "

    Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be reconstructed later in the same or another computer environment.

    \n\n

    Design an algorithm to serialize and deserialize a binary tree. There is no restriction on how your serialization/deserialization algorithm should work. You just need to ensure that a binary tree can be serialized to a string and this string can be deserialized to the original tree structure.

    \n\n

    Clarification: The input/output format is the same as how LeetCode serializes a binary tree. You do not necessarily need to follow this format, so please be creative and come up with different approaches yourself.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,2,3,null,null,4,5]\nOutput: [1,2,3,null,null,4,5]\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = []\nOutput: []\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = [1]\nOutput: [1]\n
    \n\n

    Example 4:

    \n\n
    \nInput: root = [1,2]\nOutput: [1,2]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [0, 104].
    • \n\t
    • -1000 <= Node.val <= 1000
    • \n
    \n", "content_cn": "

    \u5e8f\u5217\u5316\u662f\u5c06\u4e00\u4e2a\u6570\u636e\u7ed3\u6784\u6216\u8005\u5bf9\u8c61\u8f6c\u6362\u4e3a\u8fde\u7eed\u7684\u6bd4\u7279\u4f4d\u7684\u64cd\u4f5c\uff0c\u8fdb\u800c\u53ef\u4ee5\u5c06\u8f6c\u6362\u540e\u7684\u6570\u636e\u5b58\u50a8\u5728\u4e00\u4e2a\u6587\u4ef6\u6216\u8005\u5185\u5b58\u4e2d\uff0c\u540c\u65f6\u4e5f\u53ef\u4ee5\u901a\u8fc7\u7f51\u7edc\u4f20\u8f93\u5230\u53e6\u4e00\u4e2a\u8ba1\u7b97\u673a\u73af\u5883\uff0c\u91c7\u53d6\u76f8\u53cd\u65b9\u5f0f\u91cd\u6784\u5f97\u5230\u539f\u6570\u636e\u3002

    \n\n

    \u8bf7\u8bbe\u8ba1\u4e00\u4e2a\u7b97\u6cd5\u6765\u5b9e\u73b0\u4e8c\u53c9\u6811\u7684\u5e8f\u5217\u5316\u4e0e\u53cd\u5e8f\u5217\u5316\u3002\u8fd9\u91cc\u4e0d\u9650\u5b9a\u4f60\u7684\u5e8f\u5217 / \u53cd\u5e8f\u5217\u5316\u7b97\u6cd5\u6267\u884c\u903b\u8f91\uff0c\u4f60\u53ea\u9700\u8981\u4fdd\u8bc1\u4e00\u4e2a\u4e8c\u53c9\u6811\u53ef\u4ee5\u88ab\u5e8f\u5217\u5316\u4e3a\u4e00\u4e2a\u5b57\u7b26\u4e32\u5e76\u4e14\u5c06\u8fd9\u4e2a\u5b57\u7b26\u4e32\u53cd\u5e8f\u5217\u5316\u4e3a\u539f\u59cb\u7684\u6811\u7ed3\u6784\u3002

    \n\n

    \u63d0\u793a: \u8f93\u5165\u8f93\u51fa\u683c\u5f0f\u4e0e LeetCode \u76ee\u524d\u4f7f\u7528\u7684\u65b9\u5f0f\u4e00\u81f4\uff0c\u8be6\u60c5\u8bf7\u53c2\u9605\u00a0LeetCode \u5e8f\u5217\u5316\u4e8c\u53c9\u6811\u7684\u683c\u5f0f\u3002\u4f60\u5e76\u975e\u5fc5\u987b\u91c7\u53d6\u8fd9\u79cd\u65b9\u5f0f\uff0c\u4f60\u4e5f\u53ef\u4ee5\u91c7\u7528\u5176\u4ed6\u7684\u65b9\u6cd5\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [1,2,3,null,null,4,5]\n\u8f93\u51fa\uff1a[1,2,3,null,null,4,5]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = []\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [1]\n\u8f93\u51fa\uff1a[1]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [1,2]\n\u8f93\u51fa\uff1a[1,2]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u7ed3\u70b9\u6570\u5728\u8303\u56f4 [0, 104] \u5185
    • \n\t
    • -1000 <= Node.val <= 1000
    • \n
    \n", "tags_en": ["Tree", "Design"], "tags_cn": ["\u6811", "\u8bbe\u8ba1"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"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 */\nclass Codec {\npublic:\n\n // Encodes a tree to a single string.\n string serialize(TreeNode* root) {\n \n }\n\n // Decodes your encoded data to tree.\n TreeNode* deserialize(string data) {\n \n }\n};\n\n// Your Codec object will be instantiated and called as such:\n// Codec ser, deser;\n// TreeNode* ans = deser.deserialize(ser.serialize(root));", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode(int x) { val = x; }\n * }\n */\npublic class Codec {\n\n // Encodes a tree to a single string.\n public String serialize(TreeNode root) {\n \n }\n\n // Decodes your encoded data to tree.\n public TreeNode deserialize(String data) {\n \n }\n}\n\n// Your Codec object will be instantiated and called as such:\n// Codec ser = new Codec();\n// Codec deser = new Codec();\n// TreeNode ans = deser.deserialize(ser.serialize(root));", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Codec:\n\n def serialize(self, root):\n \"\"\"Encodes a tree to a single string.\n \n :type root: TreeNode\n :rtype: str\n \"\"\"\n \n\n def deserialize(self, data):\n \"\"\"Decodes your encoded data to tree.\n \n :type data: str\n :rtype: TreeNode\n \"\"\"\n \n\n# Your Codec object will be instantiated and called as such:\n# ser = Codec()\n# deser = Codec()\n# ans = deser.deserialize(ser.serialize(root))", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Codec:\n\n def serialize(self, root):\n \"\"\"Encodes a tree to a single string.\n \n :type root: TreeNode\n :rtype: str\n \"\"\"\n \n\n def deserialize(self, data):\n \"\"\"Decodes your encoded data to tree.\n \n :type data: str\n :rtype: TreeNode\n \"\"\"\n \n\n# Your Codec object will be instantiated and called as such:\n# ser = Codec()\n# deser = Codec()\n# ans = deser.deserialize(ser.serialize(root))", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n/** Encodes a tree to a single string. */\nchar* serialize(struct TreeNode* root) {\n \n}\n\n/** Decodes your encoded data to tree. */\nstruct TreeNode* deserialize(char* data) {\n \n}\n\n// Your functions will be called as such:\n// char* data = serialize(root);\n// deserialize(data);", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int x) { val = x; }\n * }\n */\npublic class Codec {\n\n // Encodes a tree to a single string.\n public string serialize(TreeNode root) {\n \n }\n\n // Decodes your encoded data to tree.\n public TreeNode deserialize(string data) {\n \n }\n}\n\n// Your Codec object will be instantiated and called as such:\n// Codec ser = new Codec();\n// Codec deser = new Codec();\n// TreeNode ans = deser.deserialize(ser.serialize(root));", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val) {\n * this.val = val;\n * this.left = this.right = null;\n * }\n */\n\n/**\n * Encodes a tree to a single string.\n *\n * @param {TreeNode} root\n * @return {string}\n */\nvar serialize = function(root) {\n \n};\n\n/**\n * Decodes your encoded data to tree.\n *\n * @param {string} data\n * @return {TreeNode}\n */\nvar deserialize = function(data) {\n \n};\n\n/**\n * Your functions will be called as such:\n * deserialize(serialize(root));\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val)\n# @val = val\n# @left, @right = nil, nil\n# end\n# end\n\n# Encodes a tree to a single string.\n#\n# @param {TreeNode} root\n# @return {string}\ndef serialize(root)\n \nend\n\n# Decodes your encoded data to tree.\n#\n# @param {string} data\n# @return {TreeNode}\ndef deserialize(data)\n \nend\n\n\n# Your functions will be called as such:\n# deserialize(serialize(data))", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.left = nil\n * self.right = nil\n * }\n * }\n */\n\nclass Codec {\n func serialize(_ root: TreeNode?) -> String {\n \n }\n \n func deserialize(_ data: String) -> TreeNode? {\n \n }\n}\n\n// Your Codec object will be instantiated and called as such:\n// var ser = Codec()\n// var deser = Codec()\n// deser.deserialize(ser.serialize(root))", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\n\ntype Codec struct {\n \n}\n\nfunc Constructor() Codec {\n \n}\n\n// Serializes a tree to a single string.\nfunc (this *Codec) serialize(root *TreeNode) string {\n \n}\n\n// Deserializes your encoded data to tree.\nfunc (this *Codec) deserialize(data string) *TreeNode { \n \n}\n\n\n/**\n * Your Codec object will be instantiated and called as such:\n * ser := Constructor();\n * deser := Constructor();\n * data := ser.serialize(root);\n * ans := deser.deserialize(data);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(var _value: Int) {\n * var value: Int = _value\n * var left: TreeNode = null\n * var right: TreeNode = null\n * }\n */\n\nclass Codec {\n // Encodes a list of strings to a single string.\n def serialize(root: TreeNode): String = {\n \n }\n \n // Decodes a single string to a list of strings.\n def deserialize(data: String): TreeNode = {\n \n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * var ser = new Codec()\n * var deser = new Codec()\n * val s = ser.serialize(root)\n * val ans = deser.deserialize(s)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\n\nclass Codec() {\n\t// Encodes a URL to a shortened URL.\n fun serialize(root: TreeNode?): String {\n \n }\n\n // Decodes your encoded data to tree.\n fun deserialize(data: String): TreeNode? {\n \n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * var ser = Codec()\n * var deser = Codec()\n * var data = ser.serialize(longUrl)\n * var ans = deser.deserialize(data)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n// \n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nstruct Codec {\n\t\n}\n\n/** \n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl Codec {\n fn new() -> Self {\n \n }\n\n fn serialize(&self, root: Option>>) -> String {\n \n }\n\t\n fn deserialize(&self, data: String) -> Option>> {\n \n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * let obj = Codec::new();\n * let data: String = obj.serialize(strs);\n * let ans: Option>> = obj.deserialize(data);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($value) { $this->val = $value; }\n * }\n */\n\nclass Codec {\n function __construct() {\n \n }\n \n /**\n * @param TreeNode $root\n * @return String\n */\n function serialize($root) {\n \n }\n \n /**\n * @param String $data\n * @return TreeNode\n */\n function deserialize($data) {\n \n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * $ser = Codec();\n * $deser = Codec();\n * $data = $ser->serialize($root);\n * $ans = $deser->deserialize($data);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\n/*\n * Encodes a tree to a single string.\n */\nfunction serialize(root: TreeNode | null): string {\n\n};\n\n/*\n * Decodes your encoded data to tree.\n */\nfunction deserialize(data: string): TreeNode | null {\n\n};\n\n\n/**\n * Your functions will be called as such:\n * deserialize(serialize(root));\n */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0297](https://leetcode-cn.com/problems/serialize-and-deserialize-binary-tree)", "[\u4e8c\u53c9\u6811\u7684\u5e8f\u5217\u5316\u4e0e\u53cd\u5e8f\u5217\u5316](/solution/0200-0299/0297.Serialize%20and%20Deserialize%20Binary%20Tree/README.md)", "`\u6811`,`\u8bbe\u8ba1`", "\u56f0\u96be", ""], "md_table_row_en": ["[0297](https://leetcode.com/problems/serialize-and-deserialize-binary-tree)", "[Serialize and Deserialize Binary Tree](/solution/0200-0299/0297.Serialize%20and%20Deserialize%20Binary%20Tree/README_EN.md)", "`Tree`,`Design`", "Hard", ""]}, {"question_id": "0296", "frontend_question_id": "0296", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/best-meeting-point", "url_en": "https://leetcode.com/problems/best-meeting-point", "relative_path_cn": "/solution/0200-0299/0296.Best%20Meeting%20Point/README.md", "relative_path_en": "/solution/0200-0299/0296.Best%20Meeting%20Point/README_EN.md", "title_cn": "\u6700\u4f73\u7684\u78b0\u5934\u5730\u70b9", "title_en": "Best Meeting Point", "question_title_slug": "best-meeting-point", "content_en": "

    Given an m x n binary grid grid where each 1 marks the home of one friend, return the minimal total travel distance.

    \n\n

    The total travel distance is the sum of the distances between the houses of the friends and the meeting point.

    \n\n

    The distance is calculated using Manhattan Distance, where distance(p1, p2) = |p2.x - p1.x| + |p2.y - p1.y|.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: grid = [[1,0,0,0,1],[0,0,0,0,0],[0,0,1,0,0]]\nOutput: 6\nExplanation: Given three friends living at (0,0), (0,4), and (2,2).\nThe point (0,2) is an ideal meeting point, as the total travel distance of 2 + 2 + 2 = 6 is minimal.\nSo return 6.\n
    \n\n

    Example 2:

    \n\n
    \nInput: grid = [[1,1]]\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= m, n <= 200
    • \n\t
    • grid[i][j] is either 0 or 1.
    • \n\t
    • There will be at least two friends in the grid.
    • \n
    \n", "content_cn": "

    \u6709\u4e00\u961f\u4eba\uff08\u4e24\u4eba\u6216\u4ee5\u4e0a\uff09\u60f3\u8981\u5728\u4e00\u4e2a\u5730\u65b9\u78b0\u9762\uff0c\u4ed6\u4eec\u5e0c\u671b\u80fd\u591f\u6700\u5c0f\u5316\u4ed6\u4eec\u7684\u603b\u884c\u8d70\u8ddd\u79bb\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a 2D \u7f51\u683c\uff0c\u5176\u4e2d\u5404\u4e2a\u683c\u5b50\u5185\u7684\u503c\u8981\u4e48\u662f 0\uff0c\u8981\u4e48\u662f 1\u3002

    \n\n

    1 \u8868\u793a\u67d0\u4e2a\u4eba\u7684\u5bb6\u6240\u5904\u7684\u4f4d\u7f6e\u3002\u8fd9\u91cc\uff0c\u6211\u4eec\u5c06\u4f7f\u7528 \u66fc\u54c8\u987f\u8ddd\u79bb \u6765\u8ba1\u7b97\uff0c\u5176\u4e2d distance(p1, p2) = |p2.x - p1.x| + |p2.y - p1.y|\u3002

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165: \n\n1 - 0 - 0 - 0 - 1\n|   |   |   |   |\n0 - 0 - 0 - 0 - 0\n|   |   |   |   |\n0 - 0 - 1 - 0 - 0\n\n\u8f93\u51fa: 6 \n\n\u89e3\u6790: \u7ed9\u5b9a\u7684\u4e09\u4e2a\u4eba\u5206\u522b\u4f4f\u5728(0,0)\uff0c(0,4) \u548c (2,2):\n     (0,2) \u662f\u4e00\u4e2a\u6700\u4f73\u7684\u78b0\u9762\u70b9\uff0c\u5176\u603b\u884c\u8d70\u8ddd\u79bb\u4e3a 2 + 2 + 2 = 6\uff0c\u6700\u5c0f\uff0c\u56e0\u6b64\u8fd4\u56de 6\u3002
    \n", "tags_en": ["Sort", "Math"], "tags_cn": ["\u6392\u5e8f", "\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minTotalDistance(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minTotalDistance(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minTotalDistance(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minTotalDistance(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minTotalDistance(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinTotalDistance(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar minTotalDistance = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef min_total_distance(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minTotalDistance(_ grid: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minTotalDistance(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minTotalDistance(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minTotalDistance(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_total_distance(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function minTotalDistance($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minTotalDistance(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-total-distance grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0296](https://leetcode-cn.com/problems/best-meeting-point)", "[\u6700\u4f73\u7684\u78b0\u5934\u5730\u70b9](/solution/0200-0299/0296.Best%20Meeting%20Point/README.md)", "`\u6392\u5e8f`,`\u6570\u5b66`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0296](https://leetcode.com/problems/best-meeting-point)", "[Best Meeting Point](/solution/0200-0299/0296.Best%20Meeting%20Point/README_EN.md)", "`Sort`,`Math`", "Hard", "\ud83d\udd12"]}, {"question_id": "0295", "frontend_question_id": "0295", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-median-from-data-stream", "url_en": "https://leetcode.com/problems/find-median-from-data-stream", "relative_path_cn": "/solution/0200-0299/0295.Find%20Median%20from%20Data%20Stream/README.md", "relative_path_en": "/solution/0200-0299/0295.Find%20Median%20from%20Data%20Stream/README_EN.md", "title_cn": "\u6570\u636e\u6d41\u7684\u4e2d\u4f4d\u6570", "title_en": "Find Median from Data Stream", "question_title_slug": "find-median-from-data-stream", "content_en": "

    The median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value and the median is the mean of the two middle values.

    \n\n
      \n\t
    • For example, for arr = [2,3,4], the median is 3.
    • \n\t
    • For example, for arr = [2,3], the median is (2 + 3) / 2 = 2.5.
    • \n
    \n\n

    Implement the MedianFinder class:

    \n\n
      \n\t
    • MedianFinder() initializes the MedianFinder object.
    • \n\t
    • void addNum(int num) adds the integer num from the data stream to the data structure.
    • \n\t
    • double findMedian() returns the median of all elements so far. Answers within 10-5 of the actual answer will be accepted.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["MedianFinder", "addNum", "addNum", "findMedian", "addNum", "findMedian"]\n[[], [1], [2], [], [3], []]\nOutput\n[null, null, null, 1.5, null, 2.0]\n\nExplanation\nMedianFinder medianFinder = new MedianFinder();\nmedianFinder.addNum(1);    // arr = [1]\nmedianFinder.addNum(2);    // arr = [1, 2]\nmedianFinder.findMedian(); // return 1.5 (i.e., (1 + 2) / 2)\nmedianFinder.addNum(3);    // arr[1, 2, 3]\nmedianFinder.findMedian(); // return 2.0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • -105 <= num <= 105
    • \n\t
    • There will be at least one element in the data structure before calling findMedian.
    • \n\t
    • At most 5 * 104 calls will be made to addNum and findMedian.
    • \n
    \n\n

     

    \n

    Follow up:

    \n\n
      \n\t
    • If all integer numbers from the stream are in the range [0, 100], how would you optimize your solution?
    • \n\t
    • If 99% of all integer numbers from the stream are in the range [0, 100], how would you optimize your solution?
    • \n
    \n", "content_cn": "

    \u4e2d\u4f4d\u6570\u662f\u6709\u5e8f\u5217\u8868\u4e2d\u95f4\u7684\u6570\u3002\u5982\u679c\u5217\u8868\u957f\u5ea6\u662f\u5076\u6570\uff0c\u4e2d\u4f4d\u6570\u5219\u662f\u4e2d\u95f4\u4e24\u4e2a\u6570\u7684\u5e73\u5747\u503c\u3002

    \n\n

    \u4f8b\u5982\uff0c

    \n\n

    [2,3,4] \u7684\u4e2d\u4f4d\u6570\u662f 3

    \n\n

    [2,3] \u7684\u4e2d\u4f4d\u6570\u662f (2 + 3) / 2 = 2.5

    \n\n

    \u8bbe\u8ba1\u4e00\u4e2a\u652f\u6301\u4ee5\u4e0b\u4e24\u79cd\u64cd\u4f5c\u7684\u6570\u636e\u7ed3\u6784\uff1a

    \n\n
      \n\t
    • void addNum(int num) - \u4ece\u6570\u636e\u6d41\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u6574\u6570\u5230\u6570\u636e\u7ed3\u6784\u4e2d\u3002
    • \n\t
    • double findMedian() - \u8fd4\u56de\u76ee\u524d\u6240\u6709\u5143\u7d20\u7684\u4e2d\u4f4d\u6570\u3002
    • \n
    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    addNum(1)\naddNum(2)\nfindMedian() -> 1.5\naddNum(3) \nfindMedian() -> 2
    \n\n

    \u8fdb\u9636:

    \n\n
      \n\t
    1. \u5982\u679c\u6570\u636e\u6d41\u4e2d\u6240\u6709\u6574\u6570\u90fd\u5728 0 \u5230 100 \u8303\u56f4\u5185\uff0c\u4f60\u5c06\u5982\u4f55\u4f18\u5316\u4f60\u7684\u7b97\u6cd5\uff1f
    2. \n\t
    3. \u5982\u679c\u6570\u636e\u6d41\u4e2d 99% \u7684\u6574\u6570\u90fd\u5728 0 \u5230 100 \u8303\u56f4\u5185\uff0c\u4f60\u5c06\u5982\u4f55\u4f18\u5316\u4f60\u7684\u7b97\u6cd5\uff1f
    4. \n
    \n", "tags_en": ["Heap", "Design"], "tags_cn": ["\u5806", "\u8bbe\u8ba1"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class MedianFinder {\npublic:\n /** initialize your data structure here. */\n MedianFinder() {\n\n }\n \n void addNum(int num) {\n\n }\n \n double findMedian() {\n\n }\n};\n\n/**\n * Your MedianFinder object will be instantiated and called as such:\n * MedianFinder* obj = new MedianFinder();\n * obj->addNum(num);\n * double param_2 = obj->findMedian();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class MedianFinder {\n\n /** initialize your data structure here. */\n public MedianFinder() {\n\n }\n \n public void addNum(int num) {\n\n }\n \n public double findMedian() {\n\n }\n}\n\n/**\n * Your MedianFinder object will be instantiated and called as such:\n * MedianFinder obj = new MedianFinder();\n * obj.addNum(num);\n * double param_2 = obj.findMedian();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class MedianFinder(object):\n\n def __init__(self):\n \"\"\"\n initialize your data structure here.\n \"\"\"\n\n\n def addNum(self, num):\n \"\"\"\n :type num: int\n :rtype: None\n \"\"\"\n\n\n def findMedian(self):\n \"\"\"\n :rtype: float\n \"\"\"\n\n\n\n# Your MedianFinder object will be instantiated and called as such:\n# obj = MedianFinder()\n# obj.addNum(num)\n# param_2 = obj.findMedian()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class MedianFinder:\n\n def __init__(self):\n \"\"\"\n initialize your data structure here.\n \"\"\"\n\n\n def addNum(self, num: int) -> None:\n\n\n def findMedian(self) -> float:\n\n\n\n# Your MedianFinder object will be instantiated and called as such:\n# obj = MedianFinder()\n# obj.addNum(num)\n# param_2 = obj.findMedian()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} MedianFinder;\n\n/** initialize your data structure here. */\n\nMedianFinder* medianFinderCreate() {\n\n}\n\nvoid medianFinderAddNum(MedianFinder* obj, int num) {\n\n}\n\ndouble medianFinderFindMedian(MedianFinder* obj) {\n\n}\n\nvoid medianFinderFree(MedianFinder* obj) {\n\n}\n\n/**\n * Your MedianFinder struct will be instantiated and called as such:\n * MedianFinder* obj = medianFinderCreate();\n * medianFinderAddNum(obj, num);\n \n * double param_2 = medianFinderFindMedian(obj);\n \n * medianFinderFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class MedianFinder {\n\n /** initialize your data structure here. */\n public MedianFinder() {\n\n }\n \n public void AddNum(int num) {\n\n }\n \n public double FindMedian() {\n\n }\n}\n\n/**\n * Your MedianFinder object will be instantiated and called as such:\n * MedianFinder obj = new MedianFinder();\n * obj.AddNum(num);\n * double param_2 = obj.FindMedian();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * initialize your data structure here.\n */\nvar MedianFinder = function() {\n\n};\n\n/** \n * @param {number} num\n * @return {void}\n */\nMedianFinder.prototype.addNum = function(num) {\n\n};\n\n/**\n * @return {number}\n */\nMedianFinder.prototype.findMedian = function() {\n\n};\n\n/**\n * Your MedianFinder object will be instantiated and called as such:\n * var obj = new MedianFinder()\n * obj.addNum(num)\n * var param_2 = obj.findMedian()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class MedianFinder\n\n=begin\n initialize your data structure here.\n=end\n def initialize()\n\n end\n\n\n=begin\n :type num: Integer\n :rtype: Void\n=end\n def add_num(num)\n\n end\n\n\n=begin\n :rtype: Float\n=end\n def find_median()\n\n end\n\n\nend\n\n# Your MedianFinder object will be instantiated and called as such:\n# obj = MedianFinder.new()\n# obj.add_num(num)\n# param_2 = obj.find_median()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass MedianFinder {\n\n /** initialize your data structure here. */\n init() {\n\n }\n \n func addNum(_ num: Int) {\n\n }\n \n func findMedian() -> Double {\n\n }\n}\n\n/**\n * Your MedianFinder object will be instantiated and called as such:\n * let obj = MedianFinder()\n * obj.addNum(num)\n * let ret_2: Double = obj.findMedian()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type MedianFinder struct {\n\n}\n\n\n/** initialize your data structure here. */\nfunc Constructor() MedianFinder {\n\n}\n\n\nfunc (this *MedianFinder) AddNum(num int) {\n\n}\n\n\nfunc (this *MedianFinder) FindMedian() float64 {\n\n}\n\n\n/**\n * Your MedianFinder object will be instantiated and called as such:\n * obj := Constructor();\n * obj.AddNum(num);\n * param_2 := obj.FindMedian();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class MedianFinder() {\n\n /** initialize your data structure here. */\n\n\n def addNum(num: Int) {\n\n }\n\n def findMedian(): Double = {\n\n }\n\n}\n\n/**\n * Your MedianFinder object will be instantiated and called as such:\n * var obj = new MedianFinder()\n * obj.addNum(num)\n * var param_2 = obj.findMedian()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class MedianFinder() {\n\n /** initialize your data structure here. */\n\n\n fun addNum(num: Int) {\n\n }\n\n fun findMedian(): Double {\n\n }\n\n}\n\n/**\n * Your MedianFinder object will be instantiated and called as such:\n * var obj = MedianFinder()\n * obj.addNum(num)\n * var param_2 = obj.findMedian()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct MedianFinder {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl MedianFinder {\n\n /** initialize your data structure here. */\n fn new() -> Self {\n\n }\n \n fn add_num(&self, num: i32) {\n\n }\n \n fn find_median(&self) -> f64 {\n\n }\n}\n\n/**\n * Your MedianFinder object will be instantiated and called as such:\n * let obj = MedianFinder::new();\n * obj.add_num(num);\n * let ret_2: f64 = obj.find_median();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class MedianFinder {\n /**\n * initialize your data structure here.\n */\n function __construct() {\n\n }\n\n /**\n * @param Integer $num\n * @return NULL\n */\n function addNum($num) {\n\n }\n\n /**\n * @return Float\n */\n function findMedian() {\n\n }\n}\n\n/**\n * Your MedianFinder object will be instantiated and called as such:\n * $obj = MedianFinder();\n * $obj->addNum($num);\n * $ret_2 = $obj->findMedian();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class MedianFinder {\n constructor() {\n\n }\n\n addNum(num: number): void {\n\n }\n\n findMedian(): number {\n\n }\n}\n\n/**\n * Your MedianFinder object will be instantiated and called as such:\n * var obj = new MedianFinder()\n * obj.addNum(num)\n * var param_2 = obj.findMedian()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define median-finder%\n (class object%\n (super-new)\n (init-field)\n \n ; add-num : exact-integer? -> void?\n (define/public (add-num num)\n\n )\n ; find-median : -> flonum?\n (define/public (find-median)\n\n )))\n\n;; Your median-finder% object will be instantiated and called as such:\n;; (define obj (new median-finder%))\n;; (send obj add-num num)\n;; (define param_2 (send obj find-median))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0295](https://leetcode-cn.com/problems/find-median-from-data-stream)", "[\u6570\u636e\u6d41\u7684\u4e2d\u4f4d\u6570](/solution/0200-0299/0295.Find%20Median%20from%20Data%20Stream/README.md)", "`\u5806`,`\u8bbe\u8ba1`", "\u56f0\u96be", ""], "md_table_row_en": ["[0295](https://leetcode.com/problems/find-median-from-data-stream)", "[Find Median from Data Stream](/solution/0200-0299/0295.Find%20Median%20from%20Data%20Stream/README_EN.md)", "`Heap`,`Design`", "Hard", ""]}, {"question_id": "0294", "frontend_question_id": "0294", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/flip-game-ii", "url_en": "https://leetcode.com/problems/flip-game-ii", "relative_path_cn": "/solution/0200-0299/0294.Flip%20Game%20II/README.md", "relative_path_en": "/solution/0200-0299/0294.Flip%20Game%20II/README_EN.md", "title_cn": "\u7ffb\u8f6c\u6e38\u620f II", "title_en": "Flip Game II", "question_title_slug": "flip-game-ii", "content_en": "

    You are playing a Flip Game with your friend.

    \n\n

    You are given a string currentState that contains only '+' and '-'. You and your friend take turns to flip two consecutive "++" into "--". The game ends when a person can no longer make a move, and therefore the other person will be the winner.

    \n\n

    Return true if the starting player can guarantee a win, and false otherwise.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: currentState = "++++"\nOutput: true\nExplanation: The starting player can guarantee a win by flipping the middle "++" to become "+--+".\n
    \n\n

    Example 2:

    \n\n
    \nInput: currentState = "+"\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= currentState.length <= 60
    • \n\t
    • currentState[i] is either '+' or '-'.
    • \n
    \n\n

     

    \nFollow up: Derive your algorithm's runtime complexity.", "content_cn": "

    \u4f60\u548c\u670b\u53cb\u73a9\u4e00\u4e2a\u53eb\u505a\u300c\u7ffb\u8f6c\u6e38\u620f\u300d\u7684\u6e38\u620f\u3002\u6e38\u620f\u89c4\u5219\u5982\u4e0b\uff1a

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 currentState \uff0c\u5176\u4e2d\u53ea\u542b '+' \u548c '-' \u3002\u4f60\u548c\u670b\u53cb\u8f6e\u6d41\u5c06\u00a0\u8fde\u7eed \u7684\u4e24\u4e2a\u00a0\"++\"\u00a0\u53cd\u8f6c\u6210\u00a0\"--\" \u3002\u5f53\u4e00\u65b9\u65e0\u6cd5\u8fdb\u884c\u6709\u6548\u7684\u7ffb\u8f6c\u65f6\u4fbf\u610f\u5473\u7740\u6e38\u620f\u7ed3\u675f\uff0c\u5219\u53e6\u4e00\u65b9\u83b7\u80dc\u3002

    \n\n

    \u8bf7\u4f60\u5199\u51fa\u4e00\u4e2a\u51fd\u6570\u6765\u5224\u5b9a\u8d77\u59cb\u73a9\u5bb6 \u662f\u5426\u5b58\u5728\u5fc5\u80dc\u7684\u65b9\u6848 \uff1a\u5982\u679c\u5b58\u5728\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\u00a0\n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1acurrentState = \"++++\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u8d77\u59cb\u73a9\u5bb6\u53ef\u5c06\u4e2d\u95f4\u7684 \"++\" \u7ffb\u8f6c\u53d8\u4e3a \"+--+\" \u4ece\u800c\u5f97\u80dc\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1acurrentState = \"+\"\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= currentState.length <= 60
    • \n\t
    • currentState[i] \u4e0d\u662f '+' \u5c31\u662f '-'
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u8bf7\u63a8\u5bfc\u4f60\u7b97\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u3002

    \n", "tags_en": ["Minimax", "Backtracking"], "tags_cn": ["\u6781\u5c0f\u5316\u6781\u5927", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canWin(string currentState) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canWin(String currentState) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canWin(self, currentState):\n \"\"\"\n :type currentState: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canWin(self, currentState: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canWin(char * currentState){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanWin(string currentState) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} currentState\n * @return {boolean}\n */\nvar canWin = function(currentState) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} current_state\n# @return {Boolean}\ndef can_win(current_state)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canWin(_ currentState: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canWin(currentState string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canWin(currentState: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canWin(currentState: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_win(current_state: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $currentState\n * @return Boolean\n */\n function canWin($currentState) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canWin(currentState: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-win currentState)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0294](https://leetcode-cn.com/problems/flip-game-ii)", "[\u7ffb\u8f6c\u6e38\u620f II](/solution/0200-0299/0294.Flip%20Game%20II/README.md)", "`\u6781\u5c0f\u5316\u6781\u5927`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0294](https://leetcode.com/problems/flip-game-ii)", "[Flip Game II](/solution/0200-0299/0294.Flip%20Game%20II/README_EN.md)", "`Minimax`,`Backtracking`", "Medium", "\ud83d\udd12"]}, {"question_id": "0293", "frontend_question_id": "0293", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/flip-game", "url_en": "https://leetcode.com/problems/flip-game", "relative_path_cn": "/solution/0200-0299/0293.Flip%20Game/README.md", "relative_path_en": "/solution/0200-0299/0293.Flip%20Game/README_EN.md", "title_cn": "\u7ffb\u8f6c\u6e38\u620f", "title_en": "Flip Game", "question_title_slug": "flip-game", "content_en": "

    You are playing a Flip Game with your friend.

    \n\n

    You are given a string currentState that contains only '+' and '-'. You and your friend take turns to flip two consecutive "++" into "--". The game ends when a person can no longer make a move, and therefore the other person will be the winner.

    \n\n

    Return all possible states of the string currentState after one valid move. You may return the answer in any order. If there is no valid move, return an empty list [].

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: currentState = "++++"\nOutput: ["--++","+--+","++--"]\n
    \n\n

    Example 2:

    \n\n
    \nInput: currentState = "+"\nOutput: []\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= currentState.length <= 500
    • \n\t
    • currentState[i] is either '+' or '-'.
    • \n
    \n", "content_cn": "

    \u4f60\u548c\u670b\u53cb\u73a9\u4e00\u4e2a\u53eb\u505a\u300c\u7ffb\u8f6c\u6e38\u620f\u300d\u7684\u6e38\u620f\u3002\u6e38\u620f\u89c4\u5219\u5982\u4e0b\uff1a

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 currentState \uff0c\u5176\u4e2d\u53ea\u542b '+' \u548c '-' \u3002\u4f60\u548c\u670b\u53cb\u8f6e\u6d41\u5c06\u00a0\u8fde\u7eed \u7684\u4e24\u4e2a\u00a0\"++\"\u00a0\u53cd\u8f6c\u6210\u00a0\"--\" \u3002\u5f53\u4e00\u65b9\u65e0\u6cd5\u8fdb\u884c\u6709\u6548\u7684\u7ffb\u8f6c\u65f6\u4fbf\u610f\u5473\u7740\u6e38\u620f\u7ed3\u675f\uff0c\u5219\u53e6\u4e00\u65b9\u83b7\u80dc\u3002

    \n\n

    \u8ba1\u7b97\u5e76\u8fd4\u56de \u4e00\u6b21\u6709\u6548\u64cd\u4f5c \u540e\uff0c\u5b57\u7b26\u4e32\u00a0currentState \u6240\u6709\u7684\u53ef\u80fd\u72b6\u6001\uff0c\u8fd4\u56de\u7ed3\u679c\u53ef\u4ee5\u6309 \u4efb\u610f\u987a\u5e8f \u6392\u5217\u3002\u5982\u679c\u4e0d\u5b58\u5728\u53ef\u80fd\u7684\u6709\u6548\u64cd\u4f5c\uff0c\u8bf7\u8fd4\u56de\u4e00\u4e2a\u7a7a\u5217\u8868\u00a0[] \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1acurrentState = \"++++\"\n\u8f93\u51fa\uff1a[\"--++\",\"+--+\",\"++--\"]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1acurrentState = \"+\"\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= currentState.length <= 500
    • \n\t
    • currentState[i] \u4e0d\u662f '+' \u5c31\u662f '-'
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector generatePossibleNextMoves(string currentState) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List generatePossibleNextMoves(String currentState) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def generatePossibleNextMoves(self, currentState):\n \"\"\"\n :type currentState: str\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def generatePossibleNextMoves(self, currentState: str) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** generatePossibleNextMoves(char * currentState, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList GeneratePossibleNextMoves(string currentState) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} currentState\n * @return {string[]}\n */\nvar generatePossibleNextMoves = function(currentState) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} current_state\n# @return {String[]}\ndef generate_possible_next_moves(current_state)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func generatePossibleNextMoves(_ currentState: String) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func generatePossibleNextMoves(currentState string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def generatePossibleNextMoves(currentState: String): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun generatePossibleNextMoves(currentState: String): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn generate_possible_next_moves(current_state: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $currentState\n * @return String[]\n */\n function generatePossibleNextMoves($currentState) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function generatePossibleNextMoves(currentState: string): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (generate-possible-next-moves currentState)\n (-> string? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0293](https://leetcode-cn.com/problems/flip-game)", "[\u7ffb\u8f6c\u6e38\u620f](/solution/0200-0299/0293.Flip%20Game/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0293](https://leetcode.com/problems/flip-game)", "[Flip Game](/solution/0200-0299/0293.Flip%20Game/README_EN.md)", "`String`", "Easy", "\ud83d\udd12"]}, {"question_id": "0292", "frontend_question_id": "0292", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/nim-game", "url_en": "https://leetcode.com/problems/nim-game", "relative_path_cn": "/solution/0200-0299/0292.Nim%20Game/README.md", "relative_path_en": "/solution/0200-0299/0292.Nim%20Game/README_EN.md", "title_cn": "Nim \u6e38\u620f", "title_en": "Nim Game", "question_title_slug": "nim-game", "content_en": "

    You are playing the following Nim Game with your friend:

    \n\n
      \n\t
    • Initially, there is a heap of stones on the table.
    • \n\t
    • You and your friend will alternate taking turns, and you go first.
    • \n\t
    • On each turn, the person whose turn it is will remove 1 to 3 stones from the heap.
    • \n\t
    • The one who removes the last stone is the winner.
    • \n
    \n\n

    Given n, the number of stones in the heap, return true if you can win the game assuming both you and your friend play optimally, otherwise return false.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 4\nOutput: false\nExplanation: These are the possible outcomes:\n1. You remove 1 stone. Your friend removes 3 stones, including the last stone. Your friend wins.\n2. You remove 2 stones. Your friend removes 2 stones, including the last stone. Your friend wins.\n3. You remove 3 stones. Your friend removes the last stone. Your friend wins.\nIn all outcomes, your friend wins.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 1\nOutput: true\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 2\nOutput: true\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 231 - 1
    • \n
    \n", "content_cn": "

    \u4f60\u548c\u4f60\u7684\u670b\u53cb\uff0c\u4e24\u4e2a\u4eba\u4e00\u8d77\u73a9\u00a0Nim \u6e38\u620f\uff1a

    \n\n
      \n\t
    • \u684c\u5b50\u4e0a\u6709\u4e00\u5806\u77f3\u5934\u3002
    • \n\t
    • \u4f60\u4eec\u8f6e\u6d41\u8fdb\u884c\u81ea\u5df1\u7684\u56de\u5408\uff0c\u4f60\u4f5c\u4e3a\u5148\u624b\u3002
    • \n\t
    • \u6bcf\u4e00\u56de\u5408\uff0c\u8f6e\u5230\u7684\u4eba\u62ff\u6389\u00a01 - 3 \u5757\u77f3\u5934\u3002
    • \n\t
    • \u62ff\u6389\u6700\u540e\u4e00\u5757\u77f3\u5934\u7684\u4eba\u5c31\u662f\u83b7\u80dc\u8005\u3002
    • \n
    \n\n

    \u5047\u8bbe\u4f60\u4eec\u6bcf\u4e00\u6b65\u90fd\u662f\u6700\u4f18\u89e3\u3002\u8bf7\u7f16\u5199\u4e00\u4e2a\u51fd\u6570\uff0c\u6765\u5224\u65ad\u4f60\u662f\u5426\u53ef\u4ee5\u5728\u7ed9\u5b9a\u77f3\u5934\u6570\u91cf\u4e3a n \u7684\u60c5\u51b5\u4e0b\u8d62\u5f97\u6e38\u620f\u3002\u5982\u679c\u53ef\u4ee5\u8d62\uff0c\u8fd4\u56de true\uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 4\n\u8f93\u51fa\uff1afalse \n\u89e3\u91ca\uff1a\u5982\u679c\u5806\u4e2d\u6709 4 \u5757\u77f3\u5934\uff0c\u90a3\u4e48\u4f60\u6c38\u8fdc\u4e0d\u4f1a\u8d62\u5f97\u6bd4\u8d5b\uff1b\n\u00a0    \u56e0\u4e3a\u65e0\u8bba\u4f60\u62ff\u8d70 1 \u5757\u30012 \u5757 \u8fd8\u662f 3 \u5757\u77f3\u5934\uff0c\u6700\u540e\u4e00\u5757\u77f3\u5934\u603b\u662f\u4f1a\u88ab\u4f60\u7684\u670b\u53cb\u62ff\u8d70\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 2\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 231 - 1
    • \n
    \n", "tags_en": ["Brainteaser", "Minimax"], "tags_cn": ["\u8111\u7b4b\u6025\u8f6c\u5f2f", "\u6781\u5c0f\u5316\u6781\u5927"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canWinNim(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canWinNim(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canWinNim(self, n):\n \"\"\"\n :type n: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canWinNim(self, n: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canWinNim(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanWinNim(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {boolean}\n */\nvar canWinNim = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Boolean}\ndef can_win_nim(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canWinNim(_ n: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canWinNim(n int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canWinNim(n: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canWinNim(n: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_win_nim(n: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Boolean\n */\n function canWinNim($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canWinNim(n: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-win-nim n)\n (-> exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0292](https://leetcode-cn.com/problems/nim-game)", "[Nim \u6e38\u620f](/solution/0200-0299/0292.Nim%20Game/README.md)", "`\u8111\u7b4b\u6025\u8f6c\u5f2f`,`\u6781\u5c0f\u5316\u6781\u5927`", "\u7b80\u5355", ""], "md_table_row_en": ["[0292](https://leetcode.com/problems/nim-game)", "[Nim Game](/solution/0200-0299/0292.Nim%20Game/README_EN.md)", "`Brainteaser`,`Minimax`", "Easy", ""]}, {"question_id": "0291", "frontend_question_id": "0291", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/word-pattern-ii", "url_en": "https://leetcode.com/problems/word-pattern-ii", "relative_path_cn": "/solution/0200-0299/0291.Word%20Pattern%20II/README.md", "relative_path_en": "/solution/0200-0299/0291.Word%20Pattern%20II/README_EN.md", "title_cn": "\u5355\u8bcd\u89c4\u5f8b II", "title_en": "Word Pattern II", "question_title_slug": "word-pattern-ii", "content_en": "

    Given a pattern and a string s, return true if s matches the pattern.

    \n\n

    A string s matches a pattern if there is some bijective mapping of single characters to strings such that if each character in pattern is replaced by the string it maps to, then the resulting string is s. A bijective mapping means that no two characters map to the same string, and no character maps to two different strings.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: pattern = "abab", s = "redblueredblue"\nOutput: true\nExplanation: One possible mapping is as follows:\n'a' -> "red"\n'b' -> "blue"
    \n\n

    Example 2:

    \n\n
    \nInput: pattern = "aaaa", s = "asdasdasdasd"\nOutput: true\nExplanation: One possible mapping is as follows:\n'a' -> "asd"\n
    \n\n

    Example 3:

    \n\n
    \nInput: pattern = "abab", s = "asdasdasdasd"\nOutput: true\nExplanation: One possible mapping is as follows:\n'a' -> "a"\n'b' -> "sdasd"\nNote that 'a' and 'b' cannot both map to "asd" since the mapping is a bijection.\n
    \n\n

    Example 4:

    \n\n
    \nInput: pattern = "aabb", s = "xyzabcxzyabc"\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= pattern.length, s.length <= 20
    • \n\t
    • pattern and s consist of only lower-case English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u79cd\u89c4\u5f8b\u00a0pattern\u00a0\u548c\u4e00\u4e2a\u5b57\u7b26\u4e32\u00a0str\uff0c\u8bf7\u4f60\u5224\u65ad\u00a0str\u00a0\u662f\u5426\u9075\u5faa\u5176\u76f8\u540c\u7684\u89c4\u5f8b\u3002

    \n\n

    \u8fd9\u91cc\u6211\u4eec\u6307\u7684\u662f \u5b8c\u5168\u9075\u5faa\uff0c\u4f8b\u5982 pattern\u00a0\u91cc\u7684\u6bcf\u4e2a\u5b57\u6bcd\u548c\u5b57\u7b26\u4e32\u00a0str\u00a0\u4e2d\u6bcf\u4e2a \u975e\u7a7a \u5355\u8bcd\u4e4b\u95f4\uff0c\u5b58\u5728\u7740 \u53cc\u5c04 \u7684\u5bf9\u5e94\u89c4\u5f8b\u3002\u53cc\u5c04 \u610f\u5473\u7740\u6620\u5c04\u53cc\u65b9\u4e00\u4e00\u5bf9\u5e94\uff0c\u4e0d\u4f1a\u5b58\u5728\u4e24\u4e2a\u5b57\u7b26\u6620\u5c04\u5230\u540c\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u4e5f\u4e0d\u4f1a\u5b58\u5728\u4e00\u4e2a\u5b57\u7b26\u5206\u522b\u6620\u5c04\u5230\u4e24\u4e2a\u4e0d\u540c\u7684\u5b57\u7b26\u4e32\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1apattern = \"abab\", s = \"redblueredblue\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u4e00\u79cd\u53ef\u80fd\u7684\u6620\u5c04\u5982\u4e0b\uff1a\n'a' -> \"red\"\n'b' -> \"blue\"
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1apattern = \"aaaa\", s = \"asdasdasdasd\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u4e00\u79cd\u53ef\u80fd\u7684\u6620\u5c04\u5982\u4e0b\uff1a\n'a' -> \"asd\"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1apattern = \"abab\", s = \"asdasdasdasd\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u4e00\u79cd\u53ef\u80fd\u7684\u6620\u5c04\u5982\u4e0b\uff1a\n'a' -> \"a\"\n'b' -> \"sdasd\"\n\u6ce8\u610f 'a' \u548c 'b' \u4e0d\u80fd\u540c\u65f6\u6620\u5c04\u5230 \"asd\"\uff0c\u56e0\u4e3a\u8fd9\u91cc\u7684\u6620\u5c04\u662f\u4e00\u79cd\u53cc\u5c04\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1apattern = \"aabb\", s = \"xyzabcxzyabc\"\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= pattern.length <= 20
    • \n\t
    • 0 <= s.length <= 50
    • \n\t
    • pattern \u548c s \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n", "tags_en": ["Backtracking"], "tags_cn": ["\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool wordPatternMatch(string pattern, string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean wordPatternMatch(String pattern, String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def wordPatternMatch(self, pattern, s):\n \"\"\"\n :type pattern: str\n :type s: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def wordPatternMatch(self, pattern: str, s: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool wordPatternMatch(char * pattern, char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool WordPatternMatch(string pattern, string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} pattern\n * @param {string} s\n * @return {boolean}\n */\nvar wordPatternMatch = function(pattern, s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} pattern\n# @param {String} s\n# @return {Boolean}\ndef word_pattern_match(pattern, s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func wordPatternMatch(_ pattern: String, _ s: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func wordPatternMatch(pattern string, s string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def wordPatternMatch(pattern: String, s: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun wordPatternMatch(pattern: String, s: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn word_pattern_match(pattern: String, s: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $pattern\n * @param String $s\n * @return Boolean\n */\n function wordPatternMatch($pattern, $s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function wordPatternMatch(pattern: string, s: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (word-pattern-match pattern s)\n (-> string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0291](https://leetcode-cn.com/problems/word-pattern-ii)", "[\u5355\u8bcd\u89c4\u5f8b II](/solution/0200-0299/0291.Word%20Pattern%20II/README.md)", "`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0291](https://leetcode.com/problems/word-pattern-ii)", "[Word Pattern II](/solution/0200-0299/0291.Word%20Pattern%20II/README_EN.md)", "`Backtracking`", "Medium", "\ud83d\udd12"]}, {"question_id": "0290", "frontend_question_id": "0290", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/word-pattern", "url_en": "https://leetcode.com/problems/word-pattern", "relative_path_cn": "/solution/0200-0299/0290.Word%20Pattern/README.md", "relative_path_en": "/solution/0200-0299/0290.Word%20Pattern/README_EN.md", "title_cn": "\u5355\u8bcd\u89c4\u5f8b", "title_en": "Word Pattern", "question_title_slug": "word-pattern", "content_en": "

    Given a pattern and a string s, find if s follows the same pattern.

    \n\n

    Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in s.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: pattern = "abba", s = "dog cat cat dog"\nOutput: true\n
    \n\n

    Example 2:

    \n\n
    \nInput: pattern = "abba", s = "dog cat cat fish"\nOutput: false\n
    \n\n

    Example 3:

    \n\n
    \nInput: pattern = "aaaa", s = "dog cat cat dog"\nOutput: false\n
    \n\n

    Example 4:

    \n\n
    \nInput: pattern = "abba", s = "dog dog dog dog"\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= pattern.length <= 300
    • \n\t
    • pattern contains only lower-case English letters.
    • \n\t
    • 1 <= s.length <= 3000
    • \n\t
    • s contains only lower-case English letters and spaces ' '.
    • \n\t
    • s does not contain any leading or trailing spaces.
    • \n\t
    • All the words in s are separated by a single space.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u79cd\u89c4\u5f8b pattern \u548c\u4e00\u4e2a\u5b57\u7b26\u4e32 str \uff0c\u5224\u65ad str \u662f\u5426\u9075\u5faa\u76f8\u540c\u7684\u89c4\u5f8b\u3002

    \n\n

    \u8fd9\u91cc\u7684 \u9075\u5faa \u6307\u5b8c\u5168\u5339\u914d\uff0c\u4f8b\u5982\uff0c pattern \u91cc\u7684\u6bcf\u4e2a\u5b57\u6bcd\u548c\u5b57\u7b26\u4e32 str \u4e2d\u7684\u6bcf\u4e2a\u975e\u7a7a\u5355\u8bcd\u4e4b\u95f4\u5b58\u5728\u7740\u53cc\u5411\u8fde\u63a5\u7684\u5bf9\u5e94\u89c4\u5f8b\u3002

    \n\n

    \u793a\u4f8b1:

    \n\n
    \u8f93\u5165: pattern = "abba", str = "dog cat cat dog"\n\u8f93\u51fa: true
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165:pattern = "abba", str = "dog cat cat fish"\n\u8f93\u51fa: false
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u8f93\u5165: pattern = "aaaa", str = "dog cat cat dog"\n\u8f93\u51fa: false
    \n\n

    \u793a\u4f8b 4:

    \n\n
    \u8f93\u5165: pattern = "abba", str = "dog dog dog dog"\n\u8f93\u51fa: false
    \n\n

    \u8bf4\u660e:
    \n\u4f60\u53ef\u4ee5\u5047\u8bbe pattern \u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd\uff0c str \u5305\u542b\u4e86\u7531\u5355\u4e2a\u7a7a\u683c\u5206\u9694\u7684\u5c0f\u5199\u5b57\u6bcd\u3002    

    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool wordPattern(string pattern, string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean wordPattern(String pattern, String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def wordPattern(self, pattern, s):\n \"\"\"\n :type pattern: str\n :type s: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def wordPattern(self, pattern: str, s: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool wordPattern(char * pattern, char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool WordPattern(string pattern, string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} pattern\n * @param {string} s\n * @return {boolean}\n */\nvar wordPattern = function(pattern, s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} pattern\n# @param {String} s\n# @return {Boolean}\ndef word_pattern(pattern, s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func wordPattern(_ pattern: String, _ s: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func wordPattern(pattern string, s string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def wordPattern(pattern: String, s: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun wordPattern(pattern: String, s: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn word_pattern(pattern: String, s: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $pattern\n * @param String $s\n * @return Boolean\n */\n function wordPattern($pattern, $s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function wordPattern(pattern: string, s: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (word-pattern pattern s)\n (-> string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0290](https://leetcode-cn.com/problems/word-pattern)", "[\u5355\u8bcd\u89c4\u5f8b](/solution/0200-0299/0290.Word%20Pattern/README.md)", "`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0290](https://leetcode.com/problems/word-pattern)", "[Word Pattern](/solution/0200-0299/0290.Word%20Pattern/README_EN.md)", "`Hash Table`", "Easy", ""]}, {"question_id": "0289", "frontend_question_id": "0289", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/game-of-life", "url_en": "https://leetcode.com/problems/game-of-life", "relative_path_cn": "/solution/0200-0299/0289.Game%20of%20Life/README.md", "relative_path_en": "/solution/0200-0299/0289.Game%20of%20Life/README_EN.md", "title_cn": "\u751f\u547d\u6e38\u620f", "title_en": "Game of Life", "question_title_slug": "game-of-life", "content_en": "

    According to Wikipedia's article: "The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970."

    \n\n

    The board is made up of an m x n grid of cells, where each cell has an initial state: live (represented by a 1) or dead (represented by a 0). Each cell interacts with its eight neighbors (horizontal, vertical, diagonal) using the following four rules (taken from the above Wikipedia article):

    \n\n
      \n\t
    1. Any live cell with fewer than two live neighbors dies as if caused by under-population.
    2. \n\t
    3. Any live cell with two or three live neighbors lives on to the next generation.
    4. \n\t
    5. Any live cell with more than three live neighbors dies, as if by over-population.
    6. \n\t
    7. Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction.
    8. \n
    \n\n

    The next state is created by applying the above rules simultaneously to every cell in the current state, where births and deaths occur simultaneously. Given the current state of the m x n grid board, return the next state.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: board = [[0,1,0],[0,0,1],[1,1,1],[0,0,0]]\nOutput: [[0,0,0],[1,0,1],[0,1,1],[0,1,0]]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: board = [[1,1],[1,0]]\nOutput: [[1,1],[1,1]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == board.length
    • \n\t
    • n == board[i].length
    • \n\t
    • 1 <= m, n <= 25
    • \n\t
    • board[i][j] is 0 or 1.
    • \n
    \n\n

     

    \n

    Follow up:

    \n\n
      \n\t
    • Could you solve it in-place? Remember that the board needs to be updated simultaneously: You cannot update some cells first and then use their updated values to update other cells.
    • \n\t
    • In this question, we represent the board using a 2D array. In principle, the board is infinite, which would cause problems when the active area encroaches upon the border of the array (i.e., live cells reach the border). How would you address these problems?
    • \n
    \n", "content_cn": "

    \u6839\u636e\u00a0\u767e\u5ea6\u767e\u79d1\u00a0\uff0c\u751f\u547d\u6e38\u620f\uff0c\u7b80\u79f0\u4e3a\u751f\u547d\uff0c\u662f\u82f1\u56fd\u6570\u5b66\u5bb6\u7ea6\u7ff0\u00b7\u4f55\u987f\u00b7\u5eb7\u5a01\u5728 1970 \u5e74\u53d1\u660e\u7684\u7ec6\u80de\u81ea\u52a8\u673a\u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u5305\u542b m \u00d7 n \u4e2a\u683c\u5b50\u7684\u9762\u677f\uff0c\u6bcf\u4e00\u4e2a\u683c\u5b50\u90fd\u53ef\u4ee5\u770b\u6210\u662f\u4e00\u4e2a\u7ec6\u80de\u3002\u6bcf\u4e2a\u7ec6\u80de\u90fd\u5177\u6709\u4e00\u4e2a\u521d\u59cb\u72b6\u6001\uff1a1 \u5373\u4e3a\u6d3b\u7ec6\u80de\uff08live\uff09\uff0c\u6216 0 \u5373\u4e3a\u6b7b\u7ec6\u80de\uff08dead\uff09\u3002\u6bcf\u4e2a\u7ec6\u80de\u4e0e\u5176\u516b\u4e2a\u76f8\u90bb\u4f4d\u7f6e\uff08\u6c34\u5e73\uff0c\u5782\u76f4\uff0c\u5bf9\u89d2\u7ebf\uff09\u7684\u7ec6\u80de\u90fd\u9075\u5faa\u4ee5\u4e0b\u56db\u6761\u751f\u5b58\u5b9a\u5f8b\uff1a

    \n\n
      \n\t
    1. \u5982\u679c\u6d3b\u7ec6\u80de\u5468\u56f4\u516b\u4e2a\u4f4d\u7f6e\u7684\u6d3b\u7ec6\u80de\u6570\u5c11\u4e8e\u4e24\u4e2a\uff0c\u5219\u8be5\u4f4d\u7f6e\u6d3b\u7ec6\u80de\u6b7b\u4ea1\uff1b
    2. \n\t
    3. \u5982\u679c\u6d3b\u7ec6\u80de\u5468\u56f4\u516b\u4e2a\u4f4d\u7f6e\u6709\u4e24\u4e2a\u6216\u4e09\u4e2a\u6d3b\u7ec6\u80de\uff0c\u5219\u8be5\u4f4d\u7f6e\u6d3b\u7ec6\u80de\u4ecd\u7136\u5b58\u6d3b\uff1b
    4. \n\t
    5. \u5982\u679c\u6d3b\u7ec6\u80de\u5468\u56f4\u516b\u4e2a\u4f4d\u7f6e\u6709\u8d85\u8fc7\u4e09\u4e2a\u6d3b\u7ec6\u80de\uff0c\u5219\u8be5\u4f4d\u7f6e\u6d3b\u7ec6\u80de\u6b7b\u4ea1\uff1b
    6. \n\t
    7. \u5982\u679c\u6b7b\u7ec6\u80de\u5468\u56f4\u6b63\u597d\u6709\u4e09\u4e2a\u6d3b\u7ec6\u80de\uff0c\u5219\u8be5\u4f4d\u7f6e\u6b7b\u7ec6\u80de\u590d\u6d3b\uff1b
    8. \n
    \n\n

    \u4e0b\u4e00\u4e2a\u72b6\u6001\u662f\u901a\u8fc7\u5c06\u4e0a\u8ff0\u89c4\u5219\u540c\u65f6\u5e94\u7528\u4e8e\u5f53\u524d\u72b6\u6001\u4e0b\u7684\u6bcf\u4e2a\u7ec6\u80de\u6240\u5f62\u6210\u7684\uff0c\u5176\u4e2d\u7ec6\u80de\u7684\u51fa\u751f\u548c\u6b7b\u4ea1\u662f\u540c\u65f6\u53d1\u751f\u7684\u3002\u7ed9\u4f60 m x n \u7f51\u683c\u9762\u677f board \u7684\u5f53\u524d\u72b6\u6001\uff0c\u8fd4\u56de\u4e0b\u4e00\u4e2a\u72b6\u6001\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aboard = [[0,1,0],[0,0,1],[1,1,1],[0,0,0]]\n\u8f93\u51fa\uff1a[[0,0,0],[1,0,1],[0,1,1],[0,1,0]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aboard = [[1,1],[1,0]]\n\u8f93\u51fa\uff1a[[1,1],[1,1]]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == board.length
    • \n\t
    • n == board[i].length
    • \n\t
    • 1 <= m, n <= 25
    • \n\t
    • board[i][j] \u4e3a 0 \u6216 1
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u4f60\u53ef\u4ee5\u4f7f\u7528\u539f\u5730\u7b97\u6cd5\u89e3\u51b3\u672c\u9898\u5417\uff1f\u8bf7\u6ce8\u610f\uff0c\u9762\u677f\u4e0a\u6240\u6709\u683c\u5b50\u9700\u8981\u540c\u65f6\u88ab\u66f4\u65b0\uff1a\u4f60\u4e0d\u80fd\u5148\u66f4\u65b0\u67d0\u4e9b\u683c\u5b50\uff0c\u7136\u540e\u4f7f\u7528\u5b83\u4eec\u7684\u66f4\u65b0\u540e\u7684\u503c\u518d\u66f4\u65b0\u5176\u4ed6\u683c\u5b50\u3002
    • \n\t
    • \u672c\u9898\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u4e8c\u7ef4\u6570\u7ec4\u6765\u8868\u793a\u9762\u677f\u3002\u539f\u5219\u4e0a\uff0c\u9762\u677f\u662f\u65e0\u9650\u7684\uff0c\u4f46\u5f53\u6d3b\u7ec6\u80de\u4fb5\u5360\u4e86\u9762\u677f\u8fb9\u754c\u65f6\u4f1a\u9020\u6210\u95ee\u9898\u3002\u4f60\u5c06\u5982\u4f55\u89e3\u51b3\u8fd9\u4e9b\u95ee\u9898\uff1f
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n void gameOfLife(vector>& board) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public void gameOfLife(int[][] board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def gameOfLife(self, board):\n \"\"\"\n :type board: List[List[int]]\n :rtype: None Do not return anything, modify board in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def gameOfLife(self, board: List[List[int]]) -> None:\n \"\"\"\n Do not return anything, modify board in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nvoid gameOfLife(int** board, int boardSize, int* boardColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public void GameOfLife(int[][] board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} board\n * @return {void} Do not return anything, modify board in-place instead.\n */\nvar gameOfLife = function(board) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} board\n# @return {Void} Do not return anything, modify board in-place instead.\ndef game_of_life(board)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func gameOfLife(_ board: inout [[Int]]) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func gameOfLife(board [][]int) {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def gameOfLife(board: Array[Array[Int]]): Unit = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun gameOfLife(board: Array): Unit {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn game_of_life(board: &mut Vec>) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $board\n * @return NULL\n */\n function gameOfLife(&$board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n Do not return anything, modify board in-place instead.\n */\nfunction gameOfLife(board: number[][]): void {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0289](https://leetcode-cn.com/problems/game-of-life)", "[\u751f\u547d\u6e38\u620f](/solution/0200-0299/0289.Game%20of%20Life/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0289](https://leetcode.com/problems/game-of-life)", "[Game of Life](/solution/0200-0299/0289.Game%20of%20Life/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0288", "frontend_question_id": "0288", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/unique-word-abbreviation", "url_en": "https://leetcode.com/problems/unique-word-abbreviation", "relative_path_cn": "/solution/0200-0299/0288.Unique%20Word%20Abbreviation/README.md", "relative_path_en": "/solution/0200-0299/0288.Unique%20Word%20Abbreviation/README_EN.md", "title_cn": "\u5355\u8bcd\u7684\u552f\u4e00\u7f29\u5199", "title_en": "Unique Word Abbreviation", "question_title_slug": "unique-word-abbreviation", "content_en": "

    The abbreviation of a word is a concatenation of its first letter, the number of characters between the first and last letter, and its last letter. If a word has only two characters, then it is an abbreviation of itself.

    \n\n

    For example:

    \n\n
      \n\t
    • dog --> d1g because there is one letter between the first letter 'd' and the last letter 'g'.
    • \n\t
    • internationalization --> i18n because there are 18 letters between the first letter 'i' and the last letter 'n'.
    • \n\t
    • it --> it because any word with only two characters is an abbreviation of itself.
    • \n
    \n\n

    Implement the ValidWordAbbr class:

    \n\n
      \n\t
    • ValidWordAbbr(String[] dictionary) Initializes the object with a dictionary of words.
    • \n\t
    • boolean isUnique(string word) Returns true if either of the following conditions are met (otherwise returns false):\n\t
        \n\t\t
      • There is no word in dictionary whose abbreviation is equal to word's abbreviation.
      • \n\t\t
      • For any word in dictionary whose abbreviation is equal to word's abbreviation, that word and word are the same.
      • \n\t
      \n\t
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["ValidWordAbbr", "isUnique", "isUnique", "isUnique", "isUnique"]\n[[["deer", "door", "cake", "card"]], ["dear"], ["cart"], ["cane"], ["make"]]\nOutput\n[null, false, true, false, true]\n\nExplanation\nValidWordAbbr validWordAbbr = new ValidWordAbbr(["deer", "door", "cake", "card"]);\nvalidWordAbbr.isUnique("dear"); // return false, dictionary word "deer" and word "dear" have the same abbreviation\n                                // "d2r" but are not the same.\nvalidWordAbbr.isUnique("cart"); // return true, no words in the dictionary have the abbreviation "c2t".\nvalidWordAbbr.isUnique("cane"); // return false, dictionary word "cake" and word "cane" have the same abbreviation \n                                // "c2e" but are not the same.\nvalidWordAbbr.isUnique("make"); // return true, no words in the dictionary have the abbreviation "m2e".\nvalidWordAbbr.isUnique("cake"); // return true, because "cake" is already in the dictionary and no other word in the dictionary has "c2e" abbreviation.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= dictionary.length <= 3 * 104
    • \n\t
    • 1 <= dictionary[i].length <= 20
    • \n\t
    • dictionary[i] consists of lowercase English letters.
    • \n\t
    • 1 <= word.length <= 20
    • \n\t
    • word consists of lowercase English letters.
    • \n\t
    • At most 5000 calls will be made to isUnique.
    • \n
    \n", "content_cn": "

    \u5355\u8bcd\u7684 \u7f29\u5199 \u9700\u8981\u9075\u5faa\u00a0<\u8d77\u59cb\u5b57\u6bcd><\u4e2d\u95f4\u5b57\u6bcd\u6570><\u7ed3\u5c3e\u5b57\u6bcd> \u8fd9\u6837\u7684\u683c\u5f0f\u3002\u5982\u679c\u5355\u8bcd\u53ea\u6709\u4e24\u4e2a\u5b57\u7b26\uff0c\u90a3\u4e48\u5b83\u5c31\u662f\u5b83\u81ea\u8eab\u7684 \u7f29\u5199 \u3002

    \n\n

    \u4ee5\u4e0b\u662f\u4e00\u4e9b\u5355\u8bcd\u7f29\u5199\u7684\u8303\u4f8b\uff1a

    \n\n
      \n\t
    • dog --> d1g \u56e0\u4e3a\u7b2c\u4e00\u4e2a\u5b57\u6bcd 'd' \u548c\u6700\u540e\u4e00\u4e2a\u5b57\u6bcd 'g' \u4e4b\u95f4\u6709 1 \u4e2a\u5b57\u6bcd
    • \n\t
    • internationalization --> i18n \u56e0\u4e3a\u7b2c\u4e00\u4e2a\u5b57\u6bcd 'i' \u548c\u6700\u540e\u4e00\u4e2a\u5b57\u6bcd 'n' \u4e4b\u95f4\u6709 18 \u4e2a\u5b57\u6bcd
    • \n\t
    • it --> it \u5355\u8bcd\u53ea\u6709\u4e24\u4e2a\u5b57\u7b26\uff0c\u5b83\u5c31\u662f\u5b83\u81ea\u8eab\u7684 \u7f29\u5199
    • \n
    \n\n

    \u00a0

    \n\n

    \u5b9e\u73b0 ValidWordAbbr \u7c7b\uff1a

    \n\n
      \n\t
    • ValidWordAbbr(String[] dictionary) \u4f7f\u7528\u5355\u8bcd\u5b57\u5178 dictionary \u521d\u59cb\u5316\u5bf9\u8c61
    • \n\t
    • boolean isUnique(string word) \u5982\u679c\u6ee1\u8db3\u4e0b\u8ff0\u4efb\u610f\u4e00\u4e2a\u6761\u4ef6\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \uff1a\n\t
        \n\t\t
      • \u5b57\u5178 dictionary \u4e2d\u6ca1\u6709\u4efb\u4f55\u5176\u4ed6\u5355\u8bcd\u7684 \u7f29\u5199 \u4e0e\u8be5\u5355\u8bcd word \u7684 \u7f29\u5199 \u76f8\u540c\u3002
      • \n\t\t
      • \u5b57\u5178 dictionary \u4e2d\u7684\u6240\u6709 \u7f29\u5199 \u4e0e\u8be5\u5355\u8bcd word \u7684 \u7f29\u5199 \u76f8\u540c\u7684\u5355\u8bcd\u90fd\u4e0e word \u76f8\u540c \u3002
      • \n\t
      \n\t
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\n[\"ValidWordAbbr\", \"isUnique\", \"isUnique\", \"isUnique\", \"isUnique\"]\n[[[\"deer\", \"door\", \"cake\", \"card\"]], [\"dear\"], [\"cart\"], [\"cane\"], [\"make\"]]\n\u8f93\u51fa\n[null, false, true, false, true]\n\n\u89e3\u91ca\nValidWordAbbr validWordAbbr = new ValidWordAbbr([\"deer\", \"door\", \"cake\", \"card\"]);\nvalidWordAbbr.isUnique(\"dear\"); // \u8fd4\u56de false\uff0c\u5b57\u5178\u4e2d\u7684 \"deer\" \u4e0e\u8f93\u5165 \"dear\" \u7684\u7f29\u5199\u90fd\u662f \"d2r\"\uff0c\u4f46\u8fd9\u4e24\u4e2a\u5355\u8bcd\u4e0d\u76f8\u540c\nvalidWordAbbr.isUnique(\"cart\"); // \u8fd4\u56de true\uff0c\u5b57\u5178\u4e2d\u4e0d\u5b58\u5728\u7f29\u5199\u4e3a \"c2t\" \u7684\u5355\u8bcd\nvalidWordAbbr.isUnique(\"cane\"); // \u8fd4\u56de false\uff0c\u5b57\u5178\u4e2d\u7684 \"cake\" \u4e0e\u8f93\u5165 \"cane\" \u7684\u7f29\u5199\u90fd\u662f \"c2e\"\uff0c\u4f46\u8fd9\u4e24\u4e2a\u5355\u8bcd\u4e0d\u76f8\u540c\nvalidWordAbbr.isUnique(\"make\"); // \u8fd4\u56de true\uff0c\u5b57\u5178\u4e2d\u4e0d\u5b58\u5728\u7f29\u5199\u4e3a \"m2e\" \u7684\u5355\u8bcd\nvalidWordAbbr.isUnique(\"cake\"); // \u8fd4\u56de true\uff0c\u56e0\u4e3a \"cake\" \u5df2\u7ecf\u5b58\u5728\u4e8e\u5b57\u5178\u4e2d\uff0c\u5e76\u4e14\u5b57\u5178\u4e2d\u6ca1\u6709\u5176\u4ed6\u7f29\u5199\u4e3a \"c2e\" \u7684\u5355\u8bcd\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= dictionary.length <= 3 * 104
    • \n\t
    • 1 <= dictionary[i].length <= 20
    • \n\t
    • dictionary[i] \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n\t
    • 1 <= word <= 20
    • \n\t
    • word \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n\t
    • \u6700\u591a\u8c03\u7528 5000 \u6b21 isUnique
    • \n
    \n", "tags_en": ["Design", "Hash Table"], "tags_cn": ["\u8bbe\u8ba1", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class ValidWordAbbr {\npublic:\n ValidWordAbbr(vector& dictionary) {\n\n }\n \n bool isUnique(string word) {\n\n }\n};\n\n/**\n * Your ValidWordAbbr object will be instantiated and called as such:\n * ValidWordAbbr* obj = new ValidWordAbbr(dictionary);\n * bool param_1 = obj->isUnique(word);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class ValidWordAbbr {\n\n public ValidWordAbbr(String[] dictionary) {\n\n }\n \n public boolean isUnique(String word) {\n\n }\n}\n\n/**\n * Your ValidWordAbbr object will be instantiated and called as such:\n * ValidWordAbbr obj = new ValidWordAbbr(dictionary);\n * boolean param_1 = obj.isUnique(word);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class ValidWordAbbr(object):\n\n def __init__(self, dictionary):\n \"\"\"\n :type dictionary: List[str]\n \"\"\"\n\n\n def isUnique(self, word):\n \"\"\"\n :type word: str\n :rtype: bool\n \"\"\"\n\n\n\n# Your ValidWordAbbr object will be instantiated and called as such:\n# obj = ValidWordAbbr(dictionary)\n# param_1 = obj.isUnique(word)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class ValidWordAbbr:\n\n def __init__(self, dictionary: List[str]):\n\n\n def isUnique(self, word: str) -> bool:\n\n\n\n# Your ValidWordAbbr object will be instantiated and called as such:\n# obj = ValidWordAbbr(dictionary)\n# param_1 = obj.isUnique(word)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} ValidWordAbbr;\n\n\nValidWordAbbr* validWordAbbrCreate(char ** dictionary, int dictionarySize) {\n \n}\n\nbool validWordAbbrIsUnique(ValidWordAbbr* obj, char * word) {\n \n}\n\nvoid validWordAbbrFree(ValidWordAbbr* obj) {\n \n}\n\n/**\n * Your ValidWordAbbr struct will be instantiated and called as such:\n * ValidWordAbbr* obj = validWordAbbrCreate(dictionary, dictionarySize);\n * bool param_1 = validWordAbbrIsUnique(obj, word);\n \n * validWordAbbrFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class ValidWordAbbr {\n\n public ValidWordAbbr(string[] dictionary) {\n\n }\n \n public bool IsUnique(string word) {\n\n }\n}\n\n/**\n * Your ValidWordAbbr object will be instantiated and called as such:\n * ValidWordAbbr obj = new ValidWordAbbr(dictionary);\n * bool param_1 = obj.IsUnique(word);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} dictionary\n */\nvar ValidWordAbbr = function(dictionary) {\n\n};\n\n/** \n * @param {string} word\n * @return {boolean}\n */\nValidWordAbbr.prototype.isUnique = function(word) {\n\n};\n\n/**\n * Your ValidWordAbbr object will be instantiated and called as such:\n * var obj = new ValidWordAbbr(dictionary)\n * var param_1 = obj.isUnique(word)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class ValidWordAbbr\n\n=begin\n :type dictionary: String[]\n=end\n def initialize(dictionary)\n\n end\n\n\n=begin\n :type word: String\n :rtype: Boolean\n=end\n def is_unique(word)\n\n end\n\n\nend\n\n# Your ValidWordAbbr object will be instantiated and called as such:\n# obj = ValidWordAbbr.new(dictionary)\n# param_1 = obj.is_unique(word)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass ValidWordAbbr {\n\n init(_ dictionary: [String]) {\n\n }\n \n func isUnique(_ word: String) -> Bool {\n\n }\n}\n\n/**\n * Your ValidWordAbbr object will be instantiated and called as such:\n * let obj = ValidWordAbbr(dictionary)\n * let ret_1: Bool = obj.isUnique(word)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type ValidWordAbbr struct {\n\n}\n\n\nfunc Constructor(dictionary []string) ValidWordAbbr {\n\n}\n\n\nfunc (this *ValidWordAbbr) IsUnique(word string) bool {\n\n}\n\n\n/**\n * Your ValidWordAbbr object will be instantiated and called as such:\n * obj := Constructor(dictionary);\n * param_1 := obj.IsUnique(word);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class ValidWordAbbr(_dictionary: Array[String]) {\n\n def isUnique(word: String): Boolean = {\n\n }\n\n}\n\n/**\n * Your ValidWordAbbr object will be instantiated and called as such:\n * var obj = new ValidWordAbbr(dictionary)\n * var param_1 = obj.isUnique(word)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class ValidWordAbbr(dictionary: Array) {\n\n fun isUnique(word: String): Boolean {\n\n }\n\n}\n\n/**\n * Your ValidWordAbbr object will be instantiated and called as such:\n * var obj = ValidWordAbbr(dictionary)\n * var param_1 = obj.isUnique(word)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct ValidWordAbbr {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl ValidWordAbbr {\n\n fn new(dictionary: Vec) -> Self {\n\n }\n \n fn is_unique(&self, word: String) -> bool {\n\n }\n}\n\n/**\n * Your ValidWordAbbr object will be instantiated and called as such:\n * let obj = ValidWordAbbr::new(dictionary);\n * let ret_1: bool = obj.is_unique(word);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class ValidWordAbbr {\n /**\n * @param String[] $dictionary\n */\n function __construct($dictionary) {\n\n }\n\n /**\n * @param String $word\n * @return Boolean\n */\n function isUnique($word) {\n\n }\n}\n\n/**\n * Your ValidWordAbbr object will be instantiated and called as such:\n * $obj = ValidWordAbbr($dictionary);\n * $ret_1 = $obj->isUnique($word);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class ValidWordAbbr {\n constructor(dictionary: string[]) {\n\n }\n\n isUnique(word: string): boolean {\n\n }\n}\n\n/**\n * Your ValidWordAbbr object will be instantiated and called as such:\n * var obj = new ValidWordAbbr(dictionary)\n * var param_1 = obj.isUnique(word)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define valid-word-abbr%\n (class object%\n (super-new)\n\n ; dictionary : (listof string?)\n (init-field\n dictionary)\n \n ; is-unique : string? -> boolean?\n (define/public (is-unique word)\n\n )))\n\n;; Your valid-word-abbr% object will be instantiated and called as such:\n;; (define obj (new valid-word-abbr% [dictionary dictionary]))\n;; (define param_1 (send obj is-unique word))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0288](https://leetcode-cn.com/problems/unique-word-abbreviation)", "[\u5355\u8bcd\u7684\u552f\u4e00\u7f29\u5199](/solution/0200-0299/0288.Unique%20Word%20Abbreviation/README.md)", "`\u8bbe\u8ba1`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0288](https://leetcode.com/problems/unique-word-abbreviation)", "[Unique Word Abbreviation](/solution/0200-0299/0288.Unique%20Word%20Abbreviation/README_EN.md)", "`Design`,`Hash Table`", "Medium", "\ud83d\udd12"]}, {"question_id": "0287", "frontend_question_id": "0287", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-the-duplicate-number", "url_en": "https://leetcode.com/problems/find-the-duplicate-number", "relative_path_cn": "/solution/0200-0299/0287.Find%20the%20Duplicate%20Number/README.md", "relative_path_en": "/solution/0200-0299/0287.Find%20the%20Duplicate%20Number/README_EN.md", "title_cn": "\u5bfb\u627e\u91cd\u590d\u6570", "title_en": "Find the Duplicate Number", "question_title_slug": "find-the-duplicate-number", "content_en": "

    Given an array of integers nums containing n + 1 integers where each integer is in the range [1, n] inclusive.

    \n\n

    There is only one repeated number in nums, return this repeated number.

    \n\n

    You must solve the problem without modifying the array nums and uses only constant extra space.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [1,3,4,2,2]\nOutput: 2\n

    Example 2:

    \n
    Input: nums = [3,1,3,4,2]\nOutput: 3\n

    Example 3:

    \n
    Input: nums = [1,1]\nOutput: 1\n

    Example 4:

    \n
    Input: nums = [1,1,2]\nOutput: 1\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 105
    • \n\t
    • nums.length == n + 1
    • \n\t
    • 1 <= nums[i] <= n
    • \n\t
    • All the integers in nums appear only once except for precisely one integer which appears two or more times.
    • \n
    \n\n

     

    \n

    Follow up:

    \n\n
      \n\t
    • How can we prove that at least one duplicate number must exist in nums?
    • \n\t
    • Can you solve the problem in linear runtime complexity?
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5305\u542b\u00a0n + 1 \u4e2a\u6574\u6570\u7684\u6570\u7ec4\u00a0nums \uff0c\u5176\u6570\u5b57\u90fd\u5728 1 \u5230 n\u00a0\u4e4b\u95f4\uff08\u5305\u62ec 1 \u548c n\uff09\uff0c\u53ef\u77e5\u81f3\u5c11\u5b58\u5728\u4e00\u4e2a\u91cd\u590d\u7684\u6574\u6570\u3002

    \n\n

    \u5047\u8bbe nums \u53ea\u6709 \u4e00\u4e2a\u91cd\u590d\u7684\u6574\u6570 \uff0c\u627e\u51fa \u8fd9\u4e2a\u91cd\u590d\u7684\u6570 \u3002

    \n\n

    \u4f60\u8bbe\u8ba1\u7684\u89e3\u51b3\u65b9\u6848\u5fc5\u987b\u4e0d\u4fee\u6539\u6570\u7ec4 nums \u4e14\u53ea\u7528\u5e38\u91cf\u7ea7 O(1) \u7684\u989d\u5916\u7a7a\u95f4\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,3,4,2,2]\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [3,1,3,4,2]\n\u8f93\u51fa\uff1a3\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,1]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,1,2]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= n <= 105
    • \n\t
    • nums.length == n + 1
    • \n\t
    • 1 <= nums[i] <= n
    • \n\t
    • nums \u4e2d \u53ea\u6709\u4e00\u4e2a\u6574\u6570 \u51fa\u73b0 \u4e24\u6b21\u6216\u591a\u6b21 \uff0c\u5176\u4f59\u6574\u6570\u5747\u53ea\u51fa\u73b0 \u4e00\u6b21
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u5982\u4f55\u8bc1\u660e nums \u4e2d\u81f3\u5c11\u5b58\u5728\u4e00\u4e2a\u91cd\u590d\u7684\u6570\u5b57?
    • \n\t
    • \u4f60\u53ef\u4ee5\u8bbe\u8ba1\u4e00\u4e2a\u7ebf\u6027\u7ea7\u65f6\u95f4\u590d\u6742\u5ea6 O(n) \u7684\u89e3\u51b3\u65b9\u6848\u5417\uff1f
    • \n
    \n", "tags_en": ["Array", "Two Pointers", "Binary Search"], "tags_cn": ["\u6570\u7ec4", "\u53cc\u6307\u9488", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findDuplicate(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findDuplicate(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findDuplicate(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findDuplicate(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findDuplicate(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindDuplicate(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar findDuplicate = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef find_duplicate(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findDuplicate(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findDuplicate(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findDuplicate(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findDuplicate(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_duplicate(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function findDuplicate($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findDuplicate(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-duplicate nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0287](https://leetcode-cn.com/problems/find-the-duplicate-number)", "[\u5bfb\u627e\u91cd\u590d\u6570](/solution/0200-0299/0287.Find%20the%20Duplicate%20Number/README.md)", "`\u6570\u7ec4`,`\u53cc\u6307\u9488`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0287](https://leetcode.com/problems/find-the-duplicate-number)", "[Find the Duplicate Number](/solution/0200-0299/0287.Find%20the%20Duplicate%20Number/README_EN.md)", "`Array`,`Two Pointers`,`Binary Search`", "Medium", ""]}, {"question_id": "0286", "frontend_question_id": "0286", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/walls-and-gates", "url_en": "https://leetcode.com/problems/walls-and-gates", "relative_path_cn": "/solution/0200-0299/0286.Walls%20and%20Gates/README.md", "relative_path_en": "/solution/0200-0299/0286.Walls%20and%20Gates/README_EN.md", "title_cn": "\u5899\u4e0e\u95e8", "title_en": "Walls and Gates", "question_title_slug": "walls-and-gates", "content_en": "

    You are given an m x n grid rooms initialized with these three possible values.

    \n\n
      \n\t
    • -1 A wall or an obstacle.
    • \n\t
    • 0 A gate.
    • \n\t
    • INF Infinity means an empty room. We use the value 231 - 1 = 2147483647 to represent INF as you may assume that the distance to a gate is less than 2147483647.
    • \n
    \n\n

    Fill each empty room with the distance to its nearest gate. If it is impossible to reach a gate, it should be filled with INF.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: rooms = [[2147483647,-1,0,2147483647],[2147483647,2147483647,2147483647,-1],[2147483647,-1,2147483647,-1],[0,-1,2147483647,2147483647]]\nOutput: [[3,-1,0,1],[2,2,1,-1],[1,-1,2,-1],[0,-1,3,4]]\n
    \n\n

    Example 2:

    \n\n
    \nInput: rooms = [[-1]]\nOutput: [[-1]]\n
    \n\n

    Example 3:

    \n\n
    \nInput: rooms = [[2147483647]]\nOutput: [[2147483647]]\n
    \n\n

    Example 4:

    \n\n
    \nInput: rooms = [[0]]\nOutput: [[0]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == rooms.length
    • \n\t
    • n == rooms[i].length
    • \n\t
    • 1 <= m, n <= 250
    • \n\t
    • rooms[i][j] is -1, 0, or 231 - 1.
    • \n
    \n", "content_cn": "

    \u4f60\u88ab\u7ed9\u5b9a\u4e00\u4e2a\u00a0m \u00d7 n\u00a0\u7684\u4e8c\u7ef4\u7f51\u683c rooms \uff0c\u7f51\u683c\u4e2d\u6709\u4ee5\u4e0b\u4e09\u79cd\u53ef\u80fd\u7684\u521d\u59cb\u5316\u503c\uff1a

    \n\n
      \n\t
    1. -1\u00a0\u8868\u793a\u5899\u6216\u662f\u969c\u788d\u7269
    2. \n\t
    3. 0\u00a0\u8868\u793a\u4e00\u6247\u95e8
    4. \n\t
    5. INF\u00a0\u65e0\u9650\u8868\u793a\u4e00\u4e2a\u7a7a\u7684\u623f\u95f4\u3002\u7136\u540e\uff0c\u6211\u4eec\u7528\u00a0231 - 1 = 2147483647\u00a0\u4ee3\u8868\u00a0INF\u3002\u4f60\u53ef\u4ee5\u8ba4\u4e3a\u901a\u5f80\u95e8\u7684\u8ddd\u79bb\u603b\u662f\u5c0f\u4e8e\u00a02147483647\u00a0\u7684\u3002
    6. \n
    \n\n

    \u4f60\u8981\u7ed9\u6bcf\u4e2a\u7a7a\u623f\u95f4\u4f4d\u4e0a\u586b\u4e0a\u8be5\u623f\u95f4\u5230\u00a0\u6700\u8fd1\u95e8\u7684\u8ddd\u79bb \uff0c\u5982\u679c\u65e0\u6cd5\u5230\u8fbe\u95e8\uff0c\u5219\u586b\u00a0INF\u00a0\u5373\u53ef\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1arooms = [[2147483647,-1,0,2147483647],[2147483647,2147483647,2147483647,-1],[2147483647,-1,2147483647,-1],[0,-1,2147483647,2147483647]]\n\u8f93\u51fa\uff1a[[3,-1,0,1],[2,2,1,-1],[1,-1,2,-1],[0,-1,3,4]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1arooms = [[-1]]\n\u8f93\u51fa\uff1a[[-1]]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1arooms = [[2147483647]]\n\u8f93\u51fa\uff1a[[2147483647]]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1arooms = [[0]]\n\u8f93\u51fa\uff1a[[0]]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == rooms.length
    • \n\t
    • n == rooms[i].length
    • \n\t
    • 1 <= m, n <= 250
    • \n\t
    • rooms[i][j] \u662f -1\u30010 \u6216 231 - 1
    • \n
    \n", "tags_en": ["Breadth-first Search"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n void wallsAndGates(vector>& rooms) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public void wallsAndGates(int[][] rooms) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def wallsAndGates(self, rooms):\n \"\"\"\n :type rooms: List[List[int]]\n :rtype: None Do not return anything, modify rooms in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def wallsAndGates(self, rooms: List[List[int]]) -> None:\n \"\"\"\n Do not return anything, modify rooms in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nvoid wallsAndGates(int** rooms, int roomsSize, int* roomsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public void WallsAndGates(int[][] rooms) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} rooms\n * @return {void} Do not return anything, modify rooms in-place instead.\n */\nvar wallsAndGates = function(rooms) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} rooms\n# @return {Void} Do not return anything, modify rooms in-place instead.\ndef walls_and_gates(rooms)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func wallsAndGates(_ rooms: inout [[Int]]) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func wallsAndGates(rooms [][]int) {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def wallsAndGates(rooms: Array[Array[Int]]): Unit = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun wallsAndGates(rooms: Array): Unit {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn walls_and_gates(rooms: &mut Vec>) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $rooms\n * @return NULL\n */\n function wallsAndGates(&$rooms) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n Do not return anything, modify rooms in-place instead.\n */\nfunction wallsAndGates(rooms: number[][]): void {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0286](https://leetcode-cn.com/problems/walls-and-gates)", "[\u5899\u4e0e\u95e8](/solution/0200-0299/0286.Walls%20and%20Gates/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0286](https://leetcode.com/problems/walls-and-gates)", "[Walls and Gates](/solution/0200-0299/0286.Walls%20and%20Gates/README_EN.md)", "`Breadth-first Search`", "Medium", "\ud83d\udd12"]}, {"question_id": "0285", "frontend_question_id": "0285", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/inorder-successor-in-bst", "url_en": "https://leetcode.com/problems/inorder-successor-in-bst", "relative_path_cn": "/solution/0200-0299/0285.Inorder%20Successor%20in%20BST/README.md", "relative_path_en": "/solution/0200-0299/0285.Inorder%20Successor%20in%20BST/README_EN.md", "title_cn": "\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u7684\u4e2d\u5e8f\u540e\u7ee7", "title_en": "Inorder Successor in BST", "question_title_slug": "inorder-successor-in-bst", "content_en": "

    Given the root of a binary search tree and a node p in it, return the in-order successor of that node in the BST. If the given node has no in-order successor in the tree, return null.

    \n\n

    The successor of a node p is the node with the smallest key greater than p.val.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [2,1,3], p = 1\nOutput: 2\nExplanation: 1's in-order successor node is 2. Note that both p and the return value is of TreeNode type.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [5,3,6,2,4,null,null,1], p = 6\nOutput: null\nExplanation: There is no in-order successor of the current node, so the answer is null.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 104].
    • \n\t
    • -105 <= Node.val <= 105
    • \n\t
    • All Nodes will have unique values.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u68f5\u4e8c\u53c9\u641c\u7d22\u6811\u548c\u5176\u4e2d\u7684\u4e00\u4e2a\u8282\u70b9 p \uff0c\u627e\u5230\u8be5\u8282\u70b9\u5728\u6811\u4e2d\u7684\u4e2d\u5e8f\u540e\u7ee7\u3002\u5982\u679c\u8282\u70b9\u6ca1\u6709\u4e2d\u5e8f\u540e\u7ee7\uff0c\u8bf7\u8fd4\u56de null \u3002

    \n\n

    \u8282\u70b9\u00a0p\u00a0\u7684\u540e\u7ee7\u662f\u503c\u6bd4\u00a0p.val\u00a0\u5927\u7684\u8282\u70b9\u4e2d\u952e\u503c\u6700\u5c0f\u7684\u8282\u70b9\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aroot = [2,1,3], p = 1\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u8fd9\u91cc 1 \u7684\u4e2d\u5e8f\u540e\u7ee7\u662f 2\u3002\u8bf7\u6ce8\u610f p \u548c\u8fd4\u56de\u503c\u90fd\u5e94\u662f TreeNode \u7c7b\u578b\u3002\n
    \n\n

    \u793a\u4f8b\u00a02\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aroot = [5,3,6,2,4,null,null,1], p = 6\n\u8f93\u51fa\uff1anull\n\u89e3\u91ca\uff1a\u56e0\u4e3a\u7ed9\u51fa\u7684\u8282\u70b9\u6ca1\u6709\u4e2d\u5e8f\u540e\u7ee7\uff0c\u6240\u4ee5\u7b54\u6848\u5c31\u8fd4\u56de null \u4e86\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u7684\u6570\u76ee\u5728\u8303\u56f4 [1, 104] \u5185\u3002
    • \n\t
    • -105 <= Node.val <= 105
    • \n\t
    • \u6811\u4e2d\u5404\u8282\u70b9\u7684\u503c\u5747\u4fdd\u8bc1\u552f\u4e00\u3002
    • \n
    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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 */\nclass Solution {\npublic:\n TreeNode* inorderSuccessor(TreeNode* root, TreeNode* p) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode(int x) { val = x; }\n * }\n */\nclass Solution {\n public TreeNode inorderSuccessor(TreeNode root, TreeNode p) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution(object):\n def inorderSuccessor(self, root, p):\n \"\"\"\n :type root: TreeNode\n :type p: TreeNode\n :rtype: TreeNode\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution:\n def inorderSuccessor(self, root: 'TreeNode', p: 'TreeNode') -> 'TreeNode':\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\nstruct TreeNode* inorderSuccessor(struct TreeNode* root, struct TreeNode* p) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int x) { val = x; }\n * }\n */\npublic class Solution {\n public TreeNode InorderSuccessor(TreeNode root, TreeNode p) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val) {\n * this.val = val;\n * this.left = this.right = null;\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {TreeNode} p\n * @return {TreeNode}\n */\nvar inorderSuccessor = function(root, p) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val)\n# @val = val\n# @left, @right = nil, nil\n# end\n# end\n\n# @param {TreeNode} root\n# @param {TreeNode} p\n# @return {TreeNode}\ndef inorder_successor(root, p)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.left = nil\n * self.right = nil\n * }\n * }\n */\n\nclass Solution {\n func inorderSuccessor(_ root: TreeNode?, _ p: TreeNode?) -> TreeNode? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc inorderSuccessor(root *TreeNode, p *TreeNode) *TreeNode {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(var _value: Int) {\n * var value: Int = _value\n * var left: TreeNode = null\n * var right: TreeNode = null\n * }\n */\n\nobject Solution {\n def inorderSuccessor(root: TreeNode, p: TreeNode): TreeNode = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int = 0) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\n\nclass Solution {\n fun inorderSuccessor(root: TreeNode?, p: TreeNode?): TreeNode? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n// \n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn inorder_successor(root: Option>>, p: Option>>) -> Option>> {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($value) { $this->val = $value; }\n * }\n */\n\nclass Solution {\n /**\n * @param TreeNode $root\n * @param TreeNode $p\n * @return TreeNode\n */\n function inorderSuccessor($root, $p) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction inorderSuccessor(root: TreeNode | null, p: TreeNode | null): TreeNode | null {\n\t\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0285](https://leetcode-cn.com/problems/inorder-successor-in-bst)", "[\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u7684\u4e2d\u5e8f\u540e\u7ee7](/solution/0200-0299/0285.Inorder%20Successor%20in%20BST/README.md)", "`\u6811`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0285](https://leetcode.com/problems/inorder-successor-in-bst)", "[Inorder Successor in BST](/solution/0200-0299/0285.Inorder%20Successor%20in%20BST/README_EN.md)", "`Tree`", "Medium", "\ud83d\udd12"]}, {"question_id": "0284", "frontend_question_id": "0284", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/peeking-iterator", "url_en": "https://leetcode.com/problems/peeking-iterator", "relative_path_cn": "/solution/0200-0299/0284.Peeking%20Iterator/README.md", "relative_path_en": "/solution/0200-0299/0284.Peeking%20Iterator/README_EN.md", "title_cn": "\u9876\u7aef\u8fed\u4ee3\u5668", "title_en": "Peeking Iterator", "question_title_slug": "peeking-iterator", "content_en": "

    Design an iterator that supports the peek operation on a list in addition to the hasNext and the next operations.

    \n\n

    Implement the PeekingIterator class:

    \n\n
      \n\t
    • PeekingIterator(int[] nums) Initializes the object with the given integer array nums.
    • \n\t
    • int next() Returns the next element in the array and moves the pointer to the next element.
    • \n\t
    • bool hasNext() Returns true if there are still elements in the array.
    • \n\t
    • int peek() Returns the next element in the array without moving the pointer.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["PeekingIterator", "next", "peek", "next", "next", "hasNext"]\n[[[1, 2, 3]], [], [], [], [], []]\nOutput\n[null, 1, 2, 2, 3, false]\n\nExplanation\nPeekingIterator peekingIterator = new PeekingIterator([1, 2, 3]); // [1,2,3]\npeekingIterator.next();    // return 1, the pointer moves to the next element [1,2,3].\npeekingIterator.peek();    // return 2, the pointer does not move [1,2,3].\npeekingIterator.next();    // return 2, the pointer moves to the next element [1,2,3]\npeekingIterator.next();    // return 3, the pointer moves to the next element [1,2,3]\npeekingIterator.hasNext(); // return False\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 1000
    • \n\t
    • 1 <= nums[i] <= 1000
    • \n\t
    • All the calls to next and peek are valid.
    • \n\t
    • At most 1000 calls will be made to next, hasNext, and peek.
    • \n
    \n\n

     

    \nFollow up: How would you extend your design to be generic and work with all types, not just integer?", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u8fed\u4ee3\u5668\u7c7b\u7684\u63a5\u53e3\uff0c\u63a5\u53e3\u5305\u542b\u4e24\u4e2a\u65b9\u6cd5\uff1a next() \u548c hasNext()\u3002\u8bbe\u8ba1\u5e76\u5b9e\u73b0\u4e00\u4e2a\u652f\u6301 peek() \u64cd\u4f5c\u7684\u9876\u7aef\u8fed\u4ee3\u5668 -- \u5176\u672c\u8d28\u5c31\u662f\u628a\u539f\u672c\u5e94\u7531 next() \u65b9\u6cd5\u8fd4\u56de\u7684\u5143\u7d20 peek() \u51fa\u6765\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u5047\u8bbe\u8fed\u4ee3\u5668\u88ab\u521d\u59cb\u5316\u4e3a\u5217\u8868 [1,2,3]\u3002\n\n\u8c03\u7528 next() \u8fd4\u56de 1\uff0c\u5f97\u5230\u5217\u8868\u4e2d\u7684\u7b2c\u4e00\u4e2a\u5143\u7d20\u3002\n\u73b0\u5728\u8c03\u7528 peek() \u8fd4\u56de 2\uff0c\u4e0b\u4e00\u4e2a\u5143\u7d20\u3002\u5728\u6b64\u4e4b\u540e\u8c03\u7528 next() \u4ecd\u7136\u8fd4\u56de 2\u3002\n\u6700\u540e\u4e00\u6b21\u8c03\u7528 next() \u8fd4\u56de 3\uff0c\u672b\u5c3e\u5143\u7d20\u3002\u5728\u6b64\u4e4b\u540e\u8c03\u7528 hasNext() \u5e94\u8be5\u8fd4\u56de false\u3002\n
    \n\n

    \u8fdb\u9636\uff1a\u4f60\u5c06\u5982\u4f55\u62d3\u5c55\u4f60\u7684\u8bbe\u8ba1\uff1f\u4f7f\u4e4b\u53d8\u5f97\u901a\u7528\u5316\uff0c\u4ece\u800c\u9002\u5e94\u6240\u6709\u7684\u7c7b\u578b\uff0c\u800c\u4e0d\u53ea\u662f\u6574\u6570\u578b\uff1f

    \n", "tags_en": ["Design"], "tags_cn": ["\u8bbe\u8ba1"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n * Below is the interface for Iterator, which is already defined for you.\n * **DO NOT** modify the interface for Iterator.\n *\n * class Iterator {\n *\t\tstruct Data;\n * \t\tData* data;\n * public:\n *\t\tIterator(const vector& nums);\n * \t\tIterator(const Iterator& iter);\n *\n * \t\t// Returns the next element in the iteration.\n *\t\tint next();\n *\n *\t\t// Returns true if the iteration has more elements.\n *\t\tbool hasNext() const;\n *\t};\n */\n\nclass PeekingIterator : public Iterator {\npublic:\n\tPeekingIterator(const vector& nums) : Iterator(nums) {\n\t // Initialize any member here.\n\t // **DO NOT** save a copy of nums and manipulate it directly.\n\t // You should only use the Iterator interface methods.\n\t \n\t}\n\t\n // Returns the next element in the iteration without advancing the iterator.\n\tint peek() {\n \n\t}\n\t\n\t// hasNext() and next() should behave the same as in the Iterator interface.\n\t// Override them if needed.\n\tint next() {\n\t \n\t}\n\t\n\tbool hasNext() const {\n\t \n\t}\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "// Java Iterator interface reference:\n// https://docs.oracle.com/javase/8/docs/api/java/util/Iterator.html\n\nclass PeekingIterator implements Iterator {\n\tpublic PeekingIterator(Iterator iterator) {\n\t // initialize any member here.\n\t \n\t}\n\t\n // Returns the next element in the iteration without advancing the iterator.\n\tpublic Integer peek() {\n \n\t}\n\t\n\t// hasNext() and next() should behave the same as in the Iterator interface.\n\t// Override them if needed.\n\t@Override\n\tpublic Integer next() {\n\t \n\t}\n\t\n\t@Override\n\tpublic boolean hasNext() {\n\t \n\t}\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Below is the interface for Iterator, which is already defined for you.\n#\n# class Iterator(object):\n# def __init__(self, nums):\n# \"\"\"\n# Initializes an iterator object to the beginning of a list.\n# :type nums: List[int]\n# \"\"\"\n#\n# def hasNext(self):\n# \"\"\"\n# Returns true if the iteration has more elements.\n# :rtype: bool\n# \"\"\"\n#\n# def next(self):\n# \"\"\"\n# Returns the next element in the iteration.\n# :rtype: int\n# \"\"\"\n\nclass PeekingIterator(object):\n def __init__(self, iterator):\n \"\"\"\n Initialize your data structure here.\n :type iterator: Iterator\n \"\"\"\n \n\n def peek(self):\n \"\"\"\n Returns the next element in the iteration without advancing the iterator.\n :rtype: int\n \"\"\"\n \n\n def next(self):\n \"\"\"\n :rtype: int\n \"\"\"\n \n\n def hasNext(self):\n \"\"\"\n :rtype: bool\n \"\"\"\n \n\n# Your PeekingIterator object will be instantiated and called as such:\n# iter = PeekingIterator(Iterator(nums))\n# while iter.hasNext():\n# val = iter.peek() # Get the next element but not advance the iterator.\n# iter.next() # Should return the same value as [val].", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Below is the interface for Iterator, which is already defined for you.\n#\n# class Iterator:\n# def __init__(self, nums):\n# \"\"\"\n# Initializes an iterator object to the beginning of a list.\n# :type nums: List[int]\n# \"\"\"\n#\n# def hasNext(self):\n# \"\"\"\n# Returns true if the iteration has more elements.\n# :rtype: bool\n# \"\"\"\n#\n# def next(self):\n# \"\"\"\n# Returns the next element in the iteration.\n# :rtype: int\n# \"\"\"\n\nclass PeekingIterator:\n def __init__(self, iterator):\n \"\"\"\n Initialize your data structure here.\n :type iterator: Iterator\n \"\"\"\n \n\n def peek(self):\n \"\"\"\n Returns the next element in the iteration without advancing the iterator.\n :rtype: int\n \"\"\"\n \n\n def next(self):\n \"\"\"\n :rtype: int\n \"\"\"\n \n\n def hasNext(self):\n \"\"\"\n :rtype: bool\n \"\"\"\n \n\n# Your PeekingIterator object will be instantiated and called as such:\n# iter = PeekingIterator(Iterator(nums))\n# while iter.hasNext():\n# val = iter.peek() # Get the next element but not advance the iterator.\n# iter.next() # Should return the same value as [val].", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/*\n *\tstruct Iterator {\n *\t\t// Returns true if the iteration has more elements.\n *\t\tbool (*hasNext)();\n *\n * \t\t// Returns the next element in the iteration.\n *\t\tint (*next)();\n *\t};\n */\n\nstruct PeekingIterator {\n \n};\n\nstruct PeekingIterator* Constructor(struct Iterator* iter) {\n struct PeekingIterator* piter = malloc(sizeof(struct PeekingIterator));\n piter->iterator = iter;\n piter->hasPeeked = false;\n return piter;\n}\n\nint peek(struct PeekingIterator* obj) {\n \n}\n\nint next(struct PeekingIterator* obj) {\n \n}\n\nbool hasNext(struct PeekingIterator* obj) {\n \n}\n\n/**\n * Your PeekingIterator struct will be instantiated and called as such:\n * PeekingIterator* obj = peekingIteratorCreate(arr, arrSize);\n * int param_1 = peek(obj);\n * int param_2 = next(obj);\n * bool param_3 = hasNext(obj);\n * peekingIteratorFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "// C# IEnumerator interface reference:\n// https://docs.microsoft.com/en-us/dotnet/api/system.collections.ienumerator?view=netframework-4.8\n\nclass PeekingIterator {\n // iterators refers to the first element of the array.\n public PeekingIterator(IEnumerator iterator) {\n // initialize any member here.\n }\n \n // Returns the next element in the iteration without advancing the iterator.\n public int Peek() {\n \n }\n \n // Returns the next element in the iteration and advances the iterator.\n public int Next() {\n \n }\n \n // Returns false if the iterator is refering to the end of the array of true otherwise.\n public bool HasNext() {\n\t\t\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // This is the Iterator's API interface.\n * // You should not implement it, or speculate about its implementation.\n * function Iterator() {\n * @ return {number}\n * this.next = function() { // return the next number of the iterator\n * ...\n * }; \n *\n * @return {boolean}\n * this.hasNext = function() { // return true if it still has numbers\n * ...\n * };\n * };\n */\n\n/**\n * @param {Iterator} iterator\n */\nvar PeekingIterator = function(iterator) {\n \n};\n\n/**\n * @return {number}\n */\nPeekingIterator.prototype.peek = function() {\n \n};\n\n/**\n * @return {number}\n */\nPeekingIterator.prototype.next = function() {\n \n};\n\n/**\n * @return {boolean}\n */\nPeekingIterator.prototype.hasNext = function() {\n \n};\n\n/** \n * Your PeekingIterator object will be instantiated and called as such:\n * var obj = new PeekingIterator(arr)\n * var param_1 = obj.peek()\n * var param_2 = obj.next()\n * var param_3 = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Below is the interface for Iterator, which is already defined for you.\n#\n# class Iterator\n# \tdef initialize(v)\n# \n# end\n#\n# def hasNext()\n#\t\tReturns true if the iteration has more elements.\n# end\n#\n# def next()\n# \tReturns the next element in the iteration.\n# end\n# end\n\nclass PeekingIterator\n # @param {Iterator} iter\n def initialize(iter)\n \t\n end\n \n # Returns true if the iteration has more elements.\n # @return {boolean}\n def hasNext()\n \t\n end\n \n # Returns the next element in the iteration.\n # @return {integer}\n def next()\n \t\n end\n \n # Returns the next element in the iteration without advancing the iterator.\n # @return {integer}\n def peek()\n \t\n end\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "// Swift IndexingIterator refernence:\n// https://developer.apple.com/documentation/swift/indexingiterator\n\nclass PeekingIterator {\n init(_ arr: IndexingIterator>) {\n \n }\n \n func next() -> Int {\n \n }\n \n func peek() -> Int {\n \n }\n \n func hasNext() -> Bool {\n \n }\n}\n\n/**\n * Your PeekingIterator object will be instantiated and called as such:\n * let obj = PeekingIterator(arr)\n * let ret_1: Int = obj.next()\n * let ret_2: Int = obj.peek()\n * let ret_3: Bool = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/* Below is the interface for Iterator, which is already defined for you.\n *\n * type Iterator struct {\n * \n * }\n *\n * func (this *Iterator) hasNext() bool {\n *\t\t// Returns true if the iteration has more elements.\n * }\n *\n * func (this *Iterator) next() int {\n *\t\t// Returns the next element in the iteration.\n * }\n */\n\ntype PeekingIterator struct {\n \n}\n\nfunc Constructor(iter *Iterator) *PeekingIterator {\n \n}\n\nfunc (this *PeekingIterator) hasNext() bool {\n \n}\n\nfunc (this *PeekingIterator) next() int {\n \n}\n\nfunc (this *PeekingIterator) peek() int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "// Scala Iterator reference:\n// https://www.scala-lang.org/api/2.12.2/scala/collection/Iterator.html\n\nclass PeekingIterator(_iterator: Iterator[Int]) {\n def peek(): Int = {\n \n }\n \n def next(): Int = {\n \n }\n \n def hasNext(): Boolean = {\n \n }\n}\n\n/**\n * Your PeekingIterator object will be instantiated and called as such:\n * var obj = new PeekingIterator(arr)\n * var param_1 = obj.next()\n * var param_2 = obj.peek()\n * var param_3 = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "// Kotlin Iterator reference:\n// https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-iterator/\n\nclass PeekingIterator(iterator:Iterator):Iterator {\n fun peek(): Int {\n \t\n }\n \n override fun next(): Int {\n \n }\n \n override fun hasNext(): Boolean {\n \n }\n}\n\n/**\n * Your PeekingIterator object will be instantiated and called as such:\n * var obj = PeekingIterator(arr)\n * var param_1 = obj.next()\n * var param_2 = obj.peek()\n * var param_3 = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "// PHP ArrayIterator reference:\n// https://www.php.net/arrayiterator\n\nclass PeekingIterator {\n /**\n * @param ArrayIterator $arr\n */\n function __construct($arr) {\n \n }\n \n /**\n * @return Integer\n */\n function next() {\n \n }\n \n /**\n * @return Integer\n */\n function peek() {\n \n }\n \n /**\n * @return Boolean\n */\n function hasNext() {\n \n }\n}\n\n/**\n * Your PeekingIterator object will be instantiated and called as such:\n * $obj = PeekingIterator($arr);\n * $ret_1 = $obj->next();\n * $ret_2 = $obj->peek();\n * $ret_3 = $obj->hasNext();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * // This is the Iterator's API interface.\n * // You should not implement it, or speculate about its implementation\n * class Iterator {\n * hasNext(): boolean {}\n *\n * next(): number {}\n * }\n */\n\nclass PeekingIterator {\n constructor(iterator: Iterator) {\n\n }\n\n peek(): number {\n\n }\n\n next(): number {\n\n }\n\n hasNext(): boolean {\n\n }\n}\n\n/**\n * Your PeekingIterator object will be instantiated and called as such:\n * var obj = new PeekingIterator(iterator)\n * var param_1 = obj.peek()\n * var param_2 = obj.next()\n * var param_3 = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0284](https://leetcode-cn.com/problems/peeking-iterator)", "[\u9876\u7aef\u8fed\u4ee3\u5668](/solution/0200-0299/0284.Peeking%20Iterator/README.md)", "`\u8bbe\u8ba1`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0284](https://leetcode.com/problems/peeking-iterator)", "[Peeking Iterator](/solution/0200-0299/0284.Peeking%20Iterator/README_EN.md)", "`Design`", "Medium", ""]}, {"question_id": "0283", "frontend_question_id": "0283", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/move-zeroes", "url_en": "https://leetcode.com/problems/move-zeroes", "relative_path_cn": "/solution/0200-0299/0283.Move%20Zeroes/README.md", "relative_path_en": "/solution/0200-0299/0283.Move%20Zeroes/README_EN.md", "title_cn": "\u79fb\u52a8\u96f6", "title_en": "Move Zeroes", "question_title_slug": "move-zeroes", "content_en": "

    Given an integer array nums, move all 0's to the end of it while maintaining the relative order of the non-zero elements.

    \n\n

    Note that you must do this in-place without making a copy of the array.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [0,1,0,3,12]\nOutput: [1,3,12,0,0]\n

    Example 2:

    \n
    Input: nums = [0]\nOutput: [0]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 104
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n
    \n\n

     

    \nFollow up: Could you minimize the total number of operations done?", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6570\u7ec4 nums\uff0c\u7f16\u5199\u4e00\u4e2a\u51fd\u6570\u5c06\u6240\u6709 0 \u79fb\u52a8\u5230\u6570\u7ec4\u7684\u672b\u5c3e\uff0c\u540c\u65f6\u4fdd\u6301\u975e\u96f6\u5143\u7d20\u7684\u76f8\u5bf9\u987a\u5e8f\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: [0,1,0,3,12]\n\u8f93\u51fa: [1,3,12,0,0]
    \n\n

    \u8bf4\u660e:

    \n\n
      \n\t
    1. \u5fc5\u987b\u5728\u539f\u6570\u7ec4\u4e0a\u64cd\u4f5c\uff0c\u4e0d\u80fd\u62f7\u8d1d\u989d\u5916\u7684\u6570\u7ec4\u3002
    2. \n\t
    3. \u5c3d\u91cf\u51cf\u5c11\u64cd\u4f5c\u6b21\u6570\u3002
    4. \n
    \n", "tags_en": ["Array", "Two Pointers"], "tags_cn": ["\u6570\u7ec4", "\u53cc\u6307\u9488"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n void moveZeroes(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public void moveZeroes(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def moveZeroes(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: None Do not return anything, modify nums in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def moveZeroes(self, nums: List[int]) -> None:\n \"\"\"\n Do not return anything, modify nums in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nvoid moveZeroes(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public void MoveZeroes(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {void} Do not return anything, modify nums in-place instead.\n */\nvar moveZeroes = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Void} Do not return anything, modify nums in-place instead.\ndef move_zeroes(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func moveZeroes(_ nums: inout [Int]) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func moveZeroes(nums []int) {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def moveZeroes(nums: Array[Int]): Unit = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun moveZeroes(nums: IntArray): Unit {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn move_zeroes(nums: &mut Vec) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return NULL\n */\n function moveZeroes(&$nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n Do not return anything, modify nums in-place instead.\n */\nfunction moveZeroes(nums: number[]): void {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (move-zeroes nums)\n (-> (listof exact-integer?) void?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0283](https://leetcode-cn.com/problems/move-zeroes)", "[\u79fb\u52a8\u96f6](/solution/0200-0299/0283.Move%20Zeroes/README.md)", "`\u6570\u7ec4`,`\u53cc\u6307\u9488`", "\u7b80\u5355", ""], "md_table_row_en": ["[0283](https://leetcode.com/problems/move-zeroes)", "[Move Zeroes](/solution/0200-0299/0283.Move%20Zeroes/README_EN.md)", "`Array`,`Two Pointers`", "Easy", ""]}, {"question_id": "0282", "frontend_question_id": "0282", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/expression-add-operators", "url_en": "https://leetcode.com/problems/expression-add-operators", "relative_path_cn": "/solution/0200-0299/0282.Expression%20Add%20Operators/README.md", "relative_path_en": "/solution/0200-0299/0282.Expression%20Add%20Operators/README_EN.md", "title_cn": "\u7ed9\u8868\u8fbe\u5f0f\u6dfb\u52a0\u8fd0\u7b97\u7b26", "title_en": "Expression Add Operators", "question_title_slug": "expression-add-operators", "content_en": "

    Given a string num that contains only digits and an integer target, return all possibilities to add the binary operators '+', '-', or '*' between the digits of num so that the resultant expression evaluates to the target value.

    \n\n

     

    \n

    Example 1:

    \n
    Input: num = \"123\", target = 6\nOutput: [\"1*2*3\",\"1+2+3\"]\n

    Example 2:

    \n
    Input: num = \"232\", target = 8\nOutput: [\"2*3+2\",\"2+3*2\"]\n

    Example 3:

    \n
    Input: num = \"105\", target = 5\nOutput: [\"1*0+5\",\"10-5\"]\n

    Example 4:

    \n
    Input: num = \"00\", target = 0\nOutput: [\"0*0\",\"0+0\",\"0-0\"]\n

    Example 5:

    \n
    Input: num = \"3456237490\", target = 9191\nOutput: []\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= num.length <= 10
    • \n\t
    • num consists of only digits.
    • \n\t
    • -231 <= target <= 231 - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4ec5\u5305\u542b\u6570\u5b57\u00a00-9\u00a0\u7684\u5b57\u7b26\u4e32\u548c\u4e00\u4e2a\u76ee\u6807\u503c\uff0c\u5728\u6570\u5b57\u4e4b\u95f4\u6dfb\u52a0 \u4e8c\u5143 \u8fd0\u7b97\u7b26\uff08\u4e0d\u662f\u4e00\u5143\uff09+\u3001-\u00a0\u6216\u00a0*\u00a0\uff0c\u8fd4\u56de\u6240\u6709\u80fd\u591f\u5f97\u5230\u76ee\u6807\u503c\u7684\u8868\u8fbe\u5f0f\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: num = \"123\", target = 6\n\u8f93\u51fa: [\"1+2+3\", \"1*2*3\"] \n
    \n\n

    \u793a\u4f8b\u00a02:

    \n\n
    \n\u8f93\u5165: num = \"232\", target = 8\n\u8f93\u51fa: [\"2*3+2\", \"2+3*2\"]
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \n\u8f93\u5165: num = \"105\", target = 5\n\u8f93\u51fa: [\"1*0+5\",\"10-5\"]
    \n\n

    \u793a\u4f8b\u00a04:

    \n\n
    \n\u8f93\u5165: num = \"00\", target = 0\n\u8f93\u51fa: [\"0+0\", \"0-0\", \"0*0\"]\n
    \n\n

    \u793a\u4f8b 5:

    \n\n
    \n\u8f93\u5165: num = \"3456237490\", target = 9191\n\u8f93\u51fa: []
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= num.length <= 10
    • \n\t
    • num \u4ec5\u542b\u6570\u5b57
    • \n
    \n", "tags_en": ["Divide and Conquer"], "tags_cn": ["\u5206\u6cbb\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector addOperators(string num, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List addOperators(String num, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def addOperators(self, num, target):\n \"\"\"\n :type num: str\n :type target: int\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def addOperators(self, num: str, target: int) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** addOperators(char * num, int target, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList AddOperators(string num, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} num\n * @param {number} target\n * @return {string[]}\n */\nvar addOperators = function(num, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} num\n# @param {Integer} target\n# @return {String[]}\ndef add_operators(num, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func addOperators(_ num: String, _ target: Int) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func addOperators(num string, target int) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def addOperators(num: String, target: Int): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun addOperators(num: String, target: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn add_operators(num: String, target: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $num\n * @param Integer $target\n * @return String[]\n */\n function addOperators($num, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function addOperators(num: string, target: number): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (add-operators num target)\n (-> string? exact-integer? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0282](https://leetcode-cn.com/problems/expression-add-operators)", "[\u7ed9\u8868\u8fbe\u5f0f\u6dfb\u52a0\u8fd0\u7b97\u7b26](/solution/0200-0299/0282.Expression%20Add%20Operators/README.md)", "`\u5206\u6cbb\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[0282](https://leetcode.com/problems/expression-add-operators)", "[Expression Add Operators](/solution/0200-0299/0282.Expression%20Add%20Operators/README_EN.md)", "`Divide and Conquer`", "Hard", ""]}, {"question_id": "0281", "frontend_question_id": "0281", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/zigzag-iterator", "url_en": "https://leetcode.com/problems/zigzag-iterator", "relative_path_cn": "/solution/0200-0299/0281.Zigzag%20Iterator/README.md", "relative_path_en": "/solution/0200-0299/0281.Zigzag%20Iterator/README_EN.md", "title_cn": "\u952f\u9f7f\u8fed\u4ee3\u5668", "title_en": "Zigzag Iterator", "question_title_slug": "zigzag-iterator", "content_en": "

    Given two vectors of integers v1 and v2, implement an iterator to return their elements alternately.

    \n\n

    Implement the ZigzagIterator class:

    \n\n
      \n\t
    • ZigzagIterator(List<int> v1, List<int> v2) initializes the object with the two vectors v1 and v2.
    • \n\t
    • boolean hasNext() returns true if the iterator still has elements, and false otherwise.
    • \n\t
    • int next() returns the current element of the iterator and moves the iterator to the next element.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: v1 = [1,2], v2 = [3,4,5,6]\nOutput: [1,3,2,4,5,6]\nExplanation: By calling next repeatedly until hasNext returns false, the order of elements returned by next should be: [1,3,2,4,5,6].\n
    \n\n

    Example 2:

    \n\n
    \nInput: v1 = [1], v2 = []\nOutput: [1]\n
    \n\n

    Example 3:

    \n\n
    \nInput: v1 = [], v2 = [1]\nOutput: [1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= v1.length, v2.length <= 1000
    • \n\t
    • 1 <= v1.length + v2.length <= 2000
    • \n\t
    • -231 <= v1[i], v2[i] <= 231 - 1
    • \n
    \n\n

     

    \n

    Follow up: What if you are given k vectors? How well can your code be extended to such cases?

    \n\n

    Clarification for the follow-up question:

    \n\n

    The "Zigzag" order is not clearly defined and is ambiguous for k > 2 cases. If "Zigzag" does not look right to you, replace "Zigzag" with "Cyclic".

    \n\n

    Example:

    \n\n
    \nInput: v1 = [1,2,3], v2 = [4,5,6,7], v3 = [8,9]\nOutput: [1,4,8,2,5,9,3,6,7]\n
    \n", "content_cn": "

    \u7ed9\u51fa\u4e24\u4e2a\u4e00\u7ef4\u7684\u5411\u91cf\uff0c\u8bf7\u4f60\u5b9e\u73b0\u4e00\u4e2a\u8fed\u4ee3\u5668\uff0c\u4ea4\u66ff\u8fd4\u56de\u5b83\u4eec\u4e2d\u95f4\u7684\u5143\u7d20\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165:\nv1 = [1,2]\nv2 = [3,4,5,6] \n\n\u8f93\u51fa: [1,3,2,4,5,6]\n\n\u89e3\u6790: \u901a\u8fc7\u8fde\u7eed\u8c03\u7528 next \u51fd\u6570\u76f4\u5230 hasNext \u51fd\u6570\u8fd4\u56de false\uff0c\n     next \u51fd\u6570\u8fd4\u56de\u503c\u7684\u6b21\u5e8f\u5e94\u4f9d\u6b21\u4e3a: [1,3,2,4,5,6]\u3002
    \n\n

    \u62d3\u5c55\uff1a\u5047\u5982\u7ed9\u4f60 k \u4e2a\u4e00\u7ef4\u5411\u91cf\u5462\uff1f\u4f60\u7684\u4ee3\u7801\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\u7684\u6269\u5c55\u6027\u53c8\u4f1a\u5982\u4f55\u5462?

    \n\n

    \u62d3\u5c55\u58f0\u660e\uff1a
    \n “\u952f\u9f7f” \u987a\u5e8f\u5bf9\u4e8e k > 2 \u7684\u60c5\u51b5\u5b9a\u4e49\u53ef\u80fd\u4f1a\u6709\u4e9b\u6b67\u4e49\u3002\u6240\u4ee5\uff0c\u5047\u5982\u4f60\u89c9\u5f97 “\u952f\u9f7f” \u8fd9\u4e2a\u8868\u8ff0\u4e0d\u59a5\uff0c\u4e5f\u53ef\u4ee5\u8ba4\u4e3a\u8fd9\u662f\u4e00\u79cd “\u5faa\u73af”\u3002\u4f8b\u5982\uff1a

    \n\n
    \u8f93\u5165:\n[1,2,3]\n[4,5,6,7]\n[8,9]\n\n\u8f93\u51fa: [1,4,8,2,5,9,3,6,7].\n
    \n", "tags_en": ["Design"], "tags_cn": ["\u8bbe\u8ba1"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class ZigzagIterator {\npublic:\n ZigzagIterator(vector& v1, vector& v2) {\n \n }\n\n int next() {\n \n }\n\n bool hasNext() {\n \n }\n};\n\n/**\n * Your ZigzagIterator object will be instantiated and called as such:\n * ZigzagIterator i(v1, v2);\n * while (i.hasNext()) cout << i.next();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "public class ZigzagIterator {\n\n public ZigzagIterator(List v1, List v2) {\n \n }\n\n public int next() {\n \n }\n\n public boolean hasNext() {\n \n }\n}\n\n/**\n * Your ZigzagIterator object will be instantiated and called as such:\n * ZigzagIterator i = new ZigzagIterator(v1, v2);\n * while (i.hasNext()) v[f()] = i.next();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class ZigzagIterator(object):\n\n def __init__(self, v1, v2):\n \"\"\"\n Initialize your data structure here.\n :type v1: List[int]\n :type v2: List[int]\n \"\"\"\n \n\n def next(self):\n \"\"\"\n :rtype: int\n \"\"\"\n \n\n def hasNext(self):\n \"\"\"\n :rtype: bool\n \"\"\"\n \n\n# Your ZigzagIterator object will be instantiated and called as such:\n# i, v = ZigzagIterator(v1, v2), []\n# while i.hasNext(): v.append(i.next())", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class ZigzagIterator:\n def __init__(self, v1: List[int], v2: List[int]):\n \n\n def next(self) -> int:\n \n\n def hasNext(self) -> bool:\n \n\n# Your ZigzagIterator object will be instantiated and called as such:\n# i, v = ZigzagIterator(v1, v2), []\n# while i.hasNext(): v.append(i.next())", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "struct ZigzagIterator {\n \n};\n\nstruct ZigzagIterator *zigzagIteratorCreate(int* v1, int v1Size, int* v2, int v2Size) {\n \n}\n\nbool zigzagIteratorHasNext(struct ZigzagIterator *iter) {\n \n}\n\nint zigzagIteratorNext(struct ZigzagIterator *iter) {\n \n}\n\n/** Deallocates memory previously allocated for the iterator */\nvoid zigzagIteratorFree(struct ZigzagIterator *iter) {\n \n}\n\n/**\n * Your ZigzagIterator will be called like this:\n * struct ZigzagIterator *i = zigzagIteratorCreate(v1, v1Size, v2, v2Size);\n * while (zigzagIteratorHasNext(i)) printf(\"%d\\n\", zigzagIteratorNext(i));\n * zigzagIteratorFree(i);\n */", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class ZigzagIterator {\n\n public ZigzagIterator(IList v1, IList v2) {\n \n }\n\n public bool HasNext() {\n \n }\n\n public int Next() {\n \n }\n}\n\n/**\n * Your ZigzagIterator will be called like this:\n * ZigzagIterator i = new ZigzagIterator(v1, v2);\n * while (i.HasNext()) v[f()] = i.Next();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @constructor\n * @param {Integer[]} v1\n * @param {Integer[]} v1\n */\nvar ZigzagIterator = function ZigzagIterator(v1, v2) {\n \n};\n\n\n/**\n * @this ZigzagIterator\n * @returns {boolean}\n */\nZigzagIterator.prototype.hasNext = function hasNext() {\n \n};\n\n/**\n * @this ZigzagIterator\n * @returns {integer}\n */\nZigzagIterator.prototype.next = function next() {\n \n};\n\n/**\n * Your ZigzagIterator will be called like this:\n * var i = new ZigzagIterator(v1, v2), a = [];\n * while (i.hasNext()) a.push(i.next());\n*/", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class ZigzagIterator\n # @param {Integer[]} v1\n # @param {Integer[]} v2\n def initialize(v1, v2)\n \n end\n\n # @return {Boolean}\n def has_next\n \n end\n\n # @return {Integer}\n def next\n \n end\nend\n\n# Your ZigzagIterator will be called like this:\n# i, v = ZigzagIterator.new(v1, v2), []\n# while i.has_next()\n# v << i.next\n# end", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class ZigzagIterator {\n init(_ v1: [Int], _ v2: [Int]) {\n \n }\n \n func next() -> Int {\n \n }\n \n func hasNext() -> Bool {\n \n }\n}\n\n// Your ZigzagIterator object will be instantiated and called as such:\n// var i = ZigzagIterator(v1, v2)\n// var ret = [Int]()\n// while i.hasNext() {\n// \t\tret.append(i.next())\n// }", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type ZigzagIterator struct {\n \n}\n\nfunc Constructor(v1, v2 []int) *ZigzagIterator {\n \n}\n\nfunc (this *ZigzagIterator) next() int {\n \n}\n\nfunc (this *ZigzagIterator) hasNext() bool {\n\t\n}\n\n/**\n * Your ZigzagIterator object will be instantiated and called as such:\n * obj := Constructor(param_1, param_2);\n * for obj.hasNext() {\n *\t ans = append(ans, obj.next())\n * }\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class ZigzagIterator(_v1: Array[Int], _v2: Array[Int]) {\n /** initialize your data structure here. */\n \n def next(): Int = {\n \n }\n \n def hasNext(): Boolean = {\n \n }\n}\n\n/**\n * Your ZigzagIterator object will be instantiated and called as such:\n * var obj = new ZigzagIterator(v1, v2)\n * while (obj.hasNext()) {\n * ans += obj.next()\n * }\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class ZigzagIterator {\n constructor(v1: IntArray, v2: IntArray) {\n \n }\n \n fun next(): Int {\n \n }\n \n fun hasNext(): Boolean {\n \n }\n}\n\n// Your ZigzagIterator object will be instantiated and called as such:\n// var i = ZigzagIterator(v1, v2)\n// var ret = ArrayList()\n// while(i.hasNext()){\n//\t\tret.add(i.next())\n// }", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct ZigzagIterator {\n \n}\n\n/** \n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl ZigzagIterator {\n /** initialize your data structure here. */\n \n fn new(v1: Vec, v2: Vec) -> Self {\n \n }\n \n fn next(&self) -> i32 {\n \n }\n \n fn has_next(&self) -> bool {\n \n }\n}\n\n/**\n * Your ZigzagIterator object will be instantiated and called as such:\n * let obj = ZigzagIterator::new(v1, v2);\n * let ret_1: i32 = obj.next();\n * let ret_2: bool = obj.has_next();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class ZigzagIterator {\n /**\n * Initialize your data structure here.\n * @param Integer[] $v1\n * @param Integer[] $v2\n */\n function __construct($v1, $v2) {\n \n }\n \n /**\n * @return Integer\n */\n function next() {\n \n }\n \n /**\n * @return Boolean\n */\n function hasNext() {\n \n }\n}\n\n/**\n * Your ZigzagIterator object will be instantiated and called as such:\n * $obj = ZigzagIterator($v1, $v2);\n * while ($obj->hasNext()) {\n * array_push($ans, $obj->next())\n * }\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class ZigzagIterator {\n constructor(v1: number[], v2: number[]) {\n\t\t\n }\n\n next(): number {\n\t\t\n }\n\n hasNext(): boolean {\n\t\t\n }\n}\n\n/**\n * Your PeekingIterator object will be instantiated and called as such:\n * var obj = new PeekingIterator(iterator)\n * while (obj.hasNext()) ret.push(obj.next());\n */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0281](https://leetcode-cn.com/problems/zigzag-iterator)", "[\u952f\u9f7f\u8fed\u4ee3\u5668](/solution/0200-0299/0281.Zigzag%20Iterator/README.md)", "`\u8bbe\u8ba1`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0281](https://leetcode.com/problems/zigzag-iterator)", "[Zigzag Iterator](/solution/0200-0299/0281.Zigzag%20Iterator/README_EN.md)", "`Design`", "Medium", "\ud83d\udd12"]}, {"question_id": "0280", "frontend_question_id": "0280", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/wiggle-sort", "url_en": "https://leetcode.com/problems/wiggle-sort", "relative_path_cn": "/solution/0200-0299/0280.Wiggle%20Sort/README.md", "relative_path_en": "/solution/0200-0299/0280.Wiggle%20Sort/README_EN.md", "title_cn": "\u6446\u52a8\u6392\u5e8f", "title_en": "Wiggle Sort", "question_title_slug": "wiggle-sort", "content_en": "

    Given an integer array nums, reorder it such that nums[0] <= nums[1] >= nums[2] <= nums[3]....

    \n\n

    You may assume the input array always has a valid answer.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [3,5,2,1,6,4]\nOutput: [3,5,1,6,2,4]\nExplanation: [1,6,2,5,3,4] is also accepted.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [6,6,5,6,3,8]\nOutput: [6,6,5,6,3,8]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 5 * 104
    • \n\t
    • 0 <= nums[i] <= 104
    • \n\t
    • It is guaranteed that there will be an answer for the given input nums.
    • \n
    \n\n

     

    \nFollow up: Could you do it without sorting the array?", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u65e0\u5e8f\u7684\u6570\u7ec4 nums, \u5c06\u8be5\u6570\u5b57 \u539f\u5730 \u91cd\u6392\u540e\u4f7f\u5f97 nums[0] <= nums[1] >= nums[2] <= nums[3]...\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: nums = [3,5,2,1,6,4]\n\u8f93\u51fa: \u4e00\u4e2a\u53ef\u80fd\u7684\u89e3\u7b54\u662f [3,5,1,6,2,4]
    \n", "tags_en": ["Sort", "Array"], "tags_cn": ["\u6392\u5e8f", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n void wiggleSort(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public void wiggleSort(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def wiggleSort(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: None Do not return anything, modify nums in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def wiggleSort(self, nums: List[int]) -> None:\n \"\"\"\n Do not return anything, modify nums in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nvoid wiggleSort(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public void WiggleSort(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {void} Do not return anything, modify nums in-place instead.\n */\nvar wiggleSort = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Void} Do not return anything, modify nums in-place instead.\ndef wiggle_sort(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func wiggleSort(_ nums: inout [Int]) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func wiggleSort(nums []int) {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def wiggleSort(nums: Array[Int]): Unit = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun wiggleSort(nums: IntArray): Unit {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn wiggle_sort(nums: &mut Vec) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return NULL\n */\n function wiggleSort(&$nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n Do not return anything, modify nums in-place instead.\n */\nfunction wiggleSort(nums: number[]): void {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (wiggle-sort nums)\n (-> (listof exact-integer?) void?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0280](https://leetcode-cn.com/problems/wiggle-sort)", "[\u6446\u52a8\u6392\u5e8f](/solution/0200-0299/0280.Wiggle%20Sort/README.md)", "`\u6392\u5e8f`,`\u6570\u7ec4`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0280](https://leetcode.com/problems/wiggle-sort)", "[Wiggle Sort](/solution/0200-0299/0280.Wiggle%20Sort/README_EN.md)", "`Sort`,`Array`", "Medium", "\ud83d\udd12"]}, {"question_id": "0279", "frontend_question_id": "0279", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/perfect-squares", "url_en": "https://leetcode.com/problems/perfect-squares", "relative_path_cn": "/solution/0200-0299/0279.Perfect%20Squares/README.md", "relative_path_en": "/solution/0200-0299/0279.Perfect%20Squares/README_EN.md", "title_cn": "\u5b8c\u5168\u5e73\u65b9\u6570", "title_en": "Perfect Squares", "question_title_slug": "perfect-squares", "content_en": "

    Given an integer n, return the least number of perfect square numbers that sum to n.

    \n\n

    A perfect square is an integer that is the square of an integer; in other words, it is the product of some integer with itself. For example, 1, 4, 9, and 16 are perfect squares while 3 and 11 are not.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 12\nOutput: 3\nExplanation: 12 = 4 + 4 + 4.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 13\nOutput: 2\nExplanation: 13 = 4 + 9.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u6b63\u6574\u6570\u00a0n\uff0c\u627e\u5230\u82e5\u5e72\u4e2a\u5b8c\u5168\u5e73\u65b9\u6570\uff08\u6bd4\u5982\u00a01, 4, 9, 16, ...\uff09\u4f7f\u5f97\u5b83\u4eec\u7684\u548c\u7b49\u4e8e n\u3002\u4f60\u9700\u8981\u8ba9\u7ec4\u6210\u548c\u7684\u5b8c\u5168\u5e73\u65b9\u6570\u7684\u4e2a\u6570\u6700\u5c11\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n \uff0c\u8fd4\u56de\u548c\u4e3a n \u7684\u5b8c\u5168\u5e73\u65b9\u6570\u7684 \u6700\u5c11\u6570\u91cf \u3002

    \n\n

    \u5b8c\u5168\u5e73\u65b9\u6570 \u662f\u4e00\u4e2a\u6574\u6570\uff0c\u5176\u503c\u7b49\u4e8e\u53e6\u4e00\u4e2a\u6574\u6570\u7684\u5e73\u65b9\uff1b\u6362\u53e5\u8bdd\u8bf4\uff0c\u5176\u503c\u7b49\u4e8e\u4e00\u4e2a\u6574\u6570\u81ea\u4e58\u7684\u79ef\u3002\u4f8b\u5982\uff0c1\u30014\u30019 \u548c 16 \u90fd\u662f\u5b8c\u5168\u5e73\u65b9\u6570\uff0c\u800c 3 \u548c 11 \u4e0d\u662f\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\u00a01\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 12\n\u8f93\u51fa\uff1a3 \n\u89e3\u91ca\uff1a12 = 4 + 4 + 4
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 13\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a13 = 4 + 9
    \n\u00a0\n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 104
    • \n
    \n", "tags_en": ["Breadth-first Search", "Math", "Dynamic Programming"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u6570\u5b66", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numSquares(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numSquares(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numSquares(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numSquares(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numSquares(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumSquares(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar numSquares = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef num_squares(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numSquares(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numSquares(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numSquares(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numSquares(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_squares(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function numSquares($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numSquares(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-squares n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0279](https://leetcode-cn.com/problems/perfect-squares)", "[\u5b8c\u5168\u5e73\u65b9\u6570](/solution/0200-0299/0279.Perfect%20Squares/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u6570\u5b66`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0279](https://leetcode.com/problems/perfect-squares)", "[Perfect Squares](/solution/0200-0299/0279.Perfect%20Squares/README_EN.md)", "`Breadth-first Search`,`Math`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0278", "frontend_question_id": "0278", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/first-bad-version", "url_en": "https://leetcode.com/problems/first-bad-version", "relative_path_cn": "/solution/0200-0299/0278.First%20Bad%20Version/README.md", "relative_path_en": "/solution/0200-0299/0278.First%20Bad%20Version/README_EN.md", "title_cn": "\u7b2c\u4e00\u4e2a\u9519\u8bef\u7684\u7248\u672c", "title_en": "First Bad Version", "question_title_slug": "first-bad-version", "content_en": "

    You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the previous version, all the versions after a bad version are also bad.

    \n\n

    Suppose you have n versions [1, 2, ..., n] and you want to find out the first bad one, which causes all the following ones to be bad.

    \n\n

    You are given an API bool isBadVersion(version) which returns whether version is bad. Implement a function to find the first bad version. You should minimize the number of calls to the API.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 5, bad = 4\nOutput: 4\nExplanation:\ncall isBadVersion(3) -> false\ncall isBadVersion(5) -> true\ncall isBadVersion(4) -> true\nThen 4 is the first bad version.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 1, bad = 1\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= bad <= n <= 231 - 1
    • \n
    \n", "content_cn": "

    \u4f60\u662f\u4ea7\u54c1\u7ecf\u7406\uff0c\u76ee\u524d\u6b63\u5728\u5e26\u9886\u4e00\u4e2a\u56e2\u961f\u5f00\u53d1\u65b0\u7684\u4ea7\u54c1\u3002\u4e0d\u5e78\u7684\u662f\uff0c\u4f60\u7684\u4ea7\u54c1\u7684\u6700\u65b0\u7248\u672c\u6ca1\u6709\u901a\u8fc7\u8d28\u91cf\u68c0\u6d4b\u3002\u7531\u4e8e\u6bcf\u4e2a\u7248\u672c\u90fd\u662f\u57fa\u4e8e\u4e4b\u524d\u7684\u7248\u672c\u5f00\u53d1\u7684\uff0c\u6240\u4ee5\u9519\u8bef\u7684\u7248\u672c\u4e4b\u540e\u7684\u6240\u6709\u7248\u672c\u90fd\u662f\u9519\u7684\u3002

    \n\n

    \u5047\u8bbe\u4f60\u6709 n \u4e2a\u7248\u672c [1, 2, ..., n]\uff0c\u4f60\u60f3\u627e\u51fa\u5bfc\u81f4\u4e4b\u540e\u6240\u6709\u7248\u672c\u51fa\u9519\u7684\u7b2c\u4e00\u4e2a\u9519\u8bef\u7684\u7248\u672c\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u901a\u8fc7\u8c03\u7528 bool isBadVersion(version) \u63a5\u53e3\u6765\u5224\u65ad\u7248\u672c\u53f7 version \u662f\u5426\u5728\u5355\u5143\u6d4b\u8bd5\u4e2d\u51fa\u9519\u3002\u5b9e\u73b0\u4e00\u4e2a\u51fd\u6570\u6765\u67e5\u627e\u7b2c\u4e00\u4e2a\u9519\u8bef\u7684\u7248\u672c\u3002\u4f60\u5e94\u8be5\u5c3d\u91cf\u51cf\u5c11\u5bf9\u8c03\u7528 API \u7684\u6b21\u6570\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u7ed9\u5b9a n = 5\uff0c\u5e76\u4e14 version = 4 \u662f\u7b2c\u4e00\u4e2a\u9519\u8bef\u7684\u7248\u672c\u3002\n\n\u8c03\u7528 isBadVersion(3) -> false\n\u8c03\u7528 isBadVersion(5) -> true\n\u8c03\u7528 isBadVersion(4) -> true\n\n\u6240\u4ee5\uff0c4 \u662f\u7b2c\u4e00\u4e2a\u9519\u8bef\u7684\u7248\u672c\u3002 
    \n", "tags_en": ["Binary Search"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "// The API isBadVersion is defined for you.\n// bool isBadVersion(int version);\n\nclass Solution {\npublic:\n int firstBadVersion(int n) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/* The isBadVersion API is defined in the parent class VersionControl.\n boolean isBadVersion(int version); */\n\npublic class Solution extends VersionControl {\n public int firstBadVersion(int n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# The isBadVersion API is already defined for you.\n# @param version, an integer\n# @return a bool\n# def isBadVersion(version):\n\nclass Solution(object):\n def firstBadVersion(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# The isBadVersion API is already defined for you.\n# @param version, an integer\n# @return an integer\n# def isBadVersion(version):\n\nclass Solution:\n def firstBadVersion(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "// The API isBadVersion is defined for you.\n// bool isBadVersion(int version);\n\nint firstBadVersion(int n) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/* The isBadVersion API is defined in the parent class VersionControl.\n bool IsBadVersion(int version); */\n\npublic class Solution : VersionControl {\n public int FirstBadVersion(int n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for isBadVersion()\n * \n * @param {integer} version number\n * @return {boolean} whether the version is bad\n * isBadVersion = function(version) {\n * ...\n * };\n */\n\n/**\n * @param {function} isBadVersion()\n * @return {function}\n */\nvar solution = function(isBadVersion) {\n /**\n * @param {integer} n Total versions\n * @return {integer} The first bad version\n */\n return function(n) {\n \n };\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# The is_bad_version API is already defined for you.\n# @param {Integer} version\n# @return {boolean} whether the version is bad\n# def is_bad_version(version):\n\n# @param {Integer} n\n# @return {Integer}\ndef first_bad_version(n)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * The knows API is defined in the parent class VersionControl.\n * func isBadVersion(_ version: Int) -> Bool{}\n */\n\nclass Solution : VersionControl {\n func firstBadVersion(_ n: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/** \n * Forward declaration of isBadVersion API.\n * @param version your guess about first bad version\n * @return \t \t true if current version is bad \n *\t\t\t false if current version is good\n * func isBadVersion(version int) bool;\n */\n\nfunc firstBadVersion(n int) int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/* The isBadVersion API is defined in the parent class VersionControl.\n def isBadVersion(version: Int): Boolean = {} */\n\nclass Solution extends VersionControl {\n def firstBadVersion(n: Int): Int = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/* The isBadVersion API is defined in the parent class VersionControl.\n def isBadVersion(version: Int): Boolean = {} */\n\nclass Solution: VersionControl() {\n override fun firstBadVersion(n: Int) : Int {\n \n\t}\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// The API isBadVersion is defined for you.\n// isBadVersion(versions:i32)-> bool;\n// to call it use self.isBadVersion(versions)\n\nimpl Solution {\n pub fn first_bad_version(&self, n: i32) -> i32 {\n\t\t\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/* The isBadVersion API is defined in the parent class VersionControl.\n public function isBadVersion($version){} */\n\nclass Solution extends VersionControl {\n /**\n * @param Integer $n\n * @return Integer\n */\n function firstBadVersion($n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * The knows API is defined in the parent class Relation.\n * isBadVersion(version: number): boolean {\n * ...\n * };\n */\n\nvar solution = function(isBadVersion: any) {\n\n return function(n: number): number {\n \n };\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0278](https://leetcode-cn.com/problems/first-bad-version)", "[\u7b2c\u4e00\u4e2a\u9519\u8bef\u7684\u7248\u672c](/solution/0200-0299/0278.First%20Bad%20Version/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u7b80\u5355", ""], "md_table_row_en": ["[0278](https://leetcode.com/problems/first-bad-version)", "[First Bad Version](/solution/0200-0299/0278.First%20Bad%20Version/README_EN.md)", "`Binary Search`", "Easy", ""]}, {"question_id": "0277", "frontend_question_id": "0277", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/find-the-celebrity", "url_en": "https://leetcode.com/problems/find-the-celebrity", "relative_path_cn": "/solution/0200-0299/0277.Find%20the%20Celebrity/README.md", "relative_path_en": "/solution/0200-0299/0277.Find%20the%20Celebrity/README_EN.md", "title_cn": "\u641c\u5bfb\u540d\u4eba", "title_en": "Find the Celebrity", "question_title_slug": "find-the-celebrity", "content_en": "

    Suppose you are at a party with n people (labeled from 0 to n - 1), and among them, there may exist one celebrity. The definition of a celebrity is that all the other n - 1 people know him/her, but he/she does not know any of them.

    \n\n

    Now you want to find out who the celebrity is or verify that there is not one. The only thing you are allowed to do is to ask questions like: "Hi, A. Do you know B?" to get information about whether A knows B. You need to find out the celebrity (or verify there is not one) by asking as few questions as possible (in the asymptotic sense).

    \n\n

    You are given a helper function bool knows(a, b) which tells you whether A knows B. Implement a function int findCelebrity(n). There will be exactly one celebrity if he/she is in the party. Return the celebrity's label if there is a celebrity in the party. If there is no celebrity, return -1.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: graph = [[1,1,0],[0,1,0],[1,1,1]]\nOutput: 1\nExplanation: There are three persons labeled with 0, 1 and 2. graph[i][j] = 1 means person i knows person j, otherwise graph[i][j] = 0 means person i does not know person j. The celebrity is the person labeled as 1 because both 0 and 2 know him but 1 does not know anybody.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: graph = [[1,0,1],[1,1,0],[0,1,1]]\nOutput: -1\nExplanation: There is no celebrity.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == graph.length
    • \n\t
    • n == graph[i].length
    • \n\t
    • 2 <= n <= 100
    • \n\t
    • graph[i][j] is 0 or 1.
    • \n\t
    • graph[i][i] == 1
    • \n
    \n\n

     

    \nFollow up: If the maximum number of allowed calls to the API knows is 3 * n, could you find a solution without exceeding the maximum number of calls?", "content_cn": "

    \u5047\u8bbe\u4f60\u662f\u4e00\u4e2a\u4e13\u4e1a\u7684\u72d7\u4ed4\uff0c\u53c2\u52a0\u4e86\u4e00\u4e2a\u00a0n\u00a0\u4eba\u6d3e\u5bf9\uff0c\u5176\u4e2d\u6bcf\u4e2a\u4eba\u88ab\u4ece\u00a00\u00a0\u5230\u00a0n - 1\u00a0\u6807\u53f7\u3002\u5728\u8fd9\u4e2a\u6d3e\u5bf9\u4eba\u7fa4\u5f53\u4e2d\u53ef\u80fd\u5b58\u5728\u4e00\u4f4d\u00a0\u201c\u540d\u4eba\u201d\u3002\u6240\u8c13 \u201c\u540d\u4eba\u201d \u7684\u5b9a\u4e49\u662f\uff1a\u5176\u4ed6\u6240\u6709\u00a0n - 1\u00a0\u4e2a\u4eba\u90fd\u8ba4\u8bc6\u4ed6/\u5979\uff0c\u800c\u4ed6/\u5979\u5e76\u4e0d\u8ba4\u8bc6\u5176\u4ed6\u4efb\u4f55\u4eba\u3002

    \n\n

    \u73b0\u5728\u4f60\u60f3\u8981\u786e\u8ba4\u8fd9\u4e2a \u201c\u540d\u4eba\u201d \u662f\u8c01\uff0c\u6216\u8005\u786e\u5b9a\u8fd9\u91cc\u6ca1\u6709\u00a0\u201c\u540d\u4eba\u201d\u3002\u800c\u4f60\u552f\u4e00\u80fd\u505a\u7684\u5c31\u662f\u95ee\u8bf8\u5982 \u201cA\u00a0\u4f60\u597d\u5440\uff0c\u8bf7\u95ee\u4f60\u8ba4\u4e0d\u8ba4\u8bc6\u00a0B\u5440\uff1f\u201d\u00a0\u7684\u95ee\u9898\uff0c\u4ee5\u786e\u5b9a A \u662f\u5426\u8ba4\u8bc6 B\u3002\u4f60\u9700\u8981\u5728\uff08\u6e10\u8fd1\u610f\u4e49\u4e0a\uff09\u5c3d\u53ef\u80fd\u5c11\u7684\u95ee\u9898\u5185\u6765\u786e\u5b9a\u8fd9\u4f4d \u201c\u540d\u4eba\u201d \u662f\u8c01\uff08\u6216\u8005\u786e\u5b9a\u8fd9\u91cc\u6ca1\u6709 \u201c\u540d\u4eba\u201d\uff09\u3002

    \n\n

    \u5728\u672c\u9898\u4e2d\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u8f85\u52a9\u51fd\u6570\u00a0bool knows(a, b)\u00a0\u83b7\u53d6\u5230 A\u00a0\u662f\u5426\u8ba4\u8bc6 B\u3002\u8bf7\u4f60\u6765\u5b9e\u73b0\u4e00\u4e2a\u51fd\u6570\u00a0int findCelebrity(n)\u3002

    \n\n

    \u6d3e\u5bf9\u6700\u591a\u53ea\u4f1a\u6709\u4e00\u4e2a \u201c\u540d\u4eba\u201d \u53c2\u52a0\u3002\u82e5\u00a0\u201c\u540d\u4eba\u201d \u5b58\u5728\uff0c\u8bf7\u8fd4\u56de\u4ed6/\u5979\u7684\u7f16\u53f7\uff1b\u82e5\u00a0\u201c\u540d\u4eba\u201d\u00a0\u4e0d\u5b58\u5728\uff0c\u8bf7\u8fd4\u56de\u00a0-1\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1:

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165: graph = [\n\u00a0 [1,1,0],\n\u00a0 [0,1,0],\n\u00a0 [1,1,1]\n]\n\u8f93\u51fa: 1\n\u89e3\u91ca: \u6709\u7f16\u53f7\u5206\u522b\u4e3a 0\u30011 \u548c 2 \u7684\u4e09\u4e2a\u4eba\u3002graph[i][j] = 1 \u4ee3\u8868\u7f16\u53f7\u4e3a i \u7684\u4eba\u8ba4\u8bc6\u7f16\u53f7\u4e3a j \u7684\u4eba\uff0c\u800c graph[i][j] = 0 \u5219\u4ee3\u8868\u7f16\u53f7\u4e3a i \u7684\u4eba\u4e0d\u8ba4\u8bc6\u7f16\u53f7\u4e3a j \u7684\u4eba\u3002\u201c\u540d\u4eba\u201d \u662f\u7f16\u53f7 1 \u7684\u4eba\uff0c\u56e0\u4e3a 0 \u548c 2 \u5747\u8ba4\u8bc6\u4ed6/\u5979\uff0c\u4f46 1 \u4e0d\u8ba4\u8bc6\u4efb\u4f55\u4eba\u3002\n
    \n\n

    \u793a\u4f8b\u00a02:

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165: graph = [\n\u00a0 [1,0,1],\n\u00a0 [1,1,0],\n\u00a0 [0,1,1]\n]\n\u8f93\u51fa: -1\n\u89e3\u91ca: \u6ca1\u6709 \u201c\u540d\u4eba\u201d\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == graph.length
    • \n\t
    • n == graph[i].length
    • \n\t
    • 2 <= n <= 100
    • \n\t
    • graph[i][j] \u662f 0 \u6216 1.
    • \n\t
    • graph[i][i] == 1
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u5982\u679c\u5141\u8bb8\u8c03\u7528 API knows \u7684\u6700\u5927\u6b21\u6570\u4e3a 3 * n \uff0c\u4f60\u53ef\u4ee5\u8bbe\u8ba1\u4e00\u4e2a\u4e0d\u8d85\u8fc7\u6700\u5927\u8c03\u7528\u6b21\u6570\u7684\u89e3\u51b3\u65b9\u6848\u5417\uff1f

    \n\n
      \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/* The knows API is defined for you.\n bool knows(int a, int b); */\n\nclass Solution {\npublic:\n int findCelebrity(int n) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/* The knows API is defined in the parent class Relation.\n boolean knows(int a, int b); */\n\npublic class Solution extends Relation {\n public int findCelebrity(int n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# The knows API is already defined for you.\n# @param a, person a\n# @param b, person b\n# @return a boolean, whether a knows b\n# def knows(a, b):\n\nclass Solution(object):\n def findCelebrity(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# The knows API is already defined for you.\n# return a bool, whether a knows b\n# def knows(a: int, b: int) -> bool:\n\nclass Solution:\n def findCelebrity(self, n: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/* The knows API is defined for you.\n bool knows(int a, int b); */\n\nint findCelebrity(int n) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/* The Knows API is defined in the parent class Relation.\n bool Knows(int a, int b); */\n\npublic class Solution : Relation {\n public int FindCelebrity(int n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for knows()\n * \n * @param {integer} person a\n * @param {integer} person b\n * @return {boolean} whether a knows b\n * knows = function(a, b) {\n * ...\n * };\n */\n\n/**\n * @param {function} knows()\n * @return {function}\n */\nvar solution = function(knows) {\n /**\n * @param {integer} n Total people\n * @return {integer} The celebrity\n */\n return function(n) {\n \n };\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# The knows API is already defined for you.\n# @param {Integer} person a\n# @param {Integer} person b\n# @return {Boolean} whether a knows b\n# def knows(a, b)\n\n# @param {Integer} n\n# @return {Integer}\ndef find_celebrity(n)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * The knows API is defined in the parent class Relation.\n * func knows(_ a: Int, _ b: Int) -> Bool;\n */\n\nclass Solution : Relation {\n func findCelebrity(_ n: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * The knows API is already defined for you.\n * knows := func(a int, b int) bool\n */\nfunc solution(knows func(a int, b int) bool) func(n int) int {\n return func(n int) int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/* The knows API is defined in the parent class Relation.\n def knows(a: Int, b: Int): Boolean = {} */\n\nclass Solution extends Relation {\n def findCelebrity(n: Int): Int = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/* The knows API is defined in the parent class Relation.\n fun knows(a: Int, b: Int) : Boolean {} */\n\nclass Solution: Relation() {\n override fun findCelebrity(n: Int) : Int {\n \n\t}\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "/* The knows API is defined for you.\n knows(a: i32, b: i32)->bool;\n to call it use self.knows(a,b)\n*/\n\nimpl Solution {\n pub fn find_celebrity(&self, n: i32) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/* The knows API is defined in the parent class Relation.\n public function knows($a, $b){} */\n\nclass Solution extends Relation {\n /**\n * @param Integer $n\n * @return Integer\n */\n function findCelebrity($n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * The knows API is defined in the parent class Relation.\n * knows(a: number, b: number): boolean {\n * ...\n * };\n */\n\nvar solution = function(knows: any) {\n\n return function(n: number): number {\n \n };\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0277](https://leetcode-cn.com/problems/find-the-celebrity)", "[\u641c\u5bfb\u540d\u4eba](/solution/0200-0299/0277.Find%20the%20Celebrity/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0277](https://leetcode.com/problems/find-the-celebrity)", "[Find the Celebrity](/solution/0200-0299/0277.Find%20the%20Celebrity/README_EN.md)", "`Array`", "Medium", "\ud83d\udd12"]}, {"question_id": "0276", "frontend_question_id": "0276", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/paint-fence", "url_en": "https://leetcode.com/problems/paint-fence", "relative_path_cn": "/solution/0200-0299/0276.Paint%20Fence/README.md", "relative_path_en": "/solution/0200-0299/0276.Paint%20Fence/README_EN.md", "title_cn": "\u6805\u680f\u6d82\u8272", "title_en": "Paint Fence", "question_title_slug": "paint-fence", "content_en": "

    You are painting a fence of n posts with k different colors. You must paint the posts following these rules:

    \n\n
      \n\t
    • Every post must be painted exactly one color.
    • \n\t
    • At most one pair of adjacent fence posts can have the same color.
    • \n
    \n\n

    Given the two integers n and k, return the number of ways you can paint the fence.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: n = 3, k = 2\nOutput: 6\nExplanation: All the possibilities are shown.\nNote that painting all the posts red or all the posts green is invalid because there can only be at most one pair of adjacent posts that are the same color.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 1, k = 1\nOutput: 1\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 7, k = 2\nOutput: 42\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 50
    • \n\t
    • 1 <= k <= 105
    • \n\t
    • The answer is guaranteed to be in the range [0, 231 - 1] for the given n and k.
    • \n
    \n", "content_cn": "

    \u6709 k \u79cd\u989c\u8272\u7684\u6d82\u6599\u548c\u4e00\u4e2a\u5305\u542b n \u4e2a\u6805\u680f\u67f1\u7684\u6805\u680f\uff0c\u8bf7\u4f60\u6309\u4e0b\u8ff0\u89c4\u5219\u4e3a\u6805\u680f\u8bbe\u8ba1\u6d82\u8272\u65b9\u6848\uff1a

    \n\n
      \n\t
    • \u6bcf\u4e2a\u6805\u680f\u67f1\u53ef\u4ee5\u7528\u5176\u4e2d \u4e00\u79cd \u989c\u8272\u8fdb\u884c\u4e0a\u8272\u3002
    • \n\t
    • \u76f8\u90bb\u7684\u6805\u680f\u67f1 \u6700\u591a\u8fde\u7eed\u4e24\u4e2a\u00a0\u989c\u8272\u76f8\u540c\u3002
    • \n
    \n\n

    \u7ed9\u4f60\u4e24\u4e2a\u6574\u6570 k \u548c n \uff0c\u8fd4\u56de\u6240\u6709\u6709\u6548\u7684\u6d82\u8272 \u65b9\u6848\u6570 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1an = 3, k = 2\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u6240\u6709\u7684\u53ef\u80fd\u6d82\u8272\u65b9\u6848\u5982\u4e0a\u56fe\u6240\u793a\u3002\u6ce8\u610f\uff0c\u5168\u6d82\u7ea2\u6216\u8005\u5168\u6d82\u7eff\u7684\u65b9\u6848\u5c5e\u4e8e\u65e0\u6548\u65b9\u6848\uff0c\u56e0\u4e3a\u76f8\u90bb\u7684\u6805\u680f\u67f1 \u6700\u591a\u8fde\u7eed\u4e24\u4e2a\u00a0\u989c\u8272\u76f8\u540c\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 1, k = 1\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 7, k = 2\n\u8f93\u51fa\uff1a42\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 50
    • \n\t
    • 1 <= k <= 105
    • \n\t
    • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\uff1a\u5bf9\u4e8e\u8f93\u5165\u7684 n \u548c k \uff0c\u5176\u7b54\u6848\u5728\u8303\u56f4 [0, 231 - 1] \u5185
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numWays(int n, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numWays(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numWays(self, n, k):\n \"\"\"\n :type n: int\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numWays(self, n: int, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numWays(int n, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumWays(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} k\n * @return {number}\n */\nvar numWays = function(n, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} k\n# @return {Integer}\ndef num_ways(n, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numWays(_ n: Int, _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numWays(n int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numWays(n: Int, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numWays(n: Int, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_ways(n: i32, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $k\n * @return Integer\n */\n function numWays($n, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numWays(n: number, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-ways n k)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0276](https://leetcode-cn.com/problems/paint-fence)", "[\u6805\u680f\u6d82\u8272](/solution/0200-0299/0276.Paint%20Fence/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0276](https://leetcode.com/problems/paint-fence)", "[Paint Fence](/solution/0200-0299/0276.Paint%20Fence/README_EN.md)", "`Dynamic Programming`", "Medium", "\ud83d\udd12"]}, {"question_id": "0275", "frontend_question_id": "0275", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/h-index-ii", "url_en": "https://leetcode.com/problems/h-index-ii", "relative_path_cn": "/solution/0200-0299/0275.H-Index%20II/README.md", "relative_path_en": "/solution/0200-0299/0275.H-Index%20II/README_EN.md", "title_cn": "H \u6307\u6570 II", "title_en": "H-Index II", "question_title_slug": "h-index-ii", "content_en": "

    Given an array of integers citations where citations[i] is the number of citations a researcher received for their ith paper and citations is sorted in an ascending order, return compute the researcher's h-index.

    \n\n

    According to the definition of h-index on Wikipedia: A scientist has an index h if h of their n papers have at least h citations each, and the other n − h papers have no more than h citations each.

    \n\n

    If there are several possible values for h, the maximum one is taken as the h-index.

    \n\n

    You must write an algorithm that runs in logarithmic time.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: citations = [0,1,3,5,6]\nOutput: 3\nExplanation: [0,1,3,5,6] means the researcher has 5 papers in total and each of them had received 0, 1, 3, 5, 6 citations respectively.\nSince the researcher has 3 papers with at least 3 citations each and the remaining two with no more than 3 citations each, their h-index is 3.\n
    \n\n

    Example 2:

    \n\n
    \nInput: citations = [1,2,100]\nOutput: 2\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == citations.length
    • \n\t
    • 1 <= n <= 105
    • \n\t
    • 0 <= citations[i] <= 1000
    • \n\t
    • citations is sorted in ascending order.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4f4d\u7814\u7a76\u8005\u8bba\u6587\u88ab\u5f15\u7528\u6b21\u6570\u7684\u6570\u7ec4\uff08\u88ab\u5f15\u7528\u6b21\u6570\u662f\u975e\u8d1f\u6574\u6570\uff09\uff0c\u6570\u7ec4\u5df2\u7ecf\u6309\u7167 \u5347\u5e8f\u6392\u5217 \u3002\u7f16\u5199\u4e00\u4e2a\u65b9\u6cd5\uff0c\u8ba1\u7b97\u51fa\u7814\u7a76\u8005\u7684 h \u6307\u6570\u3002

    \n\n

    h \u6307\u6570\u7684\u5b9a\u4e49: “h \u4ee3\u8868“\u9ad8\u5f15\u7528\u6b21\u6570”\uff08high citations\uff09\uff0c\u4e00\u540d\u79d1\u7814\u4eba\u5458\u7684 h \u6307\u6570\u662f\u6307\u4ed6\uff08\u5979\uff09\u7684 \uff08N \u7bc7\u8bba\u6587\u4e2d\uff09\u603b\u5171\u6709 h \u7bc7\u8bba\u6587\u5206\u522b\u88ab\u5f15\u7528\u4e86\u81f3\u5c11 h \u6b21\u3002\uff08\u5176\u4f59\u7684 N - h \u7bc7\u8bba\u6587\u6bcf\u7bc7\u88ab\u5f15\u7528\u6b21\u6570\u4e0d\u591a\u4e8e h \u6b21\u3002\uff09"

    \n\n

     

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: citations = [0,1,3,5,6]\n\u8f93\u51fa: 3 \n\u89e3\u91ca: \u7ed9\u5b9a\u6570\u7ec4\u8868\u793a\u7814\u7a76\u8005\u603b\u5171\u6709 5 \u7bc7\u8bba\u6587\uff0c\u6bcf\u7bc7\u8bba\u6587\u76f8\u5e94\u7684\u88ab\u5f15\u7528\u4e86 0, 1, 3, 5, 6 \u6b21\u3002\n     \u7531\u4e8e\u7814\u7a76\u8005\u6709 3 \u7bc7\u8bba\u6587\u6bcf\u7bc7\u81f3\u5c11\u88ab\u5f15\u7528\u4e86 3 \u6b21\uff0c\u5176\u4f59\u4e24\u7bc7\u8bba\u6587\u6bcf\u7bc7\u88ab\u5f15\u7528\u4e0d\u591a\u4e8e 3 \u6b21\uff0c\u6240\u4ee5\u5979\u7684 h \u6307\u6570\u662f 3\u3002
    \n\n

     

    \n\n

    \u8bf4\u660e:

    \n\n

    \u5982\u679c h \u6709\u591a\u6709\u79cd\u53ef\u80fd\u7684\u503c \uff0ch \u6307\u6570\u662f\u5176\u4e2d\u6700\u5927\u7684\u90a3\u4e2a\u3002

    \n\n

     

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u8fd9\u662f H \u6307\u6570 \u7684\u5ef6\u4f38\u9898\u76ee\uff0c\u672c\u9898\u4e2d\u7684 citations \u6570\u7ec4\u662f\u4fdd\u8bc1\u6709\u5e8f\u7684\u3002
    • \n\t
    • \u4f60\u53ef\u4ee5\u4f18\u5316\u4f60\u7684\u7b97\u6cd5\u5230\u5bf9\u6570\u65f6\u95f4\u590d\u6742\u5ea6\u5417\uff1f
    • \n
    \n", "tags_en": ["Binary Search"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int hIndex(vector& citations) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int hIndex(int[] citations) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def hIndex(self, citations):\n \"\"\"\n :type citations: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def hIndex(self, citations: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint hIndex(int* citations, int citationsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int HIndex(int[] citations) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} citations\n * @return {number}\n */\nvar hIndex = function(citations) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} citations\n# @return {Integer}\ndef h_index(citations)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func hIndex(_ citations: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func hIndex(citations []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def hIndex(citations: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun hIndex(citations: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn h_index(citations: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $citations\n * @return Integer\n */\n function hIndex($citations) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function hIndex(citations: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (h-index citations)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0275](https://leetcode-cn.com/problems/h-index-ii)", "[H \u6307\u6570 II](/solution/0200-0299/0275.H-Index%20II/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0275](https://leetcode.com/problems/h-index-ii)", "[H-Index II](/solution/0200-0299/0275.H-Index%20II/README_EN.md)", "`Binary Search`", "Medium", ""]}, {"question_id": "0274", "frontend_question_id": "0274", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/h-index", "url_en": "https://leetcode.com/problems/h-index", "relative_path_cn": "/solution/0200-0299/0274.H-Index/README.md", "relative_path_en": "/solution/0200-0299/0274.H-Index/README_EN.md", "title_cn": "H \u6307\u6570", "title_en": "H-Index", "question_title_slug": "h-index", "content_en": "

    Given an array of integers citations where citations[i] is the number of citations a researcher received for their ith paper, return compute the researcher's h-index.

    \n\n

    According to the definition of h-index on Wikipedia: A scientist has an index h if h of their n papers have at least h citations each, and the other n − h papers have no more than h citations each.

    \n\n

    If there are several possible values for h, the maximum one is taken as the h-index.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: citations = [3,0,6,1,5]\nOutput: 3\nExplanation: [3,0,6,1,5] means the researcher has 5 papers in total and each of them had received 3, 0, 6, 1, 5 citations respectively.\nSince the researcher has 3 papers with at least 3 citations each and the remaining two with no more than 3 citations each, their h-index is 3.\n
    \n\n

    Example 2:

    \n\n
    \nInput: citations = [1,3,1]\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == citations.length
    • \n\t
    • 1 <= n <= 5000
    • \n\t
    • 0 <= citations[i] <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4f4d\u7814\u7a76\u8005\u8bba\u6587\u88ab\u5f15\u7528\u6b21\u6570\u7684\u6570\u7ec4\uff08\u88ab\u5f15\u7528\u6b21\u6570\u662f\u975e\u8d1f\u6574\u6570\uff09\u3002\u7f16\u5199\u4e00\u4e2a\u65b9\u6cd5\uff0c\u8ba1\u7b97\u51fa\u7814\u7a76\u8005\u7684 h\u00a0\u6307\u6570\u3002

    \n\n

    h \u6307\u6570\u7684\u5b9a\u4e49\uff1ah \u4ee3\u8868\u201c\u9ad8\u5f15\u7528\u6b21\u6570\u201d\uff08high citations\uff09\uff0c\u4e00\u540d\u79d1\u7814\u4eba\u5458\u7684 h \u6307\u6570\u662f\u6307\u4ed6\uff08\u5979\uff09\u7684 \uff08N \u7bc7\u8bba\u6587\u4e2d\uff09\u603b\u5171\u6709 h \u7bc7\u8bba\u6587\u5206\u522b\u88ab\u5f15\u7528\u4e86\u81f3\u5c11 h \u6b21\u3002\u4e14\u5176\u4f59\u7684\u00a0N - h\u00a0\u7bc7\u8bba\u6587\u6bcf\u7bc7\u88ab\u5f15\u7528\u6b21\u6570\u00a0\u4e0d\u8d85\u8fc7 h \u6b21\u3002

    \n\n

    \u4f8b\u5982\uff1a\u67d0\u4eba\u7684 h \u6307\u6570\u662f 20\uff0c\u8fd9\u8868\u793a\u4ed6\u5df2\u53d1\u8868\u7684\u8bba\u6587\u4e2d\uff0c\u6bcf\u7bc7\u88ab\u5f15\u7528\u4e86\u81f3\u5c11 20 \u6b21\u7684\u8bba\u6587\u603b\u5171\u6709 20 \u7bc7\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1acitations = [3,0,6,1,5]\n\u8f93\u51fa\uff1a3 \n\u89e3\u91ca\uff1a\u7ed9\u5b9a\u6570\u7ec4\u8868\u793a\u7814\u7a76\u8005\u603b\u5171\u6709 5 \u7bc7\u8bba\u6587\uff0c\u6bcf\u7bc7\u8bba\u6587\u76f8\u5e94\u7684\u88ab\u5f15\u7528\u4e86 3, 0, 6, 1, 5 \u6b21\u3002\n\u00a0    \u7531\u4e8e\u7814\u7a76\u8005\u6709 3 \u7bc7\u8bba\u6587\u6bcf\u7bc7 \u81f3\u5c11 \u88ab\u5f15\u7528\u4e86 3 \u6b21\uff0c\u5176\u4f59\u4e24\u7bc7\u8bba\u6587\u6bcf\u7bc7\u88ab\u5f15\u7528 \u4e0d\u591a\u4e8e 3 \u6b21\uff0c\u6240\u4ee5\u5979\u7684 h \u6307\u6570\u662f 3\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a\u5982\u679c h \u6709\u591a\u79cd\u53ef\u80fd\u7684\u503c\uff0ch \u6307\u6570\u662f\u5176\u4e2d\u6700\u5927\u7684\u90a3\u4e2a\u3002

    \n", "tags_en": ["Sort", "Hash Table"], "tags_cn": ["\u6392\u5e8f", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int hIndex(vector& citations) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int hIndex(int[] citations) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def hIndex(self, citations):\n \"\"\"\n :type citations: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def hIndex(self, citations: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint hIndex(int* citations, int citationsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int HIndex(int[] citations) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} citations\n * @return {number}\n */\nvar hIndex = function(citations) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} citations\n# @return {Integer}\ndef h_index(citations)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func hIndex(_ citations: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func hIndex(citations []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def hIndex(citations: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun hIndex(citations: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn h_index(citations: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $citations\n * @return Integer\n */\n function hIndex($citations) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function hIndex(citations: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (h-index citations)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0274](https://leetcode-cn.com/problems/h-index)", "[H \u6307\u6570](/solution/0200-0299/0274.H-Index/README.md)", "`\u6392\u5e8f`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0274](https://leetcode.com/problems/h-index)", "[H-Index](/solution/0200-0299/0274.H-Index/README_EN.md)", "`Sort`,`Hash Table`", "Medium", ""]}, {"question_id": "0273", "frontend_question_id": "0273", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/integer-to-english-words", "url_en": "https://leetcode.com/problems/integer-to-english-words", "relative_path_cn": "/solution/0200-0299/0273.Integer%20to%20English%20Words/README.md", "relative_path_en": "/solution/0200-0299/0273.Integer%20to%20English%20Words/README_EN.md", "title_cn": "\u6574\u6570\u8f6c\u6362\u82f1\u6587\u8868\u793a", "title_en": "Integer to English Words", "question_title_slug": "integer-to-english-words", "content_en": "

    Convert a non-negative integer num to its English words representation.

    \n\n

     

    \n

    Example 1:

    \n
    Input: num = 123\nOutput: \"One Hundred Twenty Three\"\n

    Example 2:

    \n
    Input: num = 12345\nOutput: \"Twelve Thousand Three Hundred Forty Five\"\n

    Example 3:

    \n
    Input: num = 1234567\nOutput: \"One Million Two Hundred Thirty Four Thousand Five Hundred Sixty Seven\"\n

    Example 4:

    \n
    Input: num = 1234567891\nOutput: \"One Billion Two Hundred Thirty Four Million Five Hundred Sixty Seven Thousand Eight Hundred Ninety One\"\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= num <= 231 - 1
    • \n
    \n", "content_cn": "

    \u5c06\u975e\u8d1f\u6574\u6570 num \u8f6c\u6362\u4e3a\u5176\u5bf9\u5e94\u7684\u82f1\u6587\u8868\u793a\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anum = 123\n\u8f93\u51fa\uff1a\"One Hundred Twenty Three\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anum = 12345\n\u8f93\u51fa\uff1a\"Twelve Thousand Three Hundred Forty Five\"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anum = 1234567\n\u8f93\u51fa\uff1a\"One Million Two Hundred Thirty Four Thousand Five Hundred Sixty Seven\"\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1anum = 1234567891\n\u8f93\u51fa\uff1a\"One Billion Two Hundred Thirty Four Million Five Hundred Sixty Seven Thousand Eight Hundred Ninety One\"\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= num <= 231 - 1
    • \n
    \n", "tags_en": ["Math", "String"], "tags_cn": ["\u6570\u5b66", "\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string numberToWords(int num) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String numberToWords(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numberToWords(self, num):\n \"\"\"\n :type num: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numberToWords(self, num: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * numberToWords(int num){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string NumberToWords(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} num\n * @return {string}\n */\nvar numberToWords = function(num) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} num\n# @return {String}\ndef number_to_words(num)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numberToWords(_ num: Int) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numberToWords(num int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numberToWords(num: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numberToWords(num: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn number_to_words(num: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $num\n * @return String\n */\n function numberToWords($num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numberToWords(num: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (number-to-words num)\n (-> exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0273](https://leetcode-cn.com/problems/integer-to-english-words)", "[\u6574\u6570\u8f6c\u6362\u82f1\u6587\u8868\u793a](/solution/0200-0299/0273.Integer%20to%20English%20Words/README.md)", "`\u6570\u5b66`,`\u5b57\u7b26\u4e32`", "\u56f0\u96be", ""], "md_table_row_en": ["[0273](https://leetcode.com/problems/integer-to-english-words)", "[Integer to English Words](/solution/0200-0299/0273.Integer%20to%20English%20Words/README_EN.md)", "`Math`,`String`", "Hard", ""]}, {"question_id": "0272", "frontend_question_id": "0272", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/closest-binary-search-tree-value-ii", "url_en": "https://leetcode.com/problems/closest-binary-search-tree-value-ii", "relative_path_cn": "/solution/0200-0299/0272.Closest%20Binary%20Search%20Tree%20Value%20II/README.md", "relative_path_en": "/solution/0200-0299/0272.Closest%20Binary%20Search%20Tree%20Value%20II/README_EN.md", "title_cn": "\u6700\u63a5\u8fd1\u7684\u4e8c\u53c9\u641c\u7d22\u6811\u503c II", "title_en": "Closest Binary Search Tree Value II", "question_title_slug": "closest-binary-search-tree-value-ii", "content_en": "

    Given the root of a binary search tree, a target value, and an integer k, return the k values in the BST that are closest to the target. You may return the answer in any order.

    \n\n

    You are guaranteed to have only one unique set of k values in the BST that are closest to the target.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [4,2,5,1,3], target = 3.714286, k = 2\nOutput: [4,3]\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = [1], target = 0.000000, k = 1\nOutput: [1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is n.
    • \n\t
    • 1 <= k <= n <= 104.
    • \n\t
    • 0 <= Node.val <= 109
    • \n\t
    • -109 <= target <= 109
    • \n
    \n\n

     

    \n

    Follow up: Assume that the BST is balanced. Could you solve it in less than O(n) runtime (where n = total nodes)?

    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e0d\u4e3a\u7a7a\u7684\u4e8c\u53c9\u641c\u7d22\u6811\u548c\u4e00\u4e2a\u76ee\u6807\u503c target\uff0c\u8bf7\u5728\u8be5\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u627e\u5230\u6700\u63a5\u8fd1\u76ee\u6807\u503c target \u7684 k \u4e2a\u503c\u3002

    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    • \u7ed9\u5b9a\u7684\u76ee\u6807\u503c target \u662f\u4e00\u4e2a\u6d6e\u70b9\u6570
    • \n\t
    • \u4f60\u53ef\u4ee5\u9ed8\u8ba4 k \u503c\u6c38\u8fdc\u662f\u6709\u6548\u7684\uff0c\u5373 k ≤ \u603b\u7ed3\u70b9\u6570
    • \n\t
    • \u9898\u76ee\u4fdd\u8bc1\u8be5\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u53ea\u4f1a\u5b58\u5728\u4e00\u79cd k \u4e2a\u503c\u96c6\u5408\u6700\u63a5\u8fd1\u76ee\u6807\u503c
    • \n
    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165: root = [4,2,5,1,3]\uff0c\u76ee\u6807\u503c = 3.714286\uff0c\u4e14 k = 2\n\n    4\n   / \\\n  2   5\n / \\\n1   3\n\n\u8f93\u51fa: [4,3]
    \n\n

    \u62d3\u5c55\uff1a
    \n\u5047\u8bbe\u8be5\u4e8c\u53c9\u641c\u7d22\u6811\u662f\u5e73\u8861\u7684\uff0c\u8bf7\u95ee\u60a8\u662f\u5426\u80fd\u5728\u5c0f\u4e8e O(n)\uff08n \u4e3a\u603b\u7ed3\u70b9\u6570\uff09\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u5185\u89e3\u51b3\u8be5\u95ee\u9898\u5462\uff1f

    \n", "tags_en": ["Stack", "Tree"], "tags_cn": ["\u6808", "\u6811"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector closestKValues(TreeNode* root, double target, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public List closestKValues(TreeNode root, double target, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def closestKValues(self, root, target, k):\n \"\"\"\n :type root: TreeNode\n :type target: float\n :type k: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def closestKValues(self, root: TreeNode, target: float, k: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* closestKValues(struct TreeNode* root, double target, int k, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public IList ClosestKValues(TreeNode root, double target, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number} target\n * @param {number} k\n * @return {number[]}\n */\nvar closestKValues = function(root, target, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @param {Float} target\n# @param {Integer} k\n# @return {Integer[]}\ndef closest_k_values(root, target, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func closestKValues(_ root: TreeNode?, _ target: Double, _ k: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc closestKValues(root *TreeNode, target float64, k int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def closestKValues(root: TreeNode, target: Double, k: Int): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun closestKValues(root: TreeNode?, target: Double, k: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn closest_k_values(root: Option>>, target: f64, k: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param Float $target\n * @param Integer $k\n * @return Integer[]\n */\n function closestKValues($root, $target, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction closestKValues(root: TreeNode | null, target: number, k: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (closest-k-values root target k)\n (-> (or/c tree-node? #f) flonum? exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0272](https://leetcode-cn.com/problems/closest-binary-search-tree-value-ii)", "[\u6700\u63a5\u8fd1\u7684\u4e8c\u53c9\u641c\u7d22\u6811\u503c II](/solution/0200-0299/0272.Closest%20Binary%20Search%20Tree%20Value%20II/README.md)", "`\u6808`,`\u6811`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0272](https://leetcode.com/problems/closest-binary-search-tree-value-ii)", "[Closest Binary Search Tree Value II](/solution/0200-0299/0272.Closest%20Binary%20Search%20Tree%20Value%20II/README_EN.md)", "`Stack`,`Tree`", "Hard", "\ud83d\udd12"]}, {"question_id": "0271", "frontend_question_id": "0271", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/encode-and-decode-strings", "url_en": "https://leetcode.com/problems/encode-and-decode-strings", "relative_path_cn": "/solution/0200-0299/0271.Encode%20and%20Decode%20Strings/README.md", "relative_path_en": "/solution/0200-0299/0271.Encode%20and%20Decode%20Strings/README_EN.md", "title_cn": "\u5b57\u7b26\u4e32\u7684\u7f16\u7801\u4e0e\u89e3\u7801", "title_en": "Encode and Decode Strings", "question_title_slug": "encode-and-decode-strings", "content_en": "

    Design an algorithm to encode a list of strings to a string. The encoded string is then sent over the network and is decoded back to the original list of strings.

    \n\n

    Machine 1 (sender) has the function:

    \n\n
    \nstring encode(vector<string> strs) {\n  // ... your code\n  return encoded_string;\n}
    \nMachine 2 (receiver) has the function:\n\n
    \nvector<string> decode(string s) {\n  //... your code\n  return strs;\n}\n
    \n\n

    So Machine 1 does:

    \n\n
    \nstring encoded_string = encode(strs);\n
    \n\n

    and Machine 2 does:

    \n\n
    \nvector<string> strs2 = decode(encoded_string);\n
    \n\n

    strs2 in Machine 2 should be the same as strs in Machine 1.

    \n\n

    Implement the encode and decode methods.

    \n\n

    You are not allowed to solve the problem using any serialize methods (such as eval).

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: dummy_input = ["Hello","World"]\nOutput: ["Hello","World"]\nExplanation:\nMachine 1:\nCodec encoder = new Codec();\nString msg = encoder.encode(strs);\nMachine 1 ---msg---> Machine 2\n\nMachine 2:\nCodec decoder = new Codec();\nString[] strs = decoder.decode(msg);\n
    \n\n

    Example 2:

    \n\n
    \nInput: dummy_input = [""]\nOutput: [""]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= strs.length <= 200
    • \n\t
    • 0 <= strs[i].length <= 200
    • \n\t
    • strs[i] contains any possible characters out of 256 valid ASCII characters.
    • \n
    \n\n

     

    \n

    Follow up: Could you write a generalized algorithm to work on any possible set of characters?

    \n", "content_cn": "

    \u8bf7\u4f60\u8bbe\u8ba1\u4e00\u4e2a\u7b97\u6cd5\uff0c\u53ef\u4ee5\u5c06\u4e00\u4e2a \u5b57\u7b26\u4e32\u5217\u8868 \u7f16\u7801\u6210\u4e3a\u4e00\u4e2a \u5b57\u7b26\u4e32\u3002\u8fd9\u4e2a\u7f16\u7801\u540e\u7684\u5b57\u7b26\u4e32\u662f\u53ef\u4ee5\u901a\u8fc7\u7f51\u7edc\u8fdb\u884c\u9ad8\u6548\u4f20\u9001\u7684\uff0c\u5e76\u4e14\u53ef\u4ee5\u5728\u63a5\u6536\u7aef\u88ab\u89e3\u7801\u56de\u539f\u6765\u7684\u5b57\u7b26\u4e32\u5217\u8868\u3002

    \n\n

    1 \u53f7\u673a\uff08\u53d1\u9001\u65b9\uff09\u6709\u5982\u4e0b\u51fd\u6570\uff1a

    \n\n
    string encode(vector<string> strs) {\n  // ... your code\n  return encoded_string;\n}
    \n\n

    2 \u53f7\u673a\uff08\u63a5\u6536\u65b9\uff09\u6709\u5982\u4e0b\u51fd\u6570\uff1a

    \n\n
    vector<string> decode(string s) {\n  //... your code\n  return strs;\n}\n
    \n\n

    1 \u53f7\u673a\uff08\u53d1\u9001\u65b9\uff09\u6267\u884c\uff1a

    \n\n
    string encoded_string = encode(strs);\n
    \n\n

    2 \u53f7\u673a\uff08\u63a5\u6536\u65b9\uff09\u6267\u884c\uff1a

    \n\n
    vector<string> strs2 = decode(encoded_string);\n
    \n\n

    \u6b64\u65f6\uff0c2 \u53f7\u673a\uff08\u63a5\u6536\u65b9\uff09\u7684 strs2 \u9700\u8981\u548c 1 \u53f7\u673a\uff08\u53d1\u9001\u65b9\uff09\u7684 strs \u76f8\u540c\u3002

    \n\n

    \u8bf7\u4f60\u6765\u5b9e\u73b0\u8fd9\u4e2a encode \u548c decode \u65b9\u6cd5\u3002

    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    • \u56e0\u4e3a\u5b57\u7b26\u4e32\u53ef\u80fd\u4f1a\u5305\u542b 256 \u4e2a\u5408\u6cd5 ascii \u5b57\u7b26\u4e2d\u7684\u4efb\u4f55\u5b57\u7b26\uff0c\u6240\u4ee5\u60a8\u7684\u7b97\u6cd5\u5fc5\u987b\u8981\u80fd\u591f\u5904\u7406\u4efb\u4f55\u53ef\u80fd\u4f1a\u51fa\u73b0\u7684\u5b57\u7b26\u3002
    • \n\t
    • \u8bf7\u52ff\u4f7f\u7528 “\u7c7b\u6210\u5458”\u3001“\u5168\u5c40\u53d8\u91cf” \u6216 “\u9759\u6001\u53d8\u91cf” \u6765\u5b58\u50a8\u8fd9\u4e9b\u72b6\u6001\uff0c\u60a8\u7684\u7f16\u7801\u548c\u89e3\u7801\u7b97\u6cd5\u5e94\u8be5\u662f\u975e\u72b6\u6001\u4f9d\u8d56\u7684\u3002
    • \n\t
    • \u8bf7\u4e0d\u8981\u4f9d\u8d56\u4efb\u4f55\u65b9\u6cd5\u5e93\uff0c\u4f8b\u5982 eval \u53c8\u6216\u8005\u662f serialize \u4e4b\u7c7b\u7684\u65b9\u6cd5\u3002\u672c\u9898\u7684\u5b97\u65e8\u662f\u9700\u8981\u60a8\u81ea\u5df1\u5b9e\u73b0 “\u7f16\u7801” \u548c “\u89e3\u7801” \u7b97\u6cd5\u3002
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Codec {\npublic:\n\n // Encodes a list of strings to a single string.\n string encode(vector& strs) {\n \n }\n\n // Decodes a single string to a list of strings.\n vector decode(string s) {\n \n }\n};\n\n// Your Codec object will be instantiated and called as such:\n// Codec codec;\n// codec.decode(codec.encode(strs));", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "public class Codec {\n\n // Encodes a list of strings to a single string.\n public String encode(List strs) {\n \n }\n\n // Decodes a single string to a list of strings.\n public List decode(String s) {\n \n }\n}\n\n// Your Codec object will be instantiated and called as such:\n// Codec codec = new Codec();\n// codec.decode(codec.encode(strs));", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Codec:\n\n def encode(self, strs):\n \"\"\"Encodes a list of strings to a single string.\n \n :type strs: List[str]\n :rtype: str\n \"\"\"\n \n\n def decode(self, s):\n \"\"\"Decodes a single string to a list of strings.\n \n :type s: str\n :rtype: List[str]\n \"\"\"\n \n\n# Your Codec object will be instantiated and called as such:\n# codec = Codec()\n# codec.decode(codec.encode(strs))", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Codec:\n def encode(self, strs: [str]) -> str:\n \"\"\"Encodes a list of strings to a single string.\n \"\"\"\n \n\n def decode(self, s: str) -> [str]:\n \"\"\"Decodes a single string to a list of strings.\n \"\"\"\n \n\n\n# Your Codec object will be instantiated and called as such:\n# codec = Codec()\n# codec.decode(codec.encode(strs))", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/** Encodes a list of strings to a single string */\nchar* encode(char** strs, int strsSize) {\n \n}\n\n/**\n * Decodes a single string to a list of strings.\n *\n * Return an array of size *returnSize.\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar** decode(char* s, int* returnSize) {\n \n}\n\n// Your functions will be called as such:\n// char* s = encode(strs, strsSize);\n// decode(s, &returnSize);", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Codec {\n\n // Encodes a list of strings to a single string.\n public string encode(IList strs) {\n \n }\n\n // Decodes a single string to a list of strings.\n public IList decode(string s) {\n \n }\n}\n\n// Your Codec object will be instantiated and called as such:\n// Codec codec = new Codec();\n// codec.decode(codec.encode(strs));", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Encodes a list of strings to a single string.\n *\n * @param {string[]} strs\n * @return {string}\n */\nvar encode = function(strs) {\n \n};\n\n/**\n * Decodes a single string to a list of strings.\n *\n * @param {string} s\n * @return {string[]}\n */\nvar decode = function(s) {\n \n};\n\n/**\n * Your functions will be called as such:\n * decode(encode(strs));\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Encodes a list of strings to a single string.\n#\n# @param {string[]} strs\n# @return {string}\ndef encode(strs)\n \nend\n\n# Decodes a single string to a list of strings.\n#\n# @param {string} s\n# @return {string[]}\ndef decode(s)\n \nend\n\n\n# Your functions will be called as such:\n# decode(encode(strs))", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Codec {\n func encode(_ strs: [String]) -> String {\n \n }\n \n func decode(_ s: String) -> [String] {\n \n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * let obj = Codec()\n * val s = obj.encode(strs)\n * let ans = obj.decode(s)\n*/", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type Codec struct {\n \n}\n\n// Encodes a list of strings to a single string.\nfunc (codec *Codec) Encode(strs []string) string {\n \n}\n\n// Decodes a single string to a list of strings.\nfunc (codec *Codec) Decode(strs string) []string {\n \n}\n\n// Your Codec object will be instantiated and called as such:\n// var codec Codec\n// codec.Decode(codec.Encode(strs));", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class Codec {\n // Encodes a list of strings to a single string.\n def encode(strs: List[String]): String = {\n \n }\n \n // Decodes a single string to a list of strings.\n def decode(s: String): List[String] = {\n \n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * var obj = new Codec()\n * val s = obj.encode(strs)\n * val ans = obj.decode(s)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Codec {\n // Encodes a list of strings to a single string.\n fun encode(strs: List): String {\n \n }\n \n // Decodes a single string to a list of strings.\n fun decode(s: String): List {\n \n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * var obj = Codec()\n * val s = obj.encode(strs)\n * val ans = obj.decode(s)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct Codec {\n\t\n}\n\n/** \n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl Codec {\n fn new() -> Self {\n \n }\n\t\n fn encode(&self, strs: Vec) -> String {\n \n }\n\t\n fn decode(&self, s: String) -> Vec {\n \n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * let obj = Codec::new();\n * let s: String = obj.encode(strs);\n * let ans: VecVec = obj.decode(s);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Codec {\n /**\n * @param String[] $strs\n * @return String\n */\n function encode($strs) {\n \n }\n \n /**\n * @param String $s\n * @return String[]\n */\n function decode($s) {\n \n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * $obj = Codec();\n * $s = $obj->encode($strs);\n * $ans = $obj->decode($s);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Encodes a list of strings to a single string.\n */\nfunction encode(strs: string[]): string {\n\t\n};\n\n/**\n * Decodes a single string to a list of strings.\n */\nfunction decode(s: string): string[] {\n\t\n};\n\n/**\n * Your functions will be called as such:\n * decode(encode(strs));\n */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0271](https://leetcode-cn.com/problems/encode-and-decode-strings)", "[\u5b57\u7b26\u4e32\u7684\u7f16\u7801\u4e0e\u89e3\u7801](/solution/0200-0299/0271.Encode%20and%20Decode%20Strings/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0271](https://leetcode.com/problems/encode-and-decode-strings)", "[Encode and Decode Strings](/solution/0200-0299/0271.Encode%20and%20Decode%20Strings/README_EN.md)", "`String`", "Medium", "\ud83d\udd12"]}, {"question_id": "0270", "frontend_question_id": "0270", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/closest-binary-search-tree-value", "url_en": "https://leetcode.com/problems/closest-binary-search-tree-value", "relative_path_cn": "/solution/0200-0299/0270.Closest%20Binary%20Search%20Tree%20Value/README.md", "relative_path_en": "/solution/0200-0299/0270.Closest%20Binary%20Search%20Tree%20Value/README_EN.md", "title_cn": "\u6700\u63a5\u8fd1\u7684\u4e8c\u53c9\u641c\u7d22\u6811\u503c", "title_en": "Closest Binary Search Tree Value", "question_title_slug": "closest-binary-search-tree-value", "content_en": "

    Given the root of a binary search tree and a target value, return the value in the BST that is closest to the target.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [4,2,5,1,3], target = 3.714286\nOutput: 4\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = [1], target = 4.428571\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 104].
    • \n\t
    • 0 <= Node.val <= 109
    • \n\t
    • -109 <= target <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e0d\u4e3a\u7a7a\u7684\u4e8c\u53c9\u641c\u7d22\u6811\u548c\u4e00\u4e2a\u76ee\u6807\u503c target\uff0c\u8bf7\u5728\u8be5\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u627e\u5230\u6700\u63a5\u8fd1\u76ee\u6807\u503c target \u7684\u6570\u503c\u3002

    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    • \u7ed9\u5b9a\u7684\u76ee\u6807\u503c target \u662f\u4e00\u4e2a\u6d6e\u70b9\u6570
    • \n\t
    • \u9898\u76ee\u4fdd\u8bc1\u5728\u8be5\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u53ea\u4f1a\u5b58\u5728\u4e00\u4e2a\u6700\u63a5\u8fd1\u76ee\u6807\u503c\u7684\u6570
    • \n
    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165: root = [4,2,5,1,3]\uff0c\u76ee\u6807\u503c target = 3.714286\n\n    4\n   / \\\n  2   5\n / \\\n1   3\n\n\u8f93\u51fa: 4\n
    \n", "tags_en": ["Tree", "Binary Search"], "tags_cn": ["\u6811", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int closestValue(TreeNode* root, double target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int closestValue(TreeNode root, double target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def closestValue(self, root, target):\n \"\"\"\n :type root: TreeNode\n :type target: float\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def closestValue(self, root: TreeNode, target: float) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint closestValue(struct TreeNode* root, double target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int ClosestValue(TreeNode root, double target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number} target\n * @return {number}\n */\nvar closestValue = function(root, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @param {Float} target\n# @return {Integer}\ndef closest_value(root, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func closestValue(_ root: TreeNode?, _ target: Double) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc closestValue(root *TreeNode, target float64) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def closestValue(root: TreeNode, target: Double): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun closestValue(root: TreeNode?, target: Double): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn closest_value(root: Option>>, target: f64) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param Float $target\n * @return Integer\n */\n function closestValue($root, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction closestValue(root: TreeNode | null, target: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (closest-value root target)\n (-> (or/c tree-node? #f) flonum? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0270](https://leetcode-cn.com/problems/closest-binary-search-tree-value)", "[\u6700\u63a5\u8fd1\u7684\u4e8c\u53c9\u641c\u7d22\u6811\u503c](/solution/0200-0299/0270.Closest%20Binary%20Search%20Tree%20Value/README.md)", "`\u6811`,`\u4e8c\u5206\u67e5\u627e`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0270](https://leetcode.com/problems/closest-binary-search-tree-value)", "[Closest Binary Search Tree Value](/solution/0200-0299/0270.Closest%20Binary%20Search%20Tree%20Value/README_EN.md)", "`Tree`,`Binary Search`", "Easy", "\ud83d\udd12"]}, {"question_id": "0269", "frontend_question_id": "0269", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/alien-dictionary", "url_en": "https://leetcode.com/problems/alien-dictionary", "relative_path_cn": "/solution/0200-0299/0269.Alien%20Dictionary/README.md", "relative_path_en": "/solution/0200-0299/0269.Alien%20Dictionary/README_EN.md", "title_cn": "\u706b\u661f\u8bcd\u5178", "title_en": "Alien Dictionary", "question_title_slug": "alien-dictionary", "content_en": "

    There is a new alien language that uses the English alphabet. However, the order among the letters is unknown to you.

    \n\n

    You are given a list of strings words from the alien language's dictionary, where the strings in words are sorted lexicographically by the rules of this new language.

    \n\n

    Return a string of the unique letters in the new alien language sorted in lexicographically increasing order by the new language's rules. If there is no solution, return "". If there are multiple solutions, return any of them.

    \n\n

    A string s is lexicographically smaller than a string t if at the first letter where they differ, the letter in s comes before the letter in t in the alien language. If the first min(s.length, t.length) letters are the same, then s is smaller if and only if s.length < t.length.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: words = ["wrt","wrf","er","ett","rftt"]\nOutput: "wertf"\n
    \n\n

    Example 2:

    \n\n
    \nInput: words = ["z","x"]\nOutput: "zx"\n
    \n\n

    Example 3:

    \n\n
    \nInput: words = ["z","x","z"]\nOutput: ""\nExplanation: The order is invalid, so return "".\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= words.length <= 100
    • \n\t
    • 1 <= words[i].length <= 100
    • \n\t
    • words[i] consists of only lowercase English letters.
    • \n
    \n", "content_cn": "

    \u73b0\u6709\u4e00\u79cd\u4f7f\u7528\u82f1\u8bed\u5b57\u6bcd\u7684\u706b\u661f\u8bed\u8a00\uff0c\u8fd9\u95e8\u8bed\u8a00\u7684\u5b57\u6bcd\u987a\u5e8f\u4e0e\u82f1\u8bed\u987a\u5e8f\u4e0d\u540c\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32\u5217\u8868 words \uff0c\u4f5c\u4e3a\u8fd9\u95e8\u8bed\u8a00\u7684\u8bcd\u5178\uff0cwords \u4e2d\u7684\u5b57\u7b26\u4e32\u5df2\u7ecf \u6309\u8fd9\u95e8\u65b0\u8bed\u8a00\u7684\u5b57\u6bcd\u987a\u5e8f\u8fdb\u884c\u4e86\u6392\u5e8f \u3002

    \n\n

    \u8bf7\u4f60\u6839\u636e\u8be5\u8bcd\u5178\u8fd8\u539f\u51fa\u6b64\u8bed\u8a00\u4e2d\u5df2\u77e5\u7684\u5b57\u6bcd\u987a\u5e8f\uff0c\u5e76 \u6309\u5b57\u6bcd\u9012\u589e\u987a\u5e8f \u6392\u5217\u3002\u82e5\u4e0d\u5b58\u5728\u5408\u6cd5\u5b57\u6bcd\u987a\u5e8f\uff0c\u8fd4\u56de \"\" \u3002\u82e5\u5b58\u5728\u591a\u79cd\u53ef\u80fd\u7684\u5408\u6cd5\u5b57\u6bcd\u987a\u5e8f\uff0c\u8fd4\u56de\u5176\u4e2d \u4efb\u610f\u4e00\u79cd \u987a\u5e8f\u5373\u53ef\u3002

    \n\n

    \u5b57\u7b26\u4e32 s \u5b57\u5178\u987a\u5e8f\u5c0f\u4e8e \u5b57\u7b26\u4e32 t \u6709\u4e24\u79cd\u60c5\u51b5\uff1a

    \n\n
      \n\t
    • \u5728\u7b2c\u4e00\u4e2a\u4e0d\u540c\u5b57\u6bcd\u5904\uff0c\u5982\u679c s \u4e2d\u7684\u5b57\u6bcd\u5728\u8fd9\u95e8\u5916\u661f\u8bed\u8a00\u7684\u5b57\u6bcd\u987a\u5e8f\u4e2d\u4f4d\u4e8e t \u4e2d\u5b57\u6bcd\u4e4b\u524d\uff0c\u90a3\u4e48\u00a0s \u7684\u5b57\u5178\u987a\u5e8f\u5c0f\u4e8e t \u3002
    • \n\t
    • \u5982\u679c\u524d\u9762 min(s.length, t.length) \u5b57\u6bcd\u90fd\u76f8\u540c\uff0c\u90a3\u4e48 s.length < t.length \u65f6\uff0cs \u7684\u5b57\u5178\u987a\u5e8f\u4e5f\u5c0f\u4e8e t \u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1awords = [\"wrt\",\"wrf\",\"er\",\"ett\",\"rftt\"]\n\u8f93\u51fa\uff1a\"wertf\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1awords = [\"z\",\"x\"]\n\u8f93\u51fa\uff1a\"zx\"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1awords = [\"z\",\"x\",\"z\"]\n\u8f93\u51fa\uff1a\"\"\n\u89e3\u91ca\uff1a\u4e0d\u5b58\u5728\u5408\u6cd5\u5b57\u6bcd\u987a\u5e8f\uff0c\u56e0\u6b64\u8fd4\u56de \"\" \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= words.length <= 100
    • \n\t
    • 1 <= words[i].length <= 100
    • \n\t
    • words[i] \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n", "tags_en": ["Graph", "Topological Sort"], "tags_cn": ["\u56fe", "\u62d3\u6251\u6392\u5e8f"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string alienOrder(vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String alienOrder(String[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def alienOrder(self, words):\n \"\"\"\n :type words: List[str]\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def alienOrder(self, words: List[str]) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * alienOrder(char ** words, int wordsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string AlienOrder(string[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @return {string}\n */\nvar alienOrder = function(words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @return {String}\ndef alien_order(words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func alienOrder(_ words: [String]) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func alienOrder(words []string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def alienOrder(words: Array[String]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun alienOrder(words: Array): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn alien_order(words: Vec) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @return String\n */\n function alienOrder($words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function alienOrder(words: string[]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (alien-order words)\n (-> (listof string?) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0269](https://leetcode-cn.com/problems/alien-dictionary)", "[\u706b\u661f\u8bcd\u5178](/solution/0200-0299/0269.Alien%20Dictionary/README.md)", "`\u56fe`,`\u62d3\u6251\u6392\u5e8f`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0269](https://leetcode.com/problems/alien-dictionary)", "[Alien Dictionary](/solution/0200-0299/0269.Alien%20Dictionary/README_EN.md)", "`Graph`,`Topological Sort`", "Hard", "\ud83d\udd12"]}, {"question_id": "0268", "frontend_question_id": "0268", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/missing-number", "url_en": "https://leetcode.com/problems/missing-number", "relative_path_cn": "/solution/0200-0299/0268.Missing%20Number/README.md", "relative_path_en": "/solution/0200-0299/0268.Missing%20Number/README_EN.md", "title_cn": "\u4e22\u5931\u7684\u6570\u5b57", "title_en": "Missing Number", "question_title_slug": "missing-number", "content_en": "

    Given an array nums containing n distinct numbers in the range [0, n], return the only number in the range that is missing from the array.

    \n\n

    Follow up: Could you implement a solution using only O(1) extra space complexity and O(n) runtime complexity?

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [3,0,1]\nOutput: 2\nExplanation: n = 3 since there are 3 numbers, so all numbers are in the range [0,3]. 2 is the missing number in the range since it does not appear in nums.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [0,1]\nOutput: 2\nExplanation: n = 2 since there are 2 numbers, so all numbers are in the range [0,2]. 2 is the missing number in the range since it does not appear in nums.\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [9,6,4,2,3,5,7,0,1]\nOutput: 8\nExplanation: n = 9 since there are 9 numbers, so all numbers are in the range [0,9]. 8 is the missing number in the range since it does not appear in nums.\n
    \n\n

    Example 4:

    \n\n
    \nInput: nums = [0]\nOutput: 1\nExplanation: n = 1 since there is 1 number, so all numbers are in the range [0,1]. 1 is the missing number in the range since it does not appear in nums.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= n <= 104
    • \n\t
    • 0 <= nums[i] <= n
    • \n\t
    • All the numbers of nums are unique.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5305\u542b [0, n]\u00a0\u4e2d\u00a0n\u00a0\u4e2a\u6570\u7684\u6570\u7ec4 nums \uff0c\u627e\u51fa [0, n] \u8fd9\u4e2a\u8303\u56f4\u5185\u6ca1\u6709\u51fa\u73b0\u5728\u6570\u7ec4\u4e2d\u7684\u90a3\u4e2a\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u4f60\u80fd\u5426\u5b9e\u73b0\u7ebf\u6027\u65f6\u95f4\u590d\u6742\u5ea6\u3001\u4ec5\u4f7f\u7528\u989d\u5916\u5e38\u6570\u7a7a\u95f4\u7684\u7b97\u6cd5\u89e3\u51b3\u6b64\u95ee\u9898?
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [3,0,1]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1an = 3\uff0c\u56e0\u4e3a\u6709 3 \u4e2a\u6570\u5b57\uff0c\u6240\u4ee5\u6240\u6709\u7684\u6570\u5b57\u90fd\u5728\u8303\u56f4 [0,3] \u5185\u30022 \u662f\u4e22\u5931\u7684\u6570\u5b57\uff0c\u56e0\u4e3a\u5b83\u6ca1\u6709\u51fa\u73b0\u5728 nums \u4e2d\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [0,1]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1an = 2\uff0c\u56e0\u4e3a\u6709 2 \u4e2a\u6570\u5b57\uff0c\u6240\u4ee5\u6240\u6709\u7684\u6570\u5b57\u90fd\u5728\u8303\u56f4 [0,2] \u5185\u30022 \u662f\u4e22\u5931\u7684\u6570\u5b57\uff0c\u56e0\u4e3a\u5b83\u6ca1\u6709\u51fa\u73b0\u5728 nums \u4e2d\u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [9,6,4,2,3,5,7,0,1]\n\u8f93\u51fa\uff1a8\n\u89e3\u91ca\uff1an = 9\uff0c\u56e0\u4e3a\u6709 9 \u4e2a\u6570\u5b57\uff0c\u6240\u4ee5\u6240\u6709\u7684\u6570\u5b57\u90fd\u5728\u8303\u56f4 [0,9] \u5185\u30028 \u662f\u4e22\u5931\u7684\u6570\u5b57\uff0c\u56e0\u4e3a\u5b83\u6ca1\u6709\u51fa\u73b0\u5728 nums \u4e2d\u3002
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [0]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1an = 1\uff0c\u56e0\u4e3a\u6709 1 \u4e2a\u6570\u5b57\uff0c\u6240\u4ee5\u6240\u6709\u7684\u6570\u5b57\u90fd\u5728\u8303\u56f4 [0,1] \u5185\u30021 \u662f\u4e22\u5931\u7684\u6570\u5b57\uff0c\u56e0\u4e3a\u5b83\u6ca1\u6709\u51fa\u73b0\u5728 nums \u4e2d\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= n <= 104
    • \n\t
    • 0 <= nums[i] <= n
    • \n\t
    • nums \u4e2d\u7684\u6240\u6709\u6570\u5b57\u90fd \u72ec\u4e00\u65e0\u4e8c
    • \n
    \n", "tags_en": ["Bit Manipulation", "Array", "Math"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u6570\u7ec4", "\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int missingNumber(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int missingNumber(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def missingNumber(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def missingNumber(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint missingNumber(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MissingNumber(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar missingNumber = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef missing_number(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func missingNumber(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func missingNumber(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def missingNumber(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun missingNumber(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn missing_number(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function missingNumber($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function missingNumber(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (missing-number nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0268](https://leetcode-cn.com/problems/missing-number)", "[\u4e22\u5931\u7684\u6570\u5b57](/solution/0200-0299/0268.Missing%20Number/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u6570\u7ec4`,`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0268](https://leetcode.com/problems/missing-number)", "[Missing Number](/solution/0200-0299/0268.Missing%20Number/README_EN.md)", "`Bit Manipulation`,`Array`,`Math`", "Easy", ""]}, {"question_id": "0267", "frontend_question_id": "0267", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/palindrome-permutation-ii", "url_en": "https://leetcode.com/problems/palindrome-permutation-ii", "relative_path_cn": "/solution/0200-0299/0267.Palindrome%20Permutation%20II/README.md", "relative_path_en": "/solution/0200-0299/0267.Palindrome%20Permutation%20II/README_EN.md", "title_cn": "\u56de\u6587\u6392\u5217 II", "title_en": "Palindrome Permutation II", "question_title_slug": "palindrome-permutation-ii", "content_en": "

    Given a string s, return all the palindromic permutations (without duplicates) of it.

    \n\n

    You may return the answer in any order. If s has no palindromic permutation, return an empty list.

    \n\n

     

    \n

    Example 1:

    \n
    Input: s = \"aabb\"\nOutput: [\"abba\",\"baab\"]\n

    Example 2:

    \n
    Input: s = \"abc\"\nOutput: []\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 16
    • \n\t
    • s consists of only lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32 s \uff0c\u8fd4\u56de\u5176\u901a\u8fc7\u91cd\u65b0\u6392\u5217\u7ec4\u5408\u540e\u6240\u6709\u53ef\u80fd\u7684\u56de\u6587\u5b57\u7b26\u4e32\uff0c\u5e76\u53bb\u9664\u91cd\u590d\u7684\u7ec4\u5408\u3002

    \n\n

    \u5982\u4e0d\u80fd\u5f62\u6210\u4efb\u4f55\u56de\u6587\u6392\u5217\u65f6\uff0c\u5219\u8fd4\u56de\u4e00\u4e2a\u7a7a\u5217\u8868\u3002

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165: "aabb"\n\u8f93\u51fa: ["abba", "baab"]
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165: "abc"\n\u8f93\u51fa: []
    \n", "tags_en": ["Backtracking"], "tags_cn": ["\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector generatePalindromes(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List generatePalindromes(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def generatePalindromes(self, s):\n \"\"\"\n :type s: str\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def generatePalindromes(self, s: str) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** generatePalindromes(char * s, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList GeneratePalindromes(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string[]}\n */\nvar generatePalindromes = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String[]}\ndef generate_palindromes(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func generatePalindromes(_ s: String) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func generatePalindromes(s string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def generatePalindromes(s: String): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun generatePalindromes(s: String): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn generate_palindromes(s: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String[]\n */\n function generatePalindromes($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function generatePalindromes(s: string): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (generate-palindromes s)\n (-> string? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0267](https://leetcode-cn.com/problems/palindrome-permutation-ii)", "[\u56de\u6587\u6392\u5217 II](/solution/0200-0299/0267.Palindrome%20Permutation%20II/README.md)", "`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0267](https://leetcode.com/problems/palindrome-permutation-ii)", "[Palindrome Permutation II](/solution/0200-0299/0267.Palindrome%20Permutation%20II/README_EN.md)", "`Backtracking`", "Medium", "\ud83d\udd12"]}, {"question_id": "0266", "frontend_question_id": "0266", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/palindrome-permutation", "url_en": "https://leetcode.com/problems/palindrome-permutation", "relative_path_cn": "/solution/0200-0299/0266.Palindrome%20Permutation/README.md", "relative_path_en": "/solution/0200-0299/0266.Palindrome%20Permutation/README_EN.md", "title_cn": "\u56de\u6587\u6392\u5217", "title_en": "Palindrome Permutation", "question_title_slug": "palindrome-permutation", "content_en": "

    Given a string s, return true if a permutation of the string could form a palindrome.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "code"\nOutput: false\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "aab"\nOutput: true\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "carerac"\nOutput: true\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 5000
    • \n\t
    • s consists of only lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u5224\u65ad\u8be5\u5b57\u7b26\u4e32\u4e2d\u662f\u5426\u53ef\u4ee5\u901a\u8fc7\u91cd\u65b0\u6392\u5217\u7ec4\u5408\uff0c\u5f62\u6210\u4e00\u4e2a\u56de\u6587\u5b57\u7b26\u4e32\u3002

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165: "code"\n\u8f93\u51fa: false
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165: "aab"\n\u8f93\u51fa: true
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165: "carerac"\n\u8f93\u51fa: true
    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canPermutePalindrome(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canPermutePalindrome(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canPermutePalindrome(self, s):\n \"\"\"\n :type s: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canPermutePalindrome(self, s: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canPermutePalindrome(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanPermutePalindrome(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {boolean}\n */\nvar canPermutePalindrome = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Boolean}\ndef can_permute_palindrome(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canPermutePalindrome(_ s: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canPermutePalindrome(s string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canPermutePalindrome(s: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canPermutePalindrome(s: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_permute_palindrome(s: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Boolean\n */\n function canPermutePalindrome($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canPermutePalindrome(s: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-permute-palindrome s)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0266](https://leetcode-cn.com/problems/palindrome-permutation)", "[\u56de\u6587\u6392\u5217](/solution/0200-0299/0266.Palindrome%20Permutation/README.md)", "`\u54c8\u5e0c\u8868`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0266](https://leetcode.com/problems/palindrome-permutation)", "[Palindrome Permutation](/solution/0200-0299/0266.Palindrome%20Permutation/README_EN.md)", "`Hash Table`", "Easy", "\ud83d\udd12"]}, {"question_id": "0265", "frontend_question_id": "0265", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/paint-house-ii", "url_en": "https://leetcode.com/problems/paint-house-ii", "relative_path_cn": "/solution/0200-0299/0265.Paint%20House%20II/README.md", "relative_path_en": "/solution/0200-0299/0265.Paint%20House%20II/README_EN.md", "title_cn": "\u7c89\u5237\u623f\u5b50 II", "title_en": "Paint House II", "question_title_slug": "paint-house-ii", "content_en": "

    There are a row of n houses, each house can be painted with one of the k colors. The cost of painting each house with a certain color is different. You have to paint all the houses such that no two adjacent houses have the same color.

    \n\n

    The cost of painting each house with a certain color is represented by an n x k cost matrix costs.

    \n\n
      \n\t
    • For example, costs[0][0] is the cost of painting house 0 with color 0; costs[1][2] is the cost of painting house 1 with color 2, and so on...
    • \n
    \n\n

    Return the minimum cost to paint all houses.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: costs = [[1,5,3],[2,9,4]]\nOutput: 5\nExplanation:\nPaint house 0 into color 0, paint house 1 into color 2. Minimum cost: 1 + 4 = 5; \nOr paint house 0 into color 2, paint house 1 into color 0. Minimum cost: 3 + 2 = 5.\n
    \n\n

    Example 2:

    \n\n
    \nInput: costs = [[1,3],[2,4]]\nOutput: 5\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • costs.length == n
    • \n\t
    • costs[i].length == k
    • \n\t
    • 1 <= n <= 100
    • \n\t
    • 1 <= k <= 20
    • \n\t
    • 1 <= costs[i][j] <= 20
    • \n
    \n\n

     

    \n

    Follow up: Could you solve it in O(nk) runtime?

    \n", "content_cn": "

    \u5047\u5982\u6709\u4e00\u6392\u623f\u5b50\uff0c\u5171 n \u4e2a\uff0c\u6bcf\u4e2a\u623f\u5b50\u53ef\u4ee5\u88ab\u7c89\u5237\u6210 k \u79cd\u989c\u8272\u4e2d\u7684\u4e00\u79cd\uff0c\u4f60\u9700\u8981\u7c89\u5237\u6240\u6709\u7684\u623f\u5b50\u5e76\u4e14\u4f7f\u5176\u76f8\u90bb\u7684\u4e24\u4e2a\u623f\u5b50\u989c\u8272\u4e0d\u80fd\u76f8\u540c\u3002

    \n\n

    \u5f53\u7136\uff0c\u56e0\u4e3a\u5e02\u573a\u4e0a\u4e0d\u540c\u989c\u8272\u6cb9\u6f06\u7684\u4ef7\u683c\u4e0d\u540c\uff0c\u6240\u4ee5\u623f\u5b50\u7c89\u5237\u6210\u4e0d\u540c\u989c\u8272\u7684\u82b1\u8d39\u6210\u672c\u4e5f\u662f\u4e0d\u540c\u7684\u3002\u6bcf\u4e2a\u623f\u5b50\u7c89\u5237\u6210\u4e0d\u540c\u989c\u8272\u7684\u82b1\u8d39\u662f\u4ee5\u4e00\u4e2a n x k \u7684\u77e9\u9635\u6765\u8868\u793a\u7684\u3002

    \n\n

    \u4f8b\u5982\uff0ccosts[0][0] \u8868\u793a\u7b2c 0 \u53f7\u623f\u5b50\u7c89\u5237\u6210 0 \u53f7\u989c\u8272\u7684\u6210\u672c\u82b1\u8d39\uff1bcosts[1][2] \u8868\u793a\u7b2c 1 \u53f7\u623f\u5b50\u7c89\u5237\u6210 2 \u53f7\u989c\u8272\u7684\u6210\u672c\u82b1\u8d39\uff0c\u4ee5\u6b64\u7c7b\u63a8\u3002\u8bf7\u4f60\u8ba1\u7b97\u51fa\u7c89\u5237\u5b8c\u6240\u6709\u623f\u5b50\u6700\u5c11\u7684\u82b1\u8d39\u6210\u672c\u3002

    \n\n

    \u6ce8\u610f\uff1a

    \n\n

    \u6240\u6709\u82b1\u8d39\u5747\u4e3a\u6b63\u6574\u6570\u3002

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165: [[1,5,3],[2,9,4]]\n\u8f93\u51fa: 5\n\u89e3\u91ca: \u5c06 0 \u53f7\u623f\u5b50\u7c89\u5237\u6210 0 \u53f7\u989c\u8272\uff0c1 \u53f7\u623f\u5b50\u7c89\u5237\u6210 2 \u53f7\u989c\u8272\u3002\u6700\u5c11\u82b1\u8d39: 1 + 4 = 5; \n     \u6216\u8005\u5c06 0 \u53f7\u623f\u5b50\u7c89\u5237\u6210 2 \u53f7\u989c\u8272\uff0c1 \u53f7\u623f\u5b50\u7c89\u5237\u6210 0 \u53f7\u989c\u8272\u3002\u6700\u5c11\u82b1\u8d39: 3 + 2 = 5. \n
    \n\n

    \u8fdb\u9636\uff1a
    \n\u60a8\u80fd\u5426\u5728 O(nk) \u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e0b\u89e3\u51b3\u6b64\u95ee\u9898\uff1f

    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minCostII(vector>& costs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minCostII(int[][] costs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minCostII(self, costs):\n \"\"\"\n :type costs: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minCostII(self, costs: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minCostII(int** costs, int costsSize, int* costsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinCostII(int[][] costs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} costs\n * @return {number}\n */\nvar minCostII = function(costs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} costs\n# @return {Integer}\ndef min_cost_ii(costs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minCostII(_ costs: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minCostII(costs [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minCostII(costs: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minCostII(costs: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_cost_ii(costs: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $costs\n * @return Integer\n */\n function minCostII($costs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minCostII(costs: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-cost-ii costs)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0265](https://leetcode-cn.com/problems/paint-house-ii)", "[\u7c89\u5237\u623f\u5b50 II](/solution/0200-0299/0265.Paint%20House%20II/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0265](https://leetcode.com/problems/paint-house-ii)", "[Paint House II](/solution/0200-0299/0265.Paint%20House%20II/README_EN.md)", "`Dynamic Programming`", "Hard", "\ud83d\udd12"]}, {"question_id": "0264", "frontend_question_id": "0264", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/ugly-number-ii", "url_en": "https://leetcode.com/problems/ugly-number-ii", "relative_path_cn": "/solution/0200-0299/0264.Ugly%20Number%20II/README.md", "relative_path_en": "/solution/0200-0299/0264.Ugly%20Number%20II/README_EN.md", "title_cn": "\u4e11\u6570 II", "title_en": "Ugly Number II", "question_title_slug": "ugly-number-ii", "content_en": "

    An ugly number is a positive integer whose prime factors are limited to 2, 3, and 5.

    \n\n

    Given an integer n, return the nth ugly number.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 10\nOutput: 12\nExplanation: [1, 2, 3, 4, 5, 6, 8, 9, 10, 12] is the sequence of the first 10 ugly numbers.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 1\nOutput: 1\nExplanation: 1 has no prime factors, therefore all of its prime factors are limited to 2, 3, and 5.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 1690
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n \uff0c\u8bf7\u4f60\u627e\u51fa\u5e76\u8fd4\u56de\u7b2c n \u4e2a \u4e11\u6570 \u3002

    \n\n

    \u4e11\u6570 \u5c31\u662f\u53ea\u5305\u542b\u8d28\u56e0\u6570\u00a02\u30013 \u548c/\u6216\u00a05\u00a0\u7684\u6b63\u6574\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 10\n\u8f93\u51fa\uff1a12\n\u89e3\u91ca\uff1a[1, 2, 3, 4, 5, 6, 8, 9, 10, 12] \u662f\u7531\u524d 10 \u4e2a\u4e11\u6570\u7ec4\u6210\u7684\u5e8f\u5217\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a1 \u901a\u5e38\u88ab\u89c6\u4e3a\u4e11\u6570\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 1690
    • \n
    \n", "tags_en": ["Heap", "Math", "Dynamic Programming"], "tags_cn": ["\u5806", "\u6570\u5b66", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int nthUglyNumber(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def nthUglyNumber(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def nthUglyNumber(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint nthUglyNumber(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NthUglyNumber(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar nthUglyNumber = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef nth_ugly_number(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func nthUglyNumber(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func nthUglyNumber(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def nthUglyNumber(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun nthUglyNumber(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn nth_ugly_number(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function nthUglyNumber($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function nthUglyNumber(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (nth-ugly-number n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0264](https://leetcode-cn.com/problems/ugly-number-ii)", "[\u4e11\u6570 II](/solution/0200-0299/0264.Ugly%20Number%20II/README.md)", "`\u5806`,`\u6570\u5b66`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0264](https://leetcode.com/problems/ugly-number-ii)", "[Ugly Number II](/solution/0200-0299/0264.Ugly%20Number%20II/README_EN.md)", "`Heap`,`Math`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0263", "frontend_question_id": "0263", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/ugly-number", "url_en": "https://leetcode.com/problems/ugly-number", "relative_path_cn": "/solution/0200-0299/0263.Ugly%20Number/README.md", "relative_path_en": "/solution/0200-0299/0263.Ugly%20Number/README_EN.md", "title_cn": "\u4e11\u6570", "title_en": "Ugly Number", "question_title_slug": "ugly-number", "content_en": "

    An ugly number is a positive integer whose prime factors are limited to 2, 3, and 5.

    \n\n

    Given an integer n, return true if n is an ugly number.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 6\nOutput: true\nExplanation: 6 = 2 × 3
    \n\n

    Example 2:

    \n\n
    \nInput: n = 8\nOutput: true\nExplanation: 8 = 2 × 2 × 2\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 14\nOutput: false\nExplanation: 14 is not ugly since it includes the prime factor 7.\n
    \n\n

    Example 4:

    \n\n
    \nInput: n = 1\nOutput: true\nExplanation: 1 has no prime factors, therefore all of its prime factors are limited to 2, 3, and 5.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • -231 <= n <= 231 - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n \uff0c\u8bf7\u4f60\u5224\u65ad n \u662f\u5426\u4e3a \u4e11\u6570 \u3002\u5982\u679c\u662f\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n

    \u4e11\u6570 \u5c31\u662f\u53ea\u5305\u542b\u8d28\u56e0\u6570\u00a02\u30013 \u548c/\u6216\u00a05\u00a0\u7684\u6b63\u6574\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 6\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a6 = 2 \u00d7 3
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 8\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a8 = 2 \u00d7 2 \u00d7 2\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 14\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a14 \u4e0d\u662f\u4e11\u6570\uff0c\u56e0\u4e3a\u5b83\u5305\u542b\u4e86\u53e6\u5916\u4e00\u4e2a\u8d28\u56e0\u6570\u00a07 \u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a1 \u901a\u5e38\u88ab\u89c6\u4e3a\u4e11\u6570\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • -231 <= n <= 231 - 1
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isUgly(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isUgly(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isUgly(self, n):\n \"\"\"\n :type n: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isUgly(self, n: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isUgly(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsUgly(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {boolean}\n */\nvar isUgly = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Boolean}\ndef is_ugly(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isUgly(_ n: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isUgly(n int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isUgly(n: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isUgly(n: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_ugly(n: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Boolean\n */\n function isUgly($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isUgly(n: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-ugly n)\n (-> exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0263](https://leetcode-cn.com/problems/ugly-number)", "[\u4e11\u6570](/solution/0200-0299/0263.Ugly%20Number/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0263](https://leetcode.com/problems/ugly-number)", "[Ugly Number](/solution/0200-0299/0263.Ugly%20Number/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "0262", "frontend_question_id": "0262", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/trips-and-users", "url_en": "https://leetcode.com/problems/trips-and-users", "relative_path_cn": "/solution/0200-0299/0262.Trips%20and%20Users/README.md", "relative_path_en": "/solution/0200-0299/0262.Trips%20and%20Users/README_EN.md", "title_cn": "\u884c\u7a0b\u548c\u7528\u6237", "title_en": "Trips and Users", "question_title_slug": "trips-and-users", "content_en": "

    Table: Trips

    \n\n
    \n+-------------+----------+\n| Column Name | Type     |\n+-------------+----------+\n| Id          | int      |\n| Client_Id   | int      |\n| Driver_Id   | int      |\n| City_Id     | int      |\n| Status      | enum     |\n| Request_at  | date     |     \n+-------------+----------+\nId is the primary key for this table.\nThe table holds all taxi trips. Each trip has a unique Id, while Client_Id and Driver_Id are foreign keys to the Users_Id at the Users table.\nStatus is an ENUM type of (‘completed’, ‘cancelled_by_driver’, ‘cancelled_by_client’).\n
    \n\n

     

    \n\n

    Table: Users

    \n\n
    \n+-------------+----------+\n| Column Name | Type     |\n+-------------+----------+\n| Users_Id    | int      |\n| Banned      | enum     |\n| Role        | enum     |\n+-------------+----------+\nUsers_Id is the primary key for this table.\nThe table holds all users. Each user has a unique Users_Id, and Role is an ENUM type of (‘client’, ‘driver’, ‘partner’).\nStatus is an ENUM type of (‘Yes’, ‘No’).\n
    \n\n

     

    \n\n

    Write a SQL query to find the cancellation rate of requests with unbanned users (both client and driver must not be banned) each day between "2013-10-01" and "2013-10-03".

    \n\n

    The cancellation rate is computed by dividing the number of canceled (by client or driver) requests with unbanned users by the total number of requests with unbanned users on that day.

    \n\n

    Return the result table in any order. Round Cancellation Rate to two decimal points.

    \n\n

    The query result format is in the following example:

    \n\n

     

    \n\n
    \nTrips table:\n+----+-----------+-----------+---------+---------------------+------------+\n| Id | Client_Id | Driver_Id | City_Id | Status              | Request_at |\n+----+-----------+-----------+---------+---------------------+------------+\n| 1  | 1         | 10        | 1       | completed           | 2013-10-01 |\n| 2  | 2         | 11        | 1       | cancelled_by_driver | 2013-10-01 |\n| 3  | 3         | 12        | 6       | completed           | 2013-10-01 |\n| 4  | 4         | 13        | 6       | cancelled_by_client | 2013-10-01 |\n| 5  | 1         | 10        | 1       | completed           | 2013-10-02 |\n| 6  | 2         | 11        | 6       | completed           | 2013-10-02 |\n| 7  | 3         | 12        | 6       | completed           | 2013-10-02 |\n| 8  | 2         | 12        | 12      | completed           | 2013-10-03 |\n| 9  | 3         | 10        | 12      | completed           | 2013-10-03 |\n| 10 | 4         | 13        | 12      | cancelled_by_driver | 2013-10-03 |\n+----+-----------+-----------+---------+---------------------+------------+\n\nUsers table:\n+----------+--------+--------+\n| Users_Id | Banned | Role   |\n+----------+--------+--------+\n| 1        | No     | client |\n| 2        | Yes    | client |\n| 3        | No     | client |\n| 4        | No     | client |\n| 10       | No     | driver |\n| 11       | No     | driver |\n| 12       | No     | driver |\n| 13       | No     | driver |\n+----------+--------+--------+\n\nResult table:\n+------------+-------------------+\n| Day        | Cancellation Rate |\n+------------+-------------------+\n| 2013-10-01 | 0.33              |\n| 2013-10-02 | 0.00              |\n| 2013-10-03 | 0.50              |\n+------------+-------------------+\n\nOn 2013-10-01:\n  - There were 4 requests in total, 2 of which were canceled.\n  - However, the request with Id=2 was made by a banned client (User_Id=2), so it is ignored in the calculation.\n  - Hence there are 3 unbanned requests in total, 1 of which was canceled.\n  - The Cancellation Rate is (1 / 3) = 0.33\nOn 2013-10-02:\n  - There were 3 requests in total, 0 of which were canceled.\n  - The request with Id=6 was made by a banned client, so it is ignored.\n  - Hence there are 2 unbanned requests in total, 0 of which were canceled.\n  - The Cancellation Rate is (0 / 2) = 0.00\nOn 2013-10-03:\n  - There were 3 requests in total, 1 of which was canceled.\n  - The request with Id=8 was made by a banned client, so it is ignored.\n  - Hence there are 2 unbanned request in total, 1 of which were canceled.\n  - The Cancellation Rate is (1 / 2) = 0.50\n
    \n", "content_cn": "\u8868\uff1aTrips\n
    \n
    \n
    \n+-------------+----------+\n| Column Name | Type     |\n+-------------+----------+\n| Id          | int      |\n| Client_Id   | int      |\n| Driver_Id   | int      |\n| City_Id     | int      |\n| Status      | enum     |\n| Request_at  | date     |     \n+-------------+----------+\nId \u662f\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\u3002\n\u8fd9\u5f20\u8868\u4e2d\u5b58\u6240\u6709\u51fa\u79df\u8f66\u7684\u884c\u7a0b\u4fe1\u606f\u3002\u6bcf\u6bb5\u884c\u7a0b\u6709\u552f\u4e00 Id \uff0c\u5176\u4e2d Client_Id \u548c Driver_Id \u662f Users \u8868\u4e2d Users_Id \u7684\u5916\u952e\u3002\nStatus \u662f\u4e00\u4e2a\u8868\u793a\u884c\u7a0b\u72b6\u6001\u7684\u679a\u4e3e\u7c7b\u578b\uff0c\u679a\u4e3e\u6210\u5458\u4e3a(\u2018completed\u2019, \u2018cancelled_by_driver\u2019, \u2018cancelled_by_client\u2019) \u3002\n
    \n\n

    \u00a0

    \n\n
    \n
    \n

    \u8868\uff1aUsers

    \n
    \n
    \n\n
    \n+-------------+----------+\n| Column Name | Type     |\n+-------------+----------+\n| Users_Id    | int      |\n| Banned      | enum     |\n| Role        | enum     |\n+-------------+----------+\nUsers_Id \u662f\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\u3002\n\u8fd9\u5f20\u8868\u4e2d\u5b58\u6240\u6709\u7528\u6237\uff0c\u6bcf\u4e2a\u7528\u6237\u90fd\u6709\u4e00\u4e2a\u552f\u4e00\u7684 Users_Id \uff0cRole \u662f\u4e00\u4e2a\u8868\u793a\u7528\u6237\u8eab\u4efd\u7684\u679a\u4e3e\u7c7b\u578b\uff0c\u679a\u4e3e\u6210\u5458\u4e3a (\u2018client\u2019, \u2018driver\u2019, \u2018partner\u2019) \u3002\nBanned \u662f\u4e00\u4e2a\u8868\u793a\u7528\u6237\u662f\u5426\u88ab\u7981\u6b62\u7684\u679a\u4e3e\u7c7b\u578b\uff0c\u679a\u4e3e\u6210\u5458\u4e3a (\u2018Yes\u2019, \u2018No\u2019) \u3002\n
    \n\n

    \u00a0

    \n\n

    \u5199\u4e00\u6bb5 SQL \u8bed\u53e5\u67e5\u51fa\u00a0\"2013-10-01\"\u00a0\u81f3\u00a0\"2013-10-03\"\u00a0\u671f\u95f4\u975e\u7981\u6b62\u7528\u6237\uff08\u4e58\u5ba2\u548c\u53f8\u673a\u90fd\u5fc5\u987b\u672a\u88ab\u7981\u6b62\uff09\u7684\u53d6\u6d88\u7387\u3002\u975e\u7981\u6b62\u7528\u6237\u5373 Banned \u4e3a No \u7684\u7528\u6237\uff0c\u7981\u6b62\u7528\u6237\u5373 Banned \u4e3a Yes \u7684\u7528\u6237\u3002

    \n\n

    \u53d6\u6d88\u7387 \u7684\u8ba1\u7b97\u65b9\u5f0f\u5982\u4e0b\uff1a(\u88ab\u53f8\u673a\u6216\u4e58\u5ba2\u53d6\u6d88\u7684\u975e\u7981\u6b62\u7528\u6237\u751f\u6210\u7684\u8ba2\u5355\u6570\u91cf) / (\u975e\u7981\u6b62\u7528\u6237\u751f\u6210\u7684\u8ba2\u5355\u603b\u6570)\u3002

    \n\n

    \u8fd4\u56de\u7ed3\u679c\u8868\u4e2d\u7684\u6570\u636e\u53ef\u4ee5\u6309\u4efb\u610f\u987a\u5e8f\u7ec4\u7ec7\u3002\u5176\u4e2d\u53d6\u6d88\u7387 Cancellation Rate \u9700\u8981\u56db\u820d\u4e94\u5165\u4fdd\u7559 \u4e24\u4f4d\u5c0f\u6570 \u3002

    \n\n

    \u00a0

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a\uff1a

    \n\n
    \nTrips \u8868\uff1a\n+----+-----------+-----------+---------+---------------------+------------+\n| Id | Client_Id | Driver_Id | City_Id | Status              | Request_at |\n+----+-----------+-----------+---------+---------------------+------------+\n| 1  | 1         | 10        | 1       | completed           | 2013-10-01 |\n| 2  | 2         | 11        | 1       | cancelled_by_driver | 2013-10-01 |\n| 3  | 3         | 12        | 6       | completed           | 2013-10-01 |\n| 4  | 4         | 13        | 6       | cancelled_by_client | 2013-10-01 |\n| 5  | 1         | 10        | 1       | completed           | 2013-10-02 |\n| 6  | 2         | 11        | 6       | completed           | 2013-10-02 |\n| 7  | 3         | 12        | 6       | completed           | 2013-10-02 |\n| 8  | 2         | 12        | 12      | completed           | 2013-10-03 |\n| 9  | 3         | 10        | 12      | completed           | 2013-10-03 |\n| 10 | 4         | 13        | 12      | cancelled_by_driver | 2013-10-03 |\n+----+-----------+-----------+---------+---------------------+------------+\n\nUsers \u8868\uff1a\n+----------+--------+--------+\n| Users_Id | Banned | Role   |\n+----------+--------+--------+\n| 1        | No     | client |\n| 2        | Yes    | client |\n| 3        | No     | client |\n| 4        | No     | client |\n| 10       | No     | driver |\n| 11       | No     | driver |\n| 12       | No     | driver |\n| 13       | No     | driver |\n+----------+--------+--------+\n\nResult \u8868\uff1a\n+------------+-------------------+\n| Day        | Cancellation Rate |\n+------------+-------------------+\n| 2013-10-01 | 0.33              |\n| 2013-10-02 | 0.00              |\n| 2013-10-03 | 0.50              |\n+------------+-------------------+\n\n2013-10-01\uff1a\n  - \u5171\u6709 4 \u6761\u8bf7\u6c42\uff0c\u5176\u4e2d 2 \u6761\u53d6\u6d88\u3002\n  - \u7136\u800c\uff0cId=2 \u7684\u8bf7\u6c42\u662f\u7531\u7981\u6b62\u7528\u6237\uff08User_Id=2\uff09\u53d1\u51fa\u7684\uff0c\u6240\u4ee5\u8ba1\u7b97\u65f6\u5e94\u5f53\u5ffd\u7565\u5b83\u3002\n  - \u56e0\u6b64\uff0c\u603b\u5171\u6709 3 \u6761\u975e\u7981\u6b62\u8bf7\u6c42\u53c2\u4e0e\u8ba1\u7b97\uff0c\u5176\u4e2d 1 \u6761\u53d6\u6d88\u3002\n  - \u53d6\u6d88\u7387\u4e3a (1 / 3) = 0.33\n2013-10-02\uff1a\n  - \u5171\u6709 3 \u6761\u8bf7\u6c42\uff0c\u5176\u4e2d 0 \u6761\u53d6\u6d88\u3002\n  - \u7136\u800c\uff0cId=6 \u7684\u8bf7\u6c42\u662f\u7531\u7981\u6b62\u7528\u6237\u53d1\u51fa\u7684\uff0c\u6240\u4ee5\u8ba1\u7b97\u65f6\u5e94\u5f53\u5ffd\u7565\u5b83\u3002\n  - \u56e0\u6b64\uff0c\u603b\u5171\u6709 2 \u6761\u975e\u7981\u6b62\u8bf7\u6c42\u53c2\u4e0e\u8ba1\u7b97\uff0c\u5176\u4e2d 0 \u6761\u53d6\u6d88\u3002\n  - \u53d6\u6d88\u7387\u4e3a (0 / 2) = 0.00\n2013-10-03\uff1a\n  - \u5171\u6709 3 \u6761\u8bf7\u6c42\uff0c\u5176\u4e2d 1 \u6761\u53d6\u6d88\u3002\n  - \u7136\u800c\uff0cId=8 \u7684\u8bf7\u6c42\u662f\u7531\u7981\u6b62\u7528\u6237\u53d1\u51fa\u7684\uff0c\u6240\u4ee5\u8ba1\u7b97\u65f6\u5e94\u5f53\u5ffd\u7565\u5b83\u3002\n  - \u56e0\u6b64\uff0c\u603b\u5171\u6709 2 \u6761\u975e\u7981\u6b62\u8bf7\u6c42\u53c2\u4e0e\u8ba1\u7b97\uff0c\u5176\u4e2d 1 \u6761\u53d6\u6d88\u3002\n  - \u53d6\u6d88\u7387\u4e3a (1 / 2) = 0.50\n
    \n
    \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0262](https://leetcode-cn.com/problems/trips-and-users)", "[\u884c\u7a0b\u548c\u7528\u6237](/solution/0200-0299/0262.Trips%20and%20Users/README.md)", "", "\u56f0\u96be", ""], "md_table_row_en": ["[0262](https://leetcode.com/problems/trips-and-users)", "[Trips and Users](/solution/0200-0299/0262.Trips%20and%20Users/README_EN.md)", "", "Hard", ""]}, {"question_id": "0261", "frontend_question_id": "0261", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/graph-valid-tree", "url_en": "https://leetcode.com/problems/graph-valid-tree", "relative_path_cn": "/solution/0200-0299/0261.Graph%20Valid%20Tree/README.md", "relative_path_en": "/solution/0200-0299/0261.Graph%20Valid%20Tree/README_EN.md", "title_cn": "\u4ee5\u56fe\u5224\u6811", "title_en": "Graph Valid Tree", "question_title_slug": "graph-valid-tree", "content_en": "

    You have a graph of n nodes labeled from 0 to n - 1. You are given an integer n and a list of edges where edges[i] = [ai, bi] indicates that there is an undirected edge between nodes ai and bi in the graph.

    \n\n

    Return true if the edges of the given graph make up a valid tree, and false otherwise.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: n = 5, edges = [[0,1],[0,2],[0,3],[1,4]]\nOutput: true\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: n = 5, edges = [[0,1],[1,2],[2,3],[1,3],[1,4]]\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= 2000 <= n
    • \n\t
    • 0 <= edges.length <= 5000
    • \n\t
    • edges[i].length == 2
    • \n\t
    • 0 <= ai, bi < n
    • \n\t
    • ai != bi
    • \n\t
    • There are no self-loops or repeated edges.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4ece 0 \u5230 n-1 \u6807\u53f7\u7684 n \u4e2a\u7ed3\u70b9\uff0c\u548c\u4e00\u4e2a\u65e0\u5411\u8fb9\u5217\u8868\uff08\u6bcf\u6761\u8fb9\u4ee5\u7ed3\u70b9\u5bf9\u6765\u8868\u793a\uff09\uff0c\u8bf7\u7f16\u5199\u4e00\u4e2a\u51fd\u6570\u7528\u6765\u5224\u65ad\u8fd9\u4e9b\u8fb9\u662f\u5426\u80fd\u591f\u5f62\u6210\u4e00\u4e2a\u5408\u6cd5\u6709\u6548\u7684\u6811\u7ed3\u6784\u3002

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165: n = 5, \u8fb9\u5217\u8868 edges = [[0,1], [0,2], [0,3], [1,4]]\n\u8f93\u51fa: true
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: n = 5, \u8fb9\u5217\u8868 edges = [[0,1], [1,2], [2,3], [1,3], [1,4]]\n\u8f93\u51fa: false
    \n\n

    \u6ce8\u610f\uff1a\u4f60\u53ef\u4ee5\u5047\u5b9a\u8fb9\u5217\u8868 edges \u4e2d\u4e0d\u4f1a\u51fa\u73b0\u91cd\u590d\u7684\u8fb9\u3002\u7531\u4e8e\u6240\u6709\u7684\u8fb9\u662f\u65e0\u5411\u8fb9\uff0c\u8fb9 [0,1] \u548c\u8fb9 [1,0] \u662f\u76f8\u540c\u7684\uff0c\u56e0\u6b64\u4e0d\u4f1a\u540c\u65f6\u51fa\u73b0\u5728\u8fb9\u5217\u8868 edges \u4e2d\u3002

    \n", "tags_en": ["Depth-first Search", "Breadth-first Search", "Union Find", "Graph"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e76\u67e5\u96c6", "\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool validTree(int n, vector>& edges) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean validTree(int n, int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def validTree(self, n, edges):\n \"\"\"\n :type n: int\n :type edges: List[List[int]]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def validTree(self, n: int, edges: List[List[int]]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool validTree(int n, int** edges, int edgesSize, int* edgesColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool ValidTree(int n, int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} edges\n * @return {boolean}\n */\nvar validTree = function(n, edges) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} edges\n# @return {Boolean}\ndef valid_tree(n, edges)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func validTree(_ n: Int, _ edges: [[Int]]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func validTree(n int, edges [][]int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def validTree(n: Int, edges: Array[Array[Int]]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun validTree(n: Int, edges: Array): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn valid_tree(n: i32, edges: Vec>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $edges\n * @return Boolean\n */\n function validTree($n, $edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function validTree(n: number, edges: number[][]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (valid-tree n edges)\n (-> exact-integer? (listof (listof exact-integer?)) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0261](https://leetcode-cn.com/problems/graph-valid-tree)", "[\u4ee5\u56fe\u5224\u6811](/solution/0200-0299/0261.Graph%20Valid%20Tree/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e76\u67e5\u96c6`,`\u56fe`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0261](https://leetcode.com/problems/graph-valid-tree)", "[Graph Valid Tree](/solution/0200-0299/0261.Graph%20Valid%20Tree/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`,`Union Find`,`Graph`", "Medium", "\ud83d\udd12"]}, {"question_id": "0260", "frontend_question_id": "0260", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/single-number-iii", "url_en": "https://leetcode.com/problems/single-number-iii", "relative_path_cn": "/solution/0200-0299/0260.Single%20Number%20III/README.md", "relative_path_en": "/solution/0200-0299/0260.Single%20Number%20III/README_EN.md", "title_cn": "\u53ea\u51fa\u73b0\u4e00\u6b21\u7684\u6570\u5b57 III", "title_en": "Single Number III", "question_title_slug": "single-number-iii", "content_en": "

    Given an integer array nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in any order.

    \n\n

    You must write an algorithm that runs in linear runtime complexity and uses only constant extra space.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,1,3,2,5]\nOutput: [3,5]\nExplanation:  [5, 3] is also a valid answer.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [-1,0]\nOutput: [-1,0]\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [0,1]\nOutput: [1,0]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= nums.length <= 3 * 104
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n\t
    • Each integer in nums will appear twice, only two integers will appear once.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0nums\uff0c\u5176\u4e2d\u6070\u597d\u6709\u4e24\u4e2a\u5143\u7d20\u53ea\u51fa\u73b0\u4e00\u6b21\uff0c\u5176\u4f59\u6240\u6709\u5143\u7d20\u5747\u51fa\u73b0\u4e24\u6b21\u3002 \u627e\u51fa\u53ea\u51fa\u73b0\u4e00\u6b21\u7684\u90a3\u4e24\u4e2a\u5143\u7d20\u3002\u4f60\u53ef\u4ee5\u6309 \u4efb\u610f\u987a\u5e8f \u8fd4\u56de\u7b54\u6848\u3002

    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u7684\u7b97\u6cd5\u5e94\u8be5\u5177\u6709\u7ebf\u6027\u65f6\u95f4\u590d\u6742\u5ea6\u3002\u4f60\u80fd\u5426\u4ec5\u4f7f\u7528\u5e38\u6570\u7a7a\u95f4\u590d\u6742\u5ea6\u6765\u5b9e\u73b0\uff1f

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,1,3,2,5]\n\u8f93\u51fa\uff1a[3,5]\n\u89e3\u91ca\uff1a[5, 3] \u4e5f\u662f\u6709\u6548\u7684\u7b54\u6848\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [-1,0]\n\u8f93\u51fa\uff1a[-1,0]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [0,1]\n\u8f93\u51fa\uff1a[1,0]\n
    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= nums.length <= 3 * 104
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n\t
    • \u9664\u4e24\u4e2a\u53ea\u51fa\u73b0\u4e00\u6b21\u7684\u6574\u6570\u5916\uff0cnums \u4e2d\u7684\u5176\u4ed6\u6570\u5b57\u90fd\u51fa\u73b0\u4e24\u6b21
    • \n
    \n", "tags_en": ["Bit Manipulation"], "tags_cn": ["\u4f4d\u8fd0\u7b97"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector singleNumber(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] singleNumber(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def singleNumber(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def singleNumber(self, nums: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* singleNumber(int* nums, int numsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] SingleNumber(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar singleNumber = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer[]}\ndef single_number(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func singleNumber(_ nums: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func singleNumber(nums []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def singleNumber(nums: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun singleNumber(nums: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn single_number(nums: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer[]\n */\n function singleNumber($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function singleNumber(nums: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (single-number nums)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0260](https://leetcode-cn.com/problems/single-number-iii)", "[\u53ea\u51fa\u73b0\u4e00\u6b21\u7684\u6570\u5b57 III](/solution/0200-0299/0260.Single%20Number%20III/README.md)", "`\u4f4d\u8fd0\u7b97`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0260](https://leetcode.com/problems/single-number-iii)", "[Single Number III](/solution/0200-0299/0260.Single%20Number%20III/README_EN.md)", "`Bit Manipulation`", "Medium", ""]}, {"question_id": "0259", "frontend_question_id": "0259", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/3sum-smaller", "url_en": "https://leetcode.com/problems/3sum-smaller", "relative_path_cn": "/solution/0200-0299/0259.3Sum%20Smaller/README.md", "relative_path_en": "/solution/0200-0299/0259.3Sum%20Smaller/README_EN.md", "title_cn": "\u8f83\u5c0f\u7684\u4e09\u6570\u4e4b\u548c", "title_en": "3Sum Smaller", "question_title_slug": "3sum-smaller", "content_en": "

    Given an array of n integers nums and an integer target, find the number of index triplets i, j, k with 0 <= i < j < k < n that satisfy the condition nums[i] + nums[j] + nums[k] < target.

    \n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [-2,0,1,3], target = 2\nOutput: 2\nExplanation: Because there are two triplets which sums are less than 2:\n[-2,0,1]\n[-2,0,3]\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [], target = 0\nOutput: 0\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [0], target = 0\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 0 <= n <= 3500
    • \n\t
    • -100 <= nums[i] <= 100
    • \n\t
    • -100 <= target <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u6574\u6570\u6570\u7ec4\u548c\u4e00\u4e2a\u76ee\u6807\u503c target\uff0c\u5bfb\u627e\u80fd\u591f\u4f7f\u6761\u4ef6 nums[i] + nums[j] + nums[k] < target \u6210\u7acb\u7684\u4e09\u5143\u7ec4  i, j, k \u4e2a\u6570\uff080 <= i < j < k < n\uff09\u3002

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165: nums = [-2,0,1,3], target = 2\n\u8f93\u51fa: 2 \n\u89e3\u91ca: \u56e0\u4e3a\u4e00\u5171\u6709\u4e24\u4e2a\u4e09\u5143\u7ec4\u6ee1\u8db3\u7d2f\u52a0\u548c\u5c0f\u4e8e 2:\n     [-2,0,1]\n     [-2,0,3]\n
    \n\n

    \u8fdb\u9636\uff1a\u662f\u5426\u80fd\u5728 O(n2) \u7684\u65f6\u95f4\u590d\u6742\u5ea6\u5185\u89e3\u51b3\uff1f

    \n", "tags_en": ["Array", "Two Pointers"], "tags_cn": ["\u6570\u7ec4", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int threeSumSmaller(vector& nums, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int threeSumSmaller(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def threeSumSmaller(self, nums, target):\n \"\"\"\n :type nums: List[int]\n :type target: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def threeSumSmaller(self, nums: List[int], target: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint threeSumSmaller(int* nums, int numsSize, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ThreeSumSmaller(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} target\n * @return {number}\n */\nvar threeSumSmaller = function(nums, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} target\n# @return {Integer}\ndef three_sum_smaller(nums, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func threeSumSmaller(_ nums: [Int], _ target: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func threeSumSmaller(nums []int, target int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def threeSumSmaller(nums: Array[Int], target: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun threeSumSmaller(nums: IntArray, target: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn three_sum_smaller(nums: Vec, target: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $target\n * @return Integer\n */\n function threeSumSmaller($nums, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function threeSumSmaller(nums: number[], target: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (three-sum-smaller nums target)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0259](https://leetcode-cn.com/problems/3sum-smaller)", "[\u8f83\u5c0f\u7684\u4e09\u6570\u4e4b\u548c](/solution/0200-0299/0259.3Sum%20Smaller/README.md)", "`\u6570\u7ec4`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0259](https://leetcode.com/problems/3sum-smaller)", "[3Sum Smaller](/solution/0200-0299/0259.3Sum%20Smaller/README_EN.md)", "`Array`,`Two Pointers`", "Medium", "\ud83d\udd12"]}, {"question_id": "0258", "frontend_question_id": "0258", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/add-digits", "url_en": "https://leetcode.com/problems/add-digits", "relative_path_cn": "/solution/0200-0299/0258.Add%20Digits/README.md", "relative_path_en": "/solution/0200-0299/0258.Add%20Digits/README_EN.md", "title_cn": "\u5404\u4f4d\u76f8\u52a0", "title_en": "Add Digits", "question_title_slug": "add-digits", "content_en": "

    Given an integer num, repeatedly add all its digits until the result has only one digit, and return it.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: num = 38\nOutput: 2\nExplanation: The process is\n38 --> 3 + 8 --> 11\n11 --> 1 + 1 --> 2 \nSince 2 has only one digit, return it.\n
    \n\n

    Example 2:

    \n\n
    \nInput: num = 0\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= num <= 231 - 1
    • \n
    \n\n

     

    \n

    Follow up: Could you do it without any loop/recursion in O(1) runtime?

    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u8d1f\u6574\u6570 num\uff0c\u53cd\u590d\u5c06\u5404\u4e2a\u4f4d\u4e0a\u7684\u6570\u5b57\u76f8\u52a0\uff0c\u76f4\u5230\u7ed3\u679c\u4e3a\u4e00\u4f4d\u6570\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: 38\n\u8f93\u51fa: 2 \n\u89e3\u91ca: \u5404\u4f4d\u76f8\u52a0\u7684\u8fc7\u7a0b\u4e3a\uff1a3 + 8 = 11, 1 + 1 = 2\u3002 \u7531\u4e8e 2 \u662f\u4e00\u4f4d\u6570\uff0c\u6240\u4ee5\u8fd4\u56de 2\u3002\n
    \n\n

    \u8fdb\u9636:
    \n\u4f60\u53ef\u4ee5\u4e0d\u4f7f\u7528\u5faa\u73af\u6216\u8005\u9012\u5f52\uff0c\u4e14\u5728 O(1) \u65f6\u95f4\u590d\u6742\u5ea6\u5185\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u5417\uff1f

    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int addDigits(int num) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int addDigits(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def addDigits(self, num):\n \"\"\"\n :type num: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def addDigits(self, num: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint addDigits(int num){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int AddDigits(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} num\n * @return {number}\n */\nvar addDigits = function(num) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} num\n# @return {Integer}\ndef add_digits(num)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func addDigits(_ num: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func addDigits(num int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def addDigits(num: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun addDigits(num: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn add_digits(num: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $num\n * @return Integer\n */\n function addDigits($num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function addDigits(num: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (add-digits num)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0258](https://leetcode-cn.com/problems/add-digits)", "[\u5404\u4f4d\u76f8\u52a0](/solution/0200-0299/0258.Add%20Digits/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0258](https://leetcode.com/problems/add-digits)", "[Add Digits](/solution/0200-0299/0258.Add%20Digits/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "0257", "frontend_question_id": "0257", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/binary-tree-paths", "url_en": "https://leetcode.com/problems/binary-tree-paths", "relative_path_cn": "/solution/0200-0299/0257.Binary%20Tree%20Paths/README.md", "relative_path_en": "/solution/0200-0299/0257.Binary%20Tree%20Paths/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u7684\u6240\u6709\u8def\u5f84", "title_en": "Binary Tree Paths", "question_title_slug": "binary-tree-paths", "content_en": "

    Given the root of a binary tree, return all root-to-leaf paths in any order.

    \n\n

    A leaf is a node with no children.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,2,3,null,5]\nOutput: ["1->2->5","1->3"]\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = [1]\nOutput: ["1"]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 100].
    • \n\t
    • -100 <= Node.val <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811\uff0c\u8fd4\u56de\u6240\u6709\u4ece\u6839\u8282\u70b9\u5230\u53f6\u5b50\u8282\u70b9\u7684\u8def\u5f84\u3002

    \n\n

    \u8bf4\u660e: \u53f6\u5b50\u8282\u70b9\u662f\u6307\u6ca1\u6709\u5b50\u8282\u70b9\u7684\u8282\u70b9\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165:\n\n   1\n /   \\\n2     3\n \\\n  5\n\n\u8f93\u51fa: ["1->2->5", "1->3"]\n\n\u89e3\u91ca: \u6240\u6709\u6839\u8282\u70b9\u5230\u53f6\u5b50\u8282\u70b9\u7684\u8def\u5f84\u4e3a: 1->2->5, 1->3
    \n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector binaryTreePaths(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public List binaryTreePaths(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def binaryTreePaths(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def binaryTreePaths(self, root: TreeNode) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** binaryTreePaths(struct TreeNode* root, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public IList BinaryTreePaths(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {string[]}\n */\nvar binaryTreePaths = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {String[]}\ndef binary_tree_paths(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func binaryTreePaths(_ root: TreeNode?) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc binaryTreePaths(root *TreeNode) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def binaryTreePaths(root: TreeNode): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun binaryTreePaths(root: TreeNode?): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn binary_tree_paths(root: Option>>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return String[]\n */\n function binaryTreePaths($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction binaryTreePaths(root: TreeNode | null): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (binary-tree-paths root)\n (-> (or/c tree-node? #f) (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0257](https://leetcode-cn.com/problems/binary-tree-paths)", "[\u4e8c\u53c9\u6811\u7684\u6240\u6709\u8def\u5f84](/solution/0200-0299/0257.Binary%20Tree%20Paths/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u7b80\u5355", ""], "md_table_row_en": ["[0257](https://leetcode.com/problems/binary-tree-paths)", "[Binary Tree Paths](/solution/0200-0299/0257.Binary%20Tree%20Paths/README_EN.md)", "`Tree`,`Depth-first Search`", "Easy", ""]}, {"question_id": "0256", "frontend_question_id": "0256", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/paint-house", "url_en": "https://leetcode.com/problems/paint-house", "relative_path_cn": "/solution/0200-0299/0256.Paint%20House/README.md", "relative_path_en": "/solution/0200-0299/0256.Paint%20House/README_EN.md", "title_cn": "\u7c89\u5237\u623f\u5b50", "title_en": "Paint House", "question_title_slug": "paint-house", "content_en": "

    There is a row of n houses, where each house can be painted one of three colors: red, blue, or green. The cost of painting each house with a certain color is different. You have to paint all the houses such that no two adjacent houses have the same color.

    \n\n

    The cost of painting each house with a certain color is represented by an n x 3 cost matrix costs.

    \n\n
      \n\t
    • For example, costs[0][0] is the cost of painting house 0 with the color red; costs[1][2] is the cost of painting house 1 with color green, and so on...
    • \n
    \n\n

    Return the minimum cost to paint all houses.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: costs = [[17,2,17],[16,16,5],[14,3,19]]\nOutput: 10\nExplanation: Paint house 0 into blue, paint house 1 into green, paint house 2 into blue.\nMinimum cost: 2 + 5 + 3 = 10.\n
    \n\n

    Example 2:

    \n\n
    \nInput: costs = [[7,6,2]]\nOutput: 2\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • costs.length == n
    • \n\t
    • costs[i].length == 3
    • \n\t
    • 1 <= n <= 100
    • \n\t
    • 1 <= costs[i][j] <= 20
    • \n
    \n", "content_cn": "

    \u5047\u5982\u6709\u4e00\u6392\u623f\u5b50\uff0c\u5171 n \u4e2a\uff0c\u6bcf\u4e2a\u623f\u5b50\u53ef\u4ee5\u88ab\u7c89\u5237\u6210\u7ea2\u8272\u3001\u84dd\u8272\u6216\u8005\u7eff\u8272\u8fd9\u4e09\u79cd\u989c\u8272\u4e2d\u7684\u4e00\u79cd\uff0c\u4f60\u9700\u8981\u7c89\u5237\u6240\u6709\u7684\u623f\u5b50\u5e76\u4e14\u4f7f\u5176\u76f8\u90bb\u7684\u4e24\u4e2a\u623f\u5b50\u989c\u8272\u4e0d\u80fd\u76f8\u540c\u3002

    \n\n

    \u5f53\u7136\uff0c\u56e0\u4e3a\u5e02\u573a\u4e0a\u4e0d\u540c\u989c\u8272\u6cb9\u6f06\u7684\u4ef7\u683c\u4e0d\u540c\uff0c\u6240\u4ee5\u623f\u5b50\u7c89\u5237\u6210\u4e0d\u540c\u989c\u8272\u7684\u82b1\u8d39\u6210\u672c\u4e5f\u662f\u4e0d\u540c\u7684\u3002\u6bcf\u4e2a\u623f\u5b50\u7c89\u5237\u6210\u4e0d\u540c\u989c\u8272\u7684\u82b1\u8d39\u662f\u4ee5\u4e00\u4e2a n x 3 \u7684\u77e9\u9635\u6765\u8868\u793a\u7684\u3002

    \n\n

    \u4f8b\u5982\uff0ccosts[0][0] \u8868\u793a\u7b2c 0 \u53f7\u623f\u5b50\u7c89\u5237\u6210\u7ea2\u8272\u7684\u6210\u672c\u82b1\u8d39\uff1bcosts[1][2] \u8868\u793a\u7b2c 1 \u53f7\u623f\u5b50\u7c89\u5237\u6210\u7eff\u8272\u7684\u82b1\u8d39\uff0c\u4ee5\u6b64\u7c7b\u63a8\u3002\u8bf7\u4f60\u8ba1\u7b97\u51fa\u7c89\u5237\u5b8c\u6240\u6709\u623f\u5b50\u6700\u5c11\u7684\u82b1\u8d39\u6210\u672c\u3002

    \n\n

    \u6ce8\u610f\uff1a

    \n\n

    \u6240\u6709\u82b1\u8d39\u5747\u4e3a\u6b63\u6574\u6570\u3002

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165: [[17,2,17],[16,16,5],[14,3,19]]\n\u8f93\u51fa: 10\n\u89e3\u91ca: \u5c06 0 \u53f7\u623f\u5b50\u7c89\u5237\u6210\u84dd\u8272\uff0c1 \u53f7\u623f\u5b50\u7c89\u5237\u6210\u7eff\u8272\uff0c2 \u53f7\u623f\u5b50\u7c89\u5237\u6210\u84dd\u8272\u3002\n     \u6700\u5c11\u82b1\u8d39: 2 + 5 + 3 = 10\u3002\n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minCost(vector>& costs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minCost(int[][] costs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minCost(self, costs):\n \"\"\"\n :type costs: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minCost(self, costs: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minCost(int** costs, int costsSize, int* costsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinCost(int[][] costs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} costs\n * @return {number}\n */\nvar minCost = function(costs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} costs\n# @return {Integer}\ndef min_cost(costs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minCost(_ costs: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minCost(costs [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minCost(costs: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minCost(costs: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_cost(costs: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $costs\n * @return Integer\n */\n function minCost($costs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minCost(costs: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-cost costs)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0256](https://leetcode-cn.com/problems/paint-house)", "[\u7c89\u5237\u623f\u5b50](/solution/0200-0299/0256.Paint%20House/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0256](https://leetcode.com/problems/paint-house)", "[Paint House](/solution/0200-0299/0256.Paint%20House/README_EN.md)", "`Dynamic Programming`", "Medium", "\ud83d\udd12"]}, {"question_id": "0255", "frontend_question_id": "0255", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/verify-preorder-sequence-in-binary-search-tree", "url_en": "https://leetcode.com/problems/verify-preorder-sequence-in-binary-search-tree", "relative_path_cn": "/solution/0200-0299/0255.Verify%20Preorder%20Sequence%20in%20Binary%20Search%20Tree/README.md", "relative_path_en": "/solution/0200-0299/0255.Verify%20Preorder%20Sequence%20in%20Binary%20Search%20Tree/README_EN.md", "title_cn": "\u9a8c\u8bc1\u524d\u5e8f\u904d\u5386\u5e8f\u5217\u4e8c\u53c9\u641c\u7d22\u6811", "title_en": "Verify Preorder Sequence in Binary Search Tree", "question_title_slug": "verify-preorder-sequence-in-binary-search-tree", "content_en": "

    Given an array of unique integers preorder, return true if it is the correct preorder traversal sequence of a binary search tree.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: preorder = [5,2,1,3,6]\nOutput: true\n
    \n\n

    Example 2:

    \n\n
    \nInput: preorder = [5,2,6,1,3]\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= preorder.length <= 104
    • \n\t
    • 1 <= preorder[i] <= 104
    • \n\t
    • All the elements of preorder are unique.
    • \n
    \n\n

     

    \n

    Follow up: Could you do it using only constant space complexity?

    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\uff0c\u4f60\u9700\u8981\u9a8c\u8bc1\u5b83\u662f\u5426\u662f\u4e00\u4e2a\u4e8c\u53c9\u641c\u7d22\u6811\u6b63\u786e\u7684\u5148\u5e8f\u904d\u5386\u5e8f\u5217\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u5047\u5b9a\u8be5\u5e8f\u5217\u4e2d\u7684\u6570\u90fd\u662f\u4e0d\u76f8\u540c\u7684\u3002

    \n\n

    \u53c2\u8003\u4ee5\u4e0b\u8fd9\u9897\u4e8c\u53c9\u641c\u7d22\u6811\uff1a

    \n\n
         5\n    / \\\n   2   6\n  / \\\n 1   3
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165: [5,2,6,1,3]\n\u8f93\u51fa: false
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165: [5,2,1,3,6]\n\u8f93\u51fa: true
    \n\n

    \u8fdb\u9636\u6311\u6218\uff1a

    \n\n

    \u60a8\u80fd\u5426\u4f7f\u7528\u6052\u5b9a\u7684\u7a7a\u95f4\u590d\u6742\u5ea6\u6765\u5b8c\u6210\u6b64\u9898\uff1f

    \n", "tags_en": ["Stack", "Tree"], "tags_cn": ["\u6808", "\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool verifyPreorder(vector& preorder) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean verifyPreorder(int[] preorder) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def verifyPreorder(self, preorder):\n \"\"\"\n :type preorder: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def verifyPreorder(self, preorder: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool verifyPreorder(int* preorder, int preorderSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool VerifyPreorder(int[] preorder) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} preorder\n * @return {boolean}\n */\nvar verifyPreorder = function(preorder) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} preorder\n# @return {Boolean}\ndef verify_preorder(preorder)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func verifyPreorder(_ preorder: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func verifyPreorder(preorder []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def verifyPreorder(preorder: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun verifyPreorder(preorder: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn verify_preorder(preorder: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $preorder\n * @return Boolean\n */\n function verifyPreorder($preorder) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function verifyPreorder(preorder: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (verify-preorder preorder)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0255](https://leetcode-cn.com/problems/verify-preorder-sequence-in-binary-search-tree)", "[\u9a8c\u8bc1\u524d\u5e8f\u904d\u5386\u5e8f\u5217\u4e8c\u53c9\u641c\u7d22\u6811](/solution/0200-0299/0255.Verify%20Preorder%20Sequence%20in%20Binary%20Search%20Tree/README.md)", "`\u6808`,`\u6811`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0255](https://leetcode.com/problems/verify-preorder-sequence-in-binary-search-tree)", "[Verify Preorder Sequence in Binary Search Tree](/solution/0200-0299/0255.Verify%20Preorder%20Sequence%20in%20Binary%20Search%20Tree/README_EN.md)", "`Stack`,`Tree`", "Medium", "\ud83d\udd12"]}, {"question_id": "0254", "frontend_question_id": "0254", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/factor-combinations", "url_en": "https://leetcode.com/problems/factor-combinations", "relative_path_cn": "/solution/0200-0299/0254.Factor%20Combinations/README.md", "relative_path_en": "/solution/0200-0299/0254.Factor%20Combinations/README_EN.md", "title_cn": "\u56e0\u5b50\u7684\u7ec4\u5408", "title_en": "Factor Combinations", "question_title_slug": "factor-combinations", "content_en": "

    Numbers can be regarded as the product of their factors.

    \n\n
      \n\t
    • For example, 8 = 2 x 2 x 2 = 2 x 4.
    • \n
    \n\n

    Given an integer n, return all possible combinations of its factors. You may return the answer in any order.

    \n\n

    Note that the factors should be in the range [2, n - 1].

    \n\n

     

    \n

    Example 1:

    \n
    Input: n = 1\nOutput: []\n

    Example 2:

    \n
    Input: n = 12\nOutput: [[2,6],[3,4],[2,2,3]]\n

    Example 3:

    \n
    Input: n = 37\nOutput: []\n

    Example 4:

    \n
    Input: n = 32\nOutput: [[2,16],[4,8],[2,2,8],[2,4,4],[2,2,2,4],[2,2,2,2,2]]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 108
    • \n
    \n", "content_cn": "

    \u6574\u6570\u53ef\u4ee5\u88ab\u770b\u4f5c\u662f\u5176\u56e0\u5b50\u7684\u4e58\u79ef\u3002

    \n\n

    \u4f8b\u5982\uff1a

    \n\n
    8 = 2 x 2 x 2;\n  = 2 x 4.
    \n\n

    \u8bf7\u5b9e\u73b0\u4e00\u4e2a\u51fd\u6570\uff0c\u8be5\u51fd\u6570\u63a5\u6536\u4e00\u4e2a\u6574\u6570 n \u5e76\u8fd4\u56de\u8be5\u6574\u6570\u6240\u6709\u7684\u56e0\u5b50\u7ec4\u5408\u3002

    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    1. \u4f60\u53ef\u4ee5\u5047\u5b9a n \u4e3a\u6c38\u8fdc\u4e3a\u6b63\u6570\u3002
    2. \n\t
    3. \u56e0\u5b50\u5fc5\u987b\u5927\u4e8e 1 \u5e76\u4e14\u5c0f\u4e8e n\u3002
    4. \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165: 1\n\u8f93\u51fa: []\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165: 37\n\u8f93\u51fa: []
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165: 12\n\u8f93\u51fa:\n[\n  [2, 6],\n  [2, 2, 3],\n  [3, 4]\n]
    \n\n

    \u793a\u4f8b 4:

    \n\n
    \u8f93\u5165: 32\n\u8f93\u51fa:\n[\n  [2, 16],\n  [2, 2, 8],\n  [2, 2, 2, 4],\n  [2, 2, 2, 2, 2],\n  [2, 4, 4],\n  [4, 8]\n]\n
    \n", "tags_en": ["Backtracking"], "tags_cn": ["\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> getFactors(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> getFactors(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getFactors(self, n):\n \"\"\"\n :type n: int\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getFactors(self, n: int) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** getFactors(int n, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> GetFactors(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number[][]}\n */\nvar getFactors = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer[][]}\ndef get_factors(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getFactors(_ n: Int) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getFactors(n int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getFactors(n: Int): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getFactors(n: Int): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_factors(n: i32) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer[][]\n */\n function getFactors($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getFactors(n: number): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-factors n)\n (-> exact-integer? (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0254](https://leetcode-cn.com/problems/factor-combinations)", "[\u56e0\u5b50\u7684\u7ec4\u5408](/solution/0200-0299/0254.Factor%20Combinations/README.md)", "`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0254](https://leetcode.com/problems/factor-combinations)", "[Factor Combinations](/solution/0200-0299/0254.Factor%20Combinations/README_EN.md)", "`Backtracking`", "Medium", "\ud83d\udd12"]}, {"question_id": "0253", "frontend_question_id": "0253", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/meeting-rooms-ii", "url_en": "https://leetcode.com/problems/meeting-rooms-ii", "relative_path_cn": "/solution/0200-0299/0253.Meeting%20Rooms%20II/README.md", "relative_path_en": "/solution/0200-0299/0253.Meeting%20Rooms%20II/README_EN.md", "title_cn": "\u4f1a\u8bae\u5ba4 II", "title_en": "Meeting Rooms II", "question_title_slug": "meeting-rooms-ii", "content_en": "

    Given an array of meeting time intervals intervals where intervals[i] = [starti, endi], return the minimum number of conference rooms required.

    \n\n

     

    \n

    Example 1:

    \n
    Input: intervals = [[0,30],[5,10],[15,20]]\nOutput: 2\n

    Example 2:

    \n
    Input: intervals = [[7,10],[2,4]]\nOutput: 1\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= intervals.length <= 104
    • \n\t
    • 0 <= starti < endi <= 106
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u4f1a\u8bae\u65f6\u95f4\u5b89\u6392\u7684\u6570\u7ec4 intervals \uff0c\u6bcf\u4e2a\u4f1a\u8bae\u65f6\u95f4\u90fd\u4f1a\u5305\u62ec\u5f00\u59cb\u548c\u7ed3\u675f\u7684\u65f6\u95f4 intervals[i] = [starti, endi] \uff0c\u4e3a\u907f\u514d\u4f1a\u8bae\u51b2\u7a81\uff0c\u540c\u65f6\u8981\u8003\u8651\u5145\u5206\u5229\u7528\u4f1a\u8bae\u5ba4\u8d44\u6e90\uff0c\u8bf7\u4f60\u8ba1\u7b97\u81f3\u5c11\u9700\u8981\u591a\u5c11\u95f4\u4f1a\u8bae\u5ba4\uff0c\u624d\u80fd\u6ee1\u8db3\u8fd9\u4e9b\u4f1a\u8bae\u5b89\u6392\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aintervals = [[0,30],[5,10],[15,20]]\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aintervals = [[7,10],[2,4]]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <=\u00a0intervals.length <= 104
    • \n\t
    • 0 <= starti < endi <= 106
    • \n
    \n", "tags_en": ["Heap", "Greedy", "Sort"], "tags_cn": ["\u5806", "\u8d2a\u5fc3\u7b97\u6cd5", "\u6392\u5e8f"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minMeetingRooms(vector>& intervals) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minMeetingRooms(int[][] intervals) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minMeetingRooms(self, intervals):\n \"\"\"\n :type intervals: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minMeetingRooms(self, intervals: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minMeetingRooms(int** intervals, int intervalsSize, int* intervalsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinMeetingRooms(int[][] intervals) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} intervals\n * @return {number}\n */\nvar minMeetingRooms = function(intervals) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} intervals\n# @return {Integer}\ndef min_meeting_rooms(intervals)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minMeetingRooms(_ intervals: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minMeetingRooms(intervals [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minMeetingRooms(intervals: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minMeetingRooms(intervals: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_meeting_rooms(intervals: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $intervals\n * @return Integer\n */\n function minMeetingRooms($intervals) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minMeetingRooms(intervals: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-meeting-rooms intervals)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0253](https://leetcode-cn.com/problems/meeting-rooms-ii)", "[\u4f1a\u8bae\u5ba4 II](/solution/0200-0299/0253.Meeting%20Rooms%20II/README.md)", "`\u5806`,`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6392\u5e8f`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0253](https://leetcode.com/problems/meeting-rooms-ii)", "[Meeting Rooms II](/solution/0200-0299/0253.Meeting%20Rooms%20II/README_EN.md)", "`Heap`,`Greedy`,`Sort`", "Medium", "\ud83d\udd12"]}, {"question_id": "0252", "frontend_question_id": "0252", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/meeting-rooms", "url_en": "https://leetcode.com/problems/meeting-rooms", "relative_path_cn": "/solution/0200-0299/0252.Meeting%20Rooms/README.md", "relative_path_en": "/solution/0200-0299/0252.Meeting%20Rooms/README_EN.md", "title_cn": "\u4f1a\u8bae\u5ba4", "title_en": "Meeting Rooms", "question_title_slug": "meeting-rooms", "content_en": "

    Given an array of meeting time intervals where intervals[i] = [starti, endi], determine if a person could attend all meetings.

    \n\n

     

    \n

    Example 1:

    \n
    Input: intervals = [[0,30],[5,10],[15,20]]\nOutput: false\n

    Example 2:

    \n
    Input: intervals = [[7,10],[2,4]]\nOutput: true\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= intervals.length <= 104
    • \n\t
    • intervals[i].length == 2
    • \n\t
    • 0 <= starti < endi <= 106
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4f1a\u8bae\u65f6\u95f4\u5b89\u6392\u7684\u6570\u7ec4 intervals \uff0c\u6bcf\u4e2a\u4f1a\u8bae\u65f6\u95f4\u90fd\u4f1a\u5305\u62ec\u5f00\u59cb\u548c\u7ed3\u675f\u7684\u65f6\u95f4 intervals[i] = [starti, endi] \uff0c\u8bf7\u4f60\u5224\u65ad\u4e00\u4e2a\u4eba\u662f\u5426\u80fd\u591f\u53c2\u52a0\u8fd9\u91cc\u9762\u7684\u5168\u90e8\u4f1a\u8bae\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aintervals = [[0,30],[5,10],[15,20]]\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aintervals = [[7,10],[2,4]]\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= intervals.length <= 104
    • \n\t
    • intervals[i].length == 2
    • \n\t
    • 0 <= starti <\u00a0endi <= 106
    • \n
    \n", "tags_en": ["Sort"], "tags_cn": ["\u6392\u5e8f"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canAttendMeetings(vector>& intervals) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canAttendMeetings(int[][] intervals) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canAttendMeetings(self, intervals):\n \"\"\"\n :type intervals: List[List[int]]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canAttendMeetings(self, intervals: List[List[int]]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canAttendMeetings(int** intervals, int intervalsSize, int* intervalsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanAttendMeetings(int[][] intervals) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} intervals\n * @return {boolean}\n */\nvar canAttendMeetings = function(intervals) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} intervals\n# @return {Boolean}\ndef can_attend_meetings(intervals)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canAttendMeetings(_ intervals: [[Int]]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canAttendMeetings(intervals [][]int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canAttendMeetings(intervals: Array[Array[Int]]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canAttendMeetings(intervals: Array): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_attend_meetings(intervals: Vec>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $intervals\n * @return Boolean\n */\n function canAttendMeetings($intervals) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canAttendMeetings(intervals: number[][]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-attend-meetings intervals)\n (-> (listof (listof exact-integer?)) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0252](https://leetcode-cn.com/problems/meeting-rooms)", "[\u4f1a\u8bae\u5ba4](/solution/0200-0299/0252.Meeting%20Rooms/README.md)", "`\u6392\u5e8f`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0252](https://leetcode.com/problems/meeting-rooms)", "[Meeting Rooms](/solution/0200-0299/0252.Meeting%20Rooms/README_EN.md)", "`Sort`", "Easy", "\ud83d\udd12"]}, {"question_id": "0251", "frontend_question_id": "0251", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/flatten-2d-vector", "url_en": "https://leetcode.com/problems/flatten-2d-vector", "relative_path_cn": "/solution/0200-0299/0251.Flatten%202D%20Vector/README.md", "relative_path_en": "/solution/0200-0299/0251.Flatten%202D%20Vector/README_EN.md", "title_cn": "\u5c55\u5f00\u4e8c\u7ef4\u5411\u91cf", "title_en": "Flatten 2D Vector", "question_title_slug": "flatten-2d-vector", "content_en": "

    Design an iterator to flatten a 2D vector. It should support the next and hasNext operations.

    \n\n

    Implement the Vector2D class:

    \n\n
      \n\t
    • Vector2D(int[][] vec) initializes the object with the 2D vector vec.
    • \n\t
    • next() returns the next element from the 2D vector and moves the pointer one step forward. You may assume that all the calls to next are valid.
    • \n\t
    • hasNext() returns true if there are still some elements in the vector, and false otherwise.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["Vector2D", "next", "next", "next", "hasNext", "hasNext", "next", "hasNext"]\n[[[[1, 2], [3], [4]]], [], [], [], [], [], [], []]\nOutput\n[null, 1, 2, 3, true, true, 4, false]\n\nExplanation\nVector2D vector2D = new Vector2D([[1, 2], [3], [4]]);\nvector2D.next();    // return 1\nvector2D.next();    // return 2\nvector2D.next();    // return 3\nvector2D.hasNext(); // return True\nvector2D.hasNext(); // return True\nvector2D.next();    // return 4\nvector2D.hasNext(); // return False\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= vec.length <= 200
    • \n\t
    • 0 <= vec[i].length <= 500
    • \n\t
    • -500 <= vec[i][j] <= 500
    • \n\t
    • At most 105 calls will be made to next and hasNext.
    • \n
    \n\n

     

    \n

    Follow up: As an added challenge, try to code it using only iterators in C++ or iterators in Java.

    \n", "content_cn": "

    \u8bf7\u8bbe\u8ba1\u5e76\u5b9e\u73b0\u4e00\u4e2a\u80fd\u591f\u5c55\u5f00\u4e8c\u7ef4\u5411\u91cf\u7684\u8fed\u4ee3\u5668\u3002\u8be5\u8fed\u4ee3\u5668\u9700\u8981\u652f\u6301\u00a0next \u548c\u00a0hasNext\u00a0\u4e24\u79cd\u64cd\u4f5c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \nVector2D iterator = new Vector2D([[1,2],[3],[4]]);\n\niterator.next(); // \u8fd4\u56de 1\niterator.next(); // \u8fd4\u56de 2\niterator.next(); // \u8fd4\u56de 3\niterator.hasNext(); // \u8fd4\u56de true\niterator.hasNext(); // \u8fd4\u56de true\niterator.next(); // \u8fd4\u56de 4\niterator.hasNext(); // \u8fd4\u56de false\n
    \n\n

    \u00a0

    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    1. \u8bf7\u8bb0\u5f97\u00a0\u91cd\u7f6e\u00a0\u5728 Vector2D \u4e2d\u58f0\u660e\u7684\u7c7b\u53d8\u91cf\uff08\u9759\u6001\u53d8\u91cf\uff09\uff0c\u56e0\u4e3a\u7c7b\u53d8\u91cf\u4f1a\u00a0\u5728\u591a\u4e2a\u6d4b\u8bd5\u7528\u4f8b\u4e2d\u4fdd\u6301\u4e0d\u53d8\uff0c\u5f71\u54cd\u5224\u9898\u51c6\u786e\u3002\u8bf7 \u67e5\u9605 \u8fd9\u91cc\u3002
    2. \n\t
    3. \u4f60\u53ef\u4ee5\u5047\u5b9a next() \u7684\u8c03\u7528\u603b\u662f\u5408\u6cd5\u7684\uff0c\u5373\u5f53 next() \u88ab\u8c03\u7528\u65f6\uff0c\u4e8c\u7ef4\u5411\u91cf\u603b\u662f\u5b58\u5728\u81f3\u5c11\u4e00\u4e2a\u540e\u7eed\u5143\u7d20\u3002
    4. \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u5c1d\u8bd5\u5728\u4ee3\u7801\u4e2d\u4ec5\u4f7f\u7528 C++ \u63d0\u4f9b\u7684\u8fed\u4ee3\u5668 \u6216 Java \u63d0\u4f9b\u7684\u8fed\u4ee3\u5668\u3002

    \n", "tags_en": ["Design"], "tags_cn": ["\u8bbe\u8ba1"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Vector2D {\npublic:\n Vector2D(vector>& vec) {\n\n }\n \n int next() {\n\n }\n \n bool hasNext() {\n\n }\n};\n\n/**\n * Your Vector2D object will be instantiated and called as such:\n * Vector2D* obj = new Vector2D(vec);\n * int param_1 = obj->next();\n * bool param_2 = obj->hasNext();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Vector2D {\n\n public Vector2D(int[][] vec) {\n\n }\n \n public int next() {\n\n }\n \n public boolean hasNext() {\n\n }\n}\n\n/**\n * Your Vector2D object will be instantiated and called as such:\n * Vector2D obj = new Vector2D(vec);\n * int param_1 = obj.next();\n * boolean param_2 = obj.hasNext();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Vector2D(object):\n\n def __init__(self, vec):\n \"\"\"\n :type vec: List[List[int]]\n \"\"\"\n\n\n def next(self):\n \"\"\"\n :rtype: int\n \"\"\"\n\n\n def hasNext(self):\n \"\"\"\n :rtype: bool\n \"\"\"\n\n\n\n# Your Vector2D object will be instantiated and called as such:\n# obj = Vector2D(vec)\n# param_1 = obj.next()\n# param_2 = obj.hasNext()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Vector2D:\n\n def __init__(self, vec: List[List[int]]):\n\n\n def next(self) -> int:\n\n\n def hasNext(self) -> bool:\n\n\n\n# Your Vector2D object will be instantiated and called as such:\n# obj = Vector2D(vec)\n# param_1 = obj.next()\n# param_2 = obj.hasNext()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} Vector2D;\n\n\nVector2D* vector2DCreate(int** vec, int vecSize, int* vecColSize) {\n\n}\n\nint vector2DNext(Vector2D* obj) {\n\n}\n\nbool vector2DHasNext(Vector2D* obj) {\n\n}\n\nvoid vector2DFree(Vector2D* obj) {\n\n}\n\n/**\n * Your Vector2D struct will be instantiated and called as such:\n * Vector2D* obj = vector2DCreate(vec, vecSize, vecColSize);\n * int param_1 = vector2DNext(obj);\n \n * bool param_2 = vector2DHasNext(obj);\n \n * vector2DFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Vector2D {\n\n public Vector2D(int[][] vec) {\n\n }\n \n public int Next() {\n\n }\n \n public bool HasNext() {\n\n }\n}\n\n/**\n * Your Vector2D object will be instantiated and called as such:\n * Vector2D obj = new Vector2D(vec);\n * int param_1 = obj.Next();\n * bool param_2 = obj.HasNext();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} vec\n */\nvar Vector2D = function(vec) {\n\n};\n\n/**\n * @return {number}\n */\nVector2D.prototype.next = function() {\n\n};\n\n/**\n * @return {boolean}\n */\nVector2D.prototype.hasNext = function() {\n\n};\n\n/**\n * Your Vector2D object will be instantiated and called as such:\n * var obj = new Vector2D(vec)\n * var param_1 = obj.next()\n * var param_2 = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class Vector2D\n\n=begin\n :type vec: Integer[][]\n=end\n def initialize(vec)\n\n end\n\n\n=begin\n :rtype: Integer\n=end\n def next()\n\n end\n\n\n=begin\n :rtype: Boolean\n=end\n def has_next()\n\n end\n\n\nend\n\n# Your Vector2D object will be instantiated and called as such:\n# obj = Vector2D.new(vec)\n# param_1 = obj.next()\n# param_2 = obj.has_next()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass Vector2D {\n\n init(_ vec: [[Int]]) {\n\n }\n \n func next() -> Int {\n\n }\n \n func hasNext() -> Bool {\n\n }\n}\n\n/**\n * Your Vector2D object will be instantiated and called as such:\n * let obj = Vector2D(vec)\n * let ret_1: Int = obj.next()\n * let ret_2: Bool = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type Vector2D struct {\n\n}\n\n\nfunc Constructor(vec [][]int) Vector2D {\n\n}\n\n\nfunc (this *Vector2D) Next() int {\n\n}\n\n\nfunc (this *Vector2D) HasNext() bool {\n\n}\n\n\n/**\n * Your Vector2D object will be instantiated and called as such:\n * obj := Constructor(vec);\n * param_1 := obj.Next();\n * param_2 := obj.HasNext();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class Vector2D(_vec: Array[Array[Int]]) {\n\n def next(): Int = {\n\n }\n\n def hasNext(): Boolean = {\n\n }\n\n}\n\n/**\n * Your Vector2D object will be instantiated and called as such:\n * var obj = new Vector2D(vec)\n * var param_1 = obj.next()\n * var param_2 = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Vector2D(vec: Array) {\n\n fun next(): Int {\n\n }\n\n fun hasNext(): Boolean {\n\n }\n\n}\n\n/**\n * Your Vector2D object will be instantiated and called as such:\n * var obj = Vector2D(vec)\n * var param_1 = obj.next()\n * var param_2 = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct Vector2D {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl Vector2D {\n\n fn new(vec: Vec>) -> Self {\n\n }\n \n fn next(&self) -> i32 {\n\n }\n \n fn has_next(&self) -> bool {\n\n }\n}\n\n/**\n * Your Vector2D object will be instantiated and called as such:\n * let obj = Vector2D::new(vec);\n * let ret_1: i32 = obj.next();\n * let ret_2: bool = obj.has_next();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Vector2D {\n /**\n * @param Integer[][] $vec\n */\n function __construct($vec) {\n\n }\n\n /**\n * @return Integer\n */\n function next() {\n\n }\n\n /**\n * @return Boolean\n */\n function hasNext() {\n\n }\n}\n\n/**\n * Your Vector2D object will be instantiated and called as such:\n * $obj = Vector2D($vec);\n * $ret_1 = $obj->next();\n * $ret_2 = $obj->hasNext();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class Vector2D {\n constructor(vec: number[][]) {\n\n }\n\n next(): number {\n\n }\n\n hasNext(): boolean {\n\n }\n}\n\n/**\n * Your Vector2D object will be instantiated and called as such:\n * var obj = new Vector2D(vec)\n * var param_1 = obj.next()\n * var param_2 = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define vector2-d%\n (class object%\n (super-new)\n\n ; vec : (listof (listof exact-integer?))\n (init-field\n vec)\n \n ; next : -> exact-integer?\n (define/public (next)\n\n )\n ; has-next : -> boolean?\n (define/public (has-next)\n\n )))\n\n;; Your vector2-d% object will be instantiated and called as such:\n;; (define obj (new vector2-d% [vec vec]))\n;; (define param_1 (send obj next))\n;; (define param_2 (send obj has-next))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0251](https://leetcode-cn.com/problems/flatten-2d-vector)", "[\u5c55\u5f00\u4e8c\u7ef4\u5411\u91cf](/solution/0200-0299/0251.Flatten%202D%20Vector/README.md)", "`\u8bbe\u8ba1`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0251](https://leetcode.com/problems/flatten-2d-vector)", "[Flatten 2D Vector](/solution/0200-0299/0251.Flatten%202D%20Vector/README_EN.md)", "`Design`", "Medium", "\ud83d\udd12"]}, {"question_id": "0250", "frontend_question_id": "0250", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/count-univalue-subtrees", "url_en": "https://leetcode.com/problems/count-univalue-subtrees", "relative_path_cn": "/solution/0200-0299/0250.Count%20Univalue%20Subtrees/README.md", "relative_path_en": "/solution/0200-0299/0250.Count%20Univalue%20Subtrees/README_EN.md", "title_cn": "\u7edf\u8ba1\u540c\u503c\u5b50\u6811", "title_en": "Count Univalue Subtrees", "question_title_slug": "count-univalue-subtrees", "content_en": "

    Given the root of a binary tree, return the number of uni-value subtrees.

    \n\n

    A uni-value subtree means all nodes of the subtree have the same value.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [5,1,5,5,5,null,5]\nOutput: 4\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = []\nOutput: 0\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = [5,5,5,5,5,null,5]\nOutput: 6\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The numbrt of the node in the tree will be in the range [0, 1000].
    • \n\t
    • -1000 <= Node.val <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811\uff0c\u7edf\u8ba1\u8be5\u4e8c\u53c9\u6811\u6570\u503c\u76f8\u540c\u7684\u5b50\u6811\u4e2a\u6570\u3002

    \n\n

    \u540c\u503c\u5b50\u6811\u662f\u6307\u8be5\u5b50\u6811\u7684\u6240\u6709\u8282\u70b9\u90fd\u62e5\u6709\u76f8\u540c\u7684\u6570\u503c\u3002

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165: root = [5,1,5,5,5,null,5]\n\n              5\n             / \\\n            1   5\n           / \\   \\\n          5   5   5\n\n\u8f93\u51fa: 4\n
    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int countUnivalSubtrees(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int countUnivalSubtrees(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def countUnivalSubtrees(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def countUnivalSubtrees(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint countUnivalSubtrees(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int CountUnivalSubtrees(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar countUnivalSubtrees = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef count_unival_subtrees(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func countUnivalSubtrees(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc countUnivalSubtrees(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def countUnivalSubtrees(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun countUnivalSubtrees(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn count_unival_subtrees(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function countUnivalSubtrees($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction countUnivalSubtrees(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (count-unival-subtrees root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0250](https://leetcode-cn.com/problems/count-univalue-subtrees)", "[\u7edf\u8ba1\u540c\u503c\u5b50\u6811](/solution/0200-0299/0250.Count%20Univalue%20Subtrees/README.md)", "`\u6811`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0250](https://leetcode.com/problems/count-univalue-subtrees)", "[Count Univalue Subtrees](/solution/0200-0299/0250.Count%20Univalue%20Subtrees/README_EN.md)", "`Tree`", "Medium", "\ud83d\udd12"]}, {"question_id": "0249", "frontend_question_id": "0249", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/group-shifted-strings", "url_en": "https://leetcode.com/problems/group-shifted-strings", "relative_path_cn": "/solution/0200-0299/0249.Group%20Shifted%20Strings/README.md", "relative_path_en": "/solution/0200-0299/0249.Group%20Shifted%20Strings/README_EN.md", "title_cn": "\u79fb\u4f4d\u5b57\u7b26\u4e32\u5206\u7ec4", "title_en": "Group Shifted Strings", "question_title_slug": "group-shifted-strings", "content_en": "

    We can shift a string by shifting each of its letters to its successive letter.

    \n\n
      \n\t
    • For example, "abc" can be shifted to be "bcd".
    • \n
    \n\n

    We can keep shifting the string to form a sequence.

    \n\n
      \n\t
    • For example, we can keep shifting "abc" to form the sequence: "abc" -> "bcd" -> ... -> "xyz".
    • \n
    \n\n

    Given an array of strings strings, group all strings[i] that belong to the same shifting sequence. You may return the answer in any order.

    \n\n

     

    \n

    Example 1:

    \n
    Input: strings = [\"abc\",\"bcd\",\"acef\",\"xyz\",\"az\",\"ba\",\"a\",\"z\"]\nOutput: [[\"acef\"],[\"a\",\"z\"],[\"abc\",\"bcd\",\"xyz\"],[\"az\",\"ba\"]]\n

    Example 2:

    \n
    Input: strings = [\"a\"]\nOutput: [[\"a\"]]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= strings.length <= 200
    • \n\t
    • 1 <= strings[i].length <= 50
    • \n\t
    • strings[i] consists of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u5bf9\u8be5\u5b57\u7b26\u4e32\u53ef\u4ee5\u8fdb\u884c “\u79fb\u4f4d” \u7684\u64cd\u4f5c\uff0c\u4e5f\u5c31\u662f\u5c06\u5b57\u7b26\u4e32\u4e2d\u6bcf\u4e2a\u5b57\u6bcd\u90fd\u53d8\u4e3a\u5176\u5728\u5b57\u6bcd\u8868\u4e2d\u540e\u7eed\u7684\u5b57\u6bcd\uff0c\u6bd4\u5982\uff1a"abc" -> "bcd"\u3002\u8fd9\u6837\uff0c\u6211\u4eec\u53ef\u4ee5\u6301\u7eed\u8fdb\u884c “\u79fb\u4f4d” \u64cd\u4f5c\uff0c\u4ece\u800c\u751f\u6210\u5982\u4e0b\u79fb\u4f4d\u5e8f\u5217\uff1a

    \n\n
    "abc" -> "bcd" -> ... -> "xyz"
    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u5305\u542b\u4ec5\u5c0f\u5199\u5b57\u6bcd\u5b57\u7b26\u4e32\u7684\u5217\u8868\uff0c\u5c06\u8be5\u5217\u8868\u4e2d\u6240\u6709\u6ee1\u8db3 “\u79fb\u4f4d” \u64cd\u4f5c\u89c4\u5f8b\u7684\u7ec4\u5408\u8fdb\u884c\u5206\u7ec4\u5e76\u8fd4\u56de\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1a["abc", "bcd", "acef", "xyz", "az", "ba", "a", "z"]\n\u8f93\u51fa\uff1a\n[\n  ["abc","bcd","xyz"],\n  ["az","ba"],\n  ["acef"],\n  ["a","z"]\n]\n\u89e3\u91ca\uff1a\u53ef\u4ee5\u8ba4\u4e3a\u5b57\u6bcd\u8868\u9996\u5c3e\u76f8\u63a5\uff0c\u6240\u4ee5 'z' \u7684\u540e\u7eed\u4e3a 'a'\uff0c\u6240\u4ee5 ["az","ba"] \u4e5f\u6ee1\u8db3 “\u79fb\u4f4d” \u64cd\u4f5c\u89c4\u5f8b\u3002
    \n", "tags_en": ["Hash Table", "String"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> groupStrings(vector& strings) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> groupStrings(String[] strings) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def groupStrings(self, strings):\n \"\"\"\n :type strings: List[str]\n :rtype: List[List[str]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def groupStrings(self, strings: List[str]) -> List[List[str]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nchar *** groupStrings(char ** strings, int stringsSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> GroupStrings(string[] strings) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} strings\n * @return {string[][]}\n */\nvar groupStrings = function(strings) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} strings\n# @return {String[][]}\ndef group_strings(strings)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func groupStrings(_ strings: [String]) -> [[String]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func groupStrings(strings []string) [][]string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def groupStrings(strings: Array[String]): List[List[String]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun groupStrings(strings: Array): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn group_strings(strings: Vec) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $strings\n * @return String[][]\n */\n function groupStrings($strings) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function groupStrings(strings: string[]): string[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (group-strings strings)\n (-> (listof string?) (listof (listof string?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0249](https://leetcode-cn.com/problems/group-shifted-strings)", "[\u79fb\u4f4d\u5b57\u7b26\u4e32\u5206\u7ec4](/solution/0200-0299/0249.Group%20Shifted%20Strings/README.md)", "`\u54c8\u5e0c\u8868`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0249](https://leetcode.com/problems/group-shifted-strings)", "[Group Shifted Strings](/solution/0200-0299/0249.Group%20Shifted%20Strings/README_EN.md)", "`Hash Table`,`String`", "Medium", "\ud83d\udd12"]}, {"question_id": "0248", "frontend_question_id": "0248", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/strobogrammatic-number-iii", "url_en": "https://leetcode.com/problems/strobogrammatic-number-iii", "relative_path_cn": "/solution/0200-0299/0248.Strobogrammatic%20Number%20III/README.md", "relative_path_en": "/solution/0200-0299/0248.Strobogrammatic%20Number%20III/README_EN.md", "title_cn": "\u4e2d\u5fc3\u5bf9\u79f0\u6570 III", "title_en": "Strobogrammatic Number III", "question_title_slug": "strobogrammatic-number-iii", "content_en": "

    Given two strings low and high that represent two integers low and high where low <= high, return the number of strobogrammatic numbers in the range [low, high].

    \n\n

    A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down).

    \n\n

     

    \n

    Example 1:

    \n
    Input: low = \"50\", high = \"100\"\nOutput: 3\n

    Example 2:

    \n
    Input: low = \"0\", high = \"0\"\nOutput: 1\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= low.length, high.length <= 15
    • \n\t
    • low and high consist of only digits.
    • \n\t
    • low <= high
    • \n\t
    • low and high do not contain any leading zeros except for zero itself.
    • \n
    \n", "content_cn": "

    \u4e2d\u5fc3\u5bf9\u79f0\u6570\u662f\u6307\u4e00\u4e2a\u6570\u5b57\u5728\u65cb\u8f6c\u4e86 180 \u5ea6\u4e4b\u540e\u770b\u8d77\u6765\u4f9d\u65e7\u76f8\u540c\u7684\u6570\u5b57\uff08\u6216\u8005\u4e0a\u4e0b\u98a0\u5012\u5730\u770b\uff09\u3002

    \n\n

    \u5199\u4e00\u4e2a\u51fd\u6570\u6765\u8ba1\u7b97\u8303\u56f4\u5728 [low, high] \u4e4b\u95f4\u4e2d\u5fc3\u5bf9\u79f0\u6570\u7684\u4e2a\u6570\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: low = "50", high = "100"\n\u8f93\u51fa: 3 \n\u89e3\u91ca: 69\uff0c88 \u548c 96 \u662f\u4e09\u4e2a\u5728\u8be5\u8303\u56f4\u5185\u7684\u4e2d\u5fc3\u5bf9\u79f0\u6570
    \n\n

    \u6ce8\u610f:
    \n\u7531\u4e8e\u8303\u56f4\u53ef\u80fd\u5f88\u5927\uff0c\u6240\u4ee5 low \u548c high \u90fd\u7528\u5b57\u7b26\u4e32\u8868\u793a\u3002

    \n", "tags_en": ["Recursion", "Math"], "tags_cn": ["\u9012\u5f52", "\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int strobogrammaticInRange(string low, string high) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int strobogrammaticInRange(String low, String high) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def strobogrammaticInRange(self, low, high):\n \"\"\"\n :type low: str\n :type high: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def strobogrammaticInRange(self, low: str, high: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint strobogrammaticInRange(char * low, char * high){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int StrobogrammaticInRange(string low, string high) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} low\n * @param {string} high\n * @return {number}\n */\nvar strobogrammaticInRange = function(low, high) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} low\n# @param {String} high\n# @return {Integer}\ndef strobogrammatic_in_range(low, high)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func strobogrammaticInRange(_ low: String, _ high: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func strobogrammaticInRange(low string, high string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def strobogrammaticInRange(low: String, high: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun strobogrammaticInRange(low: String, high: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn strobogrammatic_in_range(low: String, high: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $low\n * @param String $high\n * @return Integer\n */\n function strobogrammaticInRange($low, $high) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function strobogrammaticInRange(low: string, high: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (strobogrammatic-in-range low high)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0248](https://leetcode-cn.com/problems/strobogrammatic-number-iii)", "[\u4e2d\u5fc3\u5bf9\u79f0\u6570 III](/solution/0200-0299/0248.Strobogrammatic%20Number%20III/README.md)", "`\u9012\u5f52`,`\u6570\u5b66`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0248](https://leetcode.com/problems/strobogrammatic-number-iii)", "[Strobogrammatic Number III](/solution/0200-0299/0248.Strobogrammatic%20Number%20III/README_EN.md)", "`Recursion`,`Math`", "Hard", "\ud83d\udd12"]}, {"question_id": "0247", "frontend_question_id": "0247", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/strobogrammatic-number-ii", "url_en": "https://leetcode.com/problems/strobogrammatic-number-ii", "relative_path_cn": "/solution/0200-0299/0247.Strobogrammatic%20Number%20II/README.md", "relative_path_en": "/solution/0200-0299/0247.Strobogrammatic%20Number%20II/README_EN.md", "title_cn": "\u4e2d\u5fc3\u5bf9\u79f0\u6570 II", "title_en": "Strobogrammatic Number II", "question_title_slug": "strobogrammatic-number-ii", "content_en": "

    Given an integer n, return all the strobogrammatic numbers that are of length n. You may return the answer in any order.

    \n\n

    A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down).

    \n\n

     

    \n

    Example 1:

    \n
    Input: n = 2\nOutput: [\"11\",\"69\",\"88\",\"96\"]\n

    Example 2:

    \n
    Input: n = 1\nOutput: [\"0\",\"1\",\"8\"]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 14
    • \n
    \n", "content_cn": "

    \u4e2d\u5fc3\u5bf9\u79f0\u6570\u662f\u6307\u4e00\u4e2a\u6570\u5b57\u5728\u65cb\u8f6c\u4e86 180 \u5ea6\u4e4b\u540e\u770b\u8d77\u6765\u4f9d\u65e7\u76f8\u540c\u7684\u6570\u5b57\uff08\u6216\u8005\u4e0a\u4e0b\u98a0\u5012\u5730\u770b\uff09\u3002

    \n\n

    \u627e\u5230\u6240\u6709\u957f\u5ea6\u4e3a n \u7684\u4e2d\u5fc3\u5bf9\u79f0\u6570\u3002

    \n\n

    \u793a\u4f8b :

    \n\n
    \u8f93\u5165:  n = 2\n\u8f93\u51fa: ["11","69","88","96"]\n
    \n", "tags_en": ["Recursion", "Math"], "tags_cn": ["\u9012\u5f52", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findStrobogrammatic(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List findStrobogrammatic(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findStrobogrammatic(self, n):\n \"\"\"\n :type n: int\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findStrobogrammatic(self, n: int) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** findStrobogrammatic(int n, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList FindStrobogrammatic(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {string[]}\n */\nvar findStrobogrammatic = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {String[]}\ndef find_strobogrammatic(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findStrobogrammatic(_ n: Int) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findStrobogrammatic(n int) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findStrobogrammatic(n: Int): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findStrobogrammatic(n: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_strobogrammatic(n: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return String[]\n */\n function findStrobogrammatic($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findStrobogrammatic(n: number): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-strobogrammatic n)\n (-> exact-integer? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0247](https://leetcode-cn.com/problems/strobogrammatic-number-ii)", "[\u4e2d\u5fc3\u5bf9\u79f0\u6570 II](/solution/0200-0299/0247.Strobogrammatic%20Number%20II/README.md)", "`\u9012\u5f52`,`\u6570\u5b66`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0247](https://leetcode.com/problems/strobogrammatic-number-ii)", "[Strobogrammatic Number II](/solution/0200-0299/0247.Strobogrammatic%20Number%20II/README_EN.md)", "`Recursion`,`Math`", "Medium", "\ud83d\udd12"]}, {"question_id": "0246", "frontend_question_id": "0246", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/strobogrammatic-number", "url_en": "https://leetcode.com/problems/strobogrammatic-number", "relative_path_cn": "/solution/0200-0299/0246.Strobogrammatic%20Number/README.md", "relative_path_en": "/solution/0200-0299/0246.Strobogrammatic%20Number/README_EN.md", "title_cn": "\u4e2d\u5fc3\u5bf9\u79f0\u6570", "title_en": "Strobogrammatic Number", "question_title_slug": "strobogrammatic-number", "content_en": "

    Given a string num which represents an integer, return true if num is a strobogrammatic number.

    \n\n

    A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down).

    \n\n

     

    \n

    Example 1:

    \n
    Input: num = \"69\"\nOutput: true\n

    Example 2:

    \n
    Input: num = \"88\"\nOutput: true\n

    Example 3:

    \n
    Input: num = \"962\"\nOutput: false\n

    Example 4:

    \n
    Input: num = \"1\"\nOutput: true\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= num.length <= 50
    • \n\t
    • num consists of only digits.
    • \n\t
    • num does not contain any leading zeros except for zero itself.
    • \n
    \n", "content_cn": "

    \u4e2d\u5fc3\u5bf9\u79f0\u6570\u662f\u6307\u4e00\u4e2a\u6570\u5b57\u5728\u65cb\u8f6c\u4e86 180 \u5ea6\u4e4b\u540e\u770b\u8d77\u6765\u4f9d\u65e7\u76f8\u540c\u7684\u6570\u5b57\uff08\u6216\u8005\u4e0a\u4e0b\u98a0\u5012\u5730\u770b\uff09\u3002

    \n\n

    \u8bf7\u5199\u4e00\u4e2a\u51fd\u6570\u6765\u5224\u65ad\u8be5\u6570\u5b57\u662f\u5426\u662f\u4e2d\u5fc3\u5bf9\u79f0\u6570\uff0c\u5176\u8f93\u5165\u5c06\u4f1a\u4ee5\u4e00\u4e2a\u5b57\u7b26\u4e32\u7684\u5f62\u5f0f\u6765\u8868\u8fbe\u6570\u5b57\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: num = "69"\n\u8f93\u51fa: true\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: num = "88"\n\u8f93\u51fa: true
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u8f93\u5165: num = "962"\n\u8f93\u51fa: false
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1anum = "1"\n\u8f93\u51fa\uff1atrue\n
    \n", "tags_en": ["Hash Table", "Math"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isStrobogrammatic(string num) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isStrobogrammatic(String num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isStrobogrammatic(self, num):\n \"\"\"\n :type num: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isStrobogrammatic(self, num: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isStrobogrammatic(char * num){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsStrobogrammatic(string num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} num\n * @return {boolean}\n */\nvar isStrobogrammatic = function(num) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} num\n# @return {Boolean}\ndef is_strobogrammatic(num)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isStrobogrammatic(_ num: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isStrobogrammatic(num string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isStrobogrammatic(num: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isStrobogrammatic(num: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_strobogrammatic(num: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $num\n * @return Boolean\n */\n function isStrobogrammatic($num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isStrobogrammatic(num: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-strobogrammatic num)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0246](https://leetcode-cn.com/problems/strobogrammatic-number)", "[\u4e2d\u5fc3\u5bf9\u79f0\u6570](/solution/0200-0299/0246.Strobogrammatic%20Number/README.md)", "`\u54c8\u5e0c\u8868`,`\u6570\u5b66`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0246](https://leetcode.com/problems/strobogrammatic-number)", "[Strobogrammatic Number](/solution/0200-0299/0246.Strobogrammatic%20Number/README_EN.md)", "`Hash Table`,`Math`", "Easy", "\ud83d\udd12"]}, {"question_id": "0245", "frontend_question_id": "0245", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/shortest-word-distance-iii", "url_en": "https://leetcode.com/problems/shortest-word-distance-iii", "relative_path_cn": "/solution/0200-0299/0245.Shortest%20Word%20Distance%20III/README.md", "relative_path_en": "/solution/0200-0299/0245.Shortest%20Word%20Distance%20III/README_EN.md", "title_cn": "\u6700\u77ed\u5355\u8bcd\u8ddd\u79bb III", "title_en": "Shortest Word Distance III", "question_title_slug": "shortest-word-distance-iii", "content_en": "

    Given an array of strings wordsDict and two strings that already exist in the array word1 and word2, return the shortest distance between these two words in the list.

    \n\n

    Note that word1 and word2 may be the same. It is guaranteed that they represent two individual words in the list.

    \n\n

     

    \n

    Example 1:

    \n
    Input: wordsDict = [\"practice\", \"makes\", \"perfect\", \"coding\", \"makes\"], word1 = \"makes\", word2 = \"coding\"\nOutput: 1\n

    Example 2:

    \n
    Input: wordsDict = [\"practice\", \"makes\", \"perfect\", \"coding\", \"makes\"], word1 = \"makes\", word2 = \"makes\"\nOutput: 3\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= wordsDict.length <= 3 * 104
    • \n\t
    • 1 <= wordsDict[i].length <= 10
    • \n\t
    • wordsDict[i] consists of lowercase English letters.
    • \n\t
    • word1 and word2 are in wordsDict.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5355\u8bcd\u5217\u8868\u548c\u4e24\u4e2a\u5355\u8bcd word1 \u548c word2\uff0c\u8fd4\u56de\u5217\u8868\u4e2d\u8fd9\u4e24\u4e2a\u5355\u8bcd\u4e4b\u95f4\u7684\u6700\u77ed\u8ddd\u79bb\u3002

    \n\n

    word1 \u548c word2 \u662f\u6709\u53ef\u80fd\u76f8\u540c\u7684\uff0c\u5e76\u4e14\u5b83\u4eec\u5c06\u5206\u522b\u8868\u793a\u4e3a\u5217\u8868\u4e2d\u4e24\u4e2a\u72ec\u7acb\u7684\u5355\u8bcd\u3002

    \n\n

    \u793a\u4f8b:
    \n\u5047\u8bbe words = ["practice", "makes", "perfect", "coding", "makes"].

    \n\n
    \u8f93\u5165: word1 = “makes”, word2 = “coding”\n\u8f93\u51fa: 1\n
    \n\n
    \u8f93\u5165: word1 = "makes", word2 = "makes"\n\u8f93\u51fa: 3\n
    \n\n

    \u6ce8\u610f:
    \n\u4f60\u53ef\u4ee5\u5047\u8bbe word1 \u548c word2 \u90fd\u5728\u5217\u8868\u91cc\u3002

    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int shortestWordDistance(vector& wordsDict, string word1, string word2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int shortestWordDistance(String[] wordsDict, String word1, String word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def shortestWordDistance(self, wordsDict, word1, word2):\n \"\"\"\n :type wordsDict: List[str]\n :type word1: str\n :type word2: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def shortestWordDistance(self, wordsDict: List[str], word1: str, word2: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint shortestWordDistance(char ** wordsDict, int wordsDictSize, char * word1, char * word2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ShortestWordDistance(string[] wordsDict, string word1, string word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} wordsDict\n * @param {string} word1\n * @param {string} word2\n * @return {number}\n */\nvar shortestWordDistance = function(wordsDict, word1, word2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words_dict\n# @param {String} word1\n# @param {String} word2\n# @return {Integer}\ndef shortest_word_distance(words_dict, word1, word2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func shortestWordDistance(_ wordsDict: [String], _ word1: String, _ word2: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func shortestWordDistance(wordsDict []string, word1 string, word2 string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def shortestWordDistance(wordsDict: Array[String], word1: String, word2: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun shortestWordDistance(wordsDict: Array, word1: String, word2: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn shortest_word_distance(words_dict: Vec, word1: String, word2: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $wordsDict\n * @param String $word1\n * @param String $word2\n * @return Integer\n */\n function shortestWordDistance($wordsDict, $word1, $word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function shortestWordDistance(wordsDict: string[], word1: string, word2: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (shortest-word-distance wordsDict word1 word2)\n (-> (listof string?) string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0245](https://leetcode-cn.com/problems/shortest-word-distance-iii)", "[\u6700\u77ed\u5355\u8bcd\u8ddd\u79bb III](/solution/0200-0299/0245.Shortest%20Word%20Distance%20III/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0245](https://leetcode.com/problems/shortest-word-distance-iii)", "[Shortest Word Distance III](/solution/0200-0299/0245.Shortest%20Word%20Distance%20III/README_EN.md)", "`Array`", "Medium", "\ud83d\udd12"]}, {"question_id": "0244", "frontend_question_id": "0244", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/shortest-word-distance-ii", "url_en": "https://leetcode.com/problems/shortest-word-distance-ii", "relative_path_cn": "/solution/0200-0299/0244.Shortest%20Word%20Distance%20II/README.md", "relative_path_en": "/solution/0200-0299/0244.Shortest%20Word%20Distance%20II/README_EN.md", "title_cn": "\u6700\u77ed\u5355\u8bcd\u8ddd\u79bb II", "title_en": "Shortest Word Distance II", "question_title_slug": "shortest-word-distance-ii", "content_en": "

    Design a data structure that will be initialized with a string array, and then it should answer queries of the shortest distance between two different strings from the array.

    \n\n

    Implement the WordDistance class:

    \n\n
      \n\t
    • WordDistance(String[] wordsDict) initializes the object with the strings array wordsDict.
    • \n\t
    • int shortest(String word1, String word2) returns the shortest distance between word1 and word2 in the array wordsDict.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["WordDistance", "shortest", "shortest"]\n[[["practice", "makes", "perfect", "coding", "makes"]], ["coding", "practice"], ["makes", "coding"]]\nOutput\n[null, 3, 1]\n\nExplanation\nWordDistance wordDistance = new WordDistance(["practice", "makes", "perfect", "coding", "makes"]);\nwordDistance.shortest("coding", "practice"); // return 3\nwordDistance.shortest("makes", "coding");    // return 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= wordsDict.length <= 3 * 104
    • \n\t
    • 1 <= wordsDict[i].length <= 10
    • \n\t
    • wordsDict[i] consists of lowercase English letters.
    • \n\t
    • word1 and word2 are in wordsDict.
    • \n\t
    • word1 != word2
    • \n\t
    • At most 5000 calls will be made to shortest.
    • \n
    \n", "content_cn": "

    \u8bf7\u8bbe\u8ba1\u4e00\u4e2a\u7c7b\uff0c\u4f7f\u8be5\u7c7b\u7684\u6784\u9020\u51fd\u6570\u80fd\u591f\u63a5\u6536\u4e00\u4e2a\u5355\u8bcd\u5217\u8868\u3002\u7136\u540e\u518d\u5b9e\u73b0\u4e00\u4e2a\u65b9\u6cd5\uff0c\u8be5\u65b9\u6cd5\u80fd\u591f\u5206\u522b\u63a5\u6536\u4e24\u4e2a\u5355\u8bcd word1 \u548c word2\uff0c\u5e76\u8fd4\u56de\u5217\u8868\u4e2d\u8fd9\u4e24\u4e2a\u5355\u8bcd\u4e4b\u95f4\u7684\u6700\u77ed\u8ddd\u79bb\u3002\u60a8\u7684\u65b9\u6cd5\u5c06\u88ab\u4ee5\u4e0d\u540c\u7684\u53c2\u6570\u8c03\u7528 \u591a\u6b21\u3002

    \n\n

    \u793a\u4f8b:
    \n\u5047\u8bbe words = ["practice", "makes", "perfect", "coding", "makes"]

    \n\n
    \u8f93\u5165: word1 = “coding”, word2 = “practice”\n\u8f93\u51fa: 3\n
    \n\n
    \u8f93\u5165: word1 = "makes", word2 = "coding"\n\u8f93\u51fa: 1
    \n\n

    \u6ce8\u610f:
    \n\u4f60\u53ef\u4ee5\u5047\u8bbe word1 \u4e0d\u7b49\u4e8e word2, \u5e76\u4e14 word1 \u548c word2 \u90fd\u5728\u5217\u8868\u91cc\u3002

    \n", "tags_en": ["Design", "Hash Table"], "tags_cn": ["\u8bbe\u8ba1", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class WordDistance {\npublic:\n WordDistance(vector& wordsDict) {\n\n }\n \n int shortest(string word1, string word2) {\n\n }\n};\n\n/**\n * Your WordDistance object will be instantiated and called as such:\n * WordDistance* obj = new WordDistance(wordsDict);\n * int param_1 = obj->shortest(word1,word2);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class WordDistance {\n\n public WordDistance(String[] wordsDict) {\n\n }\n \n public int shortest(String word1, String word2) {\n\n }\n}\n\n/**\n * Your WordDistance object will be instantiated and called as such:\n * WordDistance obj = new WordDistance(wordsDict);\n * int param_1 = obj.shortest(word1,word2);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class WordDistance(object):\n\n def __init__(self, wordsDict):\n \"\"\"\n :type wordsDict: List[str]\n \"\"\"\n\n\n def shortest(self, word1, word2):\n \"\"\"\n :type word1: str\n :type word2: str\n :rtype: int\n \"\"\"\n\n\n\n# Your WordDistance object will be instantiated and called as such:\n# obj = WordDistance(wordsDict)\n# param_1 = obj.shortest(word1,word2)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class WordDistance:\n\n def __init__(self, wordsDict: List[str]):\n\n\n def shortest(self, word1: str, word2: str) -> int:\n\n\n\n# Your WordDistance object will be instantiated and called as such:\n# obj = WordDistance(wordsDict)\n# param_1 = obj.shortest(word1,word2)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} WordDistance;\n\n\nWordDistance* wordDistanceCreate(char ** wordsDict, int wordsDictSize) {\n \n}\n\nint wordDistanceShortest(WordDistance* obj, char * word1, char * word2) {\n \n}\n\nvoid wordDistanceFree(WordDistance* obj) {\n \n}\n\n/**\n * Your WordDistance struct will be instantiated and called as such:\n * WordDistance* obj = wordDistanceCreate(wordsDict, wordsDictSize);\n * int param_1 = wordDistanceShortest(obj, word1, word2);\n \n * wordDistanceFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class WordDistance {\n\n public WordDistance(string[] wordsDict) {\n\n }\n \n public int Shortest(string word1, string word2) {\n\n }\n}\n\n/**\n * Your WordDistance object will be instantiated and called as such:\n * WordDistance obj = new WordDistance(wordsDict);\n * int param_1 = obj.Shortest(word1,word2);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} wordsDict\n */\nvar WordDistance = function(wordsDict) {\n\n};\n\n/** \n * @param {string} word1 \n * @param {string} word2\n * @return {number}\n */\nWordDistance.prototype.shortest = function(word1, word2) {\n\n};\n\n/**\n * Your WordDistance object will be instantiated and called as such:\n * var obj = new WordDistance(wordsDict)\n * var param_1 = obj.shortest(word1,word2)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class WordDistance\n\n=begin\n :type words_dict: String[]\n=end\n def initialize(words_dict)\n\n end\n\n\n=begin\n :type word1: String\n :type word2: String\n :rtype: Integer\n=end\n def shortest(word1, word2)\n\n end\n\n\nend\n\n# Your WordDistance object will be instantiated and called as such:\n# obj = WordDistance.new(words_dict)\n# param_1 = obj.shortest(word1, word2)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass WordDistance {\n\n init(_ wordsDict: [String]) {\n\n }\n \n func shortest(_ word1: String, _ word2: String) -> Int {\n\n }\n}\n\n/**\n * Your WordDistance object will be instantiated and called as such:\n * let obj = WordDistance(wordsDict)\n * let ret_1: Int = obj.shortest(word1, word2)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type WordDistance struct {\n\n}\n\n\nfunc Constructor(wordsDict []string) WordDistance {\n\n}\n\n\nfunc (this *WordDistance) Shortest(word1 string, word2 string) int {\n\n}\n\n\n/**\n * Your WordDistance object will be instantiated and called as such:\n * obj := Constructor(wordsDict);\n * param_1 := obj.Shortest(word1,word2);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class WordDistance(_wordsDict: Array[String]) {\n\n def shortest(word1: String, word2: String): Int = {\n\n }\n\n}\n\n/**\n * Your WordDistance object will be instantiated and called as such:\n * var obj = new WordDistance(wordsDict)\n * var param_1 = obj.shortest(word1,word2)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class WordDistance(wordsDict: Array) {\n\n fun shortest(word1: String, word2: String): Int {\n\n }\n\n}\n\n/**\n * Your WordDistance object will be instantiated and called as such:\n * var obj = WordDistance(wordsDict)\n * var param_1 = obj.shortest(word1,word2)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct WordDistance {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl WordDistance {\n\n fn new(wordsDict: Vec) -> Self {\n\n }\n \n fn shortest(&self, word1: String, word2: String) -> i32 {\n\n }\n}\n\n/**\n * Your WordDistance object will be instantiated and called as such:\n * let obj = WordDistance::new(wordsDict);\n * let ret_1: i32 = obj.shortest(word1, word2);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class WordDistance {\n /**\n * @param String[] $wordsDict\n */\n function __construct($wordsDict) {\n\n }\n\n /**\n * @param String $word1\n * @param String $word2\n * @return Integer\n */\n function shortest($word1, $word2) {\n\n }\n}\n\n/**\n * Your WordDistance object will be instantiated and called as such:\n * $obj = WordDistance($wordsDict);\n * $ret_1 = $obj->shortest($word1, $word2);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class WordDistance {\n constructor(wordsDict: string[]) {\n\n }\n\n shortest(word1: string, word2: string): number {\n\n }\n}\n\n/**\n * Your WordDistance object will be instantiated and called as such:\n * var obj = new WordDistance(wordsDict)\n * var param_1 = obj.shortest(word1,word2)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define word-distance%\n (class object%\n (super-new)\n\n ; words-dict : (listof string?)\n (init-field\n words-dict)\n \n ; shortest : string? string? -> exact-integer?\n (define/public (shortest word1 word2)\n\n )))\n\n;; Your word-distance% object will be instantiated and called as such:\n;; (define obj (new word-distance% [wordsDict wordsDict]))\n;; (define param_1 (send obj shortest word1 word2))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0244](https://leetcode-cn.com/problems/shortest-word-distance-ii)", "[\u6700\u77ed\u5355\u8bcd\u8ddd\u79bb II](/solution/0200-0299/0244.Shortest%20Word%20Distance%20II/README.md)", "`\u8bbe\u8ba1`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0244](https://leetcode.com/problems/shortest-word-distance-ii)", "[Shortest Word Distance II](/solution/0200-0299/0244.Shortest%20Word%20Distance%20II/README_EN.md)", "`Design`,`Hash Table`", "Medium", "\ud83d\udd12"]}, {"question_id": "0243", "frontend_question_id": "0243", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/shortest-word-distance", "url_en": "https://leetcode.com/problems/shortest-word-distance", "relative_path_cn": "/solution/0200-0299/0243.Shortest%20Word%20Distance/README.md", "relative_path_en": "/solution/0200-0299/0243.Shortest%20Word%20Distance/README_EN.md", "title_cn": "\u6700\u77ed\u5355\u8bcd\u8ddd\u79bb", "title_en": "Shortest Word Distance", "question_title_slug": "shortest-word-distance", "content_en": "

    Given an array of strings wordsDict and two different strings that already exist in the array word1 and word2, return the shortest distance between these two words in the list.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: wordsDict = ["practice", "makes", "perfect", "coding", "makes"], word1 = "coding", word2 = "practice"\nOutput: 3\n
    \n\n

    Example 2:

    \n\n
    \nInput: wordsDict = ["practice", "makes", "perfect", "coding", "makes"], word1 = "makes", word2 = "coding"\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= wordsDict.length <= 3 * 104
    • \n\t
    • 1 <= wordsDict[i].length <= 10
    • \n\t
    • wordsDict[i] consists of lowercase English letters.
    • \n\t
    • word1 and word2 are in wordsDict.
    • \n\t
    • word1 != word2
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5355\u8bcd\u5217\u8868\u548c\u4e24\u4e2a\u5355\u8bcd word1 \u548c word2\uff0c\u8fd4\u56de\u5217\u8868\u4e2d\u8fd9\u4e24\u4e2a\u5355\u8bcd\u4e4b\u95f4\u7684\u6700\u77ed\u8ddd\u79bb\u3002

    \n\n

    \u793a\u4f8b:
    \n\u5047\u8bbe words = ["practice", "makes", "perfect", "coding", "makes"]

    \n\n
    \u8f93\u5165: word1 = “coding”, word2 = “practice”\n\u8f93\u51fa: 3\n
    \n\n
    \u8f93\u5165: word1 = "makes", word2 = "coding"\n\u8f93\u51fa: 1\n
    \n\n

    \u6ce8\u610f:
    \n\u4f60\u53ef\u4ee5\u5047\u8bbe word1 \u4e0d\u7b49\u4e8e word2, \u5e76\u4e14 word1 \u548c word2 \u90fd\u5728\u5217\u8868\u91cc\u3002

    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int shortestDistance(vector& wordsDict, string word1, string word2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int shortestDistance(String[] wordsDict, String word1, String word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def shortestDistance(self, wordsDict, word1, word2):\n \"\"\"\n :type wordsDict: List[str]\n :type word1: str\n :type word2: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def shortestDistance(self, wordsDict: List[str], word1: str, word2: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint shortestDistance(char ** wordsDict, int wordsDictSize, char * word1, char * word2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ShortestDistance(string[] wordsDict, string word1, string word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} wordsDict\n * @param {string} word1\n * @param {string} word2\n * @return {number}\n */\nvar shortestDistance = function(wordsDict, word1, word2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words_dict\n# @param {String} word1\n# @param {String} word2\n# @return {Integer}\ndef shortest_distance(words_dict, word1, word2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func shortestDistance(_ wordsDict: [String], _ word1: String, _ word2: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func shortestDistance(wordsDict []string, word1 string, word2 string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def shortestDistance(wordsDict: Array[String], word1: String, word2: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun shortestDistance(wordsDict: Array, word1: String, word2: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn shortest_distance(words_dict: Vec, word1: String, word2: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $wordsDict\n * @param String $word1\n * @param String $word2\n * @return Integer\n */\n function shortestDistance($wordsDict, $word1, $word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function shortestDistance(wordsDict: string[], word1: string, word2: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (shortest-distance wordsDict word1 word2)\n (-> (listof string?) string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0243](https://leetcode-cn.com/problems/shortest-word-distance)", "[\u6700\u77ed\u5355\u8bcd\u8ddd\u79bb](/solution/0200-0299/0243.Shortest%20Word%20Distance/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0243](https://leetcode.com/problems/shortest-word-distance)", "[Shortest Word Distance](/solution/0200-0299/0243.Shortest%20Word%20Distance/README_EN.md)", "`Array`", "Easy", "\ud83d\udd12"]}, {"question_id": "0242", "frontend_question_id": "0242", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/valid-anagram", "url_en": "https://leetcode.com/problems/valid-anagram", "relative_path_cn": "/solution/0200-0299/0242.Valid%20Anagram/README.md", "relative_path_en": "/solution/0200-0299/0242.Valid%20Anagram/README_EN.md", "title_cn": "\u6709\u6548\u7684\u5b57\u6bcd\u5f02\u4f4d\u8bcd", "title_en": "Valid Anagram", "question_title_slug": "valid-anagram", "content_en": "

    Given two strings s and t, return true if t is an anagram of s, and false otherwise.

    \n\n

     

    \n

    Example 1:

    \n
    Input: s = \"anagram\", t = \"nagaram\"\nOutput: true\n

    Example 2:

    \n
    Input: s = \"rat\", t = \"car\"\nOutput: false\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length, t.length <= 5 * 104
    • \n\t
    • s and t consist of lowercase English letters.
    • \n
    \n\n

     

    \n

    Follow up: What if the inputs contain Unicode characters? How would you adapt your solution to such a case?

    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u5b57\u7b26\u4e32 s \u548c t \uff0c\u7f16\u5199\u4e00\u4e2a\u51fd\u6570\u6765\u5224\u65ad t \u662f\u5426\u662f s \u7684\u5b57\u6bcd\u5f02\u4f4d\u8bcd\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: s = "anagram", t = "nagaram"\n\u8f93\u51fa: true\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: s = "rat", t = "car"\n\u8f93\u51fa: false
    \n\n

    \u8bf4\u660e:
    \n\u4f60\u53ef\u4ee5\u5047\u8bbe\u5b57\u7b26\u4e32\u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd\u3002

    \n\n

    \u8fdb\u9636:
    \n\u5982\u679c\u8f93\u5165\u5b57\u7b26\u4e32\u5305\u542b unicode \u5b57\u7b26\u600e\u4e48\u529e\uff1f\u4f60\u80fd\u5426\u8c03\u6574\u4f60\u7684\u89e3\u6cd5\u6765\u5e94\u5bf9\u8fd9\u79cd\u60c5\u51b5\uff1f

    \n", "tags_en": ["Sort", "Hash Table"], "tags_cn": ["\u6392\u5e8f", "\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isAnagram(string s, string t) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isAnagram(String s, String t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isAnagram(self, s, t):\n \"\"\"\n :type s: str\n :type t: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isAnagram(self, s: str, t: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isAnagram(char * s, char * t){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsAnagram(string s, string t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string} t\n * @return {boolean}\n */\nvar isAnagram = function(s, t) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String} t\n# @return {Boolean}\ndef is_anagram(s, t)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isAnagram(_ s: String, _ t: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isAnagram(s string, t string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isAnagram(s: String, t: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isAnagram(s: String, t: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_anagram(s: String, t: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String $t\n * @return Boolean\n */\n function isAnagram($s, $t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isAnagram(s: string, t: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-anagram s t)\n (-> string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0242](https://leetcode-cn.com/problems/valid-anagram)", "[\u6709\u6548\u7684\u5b57\u6bcd\u5f02\u4f4d\u8bcd](/solution/0200-0299/0242.Valid%20Anagram/README.md)", "`\u6392\u5e8f`,`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0242](https://leetcode.com/problems/valid-anagram)", "[Valid Anagram](/solution/0200-0299/0242.Valid%20Anagram/README_EN.md)", "`Sort`,`Hash Table`", "Easy", ""]}, {"question_id": "0241", "frontend_question_id": "0241", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/different-ways-to-add-parentheses", "url_en": "https://leetcode.com/problems/different-ways-to-add-parentheses", "relative_path_cn": "/solution/0200-0299/0241.Different%20Ways%20to%20Add%20Parentheses/README.md", "relative_path_en": "/solution/0200-0299/0241.Different%20Ways%20to%20Add%20Parentheses/README_EN.md", "title_cn": "\u4e3a\u8fd0\u7b97\u8868\u8fbe\u5f0f\u8bbe\u8ba1\u4f18\u5148\u7ea7", "title_en": "Different Ways to Add Parentheses", "question_title_slug": "different-ways-to-add-parentheses", "content_en": "

    Given a string expression of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. You may return the answer in any order.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: expression = "2-1-1"\nOutput: [0,2]\nExplanation:\n((2-1)-1) = 0 \n(2-(1-1)) = 2\n
    \n\n

    Example 2:

    \n\n
    \nInput: expression = "2*3-4*5"\nOutput: [-34,-14,-10,-10,10]\nExplanation:\n(2*(3-(4*5))) = -34 \n((2*3)-(4*5)) = -14 \n((2*(3-4))*5) = -10 \n(2*((3-4)*5)) = -10 \n(((2*3)-4)*5) = 10\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= expression.length <= 20
    • \n\t
    • expression consists of digits and the operator '+', '-', and '*'.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u542b\u6709\u6570\u5b57\u548c\u8fd0\u7b97\u7b26\u7684\u5b57\u7b26\u4e32\uff0c\u4e3a\u8868\u8fbe\u5f0f\u6dfb\u52a0\u62ec\u53f7\uff0c\u6539\u53d8\u5176\u8fd0\u7b97\u4f18\u5148\u7ea7\u4ee5\u6c42\u51fa\u4e0d\u540c\u7684\u7ed3\u679c\u3002\u4f60\u9700\u8981\u7ed9\u51fa\u6240\u6709\u53ef\u80fd\u7684\u7ec4\u5408\u7684\u7ed3\u679c\u3002\u6709\u6548\u7684\u8fd0\u7b97\u7b26\u53f7\u5305\u542b +- \u4ee5\u53ca * \u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: "2-1-1"\n\u8f93\u51fa: [0, 2]\n\u89e3\u91ca: \n((2-1)-1) = 0 \n(2-(1-1)) = 2
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: "2*3-4*5"\n\u8f93\u51fa: [-34, -14, -10, -10, 10]\n\u89e3\u91ca: \n(2*(3-(4*5))) = -34 \n((2*3)-(4*5)) = -14 \n((2*(3-4))*5) = -10 \n(2*((3-4)*5)) = -10 \n(((2*3)-4)*5) = 10
    \n", "tags_en": ["Divide and Conquer"], "tags_cn": ["\u5206\u6cbb\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector diffWaysToCompute(string expression) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List diffWaysToCompute(String expression) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def diffWaysToCompute(self, expression):\n \"\"\"\n :type expression: str\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def diffWaysToCompute(self, expression: str) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* diffWaysToCompute(char * expression, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList DiffWaysToCompute(string expression) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} expression\n * @return {number[]}\n */\nvar diffWaysToCompute = function(expression) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} expression\n# @return {Integer[]}\ndef diff_ways_to_compute(expression)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func diffWaysToCompute(_ expression: String) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func diffWaysToCompute(expression string) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def diffWaysToCompute(expression: String): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun diffWaysToCompute(expression: String): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn diff_ways_to_compute(expression: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $expression\n * @return Integer[]\n */\n function diffWaysToCompute($expression) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function diffWaysToCompute(expression: string): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (diff-ways-to-compute expression)\n (-> string? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0241](https://leetcode-cn.com/problems/different-ways-to-add-parentheses)", "[\u4e3a\u8fd0\u7b97\u8868\u8fbe\u5f0f\u8bbe\u8ba1\u4f18\u5148\u7ea7](/solution/0200-0299/0241.Different%20Ways%20to%20Add%20Parentheses/README.md)", "`\u5206\u6cbb\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0241](https://leetcode.com/problems/different-ways-to-add-parentheses)", "[Different Ways to Add Parentheses](/solution/0200-0299/0241.Different%20Ways%20to%20Add%20Parentheses/README_EN.md)", "`Divide and Conquer`", "Medium", ""]}, {"question_id": "0240", "frontend_question_id": "0240", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/search-a-2d-matrix-ii", "url_en": "https://leetcode.com/problems/search-a-2d-matrix-ii", "relative_path_cn": "/solution/0200-0299/0240.Search%20a%202D%20Matrix%20II/README.md", "relative_path_en": "/solution/0200-0299/0240.Search%20a%202D%20Matrix%20II/README_EN.md", "title_cn": "\u641c\u7d22\u4e8c\u7ef4\u77e9\u9635 II", "title_en": "Search a 2D Matrix II", "question_title_slug": "search-a-2d-matrix-ii", "content_en": "

    Write an efficient algorithm that searches for a target value in an m x n integer matrix. The matrix has the following properties:

    \n\n
      \n\t
    • Integers in each row are sorted in ascending from left to right.
    • \n\t
    • Integers in each column are sorted in ascending from top to bottom.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: matrix = [[1,4,7,11,15],[2,5,8,12,19],[3,6,9,16,22],[10,13,14,17,24],[18,21,23,26,30]], target = 5\nOutput: true\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: matrix = [[1,4,7,11,15],[2,5,8,12,19],[3,6,9,16,22],[10,13,14,17,24],[18,21,23,26,30]], target = 20\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == matrix.length
    • \n\t
    • n == matrix[i].length
    • \n\t
    • 1 <= n, m <= 300
    • \n\t
    • -109 <= matix[i][j] <= 109
    • \n\t
    • All the integers in each row are sorted in ascending order.
    • \n\t
    • All the integers in each column are sorted in ascending order.
    • \n\t
    • -109 <= target <= 109
    • \n
    \n", "content_cn": "

    \u7f16\u5199\u4e00\u4e2a\u9ad8\u6548\u7684\u7b97\u6cd5\u6765\u641c\u7d22\u00a0m\u00a0x\u00a0n\u00a0\u77e9\u9635 matrix \u4e2d\u7684\u4e00\u4e2a\u76ee\u6807\u503c target \u3002\u8be5\u77e9\u9635\u5177\u6709\u4ee5\u4e0b\u7279\u6027\uff1a

    \n\n
      \n\t
    • \u6bcf\u884c\u7684\u5143\u7d20\u4ece\u5de6\u5230\u53f3\u5347\u5e8f\u6392\u5217\u3002
    • \n\t
    • \u6bcf\u5217\u7684\u5143\u7d20\u4ece\u4e0a\u5230\u4e0b\u5347\u5e8f\u6392\u5217\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1amatrix = [[1,4,7,11,15],[2,5,8,12,19],[3,6,9,16,22],[10,13,14,17,24],[18,21,23,26,30]], target = 5\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1amatrix = [[1,4,7,11,15],[2,5,8,12,19],[3,6,9,16,22],[10,13,14,17,24],[18,21,23,26,30]], target = 20\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == matrix.length
    • \n\t
    • n == matrix[i].length
    • \n\t
    • 1 <= n, m <= 300
    • \n\t
    • -109\u00a0<= matix[i][j] <= 109
    • \n\t
    • \u6bcf\u884c\u7684\u6240\u6709\u5143\u7d20\u4ece\u5de6\u5230\u53f3\u5347\u5e8f\u6392\u5217
    • \n\t
    • \u6bcf\u5217\u7684\u6240\u6709\u5143\u7d20\u4ece\u4e0a\u5230\u4e0b\u5347\u5e8f\u6392\u5217
    • \n\t
    • -109\u00a0<= target <= 109
    • \n
    \n", "tags_en": ["Binary Search", "Divide and Conquer"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e", "\u5206\u6cbb\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool searchMatrix(vector>& matrix, int target) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean searchMatrix(int[][] matrix, int target) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def searchMatrix(self, matrix, target):\n \"\"\"\n :type matrix: List[List[int]]\n :type target: int\n :rtype: bool\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def searchMatrix(self, matrix: List[List[int]], target: int) -> bool:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool searchMatrix(int** matrix, int matrixSize, int* matrixColSize, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool SearchMatrix(int[][] matrix, int target) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} matrix\n * @param {number} target\n * @return {boolean}\n */\nvar searchMatrix = function(matrix, target) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} matrix\n# @param {Integer} target\n# @return {Boolean}\ndef search_matrix(matrix, target)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func searchMatrix(_ matrix: [[Int]], _ target: Int) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func searchMatrix(matrix [][]int, target int) bool {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def searchMatrix(matrix: Array[Array[Int]], target: Int): Boolean = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun searchMatrix(matrix: Array, target: Int): Boolean {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn search_matrix(matrix: Vec>, target: i32) -> bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $matrix\n * @param Integer $target\n * @return Boolean\n */\n function searchMatrix($matrix, $target) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function searchMatrix(matrix: number[][], target: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0240](https://leetcode-cn.com/problems/search-a-2d-matrix-ii)", "[\u641c\u7d22\u4e8c\u7ef4\u77e9\u9635 II](/solution/0200-0299/0240.Search%20a%202D%20Matrix%20II/README.md)", "`\u4e8c\u5206\u67e5\u627e`,`\u5206\u6cbb\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0240](https://leetcode.com/problems/search-a-2d-matrix-ii)", "[Search a 2D Matrix II](/solution/0200-0299/0240.Search%20a%202D%20Matrix%20II/README_EN.md)", "`Binary Search`,`Divide and Conquer`", "Medium", ""]}, {"question_id": "0239", "frontend_question_id": "0239", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sliding-window-maximum", "url_en": "https://leetcode.com/problems/sliding-window-maximum", "relative_path_cn": "/solution/0200-0299/0239.Sliding%20Window%20Maximum/README.md", "relative_path_en": "/solution/0200-0299/0239.Sliding%20Window%20Maximum/README_EN.md", "title_cn": "\u6ed1\u52a8\u7a97\u53e3\u6700\u5927\u503c", "title_en": "Sliding Window Maximum", "question_title_slug": "sliding-window-maximum", "content_en": "

    You are given an array of integers nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window moves right by one position.

    \n\n

    Return the max sliding window.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,3,-1,-3,5,3,6,7], k = 3\nOutput: [3,3,5,5,6,7]\nExplanation: \nWindow position                Max\n---------------               -----\n[1  3  -1] -3  5  3  6  7       3\n 1 [3  -1  -3] 5  3  6  7       3\n 1  3 [-1  -3  5] 3  6  7       5\n 1  3  -1 [-3  5  3] 6  7       5\n 1  3  -1  -3 [5  3  6] 7       6\n 1  3  -1  -3  5 [3  6  7]      7\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1], k = 1\nOutput: [1]\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [1,-1], k = 1\nOutput: [1,-1]\n
    \n\n

    Example 4:

    \n\n
    \nInput: nums = [9,11], k = 2\nOutput: [11]\n
    \n\n

    Example 5:

    \n\n
    \nInput: nums = [4,-2], k = 2\nOutput: [4]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • -104 <= nums[i] <= 104
    • \n\t
    • 1 <= k <= nums.length
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums\uff0c\u6709\u4e00\u4e2a\u5927\u5c0f\u4e3a\u00a0k\u00a0\u7684\u6ed1\u52a8\u7a97\u53e3\u4ece\u6570\u7ec4\u7684\u6700\u5de6\u4fa7\u79fb\u52a8\u5230\u6570\u7ec4\u7684\u6700\u53f3\u4fa7\u3002\u4f60\u53ea\u53ef\u4ee5\u770b\u5230\u5728\u6ed1\u52a8\u7a97\u53e3\u5185\u7684 k\u00a0\u4e2a\u6570\u5b57\u3002\u6ed1\u52a8\u7a97\u53e3\u6bcf\u6b21\u53ea\u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\u3002

    \n\n

    \u8fd4\u56de\u6ed1\u52a8\u7a97\u53e3\u4e2d\u7684\u6700\u5927\u503c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,3,-1,-3,5,3,6,7], k = 3\n\u8f93\u51fa\uff1a[3,3,5,5,6,7]\n\u89e3\u91ca\uff1a\n\u6ed1\u52a8\u7a97\u53e3\u7684\u4f4d\u7f6e                \u6700\u5927\u503c\n---------------               -----\n[1  3  -1] -3  5  3  6  7       3\n 1 [3  -1  -3] 5  3  6  7       3\n 1  3 [-1  -3  5] 3  6  7       5\n 1  3  -1 [-3  5  3] 6  7       5\n 1  3  -1  -3 [5  3  6] 7       6\n 1  3  -1  -3  5 [3  6  7]      7\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1], k = 1\n\u8f93\u51fa\uff1a[1]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,-1], k = 1\n\u8f93\u51fa\uff1a[1,-1]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [9,11], k = 2\n\u8f93\u51fa\uff1a[11]\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [4,-2], k = 2\n\u8f93\u51fa\uff1a[4]
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • -104\u00a0<= nums[i] <= 104
    • \n\t
    • 1 <= k <= nums.length
    • \n
    \n", "tags_en": ["Heap", "Sliding Window"], "tags_cn": ["\u5806"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector maxSlidingWindow(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] maxSlidingWindow(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxSlidingWindow(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxSlidingWindow(self, nums: List[int], k: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* maxSlidingWindow(int* nums, int numsSize, int k, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] MaxSlidingWindow(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number[]}\n */\nvar maxSlidingWindow = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer[]}\ndef max_sliding_window(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxSlidingWindow(_ nums: [Int], _ k: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxSlidingWindow(nums []int, k int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxSlidingWindow(nums: Array[Int], k: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxSlidingWindow(nums: IntArray, k: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_sliding_window(nums: Vec, k: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer[]\n */\n function maxSlidingWindow($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxSlidingWindow(nums: number[], k: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-sliding-window nums k)\n (-> (listof exact-integer?) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0239](https://leetcode-cn.com/problems/sliding-window-maximum)", "[\u6ed1\u52a8\u7a97\u53e3\u6700\u5927\u503c](/solution/0200-0299/0239.Sliding%20Window%20Maximum/README.md)", "`\u5806`", "\u56f0\u96be", ""], "md_table_row_en": ["[0239](https://leetcode.com/problems/sliding-window-maximum)", "[Sliding Window Maximum](/solution/0200-0299/0239.Sliding%20Window%20Maximum/README_EN.md)", "`Heap`,`Sliding Window`", "Hard", ""]}, {"question_id": "0238", "frontend_question_id": "0238", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/product-of-array-except-self", "url_en": "https://leetcode.com/problems/product-of-array-except-self", "relative_path_cn": "/solution/0200-0299/0238.Product%20of%20Array%20Except%20Self/README.md", "relative_path_en": "/solution/0200-0299/0238.Product%20of%20Array%20Except%20Self/README_EN.md", "title_cn": "\u9664\u81ea\u8eab\u4ee5\u5916\u6570\u7ec4\u7684\u4e58\u79ef", "title_en": "Product of Array Except Self", "question_title_slug": "product-of-array-except-self", "content_en": "

    Given an integer array nums, return an array answer such that answer[i] is equal to the product of all the elements of nums except nums[i].

    \n\n

    The product of any prefix or suffix of nums is guaranteed to fit in a 32-bit integer.

    \n\n

    You must write an algorithm that runs in O(n) time and without using the division operation.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [1,2,3,4]\nOutput: [24,12,8,6]\n

    Example 2:

    \n
    Input: nums = [-1,1,0,-3,3]\nOutput: [0,0,9,0,0]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= nums.length <= 105
    • \n\t
    • -30 <= nums[i] <= 30
    • \n\t
    • The product of any prefix or suffix of nums is guaranteed to fit in a 32-bit integer.
    • \n
    \n\n

     

    \n

    Follow up: Can you solve the problem in O(1) extra space complexity? (The output array does not count as extra space for space complexity analysis.)

    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u6574\u6570\u6570\u7ec4 nums\uff0c\u5176\u4e2d n > 1\uff0c\u8fd4\u56de\u8f93\u51fa\u6570\u7ec4 output \uff0c\u5176\u4e2d output[i] \u7b49\u4e8e nums \u4e2d\u9664 nums[i] \u4e4b\u5916\u5176\u4f59\u5404\u5143\u7d20\u7684\u4e58\u79ef\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: [1,2,3,4]\n\u8f93\u51fa: [24,12,8,6]
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a\u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u6570\u7ec4\u4e4b\u4e2d\u4efb\u610f\u5143\u7d20\u7684\u5168\u90e8\u524d\u7f00\u5143\u7d20\u548c\u540e\u7f00\uff08\u751a\u81f3\u662f\u6574\u4e2a\u6570\u7ec4\uff09\u7684\u4e58\u79ef\u90fd\u5728 32 \u4f4d\u6574\u6570\u8303\u56f4\u5185\u3002

    \n\n

    \u8bf4\u660e: \u8bf7\u4e0d\u8981\u4f7f\u7528\u9664\u6cd5\uff0c\u4e14\u5728 O(n) \u65f6\u95f4\u590d\u6742\u5ea6\u5185\u5b8c\u6210\u6b64\u9898\u3002

    \n\n

    \u8fdb\u9636\uff1a
    \n\u4f60\u53ef\u4ee5\u5728\u5e38\u6570\u7a7a\u95f4\u590d\u6742\u5ea6\u5185\u5b8c\u6210\u8fd9\u4e2a\u9898\u76ee\u5417\uff1f\uff08 \u51fa\u4e8e\u5bf9\u7a7a\u95f4\u590d\u6742\u5ea6\u5206\u6790\u7684\u76ee\u7684\uff0c\u8f93\u51fa\u6570\u7ec4\u4e0d\u88ab\u89c6\u4e3a\u989d\u5916\u7a7a\u95f4\u3002\uff09

    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector productExceptSelf(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] productExceptSelf(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def productExceptSelf(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def productExceptSelf(self, nums: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* productExceptSelf(int* nums, int numsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] ProductExceptSelf(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar productExceptSelf = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer[]}\ndef product_except_self(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func productExceptSelf(_ nums: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func productExceptSelf(nums []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def productExceptSelf(nums: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun productExceptSelf(nums: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn product_except_self(nums: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer[]\n */\n function productExceptSelf($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function productExceptSelf(nums: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (product-except-self nums)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0238](https://leetcode-cn.com/problems/product-of-array-except-self)", "[\u9664\u81ea\u8eab\u4ee5\u5916\u6570\u7ec4\u7684\u4e58\u79ef](/solution/0200-0299/0238.Product%20of%20Array%20Except%20Self/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0238](https://leetcode.com/problems/product-of-array-except-self)", "[Product of Array Except Self](/solution/0200-0299/0238.Product%20of%20Array%20Except%20Self/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0237", "frontend_question_id": "0237", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/delete-node-in-a-linked-list", "url_en": "https://leetcode.com/problems/delete-node-in-a-linked-list", "relative_path_cn": "/solution/0200-0299/0237.Delete%20Node%20in%20a%20Linked%20List/README.md", "relative_path_en": "/solution/0200-0299/0237.Delete%20Node%20in%20a%20Linked%20List/README_EN.md", "title_cn": "\u5220\u9664\u94fe\u8868\u4e2d\u7684\u8282\u70b9", "title_en": "Delete Node in a Linked List", "question_title_slug": "delete-node-in-a-linked-list", "content_en": "

    Write a function to delete a node in a singly-linked list. You will not be given access to the head of the list, instead you will be given access to the node to be deleted directly.

    \n\n

    It is guaranteed that the node to be deleted is not a tail node in the list.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: head = [4,5,1,9], node = 5\nOutput: [4,1,9]\nExplanation: You are given the second node with value 5, the linked list should become 4 -> 1 -> 9 after calling your function.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: head = [4,5,1,9], node = 1\nOutput: [4,5,9]\nExplanation: You are given the third node with value 1, the linked list should become 4 -> 5 -> 9 after calling your function.\n
    \n\n

    Example 3:

    \n\n
    \nInput: head = [1,2,3,4], node = 3\nOutput: [1,2,4]\n
    \n\n

    Example 4:

    \n\n
    \nInput: head = [0,1], node = 0\nOutput: [1]\n
    \n\n

    Example 5:

    \n\n
    \nInput: head = [-3,5,-99], node = -3\nOutput: [5,-99]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of the nodes in the given list is in the range [2, 1000].
    • \n\t
    • -1000 <= Node.val <= 1000
    • \n\t
    • The value of each node in the list is unique.
    • \n\t
    • The node to be deleted is in the list and is not a tail node
    • \n
    \n", "content_cn": "

    \u8bf7\u7f16\u5199\u4e00\u4e2a\u51fd\u6570\uff0c\u4f7f\u5176\u53ef\u4ee5\u5220\u9664\u67d0\u4e2a\u94fe\u8868\u4e2d\u7ed9\u5b9a\u7684\uff08\u975e\u672b\u5c3e\uff09\u8282\u70b9\u3002\u4f20\u5165\u51fd\u6570\u7684\u552f\u4e00\u53c2\u6570\u4e3a \u8981\u88ab\u5220\u9664\u7684\u8282\u70b9 \u3002

    \n\n

     

    \n\n

    \u73b0\u6709\u4e00\u4e2a\u94fe\u8868 -- head = [4,5,1,9]\uff0c\u5b83\u53ef\u4ee5\u8868\u793a\u4e3a:

    \n\n

    \"\"

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1ahead = [4,5,1,9], node = 5\n\u8f93\u51fa\uff1a[4,1,9]\n\u89e3\u91ca\uff1a\u7ed9\u5b9a\u4f60\u94fe\u8868\u4e2d\u503c\u4e3a 5 \u7684\u7b2c\u4e8c\u4e2a\u8282\u70b9\uff0c\u90a3\u4e48\u5728\u8c03\u7528\u4e86\u4f60\u7684\u51fd\u6570\u4e4b\u540e\uff0c\u8be5\u94fe\u8868\u5e94\u53d8\u4e3a 4 -> 1 -> 9.\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1ahead = [4,5,1,9], node = 1\n\u8f93\u51fa\uff1a[4,5,9]\n\u89e3\u91ca\uff1a\u7ed9\u5b9a\u4f60\u94fe\u8868\u4e2d\u503c\u4e3a 1 \u7684\u7b2c\u4e09\u4e2a\u8282\u70b9\uff0c\u90a3\u4e48\u5728\u8c03\u7528\u4e86\u4f60\u7684\u51fd\u6570\u4e4b\u540e\uff0c\u8be5\u94fe\u8868\u5e94\u53d8\u4e3a 4 -> 5 -> 9.\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u94fe\u8868\u81f3\u5c11\u5305\u542b\u4e24\u4e2a\u8282\u70b9\u3002
    • \n\t
    • \u94fe\u8868\u4e2d\u6240\u6709\u8282\u70b9\u7684\u503c\u90fd\u662f\u552f\u4e00\u7684\u3002
    • \n\t
    • \u7ed9\u5b9a\u7684\u8282\u70b9\u4e3a\u975e\u672b\u5c3e\u8282\u70b9\u5e76\u4e14\u4e00\u5b9a\u662f\u94fe\u8868\u4e2d\u7684\u4e00\u4e2a\u6709\u6548\u8282\u70b9\u3002
    • \n\t
    • \u4e0d\u8981\u4ece\u4f60\u7684\u51fd\u6570\u4e2d\u8fd4\u56de\u4efb\u4f55\u7ed3\u679c\u3002
    • \n
    \n", "tags_en": ["Linked List"], "tags_cn": ["\u94fe\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\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 void deleteNode(ListNode* node) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode(int x) { val = x; }\n * }\n */\nclass Solution {\n public void deleteNode(ListNode node) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.next = None\n\nclass Solution(object):\n def deleteNode(self, node):\n \"\"\"\n :type node: ListNode\n :rtype: void Do not return anything, modify node in-place instead.\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, x):\n# self.val = x\n# self.next = None\n\nclass Solution:\n def deleteNode(self, node):\n \"\"\"\n :type node: ListNode\n :rtype: void Do not return anything, modify node in-place instead.\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\nvoid deleteNode(struct ListNode* node) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int x) { val = x; }\n * }\n */\npublic class Solution {\n public void DeleteNode(ListNode node) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val) {\n * this.val = val;\n * this.next = null;\n * }\n */\n/**\n * @param {ListNode} node\n * @return {void} Do not return anything, modify node in-place instead.\n */\nvar deleteNode = function(node) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val)\n# @val = val\n# @next = nil\n# end\n# end\n\n# @param {ListNode} node\n# @return {Void} Do not return anything, modify node in-place instead.\ndef delete_node(node)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.next = nil\n * }\n * }\n */\n\nclass Solution {\n func deleteNode(_ node: ListNode?) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc deleteNode(node *ListNode) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(var _x: Int = 0) {\n * var next: ListNode = null\n * var x: Int = _x\n * }\n */\n\nobject Solution {\n def deleteNode(node: ListNode): Unit = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\n\nclass Solution {\n fun deleteNode(node: ListNode?) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val) { $this->val = $val; }\n * }\n */\n\nclass Solution {\n /**\n * @param ListNode $node\n * @return \n */\n function deleteNode($node) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\n/**\n Do not return anything, modify it in-place instead.\n */\nfunction deleteNode(root: ListNode | null): void {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0237](https://leetcode-cn.com/problems/delete-node-in-a-linked-list)", "[\u5220\u9664\u94fe\u8868\u4e2d\u7684\u8282\u70b9](/solution/0200-0299/0237.Delete%20Node%20in%20a%20Linked%20List/README.md)", "`\u94fe\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0237](https://leetcode.com/problems/delete-node-in-a-linked-list)", "[Delete Node in a Linked List](/solution/0200-0299/0237.Delete%20Node%20in%20a%20Linked%20List/README_EN.md)", "`Linked List`", "Easy", ""]}, {"question_id": "0236", "frontend_question_id": "0236", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-tree", "url_en": "https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree", "relative_path_cn": "/solution/0200-0299/0236.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree/README.md", "relative_path_en": "/solution/0200-0299/0236.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148", "title_en": "Lowest Common Ancestor of a Binary Tree", "question_title_slug": "lowest-common-ancestor-of-a-binary-tree", "content_en": "

    Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.

    \n\n

    According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes p and q as the lowest node in T that has both p and q as descendants (where we allow a node to be a descendant of itself).”

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 1\nOutput: 3\nExplanation: The LCA of nodes 5 and 1 is 3.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 4\nOutput: 5\nExplanation: The LCA of nodes 5 and 4 is 5, since a node can be a descendant of itself according to the LCA definition.\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = [1,2], p = 1, q = 2\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [2, 105].
    • \n\t
    • -109 <= Node.val <= 109
    • \n\t
    • All Node.val are unique.
    • \n\t
    • p != q
    • \n\t
    • p and q will exist in the tree.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811, \u627e\u5230\u8be5\u6811\u4e2d\u4e24\u4e2a\u6307\u5b9a\u8282\u70b9\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148\u3002

    \n\n

    \u767e\u5ea6\u767e\u79d1\u4e2d\u6700\u8fd1\u516c\u5171\u7956\u5148\u7684\u5b9a\u4e49\u4e3a\uff1a\u201c\u5bf9\u4e8e\u6709\u6839\u6811 T \u7684\u4e24\u4e2a\u8282\u70b9 p\u3001q\uff0c\u6700\u8fd1\u516c\u5171\u7956\u5148\u8868\u793a\u4e3a\u4e00\u4e2a\u8282\u70b9 x\uff0c\u6ee1\u8db3 x \u662f p\u3001q \u7684\u7956\u5148\u4e14 x \u7684\u6df1\u5ea6\u5c3d\u53ef\u80fd\u5927\uff08\u4e00\u4e2a\u8282\u70b9\u4e5f\u53ef\u4ee5\u662f\u5b83\u81ea\u5df1\u7684\u7956\u5148\uff09\u3002\u201d

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 1\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u8282\u70b9 5 \u548c\u8282\u70b9 1 \u7684\u6700\u8fd1\u516c\u5171\u7956\u5148\u662f\u8282\u70b9 3 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 4\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u8282\u70b9 5 \u548c\u8282\u70b9 4 \u7684\u6700\u8fd1\u516c\u5171\u7956\u5148\u662f\u8282\u70b9 5 \u3002\u56e0\u4e3a\u6839\u636e\u5b9a\u4e49\u6700\u8fd1\u516c\u5171\u7956\u5148\u8282\u70b9\u53ef\u4ee5\u4e3a\u8282\u70b9\u672c\u8eab\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [1,2], p = 1, q = 2\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u6570\u76ee\u5728\u8303\u56f4 [2, 105] \u5185\u3002
    • \n\t
    • -109 <= Node.val <= 109
    • \n\t
    • \u6240\u6709 Node.val \u4e92\u4e0d\u76f8\u540c \u3002
    • \n\t
    • p != q
    • \n\t
    • p \u548c q \u5747\u5b58\u5728\u4e8e\u7ed9\u5b9a\u7684\u4e8c\u53c9\u6811\u4e2d\u3002
    • \n
    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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 */\nclass Solution {\npublic:\n TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode(int x) { val = x; }\n * }\n */\nclass Solution {\n public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution(object):\n def lowestCommonAncestor(self, root, p, q):\n \"\"\"\n :type root: TreeNode\n :type p: TreeNode\n :type q: TreeNode\n :rtype: TreeNode\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution:\n def lowestCommonAncestor(self, root: 'TreeNode', p: 'TreeNode', q: 'TreeNode') -> 'TreeNode':\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\nstruct TreeNode* lowestCommonAncestor(struct TreeNode* root, struct TreeNode* p, struct TreeNode* q) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int x) { val = x; }\n * }\n */\npublic class Solution {\n public TreeNode LowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val) {\n * this.val = val;\n * this.left = this.right = null;\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {TreeNode} p\n * @param {TreeNode} q\n * @return {TreeNode}\n */\nvar lowestCommonAncestor = function(root, p, q) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val)\n# @val = val\n# @left, @right = nil, nil\n# end\n# end\n\n# @param {TreeNode} root\n# @param {TreeNode} p\n# @param {TreeNode} q\n# @return {TreeNode}\ndef lowest_common_ancestor(root, p, q)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.left = nil\n * self.right = nil\n * }\n * }\n */\n\nclass Solution {\n func lowestCommonAncestor(_ root: TreeNode?, _ p: TreeNode?, _ q: TreeNode?) -> TreeNode? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\n func lowestCommonAncestor(root, p, q *TreeNode) *TreeNode {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(var _value: Int) {\n * var value: Int = _value\n * var left: TreeNode = null\n * var right: TreeNode = null\n * }\n */\n\nobject Solution {\n def lowestCommonAncestor(root: TreeNode, p: TreeNode, q: TreeNode): TreeNode = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int = 0) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\n\nclass Solution {\n fun lowestCommonAncestor(root: TreeNode?, p: TreeNode?, q: TreeNode?): TreeNode? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n// \n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn lowest_common_ancestor(root: Option>>, p: Option>>, q: Option>>) -> Option>> {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($value) { $this->val = $value; }\n * }\n */\n\nclass Solution {\n /**\n * @param TreeNode $root\n * @param TreeNode $p\n * @param TreeNode $q\n * @return TreeNode\n */\n function lowestCommonAncestor($root, $p, $q) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction lowestCommonAncestor(root: TreeNode | null, p: TreeNode | null, q: TreeNode | null): TreeNode | null {\n\t\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0236](https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-tree)", "[\u4e8c\u53c9\u6811\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148](/solution/0200-0299/0236.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree/README.md)", "`\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0236](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree)", "[Lowest Common Ancestor of a Binary Tree](/solution/0200-0299/0236.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree/README_EN.md)", "`Tree`", "Medium", ""]}, {"question_id": "0235", "frontend_question_id": "0235", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-search-tree", "url_en": "https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree", "relative_path_cn": "/solution/0200-0299/0235.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Search%20Tree/README.md", "relative_path_en": "/solution/0200-0299/0235.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Search%20Tree/README_EN.md", "title_cn": "\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148", "title_en": "Lowest Common Ancestor of a Binary Search Tree", "question_title_slug": "lowest-common-ancestor-of-a-binary-search-tree", "content_en": "

    Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.

    \n\n

    According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes p and q as the lowest node in T that has both p and q as descendants (where we allow a node to be a descendant of itself).”

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [6,2,8,0,4,7,9,null,null,3,5], p = 2, q = 8\nOutput: 6\nExplanation: The LCA of nodes 2 and 8 is 6.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [6,2,8,0,4,7,9,null,null,3,5], p = 2, q = 4\nOutput: 2\nExplanation: The LCA of nodes 2 and 4 is 2, since a node can be a descendant of itself according to the LCA definition.\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = [2,1], p = 2, q = 1\nOutput: 2\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [2, 105].
    • \n\t
    • -109 <= Node.val <= 109
    • \n\t
    • All Node.val are unique.
    • \n\t
    • p != q
    • \n\t
    • p and q will exist in the BST.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u641c\u7d22\u6811, \u627e\u5230\u8be5\u6811\u4e2d\u4e24\u4e2a\u6307\u5b9a\u8282\u70b9\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148\u3002

    \n\n

    \u767e\u5ea6\u767e\u79d1\u4e2d\u6700\u8fd1\u516c\u5171\u7956\u5148\u7684\u5b9a\u4e49\u4e3a\uff1a“\u5bf9\u4e8e\u6709\u6839\u6811 T \u7684\u4e24\u4e2a\u7ed3\u70b9 p\u3001q\uff0c\u6700\u8fd1\u516c\u5171\u7956\u5148\u8868\u793a\u4e3a\u4e00\u4e2a\u7ed3\u70b9 x\uff0c\u6ee1\u8db3 x \u662f p\u3001q \u7684\u7956\u5148\u4e14 x \u7684\u6df1\u5ea6\u5c3d\u53ef\u80fd\u5927\uff08\u4e00\u4e2a\u8282\u70b9\u4e5f\u53ef\u4ee5\u662f\u5b83\u81ea\u5df1\u7684\u7956\u5148\uff09\u3002”

    \n\n

    \u4f8b\u5982\uff0c\u7ed9\u5b9a\u5982\u4e0b\u4e8c\u53c9\u641c\u7d22\u6811:  root = [6,2,8,0,4,7,9,null,null,3,5]

    \n\n

    \"\"

    \n\n

     

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: root = [6,2,8,0,4,7,9,null,null,3,5], p = 2, q = 8\n\u8f93\u51fa: 6 \n\u89e3\u91ca: \u8282\u70b9 2 \u548c\u8282\u70b9 8 \u7684\u6700\u8fd1\u516c\u5171\u7956\u5148\u662f 6\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: root = [6,2,8,0,4,7,9,null,null,3,5], p = 2, q = 4\n\u8f93\u51fa: 2\n\u89e3\u91ca: \u8282\u70b9 2 \u548c\u8282\u70b9 4 \u7684\u6700\u8fd1\u516c\u5171\u7956\u5148\u662f 2, \u56e0\u4e3a\u6839\u636e\u5b9a\u4e49\u6700\u8fd1\u516c\u5171\u7956\u5148\u8282\u70b9\u53ef\u4ee5\u4e3a\u8282\u70b9\u672c\u8eab\u3002
    \n\n

     

    \n\n

    \u8bf4\u660e:

    \n\n
      \n\t
    • \u6240\u6709\u8282\u70b9\u7684\u503c\u90fd\u662f\u552f\u4e00\u7684\u3002
    • \n\t
    • p\u3001q \u4e3a\u4e0d\u540c\u8282\u70b9\u4e14\u5747\u5b58\u5728\u4e8e\u7ed9\u5b9a\u7684\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u3002
    • \n
    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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\nclass Solution {\npublic:\n TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode(int x) { val = x; }\n * }\n */\n\nclass Solution {\n public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution(object):\n def lowestCommonAncestor(self, root, p, q):\n \"\"\"\n :type root: TreeNode\n :type p: TreeNode\n :type q: TreeNode\n :rtype: TreeNode\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution:\n def lowestCommonAncestor(self, root: 'TreeNode', p: 'TreeNode', q: 'TreeNode') -> 'TreeNode':\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\nstruct TreeNode* lowestCommonAncestor(struct TreeNode* root, struct TreeNode* p, struct TreeNode* q) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int x) { val = x; }\n * }\n */\n\npublic class Solution {\n public TreeNode LowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val) {\n * this.val = val;\n * this.left = this.right = null;\n * }\n */\n\n/**\n * @param {TreeNode} root\n * @param {TreeNode} p\n * @param {TreeNode} q\n * @return {TreeNode}\n */\nvar lowestCommonAncestor = function(root, p, q) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val)\n# @val = val\n# @left, @right = nil, nil\n# end\n# end\n\n# @param {TreeNode} root\n# @param {TreeNode} p\n# @param {TreeNode} q\n# @return {TreeNode}\ndef lowest_common_ancestor(root, p, q)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.left = nil\n * self.right = nil\n * }\n * }\n */\n\nclass Solution {\n func lowestCommonAncestor(_ root: TreeNode?, _ p: TreeNode?, _ q: TreeNode?) -> TreeNode? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\n\nfunc lowestCommonAncestor(root, p, q *TreeNode) *TreeNode {\n\t\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(var _value: Int) {\n * var value: Int = _value\n * var left: TreeNode = null\n * var right: TreeNode = null\n * }\n */\n\nobject Solution {\n def lowestCommonAncestor(root: TreeNode, p: TreeNode, q: TreeNode): TreeNode = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int = 0) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\n\nclass Solution {\n fun lowestCommonAncestor(root: TreeNode?, p: TreeNode?, q: TreeNode?): TreeNode? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n// \n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn lowest_common_ancestor(root: Option>>, p: Option>>, q: Option>>) -> Option>> {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($value) { $this->val = $value; }\n * }\n */\n\nclass Solution {\n /**\n * @param TreeNode $root\n * @param TreeNode $p\n * @param TreeNode $q\n * @return TreeNode\n */\n function lowestCommonAncestor($root, $p, $q) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction lowestCommonAncestor(root: TreeNode | null, p: TreeNode | null, q: TreeNode | null): TreeNode | null {\n\t\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0235](https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-search-tree)", "[\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148](/solution/0200-0299/0235.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Search%20Tree/README.md)", "`\u6811`", "\u7b80\u5355", ""], "md_table_row_en": ["[0235](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree)", "[Lowest Common Ancestor of a Binary Search Tree](/solution/0200-0299/0235.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Search%20Tree/README_EN.md)", "`Tree`", "Easy", ""]}, {"question_id": "0234", "frontend_question_id": "0234", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/palindrome-linked-list", "url_en": "https://leetcode.com/problems/palindrome-linked-list", "relative_path_cn": "/solution/0200-0299/0234.Palindrome%20Linked%20List/README.md", "relative_path_en": "/solution/0200-0299/0234.Palindrome%20Linked%20List/README_EN.md", "title_cn": "\u56de\u6587\u94fe\u8868", "title_en": "Palindrome Linked List", "question_title_slug": "palindrome-linked-list", "content_en": "

    Given the head of a singly linked list, return true if it is a palindrome.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: head = [1,2,2,1]\nOutput: true\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: head = [1,2]\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the list is in the range [1, 105].
    • \n\t
    • 0 <= Node.val <= 9
    • \n
    \n\n

     

    \nFollow up: Could you do it in O(n) time and O(1) space?", "content_cn": "

    \u8bf7\u5224\u65ad\u4e00\u4e2a\u94fe\u8868\u662f\u5426\u4e3a\u56de\u6587\u94fe\u8868\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: 1->2\n\u8f93\u51fa: false
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: 1->2->2->1\n\u8f93\u51fa: true\n
    \n\n

    \u8fdb\u9636\uff1a
    \n\u4f60\u80fd\u5426\u7528 O(n) \u65f6\u95f4\u590d\u6742\u5ea6\u548c O(1) \u7a7a\u95f4\u590d\u6742\u5ea6\u89e3\u51b3\u6b64\u9898\uff1f

    \n", "tags_en": ["Linked List", "Two Pointers"], "tags_cn": ["\u94fe\u8868", "\u53cc\u6307\u9488"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n bool isPalindrome(ListNode* head) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public boolean isPalindrome(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def isPalindrome(self, head):\n \"\"\"\n :type head: ListNode\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def isPalindrome(self, head: ListNode) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nbool isPalindrome(struct ListNode* head){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public bool IsPalindrome(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} head\n * @return {boolean}\n */\nvar isPalindrome = function(head) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode} head\n# @return {Boolean}\ndef is_palindrome(head)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func isPalindrome(_ head: ListNode?) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc isPalindrome(head *ListNode) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def isPalindrome(head: ListNode): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun isPalindrome(head: ListNode?): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn is_palindrome(head: Option>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @return Boolean\n */\n function isPalindrome($head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction isPalindrome(head: ListNode | null): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (is-palindrome head)\n (-> (or/c list-node? #f) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0234](https://leetcode-cn.com/problems/palindrome-linked-list)", "[\u56de\u6587\u94fe\u8868](/solution/0200-0299/0234.Palindrome%20Linked%20List/README.md)", "`\u94fe\u8868`,`\u53cc\u6307\u9488`", "\u7b80\u5355", ""], "md_table_row_en": ["[0234](https://leetcode.com/problems/palindrome-linked-list)", "[Palindrome Linked List](/solution/0200-0299/0234.Palindrome%20Linked%20List/README_EN.md)", "`Linked List`,`Two Pointers`", "Easy", ""]}, {"question_id": "0233", "frontend_question_id": "0233", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-digit-one", "url_en": "https://leetcode.com/problems/number-of-digit-one", "relative_path_cn": "/solution/0200-0299/0233.Number%20of%20Digit%20One/README.md", "relative_path_en": "/solution/0200-0299/0233.Number%20of%20Digit%20One/README_EN.md", "title_cn": "\u6570\u5b57 1 \u7684\u4e2a\u6570", "title_en": "Number of Digit One", "question_title_slug": "number-of-digit-one", "content_en": "

    Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 13\nOutput: 6\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 0\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= n <= 2 * 109
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570 n\uff0c\u8ba1\u7b97\u6240\u6709\u5c0f\u4e8e\u7b49\u4e8e n \u7684\u975e\u8d1f\u6574\u6570\u4e2d\u6570\u5b57 1 \u51fa\u73b0\u7684\u4e2a\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 13\n\u8f93\u51fa\uff1a6\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 0\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= n <= 2 * 109
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countDigitOne(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countDigitOne(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countDigitOne(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countDigitOne(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countDigitOne(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountDigitOne(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar countDigitOne = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef count_digit_one(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countDigitOne(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countDigitOne(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countDigitOne(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countDigitOne(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_digit_one(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function countDigitOne($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countDigitOne(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-digit-one n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0233](https://leetcode-cn.com/problems/number-of-digit-one)", "[\u6570\u5b57 1 \u7684\u4e2a\u6570](/solution/0200-0299/0233.Number%20of%20Digit%20One/README.md)", "`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[0233](https://leetcode.com/problems/number-of-digit-one)", "[Number of Digit One](/solution/0200-0299/0233.Number%20of%20Digit%20One/README_EN.md)", "`Math`", "Hard", ""]}, {"question_id": "0232", "frontend_question_id": "0232", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/implement-queue-using-stacks", "url_en": "https://leetcode.com/problems/implement-queue-using-stacks", "relative_path_cn": "/solution/0200-0299/0232.Implement%20Queue%20using%20Stacks/README.md", "relative_path_en": "/solution/0200-0299/0232.Implement%20Queue%20using%20Stacks/README_EN.md", "title_cn": "\u7528\u6808\u5b9e\u73b0\u961f\u5217", "title_en": "Implement Queue using Stacks", "question_title_slug": "implement-queue-using-stacks", "content_en": "

    Implement a first in first out (FIFO) queue using only two stacks. The implemented queue should support all the functions of a normal queue (push, peek, pop, and empty).

    \n\n

    Implement the MyQueue class:

    \n\n
      \n\t
    • void push(int x) Pushes element x to the back of the queue.
    • \n\t
    • int pop() Removes the element from the front of the queue and returns it.
    • \n\t
    • int peek() Returns the element at the front of the queue.
    • \n\t
    • boolean empty() Returns true if the queue is empty, false otherwise.
    • \n
    \n\n

    Notes:

    \n\n
      \n\t
    • You must use only standard operations of a stack, which means only push to top, peek/pop from top, size, and is empty operations are valid.
    • \n\t
    • Depending on your language, the stack may not be supported natively. You may simulate a stack using a list or deque (double-ended queue) as long as you use only a stack's standard operations.
    • \n
    \n\n

    Follow-up: Can you implement the queue such that each operation is amortized O(1) time complexity? In other words, performing n operations will take overall O(n) time even if one of those operations may take longer.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["MyQueue", "push", "push", "peek", "pop", "empty"]\n[[], [1], [2], [], [], []]\nOutput\n[null, null, null, 1, 1, false]\n\nExplanation\nMyQueue myQueue = new MyQueue();\nmyQueue.push(1); // queue is: [1]\nmyQueue.push(2); // queue is: [1, 2] (leftmost is front of the queue)\nmyQueue.peek(); // return 1\nmyQueue.pop(); // return 1, queue is [2]\nmyQueue.empty(); // return false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= x <= 9
    • \n\t
    • At most 100 calls will be made to push, pop, peek, and empty.
    • \n\t
    • All the calls to pop and peek are valid.
    • \n
    \n", "content_cn": "

    \u8bf7\u4f60\u4ec5\u4f7f\u7528\u4e24\u4e2a\u6808\u5b9e\u73b0\u5148\u5165\u5148\u51fa\u961f\u5217\u3002\u961f\u5217\u5e94\u5f53\u652f\u6301\u4e00\u822c\u961f\u5217\u652f\u6301\u7684\u6240\u6709\u64cd\u4f5c\uff08push\u3001pop\u3001peek\u3001empty\uff09\uff1a

    \n\n

    \u5b9e\u73b0 MyQueue \u7c7b\uff1a

    \n\n
      \n\t
    • void push(int x) \u5c06\u5143\u7d20 x \u63a8\u5230\u961f\u5217\u7684\u672b\u5c3e
    • \n\t
    • int pop() \u4ece\u961f\u5217\u7684\u5f00\u5934\u79fb\u9664\u5e76\u8fd4\u56de\u5143\u7d20
    • \n\t
    • int peek() \u8fd4\u56de\u961f\u5217\u5f00\u5934\u7684\u5143\u7d20
    • \n\t
    • boolean empty() \u5982\u679c\u961f\u5217\u4e3a\u7a7a\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false
    • \n
    \n\n

    \u00a0

    \n\n

    \u8bf4\u660e\uff1a

    \n\n
      \n\t
    • \u4f60\u53ea\u80fd\u4f7f\u7528\u6807\u51c6\u7684\u6808\u64cd\u4f5c \u2014\u2014 \u4e5f\u5c31\u662f\u53ea\u6709\u00a0push to top,\u00a0peek/pop from top,\u00a0size, \u548c\u00a0is empty\u00a0\u64cd\u4f5c\u662f\u5408\u6cd5\u7684\u3002
    • \n\t
    • \u4f60\u6240\u4f7f\u7528\u7684\u8bed\u8a00\u4e5f\u8bb8\u4e0d\u652f\u6301\u6808\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528 list \u6216\u8005 deque\uff08\u53cc\u7aef\u961f\u5217\uff09\u6765\u6a21\u62df\u4e00\u4e2a\u6808\uff0c\u53ea\u8981\u662f\u6807\u51c6\u7684\u6808\u64cd\u4f5c\u5373\u53ef\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u4f60\u80fd\u5426\u5b9e\u73b0\u6bcf\u4e2a\u64cd\u4f5c\u5747\u644a\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(1) \u7684\u961f\u5217\uff1f\u6362\u53e5\u8bdd\u8bf4\uff0c\u6267\u884c n \u4e2a\u64cd\u4f5c\u7684\u603b\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n) \uff0c\u5373\u4f7f\u5176\u4e2d\u4e00\u4e2a\u64cd\u4f5c\u53ef\u80fd\u82b1\u8d39\u8f83\u957f\u65f6\u95f4\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\n[\"MyQueue\", \"push\", \"push\", \"peek\", \"pop\", \"empty\"]\n[[], [1], [2], [], [], []]\n\u8f93\u51fa\uff1a\n[null, null, null, 1, 1, false]\n\n\u89e3\u91ca\uff1a\nMyQueue myQueue = new MyQueue();\nmyQueue.push(1); // queue is: [1]\nmyQueue.push(2); // queue is: [1, 2] (leftmost is front of the queue)\nmyQueue.peek(); // return 1\nmyQueue.pop(); // return 1, queue is [2]\nmyQueue.empty(); // return false\n
    \n\n
      \n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= x <= 9
    • \n\t
    • \u6700\u591a\u8c03\u7528 100 \u6b21 push\u3001pop\u3001peek \u548c empty
    • \n\t
    • \u5047\u8bbe\u6240\u6709\u64cd\u4f5c\u90fd\u662f\u6709\u6548\u7684 \uff08\u4f8b\u5982\uff0c\u4e00\u4e2a\u7a7a\u7684\u961f\u5217\u4e0d\u4f1a\u8c03\u7528 pop \u6216\u8005 peek \u64cd\u4f5c\uff09
    • \n
    \n", "tags_en": ["Stack", "Design"], "tags_cn": ["\u6808", "\u8bbe\u8ba1"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class MyQueue {\npublic:\n /** Initialize your data structure here. */\n MyQueue() {\n\n }\n \n /** Push element x to the back of queue. */\n void push(int x) {\n\n }\n \n /** Removes the element from in front of queue and returns that element. */\n int pop() {\n\n }\n \n /** Get the front element. */\n int peek() {\n\n }\n \n /** Returns whether the queue is empty. */\n bool empty() {\n\n }\n};\n\n/**\n * Your MyQueue object will be instantiated and called as such:\n * MyQueue* obj = new MyQueue();\n * obj->push(x);\n * int param_2 = obj->pop();\n * int param_3 = obj->peek();\n * bool param_4 = obj->empty();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class MyQueue {\n\n /** Initialize your data structure here. */\n public MyQueue() {\n\n }\n \n /** Push element x to the back of queue. */\n public void push(int x) {\n\n }\n \n /** Removes the element from in front of queue and returns that element. */\n public int pop() {\n\n }\n \n /** Get the front element. */\n public int peek() {\n\n }\n \n /** Returns whether the queue is empty. */\n public boolean empty() {\n\n }\n}\n\n/**\n * Your MyQueue object will be instantiated and called as such:\n * MyQueue obj = new MyQueue();\n * obj.push(x);\n * int param_2 = obj.pop();\n * int param_3 = obj.peek();\n * boolean param_4 = obj.empty();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class MyQueue(object):\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def push(self, x):\n \"\"\"\n Push element x to the back of queue.\n :type x: int\n :rtype: None\n \"\"\"\n\n\n def pop(self):\n \"\"\"\n Removes the element from in front of queue and returns that element.\n :rtype: int\n \"\"\"\n\n\n def peek(self):\n \"\"\"\n Get the front element.\n :rtype: int\n \"\"\"\n\n\n def empty(self):\n \"\"\"\n Returns whether the queue is empty.\n :rtype: bool\n \"\"\"\n\n\n\n# Your MyQueue object will be instantiated and called as such:\n# obj = MyQueue()\n# obj.push(x)\n# param_2 = obj.pop()\n# param_3 = obj.peek()\n# param_4 = obj.empty()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class MyQueue:\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def push(self, x: int) -> None:\n \"\"\"\n Push element x to the back of queue.\n \"\"\"\n\n\n def pop(self) -> int:\n \"\"\"\n Removes the element from in front of queue and returns that element.\n \"\"\"\n\n\n def peek(self) -> int:\n \"\"\"\n Get the front element.\n \"\"\"\n\n\n def empty(self) -> bool:\n \"\"\"\n Returns whether the queue is empty.\n \"\"\"\n\n\n\n# Your MyQueue object will be instantiated and called as such:\n# obj = MyQueue()\n# obj.push(x)\n# param_2 = obj.pop()\n# param_3 = obj.peek()\n# param_4 = obj.empty()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} MyQueue;\n\n/** Initialize your data structure here. */\n\nMyQueue* myQueueCreate() {\n\n}\n\n/** Push element x to the back of queue. */\nvoid myQueuePush(MyQueue* obj, int x) {\n\n}\n\n/** Removes the element from in front of queue and returns that element. */\nint myQueuePop(MyQueue* obj) {\n\n}\n\n/** Get the front element. */\nint myQueuePeek(MyQueue* obj) {\n\n}\n\n/** Returns whether the queue is empty. */\nbool myQueueEmpty(MyQueue* obj) {\n\n}\n\nvoid myQueueFree(MyQueue* obj) {\n\n}\n\n/**\n * Your MyQueue struct will be instantiated and called as such:\n * MyQueue* obj = myQueueCreate();\n * myQueuePush(obj, x);\n \n * int param_2 = myQueuePop(obj);\n \n * int param_3 = myQueuePeek(obj);\n \n * bool param_4 = myQueueEmpty(obj);\n \n * myQueueFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class MyQueue {\n\n /** Initialize your data structure here. */\n public MyQueue() {\n\n }\n \n /** Push element x to the back of queue. */\n public void Push(int x) {\n\n }\n \n /** Removes the element from in front of queue and returns that element. */\n public int Pop() {\n\n }\n \n /** Get the front element. */\n public int Peek() {\n\n }\n \n /** Returns whether the queue is empty. */\n public bool Empty() {\n\n }\n}\n\n/**\n * Your MyQueue object will be instantiated and called as such:\n * MyQueue obj = new MyQueue();\n * obj.Push(x);\n * int param_2 = obj.Pop();\n * int param_3 = obj.Peek();\n * bool param_4 = obj.Empty();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Initialize your data structure here.\n */\nvar MyQueue = function() {\n\n};\n\n/**\n * Push element x to the back of queue. \n * @param {number} x\n * @return {void}\n */\nMyQueue.prototype.push = function(x) {\n\n};\n\n/**\n * Removes the element from in front of queue and returns that element.\n * @return {number}\n */\nMyQueue.prototype.pop = function() {\n\n};\n\n/**\n * Get the front element.\n * @return {number}\n */\nMyQueue.prototype.peek = function() {\n\n};\n\n/**\n * Returns whether the queue is empty.\n * @return {boolean}\n */\nMyQueue.prototype.empty = function() {\n\n};\n\n/**\n * Your MyQueue object will be instantiated and called as such:\n * var obj = new MyQueue()\n * obj.push(x)\n * var param_2 = obj.pop()\n * var param_3 = obj.peek()\n * var param_4 = obj.empty()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class MyQueue\n\n=begin\n Initialize your data structure here.\n=end\n def initialize()\n\n end\n\n\n=begin\n Push element x to the back of queue.\n :type x: Integer\n :rtype: Void\n=end\n def push(x)\n\n end\n\n\n=begin\n Removes the element from in front of queue and returns that element.\n :rtype: Integer\n=end\n def pop()\n\n end\n\n\n=begin\n Get the front element.\n :rtype: Integer\n=end\n def peek()\n\n end\n\n\n=begin\n Returns whether the queue is empty.\n :rtype: Boolean\n=end\n def empty()\n\n end\n\n\nend\n\n# Your MyQueue object will be instantiated and called as such:\n# obj = MyQueue.new()\n# obj.push(x)\n# param_2 = obj.pop()\n# param_3 = obj.peek()\n# param_4 = obj.empty()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass MyQueue {\n\n /** Initialize your data structure here. */\n init() {\n\n }\n \n /** Push element x to the back of queue. */\n func push(_ x: Int) {\n\n }\n \n /** Removes the element from in front of queue and returns that element. */\n func pop() -> Int {\n\n }\n \n /** Get the front element. */\n func peek() -> Int {\n\n }\n \n /** Returns whether the queue is empty. */\n func empty() -> Bool {\n\n }\n}\n\n/**\n * Your MyQueue object will be instantiated and called as such:\n * let obj = MyQueue()\n * obj.push(x)\n * let ret_2: Int = obj.pop()\n * let ret_3: Int = obj.peek()\n * let ret_4: Bool = obj.empty()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type MyQueue struct {\n\n}\n\n\n/** Initialize your data structure here. */\nfunc Constructor() MyQueue {\n\n}\n\n\n/** Push element x to the back of queue. */\nfunc (this *MyQueue) Push(x int) {\n\n}\n\n\n/** Removes the element from in front of queue and returns that element. */\nfunc (this *MyQueue) Pop() int {\n\n}\n\n\n/** Get the front element. */\nfunc (this *MyQueue) Peek() int {\n\n}\n\n\n/** Returns whether the queue is empty. */\nfunc (this *MyQueue) Empty() bool {\n\n}\n\n\n/**\n * Your MyQueue object will be instantiated and called as such:\n * obj := Constructor();\n * obj.Push(x);\n * param_2 := obj.Pop();\n * param_3 := obj.Peek();\n * param_4 := obj.Empty();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class MyQueue() {\n\n /** Initialize your data structure here. */\n\n\n /** Push element x to the back of queue. */\n def push(x: Int) {\n\n }\n\n /** Removes the element from in front of queue and returns that element. */\n def pop(): Int = {\n\n }\n\n /** Get the front element. */\n def peek(): Int = {\n\n }\n\n /** Returns whether the queue is empty. */\n def empty(): Boolean = {\n\n }\n\n}\n\n/**\n * Your MyQueue object will be instantiated and called as such:\n * var obj = new MyQueue()\n * obj.push(x)\n * var param_2 = obj.pop()\n * var param_3 = obj.peek()\n * var param_4 = obj.empty()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class MyQueue() {\n\n /** Initialize your data structure here. */\n\n\n /** Push element x to the back of queue. */\n fun push(x: Int) {\n\n }\n\n /** Removes the element from in front of queue and returns that element. */\n fun pop(): Int {\n\n }\n\n /** Get the front element. */\n fun peek(): Int {\n\n }\n\n /** Returns whether the queue is empty. */\n fun empty(): Boolean {\n\n }\n\n}\n\n/**\n * Your MyQueue object will be instantiated and called as such:\n * var obj = MyQueue()\n * obj.push(x)\n * var param_2 = obj.pop()\n * var param_3 = obj.peek()\n * var param_4 = obj.empty()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct MyQueue {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl MyQueue {\n\n /** Initialize your data structure here. */\n fn new() -> Self {\n\n }\n \n /** Push element x to the back of queue. */\n fn push(&self, x: i32) {\n\n }\n \n /** Removes the element from in front of queue and returns that element. */\n fn pop(&self) -> i32 {\n\n }\n \n /** Get the front element. */\n fn peek(&self) -> i32 {\n\n }\n \n /** Returns whether the queue is empty. */\n fn empty(&self) -> bool {\n\n }\n}\n\n/**\n * Your MyQueue object will be instantiated and called as such:\n * let obj = MyQueue::new();\n * obj.push(x);\n * let ret_2: i32 = obj.pop();\n * let ret_3: i32 = obj.peek();\n * let ret_4: bool = obj.empty();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class MyQueue {\n /**\n * Initialize your data structure here.\n */\n function __construct() {\n\n }\n\n /**\n * Push element x to the back of queue.\n * @param Integer $x\n * @return NULL\n */\n function push($x) {\n\n }\n\n /**\n * Removes the element from in front of queue and returns that element.\n * @return Integer\n */\n function pop() {\n\n }\n\n /**\n * Get the front element.\n * @return Integer\n */\n function peek() {\n\n }\n\n /**\n * Returns whether the queue is empty.\n * @return Boolean\n */\n function empty() {\n\n }\n}\n\n/**\n * Your MyQueue object will be instantiated and called as such:\n * $obj = MyQueue();\n * $obj->push($x);\n * $ret_2 = $obj->pop();\n * $ret_3 = $obj->peek();\n * $ret_4 = $obj->empty();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class MyQueue {\n constructor() {\n\n }\n\n push(x: number): void {\n\n }\n\n pop(): number {\n\n }\n\n peek(): number {\n\n }\n\n empty(): boolean {\n\n }\n}\n\n/**\n * Your MyQueue object will be instantiated and called as such:\n * var obj = new MyQueue()\n * obj.push(x)\n * var param_2 = obj.pop()\n * var param_3 = obj.peek()\n * var param_4 = obj.empty()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define my-queue%\n (class object%\n (super-new)\n (init-field)\n \n ; push : exact-integer? -> void?\n (define/public (push x)\n\n )\n ; pop : -> exact-integer?\n (define/public (pop)\n\n )\n ; peek : -> exact-integer?\n (define/public (peek)\n\n )\n ; empty : -> boolean?\n (define/public (empty)\n\n )))\n\n;; Your my-queue% object will be instantiated and called as such:\n;; (define obj (new my-queue%))\n;; (send obj push x)\n;; (define param_2 (send obj pop))\n;; (define param_3 (send obj peek))\n;; (define param_4 (send obj empty))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0232](https://leetcode-cn.com/problems/implement-queue-using-stacks)", "[\u7528\u6808\u5b9e\u73b0\u961f\u5217](/solution/0200-0299/0232.Implement%20Queue%20using%20Stacks/README.md)", "`\u6808`,`\u8bbe\u8ba1`", "\u7b80\u5355", ""], "md_table_row_en": ["[0232](https://leetcode.com/problems/implement-queue-using-stacks)", "[Implement Queue using Stacks](/solution/0200-0299/0232.Implement%20Queue%20using%20Stacks/README_EN.md)", "`Stack`,`Design`", "Easy", ""]}, {"question_id": "0231", "frontend_question_id": "0231", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/power-of-two", "url_en": "https://leetcode.com/problems/power-of-two", "relative_path_cn": "/solution/0200-0299/0231.Power%20of%20Two/README.md", "relative_path_en": "/solution/0200-0299/0231.Power%20of%20Two/README_EN.md", "title_cn": "2 \u7684\u5e42", "title_en": "Power of Two", "question_title_slug": "power-of-two", "content_en": "

    Given an integer n, return true if it is a power of two. Otherwise, return false.

    \n\n

    An integer n is a power of two, if there exists an integer x such that n == 2x.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 1\nOutput: true\nExplanation: 20 = 1\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 16\nOutput: true\nExplanation: 24 = 16\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 3\nOutput: false\n
    \n\n

    Example 4:

    \n\n
    \nInput: n = 4\nOutput: true\n
    \n\n

    Example 5:

    \n\n
    \nInput: n = 5\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • -231 <= n <= 231 - 1
    • \n
    \n\n

     

    \nFollow up: Could you solve it without loops/recursion?", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n\uff0c\u8bf7\u4f60\u5224\u65ad\u8be5\u6574\u6570\u662f\u5426\u662f 2 \u7684\u5e42\u6b21\u65b9\u3002\u5982\u679c\u662f\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n

    \u5982\u679c\u5b58\u5728\u4e00\u4e2a\u6574\u6570 x \u4f7f\u5f97\u00a0n == 2x \uff0c\u5219\u8ba4\u4e3a n \u662f 2 \u7684\u5e42\u6b21\u65b9\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a20 = 1\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 16\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a24 = 16\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 3\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 4\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 5\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • -231 <= n <= 231 - 1
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u80fd\u591f\u4e0d\u4f7f\u7528\u5faa\u73af/\u9012\u5f52\u89e3\u51b3\u6b64\u95ee\u9898\u5417\uff1f

    \n", "tags_en": ["Bit Manipulation", "Math"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isPowerOfTwo(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isPowerOfTwo(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isPowerOfTwo(self, n):\n \"\"\"\n :type n: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isPowerOfTwo(self, n: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isPowerOfTwo(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsPowerOfTwo(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {boolean}\n */\nvar isPowerOfTwo = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Boolean}\ndef is_power_of_two(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isPowerOfTwo(_ n: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isPowerOfTwo(n int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isPowerOfTwo(n: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isPowerOfTwo(n: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_power_of_two(n: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Boolean\n */\n function isPowerOfTwo($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isPowerOfTwo(n: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-power-of-two n)\n (-> exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0231](https://leetcode-cn.com/problems/power-of-two)", "[2 \u7684\u5e42](/solution/0200-0299/0231.Power%20of%20Two/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0231](https://leetcode.com/problems/power-of-two)", "[Power of Two](/solution/0200-0299/0231.Power%20of%20Two/README_EN.md)", "`Bit Manipulation`,`Math`", "Easy", ""]}, {"question_id": "0230", "frontend_question_id": "0230", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/kth-smallest-element-in-a-bst", "url_en": "https://leetcode.com/problems/kth-smallest-element-in-a-bst", "relative_path_cn": "/solution/0200-0299/0230.Kth%20Smallest%20Element%20in%20a%20BST/README.md", "relative_path_en": "/solution/0200-0299/0230.Kth%20Smallest%20Element%20in%20a%20BST/README_EN.md", "title_cn": "\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u7b2cK\u5c0f\u7684\u5143\u7d20", "title_en": "Kth Smallest Element in a BST", "question_title_slug": "kth-smallest-element-in-a-bst", "content_en": "

    Given the root of a binary search tree, and an integer k, return the kth (1-indexed) smallest element in the tree.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [3,1,4,null,2], k = 1\nOutput: 1\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [5,3,6,2,4,null,null,1], k = 3\nOutput: 3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is n.
    • \n\t
    • 1 <= k <= n <= 104
    • \n\t
    • 0 <= Node.val <= 104
    • \n
    \n\n

     

    \nFollow up: If the BST is modified often (i.e., we can do insert and delete operations) and you need to find the kth smallest frequently, how would you optimize?", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6839\u8282\u70b9 root \uff0c\u548c\u4e00\u4e2a\u6574\u6570 k \uff0c\u8bf7\u4f60\u8bbe\u8ba1\u4e00\u4e2a\u7b97\u6cd5\u67e5\u627e\u5176\u4e2d\u7b2c\u00a0k\u00a0\u4e2a\u6700\u5c0f\u5143\u7d20\uff08\u4ece 1 \u5f00\u59cb\u8ba1\u6570\uff09\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [3,1,4,null,2], k = 1\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [5,3,6,2,4,null,null,1], k = 3\n\u8f93\u51fa\uff1a3\n
    \n\n

    \u00a0

    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u7684\u8282\u70b9\u6570\u4e3a n \u3002
    • \n\t
    • 1 <= k <= n <= 104
    • \n\t
    • 0 <= Node.val <= 104
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u5982\u679c\u4e8c\u53c9\u641c\u7d22\u6811\u7ecf\u5e38\u88ab\u4fee\u6539\uff08\u63d2\u5165/\u5220\u9664\u64cd\u4f5c\uff09\u5e76\u4e14\u4f60\u9700\u8981\u9891\u7e41\u5730\u67e5\u627e\u7b2c k \u5c0f\u7684\u503c\uff0c\u4f60\u5c06\u5982\u4f55\u4f18\u5316\u7b97\u6cd5\uff1f

    \n", "tags_en": ["Tree", "Binary Search"], "tags_cn": ["\u6811", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int kthSmallest(TreeNode* root, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int kthSmallest(TreeNode root, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def kthSmallest(self, root, k):\n \"\"\"\n :type root: TreeNode\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def kthSmallest(self, root: TreeNode, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint kthSmallest(struct TreeNode* root, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int KthSmallest(TreeNode root, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number} k\n * @return {number}\n */\nvar kthSmallest = function(root, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @param {Integer} k\n# @return {Integer}\ndef kth_smallest(root, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func kthSmallest(_ root: TreeNode?, _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc kthSmallest(root *TreeNode, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def kthSmallest(root: TreeNode, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun kthSmallest(root: TreeNode?, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn kth_smallest(root: Option>>, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param Integer $k\n * @return Integer\n */\n function kthSmallest($root, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction kthSmallest(root: TreeNode | null, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (kth-smallest root k)\n (-> (or/c tree-node? #f) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0230](https://leetcode-cn.com/problems/kth-smallest-element-in-a-bst)", "[\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u7b2cK\u5c0f\u7684\u5143\u7d20](/solution/0200-0299/0230.Kth%20Smallest%20Element%20in%20a%20BST/README.md)", "`\u6811`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0230](https://leetcode.com/problems/kth-smallest-element-in-a-bst)", "[Kth Smallest Element in a BST](/solution/0200-0299/0230.Kth%20Smallest%20Element%20in%20a%20BST/README_EN.md)", "`Tree`,`Binary Search`", "Medium", ""]}, {"question_id": "0229", "frontend_question_id": "0229", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/majority-element-ii", "url_en": "https://leetcode.com/problems/majority-element-ii", "relative_path_cn": "/solution/0200-0299/0229.Majority%20Element%20II/README.md", "relative_path_en": "/solution/0200-0299/0229.Majority%20Element%20II/README_EN.md", "title_cn": "\u6c42\u4f17\u6570 II", "title_en": "Majority Element II", "question_title_slug": "majority-element-ii", "content_en": "

    Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times.

    \n\n

    Follow-up: Could you solve the problem in linear time and in O(1) space?

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [3,2,3]\nOutput: [3]\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1]\nOutput: [1]\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [1,2]\nOutput: [1,2]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 5 * 104
    • \n\t
    • -109 <= nums[i] <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5927\u5c0f\u4e3a\u00a0n\u00a0\u7684\u6574\u6570\u6570\u7ec4\uff0c\u627e\u51fa\u5176\u4e2d\u6240\u6709\u51fa\u73b0\u8d85\u8fc7\u00a0\u230a n/3 \u230b\u00a0\u6b21\u7684\u5143\u7d20\u3002

    \n\n

    \u8fdb\u9636\uff1a\u5c1d\u8bd5\u8bbe\u8ba1\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\u3001\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a O(1)\u7684\u7b97\u6cd5\u89e3\u51b3\u6b64\u95ee\u9898\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\u00a01\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[3,2,3]\n\u8f93\u51fa\uff1a[3]
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1]\n\u8f93\u51fa\uff1a[1]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[1,1,1,3,3,2,2,2]\n\u8f93\u51fa\uff1a[1,2]
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 5 * 104
    • \n\t
    • -109 <= nums[i] <= 109
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector majorityElement(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List majorityElement(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def majorityElement(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def majorityElement(self, nums: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* majorityElement(int* nums, int numsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList MajorityElement(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar majorityElement = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer[]}\ndef majority_element(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func majorityElement(_ nums: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func majorityElement(nums []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def majorityElement(nums: Array[Int]): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun majorityElement(nums: IntArray): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn majority_element(nums: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer[]\n */\n function majorityElement($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function majorityElement(nums: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (majority-element nums)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0229](https://leetcode-cn.com/problems/majority-element-ii)", "[\u6c42\u4f17\u6570 II](/solution/0200-0299/0229.Majority%20Element%20II/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0229](https://leetcode.com/problems/majority-element-ii)", "[Majority Element II](/solution/0200-0299/0229.Majority%20Element%20II/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0228", "frontend_question_id": "0228", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/summary-ranges", "url_en": "https://leetcode.com/problems/summary-ranges", "relative_path_cn": "/solution/0200-0299/0228.Summary%20Ranges/README.md", "relative_path_en": "/solution/0200-0299/0228.Summary%20Ranges/README_EN.md", "title_cn": "\u6c47\u603b\u533a\u95f4", "title_en": "Summary Ranges", "question_title_slug": "summary-ranges", "content_en": "

    You are given a sorted unique integer array nums.

    \n\n

    Return the smallest sorted list of ranges that cover all the numbers in the array exactly. That is, each element of nums is covered by exactly one of the ranges, and there is no integer x such that x is in one of the ranges but not in nums.

    \n\n

    Each range [a,b] in the list should be output as:

    \n\n
      \n\t
    • "a->b" if a != b
    • \n\t
    • "a" if a == b
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [0,1,2,4,5,7]\nOutput: ["0->2","4->5","7"]\nExplanation: The ranges are:\n[0,2] --> "0->2"\n[4,5] --> "4->5"\n[7,7] --> "7"\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [0,2,3,4,6,8,9]\nOutput: ["0","2->4","6","8->9"]\nExplanation: The ranges are:\n[0,0] --> "0"\n[2,4] --> "2->4"\n[6,6] --> "6"\n[8,9] --> "8->9"\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = []\nOutput: []\n
    \n\n

    Example 4:

    \n\n
    \nInput: nums = [-1]\nOutput: ["-1"]\n
    \n\n

    Example 5:

    \n\n
    \nInput: nums = [0]\nOutput: ["0"]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= nums.length <= 20
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n\t
    • All the values of nums are unique.
    • \n\t
    • nums is sorted in ascending order.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u65e0\u91cd\u590d\u5143\u7d20\u7684\u6709\u5e8f\u6574\u6570\u6570\u7ec4 nums \u3002

    \n\n

    \u8fd4\u56de \u6070\u597d\u8986\u76d6\u6570\u7ec4\u4e2d\u6240\u6709\u6570\u5b57 \u7684 \u6700\u5c0f\u6709\u5e8f \u533a\u95f4\u8303\u56f4\u5217\u8868\u3002\u4e5f\u5c31\u662f\u8bf4\uff0cnums \u7684\u6bcf\u4e2a\u5143\u7d20\u90fd\u6070\u597d\u88ab\u67d0\u4e2a\u533a\u95f4\u8303\u56f4\u6240\u8986\u76d6\uff0c\u5e76\u4e14\u4e0d\u5b58\u5728\u5c5e\u4e8e\u67d0\u4e2a\u8303\u56f4\u4f46\u4e0d\u5c5e\u4e8e nums \u7684\u6570\u5b57 x \u3002

    \n\n

    \u5217\u8868\u4e2d\u7684\u6bcf\u4e2a\u533a\u95f4\u8303\u56f4 [a,b] \u5e94\u8be5\u6309\u5982\u4e0b\u683c\u5f0f\u8f93\u51fa\uff1a

    \n\n
      \n\t
    • \"a->b\" \uff0c\u5982\u679c a != b
    • \n\t
    • \"a\" \uff0c\u5982\u679c a == b
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [0,1,2,4,5,7]\n\u8f93\u51fa\uff1a[\"0->2\",\"4->5\",\"7\"]\n\u89e3\u91ca\uff1a\u533a\u95f4\u8303\u56f4\u662f\uff1a\n[0,2] --> \"0->2\"\n[4,5] --> \"4->5\"\n[7,7] --> \"7\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [0,2,3,4,6,8,9]\n\u8f93\u51fa\uff1a[\"0\",\"2->4\",\"6\",\"8->9\"]\n\u89e3\u91ca\uff1a\u533a\u95f4\u8303\u56f4\u662f\uff1a\n[0,0] --> \"0\"\n[2,4] --> \"2->4\"\n[6,6] --> \"6\"\n[8,9] --> \"8->9\"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = []\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [-1]\n\u8f93\u51fa\uff1a[\"-1\"]\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [0]\n\u8f93\u51fa\uff1a[\"0\"]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= nums.length <= 20
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n\t
    • nums \u4e2d\u7684\u6240\u6709\u503c\u90fd \u4e92\u4e0d\u76f8\u540c
    • \n\t
    • nums \u6309\u5347\u5e8f\u6392\u5217
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector summaryRanges(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List summaryRanges(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def summaryRanges(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def summaryRanges(self, nums: List[int]) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** summaryRanges(int* nums, int numsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList SummaryRanges(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {string[]}\n */\nvar summaryRanges = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {String[]}\ndef summary_ranges(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func summaryRanges(_ nums: [Int]) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func summaryRanges(nums []int) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def summaryRanges(nums: Array[Int]): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun summaryRanges(nums: IntArray): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn summary_ranges(nums: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return String[]\n */\n function summaryRanges($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function summaryRanges(nums: number[]): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (summary-ranges nums)\n (-> (listof exact-integer?) (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0228](https://leetcode-cn.com/problems/summary-ranges)", "[\u6c47\u603b\u533a\u95f4](/solution/0200-0299/0228.Summary%20Ranges/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0228](https://leetcode.com/problems/summary-ranges)", "[Summary Ranges](/solution/0200-0299/0228.Summary%20Ranges/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0227", "frontend_question_id": "0227", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/basic-calculator-ii", "url_en": "https://leetcode.com/problems/basic-calculator-ii", "relative_path_cn": "/solution/0200-0299/0227.Basic%20Calculator%20II/README.md", "relative_path_en": "/solution/0200-0299/0227.Basic%20Calculator%20II/README_EN.md", "title_cn": "\u57fa\u672c\u8ba1\u7b97\u5668 II", "title_en": "Basic Calculator II", "question_title_slug": "basic-calculator-ii", "content_en": "

    Given a string s which represents an expression, evaluate this expression and return its value

    \n\n

    The integer division should truncate toward zero.

    \n\n

    Note: You are not allowed to use any built-in function which evaluates strings as mathematical expressions, such as eval().

    \n\n

     

    \n

    Example 1:

    \n
    Input: s = \"3+2*2\"\nOutput: 7\n

    Example 2:

    \n
    Input: s = \" 3/2 \"\nOutput: 1\n

    Example 3:

    \n
    Input: s = \" 3+5 / 2 \"\nOutput: 5\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 3 * 105
    • \n\t
    • s consists of integers and operators ('+', '-', '*', '/') separated by some number of spaces.
    • \n\t
    • s represents a valid expression.
    • \n\t
    • All the integers in the expression are non-negative integers in the range [0, 231 - 1].
    • \n\t
    • The answer is guaranteed to fit in a 32-bit integer.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32\u8868\u8fbe\u5f0f s \uff0c\u8bf7\u4f60\u5b9e\u73b0\u4e00\u4e2a\u57fa\u672c\u8ba1\u7b97\u5668\u6765\u8ba1\u7b97\u5e76\u8fd4\u56de\u5b83\u7684\u503c\u3002

    \n\n

    \u6574\u6570\u9664\u6cd5\u4ec5\u4fdd\u7559\u6574\u6570\u90e8\u5206\u3002

    \n\n
    \n
    \n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"3+2*2\"\n\u8f93\u51fa\uff1a7\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \" 3/2 \"\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \" 3+5 / 2 \"\n\u8f93\u51fa\uff1a5\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 3 * 105
    • \n\t
    • s \u7531\u6574\u6570\u548c\u7b97\u7b26 ('+', '-', '*', '/') \u7ec4\u6210\uff0c\u4e2d\u95f4\u7531\u4e00\u4e9b\u7a7a\u683c\u9694\u5f00
    • \n\t
    • s \u8868\u793a\u4e00\u4e2a \u6709\u6548\u8868\u8fbe\u5f0f
    • \n\t
    • \u8868\u8fbe\u5f0f\u4e2d\u7684\u6240\u6709\u6574\u6570\u90fd\u662f\u975e\u8d1f\u6574\u6570\uff0c\u4e14\u5728\u8303\u56f4 [0, 231 - 1] \u5185
    • \n\t
    • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u7b54\u6848\u662f\u4e00\u4e2a 32-bit \u6574\u6570
    • \n
    \n
    \n
    \n", "tags_en": ["Stack", "String"], "tags_cn": ["\u6808", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int calculate(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int calculate(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def calculate(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def calculate(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint calculate(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int Calculate(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar calculate = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef calculate(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func calculate(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func calculate(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def calculate(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun calculate(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn calculate(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function calculate($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function calculate(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (calculate s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0227](https://leetcode-cn.com/problems/basic-calculator-ii)", "[\u57fa\u672c\u8ba1\u7b97\u5668 II](/solution/0200-0299/0227.Basic%20Calculator%20II/README.md)", "`\u6808`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0227](https://leetcode.com/problems/basic-calculator-ii)", "[Basic Calculator II](/solution/0200-0299/0227.Basic%20Calculator%20II/README_EN.md)", "`Stack`,`String`", "Medium", ""]}, {"question_id": "0226", "frontend_question_id": "0226", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/invert-binary-tree", "url_en": "https://leetcode.com/problems/invert-binary-tree", "relative_path_cn": "/solution/0200-0299/0226.Invert%20Binary%20Tree/README.md", "relative_path_en": "/solution/0200-0299/0226.Invert%20Binary%20Tree/README_EN.md", "title_cn": "\u7ffb\u8f6c\u4e8c\u53c9\u6811", "title_en": "Invert Binary Tree", "question_title_slug": "invert-binary-tree", "content_en": "

    Given the root of a binary tree, invert the tree, and return its root.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [4,2,7,1,3,6,9]\nOutput: [4,7,2,9,6,3,1]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [2,1,3]\nOutput: [2,3,1]\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = []\nOutput: []\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [0, 100].
    • \n\t
    • -100 <= Node.val <= 100
    • \n
    \n", "content_cn": "

    \u7ffb\u8f6c\u4e00\u68f5\u4e8c\u53c9\u6811\u3002

    \n\n

    \u793a\u4f8b\uff1a

    \n\n

    \u8f93\u5165\uff1a

    \n\n
         4\n   /   \\\n  2     7\n / \\   / \\\n1   3 6   9
    \n\n

    \u8f93\u51fa\uff1a

    \n\n
         4\n   /   \\\n  7     2\n / \\   / \\\n9   6 3   1
    \n\n

    \u5907\u6ce8:
    \n\u8fd9\u4e2a\u95ee\u9898\u662f\u53d7\u5230 Max Howell \u7684 \u539f\u95ee\u9898 \u542f\u53d1\u7684 \uff1a

    \n\n
    \u8c37\u6b4c\uff1a\u6211\u4eec90\uff05\u7684\u5de5\u7a0b\u5e08\u4f7f\u7528\u60a8\u7f16\u5199\u7684\u8f6f\u4ef6(Homebrew)\uff0c\u4f46\u662f\u60a8\u5374\u65e0\u6cd5\u5728\u9762\u8bd5\u65f6\u5728\u767d\u677f\u4e0a\u5199\u51fa\u7ffb\u8f6c\u4e8c\u53c9\u6811\u8fd9\u9053\u9898\uff0c\u8fd9\u592a\u7cdf\u7cd5\u4e86\u3002
    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* invertTree(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode invertTree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def invertTree(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: TreeNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def invertTree(self, root: TreeNode) -> TreeNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* invertTree(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode InvertTree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {TreeNode}\n */\nvar invertTree = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {TreeNode}\ndef invert_tree(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func invertTree(_ root: TreeNode?) -> TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc invertTree(root *TreeNode) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def invertTree(root: TreeNode): TreeNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun invertTree(root: TreeNode?): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn invert_tree(root: Option>>) -> Option>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return TreeNode\n */\n function invertTree($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction invertTree(root: TreeNode | null): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (invert-tree root)\n (-> (or/c tree-node? #f) (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0226](https://leetcode-cn.com/problems/invert-binary-tree)", "[\u7ffb\u8f6c\u4e8c\u53c9\u6811](/solution/0200-0299/0226.Invert%20Binary%20Tree/README.md)", "`\u6811`", "\u7b80\u5355", ""], "md_table_row_en": ["[0226](https://leetcode.com/problems/invert-binary-tree)", "[Invert Binary Tree](/solution/0200-0299/0226.Invert%20Binary%20Tree/README_EN.md)", "`Tree`", "Easy", ""]}, {"question_id": "0225", "frontend_question_id": "0225", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/implement-stack-using-queues", "url_en": "https://leetcode.com/problems/implement-stack-using-queues", "relative_path_cn": "/solution/0200-0299/0225.Implement%20Stack%20using%20Queues/README.md", "relative_path_en": "/solution/0200-0299/0225.Implement%20Stack%20using%20Queues/README_EN.md", "title_cn": "\u7528\u961f\u5217\u5b9e\u73b0\u6808", "title_en": "Implement Stack using Queues", "question_title_slug": "implement-stack-using-queues", "content_en": "

    Implement a last in first out (LIFO) stack using only two queues. The implemented stack should support all the functions of a normal queue (push, top, pop, and empty).

    \n\n

    Implement the MyStack class:

    \n\n
      \n\t
    • void push(int x) Pushes element x to the top of the stack.
    • \n\t
    • int pop() Removes the element on the top of the stack and returns it.
    • \n\t
    • int top() Returns the element on the top of the stack.
    • \n\t
    • boolean empty() Returns true if the stack is empty, false otherwise.
    • \n
    \n\n

    Notes:

    \n\n
      \n\t
    • You must use only standard operations of a queue, which means only push to back, peek/pop from front, size, and is empty operations are valid.
    • \n\t
    • Depending on your language, the queue may not be supported natively. You may simulate a queue using a list or deque (double-ended queue), as long as you use only a queue's standard operations.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["MyStack", "push", "push", "top", "pop", "empty"]\n[[], [1], [2], [], [], []]\nOutput\n[null, null, null, 2, 2, false]\n\nExplanation\nMyStack myStack = new MyStack();\nmyStack.push(1);\nmyStack.push(2);\nmyStack.top(); // return 2\nmyStack.pop(); // return 2\nmyStack.empty(); // return False\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= x <= 9
    • \n\t
    • At most 100 calls will be made to push, pop, top, and empty.
    • \n\t
    • All the calls to pop and top are valid.
    • \n
    \n\n

     

    \n

    Follow-up: Can you implement the stack such that each operation is amortized O(1) time complexity? In other words, performing n operations will take overall O(n) time even if one of those operations may take longer. You can use more than two queues.

    \n", "content_cn": "

    \u8bf7\u4f60\u4ec5\u4f7f\u7528\u4e24\u4e2a\u961f\u5217\u5b9e\u73b0\u4e00\u4e2a\u540e\u5165\u5148\u51fa\uff08LIFO\uff09\u7684\u6808\uff0c\u5e76\u652f\u6301\u666e\u901a\u961f\u5217\u7684\u5168\u90e8\u56db\u79cd\u64cd\u4f5c\uff08push\u3001top\u3001pop \u548c empty\uff09\u3002

    \n\n

    \u5b9e\u73b0 MyStack \u7c7b\uff1a

    \n\n
      \n\t
    • void push(int x) \u5c06\u5143\u7d20 x \u538b\u5165\u6808\u9876\u3002
    • \n\t
    • int pop() \u79fb\u9664\u5e76\u8fd4\u56de\u6808\u9876\u5143\u7d20\u3002
    • \n\t
    • int top() \u8fd4\u56de\u6808\u9876\u5143\u7d20\u3002
    • \n\t
    • boolean empty() \u5982\u679c\u6808\u662f\u7a7a\u7684\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    • \u4f60\u53ea\u80fd\u4f7f\u7528\u961f\u5217\u7684\u57fa\u672c\u64cd\u4f5c \u2014\u2014 \u4e5f\u5c31\u662f\u00a0push to back\u3001peek/pop from front\u3001size \u548c\u00a0is empty\u00a0\u8fd9\u4e9b\u64cd\u4f5c\u3002
    • \n\t
    • \u4f60\u6240\u4f7f\u7528\u7684\u8bed\u8a00\u4e5f\u8bb8\u4e0d\u652f\u6301\u961f\u5217\u3002\u00a0\u4f60\u53ef\u4ee5\u4f7f\u7528 list \uff08\u5217\u8868\uff09\u6216\u8005 deque\uff08\u53cc\u7aef\u961f\u5217\uff09\u6765\u6a21\u62df\u4e00\u4e2a\u961f\u5217\u00a0, \u53ea\u8981\u662f\u6807\u51c6\u7684\u961f\u5217\u64cd\u4f5c\u5373\u53ef\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\n[\"MyStack\", \"push\", \"push\", \"top\", \"pop\", \"empty\"]\n[[], [1], [2], [], [], []]\n\u8f93\u51fa\uff1a\n[null, null, null, 2, 2, false]\n\n\u89e3\u91ca\uff1a\nMyStack myStack = new MyStack();\nmyStack.push(1);\nmyStack.push(2);\nmyStack.top(); // \u8fd4\u56de 2\nmyStack.pop(); // \u8fd4\u56de 2\nmyStack.empty(); // \u8fd4\u56de False\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= x <= 9
    • \n\t
    • \u6700\u591a\u8c03\u7528100 \u6b21 push\u3001pop\u3001top \u548c empty
    • \n\t
    • \u6bcf\u6b21\u8c03\u7528 pop \u548c top \u90fd\u4fdd\u8bc1\u6808\u4e0d\u4e3a\u7a7a
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u80fd\u5426\u5b9e\u73b0\u6bcf\u79cd\u64cd\u4f5c\u7684\u5747\u644a\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(1) \u7684\u6808\uff1f\u6362\u53e5\u8bdd\u8bf4\uff0c\u6267\u884c n \u4e2a\u64cd\u4f5c\u7684\u603b\u65f6\u95f4\u590d\u6742\u5ea6 O(n) \uff0c\u5c3d\u7ba1\u5176\u4e2d\u67d0\u4e2a\u64cd\u4f5c\u53ef\u80fd\u9700\u8981\u6bd4\u5176\u4ed6\u64cd\u4f5c\u66f4\u957f\u7684\u65f6\u95f4\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u4e24\u4e2a\u4ee5\u4e0a\u7684\u961f\u5217\u3002

    \n", "tags_en": ["Stack", "Design"], "tags_cn": ["\u6808", "\u8bbe\u8ba1"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class MyStack {\npublic:\n /** Initialize your data structure here. */\n MyStack() {\n\n }\n \n /** Push element x onto stack. */\n void push(int x) {\n\n }\n \n /** Removes the element on top of the stack and returns that element. */\n int pop() {\n\n }\n \n /** Get the top element. */\n int top() {\n\n }\n \n /** Returns whether the stack is empty. */\n bool empty() {\n\n }\n};\n\n/**\n * Your MyStack object will be instantiated and called as such:\n * MyStack* obj = new MyStack();\n * obj->push(x);\n * int param_2 = obj->pop();\n * int param_3 = obj->top();\n * bool param_4 = obj->empty();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class MyStack {\n\n /** Initialize your data structure here. */\n public MyStack() {\n\n }\n \n /** Push element x onto stack. */\n public void push(int x) {\n\n }\n \n /** Removes the element on top of the stack and returns that element. */\n public int pop() {\n\n }\n \n /** Get the top element. */\n public int top() {\n\n }\n \n /** Returns whether the stack is empty. */\n public boolean empty() {\n\n }\n}\n\n/**\n * Your MyStack object will be instantiated and called as such:\n * MyStack obj = new MyStack();\n * obj.push(x);\n * int param_2 = obj.pop();\n * int param_3 = obj.top();\n * boolean param_4 = obj.empty();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class MyStack(object):\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def push(self, x):\n \"\"\"\n Push element x onto stack.\n :type x: int\n :rtype: None\n \"\"\"\n\n\n def pop(self):\n \"\"\"\n Removes the element on top of the stack and returns that element.\n :rtype: int\n \"\"\"\n\n\n def top(self):\n \"\"\"\n Get the top element.\n :rtype: int\n \"\"\"\n\n\n def empty(self):\n \"\"\"\n Returns whether the stack is empty.\n :rtype: bool\n \"\"\"\n\n\n\n# Your MyStack object will be instantiated and called as such:\n# obj = MyStack()\n# obj.push(x)\n# param_2 = obj.pop()\n# param_3 = obj.top()\n# param_4 = obj.empty()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class MyStack:\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def push(self, x: int) -> None:\n \"\"\"\n Push element x onto stack.\n \"\"\"\n\n\n def pop(self) -> int:\n \"\"\"\n Removes the element on top of the stack and returns that element.\n \"\"\"\n\n\n def top(self) -> int:\n \"\"\"\n Get the top element.\n \"\"\"\n\n\n def empty(self) -> bool:\n \"\"\"\n Returns whether the stack is empty.\n \"\"\"\n\n\n\n# Your MyStack object will be instantiated and called as such:\n# obj = MyStack()\n# obj.push(x)\n# param_2 = obj.pop()\n# param_3 = obj.top()\n# param_4 = obj.empty()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} MyStack;\n\n/** Initialize your data structure here. */\n\nMyStack* myStackCreate() {\n\n}\n\n/** Push element x onto stack. */\nvoid myStackPush(MyStack* obj, int x) {\n\n}\n\n/** Removes the element on top of the stack and returns that element. */\nint myStackPop(MyStack* obj) {\n\n}\n\n/** Get the top element. */\nint myStackTop(MyStack* obj) {\n\n}\n\n/** Returns whether the stack is empty. */\nbool myStackEmpty(MyStack* obj) {\n\n}\n\nvoid myStackFree(MyStack* obj) {\n\n}\n\n/**\n * Your MyStack struct will be instantiated and called as such:\n * MyStack* obj = myStackCreate();\n * myStackPush(obj, x);\n \n * int param_2 = myStackPop(obj);\n \n * int param_3 = myStackTop(obj);\n \n * bool param_4 = myStackEmpty(obj);\n \n * myStackFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class MyStack {\n\n /** Initialize your data structure here. */\n public MyStack() {\n\n }\n \n /** Push element x onto stack. */\n public void Push(int x) {\n\n }\n \n /** Removes the element on top of the stack and returns that element. */\n public int Pop() {\n\n }\n \n /** Get the top element. */\n public int Top() {\n\n }\n \n /** Returns whether the stack is empty. */\n public bool Empty() {\n\n }\n}\n\n/**\n * Your MyStack object will be instantiated and called as such:\n * MyStack obj = new MyStack();\n * obj.Push(x);\n * int param_2 = obj.Pop();\n * int param_3 = obj.Top();\n * bool param_4 = obj.Empty();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Initialize your data structure here.\n */\nvar MyStack = function() {\n\n};\n\n/**\n * Push element x onto stack. \n * @param {number} x\n * @return {void}\n */\nMyStack.prototype.push = function(x) {\n\n};\n\n/**\n * Removes the element on top of the stack and returns that element.\n * @return {number}\n */\nMyStack.prototype.pop = function() {\n\n};\n\n/**\n * Get the top element.\n * @return {number}\n */\nMyStack.prototype.top = function() {\n\n};\n\n/**\n * Returns whether the stack is empty.\n * @return {boolean}\n */\nMyStack.prototype.empty = function() {\n\n};\n\n/**\n * Your MyStack object will be instantiated and called as such:\n * var obj = new MyStack()\n * obj.push(x)\n * var param_2 = obj.pop()\n * var param_3 = obj.top()\n * var param_4 = obj.empty()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class MyStack\n\n=begin\n Initialize your data structure here.\n=end\n def initialize()\n\n end\n\n\n=begin\n Push element x onto stack.\n :type x: Integer\n :rtype: Void\n=end\n def push(x)\n\n end\n\n\n=begin\n Removes the element on top of the stack and returns that element.\n :rtype: Integer\n=end\n def pop()\n\n end\n\n\n=begin\n Get the top element.\n :rtype: Integer\n=end\n def top()\n\n end\n\n\n=begin\n Returns whether the stack is empty.\n :rtype: Boolean\n=end\n def empty()\n\n end\n\n\nend\n\n# Your MyStack object will be instantiated and called as such:\n# obj = MyStack.new()\n# obj.push(x)\n# param_2 = obj.pop()\n# param_3 = obj.top()\n# param_4 = obj.empty()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass MyStack {\n\n /** Initialize your data structure here. */\n init() {\n\n }\n \n /** Push element x onto stack. */\n func push(_ x: Int) {\n\n }\n \n /** Removes the element on top of the stack and returns that element. */\n func pop() -> Int {\n\n }\n \n /** Get the top element. */\n func top() -> Int {\n\n }\n \n /** Returns whether the stack is empty. */\n func empty() -> Bool {\n\n }\n}\n\n/**\n * Your MyStack object will be instantiated and called as such:\n * let obj = MyStack()\n * obj.push(x)\n * let ret_2: Int = obj.pop()\n * let ret_3: Int = obj.top()\n * let ret_4: Bool = obj.empty()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type MyStack struct {\n\n}\n\n\n/** Initialize your data structure here. */\nfunc Constructor() MyStack {\n\n}\n\n\n/** Push element x onto stack. */\nfunc (this *MyStack) Push(x int) {\n\n}\n\n\n/** Removes the element on top of the stack and returns that element. */\nfunc (this *MyStack) Pop() int {\n\n}\n\n\n/** Get the top element. */\nfunc (this *MyStack) Top() int {\n\n}\n\n\n/** Returns whether the stack is empty. */\nfunc (this *MyStack) Empty() bool {\n\n}\n\n\n/**\n * Your MyStack object will be instantiated and called as such:\n * obj := Constructor();\n * obj.Push(x);\n * param_2 := obj.Pop();\n * param_3 := obj.Top();\n * param_4 := obj.Empty();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class MyStack() {\n\n /** Initialize your data structure here. */\n\n\n /** Push element x onto stack. */\n def push(x: Int) {\n\n }\n\n /** Removes the element on top of the stack and returns that element. */\n def pop(): Int = {\n\n }\n\n /** Get the top element. */\n def top(): Int = {\n\n }\n\n /** Returns whether the stack is empty. */\n def empty(): Boolean = {\n\n }\n\n}\n\n/**\n * Your MyStack object will be instantiated and called as such:\n * var obj = new MyStack()\n * obj.push(x)\n * var param_2 = obj.pop()\n * var param_3 = obj.top()\n * var param_4 = obj.empty()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class MyStack() {\n\n /** Initialize your data structure here. */\n\n\n /** Push element x onto stack. */\n fun push(x: Int) {\n\n }\n\n /** Removes the element on top of the stack and returns that element. */\n fun pop(): Int {\n\n }\n\n /** Get the top element. */\n fun top(): Int {\n\n }\n\n /** Returns whether the stack is empty. */\n fun empty(): Boolean {\n\n }\n\n}\n\n/**\n * Your MyStack object will be instantiated and called as such:\n * var obj = MyStack()\n * obj.push(x)\n * var param_2 = obj.pop()\n * var param_3 = obj.top()\n * var param_4 = obj.empty()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct MyStack {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl MyStack {\n\n /** Initialize your data structure here. */\n fn new() -> Self {\n\n }\n \n /** Push element x onto stack. */\n fn push(&self, x: i32) {\n\n }\n \n /** Removes the element on top of the stack and returns that element. */\n fn pop(&self) -> i32 {\n\n }\n \n /** Get the top element. */\n fn top(&self) -> i32 {\n\n }\n \n /** Returns whether the stack is empty. */\n fn empty(&self) -> bool {\n\n }\n}\n\n/**\n * Your MyStack object will be instantiated and called as such:\n * let obj = MyStack::new();\n * obj.push(x);\n * let ret_2: i32 = obj.pop();\n * let ret_3: i32 = obj.top();\n * let ret_4: bool = obj.empty();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class MyStack {\n /**\n * Initialize your data structure here.\n */\n function __construct() {\n\n }\n\n /**\n * Push element x onto stack.\n * @param Integer $x\n * @return NULL\n */\n function push($x) {\n\n }\n\n /**\n * Removes the element on top of the stack and returns that element.\n * @return Integer\n */\n function pop() {\n\n }\n\n /**\n * Get the top element.\n * @return Integer\n */\n function top() {\n\n }\n\n /**\n * Returns whether the stack is empty.\n * @return Boolean\n */\n function empty() {\n\n }\n}\n\n/**\n * Your MyStack object will be instantiated and called as such:\n * $obj = MyStack();\n * $obj->push($x);\n * $ret_2 = $obj->pop();\n * $ret_3 = $obj->top();\n * $ret_4 = $obj->empty();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class MyStack {\n constructor() {\n\n }\n\n push(x: number): void {\n\n }\n\n pop(): number {\n\n }\n\n top(): number {\n\n }\n\n empty(): boolean {\n\n }\n}\n\n/**\n * Your MyStack object will be instantiated and called as such:\n * var obj = new MyStack()\n * obj.push(x)\n * var param_2 = obj.pop()\n * var param_3 = obj.top()\n * var param_4 = obj.empty()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define my-stack%\n (class object%\n (super-new)\n (init-field)\n \n ; push : exact-integer? -> void?\n (define/public (push x)\n\n )\n ; pop : -> exact-integer?\n (define/public (pop)\n\n )\n ; top : -> exact-integer?\n (define/public (top)\n\n )\n ; empty : -> boolean?\n (define/public (empty)\n\n )))\n\n;; Your my-stack% object will be instantiated and called as such:\n;; (define obj (new my-stack%))\n;; (send obj push x)\n;; (define param_2 (send obj pop))\n;; (define param_3 (send obj top))\n;; (define param_4 (send obj empty))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0225](https://leetcode-cn.com/problems/implement-stack-using-queues)", "[\u7528\u961f\u5217\u5b9e\u73b0\u6808](/solution/0200-0299/0225.Implement%20Stack%20using%20Queues/README.md)", "`\u6808`,`\u8bbe\u8ba1`", "\u7b80\u5355", ""], "md_table_row_en": ["[0225](https://leetcode.com/problems/implement-stack-using-queues)", "[Implement Stack using Queues](/solution/0200-0299/0225.Implement%20Stack%20using%20Queues/README_EN.md)", "`Stack`,`Design`", "Easy", ""]}, {"question_id": "0224", "frontend_question_id": "0224", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/basic-calculator", "url_en": "https://leetcode.com/problems/basic-calculator", "relative_path_cn": "/solution/0200-0299/0224.Basic%20Calculator/README.md", "relative_path_en": "/solution/0200-0299/0224.Basic%20Calculator/README_EN.md", "title_cn": "\u57fa\u672c\u8ba1\u7b97\u5668", "title_en": "Basic Calculator", "question_title_slug": "basic-calculator", "content_en": "

    Given a string s representing a valid expression, implement a basic calculator to evaluate it, and return the result of the evaluation.

    \n\n

    Note: You are not allowed to use any built-in function which evaluates strings as mathematical expressions, such as eval().

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "1 + 1"\nOutput: 2\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = " 2-1 + 2 "\nOutput: 3\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "(1+(4+5+2)-3)+(6+8)"\nOutput: 23\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "+48 + -48"\nOutput: 0\nExplanation: Numbers can have multiple digits and start with +/-.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 3 * 105
    • \n\t
    • s consists of digits, '+', '-', '(', ')', and ' '.
    • \n\t
    • s represents a valid expression.
    • \n\t
    • Every number and running calculation will fit in a signed 32-bit integer.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32\u8868\u8fbe\u5f0f s \uff0c\u8bf7\u4f60\u5b9e\u73b0\u4e00\u4e2a\u57fa\u672c\u8ba1\u7b97\u5668\u6765\u8ba1\u7b97\u5e76\u8fd4\u56de\u5b83\u7684\u503c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"1 + 1\"\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \" 2-1 + 2 \"\n\u8f93\u51fa\uff1a3\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"(1+(4+5+2)-3)+(6+8)\"\n\u8f93\u51fa\uff1a23\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 3\u00a0* 105
    • \n\t
    • s \u7531\u6570\u5b57\u3001'+'\u3001'-'\u3001'('\u3001')'\u3001\u548c ' ' \u7ec4\u6210
    • \n\t
    • s \u8868\u793a\u4e00\u4e2a\u6709\u6548\u7684\u8868\u8fbe\u5f0f
    • \n
    \n", "tags_en": ["Stack", "Math"], "tags_cn": ["\u6808", "\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int calculate(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int calculate(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def calculate(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def calculate(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint calculate(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int Calculate(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar calculate = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef calculate(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func calculate(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func calculate(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def calculate(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun calculate(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn calculate(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function calculate($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function calculate(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (calculate s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0224](https://leetcode-cn.com/problems/basic-calculator)", "[\u57fa\u672c\u8ba1\u7b97\u5668](/solution/0200-0299/0224.Basic%20Calculator/README.md)", "`\u6808`,`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[0224](https://leetcode.com/problems/basic-calculator)", "[Basic Calculator](/solution/0200-0299/0224.Basic%20Calculator/README_EN.md)", "`Stack`,`Math`", "Hard", ""]}, {"question_id": "0223", "frontend_question_id": "0223", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/rectangle-area", "url_en": "https://leetcode.com/problems/rectangle-area", "relative_path_cn": "/solution/0200-0299/0223.Rectangle%20Area/README.md", "relative_path_en": "/solution/0200-0299/0223.Rectangle%20Area/README_EN.md", "title_cn": "\u77e9\u5f62\u9762\u79ef", "title_en": "Rectangle Area", "question_title_slug": "rectangle-area", "content_en": "

    Given the coordinates of two rectilinear rectangles in a 2D plane, return the total area covered by the two rectangles.

    \n\n

    The first rectangle is defined by its bottom-left corner (ax1, ay1) and its top-right corner (ax2, ay2).

    \n\n

    The second rectangle is defined by its bottom-left corner (bx1, by1) and its top-right corner (bx2, by2).

    \n\n

     

    \n

    Example 1:

    \n\"Rectangle\n
    \nInput: ax1 = -3, ay1 = 0, ax2 = 3, ay2 = 4, bx1 = 0, by1 = -1, bx2 = 9, by2 = 2\nOutput: 45\n
    \n\n

    Example 2:

    \n\n
    \nInput: ax1 = -2, ay1 = -2, ax2 = 2, ay2 = 2, bx1 = -2, by1 = -2, bx2 = 2, by2 = 2\nOutput: 16\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • -104 <= ax1, ay1, ax2, ay2, bx1, by1, bx2, by2 <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60 \u4e8c\u7ef4 \u5e73\u9762\u4e0a\u4e24\u4e2a \u7531\u76f4\u7ebf\u6784\u6210\u7684 \u77e9\u5f62\uff0c\u8bf7\u4f60\u8ba1\u7b97\u5e76\u8fd4\u56de\u4e24\u4e2a\u77e9\u5f62\u8986\u76d6\u7684\u603b\u9762\u79ef\u3002

    \n\n

    \u6bcf\u4e2a\u77e9\u5f62\u7531\u5176 \u5de6\u4e0b \u9876\u70b9\u548c \u53f3\u4e0a \u9876\u70b9\u5750\u6807\u8868\u793a\uff1a

    \n\n
    \n
      \n\t
    • \u7b2c\u4e00\u4e2a\u77e9\u5f62\u7531\u5176\u5de6\u4e0b\u9876\u70b9 (ax1, ay1) \u548c\u53f3\u4e0a\u9876\u70b9 (ax2, ay2) \u5b9a\u4e49\u3002
    • \n\t
    • \u7b2c\u4e8c\u4e2a\u77e9\u5f62\u7531\u5176\u5de6\u4e0b\u9876\u70b9 (bx1, by1) \u548c\u53f3\u4e0a\u9876\u70b9 (bx2, by2) \u5b9a\u4e49\u3002
    • \n
    \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"Rectangle\n
    \n\u8f93\u5165\uff1aax1 = -3, ay1 = 0, ax2 = 3, ay2 = 4, bx1 = 0, by1 = -1, bx2 = 9, by2 = 2\n\u8f93\u51fa\uff1a45\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aax1 = -2, ay1 = -2, ax2 = 2, ay2 = 2, bx1 = -2, by1 = -2, bx2 = 2, by2 = 2\n\u8f93\u51fa\uff1a16\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • -104 <= ax1, ay1, ax2, ay2, bx1, by1, bx2, by2 <= 104
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int computeArea(int ax1, int ay1, int ax2, int ay2, int bx1, int by1, int bx2, int by2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int computeArea(int ax1, int ay1, int ax2, int ay2, int bx1, int by1, int bx2, int by2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def computeArea(self, ax1, ay1, ax2, ay2, bx1, by1, bx2, by2):\n \"\"\"\n :type ax1: int\n :type ay1: int\n :type ax2: int\n :type ay2: int\n :type bx1: int\n :type by1: int\n :type bx2: int\n :type by2: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def computeArea(self, ax1: int, ay1: int, ax2: int, ay2: int, bx1: int, by1: int, bx2: int, by2: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint computeArea(int ax1, int ay1, int ax2, int ay2, int bx1, int by1, int bx2, int by2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ComputeArea(int ax1, int ay1, int ax2, int ay2, int bx1, int by1, int bx2, int by2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} ax1\n * @param {number} ay1\n * @param {number} ax2\n * @param {number} ay2\n * @param {number} bx1\n * @param {number} by1\n * @param {number} bx2\n * @param {number} by2\n * @return {number}\n */\nvar computeArea = function(ax1, ay1, ax2, ay2, bx1, by1, bx2, by2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} ax1\n# @param {Integer} ay1\n# @param {Integer} ax2\n# @param {Integer} ay2\n# @param {Integer} bx1\n# @param {Integer} by1\n# @param {Integer} bx2\n# @param {Integer} by2\n# @return {Integer}\ndef compute_area(ax1, ay1, ax2, ay2, bx1, by1, bx2, by2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func computeArea(_ ax1: Int, _ ay1: Int, _ ax2: Int, _ ay2: Int, _ bx1: Int, _ by1: Int, _ bx2: Int, _ by2: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func computeArea(ax1 int, ay1 int, ax2 int, ay2 int, bx1 int, by1 int, bx2 int, by2 int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def computeArea(ax1: Int, ay1: Int, ax2: Int, ay2: Int, bx1: Int, by1: Int, bx2: Int, by2: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun computeArea(ax1: Int, ay1: Int, ax2: Int, ay2: Int, bx1: Int, by1: Int, bx2: Int, by2: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn compute_area(ax1: i32, ay1: i32, ax2: i32, ay2: i32, bx1: i32, by1: i32, bx2: i32, by2: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $ax1\n * @param Integer $ay1\n * @param Integer $ax2\n * @param Integer $ay2\n * @param Integer $bx1\n * @param Integer $by1\n * @param Integer $bx2\n * @param Integer $by2\n * @return Integer\n */\n function computeArea($ax1, $ay1, $ax2, $ay2, $bx1, $by1, $bx2, $by2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function computeArea(ax1: number, ay1: number, ax2: number, ay2: number, bx1: number, by1: number, bx2: number, by2: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (compute-area ax1 ay1 ax2 ay2 bx1 by1 bx2 by2)\n (-> exact-integer? exact-integer? exact-integer? exact-integer? exact-integer? exact-integer? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0223](https://leetcode-cn.com/problems/rectangle-area)", "[\u77e9\u5f62\u9762\u79ef](/solution/0200-0299/0223.Rectangle%20Area/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0223](https://leetcode.com/problems/rectangle-area)", "[Rectangle Area](/solution/0200-0299/0223.Rectangle%20Area/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "0222", "frontend_question_id": "0222", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-complete-tree-nodes", "url_en": "https://leetcode.com/problems/count-complete-tree-nodes", "relative_path_cn": "/solution/0200-0299/0222.Count%20Complete%20Tree%20Nodes/README.md", "relative_path_en": "/solution/0200-0299/0222.Count%20Complete%20Tree%20Nodes/README_EN.md", "title_cn": "\u5b8c\u5168\u4e8c\u53c9\u6811\u7684\u8282\u70b9\u4e2a\u6570", "title_en": "Count Complete Tree Nodes", "question_title_slug": "count-complete-tree-nodes", "content_en": "

    Given the root of a complete binary tree, return the number of the nodes in the tree.

    \n\n

    According to Wikipedia, every level, except possibly the last, is completely filled in a complete binary tree, and all nodes in the last level are as far left as possible. It can have between 1 and 2h nodes inclusive at the last level h.

    \n\n

    Design an algorithm that runs in less than O(n) time complexity.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,2,3,4,5,6]\nOutput: 6\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = []\nOutput: 0\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = [1]\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [0, 5 * 104].
    • \n\t
    • 0 <= Node.val <= 5 * 104
    • \n\t
    • The tree is guaranteed to be complete.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u68f5 \u5b8c\u5168\u4e8c\u53c9\u6811 \u7684\u6839\u8282\u70b9 root \uff0c\u6c42\u51fa\u8be5\u6811\u7684\u8282\u70b9\u4e2a\u6570\u3002

    \n\n

    \u5b8c\u5168\u4e8c\u53c9\u6811 \u7684\u5b9a\u4e49\u5982\u4e0b\uff1a\u5728\u5b8c\u5168\u4e8c\u53c9\u6811\u4e2d\uff0c\u9664\u4e86\u6700\u5e95\u5c42\u8282\u70b9\u53ef\u80fd\u6ca1\u586b\u6ee1\u5916\uff0c\u5176\u4f59\u6bcf\u5c42\u8282\u70b9\u6570\u90fd\u8fbe\u5230\u6700\u5927\u503c\uff0c\u5e76\u4e14\u6700\u4e0b\u9762\u4e00\u5c42\u7684\u8282\u70b9\u90fd\u96c6\u4e2d\u5728\u8be5\u5c42\u6700\u5de6\u8fb9\u7684\u82e5\u5e72\u4f4d\u7f6e\u3002\u82e5\u6700\u5e95\u5c42\u4e3a\u7b2c h \u5c42\uff0c\u5219\u8be5\u5c42\u5305\u542b 1~\u00a02h\u00a0\u4e2a\u8282\u70b9\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [1,2,3,4,5,6]\n\u8f93\u51fa\uff1a6\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = []\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [1]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u7684\u6570\u76ee\u8303\u56f4\u662f[0, 5 * 104]
    • \n\t
    • 0 <= Node.val <= 5 * 104
    • \n\t
    • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u8f93\u5165\u7684\u6811\u662f \u5b8c\u5168\u4e8c\u53c9\u6811
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u904d\u5386\u6811\u6765\u7edf\u8ba1\u8282\u70b9\u662f\u4e00\u79cd\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n) \u7684\u7b80\u5355\u89e3\u51b3\u65b9\u6848\u3002\u4f60\u53ef\u4ee5\u8bbe\u8ba1\u4e00\u4e2a\u66f4\u5feb\u7684\u7b97\u6cd5\u5417\uff1f

    \n", "tags_en": ["Tree", "Binary Search"], "tags_cn": ["\u6811", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int countNodes(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int countNodes(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def countNodes(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def countNodes(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint countNodes(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int CountNodes(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar countNodes = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef count_nodes(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func countNodes(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc countNodes(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def countNodes(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun countNodes(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn count_nodes(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function countNodes($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction countNodes(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (count-nodes root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0222](https://leetcode-cn.com/problems/count-complete-tree-nodes)", "[\u5b8c\u5168\u4e8c\u53c9\u6811\u7684\u8282\u70b9\u4e2a\u6570](/solution/0200-0299/0222.Count%20Complete%20Tree%20Nodes/README.md)", "`\u6811`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0222](https://leetcode.com/problems/count-complete-tree-nodes)", "[Count Complete Tree Nodes](/solution/0200-0299/0222.Count%20Complete%20Tree%20Nodes/README_EN.md)", "`Tree`,`Binary Search`", "Medium", ""]}, {"question_id": "0221", "frontend_question_id": "0221", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximal-square", "url_en": "https://leetcode.com/problems/maximal-square", "relative_path_cn": "/solution/0200-0299/0221.Maximal%20Square/README.md", "relative_path_en": "/solution/0200-0299/0221.Maximal%20Square/README_EN.md", "title_cn": "\u6700\u5927\u6b63\u65b9\u5f62", "title_en": "Maximal Square", "question_title_slug": "maximal-square", "content_en": "

    Given an m x n binary matrix filled with 0's and 1's, find the largest square containing only 1's and return its area.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: matrix = [["1","0","1","0","0"],["1","0","1","1","1"],["1","1","1","1","1"],["1","0","0","1","0"]]\nOutput: 4\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: matrix = [["0","1"],["1","0"]]\nOutput: 1\n
    \n\n

    Example 3:

    \n\n
    \nInput: matrix = [["0"]]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == matrix.length
    • \n\t
    • n == matrix[i].length
    • \n\t
    • 1 <= m, n <= 300
    • \n\t
    • matrix[i][j] is '0' or '1'.
    • \n
    \n", "content_cn": "

    \u5728\u4e00\u4e2a\u7531 '0' \u548c '1' \u7ec4\u6210\u7684\u4e8c\u7ef4\u77e9\u9635\u5185\uff0c\u627e\u5230\u53ea\u5305\u542b '1' \u7684\u6700\u5927\u6b63\u65b9\u5f62\uff0c\u5e76\u8fd4\u56de\u5176\u9762\u79ef\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1amatrix = [[\"1\",\"0\",\"1\",\"0\",\"0\"],[\"1\",\"0\",\"1\",\"1\",\"1\"],[\"1\",\"1\",\"1\",\"1\",\"1\"],[\"1\",\"0\",\"0\",\"1\",\"0\"]]\n\u8f93\u51fa\uff1a4\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1amatrix = [[\"0\",\"1\"],[\"1\",\"0\"]]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1amatrix = [[\"0\"]]\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == matrix.length
    • \n\t
    • n == matrix[i].length
    • \n\t
    • 1 <= m, n <= 300
    • \n\t
    • matrix[i][j] \u4e3a '0' \u6216 '1'
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maximalSquare(vector>& matrix) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maximalSquare(char[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximalSquare(self, matrix):\n \"\"\"\n :type matrix: List[List[str]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximalSquare(self, matrix: List[List[str]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maximalSquare(char** matrix, int matrixSize, int* matrixColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaximalSquare(char[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {character[][]} matrix\n * @return {number}\n */\nvar maximalSquare = function(matrix) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Character[][]} matrix\n# @return {Integer}\ndef maximal_square(matrix)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximalSquare(_ matrix: [[Character]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximalSquare(matrix [][]byte) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximalSquare(matrix: Array[Array[Char]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximalSquare(matrix: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximal_square(matrix: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $matrix\n * @return Integer\n */\n function maximalSquare($matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximalSquare(matrix: string[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximal-square matrix)\n (-> (listof (listof char?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0221](https://leetcode-cn.com/problems/maximal-square)", "[\u6700\u5927\u6b63\u65b9\u5f62](/solution/0200-0299/0221.Maximal%20Square/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0221](https://leetcode.com/problems/maximal-square)", "[Maximal Square](/solution/0200-0299/0221.Maximal%20Square/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0220", "frontend_question_id": "0220", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/contains-duplicate-iii", "url_en": "https://leetcode.com/problems/contains-duplicate-iii", "relative_path_cn": "/solution/0200-0299/0220.Contains%20Duplicate%20III/README.md", "relative_path_en": "/solution/0200-0299/0220.Contains%20Duplicate%20III/README_EN.md", "title_cn": "\u5b58\u5728\u91cd\u590d\u5143\u7d20 III", "title_en": "Contains Duplicate III", "question_title_slug": "contains-duplicate-iii", "content_en": "

    Given an integer array nums and two integers k and t, return true if there are two distinct indices i and j in the array such that abs(nums[i] - nums[j]) <= t and abs(i - j) <= k.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [1,2,3,1], k = 3, t = 0\nOutput: true\n

    Example 2:

    \n
    Input: nums = [1,0,1,1], k = 1, t = 2\nOutput: true\n

    Example 3:

    \n
    Input: nums = [1,5,9,1,5,9], k = 2, t = 3\nOutput: false\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= nums.length <= 2 * 104
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n\t
    • 0 <= k <= 104
    • \n\t
    • 0 <= t <= 231 - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \u548c\u4e24\u4e2a\u6574\u6570\u00a0k \u548c t \u3002\u8bf7\u4f60\u5224\u65ad\u662f\u5426\u5b58\u5728 \u4e24\u4e2a\u4e0d\u540c\u4e0b\u6807 i \u548c j\uff0c\u4f7f\u5f97\u00a0abs(nums[i] - nums[j]) <= t \uff0c\u540c\u65f6\u53c8\u6ee1\u8db3 abs(i - j) <= k \u3002

    \n\n

    \u5982\u679c\u5b58\u5728\u5219\u8fd4\u56de true\uff0c\u4e0d\u5b58\u5728\u8fd4\u56de false\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\u00a01\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,3,1], k = 3, t = 0\n\u8f93\u51fa\uff1atrue
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,0,1,1], k = 1, t = 2\n\u8f93\u51fa\uff1atrue
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,5,9,1,5,9], k = 2, t = 3\n\u8f93\u51fa\uff1afalse
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= nums.length <= 2 * 104
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n\t
    • 0 <= k <= 104
    • \n\t
    • 0 <= t <= 231 - 1
    • \n
    \n", "tags_en": ["Sort", "Ordered Map"], "tags_cn": ["\u6392\u5e8f"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector& nums, int k, int t) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean containsNearbyAlmostDuplicate(int[] nums, int k, int t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def containsNearbyAlmostDuplicate(self, nums, k, t):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :type t: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def containsNearbyAlmostDuplicate(self, nums: List[int], k: int, t: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool containsNearbyAlmostDuplicate(int* nums, int numsSize, int k, int t){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool ContainsNearbyAlmostDuplicate(int[] nums, int k, int t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @param {number} t\n * @return {boolean}\n */\nvar containsNearbyAlmostDuplicate = function(nums, k, t) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @param {Integer} t\n# @return {Boolean}\ndef contains_nearby_almost_duplicate(nums, k, t)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func containsNearbyAlmostDuplicate(_ nums: [Int], _ k: Int, _ t: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func containsNearbyAlmostDuplicate(nums []int, k int, t int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def containsNearbyAlmostDuplicate(nums: Array[Int], k: Int, t: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun containsNearbyAlmostDuplicate(nums: IntArray, k: Int, t: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn contains_nearby_almost_duplicate(nums: Vec, k: i32, t: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @param Integer $t\n * @return Boolean\n */\n function containsNearbyAlmostDuplicate($nums, $k, $t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function containsNearbyAlmostDuplicate(nums: number[], k: number, t: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (contains-nearby-almost-duplicate nums k t)\n (-> (listof exact-integer?) exact-integer? exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0220](https://leetcode-cn.com/problems/contains-duplicate-iii)", "[\u5b58\u5728\u91cd\u590d\u5143\u7d20 III](/solution/0200-0299/0220.Contains%20Duplicate%20III/README.md)", "`\u6392\u5e8f`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0220](https://leetcode.com/problems/contains-duplicate-iii)", "[Contains Duplicate III](/solution/0200-0299/0220.Contains%20Duplicate%20III/README_EN.md)", "`Sort`,`Ordered Map`", "Medium", ""]}, {"question_id": "0219", "frontend_question_id": "0219", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/contains-duplicate-ii", "url_en": "https://leetcode.com/problems/contains-duplicate-ii", "relative_path_cn": "/solution/0200-0299/0219.Contains%20Duplicate%20II/README.md", "relative_path_en": "/solution/0200-0299/0219.Contains%20Duplicate%20II/README_EN.md", "title_cn": "\u5b58\u5728\u91cd\u590d\u5143\u7d20 II", "title_en": "Contains Duplicate II", "question_title_slug": "contains-duplicate-ii", "content_en": "

    Given an integer array nums and an integer k, return true if there are two distinct indices i and j in the array such that nums[i] == nums[j] and abs(i - j) <= k.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,3,1], k = 3\nOutput: true\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,0,1,1], k = 1\nOutput: true\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [1,2,3,1,2,3], k = 2\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • -109 <= nums[i] <= 109
    • \n\t
    • 0 <= k <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u548c\u4e00\u4e2a\u6574\u6570 k\uff0c\u5224\u65ad\u6570\u7ec4\u4e2d\u662f\u5426\u5b58\u5728\u4e24\u4e2a\u4e0d\u540c\u7684\u7d22\u5f15 i \u548c j\uff0c\u4f7f\u5f97 nums [i] = nums [j]\uff0c\u5e76\u4e14 i \u548c j \u7684\u5dee\u7684 \u7edd\u5bf9\u503c \u81f3\u591a\u4e3a k\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: nums = [1,2,3,1], k = 3\n\u8f93\u51fa: true
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: nums = [1,0,1,1], k = 1\n\u8f93\u51fa: true
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u8f93\u5165: nums = [1,2,3,1,2,3], k = 2\n\u8f93\u51fa: false
    \n", "tags_en": ["Array", "Hash Table"], "tags_cn": ["\u6570\u7ec4", "\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool containsNearbyDuplicate(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean containsNearbyDuplicate(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def containsNearbyDuplicate(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def containsNearbyDuplicate(self, nums: List[int], k: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool containsNearbyDuplicate(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool ContainsNearbyDuplicate(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {boolean}\n */\nvar containsNearbyDuplicate = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Boolean}\ndef contains_nearby_duplicate(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func containsNearbyDuplicate(_ nums: [Int], _ k: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func containsNearbyDuplicate(nums []int, k int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def containsNearbyDuplicate(nums: Array[Int], k: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun containsNearbyDuplicate(nums: IntArray, k: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn contains_nearby_duplicate(nums: Vec, k: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Boolean\n */\n function containsNearbyDuplicate($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function containsNearbyDuplicate(nums: number[], k: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (contains-nearby-duplicate nums k)\n (-> (listof exact-integer?) exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0219](https://leetcode-cn.com/problems/contains-duplicate-ii)", "[\u5b58\u5728\u91cd\u590d\u5143\u7d20 II](/solution/0200-0299/0219.Contains%20Duplicate%20II/README.md)", "`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0219](https://leetcode.com/problems/contains-duplicate-ii)", "[Contains Duplicate II](/solution/0200-0299/0219.Contains%20Duplicate%20II/README_EN.md)", "`Array`,`Hash Table`", "Easy", ""]}, {"question_id": "0218", "frontend_question_id": "0218", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/the-skyline-problem", "url_en": "https://leetcode.com/problems/the-skyline-problem", "relative_path_cn": "/solution/0200-0299/0218.The%20Skyline%20Problem/README.md", "relative_path_en": "/solution/0200-0299/0218.The%20Skyline%20Problem/README_EN.md", "title_cn": "\u5929\u9645\u7ebf\u95ee\u9898", "title_en": "The Skyline Problem", "question_title_slug": "the-skyline-problem", "content_en": "

    A city's skyline is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return the skyline formed by these buildings collectively.

    \n\n

    The geometric information of each building is given in the array buildings where buildings[i] = [lefti, righti, heighti]:

    \n\n
      \n\t
    • lefti is the x coordinate of the left edge of the ith building.
    • \n\t
    • righti is the x coordinate of the right edge of the ith building.
    • \n\t
    • heighti is the height of the ith building.
    • \n
    \n\n

    You may assume all buildings are perfect rectangles grounded on an absolutely flat surface at height 0.

    \n\n

    The skyline should be represented as a list of "key points" sorted by their x-coordinate in the form [[x1,y1],[x2,y2],...]. Each key point is the left endpoint of some horizontal segment in the skyline except the last point in the list, which always has a y-coordinate 0 and is used to mark the skyline's termination where the rightmost building ends. Any ground between the leftmost and rightmost buildings should be part of the skyline's contour.

    \n\n

    Note: There must be no consecutive horizontal lines of equal height in the output skyline. For instance, [...,[2 3],[4 5],[7 5],[11 5],[12 7],...] is not acceptable; the three lines of height 5 should be merged into one in the final output as such: [...,[2 3],[4 5],[12 7],...]

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: buildings = [[2,9,10],[3,7,15],[5,12,12],[15,20,10],[19,24,8]]\nOutput: [[2,10],[3,15],[7,12],[12,0],[15,10],[20,8],[24,0]]\nExplanation:\nFigure A shows the buildings of the input.\nFigure B shows the skyline formed by those buildings. The red points in figure B represent the key points in the output list.\n
    \n\n

    Example 2:

    \n\n
    \nInput: buildings = [[0,2,3],[2,5,3]]\nOutput: [[0,3],[5,0]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= buildings.length <= 104
    • \n\t
    • 0 <= lefti < righti <= 231 - 1
    • \n\t
    • 1 <= heighti <= 231 - 1
    • \n\t
    • buildings is sorted by lefti in non-decreasing order.
    • \n
    \n", "content_cn": "

    \u57ce\u5e02\u7684\u5929\u9645\u7ebf\u662f\u4ece\u8fdc\u5904\u89c2\u770b\u8be5\u57ce\u5e02\u4e2d\u6240\u6709\u5efa\u7b51\u7269\u5f62\u6210\u7684\u8f6e\u5ed3\u7684\u5916\u90e8\u8f6e\u5ed3\u3002\u7ed9\u4f60\u6240\u6709\u5efa\u7b51\u7269\u7684\u4f4d\u7f6e\u548c\u9ad8\u5ea6\uff0c\u8bf7\u8fd4\u56de\u7531\u8fd9\u4e9b\u5efa\u7b51\u7269\u5f62\u6210\u7684 \u5929\u9645\u7ebf \u3002

    \n\n

    \u6bcf\u4e2a\u5efa\u7b51\u7269\u7684\u51e0\u4f55\u4fe1\u606f\u7531\u6570\u7ec4 buildings \u8868\u793a\uff0c\u5176\u4e2d\u4e09\u5143\u7ec4 buildings[i] = [lefti, righti, heighti] \u8868\u793a\uff1a

    \n\n
      \n\t
    • lefti \u662f\u7b2c i \u5ea7\u5efa\u7b51\u7269\u5de6\u8fb9\u7f18\u7684 x \u5750\u6807\u3002
    • \n\t
    • righti \u662f\u7b2c i \u5ea7\u5efa\u7b51\u7269\u53f3\u8fb9\u7f18\u7684 x \u5750\u6807\u3002
    • \n\t
    • heighti \u662f\u7b2c i \u5ea7\u5efa\u7b51\u7269\u7684\u9ad8\u5ea6\u3002
    • \n
    \n\n

    \u5929\u9645\u7ebf \u5e94\u8be5\u8868\u793a\u4e3a\u7531 \u201c\u5173\u952e\u70b9\u201d \u7ec4\u6210\u7684\u5217\u8868\uff0c\u683c\u5f0f [[x1,y1],[x2,y2],...] \uff0c\u5e76\u6309 x \u5750\u6807 \u8fdb\u884c \u6392\u5e8f \u3002\u5173\u952e\u70b9\u662f\u6c34\u5e73\u7ebf\u6bb5\u7684\u5de6\u7aef\u70b9\u3002\u5217\u8868\u4e2d\u6700\u540e\u4e00\u4e2a\u70b9\u662f\u6700\u53f3\u4fa7\u5efa\u7b51\u7269\u7684\u7ec8\u70b9\uff0cy \u5750\u6807\u59cb\u7ec8\u4e3a 0 \uff0c\u4ec5\u7528\u4e8e\u6807\u8bb0\u5929\u9645\u7ebf\u7684\u7ec8\u70b9\u3002\u6b64\u5916\uff0c\u4efb\u4f55\u4e24\u4e2a\u76f8\u90bb\u5efa\u7b51\u7269\u4e4b\u95f4\u7684\u5730\u9762\u90fd\u5e94\u88ab\u89c6\u4e3a\u5929\u9645\u7ebf\u8f6e\u5ed3\u7684\u4e00\u90e8\u5206\u3002

    \n\n

    \u6ce8\u610f\uff1a\u8f93\u51fa\u5929\u9645\u7ebf\u4e2d\u4e0d\u5f97\u6709\u8fde\u7eed\u7684\u76f8\u540c\u9ad8\u5ea6\u7684\u6c34\u5e73\u7ebf\u3002\u4f8b\u5982 [...[2 3], [4 5], [7 5], [11 5], [12 7]...] \u662f\u4e0d\u6b63\u786e\u7684\u7b54\u6848\uff1b\u4e09\u6761\u9ad8\u5ea6\u4e3a 5 \u7684\u7ebf\u5e94\u8be5\u5728\u6700\u7ec8\u8f93\u51fa\u4e2d\u5408\u5e76\u4e3a\u4e00\u4e2a\uff1a[...[2 3], [4 5], [12 7], ...]

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1abuildings = [[2,9,10],[3,7,15],[5,12,12],[15,20,10],[19,24,8]]\n\u8f93\u51fa\uff1a[[2,10],[3,15],[7,12],[12,0],[15,10],[20,8],[24,0]]\n\u89e3\u91ca\uff1a\n\u56fe A \u663e\u793a\u8f93\u5165\u7684\u6240\u6709\u5efa\u7b51\u7269\u7684\u4f4d\u7f6e\u548c\u9ad8\u5ea6\uff0c\n\u56fe B \u663e\u793a\u7531\u8fd9\u4e9b\u5efa\u7b51\u7269\u5f62\u6210\u7684\u5929\u9645\u7ebf\u3002\u56fe B \u4e2d\u7684\u7ea2\u70b9\u8868\u793a\u8f93\u51fa\u5217\u8868\u4e2d\u7684\u5173\u952e\u70b9\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1abuildings = [[0,2,3],[2,5,3]]\n\u8f93\u51fa\uff1a[[0,3],[5,0]]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= buildings.length <= 104
    • \n\t
    • 0 <= lefti < righti <= 231 - 1
    • \n\t
    • 1 <= heighti <= 231 - 1
    • \n\t
    • buildings \u6309 lefti \u975e\u9012\u51cf\u6392\u5e8f
    • \n
    \n", "tags_en": ["Heap", "Binary Indexed Tree", "Segment Tree", "Divide and Conquer", "Line Sweep"], "tags_cn": ["\u5806", "\u6811\u72b6\u6570\u7ec4", "\u7ebf\u6bb5\u6811", "\u5206\u6cbb\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> getSkyline(vector>& buildings) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> getSkyline(int[][] buildings) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getSkyline(self, buildings):\n \"\"\"\n :type buildings: List[List[int]]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getSkyline(self, buildings: List[List[int]]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** getSkyline(int** buildings, int buildingsSize, int* buildingsColSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> GetSkyline(int[][] buildings) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} buildings\n * @return {number[][]}\n */\nvar getSkyline = function(buildings) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} buildings\n# @return {Integer[][]}\ndef get_skyline(buildings)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getSkyline(_ buildings: [[Int]]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getSkyline(buildings [][]int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getSkyline(buildings: Array[Array[Int]]): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getSkyline(buildings: Array): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_skyline(buildings: Vec>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $buildings\n * @return Integer[][]\n */\n function getSkyline($buildings) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getSkyline(buildings: number[][]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-skyline buildings)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0218](https://leetcode-cn.com/problems/the-skyline-problem)", "[\u5929\u9645\u7ebf\u95ee\u9898](/solution/0200-0299/0218.The%20Skyline%20Problem/README.md)", "`\u5806`,`\u6811\u72b6\u6570\u7ec4`,`\u7ebf\u6bb5\u6811`,`\u5206\u6cbb\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[0218](https://leetcode.com/problems/the-skyline-problem)", "[The Skyline Problem](/solution/0200-0299/0218.The%20Skyline%20Problem/README_EN.md)", "`Heap`,`Binary Indexed Tree`,`Segment Tree`,`Divide and Conquer`,`Line Sweep`", "Hard", ""]}, {"question_id": "0217", "frontend_question_id": "0217", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/contains-duplicate", "url_en": "https://leetcode.com/problems/contains-duplicate", "relative_path_cn": "/solution/0200-0299/0217.Contains%20Duplicate/README.md", "relative_path_en": "/solution/0200-0299/0217.Contains%20Duplicate/README_EN.md", "title_cn": "\u5b58\u5728\u91cd\u590d\u5143\u7d20", "title_en": "Contains Duplicate", "question_title_slug": "contains-duplicate", "content_en": "

    Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [1,2,3,1]\nOutput: true\n

    Example 2:

    \n
    Input: nums = [1,2,3,4]\nOutput: false\n

    Example 3:

    \n
    Input: nums = [1,1,1,3,3,4,3,2,4,2]\nOutput: true\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • -109 <= nums[i] <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\uff0c\u5224\u65ad\u662f\u5426\u5b58\u5728\u91cd\u590d\u5143\u7d20\u3002

    \n\n

    \u5982\u679c\u5b58\u5728\u4e00\u503c\u5728\u6570\u7ec4\u4e2d\u51fa\u73b0\u81f3\u5c11\u4e24\u6b21\uff0c\u51fd\u6570\u8fd4\u56de true \u3002\u5982\u679c\u6570\u7ec4\u4e2d\u6bcf\u4e2a\u5143\u7d20\u90fd\u4e0d\u76f8\u540c\uff0c\u5219\u8fd4\u56de false \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: [1,2,3,1]\n\u8f93\u51fa: true
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: [1,2,3,4]\n\u8f93\u51fa: false
    \n\n

    \u793a\u4f8b\u00a03:

    \n\n
    \n\u8f93\u5165: [1,1,1,3,3,4,3,2,4,2]\n\u8f93\u51fa: true
    \n", "tags_en": ["Array", "Hash Table"], "tags_cn": ["\u6570\u7ec4", "\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool containsDuplicate(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean containsDuplicate(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def containsDuplicate(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def containsDuplicate(self, nums: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool containsDuplicate(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool ContainsDuplicate(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {boolean}\n */\nvar containsDuplicate = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Boolean}\ndef contains_duplicate(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func containsDuplicate(_ nums: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func containsDuplicate(nums []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def containsDuplicate(nums: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun containsDuplicate(nums: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn contains_duplicate(nums: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Boolean\n */\n function containsDuplicate($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function containsDuplicate(nums: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (contains-duplicate nums)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0217](https://leetcode-cn.com/problems/contains-duplicate)", "[\u5b58\u5728\u91cd\u590d\u5143\u7d20](/solution/0200-0299/0217.Contains%20Duplicate/README.md)", "`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0217](https://leetcode.com/problems/contains-duplicate)", "[Contains Duplicate](/solution/0200-0299/0217.Contains%20Duplicate/README_EN.md)", "`Array`,`Hash Table`", "Easy", ""]}, {"question_id": "0216", "frontend_question_id": "0216", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/combination-sum-iii", "url_en": "https://leetcode.com/problems/combination-sum-iii", "relative_path_cn": "/solution/0200-0299/0216.Combination%20Sum%20III/README.md", "relative_path_en": "/solution/0200-0299/0216.Combination%20Sum%20III/README_EN.md", "title_cn": "\u7ec4\u5408\u603b\u548c III", "title_en": "Combination Sum III", "question_title_slug": "combination-sum-iii", "content_en": "

    Find all valid combinations of k numbers that sum up to n such that the following conditions are true:

    \n\n
      \n\t
    • Only numbers 1 through 9 are used.
    • \n\t
    • Each number is used at most once.
    • \n
    \n\n

    Return a list of all possible valid combinations. The list must not contain the same combination twice, and the combinations may be returned in any order.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: k = 3, n = 7\nOutput: [[1,2,4]]\nExplanation:\n1 + 2 + 4 = 7\nThere are no other valid combinations.
    \n\n

    Example 2:

    \n\n
    \nInput: k = 3, n = 9\nOutput: [[1,2,6],[1,3,5],[2,3,4]]\nExplanation:\n1 + 2 + 6 = 9\n1 + 3 + 5 = 9\n2 + 3 + 4 = 9\nThere are no other valid combinations.\n
    \n\n

    Example 3:

    \n\n
    \nInput: k = 4, n = 1\nOutput: []\nExplanation: There are no valid combinations. [1,2,1] is not valid because 1 is used twice.\n
    \n\n

    Example 4:

    \n\n
    \nInput: k = 3, n = 2\nOutput: []\nExplanation: There are no valid combinations.\n
    \n\n

    Example 5:

    \n\n
    \nInput: k = 9, n = 45\nOutput: [[1,2,3,4,5,6,7,8,9]]\nExplanation:\n1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 = 45\n\u200b\u200b\u200b\u200b\u200b\u200b\u200bThere are no other valid combinations.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= k <= 9
    • \n\t
    • 1 <= n <= 60
    • \n
    \n", "content_cn": "

    \u627e\u51fa\u6240\u6709\u76f8\u52a0\u4e4b\u548c\u4e3a n \u7684 \u4e2a\u6570\u7684\u7ec4\u5408\u3002\u7ec4\u5408\u4e2d\u53ea\u5141\u8bb8\u542b\u6709 1 - 9 \u7684\u6b63\u6574\u6570\uff0c\u5e76\u4e14\u6bcf\u79cd\u7ec4\u5408\u4e2d\u4e0d\u5b58\u5728\u91cd\u590d\u7684\u6570\u5b57\u3002

    \n\n

    \u8bf4\u660e\uff1a

    \n\n
      \n\t
    • \u6240\u6709\u6570\u5b57\u90fd\u662f\u6b63\u6574\u6570\u3002
    • \n\t
    • \u89e3\u96c6\u4e0d\u80fd\u5305\u542b\u91cd\u590d\u7684\u7ec4\u5408\u3002 
    • \n
    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: k = 3, n = 7\n\u8f93\u51fa: [[1,2,4]]\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: k = 3, n = 9\n\u8f93\u51fa: [[1,2,6], [1,3,5], [2,3,4]]\n
    \n", "tags_en": ["Array", "Backtracking"], "tags_cn": ["\u6570\u7ec4", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> combinationSum3(int k, int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> combinationSum3(int k, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def combinationSum3(self, k, n):\n \"\"\"\n :type k: int\n :type n: int\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def combinationSum3(self, k: int, n: int) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** combinationSum3(int k, int n, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> CombinationSum3(int k, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} k\n * @param {number} n\n * @return {number[][]}\n */\nvar combinationSum3 = function(k, n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} k\n# @param {Integer} n\n# @return {Integer[][]}\ndef combination_sum3(k, n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func combinationSum3(_ k: Int, _ n: Int) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func combinationSum3(k int, n int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def combinationSum3(k: Int, n: Int): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun combinationSum3(k: Int, n: Int): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn combination_sum3(k: i32, n: i32) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $k\n * @param Integer $n\n * @return Integer[][]\n */\n function combinationSum3($k, $n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function combinationSum3(k: number, n: number): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (combination-sum3 k n)\n (-> exact-integer? exact-integer? (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0216](https://leetcode-cn.com/problems/combination-sum-iii)", "[\u7ec4\u5408\u603b\u548c III](/solution/0200-0299/0216.Combination%20Sum%20III/README.md)", "`\u6570\u7ec4`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0216](https://leetcode.com/problems/combination-sum-iii)", "[Combination Sum III](/solution/0200-0299/0216.Combination%20Sum%20III/README_EN.md)", "`Array`,`Backtracking`", "Medium", ""]}, {"question_id": "0215", "frontend_question_id": "0215", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/kth-largest-element-in-an-array", "url_en": "https://leetcode.com/problems/kth-largest-element-in-an-array", "relative_path_cn": "/solution/0200-0299/0215.Kth%20Largest%20Element%20in%20an%20Array/README.md", "relative_path_en": "/solution/0200-0299/0215.Kth%20Largest%20Element%20in%20an%20Array/README_EN.md", "title_cn": "\u6570\u7ec4\u4e2d\u7684\u7b2cK\u4e2a\u6700\u5927\u5143\u7d20", "title_en": "Kth Largest Element in an Array", "question_title_slug": "kth-largest-element-in-an-array", "content_en": "

    Given an integer array nums and an integer k, return the kth largest element in the array.

    \n\n

    Note that it is the kth largest element in the sorted order, not the kth distinct element.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [3,2,1,5,6,4], k = 2\nOutput: 5\n

    Example 2:

    \n
    Input: nums = [3,2,3,1,2,4,5,5,6], k = 4\nOutput: 4\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= k <= nums.length <= 104
    • \n\t
    • -104 <= nums[i] <= 104
    • \n
    \n", "content_cn": "

    \u5728\u672a\u6392\u5e8f\u7684\u6570\u7ec4\u4e2d\u627e\u5230\u7b2c k \u4e2a\u6700\u5927\u7684\u5143\u7d20\u3002\u8bf7\u6ce8\u610f\uff0c\u4f60\u9700\u8981\u627e\u7684\u662f\u6570\u7ec4\u6392\u5e8f\u540e\u7684\u7b2c k \u4e2a\u6700\u5927\u7684\u5143\u7d20\uff0c\u800c\u4e0d\u662f\u7b2c k \u4e2a\u4e0d\u540c\u7684\u5143\u7d20\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: [3,2,1,5,6,4] \u548c k = 2\n\u8f93\u51fa: 5\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: [3,2,3,1,2,4,5,5,6] \u548c k = 4\n\u8f93\u51fa: 4
    \n\n

    \u8bf4\u660e:

    \n\n

    \u4f60\u53ef\u4ee5\u5047\u8bbe k \u603b\u662f\u6709\u6548\u7684\uff0c\u4e14 1 ≤ k ≤ \u6570\u7ec4\u7684\u957f\u5ea6\u3002

    \n", "tags_en": ["Heap", "Divide and Conquer"], "tags_cn": ["\u5806", "\u5206\u6cbb\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findKthLargest(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findKthLargest(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findKthLargest(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findKthLargest(self, nums: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findKthLargest(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindKthLargest(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar findKthLargest = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef find_kth_largest(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findKthLargest(_ nums: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findKthLargest(nums []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findKthLargest(nums: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findKthLargest(nums: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_kth_largest(nums: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer\n */\n function findKthLargest($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findKthLargest(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-kth-largest nums k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0215](https://leetcode-cn.com/problems/kth-largest-element-in-an-array)", "[\u6570\u7ec4\u4e2d\u7684\u7b2cK\u4e2a\u6700\u5927\u5143\u7d20](/solution/0200-0299/0215.Kth%20Largest%20Element%20in%20an%20Array/README.md)", "`\u5806`,`\u5206\u6cbb\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0215](https://leetcode.com/problems/kth-largest-element-in-an-array)", "[Kth Largest Element in an Array](/solution/0200-0299/0215.Kth%20Largest%20Element%20in%20an%20Array/README_EN.md)", "`Heap`,`Divide and Conquer`", "Medium", ""]}, {"question_id": "0214", "frontend_question_id": "0214", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/shortest-palindrome", "url_en": "https://leetcode.com/problems/shortest-palindrome", "relative_path_cn": "/solution/0200-0299/0214.Shortest%20Palindrome/README.md", "relative_path_en": "/solution/0200-0299/0214.Shortest%20Palindrome/README_EN.md", "title_cn": "\u6700\u77ed\u56de\u6587\u4e32", "title_en": "Shortest Palindrome", "question_title_slug": "shortest-palindrome", "content_en": "

    You are given a string s. You can convert s to a palindrome by adding characters in front of it.

    \n\n

    Return the shortest palindrome you can find by performing this transformation.

    \n\n

     

    \n

    Example 1:

    \n
    Input: s = \"aacecaaa\"\nOutput: \"aaacecaaa\"\n

    Example 2:

    \n
    Input: s = \"abcd\"\nOutput: \"dcbabcd\"\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= s.length <= 5 * 104
    • \n\t
    • s consists of lowercase English letters only.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32 s\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u5728\u5b57\u7b26\u4e32\u524d\u9762\u6dfb\u52a0\u5b57\u7b26\u5c06\u5176\u8f6c\u6362\u4e3a\u56de\u6587\u4e32\u3002\u627e\u5230\u5e76\u8fd4\u56de\u53ef\u4ee5\u7528\u8fd9\u79cd\u65b9\u5f0f\u8f6c\u6362\u7684\u6700\u77ed\u56de\u6587\u4e32\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"aacecaaa\"\n\u8f93\u51fa\uff1a\"aaacecaaa\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"abcd\"\n\u8f93\u51fa\uff1a\"dcbabcd\"\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= s.length <= 5 * 104
    • \n\t
    • s \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string shortestPalindrome(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String shortestPalindrome(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def shortestPalindrome(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def shortestPalindrome(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * shortestPalindrome(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ShortestPalindrome(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar shortestPalindrome = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef shortest_palindrome(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func shortestPalindrome(_ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func shortestPalindrome(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def shortestPalindrome(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun shortestPalindrome(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn shortest_palindrome(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function shortestPalindrome($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function shortestPalindrome(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (shortest-palindrome s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0214](https://leetcode-cn.com/problems/shortest-palindrome)", "[\u6700\u77ed\u56de\u6587\u4e32](/solution/0200-0299/0214.Shortest%20Palindrome/README.md)", "`\u5b57\u7b26\u4e32`", "\u56f0\u96be", ""], "md_table_row_en": ["[0214](https://leetcode.com/problems/shortest-palindrome)", "[Shortest Palindrome](/solution/0200-0299/0214.Shortest%20Palindrome/README_EN.md)", "`String`", "Hard", ""]}, {"question_id": "0213", "frontend_question_id": "0213", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/house-robber-ii", "url_en": "https://leetcode.com/problems/house-robber-ii", "relative_path_cn": "/solution/0200-0299/0213.House%20Robber%20II/README.md", "relative_path_en": "/solution/0200-0299/0213.House%20Robber%20II/README_EN.md", "title_cn": "\u6253\u5bb6\u52ab\u820d II", "title_en": "House Robber II", "question_title_slug": "house-robber-ii", "content_en": "

    You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place are arranged in a circle. That means the first house is the neighbor of the last one. Meanwhile, adjacent houses have a security system connected, and it will automatically contact the police if two adjacent houses were broken into on the same night.

    \n\n

    Given an integer array nums representing the amount of money of each house, return the maximum amount of money you can rob tonight without alerting the police.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [2,3,2]\nOutput: 3\nExplanation: You cannot rob house 1 (money = 2) and then rob house 3 (money = 2), because they are adjacent houses.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,2,3,1]\nOutput: 4\nExplanation: Rob house 1 (money = 1) and then rob house 3 (money = 3).\nTotal amount you can rob = 1 + 3 = 4.\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [0]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 100
    • \n\t
    • 0 <= nums[i] <= 1000
    • \n
    \n", "content_cn": "

    \u4f60\u662f\u4e00\u4e2a\u4e13\u4e1a\u7684\u5c0f\u5077\uff0c\u8ba1\u5212\u5077\u7a83\u6cbf\u8857\u7684\u623f\u5c4b\uff0c\u6bcf\u95f4\u623f\u5185\u90fd\u85cf\u6709\u4e00\u5b9a\u7684\u73b0\u91d1\u3002\u8fd9\u4e2a\u5730\u65b9\u6240\u6709\u7684\u623f\u5c4b\u90fd \u56f4\u6210\u4e00\u5708 \uff0c\u8fd9\u610f\u5473\u7740\u7b2c\u4e00\u4e2a\u623f\u5c4b\u548c\u6700\u540e\u4e00\u4e2a\u623f\u5c4b\u662f\u7d27\u6328\u7740\u7684\u3002\u540c\u65f6\uff0c\u76f8\u90bb\u7684\u623f\u5c4b\u88c5\u6709\u76f8\u4e92\u8fde\u901a\u7684\u9632\u76d7\u7cfb\u7edf\uff0c\u5982\u679c\u4e24\u95f4\u76f8\u90bb\u7684\u623f\u5c4b\u5728\u540c\u4e00\u665a\u4e0a\u88ab\u5c0f\u5077\u95ef\u5165\uff0c\u7cfb\u7edf\u4f1a\u81ea\u52a8\u62a5\u8b66 \u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u4ee3\u8868\u6bcf\u4e2a\u623f\u5c4b\u5b58\u653e\u91d1\u989d\u7684\u975e\u8d1f\u6574\u6570\u6570\u7ec4\uff0c\u8ba1\u7b97\u4f60 \u5728\u4e0d\u89e6\u52a8\u8b66\u62a5\u88c5\u7f6e\u7684\u60c5\u51b5\u4e0b \uff0c\u4eca\u665a\u80fd\u591f\u5077\u7a83\u5230\u7684\u6700\u9ad8\u91d1\u989d\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\u00a01\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [2,3,2]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u4f60\u4e0d\u80fd\u5148\u5077\u7a83 1 \u53f7\u623f\u5c4b\uff08\u91d1\u989d = 2\uff09\uff0c\u7136\u540e\u5077\u7a83 3 \u53f7\u623f\u5c4b\uff08\u91d1\u989d = 2\uff09, \u56e0\u4e3a\u4ed6\u4eec\u662f\u76f8\u90bb\u7684\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,3,1]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u5148\u5077\u7a83 1 \u53f7\u623f\u5c4b\uff08\u91d1\u989d = 1\uff09\uff0c\u7136\u540e\u5077\u7a83 3 \u53f7\u623f\u5c4b\uff08\u91d1\u989d = 3\uff09\u3002\n\u00a0    \u5077\u7a83\u5230\u7684\u6700\u9ad8\u91d1\u989d = 1 + 3 = 4 \u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [0]\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 100
    • \n\t
    • 0 <= nums[i] <= 1000
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int rob(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int rob(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def rob(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def rob(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint rob(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int Rob(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar rob = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef rob(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func rob(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func rob(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def rob(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun rob(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn rob(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function rob($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function rob(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (rob nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0213](https://leetcode-cn.com/problems/house-robber-ii)", "[\u6253\u5bb6\u52ab\u820d II](/solution/0200-0299/0213.House%20Robber%20II/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0213](https://leetcode.com/problems/house-robber-ii)", "[House Robber II](/solution/0200-0299/0213.House%20Robber%20II/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0212", "frontend_question_id": "0212", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/word-search-ii", "url_en": "https://leetcode.com/problems/word-search-ii", "relative_path_cn": "/solution/0200-0299/0212.Word%20Search%20II/README.md", "relative_path_en": "/solution/0200-0299/0212.Word%20Search%20II/README_EN.md", "title_cn": "\u5355\u8bcd\u641c\u7d22 II", "title_en": "Word Search II", "question_title_slug": "word-search-ii", "content_en": "

    Given an m x n board of characters and a list of strings words, return all words on the board.

    \n\n

    Each word must be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically neighboring. The same letter cell may not be used more than once in a word.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: board = [["o","a","a","n"],["e","t","a","e"],["i","h","k","r"],["i","f","l","v"]], words = ["oath","pea","eat","rain"]\nOutput: ["eat","oath"]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: board = [["a","b"],["c","d"]], words = ["abcb"]\nOutput: []\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == board.length
    • \n\t
    • n == board[i].length
    • \n\t
    • 1 <= m, n <= 12
    • \n\t
    • board[i][j] is a lowercase English letter.
    • \n\t
    • 1 <= words.length <= 3 * 104
    • \n\t
    • 1 <= words[i].length <= 10
    • \n\t
    • words[i] consists of lowercase English letters.
    • \n\t
    • All the strings of words are unique.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u00a0m x n \u4e8c\u7ef4\u5b57\u7b26\u7f51\u683c\u00a0board\u00a0\u548c\u4e00\u4e2a\u5355\u8bcd\uff08\u5b57\u7b26\u4e32\uff09\u5217\u8868 words\uff0c\u627e\u51fa\u6240\u6709\u540c\u65f6\u5728\u4e8c\u7ef4\u7f51\u683c\u548c\u5b57\u5178\u4e2d\u51fa\u73b0\u7684\u5355\u8bcd\u3002

    \n\n

    \u5355\u8bcd\u5fc5\u987b\u6309\u7167\u5b57\u6bcd\u987a\u5e8f\uff0c\u901a\u8fc7 \u76f8\u90bb\u7684\u5355\u5143\u683c \u5185\u7684\u5b57\u6bcd\u6784\u6210\uff0c\u5176\u4e2d\u201c\u76f8\u90bb\u201d\u5355\u5143\u683c\u662f\u90a3\u4e9b\u6c34\u5e73\u76f8\u90bb\u6216\u5782\u76f4\u76f8\u90bb\u7684\u5355\u5143\u683c\u3002\u540c\u4e00\u4e2a\u5355\u5143\u683c\u5185\u7684\u5b57\u6bcd\u5728\u4e00\u4e2a\u5355\u8bcd\u4e2d\u4e0d\u5141\u8bb8\u88ab\u91cd\u590d\u4f7f\u7528\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aboard = [[\"o\",\"a\",\"a\",\"n\"],[\"e\",\"t\",\"a\",\"e\"],[\"i\",\"h\",\"k\",\"r\"],[\"i\",\"f\",\"l\",\"v\"]], words = [\"oath\",\"pea\",\"eat\",\"rain\"]\n\u8f93\u51fa\uff1a[\"eat\",\"oath\"]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aboard = [[\"a\",\"b\"],[\"c\",\"d\"]], words = [\"abcb\"]\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == board.length
    • \n\t
    • n == board[i].length
    • \n\t
    • 1 <= m, n <= 12
    • \n\t
    • board[i][j] \u662f\u4e00\u4e2a\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd
    • \n\t
    • 1 <= words.length <= 3 * 104
    • \n\t
    • 1 <= words[i].length <= 10
    • \n\t
    • words[i] \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n\t
    • words \u4e2d\u7684\u6240\u6709\u5b57\u7b26\u4e32\u4e92\u4e0d\u76f8\u540c
    • \n
    \n", "tags_en": ["Trie", "Backtracking"], "tags_cn": ["\u5b57\u5178\u6811", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findWords(vector>& board, vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List findWords(char[][] board, String[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findWords(self, board, words):\n \"\"\"\n :type board: List[List[str]]\n :type words: List[str]\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findWords(self, board: List[List[str]], words: List[str]) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** findWords(char** board, int boardSize, int* boardColSize, char ** words, int wordsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList FindWords(char[][] board, string[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {character[][]} board\n * @param {string[]} words\n * @return {string[]}\n */\nvar findWords = function(board, words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Character[][]} board\n# @param {String[]} words\n# @return {String[]}\ndef find_words(board, words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findWords(_ board: [[Character]], _ words: [String]) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findWords(board [][]byte, words []string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findWords(board: Array[Array[Char]], words: Array[String]): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findWords(board: Array, words: Array): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_words(board: Vec>, words: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $board\n * @param String[] $words\n * @return String[]\n */\n function findWords($board, $words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findWords(board: string[][], words: string[]): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-words board words)\n (-> (listof (listof char?)) (listof string?) (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0212](https://leetcode-cn.com/problems/word-search-ii)", "[\u5355\u8bcd\u641c\u7d22 II](/solution/0200-0299/0212.Word%20Search%20II/README.md)", "`\u5b57\u5178\u6811`,`\u56de\u6eaf\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[0212](https://leetcode.com/problems/word-search-ii)", "[Word Search II](/solution/0200-0299/0212.Word%20Search%20II/README_EN.md)", "`Trie`,`Backtracking`", "Hard", ""]}, {"question_id": "0211", "frontend_question_id": "0211", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/design-add-and-search-words-data-structure", "url_en": "https://leetcode.com/problems/design-add-and-search-words-data-structure", "relative_path_cn": "/solution/0200-0299/0211.Design%20Add%20and%20Search%20Words%20Data%20Structure/README.md", "relative_path_en": "/solution/0200-0299/0211.Design%20Add%20and%20Search%20Words%20Data%20Structure/README_EN.md", "title_cn": "\u6dfb\u52a0\u4e0e\u641c\u7d22\u5355\u8bcd - \u6570\u636e\u7ed3\u6784\u8bbe\u8ba1", "title_en": "Design Add and Search Words Data Structure", "question_title_slug": "design-add-and-search-words-data-structure", "content_en": "

    Design a data structure that supports adding new words and finding if a string matches any previously added string.

    \n\n

    Implement the WordDictionary class:

    \n\n
      \n\t
    • WordDictionary() Initializes the object.
    • \n\t
    • void addWord(word) Adds word to the data structure, it can be matched later.
    • \n\t
    • bool search(word) Returns true if there is any string in the data structure that matches word or false otherwise. word may contain dots '.' where dots can be matched with any letter.
    • \n
    \n\n

     

    \n

    Example:

    \n\n
    \nInput\n["WordDictionary","addWord","addWord","addWord","search","search","search","search"]\n[[],["bad"],["dad"],["mad"],["pad"],["bad"],[".ad"],["b.."]]\nOutput\n[null,null,null,null,false,true,true,true]\n\nExplanation\nWordDictionary wordDictionary = new WordDictionary();\nwordDictionary.addWord("bad");\nwordDictionary.addWord("dad");\nwordDictionary.addWord("mad");\nwordDictionary.search("pad"); // return False\nwordDictionary.search("bad"); // return True\nwordDictionary.search(".ad"); // return True\nwordDictionary.search("b.."); // return True\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= word.length <= 500
    • \n\t
    • word in addWord consists lower-case English letters.
    • \n\t
    • word in search consist of  '.' or lower-case English letters.
    • \n\t
    • At most 50000 calls will be made to addWord and search.
    • \n
    \n", "content_cn": "

    \u8bf7\u4f60\u8bbe\u8ba1\u4e00\u4e2a\u6570\u636e\u7ed3\u6784\uff0c\u652f\u6301 \u6dfb\u52a0\u65b0\u5355\u8bcd \u548c \u67e5\u627e\u5b57\u7b26\u4e32\u662f\u5426\u4e0e\u4efb\u4f55\u5148\u524d\u6dfb\u52a0\u7684\u5b57\u7b26\u4e32\u5339\u914d \u3002

    \n\n

    \u5b9e\u73b0\u8bcd\u5178\u7c7b WordDictionary \uff1a

    \n\n
      \n\t
    • WordDictionary() \u521d\u59cb\u5316\u8bcd\u5178\u5bf9\u8c61
    • \n\t
    • void addWord(word) \u5c06 word \u6dfb\u52a0\u5230\u6570\u636e\u7ed3\u6784\u4e2d\uff0c\u4e4b\u540e\u53ef\u4ee5\u5bf9\u5b83\u8fdb\u884c\u5339\u914d
    • \n\t
    • bool search(word) \u5982\u679c\u6570\u636e\u7ed3\u6784\u4e2d\u5b58\u5728\u5b57\u7b26\u4e32\u4e0e\u00a0word \u5339\u914d\uff0c\u5219\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de\u00a0 false \u3002word \u4e2d\u53ef\u80fd\u5305\u542b\u4e00\u4e9b '.' \uff0c\u6bcf\u4e2a\u00a0. \u90fd\u53ef\u4ee5\u8868\u793a\u4efb\u4f55\u4e00\u4e2a\u5b57\u6bcd\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\n[\"WordDictionary\",\"addWord\",\"addWord\",\"addWord\",\"search\",\"search\",\"search\",\"search\"]\n[[],[\"bad\"],[\"dad\"],[\"mad\"],[\"pad\"],[\"bad\"],[\".ad\"],[\"b..\"]]\n\u8f93\u51fa\uff1a\n[null,null,null,null,false,true,true,true]\n\n\u89e3\u91ca\uff1a\nWordDictionary wordDictionary = new WordDictionary();\nwordDictionary.addWord(\"bad\");\nwordDictionary.addWord(\"dad\");\nwordDictionary.addWord(\"mad\");\nwordDictionary.search(\"pad\"); // return False\nwordDictionary.search(\"bad\"); // return True\nwordDictionary.search(\".ad\"); // return True\nwordDictionary.search(\"b..\"); // return True\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= word.length <= 500
    • \n\t
    • addWord \u4e2d\u7684 word \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n\t
    • search \u4e2d\u7684 word \u7531 '.' \u6216\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n\t
    • \u6700\u591a\u8c03\u7528 50000 \u6b21 addWord \u548c search
    • \n
    \n", "tags_en": ["Depth-first Search", "Design", "Trie", "Backtracking"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u8bbe\u8ba1", "\u5b57\u5178\u6811", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class WordDictionary {\npublic:\n /** Initialize your data structure here. */\n WordDictionary() {\n\n }\n \n void addWord(string word) {\n\n }\n \n bool search(string word) {\n\n }\n};\n\n/**\n * Your WordDictionary object will be instantiated and called as such:\n * WordDictionary* obj = new WordDictionary();\n * obj->addWord(word);\n * bool param_2 = obj->search(word);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class WordDictionary {\n\n /** Initialize your data structure here. */\n public WordDictionary() {\n\n }\n \n public void addWord(String word) {\n\n }\n \n public boolean search(String word) {\n\n }\n}\n\n/**\n * Your WordDictionary object will be instantiated and called as such:\n * WordDictionary obj = new WordDictionary();\n * obj.addWord(word);\n * boolean param_2 = obj.search(word);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class WordDictionary(object):\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def addWord(self, word):\n \"\"\"\n :type word: str\n :rtype: None\n \"\"\"\n\n\n def search(self, word):\n \"\"\"\n :type word: str\n :rtype: bool\n \"\"\"\n\n\n\n# Your WordDictionary object will be instantiated and called as such:\n# obj = WordDictionary()\n# obj.addWord(word)\n# param_2 = obj.search(word)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class WordDictionary:\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def addWord(self, word: str) -> None:\n\n\n def search(self, word: str) -> bool:\n\n\n\n# Your WordDictionary object will be instantiated and called as such:\n# obj = WordDictionary()\n# obj.addWord(word)\n# param_2 = obj.search(word)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} WordDictionary;\n\n/** Initialize your data structure here. */\n\nWordDictionary* wordDictionaryCreate() {\n \n}\n\nvoid wordDictionaryAddWord(WordDictionary* obj, char * word) {\n \n}\n\nbool wordDictionarySearch(WordDictionary* obj, char * word) {\n \n}\n\nvoid wordDictionaryFree(WordDictionary* obj) {\n \n}\n\n/**\n * Your WordDictionary struct will be instantiated and called as such:\n * WordDictionary* obj = wordDictionaryCreate();\n * wordDictionaryAddWord(obj, word);\n \n * bool param_2 = wordDictionarySearch(obj, word);\n \n * wordDictionaryFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class WordDictionary {\n\n /** Initialize your data structure here. */\n public WordDictionary() {\n\n }\n \n public void AddWord(string word) {\n\n }\n \n public bool Search(string word) {\n\n }\n}\n\n/**\n * Your WordDictionary object will be instantiated and called as such:\n * WordDictionary obj = new WordDictionary();\n * obj.AddWord(word);\n * bool param_2 = obj.Search(word);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Initialize your data structure here.\n */\nvar WordDictionary = function() {\n\n};\n\n/** \n * @param {string} word\n * @return {void}\n */\nWordDictionary.prototype.addWord = function(word) {\n\n};\n\n/** \n * @param {string} word\n * @return {boolean}\n */\nWordDictionary.prototype.search = function(word) {\n\n};\n\n/**\n * Your WordDictionary object will be instantiated and called as such:\n * var obj = new WordDictionary()\n * obj.addWord(word)\n * var param_2 = obj.search(word)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class WordDictionary\n\n=begin\n Initialize your data structure here.\n=end\n def initialize()\n\n end\n\n\n=begin\n :type word: String\n :rtype: Void\n=end\n def add_word(word)\n\n end\n\n\n=begin\n :type word: String\n :rtype: Boolean\n=end\n def search(word)\n\n end\n\n\nend\n\n# Your WordDictionary object will be instantiated and called as such:\n# obj = WordDictionary.new()\n# obj.add_word(word)\n# param_2 = obj.search(word)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass WordDictionary {\n\n /** Initialize your data structure here. */\n init() {\n\n }\n \n func addWord(_ word: String) {\n\n }\n \n func search(_ word: String) -> Bool {\n\n }\n}\n\n/**\n * Your WordDictionary object will be instantiated and called as such:\n * let obj = WordDictionary()\n * obj.addWord(word)\n * let ret_2: Bool = obj.search(word)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type WordDictionary struct {\n\n}\n\n\n/** Initialize your data structure here. */\nfunc Constructor() WordDictionary {\n\n}\n\n\nfunc (this *WordDictionary) AddWord(word string) {\n\n}\n\n\nfunc (this *WordDictionary) Search(word string) bool {\n\n}\n\n\n/**\n * Your WordDictionary object will be instantiated and called as such:\n * obj := Constructor();\n * obj.AddWord(word);\n * param_2 := obj.Search(word);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class WordDictionary() {\n\n /** Initialize your data structure here. */\n\n\n def addWord(word: String) {\n\n }\n\n def search(word: String): Boolean = {\n\n }\n\n}\n\n/**\n * Your WordDictionary object will be instantiated and called as such:\n * var obj = new WordDictionary()\n * obj.addWord(word)\n * var param_2 = obj.search(word)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class WordDictionary() {\n\n /** Initialize your data structure here. */\n\n\n fun addWord(word: String) {\n\n }\n\n fun search(word: String): Boolean {\n\n }\n\n}\n\n/**\n * Your WordDictionary object will be instantiated and called as such:\n * var obj = WordDictionary()\n * obj.addWord(word)\n * var param_2 = obj.search(word)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct WordDictionary {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl WordDictionary {\n\n /** Initialize your data structure here. */\n fn new() -> Self {\n\n }\n \n fn add_word(&self, word: String) {\n\n }\n \n fn search(&self, word: String) -> bool {\n\n }\n}\n\n/**\n * Your WordDictionary object will be instantiated and called as such:\n * let obj = WordDictionary::new();\n * obj.add_word(word);\n * let ret_2: bool = obj.search(word);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class WordDictionary {\n /**\n * Initialize your data structure here.\n */\n function __construct() {\n\n }\n\n /**\n * @param String $word\n * @return NULL\n */\n function addWord($word) {\n\n }\n\n /**\n * @param String $word\n * @return Boolean\n */\n function search($word) {\n\n }\n}\n\n/**\n * Your WordDictionary object will be instantiated and called as such:\n * $obj = WordDictionary();\n * $obj->addWord($word);\n * $ret_2 = $obj->search($word);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class WordDictionary {\n constructor() {\n\n }\n\n addWord(word: string): void {\n\n }\n\n search(word: string): boolean {\n\n }\n}\n\n/**\n * Your WordDictionary object will be instantiated and called as such:\n * var obj = new WordDictionary()\n * obj.addWord(word)\n * var param_2 = obj.search(word)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define word-dictionary%\n (class object%\n (super-new)\n (init-field)\n \n ; add-word : string? -> void?\n (define/public (add-word word)\n\n )\n ; search : string? -> boolean?\n (define/public (search word)\n\n )))\n\n;; Your word-dictionary% object will be instantiated and called as such:\n;; (define obj (new word-dictionary%))\n;; (send obj add-word word)\n;; (define param_2 (send obj search word))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0211](https://leetcode-cn.com/problems/design-add-and-search-words-data-structure)", "[\u6dfb\u52a0\u4e0e\u641c\u7d22\u5355\u8bcd - \u6570\u636e\u7ed3\u6784\u8bbe\u8ba1](/solution/0200-0299/0211.Design%20Add%20and%20Search%20Words%20Data%20Structure/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u8bbe\u8ba1`,`\u5b57\u5178\u6811`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0211](https://leetcode.com/problems/design-add-and-search-words-data-structure)", "[Design Add and Search Words Data Structure](/solution/0200-0299/0211.Design%20Add%20and%20Search%20Words%20Data%20Structure/README_EN.md)", "`Depth-first Search`,`Design`,`Trie`,`Backtracking`", "Medium", ""]}, {"question_id": "0210", "frontend_question_id": "0210", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/course-schedule-ii", "url_en": "https://leetcode.com/problems/course-schedule-ii", "relative_path_cn": "/solution/0200-0299/0210.Course%20Schedule%20II/README.md", "relative_path_en": "/solution/0200-0299/0210.Course%20Schedule%20II/README_EN.md", "title_cn": "\u8bfe\u7a0b\u8868 II", "title_en": "Course Schedule II", "question_title_slug": "course-schedule-ii", "content_en": "

    There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i] = [ai, bi] indicates that you must take course bi first if you want to take course ai.

    \n\n
      \n\t
    • For example, the pair [0, 1], indicates that to take course 0 you have to first take course 1.
    • \n
    \n\n

    Return the ordering of courses you should take to finish all courses. If there are many valid answers, return any of them. If it is impossible to finish all courses, return an empty array.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: numCourses = 2, prerequisites = [[1,0]]\nOutput: [0,1]\nExplanation: There are a total of 2 courses to take. To take course 1 you should have finished course 0. So the correct course order is [0,1].\n
    \n\n

    Example 2:

    \n\n
    \nInput: numCourses = 4, prerequisites = [[1,0],[2,0],[3,1],[3,2]]\nOutput: [0,2,1,3]\nExplanation: There are a total of 4 courses to take. To take course 3 you should have finished both courses 1 and 2. Both courses 1 and 2 should be taken after you finished course 0.\nSo one correct course order is [0,1,2,3]. Another correct ordering is [0,2,1,3].\n
    \n\n

    Example 3:

    \n\n
    \nInput: numCourses = 1, prerequisites = []\nOutput: [0]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= numCourses <= 2000
    • \n\t
    • 0 <= prerequisites.length <= numCourses * (numCourses - 1)
    • \n\t
    • prerequisites[i].length == 2
    • \n\t
    • 0 <= ai, bi < numCourses
    • \n\t
    • ai != bi
    • \n\t
    • All the pairs [ai, bi] are distinct.
    • \n
    \n", "content_cn": "

    \u73b0\u5728\u4f60\u603b\u5171\u6709 n \u95e8\u8bfe\u9700\u8981\u9009\uff0c\u8bb0\u4e3a 0 \u5230 n-1\u3002

    \n\n

    \u5728\u9009\u4fee\u67d0\u4e9b\u8bfe\u7a0b\u4e4b\u524d\u9700\u8981\u4e00\u4e9b\u5148\u4fee\u8bfe\u7a0b\u3002 \u4f8b\u5982\uff0c\u60f3\u8981\u5b66\u4e60\u8bfe\u7a0b 0 \uff0c\u4f60\u9700\u8981\u5148\u5b8c\u6210\u8bfe\u7a0b 1 \uff0c\u6211\u4eec\u7528\u4e00\u4e2a\u5339\u914d\u6765\u8868\u793a\u4ed6\u4eec: [0,1]

    \n\n

    \u7ed9\u5b9a\u8bfe\u7a0b\u603b\u91cf\u4ee5\u53ca\u5b83\u4eec\u7684\u5148\u51b3\u6761\u4ef6\uff0c\u8fd4\u56de\u4f60\u4e3a\u4e86\u5b66\u5b8c\u6240\u6709\u8bfe\u7a0b\u6240\u5b89\u6392\u7684\u5b66\u4e60\u987a\u5e8f\u3002

    \n\n

    \u53ef\u80fd\u4f1a\u6709\u591a\u4e2a\u6b63\u786e\u7684\u987a\u5e8f\uff0c\u4f60\u53ea\u8981\u8fd4\u56de\u4e00\u79cd\u5c31\u53ef\u4ee5\u4e86\u3002\u5982\u679c\u4e0d\u53ef\u80fd\u5b8c\u6210\u6240\u6709\u8bfe\u7a0b\uff0c\u8fd4\u56de\u4e00\u4e2a\u7a7a\u6570\u7ec4\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: 2, [[1,0]] \n\u8f93\u51fa: [0,1]\n\u89e3\u91ca: \u603b\u5171\u6709 2 \u95e8\u8bfe\u7a0b\u3002\u8981\u5b66\u4e60\u8bfe\u7a0b 1\uff0c\u4f60\u9700\u8981\u5148\u5b8c\u6210\u8bfe\u7a0b 0\u3002\u56e0\u6b64\uff0c\u6b63\u786e\u7684\u8bfe\u7a0b\u987a\u5e8f\u4e3a [0,1] \u3002
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: 4, [[1,0],[2,0],[3,1],[3,2]]\n\u8f93\u51fa: [0,1,2,3] or [0,2,1,3]\n\u89e3\u91ca: \u603b\u5171\u6709 4 \u95e8\u8bfe\u7a0b\u3002\u8981\u5b66\u4e60\u8bfe\u7a0b 3\uff0c\u4f60\u5e94\u8be5\u5148\u5b8c\u6210\u8bfe\u7a0b 1 \u548c\u8bfe\u7a0b 2\u3002\u5e76\u4e14\u8bfe\u7a0b 1 \u548c\u8bfe\u7a0b 2 \u90fd\u5e94\u8be5\u6392\u5728\u8bfe\u7a0b 0 \u4e4b\u540e\u3002\n     \u56e0\u6b64\uff0c\u4e00\u4e2a\u6b63\u786e\u7684\u8bfe\u7a0b\u987a\u5e8f\u662f [0,1,2,3] \u3002\u53e6\u4e00\u4e2a\u6b63\u786e\u7684\u6392\u5e8f\u662f [0,2,1,3] \u3002\n
    \n\n

    \u8bf4\u660e:

    \n\n
      \n\t
    1. \u8f93\u5165\u7684\u5148\u51b3\u6761\u4ef6\u662f\u7531\u8fb9\u7f18\u5217\u8868\u8868\u793a\u7684\u56fe\u5f62\uff0c\u800c\u4e0d\u662f\u90bb\u63a5\u77e9\u9635\u3002\u8be6\u60c5\u8bf7\u53c2\u89c1\u56fe\u7684\u8868\u793a\u6cd5\u3002
    2. \n\t
    3. \u4f60\u53ef\u4ee5\u5047\u5b9a\u8f93\u5165\u7684\u5148\u51b3\u6761\u4ef6\u4e2d\u6ca1\u6709\u91cd\u590d\u7684\u8fb9\u3002
    4. \n
    \n\n

    \u63d0\u793a:

    \n\n
      \n\t
    1. \u8fd9\u4e2a\u95ee\u9898\u76f8\u5f53\u4e8e\u67e5\u627e\u4e00\u4e2a\u5faa\u73af\u662f\u5426\u5b58\u5728\u4e8e\u6709\u5411\u56fe\u4e2d\u3002\u5982\u679c\u5b58\u5728\u5faa\u73af\uff0c\u5219\u4e0d\u5b58\u5728\u62d3\u6251\u6392\u5e8f\uff0c\u56e0\u6b64\u4e0d\u53ef\u80fd\u9009\u53d6\u6240\u6709\u8bfe\u7a0b\u8fdb\u884c\u5b66\u4e60\u3002
    2. \n\t
    3. \u901a\u8fc7 DFS \u8fdb\u884c\u62d3\u6251\u6392\u5e8f - \u4e00\u4e2a\u5173\u4e8eCoursera\u7684\u7cbe\u5f69\u89c6\u9891\u6559\u7a0b\uff0821\u5206\u949f\uff09\uff0c\u4ecb\u7ecd\u62d3\u6251\u6392\u5e8f\u7684\u57fa\u672c\u6982\u5ff5\u3002
    4. \n\t
    5. \n\t

      \u62d3\u6251\u6392\u5e8f\u4e5f\u53ef\u4ee5\u901a\u8fc7 BFS \u5b8c\u6210\u3002

      \n\t
    6. \n
    \n", "tags_en": ["Depth-first Search", "Breadth-first Search", "Graph", "Topological Sort"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u56fe", "\u62d3\u6251\u6392\u5e8f"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findOrder(int numCourses, vector>& prerequisites) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] findOrder(int numCourses, int[][] prerequisites) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findOrder(self, numCourses, prerequisites):\n \"\"\"\n :type numCourses: int\n :type prerequisites: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findOrder(self, numCourses: int, prerequisites: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* findOrder(int numCourses, int** prerequisites, int prerequisitesSize, int* prerequisitesColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] FindOrder(int numCourses, int[][] prerequisites) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} numCourses\n * @param {number[][]} prerequisites\n * @return {number[]}\n */\nvar findOrder = function(numCourses, prerequisites) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} num_courses\n# @param {Integer[][]} prerequisites\n# @return {Integer[]}\ndef find_order(num_courses, prerequisites)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findOrder(_ numCourses: Int, _ prerequisites: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findOrder(numCourses int, prerequisites [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findOrder(numCourses: Int, prerequisites: Array[Array[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findOrder(numCourses: Int, prerequisites: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_order(num_courses: i32, prerequisites: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $numCourses\n * @param Integer[][] $prerequisites\n * @return Integer[]\n */\n function findOrder($numCourses, $prerequisites) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findOrder(numCourses: number, prerequisites: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-order numCourses prerequisites)\n (-> exact-integer? (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0210](https://leetcode-cn.com/problems/course-schedule-ii)", "[\u8bfe\u7a0b\u8868 II](/solution/0200-0299/0210.Course%20Schedule%20II/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u56fe`,`\u62d3\u6251\u6392\u5e8f`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0210](https://leetcode.com/problems/course-schedule-ii)", "[Course Schedule II](/solution/0200-0299/0210.Course%20Schedule%20II/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`,`Graph`,`Topological Sort`", "Medium", ""]}, {"question_id": "0209", "frontend_question_id": "0209", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-size-subarray-sum", "url_en": "https://leetcode.com/problems/minimum-size-subarray-sum", "relative_path_cn": "/solution/0200-0299/0209.Minimum%20Size%20Subarray%20Sum/README.md", "relative_path_en": "/solution/0200-0299/0209.Minimum%20Size%20Subarray%20Sum/README_EN.md", "title_cn": "\u957f\u5ea6\u6700\u5c0f\u7684\u5b50\u6570\u7ec4", "title_en": "Minimum Size Subarray Sum", "question_title_slug": "minimum-size-subarray-sum", "content_en": "

    Given an array of positive integers nums and a positive integer target, return the minimal length of a contiguous subarray [numsl, numsl+1, ..., numsr-1, numsr] of which the sum is greater than or equal to target. If there is no such subarray, return 0 instead.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: target = 7, nums = [2,3,1,2,4,3]\nOutput: 2\nExplanation: The subarray [4,3] has the minimal length under the problem constraint.\n
    \n\n

    Example 2:

    \n\n
    \nInput: target = 4, nums = [1,4,4]\nOutput: 1\n
    \n\n

    Example 3:

    \n\n
    \nInput: target = 11, nums = [1,1,1,1,1,1,1,1]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= target <= 109
    • \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • 1 <= nums[i] <= 105
    • \n
    \n\n

     

    \nFollow up: If you have figured out the O(n) solution, try coding another solution of which the time complexity is O(n log(n)).", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u542b\u6709\u00a0n\u00a0\u4e2a\u6b63\u6574\u6570\u7684\u6570\u7ec4\u548c\u4e00\u4e2a\u6b63\u6574\u6570 target \u3002

    \n\n

    \u627e\u51fa\u8be5\u6570\u7ec4\u4e2d\u6ee1\u8db3\u5176\u548c \u2265 target \u7684\u957f\u5ea6\u6700\u5c0f\u7684 \u8fde\u7eed\u5b50\u6570\u7ec4\u00a0[numsl, numsl+1, ..., numsr-1, numsr] \uff0c\u5e76\u8fd4\u56de\u5176\u957f\u5ea6\u3002\u5982\u679c\u4e0d\u5b58\u5728\u7b26\u5408\u6761\u4ef6\u7684\u5b50\u6570\u7ec4\uff0c\u8fd4\u56de 0 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1atarget = 7, nums = [2,3,1,2,4,3]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5b50\u6570\u7ec4\u00a0[4,3]\u00a0\u662f\u8be5\u6761\u4ef6\u4e0b\u7684\u957f\u5ea6\u6700\u5c0f\u7684\u5b50\u6570\u7ec4\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1atarget = 4, nums = [1,4,4]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1atarget = 11, nums = [1,1,1,1,1,1,1,1]\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= target <= 109
    • \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • 1 <= nums[i] <= 105
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u5982\u679c\u4f60\u5df2\u7ecf\u5b9e\u73b0 O(n) \u65f6\u95f4\u590d\u6742\u5ea6\u7684\u89e3\u6cd5, \u8bf7\u5c1d\u8bd5\u8bbe\u8ba1\u4e00\u4e2a O(n log(n)) \u65f6\u95f4\u590d\u6742\u5ea6\u7684\u89e3\u6cd5\u3002
    • \n
    \n", "tags_en": ["Array", "Two Pointers", "Binary Search"], "tags_cn": ["\u6570\u7ec4", "\u53cc\u6307\u9488", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minSubArrayLen(int target, vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minSubArrayLen(int target, int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minSubArrayLen(self, target, nums):\n \"\"\"\n :type target: int\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minSubArrayLen(self, target: int, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minSubArrayLen(int target, int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinSubArrayLen(int target, int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} target\n * @param {number[]} nums\n * @return {number}\n */\nvar minSubArrayLen = function(target, nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} target\n# @param {Integer[]} nums\n# @return {Integer}\ndef min_sub_array_len(target, nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minSubArrayLen(_ target: Int, _ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minSubArrayLen(target int, nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minSubArrayLen(target: Int, nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minSubArrayLen(target: Int, nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_sub_array_len(target: i32, nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $target\n * @param Integer[] $nums\n * @return Integer\n */\n function minSubArrayLen($target, $nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minSubArrayLen(target: number, nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-sub-array-len target nums)\n (-> exact-integer? (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0209](https://leetcode-cn.com/problems/minimum-size-subarray-sum)", "[\u957f\u5ea6\u6700\u5c0f\u7684\u5b50\u6570\u7ec4](/solution/0200-0299/0209.Minimum%20Size%20Subarray%20Sum/README.md)", "`\u6570\u7ec4`,`\u53cc\u6307\u9488`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0209](https://leetcode.com/problems/minimum-size-subarray-sum)", "[Minimum Size Subarray Sum](/solution/0200-0299/0209.Minimum%20Size%20Subarray%20Sum/README_EN.md)", "`Array`,`Two Pointers`,`Binary Search`", "Medium", ""]}, {"question_id": "0208", "frontend_question_id": "0208", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/implement-trie-prefix-tree", "url_en": "https://leetcode.com/problems/implement-trie-prefix-tree", "relative_path_cn": "/solution/0200-0299/0208.Implement%20Trie%20%28Prefix%20Tree%29/README.md", "relative_path_en": "/solution/0200-0299/0208.Implement%20Trie%20%28Prefix%20Tree%29/README_EN.md", "title_cn": "\u5b9e\u73b0 Trie (\u524d\u7f00\u6811)", "title_en": "Implement Trie (Prefix Tree)", "question_title_slug": "implement-trie-prefix-tree", "content_en": "

    A trie (pronounced as "try") or prefix tree is a tree data structure used to efficiently store and retrieve keys in a dataset of strings. There are various applications of this data structure, such as autocomplete and spellchecker.

    \n\n

    Implement the Trie class:

    \n\n
      \n\t
    • Trie() Initializes the trie object.
    • \n\t
    • void insert(String word) Inserts the string word into the trie.
    • \n\t
    • boolean search(String word) Returns true if the string word is in the trie (i.e., was inserted before), and false otherwise.
    • \n\t
    • boolean startsWith(String prefix) Returns true if there is a previously inserted string word that has the prefix prefix, and false otherwise.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["Trie", "insert", "search", "search", "startsWith", "insert", "search"]\n[[], ["apple"], ["apple"], ["app"], ["app"], ["app"], ["app"]]\nOutput\n[null, null, true, false, true, null, true]\n\nExplanation\nTrie trie = new Trie();\ntrie.insert("apple");\ntrie.search("apple");   // return True\ntrie.search("app");     // return False\ntrie.startsWith("app"); // return True\ntrie.insert("app");\ntrie.search("app");     // return True\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= word.length, prefix.length <= 2000
    • \n\t
    • word and prefix consist only of lowercase English letters.
    • \n\t
    • At most 3 * 104 calls in total will be made to insert, search, and startsWith.
    • \n
    \n", "content_cn": "

    Trie\uff08\u53d1\u97f3\u7c7b\u4f3c \"try\"\uff09\u6216\u8005\u8bf4 \u524d\u7f00\u6811 \u662f\u4e00\u79cd\u6811\u5f62\u6570\u636e\u7ed3\u6784\uff0c\u7528\u4e8e\u9ad8\u6548\u5730\u5b58\u50a8\u548c\u68c0\u7d22\u5b57\u7b26\u4e32\u6570\u636e\u96c6\u4e2d\u7684\u952e\u3002\u8fd9\u4e00\u6570\u636e\u7ed3\u6784\u6709\u76f8\u5f53\u591a\u7684\u5e94\u7528\u60c5\u666f\uff0c\u4f8b\u5982\u81ea\u52a8\u8865\u5b8c\u548c\u62fc\u5199\u68c0\u67e5\u3002

    \n\n

    \u8bf7\u4f60\u5b9e\u73b0 Trie \u7c7b\uff1a

    \n\n
      \n\t
    • Trie() \u521d\u59cb\u5316\u524d\u7f00\u6811\u5bf9\u8c61\u3002
    • \n\t
    • void insert(String word) \u5411\u524d\u7f00\u6811\u4e2d\u63d2\u5165\u5b57\u7b26\u4e32 word \u3002
    • \n\t
    • boolean search(String word) \u5982\u679c\u5b57\u7b26\u4e32 word \u5728\u524d\u7f00\u6811\u4e2d\uff0c\u8fd4\u56de true\uff08\u5373\uff0c\u5728\u68c0\u7d22\u4e4b\u524d\u5df2\u7ecf\u63d2\u5165\uff09\uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002
    • \n\t
    • boolean startsWith(String prefix) \u5982\u679c\u4e4b\u524d\u5df2\u7ecf\u63d2\u5165\u7684\u5b57\u7b26\u4e32\u00a0word \u7684\u524d\u7f00\u4e4b\u4e00\u4e3a prefix \uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\n[\"Trie\", \"insert\", \"search\", \"search\", \"startsWith\", \"insert\", \"search\"]\n[[], [\"apple\"], [\"apple\"], [\"app\"], [\"app\"], [\"app\"], [\"app\"]]\n\u8f93\u51fa\n[null, null, true, false, true, null, true]\n\n\u89e3\u91ca\nTrie trie = new Trie();\ntrie.insert(\"apple\");\ntrie.search(\"apple\");   // \u8fd4\u56de True\ntrie.search(\"app\");     // \u8fd4\u56de False\ntrie.startsWith(\"app\"); // \u8fd4\u56de True\ntrie.insert(\"app\");\ntrie.search(\"app\");     // \u8fd4\u56de True\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= word.length, prefix.length <= 2000
    • \n\t
    • word \u548c prefix \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n\t
    • insert\u3001search \u548c startsWith \u8c03\u7528\u6b21\u6570 \u603b\u8ba1 \u4e0d\u8d85\u8fc7 3 * 104 \u6b21
    • \n
    \n", "tags_en": ["Design", "Trie"], "tags_cn": ["\u8bbe\u8ba1", "\u5b57\u5178\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Trie {\npublic:\n /** Initialize your data structure here. */\n Trie() {\n\n }\n \n /** Inserts a word into the trie. */\n void insert(string word) {\n\n }\n \n /** Returns if the word is in the trie. */\n bool search(string word) {\n\n }\n \n /** Returns if there is any word in the trie that starts with the given prefix. */\n bool startsWith(string prefix) {\n\n }\n};\n\n/**\n * Your Trie object will be instantiated and called as such:\n * Trie* obj = new Trie();\n * obj->insert(word);\n * bool param_2 = obj->search(word);\n * bool param_3 = obj->startsWith(prefix);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Trie {\n\n /** Initialize your data structure here. */\n public Trie() {\n\n }\n \n /** Inserts a word into the trie. */\n public void insert(String word) {\n\n }\n \n /** Returns if the word is in the trie. */\n public boolean search(String word) {\n\n }\n \n /** Returns if there is any word in the trie that starts with the given prefix. */\n public boolean startsWith(String prefix) {\n\n }\n}\n\n/**\n * Your Trie object will be instantiated and called as such:\n * Trie obj = new Trie();\n * obj.insert(word);\n * boolean param_2 = obj.search(word);\n * boolean param_3 = obj.startsWith(prefix);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Trie(object):\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def insert(self, word):\n \"\"\"\n Inserts a word into the trie.\n :type word: str\n :rtype: None\n \"\"\"\n\n\n def search(self, word):\n \"\"\"\n Returns if the word is in the trie.\n :type word: str\n :rtype: bool\n \"\"\"\n\n\n def startsWith(self, prefix):\n \"\"\"\n Returns if there is any word in the trie that starts with the given prefix.\n :type prefix: str\n :rtype: bool\n \"\"\"\n\n\n\n# Your Trie object will be instantiated and called as such:\n# obj = Trie()\n# obj.insert(word)\n# param_2 = obj.search(word)\n# param_3 = obj.startsWith(prefix)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Trie:\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def insert(self, word: str) -> None:\n \"\"\"\n Inserts a word into the trie.\n \"\"\"\n\n\n def search(self, word: str) -> bool:\n \"\"\"\n Returns if the word is in the trie.\n \"\"\"\n\n\n def startsWith(self, prefix: str) -> bool:\n \"\"\"\n Returns if there is any word in the trie that starts with the given prefix.\n \"\"\"\n\n\n\n# Your Trie object will be instantiated and called as such:\n# obj = Trie()\n# obj.insert(word)\n# param_2 = obj.search(word)\n# param_3 = obj.startsWith(prefix)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} Trie;\n\n/** Initialize your data structure here. */\n\nTrie* trieCreate() {\n \n}\n\n/** Inserts a word into the trie. */\nvoid trieInsert(Trie* obj, char * word) {\n \n}\n\n/** Returns if the word is in the trie. */\nbool trieSearch(Trie* obj, char * word) {\n \n}\n\n/** Returns if there is any word in the trie that starts with the given prefix. */\nbool trieStartsWith(Trie* obj, char * prefix) {\n \n}\n\nvoid trieFree(Trie* obj) {\n \n}\n\n/**\n * Your Trie struct will be instantiated and called as such:\n * Trie* obj = trieCreate();\n * trieInsert(obj, word);\n \n * bool param_2 = trieSearch(obj, word);\n \n * bool param_3 = trieStartsWith(obj, prefix);\n \n * trieFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Trie {\n\n /** Initialize your data structure here. */\n public Trie() {\n\n }\n \n /** Inserts a word into the trie. */\n public void Insert(string word) {\n\n }\n \n /** Returns if the word is in the trie. */\n public bool Search(string word) {\n\n }\n \n /** Returns if there is any word in the trie that starts with the given prefix. */\n public bool StartsWith(string prefix) {\n\n }\n}\n\n/**\n * Your Trie object will be instantiated and called as such:\n * Trie obj = new Trie();\n * obj.Insert(word);\n * bool param_2 = obj.Search(word);\n * bool param_3 = obj.StartsWith(prefix);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Initialize your data structure here.\n */\nvar Trie = function() {\n\n};\n\n/**\n * Inserts a word into the trie. \n * @param {string} word\n * @return {void}\n */\nTrie.prototype.insert = function(word) {\n\n};\n\n/**\n * Returns if the word is in the trie. \n * @param {string} word\n * @return {boolean}\n */\nTrie.prototype.search = function(word) {\n\n};\n\n/**\n * Returns if there is any word in the trie that starts with the given prefix. \n * @param {string} prefix\n * @return {boolean}\n */\nTrie.prototype.startsWith = function(prefix) {\n\n};\n\n/**\n * Your Trie object will be instantiated and called as such:\n * var obj = new Trie()\n * obj.insert(word)\n * var param_2 = obj.search(word)\n * var param_3 = obj.startsWith(prefix)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class Trie\n\n=begin\n Initialize your data structure here.\n=end\n def initialize()\n\n end\n\n\n=begin\n Inserts a word into the trie.\n :type word: String\n :rtype: Void\n=end\n def insert(word)\n\n end\n\n\n=begin\n Returns if the word is in the trie.\n :type word: String\n :rtype: Boolean\n=end\n def search(word)\n\n end\n\n\n=begin\n Returns if there is any word in the trie that starts with the given prefix.\n :type prefix: String\n :rtype: Boolean\n=end\n def starts_with(prefix)\n\n end\n\n\nend\n\n# Your Trie object will be instantiated and called as such:\n# obj = Trie.new()\n# obj.insert(word)\n# param_2 = obj.search(word)\n# param_3 = obj.starts_with(prefix)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass Trie {\n\n /** Initialize your data structure here. */\n init() {\n\n }\n \n /** Inserts a word into the trie. */\n func insert(_ word: String) {\n\n }\n \n /** Returns if the word is in the trie. */\n func search(_ word: String) -> Bool {\n\n }\n \n /** Returns if there is any word in the trie that starts with the given prefix. */\n func startsWith(_ prefix: String) -> Bool {\n\n }\n}\n\n/**\n * Your Trie object will be instantiated and called as such:\n * let obj = Trie()\n * obj.insert(word)\n * let ret_2: Bool = obj.search(word)\n * let ret_3: Bool = obj.startsWith(prefix)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type Trie struct {\n\n}\n\n\n/** Initialize your data structure here. */\nfunc Constructor() Trie {\n\n}\n\n\n/** Inserts a word into the trie. */\nfunc (this *Trie) Insert(word string) {\n\n}\n\n\n/** Returns if the word is in the trie. */\nfunc (this *Trie) Search(word string) bool {\n\n}\n\n\n/** Returns if there is any word in the trie that starts with the given prefix. */\nfunc (this *Trie) StartsWith(prefix string) bool {\n\n}\n\n\n/**\n * Your Trie object will be instantiated and called as such:\n * obj := Constructor();\n * obj.Insert(word);\n * param_2 := obj.Search(word);\n * param_3 := obj.StartsWith(prefix);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class Trie() {\n\n /** Initialize your data structure here. */\n\n\n /** Inserts a word into the trie. */\n def insert(word: String) {\n\n }\n\n /** Returns if the word is in the trie. */\n def search(word: String): Boolean = {\n\n }\n\n /** Returns if there is any word in the trie that starts with the given prefix. */\n def startsWith(prefix: String): Boolean = {\n\n }\n\n}\n\n/**\n * Your Trie object will be instantiated and called as such:\n * var obj = new Trie()\n * obj.insert(word)\n * var param_2 = obj.search(word)\n * var param_3 = obj.startsWith(prefix)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Trie() {\n\n /** Initialize your data structure here. */\n\n\n /** Inserts a word into the trie. */\n fun insert(word: String) {\n\n }\n\n /** Returns if the word is in the trie. */\n fun search(word: String): Boolean {\n\n }\n\n /** Returns if there is any word in the trie that starts with the given prefix. */\n fun startsWith(prefix: String): Boolean {\n\n }\n\n}\n\n/**\n * Your Trie object will be instantiated and called as such:\n * var obj = Trie()\n * obj.insert(word)\n * var param_2 = obj.search(word)\n * var param_3 = obj.startsWith(prefix)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct Trie {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl Trie {\n\n /** Initialize your data structure here. */\n fn new() -> Self {\n\n }\n \n /** Inserts a word into the trie. */\n fn insert(&self, word: String) {\n\n }\n \n /** Returns if the word is in the trie. */\n fn search(&self, word: String) -> bool {\n\n }\n \n /** Returns if there is any word in the trie that starts with the given prefix. */\n fn starts_with(&self, prefix: String) -> bool {\n\n }\n}\n\n/**\n * Your Trie object will be instantiated and called as such:\n * let obj = Trie::new();\n * obj.insert(word);\n * let ret_2: bool = obj.search(word);\n * let ret_3: bool = obj.starts_with(prefix);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Trie {\n /**\n * Initialize your data structure here.\n */\n function __construct() {\n\n }\n\n /**\n * Inserts a word into the trie.\n * @param String $word\n * @return NULL\n */\n function insert($word) {\n\n }\n\n /**\n * Returns if the word is in the trie.\n * @param String $word\n * @return Boolean\n */\n function search($word) {\n\n }\n\n /**\n * Returns if there is any word in the trie that starts with the given prefix.\n * @param String $prefix\n * @return Boolean\n */\n function startsWith($prefix) {\n\n }\n}\n\n/**\n * Your Trie object will be instantiated and called as such:\n * $obj = Trie();\n * $obj->insert($word);\n * $ret_2 = $obj->search($word);\n * $ret_3 = $obj->startsWith($prefix);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class Trie {\n constructor() {\n\n }\n\n insert(word: string): void {\n\n }\n\n search(word: string): boolean {\n\n }\n\n startsWith(prefix: string): boolean {\n\n }\n}\n\n/**\n * Your Trie object will be instantiated and called as such:\n * var obj = new Trie()\n * obj.insert(word)\n * var param_2 = obj.search(word)\n * var param_3 = obj.startsWith(prefix)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define trie%\n (class object%\n (super-new)\n (init-field)\n \n ; insert : string? -> void?\n (define/public (insert word)\n\n )\n ; search : string? -> boolean?\n (define/public (search word)\n\n )\n ; starts-with : string? -> boolean?\n (define/public (starts-with prefix)\n\n )))\n\n;; Your trie% object will be instantiated and called as such:\n;; (define obj (new trie%))\n;; (send obj insert word)\n;; (define param_2 (send obj search word))\n;; (define param_3 (send obj starts-with prefix))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0208](https://leetcode-cn.com/problems/implement-trie-prefix-tree)", "[\u5b9e\u73b0 Trie (\u524d\u7f00\u6811)](/solution/0200-0299/0208.Implement%20Trie%20%28Prefix%20Tree%29/README.md)", "`\u8bbe\u8ba1`,`\u5b57\u5178\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0208](https://leetcode.com/problems/implement-trie-prefix-tree)", "[Implement Trie (Prefix Tree)](/solution/0200-0299/0208.Implement%20Trie%20%28Prefix%20Tree%29/README_EN.md)", "`Design`,`Trie`", "Medium", ""]}, {"question_id": "0207", "frontend_question_id": "0207", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/course-schedule", "url_en": "https://leetcode.com/problems/course-schedule", "relative_path_cn": "/solution/0200-0299/0207.Course%20Schedule/README.md", "relative_path_en": "/solution/0200-0299/0207.Course%20Schedule/README_EN.md", "title_cn": "\u8bfe\u7a0b\u8868", "title_en": "Course Schedule", "question_title_slug": "course-schedule", "content_en": "

    There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i] = [ai, bi] indicates that you must take course bi first if you want to take course ai.

    \n\n
      \n\t
    • For example, the pair [0, 1], indicates that to take course 0 you have to first take course 1.
    • \n
    \n\n

    Return true if you can finish all courses. Otherwise, return false.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: numCourses = 2, prerequisites = [[1,0]]\nOutput: true\nExplanation: There are a total of 2 courses to take. \nTo take course 1 you should have finished course 0. So it is possible.\n
    \n\n

    Example 2:

    \n\n
    \nInput: numCourses = 2, prerequisites = [[1,0],[0,1]]\nOutput: false\nExplanation: There are a total of 2 courses to take. \nTo take course 1 you should have finished course 0, and to take course 0 you should also have finished course 1. So it is impossible.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= numCourses <= 105
    • \n\t
    • 0 <= prerequisites.length <= 5000
    • \n\t
    • prerequisites[i].length == 2
    • \n\t
    • 0 <= ai, bi < numCourses
    • \n\t
    • All the pairs prerequisites[i] are unique.
    • \n
    \n", "content_cn": "

    \u4f60\u8fd9\u4e2a\u5b66\u671f\u5fc5\u987b\u9009\u4fee numCourses \u95e8\u8bfe\u7a0b\uff0c\u8bb0\u4e3a\u00a00\u00a0\u5230\u00a0numCourses - 1 \u3002

    \n\n

    \u5728\u9009\u4fee\u67d0\u4e9b\u8bfe\u7a0b\u4e4b\u524d\u9700\u8981\u4e00\u4e9b\u5148\u4fee\u8bfe\u7a0b\u3002 \u5148\u4fee\u8bfe\u7a0b\u6309\u6570\u7ec4\u00a0prerequisites \u7ed9\u51fa\uff0c\u5176\u4e2d\u00a0prerequisites[i] = [ai, bi] \uff0c\u8868\u793a\u5982\u679c\u8981\u5b66\u4e60\u8bfe\u7a0b\u00a0ai \u5219 \u5fc5\u987b \u5148\u5b66\u4e60\u8bfe\u7a0b\u00a0 bi \u3002

    \n\n
      \n\t
    • \u4f8b\u5982\uff0c\u5148\u4fee\u8bfe\u7a0b\u5bf9\u00a0[0, 1] \u8868\u793a\uff1a\u60f3\u8981\u5b66\u4e60\u8bfe\u7a0b 0 \uff0c\u4f60\u9700\u8981\u5148\u5b8c\u6210\u8bfe\u7a0b 1 \u3002
    • \n
    \n\n

    \u8bf7\u4f60\u5224\u65ad\u662f\u5426\u53ef\u80fd\u5b8c\u6210\u6240\u6709\u8bfe\u7a0b\u7684\u5b66\u4e60\uff1f\u5982\u679c\u53ef\u4ee5\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anumCourses = 2, prerequisites = [[1,0]]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u603b\u5171\u6709 2 \u95e8\u8bfe\u7a0b\u3002\u5b66\u4e60\u8bfe\u7a0b 1 \u4e4b\u524d\uff0c\u4f60\u9700\u8981\u5b8c\u6210\u8bfe\u7a0b 0 \u3002\u8fd9\u662f\u53ef\u80fd\u7684\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anumCourses = 2, prerequisites = [[1,0],[0,1]]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u603b\u5171\u6709 2 \u95e8\u8bfe\u7a0b\u3002\u5b66\u4e60\u8bfe\u7a0b 1 \u4e4b\u524d\uff0c\u4f60\u9700\u8981\u5148\u5b8c\u6210\u200b\u8bfe\u7a0b 0 \uff1b\u5e76\u4e14\u5b66\u4e60\u8bfe\u7a0b 0 \u4e4b\u524d\uff0c\u4f60\u8fd8\u5e94\u5148\u5b8c\u6210\u8bfe\u7a0b 1 \u3002\u8fd9\u662f\u4e0d\u53ef\u80fd\u7684\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= numCourses <= 105
    • \n\t
    • 0 <= prerequisites.length <= 5000
    • \n\t
    • prerequisites[i].length == 2
    • \n\t
    • 0 <= ai, bi < numCourses
    • \n\t
    • prerequisites[i] \u4e2d\u7684\u6240\u6709\u8bfe\u7a0b\u5bf9 \u4e92\u4e0d\u76f8\u540c
    • \n
    \n", "tags_en": ["Depth-first Search", "Breadth-first Search", "Graph", "Topological Sort"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u56fe", "\u62d3\u6251\u6392\u5e8f"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canFinish(int numCourses, vector>& prerequisites) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canFinish(int numCourses, int[][] prerequisites) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canFinish(self, numCourses, prerequisites):\n \"\"\"\n :type numCourses: int\n :type prerequisites: List[List[int]]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canFinish(self, numCourses: int, prerequisites: List[List[int]]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canFinish(int numCourses, int** prerequisites, int prerequisitesSize, int* prerequisitesColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanFinish(int numCourses, int[][] prerequisites) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} numCourses\n * @param {number[][]} prerequisites\n * @return {boolean}\n */\nvar canFinish = function(numCourses, prerequisites) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} num_courses\n# @param {Integer[][]} prerequisites\n# @return {Boolean}\ndef can_finish(num_courses, prerequisites)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canFinish(_ numCourses: Int, _ prerequisites: [[Int]]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canFinish(numCourses int, prerequisites [][]int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canFinish(numCourses: Int, prerequisites: Array[Array[Int]]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canFinish(numCourses: Int, prerequisites: Array): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_finish(num_courses: i32, prerequisites: Vec>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $numCourses\n * @param Integer[][] $prerequisites\n * @return Boolean\n */\n function canFinish($numCourses, $prerequisites) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canFinish(numCourses: number, prerequisites: number[][]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-finish numCourses prerequisites)\n (-> exact-integer? (listof (listof exact-integer?)) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0207](https://leetcode-cn.com/problems/course-schedule)", "[\u8bfe\u7a0b\u8868](/solution/0200-0299/0207.Course%20Schedule/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u56fe`,`\u62d3\u6251\u6392\u5e8f`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0207](https://leetcode.com/problems/course-schedule)", "[Course Schedule](/solution/0200-0299/0207.Course%20Schedule/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`,`Graph`,`Topological Sort`", "Medium", ""]}, {"question_id": "0206", "frontend_question_id": "0206", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reverse-linked-list", "url_en": "https://leetcode.com/problems/reverse-linked-list", "relative_path_cn": "/solution/0200-0299/0206.Reverse%20Linked%20List/README.md", "relative_path_en": "/solution/0200-0299/0206.Reverse%20Linked%20List/README_EN.md", "title_cn": "\u53cd\u8f6c\u94fe\u8868", "title_en": "Reverse Linked List", "question_title_slug": "reverse-linked-list", "content_en": "

    Given the head of a singly linked list, reverse the list, and return the reversed list.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: head = [1,2,3,4,5]\nOutput: [5,4,3,2,1]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: head = [1,2]\nOutput: [2,1]\n
    \n\n

    Example 3:

    \n\n
    \nInput: head = []\nOutput: []\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the list is the range [0, 5000].
    • \n\t
    • -5000 <= Node.val <= 5000
    • \n
    \n\n

     

    \n

    Follow up: A linked list can be reversed either iteratively or recursively. Could you implement both?

    \n", "content_cn": "\u7ed9\u4f60\u5355\u94fe\u8868\u7684\u5934\u8282\u70b9 head \uff0c\u8bf7\u4f60\u53cd\u8f6c\u94fe\u8868\uff0c\u5e76\u8fd4\u56de\u53cd\u8f6c\u540e\u7684\u94fe\u8868\u3002\n
    \n
    \n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1ahead = [1,2,3,4,5]\n\u8f93\u51fa\uff1a[5,4,3,2,1]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1ahead = [1,2]\n\u8f93\u51fa\uff1a[2,1]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahead = []\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u94fe\u8868\u4e2d\u8282\u70b9\u7684\u6570\u76ee\u8303\u56f4\u662f [0, 5000]
    • \n\t
    • -5000 <= Node.val <= 5000
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u94fe\u8868\u53ef\u4ee5\u9009\u7528\u8fed\u4ee3\u6216\u9012\u5f52\u65b9\u5f0f\u5b8c\u6210\u53cd\u8f6c\u3002\u4f60\u80fd\u5426\u7528\u4e24\u79cd\u65b9\u6cd5\u89e3\u51b3\u8fd9\u9053\u9898\uff1f

    \n
    \n
    \n", "tags_en": ["Linked List"], "tags_cn": ["\u94fe\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n ListNode* reverseList(ListNode* head) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public ListNode reverseList(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def reverseList(self, head):\n \"\"\"\n :type head: ListNode\n :rtype: ListNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def reverseList(self, head: ListNode) -> ListNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nstruct ListNode* reverseList(struct ListNode* head){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public ListNode ReverseList(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} head\n * @return {ListNode}\n */\nvar reverseList = function(head) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode} head\n# @return {ListNode}\ndef reverse_list(head)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func reverseList(_ head: ListNode?) -> ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc reverseList(head *ListNode) *ListNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def reverseList(head: ListNode): ListNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun reverseList(head: ListNode?): ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn reverse_list(head: Option>) -> Option> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @return ListNode\n */\n function reverseList($head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction reverseList(head: ListNode | null): ListNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (reverse-list head)\n (-> (or/c list-node? #f) (or/c list-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0206](https://leetcode-cn.com/problems/reverse-linked-list)", "[\u53cd\u8f6c\u94fe\u8868](/solution/0200-0299/0206.Reverse%20Linked%20List/README.md)", "`\u94fe\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0206](https://leetcode.com/problems/reverse-linked-list)", "[Reverse Linked List](/solution/0200-0299/0206.Reverse%20Linked%20List/README_EN.md)", "`Linked List`", "Easy", ""]}, {"question_id": "0205", "frontend_question_id": "0205", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/isomorphic-strings", "url_en": "https://leetcode.com/problems/isomorphic-strings", "relative_path_cn": "/solution/0200-0299/0205.Isomorphic%20Strings/README.md", "relative_path_en": "/solution/0200-0299/0205.Isomorphic%20Strings/README_EN.md", "title_cn": "\u540c\u6784\u5b57\u7b26\u4e32", "title_en": "Isomorphic Strings", "question_title_slug": "isomorphic-strings", "content_en": "

    Given two strings s and t, determine if they are isomorphic.

    \n\n

    Two strings s and t are isomorphic if the characters in s can be replaced to get t.

    \n\n

    All occurrences of a character must be replaced with another character while preserving the order of characters. No two characters may map to the same character, but a character may map to itself.

    \n\n

     

    \n

    Example 1:

    \n
    Input: s = \"egg\", t = \"add\"\nOutput: true\n

    Example 2:

    \n
    Input: s = \"foo\", t = \"bar\"\nOutput: false\n

    Example 3:

    \n
    Input: s = \"paper\", t = \"title\"\nOutput: true\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 5 * 104
    • \n\t
    • t.length == s.length
    • \n\t
    • s and t consist of any valid ascii character.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u5b57\u7b26\u4e32\u00a0s\u00a0\u548c\u00a0t\uff0c\u5224\u65ad\u5b83\u4eec\u662f\u5426\u662f\u540c\u6784\u7684\u3002

    \n\n

    \u5982\u679c\u00a0s\u00a0\u4e2d\u7684\u5b57\u7b26\u53ef\u4ee5\u6309\u67d0\u79cd\u6620\u5c04\u5173\u7cfb\u66ff\u6362\u5f97\u5230\u00a0t\u00a0\uff0c\u90a3\u4e48\u8fd9\u4e24\u4e2a\u5b57\u7b26\u4e32\u662f\u540c\u6784\u7684\u3002

    \n\n

    \u6bcf\u4e2a\u51fa\u73b0\u7684\u5b57\u7b26\u90fd\u5e94\u5f53\u6620\u5c04\u5230\u53e6\u4e00\u4e2a\u5b57\u7b26\uff0c\u540c\u65f6\u4e0d\u6539\u53d8\u5b57\u7b26\u7684\u987a\u5e8f\u3002\u4e0d\u540c\u5b57\u7b26\u4e0d\u80fd\u6620\u5c04\u5230\u540c\u4e00\u4e2a\u5b57\u7b26\u4e0a\uff0c\u76f8\u540c\u5b57\u7b26\u53ea\u80fd\u6620\u5c04\u5230\u540c\u4e00\u4e2a\u5b57\u7b26\u4e0a\uff0c\u5b57\u7b26\u53ef\u4ee5\u6620\u5c04\u5230\u81ea\u5df1\u672c\u8eab\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165\uff1as = \"egg\", t = \"add\"\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"foo\", t = \"bar\"\n\u8f93\u51fa\uff1afalse
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"paper\", t = \"title\"\n\u8f93\u51fa\uff1atrue
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u53ef\u4ee5\u5047\u8bbe\u00a0s\u00a0\u548c t \u957f\u5ea6\u76f8\u540c\u3002
    • \n
    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isIsomorphic(string s, string t) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isIsomorphic(String s, String t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isIsomorphic(self, s, t):\n \"\"\"\n :type s: str\n :type t: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isIsomorphic(self, s: str, t: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isIsomorphic(char * s, char * t){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsIsomorphic(string s, string t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string} t\n * @return {boolean}\n */\nvar isIsomorphic = function(s, t) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String} t\n# @return {Boolean}\ndef is_isomorphic(s, t)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isIsomorphic(_ s: String, _ t: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isIsomorphic(s string, t string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isIsomorphic(s: String, t: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isIsomorphic(s: String, t: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_isomorphic(s: String, t: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String $t\n * @return Boolean\n */\n function isIsomorphic($s, $t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isIsomorphic(s: string, t: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-isomorphic s t)\n (-> string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0205](https://leetcode-cn.com/problems/isomorphic-strings)", "[\u540c\u6784\u5b57\u7b26\u4e32](/solution/0200-0299/0205.Isomorphic%20Strings/README.md)", "`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0205](https://leetcode.com/problems/isomorphic-strings)", "[Isomorphic Strings](/solution/0200-0299/0205.Isomorphic%20Strings/README_EN.md)", "`Hash Table`", "Easy", ""]}, {"question_id": "0204", "frontend_question_id": "0204", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-primes", "url_en": "https://leetcode.com/problems/count-primes", "relative_path_cn": "/solution/0200-0299/0204.Count%20Primes/README.md", "relative_path_en": "/solution/0200-0299/0204.Count%20Primes/README_EN.md", "title_cn": "\u8ba1\u6570\u8d28\u6570", "title_en": "Count Primes", "question_title_slug": "count-primes", "content_en": "

    Count the number of prime numbers less than a non-negative number, n.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 10\nOutput: 4\nExplanation: There are 4 prime numbers less than 10, they are 2, 3, 5, 7.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 0\nOutput: 0\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 1\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= n <= 5 * 106
    • \n
    \n", "content_cn": "

    \u7edf\u8ba1\u6240\u6709\u5c0f\u4e8e\u975e\u8d1f\u6574\u6570 n \u7684\u8d28\u6570\u7684\u6570\u91cf\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1an = 10\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u5c0f\u4e8e 10 \u7684\u8d28\u6570\u4e00\u5171\u6709 4 \u4e2a, \u5b83\u4eec\u662f 2, 3, 5, 7 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1an = 0\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1a0\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= n <= 5 * 106
    • \n
    \n", "tags_en": ["Hash Table", "Math"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countPrimes(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countPrimes(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countPrimes(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countPrimes(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countPrimes(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountPrimes(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar countPrimes = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef count_primes(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countPrimes(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countPrimes(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countPrimes(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countPrimes(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_primes(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function countPrimes($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countPrimes(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-primes n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0204](https://leetcode-cn.com/problems/count-primes)", "[\u8ba1\u6570\u8d28\u6570](/solution/0200-0299/0204.Count%20Primes/README.md)", "`\u54c8\u5e0c\u8868`,`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0204](https://leetcode.com/problems/count-primes)", "[Count Primes](/solution/0200-0299/0204.Count%20Primes/README_EN.md)", "`Hash Table`,`Math`", "Easy", ""]}, {"question_id": "0203", "frontend_question_id": "0203", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/remove-linked-list-elements", "url_en": "https://leetcode.com/problems/remove-linked-list-elements", "relative_path_cn": "/solution/0200-0299/0203.Remove%20Linked%20List%20Elements/README.md", "relative_path_en": "/solution/0200-0299/0203.Remove%20Linked%20List%20Elements/README_EN.md", "title_cn": "\u79fb\u9664\u94fe\u8868\u5143\u7d20", "title_en": "Remove Linked List Elements", "question_title_slug": "remove-linked-list-elements", "content_en": "

    Given the head of a linked list and an integer val, remove all the nodes of the linked list that has Node.val == val, and return the new head.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: head = [1,2,6,3,4,5,6], val = 6\nOutput: [1,2,3,4,5]\n
    \n\n

    Example 2:

    \n\n
    \nInput: head = [], val = 1\nOutput: []\n
    \n\n

    Example 3:

    \n\n
    \nInput: head = [7,7,7,7], val = 7\nOutput: []\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the list is in the range [0, 104].
    • \n\t
    • 1 <= Node.val <= 50
    • \n\t
    • 0 <= k <= 50
    • \n
    \n", "content_cn": "\u7ed9\u4f60\u4e00\u4e2a\u94fe\u8868\u7684\u5934\u8282\u70b9 head \u548c\u4e00\u4e2a\u6574\u6570 val \uff0c\u8bf7\u4f60\u5220\u9664\u94fe\u8868\u4e2d\u6240\u6709\u6ee1\u8db3 Node.val == val \u7684\u8282\u70b9\uff0c\u5e76\u8fd4\u56de \u65b0\u7684\u5934\u8282\u70b9 \u3002\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1ahead = [1,2,6,3,4,5,6], val = 6\n\u8f93\u51fa\uff1a[1,2,3,4,5]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahead = [], val = 1\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahead = [7,7,7,7], val = 7\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u5217\u8868\u4e2d\u7684\u8282\u70b9\u5728\u8303\u56f4 [0, 104] \u5185
    • \n\t
    • 1 <= Node.val <= 50
    • \n\t
    • 0 <= k <= 50
    • \n
    \n", "tags_en": ["Linked List"], "tags_cn": ["\u94fe\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n ListNode* removeElements(ListNode* head, int val) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public ListNode removeElements(ListNode head, int val) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def removeElements(self, head, val):\n \"\"\"\n :type head: ListNode\n :type val: int\n :rtype: ListNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def removeElements(self, head: ListNode, val: int) -> ListNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nstruct ListNode* removeElements(struct ListNode* head, int val){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public ListNode RemoveElements(ListNode head, int val) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} head\n * @param {number} val\n * @return {ListNode}\n */\nvar removeElements = function(head, val) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode} head\n# @param {Integer} val\n# @return {ListNode}\ndef remove_elements(head, val)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func removeElements(_ head: ListNode?, _ val: Int) -> ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc removeElements(head *ListNode, val int) *ListNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def removeElements(head: ListNode, `val`: Int): ListNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun removeElements(head: ListNode?, `val`: Int): ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn remove_elements(head: Option>, val: i32) -> Option> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @param Integer $val\n * @return ListNode\n */\n function removeElements($head, $val) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction removeElements(head: ListNode | null, val: number): ListNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (remove-elements head val)\n (-> (or/c list-node? #f) exact-integer? (or/c list-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0203](https://leetcode-cn.com/problems/remove-linked-list-elements)", "[\u79fb\u9664\u94fe\u8868\u5143\u7d20](/solution/0200-0299/0203.Remove%20Linked%20List%20Elements/README.md)", "`\u94fe\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0203](https://leetcode.com/problems/remove-linked-list-elements)", "[Remove Linked List Elements](/solution/0200-0299/0203.Remove%20Linked%20List%20Elements/README_EN.md)", "`Linked List`", "Easy", ""]}, {"question_id": "0202", "frontend_question_id": "0202", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/happy-number", "url_en": "https://leetcode.com/problems/happy-number", "relative_path_cn": "/solution/0200-0299/0202.Happy%20Number/README.md", "relative_path_en": "/solution/0200-0299/0202.Happy%20Number/README_EN.md", "title_cn": "\u5feb\u4e50\u6570", "title_en": "Happy Number", "question_title_slug": "happy-number", "content_en": "

    Write an algorithm to determine if a number n is happy.

    \n\n

    A happy number is a number defined by the following process:

    \n\n
      \n\t
    • Starting with any positive integer, replace the number by the sum of the squares of its digits.
    • \n\t
    • Repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1.
    • \n\t
    • Those numbers for which this process ends in 1 are happy.
    • \n
    \n\n

    Return true if n is a happy number, and false if not.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 19\nOutput: true\nExplanation:\n12 + 92 = 82\n82 + 22 = 68\n62 + 82 = 100\n12 + 02 + 02 = 1\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 2\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 231 - 1
    • \n
    \n", "content_cn": "

    \u7f16\u5199\u4e00\u4e2a\u7b97\u6cd5\u6765\u5224\u65ad\u4e00\u4e2a\u6570 n \u662f\u4e0d\u662f\u5feb\u4e50\u6570\u3002

    \n\n

    \u300c\u5feb\u4e50\u6570\u300d\u5b9a\u4e49\u4e3a\uff1a

    \n\n
      \n\t
    • \u5bf9\u4e8e\u4e00\u4e2a\u6b63\u6574\u6570\uff0c\u6bcf\u4e00\u6b21\u5c06\u8be5\u6570\u66ff\u6362\u4e3a\u5b83\u6bcf\u4e2a\u4f4d\u7f6e\u4e0a\u7684\u6570\u5b57\u7684\u5e73\u65b9\u548c\u3002
    • \n\t
    • \u7136\u540e\u91cd\u590d\u8fd9\u4e2a\u8fc7\u7a0b\u76f4\u5230\u8fd9\u4e2a\u6570\u53d8\u4e3a 1\uff0c\u4e5f\u53ef\u80fd\u662f \u65e0\u9650\u5faa\u73af \u4f46\u59cb\u7ec8\u53d8\u4e0d\u5230 1\u3002
    • \n\t
    • \u5982\u679c \u53ef\u4ee5\u53d8\u4e3a\u00a0 1\uff0c\u90a3\u4e48\u8fd9\u4e2a\u6570\u5c31\u662f\u5feb\u4e50\u6570\u3002
    • \n
    \n\n

    \u5982\u679c n \u662f\u5feb\u4e50\u6570\u5c31\u8fd4\u56de true \uff1b\u4e0d\u662f\uff0c\u5219\u8fd4\u56de false \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1a19\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\n12 + 92 = 82\n82 + 22 = 68\n62 + 82 = 100\n12 + 02 + 02 = 1\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 2\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 231 - 1
    • \n
    \n", "tags_en": ["Hash Table", "Math"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isHappy(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isHappy(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isHappy(self, n):\n \"\"\"\n :type n: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isHappy(self, n: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isHappy(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsHappy(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {boolean}\n */\nvar isHappy = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Boolean}\ndef is_happy(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isHappy(_ n: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isHappy(n int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isHappy(n: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isHappy(n: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_happy(n: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Boolean\n */\n function isHappy($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isHappy(n: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-happy n)\n (-> exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0202](https://leetcode-cn.com/problems/happy-number)", "[\u5feb\u4e50\u6570](/solution/0200-0299/0202.Happy%20Number/README.md)", "`\u54c8\u5e0c\u8868`,`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0202](https://leetcode.com/problems/happy-number)", "[Happy Number](/solution/0200-0299/0202.Happy%20Number/README_EN.md)", "`Hash Table`,`Math`", "Easy", ""]}, {"question_id": "0201", "frontend_question_id": "0201", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/bitwise-and-of-numbers-range", "url_en": "https://leetcode.com/problems/bitwise-and-of-numbers-range", "relative_path_cn": "/solution/0200-0299/0201.Bitwise%20AND%20of%20Numbers%20Range/README.md", "relative_path_en": "/solution/0200-0299/0201.Bitwise%20AND%20of%20Numbers%20Range/README_EN.md", "title_cn": "\u6570\u5b57\u8303\u56f4\u6309\u4f4d\u4e0e", "title_en": "Bitwise AND of Numbers Range", "question_title_slug": "bitwise-and-of-numbers-range", "content_en": "

    Given two integers left and right that represent the range [left, right], return the bitwise AND of all numbers in this range, inclusive.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: left = 5, right = 7\nOutput: 4\n
    \n\n

    Example 2:

    \n\n
    \nInput: left = 0, right = 0\nOutput: 0\n
    \n\n

    Example 3:

    \n\n
    \nInput: left = 1, right = 2147483647\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= left <= right <= 231 - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u6574\u6570 left \u548c right \uff0c\u8868\u793a\u533a\u95f4 [left, right] \uff0c\u8fd4\u56de\u6b64\u533a\u95f4\u5185\u6240\u6709\u6570\u5b57 \u6309\u4f4d\u4e0e \u7684\u7ed3\u679c\uff08\u5305\u542b left \u3001right \u7aef\u70b9\uff09\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aleft = 5, right = 7\n\u8f93\u51fa\uff1a4\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aleft = 0, right = 0\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aleft = 1, right = 2147483647\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= left <= right <= 231 - 1
    • \n
    \n", "tags_en": ["Bit Manipulation"], "tags_cn": ["\u4f4d\u8fd0\u7b97"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int rangeBitwiseAnd(int left, int right) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int rangeBitwiseAnd(int left, int right) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def rangeBitwiseAnd(self, left, right):\n \"\"\"\n :type left: int\n :type right: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def rangeBitwiseAnd(self, left: int, right: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint rangeBitwiseAnd(int left, int right){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int RangeBitwiseAnd(int left, int right) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} left\n * @param {number} right\n * @return {number}\n */\nvar rangeBitwiseAnd = function(left, right) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} left\n# @param {Integer} right\n# @return {Integer}\ndef range_bitwise_and(left, right)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func rangeBitwiseAnd(_ left: Int, _ right: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func rangeBitwiseAnd(left int, right int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def rangeBitwiseAnd(left: Int, right: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun rangeBitwiseAnd(left: Int, right: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn range_bitwise_and(left: i32, right: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $left\n * @param Integer $right\n * @return Integer\n */\n function rangeBitwiseAnd($left, $right) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function rangeBitwiseAnd(left: number, right: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (range-bitwise-and left right)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0201](https://leetcode-cn.com/problems/bitwise-and-of-numbers-range)", "[\u6570\u5b57\u8303\u56f4\u6309\u4f4d\u4e0e](/solution/0200-0299/0201.Bitwise%20AND%20of%20Numbers%20Range/README.md)", "`\u4f4d\u8fd0\u7b97`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0201](https://leetcode.com/problems/bitwise-and-of-numbers-range)", "[Bitwise AND of Numbers Range](/solution/0200-0299/0201.Bitwise%20AND%20of%20Numbers%20Range/README_EN.md)", "`Bit Manipulation`", "Medium", ""]}, {"question_id": "0200", "frontend_question_id": "0200", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-islands", "url_en": "https://leetcode.com/problems/number-of-islands", "relative_path_cn": "/solution/0200-0299/0200.Number%20of%20Islands/README.md", "relative_path_en": "/solution/0200-0299/0200.Number%20of%20Islands/README_EN.md", "title_cn": "\u5c9b\u5c7f\u6570\u91cf", "title_en": "Number of Islands", "question_title_slug": "number-of-islands", "content_en": "

    Given an m x n 2D binary grid grid which represents a map of '1's (land) and '0's (water), return the number of islands.

    \n\n

    An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surrounded by water.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: grid = [\n  ["1","1","1","1","0"],\n  ["1","1","0","1","0"],\n  ["1","1","0","0","0"],\n  ["0","0","0","0","0"]\n]\nOutput: 1\n
    \n\n

    Example 2:

    \n\n
    \nInput: grid = [\n  ["1","1","0","0","0"],\n  ["1","1","0","0","0"],\n  ["0","0","1","0","0"],\n  ["0","0","0","1","1"]\n]\nOutput: 3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= m, n <= 300
    • \n\t
    • grid[i][j] is '0' or '1'.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u7531\u00a0'1'\uff08\u9646\u5730\uff09\u548c '0'\uff08\u6c34\uff09\u7ec4\u6210\u7684\u7684\u4e8c\u7ef4\u7f51\u683c\uff0c\u8bf7\u4f60\u8ba1\u7b97\u7f51\u683c\u4e2d\u5c9b\u5c7f\u7684\u6570\u91cf\u3002

    \n\n

    \u5c9b\u5c7f\u603b\u662f\u88ab\u6c34\u5305\u56f4\uff0c\u5e76\u4e14\u6bcf\u5ea7\u5c9b\u5c7f\u53ea\u80fd\u7531\u6c34\u5e73\u65b9\u5411\u548c/\u6216\u7ad6\u76f4\u65b9\u5411\u4e0a\u76f8\u90bb\u7684\u9646\u5730\u8fde\u63a5\u5f62\u6210\u3002

    \n\n

    \u6b64\u5916\uff0c\u4f60\u53ef\u4ee5\u5047\u8bbe\u8be5\u7f51\u683c\u7684\u56db\u6761\u8fb9\u5747\u88ab\u6c34\u5305\u56f4\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1agrid = [\n  [\"1\",\"1\",\"1\",\"1\",\"0\"],\n  [\"1\",\"1\",\"0\",\"1\",\"0\"],\n  [\"1\",\"1\",\"0\",\"0\",\"0\"],\n  [\"0\",\"0\",\"0\",\"0\",\"0\"]\n]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1agrid = [\n  [\"1\",\"1\",\"0\",\"0\",\"0\"],\n  [\"1\",\"1\",\"0\",\"0\",\"0\"],\n  [\"0\",\"0\",\"1\",\"0\",\"0\"],\n  [\"0\",\"0\",\"0\",\"1\",\"1\"]\n]\n\u8f93\u51fa\uff1a3\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= m, n <= 300
    • \n\t
    • grid[i][j] \u7684\u503c\u4e3a '0' \u6216 '1'
    • \n
    \n", "tags_en": ["Depth-first Search", "Breadth-first Search", "Union Find"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e76\u67e5\u96c6"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numIslands(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numIslands(char[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numIslands(self, grid):\n \"\"\"\n :type grid: List[List[str]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numIslands(self, grid: List[List[str]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numIslands(char** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumIslands(char[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {character[][]} grid\n * @return {number}\n */\nvar numIslands = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Character[][]} grid\n# @return {Integer}\ndef num_islands(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numIslands(_ grid: [[Character]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numIslands(grid [][]byte) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numIslands(grid: Array[Array[Char]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numIslands(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_islands(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $grid\n * @return Integer\n */\n function numIslands($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numIslands(grid: string[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-islands grid)\n (-> (listof (listof char?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0200](https://leetcode-cn.com/problems/number-of-islands)", "[\u5c9b\u5c7f\u6570\u91cf](/solution/0200-0299/0200.Number%20of%20Islands/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e76\u67e5\u96c6`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0200](https://leetcode.com/problems/number-of-islands)", "[Number of Islands](/solution/0200-0299/0200.Number%20of%20Islands/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`,`Union Find`", "Medium", ""]}, {"question_id": "0199", "frontend_question_id": "0199", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/binary-tree-right-side-view", "url_en": "https://leetcode.com/problems/binary-tree-right-side-view", "relative_path_cn": "/solution/0100-0199/0199.Binary%20Tree%20Right%20Side%20View/README.md", "relative_path_en": "/solution/0100-0199/0199.Binary%20Tree%20Right%20Side%20View/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u7684\u53f3\u89c6\u56fe", "title_en": "Binary Tree Right Side View", "question_title_slug": "binary-tree-right-side-view", "content_en": "

    Given the root of a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,2,3,null,5,null,4]\nOutput: [1,3,4]\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = [1,null,3]\nOutput: [1,3]\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = []\nOutput: []\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [0, 100].
    • \n\t
    • -100 <= Node.val <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u68f5\u4e8c\u53c9\u6811\uff0c\u60f3\u8c61\u81ea\u5df1\u7ad9\u5728\u5b83\u7684\u53f3\u4fa7\uff0c\u6309\u7167\u4ece\u9876\u90e8\u5230\u5e95\u90e8\u7684\u987a\u5e8f\uff0c\u8fd4\u56de\u4ece\u53f3\u4fa7\u6240\u80fd\u770b\u5230\u7684\u8282\u70b9\u503c\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: [1,2,3,null,5,null,4]\n\u8f93\u51fa: [1, 3, 4]\n\u89e3\u91ca:\n\n   1            <---\n /   \\\n2     3         <---\n \\     \\\n  5     4       <---\n
    \n", "tags_en": ["Tree", "Depth-first Search", "Breadth-first Search", "Recursion", "Queue"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u9012\u5f52", "\u961f\u5217"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector rightSideView(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public List rightSideView(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def rightSideView(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def rightSideView(self, root: TreeNode) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* rightSideView(struct TreeNode* root, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public IList RightSideView(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number[]}\n */\nvar rightSideView = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer[]}\ndef right_side_view(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func rightSideView(_ root: TreeNode?) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc rightSideView(root *TreeNode) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def rightSideView(root: TreeNode): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun rightSideView(root: TreeNode?): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn right_side_view(root: Option>>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer[]\n */\n function rightSideView($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction rightSideView(root: TreeNode | null): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (right-side-view root)\n (-> (or/c tree-node? #f) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0199](https://leetcode-cn.com/problems/binary-tree-right-side-view)", "[\u4e8c\u53c9\u6811\u7684\u53f3\u89c6\u56fe](/solution/0100-0199/0199.Binary%20Tree%20Right%20Side%20View/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u9012\u5f52`,`\u961f\u5217`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0199](https://leetcode.com/problems/binary-tree-right-side-view)", "[Binary Tree Right Side View](/solution/0100-0199/0199.Binary%20Tree%20Right%20Side%20View/README_EN.md)", "`Tree`,`Depth-first Search`,`Breadth-first Search`,`Recursion`,`Queue`", "Medium", ""]}, {"question_id": "0198", "frontend_question_id": "0198", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/house-robber", "url_en": "https://leetcode.com/problems/house-robber", "relative_path_cn": "/solution/0100-0199/0198.House%20Robber/README.md", "relative_path_en": "/solution/0100-0199/0198.House%20Robber/README_EN.md", "title_cn": "\u6253\u5bb6\u52ab\u820d", "title_en": "House Robber", "question_title_slug": "house-robber", "content_en": "

    You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security systems connected and it will automatically contact the police if two adjacent houses were broken into on the same night.

    \n\n

    Given an integer array nums representing the amount of money of each house, return the maximum amount of money you can rob tonight without alerting the police.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,3,1]\nOutput: 4\nExplanation: Rob house 1 (money = 1) and then rob house 3 (money = 3).\nTotal amount you can rob = 1 + 3 = 4.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [2,7,9,3,1]\nOutput: 12\nExplanation: Rob house 1 (money = 2), rob house 3 (money = 9) and rob house 5 (money = 1).\nTotal amount you can rob = 2 + 9 + 1 = 12.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 100
    • \n\t
    • 0 <= nums[i] <= 400
    • \n
    \n", "content_cn": "

    \u4f60\u662f\u4e00\u4e2a\u4e13\u4e1a\u7684\u5c0f\u5077\uff0c\u8ba1\u5212\u5077\u7a83\u6cbf\u8857\u7684\u623f\u5c4b\u3002\u6bcf\u95f4\u623f\u5185\u90fd\u85cf\u6709\u4e00\u5b9a\u7684\u73b0\u91d1\uff0c\u5f71\u54cd\u4f60\u5077\u7a83\u7684\u552f\u4e00\u5236\u7ea6\u56e0\u7d20\u5c31\u662f\u76f8\u90bb\u7684\u623f\u5c4b\u88c5\u6709\u76f8\u4e92\u8fde\u901a\u7684\u9632\u76d7\u7cfb\u7edf\uff0c\u5982\u679c\u4e24\u95f4\u76f8\u90bb\u7684\u623f\u5c4b\u5728\u540c\u4e00\u665a\u4e0a\u88ab\u5c0f\u5077\u95ef\u5165\uff0c\u7cfb\u7edf\u4f1a\u81ea\u52a8\u62a5\u8b66\u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u4ee3\u8868\u6bcf\u4e2a\u623f\u5c4b\u5b58\u653e\u91d1\u989d\u7684\u975e\u8d1f\u6574\u6570\u6570\u7ec4\uff0c\u8ba1\u7b97\u4f60 \u4e0d\u89e6\u52a8\u8b66\u62a5\u88c5\u7f6e\u7684\u60c5\u51b5\u4e0b \uff0c\u4e00\u591c\u4e4b\u5185\u80fd\u591f\u5077\u7a83\u5230\u7684\u6700\u9ad8\u91d1\u989d\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[1,2,3,1]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u5077\u7a83 1 \u53f7\u623f\u5c4b (\u91d1\u989d = 1) \uff0c\u7136\u540e\u5077\u7a83 3 \u53f7\u623f\u5c4b (\u91d1\u989d = 3)\u3002\n\u00a0    \u5077\u7a83\u5230\u7684\u6700\u9ad8\u91d1\u989d = 1 + 3 = 4 \u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[2,7,9,3,1]\n\u8f93\u51fa\uff1a12\n\u89e3\u91ca\uff1a\u5077\u7a83 1 \u53f7\u623f\u5c4b (\u91d1\u989d = 2), \u5077\u7a83 3 \u53f7\u623f\u5c4b (\u91d1\u989d = 9)\uff0c\u63a5\u7740\u5077\u7a83 5 \u53f7\u623f\u5c4b (\u91d1\u989d = 1)\u3002\n\u00a0    \u5077\u7a83\u5230\u7684\u6700\u9ad8\u91d1\u989d = 2 + 9 + 1 = 12 \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 100
    • \n\t
    • 0 <= nums[i] <= 400
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int rob(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int rob(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def rob(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def rob(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint rob(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int Rob(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar rob = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef rob(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func rob(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func rob(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def rob(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun rob(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn rob(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function rob($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function rob(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (rob nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0198](https://leetcode-cn.com/problems/house-robber)", "[\u6253\u5bb6\u52ab\u820d](/solution/0100-0199/0198.House%20Robber/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0198](https://leetcode.com/problems/house-robber)", "[House Robber](/solution/0100-0199/0198.House%20Robber/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0197", "frontend_question_id": "0197", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/rising-temperature", "url_en": "https://leetcode.com/problems/rising-temperature", "relative_path_cn": "/solution/0100-0199/0197.Rising%20Temperature/README.md", "relative_path_en": "/solution/0100-0199/0197.Rising%20Temperature/README_EN.md", "title_cn": "\u4e0a\u5347\u7684\u6e29\u5ea6", "title_en": "Rising Temperature", "question_title_slug": "rising-temperature", "content_en": "

    Table: Weather

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| recordDate    | date    |\n| temperature   | int     |\n+---------------+---------+\nid is the primary key for this table.\nThis table contains information about the temperature in a certain day.\n
    \n\n

     

    \n\n

    Write an SQL query to find all dates' id with higher temperature compared to its previous dates (yesterday).

    \n\n

    Return the result table in any order.

    \n\n

    The query result format is in the following example:

    \n\n
    \nWeather\n+----+------------+-------------+\n| id | recordDate | Temperature |\n+----+------------+-------------+\n| 1  | 2015-01-01 | 10          |\n| 2  | 2015-01-02 | 25          |\n| 3  | 2015-01-03 | 20          |\n| 4  | 2015-01-04 | 30          |\n+----+------------+-------------+\n\nResult table:\n+----+\n| id |\n+----+\n| 2  |\n| 4  |\n+----+\nIn 2015-01-02, temperature was higher than the previous day (10 -> 25).\nIn 2015-01-04, temperature was higher than the previous day (20 -> 30).\n
    \n", "content_cn": "
    \n
    \n

    \u8868 Weather

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| recordDate    | date    |\n| temperature   | int     |\n+---------------+---------+\nid \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\n\u8be5\u8868\u5305\u542b\u7279\u5b9a\u65e5\u671f\u7684\u6e29\u5ea6\u4fe1\u606f
    \n\n

    \u00a0

    \n\n

    \u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\uff0c\u6765\u67e5\u627e\u4e0e\u4e4b\u524d\uff08\u6628\u5929\u7684\uff09\u65e5\u671f\u76f8\u6bd4\u6e29\u5ea6\u66f4\u9ad8\u7684\u6240\u6709\u65e5\u671f\u7684 id \u3002

    \n\n

    \u8fd4\u56de\u7ed3\u679c \u4e0d\u8981\u6c42\u987a\u5e8f \u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\uff1a

    \n\n
    \nWeather\n+----+------------+-------------+\n| id | recordDate | Temperature |\n+----+------------+-------------+\n| 1  | 2015-01-01 | 10          |\n| 2  | 2015-01-02 | 25          |\n| 3  | 2015-01-03 | 20          |\n| 4  | 2015-01-04 | 30          |\n+----+------------+-------------+\n\nResult table:\n+----+\n| id |\n+----+\n| 2  |\n| 4  |\n+----+\n2015-01-02 \u7684\u6e29\u5ea6\u6bd4\u524d\u4e00\u5929\u9ad8\uff0810 -> 25\uff09\n2015-01-04 \u7684\u6e29\u5ea6\u6bd4\u524d\u4e00\u5929\u9ad8\uff0820 -> 30\uff09\n
    \n
    \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0197](https://leetcode-cn.com/problems/rising-temperature)", "[\u4e0a\u5347\u7684\u6e29\u5ea6](/solution/0100-0199/0197.Rising%20Temperature/README.md)", "", "\u7b80\u5355", ""], "md_table_row_en": ["[0197](https://leetcode.com/problems/rising-temperature)", "[Rising Temperature](/solution/0100-0199/0197.Rising%20Temperature/README_EN.md)", "", "Easy", ""]}, {"question_id": "0196", "frontend_question_id": "0196", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/delete-duplicate-emails", "url_en": "https://leetcode.com/problems/delete-duplicate-emails", "relative_path_cn": "/solution/0100-0199/0196.Delete%20Duplicate%20Emails/README.md", "relative_path_en": "/solution/0100-0199/0196.Delete%20Duplicate%20Emails/README_EN.md", "title_cn": "\u5220\u9664\u91cd\u590d\u7684\u7535\u5b50\u90ae\u7bb1", "title_en": "Delete Duplicate Emails", "question_title_slug": "delete-duplicate-emails", "content_en": "

    Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique emails based on its smallest Id.

    \r\n\r\n
    \r\n+----+------------------+\r\n| Id | Email            |\r\n+----+------------------+\r\n| 1  | john@example.com |\r\n| 2  | bob@example.com  |\r\n| 3  | john@example.com |\r\n+----+------------------+\r\nId is the primary key column for this table.\r\n
    \r\n\r\n

    For example, after running your query, the above Person table should have the following rows:

    \r\n\r\n
    \r\n+----+------------------+\r\n| Id | Email            |\r\n+----+------------------+\r\n| 1  | john@example.com |\r\n| 2  | bob@example.com  |\r\n+----+------------------+\r\n
    \r\n\r\n

    Note:

    \r\n\r\n

    Your output is the whole Person table after executing your sql. Use delete statement.

    \r\n", "content_cn": "

    \u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\uff0c\u6765\u5220\u9664 Person \u8868\u4e2d\u6240\u6709\u91cd\u590d\u7684\u7535\u5b50\u90ae\u7bb1\uff0c\u91cd\u590d\u7684\u90ae\u7bb1\u91cc\u53ea\u4fdd\u7559 Id \u6700\u5c0f \u7684\u90a3\u4e2a\u3002

    \n\n
    +----+------------------+\n| Id | Email            |\n+----+------------------+\n| 1  | john@example.com |\n| 2  | bob@example.com  |\n| 3  | john@example.com |\n+----+------------------+\nId \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\u3002\n
    \n\n

    \u4f8b\u5982\uff0c\u5728\u8fd0\u884c\u4f60\u7684\u67e5\u8be2\u8bed\u53e5\u4e4b\u540e\uff0c\u4e0a\u9762\u7684 Person \u8868\u5e94\u8fd4\u56de\u4ee5\u4e0b\u51e0\u884c:

    \n\n
    +----+------------------+\n| Id | Email            |\n+----+------------------+\n| 1  | john@example.com |\n| 2  | bob@example.com  |\n+----+------------------+\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6267\u884c SQL \u4e4b\u540e\uff0c\u8f93\u51fa\u662f\u6574\u4e2a Person \u8868\u3002
    • \n\t
    • \u4f7f\u7528 delete \u8bed\u53e5\u3002
    • \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0196](https://leetcode-cn.com/problems/delete-duplicate-emails)", "[\u5220\u9664\u91cd\u590d\u7684\u7535\u5b50\u90ae\u7bb1](/solution/0100-0199/0196.Delete%20Duplicate%20Emails/README.md)", "", "\u7b80\u5355", ""], "md_table_row_en": ["[0196](https://leetcode.com/problems/delete-duplicate-emails)", "[Delete Duplicate Emails](/solution/0100-0199/0196.Delete%20Duplicate%20Emails/README_EN.md)", "", "Easy", ""]}, {"question_id": "0195", "frontend_question_id": "0195", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/tenth-line", "url_en": "https://leetcode.com/problems/tenth-line", "relative_path_cn": "/solution/0100-0199/0195.Tenth%20Line/README.md", "relative_path_en": "/solution/0100-0199/0195.Tenth%20Line/README_EN.md", "title_cn": "\u7b2c\u5341\u884c", "title_en": "Tenth Line", "question_title_slug": "tenth-line", "content_en": "

    Given a text file file.txt, print just the 10th line of the file.

    \r\n\r\n

    Example:

    \r\n\r\n

    Assume that file.txt has the following content:

    \r\n\r\n
    \r\nLine 1\r\nLine 2\r\nLine 3\r\nLine 4\r\nLine 5\r\nLine 6\r\nLine 7\r\nLine 8\r\nLine 9\r\nLine 10\r\n
    \r\n\r\n

    Your script should output the tenth line, which is:

    \r\n\r\n
    \r\nLine 10\r\n
    \r\n\r\n
    Note:
    \r\n1. If the file contains less than 10 lines, what should you output?
    \r\n2. There's at least three different solutions. Try to explore all possibilities.
    \r\n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6587\u672c\u6587\u4ef6 file.txt\uff0c\u8bf7\u53ea\u6253\u5370\u8fd9\u4e2a\u6587\u4ef6\u4e2d\u7684\u7b2c\u5341\u884c\u3002

    \n\n

    \u793a\u4f8b:

    \n\n

    \u5047\u8bbe file.txt \u6709\u5982\u4e0b\u5185\u5bb9\uff1a

    \n\n
    Line 1\nLine 2\nLine 3\nLine 4\nLine 5\nLine 6\nLine 7\nLine 8\nLine 9\nLine 10\n
    \n\n

    \u4f60\u7684\u811a\u672c\u5e94\u5f53\u663e\u793a\u7b2c\u5341\u884c\uff1a

    \n\n
    Line 10\n
    \n\n

    \u8bf4\u660e:
    \n1. \u5982\u679c\u6587\u4ef6\u5c11\u4e8e\u5341\u884c\uff0c\u4f60\u5e94\u5f53\u8f93\u51fa\u4ec0\u4e48\uff1f
    \n2. \u81f3\u5c11\u6709\u4e09\u79cd\u4e0d\u540c\u7684\u89e3\u6cd5\uff0c\u8bf7\u5c1d\u8bd5\u5c3d\u53ef\u80fd\u591a\u7684\u65b9\u6cd5\u6765\u89e3\u9898\u3002

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "Bash", "langSlug": "bash", "code": "# Read from the file file.txt and output the tenth line to stdout.", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0195](https://leetcode-cn.com/problems/tenth-line)", "[\u7b2c\u5341\u884c](/solution/0100-0199/0195.Tenth%20Line/README.md)", "", "\u7b80\u5355", ""], "md_table_row_en": ["[0195](https://leetcode.com/problems/tenth-line)", "[Tenth Line](/solution/0100-0199/0195.Tenth%20Line/README_EN.md)", "", "Easy", ""]}, {"question_id": "0194", "frontend_question_id": "0194", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/transpose-file", "url_en": "https://leetcode.com/problems/transpose-file", "relative_path_cn": "/solution/0100-0199/0194.Transpose%20File/README.md", "relative_path_en": "/solution/0100-0199/0194.Transpose%20File/README_EN.md", "title_cn": "\u8f6c\u7f6e\u6587\u4ef6", "title_en": "Transpose File", "question_title_slug": "transpose-file", "content_en": "

    Given a text file file.txt, transpose its content.

    \n\n

    You may assume that each row has the same number of columns, and each field is separated by the ' ' character.

    \n\n

    Example:

    \n\n

    If file.txt has the following content:

    \n\n
    \nname age\nalice 21\nryan 30\n
    \n\n

    Output the following:

    \n\n
    \nname alice ryan\nage 21 30\n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6587\u4ef6\u00a0file.txt\uff0c\u8f6c\u7f6e\u5b83\u7684\u5185\u5bb9\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u5047\u8bbe\u6bcf\u884c\u5217\u6570\u76f8\u540c\uff0c\u5e76\u4e14\u6bcf\u4e2a\u5b57\u6bb5\u7531\u00a0' ' \u5206\u9694\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n

    \u5047\u8bbe\u00a0file.txt\u00a0\u6587\u4ef6\u5185\u5bb9\u5982\u4e0b\uff1a

    \n\n
    \nname age\nalice 21\nryan 30\n
    \n\n

    \u5e94\u5f53\u8f93\u51fa\uff1a

    \n\n
    \nname alice ryan\nage 21 30\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "Bash", "langSlug": "bash", "code": "# Read from the file file.txt and print its transposed content to stdout.", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0194](https://leetcode-cn.com/problems/transpose-file)", "[\u8f6c\u7f6e\u6587\u4ef6](/solution/0100-0199/0194.Transpose%20File/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0194](https://leetcode.com/problems/transpose-file)", "[Transpose File](/solution/0100-0199/0194.Transpose%20File/README_EN.md)", "", "Medium", ""]}, {"question_id": "0193", "frontend_question_id": "0193", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/valid-phone-numbers", "url_en": "https://leetcode.com/problems/valid-phone-numbers", "relative_path_cn": "/solution/0100-0199/0193.Valid%20Phone%20Numbers/README.md", "relative_path_en": "/solution/0100-0199/0193.Valid%20Phone%20Numbers/README_EN.md", "title_cn": "\u6709\u6548\u7535\u8bdd\u53f7\u7801", "title_en": "Valid Phone Numbers", "question_title_slug": "valid-phone-numbers", "content_en": "

    Given a text file file.txt that contains a list of phone numbers (one per line), write a one-liner bash script to print all valid phone numbers.

    \n\n

    You may assume that a valid phone number must appear in one of the following two formats: (xxx) xxx-xxxx or xxx-xxx-xxxx. (x means a digit)

    \n\n

    You may also assume each line in the text file must not contain leading or trailing white spaces.

    \n\n

    Example:

    \n\n

    Assume that file.txt has the following content:

    \n\n
    \n987-123-4567\n123 456 7890\n(123) 456-7890\n
    \n\n

    Your script should output the following valid phone numbers:

    \n\n
    \n987-123-4567\n(123) 456-7890\n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5305\u542b\u7535\u8bdd\u53f7\u7801\u5217\u8868\uff08\u4e00\u884c\u4e00\u4e2a\u7535\u8bdd\u53f7\u7801\uff09\u7684\u6587\u672c\u6587\u4ef6 file.txt\uff0c\u5199\u4e00\u4e2a\u5355\u884c bash \u811a\u672c\u8f93\u51fa\u6240\u6709\u6709\u6548\u7684\u7535\u8bdd\u53f7\u7801\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u5047\u8bbe\u4e00\u4e2a\u6709\u6548\u7684\u7535\u8bdd\u53f7\u7801\u5fc5\u987b\u6ee1\u8db3\u4ee5\u4e0b\u4e24\u79cd\u683c\u5f0f\uff1a (xxx) xxx-xxxx \u6216\u00a0xxx-xxx-xxxx\u3002\uff08x \u8868\u793a\u4e00\u4e2a\u6570\u5b57\uff09

    \n\n

    \u4f60\u4e5f\u53ef\u4ee5\u5047\u8bbe\u6bcf\u884c\u524d\u540e\u6ca1\u6709\u591a\u4f59\u7684\u7a7a\u683c\u5b57\u7b26\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n

    \u5047\u8bbe\u00a0file.txt\u00a0\u5185\u5bb9\u5982\u4e0b\uff1a

    \n\n
    \n987-123-4567\n123 456 7890\n(123) 456-7890\n
    \n\n

    \u4f60\u7684\u811a\u672c\u5e94\u5f53\u8f93\u51fa\u4e0b\u5217\u6709\u6548\u7684\u7535\u8bdd\u53f7\u7801\uff1a

    \n\n
    \n987-123-4567\n(123) 456-7890\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "Bash", "langSlug": "bash", "code": "# Read from the file file.txt and output all valid phone numbers to stdout.", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0193](https://leetcode-cn.com/problems/valid-phone-numbers)", "[\u6709\u6548\u7535\u8bdd\u53f7\u7801](/solution/0100-0199/0193.Valid%20Phone%20Numbers/README.md)", "", "\u7b80\u5355", ""], "md_table_row_en": ["[0193](https://leetcode.com/problems/valid-phone-numbers)", "[Valid Phone Numbers](/solution/0100-0199/0193.Valid%20Phone%20Numbers/README_EN.md)", "", "Easy", ""]}, {"question_id": "0192", "frontend_question_id": "0192", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/word-frequency", "url_en": "https://leetcode.com/problems/word-frequency", "relative_path_cn": "/solution/0100-0199/0192.Word%20Frequency/README.md", "relative_path_en": "/solution/0100-0199/0192.Word%20Frequency/README_EN.md", "title_cn": "\u7edf\u8ba1\u8bcd\u9891", "title_en": "Word Frequency", "question_title_slug": "word-frequency", "content_en": "

    Write a bash script to calculate the frequency of each word in a text file words.txt.

    \r\n\r\n

    For simplicity sake, you may assume:

    \r\n\r\n
      \r\n\t
    • words.txt contains only lowercase characters and space ' ' characters.
    • \r\n\t
    • Each word must consist of lowercase characters only.
    • \r\n\t
    • Words are separated by one or more whitespace characters.
    • \r\n
    \r\n\r\n

    Example:

    \r\n\r\n

    Assume that words.txt has the following content:

    \r\n\r\n
    \r\nthe day is sunny the the\r\nthe sunny is is\r\n
    \r\n\r\n

    Your script should output the following, sorted by descending frequency:

    \r\n\r\n
    \r\nthe 4\r\nis 3\r\nsunny 2\r\nday 1\r\n
    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    • Don't worry about handling ties, it is guaranteed that each word's frequency count is unique.
    • \r\n\t
    • Could you write it in one-line using Unix pipes?
    • \r\n
    \r\n", "content_cn": "

    \u5199\u4e00\u4e2a bash \u811a\u672c\u4ee5\u7edf\u8ba1\u4e00\u4e2a\u6587\u672c\u6587\u4ef6 words.txt \u4e2d\u6bcf\u4e2a\u5355\u8bcd\u51fa\u73b0\u7684\u9891\u7387\u3002

    \n\n

    \u4e3a\u4e86\u7b80\u5355\u8d77\u89c1\uff0c\u4f60\u53ef\u4ee5\u5047\u8bbe\uff1a

    \n\n
      \n\t
    • words.txt\u53ea\u5305\u62ec\u5c0f\u5199\u5b57\u6bcd\u548c ' ' \u3002
    • \n\t
    • \u6bcf\u4e2a\u5355\u8bcd\u53ea\u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210\u3002
    • \n\t
    • \u5355\u8bcd\u95f4\u7531\u4e00\u4e2a\u6216\u591a\u4e2a\u7a7a\u683c\u5b57\u7b26\u5206\u9694\u3002
    • \n
    \n\n

    \u793a\u4f8b:

    \n\n

    \u5047\u8bbe words.txt \u5185\u5bb9\u5982\u4e0b\uff1a

    \n\n
    the day is sunny the the\nthe sunny is is\n
    \n\n

    \u4f60\u7684\u811a\u672c\u5e94\u5f53\u8f93\u51fa\uff08\u4ee5\u8bcd\u9891\u964d\u5e8f\u6392\u5217\uff09\uff1a

    \n\n
    the 4\nis 3\nsunny 2\nday 1\n
    \n\n

    \u8bf4\u660e:

    \n\n
      \n\t
    • \u4e0d\u8981\u62c5\u5fc3\u8bcd\u9891\u76f8\u540c\u7684\u5355\u8bcd\u7684\u6392\u5e8f\u95ee\u9898\uff0c\u6bcf\u4e2a\u5355\u8bcd\u51fa\u73b0\u7684\u9891\u7387\u90fd\u662f\u552f\u4e00\u7684\u3002
    • \n\t
    • \u4f60\u53ef\u4ee5\u4f7f\u7528\u4e00\u884c Unix pipes \u5b9e\u73b0\u5417\uff1f
    • \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "Bash", "langSlug": "bash", "code": "# Read from the file words.txt and output the word frequency list to stdout.", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0192](https://leetcode-cn.com/problems/word-frequency)", "[\u7edf\u8ba1\u8bcd\u9891](/solution/0100-0199/0192.Word%20Frequency/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0192](https://leetcode.com/problems/word-frequency)", "[Word Frequency](/solution/0100-0199/0192.Word%20Frequency/README_EN.md)", "", "Medium", ""]}, {"question_id": "0191", "frontend_question_id": "0191", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-1-bits", "url_en": "https://leetcode.com/problems/number-of-1-bits", "relative_path_cn": "/solution/0100-0199/0191.Number%20of%201%20Bits/README.md", "relative_path_en": "/solution/0100-0199/0191.Number%20of%201%20Bits/README_EN.md", "title_cn": "\u4f4d1\u7684\u4e2a\u6570", "title_en": "Number of 1 Bits", "question_title_slug": "number-of-1-bits", "content_en": "

    Write a function that takes an unsigned integer and returns the number of '1' bits it has (also known as the Hamming weight).

    \n\n

    Note:

    \n\n
      \n\t
    • Note that in some languages, such as Java, there is no unsigned integer type. In this case, the input will be given as a signed integer type. It should not affect your implementation, as the integer's internal binary representation is the same, whether it is signed or unsigned.
    • \n\t
    • In Java, the compiler represents the signed integers using 2's complement notation. Therefore, in Example 3, the input represents the signed integer. -3.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 00000000000000000000000000001011\nOutput: 3\nExplanation: The input binary string 00000000000000000000000000001011 has a total of three '1' bits.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 00000000000000000000000010000000\nOutput: 1\nExplanation: The input binary string 00000000000000000000000010000000 has a total of one '1' bit.\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 11111111111111111111111111111101\nOutput: 31\nExplanation: The input binary string 11111111111111111111111111111101 has a total of thirty one '1' bits.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The input must be a binary string of length 32.
    • \n
    \n\n

     

    \nFollow up: If this function is called many times, how would you optimize it?", "content_cn": "

    \u7f16\u5199\u4e00\u4e2a\u51fd\u6570\uff0c\u8f93\u5165\u662f\u4e00\u4e2a\u65e0\u7b26\u53f7\u6574\u6570\uff08\u4ee5\u4e8c\u8fdb\u5236\u4e32\u7684\u5f62\u5f0f\uff09\uff0c\u8fd4\u56de\u5176\u4e8c\u8fdb\u5236\u8868\u8fbe\u5f0f\u4e2d\u6570\u5b57\u4f4d\u6570\u4e3a '1' \u7684\u4e2a\u6570\uff08\u4e5f\u88ab\u79f0\u4e3a\u6c49\u660e\u91cd\u91cf\uff09\u3002

    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u8bf7\u6ce8\u610f\uff0c\u5728\u67d0\u4e9b\u8bed\u8a00\uff08\u5982 Java\uff09\u4e2d\uff0c\u6ca1\u6709\u65e0\u7b26\u53f7\u6574\u6570\u7c7b\u578b\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u8f93\u5165\u548c\u8f93\u51fa\u90fd\u5c06\u88ab\u6307\u5b9a\u4e3a\u6709\u7b26\u53f7\u6574\u6570\u7c7b\u578b\uff0c\u5e76\u4e14\u4e0d\u5e94\u5f71\u54cd\u60a8\u7684\u5b9e\u73b0\uff0c\u56e0\u4e3a\u65e0\u8bba\u6574\u6570\u662f\u6709\u7b26\u53f7\u7684\u8fd8\u662f\u65e0\u7b26\u53f7\u7684\uff0c\u5176\u5185\u90e8\u7684\u4e8c\u8fdb\u5236\u8868\u793a\u5f62\u5f0f\u90fd\u662f\u76f8\u540c\u7684\u3002
    • \n\t
    • \u5728 Java \u4e2d\uff0c\u7f16\u8bd1\u5668\u4f7f\u7528\u4e8c\u8fdb\u5236\u8865\u7801\u8bb0\u6cd5\u6765\u8868\u793a\u6709\u7b26\u53f7\u6574\u6570\u3002\u56e0\u6b64\uff0c\u5728\u4e0a\u9762\u7684\u00a0\u793a\u4f8b 3\u00a0\u4e2d\uff0c\u8f93\u5165\u8868\u793a\u6709\u7b26\u53f7\u6574\u6570 -3\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1a00000000000000000000000000001011\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u8f93\u5165\u7684\u4e8c\u8fdb\u5236\u4e32 00000000000000000000000000001011\u00a0\u4e2d\uff0c\u5171\u6709\u4e09\u4f4d\u4e3a '1'\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1a00000000000000000000000010000000\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u8f93\u5165\u7684\u4e8c\u8fdb\u5236\u4e32 00000000000000000000000010000000\u00a0\u4e2d\uff0c\u5171\u6709\u4e00\u4f4d\u4e3a '1'\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1a11111111111111111111111111111101\n\u8f93\u51fa\uff1a31\n\u89e3\u91ca\uff1a\u8f93\u5165\u7684\u4e8c\u8fdb\u5236\u4e32 11111111111111111111111111111101 \u4e2d\uff0c\u5171\u6709 31 \u4f4d\u4e3a '1'\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u8f93\u5165\u5fc5\u987b\u662f\u957f\u5ea6\u4e3a 32 \u7684 \u4e8c\u8fdb\u5236\u4e32 \u3002
    • \n
    \n\n
      \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u5982\u679c\u591a\u6b21\u8c03\u7528\u8fd9\u4e2a\u51fd\u6570\uff0c\u4f60\u5c06\u5982\u4f55\u4f18\u5316\u4f60\u7684\u7b97\u6cd5\uff1f
    • \n
    \n", "tags_en": ["Bit Manipulation"], "tags_cn": ["\u4f4d\u8fd0\u7b97"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int hammingWeight(uint32_t n) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "public class Solution {\n // you need to treat n as an unsigned value\n public int hammingWeight(int n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def hammingWeight(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def hammingWeight(self, n: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "int hammingWeight(uint32_t n) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int HammingWeight(uint n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n - a positive integer\n * @return {number}\n */\nvar hammingWeight = function(n) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n, a positive integer\n# @return {Integer}\ndef hamming_weight(n)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func hammingWeight(_ n: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func hammingWeight(num uint32) int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n // you need treat n as an unsigned value\n def hammingWeight(n: Int): Int = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n // you need treat n as an unsigned value\n fun hammingWeight(n:Int):Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn hammingWeight (n: u32) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n /**\n * @param Integer $n\n * @return Integer\n */\n function hammingWeight($n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function hammingWeight(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0191](https://leetcode-cn.com/problems/number-of-1-bits)", "[\u4f4d1\u7684\u4e2a\u6570](/solution/0100-0199/0191.Number%20of%201%20Bits/README.md)", "`\u4f4d\u8fd0\u7b97`", "\u7b80\u5355", ""], "md_table_row_en": ["[0191](https://leetcode.com/problems/number-of-1-bits)", "[Number of 1 Bits](/solution/0100-0199/0191.Number%20of%201%20Bits/README_EN.md)", "`Bit Manipulation`", "Easy", ""]}, {"question_id": "0190", "frontend_question_id": "0190", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reverse-bits", "url_en": "https://leetcode.com/problems/reverse-bits", "relative_path_cn": "/solution/0100-0199/0190.Reverse%20Bits/README.md", "relative_path_en": "/solution/0100-0199/0190.Reverse%20Bits/README_EN.md", "title_cn": "\u98a0\u5012\u4e8c\u8fdb\u5236\u4f4d", "title_en": "Reverse Bits", "question_title_slug": "reverse-bits", "content_en": "

    Reverse bits of a given 32 bits unsigned integer.

    \n\n

    Note:

    \n\n
      \n\t
    • Note that in some languages such as Java, there is no unsigned integer type. In this case, both input and output will be given as a signed integer type. They should not affect your implementation, as the integer's internal binary representation is the same, whether it is signed or unsigned.
    • \n\t
    • In Java, the compiler represents the signed integers using 2's complement notation. Therefore, in Example 2 above, the input represents the signed integer -3 and the output represents the signed integer -1073741825.
    • \n
    \n\n

    Follow up:

    \n\n

    If this function is called many times, how would you optimize it?

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 00000010100101000001111010011100\nOutput:    964176192 (00111001011110000010100101000000)\nExplanation: The input binary string 00000010100101000001111010011100 represents the unsigned integer 43261596, so return 964176192 which its binary representation is 00111001011110000010100101000000.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 11111111111111111111111111111101\nOutput:   3221225471 (10111111111111111111111111111111)\nExplanation: The input binary string 11111111111111111111111111111101 represents the unsigned integer 4294967293, so return 3221225471 which its binary representation is 10111111111111111111111111111111.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The input must be a binary string of length 32
    • \n
    \n", "content_cn": "

    \u98a0\u5012\u7ed9\u5b9a\u7684 32 \u4f4d\u65e0\u7b26\u53f7\u6574\u6570\u7684\u4e8c\u8fdb\u5236\u4f4d\u3002

    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u8bf7\u6ce8\u610f\uff0c\u5728\u67d0\u4e9b\u8bed\u8a00\uff08\u5982 Java\uff09\u4e2d\uff0c\u6ca1\u6709\u65e0\u7b26\u53f7\u6574\u6570\u7c7b\u578b\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u8f93\u5165\u548c\u8f93\u51fa\u90fd\u5c06\u88ab\u6307\u5b9a\u4e3a\u6709\u7b26\u53f7\u6574\u6570\u7c7b\u578b\uff0c\u5e76\u4e14\u4e0d\u5e94\u5f71\u54cd\u60a8\u7684\u5b9e\u73b0\uff0c\u56e0\u4e3a\u65e0\u8bba\u6574\u6570\u662f\u6709\u7b26\u53f7\u7684\u8fd8\u662f\u65e0\u7b26\u53f7\u7684\uff0c\u5176\u5185\u90e8\u7684\u4e8c\u8fdb\u5236\u8868\u793a\u5f62\u5f0f\u90fd\u662f\u76f8\u540c\u7684\u3002
    • \n\t
    • \u5728 Java \u4e2d\uff0c\u7f16\u8bd1\u5668\u4f7f\u7528\u4e8c\u8fdb\u5236\u8865\u7801\u8bb0\u6cd5\u6765\u8868\u793a\u6709\u7b26\u53f7\u6574\u6570\u3002\u56e0\u6b64\uff0c\u5728\u4e0a\u9762\u7684\u00a0\u793a\u4f8b 2\u00a0\u4e2d\uff0c\u8f93\u5165\u8868\u793a\u6709\u7b26\u53f7\u6574\u6570 -3\uff0c\u8f93\u51fa\u8868\u793a\u6709\u7b26\u53f7\u6574\u6570 -1073741825\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636:
    \n\u5982\u679c\u591a\u6b21\u8c03\u7528\u8fd9\u4e2a\u51fd\u6570\uff0c\u4f60\u5c06\u5982\u4f55\u4f18\u5316\u4f60\u7684\u7b97\u6cd5\uff1f

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165: 00000010100101000001111010011100\n\u8f93\u51fa: 00111001011110000010100101000000\n\u89e3\u91ca: \u8f93\u5165\u7684\u4e8c\u8fdb\u5236\u4e32 00000010100101000001111010011100 \u8868\u793a\u65e0\u7b26\u53f7\u6574\u6570 43261596\uff0c\n     \u56e0\u6b64\u8fd4\u56de 964176192\uff0c\u5176\u4e8c\u8fdb\u5236\u8868\u793a\u5f62\u5f0f\u4e3a 00111001011110000010100101000000\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1a11111111111111111111111111111101\n\u8f93\u51fa\uff1a10111111111111111111111111111111\n\u89e3\u91ca\uff1a\u8f93\u5165\u7684\u4e8c\u8fdb\u5236\u4e32 11111111111111111111111111111101 \u8868\u793a\u65e0\u7b26\u53f7\u6574\u6570 4294967293\uff0c\n\u00a0    \u56e0\u6b64\u8fd4\u56de 3221225471 \u5176\u4e8c\u8fdb\u5236\u8868\u793a\u5f62\u5f0f\u4e3a 10111111111111111111111111111111 \u3002
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 00000010100101000001111010011100\n\u8f93\u51fa\uff1a964176192 (00111001011110000010100101000000)\n\u89e3\u91ca\uff1a\u8f93\u5165\u7684\u4e8c\u8fdb\u5236\u4e32 00000010100101000001111010011100 \u8868\u793a\u65e0\u7b26\u53f7\u6574\u6570 43261596\uff0c\n     \u56e0\u6b64\u8fd4\u56de 964176192\uff0c\u5176\u4e8c\u8fdb\u5236\u8868\u793a\u5f62\u5f0f\u4e3a 00111001011110000010100101000000\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 11111111111111111111111111111101\n\u8f93\u51fa\uff1a3221225471 (10111111111111111111111111111111)\n\u89e3\u91ca\uff1a\u8f93\u5165\u7684\u4e8c\u8fdb\u5236\u4e32 11111111111111111111111111111101 \u8868\u793a\u65e0\u7b26\u53f7\u6574\u6570 4294967293\uff0c\n   \u00a0 \u56e0\u6b64\u8fd4\u56de 3221225471 \u5176\u4e8c\u8fdb\u5236\u8868\u793a\u5f62\u5f0f\u4e3a 10111111111111111111111111111111 \u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u8f93\u5165\u662f\u4e00\u4e2a\u957f\u5ea6\u4e3a 32 \u7684\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32
    • \n
    \n", "tags_en": ["Bit Manipulation"], "tags_cn": ["\u4f4d\u8fd0\u7b97"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n uint32_t reverseBits(uint32_t n) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "public class Solution {\n // you need treat n as an unsigned value\n public int reverseBits(int n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution:\n # @param n, an integer\n # @return an integer\n def reverseBits(self, n):\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def reverseBits(self, n: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "uint32_t reverseBits(uint32_t n) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public uint reverseBits(uint n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n - a positive integer\n * @return {number} - a positive integer\n */\nvar reverseBits = function(n) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n, a positive integer\n# @return {Integer}\ndef reverse_bits(n)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func reverseBits(_ n: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func reverseBits(num uint32) uint32 {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n // you need treat n as an unsigned value\n def reverseBits(x: Int): Int = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n // you need treat n as an unsigned value\n fun reverseBits(n:Int):Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn reverse_bits(x: u32) -> u32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n /**\n * @param Integer $n\n * @return Integer\n */\n function reverseBits($n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function reverseBits(n: number): number {\n\t\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0190](https://leetcode-cn.com/problems/reverse-bits)", "[\u98a0\u5012\u4e8c\u8fdb\u5236\u4f4d](/solution/0100-0199/0190.Reverse%20Bits/README.md)", "`\u4f4d\u8fd0\u7b97`", "\u7b80\u5355", ""], "md_table_row_en": ["[0190](https://leetcode.com/problems/reverse-bits)", "[Reverse Bits](/solution/0100-0199/0190.Reverse%20Bits/README_EN.md)", "`Bit Manipulation`", "Easy", ""]}, {"question_id": "0189", "frontend_question_id": "0189", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/rotate-array", "url_en": "https://leetcode.com/problems/rotate-array", "relative_path_cn": "/solution/0100-0199/0189.Rotate%20Array/README.md", "relative_path_en": "/solution/0100-0199/0189.Rotate%20Array/README_EN.md", "title_cn": "\u65cb\u8f6c\u6570\u7ec4", "title_en": "Rotate Array", "question_title_slug": "rotate-array", "content_en": "

    Given an array, rotate the array to the right by k steps, where k is non-negative.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,3,4,5,6,7], k = 3\nOutput: [5,6,7,1,2,3,4]\nExplanation:\nrotate 1 steps to the right: [7,1,2,3,4,5,6]\nrotate 2 steps to the right: [6,7,1,2,3,4,5]\nrotate 3 steps to the right: [5,6,7,1,2,3,4]\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [-1,-100,3,99], k = 2\nOutput: [3,99,-1,-100]\nExplanation: \nrotate 1 steps to the right: [99,-1,-100,3]\nrotate 2 steps to the right: [3,99,-1,-100]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n\t
    • 0 <= k <= 105
    • \n
    \n\n

     

    \n

    Follow up:

    \n\n
      \n\t
    • Try to come up with as many solutions as you can. There are at least three different ways to solve this problem.
    • \n\t
    • Could you do it in-place with O(1) extra space?
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6570\u7ec4\uff0c\u5c06\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u5411\u53f3\u79fb\u52a8\u00a0k\u00a0\u4e2a\u4f4d\u7f6e\uff0c\u5176\u4e2d\u00a0k\u00a0\u662f\u975e\u8d1f\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u5c3d\u53ef\u80fd\u60f3\u51fa\u66f4\u591a\u7684\u89e3\u51b3\u65b9\u6848\uff0c\u81f3\u5c11\u6709\u4e09\u79cd\u4e0d\u540c\u7684\u65b9\u6cd5\u53ef\u4ee5\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u3002
    • \n\t
    • \u4f60\u53ef\u4ee5\u4f7f\u7528\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a\u00a0O(1) \u7684\u00a0\u539f\u5730\u00a0\u7b97\u6cd5\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u5417\uff1f
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: nums = [1,2,3,4,5,6,7], k = 3\n\u8f93\u51fa: [5,6,7,1,2,3,4]\n\u89e3\u91ca:\n\u5411\u53f3\u65cb\u8f6c 1 \u6b65: [7,1,2,3,4,5,6]\n\u5411\u53f3\u65cb\u8f6c 2 \u6b65: [6,7,1,2,3,4,5]\n\u5411\u53f3\u65cb\u8f6c 3 \u6b65: [5,6,7,1,2,3,4]\n
    \n\n

    \u793a\u4f8b\u00a02:

    \n\n
    \n\u8f93\u5165\uff1anums = [-1,-100,3,99], k = 2\n\u8f93\u51fa\uff1a[3,99,-1,-100]\n\u89e3\u91ca: \n\u5411\u53f3\u65cb\u8f6c 1 \u6b65: [99,-1,-100,3]\n\u5411\u53f3\u65cb\u8f6c 2 \u6b65: [3,99,-1,-100]
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 2 * 104
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n\t
    • 0 <= k <= 105
    • \n
    \n\n
      \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n void rotate(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public void rotate(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def rotate(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: None Do not return anything, modify nums in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def rotate(self, nums: List[int], k: int) -> None:\n \"\"\"\n Do not return anything, modify nums in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nvoid rotate(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public void Rotate(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {void} Do not return anything, modify nums in-place instead.\n */\nvar rotate = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Void} Do not return anything, modify nums in-place instead.\ndef rotate(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func rotate(_ nums: inout [Int], _ k: Int) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func rotate(nums []int, k int) {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def rotate(nums: Array[Int], k: Int): Unit = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun rotate(nums: IntArray, k: Int): Unit {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn rotate(nums: &mut Vec, k: i32) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return NULL\n */\n function rotate(&$nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n Do not return anything, modify nums in-place instead.\n */\nfunction rotate(nums: number[], k: number): void {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0189](https://leetcode-cn.com/problems/rotate-array)", "[\u65cb\u8f6c\u6570\u7ec4](/solution/0100-0199/0189.Rotate%20Array/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0189](https://leetcode.com/problems/rotate-array)", "[Rotate Array](/solution/0100-0199/0189.Rotate%20Array/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0188", "frontend_question_id": "0188", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-iv", "url_en": "https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iv", "relative_path_cn": "/solution/0100-0199/0188.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20IV/README.md", "relative_path_en": "/solution/0100-0199/0188.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20IV/README_EN.md", "title_cn": "\u4e70\u5356\u80a1\u7968\u7684\u6700\u4f73\u65f6\u673a IV", "title_en": "Best Time to Buy and Sell Stock IV", "question_title_slug": "best-time-to-buy-and-sell-stock-iv", "content_en": "

    You are given an integer array prices where prices[i] is the price of a given stock on the ith day, and an integer k.

    \n\n

    Find the maximum profit you can achieve. You may complete at most k transactions.

    \n\n

    Note: You may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again).

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: k = 2, prices = [2,4,1]\nOutput: 2\nExplanation: Buy on day 1 (price = 2) and sell on day 2 (price = 4), profit = 4-2 = 2.\n
    \n\n

    Example 2:

    \n\n
    \nInput: k = 2, prices = [3,2,6,5,0,3]\nOutput: 7\nExplanation: Buy on day 2 (price = 2) and sell on day 3 (price = 6), profit = 6-2 = 4. Then buy on day 5 (price = 0) and sell on day 6 (price = 3), profit = 3-0 = 3.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= k <= 100
    • \n\t
    • 0 <= prices.length <= 1000
    • \n\t
    • 0 <= prices[i] <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0prices \uff0c\u5b83\u7684\u7b2c i \u4e2a\u5143\u7d20\u00a0prices[i] \u662f\u4e00\u652f\u7ed9\u5b9a\u7684\u80a1\u7968\u5728\u7b2c i \u5929\u7684\u4ef7\u683c\u3002

    \n\n

    \u8bbe\u8ba1\u4e00\u4e2a\u7b97\u6cd5\u6765\u8ba1\u7b97\u4f60\u6240\u80fd\u83b7\u53d6\u7684\u6700\u5927\u5229\u6da6\u3002\u4f60\u6700\u591a\u53ef\u4ee5\u5b8c\u6210 k \u7b14\u4ea4\u6613\u3002

    \n\n

    \u6ce8\u610f\uff1a\u4f60\u4e0d\u80fd\u540c\u65f6\u53c2\u4e0e\u591a\u7b14\u4ea4\u6613\uff08\u4f60\u5fc5\u987b\u5728\u518d\u6b21\u8d2d\u4e70\u524d\u51fa\u552e\u6389\u4e4b\u524d\u7684\u80a1\u7968\uff09\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1ak = 2, prices = [2,4,1]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5728\u7b2c 1 \u5929 (\u80a1\u7968\u4ef7\u683c = 2) \u7684\u65f6\u5019\u4e70\u5165\uff0c\u5728\u7b2c 2 \u5929 (\u80a1\u7968\u4ef7\u683c = 4) \u7684\u65f6\u5019\u5356\u51fa\uff0c\u8fd9\u7b14\u4ea4\u6613\u6240\u80fd\u83b7\u5f97\u5229\u6da6 = 4-2 = 2 \u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1ak = 2, prices = [3,2,6,5,0,3]\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\u5728\u7b2c 2 \u5929 (\u80a1\u7968\u4ef7\u683c = 2) \u7684\u65f6\u5019\u4e70\u5165\uff0c\u5728\u7b2c 3 \u5929 (\u80a1\u7968\u4ef7\u683c = 6) \u7684\u65f6\u5019\u5356\u51fa, \u8fd9\u7b14\u4ea4\u6613\u6240\u80fd\u83b7\u5f97\u5229\u6da6 = 6-2 = 4 \u3002\n     \u968f\u540e\uff0c\u5728\u7b2c 5 \u5929 (\u80a1\u7968\u4ef7\u683c = 0) \u7684\u65f6\u5019\u4e70\u5165\uff0c\u5728\u7b2c 6 \u5929 (\u80a1\u7968\u4ef7\u683c = 3) \u7684\u65f6\u5019\u5356\u51fa, \u8fd9\u7b14\u4ea4\u6613\u6240\u80fd\u83b7\u5f97\u5229\u6da6 = 3-0 = 3 \u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= k <= 100
    • \n\t
    • 0 <= prices.length <= 1000
    • \n\t
    • 0 <= prices[i] <= 1000
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxProfit(int k, vector& prices) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxProfit(int k, int[] prices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxProfit(self, k, prices):\n \"\"\"\n :type k: int\n :type prices: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxProfit(self, k: int, prices: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxProfit(int k, int* prices, int pricesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxProfit(int k, int[] prices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} k\n * @param {number[]} prices\n * @return {number}\n */\nvar maxProfit = function(k, prices) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} k\n# @param {Integer[]} prices\n# @return {Integer}\ndef max_profit(k, prices)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxProfit(_ k: Int, _ prices: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxProfit(k int, prices []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxProfit(k: Int, prices: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxProfit(k: Int, prices: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_profit(k: i32, prices: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $k\n * @param Integer[] $prices\n * @return Integer\n */\n function maxProfit($k, $prices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxProfit(k: number, prices: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-profit k prices)\n (-> exact-integer? (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0188](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-iv)", "[\u4e70\u5356\u80a1\u7968\u7684\u6700\u4f73\u65f6\u673a IV](/solution/0100-0199/0188.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20IV/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0188](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iv)", "[Best Time to Buy and Sell Stock IV](/solution/0100-0199/0188.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20IV/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "0187", "frontend_question_id": "0187", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/repeated-dna-sequences", "url_en": "https://leetcode.com/problems/repeated-dna-sequences", "relative_path_cn": "/solution/0100-0199/0187.Repeated%20DNA%20Sequences/README.md", "relative_path_en": "/solution/0100-0199/0187.Repeated%20DNA%20Sequences/README_EN.md", "title_cn": "\u91cd\u590d\u7684DNA\u5e8f\u5217", "title_en": "Repeated DNA Sequences", "question_title_slug": "repeated-dna-sequences", "content_en": "

    The DNA sequence is composed of a series of nucleotides abbreviated as 'A', 'C', 'G', and 'T'.

    \n\n
      \n\t
    • For example, "ACGAATTCCG" is a DNA sequence.
    • \n
    \n\n

    When studying DNA, it is useful to identify repeated sequences within the DNA.

    \n\n

    Given a string s that represents a DNA sequence, return all the 10-letter-long sequences (substrings) that occur more than once in a DNA molecule. You may return the answer in any order.

    \n\n

     

    \n

    Example 1:

    \n
    Input: s = \"AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT\"\nOutput: [\"AAAAACCCCC\",\"CCCCCAAAAA\"]\n

    Example 2:

    \n
    Input: s = \"AAAAAAAAAAAAA\"\nOutput: [\"AAAAAAAAAA\"]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 105
    • \n\t
    • s[i] is either 'A', 'C', 'G', or 'T'.
    • \n
    \n", "content_cn": "

    \u6240\u6709 DNA \u90fd\u7531\u4e00\u7cfb\u5217\u7f29\u5199\u4e3a 'A'\uff0c'C'\uff0c'G' \u548c 'T' \u7684\u6838\u82f7\u9178\u7ec4\u6210\uff0c\u4f8b\u5982\uff1a\"ACGAATTCCG\"\u3002\u5728\u7814\u7a76 DNA \u65f6\uff0c\u8bc6\u522b DNA \u4e2d\u7684\u91cd\u590d\u5e8f\u5217\u6709\u65f6\u4f1a\u5bf9\u7814\u7a76\u975e\u5e38\u6709\u5e2e\u52a9\u3002

    \n\n

    \u7f16\u5199\u4e00\u4e2a\u51fd\u6570\u6765\u627e\u51fa\u6240\u6709\u76ee\u6807\u5b50\u4e32\uff0c\u76ee\u6807\u5b50\u4e32\u7684\u957f\u5ea6\u4e3a 10\uff0c\u4e14\u5728 DNA \u5b57\u7b26\u4e32 s \u4e2d\u51fa\u73b0\u6b21\u6570\u8d85\u8fc7\u4e00\u6b21\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT\"\n\u8f93\u51fa\uff1a[\"AAAAACCCCC\",\"CCCCCAAAAA\"]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"AAAAAAAAAAAAA\"\n\u8f93\u51fa\uff1a[\"AAAAAAAAAA\"]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= s.length <= 105
    • \n\t
    • s[i] \u4e3a 'A'\u3001'C'\u3001'G' \u6216 'T'
    • \n
    \n", "tags_en": ["Bit Manipulation", "Hash Table"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findRepeatedDnaSequences(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List findRepeatedDnaSequences(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findRepeatedDnaSequences(self, s):\n \"\"\"\n :type s: str\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findRepeatedDnaSequences(self, s: str) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** findRepeatedDnaSequences(char * s, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList FindRepeatedDnaSequences(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string[]}\n */\nvar findRepeatedDnaSequences = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String[]}\ndef find_repeated_dna_sequences(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findRepeatedDnaSequences(_ s: String) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findRepeatedDnaSequences(s string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findRepeatedDnaSequences(s: String): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findRepeatedDnaSequences(s: String): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_repeated_dna_sequences(s: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String[]\n */\n function findRepeatedDnaSequences($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findRepeatedDnaSequences(s: string): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-repeated-dna-sequences s)\n (-> string? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0187](https://leetcode-cn.com/problems/repeated-dna-sequences)", "[\u91cd\u590d\u7684DNA\u5e8f\u5217](/solution/0100-0199/0187.Repeated%20DNA%20Sequences/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0187](https://leetcode.com/problems/repeated-dna-sequences)", "[Repeated DNA Sequences](/solution/0100-0199/0187.Repeated%20DNA%20Sequences/README_EN.md)", "`Bit Manipulation`,`Hash Table`", "Medium", ""]}, {"question_id": "0186", "frontend_question_id": "0186", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/reverse-words-in-a-string-ii", "url_en": "https://leetcode.com/problems/reverse-words-in-a-string-ii", "relative_path_cn": "/solution/0100-0199/0186.Reverse%20Words%20in%20a%20String%20II/README.md", "relative_path_en": "/solution/0100-0199/0186.Reverse%20Words%20in%20a%20String%20II/README_EN.md", "title_cn": "\u7ffb\u8f6c\u5b57\u7b26\u4e32\u91cc\u7684\u5355\u8bcd II", "title_en": "Reverse Words in a String II", "question_title_slug": "reverse-words-in-a-string-ii", "content_en": "

    Given a character array s, reverse the order of the words.

    \n\n

    A word is defined as a sequence of non-space characters. The words in s will be separated by a single space.

    \n\n

    Your code must solve the problem in-place, i.e. without allocating extra space.

    \n\n

     

    \n

    Example 1:

    \n
    Input: s = [\"t\",\"h\",\"e\",\" \",\"s\",\"k\",\"y\",\" \",\"i\",\"s\",\" \",\"b\",\"l\",\"u\",\"e\"]\nOutput: [\"b\",\"l\",\"u\",\"e\",\" \",\"i\",\"s\",\" \",\"s\",\"k\",\"y\",\" \",\"t\",\"h\",\"e\"]\n

    Example 2:

    \n
    Input: s = [\"a\"]\nOutput: [\"a\"]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 105
    • \n\t
    • s[i] is an English letter (uppercase or lowercase), digit, or space ' '.
    • \n\t
    • There is at least one word in s.
    • \n\t
    • s does not contain leading or trailing spaces.
    • \n\t
    • All the words in s are guaranteed to be separated by a single space.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u9010\u4e2a\u7ffb\u8f6c\u5b57\u7b26\u4e32\u4e2d\u7684\u6bcf\u4e2a\u5355\u8bcd\u3002

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165: ["t","h","e"," ","s","k","y"," ","i","s"," ","b","l","u","e"]\n\u8f93\u51fa: ["b","l","u","e"," ","i","s"," ","s","k","y"," ","t","h","e"]
    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    • \u5355\u8bcd\u7684\u5b9a\u4e49\u662f\u4e0d\u5305\u542b\u7a7a\u683c\u7684\u4e00\u7cfb\u5217\u5b57\u7b26
    • \n\t
    • \u8f93\u5165\u5b57\u7b26\u4e32\u4e2d\u4e0d\u4f1a\u5305\u542b\u524d\u7f6e\u6216\u5c3e\u968f\u7684\u7a7a\u683c
    • \n\t
    • \u5355\u8bcd\u4e0e\u5355\u8bcd\u4e4b\u95f4\u6c38\u8fdc\u662f\u4ee5\u5355\u4e2a\u7a7a\u683c\u9694\u5f00\u7684
    • \n
    \n\n

    \u8fdb\u9636\uff1a\u4f7f\u7528 O(1) \u989d\u5916\u7a7a\u95f4\u590d\u6742\u5ea6\u7684\u539f\u5730\u89e3\u6cd5\u3002

    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n void reverseWords(vector& s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public void reverseWords(char[] s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def reverseWords(self, s):\n \"\"\"\n :type s: List[str]\n :rtype: None Do not return anything, modify s in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def reverseWords(self, s: List[str]) -> None:\n \"\"\"\n Do not return anything, modify s in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nvoid reverseWords(char* s, int sSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public void ReverseWords(char[] s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {character[]} s\n * @return {void} Do not return anything, modify s in-place instead.\n */\nvar reverseWords = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Character[]} s\n# @return {Void} Do not return anything, modify s in-place instead.\ndef reverse_words(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func reverseWords(_ s: inout [Character]) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func reverseWords(s []byte) {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def reverseWords(s: Array[Char]): Unit = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun reverseWords(s: CharArray): Unit {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn reverse_words(s: &mut Vec) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $s\n * @return NULL\n */\n function reverseWords(&$s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n Do not return anything, modify s in-place instead.\n */\nfunction reverseWords(s: string[]): void {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0186](https://leetcode-cn.com/problems/reverse-words-in-a-string-ii)", "[\u7ffb\u8f6c\u5b57\u7b26\u4e32\u91cc\u7684\u5355\u8bcd II](/solution/0100-0199/0186.Reverse%20Words%20in%20a%20String%20II/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0186](https://leetcode.com/problems/reverse-words-in-a-string-ii)", "[Reverse Words in a String II](/solution/0100-0199/0186.Reverse%20Words%20in%20a%20String%20II/README_EN.md)", "`String`", "Medium", "\ud83d\udd12"]}, {"question_id": "0185", "frontend_question_id": "0185", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/department-top-three-salaries", "url_en": "https://leetcode.com/problems/department-top-three-salaries", "relative_path_cn": "/solution/0100-0199/0185.Department%20Top%20Three%20Salaries/README.md", "relative_path_en": "/solution/0100-0199/0185.Department%20Top%20Three%20Salaries/README_EN.md", "title_cn": "\u90e8\u95e8\u5de5\u8d44\u524d\u4e09\u9ad8\u7684\u6240\u6709\u5458\u5de5", "title_en": "Department Top Three Salaries", "question_title_slug": "department-top-three-salaries", "content_en": "

    Table: Employee

    \n\n
    \n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| Id           | int     |\n| Name         | varchar |\n| Salary       | int     |\n| DepartmentId | int     |\n+--------------+---------+\nId is the primary key for this table.\nEach row contains the ID, name, salary, and department of one employee.\n
    \n\n

     

    \n\n

    Table: Department

    \n\n
    \n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| Id          | int     |\n| Name        | varchar |\n+-------------+---------+\nId is the primary key for this table.\nEach row contains the ID and the name of one department.\n
    \n\n

     

    \n\n

    A company's executives are interested in seeing who earns the most money in each of the company's departments. A high earner in a department is an employee who has a salary in the top three unique salaries for that department.

    \n\n

    Write an SQL query to find the employees who are high earners in each of the departments.

    \n\n

    Return the result table in any order.

    \n\n

    The query result format is in the following example:

    \n\n

     

    \n\n
    \nEmployee table:\n+----+-------+--------+--------------+\n| Id | Name  | Salary | DepartmentId |\n+----+-------+--------+--------------+\n| 1  | Joe   | 85000  | 1            |\n| 2  | Henry | 80000  | 2            |\n| 3  | Sam   | 60000  | 2            |\n| 4  | Max   | 90000  | 1            |\n| 5  | Janet | 69000  | 1            |\n| 6  | Randy | 85000  | 1            |\n| 7  | Will  | 70000  | 1            |\n+----+-------+--------+--------------+\n\nDepartment table:\n+----+-------+\n| Id | Name  |\n+----+-------+\n| 1  | IT    |\n| 2  | Sales |\n+----+-------+\n\nResult table:\n+------------+----------+--------+\n| Department | Employee | Salary |\n+------------+----------+--------+\n| IT         | Max      | 90000  |\n| IT         | Joe      | 85000  |\n| IT         | Randy    | 85000  |\n| IT         | Will     | 70000  |\n| Sales      | Henry    | 80000  |\n| Sales      | Sam      | 60000  |\n+------------+----------+--------+\n\nIn the IT department:\n- Max earns the highest unique salary\n- Both Randy and Joe earn the second-highest unique salary\n- Will earns the third-highest unique salary\n\nIn the Sales department:\n- Henry earns the highest salary\n- Sam earns the second-highest salary\n- There is no third-highest salary as there are only two employees
    \n", "content_cn": "

    Employee \u8868\u5305\u542b\u6240\u6709\u5458\u5de5\u4fe1\u606f\uff0c\u6bcf\u4e2a\u5458\u5de5\u6709\u5176\u5bf9\u5e94\u7684\u5de5\u53f7 Id\uff0c\u59d3\u540d Name\uff0c\u5de5\u8d44 Salary \u548c\u90e8\u95e8\u7f16\u53f7 DepartmentId \u3002

    \n\n
    +----+-------+--------+--------------+\n| Id | Name  | Salary | DepartmentId |\n+----+-------+--------+--------------+\n| 1  | Joe   | 85000  | 1            |\n| 2  | Henry | 80000  | 2            |\n| 3  | Sam   | 60000  | 2            |\n| 4  | Max   | 90000  | 1            |\n| 5  | Janet | 69000  | 1            |\n| 6  | Randy | 85000  | 1            |\n| 7  | Will  | 70000  | 1            |\n+----+-------+--------+--------------+
    \n\n

    Department \u8868\u5305\u542b\u516c\u53f8\u6240\u6709\u90e8\u95e8\u7684\u4fe1\u606f\u3002

    \n\n
    +----+----------+\n| Id | Name     |\n+----+----------+\n| 1  | IT       |\n| 2  | Sales    |\n+----+----------+
    \n\n

    \u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\uff0c\u627e\u51fa\u6bcf\u4e2a\u90e8\u95e8\u83b7\u5f97\u524d\u4e09\u9ad8\u5de5\u8d44\u7684\u6240\u6709\u5458\u5de5\u3002\u4f8b\u5982\uff0c\u6839\u636e\u4e0a\u8ff0\u7ed9\u5b9a\u7684\u8868\uff0c\u67e5\u8be2\u7ed3\u679c\u5e94\u8fd4\u56de\uff1a

    \n\n
    +------------+----------+--------+\n| Department | Employee | Salary |\n+------------+----------+--------+\n| IT         | Max      | 90000  |\n| IT         | Randy    | 85000  |\n| IT         | Joe      | 85000  |\n| IT         | Will     | 70000  |\n| Sales      | Henry    | 80000  |\n| Sales      | Sam      | 60000  |\n+------------+----------+--------+
    \n\n

    \u89e3\u91ca\uff1a

    \n\n

    IT \u90e8\u95e8\u4e2d\uff0cMax \u83b7\u5f97\u4e86\u6700\u9ad8\u7684\u5de5\u8d44\uff0cRandy \u548c Joe \u90fd\u62ff\u5230\u4e86\u7b2c\u4e8c\u9ad8\u7684\u5de5\u8d44\uff0cWill \u7684\u5de5\u8d44\u6392\u7b2c\u4e09\u3002\u9500\u552e\u90e8\u95e8\uff08Sales\uff09\u53ea\u6709\u4e24\u540d\u5458\u5de5\uff0cHenry \u7684\u5de5\u8d44\u6700\u9ad8\uff0cSam \u7684\u5de5\u8d44\u6392\u7b2c\u4e8c\u3002

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0185](https://leetcode-cn.com/problems/department-top-three-salaries)", "[\u90e8\u95e8\u5de5\u8d44\u524d\u4e09\u9ad8\u7684\u6240\u6709\u5458\u5de5](/solution/0100-0199/0185.Department%20Top%20Three%20Salaries/README.md)", "", "\u56f0\u96be", ""], "md_table_row_en": ["[0185](https://leetcode.com/problems/department-top-three-salaries)", "[Department Top Three Salaries](/solution/0100-0199/0185.Department%20Top%20Three%20Salaries/README_EN.md)", "", "Hard", ""]}, {"question_id": "0184", "frontend_question_id": "0184", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/department-highest-salary", "url_en": "https://leetcode.com/problems/department-highest-salary", "relative_path_cn": "/solution/0100-0199/0184.Department%20Highest%20Salary/README.md", "relative_path_en": "/solution/0100-0199/0184.Department%20Highest%20Salary/README_EN.md", "title_cn": "\u90e8\u95e8\u5de5\u8d44\u6700\u9ad8\u7684\u5458\u5de5", "title_en": "Department Highest Salary", "question_title_slug": "department-highest-salary", "content_en": "

    The Employee table holds all employees. Every employee has an Id, a salary, and there is also a column for the department Id.

    \r\n\r\n
    \r\n+----+-------+--------+--------------+\r\n| Id | Name  | Salary | DepartmentId |\r\n+----+-------+--------+--------------+\r\n| 1  | Joe   | 70000  | 1            |\r\n| 2  | Jim   | 90000  | 1            |\r\n| 3  | Henry | 80000  | 2            |\r\n| 4  | Sam   | 60000  | 2            |\r\n| 5  | Max   | 90000  | 1            |\r\n+----+-------+--------+--------------+\r\n
    \r\n\r\n

    The Department table holds all departments of the company.

    \r\n\r\n
    \r\n+----+----------+\r\n| Id | Name     |\r\n+----+----------+\r\n| 1  | IT       |\r\n| 2  | Sales    |\r\n+----+----------+\r\n
    \r\n\r\n

    Write a SQL query to find employees who have the highest salary in each of the departments. For the above tables, your SQL query should return the following rows (order of rows does not matter).

    \r\n\r\n
    \r\n+------------+----------+--------+\r\n| Department | Employee | Salary |\r\n+------------+----------+--------+\r\n| IT         | Max      | 90000  |\r\n| IT         | Jim      | 90000  |\r\n| Sales      | Henry    | 80000  |\r\n+------------+----------+--------+\r\n
    \r\n\r\n

    Explanation:

    \r\n\r\n

    Max and Jim both have the highest salary in the IT department and Henry has the highest salary in the Sales department.

    \r\n", "content_cn": "

    Employee \u8868\u5305\u542b\u6240\u6709\u5458\u5de5\u4fe1\u606f\uff0c\u6bcf\u4e2a\u5458\u5de5\u6709\u5176\u5bf9\u5e94\u7684 Id, salary \u548c department Id\u3002

    \n\n
    +----+-------+--------+--------------+\n| Id | Name  | Salary | DepartmentId |\n+----+-------+--------+--------------+\n| 1  | Joe   | 70000  | 1            |\n| 2  | Jim   | 90000  | 1            |\n| 3  | Henry | 80000  | 2            |\n| 4  | Sam   | 60000  | 2            |\n| 5  | Max   | 90000  | 1            |\n+----+-------+--------+--------------+
    \n\n

    Department \u8868\u5305\u542b\u516c\u53f8\u6240\u6709\u90e8\u95e8\u7684\u4fe1\u606f\u3002

    \n\n
    +----+----------+\n| Id | Name     |\n+----+----------+\n| 1  | IT       |\n| 2  | Sales    |\n+----+----------+
    \n\n

    \u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\uff0c\u627e\u51fa\u6bcf\u4e2a\u90e8\u95e8\u5de5\u8d44\u6700\u9ad8\u7684\u5458\u5de5\u3002\u5bf9\u4e8e\u4e0a\u8ff0\u8868\uff0c\u60a8\u7684 SQL \u67e5\u8be2\u5e94\u8fd4\u56de\u4ee5\u4e0b\u884c\uff08\u884c\u7684\u987a\u5e8f\u65e0\u5173\u7d27\u8981\uff09\u3002

    \n\n
    +------------+----------+--------+\n| Department | Employee | Salary |\n+------------+----------+--------+\n| IT         | Max      | 90000  |\n| IT         | Jim      | 90000  |\n| Sales      | Henry    | 80000  |\n+------------+----------+--------+
    \n\n

    \u89e3\u91ca\uff1a

    \n\n

    Max \u548c Jim \u5728 IT \u90e8\u95e8\u7684\u5de5\u8d44\u90fd\u662f\u6700\u9ad8\u7684\uff0cHenry \u5728\u9500\u552e\u90e8\u7684\u5de5\u8d44\u6700\u9ad8\u3002

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0184](https://leetcode-cn.com/problems/department-highest-salary)", "[\u90e8\u95e8\u5de5\u8d44\u6700\u9ad8\u7684\u5458\u5de5](/solution/0100-0199/0184.Department%20Highest%20Salary/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0184](https://leetcode.com/problems/department-highest-salary)", "[Department Highest Salary](/solution/0100-0199/0184.Department%20Highest%20Salary/README_EN.md)", "", "Medium", ""]}, {"question_id": "0183", "frontend_question_id": "0183", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/customers-who-never-order", "url_en": "https://leetcode.com/problems/customers-who-never-order", "relative_path_cn": "/solution/0100-0199/0183.Customers%20Who%20Never%20Order/README.md", "relative_path_en": "/solution/0100-0199/0183.Customers%20Who%20Never%20Order/README_EN.md", "title_cn": "\u4ece\u4e0d\u8ba2\u8d2d\u7684\u5ba2\u6237", "title_en": "Customers Who Never Order", "question_title_slug": "customers-who-never-order", "content_en": "

    Suppose that a website contains two tables, the Customers table and the Orders table. Write a SQL query to find all customers who never order anything.

    \r\n\r\n

    Table: Customers.

    \r\n\r\n
    \r\n+----+-------+\r\n| Id | Name  |\r\n+----+-------+\r\n| 1  | Joe   |\r\n| 2  | Henry |\r\n| 3  | Sam   |\r\n| 4  | Max   |\r\n+----+-------+\r\n
    \r\n\r\n

    Table: Orders.

    \r\n\r\n
    \r\n+----+------------+\r\n| Id | CustomerId |\r\n+----+------------+\r\n| 1  | 3          |\r\n| 2  | 1          |\r\n+----+------------+\r\n
    \r\n\r\n

    Using the above tables as example, return the following:

    \r\n\r\n
    \r\n+-----------+\r\n| Customers |\r\n+-----------+\r\n| Henry     |\r\n| Max       |\r\n+-----------+\r\n
    \r\n", "content_cn": "

    \u67d0\u7f51\u7ad9\u5305\u542b\u4e24\u4e2a\u8868\uff0cCustomers \u8868\u548c Orders \u8868\u3002\u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\uff0c\u627e\u51fa\u6240\u6709\u4ece\u4e0d\u8ba2\u8d2d\u4efb\u4f55\u4e1c\u897f\u7684\u5ba2\u6237\u3002

    \n\n

    Customers \u8868\uff1a

    \n\n
    +----+-------+\n| Id | Name  |\n+----+-------+\n| 1  | Joe   |\n| 2  | Henry |\n| 3  | Sam   |\n| 4  | Max   |\n+----+-------+\n
    \n\n

    Orders \u8868\uff1a

    \n\n
    +----+------------+\n| Id | CustomerId |\n+----+------------+\n| 1  | 3          |\n| 2  | 1          |\n+----+------------+\n
    \n\n

    \u4f8b\u5982\u7ed9\u5b9a\u4e0a\u8ff0\u8868\u683c\uff0c\u4f60\u7684\u67e5\u8be2\u5e94\u8fd4\u56de\uff1a

    \n\n
    +-----------+\n| Customers |\n+-----------+\n| Henry     |\n| Max       |\n+-----------+\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0183](https://leetcode-cn.com/problems/customers-who-never-order)", "[\u4ece\u4e0d\u8ba2\u8d2d\u7684\u5ba2\u6237](/solution/0100-0199/0183.Customers%20Who%20Never%20Order/README.md)", "", "\u7b80\u5355", ""], "md_table_row_en": ["[0183](https://leetcode.com/problems/customers-who-never-order)", "[Customers Who Never Order](/solution/0100-0199/0183.Customers%20Who%20Never%20Order/README_EN.md)", "", "Easy", ""]}, {"question_id": "0182", "frontend_question_id": "0182", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/duplicate-emails", "url_en": "https://leetcode.com/problems/duplicate-emails", "relative_path_cn": "/solution/0100-0199/0182.Duplicate%20Emails/README.md", "relative_path_en": "/solution/0100-0199/0182.Duplicate%20Emails/README_EN.md", "title_cn": "\u67e5\u627e\u91cd\u590d\u7684\u7535\u5b50\u90ae\u7bb1", "title_en": "Duplicate Emails", "question_title_slug": "duplicate-emails", "content_en": "

    Write a SQL query to find all duplicate emails in a table named Person.

    \r\n\r\n
    \r\n+----+---------+\r\n| Id | Email   |\r\n+----+---------+\r\n| 1  | a@b.com |\r\n| 2  | c@d.com |\r\n| 3  | a@b.com |\r\n+----+---------+\r\n
    \r\n\r\n

    For example, your query should return the following for the above table:

    \r\n\r\n
    \r\n+---------+\r\n| Email   |\r\n+---------+\r\n| a@b.com |\r\n+---------+\r\n
    \r\n\r\n

    Note: All emails are in lowercase.

    \r\n", "content_cn": "

    \u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\uff0c\u67e5\u627e Person \u8868\u4e2d\u6240\u6709\u91cd\u590d\u7684\u7535\u5b50\u90ae\u7bb1\u3002

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    +----+---------+\n| Id | Email   |\n+----+---------+\n| 1  | a@b.com |\n| 2  | c@d.com |\n| 3  | a@b.com |\n+----+---------+\n
    \n\n

    \u6839\u636e\u4ee5\u4e0a\u8f93\u5165\uff0c\u4f60\u7684\u67e5\u8be2\u5e94\u8fd4\u56de\u4ee5\u4e0b\u7ed3\u679c\uff1a

    \n\n
    +---------+\n| Email   |\n+---------+\n| a@b.com |\n+---------+\n
    \n\n

    \u8bf4\u660e\uff1a\u6240\u6709\u7535\u5b50\u90ae\u7bb1\u90fd\u662f\u5c0f\u5199\u5b57\u6bcd\u3002

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0182](https://leetcode-cn.com/problems/duplicate-emails)", "[\u67e5\u627e\u91cd\u590d\u7684\u7535\u5b50\u90ae\u7bb1](/solution/0100-0199/0182.Duplicate%20Emails/README.md)", "", "\u7b80\u5355", ""], "md_table_row_en": ["[0182](https://leetcode.com/problems/duplicate-emails)", "[Duplicate Emails](/solution/0100-0199/0182.Duplicate%20Emails/README_EN.md)", "", "Easy", ""]}, {"question_id": "0181", "frontend_question_id": "0181", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/employees-earning-more-than-their-managers", "url_en": "https://leetcode.com/problems/employees-earning-more-than-their-managers", "relative_path_cn": "/solution/0100-0199/0181.Employees%20Earning%20More%20Than%20Their%20Managers/README.md", "relative_path_en": "/solution/0100-0199/0181.Employees%20Earning%20More%20Than%20Their%20Managers/README_EN.md", "title_cn": "\u8d85\u8fc7\u7ecf\u7406\u6536\u5165\u7684\u5458\u5de5", "title_en": "Employees Earning More Than Their Managers", "question_title_slug": "employees-earning-more-than-their-managers", "content_en": "

    The Employee table holds all employees including their managers. Every employee has an Id, and there is also a column for the manager Id.

    \r\n\r\n
    \r\n+----+-------+--------+-----------+\r\n| Id | Name  | Salary | ManagerId |\r\n+----+-------+--------+-----------+\r\n| 1  | Joe   | 70000  | 3         |\r\n| 2  | Henry | 80000  | 4         |\r\n| 3  | Sam   | 60000  | NULL      |\r\n| 4  | Max   | 90000  | NULL      |\r\n+----+-------+--------+-----------+\r\n
    \r\n\r\n

    Given the Employee table, write a SQL query that finds out employees who earn more than their managers. For the above table, Joe is the only employee who earns more than his manager.

    \r\n\r\n
    \r\n+----------+\r\n| Employee |\r\n+----------+\r\n| Joe      |\r\n+----------+\r\n
    \r\n", "content_cn": "

    Employee \u8868\u5305\u542b\u6240\u6709\u5458\u5de5\uff0c\u4ed6\u4eec\u7684\u7ecf\u7406\u4e5f\u5c5e\u4e8e\u5458\u5de5\u3002\u6bcf\u4e2a\u5458\u5de5\u90fd\u6709\u4e00\u4e2a Id\uff0c\u6b64\u5916\u8fd8\u6709\u4e00\u5217\u5bf9\u5e94\u5458\u5de5\u7684\u7ecf\u7406\u7684 Id\u3002

    \n\n
    +----+-------+--------+-----------+\n| Id | Name  | Salary | ManagerId |\n+----+-------+--------+-----------+\n| 1  | Joe   | 70000  | 3         |\n| 2  | Henry | 80000  | 4         |\n| 3  | Sam   | 60000  | NULL      |\n| 4  | Max   | 90000  | NULL      |\n+----+-------+--------+-----------+\n
    \n\n

    \u7ed9\u5b9a Employee \u8868\uff0c\u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\uff0c\u8be5\u67e5\u8be2\u53ef\u4ee5\u83b7\u53d6\u6536\u5165\u8d85\u8fc7\u4ed6\u4eec\u7ecf\u7406\u7684\u5458\u5de5\u7684\u59d3\u540d\u3002\u5728\u4e0a\u9762\u7684\u8868\u683c\u4e2d\uff0cJoe \u662f\u552f\u4e00\u4e00\u4e2a\u6536\u5165\u8d85\u8fc7\u4ed6\u7684\u7ecf\u7406\u7684\u5458\u5de5\u3002

    \n\n
    +----------+\n| Employee |\n+----------+\n| Joe      |\n+----------+\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0181](https://leetcode-cn.com/problems/employees-earning-more-than-their-managers)", "[\u8d85\u8fc7\u7ecf\u7406\u6536\u5165\u7684\u5458\u5de5](/solution/0100-0199/0181.Employees%20Earning%20More%20Than%20Their%20Managers/README.md)", "", "\u7b80\u5355", ""], "md_table_row_en": ["[0181](https://leetcode.com/problems/employees-earning-more-than-their-managers)", "[Employees Earning More Than Their Managers](/solution/0100-0199/0181.Employees%20Earning%20More%20Than%20Their%20Managers/README_EN.md)", "", "Easy", ""]}, {"question_id": "0180", "frontend_question_id": "0180", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/consecutive-numbers", "url_en": "https://leetcode.com/problems/consecutive-numbers", "relative_path_cn": "/solution/0100-0199/0180.Consecutive%20Numbers/README.md", "relative_path_en": "/solution/0100-0199/0180.Consecutive%20Numbers/README_EN.md", "title_cn": "\u8fde\u7eed\u51fa\u73b0\u7684\u6570\u5b57", "title_en": "Consecutive Numbers", "question_title_slug": "consecutive-numbers", "content_en": "

    Table: Logs

    \n\n
    \n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| id          | int     |\n| num         | varchar |\n+-------------+---------+\nid is the primary key for this table.\n
    \n\n

     

    \n\n

    Write an SQL query to find all numbers that appear at least three times consecutively.

    \n\n

    Return the result table in any order.

    \n\n

    The query result format is in the following example:

    \n\n

     

    \n\n
    \nLogs table:\n+----+-----+\n| Id | Num |\n+----+-----+\n| 1  | 1   |\n| 2  | 1   |\n| 3  | 1   |\n| 4  | 2   |\n| 5  | 1   |\n| 6  | 2   |\n| 7  | 2   |\n+----+-----+\n\nResult table:\n+-----------------+\n| ConsecutiveNums |\n+-----------------+\n| 1               |\n+-----------------+\n1 is the only number that appears consecutively for at least three times.\n
    \n", "content_cn": "

    \u8868\uff1aLogs

    \n\n
    \n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| id          | int     |\n| num         | varchar |\n+-------------+---------+\nid \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\u3002
    \n\n

    \u00a0

    \n\n

    \u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\uff0c\u67e5\u627e\u6240\u6709\u81f3\u5c11\u8fde\u7eed\u51fa\u73b0\u4e09\u6b21\u7684\u6570\u5b57\u3002

    \n\n

    \u8fd4\u56de\u7684\u7ed3\u679c\u8868\u4e2d\u7684\u6570\u636e\u53ef\u4ee5\u6309 \u4efb\u610f\u987a\u5e8f \u6392\u5217\u3002

    \n\n

    \u00a0

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u9762\u7684\u4f8b\u5b50\u6240\u793a\uff1a

    \n\n

    \u00a0

    \n\n
    \nLogs \u8868\uff1a\n+----+-----+\n| Id | Num |\n+----+-----+\n| 1  | 1   |\n| 2  | 1   |\n| 3  | 1   |\n| 4  | 2   |\n| 5  | 1   |\n| 6  | 2   |\n| 7  | 2   |\n+----+-----+\n\nResult \u8868\uff1a\n+-----------------+\n| ConsecutiveNums |\n+-----------------+\n| 1               |\n+-----------------+\n1 \u662f\u552f\u4e00\u8fde\u7eed\u51fa\u73b0\u81f3\u5c11\u4e09\u6b21\u7684\u6570\u5b57\u3002\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0180](https://leetcode-cn.com/problems/consecutive-numbers)", "[\u8fde\u7eed\u51fa\u73b0\u7684\u6570\u5b57](/solution/0100-0199/0180.Consecutive%20Numbers/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0180](https://leetcode.com/problems/consecutive-numbers)", "[Consecutive Numbers](/solution/0100-0199/0180.Consecutive%20Numbers/README_EN.md)", "", "Medium", ""]}, {"question_id": "0179", "frontend_question_id": "0179", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/largest-number", "url_en": "https://leetcode.com/problems/largest-number", "relative_path_cn": "/solution/0100-0199/0179.Largest%20Number/README.md", "relative_path_en": "/solution/0100-0199/0179.Largest%20Number/README_EN.md", "title_cn": "\u6700\u5927\u6570", "title_en": "Largest Number", "question_title_slug": "largest-number", "content_en": "

    Given a list of non-negative integers nums, arrange them such that they form the largest number.

    \n\n

    Note: The result may be very large, so you need to return a string instead of an integer.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [10,2]\nOutput: "210"\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [3,30,34,5,9]\nOutput: "9534330"\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [1]\nOutput: "1"\n
    \n\n

    Example 4:

    \n\n
    \nInput: nums = [10]\nOutput: "10"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 100
    • \n\t
    • 0 <= nums[i] <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u7ec4\u975e\u8d1f\u6574\u6570 nums\uff0c\u91cd\u65b0\u6392\u5217\u6bcf\u4e2a\u6570\u7684\u987a\u5e8f\uff08\u6bcf\u4e2a\u6570\u4e0d\u53ef\u62c6\u5206\uff09\u4f7f\u4e4b\u7ec4\u6210\u4e00\u4e2a\u6700\u5927\u7684\u6574\u6570\u3002

    \n\n

    \u6ce8\u610f\uff1a\u8f93\u51fa\u7ed3\u679c\u53ef\u80fd\u975e\u5e38\u5927\uff0c\u6240\u4ee5\u4f60\u9700\u8981\u8fd4\u56de\u4e00\u4e2a\u5b57\u7b26\u4e32\u800c\u4e0d\u662f\u6574\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [10,2]\n\u8f93\u51fa\uff1a\"210\"
    \n\n

    \u793a\u4f8b\u00a02\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [3,30,34,5,9]\n\u8f93\u51fa\uff1a\"9534330\"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1]\n\u8f93\u51fa\uff1a\"1\"\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [10]\n\u8f93\u51fa\uff1a\"10\"\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 100
    • \n\t
    • 0 <= nums[i] <= 109
    • \n
    \n", "tags_en": ["Sort"], "tags_cn": ["\u6392\u5e8f"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string largestNumber(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String largestNumber(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def largestNumber(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def largestNumber(self, nums: List[int]) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * largestNumber(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string LargestNumber(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {string}\n */\nvar largestNumber = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {String}\ndef largest_number(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func largestNumber(_ nums: [Int]) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func largestNumber(nums []int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def largestNumber(nums: Array[Int]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun largestNumber(nums: IntArray): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn largest_number(nums: Vec) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return String\n */\n function largestNumber($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function largestNumber(nums: number[]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (largest-number nums)\n (-> (listof exact-integer?) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0179](https://leetcode-cn.com/problems/largest-number)", "[\u6700\u5927\u6570](/solution/0100-0199/0179.Largest%20Number/README.md)", "`\u6392\u5e8f`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0179](https://leetcode.com/problems/largest-number)", "[Largest Number](/solution/0100-0199/0179.Largest%20Number/README_EN.md)", "`Sort`", "Medium", ""]}, {"question_id": "0178", "frontend_question_id": "0178", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/rank-scores", "url_en": "https://leetcode.com/problems/rank-scores", "relative_path_cn": "/solution/0100-0199/0178.Rank%20Scores/README.md", "relative_path_en": "/solution/0100-0199/0178.Rank%20Scores/README_EN.md", "title_cn": "\u5206\u6570\u6392\u540d", "title_en": "Rank Scores", "question_title_slug": "rank-scores", "content_en": "

    Write a SQL query to rank scores. If there is a tie between two scores, both should have the same ranking. Note that after a tie, the next ranking number should be the next consecutive integer value. In other words, there should be no "holes" between ranks.

    \n\n
    \n+----+-------+\n| Id | Score |\n+----+-------+\n| 1  | 3.50  |\n| 2  | 3.65  |\n| 3  | 4.00  |\n| 4  | 3.85  |\n| 5  | 4.00  |\n| 6  | 3.65  |\n+----+-------+\n
    \n\n

    For example, given the above Scores table, your query should generate the following report (order by highest score):

    \n\n
    \n+-------+---------+\n| score | Rank    |\n+-------+---------+\n| 4.00  | 1       |\n| 4.00  | 1       |\n| 3.85  | 2       |\n| 3.65  | 3       |\n| 3.65  | 3       |\n| 3.50  | 4       |\n+-------+---------+\n
    \n\n

    Important Note: For MySQL solutions, to escape reserved words used as column names, you can use an apostrophe before and after the keyword. For example `Rank`.

    \n", "content_cn": "

    \u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\u6765\u5b9e\u73b0\u5206\u6570\u6392\u540d\u3002

    \n\n

    \u5982\u679c\u4e24\u4e2a\u5206\u6570\u76f8\u540c\uff0c\u5219\u4e24\u4e2a\u5206\u6570\u6392\u540d\uff08Rank\uff09\u76f8\u540c\u3002\u8bf7\u6ce8\u610f\uff0c\u5e73\u5206\u540e\u7684\u4e0b\u4e00\u4e2a\u540d\u6b21\u5e94\u8be5\u662f\u4e0b\u4e00\u4e2a\u8fde\u7eed\u7684\u6574\u6570\u503c\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u540d\u6b21\u4e4b\u95f4\u4e0d\u5e94\u8be5\u6709“\u95f4\u9694”\u3002

    \n\n
    +----+-------+\n| Id | Score |\n+----+-------+\n| 1  | 3.50  |\n| 2  | 3.65  |\n| 3  | 4.00  |\n| 4  | 3.85  |\n| 5  | 4.00  |\n| 6  | 3.65  |\n+----+-------+\n
    \n\n

    \u4f8b\u5982\uff0c\u6839\u636e\u4e0a\u8ff0\u7ed9\u5b9a\u7684 Scores \u8868\uff0c\u4f60\u7684\u67e5\u8be2\u5e94\u8be5\u8fd4\u56de\uff08\u6309\u5206\u6570\u4ece\u9ad8\u5230\u4f4e\u6392\u5217\uff09\uff1a

    \n\n
    +-------+------+\n| Score | Rank |\n+-------+------+\n| 4.00  | 1    |\n| 4.00  | 1    |\n| 3.85  | 2    |\n| 3.65  | 3    |\n| 3.65  | 3    |\n| 3.50  | 4    |\n+-------+------+\n
    \n\n

    \u91cd\u8981\u63d0\u793a\uff1a\u5bf9\u4e8e MySQL \u89e3\u51b3\u65b9\u6848\uff0c\u5982\u679c\u8981\u8f6c\u4e49\u7528\u4f5c\u5217\u540d\u7684\u4fdd\u7559\u5b57\uff0c\u53ef\u4ee5\u5728\u5173\u952e\u5b57\u4e4b\u524d\u548c\u4e4b\u540e\u4f7f\u7528\u6487\u53f7\u3002\u4f8b\u5982 `Rank`

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0178](https://leetcode-cn.com/problems/rank-scores)", "[\u5206\u6570\u6392\u540d](/solution/0100-0199/0178.Rank%20Scores/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0178](https://leetcode.com/problems/rank-scores)", "[Rank Scores](/solution/0100-0199/0178.Rank%20Scores/README_EN.md)", "", "Medium", ""]}, {"question_id": "0177", "frontend_question_id": "0177", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/nth-highest-salary", "url_en": "https://leetcode.com/problems/nth-highest-salary", "relative_path_cn": "/solution/0100-0199/0177.Nth%20Highest%20Salary/README.md", "relative_path_en": "/solution/0100-0199/0177.Nth%20Highest%20Salary/README_EN.md", "title_cn": "\u7b2cN\u9ad8\u7684\u85aa\u6c34", "title_en": "Nth Highest Salary", "question_title_slug": "nth-highest-salary", "content_en": "

    Write a SQL query to get the nth highest salary from the Employee table.

    \r\n\r\n
    \r\n+----+--------+\r\n| Id | Salary |\r\n+----+--------+\r\n| 1  | 100    |\r\n| 2  | 200    |\r\n| 3  | 300    |\r\n+----+--------+\r\n
    \r\n\r\n

    For example, given the above Employee table, the nth highest salary where n = 2 is 200. If there is no nth highest salary, then the query should return null.

    \r\n\r\n
    \r\n+------------------------+\r\n| getNthHighestSalary(2) |\r\n+------------------------+\r\n| 200                    |\r\n+------------------------+\r\n
    \r\n", "content_cn": "

    \u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\uff0c\u83b7\u53d6 Employee \u8868\u4e2d\u7b2c \u9ad8\u7684\u85aa\u6c34\uff08Salary\uff09\u3002

    \n\n
    +----+--------+\n| Id | Salary |\n+----+--------+\n| 1  | 100    |\n| 2  | 200    |\n| 3  | 300    |\n+----+--------+\n
    \n\n

    \u4f8b\u5982\u4e0a\u8ff0 Employee \u8868\uff0cn = 2 \u65f6\uff0c\u5e94\u8fd4\u56de\u7b2c\u4e8c\u9ad8\u7684\u85aa\u6c34 200\u3002\u5982\u679c\u4e0d\u5b58\u5728\u7b2c \u9ad8\u7684\u85aa\u6c34\uff0c\u90a3\u4e48\u67e5\u8be2\u5e94\u8fd4\u56de null\u3002

    \n\n
    +------------------------+\n| getNthHighestSalary(2) |\n+------------------------+\n| 200                    |\n+------------------------+\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT\nBEGIN\n RETURN (\n # Write your MySQL query statement below.\n \n );\nEND", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "CREATE FUNCTION getNthHighestSalary(@N INT) RETURNS INT AS\nBEGIN\n RETURN (\n /* Write your T-SQL query statement below. */\n \n );\nEND", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "CREATE FUNCTION getNthHighestSalary(N IN NUMBER) RETURN NUMBER IS\nresult NUMBER;\nBEGIN\n /* Write your PL/SQL query statement below */\n \n RETURN result;\nEND;", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0177](https://leetcode-cn.com/problems/nth-highest-salary)", "[\u7b2cN\u9ad8\u7684\u85aa\u6c34](/solution/0100-0199/0177.Nth%20Highest%20Salary/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0177](https://leetcode.com/problems/nth-highest-salary)", "[Nth Highest Salary](/solution/0100-0199/0177.Nth%20Highest%20Salary/README_EN.md)", "", "Medium", ""]}, {"question_id": "0176", "frontend_question_id": "0176", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/second-highest-salary", "url_en": "https://leetcode.com/problems/second-highest-salary", "relative_path_cn": "/solution/0100-0199/0176.Second%20Highest%20Salary/README.md", "relative_path_en": "/solution/0100-0199/0176.Second%20Highest%20Salary/README_EN.md", "title_cn": "\u7b2c\u4e8c\u9ad8\u7684\u85aa\u6c34", "title_en": "Second Highest Salary", "question_title_slug": "second-highest-salary", "content_en": "

    Write a SQL query to get the second highest salary from the Employee table.

    \r\n\r\n
    \r\n+----+--------+\r\n| Id | Salary |\r\n+----+--------+\r\n| 1  | 100    |\r\n| 2  | 200    |\r\n| 3  | 300    |\r\n+----+--------+\r\n
    \r\n\r\n

    For example, given the above Employee table, the query should return 200 as the second highest salary. If there is no second highest salary, then the query should return null.

    \r\n\r\n
    \r\n+---------------------+\r\n| SecondHighestSalary |\r\n+---------------------+\r\n| 200                 |\r\n+---------------------+\r\n
    \r\n", "content_cn": "

    \u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\uff0c\u83b7\u53d6 Employee \u8868\u4e2d\u7b2c\u4e8c\u9ad8\u7684\u85aa\u6c34\uff08Salary\uff09 \u3002

    \n\n
    +----+--------+\n| Id | Salary |\n+----+--------+\n| 1  | 100    |\n| 2  | 200    |\n| 3  | 300    |\n+----+--------+\n
    \n\n

    \u4f8b\u5982\u4e0a\u8ff0 Employee \u8868\uff0cSQL\u67e5\u8be2\u5e94\u8be5\u8fd4\u56de 200 \u4f5c\u4e3a\u7b2c\u4e8c\u9ad8\u7684\u85aa\u6c34\u3002\u5982\u679c\u4e0d\u5b58\u5728\u7b2c\u4e8c\u9ad8\u7684\u85aa\u6c34\uff0c\u90a3\u4e48\u67e5\u8be2\u5e94\u8fd4\u56de null\u3002

    \n\n
    +---------------------+\n| SecondHighestSalary |\n+---------------------+\n| 200                 |\n+---------------------+\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0176](https://leetcode-cn.com/problems/second-highest-salary)", "[\u7b2c\u4e8c\u9ad8\u7684\u85aa\u6c34](/solution/0100-0199/0176.Second%20Highest%20Salary/README.md)", "", "\u7b80\u5355", ""], "md_table_row_en": ["[0176](https://leetcode.com/problems/second-highest-salary)", "[Second Highest Salary](/solution/0100-0199/0176.Second%20Highest%20Salary/README_EN.md)", "", "Easy", ""]}, {"question_id": "0175", "frontend_question_id": "0175", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/combine-two-tables", "url_en": "https://leetcode.com/problems/combine-two-tables", "relative_path_cn": "/solution/0100-0199/0175.Combine%20Two%20Tables/README.md", "relative_path_en": "/solution/0100-0199/0175.Combine%20Two%20Tables/README_EN.md", "title_cn": "\u7ec4\u5408\u4e24\u4e2a\u8868", "title_en": "Combine Two Tables", "question_title_slug": "combine-two-tables", "content_en": "

    Table: Person

    \r\n\r\n
    \r\n+-------------+---------+\r\n| Column Name | Type    |\r\n+-------------+---------+\r\n| PersonId    | int     |\r\n| FirstName   | varchar |\r\n| LastName    | varchar |\r\n+-------------+---------+\r\nPersonId is the primary key column for this table.\r\n
    \r\n\r\n

    Table: Address

    \r\n\r\n
    \r\n+-------------+---------+\r\n| Column Name | Type    |\r\n+-------------+---------+\r\n| AddressId   | int     |\r\n| PersonId    | int     |\r\n| City        | varchar |\r\n| State       | varchar |\r\n+-------------+---------+\r\nAddressId is the primary key column for this table.\r\n
    \r\n\r\n

     

    \r\n\r\n

    Write a SQL query for a report that provides the following information for each person in the Person table, regardless if there is an address for each of those people:

    \r\n\r\n
    \r\nFirstName, LastName, City, State\r\n
    \r\n", "content_cn": "

    \u88681: Person

    \n\n
    +-------------+---------+\n| \u5217\u540d         | \u7c7b\u578b     |\n+-------------+---------+\n| PersonId    | int     |\n| FirstName   | varchar |\n| LastName    | varchar |\n+-------------+---------+\nPersonId \u662f\u4e0a\u8868\u4e3b\u952e\n
    \n\n

    \u88682: Address

    \n\n
    +-------------+---------+\n| \u5217\u540d         | \u7c7b\u578b    |\n+-------------+---------+\n| AddressId   | int     |\n| PersonId    | int     |\n| City        | varchar |\n| State       | varchar |\n+-------------+---------+\nAddressId \u662f\u4e0a\u8868\u4e3b\u952e\n
    \n\n

     

    \n\n

    \u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\uff0c\u6ee1\u8db3\u6761\u4ef6\uff1a\u65e0\u8bba person \u662f\u5426\u6709\u5730\u5740\u4fe1\u606f\uff0c\u90fd\u9700\u8981\u57fa\u4e8e\u4e0a\u8ff0\u4e24\u8868\u63d0\u4f9b person \u7684\u4ee5\u4e0b\u4fe1\u606f\uff1a

    \n\n

     

    \n\n
    FirstName, LastName, City, State\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0175](https://leetcode-cn.com/problems/combine-two-tables)", "[\u7ec4\u5408\u4e24\u4e2a\u8868](/solution/0100-0199/0175.Combine%20Two%20Tables/README.md)", "", "\u7b80\u5355", ""], "md_table_row_en": ["[0175](https://leetcode.com/problems/combine-two-tables)", "[Combine Two Tables](/solution/0100-0199/0175.Combine%20Two%20Tables/README_EN.md)", "", "Easy", ""]}, {"question_id": "0174", "frontend_question_id": "0174", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/dungeon-game", "url_en": "https://leetcode.com/problems/dungeon-game", "relative_path_cn": "/solution/0100-0199/0174.Dungeon%20Game/README.md", "relative_path_en": "/solution/0100-0199/0174.Dungeon%20Game/README_EN.md", "title_cn": "\u5730\u4e0b\u57ce\u6e38\u620f", "title_en": "Dungeon Game", "question_title_slug": "dungeon-game", "content_en": "

    The demons had captured the princess and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of m x n rooms laid out in a 2D grid. Our valiant knight was initially positioned in the top-left room and must fight his way through dungeon to rescue the princess.

    \n\n

    The knight has an initial health point represented by a positive integer. If at any point his health point drops to 0 or below, he dies immediately.

    \n\n

    Some of the rooms are guarded by demons (represented by negative integers), so the knight loses health upon entering these rooms; other rooms are either empty (represented as 0) or contain magic orbs that increase the knight's health (represented by positive integers).

    \n\n

    To reach the princess as quickly as possible, the knight decides to move only rightward or downward in each step.

    \n\n

    Return the knight's minimum initial health so that he can rescue the princess.

    \n\n

    Note that any room can contain threats or power-ups, even the first room the knight enters and the bottom-right room where the princess is imprisoned.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: dungeon = [[-2,-3,3],[-5,-10,1],[10,30,-5]]\nOutput: 7\nExplanation: The initial health of the knight must be at least 7 if he follows the optimal path: RIGHT-> RIGHT -> DOWN -> DOWN.\n
    \n\n

    Example 2:

    \n\n
    \nInput: dungeon = [[0]]\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == dungeon.length
    • \n\t
    • n == dungeon[i].length
    • \n\t
    • 1 <= m, n <= 200
    • \n\t
    • -1000 <= dungeon[i][j] <= 1000
    • \n
    \n", "content_cn": "\r\n\r\n

    \u4e00\u4e9b\u6076\u9b54\u6293\u4f4f\u4e86\u516c\u4e3b\uff08P\uff09\u5e76\u5c06\u5979\u5173\u5728\u4e86\u5730\u4e0b\u57ce\u7684\u53f3\u4e0b\u89d2\u3002\u5730\u4e0b\u57ce\u662f\u7531 M x N \u4e2a\u623f\u95f4\u7ec4\u6210\u7684\u4e8c\u7ef4\u7f51\u683c\u3002\u6211\u4eec\u82f1\u52c7\u7684\u9a91\u58eb\uff08K\uff09\u6700\u521d\u88ab\u5b89\u7f6e\u5728\u5de6\u4e0a\u89d2\u7684\u623f\u95f4\u91cc\uff0c\u4ed6\u5fc5\u987b\u7a7f\u8fc7\u5730\u4e0b\u57ce\u5e76\u901a\u8fc7\u5bf9\u6297\u6076\u9b54\u6765\u62ef\u6551\u516c\u4e3b\u3002

    \r\n\r\n

    \u9a91\u58eb\u7684\u521d\u59cb\u5065\u5eb7\u70b9\u6570\u4e3a\u4e00\u4e2a\u6b63\u6574\u6570\u3002\u5982\u679c\u4ed6\u7684\u5065\u5eb7\u70b9\u6570\u5728\u67d0\u4e00\u65f6\u523b\u964d\u81f3 0 \u6216\u4ee5\u4e0b\uff0c\u4ed6\u4f1a\u7acb\u5373\u6b7b\u4ea1\u3002

    \r\n\r\n

    \u6709\u4e9b\u623f\u95f4\u7531\u6076\u9b54\u5b88\u536b\uff0c\u56e0\u6b64\u9a91\u58eb\u5728\u8fdb\u5165\u8fd9\u4e9b\u623f\u95f4\u65f6\u4f1a\u5931\u53bb\u5065\u5eb7\u70b9\u6570\uff08\u82e5\u623f\u95f4\u91cc\u7684\u503c\u4e3a\u8d1f\u6574\u6570\uff0c\u5219\u8868\u793a\u9a91\u58eb\u5c06\u635f\u5931\u5065\u5eb7\u70b9\u6570\uff09\uff1b\u5176\u4ed6\u623f\u95f4\u8981\u4e48\u662f\u7a7a\u7684\uff08\u623f\u95f4\u91cc\u7684\u503c\u4e3a 0\uff09\uff0c\u8981\u4e48\u5305\u542b\u589e\u52a0\u9a91\u58eb\u5065\u5eb7\u70b9\u6570\u7684\u9b54\u6cd5\u7403\uff08\u82e5\u623f\u95f4\u91cc\u7684\u503c\u4e3a\u6b63\u6574\u6570\uff0c\u5219\u8868\u793a\u9a91\u58eb\u5c06\u589e\u52a0\u5065\u5eb7\u70b9\u6570\uff09\u3002

    \r\n\r\n

    \u4e3a\u4e86\u5c3d\u5feb\u5230\u8fbe\u516c\u4e3b\uff0c\u9a91\u58eb\u51b3\u5b9a\u6bcf\u6b21\u53ea\u5411\u53f3\u6216\u5411\u4e0b\u79fb\u52a8\u4e00\u6b65\u3002

    \r\n\r\n

     

    \r\n\r\n

    \u7f16\u5199\u4e00\u4e2a\u51fd\u6570\u6765\u8ba1\u7b97\u786e\u4fdd\u9a91\u58eb\u80fd\u591f\u62ef\u6551\u5230\u516c\u4e3b\u6240\u9700\u7684\u6700\u4f4e\u521d\u59cb\u5065\u5eb7\u70b9\u6570\u3002

    \r\n\r\n

    \u4f8b\u5982\uff0c\u8003\u8651\u5230\u5982\u4e0b\u5e03\u5c40\u7684\u5730\u4e0b\u57ce\uff0c\u5982\u679c\u9a91\u58eb\u9075\u5faa\u6700\u4f73\u8def\u5f84 \u53f3 -> \u53f3 -> \u4e0b -> \u4e0b\uff0c\u5219\u9a91\u58eb\u7684\u521d\u59cb\u5065\u5eb7\u70b9\u6570\u81f3\u5c11\u4e3a 7\u3002

    \r\n\r\n\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
    -2 (K)-33
    -5-101
    1030-5 (P)
    \r\n\r\n\r\n

     

    \r\n\r\n

    \u8bf4\u660e:

    \r\n\r\n
      \r\n\t
    • \r\n\t

      \u9a91\u58eb\u7684\u5065\u5eb7\u70b9\u6570\u6ca1\u6709\u4e0a\u9650\u3002

      \r\n\t
    • \r\n\t
    • \u4efb\u4f55\u623f\u95f4\u90fd\u53ef\u80fd\u5bf9\u9a91\u58eb\u7684\u5065\u5eb7\u70b9\u6570\u9020\u6210\u5a01\u80c1\uff0c\u4e5f\u53ef\u80fd\u589e\u52a0\u9a91\u58eb\u7684\u5065\u5eb7\u70b9\u6570\uff0c\u5305\u62ec\u9a91\u58eb\u8fdb\u5165\u7684\u5de6\u4e0a\u89d2\u623f\u95f4\u4ee5\u53ca\u516c\u4e3b\u88ab\u76d1\u7981\u7684\u53f3\u4e0b\u89d2\u623f\u95f4\u3002
    • \r\n
    ", "tags_en": ["Binary Search", "Dynamic Programming"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int calculateMinimumHP(vector>& dungeon) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int calculateMinimumHP(int[][] dungeon) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def calculateMinimumHP(self, dungeon):\n \"\"\"\n :type dungeon: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def calculateMinimumHP(self, dungeon: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint calculateMinimumHP(int** dungeon, int dungeonSize, int* dungeonColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CalculateMinimumHP(int[][] dungeon) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} dungeon\n * @return {number}\n */\nvar calculateMinimumHP = function(dungeon) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} dungeon\n# @return {Integer}\ndef calculate_minimum_hp(dungeon)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func calculateMinimumHP(_ dungeon: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func calculateMinimumHP(dungeon [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def calculateMinimumHP(dungeon: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun calculateMinimumHP(dungeon: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn calculate_minimum_hp(dungeon: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $dungeon\n * @return Integer\n */\n function calculateMinimumHP($dungeon) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function calculateMinimumHP(dungeon: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (calculate-minimum-hp dungeon)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0174](https://leetcode-cn.com/problems/dungeon-game)", "[\u5730\u4e0b\u57ce\u6e38\u620f](/solution/0100-0199/0174.Dungeon%20Game/README.md)", "`\u4e8c\u5206\u67e5\u627e`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0174](https://leetcode.com/problems/dungeon-game)", "[Dungeon Game](/solution/0100-0199/0174.Dungeon%20Game/README_EN.md)", "`Binary Search`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0173", "frontend_question_id": "0173", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/binary-search-tree-iterator", "url_en": "https://leetcode.com/problems/binary-search-tree-iterator", "relative_path_cn": "/solution/0100-0199/0173.Binary%20Search%20Tree%20Iterator/README.md", "relative_path_en": "/solution/0100-0199/0173.Binary%20Search%20Tree%20Iterator/README_EN.md", "title_cn": "\u4e8c\u53c9\u641c\u7d22\u6811\u8fed\u4ee3\u5668", "title_en": "Binary Search Tree Iterator", "question_title_slug": "binary-search-tree-iterator", "content_en": "

    Implement the BSTIterator class that represents an iterator over the in-order traversal of a binary search tree (BST):

    \n\n
      \n\t
    • BSTIterator(TreeNode root) Initializes an object of the BSTIterator class. The root of the BST is given as part of the constructor. The pointer should be initialized to a non-existent number smaller than any element in the BST.
    • \n\t
    • boolean hasNext() Returns true if there exists a number in the traversal to the right of the pointer, otherwise returns false.
    • \n\t
    • int next() Moves the pointer to the right, then returns the number at the pointer.
    • \n
    \n\n

    Notice that by initializing the pointer to a non-existent smallest number, the first call to next() will return the smallest element in the BST.

    \n\n

    You may assume that next() calls will always be valid. That is, there will be at least a next number in the in-order traversal when next() is called.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput\n["BSTIterator", "next", "next", "hasNext", "next", "hasNext", "next", "hasNext", "next", "hasNext"]\n[[[7, 3, 15, null, null, 9, 20]], [], [], [], [], [], [], [], [], []]\nOutput\n[null, 3, 7, true, 9, true, 15, true, 20, false]\n\nExplanation\nBSTIterator bSTIterator = new BSTIterator([7, 3, 15, null, null, 9, 20]);\nbSTIterator.next();    // return 3\nbSTIterator.next();    // return 7\nbSTIterator.hasNext(); // return True\nbSTIterator.next();    // return 9\nbSTIterator.hasNext(); // return True\nbSTIterator.next();    // return 15\nbSTIterator.hasNext(); // return True\nbSTIterator.next();    // return 20\nbSTIterator.hasNext(); // return False\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 105].
    • \n\t
    • 0 <= Node.val <= 106
    • \n\t
    • At most 105 calls will be made to hasNext, and next.
    • \n
    \n\n

     

    \n

    Follow up:

    \n\n
      \n\t
    • Could you implement next() and hasNext() to run in average O(1) time and use O(h) memory, where h is the height of the tree?
    • \n
    \n", "content_cn": "\u5b9e\u73b0\u4e00\u4e2a\u4e8c\u53c9\u641c\u7d22\u6811\u8fed\u4ee3\u5668\u7c7bBSTIterator \uff0c\u8868\u793a\u4e00\u4e2a\u6309\u4e2d\u5e8f\u904d\u5386\u4e8c\u53c9\u641c\u7d22\u6811\uff08BST\uff09\u7684\u8fed\u4ee3\u5668\uff1a\n
    \n
    \n
      \n\t
    • BSTIterator(TreeNode root) \u521d\u59cb\u5316 BSTIterator \u7c7b\u7684\u4e00\u4e2a\u5bf9\u8c61\u3002BST \u7684\u6839\u8282\u70b9 root \u4f1a\u4f5c\u4e3a\u6784\u9020\u51fd\u6570\u7684\u4e00\u90e8\u5206\u7ed9\u51fa\u3002\u6307\u9488\u5e94\u521d\u59cb\u5316\u4e3a\u4e00\u4e2a\u4e0d\u5b58\u5728\u4e8e BST \u4e2d\u7684\u6570\u5b57\uff0c\u4e14\u8be5\u6570\u5b57\u5c0f\u4e8e BST \u4e2d\u7684\u4efb\u4f55\u5143\u7d20\u3002
    • \n\t
    • boolean hasNext() \u5982\u679c\u5411\u6307\u9488\u53f3\u4fa7\u904d\u5386\u5b58\u5728\u6570\u5b57\uff0c\u5219\u8fd4\u56de true \uff1b\u5426\u5219\u8fd4\u56de false \u3002
    • \n\t
    • int next()\u5c06\u6307\u9488\u5411\u53f3\u79fb\u52a8\uff0c\u7136\u540e\u8fd4\u56de\u6307\u9488\u5904\u7684\u6570\u5b57\u3002
    • \n
    \n\n

    \u6ce8\u610f\uff0c\u6307\u9488\u521d\u59cb\u5316\u4e3a\u4e00\u4e2a\u4e0d\u5b58\u5728\u4e8e BST \u4e2d\u7684\u6570\u5b57\uff0c\u6240\u4ee5\u5bf9 next() \u7684\u9996\u6b21\u8c03\u7528\u5c06\u8fd4\u56de BST \u4e2d\u7684\u6700\u5c0f\u5143\u7d20\u3002

    \n
    \n
    \n\n

    \u4f60\u53ef\u4ee5\u5047\u8bbe\u00a0next()\u00a0\u8c03\u7528\u603b\u662f\u6709\u6548\u7684\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u5f53\u8c03\u7528 next()\u00a0\u65f6\uff0cBST \u7684\u4e2d\u5e8f\u904d\u5386\u4e2d\u81f3\u5c11\u5b58\u5728\u4e00\u4e2a\u4e0b\u4e00\u4e2a\u6570\u5b57\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\"\"\n
    \n\u8f93\u5165\n[\"BSTIterator\", \"next\", \"next\", \"hasNext\", \"next\", \"hasNext\", \"next\", \"hasNext\", \"next\", \"hasNext\"]\n[[[7, 3, 15, null, null, 9, 20]], [], [], [], [], [], [], [], [], []]\n\u8f93\u51fa\n[null, 3, 7, true, 9, true, 15, true, 20, false]\n\n\u89e3\u91ca\nBSTIterator bSTIterator = new BSTIterator([7, 3, 15, null, null, 9, 20]);\nbSTIterator.next();    // \u8fd4\u56de 3\nbSTIterator.next();    // \u8fd4\u56de 7\nbSTIterator.hasNext(); // \u8fd4\u56de True\nbSTIterator.next();    // \u8fd4\u56de 9\nbSTIterator.hasNext(); // \u8fd4\u56de True\nbSTIterator.next();    // \u8fd4\u56de 15\nbSTIterator.hasNext(); // \u8fd4\u56de True\nbSTIterator.next();    // \u8fd4\u56de 20\nbSTIterator.hasNext(); // \u8fd4\u56de False\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u7684\u6570\u76ee\u5728\u8303\u56f4 [1, 105] \u5185
    • \n\t
    • 0 <= Node.val <= 106
    • \n\t
    • \u6700\u591a\u8c03\u7528 105 \u6b21 hasNext \u548c next \u64cd\u4f5c
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u4f60\u53ef\u4ee5\u8bbe\u8ba1\u4e00\u4e2a\u6ee1\u8db3\u4e0b\u8ff0\u6761\u4ef6\u7684\u89e3\u51b3\u65b9\u6848\u5417\uff1fnext() \u548c hasNext() \u64cd\u4f5c\u5747\u644a\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(1) \uff0c\u5e76\u4f7f\u7528 O(h) \u5185\u5b58\u3002\u5176\u4e2d h \u662f\u6811\u7684\u9ad8\u5ea6\u3002
    • \n
    \n", "tags_en": ["Stack", "Tree", "Design"], "tags_cn": ["\u6808", "\u6811", "\u8bbe\u8ba1"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass BSTIterator {\npublic:\n BSTIterator(TreeNode* root) {\n\n }\n \n int next() {\n\n }\n \n bool hasNext() {\n\n }\n};\n\n/**\n * Your BSTIterator object will be instantiated and called as such:\n * BSTIterator* obj = new BSTIterator(root);\n * int param_1 = obj->next();\n * bool param_2 = obj->hasNext();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass BSTIterator {\n\n public BSTIterator(TreeNode root) {\n\n }\n \n public int next() {\n\n }\n \n public boolean hasNext() {\n\n }\n}\n\n/**\n * Your BSTIterator object will be instantiated and called as such:\n * BSTIterator obj = new BSTIterator(root);\n * int param_1 = obj.next();\n * boolean param_2 = obj.hasNext();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass BSTIterator(object):\n\n def __init__(self, root):\n \"\"\"\n :type root: TreeNode\n \"\"\"\n\n\n def next(self):\n \"\"\"\n :rtype: int\n \"\"\"\n\n\n def hasNext(self):\n \"\"\"\n :rtype: bool\n \"\"\"\n\n\n\n# Your BSTIterator object will be instantiated and called as such:\n# obj = BSTIterator(root)\n# param_1 = obj.next()\n# param_2 = obj.hasNext()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass BSTIterator:\n\n def __init__(self, root: TreeNode):\n\n\n def next(self) -> int:\n\n\n def hasNext(self) -> bool:\n\n\n\n# Your BSTIterator object will be instantiated and called as such:\n# obj = BSTIterator(root)\n# param_1 = obj.next()\n# param_2 = obj.hasNext()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n\ntypedef struct {\n\n} BSTIterator;\n\n\nBSTIterator* bSTIteratorCreate(struct TreeNode* root) {\n\n}\n\nint bSTIteratorNext(BSTIterator* obj) {\n\n}\n\nbool bSTIteratorHasNext(BSTIterator* obj) {\n\n}\n\nvoid bSTIteratorFree(BSTIterator* obj) {\n\n}\n\n/**\n * Your BSTIterator struct will be instantiated and called as such:\n * BSTIterator* obj = bSTIteratorCreate(root);\n * int param_1 = bSTIteratorNext(obj);\n \n * bool param_2 = bSTIteratorHasNext(obj);\n \n * bSTIteratorFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class BSTIterator {\n\n public BSTIterator(TreeNode root) {\n\n }\n \n public int Next() {\n\n }\n \n public bool HasNext() {\n\n }\n}\n\n/**\n * Your BSTIterator object will be instantiated and called as such:\n * BSTIterator obj = new BSTIterator(root);\n * int param_1 = obj.Next();\n * bool param_2 = obj.HasNext();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n */\nvar BSTIterator = function(root) {\n\n};\n\n/**\n * @return {number}\n */\nBSTIterator.prototype.next = function() {\n\n};\n\n/**\n * @return {boolean}\n */\nBSTIterator.prototype.hasNext = function() {\n\n};\n\n/**\n * Your BSTIterator object will be instantiated and called as such:\n * var obj = new BSTIterator(root)\n * var param_1 = obj.next()\n * var param_2 = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\nclass BSTIterator\n\n=begin\n :type root: TreeNode\n=end\n def initialize(root)\n\n end\n\n\n=begin\n :rtype: Integer\n=end\n def next()\n\n end\n\n\n=begin\n :rtype: Boolean\n=end\n def has_next()\n\n end\n\n\nend\n\n# Your BSTIterator object will be instantiated and called as such:\n# obj = BSTIterator.new(root)\n# param_1 = obj.next()\n# param_2 = obj.has_next()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\n\nclass BSTIterator {\n\n init(_ root: TreeNode?) {\n\n }\n \n func next() -> Int {\n\n }\n \n func hasNext() -> Bool {\n\n }\n}\n\n/**\n * Your BSTIterator object will be instantiated and called as such:\n * let obj = BSTIterator(root)\n * let ret_1: Int = obj.next()\n * let ret_2: Bool = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\ntype BSTIterator struct {\n\n}\n\n\nfunc Constructor(root *TreeNode) BSTIterator {\n\n}\n\n\nfunc (this *BSTIterator) Next() int {\n\n}\n\n\nfunc (this *BSTIterator) HasNext() bool {\n\n}\n\n\n/**\n * Your BSTIterator object will be instantiated and called as such:\n * obj := Constructor(root);\n * param_1 := obj.Next();\n * param_2 := obj.HasNext();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nclass BSTIterator(_root: TreeNode) {\n\n def next(): Int = {\n\n }\n\n def hasNext(): Boolean = {\n\n }\n\n}\n\n/**\n * Your BSTIterator object will be instantiated and called as such:\n * var obj = new BSTIterator(root)\n * var param_1 = obj.next()\n * var param_2 = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass BSTIterator(root: TreeNode?) {\n\n fun next(): Int {\n\n }\n\n fun hasNext(): Boolean {\n\n }\n\n}\n\n/**\n * Your BSTIterator object will be instantiated and called as such:\n * var obj = BSTIterator(root)\n * var param_1 = obj.next()\n * var param_2 = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nstruct BSTIterator {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl BSTIterator {\n\n fn new(root: Option>>) -> Self {\n\n }\n \n fn next(&self) -> i32 {\n\n }\n \n fn has_next(&self) -> bool {\n\n }\n}\n\n/**\n * Your BSTIterator object will be instantiated and called as such:\n * let obj = BSTIterator::new(root);\n * let ret_1: i32 = obj.next();\n * let ret_2: bool = obj.has_next();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass BSTIterator {\n /**\n * @param TreeNode $root\n */\n function __construct($root) {\n\n }\n\n /**\n * @return Integer\n */\n function next() {\n\n }\n\n /**\n * @return Boolean\n */\n function hasNext() {\n\n }\n}\n\n/**\n * Your BSTIterator object will be instantiated and called as such:\n * $obj = BSTIterator($root);\n * $ret_1 = $obj->next();\n * $ret_2 = $obj->hasNext();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nclass BSTIterator {\n constructor(root: TreeNode | null) {\n\n }\n\n next(): number {\n\n }\n\n hasNext(): boolean {\n\n }\n}\n\n/**\n * Your BSTIterator object will be instantiated and called as such:\n * var obj = new BSTIterator(root)\n * var param_1 = obj.next()\n * var param_2 = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define bst-iterator%\n (class object%\n (super-new)\n\n ; root : (or/c tree-node? #f)\n (init-field\n root)\n \n ; next : -> exact-integer?\n (define/public (next)\n\n )\n ; has-next : -> boolean?\n (define/public (has-next)\n\n )))\n\n;; Your bst-iterator% object will be instantiated and called as such:\n;; (define obj (new bst-iterator% [root root]))\n;; (define param_1 (send obj next))\n;; (define param_2 (send obj has-next))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0173](https://leetcode-cn.com/problems/binary-search-tree-iterator)", "[\u4e8c\u53c9\u641c\u7d22\u6811\u8fed\u4ee3\u5668](/solution/0100-0199/0173.Binary%20Search%20Tree%20Iterator/README.md)", "`\u6808`,`\u6811`,`\u8bbe\u8ba1`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0173](https://leetcode.com/problems/binary-search-tree-iterator)", "[Binary Search Tree Iterator](/solution/0100-0199/0173.Binary%20Search%20Tree%20Iterator/README_EN.md)", "`Stack`,`Tree`,`Design`", "Medium", ""]}, {"question_id": "0172", "frontend_question_id": "0172", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/factorial-trailing-zeroes", "url_en": "https://leetcode.com/problems/factorial-trailing-zeroes", "relative_path_cn": "/solution/0100-0199/0172.Factorial%20Trailing%20Zeroes/README.md", "relative_path_en": "/solution/0100-0199/0172.Factorial%20Trailing%20Zeroes/README_EN.md", "title_cn": "\u9636\u4e58\u540e\u7684\u96f6", "title_en": "Factorial Trailing Zeroes", "question_title_slug": "factorial-trailing-zeroes", "content_en": "

    Given an integer n, return the number of trailing zeroes in n!.

    \n\n

    Follow up: Could you write a solution that works in logarithmic time complexity?

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 3\nOutput: 0\nExplanation: 3! = 6, no trailing zero.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 5\nOutput: 1\nExplanation: 5! = 120, one trailing zero.\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 0\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= n <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570 n\uff0c\u8fd4\u56de n! \u7ed3\u679c\u5c3e\u6570\u4e2d\u96f6\u7684\u6570\u91cf\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: 3\n\u8f93\u51fa: 0\n\u89e3\u91ca: 3! = 6, \u5c3e\u6570\u4e2d\u6ca1\u6709\u96f6\u3002
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: 5\n\u8f93\u51fa: 1\n\u89e3\u91ca: 5! = 120, \u5c3e\u6570\u4e2d\u6709 1 \u4e2a\u96f6.
    \n\n

    \u8bf4\u660e: \u4f60\u7b97\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u5e94\u4e3a O(log n) \u3002

    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int trailingZeroes(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int trailingZeroes(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def trailingZeroes(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def trailingZeroes(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint trailingZeroes(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int TrailingZeroes(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar trailingZeroes = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef trailing_zeroes(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func trailingZeroes(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func trailingZeroes(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def trailingZeroes(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun trailingZeroes(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn trailing_zeroes(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function trailingZeroes($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function trailingZeroes(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (trailing-zeroes n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0172](https://leetcode-cn.com/problems/factorial-trailing-zeroes)", "[\u9636\u4e58\u540e\u7684\u96f6](/solution/0100-0199/0172.Factorial%20Trailing%20Zeroes/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0172](https://leetcode.com/problems/factorial-trailing-zeroes)", "[Factorial Trailing Zeroes](/solution/0100-0199/0172.Factorial%20Trailing%20Zeroes/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "0171", "frontend_question_id": "0171", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/excel-sheet-column-number", "url_en": "https://leetcode.com/problems/excel-sheet-column-number", "relative_path_cn": "/solution/0100-0199/0171.Excel%20Sheet%20Column%20Number/README.md", "relative_path_en": "/solution/0100-0199/0171.Excel%20Sheet%20Column%20Number/README_EN.md", "title_cn": "Excel\u8868\u5217\u5e8f\u53f7", "title_en": "Excel Sheet Column Number", "question_title_slug": "excel-sheet-column-number", "content_en": "

    Given a string columnTitle that represents the column title as appear in an Excel sheet, return its corresponding column number.

    \n\n

    For example:

    \n\n
    \nA -> 1\nB -> 2\nC -> 3\n...\nZ -> 26\nAA -> 27\nAB -> 28 \n...\n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: columnTitle = "A"\nOutput: 1\n
    \n\n

    Example 2:

    \n\n
    \nInput: columnTitle = "AB"\nOutput: 28\n
    \n\n

    Example 3:

    \n\n
    \nInput: columnTitle = "ZY"\nOutput: 701\n
    \n\n

    Example 4:

    \n\n
    \nInput: columnTitle = "FXSHRXW"\nOutput: 2147483647\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= columnTitle.length <= 7
    • \n\t
    • columnTitle consists only of uppercase English letters.
    • \n\t
    • columnTitle is in the range ["A", "FXSHRXW"].
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2aExcel\u8868\u683c\u4e2d\u7684\u5217\u540d\u79f0\uff0c\u8fd4\u56de\u5176\u76f8\u5e94\u7684\u5217\u5e8f\u53f7\u3002

    \n\n

    \u4f8b\u5982\uff0c

    \n\n
        A -> 1\n    B -> 2\n    C -> 3\n    ...\n    Z -> 26\n    AA -> 27\n    AB -> 28 \n    ...\n
    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: "A"\n\u8f93\u51fa: 1\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: "AB"\n\u8f93\u51fa: 28\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u8f93\u5165: "ZY"\n\u8f93\u51fa: 701
    \n\n

    \u81f4\u8c22\uff1a
    \n\u7279\u522b\u611f\u8c22 @ts \u6dfb\u52a0\u6b64\u95ee\u9898\u5e76\u521b\u5efa\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002

    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int titleToNumber(string columnTitle) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int titleToNumber(String columnTitle) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def titleToNumber(self, columnTitle):\n \"\"\"\n :type columnTitle: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def titleToNumber(self, columnTitle: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint titleToNumber(char * columnTitle){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int TitleToNumber(string columnTitle) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} columnTitle\n * @return {number}\n */\nvar titleToNumber = function(columnTitle) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} column_title\n# @return {Integer}\ndef title_to_number(column_title)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func titleToNumber(_ columnTitle: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func titleToNumber(columnTitle string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def titleToNumber(columnTitle: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun titleToNumber(columnTitle: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn title_to_number(column_title: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $columnTitle\n * @return Integer\n */\n function titleToNumber($columnTitle) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function titleToNumber(columnTitle: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (title-to-number columnTitle)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0171](https://leetcode-cn.com/problems/excel-sheet-column-number)", "[Excel\u8868\u5217\u5e8f\u53f7](/solution/0100-0199/0171.Excel%20Sheet%20Column%20Number/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0171](https://leetcode.com/problems/excel-sheet-column-number)", "[Excel Sheet Column Number](/solution/0100-0199/0171.Excel%20Sheet%20Column%20Number/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "0170", "frontend_question_id": "0170", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/two-sum-iii-data-structure-design", "url_en": "https://leetcode.com/problems/two-sum-iii-data-structure-design", "relative_path_cn": "/solution/0100-0199/0170.Two%20Sum%20III%20-%20Data%20structure%20design/README.md", "relative_path_en": "/solution/0100-0199/0170.Two%20Sum%20III%20-%20Data%20structure%20design/README_EN.md", "title_cn": "\u4e24\u6570\u4e4b\u548c III - \u6570\u636e\u7ed3\u6784\u8bbe\u8ba1", "title_en": "Two Sum III - Data structure design", "question_title_slug": "two-sum-iii-data-structure-design", "content_en": "

    Design a data structure that accepts a stream of integers and checks if it has a pair of integers that sum up to a particular value.

    \n\n

    Implement the TwoSum class:

    \n\n
      \n\t
    • TwoSum() Initializes the TwoSum object, with an empty array initially.
    • \n\t
    • void add(int number) Adds number to the data structure.
    • \n\t
    • boolean find(int value) Returns true if there exists any pair of numbers whose sum is equal to value, otherwise, it returns false.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["TwoSum", "add", "add", "add", "find", "find"]\n[[], [1], [3], [5], [4], [7]]\nOutput\n[null, null, null, null, true, false]\n\nExplanation\nTwoSum twoSum = new TwoSum();\ntwoSum.add(1);   // [] --> [1]\ntwoSum.add(3);   // [1] --> [1,3]\ntwoSum.add(5);   // [1,3] --> [1,3,5]\ntwoSum.find(4);  // 1 + 3 = 4, return true\ntwoSum.find(7);  // No two integers sum up to 7, return false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • -105 <= number <= 105
    • \n\t
    • -231 <= value <= 231 - 1
    • \n\t
    • At most 5 * 104 calls will be made to add and find.
    • \n
    \n", "content_cn": "

    \u8bbe\u8ba1\u4e00\u4e2a\u63a5\u6536\u6574\u6570\u6d41\u7684\u6570\u636e\u7ed3\u6784\uff0c\u8be5\u6570\u636e\u7ed3\u6784\u652f\u6301\u68c0\u67e5\u662f\u5426\u5b58\u5728\u4e24\u6570\u4e4b\u548c\u7b49\u4e8e\u7279\u5b9a\u503c\u3002

    \n\n

    \u5b9e\u73b0 TwoSum \u7c7b\uff1a

    \n\n
      \n\t
    • TwoSum() \u4f7f\u7528\u7a7a\u6570\u7ec4\u521d\u59cb\u5316 TwoSum \u5bf9\u8c61
    • \n\t
    • void add(int number) \u5411\u6570\u636e\u7ed3\u6784\u6dfb\u52a0\u4e00\u4e2a\u6570 number
    • \n\t
    • boolean find(int value) \u5bfb\u627e\u6570\u636e\u7ed3\u6784\u4e2d\u662f\u5426\u5b58\u5728\u4e00\u5bf9\u6574\u6570\uff0c\u4f7f\u5f97\u4e24\u6570\u4e4b\u548c\u4e0e\u7ed9\u5b9a\u7684\u503c\u76f8\u7b49\u3002\u5982\u679c\u5b58\u5728\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\n[\"TwoSum\", \"add\", \"add\", \"add\", \"find\", \"find\"]\n[[], [1], [3], [5], [4], [7]]\n\u8f93\u51fa\uff1a\n[null, null, null, null, true, false]\n\n\u89e3\u91ca\uff1a\nTwoSum twoSum = new TwoSum();\ntwoSum.add(1);   // [] --> [1]\ntwoSum.add(3);   // [1] --> [1,3]\ntwoSum.add(5);   // [1,3] --> [1,3,5]\ntwoSum.find(4);  // 1 + 3 = 4\uff0c\u8fd4\u56de true\ntwoSum.find(7);  // \u6ca1\u6709\u4e24\u4e2a\u6574\u6570\u52a0\u8d77\u6765\u7b49\u4e8e 7 \uff0c\u8fd4\u56de false
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • -105 <= number <= 105
    • \n\t
    • -231 <= value <= 231 - 1
    • \n\t
    • \u6700\u591a\u8c03\u7528 5 * 104 \u6b21 add \u548c find
    • \n
    \n", "tags_en": ["Design", "Hash Table"], "tags_cn": ["\u8bbe\u8ba1", "\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class TwoSum {\npublic:\n /** Initialize your data structure here. */\n TwoSum() {\n\n }\n \n /** Add the number to an internal data structure.. */\n void add(int number) {\n\n }\n \n /** Find if there exists any pair of numbers which sum is equal to the value. */\n bool find(int value) {\n\n }\n};\n\n/**\n * Your TwoSum object will be instantiated and called as such:\n * TwoSum* obj = new TwoSum();\n * obj->add(number);\n * bool param_2 = obj->find(value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class TwoSum {\n\n /** Initialize your data structure here. */\n public TwoSum() {\n\n }\n \n /** Add the number to an internal data structure.. */\n public void add(int number) {\n\n }\n \n /** Find if there exists any pair of numbers which sum is equal to the value. */\n public boolean find(int value) {\n\n }\n}\n\n/**\n * Your TwoSum object will be instantiated and called as such:\n * TwoSum obj = new TwoSum();\n * obj.add(number);\n * boolean param_2 = obj.find(value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class TwoSum(object):\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def add(self, number):\n \"\"\"\n Add the number to an internal data structure..\n :type number: int\n :rtype: None\n \"\"\"\n\n\n def find(self, value):\n \"\"\"\n Find if there exists any pair of numbers which sum is equal to the value.\n :type value: int\n :rtype: bool\n \"\"\"\n\n\n\n# Your TwoSum object will be instantiated and called as such:\n# obj = TwoSum()\n# obj.add(number)\n# param_2 = obj.find(value)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class TwoSum:\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def add(self, number: int) -> None:\n \"\"\"\n Add the number to an internal data structure..\n \"\"\"\n\n\n def find(self, value: int) -> bool:\n \"\"\"\n Find if there exists any pair of numbers which sum is equal to the value.\n \"\"\"\n\n\n\n# Your TwoSum object will be instantiated and called as such:\n# obj = TwoSum()\n# obj.add(number)\n# param_2 = obj.find(value)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} TwoSum;\n\n/** Initialize your data structure here. */\n\nTwoSum* twoSumCreate() {\n\n}\n\n/** Add the number to an internal data structure.. */\nvoid twoSumAdd(TwoSum* obj, int number) {\n\n}\n\n/** Find if there exists any pair of numbers which sum is equal to the value. */\nbool twoSumFind(TwoSum* obj, int value) {\n\n}\n\nvoid twoSumFree(TwoSum* obj) {\n\n}\n\n/**\n * Your TwoSum struct will be instantiated and called as such:\n * TwoSum* obj = twoSumCreate();\n * twoSumAdd(obj, number);\n \n * bool param_2 = twoSumFind(obj, value);\n \n * twoSumFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class TwoSum {\n\n /** Initialize your data structure here. */\n public TwoSum() {\n\n }\n \n /** Add the number to an internal data structure.. */\n public void Add(int number) {\n\n }\n \n /** Find if there exists any pair of numbers which sum is equal to the value. */\n public bool Find(int value) {\n\n }\n}\n\n/**\n * Your TwoSum object will be instantiated and called as such:\n * TwoSum obj = new TwoSum();\n * obj.Add(number);\n * bool param_2 = obj.Find(value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Initialize your data structure here.\n */\nvar TwoSum = function() {\n\n};\n\n/**\n * Add the number to an internal data structure.. \n * @param {number} number\n * @return {void}\n */\nTwoSum.prototype.add = function(number) {\n\n};\n\n/**\n * Find if there exists any pair of numbers which sum is equal to the value. \n * @param {number} value\n * @return {boolean}\n */\nTwoSum.prototype.find = function(value) {\n\n};\n\n/**\n * Your TwoSum object will be instantiated and called as such:\n * var obj = new TwoSum()\n * obj.add(number)\n * var param_2 = obj.find(value)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class TwoSum\n\n=begin\n Initialize your data structure here.\n=end\n def initialize()\n\n end\n\n\n=begin\n Add the number to an internal data structure..\n :type number: Integer\n :rtype: Void\n=end\n def add(number)\n\n end\n\n\n=begin\n Find if there exists any pair of numbers which sum is equal to the value.\n :type value: Integer\n :rtype: Boolean\n=end\n def find(value)\n\n end\n\n\nend\n\n# Your TwoSum object will be instantiated and called as such:\n# obj = TwoSum.new()\n# obj.add(number)\n# param_2 = obj.find(value)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass TwoSum {\n\n /** Initialize your data structure here. */\n init() {\n\n }\n \n /** Add the number to an internal data structure.. */\n func add(_ number: Int) {\n\n }\n \n /** Find if there exists any pair of numbers which sum is equal to the value. */\n func find(_ value: Int) -> Bool {\n\n }\n}\n\n/**\n * Your TwoSum object will be instantiated and called as such:\n * let obj = TwoSum()\n * obj.add(number)\n * let ret_2: Bool = obj.find(value)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type TwoSum struct {\n\n}\n\n\n/** Initialize your data structure here. */\nfunc Constructor() TwoSum {\n\n}\n\n\n/** Add the number to an internal data structure.. */\nfunc (this *TwoSum) Add(number int) {\n\n}\n\n\n/** Find if there exists any pair of numbers which sum is equal to the value. */\nfunc (this *TwoSum) Find(value int) bool {\n\n}\n\n\n/**\n * Your TwoSum object will be instantiated and called as such:\n * obj := Constructor();\n * obj.Add(number);\n * param_2 := obj.Find(value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class TwoSum() {\n\n /** Initialize your data structure here. */\n\n\n /** Add the number to an internal data structure.. */\n def add(number: Int) {\n\n }\n\n /** Find if there exists any pair of numbers which sum is equal to the value. */\n def find(value: Int): Boolean = {\n\n }\n\n}\n\n/**\n * Your TwoSum object will be instantiated and called as such:\n * var obj = new TwoSum()\n * obj.add(number)\n * var param_2 = obj.find(value)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class TwoSum() {\n\n /** Initialize your data structure here. */\n\n\n /** Add the number to an internal data structure.. */\n fun add(number: Int) {\n\n }\n\n /** Find if there exists any pair of numbers which sum is equal to the value. */\n fun find(value: Int): Boolean {\n\n }\n\n}\n\n/**\n * Your TwoSum object will be instantiated and called as such:\n * var obj = TwoSum()\n * obj.add(number)\n * var param_2 = obj.find(value)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct TwoSum {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl TwoSum {\n\n /** Initialize your data structure here. */\n fn new() -> Self {\n\n }\n \n /** Add the number to an internal data structure.. */\n fn add(&self, number: i32) {\n\n }\n \n /** Find if there exists any pair of numbers which sum is equal to the value. */\n fn find(&self, value: i32) -> bool {\n\n }\n}\n\n/**\n * Your TwoSum object will be instantiated and called as such:\n * let obj = TwoSum::new();\n * obj.add(number);\n * let ret_2: bool = obj.find(value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class TwoSum {\n /**\n * Initialize your data structure here.\n */\n function __construct() {\n\n }\n\n /**\n * Add the number to an internal data structure..\n * @param Integer $number\n * @return NULL\n */\n function add($number) {\n\n }\n\n /**\n * Find if there exists any pair of numbers which sum is equal to the value.\n * @param Integer $value\n * @return Boolean\n */\n function find($value) {\n\n }\n}\n\n/**\n * Your TwoSum object will be instantiated and called as such:\n * $obj = TwoSum();\n * $obj->add($number);\n * $ret_2 = $obj->find($value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class TwoSum {\n constructor() {\n\n }\n\n add(number: number): void {\n\n }\n\n find(value: number): boolean {\n\n }\n}\n\n/**\n * Your TwoSum object will be instantiated and called as such:\n * var obj = new TwoSum()\n * obj.add(number)\n * var param_2 = obj.find(value)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define two-sum%\n (class object%\n (super-new)\n (init-field)\n \n ; add : exact-integer? -> void?\n (define/public (add number)\n\n )\n ; find : exact-integer? -> boolean?\n (define/public (find value)\n\n )))\n\n;; Your two-sum% object will be instantiated and called as such:\n;; (define obj (new two-sum%))\n;; (send obj add number)\n;; (define param_2 (send obj find value))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0170](https://leetcode-cn.com/problems/two-sum-iii-data-structure-design)", "[\u4e24\u6570\u4e4b\u548c III - \u6570\u636e\u7ed3\u6784\u8bbe\u8ba1](/solution/0100-0199/0170.Two%20Sum%20III%20-%20Data%20structure%20design/README.md)", "`\u8bbe\u8ba1`,`\u54c8\u5e0c\u8868`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0170](https://leetcode.com/problems/two-sum-iii-data-structure-design)", "[Two Sum III - Data structure design](/solution/0100-0199/0170.Two%20Sum%20III%20-%20Data%20structure%20design/README_EN.md)", "`Design`,`Hash Table`", "Easy", "\ud83d\udd12"]}, {"question_id": "0169", "frontend_question_id": "0169", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/majority-element", "url_en": "https://leetcode.com/problems/majority-element", "relative_path_cn": "/solution/0100-0199/0169.Majority%20Element/README.md", "relative_path_en": "/solution/0100-0199/0169.Majority%20Element/README_EN.md", "title_cn": "\u591a\u6570\u5143\u7d20", "title_en": "Majority Element", "question_title_slug": "majority-element", "content_en": "

    Given an array nums of size n, return the majority element.

    \n\n

    The majority element is the element that appears more than ⌊n / 2⌋ times. You may assume that the majority element always exists in the array.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [3,2,3]\nOutput: 3\n

    Example 2:

    \n
    Input: nums = [2,2,1,1,1,2,2]\nOutput: 2\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= n <= 5 * 104
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n
    \n\n

     

    \nFollow-up: Could you solve the problem in linear time and in O(1) space?", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5927\u5c0f\u4e3a n \u7684\u6570\u7ec4\uff0c\u627e\u5230\u5176\u4e2d\u7684\u591a\u6570\u5143\u7d20\u3002\u591a\u6570\u5143\u7d20\u662f\u6307\u5728\u6570\u7ec4\u4e2d\u51fa\u73b0\u6b21\u6570 \u5927\u4e8e\u00a0\u230a n/2 \u230b\u00a0\u7684\u5143\u7d20\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u5047\u8bbe\u6570\u7ec4\u662f\u975e\u7a7a\u7684\uff0c\u5e76\u4e14\u7ed9\u5b9a\u7684\u6570\u7ec4\u603b\u662f\u5b58\u5728\u591a\u6570\u5143\u7d20\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\u00a01\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[3,2,3]\n\u8f93\u51fa\uff1a3
    \n\n

    \u793a\u4f8b\u00a02\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[2,2,1,1,1,2,2]\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u5c1d\u8bd5\u8bbe\u8ba1\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\u3001\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a O(1) \u7684\u7b97\u6cd5\u89e3\u51b3\u6b64\u95ee\u9898\u3002
    • \n
    \n", "tags_en": ["Bit Manipulation", "Array", "Divide and Conquer"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u6570\u7ec4", "\u5206\u6cbb\u7b97\u6cd5"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int majorityElement(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int majorityElement(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def majorityElement(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def majorityElement(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint majorityElement(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MajorityElement(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar majorityElement = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef majority_element(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func majorityElement(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func majorityElement(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def majorityElement(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun majorityElement(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn majority_element(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function majorityElement($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function majorityElement(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (majority-element nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0169](https://leetcode-cn.com/problems/majority-element)", "[\u591a\u6570\u5143\u7d20](/solution/0100-0199/0169.Majority%20Element/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u6570\u7ec4`,`\u5206\u6cbb\u7b97\u6cd5`", "\u7b80\u5355", ""], "md_table_row_en": ["[0169](https://leetcode.com/problems/majority-element)", "[Majority Element](/solution/0100-0199/0169.Majority%20Element/README_EN.md)", "`Bit Manipulation`,`Array`,`Divide and Conquer`", "Easy", ""]}, {"question_id": "0168", "frontend_question_id": "0168", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/excel-sheet-column-title", "url_en": "https://leetcode.com/problems/excel-sheet-column-title", "relative_path_cn": "/solution/0100-0199/0168.Excel%20Sheet%20Column%20Title/README.md", "relative_path_en": "/solution/0100-0199/0168.Excel%20Sheet%20Column%20Title/README_EN.md", "title_cn": "Excel\u8868\u5217\u540d\u79f0", "title_en": "Excel Sheet Column Title", "question_title_slug": "excel-sheet-column-title", "content_en": "

    Given an integer columnNumber, return its corresponding column title as it appears in an Excel sheet.

    \n\n

    For example:

    \n\n
    \nA -> 1\nB -> 2\nC -> 3\n...\nZ -> 26\nAA -> 27\nAB -> 28 \n...\n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: columnNumber = 1\nOutput: "A"\n
    \n\n

    Example 2:

    \n\n
    \nInput: columnNumber = 28\nOutput: "AB"\n
    \n\n

    Example 3:

    \n\n
    \nInput: columnNumber = 701\nOutput: "ZY"\n
    \n\n

    Example 4:

    \n\n
    \nInput: columnNumber = 2147483647\nOutput: "FXSHRXW"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= columnNumber <= 231 - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6b63\u6574\u6570\uff0c\u8fd4\u56de\u5b83\u5728 Excel \u8868\u4e2d\u76f8\u5bf9\u5e94\u7684\u5217\u540d\u79f0\u3002

    \n\n

    \u4f8b\u5982\uff0c

    \n\n
        1 -> A\n    2 -> B\n    3 -> C\n    ...\n    26 -> Z\n    27 -> AA\n    28 -> AB \n    ...\n
    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: 1\n\u8f93\u51fa: "A"\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: 28\n\u8f93\u51fa: "AB"\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u8f93\u5165: 701\n\u8f93\u51fa: "ZY"\n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string convertToTitle(int columnNumber) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String convertToTitle(int columnNumber) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def convertToTitle(self, columnNumber):\n \"\"\"\n :type columnNumber: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def convertToTitle(self, columnNumber: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * convertToTitle(int columnNumber){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ConvertToTitle(int columnNumber) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} columnNumber\n * @return {string}\n */\nvar convertToTitle = function(columnNumber) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} column_number\n# @return {String}\ndef convert_to_title(column_number)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func convertToTitle(_ columnNumber: Int) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func convertToTitle(columnNumber int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def convertToTitle(columnNumber: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun convertToTitle(columnNumber: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn convert_to_title(column_number: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $columnNumber\n * @return String\n */\n function convertToTitle($columnNumber) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function convertToTitle(columnNumber: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (convert-to-title columnNumber)\n (-> exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0168](https://leetcode-cn.com/problems/excel-sheet-column-title)", "[Excel\u8868\u5217\u540d\u79f0](/solution/0100-0199/0168.Excel%20Sheet%20Column%20Title/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0168](https://leetcode.com/problems/excel-sheet-column-title)", "[Excel Sheet Column Title](/solution/0100-0199/0168.Excel%20Sheet%20Column%20Title/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "0167", "frontend_question_id": "0167", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/two-sum-ii-input-array-is-sorted", "url_en": "https://leetcode.com/problems/two-sum-ii-input-array-is-sorted", "relative_path_cn": "/solution/0100-0199/0167.Two%20Sum%20II%20-%20Input%20array%20is%20sorted/README.md", "relative_path_en": "/solution/0100-0199/0167.Two%20Sum%20II%20-%20Input%20array%20is%20sorted/README_EN.md", "title_cn": "\u4e24\u6570\u4e4b\u548c II - \u8f93\u5165\u6709\u5e8f\u6570\u7ec4", "title_en": "Two Sum II - Input array is sorted", "question_title_slug": "two-sum-ii-input-array-is-sorted", "content_en": "

    Given an array of integers numbers that is already sorted in non-decreasing order, find two numbers such that they add up to a specific target number.

    \n\n

    Return the indices of the two numbers (1-indexed) as an integer array answer of size 2, where 1 <= answer[0] < answer[1] <= numbers.length.

    \n\n

    The tests are generated such that there is exactly one solution. You may not use the same element twice.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: numbers = [2,7,11,15], target = 9\nOutput: [1,2]\nExplanation: The sum of 2 and 7 is 9. Therefore index1 = 1, index2 = 2.\n
    \n\n

    Example 2:

    \n\n
    \nInput: numbers = [2,3,4], target = 6\nOutput: [1,3]\n
    \n\n

    Example 3:

    \n\n
    \nInput: numbers = [-1,0], target = -1\nOutput: [1,2]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= numbers.length <= 3 * 104
    • \n\t
    • -1000 <= numbers[i] <= 1000
    • \n\t
    • numbers is sorted in non-decreasing order.
    • \n\t
    • -1000 <= target <= 1000
    • \n\t
    • The tests are generated such that there is exactly one solution.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5df2\u6309\u7167 \u5347\u5e8f\u6392\u5217\u00a0 \u7684\u6574\u6570\u6570\u7ec4\u00a0numbers \uff0c\u8bf7\u4f60\u4ece\u6570\u7ec4\u4e2d\u627e\u51fa\u4e24\u4e2a\u6570\u6ee1\u8db3\u76f8\u52a0\u4e4b\u548c\u7b49\u4e8e\u76ee\u6807\u6570\u00a0target \u3002

    \n\n

    \u51fd\u6570\u5e94\u8be5\u4ee5\u957f\u5ea6\u4e3a 2 \u7684\u6574\u6570\u6570\u7ec4\u7684\u5f62\u5f0f\u8fd4\u56de\u8fd9\u4e24\u4e2a\u6570\u7684\u4e0b\u6807\u503c\u3002numbers \u7684\u4e0b\u6807 \u4ece 1 \u5f00\u59cb\u8ba1\u6570 \uff0c\u6240\u4ee5\u7b54\u6848\u6570\u7ec4\u5e94\u5f53\u6ee1\u8db3 1 <= answer[0] < answer[1] <= numbers.length \u3002

    \n\n

    \u4f60\u53ef\u4ee5\u5047\u8bbe\u6bcf\u4e2a\u8f93\u5165\u53ea\u5bf9\u5e94\u552f\u4e00\u7684\u7b54\u6848\uff0c\u800c\u4e14\u4f60\u4e0d\u53ef\u4ee5\u91cd\u590d\u4f7f\u7528\u76f8\u540c\u7684\u5143\u7d20\u3002

    \n\u00a0\n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anumbers = [2,7,11,15], target = 9\n\u8f93\u51fa\uff1a[1,2]\n\u89e3\u91ca\uff1a2 \u4e0e 7 \u4e4b\u548c\u7b49\u4e8e\u76ee\u6807\u6570 9 \u3002\u56e0\u6b64 index1 = 1, index2 = 2 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anumbers = [2,3,4], target = 6\n\u8f93\u51fa\uff1a[1,3]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anumbers = [-1,0], target = -1\n\u8f93\u51fa\uff1a[1,2]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= numbers.length <= 3 * 104
    • \n\t
    • -1000 <= numbers[i] <= 1000
    • \n\t
    • numbers \u6309 \u9012\u589e\u987a\u5e8f \u6392\u5217
    • \n\t
    • -1000 <= target <= 1000
    • \n\t
    • \u4ec5\u5b58\u5728\u4e00\u4e2a\u6709\u6548\u7b54\u6848
    • \n
    \n", "tags_en": ["Array", "Two Pointers", "Binary Search"], "tags_cn": ["\u6570\u7ec4", "\u53cc\u6307\u9488", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector twoSum(vector& numbers, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] twoSum(int[] numbers, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def twoSum(self, numbers, target):\n \"\"\"\n :type numbers: List[int]\n :type target: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def twoSum(self, numbers: List[int], target: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* twoSum(int* numbers, int numbersSize, int target, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] TwoSum(int[] numbers, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} numbers\n * @param {number} target\n * @return {number[]}\n */\nvar twoSum = function(numbers, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} numbers\n# @param {Integer} target\n# @return {Integer[]}\ndef two_sum(numbers, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func twoSum(_ numbers: [Int], _ target: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func twoSum(numbers []int, target int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def twoSum(numbers: Array[Int], target: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun twoSum(numbers: IntArray, target: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn two_sum(numbers: Vec, target: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $numbers\n * @param Integer $target\n * @return Integer[]\n */\n function twoSum($numbers, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function twoSum(numbers: number[], target: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (two-sum numbers target)\n (-> (listof exact-integer?) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0167](https://leetcode-cn.com/problems/two-sum-ii-input-array-is-sorted)", "[\u4e24\u6570\u4e4b\u548c II - \u8f93\u5165\u6709\u5e8f\u6570\u7ec4](/solution/0100-0199/0167.Two%20Sum%20II%20-%20Input%20array%20is%20sorted/README.md)", "`\u6570\u7ec4`,`\u53cc\u6307\u9488`,`\u4e8c\u5206\u67e5\u627e`", "\u7b80\u5355", ""], "md_table_row_en": ["[0167](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted)", "[Two Sum II - Input array is sorted](/solution/0100-0199/0167.Two%20Sum%20II%20-%20Input%20array%20is%20sorted/README_EN.md)", "`Array`,`Two Pointers`,`Binary Search`", "Easy", ""]}, {"question_id": "0166", "frontend_question_id": "0166", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/fraction-to-recurring-decimal", "url_en": "https://leetcode.com/problems/fraction-to-recurring-decimal", "relative_path_cn": "/solution/0100-0199/0166.Fraction%20to%20Recurring%20Decimal/README.md", "relative_path_en": "/solution/0100-0199/0166.Fraction%20to%20Recurring%20Decimal/README_EN.md", "title_cn": "\u5206\u6570\u5230\u5c0f\u6570", "title_en": "Fraction to Recurring Decimal", "question_title_slug": "fraction-to-recurring-decimal", "content_en": "

    Given two integers representing the numerator and denominator of a fraction, return the fraction in string format.

    \n\n

    If the fractional part is repeating, enclose the repeating part in parentheses.

    \n\n

    If multiple answers are possible, return any of them.

    \n\n

    It is guaranteed that the length of the answer string is less than 104 for all the given inputs.

    \n\n

     

    \n

    Example 1:

    \n
    Input: numerator = 1, denominator = 2\nOutput: \"0.5\"\n

    Example 2:

    \n
    Input: numerator = 2, denominator = 1\nOutput: \"2\"\n

    Example 3:

    \n
    Input: numerator = 2, denominator = 3\nOutput: \"0.(6)\"\n

    Example 4:

    \n
    Input: numerator = 4, denominator = 333\nOutput: \"0.(012)\"\n

    Example 5:

    \n
    Input: numerator = 1, denominator = 5\nOutput: \"0.2\"\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • -231 <= numerator, denominator <= 231 - 1
    • \n\t
    • denominator != 0
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u6574\u6570\uff0c\u5206\u522b\u8868\u793a\u5206\u6570\u7684\u5206\u5b50\u00a0numerator \u548c\u5206\u6bcd denominator\uff0c\u4ee5 \u5b57\u7b26\u4e32\u5f62\u5f0f\u8fd4\u56de\u5c0f\u6570 \u3002

    \n\n

    \u5982\u679c\u5c0f\u6570\u90e8\u5206\u4e3a\u5faa\u73af\u5c0f\u6570\uff0c\u5219\u5c06\u5faa\u73af\u7684\u90e8\u5206\u62ec\u5728\u62ec\u53f7\u5185\u3002

    \n\n

    \u5982\u679c\u5b58\u5728\u591a\u4e2a\u7b54\u6848\uff0c\u53ea\u9700\u8fd4\u56de \u4efb\u610f\u4e00\u4e2a \u3002

    \n\n

    \u5bf9\u4e8e\u6240\u6709\u7ed9\u5b9a\u7684\u8f93\u5165\uff0c\u4fdd\u8bc1 \u7b54\u6848\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u5c0f\u4e8e 104 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anumerator = 1, denominator = 2\n\u8f93\u51fa\uff1a\"0.5\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anumerator = 2, denominator = 1\n\u8f93\u51fa\uff1a\"2\"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anumerator = 2, denominator = 3\n\u8f93\u51fa\uff1a\"0.(6)\"\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1anumerator = 4, denominator = 333\n\u8f93\u51fa\uff1a\"0.(012)\"\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1anumerator = 1, denominator = 5\n\u8f93\u51fa\uff1a\"0.2\"\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • -231 <=\u00a0numerator, denominator <= 231 - 1
    • \n\t
    • denominator != 0
    • \n
    \n", "tags_en": ["Hash Table", "Math"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string fractionToDecimal(int numerator, int denominator) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String fractionToDecimal(int numerator, int denominator) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def fractionToDecimal(self, numerator, denominator):\n \"\"\"\n :type numerator: int\n :type denominator: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def fractionToDecimal(self, numerator: int, denominator: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * fractionToDecimal(int numerator, int denominator){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string FractionToDecimal(int numerator, int denominator) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} numerator\n * @param {number} denominator\n * @return {string}\n */\nvar fractionToDecimal = function(numerator, denominator) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} numerator\n# @param {Integer} denominator\n# @return {String}\ndef fraction_to_decimal(numerator, denominator)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func fractionToDecimal(_ numerator: Int, _ denominator: Int) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func fractionToDecimal(numerator int, denominator int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def fractionToDecimal(numerator: Int, denominator: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun fractionToDecimal(numerator: Int, denominator: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn fraction_to_decimal(numerator: i32, denominator: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $numerator\n * @param Integer $denominator\n * @return String\n */\n function fractionToDecimal($numerator, $denominator) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function fractionToDecimal(numerator: number, denominator: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (fraction-to-decimal numerator denominator)\n (-> exact-integer? exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0166](https://leetcode-cn.com/problems/fraction-to-recurring-decimal)", "[\u5206\u6570\u5230\u5c0f\u6570](/solution/0100-0199/0166.Fraction%20to%20Recurring%20Decimal/README.md)", "`\u54c8\u5e0c\u8868`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0166](https://leetcode.com/problems/fraction-to-recurring-decimal)", "[Fraction to Recurring Decimal](/solution/0100-0199/0166.Fraction%20to%20Recurring%20Decimal/README_EN.md)", "`Hash Table`,`Math`", "Medium", ""]}, {"question_id": "0165", "frontend_question_id": "0165", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/compare-version-numbers", "url_en": "https://leetcode.com/problems/compare-version-numbers", "relative_path_cn": "/solution/0100-0199/0165.Compare%20Version%20Numbers/README.md", "relative_path_en": "/solution/0100-0199/0165.Compare%20Version%20Numbers/README_EN.md", "title_cn": "\u6bd4\u8f83\u7248\u672c\u53f7", "title_en": "Compare Version Numbers", "question_title_slug": "compare-version-numbers", "content_en": "

    Given two version numbers, version1 and version2, compare them.

    \n\n
      \n
    \n\n

    Version numbers consist of one or more revisions joined by a dot '.'. Each revision consists of digits and may contain leading zeros. Every revision contains at least one character. Revisions are 0-indexed from left to right, with the leftmost revision being revision 0, the next revision being revision 1, and so on. For example 2.5.33 and 0.1 are valid version numbers.

    \n\n

    To compare version numbers, compare their revisions in left-to-right order. Revisions are compared using their integer value ignoring any leading zeros. This means that revisions 1 and 001 are considered equal. If a version number does not specify a revision at an index, then treat the revision as 0. For example, version 1.0 is less than version 1.1 because their revision 0s are the same, but their revision 1s are 0 and 1 respectively, and 0 < 1.

    \n\n

    Return the following:

    \n\n
      \n\t
    • If version1 < version2, return -1.
    • \n\t
    • If version1 > version2, return 1.
    • \n\t
    • Otherwise, return 0.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: version1 = "1.01", version2 = "1.001"\nOutput: 0\nExplanation: Ignoring leading zeroes, both "01" and "001" represent the same integer "1".\n
    \n\n

    Example 2:

    \n\n
    \nInput: version1 = "1.0", version2 = "1.0.0"\nOutput: 0\nExplanation: version1 does not specify revision 2, which means it is treated as "0".\n
    \n\n

    Example 3:

    \n\n
    \nInput: version1 = "0.1", version2 = "1.1"\nOutput: -1\nExplanation: version1's revision 0 is "0", while version2's revision 0 is "1". 0 < 1, so version1 < version2.\n
    \n\n

    Example 4:

    \n\n
    \nInput: version1 = "1.0.1", version2 = "1"\nOutput: 1\n
    \n\n

    Example 5:

    \n\n
    \nInput: version1 = "7.5.2.4", version2 = "7.5.3"\nOutput: -1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= version1.length, version2.length <= 500
    • \n\t
    • version1 and version2 only contain digits and '.'.
    • \n\t
    • version1 and version2 are valid version numbers.
    • \n\t
    • All the given revisions in version1 and version2 can be stored in a 32-bit integer.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u7248\u672c\u53f7 version1 \u548c version2 \uff0c\u8bf7\u4f60\u6bd4\u8f83\u5b83\u4eec\u3002

    \n\n

    \u7248\u672c\u53f7\u7531\u4e00\u4e2a\u6216\u591a\u4e2a\u4fee\u8ba2\u53f7\u7ec4\u6210\uff0c\u5404\u4fee\u8ba2\u53f7\u7531\u4e00\u4e2a '.' \u8fde\u63a5\u3002\u6bcf\u4e2a\u4fee\u8ba2\u53f7\u7531 \u591a\u4f4d\u6570\u5b57 \u7ec4\u6210\uff0c\u53ef\u80fd\u5305\u542b \u524d\u5bfc\u96f6 \u3002\u6bcf\u4e2a\u7248\u672c\u53f7\u81f3\u5c11\u5305\u542b\u4e00\u4e2a\u5b57\u7b26\u3002\u4fee\u8ba2\u53f7\u4ece\u5de6\u5230\u53f3\u7f16\u53f7\uff0c\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff0c\u6700\u5de6\u8fb9\u7684\u4fee\u8ba2\u53f7\u4e0b\u6807\u4e3a 0 \uff0c\u4e0b\u4e00\u4e2a\u4fee\u8ba2\u53f7\u4e0b\u6807\u4e3a 1 \uff0c\u4ee5\u6b64\u7c7b\u63a8\u3002\u4f8b\u5982\uff0c2.5.33 \u548c 0.1 \u90fd\u662f\u6709\u6548\u7684\u7248\u672c\u53f7\u3002

    \n\n

    \u6bd4\u8f83\u7248\u672c\u53f7\u65f6\uff0c\u8bf7\u6309\u4ece\u5de6\u5230\u53f3\u7684\u987a\u5e8f\u4f9d\u6b21\u6bd4\u8f83\u5b83\u4eec\u7684\u4fee\u8ba2\u53f7\u3002\u6bd4\u8f83\u4fee\u8ba2\u53f7\u65f6\uff0c\u53ea\u9700\u6bd4\u8f83 \u5ffd\u7565\u4efb\u4f55\u524d\u5bfc\u96f6\u540e\u7684\u6574\u6570\u503c \u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u4fee\u8ba2\u53f7 1 \u548c\u4fee\u8ba2\u53f7 001 \u76f8\u7b49 \u3002\u5982\u679c\u7248\u672c\u53f7\u6ca1\u6709\u6307\u5b9a\u67d0\u4e2a\u4e0b\u6807\u5904\u7684\u4fee\u8ba2\u53f7\uff0c\u5219\u8be5\u4fee\u8ba2\u53f7\u89c6\u4e3a 0 \u3002\u4f8b\u5982\uff0c\u7248\u672c 1.0 \u5c0f\u4e8e\u7248\u672c 1.1 \uff0c\u56e0\u4e3a\u5b83\u4eec\u4e0b\u6807\u4e3a 0 \u7684\u4fee\u8ba2\u53f7\u76f8\u540c\uff0c\u800c\u4e0b\u6807\u4e3a 1 \u7684\u4fee\u8ba2\u53f7\u5206\u522b\u4e3a 0 \u548c 1 \uff0c0 < 1 \u3002

    \n\n

    \u8fd4\u56de\u89c4\u5219\u5982\u4e0b\uff1a

    \n\n
      \n\t
    • \u5982\u679c\u00a0version1\u00a0>\u00a0version2\u00a0\u8fd4\u56de\u00a01\uff0c
    • \n\t
    • \u5982\u679c\u00a0version1\u00a0<\u00a0version2 \u8fd4\u56de -1\uff0c
    • \n\t
    • \u9664\u6b64\u4e4b\u5916\u8fd4\u56de 0\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aversion1 = \"1.01\", version2 = \"1.001\"\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u5ffd\u7565\u524d\u5bfc\u96f6\uff0c\"01\" \u548c \"001\" \u90fd\u8868\u793a\u76f8\u540c\u7684\u6574\u6570 \"1\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aversion1 = \"1.0\", version2 = \"1.0.0\"\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1aversion1 \u6ca1\u6709\u6307\u5b9a\u4e0b\u6807\u4e3a 2 \u7684\u4fee\u8ba2\u53f7\uff0c\u5373\u89c6\u4e3a \"0\"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aversion1 = \"0.1\", version2 = \"1.1\"\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1aversion1 \u4e2d\u4e0b\u6807\u4e3a 0 \u7684\u4fee\u8ba2\u53f7\u662f \"0\"\uff0cversion2 \u4e2d\u4e0b\u6807\u4e3a 0 \u7684\u4fee\u8ba2\u53f7\u662f \"1\" \u30020 < 1\uff0c\u6240\u4ee5 version1 < version2\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1aversion1 = \"1.0.1\", version2 = \"1\"\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1aversion1 = \"7.5.2.4\", version2 = \"7.5.3\"\n\u8f93\u51fa\uff1a-1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= version1.length, version2.length <= 500
    • \n\t
    • version1 \u548c version2 \u4ec5\u5305\u542b\u6570\u5b57\u548c '.'
    • \n\t
    • version1 \u548c version2 \u90fd\u662f \u6709\u6548\u7248\u672c\u53f7
    • \n\t
    • version1 \u548c version2 \u7684\u6240\u6709\u4fee\u8ba2\u53f7\u90fd\u53ef\u4ee5\u5b58\u50a8\u5728 32 \u4f4d\u6574\u6570 \u4e2d
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int compareVersion(string version1, string version2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int compareVersion(String version1, String version2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def compareVersion(self, version1, version2):\n \"\"\"\n :type version1: str\n :type version2: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def compareVersion(self, version1: str, version2: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint compareVersion(char * version1, char * version2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CompareVersion(string version1, string version2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} version1\n * @param {string} version2\n * @return {number}\n */\nvar compareVersion = function(version1, version2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} version1\n# @param {String} version2\n# @return {Integer}\ndef compare_version(version1, version2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func compareVersion(_ version1: String, _ version2: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func compareVersion(version1 string, version2 string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def compareVersion(version1: String, version2: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun compareVersion(version1: String, version2: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn compare_version(version1: String, version2: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $version1\n * @param String $version2\n * @return Integer\n */\n function compareVersion($version1, $version2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function compareVersion(version1: string, version2: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (compare-version version1 version2)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0165](https://leetcode-cn.com/problems/compare-version-numbers)", "[\u6bd4\u8f83\u7248\u672c\u53f7](/solution/0100-0199/0165.Compare%20Version%20Numbers/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0165](https://leetcode.com/problems/compare-version-numbers)", "[Compare Version Numbers](/solution/0100-0199/0165.Compare%20Version%20Numbers/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "0164", "frontend_question_id": "0164", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-gap", "url_en": "https://leetcode.com/problems/maximum-gap", "relative_path_cn": "/solution/0100-0199/0164.Maximum%20Gap/README.md", "relative_path_en": "/solution/0100-0199/0164.Maximum%20Gap/README_EN.md", "title_cn": "\u6700\u5927\u95f4\u8ddd", "title_en": "Maximum Gap", "question_title_slug": "maximum-gap", "content_en": "

    Given an integer array nums, return the maximum difference between two successive elements in its sorted form. If the array contains less than two elements, return 0.

    \n\n

    You must write an algorithm that runs in linear time and uses linear extra space.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [3,6,9,1]\nOutput: 3\nExplanation: The sorted form of the array is [1,3,6,9], either (3,6) or (6,9) has the maximum difference 3.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [10]\nOutput: 0\nExplanation: The array contains less than 2 elements, therefore return 0.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 104
    • \n\t
    • 0 <= nums[i] <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u65e0\u5e8f\u7684\u6570\u7ec4\uff0c\u627e\u51fa\u6570\u7ec4\u5728\u6392\u5e8f\u4e4b\u540e\uff0c\u76f8\u90bb\u5143\u7d20\u4e4b\u95f4\u6700\u5927\u7684\u5dee\u503c\u3002

    \n\n

    \u5982\u679c\u6570\u7ec4\u5143\u7d20\u4e2a\u6570\u5c0f\u4e8e 2\uff0c\u5219\u8fd4\u56de 0\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: [3,6,9,1]\n\u8f93\u51fa: 3\n\u89e3\u91ca: \u6392\u5e8f\u540e\u7684\u6570\u7ec4\u662f [1,3,6,9], \u5176\u4e2d\u76f8\u90bb\u5143\u7d20 (3,6) \u548c (6,9) \u4e4b\u95f4\u90fd\u5b58\u5728\u6700\u5927\u5dee\u503c 3\u3002
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: [10]\n\u8f93\u51fa: 0\n\u89e3\u91ca: \u6570\u7ec4\u5143\u7d20\u4e2a\u6570\u5c0f\u4e8e 2\uff0c\u56e0\u6b64\u8fd4\u56de 0\u3002
    \n\n

    \u8bf4\u660e:

    \n\n
      \n\t
    • \u4f60\u53ef\u4ee5\u5047\u8bbe\u6570\u7ec4\u4e2d\u6240\u6709\u5143\u7d20\u90fd\u662f\u975e\u8d1f\u6574\u6570\uff0c\u4e14\u6570\u503c\u5728 32 \u4f4d\u6709\u7b26\u53f7\u6574\u6570\u8303\u56f4\u5185\u3002
    • \n\t
    • \u8bf7\u5c1d\u8bd5\u5728\u7ebf\u6027\u65f6\u95f4\u590d\u6742\u5ea6\u548c\u7a7a\u95f4\u590d\u6742\u5ea6\u7684\u6761\u4ef6\u4e0b\u89e3\u51b3\u6b64\u95ee\u9898\u3002
    • \n
    \n", "tags_en": ["Sort"], "tags_cn": ["\u6392\u5e8f"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maximumGap(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maximumGap(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximumGap(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximumGap(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maximumGap(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaximumGap(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar maximumGap = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef maximum_gap(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximumGap(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximumGap(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximumGap(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximumGap(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximum_gap(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function maximumGap($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximumGap(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximum-gap nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0164](https://leetcode-cn.com/problems/maximum-gap)", "[\u6700\u5927\u95f4\u8ddd](/solution/0100-0199/0164.Maximum%20Gap/README.md)", "`\u6392\u5e8f`", "\u56f0\u96be", ""], "md_table_row_en": ["[0164](https://leetcode.com/problems/maximum-gap)", "[Maximum Gap](/solution/0100-0199/0164.Maximum%20Gap/README_EN.md)", "`Sort`", "Hard", ""]}, {"question_id": "0163", "frontend_question_id": "0163", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/missing-ranges", "url_en": "https://leetcode.com/problems/missing-ranges", "relative_path_cn": "/solution/0100-0199/0163.Missing%20Ranges/README.md", "relative_path_en": "/solution/0100-0199/0163.Missing%20Ranges/README_EN.md", "title_cn": "\u7f3a\u5931\u7684\u533a\u95f4", "title_en": "Missing Ranges", "question_title_slug": "missing-ranges", "content_en": "

    You are given an inclusive range [lower, upper] and a sorted unique integer array nums, where all elements are in the inclusive range.

    \n\n

    A number x is considered missing if x is in the range [lower, upper] and x is not in nums.

    \n\n

    Return the smallest sorted list of ranges that cover every missing number exactly. That is, no element of nums is in any of the ranges, and each missing number is in one of the ranges.

    \n\n

    Each range [a,b] in the list should be output as:

    \n\n
      \n\t
    • "a->b" if a != b
    • \n\t
    • "a" if a == b
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [0,1,3,50,75], lower = 0, upper = 99\nOutput: ["2","4->49","51->74","76->99"]\nExplanation: The ranges are:\n[2,2] --> "2"\n[4,49] --> "4->49"\n[51,74] --> "51->74"\n[76,99] --> "76->99"\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [], lower = 1, upper = 1\nOutput: ["1"]\nExplanation: The only missing range is [1,1], which becomes "1".\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [], lower = -3, upper = -1\nOutput: ["-3->-1"]\nExplanation: The only missing range is [-3,-1], which becomes "-3->-1".\n
    \n\n

    Example 4:

    \n\n
    \nInput: nums = [-1], lower = -1, upper = -1\nOutput: []\nExplanation: There are no missing ranges since there are no missing numbers.\n
    \n\n

    Example 5:

    \n\n
    \nInput: nums = [-1], lower = -2, upper = -1\nOutput: ["-2"]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • -109 <= lower <= upper <= 109
    • \n\t
    • 0 <= nums.length <= 100
    • \n\t
    • lower <= nums[i] <= upper
    • \n\t
    • All the values of nums are unique.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6392\u5e8f\u7684\u6574\u6570\u6570\u7ec4 nums \uff0c\u5176\u4e2d\u5143\u7d20\u7684\u8303\u56f4\u5728 \u95ed\u533a\u95f4 [lower, upper] \u5f53\u4e2d\uff0c\u8fd4\u56de\u4e0d\u5305\u542b\u5728\u6570\u7ec4\u4e2d\u7684\u7f3a\u5931\u533a\u95f4\u3002

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165: nums = [0, 1, 3, 50, 75], lower = 0 \u548c upper = 99,\n\u8f93\u51fa: ["2", "4->49", "51->74", "76->99"]\n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findMissingRanges(vector& nums, int lower, int upper) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List findMissingRanges(int[] nums, int lower, int upper) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findMissingRanges(self, nums, lower, upper):\n \"\"\"\n :type nums: List[int]\n :type lower: int\n :type upper: int\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findMissingRanges(self, nums: List[int], lower: int, upper: int) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** findMissingRanges(int* nums, int numsSize, int lower, int upper, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList FindMissingRanges(int[] nums, int lower, int upper) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} lower\n * @param {number} upper\n * @return {string[]}\n */\nvar findMissingRanges = function(nums, lower, upper) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} lower\n# @param {Integer} upper\n# @return {String[]}\ndef find_missing_ranges(nums, lower, upper)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findMissingRanges(_ nums: [Int], _ lower: Int, _ upper: Int) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findMissingRanges(nums []int, lower int, upper int) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findMissingRanges(nums: Array[Int], lower: Int, upper: Int): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findMissingRanges(nums: IntArray, lower: Int, upper: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_missing_ranges(nums: Vec, lower: i32, upper: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $lower\n * @param Integer $upper\n * @return String[]\n */\n function findMissingRanges($nums, $lower, $upper) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findMissingRanges(nums: number[], lower: number, upper: number): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-missing-ranges nums lower upper)\n (-> (listof exact-integer?) exact-integer? exact-integer? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0163](https://leetcode-cn.com/problems/missing-ranges)", "[\u7f3a\u5931\u7684\u533a\u95f4](/solution/0100-0199/0163.Missing%20Ranges/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0163](https://leetcode.com/problems/missing-ranges)", "[Missing Ranges](/solution/0100-0199/0163.Missing%20Ranges/README_EN.md)", "`Array`", "Easy", "\ud83d\udd12"]}, {"question_id": "0162", "frontend_question_id": "0162", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-peak-element", "url_en": "https://leetcode.com/problems/find-peak-element", "relative_path_cn": "/solution/0100-0199/0162.Find%20Peak%20Element/README.md", "relative_path_en": "/solution/0100-0199/0162.Find%20Peak%20Element/README_EN.md", "title_cn": "\u5bfb\u627e\u5cf0\u503c", "title_en": "Find Peak Element", "question_title_slug": "find-peak-element", "content_en": "

    A peak element is an element that is strictly greater than its neighbors.

    \n\n

    Given an integer array nums, find a peak element, and return its index. If the array contains multiple peaks, return the index to any of the peaks.

    \n\n

    You may imagine that nums[-1] = nums[n] = -∞.

    \n\n

    You must write an algorithm that runs in O(log n) time.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,3,1]\nOutput: 2\nExplanation: 3 is a peak element and your function should return the index number 2.
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,2,1,3,5,6,4]\nOutput: 5\nExplanation: Your function can return either index number 1 where the peak element is 2, or index number 5 where the peak element is 6.
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 1000
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n\t
    • nums[i] != nums[i + 1] for all valid i.
    • \n
    \n", "content_cn": "

    \u5cf0\u503c\u5143\u7d20\u662f\u6307\u5176\u503c\u5927\u4e8e\u5de6\u53f3\u76f8\u90bb\u503c\u7684\u5143\u7d20\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u8f93\u5165\u6570\u7ec4\u00a0nums\uff0c\u627e\u5230\u5cf0\u503c\u5143\u7d20\u5e76\u8fd4\u56de\u5176\u7d22\u5f15\u3002\u6570\u7ec4\u53ef\u80fd\u5305\u542b\u591a\u4e2a\u5cf0\u503c\uff0c\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u8fd4\u56de \u4efb\u4f55\u4e00\u4e2a\u5cf0\u503c \u6240\u5728\u4f4d\u7f6e\u5373\u53ef\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u5047\u8bbe\u00a0nums[-1] = nums[n] = -\u221e \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,3,1]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a3 \u662f\u5cf0\u503c\u5143\u7d20\uff0c\u4f60\u7684\u51fd\u6570\u5e94\u8be5\u8fd4\u56de\u5176\u7d22\u5f15 2\u3002
    \n\n

    \u793a\u4f8b\u00a02\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,1,3,5,6,4]\n\u8f93\u51fa\uff1a1 \u6216 5 \n\u89e3\u91ca\uff1a\u4f60\u7684\u51fd\u6570\u53ef\u4ee5\u8fd4\u56de\u7d22\u5f15 1\uff0c\u5176\u5cf0\u503c\u5143\u7d20\u4e3a 2\uff1b\n\u00a0    \u6216\u8005\u8fd4\u56de\u7d22\u5f15 5\uff0c \u5176\u5cf0\u503c\u5143\u7d20\u4e3a 6\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 1000
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n\t
    • \u5bf9\u4e8e\u6240\u6709\u6709\u6548\u7684 i \u90fd\u6709 nums[i] != nums[i + 1]
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u53ef\u4ee5\u5b9e\u73b0\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(logN) \u7684\u89e3\u51b3\u65b9\u6848\u5417\uff1f

    \n", "tags_en": ["Array", "Binary Search"], "tags_cn": ["\u6570\u7ec4", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findPeakElement(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findPeakElement(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findPeakElement(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findPeakElement(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findPeakElement(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindPeakElement(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar findPeakElement = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef find_peak_element(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findPeakElement(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findPeakElement(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findPeakElement(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findPeakElement(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_peak_element(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function findPeakElement($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findPeakElement(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-peak-element nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0162](https://leetcode-cn.com/problems/find-peak-element)", "[\u5bfb\u627e\u5cf0\u503c](/solution/0100-0199/0162.Find%20Peak%20Element/README.md)", "`\u6570\u7ec4`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0162](https://leetcode.com/problems/find-peak-element)", "[Find Peak Element](/solution/0100-0199/0162.Find%20Peak%20Element/README_EN.md)", "`Array`,`Binary Search`", "Medium", ""]}, {"question_id": "0161", "frontend_question_id": "0161", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/one-edit-distance", "url_en": "https://leetcode.com/problems/one-edit-distance", "relative_path_cn": "/solution/0100-0199/0161.One%20Edit%20Distance/README.md", "relative_path_en": "/solution/0100-0199/0161.One%20Edit%20Distance/README_EN.md", "title_cn": "\u76f8\u9694\u4e3a 1 \u7684\u7f16\u8f91\u8ddd\u79bb", "title_en": "One Edit Distance", "question_title_slug": "one-edit-distance", "content_en": "

    Given two strings s and t, return true if they are both one edit distance apart, otherwise return false.

    \n\n

    A string s is said to be one distance apart from a string t if you can:

    \n\n
      \n\t
    • Insert exactly one character into s to get t.
    • \n\t
    • Delete exactly one character from s to get t.
    • \n\t
    • Replace exactly one character of s with a different character to get t.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "ab", t = "acb"\nOutput: true\nExplanation: We can insert 'c' into s to get t.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "", t = ""\nOutput: false\nExplanation: We cannot get t from s by only one step.\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "a", t = ""\nOutput: true\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "", t = "A"\nOutput: true\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= s.length <= 104
    • \n\t
    • 0 <= t.length <= 104
    • \n\t
    • s and t consist of lower-case letters, upper-case letters and/or digits.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u5b57\u7b26\u4e32 s \u548c t\uff0c\u5224\u65ad\u4ed6\u4eec\u7684\u7f16\u8f91\u8ddd\u79bb\u662f\u5426\u4e3a 1\u3002

    \n\n

    \u6ce8\u610f\uff1a

    \n\n

    \u6ee1\u8db3\u7f16\u8f91\u8ddd\u79bb\u7b49\u4e8e 1 \u6709\u4e09\u79cd\u53ef\u80fd\u7684\u60c5\u5f62\uff1a

    \n\n
      \n\t
    1. \u5f80 s \u4e2d\u63d2\u5165\u4e00\u4e2a\u5b57\u7b26\u5f97\u5230 t
    2. \n\t
    3. \u4ece s \u4e2d\u5220\u9664\u4e00\u4e2a\u5b57\u7b26\u5f97\u5230 t
    4. \n\t
    5. \u5728 s \u4e2d\u66ff\u6362\u4e00\u4e2a\u5b57\u7b26\u5f97\u5230 t
    6. \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165: s = "ab", t = "acb"\n\u8f93\u51fa: true\n\u89e3\u91ca: \u53ef\u4ee5\u5c06 'c' \u63d2\u5165\u5b57\u7b26\u4e32 s \u6765\u5f97\u5230 t\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: s = "cab", t = "ad"\n\u8f93\u51fa: false\n\u89e3\u91ca: \u65e0\u6cd5\u901a\u8fc7 1 \u6b65\u64cd\u4f5c\u4f7f s \u53d8\u4e3a t\u3002
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u8f93\u5165: s = "1203", t = "1213"\n\u8f93\u51fa: true\n\u89e3\u91ca: \u53ef\u4ee5\u5c06\u5b57\u7b26\u4e32 s \u4e2d\u7684 '0' \u66ff\u6362\u4e3a '1' \u6765\u5f97\u5230 t\u3002
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isOneEditDistance(string s, string t) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isOneEditDistance(String s, String t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isOneEditDistance(self, s, t):\n \"\"\"\n :type s: str\n :type t: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isOneEditDistance(self, s: str, t: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isOneEditDistance(char * s, char * t){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsOneEditDistance(string s, string t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string} t\n * @return {boolean}\n */\nvar isOneEditDistance = function(s, t) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String} t\n# @return {Boolean}\ndef is_one_edit_distance(s, t)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isOneEditDistance(_ s: String, _ t: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isOneEditDistance(s string, t string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isOneEditDistance(s: String, t: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isOneEditDistance(s: String, t: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_one_edit_distance(s: String, t: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String $t\n * @return Boolean\n */\n function isOneEditDistance($s, $t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isOneEditDistance(s: string, t: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-one-edit-distance s t)\n (-> string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0161](https://leetcode-cn.com/problems/one-edit-distance)", "[\u76f8\u9694\u4e3a 1 \u7684\u7f16\u8f91\u8ddd\u79bb](/solution/0100-0199/0161.One%20Edit%20Distance/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0161](https://leetcode.com/problems/one-edit-distance)", "[One Edit Distance](/solution/0100-0199/0161.One%20Edit%20Distance/README_EN.md)", "`String`", "Medium", "\ud83d\udd12"]}, {"question_id": "0160", "frontend_question_id": "0160", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/intersection-of-two-linked-lists", "url_en": "https://leetcode.com/problems/intersection-of-two-linked-lists", "relative_path_cn": "/solution/0100-0199/0160.Intersection%20of%20Two%20Linked%20Lists/README.md", "relative_path_en": "/solution/0100-0199/0160.Intersection%20of%20Two%20Linked%20Lists/README_EN.md", "title_cn": "\u76f8\u4ea4\u94fe\u8868", "title_en": "Intersection of Two Linked Lists", "question_title_slug": "intersection-of-two-linked-lists", "content_en": "

    Given the heads of two singly linked-lists headA and headB, return the node at which the two lists intersect. If the two linked lists have no intersection at all, return null.

    \n\n

    For example, the following two linked lists begin to intersect at node c1:

    \n\"\"\n

    It is guaranteed that there are no cycles anywhere in the entire linked structure.

    \n\n

    Note that the linked lists must retain their original structure after the function returns.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: intersectVal = 8, listA = [4,1,8,4,5], listB = [5,6,1,8,4,5], skipA = 2, skipB = 3\nOutput: Intersected at '8'\nExplanation: The intersected node's value is 8 (note that this must not be 0 if the two lists intersect).\nFrom the head of A, it reads as [4,1,8,4,5]. From the head of B, it reads as [5,6,1,8,4,5]. There are 2 nodes before the intersected node in A; There are 3 nodes before the intersected node in B.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: intersectVal = 2, listA = [1,9,1,2,4], listB = [3,2,4], skipA = 3, skipB = 1\nOutput: Intersected at '2'\nExplanation: The intersected node's value is 2 (note that this must not be 0 if the two lists intersect).\nFrom the head of A, it reads as [1,9,1,2,4]. From the head of B, it reads as [3,2,4]. There are 3 nodes before the intersected node in A; There are 1 node before the intersected node in B.\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: intersectVal = 0, listA = [2,6,4], listB = [1,5], skipA = 3, skipB = 2\nOutput: No intersection\nExplanation: From the head of A, it reads as [2,6,4]. From the head of B, it reads as [1,5]. Since the two lists do not intersect, intersectVal must be 0, while skipA and skipB can be arbitrary values.\nExplanation: The two lists do not intersect, so return null.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes of listA is in the m.
    • \n\t
    • The number of nodes of listB is in the n.
    • \n\t
    • 0 <= m, n <= 3 * 104
    • \n\t
    • 1 <= Node.val <= 105
    • \n\t
    • 0 <= skipA <= m
    • \n\t
    • 0 <= skipB <= n
    • \n\t
    • intersectVal is 0 if listA and listB do not intersect.
    • \n\t
    • intersectVal == listA[skipA + 1] == listB[skipB + 1] if listA and listB intersect.
    • \n
    \n\n

     

    \nFollow up: Could you write a solution that runs in O(n) time and use only O(1) memory?", "content_cn": "

    \u7f16\u5199\u4e00\u4e2a\u7a0b\u5e8f\uff0c\u627e\u5230\u4e24\u4e2a\u5355\u94fe\u8868\u76f8\u4ea4\u7684\u8d77\u59cb\u8282\u70b9\u3002

    \n\n

    \u5982\u4e0b\u9762\u7684\u4e24\u4e2a\u94fe\u8868\uff1a

    \n\n

    \"\"

    \n\n

    \u5728\u8282\u70b9 c1 \u5f00\u59cb\u76f8\u4ea4\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1aintersectVal = 8, listA = [4,1,8,4,5], listB = [5,0,1,8,4,5], skipA = 2, skipB = 3\n\u8f93\u51fa\uff1aReference of the node with value = 8\n\u8f93\u5165\u89e3\u91ca\uff1a\u76f8\u4ea4\u8282\u70b9\u7684\u503c\u4e3a 8 \uff08\u6ce8\u610f\uff0c\u5982\u679c\u4e24\u4e2a\u94fe\u8868\u76f8\u4ea4\u5219\u4e0d\u80fd\u4e3a 0\uff09\u3002\u4ece\u5404\u81ea\u7684\u8868\u5934\u5f00\u59cb\u7b97\u8d77\uff0c\u94fe\u8868 A \u4e3a [4,1,8,4,5]\uff0c\u94fe\u8868 B \u4e3a [5,0,1,8,4,5]\u3002\u5728 A \u4e2d\uff0c\u76f8\u4ea4\u8282\u70b9\u524d\u6709 2 \u4e2a\u8282\u70b9\uff1b\u5728 B \u4e2d\uff0c\u76f8\u4ea4\u8282\u70b9\u524d\u6709 3 \u4e2a\u8282\u70b9\u3002\n
    \n\n

     

    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1aintersectVal = 2, listA = [0,9,1,2,4], listB = [3,2,4], skipA = 3, skipB = 1\n\u8f93\u51fa\uff1aReference of the node with value = 2\n\u8f93\u5165\u89e3\u91ca\uff1a\u76f8\u4ea4\u8282\u70b9\u7684\u503c\u4e3a 2 \uff08\u6ce8\u610f\uff0c\u5982\u679c\u4e24\u4e2a\u94fe\u8868\u76f8\u4ea4\u5219\u4e0d\u80fd\u4e3a 0\uff09\u3002\u4ece\u5404\u81ea\u7684\u8868\u5934\u5f00\u59cb\u7b97\u8d77\uff0c\u94fe\u8868 A \u4e3a [0,9,1,2,4]\uff0c\u94fe\u8868 B \u4e3a [3,2,4]\u3002\u5728 A \u4e2d\uff0c\u76f8\u4ea4\u8282\u70b9\u524d\u6709 3 \u4e2a\u8282\u70b9\uff1b\u5728 B \u4e2d\uff0c\u76f8\u4ea4\u8282\u70b9\u524d\u6709 1 \u4e2a\u8282\u70b9\u3002\n
    \n\n

     

    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1aintersectVal = 0, listA = [2,6,4], listB = [1,5], skipA = 3, skipB = 2\n\u8f93\u51fa\uff1anull\n\u8f93\u5165\u89e3\u91ca\uff1a\u4ece\u5404\u81ea\u7684\u8868\u5934\u5f00\u59cb\u7b97\u8d77\uff0c\u94fe\u8868 A \u4e3a [2,6,4]\uff0c\u94fe\u8868 B \u4e3a [1,5]\u3002\u7531\u4e8e\u8fd9\u4e24\u4e2a\u94fe\u8868\u4e0d\u76f8\u4ea4\uff0c\u6240\u4ee5 intersectVal \u5fc5\u987b\u4e3a 0\uff0c\u800c skipA \u548c skipB \u53ef\u4ee5\u662f\u4efb\u610f\u503c\u3002\n\u89e3\u91ca\uff1a\u8fd9\u4e24\u4e2a\u94fe\u8868\u4e0d\u76f8\u4ea4\uff0c\u56e0\u6b64\u8fd4\u56de null\u3002\n
    \n\n

     

    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    • \u5982\u679c\u4e24\u4e2a\u94fe\u8868\u6ca1\u6709\u4ea4\u70b9\uff0c\u8fd4\u56de null.
    • \n\t
    • \u5728\u8fd4\u56de\u7ed3\u679c\u540e\uff0c\u4e24\u4e2a\u94fe\u8868\u4ecd\u987b\u4fdd\u6301\u539f\u6709\u7684\u7ed3\u6784\u3002
    • \n\t
    • \u53ef\u5047\u5b9a\u6574\u4e2a\u94fe\u8868\u7ed3\u6784\u4e2d\u6ca1\u6709\u5faa\u73af\u3002
    • \n\t
    • \u7a0b\u5e8f\u5c3d\u91cf\u6ee1\u8db3 O(n) \u65f6\u95f4\u590d\u6742\u5ea6\uff0c\u4e14\u4ec5\u7528 O(1) \u5185\u5b58\u3002
    • \n
    \n", "tags_en": ["Linked List"], "tags_cn": ["\u94fe\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\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 ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode(int x) {\n * val = x;\n * next = null;\n * }\n * }\n */\npublic class Solution {\n public ListNode getIntersectionNode(ListNode headA, ListNode headB) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.next = None\n\nclass Solution(object):\n def getIntersectionNode(self, headA, headB):\n \"\"\"\n :type head1, head1: ListNode\n :rtype: ListNode\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, x):\n# self.val = x\n# self.next = None\n\nclass Solution:\n def getIntersectionNode(self, headA: ListNode, headB: ListNode) -> ListNode:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\nstruct ListNode *getIntersectionNode(struct ListNode *headA, struct ListNode *headB) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int x) { val = x; }\n * }\n */\npublic class Solution {\n public ListNode GetIntersectionNode(ListNode headA, ListNode headB) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val) {\n * this.val = val;\n * this.next = null;\n * }\n */\n\n/**\n * @param {ListNode} headA\n * @param {ListNode} headB\n * @return {ListNode}\n */\nvar getIntersectionNode = function(headA, headB) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val)\n# @val = val\n# @next = nil\n# end\n# end\n\n# @param {ListNode} headA\n# @param {ListNode} headB\n# @return {ListNode}\ndef getIntersectionNode(headA, headB)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.next = nil\n * }\n * }\n */\n\nclass Solution {\n func getIntersectionNode(_ headA: ListNode?, _ headB: ListNode?) -> ListNode? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc getIntersectionNode(headA, headB *ListNode) *ListNode {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(var _x: Int = 0) {\n * var next: ListNode = null\n * var x: Int = _x\n * }\n */\n\nobject Solution {\n def getIntersectionNode(headA: ListNode, headB: ListNode): ListNode = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\n\nclass Solution {\n fun getIntersectionNode(headA:ListNode?, headB:ListNode?):ListNode? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val) { $this->val = $val; }\n * }\n */\n\nclass Solution {\n /**\n * @param ListNode $headA\n * @param ListNode $headB\n * @return ListNode\n */\n function getIntersectionNode($headA, $headB) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction getIntersectionNode(headA: ListNode | null, headB: ListNode | null): ListNode | null {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0160](https://leetcode-cn.com/problems/intersection-of-two-linked-lists)", "[\u76f8\u4ea4\u94fe\u8868](/solution/0100-0199/0160.Intersection%20of%20Two%20Linked%20Lists/README.md)", "`\u94fe\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0160](https://leetcode.com/problems/intersection-of-two-linked-lists)", "[Intersection of Two Linked Lists](/solution/0100-0199/0160.Intersection%20of%20Two%20Linked%20Lists/README_EN.md)", "`Linked List`", "Easy", ""]}, {"question_id": "0159", "frontend_question_id": "0159", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/longest-substring-with-at-most-two-distinct-characters", "url_en": "https://leetcode.com/problems/longest-substring-with-at-most-two-distinct-characters", "relative_path_cn": "/solution/0100-0199/0159.Longest%20Substring%20with%20At%20Most%20Two%20Distinct%20Characters/README.md", "relative_path_en": "/solution/0100-0199/0159.Longest%20Substring%20with%20At%20Most%20Two%20Distinct%20Characters/README_EN.md", "title_cn": "\u81f3\u591a\u5305\u542b\u4e24\u4e2a\u4e0d\u540c\u5b57\u7b26\u7684\u6700\u957f\u5b50\u4e32", "title_en": "Longest Substring with At Most Two Distinct Characters", "question_title_slug": "longest-substring-with-at-most-two-distinct-characters", "content_en": "

    Given a string s, return the length of the longest substring that contains at most two distinct characters.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "eceba"\nOutput: 3\nExplanation: The substring is "ece" which its length is 3.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "ccaabbb"\nOutput: 5\nExplanation: The substring is "aabbb" which its length is 5.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 104
    • \n\t
    • s consists of English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32 s \uff0c\u627e\u51fa \u81f3\u591a \u5305\u542b\u4e24\u4e2a\u4e0d\u540c\u5b57\u7b26\u7684\u6700\u957f\u5b50\u4e32 t \uff0c\u5e76\u8fd4\u56de\u8be5\u5b50\u4e32\u7684\u957f\u5ea6\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: "eceba"\n\u8f93\u51fa: 3\n\u89e3\u91ca: t \u662f "ece"\uff0c\u957f\u5ea6\u4e3a3\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: "ccaabbb"\n\u8f93\u51fa: 5\n\u89e3\u91ca: t \u662f "aabbb"\uff0c\u957f\u5ea6\u4e3a5\u3002\n
    \n", "tags_en": ["Hash Table", "Two Pointers", "String", "Sliding Window"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u53cc\u6307\u9488", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int lengthOfLongestSubstringTwoDistinct(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int lengthOfLongestSubstringTwoDistinct(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def lengthOfLongestSubstringTwoDistinct(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def lengthOfLongestSubstringTwoDistinct(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint lengthOfLongestSubstringTwoDistinct(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LengthOfLongestSubstringTwoDistinct(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar lengthOfLongestSubstringTwoDistinct = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef length_of_longest_substring_two_distinct(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func lengthOfLongestSubstringTwoDistinct(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func lengthOfLongestSubstringTwoDistinct(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def lengthOfLongestSubstringTwoDistinct(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun lengthOfLongestSubstringTwoDistinct(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn length_of_longest_substring_two_distinct(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function lengthOfLongestSubstringTwoDistinct($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function lengthOfLongestSubstringTwoDistinct(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (length-of-longest-substring-two-distinct s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0159](https://leetcode-cn.com/problems/longest-substring-with-at-most-two-distinct-characters)", "[\u81f3\u591a\u5305\u542b\u4e24\u4e2a\u4e0d\u540c\u5b57\u7b26\u7684\u6700\u957f\u5b50\u4e32](/solution/0100-0199/0159.Longest%20Substring%20with%20At%20Most%20Two%20Distinct%20Characters/README.md)", "`\u54c8\u5e0c\u8868`,`\u53cc\u6307\u9488`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0159](https://leetcode.com/problems/longest-substring-with-at-most-two-distinct-characters)", "[Longest Substring with At Most Two Distinct Characters](/solution/0100-0199/0159.Longest%20Substring%20with%20At%20Most%20Two%20Distinct%20Characters/README_EN.md)", "`Hash Table`,`Two Pointers`,`String`,`Sliding Window`", "Medium", "\ud83d\udd12"]}, {"question_id": "0158", "frontend_question_id": "0158", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/read-n-characters-given-read4-ii-call-multiple-times", "url_en": "https://leetcode.com/problems/read-n-characters-given-read4-ii-call-multiple-times", "relative_path_cn": "/solution/0100-0199/0158.Read%20N%20Characters%20Given%20Read4%20II%20-%20Call%20multiple%20times/README.md", "relative_path_en": "/solution/0100-0199/0158.Read%20N%20Characters%20Given%20Read4%20II%20-%20Call%20multiple%20times/README_EN.md", "title_cn": "\u7528 Read4 \u8bfb\u53d6 N \u4e2a\u5b57\u7b26 II", "title_en": "Read N Characters Given Read4 II - Call multiple times", "question_title_slug": "read-n-characters-given-read4-ii-call-multiple-times", "content_en": "

    Given a file and assume that you can only read the file using a given method read4, implement a method read to read n characters. Your method read may be called multiple times.

    \n\n

    Method read4:

    \n\n

    The API read4 reads four consecutive characters from file, then writes those characters into the buffer array buf4.

    \n\n

    The return value is the number of actual characters read.

    \n\n

    Note that read4() has its own file pointer, much like FILE *fp in C.

    \n\n

    Definition of read4:

    \n\n
    \n    Parameter:  char[] buf4\n    Returns:    int\n\nbuf4[] is a destination, not a source. The results from read4 will be copied to buf4[].\n
    \n\n

    Below is a high-level example of how read4 works:

    \n\"\"\n
    \nFile file("abcde"); // File is "abcde", initially file pointer (fp) points to 'a'\nchar[] buf4 = new char[4]; // Create buffer with enough space to store characters\nread4(buf4); // read4 returns 4. Now buf4 = "abcd", fp points to 'e'\nread4(buf4); // read4 returns 1. Now buf4 = "e", fp points to end of file\nread4(buf4); // read4 returns 0. Now buf4 = "", fp points to end of file\n
    \n\n

     

    \n\n

    Method read:

    \n\n

    By using the read4 method, implement the method read that reads n characters from file and store it in the buffer array buf. Consider that you cannot manipulate file directly.

    \n\n

    The return value is the number of actual characters read.

    \n\n

    Definition of read:

    \n\n
    \n    Parameters:\tchar[] buf, int n\n    Returns:\tint\n\nbuf[] is a destination, not a source. You will need to write the results to buf[].\n
    \n\n

    Note:

    \n\n
      \n\t
    • Consider that you cannot manipulate the file directly. The file is only accessible for read4 but not for read.
    • \n\t
    • The read function may be called multiple times.
    • \n\t
    • Please remember to RESET your class variables declared in Solution, as static/class variables are persisted across multiple test cases. Please see here for more details.
    • \n\t
    • You may assume the destination buffer array, buf, is guaranteed to have enough space for storing n characters.
    • \n\t
    • It is guaranteed that in a given test case the same buffer buf is called by read.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: file = "abc", queries = [1,2,1]\nOutput: [1,2,0]\nExplanation: The test case represents the following scenario:\nFile file("abc");\nSolution sol;\nsol.read(buf, 1); // After calling your read method, buf should contain "a". We read a total of 1 character from the file, so return 1.\nsol.read(buf, 2); // Now buf should contain "bc". We read a total of 2 characters from the file, so return 2.\nsol.read(buf, 1); // We have reached the end of file, no more characters can be read. So return 0.\nAssume buf is allocated and guaranteed to have enough space for storing all characters from the file.\n
    \n\n

    Example 2:

    \n\n
    \nInput: file = "abc", queries = [4,1]\nOutput: [3,0]\nExplanation: The test case represents the following scenario:\nFile file("abc");\nSolution sol;\nsol.read(buf, 4); // After calling your read method, buf should contain "abc". We read a total of 3 characters from the file, so return 3.\nsol.read(buf, 1); // We have reached the end of file, no more characters can be read. So return 0.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= file.length <= 500
    • \n\t
    • file consist of English letters and digits.
    • \n\t
    • 1 <= queries.length <= 10
    • \n\t
    • 1 <= queries[i] <= 500
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6587\u4ef6\uff0c\u5e76\u4e14\u8be5\u6587\u4ef6\u53ea\u80fd\u901a\u8fc7\u7ed9\u5b9a\u7684\u00a0read4\u00a0\u65b9\u6cd5\u6765\u8bfb\u53d6\uff0c\u8bf7\u5b9e\u73b0\u4e00\u4e2a\u65b9\u6cd5\u4f7f\u5176\u80fd\u591f\u8bfb\u53d6 n \u4e2a\u5b57\u7b26\u3002\u6ce8\u610f\uff1a\u4f60\u7684\u00a0read \u65b9\u6cd5\u53ef\u80fd\u4f1a\u88ab\u8c03\u7528\u591a\u6b21\u3002

    \n\n

    read4 \u7684\u5b9a\u4e49\uff1a

    \n\n

    read4 API \u4ece\u6587\u4ef6\u4e2d\u8bfb\u53d6 4 \u4e2a\u8fde\u7eed\u7684\u5b57\u7b26\uff0c\u7136\u540e\u5c06\u8fd9\u4e9b\u5b57\u7b26\u5199\u5165\u7f13\u51b2\u533a\u6570\u7ec4 buf4 \u3002

    \n\n

    \u8fd4\u56de\u503c\u662f\u8bfb\u53d6\u7684\u5b9e\u9645\u5b57\u7b26\u6570\u3002

    \n\n

    \u8bf7\u6ce8\u610f\uff0cread4() \u6709\u5176\u81ea\u5df1\u7684\u6587\u4ef6\u6307\u9488\uff0c\u7c7b\u4f3c\u4e8e C \u4e2d\u7684 FILE * fp \u3002

    \n\n
    \n\u53c2\u6570\u7c7b\u578b: char[] buf4\n\u8fd4\u56de\u7c7b\u578b: int\n\n\u6ce8\u610f: buf4[] \u662f\u76ee\u6807\u7f13\u5b58\u533a\u4e0d\u662f\u6e90\u7f13\u5b58\u533a\uff0cread4 \u7684\u8fd4\u56de\u7ed3\u679c\u5c06\u4f1a\u590d\u5236\u5230 buf4[] \u5f53\u4e2d\u3002\n
    \n\n

    \u4e0b\u5217\u662f\u4e00\u4e9b\u4f7f\u7528 read4 \u7684\u4f8b\u5b50\uff1a

    \n\n

    \"\"

    \n\n
    \nFile file(\"abcde\"); // \u6587\u4ef6\u540d\u4e3a \"abcde\"\uff0c \u521d\u59cb\u6587\u4ef6\u6307\u9488 (fp) \u6307\u5411 'a' \nchar[] buf4 = new char[4]; // \u521b\u5efa\u4e00\u4e2a\u7f13\u5b58\u533a\u4f7f\u5176\u80fd\u5bb9\u7eb3\u8db3\u591f\u7684\u5b57\u7b26\nread4(buf4); // read4 \u8fd4\u56de 4\u3002\u73b0\u5728 buf4 = \"abcd\"\uff0cfp \u6307\u5411 'e'\nread4(buf4); // read4 \u8fd4\u56de 1\u3002\u73b0\u5728 buf4 = \"e\"\uff0cfp \u6307\u5411\u6587\u4ef6\u672b\u5c3e\nread4(buf4); // read4 \u8fd4\u56de 0\u3002\u73b0\u5728 buf4 = \"\"\uff0cfp \u6307\u5411\u6587\u4ef6\u672b\u5c3e
    \n\n

    read \u65b9\u6cd5\uff1a

    \n\n

    \u901a\u8fc7\u4f7f\u7528 read4 \u65b9\u6cd5\uff0c\u5b9e\u73b0\u00a0read \u65b9\u6cd5\u3002\u8be5\u65b9\u6cd5\u53ef\u4ee5\u4ece\u6587\u4ef6\u4e2d\u8bfb\u53d6 n \u4e2a\u5b57\u7b26\u5e76\u5c06\u5176\u5b58\u50a8\u5230\u7f13\u5b58\u6570\u7ec4\u00a0buf \u4e2d\u3002\u60a8\u00a0\u4e0d\u80fd\u00a0\u76f4\u63a5\u64cd\u4f5c\u6587\u4ef6\u3002

    \n\n

    \u8fd4\u56de\u503c\u4e3a\u5b9e\u9645\u8bfb\u53d6\u7684\u5b57\u7b26\u3002

    \n\n

    read\u00a0\u7684\u5b9a\u4e49\uff1a

    \n\n
    \n\u53c2\u6570:   char[] buf, int n\n\u8fd4\u56de\u503c: int\n\n\u6ce8\u610f: buf[] \u662f\u76ee\u6807\u7f13\u5b58\u533a\u4e0d\u662f\u6e90\u7f13\u5b58\u533a\uff0c\u4f60\u9700\u8981\u5c06\u7ed3\u679c\u5199\u5165 buf[] \u4e2d\u3002\n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \nFile file(\"abc\");\nSolution sol;\n// \u5047\u5b9a buf \u5df2\u7ecf\u88ab\u5206\u914d\u4e86\u5185\u5b58\uff0c\u5e76\u4e14\u6709\u8db3\u591f\u7684\u7a7a\u95f4\u6765\u5b58\u50a8\u6587\u4ef6\u4e2d\u7684\u6240\u6709\u5b57\u7b26\u3002\nsol.read(buf, 1); // \u5f53\u8c03\u7528\u4e86\u60a8\u7684 read \u65b9\u6cd5\u540e\uff0cbuf \u9700\u8981\u5305\u542b \"a\"\u3002 \u4e00\u5171\u8bfb\u53d6 1 \u4e2a\u5b57\u7b26\uff0c\u56e0\u6b64\u8fd4\u56de 1\u3002\nsol.read(buf, 2); // \u73b0\u5728 buf \u9700\u8981\u5305\u542b \"bc\"\u3002\u4e00\u5171\u8bfb\u53d6 2 \u4e2a\u5b57\u7b26\uff0c\u56e0\u6b64\u8fd4\u56de 2\u3002\nsol.read(buf, 1); // \u7531\u4e8e\u5df2\u7ecf\u5230\u8fbe\u4e86\u6587\u4ef6\u672b\u5c3e\uff0c\u6ca1\u6709\u66f4\u591a\u7684\u5b57\u7b26\u53ef\u4ee5\u8bfb\u53d6\uff0c\u56e0\u6b64\u8fd4\u56de 0\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \nFile file(\"abc\");\nSolution sol;\nsol.read(buf, 4); // \u5f53\u8c03\u7528\u4e86\u60a8\u7684 read \u65b9\u6cd5\u540e\uff0cbuf \u9700\u8981\u5305\u542b \"abc\"\u3002 \u4e00\u5171\u53ea\u80fd\u8bfb\u53d6 3 \u4e2a\u5b57\u7b26\uff0c\u56e0\u6b64\u8fd4\u56de 3\u3002\nsol.read(buf, 1); // \u7531\u4e8e\u5df2\u7ecf\u5230\u8fbe\u4e86\u6587\u4ef6\u672b\u5c3e\uff0c\u6ca1\u6709\u66f4\u591a\u7684\u5b57\u7b26\u53ef\u4ee5\u8bfb\u53d6\uff0c\u56e0\u6b64\u8fd4\u56de 0\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u4f60 \u4e0d\u80fd \u76f4\u63a5\u64cd\u4f5c\u8be5\u6587\u4ef6\uff0c\u6587\u4ef6\u53ea\u80fd\u901a\u8fc7 read4 \u83b7\u53d6\u800c \u4e0d\u80fd \u901a\u8fc7 read\u3002
    • \n\t
    • read\u00a0 \u51fd\u6570\u53ef\u4ee5\u88ab\u8c03\u7528\u00a0\u591a\u6b21\u3002
    • \n\t
    • \u8bf7\u8bb0\u5f97\u00a0\u91cd\u7f6e\u00a0\u5728 Solution \u4e2d\u58f0\u660e\u7684\u7c7b\u53d8\u91cf\uff08\u9759\u6001\u53d8\u91cf\uff09\uff0c\u56e0\u4e3a\u7c7b\u53d8\u91cf\u4f1a\u00a0\u5728\u591a\u4e2a\u6d4b\u8bd5\u7528\u4f8b\u4e2d\u4fdd\u6301\u4e0d\u53d8\uff0c\u5f71\u54cd\u5224\u9898\u51c6\u786e\u3002\u8bf7 \u67e5\u9605 \u8fd9\u91cc\u3002
    • \n\t
    • \u4f60\u53ef\u4ee5\u5047\u5b9a\u76ee\u6807\u7f13\u5b58\u6570\u7ec4\u00a0buf \u4fdd\u8bc1\u6709\u8db3\u591f\u7684\u7a7a\u95f4\u5b58\u4e0b n \u4e2a\u5b57\u7b26\u3002\u00a0
    • \n\t
    • \u4fdd\u8bc1\u5728\u4e00\u4e2a\u7ed9\u5b9a\u6d4b\u8bd5\u7528\u4f8b\u4e2d\uff0cread \u51fd\u6570\u4f7f\u7528\u7684\u662f\u540c\u4e00\u4e2a buf\u3002
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * The read4 API is defined in the parent class Reader4.\n * int read4(char *buf4);\n */\n\nclass Solution {\npublic:\n /**\n * @param buf Destination buffer\n * @param n Number of characters to read\n * @return The number of actual characters read\n */\n int read(char *buf, int n) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * The read4 API is defined in the parent class Reader4.\n * int read4(char[] buf4); \n */\n\npublic class Solution extends Reader4 {\n /**\n * @param buf Destination buffer\n * @param n Number of characters to read\n * @return The number of actual characters read\n */\n public int read(char[] buf, int n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# The read4 API is already defined for you.\n# @param buf4, List[str]\n# @return an integer\n# def read4(buf4):\n\nclass Solution(object):\n def read(self, buf, n):\n \"\"\"\n :type buf: List[str]\n :type n: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# The read4 API is already defined for you.\n# def read4(buf4: List[str]) -> int:\n\nclass Solution:\n def read(self, buf: List[str], n: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * The read4 API is defined in the parent class Reader4.\n * int read4(char *buf4);\n */\n\ntypedef struct {\n \n} Solution;\n\n/** initialize your data structure here. */\nSolution* solutionCreate() {\n\n}\n\n/**\n * @param buf Destination buffer\n * @param n Number of characters to read\n * @return The number of actual characters read\n */\nint _read(Solution* obj, char* buf, int n) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * The Read4 API is defined in the parent class Reader4.\n * int Read4(char[] buf4);\n */\n\npublic class Solution : Reader4 {\n /**\n * @param buf Destination buffer\n * @param n Number of characters to read\n * @return The number of actual characters read\n */\n public int Read(char[] buf, int n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for read4()\n * \n * @param {character[]} buf Destination buffer\n * @return {number} The number of characters read\n * read4 = function(buf4) {\n * ...\n * };\n */\n\n/**\n * @param {function} read4()\n * @return {function}\n */\nvar solution = function(read4) {\n /**\n * @param {character[]} buf Destination buffer\n * @param {number} n Number of characters to read\n * @return {number} The number of actual characters read\n */\n return function(buf, n) {\n \n };\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# The read4 API is already defined for you.\n# Below is an example of how the read4 API can be called.\n# file = File.new(\"abcdefghijk\") File is \"abcdefghijk\", initially file pointer (fp) points to 'a'\n# buf4 = [' '] * 4 Create buffer with enough space to store characters\n# read4(buf4) # read4 returns 4. Now buf = ['a','b','c','d'], fp points to 'e'\n# read4(buf4) # read4 returns 4. Now buf = ['e','f','g','h'], fp points to 'i'\n# read4(buf4) # read4 returns 3. Now buf = ['i','j','k',...], fp points to end of file\n\nclass Solution\n # @param {List[str]} buf\n\t# @param {int} n\n\t# @return {int}\n def read(buf, n)\n \n end\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * The read4 API is defined in the parent class Reader4.\n * func read4(_ buf4: inout [Character]) -> Int;\n */\n\nclass Solution : Reader4 {\n\t/**\n * @param buf Destination buffer\n * @param n Number of characters to read\n * @return The number of actual characters read\n */\n func read(_ buf: inout [Character], _ n: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * The read4 API is already defined for you.\n *\n * read4 := func(buf4 []byte) int\n *\n * // Below is an example of how the read4 API can be called.\n * file := File(\"abcdefghijk\") // File is \"abcdefghijk\", initially file pointer (fp) points to 'a'\n * buf4 := make([]byte, 4) // Create buffer with enough space to store characters\n * read4(buf4) // read4 returns 4. Now buf = ['a','b','c','d'], fp points to 'e'\n * read4(buf4) // read4 returns 4. Now buf = ['e','f','g','h'], fp points to 'i'\n * read4(buf4) // read4 returns 3. Now buf = ['i','j','k',...], fp points to end of file\n */\n\nvar solution = func(read4 func([]byte) int) func([]byte, int) int {\n // implement read below.\n return func(buf []byte, n int) int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * The read4 API is defined in the parent class Reader4.\n * def read4(buf4: Array[Char]): Int = {}\n */\n\nclass Solution extends Reader4 {\n /**\n * @param buf Destination buffer\n \t * @param n Number of characters to read\n * @return The number of actual characters read\n */\n def read(buf: Array[Char], n: Int): Int = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n* The read4 API is defined in the parent class Reader4.\n* fun read4(buf4:CharArray): Int {}\n*/\n\nclass Solution:Reader4() {\n /**\n * @param buf Destination buffer\n * @param n Number of characters to read\n * @return The number of actual characters read\n */\n override fun read(buf:CharArray, n:Int): Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/* The read4 API is defined in the parent class Reader4.\n public function read4(&$buf4){} */\n\nclass Solution extends Reader4 {\n /**\n * @param Char[] &$buf\tDestination buffer\n * @param Integer $n\t\tNumber of characters to read\n * @return Integer \t\t\tThe number of actual characters read\n */\n function read(&$buf, $n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for read4()\n * read4 = function(buf4: string[]): number {\n * ...\n * };\n */\n\nvar solution = function(read4: any) {\n\n return function(buf: string[], n: number): number {\n \n };\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0158](https://leetcode-cn.com/problems/read-n-characters-given-read4-ii-call-multiple-times)", "[\u7528 Read4 \u8bfb\u53d6 N \u4e2a\u5b57\u7b26 II](/solution/0100-0199/0158.Read%20N%20Characters%20Given%20Read4%20II%20-%20Call%20multiple%20times/README.md)", "`\u5b57\u7b26\u4e32`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0158](https://leetcode.com/problems/read-n-characters-given-read4-ii-call-multiple-times)", "[Read N Characters Given Read4 II - Call multiple times](/solution/0100-0199/0158.Read%20N%20Characters%20Given%20Read4%20II%20-%20Call%20multiple%20times/README_EN.md)", "`String`", "Hard", "\ud83d\udd12"]}, {"question_id": "0157", "frontend_question_id": "0157", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/read-n-characters-given-read4", "url_en": "https://leetcode.com/problems/read-n-characters-given-read4", "relative_path_cn": "/solution/0100-0199/0157.Read%20N%20Characters%20Given%20Read4/README.md", "relative_path_en": "/solution/0100-0199/0157.Read%20N%20Characters%20Given%20Read4/README_EN.md", "title_cn": "\u7528 Read4 \u8bfb\u53d6 N \u4e2a\u5b57\u7b26", "title_en": "Read N Characters Given Read4", "question_title_slug": "read-n-characters-given-read4", "content_en": "

    Given a file and assume that you can only read the file using a given method read4, implement a method to read n characters.

    \n\n

    Method read4:

    \n\n

    The API read4 reads four consecutive characters from file, then writes those characters into the buffer array buf4.

    \n\n

    The return value is the number of actual characters read.

    \n\n

    Note that read4() has its own file pointer, much like FILE *fp in C.

    \n\n

    Definition of read4:

    \n\n
    \n    Parameter:  char[] buf4\n    Returns:    int\n\nbuf4[] is a destination, not a source. The results from read4 will be copied to buf4[].\n
    \n\n

    Below is a high-level example of how read4 works:

    \n\"\"\n
    \nFile file("abcde"); // File is "abcde", initially file pointer (fp) points to 'a'\nchar[] buf4 = new char[4]; // Create buffer with enough space to store characters\nread4(buf4); // read4 returns 4. Now buf4 = "abcd", fp points to 'e'\nread4(buf4); // read4 returns 1. Now buf4 = "e", fp points to end of file\nread4(buf4); // read4 returns 0. Now buf4 = "", fp points to end of file\n
    \n\n

     

    \n\n

    Method read:

    \n\n

    By using the read4 method, implement the method read that reads n characters from file and store it in the buffer array buf. Consider that you cannot manipulate file directly.

    \n\n

    The return value is the number of actual characters read.

    \n\n

    Definition of read:

    \n\n
    \n    Parameters:\tchar[] buf, int n\n    Returns:\tint\n\nbuf[] is a destination, not a source. You will need to write the results to buf[].\n
    \n\n

    Note:

    \n\n
      \n\t
    • Consider that you cannot manipulate the file directly. The file is only accessible for read4 but not for read.
    • \n\t
    • The read function will only be called once for each test case.
    • \n\t
    • You may assume the destination buffer array, buf, is guaranteed to have enough space for storing n characters.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: file = "abc", n = 4\nOutput: 3\nExplanation: After calling your read method, buf should contain "abc". We read a total of 3 characters from the file, so return 3.\nNote that "abc" is the file's content, not buf. buf is the destination buffer that you will have to write the results to.\n
    \n\n

    Example 2:

    \n\n
    \nInput: file = "abcde", n = 5\nOutput: 5\nExplanation: After calling your read method, buf should contain "abcde". We read a total of 5 characters from the file, so return 5.\n
    \n\n

    Example 3:

    \n\n
    \nInput: file = "abcdABCD1234", n = 12\nOutput: 12\nExplanation: After calling your read method, buf should contain "abcdABCD1234". We read a total of 12 characters from the file, so return 12.\n
    \n\n

    Example 4:

    \n\n
    \nInput: file = "leetcode", n = 5\nOutput: 5\nExplanation: After calling your read method, buf should contain "leetc". We read a total of 5 characters from the file, so return 5.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= file.length <= 500
    • \n\t
    • file consist of English letters and digits.
    • \n\t
    • 1 <= n <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6587\u4ef6\uff0c\u5e76\u4e14\u8be5\u6587\u4ef6\u53ea\u80fd\u901a\u8fc7\u7ed9\u5b9a\u7684 read4 \u65b9\u6cd5\u6765\u8bfb\u53d6\uff0c\u8bf7\u5b9e\u73b0\u4e00\u4e2a\u65b9\u6cd5\u4f7f\u5176\u80fd\u591f\u8bfb\u53d6 n \u4e2a\u5b57\u7b26\u3002

    \n\n

    read4 \u65b9\u6cd5\uff1a

    \n\n

    API read4 \u53ef\u4ee5\u4ece\u6587\u4ef6\u4e2d\u8bfb\u53d6 4 \u4e2a\u8fde\u7eed\u7684\u5b57\u7b26\uff0c\u5e76\u4e14\u5c06\u5b83\u4eec\u5199\u5165\u7f13\u5b58\u6570\u7ec4 buf \u4e2d\u3002

    \n\n

    \u8fd4\u56de\u503c\u4e3a\u5b9e\u9645\u8bfb\u53d6\u7684\u5b57\u7b26\u4e2a\u6570\u3002

    \n\n

    \u6ce8\u610f read4() \u81ea\u8eab\u62e5\u6709\u6587\u4ef6\u6307\u9488\uff0c\u5f88\u7c7b\u4f3c\u4e8e C \u8bed\u8a00\u4e2d\u7684 FILE *fp \u3002

    \n\n

    read4 \u7684\u5b9a\u4e49\uff1a

    \n\n
    \u53c2\u6570\u7c7b\u578b: char[] buf4\n\u8fd4\u56de\u7c7b\u578b: int\n\n\u6ce8\u610f: buf4[] \u662f\u76ee\u6807\u7f13\u5b58\u533a\u4e0d\u662f\u6e90\u7f13\u5b58\u533a\uff0cread4 \u7684\u8fd4\u56de\u7ed3\u679c\u5c06\u4f1a\u590d\u5236\u5230 buf4[] \u5f53\u4e2d\u3002\n
    \n\n

    \u4e0b\u5217\u662f\u4e00\u4e9b\u4f7f\u7528 read4 \u7684\u4f8b\u5b50\uff1a

    \n\n

    \n\n
    File file("abcde"); // \u6587\u4ef6\u540d\u4e3a "abcde"\uff0c \u521d\u59cb\u6587\u4ef6\u6307\u9488 (fp) \u6307\u5411 'a' \nchar[] buf4 = new char[4]; // \u521b\u5efa\u4e00\u4e2a\u7f13\u5b58\u533a\u4f7f\u5176\u80fd\u5bb9\u7eb3\u8db3\u591f\u7684\u5b57\u7b26\nread4(buf4); // read4 \u8fd4\u56de 4\u3002\u73b0\u5728 buf4 = "abcd"\uff0cfp \u6307\u5411 'e'\nread4(buf4); // read4 \u8fd4\u56de 1\u3002\u73b0\u5728 buf4 = "e"\uff0cfp \u6307\u5411\u6587\u4ef6\u672b\u5c3e\nread4(buf4); // read4 \u8fd4\u56de 0\u3002\u73b0\u5728 buf = ""\uff0cfp \u6307\u5411\u6587\u4ef6\u672b\u5c3e
    \n\n

    read \u65b9\u6cd5\uff1a

    \n\n

    \u901a\u8fc7\u4f7f\u7528 read4 \u65b9\u6cd5\uff0c\u5b9e\u73b0 read \u65b9\u6cd5\u3002\u8be5\u65b9\u6cd5\u53ef\u4ee5\u4ece\u6587\u4ef6\u4e2d\u8bfb\u53d6 n \u4e2a\u5b57\u7b26\u5e76\u5c06\u5176\u5b58\u50a8\u5230\u7f13\u5b58\u6570\u7ec4 buf \u4e2d\u3002\u60a8 \u4e0d\u80fd \u76f4\u63a5\u64cd\u4f5c\u6587\u4ef6\u3002

    \n\n

    \u8fd4\u56de\u503c\u4e3a\u5b9e\u9645\u8bfb\u53d6\u7684\u5b57\u7b26\u3002

    \n\n

    read \u7684\u5b9a\u4e49\uff1a

    \n\n
    \u53c2\u6570\u7c7b\u578b:   char[] buf, int n\n\u8fd4\u56de\u7c7b\u578b:   int\n\n\u6ce8\u610f: buf[] \u662f\u76ee\u6807\u7f13\u5b58\u533a\u4e0d\u662f\u6e90\u7f13\u5b58\u533a\uff0c\u4f60\u9700\u8981\u5c06\u7ed3\u679c\u5199\u5165 buf[] \u4e2d\u3002\n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a file = "abc", n = 4\n\u8f93\u51fa\uff1a 3\n\u89e3\u91ca\uff1a \u5f53\u6267\u884c\u4f60\u7684 read \u65b9\u6cd5\u540e\uff0cbuf \u9700\u8981\u5305\u542b "abc"\u3002 \u6587\u4ef6\u4e00\u5171 3 \u4e2a\u5b57\u7b26\uff0c\u56e0\u6b64\u8fd4\u56de 3\u3002 \u6ce8\u610f "abc" \u662f\u6587\u4ef6\u7684\u5185\u5bb9\uff0c\u4e0d\u662f buf \u7684\u5185\u5bb9\uff0cbuf \u662f\u4f60\u9700\u8981\u5199\u5165\u7ed3\u679c\u7684\u76ee\u6807\u7f13\u5b58\u533a\u3002 
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a file = "abcde", n = 5\n\u8f93\u51fa\uff1a 5\n\u89e3\u91ca\uff1a \u5f53\u6267\u884c\u4f60\u7684 read \u65b9\u6cd5\u540e\uff0cbuf \u9700\u8981\u5305\u542b "abcde"\u3002\u6587\u4ef6\u5171 5 \u4e2a\u5b57\u7b26\uff0c\u56e0\u6b64\u8fd4\u56de 5\u3002\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u8f93\u5165\uff1a file = "abcdABCD1234", n = 12\n\u8f93\u51fa\uff1a 12\n\u89e3\u91ca\uff1a \u5f53\u6267\u884c\u4f60\u7684 read \u65b9\u6cd5\u540e\uff0cbuf \u9700\u8981\u5305\u542b "abcdABCD1234"\u3002\u6587\u4ef6\u4e00\u5171 12 \u4e2a\u5b57\u7b26\uff0c\u56e0\u6b64\u8fd4\u56de 12\u3002\n
    \n\n

    \u793a\u4f8b 4:

    \n\n
    \u8f93\u5165\uff1a file = "leetcode", n = 5\n\u8f93\u51fa\uff1a 5\n\u89e3\u91ca\uff1a \u5f53\u6267\u884c\u4f60\u7684 read \u65b9\u6cd5\u540e\uff0cbuf \u9700\u8981\u5305\u542b "leetc"\u3002\u6587\u4ef6\u4e2d\u4e00\u5171 5 \u4e2a\u5b57\u7b26\uff0c\u56e0\u6b64\u8fd4\u56de 5\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u4f60 \u4e0d\u80fd \u76f4\u63a5\u64cd\u4f5c\u8be5\u6587\u4ef6\uff0c\u6587\u4ef6\u53ea\u80fd\u901a\u8fc7 read4 \u83b7\u53d6\u800c \u4e0d\u80fd \u901a\u8fc7 read\u3002
    • \n\t
    • read  \u51fd\u6570\u53ea\u5728\u6bcf\u4e2a\u6d4b\u8bd5\u7528\u4f8b\u8c03\u7528\u4e00\u6b21\u3002
    • \n\t
    • \u4f60\u53ef\u4ee5\u5047\u5b9a\u76ee\u6807\u7f13\u5b58\u6570\u7ec4 buf \u4fdd\u8bc1\u6709\u8db3\u591f\u7684\u7a7a\u95f4\u5b58\u4e0b n \u4e2a\u5b57\u7b26\u3002 
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * The read4 API is defined in the parent class Reader4.\n * int read4(char *buf4);\n */\n\nclass Solution {\npublic:\n /**\n * @param buf Destination buffer\n * @param n Number of characters to read\n * @return The number of actual characters read\n */\n int read(char *buf, int n) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * The read4 API is defined in the parent class Reader4.\n * int read4(char[] buf4);\n */\n\npublic class Solution extends Reader4 {\n /**\n * @param buf Destination buffer\n * @param n Number of characters to read\n * @return The number of actual characters read\n */\n public int read(char[] buf, int n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "\"\"\"\nThe read4 API is already defined for you.\n\n @param buf4, a list of characters\n @return an integer\n def read4(buf4):\n\n# Below is an example of how the read4 API can be called.\nfile = File(\"abcdefghijk\") # File is \"abcdefghijk\", initially file pointer (fp) points to 'a'\nbuf4 = [' '] * 4 # Create buffer with enough space to store characters\nread4(buf4) # read4 returns 4. Now buf = ['a','b','c','d'], fp points to 'e'\nread4(buf4) # read4 returns 4. Now buf = ['e','f','g','h'], fp points to 'i'\nread4(buf4) # read4 returns 3. Now buf = ['i','j','k',...], fp points to end of file\n\"\"\"\n\nclass Solution(object):\n def read(self, buf, n):\n \"\"\"\n :type buf: Destination buffer (List[str])\n :type n: Number of characters to read (int)\n :rtype: The number of actual characters read (int)\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "\"\"\"\nThe read4 API is already defined for you.\n\n @param buf4, a list of characters\n @return an integer\n def read4(buf4):\n\n# Below is an example of how the read4 API can be called.\nfile = File(\"abcdefghijk\") # File is \"abcdefghijk\", initially file pointer (fp) points to 'a'\nbuf4 = [' '] * 4 # Create buffer with enough space to store characters\nread4(buf4) # read4 returns 4. Now buf = ['a','b','c','d'], fp points to 'e'\nread4(buf4) # read4 returns 4. Now buf = ['e','f','g','h'], fp points to 'i'\nread4(buf4) # read4 returns 3. Now buf = ['i','j','k',...], fp points to end of file\n\"\"\"\n\nclass Solution:\n def read(self, buf, n):\n \"\"\"\n :type buf: Destination buffer (List[str])\n :type n: Number of characters to read (int)\n :rtype: The number of actual characters read (int)\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * The read4 API is defined in the parent class Reader4.\n * int read4(char *buf4);\n */\n\n/**\n * @param buf Destination buffer\n * @param n Number of characters to read\n * @return The number of actual characters read\n */\nint _read(char* buf, int n) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * The Read4 API is defined in the parent class Reader4.\n * int Read4(char[] buf4);\n */\n\npublic class Solution : Reader4 {\n /**\n * @param buf Destination buffer\n * @param n Number of characters to read\n * @return The number of actual characters read\n */\n public int Read(char[] buf, int n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for read4()\n * \n * @param {character[]} buf4 Destination buffer\n * @return {number} The number of actual characters read\n * read4 = function(buf4) {\n * ...\n * };\n */\n\n/**\n * @param {function} read4()\n * @return {function}\n */\nvar solution = function(read4) {\n /**\n * @param {character[]} buf Destination buffer\n * @param {number} n Number of characters to read\n * @return {number} The number of actual characters read\n */\n return function(buf, n) {\n \n };\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# The read4 API is already defined for you.\n# Below is an example of how the read4 API can be called.\n# file = File.new(\"abcdefghijk\") File is \"abcdefghijk\", initially file pointer (fp) points to 'a'\n# buf4 = [' '] * 4 Create buffer with enough space to store characters\n# read4(buf4) # read4 returns 4. Now buf = ['a','b','c','d'], fp points to 'e'\n# read4(buf4) # read4 returns 4. Now buf = ['e','f','g','h'], fp points to 'i'\n# read4(buf4) # read4 returns 3. Now buf = ['i','j','k',...], fp points to end of file\n\n# @param {List[str]} buf\n# @param {int} n\n# @return {int}\ndef read(buf, n)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * The read4 API is defined in the parent class Reader4.\n * func read4(_ buf4: inout [Character]) -> Int;\n */\n\nclass Solution : Reader4 {\n\t/**\n * @param buf Destination buffer\n * @param n Number of characters to read\n * @return The number of actual characters read\n */\n func read(_ buf: inout [Character], _ n: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * The read4 API is already defined for you.\n *\n * read4 := func(buf4 []byte) int\n *\n * // Below is an example of how the read4 API can be called.\n * file := File(\"abcdefghijk\") // File is \"abcdefghijk\", initially file pointer (fp) points to 'a'\n * buf4 := make([]byte, 4) // Create buffer with enough space to store characters\n * read4(buf4) // read4 returns 4. Now buf = ['a','b','c','d'], fp points to 'e'\n * read4(buf4) // read4 returns 4. Now buf = ['e','f','g','h'], fp points to 'i'\n * read4(buf4) // read4 returns 3. Now buf = ['i','j','k',...], fp points to end of file\n */\n\nvar solution = func(read4 func([]byte) int) func([]byte, int) int {\n // implement read below.\n return func(buf []byte, n int) int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * The read4 API is defined in the parent class Reader4.\n * def read4(buf4: Array[Char]): Int = {}\n */\n\nclass Solution extends Reader4 {\n /**\n * @param buf Destination buffer\n \t * @param n Number of characters to read\n * @return The number of actual characters read\n */\n def read(buf: Array[Char], n: Int): Int = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n* The read4 API is defined in the parent class Reader4.\n* fun read4(buf4:CharArray): Int {}\n*/\n\nclass Solution:Reader4() {\n /**\n * @param buf Destination buffer\n * @param n Number of characters to read\n * @return The number of actual characters read\n */\n override fun read(buf:CharArray, n:Int): Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "/**\n * The read4 API is defined as.\n * fn read4(&self,buf4: &mut [char]) -> i32;\n * You can call it using self.read4(buf4)\n */\n\nimpl Solution {\n pub fn read(&self, buf: &mut [char], n: i32) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/* The read4 API is defined in the parent class Reader4.\n public function read4(&$buf4){} */\n\nclass Solution extends Reader4 {\n /**\n * @param Char[] &$buf\tDestination buffer\n * @param Integer $n\t\tNumber of characters to read\n * @return Integer \t\t\tThe number of actual characters read\n */\n function read(&$buf, $n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for read4()\n * read4 = function(buf4: string[]): number {\n * ...\n * };\n */\n\nvar solution = function(read4: any) {\n\n return function(buf: string[], n: number): number {\n \n };\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0157](https://leetcode-cn.com/problems/read-n-characters-given-read4)", "[\u7528 Read4 \u8bfb\u53d6 N \u4e2a\u5b57\u7b26](/solution/0100-0199/0157.Read%20N%20Characters%20Given%20Read4/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0157](https://leetcode.com/problems/read-n-characters-given-read4)", "[Read N Characters Given Read4](/solution/0100-0199/0157.Read%20N%20Characters%20Given%20Read4/README_EN.md)", "`String`", "Easy", "\ud83d\udd12"]}, {"question_id": "0156", "frontend_question_id": "0156", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/binary-tree-upside-down", "url_en": "https://leetcode.com/problems/binary-tree-upside-down", "relative_path_cn": "/solution/0100-0199/0156.Binary%20Tree%20Upside%20Down/README.md", "relative_path_en": "/solution/0100-0199/0156.Binary%20Tree%20Upside%20Down/README_EN.md", "title_cn": "\u4e0a\u4e0b\u7ffb\u8f6c\u4e8c\u53c9\u6811", "title_en": "Binary Tree Upside Down", "question_title_slug": "binary-tree-upside-down", "content_en": "

    Given the root of a binary tree, turn the tree upside down and return the new root.

    \n\n

    You can turn a binary tree upside down with the following steps:

    \n\n
      \n\t
    1. The original left child becomes the new root.
    2. \n\t
    3. The original root becomes the new right child.
    4. \n\t
    5. The original right child becomes the new left child.
    6. \n
    \n\n

    \"\"

    \n\n

    The mentioned steps are done level by level, it is guaranteed that every node in the given tree has either 0 or 2 children.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,2,3,4,5]\nOutput: [4,5,2,null,null,3,1]\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = []\nOutput: []\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = [1]\nOutput: [1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree will be in the range [0, 10].
    • \n\t
    • 1 <= Node.val <= 10
    • \n\t
    • Every node has either 0 or 2 children.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811\uff0c\u5176\u4e2d\u6240\u6709\u7684\u53f3\u8282\u70b9\u8981\u4e48\u662f\u5177\u6709\u5144\u5f1f\u8282\u70b9\uff08\u62e5\u6709\u76f8\u540c\u7236\u8282\u70b9\u7684\u5de6\u8282\u70b9\uff09\u7684\u53f6\u8282\u70b9\uff0c\u8981\u4e48\u4e3a\u7a7a\uff0c\u5c06\u6b64\u4e8c\u53c9\u6811\u4e0a\u4e0b\u7ffb\u8f6c\u5e76\u5c06\u5b83\u53d8\u6210\u4e00\u68f5\u6811\uff0c \u539f\u6765\u7684\u53f3\u8282\u70b9\u5c06\u8f6c\u6362\u6210\u5de6\u53f6\u8282\u70b9\u3002\u8fd4\u56de\u65b0\u7684\u6839\u3002

    \n\n

    \u4f8b\u5b50:

    \n\n
    \u8f93\u5165: [1,2,3,4,5]\n\n    1\n   / \\\n  2   3\n / \\\n4   5\n\n\u8f93\u51fa: \u8fd4\u56de\u4e8c\u53c9\u6811\u7684\u6839 [4,5,2,#,#,3,1]\n\n   4\n  / \\\n 5   2\n    / \\\n   3   1  \n
    \n\n

    \u8bf4\u660e:

    \n\n

    \u5bf9 [4,5,2,#,#,3,1] \u611f\u5230\u56f0\u60d1? \u4e0b\u9762\u8be6\u7ec6\u4ecb\u7ecd\u8bf7\u67e5\u770b \u4e8c\u53c9\u6811\u662f\u5982\u4f55\u88ab\u5e8f\u5217\u5316\u7684\u3002

    \n\n

    \u4e8c\u53c9\u6811\u7684\u5e8f\u5217\u5316\u9075\u5faa\u5c42\u6b21\u904d\u5386\u89c4\u5219\uff0c\u5f53\u6ca1\u6709\u8282\u70b9\u5b58\u5728\u65f6\uff0c'#' \u8868\u793a\u8def\u5f84\u7ec8\u6b62\u7b26\u3002

    \n\n

    \u8fd9\u91cc\u6709\u4e00\u4e2a\u4f8b\u5b50:

    \n\n
       1\n  / \\\n 2   3\n    /\n   4\n    \\\n     5\n
    \n\n

    \u4e0a\u9762\u7684\u4e8c\u53c9\u6811\u5219\u88ab\u5e8f\u5217\u5316\u4e3a [1,2,3,#,#,4,#,#,5].

    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* upsideDownBinaryTree(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode upsideDownBinaryTree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def upsideDownBinaryTree(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: TreeNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def upsideDownBinaryTree(self, root: TreeNode) -> TreeNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* upsideDownBinaryTree(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode UpsideDownBinaryTree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {TreeNode}\n */\nvar upsideDownBinaryTree = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {TreeNode}\ndef upside_down_binary_tree(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func upsideDownBinaryTree(_ root: TreeNode?) -> TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc upsideDownBinaryTree(root *TreeNode) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def upsideDownBinaryTree(root: TreeNode): TreeNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun upsideDownBinaryTree(root: TreeNode?): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn upside_down_binary_tree(root: Option>>) -> Option>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return TreeNode\n */\n function upsideDownBinaryTree($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction upsideDownBinaryTree(root: TreeNode | null): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (upside-down-binary-tree root)\n (-> (or/c tree-node? #f) (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0156](https://leetcode-cn.com/problems/binary-tree-upside-down)", "[\u4e0a\u4e0b\u7ffb\u8f6c\u4e8c\u53c9\u6811](/solution/0100-0199/0156.Binary%20Tree%20Upside%20Down/README.md)", "`\u6811`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0156](https://leetcode.com/problems/binary-tree-upside-down)", "[Binary Tree Upside Down](/solution/0100-0199/0156.Binary%20Tree%20Upside%20Down/README_EN.md)", "`Tree`", "Medium", "\ud83d\udd12"]}, {"question_id": "0155", "frontend_question_id": "0155", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/min-stack", "url_en": "https://leetcode.com/problems/min-stack", "relative_path_cn": "/solution/0100-0199/0155.Min%20Stack/README.md", "relative_path_en": "/solution/0100-0199/0155.Min%20Stack/README_EN.md", "title_cn": "\u6700\u5c0f\u6808", "title_en": "Min Stack", "question_title_slug": "min-stack", "content_en": "

    Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.

    \n\n

    Implement the MinStack class:

    \n\n
      \n\t
    • MinStack() initializes the stack object.
    • \n\t
    • void push(val) pushes the element val onto the stack.
    • \n\t
    • void pop() removes the element on the top of the stack.
    • \n\t
    • int top() gets the top element of the stack.
    • \n\t
    • int getMin() retrieves the minimum element in the stack.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["MinStack","push","push","push","getMin","pop","top","getMin"]\n[[],[-2],[0],[-3],[],[],[],[]]\n\nOutput\n[null,null,null,null,-3,null,0,-2]\n\nExplanation\nMinStack minStack = new MinStack();\nminStack.push(-2);\nminStack.push(0);\nminStack.push(-3);\nminStack.getMin(); // return -3\nminStack.pop();\nminStack.top();    // return 0\nminStack.getMin(); // return -2\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • -231 <= val <= 231 - 1
    • \n\t
    • Methods pop, top and getMin operations will always be called on non-empty stacks.
    • \n\t
    • At most 3 * 104 calls will be made to push, pop, top, and getMin.
    • \n
    \n", "content_cn": "

    \u8bbe\u8ba1\u4e00\u4e2a\u652f\u6301 push \uff0cpop \uff0ctop \u64cd\u4f5c\uff0c\u5e76\u80fd\u5728\u5e38\u6570\u65f6\u95f4\u5185\u68c0\u7d22\u5230\u6700\u5c0f\u5143\u7d20\u7684\u6808\u3002

    \n\n
      \n\t
    • push(x) —— \u5c06\u5143\u7d20 x \u63a8\u5165\u6808\u4e2d\u3002
    • \n\t
    • pop() —— \u5220\u9664\u6808\u9876\u7684\u5143\u7d20\u3002
    • \n\t
    • top() —— \u83b7\u53d6\u6808\u9876\u5143\u7d20\u3002
    • \n\t
    • getMin() —— \u68c0\u7d22\u6808\u4e2d\u7684\u6700\u5c0f\u5143\u7d20\u3002
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165\uff1a\n["MinStack","push","push","push","getMin","pop","top","getMin"]\n[[],[-2],[0],[-3],[],[],[],[]]\n\n\u8f93\u51fa\uff1a\n[null,null,null,null,-3,null,0,-2]\n\n\u89e3\u91ca\uff1a\nMinStack minStack = new MinStack();\nminStack.push(-2);\nminStack.push(0);\nminStack.push(-3);\nminStack.getMin();   --> \u8fd4\u56de -3.\nminStack.pop();\nminStack.top();      --> \u8fd4\u56de 0.\nminStack.getMin();   --> \u8fd4\u56de -2.\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • pop\u3001top \u548c getMin \u64cd\u4f5c\u603b\u662f\u5728 \u975e\u7a7a\u6808 \u4e0a\u8c03\u7528\u3002
    • \n
    \n", "tags_en": ["Stack", "Design"], "tags_cn": ["\u6808", "\u8bbe\u8ba1"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class MinStack {\npublic:\n /** initialize your data structure here. */\n MinStack() {\n\n }\n \n void push(int val) {\n\n }\n \n void pop() {\n\n }\n \n int top() {\n\n }\n \n int getMin() {\n\n }\n};\n\n/**\n * Your MinStack object will be instantiated and called as such:\n * MinStack* obj = new MinStack();\n * obj->push(val);\n * obj->pop();\n * int param_3 = obj->top();\n * int param_4 = obj->getMin();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class MinStack {\n\n /** initialize your data structure here. */\n public MinStack() {\n\n }\n \n public void push(int val) {\n\n }\n \n public void pop() {\n\n }\n \n public int top() {\n\n }\n \n public int getMin() {\n\n }\n}\n\n/**\n * Your MinStack object will be instantiated and called as such:\n * MinStack obj = new MinStack();\n * obj.push(val);\n * obj.pop();\n * int param_3 = obj.top();\n * int param_4 = obj.getMin();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class MinStack(object):\n\n def __init__(self):\n \"\"\"\n initialize your data structure here.\n \"\"\"\n\n\n def push(self, val):\n \"\"\"\n :type val: int\n :rtype: None\n \"\"\"\n\n\n def pop(self):\n \"\"\"\n :rtype: None\n \"\"\"\n\n\n def top(self):\n \"\"\"\n :rtype: int\n \"\"\"\n\n\n def getMin(self):\n \"\"\"\n :rtype: int\n \"\"\"\n\n\n\n# Your MinStack object will be instantiated and called as such:\n# obj = MinStack()\n# obj.push(val)\n# obj.pop()\n# param_3 = obj.top()\n# param_4 = obj.getMin()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class MinStack:\n\n def __init__(self):\n \"\"\"\n initialize your data structure here.\n \"\"\"\n\n\n def push(self, val: int) -> None:\n\n\n def pop(self) -> None:\n\n\n def top(self) -> int:\n\n\n def getMin(self) -> int:\n\n\n\n# Your MinStack object will be instantiated and called as such:\n# obj = MinStack()\n# obj.push(val)\n# obj.pop()\n# param_3 = obj.top()\n# param_4 = obj.getMin()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} MinStack;\n\n/** initialize your data structure here. */\n\nMinStack* minStackCreate() {\n\n}\n\nvoid minStackPush(MinStack* obj, int val) {\n\n}\n\nvoid minStackPop(MinStack* obj) {\n\n}\n\nint minStackTop(MinStack* obj) {\n\n}\n\nint minStackGetMin(MinStack* obj) {\n\n}\n\nvoid minStackFree(MinStack* obj) {\n\n}\n\n/**\n * Your MinStack struct will be instantiated and called as such:\n * MinStack* obj = minStackCreate();\n * minStackPush(obj, val);\n \n * minStackPop(obj);\n \n * int param_3 = minStackTop(obj);\n \n * int param_4 = minStackGetMin(obj);\n \n * minStackFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class MinStack {\n\n /** initialize your data structure here. */\n public MinStack() {\n\n }\n \n public void Push(int val) {\n\n }\n \n public void Pop() {\n\n }\n \n public int Top() {\n\n }\n \n public int GetMin() {\n\n }\n}\n\n/**\n * Your MinStack object will be instantiated and called as such:\n * MinStack obj = new MinStack();\n * obj.Push(val);\n * obj.Pop();\n * int param_3 = obj.Top();\n * int param_4 = obj.GetMin();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * initialize your data structure here.\n */\nvar MinStack = function() {\n\n};\n\n/** \n * @param {number} val\n * @return {void}\n */\nMinStack.prototype.push = function(val) {\n\n};\n\n/**\n * @return {void}\n */\nMinStack.prototype.pop = function() {\n\n};\n\n/**\n * @return {number}\n */\nMinStack.prototype.top = function() {\n\n};\n\n/**\n * @return {number}\n */\nMinStack.prototype.getMin = function() {\n\n};\n\n/**\n * Your MinStack object will be instantiated and called as such:\n * var obj = new MinStack()\n * obj.push(val)\n * obj.pop()\n * var param_3 = obj.top()\n * var param_4 = obj.getMin()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class MinStack\n\n=begin\n initialize your data structure here.\n=end\n def initialize()\n\n end\n\n\n=begin\n :type val: Integer\n :rtype: Void\n=end\n def push(val)\n\n end\n\n\n=begin\n :rtype: Void\n=end\n def pop()\n\n end\n\n\n=begin\n :rtype: Integer\n=end\n def top()\n\n end\n\n\n=begin\n :rtype: Integer\n=end\n def get_min()\n\n end\n\n\nend\n\n# Your MinStack object will be instantiated and called as such:\n# obj = MinStack.new()\n# obj.push(val)\n# obj.pop()\n# param_3 = obj.top()\n# param_4 = obj.get_min()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass MinStack {\n\n /** initialize your data structure here. */\n init() {\n\n }\n \n func push(_ val: Int) {\n\n }\n \n func pop() {\n\n }\n \n func top() -> Int {\n\n }\n \n func getMin() -> Int {\n\n }\n}\n\n/**\n * Your MinStack object will be instantiated and called as such:\n * let obj = MinStack()\n * obj.push(val)\n * obj.pop()\n * let ret_3: Int = obj.top()\n * let ret_4: Int = obj.getMin()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type MinStack struct {\n\n}\n\n\n/** initialize your data structure here. */\nfunc Constructor() MinStack {\n\n}\n\n\nfunc (this *MinStack) Push(val int) {\n\n}\n\n\nfunc (this *MinStack) Pop() {\n\n}\n\n\nfunc (this *MinStack) Top() int {\n\n}\n\n\nfunc (this *MinStack) GetMin() int {\n\n}\n\n\n/**\n * Your MinStack object will be instantiated and called as such:\n * obj := Constructor();\n * obj.Push(val);\n * obj.Pop();\n * param_3 := obj.Top();\n * param_4 := obj.GetMin();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class MinStack() {\n\n /** initialize your data structure here. */\n\n\n def push(`val`: Int) {\n\n }\n\n def pop() {\n\n }\n\n def top(): Int = {\n\n }\n\n def getMin(): Int = {\n\n }\n\n}\n\n/**\n * Your MinStack object will be instantiated and called as such:\n * var obj = new MinStack()\n * obj.push(`val`)\n * obj.pop()\n * var param_3 = obj.top()\n * var param_4 = obj.getMin()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class MinStack() {\n\n /** initialize your data structure here. */\n\n\n fun push(`val`: Int) {\n\n }\n\n fun pop() {\n\n }\n\n fun top(): Int {\n\n }\n\n fun getMin(): Int {\n\n }\n\n}\n\n/**\n * Your MinStack object will be instantiated and called as such:\n * var obj = MinStack()\n * obj.push(`val`)\n * obj.pop()\n * var param_3 = obj.top()\n * var param_4 = obj.getMin()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct MinStack {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl MinStack {\n\n /** initialize your data structure here. */\n fn new() -> Self {\n\n }\n \n fn push(&self, val: i32) {\n\n }\n \n fn pop(&self) {\n\n }\n \n fn top(&self) -> i32 {\n\n }\n \n fn get_min(&self) -> i32 {\n\n }\n}\n\n/**\n * Your MinStack object will be instantiated and called as such:\n * let obj = MinStack::new();\n * obj.push(val);\n * obj.pop();\n * let ret_3: i32 = obj.top();\n * let ret_4: i32 = obj.get_min();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class MinStack {\n /**\n * initialize your data structure here.\n */\n function __construct() {\n\n }\n\n /**\n * @param Integer $val\n * @return NULL\n */\n function push($val) {\n\n }\n\n /**\n * @return NULL\n */\n function pop() {\n\n }\n\n /**\n * @return Integer\n */\n function top() {\n\n }\n\n /**\n * @return Integer\n */\n function getMin() {\n\n }\n}\n\n/**\n * Your MinStack object will be instantiated and called as such:\n * $obj = MinStack();\n * $obj->push($val);\n * $obj->pop();\n * $ret_3 = $obj->top();\n * $ret_4 = $obj->getMin();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class MinStack {\n constructor() {\n\n }\n\n push(val: number): void {\n\n }\n\n pop(): void {\n\n }\n\n top(): number {\n\n }\n\n getMin(): number {\n\n }\n}\n\n/**\n * Your MinStack object will be instantiated and called as such:\n * var obj = new MinStack()\n * obj.push(val)\n * obj.pop()\n * var param_3 = obj.top()\n * var param_4 = obj.getMin()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define min-stack%\n (class object%\n (super-new)\n (init-field)\n \n ; push : exact-integer? -> void?\n (define/public (push val)\n\n )\n ; pop : -> void?\n (define/public (pop)\n\n )\n ; top : -> exact-integer?\n (define/public (top)\n\n )\n ; get-min : -> exact-integer?\n (define/public (get-min)\n\n )))\n\n;; Your min-stack% object will be instantiated and called as such:\n;; (define obj (new min-stack%))\n;; (send obj push val)\n;; (send obj pop)\n;; (define param_3 (send obj top))\n;; (define param_4 (send obj get-min))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0155](https://leetcode-cn.com/problems/min-stack)", "[\u6700\u5c0f\u6808](/solution/0100-0199/0155.Min%20Stack/README.md)", "`\u6808`,`\u8bbe\u8ba1`", "\u7b80\u5355", ""], "md_table_row_en": ["[0155](https://leetcode.com/problems/min-stack)", "[Min Stack](/solution/0100-0199/0155.Min%20Stack/README_EN.md)", "`Stack`,`Design`", "Easy", ""]}, {"question_id": "0154", "frontend_question_id": "0154", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array-ii", "url_en": "https://leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii", "relative_path_cn": "/solution/0100-0199/0154.Find%20Minimum%20in%20Rotated%20Sorted%20Array%20II/README.md", "relative_path_en": "/solution/0100-0199/0154.Find%20Minimum%20in%20Rotated%20Sorted%20Array%20II/README_EN.md", "title_cn": "\u5bfb\u627e\u65cb\u8f6c\u6392\u5e8f\u6570\u7ec4\u4e2d\u7684\u6700\u5c0f\u503c II", "title_en": "Find Minimum in Rotated Sorted Array II", "question_title_slug": "find-minimum-in-rotated-sorted-array-ii", "content_en": "

    Suppose an array of length n sorted in ascending order is rotated between 1 and n times. For example, the array nums = [0,1,4,4,5,6,7] might become:

    \n\n
      \n\t
    • [4,5,6,7,0,1,4] if it was rotated 4 times.
    • \n\t
    • [0,1,4,4,5,6,7] if it was rotated 7 times.
    • \n
    \n\n

    Notice that rotating an array [a[0], a[1], a[2], ..., a[n-1]] 1 time results in the array [a[n-1], a[0], a[1], a[2], ..., a[n-2]].

    \n\n

    Given the sorted rotated array nums that may contain duplicates, return the minimum element of this array.

    \n\n

    You must decrease the overall operation steps as much as possible.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [1,3,5]\nOutput: 1\n

    Example 2:

    \n
    Input: nums = [2,2,2,0,1]\nOutput: 0\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= n <= 5000
    • \n\t
    • -5000 <= nums[i] <= 5000
    • \n\t
    • nums is sorted and rotated between 1 and n times.
    • \n
    \n\n

     

    \n

    Follow up: This problem is similar to Find Minimum in Rotated Sorted Array, but nums may contain duplicates. Would this affect the runtime complexity? How and why?

    \n\n

     

    \n", "content_cn": "\u5df2\u77e5\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u6570\u7ec4\uff0c\u9884\u5148\u6309\u7167\u5347\u5e8f\u6392\u5217\uff0c\u7ecf\u7531 1 \u5230 n \u6b21 \u65cb\u8f6c \u540e\uff0c\u5f97\u5230\u8f93\u5165\u6570\u7ec4\u3002\u4f8b\u5982\uff0c\u539f\u6570\u7ec4 nums = [0,1,4,4,5,6,7] \u5728\u53d8\u5316\u540e\u53ef\u80fd\u5f97\u5230\uff1a\n
      \n\t
    • \u82e5\u65cb\u8f6c 4 \u6b21\uff0c\u5219\u53ef\u4ee5\u5f97\u5230 [4,5,6,7,0,1,4]
    • \n\t
    • \u82e5\u65cb\u8f6c 7 \u6b21\uff0c\u5219\u53ef\u4ee5\u5f97\u5230 [0,1,4,4,5,6,7]
    • \n
    \n\n

    \u6ce8\u610f\uff0c\u6570\u7ec4 [a[0], a[1], a[2], ..., a[n-1]] \u65cb\u8f6c\u4e00\u6b21 \u7684\u7ed3\u679c\u4e3a\u6570\u7ec4 [a[n-1], a[0], a[1], a[2], ..., a[n-2]] \u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u53ef\u80fd\u5b58\u5728 \u91cd\u590d \u5143\u7d20\u503c\u7684\u6570\u7ec4 nums \uff0c\u5b83\u539f\u6765\u662f\u4e00\u4e2a\u5347\u5e8f\u6392\u5217\u7684\u6570\u7ec4\uff0c\u5e76\u6309\u4e0a\u8ff0\u60c5\u5f62\u8fdb\u884c\u4e86\u591a\u6b21\u65cb\u8f6c\u3002\u8bf7\u4f60\u627e\u51fa\u5e76\u8fd4\u56de\u6570\u7ec4\u4e2d\u7684 \u6700\u5c0f\u5143\u7d20 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,3,5]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [2,2,2,0,1]\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= n <= 5000
    • \n\t
    • -5000 <= nums[i] <= 5000
    • \n\t
    • nums \u539f\u6765\u662f\u4e00\u4e2a\u5347\u5e8f\u6392\u5e8f\u7684\u6570\u7ec4\uff0c\u5e76\u8fdb\u884c\u4e86 1 \u81f3 n \u6b21\u65cb\u8f6c
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a

    \n\n\n", "tags_en": ["Array", "Binary Search"], "tags_cn": ["\u6570\u7ec4", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findMin(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findMin(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findMin(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findMin(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findMin(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindMin(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar findMin = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef find_min(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findMin(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findMin(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findMin(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findMin(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_min(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function findMin($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findMin(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-min nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0154](https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array-ii)", "[\u5bfb\u627e\u65cb\u8f6c\u6392\u5e8f\u6570\u7ec4\u4e2d\u7684\u6700\u5c0f\u503c II](/solution/0100-0199/0154.Find%20Minimum%20in%20Rotated%20Sorted%20Array%20II/README.md)", "`\u6570\u7ec4`,`\u4e8c\u5206\u67e5\u627e`", "\u56f0\u96be", ""], "md_table_row_en": ["[0154](https://leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii)", "[Find Minimum in Rotated Sorted Array II](/solution/0100-0199/0154.Find%20Minimum%20in%20Rotated%20Sorted%20Array%20II/README_EN.md)", "`Array`,`Binary Search`", "Hard", ""]}, {"question_id": "0153", "frontend_question_id": "0153", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array", "url_en": "https://leetcode.com/problems/find-minimum-in-rotated-sorted-array", "relative_path_cn": "/solution/0100-0199/0153.Find%20Minimum%20in%20Rotated%20Sorted%20Array/README.md", "relative_path_en": "/solution/0100-0199/0153.Find%20Minimum%20in%20Rotated%20Sorted%20Array/README_EN.md", "title_cn": "\u5bfb\u627e\u65cb\u8f6c\u6392\u5e8f\u6570\u7ec4\u4e2d\u7684\u6700\u5c0f\u503c", "title_en": "Find Minimum in Rotated Sorted Array", "question_title_slug": "find-minimum-in-rotated-sorted-array", "content_en": "

    Suppose an array of length n sorted in ascending order is rotated between 1 and n times. For example, the array nums = [0,1,2,4,5,6,7] might become:

    \n\n
      \n\t
    • [4,5,6,7,0,1,2] if it was rotated 4 times.
    • \n\t
    • [0,1,2,4,5,6,7] if it was rotated 7 times.
    • \n
    \n\n

    Notice that rotating an array [a[0], a[1], a[2], ..., a[n-1]] 1 time results in the array [a[n-1], a[0], a[1], a[2], ..., a[n-2]].

    \n\n

    Given the sorted rotated array nums of unique elements, return the minimum element of this array.

    \n\n

    You must write an algorithm that runs in O(log n) time.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [3,4,5,1,2]\nOutput: 1\nExplanation: The original array was [1,2,3,4,5] rotated 3 times.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [4,5,6,7,0,1,2]\nOutput: 0\nExplanation: The original array was [0,1,2,4,5,6,7] and it was rotated 4 times.\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [11,13,15,17]\nOutput: 11\nExplanation: The original array was [11,13,15,17] and it was rotated 4 times. \n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= n <= 5000
    • \n\t
    • -5000 <= nums[i] <= 5000
    • \n\t
    • All the integers of nums are unique.
    • \n\t
    • nums is sorted and rotated between 1 and n times.
    • \n
    \n", "content_cn": "\u5df2\u77e5\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u6570\u7ec4\uff0c\u9884\u5148\u6309\u7167\u5347\u5e8f\u6392\u5217\uff0c\u7ecf\u7531 1 \u5230 n \u6b21 \u65cb\u8f6c \u540e\uff0c\u5f97\u5230\u8f93\u5165\u6570\u7ec4\u3002\u4f8b\u5982\uff0c\u539f\u6570\u7ec4 nums = [0,1,2,4,5,6,7] \u5728\u53d8\u5316\u540e\u53ef\u80fd\u5f97\u5230\uff1a\n
      \n\t
    • \u82e5\u65cb\u8f6c 4 \u6b21\uff0c\u5219\u53ef\u4ee5\u5f97\u5230 [4,5,6,7,0,1,2]
    • \n\t
    • \u82e5\u65cb\u8f6c 7 \u6b21\uff0c\u5219\u53ef\u4ee5\u5f97\u5230 [0,1,2,4,5,6,7]
    • \n
    \n\n

    \u6ce8\u610f\uff0c\u6570\u7ec4 [a[0], a[1], a[2], ..., a[n-1]] \u65cb\u8f6c\u4e00\u6b21 \u7684\u7ed3\u679c\u4e3a\u6570\u7ec4 [a[n-1], a[0], a[1], a[2], ..., a[n-2]] \u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u5143\u7d20\u503c \u4e92\u4e0d\u76f8\u540c \u7684\u6570\u7ec4 nums \uff0c\u5b83\u539f\u6765\u662f\u4e00\u4e2a\u5347\u5e8f\u6392\u5217\u7684\u6570\u7ec4\uff0c\u5e76\u6309\u4e0a\u8ff0\u60c5\u5f62\u8fdb\u884c\u4e86\u591a\u6b21\u65cb\u8f6c\u3002\u8bf7\u4f60\u627e\u51fa\u5e76\u8fd4\u56de\u6570\u7ec4\u4e2d\u7684 \u6700\u5c0f\u5143\u7d20 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [3,4,5,1,2]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u539f\u6570\u7ec4\u4e3a [1,2,3,4,5] \uff0c\u65cb\u8f6c 3 \u6b21\u5f97\u5230\u8f93\u5165\u6570\u7ec4\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [4,5,6,7,0,1,2]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u539f\u6570\u7ec4\u4e3a [0,1,2,4,5,6,7] \uff0c\u65cb\u8f6c 4 \u6b21\u5f97\u5230\u8f93\u5165\u6570\u7ec4\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [11,13,15,17]\n\u8f93\u51fa\uff1a11\n\u89e3\u91ca\uff1a\u539f\u6570\u7ec4\u4e3a [11,13,15,17] \uff0c\u65cb\u8f6c 4 \u6b21\u5f97\u5230\u8f93\u5165\u6570\u7ec4\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= n <= 5000
    • \n\t
    • -5000 <= nums[i] <= 5000
    • \n\t
    • nums \u4e2d\u7684\u6240\u6709\u6574\u6570 \u4e92\u4e0d\u76f8\u540c
    • \n\t
    • nums \u539f\u6765\u662f\u4e00\u4e2a\u5347\u5e8f\u6392\u5e8f\u7684\u6570\u7ec4\uff0c\u5e76\u8fdb\u884c\u4e86 1 \u81f3 n \u6b21\u65cb\u8f6c
    • \n
    \n", "tags_en": ["Array", "Binary Search"], "tags_cn": ["\u6570\u7ec4", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findMin(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findMin(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findMin(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findMin(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findMin(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindMin(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar findMin = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef find_min(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findMin(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findMin(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findMin(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findMin(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_min(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function findMin($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findMin(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-min nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0153](https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array)", "[\u5bfb\u627e\u65cb\u8f6c\u6392\u5e8f\u6570\u7ec4\u4e2d\u7684\u6700\u5c0f\u503c](/solution/0100-0199/0153.Find%20Minimum%20in%20Rotated%20Sorted%20Array/README.md)", "`\u6570\u7ec4`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0153](https://leetcode.com/problems/find-minimum-in-rotated-sorted-array)", "[Find Minimum in Rotated Sorted Array](/solution/0100-0199/0153.Find%20Minimum%20in%20Rotated%20Sorted%20Array/README_EN.md)", "`Array`,`Binary Search`", "Medium", ""]}, {"question_id": "0152", "frontend_question_id": "0152", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-product-subarray", "url_en": "https://leetcode.com/problems/maximum-product-subarray", "relative_path_cn": "/solution/0100-0199/0152.Maximum%20Product%20Subarray/README.md", "relative_path_en": "/solution/0100-0199/0152.Maximum%20Product%20Subarray/README_EN.md", "title_cn": "\u4e58\u79ef\u6700\u5927\u5b50\u6570\u7ec4", "title_en": "Maximum Product Subarray", "question_title_slug": "maximum-product-subarray", "content_en": "

    Given an integer array nums, find a contiguous non-empty subarray within the array that has the largest product, and return the product.

    \n\n

    It is guaranteed that the answer will fit in a 32-bit integer.

    \n\n

    A subarray is a contiguous subsequence of the array.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [2,3,-2,4]\nOutput: 6\nExplanation: [2,3] has the largest product 6.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [-2,0,-1]\nOutput: 0\nExplanation: The result cannot be 2, because [-2,-1] is not a subarray.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 2 * 104
    • \n\t
    • -10 <= nums[i] <= 10
    • \n\t
    • The product of any prefix or suffix of nums is guaranteed to fit in a 32-bit integer.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \uff0c\u8bf7\u4f60\u627e\u51fa\u6570\u7ec4\u4e2d\u4e58\u79ef\u6700\u5927\u7684\u8fde\u7eed\u5b50\u6570\u7ec4\uff08\u8be5\u5b50\u6570\u7ec4\u4e2d\u81f3\u5c11\u5305\u542b\u4e00\u4e2a\u6570\u5b57\uff09\uff0c\u5e76\u8fd4\u56de\u8be5\u5b50\u6570\u7ec4\u6240\u5bf9\u5e94\u7684\u4e58\u79ef\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: [2,3,-2,4]\n\u8f93\u51fa: 6\n\u89e3\u91ca: \u5b50\u6570\u7ec4 [2,3] \u6709\u6700\u5927\u4e58\u79ef 6\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: [-2,0,-1]\n\u8f93\u51fa: 0\n\u89e3\u91ca: \u7ed3\u679c\u4e0d\u80fd\u4e3a 2, \u56e0\u4e3a [-2,-1] \u4e0d\u662f\u5b50\u6570\u7ec4\u3002
    \n", "tags_en": ["Array", "Dynamic Programming"], "tags_cn": ["\u6570\u7ec4", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxProduct(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxProduct(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxProduct(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxProduct(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxProduct(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxProduct(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar maxProduct = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef max_product(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxProduct(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxProduct(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxProduct(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxProduct(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_product(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function maxProduct($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxProduct(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-product nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0152](https://leetcode-cn.com/problems/maximum-product-subarray)", "[\u4e58\u79ef\u6700\u5927\u5b50\u6570\u7ec4](/solution/0100-0199/0152.Maximum%20Product%20Subarray/README.md)", "`\u6570\u7ec4`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0152](https://leetcode.com/problems/maximum-product-subarray)", "[Maximum Product Subarray](/solution/0100-0199/0152.Maximum%20Product%20Subarray/README_EN.md)", "`Array`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0151", "frontend_question_id": "0151", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reverse-words-in-a-string", "url_en": "https://leetcode.com/problems/reverse-words-in-a-string", "relative_path_cn": "/solution/0100-0199/0151.Reverse%20Words%20in%20a%20String/README.md", "relative_path_en": "/solution/0100-0199/0151.Reverse%20Words%20in%20a%20String/README_EN.md", "title_cn": "\u7ffb\u8f6c\u5b57\u7b26\u4e32\u91cc\u7684\u5355\u8bcd", "title_en": "Reverse Words in a String", "question_title_slug": "reverse-words-in-a-string", "content_en": "

    Given an input string s, reverse the order of the words.

    \n\n

    A word is defined as a sequence of non-space characters. The words in s will be separated by at least one space.

    \n\n

    Return a string of the words in reverse order concatenated by a single space.

    \n\n

    Note that s may contain leading or trailing spaces or multiple spaces between two words. The returned string should only have a single space separating the words. Do not include any extra spaces.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "the sky is blue"\nOutput: "blue is sky the"\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "  hello world  "\nOutput: "world hello"\nExplanation: Your reversed string should not contain leading or trailing spaces.\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "a good   example"\nOutput: "example good a"\nExplanation: You need to reduce multiple spaces between two words to a single space in the reversed string.\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "  Bob    Loves  Alice   "\nOutput: "Alice Loves Bob"\n
    \n\n

    Example 5:

    \n\n
    \nInput: s = "Alice does not even like bob"\nOutput: "bob like even not does Alice"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 104
    • \n\t
    • s contains English letters (upper-case and lower-case), digits, and spaces ' '.
    • \n\t
    • There is at least one word in s.
    • \n
    \n\n

     

    \n

    Follow up: Could you solve it in-place with O(1) extra space?

    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \uff0c\u9010\u4e2a\u7ffb\u8f6c\u5b57\u7b26\u4e32\u4e2d\u7684\u6240\u6709 \u5355\u8bcd \u3002

    \n\n

    \u5355\u8bcd \u662f\u7531\u975e\u7a7a\u683c\u5b57\u7b26\u7ec4\u6210\u7684\u5b57\u7b26\u4e32\u3002s \u4e2d\u4f7f\u7528\u81f3\u5c11\u4e00\u4e2a\u7a7a\u683c\u5c06\u5b57\u7b26\u4e32\u4e2d\u7684 \u5355\u8bcd \u5206\u9694\u5f00\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u4e00\u4e2a\u7ffb\u8f6c s \u4e2d\u5355\u8bcd\u987a\u5e8f\u5e76\u7528\u5355\u4e2a\u7a7a\u683c\u76f8\u8fde\u7684\u5b57\u7b26\u4e32\u3002

    \n\n

    \u8bf4\u660e\uff1a

    \n\n
      \n\t
    • \u8f93\u5165\u5b57\u7b26\u4e32 s \u53ef\u4ee5\u5728\u524d\u9762\u3001\u540e\u9762\u6216\u8005\u5355\u8bcd\u95f4\u5305\u542b\u591a\u4f59\u7684\u7a7a\u683c\u3002
    • \n\t
    • \u7ffb\u8f6c\u540e\u5355\u8bcd\u95f4\u5e94\u5f53\u4ec5\u7528\u4e00\u4e2a\u7a7a\u683c\u5206\u9694\u3002
    • \n\t
    • \u7ffb\u8f6c\u540e\u7684\u5b57\u7b26\u4e32\u4e2d\u4e0d\u5e94\u5305\u542b\u989d\u5916\u7684\u7a7a\u683c\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"the sky is blue\"\n\u8f93\u51fa\uff1a\"blue is sky the\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \" \u00a0hello world \u00a0\"\n\u8f93\u51fa\uff1a\"world hello\"\n\u89e3\u91ca\uff1a\u8f93\u5165\u5b57\u7b26\u4e32\u53ef\u4ee5\u5728\u524d\u9762\u6216\u8005\u540e\u9762\u5305\u542b\u591a\u4f59\u7684\u7a7a\u683c\uff0c\u4f46\u662f\u7ffb\u8f6c\u540e\u7684\u5b57\u7b26\u4e0d\u80fd\u5305\u62ec\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"a good \u00a0 example\"\n\u8f93\u51fa\uff1a\"example good a\"\n\u89e3\u91ca\uff1a\u5982\u679c\u4e24\u4e2a\u5355\u8bcd\u95f4\u6709\u591a\u4f59\u7684\u7a7a\u683c\uff0c\u5c06\u7ffb\u8f6c\u540e\u5355\u8bcd\u95f4\u7684\u7a7a\u683c\u51cf\u5c11\u5230\u53ea\u542b\u4e00\u4e2a\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"  Bob    Loves  Alice   \"\n\u8f93\u51fa\uff1a\"Alice Loves Bob\"\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"Alice does not even like bob\"\n\u8f93\u51fa\uff1a\"bob like even not does Alice\"\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 104
    • \n\t
    • s \u5305\u542b\u82f1\u6587\u5927\u5c0f\u5199\u5b57\u6bcd\u3001\u6570\u5b57\u548c\u7a7a\u683c ' '
    • \n\t
    • s \u4e2d \u81f3\u5c11\u5b58\u5728\u4e00\u4e2a \u5355\u8bcd
    • \n
    \n\n
      \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u8bf7\u5c1d\u8bd5\u4f7f\u7528\u00a0O(1) \u989d\u5916\u7a7a\u95f4\u590d\u6742\u5ea6\u7684\u539f\u5730\u89e3\u6cd5\u3002
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string reverseWords(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String reverseWords(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def reverseWords(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def reverseWords(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * reverseWords(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ReverseWords(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar reverseWords = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef reverse_words(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func reverseWords(_ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func reverseWords(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def reverseWords(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun reverseWords(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn reverse_words(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function reverseWords($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function reverseWords(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (reverse-words s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0151](https://leetcode-cn.com/problems/reverse-words-in-a-string)", "[\u7ffb\u8f6c\u5b57\u7b26\u4e32\u91cc\u7684\u5355\u8bcd](/solution/0100-0199/0151.Reverse%20Words%20in%20a%20String/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0151](https://leetcode.com/problems/reverse-words-in-a-string)", "[Reverse Words in a String](/solution/0100-0199/0151.Reverse%20Words%20in%20a%20String/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "0150", "frontend_question_id": "0150", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/evaluate-reverse-polish-notation", "url_en": "https://leetcode.com/problems/evaluate-reverse-polish-notation", "relative_path_cn": "/solution/0100-0199/0150.Evaluate%20Reverse%20Polish%20Notation/README.md", "relative_path_en": "/solution/0100-0199/0150.Evaluate%20Reverse%20Polish%20Notation/README_EN.md", "title_cn": "\u9006\u6ce2\u5170\u8868\u8fbe\u5f0f\u6c42\u503c", "title_en": "Evaluate Reverse Polish Notation", "question_title_slug": "evaluate-reverse-polish-notation", "content_en": "

    Evaluate the value of an arithmetic expression in Reverse Polish Notation.

    \n\n

    Valid operators are +, -, *, and /. Each operand may be an integer or another expression.

    \n\n

    Note that division between two integers should truncate toward zero.

    \n\n

    It is guaranteed that the given RPN expression is always valid. That means the expression would always evaluate to a result, and there will not be any division by zero operation.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: tokens = ["2","1","+","3","*"]\nOutput: 9\nExplanation: ((2 + 1) * 3) = 9\n
    \n\n

    Example 2:

    \n\n
    \nInput: tokens = ["4","13","5","/","+"]\nOutput: 6\nExplanation: (4 + (13 / 5)) = 6\n
    \n\n

    Example 3:

    \n\n
    \nInput: tokens = ["10","6","9","3","+","-11","*","/","*","17","+","5","+"]\nOutput: 22\nExplanation: ((10 * (6 / ((9 + 3) * -11))) + 17) + 5\n= ((10 * (6 / (12 * -11))) + 17) + 5\n= ((10 * (6 / -132)) + 17) + 5\n= ((10 * 0) + 17) + 5\n= (0 + 17) + 5\n= 17 + 5\n= 22\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= tokens.length <= 104
    • \n\t
    • tokens[i] is either an operator: "+", "-", "*", or "/", or an integer in the range [-200, 200].
    • \n
    \n", "content_cn": "

    \u6839\u636e \u9006\u6ce2\u5170\u8868\u793a\u6cd5\uff0c\u6c42\u8868\u8fbe\u5f0f\u7684\u503c\u3002

    \n\n

    \u6709\u6548\u7684\u7b97\u7b26\u5305\u62ec\u00a0+\u3001-\u3001*\u3001/\u00a0\u3002\u6bcf\u4e2a\u8fd0\u7b97\u5bf9\u8c61\u53ef\u4ee5\u662f\u6574\u6570\uff0c\u4e5f\u53ef\u4ee5\u662f\u53e6\u4e00\u4e2a\u9006\u6ce2\u5170\u8868\u8fbe\u5f0f\u3002

    \n\n

    \u00a0

    \n\n

    \u8bf4\u660e\uff1a

    \n\n
      \n\t
    • \u6574\u6570\u9664\u6cd5\u53ea\u4fdd\u7559\u6574\u6570\u90e8\u5206\u3002
    • \n\t
    • \u7ed9\u5b9a\u9006\u6ce2\u5170\u8868\u8fbe\u5f0f\u603b\u662f\u6709\u6548\u7684\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u8868\u8fbe\u5f0f\u603b\u4f1a\u5f97\u51fa\u6709\u6548\u6570\u503c\u4e14\u4e0d\u5b58\u5728\u9664\u6570\u4e3a 0 \u7684\u60c5\u51b5\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\u00a01\uff1a

    \n\n
    \n\u8f93\u5165\uff1atokens = [\"2\",\"1\",\"+\",\"3\",\"*\"]\n\u8f93\u51fa\uff1a9\n\u89e3\u91ca\uff1a\u8be5\u7b97\u5f0f\u8f6c\u5316\u4e3a\u5e38\u89c1\u7684\u4e2d\u7f00\u7b97\u672f\u8868\u8fbe\u5f0f\u4e3a\uff1a((2 + 1) * 3) = 9\n
    \n\n

    \u793a\u4f8b\u00a02\uff1a

    \n\n
    \n\u8f93\u5165\uff1atokens = [\"4\",\"13\",\"5\",\"/\",\"+\"]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u8be5\u7b97\u5f0f\u8f6c\u5316\u4e3a\u5e38\u89c1\u7684\u4e2d\u7f00\u7b97\u672f\u8868\u8fbe\u5f0f\u4e3a\uff1a(4 + (13 / 5)) = 6\n
    \n\n

    \u793a\u4f8b\u00a03\uff1a

    \n\n
    \n\u8f93\u5165\uff1atokens = [\"10\",\"6\",\"9\",\"3\",\"+\",\"-11\",\"*\",\"/\",\"*\",\"17\",\"+\",\"5\",\"+\"]\n\u8f93\u51fa\uff1a22\n\u89e3\u91ca\uff1a\n\u8be5\u7b97\u5f0f\u8f6c\u5316\u4e3a\u5e38\u89c1\u7684\u4e2d\u7f00\u7b97\u672f\u8868\u8fbe\u5f0f\u4e3a\uff1a\n  ((10 * (6 / ((9 + 3) * -11))) + 17) + 5\n= ((10 * (6 / (12 * -11))) + 17) + 5\n= ((10 * (6 / -132)) + 17) + 5\n= ((10 * 0) + 17) + 5\n= (0 + 17) + 5\n= 17 + 5\n= 22
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= tokens.length <= 104
    • \n\t
    • tokens[i] \u8981\u4e48\u662f\u4e00\u4e2a\u7b97\u7b26\uff08\"+\"\u3001\"-\"\u3001\"*\" \u6216 \"/\"\uff09\uff0c\u8981\u4e48\u662f\u4e00\u4e2a\u5728\u8303\u56f4 [-200, 200] \u5185\u7684\u6574\u6570
    • \n
    \n\n

    \u00a0

    \n\n

    \u9006\u6ce2\u5170\u8868\u8fbe\u5f0f\uff1a

    \n\n

    \u9006\u6ce2\u5170\u8868\u8fbe\u5f0f\u662f\u4e00\u79cd\u540e\u7f00\u8868\u8fbe\u5f0f\uff0c\u6240\u8c13\u540e\u7f00\u5c31\u662f\u6307\u7b97\u7b26\u5199\u5728\u540e\u9762\u3002

    \n\n
      \n\t
    • \u5e73\u5e38\u4f7f\u7528\u7684\u7b97\u5f0f\u5219\u662f\u4e00\u79cd\u4e2d\u7f00\u8868\u8fbe\u5f0f\uff0c\u5982 ( 1 + 2 ) * ( 3 + 4 ) \u3002
    • \n\t
    • \u8be5\u7b97\u5f0f\u7684\u9006\u6ce2\u5170\u8868\u8fbe\u5f0f\u5199\u6cd5\u4e3a ( ( 1 2 + ) ( 3 4 + ) * ) \u3002
    • \n
    \n\n

    \u9006\u6ce2\u5170\u8868\u8fbe\u5f0f\u4e3b\u8981\u6709\u4ee5\u4e0b\u4e24\u4e2a\u4f18\u70b9\uff1a

    \n\n
      \n\t
    • \u53bb\u6389\u62ec\u53f7\u540e\u8868\u8fbe\u5f0f\u65e0\u6b67\u4e49\uff0c\u4e0a\u5f0f\u5373\u4fbf\u5199\u6210 1 2 + 3 4 + * \u4e5f\u53ef\u4ee5\u4f9d\u636e\u6b21\u5e8f\u8ba1\u7b97\u51fa\u6b63\u786e\u7ed3\u679c\u3002
    • \n\t
    • \u9002\u5408\u7528\u6808\u64cd\u4f5c\u8fd0\u7b97\uff1a\u9047\u5230\u6570\u5b57\u5219\u5165\u6808\uff1b\u9047\u5230\u7b97\u7b26\u5219\u53d6\u51fa\u6808\u9876\u4e24\u4e2a\u6570\u5b57\u8fdb\u884c\u8ba1\u7b97\uff0c\u5e76\u5c06\u7ed3\u679c\u538b\u5165\u6808\u4e2d\u3002
    • \n
    \n", "tags_en": ["Stack"], "tags_cn": ["\u6808"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int evalRPN(vector& tokens) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int evalRPN(String[] tokens) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def evalRPN(self, tokens):\n \"\"\"\n :type tokens: List[str]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def evalRPN(self, tokens: List[str]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint evalRPN(char ** tokens, int tokensSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int EvalRPN(string[] tokens) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} tokens\n * @return {number}\n */\nvar evalRPN = function(tokens) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} tokens\n# @return {Integer}\ndef eval_rpn(tokens)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func evalRPN(_ tokens: [String]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func evalRPN(tokens []string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def evalRPN(tokens: Array[String]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun evalRPN(tokens: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn eval_rpn(tokens: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $tokens\n * @return Integer\n */\n function evalRPN($tokens) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function evalRPN(tokens: string[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (eval-rpn tokens)\n (-> (listof string?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0150](https://leetcode-cn.com/problems/evaluate-reverse-polish-notation)", "[\u9006\u6ce2\u5170\u8868\u8fbe\u5f0f\u6c42\u503c](/solution/0100-0199/0150.Evaluate%20Reverse%20Polish%20Notation/README.md)", "`\u6808`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0150](https://leetcode.com/problems/evaluate-reverse-polish-notation)", "[Evaluate Reverse Polish Notation](/solution/0100-0199/0150.Evaluate%20Reverse%20Polish%20Notation/README_EN.md)", "`Stack`", "Medium", ""]}, {"question_id": "0149", "frontend_question_id": "0149", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/max-points-on-a-line", "url_en": "https://leetcode.com/problems/max-points-on-a-line", "relative_path_cn": "/solution/0100-0199/0149.Max%20Points%20on%20a%20Line/README.md", "relative_path_en": "/solution/0100-0199/0149.Max%20Points%20on%20a%20Line/README_EN.md", "title_cn": "\u76f4\u7ebf\u4e0a\u6700\u591a\u7684\u70b9\u6570", "title_en": "Max Points on a Line", "question_title_slug": "max-points-on-a-line", "content_en": "

    Given an array of points where points[i] = [xi, yi] represents a point on the X-Y plane, return the maximum number of points that lie on the same straight line.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: points = [[1,1],[2,2],[3,3]]\nOutput: 3\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: points = [[1,1],[3,2],[5,3],[4,1],[2,3],[1,4]]\nOutput: 4\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= points.length <= 300
    • \n\t
    • points[i].length == 2
    • \n\t
    • -104 <= xi, yi <= 104
    • \n\t
    • All the points are unique.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u7ef4\u5e73\u9762\uff0c\u5e73\u9762\u4e0a\u6709 \u4e2a\u70b9\uff0c\u6c42\u6700\u591a\u6709\u591a\u5c11\u4e2a\u70b9\u5728\u540c\u4e00\u6761\u76f4\u7ebf\u4e0a\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: [[1,1],[2,2],[3,3]]\n\u8f93\u51fa: 3\n\u89e3\u91ca:\n^\n|\n|        o\n|     o\n|  o  \n+------------->\n0  1  2  3  4\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: [[1,1],[3,2],[5,3],[4,1],[2,3],[1,4]]\n\u8f93\u51fa: 4\n\u89e3\u91ca:\n^\n|\n|  o\n|     o        o\n|        o\n|  o        o\n+------------------->\n0  1  2  3  4  5  6
    \n", "tags_en": ["Hash Table", "Math"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxPoints(vector>& points) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxPoints(int[][] points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxPoints(self, points):\n \"\"\"\n :type points: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxPoints(self, points: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxPoints(int** points, int pointsSize, int* pointsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxPoints(int[][] points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} points\n * @return {number}\n */\nvar maxPoints = function(points) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} points\n# @return {Integer}\ndef max_points(points)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxPoints(_ points: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxPoints(points [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxPoints(points: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxPoints(points: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_points(points: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $points\n * @return Integer\n */\n function maxPoints($points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxPoints(points: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-points points)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0149](https://leetcode-cn.com/problems/max-points-on-a-line)", "[\u76f4\u7ebf\u4e0a\u6700\u591a\u7684\u70b9\u6570](/solution/0100-0199/0149.Max%20Points%20on%20a%20Line/README.md)", "`\u54c8\u5e0c\u8868`,`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[0149](https://leetcode.com/problems/max-points-on-a-line)", "[Max Points on a Line](/solution/0100-0199/0149.Max%20Points%20on%20a%20Line/README_EN.md)", "`Hash Table`,`Math`", "Hard", ""]}, {"question_id": "0148", "frontend_question_id": "0148", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sort-list", "url_en": "https://leetcode.com/problems/sort-list", "relative_path_cn": "/solution/0100-0199/0148.Sort%20List/README.md", "relative_path_en": "/solution/0100-0199/0148.Sort%20List/README_EN.md", "title_cn": "\u6392\u5e8f\u94fe\u8868", "title_en": "Sort List", "question_title_slug": "sort-list", "content_en": "

    Given the head of a linked list, return the list after sorting it in ascending order.

    \n\n

    Follow up: Can you sort the linked list in O(n logn) time and O(1) memory (i.e. constant space)?

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: head = [4,2,1,3]\nOutput: [1,2,3,4]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: head = [-1,5,3,4,0]\nOutput: [-1,0,3,4,5]\n
    \n\n

    Example 3:

    \n\n
    \nInput: head = []\nOutput: []\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the list is in the range [0, 5 * 104].
    • \n\t
    • -105 <= Node.val <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u94fe\u8868\u7684\u5934\u7ed3\u70b9\u00a0head\u00a0\uff0c\u8bf7\u5c06\u5176\u6309 \u5347\u5e8f \u6392\u5217\u5e76\u8fd4\u56de \u6392\u5e8f\u540e\u7684\u94fe\u8868 \u3002

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u4f60\u53ef\u4ee5\u5728\u00a0O(n\u00a0log\u00a0n) \u65f6\u95f4\u590d\u6742\u5ea6\u548c\u5e38\u6570\u7ea7\u7a7a\u95f4\u590d\u6742\u5ea6\u4e0b\uff0c\u5bf9\u94fe\u8868\u8fdb\u884c\u6392\u5e8f\u5417\uff1f
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1ahead = [4,2,1,3]\n\u8f93\u51fa\uff1a[1,2,3,4]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1ahead = [-1,5,3,4,0]\n\u8f93\u51fa\uff1a[-1,0,3,4,5]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahead = []\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u94fe\u8868\u4e2d\u8282\u70b9\u7684\u6570\u76ee\u5728\u8303\u56f4\u00a0[0, 5 * 104]\u00a0\u5185
    • \n\t
    • -105\u00a0<= Node.val <= 105
    • \n
    \n", "tags_en": ["Sort", "Linked List"], "tags_cn": ["\u6392\u5e8f", "\u94fe\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n ListNode* sortList(ListNode* head) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public ListNode sortList(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def sortList(self, head):\n \"\"\"\n :type head: ListNode\n :rtype: ListNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def sortList(self, head: ListNode) -> ListNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nstruct ListNode* sortList(struct ListNode* head){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public ListNode SortList(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} head\n * @return {ListNode}\n */\nvar sortList = function(head) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode} head\n# @return {ListNode}\ndef sort_list(head)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func sortList(_ head: ListNode?) -> ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc sortList(head *ListNode) *ListNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def sortList(head: ListNode): ListNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun sortList(head: ListNode?): ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn sort_list(head: Option>) -> Option> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @return ListNode\n */\n function sortList($head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction sortList(head: ListNode | null): ListNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (sort-list head)\n (-> (or/c list-node? #f) (or/c list-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0148](https://leetcode-cn.com/problems/sort-list)", "[\u6392\u5e8f\u94fe\u8868](/solution/0100-0199/0148.Sort%20List/README.md)", "`\u6392\u5e8f`,`\u94fe\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0148](https://leetcode.com/problems/sort-list)", "[Sort List](/solution/0100-0199/0148.Sort%20List/README_EN.md)", "`Sort`,`Linked List`", "Medium", ""]}, {"question_id": "0147", "frontend_question_id": "0147", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/insertion-sort-list", "url_en": "https://leetcode.com/problems/insertion-sort-list", "relative_path_cn": "/solution/0100-0199/0147.Insertion%20Sort%20List/README.md", "relative_path_en": "/solution/0100-0199/0147.Insertion%20Sort%20List/README_EN.md", "title_cn": "\u5bf9\u94fe\u8868\u8fdb\u884c\u63d2\u5165\u6392\u5e8f", "title_en": "Insertion Sort List", "question_title_slug": "insertion-sort-list", "content_en": "

    Given the head of a singly linked list, sort the list using insertion sort, and return the sorted list's head.

    \n\n

    The steps of the insertion sort algorithm:

    \n\n
      \n\t
    1. Insertion sort iterates, consuming one input element each repetition and growing a sorted output list.
    2. \n\t
    3. At each iteration, insertion sort removes one element from the input data, finds the location it belongs within the sorted list and inserts it there.
    4. \n\t
    5. It repeats until no input elements remain.
    6. \n
    \n\n

    The following is a graphical example of the insertion sort algorithm. The partially sorted list (black) initially contains only the first element in the list. One element (red) is removed from the input data and inserted in-place into the sorted list with each iteration.

    \n\"\"\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: head = [4,2,1,3]\nOutput: [1,2,3,4]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: head = [-1,5,3,4,0]\nOutput: [-1,0,3,4,5]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the list is in the range [1, 5000].
    • \n\t
    • -5000 <= Node.val <= 5000
    • \n
    \n", "content_cn": "

    \u5bf9\u94fe\u8868\u8fdb\u884c\u63d2\u5165\u6392\u5e8f\u3002

    \n\n

    \"\"
    \n\u63d2\u5165\u6392\u5e8f\u7684\u52a8\u753b\u6f14\u793a\u5982\u4e0a\u3002\u4ece\u7b2c\u4e00\u4e2a\u5143\u7d20\u5f00\u59cb\uff0c\u8be5\u94fe\u8868\u53ef\u4ee5\u88ab\u8ba4\u4e3a\u5df2\u7ecf\u90e8\u5206\u6392\u5e8f\uff08\u7528\u9ed1\u8272\u8868\u793a\uff09\u3002
    \n\u6bcf\u6b21\u8fed\u4ee3\u65f6\uff0c\u4ece\u8f93\u5165\u6570\u636e\u4e2d\u79fb\u9664\u4e00\u4e2a\u5143\u7d20\uff08\u7528\u7ea2\u8272\u8868\u793a\uff09\uff0c\u5e76\u539f\u5730\u5c06\u5176\u63d2\u5165\u5230\u5df2\u6392\u597d\u5e8f\u7684\u94fe\u8868\u4e2d\u3002

    \n\n

     

    \n\n

    \u63d2\u5165\u6392\u5e8f\u7b97\u6cd5\uff1a

    \n\n
      \n\t
    1. \u63d2\u5165\u6392\u5e8f\u662f\u8fed\u4ee3\u7684\uff0c\u6bcf\u6b21\u53ea\u79fb\u52a8\u4e00\u4e2a\u5143\u7d20\uff0c\u76f4\u5230\u6240\u6709\u5143\u7d20\u53ef\u4ee5\u5f62\u6210\u4e00\u4e2a\u6709\u5e8f\u7684\u8f93\u51fa\u5217\u8868\u3002
    2. \n\t
    3. \u6bcf\u6b21\u8fed\u4ee3\u4e2d\uff0c\u63d2\u5165\u6392\u5e8f\u53ea\u4ece\u8f93\u5165\u6570\u636e\u4e2d\u79fb\u9664\u4e00\u4e2a\u5f85\u6392\u5e8f\u7684\u5143\u7d20\uff0c\u627e\u5230\u5b83\u5728\u5e8f\u5217\u4e2d\u9002\u5f53\u7684\u4f4d\u7f6e\uff0c\u5e76\u5c06\u5176\u63d2\u5165\u3002
    4. \n\t
    5. \u91cd\u590d\u76f4\u5230\u6240\u6709\u8f93\u5165\u6570\u636e\u63d2\u5165\u5b8c\u4e3a\u6b62\u3002
    6. \n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165: 4->2->1->3\n\u8f93\u51fa: 1->2->3->4\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165: -1->5->3->4->0\n\u8f93\u51fa: -1->0->3->4->5\n
    \n", "tags_en": ["Sort", "Linked List"], "tags_cn": ["\u6392\u5e8f", "\u94fe\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n ListNode* insertionSortList(ListNode* head) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public ListNode insertionSortList(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def insertionSortList(self, head):\n \"\"\"\n :type head: ListNode\n :rtype: ListNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def insertionSortList(self, head: ListNode) -> ListNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nstruct ListNode* insertionSortList(struct ListNode* head){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public ListNode InsertionSortList(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} head\n * @return {ListNode}\n */\nvar insertionSortList = function(head) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode} head\n# @return {ListNode}\ndef insertion_sort_list(head)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func insertionSortList(_ head: ListNode?) -> ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc insertionSortList(head *ListNode) *ListNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def insertionSortList(head: ListNode): ListNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun insertionSortList(head: ListNode?): ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn insertion_sort_list(head: Option>) -> Option> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @return ListNode\n */\n function insertionSortList($head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction insertionSortList(head: ListNode | null): ListNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (insertion-sort-list head)\n (-> (or/c list-node? #f) (or/c list-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0147](https://leetcode-cn.com/problems/insertion-sort-list)", "[\u5bf9\u94fe\u8868\u8fdb\u884c\u63d2\u5165\u6392\u5e8f](/solution/0100-0199/0147.Insertion%20Sort%20List/README.md)", "`\u6392\u5e8f`,`\u94fe\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0147](https://leetcode.com/problems/insertion-sort-list)", "[Insertion Sort List](/solution/0100-0199/0147.Insertion%20Sort%20List/README_EN.md)", "`Sort`,`Linked List`", "Medium", ""]}, {"question_id": "0146", "frontend_question_id": "0146", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/lru-cache", "url_en": "https://leetcode.com/problems/lru-cache", "relative_path_cn": "/solution/0100-0199/0146.LRU%20Cache/README.md", "relative_path_en": "/solution/0100-0199/0146.LRU%20Cache/README_EN.md", "title_cn": "LRU \u7f13\u5b58\u673a\u5236", "title_en": "LRU Cache", "question_title_slug": "lru-cache", "content_en": "

    Design a data structure that follows the constraints of a Least Recently Used (LRU) cache.

    \n\n

    Implement the LRUCache class:

    \n\n
      \n\t
    • LRUCache(int capacity) Initialize the LRU cache with positive size capacity.
    • \n\t
    • int get(int key) Return the value of the key if the key exists, otherwise return -1.
    • \n\t
    • void put(int key, int value) Update the value of the key if the key exists. Otherwise, add the key-value pair to the cache. If the number of keys exceeds the capacity from this operation, evict the least recently used key.
    • \n
    \n\n

    Follow up:
    \nCould you do get and put in O(1) time complexity?

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["LRUCache", "put", "put", "get", "put", "get", "put", "get", "get", "get"]\n[[2], [1, 1], [2, 2], [1], [3, 3], [2], [4, 4], [1], [3], [4]]\nOutput\n[null, null, null, 1, null, -1, null, -1, 3, 4]\n\nExplanation\nLRUCache lRUCache = new LRUCache(2);\nlRUCache.put(1, 1); // cache is {1=1}\nlRUCache.put(2, 2); // cache is {1=1, 2=2}\nlRUCache.get(1);    // return 1\nlRUCache.put(3, 3); // LRU key was 2, evicts key 2, cache is {1=1, 3=3}\nlRUCache.get(2);    // returns -1 (not found)\nlRUCache.put(4, 4); // LRU key was 1, evicts key 1, cache is {4=4, 3=3}\nlRUCache.get(1);    // return -1 (not found)\nlRUCache.get(3);    // return 3\nlRUCache.get(4);    // return 4\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= capacity <= 3000
    • \n\t
    • 0 <= key <= 3000
    • \n\t
    • 0 <= value <= 104
    • \n\t
    • At most 3 * 104 calls will be made to get and put.
    • \n
    \n", "content_cn": "
    \u8fd0\u7528\u4f60\u6240\u638c\u63e1\u7684\u6570\u636e\u7ed3\u6784\uff0c\u8bbe\u8ba1\u548c\u5b9e\u73b0\u4e00\u4e2a\u00a0 LRU (\u6700\u8fd1\u6700\u5c11\u4f7f\u7528) \u7f13\u5b58\u673a\u5236 \u3002
    \n\n
    \n
    \n

    \u5b9e\u73b0 LRUCache \u7c7b\uff1a

    \n\n
      \n\t
    • LRUCache(int capacity) \u4ee5\u6b63\u6574\u6570\u4f5c\u4e3a\u5bb9\u91cf\u00a0capacity \u521d\u59cb\u5316 LRU \u7f13\u5b58
    • \n\t
    • int get(int key) \u5982\u679c\u5173\u952e\u5b57 key \u5b58\u5728\u4e8e\u7f13\u5b58\u4e2d\uff0c\u5219\u8fd4\u56de\u5173\u952e\u5b57\u7684\u503c\uff0c\u5426\u5219\u8fd4\u56de -1 \u3002
    • \n\t
    • void put(int key, int value)\u00a0\u5982\u679c\u5173\u952e\u5b57\u5df2\u7ecf\u5b58\u5728\uff0c\u5219\u53d8\u66f4\u5176\u6570\u636e\u503c\uff1b\u5982\u679c\u5173\u952e\u5b57\u4e0d\u5b58\u5728\uff0c\u5219\u63d2\u5165\u8be5\u7ec4\u300c\u5173\u952e\u5b57-\u503c\u300d\u3002\u5f53\u7f13\u5b58\u5bb9\u91cf\u8fbe\u5230\u4e0a\u9650\u65f6\uff0c\u5b83\u5e94\u8be5\u5728\u5199\u5165\u65b0\u6570\u636e\u4e4b\u524d\u5220\u9664\u6700\u4e45\u672a\u4f7f\u7528\u7684\u6570\u636e\u503c\uff0c\u4ece\u800c\u4e3a\u65b0\u7684\u6570\u636e\u503c\u7559\u51fa\u7a7a\u95f4\u3002
    • \n
    \n\n

    \u00a0

    \n
    \n
    \n\n

    \u8fdb\u9636\uff1a\u4f60\u662f\u5426\u53ef\u4ee5\u5728\u00a0O(1) \u65f6\u95f4\u590d\u6742\u5ea6\u5185\u5b8c\u6210\u8fd9\u4e24\u79cd\u64cd\u4f5c\uff1f

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\n[\"LRUCache\", \"put\", \"put\", \"get\", \"put\", \"get\", \"put\", \"get\", \"get\", \"get\"]\n[[2], [1, 1], [2, 2], [1], [3, 3], [2], [4, 4], [1], [3], [4]]\n\u8f93\u51fa\n[null, null, null, 1, null, -1, null, -1, 3, 4]\n\n\u89e3\u91ca\nLRUCache lRUCache = new LRUCache(2);\nlRUCache.put(1, 1); // \u7f13\u5b58\u662f {1=1}\nlRUCache.put(2, 2); // \u7f13\u5b58\u662f {1=1, 2=2}\nlRUCache.get(1);    // \u8fd4\u56de 1\nlRUCache.put(3, 3); // \u8be5\u64cd\u4f5c\u4f1a\u4f7f\u5f97\u5173\u952e\u5b57 2 \u4f5c\u5e9f\uff0c\u7f13\u5b58\u662f {1=1, 3=3}\nlRUCache.get(2);    // \u8fd4\u56de -1 (\u672a\u627e\u5230)\nlRUCache.put(4, 4); // \u8be5\u64cd\u4f5c\u4f1a\u4f7f\u5f97\u5173\u952e\u5b57 1 \u4f5c\u5e9f\uff0c\u7f13\u5b58\u662f {4=4, 3=3}\nlRUCache.get(1);    // \u8fd4\u56de -1 (\u672a\u627e\u5230)\nlRUCache.get(3);    // \u8fd4\u56de 3\nlRUCache.get(4);    // \u8fd4\u56de 4\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= capacity <= 3000
    • \n\t
    • 0 <= key <= 3000
    • \n\t
    • 0 <= value <= 104
    • \n\t
    • \u6700\u591a\u8c03\u7528 3 * 104 \u6b21 get \u548c put
    • \n
    \n", "tags_en": ["Design"], "tags_cn": ["\u8bbe\u8ba1"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class LRUCache {\npublic:\n LRUCache(int capacity) {\n\n }\n \n int get(int key) {\n\n }\n \n void put(int key, int value) {\n\n }\n};\n\n/**\n * Your LRUCache object will be instantiated and called as such:\n * LRUCache* obj = new LRUCache(capacity);\n * int param_1 = obj->get(key);\n * obj->put(key,value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class LRUCache {\n\n public LRUCache(int capacity) {\n\n }\n \n public int get(int key) {\n\n }\n \n public void put(int key, int value) {\n\n }\n}\n\n/**\n * Your LRUCache object will be instantiated and called as such:\n * LRUCache obj = new LRUCache(capacity);\n * int param_1 = obj.get(key);\n * obj.put(key,value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class LRUCache(object):\n\n def __init__(self, capacity):\n \"\"\"\n :type capacity: int\n \"\"\"\n\n\n def get(self, key):\n \"\"\"\n :type key: int\n :rtype: int\n \"\"\"\n\n\n def put(self, key, value):\n \"\"\"\n :type key: int\n :type value: int\n :rtype: None\n \"\"\"\n\n\n\n# Your LRUCache object will be instantiated and called as such:\n# obj = LRUCache(capacity)\n# param_1 = obj.get(key)\n# obj.put(key,value)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class LRUCache:\n\n def __init__(self, capacity: int):\n\n\n def get(self, key: int) -> int:\n\n\n def put(self, key: int, value: int) -> None:\n\n\n\n# Your LRUCache object will be instantiated and called as such:\n# obj = LRUCache(capacity)\n# param_1 = obj.get(key)\n# obj.put(key,value)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} LRUCache;\n\n\nLRUCache* lRUCacheCreate(int capacity) {\n\n}\n\nint lRUCacheGet(LRUCache* obj, int key) {\n\n}\n\nvoid lRUCachePut(LRUCache* obj, int key, int value) {\n\n}\n\nvoid lRUCacheFree(LRUCache* obj) {\n\n}\n\n/**\n * Your LRUCache struct will be instantiated and called as such:\n * LRUCache* obj = lRUCacheCreate(capacity);\n * int param_1 = lRUCacheGet(obj, key);\n \n * lRUCachePut(obj, key, value);\n \n * lRUCacheFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class LRUCache {\n\n public LRUCache(int capacity) {\n\n }\n \n public int Get(int key) {\n\n }\n \n public void Put(int key, int value) {\n\n }\n}\n\n/**\n * Your LRUCache object will be instantiated and called as such:\n * LRUCache obj = new LRUCache(capacity);\n * int param_1 = obj.Get(key);\n * obj.Put(key,value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} capacity\n */\nvar LRUCache = function(capacity) {\n\n};\n\n/** \n * @param {number} key\n * @return {number}\n */\nLRUCache.prototype.get = function(key) {\n\n};\n\n/** \n * @param {number} key \n * @param {number} value\n * @return {void}\n */\nLRUCache.prototype.put = function(key, value) {\n\n};\n\n/**\n * Your LRUCache object will be instantiated and called as such:\n * var obj = new LRUCache(capacity)\n * var param_1 = obj.get(key)\n * obj.put(key,value)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class LRUCache\n\n=begin\n :type capacity: Integer\n=end\n def initialize(capacity)\n\n end\n\n\n=begin\n :type key: Integer\n :rtype: Integer\n=end\n def get(key)\n\n end\n\n\n=begin\n :type key: Integer\n :type value: Integer\n :rtype: Void\n=end\n def put(key, value)\n\n end\n\n\nend\n\n# Your LRUCache object will be instantiated and called as such:\n# obj = LRUCache.new(capacity)\n# param_1 = obj.get(key)\n# obj.put(key, value)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass LRUCache {\n\n init(_ capacity: Int) {\n\n }\n \n func get(_ key: Int) -> Int {\n\n }\n \n func put(_ key: Int, _ value: Int) {\n\n }\n}\n\n/**\n * Your LRUCache object will be instantiated and called as such:\n * let obj = LRUCache(capacity)\n * let ret_1: Int = obj.get(key)\n * obj.put(key, value)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type LRUCache struct {\n\n}\n\n\nfunc Constructor(capacity int) LRUCache {\n\n}\n\n\nfunc (this *LRUCache) Get(key int) int {\n\n}\n\n\nfunc (this *LRUCache) Put(key int, value int) {\n\n}\n\n\n/**\n * Your LRUCache object will be instantiated and called as such:\n * obj := Constructor(capacity);\n * param_1 := obj.Get(key);\n * obj.Put(key,value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class LRUCache(_capacity: Int) {\n\n def get(key: Int): Int = {\n\n }\n\n def put(key: Int, value: Int) {\n\n }\n\n}\n\n/**\n * Your LRUCache object will be instantiated and called as such:\n * var obj = new LRUCache(capacity)\n * var param_1 = obj.get(key)\n * obj.put(key,value)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class LRUCache(capacity: Int) {\n\n fun get(key: Int): Int {\n\n }\n\n fun put(key: Int, value: Int) {\n\n }\n\n}\n\n/**\n * Your LRUCache object will be instantiated and called as such:\n * var obj = LRUCache(capacity)\n * var param_1 = obj.get(key)\n * obj.put(key,value)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct LRUCache {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl LRUCache {\n\n fn new(capacity: i32) -> Self {\n\n }\n \n fn get(&self, key: i32) -> i32 {\n\n }\n \n fn put(&self, key: i32, value: i32) {\n\n }\n}\n\n/**\n * Your LRUCache object will be instantiated and called as such:\n * let obj = LRUCache::new(capacity);\n * let ret_1: i32 = obj.get(key);\n * obj.put(key, value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class LRUCache {\n /**\n * @param Integer $capacity\n */\n function __construct($capacity) {\n\n }\n\n /**\n * @param Integer $key\n * @return Integer\n */\n function get($key) {\n\n }\n\n /**\n * @param Integer $key\n * @param Integer $value\n * @return NULL\n */\n function put($key, $value) {\n\n }\n}\n\n/**\n * Your LRUCache object will be instantiated and called as such:\n * $obj = LRUCache($capacity);\n * $ret_1 = $obj->get($key);\n * $obj->put($key, $value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class LRUCache {\n constructor(capacity: number) {\n\n }\n\n get(key: number): number {\n\n }\n\n put(key: number, value: number): void {\n\n }\n}\n\n/**\n * Your LRUCache object will be instantiated and called as such:\n * var obj = new LRUCache(capacity)\n * var param_1 = obj.get(key)\n * obj.put(key,value)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define lru-cache%\n (class object%\n (super-new)\n\n ; capacity : exact-integer?\n (init-field\n capacity)\n \n ; get : exact-integer? -> exact-integer?\n (define/public (get key)\n\n )\n ; put : exact-integer? exact-integer? -> void?\n (define/public (put key value)\n\n )))\n\n;; Your lru-cache% object will be instantiated and called as such:\n;; (define obj (new lru-cache% [capacity capacity]))\n;; (define param_1 (send obj get key))\n;; (send obj put key value)", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0146](https://leetcode-cn.com/problems/lru-cache)", "[LRU \u7f13\u5b58\u673a\u5236](/solution/0100-0199/0146.LRU%20Cache/README.md)", "`\u8bbe\u8ba1`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0146](https://leetcode.com/problems/lru-cache)", "[LRU Cache](/solution/0100-0199/0146.LRU%20Cache/README_EN.md)", "`Design`", "Medium", ""]}, {"question_id": "0145", "frontend_question_id": "0145", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/binary-tree-postorder-traversal", "url_en": "https://leetcode.com/problems/binary-tree-postorder-traversal", "relative_path_cn": "/solution/0100-0199/0145.Binary%20Tree%20Postorder%20Traversal/README.md", "relative_path_en": "/solution/0100-0199/0145.Binary%20Tree%20Postorder%20Traversal/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u7684\u540e\u5e8f\u904d\u5386", "title_en": "Binary Tree Postorder Traversal", "question_title_slug": "binary-tree-postorder-traversal", "content_en": "

    Given the root of a binary tree, return the postorder traversal of its nodes' values.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,null,2,3]\nOutput: [3,2,1]\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = []\nOutput: []\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = [1]\nOutput: [1]\n
    \n\n

    Example 4:

    \n\"\"\n
    \nInput: root = [1,2]\nOutput: [2,1]\n
    \n\n

    Example 5:

    \n\"\"\n
    \nInput: root = [1,null,2]\nOutput: [2,1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of the nodes in the tree is in the range [0, 100].
    • \n\t
    • -100 <= Node.val <= 100
    • \n
    \n\n

     

    \nFollow up: Recursive solution is trivial, could you do it iteratively?", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811\uff0c\u8fd4\u56de\u5b83\u7684 \u540e\u5e8f \u904d\u5386\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: [1,null,2,3]  \n   1\n    \\\n     2\n    /\n   3 \n\n\u8f93\u51fa: [3,2,1]
    \n\n

    \u8fdb\u9636: \u9012\u5f52\u7b97\u6cd5\u5f88\u7b80\u5355\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u8fed\u4ee3\u7b97\u6cd5\u5b8c\u6210\u5417\uff1f

    \n", "tags_en": ["Stack", "Tree"], "tags_cn": ["\u6808", "\u6811"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector postorderTraversal(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public List postorderTraversal(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def postorderTraversal(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def postorderTraversal(self, root: TreeNode) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* postorderTraversal(struct TreeNode* root, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public IList PostorderTraversal(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number[]}\n */\nvar postorderTraversal = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer[]}\ndef postorder_traversal(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func postorderTraversal(_ root: TreeNode?) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc postorderTraversal(root *TreeNode) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def postorderTraversal(root: TreeNode): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun postorderTraversal(root: TreeNode?): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn postorder_traversal(root: Option>>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer[]\n */\n function postorderTraversal($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction postorderTraversal(root: TreeNode | null): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (postorder-traversal root)\n (-> (or/c tree-node? #f) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0145](https://leetcode-cn.com/problems/binary-tree-postorder-traversal)", "[\u4e8c\u53c9\u6811\u7684\u540e\u5e8f\u904d\u5386](/solution/0100-0199/0145.Binary%20Tree%20Postorder%20Traversal/README.md)", "`\u6808`,`\u6811`", "\u7b80\u5355", ""], "md_table_row_en": ["[0145](https://leetcode.com/problems/binary-tree-postorder-traversal)", "[Binary Tree Postorder Traversal](/solution/0100-0199/0145.Binary%20Tree%20Postorder%20Traversal/README_EN.md)", "`Stack`,`Tree`", "Easy", ""]}, {"question_id": "0144", "frontend_question_id": "0144", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/binary-tree-preorder-traversal", "url_en": "https://leetcode.com/problems/binary-tree-preorder-traversal", "relative_path_cn": "/solution/0100-0199/0144.Binary%20Tree%20Preorder%20Traversal/README.md", "relative_path_en": "/solution/0100-0199/0144.Binary%20Tree%20Preorder%20Traversal/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u7684\u524d\u5e8f\u904d\u5386", "title_en": "Binary Tree Preorder Traversal", "question_title_slug": "binary-tree-preorder-traversal", "content_en": "

    Given the root of a binary tree, return the preorder traversal of its nodes' values.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,null,2,3]\nOutput: [1,2,3]\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = []\nOutput: []\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = [1]\nOutput: [1]\n
    \n\n

    Example 4:

    \n\"\"\n
    \nInput: root = [1,2]\nOutput: [1,2]\n
    \n\n

    Example 5:

    \n\"\"\n
    \nInput: root = [1,null,2]\nOutput: [1,2]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [0, 100].
    • \n\t
    • -100 <= Node.val <= 100
    • \n
    \n\n

     

    \n

    Follow up: Recursive solution is trivial, could you do it iteratively?

    \n", "content_cn": "

    \u7ed9\u4f60\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9 root \uff0c\u8fd4\u56de\u5b83\u8282\u70b9\u503c\u7684\u00a0\u524d\u5e8f\u00a0\u904d\u5386\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [1,null,2,3]\n\u8f93\u51fa\uff1a[1,2,3]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = []\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [1]\n\u8f93\u51fa\uff1a[1]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [1,2]\n\u8f93\u51fa\uff1a[1,2]\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [1,null,2]\n\u8f93\u51fa\uff1a[1,2]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u6570\u76ee\u5728\u8303\u56f4 [0, 100] \u5185
    • \n\t
    • -100 <= Node.val <= 100
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u9012\u5f52\u7b97\u6cd5\u5f88\u7b80\u5355\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u8fed\u4ee3\u7b97\u6cd5\u5b8c\u6210\u5417\uff1f

    \n", "tags_en": ["Stack", "Tree"], "tags_cn": ["\u6808", "\u6811"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector preorderTraversal(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public List preorderTraversal(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def preorderTraversal(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def preorderTraversal(self, root: TreeNode) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* preorderTraversal(struct TreeNode* root, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public IList PreorderTraversal(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number[]}\n */\nvar preorderTraversal = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer[]}\ndef preorder_traversal(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func preorderTraversal(_ root: TreeNode?) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc preorderTraversal(root *TreeNode) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def preorderTraversal(root: TreeNode): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun preorderTraversal(root: TreeNode?): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn preorder_traversal(root: Option>>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer[]\n */\n function preorderTraversal($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction preorderTraversal(root: TreeNode | null): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (preorder-traversal root)\n (-> (or/c tree-node? #f) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0144](https://leetcode-cn.com/problems/binary-tree-preorder-traversal)", "[\u4e8c\u53c9\u6811\u7684\u524d\u5e8f\u904d\u5386](/solution/0100-0199/0144.Binary%20Tree%20Preorder%20Traversal/README.md)", "`\u6808`,`\u6811`", "\u7b80\u5355", ""], "md_table_row_en": ["[0144](https://leetcode.com/problems/binary-tree-preorder-traversal)", "[Binary Tree Preorder Traversal](/solution/0100-0199/0144.Binary%20Tree%20Preorder%20Traversal/README_EN.md)", "`Stack`,`Tree`", "Easy", ""]}, {"question_id": "0143", "frontend_question_id": "0143", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reorder-list", "url_en": "https://leetcode.com/problems/reorder-list", "relative_path_cn": "/solution/0100-0199/0143.Reorder%20List/README.md", "relative_path_en": "/solution/0100-0199/0143.Reorder%20List/README_EN.md", "title_cn": "\u91cd\u6392\u94fe\u8868", "title_en": "Reorder List", "question_title_slug": "reorder-list", "content_en": "

    You are given the head of a singly linked-list. The list can be represented as:

    \n\n
    \nL0 → L1 → … → Ln - 1 → Ln\n
    \n\n

    Reorder the list to be on the following form:

    \n\n
    \nL0 → Ln → L1 → Ln - 1 → L2 → Ln - 2 → …\n
    \n\n

    You may not modify the values in the list's nodes. Only nodes themselves may be changed.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: head = [1,2,3,4]\nOutput: [1,4,2,3]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: head = [1,2,3,4,5]\nOutput: [1,5,2,4,3]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the list is in the range [1, 5 * 104].
    • \n\t
    • 1 <= Node.val <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5355\u94fe\u8868 L\uff1aL0L1→…→Ln-1Ln \uff0c
    \n\u5c06\u5176\u91cd\u65b0\u6392\u5217\u540e\u53d8\u4e3a\uff1a L0LnL1Ln-1L2Ln-2→…

    \n\n

    \u4f60\u4e0d\u80fd\u53ea\u662f\u5355\u7eaf\u7684\u6539\u53d8\u8282\u70b9\u5185\u90e8\u7684\u503c\uff0c\u800c\u662f\u9700\u8981\u5b9e\u9645\u7684\u8fdb\u884c\u8282\u70b9\u4ea4\u6362\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u7ed9\u5b9a\u94fe\u8868 1->2->3->4, \u91cd\u65b0\u6392\u5217\u4e3a 1->4->2->3.
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u7ed9\u5b9a\u94fe\u8868 1->2->3->4->5, \u91cd\u65b0\u6392\u5217\u4e3a 1->5->2->4->3.
    \n", "tags_en": ["Linked List"], "tags_cn": ["\u94fe\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n void reorderList(ListNode* head) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public void reorderList(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def reorderList(self, head):\n \"\"\"\n :type head: ListNode\n :rtype: None Do not return anything, modify head in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def reorderList(self, head: ListNode) -> None:\n \"\"\"\n Do not return anything, modify head in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nvoid reorderList(struct ListNode* head){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public void ReorderList(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} head\n * @return {void} Do not return anything, modify head in-place instead.\n */\nvar reorderList = function(head) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode} head\n# @return {Void} Do not return anything, modify head in-place instead.\ndef reorder_list(head)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func reorderList(_ head: ListNode?) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc reorderList(head *ListNode) {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def reorderList(head: ListNode): Unit = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun reorderList(head: ListNode?): Unit {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn reorder_list(head: &mut Option>) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @return NULL\n */\n function reorderList($head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\n/**\n Do not return anything, modify head in-place instead.\n */\nfunction reorderList(head: ListNode | null): void {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (reorder-list head)\n (-> (or/c list-node? #f) void?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0143](https://leetcode-cn.com/problems/reorder-list)", "[\u91cd\u6392\u94fe\u8868](/solution/0100-0199/0143.Reorder%20List/README.md)", "`\u94fe\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0143](https://leetcode.com/problems/reorder-list)", "[Reorder List](/solution/0100-0199/0143.Reorder%20List/README_EN.md)", "`Linked List`", "Medium", ""]}, {"question_id": "0142", "frontend_question_id": "0142", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/linked-list-cycle-ii", "url_en": "https://leetcode.com/problems/linked-list-cycle-ii", "relative_path_cn": "/solution/0100-0199/0142.Linked%20List%20Cycle%20II/README.md", "relative_path_en": "/solution/0100-0199/0142.Linked%20List%20Cycle%20II/README_EN.md", "title_cn": "\u73af\u5f62\u94fe\u8868 II", "title_en": "Linked List Cycle II", "question_title_slug": "linked-list-cycle-ii", "content_en": "

    Given a linked list, return the node where the cycle begins. If there is no cycle, return null.

    \n\n

    There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the next pointer. Internally, pos is used to denote the index of the node that tail's next pointer is connected to. Note that pos is not passed as a parameter.

    \n\n

    Notice that you should not modify the linked list.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: head = [3,2,0,-4], pos = 1\nOutput: tail connects to node index 1\nExplanation: There is a cycle in the linked list, where tail connects to the second node.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: head = [1,2], pos = 0\nOutput: tail connects to node index 0\nExplanation: There is a cycle in the linked list, where tail connects to the first node.\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: head = [1], pos = -1\nOutput: no cycle\nExplanation: There is no cycle in the linked list.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of the nodes in the list is in the range [0, 104].
    • \n\t
    • -105 <= Node.val <= 105
    • \n\t
    • pos is -1 or a valid index in the linked-list.
    • \n
    \n\n

     

    \n

    Follow up: Can you solve it using O(1) (i.e. constant) memory?

    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u94fe\u8868\uff0c\u8fd4\u56de\u94fe\u8868\u5f00\u59cb\u5165\u73af\u7684\u7b2c\u4e00\u4e2a\u8282\u70b9\u3002\u00a0\u5982\u679c\u94fe\u8868\u65e0\u73af\uff0c\u5219\u8fd4\u56de\u00a0null\u3002

    \n\n

    \u4e3a\u4e86\u8868\u793a\u7ed9\u5b9a\u94fe\u8868\u4e2d\u7684\u73af\uff0c\u6211\u4eec\u4f7f\u7528\u6574\u6570 pos \u6765\u8868\u793a\u94fe\u8868\u5c3e\u8fde\u63a5\u5230\u94fe\u8868\u4e2d\u7684\u4f4d\u7f6e\uff08\u7d22\u5f15\u4ece 0 \u5f00\u59cb\uff09\u3002 \u5982\u679c pos \u662f -1\uff0c\u5219\u5728\u8be5\u94fe\u8868\u4e2d\u6ca1\u6709\u73af\u3002\u6ce8\u610f\uff0cpos \u4ec5\u4ec5\u662f\u7528\u4e8e\u6807\u8bc6\u73af\u7684\u60c5\u51b5\uff0c\u5e76\u4e0d\u4f1a\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u5230\u51fd\u6570\u4e2d\u3002

    \n\n

    \u8bf4\u660e\uff1a\u4e0d\u5141\u8bb8\u4fee\u6539\u7ed9\u5b9a\u7684\u94fe\u8868\u3002

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u4f60\u662f\u5426\u53ef\u4ee5\u4f7f\u7528 O(1) \u7a7a\u95f4\u89e3\u51b3\u6b64\u9898\uff1f
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1ahead = [3,2,0,-4], pos = 1\n\u8f93\u51fa\uff1a\u8fd4\u56de\u7d22\u5f15\u4e3a 1 \u7684\u94fe\u8868\u8282\u70b9\n\u89e3\u91ca\uff1a\u94fe\u8868\u4e2d\u6709\u4e00\u4e2a\u73af\uff0c\u5176\u5c3e\u90e8\u8fde\u63a5\u5230\u7b2c\u4e8c\u4e2a\u8282\u70b9\u3002\n
    \n\n

    \u793a\u4f8b\u00a02\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1ahead = [1,2], pos = 0\n\u8f93\u51fa\uff1a\u8fd4\u56de\u7d22\u5f15\u4e3a 0 \u7684\u94fe\u8868\u8282\u70b9\n\u89e3\u91ca\uff1a\u94fe\u8868\u4e2d\u6709\u4e00\u4e2a\u73af\uff0c\u5176\u5c3e\u90e8\u8fde\u63a5\u5230\u7b2c\u4e00\u4e2a\u8282\u70b9\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1ahead = [1], pos = -1\n\u8f93\u51fa\uff1a\u8fd4\u56de null\n\u89e3\u91ca\uff1a\u94fe\u8868\u4e2d\u6ca1\u6709\u73af\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u94fe\u8868\u4e2d\u8282\u70b9\u7684\u6570\u76ee\u8303\u56f4\u5728\u8303\u56f4 [0, 104] \u5185
    • \n\t
    • -105 <= Node.val <= 105
    • \n\t
    • pos \u7684\u503c\u4e3a -1 \u6216\u8005\u94fe\u8868\u4e2d\u7684\u4e00\u4e2a\u6709\u6548\u7d22\u5f15
    • \n
    \n", "tags_en": ["Linked List", "Two Pointers"], "tags_cn": ["\u94fe\u8868", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\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 ListNode *detectCycle(ListNode *head) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * int val;\n * ListNode next;\n * ListNode(int x) {\n * val = x;\n * next = null;\n * }\n * }\n */\npublic class Solution {\n public ListNode detectCycle(ListNode head) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.next = None\n\nclass Solution(object):\n def detectCycle(self, head):\n \"\"\"\n :type head: ListNode\n :rtype: ListNode\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, x):\n# self.val = x\n# self.next = None\n\nclass Solution:\n def detectCycle(self, head: ListNode) -> ListNode:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\nstruct ListNode *detectCycle(struct ListNode *head) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int x) {\n * val = x;\n * next = null;\n * }\n * }\n */\npublic class Solution {\n public ListNode DetectCycle(ListNode head) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val) {\n * this.val = val;\n * this.next = null;\n * }\n */\n\n/**\n * @param {ListNode} head\n * @return {ListNode}\n */\nvar detectCycle = function(head) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val)\n# @val = val\n# @next = nil\n# end\n# end\n\n# @param {ListNode} head\n# @return {ListNode}\ndef detectCycle(head)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.next = nil\n * }\n * }\n */\n\nclass Solution {\n func detectCycle(_ head: ListNode?) -> ListNode? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc detectCycle(head *ListNode) *ListNode {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(var _x: Int = 0) {\n * var next: ListNode = null\n * var x: Int = _x\n * }\n */\n\nobject Solution {\n def detectCycle(head: ListNode): ListNode = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\n\nclass Solution {\n fun detectCycle(head: ListNode?): ListNode? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val) { $this->val = $val; }\n * }\n */\n\nclass Solution {\n /**\n * @param ListNode $head\n * @return ListNode\n */\n function detectCycle($head) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction detectCycle(head: ListNode | null): ListNode | null {\n \n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0142](https://leetcode-cn.com/problems/linked-list-cycle-ii)", "[\u73af\u5f62\u94fe\u8868 II](/solution/0100-0199/0142.Linked%20List%20Cycle%20II/README.md)", "`\u94fe\u8868`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0142](https://leetcode.com/problems/linked-list-cycle-ii)", "[Linked List Cycle II](/solution/0100-0199/0142.Linked%20List%20Cycle%20II/README_EN.md)", "`Linked List`,`Two Pointers`", "Medium", ""]}, {"question_id": "0141", "frontend_question_id": "0141", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/linked-list-cycle", "url_en": "https://leetcode.com/problems/linked-list-cycle", "relative_path_cn": "/solution/0100-0199/0141.Linked%20List%20Cycle/README.md", "relative_path_en": "/solution/0100-0199/0141.Linked%20List%20Cycle/README_EN.md", "title_cn": "\u73af\u5f62\u94fe\u8868", "title_en": "Linked List Cycle", "question_title_slug": "linked-list-cycle", "content_en": "

    Given head, the head of a linked list, determine if the linked list has a cycle in it.

    \n\n

    There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the next pointer. Internally, pos is used to denote the index of the node that tail's next pointer is connected to. Note that pos is not passed as a parameter.

    \n\n

    Return true if there is a cycle in the linked list. Otherwise, return false.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: head = [3,2,0,-4], pos = 1\nOutput: true\nExplanation: There is a cycle in the linked list, where the tail connects to the 1st node (0-indexed).\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: head = [1,2], pos = 0\nOutput: true\nExplanation: There is a cycle in the linked list, where the tail connects to the 0th node.\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: head = [1], pos = -1\nOutput: false\nExplanation: There is no cycle in the linked list.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of the nodes in the list is in the range [0, 104].
    • \n\t
    • -105 <= Node.val <= 105
    • \n\t
    • pos is -1 or a valid index in the linked-list.
    • \n
    \n\n

     

    \n

    Follow up: Can you solve it using O(1) (i.e. constant) memory?

    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u94fe\u8868\uff0c\u5224\u65ad\u94fe\u8868\u4e2d\u662f\u5426\u6709\u73af\u3002

    \n\n

    \u5982\u679c\u94fe\u8868\u4e2d\u6709\u67d0\u4e2a\u8282\u70b9\uff0c\u53ef\u4ee5\u901a\u8fc7\u8fde\u7eed\u8ddf\u8e2a next \u6307\u9488\u518d\u6b21\u5230\u8fbe\uff0c\u5219\u94fe\u8868\u4e2d\u5b58\u5728\u73af\u3002 \u4e3a\u4e86\u8868\u793a\u7ed9\u5b9a\u94fe\u8868\u4e2d\u7684\u73af\uff0c\u6211\u4eec\u4f7f\u7528\u6574\u6570 pos \u6765\u8868\u793a\u94fe\u8868\u5c3e\u8fde\u63a5\u5230\u94fe\u8868\u4e2d\u7684\u4f4d\u7f6e\uff08\u7d22\u5f15\u4ece 0 \u5f00\u59cb\uff09\u3002 \u5982\u679c pos \u662f -1\uff0c\u5219\u5728\u8be5\u94fe\u8868\u4e2d\u6ca1\u6709\u73af\u3002\u6ce8\u610f\uff1apos \u4e0d\u4f5c\u4e3a\u53c2\u6570\u8fdb\u884c\u4f20\u9012\uff0c\u4ec5\u4ec5\u662f\u4e3a\u4e86\u6807\u8bc6\u94fe\u8868\u7684\u5b9e\u9645\u60c5\u51b5\u3002

    \n\n

    \u5982\u679c\u94fe\u8868\u4e2d\u5b58\u5728\u73af\uff0c\u5219\u8fd4\u56de true \u3002 \u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n

     

    \n\n

    \u8fdb\u9636\uff1a

    \n\n

    \u4f60\u80fd\u7528 O(1)\uff08\u5373\uff0c\u5e38\u91cf\uff09\u5185\u5b58\u89e3\u51b3\u6b64\u95ee\u9898\u5417\uff1f

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1ahead = [3,2,0,-4], pos = 1\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u94fe\u8868\u4e2d\u6709\u4e00\u4e2a\u73af\uff0c\u5176\u5c3e\u90e8\u8fde\u63a5\u5230\u7b2c\u4e8c\u4e2a\u8282\u70b9\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1ahead = [1,2], pos = 0\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u94fe\u8868\u4e2d\u6709\u4e00\u4e2a\u73af\uff0c\u5176\u5c3e\u90e8\u8fde\u63a5\u5230\u7b2c\u4e00\u4e2a\u8282\u70b9\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1ahead = [1], pos = -1\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u94fe\u8868\u4e2d\u6ca1\u6709\u73af\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u94fe\u8868\u4e2d\u8282\u70b9\u7684\u6570\u76ee\u8303\u56f4\u662f [0, 104]
    • \n\t
    • -105 <= Node.val <= 105
    • \n\t
    • pos \u4e3a -1 \u6216\u8005\u94fe\u8868\u4e2d\u7684\u4e00\u4e2a \u6709\u6548\u7d22\u5f15 \u3002
    • \n
    \n", "tags_en": ["Linked List", "Two Pointers"], "tags_cn": ["\u94fe\u8868", "\u53cc\u6307\u9488"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\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 bool hasCycle(ListNode *head) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * int val;\n * ListNode next;\n * ListNode(int x) {\n * val = x;\n * next = null;\n * }\n * }\n */\npublic class Solution {\n public boolean hasCycle(ListNode head) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.next = None\n\nclass Solution(object):\n def hasCycle(self, head):\n \"\"\"\n :type head: ListNode\n :rtype: bool\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, x):\n# self.val = x\n# self.next = None\n\nclass Solution:\n def hasCycle(self, head: ListNode) -> bool:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\nbool hasCycle(struct ListNode *head) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int x) {\n * val = x;\n * next = null;\n * }\n * }\n */\npublic class Solution {\n public bool HasCycle(ListNode head) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val) {\n * this.val = val;\n * this.next = null;\n * }\n */\n\n/**\n * @param {ListNode} head\n * @return {boolean}\n */\nvar hasCycle = function(head) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val)\n# @val = val\n# @next = nil\n# end\n# end\n\n# @param {ListNode} head\n# @return {Boolean}\ndef hasCycle(head)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.next = nil\n * }\n * }\n */\n\nclass Solution {\n func hasCycle(_ head: ListNode?) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc hasCycle(head *ListNode) bool {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(var _x: Int = 0) {\n * var next: ListNode = null\n * var x: Int = _x\n * }\n */\n\nobject Solution {\n def hasCycle(head: ListNode): Boolean = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\n\nclass Solution {\n fun hasCycle(head: ListNode?): Boolean {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val) { $this->val = $val; }\n * }\n */\n\nclass Solution {\n /**\n * @param ListNode $head\n * @return Boolean\n */\n function hasCycle($head) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction hasCycle(head: ListNode | null): boolean {\n \n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0141](https://leetcode-cn.com/problems/linked-list-cycle)", "[\u73af\u5f62\u94fe\u8868](/solution/0100-0199/0141.Linked%20List%20Cycle/README.md)", "`\u94fe\u8868`,`\u53cc\u6307\u9488`", "\u7b80\u5355", ""], "md_table_row_en": ["[0141](https://leetcode.com/problems/linked-list-cycle)", "[Linked List Cycle](/solution/0100-0199/0141.Linked%20List%20Cycle/README_EN.md)", "`Linked List`,`Two Pointers`", "Easy", ""]}, {"question_id": "0140", "frontend_question_id": "0140", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/word-break-ii", "url_en": "https://leetcode.com/problems/word-break-ii", "relative_path_cn": "/solution/0100-0199/0140.Word%20Break%20II/README.md", "relative_path_en": "/solution/0100-0199/0140.Word%20Break%20II/README_EN.md", "title_cn": "\u5355\u8bcd\u62c6\u5206 II", "title_en": "Word Break II", "question_title_slug": "word-break-ii", "content_en": "

    Given a string s and a dictionary of strings wordDict, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible sentences in any order.

    \n\n

    Note that the same word in the dictionary may be reused multiple times in the segmentation.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "catsanddog", wordDict = ["cat","cats","and","sand","dog"]\nOutput: ["cats and dog","cat sand dog"]\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "pineapplepenapple", wordDict = ["apple","pen","applepen","pine","pineapple"]\nOutput: ["pine apple pen apple","pineapple pen apple","pine applepen apple"]\nExplanation: Note that you are allowed to reuse a dictionary word.\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "catsandog", wordDict = ["cats","dog","sand","and","cat"]\nOutput: []\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 20
    • \n\t
    • 1 <= wordDict.length <= 1000
    • \n\t
    • 1 <= wordDict[i].length <= 10
    • \n\t
    • s and wordDict[i] consist of only lowercase English letters.
    • \n\t
    • All the strings of wordDict are unique.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u7a7a\u5b57\u7b26\u4e32 s \u548c\u4e00\u4e2a\u5305\u542b\u975e\u7a7a\u5355\u8bcd\u5217\u8868\u7684\u5b57\u5178 wordDict\uff0c\u5728\u5b57\u7b26\u4e32\u4e2d\u589e\u52a0\u7a7a\u683c\u6765\u6784\u5efa\u4e00\u4e2a\u53e5\u5b50\uff0c\u4f7f\u5f97\u53e5\u5b50\u4e2d\u6240\u6709\u7684\u5355\u8bcd\u90fd\u5728\u8bcd\u5178\u4e2d\u3002\u8fd4\u56de\u6240\u6709\u8fd9\u4e9b\u53ef\u80fd\u7684\u53e5\u5b50\u3002

    \n\n

    \u8bf4\u660e\uff1a

    \n\n
      \n\t
    • \u5206\u9694\u65f6\u53ef\u4ee5\u91cd\u590d\u4f7f\u7528\u5b57\u5178\u4e2d\u7684\u5355\u8bcd\u3002
    • \n\t
    • \u4f60\u53ef\u4ee5\u5047\u8bbe\u5b57\u5178\u4e2d\u6ca1\u6709\u91cd\u590d\u7684\u5355\u8bcd\u3002
    • \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165:\ns = "catsanddog"\nwordDict = ["cat", "cats", "and", "sand", "dog"]\n\u8f93\u51fa:\n[\n  "cats and dog",\n  "cat sand dog"\n]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165:\ns = "pineapplepenapple"\nwordDict = ["apple", "pen", "applepen", "pine", "pineapple"]\n\u8f93\u51fa:\n[\n  "pine apple pen apple",\n  "pineapple pen apple",\n  "pine applepen apple"\n]\n\u89e3\u91ca: \u6ce8\u610f\u4f60\u53ef\u4ee5\u91cd\u590d\u4f7f\u7528\u5b57\u5178\u4e2d\u7684\u5355\u8bcd\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165:\ns = "catsandog"\nwordDict = ["cats", "dog", "sand", "and", "cat"]\n\u8f93\u51fa:\n[]\n
    \n", "tags_en": ["Dynamic Programming", "Backtracking"], "tags_cn": ["\u52a8\u6001\u89c4\u5212", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector wordBreak(string s, vector& wordDict) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List wordBreak(String s, List wordDict) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def wordBreak(self, s, wordDict):\n \"\"\"\n :type s: str\n :type wordDict: List[str]\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def wordBreak(self, s: str, wordDict: List[str]) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** wordBreak(char * s, char ** wordDict, int wordDictSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList WordBreak(string s, IList wordDict) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string[]} wordDict\n * @return {string[]}\n */\nvar wordBreak = function(s, wordDict) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String[]} word_dict\n# @return {String[]}\ndef word_break(s, word_dict)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func wordBreak(_ s: String, _ wordDict: [String]) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func wordBreak(s string, wordDict []string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def wordBreak(s: String, wordDict: List[String]): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun wordBreak(s: String, wordDict: List): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn word_break(s: String, word_dict: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String[] $wordDict\n * @return String[]\n */\n function wordBreak($s, $wordDict) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function wordBreak(s: string, wordDict: string[]): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (word-break s wordDict)\n (-> string? (listof string?) (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0140](https://leetcode-cn.com/problems/word-break-ii)", "[\u5355\u8bcd\u62c6\u5206 II](/solution/0100-0199/0140.Word%20Break%20II/README.md)", "`\u52a8\u6001\u89c4\u5212`,`\u56de\u6eaf\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[0140](https://leetcode.com/problems/word-break-ii)", "[Word Break II](/solution/0100-0199/0140.Word%20Break%20II/README_EN.md)", "`Dynamic Programming`,`Backtracking`", "Hard", ""]}, {"question_id": "0139", "frontend_question_id": "0139", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/word-break", "url_en": "https://leetcode.com/problems/word-break", "relative_path_cn": "/solution/0100-0199/0139.Word%20Break/README.md", "relative_path_en": "/solution/0100-0199/0139.Word%20Break/README_EN.md", "title_cn": "\u5355\u8bcd\u62c6\u5206", "title_en": "Word Break", "question_title_slug": "word-break", "content_en": "

    Given a string s and a dictionary of strings wordDict, return true if s can be segmented into a space-separated sequence of one or more dictionary words.

    \n\n

    Note that the same word in the dictionary may be reused multiple times in the segmentation.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "leetcode", wordDict = ["leet","code"]\nOutput: true\nExplanation: Return true because "leetcode" can be segmented as "leet code".\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "applepenapple", wordDict = ["apple","pen"]\nOutput: true\nExplanation: Return true because "applepenapple" can be segmented as "apple pen apple".\nNote that you are allowed to reuse a dictionary word.\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "catsandog", wordDict = ["cats","dog","sand","and","cat"]\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 300
    • \n\t
    • 1 <= wordDict.length <= 1000
    • \n\t
    • 1 <= wordDict[i].length <= 20
    • \n\t
    • s and wordDict[i] consist of only lowercase English letters.
    • \n\t
    • All the strings of wordDict are unique.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u7a7a\u5b57\u7b26\u4e32 s \u548c\u4e00\u4e2a\u5305\u542b\u975e\u7a7a\u5355\u8bcd\u7684\u5217\u8868 wordDict\uff0c\u5224\u5b9a s \u662f\u5426\u53ef\u4ee5\u88ab\u7a7a\u683c\u62c6\u5206\u4e3a\u4e00\u4e2a\u6216\u591a\u4e2a\u5728\u5b57\u5178\u4e2d\u51fa\u73b0\u7684\u5355\u8bcd\u3002

    \n\n

    \u8bf4\u660e\uff1a

    \n\n
      \n\t
    • \u62c6\u5206\u65f6\u53ef\u4ee5\u91cd\u590d\u4f7f\u7528\u5b57\u5178\u4e2d\u7684\u5355\u8bcd\u3002
    • \n\t
    • \u4f60\u53ef\u4ee5\u5047\u8bbe\u5b57\u5178\u4e2d\u6ca1\u6709\u91cd\u590d\u7684\u5355\u8bcd\u3002
    • \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165: s = "leetcode", wordDict = ["leet", "code"]\n\u8f93\u51fa: true\n\u89e3\u91ca: \u8fd4\u56de true \u56e0\u4e3a "leetcode" \u53ef\u4ee5\u88ab\u62c6\u5206\u6210 "leet code"\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165: s = "applepenapple", wordDict = ["apple", "pen"]\n\u8f93\u51fa: true\n\u89e3\u91ca: \u8fd4\u56de true \u56e0\u4e3a "applepenapple" \u53ef\u4ee5\u88ab\u62c6\u5206\u6210 "apple pen apple"\u3002\n     \u6ce8\u610f\u4f60\u53ef\u4ee5\u91cd\u590d\u4f7f\u7528\u5b57\u5178\u4e2d\u7684\u5355\u8bcd\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165: s = "catsandog", wordDict = ["cats", "dog", "sand", "and", "cat"]\n\u8f93\u51fa: false\n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool wordBreak(string s, vector& wordDict) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean wordBreak(String s, List wordDict) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def wordBreak(self, s, wordDict):\n \"\"\"\n :type s: str\n :type wordDict: List[str]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def wordBreak(self, s: str, wordDict: List[str]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool wordBreak(char * s, char ** wordDict, int wordDictSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool WordBreak(string s, IList wordDict) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string[]} wordDict\n * @return {boolean}\n */\nvar wordBreak = function(s, wordDict) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String[]} word_dict\n# @return {Boolean}\ndef word_break(s, word_dict)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func wordBreak(_ s: String, _ wordDict: [String]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func wordBreak(s string, wordDict []string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def wordBreak(s: String, wordDict: List[String]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun wordBreak(s: String, wordDict: List): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn word_break(s: String, word_dict: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String[] $wordDict\n * @return Boolean\n */\n function wordBreak($s, $wordDict) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function wordBreak(s: string, wordDict: string[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (word-break s wordDict)\n (-> string? (listof string?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0139](https://leetcode-cn.com/problems/word-break)", "[\u5355\u8bcd\u62c6\u5206](/solution/0100-0199/0139.Word%20Break/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0139](https://leetcode.com/problems/word-break)", "[Word Break](/solution/0100-0199/0139.Word%20Break/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0138", "frontend_question_id": "0138", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/copy-list-with-random-pointer", "url_en": "https://leetcode.com/problems/copy-list-with-random-pointer", "relative_path_cn": "/solution/0100-0199/0138.Copy%20List%20with%20Random%20Pointer/README.md", "relative_path_en": "/solution/0100-0199/0138.Copy%20List%20with%20Random%20Pointer/README_EN.md", "title_cn": "\u590d\u5236\u5e26\u968f\u673a\u6307\u9488\u7684\u94fe\u8868", "title_en": "Copy List with Random Pointer", "question_title_slug": "copy-list-with-random-pointer", "content_en": "

    A linked list of length n is given such that each node contains an additional random pointer, which could point to any node in the list, or null.

    \n\n

    Construct a deep copy of the list. The deep copy should consist of exactly n brand new nodes, where each new node has its value set to the value of its corresponding original node. Both the next and random pointer of the new nodes should point to new nodes in the copied list such that the pointers in the original list and copied list represent the same list state. None of the pointers in the new list should point to nodes in the original list.

    \n\n

    For example, if there are two nodes X and Y in the original list, where X.random --> Y, then for the corresponding two nodes x and y in the copied list, x.random --> y.

    \n\n

    Return the head of the copied linked list.

    \n\n

    The linked list is represented in the input/output as a list of n nodes. Each node is represented as a pair of [val, random_index] where:

    \n\n
      \n\t
    • val: an integer representing Node.val
    • \n\t
    • random_index: the index of the node (range from 0 to n-1) that the random pointer points to, or null if it does not point to any node.
    • \n
    \n\n

    Your code will only be given the head of the original linked list.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: head = [[7,null],[13,0],[11,4],[10,2],[1,0]]\nOutput: [[7,null],[13,0],[11,4],[10,2],[1,0]]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: head = [[1,1],[2,1]]\nOutput: [[1,1],[2,1]]\n
    \n\n

    Example 3:

    \n\n

    \"\"

    \n\n
    \nInput: head = [[3,null],[3,0],[3,null]]\nOutput: [[3,null],[3,0],[3,null]]\n
    \n\n

    Example 4:

    \n\n
    \nInput: head = []\nOutput: []\nExplanation: The given linked list is empty (null pointer), so return null.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= n <= 1000
    • \n\t
    • -10000 <= Node.val <= 10000
    • \n\t
    • Node.random is null or is pointing to some node in the linked list.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u94fe\u8868\uff0c\u6bcf\u4e2a\u8282\u70b9\u5305\u542b\u4e00\u4e2a\u989d\u5916\u589e\u52a0\u7684\u968f\u673a\u6307\u9488 random \uff0c\u8be5\u6307\u9488\u53ef\u4ee5\u6307\u5411\u94fe\u8868\u4e2d\u7684\u4efb\u4f55\u8282\u70b9\u6216\u7a7a\u8282\u70b9\u3002

    \n\n

    \u6784\u9020\u8fd9\u4e2a\u94fe\u8868\u7684\u00a0\u6df1\u62f7\u8d1d\u3002\u00a0\u6df1\u62f7\u8d1d\u5e94\u8be5\u6b63\u597d\u7531 n \u4e2a \u5168\u65b0 \u8282\u70b9\u7ec4\u6210\uff0c\u5176\u4e2d\u6bcf\u4e2a\u65b0\u8282\u70b9\u7684\u503c\u90fd\u8bbe\u4e3a\u5176\u5bf9\u5e94\u7684\u539f\u8282\u70b9\u7684\u503c\u3002\u65b0\u8282\u70b9\u7684 next \u6307\u9488\u548c random \u6307\u9488\u4e5f\u90fd\u5e94\u6307\u5411\u590d\u5236\u94fe\u8868\u4e2d\u7684\u65b0\u8282\u70b9\uff0c\u5e76\u4f7f\u539f\u94fe\u8868\u548c\u590d\u5236\u94fe\u8868\u4e2d\u7684\u8fd9\u4e9b\u6307\u9488\u80fd\u591f\u8868\u793a\u76f8\u540c\u7684\u94fe\u8868\u72b6\u6001\u3002\u590d\u5236\u94fe\u8868\u4e2d\u7684\u6307\u9488\u90fd\u4e0d\u5e94\u6307\u5411\u539f\u94fe\u8868\u4e2d\u7684\u8282\u70b9 \u3002

    \n\n

    \u4f8b\u5982\uff0c\u5982\u679c\u539f\u94fe\u8868\u4e2d\u6709 X \u548c Y \u4e24\u4e2a\u8282\u70b9\uff0c\u5176\u4e2d X.random --> Y \u3002\u90a3\u4e48\u5728\u590d\u5236\u94fe\u8868\u4e2d\u5bf9\u5e94\u7684\u4e24\u4e2a\u8282\u70b9 x \u548c y \uff0c\u540c\u6837\u6709 x.random --> y \u3002

    \n\n

    \u8fd4\u56de\u590d\u5236\u94fe\u8868\u7684\u5934\u8282\u70b9\u3002

    \n\n

    \u7528\u4e00\u4e2a\u7531\u00a0n\u00a0\u4e2a\u8282\u70b9\u7ec4\u6210\u7684\u94fe\u8868\u6765\u8868\u793a\u8f93\u5165/\u8f93\u51fa\u4e2d\u7684\u94fe\u8868\u3002\u6bcf\u4e2a\u8282\u70b9\u7528\u4e00\u4e2a\u00a0[val, random_index]\u00a0\u8868\u793a\uff1a

    \n\n
      \n\t
    • val\uff1a\u4e00\u4e2a\u8868\u793a\u00a0Node.val\u00a0\u7684\u6574\u6570\u3002
    • \n\t
    • random_index\uff1a\u968f\u673a\u6307\u9488\u6307\u5411\u7684\u8282\u70b9\u7d22\u5f15\uff08\u8303\u56f4\u4ece\u00a00\u00a0\u5230\u00a0n-1\uff09\uff1b\u5982\u679c\u4e0d\u6307\u5411\u4efb\u4f55\u8282\u70b9\uff0c\u5219\u4e3a\u00a0\u00a0null\u00a0\u3002
    • \n
    \n\n

    \u4f60\u7684\u4ee3\u7801 \u53ea \u63a5\u53d7\u539f\u94fe\u8868\u7684\u5934\u8282\u70b9 head \u4f5c\u4e3a\u4f20\u5165\u53c2\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1ahead = [[7,null],[13,0],[11,4],[10,2],[1,0]]\n\u8f93\u51fa\uff1a[[7,null],[13,0],[11,4],[10,2],[1,0]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1ahead = [[1,1],[2,1]]\n\u8f93\u51fa\uff1a[[1,1],[2,1]]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1ahead = [[3,null],[3,0],[3,null]]\n\u8f93\u51fa\uff1a[[3,null],[3,0],[3,null]]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahead = []\n\u8f93\u51fa\uff1a[]\n\u89e3\u91ca\uff1a\u7ed9\u5b9a\u7684\u94fe\u8868\u4e3a\u7a7a\uff08\u7a7a\u6307\u9488\uff09\uff0c\u56e0\u6b64\u8fd4\u56de null\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= n <= 1000
    • \n\t
    • -10000 <= Node.val <= 10000
    • \n\t
    • Node.random\u00a0\u4e3a\u7a7a\uff08null\uff09\u6216\u6307\u5411\u94fe\u8868\u4e2d\u7684\u8282\u70b9\u3002
    • \n
    \n", "tags_en": ["Hash Table", "Linked List"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u94fe\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* next;\n Node* random;\n \n Node(int _val) {\n val = _val;\n next = NULL;\n random = NULL;\n }\n};\n*/\n\nclass Solution {\npublic:\n Node* copyRandomList(Node* head) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/*\n// Definition for a Node.\nclass Node {\n int val;\n Node next;\n Node random;\n\n public Node(int val) {\n this.val = val;\n this.next = null;\n this.random = null;\n }\n}\n*/\n\nclass Solution {\n public Node copyRandomList(Node head) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "\"\"\"\n# Definition for a Node.\nclass Node:\n def __init__(self, x, next=None, random=None):\n self.val = int(x)\n self.next = next\n self.random = random\n\"\"\"\n\nclass Solution(object):\n def copyRandomList(self, head):\n \"\"\"\n :type head: Node\n :rtype: Node\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "\"\"\"\n# Definition for a Node.\nclass Node:\n def __init__(self, x: int, next: 'Node' = None, random: 'Node' = None):\n self.val = int(x)\n self.next = next\n self.random = random\n\"\"\"\n\nclass Solution:\n def copyRandomList(self, head: 'Node') -> 'Node':\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a Node.\n * struct Node {\n * int val;\n * struct Node *next;\n * struct Node *random;\n * };\n */\n\nstruct Node* copyRandomList(struct Node* head) {\n\t\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/*\n// Definition for a Node.\npublic class Node {\n public int val;\n public Node next;\n public Node random;\n \n public Node(int _val) {\n val = _val;\n next = null;\n random = null;\n }\n}\n*/\n\npublic class Solution {\n public Node CopyRandomList(Node head) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // Definition for a Node.\n * function Node(val, next, random) {\n * this.val = val;\n * this.next = next;\n * this.random = random;\n * };\n */\n\n/**\n * @param {Node} head\n * @return {Node}\n */\nvar copyRandomList = function(head) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for Node.\n# class Node\n# attr_accessor :val, :next, :random\n# def initialize(val = 0)\n# @val = val\n#\t\t @next = nil\n#\t\t @random = nil\n# end\n# end\n\n# @param {Node} node\n# @return {Node}\ndef copyRandomList(head)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a Node.\n * public class Node {\n * public var val: Int\n * public var next: Node?\n * public var random: Node?\n * public init(_ val: Int) {\n * self.val = val\n * self.next = nil\n * \t self.random = nil\n * }\n * }\n */\n\nclass Solution {\n func copyRandomList(_ head: Node?) -> Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a Node.\n * type Node struct {\n * Val int\n * Next *Node\n * Random *Node\n * }\n */\n\nfunc copyRandomList(head *Node) *Node {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a Node.\n * class Node(var _value: Int) {\n * var value: Int = _value\n * var next: Node = null\n * var random: Node = null\n * }\n */\n\nobject Solution {\n def copyRandomList(head: Node): Node = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = Node(5)\n * var v = ti.`val`\n * Definition for a Node.\n * class Node(var `val`: Int) {\n * var next: Node? = null\n * var random: Node? = null\n * }\n */\n\nclass Solution {\n fun copyRandomList(node: Node?): Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a Node.\n * class Node {\n * public $val = null;\n * public $next = null;\n * public $random = null;\n * function __construct($val = 0) {\n * $this->val = $val;\n * $this->next = null;\n * $this->random = null;\n * }\n * }\n */\n\nclass Solution {\n /**\n * @param Node $head\n * @return Node\n */\n function copyRandomList($head) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for Node.\n * class Node {\n * val: number\n * next: Node | null\n * random: Node | null\n * constructor(val?: number, next?: Node, random?: Node) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * this.random = (random===undefined ? null : random)\n * }\n * }\n */\n\nfunction copyRandomList(head: Node | null): Node | null {\n \n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0138](https://leetcode-cn.com/problems/copy-list-with-random-pointer)", "[\u590d\u5236\u5e26\u968f\u673a\u6307\u9488\u7684\u94fe\u8868](/solution/0100-0199/0138.Copy%20List%20with%20Random%20Pointer/README.md)", "`\u54c8\u5e0c\u8868`,`\u94fe\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0138](https://leetcode.com/problems/copy-list-with-random-pointer)", "[Copy List with Random Pointer](/solution/0100-0199/0138.Copy%20List%20with%20Random%20Pointer/README_EN.md)", "`Hash Table`,`Linked List`", "Medium", ""]}, {"question_id": "0137", "frontend_question_id": "0137", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/single-number-ii", "url_en": "https://leetcode.com/problems/single-number-ii", "relative_path_cn": "/solution/0100-0199/0137.Single%20Number%20II/README.md", "relative_path_en": "/solution/0100-0199/0137.Single%20Number%20II/README_EN.md", "title_cn": "\u53ea\u51fa\u73b0\u4e00\u6b21\u7684\u6570\u5b57 II", "title_en": "Single Number II", "question_title_slug": "single-number-ii", "content_en": "

    Given an integer array nums where every element appears three times except for one, which appears exactly once. Find the single element and return it.

    \n\n

    You must implement a solution with a linear runtime complexity and use only constant extra space.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [2,2,3,2]\nOutput: 3\n

    Example 2:

    \n
    Input: nums = [0,1,0,1,0,1,99]\nOutput: 99\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 3 * 104
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n\t
    • Each element in nums appears exactly three times except for one element which appears once.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0nums \uff0c\u9664\u67d0\u4e2a\u5143\u7d20\u4ec5\u51fa\u73b0 \u4e00\u6b21 \u5916\uff0c\u5176\u4f59\u6bcf\u4e2a\u5143\u7d20\u90fd\u6070\u51fa\u73b0 \u4e09\u6b21 \u3002\u8bf7\u4f60\u627e\u51fa\u5e76\u8fd4\u56de\u90a3\u4e2a\u53ea\u51fa\u73b0\u4e86\u4e00\u6b21\u7684\u5143\u7d20\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [2,2,3,2]\n\u8f93\u51fa\uff1a3\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [0,1,0,1,0,1,99]\n\u8f93\u51fa\uff1a99\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 3 * 104
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n\t
    • nums \u4e2d\uff0c\u9664\u67d0\u4e2a\u5143\u7d20\u4ec5\u51fa\u73b0 \u4e00\u6b21 \u5916\uff0c\u5176\u4f59\u6bcf\u4e2a\u5143\u7d20\u90fd\u6070\u51fa\u73b0 \u4e09\u6b21
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u7684\u7b97\u6cd5\u5e94\u8be5\u5177\u6709\u7ebf\u6027\u65f6\u95f4\u590d\u6742\u5ea6\u3002 \u4f60\u53ef\u4ee5\u4e0d\u4f7f\u7528\u989d\u5916\u7a7a\u95f4\u6765\u5b9e\u73b0\u5417\uff1f

    \n", "tags_en": ["Bit Manipulation"], "tags_cn": ["\u4f4d\u8fd0\u7b97"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int singleNumber(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int singleNumber(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def singleNumber(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def singleNumber(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint singleNumber(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SingleNumber(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar singleNumber = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef single_number(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func singleNumber(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func singleNumber(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def singleNumber(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun singleNumber(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn single_number(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function singleNumber($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function singleNumber(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (single-number nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0137](https://leetcode-cn.com/problems/single-number-ii)", "[\u53ea\u51fa\u73b0\u4e00\u6b21\u7684\u6570\u5b57 II](/solution/0100-0199/0137.Single%20Number%20II/README.md)", "`\u4f4d\u8fd0\u7b97`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0137](https://leetcode.com/problems/single-number-ii)", "[Single Number II](/solution/0100-0199/0137.Single%20Number%20II/README_EN.md)", "`Bit Manipulation`", "Medium", ""]}, {"question_id": "0136", "frontend_question_id": "0136", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/single-number", "url_en": "https://leetcode.com/problems/single-number", "relative_path_cn": "/solution/0100-0199/0136.Single%20Number/README.md", "relative_path_en": "/solution/0100-0199/0136.Single%20Number/README_EN.md", "title_cn": "\u53ea\u51fa\u73b0\u4e00\u6b21\u7684\u6570\u5b57", "title_en": "Single Number", "question_title_slug": "single-number", "content_en": "

    Given a non-empty array of integers nums, every element appears twice except for one. Find that single one.

    \n\n

    You must implement a solution with a linear runtime complexity and use only constant extra space.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [2,2,1]\nOutput: 1\n

    Example 2:

    \n
    Input: nums = [4,1,2,1,2]\nOutput: 4\n

    Example 3:

    \n
    Input: nums = [1]\nOutput: 1\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 3 * 104
    • \n\t
    • -3 * 104 <= nums[i] <= 3 * 104
    • \n\t
    • Each element in the array appears twice except for one element which appears only once.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u7a7a\u6574\u6570\u6570\u7ec4\uff0c\u9664\u4e86\u67d0\u4e2a\u5143\u7d20\u53ea\u51fa\u73b0\u4e00\u6b21\u4ee5\u5916\uff0c\u5176\u4f59\u6bcf\u4e2a\u5143\u7d20\u5747\u51fa\u73b0\u4e24\u6b21\u3002\u627e\u51fa\u90a3\u4e2a\u53ea\u51fa\u73b0\u4e86\u4e00\u6b21\u7684\u5143\u7d20\u3002

    \n\n

    \u8bf4\u660e\uff1a

    \n\n

    \u4f60\u7684\u7b97\u6cd5\u5e94\u8be5\u5177\u6709\u7ebf\u6027\u65f6\u95f4\u590d\u6742\u5ea6\u3002 \u4f60\u53ef\u4ee5\u4e0d\u4f7f\u7528\u989d\u5916\u7a7a\u95f4\u6765\u5b9e\u73b0\u5417\uff1f

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: [2,2,1]\n\u8f93\u51fa: 1\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: [4,1,2,1,2]\n\u8f93\u51fa: 4
    \n", "tags_en": ["Bit Manipulation", "Hash Table"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int singleNumber(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int singleNumber(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def singleNumber(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def singleNumber(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint singleNumber(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SingleNumber(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar singleNumber = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef single_number(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func singleNumber(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func singleNumber(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def singleNumber(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun singleNumber(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn single_number(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function singleNumber($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function singleNumber(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (single-number nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0136](https://leetcode-cn.com/problems/single-number)", "[\u53ea\u51fa\u73b0\u4e00\u6b21\u7684\u6570\u5b57](/solution/0100-0199/0136.Single%20Number/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0136](https://leetcode.com/problems/single-number)", "[Single Number](/solution/0100-0199/0136.Single%20Number/README_EN.md)", "`Bit Manipulation`,`Hash Table`", "Easy", ""]}, {"question_id": "0135", "frontend_question_id": "0135", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/candy", "url_en": "https://leetcode.com/problems/candy", "relative_path_cn": "/solution/0100-0199/0135.Candy/README.md", "relative_path_en": "/solution/0100-0199/0135.Candy/README_EN.md", "title_cn": "\u5206\u53d1\u7cd6\u679c", "title_en": "Candy", "question_title_slug": "candy", "content_en": "

    There are n children standing in a line. Each child is assigned a rating value given in the integer array ratings.

    \n\n

    You are giving candies to these children subjected to the following requirements:

    \n\n
      \n\t
    • Each child must have at least one candy.
    • \n\t
    • Children with a higher rating get more candies than their neighbors.
    • \n
    \n\n

    Return the minimum number of candies you need to have to distribute the candies to the children.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: ratings = [1,0,2]\nOutput: 5\nExplanation: You can allocate to the first, second and third child with 2, 1, 2 candies respectively.\n
    \n\n

    Example 2:

    \n\n
    \nInput: ratings = [1,2,2]\nOutput: 4\nExplanation: You can allocate to the first, second and third child with 1, 2, 1 candies respectively.\nThe third child gets 1 candy because it satisfies the above two conditions.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == ratings.length
    • \n\t
    • 1 <= n <= 2 * 104
    • \n\t
    • 0 <= ratings[i] <= 2 * 104
    • \n
    \n", "content_cn": "

    \u8001\u5e08\u60f3\u7ed9\u5b69\u5b50\u4eec\u5206\u53d1\u7cd6\u679c\uff0c\u6709 N\u00a0\u4e2a\u5b69\u5b50\u7ad9\u6210\u4e86\u4e00\u6761\u76f4\u7ebf\uff0c\u8001\u5e08\u4f1a\u6839\u636e\u6bcf\u4e2a\u5b69\u5b50\u7684\u8868\u73b0\uff0c\u9884\u5148\u7ed9\u4ed6\u4eec\u8bc4\u5206\u3002

    \n\n

    \u4f60\u9700\u8981\u6309\u7167\u4ee5\u4e0b\u8981\u6c42\uff0c\u5e2e\u52a9\u8001\u5e08\u7ed9\u8fd9\u4e9b\u5b69\u5b50\u5206\u53d1\u7cd6\u679c\uff1a

    \n\n
      \n\t
    • \u6bcf\u4e2a\u5b69\u5b50\u81f3\u5c11\u5206\u914d\u5230 1 \u4e2a\u7cd6\u679c\u3002
    • \n\t
    • \u8bc4\u5206\u66f4\u9ad8\u7684\u5b69\u5b50\u5fc5\u987b\u6bd4\u4ed6\u4e24\u4fa7\u7684\u90bb\u4f4d\u5b69\u5b50\u83b7\u5f97\u66f4\u591a\u7684\u7cd6\u679c\u3002
    • \n
    \n\n

    \u90a3\u4e48\u8fd9\u6837\u4e0b\u6765\uff0c\u8001\u5e08\u81f3\u5c11\u9700\u8981\u51c6\u5907\u591a\u5c11\u9897\u7cd6\u679c\u5462\uff1f

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\u00a01\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[1,0,2]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u5206\u522b\u7ed9\u8fd9\u4e09\u4e2a\u5b69\u5b50\u5206\u53d1 2\u30011\u30012 \u9897\u7cd6\u679c\u3002\n
    \n\n

    \u793a\u4f8b\u00a02\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[1,2,2]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u5206\u522b\u7ed9\u8fd9\u4e09\u4e2a\u5b69\u5b50\u5206\u53d1 1\u30012\u30011 \u9897\u7cd6\u679c\u3002\n     \u7b2c\u4e09\u4e2a\u5b69\u5b50\u53ea\u5f97\u5230 1 \u9897\u7cd6\u679c\uff0c\u8fd9\u5df2\u6ee1\u8db3\u4e0a\u8ff0\u4e24\u4e2a\u6761\u4ef6\u3002
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int candy(vector& ratings) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int candy(int[] ratings) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def candy(self, ratings):\n \"\"\"\n :type ratings: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def candy(self, ratings: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint candy(int* ratings, int ratingsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int Candy(int[] ratings) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} ratings\n * @return {number}\n */\nvar candy = function(ratings) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} ratings\n# @return {Integer}\ndef candy(ratings)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func candy(_ ratings: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func candy(ratings []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def candy(ratings: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun candy(ratings: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn candy(ratings: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $ratings\n * @return Integer\n */\n function candy($ratings) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function candy(ratings: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (candy ratings)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0135](https://leetcode-cn.com/problems/candy)", "[\u5206\u53d1\u7cd6\u679c](/solution/0100-0199/0135.Candy/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[0135](https://leetcode.com/problems/candy)", "[Candy](/solution/0100-0199/0135.Candy/README_EN.md)", "`Greedy`", "Hard", ""]}, {"question_id": "0134", "frontend_question_id": "0134", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/gas-station", "url_en": "https://leetcode.com/problems/gas-station", "relative_path_cn": "/solution/0100-0199/0134.Gas%20Station/README.md", "relative_path_en": "/solution/0100-0199/0134.Gas%20Station/README_EN.md", "title_cn": "\u52a0\u6cb9\u7ad9", "title_en": "Gas Station", "question_title_slug": "gas-station", "content_en": "

    There are n gas stations along a circular route, where the amount of gas at the ith station is gas[i].

    \n\n

    You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from the ith station to its next (i + 1)th station. You begin the journey with an empty tank at one of the gas stations.

    \n\n

    Given two integer arrays gas and cost, return the starting gas station's index if you can travel around the circuit once in the clockwise direction, otherwise return -1. If there exists a solution, it is guaranteed to be unique

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: gas = [1,2,3,4,5], cost = [3,4,5,1,2]\nOutput: 3\nExplanation:\nStart at station 3 (index 3) and fill up with 4 unit of gas. Your tank = 0 + 4 = 4\nTravel to station 4. Your tank = 4 - 1 + 5 = 8\nTravel to station 0. Your tank = 8 - 2 + 1 = 7\nTravel to station 1. Your tank = 7 - 3 + 2 = 6\nTravel to station 2. Your tank = 6 - 4 + 3 = 5\nTravel to station 3. The cost is 5. Your gas is just enough to travel back to station 3.\nTherefore, return 3 as the starting index.\n
    \n\n

    Example 2:

    \n\n
    \nInput: gas = [2,3,4], cost = [3,4,3]\nOutput: -1\nExplanation:\nYou can't start at station 0 or 1, as there is not enough gas to travel to the next station.\nLet's start at station 2 and fill up with 4 unit of gas. Your tank = 0 + 4 = 4\nTravel to station 0. Your tank = 4 - 3 + 2 = 3\nTravel to station 1. Your tank = 3 - 3 + 3 = 3\nYou cannot travel back to station 2, as it requires 4 unit of gas but you only have 3.\nTherefore, you can't travel around the circuit once no matter where you start.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • gas.length == n
    • \n\t
    • cost.length == n
    • \n\t
    • 1 <= n <= 104
    • \n\t
    • 0 <= gas[i], cost[i] <= 104
    • \n
    \n", "content_cn": "

    \u5728\u4e00\u6761\u73af\u8def\u4e0a\u6709 N \u4e2a\u52a0\u6cb9\u7ad9\uff0c\u5176\u4e2d\u7b2c i \u4e2a\u52a0\u6cb9\u7ad9\u6709\u6c7d\u6cb9 gas[i] \u5347\u3002

    \n\n

    \u4f60\u6709\u4e00\u8f86\u6cb9\u7bb1\u5bb9\u91cf\u65e0\u9650\u7684\u7684\u6c7d\u8f66\uff0c\u4ece\u7b2c i \u4e2a\u52a0\u6cb9\u7ad9\u5f00\u5f80\u7b2c i+1 \u4e2a\u52a0\u6cb9\u7ad9\u9700\u8981\u6d88\u8017\u6c7d\u6cb9 cost[i] \u5347\u3002\u4f60\u4ece\u5176\u4e2d\u7684\u4e00\u4e2a\u52a0\u6cb9\u7ad9\u51fa\u53d1\uff0c\u5f00\u59cb\u65f6\u6cb9\u7bb1\u4e3a\u7a7a\u3002

    \n\n

    \u5982\u679c\u4f60\u53ef\u4ee5\u7ed5\u73af\u8def\u884c\u9a76\u4e00\u5468\uff0c\u5219\u8fd4\u56de\u51fa\u53d1\u65f6\u52a0\u6cb9\u7ad9\u7684\u7f16\u53f7\uff0c\u5426\u5219\u8fd4\u56de -1\u3002

    \n\n

    \u8bf4\u660e: 

    \n\n
      \n\t
    • \u5982\u679c\u9898\u76ee\u6709\u89e3\uff0c\u8be5\u7b54\u6848\u5373\u4e3a\u552f\u4e00\u7b54\u6848\u3002
    • \n\t
    • \u8f93\u5165\u6570\u7ec4\u5747\u4e3a\u975e\u7a7a\u6570\u7ec4\uff0c\u4e14\u957f\u5ea6\u76f8\u540c\u3002
    • \n\t
    • \u8f93\u5165\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u5747\u4e3a\u975e\u8d1f\u6570\u3002
    • \n
    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: \ngas  = [1,2,3,4,5]\ncost = [3,4,5,1,2]\n\n\u8f93\u51fa: 3\n\n\u89e3\u91ca:\n\u4ece 3 \u53f7\u52a0\u6cb9\u7ad9(\u7d22\u5f15\u4e3a 3 \u5904)\u51fa\u53d1\uff0c\u53ef\u83b7\u5f97 4 \u5347\u6c7d\u6cb9\u3002\u6b64\u65f6\u6cb9\u7bb1\u6709 = 0 + 4 = 4 \u5347\u6c7d\u6cb9\n\u5f00\u5f80 4 \u53f7\u52a0\u6cb9\u7ad9\uff0c\u6b64\u65f6\u6cb9\u7bb1\u6709 4 - 1 + 5 = 8 \u5347\u6c7d\u6cb9\n\u5f00\u5f80 0 \u53f7\u52a0\u6cb9\u7ad9\uff0c\u6b64\u65f6\u6cb9\u7bb1\u6709 8 - 2 + 1 = 7 \u5347\u6c7d\u6cb9\n\u5f00\u5f80 1 \u53f7\u52a0\u6cb9\u7ad9\uff0c\u6b64\u65f6\u6cb9\u7bb1\u6709 7 - 3 + 2 = 6 \u5347\u6c7d\u6cb9\n\u5f00\u5f80 2 \u53f7\u52a0\u6cb9\u7ad9\uff0c\u6b64\u65f6\u6cb9\u7bb1\u6709 6 - 4 + 3 = 5 \u5347\u6c7d\u6cb9\n\u5f00\u5f80 3 \u53f7\u52a0\u6cb9\u7ad9\uff0c\u4f60\u9700\u8981\u6d88\u8017 5 \u5347\u6c7d\u6cb9\uff0c\u6b63\u597d\u8db3\u591f\u4f60\u8fd4\u56de\u5230 3 \u53f7\u52a0\u6cb9\u7ad9\u3002\n\u56e0\u6b64\uff0c3 \u53ef\u4e3a\u8d77\u59cb\u7d22\u5f15\u3002
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: \ngas  = [2,3,4]\ncost = [3,4,3]\n\n\u8f93\u51fa: -1\n\n\u89e3\u91ca:\n\u4f60\u4e0d\u80fd\u4ece 0 \u53f7\u6216 1 \u53f7\u52a0\u6cb9\u7ad9\u51fa\u53d1\uff0c\u56e0\u4e3a\u6ca1\u6709\u8db3\u591f\u7684\u6c7d\u6cb9\u53ef\u4ee5\u8ba9\u4f60\u884c\u9a76\u5230\u4e0b\u4e00\u4e2a\u52a0\u6cb9\u7ad9\u3002\n\u6211\u4eec\u4ece 2 \u53f7\u52a0\u6cb9\u7ad9\u51fa\u53d1\uff0c\u53ef\u4ee5\u83b7\u5f97 4 \u5347\u6c7d\u6cb9\u3002 \u6b64\u65f6\u6cb9\u7bb1\u6709 = 0 + 4 = 4 \u5347\u6c7d\u6cb9\n\u5f00\u5f80 0 \u53f7\u52a0\u6cb9\u7ad9\uff0c\u6b64\u65f6\u6cb9\u7bb1\u6709 4 - 3 + 2 = 3 \u5347\u6c7d\u6cb9\n\u5f00\u5f80 1 \u53f7\u52a0\u6cb9\u7ad9\uff0c\u6b64\u65f6\u6cb9\u7bb1\u6709 3 - 3 + 3 = 3 \u5347\u6c7d\u6cb9\n\u4f60\u65e0\u6cd5\u8fd4\u56de 2 \u53f7\u52a0\u6cb9\u7ad9\uff0c\u56e0\u4e3a\u8fd4\u7a0b\u9700\u8981\u6d88\u8017 4 \u5347\u6c7d\u6cb9\uff0c\u4f46\u662f\u4f60\u7684\u6cb9\u7bb1\u53ea\u6709 3 \u5347\u6c7d\u6cb9\u3002\n\u56e0\u6b64\uff0c\u65e0\u8bba\u600e\u6837\uff0c\u4f60\u90fd\u4e0d\u53ef\u80fd\u7ed5\u73af\u8def\u884c\u9a76\u4e00\u5468\u3002
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int canCompleteCircuit(vector& gas, vector& cost) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int canCompleteCircuit(int[] gas, int[] cost) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canCompleteCircuit(self, gas, cost):\n \"\"\"\n :type gas: List[int]\n :type cost: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canCompleteCircuit(self, gas: List[int], cost: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint canCompleteCircuit(int* gas, int gasSize, int* cost, int costSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CanCompleteCircuit(int[] gas, int[] cost) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} gas\n * @param {number[]} cost\n * @return {number}\n */\nvar canCompleteCircuit = function(gas, cost) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} gas\n# @param {Integer[]} cost\n# @return {Integer}\ndef can_complete_circuit(gas, cost)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canCompleteCircuit(_ gas: [Int], _ cost: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canCompleteCircuit(gas []int, cost []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canCompleteCircuit(gas: Array[Int], cost: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canCompleteCircuit(gas: IntArray, cost: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_complete_circuit(gas: Vec, cost: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $gas\n * @param Integer[] $cost\n * @return Integer\n */\n function canCompleteCircuit($gas, $cost) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canCompleteCircuit(gas: number[], cost: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-complete-circuit gas cost)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0134](https://leetcode-cn.com/problems/gas-station)", "[\u52a0\u6cb9\u7ad9](/solution/0100-0199/0134.Gas%20Station/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0134](https://leetcode.com/problems/gas-station)", "[Gas Station](/solution/0100-0199/0134.Gas%20Station/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "0133", "frontend_question_id": "0133", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/clone-graph", "url_en": "https://leetcode.com/problems/clone-graph", "relative_path_cn": "/solution/0100-0199/0133.Clone%20Graph/README.md", "relative_path_en": "/solution/0100-0199/0133.Clone%20Graph/README_EN.md", "title_cn": "\u514b\u9686\u56fe", "title_en": "Clone Graph", "question_title_slug": "clone-graph", "content_en": "

    Given a reference of a node in a connected undirected graph.

    \n\n

    Return a deep copy (clone) of the graph.

    \n\n

    Each node in the graph contains a value (int) and a list (List[Node]) of its neighbors.

    \n\n
    \nclass Node {\n    public int val;\n    public List<Node> neighbors;\n}\n
    \n\n

     

    \n\n

    Test case format:

    \n\n

    For simplicity, each node's value is the same as the node's index (1-indexed). For example, the first node with val == 1, the second node with val == 2, and so on. The graph is represented in the test case using an adjacency list.

    \n\n

    An adjacency list is a collection of unordered lists used to represent a finite graph. Each list describes the set of neighbors of a node in the graph.

    \n\n

    The given node will always be the first node with val = 1. You must return the copy of the given node as a reference to the cloned graph.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: adjList = [[2,4],[1,3],[2,4],[1,3]]\nOutput: [[2,4],[1,3],[2,4],[1,3]]\nExplanation: There are 4 nodes in the graph.\n1st node (val = 1)'s neighbors are 2nd node (val = 2) and 4th node (val = 4).\n2nd node (val = 2)'s neighbors are 1st node (val = 1) and 3rd node (val = 3).\n3rd node (val = 3)'s neighbors are 2nd node (val = 2) and 4th node (val = 4).\n4th node (val = 4)'s neighbors are 1st node (val = 1) and 3rd node (val = 3).\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: adjList = [[]]\nOutput: [[]]\nExplanation: Note that the input contains one empty list. The graph consists of only one node with val = 1 and it does not have any neighbors.\n
    \n\n

    Example 3:

    \n\n
    \nInput: adjList = []\nOutput: []\nExplanation: This an empty graph, it does not have any nodes.\n
    \n\n

    Example 4:

    \n\"\"\n
    \nInput: adjList = [[2],[1]]\nOutput: [[2],[1]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the graph is in the range [0, 100].
    • \n\t
    • 1 <= Node.val <= 100
    • \n\t
    • Node.val is unique for each node.
    • \n\t
    • There are no repeated edges and no self-loops in the graph.
    • \n\t
    • The Graph is connected and all nodes can be visited starting from the given node.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u65e0\u5411 \u8fde\u901a \u56fe\u4e2d\u4e00\u4e2a\u8282\u70b9\u7684\u5f15\u7528\uff0c\u8bf7\u4f60\u8fd4\u56de\u8be5\u56fe\u7684 \u6df1\u62f7\u8d1d\uff08\u514b\u9686\uff09\u3002

    \n\n

    \u56fe\u4e2d\u7684\u6bcf\u4e2a\u8282\u70b9\u90fd\u5305\u542b\u5b83\u7684\u503c val\uff08int\uff09 \u548c\u5176\u90bb\u5c45\u7684\u5217\u8868\uff08list[Node]\uff09\u3002

    \n\n
    class Node {\n    public int val;\n    public List<Node> neighbors;\n}
    \n\n

     

    \n\n

    \u6d4b\u8bd5\u7528\u4f8b\u683c\u5f0f\uff1a

    \n\n

    \u7b80\u5355\u8d77\u89c1\uff0c\u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u90fd\u548c\u5b83\u7684\u7d22\u5f15\u76f8\u540c\u3002\u4f8b\u5982\uff0c\u7b2c\u4e00\u4e2a\u8282\u70b9\u503c\u4e3a 1\uff08val = 1\uff09\uff0c\u7b2c\u4e8c\u4e2a\u8282\u70b9\u503c\u4e3a 2\uff08val = 2\uff09\uff0c\u4ee5\u6b64\u7c7b\u63a8\u3002\u8be5\u56fe\u5728\u6d4b\u8bd5\u7528\u4f8b\u4e2d\u4f7f\u7528\u90bb\u63a5\u5217\u8868\u8868\u793a\u3002

    \n\n

    \u90bb\u63a5\u5217\u8868 \u662f\u7528\u4e8e\u8868\u793a\u6709\u9650\u56fe\u7684\u65e0\u5e8f\u5217\u8868\u7684\u96c6\u5408\u3002\u6bcf\u4e2a\u5217\u8868\u90fd\u63cf\u8ff0\u4e86\u56fe\u4e2d\u8282\u70b9\u7684\u90bb\u5c45\u96c6\u3002

    \n\n

    \u7ed9\u5b9a\u8282\u70b9\u5c06\u59cb\u7ec8\u662f\u56fe\u4e2d\u7684\u7b2c\u4e00\u4e2a\u8282\u70b9\uff08\u503c\u4e3a 1\uff09\u3002\u4f60\u5fc5\u987b\u5c06 \u7ed9\u5b9a\u8282\u70b9\u7684\u62f7\u8d1d \u4f5c\u4e3a\u5bf9\u514b\u9686\u56fe\u7684\u5f15\u7528\u8fd4\u56de\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1aadjList = [[2,4],[1,3],[2,4],[1,3]]\n\u8f93\u51fa\uff1a[[2,4],[1,3],[2,4],[1,3]]\n\u89e3\u91ca\uff1a\n\u56fe\u4e2d\u6709 4 \u4e2a\u8282\u70b9\u3002\n\u8282\u70b9 1 \u7684\u503c\u662f 1\uff0c\u5b83\u6709\u4e24\u4e2a\u90bb\u5c45\uff1a\u8282\u70b9 2 \u548c 4 \u3002\n\u8282\u70b9 2 \u7684\u503c\u662f 2\uff0c\u5b83\u6709\u4e24\u4e2a\u90bb\u5c45\uff1a\u8282\u70b9 1 \u548c 3 \u3002\n\u8282\u70b9 3 \u7684\u503c\u662f 3\uff0c\u5b83\u6709\u4e24\u4e2a\u90bb\u5c45\uff1a\u8282\u70b9 2 \u548c 4 \u3002\n\u8282\u70b9 4 \u7684\u503c\u662f 4\uff0c\u5b83\u6709\u4e24\u4e2a\u90bb\u5c45\uff1a\u8282\u70b9 1 \u548c 3 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1aadjList = [[]]\n\u8f93\u51fa\uff1a[[]]\n\u89e3\u91ca\uff1a\u8f93\u5165\u5305\u542b\u4e00\u4e2a\u7a7a\u5217\u8868\u3002\u8be5\u56fe\u4ec5\u4ec5\u53ea\u6709\u4e00\u4e2a\u503c\u4e3a 1 \u7684\u8282\u70b9\uff0c\u5b83\u6ca1\u6709\u4efb\u4f55\u90bb\u5c45\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aadjList = []\n\u8f93\u51fa\uff1a[]\n\u89e3\u91ca\uff1a\u8fd9\u4e2a\u56fe\u662f\u7a7a\u7684\uff0c\u5b83\u4e0d\u542b\u4efb\u4f55\u8282\u70b9\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1aadjList = [[2],[1]]\n\u8f93\u51fa\uff1a[[2],[1]]
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. \u8282\u70b9\u6570\u4e0d\u8d85\u8fc7 100 \u3002
    2. \n\t
    3. \u6bcf\u4e2a\u8282\u70b9\u503c Node.val \u90fd\u662f\u552f\u4e00\u7684\uff0c1 <= Node.val <= 100\u3002
    4. \n\t
    5. \u65e0\u5411\u56fe\u662f\u4e00\u4e2a\u7b80\u5355\u56fe\uff0c\u8fd9\u610f\u5473\u7740\u56fe\u4e2d\u6ca1\u6709\u91cd\u590d\u7684\u8fb9\uff0c\u4e5f\u6ca1\u6709\u81ea\u73af\u3002
    6. \n\t
    7. \u7531\u4e8e\u56fe\u662f\u65e0\u5411\u7684\uff0c\u5982\u679c\u8282\u70b9 p \u662f\u8282\u70b9 q \u7684\u90bb\u5c45\uff0c\u90a3\u4e48\u8282\u70b9 q \u4e5f\u5fc5\u987b\u662f\u8282\u70b9 p \u7684\u90bb\u5c45\u3002
    8. \n\t
    9. \u56fe\u662f\u8fde\u901a\u56fe\uff0c\u4f60\u53ef\u4ee5\u4ece\u7ed9\u5b9a\u8282\u70b9\u8bbf\u95ee\u5230\u6240\u6709\u8282\u70b9\u3002
    10. \n
    \n", "tags_en": ["Depth-first Search", "Breadth-first Search", "Graph"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n vector neighbors;\n Node() {\n val = 0;\n neighbors = vector();\n }\n Node(int _val) {\n val = _val;\n neighbors = vector();\n }\n Node(int _val, vector _neighbors) {\n val = _val;\n neighbors = _neighbors;\n }\n};\n*/\n\nclass Solution {\npublic:\n Node* cloneGraph(Node* node) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/*\n// Definition for a Node.\nclass Node {\n public int val;\n public List neighbors;\n public Node() {\n val = 0;\n neighbors = new ArrayList();\n }\n public Node(int _val) {\n val = _val;\n neighbors = new ArrayList();\n }\n public Node(int _val, ArrayList _neighbors) {\n val = _val;\n neighbors = _neighbors;\n }\n}\n*/\n\nclass Solution {\n public Node cloneGraph(Node node) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "\"\"\"\n# Definition for a Node.\nclass Node(object):\n def __init__(self, val = 0, neighbors = None):\n self.val = val\n self.neighbors = neighbors if neighbors is not None else []\n\"\"\"\n\nclass Solution(object):\n def cloneGraph(self, node):\n \"\"\"\n :type node: Node\n :rtype: Node\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "\"\"\"\n# Definition for a Node.\nclass Node:\n def __init__(self, val = 0, neighbors = None):\n self.val = val\n self.neighbors = neighbors if neighbors is not None else []\n\"\"\"\n\nclass Solution:\n def cloneGraph(self, node: 'Node') -> 'Node':\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a Node.\n * struct Node {\n * int val;\n * int numNeighbors;\n * struct Node** neighbors;\n * };\n */\n\nstruct Node *cloneGraph(struct Node *s) {\n\t\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/*\n// Definition for a Node.\npublic class Node {\n public int val;\n public IList neighbors;\n\n public Node() {\n val = 0;\n neighbors = new List();\n }\n\n public Node(int _val) {\n val = _val;\n neighbors = new List();\n }\n\n public Node(int _val, List _neighbors) {\n val = _val;\n neighbors = _neighbors;\n }\n}\n*/\n\npublic class Solution {\n public Node CloneGraph(Node node) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // Definition for a Node.\n * function Node(val, neighbors) {\n * this.val = val === undefined ? 0 : val;\n * this.neighbors = neighbors === undefined ? [] : neighbors;\n * };\n */\n\n/**\n * @param {Node} node\n * @return {Node}\n */\nvar cloneGraph = function(node) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a Node.\n# class Node\n# attr_accessor :val, :neighbors\n# def initialize(val = 0, neighbors = nil)\n#\t\t @val = val\n#\t\t neighbors = [] if neighbors.nil?\n# @neighbors = neighbors\n# end\n# end\n\n# @param {Node} node\n# @return {Node}\ndef cloneGraph(node)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a Node.\n * public class Node {\n * public var val: Int\n * public var neighbors: [Node?]\n * public init(_ val: Int) {\n * self.val = val\n * self.neighbors = []\n * }\n * }\n */\n\nclass Solution {\n func cloneGraph(_ node: Node?) -> Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a Node.\n * type Node struct {\n * Val int\n * Neighbors []*Node\n * }\n */\n\nfunc cloneGraph(node *Node) *Node {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a Node.\n * class Node(var _value: Int) {\n * var value: Int = _value\n * var neighbors: List[Node] = List()\n * }\n */\n\nobject Solution {\n def cloneGraph(graph: Node): Node = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a Node.\n * class Node(var `val`: Int) {\n * var neighbors: ArrayList = ArrayList()\n * }\n */\n\nclass Solution {\n fun cloneGraph(node: Node?): Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a Node.\n * class Node {\n * public $val = null;\n * public $neighbors = null;\n * function __construct($val = 0) {\n * $this->val = $val;\n * $this->neighbors = array();\n * }\n * }\n */\n\nclass Solution {\n /**\n * @param Node $node\n * @return Node\n */\n function cloneGraph($node) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for Node.\n * class Node {\n * val: number\n * neighbors: Node[]\n * constructor(val?: number, neighbors?: Node[]) {\n * this.val = (val===undefined ? 0 : val)\n * this.neighbors = (neighbors===undefined ? [] : neighbors)\n * }\n * }\n */\n\nfunction cloneGraph(node: Node | null): Node | null {\n\t\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0133](https://leetcode-cn.com/problems/clone-graph)", "[\u514b\u9686\u56fe](/solution/0100-0199/0133.Clone%20Graph/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u56fe`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0133](https://leetcode.com/problems/clone-graph)", "[Clone Graph](/solution/0100-0199/0133.Clone%20Graph/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`,`Graph`", "Medium", ""]}, {"question_id": "0132", "frontend_question_id": "0132", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/palindrome-partitioning-ii", "url_en": "https://leetcode.com/problems/palindrome-partitioning-ii", "relative_path_cn": "/solution/0100-0199/0132.Palindrome%20Partitioning%20II/README.md", "relative_path_en": "/solution/0100-0199/0132.Palindrome%20Partitioning%20II/README_EN.md", "title_cn": "\u5206\u5272\u56de\u6587\u4e32 II", "title_en": "Palindrome Partitioning II", "question_title_slug": "palindrome-partitioning-ii", "content_en": "

    Given a string s, partition s such that every substring of the partition is a palindrome.

    \n\n

    Return the minimum cuts needed for a palindrome partitioning of s.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "aab"\nOutput: 1\nExplanation: The palindrome partitioning ["aa","b"] could be produced using 1 cut.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "a"\nOutput: 0\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "ab"\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 2000
    • \n\t
    • s consists of lower-case English letters only.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s\uff0c\u8bf7\u4f60\u5c06 s \u5206\u5272\u6210\u4e00\u4e9b\u5b50\u4e32\uff0c\u4f7f\u6bcf\u4e2a\u5b50\u4e32\u90fd\u662f\u56de\u6587\u3002

    \n\n

    \u8fd4\u56de\u7b26\u5408\u8981\u6c42\u7684 \u6700\u5c11\u5206\u5272\u6b21\u6570 \u3002

    \n\n
    \n
    \n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"aab\"\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u53ea\u9700\u4e00\u6b21\u5206\u5272\u5c31\u53ef\u5c06\u00a0s \u5206\u5272\u6210 [\"aa\",\"b\"] \u8fd9\u6837\u4e24\u4e2a\u56de\u6587\u5b50\u4e32\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"a\"\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"ab\"\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 2000
    • \n\t
    • s \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n
    \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minCut(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minCut(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minCut(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minCut(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minCut(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinCut(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar minCut = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef min_cut(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minCut(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minCut(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minCut(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minCut(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_cut(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function minCut($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minCut(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-cut s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0132](https://leetcode-cn.com/problems/palindrome-partitioning-ii)", "[\u5206\u5272\u56de\u6587\u4e32 II](/solution/0100-0199/0132.Palindrome%20Partitioning%20II/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0132](https://leetcode.com/problems/palindrome-partitioning-ii)", "[Palindrome Partitioning II](/solution/0100-0199/0132.Palindrome%20Partitioning%20II/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "0131", "frontend_question_id": "0131", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/palindrome-partitioning", "url_en": "https://leetcode.com/problems/palindrome-partitioning", "relative_path_cn": "/solution/0100-0199/0131.Palindrome%20Partitioning/README.md", "relative_path_en": "/solution/0100-0199/0131.Palindrome%20Partitioning/README_EN.md", "title_cn": "\u5206\u5272\u56de\u6587\u4e32", "title_en": "Palindrome Partitioning", "question_title_slug": "palindrome-partitioning", "content_en": "

    Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s.

    \n\n

    A palindrome string is a string that reads the same backward as forward.

    \n\n

     

    \n

    Example 1:

    \n
    Input: s = \"aab\"\nOutput: [[\"a\",\"a\",\"b\"],[\"aa\",\"b\"]]\n

    Example 2:

    \n
    Input: s = \"a\"\nOutput: [[\"a\"]]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 16
    • \n\t
    • s contains only lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s\uff0c\u8bf7\u4f60\u5c06 s \u5206\u5272\u6210\u4e00\u4e9b\u5b50\u4e32\uff0c\u4f7f\u6bcf\u4e2a\u5b50\u4e32\u90fd\u662f \u56de\u6587\u4e32 \u3002\u8fd4\u56de s \u6240\u6709\u53ef\u80fd\u7684\u5206\u5272\u65b9\u6848\u3002

    \n\n

    \u56de\u6587\u4e32 \u662f\u6b63\u7740\u8bfb\u548c\u53cd\u7740\u8bfb\u90fd\u4e00\u6837\u7684\u5b57\u7b26\u4e32\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"aab\"\n\u8f93\u51fa\uff1a[[\"a\",\"a\",\"b\"],[\"aa\",\"b\"]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"a\"\n\u8f93\u51fa\uff1a[[\"a\"]]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 16
    • \n\t
    • s \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n", "tags_en": ["Depth-first Search", "Dynamic Programming", "Backtracking"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u52a8\u6001\u89c4\u5212", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> partition(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> partition(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def partition(self, s):\n \"\"\"\n :type s: str\n :rtype: List[List[str]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def partition(self, s: str) -> List[List[str]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nchar *** partition(char * s, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> Partition(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string[][]}\n */\nvar partition = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String[][]}\ndef partition(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func partition(_ s: String) -> [[String]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func partition(s string) [][]string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def partition(s: String): List[List[String]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun partition(s: String): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn partition(s: String) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String[][]\n */\n function partition($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function partition(s: string): string[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (partition s)\n (-> string? (listof (listof string?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0131](https://leetcode-cn.com/problems/palindrome-partitioning)", "[\u5206\u5272\u56de\u6587\u4e32](/solution/0100-0199/0131.Palindrome%20Partitioning/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u52a8\u6001\u89c4\u5212`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0131](https://leetcode.com/problems/palindrome-partitioning)", "[Palindrome Partitioning](/solution/0100-0199/0131.Palindrome%20Partitioning/README_EN.md)", "`Depth-first Search`,`Dynamic Programming`,`Backtracking`", "Medium", ""]}, {"question_id": "0130", "frontend_question_id": "0130", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/surrounded-regions", "url_en": "https://leetcode.com/problems/surrounded-regions", "relative_path_cn": "/solution/0100-0199/0130.Surrounded%20Regions/README.md", "relative_path_en": "/solution/0100-0199/0130.Surrounded%20Regions/README_EN.md", "title_cn": "\u88ab\u56f4\u7ed5\u7684\u533a\u57df", "title_en": "Surrounded Regions", "question_title_slug": "surrounded-regions", "content_en": "

    Given an m x n matrix board containing 'X' and 'O', capture all regions surrounded by 'X'.

    \n\n

    A region is captured by flipping all 'O's into 'X's in that surrounded region.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: board = [["X","X","X","X"],["X","O","O","X"],["X","X","O","X"],["X","O","X","X"]]\nOutput: [["X","X","X","X"],["X","X","X","X"],["X","X","X","X"],["X","O","X","X"]]\nExplanation: Surrounded regions should not be on the border, which means that any 'O' on the border of the board are not flipped to 'X'. Any 'O' that is not on the border and it is not connected to an 'O' on the border will be flipped to 'X'. Two cells are connected if they are adjacent cells connected horizontally or vertically.\n
    \n\n

    Example 2:

    \n\n
    \nInput: board = [["X"]]\nOutput: [["X"]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == board.length
    • \n\t
    • n == board[i].length
    • \n\t
    • 1 <= m, n <= 200
    • \n\t
    • board[i][j] is 'X' or 'O'.
    • \n
    \n", "content_cn": "\u7ed9\u4f60\u4e00\u4e2a m x n \u7684\u77e9\u9635 board \uff0c\u7531\u82e5\u5e72\u5b57\u7b26 'X' \u548c 'O' \uff0c\u627e\u5230\u6240\u6709\u88ab 'X' \u56f4\u7ed5\u7684\u533a\u57df\uff0c\u5e76\u5c06\u8fd9\u4e9b\u533a\u57df\u91cc\u6240\u6709\u7684\u00a0'O' \u7528 'X' \u586b\u5145\u3002\n
    \n
    \n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aboard = [[\"X\",\"X\",\"X\",\"X\"],[\"X\",\"O\",\"O\",\"X\"],[\"X\",\"X\",\"O\",\"X\"],[\"X\",\"O\",\"X\",\"X\"]]\n\u8f93\u51fa\uff1a[[\"X\",\"X\",\"X\",\"X\"],[\"X\",\"X\",\"X\",\"X\"],[\"X\",\"X\",\"X\",\"X\"],[\"X\",\"O\",\"X\",\"X\"]]\n\u89e3\u91ca\uff1a\u88ab\u56f4\u7ed5\u7684\u533a\u95f4\u4e0d\u4f1a\u5b58\u5728\u4e8e\u8fb9\u754c\u4e0a\uff0c\u6362\u53e5\u8bdd\u8bf4\uff0c\u4efb\u4f55\u8fb9\u754c\u4e0a\u7684\u00a0'O'\u00a0\u90fd\u4e0d\u4f1a\u88ab\u586b\u5145\u4e3a\u00a0'X'\u3002 \u4efb\u4f55\u4e0d\u5728\u8fb9\u754c\u4e0a\uff0c\u6216\u4e0d\u4e0e\u8fb9\u754c\u4e0a\u7684\u00a0'O'\u00a0\u76f8\u8fde\u7684\u00a0'O'\u00a0\u6700\u7ec8\u90fd\u4f1a\u88ab\u586b\u5145\u4e3a\u00a0'X'\u3002\u5982\u679c\u4e24\u4e2a\u5143\u7d20\u5728\u6c34\u5e73\u6216\u5782\u76f4\u65b9\u5411\u76f8\u90bb\uff0c\u5219\u79f0\u5b83\u4eec\u662f\u201c\u76f8\u8fde\u201d\u7684\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aboard = [[\"X\"]]\n\u8f93\u51fa\uff1a[[\"X\"]]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == board.length
    • \n\t
    • n == board[i].length
    • \n\t
    • 1 <= m, n <= 200
    • \n\t
    • board[i][j] \u4e3a 'X' \u6216 'O'
    • \n
    \n
    \n
    \n", "tags_en": ["Depth-first Search", "Breadth-first Search", "Union Find"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e76\u67e5\u96c6"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n void solve(vector>& board) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public void solve(char[][] board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def solve(self, board):\n \"\"\"\n :type board: List[List[str]]\n :rtype: None Do not return anything, modify board in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def solve(self, board: List[List[str]]) -> None:\n \"\"\"\n Do not return anything, modify board in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nvoid solve(char** board, int boardSize, int* boardColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public void Solve(char[][] board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {character[][]} board\n * @return {void} Do not return anything, modify board in-place instead.\n */\nvar solve = function(board) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Character[][]} board\n# @return {Void} Do not return anything, modify board in-place instead.\ndef solve(board)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func solve(_ board: inout [[Character]]) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func solve(board [][]byte) {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def solve(board: Array[Array[Char]]): Unit = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun solve(board: Array): Unit {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn solve(board: &mut Vec>) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $board\n * @return NULL\n */\n function solve(&$board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n Do not return anything, modify board in-place instead.\n */\nfunction solve(board: string[][]): void {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0130](https://leetcode-cn.com/problems/surrounded-regions)", "[\u88ab\u56f4\u7ed5\u7684\u533a\u57df](/solution/0100-0199/0130.Surrounded%20Regions/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e76\u67e5\u96c6`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0130](https://leetcode.com/problems/surrounded-regions)", "[Surrounded Regions](/solution/0100-0199/0130.Surrounded%20Regions/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`,`Union Find`", "Medium", ""]}, {"question_id": "0129", "frontend_question_id": "0129", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sum-root-to-leaf-numbers", "url_en": "https://leetcode.com/problems/sum-root-to-leaf-numbers", "relative_path_cn": "/solution/0100-0199/0129.Sum%20Root%20to%20Leaf%20Numbers/README.md", "relative_path_en": "/solution/0100-0199/0129.Sum%20Root%20to%20Leaf%20Numbers/README_EN.md", "title_cn": "\u6c42\u6839\u8282\u70b9\u5230\u53f6\u8282\u70b9\u6570\u5b57\u4e4b\u548c", "title_en": "Sum Root to Leaf Numbers", "question_title_slug": "sum-root-to-leaf-numbers", "content_en": "

    You are given the root of a binary tree containing digits from 0 to 9 only.

    \n\n

    Each root-to-leaf path in the tree represents a number.

    \n\n
      \n\t
    • For example, the root-to-leaf path 1 -> 2 -> 3 represents the number 123.
    • \n
    \n\n

    Return the total sum of all root-to-leaf numbers. Test cases are generated so that the answer will fit in a 32-bit integer.

    \n\n

    A leaf node is a node with no children.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,2,3]\nOutput: 25\nExplanation:\nThe root-to-leaf path 1->2 represents the number 12.\nThe root-to-leaf path 1->3 represents the number 13.\nTherefore, sum = 12 + 13 = 25.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [4,9,0,5,1]\nOutput: 1026\nExplanation:\nThe root-to-leaf path 4->9->5 represents the number 495.\nThe root-to-leaf path 4->9->1 represents the number 491.\nThe root-to-leaf path 4->0 represents the number 40.\nTherefore, sum = 495 + 491 + 40 = 1026.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 1000].
    • \n\t
    • 0 <= Node.val <= 9
    • \n\t
    • The depth of the tree will not exceed 10.
    • \n
    \n", "content_cn": "\u7ed9\u4f60\u4e00\u4e2a\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9 root \uff0c\u6811\u4e2d\u6bcf\u4e2a\u8282\u70b9\u90fd\u5b58\u653e\u6709\u4e00\u4e2a 0 \u5230 9 \u4e4b\u95f4\u7684\u6570\u5b57\u3002\n
    \n
    \n

    \u6bcf\u6761\u4ece\u6839\u8282\u70b9\u5230\u53f6\u8282\u70b9\u7684\u8def\u5f84\u90fd\u4ee3\u8868\u4e00\u4e2a\u6570\u5b57\uff1a

    \n\n
      \n\t
    • \u4f8b\u5982\uff0c\u4ece\u6839\u8282\u70b9\u5230\u53f6\u8282\u70b9\u7684\u8def\u5f84 1 -> 2 -> 3 \u8868\u793a\u6570\u5b57 123 \u3002
    • \n
    \n\n

    \u8ba1\u7b97\u4ece\u6839\u8282\u70b9\u5230\u53f6\u8282\u70b9\u751f\u6210\u7684 \u6240\u6709\u6570\u5b57\u4e4b\u548c \u3002

    \n\n

    \u53f6\u8282\u70b9 \u662f\u6307\u6ca1\u6709\u5b50\u8282\u70b9\u7684\u8282\u70b9\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [1,2,3]\n\u8f93\u51fa\uff1a25\n\u89e3\u91ca\uff1a\n\u4ece\u6839\u5230\u53f6\u5b50\u8282\u70b9\u8def\u5f84 1->2 \u4ee3\u8868\u6570\u5b57 12\n\u4ece\u6839\u5230\u53f6\u5b50\u8282\u70b9\u8def\u5f84 1->3 \u4ee3\u8868\u6570\u5b57 13\n\u56e0\u6b64\uff0c\u6570\u5b57\u603b\u548c = 12 + 13 = 25
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [4,9,0,5,1]\n\u8f93\u51fa\uff1a1026\n\u89e3\u91ca\uff1a\n\u4ece\u6839\u5230\u53f6\u5b50\u8282\u70b9\u8def\u5f84 4->9->5 \u4ee3\u8868\u6570\u5b57 495\n\u4ece\u6839\u5230\u53f6\u5b50\u8282\u70b9\u8def\u5f84 4->9->1 \u4ee3\u8868\u6570\u5b57 491\n\u4ece\u6839\u5230\u53f6\u5b50\u8282\u70b9\u8def\u5f84 4->0 \u4ee3\u8868\u6570\u5b57 40\n\u56e0\u6b64\uff0c\u6570\u5b57\u603b\u548c = 495 + 491 + 40 = 1026\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u7684\u6570\u76ee\u5728\u8303\u56f4 [1, 1000] \u5185
    • \n\t
    • 0 <= Node.val <= 9
    • \n\t
    • \u6811\u7684\u6df1\u5ea6\u4e0d\u8d85\u8fc7 10
    • \n
    \n
    \n
    \n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int sumNumbers(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int sumNumbers(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def sumNumbers(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def sumNumbers(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint sumNumbers(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int SumNumbers(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar sumNumbers = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef sum_numbers(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func sumNumbers(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc sumNumbers(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def sumNumbers(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun sumNumbers(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn sum_numbers(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function sumNumbers($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction sumNumbers(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (sum-numbers root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0129](https://leetcode-cn.com/problems/sum-root-to-leaf-numbers)", "[\u6c42\u6839\u8282\u70b9\u5230\u53f6\u8282\u70b9\u6570\u5b57\u4e4b\u548c](/solution/0100-0199/0129.Sum%20Root%20to%20Leaf%20Numbers/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0129](https://leetcode.com/problems/sum-root-to-leaf-numbers)", "[Sum Root to Leaf Numbers](/solution/0100-0199/0129.Sum%20Root%20to%20Leaf%20Numbers/README_EN.md)", "`Tree`,`Depth-first Search`", "Medium", ""]}, {"question_id": "0128", "frontend_question_id": "0128", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-consecutive-sequence", "url_en": "https://leetcode.com/problems/longest-consecutive-sequence", "relative_path_cn": "/solution/0100-0199/0128.Longest%20Consecutive%20Sequence/README.md", "relative_path_en": "/solution/0100-0199/0128.Longest%20Consecutive%20Sequence/README_EN.md", "title_cn": "\u6700\u957f\u8fde\u7eed\u5e8f\u5217", "title_en": "Longest Consecutive Sequence", "question_title_slug": "longest-consecutive-sequence", "content_en": "

    Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence.

    \n\n

    You must write an algorithm that runs in O(n) time.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [100,4,200,1,3,2]\nOutput: 4\nExplanation: The longest consecutive elements sequence is [1, 2, 3, 4]. Therefore its length is 4.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [0,3,7,2,5,8,4,6,0,1]\nOutput: 9\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= nums.length <= 105
    • \n\t
    • -109 <= nums[i] <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u672a\u6392\u5e8f\u7684\u6574\u6570\u6570\u7ec4 nums \uff0c\u627e\u51fa\u6570\u5b57\u8fde\u7eed\u7684\u6700\u957f\u5e8f\u5217\uff08\u4e0d\u8981\u6c42\u5e8f\u5217\u5143\u7d20\u5728\u539f\u6570\u7ec4\u4e2d\u8fde\u7eed\uff09\u7684\u957f\u5ea6\u3002

    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u53ef\u4ee5\u8bbe\u8ba1\u5e76\u5b9e\u73b0\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a\u00a0O(n) \u7684\u89e3\u51b3\u65b9\u6848\u5417\uff1f

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [100,4,200,1,3,2]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u6700\u957f\u6570\u5b57\u8fde\u7eed\u5e8f\u5217\u662f [1, 2, 3, 4]\u3002\u5b83\u7684\u957f\u5ea6\u4e3a 4\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [0,3,7,2,5,8,4,6,0,1]\n\u8f93\u51fa\uff1a9\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= nums.length <= 104
    • \n\t
    • -109 <= nums[i] <= 109
    • \n
    \n", "tags_en": ["Union Find", "Array"], "tags_cn": ["\u5e76\u67e5\u96c6", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int longestConsecutive(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int longestConsecutive(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestConsecutive(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestConsecutive(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint longestConsecutive(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LongestConsecutive(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar longestConsecutive = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef longest_consecutive(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestConsecutive(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestConsecutive(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestConsecutive(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestConsecutive(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_consecutive(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function longestConsecutive($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestConsecutive(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-consecutive nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0128](https://leetcode-cn.com/problems/longest-consecutive-sequence)", "[\u6700\u957f\u8fde\u7eed\u5e8f\u5217](/solution/0100-0199/0128.Longest%20Consecutive%20Sequence/README.md)", "`\u5e76\u67e5\u96c6`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0128](https://leetcode.com/problems/longest-consecutive-sequence)", "[Longest Consecutive Sequence](/solution/0100-0199/0128.Longest%20Consecutive%20Sequence/README_EN.md)", "`Union Find`,`Array`", "Medium", ""]}, {"question_id": "0127", "frontend_question_id": "0127", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/word-ladder", "url_en": "https://leetcode.com/problems/word-ladder", "relative_path_cn": "/solution/0100-0199/0127.Word%20Ladder/README.md", "relative_path_en": "/solution/0100-0199/0127.Word%20Ladder/README_EN.md", "title_cn": "\u5355\u8bcd\u63a5\u9f99", "title_en": "Word Ladder", "question_title_slug": "word-ladder", "content_en": "

    A transformation sequence from word beginWord to word endWord using a dictionary wordList is a sequence of words beginWord -> s1 -> s2 -> ... -> sk such that:

    \n\n
      \n\t
    • Every adjacent pair of words differs by a single letter.
    • \n\t
    • Every si for 1 <= i <= k is in wordList. Note that beginWord does not need to be in wordList.
    • \n\t
    • sk == endWord
    • \n
    \n\n

    Given two words, beginWord and endWord, and a dictionary wordList, return the number of words in the shortest transformation sequence from beginWord to endWord, or 0 if no such sequence exists.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: beginWord = "hit", endWord = "cog", wordList = ["hot","dot","dog","lot","log","cog"]\nOutput: 5\nExplanation: One shortest transformation sequence is "hit" -> "hot" -> "dot" -> "dog" -> cog", which is 5 words long.\n
    \n\n

    Example 2:

    \n\n
    \nInput: beginWord = "hit", endWord = "cog", wordList = ["hot","dot","dog","lot","log"]\nOutput: 0\nExplanation: The endWord "cog" is not in wordList, therefore there is no valid transformation sequence.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= beginWord.length <= 10
    • \n\t
    • endWord.length == beginWord.length
    • \n\t
    • 1 <= wordList.length <= 5000
    • \n\t
    • wordList[i].length == beginWord.length
    • \n\t
    • beginWord, endWord, and wordList[i] consist of lowercase English letters.
    • \n\t
    • beginWord != endWord
    • \n\t
    • All the words in wordList are unique.
    • \n
    \n", "content_cn": "

    \u5b57\u5178\u00a0wordList \u4e2d\u4ece\u5355\u8bcd beginWord\u00a0\u548c endWord \u7684 \u8f6c\u6362\u5e8f\u5217 \u662f\u4e00\u4e2a\u6309\u4e0b\u8ff0\u89c4\u683c\u5f62\u6210\u7684\u5e8f\u5217\uff1a

    \n\n
      \n\t
    • \u5e8f\u5217\u4e2d\u7b2c\u4e00\u4e2a\u5355\u8bcd\u662f beginWord \u3002
    • \n\t
    • \u5e8f\u5217\u4e2d\u6700\u540e\u4e00\u4e2a\u5355\u8bcd\u662f endWord \u3002
    • \n\t
    • \u6bcf\u6b21\u8f6c\u6362\u53ea\u80fd\u6539\u53d8\u4e00\u4e2a\u5b57\u6bcd\u3002
    • \n\t
    • \u8f6c\u6362\u8fc7\u7a0b\u4e2d\u7684\u4e2d\u95f4\u5355\u8bcd\u5fc5\u987b\u662f\u5b57\u5178\u00a0wordList \u4e2d\u7684\u5355\u8bcd\u3002
    • \n
    \n\n

    \u7ed9\u4f60\u4e24\u4e2a\u5355\u8bcd beginWord\u00a0\u548c endWord \u548c\u4e00\u4e2a\u5b57\u5178 wordList \uff0c\u627e\u5230\u4ece\u00a0beginWord \u5230\u00a0endWord \u7684 \u6700\u77ed\u8f6c\u6362\u5e8f\u5217 \u4e2d\u7684 \u5355\u8bcd\u6570\u76ee \u3002\u5982\u679c\u4e0d\u5b58\u5728\u8fd9\u6837\u7684\u8f6c\u6362\u5e8f\u5217\uff0c\u8fd4\u56de 0\u3002

    \n\u00a0\n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1abeginWord = \"hit\", endWord = \"cog\", wordList = [\"hot\",\"dot\",\"dog\",\"lot\",\"log\",\"cog\"]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u4e00\u4e2a\u6700\u77ed\u8f6c\u6362\u5e8f\u5217\u662f \"hit\" -> \"hot\" -> \"dot\" -> \"dog\" -> \"cog\", \u8fd4\u56de\u5b83\u7684\u957f\u5ea6 5\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1abeginWord = \"hit\", endWord = \"cog\", wordList = [\"hot\",\"dot\",\"dog\",\"lot\",\"log\"]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1aendWord \"cog\" \u4e0d\u5728\u5b57\u5178\u4e2d\uff0c\u6240\u4ee5\u65e0\u6cd5\u8fdb\u884c\u8f6c\u6362\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= beginWord.length <= 10
    • \n\t
    • endWord.length == beginWord.length
    • \n\t
    • 1 <= wordList.length <= 5000
    • \n\t
    • wordList[i].length == beginWord.length
    • \n\t
    • beginWord\u3001endWord \u548c wordList[i] \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n\t
    • beginWord != endWord
    • \n\t
    • wordList \u4e2d\u7684\u6240\u6709\u5b57\u7b26\u4e32 \u4e92\u4e0d\u76f8\u540c
    • \n
    \n", "tags_en": ["Breadth-first Search"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int ladderLength(string beginWord, string endWord, vector& wordList) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int ladderLength(String beginWord, String endWord, List wordList) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def ladderLength(self, beginWord, endWord, wordList):\n \"\"\"\n :type beginWord: str\n :type endWord: str\n :type wordList: List[str]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def ladderLength(self, beginWord: str, endWord: str, wordList: List[str]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint ladderLength(char * beginWord, char * endWord, char ** wordList, int wordListSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LadderLength(string beginWord, string endWord, IList wordList) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} beginWord\n * @param {string} endWord\n * @param {string[]} wordList\n * @return {number}\n */\nvar ladderLength = function(beginWord, endWord, wordList) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} begin_word\n# @param {String} end_word\n# @param {String[]} word_list\n# @return {Integer}\ndef ladder_length(begin_word, end_word, word_list)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func ladderLength(_ beginWord: String, _ endWord: String, _ wordList: [String]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func ladderLength(beginWord string, endWord string, wordList []string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def ladderLength(beginWord: String, endWord: String, wordList: List[String]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun ladderLength(beginWord: String, endWord: String, wordList: List): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn ladder_length(begin_word: String, end_word: String, word_list: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $beginWord\n * @param String $endWord\n * @param String[] $wordList\n * @return Integer\n */\n function ladderLength($beginWord, $endWord, $wordList) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function ladderLength(beginWord: string, endWord: string, wordList: string[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (ladder-length beginWord endWord wordList)\n (-> string? string? (listof string?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0127](https://leetcode-cn.com/problems/word-ladder)", "[\u5355\u8bcd\u63a5\u9f99](/solution/0100-0199/0127.Word%20Ladder/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[0127](https://leetcode.com/problems/word-ladder)", "[Word Ladder](/solution/0100-0199/0127.Word%20Ladder/README_EN.md)", "`Breadth-first Search`", "Hard", ""]}, {"question_id": "0126", "frontend_question_id": "0126", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/word-ladder-ii", "url_en": "https://leetcode.com/problems/word-ladder-ii", "relative_path_cn": "/solution/0100-0199/0126.Word%20Ladder%20II/README.md", "relative_path_en": "/solution/0100-0199/0126.Word%20Ladder%20II/README_EN.md", "title_cn": "\u5355\u8bcd\u63a5\u9f99 II", "title_en": "Word Ladder II", "question_title_slug": "word-ladder-ii", "content_en": "

    A transformation sequence from word beginWord to word endWord using a dictionary wordList is a sequence of words beginWord -> s1 -> s2 -> ... -> sk such that:

    \n\n
      \n\t
    • Every adjacent pair of words differs by a single letter.
    • \n\t
    • Every si for 1 <= i <= k is in wordList. Note that beginWord does not need to be in wordList.
    • \n\t
    • sk == endWord
    • \n
    \n\n

    Given two words, beginWord and endWord, and a dictionary wordList, return all the shortest transformation sequences from beginWord to endWord, or an empty list if no such sequence exists. Each sequence should be returned as a list of the words [beginWord, s1, s2, ..., sk].

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: beginWord = "hit", endWord = "cog", wordList = ["hot","dot","dog","lot","log","cog"]\nOutput: [["hit","hot","dot","dog","cog"],["hit","hot","lot","log","cog"]]\nExplanation: There are 2 shortest transformation sequences:\n"hit" -> "hot" -> "dot" -> "dog" -> "cog"\n"hit" -> "hot" -> "lot" -> "log" -> "cog"\n
    \n\n

    Example 2:

    \n\n
    \nInput: beginWord = "hit", endWord = "cog", wordList = ["hot","dot","dog","lot","log"]\nOutput: []\nExplanation: The endWord "cog" is not in wordList, therefore there is no valid transformation sequence.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= beginWord.length <= 5
    • \n\t
    • endWord.length == beginWord.length
    • \n\t
    • 1 <= wordList.length <= 1000
    • \n\t
    • wordList[i].length == beginWord.length
    • \n\t
    • beginWord, endWord, and wordList[i] consist of lowercase English letters.
    • \n\t
    • beginWord != endWord
    • \n\t
    • All the words in wordList are unique.
    • \n
    \n", "content_cn": "

    \u6309\u5b57\u5178\u00a0wordList \u5b8c\u6210\u4ece\u5355\u8bcd beginWord \u5230\u5355\u8bcd endWord \u8f6c\u5316\uff0c\u4e00\u4e2a\u8868\u793a\u6b64\u8fc7\u7a0b\u7684 \u8f6c\u6362\u5e8f\u5217 \u662f\u5f62\u5f0f\u4e0a\u50cf beginWord -> s1 -> s2 -> ... -> sk \u8fd9\u6837\u7684\u5355\u8bcd\u5e8f\u5217\uff0c\u5e76\u6ee1\u8db3\uff1a

    \n\n
    \n
    \n
      \n\t
    • \u6bcf\u5bf9\u76f8\u90bb\u7684\u5355\u8bcd\u4e4b\u95f4\u4ec5\u6709\u5355\u4e2a\u5b57\u6bcd\u4e0d\u540c\u3002
    • \n\t
    • \u8f6c\u6362\u8fc7\u7a0b\u4e2d\u7684\u6bcf\u4e2a\u5355\u8bcd si\uff081 <= i <= k\uff09\u5fc5\u987b\u662f\u5b57\u5178\u00a0wordList \u4e2d\u7684\u5355\u8bcd\u3002\u6ce8\u610f\uff0cbeginWord \u4e0d\u5fc5\u662f\u5b57\u5178 wordList \u4e2d\u7684\u5355\u8bcd\u3002
    • \n\t
    • sk == endWord
    • \n
    \n\n

    \u7ed9\u4f60\u4e24\u4e2a\u5355\u8bcd beginWord \u548c endWord \uff0c\u4ee5\u53ca\u4e00\u4e2a\u5b57\u5178 wordList \u3002\u8bf7\u4f60\u627e\u51fa\u5e76\u8fd4\u56de\u6240\u6709\u4ece beginWord \u5230 endWord \u7684 \u6700\u77ed\u8f6c\u6362\u5e8f\u5217 \uff0c\u5982\u679c\u4e0d\u5b58\u5728\u8fd9\u6837\u7684\u8f6c\u6362\u5e8f\u5217\uff0c\u8fd4\u56de\u4e00\u4e2a\u7a7a\u5217\u8868\u3002\u6bcf\u4e2a\u5e8f\u5217\u90fd\u5e94\u8be5\u4ee5\u5355\u8bcd\u5217\u8868 [beginWord, s1, s2, ..., sk] \u7684\u5f62\u5f0f\u8fd4\u56de\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1abeginWord = \"hit\", endWord = \"cog\", wordList = [\"hot\",\"dot\",\"dog\",\"lot\",\"log\",\"cog\"]\n\u8f93\u51fa\uff1a[[\"hit\",\"hot\",\"dot\",\"dog\",\"cog\"],[\"hit\",\"hot\",\"lot\",\"log\",\"cog\"]]\n\u89e3\u91ca\uff1a\u5b58\u5728 2 \u79cd\u6700\u77ed\u7684\u8f6c\u6362\u5e8f\u5217\uff1a\n\"hit\" -> \"hot\" -> \"dot\" -> \"dog\" -> \"cog\"\n\"hit\" -> \"hot\" -> \"lot\" -> \"log\" -> \"cog\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1abeginWord = \"hit\", endWord = \"cog\", wordList = [\"hot\",\"dot\",\"dog\",\"lot\",\"log\"]\n\u8f93\u51fa\uff1a[]\n\u89e3\u91ca\uff1aendWord \"cog\" \u4e0d\u5728\u5b57\u5178 wordList \u4e2d\uff0c\u6240\u4ee5\u4e0d\u5b58\u5728\u7b26\u5408\u8981\u6c42\u7684\u8f6c\u6362\u5e8f\u5217\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= beginWord.length <= 7
    • \n\t
    • endWord.length == beginWord.length
    • \n\t
    • 1 <= wordList.length <= 5000
    • \n\t
    • wordList[i].length == beginWord.length
    • \n\t
    • beginWord\u3001endWord \u548c wordList[i] \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n\t
    • beginWord != endWord
    • \n\t
    • wordList \u4e2d\u7684\u6240\u6709\u5355\u8bcd \u4e92\u4e0d\u76f8\u540c
    • \n
    \n
    \n
    \n", "tags_en": ["Breadth-first Search", "Array", "String", "Backtracking"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u6570\u7ec4", "\u5b57\u7b26\u4e32", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> findLadders(string beginWord, string endWord, vector& wordList) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> findLadders(String beginWord, String endWord, List wordList) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findLadders(self, beginWord, endWord, wordList):\n \"\"\"\n :type beginWord: str\n :type endWord: str\n :type wordList: List[str]\n :rtype: List[List[str]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findLadders(self, beginWord: str, endWord: str, wordList: List[str]) -> List[List[str]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nchar *** findLadders(char * beginWord, char * endWord, char ** wordList, int wordListSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> FindLadders(string beginWord, string endWord, IList wordList) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} beginWord\n * @param {string} endWord\n * @param {string[]} wordList\n * @return {string[][]}\n */\nvar findLadders = function(beginWord, endWord, wordList) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} begin_word\n# @param {String} end_word\n# @param {String[]} word_list\n# @return {String[][]}\ndef find_ladders(begin_word, end_word, word_list)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findLadders(_ beginWord: String, _ endWord: String, _ wordList: [String]) -> [[String]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findLadders(beginWord string, endWord string, wordList []string) [][]string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findLadders(beginWord: String, endWord: String, wordList: List[String]): List[List[String]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findLadders(beginWord: String, endWord: String, wordList: List): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_ladders(begin_word: String, end_word: String, word_list: Vec) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $beginWord\n * @param String $endWord\n * @param String[] $wordList\n * @return String[][]\n */\n function findLadders($beginWord, $endWord, $wordList) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findLadders(beginWord: string, endWord: string, wordList: string[]): string[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-ladders beginWord endWord wordList)\n (-> string? string? (listof string?) (listof (listof string?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0126](https://leetcode-cn.com/problems/word-ladder-ii)", "[\u5355\u8bcd\u63a5\u9f99 II](/solution/0100-0199/0126.Word%20Ladder%20II/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u6570\u7ec4`,`\u5b57\u7b26\u4e32`,`\u56de\u6eaf\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[0126](https://leetcode.com/problems/word-ladder-ii)", "[Word Ladder II](/solution/0100-0199/0126.Word%20Ladder%20II/README_EN.md)", "`Breadth-first Search`,`Array`,`String`,`Backtracking`", "Hard", ""]}, {"question_id": "0125", "frontend_question_id": "0125", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/valid-palindrome", "url_en": "https://leetcode.com/problems/valid-palindrome", "relative_path_cn": "/solution/0100-0199/0125.Valid%20Palindrome/README.md", "relative_path_en": "/solution/0100-0199/0125.Valid%20Palindrome/README_EN.md", "title_cn": "\u9a8c\u8bc1\u56de\u6587\u4e32", "title_en": "Valid Palindrome", "question_title_slug": "valid-palindrome", "content_en": "

    Given a string s, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "A man, a plan, a canal: Panama"\nOutput: true\nExplanation: "amanaplanacanalpanama" is a palindrome.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "race a car"\nOutput: false\nExplanation: "raceacar" is not a palindrome.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 2 * 105
    • \n\t
    • s consists only of printable ASCII characters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u9a8c\u8bc1\u5b83\u662f\u5426\u662f\u56de\u6587\u4e32\uff0c\u53ea\u8003\u8651\u5b57\u6bcd\u548c\u6570\u5b57\u5b57\u7b26\uff0c\u53ef\u4ee5\u5ffd\u7565\u5b57\u6bcd\u7684\u5927\u5c0f\u5199\u3002

    \n\n

    \u8bf4\u660e\uff1a\u672c\u9898\u4e2d\uff0c\u6211\u4eec\u5c06\u7a7a\u5b57\u7b26\u4e32\u5b9a\u4e49\u4e3a\u6709\u6548\u7684\u56de\u6587\u4e32\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: "A man, a plan, a canal: Panama"\n\u8f93\u51fa: true\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: "race a car"\n\u8f93\u51fa: false\n
    \n", "tags_en": ["Two Pointers", "String"], "tags_cn": ["\u53cc\u6307\u9488", "\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isPalindrome(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isPalindrome(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isPalindrome(self, s):\n \"\"\"\n :type s: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isPalindrome(self, s: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isPalindrome(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsPalindrome(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {boolean}\n */\nvar isPalindrome = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Boolean}\ndef is_palindrome(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isPalindrome(_ s: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isPalindrome(s string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isPalindrome(s: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isPalindrome(s: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_palindrome(s: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Boolean\n */\n function isPalindrome($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isPalindrome(s: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-palindrome s)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0125](https://leetcode-cn.com/problems/valid-palindrome)", "[\u9a8c\u8bc1\u56de\u6587\u4e32](/solution/0100-0199/0125.Valid%20Palindrome/README.md)", "`\u53cc\u6307\u9488`,`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0125](https://leetcode.com/problems/valid-palindrome)", "[Valid Palindrome](/solution/0100-0199/0125.Valid%20Palindrome/README_EN.md)", "`Two Pointers`,`String`", "Easy", ""]}, {"question_id": "0124", "frontend_question_id": "0124", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/binary-tree-maximum-path-sum", "url_en": "https://leetcode.com/problems/binary-tree-maximum-path-sum", "relative_path_cn": "/solution/0100-0199/0124.Binary%20Tree%20Maximum%20Path%20Sum/README.md", "relative_path_en": "/solution/0100-0199/0124.Binary%20Tree%20Maximum%20Path%20Sum/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u4e2d\u7684\u6700\u5927\u8def\u5f84\u548c", "title_en": "Binary Tree Maximum Path Sum", "question_title_slug": "binary-tree-maximum-path-sum", "content_en": "

    A path in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence at most once. Note that the path does not need to pass through the root.

    \n\n

    The path sum of a path is the sum of the node's values in the path.

    \n\n

    Given the root of a binary tree, return the maximum path sum of any path.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,2,3]\nOutput: 6\nExplanation: The optimal path is 2 -> 1 -> 3 with a path sum of 2 + 1 + 3 = 6.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [-10,9,20,null,null,15,7]\nOutput: 42\nExplanation: The optimal path is 15 -> 20 -> 7 with a path sum of 15 + 20 + 7 = 42.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 3 * 104].
    • \n\t
    • -1000 <= Node.val <= 1000
    • \n
    \n", "content_cn": "

    \u8def\u5f84 \u88ab\u5b9a\u4e49\u4e3a\u4e00\u6761\u4ece\u6811\u4e2d\u4efb\u610f\u8282\u70b9\u51fa\u53d1\uff0c\u6cbf\u7236\u8282\u70b9-\u5b50\u8282\u70b9\u8fde\u63a5\uff0c\u8fbe\u5230\u4efb\u610f\u8282\u70b9\u7684\u5e8f\u5217\u3002\u540c\u4e00\u4e2a\u8282\u70b9\u5728\u4e00\u6761\u8def\u5f84\u5e8f\u5217\u4e2d \u81f3\u591a\u51fa\u73b0\u4e00\u6b21 \u3002\u8be5\u8def\u5f84 \u81f3\u5c11\u5305\u542b\u4e00\u4e2a \u8282\u70b9\uff0c\u4e14\u4e0d\u4e00\u5b9a\u7ecf\u8fc7\u6839\u8282\u70b9\u3002

    \n\n

    \u8def\u5f84\u548c \u662f\u8def\u5f84\u4e2d\u5404\u8282\u70b9\u503c\u7684\u603b\u548c\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9 root \uff0c\u8fd4\u56de\u5176 \u6700\u5927\u8def\u5f84\u548c \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [1,2,3]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u6700\u4f18\u8def\u5f84\u662f 2 -> 1 -> 3 \uff0c\u8def\u5f84\u548c\u4e3a 2 + 1 + 3 = 6
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [-10,9,20,null,null,15,7]\n\u8f93\u51fa\uff1a42\n\u89e3\u91ca\uff1a\u6700\u4f18\u8def\u5f84\u662f 15 -> 20 -> 7 \uff0c\u8def\u5f84\u548c\u4e3a 15 + 20 + 7 = 42\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u6570\u76ee\u8303\u56f4\u662f [1, 3 * 104]
    • \n\t
    • -1000 <= Node.val <= 1000
    • \n
    \n", "tags_en": ["Tree", "Depth-first Search", "Recursion"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u9012\u5f52"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int maxPathSum(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int maxPathSum(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def maxPathSum(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def maxPathSum(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint maxPathSum(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int MaxPathSum(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar maxPathSum = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef max_path_sum(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func maxPathSum(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc maxPathSum(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def maxPathSum(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun maxPathSum(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn max_path_sum(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function maxPathSum($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction maxPathSum(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (max-path-sum root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0124](https://leetcode-cn.com/problems/binary-tree-maximum-path-sum)", "[\u4e8c\u53c9\u6811\u4e2d\u7684\u6700\u5927\u8def\u5f84\u548c](/solution/0100-0199/0124.Binary%20Tree%20Maximum%20Path%20Sum/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u9012\u5f52`", "\u56f0\u96be", ""], "md_table_row_en": ["[0124](https://leetcode.com/problems/binary-tree-maximum-path-sum)", "[Binary Tree Maximum Path Sum](/solution/0100-0199/0124.Binary%20Tree%20Maximum%20Path%20Sum/README_EN.md)", "`Tree`,`Depth-first Search`,`Recursion`", "Hard", ""]}, {"question_id": "0123", "frontend_question_id": "0123", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-iii", "url_en": "https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iii", "relative_path_cn": "/solution/0100-0199/0123.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20III/README.md", "relative_path_en": "/solution/0100-0199/0123.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20III/README_EN.md", "title_cn": "\u4e70\u5356\u80a1\u7968\u7684\u6700\u4f73\u65f6\u673a III", "title_en": "Best Time to Buy and Sell Stock III", "question_title_slug": "best-time-to-buy-and-sell-stock-iii", "content_en": "

    You are given an array prices where prices[i] is the price of a given stock on the ith day.

    \n\n

    Find the maximum profit you can achieve. You may complete at most two transactions.

    \n\n

    Note: You may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again).

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: prices = [3,3,5,0,0,3,1,4]\nOutput: 6\nExplanation: Buy on day 4 (price = 0) and sell on day 6 (price = 3), profit = 3-0 = 3.\nThen buy on day 7 (price = 1) and sell on day 8 (price = 4), profit = 4-1 = 3.
    \n\n

    Example 2:

    \n\n
    \nInput: prices = [1,2,3,4,5]\nOutput: 4\nExplanation: Buy on day 1 (price = 1) and sell on day 5 (price = 5), profit = 5-1 = 4.\nNote that you cannot buy on day 1, buy on day 2 and sell them later, as you are engaging multiple transactions at the same time. You must sell before buying again.\n
    \n\n

    Example 3:

    \n\n
    \nInput: prices = [7,6,4,3,1]\nOutput: 0\nExplanation: In this case, no transaction is done, i.e. max profit = 0.\n
    \n\n

    Example 4:

    \n\n
    \nInput: prices = [1]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= prices.length <= 105
    • \n\t
    • 0 <= prices[i] <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6570\u7ec4\uff0c\u5b83\u7684\u7b2c i \u4e2a\u5143\u7d20\u662f\u4e00\u652f\u7ed9\u5b9a\u7684\u80a1\u7968\u5728\u7b2c i \u5929\u7684\u4ef7\u683c\u3002

    \n\n

    \u8bbe\u8ba1\u4e00\u4e2a\u7b97\u6cd5\u6765\u8ba1\u7b97\u4f60\u6240\u80fd\u83b7\u53d6\u7684\u6700\u5927\u5229\u6da6\u3002\u4f60\u6700\u591a\u53ef\u4ee5\u5b8c\u6210\u00a0\u4e24\u7b14\u00a0\u4ea4\u6613\u3002

    \n\n

    \u6ce8\u610f\uff1a\u4f60\u4e0d\u80fd\u540c\u65f6\u53c2\u4e0e\u591a\u7b14\u4ea4\u6613\uff08\u4f60\u5fc5\u987b\u5728\u518d\u6b21\u8d2d\u4e70\u524d\u51fa\u552e\u6389\u4e4b\u524d\u7684\u80a1\u7968\uff09\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\u00a01:

    \n\n
    \n\u8f93\u5165\uff1aprices = [3,3,5,0,0,3,1,4]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u5728\u7b2c 4 \u5929\uff08\u80a1\u7968\u4ef7\u683c = 0\uff09\u7684\u65f6\u5019\u4e70\u5165\uff0c\u5728\u7b2c 6 \u5929\uff08\u80a1\u7968\u4ef7\u683c = 3\uff09\u7684\u65f6\u5019\u5356\u51fa\uff0c\u8fd9\u7b14\u4ea4\u6613\u6240\u80fd\u83b7\u5f97\u5229\u6da6 = 3-0 = 3 \u3002\n\u00a0    \u968f\u540e\uff0c\u5728\u7b2c 7 \u5929\uff08\u80a1\u7968\u4ef7\u683c = 1\uff09\u7684\u65f6\u5019\u4e70\u5165\uff0c\u5728\u7b2c 8 \u5929 \uff08\u80a1\u7968\u4ef7\u683c = 4\uff09\u7684\u65f6\u5019\u5356\u51fa\uff0c\u8fd9\u7b14\u4ea4\u6613\u6240\u80fd\u83b7\u5f97\u5229\u6da6 = 4-1 = 3 \u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aprices = [1,2,3,4,5]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u5728\u7b2c 1 \u5929\uff08\u80a1\u7968\u4ef7\u683c = 1\uff09\u7684\u65f6\u5019\u4e70\u5165\uff0c\u5728\u7b2c 5 \u5929 \uff08\u80a1\u7968\u4ef7\u683c = 5\uff09\u7684\u65f6\u5019\u5356\u51fa, \u8fd9\u7b14\u4ea4\u6613\u6240\u80fd\u83b7\u5f97\u5229\u6da6 = 5-1 = 4 \u3002 \u00a0 \n\u00a0    \u6ce8\u610f\u4f60\u4e0d\u80fd\u5728\u7b2c 1 \u5929\u548c\u7b2c 2 \u5929\u63a5\u8fde\u8d2d\u4e70\u80a1\u7968\uff0c\u4e4b\u540e\u518d\u5c06\u5b83\u4eec\u5356\u51fa\u3002 \u00a0 \n\u00a0    \u56e0\u4e3a\u8fd9\u6837\u5c5e\u4e8e\u540c\u65f6\u53c2\u4e0e\u4e86\u591a\u7b14\u4ea4\u6613\uff0c\u4f60\u5fc5\u987b\u5728\u518d\u6b21\u8d2d\u4e70\u524d\u51fa\u552e\u6389\u4e4b\u524d\u7684\u80a1\u7968\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aprices = [7,6,4,3,1] \n\u8f93\u51fa\uff1a0 \n\u89e3\u91ca\uff1a\u5728\u8fd9\u4e2a\u60c5\u51b5\u4e0b, \u6ca1\u6709\u4ea4\u6613\u5b8c\u6210, \u6240\u4ee5\u6700\u5927\u5229\u6da6\u4e3a 0\u3002
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1aprices = [1]\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <=\u00a0prices.length <= 105
    • \n\t
    • 0 <=\u00a0prices[i] <=\u00a0105
    • \n
    \n", "tags_en": ["Array", "Dynamic Programming"], "tags_cn": ["\u6570\u7ec4", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxProfit(vector& prices) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxProfit(int[] prices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxProfit(self, prices):\n \"\"\"\n :type prices: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxProfit(self, prices: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxProfit(int* prices, int pricesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxProfit(int[] prices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} prices\n * @return {number}\n */\nvar maxProfit = function(prices) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} prices\n# @return {Integer}\ndef max_profit(prices)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxProfit(_ prices: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxProfit(prices []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxProfit(prices: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxProfit(prices: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_profit(prices: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $prices\n * @return Integer\n */\n function maxProfit($prices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxProfit(prices: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-profit prices)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0123](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-iii)", "[\u4e70\u5356\u80a1\u7968\u7684\u6700\u4f73\u65f6\u673a III](/solution/0100-0199/0123.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20III/README.md)", "`\u6570\u7ec4`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0123](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iii)", "[Best Time to Buy and Sell Stock III](/solution/0100-0199/0123.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20III/README_EN.md)", "`Array`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0122", "frontend_question_id": "0122", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-ii", "url_en": "https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii", "relative_path_cn": "/solution/0100-0199/0122.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20II/README.md", "relative_path_en": "/solution/0100-0199/0122.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20II/README_EN.md", "title_cn": "\u4e70\u5356\u80a1\u7968\u7684\u6700\u4f73\u65f6\u673a II", "title_en": "Best Time to Buy and Sell Stock II", "question_title_slug": "best-time-to-buy-and-sell-stock-ii", "content_en": "

    You are given an array prices where prices[i] is the price of a given stock on the ith day.

    \n\n

    Find the maximum profit you can achieve. You may complete as many transactions as you like (i.e., buy one and sell one share of the stock multiple times).

    \n\n

    Note: You may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again).

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: prices = [7,1,5,3,6,4]\nOutput: 7\nExplanation: Buy on day 2 (price = 1) and sell on day 3 (price = 5), profit = 5-1 = 4.\nThen buy on day 4 (price = 3) and sell on day 5 (price = 6), profit = 6-3 = 3.\n
    \n\n

    Example 2:

    \n\n
    \nInput: prices = [1,2,3,4,5]\nOutput: 4\nExplanation: Buy on day 1 (price = 1) and sell on day 5 (price = 5), profit = 5-1 = 4.\nNote that you cannot buy on day 1, buy on day 2 and sell them later, as you are engaging multiple transactions at the same time. You must sell before buying again.\n
    \n\n

    Example 3:

    \n\n
    \nInput: prices = [7,6,4,3,1]\nOutput: 0\nExplanation: In this case, no transaction is done, i.e., max profit = 0.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= prices.length <= 3 * 104
    • \n\t
    • 0 <= prices[i] <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6570\u7ec4 prices \uff0c\u5176\u4e2d\u00a0prices[i] \u662f\u4e00\u652f\u7ed9\u5b9a\u80a1\u7968\u7b2c i \u5929\u7684\u4ef7\u683c\u3002

    \n\n

    \u8bbe\u8ba1\u4e00\u4e2a\u7b97\u6cd5\u6765\u8ba1\u7b97\u4f60\u6240\u80fd\u83b7\u53d6\u7684\u6700\u5927\u5229\u6da6\u3002\u4f60\u53ef\u4ee5\u5c3d\u53ef\u80fd\u5730\u5b8c\u6210\u66f4\u591a\u7684\u4ea4\u6613\uff08\u591a\u6b21\u4e70\u5356\u4e00\u652f\u80a1\u7968\uff09\u3002

    \n\n

    \u6ce8\u610f\uff1a\u4f60\u4e0d\u80fd\u540c\u65f6\u53c2\u4e0e\u591a\u7b14\u4ea4\u6613\uff08\u4f60\u5fc5\u987b\u5728\u518d\u6b21\u8d2d\u4e70\u524d\u51fa\u552e\u6389\u4e4b\u524d\u7684\u80a1\u7968\uff09\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: prices = [7,1,5,3,6,4]\n\u8f93\u51fa: 7\n\u89e3\u91ca: \u5728\u7b2c 2 \u5929\uff08\u80a1\u7968\u4ef7\u683c = 1\uff09\u7684\u65f6\u5019\u4e70\u5165\uff0c\u5728\u7b2c 3 \u5929\uff08\u80a1\u7968\u4ef7\u683c = 5\uff09\u7684\u65f6\u5019\u5356\u51fa, \u8fd9\u7b14\u4ea4\u6613\u6240\u80fd\u83b7\u5f97\u5229\u6da6 = 5-1 = 4 \u3002\n\u00a0    \u968f\u540e\uff0c\u5728\u7b2c 4 \u5929\uff08\u80a1\u7968\u4ef7\u683c = 3\uff09\u7684\u65f6\u5019\u4e70\u5165\uff0c\u5728\u7b2c 5 \u5929\uff08\u80a1\u7968\u4ef7\u683c = 6\uff09\u7684\u65f6\u5019\u5356\u51fa, \u8fd9\u7b14\u4ea4\u6613\u6240\u80fd\u83b7\u5f97\u5229\u6da6 = 6-3 = 3 \u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: prices = [1,2,3,4,5]\n\u8f93\u51fa: 4\n\u89e3\u91ca: \u5728\u7b2c 1 \u5929\uff08\u80a1\u7968\u4ef7\u683c = 1\uff09\u7684\u65f6\u5019\u4e70\u5165\uff0c\u5728\u7b2c 5 \u5929 \uff08\u80a1\u7968\u4ef7\u683c = 5\uff09\u7684\u65f6\u5019\u5356\u51fa, \u8fd9\u7b14\u4ea4\u6613\u6240\u80fd\u83b7\u5f97\u5229\u6da6 = 5-1 = 4 \u3002\n\u00a0    \u6ce8\u610f\u4f60\u4e0d\u80fd\u5728\u7b2c 1 \u5929\u548c\u7b2c 2 \u5929\u63a5\u8fde\u8d2d\u4e70\u80a1\u7968\uff0c\u4e4b\u540e\u518d\u5c06\u5b83\u4eec\u5356\u51fa\u3002\u56e0\u4e3a\u8fd9\u6837\u5c5e\u4e8e\u540c\u65f6\u53c2\u4e0e\u4e86\u591a\u7b14\u4ea4\u6613\uff0c\u4f60\u5fc5\u987b\u5728\u518d\u6b21\u8d2d\u4e70\u524d\u51fa\u552e\u6389\u4e4b\u524d\u7684\u80a1\u7968\u3002\n
    \n\n

    \u793a\u4f8b\u00a03:

    \n\n
    \n\u8f93\u5165: prices = [7,6,4,3,1]\n\u8f93\u51fa: 0\n\u89e3\u91ca: \u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b, \u6ca1\u6709\u4ea4\u6613\u5b8c\u6210, \u6240\u4ee5\u6700\u5927\u5229\u6da6\u4e3a 0\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= prices.length <= 3 * 104
    • \n\t
    • 0 <= prices[i] <= 104
    • \n
    \n", "tags_en": ["Greedy", "Array"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxProfit(vector& prices) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxProfit(int[] prices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxProfit(self, prices):\n \"\"\"\n :type prices: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxProfit(self, prices: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxProfit(int* prices, int pricesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxProfit(int[] prices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} prices\n * @return {number}\n */\nvar maxProfit = function(prices) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} prices\n# @return {Integer}\ndef max_profit(prices)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxProfit(_ prices: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxProfit(prices []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxProfit(prices: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxProfit(prices: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_profit(prices: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $prices\n * @return Integer\n */\n function maxProfit($prices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxProfit(prices: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-profit prices)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0122](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-ii)", "[\u4e70\u5356\u80a1\u7968\u7684\u6700\u4f73\u65f6\u673a II](/solution/0100-0199/0122.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20II/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0122](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii)", "[Best Time to Buy and Sell Stock II](/solution/0100-0199/0122.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20II/README_EN.md)", "`Greedy`,`Array`", "Easy", ""]}, {"question_id": "0121", "frontend_question_id": "0121", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock", "url_en": "https://leetcode.com/problems/best-time-to-buy-and-sell-stock", "relative_path_cn": "/solution/0100-0199/0121.Best%20Time%20to%20Buy%20and%20Sell%20Stock/README.md", "relative_path_en": "/solution/0100-0199/0121.Best%20Time%20to%20Buy%20and%20Sell%20Stock/README_EN.md", "title_cn": "\u4e70\u5356\u80a1\u7968\u7684\u6700\u4f73\u65f6\u673a", "title_en": "Best Time to Buy and Sell Stock", "question_title_slug": "best-time-to-buy-and-sell-stock", "content_en": "

    You are given an array prices where prices[i] is the price of a given stock on the ith day.

    \n\n

    You want to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to sell that stock.

    \n\n

    Return the maximum profit you can achieve from this transaction. If you cannot achieve any profit, return 0.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: prices = [7,1,5,3,6,4]\nOutput: 5\nExplanation: Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6-1 = 5.\nNote that buying on day 2 and selling on day 1 is not allowed because you must buy before you sell.\n
    \n\n

    Example 2:

    \n\n
    \nInput: prices = [7,6,4,3,1]\nOutput: 0\nExplanation: In this case, no transactions are done and the max profit = 0.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= prices.length <= 105
    • \n\t
    • 0 <= prices[i] <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6570\u7ec4 prices \uff0c\u5b83\u7684\u7b2c\u00a0i \u4e2a\u5143\u7d20\u00a0prices[i] \u8868\u793a\u4e00\u652f\u7ed9\u5b9a\u80a1\u7968\u7b2c i \u5929\u7684\u4ef7\u683c\u3002

    \n\n

    \u4f60\u53ea\u80fd\u9009\u62e9 \u67d0\u4e00\u5929 \u4e70\u5165\u8fd9\u53ea\u80a1\u7968\uff0c\u5e76\u9009\u62e9\u5728 \u672a\u6765\u7684\u67d0\u4e00\u4e2a\u4e0d\u540c\u7684\u65e5\u5b50 \u5356\u51fa\u8be5\u80a1\u7968\u3002\u8bbe\u8ba1\u4e00\u4e2a\u7b97\u6cd5\u6765\u8ba1\u7b97\u4f60\u6240\u80fd\u83b7\u53d6\u7684\u6700\u5927\u5229\u6da6\u3002

    \n\n

    \u8fd4\u56de\u4f60\u53ef\u4ee5\u4ece\u8fd9\u7b14\u4ea4\u6613\u4e2d\u83b7\u53d6\u7684\u6700\u5927\u5229\u6da6\u3002\u5982\u679c\u4f60\u4e0d\u80fd\u83b7\u53d6\u4efb\u4f55\u5229\u6da6\uff0c\u8fd4\u56de 0 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[7,1,5,3,6,4]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u5728\u7b2c 2 \u5929\uff08\u80a1\u7968\u4ef7\u683c = 1\uff09\u7684\u65f6\u5019\u4e70\u5165\uff0c\u5728\u7b2c 5 \u5929\uff08\u80a1\u7968\u4ef7\u683c = 6\uff09\u7684\u65f6\u5019\u5356\u51fa\uff0c\u6700\u5927\u5229\u6da6 = 6-1 = 5 \u3002\n     \u6ce8\u610f\u5229\u6da6\u4e0d\u80fd\u662f 7-1 = 6, \u56e0\u4e3a\u5356\u51fa\u4ef7\u683c\u9700\u8981\u5927\u4e8e\u4e70\u5165\u4ef7\u683c\uff1b\u540c\u65f6\uff0c\u4f60\u4e0d\u80fd\u5728\u4e70\u5165\u524d\u5356\u51fa\u80a1\u7968\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aprices = [7,6,4,3,1]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b, \u6ca1\u6709\u4ea4\u6613\u5b8c\u6210, \u6240\u4ee5\u6700\u5927\u5229\u6da6\u4e3a 0\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= prices.length <= 105
    • \n\t
    • 0 <= prices[i] <= 104
    • \n
    \n", "tags_en": ["Array", "Dynamic Programming"], "tags_cn": ["\u6570\u7ec4", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxProfit(vector& prices) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxProfit(int[] prices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxProfit(self, prices):\n \"\"\"\n :type prices: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxProfit(self, prices: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxProfit(int* prices, int pricesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxProfit(int[] prices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} prices\n * @return {number}\n */\nvar maxProfit = function(prices) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} prices\n# @return {Integer}\ndef max_profit(prices)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxProfit(_ prices: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxProfit(prices []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxProfit(prices: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxProfit(prices: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_profit(prices: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $prices\n * @return Integer\n */\n function maxProfit($prices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxProfit(prices: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-profit prices)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0121](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock)", "[\u4e70\u5356\u80a1\u7968\u7684\u6700\u4f73\u65f6\u673a](/solution/0100-0199/0121.Best%20Time%20to%20Buy%20and%20Sell%20Stock/README.md)", "`\u6570\u7ec4`,`\u52a8\u6001\u89c4\u5212`", "\u7b80\u5355", ""], "md_table_row_en": ["[0121](https://leetcode.com/problems/best-time-to-buy-and-sell-stock)", "[Best Time to Buy and Sell Stock](/solution/0100-0199/0121.Best%20Time%20to%20Buy%20and%20Sell%20Stock/README_EN.md)", "`Array`,`Dynamic Programming`", "Easy", ""]}, {"question_id": "0120", "frontend_question_id": "0120", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/triangle", "url_en": "https://leetcode.com/problems/triangle", "relative_path_cn": "/solution/0100-0199/0120.Triangle/README.md", "relative_path_en": "/solution/0100-0199/0120.Triangle/README_EN.md", "title_cn": "\u4e09\u89d2\u5f62\u6700\u5c0f\u8def\u5f84\u548c", "title_en": "Triangle", "question_title_slug": "triangle", "content_en": "

    Given a triangle array, return the minimum path sum from top to bottom.

    \n\n

    For each step, you may move to an adjacent number of the row below. More formally, if you are on index i on the current row, you may move to either index i or index i + 1 on the next row.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: triangle = [[2],[3,4],[6,5,7],[4,1,8,3]]\nOutput: 11\nExplanation: The triangle looks like:\n   2\n  3 4\n 6 5 7\n4 1 8 3\nThe minimum path sum from top to bottom is 2 + 3 + 5 + 1 = 11 (underlined above).\n
    \n\n

    Example 2:

    \n\n
    \nInput: triangle = [[-10]]\nOutput: -10\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= triangle.length <= 200
    • \n\t
    • triangle[0].length == 1
    • \n\t
    • triangle[i].length == triangle[i - 1].length + 1
    • \n\t
    • -104 <= triangle[i][j] <= 104
    • \n
    \n\n

     

    \nFollow up: Could you do this using only O(n) extra space, where n is the total number of rows in the triangle?", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e09\u89d2\u5f62 triangle \uff0c\u627e\u51fa\u81ea\u9876\u5411\u4e0b\u7684\u6700\u5c0f\u8def\u5f84\u548c\u3002

    \n\n

    \u6bcf\u4e00\u6b65\u53ea\u80fd\u79fb\u52a8\u5230\u4e0b\u4e00\u884c\u4e2d\u76f8\u90bb\u7684\u7ed3\u70b9\u4e0a\u3002\u76f8\u90bb\u7684\u7ed3\u70b9 \u5728\u8fd9\u91cc\u6307\u7684\u662f \u4e0b\u6807 \u4e0e \u4e0a\u4e00\u5c42\u7ed3\u70b9\u4e0b\u6807 \u76f8\u540c\u6216\u8005\u7b49\u4e8e \u4e0a\u4e00\u5c42\u7ed3\u70b9\u4e0b\u6807 + 1 \u7684\u4e24\u4e2a\u7ed3\u70b9\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u5982\u679c\u6b63\u4f4d\u4e8e\u5f53\u524d\u884c\u7684\u4e0b\u6807 i \uff0c\u90a3\u4e48\u4e0b\u4e00\u6b65\u53ef\u4ee5\u79fb\u52a8\u5230\u4e0b\u4e00\u884c\u7684\u4e0b\u6807 i \u6216 i + 1 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1atriangle = [[2],[3,4],[6,5,7],[4,1,8,3]]\n\u8f93\u51fa\uff1a11\n\u89e3\u91ca\uff1a\u5982\u4e0b\u9762\u7b80\u56fe\u6240\u793a\uff1a\n   2\n  3 4\n 6 5 7\n4 1 8 3\n\u81ea\u9876\u5411\u4e0b\u7684\u6700\u5c0f\u8def\u5f84\u548c\u4e3a\u00a011\uff08\u5373\uff0c2\u00a0+\u00a03\u00a0+\u00a05\u00a0+\u00a01\u00a0= 11\uff09\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1atriangle = [[-10]]\n\u8f93\u51fa\uff1a-10\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= triangle.length <= 200
    • \n\t
    • triangle[0].length == 1
    • \n\t
    • triangle[i].length == triangle[i - 1].length + 1
    • \n\t
    • -104 <= triangle[i][j] <= 104
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u4f60\u53ef\u4ee5\u53ea\u4f7f\u7528 O(n)\u00a0\u7684\u989d\u5916\u7a7a\u95f4\uff08n \u4e3a\u4e09\u89d2\u5f62\u7684\u603b\u884c\u6570\uff09\u6765\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u5417\uff1f
    • \n
    \n", "tags_en": ["Array", "Dynamic Programming"], "tags_cn": ["\u6570\u7ec4", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minimumTotal(vector>& triangle) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minimumTotal(List> triangle) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimumTotal(self, triangle):\n \"\"\"\n :type triangle: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimumTotal(self, triangle: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minimumTotal(int** triangle, int triangleSize, int* triangleColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinimumTotal(IList> triangle) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} triangle\n * @return {number}\n */\nvar minimumTotal = function(triangle) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} triangle\n# @return {Integer}\ndef minimum_total(triangle)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimumTotal(_ triangle: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimumTotal(triangle [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimumTotal(triangle: List[List[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimumTotal(triangle: List>): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimum_total(triangle: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $triangle\n * @return Integer\n */\n function minimumTotal($triangle) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimumTotal(triangle: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimum-total triangle)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0120](https://leetcode-cn.com/problems/triangle)", "[\u4e09\u89d2\u5f62\u6700\u5c0f\u8def\u5f84\u548c](/solution/0100-0199/0120.Triangle/README.md)", "`\u6570\u7ec4`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0120](https://leetcode.com/problems/triangle)", "[Triangle](/solution/0100-0199/0120.Triangle/README_EN.md)", "`Array`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0119", "frontend_question_id": "0119", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/pascals-triangle-ii", "url_en": "https://leetcode.com/problems/pascals-triangle-ii", "relative_path_cn": "/solution/0100-0199/0119.Pascal%27s%20Triangle%20II/README.md", "relative_path_en": "/solution/0100-0199/0119.Pascal%27s%20Triangle%20II/README_EN.md", "title_cn": "\u6768\u8f89\u4e09\u89d2 II", "title_en": "Pascal's Triangle II", "question_title_slug": "pascals-triangle-ii", "content_en": "

    Given an integer rowIndex, return the rowIndexth (0-indexed) row of the Pascal's triangle.

    \n\n

    In Pascal's triangle, each number is the sum of the two numbers directly above it as shown:

    \n\"\"\n

     

    \n

    Example 1:

    \n
    Input: rowIndex = 3\nOutput: [1,3,3,1]\n

    Example 2:

    \n
    Input: rowIndex = 0\nOutput: [1]\n

    Example 3:

    \n
    Input: rowIndex = 1\nOutput: [1,1]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= rowIndex <= 33
    • \n
    \n\n

     

    \n

    Follow up: Could you optimize your algorithm to use only O(rowIndex) extra space?

    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u8d1f\u7d22\u5f15 k\uff0c\u5176\u4e2d k ≤ 33\uff0c\u8fd4\u56de\u6768\u8f89\u4e09\u89d2\u7684\u7b2c k \u884c\u3002

    \n\n

    \"\"

    \n\n

    \u5728\u6768\u8f89\u4e09\u89d2\u4e2d\uff0c\u6bcf\u4e2a\u6570\u662f\u5b83\u5de6\u4e0a\u65b9\u548c\u53f3\u4e0a\u65b9\u7684\u6570\u7684\u548c\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: 3\n\u8f93\u51fa: [1,3,3,1]\n
    \n\n

    \u8fdb\u9636\uff1a

    \n\n

    \u4f60\u53ef\u4ee5\u4f18\u5316\u4f60\u7684\u7b97\u6cd5\u5230 O(k) \u7a7a\u95f4\u590d\u6742\u5ea6\u5417\uff1f

    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector getRow(int rowIndex) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List getRow(int rowIndex) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getRow(self, rowIndex):\n \"\"\"\n :type rowIndex: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getRow(self, rowIndex: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* getRow(int rowIndex, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList GetRow(int rowIndex) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} rowIndex\n * @return {number[]}\n */\nvar getRow = function(rowIndex) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} row_index\n# @return {Integer[]}\ndef get_row(row_index)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getRow(_ rowIndex: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getRow(rowIndex int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getRow(rowIndex: Int): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getRow(rowIndex: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_row(row_index: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $rowIndex\n * @return Integer[]\n */\n function getRow($rowIndex) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getRow(rowIndex: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-row rowIndex)\n (-> exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0119](https://leetcode-cn.com/problems/pascals-triangle-ii)", "[\u6768\u8f89\u4e09\u89d2 II](/solution/0100-0199/0119.Pascal%27s%20Triangle%20II/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0119](https://leetcode.com/problems/pascals-triangle-ii)", "[Pascal's Triangle II](/solution/0100-0199/0119.Pascal%27s%20Triangle%20II/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0118", "frontend_question_id": "0118", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/pascals-triangle", "url_en": "https://leetcode.com/problems/pascals-triangle", "relative_path_cn": "/solution/0100-0199/0118.Pascal%27s%20Triangle/README.md", "relative_path_en": "/solution/0100-0199/0118.Pascal%27s%20Triangle/README_EN.md", "title_cn": "\u6768\u8f89\u4e09\u89d2", "title_en": "Pascal's Triangle", "question_title_slug": "pascals-triangle", "content_en": "

    Given an integer numRows, return the first numRows of Pascal's triangle.

    \n\n

    In Pascal's triangle, each number is the sum of the two numbers directly above it as shown:

    \n\"\"\n

     

    \n

    Example 1:

    \n
    Input: numRows = 5\nOutput: [[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1]]\n

    Example 2:

    \n
    Input: numRows = 1\nOutput: [[1]]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= numRows <= 30
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u8d1f\u6574\u6570 numRows\uff0c\u751f\u6210\u6768\u8f89\u4e09\u89d2\u7684\u524d numRows \u884c\u3002

    \n\n

    \"\"

    \n\n

    \u5728\u6768\u8f89\u4e09\u89d2\u4e2d\uff0c\u6bcf\u4e2a\u6570\u662f\u5b83\u5de6\u4e0a\u65b9\u548c\u53f3\u4e0a\u65b9\u7684\u6570\u7684\u548c\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: 5\n\u8f93\u51fa:\n[\n     [1],\n    [1,1],\n   [1,2,1],\n  [1,3,3,1],\n [1,4,6,4,1]\n]
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> generate(int numRows) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> generate(int numRows) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def generate(self, numRows):\n \"\"\"\n :type numRows: int\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def generate(self, numRows: int) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** generate(int numRows, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> Generate(int numRows) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} numRows\n * @return {number[][]}\n */\nvar generate = function(numRows) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} num_rows\n# @return {Integer[][]}\ndef generate(num_rows)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func generate(_ numRows: Int) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func generate(numRows int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def generate(numRows: Int): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun generate(numRows: Int): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn generate(num_rows: i32) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $numRows\n * @return Integer[][]\n */\n function generate($numRows) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function generate(numRows: number): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (generate numRows)\n (-> exact-integer? (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0118](https://leetcode-cn.com/problems/pascals-triangle)", "[\u6768\u8f89\u4e09\u89d2](/solution/0100-0199/0118.Pascal%27s%20Triangle/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0118](https://leetcode.com/problems/pascals-triangle)", "[Pascal's Triangle](/solution/0100-0199/0118.Pascal%27s%20Triangle/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0117", "frontend_question_id": "0117", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/populating-next-right-pointers-in-each-node-ii", "url_en": "https://leetcode.com/problems/populating-next-right-pointers-in-each-node-ii", "relative_path_cn": "/solution/0100-0199/0117.Populating%20Next%20Right%20Pointers%20in%20Each%20Node%20II/README.md", "relative_path_en": "/solution/0100-0199/0117.Populating%20Next%20Right%20Pointers%20in%20Each%20Node%20II/README_EN.md", "title_cn": "\u586b\u5145\u6bcf\u4e2a\u8282\u70b9\u7684\u4e0b\u4e00\u4e2a\u53f3\u4fa7\u8282\u70b9\u6307\u9488 II", "title_en": "Populating Next Right Pointers in Each Node II", "question_title_slug": "populating-next-right-pointers-in-each-node-ii", "content_en": "

    Given a binary tree

    \r\n\r\n
    \r\nstruct Node {\r\n  int val;\r\n  Node *left;\r\n  Node *right;\r\n  Node *next;\r\n}\r\n
    \r\n\r\n

    Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL.

    \r\n\r\n

    Initially, all next pointers are set to NULL.

    \r\n\r\n

     

    \r\n\r\n

    Follow up:

    \r\n\r\n
      \r\n\t
    • You may only use constant extra space.
    • \r\n\t
    • Recursive approach is fine, you may assume implicit stack space does not count as extra space for this problem.
    • \r\n
    \r\n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: root = [1,2,3,4,5,null,7]\nOutput: [1,#,2,3,#,4,5,7,#]\nExplanation: Given the above binary tree (Figure A), your function should populate each next pointer to point to its next right node, just like in Figure B. The serialized output is in level order as connected by the next pointers, with '#' signifying the end of each level.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the given tree is less than 6000.
    • \n\t
    • -100 <= node.val <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811

    \n\n
    \nstruct Node {\n  int val;\n  Node *left;\n  Node *right;\n  Node *next;\n}
    \n\n

    \u586b\u5145\u5b83\u7684\u6bcf\u4e2a next \u6307\u9488\uff0c\u8ba9\u8fd9\u4e2a\u6307\u9488\u6307\u5411\u5176\u4e0b\u4e00\u4e2a\u53f3\u4fa7\u8282\u70b9\u3002\u5982\u679c\u627e\u4e0d\u5230\u4e0b\u4e00\u4e2a\u53f3\u4fa7\u8282\u70b9\uff0c\u5219\u5c06 next \u6307\u9488\u8bbe\u7f6e\u4e3a NULL\u3002

    \n\n

    \u521d\u59cb\u72b6\u6001\u4e0b\uff0c\u6240\u6709\u00a0next \u6307\u9488\u90fd\u88ab\u8bbe\u7f6e\u4e3a NULL\u3002

    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u4f60\u53ea\u80fd\u4f7f\u7528\u5e38\u91cf\u7ea7\u989d\u5916\u7a7a\u95f4\u3002
    • \n\t
    • \u4f7f\u7528\u9012\u5f52\u89e3\u9898\u4e5f\u7b26\u5408\u8981\u6c42\uff0c\u672c\u9898\u4e2d\u9012\u5f52\u7a0b\u5e8f\u5360\u7528\u7684\u6808\u7a7a\u95f4\u4e0d\u7b97\u505a\u989d\u5916\u7684\u7a7a\u95f4\u590d\u6742\u5ea6\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aroot = [1,2,3,4,5,null,7]\n\u8f93\u51fa\uff1a[1,#,2,3,#,4,5,7,#]\n\u89e3\u91ca\uff1a\u7ed9\u5b9a\u4e8c\u53c9\u6811\u5982\u56fe A \u6240\u793a\uff0c\u4f60\u7684\u51fd\u6570\u5e94\u8be5\u586b\u5145\u5b83\u7684\u6bcf\u4e2a next \u6307\u9488\uff0c\u4ee5\u6307\u5411\u5176\u4e0b\u4e00\u4e2a\u53f3\u4fa7\u8282\u70b9\uff0c\u5982\u56fe B \u6240\u793a\u3002\u5e8f\u5217\u5316\u8f93\u51fa\u6309\u5c42\u5e8f\u904d\u5386\u987a\u5e8f\uff08\u7531 next \u6307\u9488\u8fde\u63a5\uff09\uff0c'#' \u8868\u793a\u6bcf\u5c42\u7684\u672b\u5c3e\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u7684\u8282\u70b9\u6570\u5c0f\u4e8e 6000
    • \n\t
    • -100\u00a0<= node.val <= 100
    • \n
    \n\n

    \u00a0

    \n\n
      \n
    \n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* next;\n\n Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val, Node* _left, Node* _right, Node* _next)\n : val(_val), left(_left), right(_right), next(_next) {}\n};\n*/\n\nclass Solution {\npublic:\n Node* connect(Node* root) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/*\n// Definition for a Node.\nclass Node {\n public int val;\n public Node left;\n public Node right;\n public Node next;\n\n public Node() {}\n \n public Node(int _val) {\n val = _val;\n }\n\n public Node(int _val, Node _left, Node _right, Node _next) {\n val = _val;\n left = _left;\n right = _right;\n next = _next;\n }\n};\n*/\n\nclass Solution {\n public Node connect(Node root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "\"\"\"\n# Definition for a Node.\nclass Node(object):\n def __init__(self, val=0, left=None, right=None, next=None):\n self.val = val\n self.left = left\n self.right = right\n self.next = next\n\"\"\"\n\nclass Solution(object):\n def connect(self, root):\n \"\"\"\n :type root: Node\n :rtype: Node\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "\"\"\"\n# Definition for a Node.\nclass Node:\n def __init__(self, val: int = 0, left: 'Node' = None, right: 'Node' = None, next: 'Node' = None):\n self.val = val\n self.left = left\n self.right = right\n self.next = next\n\"\"\"\n\nclass Solution:\n def connect(self, root: 'Node') -> 'Node':\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a Node.\n * struct Node {\n * int val;\n * struct Node *left;\n * struct Node *right;\n * struct Node *next;\n * };\n */\n\nstruct Node* connect(struct Node* root) {\n\t\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/*\n// Definition for a Node.\npublic class Node {\n public int val;\n public Node left;\n public Node right;\n public Node next;\n\n public Node() {}\n\n public Node(int _val) {\n val = _val;\n }\n\n public Node(int _val, Node _left, Node _right, Node _next) {\n val = _val;\n left = _left;\n right = _right;\n next = _next;\n }\n}\n*/\n\npublic class Solution {\n public Node Connect(Node root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // Definition for a Node.\n * function Node(val, left, right, next) {\n * this.val = val === undefined ? null : val;\n * this.left = left === undefined ? null : left;\n * this.right = right === undefined ? null : right;\n * this.next = next === undefined ? null : next;\n * };\n */\n\n/**\n * @param {Node} root\n * @return {Node}\n */\nvar connect = function(root) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a Node.\n# class Node\n# attr_accessor :val, :left, :right, :next\n# def initialize(val)\n# @val = val\n# @left, @right, @next = nil, nil, nil\n# end\n# end\n\n# @param {Node} root\n# @return {Node}\ndef connect(root)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a Node.\n * public class Node {\n * public var val: Int\n * public var left: Node?\n * public var right: Node?\n *\t public var next: Node?\n * public init(_ val: Int) {\n * self.val = val\n * self.left = nil\n * self.right = nil\n * self.next = nil\n * }\n * }\n */\n\nclass Solution {\n func connect(_ root: Node?) -> Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a Node.\n * type Node struct {\n * Val int\n * Left *Node\n * Right *Node\n * Next *Node\n * }\n */\n\nfunc connect(root *Node) *Node {\n\t\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a Node.\n * class Node(var _value: Int) {\n * var value: Int = _value\n * var left: Node = null\n * var right: Node = null\n * var next: Node = null\n * }\n */\n\nobject Solution {\n def connect(root: Node): Node = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a Node.\n * class Node(var `val`: Int) {\n * var left: Node? = null\n * var right: Node? = null\n * var next: Node? = null\n * }\n */\n\nclass Solution {\n fun connect(root: Node?): Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a Node.\n * class Node {\n * function __construct($val = 0) {\n * $this->val = $val;\n * $this->left = null;\n * $this->right = null;\n * $this->next = null;\n * }\n * }\n */\n\nclass Solution {\n /**\n * @param Node $root\n * @return Node\n */\n public function connect($root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for Node.\n * class Node {\n * val: number\n * left: Node | null\n * right: Node | null\n * next: Node | null\n * constructor(val?: number, left?: Node, right?: Node, next?: Node) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction connect(root: Node | null): Node | null {\n \n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0117](https://leetcode-cn.com/problems/populating-next-right-pointers-in-each-node-ii)", "[\u586b\u5145\u6bcf\u4e2a\u8282\u70b9\u7684\u4e0b\u4e00\u4e2a\u53f3\u4fa7\u8282\u70b9\u6307\u9488 II](/solution/0100-0199/0117.Populating%20Next%20Right%20Pointers%20in%20Each%20Node%20II/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0117](https://leetcode.com/problems/populating-next-right-pointers-in-each-node-ii)", "[Populating Next Right Pointers in Each Node II](/solution/0100-0199/0117.Populating%20Next%20Right%20Pointers%20in%20Each%20Node%20II/README_EN.md)", "`Tree`,`Depth-first Search`", "Medium", ""]}, {"question_id": "0116", "frontend_question_id": "0116", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/populating-next-right-pointers-in-each-node", "url_en": "https://leetcode.com/problems/populating-next-right-pointers-in-each-node", "relative_path_cn": "/solution/0100-0199/0116.Populating%20Next%20Right%20Pointers%20in%20Each%20Node/README.md", "relative_path_en": "/solution/0100-0199/0116.Populating%20Next%20Right%20Pointers%20in%20Each%20Node/README_EN.md", "title_cn": "\u586b\u5145\u6bcf\u4e2a\u8282\u70b9\u7684\u4e0b\u4e00\u4e2a\u53f3\u4fa7\u8282\u70b9\u6307\u9488", "title_en": "Populating Next Right Pointers in Each Node", "question_title_slug": "populating-next-right-pointers-in-each-node", "content_en": "

    You are given a perfect binary tree where all leaves are on the same level, and every parent has two children. The binary tree has the following definition:

    \r\n\r\n
    \r\nstruct Node {\r\n  int val;\r\n  Node *left;\r\n  Node *right;\r\n  Node *next;\r\n}\r\n
    \r\n\r\n

    Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL.

    \r\n\r\n

    Initially, all next pointers are set to NULL.

    \r\n\r\n

     

    \r\n\r\n

    Follow up:

    \r\n\r\n
      \r\n\t
    • You may only use constant extra space.
    • \r\n\t
    • Recursive approach is fine, you may assume implicit stack space does not count as extra space for this problem.
    • \r\n
    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n

    \"\"

    \r\n\r\n
    \r\nInput: root = [1,2,3,4,5,6,7]\r\nOutput: [1,#,2,3,#,4,5,6,7,#]\r\nExplanation: Given the above perfect binary tree (Figure A), your function should populate each next pointer to point to its next right node, just like in Figure B. The serialized output is in level order as connected by the next pointers, with '#' signifying the end of each level.\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • The number of nodes in the given tree is less than 4096.
    • \r\n\t
    • -1000 <= node.val <= 1000
    • \r\n
    ", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u00a0\u5b8c\u7f8e\u4e8c\u53c9\u6811\u00a0\uff0c\u5176\u6240\u6709\u53f6\u5b50\u8282\u70b9\u90fd\u5728\u540c\u4e00\u5c42\uff0c\u6bcf\u4e2a\u7236\u8282\u70b9\u90fd\u6709\u4e24\u4e2a\u5b50\u8282\u70b9\u3002\u4e8c\u53c9\u6811\u5b9a\u4e49\u5982\u4e0b\uff1a

    \n\n
    \nstruct Node {\n  int val;\n  Node *left;\n  Node *right;\n  Node *next;\n}
    \n\n

    \u586b\u5145\u5b83\u7684\u6bcf\u4e2a next \u6307\u9488\uff0c\u8ba9\u8fd9\u4e2a\u6307\u9488\u6307\u5411\u5176\u4e0b\u4e00\u4e2a\u53f3\u4fa7\u8282\u70b9\u3002\u5982\u679c\u627e\u4e0d\u5230\u4e0b\u4e00\u4e2a\u53f3\u4fa7\u8282\u70b9\uff0c\u5219\u5c06 next \u6307\u9488\u8bbe\u7f6e\u4e3a NULL\u3002

    \n\n

    \u521d\u59cb\u72b6\u6001\u4e0b\uff0c\u6240\u6709\u00a0next \u6307\u9488\u90fd\u88ab\u8bbe\u7f6e\u4e3a NULL\u3002

    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u4f60\u53ea\u80fd\u4f7f\u7528\u5e38\u91cf\u7ea7\u989d\u5916\u7a7a\u95f4\u3002
    • \n\t
    • \u4f7f\u7528\u9012\u5f52\u89e3\u9898\u4e5f\u7b26\u5408\u8981\u6c42\uff0c\u672c\u9898\u4e2d\u9012\u5f52\u7a0b\u5e8f\u5360\u7528\u7684\u6808\u7a7a\u95f4\u4e0d\u7b97\u505a\u989d\u5916\u7684\u7a7a\u95f4\u590d\u6742\u5ea6\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aroot = [1,2,3,4,5,6,7]\n\u8f93\u51fa\uff1a[1,#,2,3,#,4,5,6,7,#]\n\u89e3\u91ca\uff1a\u7ed9\u5b9a\u4e8c\u53c9\u6811\u5982\u56fe A \u6240\u793a\uff0c\u4f60\u7684\u51fd\u6570\u5e94\u8be5\u586b\u5145\u5b83\u7684\u6bcf\u4e2a next \u6307\u9488\uff0c\u4ee5\u6307\u5411\u5176\u4e0b\u4e00\u4e2a\u53f3\u4fa7\u8282\u70b9\uff0c\u5982\u56fe B \u6240\u793a\u3002\u5e8f\u5217\u5316\u7684\u8f93\u51fa\u6309\u5c42\u5e8f\u904d\u5386\u6392\u5217\uff0c\u540c\u4e00\u5c42\u8282\u70b9\u7531 next \u6307\u9488\u8fde\u63a5\uff0c'#' \u6807\u5fd7\u7740\u6bcf\u4e00\u5c42\u7684\u7ed3\u675f\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u7684\u6570\u91cf\u5c11\u4e8e\u00a04096
    • \n\t
    • -1000 <= node.val <= 1000
    • \n
    \n", "tags_en": ["Tree", "Depth-first Search", "Breadth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* next;\n\n Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val, Node* _left, Node* _right, Node* _next)\n : val(_val), left(_left), right(_right), next(_next) {}\n};\n*/\n\nclass Solution {\npublic:\n Node* connect(Node* root) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/*\n// Definition for a Node.\nclass Node {\n public int val;\n public Node left;\n public Node right;\n public Node next;\n\n public Node() {}\n \n public Node(int _val) {\n val = _val;\n }\n\n public Node(int _val, Node _left, Node _right, Node _next) {\n val = _val;\n left = _left;\n right = _right;\n next = _next;\n }\n};\n*/\n\nclass Solution {\n public Node connect(Node root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "\"\"\"\n# Definition for a Node.\nclass Node(object):\n def __init__(self, val=0, left=None, right=None, next=None):\n self.val = val\n self.left = left\n self.right = right\n self.next = next\n\"\"\"\n\nclass Solution(object):\n def connect(self, root):\n \"\"\"\n :type root: Node\n :rtype: Node\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "\"\"\"\n# Definition for a Node.\nclass Node:\n def __init__(self, val: int = 0, left: 'Node' = None, right: 'Node' = None, next: 'Node' = None):\n self.val = val\n self.left = left\n self.right = right\n self.next = next\n\"\"\"\n\nclass Solution:\n def connect(self, root: 'Node') -> 'Node':\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a Node.\n * struct Node {\n * int val;\n * struct Node *left;\n * struct Node *right;\n * struct Node *next;\n * };\n */\n\nstruct Node* connect(struct Node* root) {\n\t\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/*\n// Definition for a Node.\npublic class Node {\n public int val;\n public Node left;\n public Node right;\n public Node next;\n\n public Node() {}\n\n public Node(int _val) {\n val = _val;\n }\n\n public Node(int _val, Node _left, Node _right, Node _next) {\n val = _val;\n left = _left;\n right = _right;\n next = _next;\n }\n}\n*/\n\npublic class Solution {\n public Node Connect(Node root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // Definition for a Node.\n * function Node(val, left, right, next) {\n * this.val = val === undefined ? null : val;\n * this.left = left === undefined ? null : left;\n * this.right = right === undefined ? null : right;\n * this.next = next === undefined ? null : next;\n * };\n */\n\n/**\n * @param {Node} root\n * @return {Node}\n */\nvar connect = function(root) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for Node.\n# class Node\n# attr_accessor :val, :left, :right, :next\n# def initialize(val)\n# @val = val\n# @left, @right, @next = nil, nil, nil\n# end\n# end\n\n# @param {Node} root\n# @return {Node}\ndef connect(root)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a Node.\n * public class Node {\n * public var val: Int\n * public var left: Node?\n * public var right: Node?\n *\t public var next: Node?\n * public init(_ val: Int) {\n * self.val = val\n * self.left = nil\n * self.right = nil\n * self.next = nil\n * }\n * }\n */\n\nclass Solution {\n func connect(_ root: Node?) -> Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a Node.\n * type Node struct {\n * Val int\n * Left *Node\n * Right *Node\n * Next *Node\n * }\n */\n\nfunc connect(root *Node) *Node {\n\t\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a Node.\n * class Node(var _value: Int) {\n * var value: Int = _value\n * var left: Node = null\n * var right: Node = null\n * var next: Node = null\n * }\n */\n\nobject Solution {\n def connect(root: Node): Node = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a Node.\n * class Node(var `val`: Int) {\n * var left: Node? = null\n * var right: Node? = null\n * var next: Node? = null\n * }\n */\n\nclass Solution {\n fun connect(root: Node?): Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a Node.\n * class Node {\n * function __construct($val = 0) {\n * $this->val = $val;\n * $this->left = null;\n * $this->right = null;\n * $this->next = null;\n * }\n * }\n */\n\nclass Solution {\n /**\n * @param Node $root\n * @return Node\n */\n public function connect($root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for Node.\n * class Node {\n * val: number\n * left: Node | null\n * right: Node | null\n * next: Node | null\n * constructor(val?: number, left?: Node, right?: Node, next?: Node) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction connect(root: Node | null): Node | null {\n \n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0116](https://leetcode-cn.com/problems/populating-next-right-pointers-in-each-node)", "[\u586b\u5145\u6bcf\u4e2a\u8282\u70b9\u7684\u4e0b\u4e00\u4e2a\u53f3\u4fa7\u8282\u70b9\u6307\u9488](/solution/0100-0199/0116.Populating%20Next%20Right%20Pointers%20in%20Each%20Node/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0116](https://leetcode.com/problems/populating-next-right-pointers-in-each-node)", "[Populating Next Right Pointers in Each Node](/solution/0100-0199/0116.Populating%20Next%20Right%20Pointers%20in%20Each%20Node/README_EN.md)", "`Tree`,`Depth-first Search`,`Breadth-first Search`", "Medium", ""]}, {"question_id": "0115", "frontend_question_id": "0115", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/distinct-subsequences", "url_en": "https://leetcode.com/problems/distinct-subsequences", "relative_path_cn": "/solution/0100-0199/0115.Distinct%20Subsequences/README.md", "relative_path_en": "/solution/0100-0199/0115.Distinct%20Subsequences/README_EN.md", "title_cn": "\u4e0d\u540c\u7684\u5b50\u5e8f\u5217", "title_en": "Distinct Subsequences", "question_title_slug": "distinct-subsequences", "content_en": "

    Given two strings s and t, return the number of distinct subsequences of s which equals t.

    \n\n

    A string's subsequence is a new string formed from the original string by deleting some (can be none) of the characters without disturbing the remaining characters' relative positions. (i.e., "ACE" is a subsequence of "ABCDE" while "AEC" is not).

    \n\n

    It is guaranteed the answer fits on a 32-bit signed integer.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "rabbbit", t = "rabbit"\nOutput: 3\nExplanation:\nAs shown below, there are 3 ways you can generate "rabbit" from S.\nrabbbit\nrabbbit\nrabbbit\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "babgbag", t = "bag"\nOutput: 5\nExplanation:\nAs shown below, there are 5 ways you can generate "bag" from S.\nbabgbag\nbabgbag\nbabgbag\nbabgbag\nbabgbag
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length, t.length <= 1000
    • \n\t
    • s and t consist of English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32 s \u548c\u4e00\u4e2a\u5b57\u7b26\u4e32 t \uff0c\u8ba1\u7b97\u5728 s \u7684\u5b50\u5e8f\u5217\u4e2d t \u51fa\u73b0\u7684\u4e2a\u6570\u3002

    \n\n

    \u5b57\u7b26\u4e32\u7684\u4e00\u4e2a \u5b50\u5e8f\u5217 \u662f\u6307\uff0c\u901a\u8fc7\u5220\u9664\u4e00\u4e9b\uff08\u4e5f\u53ef\u4ee5\u4e0d\u5220\u9664\uff09\u5b57\u7b26\u4e14\u4e0d\u5e72\u6270\u5269\u4f59\u5b57\u7b26\u76f8\u5bf9\u4f4d\u7f6e\u6240\u7ec4\u6210\u7684\u65b0\u5b57\u7b26\u4e32\u3002\uff08\u4f8b\u5982\uff0c\"ACE\"\u00a0\u662f\u00a0\"ABCDE\"\u00a0\u7684\u4e00\u4e2a\u5b50\u5e8f\u5217\uff0c\u800c\u00a0\"AEC\"\u00a0\u4e0d\u662f\uff09

    \n\n

    \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u7b54\u6848\u7b26\u5408 32 \u4f4d\u5e26\u7b26\u53f7\u6574\u6570\u8303\u56f4\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\u00a01\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"rabbbit\", t = \"rabbit\"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\n\u5982\u4e0b\u56fe\u6240\u793a, \u6709 3 \u79cd\u53ef\u4ee5\u4ece s \u4e2d\u5f97\u5230 \"rabbit\" \u7684\u65b9\u6848\u3002\n(\u4e0a\u7bad\u5934\u7b26\u53f7 ^ \u8868\u793a\u9009\u53d6\u7684\u5b57\u6bcd)\nrabbbit\n^^^^ ^^\nrabbbit\n^^ ^^^^\nrabbbit\n^^^ ^^^\n
    \n\n

    \u793a\u4f8b\u00a02\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"babgbag\", t = \"bag\"\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\n\u5982\u4e0b\u56fe\u6240\u793a, \u6709 5 \u79cd\u53ef\u4ee5\u4ece s \u4e2d\u5f97\u5230 \"bag\" \u7684\u65b9\u6848\u3002 \n(\u4e0a\u7bad\u5934\u7b26\u53f7 ^ \u8868\u793a\u9009\u53d6\u7684\u5b57\u6bcd)\nbabgbag\n^^ ^\nbabgbag\n^^    ^\nbabgbag\n^    ^^\nbabgbag\n  ^  ^^\nbabgbag\n    ^^^
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= s.length, t.length <= 1000
    • \n\t
    • s \u548c t \u7531\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n", "tags_en": ["String", "Dynamic Programming"], "tags_cn": ["\u5b57\u7b26\u4e32", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numDistinct(string s, string t) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numDistinct(String s, String t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numDistinct(self, s, t):\n \"\"\"\n :type s: str\n :type t: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numDistinct(self, s: str, t: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numDistinct(char * s, char * t){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumDistinct(string s, string t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string} t\n * @return {number}\n */\nvar numDistinct = function(s, t) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String} t\n# @return {Integer}\ndef num_distinct(s, t)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numDistinct(_ s: String, _ t: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numDistinct(s string, t string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numDistinct(s: String, t: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numDistinct(s: String, t: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_distinct(s: String, t: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String $t\n * @return Integer\n */\n function numDistinct($s, $t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numDistinct(s: string, t: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-distinct s t)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0115](https://leetcode-cn.com/problems/distinct-subsequences)", "[\u4e0d\u540c\u7684\u5b50\u5e8f\u5217](/solution/0100-0199/0115.Distinct%20Subsequences/README.md)", "`\u5b57\u7b26\u4e32`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0115](https://leetcode.com/problems/distinct-subsequences)", "[Distinct Subsequences](/solution/0100-0199/0115.Distinct%20Subsequences/README_EN.md)", "`String`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0114", "frontend_question_id": "0114", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/flatten-binary-tree-to-linked-list", "url_en": "https://leetcode.com/problems/flatten-binary-tree-to-linked-list", "relative_path_cn": "/solution/0100-0199/0114.Flatten%20Binary%20Tree%20to%20Linked%20List/README.md", "relative_path_en": "/solution/0100-0199/0114.Flatten%20Binary%20Tree%20to%20Linked%20List/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u5c55\u5f00\u4e3a\u94fe\u8868", "title_en": "Flatten Binary Tree to Linked List", "question_title_slug": "flatten-binary-tree-to-linked-list", "content_en": "

    Given the root of a binary tree, flatten the tree into a "linked list":

    \n\n
      \n\t
    • The "linked list" should use the same TreeNode class where the right child pointer points to the next node in the list and the left child pointer is always null.
    • \n\t
    • The "linked list" should be in the same order as a pre-order traversal of the binary tree.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,2,5,3,4,null,6]\nOutput: [1,null,2,null,3,null,4,null,5,null,6]\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = []\nOutput: []\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = [0]\nOutput: [0]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [0, 2000].
    • \n\t
    • -100 <= Node.val <= 100
    • \n
    \n\n

     

    \nFollow up: Can you flatten the tree in-place (with O(1) extra space)?", "content_cn": "

    \u7ed9\u4f60\u4e8c\u53c9\u6811\u7684\u6839\u7ed3\u70b9 root \uff0c\u8bf7\u4f60\u5c06\u5b83\u5c55\u5f00\u4e3a\u4e00\u4e2a\u5355\u94fe\u8868\uff1a

    \n\n
      \n\t
    • \u5c55\u5f00\u540e\u7684\u5355\u94fe\u8868\u5e94\u8be5\u540c\u6837\u4f7f\u7528 TreeNode \uff0c\u5176\u4e2d right \u5b50\u6307\u9488\u6307\u5411\u94fe\u8868\u4e2d\u4e0b\u4e00\u4e2a\u7ed3\u70b9\uff0c\u800c\u5de6\u5b50\u6307\u9488\u59cb\u7ec8\u4e3a null \u3002
    • \n\t
    • \u5c55\u5f00\u540e\u7684\u5355\u94fe\u8868\u5e94\u8be5\u4e0e\u4e8c\u53c9\u6811 \u5148\u5e8f\u904d\u5386 \u987a\u5e8f\u76f8\u540c\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [1,2,5,3,4,null,6]\n\u8f93\u51fa\uff1a[1,null,2,null,3,null,4,null,5,null,6]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = []\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [0]\n\u8f93\u51fa\uff1a[0]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u7ed3\u70b9\u6570\u5728\u8303\u56f4 [0, 2000] \u5185
    • \n\t
    • -100 <= Node.val <= 100
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u53ef\u4ee5\u4f7f\u7528\u539f\u5730\u7b97\u6cd5\uff08O(1) \u989d\u5916\u7a7a\u95f4\uff09\u5c55\u5f00\u8fd9\u68f5\u6811\u5417\uff1f

    \n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n void flatten(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public void flatten(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def flatten(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: None Do not return anything, modify root in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def flatten(self, root: TreeNode) -> None:\n \"\"\"\n Do not return anything, modify root in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nvoid flatten(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public void Flatten(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {void} Do not return anything, modify root in-place instead.\n */\nvar flatten = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Void} Do not return anything, modify root in-place instead.\ndef flatten(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func flatten(_ root: TreeNode?) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc flatten(root *TreeNode) {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def flatten(root: TreeNode): Unit = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun flatten(root: TreeNode?): Unit {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn flatten(root: &mut Option>>) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return NULL\n */\n function flatten($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\n/**\n Do not return anything, modify root in-place instead.\n */\nfunction flatten(root: TreeNode | null): void {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (flatten root)\n (-> (or/c tree-node? #f) void?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0114](https://leetcode-cn.com/problems/flatten-binary-tree-to-linked-list)", "[\u4e8c\u53c9\u6811\u5c55\u5f00\u4e3a\u94fe\u8868](/solution/0100-0199/0114.Flatten%20Binary%20Tree%20to%20Linked%20List/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0114](https://leetcode.com/problems/flatten-binary-tree-to-linked-list)", "[Flatten Binary Tree to Linked List](/solution/0100-0199/0114.Flatten%20Binary%20Tree%20to%20Linked%20List/README_EN.md)", "`Tree`,`Depth-first Search`", "Medium", ""]}, {"question_id": "0113", "frontend_question_id": "0113", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/path-sum-ii", "url_en": "https://leetcode.com/problems/path-sum-ii", "relative_path_cn": "/solution/0100-0199/0113.Path%20Sum%20II/README.md", "relative_path_en": "/solution/0100-0199/0113.Path%20Sum%20II/README_EN.md", "title_cn": "\u8def\u5f84\u603b\u548c II", "title_en": "Path Sum II", "question_title_slug": "path-sum-ii", "content_en": "

    Given the root of a binary tree and an integer targetSum, return all root-to-leaf paths where each path's sum equals targetSum.

    \n\n

    A leaf is a node with no children.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [5,4,8,11,null,13,4,7,2,null,null,5,1], targetSum = 22\nOutput: [[5,4,11,2],[5,8,4,5]]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [1,2,3], targetSum = 5\nOutput: []\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = [1,2], targetSum = 0\nOutput: []\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [0, 5000].
    • \n\t
    • -1000 <= Node.val <= 1000
    • \n\t
    • -1000 <= targetSum <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9 root \u548c\u4e00\u4e2a\u6574\u6570\u76ee\u6807\u548c targetSum \uff0c\u627e\u51fa\u6240\u6709 \u4ece\u6839\u8282\u70b9\u5230\u53f6\u5b50\u8282\u70b9 \u8def\u5f84\u603b\u548c\u7b49\u4e8e\u7ed9\u5b9a\u76ee\u6807\u548c\u7684\u8def\u5f84\u3002

    \n\n

    \u53f6\u5b50\u8282\u70b9 \u662f\u6307\u6ca1\u6709\u5b50\u8282\u70b9\u7684\u8282\u70b9\u3002

    \n\n
    \n
    \n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [5,4,8,11,null,13,4,7,2,null,null,5,1], targetSum = 22\n\u8f93\u51fa\uff1a[[5,4,11,2],[5,8,4,5]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [1,2,3], targetSum = 5\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [1,2], targetSum = 0\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u603b\u6570\u5728\u8303\u56f4 [0, 5000] \u5185
    • \n\t
    • -1000 <= Node.val <= 1000
    • \n\t
    • -1000 <= targetSum <= 1000
    • \n
    \n
    \n
    \n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector> pathSum(TreeNode* root, int targetSum) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public List> pathSum(TreeNode root, int targetSum) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def pathSum(self, root, targetSum):\n \"\"\"\n :type root: TreeNode\n :type targetSum: int\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def pathSum(self, root: TreeNode, targetSum: int) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** pathSum(struct TreeNode* root, int targetSum, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public IList> PathSum(TreeNode root, int targetSum) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number} targetSum\n * @return {number[][]}\n */\nvar pathSum = function(root, targetSum) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @param {Integer} target_sum\n# @return {Integer[][]}\ndef path_sum(root, target_sum)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func pathSum(_ root: TreeNode?, _ targetSum: Int) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc pathSum(root *TreeNode, targetSum int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def pathSum(root: TreeNode, targetSum: Int): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun pathSum(root: TreeNode?, targetSum: Int): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn path_sum(root: Option>>, target_sum: i32) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param Integer $targetSum\n * @return Integer[][]\n */\n function pathSum($root, $targetSum) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction pathSum(root: TreeNode | null, targetSum: number): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (path-sum root targetSum)\n (-> (or/c tree-node? #f) exact-integer? (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0113](https://leetcode-cn.com/problems/path-sum-ii)", "[\u8def\u5f84\u603b\u548c II](/solution/0100-0199/0113.Path%20Sum%20II/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0113](https://leetcode.com/problems/path-sum-ii)", "[Path Sum II](/solution/0100-0199/0113.Path%20Sum%20II/README_EN.md)", "`Tree`,`Depth-first Search`", "Medium", ""]}, {"question_id": "0112", "frontend_question_id": "0112", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/path-sum", "url_en": "https://leetcode.com/problems/path-sum", "relative_path_cn": "/solution/0100-0199/0112.Path%20Sum/README.md", "relative_path_en": "/solution/0100-0199/0112.Path%20Sum/README_EN.md", "title_cn": "\u8def\u5f84\u603b\u548c", "title_en": "Path Sum", "question_title_slug": "path-sum", "content_en": "

    Given the root of a binary tree and an integer targetSum, return true if the tree has a root-to-leaf path such that adding up all the values along the path equals targetSum.

    \n\n

    A leaf is a node with no children.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [5,4,8,11,null,13,4,7,2,null,null,null,1], targetSum = 22\nOutput: true\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [1,2,3], targetSum = 5\nOutput: false\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = [1,2], targetSum = 0\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [0, 5000].
    • \n\t
    • -1000 <= Node.val <= 1000
    • \n\t
    • -1000 <= targetSum <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9\u00a0root \u548c\u4e00\u4e2a\u8868\u793a\u76ee\u6807\u548c\u7684\u6574\u6570\u00a0targetSum \uff0c\u5224\u65ad\u8be5\u6811\u4e2d\u662f\u5426\u5b58\u5728 \u6839\u8282\u70b9\u5230\u53f6\u5b50\u8282\u70b9 \u7684\u8def\u5f84\uff0c\u8fd9\u6761\u8def\u5f84\u4e0a\u6240\u6709\u8282\u70b9\u503c\u76f8\u52a0\u7b49\u4e8e\u76ee\u6807\u548c\u00a0targetSum \u3002

    \n\n

    \u53f6\u5b50\u8282\u70b9 \u662f\u6307\u6ca1\u6709\u5b50\u8282\u70b9\u7684\u8282\u70b9\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [5,4,8,11,null,13,4,7,2,null,null,null,1], targetSum = 22\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [1,2,3], targetSum = 5\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [1,2], targetSum = 0\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u7684\u6570\u76ee\u5728\u8303\u56f4 [0, 5000] \u5185
    • \n\t
    • -1000 <= Node.val <= 1000
    • \n\t
    • -1000 <= targetSum <= 1000
    • \n
    \n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n bool hasPathSum(TreeNode* root, int targetSum) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public boolean hasPathSum(TreeNode root, int targetSum) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def hasPathSum(self, root, targetSum):\n \"\"\"\n :type root: TreeNode\n :type targetSum: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def hasPathSum(self, root: TreeNode, targetSum: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nbool hasPathSum(struct TreeNode* root, int targetSum){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public bool HasPathSum(TreeNode root, int targetSum) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number} targetSum\n * @return {boolean}\n */\nvar hasPathSum = function(root, targetSum) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @param {Integer} target_sum\n# @return {Boolean}\ndef has_path_sum(root, target_sum)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func hasPathSum(_ root: TreeNode?, _ targetSum: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc hasPathSum(root *TreeNode, targetSum int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def hasPathSum(root: TreeNode, targetSum: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun hasPathSum(root: TreeNode?, targetSum: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn has_path_sum(root: Option>>, target_sum: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param Integer $targetSum\n * @return Boolean\n */\n function hasPathSum($root, $targetSum) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction hasPathSum(root: TreeNode | null, targetSum: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (has-path-sum root targetSum)\n (-> (or/c tree-node? #f) exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0112](https://leetcode-cn.com/problems/path-sum)", "[\u8def\u5f84\u603b\u548c](/solution/0100-0199/0112.Path%20Sum/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u7b80\u5355", ""], "md_table_row_en": ["[0112](https://leetcode.com/problems/path-sum)", "[Path Sum](/solution/0100-0199/0112.Path%20Sum/README_EN.md)", "`Tree`,`Depth-first Search`", "Easy", ""]}, {"question_id": "0111", "frontend_question_id": "0111", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-depth-of-binary-tree", "url_en": "https://leetcode.com/problems/minimum-depth-of-binary-tree", "relative_path_cn": "/solution/0100-0199/0111.Minimum%20Depth%20of%20Binary%20Tree/README.md", "relative_path_en": "/solution/0100-0199/0111.Minimum%20Depth%20of%20Binary%20Tree/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u7684\u6700\u5c0f\u6df1\u5ea6", "title_en": "Minimum Depth of Binary Tree", "question_title_slug": "minimum-depth-of-binary-tree", "content_en": "

    Given a binary tree, find its minimum depth.

    \n\n

    The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.

    \n\n

    Note: A leaf is a node with no children.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [3,9,20,null,null,15,7]\nOutput: 2\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = [2,null,3,null,4,null,5,null,6]\nOutput: 5\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [0, 105].
    • \n\t
    • -1000 <= Node.val <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811\uff0c\u627e\u51fa\u5176\u6700\u5c0f\u6df1\u5ea6\u3002

    \n\n

    \u6700\u5c0f\u6df1\u5ea6\u662f\u4ece\u6839\u8282\u70b9\u5230\u6700\u8fd1\u53f6\u5b50\u8282\u70b9\u7684\u6700\u77ed\u8def\u5f84\u4e0a\u7684\u8282\u70b9\u6570\u91cf\u3002

    \n\n

    \u8bf4\u660e\uff1a\u53f6\u5b50\u8282\u70b9\u662f\u6307\u6ca1\u6709\u5b50\u8282\u70b9\u7684\u8282\u70b9\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [3,9,20,null,null,15,7]\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [2,null,3,null,4,null,5,null,6]\n\u8f93\u51fa\uff1a5\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u6570\u7684\u8303\u56f4\u5728 [0, 105] \u5185
    • \n\t
    • -1000 <= Node.val <= 1000
    • \n
    \n", "tags_en": ["Tree", "Depth-first Search", "Breadth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int minDepth(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int minDepth(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def minDepth(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def minDepth(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint minDepth(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int MinDepth(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar minDepth = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef min_depth(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func minDepth(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc minDepth(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def minDepth(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun minDepth(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn min_depth(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function minDepth($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction minDepth(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (min-depth root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0111](https://leetcode-cn.com/problems/minimum-depth-of-binary-tree)", "[\u4e8c\u53c9\u6811\u7684\u6700\u5c0f\u6df1\u5ea6](/solution/0100-0199/0111.Minimum%20Depth%20of%20Binary%20Tree/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u7b80\u5355", ""], "md_table_row_en": ["[0111](https://leetcode.com/problems/minimum-depth-of-binary-tree)", "[Minimum Depth of Binary Tree](/solution/0100-0199/0111.Minimum%20Depth%20of%20Binary%20Tree/README_EN.md)", "`Tree`,`Depth-first Search`,`Breadth-first Search`", "Easy", ""]}, {"question_id": "0110", "frontend_question_id": "0110", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/balanced-binary-tree", "url_en": "https://leetcode.com/problems/balanced-binary-tree", "relative_path_cn": "/solution/0100-0199/0110.Balanced%20Binary%20Tree/README.md", "relative_path_en": "/solution/0100-0199/0110.Balanced%20Binary%20Tree/README_EN.md", "title_cn": "\u5e73\u8861\u4e8c\u53c9\u6811", "title_en": "Balanced Binary Tree", "question_title_slug": "balanced-binary-tree", "content_en": "

    Given a binary tree, determine if it is height-balanced.

    \n\n

    For this problem, a height-balanced binary tree is defined as:

    \n\n
    \n

    a binary tree in which the left and right subtrees of every node differ in height by no more than 1.

    \n
    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [3,9,20,null,null,15,7]\nOutput: true\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [1,2,2,3,3,null,null,4,4]\nOutput: false\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = []\nOutput: true\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [0, 5000].
    • \n\t
    • -104 <= Node.val <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811\uff0c\u5224\u65ad\u5b83\u662f\u5426\u662f\u9ad8\u5ea6\u5e73\u8861\u7684\u4e8c\u53c9\u6811\u3002

    \n\n

    \u672c\u9898\u4e2d\uff0c\u4e00\u68f5\u9ad8\u5ea6\u5e73\u8861\u4e8c\u53c9\u6811\u5b9a\u4e49\u4e3a\uff1a

    \n\n
    \n

    \u4e00\u4e2a\u4e8c\u53c9\u6811\u6bcf\u4e2a\u8282\u70b9\u00a0\u7684\u5de6\u53f3\u4e24\u4e2a\u5b50\u6811\u7684\u9ad8\u5ea6\u5dee\u7684\u7edd\u5bf9\u503c\u4e0d\u8d85\u8fc7 1 \u3002

    \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [3,9,20,null,null,15,7]\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [1,2,2,3,3,null,null,4,4]\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = []\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u7684\u8282\u70b9\u6570\u5728\u8303\u56f4 [0, 5000] \u5185
    • \n\t
    • -104 <= Node.val <= 104
    • \n
    \n", "tags_en": ["Tree", "Depth-first Search", "Recursion"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u9012\u5f52"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n bool isBalanced(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public boolean isBalanced(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def isBalanced(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def isBalanced(self, root: TreeNode) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nbool isBalanced(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public bool IsBalanced(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {boolean}\n */\nvar isBalanced = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Boolean}\ndef is_balanced(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func isBalanced(_ root: TreeNode?) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc isBalanced(root *TreeNode) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def isBalanced(root: TreeNode): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun isBalanced(root: TreeNode?): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn is_balanced(root: Option>>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Boolean\n */\n function isBalanced($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction isBalanced(root: TreeNode | null): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (is-balanced root)\n (-> (or/c tree-node? #f) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0110](https://leetcode-cn.com/problems/balanced-binary-tree)", "[\u5e73\u8861\u4e8c\u53c9\u6811](/solution/0100-0199/0110.Balanced%20Binary%20Tree/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u9012\u5f52`", "\u7b80\u5355", ""], "md_table_row_en": ["[0110](https://leetcode.com/problems/balanced-binary-tree)", "[Balanced Binary Tree](/solution/0100-0199/0110.Balanced%20Binary%20Tree/README_EN.md)", "`Tree`,`Depth-first Search`,`Recursion`", "Easy", ""]}, {"question_id": "0109", "frontend_question_id": "0109", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/convert-sorted-list-to-binary-search-tree", "url_en": "https://leetcode.com/problems/convert-sorted-list-to-binary-search-tree", "relative_path_cn": "/solution/0100-0199/0109.Convert%20Sorted%20List%20to%20Binary%20Search%20Tree/README.md", "relative_path_en": "/solution/0100-0199/0109.Convert%20Sorted%20List%20to%20Binary%20Search%20Tree/README_EN.md", "title_cn": "\u6709\u5e8f\u94fe\u8868\u8f6c\u6362\u4e8c\u53c9\u641c\u7d22\u6811", "title_en": "Convert Sorted List to Binary Search Tree", "question_title_slug": "convert-sorted-list-to-binary-search-tree", "content_en": "

    Given the head of a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.

    \n\n

    For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: head = [-10,-3,0,5,9]\nOutput: [0,-3,9,-10,null,5]\nExplanation: One possible answer is [0,-3,9,-10,null,5], which represents the shown height balanced BST.\n
    \n\n

    Example 2:

    \n\n
    \nInput: head = []\nOutput: []\n
    \n\n

    Example 3:

    \n\n
    \nInput: head = [0]\nOutput: [0]\n
    \n\n

    Example 4:

    \n\n
    \nInput: head = [1,3]\nOutput: [3,1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in head is in the range [0, 2 * 104].
    • \n\t
    • -105 <= Node.val <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5355\u94fe\u8868\uff0c\u5176\u4e2d\u7684\u5143\u7d20\u6309\u5347\u5e8f\u6392\u5e8f\uff0c\u5c06\u5176\u8f6c\u6362\u4e3a\u9ad8\u5ea6\u5e73\u8861\u7684\u4e8c\u53c9\u641c\u7d22\u6811\u3002

    \n\n

    \u672c\u9898\u4e2d\uff0c\u4e00\u4e2a\u9ad8\u5ea6\u5e73\u8861\u4e8c\u53c9\u6811\u662f\u6307\u4e00\u4e2a\u4e8c\u53c9\u6811\u6bcf\u4e2a\u8282\u70b9 \u7684\u5de6\u53f3\u4e24\u4e2a\u5b50\u6811\u7684\u9ad8\u5ea6\u5dee\u7684\u7edd\u5bf9\u503c\u4e0d\u8d85\u8fc7 1\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u7ed9\u5b9a\u7684\u6709\u5e8f\u94fe\u8868\uff1a [-10, -3, 0, 5, 9],\n\n\u4e00\u4e2a\u53ef\u80fd\u7684\u7b54\u6848\u662f\uff1a[0, -3, 9, -10, null, 5], \u5b83\u53ef\u4ee5\u8868\u793a\u4e0b\u9762\u8fd9\u4e2a\u9ad8\u5ea6\u5e73\u8861\u4e8c\u53c9\u641c\u7d22\u6811\uff1a\n\n      0\n     / \\\n   -3   9\n   /   /\n -10  5\n
    \n", "tags_en": ["Depth-first Search", "Linked List"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u94fe\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* sortedListToBST(ListNode* head) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode sortedListToBST(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\n# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def sortedListToBST(self, head):\n \"\"\"\n :type head: ListNode\n :rtype: TreeNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\n# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def sortedListToBST(self, head: ListNode) -> TreeNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* sortedListToBST(struct ListNode* head){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode SortedListToBST(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {ListNode} head\n * @return {TreeNode}\n */\nvar sortedListToBST = function(head) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {ListNode} head\n# @return {TreeNode}\ndef sorted_list_to_bst(head)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func sortedListToBST(_ head: ListNode?) -> TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\n/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc sortedListToBST(head *ListNode) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\n/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def sortedListToBST(head: ListNode): TreeNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\n/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun sortedListToBST(head: ListNode?): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\n// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn sorted_list_to_bst(head: Option>) -> Option>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\n/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @return TreeNode\n */\n function sortedListToBST($head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\n/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction sortedListToBST(head: ListNode | null): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (sorted-list-to-bst head)\n (-> (or/c list-node? #f) (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0109](https://leetcode-cn.com/problems/convert-sorted-list-to-binary-search-tree)", "[\u6709\u5e8f\u94fe\u8868\u8f6c\u6362\u4e8c\u53c9\u641c\u7d22\u6811](/solution/0100-0199/0109.Convert%20Sorted%20List%20to%20Binary%20Search%20Tree/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u94fe\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0109](https://leetcode.com/problems/convert-sorted-list-to-binary-search-tree)", "[Convert Sorted List to Binary Search Tree](/solution/0100-0199/0109.Convert%20Sorted%20List%20to%20Binary%20Search%20Tree/README_EN.md)", "`Depth-first Search`,`Linked List`", "Medium", ""]}, {"question_id": "0108", "frontend_question_id": "0108", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/convert-sorted-array-to-binary-search-tree", "url_en": "https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree", "relative_path_cn": "/solution/0100-0199/0108.Convert%20Sorted%20Array%20to%20Binary%20Search%20Tree/README.md", "relative_path_en": "/solution/0100-0199/0108.Convert%20Sorted%20Array%20to%20Binary%20Search%20Tree/README_EN.md", "title_cn": "\u5c06\u6709\u5e8f\u6570\u7ec4\u8f6c\u6362\u4e3a\u4e8c\u53c9\u641c\u7d22\u6811", "title_en": "Convert Sorted Array to Binary Search Tree", "question_title_slug": "convert-sorted-array-to-binary-search-tree", "content_en": "

    Given an integer array nums where the elements are sorted in ascending order, convert it to a height-balanced binary search tree.

    \n\n

    A height-balanced binary tree is a binary tree in which the depth of the two subtrees of every node never differs by more than one.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: nums = [-10,-3,0,5,9]\nOutput: [0,-3,9,-10,null,5]\nExplanation: [0,-10,5,null,-3,null,9] is also accepted:\n\"\"\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: nums = [1,3]\nOutput: [3,1]\nExplanation: [1,3] and [3,1] are both a height-balanced BSTs.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 104
    • \n\t
    • -104 <= nums[i] <= 104
    • \n\t
    • nums is sorted in a strictly increasing order.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \uff0c\u5176\u4e2d\u5143\u7d20\u5df2\u7ecf\u6309 \u5347\u5e8f \u6392\u5217\uff0c\u8bf7\u4f60\u5c06\u5176\u8f6c\u6362\u4e3a\u4e00\u68f5 \u9ad8\u5ea6\u5e73\u8861 \u4e8c\u53c9\u641c\u7d22\u6811\u3002

    \n\n

    \u9ad8\u5ea6\u5e73\u8861 \u4e8c\u53c9\u6811\u662f\u4e00\u68f5\u6ee1\u8db3\u300c\u6bcf\u4e2a\u8282\u70b9\u7684\u5de6\u53f3\u4e24\u4e2a\u5b50\u6811\u7684\u9ad8\u5ea6\u5dee\u7684\u7edd\u5bf9\u503c\u4e0d\u8d85\u8fc7 1 \u300d\u7684\u4e8c\u53c9\u6811\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1anums = [-10,-3,0,5,9]\n\u8f93\u51fa\uff1a[0,-3,9,-10,null,5]\n\u89e3\u91ca\uff1a[0,-10,5,null,-3,null,9] \u4e5f\u5c06\u88ab\u89c6\u4e3a\u6b63\u786e\u7b54\u6848\uff1a\n\"\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1anums = [1,3]\n\u8f93\u51fa\uff1a[3,1]\n\u89e3\u91ca\uff1a[1,3] \u548c [3,1] \u90fd\u662f\u9ad8\u5ea6\u5e73\u8861\u4e8c\u53c9\u641c\u7d22\u6811\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 104
    • \n\t
    • -104 <= nums[i] <= 104
    • \n\t
    • nums \u6309 \u4e25\u683c\u9012\u589e \u987a\u5e8f\u6392\u5217
    • \n
    \n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* sortedArrayToBST(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode sortedArrayToBST(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def sortedArrayToBST(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: TreeNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def sortedArrayToBST(self, nums: List[int]) -> TreeNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* sortedArrayToBST(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode SortedArrayToBST(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {number[]} nums\n * @return {TreeNode}\n */\nvar sortedArrayToBST = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {Integer[]} nums\n# @return {TreeNode}\ndef sorted_array_to_bst(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func sortedArrayToBST(_ nums: [Int]) -> TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc sortedArrayToBST(nums []int) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def sortedArrayToBST(nums: Array[Int]): TreeNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun sortedArrayToBST(nums: IntArray): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn sorted_array_to_bst(nums: Vec) -> Option>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param Integer[] $nums\n * @return TreeNode\n */\n function sortedArrayToBST($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction sortedArrayToBST(nums: number[]): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (sorted-array-to-bst nums)\n (-> (listof exact-integer?) (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0108](https://leetcode-cn.com/problems/convert-sorted-array-to-binary-search-tree)", "[\u5c06\u6709\u5e8f\u6570\u7ec4\u8f6c\u6362\u4e3a\u4e8c\u53c9\u641c\u7d22\u6811](/solution/0100-0199/0108.Convert%20Sorted%20Array%20to%20Binary%20Search%20Tree/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u7b80\u5355", ""], "md_table_row_en": ["[0108](https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree)", "[Convert Sorted Array to Binary Search Tree](/solution/0100-0199/0108.Convert%20Sorted%20Array%20to%20Binary%20Search%20Tree/README_EN.md)", "`Tree`,`Depth-first Search`", "Easy", ""]}, {"question_id": "0107", "frontend_question_id": "0107", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/binary-tree-level-order-traversal-ii", "url_en": "https://leetcode.com/problems/binary-tree-level-order-traversal-ii", "relative_path_cn": "/solution/0100-0199/0107.Binary%20Tree%20Level%20Order%20Traversal%20II/README.md", "relative_path_en": "/solution/0100-0199/0107.Binary%20Tree%20Level%20Order%20Traversal%20II/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u7684\u5c42\u5e8f\u904d\u5386 II", "title_en": "Binary Tree Level Order Traversal II", "question_title_slug": "binary-tree-level-order-traversal-ii", "content_en": "

    Given the root of a binary tree, return the bottom-up level order traversal of its nodes' values. (i.e., from left to right, level by level from leaf to root).

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [3,9,20,null,null,15,7]\nOutput: [[15,7],[9,20],[3]]\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = [1]\nOutput: [[1]]\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = []\nOutput: []\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [0, 2000].
    • \n\t
    • -1000 <= Node.val <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811\uff0c\u8fd4\u56de\u5176\u8282\u70b9\u503c\u81ea\u5e95\u5411\u4e0a\u7684\u5c42\u5e8f\u904d\u5386\u3002 \uff08\u5373\u6309\u4ece\u53f6\u5b50\u8282\u70b9\u6240\u5728\u5c42\u5230\u6839\u8282\u70b9\u6240\u5728\u7684\u5c42\uff0c\u9010\u5c42\u4ece\u5de6\u5411\u53f3\u904d\u5386\uff09

    \n\n

    \u4f8b\u5982\uff1a
    \n\u7ed9\u5b9a\u4e8c\u53c9\u6811 [3,9,20,null,null,15,7],

    \n\n
    \n    3\n   / \\\n  9  20\n    /  \\\n   15   7\n
    \n\n

    \u8fd4\u56de\u5176\u81ea\u5e95\u5411\u4e0a\u7684\u5c42\u5e8f\u904d\u5386\u4e3a\uff1a

    \n\n
    \n[\n  [15,7],\n  [9,20],\n  [3]\n]\n
    \n", "tags_en": ["Tree", "Breadth-first Search"], "tags_cn": ["\u6811", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector> levelOrderBottom(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public List> levelOrderBottom(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def levelOrderBottom(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def levelOrderBottom(self, root: TreeNode) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** levelOrderBottom(struct TreeNode* root, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public IList> LevelOrderBottom(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number[][]}\n */\nvar levelOrderBottom = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer[][]}\ndef level_order_bottom(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func levelOrderBottom(_ root: TreeNode?) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc levelOrderBottom(root *TreeNode) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def levelOrderBottom(root: TreeNode): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun levelOrderBottom(root: TreeNode?): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn level_order_bottom(root: Option>>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer[][]\n */\n function levelOrderBottom($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction levelOrderBottom(root: TreeNode | null): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (level-order-bottom root)\n (-> (or/c tree-node? #f) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0107](https://leetcode-cn.com/problems/binary-tree-level-order-traversal-ii)", "[\u4e8c\u53c9\u6811\u7684\u5c42\u5e8f\u904d\u5386 II](/solution/0100-0199/0107.Binary%20Tree%20Level%20Order%20Traversal%20II/README.md)", "`\u6811`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0107](https://leetcode.com/problems/binary-tree-level-order-traversal-ii)", "[Binary Tree Level Order Traversal II](/solution/0100-0199/0107.Binary%20Tree%20Level%20Order%20Traversal%20II/README_EN.md)", "`Tree`,`Breadth-first Search`", "Medium", ""]}, {"question_id": "0106", "frontend_question_id": "0106", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal", "url_en": "https://leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal", "relative_path_cn": "/solution/0100-0199/0106.Construct%20Binary%20Tree%20from%20Inorder%20and%20Postorder%20Traversal/README.md", "relative_path_en": "/solution/0100-0199/0106.Construct%20Binary%20Tree%20from%20Inorder%20and%20Postorder%20Traversal/README_EN.md", "title_cn": "\u4ece\u4e2d\u5e8f\u4e0e\u540e\u5e8f\u904d\u5386\u5e8f\u5217\u6784\u9020\u4e8c\u53c9\u6811", "title_en": "Construct Binary Tree from Inorder and Postorder Traversal", "question_title_slug": "construct-binary-tree-from-inorder-and-postorder-traversal", "content_en": "

    Given two integer arrays inorder and postorder where inorder is the inorder traversal of a binary tree and postorder is the postorder traversal of the same tree, construct and return the binary tree.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: inorder = [9,3,15,20,7], postorder = [9,15,7,20,3]\nOutput: [3,9,20,null,null,15,7]\n
    \n\n

    Example 2:

    \n\n
    \nInput: inorder = [-1], postorder = [-1]\nOutput: [-1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= inorder.length <= 3000
    • \n\t
    • postorder.length == inorder.length
    • \n\t
    • -3000 <= inorder[i], postorder[i] <= 3000
    • \n\t
    • inorder and postorder consist of unique values.
    • \n\t
    • Each value of postorder also appears in inorder.
    • \n\t
    • inorder is guaranteed to be the inorder traversal of the tree.
    • \n\t
    • postorder is guaranteed to be the postorder traversal of the tree.
    • \n
    \n", "content_cn": "

    \u6839\u636e\u4e00\u68f5\u6811\u7684\u4e2d\u5e8f\u904d\u5386\u4e0e\u540e\u5e8f\u904d\u5386\u6784\u9020\u4e8c\u53c9\u6811\u3002

    \n\n

    \u6ce8\u610f:
    \n\u4f60\u53ef\u4ee5\u5047\u8bbe\u6811\u4e2d\u6ca1\u6709\u91cd\u590d\u7684\u5143\u7d20\u3002

    \n\n

    \u4f8b\u5982\uff0c\u7ed9\u51fa

    \n\n
    \u4e2d\u5e8f\u904d\u5386 inorder = [9,3,15,20,7]\n\u540e\u5e8f\u904d\u5386 postorder = [9,15,7,20,3]
    \n\n

    \u8fd4\u56de\u5982\u4e0b\u7684\u4e8c\u53c9\u6811\uff1a

    \n\n
        3\n   / \\\n  9  20\n    /  \\\n   15   7\n
    \n", "tags_en": ["Tree", "Depth-first Search", "Array"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* buildTree(vector& inorder, vector& postorder) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode buildTree(int[] inorder, int[] postorder) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def buildTree(self, inorder, postorder):\n \"\"\"\n :type inorder: List[int]\n :type postorder: List[int]\n :rtype: TreeNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def buildTree(self, inorder: List[int], postorder: List[int]) -> TreeNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* buildTree(int* inorder, int inorderSize, int* postorder, int postorderSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode BuildTree(int[] inorder, int[] postorder) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {number[]} inorder\n * @param {number[]} postorder\n * @return {TreeNode}\n */\nvar buildTree = function(inorder, postorder) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {Integer[]} inorder\n# @param {Integer[]} postorder\n# @return {TreeNode}\ndef build_tree(inorder, postorder)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func buildTree(_ inorder: [Int], _ postorder: [Int]) -> TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc buildTree(inorder []int, postorder []int) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def buildTree(inorder: Array[Int], postorder: Array[Int]): TreeNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun buildTree(inorder: IntArray, postorder: IntArray): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn build_tree(inorder: Vec, postorder: Vec) -> Option>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param Integer[] $inorder\n * @param Integer[] $postorder\n * @return TreeNode\n */\n function buildTree($inorder, $postorder) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction buildTree(inorder: number[], postorder: number[]): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (build-tree inorder postorder)\n (-> (listof exact-integer?) (listof exact-integer?) (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0106](https://leetcode-cn.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal)", "[\u4ece\u4e2d\u5e8f\u4e0e\u540e\u5e8f\u904d\u5386\u5e8f\u5217\u6784\u9020\u4e8c\u53c9\u6811](/solution/0100-0199/0106.Construct%20Binary%20Tree%20from%20Inorder%20and%20Postorder%20Traversal/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0106](https://leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal)", "[Construct Binary Tree from Inorder and Postorder Traversal](/solution/0100-0199/0106.Construct%20Binary%20Tree%20from%20Inorder%20and%20Postorder%20Traversal/README_EN.md)", "`Tree`,`Depth-first Search`,`Array`", "Medium", ""]}, {"question_id": "0105", "frontend_question_id": "0105", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal", "url_en": "https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal", "relative_path_cn": "/solution/0100-0199/0105.Construct%20Binary%20Tree%20from%20Preorder%20and%20Inorder%20Traversal/README.md", "relative_path_en": "/solution/0100-0199/0105.Construct%20Binary%20Tree%20from%20Preorder%20and%20Inorder%20Traversal/README_EN.md", "title_cn": "\u4ece\u524d\u5e8f\u4e0e\u4e2d\u5e8f\u904d\u5386\u5e8f\u5217\u6784\u9020\u4e8c\u53c9\u6811", "title_en": "Construct Binary Tree from Preorder and Inorder Traversal", "question_title_slug": "construct-binary-tree-from-preorder-and-inorder-traversal", "content_en": "

    Given two integer arrays preorder and inorder where preorder is the preorder traversal of a binary tree and inorder is the inorder traversal of the same tree, construct and return the binary tree.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: preorder = [3,9,20,15,7], inorder = [9,3,15,20,7]\nOutput: [3,9,20,null,null,15,7]\n
    \n\n

    Example 2:

    \n\n
    \nInput: preorder = [-1], inorder = [-1]\nOutput: [-1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= preorder.length <= 3000
    • \n\t
    • inorder.length == preorder.length
    • \n\t
    • -3000 <= preorder[i], inorder[i] <= 3000
    • \n\t
    • preorder and inorder consist of unique values.
    • \n\t
    • Each value of inorder also appears in preorder.
    • \n\t
    • preorder is guaranteed to be the preorder traversal of the tree.
    • \n\t
    • inorder is guaranteed to be the inorder traversal of the tree.
    • \n
    \n", "content_cn": "

    \u6839\u636e\u4e00\u68f5\u6811\u7684\u524d\u5e8f\u904d\u5386\u4e0e\u4e2d\u5e8f\u904d\u5386\u6784\u9020\u4e8c\u53c9\u6811\u3002

    \n\n

    \u6ce8\u610f:
    \n\u4f60\u53ef\u4ee5\u5047\u8bbe\u6811\u4e2d\u6ca1\u6709\u91cd\u590d\u7684\u5143\u7d20\u3002

    \n\n

    \u4f8b\u5982\uff0c\u7ed9\u51fa

    \n\n
    \u524d\u5e8f\u904d\u5386 preorder = [3,9,20,15,7]\n\u4e2d\u5e8f\u904d\u5386 inorder = [9,3,15,20,7]
    \n\n

    \u8fd4\u56de\u5982\u4e0b\u7684\u4e8c\u53c9\u6811\uff1a

    \n\n
        3\n   / \\\n  9  20\n    /  \\\n   15   7
    \n", "tags_en": ["Tree", "Depth-first Search", "Array"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* buildTree(vector& preorder, vector& inorder) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode buildTree(int[] preorder, int[] inorder) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def buildTree(self, preorder, inorder):\n \"\"\"\n :type preorder: List[int]\n :type inorder: List[int]\n :rtype: TreeNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def buildTree(self, preorder: List[int], inorder: List[int]) -> TreeNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* buildTree(int* preorder, int preorderSize, int* inorder, int inorderSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode BuildTree(int[] preorder, int[] inorder) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {number[]} preorder\n * @param {number[]} inorder\n * @return {TreeNode}\n */\nvar buildTree = function(preorder, inorder) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {Integer[]} preorder\n# @param {Integer[]} inorder\n# @return {TreeNode}\ndef build_tree(preorder, inorder)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func buildTree(_ preorder: [Int], _ inorder: [Int]) -> TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc buildTree(preorder []int, inorder []int) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def buildTree(preorder: Array[Int], inorder: Array[Int]): TreeNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun buildTree(preorder: IntArray, inorder: IntArray): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn build_tree(preorder: Vec, inorder: Vec) -> Option>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param Integer[] $preorder\n * @param Integer[] $inorder\n * @return TreeNode\n */\n function buildTree($preorder, $inorder) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction buildTree(preorder: number[], inorder: number[]): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (build-tree preorder inorder)\n (-> (listof exact-integer?) (listof exact-integer?) (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0105](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal)", "[\u4ece\u524d\u5e8f\u4e0e\u4e2d\u5e8f\u904d\u5386\u5e8f\u5217\u6784\u9020\u4e8c\u53c9\u6811](/solution/0100-0199/0105.Construct%20Binary%20Tree%20from%20Preorder%20and%20Inorder%20Traversal/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0105](https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal)", "[Construct Binary Tree from Preorder and Inorder Traversal](/solution/0100-0199/0105.Construct%20Binary%20Tree%20from%20Preorder%20and%20Inorder%20Traversal/README_EN.md)", "`Tree`,`Depth-first Search`,`Array`", "Medium", ""]}, {"question_id": "0104", "frontend_question_id": "0104", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-depth-of-binary-tree", "url_en": "https://leetcode.com/problems/maximum-depth-of-binary-tree", "relative_path_cn": "/solution/0100-0199/0104.Maximum%20Depth%20of%20Binary%20Tree/README.md", "relative_path_en": "/solution/0100-0199/0104.Maximum%20Depth%20of%20Binary%20Tree/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u7684\u6700\u5927\u6df1\u5ea6", "title_en": "Maximum Depth of Binary Tree", "question_title_slug": "maximum-depth-of-binary-tree", "content_en": "

    Given the root of a binary tree, return its maximum depth.

    \r\n\r\n

    A binary tree's maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\"\"\r\n
    \r\nInput: root = [3,9,20,null,null,15,7]\r\nOutput: 3\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: root = [1,null,2]\r\nOutput: 2\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: root = []\r\nOutput: 0\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: root = [0]\r\nOutput: 1\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • The number of nodes in the tree is in the range [0, 104].
    • \r\n\t
    • -100 <= Node.val <= 100
    • \r\n
    ", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811\uff0c\u627e\u51fa\u5176\u6700\u5927\u6df1\u5ea6\u3002

    \n\n

    \u4e8c\u53c9\u6811\u7684\u6df1\u5ea6\u4e3a\u6839\u8282\u70b9\u5230\u6700\u8fdc\u53f6\u5b50\u8282\u70b9\u7684\u6700\u957f\u8def\u5f84\u4e0a\u7684\u8282\u70b9\u6570\u3002

    \n\n

    \u8bf4\u660e: \u53f6\u5b50\u8282\u70b9\u662f\u6307\u6ca1\u6709\u5b50\u8282\u70b9\u7684\u8282\u70b9\u3002

    \n\n

    \u793a\u4f8b\uff1a
    \n\u7ed9\u5b9a\u4e8c\u53c9\u6811 [3,9,20,null,null,15,7]\uff0c

    \n\n
        3\n   / \\\n  9  20\n    /  \\\n   15   7
    \n\n

    \u8fd4\u56de\u5b83\u7684\u6700\u5927\u6df1\u5ea6 3 \u3002

    \n", "tags_en": ["Tree", "Depth-first Search", "Recursion"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u9012\u5f52"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int maxDepth(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int maxDepth(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def maxDepth(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def maxDepth(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint maxDepth(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int MaxDepth(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar maxDepth = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef max_depth(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func maxDepth(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc maxDepth(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def maxDepth(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun maxDepth(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn max_depth(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function maxDepth($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction maxDepth(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (max-depth root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0104](https://leetcode-cn.com/problems/maximum-depth-of-binary-tree)", "[\u4e8c\u53c9\u6811\u7684\u6700\u5927\u6df1\u5ea6](/solution/0100-0199/0104.Maximum%20Depth%20of%20Binary%20Tree/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u9012\u5f52`", "\u7b80\u5355", ""], "md_table_row_en": ["[0104](https://leetcode.com/problems/maximum-depth-of-binary-tree)", "[Maximum Depth of Binary Tree](/solution/0100-0199/0104.Maximum%20Depth%20of%20Binary%20Tree/README_EN.md)", "`Tree`,`Depth-first Search`,`Recursion`", "Easy", ""]}, {"question_id": "0103", "frontend_question_id": "0103", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/binary-tree-zigzag-level-order-traversal", "url_en": "https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal", "relative_path_cn": "/solution/0100-0199/0103.Binary%20Tree%20Zigzag%20Level%20Order%20Traversal/README.md", "relative_path_en": "/solution/0100-0199/0103.Binary%20Tree%20Zigzag%20Level%20Order%20Traversal/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u7684\u952f\u9f7f\u5f62\u5c42\u5e8f\u904d\u5386", "title_en": "Binary Tree Zigzag Level Order Traversal", "question_title_slug": "binary-tree-zigzag-level-order-traversal", "content_en": "

    Given the root of a binary tree, return the zigzag level order traversal of its nodes' values. (i.e., from left to right, then right to left for the next level and alternate between).

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [3,9,20,null,null,15,7]\nOutput: [[3],[20,9],[15,7]]\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = [1]\nOutput: [[1]]\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = []\nOutput: []\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [0, 2000].
    • \n\t
    • -100 <= Node.val <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811\uff0c\u8fd4\u56de\u5176\u8282\u70b9\u503c\u7684\u952f\u9f7f\u5f62\u5c42\u5e8f\u904d\u5386\u3002\uff08\u5373\u5148\u4ece\u5de6\u5f80\u53f3\uff0c\u518d\u4ece\u53f3\u5f80\u5de6\u8fdb\u884c\u4e0b\u4e00\u5c42\u904d\u5386\uff0c\u4ee5\u6b64\u7c7b\u63a8\uff0c\u5c42\u4e0e\u5c42\u4e4b\u95f4\u4ea4\u66ff\u8fdb\u884c\uff09\u3002

    \n\n

    \u4f8b\u5982\uff1a
    \n\u7ed9\u5b9a\u4e8c\u53c9\u6811\u00a0[3,9,20,null,null,15,7],

    \n\n
    \n    3\n   / \\\n  9  20\n    /  \\\n   15   7\n
    \n\n

    \u8fd4\u56de\u952f\u9f7f\u5f62\u5c42\u5e8f\u904d\u5386\u5982\u4e0b\uff1a

    \n\n
    \n[\n  [3],\n  [20,9],\n  [15,7]\n]\n
    \n", "tags_en": ["Stack", "Tree", "Breadth-first Search"], "tags_cn": ["\u6808", "\u6811", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector> zigzagLevelOrder(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public List> zigzagLevelOrder(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def zigzagLevelOrder(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def zigzagLevelOrder(self, root: TreeNode) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** zigzagLevelOrder(struct TreeNode* root, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public IList> ZigzagLevelOrder(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number[][]}\n */\nvar zigzagLevelOrder = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer[][]}\ndef zigzag_level_order(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func zigzagLevelOrder(_ root: TreeNode?) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc zigzagLevelOrder(root *TreeNode) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def zigzagLevelOrder(root: TreeNode): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun zigzagLevelOrder(root: TreeNode?): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn zigzag_level_order(root: Option>>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer[][]\n */\n function zigzagLevelOrder($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction zigzagLevelOrder(root: TreeNode | null): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (zigzag-level-order root)\n (-> (or/c tree-node? #f) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0103](https://leetcode-cn.com/problems/binary-tree-zigzag-level-order-traversal)", "[\u4e8c\u53c9\u6811\u7684\u952f\u9f7f\u5f62\u5c42\u5e8f\u904d\u5386](/solution/0100-0199/0103.Binary%20Tree%20Zigzag%20Level%20Order%20Traversal/README.md)", "`\u6808`,`\u6811`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0103](https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal)", "[Binary Tree Zigzag Level Order Traversal](/solution/0100-0199/0103.Binary%20Tree%20Zigzag%20Level%20Order%20Traversal/README_EN.md)", "`Stack`,`Tree`,`Breadth-first Search`", "Medium", ""]}, {"question_id": "0102", "frontend_question_id": "0102", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/binary-tree-level-order-traversal", "url_en": "https://leetcode.com/problems/binary-tree-level-order-traversal", "relative_path_cn": "/solution/0100-0199/0102.Binary%20Tree%20Level%20Order%20Traversal/README.md", "relative_path_en": "/solution/0100-0199/0102.Binary%20Tree%20Level%20Order%20Traversal/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u7684\u5c42\u5e8f\u904d\u5386", "title_en": "Binary Tree Level Order Traversal", "question_title_slug": "binary-tree-level-order-traversal", "content_en": "

    Given the root of a binary tree, return the level order traversal of its nodes' values. (i.e., from left to right, level by level).

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [3,9,20,null,null,15,7]\nOutput: [[3],[9,20],[15,7]]\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = [1]\nOutput: [[1]]\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = []\nOutput: []\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [0, 2000].
    • \n\t
    • -1000 <= Node.val <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u4e8c\u53c9\u6811\uff0c\u8bf7\u4f60\u8fd4\u56de\u5176\u6309 \u5c42\u5e8f\u904d\u5386 \u5f97\u5230\u7684\u8282\u70b9\u503c\u3002 \uff08\u5373\u9010\u5c42\u5730\uff0c\u4ece\u5de6\u5230\u53f3\u8bbf\u95ee\u6240\u6709\u8282\u70b9\uff09\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a
    \n\u4e8c\u53c9\u6811\uff1a[3,9,20,null,null,15,7],

    \n\n
    \n    3\n   / \\\n  9  20\n    /  \\\n   15   7\n
    \n\n

    \u8fd4\u56de\u5176\u5c42\u5e8f\u904d\u5386\u7ed3\u679c\uff1a

    \n\n
    \n[\n  [3],\n  [9,20],\n  [15,7]\n]\n
    \n", "tags_en": ["Tree", "Breadth-first Search"], "tags_cn": ["\u6811", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector> levelOrder(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public List> levelOrder(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def levelOrder(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def levelOrder(self, root: TreeNode) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** levelOrder(struct TreeNode* root, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public IList> LevelOrder(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number[][]}\n */\nvar levelOrder = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer[][]}\ndef level_order(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func levelOrder(_ root: TreeNode?) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc levelOrder(root *TreeNode) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def levelOrder(root: TreeNode): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun levelOrder(root: TreeNode?): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn level_order(root: Option>>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer[][]\n */\n function levelOrder($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction levelOrder(root: TreeNode | null): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (level-order root)\n (-> (or/c tree-node? #f) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0102](https://leetcode-cn.com/problems/binary-tree-level-order-traversal)", "[\u4e8c\u53c9\u6811\u7684\u5c42\u5e8f\u904d\u5386](/solution/0100-0199/0102.Binary%20Tree%20Level%20Order%20Traversal/README.md)", "`\u6811`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0102](https://leetcode.com/problems/binary-tree-level-order-traversal)", "[Binary Tree Level Order Traversal](/solution/0100-0199/0102.Binary%20Tree%20Level%20Order%20Traversal/README_EN.md)", "`Tree`,`Breadth-first Search`", "Medium", ""]}, {"question_id": "0101", "frontend_question_id": "0101", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/symmetric-tree", "url_en": "https://leetcode.com/problems/symmetric-tree", "relative_path_cn": "/solution/0100-0199/0101.Symmetric%20Tree/README.md", "relative_path_en": "/solution/0100-0199/0101.Symmetric%20Tree/README_EN.md", "title_cn": "\u5bf9\u79f0\u4e8c\u53c9\u6811", "title_en": "Symmetric Tree", "question_title_slug": "symmetric-tree", "content_en": "

    Given the root of a binary tree, check whether it is a mirror of itself (i.e., symmetric around its center).

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,2,2,3,4,4,3]\nOutput: true\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [1,2,2,null,3,null,3]\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 1000].
    • \n\t
    • -100 <= Node.val <= 100
    • \n
    \n\n

     

    \nFollow up: Could you solve it both recursively and iteratively?", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811\uff0c\u68c0\u67e5\u5b83\u662f\u5426\u662f\u955c\u50cf\u5bf9\u79f0\u7684\u3002

    \n\n

     

    \n\n

    \u4f8b\u5982\uff0c\u4e8c\u53c9\u6811 [1,2,2,3,4,4,3] \u662f\u5bf9\u79f0\u7684\u3002

    \n\n
        1\n   / \\\n  2   2\n / \\ / \\\n3  4 4  3\n
    \n\n

     

    \n\n

    \u4f46\u662f\u4e0b\u9762\u8fd9\u4e2a [1,2,2,null,3,null,3] \u5219\u4e0d\u662f\u955c\u50cf\u5bf9\u79f0\u7684:

    \n\n
        1\n   / \\\n  2   2\n   \\   \\\n   3    3\n
    \n\n

     

    \n\n

    \u8fdb\u9636\uff1a

    \n\n

    \u4f60\u53ef\u4ee5\u8fd0\u7528\u9012\u5f52\u548c\u8fed\u4ee3\u4e24\u79cd\u65b9\u6cd5\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u5417\uff1f

    \n", "tags_en": ["Tree", "Depth-first Search", "Breadth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n bool isSymmetric(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public boolean isSymmetric(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def isSymmetric(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def isSymmetric(self, root: TreeNode) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nbool isSymmetric(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public bool IsSymmetric(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {boolean}\n */\nvar isSymmetric = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Boolean}\ndef is_symmetric(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func isSymmetric(_ root: TreeNode?) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc isSymmetric(root *TreeNode) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def isSymmetric(root: TreeNode): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun isSymmetric(root: TreeNode?): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn is_symmetric(root: Option>>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Boolean\n */\n function isSymmetric($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction isSymmetric(root: TreeNode | null): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (is-symmetric root)\n (-> (or/c tree-node? #f) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0101](https://leetcode-cn.com/problems/symmetric-tree)", "[\u5bf9\u79f0\u4e8c\u53c9\u6811](/solution/0100-0199/0101.Symmetric%20Tree/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u7b80\u5355", ""], "md_table_row_en": ["[0101](https://leetcode.com/problems/symmetric-tree)", "[Symmetric Tree](/solution/0100-0199/0101.Symmetric%20Tree/README_EN.md)", "`Tree`,`Depth-first Search`,`Breadth-first Search`", "Easy", ""]}, {"question_id": "0100", "frontend_question_id": "0100", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/same-tree", "url_en": "https://leetcode.com/problems/same-tree", "relative_path_cn": "/solution/0100-0199/0100.Same%20Tree/README.md", "relative_path_en": "/solution/0100-0199/0100.Same%20Tree/README_EN.md", "title_cn": "\u76f8\u540c\u7684\u6811", "title_en": "Same Tree", "question_title_slug": "same-tree", "content_en": "

    Given the roots of two binary trees p and q, write a function to check if they are the same or not.

    \n\n

    Two binary trees are considered the same if they are structurally identical, and the nodes have the same value.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: p = [1,2,3], q = [1,2,3]\nOutput: true\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: p = [1,2], q = [1,null,2]\nOutput: false\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: p = [1,2,1], q = [1,1,2]\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in both trees is in the range [0, 100].
    • \n\t
    • -104 <= Node.val <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u68f5\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9 p \u548c q \uff0c\u7f16\u5199\u4e00\u4e2a\u51fd\u6570\u6765\u68c0\u9a8c\u8fd9\u4e24\u68f5\u6811\u662f\u5426\u76f8\u540c\u3002

    \n\n

    \u5982\u679c\u4e24\u4e2a\u6811\u5728\u7ed3\u6784\u4e0a\u76f8\u540c\uff0c\u5e76\u4e14\u8282\u70b9\u5177\u6709\u76f8\u540c\u7684\u503c\uff0c\u5219\u8ba4\u4e3a\u5b83\u4eec\u662f\u76f8\u540c\u7684\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1ap = [1,2,3], q = [1,2,3]\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1ap = [1,2], q = [1,null,2]\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1ap = [1,2,1], q = [1,1,2]\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u4e24\u68f5\u6811\u4e0a\u7684\u8282\u70b9\u6570\u76ee\u90fd\u5728\u8303\u56f4 [0, 100] \u5185
    • \n\t
    • -104 <= Node.val <= 104
    • \n
    \n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n bool isSameTree(TreeNode* p, TreeNode* q) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public boolean isSameTree(TreeNode p, TreeNode q) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def isSameTree(self, p, q):\n \"\"\"\n :type p: TreeNode\n :type q: TreeNode\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def isSameTree(self, p: TreeNode, q: TreeNode) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nbool isSameTree(struct TreeNode* p, struct TreeNode* q){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public bool IsSameTree(TreeNode p, TreeNode q) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} p\n * @param {TreeNode} q\n * @return {boolean}\n */\nvar isSameTree = function(p, q) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} p\n# @param {TreeNode} q\n# @return {Boolean}\ndef is_same_tree(p, q)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func isSameTree(_ p: TreeNode?, _ q: TreeNode?) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc isSameTree(p *TreeNode, q *TreeNode) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def isSameTree(p: TreeNode, q: TreeNode): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun isSameTree(p: TreeNode?, q: TreeNode?): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn is_same_tree(p: Option>>, q: Option>>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $p\n * @param TreeNode $q\n * @return Boolean\n */\n function isSameTree($p, $q) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction isSameTree(p: TreeNode | null, q: TreeNode | null): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (is-same-tree p q)\n (-> (or/c tree-node? #f) (or/c tree-node? #f) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0100](https://leetcode-cn.com/problems/same-tree)", "[\u76f8\u540c\u7684\u6811](/solution/0100-0199/0100.Same%20Tree/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u7b80\u5355", ""], "md_table_row_en": ["[0100](https://leetcode.com/problems/same-tree)", "[Same Tree](/solution/0100-0199/0100.Same%20Tree/README_EN.md)", "`Tree`,`Depth-first Search`", "Easy", ""]}, {"question_id": "0099", "frontend_question_id": "0099", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/recover-binary-search-tree", "url_en": "https://leetcode.com/problems/recover-binary-search-tree", "relative_path_cn": "/solution/0000-0099/0099.Recover%20Binary%20Search%20Tree/README.md", "relative_path_en": "/solution/0000-0099/0099.Recover%20Binary%20Search%20Tree/README_EN.md", "title_cn": "\u6062\u590d\u4e8c\u53c9\u641c\u7d22\u6811", "title_en": "Recover Binary Search Tree", "question_title_slug": "recover-binary-search-tree", "content_en": "

    You are given the root of a binary search tree (BST), where exactly two nodes of the tree were swapped by mistake. Recover the tree without changing its structure.

    \n\n

    Follow up: A solution using O(n) space is pretty straight forward. Could you devise a constant space solution?

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,3,null,null,2]\nOutput: [3,1,null,null,2]\nExplanation: 3 cannot be a left child of 1 because 3 > 1. Swapping 1 and 3 makes the BST valid.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [3,1,4,null,null,2]\nOutput: [2,1,4,null,null,3]\nExplanation: 2 cannot be in the right subtree of 3 because 2 < 3. Swapping 2 and 3 makes the BST valid.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [2, 1000].
    • \n\t
    • -231 <= Node.val <= 231 - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6839\u8282\u70b9 root \uff0c\u8be5\u6811\u4e2d\u7684\u4e24\u4e2a\u8282\u70b9\u88ab\u9519\u8bef\u5730\u4ea4\u6362\u3002\u8bf7\u5728\u4e0d\u6539\u53d8\u5176\u7ed3\u6784\u7684\u60c5\u51b5\u4e0b\uff0c\u6062\u590d\u8fd9\u68f5\u6811\u3002

    \n\n

    \u8fdb\u9636\uff1a\u4f7f\u7528 O(n) \u7a7a\u95f4\u590d\u6742\u5ea6\u7684\u89e3\u6cd5\u5f88\u5bb9\u6613\u5b9e\u73b0\u3002\u4f60\u80fd\u60f3\u51fa\u4e00\u4e2a\u53ea\u4f7f\u7528\u5e38\u6570\u7a7a\u95f4\u7684\u89e3\u51b3\u65b9\u6848\u5417\uff1f

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [1,3,null,null,2]\n\u8f93\u51fa\uff1a[3,1,null,null,2]\n\u89e3\u91ca\uff1a3 \u4e0d\u80fd\u662f 1 \u5de6\u5b69\u5b50\uff0c\u56e0\u4e3a 3 > 1 \u3002\u4ea4\u6362 1 \u548c 3 \u4f7f\u4e8c\u53c9\u641c\u7d22\u6811\u6709\u6548\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [3,1,4,null,null,2]\n\u8f93\u51fa\uff1a[2,1,4,null,null,3]\n\u89e3\u91ca\uff1a2 \u4e0d\u80fd\u5728 3 \u7684\u53f3\u5b50\u6811\u4e2d\uff0c\u56e0\u4e3a 2 < 3 \u3002\u4ea4\u6362 2 \u548c 3 \u4f7f\u4e8c\u53c9\u641c\u7d22\u6811\u6709\u6548\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e0a\u8282\u70b9\u7684\u6570\u76ee\u5728\u8303\u56f4 [2, 1000] \u5185
    • \n\t
    • -231 <= Node.val <= 231 - 1
    • \n
    \n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n void recoverTree(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public void recoverTree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def recoverTree(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: None Do not return anything, modify root in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def recoverTree(self, root: TreeNode) -> None:\n \"\"\"\n Do not return anything, modify root in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nvoid recoverTree(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public void RecoverTree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {void} Do not return anything, modify root in-place instead.\n */\nvar recoverTree = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Void} Do not return anything, modify root in-place instead.\ndef recover_tree(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func recoverTree(_ root: TreeNode?) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc recoverTree(root *TreeNode) {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def recoverTree(root: TreeNode): Unit = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun recoverTree(root: TreeNode?): Unit {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn recover_tree(root: &mut Option>>) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return NULL\n */\n function recoverTree($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\n/**\n Do not return anything, modify root in-place instead.\n */\nfunction recoverTree(root: TreeNode | null): void {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (recover-tree root)\n (-> (or/c tree-node? #f) void?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0099](https://leetcode-cn.com/problems/recover-binary-search-tree)", "[\u6062\u590d\u4e8c\u53c9\u641c\u7d22\u6811](/solution/0000-0099/0099.Recover%20Binary%20Search%20Tree/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[0099](https://leetcode.com/problems/recover-binary-search-tree)", "[Recover Binary Search Tree](/solution/0000-0099/0099.Recover%20Binary%20Search%20Tree/README_EN.md)", "`Tree`,`Depth-first Search`", "Hard", ""]}, {"question_id": "0098", "frontend_question_id": "0098", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/validate-binary-search-tree", "url_en": "https://leetcode.com/problems/validate-binary-search-tree", "relative_path_cn": "/solution/0000-0099/0098.Validate%20Binary%20Search%20Tree/README.md", "relative_path_en": "/solution/0000-0099/0098.Validate%20Binary%20Search%20Tree/README_EN.md", "title_cn": "\u9a8c\u8bc1\u4e8c\u53c9\u641c\u7d22\u6811", "title_en": "Validate Binary Search Tree", "question_title_slug": "validate-binary-search-tree", "content_en": "

    Given the root of a binary tree, determine if it is a valid binary search tree (BST).

    \n\n

    A valid BST is defined as follows:

    \n\n
      \n\t
    • The left subtree of a node contains only nodes with keys less than the node's key.
    • \n\t
    • The right subtree of a node contains only nodes with keys greater than the node's key.
    • \n\t
    • Both the left and right subtrees must also be binary search trees.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [2,1,3]\nOutput: true\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [5,1,4,null,null,3,6]\nOutput: false\nExplanation: The root node's value is 5 but its right child's value is 4.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 104].
    • \n\t
    • -231 <= Node.val <= 231 - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811\uff0c\u5224\u65ad\u5176\u662f\u5426\u662f\u4e00\u4e2a\u6709\u6548\u7684\u4e8c\u53c9\u641c\u7d22\u6811\u3002

    \n\n

    \u5047\u8bbe\u4e00\u4e2a\u4e8c\u53c9\u641c\u7d22\u6811\u5177\u6709\u5982\u4e0b\u7279\u5f81\uff1a

    \n\n
      \n\t
    • \u8282\u70b9\u7684\u5de6\u5b50\u6811\u53ea\u5305\u542b\u5c0f\u4e8e\u5f53\u524d\u8282\u70b9\u7684\u6570\u3002
    • \n\t
    • \u8282\u70b9\u7684\u53f3\u5b50\u6811\u53ea\u5305\u542b\u5927\u4e8e\u5f53\u524d\u8282\u70b9\u7684\u6570\u3002
    • \n\t
    • \u6240\u6709\u5de6\u5b50\u6811\u548c\u53f3\u5b50\u6811\u81ea\u8eab\u5fc5\u987b\u4e5f\u662f\u4e8c\u53c9\u641c\u7d22\u6811\u3002
    • \n
    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165:\n    2\n   / \\\n  1   3\n\u8f93\u51fa: true\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165:\n    5\n   / \\\n  1   4\n     / \\\n    3   6\n\u8f93\u51fa: false\n\u89e3\u91ca: \u8f93\u5165\u4e3a: [5,1,4,null,null,3,6]\u3002\n     \u6839\u8282\u70b9\u7684\u503c\u4e3a 5 \uff0c\u4f46\u662f\u5176\u53f3\u5b50\u8282\u70b9\u503c\u4e3a 4 \u3002\n
    \n", "tags_en": ["Tree", "Depth-first Search", "Recursion"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u9012\u5f52"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n bool isValidBST(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public boolean isValidBST(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def isValidBST(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def isValidBST(self, root: TreeNode) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nbool isValidBST(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public bool IsValidBST(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {boolean}\n */\nvar isValidBST = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Boolean}\ndef is_valid_bst(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func isValidBST(_ root: TreeNode?) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc isValidBST(root *TreeNode) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def isValidBST(root: TreeNode): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun isValidBST(root: TreeNode?): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn is_valid_bst(root: Option>>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Boolean\n */\n function isValidBST($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction isValidBST(root: TreeNode | null): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (is-valid-bst root)\n (-> (or/c tree-node? #f) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0098](https://leetcode-cn.com/problems/validate-binary-search-tree)", "[\u9a8c\u8bc1\u4e8c\u53c9\u641c\u7d22\u6811](/solution/0000-0099/0098.Validate%20Binary%20Search%20Tree/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u9012\u5f52`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0098](https://leetcode.com/problems/validate-binary-search-tree)", "[Validate Binary Search Tree](/solution/0000-0099/0098.Validate%20Binary%20Search%20Tree/README_EN.md)", "`Tree`,`Depth-first Search`,`Recursion`", "Medium", ""]}, {"question_id": "0097", "frontend_question_id": "0097", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/interleaving-string", "url_en": "https://leetcode.com/problems/interleaving-string", "relative_path_cn": "/solution/0000-0099/0097.Interleaving%20String/README.md", "relative_path_en": "/solution/0000-0099/0097.Interleaving%20String/README_EN.md", "title_cn": "\u4ea4\u9519\u5b57\u7b26\u4e32", "title_en": "Interleaving String", "question_title_slug": "interleaving-string", "content_en": "

    Given strings s1, s2, and s3, find whether s3 is formed by an interleaving of s1 and s2.

    \n\n

    An interleaving of two strings s and t is a configuration where they are divided into non-empty substrings such that:

    \n\n
      \n\t
    • s = s1 + s2 + ... + sn
    • \n\t
    • t = t1 + t2 + ... + tm
    • \n\t
    • |n - m| <= 1
    • \n\t
    • The interleaving is s1 + t1 + s2 + t2 + s3 + t3 + ... or t1 + s1 + t2 + s2 + t3 + s3 + ...
    • \n
    \n\n

    Note: a + b is the concatenation of strings a and b.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: s1 = "aabcc", s2 = "dbbca", s3 = "aadbbcbcac"\nOutput: true\n
    \n\n

    Example 2:

    \n\n
    \nInput: s1 = "aabcc", s2 = "dbbca", s3 = "aadbbbaccc"\nOutput: false\n
    \n\n

    Example 3:

    \n\n
    \nInput: s1 = "", s2 = "", s3 = ""\nOutput: true\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= s1.length, s2.length <= 100
    • \n\t
    • 0 <= s3.length <= 200
    • \n\t
    • s1, s2, and s3 consist of lowercase English letters.
    • \n
    \n\n

     

    \n

    Follow up: Could you solve it using only O(s2.length) additional memory space?

    \n", "content_cn": "

    \u7ed9\u5b9a\u4e09\u4e2a\u5b57\u7b26\u4e32\u00a0s1\u3001s2\u3001s3\uff0c\u8bf7\u4f60\u5e2e\u5fd9\u9a8c\u8bc1\u00a0s3\u00a0\u662f\u5426\u662f\u7531\u00a0s1\u00a0\u548c\u00a0s2 \u4ea4\u9519 \u7ec4\u6210\u7684\u3002

    \n\n

    \u4e24\u4e2a\u5b57\u7b26\u4e32 s \u548c t \u4ea4\u9519 \u7684\u5b9a\u4e49\u4e0e\u8fc7\u7a0b\u5982\u4e0b\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5b57\u7b26\u4e32\u90fd\u4f1a\u88ab\u5206\u5272\u6210\u82e5\u5e72 \u975e\u7a7a \u5b50\u5b57\u7b26\u4e32\uff1a

    \n\n
      \n\t
    • s = s1 + s2 + ... + sn
    • \n\t
    • t = t1 + t2 + ... + tm
    • \n\t
    • |n - m| <= 1
    • \n\t
    • \u4ea4\u9519 \u662f s1 + t1 + s2 + t2 + s3 + t3 + ... \u6216\u8005 t1 + s1 + t2 + s2 + t3 + s3 + ...
    • \n
    \n\n

    \u63d0\u793a\uff1aa + b \u610f\u5473\u7740\u5b57\u7b26\u4e32 a \u548c b \u8fde\u63a5\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1as1 = \"aabcc\", s2 = \"dbbca\", s3 = \"aadbbcbcac\"\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as1 = \"aabcc\", s2 = \"dbbca\", s3 = \"aadbbbaccc\"\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as1 = \"\", s2 = \"\", s3 = \"\"\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= s1.length, s2.length <= 100
    • \n\t
    • 0 <= s3.length <= 200
    • \n\t
    • s1\u3001s2\u3001\u548c s3 \u90fd\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n", "tags_en": ["String", "Dynamic Programming"], "tags_cn": ["\u5b57\u7b26\u4e32", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isInterleave(string s1, string s2, string s3) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isInterleave(String s1, String s2, String s3) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isInterleave(self, s1, s2, s3):\n \"\"\"\n :type s1: str\n :type s2: str\n :type s3: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isInterleave(self, s1: str, s2: str, s3: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isInterleave(char * s1, char * s2, char * s3){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsInterleave(string s1, string s2, string s3) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s1\n * @param {string} s2\n * @param {string} s3\n * @return {boolean}\n */\nvar isInterleave = function(s1, s2, s3) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s1\n# @param {String} s2\n# @param {String} s3\n# @return {Boolean}\ndef is_interleave(s1, s2, s3)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isInterleave(_ s1: String, _ s2: String, _ s3: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isInterleave(s1 string, s2 string, s3 string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isInterleave(s1: String, s2: String, s3: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isInterleave(s1: String, s2: String, s3: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_interleave(s1: String, s2: String, s3: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s1\n * @param String $s2\n * @param String $s3\n * @return Boolean\n */\n function isInterleave($s1, $s2, $s3) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isInterleave(s1: string, s2: string, s3: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-interleave s1 s2 s3)\n (-> string? string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0097](https://leetcode-cn.com/problems/interleaving-string)", "[\u4ea4\u9519\u5b57\u7b26\u4e32](/solution/0000-0099/0097.Interleaving%20String/README.md)", "`\u5b57\u7b26\u4e32`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0097](https://leetcode.com/problems/interleaving-string)", "[Interleaving String](/solution/0000-0099/0097.Interleaving%20String/README_EN.md)", "`String`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0096", "frontend_question_id": "0096", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/unique-binary-search-trees", "url_en": "https://leetcode.com/problems/unique-binary-search-trees", "relative_path_cn": "/solution/0000-0099/0096.Unique%20Binary%20Search%20Trees/README.md", "relative_path_en": "/solution/0000-0099/0096.Unique%20Binary%20Search%20Trees/README_EN.md", "title_cn": "\u4e0d\u540c\u7684\u4e8c\u53c9\u641c\u7d22\u6811", "title_en": "Unique Binary Search Trees", "question_title_slug": "unique-binary-search-trees", "content_en": "

    Given an integer n, return the number of structurally unique BST's (binary search trees) which has exactly n nodes of unique values from 1 to n.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: n = 3\nOutput: 5\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 1\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 19
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n \uff0c\u6c42\u6070\u7531 n \u4e2a\u8282\u70b9\u7ec4\u6210\u4e14\u8282\u70b9\u503c\u4ece 1 \u5230 n \u4e92\u4e0d\u76f8\u540c\u7684 \u4e8c\u53c9\u641c\u7d22\u6811 \u6709\u591a\u5c11\u79cd\uff1f\u8fd4\u56de\u6ee1\u8db3\u9898\u610f\u7684\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u79cd\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1an = 3\n\u8f93\u51fa\uff1a5\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 19
    • \n
    \n", "tags_en": ["Tree", "Dynamic Programming"], "tags_cn": ["\u6811", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numTrees(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numTrees(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numTrees(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numTrees(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numTrees(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumTrees(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar numTrees = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef num_trees(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numTrees(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numTrees(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numTrees(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numTrees(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_trees(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function numTrees($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numTrees(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-trees n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0096](https://leetcode-cn.com/problems/unique-binary-search-trees)", "[\u4e0d\u540c\u7684\u4e8c\u53c9\u641c\u7d22\u6811](/solution/0000-0099/0096.Unique%20Binary%20Search%20Trees/README.md)", "`\u6811`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0096](https://leetcode.com/problems/unique-binary-search-trees)", "[Unique Binary Search Trees](/solution/0000-0099/0096.Unique%20Binary%20Search%20Trees/README_EN.md)", "`Tree`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0095", "frontend_question_id": "0095", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/unique-binary-search-trees-ii", "url_en": "https://leetcode.com/problems/unique-binary-search-trees-ii", "relative_path_cn": "/solution/0000-0099/0095.Unique%20Binary%20Search%20Trees%20II/README.md", "relative_path_en": "/solution/0000-0099/0095.Unique%20Binary%20Search%20Trees%20II/README_EN.md", "title_cn": "\u4e0d\u540c\u7684\u4e8c\u53c9\u641c\u7d22\u6811 II", "title_en": "Unique Binary Search Trees II", "question_title_slug": "unique-binary-search-trees-ii", "content_en": "

    Given an integer n, return all the structurally unique BST's (binary search trees), which has exactly n nodes of unique values from 1 to n. Return the answer in any order.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: n = 3\nOutput: [[1,null,2,null,3],[1,null,3,2],[2,1,3],[3,1,null,null,2],[3,2,null,1]]\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 1\nOutput: [[1]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 8
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n \uff0c\u8bf7\u4f60\u751f\u6210\u5e76\u8fd4\u56de\u6240\u6709\u7531 n \u4e2a\u8282\u70b9\u7ec4\u6210\u4e14\u8282\u70b9\u503c\u4ece 1 \u5230 n \u4e92\u4e0d\u76f8\u540c\u7684\u4e0d\u540c \u4e8c\u53c9\u641c\u7d22\u6811 \u3002\u53ef\u4ee5\u6309 \u4efb\u610f\u987a\u5e8f \u8fd4\u56de\u7b54\u6848\u3002

    \n\n

    \u00a0

    \n\n
    \n
    \n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1an = 3\n\u8f93\u51fa\uff1a[[1,null,2,null,3],[1,null,3,2],[2,1,3],[3,1,null,null,2],[3,2,null,1]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1a[[1]]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 8
    • \n
    \n
    \n
    \n", "tags_en": ["Tree", "Dynamic Programming"], "tags_cn": ["\u6811", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector generateTrees(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public List generateTrees(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def generateTrees(self, n):\n \"\"\"\n :type n: int\n :rtype: List[TreeNode]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def generateTrees(self, n: int) -> List[TreeNode]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nstruct TreeNode** generateTrees(int n, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public IList GenerateTrees(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {number} n\n * @return {TreeNode[]}\n */\nvar generateTrees = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {Integer} n\n# @return {TreeNode[]}\ndef generate_trees(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func generateTrees(_ n: Int) -> [TreeNode?] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc generateTrees(n int) []*TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def generateTrees(n: Int): List[TreeNode] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun generateTrees(n: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn generate_trees(n: i32) -> Vec>>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param Integer $n\n * @return TreeNode[]\n */\n function generateTrees($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction generateTrees(n: number): Array {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (generate-trees n)\n (-> exact-integer? (listof (or/c tree-node? #f)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0095](https://leetcode-cn.com/problems/unique-binary-search-trees-ii)", "[\u4e0d\u540c\u7684\u4e8c\u53c9\u641c\u7d22\u6811 II](/solution/0000-0099/0095.Unique%20Binary%20Search%20Trees%20II/README.md)", "`\u6811`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0095](https://leetcode.com/problems/unique-binary-search-trees-ii)", "[Unique Binary Search Trees II](/solution/0000-0099/0095.Unique%20Binary%20Search%20Trees%20II/README_EN.md)", "`Tree`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0094", "frontend_question_id": "0094", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/binary-tree-inorder-traversal", "url_en": "https://leetcode.com/problems/binary-tree-inorder-traversal", "relative_path_cn": "/solution/0000-0099/0094.Binary%20Tree%20Inorder%20Traversal/README.md", "relative_path_en": "/solution/0000-0099/0094.Binary%20Tree%20Inorder%20Traversal/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u7684\u4e2d\u5e8f\u904d\u5386", "title_en": "Binary Tree Inorder Traversal", "question_title_slug": "binary-tree-inorder-traversal", "content_en": "

    Given the root of a binary tree, return the inorder traversal of its nodes' values.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,null,2,3]\nOutput: [1,3,2]\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = []\nOutput: []\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = [1]\nOutput: [1]\n
    \n\n

    Example 4:

    \n\"\"\n
    \nInput: root = [1,2]\nOutput: [2,1]\n
    \n\n

    Example 5:

    \n\"\"\n
    \nInput: root = [1,null,2]\nOutput: [1,2]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [0, 100].
    • \n\t
    • -100 <= Node.val <= 100
    • \n
    \n\n

     

    \nFollow up: Recursive solution is trivial, could you do it iteratively?", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9 root \uff0c\u8fd4\u56de\u5b83\u7684 \u4e2d\u5e8f\u00a0\u904d\u5386\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [1,null,2,3]\n\u8f93\u51fa\uff1a[1,3,2]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = []\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [1]\n\u8f93\u51fa\uff1a[1]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [1,2]\n\u8f93\u51fa\uff1a[2,1]\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [1,null,2]\n\u8f93\u51fa\uff1a[1,2]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u6570\u76ee\u5728\u8303\u56f4 [0, 100] \u5185
    • \n\t
    • -100 <= Node.val <= 100
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636:\u00a0\u9012\u5f52\u7b97\u6cd5\u5f88\u7b80\u5355\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u8fed\u4ee3\u7b97\u6cd5\u5b8c\u6210\u5417\uff1f

    \n", "tags_en": ["Stack", "Tree", "Hash Table"], "tags_cn": ["\u6808", "\u6811", "\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector inorderTraversal(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public List inorderTraversal(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def inorderTraversal(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def inorderTraversal(self, root: TreeNode) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* inorderTraversal(struct TreeNode* root, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public IList InorderTraversal(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number[]}\n */\nvar inorderTraversal = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer[]}\ndef inorder_traversal(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func inorderTraversal(_ root: TreeNode?) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc inorderTraversal(root *TreeNode) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def inorderTraversal(root: TreeNode): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun inorderTraversal(root: TreeNode?): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn inorder_traversal(root: Option>>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer[]\n */\n function inorderTraversal($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction inorderTraversal(root: TreeNode | null): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (inorder-traversal root)\n (-> (or/c tree-node? #f) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0094](https://leetcode-cn.com/problems/binary-tree-inorder-traversal)", "[\u4e8c\u53c9\u6811\u7684\u4e2d\u5e8f\u904d\u5386](/solution/0000-0099/0094.Binary%20Tree%20Inorder%20Traversal/README.md)", "`\u6808`,`\u6811`,`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0094](https://leetcode.com/problems/binary-tree-inorder-traversal)", "[Binary Tree Inorder Traversal](/solution/0000-0099/0094.Binary%20Tree%20Inorder%20Traversal/README_EN.md)", "`Stack`,`Tree`,`Hash Table`", "Easy", ""]}, {"question_id": "0093", "frontend_question_id": "0093", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/restore-ip-addresses", "url_en": "https://leetcode.com/problems/restore-ip-addresses", "relative_path_cn": "/solution/0000-0099/0093.Restore%20IP%20Addresses/README.md", "relative_path_en": "/solution/0000-0099/0093.Restore%20IP%20Addresses/README_EN.md", "title_cn": "\u590d\u539f IP \u5730\u5740", "title_en": "Restore IP Addresses", "question_title_slug": "restore-ip-addresses", "content_en": "

    Given a string s containing only digits, return all possible valid IP addresses that can be obtained from s. You can return them in any order.

    \n\n

    A valid IP address consists of exactly four integers, each integer is between 0 and 255, separated by single dots and cannot have leading zeros. For example, "0.1.2.201" and "192.168.1.1" are valid IP addresses and "0.011.255.245", "192.168.1.312" and "192.168@1.1" are invalid IP addresses. 

    \n\n

     

    \n

    Example 1:

    \n
    Input: s = \"25525511135\"\nOutput: [\"255.255.11.135\",\"255.255.111.35\"]\n

    Example 2:

    \n
    Input: s = \"0000\"\nOutput: [\"0.0.0.0\"]\n

    Example 3:

    \n
    Input: s = \"1111\"\nOutput: [\"1.1.1.1\"]\n

    Example 4:

    \n
    Input: s = \"010010\"\nOutput: [\"0.10.0.10\",\"0.100.1.0\"]\n

    Example 5:

    \n
    Input: s = \"101023\"\nOutput: [\"1.0.10.23\",\"1.0.102.3\",\"10.1.0.23\",\"10.10.2.3\",\"101.0.2.3\"]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= s.length <= 3000
    • \n\t
    • s consists of digits only.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u53ea\u5305\u542b\u6570\u5b57\u7684\u5b57\u7b26\u4e32\uff0c\u7528\u4ee5\u8868\u793a\u4e00\u4e2a IP \u5730\u5740\uff0c\u8fd4\u56de\u6240\u6709\u53ef\u80fd\u4ece s \u83b7\u5f97\u7684 \u6709\u6548 IP \u5730\u5740 \u3002\u4f60\u53ef\u4ee5\u6309\u4efb\u4f55\u987a\u5e8f\u8fd4\u56de\u7b54\u6848\u3002

    \n\n

    \u6709\u6548 IP \u5730\u5740 \u6b63\u597d\u7531\u56db\u4e2a\u6574\u6570\uff08\u6bcf\u4e2a\u6574\u6570\u4f4d\u4e8e 0 \u5230 255 \u4e4b\u95f4\u7ec4\u6210\uff0c\u4e14\u4e0d\u80fd\u542b\u6709\u524d\u5bfc 0\uff09\uff0c\u6574\u6570\u4e4b\u95f4\u7528 '.' \u5206\u9694\u3002

    \n\n

    \u4f8b\u5982\uff1a\"0.1.2.201\" \u548c \"192.168.1.1\" \u662f \u6709\u6548 IP \u5730\u5740\uff0c\u4f46\u662f \"0.011.255.245\"\u3001\"192.168.1.312\" \u548c \"192.168@1.1\" \u662f \u65e0\u6548 IP \u5730\u5740\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"25525511135\"\n\u8f93\u51fa\uff1a[\"255.255.11.135\",\"255.255.111.35\"]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"0000\"\n\u8f93\u51fa\uff1a[\"0.0.0.0\"]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"1111\"\n\u8f93\u51fa\uff1a[\"1.1.1.1\"]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"010010\"\n\u8f93\u51fa\uff1a[\"0.10.0.10\",\"0.100.1.0\"]\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"101023\"\n\u8f93\u51fa\uff1a[\"1.0.10.23\",\"1.0.102.3\",\"10.1.0.23\",\"10.10.2.3\",\"101.0.2.3\"]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= s.length <= 3000
    • \n\t
    • s \u4ec5\u7531\u6570\u5b57\u7ec4\u6210
    • \n
    \n", "tags_en": ["String", "Backtracking"], "tags_cn": ["\u5b57\u7b26\u4e32", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector restoreIpAddresses(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List restoreIpAddresses(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def restoreIpAddresses(self, s):\n \"\"\"\n :type s: str\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def restoreIpAddresses(self, s: str) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** restoreIpAddresses(char * s, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList RestoreIpAddresses(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string[]}\n */\nvar restoreIpAddresses = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String[]}\ndef restore_ip_addresses(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func restoreIpAddresses(_ s: String) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func restoreIpAddresses(s string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def restoreIpAddresses(s: String): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun restoreIpAddresses(s: String): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn restore_ip_addresses(s: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String[]\n */\n function restoreIpAddresses($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function restoreIpAddresses(s: string): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (restore-ip-addresses s)\n (-> string? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0093](https://leetcode-cn.com/problems/restore-ip-addresses)", "[\u590d\u539f IP \u5730\u5740](/solution/0000-0099/0093.Restore%20IP%20Addresses/README.md)", "`\u5b57\u7b26\u4e32`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0093](https://leetcode.com/problems/restore-ip-addresses)", "[Restore IP Addresses](/solution/0000-0099/0093.Restore%20IP%20Addresses/README_EN.md)", "`String`,`Backtracking`", "Medium", ""]}, {"question_id": "0092", "frontend_question_id": "0092", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reverse-linked-list-ii", "url_en": "https://leetcode.com/problems/reverse-linked-list-ii", "relative_path_cn": "/solution/0000-0099/0092.Reverse%20Linked%20List%20II/README.md", "relative_path_en": "/solution/0000-0099/0092.Reverse%20Linked%20List%20II/README_EN.md", "title_cn": "\u53cd\u8f6c\u94fe\u8868 II", "title_en": "Reverse Linked List II", "question_title_slug": "reverse-linked-list-ii", "content_en": "

    Given the head of a singly linked list and two integers left and right where left <= right, reverse the nodes of the list from position left to position right, and return the reversed list.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: head = [1,2,3,4,5], left = 2, right = 4\nOutput: [1,4,3,2,5]\n
    \n\n

    Example 2:

    \n\n
    \nInput: head = [5], left = 1, right = 1\nOutput: [5]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the list is n.
    • \n\t
    • 1 <= n <= 500
    • \n\t
    • -500 <= Node.val <= 500
    • \n\t
    • 1 <= left <= right <= n
    • \n
    \n\n

     

    \nFollow up: Could you do it in one pass?", "content_cn": "\u7ed9\u4f60\u5355\u94fe\u8868\u7684\u5934\u6307\u9488 head \u548c\u4e24\u4e2a\u6574\u6570\u00a0left \u548c right \uff0c\u5176\u4e2d\u00a0left <= right \u3002\u8bf7\u4f60\u53cd\u8f6c\u4ece\u4f4d\u7f6e left \u5230\u4f4d\u7f6e right \u7684\u94fe\u8868\u8282\u70b9\uff0c\u8fd4\u56de \u53cd\u8f6c\u540e\u7684\u94fe\u8868 \u3002\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1ahead = [1,2,3,4,5], left = 2, right = 4\n\u8f93\u51fa\uff1a[1,4,3,2,5]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahead = [5], left = 1, right = 1\n\u8f93\u51fa\uff1a[5]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u94fe\u8868\u4e2d\u8282\u70b9\u6570\u76ee\u4e3a n
    • \n\t
    • 1 <= n <= 500
    • \n\t
    • -500 <= Node.val <= 500
    • \n\t
    • 1 <= left <= right <= n
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a \u4f60\u53ef\u4ee5\u4f7f\u7528\u4e00\u8d9f\u626b\u63cf\u5b8c\u6210\u53cd\u8f6c\u5417\uff1f

    \n", "tags_en": ["Linked List"], "tags_cn": ["\u94fe\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n ListNode* reverseBetween(ListNode* head, int left, int right) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public ListNode reverseBetween(ListNode head, int left, int right) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def reverseBetween(self, head, left, right):\n \"\"\"\n :type head: ListNode\n :type left: int\n :type right: int\n :rtype: ListNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def reverseBetween(self, head: ListNode, left: int, right: int) -> ListNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nstruct ListNode* reverseBetween(struct ListNode* head, int left, int right){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public ListNode ReverseBetween(ListNode head, int left, int right) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} head\n * @param {number} left\n * @param {number} right\n * @return {ListNode}\n */\nvar reverseBetween = function(head, left, right) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode} head\n# @param {Integer} left\n# @param {Integer} right\n# @return {ListNode}\ndef reverse_between(head, left, right)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func reverseBetween(_ head: ListNode?, _ left: Int, _ right: Int) -> ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc reverseBetween(head *ListNode, left int, right int) *ListNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def reverseBetween(head: ListNode, left: Int, right: Int): ListNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun reverseBetween(head: ListNode?, left: Int, right: Int): ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn reverse_between(head: Option>, left: i32, right: i32) -> Option> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @param Integer $left\n * @param Integer $right\n * @return ListNode\n */\n function reverseBetween($head, $left, $right) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction reverseBetween(head: ListNode | null, left: number, right: number): ListNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (reverse-between head left right)\n (-> (or/c list-node? #f) exact-integer? exact-integer? (or/c list-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0092](https://leetcode-cn.com/problems/reverse-linked-list-ii)", "[\u53cd\u8f6c\u94fe\u8868 II](/solution/0000-0099/0092.Reverse%20Linked%20List%20II/README.md)", "`\u94fe\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0092](https://leetcode.com/problems/reverse-linked-list-ii)", "[Reverse Linked List II](/solution/0000-0099/0092.Reverse%20Linked%20List%20II/README_EN.md)", "`Linked List`", "Medium", ""]}, {"question_id": "0091", "frontend_question_id": "0091", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/decode-ways", "url_en": "https://leetcode.com/problems/decode-ways", "relative_path_cn": "/solution/0000-0099/0091.Decode%20Ways/README.md", "relative_path_en": "/solution/0000-0099/0091.Decode%20Ways/README_EN.md", "title_cn": "\u89e3\u7801\u65b9\u6cd5", "title_en": "Decode Ways", "question_title_slug": "decode-ways", "content_en": "

    A message containing letters from A-Z can be encoded into numbers using the following mapping:

    \n\n
    \n'A' -> "1"\n'B' -> "2"\n...\n'Z' -> "26"\n
    \n\n

    To decode an encoded message, all the digits must be grouped then mapped back into letters using the reverse of the mapping above (there may be multiple ways). For example, "11106" can be mapped into:

    \n\n
      \n\t
    • "AAJF" with the grouping (1 1 10 6)
    • \n\t
    • "KJF" with the grouping (11 10 6)
    • \n
    \n\n

    Note that the grouping (1 11 06) is invalid because "06" cannot be mapped into 'F' since "6" is different from "06".

    \n\n

    Given a string s containing only digits, return the number of ways to decode it.

    \n\n

    The answer is guaranteed to fit in a 32-bit integer.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "12"\nOutput: 2\nExplanation: "12" could be decoded as "AB" (1 2) or "L" (12).\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "226"\nOutput: 3\nExplanation: "226" could be decoded as "BZ" (2 26), "VF" (22 6), or "BBF" (2 2 6).\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "0"\nOutput: 0\nExplanation: There is no character that is mapped to a number starting with 0.\nThe only valid mappings with 0 are 'J' -> "10" and 'T' -> "20", neither of which start with 0.\nHence, there are no valid ways to decode this since all digits need to be mapped.\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "06"\nOutput: 0\nExplanation: "06" cannot be mapped to "F" because of the leading zero ("6" is different from "06").\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 100
    • \n\t
    • s contains only digits and may contain leading zero(s).
    • \n
    \n", "content_cn": "

    \u4e00\u6761\u5305\u542b\u5b57\u6bcd\u00a0A-Z \u7684\u6d88\u606f\u901a\u8fc7\u4ee5\u4e0b\u6620\u5c04\u8fdb\u884c\u4e86 \u7f16\u7801 \uff1a

    \n\n
    \n'A' -> 1\n'B' -> 2\n...\n'Z' -> 26\n
    \n\n

    \u8981 \u89e3\u7801 \u5df2\u7f16\u7801\u7684\u6d88\u606f\uff0c\u6240\u6709\u6570\u5b57\u5fc5\u987b\u57fa\u4e8e\u4e0a\u8ff0\u6620\u5c04\u7684\u65b9\u6cd5\uff0c\u53cd\u5411\u6620\u5c04\u56de\u5b57\u6bcd\uff08\u53ef\u80fd\u6709\u591a\u79cd\u65b9\u6cd5\uff09\u3002\u4f8b\u5982\uff0c\"11106\" \u53ef\u4ee5\u6620\u5c04\u4e3a\uff1a

    \n\n
      \n\t
    • \"AAJF\" \uff0c\u5c06\u6d88\u606f\u5206\u7ec4\u4e3a (1 1 10 6)
    • \n\t
    • \"KJF\" \uff0c\u5c06\u6d88\u606f\u5206\u7ec4\u4e3a (11 10 6)
    • \n
    \n\n

    \u6ce8\u610f\uff0c\u6d88\u606f\u4e0d\u80fd\u5206\u7ec4\u4e3a\u00a0 (1 11 06) \uff0c\u56e0\u4e3a \"06\" \u4e0d\u80fd\u6620\u5c04\u4e3a \"F\" \uff0c\u8fd9\u662f\u7531\u4e8e \"6\" \u548c \"06\" \u5728\u6620\u5c04\u4e2d\u5e76\u4e0d\u7b49\u4ef7\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u53ea\u542b\u6570\u5b57\u7684 \u975e\u7a7a \u5b57\u7b26\u4e32 s \uff0c\u8bf7\u8ba1\u7b97\u5e76\u8fd4\u56de \u89e3\u7801 \u65b9\u6cd5\u7684 \u603b\u6570 \u3002

    \n\n

    \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u7b54\u6848\u80af\u5b9a\u662f\u4e00\u4e2a 32 \u4f4d \u7684\u6574\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"12\"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5b83\u53ef\u4ee5\u89e3\u7801\u4e3a \"AB\"\uff081 2\uff09\u6216\u8005 \"L\"\uff0812\uff09\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"226\"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u5b83\u53ef\u4ee5\u89e3\u7801\u4e3a \"BZ\" (2 26), \"VF\" (22 6), \u6216\u8005 \"BBF\" (2 2 6) \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"0\"\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6ca1\u6709\u5b57\u7b26\u6620\u5c04\u5230\u4ee5 0 \u5f00\u5934\u7684\u6570\u5b57\u3002\n\u542b\u6709 0 \u7684\u6709\u6548\u6620\u5c04\u662f 'J' -> \"10\" \u548c 'T'-> \"20\" \u3002\n\u7531\u4e8e\u6ca1\u6709\u5b57\u7b26\uff0c\u56e0\u6b64\u6ca1\u6709\u6709\u6548\u7684\u65b9\u6cd5\u5bf9\u6b64\u8fdb\u884c\u89e3\u7801\uff0c\u56e0\u4e3a\u6240\u6709\u6570\u5b57\u90fd\u9700\u8981\u6620\u5c04\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"06\"\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\"06\" \u4e0d\u80fd\u6620\u5c04\u5230 \"F\" \uff0c\u56e0\u4e3a\u5b57\u7b26\u4e32\u542b\u6709\u524d\u5bfc 0\uff08\"6\" \u548c \"06\" \u5728\u6620\u5c04\u4e2d\u5e76\u4e0d\u7b49\u4ef7\uff09\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 100
    • \n\t
    • s \u53ea\u5305\u542b\u6570\u5b57\uff0c\u5e76\u4e14\u53ef\u80fd\u5305\u542b\u524d\u5bfc\u96f6\u3002
    • \n
    \n", "tags_en": ["String", "Dynamic Programming"], "tags_cn": ["\u5b57\u7b26\u4e32", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numDecodings(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numDecodings(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numDecodings(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numDecodings(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numDecodings(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumDecodings(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar numDecodings = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef num_decodings(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numDecodings(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numDecodings(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numDecodings(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numDecodings(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_decodings(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function numDecodings($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numDecodings(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-decodings s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0091](https://leetcode-cn.com/problems/decode-ways)", "[\u89e3\u7801\u65b9\u6cd5](/solution/0000-0099/0091.Decode%20Ways/README.md)", "`\u5b57\u7b26\u4e32`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0091](https://leetcode.com/problems/decode-ways)", "[Decode Ways](/solution/0000-0099/0091.Decode%20Ways/README_EN.md)", "`String`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0090", "frontend_question_id": "0090", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/subsets-ii", "url_en": "https://leetcode.com/problems/subsets-ii", "relative_path_cn": "/solution/0000-0099/0090.Subsets%20II/README.md", "relative_path_en": "/solution/0000-0099/0090.Subsets%20II/README_EN.md", "title_cn": "\u5b50\u96c6 II", "title_en": "Subsets II", "question_title_slug": "subsets-ii", "content_en": "

    Given an integer array nums that may contain duplicates, return all possible subsets (the power set).

    \n\n

    The solution set must not contain duplicate subsets. Return the solution in any order.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [1,2,2]\nOutput: [[],[1],[1,2],[1,2,2],[2],[2,2]]\n

    Example 2:

    \n
    Input: nums = [0]\nOutput: [[],[0]]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 10
    • \n\t
    • -10 <= nums[i] <= 10
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \uff0c\u5176\u4e2d\u53ef\u80fd\u5305\u542b\u91cd\u590d\u5143\u7d20\uff0c\u8bf7\u4f60\u8fd4\u56de\u8be5\u6570\u7ec4\u6240\u6709\u53ef\u80fd\u7684\u5b50\u96c6\uff08\u5e42\u96c6\uff09\u3002

    \n\n

    \u89e3\u96c6 \u4e0d\u80fd \u5305\u542b\u91cd\u590d\u7684\u5b50\u96c6\u3002\u8fd4\u56de\u7684\u89e3\u96c6\u4e2d\uff0c\u5b50\u96c6\u53ef\u4ee5\u6309 \u4efb\u610f\u987a\u5e8f \u6392\u5217\u3002

    \n\n
    \n
    \n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,2]\n\u8f93\u51fa\uff1a[[],[1],[1,2],[1,2,2],[2],[2,2]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [0]\n\u8f93\u51fa\uff1a[[],[0]]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 10
    • \n\t
    • -10 <= nums[i] <= 10
    • \n
    \n
    \n
    \n", "tags_en": ["Array", "Backtracking"], "tags_cn": ["\u6570\u7ec4", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> subsetsWithDup(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> subsetsWithDup(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def subsetsWithDup(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def subsetsWithDup(self, nums: List[int]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** subsetsWithDup(int* nums, int numsSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> SubsetsWithDup(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number[][]}\n */\nvar subsetsWithDup = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer[][]}\ndef subsets_with_dup(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func subsetsWithDup(_ nums: [Int]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func subsetsWithDup(nums []int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def subsetsWithDup(nums: Array[Int]): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun subsetsWithDup(nums: IntArray): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn subsets_with_dup(nums: Vec) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer[][]\n */\n function subsetsWithDup($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function subsetsWithDup(nums: number[]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (subsets-with-dup nums)\n (-> (listof exact-integer?) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0090](https://leetcode-cn.com/problems/subsets-ii)", "[\u5b50\u96c6 II](/solution/0000-0099/0090.Subsets%20II/README.md)", "`\u6570\u7ec4`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0090](https://leetcode.com/problems/subsets-ii)", "[Subsets II](/solution/0000-0099/0090.Subsets%20II/README_EN.md)", "`Array`,`Backtracking`", "Medium", ""]}, {"question_id": "0089", "frontend_question_id": "0089", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/gray-code", "url_en": "https://leetcode.com/problems/gray-code", "relative_path_cn": "/solution/0000-0099/0089.Gray%20Code/README.md", "relative_path_en": "/solution/0000-0099/0089.Gray%20Code/README_EN.md", "title_cn": "\u683c\u96f7\u7f16\u7801", "title_en": "Gray Code", "question_title_slug": "gray-code", "content_en": "

    An n-bit gray code sequence is a sequence of 2n integers where:

    \n\n
      \n\t
    • Every integer is in the inclusive range [0, 2n - 1],
    • \n\t
    • The first integer is 0,
    • \n\t
    • An integer appears no more than once in the sequence,
    • \n\t
    • The binary representation of every pair of adjacent integers differs by exactly one bit, and
    • \n\t
    • The binary representation of the first and last integers differs by exactly one bit.
    • \n
    \n\n

    Given an integer n, return any valid n-bit gray code sequence.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 2\nOutput: [0,1,3,2]\nExplanation:\nThe binary representation of [0,1,3,2] is [00,01,11,10].\n- 00 and 01 differ by one bit\n- 01 and 11 differ by one bit\n- 11 and 10 differ by one bit\n- 10 and 00 differ by one bit\n[0,2,3,1] is also a valid gray code sequence, whose binary representation is [00,10,11,01].\n- 00 and 10 differ by one bit\n- 10 and 11 differ by one bit\n- 11 and 01 differ by one bit\n- 01 and 00 differ by one bit\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 1\nOutput: [0,1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 16
    • \n
    \n", "content_cn": "

    \u683c\u96f7\u7f16\u7801\u662f\u4e00\u4e2a\u4e8c\u8fdb\u5236\u6570\u5b57\u7cfb\u7edf\uff0c\u5728\u8be5\u7cfb\u7edf\u4e2d\uff0c\u4e24\u4e2a\u8fde\u7eed\u7684\u6570\u503c\u4ec5\u6709\u4e00\u4e2a\u4f4d\u6570\u7684\u5dee\u5f02\u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u4ee3\u8868\u7f16\u7801\u603b\u4f4d\u6570\u7684\u975e\u8d1f\u6574\u6570 n\uff0c\u6253\u5370\u5176\u683c\u96f7\u7f16\u7801\u5e8f\u5217\u3002\u5373\u4f7f\u6709\u591a\u4e2a\u4e0d\u540c\u7b54\u6848\uff0c\u4f60\u4e5f\u53ea\u9700\u8981\u8fd4\u56de\u5176\u4e2d\u4e00\u79cd\u3002

    \n\n

    \u683c\u96f7\u7f16\u7801\u5e8f\u5217\u5fc5\u987b\u4ee5 0 \u5f00\u5934\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: 2\n\u8f93\u51fa: [0,1,3,2]\n\u89e3\u91ca:\n00 - 0\n01 - 1\n11 - 3\n10 - 2\n\n\u5bf9\u4e8e\u7ed9\u5b9a\u7684 n\uff0c\u5176\u683c\u96f7\u7f16\u7801\u5e8f\u5217\u5e76\u4e0d\u552f\u4e00\u3002\n\u4f8b\u5982\uff0c[0,2,3,1] \u4e5f\u662f\u4e00\u4e2a\u6709\u6548\u7684\u683c\u96f7\u7f16\u7801\u5e8f\u5217\u3002\n\n00 - 0\n10 - 2\n11 - 3\n01 - 1
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: 0\n\u8f93\u51fa: [0]\n\u89e3\u91ca: \u6211\u4eec\u5b9a\u4e49\u683c\u96f7\u7f16\u7801\u5e8f\u5217\u5fc5\u987b\u4ee5 0 \u5f00\u5934\u3002\n     \u7ed9\u5b9a\u7f16\u7801\u603b\u4f4d\u6570\u4e3a n \u7684\u683c\u96f7\u7f16\u7801\u5e8f\u5217\uff0c\u5176\u957f\u5ea6\u4e3a 2n\u3002\u5f53 n = 0 \u65f6\uff0c\u957f\u5ea6\u4e3a 20 = 1\u3002\n     \u56e0\u6b64\uff0c\u5f53 n = 0 \u65f6\uff0c\u5176\u683c\u96f7\u7f16\u7801\u5e8f\u5217\u4e3a [0]\u3002\n
    \n", "tags_en": ["Backtracking"], "tags_cn": ["\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector grayCode(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List grayCode(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def grayCode(self, n):\n \"\"\"\n :type n: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def grayCode(self, n: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* grayCode(int n, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList GrayCode(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number[]}\n */\nvar grayCode = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer[]}\ndef gray_code(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func grayCode(_ n: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func grayCode(n int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def grayCode(n: Int): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun grayCode(n: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn gray_code(n: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer[]\n */\n function grayCode($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function grayCode(n: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (gray-code n)\n (-> exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0089](https://leetcode-cn.com/problems/gray-code)", "[\u683c\u96f7\u7f16\u7801](/solution/0000-0099/0089.Gray%20Code/README.md)", "`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0089](https://leetcode.com/problems/gray-code)", "[Gray Code](/solution/0000-0099/0089.Gray%20Code/README_EN.md)", "`Backtracking`", "Medium", ""]}, {"question_id": "0088", "frontend_question_id": "0088", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/merge-sorted-array", "url_en": "https://leetcode.com/problems/merge-sorted-array", "relative_path_cn": "/solution/0000-0099/0088.Merge%20Sorted%20Array/README.md", "relative_path_en": "/solution/0000-0099/0088.Merge%20Sorted%20Array/README_EN.md", "title_cn": "\u5408\u5e76\u4e24\u4e2a\u6709\u5e8f\u6570\u7ec4", "title_en": "Merge Sorted Array", "question_title_slug": "merge-sorted-array", "content_en": "

    You are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in nums1 and nums2 respectively.

    \n\n

    Merge nums1 and nums2 into a single array sorted in non-decreasing order.

    \n\n

    The final sorted array should not be returned by the function, but instead be stored inside the array nums1. To accommodate this, nums1 has a length of m + n, where the first m elements denote the elements that should be merged, and the last n elements are set to 0 and should be ignored. nums2 has a length of n.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums1 = [1,2,3,0,0,0], m = 3, nums2 = [2,5,6], n = 3\nOutput: [1,2,2,3,5,6]\nExplanation: The arrays we are merging are [1,2,3] and [2,5,6].\nThe result of the merge is [1,2,2,3,5,6] with the underlined elements coming from nums1.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums1 = [1], m = 1, nums2 = [], n = 0\nOutput: [1]\nExplanation: The arrays we are merging are [1] and [].\nThe result of the merge is [1].\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums1 = [0], m = 0, nums2 = [1], n = 1\nOutput: [1]\nExplanation: The arrays we are merging are [] and [1].\nThe result of the merge is [1].\nNote that because m = 0, there are no elements in nums1. The 0 is only there to ensure the merge result can fit in nums1.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • nums1.length == m + n
    • \n\t
    • nums2.length == n
    • \n\t
    • 0 <= m, n <= 200
    • \n\t
    • 1 <= m + n <= 200
    • \n\t
    • -109 <= nums1[i], nums2[j] <= 109
    • \n
    \n\n

     

    \n

    Follow up: Can you come up with an algorithm that runs in O(m + n) time?

    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u6709\u5e8f\u6574\u6570\u6570\u7ec4\u00a0nums1 \u548c nums2\uff0c\u8bf7\u4f60\u5c06 nums2 \u5408\u5e76\u5230\u00a0nums1\u00a0\u4e2d\uff0c\u4f7f nums1 \u6210\u4e3a\u4e00\u4e2a\u6709\u5e8f\u6570\u7ec4\u3002

    \n\n

    \u521d\u59cb\u5316\u00a0nums1 \u548c nums2 \u7684\u5143\u7d20\u6570\u91cf\u5206\u522b\u4e3a\u00a0m \u548c n \u3002\u4f60\u53ef\u4ee5\u5047\u8bbe\u00a0nums1 \u7684\u7a7a\u95f4\u5927\u5c0f\u7b49\u4e8e\u00a0m + n\uff0c\u8fd9\u6837\u5b83\u5c31\u6709\u8db3\u591f\u7684\u7a7a\u95f4\u4fdd\u5b58\u6765\u81ea nums2 \u7684\u5143\u7d20\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums1 = [1,2,3,0,0,0], m = 3, nums2 = [2,5,6], n = 3\n\u8f93\u51fa\uff1a[1,2,2,3,5,6]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums1 = [1], m = 1, nums2 = [], n = 0\n\u8f93\u51fa\uff1a[1]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • nums1.length == m + n
    • \n\t
    • nums2.length == n
    • \n\t
    • 0 <= m, n <= 200
    • \n\t
    • 1 <= m + n <= 200
    • \n\t
    • -109 <= nums1[i], nums2[i] <= 109
    • \n
    \n", "tags_en": ["Array", "Two Pointers"], "tags_cn": ["\u6570\u7ec4", "\u53cc\u6307\u9488"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n void merge(vector& nums1, int m, vector& nums2, int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public void merge(int[] nums1, int m, int[] nums2, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def merge(self, nums1, m, nums2, n):\n \"\"\"\n :type nums1: List[int]\n :type m: int\n :type nums2: List[int]\n :type n: int\n :rtype: None Do not return anything, modify nums1 in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def merge(self, nums1: List[int], m: int, nums2: List[int], n: int) -> None:\n \"\"\"\n Do not return anything, modify nums1 in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nvoid merge(int* nums1, int nums1Size, int m, int* nums2, int nums2Size, int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public void Merge(int[] nums1, int m, int[] nums2, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums1\n * @param {number} m\n * @param {number[]} nums2\n * @param {number} n\n * @return {void} Do not return anything, modify nums1 in-place instead.\n */\nvar merge = function(nums1, m, nums2, n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums1\n# @param {Integer} m\n# @param {Integer[]} nums2\n# @param {Integer} n\n# @return {Void} Do not return anything, modify nums1 in-place instead.\ndef merge(nums1, m, nums2, n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func merge(_ nums1: inout [Int], _ m: Int, _ nums2: [Int], _ n: Int) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func merge(nums1 []int, m int, nums2 []int, n int) {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def merge(nums1: Array[Int], m: Int, nums2: Array[Int], n: Int): Unit = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun merge(nums1: IntArray, m: Int, nums2: IntArray, n: Int): Unit {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn merge(nums1: &mut Vec, m: i32, nums2: &mut Vec, n: i32) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums1\n * @param Integer $m\n * @param Integer[] $nums2\n * @param Integer $n\n * @return NULL\n */\n function merge(&$nums1, $m, $nums2, $n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n Do not return anything, modify nums1 in-place instead.\n */\nfunction merge(nums1: number[], m: number, nums2: number[], n: number): void {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0088](https://leetcode-cn.com/problems/merge-sorted-array)", "[\u5408\u5e76\u4e24\u4e2a\u6709\u5e8f\u6570\u7ec4](/solution/0000-0099/0088.Merge%20Sorted%20Array/README.md)", "`\u6570\u7ec4`,`\u53cc\u6307\u9488`", "\u7b80\u5355", ""], "md_table_row_en": ["[0088](https://leetcode.com/problems/merge-sorted-array)", "[Merge Sorted Array](/solution/0000-0099/0088.Merge%20Sorted%20Array/README_EN.md)", "`Array`,`Two Pointers`", "Easy", ""]}, {"question_id": "0087", "frontend_question_id": "0087", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/scramble-string", "url_en": "https://leetcode.com/problems/scramble-string", "relative_path_cn": "/solution/0000-0099/0087.Scramble%20String/README.md", "relative_path_en": "/solution/0000-0099/0087.Scramble%20String/README_EN.md", "title_cn": "\u6270\u4e71\u5b57\u7b26\u4e32", "title_en": "Scramble String", "question_title_slug": "scramble-string", "content_en": "

    We can scramble a string s to get a string t using the following algorithm:

    \n\n
      \n\t
    1. If the length of the string is 1, stop.
    2. \n\t
    3. If the length of the string is > 1, do the following:\n\t
        \n\t\t
      • Split the string into two non-empty substrings at a random index, i.e., if the string is s, divide it to x and y where s = x + y.
      • \n\t\t
      • Randomly decide to swap the two substrings or to keep them in the same order. i.e., after this step, s may become s = x + y or s = y + x.
      • \n\t\t
      • Apply step 1 recursively on each of the two substrings x and y.
      • \n\t
      \n\t
    4. \n
    \n\n

    Given two strings s1 and s2 of the same length, return true if s2 is a scrambled string of s1, otherwise, return false.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s1 = "great", s2 = "rgeat"\nOutput: true\nExplanation: One possible scenario applied on s1 is:\n"great" --> "gr/eat" // divide at random index.\n"gr/eat" --> "gr/eat" // random decision is not to swap the two substrings and keep them in order.\n"gr/eat" --> "g/r / e/at" // apply the same algorithm recursively on both substrings. divide at ranom index each of them.\n"g/r / e/at" --> "r/g / e/at" // random decision was to swap the first substring and to keep the second substring in the same order.\n"r/g / e/at" --> "r/g / e/ a/t" // again apply the algorithm recursively, divide "at" to "a/t".\n"r/g / e/ a/t" --> "r/g / e/ a/t" // random decision is to keep both substrings in the same order.\nThe algorithm stops now and the result string is "rgeat" which is s2.\nAs there is one possible scenario that led s1 to be scrambled to s2, we return true.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s1 = "abcde", s2 = "caebd"\nOutput: false\n
    \n\n

    Example 3:

    \n\n
    \nInput: s1 = "a", s2 = "a"\nOutput: true\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • s1.length == s2.length
    • \n\t
    • 1 <= s1.length <= 30
    • \n\t
    • s1 and s2 consist of lower-case English letters.
    • \n
    \n", "content_cn": "\u4f7f\u7528\u4e0b\u9762\u63cf\u8ff0\u7684\u7b97\u6cd5\u53ef\u4ee5\u6270\u4e71\u5b57\u7b26\u4e32 s \u5f97\u5230\u5b57\u7b26\u4e32 t \uff1a\n
      \n\t
    1. \u5982\u679c\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u4e3a 1 \uff0c\u7b97\u6cd5\u505c\u6b62
    2. \n\t
    3. \u5982\u679c\u5b57\u7b26\u4e32\u7684\u957f\u5ea6 > 1 \uff0c\u6267\u884c\u4e0b\u8ff0\u6b65\u9aa4\uff1a\n\t
        \n\t\t
      • \u5728\u4e00\u4e2a\u968f\u673a\u4e0b\u6807\u5904\u5c06\u5b57\u7b26\u4e32\u5206\u5272\u6210\u4e24\u4e2a\u975e\u7a7a\u7684\u5b50\u5b57\u7b26\u4e32\u3002\u5373\uff0c\u5982\u679c\u5df2\u77e5\u5b57\u7b26\u4e32 s \uff0c\u5219\u53ef\u4ee5\u5c06\u5176\u5206\u6210\u4e24\u4e2a\u5b50\u5b57\u7b26\u4e32 x \u548c y \uff0c\u4e14\u6ee1\u8db3 s = x + y \u3002
      • \n\t\t
      • \u968f\u673a \u51b3\u5b9a\u662f\u8981\u300c\u4ea4\u6362\u4e24\u4e2a\u5b50\u5b57\u7b26\u4e32\u300d\u8fd8\u662f\u8981\u300c\u4fdd\u6301\u8fd9\u4e24\u4e2a\u5b50\u5b57\u7b26\u4e32\u7684\u987a\u5e8f\u4e0d\u53d8\u300d\u3002\u5373\uff0c\u5728\u6267\u884c\u8fd9\u4e00\u6b65\u9aa4\u4e4b\u540e\uff0cs \u53ef\u80fd\u662f s = x + y \u6216\u8005 s = y + x \u3002
      • \n\t\t
      • \u5728 x \u548c y \u8fd9\u4e24\u4e2a\u5b50\u5b57\u7b26\u4e32\u4e0a\u7ee7\u7eed\u4ece\u6b65\u9aa4 1 \u5f00\u59cb\u9012\u5f52\u6267\u884c\u6b64\u7b97\u6cd5\u3002
      • \n\t
      \n\t
    4. \n
    \n\n

    \u7ed9\u4f60\u4e24\u4e2a \u957f\u5ea6\u76f8\u7b49 \u7684\u5b57\u7b26\u4e32 s1 \u548c\u00a0s2\uff0c\u5224\u65ad\u00a0s2\u00a0\u662f\u5426\u662f\u00a0s1\u00a0\u7684\u6270\u4e71\u5b57\u7b26\u4e32\u3002\u5982\u679c\u662f\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as1 = \"great\", s2 = \"rgeat\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1as1 \u4e0a\u53ef\u80fd\u53d1\u751f\u7684\u4e00\u79cd\u60c5\u5f62\u662f\uff1a\n\"great\" --> \"gr/eat\" // \u5728\u4e00\u4e2a\u968f\u673a\u4e0b\u6807\u5904\u5206\u5272\u5f97\u5230\u4e24\u4e2a\u5b50\u5b57\u7b26\u4e32\n\"gr/eat\" --> \"gr/eat\" // \u968f\u673a\u51b3\u5b9a\uff1a\u300c\u4fdd\u6301\u8fd9\u4e24\u4e2a\u5b50\u5b57\u7b26\u4e32\u7684\u987a\u5e8f\u4e0d\u53d8\u300d\n\"gr/eat\" --> \"g/r / e/at\" // \u5728\u5b50\u5b57\u7b26\u4e32\u4e0a\u9012\u5f52\u6267\u884c\u6b64\u7b97\u6cd5\u3002\u4e24\u4e2a\u5b50\u5b57\u7b26\u4e32\u5206\u522b\u5728\u968f\u673a\u4e0b\u6807\u5904\u8fdb\u884c\u4e00\u8f6e\u5206\u5272\n\"g/r / e/at\" --> \"r/g / e/at\" // \u968f\u673a\u51b3\u5b9a\uff1a\u7b2c\u4e00\u7ec4\u300c\u4ea4\u6362\u4e24\u4e2a\u5b50\u5b57\u7b26\u4e32\u300d\uff0c\u7b2c\u4e8c\u7ec4\u300c\u4fdd\u6301\u8fd9\u4e24\u4e2a\u5b50\u5b57\u7b26\u4e32\u7684\u987a\u5e8f\u4e0d\u53d8\u300d\n\"r/g / e/at\" --> \"r/g / e/ a/t\" // \u7ee7\u7eed\u9012\u5f52\u6267\u884c\u6b64\u7b97\u6cd5\uff0c\u5c06 \"at\" \u5206\u5272\u5f97\u5230 \"a/t\"\n\"r/g / e/ a/t\" --> \"r/g / e/ a/t\" // \u968f\u673a\u51b3\u5b9a\uff1a\u300c\u4fdd\u6301\u8fd9\u4e24\u4e2a\u5b50\u5b57\u7b26\u4e32\u7684\u987a\u5e8f\u4e0d\u53d8\u300d\n\u7b97\u6cd5\u7ec8\u6b62\uff0c\u7ed3\u679c\u5b57\u7b26\u4e32\u548c s2 \u76f8\u540c\uff0c\u90fd\u662f \"rgeat\"\n\u8fd9\u662f\u4e00\u79cd\u80fd\u591f\u6270\u4e71 s1 \u5f97\u5230 s2 \u7684\u60c5\u5f62\uff0c\u53ef\u4ee5\u8ba4\u4e3a s2 \u662f s1 \u7684\u6270\u4e71\u5b57\u7b26\u4e32\uff0c\u8fd4\u56de true\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as1 = \"abcde\", s2 = \"caebd\"\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as1 = \"a\", s2 = \"a\"\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • s1.length == s2.length
    • \n\t
    • 1 <= s1.length <= 30
    • \n\t
    • s1 \u548c s2 \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n", "tags_en": ["String", "Dynamic Programming"], "tags_cn": ["\u5b57\u7b26\u4e32", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isScramble(string s1, string s2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isScramble(String s1, String s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isScramble(self, s1, s2):\n \"\"\"\n :type s1: str\n :type s2: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isScramble(self, s1: str, s2: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isScramble(char * s1, char * s2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsScramble(string s1, string s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s1\n * @param {string} s2\n * @return {boolean}\n */\nvar isScramble = function(s1, s2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s1\n# @param {String} s2\n# @return {Boolean}\ndef is_scramble(s1, s2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isScramble(_ s1: String, _ s2: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isScramble(s1 string, s2 string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isScramble(s1: String, s2: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isScramble(s1: String, s2: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_scramble(s1: String, s2: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s1\n * @param String $s2\n * @return Boolean\n */\n function isScramble($s1, $s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isScramble(s1: string, s2: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-scramble s1 s2)\n (-> string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0087](https://leetcode-cn.com/problems/scramble-string)", "[\u6270\u4e71\u5b57\u7b26\u4e32](/solution/0000-0099/0087.Scramble%20String/README.md)", "`\u5b57\u7b26\u4e32`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0087](https://leetcode.com/problems/scramble-string)", "[Scramble String](/solution/0000-0099/0087.Scramble%20String/README_EN.md)", "`String`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0086", "frontend_question_id": "0086", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/partition-list", "url_en": "https://leetcode.com/problems/partition-list", "relative_path_cn": "/solution/0000-0099/0086.Partition%20List/README.md", "relative_path_en": "/solution/0000-0099/0086.Partition%20List/README_EN.md", "title_cn": "\u5206\u9694\u94fe\u8868", "title_en": "Partition List", "question_title_slug": "partition-list", "content_en": "

    Given the head of a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.

    \n\n

    You should preserve the original relative order of the nodes in each of the two partitions.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: head = [1,4,3,2,5,2], x = 3\nOutput: [1,2,2,4,3,5]\n
    \n\n

    Example 2:

    \n\n
    \nInput: head = [2,1], x = 2\nOutput: [1,2]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the list is in the range [0, 200].
    • \n\t
    • -100 <= Node.val <= 100
    • \n\t
    • -200 <= x <= 200
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u94fe\u8868\u7684\u5934\u8282\u70b9 head \u548c\u4e00\u4e2a\u7279\u5b9a\u503c x \uff0c\u8bf7\u4f60\u5bf9\u94fe\u8868\u8fdb\u884c\u5206\u9694\uff0c\u4f7f\u5f97\u6240\u6709 \u5c0f\u4e8e x \u7684\u8282\u70b9\u90fd\u51fa\u73b0\u5728 \u5927\u4e8e\u6216\u7b49\u4e8e x \u7684\u8282\u70b9\u4e4b\u524d\u3002

    \n\n

    \u4f60\u5e94\u5f53 \u4fdd\u7559 \u4e24\u4e2a\u5206\u533a\u4e2d\u6bcf\u4e2a\u8282\u70b9\u7684\u521d\u59cb\u76f8\u5bf9\u4f4d\u7f6e\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1ahead = [1,4,3,2,5,2], x = 3\n\u8f93\u51fa\uff1a[1,2,2,4,3,5]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahead = [2,1], x = 2\n\u8f93\u51fa\uff1a[1,2]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u94fe\u8868\u4e2d\u8282\u70b9\u7684\u6570\u76ee\u5728\u8303\u56f4 [0, 200] \u5185
    • \n\t
    • -100 <= Node.val <= 100
    • \n\t
    • -200 <= x <= 200
    • \n
    \n", "tags_en": ["Linked List", "Two Pointers"], "tags_cn": ["\u94fe\u8868", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n ListNode* partition(ListNode* head, int x) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public ListNode partition(ListNode head, int x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def partition(self, head, x):\n \"\"\"\n :type head: ListNode\n :type x: int\n :rtype: ListNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def partition(self, head: ListNode, x: int) -> ListNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nstruct ListNode* partition(struct ListNode* head, int x){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public ListNode Partition(ListNode head, int x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} head\n * @param {number} x\n * @return {ListNode}\n */\nvar partition = function(head, x) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode} head\n# @param {Integer} x\n# @return {ListNode}\ndef partition(head, x)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func partition(_ head: ListNode?, _ x: Int) -> ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc partition(head *ListNode, x int) *ListNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def partition(head: ListNode, x: Int): ListNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun partition(head: ListNode?, x: Int): ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn partition(head: Option>, x: i32) -> Option> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @param Integer $x\n * @return ListNode\n */\n function partition($head, $x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction partition(head: ListNode | null, x: number): ListNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (partition head x)\n (-> (or/c list-node? #f) exact-integer? (or/c list-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0086](https://leetcode-cn.com/problems/partition-list)", "[\u5206\u9694\u94fe\u8868](/solution/0000-0099/0086.Partition%20List/README.md)", "`\u94fe\u8868`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0086](https://leetcode.com/problems/partition-list)", "[Partition List](/solution/0000-0099/0086.Partition%20List/README_EN.md)", "`Linked List`,`Two Pointers`", "Medium", ""]}, {"question_id": "0085", "frontend_question_id": "0085", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximal-rectangle", "url_en": "https://leetcode.com/problems/maximal-rectangle", "relative_path_cn": "/solution/0000-0099/0085.Maximal%20Rectangle/README.md", "relative_path_en": "/solution/0000-0099/0085.Maximal%20Rectangle/README_EN.md", "title_cn": "\u6700\u5927\u77e9\u5f62", "title_en": "Maximal Rectangle", "question_title_slug": "maximal-rectangle", "content_en": "

    Given a rows x cols binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: matrix = [["1","0","1","0","0"],["1","0","1","1","1"],["1","1","1","1","1"],["1","0","0","1","0"]]\nOutput: 6\nExplanation: The maximal rectangle is shown in the above picture.\n
    \n\n

    Example 2:

    \n\n
    \nInput: matrix = []\nOutput: 0\n
    \n\n

    Example 3:

    \n\n
    \nInput: matrix = [["0"]]\nOutput: 0\n
    \n\n

    Example 4:

    \n\n
    \nInput: matrix = [["1"]]\nOutput: 1\n
    \n\n

    Example 5:

    \n\n
    \nInput: matrix = [["0","0"]]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • rows == matrix.length
    • \n\t
    • cols == matrix[i].length
    • \n\t
    • 0 <= row, cols <= 200
    • \n\t
    • matrix[i][j] is '0' or '1'.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4ec5\u5305\u542b\u00a00 \u548c 1 \u3001\u5927\u5c0f\u4e3a rows x cols \u7684\u4e8c\u7ef4\u4e8c\u8fdb\u5236\u77e9\u9635\uff0c\u627e\u51fa\u53ea\u5305\u542b 1 \u7684\u6700\u5927\u77e9\u5f62\uff0c\u5e76\u8fd4\u56de\u5176\u9762\u79ef\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1amatrix = [[\"1\",\"0\",\"1\",\"0\",\"0\"],[\"1\",\"0\",\"1\",\"1\",\"1\"],[\"1\",\"1\",\"1\",\"1\",\"1\"],[\"1\",\"0\",\"0\",\"1\",\"0\"]]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u6700\u5927\u77e9\u5f62\u5982\u4e0a\u56fe\u6240\u793a\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1amatrix = []\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1amatrix = [[\"0\"]]\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1amatrix = [[\"1\"]]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1amatrix = [[\"0\",\"0\"]]\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • rows == matrix.length
    • \n\t
    • cols == matrix[0].length
    • \n\t
    • 0 <= row, cols <= 200
    • \n\t
    • matrix[i][j] \u4e3a '0' \u6216 '1'
    • \n
    \n", "tags_en": ["Stack", "Array", "Hash Table", "Dynamic Programming"], "tags_cn": ["\u6808", "\u6570\u7ec4", "\u54c8\u5e0c\u8868", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maximalRectangle(vector>& matrix) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maximalRectangle(char[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximalRectangle(self, matrix):\n \"\"\"\n :type matrix: List[List[str]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximalRectangle(self, matrix: List[List[str]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maximalRectangle(char** matrix, int matrixSize, int* matrixColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaximalRectangle(char[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {character[][]} matrix\n * @return {number}\n */\nvar maximalRectangle = function(matrix) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Character[][]} matrix\n# @return {Integer}\ndef maximal_rectangle(matrix)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximalRectangle(_ matrix: [[Character]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximalRectangle(matrix [][]byte) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximalRectangle(matrix: Array[Array[Char]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximalRectangle(matrix: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximal_rectangle(matrix: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $matrix\n * @return Integer\n */\n function maximalRectangle($matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximalRectangle(matrix: string[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximal-rectangle matrix)\n (-> (listof (listof char?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0085](https://leetcode-cn.com/problems/maximal-rectangle)", "[\u6700\u5927\u77e9\u5f62](/solution/0000-0099/0085.Maximal%20Rectangle/README.md)", "`\u6808`,`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0085](https://leetcode.com/problems/maximal-rectangle)", "[Maximal Rectangle](/solution/0000-0099/0085.Maximal%20Rectangle/README_EN.md)", "`Stack`,`Array`,`Hash Table`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0084", "frontend_question_id": "0084", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/largest-rectangle-in-histogram", "url_en": "https://leetcode.com/problems/largest-rectangle-in-histogram", "relative_path_cn": "/solution/0000-0099/0084.Largest%20Rectangle%20in%20Histogram/README.md", "relative_path_en": "/solution/0000-0099/0084.Largest%20Rectangle%20in%20Histogram/README_EN.md", "title_cn": "\u67f1\u72b6\u56fe\u4e2d\u6700\u5927\u7684\u77e9\u5f62", "title_en": "Largest Rectangle in Histogram", "question_title_slug": "largest-rectangle-in-histogram", "content_en": "

    Given an array of integers heights representing the histogram's bar height where the width of each bar is 1, return the area of the largest rectangle in the histogram.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: heights = [2,1,5,6,2,3]\nOutput: 10\nExplanation: The above is a histogram where width of each bar is 1.\nThe largest rectangle is shown in the red area, which has an area = 10 units.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: heights = [2,4]\nOutput: 4\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= heights.length <= 105
    • \n\t
    • 0 <= heights[i] <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a n \u4e2a\u975e\u8d1f\u6574\u6570\uff0c\u7528\u6765\u8868\u793a\u67f1\u72b6\u56fe\u4e2d\u5404\u4e2a\u67f1\u5b50\u7684\u9ad8\u5ea6\u3002\u6bcf\u4e2a\u67f1\u5b50\u5f7c\u6b64\u76f8\u90bb\uff0c\u4e14\u5bbd\u5ea6\u4e3a 1 \u3002

    \n\n

    \u6c42\u5728\u8be5\u67f1\u72b6\u56fe\u4e2d\uff0c\u80fd\u591f\u52fe\u52d2\u51fa\u6765\u7684\u77e9\u5f62\u7684\u6700\u5927\u9762\u79ef\u3002

    \n\n

     

    \n\n

    \n\n

    \u4ee5\u4e0a\u662f\u67f1\u72b6\u56fe\u7684\u793a\u4f8b\uff0c\u5176\u4e2d\u6bcf\u4e2a\u67f1\u5b50\u7684\u5bbd\u5ea6\u4e3a 1\uff0c\u7ed9\u5b9a\u7684\u9ad8\u5ea6\u4e3a [2,1,5,6,2,3]\u3002

    \n\n

     

    \n\n

    \n\n

    \u56fe\u4e2d\u9634\u5f71\u90e8\u5206\u4e3a\u6240\u80fd\u52fe\u52d2\u51fa\u7684\u6700\u5927\u77e9\u5f62\u9762\u79ef\uff0c\u5176\u9762\u79ef\u4e3a 10 \u4e2a\u5355\u4f4d\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: [2,1,5,6,2,3]\n\u8f93\u51fa: 10
    \n", "tags_en": ["Stack", "Array"], "tags_cn": ["\u6808", "\u6570\u7ec4"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int largestRectangleArea(vector& heights) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int largestRectangleArea(int[] heights) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def largestRectangleArea(self, heights):\n \"\"\"\n :type heights: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def largestRectangleArea(self, heights: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint largestRectangleArea(int* heights, int heightsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LargestRectangleArea(int[] heights) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} heights\n * @return {number}\n */\nvar largestRectangleArea = function(heights) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} heights\n# @return {Integer}\ndef largest_rectangle_area(heights)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func largestRectangleArea(_ heights: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func largestRectangleArea(heights []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def largestRectangleArea(heights: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun largestRectangleArea(heights: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn largest_rectangle_area(heights: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $heights\n * @return Integer\n */\n function largestRectangleArea($heights) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function largestRectangleArea(heights: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (largest-rectangle-area heights)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0084](https://leetcode-cn.com/problems/largest-rectangle-in-histogram)", "[\u67f1\u72b6\u56fe\u4e2d\u6700\u5927\u7684\u77e9\u5f62](/solution/0000-0099/0084.Largest%20Rectangle%20in%20Histogram/README.md)", "`\u6808`,`\u6570\u7ec4`", "\u56f0\u96be", ""], "md_table_row_en": ["[0084](https://leetcode.com/problems/largest-rectangle-in-histogram)", "[Largest Rectangle in Histogram](/solution/0000-0099/0084.Largest%20Rectangle%20in%20Histogram/README_EN.md)", "`Stack`,`Array`", "Hard", ""]}, {"question_id": "0083", "frontend_question_id": "0083", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list", "url_en": "https://leetcode.com/problems/remove-duplicates-from-sorted-list", "relative_path_cn": "/solution/0000-0099/0083.Remove%20Duplicates%20from%20Sorted%20List/README.md", "relative_path_en": "/solution/0000-0099/0083.Remove%20Duplicates%20from%20Sorted%20List/README_EN.md", "title_cn": "\u5220\u9664\u6392\u5e8f\u94fe\u8868\u4e2d\u7684\u91cd\u590d\u5143\u7d20", "title_en": "Remove Duplicates from Sorted List", "question_title_slug": "remove-duplicates-from-sorted-list", "content_en": "

    Given the head of a sorted linked list, delete all duplicates such that each element appears only once. Return the linked list sorted as well.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: head = [1,1,2]\nOutput: [1,2]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: head = [1,1,2,3,3]\nOutput: [1,2,3]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the list is in the range [0, 300].
    • \n\t
    • -100 <= Node.val <= 100
    • \n\t
    • The list is guaranteed to be sorted in ascending order.
    • \n
    \n", "content_cn": "

    \u5b58\u5728\u4e00\u4e2a\u6309\u5347\u5e8f\u6392\u5217\u7684\u94fe\u8868\uff0c\u7ed9\u4f60\u8fd9\u4e2a\u94fe\u8868\u7684\u5934\u8282\u70b9 head \uff0c\u8bf7\u4f60\u5220\u9664\u6240\u6709\u91cd\u590d\u7684\u5143\u7d20\uff0c\u4f7f\u6bcf\u4e2a\u5143\u7d20 \u53ea\u51fa\u73b0\u4e00\u6b21 \u3002

    \n\n

    \u8fd4\u56de\u540c\u6837\u6309\u5347\u5e8f\u6392\u5217\u7684\u7ed3\u679c\u94fe\u8868\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1ahead = [1,1,2]\n\u8f93\u51fa\uff1a[1,2]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1ahead = [1,1,2,3,3]\n\u8f93\u51fa\uff1a[1,2,3]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u94fe\u8868\u4e2d\u8282\u70b9\u6570\u76ee\u5728\u8303\u56f4 [0, 300] \u5185
    • \n\t
    • -100 <= Node.val <= 100
    • \n\t
    • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u94fe\u8868\u5df2\u7ecf\u6309\u5347\u5e8f\u6392\u5217
    • \n
    \n", "tags_en": ["Linked List"], "tags_cn": ["\u94fe\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n ListNode* deleteDuplicates(ListNode* head) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public ListNode deleteDuplicates(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def deleteDuplicates(self, head):\n \"\"\"\n :type head: ListNode\n :rtype: ListNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def deleteDuplicates(self, head: ListNode) -> ListNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nstruct ListNode* deleteDuplicates(struct ListNode* head){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public ListNode DeleteDuplicates(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} head\n * @return {ListNode}\n */\nvar deleteDuplicates = function(head) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode} head\n# @return {ListNode}\ndef delete_duplicates(head)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func deleteDuplicates(_ head: ListNode?) -> ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc deleteDuplicates(head *ListNode) *ListNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def deleteDuplicates(head: ListNode): ListNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun deleteDuplicates(head: ListNode?): ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn delete_duplicates(head: Option>) -> Option> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @return ListNode\n */\n function deleteDuplicates($head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction deleteDuplicates(head: ListNode | null): ListNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (delete-duplicates head)\n (-> (or/c list-node? #f) (or/c list-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0083](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list)", "[\u5220\u9664\u6392\u5e8f\u94fe\u8868\u4e2d\u7684\u91cd\u590d\u5143\u7d20](/solution/0000-0099/0083.Remove%20Duplicates%20from%20Sorted%20List/README.md)", "`\u94fe\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0083](https://leetcode.com/problems/remove-duplicates-from-sorted-list)", "[Remove Duplicates from Sorted List](/solution/0000-0099/0083.Remove%20Duplicates%20from%20Sorted%20List/README_EN.md)", "`Linked List`", "Easy", ""]}, {"question_id": "0082", "frontend_question_id": "0082", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list-ii", "url_en": "https://leetcode.com/problems/remove-duplicates-from-sorted-list-ii", "relative_path_cn": "/solution/0000-0099/0082.Remove%20Duplicates%20from%20Sorted%20List%20II/README.md", "relative_path_en": "/solution/0000-0099/0082.Remove%20Duplicates%20from%20Sorted%20List%20II/README_EN.md", "title_cn": "\u5220\u9664\u6392\u5e8f\u94fe\u8868\u4e2d\u7684\u91cd\u590d\u5143\u7d20 II", "title_en": "Remove Duplicates from Sorted List II", "question_title_slug": "remove-duplicates-from-sorted-list-ii", "content_en": "

    Given the head of a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. Return the linked list sorted as well.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: head = [1,2,3,3,4,4,5]\nOutput: [1,2,5]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: head = [1,1,1,2,3]\nOutput: [2,3]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the list is in the range [0, 300].
    • \n\t
    • -100 <= Node.val <= 100
    • \n\t
    • The list is guaranteed to be sorted in ascending order.
    • \n
    \n", "content_cn": "

    \u5b58\u5728\u4e00\u4e2a\u6309\u5347\u5e8f\u6392\u5217\u7684\u94fe\u8868\uff0c\u7ed9\u4f60\u8fd9\u4e2a\u94fe\u8868\u7684\u5934\u8282\u70b9 head \uff0c\u8bf7\u4f60\u5220\u9664\u94fe\u8868\u4e2d\u6240\u6709\u5b58\u5728\u6570\u5b57\u91cd\u590d\u60c5\u51b5\u7684\u8282\u70b9\uff0c\u53ea\u4fdd\u7559\u539f\u59cb\u94fe\u8868\u4e2d\u00a0\u6ca1\u6709\u91cd\u590d\u51fa\u73b0\u00a0\u7684\u6570\u5b57\u3002

    \n\n

    \u8fd4\u56de\u540c\u6837\u6309\u5347\u5e8f\u6392\u5217\u7684\u7ed3\u679c\u94fe\u8868\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1ahead = [1,2,3,3,4,4,5]\n\u8f93\u51fa\uff1a[1,2,5]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1ahead = [1,1,1,2,3]\n\u8f93\u51fa\uff1a[2,3]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u94fe\u8868\u4e2d\u8282\u70b9\u6570\u76ee\u5728\u8303\u56f4 [0, 300] \u5185
    • \n\t
    • -100 <= Node.val <= 100
    • \n\t
    • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u94fe\u8868\u5df2\u7ecf\u6309\u5347\u5e8f\u6392\u5217
    • \n
    \n", "tags_en": ["Linked List"], "tags_cn": ["\u94fe\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n ListNode* deleteDuplicates(ListNode* head) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public ListNode deleteDuplicates(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def deleteDuplicates(self, head):\n \"\"\"\n :type head: ListNode\n :rtype: ListNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def deleteDuplicates(self, head: ListNode) -> ListNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nstruct ListNode* deleteDuplicates(struct ListNode* head){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public ListNode DeleteDuplicates(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} head\n * @return {ListNode}\n */\nvar deleteDuplicates = function(head) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode} head\n# @return {ListNode}\ndef delete_duplicates(head)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func deleteDuplicates(_ head: ListNode?) -> ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc deleteDuplicates(head *ListNode) *ListNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def deleteDuplicates(head: ListNode): ListNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun deleteDuplicates(head: ListNode?): ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn delete_duplicates(head: Option>) -> Option> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @return ListNode\n */\n function deleteDuplicates($head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction deleteDuplicates(head: ListNode | null): ListNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (delete-duplicates head)\n (-> (or/c list-node? #f) (or/c list-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0082](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list-ii)", "[\u5220\u9664\u6392\u5e8f\u94fe\u8868\u4e2d\u7684\u91cd\u590d\u5143\u7d20 II](/solution/0000-0099/0082.Remove%20Duplicates%20from%20Sorted%20List%20II/README.md)", "`\u94fe\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0082](https://leetcode.com/problems/remove-duplicates-from-sorted-list-ii)", "[Remove Duplicates from Sorted List II](/solution/0000-0099/0082.Remove%20Duplicates%20from%20Sorted%20List%20II/README_EN.md)", "`Linked List`", "Medium", ""]}, {"question_id": "0081", "frontend_question_id": "0081", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/search-in-rotated-sorted-array-ii", "url_en": "https://leetcode.com/problems/search-in-rotated-sorted-array-ii", "relative_path_cn": "/solution/0000-0099/0081.Search%20in%20Rotated%20Sorted%20Array%20II/README.md", "relative_path_en": "/solution/0000-0099/0081.Search%20in%20Rotated%20Sorted%20Array%20II/README_EN.md", "title_cn": "\u641c\u7d22\u65cb\u8f6c\u6392\u5e8f\u6570\u7ec4 II", "title_en": "Search in Rotated Sorted Array II", "question_title_slug": "search-in-rotated-sorted-array-ii", "content_en": "

    There is an integer array nums sorted in non-decreasing order (not necessarily with distinct values).

    \n\n

    Before being passed to your function, nums is rotated at an unknown pivot index k (0 <= k < nums.length) such that the resulting array is [nums[k], nums[k+1], ..., nums[n-1], nums[0], nums[1], ..., nums[k-1]] (0-indexed). For example, [0,1,2,4,4,4,5,6,6,7] might be rotated at pivot index 5 and become [4,5,6,6,7,0,1,2,4,4].

    \n\n

    Given the array nums after the rotation and an integer target, return true if target is in nums, or false if it is not in nums.

    \n\n

    You must decrease the overall operation steps as much as possible.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [2,5,6,0,0,1,2], target = 0\nOutput: true\n

    Example 2:

    \n
    Input: nums = [2,5,6,0,0,1,2], target = 3\nOutput: false\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 5000
    • \n\t
    • -104 <= nums[i] <= 104
    • \n\t
    • nums is guaranteed to be rotated at some pivot.
    • \n\t
    • -104 <= target <= 104
    • \n
    \n\n

     

    \n

    Follow up: This problem is similar to Search in Rotated Sorted Array, but nums may contain duplicates. Would this affect the runtime complexity? How and why?

    \n", "content_cn": "

    \u5df2\u77e5\u5b58\u5728\u4e00\u4e2a\u6309\u975e\u964d\u5e8f\u6392\u5217\u7684\u6574\u6570\u6570\u7ec4 nums \uff0c\u6570\u7ec4\u4e2d\u7684\u503c\u4e0d\u5fc5\u4e92\u4e0d\u76f8\u540c\u3002

    \n\n

    \u5728\u4f20\u9012\u7ed9\u51fd\u6570\u4e4b\u524d\uff0cnums \u5728\u9884\u5148\u672a\u77e5\u7684\u67d0\u4e2a\u4e0b\u6807 k\uff080 <= k < nums.length\uff09\u4e0a\u8fdb\u884c\u4e86 \u65cb\u8f6c \uff0c\u4f7f\u6570\u7ec4\u53d8\u4e3a [nums[k], nums[k+1], ..., nums[n-1], nums[0], nums[1], ..., nums[k-1]]\uff08\u4e0b\u6807 \u4ece 0 \u5f00\u59cb \u8ba1\u6570\uff09\u3002\u4f8b\u5982\uff0c [0,1,2,4,4,4,5,6,6,7] \u5728\u4e0b\u6807 5 \u5904\u7ecf\u65cb\u8f6c\u540e\u53ef\u80fd\u53d8\u4e3a [4,5,6,6,7,0,1,2,4,4] \u3002

    \n\n

    \u7ed9\u4f60 \u65cb\u8f6c\u540e \u7684\u6570\u7ec4 nums \u548c\u4e00\u4e2a\u6574\u6570 target \uff0c\u8bf7\u4f60\u7f16\u5199\u4e00\u4e2a\u51fd\u6570\u6765\u5224\u65ad\u7ed9\u5b9a\u7684\u76ee\u6807\u503c\u662f\u5426\u5b58\u5728\u4e8e\u6570\u7ec4\u4e2d\u3002\u5982\u679c nums \u4e2d\u5b58\u5728\u8fd9\u4e2a\u76ee\u6807\u503c target \uff0c\u5219\u8fd4\u56de true \uff0c\u5426\u5219\u8fd4\u56de false \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\u00a01\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [2,5,6,0,0,1,2], target = 0\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b\u00a02\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [2,5,6,0,0,1,2], target = 3\n\u8f93\u51fa\uff1afalse
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 5000
    • \n\t
    • -104 <= nums[i] <= 104
    • \n\t
    • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1 nums \u5728\u9884\u5148\u672a\u77e5\u7684\u67d0\u4e2a\u4e0b\u6807\u4e0a\u8fdb\u884c\u4e86\u65cb\u8f6c
    • \n\t
    • -104 <= target <= 104
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u8fd9\u662f \u641c\u7d22\u65cb\u8f6c\u6392\u5e8f\u6570\u7ec4\u00a0\u7684\u5ef6\u4f38\u9898\u76ee\uff0c\u672c\u9898\u4e2d\u7684\u00a0nums\u00a0 \u53ef\u80fd\u5305\u542b\u91cd\u590d\u5143\u7d20\u3002
    • \n\t
    • \u8fd9\u4f1a\u5f71\u54cd\u5230\u7a0b\u5e8f\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u5417\uff1f\u4f1a\u6709\u600e\u6837\u7684\u5f71\u54cd\uff0c\u4e3a\u4ec0\u4e48\uff1f
    • \n
    \n", "tags_en": ["Array", "Binary Search"], "tags_cn": ["\u6570\u7ec4", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool search(vector& nums, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean search(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def search(self, nums, target):\n \"\"\"\n :type nums: List[int]\n :type target: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def search(self, nums: List[int], target: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool search(int* nums, int numsSize, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool Search(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} target\n * @return {boolean}\n */\nvar search = function(nums, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} target\n# @return {Boolean}\ndef search(nums, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func search(_ nums: [Int], _ target: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func search(nums []int, target int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def search(nums: Array[Int], target: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun search(nums: IntArray, target: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn search(nums: Vec, target: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $target\n * @return Boolean\n */\n function search($nums, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function search(nums: number[], target: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (search nums target)\n (-> (listof exact-integer?) exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0081](https://leetcode-cn.com/problems/search-in-rotated-sorted-array-ii)", "[\u641c\u7d22\u65cb\u8f6c\u6392\u5e8f\u6570\u7ec4 II](/solution/0000-0099/0081.Search%20in%20Rotated%20Sorted%20Array%20II/README.md)", "`\u6570\u7ec4`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0081](https://leetcode.com/problems/search-in-rotated-sorted-array-ii)", "[Search in Rotated Sorted Array II](/solution/0000-0099/0081.Search%20in%20Rotated%20Sorted%20Array%20II/README_EN.md)", "`Array`,`Binary Search`", "Medium", ""]}, {"question_id": "0080", "frontend_question_id": "0080", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array-ii", "url_en": "https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii", "relative_path_cn": "/solution/0000-0099/0080.Remove%20Duplicates%20from%20Sorted%20Array%20II/README.md", "relative_path_en": "/solution/0000-0099/0080.Remove%20Duplicates%20from%20Sorted%20Array%20II/README_EN.md", "title_cn": "\u5220\u9664\u6709\u5e8f\u6570\u7ec4\u4e2d\u7684\u91cd\u590d\u9879 II", "title_en": "Remove Duplicates from Sorted Array II", "question_title_slug": "remove-duplicates-from-sorted-array-ii", "content_en": "

    Given a sorted array nums, remove the duplicates in-place such that duplicates appeared at most twice and return the new length.

    \n\n

    Do not allocate extra space for another array; you must do this by modifying the input array in-place with O(1) extra memory.

    \n\n

    Clarification:

    \n\n

    Confused why the returned value is an integer, but your answer is an array?

    \n\n

    Note that the input array is passed in by reference, which means a modification to the input array will be known to the caller.

    \n\n

    Internally you can think of this:

    \n\n
    \n// nums is passed in by reference. (i.e., without making a copy)\nint len = removeDuplicates(nums);\n\n// any modification to nums in your function would be known by the caller.\n// using the length returned by your function, it prints the first len elements.\nfor (int i = 0; i < len; i++) {\n    print(nums[i]);\n}\n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,1,1,2,2,3]\nOutput: 5, nums = [1,1,2,2,3]\nExplanation: Your function should return length = 5, with the first five elements of nums being 1, 1, 2, 2 and 3 respectively. It doesn't matter what you leave beyond the returned length.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [0,0,1,1,1,1,2,3,3]\nOutput: 7, nums = [0,0,1,1,2,3,3]\nExplanation: Your function should return length = 7, with the first seven elements of nums being modified to 0, 0, 1, 1, 2, 3 and 3 respectively. It doesn't matter what values are set beyond the returned length.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 3 * 104
    • \n\t
    • -104 <= nums[i] <= 104
    • \n\t
    • nums is sorted in ascending order.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6709\u5e8f\u6570\u7ec4 nums \uff0c\u8bf7\u4f60 \u539f\u5730 \u5220\u9664\u91cd\u590d\u51fa\u73b0\u7684\u5143\u7d20\uff0c\u4f7f\u6bcf\u4e2a\u5143\u7d20 \u6700\u591a\u51fa\u73b0\u4e24\u6b21 \uff0c\u8fd4\u56de\u5220\u9664\u540e\u6570\u7ec4\u7684\u65b0\u957f\u5ea6\u3002

    \n\n

    \u4e0d\u8981\u4f7f\u7528\u989d\u5916\u7684\u6570\u7ec4\u7a7a\u95f4\uff0c\u4f60\u5fc5\u987b\u5728 \u539f\u5730 \u4fee\u6539\u8f93\u5165\u6570\u7ec4 \u5e76\u5728\u4f7f\u7528 O(1) \u989d\u5916\u7a7a\u95f4\u7684\u6761\u4ef6\u4e0b\u5b8c\u6210\u3002

    \n\n

    \u00a0

    \n\n

    \u8bf4\u660e\uff1a

    \n\n

    \u4e3a\u4ec0\u4e48\u8fd4\u56de\u6570\u503c\u662f\u6574\u6570\uff0c\u4f46\u8f93\u51fa\u7684\u7b54\u6848\u662f\u6570\u7ec4\u5462\uff1f

    \n\n

    \u8bf7\u6ce8\u610f\uff0c\u8f93\u5165\u6570\u7ec4\u662f\u4ee5\u300c\u5f15\u7528\u300d\u65b9\u5f0f\u4f20\u9012\u7684\uff0c\u8fd9\u610f\u5473\u7740\u5728\u51fd\u6570\u91cc\u4fee\u6539\u8f93\u5165\u6570\u7ec4\u5bf9\u4e8e\u8c03\u7528\u8005\u662f\u53ef\u89c1\u7684\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u60f3\u8c61\u5185\u90e8\u64cd\u4f5c\u5982\u4e0b:

    \n\n
    \n// nums \u662f\u4ee5\u201c\u5f15\u7528\u201d\u65b9\u5f0f\u4f20\u9012\u7684\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u4e0d\u5bf9\u5b9e\u53c2\u505a\u4efb\u4f55\u62f7\u8d1d\nint len = removeDuplicates(nums);\n\n// \u5728\u51fd\u6570\u91cc\u4fee\u6539\u8f93\u5165\u6570\u7ec4\u5bf9\u4e8e\u8c03\u7528\u8005\u662f\u53ef\u89c1\u7684\u3002\n// \u6839\u636e\u4f60\u7684\u51fd\u6570\u8fd4\u56de\u7684\u957f\u5ea6, \u5b83\u4f1a\u6253\u5370\u51fa\u6570\u7ec4\u4e2d \u8be5\u957f\u5ea6\u8303\u56f4\u5185 \u7684\u6240\u6709\u5143\u7d20\u3002\nfor (int i = 0; i < len; i++) {\n\u00a0 \u00a0 print(nums[i]);\n}\n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,1,1,2,2,3]\n\u8f93\u51fa\uff1a5, nums = [1,1,2,2,3]\n\u89e3\u91ca\uff1a\u51fd\u6570\u5e94\u8fd4\u56de\u65b0\u957f\u5ea6 length = 5, \u5e76\u4e14\u539f\u6570\u7ec4\u7684\u524d\u4e94\u4e2a\u5143\u7d20\u88ab\u4fee\u6539\u4e3a 1, 1, 2, 2, 3 \u3002 \u4e0d\u9700\u8981\u8003\u8651\u6570\u7ec4\u4e2d\u8d85\u51fa\u65b0\u957f\u5ea6\u540e\u9762\u7684\u5143\u7d20\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [0,0,1,1,1,1,2,3,3]\n\u8f93\u51fa\uff1a7, nums = [0,0,1,1,2,3,3]\n\u89e3\u91ca\uff1a\u51fd\u6570\u5e94\u8fd4\u56de\u65b0\u957f\u5ea6 length = 7, \u5e76\u4e14\u539f\u6570\u7ec4\u7684\u524d\u4e94\u4e2a\u5143\u7d20\u88ab\u4fee\u6539\u4e3a\u00a00, 0, 1, 1, 2, 3, 3 \u3002 \u4e0d\u9700\u8981\u8003\u8651\u6570\u7ec4\u4e2d\u8d85\u51fa\u65b0\u957f\u5ea6\u540e\u9762\u7684\u5143\u7d20\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 3 * 104
    • \n\t
    • -104 <= nums[i] <= 104
    • \n\t
    • nums \u5df2\u6309\u5347\u5e8f\u6392\u5217
    • \n
    \n", "tags_en": ["Array", "Two Pointers"], "tags_cn": ["\u6570\u7ec4", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int removeDuplicates(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int removeDuplicates(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def removeDuplicates(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def removeDuplicates(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint removeDuplicates(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int RemoveDuplicates(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar removeDuplicates = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef remove_duplicates(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func removeDuplicates(_ nums: inout [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func removeDuplicates(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def removeDuplicates(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun removeDuplicates(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn remove_duplicates(nums: &mut Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function removeDuplicates(&$nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function removeDuplicates(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0080](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array-ii)", "[\u5220\u9664\u6709\u5e8f\u6570\u7ec4\u4e2d\u7684\u91cd\u590d\u9879 II](/solution/0000-0099/0080.Remove%20Duplicates%20from%20Sorted%20Array%20II/README.md)", "`\u6570\u7ec4`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0080](https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii)", "[Remove Duplicates from Sorted Array II](/solution/0000-0099/0080.Remove%20Duplicates%20from%20Sorted%20Array%20II/README_EN.md)", "`Array`,`Two Pointers`", "Medium", ""]}, {"question_id": "0079", "frontend_question_id": "0079", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/word-search", "url_en": "https://leetcode.com/problems/word-search", "relative_path_cn": "/solution/0000-0099/0079.Word%20Search/README.md", "relative_path_en": "/solution/0000-0099/0079.Word%20Search/README_EN.md", "title_cn": "\u5355\u8bcd\u641c\u7d22", "title_en": "Word Search", "question_title_slug": "word-search", "content_en": "

    Given an m x n grid of characters board and a string word, return true if word exists in the grid.

    \n\n

    The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically neighboring. The same letter cell may not be used more than once.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "ABCCED"\nOutput: true\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "SEE"\nOutput: true\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "ABCB"\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == board.length
    • \n\t
    • n = board[i].length
    • \n\t
    • 1 <= m, n <= 6
    • \n\t
    • 1 <= word.length <= 15
    • \n\t
    • board and word consists of only lowercase and uppercase English letters.
    • \n
    \n\n

     

    \n

    Follow up: Could you use search pruning to make your solution faster with a larger board?

    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u00a0m x n \u4e8c\u7ef4\u5b57\u7b26\u7f51\u683c\u00a0board \u548c\u4e00\u4e2a\u5b57\u7b26\u4e32\u5355\u8bcd\u00a0word \u3002\u5982\u679c\u00a0word \u5b58\u5728\u4e8e\u7f51\u683c\u4e2d\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n

    \u5355\u8bcd\u5fc5\u987b\u6309\u7167\u5b57\u6bcd\u987a\u5e8f\uff0c\u901a\u8fc7\u76f8\u90bb\u7684\u5355\u5143\u683c\u5185\u7684\u5b57\u6bcd\u6784\u6210\uff0c\u5176\u4e2d\u201c\u76f8\u90bb\u201d\u5355\u5143\u683c\u662f\u90a3\u4e9b\u6c34\u5e73\u76f8\u90bb\u6216\u5782\u76f4\u76f8\u90bb\u7684\u5355\u5143\u683c\u3002\u540c\u4e00\u4e2a\u5355\u5143\u683c\u5185\u7684\u5b57\u6bcd\u4e0d\u5141\u8bb8\u88ab\u91cd\u590d\u4f7f\u7528\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aboard = [[\"A\",\"B\",\"C\",\"E\"],[\"S\",\"F\",\"C\",\"S\"],[\"A\",\"D\",\"E\",\"E\"]], word = \"ABCCED\"\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aboard = [[\"A\",\"B\",\"C\",\"E\"],[\"S\",\"F\",\"C\",\"S\"],[\"A\",\"D\",\"E\",\"E\"]], word = \"SEE\"\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aboard = [[\"A\",\"B\",\"C\",\"E\"],[\"S\",\"F\",\"C\",\"S\"],[\"A\",\"D\",\"E\",\"E\"]], word = \"ABCB\"\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == board.length
    • \n\t
    • n = board[i].length
    • \n\t
    • 1 <= m, n <= 6
    • \n\t
    • 1 <= word.length <= 15
    • \n\t
    • board \u548c word \u4ec5\u7531\u5927\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u53ef\u4ee5\u4f7f\u7528\u641c\u7d22\u526a\u679d\u7684\u6280\u672f\u6765\u4f18\u5316\u89e3\u51b3\u65b9\u6848\uff0c\u4f7f\u5176\u5728 board \u66f4\u5927\u7684\u60c5\u51b5\u4e0b\u53ef\u4ee5\u66f4\u5feb\u89e3\u51b3\u95ee\u9898\uff1f

    \n", "tags_en": ["Array", "Backtracking"], "tags_cn": ["\u6570\u7ec4", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool exist(vector>& board, string word) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean exist(char[][] board, String word) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def exist(self, board, word):\n \"\"\"\n :type board: List[List[str]]\n :type word: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def exist(self, board: List[List[str]], word: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool exist(char** board, int boardSize, int* boardColSize, char * word){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool Exist(char[][] board, string word) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {character[][]} board\n * @param {string} word\n * @return {boolean}\n */\nvar exist = function(board, word) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Character[][]} board\n# @param {String} word\n# @return {Boolean}\ndef exist(board, word)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func exist(_ board: [[Character]], _ word: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func exist(board [][]byte, word string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def exist(board: Array[Array[Char]], word: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun exist(board: Array, word: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn exist(board: Vec>, word: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $board\n * @param String $word\n * @return Boolean\n */\n function exist($board, $word) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function exist(board: string[][], word: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (exist board word)\n (-> (listof (listof char?)) string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0079](https://leetcode-cn.com/problems/word-search)", "[\u5355\u8bcd\u641c\u7d22](/solution/0000-0099/0079.Word%20Search/README.md)", "`\u6570\u7ec4`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0079](https://leetcode.com/problems/word-search)", "[Word Search](/solution/0000-0099/0079.Word%20Search/README_EN.md)", "`Array`,`Backtracking`", "Medium", ""]}, {"question_id": "0078", "frontend_question_id": "0078", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/subsets", "url_en": "https://leetcode.com/problems/subsets", "relative_path_cn": "/solution/0000-0099/0078.Subsets/README.md", "relative_path_en": "/solution/0000-0099/0078.Subsets/README_EN.md", "title_cn": "\u5b50\u96c6", "title_en": "Subsets", "question_title_slug": "subsets", "content_en": "

    Given an integer array nums of unique elements, return all possible subsets (the power set).

    \n\n

    The solution set must not contain duplicate subsets. Return the solution in any order.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,3]\nOutput: [[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]]\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [0]\nOutput: [[],[0]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 10
    • \n\t
    • -10 <= nums[i] <= 10
    • \n\t
    • All the numbers of nums are unique.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0nums \uff0c\u6570\u7ec4\u4e2d\u7684\u5143\u7d20 \u4e92\u4e0d\u76f8\u540c \u3002\u8fd4\u56de\u8be5\u6570\u7ec4\u6240\u6709\u53ef\u80fd\u7684\u5b50\u96c6\uff08\u5e42\u96c6\uff09\u3002

    \n\n

    \u89e3\u96c6 \u4e0d\u80fd \u5305\u542b\u91cd\u590d\u7684\u5b50\u96c6\u3002\u4f60\u53ef\u4ee5\u6309 \u4efb\u610f\u987a\u5e8f \u8fd4\u56de\u89e3\u96c6\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,3]\n\u8f93\u51fa\uff1a[[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [0]\n\u8f93\u51fa\uff1a[[],[0]]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 10
    • \n\t
    • -10 <= nums[i] <= 10
    • \n\t
    • nums \u4e2d\u7684\u6240\u6709\u5143\u7d20 \u4e92\u4e0d\u76f8\u540c
    • \n
    \n", "tags_en": ["Bit Manipulation", "Array", "Backtracking"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u6570\u7ec4", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> subsets(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> subsets(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def subsets(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def subsets(self, nums: List[int]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** subsets(int* nums, int numsSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> Subsets(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number[][]}\n */\nvar subsets = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer[][]}\ndef subsets(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func subsets(_ nums: [Int]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func subsets(nums []int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def subsets(nums: Array[Int]): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun subsets(nums: IntArray): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn subsets(nums: Vec) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer[][]\n */\n function subsets($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function subsets(nums: number[]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (subsets nums)\n (-> (listof exact-integer?) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0078](https://leetcode-cn.com/problems/subsets)", "[\u5b50\u96c6](/solution/0000-0099/0078.Subsets/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u6570\u7ec4`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0078](https://leetcode.com/problems/subsets)", "[Subsets](/solution/0000-0099/0078.Subsets/README_EN.md)", "`Bit Manipulation`,`Array`,`Backtracking`", "Medium", ""]}, {"question_id": "0077", "frontend_question_id": "0077", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/combinations", "url_en": "https://leetcode.com/problems/combinations", "relative_path_cn": "/solution/0000-0099/0077.Combinations/README.md", "relative_path_en": "/solution/0000-0099/0077.Combinations/README_EN.md", "title_cn": "\u7ec4\u5408", "title_en": "Combinations", "question_title_slug": "combinations", "content_en": "

    Given two integers n and k, return all possible combinations of k numbers out of the range [1, n].

    \n\n

    You may return the answer in any order.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 4, k = 2\nOutput:\n[\n  [2,4],\n  [3,4],\n  [2,3],\n  [1,2],\n  [1,3],\n  [1,4],\n]\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 1, k = 1\nOutput: [[1]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 20
    • \n\t
    • 1 <= k <= n
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u6574\u6570 n \u548c k\uff0c\u8fd4\u56de 1 ... n \u4e2d\u6240\u6709\u53ef\u80fd\u7684 k \u4e2a\u6570\u7684\u7ec4\u5408\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: n = 4, k = 2\n\u8f93\u51fa:\n[\n  [2,4],\n  [3,4],\n  [2,3],\n  [1,2],\n  [1,3],\n  [1,4],\n]
    \n", "tags_en": ["Backtracking"], "tags_cn": ["\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> combine(int n, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> combine(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def combine(self, n, k):\n \"\"\"\n :type n: int\n :type k: int\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def combine(self, n: int, k: int) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** combine(int n, int k, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> Combine(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} k\n * @return {number[][]}\n */\nvar combine = function(n, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} k\n# @return {Integer[][]}\ndef combine(n, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func combine(_ n: Int, _ k: Int) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func combine(n int, k int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def combine(n: Int, k: Int): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun combine(n: Int, k: Int): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn combine(n: i32, k: i32) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $k\n * @return Integer[][]\n */\n function combine($n, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function combine(n: number, k: number): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (combine n k)\n (-> exact-integer? exact-integer? (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0077](https://leetcode-cn.com/problems/combinations)", "[\u7ec4\u5408](/solution/0000-0099/0077.Combinations/README.md)", "`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0077](https://leetcode.com/problems/combinations)", "[Combinations](/solution/0000-0099/0077.Combinations/README_EN.md)", "`Backtracking`", "Medium", ""]}, {"question_id": "0076", "frontend_question_id": "0076", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-window-substring", "url_en": "https://leetcode.com/problems/minimum-window-substring", "relative_path_cn": "/solution/0000-0099/0076.Minimum%20Window%20Substring/README.md", "relative_path_en": "/solution/0000-0099/0076.Minimum%20Window%20Substring/README_EN.md", "title_cn": "\u6700\u5c0f\u8986\u76d6\u5b50\u4e32", "title_en": "Minimum Window Substring", "question_title_slug": "minimum-window-substring", "content_en": "

    Given two strings s and t of lengths m and n respectively, return the minimum window substring of s such that every character in t (including duplicates) is included in the window. If there is no such substring, return the empty string "".

    \n\n

    The testcases will be generated such that the answer is unique.

    \n\n

    A substring is a contiguous sequence of characters within the string.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "ADOBECODEBANC", t = "ABC"\nOutput: "BANC"\nExplanation: The minimum window substring "BANC" includes 'A', 'B', and 'C' from string t.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "a", t = "a"\nOutput: "a"\nExplanation: The entire string s is the minimum window.\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "a", t = "aa"\nOutput: ""\nExplanation: Both 'a's from t must be included in the window.\nSince the largest window of s only has one 'a', return empty string.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == s.length
    • \n\t
    • n == t.length
    • \n\t
    • 1 <= m, n <= 105
    • \n\t
    • s and t consist of uppercase and lowercase English letters.
    • \n
    \n\n

     

    \nFollow up: Could you find an algorithm that runs in O(m + n) time?", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \u3001\u4e00\u4e2a\u5b57\u7b26\u4e32 t \u3002\u8fd4\u56de s \u4e2d\u6db5\u76d6 t \u6240\u6709\u5b57\u7b26\u7684\u6700\u5c0f\u5b50\u4e32\u3002\u5982\u679c s \u4e2d\u4e0d\u5b58\u5728\u6db5\u76d6 t \u6240\u6709\u5b57\u7b26\u7684\u5b50\u4e32\uff0c\u5219\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32 \"\" \u3002

    \n\n

    \u6ce8\u610f\uff1a\u5982\u679c s \u4e2d\u5b58\u5728\u8fd9\u6837\u7684\u5b50\u4e32\uff0c\u6211\u4eec\u4fdd\u8bc1\u5b83\u662f\u552f\u4e00\u7684\u7b54\u6848\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"ADOBECODEBANC\", t = \"ABC\"\n\u8f93\u51fa\uff1a\"BANC\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"a\", t = \"a\"\n\u8f93\u51fa\uff1a\"a\"\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length, t.length <= 105
    • \n\t
    • s \u548c t \u7531\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n\n

    \u00a0

    \n\u8fdb\u9636\uff1a\u4f60\u80fd\u8bbe\u8ba1\u4e00\u4e2a\u5728 o(n) \u65f6\u95f4\u5185\u89e3\u51b3\u6b64\u95ee\u9898\u7684\u7b97\u6cd5\u5417\uff1f", "tags_en": ["Hash Table", "Two Pointers", "String", "Sliding Window"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u53cc\u6307\u9488", "\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string minWindow(string s, string t) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String minWindow(String s, String t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minWindow(self, s, t):\n \"\"\"\n :type s: str\n :type t: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minWindow(self, s: str, t: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * minWindow(char * s, char * t){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string MinWindow(string s, string t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string} t\n * @return {string}\n */\nvar minWindow = function(s, t) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String} t\n# @return {String}\ndef min_window(s, t)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minWindow(_ s: String, _ t: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minWindow(s string, t string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minWindow(s: String, t: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minWindow(s: String, t: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_window(s: String, t: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String $t\n * @return String\n */\n function minWindow($s, $t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minWindow(s: string, t: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-window s t)\n (-> string? string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0076](https://leetcode-cn.com/problems/minimum-window-substring)", "[\u6700\u5c0f\u8986\u76d6\u5b50\u4e32](/solution/0000-0099/0076.Minimum%20Window%20Substring/README.md)", "`\u54c8\u5e0c\u8868`,`\u53cc\u6307\u9488`,`\u5b57\u7b26\u4e32`", "\u56f0\u96be", ""], "md_table_row_en": ["[0076](https://leetcode.com/problems/minimum-window-substring)", "[Minimum Window Substring](/solution/0000-0099/0076.Minimum%20Window%20Substring/README_EN.md)", "`Hash Table`,`Two Pointers`,`String`,`Sliding Window`", "Hard", ""]}, {"question_id": "0075", "frontend_question_id": "0075", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sort-colors", "url_en": "https://leetcode.com/problems/sort-colors", "relative_path_cn": "/solution/0000-0099/0075.Sort%20Colors/README.md", "relative_path_en": "/solution/0000-0099/0075.Sort%20Colors/README_EN.md", "title_cn": "\u989c\u8272\u5206\u7c7b", "title_en": "Sort Colors", "question_title_slug": "sort-colors", "content_en": "

    Given an array nums with n objects colored red, white, or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white, and blue.

    \n\n

    We will use the integers 0, 1, and 2 to represent the color red, white, and blue, respectively.

    \n\n

    You must solve this problem without using the library's sort function.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [2,0,2,1,1,0]\nOutput: [0,0,1,1,2,2]\n

    Example 2:

    \n
    Input: nums = [2,0,1]\nOutput: [0,1,2]\n

    Example 3:

    \n
    Input: nums = [0]\nOutput: [0]\n

    Example 4:

    \n
    Input: nums = [1]\nOutput: [1]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= n <= 300
    • \n\t
    • nums[i] is 0, 1, or 2.
    • \n
    \n\n

     

    \n

    Follow up: Could you come up with a one-pass algorithm using only constant extra space?

    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5305\u542b\u7ea2\u8272\u3001\u767d\u8272\u548c\u84dd\u8272\uff0c\u4e00\u5171\u00a0n \u4e2a\u5143\u7d20\u7684\u6570\u7ec4\uff0c\u539f\u5730\u5bf9\u5b83\u4eec\u8fdb\u884c\u6392\u5e8f\uff0c\u4f7f\u5f97\u76f8\u540c\u989c\u8272\u7684\u5143\u7d20\u76f8\u90bb\uff0c\u5e76\u6309\u7167\u7ea2\u8272\u3001\u767d\u8272\u3001\u84dd\u8272\u987a\u5e8f\u6392\u5217\u3002

    \n\n

    \u6b64\u9898\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u6574\u6570 0\u3001\u00a01 \u548c 2 \u5206\u522b\u8868\u793a\u7ea2\u8272\u3001\u767d\u8272\u548c\u84dd\u8272\u3002

    \n\n
      \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [2,0,2,1,1,0]\n\u8f93\u51fa\uff1a[0,0,1,1,2,2]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [2,0,1]\n\u8f93\u51fa\uff1a[0,1,2]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [0]\n\u8f93\u51fa\uff1a[0]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1]\n\u8f93\u51fa\uff1a[1]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= n <= 300
    • \n\t
    • nums[i] \u4e3a 0\u30011 \u6216 2
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u4f60\u53ef\u4ee5\u4e0d\u4f7f\u7528\u4ee3\u7801\u5e93\u4e2d\u7684\u6392\u5e8f\u51fd\u6570\u6765\u89e3\u51b3\u8fd9\u9053\u9898\u5417\uff1f
    • \n\t
    • \u4f60\u80fd\u60f3\u51fa\u4e00\u4e2a\u4ec5\u4f7f\u7528\u5e38\u6570\u7a7a\u95f4\u7684\u4e00\u8d9f\u626b\u63cf\u7b97\u6cd5\u5417\uff1f
    • \n
    \n", "tags_en": ["Sort", "Array", "Two Pointers"], "tags_cn": ["\u6392\u5e8f", "\u6570\u7ec4", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n void sortColors(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public void sortColors(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def sortColors(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: None Do not return anything, modify nums in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def sortColors(self, nums: List[int]) -> None:\n \"\"\"\n Do not return anything, modify nums in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nvoid sortColors(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public void SortColors(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {void} Do not return anything, modify nums in-place instead.\n */\nvar sortColors = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Void} Do not return anything, modify nums in-place instead.\ndef sort_colors(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func sortColors(_ nums: inout [Int]) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func sortColors(nums []int) {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def sortColors(nums: Array[Int]): Unit = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun sortColors(nums: IntArray): Unit {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sort_colors(nums: &mut Vec) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return NULL\n */\n function sortColors(&$nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n Do not return anything, modify nums in-place instead.\n */\nfunction sortColors(nums: number[]): void {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0075](https://leetcode-cn.com/problems/sort-colors)", "[\u989c\u8272\u5206\u7c7b](/solution/0000-0099/0075.Sort%20Colors/README.md)", "`\u6392\u5e8f`,`\u6570\u7ec4`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0075](https://leetcode.com/problems/sort-colors)", "[Sort Colors](/solution/0000-0099/0075.Sort%20Colors/README_EN.md)", "`Sort`,`Array`,`Two Pointers`", "Medium", ""]}, {"question_id": "0074", "frontend_question_id": "0074", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/search-a-2d-matrix", "url_en": "https://leetcode.com/problems/search-a-2d-matrix", "relative_path_cn": "/solution/0000-0099/0074.Search%20a%202D%20Matrix/README.md", "relative_path_en": "/solution/0000-0099/0074.Search%20a%202D%20Matrix/README_EN.md", "title_cn": "\u641c\u7d22\u4e8c\u7ef4\u77e9\u9635", "title_en": "Search a 2D Matrix", "question_title_slug": "search-a-2d-matrix", "content_en": "

    Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:

    \n\n
      \n\t
    • Integers in each row are sorted from left to right.
    • \n\t
    • The first integer of each row is greater than the last integer of the previous row.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 3\nOutput: true\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 13\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == matrix.length
    • \n\t
    • n == matrix[i].length
    • \n\t
    • 1 <= m, n <= 100
    • \n\t
    • -104 <= matrix[i][j], target <= 104
    • \n
    \n", "content_cn": "

    \u7f16\u5199\u4e00\u4e2a\u9ad8\u6548\u7684\u7b97\u6cd5\u6765\u5224\u65ad\u00a0m x n\u00a0\u77e9\u9635\u4e2d\uff0c\u662f\u5426\u5b58\u5728\u4e00\u4e2a\u76ee\u6807\u503c\u3002\u8be5\u77e9\u9635\u5177\u6709\u5982\u4e0b\u7279\u6027\uff1a

    \n\n
      \n\t
    • \u6bcf\u884c\u4e2d\u7684\u6574\u6570\u4ece\u5de6\u5230\u53f3\u6309\u5347\u5e8f\u6392\u5217\u3002
    • \n\t
    • \u6bcf\u884c\u7684\u7b2c\u4e00\u4e2a\u6574\u6570\u5927\u4e8e\u524d\u4e00\u884c\u7684\u6700\u540e\u4e00\u4e2a\u6574\u6570\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1amatrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 3\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1amatrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 13\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == matrix.length
    • \n\t
    • n == matrix[i].length
    • \n\t
    • 1 <= m, n <= 100
    • \n\t
    • -104 <= matrix[i][j], target <= 104
    • \n
    \n", "tags_en": ["Array", "Binary Search"], "tags_cn": ["\u6570\u7ec4", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool searchMatrix(vector>& matrix, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean searchMatrix(int[][] matrix, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def searchMatrix(self, matrix, target):\n \"\"\"\n :type matrix: List[List[int]]\n :type target: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def searchMatrix(self, matrix: List[List[int]], target: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool searchMatrix(int** matrix, int matrixSize, int* matrixColSize, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool SearchMatrix(int[][] matrix, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} matrix\n * @param {number} target\n * @return {boolean}\n */\nvar searchMatrix = function(matrix, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} matrix\n# @param {Integer} target\n# @return {Boolean}\ndef search_matrix(matrix, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func searchMatrix(_ matrix: [[Int]], _ target: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func searchMatrix(matrix [][]int, target int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def searchMatrix(matrix: Array[Array[Int]], target: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun searchMatrix(matrix: Array, target: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn search_matrix(matrix: Vec>, target: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $matrix\n * @param Integer $target\n * @return Boolean\n */\n function searchMatrix($matrix, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function searchMatrix(matrix: number[][], target: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (search-matrix matrix target)\n (-> (listof (listof exact-integer?)) exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0074](https://leetcode-cn.com/problems/search-a-2d-matrix)", "[\u641c\u7d22\u4e8c\u7ef4\u77e9\u9635](/solution/0000-0099/0074.Search%20a%202D%20Matrix/README.md)", "`\u6570\u7ec4`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0074](https://leetcode.com/problems/search-a-2d-matrix)", "[Search a 2D Matrix](/solution/0000-0099/0074.Search%20a%202D%20Matrix/README_EN.md)", "`Array`,`Binary Search`", "Medium", ""]}, {"question_id": "0073", "frontend_question_id": "0073", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/set-matrix-zeroes", "url_en": "https://leetcode.com/problems/set-matrix-zeroes", "relative_path_cn": "/solution/0000-0099/0073.Set%20Matrix%20Zeroes/README.md", "relative_path_en": "/solution/0000-0099/0073.Set%20Matrix%20Zeroes/README_EN.md", "title_cn": "\u77e9\u9635\u7f6e\u96f6", "title_en": "Set Matrix Zeroes", "question_title_slug": "set-matrix-zeroes", "content_en": "

    Given an m x n matrix. If an element is 0, set its entire row and column to 0. Do it in-place.

    \n\n

    Follow up:

    \n\n
      \n\t
    • A straight forward solution using O(mn) space is probably a bad idea.
    • \n\t
    • A simple improvement uses O(m + n) space, but still not the best solution.
    • \n\t
    • Could you devise a constant space solution?
    • \n
    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: matrix = [[1,1,1],[1,0,1],[1,1,1]]\nOutput: [[1,0,1],[0,0,0],[1,0,1]]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: matrix = [[0,1,2,0],[3,4,5,2],[1,3,1,5]]\nOutput: [[0,0,0,0],[0,4,5,0],[0,3,1,0]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == matrix.length
    • \n\t
    • n == matrix[0].length
    • \n\t
    • 1 <= m, n <= 200
    • \n\t
    • -231 <= matrix[i][j] <= 231 - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u00a0m x n \u7684\u77e9\u9635\uff0c\u5982\u679c\u4e00\u4e2a\u5143\u7d20\u4e3a 0 \uff0c\u5219\u5c06\u5176\u6240\u5728\u884c\u548c\u5217\u7684\u6240\u6709\u5143\u7d20\u90fd\u8bbe\u4e3a 0 \u3002\u8bf7\u4f7f\u7528 \u539f\u5730 \u7b97\u6cd5\u3002

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u4e00\u4e2a\u76f4\u89c2\u7684\u89e3\u51b3\u65b9\u6848\u662f\u4f7f\u7528 \u00a0O(mn)\u00a0\u7684\u989d\u5916\u7a7a\u95f4\uff0c\u4f46\u8fd9\u5e76\u4e0d\u662f\u4e00\u4e2a\u597d\u7684\u89e3\u51b3\u65b9\u6848\u3002
    • \n\t
    • \u4e00\u4e2a\u7b80\u5355\u7684\u6539\u8fdb\u65b9\u6848\u662f\u4f7f\u7528 O(m\u00a0+\u00a0n) \u7684\u989d\u5916\u7a7a\u95f4\uff0c\u4f46\u8fd9\u4ecd\u7136\u4e0d\u662f\u6700\u597d\u7684\u89e3\u51b3\u65b9\u6848\u3002
    • \n\t
    • \u4f60\u80fd\u60f3\u51fa\u4e00\u4e2a\u4ec5\u4f7f\u7528\u5e38\u91cf\u7a7a\u95f4\u7684\u89e3\u51b3\u65b9\u6848\u5417\uff1f
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1amatrix = [[1,1,1],[1,0,1],[1,1,1]]\n\u8f93\u51fa\uff1a[[1,0,1],[0,0,0],[1,0,1]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1amatrix = [[0,1,2,0],[3,4,5,2],[1,3,1,5]]\n\u8f93\u51fa\uff1a[[0,0,0,0],[0,4,5,0],[0,3,1,0]]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == matrix.length
    • \n\t
    • n == matrix[0].length
    • \n\t
    • 1 <= m, n <= 200
    • \n\t
    • -231 <= matrix[i][j] <= 231 - 1
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n void setZeroes(vector>& matrix) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public void setZeroes(int[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def setZeroes(self, matrix):\n \"\"\"\n :type matrix: List[List[int]]\n :rtype: None Do not return anything, modify matrix in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def setZeroes(self, matrix: List[List[int]]) -> None:\n \"\"\"\n Do not return anything, modify matrix in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nvoid setZeroes(int** matrix, int matrixSize, int* matrixColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public void SetZeroes(int[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} matrix\n * @return {void} Do not return anything, modify matrix in-place instead.\n */\nvar setZeroes = function(matrix) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} matrix\n# @return {Void} Do not return anything, modify matrix in-place instead.\ndef set_zeroes(matrix)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func setZeroes(_ matrix: inout [[Int]]) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func setZeroes(matrix [][]int) {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def setZeroes(matrix: Array[Array[Int]]): Unit = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun setZeroes(matrix: Array): Unit {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn set_zeroes(matrix: &mut Vec>) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $matrix\n * @return NULL\n */\n function setZeroes(&$matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n Do not return anything, modify matrix in-place instead.\n */\nfunction setZeroes(matrix: number[][]): void {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0073](https://leetcode-cn.com/problems/set-matrix-zeroes)", "[\u77e9\u9635\u7f6e\u96f6](/solution/0000-0099/0073.Set%20Matrix%20Zeroes/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0073](https://leetcode.com/problems/set-matrix-zeroes)", "[Set Matrix Zeroes](/solution/0000-0099/0073.Set%20Matrix%20Zeroes/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0072", "frontend_question_id": "0072", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/edit-distance", "url_en": "https://leetcode.com/problems/edit-distance", "relative_path_cn": "/solution/0000-0099/0072.Edit%20Distance/README.md", "relative_path_en": "/solution/0000-0099/0072.Edit%20Distance/README_EN.md", "title_cn": "\u7f16\u8f91\u8ddd\u79bb", "title_en": "Edit Distance", "question_title_slug": "edit-distance", "content_en": "

    Given two strings word1 and word2, return the minimum number of operations required to convert word1 to word2.

    \n\n

    You have the following three operations permitted on a word:

    \n\n
      \n\t
    • Insert a character
    • \n\t
    • Delete a character
    • \n\t
    • Replace a character
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: word1 = "horse", word2 = "ros"\nOutput: 3\nExplanation: \nhorse -> rorse (replace 'h' with 'r')\nrorse -> rose (remove 'r')\nrose -> ros (remove 'e')\n
    \n\n

    Example 2:

    \n\n
    \nInput: word1 = "intention", word2 = "execution"\nOutput: 5\nExplanation: \nintention -> inention (remove 't')\ninention -> enention (replace 'i' with 'e')\nenention -> exention (replace 'n' with 'x')\nexention -> exection (replace 'n' with 'c')\nexection -> execution (insert 'u')\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= word1.length, word2.length <= 500
    • \n\t
    • word1 and word2 consist of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u5355\u8bcd\u00a0word1 \u548c\u00a0word2\uff0c\u8bf7\u4f60\u8ba1\u7b97\u51fa\u5c06\u00a0word1\u00a0\u8f6c\u6362\u6210\u00a0word2 \u6240\u4f7f\u7528\u7684\u6700\u5c11\u64cd\u4f5c\u6570\u00a0\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u5bf9\u4e00\u4e2a\u5355\u8bcd\u8fdb\u884c\u5982\u4e0b\u4e09\u79cd\u64cd\u4f5c\uff1a

    \n\n
      \n\t
    • \u63d2\u5165\u4e00\u4e2a\u5b57\u7b26
    • \n\t
    • \u5220\u9664\u4e00\u4e2a\u5b57\u7b26
    • \n\t
    • \u66ff\u6362\u4e00\u4e2a\u5b57\u7b26
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\u00a01\uff1a

    \n\n
    \n\u8f93\u5165\uff1aword1 = \"horse\", word2 = \"ros\"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\nhorse -> rorse (\u5c06 'h' \u66ff\u6362\u4e3a 'r')\nrorse -> rose (\u5220\u9664 'r')\nrose -> ros (\u5220\u9664 'e')\n
    \n\n

    \u793a\u4f8b\u00a02\uff1a

    \n\n
    \n\u8f93\u5165\uff1aword1 = \"intention\", word2 = \"execution\"\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\nintention -> inention (\u5220\u9664 't')\ninention -> enention (\u5c06 'i' \u66ff\u6362\u4e3a 'e')\nenention -> exention (\u5c06 'n' \u66ff\u6362\u4e3a 'x')\nexention -> exection (\u5c06 'n' \u66ff\u6362\u4e3a 'c')\nexection -> execution (\u63d2\u5165 'u')\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= word1.length, word2.length <= 500
    • \n\t
    • word1 \u548c word2 \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n", "tags_en": ["String", "Dynamic Programming"], "tags_cn": ["\u5b57\u7b26\u4e32", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minDistance(string word1, string word2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minDistance(String word1, String word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minDistance(self, word1, word2):\n \"\"\"\n :type word1: str\n :type word2: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minDistance(self, word1: str, word2: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minDistance(char * word1, char * word2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinDistance(string word1, string word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} word1\n * @param {string} word2\n * @return {number}\n */\nvar minDistance = function(word1, word2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} word1\n# @param {String} word2\n# @return {Integer}\ndef min_distance(word1, word2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minDistance(_ word1: String, _ word2: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minDistance(word1 string, word2 string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minDistance(word1: String, word2: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minDistance(word1: String, word2: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_distance(word1: String, word2: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $word1\n * @param String $word2\n * @return Integer\n */\n function minDistance($word1, $word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minDistance(word1: string, word2: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-distance word1 word2)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0072](https://leetcode-cn.com/problems/edit-distance)", "[\u7f16\u8f91\u8ddd\u79bb](/solution/0000-0099/0072.Edit%20Distance/README.md)", "`\u5b57\u7b26\u4e32`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0072](https://leetcode.com/problems/edit-distance)", "[Edit Distance](/solution/0000-0099/0072.Edit%20Distance/README_EN.md)", "`String`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0071", "frontend_question_id": "0071", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/simplify-path", "url_en": "https://leetcode.com/problems/simplify-path", "relative_path_cn": "/solution/0000-0099/0071.Simplify%20Path/README.md", "relative_path_en": "/solution/0000-0099/0071.Simplify%20Path/README_EN.md", "title_cn": "\u7b80\u5316\u8def\u5f84", "title_en": "Simplify Path", "question_title_slug": "simplify-path", "content_en": "

    Given a string path, which is an absolute path (starting with a slash '/') to a file or directory in a Unix-style file system, convert it to the simplified canonical path.

    \n\n

    In a Unix-style file system, a period '.' refers to the current directory, a double period '..' refers to the directory up a level, and any multiple consecutive slashes (i.e. '//') are treated as a single slash '/'. For this problem, any other format of periods such as '...' are treated as file/directory names.

    \n\n

    The canonical path should have the following format:

    \n\n
      \n\t
    • The path starts with a single slash '/'.
    • \n\t
    • Any two directories are separated by a single slash '/'.
    • \n\t
    • The path does not end with a trailing '/'.
    • \n\t
    • The path only contains the directories on the path from the root directory to the target file or directory (i.e., no period '.' or double period '..')
    • \n
    \n\n

    Return the simplified canonical path.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: path = "/home/"\nOutput: "/home"\nExplanation: Note that there is no trailing slash after the last directory name.\n
    \n\n

    Example 2:

    \n\n
    \nInput: path = "/../"\nOutput: "/"\nExplanation: Going one level up from the root directory is a no-op, as the root level is the highest level you can go.\n
    \n\n

    Example 3:

    \n\n
    \nInput: path = "/home//foo/"\nOutput: "/home/foo"\nExplanation: In the canonical path, multiple consecutive slashes are replaced by a single one.\n
    \n\n

    Example 4:

    \n\n
    \nInput: path = "/a/./b/../../c/"\nOutput: "/c"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= path.length <= 3000
    • \n\t
    • path consists of English letters, digits, period '.', slash '/' or '_'.
    • \n\t
    • path is a valid absolute Unix path.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 path \uff0c\u8868\u793a\u6307\u5411\u67d0\u4e00\u6587\u4ef6\u6216\u76ee\u5f55\u7684\u00a0Unix \u98ce\u683c \u7edd\u5bf9\u8def\u5f84 \uff08\u4ee5 '/' \u5f00\u5934\uff09\uff0c\u8bf7\u4f60\u5c06\u5176\u8f6c\u5316\u4e3a\u66f4\u52a0\u7b80\u6d01\u7684\u89c4\u8303\u8def\u5f84\u3002

    \n\n

    \u5728 Unix \u98ce\u683c\u7684\u6587\u4ef6\u7cfb\u7edf\u4e2d\uff0c\u4e00\u4e2a\u70b9\uff08.\uff09\u8868\u793a\u5f53\u524d\u76ee\u5f55\u672c\u8eab\uff1b\u6b64\u5916\uff0c\u4e24\u4e2a\u70b9 \uff08..\uff09\u00a0\u8868\u793a\u5c06\u76ee\u5f55\u5207\u6362\u5230\u4e0a\u4e00\u7ea7\uff08\u6307\u5411\u7236\u76ee\u5f55\uff09\uff1b\u4e24\u8005\u90fd\u53ef\u4ee5\u662f\u590d\u6742\u76f8\u5bf9\u8def\u5f84\u7684\u7ec4\u6210\u90e8\u5206\u3002\u4efb\u610f\u591a\u4e2a\u8fde\u7eed\u7684\u659c\u6760\uff08\u5373\uff0c'//'\uff09\u90fd\u88ab\u89c6\u4e3a\u5355\u4e2a\u659c\u6760 '/' \u3002 \u5bf9\u4e8e\u6b64\u95ee\u9898\uff0c\u4efb\u4f55\u5176\u4ed6\u683c\u5f0f\u7684\u70b9\uff08\u4f8b\u5982\uff0c'...'\uff09\u5747\u88ab\u89c6\u4e3a\u6587\u4ef6/\u76ee\u5f55\u540d\u79f0\u3002

    \n\n

    \u8bf7\u6ce8\u610f\uff0c\u8fd4\u56de\u7684 \u89c4\u8303\u8def\u5f84 \u5fc5\u987b\u9075\u5faa\u4e0b\u8ff0\u683c\u5f0f\uff1a

    \n\n
      \n\t
    • \u59cb\u7ec8\u4ee5\u659c\u6760 '/' \u5f00\u5934\u3002
    • \n\t
    • \u4e24\u4e2a\u76ee\u5f55\u540d\u4e4b\u95f4\u5fc5\u987b\u53ea\u6709\u4e00\u4e2a\u659c\u6760 '/' \u3002
    • \n\t
    • \u6700\u540e\u4e00\u4e2a\u76ee\u5f55\u540d\uff08\u5982\u679c\u5b58\u5728\uff09\u4e0d\u80fd \u4ee5 '/' \u7ed3\u5c3e\u3002
    • \n\t
    • \u6b64\u5916\uff0c\u8def\u5f84\u4ec5\u5305\u542b\u4ece\u6839\u76ee\u5f55\u5230\u76ee\u6807\u6587\u4ef6\u6216\u76ee\u5f55\u7684\u8def\u5f84\u4e0a\u7684\u76ee\u5f55\uff08\u5373\uff0c\u4e0d\u542b '.' \u6216 '..'\uff09\u3002
    • \n
    \n\n

    \u8fd4\u56de\u7b80\u5316\u540e\u5f97\u5230\u7684 \u89c4\u8303\u8def\u5f84 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1apath = \"/home/\"\n\u8f93\u51fa\uff1a\"/home\"\n\u89e3\u91ca\uff1a\u6ce8\u610f\uff0c\u6700\u540e\u4e00\u4e2a\u76ee\u5f55\u540d\u540e\u9762\u6ca1\u6709\u659c\u6760\u3002 
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1apath = \"/../\"\n\u8f93\u51fa\uff1a\"/\"\n\u89e3\u91ca\uff1a\u4ece\u6839\u76ee\u5f55\u5411\u4e0a\u4e00\u7ea7\u662f\u4e0d\u53ef\u884c\u7684\uff0c\u56e0\u4e3a\u6839\u76ee\u5f55\u662f\u4f60\u53ef\u4ee5\u5230\u8fbe\u7684\u6700\u9ad8\u7ea7\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1apath = \"/home//foo/\"\n\u8f93\u51fa\uff1a\"/home/foo\"\n\u89e3\u91ca\uff1a\u5728\u89c4\u8303\u8def\u5f84\u4e2d\uff0c\u591a\u4e2a\u8fde\u7eed\u659c\u6760\u9700\u8981\u7528\u4e00\u4e2a\u659c\u6760\u66ff\u6362\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1apath = \"/a/./b/../../c/\"\n\u8f93\u51fa\uff1a\"/c\"\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= path.length <= 3000
    • \n\t
    • path \u7531\u82f1\u6587\u5b57\u6bcd\uff0c\u6570\u5b57\uff0c'.'\uff0c'/' \u6216 '_' \u7ec4\u6210\u3002
    • \n\t
    • path \u662f\u4e00\u4e2a\u6709\u6548\u7684 Unix \u98ce\u683c\u7edd\u5bf9\u8def\u5f84\u3002
    • \n
    \n", "tags_en": ["Stack", "String"], "tags_cn": ["\u6808", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string simplifyPath(string path) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String simplifyPath(String path) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def simplifyPath(self, path):\n \"\"\"\n :type path: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def simplifyPath(self, path: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * simplifyPath(char * path){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string SimplifyPath(string path) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} path\n * @return {string}\n */\nvar simplifyPath = function(path) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} path\n# @return {String}\ndef simplify_path(path)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func simplifyPath(_ path: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func simplifyPath(path string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def simplifyPath(path: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun simplifyPath(path: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn simplify_path(path: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $path\n * @return String\n */\n function simplifyPath($path) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function simplifyPath(path: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (simplify-path path)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0071](https://leetcode-cn.com/problems/simplify-path)", "[\u7b80\u5316\u8def\u5f84](/solution/0000-0099/0071.Simplify%20Path/README.md)", "`\u6808`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0071](https://leetcode.com/problems/simplify-path)", "[Simplify Path](/solution/0000-0099/0071.Simplify%20Path/README_EN.md)", "`Stack`,`String`", "Medium", ""]}, {"question_id": "0070", "frontend_question_id": "0070", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/climbing-stairs", "url_en": "https://leetcode.com/problems/climbing-stairs", "relative_path_cn": "/solution/0000-0099/0070.Climbing%20Stairs/README.md", "relative_path_en": "/solution/0000-0099/0070.Climbing%20Stairs/README_EN.md", "title_cn": "\u722c\u697c\u68af", "title_en": "Climbing Stairs", "question_title_slug": "climbing-stairs", "content_en": "

    You are climbing a staircase. It takes n steps to reach the top.

    \n\n

    Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 2\nOutput: 2\nExplanation: There are two ways to climb to the top.\n1. 1 step + 1 step\n2. 2 steps\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 3\nOutput: 3\nExplanation: There are three ways to climb to the top.\n1. 1 step + 1 step + 1 step\n2. 1 step + 2 steps\n3. 2 steps + 1 step\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 45
    • \n
    \n", "content_cn": "

    \u5047\u8bbe\u4f60\u6b63\u5728\u722c\u697c\u68af\u3002\u9700\u8981 n \u9636\u4f60\u624d\u80fd\u5230\u8fbe\u697c\u9876\u3002

    \n\n

    \u6bcf\u6b21\u4f60\u53ef\u4ee5\u722c 1 \u6216 2 \u4e2a\u53f0\u9636\u3002\u4f60\u6709\u591a\u5c11\u79cd\u4e0d\u540c\u7684\u65b9\u6cd5\u53ef\u4ee5\u722c\u5230\u697c\u9876\u5462\uff1f

    \n\n

    \u6ce8\u610f\uff1a\u7ed9\u5b9a n \u662f\u4e00\u4e2a\u6b63\u6574\u6570\u3002

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a 2\n\u8f93\u51fa\uff1a 2\n\u89e3\u91ca\uff1a \u6709\u4e24\u79cd\u65b9\u6cd5\u53ef\u4ee5\u722c\u5230\u697c\u9876\u3002\n1.  1 \u9636 + 1 \u9636\n2.  2 \u9636
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a 3\n\u8f93\u51fa\uff1a 3\n\u89e3\u91ca\uff1a \u6709\u4e09\u79cd\u65b9\u6cd5\u53ef\u4ee5\u722c\u5230\u697c\u9876\u3002\n1.  1 \u9636 + 1 \u9636 + 1 \u9636\n2.  1 \u9636 + 2 \u9636\n3.  2 \u9636 + 1 \u9636\n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int climbStairs(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int climbStairs(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def climbStairs(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def climbStairs(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint climbStairs(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ClimbStairs(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar climbStairs = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef climb_stairs(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func climbStairs(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func climbStairs(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def climbStairs(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun climbStairs(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn climb_stairs(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function climbStairs($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function climbStairs(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (climb-stairs n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0070](https://leetcode-cn.com/problems/climbing-stairs)", "[\u722c\u697c\u68af](/solution/0000-0099/0070.Climbing%20Stairs/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u7b80\u5355", ""], "md_table_row_en": ["[0070](https://leetcode.com/problems/climbing-stairs)", "[Climbing Stairs](/solution/0000-0099/0070.Climbing%20Stairs/README_EN.md)", "`Dynamic Programming`", "Easy", ""]}, {"question_id": "0069", "frontend_question_id": "0069", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sqrtx", "url_en": "https://leetcode.com/problems/sqrtx", "relative_path_cn": "/solution/0000-0099/0069.Sqrt%28x%29/README.md", "relative_path_en": "/solution/0000-0099/0069.Sqrt%28x%29/README_EN.md", "title_cn": "x \u7684\u5e73\u65b9\u6839", "title_en": "Sqrt(x)", "question_title_slug": "sqrtx", "content_en": "

    Given a non-negative integer x, compute and return the square root of x.

    \n\n

    Since the return type is an integer, the decimal digits are truncated, and only the integer part of the result is returned.

    \n\n

    Note: You are not allowed to use any built-in exponent function or operator, such as pow(x, 0.5) or x ** 0.5.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: x = 4\nOutput: 2\n
    \n\n

    Example 2:

    \n\n
    \nInput: x = 8\nOutput: 2\nExplanation: The square root of 8 is 2.82842..., and since the decimal part is truncated, 2 is returned.
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= x <= 231 - 1
    • \n
    \n", "content_cn": "

    \u5b9e\u73b0 int sqrt(int x) \u51fd\u6570\u3002

    \n\n

    \u8ba1\u7b97\u5e76\u8fd4\u56de x \u7684\u5e73\u65b9\u6839\uff0c\u5176\u4e2d x \u662f\u975e\u8d1f\u6574\u6570\u3002

    \n\n

    \u7531\u4e8e\u8fd4\u56de\u7c7b\u578b\u662f\u6574\u6570\uff0c\u7ed3\u679c\u53ea\u4fdd\u7559\u6574\u6570\u7684\u90e8\u5206\uff0c\u5c0f\u6570\u90e8\u5206\u5c06\u88ab\u820d\u53bb\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: 4\n\u8f93\u51fa: 2\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: 8\n\u8f93\u51fa: 2\n\u8bf4\u660e: 8 \u7684\u5e73\u65b9\u6839\u662f 2.82842..., \n     \u7531\u4e8e\u8fd4\u56de\u7c7b\u578b\u662f\u6574\u6570\uff0c\u5c0f\u6570\u90e8\u5206\u5c06\u88ab\u820d\u53bb\u3002\n
    \n", "tags_en": ["Math", "Binary Search"], "tags_cn": ["\u6570\u5b66", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int mySqrt(int x) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int mySqrt(int x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def mySqrt(self, x):\n \"\"\"\n :type x: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def mySqrt(self, x: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint mySqrt(int x){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MySqrt(int x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} x\n * @return {number}\n */\nvar mySqrt = function(x) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} x\n# @return {Integer}\ndef my_sqrt(x)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func mySqrt(_ x: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func mySqrt(x int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def mySqrt(x: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun mySqrt(x: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn my_sqrt(x: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $x\n * @return Integer\n */\n function mySqrt($x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function mySqrt(x: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (my-sqrt x)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0069](https://leetcode-cn.com/problems/sqrtx)", "[x \u7684\u5e73\u65b9\u6839](/solution/0000-0099/0069.Sqrt%28x%29/README.md)", "`\u6570\u5b66`,`\u4e8c\u5206\u67e5\u627e`", "\u7b80\u5355", ""], "md_table_row_en": ["[0069](https://leetcode.com/problems/sqrtx)", "[Sqrt(x)](/solution/0000-0099/0069.Sqrt%28x%29/README_EN.md)", "`Math`,`Binary Search`", "Easy", ""]}, {"question_id": "0068", "frontend_question_id": "0068", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/text-justification", "url_en": "https://leetcode.com/problems/text-justification", "relative_path_cn": "/solution/0000-0099/0068.Text%20Justification/README.md", "relative_path_en": "/solution/0000-0099/0068.Text%20Justification/README_EN.md", "title_cn": "\u6587\u672c\u5de6\u53f3\u5bf9\u9f50", "title_en": "Text Justification", "question_title_slug": "text-justification", "content_en": "

    Given an array of words and a width maxWidth, format the text such that each line has exactly maxWidth characters and is fully (left and right) justified.

    \n\n

    You should pack your words in a greedy approach; that is, pack as many words as you can in each line. Pad extra spaces ' ' when necessary so that each line has exactly maxWidth characters.

    \n\n

    Extra spaces between words should be distributed as evenly as possible. If the number of spaces on a line do not divide evenly between words, the empty slots on the left will be assigned more spaces than the slots on the right.

    \n\n

    For the last line of text, it should be left justified and no extra space is inserted between words.

    \n\n

    Note:

    \n\n
      \n\t
    • A word is defined as a character sequence consisting of non-space characters only.
    • \n\t
    • Each word's length is guaranteed to be greater than 0 and not exceed maxWidth.
    • \n\t
    • The input array words contains at least one word.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: words = ["This", "is", "an", "example", "of", "text", "justification."], maxWidth = 16\nOutput:\n[\n   "This    is    an",\n   "example  of text",\n   "justification.  "\n]
    \n\n

    Example 2:

    \n\n
    \nInput: words = ["What","must","be","acknowledgment","shall","be"], maxWidth = 16\nOutput:\n[\n  "What   must   be",\n  "acknowledgment  ",\n  "shall be        "\n]\nExplanation: Note that the last line is "shall be    " instead of "shall     be", because the last line must be left-justified instead of fully-justified.\nNote that the second line is also left-justified becase it contains only one word.
    \n\n

    Example 3:

    \n\n
    \nInput: words = ["Science","is","what","we","understand","well","enough","to","explain","to","a","computer.","Art","is","everything","else","we","do"], maxWidth = 20\nOutput:\n[\n  "Science  is  what we",\n  "understand      well",\n  "enough to explain to",\n  "a  computer.  Art is",\n  "everything  else  we",\n  "do                  "\n]
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= words.length <= 300
    • \n\t
    • 1 <= words[i].length <= 20
    • \n\t
    • words[i] consists of only English letters and symbols.
    • \n\t
    • 1 <= maxWidth <= 100
    • \n\t
    • words[i].length <= maxWidth
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5355\u8bcd\u6570\u7ec4\u548c\u4e00\u4e2a\u957f\u5ea6 maxWidth\uff0c\u91cd\u65b0\u6392\u7248\u5355\u8bcd\uff0c\u4f7f\u5176\u6210\u4e3a\u6bcf\u884c\u6070\u597d\u6709 maxWidth \u4e2a\u5b57\u7b26\uff0c\u4e14\u5de6\u53f3\u4e24\u7aef\u5bf9\u9f50\u7684\u6587\u672c\u3002

    \n\n

    \u4f60\u5e94\u8be5\u4f7f\u7528“\u8d2a\u5fc3\u7b97\u6cd5”\u6765\u653e\u7f6e\u7ed9\u5b9a\u7684\u5355\u8bcd\uff1b\u4e5f\u5c31\u662f\u8bf4\uff0c\u5c3d\u53ef\u80fd\u591a\u5730\u5f80\u6bcf\u884c\u4e2d\u653e\u7f6e\u5355\u8bcd\u3002\u5fc5\u8981\u65f6\u53ef\u7528\u7a7a\u683c ' ' \u586b\u5145\uff0c\u4f7f\u5f97\u6bcf\u884c\u6070\u597d\u6709 maxWidth \u4e2a\u5b57\u7b26\u3002

    \n\n

    \u8981\u6c42\u5c3d\u53ef\u80fd\u5747\u5300\u5206\u914d\u5355\u8bcd\u95f4\u7684\u7a7a\u683c\u6570\u91cf\u3002\u5982\u679c\u67d0\u4e00\u884c\u5355\u8bcd\u95f4\u7684\u7a7a\u683c\u4e0d\u80fd\u5747\u5300\u5206\u914d\uff0c\u5219\u5de6\u4fa7\u653e\u7f6e\u7684\u7a7a\u683c\u6570\u8981\u591a\u4e8e\u53f3\u4fa7\u7684\u7a7a\u683c\u6570\u3002

    \n\n

    \u6587\u672c\u7684\u6700\u540e\u4e00\u884c\u5e94\u4e3a\u5de6\u5bf9\u9f50\uff0c\u4e14\u5355\u8bcd\u4e4b\u95f4\u4e0d\u63d2\u5165\u989d\u5916\u7684\u7a7a\u683c\u3002

    \n\n

    \u8bf4\u660e:

    \n\n
      \n\t
    • \u5355\u8bcd\u662f\u6307\u7531\u975e\u7a7a\u683c\u5b57\u7b26\u7ec4\u6210\u7684\u5b57\u7b26\u5e8f\u5217\u3002
    • \n\t
    • \u6bcf\u4e2a\u5355\u8bcd\u7684\u957f\u5ea6\u5927\u4e8e 0\uff0c\u5c0f\u4e8e\u7b49\u4e8e maxWidth\u3002
    • \n\t
    • \u8f93\u5165\u5355\u8bcd\u6570\u7ec4 words \u81f3\u5c11\u5305\u542b\u4e00\u4e2a\u5355\u8bcd\u3002
    • \n
    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165:\nwords = ["This", "is", "an", "example", "of", "text", "justification."]\nmaxWidth = 16\n\u8f93\u51fa:\n[\n   "This    is    an",\n   "example  of text",\n   "justification.  "\n]\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165:\nwords = ["What","must","be","acknowledgment","shall","be"]\nmaxWidth = 16\n\u8f93\u51fa:\n[\n  "What   must   be",\n  "acknowledgment  ",\n  "shall be        "\n]\n\u89e3\u91ca: \u6ce8\u610f\u6700\u540e\u4e00\u884c\u7684\u683c\u5f0f\u5e94\u4e3a "shall be    " \u800c\u4e0d\u662f "shall     be",\n     \u56e0\u4e3a\u6700\u540e\u4e00\u884c\u5e94\u4e3a\u5de6\u5bf9\u9f50\uff0c\u800c\u4e0d\u662f\u5de6\u53f3\u4e24\u7aef\u5bf9\u9f50\u3002       \n     \u7b2c\u4e8c\u884c\u540c\u6837\u4e3a\u5de6\u5bf9\u9f50\uff0c\u8fd9\u662f\u56e0\u4e3a\u8fd9\u884c\u53ea\u5305\u542b\u4e00\u4e2a\u5355\u8bcd\u3002\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u8f93\u5165:\nwords = ["Science","is","what","we","understand","well","enough","to","explain",\n         "to","a","computer.","Art","is","everything","else","we","do"]\nmaxWidth = 20\n\u8f93\u51fa:\n[\n  "Science  is  what we",\n  "understand      well",\n  "enough to explain to",\n  "a  computer.  Art is",\n  "everything  else  we",\n  "do                  "\n]\n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector fullJustify(vector& words, int maxWidth) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List fullJustify(String[] words, int maxWidth) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def fullJustify(self, words, maxWidth):\n \"\"\"\n :type words: List[str]\n :type maxWidth: int\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def fullJustify(self, words: List[str], maxWidth: int) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** fullJustify(char ** words, int wordsSize, int maxWidth, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList FullJustify(string[] words, int maxWidth) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @param {number} maxWidth\n * @return {string[]}\n */\nvar fullJustify = function(words, maxWidth) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @param {Integer} max_width\n# @return {String[]}\ndef full_justify(words, max_width)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func fullJustify(_ words: [String], _ maxWidth: Int) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func fullJustify(words []string, maxWidth int) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def fullJustify(words: Array[String], maxWidth: Int): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun fullJustify(words: Array, maxWidth: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn full_justify(words: Vec, max_width: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @param Integer $maxWidth\n * @return String[]\n */\n function fullJustify($words, $maxWidth) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function fullJustify(words: string[], maxWidth: number): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (full-justify words maxWidth)\n (-> (listof string?) exact-integer? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0068](https://leetcode-cn.com/problems/text-justification)", "[\u6587\u672c\u5de6\u53f3\u5bf9\u9f50](/solution/0000-0099/0068.Text%20Justification/README.md)", "`\u5b57\u7b26\u4e32`", "\u56f0\u96be", ""], "md_table_row_en": ["[0068](https://leetcode.com/problems/text-justification)", "[Text Justification](/solution/0000-0099/0068.Text%20Justification/README_EN.md)", "`String`", "Hard", ""]}, {"question_id": "0067", "frontend_question_id": "0067", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/add-binary", "url_en": "https://leetcode.com/problems/add-binary", "relative_path_cn": "/solution/0000-0099/0067.Add%20Binary/README.md", "relative_path_en": "/solution/0000-0099/0067.Add%20Binary/README_EN.md", "title_cn": "\u4e8c\u8fdb\u5236\u6c42\u548c", "title_en": "Add Binary", "question_title_slug": "add-binary", "content_en": "

    Given two binary strings a and b, return their sum as a binary string.

    \n\n

     

    \n

    Example 1:

    \n
    Input: a = \"11\", b = \"1\"\nOutput: \"100\"\n

    Example 2:

    \n
    Input: a = \"1010\", b = \"1011\"\nOutput: \"10101\"\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= a.length, b.length <= 104
    • \n\t
    • a and b consist only of '0' or '1' characters.
    • \n\t
    • Each string does not contain leading zeros except for the zero itself.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32\uff0c\u8fd4\u56de\u5b83\u4eec\u7684\u548c\uff08\u7528\u4e8c\u8fdb\u5236\u8868\u793a\uff09\u3002

    \n\n

    \u8f93\u5165\u4e3a \u975e\u7a7a \u5b57\u7b26\u4e32\u4e14\u53ea\u5305\u542b\u6570\u5b57 1 \u548c 0\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: a = "11", b = "1"\n\u8f93\u51fa: "100"
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: a = "1010", b = "1011"\n\u8f93\u51fa: "10101"
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6bcf\u4e2a\u5b57\u7b26\u4e32\u4ec5\u7531\u5b57\u7b26 '0' \u6216 '1' \u7ec4\u6210\u3002
    • \n\t
    • 1 <= a.length, b.length <= 10^4
    • \n\t
    • \u5b57\u7b26\u4e32\u5982\u679c\u4e0d\u662f "0" \uff0c\u5c31\u90fd\u4e0d\u542b\u524d\u5bfc\u96f6\u3002
    • \n
    \n", "tags_en": ["Math", "String"], "tags_cn": ["\u6570\u5b66", "\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string addBinary(string a, string b) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String addBinary(String a, String b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def addBinary(self, a, b):\n \"\"\"\n :type a: str\n :type b: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def addBinary(self, a: str, b: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * addBinary(char * a, char * b){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string AddBinary(string a, string b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} a\n * @param {string} b\n * @return {string}\n */\nvar addBinary = function(a, b) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} a\n# @param {String} b\n# @return {String}\ndef add_binary(a, b)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func addBinary(_ a: String, _ b: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func addBinary(a string, b string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def addBinary(a: String, b: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun addBinary(a: String, b: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn add_binary(a: String, b: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $a\n * @param String $b\n * @return String\n */\n function addBinary($a, $b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function addBinary(a: string, b: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (add-binary a b)\n (-> string? string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0067](https://leetcode-cn.com/problems/add-binary)", "[\u4e8c\u8fdb\u5236\u6c42\u548c](/solution/0000-0099/0067.Add%20Binary/README.md)", "`\u6570\u5b66`,`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0067](https://leetcode.com/problems/add-binary)", "[Add Binary](/solution/0000-0099/0067.Add%20Binary/README_EN.md)", "`Math`,`String`", "Easy", ""]}, {"question_id": "0066", "frontend_question_id": "0066", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/plus-one", "url_en": "https://leetcode.com/problems/plus-one", "relative_path_cn": "/solution/0000-0099/0066.Plus%20One/README.md", "relative_path_en": "/solution/0000-0099/0066.Plus%20One/README_EN.md", "title_cn": "\u52a0\u4e00", "title_en": "Plus One", "question_title_slug": "plus-one", "content_en": "

    Given a non-empty array of decimal digits representing a non-negative integer, increment one to the integer.

    \n\n

    The digits are stored such that the most significant digit is at the head of the list, and each element in the array contains a single digit.

    \n\n

    You may assume the integer does not contain any leading zero, except the number 0 itself.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: digits = [1,2,3]\nOutput: [1,2,4]\nExplanation: The array represents the integer 123.\n
    \n\n

    Example 2:

    \n\n
    \nInput: digits = [4,3,2,1]\nOutput: [4,3,2,2]\nExplanation: The array represents the integer 4321.\n
    \n\n

    Example 3:

    \n\n
    \nInput: digits = [0]\nOutput: [1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= digits.length <= 100
    • \n\t
    • 0 <= digits[i] <= 9
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u7531 \u6574\u6570 \u7ec4\u6210\u7684 \u975e\u7a7a \u6570\u7ec4\u6240\u8868\u793a\u7684\u975e\u8d1f\u6574\u6570\uff0c\u5728\u8be5\u6570\u7684\u57fa\u7840\u4e0a\u52a0\u4e00\u3002

    \n\n

    \u6700\u9ad8\u4f4d\u6570\u5b57\u5b58\u653e\u5728\u6570\u7ec4\u7684\u9996\u4f4d\uff0c \u6570\u7ec4\u4e2d\u6bcf\u4e2a\u5143\u7d20\u53ea\u5b58\u50a8\u5355\u4e2a\u6570\u5b57\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u5047\u8bbe\u9664\u4e86\u6574\u6570 0 \u4e4b\u5916\uff0c\u8fd9\u4e2a\u6574\u6570\u4e0d\u4f1a\u4ee5\u96f6\u5f00\u5934\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\u00a01\uff1a

    \n\n
    \n\u8f93\u5165\uff1adigits = [1,2,3]\n\u8f93\u51fa\uff1a[1,2,4]\n\u89e3\u91ca\uff1a\u8f93\u5165\u6570\u7ec4\u8868\u793a\u6570\u5b57 123\u3002\n
    \n\n

    \u793a\u4f8b\u00a02\uff1a

    \n\n
    \n\u8f93\u5165\uff1adigits = [4,3,2,1]\n\u8f93\u51fa\uff1a[4,3,2,2]\n\u89e3\u91ca\uff1a\u8f93\u5165\u6570\u7ec4\u8868\u793a\u6570\u5b57 4321\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1adigits = [0]\n\u8f93\u51fa\uff1a[1]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= digits.length <= 100
    • \n\t
    • 0 <= digits[i] <= 9
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector plusOne(vector& digits) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] plusOne(int[] digits) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def plusOne(self, digits):\n \"\"\"\n :type digits: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def plusOne(self, digits: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* plusOne(int* digits, int digitsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] PlusOne(int[] digits) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} digits\n * @return {number[]}\n */\nvar plusOne = function(digits) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} digits\n# @return {Integer[]}\ndef plus_one(digits)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func plusOne(_ digits: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func plusOne(digits []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def plusOne(digits: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun plusOne(digits: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn plus_one(digits: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $digits\n * @return Integer[]\n */\n function plusOne($digits) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function plusOne(digits: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (plus-one digits)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0066](https://leetcode-cn.com/problems/plus-one)", "[\u52a0\u4e00](/solution/0000-0099/0066.Plus%20One/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0066](https://leetcode.com/problems/plus-one)", "[Plus One](/solution/0000-0099/0066.Plus%20One/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0065", "frontend_question_id": "0065", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/valid-number", "url_en": "https://leetcode.com/problems/valid-number", "relative_path_cn": "/solution/0000-0099/0065.Valid%20Number/README.md", "relative_path_en": "/solution/0000-0099/0065.Valid%20Number/README_EN.md", "title_cn": "\u6709\u6548\u6570\u5b57", "title_en": "Valid Number", "question_title_slug": "valid-number", "content_en": "

    A valid number can be split up into these components (in order):

    \n\n
      \n\t
    1. A decimal number or an integer.
    2. \n\t
    3. (Optional) An 'e' or 'E', followed by an integer.
    4. \n
    \n\n

    A decimal number can be split up into these components (in order):

    \n\n
      \n\t
    1. (Optional) A sign character (either '+' or '-').
    2. \n\t
    3. One of the following formats:\n\t
        \n\t\t
      1. One or more digits, followed by a dot '.'.
      2. \n\t\t
      3. One or more digits, followed by a dot '.', followed by one or more digits.
      4. \n\t\t
      5. A dot '.', followed by one or more digits.
      6. \n\t
      \n\t
    4. \n
    \n\n

    An integer can be split up into these components (in order):

    \n\n
      \n\t
    1. (Optional) A sign character (either '+' or '-').
    2. \n\t
    3. One or more digits.
    4. \n
    \n\n

    For example, all the following are valid numbers: ["2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7", "+6e-1", "53.5e93", "-123.456e789"], while the following are not valid numbers: ["abc", "1a", "1e", "e3", "99e2.5", "--6", "-+3", "95a54e53"].

    \n\n

    Given a string s, return true if s is a valid number.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "0"\nOutput: true\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "e"\nOutput: false\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "."\nOutput: false\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = ".1"\nOutput: true\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 20
    • \n\t
    • s consists of only English letters (both uppercase and lowercase), digits (0-9), plus '+', minus '-', or dot '.'.
    • \n
    \n", "content_cn": "

    \u6709\u6548\u6570\u5b57\uff08\u6309\u987a\u5e8f\uff09\u53ef\u4ee5\u5206\u6210\u4ee5\u4e0b\u51e0\u4e2a\u90e8\u5206\uff1a

    \n\n
      \n\t
    1. \u4e00\u4e2a \u5c0f\u6570 \u6216\u8005 \u6574\u6570
    2. \n\t
    3. \uff08\u53ef\u9009\uff09\u4e00\u4e2a 'e' \u6216 'E' \uff0c\u540e\u9762\u8ddf\u7740\u4e00\u4e2a \u6574\u6570
    4. \n
    \n\n

    \u5c0f\u6570\uff08\u6309\u987a\u5e8f\uff09\u53ef\u4ee5\u5206\u6210\u4ee5\u4e0b\u51e0\u4e2a\u90e8\u5206\uff1a

    \n\n
      \n\t
    1. \uff08\u53ef\u9009\uff09\u4e00\u4e2a\u7b26\u53f7\u5b57\u7b26\uff08'+' \u6216 '-'\uff09
    2. \n\t
    3. \u4e0b\u8ff0\u683c\u5f0f\u4e4b\u4e00\uff1a\n\t
        \n\t\t
      1. \u81f3\u5c11\u4e00\u4f4d\u6570\u5b57\uff0c\u540e\u9762\u8ddf\u7740\u4e00\u4e2a\u70b9 '.'
      2. \n\t\t
      3. \u81f3\u5c11\u4e00\u4f4d\u6570\u5b57\uff0c\u540e\u9762\u8ddf\u7740\u4e00\u4e2a\u70b9 '.' \uff0c\u540e\u9762\u518d\u8ddf\u7740\u81f3\u5c11\u4e00\u4f4d\u6570\u5b57
      4. \n\t\t
      5. \u4e00\u4e2a\u70b9 '.' \uff0c\u540e\u9762\u8ddf\u7740\u81f3\u5c11\u4e00\u4f4d\u6570\u5b57
      6. \n\t
      \n\t
    4. \n
    \n\n

    \u6574\u6570\uff08\u6309\u987a\u5e8f\uff09\u53ef\u4ee5\u5206\u6210\u4ee5\u4e0b\u51e0\u4e2a\u90e8\u5206\uff1a

    \n\n
      \n\t
    1. \uff08\u53ef\u9009\uff09\u4e00\u4e2a\u7b26\u53f7\u5b57\u7b26\uff08'+' \u6216 '-'\uff09
    2. \n\t
    3. \u81f3\u5c11\u4e00\u4f4d\u6570\u5b57
    4. \n
    \n\n

    \u90e8\u5206\u6709\u6548\u6570\u5b57\u5217\u4e3e\u5982\u4e0b\uff1a

    \n\n
      \n\t
    • [\"2\", \"0089\", \"-0.1\", \"+3.14\", \"4.\", \"-.9\", \"2e10\", \"-90E3\", \"3e+7\", \"+6e-1\", \"53.5e93\", \"-123.456e789\"]
    • \n
    \n\n

    \u90e8\u5206\u65e0\u6548\u6570\u5b57\u5217\u4e3e\u5982\u4e0b\uff1a

    \n\n
      \n\t
    • [\"abc\", \"1a\", \"1e\", \"e3\", \"99e2.5\", \"--6\", \"-+3\", \"95a54e53\"]
    • \n
    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \uff0c\u5982\u679c s \u662f\u4e00\u4e2a \u6709\u6548\u6570\u5b57 \uff0c\u8bf7\u8fd4\u56de true \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"0\"\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"e\"\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \".\"\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \".1\"\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 20
    • \n\t
    • s \u4ec5\u542b\u82f1\u6587\u5b57\u6bcd\uff08\u5927\u5199\u548c\u5c0f\u5199\uff09\uff0c\u6570\u5b57\uff080-9\uff09\uff0c\u52a0\u53f7 '+' \uff0c\u51cf\u53f7 '-' \uff0c\u6216\u8005\u70b9 '.' \u3002
    • \n
    \n", "tags_en": ["Math", "String"], "tags_cn": ["\u6570\u5b66", "\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isNumber(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isNumber(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isNumber(self, s):\n \"\"\"\n :type s: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isNumber(self, s: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isNumber(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsNumber(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {boolean}\n */\nvar isNumber = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Boolean}\ndef is_number(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isNumber(_ s: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isNumber(s string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isNumber(s: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isNumber(s: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_number(s: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Boolean\n */\n function isNumber($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isNumber(s: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-number s)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0065](https://leetcode-cn.com/problems/valid-number)", "[\u6709\u6548\u6570\u5b57](/solution/0000-0099/0065.Valid%20Number/README.md)", "`\u6570\u5b66`,`\u5b57\u7b26\u4e32`", "\u56f0\u96be", ""], "md_table_row_en": ["[0065](https://leetcode.com/problems/valid-number)", "[Valid Number](/solution/0000-0099/0065.Valid%20Number/README_EN.md)", "`Math`,`String`", "Hard", ""]}, {"question_id": "0064", "frontend_question_id": "0064", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-path-sum", "url_en": "https://leetcode.com/problems/minimum-path-sum", "relative_path_cn": "/solution/0000-0099/0064.Minimum%20Path%20Sum/README.md", "relative_path_en": "/solution/0000-0099/0064.Minimum%20Path%20Sum/README_EN.md", "title_cn": "\u6700\u5c0f\u8def\u5f84\u548c", "title_en": "Minimum Path Sum", "question_title_slug": "minimum-path-sum", "content_en": "

    Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.

    \n\n

    Note: You can only move either down or right at any point in time.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: grid = [[1,3,1],[1,5,1],[4,2,1]]\nOutput: 7\nExplanation: Because the path 1 → 3 → 1 → 1 → 1 minimizes the sum.\n
    \n\n

    Example 2:

    \n\n
    \nInput: grid = [[1,2,3],[4,5,6]]\nOutput: 12\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= m, n <= 200
    • \n\t
    • 0 <= grid[i][j] <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5305\u542b\u975e\u8d1f\u6574\u6570\u7684 m\u00a0x\u00a0n\u00a0\u7f51\u683c\u00a0grid \uff0c\u8bf7\u627e\u51fa\u4e00\u6761\u4ece\u5de6\u4e0a\u89d2\u5230\u53f3\u4e0b\u89d2\u7684\u8def\u5f84\uff0c\u4f7f\u5f97\u8def\u5f84\u4e0a\u7684\u6570\u5b57\u603b\u548c\u4e3a\u6700\u5c0f\u3002

    \n\n

    \u8bf4\u660e\uff1a\u6bcf\u6b21\u53ea\u80fd\u5411\u4e0b\u6216\u8005\u5411\u53f3\u79fb\u52a8\u4e00\u6b65\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1agrid = [[1,3,1],[1,5,1],[4,2,1]]\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\u56e0\u4e3a\u8def\u5f84 1\u21923\u21921\u21921\u21921 \u7684\u603b\u548c\u6700\u5c0f\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1agrid = [[1,2,3],[4,5,6]]\n\u8f93\u51fa\uff1a12\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= m, n <= 200
    • \n\t
    • 0 <= grid[i][j] <= 100
    • \n
    \n", "tags_en": ["Array", "Dynamic Programming"], "tags_cn": ["\u6570\u7ec4", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minPathSum(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minPathSum(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minPathSum(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minPathSum(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minPathSum(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinPathSum(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar minPathSum = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef min_path_sum(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minPathSum(_ grid: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minPathSum(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minPathSum(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minPathSum(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_path_sum(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function minPathSum($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minPathSum(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-path-sum grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0064](https://leetcode-cn.com/problems/minimum-path-sum)", "[\u6700\u5c0f\u8def\u5f84\u548c](/solution/0000-0099/0064.Minimum%20Path%20Sum/README.md)", "`\u6570\u7ec4`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0064](https://leetcode.com/problems/minimum-path-sum)", "[Minimum Path Sum](/solution/0000-0099/0064.Minimum%20Path%20Sum/README_EN.md)", "`Array`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0063", "frontend_question_id": "0063", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/unique-paths-ii", "url_en": "https://leetcode.com/problems/unique-paths-ii", "relative_path_cn": "/solution/0000-0099/0063.Unique%20Paths%20II/README.md", "relative_path_en": "/solution/0000-0099/0063.Unique%20Paths%20II/README_EN.md", "title_cn": "\u4e0d\u540c\u8def\u5f84 II", "title_en": "Unique Paths II", "question_title_slug": "unique-paths-ii", "content_en": "

    A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).

    \n\n

    The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).

    \n\n

    Now consider if some obstacles are added to the grids. How many unique paths would there be?

    \n\n

    An obstacle and space is marked as 1 and 0 respectively in the grid.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: obstacleGrid = [[0,0,0],[0,1,0],[0,0,0]]\nOutput: 2\nExplanation: There is one obstacle in the middle of the 3x3 grid above.\nThere are two ways to reach the bottom-right corner:\n1. Right -> Right -> Down -> Down\n2. Down -> Down -> Right -> Right\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: obstacleGrid = [[0,1],[0,0]]\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == obstacleGrid.length
    • \n\t
    • n == obstacleGrid[i].length
    • \n\t
    • 1 <= m, n <= 100
    • \n\t
    • obstacleGrid[i][j] is 0 or 1.
    • \n
    \n", "content_cn": "

    \u4e00\u4e2a\u673a\u5668\u4eba\u4f4d\u4e8e\u4e00\u4e2a m x n \u7f51\u683c\u7684\u5de6\u4e0a\u89d2 \uff08\u8d77\u59cb\u70b9\u5728\u4e0b\u56fe\u4e2d\u6807\u8bb0\u4e3a\u201cStart\u201d \uff09\u3002

    \n\n

    \u673a\u5668\u4eba\u6bcf\u6b21\u53ea\u80fd\u5411\u4e0b\u6216\u8005\u5411\u53f3\u79fb\u52a8\u4e00\u6b65\u3002\u673a\u5668\u4eba\u8bd5\u56fe\u8fbe\u5230\u7f51\u683c\u7684\u53f3\u4e0b\u89d2\uff08\u5728\u4e0b\u56fe\u4e2d\u6807\u8bb0\u4e3a\u201cFinish\u201d\uff09\u3002

    \n\n

    \u73b0\u5728\u8003\u8651\u7f51\u683c\u4e2d\u6709\u969c\u788d\u7269\u3002\u90a3\u4e48\u4ece\u5de6\u4e0a\u89d2\u5230\u53f3\u4e0b\u89d2\u5c06\u4f1a\u6709\u591a\u5c11\u6761\u4e0d\u540c\u7684\u8def\u5f84\uff1f

    \n\n

    \n\n

    \u7f51\u683c\u4e2d\u7684\u969c\u788d\u7269\u548c\u7a7a\u4f4d\u7f6e\u5206\u522b\u7528 1 \u548c 0 \u6765\u8868\u793a\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aobstacleGrid = [[0,0,0],[0,1,0],[0,0,0]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n3x3 \u7f51\u683c\u7684\u6b63\u4e2d\u95f4\u6709\u4e00\u4e2a\u969c\u788d\u7269\u3002\n\u4ece\u5de6\u4e0a\u89d2\u5230\u53f3\u4e0b\u89d2\u4e00\u5171\u6709 2 \u6761\u4e0d\u540c\u7684\u8def\u5f84\uff1a\n1. \u5411\u53f3 -> \u5411\u53f3 -> \u5411\u4e0b -> \u5411\u4e0b\n2. \u5411\u4e0b -> \u5411\u4e0b -> \u5411\u53f3 -> \u5411\u53f3\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aobstacleGrid = [[0,1],[0,0]]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m ==\u00a0obstacleGrid.length
    • \n\t
    • n ==\u00a0obstacleGrid[i].length
    • \n\t
    • 1 <= m, n <= 100
    • \n\t
    • obstacleGrid[i][j] \u4e3a 0 \u6216 1
    • \n
    \n", "tags_en": ["Array", "Dynamic Programming"], "tags_cn": ["\u6570\u7ec4", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int uniquePathsWithObstacles(vector>& obstacleGrid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int uniquePathsWithObstacles(int[][] obstacleGrid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def uniquePathsWithObstacles(self, obstacleGrid):\n \"\"\"\n :type obstacleGrid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def uniquePathsWithObstacles(self, obstacleGrid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint uniquePathsWithObstacles(int** obstacleGrid, int obstacleGridSize, int* obstacleGridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int UniquePathsWithObstacles(int[][] obstacleGrid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} obstacleGrid\n * @return {number}\n */\nvar uniquePathsWithObstacles = function(obstacleGrid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} obstacle_grid\n# @return {Integer}\ndef unique_paths_with_obstacles(obstacle_grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func uniquePathsWithObstacles(_ obstacleGrid: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func uniquePathsWithObstacles(obstacleGrid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def uniquePathsWithObstacles(obstacleGrid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun uniquePathsWithObstacles(obstacleGrid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn unique_paths_with_obstacles(obstacle_grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $obstacleGrid\n * @return Integer\n */\n function uniquePathsWithObstacles($obstacleGrid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function uniquePathsWithObstacles(obstacleGrid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (unique-paths-with-obstacles obstacleGrid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0063](https://leetcode-cn.com/problems/unique-paths-ii)", "[\u4e0d\u540c\u8def\u5f84 II](/solution/0000-0099/0063.Unique%20Paths%20II/README.md)", "`\u6570\u7ec4`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0063](https://leetcode.com/problems/unique-paths-ii)", "[Unique Paths II](/solution/0000-0099/0063.Unique%20Paths%20II/README_EN.md)", "`Array`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0062", "frontend_question_id": "0062", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/unique-paths", "url_en": "https://leetcode.com/problems/unique-paths", "relative_path_cn": "/solution/0000-0099/0062.Unique%20Paths/README.md", "relative_path_en": "/solution/0000-0099/0062.Unique%20Paths/README_EN.md", "title_cn": "\u4e0d\u540c\u8def\u5f84", "title_en": "Unique Paths", "question_title_slug": "unique-paths", "content_en": "

    A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).

    \n\n

    The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).

    \n\n

    How many possible unique paths are there?

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: m = 3, n = 7\nOutput: 28\n
    \n\n

    Example 2:

    \n\n
    \nInput: m = 3, n = 2\nOutput: 3\nExplanation:\nFrom the top-left corner, there are a total of 3 ways to reach the bottom-right corner:\n1. Right -> Down -> Down\n2. Down -> Down -> Right\n3. Down -> Right -> Down\n
    \n\n

    Example 3:

    \n\n
    \nInput: m = 7, n = 3\nOutput: 28\n
    \n\n

    Example 4:

    \n\n
    \nInput: m = 3, n = 3\nOutput: 6\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= m, n <= 100
    • \n\t
    • It's guaranteed that the answer will be less than or equal to 2 * 109.
    • \n
    \n", "content_cn": "

    \u4e00\u4e2a\u673a\u5668\u4eba\u4f4d\u4e8e\u4e00\u4e2a m x n\u00a0\u7f51\u683c\u7684\u5de6\u4e0a\u89d2 \uff08\u8d77\u59cb\u70b9\u5728\u4e0b\u56fe\u4e2d\u6807\u8bb0\u4e3a \u201cStart\u201d \uff09\u3002

    \n\n

    \u673a\u5668\u4eba\u6bcf\u6b21\u53ea\u80fd\u5411\u4e0b\u6216\u8005\u5411\u53f3\u79fb\u52a8\u4e00\u6b65\u3002\u673a\u5668\u4eba\u8bd5\u56fe\u8fbe\u5230\u7f51\u683c\u7684\u53f3\u4e0b\u89d2\uff08\u5728\u4e0b\u56fe\u4e2d\u6807\u8bb0\u4e3a \u201cFinish\u201d \uff09\u3002

    \n\n

    \u95ee\u603b\u5171\u6709\u591a\u5c11\u6761\u4e0d\u540c\u7684\u8def\u5f84\uff1f

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1am = 3, n = 7\n\u8f93\u51fa\uff1a28
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1am = 3, n = 2\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\n\u4ece\u5de6\u4e0a\u89d2\u5f00\u59cb\uff0c\u603b\u5171\u6709 3 \u6761\u8def\u5f84\u53ef\u4ee5\u5230\u8fbe\u53f3\u4e0b\u89d2\u3002\n1. \u5411\u53f3 -> \u5411\u4e0b -> \u5411\u4e0b\n2. \u5411\u4e0b -> \u5411\u4e0b -> \u5411\u53f3\n3. \u5411\u4e0b -> \u5411\u53f3 -> \u5411\u4e0b\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1am = 7, n = 3\n\u8f93\u51fa\uff1a28\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1am = 3, n = 3\n\u8f93\u51fa\uff1a6
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= m, n <= 100
    • \n\t
    • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u7b54\u6848\u5c0f\u4e8e\u7b49\u4e8e 2 * 109
    • \n
    \n", "tags_en": ["Array", "Dynamic Programming"], "tags_cn": ["\u6570\u7ec4", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int uniquePaths(int m, int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int uniquePaths(int m, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def uniquePaths(self, m, n):\n \"\"\"\n :type m: int\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def uniquePaths(self, m: int, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint uniquePaths(int m, int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int UniquePaths(int m, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} m\n * @param {number} n\n * @return {number}\n */\nvar uniquePaths = function(m, n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} m\n# @param {Integer} n\n# @return {Integer}\ndef unique_paths(m, n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func uniquePaths(_ m: Int, _ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func uniquePaths(m int, n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def uniquePaths(m: Int, n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun uniquePaths(m: Int, n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn unique_paths(m: i32, n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $m\n * @param Integer $n\n * @return Integer\n */\n function uniquePaths($m, $n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function uniquePaths(m: number, n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (unique-paths m n)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0062](https://leetcode-cn.com/problems/unique-paths)", "[\u4e0d\u540c\u8def\u5f84](/solution/0000-0099/0062.Unique%20Paths/README.md)", "`\u6570\u7ec4`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0062](https://leetcode.com/problems/unique-paths)", "[Unique Paths](/solution/0000-0099/0062.Unique%20Paths/README_EN.md)", "`Array`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0061", "frontend_question_id": "0061", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/rotate-list", "url_en": "https://leetcode.com/problems/rotate-list", "relative_path_cn": "/solution/0000-0099/0061.Rotate%20List/README.md", "relative_path_en": "/solution/0000-0099/0061.Rotate%20List/README_EN.md", "title_cn": "\u65cb\u8f6c\u94fe\u8868", "title_en": "Rotate List", "question_title_slug": "rotate-list", "content_en": "

    Given the head of a linked list, rotate the list to the right by k places.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: head = [1,2,3,4,5], k = 2\nOutput: [4,5,1,2,3]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: head = [0,1,2], k = 4\nOutput: [2,0,1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the list is in the range [0, 500].
    • \n\t
    • -100 <= Node.val <= 100
    • \n\t
    • 0 <= k <= 2 * 109
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u94fe\u8868\u7684\u5934\u8282\u70b9 head \uff0c\u65cb\u8f6c\u94fe\u8868\uff0c\u5c06\u94fe\u8868\u6bcf\u4e2a\u8282\u70b9\u5411\u53f3\u79fb\u52a8\u00a0k\u00a0\u4e2a\u4f4d\u7f6e\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1ahead = [1,2,3,4,5], k = 2\n\u8f93\u51fa\uff1a[4,5,1,2,3]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1ahead = [0,1,2], k = 4\n\u8f93\u51fa\uff1a[2,0,1]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u94fe\u8868\u4e2d\u8282\u70b9\u7684\u6570\u76ee\u5728\u8303\u56f4 [0, 500] \u5185
    • \n\t
    • -100 <= Node.val <= 100
    • \n\t
    • 0 <= k <= 2 * 109
    • \n
    \n", "tags_en": ["Linked List", "Two Pointers"], "tags_cn": ["\u94fe\u8868", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n ListNode* rotateRight(ListNode* head, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public ListNode rotateRight(ListNode head, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def rotateRight(self, head, k):\n \"\"\"\n :type head: ListNode\n :type k: int\n :rtype: ListNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def rotateRight(self, head: ListNode, k: int) -> ListNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nstruct ListNode* rotateRight(struct ListNode* head, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public ListNode RotateRight(ListNode head, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} head\n * @param {number} k\n * @return {ListNode}\n */\nvar rotateRight = function(head, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode} head\n# @param {Integer} k\n# @return {ListNode}\ndef rotate_right(head, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func rotateRight(_ head: ListNode?, _ k: Int) -> ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc rotateRight(head *ListNode, k int) *ListNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def rotateRight(head: ListNode, k: Int): ListNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun rotateRight(head: ListNode?, k: Int): ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn rotate_right(head: Option>, k: i32) -> Option> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @param Integer $k\n * @return ListNode\n */\n function rotateRight($head, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction rotateRight(head: ListNode | null, k: number): ListNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (rotate-right head k)\n (-> (or/c list-node? #f) exact-integer? (or/c list-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0061](https://leetcode-cn.com/problems/rotate-list)", "[\u65cb\u8f6c\u94fe\u8868](/solution/0000-0099/0061.Rotate%20List/README.md)", "`\u94fe\u8868`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0061](https://leetcode.com/problems/rotate-list)", "[Rotate List](/solution/0000-0099/0061.Rotate%20List/README_EN.md)", "`Linked List`,`Two Pointers`", "Medium", ""]}, {"question_id": "0060", "frontend_question_id": "0060", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/permutation-sequence", "url_en": "https://leetcode.com/problems/permutation-sequence", "relative_path_cn": "/solution/0000-0099/0060.Permutation%20Sequence/README.md", "relative_path_en": "/solution/0000-0099/0060.Permutation%20Sequence/README_EN.md", "title_cn": "\u6392\u5217\u5e8f\u5217", "title_en": "Permutation Sequence", "question_title_slug": "permutation-sequence", "content_en": "

    The set [1, 2, 3, ..., n] contains a total of n! unique permutations.

    \n\n

    By listing and labeling all of the permutations in order, we get the following sequence for n = 3:

    \n\n
      \n\t
    1. "123"
    2. \n\t
    3. "132"
    4. \n\t
    5. "213"
    6. \n\t
    7. "231"
    8. \n\t
    9. "312"
    10. \n\t
    11. "321"
    12. \n
    \n\n

    Given n and k, return the kth permutation sequence.

    \n\n

     

    \n

    Example 1:

    \n
    Input: n = 3, k = 3\nOutput: \"213\"\n

    Example 2:

    \n
    Input: n = 4, k = 9\nOutput: \"2314\"\n

    Example 3:

    \n
    Input: n = 3, k = 1\nOutput: \"123\"\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 9
    • \n\t
    • 1 <= k <= n!
    • \n
    \n", "content_cn": "

    \u7ed9\u51fa\u96c6\u5408\u00a0[1,2,3,...,n]\uff0c\u5176\u6240\u6709\u5143\u7d20\u5171\u6709\u00a0n! \u79cd\u6392\u5217\u3002

    \n\n

    \u6309\u5927\u5c0f\u987a\u5e8f\u5217\u51fa\u6240\u6709\u6392\u5217\u60c5\u51b5\uff0c\u5e76\u4e00\u4e00\u6807\u8bb0\uff0c\u5f53\u00a0n = 3 \u65f6, \u6240\u6709\u6392\u5217\u5982\u4e0b\uff1a

    \n\n
      \n\t
    1. \"123\"
    2. \n\t
    3. \"132\"
    4. \n\t
    5. \"213\"
    6. \n\t
    7. \"231\"
    8. \n\t
    9. \"312\"
    10. \n\t
    11. \"321\"
    12. \n
    \n\n

    \u7ed9\u5b9a\u00a0n \u548c\u00a0k\uff0c\u8fd4\u56de\u7b2c\u00a0k\u00a0\u4e2a\u6392\u5217\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 3, k = 3\n\u8f93\u51fa\uff1a\"213\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 4, k = 9\n\u8f93\u51fa\uff1a\"2314\"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 3, k = 1\n\u8f93\u51fa\uff1a\"123\"\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 9
    • \n\t
    • 1 <= k <= n!
    • \n
    \n", "tags_en": ["Math", "Backtracking"], "tags_cn": ["\u6570\u5b66", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string getPermutation(int n, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String getPermutation(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getPermutation(self, n, k):\n \"\"\"\n :type n: int\n :type k: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getPermutation(self, n: int, k: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * getPermutation(int n, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string GetPermutation(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} k\n * @return {string}\n */\nvar getPermutation = function(n, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} k\n# @return {String}\ndef get_permutation(n, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getPermutation(_ n: Int, _ k: Int) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getPermutation(n int, k int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getPermutation(n: Int, k: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getPermutation(n: Int, k: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_permutation(n: i32, k: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $k\n * @return String\n */\n function getPermutation($n, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getPermutation(n: number, k: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-permutation n k)\n (-> exact-integer? exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0060](https://leetcode-cn.com/problems/permutation-sequence)", "[\u6392\u5217\u5e8f\u5217](/solution/0000-0099/0060.Permutation%20Sequence/README.md)", "`\u6570\u5b66`,`\u56de\u6eaf\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[0060](https://leetcode.com/problems/permutation-sequence)", "[Permutation Sequence](/solution/0000-0099/0060.Permutation%20Sequence/README_EN.md)", "`Math`,`Backtracking`", "Hard", ""]}, {"question_id": "0059", "frontend_question_id": "0059", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/spiral-matrix-ii", "url_en": "https://leetcode.com/problems/spiral-matrix-ii", "relative_path_cn": "/solution/0000-0099/0059.Spiral%20Matrix%20II/README.md", "relative_path_en": "/solution/0000-0099/0059.Spiral%20Matrix%20II/README_EN.md", "title_cn": "\u87ba\u65cb\u77e9\u9635 II", "title_en": "Spiral Matrix II", "question_title_slug": "spiral-matrix-ii", "content_en": "

    Given a positive integer n, generate an n x n matrix filled with elements from 1 to n2 in spiral order.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: n = 3\nOutput: [[1,2,3],[8,9,4],[7,6,5]]\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 1\nOutput: [[1]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 20
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6b63\u6574\u6570\u00a0n \uff0c\u751f\u6210\u4e00\u4e2a\u5305\u542b 1 \u5230\u00a0n2\u00a0\u6240\u6709\u5143\u7d20\uff0c\u4e14\u5143\u7d20\u6309\u987a\u65f6\u9488\u987a\u5e8f\u87ba\u65cb\u6392\u5217\u7684\u00a0n x n \u6b63\u65b9\u5f62\u77e9\u9635 matrix \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1an = 3\n\u8f93\u51fa\uff1a[[1,2,3],[8,9,4],[7,6,5]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1a[[1]]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 20
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> generateMatrix(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[][] generateMatrix(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def generateMatrix(self, n):\n \"\"\"\n :type n: int\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def generateMatrix(self, n: int) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** generateMatrix(int n, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[][] GenerateMatrix(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number[][]}\n */\nvar generateMatrix = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer[][]}\ndef generate_matrix(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func generateMatrix(_ n: Int) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func generateMatrix(n int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def generateMatrix(n: Int): Array[Array[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun generateMatrix(n: Int): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn generate_matrix(n: i32) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer[][]\n */\n function generateMatrix($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function generateMatrix(n: number): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (generate-matrix n)\n (-> exact-integer? (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0059](https://leetcode-cn.com/problems/spiral-matrix-ii)", "[\u87ba\u65cb\u77e9\u9635 II](/solution/0000-0099/0059.Spiral%20Matrix%20II/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0059](https://leetcode.com/problems/spiral-matrix-ii)", "[Spiral Matrix II](/solution/0000-0099/0059.Spiral%20Matrix%20II/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0058", "frontend_question_id": "0058", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/length-of-last-word", "url_en": "https://leetcode.com/problems/length-of-last-word", "relative_path_cn": "/solution/0000-0099/0058.Length%20of%20Last%20Word/README.md", "relative_path_en": "/solution/0000-0099/0058.Length%20of%20Last%20Word/README_EN.md", "title_cn": "\u6700\u540e\u4e00\u4e2a\u5355\u8bcd\u7684\u957f\u5ea6", "title_en": "Length of Last Word", "question_title_slug": "length-of-last-word", "content_en": "

    Given a string s consists of some words separated by spaces, return the length of the last word in the string. If the last word does not exist, return 0.

    \n\n

    A word is a maximal substring consisting of non-space characters only.

    \n\n

     

    \n

    Example 1:

    \n
    Input: s = \"Hello World\"\nOutput: 5\n

    Example 2:

    \n
    Input: s = \" \"\nOutput: 0\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 104
    • \n\t
    • s consists of only English letters and spaces ' '.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s\uff0c\u7531\u82e5\u5e72\u5355\u8bcd\u7ec4\u6210\uff0c\u5355\u8bcd\u4e4b\u95f4\u7528\u7a7a\u683c\u9694\u5f00\u3002\u8fd4\u56de\u5b57\u7b26\u4e32\u4e2d\u6700\u540e\u4e00\u4e2a\u5355\u8bcd\u7684\u957f\u5ea6\u3002\u5982\u679c\u4e0d\u5b58\u5728\u6700\u540e\u4e00\u4e2a\u5355\u8bcd\uff0c\u8bf7\u8fd4\u56de 0\u00a0\u3002

    \n\n

    \u5355\u8bcd \u662f\u6307\u4ec5\u7531\u5b57\u6bcd\u7ec4\u6210\u3001\u4e0d\u5305\u542b\u4efb\u4f55\u7a7a\u683c\u5b57\u7b26\u7684\u6700\u5927\u5b50\u5b57\u7b26\u4e32\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"Hello World\"\n\u8f93\u51fa\uff1a5\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \" \"\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 104
    • \n\t
    • s \u4ec5\u6709\u82f1\u6587\u5b57\u6bcd\u548c\u7a7a\u683c ' ' \u7ec4\u6210
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int lengthOfLastWord(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int lengthOfLastWord(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def lengthOfLastWord(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def lengthOfLastWord(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint lengthOfLastWord(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LengthOfLastWord(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar lengthOfLastWord = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef length_of_last_word(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func lengthOfLastWord(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func lengthOfLastWord(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def lengthOfLastWord(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun lengthOfLastWord(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn length_of_last_word(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function lengthOfLastWord($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function lengthOfLastWord(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (length-of-last-word s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0058](https://leetcode-cn.com/problems/length-of-last-word)", "[\u6700\u540e\u4e00\u4e2a\u5355\u8bcd\u7684\u957f\u5ea6](/solution/0000-0099/0058.Length%20of%20Last%20Word/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0058](https://leetcode.com/problems/length-of-last-word)", "[Length of Last Word](/solution/0000-0099/0058.Length%20of%20Last%20Word/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "0057", "frontend_question_id": "0057", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/insert-interval", "url_en": "https://leetcode.com/problems/insert-interval", "relative_path_cn": "/solution/0000-0099/0057.Insert%20Interval/README.md", "relative_path_en": "/solution/0000-0099/0057.Insert%20Interval/README_EN.md", "title_cn": "\u63d2\u5165\u533a\u95f4", "title_en": "Insert Interval", "question_title_slug": "insert-interval", "content_en": "

    Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).

    \n\n

    You may assume that the intervals were initially sorted according to their start times.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: intervals = [[1,3],[6,9]], newInterval = [2,5]\nOutput: [[1,5],[6,9]]\n
    \n\n

    Example 2:

    \n\n
    \nInput: intervals = [[1,2],[3,5],[6,7],[8,10],[12,16]], newInterval = [4,8]\nOutput: [[1,2],[3,10],[12,16]]\nExplanation: Because the new interval [4,8] overlaps with [3,5],[6,7],[8,10].
    \n\n

    Example 3:

    \n\n
    \nInput: intervals = [], newInterval = [5,7]\nOutput: [[5,7]]\n
    \n\n

    Example 4:

    \n\n
    \nInput: intervals = [[1,5]], newInterval = [2,3]\nOutput: [[1,5]]\n
    \n\n

    Example 5:

    \n\n
    \nInput: intervals = [[1,5]], newInterval = [2,7]\nOutput: [[1,7]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= intervals.length <= 104
    • \n\t
    • intervals[i].length == 2
    • \n\t
    • 0 <= intervals[i][0] <= intervals[i][1] <= 105
    • \n\t
    • intervals is sorted by intervals[i][0] in ascending order.
    • \n\t
    • newInterval.length == 2
    • \n\t
    • 0 <= newInterval[0] <= newInterval[1] <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a \u65e0\u91cd\u53e0\u7684 \uff0c\u6309\u7167\u533a\u95f4\u8d77\u59cb\u7aef\u70b9\u6392\u5e8f\u7684\u533a\u95f4\u5217\u8868\u3002

    \n\n

    \u5728\u5217\u8868\u4e2d\u63d2\u5165\u4e00\u4e2a\u65b0\u7684\u533a\u95f4\uff0c\u4f60\u9700\u8981\u786e\u4fdd\u5217\u8868\u4e2d\u7684\u533a\u95f4\u4ecd\u7136\u6709\u5e8f\u4e14\u4e0d\u91cd\u53e0\uff08\u5982\u679c\u6709\u5fc5\u8981\u7684\u8bdd\uff0c\u53ef\u4ee5\u5408\u5e76\u533a\u95f4\uff09\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\u00a01\uff1a

    \n\n
    \n\u8f93\u5165\uff1aintervals = [[1,3],[6,9]], newInterval = [2,5]\n\u8f93\u51fa\uff1a[[1,5],[6,9]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aintervals = [[1,2],[3,5],[6,7],[8,10],[12,16]], newInterval = [4,8]\n\u8f93\u51fa\uff1a[[1,2],[3,10],[12,16]]\n\u89e3\u91ca\uff1a\u8fd9\u662f\u56e0\u4e3a\u65b0\u7684\u533a\u95f4 [4,8] \u4e0e [3,5],[6,7],[8,10]\u00a0\u91cd\u53e0\u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aintervals = [], newInterval = [5,7]\n\u8f93\u51fa\uff1a[[5,7]]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1aintervals = [[1,5]], newInterval = [2,3]\n\u8f93\u51fa\uff1a[[1,5]]\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1aintervals = [[1,5]], newInterval = [2,7]\n\u8f93\u51fa\uff1a[[1,7]]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= intervals.length <= 104
    • \n\t
    • intervals[i].length == 2
    • \n\t
    • 0 <=\u00a0intervals[i][0] <=\u00a0intervals[i][1] <= 105
    • \n\t
    • intervals \u6839\u636e intervals[i][0] \u6309 \u5347\u5e8f \u6392\u5217
    • \n\t
    • newInterval.length == 2
    • \n\t
    • 0 <=\u00a0newInterval[0] <=\u00a0newInterval[1] <= 105
    • \n
    \n", "tags_en": ["Sort", "Array"], "tags_cn": ["\u6392\u5e8f", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> insert(vector>& intervals, vector& newInterval) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[][] insert(int[][] intervals, int[] newInterval) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def insert(self, intervals, newInterval):\n \"\"\"\n :type intervals: List[List[int]]\n :type newInterval: List[int]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def insert(self, intervals: List[List[int]], newInterval: List[int]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** insert(int** intervals, int intervalsSize, int* intervalsColSize, int* newInterval, int newIntervalSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[][] Insert(int[][] intervals, int[] newInterval) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} intervals\n * @param {number[]} newInterval\n * @return {number[][]}\n */\nvar insert = function(intervals, newInterval) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} intervals\n# @param {Integer[]} new_interval\n# @return {Integer[][]}\ndef insert(intervals, new_interval)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func insert(_ intervals: [[Int]], _ newInterval: [Int]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func insert(intervals [][]int, newInterval []int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def insert(intervals: Array[Array[Int]], newInterval: Array[Int]): Array[Array[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun insert(intervals: Array, newInterval: IntArray): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn insert(intervals: Vec>, new_interval: Vec) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $intervals\n * @param Integer[] $newInterval\n * @return Integer[][]\n */\n function insert($intervals, $newInterval) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function insert(intervals: number[][], newInterval: number[]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (insert intervals newInterval)\n (-> (listof (listof exact-integer?)) (listof exact-integer?) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0057](https://leetcode-cn.com/problems/insert-interval)", "[\u63d2\u5165\u533a\u95f4](/solution/0000-0099/0057.Insert%20Interval/README.md)", "`\u6392\u5e8f`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0057](https://leetcode.com/problems/insert-interval)", "[Insert Interval](/solution/0000-0099/0057.Insert%20Interval/README_EN.md)", "`Sort`,`Array`", "Medium", ""]}, {"question_id": "0056", "frontend_question_id": "0056", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/merge-intervals", "url_en": "https://leetcode.com/problems/merge-intervals", "relative_path_cn": "/solution/0000-0099/0056.Merge%20Intervals/README.md", "relative_path_en": "/solution/0000-0099/0056.Merge%20Intervals/README_EN.md", "title_cn": "\u5408\u5e76\u533a\u95f4", "title_en": "Merge Intervals", "question_title_slug": "merge-intervals", "content_en": "

    Given an array of intervals where intervals[i] = [starti, endi], merge all overlapping intervals, and return an array of the non-overlapping intervals that cover all the intervals in the input.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: intervals = [[1,3],[2,6],[8,10],[15,18]]\nOutput: [[1,6],[8,10],[15,18]]\nExplanation: Since intervals [1,3] and [2,6] overlaps, merge them into [1,6].\n
    \n\n

    Example 2:

    \n\n
    \nInput: intervals = [[1,4],[4,5]]\nOutput: [[1,5]]\nExplanation: Intervals [1,4] and [4,5] are considered overlapping.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= intervals.length <= 104
    • \n\t
    • intervals[i].length == 2
    • \n\t
    • 0 <= starti <= endi <= 104
    • \n
    \n", "content_cn": "

    \u4ee5\u6570\u7ec4 intervals \u8868\u793a\u82e5\u5e72\u4e2a\u533a\u95f4\u7684\u96c6\u5408\uff0c\u5176\u4e2d\u5355\u4e2a\u533a\u95f4\u4e3a intervals[i] = [starti, endi] \u3002\u8bf7\u4f60\u5408\u5e76\u6240\u6709\u91cd\u53e0\u7684\u533a\u95f4\uff0c\u5e76\u8fd4\u56de\u4e00\u4e2a\u4e0d\u91cd\u53e0\u7684\u533a\u95f4\u6570\u7ec4\uff0c\u8be5\u6570\u7ec4\u9700\u6070\u597d\u8986\u76d6\u8f93\u5165\u4e2d\u7684\u6240\u6709\u533a\u95f4\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aintervals = [[1,3],[2,6],[8,10],[15,18]]\n\u8f93\u51fa\uff1a[[1,6],[8,10],[15,18]]\n\u89e3\u91ca\uff1a\u533a\u95f4 [1,3] \u548c [2,6] \u91cd\u53e0, \u5c06\u5b83\u4eec\u5408\u5e76\u4e3a [1,6].\n
    \n\n

    \u793a\u4f8b\u00a02\uff1a

    \n\n
    \n\u8f93\u5165\uff1aintervals = [[1,4],[4,5]]\n\u8f93\u51fa\uff1a[[1,5]]\n\u89e3\u91ca\uff1a\u533a\u95f4 [1,4] \u548c [4,5] \u53ef\u88ab\u89c6\u4e3a\u91cd\u53e0\u533a\u95f4\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= intervals.length <= 104
    • \n\t
    • intervals[i].length == 2
    • \n\t
    • 0 <= starti <= endi <= 104
    • \n
    \n", "tags_en": ["Sort", "Array"], "tags_cn": ["\u6392\u5e8f", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> merge(vector>& intervals) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[][] merge(int[][] intervals) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def merge(self, intervals):\n \"\"\"\n :type intervals: List[List[int]]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def merge(self, intervals: List[List[int]]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** merge(int** intervals, int intervalsSize, int* intervalsColSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[][] Merge(int[][] intervals) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} intervals\n * @return {number[][]}\n */\nvar merge = function(intervals) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} intervals\n# @return {Integer[][]}\ndef merge(intervals)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func merge(_ intervals: [[Int]]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func merge(intervals [][]int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def merge(intervals: Array[Array[Int]]): Array[Array[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun merge(intervals: Array): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn merge(intervals: Vec>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $intervals\n * @return Integer[][]\n */\n function merge($intervals) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function merge(intervals: number[][]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (merge intervals)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0056](https://leetcode-cn.com/problems/merge-intervals)", "[\u5408\u5e76\u533a\u95f4](/solution/0000-0099/0056.Merge%20Intervals/README.md)", "`\u6392\u5e8f`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0056](https://leetcode.com/problems/merge-intervals)", "[Merge Intervals](/solution/0000-0099/0056.Merge%20Intervals/README_EN.md)", "`Sort`,`Array`", "Medium", ""]}, {"question_id": "0055", "frontend_question_id": "0055", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/jump-game", "url_en": "https://leetcode.com/problems/jump-game", "relative_path_cn": "/solution/0000-0099/0055.Jump%20Game/README.md", "relative_path_en": "/solution/0000-0099/0055.Jump%20Game/README_EN.md", "title_cn": "\u8df3\u8dc3\u6e38\u620f", "title_en": "Jump Game", "question_title_slug": "jump-game", "content_en": "

    Given an array of non-negative integers nums, you are initially positioned at the first index of the array.

    \n\n

    Each element in the array represents your maximum jump length at that position.

    \n\n

    Determine if you are able to reach the last index.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [2,3,1,1,4]\nOutput: true\nExplanation: Jump 1 step from index 0 to 1, then 3 steps to the last index.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [3,2,1,0,4]\nOutput: false\nExplanation: You will always arrive at index 3 no matter what. Its maximum jump length is 0, which makes it impossible to reach the last index.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 104
    • \n\t
    • 0 <= nums[i] <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\u6570\u7ec4\u00a0nums \uff0c\u4f60\u6700\u521d\u4f4d\u4e8e\u6570\u7ec4\u7684 \u7b2c\u4e00\u4e2a\u4e0b\u6807 \u3002

    \n\n

    \u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u4ee3\u8868\u4f60\u5728\u8be5\u4f4d\u7f6e\u53ef\u4ee5\u8df3\u8dc3\u7684\u6700\u5927\u957f\u5ea6\u3002

    \n\n

    \u5224\u65ad\u4f60\u662f\u5426\u80fd\u591f\u5230\u8fbe\u6700\u540e\u4e00\u4e2a\u4e0b\u6807\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\u00a01\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [2,3,1,1,4]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u53ef\u4ee5\u5148\u8df3 1 \u6b65\uff0c\u4ece\u4e0b\u6807 0 \u5230\u8fbe\u4e0b\u6807 1, \u7136\u540e\u518d\u4ece\u4e0b\u6807 1 \u8df3 3 \u6b65\u5230\u8fbe\u6700\u540e\u4e00\u4e2a\u4e0b\u6807\u3002\n
    \n\n

    \u793a\u4f8b\u00a02\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [3,2,1,0,4]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u65e0\u8bba\u600e\u6837\uff0c\u603b\u4f1a\u5230\u8fbe\u4e0b\u6807\u4e3a 3 \u7684\u4f4d\u7f6e\u3002\u4f46\u8be5\u4e0b\u6807\u7684\u6700\u5927\u8df3\u8dc3\u957f\u5ea6\u662f 0 \uff0c \u6240\u4ee5\u6c38\u8fdc\u4e0d\u53ef\u80fd\u5230\u8fbe\u6700\u540e\u4e00\u4e2a\u4e0b\u6807\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 3 * 104
    • \n\t
    • 0 <= nums[i] <= 105
    • \n
    \n", "tags_en": ["Greedy", "Array"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canJump(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canJump(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canJump(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canJump(self, nums: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canJump(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanJump(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {boolean}\n */\nvar canJump = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Boolean}\ndef can_jump(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canJump(_ nums: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canJump(nums []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canJump(nums: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canJump(nums: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_jump(nums: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Boolean\n */\n function canJump($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canJump(nums: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-jump nums)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0055](https://leetcode-cn.com/problems/jump-game)", "[\u8df3\u8dc3\u6e38\u620f](/solution/0000-0099/0055.Jump%20Game/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0055](https://leetcode.com/problems/jump-game)", "[Jump Game](/solution/0000-0099/0055.Jump%20Game/README_EN.md)", "`Greedy`,`Array`", "Medium", ""]}, {"question_id": "0054", "frontend_question_id": "0054", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/spiral-matrix", "url_en": "https://leetcode.com/problems/spiral-matrix", "relative_path_cn": "/solution/0000-0099/0054.Spiral%20Matrix/README.md", "relative_path_en": "/solution/0000-0099/0054.Spiral%20Matrix/README_EN.md", "title_cn": "\u87ba\u65cb\u77e9\u9635", "title_en": "Spiral Matrix", "question_title_slug": "spiral-matrix", "content_en": "

    Given an m x n matrix, return all elements of the matrix in spiral order.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: matrix = [[1,2,3],[4,5,6],[7,8,9]]\nOutput: [1,2,3,6,9,8,7,4,5]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: matrix = [[1,2,3,4],[5,6,7,8],[9,10,11,12]]\nOutput: [1,2,3,4,8,12,11,10,9,5,6,7]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == matrix.length
    • \n\t
    • n == matrix[i].length
    • \n\t
    • 1 <= m, n <= 10
    • \n\t
    • -100 <= matrix[i][j] <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a m \u884c n \u5217\u7684\u77e9\u9635\u00a0matrix \uff0c\u8bf7\u6309\u7167 \u987a\u65f6\u9488\u87ba\u65cb\u987a\u5e8f \uff0c\u8fd4\u56de\u77e9\u9635\u4e2d\u7684\u6240\u6709\u5143\u7d20\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1amatrix = [[1,2,3],[4,5,6],[7,8,9]]\n\u8f93\u51fa\uff1a[1,2,3,6,9,8,7,4,5]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1amatrix = [[1,2,3,4],[5,6,7,8],[9,10,11,12]]\n\u8f93\u51fa\uff1a[1,2,3,4,8,12,11,10,9,5,6,7]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == matrix.length
    • \n\t
    • n == matrix[i].length
    • \n\t
    • 1 <= m, n <= 10
    • \n\t
    • -100 <= matrix[i][j] <= 100
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector spiralOrder(vector>& matrix) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List spiralOrder(int[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def spiralOrder(self, matrix):\n \"\"\"\n :type matrix: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def spiralOrder(self, matrix: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* spiralOrder(int** matrix, int matrixSize, int* matrixColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList SpiralOrder(int[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} matrix\n * @return {number[]}\n */\nvar spiralOrder = function(matrix) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} matrix\n# @return {Integer[]}\ndef spiral_order(matrix)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func spiralOrder(_ matrix: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func spiralOrder(matrix [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def spiralOrder(matrix: Array[Array[Int]]): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun spiralOrder(matrix: Array): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn spiral_order(matrix: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $matrix\n * @return Integer[]\n */\n function spiralOrder($matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function spiralOrder(matrix: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (spiral-order matrix)\n (-> (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0054](https://leetcode-cn.com/problems/spiral-matrix)", "[\u87ba\u65cb\u77e9\u9635](/solution/0000-0099/0054.Spiral%20Matrix/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0054](https://leetcode.com/problems/spiral-matrix)", "[Spiral Matrix](/solution/0000-0099/0054.Spiral%20Matrix/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0053", "frontend_question_id": "0053", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-subarray", "url_en": "https://leetcode.com/problems/maximum-subarray", "relative_path_cn": "/solution/0000-0099/0053.Maximum%20Subarray/README.md", "relative_path_en": "/solution/0000-0099/0053.Maximum%20Subarray/README_EN.md", "title_cn": "\u6700\u5927\u5b50\u5e8f\u548c", "title_en": "Maximum Subarray", "question_title_slug": "maximum-subarray", "content_en": "

    Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [-2,1,-3,4,-1,2,1,-5,4]\nOutput: 6\nExplanation: [4,-1,2,1] has the largest sum = 6.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1]\nOutput: 1\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [5,4,-1,7,8]\nOutput: 23\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 3 * 104
    • \n\t
    • -105 <= nums[i] <= 105
    • \n
    \n\n

     

    \nFollow up: If you have figured out the O(n) solution, try coding another solution using the divide and conquer approach, which is more subtle.", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums\u00a0\uff0c\u627e\u5230\u4e00\u4e2a\u5177\u6709\u6700\u5927\u548c\u7684\u8fde\u7eed\u5b50\u6570\u7ec4\uff08\u5b50\u6570\u7ec4\u6700\u5c11\u5305\u542b\u4e00\u4e2a\u5143\u7d20\uff09\uff0c\u8fd4\u56de\u5176\u6700\u5927\u548c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [-2,1,-3,4,-1,2,1,-5,4]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u8fde\u7eed\u5b50\u6570\u7ec4\u00a0[4,-1,2,1] \u7684\u548c\u6700\u5927\uff0c\u4e3a\u00a06 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [0]\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [-1]\n\u8f93\u51fa\uff1a-1\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [-100000]\n\u8f93\u51fa\uff1a-100000\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 3 * 104
    • \n\t
    • -105 <= nums[i] <= 105
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u5982\u679c\u4f60\u5df2\u7ecf\u5b9e\u73b0\u590d\u6742\u5ea6\u4e3a O(n) \u7684\u89e3\u6cd5\uff0c\u5c1d\u8bd5\u4f7f\u7528\u66f4\u4e3a\u7cbe\u5999\u7684 \u5206\u6cbb\u6cd5 \u6c42\u89e3\u3002

    \n", "tags_en": ["Array", "Divide and Conquer", "Dynamic Programming"], "tags_cn": ["\u6570\u7ec4", "\u5206\u6cbb\u7b97\u6cd5", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxSubArray(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxSubArray(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxSubArray(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxSubArray(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxSubArray(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxSubArray(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar maxSubArray = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef max_sub_array(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxSubArray(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxSubArray(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxSubArray(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxSubArray(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_sub_array(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function maxSubArray($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxSubArray(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-sub-array nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0053](https://leetcode-cn.com/problems/maximum-subarray)", "[\u6700\u5927\u5b50\u5e8f\u548c](/solution/0000-0099/0053.Maximum%20Subarray/README.md)", "`\u6570\u7ec4`,`\u5206\u6cbb\u7b97\u6cd5`,`\u52a8\u6001\u89c4\u5212`", "\u7b80\u5355", ""], "md_table_row_en": ["[0053](https://leetcode.com/problems/maximum-subarray)", "[Maximum Subarray](/solution/0000-0099/0053.Maximum%20Subarray/README_EN.md)", "`Array`,`Divide and Conquer`,`Dynamic Programming`", "Easy", ""]}, {"question_id": "0052", "frontend_question_id": "0052", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/n-queens-ii", "url_en": "https://leetcode.com/problems/n-queens-ii", "relative_path_cn": "/solution/0000-0099/0052.N-Queens%20II/README.md", "relative_path_en": "/solution/0000-0099/0052.N-Queens%20II/README_EN.md", "title_cn": "N\u7687\u540e II", "title_en": "N-Queens II", "question_title_slug": "n-queens-ii", "content_en": "

    The n-queens puzzle is the problem of placing n queens on an n x n chessboard such that no two queens attack each other.

    \n\n

    Given an integer n, return the number of distinct solutions to the n-queens puzzle.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: n = 4\nOutput: 2\nExplanation: There are two distinct solutions to the 4-queens puzzle as shown.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 1\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 9
    • \n
    \n", "content_cn": "

    n\u00a0\u7687\u540e\u95ee\u9898 \u7814\u7a76\u7684\u662f\u5982\u4f55\u5c06 n\u00a0\u4e2a\u7687\u540e\u653e\u7f6e\u5728 n\u00d7n \u7684\u68cb\u76d8\u4e0a\uff0c\u5e76\u4e14\u4f7f\u7687\u540e\u5f7c\u6b64\u4e4b\u95f4\u4e0d\u80fd\u76f8\u4e92\u653b\u51fb\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n \uff0c\u8fd4\u56de n \u7687\u540e\u95ee\u9898 \u4e0d\u540c\u7684\u89e3\u51b3\u65b9\u6848\u7684\u6570\u91cf\u3002

    \n\n

    \u00a0

    \n\n
    \n
    \n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1an = 4\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5982\u4e0a\u56fe\u6240\u793a\uff0c4 \u7687\u540e\u95ee\u9898\u5b58\u5728\u4e24\u4e2a\u4e0d\u540c\u7684\u89e3\u6cd5\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 9
    • \n\t
    • \u7687\u540e\u5f7c\u6b64\u4e0d\u80fd\u76f8\u4e92\u653b\u51fb\uff0c\u4e5f\u5c31\u662f\u8bf4\uff1a\u4efb\u4f55\u4e24\u4e2a\u7687\u540e\u90fd\u4e0d\u80fd\u5904\u4e8e\u540c\u4e00\u6761\u6a2a\u884c\u3001\u7eb5\u884c\u6216\u659c\u7ebf\u4e0a\u3002
    • \n
    \n
    \n
    \n", "tags_en": ["Backtracking"], "tags_cn": ["\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int totalNQueens(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int totalNQueens(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def totalNQueens(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def totalNQueens(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint totalNQueens(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int TotalNQueens(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar totalNQueens = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef total_n_queens(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func totalNQueens(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func totalNQueens(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def totalNQueens(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun totalNQueens(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn total_n_queens(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function totalNQueens($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function totalNQueens(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (total-n-queens n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0052](https://leetcode-cn.com/problems/n-queens-ii)", "[N\u7687\u540e II](/solution/0000-0099/0052.N-Queens%20II/README.md)", "`\u56de\u6eaf\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[0052](https://leetcode.com/problems/n-queens-ii)", "[N-Queens II](/solution/0000-0099/0052.N-Queens%20II/README_EN.md)", "`Backtracking`", "Hard", ""]}, {"question_id": "0051", "frontend_question_id": "0051", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/n-queens", "url_en": "https://leetcode.com/problems/n-queens", "relative_path_cn": "/solution/0000-0099/0051.N-Queens/README.md", "relative_path_en": "/solution/0000-0099/0051.N-Queens/README_EN.md", "title_cn": "N \u7687\u540e", "title_en": "N-Queens", "question_title_slug": "n-queens", "content_en": "

    The n-queens puzzle is the problem of placing n queens on an n x n chessboard such that no two queens attack each other.

    \n\n

    Given an integer n, return all distinct solutions to the n-queens puzzle. You may return the answer in any order.

    \n\n

    Each solution contains a distinct board configuration of the n-queens' placement, where 'Q' and '.' both indicate a queen and an empty space, respectively.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: n = 4\nOutput: [[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]\nExplanation: There exist two distinct solutions to the 4-queens puzzle as shown above\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 1\nOutput: [["Q"]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 9
    • \n
    \n", "content_cn": "

    n\u00a0\u7687\u540e\u95ee\u9898 \u7814\u7a76\u7684\u662f\u5982\u4f55\u5c06 n\u00a0\u4e2a\u7687\u540e\u653e\u7f6e\u5728 n\u00d7n \u7684\u68cb\u76d8\u4e0a\uff0c\u5e76\u4e14\u4f7f\u7687\u540e\u5f7c\u6b64\u4e4b\u95f4\u4e0d\u80fd\u76f8\u4e92\u653b\u51fb\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n \uff0c\u8fd4\u56de\u6240\u6709\u4e0d\u540c\u7684\u00a0n\u00a0\u7687\u540e\u95ee\u9898 \u7684\u89e3\u51b3\u65b9\u6848\u3002

    \n\n
    \n
    \n

    \u6bcf\u4e00\u79cd\u89e3\u6cd5\u5305\u542b\u4e00\u4e2a\u4e0d\u540c\u7684\u00a0n \u7687\u540e\u95ee\u9898 \u7684\u68cb\u5b50\u653e\u7f6e\u65b9\u6848\uff0c\u8be5\u65b9\u6848\u4e2d 'Q' \u548c '.' \u5206\u522b\u4ee3\u8868\u4e86\u7687\u540e\u548c\u7a7a\u4f4d\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1an = 4\n\u8f93\u51fa\uff1a[[\".Q..\",\"...Q\",\"Q...\",\"..Q.\"],[\"..Q.\",\"Q...\",\"...Q\",\".Q..\"]]\n\u89e3\u91ca\uff1a\u5982\u4e0a\u56fe\u6240\u793a\uff0c4 \u7687\u540e\u95ee\u9898\u5b58\u5728\u4e24\u4e2a\u4e0d\u540c\u7684\u89e3\u6cd5\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1a[[\"Q\"]]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 9
    • \n\t
    • \u7687\u540e\u5f7c\u6b64\u4e0d\u80fd\u76f8\u4e92\u653b\u51fb\uff0c\u4e5f\u5c31\u662f\u8bf4\uff1a\u4efb\u4f55\u4e24\u4e2a\u7687\u540e\u90fd\u4e0d\u80fd\u5904\u4e8e\u540c\u4e00\u6761\u6a2a\u884c\u3001\u7eb5\u884c\u6216\u659c\u7ebf\u4e0a\u3002
    • \n
    \n
    \n
    \n", "tags_en": ["Backtracking"], "tags_cn": ["\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> solveNQueens(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> solveNQueens(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def solveNQueens(self, n):\n \"\"\"\n :type n: int\n :rtype: List[List[str]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def solveNQueens(self, n: int) -> List[List[str]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nchar *** solveNQueens(int n, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> SolveNQueens(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {string[][]}\n */\nvar solveNQueens = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {String[][]}\ndef solve_n_queens(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func solveNQueens(_ n: Int) -> [[String]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func solveNQueens(n int) [][]string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def solveNQueens(n: Int): List[List[String]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun solveNQueens(n: Int): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn solve_n_queens(n: i32) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return String[][]\n */\n function solveNQueens($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function solveNQueens(n: number): string[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (solve-n-queens n)\n (-> exact-integer? (listof (listof string?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0051](https://leetcode-cn.com/problems/n-queens)", "[N \u7687\u540e](/solution/0000-0099/0051.N-Queens/README.md)", "`\u56de\u6eaf\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[0051](https://leetcode.com/problems/n-queens)", "[N-Queens](/solution/0000-0099/0051.N-Queens/README_EN.md)", "`Backtracking`", "Hard", ""]}, {"question_id": "0050", "frontend_question_id": "0050", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/powx-n", "url_en": "https://leetcode.com/problems/powx-n", "relative_path_cn": "/solution/0000-0099/0050.Pow%28x%2C%20n%29/README.md", "relative_path_en": "/solution/0000-0099/0050.Pow%28x%2C%20n%29/README_EN.md", "title_cn": "Pow(x, n)", "title_en": "Pow(x, n)", "question_title_slug": "powx-n", "content_en": "

    Implement pow(x, n), which calculates x raised to the power n (i.e., xn).

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: x = 2.00000, n = 10\nOutput: 1024.00000\n
    \n\n

    Example 2:

    \n\n
    \nInput: x = 2.10000, n = 3\nOutput: 9.26100\n
    \n\n

    Example 3:

    \n\n
    \nInput: x = 2.00000, n = -2\nOutput: 0.25000\nExplanation: 2-2 = 1/22 = 1/4 = 0.25\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • -100.0 < x < 100.0
    • \n\t
    • -231 <= n <= 231-1
    • \n\t
    • -104 <= xn <= 104
    • \n
    \n", "content_cn": "

    \u5b9e\u73b0\u00a0pow(x, n)\u00a0\uff0c\u5373\u8ba1\u7b97 x \u7684 n \u6b21\u5e42\u51fd\u6570\uff08\u5373\uff0cxn\uff09\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1ax = 2.00000, n = 10\n\u8f93\u51fa\uff1a1024.00000\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1ax = 2.10000, n = 3\n\u8f93\u51fa\uff1a9.26100\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1ax = 2.00000, n = -2\n\u8f93\u51fa\uff1a0.25000\n\u89e3\u91ca\uff1a2-2 = 1/22 = 1/4 = 0.25\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • -100.0 <\u00a0x\u00a0< 100.0
    • \n\t
    • -231\u00a0<= n <=\u00a0231-1
    • \n\t
    • -104 <= xn <= 104
    • \n
    \n", "tags_en": ["Math", "Binary Search"], "tags_cn": ["\u6570\u5b66", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n double myPow(double x, int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double myPow(double x, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def myPow(self, x, n):\n \"\"\"\n :type x: float\n :type n: int\n :rtype: float\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def myPow(self, x: float, n: int) -> float:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\ndouble myPow(double x, int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double MyPow(double x, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} x\n * @param {number} n\n * @return {number}\n */\nvar myPow = function(x, n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Float} x\n# @param {Integer} n\n# @return {Float}\ndef my_pow(x, n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func myPow(_ x: Double, _ n: Int) -> Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func myPow(x float64, n int) float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def myPow(x: Double, n: Int): Double = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun myPow(x: Double, n: Int): Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn my_pow(x: f64, n: i32) -> f64 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Float $x\n * @param Integer $n\n * @return Float\n */\n function myPow($x, $n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function myPow(x: number, n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (my-pow x n)\n (-> flonum? exact-integer? flonum?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0050](https://leetcode-cn.com/problems/powx-n)", "[Pow(x, n)](/solution/0000-0099/0050.Pow%28x%2C%20n%29/README.md)", "`\u6570\u5b66`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0050](https://leetcode.com/problems/powx-n)", "[Pow(x, n)](/solution/0000-0099/0050.Pow%28x%2C%20n%29/README_EN.md)", "`Math`,`Binary Search`", "Medium", ""]}, {"question_id": "0049", "frontend_question_id": "0049", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/group-anagrams", "url_en": "https://leetcode.com/problems/group-anagrams", "relative_path_cn": "/solution/0000-0099/0049.Group%20Anagrams/README.md", "relative_path_en": "/solution/0000-0099/0049.Group%20Anagrams/README_EN.md", "title_cn": "\u5b57\u6bcd\u5f02\u4f4d\u8bcd\u5206\u7ec4", "title_en": "Group Anagrams", "question_title_slug": "group-anagrams", "content_en": "

    Given an array of strings strs, group the anagrams together. You can return the answer in any order.

    \n\n

    An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.

    \n\n

     

    \n

    Example 1:

    \n
    Input: strs = [\"eat\",\"tea\",\"tan\",\"ate\",\"nat\",\"bat\"]\nOutput: [[\"bat\"],[\"nat\",\"tan\"],[\"ate\",\"eat\",\"tea\"]]\n

    Example 2:

    \n
    Input: strs = [\"\"]\nOutput: [[\"\"]]\n

    Example 3:

    \n
    Input: strs = [\"a\"]\nOutput: [[\"a\"]]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= strs.length <= 104
    • \n\t
    • 0 <= strs[i].length <= 100
    • \n\t
    • strs[i] consists of lower-case English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4\uff0c\u5c06\u5b57\u6bcd\u5f02\u4f4d\u8bcd\u7ec4\u5408\u5728\u4e00\u8d77\u3002\u5b57\u6bcd\u5f02\u4f4d\u8bcd\u6307\u5b57\u6bcd\u76f8\u540c\uff0c\u4f46\u6392\u5217\u4e0d\u540c\u7684\u5b57\u7b26\u4e32\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: ["eat", "tea", "tan", "ate", "nat", "bat"]\n\u8f93\u51fa:\n[\n  ["ate","eat","tea"],\n  ["nat","tan"],\n  ["bat"]\n]
    \n\n

    \u8bf4\u660e\uff1a

    \n\n
      \n\t
    • \u6240\u6709\u8f93\u5165\u5747\u4e3a\u5c0f\u5199\u5b57\u6bcd\u3002
    • \n\t
    • \u4e0d\u8003\u8651\u7b54\u6848\u8f93\u51fa\u7684\u987a\u5e8f\u3002
    • \n
    \n", "tags_en": ["Hash Table", "String"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> groupAnagrams(vector& strs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> groupAnagrams(String[] strs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def groupAnagrams(self, strs):\n \"\"\"\n :type strs: List[str]\n :rtype: List[List[str]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def groupAnagrams(self, strs: List[str]) -> List[List[str]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nchar *** groupAnagrams(char ** strs, int strsSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> GroupAnagrams(string[] strs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} strs\n * @return {string[][]}\n */\nvar groupAnagrams = function(strs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} strs\n# @return {String[][]}\ndef group_anagrams(strs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func groupAnagrams(_ strs: [String]) -> [[String]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func groupAnagrams(strs []string) [][]string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def groupAnagrams(strs: Array[String]): List[List[String]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun groupAnagrams(strs: Array): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn group_anagrams(strs: Vec) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $strs\n * @return String[][]\n */\n function groupAnagrams($strs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function groupAnagrams(strs: string[]): string[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (group-anagrams strs)\n (-> (listof string?) (listof (listof string?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0049](https://leetcode-cn.com/problems/group-anagrams)", "[\u5b57\u6bcd\u5f02\u4f4d\u8bcd\u5206\u7ec4](/solution/0000-0099/0049.Group%20Anagrams/README.md)", "`\u54c8\u5e0c\u8868`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0049](https://leetcode.com/problems/group-anagrams)", "[Group Anagrams](/solution/0000-0099/0049.Group%20Anagrams/README_EN.md)", "`Hash Table`,`String`", "Medium", ""]}, {"question_id": "0048", "frontend_question_id": "0048", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/rotate-image", "url_en": "https://leetcode.com/problems/rotate-image", "relative_path_cn": "/solution/0000-0099/0048.Rotate%20Image/README.md", "relative_path_en": "/solution/0000-0099/0048.Rotate%20Image/README_EN.md", "title_cn": "\u65cb\u8f6c\u56fe\u50cf", "title_en": "Rotate Image", "question_title_slug": "rotate-image", "content_en": "

    You are given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise).

    \n\n

    You have to rotate the image in-place, which means you have to modify the input 2D matrix directly. DO NOT allocate another 2D matrix and do the rotation.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: matrix = [[1,2,3],[4,5,6],[7,8,9]]\nOutput: [[7,4,1],[8,5,2],[9,6,3]]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: matrix = [[5,1,9,11],[2,4,8,10],[13,3,6,7],[15,14,12,16]]\nOutput: [[15,13,2,5],[14,3,4,1],[12,6,8,9],[16,7,10,11]]\n
    \n\n

    Example 3:

    \n\n
    \nInput: matrix = [[1]]\nOutput: [[1]]\n
    \n\n

    Example 4:

    \n\n
    \nInput: matrix = [[1,2],[3,4]]\nOutput: [[3,1],[4,2]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • matrix.length == n
    • \n\t
    • matrix[i].length == n
    • \n\t
    • 1 <= n <= 20
    • \n\t
    • -1000 <= matrix[i][j] <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a n\u00a0\u00d7\u00a0n \u7684\u4e8c\u7ef4\u77e9\u9635\u00a0matrix \u8868\u793a\u4e00\u4e2a\u56fe\u50cf\u3002\u8bf7\u4f60\u5c06\u56fe\u50cf\u987a\u65f6\u9488\u65cb\u8f6c 90 \u5ea6\u3002

    \n\n

    \u4f60\u5fc5\u987b\u5728 \u539f\u5730 \u65cb\u8f6c\u56fe\u50cf\uff0c\u8fd9\u610f\u5473\u7740\u4f60\u9700\u8981\u76f4\u63a5\u4fee\u6539\u8f93\u5165\u7684\u4e8c\u7ef4\u77e9\u9635\u3002\u8bf7\u4e0d\u8981 \u4f7f\u7528\u53e6\u4e00\u4e2a\u77e9\u9635\u6765\u65cb\u8f6c\u56fe\u50cf\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1amatrix = [[1,2,3],[4,5,6],[7,8,9]]\n\u8f93\u51fa\uff1a[[7,4,1],[8,5,2],[9,6,3]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1amatrix = [[5,1,9,11],[2,4,8,10],[13,3,6,7],[15,14,12,16]]\n\u8f93\u51fa\uff1a[[15,13,2,5],[14,3,4,1],[12,6,8,9],[16,7,10,11]]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1amatrix = [[1]]\n\u8f93\u51fa\uff1a[[1]]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1amatrix = [[1,2],[3,4]]\n\u8f93\u51fa\uff1a[[3,1],[4,2]]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • matrix.length == n
    • \n\t
    • matrix[i].length == n
    • \n\t
    • 1 <= n <= 20
    • \n\t
    • -1000 <= matrix[i][j] <= 1000
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n void rotate(vector>& matrix) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public void rotate(int[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def rotate(self, matrix):\n \"\"\"\n :type matrix: List[List[int]]\n :rtype: None Do not return anything, modify matrix in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def rotate(self, matrix: List[List[int]]) -> None:\n \"\"\"\n Do not return anything, modify matrix in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nvoid rotate(int** matrix, int matrixSize, int* matrixColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public void Rotate(int[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} matrix\n * @return {void} Do not return anything, modify matrix in-place instead.\n */\nvar rotate = function(matrix) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} matrix\n# @return {Void} Do not return anything, modify matrix in-place instead.\ndef rotate(matrix)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func rotate(_ matrix: inout [[Int]]) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func rotate(matrix [][]int) {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def rotate(matrix: Array[Array[Int]]): Unit = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun rotate(matrix: Array): Unit {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn rotate(matrix: &mut Vec>) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $matrix\n * @return NULL\n */\n function rotate(&$matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n Do not return anything, modify matrix in-place instead.\n */\nfunction rotate(matrix: number[][]): void {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0048](https://leetcode-cn.com/problems/rotate-image)", "[\u65cb\u8f6c\u56fe\u50cf](/solution/0000-0099/0048.Rotate%20Image/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0048](https://leetcode.com/problems/rotate-image)", "[Rotate Image](/solution/0000-0099/0048.Rotate%20Image/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0047", "frontend_question_id": "0047", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/permutations-ii", "url_en": "https://leetcode.com/problems/permutations-ii", "relative_path_cn": "/solution/0000-0099/0047.Permutations%20II/README.md", "relative_path_en": "/solution/0000-0099/0047.Permutations%20II/README_EN.md", "title_cn": "\u5168\u6392\u5217 II", "title_en": "Permutations II", "question_title_slug": "permutations-ii", "content_en": "

    Given a collection of numbers, nums, that might contain duplicates, return all possible unique permutations in any order.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,1,2]\nOutput:\n[[1,1,2],\n [1,2,1],\n [2,1,1]]\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,2,3]\nOutput: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 8
    • \n\t
    • -10 <= nums[i] <= 10
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u53ef\u5305\u542b\u91cd\u590d\u6570\u5b57\u7684\u5e8f\u5217 nums \uff0c\u6309\u4efb\u610f\u987a\u5e8f \u8fd4\u56de\u6240\u6709\u4e0d\u91cd\u590d\u7684\u5168\u6392\u5217\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,1,2]\n\u8f93\u51fa\uff1a\n[[1,1,2],\n [1,2,1],\n [2,1,1]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,3]\n\u8f93\u51fa\uff1a[[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 8
    • \n\t
    • -10 <= nums[i] <= 10
    • \n
    \n", "tags_en": ["Backtracking"], "tags_cn": ["\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> permuteUnique(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> permuteUnique(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def permuteUnique(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def permuteUnique(self, nums: List[int]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** permuteUnique(int* nums, int numsSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> PermuteUnique(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number[][]}\n */\nvar permuteUnique = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer[][]}\ndef permute_unique(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func permuteUnique(_ nums: [Int]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func permuteUnique(nums []int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def permuteUnique(nums: Array[Int]): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun permuteUnique(nums: IntArray): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn permute_unique(nums: Vec) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer[][]\n */\n function permuteUnique($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function permuteUnique(nums: number[]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (permute-unique nums)\n (-> (listof exact-integer?) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0047](https://leetcode-cn.com/problems/permutations-ii)", "[\u5168\u6392\u5217 II](/solution/0000-0099/0047.Permutations%20II/README.md)", "`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0047](https://leetcode.com/problems/permutations-ii)", "[Permutations II](/solution/0000-0099/0047.Permutations%20II/README_EN.md)", "`Backtracking`", "Medium", ""]}, {"question_id": "0046", "frontend_question_id": "0046", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/permutations", "url_en": "https://leetcode.com/problems/permutations", "relative_path_cn": "/solution/0000-0099/0046.Permutations/README.md", "relative_path_en": "/solution/0000-0099/0046.Permutations/README_EN.md", "title_cn": "\u5168\u6392\u5217", "title_en": "Permutations", "question_title_slug": "permutations", "content_en": "

    Given an array nums of distinct integers, return all the possible permutations. You can return the answer in any order.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [1,2,3]\nOutput: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]\n

    Example 2:

    \n
    Input: nums = [0,1]\nOutput: [[0,1],[1,0]]\n

    Example 3:

    \n
    Input: nums = [1]\nOutput: [[1]]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 6
    • \n\t
    • -10 <= nums[i] <= 10
    • \n\t
    • All the integers of nums are unique.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e0d\u542b\u91cd\u590d\u6570\u5b57\u7684\u6570\u7ec4 nums \uff0c\u8fd4\u56de\u5176 \u6240\u6709\u53ef\u80fd\u7684\u5168\u6392\u5217 \u3002\u4f60\u53ef\u4ee5 \u6309\u4efb\u610f\u987a\u5e8f \u8fd4\u56de\u7b54\u6848\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,3]\n\u8f93\u51fa\uff1a[[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [0,1]\n\u8f93\u51fa\uff1a[[0,1],[1,0]]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1]\n\u8f93\u51fa\uff1a[[1]]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 6
    • \n\t
    • -10 <= nums[i] <= 10
    • \n\t
    • nums \u4e2d\u7684\u6240\u6709\u6574\u6570 \u4e92\u4e0d\u76f8\u540c
    • \n
    \n", "tags_en": ["Backtracking"], "tags_cn": ["\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> permute(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> permute(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def permute(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def permute(self, nums: List[int]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** permute(int* nums, int numsSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> Permute(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number[][]}\n */\nvar permute = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer[][]}\ndef permute(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func permute(_ nums: [Int]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func permute(nums []int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def permute(nums: Array[Int]): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun permute(nums: IntArray): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn permute(nums: Vec) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer[][]\n */\n function permute($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function permute(nums: number[]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (permute nums)\n (-> (listof exact-integer?) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0046](https://leetcode-cn.com/problems/permutations)", "[\u5168\u6392\u5217](/solution/0000-0099/0046.Permutations/README.md)", "`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0046](https://leetcode.com/problems/permutations)", "[Permutations](/solution/0000-0099/0046.Permutations/README_EN.md)", "`Backtracking`", "Medium", ""]}, {"question_id": "0045", "frontend_question_id": "0045", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/jump-game-ii", "url_en": "https://leetcode.com/problems/jump-game-ii", "relative_path_cn": "/solution/0000-0099/0045.Jump%20Game%20II/README.md", "relative_path_en": "/solution/0000-0099/0045.Jump%20Game%20II/README_EN.md", "title_cn": "\u8df3\u8dc3\u6e38\u620f II", "title_en": "Jump Game II", "question_title_slug": "jump-game-ii", "content_en": "

    Given an array of non-negative integers nums, you are initially positioned at the first index of the array.

    \n\n

    Each element in the array represents your maximum jump length at that position.

    \n\n

    Your goal is to reach the last index in the minimum number of jumps.

    \n\n

    You can assume that you can always reach the last index.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [2,3,1,1,4]\nOutput: 2\nExplanation: The minimum number of jumps to reach the last index is 2. Jump 1 step from index 0 to 1, then 3 steps to the last index.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [2,3,0,1,4]\nOutput: 2\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 104
    • \n\t
    • 0 <= nums[i] <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\u6570\u7ec4\uff0c\u4f60\u6700\u521d\u4f4d\u4e8e\u6570\u7ec4\u7684\u7b2c\u4e00\u4e2a\u4f4d\u7f6e\u3002

    \n\n

    \u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u4ee3\u8868\u4f60\u5728\u8be5\u4f4d\u7f6e\u53ef\u4ee5\u8df3\u8dc3\u7684\u6700\u5927\u957f\u5ea6\u3002

    \n\n

    \u4f60\u7684\u76ee\u6807\u662f\u4f7f\u7528\u6700\u5c11\u7684\u8df3\u8dc3\u6b21\u6570\u5230\u8fbe\u6570\u7ec4\u7684\u6700\u540e\u4e00\u4e2a\u4f4d\u7f6e\u3002

    \n\n

    \u5047\u8bbe\u4f60\u603b\u662f\u53ef\u4ee5\u5230\u8fbe\u6570\u7ec4\u7684\u6700\u540e\u4e00\u4e2a\u4f4d\u7f6e\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: [2,3,1,1,4]\n\u8f93\u51fa: 2\n\u89e3\u91ca: \u8df3\u5230\u6700\u540e\u4e00\u4e2a\u4f4d\u7f6e\u7684\u6700\u5c0f\u8df3\u8dc3\u6570\u662f 2\u3002\n\u00a0    \u4ece\u4e0b\u6807\u4e3a 0 \u8df3\u5230\u4e0b\u6807\u4e3a 1 \u7684\u4f4d\u7f6e\uff0c\u8df3\u00a01\u00a0\u6b65\uff0c\u7136\u540e\u8df3\u00a03\u00a0\u6b65\u5230\u8fbe\u6570\u7ec4\u7684\u6700\u540e\u4e00\u4e2a\u4f4d\u7f6e\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: [2,3,0,1,4]\n\u8f93\u51fa: 2\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a:

    \n\n
      \n\t
    • 1 <= nums.length <= 1000
    • \n\t
    • 0 <= nums[i] <= 105
    • \n
    \n", "tags_en": ["Greedy", "Array"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int jump(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int jump(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def jump(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def jump(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint jump(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int Jump(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar jump = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef jump(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func jump(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func jump(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def jump(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun jump(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn jump(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function jump($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function jump(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (jump nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0045](https://leetcode-cn.com/problems/jump-game-ii)", "[\u8df3\u8dc3\u6e38\u620f II](/solution/0000-0099/0045.Jump%20Game%20II/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0045](https://leetcode.com/problems/jump-game-ii)", "[Jump Game II](/solution/0000-0099/0045.Jump%20Game%20II/README_EN.md)", "`Greedy`,`Array`", "Medium", ""]}, {"question_id": "0044", "frontend_question_id": "0044", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/wildcard-matching", "url_en": "https://leetcode.com/problems/wildcard-matching", "relative_path_cn": "/solution/0000-0099/0044.Wildcard%20Matching/README.md", "relative_path_en": "/solution/0000-0099/0044.Wildcard%20Matching/README_EN.md", "title_cn": "\u901a\u914d\u7b26\u5339\u914d", "title_en": "Wildcard Matching", "question_title_slug": "wildcard-matching", "content_en": "

    Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for '?' and '*' where:

    \n\n
      \n\t
    • '?' Matches any single character.
    • \n\t
    • '*' Matches any sequence of characters (including the empty sequence).
    • \n
    \n\n

    The matching should cover the entire input string (not partial).

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "aa", p = "a"\nOutput: false\nExplanation: "a" does not match the entire string "aa".\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "aa", p = "*"\nOutput: true\nExplanation: '*' matches any sequence.\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "cb", p = "?a"\nOutput: false\nExplanation: '?' matches 'c', but the second letter is 'a', which does not match 'b'.\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "adceb", p = "*a*b"\nOutput: true\nExplanation: The first '*' matches the empty sequence, while the second '*' matches the substring "dce".\n
    \n\n

    Example 5:

    \n\n
    \nInput: s = "acdcb", p = "a*c?b"\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= s.length, p.length <= 2000
    • \n\t
    • s contains only lowercase English letters.
    • \n\t
    • p contains only lowercase English letters, '?' or '*'.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32 (s) \u548c\u4e00\u4e2a\u5b57\u7b26\u6a21\u5f0f (p) \uff0c\u5b9e\u73b0\u4e00\u4e2a\u652f\u6301 '?' \u548c '*' \u7684\u901a\u914d\u7b26\u5339\u914d\u3002

    \n\n
    '?' \u53ef\u4ee5\u5339\u914d\u4efb\u4f55\u5355\u4e2a\u5b57\u7b26\u3002\n'*' \u53ef\u4ee5\u5339\u914d\u4efb\u610f\u5b57\u7b26\u4e32\uff08\u5305\u62ec\u7a7a\u5b57\u7b26\u4e32\uff09\u3002\n
    \n\n

    \u4e24\u4e2a\u5b57\u7b26\u4e32\u5b8c\u5168\u5339\u914d\u624d\u7b97\u5339\u914d\u6210\u529f\u3002

    \n\n

    \u8bf4\u660e:

    \n\n
      \n\t
    • s \u53ef\u80fd\u4e3a\u7a7a\uff0c\u4e14\u53ea\u5305\u542b\u4ece a-z \u7684\u5c0f\u5199\u5b57\u6bcd\u3002
    • \n\t
    • p \u53ef\u80fd\u4e3a\u7a7a\uff0c\u4e14\u53ea\u5305\u542b\u4ece a-z \u7684\u5c0f\u5199\u5b57\u6bcd\uff0c\u4ee5\u53ca\u5b57\u7b26 ? \u548c *\u3002
    • \n
    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165:\ns = "aa"\np = "a"\n\u8f93\u51fa: false\n\u89e3\u91ca: "a" \u65e0\u6cd5\u5339\u914d "aa" \u6574\u4e2a\u5b57\u7b26\u4e32\u3002
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165:\ns = "aa"\np = "*"\n\u8f93\u51fa: true\n\u89e3\u91ca: '*' \u53ef\u4ee5\u5339\u914d\u4efb\u610f\u5b57\u7b26\u4e32\u3002\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u8f93\u5165:\ns = "cb"\np = "?a"\n\u8f93\u51fa: false\n\u89e3\u91ca: '?' \u53ef\u4ee5\u5339\u914d 'c', \u4f46\u7b2c\u4e8c\u4e2a 'a' \u65e0\u6cd5\u5339\u914d 'b'\u3002\n
    \n\n

    \u793a\u4f8b 4:

    \n\n
    \u8f93\u5165:\ns = "adceb"\np = "*a*b"\n\u8f93\u51fa: true\n\u89e3\u91ca: \u7b2c\u4e00\u4e2a '*' \u53ef\u4ee5\u5339\u914d\u7a7a\u5b57\u7b26\u4e32, \u7b2c\u4e8c\u4e2a '*' \u53ef\u4ee5\u5339\u914d\u5b57\u7b26\u4e32 "dce".\n
    \n\n

    \u793a\u4f8b 5:

    \n\n
    \u8f93\u5165:\ns = "acdcb"\np = "a*c?b"\n\u8f93\u51fa: false
    \n", "tags_en": ["Greedy", "String", "Dynamic Programming", "Backtracking"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u5b57\u7b26\u4e32", "\u52a8\u6001\u89c4\u5212", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isMatch(string s, string p) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isMatch(String s, String p) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isMatch(self, s, p):\n \"\"\"\n :type s: str\n :type p: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isMatch(self, s: str, p: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isMatch(char * s, char * p){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsMatch(string s, string p) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string} p\n * @return {boolean}\n */\nvar isMatch = function(s, p) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String} p\n# @return {Boolean}\ndef is_match(s, p)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isMatch(_ s: String, _ p: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isMatch(s string, p string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isMatch(s: String, p: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isMatch(s: String, p: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_match(s: String, p: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String $p\n * @return Boolean\n */\n function isMatch($s, $p) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isMatch(s: string, p: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-match s p)\n (-> string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0044](https://leetcode-cn.com/problems/wildcard-matching)", "[\u901a\u914d\u7b26\u5339\u914d](/solution/0000-0099/0044.Wildcard%20Matching/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u5b57\u7b26\u4e32`,`\u52a8\u6001\u89c4\u5212`,`\u56de\u6eaf\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[0044](https://leetcode.com/problems/wildcard-matching)", "[Wildcard Matching](/solution/0000-0099/0044.Wildcard%20Matching/README_EN.md)", "`Greedy`,`String`,`Dynamic Programming`,`Backtracking`", "Hard", ""]}, {"question_id": "0043", "frontend_question_id": "0043", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/multiply-strings", "url_en": "https://leetcode.com/problems/multiply-strings", "relative_path_cn": "/solution/0000-0099/0043.Multiply%20Strings/README.md", "relative_path_en": "/solution/0000-0099/0043.Multiply%20Strings/README_EN.md", "title_cn": "\u5b57\u7b26\u4e32\u76f8\u4e58", "title_en": "Multiply Strings", "question_title_slug": "multiply-strings", "content_en": "

    Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2, also represented as a string.

    \n\n

    Note: You must not use any built-in BigInteger library or convert the inputs to integer directly.

    \n\n

     

    \n

    Example 1:

    \n
    Input: num1 = \"2\", num2 = \"3\"\nOutput: \"6\"\n

    Example 2:

    \n
    Input: num1 = \"123\", num2 = \"456\"\nOutput: \"56088\"\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= num1.length, num2.length <= 200
    • \n\t
    • num1 and num2 consist of digits only.
    • \n\t
    • Both num1 and num2 do not contain any leading zero, except the number 0 itself.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u4ee5\u5b57\u7b26\u4e32\u5f62\u5f0f\u8868\u793a\u7684\u975e\u8d1f\u6574\u6570 num1 \u548c num2\uff0c\u8fd4\u56de num1 \u548c num2 \u7684\u4e58\u79ef\uff0c\u5b83\u4eec\u7684\u4e58\u79ef\u4e5f\u8868\u793a\u4e3a\u5b57\u7b26\u4e32\u5f62\u5f0f\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: num1 = "2", num2 = "3"\n\u8f93\u51fa: "6"
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: num1 = "123", num2 = "456"\n\u8f93\u51fa: "56088"
    \n\n

    \u8bf4\u660e\uff1a

    \n\n
      \n\t
    1. num1 \u548c num2 \u7684\u957f\u5ea6\u5c0f\u4e8e110\u3002
    2. \n\t
    3. num1 \u548c num2 \u53ea\u5305\u542b\u6570\u5b57 0-9\u3002
    4. \n\t
    5. num1 \u548c num2 \u5747\u4e0d\u4ee5\u96f6\u5f00\u5934\uff0c\u9664\u975e\u662f\u6570\u5b57 0 \u672c\u8eab\u3002
    6. \n\t
    7. \u4e0d\u80fd\u4f7f\u7528\u4efb\u4f55\u6807\u51c6\u5e93\u7684\u5927\u6570\u7c7b\u578b\uff08\u6bd4\u5982 BigInteger\uff09\u6216\u76f4\u63a5\u5c06\u8f93\u5165\u8f6c\u6362\u4e3a\u6574\u6570\u6765\u5904\u7406\u3002
    8. \n
    \n", "tags_en": ["Math", "String"], "tags_cn": ["\u6570\u5b66", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string multiply(string num1, string num2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String multiply(String num1, String num2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def multiply(self, num1, num2):\n \"\"\"\n :type num1: str\n :type num2: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def multiply(self, num1: str, num2: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * multiply(char * num1, char * num2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string Multiply(string num1, string num2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} num1\n * @param {string} num2\n * @return {string}\n */\nvar multiply = function(num1, num2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} num1\n# @param {String} num2\n# @return {String}\ndef multiply(num1, num2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func multiply(_ num1: String, _ num2: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func multiply(num1 string, num2 string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def multiply(num1: String, num2: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun multiply(num1: String, num2: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn multiply(num1: String, num2: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $num1\n * @param String $num2\n * @return String\n */\n function multiply($num1, $num2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function multiply(num1: string, num2: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (multiply num1 num2)\n (-> string? string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0043](https://leetcode-cn.com/problems/multiply-strings)", "[\u5b57\u7b26\u4e32\u76f8\u4e58](/solution/0000-0099/0043.Multiply%20Strings/README.md)", "`\u6570\u5b66`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0043](https://leetcode.com/problems/multiply-strings)", "[Multiply Strings](/solution/0000-0099/0043.Multiply%20Strings/README_EN.md)", "`Math`,`String`", "Medium", ""]}, {"question_id": "0042", "frontend_question_id": "0042", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/trapping-rain-water", "url_en": "https://leetcode.com/problems/trapping-rain-water", "relative_path_cn": "/solution/0000-0099/0042.Trapping%20Rain%20Water/README.md", "relative_path_en": "/solution/0000-0099/0042.Trapping%20Rain%20Water/README_EN.md", "title_cn": "\u63a5\u96e8\u6c34", "title_en": "Trapping Rain Water", "question_title_slug": "trapping-rain-water", "content_en": "

    Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: height = [0,1,0,2,1,0,1,3,2,1,2,1]\nOutput: 6\nExplanation: The above elevation map (black section) is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being trapped.\n
    \n\n

    Example 2:

    \n\n
    \nInput: height = [4,2,0,3,2,5]\nOutput: 9\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == height.length
    • \n\t
    • 0 <= n <= 3 * 104
    • \n\t
    • 0 <= height[i] <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u00a0n \u4e2a\u975e\u8d1f\u6574\u6570\u8868\u793a\u6bcf\u4e2a\u5bbd\u5ea6\u4e3a 1 \u7684\u67f1\u5b50\u7684\u9ad8\u5ea6\u56fe\uff0c\u8ba1\u7b97\u6309\u6b64\u6392\u5217\u7684\u67f1\u5b50\uff0c\u4e0b\u96e8\u4e4b\u540e\u80fd\u63a5\u591a\u5c11\u96e8\u6c34\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \n\n
    \n\u8f93\u5165\uff1aheight = [0,1,0,2,1,0,1,3,2,1,2,1]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u4e0a\u9762\u662f\u7531\u6570\u7ec4 [0,1,0,2,1,0,1,3,2,1,2,1] \u8868\u793a\u7684\u9ad8\u5ea6\u56fe\uff0c\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u53ef\u4ee5\u63a5 6 \u4e2a\u5355\u4f4d\u7684\u96e8\u6c34\uff08\u84dd\u8272\u90e8\u5206\u8868\u793a\u96e8\u6c34\uff09\u3002 \n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aheight = [4,2,0,3,2,5]\n\u8f93\u51fa\uff1a9\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == height.length
    • \n\t
    • 0 <= n <= 3 * 104
    • \n\t
    • 0 <= height[i] <= 105
    • \n
    \n", "tags_en": ["Stack", "Array", "Two Pointers", "Dynamic Programming"], "tags_cn": ["\u6808", "\u6570\u7ec4", "\u53cc\u6307\u9488", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int trap(vector& height) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int trap(int[] height) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def trap(self, height):\n \"\"\"\n :type height: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def trap(self, height: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint trap(int* height, int heightSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int Trap(int[] height) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} height\n * @return {number}\n */\nvar trap = function(height) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} height\n# @return {Integer}\ndef trap(height)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func trap(_ height: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func trap(height []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def trap(height: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun trap(height: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn trap(height: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $height\n * @return Integer\n */\n function trap($height) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function trap(height: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (trap height)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0042](https://leetcode-cn.com/problems/trapping-rain-water)", "[\u63a5\u96e8\u6c34](/solution/0000-0099/0042.Trapping%20Rain%20Water/README.md)", "`\u6808`,`\u6570\u7ec4`,`\u53cc\u6307\u9488`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0042](https://leetcode.com/problems/trapping-rain-water)", "[Trapping Rain Water](/solution/0000-0099/0042.Trapping%20Rain%20Water/README_EN.md)", "`Stack`,`Array`,`Two Pointers`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0041", "frontend_question_id": "0041", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/first-missing-positive", "url_en": "https://leetcode.com/problems/first-missing-positive", "relative_path_cn": "/solution/0000-0099/0041.First%20Missing%20Positive/README.md", "relative_path_en": "/solution/0000-0099/0041.First%20Missing%20Positive/README_EN.md", "title_cn": "\u7f3a\u5931\u7684\u7b2c\u4e00\u4e2a\u6b63\u6570", "title_en": "First Missing Positive", "question_title_slug": "first-missing-positive", "content_en": "

    Given an unsorted integer array nums, find the smallest missing positive integer.

    \n\n

    You must implement an algorithm that runs in O(n) time and uses constant extra space.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [1,2,0]\nOutput: 3\n

    Example 2:

    \n
    Input: nums = [3,4,-1,1]\nOutput: 2\n

    Example 3:

    \n
    Input: nums = [7,8,9,11,12]\nOutput: 1\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 5 * 105
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u672a\u6392\u5e8f\u7684\u6574\u6570\u6570\u7ec4 nums \uff0c\u8bf7\u4f60\u627e\u51fa\u5176\u4e2d\u6ca1\u6709\u51fa\u73b0\u7684\u6700\u5c0f\u7684\u6b63\u6574\u6570\u3002

    \n\u8bf7\u4f60\u5b9e\u73b0\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n) \u5e76\u4e14\u53ea\u4f7f\u7528\u5e38\u6570\u7ea7\u522b\u989d\u5916\u7a7a\u95f4\u7684\u89e3\u51b3\u65b9\u6848\u3002\n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,0]\n\u8f93\u51fa\uff1a3\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [3,4,-1,1]\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [7,8,9,11,12]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 5 * 105
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int firstMissingPositive(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int firstMissingPositive(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def firstMissingPositive(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def firstMissingPositive(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint firstMissingPositive(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FirstMissingPositive(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar firstMissingPositive = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef first_missing_positive(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func firstMissingPositive(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func firstMissingPositive(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def firstMissingPositive(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun firstMissingPositive(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn first_missing_positive(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function firstMissingPositive($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function firstMissingPositive(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (first-missing-positive nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0041](https://leetcode-cn.com/problems/first-missing-positive)", "[\u7f3a\u5931\u7684\u7b2c\u4e00\u4e2a\u6b63\u6570](/solution/0000-0099/0041.First%20Missing%20Positive/README.md)", "`\u6570\u7ec4`", "\u56f0\u96be", ""], "md_table_row_en": ["[0041](https://leetcode.com/problems/first-missing-positive)", "[First Missing Positive](/solution/0000-0099/0041.First%20Missing%20Positive/README_EN.md)", "`Array`", "Hard", ""]}, {"question_id": "0040", "frontend_question_id": "0040", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/combination-sum-ii", "url_en": "https://leetcode.com/problems/combination-sum-ii", "relative_path_cn": "/solution/0000-0099/0040.Combination%20Sum%20II/README.md", "relative_path_en": "/solution/0000-0099/0040.Combination%20Sum%20II/README_EN.md", "title_cn": "\u7ec4\u5408\u603b\u548c II", "title_en": "Combination Sum II", "question_title_slug": "combination-sum-ii", "content_en": "

    Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numbers sum to target.

    \n\n

    Each number in candidates may only be used once in the combination.

    \n\n

    Note: The solution set must not contain duplicate combinations.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: candidates = [10,1,2,7,6,1,5], target = 8\nOutput: \n[\n[1,1,6],\n[1,2,5],\n[1,7],\n[2,6]\n]\n
    \n\n

    Example 2:

    \n\n
    \nInput: candidates = [2,5,2,1,2], target = 5\nOutput: \n[\n[1,2,2],\n[5]\n]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= candidates.length <= 100
    • \n\t
    • 1 <= candidates[i] <= 50
    • \n\t
    • 1 <= target <= 30
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6570\u7ec4 candidates \u548c\u4e00\u4e2a\u76ee\u6807\u6570 target \uff0c\u627e\u51fa candidates \u4e2d\u6240\u6709\u53ef\u4ee5\u4f7f\u6570\u5b57\u548c\u4e3a target \u7684\u7ec4\u5408\u3002

    \n\n

    candidates \u4e2d\u7684\u6bcf\u4e2a\u6570\u5b57\u5728\u6bcf\u4e2a\u7ec4\u5408\u4e2d\u53ea\u80fd\u4f7f\u7528\u4e00\u6b21\u3002

    \n\n

    \u8bf4\u660e\uff1a

    \n\n
      \n\t
    • \u6240\u6709\u6570\u5b57\uff08\u5305\u62ec\u76ee\u6807\u6570\uff09\u90fd\u662f\u6b63\u6574\u6570\u3002
    • \n\t
    • \u89e3\u96c6\u4e0d\u80fd\u5305\u542b\u91cd\u590d\u7684\u7ec4\u5408\u3002 
    • \n
    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: candidates = [10,1,2,7,6,1,5], target = 8,\n\u6240\u6c42\u89e3\u96c6\u4e3a:\n[\n  [1, 7],\n  [1, 2, 5],\n  [2, 6],\n  [1, 1, 6]\n]\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: candidates = [2,5,2,1,2], target = 5,\n\u6240\u6c42\u89e3\u96c6\u4e3a:\n[\n  [1,2,2],\n  [5]\n]
    \n", "tags_en": ["Array", "Backtracking"], "tags_cn": ["\u6570\u7ec4", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> combinationSum2(vector& candidates, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> combinationSum2(int[] candidates, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def combinationSum2(self, candidates, target):\n \"\"\"\n :type candidates: List[int]\n :type target: int\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def combinationSum2(self, candidates: List[int], target: int) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** combinationSum2(int* candidates, int candidatesSize, int target, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> CombinationSum2(int[] candidates, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} candidates\n * @param {number} target\n * @return {number[][]}\n */\nvar combinationSum2 = function(candidates, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} candidates\n# @param {Integer} target\n# @return {Integer[][]}\ndef combination_sum2(candidates, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func combinationSum2(_ candidates: [Int], _ target: Int) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func combinationSum2(candidates []int, target int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def combinationSum2(candidates: Array[Int], target: Int): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun combinationSum2(candidates: IntArray, target: Int): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn combination_sum2(candidates: Vec, target: i32) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $candidates\n * @param Integer $target\n * @return Integer[][]\n */\n function combinationSum2($candidates, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function combinationSum2(candidates: number[], target: number): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (combination-sum2 candidates target)\n (-> (listof exact-integer?) exact-integer? (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0040](https://leetcode-cn.com/problems/combination-sum-ii)", "[\u7ec4\u5408\u603b\u548c II](/solution/0000-0099/0040.Combination%20Sum%20II/README.md)", "`\u6570\u7ec4`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0040](https://leetcode.com/problems/combination-sum-ii)", "[Combination Sum II](/solution/0000-0099/0040.Combination%20Sum%20II/README_EN.md)", "`Array`,`Backtracking`", "Medium", ""]}, {"question_id": "0039", "frontend_question_id": "0039", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/combination-sum", "url_en": "https://leetcode.com/problems/combination-sum", "relative_path_cn": "/solution/0000-0099/0039.Combination%20Sum/README.md", "relative_path_en": "/solution/0000-0099/0039.Combination%20Sum/README_EN.md", "title_cn": "\u7ec4\u5408\u603b\u548c", "title_en": "Combination Sum", "question_title_slug": "combination-sum", "content_en": "

    Given an array of distinct integers candidates and a target integer target, return a list of all unique combinations of candidates where the chosen numbers sum to target. You may return the combinations in any order.

    \n\n

    The same number may be chosen from candidates an unlimited number of times. Two combinations are unique if the frequency of at least one of the chosen numbers is different.

    \n\n

    It is guaranteed that the number of unique combinations that sum up to target is less than 150 combinations for the given input.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: candidates = [2,3,6,7], target = 7\nOutput: [[2,2,3],[7]]\nExplanation:\n2 and 3 are candidates, and 2 + 2 + 3 = 7. Note that 2 can be used multiple times.\n7 is a candidate, and 7 = 7.\nThese are the only two combinations.\n
    \n\n

    Example 2:

    \n\n
    \nInput: candidates = [2,3,5], target = 8\nOutput: [[2,2,2,2],[2,3,3],[3,5]]\n
    \n\n

    Example 3:

    \n\n
    \nInput: candidates = [2], target = 1\nOutput: []\n
    \n\n

    Example 4:

    \n\n
    \nInput: candidates = [1], target = 1\nOutput: [[1]]\n
    \n\n

    Example 5:

    \n\n
    \nInput: candidates = [1], target = 2\nOutput: [[1,1]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= candidates.length <= 30
    • \n\t
    • 1 <= candidates[i] <= 200
    • \n\t
    • All elements of candidates are distinct.
    • \n\t
    • 1 <= target <= 500
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u65e0\u91cd\u590d\u5143\u7d20\u7684\u6570\u7ec4 candidates \u548c\u4e00\u4e2a\u76ee\u6807\u6570 target \uff0c\u627e\u51fa candidates \u4e2d\u6240\u6709\u53ef\u4ee5\u4f7f\u6570\u5b57\u548c\u4e3a target \u7684\u7ec4\u5408\u3002

    \n\n

    candidates \u4e2d\u7684\u6570\u5b57\u53ef\u4ee5\u65e0\u9650\u5236\u91cd\u590d\u88ab\u9009\u53d6\u3002

    \n\n

    \u8bf4\u660e\uff1a

    \n\n
      \n\t
    • \u6240\u6709\u6570\u5b57\uff08\u5305\u62ec target\uff09\u90fd\u662f\u6b63\u6574\u6570\u3002
    • \n\t
    • \u89e3\u96c6\u4e0d\u80fd\u5305\u542b\u91cd\u590d\u7684\u7ec4\u5408\u3002 
    • \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1acandidates = [2,3,6,7], target = 7,\n\u6240\u6c42\u89e3\u96c6\u4e3a\uff1a\n[\n  [7],\n  [2,2,3]\n]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1acandidates = [2,3,5], target = 8,\n\u6240\u6c42\u89e3\u96c6\u4e3a\uff1a\n[\n  [2,2,2,2],\n  [2,3,3],\n  [3,5]\n]
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= candidates.length <= 30
    • \n\t
    • 1 <= candidates[i] <= 200
    • \n\t
    • candidate \u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u90fd\u662f\u72ec\u4e00\u65e0\u4e8c\u7684\u3002
    • \n\t
    • 1 <= target <= 500
    • \n
    \n", "tags_en": ["Array", "Backtracking"], "tags_cn": ["\u6570\u7ec4", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> combinationSum(vector& candidates, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> combinationSum(int[] candidates, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def combinationSum(self, candidates, target):\n \"\"\"\n :type candidates: List[int]\n :type target: int\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** combinationSum(int* candidates, int candidatesSize, int target, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> CombinationSum(int[] candidates, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} candidates\n * @param {number} target\n * @return {number[][]}\n */\nvar combinationSum = function(candidates, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} candidates\n# @param {Integer} target\n# @return {Integer[][]}\ndef combination_sum(candidates, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func combinationSum(_ candidates: [Int], _ target: Int) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func combinationSum(candidates []int, target int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def combinationSum(candidates: Array[Int], target: Int): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun combinationSum(candidates: IntArray, target: Int): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn combination_sum(candidates: Vec, target: i32) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $candidates\n * @param Integer $target\n * @return Integer[][]\n */\n function combinationSum($candidates, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function combinationSum(candidates: number[], target: number): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (combination-sum candidates target)\n (-> (listof exact-integer?) exact-integer? (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0039](https://leetcode-cn.com/problems/combination-sum)", "[\u7ec4\u5408\u603b\u548c](/solution/0000-0099/0039.Combination%20Sum/README.md)", "`\u6570\u7ec4`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0039](https://leetcode.com/problems/combination-sum)", "[Combination Sum](/solution/0000-0099/0039.Combination%20Sum/README_EN.md)", "`Array`,`Backtracking`", "Medium", ""]}, {"question_id": "0038", "frontend_question_id": "0038", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-and-say", "url_en": "https://leetcode.com/problems/count-and-say", "relative_path_cn": "/solution/0000-0099/0038.Count%20and%20Say/README.md", "relative_path_en": "/solution/0000-0099/0038.Count%20and%20Say/README_EN.md", "title_cn": "\u5916\u89c2\u6570\u5217", "title_en": "Count and Say", "question_title_slug": "count-and-say", "content_en": "

    The count-and-say sequence is a sequence of digit strings defined by the recursive formula:

    \n\n
      \n\t
    • countAndSay(1) = "1"
    • \n\t
    • countAndSay(n) is the way you would "say" the digit string from countAndSay(n-1), which is then converted into a different digit string.
    • \n
    \n\n

    To determine how you "say" a digit string, split it into the minimal number of groups so that each group is a contiguous section all of the same character. Then for each group, say the number of characters, then say the character. To convert the saying into a digit string, replace the counts with a number and concatenate every saying.

    \n\n

    For example, the saying and conversion for digit string "3322251":

    \n\"\"\n

    Given a positive integer n, return the nth term of the count-and-say sequence.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 1\nOutput: "1"\nExplanation: This is the base case.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 4\nOutput: "1211"\nExplanation:\ncountAndSay(1) = "1"\ncountAndSay(2) = say "1" = one 1 = "11"\ncountAndSay(3) = say "11" = two 1's = "21"\ncountAndSay(4) = say "21" = one 2 + one 1 = "12" + "11" = "1211"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 30
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6b63\u6574\u6570 n \uff0c\u8f93\u51fa\u5916\u89c2\u6570\u5217\u7684\u7b2c n \u9879\u3002

    \n\n

    \u300c\u5916\u89c2\u6570\u5217\u300d\u662f\u4e00\u4e2a\u6574\u6570\u5e8f\u5217\uff0c\u4ece\u6570\u5b57 1 \u5f00\u59cb\uff0c\u5e8f\u5217\u4e2d\u7684\u6bcf\u4e00\u9879\u90fd\u662f\u5bf9\u524d\u4e00\u9879\u7684\u63cf\u8ff0\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u5c06\u5176\u89c6\u4f5c\u662f\u7531\u9012\u5f52\u516c\u5f0f\u5b9a\u4e49\u7684\u6570\u5b57\u5b57\u7b26\u4e32\u5e8f\u5217\uff1a

    \n\n
      \n\t
    • countAndSay(1) = \"1\"
    • \n\t
    • countAndSay(n) \u662f\u5bf9 countAndSay(n-1) \u7684\u63cf\u8ff0\uff0c\u7136\u540e\u8f6c\u6362\u6210\u53e6\u4e00\u4e2a\u6570\u5b57\u5b57\u7b26\u4e32\u3002
    • \n
    \n\n

    \u524d\u4e94\u9879\u5982\u4e0b\uff1a

    \n\n
    \n1.     1\n2.     11\n3.     21\n4.     1211\n5.     111221\n\u7b2c\u4e00\u9879\u662f\u6570\u5b57 1 \n\u63cf\u8ff0\u524d\u4e00\u9879\uff0c\u8fd9\u4e2a\u6570\u662f 1 \u5373 \u201c \u4e00 \u4e2a 1 \u201d\uff0c\u8bb0\u4f5c \"11\"\n\u63cf\u8ff0\u524d\u4e00\u9879\uff0c\u8fd9\u4e2a\u6570\u662f 11 \u5373 \u201c \u4e8c \u4e2a 1 \u201d \uff0c\u8bb0\u4f5c \"21\"\n\u63cf\u8ff0\u524d\u4e00\u9879\uff0c\u8fd9\u4e2a\u6570\u662f 21 \u5373 \u201c \u4e00 \u4e2a 2 + \u4e00 \u4e2a 1 \u201d \uff0c\u8bb0\u4f5c \"1211\"\n\u63cf\u8ff0\u524d\u4e00\u9879\uff0c\u8fd9\u4e2a\u6570\u662f 1211 \u5373 \u201c \u4e00 \u4e2a 1 + \u4e00 \u4e2a 2 + \u4e8c \u4e2a 1 \u201d \uff0c\u8bb0\u4f5c \"111221\"\n
    \n\n

    \u8981 \u63cf\u8ff0 \u4e00\u4e2a\u6570\u5b57\u5b57\u7b26\u4e32\uff0c\u9996\u5148\u8981\u5c06\u5b57\u7b26\u4e32\u5206\u5272\u4e3a \u6700\u5c0f \u6570\u91cf\u7684\u7ec4\uff0c\u6bcf\u4e2a\u7ec4\u90fd\u7531\u8fde\u7eed\u7684\u6700\u591a \u76f8\u540c\u5b57\u7b26 \u7ec4\u6210\u3002\u7136\u540e\u5bf9\u4e8e\u6bcf\u4e2a\u7ec4\uff0c\u5148\u63cf\u8ff0\u5b57\u7b26\u7684\u6570\u91cf\uff0c\u7136\u540e\u63cf\u8ff0\u5b57\u7b26\uff0c\u5f62\u6210\u4e00\u4e2a\u63cf\u8ff0\u7ec4\u3002\u8981\u5c06\u63cf\u8ff0\u8f6c\u6362\u4e3a\u6570\u5b57\u5b57\u7b26\u4e32\uff0c\u5148\u5c06\u6bcf\u7ec4\u4e2d\u7684\u5b57\u7b26\u6570\u91cf\u7528\u6570\u5b57\u66ff\u6362\uff0c\u518d\u5c06\u6240\u6709\u63cf\u8ff0\u7ec4\u8fde\u63a5\u8d77\u6765\u3002

    \n\n

    \u4f8b\u5982\uff0c\u6570\u5b57\u5b57\u7b26\u4e32 \"3322251\" \u7684\u63cf\u8ff0\u5982\u4e0b\u56fe\uff1a

    \n\"\"\n
      \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1a\"1\"\n\u89e3\u91ca\uff1a\u8fd9\u662f\u4e00\u4e2a\u57fa\u672c\u6837\u4f8b\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 4\n\u8f93\u51fa\uff1a\"1211\"\n\u89e3\u91ca\uff1a\ncountAndSay(1) = \"1\"\ncountAndSay(2) = \u8bfb \"1\" = \u4e00 \u4e2a 1 = \"11\"\ncountAndSay(3) = \u8bfb \"11\" = \u4e8c \u4e2a 1 = \"21\"\ncountAndSay(4) = \u8bfb \"21\" = \u4e00 \u4e2a 2 + \u4e00 \u4e2a 1 = \"12\" + \"11\" = \"1211\"\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 30
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string countAndSay(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String countAndSay(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countAndSay(self, n):\n \"\"\"\n :type n: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countAndSay(self, n: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * countAndSay(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string CountAndSay(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {string}\n */\nvar countAndSay = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {String}\ndef count_and_say(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countAndSay(_ n: Int) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countAndSay(n int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countAndSay(n: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countAndSay(n: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_and_say(n: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return String\n */\n function countAndSay($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countAndSay(n: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-and-say n)\n (-> exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0038](https://leetcode-cn.com/problems/count-and-say)", "[\u5916\u89c2\u6570\u5217](/solution/0000-0099/0038.Count%20and%20Say/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0038](https://leetcode.com/problems/count-and-say)", "[Count and Say](/solution/0000-0099/0038.Count%20and%20Say/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "0037", "frontend_question_id": "0037", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sudoku-solver", "url_en": "https://leetcode.com/problems/sudoku-solver", "relative_path_cn": "/solution/0000-0099/0037.Sudoku%20Solver/README.md", "relative_path_en": "/solution/0000-0099/0037.Sudoku%20Solver/README_EN.md", "title_cn": "\u89e3\u6570\u72ec", "title_en": "Sudoku Solver", "question_title_slug": "sudoku-solver", "content_en": "

    Write a program to solve a Sudoku puzzle by filling the empty cells.

    \n\n

    A sudoku solution must satisfy all of the following rules:

    \n\n
      \n\t
    1. Each of the digits 1-9 must occur exactly once in each row.
    2. \n\t
    3. Each of the digits 1-9 must occur exactly once in each column.
    4. \n\t
    5. Each of the digits 1-9 must occur exactly once in each of the 9 3x3 sub-boxes of the grid.
    6. \n
    \n\n

    The '.' character indicates empty cells.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: board = [["5","3",".",".","7",".",".",".","."],["6",".",".","1","9","5",".",".","."],[".","9","8",".",".",".",".","6","."],["8",".",".",".","6",".",".",".","3"],["4",".",".","8",".","3",".",".","1"],["7",".",".",".","2",".",".",".","6"],[".","6",".",".",".",".","2","8","."],[".",".",".","4","1","9",".",".","5"],[".",".",".",".","8",".",".","7","9"]]\nOutput: [["5","3","4","6","7","8","9","1","2"],["6","7","2","1","9","5","3","4","8"],["1","9","8","3","4","2","5","6","7"],["8","5","9","7","6","1","4","2","3"],["4","2","6","8","5","3","7","9","1"],["7","1","3","9","2","4","8","5","6"],["9","6","1","5","3","7","2","8","4"],["2","8","7","4","1","9","6","3","5"],["3","4","5","2","8","6","1","7","9"]]\nExplanation: The input board is shown above and the only valid solution is shown below:\n\n\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • board.length == 9
    • \n\t
    • board[i].length == 9
    • \n\t
    • board[i][j] is a digit or '.'.
    • \n\t
    • It is guaranteed that the input board has only one solution.
    • \n
    \n", "content_cn": "

    \u7f16\u5199\u4e00\u4e2a\u7a0b\u5e8f\uff0c\u901a\u8fc7\u586b\u5145\u7a7a\u683c\u6765\u89e3\u51b3\u6570\u72ec\u95ee\u9898\u3002

    \n\n

    \u6570\u72ec\u7684\u89e3\u6cd5\u9700 \u9075\u5faa\u5982\u4e0b\u89c4\u5219\uff1a

    \n\n
      \n\t
    1. \u6570\u5b57\u00a01-9\u00a0\u5728\u6bcf\u4e00\u884c\u53ea\u80fd\u51fa\u73b0\u4e00\u6b21\u3002
    2. \n\t
    3. \u6570\u5b57\u00a01-9\u00a0\u5728\u6bcf\u4e00\u5217\u53ea\u80fd\u51fa\u73b0\u4e00\u6b21\u3002
    4. \n\t
    5. \u6570\u5b57\u00a01-9\u00a0\u5728\u6bcf\u4e00\u4e2a\u4ee5\u7c97\u5b9e\u7ebf\u5206\u9694\u7684\u00a03x3\u00a0\u5bab\u5185\u53ea\u80fd\u51fa\u73b0\u4e00\u6b21\u3002\uff08\u8bf7\u53c2\u8003\u793a\u4f8b\u56fe\uff09
    6. \n
    \n\n

    \u6570\u72ec\u90e8\u5206\u7a7a\u683c\u5185\u5df2\u586b\u5165\u4e86\u6570\u5b57\uff0c\u7a7a\u767d\u683c\u7528\u00a0'.'\u00a0\u8868\u793a\u3002

    \n\n

    \u00a0

    \n\n
    \n
    \n
    \n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1aboard = [[\"5\",\"3\",\".\",\".\",\"7\",\".\",\".\",\".\",\".\"],[\"6\",\".\",\".\",\"1\",\"9\",\"5\",\".\",\".\",\".\"],[\".\",\"9\",\"8\",\".\",\".\",\".\",\".\",\"6\",\".\"],[\"8\",\".\",\".\",\".\",\"6\",\".\",\".\",\".\",\"3\"],[\"4\",\".\",\".\",\"8\",\".\",\"3\",\".\",\".\",\"1\"],[\"7\",\".\",\".\",\".\",\"2\",\".\",\".\",\".\",\"6\"],[\".\",\"6\",\".\",\".\",\".\",\".\",\"2\",\"8\",\".\"],[\".\",\".\",\".\",\"4\",\"1\",\"9\",\".\",\".\",\"5\"],[\".\",\".\",\".\",\".\",\"8\",\".\",\".\",\"7\",\"9\"]]\n\u8f93\u51fa\uff1a[[\"5\",\"3\",\"4\",\"6\",\"7\",\"8\",\"9\",\"1\",\"2\"],[\"6\",\"7\",\"2\",\"1\",\"9\",\"5\",\"3\",\"4\",\"8\"],[\"1\",\"9\",\"8\",\"3\",\"4\",\"2\",\"5\",\"6\",\"7\"],[\"8\",\"5\",\"9\",\"7\",\"6\",\"1\",\"4\",\"2\",\"3\"],[\"4\",\"2\",\"6\",\"8\",\"5\",\"3\",\"7\",\"9\",\"1\"],[\"7\",\"1\",\"3\",\"9\",\"2\",\"4\",\"8\",\"5\",\"6\"],[\"9\",\"6\",\"1\",\"5\",\"3\",\"7\",\"2\",\"8\",\"4\"],[\"2\",\"8\",\"7\",\"4\",\"1\",\"9\",\"6\",\"3\",\"5\"],[\"3\",\"4\",\"5\",\"2\",\"8\",\"6\",\"1\",\"7\",\"9\"]]\n\u89e3\u91ca\uff1a\u8f93\u5165\u7684\u6570\u72ec\u5982\u4e0a\u56fe\u6240\u793a\uff0c\u552f\u4e00\u6709\u6548\u7684\u89e3\u51b3\u65b9\u6848\u5982\u4e0b\u6240\u793a\uff1a\n\n\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • board.length == 9
    • \n\t
    • board[i].length == 9
    • \n\t
    • board[i][j] \u662f\u4e00\u4f4d\u6570\u5b57\u6216\u8005 '.'
    • \n\t
    • \u9898\u76ee\u6570\u636e \u4fdd\u8bc1 \u8f93\u5165\u6570\u72ec\u4ec5\u6709\u4e00\u4e2a\u89e3
    • \n
    \n
    \n
    \n
    \n", "tags_en": ["Hash Table", "Backtracking"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n void solveSudoku(vector>& board) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public void solveSudoku(char[][] board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def solveSudoku(self, board):\n \"\"\"\n :type board: List[List[str]]\n :rtype: None Do not return anything, modify board in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def solveSudoku(self, board: List[List[str]]) -> None:\n \"\"\"\n Do not return anything, modify board in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nvoid solveSudoku(char** board, int boardSize, int* boardColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public void SolveSudoku(char[][] board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {character[][]} board\n * @return {void} Do not return anything, modify board in-place instead.\n */\nvar solveSudoku = function(board) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Character[][]} board\n# @return {Void} Do not return anything, modify board in-place instead.\ndef solve_sudoku(board)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func solveSudoku(_ board: inout [[Character]]) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func solveSudoku(board [][]byte) {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def solveSudoku(board: Array[Array[Char]]): Unit = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun solveSudoku(board: Array): Unit {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn solve_sudoku(board: &mut Vec>) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $board\n * @return NULL\n */\n function solveSudoku(&$board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n Do not return anything, modify board in-place instead.\n */\nfunction solveSudoku(board: string[][]): void {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0037](https://leetcode-cn.com/problems/sudoku-solver)", "[\u89e3\u6570\u72ec](/solution/0000-0099/0037.Sudoku%20Solver/README.md)", "`\u54c8\u5e0c\u8868`,`\u56de\u6eaf\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[0037](https://leetcode.com/problems/sudoku-solver)", "[Sudoku Solver](/solution/0000-0099/0037.Sudoku%20Solver/README_EN.md)", "`Hash Table`,`Backtracking`", "Hard", ""]}, {"question_id": "0036", "frontend_question_id": "0036", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/valid-sudoku", "url_en": "https://leetcode.com/problems/valid-sudoku", "relative_path_cn": "/solution/0000-0099/0036.Valid%20Sudoku/README.md", "relative_path_en": "/solution/0000-0099/0036.Valid%20Sudoku/README_EN.md", "title_cn": "\u6709\u6548\u7684\u6570\u72ec", "title_en": "Valid Sudoku", "question_title_slug": "valid-sudoku", "content_en": "

    Determine if a 9 x 9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules:

    \n\n
      \n\t
    1. Each row must contain the digits 1-9 without repetition.
    2. \n\t
    3. Each column must contain the digits 1-9 without repetition.
    4. \n\t
    5. Each of the nine 3 x 3 sub-boxes of the grid must contain the digits 1-9 without repetition.
    6. \n
    \n\n

    Note:

    \n\n
      \n\t
    • A Sudoku board (partially filled) could be valid but is not necessarily solvable.
    • \n\t
    • Only the filled cells need to be validated according to the mentioned rules.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: board = \n[["5","3",".",".","7",".",".",".","."]\n,["6",".",".","1","9","5",".",".","."]\n,[".","9","8",".",".",".",".","6","."]\n,["8",".",".",".","6",".",".",".","3"]\n,["4",".",".","8",".","3",".",".","1"]\n,["7",".",".",".","2",".",".",".","6"]\n,[".","6",".",".",".",".","2","8","."]\n,[".",".",".","4","1","9",".",".","5"]\n,[".",".",".",".","8",".",".","7","9"]]\nOutput: true\n
    \n\n

    Example 2:

    \n\n
    \nInput: board = \n[["8","3",".",".","7",".",".",".","."]\n,["6",".",".","1","9","5",".",".","."]\n,[".","9","8",".",".",".",".","6","."]\n,["8",".",".",".","6",".",".",".","3"]\n,["4",".",".","8",".","3",".",".","1"]\n,["7",".",".",".","2",".",".",".","6"]\n,[".","6",".",".",".",".","2","8","."]\n,[".",".",".","4","1","9",".",".","5"]\n,[".",".",".",".","8",".",".","7","9"]]\nOutput: false\nExplanation: Same as Example 1, except with the 5 in the top left corner being modified to 8. Since there are two 8's in the top left 3x3 sub-box, it is invalid.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • board.length == 9
    • \n\t
    • board[i].length == 9
    • \n\t
    • board[i][j] is a digit or '.'.
    • \n
    \n", "content_cn": "

    \u8bf7\u4f60\u5224\u65ad\u4e00\u4e2a\u00a09x9 \u7684\u6570\u72ec\u662f\u5426\u6709\u6548\u3002\u53ea\u9700\u8981 \u6839\u636e\u4ee5\u4e0b\u89c4\u5219 \uff0c\u9a8c\u8bc1\u5df2\u7ecf\u586b\u5165\u7684\u6570\u5b57\u662f\u5426\u6709\u6548\u5373\u53ef\u3002

    \n\n
      \n\t
    1. \u6570\u5b57\u00a01-9\u00a0\u5728\u6bcf\u4e00\u884c\u53ea\u80fd\u51fa\u73b0\u4e00\u6b21\u3002
    2. \n\t
    3. \u6570\u5b57\u00a01-9\u00a0\u5728\u6bcf\u4e00\u5217\u53ea\u80fd\u51fa\u73b0\u4e00\u6b21\u3002
    4. \n\t
    5. \u6570\u5b57\u00a01-9\u00a0\u5728\u6bcf\u4e00\u4e2a\u4ee5\u7c97\u5b9e\u7ebf\u5206\u9694\u7684\u00a03x3\u00a0\u5bab\u5185\u53ea\u80fd\u51fa\u73b0\u4e00\u6b21\u3002\uff08\u8bf7\u53c2\u8003\u793a\u4f8b\u56fe\uff09
    6. \n
    \n\n

    \u6570\u72ec\u90e8\u5206\u7a7a\u683c\u5185\u5df2\u586b\u5165\u4e86\u6570\u5b57\uff0c\u7a7a\u767d\u683c\u7528\u00a0'.'\u00a0\u8868\u793a\u3002

    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    • \u4e00\u4e2a\u6709\u6548\u7684\u6570\u72ec\uff08\u90e8\u5206\u5df2\u88ab\u586b\u5145\uff09\u4e0d\u4e00\u5b9a\u662f\u53ef\u89e3\u7684\u3002
    • \n\t
    • \u53ea\u9700\u8981\u6839\u636e\u4ee5\u4e0a\u89c4\u5219\uff0c\u9a8c\u8bc1\u5df2\u7ecf\u586b\u5165\u7684\u6570\u5b57\u662f\u5426\u6709\u6548\u5373\u53ef\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aboard = \n[[\"5\",\"3\",\".\",\".\",\"7\",\".\",\".\",\".\",\".\"]\n,[\"6\",\".\",\".\",\"1\",\"9\",\"5\",\".\",\".\",\".\"]\n,[\".\",\"9\",\"8\",\".\",\".\",\".\",\".\",\"6\",\".\"]\n,[\"8\",\".\",\".\",\".\",\"6\",\".\",\".\",\".\",\"3\"]\n,[\"4\",\".\",\".\",\"8\",\".\",\"3\",\".\",\".\",\"1\"]\n,[\"7\",\".\",\".\",\".\",\"2\",\".\",\".\",\".\",\"6\"]\n,[\".\",\"6\",\".\",\".\",\".\",\".\",\"2\",\"8\",\".\"]\n,[\".\",\".\",\".\",\"4\",\"1\",\"9\",\".\",\".\",\"5\"]\n,[\".\",\".\",\".\",\".\",\"8\",\".\",\".\",\"7\",\"9\"]]\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aboard = \n[[\"8\",\"3\",\".\",\".\",\"7\",\".\",\".\",\".\",\".\"]\n,[\"6\",\".\",\".\",\"1\",\"9\",\"5\",\".\",\".\",\".\"]\n,[\".\",\"9\",\"8\",\".\",\".\",\".\",\".\",\"6\",\".\"]\n,[\"8\",\".\",\".\",\".\",\"6\",\".\",\".\",\".\",\"3\"]\n,[\"4\",\".\",\".\",\"8\",\".\",\"3\",\".\",\".\",\"1\"]\n,[\"7\",\".\",\".\",\".\",\"2\",\".\",\".\",\".\",\"6\"]\n,[\".\",\"6\",\".\",\".\",\".\",\".\",\"2\",\"8\",\".\"]\n,[\".\",\".\",\".\",\"4\",\"1\",\"9\",\".\",\".\",\"5\"]\n,[\".\",\".\",\".\",\".\",\"8\",\".\",\".\",\"7\",\"9\"]]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u9664\u4e86\u7b2c\u4e00\u884c\u7684\u7b2c\u4e00\u4e2a\u6570\u5b57\u4ece 5 \u6539\u4e3a 8 \u4ee5\u5916\uff0c\u7a7a\u683c\u5185\u5176\u4ed6\u6570\u5b57\u5747\u4e0e \u793a\u4f8b1 \u76f8\u540c\u3002 \u4f46\u7531\u4e8e\u4f4d\u4e8e\u5de6\u4e0a\u89d2\u7684 3x3 \u5bab\u5185\u6709\u4e24\u4e2a 8 \u5b58\u5728, \u56e0\u6b64\u8fd9\u4e2a\u6570\u72ec\u662f\u65e0\u6548\u7684\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • board.length == 9
    • \n\t
    • board[i].length == 9
    • \n\t
    • board[i][j] \u662f\u4e00\u4f4d\u6570\u5b57\u6216\u8005 '.'
    • \n
    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isValidSudoku(vector>& board) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isValidSudoku(char[][] board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isValidSudoku(self, board):\n \"\"\"\n :type board: List[List[str]]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isValidSudoku(self, board: List[List[str]]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isValidSudoku(char** board, int boardSize, int* boardColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsValidSudoku(char[][] board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {character[][]} board\n * @return {boolean}\n */\nvar isValidSudoku = function(board) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Character[][]} board\n# @return {Boolean}\ndef is_valid_sudoku(board)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isValidSudoku(_ board: [[Character]]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isValidSudoku(board [][]byte) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isValidSudoku(board: Array[Array[Char]]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isValidSudoku(board: Array): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_valid_sudoku(board: Vec>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $board\n * @return Boolean\n */\n function isValidSudoku($board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isValidSudoku(board: string[][]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-valid-sudoku board)\n (-> (listof (listof char?)) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0036](https://leetcode-cn.com/problems/valid-sudoku)", "[\u6709\u6548\u7684\u6570\u72ec](/solution/0000-0099/0036.Valid%20Sudoku/README.md)", "`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0036](https://leetcode.com/problems/valid-sudoku)", "[Valid Sudoku](/solution/0000-0099/0036.Valid%20Sudoku/README_EN.md)", "`Hash Table`", "Medium", ""]}, {"question_id": "0035", "frontend_question_id": "0035", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/search-insert-position", "url_en": "https://leetcode.com/problems/search-insert-position", "relative_path_cn": "/solution/0000-0099/0035.Search%20Insert%20Position/README.md", "relative_path_en": "/solution/0000-0099/0035.Search%20Insert%20Position/README_EN.md", "title_cn": "\u641c\u7d22\u63d2\u5165\u4f4d\u7f6e", "title_en": "Search Insert Position", "question_title_slug": "search-insert-position", "content_en": "

    Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.

    \n\n

    You must write an algorithm with O(log n) runtime complexity.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [1,3,5,6], target = 5\nOutput: 2\n

    Example 2:

    \n
    Input: nums = [1,3,5,6], target = 2\nOutput: 1\n

    Example 3:

    \n
    Input: nums = [1,3,5,6], target = 7\nOutput: 4\n

    Example 4:

    \n
    Input: nums = [1,3,5,6], target = 0\nOutput: 0\n

    Example 5:

    \n
    Input: nums = [1], target = 0\nOutput: 0\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 104
    • \n\t
    • -104 <= nums[i] <= 104
    • \n\t
    • nums contains distinct values sorted in ascending order.
    • \n\t
    • -104 <= target <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6392\u5e8f\u6570\u7ec4\u548c\u4e00\u4e2a\u76ee\u6807\u503c\uff0c\u5728\u6570\u7ec4\u4e2d\u627e\u5230\u76ee\u6807\u503c\uff0c\u5e76\u8fd4\u56de\u5176\u7d22\u5f15\u3002\u5982\u679c\u76ee\u6807\u503c\u4e0d\u5b58\u5728\u4e8e\u6570\u7ec4\u4e2d\uff0c\u8fd4\u56de\u5b83\u5c06\u4f1a\u88ab\u6309\u987a\u5e8f\u63d2\u5165\u7684\u4f4d\u7f6e\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u5047\u8bbe\u6570\u7ec4\u4e2d\u65e0\u91cd\u590d\u5143\u7d20\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: [1,3,5,6], 5\n\u8f93\u51fa: 2\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: [1,3,5,6], 2\n\u8f93\u51fa: 1\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u8f93\u5165: [1,3,5,6], 7\n\u8f93\u51fa: 4\n
    \n\n

    \u793a\u4f8b 4:

    \n\n
    \u8f93\u5165: [1,3,5,6], 0\n\u8f93\u51fa: 0\n
    \n", "tags_en": ["Array", "Binary Search"], "tags_cn": ["\u6570\u7ec4", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int searchInsert(vector& nums, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int searchInsert(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def searchInsert(self, nums, target):\n \"\"\"\n :type nums: List[int]\n :type target: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def searchInsert(self, nums: List[int], target: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint searchInsert(int* nums, int numsSize, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SearchInsert(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} target\n * @return {number}\n */\nvar searchInsert = function(nums, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} target\n# @return {Integer}\ndef search_insert(nums, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func searchInsert(_ nums: [Int], _ target: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func searchInsert(nums []int, target int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def searchInsert(nums: Array[Int], target: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun searchInsert(nums: IntArray, target: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn search_insert(nums: Vec, target: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $target\n * @return Integer\n */\n function searchInsert($nums, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function searchInsert(nums: number[], target: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (search-insert nums target)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0035](https://leetcode-cn.com/problems/search-insert-position)", "[\u641c\u7d22\u63d2\u5165\u4f4d\u7f6e](/solution/0000-0099/0035.Search%20Insert%20Position/README.md)", "`\u6570\u7ec4`,`\u4e8c\u5206\u67e5\u627e`", "\u7b80\u5355", ""], "md_table_row_en": ["[0035](https://leetcode.com/problems/search-insert-position)", "[Search Insert Position](/solution/0000-0099/0035.Search%20Insert%20Position/README_EN.md)", "`Array`,`Binary Search`", "Easy", ""]}, {"question_id": "0034", "frontend_question_id": "0034", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-first-and-last-position-of-element-in-sorted-array", "url_en": "https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array", "relative_path_cn": "/solution/0000-0099/0034.Find%20First%20and%20Last%20Position%20of%20Element%20in%20Sorted%20Array/README.md", "relative_path_en": "/solution/0000-0099/0034.Find%20First%20and%20Last%20Position%20of%20Element%20in%20Sorted%20Array/README_EN.md", "title_cn": "\u5728\u6392\u5e8f\u6570\u7ec4\u4e2d\u67e5\u627e\u5143\u7d20\u7684\u7b2c\u4e00\u4e2a\u548c\u6700\u540e\u4e00\u4e2a\u4f4d\u7f6e", "title_en": "Find First and Last Position of Element in Sorted Array", "question_title_slug": "find-first-and-last-position-of-element-in-sorted-array", "content_en": "

    Given an array of integers nums sorted in ascending order, find the starting and ending position of a given target value.

    \n\n

    If target is not found in the array, return [-1, -1].

    \n\n

    You must write an algorithm with O(log n) runtime complexity.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [5,7,7,8,8,10], target = 8\nOutput: [3,4]\n

    Example 2:

    \n
    Input: nums = [5,7,7,8,8,10], target = 6\nOutput: [-1,-1]\n

    Example 3:

    \n
    Input: nums = [], target = 0\nOutput: [-1,-1]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= nums.length <= 105
    • \n\t
    • -109 <= nums[i] <= 109
    • \n\t
    • nums is a non-decreasing array.
    • \n\t
    • -109 <= target <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6309\u7167\u5347\u5e8f\u6392\u5217\u7684\u6574\u6570\u6570\u7ec4 nums\uff0c\u548c\u4e00\u4e2a\u76ee\u6807\u503c target\u3002\u627e\u51fa\u7ed9\u5b9a\u76ee\u6807\u503c\u5728\u6570\u7ec4\u4e2d\u7684\u5f00\u59cb\u4f4d\u7f6e\u548c\u7ed3\u675f\u4f4d\u7f6e\u3002

    \n\n

    \u5982\u679c\u6570\u7ec4\u4e2d\u4e0d\u5b58\u5728\u76ee\u6807\u503c target\uff0c\u8fd4\u56de\u00a0[-1, -1]\u3002

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u4f60\u53ef\u4ee5\u8bbe\u8ba1\u5e76\u5b9e\u73b0\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a\u00a0O(log n)\u00a0\u7684\u7b97\u6cd5\u89e3\u51b3\u6b64\u95ee\u9898\u5417\uff1f
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [5,7,7,8,8,10], target = 8\n\u8f93\u51fa\uff1a[3,4]
    \n\n

    \u793a\u4f8b\u00a02\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [5,7,7,8,8,10], target = 6\n\u8f93\u51fa\uff1a[-1,-1]
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [], target = 0\n\u8f93\u51fa\uff1a[-1,-1]
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= nums.length <= 105
    • \n\t
    • -109\u00a0<= nums[i]\u00a0<= 109
    • \n\t
    • nums\u00a0\u662f\u4e00\u4e2a\u975e\u9012\u51cf\u6570\u7ec4
    • \n\t
    • -109\u00a0<= target\u00a0<= 109
    • \n
    \n", "tags_en": ["Array", "Binary Search"], "tags_cn": ["\u6570\u7ec4", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector searchRange(vector& nums, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] searchRange(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def searchRange(self, nums, target):\n \"\"\"\n :type nums: List[int]\n :type target: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def searchRange(self, nums: List[int], target: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* searchRange(int* nums, int numsSize, int target, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] SearchRange(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} target\n * @return {number[]}\n */\nvar searchRange = function(nums, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} target\n# @return {Integer[]}\ndef search_range(nums, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func searchRange(_ nums: [Int], _ target: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func searchRange(nums []int, target int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def searchRange(nums: Array[Int], target: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun searchRange(nums: IntArray, target: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn search_range(nums: Vec, target: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $target\n * @return Integer[]\n */\n function searchRange($nums, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function searchRange(nums: number[], target: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (search-range nums target)\n (-> (listof exact-integer?) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0034](https://leetcode-cn.com/problems/find-first-and-last-position-of-element-in-sorted-array)", "[\u5728\u6392\u5e8f\u6570\u7ec4\u4e2d\u67e5\u627e\u5143\u7d20\u7684\u7b2c\u4e00\u4e2a\u548c\u6700\u540e\u4e00\u4e2a\u4f4d\u7f6e](/solution/0000-0099/0034.Find%20First%20and%20Last%20Position%20of%20Element%20in%20Sorted%20Array/README.md)", "`\u6570\u7ec4`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0034](https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array)", "[Find First and Last Position of Element in Sorted Array](/solution/0000-0099/0034.Find%20First%20and%20Last%20Position%20of%20Element%20in%20Sorted%20Array/README_EN.md)", "`Array`,`Binary Search`", "Medium", ""]}, {"question_id": "0033", "frontend_question_id": "0033", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/search-in-rotated-sorted-array", "url_en": "https://leetcode.com/problems/search-in-rotated-sorted-array", "relative_path_cn": "/solution/0000-0099/0033.Search%20in%20Rotated%20Sorted%20Array/README.md", "relative_path_en": "/solution/0000-0099/0033.Search%20in%20Rotated%20Sorted%20Array/README_EN.md", "title_cn": "\u641c\u7d22\u65cb\u8f6c\u6392\u5e8f\u6570\u7ec4", "title_en": "Search in Rotated Sorted Array", "question_title_slug": "search-in-rotated-sorted-array", "content_en": "

    There is an integer array nums sorted in ascending order (with distinct values).

    \n\n

    Prior to being passed to your function, nums is rotated at an unknown pivot index k (0 <= k < nums.length) such that the resulting array is [nums[k], nums[k+1], ..., nums[n-1], nums[0], nums[1], ..., nums[k-1]] (0-indexed). For example, [0,1,2,4,5,6,7] might be rotated at pivot index 3 and become [4,5,6,7,0,1,2].

    \n\n

    Given the array nums after the rotation and an integer target, return the index of target if it is in nums, or -1 if it is not in nums.

    \n\n

    You must write an algorithm with O(log n) runtime complexity.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [4,5,6,7,0,1,2], target = 0\nOutput: 4\n

    Example 2:

    \n
    Input: nums = [4,5,6,7,0,1,2], target = 3\nOutput: -1\n

    Example 3:

    \n
    Input: nums = [1], target = 0\nOutput: -1\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 5000
    • \n\t
    • -104 <= nums[i] <= 104
    • \n\t
    • All values of nums are unique.
    • \n\t
    • nums is guaranteed to be rotated at some pivot.
    • \n\t
    • -104 <= target <= 104
    • \n
    \n", "content_cn": "

    \u6574\u6570\u6570\u7ec4 nums \u6309\u5347\u5e8f\u6392\u5217\uff0c\u6570\u7ec4\u4e2d\u7684\u503c \u4e92\u4e0d\u76f8\u540c \u3002

    \n\n

    \u5728\u4f20\u9012\u7ed9\u51fd\u6570\u4e4b\u524d\uff0cnums \u5728\u9884\u5148\u672a\u77e5\u7684\u67d0\u4e2a\u4e0b\u6807 k\uff080 <= k < nums.length\uff09\u4e0a\u8fdb\u884c\u4e86 \u65cb\u8f6c\uff0c\u4f7f\u6570\u7ec4\u53d8\u4e3a [nums[k], nums[k+1], ..., nums[n-1], nums[0], nums[1], ..., nums[k-1]]\uff08\u4e0b\u6807 \u4ece 0 \u5f00\u59cb \u8ba1\u6570\uff09\u3002\u4f8b\u5982\uff0c [0,1,2,4,5,6,7] \u5728\u4e0b\u6807 3 \u5904\u7ecf\u65cb\u8f6c\u540e\u53ef\u80fd\u53d8\u4e3a\u00a0[4,5,6,7,0,1,2] \u3002

    \n\n

    \u7ed9\u4f60 \u65cb\u8f6c\u540e \u7684\u6570\u7ec4 nums \u548c\u4e00\u4e2a\u6574\u6570 target \uff0c\u5982\u679c nums \u4e2d\u5b58\u5728\u8fd9\u4e2a\u76ee\u6807\u503c target \uff0c\u5219\u8fd4\u56de\u5b83\u7684\u4e0b\u6807\uff0c\u5426\u5219\u8fd4\u56de\u00a0-1\u00a0\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [4,5,6,7,0,1,2], target = 0\n\u8f93\u51fa\uff1a4\n
    \n\n

    \u793a\u4f8b\u00a02\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [4,5,6,7,0,1,2], target = 3\n\u8f93\u51fa\uff1a-1
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1], target = 0\n\u8f93\u51fa\uff1a-1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 5000
    • \n\t
    • -10^4 <= nums[i] <= 10^4
    • \n\t
    • nums \u4e2d\u7684\u6bcf\u4e2a\u503c\u90fd \u72ec\u4e00\u65e0\u4e8c
    • \n\t
    • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1 nums \u5728\u9884\u5148\u672a\u77e5\u7684\u67d0\u4e2a\u4e0b\u6807\u4e0a\u8fdb\u884c\u4e86\u65cb\u8f6c
    • \n\t
    • -10^4 <= target <= 10^4
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u53ef\u4ee5\u8bbe\u8ba1\u4e00\u4e2a\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(log n) \u7684\u89e3\u51b3\u65b9\u6848\u5417\uff1f

    \n", "tags_en": ["Array", "Binary Search"], "tags_cn": ["\u6570\u7ec4", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int search(vector& nums, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int search(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def search(self, nums, target):\n \"\"\"\n :type nums: List[int]\n :type target: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def search(self, nums: List[int], target: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint search(int* nums, int numsSize, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int Search(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} target\n * @return {number}\n */\nvar search = function(nums, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} target\n# @return {Integer}\ndef search(nums, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func search(_ nums: [Int], _ target: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func search(nums []int, target int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def search(nums: Array[Int], target: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun search(nums: IntArray, target: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn search(nums: Vec, target: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $target\n * @return Integer\n */\n function search($nums, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function search(nums: number[], target: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (search nums target)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0033](https://leetcode-cn.com/problems/search-in-rotated-sorted-array)", "[\u641c\u7d22\u65cb\u8f6c\u6392\u5e8f\u6570\u7ec4](/solution/0000-0099/0033.Search%20in%20Rotated%20Sorted%20Array/README.md)", "`\u6570\u7ec4`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0033](https://leetcode.com/problems/search-in-rotated-sorted-array)", "[Search in Rotated Sorted Array](/solution/0000-0099/0033.Search%20in%20Rotated%20Sorted%20Array/README_EN.md)", "`Array`,`Binary Search`", "Medium", ""]}, {"question_id": "0032", "frontend_question_id": "0032", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-valid-parentheses", "url_en": "https://leetcode.com/problems/longest-valid-parentheses", "relative_path_cn": "/solution/0000-0099/0032.Longest%20Valid%20Parentheses/README.md", "relative_path_en": "/solution/0000-0099/0032.Longest%20Valid%20Parentheses/README_EN.md", "title_cn": "\u6700\u957f\u6709\u6548\u62ec\u53f7", "title_en": "Longest Valid Parentheses", "question_title_slug": "longest-valid-parentheses", "content_en": "

    Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "(()"\nOutput: 2\nExplanation: The longest valid parentheses substring is "()".\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = ")()())"\nOutput: 4\nExplanation: The longest valid parentheses substring is "()()".\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = ""\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= s.length <= 3 * 104
    • \n\t
    • s[i] is '(', or ')'.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u53ea\u5305\u542b '('\u00a0\u548c ')'\u00a0\u7684\u5b57\u7b26\u4e32\uff0c\u627e\u51fa\u6700\u957f\u6709\u6548\uff08\u683c\u5f0f\u6b63\u786e\u4e14\u8fde\u7eed\uff09\u62ec\u53f7\u5b50\u4e32\u7684\u957f\u5ea6\u3002

    \n\n

    \u00a0

    \n\n
    \n
    \n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"(()\"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6700\u957f\u6709\u6548\u62ec\u53f7\u5b50\u4e32\u662f \"()\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \")()())\"\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u6700\u957f\u6709\u6548\u62ec\u53f7\u5b50\u4e32\u662f \"()()\"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"\"\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= s.length <= 3 * 104
    • \n\t
    • s[i] \u4e3a '(' \u6216 ')'
    • \n
    \n
    \n
    \n", "tags_en": ["String", "Dynamic Programming"], "tags_cn": ["\u5b57\u7b26\u4e32", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int longestValidParentheses(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int longestValidParentheses(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestValidParentheses(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestValidParentheses(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint longestValidParentheses(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LongestValidParentheses(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar longestValidParentheses = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef longest_valid_parentheses(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestValidParentheses(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestValidParentheses(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestValidParentheses(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestValidParentheses(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_valid_parentheses(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function longestValidParentheses($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestValidParentheses(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-valid-parentheses s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0032](https://leetcode-cn.com/problems/longest-valid-parentheses)", "[\u6700\u957f\u6709\u6548\u62ec\u53f7](/solution/0000-0099/0032.Longest%20Valid%20Parentheses/README.md)", "`\u5b57\u7b26\u4e32`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0032](https://leetcode.com/problems/longest-valid-parentheses)", "[Longest Valid Parentheses](/solution/0000-0099/0032.Longest%20Valid%20Parentheses/README_EN.md)", "`String`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0031", "frontend_question_id": "0031", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/next-permutation", "url_en": "https://leetcode.com/problems/next-permutation", "relative_path_cn": "/solution/0000-0099/0031.Next%20Permutation/README.md", "relative_path_en": "/solution/0000-0099/0031.Next%20Permutation/README_EN.md", "title_cn": "\u4e0b\u4e00\u4e2a\u6392\u5217", "title_en": "Next Permutation", "question_title_slug": "next-permutation", "content_en": "

    Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.

    \n\n

    If such an arrangement is not possible, it must rearrange it as the lowest possible order (i.e., sorted in ascending order).

    \n\n

    The replacement must be in place and use only constant extra memory.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [1,2,3]\nOutput: [1,3,2]\n

    Example 2:

    \n
    Input: nums = [3,2,1]\nOutput: [1,2,3]\n

    Example 3:

    \n
    Input: nums = [1,1,5]\nOutput: [1,5,1]\n

    Example 4:

    \n
    Input: nums = [1]\nOutput: [1]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 100
    • \n\t
    • 0 <= nums[i] <= 100
    • \n
    \n", "content_cn": "

    \u5b9e\u73b0\u83b7\u53d6 \u4e0b\u4e00\u4e2a\u6392\u5217 \u7684\u51fd\u6570\uff0c\u7b97\u6cd5\u9700\u8981\u5c06\u7ed9\u5b9a\u6570\u5b57\u5e8f\u5217\u91cd\u65b0\u6392\u5217\u6210\u5b57\u5178\u5e8f\u4e2d\u4e0b\u4e00\u4e2a\u66f4\u5927\u7684\u6392\u5217\u3002

    \n\n

    \u5982\u679c\u4e0d\u5b58\u5728\u4e0b\u4e00\u4e2a\u66f4\u5927\u7684\u6392\u5217\uff0c\u5219\u5c06\u6570\u5b57\u91cd\u65b0\u6392\u5217\u6210\u6700\u5c0f\u7684\u6392\u5217\uff08\u5373\u5347\u5e8f\u6392\u5217\uff09\u3002

    \n\n

    \u5fc5\u987b \u539f\u5730 \u4fee\u6539\uff0c\u53ea\u5141\u8bb8\u4f7f\u7528\u989d\u5916\u5e38\u6570\u7a7a\u95f4\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,3]\n\u8f93\u51fa\uff1a[1,3,2]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [3,2,1]\n\u8f93\u51fa\uff1a[1,2,3]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,1,5]\n\u8f93\u51fa\uff1a[1,5,1]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1]\n\u8f93\u51fa\uff1a[1]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 100
    • \n\t
    • 0 <= nums[i] <= 100
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n void nextPermutation(vector& nums) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public void nextPermutation(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def nextPermutation(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: None Do not return anything, modify nums in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def nextPermutation(self, nums: List[int]) -> None:\n \"\"\"\n Do not return anything, modify nums in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nvoid nextPermutation(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public void NextPermutation(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {void} Do not return anything, modify nums in-place instead.\n */\nvar nextPermutation = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Void} Do not return anything, modify nums in-place instead.\ndef next_permutation(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func nextPermutation(_ nums: inout [Int]) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func nextPermutation(nums []int) {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def nextPermutation(nums: Array[Int]): Unit = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun nextPermutation(nums: IntArray): Unit {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn next_permutation(nums: &mut Vec) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return NULL\n */\n function nextPermutation(&$nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n Do not return anything, modify nums in-place instead.\n */\nfunction nextPermutation(nums: number[]): void {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0031](https://leetcode-cn.com/problems/next-permutation)", "[\u4e0b\u4e00\u4e2a\u6392\u5217](/solution/0000-0099/0031.Next%20Permutation/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0031](https://leetcode.com/problems/next-permutation)", "[Next Permutation](/solution/0000-0099/0031.Next%20Permutation/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0030", "frontend_question_id": "0030", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/substring-with-concatenation-of-all-words", "url_en": "https://leetcode.com/problems/substring-with-concatenation-of-all-words", "relative_path_cn": "/solution/0000-0099/0030.Substring%20with%20Concatenation%20of%20All%20Words/README.md", "relative_path_en": "/solution/0000-0099/0030.Substring%20with%20Concatenation%20of%20All%20Words/README_EN.md", "title_cn": "\u4e32\u8054\u6240\u6709\u5355\u8bcd\u7684\u5b50\u4e32", "title_en": "Substring with Concatenation of All Words", "question_title_slug": "substring-with-concatenation-of-all-words", "content_en": "

    You are given a string s and an array of strings words of the same length. Return all starting indices of substring(s) in s that is a concatenation of each word in words exactly once, in any order, and without any intervening characters.

    \n\n

    You can return the answer in any order.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "barfoothefoobarman", words = ["foo","bar"]\nOutput: [0,9]\nExplanation: Substrings starting at index 0 and 9 are "barfoo" and "foobar" respectively.\nThe output order does not matter, returning [9,0] is fine too.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "wordgoodgoodgoodbestword", words = ["word","good","best","word"]\nOutput: []\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "barfoofoobarthefoobarman", words = ["bar","foo","the"]\nOutput: [6,9,12]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 104
    • \n\t
    • s consists of lower-case English letters.
    • \n\t
    • 1 <= words.length <= 5000
    • \n\t
    • 1 <= words[i].length <= 30
    • \n\t
    • words[i] consists of lower-case English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\u00a0s\u00a0\u548c\u4e00\u4e9b \u957f\u5ea6\u76f8\u540c \u7684\u5355\u8bcd\u00a0words \u3002\u627e\u51fa s \u4e2d\u6070\u597d\u53ef\u4ee5\u7531\u00a0words \u4e2d\u6240\u6709\u5355\u8bcd\u4e32\u8054\u5f62\u6210\u7684\u5b50\u4e32\u7684\u8d77\u59cb\u4f4d\u7f6e\u3002

    \n\n

    \u6ce8\u610f\u5b50\u4e32\u8981\u4e0e\u00a0words \u4e2d\u7684\u5355\u8bcd\u5b8c\u5168\u5339\u914d\uff0c\u4e2d\u95f4\u4e0d\u80fd\u6709\u5176\u4ed6\u5b57\u7b26 \uff0c\u4f46\u4e0d\u9700\u8981\u8003\u8651\u00a0words\u00a0\u4e2d\u5355\u8bcd\u4e32\u8054\u7684\u987a\u5e8f\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"barfoothefoobarman\", words = [\"foo\",\"bar\"]\n\u8f93\u51fa\uff1a[0,9]\n\u89e3\u91ca\uff1a\n\u4ece\u7d22\u5f15 0 \u548c 9 \u5f00\u59cb\u7684\u5b50\u4e32\u5206\u522b\u662f \"barfoo\" \u548c \"foobar\" \u3002\n\u8f93\u51fa\u7684\u987a\u5e8f\u4e0d\u91cd\u8981, [9,0] \u4e5f\u662f\u6709\u6548\u7b54\u6848\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"wordgoodgoodgoodbestword\", words = [\"word\",\"good\",\"best\",\"word\"]\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"barfoofoobarthefoobarman\", words = [\"bar\",\"foo\",\"the\"]\n\u8f93\u51fa\uff1a[6,9,12]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 104
    • \n\t
    • s \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n\t
    • 1 <= words.length <= 5000
    • \n\t
    • 1 <= words[i].length <= 30
    • \n\t
    • words[i]\u00a0\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n", "tags_en": ["Hash Table", "Two Pointers", "String"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u53cc\u6307\u9488", "\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findSubstring(string s, vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List findSubstring(String s, String[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findSubstring(self, s, words):\n \"\"\"\n :type s: str\n :type words: List[str]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findSubstring(self, s: str, words: List[str]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* findSubstring(char * s, char ** words, int wordsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList FindSubstring(string s, string[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string[]} words\n * @return {number[]}\n */\nvar findSubstring = function(s, words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String[]} words\n# @return {Integer[]}\ndef find_substring(s, words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findSubstring(_ s: String, _ words: [String]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findSubstring(s string, words []string) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findSubstring(s: String, words: Array[String]): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findSubstring(s: String, words: Array): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_substring(s: String, words: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String[] $words\n * @return Integer[]\n */\n function findSubstring($s, $words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findSubstring(s: string, words: string[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-substring s words)\n (-> string? (listof string?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0030](https://leetcode-cn.com/problems/substring-with-concatenation-of-all-words)", "[\u4e32\u8054\u6240\u6709\u5355\u8bcd\u7684\u5b50\u4e32](/solution/0000-0099/0030.Substring%20with%20Concatenation%20of%20All%20Words/README.md)", "`\u54c8\u5e0c\u8868`,`\u53cc\u6307\u9488`,`\u5b57\u7b26\u4e32`", "\u56f0\u96be", ""], "md_table_row_en": ["[0030](https://leetcode.com/problems/substring-with-concatenation-of-all-words)", "[Substring with Concatenation of All Words](/solution/0000-0099/0030.Substring%20with%20Concatenation%20of%20All%20Words/README_EN.md)", "`Hash Table`,`Two Pointers`,`String`", "Hard", ""]}, {"question_id": "0029", "frontend_question_id": "0029", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/divide-two-integers", "url_en": "https://leetcode.com/problems/divide-two-integers", "relative_path_cn": "/solution/0000-0099/0029.Divide%20Two%20Integers/README.md", "relative_path_en": "/solution/0000-0099/0029.Divide%20Two%20Integers/README_EN.md", "title_cn": "\u4e24\u6570\u76f8\u9664", "title_en": "Divide Two Integers", "question_title_slug": "divide-two-integers", "content_en": "

    Given two integers dividend and divisor, divide two integers without using multiplication, division, and mod operator.

    \n\n

    Return the quotient after dividing dividend by divisor.

    \n\n

    The integer division should truncate toward zero, which means losing its fractional part. For example, truncate(8.345) = 8 and truncate(-2.7335) = -2.

    \n\n

    Note: Assume we are dealing with an environment that could only store integers within the 32-bit signed integer range: [−231, 231 − 1]. For this problem, assume that your function returns 231 − 1 when the division result overflows.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: dividend = 10, divisor = 3\nOutput: 3\nExplanation: 10/3 = truncate(3.33333..) = 3.\n
    \n\n

    Example 2:

    \n\n
    \nInput: dividend = 7, divisor = -3\nOutput: -2\nExplanation: 7/-3 = truncate(-2.33333..) = -2.\n
    \n\n

    Example 3:

    \n\n
    \nInput: dividend = 0, divisor = 1\nOutput: 0\n
    \n\n

    Example 4:

    \n\n
    \nInput: dividend = 1, divisor = 1\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • -231 <= dividend, divisor <= 231 - 1
    • \n\t
    • divisor != 0
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u6574\u6570\uff0c\u88ab\u9664\u6570 dividend \u548c\u9664\u6570 divisor\u3002\u5c06\u4e24\u6570\u76f8\u9664\uff0c\u8981\u6c42\u4e0d\u4f7f\u7528\u4e58\u6cd5\u3001\u9664\u6cd5\u548c mod \u8fd0\u7b97\u7b26\u3002

    \n\n

    \u8fd4\u56de\u88ab\u9664\u6570 dividend \u9664\u4ee5\u9664\u6570 divisor \u5f97\u5230\u7684\u5546\u3002

    \n\n

    \u6574\u6570\u9664\u6cd5\u7684\u7ed3\u679c\u5e94\u5f53\u622a\u53bb\uff08truncate\uff09\u5176\u5c0f\u6570\u90e8\u5206\uff0c\u4f8b\u5982\uff1atruncate(8.345) = 8 \u4ee5\u53ca truncate(-2.7335) = -2

    \n\n

     

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: dividend = 10, divisor = 3\n\u8f93\u51fa: 3\n\u89e3\u91ca: 10/3 = truncate(3.33333..) = truncate(3) = 3
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: dividend = 7, divisor = -3\n\u8f93\u51fa: -2\n\u89e3\u91ca: 7/-3 = truncate(-2.33333..) = -2
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u88ab\u9664\u6570\u548c\u9664\u6570\u5747\u4e3a 32 \u4f4d\u6709\u7b26\u53f7\u6574\u6570\u3002
    • \n\t
    • \u9664\u6570\u4e0d\u4e3a 0\u3002
    • \n\t
    • \u5047\u8bbe\u6211\u4eec\u7684\u73af\u5883\u53ea\u80fd\u5b58\u50a8 32 \u4f4d\u6709\u7b26\u53f7\u6574\u6570\uff0c\u5176\u6570\u503c\u8303\u56f4\u662f [−231,  231 − 1]\u3002\u672c\u9898\u4e2d\uff0c\u5982\u679c\u9664\u6cd5\u7ed3\u679c\u6ea2\u51fa\uff0c\u5219\u8fd4\u56de 231 − 1\u3002
    • \n
    \n", "tags_en": ["Math", "Binary Search"], "tags_cn": ["\u6570\u5b66", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int divide(int dividend, int divisor) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int divide(int dividend, int divisor) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def divide(self, dividend, divisor):\n \"\"\"\n :type dividend: int\n :type divisor: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def divide(self, dividend: int, divisor: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint divide(int dividend, int divisor){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int Divide(int dividend, int divisor) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} dividend\n * @param {number} divisor\n * @return {number}\n */\nvar divide = function(dividend, divisor) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} dividend\n# @param {Integer} divisor\n# @return {Integer}\ndef divide(dividend, divisor)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func divide(_ dividend: Int, _ divisor: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func divide(dividend int, divisor int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def divide(dividend: Int, divisor: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun divide(dividend: Int, divisor: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn divide(dividend: i32, divisor: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $dividend\n * @param Integer $divisor\n * @return Integer\n */\n function divide($dividend, $divisor) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function divide(dividend: number, divisor: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (divide dividend divisor)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0029](https://leetcode-cn.com/problems/divide-two-integers)", "[\u4e24\u6570\u76f8\u9664](/solution/0000-0099/0029.Divide%20Two%20Integers/README.md)", "`\u6570\u5b66`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0029](https://leetcode.com/problems/divide-two-integers)", "[Divide Two Integers](/solution/0000-0099/0029.Divide%20Two%20Integers/README_EN.md)", "`Math`,`Binary Search`", "Medium", ""]}, {"question_id": "0028", "frontend_question_id": "0028", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/implement-strstr", "url_en": "https://leetcode.com/problems/implement-strstr", "relative_path_cn": "/solution/0000-0099/0028.Implement%20strStr%28%29/README.md", "relative_path_en": "/solution/0000-0099/0028.Implement%20strStr%28%29/README_EN.md", "title_cn": "\u5b9e\u73b0 strStr()", "title_en": "Implement strStr()", "question_title_slug": "implement-strstr", "content_en": "

    Implement strStr().

    \n\n

    Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.

    \n\n

    Clarification:

    \n\n

    What should we return when needle is an empty string? This is a great question to ask during an interview.

    \n\n

    For the purpose of this problem, we will return 0 when needle is an empty string. This is consistent to C's strstr() and Java's indexOf().

    \n\n

     

    \n

    Example 1:

    \n
    Input: haystack = \"hello\", needle = \"ll\"\nOutput: 2\n

    Example 2:

    \n
    Input: haystack = \"aaaaa\", needle = \"bba\"\nOutput: -1\n

    Example 3:

    \n
    Input: haystack = \"\", needle = \"\"\nOutput: 0\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= haystack.length, needle.length <= 5 * 104
    • \n\t
    • haystack and needle consist of only lower-case English characters.
    • \n
    \n", "content_cn": "

    \u5b9e\u73b0\u00a0strStr()\u00a0\u51fd\u6570\u3002

    \n\n

    \u7ed9\u4f60\u4e24\u4e2a\u5b57\u7b26\u4e32\u00a0haystack \u548c needle \uff0c\u8bf7\u4f60\u5728 haystack \u5b57\u7b26\u4e32\u4e2d\u627e\u51fa needle \u5b57\u7b26\u4e32\u51fa\u73b0\u7684\u7b2c\u4e00\u4e2a\u4f4d\u7f6e\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\u3002\u5982\u679c\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u00a0 -1 \u3002

    \n\n

    \u00a0

    \n\n

    \u8bf4\u660e\uff1a

    \n\n

    \u5f53\u00a0needle\u00a0\u662f\u7a7a\u5b57\u7b26\u4e32\u65f6\uff0c\u6211\u4eec\u5e94\u5f53\u8fd4\u56de\u4ec0\u4e48\u503c\u5462\uff1f\u8fd9\u662f\u4e00\u4e2a\u5728\u9762\u8bd5\u4e2d\u5f88\u597d\u7684\u95ee\u9898\u3002

    \n\n

    \u5bf9\u4e8e\u672c\u9898\u800c\u8a00\uff0c\u5f53\u00a0needle\u00a0\u662f\u7a7a\u5b57\u7b26\u4e32\u65f6\u6211\u4eec\u5e94\u5f53\u8fd4\u56de 0 \u3002\u8fd9\u4e0e C \u8bed\u8a00\u7684\u00a0strstr()\u00a0\u4ee5\u53ca Java \u7684\u00a0indexOf()\u00a0\u5b9a\u4e49\u76f8\u7b26\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahaystack = \"hello\", needle = \"ll\"\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahaystack = \"aaaaa\", needle = \"bba\"\n\u8f93\u51fa\uff1a-1\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahaystack = \"\", needle = \"\"\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= haystack.length, needle.length <= 5 * 104
    • \n\t
    • haystack \u548c needle \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u7b26\u7ec4\u6210
    • \n
    \n", "tags_en": ["Two Pointers", "String"], "tags_cn": ["\u53cc\u6307\u9488", "\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int strStr(string haystack, string needle) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int strStr(String haystack, String needle) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def strStr(self, haystack, needle):\n \"\"\"\n :type haystack: str\n :type needle: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def strStr(self, haystack: str, needle: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint strStr(char * haystack, char * needle){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int StrStr(string haystack, string needle) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} haystack\n * @param {string} needle\n * @return {number}\n */\nvar strStr = function(haystack, needle) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} haystack\n# @param {String} needle\n# @return {Integer}\ndef str_str(haystack, needle)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func strStr(_ haystack: String, _ needle: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func strStr(haystack string, needle string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def strStr(haystack: String, needle: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun strStr(haystack: String, needle: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn str_str(haystack: String, needle: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $haystack\n * @param String $needle\n * @return Integer\n */\n function strStr($haystack, $needle) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function strStr(haystack: string, needle: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (str-str haystack needle)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0028](https://leetcode-cn.com/problems/implement-strstr)", "[\u5b9e\u73b0 strStr()](/solution/0000-0099/0028.Implement%20strStr%28%29/README.md)", "`\u53cc\u6307\u9488`,`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0028](https://leetcode.com/problems/implement-strstr)", "[Implement strStr()](/solution/0000-0099/0028.Implement%20strStr%28%29/README_EN.md)", "`Two Pointers`,`String`", "Easy", ""]}, {"question_id": "0027", "frontend_question_id": "0027", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/remove-element", "url_en": "https://leetcode.com/problems/remove-element", "relative_path_cn": "/solution/0000-0099/0027.Remove%20Element/README.md", "relative_path_en": "/solution/0000-0099/0027.Remove%20Element/README_EN.md", "title_cn": "\u79fb\u9664\u5143\u7d20", "title_en": "Remove Element", "question_title_slug": "remove-element", "content_en": "

    Given an array nums and a value val, remove all instances of that value in-place and return the new length.

    \n\n

    Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.

    \n\n

    The order of elements can be changed. It doesn't matter what you leave beyond the new length.

    \n\n

    Clarification:

    \n\n

    Confused why the returned value is an integer but your answer is an array?

    \n\n

    Note that the input array is passed in by reference, which means a modification to the input array will be known to the caller as well.

    \n\n

    Internally you can think of this:

    \n\n
    \n// nums is passed in by reference. (i.e., without making a copy)\nint len = removeElement(nums, val);\n\n// any modification to nums in your function would be known by the caller.\n// using the length returned by your function, it prints the first len elements.\nfor (int i = 0; i < len; i++) {\n    print(nums[i]);\n}
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [3,2,2,3], val = 3\nOutput: 2, nums = [2,2]\nExplanation: Your function should return length = 2, with the first two elements of nums being 2.\nIt doesn't matter what you leave beyond the returned length. For example if you return 2 with nums = [2,2,3,3] or nums = [2,2,0,0], your answer will be accepted.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [0,1,2,2,3,0,4,2], val = 2\nOutput: 5, nums = [0,1,4,0,3]\nExplanation: Your function should return length = 5, with the first five elements of nums containing 0, 1, 3, 0, and 4. Note that the order of those five elements can be arbitrary. It doesn't matter what values are set beyond the returned length.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= nums.length <= 100
    • \n\t
    • 0 <= nums[i] <= 50
    • \n\t
    • 0 <= val <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 nums\u00a0\u548c\u4e00\u4e2a\u503c val\uff0c\u4f60\u9700\u8981 \u539f\u5730 \u79fb\u9664\u6240\u6709\u6570\u503c\u7b49\u4e8e\u00a0val\u00a0\u7684\u5143\u7d20\uff0c\u5e76\u8fd4\u56de\u79fb\u9664\u540e\u6570\u7ec4\u7684\u65b0\u957f\u5ea6\u3002

    \n\n

    \u4e0d\u8981\u4f7f\u7528\u989d\u5916\u7684\u6570\u7ec4\u7a7a\u95f4\uff0c\u4f60\u5fc5\u987b\u4ec5\u4f7f\u7528 O(1) \u989d\u5916\u7a7a\u95f4\u5e76 \u539f\u5730 \u4fee\u6539\u8f93\u5165\u6570\u7ec4\u3002

    \n\n

    \u5143\u7d20\u7684\u987a\u5e8f\u53ef\u4ee5\u6539\u53d8\u3002\u4f60\u4e0d\u9700\u8981\u8003\u8651\u6570\u7ec4\u4e2d\u8d85\u51fa\u65b0\u957f\u5ea6\u540e\u9762\u7684\u5143\u7d20\u3002

    \n\n

    \u00a0

    \n\n

    \u8bf4\u660e:

    \n\n

    \u4e3a\u4ec0\u4e48\u8fd4\u56de\u6570\u503c\u662f\u6574\u6570\uff0c\u4f46\u8f93\u51fa\u7684\u7b54\u6848\u662f\u6570\u7ec4\u5462?

    \n\n

    \u8bf7\u6ce8\u610f\uff0c\u8f93\u5165\u6570\u7ec4\u662f\u4ee5\u300c\u5f15\u7528\u300d\u65b9\u5f0f\u4f20\u9012\u7684\uff0c\u8fd9\u610f\u5473\u7740\u5728\u51fd\u6570\u91cc\u4fee\u6539\u8f93\u5165\u6570\u7ec4\u5bf9\u4e8e\u8c03\u7528\u8005\u662f\u53ef\u89c1\u7684\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u60f3\u8c61\u5185\u90e8\u64cd\u4f5c\u5982\u4e0b:

    \n\n
    \n// nums \u662f\u4ee5\u201c\u5f15\u7528\u201d\u65b9\u5f0f\u4f20\u9012\u7684\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u4e0d\u5bf9\u5b9e\u53c2\u4f5c\u4efb\u4f55\u62f7\u8d1d\nint len = removeElement(nums, val);\n\n// \u5728\u51fd\u6570\u91cc\u4fee\u6539\u8f93\u5165\u6570\u7ec4\u5bf9\u4e8e\u8c03\u7528\u8005\u662f\u53ef\u89c1\u7684\u3002\n// \u6839\u636e\u4f60\u7684\u51fd\u6570\u8fd4\u56de\u7684\u957f\u5ea6, \u5b83\u4f1a\u6253\u5370\u51fa\u6570\u7ec4\u4e2d \u8be5\u957f\u5ea6\u8303\u56f4\u5185 \u7684\u6240\u6709\u5143\u7d20\u3002\nfor (int i = 0; i < len; i++) {\n\u00a0 \u00a0 print(nums[i]);\n}\n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [3,2,2,3], val = 3\n\u8f93\u51fa\uff1a2, nums = [2,2]\n\u89e3\u91ca\uff1a\u51fd\u6570\u5e94\u8be5\u8fd4\u56de\u65b0\u7684\u957f\u5ea6 2, \u5e76\u4e14 nums \u4e2d\u7684\u524d\u4e24\u4e2a\u5143\u7d20\u5747\u4e3a 2\u3002\u4f60\u4e0d\u9700\u8981\u8003\u8651\u6570\u7ec4\u4e2d\u8d85\u51fa\u65b0\u957f\u5ea6\u540e\u9762\u7684\u5143\u7d20\u3002\u4f8b\u5982\uff0c\u51fd\u6570\u8fd4\u56de\u7684\u65b0\u957f\u5ea6\u4e3a 2 \uff0c\u800c nums = [2,2,3,3] \u6216 nums = [2,2,0,0]\uff0c\u4e5f\u4f1a\u88ab\u89c6\u4f5c\u6b63\u786e\u7b54\u6848\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [0,1,2,2,3,0,4,2], val = 2\n\u8f93\u51fa\uff1a5, nums = [0,1,4,0,3]\n\u89e3\u91ca\uff1a\u51fd\u6570\u5e94\u8be5\u8fd4\u56de\u65b0\u7684\u957f\u5ea6 5, \u5e76\u4e14 nums \u4e2d\u7684\u524d\u4e94\u4e2a\u5143\u7d20\u4e3a 0, 1, 3, 0, 4\u3002\u6ce8\u610f\u8fd9\u4e94\u4e2a\u5143\u7d20\u53ef\u4e3a\u4efb\u610f\u987a\u5e8f\u3002\u4f60\u4e0d\u9700\u8981\u8003\u8651\u6570\u7ec4\u4e2d\u8d85\u51fa\u65b0\u957f\u5ea6\u540e\u9762\u7684\u5143\u7d20\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= nums.length <= 100
    • \n\t
    • 0 <= nums[i] <= 50
    • \n\t
    • 0 <= val <= 100
    • \n
    \n", "tags_en": ["Array", "Two Pointers"], "tags_cn": ["\u6570\u7ec4", "\u53cc\u6307\u9488"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int removeElement(vector& nums, int val) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int removeElement(int[] nums, int val) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def removeElement(self, nums, val):\n \"\"\"\n :type nums: List[int]\n :type val: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def removeElement(self, nums: List[int], val: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint removeElement(int* nums, int numsSize, int val){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int RemoveElement(int[] nums, int val) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} val\n * @return {number}\n */\nvar removeElement = function(nums, val) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} val\n# @return {Integer}\ndef remove_element(nums, val)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func removeElement(_ nums: inout [Int], _ val: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func removeElement(nums []int, val int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def removeElement(nums: Array[Int], `val`: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun removeElement(nums: IntArray, `val`: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn remove_element(nums: &mut Vec, val: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $val\n * @return Integer\n */\n function removeElement(&$nums, $val) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function removeElement(nums: number[], val: number): number {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0027](https://leetcode-cn.com/problems/remove-element)", "[\u79fb\u9664\u5143\u7d20](/solution/0000-0099/0027.Remove%20Element/README.md)", "`\u6570\u7ec4`,`\u53cc\u6307\u9488`", "\u7b80\u5355", ""], "md_table_row_en": ["[0027](https://leetcode.com/problems/remove-element)", "[Remove Element](/solution/0000-0099/0027.Remove%20Element/README_EN.md)", "`Array`,`Two Pointers`", "Easy", ""]}, {"question_id": "0026", "frontend_question_id": "0026", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array", "url_en": "https://leetcode.com/problems/remove-duplicates-from-sorted-array", "relative_path_cn": "/solution/0000-0099/0026.Remove%20Duplicates%20from%20Sorted%20Array/README.md", "relative_path_en": "/solution/0000-0099/0026.Remove%20Duplicates%20from%20Sorted%20Array/README_EN.md", "title_cn": "\u5220\u9664\u6709\u5e8f\u6570\u7ec4\u4e2d\u7684\u91cd\u590d\u9879", "title_en": "Remove Duplicates from Sorted Array", "question_title_slug": "remove-duplicates-from-sorted-array", "content_en": "

    Given a sorted array nums, remove the duplicates in-place such that each element appears only once and returns the new length.

    \n\n

    Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.

    \n\n

    Clarification:

    \n\n

    Confused why the returned value is an integer but your answer is an array?

    \n\n

    Note that the input array is passed in by reference, which means a modification to the input array will be known to the caller as well.

    \n\n

    Internally you can think of this:

    \n\n
    \n// nums is passed in by reference. (i.e., without making a copy)\nint len = removeDuplicates(nums);\n\n// any modification to nums in your function would be known by the caller.\n// using the length returned by your function, it prints the first len elements.\nfor (int i = 0; i < len; i++) {\n    print(nums[i]);\n}\n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,1,2]\nOutput: 2, nums = [1,2]\nExplanation: Your function should return length = 2, with the first two elements of nums being 1 and 2 respectively. It doesn't matter what you leave beyond the returned length.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [0,0,1,1,1,2,2,3,3,4]\nOutput: 5, nums = [0,1,2,3,4]\nExplanation: Your function should return length = 5, with the first five elements of nums being modified to 0, 1, 2, 3, and 4 respectively. It doesn't matter what values are set beyond the returned length.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= nums.length <= 3 * 104
    • \n\t
    • -104 <= nums[i] <= 104
    • \n\t
    • nums is sorted in ascending order.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6709\u5e8f\u6570\u7ec4 nums \uff0c\u8bf7\u4f60 \u539f\u5730 \u5220\u9664\u91cd\u590d\u51fa\u73b0\u7684\u5143\u7d20\uff0c\u4f7f\u6bcf\u4e2a\u5143\u7d20 \u53ea\u51fa\u73b0\u4e00\u6b21 \uff0c\u8fd4\u56de\u5220\u9664\u540e\u6570\u7ec4\u7684\u65b0\u957f\u5ea6\u3002

    \n\n

    \u4e0d\u8981\u4f7f\u7528\u989d\u5916\u7684\u6570\u7ec4\u7a7a\u95f4\uff0c\u4f60\u5fc5\u987b\u5728 \u539f\u5730 \u4fee\u6539\u8f93\u5165\u6570\u7ec4 \u5e76\u5728\u4f7f\u7528 O(1) \u989d\u5916\u7a7a\u95f4\u7684\u6761\u4ef6\u4e0b\u5b8c\u6210\u3002

    \n\n

    \u00a0

    \n\n

    \u8bf4\u660e:

    \n\n

    \u4e3a\u4ec0\u4e48\u8fd4\u56de\u6570\u503c\u662f\u6574\u6570\uff0c\u4f46\u8f93\u51fa\u7684\u7b54\u6848\u662f\u6570\u7ec4\u5462?

    \n\n

    \u8bf7\u6ce8\u610f\uff0c\u8f93\u5165\u6570\u7ec4\u662f\u4ee5\u300c\u5f15\u7528\u300d\u65b9\u5f0f\u4f20\u9012\u7684\uff0c\u8fd9\u610f\u5473\u7740\u5728\u51fd\u6570\u91cc\u4fee\u6539\u8f93\u5165\u6570\u7ec4\u5bf9\u4e8e\u8c03\u7528\u8005\u662f\u53ef\u89c1\u7684\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u60f3\u8c61\u5185\u90e8\u64cd\u4f5c\u5982\u4e0b:

    \n\n
    \n// nums \u662f\u4ee5\u201c\u5f15\u7528\u201d\u65b9\u5f0f\u4f20\u9012\u7684\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u4e0d\u5bf9\u5b9e\u53c2\u505a\u4efb\u4f55\u62f7\u8d1d\nint len = removeDuplicates(nums);\n\n// \u5728\u51fd\u6570\u91cc\u4fee\u6539\u8f93\u5165\u6570\u7ec4\u5bf9\u4e8e\u8c03\u7528\u8005\u662f\u53ef\u89c1\u7684\u3002\n// \u6839\u636e\u4f60\u7684\u51fd\u6570\u8fd4\u56de\u7684\u957f\u5ea6, \u5b83\u4f1a\u6253\u5370\u51fa\u6570\u7ec4\u4e2d \u8be5\u957f\u5ea6\u8303\u56f4\u5185 \u7684\u6240\u6709\u5143\u7d20\u3002\nfor (int i = 0; i < len; i++) {\n\u00a0 \u00a0 print(nums[i]);\n}\n
    \n\u00a0\n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,1,2]\n\u8f93\u51fa\uff1a2, nums = [1,2]\n\u89e3\u91ca\uff1a\u51fd\u6570\u5e94\u8be5\u8fd4\u56de\u65b0\u7684\u957f\u5ea6 2 \uff0c\u5e76\u4e14\u539f\u6570\u7ec4 nums \u7684\u524d\u4e24\u4e2a\u5143\u7d20\u88ab\u4fee\u6539\u4e3a 1, 2 \u3002\u4e0d\u9700\u8981\u8003\u8651\u6570\u7ec4\u4e2d\u8d85\u51fa\u65b0\u957f\u5ea6\u540e\u9762\u7684\u5143\u7d20\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [0,0,1,1,1,2,2,3,3,4]\n\u8f93\u51fa\uff1a5, nums = [0,1,2,3,4]\n\u89e3\u91ca\uff1a\u51fd\u6570\u5e94\u8be5\u8fd4\u56de\u65b0\u7684\u957f\u5ea6 5 \uff0c \u5e76\u4e14\u539f\u6570\u7ec4 nums \u7684\u524d\u4e94\u4e2a\u5143\u7d20\u88ab\u4fee\u6539\u4e3a 0, 1, 2, 3, 4 \u3002\u4e0d\u9700\u8981\u8003\u8651\u6570\u7ec4\u4e2d\u8d85\u51fa\u65b0\u957f\u5ea6\u540e\u9762\u7684\u5143\u7d20\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= nums.length <= 3 * 104
    • \n\t
    • -104 <= nums[i] <= 104
    • \n\t
    • nums \u5df2\u6309\u5347\u5e8f\u6392\u5217
    • \n
    \n\n

    \u00a0

    \n", "tags_en": ["Array", "Two Pointers"], "tags_cn": ["\u6570\u7ec4", "\u53cc\u6307\u9488"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int removeDuplicates(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int removeDuplicates(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def removeDuplicates(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def removeDuplicates(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint removeDuplicates(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int RemoveDuplicates(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar removeDuplicates = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef remove_duplicates(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func removeDuplicates(_ nums: inout [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func removeDuplicates(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def removeDuplicates(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun removeDuplicates(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn remove_duplicates(nums: &mut Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function removeDuplicates(&$nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function removeDuplicates(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0026](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array)", "[\u5220\u9664\u6709\u5e8f\u6570\u7ec4\u4e2d\u7684\u91cd\u590d\u9879](/solution/0000-0099/0026.Remove%20Duplicates%20from%20Sorted%20Array/README.md)", "`\u6570\u7ec4`,`\u53cc\u6307\u9488`", "\u7b80\u5355", ""], "md_table_row_en": ["[0026](https://leetcode.com/problems/remove-duplicates-from-sorted-array)", "[Remove Duplicates from Sorted Array](/solution/0000-0099/0026.Remove%20Duplicates%20from%20Sorted%20Array/README_EN.md)", "`Array`,`Two Pointers`", "Easy", ""]}, {"question_id": "0025", "frontend_question_id": "0025", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reverse-nodes-in-k-group", "url_en": "https://leetcode.com/problems/reverse-nodes-in-k-group", "relative_path_cn": "/solution/0000-0099/0025.Reverse%20Nodes%20in%20k-Group/README.md", "relative_path_en": "/solution/0000-0099/0025.Reverse%20Nodes%20in%20k-Group/README_EN.md", "title_cn": "K \u4e2a\u4e00\u7ec4\u7ffb\u8f6c\u94fe\u8868", "title_en": "Reverse Nodes in k-Group", "question_title_slug": "reverse-nodes-in-k-group", "content_en": "

    Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.

    \n\n

    k is a positive integer and is less than or equal to the length of the linked list. If the number of nodes is not a multiple of k then left-out nodes, in the end, should remain as it is.

    \n\n

    You may not alter the values in the list's nodes, only nodes themselves may be changed.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: head = [1,2,3,4,5], k = 2\nOutput: [2,1,4,3,5]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: head = [1,2,3,4,5], k = 3\nOutput: [3,2,1,4,5]\n
    \n\n

    Example 3:

    \n\n
    \nInput: head = [1,2,3,4,5], k = 1\nOutput: [1,2,3,4,5]\n
    \n\n

    Example 4:

    \n\n
    \nInput: head = [1], k = 1\nOutput: [1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the list is in the range sz.
    • \n\t
    • 1 <= sz <= 5000
    • \n\t
    • 0 <= Node.val <= 1000
    • \n\t
    • 1 <= k <= sz
    • \n
    \n\n

     

    \nFollow-up: Can you solve the problem in O(1) extra memory space?", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u94fe\u8868\uff0c\u6bcf\u00a0k\u00a0\u4e2a\u8282\u70b9\u4e00\u7ec4\u8fdb\u884c\u7ffb\u8f6c\uff0c\u8bf7\u4f60\u8fd4\u56de\u7ffb\u8f6c\u540e\u7684\u94fe\u8868\u3002

    \n\n

    k\u00a0\u662f\u4e00\u4e2a\u6b63\u6574\u6570\uff0c\u5b83\u7684\u503c\u5c0f\u4e8e\u6216\u7b49\u4e8e\u94fe\u8868\u7684\u957f\u5ea6\u3002

    \n\n

    \u5982\u679c\u8282\u70b9\u603b\u6570\u4e0d\u662f\u00a0k\u00a0\u7684\u6574\u6570\u500d\uff0c\u90a3\u4e48\u8bf7\u5c06\u6700\u540e\u5269\u4f59\u7684\u8282\u70b9\u4fdd\u6301\u539f\u6709\u987a\u5e8f\u3002

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u4f60\u53ef\u4ee5\u8bbe\u8ba1\u4e00\u4e2a\u53ea\u4f7f\u7528\u5e38\u6570\u989d\u5916\u7a7a\u95f4\u7684\u7b97\u6cd5\u6765\u89e3\u51b3\u6b64\u95ee\u9898\u5417\uff1f
    • \n\t
    • \u4f60\u4e0d\u80fd\u53ea\u662f\u5355\u7eaf\u7684\u6539\u53d8\u8282\u70b9\u5185\u90e8\u7684\u503c\uff0c\u800c\u662f\u9700\u8981\u5b9e\u9645\u8fdb\u884c\u8282\u70b9\u4ea4\u6362\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1ahead = [1,2,3,4,5], k = 2\n\u8f93\u51fa\uff1a[2,1,4,3,5]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1ahead = [1,2,3,4,5], k = 3\n\u8f93\u51fa\uff1a[3,2,1,4,5]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahead = [1,2,3,4,5], k = 1\n\u8f93\u51fa\uff1a[1,2,3,4,5]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahead = [1], k = 1\n\u8f93\u51fa\uff1a[1]\n
    \n\n
      \n
    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u5217\u8868\u4e2d\u8282\u70b9\u7684\u6570\u91cf\u5728\u8303\u56f4 sz \u5185
    • \n\t
    • 1 <= sz <= 5000
    • \n\t
    • 0 <= Node.val <= 1000
    • \n\t
    • 1 <= k <= sz
    • \n
    \n", "tags_en": ["Linked List"], "tags_cn": ["\u94fe\u8868"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n ListNode* reverseKGroup(ListNode* head, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public ListNode reverseKGroup(ListNode head, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def reverseKGroup(self, head, k):\n \"\"\"\n :type head: ListNode\n :type k: int\n :rtype: ListNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def reverseKGroup(self, head: ListNode, k: int) -> ListNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nstruct ListNode* reverseKGroup(struct ListNode* head, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public ListNode ReverseKGroup(ListNode head, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} head\n * @param {number} k\n * @return {ListNode}\n */\nvar reverseKGroup = function(head, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode} head\n# @param {Integer} k\n# @return {ListNode}\ndef reverse_k_group(head, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func reverseKGroup(_ head: ListNode?, _ k: Int) -> ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc reverseKGroup(head *ListNode, k int) *ListNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def reverseKGroup(head: ListNode, k: Int): ListNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun reverseKGroup(head: ListNode?, k: Int): ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn reverse_k_group(head: Option>, k: i32) -> Option> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @param Integer $k\n * @return ListNode\n */\n function reverseKGroup($head, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction reverseKGroup(head: ListNode | null, k: number): ListNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (reverse-k-group head k)\n (-> (or/c list-node? #f) exact-integer? (or/c list-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0025](https://leetcode-cn.com/problems/reverse-nodes-in-k-group)", "[K \u4e2a\u4e00\u7ec4\u7ffb\u8f6c\u94fe\u8868](/solution/0000-0099/0025.Reverse%20Nodes%20in%20k-Group/README.md)", "`\u94fe\u8868`", "\u56f0\u96be", ""], "md_table_row_en": ["[0025](https://leetcode.com/problems/reverse-nodes-in-k-group)", "[Reverse Nodes in k-Group](/solution/0000-0099/0025.Reverse%20Nodes%20in%20k-Group/README_EN.md)", "`Linked List`", "Hard", ""]}, {"question_id": "0024", "frontend_question_id": "0024", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/swap-nodes-in-pairs", "url_en": "https://leetcode.com/problems/swap-nodes-in-pairs", "relative_path_cn": "/solution/0000-0099/0024.Swap%20Nodes%20in%20Pairs/README.md", "relative_path_en": "/solution/0000-0099/0024.Swap%20Nodes%20in%20Pairs/README_EN.md", "title_cn": "\u4e24\u4e24\u4ea4\u6362\u94fe\u8868\u4e2d\u7684\u8282\u70b9", "title_en": "Swap Nodes in Pairs", "question_title_slug": "swap-nodes-in-pairs", "content_en": "

    Given a linked list, swap every two adjacent nodes and return its head. You must solve the problem without modifying the values in the list's nodes (i.e., only nodes themselves may be changed.)

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: head = [1,2,3,4]\nOutput: [2,1,4,3]\n
    \n\n

    Example 2:

    \n\n
    \nInput: head = []\nOutput: []\n
    \n\n

    Example 3:

    \n\n
    \nInput: head = [1]\nOutput: [1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the list is in the range [0, 100].
    • \n\t
    • 0 <= Node.val <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u94fe\u8868\uff0c\u4e24\u4e24\u4ea4\u6362\u5176\u4e2d\u76f8\u90bb\u7684\u8282\u70b9\uff0c\u5e76\u8fd4\u56de\u4ea4\u6362\u540e\u7684\u94fe\u8868\u3002

    \n\n

    \u4f60\u4e0d\u80fd\u53ea\u662f\u5355\u7eaf\u7684\u6539\u53d8\u8282\u70b9\u5185\u90e8\u7684\u503c\uff0c\u800c\u662f\u9700\u8981\u5b9e\u9645\u7684\u8fdb\u884c\u8282\u70b9\u4ea4\u6362\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1ahead = [1,2,3,4]\n\u8f93\u51fa\uff1a[2,1,4,3]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahead = []\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahead = [1]\n\u8f93\u51fa\uff1a[1]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u94fe\u8868\u4e2d\u8282\u70b9\u7684\u6570\u76ee\u5728\u8303\u56f4 [0, 100] \u5185
    • \n\t
    • 0 <= Node.val <= 100
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u80fd\u5728\u4e0d\u4fee\u6539\u94fe\u8868\u8282\u70b9\u503c\u7684\u60c5\u51b5\u4e0b\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u5417?\uff08\u4e5f\u5c31\u662f\u8bf4\uff0c\u4ec5\u4fee\u6539\u8282\u70b9\u672c\u8eab\u3002\uff09

    \n", "tags_en": ["Recursion", "Linked List"], "tags_cn": ["\u9012\u5f52", "\u94fe\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n ListNode* swapPairs(ListNode* head) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public ListNode swapPairs(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def swapPairs(self, head):\n \"\"\"\n :type head: ListNode\n :rtype: ListNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def swapPairs(self, head: ListNode) -> ListNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nstruct ListNode* swapPairs(struct ListNode* head){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public ListNode SwapPairs(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} head\n * @return {ListNode}\n */\nvar swapPairs = function(head) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode} head\n# @return {ListNode}\ndef swap_pairs(head)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func swapPairs(_ head: ListNode?) -> ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc swapPairs(head *ListNode) *ListNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def swapPairs(head: ListNode): ListNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun swapPairs(head: ListNode?): ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn swap_pairs(head: Option>) -> Option> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @return ListNode\n */\n function swapPairs($head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction swapPairs(head: ListNode | null): ListNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (swap-pairs head)\n (-> (or/c list-node? #f) (or/c list-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0024](https://leetcode-cn.com/problems/swap-nodes-in-pairs)", "[\u4e24\u4e24\u4ea4\u6362\u94fe\u8868\u4e2d\u7684\u8282\u70b9](/solution/0000-0099/0024.Swap%20Nodes%20in%20Pairs/README.md)", "`\u9012\u5f52`,`\u94fe\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0024](https://leetcode.com/problems/swap-nodes-in-pairs)", "[Swap Nodes in Pairs](/solution/0000-0099/0024.Swap%20Nodes%20in%20Pairs/README_EN.md)", "`Recursion`,`Linked List`", "Medium", ""]}, {"question_id": "0023", "frontend_question_id": "0023", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/merge-k-sorted-lists", "url_en": "https://leetcode.com/problems/merge-k-sorted-lists", "relative_path_cn": "/solution/0000-0099/0023.Merge%20k%20Sorted%20Lists/README.md", "relative_path_en": "/solution/0000-0099/0023.Merge%20k%20Sorted%20Lists/README_EN.md", "title_cn": "\u5408\u5e76K\u4e2a\u5347\u5e8f\u94fe\u8868", "title_en": "Merge k Sorted Lists", "question_title_slug": "merge-k-sorted-lists", "content_en": "

    You are given an array of k linked-lists lists, each linked-list is sorted in ascending order.

    \n\n

    Merge all the linked-lists into one sorted linked-list and return it.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: lists = [[1,4,5],[1,3,4],[2,6]]\nOutput: [1,1,2,3,4,4,5,6]\nExplanation: The linked-lists are:\n[\n  1->4->5,\n  1->3->4,\n  2->6\n]\nmerging them into one sorted list:\n1->1->2->3->4->4->5->6\n
    \n\n

    Example 2:

    \n\n
    \nInput: lists = []\nOutput: []\n
    \n\n

    Example 3:

    \n\n
    \nInput: lists = [[]]\nOutput: []\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • k == lists.length
    • \n\t
    • 0 <= k <= 10^4
    • \n\t
    • 0 <= lists[i].length <= 500
    • \n\t
    • -10^4 <= lists[i][j] <= 10^4
    • \n\t
    • lists[i] is sorted in ascending order.
    • \n\t
    • The sum of lists[i].length won't exceed 10^4.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u94fe\u8868\u6570\u7ec4\uff0c\u6bcf\u4e2a\u94fe\u8868\u90fd\u5df2\u7ecf\u6309\u5347\u5e8f\u6392\u5217\u3002

    \n\n

    \u8bf7\u4f60\u5c06\u6240\u6709\u94fe\u8868\u5408\u5e76\u5230\u4e00\u4e2a\u5347\u5e8f\u94fe\u8868\u4e2d\uff0c\u8fd4\u56de\u5408\u5e76\u540e\u7684\u94fe\u8868\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1alists = [[1,4,5],[1,3,4],[2,6]]\n\u8f93\u51fa\uff1a[1,1,2,3,4,4,5,6]\n\u89e3\u91ca\uff1a\u94fe\u8868\u6570\u7ec4\u5982\u4e0b\uff1a\n[\n  1->4->5,\n  1->3->4,\n  2->6\n]\n\u5c06\u5b83\u4eec\u5408\u5e76\u5230\u4e00\u4e2a\u6709\u5e8f\u94fe\u8868\u4e2d\u5f97\u5230\u3002\n1->1->2->3->4->4->5->6\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1alists = []\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1alists = [[]]\n\u8f93\u51fa\uff1a[]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • k == lists.length
    • \n\t
    • 0 <= k <= 10^4
    • \n\t
    • 0 <= lists[i].length <= 500
    • \n\t
    • -10^4 <= lists[i][j] <= 10^4
    • \n\t
    • lists[i] \u6309 \u5347\u5e8f \u6392\u5217
    • \n\t
    • lists[i].length \u7684\u603b\u548c\u4e0d\u8d85\u8fc7 10^4
    • \n
    \n", "tags_en": ["Heap", "Linked List", "Divide and Conquer"], "tags_cn": ["\u5806", "\u94fe\u8868", "\u5206\u6cbb\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n ListNode* mergeKLists(vector& lists) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public ListNode mergeKLists(ListNode[] lists) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def mergeKLists(self, lists):\n \"\"\"\n :type lists: List[ListNode]\n :rtype: ListNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def mergeKLists(self, lists: List[ListNode]) -> ListNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nstruct ListNode* mergeKLists(struct ListNode** lists, int listsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public ListNode MergeKLists(ListNode[] lists) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode[]} lists\n * @return {ListNode}\n */\nvar mergeKLists = function(lists) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode[]} lists\n# @return {ListNode}\ndef merge_k_lists(lists)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func mergeKLists(_ lists: [ListNode?]) -> ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc mergeKLists(lists []*ListNode) *ListNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def mergeKLists(lists: Array[ListNode]): ListNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun mergeKLists(lists: Array): ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn merge_k_lists(lists: Vec>>) -> Option> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode[] $lists\n * @return ListNode\n */\n function mergeKLists($lists) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction mergeKLists(lists: Array): ListNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (merge-k-lists lists)\n (-> (listof (or/c list-node? #f)) (or/c list-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0023](https://leetcode-cn.com/problems/merge-k-sorted-lists)", "[\u5408\u5e76K\u4e2a\u5347\u5e8f\u94fe\u8868](/solution/0000-0099/0023.Merge%20k%20Sorted%20Lists/README.md)", "`\u5806`,`\u94fe\u8868`,`\u5206\u6cbb\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[0023](https://leetcode.com/problems/merge-k-sorted-lists)", "[Merge k Sorted Lists](/solution/0000-0099/0023.Merge%20k%20Sorted%20Lists/README_EN.md)", "`Heap`,`Linked List`,`Divide and Conquer`", "Hard", ""]}, {"question_id": "0022", "frontend_question_id": "0022", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/generate-parentheses", "url_en": "https://leetcode.com/problems/generate-parentheses", "relative_path_cn": "/solution/0000-0099/0022.Generate%20Parentheses/README.md", "relative_path_en": "/solution/0000-0099/0022.Generate%20Parentheses/README_EN.md", "title_cn": "\u62ec\u53f7\u751f\u6210", "title_en": "Generate Parentheses", "question_title_slug": "generate-parentheses", "content_en": "

    Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.

    \n\n

     

    \n

    Example 1:

    \n
    Input: n = 3\nOutput: [\"((()))\",\"(()())\",\"(())()\",\"()(())\",\"()()()\"]\n

    Example 2:

    \n
    Input: n = 1\nOutput: [\"()\"]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 8
    • \n
    \n", "content_cn": "

    \u6570\u5b57 n\u00a0\u4ee3\u8868\u751f\u6210\u62ec\u53f7\u7684\u5bf9\u6570\uff0c\u8bf7\u4f60\u8bbe\u8ba1\u4e00\u4e2a\u51fd\u6570\uff0c\u7528\u4e8e\u80fd\u591f\u751f\u6210\u6240\u6709\u53ef\u80fd\u7684\u5e76\u4e14 \u6709\u6548\u7684 \u62ec\u53f7\u7ec4\u5408\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 3\n\u8f93\u51fa\uff1a[\"((()))\",\"(()())\",\"(())()\",\"()(())\",\"()()()\"]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1a[\"()\"]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 8
    • \n
    \n", "tags_en": ["String", "Backtracking"], "tags_cn": ["\u5b57\u7b26\u4e32", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector generateParenthesis(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List generateParenthesis(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def generateParenthesis(self, n):\n \"\"\"\n :type n: int\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def generateParenthesis(self, n: int) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** generateParenthesis(int n, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList GenerateParenthesis(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {string[]}\n */\nvar generateParenthesis = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {String[]}\ndef generate_parenthesis(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func generateParenthesis(_ n: Int) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func generateParenthesis(n int) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def generateParenthesis(n: Int): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun generateParenthesis(n: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn generate_parenthesis(n: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return String[]\n */\n function generateParenthesis($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function generateParenthesis(n: number): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (generate-parenthesis n)\n (-> exact-integer? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0022](https://leetcode-cn.com/problems/generate-parentheses)", "[\u62ec\u53f7\u751f\u6210](/solution/0000-0099/0022.Generate%20Parentheses/README.md)", "`\u5b57\u7b26\u4e32`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0022](https://leetcode.com/problems/generate-parentheses)", "[Generate Parentheses](/solution/0000-0099/0022.Generate%20Parentheses/README_EN.md)", "`String`,`Backtracking`", "Medium", ""]}, {"question_id": "0021", "frontend_question_id": "0021", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/merge-two-sorted-lists", "url_en": "https://leetcode.com/problems/merge-two-sorted-lists", "relative_path_cn": "/solution/0000-0099/0021.Merge%20Two%20Sorted%20Lists/README.md", "relative_path_en": "/solution/0000-0099/0021.Merge%20Two%20Sorted%20Lists/README_EN.md", "title_cn": "\u5408\u5e76\u4e24\u4e2a\u6709\u5e8f\u94fe\u8868", "title_en": "Merge Two Sorted Lists", "question_title_slug": "merge-two-sorted-lists", "content_en": "

    Merge two sorted linked lists and return it as a sorted list. The list should be made by splicing together the nodes of the first two lists.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: l1 = [1,2,4], l2 = [1,3,4]\nOutput: [1,1,2,3,4,4]\n
    \n\n

    Example 2:

    \n\n
    \nInput: l1 = [], l2 = []\nOutput: []\n
    \n\n

    Example 3:

    \n\n
    \nInput: l1 = [], l2 = [0]\nOutput: [0]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in both lists is in the range [0, 50].
    • \n\t
    • -100 <= Node.val <= 100
    • \n\t
    • Both l1 and l2 are sorted in non-decreasing order.
    • \n
    \n", "content_cn": "

    \u5c06\u4e24\u4e2a\u5347\u5e8f\u94fe\u8868\u5408\u5e76\u4e3a\u4e00\u4e2a\u65b0\u7684 \u5347\u5e8f \u94fe\u8868\u5e76\u8fd4\u56de\u3002\u65b0\u94fe\u8868\u662f\u901a\u8fc7\u62fc\u63a5\u7ed9\u5b9a\u7684\u4e24\u4e2a\u94fe\u8868\u7684\u6240\u6709\u8282\u70b9\u7ec4\u6210\u7684\u3002\u00a0

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1al1 = [1,2,4], l2 = [1,3,4]\n\u8f93\u51fa\uff1a[1,1,2,3,4,4]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1al1 = [], l2 = []\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1al1 = [], l2 = [0]\n\u8f93\u51fa\uff1a[0]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u4e24\u4e2a\u94fe\u8868\u7684\u8282\u70b9\u6570\u76ee\u8303\u56f4\u662f [0, 50]
    • \n\t
    • -100 <= Node.val <= 100
    • \n\t
    • l1 \u548c l2 \u5747\u6309 \u975e\u9012\u51cf\u987a\u5e8f \u6392\u5217
    • \n
    \n", "tags_en": ["Recursion", "Linked List"], "tags_cn": ["\u9012\u5f52", "\u94fe\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public ListNode mergeTwoLists(ListNode l1, ListNode l2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def mergeTwoLists(self, l1, l2):\n \"\"\"\n :type l1: ListNode\n :type l2: ListNode\n :rtype: ListNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def mergeTwoLists(self, l1: ListNode, l2: ListNode) -> ListNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nstruct ListNode* mergeTwoLists(struct ListNode* l1, struct ListNode* l2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public ListNode MergeTwoLists(ListNode l1, ListNode l2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} l1\n * @param {ListNode} l2\n * @return {ListNode}\n */\nvar mergeTwoLists = function(l1, l2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode} l1\n# @param {ListNode} l2\n# @return {ListNode}\ndef merge_two_lists(l1, l2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func mergeTwoLists(_ l1: ListNode?, _ l2: ListNode?) -> ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc mergeTwoLists(l1 *ListNode, l2 *ListNode) *ListNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def mergeTwoLists(l1: ListNode, l2: ListNode): ListNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun mergeTwoLists(l1: ListNode?, l2: ListNode?): ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn merge_two_lists(l1: Option>, l2: Option>) -> Option> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $l1\n * @param ListNode $l2\n * @return ListNode\n */\n function mergeTwoLists($l1, $l2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction mergeTwoLists(l1: ListNode | null, l2: ListNode | null): ListNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (merge-two-lists l1 l2)\n (-> (or/c list-node? #f) (or/c list-node? #f) (or/c list-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0021](https://leetcode-cn.com/problems/merge-two-sorted-lists)", "[\u5408\u5e76\u4e24\u4e2a\u6709\u5e8f\u94fe\u8868](/solution/0000-0099/0021.Merge%20Two%20Sorted%20Lists/README.md)", "`\u9012\u5f52`,`\u94fe\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0021](https://leetcode.com/problems/merge-two-sorted-lists)", "[Merge Two Sorted Lists](/solution/0000-0099/0021.Merge%20Two%20Sorted%20Lists/README_EN.md)", "`Recursion`,`Linked List`", "Easy", ""]}, {"question_id": "0020", "frontend_question_id": "0020", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/valid-parentheses", "url_en": "https://leetcode.com/problems/valid-parentheses", "relative_path_cn": "/solution/0000-0099/0020.Valid%20Parentheses/README.md", "relative_path_en": "/solution/0000-0099/0020.Valid%20Parentheses/README_EN.md", "title_cn": "\u6709\u6548\u7684\u62ec\u53f7", "title_en": "Valid Parentheses", "question_title_slug": "valid-parentheses", "content_en": "

    Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.

    \n\n

    An input string is valid if:

    \n\n
      \n\t
    1. Open brackets must be closed by the same type of brackets.
    2. \n\t
    3. Open brackets must be closed in the correct order.
    4. \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "()"\nOutput: true\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "()[]{}"\nOutput: true\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "(]"\nOutput: false\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "([)]"\nOutput: false\n
    \n\n

    Example 5:

    \n\n
    \nInput: s = "{[]}"\nOutput: true\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 104
    • \n\t
    • s consists of parentheses only '()[]{}'.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u53ea\u5305\u62ec '('\uff0c')'\uff0c'{'\uff0c'}'\uff0c'['\uff0c']'\u00a0\u7684\u5b57\u7b26\u4e32 s \uff0c\u5224\u65ad\u5b57\u7b26\u4e32\u662f\u5426\u6709\u6548\u3002

    \n\n

    \u6709\u6548\u5b57\u7b26\u4e32\u9700\u6ee1\u8db3\uff1a

    \n\n
      \n\t
    1. \u5de6\u62ec\u53f7\u5fc5\u987b\u7528\u76f8\u540c\u7c7b\u578b\u7684\u53f3\u62ec\u53f7\u95ed\u5408\u3002
    2. \n\t
    3. \u5de6\u62ec\u53f7\u5fc5\u987b\u4ee5\u6b63\u786e\u7684\u987a\u5e8f\u95ed\u5408\u3002
    4. \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"()\"\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b\u00a02\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"()[]{}\"\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b\u00a03\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"(]\"\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b\u00a04\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"([)]\"\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b\u00a05\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"{[]}\"\n\u8f93\u51fa\uff1atrue
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 104
    • \n\t
    • s \u4ec5\u7531\u62ec\u53f7 '()[]{}' \u7ec4\u6210
    • \n
    \n", "tags_en": ["Stack", "String"], "tags_cn": ["\u6808", "\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isValid(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isValid(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isValid(self, s):\n \"\"\"\n :type s: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isValid(self, s: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isValid(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsValid(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {boolean}\n */\nvar isValid = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Boolean}\ndef is_valid(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isValid(_ s: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isValid(s string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isValid(s: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isValid(s: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_valid(s: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Boolean\n */\n function isValid($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isValid(s: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-valid s)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0020](https://leetcode-cn.com/problems/valid-parentheses)", "[\u6709\u6548\u7684\u62ec\u53f7](/solution/0000-0099/0020.Valid%20Parentheses/README.md)", "`\u6808`,`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0020](https://leetcode.com/problems/valid-parentheses)", "[Valid Parentheses](/solution/0000-0099/0020.Valid%20Parentheses/README_EN.md)", "`Stack`,`String`", "Easy", ""]}, {"question_id": "0019", "frontend_question_id": "0019", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list", "url_en": "https://leetcode.com/problems/remove-nth-node-from-end-of-list", "relative_path_cn": "/solution/0000-0099/0019.Remove%20Nth%20Node%20From%20End%20of%20List/README.md", "relative_path_en": "/solution/0000-0099/0019.Remove%20Nth%20Node%20From%20End%20of%20List/README_EN.md", "title_cn": "\u5220\u9664\u94fe\u8868\u7684\u5012\u6570\u7b2c N \u4e2a\u7ed3\u70b9", "title_en": "Remove Nth Node From End of List", "question_title_slug": "remove-nth-node-from-end-of-list", "content_en": "

    Given the head of a linked list, remove the nth node from the end of the list and return its head.

    \n\n

    Follow up: Could you do this in one pass?

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: head = [1,2,3,4,5], n = 2\nOutput: [1,2,3,5]\n
    \n\n

    Example 2:

    \n\n
    \nInput: head = [1], n = 1\nOutput: []\n
    \n\n

    Example 3:

    \n\n
    \nInput: head = [1,2], n = 1\nOutput: [1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the list is sz.
    • \n\t
    • 1 <= sz <= 30
    • \n\t
    • 0 <= Node.val <= 100
    • \n\t
    • 1 <= n <= sz
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u94fe\u8868\uff0c\u5220\u9664\u94fe\u8868\u7684\u5012\u6570\u7b2c\u00a0n\u00a0\u4e2a\u7ed3\u70b9\uff0c\u5e76\u4e14\u8fd4\u56de\u94fe\u8868\u7684\u5934\u7ed3\u70b9\u3002

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u80fd\u5c1d\u8bd5\u4f7f\u7528\u4e00\u8d9f\u626b\u63cf\u5b9e\u73b0\u5417\uff1f

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1ahead = [1,2,3,4,5], n = 2\n\u8f93\u51fa\uff1a[1,2,3,5]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahead = [1], n = 1\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahead = [1,2], n = 1\n\u8f93\u51fa\uff1a[1]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u94fe\u8868\u4e2d\u7ed3\u70b9\u7684\u6570\u76ee\u4e3a sz
    • \n\t
    • 1 <= sz <= 30
    • \n\t
    • 0 <= Node.val <= 100
    • \n\t
    • 1 <= n <= sz
    • \n
    \n", "tags_en": ["Linked List", "Two Pointers"], "tags_cn": ["\u94fe\u8868", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n ListNode* removeNthFromEnd(ListNode* head, int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public ListNode removeNthFromEnd(ListNode head, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def removeNthFromEnd(self, head, n):\n \"\"\"\n :type head: ListNode\n :type n: int\n :rtype: ListNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def removeNthFromEnd(self, head: ListNode, n: int) -> ListNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nstruct ListNode* removeNthFromEnd(struct ListNode* head, int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public ListNode RemoveNthFromEnd(ListNode head, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} head\n * @param {number} n\n * @return {ListNode}\n */\nvar removeNthFromEnd = function(head, n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode} head\n# @param {Integer} n\n# @return {ListNode}\ndef remove_nth_from_end(head, n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func removeNthFromEnd(_ head: ListNode?, _ n: Int) -> ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc removeNthFromEnd(head *ListNode, n int) *ListNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def removeNthFromEnd(head: ListNode, n: Int): ListNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun removeNthFromEnd(head: ListNode?, n: Int): ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn remove_nth_from_end(head: Option>, n: i32) -> Option> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @param Integer $n\n * @return ListNode\n */\n function removeNthFromEnd($head, $n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction removeNthFromEnd(head: ListNode | null, n: number): ListNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (remove-nth-from-end head n)\n (-> (or/c list-node? #f) exact-integer? (or/c list-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0019](https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list)", "[\u5220\u9664\u94fe\u8868\u7684\u5012\u6570\u7b2c N \u4e2a\u7ed3\u70b9](/solution/0000-0099/0019.Remove%20Nth%20Node%20From%20End%20of%20List/README.md)", "`\u94fe\u8868`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0019](https://leetcode.com/problems/remove-nth-node-from-end-of-list)", "[Remove Nth Node From End of List](/solution/0000-0099/0019.Remove%20Nth%20Node%20From%20End%20of%20List/README_EN.md)", "`Linked List`,`Two Pointers`", "Medium", ""]}, {"question_id": "0018", "frontend_question_id": "0018", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/4sum", "url_en": "https://leetcode.com/problems/4sum", "relative_path_cn": "/solution/0000-0099/0018.4Sum/README.md", "relative_path_en": "/solution/0000-0099/0018.4Sum/README_EN.md", "title_cn": "\u56db\u6570\u4e4b\u548c", "title_en": "4Sum", "question_title_slug": "4sum", "content_en": "

    Given an array nums of n integers, return an array of all the unique quadruplets [nums[a], nums[b], nums[c], nums[d]] such that:

    \n\n
      \n\t
    • 0 <= a, b, c, d < n
    • \n\t
    • a, b, c, and d are distinct.
    • \n\t
    • nums[a] + nums[b] + nums[c] + nums[d] == target
    • \n
    \n\n

    You may return the answer in any order.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,0,-1,0,-2,2], target = 0\nOutput: [[-2,-1,1,2],[-2,0,0,2],[-1,0,0,1]]\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [2,2,2,2,2], target = 8\nOutput: [[2,2,2,2]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 200
    • \n\t
    • -109 <= nums[i] <= 109
    • \n\t
    • -109 <= target <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5305\u542b\u00a0n \u4e2a\u6574\u6570\u7684\u6570\u7ec4\u00a0nums\u00a0\u548c\u4e00\u4e2a\u76ee\u6807\u503c\u00a0target\uff0c\u5224\u65ad\u00a0nums\u00a0\u4e2d\u662f\u5426\u5b58\u5728\u56db\u4e2a\u5143\u7d20 a\uff0cb\uff0cc\u00a0\u548c d\u00a0\uff0c\u4f7f\u5f97\u00a0a + b + c + d\u00a0\u7684\u503c\u4e0e\u00a0target\u00a0\u76f8\u7b49\uff1f\u627e\u51fa\u6240\u6709\u6ee1\u8db3\u6761\u4ef6\u4e14\u4e0d\u91cd\u590d\u7684\u56db\u5143\u7ec4\u3002

    \n\n

    \u6ce8\u610f\uff1a\u7b54\u6848\u4e2d\u4e0d\u53ef\u4ee5\u5305\u542b\u91cd\u590d\u7684\u56db\u5143\u7ec4\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,0,-1,0,-2,2], target = 0\n\u8f93\u51fa\uff1a[[-2,-1,1,2],[-2,0,0,2],[-1,0,0,1]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [], target = 0\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= nums.length <= 200
    • \n\t
    • -109 <= nums[i] <= 109
    • \n\t
    • -109 <= target <= 109
    • \n
    \n", "tags_en": ["Array", "Hash Table", "Two Pointers"], "tags_cn": ["\u6570\u7ec4", "\u54c8\u5e0c\u8868", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> fourSum(vector& nums, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> fourSum(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def fourSum(self, nums, target):\n \"\"\"\n :type nums: List[int]\n :type target: int\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def fourSum(self, nums: List[int], target: int) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** fourSum(int* nums, int numsSize, int target, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> FourSum(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} target\n * @return {number[][]}\n */\nvar fourSum = function(nums, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} target\n# @return {Integer[][]}\ndef four_sum(nums, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func fourSum(_ nums: [Int], _ target: Int) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func fourSum(nums []int, target int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def fourSum(nums: Array[Int], target: Int): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun fourSum(nums: IntArray, target: Int): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn four_sum(nums: Vec, target: i32) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $target\n * @return Integer[][]\n */\n function fourSum($nums, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function fourSum(nums: number[], target: number): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (four-sum nums target)\n (-> (listof exact-integer?) exact-integer? (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0018](https://leetcode-cn.com/problems/4sum)", "[\u56db\u6570\u4e4b\u548c](/solution/0000-0099/0018.4Sum/README.md)", "`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0018](https://leetcode.com/problems/4sum)", "[4Sum](/solution/0000-0099/0018.4Sum/README_EN.md)", "`Array`,`Hash Table`,`Two Pointers`", "Medium", ""]}, {"question_id": "0017", "frontend_question_id": "0017", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number", "url_en": "https://leetcode.com/problems/letter-combinations-of-a-phone-number", "relative_path_cn": "/solution/0000-0099/0017.Letter%20Combinations%20of%20a%20Phone%20Number/README.md", "relative_path_en": "/solution/0000-0099/0017.Letter%20Combinations%20of%20a%20Phone%20Number/README_EN.md", "title_cn": "\u7535\u8bdd\u53f7\u7801\u7684\u5b57\u6bcd\u7ec4\u5408", "title_en": "Letter Combinations of a Phone Number", "question_title_slug": "letter-combinations-of-a-phone-number", "content_en": "

    Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. Return the answer in any order.

    \n\n

    A mapping of digit to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters.

    \n\n

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: digits = "23"\nOutput: ["ad","ae","af","bd","be","bf","cd","ce","cf"]\n
    \n\n

    Example 2:

    \n\n
    \nInput: digits = ""\nOutput: []\n
    \n\n

    Example 3:

    \n\n
    \nInput: digits = "2"\nOutput: ["a","b","c"]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= digits.length <= 4
    • \n\t
    • digits[i] is a digit in the range ['2', '9'].
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4ec5\u5305\u542b\u6570\u5b57\u00a02-9\u00a0\u7684\u5b57\u7b26\u4e32\uff0c\u8fd4\u56de\u6240\u6709\u5b83\u80fd\u8868\u793a\u7684\u5b57\u6bcd\u7ec4\u5408\u3002\u7b54\u6848\u53ef\u4ee5\u6309 \u4efb\u610f\u987a\u5e8f \u8fd4\u56de\u3002

    \n\n

    \u7ed9\u51fa\u6570\u5b57\u5230\u5b57\u6bcd\u7684\u6620\u5c04\u5982\u4e0b\uff08\u4e0e\u7535\u8bdd\u6309\u952e\u76f8\u540c\uff09\u3002\u6ce8\u610f 1 \u4e0d\u5bf9\u5e94\u4efb\u4f55\u5b57\u6bcd\u3002

    \n\n

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1adigits = \"23\"\n\u8f93\u51fa\uff1a[\"ad\",\"ae\",\"af\",\"bd\",\"be\",\"bf\",\"cd\",\"ce\",\"cf\"]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1adigits = \"\"\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1adigits = \"2\"\n\u8f93\u51fa\uff1a[\"a\",\"b\",\"c\"]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= digits.length <= 4
    • \n\t
    • digits[i] \u662f\u8303\u56f4 ['2', '9'] \u7684\u4e00\u4e2a\u6570\u5b57\u3002
    • \n
    \n", "tags_en": ["Depth-first Search", "Recursion", "String", "Backtracking"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u9012\u5f52", "\u5b57\u7b26\u4e32", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector letterCombinations(string digits) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List letterCombinations(String digits) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def letterCombinations(self, digits):\n \"\"\"\n :type digits: str\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def letterCombinations(self, digits: str) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** letterCombinations(char * digits, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList LetterCombinations(string digits) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} digits\n * @return {string[]}\n */\nvar letterCombinations = function(digits) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} digits\n# @return {String[]}\ndef letter_combinations(digits)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func letterCombinations(_ digits: String) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func letterCombinations(digits string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def letterCombinations(digits: String): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun letterCombinations(digits: String): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn letter_combinations(digits: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $digits\n * @return String[]\n */\n function letterCombinations($digits) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function letterCombinations(digits: string): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (letter-combinations digits)\n (-> string? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0017](https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number)", "[\u7535\u8bdd\u53f7\u7801\u7684\u5b57\u6bcd\u7ec4\u5408](/solution/0000-0099/0017.Letter%20Combinations%20of%20a%20Phone%20Number/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u9012\u5f52`,`\u5b57\u7b26\u4e32`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0017](https://leetcode.com/problems/letter-combinations-of-a-phone-number)", "[Letter Combinations of a Phone Number](/solution/0000-0099/0017.Letter%20Combinations%20of%20a%20Phone%20Number/README_EN.md)", "`Depth-first Search`,`Recursion`,`String`,`Backtracking`", "Medium", ""]}, {"question_id": "0016", "frontend_question_id": "0016", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/3sum-closest", "url_en": "https://leetcode.com/problems/3sum-closest", "relative_path_cn": "/solution/0000-0099/0016.3Sum%20Closest/README.md", "relative_path_en": "/solution/0000-0099/0016.3Sum%20Closest/README_EN.md", "title_cn": "\u6700\u63a5\u8fd1\u7684\u4e09\u6570\u4e4b\u548c", "title_en": "3Sum Closest", "question_title_slug": "3sum-closest", "content_en": "

    Given an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume that each input would have exactly one solution.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [-1,2,1,-4], target = 1\nOutput: 2\nExplanation: The sum that is closest to the target is 2. (-1 + 2 + 1 = 2).\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 3 <= nums.length <= 10^3
    • \n\t
    • -10^3 <= nums[i] <= 10^3
    • \n\t
    • -10^4 <= target <= 10^4
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5305\u62ec n \u4e2a\u6574\u6570\u7684\u6570\u7ec4 nums \u548c \u4e00\u4e2a\u76ee\u6807\u503c target\u3002\u627e\u51fa nums \u4e2d\u7684\u4e09\u4e2a\u6574\u6570\uff0c\u4f7f\u5f97\u5b83\u4eec\u7684\u548c\u4e0e target \u6700\u63a5\u8fd1\u3002\u8fd4\u56de\u8fd9\u4e09\u4e2a\u6570\u7684\u548c\u3002\u5047\u5b9a\u6bcf\u7ec4\u8f93\u5165\u53ea\u5b58\u5728\u552f\u4e00\u7b54\u6848\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [-1,2,1,-4], target = 1\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u4e0e target \u6700\u63a5\u8fd1\u7684\u548c\u662f 2 (-1 + 2 + 1 = 2) \u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 3 <= nums.length <= 10^3
    • \n\t
    • -10^3 <= nums[i] <= 10^3
    • \n\t
    • -10^4 <= target <= 10^4
    • \n
    \n", "tags_en": ["Array", "Two Pointers"], "tags_cn": ["\u6570\u7ec4", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int threeSumClosest(vector& nums, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int threeSumClosest(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def threeSumClosest(self, nums, target):\n \"\"\"\n :type nums: List[int]\n :type target: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def threeSumClosest(self, nums: List[int], target: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint threeSumClosest(int* nums, int numsSize, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ThreeSumClosest(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} target\n * @return {number}\n */\nvar threeSumClosest = function(nums, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} target\n# @return {Integer}\ndef three_sum_closest(nums, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func threeSumClosest(_ nums: [Int], _ target: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func threeSumClosest(nums []int, target int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def threeSumClosest(nums: Array[Int], target: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun threeSumClosest(nums: IntArray, target: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn three_sum_closest(nums: Vec, target: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $target\n * @return Integer\n */\n function threeSumClosest($nums, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function threeSumClosest(nums: number[], target: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (three-sum-closest nums target)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0016](https://leetcode-cn.com/problems/3sum-closest)", "[\u6700\u63a5\u8fd1\u7684\u4e09\u6570\u4e4b\u548c](/solution/0000-0099/0016.3Sum%20Closest/README.md)", "`\u6570\u7ec4`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0016](https://leetcode.com/problems/3sum-closest)", "[3Sum Closest](/solution/0000-0099/0016.3Sum%20Closest/README_EN.md)", "`Array`,`Two Pointers`", "Medium", ""]}, {"question_id": "0015", "frontend_question_id": "0015", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/3sum", "url_en": "https://leetcode.com/problems/3sum", "relative_path_cn": "/solution/0000-0099/0015.3Sum/README.md", "relative_path_en": "/solution/0000-0099/0015.3Sum/README_EN.md", "title_cn": "\u4e09\u6570\u4e4b\u548c", "title_en": "3Sum", "question_title_slug": "3sum", "content_en": "

    Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0.

    \n\n

    Notice that the solution set must not contain duplicate triplets.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [-1,0,1,2,-1,-4]\nOutput: [[-1,-1,2],[-1,0,1]]\n

    Example 2:

    \n
    Input: nums = []\nOutput: []\n

    Example 3:

    \n
    Input: nums = [0]\nOutput: []\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= nums.length <= 3000
    • \n\t
    • -105 <= nums[i] <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5305\u542b n \u4e2a\u6574\u6570\u7684\u6570\u7ec4\u00a0nums\uff0c\u5224\u65ad\u00a0nums\u00a0\u4e2d\u662f\u5426\u5b58\u5728\u4e09\u4e2a\u5143\u7d20 a\uff0cb\uff0cc \uff0c\u4f7f\u5f97\u00a0a + b + c = 0 \uff1f\u8bf7\u4f60\u627e\u51fa\u6240\u6709\u548c\u4e3a 0 \u4e14\u4e0d\u91cd\u590d\u7684\u4e09\u5143\u7ec4\u3002

    \n\n

    \u6ce8\u610f\uff1a\u7b54\u6848\u4e2d\u4e0d\u53ef\u4ee5\u5305\u542b\u91cd\u590d\u7684\u4e09\u5143\u7ec4\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [-1,0,1,2,-1,-4]\n\u8f93\u51fa\uff1a[[-1,-1,2],[-1,0,1]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = []\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [0]\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= nums.length <= 3000
    • \n\t
    • -105 <= nums[i] <= 105
    • \n
    \n", "tags_en": ["Array", "Two Pointers"], "tags_cn": ["\u6570\u7ec4", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> threeSum(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> threeSum(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def threeSum(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def threeSum(self, nums: List[int]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** threeSum(int* nums, int numsSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> ThreeSum(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number[][]}\n */\nvar threeSum = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer[][]}\ndef three_sum(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func threeSum(_ nums: [Int]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func threeSum(nums []int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def threeSum(nums: Array[Int]): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun threeSum(nums: IntArray): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn three_sum(nums: Vec) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer[][]\n */\n function threeSum($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function threeSum(nums: number[]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (three-sum nums)\n (-> (listof exact-integer?) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0015](https://leetcode-cn.com/problems/3sum)", "[\u4e09\u6570\u4e4b\u548c](/solution/0000-0099/0015.3Sum/README.md)", "`\u6570\u7ec4`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0015](https://leetcode.com/problems/3sum)", "[3Sum](/solution/0000-0099/0015.3Sum/README_EN.md)", "`Array`,`Two Pointers`", "Medium", ""]}, {"question_id": "0014", "frontend_question_id": "0014", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-common-prefix", "url_en": "https://leetcode.com/problems/longest-common-prefix", "relative_path_cn": "/solution/0000-0099/0014.Longest%20Common%20Prefix/README.md", "relative_path_en": "/solution/0000-0099/0014.Longest%20Common%20Prefix/README_EN.md", "title_cn": "\u6700\u957f\u516c\u5171\u524d\u7f00", "title_en": "Longest Common Prefix", "question_title_slug": "longest-common-prefix", "content_en": "

    Write a function to find the longest common prefix string amongst an array of strings.

    \n\n

    If there is no common prefix, return an empty string "".

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: strs = ["flower","flow","flight"]\nOutput: "fl"\n
    \n\n

    Example 2:

    \n\n
    \nInput: strs = ["dog","racecar","car"]\nOutput: ""\nExplanation: There is no common prefix among the input strings.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= strs.length <= 200
    • \n\t
    • 0 <= strs[i].length <= 200
    • \n\t
    • strs[i] consists of only lower-case English letters.
    • \n
    \n", "content_cn": "

    \u7f16\u5199\u4e00\u4e2a\u51fd\u6570\u6765\u67e5\u627e\u5b57\u7b26\u4e32\u6570\u7ec4\u4e2d\u7684\u6700\u957f\u516c\u5171\u524d\u7f00\u3002

    \n\n

    \u5982\u679c\u4e0d\u5b58\u5728\u516c\u5171\u524d\u7f00\uff0c\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32\u00a0\"\"\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1astrs = [\"flower\",\"flow\",\"flight\"]\n\u8f93\u51fa\uff1a\"fl\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1astrs = [\"dog\",\"racecar\",\"car\"]\n\u8f93\u51fa\uff1a\"\"\n\u89e3\u91ca\uff1a\u8f93\u5165\u4e0d\u5b58\u5728\u516c\u5171\u524d\u7f00\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= strs.length <= 200
    • \n\t
    • 0 <= strs[i].length <= 200
    • \n\t
    • strs[i] \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string longestCommonPrefix(vector& strs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String longestCommonPrefix(String[] strs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestCommonPrefix(self, strs):\n \"\"\"\n :type strs: List[str]\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestCommonPrefix(self, strs: List[str]) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * longestCommonPrefix(char ** strs, int strsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string LongestCommonPrefix(string[] strs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} strs\n * @return {string}\n */\nvar longestCommonPrefix = function(strs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} strs\n# @return {String}\ndef longest_common_prefix(strs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestCommonPrefix(_ strs: [String]) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestCommonPrefix(strs []string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestCommonPrefix(strs: Array[String]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestCommonPrefix(strs: Array): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_common_prefix(strs: Vec) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $strs\n * @return String\n */\n function longestCommonPrefix($strs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestCommonPrefix(strs: string[]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-common-prefix strs)\n (-> (listof string?) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0014](https://leetcode-cn.com/problems/longest-common-prefix)", "[\u6700\u957f\u516c\u5171\u524d\u7f00](/solution/0000-0099/0014.Longest%20Common%20Prefix/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0014](https://leetcode.com/problems/longest-common-prefix)", "[Longest Common Prefix](/solution/0000-0099/0014.Longest%20Common%20Prefix/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "0013", "frontend_question_id": "0013", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/roman-to-integer", "url_en": "https://leetcode.com/problems/roman-to-integer", "relative_path_cn": "/solution/0000-0099/0013.Roman%20to%20Integer/README.md", "relative_path_en": "/solution/0000-0099/0013.Roman%20to%20Integer/README_EN.md", "title_cn": "\u7f57\u9a6c\u6570\u5b57\u8f6c\u6574\u6570", "title_en": "Roman to Integer", "question_title_slug": "roman-to-integer", "content_en": "

    Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.

    \n\n
    \nSymbol       Value\nI             1\nV             5\nX             10\nL             50\nC             100\nD             500\nM             1000
    \n\n

    For example, 2 is written as II in Roman numeral, just two one's added together. 12 is written as XII, which is simply X + II. The number 27 is written as XXVII, which is XX + V + II.

    \n\n

    Roman numerals are usually written largest to smallest from left to right. However, the numeral for four is not IIII. Instead, the number four is written as IV. Because the one is before the five we subtract it making four. The same principle applies to the number nine, which is written as IX. There are six instances where subtraction is used:

    \n\n
      \n\t
    • I can be placed before V (5) and X (10) to make 4 and 9. 
    • \n\t
    • X can be placed before L (50) and C (100) to make 40 and 90. 
    • \n\t
    • C can be placed before D (500) and M (1000) to make 400 and 900.
    • \n
    \n\n

    Given a roman numeral, convert it to an integer.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "III"\nOutput: 3\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "IV"\nOutput: 4\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "IX"\nOutput: 9\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "LVIII"\nOutput: 58\nExplanation: L = 50, V= 5, III = 3.\n
    \n\n

    Example 5:

    \n\n
    \nInput: s = "MCMXCIV"\nOutput: 1994\nExplanation: M = 1000, CM = 900, XC = 90 and IV = 4.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 15
    • \n\t
    • s contains only the characters ('I', 'V', 'X', 'L', 'C', 'D', 'M').
    • \n\t
    • It is guaranteed that s is a valid roman numeral in the range [1, 3999].
    • \n
    \n", "content_cn": "

    \u7f57\u9a6c\u6570\u5b57\u5305\u542b\u4ee5\u4e0b\u4e03\u79cd\u5b57\u7b26:\u00a0I\uff0c\u00a0V\uff0c\u00a0X\uff0c\u00a0L\uff0cC\uff0cD\u00a0\u548c\u00a0M\u3002

    \n\n
    \n\u5b57\u7b26          \u6570\u503c\nI             1\nV             5\nX             10\nL             50\nC             100\nD             500\nM             1000
    \n\n

    \u4f8b\u5982\uff0c \u7f57\u9a6c\u6570\u5b57 2 \u5199\u505a\u00a0II\u00a0\uff0c\u5373\u4e3a\u4e24\u4e2a\u5e76\u5217\u7684 1\u300212 \u5199\u505a\u00a0XII\u00a0\uff0c\u5373\u4e3a\u00a0X\u00a0+\u00a0II\u00a0\u3002 27 \u5199\u505a\u00a0\u00a0XXVII, \u5373\u4e3a\u00a0XX\u00a0+\u00a0V\u00a0+\u00a0II\u00a0\u3002

    \n\n

    \u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u7f57\u9a6c\u6570\u5b57\u4e2d\u5c0f\u7684\u6570\u5b57\u5728\u5927\u7684\u6570\u5b57\u7684\u53f3\u8fb9\u3002\u4f46\u4e5f\u5b58\u5728\u7279\u4f8b\uff0c\u4f8b\u5982 4 \u4e0d\u5199\u505a\u00a0IIII\uff0c\u800c\u662f\u00a0IV\u3002\u6570\u5b57 1 \u5728\u6570\u5b57 5 \u7684\u5de6\u8fb9\uff0c\u6240\u8868\u793a\u7684\u6570\u7b49\u4e8e\u5927\u6570 5 \u51cf\u5c0f\u6570 1 \u5f97\u5230\u7684\u6570\u503c 4 \u3002\u540c\u6837\u5730\uff0c\u6570\u5b57 9 \u8868\u793a\u4e3a\u00a0IX\u3002\u8fd9\u4e2a\u7279\u6b8a\u7684\u89c4\u5219\u53ea\u9002\u7528\u4e8e\u4ee5\u4e0b\u516d\u79cd\u60c5\u51b5\uff1a

    \n\n
      \n\t
    • I\u00a0\u53ef\u4ee5\u653e\u5728\u00a0V\u00a0(5) \u548c\u00a0X\u00a0(10) \u7684\u5de6\u8fb9\uff0c\u6765\u8868\u793a 4 \u548c 9\u3002
    • \n\t
    • X\u00a0\u53ef\u4ee5\u653e\u5728\u00a0L\u00a0(50) \u548c\u00a0C\u00a0(100) \u7684\u5de6\u8fb9\uff0c\u6765\u8868\u793a 40 \u548c\u00a090\u3002\u00a0
    • \n\t
    • C\u00a0\u53ef\u4ee5\u653e\u5728\u00a0D\u00a0(500) \u548c\u00a0M\u00a0(1000) \u7684\u5de6\u8fb9\uff0c\u6765\u8868\u793a\u00a0400 \u548c\u00a0900\u3002
    • \n
    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u7f57\u9a6c\u6570\u5b57\uff0c\u5c06\u5176\u8f6c\u6362\u6210\u6574\u6570\u3002\u8f93\u5165\u786e\u4fdd\u5728 1\u00a0\u5230 3999 \u7684\u8303\u56f4\u5185\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\u00a01:

    \n\n
    \n\u8f93\u5165:\u00a0\"III\"\n\u8f93\u51fa: 3
    \n\n

    \u793a\u4f8b\u00a02:

    \n\n
    \n\u8f93\u5165:\u00a0\"IV\"\n\u8f93\u51fa: 4
    \n\n

    \u793a\u4f8b\u00a03:

    \n\n
    \n\u8f93\u5165:\u00a0\"IX\"\n\u8f93\u51fa: 9
    \n\n

    \u793a\u4f8b\u00a04:

    \n\n
    \n\u8f93\u5165:\u00a0\"LVIII\"\n\u8f93\u51fa: 58\n\u89e3\u91ca: L = 50, V= 5, III = 3.\n
    \n\n

    \u793a\u4f8b\u00a05:

    \n\n
    \n\u8f93\u5165:\u00a0\"MCMXCIV\"\n\u8f93\u51fa: 1994\n\u89e3\u91ca: M = 1000, CM = 900, XC = 90, IV = 4.
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 15
    • \n\t
    • s \u4ec5\u542b\u5b57\u7b26 ('I', 'V', 'X', 'L', 'C', 'D', 'M')
    • \n\t
    • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1 s \u662f\u4e00\u4e2a\u6709\u6548\u7684\u7f57\u9a6c\u6570\u5b57\uff0c\u4e14\u8868\u793a\u6574\u6570\u5728\u8303\u56f4 [1, 3999] \u5185
    • \n\t
    • \u9898\u76ee\u6240\u7ed9\u6d4b\u8bd5\u7528\u4f8b\u7686\u7b26\u5408\u7f57\u9a6c\u6570\u5b57\u4e66\u5199\u89c4\u5219\uff0c\u4e0d\u4f1a\u51fa\u73b0\u8de8\u4f4d\u7b49\u60c5\u51b5\u3002
    • \n\t
    • IL \u548c IM \u8fd9\u6837\u7684\u4f8b\u5b50\u5e76\u4e0d\u7b26\u5408\u9898\u76ee\u8981\u6c42\uff0c49 \u5e94\u8be5\u5199\u4f5c XLIX\uff0c999 \u5e94\u8be5\u5199\u4f5c CMXCIX \u3002
    • \n\t
    • \u5173\u4e8e\u7f57\u9a6c\u6570\u5b57\u7684\u8be6\u5c3d\u4e66\u5199\u89c4\u5219\uff0c\u53ef\u4ee5\u53c2\u8003 \u7f57\u9a6c\u6570\u5b57 - Mathematics \u3002
    • \n
    \n", "tags_en": ["Math", "String"], "tags_cn": ["\u6570\u5b66", "\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int romanToInt(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int romanToInt(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def romanToInt(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def romanToInt(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint romanToInt(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int RomanToInt(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar romanToInt = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef roman_to_int(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func romanToInt(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func romanToInt(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def romanToInt(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun romanToInt(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn roman_to_int(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function romanToInt($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function romanToInt(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (roman-to-int s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0013](https://leetcode-cn.com/problems/roman-to-integer)", "[\u7f57\u9a6c\u6570\u5b57\u8f6c\u6574\u6570](/solution/0000-0099/0013.Roman%20to%20Integer/README.md)", "`\u6570\u5b66`,`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0013](https://leetcode.com/problems/roman-to-integer)", "[Roman to Integer](/solution/0000-0099/0013.Roman%20to%20Integer/README_EN.md)", "`Math`,`String`", "Easy", ""]}, {"question_id": "0012", "frontend_question_id": "0012", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/integer-to-roman", "url_en": "https://leetcode.com/problems/integer-to-roman", "relative_path_cn": "/solution/0000-0099/0012.Integer%20to%20Roman/README.md", "relative_path_en": "/solution/0000-0099/0012.Integer%20to%20Roman/README_EN.md", "title_cn": "\u6574\u6570\u8f6c\u7f57\u9a6c\u6570\u5b57", "title_en": "Integer to Roman", "question_title_slug": "integer-to-roman", "content_en": "

    Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.

    \n\n
    \nSymbol       Value\nI             1\nV             5\nX             10\nL             50\nC             100\nD             500\nM             1000
    \n\n

    For example, 2 is written as II in Roman numeral, just two one's added together. 12 is written as XII, which is simply X + II. The number 27 is written as XXVII, which is XX + V + II.

    \n\n

    Roman numerals are usually written largest to smallest from left to right. However, the numeral for four is not IIII. Instead, the number four is written as IV. Because the one is before the five we subtract it making four. The same principle applies to the number nine, which is written as IX. There are six instances where subtraction is used:

    \n\n
      \n\t
    • I can be placed before V (5) and X (10) to make 4 and 9. 
    • \n\t
    • X can be placed before L (50) and C (100) to make 40 and 90. 
    • \n\t
    • C can be placed before D (500) and M (1000) to make 400 and 900.
    • \n
    \n\n

    Given an integer, convert it to a roman numeral.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: num = 3\nOutput: "III"\n
    \n\n

    Example 2:

    \n\n
    \nInput: num = 4\nOutput: "IV"\n
    \n\n

    Example 3:

    \n\n
    \nInput: num = 9\nOutput: "IX"\n
    \n\n

    Example 4:

    \n\n
    \nInput: num = 58\nOutput: "LVIII"\nExplanation: L = 50, V = 5, III = 3.\n
    \n\n

    Example 5:

    \n\n
    \nInput: num = 1994\nOutput: "MCMXCIV"\nExplanation: M = 1000, CM = 900, XC = 90 and IV = 4.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= num <= 3999
    • \n
    \n", "content_cn": "

    \u7f57\u9a6c\u6570\u5b57\u5305\u542b\u4ee5\u4e0b\u4e03\u79cd\u5b57\u7b26\uff1a\u00a0I\uff0c\u00a0V\uff0c\u00a0X\uff0c\u00a0L\uff0cC\uff0cD\u00a0\u548c\u00a0M\u3002

    \n\n
    \n\u5b57\u7b26          \u6570\u503c\nI             1\nV             5\nX             10\nL             50\nC             100\nD             500\nM             1000
    \n\n

    \u4f8b\u5982\uff0c \u7f57\u9a6c\u6570\u5b57 2 \u5199\u505a\u00a0II\u00a0\uff0c\u5373\u4e3a\u4e24\u4e2a\u5e76\u5217\u7684 1\u300212 \u5199\u505a\u00a0XII\u00a0\uff0c\u5373\u4e3a\u00a0X\u00a0+\u00a0II\u00a0\u3002 27 \u5199\u505a\u00a0\u00a0XXVII, \u5373\u4e3a\u00a0XX\u00a0+\u00a0V\u00a0+\u00a0II\u00a0\u3002

    \n\n

    \u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u7f57\u9a6c\u6570\u5b57\u4e2d\u5c0f\u7684\u6570\u5b57\u5728\u5927\u7684\u6570\u5b57\u7684\u53f3\u8fb9\u3002\u4f46\u4e5f\u5b58\u5728\u7279\u4f8b\uff0c\u4f8b\u5982 4 \u4e0d\u5199\u505a\u00a0IIII\uff0c\u800c\u662f\u00a0IV\u3002\u6570\u5b57 1 \u5728\u6570\u5b57 5 \u7684\u5de6\u8fb9\uff0c\u6240\u8868\u793a\u7684\u6570\u7b49\u4e8e\u5927\u6570 5 \u51cf\u5c0f\u6570 1 \u5f97\u5230\u7684\u6570\u503c 4 \u3002\u540c\u6837\u5730\uff0c\u6570\u5b57 9 \u8868\u793a\u4e3a\u00a0IX\u3002\u8fd9\u4e2a\u7279\u6b8a\u7684\u89c4\u5219\u53ea\u9002\u7528\u4e8e\u4ee5\u4e0b\u516d\u79cd\u60c5\u51b5\uff1a

    \n\n
      \n\t
    • I\u00a0\u53ef\u4ee5\u653e\u5728\u00a0V\u00a0(5) \u548c\u00a0X\u00a0(10) \u7684\u5de6\u8fb9\uff0c\u6765\u8868\u793a 4 \u548c 9\u3002
    • \n\t
    • X\u00a0\u53ef\u4ee5\u653e\u5728\u00a0L\u00a0(50) \u548c\u00a0C\u00a0(100) \u7684\u5de6\u8fb9\uff0c\u6765\u8868\u793a 40 \u548c\u00a090\u3002\u00a0
    • \n\t
    • C\u00a0\u53ef\u4ee5\u653e\u5728\u00a0D\u00a0(500) \u548c\u00a0M\u00a0(1000) \u7684\u5de6\u8fb9\uff0c\u6765\u8868\u793a\u00a0400 \u548c\u00a0900\u3002
    • \n
    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\uff0c\u5c06\u5176\u8f6c\u4e3a\u7f57\u9a6c\u6570\u5b57\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\u00a01:

    \n\n
    \n\u8f93\u5165:\u00a0num = 3\n\u8f93\u51fa: \"III\"
    \n\n

    \u793a\u4f8b\u00a02:

    \n\n
    \n\u8f93\u5165:\u00a0num = 4\n\u8f93\u51fa: \"IV\"
    \n\n

    \u793a\u4f8b\u00a03:

    \n\n
    \n\u8f93\u5165:\u00a0num = 9\n\u8f93\u51fa: \"IX\"
    \n\n

    \u793a\u4f8b\u00a04:

    \n\n
    \n\u8f93\u5165:\u00a0num = 58\n\u8f93\u51fa: \"LVIII\"\n\u89e3\u91ca: L = 50, V = 5, III = 3.\n
    \n\n

    \u793a\u4f8b\u00a05:

    \n\n
    \n\u8f93\u5165:\u00a0num = 1994\n\u8f93\u51fa: \"MCMXCIV\"\n\u89e3\u91ca: M = 1000, CM = 900, XC = 90, IV = 4.
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= num <= 3999
    • \n
    \n", "tags_en": ["Math", "String"], "tags_cn": ["\u6570\u5b66", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string intToRoman(int num) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String intToRoman(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def intToRoman(self, num):\n \"\"\"\n :type num: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def intToRoman(self, num: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * intToRoman(int num){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string IntToRoman(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} num\n * @return {string}\n */\nvar intToRoman = function(num) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} num\n# @return {String}\ndef int_to_roman(num)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func intToRoman(_ num: Int) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func intToRoman(num int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def intToRoman(num: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun intToRoman(num: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn int_to_roman(num: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $num\n * @return String\n */\n function intToRoman($num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function intToRoman(num: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (int-to-roman num)\n (-> exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0012](https://leetcode-cn.com/problems/integer-to-roman)", "[\u6574\u6570\u8f6c\u7f57\u9a6c\u6570\u5b57](/solution/0000-0099/0012.Integer%20to%20Roman/README.md)", "`\u6570\u5b66`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0012](https://leetcode.com/problems/integer-to-roman)", "[Integer to Roman](/solution/0000-0099/0012.Integer%20to%20Roman/README_EN.md)", "`Math`,`String`", "Medium", ""]}, {"question_id": "0011", "frontend_question_id": "0011", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/container-with-most-water", "url_en": "https://leetcode.com/problems/container-with-most-water", "relative_path_cn": "/solution/0000-0099/0011.Container%20With%20Most%20Water/README.md", "relative_path_en": "/solution/0000-0099/0011.Container%20With%20Most%20Water/README_EN.md", "title_cn": "\u76db\u6700\u591a\u6c34\u7684\u5bb9\u5668", "title_en": "Container With Most Water", "question_title_slug": "container-with-most-water", "content_en": "

    Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of the line i is at (i, ai) and (i, 0). Find two lines, which, together with the x-axis forms a container, such that the container contains the most water.

    \n\n

    Notice that you may not slant the container.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: height = [1,8,6,2,5,4,8,3,7]\nOutput: 49\nExplanation: The above vertical lines are represented by array [1,8,6,2,5,4,8,3,7]. In this case, the max area of water (blue section) the container can contain is 49.\n
    \n\n

    Example 2:

    \n\n
    \nInput: height = [1,1]\nOutput: 1\n
    \n\n

    Example 3:

    \n\n
    \nInput: height = [4,3,2,1,4]\nOutput: 16\n
    \n\n

    Example 4:

    \n\n
    \nInput: height = [1,2,1]\nOutput: 2\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == height.length
    • \n\t
    • 2 <= n <= 105
    • \n\t
    • 0 <= height[i] <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60 n \u4e2a\u975e\u8d1f\u6574\u6570 a1\uff0ca2\uff0c...\uff0can\uff0c\u6bcf\u4e2a\u6570\u4ee3\u8868\u5750\u6807\u4e2d\u7684\u4e00\u4e2a\u70b9\u00a0(i,\u00a0ai) \u3002\u5728\u5750\u6807\u5185\u753b n \u6761\u5782\u76f4\u7ebf\uff0c\u5782\u76f4\u7ebf i\u00a0\u7684\u4e24\u4e2a\u7aef\u70b9\u5206\u522b\u4e3a\u00a0(i,\u00a0ai) \u548c (i, 0) \u3002\u627e\u51fa\u5176\u4e2d\u7684\u4e24\u6761\u7ebf\uff0c\u4f7f\u5f97\u5b83\u4eec\u4e0e\u00a0x\u00a0\u8f74\u5171\u540c\u6784\u6210\u7684\u5bb9\u5668\u53ef\u4ee5\u5bb9\u7eb3\u6700\u591a\u7684\u6c34\u3002

    \n\n

    \u8bf4\u660e\uff1a\u4f60\u4e0d\u80fd\u503e\u659c\u5bb9\u5668\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1a[1,8,6,2,5,4,8,3,7]\n\u8f93\u51fa\uff1a49 \n\u89e3\u91ca\uff1a\u56fe\u4e2d\u5782\u76f4\u7ebf\u4ee3\u8868\u8f93\u5165\u6570\u7ec4 [1,8,6,2,5,4,8,3,7]\u3002\u5728\u6b64\u60c5\u51b5\u4e0b\uff0c\u5bb9\u5668\u80fd\u591f\u5bb9\u7eb3\u6c34\uff08\u8868\u793a\u4e3a\u84dd\u8272\u90e8\u5206\uff09\u7684\u6700\u5927\u503c\u4e3a\u00a049\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aheight = [1,1]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aheight = [4,3,2,1,4]\n\u8f93\u51fa\uff1a16\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1aheight = [1,2,1]\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n = height.length
    • \n\t
    • 2 <= n <= 3 * 104
    • \n\t
    • 0 <= height[i] <= 3 * 104
    • \n
    \n", "tags_en": ["Array", "Two Pointers"], "tags_cn": ["\u6570\u7ec4", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxArea(vector& height) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxArea(int[] height) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxArea(self, height):\n \"\"\"\n :type height: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxArea(self, height: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxArea(int* height, int heightSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxArea(int[] height) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} height\n * @return {number}\n */\nvar maxArea = function(height) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} height\n# @return {Integer}\ndef max_area(height)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxArea(_ height: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxArea(height []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxArea(height: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxArea(height: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_area(height: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $height\n * @return Integer\n */\n function maxArea($height) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxArea(height: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-area height)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0011](https://leetcode-cn.com/problems/container-with-most-water)", "[\u76db\u6700\u591a\u6c34\u7684\u5bb9\u5668](/solution/0000-0099/0011.Container%20With%20Most%20Water/README.md)", "`\u6570\u7ec4`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0011](https://leetcode.com/problems/container-with-most-water)", "[Container With Most Water](/solution/0000-0099/0011.Container%20With%20Most%20Water/README_EN.md)", "`Array`,`Two Pointers`", "Medium", ""]}, {"question_id": "0010", "frontend_question_id": "0010", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/regular-expression-matching", "url_en": "https://leetcode.com/problems/regular-expression-matching", "relative_path_cn": "/solution/0000-0099/0010.Regular%20Expression%20Matching/README.md", "relative_path_en": "/solution/0000-0099/0010.Regular%20Expression%20Matching/README_EN.md", "title_cn": "\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d", "title_en": "Regular Expression Matching", "question_title_slug": "regular-expression-matching", "content_en": "

    Given an input string (s) and a pattern (p), implement regular expression matching with support for '.' and '*' where: 

    \n\n
      \n\t
    • '.' Matches any single character.\u200b\u200b\u200b\u200b
    • \n\t
    • '*' Matches zero or more of the preceding element.
    • \n
    \n\n

    The matching should cover the entire input string (not partial).

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "aa", p = "a"\nOutput: false\nExplanation: "a" does not match the entire string "aa".\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "aa", p = "a*"\nOutput: true\nExplanation: '*' means zero or more of the preceding element, 'a'. Therefore, by repeating 'a' once, it becomes "aa".\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "ab", p = ".*"\nOutput: true\nExplanation: ".*" means "zero or more (*) of any character (.)".\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "aab", p = "c*a*b"\nOutput: true\nExplanation: c can be repeated 0 times, a can be repeated 1 time. Therefore, it matches "aab".\n
    \n\n

    Example 5:

    \n\n
    \nInput: s = "mississippi", p = "mis*is*p*."\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= s.length <= 20
    • \n\t
    • 0 <= p.length <= 30
    • \n\t
    • s contains only lowercase English letters.
    • \n\t
    • p contains only lowercase English letters, '.', and '*'.
    • \n\t
    • It is guaranteed for each appearance of the character '*', there will be a previous valid character to match.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32\u00a0s\u00a0\u548c\u4e00\u4e2a\u5b57\u7b26\u89c4\u5f8b\u00a0p\uff0c\u8bf7\u4f60\u6765\u5b9e\u73b0\u4e00\u4e2a\u652f\u6301 '.'\u00a0\u548c\u00a0'*'\u00a0\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d\u3002

    \n\n
      \n\t
    • '.' \u5339\u914d\u4efb\u610f\u5355\u4e2a\u5b57\u7b26
    • \n\t
    • '*' \u5339\u914d\u96f6\u4e2a\u6216\u591a\u4e2a\u524d\u9762\u7684\u90a3\u4e00\u4e2a\u5143\u7d20
    • \n
    \n\n

    \u6240\u8c13\u5339\u914d\uff0c\u662f\u8981\u6db5\u76d6\u00a0\u6574\u4e2a\u00a0\u5b57\u7b26\u4e32\u00a0s\u7684\uff0c\u800c\u4e0d\u662f\u90e8\u5206\u5b57\u7b26\u4e32\u3002

    \n\u00a0\n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"aa\" p = \"a\"\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\"a\" \u65e0\u6cd5\u5339\u914d \"aa\" \u6574\u4e2a\u5b57\u7b26\u4e32\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165\uff1as = \"aa\" p = \"a*\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u56e0\u4e3a '*' \u4ee3\u8868\u53ef\u4ee5\u5339\u914d\u96f6\u4e2a\u6216\u591a\u4e2a\u524d\u9762\u7684\u90a3\u4e00\u4e2a\u5143\u7d20, \u5728\u8fd9\u91cc\u524d\u9762\u7684\u5143\u7d20\u5c31\u662f 'a'\u3002\u56e0\u6b64\uff0c\u5b57\u7b26\u4e32 \"aa\" \u53ef\u88ab\u89c6\u4e3a 'a' \u91cd\u590d\u4e86\u4e00\u6b21\u3002\n
    \n\n

    \u793a\u4f8b\u00a03\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"ab\" p = \".*\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\".*\" \u8868\u793a\u53ef\u5339\u914d\u96f6\u4e2a\u6216\u591a\u4e2a\uff08'*'\uff09\u4efb\u610f\u5b57\u7b26\uff08'.'\uff09\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"aab\" p = \"c*a*b\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u56e0\u4e3a '*' \u8868\u793a\u96f6\u4e2a\u6216\u591a\u4e2a\uff0c\u8fd9\u91cc 'c' \u4e3a 0 \u4e2a, 'a' \u88ab\u91cd\u590d\u4e00\u6b21\u3002\u56e0\u6b64\u53ef\u4ee5\u5339\u914d\u5b57\u7b26\u4e32 \"aab\"\u3002\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"mississippi\" p = \"mis*is*p*.\"\n\u8f93\u51fa\uff1afalse
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= s.length\u00a0<= 20
    • \n\t
    • 0 <= p.length\u00a0<= 30
    • \n\t
    • s\u00a0\u53ef\u80fd\u4e3a\u7a7a\uff0c\u4e14\u53ea\u5305\u542b\u4ece\u00a0a-z\u00a0\u7684\u5c0f\u5199\u5b57\u6bcd\u3002
    • \n\t
    • p\u00a0\u53ef\u80fd\u4e3a\u7a7a\uff0c\u4e14\u53ea\u5305\u542b\u4ece\u00a0a-z\u00a0\u7684\u5c0f\u5199\u5b57\u6bcd\uff0c\u4ee5\u53ca\u5b57\u7b26\u00a0.\u00a0\u548c\u00a0*\u3002
    • \n\t
    • \u4fdd\u8bc1\u6bcf\u6b21\u51fa\u73b0\u5b57\u7b26\u00a0* \u65f6\uff0c\u524d\u9762\u90fd\u5339\u914d\u5230\u6709\u6548\u7684\u5b57\u7b26
    • \n
    \n", "tags_en": ["String", "Dynamic Programming", "Backtracking"], "tags_cn": ["\u5b57\u7b26\u4e32", "\u52a8\u6001\u89c4\u5212", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isMatch(string s, string p) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isMatch(String s, String p) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isMatch(self, s, p):\n \"\"\"\n :type s: str\n :type p: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isMatch(self, s: str, p: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isMatch(char * s, char * p){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsMatch(string s, string p) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string} p\n * @return {boolean}\n */\nvar isMatch = function(s, p) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String} p\n# @return {Boolean}\ndef is_match(s, p)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isMatch(_ s: String, _ p: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isMatch(s string, p string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isMatch(s: String, p: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isMatch(s: String, p: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_match(s: String, p: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String $p\n * @return Boolean\n */\n function isMatch($s, $p) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isMatch(s: string, p: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-match s p)\n (-> string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0010](https://leetcode-cn.com/problems/regular-expression-matching)", "[\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d](/solution/0000-0099/0010.Regular%20Expression%20Matching/README.md)", "`\u5b57\u7b26\u4e32`,`\u52a8\u6001\u89c4\u5212`,`\u56de\u6eaf\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[0010](https://leetcode.com/problems/regular-expression-matching)", "[Regular Expression Matching](/solution/0000-0099/0010.Regular%20Expression%20Matching/README_EN.md)", "`String`,`Dynamic Programming`,`Backtracking`", "Hard", ""]}, {"question_id": "0009", "frontend_question_id": "0009", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/palindrome-number", "url_en": "https://leetcode.com/problems/palindrome-number", "relative_path_cn": "/solution/0000-0099/0009.Palindrome%20Number/README.md", "relative_path_en": "/solution/0000-0099/0009.Palindrome%20Number/README_EN.md", "title_cn": "\u56de\u6587\u6570", "title_en": "Palindrome Number", "question_title_slug": "palindrome-number", "content_en": "

    Given an integer x, return true if x is palindrome integer.

    \n\n

    An integer is a palindrome when it reads the same backward as forward. For example, 121 is palindrome while 123 is not.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: x = 121\nOutput: true\n
    \n\n

    Example 2:

    \n\n
    \nInput: x = -121\nOutput: false\nExplanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.\n
    \n\n

    Example 3:

    \n\n
    \nInput: x = 10\nOutput: false\nExplanation: Reads 01 from right to left. Therefore it is not a palindrome.\n
    \n\n

    Example 4:

    \n\n
    \nInput: x = -101\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • -231 <= x <= 231 - 1
    • \n
    \n\n

     

    \nFollow up: Could you solve it without converting the integer to a string?", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 x \uff0c\u5982\u679c x \u662f\u4e00\u4e2a\u56de\u6587\u6574\u6570\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n

    \u56de\u6587\u6570\u662f\u6307\u6b63\u5e8f\uff08\u4ece\u5de6\u5411\u53f3\uff09\u548c\u5012\u5e8f\uff08\u4ece\u53f3\u5411\u5de6\uff09\u8bfb\u90fd\u662f\u4e00\u6837\u7684\u6574\u6570\u3002\u4f8b\u5982\uff0c121 \u662f\u56de\u6587\uff0c\u800c 123 \u4e0d\u662f\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1ax = 121\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b\u00a02\uff1a

    \n\n
    \n\u8f93\u5165\uff1ax = -121\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u4ece\u5de6\u5411\u53f3\u8bfb, \u4e3a -121 \u3002 \u4ece\u53f3\u5411\u5de6\u8bfb, \u4e3a 121- \u3002\u56e0\u6b64\u5b83\u4e0d\u662f\u4e00\u4e2a\u56de\u6587\u6570\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1ax = 10\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u4ece\u53f3\u5411\u5de6\u8bfb, \u4e3a 01 \u3002\u56e0\u6b64\u5b83\u4e0d\u662f\u4e00\u4e2a\u56de\u6587\u6570\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1ax = -101\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • -231\u00a0<= x <= 231\u00a0- 1
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u80fd\u4e0d\u5c06\u6574\u6570\u8f6c\u4e3a\u5b57\u7b26\u4e32\u6765\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u5417\uff1f

    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isPalindrome(int x) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isPalindrome(int x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isPalindrome(self, x):\n \"\"\"\n :type x: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isPalindrome(self, x: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isPalindrome(int x){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsPalindrome(int x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} x\n * @return {boolean}\n */\nvar isPalindrome = function(x) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} x\n# @return {Boolean}\ndef is_palindrome(x)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isPalindrome(_ x: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isPalindrome(x int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isPalindrome(x: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isPalindrome(x: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_palindrome(x: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $x\n * @return Boolean\n */\n function isPalindrome($x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isPalindrome(x: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-palindrome x)\n (-> exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0009](https://leetcode-cn.com/problems/palindrome-number)", "[\u56de\u6587\u6570](/solution/0000-0099/0009.Palindrome%20Number/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0009](https://leetcode.com/problems/palindrome-number)", "[Palindrome Number](/solution/0000-0099/0009.Palindrome%20Number/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "0008", "frontend_question_id": "0008", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/string-to-integer-atoi", "url_en": "https://leetcode.com/problems/string-to-integer-atoi", "relative_path_cn": "/solution/0000-0099/0008.String%20to%20Integer%20%28atoi%29/README.md", "relative_path_en": "/solution/0000-0099/0008.String%20to%20Integer%20%28atoi%29/README_EN.md", "title_cn": "\u5b57\u7b26\u4e32\u8f6c\u6362\u6574\u6570 (atoi)", "title_en": "String to Integer (atoi)", "question_title_slug": "string-to-integer-atoi", "content_en": "

    Implement the myAtoi(string s) function, which converts a string to a 32-bit signed integer (similar to C/C++'s atoi function).

    \n\n

    The algorithm for myAtoi(string s) is as follows:

    \n\n
      \n\t
    1. Read in and ignore any leading whitespace.
    2. \n\t
    3. Check if the next character (if not already at the end of the string) is '-' or '+'. Read this character in if it is either. This determines if the final result is negative or positive respectively. Assume the result is positive if neither is present.
    4. \n\t
    5. Read in next the characters until the next non-digit charcter or the end of the input is reached. The rest of the string is ignored.
    6. \n\t
    7. Convert these digits into an integer (i.e. "123" -> 123, "0032" -> 32). If no digits were read, then the integer is 0. Change the sign as necessary (from step 2).
    8. \n\t
    9. If the integer is out of the 32-bit signed integer range [-231, 231 - 1], then clamp the integer so that it remains in the range. Specifically, integers less than -231 should be clamped to -231, and integers greater than 231 - 1 should be clamped to 231 - 1.
    10. \n\t
    11. Return the integer as the final result.
    12. \n
    \n\n

    Note:

    \n\n
      \n\t
    • Only the space character ' ' is considered a whitespace character.
    • \n\t
    • Do not ignore any characters other than the leading whitespace or the rest of the string after the digits.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "42"\nOutput: 42\nExplanation: The underlined characters are what is read in, the caret is the current reader position.\nStep 1: "42" (no characters read because there is no leading whitespace)\n         ^\nStep 2: "42" (no characters read because there is neither a '-' nor '+')\n         ^\nStep 3: "42" ("42" is read in)\n           ^\nThe parsed integer is 42.\nSince 42 is in the range [-231, 231 - 1], the final result is 42.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "   -42"\nOutput: -42\nExplanation:\nStep 1: "   -42" (leading whitespace is read and ignored)\n            ^\nStep 2: "   -42" ('-' is read, so the result should be negative)\n             ^\nStep 3: "   -42" ("42" is read in)\n               ^\nThe parsed integer is -42.\nSince -42 is in the range [-231, 231 - 1], the final result is -42.\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "4193 with words"\nOutput: 4193\nExplanation:\nStep 1: "4193 with words" (no characters read because there is no leading whitespace)\n         ^\nStep 2: "4193 with words" (no characters read because there is neither a '-' nor '+')\n         ^\nStep 3: "4193 with words" ("4193" is read in; reading stops because the next character is a non-digit)\n             ^\nThe parsed integer is 4193.\nSince 4193 is in the range [-231, 231 - 1], the final result is 4193.\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "words and 987"\nOutput: 0\nExplanation:\nStep 1: "words and 987" (no characters read because there is no leading whitespace)\n         ^\nStep 2: "words and 987" (no characters read because there is neither a '-' nor '+')\n         ^\nStep 3: "words and 987" (reading stops immediately because there is a non-digit 'w')\n         ^\nThe parsed integer is 0 because no digits were read.\nSince 0 is in the range [-231, 231 - 1], the final result is 0.\n
    \n\n

    Example 5:

    \n\n
    \nInput: s = "-91283472332"\nOutput: -2147483648\nExplanation:\nStep 1: "-91283472332" (no characters read because there is no leading whitespace)\n         ^\nStep 2: "-91283472332" ('-' is read, so the result should be negative)\n          ^\nStep 3: "-91283472332" ("91283472332" is read in)\n                     ^\nThe parsed integer is -91283472332.\nSince -91283472332 is less than the lower bound of the range [-231, 231 - 1], the final result is clamped to -231 = -2147483648. \n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= s.length <= 200
    • \n\t
    • s consists of English letters (lower-case and upper-case), digits (0-9), ' ', '+', '-', and '.'.
    • \n
    \n", "content_cn": "

    \u8bf7\u4f60\u6765\u5b9e\u73b0\u4e00\u4e2a\u00a0myAtoi(string s)\u00a0\u51fd\u6570\uff0c\u4f7f\u5176\u80fd\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u6210\u4e00\u4e2a 32 \u4f4d\u6709\u7b26\u53f7\u6574\u6570\uff08\u7c7b\u4f3c C/C++ \u4e2d\u7684 atoi \u51fd\u6570\uff09\u3002

    \n\n

    \u51fd\u6570\u00a0myAtoi(string s) \u7684\u7b97\u6cd5\u5982\u4e0b\uff1a

    \n\n
      \n\t
    • \u8bfb\u5165\u5b57\u7b26\u4e32\u5e76\u4e22\u5f03\u65e0\u7528\u7684\u524d\u5bfc\u7a7a\u683c
    • \n\t
    • \u68c0\u67e5\u4e0b\u4e00\u4e2a\u5b57\u7b26\uff08\u5047\u8bbe\u8fd8\u672a\u5230\u5b57\u7b26\u672b\u5c3e\uff09\u4e3a\u6b63\u8fd8\u662f\u8d1f\u53f7\uff0c\u8bfb\u53d6\u8be5\u5b57\u7b26\uff08\u5982\u679c\u6709\uff09\u3002 \u786e\u5b9a\u6700\u7ec8\u7ed3\u679c\u662f\u8d1f\u6570\u8fd8\u662f\u6b63\u6570\u3002 \u5982\u679c\u4e24\u8005\u90fd\u4e0d\u5b58\u5728\uff0c\u5219\u5047\u5b9a\u7ed3\u679c\u4e3a\u6b63\u3002
    • \n\t
    • \u8bfb\u5165\u4e0b\u4e00\u4e2a\u5b57\u7b26\uff0c\u76f4\u5230\u5230\u8fbe\u4e0b\u4e00\u4e2a\u975e\u6570\u5b57\u5b57\u7b26\u6216\u5230\u8fbe\u8f93\u5165\u7684\u7ed3\u5c3e\u3002\u5b57\u7b26\u4e32\u7684\u5176\u4f59\u90e8\u5206\u5c06\u88ab\u5ffd\u7565\u3002
    • \n\t
    • \u5c06\u524d\u9762\u6b65\u9aa4\u8bfb\u5165\u7684\u8fd9\u4e9b\u6570\u5b57\u8f6c\u6362\u4e3a\u6574\u6570\uff08\u5373\uff0c\"123\" -> 123\uff0c \"0032\" -> 32\uff09\u3002\u5982\u679c\u6ca1\u6709\u8bfb\u5165\u6570\u5b57\uff0c\u5219\u6574\u6570\u4e3a 0 \u3002\u5fc5\u8981\u65f6\u66f4\u6539\u7b26\u53f7\uff08\u4ece\u6b65\u9aa4 2 \u5f00\u59cb\uff09\u3002
    • \n\t
    • \u5982\u679c\u6574\u6570\u6570\u8d85\u8fc7 32 \u4f4d\u6709\u7b26\u53f7\u6574\u6570\u8303\u56f4 [\u2212231,\u00a0 231\u00a0\u2212 1] \uff0c\u9700\u8981\u622a\u65ad\u8fd9\u4e2a\u6574\u6570\uff0c\u4f7f\u5176\u4fdd\u6301\u5728\u8fd9\u4e2a\u8303\u56f4\u5185\u3002\u5177\u4f53\u6765\u8bf4\uff0c\u5c0f\u4e8e \u2212231 \u7684\u6574\u6570\u5e94\u8be5\u88ab\u56fa\u5b9a\u4e3a \u2212231 \uff0c\u5927\u4e8e 231\u00a0\u2212 1 \u7684\u6574\u6570\u5e94\u8be5\u88ab\u56fa\u5b9a\u4e3a 231\u00a0\u2212 1 \u3002
    • \n\t
    • \u8fd4\u56de\u6574\u6570\u4f5c\u4e3a\u6700\u7ec8\u7ed3\u679c\u3002
    • \n
    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    • \u672c\u9898\u4e2d\u7684\u7a7a\u767d\u5b57\u7b26\u53ea\u5305\u62ec\u7a7a\u683c\u5b57\u7b26 ' ' \u3002
    • \n\t
    • \u9664\u524d\u5bfc\u7a7a\u683c\u6216\u6570\u5b57\u540e\u7684\u5176\u4f59\u5b57\u7b26\u4e32\u5916\uff0c\u8bf7\u52ff\u5ffd\u7565 \u4efb\u4f55\u5176\u4ed6\u5b57\u7b26\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\u00a01\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"42\"\n\u8f93\u51fa\uff1a42\n\u89e3\u91ca\uff1a\u52a0\u7c97\u7684\u5b57\u7b26\u4e32\u4e3a\u5df2\u7ecf\u8bfb\u5165\u7684\u5b57\u7b26\uff0c\u63d2\u5165\u7b26\u53f7\u662f\u5f53\u524d\u8bfb\u53d6\u7684\u5b57\u7b26\u3002\n\u7b2c 1 \u6b65\uff1a\"42\"\uff08\u5f53\u524d\u6ca1\u6709\u8bfb\u5165\u5b57\u7b26\uff0c\u56e0\u4e3a\u6ca1\u6709\u524d\u5bfc\u7a7a\u683c\uff09\n         ^\n\u7b2c 2 \u6b65\uff1a\"42\"\uff08\u5f53\u524d\u6ca1\u6709\u8bfb\u5165\u5b57\u7b26\uff0c\u56e0\u4e3a\u8fd9\u91cc\u4e0d\u5b58\u5728 '-' \u6216\u8005 '+'\uff09\n         ^\n\u7b2c 3 \u6b65\uff1a\"42\"\uff08\u8bfb\u5165 \"42\"\uff09\n           ^\n\u89e3\u6790\u5f97\u5230\u6574\u6570 42 \u3002\n\u7531\u4e8e \"42\" \u5728\u8303\u56f4 [-231, 231 - 1] \u5185\uff0c\u6700\u7ec8\u7ed3\u679c\u4e3a 42 \u3002
    \n\n

    \u793a\u4f8b\u00a02\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"   -42\"\n\u8f93\u51fa\uff1a-42\n\u89e3\u91ca\uff1a\n\u7b2c 1 \u6b65\uff1a\"   -42\"\uff08\u8bfb\u5165\u524d\u5bfc\u7a7a\u683c\uff0c\u4f46\u5ffd\u89c6\u6389\uff09\n            ^\n\u7b2c 2 \u6b65\uff1a\"   -42\"\uff08\u8bfb\u5165 '-' \u5b57\u7b26\uff0c\u6240\u4ee5\u7ed3\u679c\u5e94\u8be5\u662f\u8d1f\u6570\uff09\n             ^\n\u7b2c 3 \u6b65\uff1a\"   -42\"\uff08\u8bfb\u5165 \"42\"\uff09\n               ^\n\u89e3\u6790\u5f97\u5230\u6574\u6570 -42 \u3002\n\u7531\u4e8e \"-42\" \u5728\u8303\u56f4 [-231, 231 - 1] \u5185\uff0c\u6700\u7ec8\u7ed3\u679c\u4e3a -42 \u3002\n
    \n\n

    \u793a\u4f8b\u00a03\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"4193 with words\"\n\u8f93\u51fa\uff1a4193\n\u89e3\u91ca\uff1a\n\u7b2c 1 \u6b65\uff1a\"4193 with words\"\uff08\u5f53\u524d\u6ca1\u6709\u8bfb\u5165\u5b57\u7b26\uff0c\u56e0\u4e3a\u6ca1\u6709\u524d\u5bfc\u7a7a\u683c\uff09\n         ^\n\u7b2c 2 \u6b65\uff1a\"4193 with words\"\uff08\u5f53\u524d\u6ca1\u6709\u8bfb\u5165\u5b57\u7b26\uff0c\u56e0\u4e3a\u8fd9\u91cc\u4e0d\u5b58\u5728 '-' \u6216\u8005 '+'\uff09\n         ^\n\u7b2c 3 \u6b65\uff1a\"4193 with words\"\uff08\u8bfb\u5165 \"4193\"\uff1b\u7531\u4e8e\u4e0b\u4e00\u4e2a\u5b57\u7b26\u4e0d\u662f\u4e00\u4e2a\u6570\u5b57\uff0c\u6240\u4ee5\u8bfb\u5165\u505c\u6b62\uff09\n             ^\n\u89e3\u6790\u5f97\u5230\u6574\u6570 4193 \u3002\n\u7531\u4e8e \"4193\" \u5728\u8303\u56f4 [-231, 231 - 1] \u5185\uff0c\u6700\u7ec8\u7ed3\u679c\u4e3a 4193 \u3002\n
    \n\n

    \u793a\u4f8b\u00a04\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"words and 987\"\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\n\u7b2c 1 \u6b65\uff1a\"words and 987\"\uff08\u5f53\u524d\u6ca1\u6709\u8bfb\u5165\u5b57\u7b26\uff0c\u56e0\u4e3a\u6ca1\u6709\u524d\u5bfc\u7a7a\u683c\uff09\n         ^\n\u7b2c 2 \u6b65\uff1a\"words and 987\"\uff08\u5f53\u524d\u6ca1\u6709\u8bfb\u5165\u5b57\u7b26\uff0c\u56e0\u4e3a\u8fd9\u91cc\u4e0d\u5b58\u5728 '-' \u6216\u8005 '+'\uff09\n         ^\n\u7b2c 3 \u6b65\uff1a\"words and 987\"\uff08\u7531\u4e8e\u5f53\u524d\u5b57\u7b26 'w' \u4e0d\u662f\u4e00\u4e2a\u6570\u5b57\uff0c\u6240\u4ee5\u8bfb\u5165\u505c\u6b62\uff09\n         ^\n\u89e3\u6790\u5f97\u5230\u6574\u6570 0 \uff0c\u56e0\u4e3a\u6ca1\u6709\u8bfb\u5165\u4efb\u4f55\u6570\u5b57\u3002\n\u7531\u4e8e 0 \u5728\u8303\u56f4 [-231, 231 - 1] \u5185\uff0c\u6700\u7ec8\u7ed3\u679c\u4e3a 0 \u3002
    \n\n

    \u793a\u4f8b\u00a05\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"-91283472332\"\n\u8f93\u51fa\uff1a-2147483648\n\u89e3\u91ca\uff1a\n\u7b2c 1 \u6b65\uff1a\"-91283472332\"\uff08\u5f53\u524d\u6ca1\u6709\u8bfb\u5165\u5b57\u7b26\uff0c\u56e0\u4e3a\u6ca1\u6709\u524d\u5bfc\u7a7a\u683c\uff09\n         ^\n\u7b2c 2 \u6b65\uff1a\"-91283472332\"\uff08\u8bfb\u5165 '-' \u5b57\u7b26\uff0c\u6240\u4ee5\u7ed3\u679c\u5e94\u8be5\u662f\u8d1f\u6570\uff09\n          ^\n\u7b2c 3 \u6b65\uff1a\"-91283472332\"\uff08\u8bfb\u5165 \"91283472332\"\uff09\n                     ^\n\u89e3\u6790\u5f97\u5230\u6574\u6570 -91283472332 \u3002\n\u7531\u4e8e -91283472332 \u5c0f\u4e8e\u8303\u56f4 [-231, 231 - 1] \u7684\u4e0b\u754c\uff0c\u6700\u7ec8\u7ed3\u679c\u88ab\u622a\u65ad\u4e3a -231 = -2147483648 \u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= s.length <= 200
    • \n\t
    • s \u7531\u82f1\u6587\u5b57\u6bcd\uff08\u5927\u5199\u548c\u5c0f\u5199\uff09\u3001\u6570\u5b57\uff080-9\uff09\u3001' '\u3001'+'\u3001'-' \u548c '.' \u7ec4\u6210
    • \n
    \n", "tags_en": ["Math", "String"], "tags_cn": ["\u6570\u5b66", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int myAtoi(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int myAtoi(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def myAtoi(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def myAtoi(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint myAtoi(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MyAtoi(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar myAtoi = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef my_atoi(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func myAtoi(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func myAtoi(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def myAtoi(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun myAtoi(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn my_atoi(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function myAtoi($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function myAtoi(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (my-atoi s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0008](https://leetcode-cn.com/problems/string-to-integer-atoi)", "[\u5b57\u7b26\u4e32\u8f6c\u6362\u6574\u6570 (atoi)](/solution/0000-0099/0008.String%20to%20Integer%20%28atoi%29/README.md)", "`\u6570\u5b66`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0008](https://leetcode.com/problems/string-to-integer-atoi)", "[String to Integer (atoi)](/solution/0000-0099/0008.String%20to%20Integer%20%28atoi%29/README_EN.md)", "`Math`,`String`", "Medium", ""]}, {"question_id": "0007", "frontend_question_id": "0007", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reverse-integer", "url_en": "https://leetcode.com/problems/reverse-integer", "relative_path_cn": "/solution/0000-0099/0007.Reverse%20Integer/README.md", "relative_path_en": "/solution/0000-0099/0007.Reverse%20Integer/README_EN.md", "title_cn": "\u6574\u6570\u53cd\u8f6c", "title_en": "Reverse Integer", "question_title_slug": "reverse-integer", "content_en": "

    Given a signed 32-bit integer x, return x with its digits reversed. If reversing x causes the value to go outside the signed 32-bit integer range [-231, 231 - 1], then return 0.

    \n\n

    Assume the environment does not allow you to store 64-bit integers (signed or unsigned).

    \n\n

     

    \n

    Example 1:

    \n
    Input: x = 123\nOutput: 321\n

    Example 2:

    \n
    Input: x = -123\nOutput: -321\n

    Example 3:

    \n
    Input: x = 120\nOutput: 21\n

    Example 4:

    \n
    Input: x = 0\nOutput: 0\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • -231 <= x <= 231 - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a 32 \u4f4d\u7684\u6709\u7b26\u53f7\u6574\u6570 x \uff0c\u8fd4\u56de\u5c06 x \u4e2d\u7684\u6570\u5b57\u90e8\u5206\u53cd\u8f6c\u540e\u7684\u7ed3\u679c\u3002

    \n\n

    \u5982\u679c\u53cd\u8f6c\u540e\u6574\u6570\u8d85\u8fc7 32 \u4f4d\u7684\u6709\u7b26\u53f7\u6574\u6570\u7684\u8303\u56f4\u00a0[\u2212231,\u00a0 231\u00a0\u2212 1] \uff0c\u5c31\u8fd4\u56de 0\u3002

    \n\u5047\u8bbe\u73af\u5883\u4e0d\u5141\u8bb8\u5b58\u50a8 64 \u4f4d\u6574\u6570\uff08\u6709\u7b26\u53f7\u6216\u65e0\u7b26\u53f7\uff09\u3002\n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1ax = 123\n\u8f93\u51fa\uff1a321\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1ax = -123\n\u8f93\u51fa\uff1a-321\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1ax = 120\n\u8f93\u51fa\uff1a21\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1ax = 0\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • -231 <= x <= 231 - 1
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int reverse(int x) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int reverse(int x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def reverse(self, x):\n \"\"\"\n :type x: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def reverse(self, x: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint reverse(int x){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int Reverse(int x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} x\n * @return {number}\n */\nvar reverse = function(x) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} x\n# @return {Integer}\ndef reverse(x)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func reverse(_ x: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func reverse(x int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def reverse(x: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun reverse(x: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn reverse(x: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $x\n * @return Integer\n */\n function reverse($x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function reverse(x: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (reverse x)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0007](https://leetcode-cn.com/problems/reverse-integer)", "[\u6574\u6570\u53cd\u8f6c](/solution/0000-0099/0007.Reverse%20Integer/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0007](https://leetcode.com/problems/reverse-integer)", "[Reverse Integer](/solution/0000-0099/0007.Reverse%20Integer/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "0006", "frontend_question_id": "0006", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/zigzag-conversion", "url_en": "https://leetcode.com/problems/zigzag-conversion", "relative_path_cn": "/solution/0000-0099/0006.ZigZag%20Conversion/README.md", "relative_path_en": "/solution/0000-0099/0006.ZigZag%20Conversion/README_EN.md", "title_cn": "Z \u5b57\u5f62\u53d8\u6362", "title_en": "ZigZag Conversion", "question_title_slug": "zigzag-conversion", "content_en": "

    The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)

    \n\n
    \nP   A   H   N\nA P L S I I G\nY   I   R\n
    \n\n

    And then read line by line: "PAHNAPLSIIGYIR"

    \n\n

    Write the code that will take a string and make this conversion given a number of rows:

    \n\n
    \nstring convert(string s, int numRows);\n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "PAYPALISHIRING", numRows = 3\nOutput: "PAHNAPLSIIGYIR"\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "PAYPALISHIRING", numRows = 4\nOutput: "PINALSIGYAHRPI"\nExplanation:\nP     I    N\nA   L S  I G\nY A   H R\nP     I\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "A", numRows = 1\nOutput: "A"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 1000
    • \n\t
    • s consists of English letters (lower-case and upper-case), ',' and '.'.
    • \n\t
    • 1 <= numRows <= 1000
    • \n
    \n", "content_cn": "

    \u5c06\u4e00\u4e2a\u7ed9\u5b9a\u5b57\u7b26\u4e32 s \u6839\u636e\u7ed9\u5b9a\u7684\u884c\u6570 numRows \uff0c\u4ee5\u4ece\u4e0a\u5f80\u4e0b\u3001\u4ece\u5de6\u5230\u53f3\u8fdb\u884c\u00a0Z \u5b57\u5f62\u6392\u5217\u3002

    \n\n

    \u6bd4\u5982\u8f93\u5165\u5b57\u7b26\u4e32\u4e3a \"PAYPALISHIRING\"\u00a0\u884c\u6570\u4e3a 3 \u65f6\uff0c\u6392\u5217\u5982\u4e0b\uff1a

    \n\n
    \nP   A   H   N\nA P L S I I G\nY   I   R
    \n\n

    \u4e4b\u540e\uff0c\u4f60\u7684\u8f93\u51fa\u9700\u8981\u4ece\u5de6\u5f80\u53f3\u9010\u884c\u8bfb\u53d6\uff0c\u4ea7\u751f\u51fa\u4e00\u4e2a\u65b0\u7684\u5b57\u7b26\u4e32\uff0c\u6bd4\u5982\uff1a\"PAHNAPLSIIGYIR\"\u3002

    \n\n

    \u8bf7\u4f60\u5b9e\u73b0\u8fd9\u4e2a\u5c06\u5b57\u7b26\u4e32\u8fdb\u884c\u6307\u5b9a\u884c\u6570\u53d8\u6362\u7684\u51fd\u6570\uff1a

    \n\n
    \nstring convert(string s, int numRows);
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"PAYPALISHIRING\", numRows = 3\n\u8f93\u51fa\uff1a\"PAHNAPLSIIGYIR\"\n
    \n\u793a\u4f8b 2\uff1a\n\n
    \n\u8f93\u5165\uff1as = \"PAYPALISHIRING\", numRows = 4\n\u8f93\u51fa\uff1a\"PINALSIGYAHRPI\"\n\u89e3\u91ca\uff1a\nP     I    N\nA   L S  I G\nY A   H R\nP     I\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"A\", numRows = 1\n\u8f93\u51fa\uff1a\"A\"\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 1000
    • \n\t
    • s \u7531\u82f1\u6587\u5b57\u6bcd\uff08\u5c0f\u5199\u548c\u5927\u5199\uff09\u3001',' \u548c '.' \u7ec4\u6210
    • \n\t
    • 1 <= numRows <= 1000
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String convert(String s, int numRows) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def convert(self, s, numRows):\n \"\"\"\n :type s: str\n :type numRows: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def convert(self, s: str, numRows: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * convert(char * s, int numRows){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string Convert(string s, int numRows) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number} numRows\n * @return {string}\n */\nvar convert = function(s, numRows) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer} num_rows\n# @return {String}\ndef convert(s, num_rows)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func convert(_ s: String, _ numRows: Int) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func convert(s string, numRows int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def convert(s: String, numRows: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun convert(s: String, numRows: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn convert(s: String, num_rows: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer $numRows\n * @return String\n */\n function convert($s, $numRows) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function convert(s: string, numRows: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (convert s numRows)\n (-> string? exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0006](https://leetcode-cn.com/problems/zigzag-conversion)", "[Z \u5b57\u5f62\u53d8\u6362](/solution/0000-0099/0006.ZigZag%20Conversion/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0006](https://leetcode.com/problems/zigzag-conversion)", "[ZigZag Conversion](/solution/0000-0099/0006.ZigZag%20Conversion/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "0005", "frontend_question_id": "0005", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-palindromic-substring", "url_en": "https://leetcode.com/problems/longest-palindromic-substring", "relative_path_cn": "/solution/0000-0099/0005.Longest%20Palindromic%20Substring/README.md", "relative_path_en": "/solution/0000-0099/0005.Longest%20Palindromic%20Substring/README_EN.md", "title_cn": "\u6700\u957f\u56de\u6587\u5b50\u4e32", "title_en": "Longest Palindromic Substring", "question_title_slug": "longest-palindromic-substring", "content_en": "

    Given a string s, return the longest palindromic substring in s.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "babad"\nOutput: "bab"\nNote: "aba" is also a valid answer.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "cbbd"\nOutput: "bb"\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "a"\nOutput: "a"\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "ac"\nOutput: "a"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 1000
    • \n\t
    • s consist of only digits and English letters (lower-case and/or upper-case),
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s\uff0c\u627e\u5230 s \u4e2d\u6700\u957f\u7684\u56de\u6587\u5b50\u4e32\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"babad\"\n\u8f93\u51fa\uff1a\"bab\"\n\u89e3\u91ca\uff1a\"aba\" \u540c\u6837\u662f\u7b26\u5408\u9898\u610f\u7684\u7b54\u6848\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"cbbd\"\n\u8f93\u51fa\uff1a\"bb\"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"a\"\n\u8f93\u51fa\uff1a\"a\"\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"ac\"\n\u8f93\u51fa\uff1a\"a\"\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 1000
    • \n\t
    • s \u4ec5\u7531\u6570\u5b57\u548c\u82f1\u6587\u5b57\u6bcd\uff08\u5927\u5199\u548c/\u6216\u5c0f\u5199\uff09\u7ec4\u6210
    • \n
    \n", "tags_en": ["String", "Dynamic Programming"], "tags_cn": ["\u5b57\u7b26\u4e32", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string longestPalindrome(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String longestPalindrome(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestPalindrome(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestPalindrome(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * longestPalindrome(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string LongestPalindrome(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar longestPalindrome = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef longest_palindrome(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestPalindrome(_ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestPalindrome(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestPalindrome(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestPalindrome(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_palindrome(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function longestPalindrome($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestPalindrome(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-palindrome s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0005](https://leetcode-cn.com/problems/longest-palindromic-substring)", "[\u6700\u957f\u56de\u6587\u5b50\u4e32](/solution/0000-0099/0005.Longest%20Palindromic%20Substring/README.md)", "`\u5b57\u7b26\u4e32`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0005](https://leetcode.com/problems/longest-palindromic-substring)", "[Longest Palindromic Substring](/solution/0000-0099/0005.Longest%20Palindromic%20Substring/README_EN.md)", "`String`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0004", "frontend_question_id": "0004", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/median-of-two-sorted-arrays", "url_en": "https://leetcode.com/problems/median-of-two-sorted-arrays", "relative_path_cn": "/solution/0000-0099/0004.Median%20of%20Two%20Sorted%20Arrays/README.md", "relative_path_en": "/solution/0000-0099/0004.Median%20of%20Two%20Sorted%20Arrays/README_EN.md", "title_cn": "\u5bfb\u627e\u4e24\u4e2a\u6b63\u5e8f\u6570\u7ec4\u7684\u4e2d\u4f4d\u6570", "title_en": "Median of Two Sorted Arrays", "question_title_slug": "median-of-two-sorted-arrays", "content_en": "

    Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays.

    \n\n

    The overall run time complexity should be O(log (m+n)).

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums1 = [1,3], nums2 = [2]\nOutput: 2.00000\nExplanation: merged array = [1,2,3] and median is 2.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums1 = [1,2], nums2 = [3,4]\nOutput: 2.50000\nExplanation: merged array = [1,2,3,4] and median is (2 + 3) / 2 = 2.5.\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums1 = [0,0], nums2 = [0,0]\nOutput: 0.00000\n
    \n\n

    Example 4:

    \n\n
    \nInput: nums1 = [], nums2 = [1]\nOutput: 1.00000\n
    \n\n

    Example 5:

    \n\n
    \nInput: nums1 = [2], nums2 = []\nOutput: 2.00000\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • nums1.length == m
    • \n\t
    • nums2.length == n
    • \n\t
    • 0 <= m <= 1000
    • \n\t
    • 0 <= n <= 1000
    • \n\t
    • 1 <= m + n <= 2000
    • \n\t
    • -106 <= nums1[i], nums2[i] <= 106
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u5927\u5c0f\u5206\u522b\u4e3a m \u548c n \u7684\u6b63\u5e8f\uff08\u4ece\u5c0f\u5230\u5927\uff09\u6570\u7ec4\u00a0nums1 \u548c\u00a0nums2\u3002\u8bf7\u4f60\u627e\u51fa\u5e76\u8fd4\u56de\u8fd9\u4e24\u4e2a\u6b63\u5e8f\u6570\u7ec4\u7684 \u4e2d\u4f4d\u6570 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums1 = [1,3], nums2 = [2]\n\u8f93\u51fa\uff1a2.00000\n\u89e3\u91ca\uff1a\u5408\u5e76\u6570\u7ec4 = [1,2,3] \uff0c\u4e2d\u4f4d\u6570 2\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums1 = [1,2], nums2 = [3,4]\n\u8f93\u51fa\uff1a2.50000\n\u89e3\u91ca\uff1a\u5408\u5e76\u6570\u7ec4 = [1,2,3,4] \uff0c\u4e2d\u4f4d\u6570 (2 + 3) / 2 = 2.5\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums1 = [0,0], nums2 = [0,0]\n\u8f93\u51fa\uff1a0.00000\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums1 = [], nums2 = [1]\n\u8f93\u51fa\uff1a1.00000\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums1 = [2], nums2 = []\n\u8f93\u51fa\uff1a2.00000\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • nums1.length == m
    • \n\t
    • nums2.length == n
    • \n\t
    • 0 <= m <= 1000
    • \n\t
    • 0 <= n <= 1000
    • \n\t
    • 1 <= m + n <= 2000
    • \n\t
    • -106 <= nums1[i], nums2[i] <= 106
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u80fd\u8bbe\u8ba1\u4e00\u4e2a\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(log (m+n)) \u7684\u7b97\u6cd5\u89e3\u51b3\u6b64\u95ee\u9898\u5417\uff1f

    \n", "tags_en": ["Array", "Binary Search", "Divide and Conquer"], "tags_cn": ["\u6570\u7ec4", "\u4e8c\u5206\u67e5\u627e", "\u5206\u6cbb\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n double findMedianSortedArrays(vector& nums1, vector& nums2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double findMedianSortedArrays(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findMedianSortedArrays(self, nums1, nums2):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n :rtype: float\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findMedianSortedArrays(self, nums1: List[int], nums2: List[int]) -> float:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\ndouble findMedianSortedArrays(int* nums1, int nums1Size, int* nums2, int nums2Size){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double FindMedianSortedArrays(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums1\n * @param {number[]} nums2\n * @return {number}\n */\nvar findMedianSortedArrays = function(nums1, nums2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums1\n# @param {Integer[]} nums2\n# @return {Float}\ndef find_median_sorted_arrays(nums1, nums2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findMedianSortedArrays(_ nums1: [Int], _ nums2: [Int]) -> Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findMedianSortedArrays(nums1 []int, nums2 []int) float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findMedianSortedArrays(nums1: Array[Int], nums2: Array[Int]): Double = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findMedianSortedArrays(nums1: IntArray, nums2: IntArray): Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_median_sorted_arrays(nums1: Vec, nums2: Vec) -> f64 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums1\n * @param Integer[] $nums2\n * @return Float\n */\n function findMedianSortedArrays($nums1, $nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findMedianSortedArrays(nums1: number[], nums2: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-median-sorted-arrays nums1 nums2)\n (-> (listof exact-integer?) (listof exact-integer?) flonum?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0004](https://leetcode-cn.com/problems/median-of-two-sorted-arrays)", "[\u5bfb\u627e\u4e24\u4e2a\u6b63\u5e8f\u6570\u7ec4\u7684\u4e2d\u4f4d\u6570](/solution/0000-0099/0004.Median%20of%20Two%20Sorted%20Arrays/README.md)", "`\u6570\u7ec4`,`\u4e8c\u5206\u67e5\u627e`,`\u5206\u6cbb\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[0004](https://leetcode.com/problems/median-of-two-sorted-arrays)", "[Median of Two Sorted Arrays](/solution/0000-0099/0004.Median%20of%20Two%20Sorted%20Arrays/README_EN.md)", "`Array`,`Binary Search`,`Divide and Conquer`", "Hard", ""]}, {"question_id": "0003", "frontend_question_id": "0003", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-substring-without-repeating-characters", "url_en": "https://leetcode.com/problems/longest-substring-without-repeating-characters", "relative_path_cn": "/solution/0000-0099/0003.Longest%20Substring%20Without%20Repeating%20Characters/README.md", "relative_path_en": "/solution/0000-0099/0003.Longest%20Substring%20Without%20Repeating%20Characters/README_EN.md", "title_cn": "\u65e0\u91cd\u590d\u5b57\u7b26\u7684\u6700\u957f\u5b50\u4e32", "title_en": "Longest Substring Without Repeating Characters", "question_title_slug": "longest-substring-without-repeating-characters", "content_en": "

    Given a string s, find the length of the longest substring without repeating characters.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "abcabcbb"\nOutput: 3\nExplanation: The answer is "abc", with the length of 3.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "bbbbb"\nOutput: 1\nExplanation: The answer is "b", with the length of 1.\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "pwwkew"\nOutput: 3\nExplanation: The answer is "wke", with the length of 3.\nNotice that the answer must be a substring, "pwke" is a subsequence and not a substring.\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = ""\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= s.length <= 5 * 104
    • \n\t
    • s consists of English letters, digits, symbols and spaces.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u8bf7\u4f60\u627e\u51fa\u5176\u4e2d\u4e0d\u542b\u6709\u91cd\u590d\u5b57\u7b26\u7684\u00a0\u6700\u957f\u5b50\u4e32\u00a0\u7684\u957f\u5ea6\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\u00a01:

    \n\n
    \n\u8f93\u5165: s = \"abcabcbb\"\n\u8f93\u51fa: 3 \n\u89e3\u91ca: \u56e0\u4e3a\u65e0\u91cd\u590d\u5b57\u7b26\u7684\u6700\u957f\u5b50\u4e32\u662f \"abc\"\uff0c\u6240\u4ee5\u5176\u957f\u5ea6\u4e3a 3\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: s = \"bbbbb\"\n\u8f93\u51fa: 1\n\u89e3\u91ca: \u56e0\u4e3a\u65e0\u91cd\u590d\u5b57\u7b26\u7684\u6700\u957f\u5b50\u4e32\u662f \"b\"\uff0c\u6240\u4ee5\u5176\u957f\u5ea6\u4e3a 1\u3002\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \n\u8f93\u5165: s = \"pwwkew\"\n\u8f93\u51fa: 3\n\u89e3\u91ca: \u56e0\u4e3a\u65e0\u91cd\u590d\u5b57\u7b26\u7684\u6700\u957f\u5b50\u4e32\u662f\u00a0\"wke\"\uff0c\u6240\u4ee5\u5176\u957f\u5ea6\u4e3a 3\u3002\n\u00a0    \u8bf7\u6ce8\u610f\uff0c\u4f60\u7684\u7b54\u6848\u5fc5\u987b\u662f \u5b50\u4e32 \u7684\u957f\u5ea6\uff0c\"pwke\"\u00a0\u662f\u4e00\u4e2a\u5b50\u5e8f\u5217\uff0c\u4e0d\u662f\u5b50\u4e32\u3002\n
    \n\n

    \u793a\u4f8b 4:

    \n\n
    \n\u8f93\u5165: s = \"\"\n\u8f93\u51fa: 0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= s.length <= 5 * 104
    • \n\t
    • s\u00a0\u7531\u82f1\u6587\u5b57\u6bcd\u3001\u6570\u5b57\u3001\u7b26\u53f7\u548c\u7a7a\u683c\u7ec4\u6210
    • \n
    \n", "tags_en": ["Hash Table", "Two Pointers", "String", "Sliding Window"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u53cc\u6307\u9488", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int lengthOfLongestSubstring(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def lengthOfLongestSubstring(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def lengthOfLongestSubstring(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint lengthOfLongestSubstring(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LengthOfLongestSubstring(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar lengthOfLongestSubstring = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef length_of_longest_substring(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func lengthOfLongestSubstring(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func lengthOfLongestSubstring(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def lengthOfLongestSubstring(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun lengthOfLongestSubstring(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn length_of_longest_substring(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function lengthOfLongestSubstring($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function lengthOfLongestSubstring(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (length-of-longest-substring s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0003](https://leetcode-cn.com/problems/longest-substring-without-repeating-characters)", "[\u65e0\u91cd\u590d\u5b57\u7b26\u7684\u6700\u957f\u5b50\u4e32](/solution/0000-0099/0003.Longest%20Substring%20Without%20Repeating%20Characters/README.md)", "`\u54c8\u5e0c\u8868`,`\u53cc\u6307\u9488`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0003](https://leetcode.com/problems/longest-substring-without-repeating-characters)", "[Longest Substring Without Repeating Characters](/solution/0000-0099/0003.Longest%20Substring%20Without%20Repeating%20Characters/README_EN.md)", "`Hash Table`,`Two Pointers`,`String`,`Sliding Window`", "Medium", ""]}, {"question_id": "0002", "frontend_question_id": "0002", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/add-two-numbers", "url_en": "https://leetcode.com/problems/add-two-numbers", "relative_path_cn": "/solution/0000-0099/0002.Add%20Two%20Numbers/README.md", "relative_path_en": "/solution/0000-0099/0002.Add%20Two%20Numbers/README_EN.md", "title_cn": "\u4e24\u6570\u76f8\u52a0", "title_en": "Add Two Numbers", "question_title_slug": "add-two-numbers", "content_en": "

    You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list.

    \n\n

    You may assume the two numbers do not contain any leading zero, except the number 0 itself.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: l1 = [2,4,3], l2 = [5,6,4]\nOutput: [7,0,8]\nExplanation: 342 + 465 = 807.\n
    \n\n

    Example 2:

    \n\n
    \nInput: l1 = [0], l2 = [0]\nOutput: [0]\n
    \n\n

    Example 3:

    \n\n
    \nInput: l1 = [9,9,9,9,9,9,9], l2 = [9,9,9,9]\nOutput: [8,9,9,9,0,0,0,1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in each linked list is in the range [1, 100].
    • \n\t
    • 0 <= Node.val <= 9
    • \n\t
    • It is guaranteed that the list represents a number that does not have leading zeros.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u00a0\u975e\u7a7a \u7684\u94fe\u8868\uff0c\u8868\u793a\u4e24\u4e2a\u975e\u8d1f\u7684\u6574\u6570\u3002\u5b83\u4eec\u6bcf\u4f4d\u6570\u5b57\u90fd\u662f\u6309\u7167\u00a0\u9006\u5e8f\u00a0\u7684\u65b9\u5f0f\u5b58\u50a8\u7684\uff0c\u5e76\u4e14\u6bcf\u4e2a\u8282\u70b9\u53ea\u80fd\u5b58\u50a8\u00a0\u4e00\u4f4d\u00a0\u6570\u5b57\u3002

    \n\n

    \u8bf7\u4f60\u5c06\u4e24\u4e2a\u6570\u76f8\u52a0\uff0c\u5e76\u4ee5\u76f8\u540c\u5f62\u5f0f\u8fd4\u56de\u4e00\u4e2a\u8868\u793a\u548c\u7684\u94fe\u8868\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u5047\u8bbe\u9664\u4e86\u6570\u5b57 0 \u4e4b\u5916\uff0c\u8fd9\u4e24\u4e2a\u6570\u90fd\u4e0d\u4f1a\u4ee5 0\u00a0\u5f00\u5934\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1al1 = [2,4,3], l2 = [5,6,4]\n\u8f93\u51fa\uff1a[7,0,8]\n\u89e3\u91ca\uff1a342 + 465 = 807.\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1al1 = [0], l2 = [0]\n\u8f93\u51fa\uff1a[0]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1al1 = [9,9,9,9,9,9,9], l2 = [9,9,9,9]\n\u8f93\u51fa\uff1a[8,9,9,9,0,0,0,1]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6bcf\u4e2a\u94fe\u8868\u4e2d\u7684\u8282\u70b9\u6570\u5728\u8303\u56f4 [1, 100] \u5185
    • \n\t
    • 0 <= Node.val <= 9
    • \n\t
    • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u5217\u8868\u8868\u793a\u7684\u6570\u5b57\u4e0d\u542b\u524d\u5bfc\u96f6
    • \n
    \n", "tags_en": ["Recursion", "Linked List", "Math"], "tags_cn": ["\u9012\u5f52", "\u94fe\u8868", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public ListNode addTwoNumbers(ListNode l1, ListNode l2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def addTwoNumbers(self, l1, l2):\n \"\"\"\n :type l1: ListNode\n :type l2: ListNode\n :rtype: ListNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nstruct ListNode* addTwoNumbers(struct ListNode* l1, struct ListNode* l2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public ListNode AddTwoNumbers(ListNode l1, ListNode l2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} l1\n * @param {ListNode} l2\n * @return {ListNode}\n */\nvar addTwoNumbers = function(l1, l2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode} l1\n# @param {ListNode} l2\n# @return {ListNode}\ndef add_two_numbers(l1, l2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func addTwoNumbers(_ l1: ListNode?, _ l2: ListNode?) -> ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc addTwoNumbers(l1 *ListNode, l2 *ListNode) *ListNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def addTwoNumbers(l1: ListNode, l2: ListNode): ListNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun addTwoNumbers(l1: ListNode?, l2: ListNode?): ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn add_two_numbers(l1: Option>, l2: Option>) -> Option> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $l1\n * @param ListNode $l2\n * @return ListNode\n */\n function addTwoNumbers($l1, $l2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction addTwoNumbers(l1: ListNode | null, l2: ListNode | null): ListNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (add-two-numbers l1 l2)\n (-> (or/c list-node? #f) (or/c list-node? #f) (or/c list-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0002](https://leetcode-cn.com/problems/add-two-numbers)", "[\u4e24\u6570\u76f8\u52a0](/solution/0000-0099/0002.Add%20Two%20Numbers/README.md)", "`\u9012\u5f52`,`\u94fe\u8868`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0002](https://leetcode.com/problems/add-two-numbers)", "[Add Two Numbers](/solution/0000-0099/0002.Add%20Two%20Numbers/README_EN.md)", "`Recursion`,`Linked List`,`Math`", "Medium", ""]}, {"question_id": "0001", "frontend_question_id": "0001", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/two-sum", "url_en": "https://leetcode.com/problems/two-sum", "relative_path_cn": "/solution/0000-0099/0001.Two%20Sum/README.md", "relative_path_en": "/solution/0000-0099/0001.Two%20Sum/README_EN.md", "title_cn": "\u4e24\u6570\u4e4b\u548c", "title_en": "Two Sum", "question_title_slug": "two-sum", "content_en": "

    Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.

    \n\n

    You may assume that each input would have exactly one solution, and you may not use the same element twice.

    \n\n

    You can return the answer in any order.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [2,7,11,15], target = 9\nOutput: [0,1]\nOutput: Because nums[0] + nums[1] == 9, we return [0, 1].\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [3,2,4], target = 6\nOutput: [1,2]\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [3,3], target = 6\nOutput: [0,1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= nums.length <= 104
    • \n\t
    • -109 <= nums[i] <= 109
    • \n\t
    • -109 <= target <= 109
    • \n\t
    • Only one valid answer exists.
    • \n
    \n\n

     

    \nFollow-up: Can you come up with an algorithm that is less than O(n2time complexity?", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums\u00a0\u548c\u4e00\u4e2a\u6574\u6570\u76ee\u6807\u503c target\uff0c\u8bf7\u4f60\u5728\u8be5\u6570\u7ec4\u4e2d\u627e\u51fa \u548c\u4e3a\u76ee\u6807\u503c target\u00a0 \u7684\u90a3\u00a0\u4e24\u4e2a\u00a0\u6574\u6570\uff0c\u5e76\u8fd4\u56de\u5b83\u4eec\u7684\u6570\u7ec4\u4e0b\u6807\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u5047\u8bbe\u6bcf\u79cd\u8f93\u5165\u53ea\u4f1a\u5bf9\u5e94\u4e00\u4e2a\u7b54\u6848\u3002\u4f46\u662f\uff0c\u6570\u7ec4\u4e2d\u540c\u4e00\u4e2a\u5143\u7d20\u5728\u7b54\u6848\u91cc\u4e0d\u80fd\u91cd\u590d\u51fa\u73b0\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u6309\u4efb\u610f\u987a\u5e8f\u8fd4\u56de\u7b54\u6848\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [2,7,11,15], target = 9\n\u8f93\u51fa\uff1a[0,1]\n\u89e3\u91ca\uff1a\u56e0\u4e3a nums[0] + nums[1] == 9 \uff0c\u8fd4\u56de [0, 1] \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [3,2,4], target = 6\n\u8f93\u51fa\uff1a[1,2]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [3,3], target = 6\n\u8f93\u51fa\uff1a[0,1]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= nums.length <= 104
    • \n\t
    • -109 <= nums[i] <= 109
    • \n\t
    • -109 <= target <= 109
    • \n\t
    • \u53ea\u4f1a\u5b58\u5728\u4e00\u4e2a\u6709\u6548\u7b54\u6848
    • \n
    \n\n

    \u8fdb\u9636\uff1a\u4f60\u53ef\u4ee5\u60f3\u51fa\u4e00\u4e2a\u65f6\u95f4\u590d\u6742\u5ea6\u5c0f\u4e8e O(n2) \u7684\u7b97\u6cd5\u5417\uff1f

    \n", "tags_en": ["Array", "Hash Table"], "tags_cn": ["\u6570\u7ec4", "\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector twoSum(vector& nums, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] twoSum(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def twoSum(self, nums, target):\n \"\"\"\n :type nums: List[int]\n :type target: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def twoSum(self, nums: List[int], target: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* twoSum(int* nums, int numsSize, int target, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] TwoSum(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} target\n * @return {number[]}\n */\nvar twoSum = function(nums, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} target\n# @return {Integer[]}\ndef two_sum(nums, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func twoSum(_ nums: [Int], _ target: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func twoSum(nums []int, target int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def twoSum(nums: Array[Int], target: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun twoSum(nums: IntArray, target: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn two_sum(nums: Vec, target: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $target\n * @return Integer[]\n */\n function twoSum($nums, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function twoSum(nums: number[], target: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (two-sum nums target)\n (-> (listof exact-integer?) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0001](https://leetcode-cn.com/problems/two-sum)", "[\u4e24\u6570\u4e4b\u548c](/solution/0000-0099/0001.Two%20Sum/README.md)", "`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0001](https://leetcode.com/problems/two-sum)", "[Two Sum](/solution/0000-0099/0001.Two%20Sum/README_EN.md)", "`Array`,`Hash Table`", "Easy", ""]}] \ No newline at end of file +[{"question_id": "2031", "frontend_question_id": "1884", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/egg-drop-with-2-eggs-and-n-floors", "url_en": "https://leetcode.com/problems/egg-drop-with-2-eggs-and-n-floors", "relative_path_cn": "/solution/1800-1899/1884.Egg%20Drop%20With%202%20Eggs%20and%20N%20Floors/README.md", "relative_path_en": "/solution/1800-1899/1884.Egg%20Drop%20With%202%20Eggs%20and%20N%20Floors/README_EN.md", "title_cn": "\u9e21\u86cb\u6389\u843d-\u4e24\u679a\u9e21\u86cb", "title_en": "Egg Drop With 2 Eggs and N Floors", "question_title_slug": "egg-drop-with-2-eggs-and-n-floors", "content_en": "

    You are given two identical eggs and you have access to a building with n floors labeled from 1 to n.

    \n\n

    You know that there exists a floor f where 0 <= f <= n such that any egg dropped at a floor higher than f will break, and any egg dropped at or below floor f will not break.

    \n\n

    In each move, you may take an unbroken egg and drop it from any floor x (where 1 <= x <= n). If the egg breaks, you can no longer use it. However, if the egg does not break, you may reuse it in future moves.

    \n\n

    Return the minimum number of moves that you need to determine with certainty what the value of f is.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 2\nOutput: 2\nExplanation: We can drop the first egg from floor 1 and the second egg from floor 2.\nIf the first egg breaks, we know that f = 0.\nIf the second egg breaks but the first egg didn't, we know that f = 1.\nOtherwise, if both eggs survive, we know that f = 2.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 100\nOutput: 14\nExplanation: One optimal strategy is:\n- Drop the 1st egg at floor 9. If it breaks, we know f is between 0 and 8. Drop the 2nd egg starting\n  from floor 1 and going up one at a time to find f within 7 more drops. Total drops is 1 + 7 = 8.\n- If the 1st egg does not break, drop the 1st egg again at floor 22. If it breaks, we know f is between 9\n  and 21. Drop the 2nd egg starting from floor 10 and going up one at a time to find f within 12 more\n  drops. Total drops is 2 + 12 = 14.\n- If the 1st egg does not break again, follow a similar process dropping the 1st egg from floors 34, 45,\n  55, 64, 72, 79, 85, 90, 94, 97, 99, and 100.\nRegardless of the outcome, it takes at most 14 drops to determine f.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60 2\u00a0\u679a\u76f8\u540c \u7684\u9e21\u86cb\uff0c\u548c\u4e00\u680b\u4ece\u7b2c 1\u00a0\u5c42\u5230\u7b2c n \u5c42\u5171\u6709 n \u5c42\u697c\u7684\u5efa\u7b51\u3002

    \n\n

    \u5df2\u77e5\u5b58\u5728\u697c\u5c42 f \uff0c\u6ee1\u8db3\u00a00 <= f <= n \uff0c\u4efb\u4f55\u4ece \u9ad8\u4e8e f \u7684\u697c\u5c42\u843d\u4e0b\u7684\u9e21\u86cb\u90fd \u4f1a\u788e \uff0c\u4ece f \u697c\u5c42\u6216\u6bd4\u5b83\u4f4e \u7684\u697c\u5c42\u843d\u4e0b\u7684\u9e21\u86cb\u90fd \u4e0d\u4f1a\u788e \u3002

    \n\n

    \u6bcf\u6b21\u64cd\u4f5c\uff0c\u4f60\u53ef\u4ee5\u53d6\u4e00\u679a \u6ca1\u6709\u788e \u7684\u9e21\u86cb\u5e76\u628a\u5b83\u4ece\u4efb\u4e00\u697c\u5c42 x \u6254\u4e0b\uff08\u6ee1\u8db3\u00a01 <= x <= n\uff09\u3002\u5982\u679c\u9e21\u86cb\u788e\u4e86\uff0c\u4f60\u5c31\u4e0d\u80fd\u518d\u6b21\u4f7f\u7528\u5b83\u3002\u5982\u679c\u67d0\u679a\u9e21\u86cb\u6254\u4e0b\u540e\u6ca1\u6709\u6454\u788e\uff0c\u5219\u53ef\u4ee5\u5728\u4e4b\u540e\u7684\u64cd\u4f5c\u4e2d \u91cd\u590d\u4f7f\u7528 \u8fd9\u679a\u9e21\u86cb\u3002

    \n\n

    \u8bf7\u4f60\u8ba1\u7b97\u5e76\u8fd4\u56de\u8981\u786e\u5b9a f \u786e\u5207\u7684\u503c \u7684 \u6700\u5c0f\u64cd\u4f5c\u6b21\u6570 \u662f\u591a\u5c11\uff1f

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 2\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6211\u4eec\u53ef\u4ee5\u5c06\u7b2c\u4e00\u679a\u9e21\u86cb\u4ece 1 \u697c\u6254\u4e0b\uff0c\u7136\u540e\u5c06\u7b2c\u4e8c\u679a\u4ece 2 \u697c\u6254\u4e0b\u3002\n\u5982\u679c\u7b2c\u4e00\u679a\u9e21\u86cb\u788e\u4e86\uff0c\u53ef\u77e5 f = 0\uff1b\n\u5982\u679c\u7b2c\u4e8c\u6ca1\u9e21\u86cb\u788e\u4e86\uff0c\u4f46\u7b2c\u4e00\u679a\u6ca1\u788e\uff0c\u53ef\u77e5 f = 1\uff1b\n\u5426\u5219\uff0c\u5f53\u4e24\u4e2a\u9e21\u86cb\u90fd\u6ca1\u788e\u65f6\uff0c\u53ef\u77e5 f = 2\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 100\n\u8f93\u51fa\uff1a14\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 1000
    • \n
    \n", "tags_en": ["Math", "Binary Search", "Dynamic Programming"], "tags_cn": ["\u6570\u5b66", "\u4e8c\u5206\u67e5\u627e", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int twoEggDrop(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int twoEggDrop(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def twoEggDrop(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def twoEggDrop(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint twoEggDrop(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int TwoEggDrop(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar twoEggDrop = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef two_egg_drop(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func twoEggDrop(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func twoEggDrop(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def twoEggDrop(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun twoEggDrop(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn two_egg_drop(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function twoEggDrop($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function twoEggDrop(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (two-egg-drop n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1884](https://leetcode-cn.com/problems/egg-drop-with-2-eggs-and-n-floors)", "[\u9e21\u86cb\u6389\u843d-\u4e24\u679a\u9e21\u86cb](/solution/1800-1899/1884.Egg%20Drop%20With%202%20Eggs%20and%20N%20Floors/README.md)", "`\u6570\u5b66`,`\u4e8c\u5206\u67e5\u627e`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1884](https://leetcode.com/problems/egg-drop-with-2-eggs-and-n-floors)", "[Egg Drop With 2 Eggs and N Floors](/solution/1800-1899/1884.Egg%20Drop%20With%202%20Eggs%20and%20N%20Floors/README_EN.md)", "`Math`,`Binary Search`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "2030", "frontend_question_id": "1875", "paid_only": true, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/group-employees-of-the-same-salary", "url_en": "https://leetcode.com/problems/group-employees-of-the-same-salary", "relative_path_cn": "/solution/1800-1899/1875.Group%20Employees%20of%20the%20Same%20Salary/README.md", "relative_path_en": "/solution/1800-1899/1875.Group%20Employees%20of%20the%20Same%20Salary/README_EN.md", "title_cn": "", "title_en": "Group Employees of the Same Salary", "question_title_slug": "group-employees-of-the-same-salary", "content_en": "

    Table: Employees

    \r\n\r\n
    \r\n+-------------+---------+\r\n| Column Name | Type    |\r\n+-------------+---------+\r\n| employee_id | int     |\r\n| name        | varchar |\r\n| salary      | int     |\r\n+-------------+---------+\r\nemployee_id is the primary key for this table.\r\nEach row of this table indicates the employee ID, employee name, and salary.\r\n
    \r\n\r\n

     

    \r\n\r\n

    A company wants to divide the employees into teams such that all the members on each team have the same salary. The teams should follow these criteria:

    \r\n\r\n
      \r\n\t
    • Each team should consist of at least two employees.
    • \r\n\t
    • All the employees on a team should have the same salary.
    • \r\n\t
    • All the employees of the same salary should be assigned to the same team.
    • \r\n\t
    • If the salary of an employee is unique, we do not assign this employee to any team.
    • \r\n\t
    • A team's ID is assigned based on the rank of the team's salary relative to the other teams' salaries, where the team with the lowest salary has team_id = 1. Note that the salaries for employees not on a team are not included in this ranking.
    • \r\n
    \r\n\r\n

    Write an SQL query to get the team_id of each employee that is in a team.

    \r\n\r\n

    Return the result table ordered by team_id in ascending order. In case of a tie, order it by employee_id in ascending order.

    \r\n\r\n

    The query result format is in the following example:

    \r\n\r\n

     

    \r\n\r\n
    \r\nEmployees table:\r\n+-------------+---------+--------+\r\n| employee_id | name    | salary |\r\n+-------------+---------+--------+\r\n| 2           | Meir    | 3000   |\r\n| 3           | Michael | 3000   |\r\n| 7           | Addilyn | 7400   |\r\n| 8           | Juan    | 6100   |\r\n| 9           | Kannon  | 7400   |\r\n+-------------+---------+--------+\r\n\r\nResult table:\r\n+-------------+---------+--------+---------+\r\n| employee_id | name    | salary | team_id |\r\n+-------------+---------+--------+---------+\r\n| 2           | Meir    | 3000   | 1       |\r\n| 3           | Michael | 3000   | 1       |\r\n| 7           | Addilyn | 7400   | 2       |\r\n| 9           | Kannon  | 7400   | 2       |\r\n+-------------+---------+--------+---------+\r\n\r\nMeir (employee_id=2) and Michael (employee_id=3) are in the same team because they have the same salary of 3000.\r\nAddilyn (employee_id=7) and Kannon (employee_id=9) are in the same team because they have the same salary of 7400.\r\nJuan (employee_id=8) is not included in any team because their salary of 6100 is unique (i.e. no other employee has the same salary).\r\nThe team IDs are assigned as follows (based on salary ranking, lowest first):\r\n- team_id=1: Meir and Michael, salary of 3000\r\n- team_id=2: Addilyn and Kannon, salary of 7400\r\nJuan's salary of 6100 is not included in the ranking because they are not on a team.
    ", "content_cn": null, "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1875](https://leetcode-cn.com/problems/group-employees-of-the-same-salary)", "[Group Employees of the Same Salary](/solution/1800-1899/1875.Group%20Employees%20of%20the%20Same%20Salary/README_EN.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1875](https://leetcode.com/problems/group-employees-of-the-same-salary)", "[Group Employees of the Same Salary](/solution/1800-1899/1875.Group%20Employees%20of%20the%20Same%20Salary/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "2029", "frontend_question_id": "1874", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/minimize-product-sum-of-two-arrays", "url_en": "https://leetcode.com/problems/minimize-product-sum-of-two-arrays", "relative_path_cn": "/solution/1800-1899/1874.Minimize%20Product%20Sum%20of%20Two%20Arrays/README.md", "relative_path_en": "/solution/1800-1899/1874.Minimize%20Product%20Sum%20of%20Two%20Arrays/README_EN.md", "title_cn": "", "title_en": "Minimize Product Sum of Two Arrays", "question_title_slug": "minimize-product-sum-of-two-arrays", "content_en": "

    The product sum of two equal-length arrays a and b is equal to the sum of a[i] * b[i] for all 0 <= i < a.length (0-indexed).

    \r\n\r\n
      \r\n\t
    • For example, if a = [1,2,3,4] and b = [5,2,3,1], the product sum would be 1*5 + 2*2 + 3*3 + 4*1 = 22.
    • \r\n
    \r\n\r\n

    Given two arrays nums1 and nums2 of length n, return the minimum product sum if you are allowed to rearrange the order of the elements in nums1

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: nums1 = [5,3,4,2], nums2 = [4,2,2,5]\r\nOutput: 40\r\nExplanation: We can rearrange nums1 to become [3,5,4,2]. The product sum of [3,5,4,2] and [4,2,2,5] is 3*4 + 5*2 + 4*2 + 2*5 = 40.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: nums1 = [2,1,4,5,7], nums2 = [3,2,4,8,6]\r\nOutput: 65\r\nExplanation: We can rearrange nums1 to become [5,7,4,1,2]. The product sum of [5,7,4,1,2] and [3,2,4,8,6] is 5*3 + 7*2 + 4*4 + 1*8 + 2*6 = 65.\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • n == nums1.length == nums2.length
    • \r\n\t
    • 1 <= n <= 105
    • \r\n\t
    • 1 <= nums1[i], nums2[i] <= 100
    • \r\n
    ", "content_cn": null, "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minProductSum(vector& nums1, vector& nums2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minProductSum(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minProductSum(self, nums1, nums2):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minProductSum(self, nums1: List[int], nums2: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minProductSum(int* nums1, int nums1Size, int* nums2, int nums2Size){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinProductSum(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums1\n * @param {number[]} nums2\n * @return {number}\n */\nvar minProductSum = function(nums1, nums2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums1\n# @param {Integer[]} nums2\n# @return {Integer}\ndef min_product_sum(nums1, nums2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minProductSum(_ nums1: [Int], _ nums2: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minProductSum(nums1 []int, nums2 []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minProductSum(nums1: Array[Int], nums2: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minProductSum(nums1: IntArray, nums2: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_product_sum(nums1: Vec, nums2: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums1\n * @param Integer[] $nums2\n * @return Integer\n */\n function minProductSum($nums1, $nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minProductSum(nums1: number[], nums2: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-product-sum nums1 nums2)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1874](https://leetcode-cn.com/problems/minimize-product-sum-of-two-arrays)", "[Minimize Product Sum of Two Arrays](/solution/1800-1899/1874.Minimize%20Product%20Sum%20of%20Two%20Arrays/README_EN.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1874](https://leetcode.com/problems/minimize-product-sum-of-two-arrays)", "[Minimize Product Sum of Two Arrays](/solution/1800-1899/1874.Minimize%20Product%20Sum%20of%20Two%20Arrays/README_EN.md)", "`Greedy`", "Medium", "\ud83d\udd12"]}, {"question_id": "2024", "frontend_question_id": "1873", "paid_only": true, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/calculate-special-bonus", "url_en": "https://leetcode.com/problems/calculate-special-bonus", "relative_path_cn": "/solution/1800-1899/1873.Calculate%20Special%20Bonus/README.md", "relative_path_en": "/solution/1800-1899/1873.Calculate%20Special%20Bonus/README_EN.md", "title_cn": "", "title_en": "Calculate Special Bonus", "question_title_slug": "calculate-special-bonus", "content_en": "

    Table: Employees

    \r\n\r\n
    \r\n+-------------+---------+\r\n| Column Name | Type    |\r\n+-------------+---------+\r\n| employee_id | int     |\r\n| name        | varchar |\r\n| salary      | int     |\r\n+-------------+---------+\r\nemployee_id is the primary key for this table.\r\nEach row of this table indicates the employee ID, employee name, and salary.\r\n
    \r\n\r\n

     

    \r\n\r\n

    Write an SQL query to calculate the bonus of each employee. The bonus of an employee is 100% of their salary if the ID of the employee is an odd number and the employee name does not start with the character 'M'. The bonus of an employee is 0 otherwise.

    \r\n\r\n

    Return the result table ordered by employee_id.

    \r\n\r\n

    The query result format is in the following example:

    \r\n\r\n

     

    \r\n\r\n
    \r\nEmployees table:\r\n+-------------+---------+--------+\r\n| employee_id | name    | salary |\r\n+-------------+---------+--------+\r\n| 2           | Meir    | 3000   |\r\n| 3           | Michael | 3800   |\r\n| 7           | Addilyn | 7400   |\r\n| 8           | Juan    | 6100   |\r\n| 9           | Kannon  | 7700   |\r\n+-------------+---------+--------+\r\n\r\nResult table:\r\n+-------------+-------+\r\n| employee_id | bonus |\r\n+-------------+-------+\r\n| 2           | 0     |\r\n| 3           | 0     |\r\n| 7           | 7400  |\r\n| 8           | 0     |\r\n| 9           | 7700  |\r\n+-------------+-------+\r\n\r\nThe employees with IDs 2 and 8 get 0 bonus because they have an even employee_id.\r\nThe employee with ID 3 gets 0 bonus because their name starts with 'M'.\r\nThe rest of the employees get a 100% bonus.\r\n
    ", "content_cn": null, "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1873](https://leetcode-cn.com/problems/calculate-special-bonus)", "[Calculate Special Bonus](/solution/1800-1899/1873.Calculate%20Special%20Bonus/README_EN.md)", "", "\u7b80\u5355", ""], "md_table_row_en": ["[1873](https://leetcode.com/problems/calculate-special-bonus)", "[Calculate Special Bonus](/solution/1800-1899/1873.Calculate%20Special%20Bonus/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "2019", "frontend_question_id": "1868", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/product-of-two-run-length-encoded-arrays", "url_en": "https://leetcode.com/problems/product-of-two-run-length-encoded-arrays", "relative_path_cn": "/solution/1800-1899/1868.Product%20of%20Two%20Run-Length%20Encoded%20Arrays/README.md", "relative_path_en": "/solution/1800-1899/1868.Product%20of%20Two%20Run-Length%20Encoded%20Arrays/README_EN.md", "title_cn": "", "title_en": "Product of Two Run-Length Encoded Arrays", "question_title_slug": "product-of-two-run-length-encoded-arrays", "content_en": "

    Run-length encoding is a compression algorithm that allows for an integer array nums with many segments of consecutive repeated numbers to be represented by a (generally smaller) 2D array encoded. Each encoded[i] = [vali, freqi] describes the ith segment of repeated numbers in nums where vali is the value that is repeated freqi times.

    \n\n
      \n\t
    • For example, nums = [1,1,1,2,2,2,2,2] is represented by the run-length encoded array encoded = [[1,3],[2,5]]. Another way to read this is "three 1's followed by five 2's".
    • \n
    \n\n

    The product of two run-length encoded arrays encoded1 and encoded2 can be calculated using the following steps:

    \n\n
      \n\t
    1. Expand both encoded1 and encoded2 into the full arrays nums1 and nums2 respectively.
    2. \n\t
    3. Create a new array prodNums of length nums1.length and set prodNums[i] = nums1[i] * nums2[i].
    4. \n\t
    5. Compress prodNums into a run-length encoded array and return it.
    6. \n
    \n\n

    You are given two run-length encoded arrays encoded1 and encoded2 representing full arrays nums1 and nums2 respectively. Both nums1 and nums2 have the same length. Each encoded1[i] = [vali, freqi] describes the ith segment of nums1, and each encoded2[j] = [valj, freqj] describes the jth segment of nums2.

    \n\n

    Return the product of encoded1 and encoded2.

    \n\n

    Note: Compression should be done such that the run-length encoded array has the minimum possible length.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: encoded1 = [[1,3],[2,3]], encoded2 = [[6,3],[3,3]]\nOutput: [[6,6]]\nExplanation: encoded1 expands to [1,1,1,2,2,2] and encoded2 expands to [6,6,6,3,3,3].\nprodNums = [6,6,6,6,6,6], which is compressed into the run-length encoded array [[6,6]].\n
    \n\n

    Example 2:

    \n\n
    \nInput: encoded1 = [[1,3],[2,1],[3,2]], encoded2 = [[2,3],[3,3]]\nOutput: [[2,3],[6,1],[9,2]]\nExplanation: encoded1 expands to [1,1,1,2,3,3] and encoded2 expands to [2,2,2,3,3,3].\nprodNums = [2,2,2,6,9,9], which is compressed into the run-length encoded array [[2,3],[6,1],[9,2]].\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= encoded1.length, encoded2.length <= 105
    • \n\t
    • encoded1[i].length == 2
    • \n\t
    • encoded2[j].length == 2
    • \n\t
    • 1 <= vali, freqi <= 104 for each encoded1[i].
    • \n\t
    • 1 <= valj, freqj <= 104 for each encoded2[j].
    • \n\t
    • The full arrays that encoded1 and encoded2 represent are the same length.
    • \n
    \n", "content_cn": null, "tags_en": ["Two Pointers"], "tags_cn": ["\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> findRLEArray(vector>& encoded1, vector>& encoded2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> findRLEArray(int[][] encoded1, int[][] encoded2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findRLEArray(self, encoded1, encoded2):\n \"\"\"\n :type encoded1: List[List[int]]\n :type encoded2: List[List[int]]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findRLEArray(self, encoded1: List[List[int]], encoded2: List[List[int]]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** findRLEArray(int** encoded1, int encoded1Size, int* encoded1ColSize, int** encoded2, int encoded2Size, int* encoded2ColSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> FindRLEArray(int[][] encoded1, int[][] encoded2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} encoded1\n * @param {number[][]} encoded2\n * @return {number[][]}\n */\nvar findRLEArray = function(encoded1, encoded2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} encoded1\n# @param {Integer[][]} encoded2\n# @return {Integer[][]}\ndef find_rle_array(encoded1, encoded2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findRLEArray(_ encoded1: [[Int]], _ encoded2: [[Int]]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findRLEArray(encoded1 [][]int, encoded2 [][]int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findRLEArray(encoded1: Array[Array[Int]], encoded2: Array[Array[Int]]): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findRLEArray(encoded1: Array, encoded2: Array): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_rle_array(encoded1: Vec>, encoded2: Vec>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $encoded1\n * @param Integer[][] $encoded2\n * @return Integer[][]\n */\n function findRLEArray($encoded1, $encoded2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findRLEArray(encoded1: number[][], encoded2: number[][]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-rle-array encoded1 encoded2)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1868](https://leetcode-cn.com/problems/product-of-two-run-length-encoded-arrays)", "[Product of Two Run-Length Encoded Arrays](/solution/1800-1899/1868.Product%20of%20Two%20Run-Length%20Encoded%20Arrays/README_EN.md)", "`\u53cc\u6307\u9488`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1868](https://leetcode.com/problems/product-of-two-run-length-encoded-arrays)", "[Product of Two Run-Length Encoded Arrays](/solution/1800-1899/1868.Product%20of%20Two%20Run-Length%20Encoded%20Arrays/README_EN.md)", "`Two Pointers`", "Medium", "\ud83d\udd12"]}, {"question_id": "2018", "frontend_question_id": "1889", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-space-wasted-from-packaging", "url_en": "https://leetcode.com/problems/minimum-space-wasted-from-packaging", "relative_path_cn": "/solution/1800-1899/1889.Minimum%20Space%20Wasted%20From%20Packaging/README.md", "relative_path_en": "/solution/1800-1899/1889.Minimum%20Space%20Wasted%20From%20Packaging/README_EN.md", "title_cn": "\u88c5\u5305\u88f9\u7684\u6700\u5c0f\u6d6a\u8d39\u7a7a\u95f4", "title_en": "Minimum Space Wasted From Packaging", "question_title_slug": "minimum-space-wasted-from-packaging", "content_en": "

    You have n packages that you are trying to place in boxes, one package in each box. There are m suppliers that each produce boxes of different sizes (with infinite supply). A package can be placed in a box if the size of the package is less than or equal to the size of the box.

    \n\n

    The package sizes are given as an integer array packages, where packages[i] is the size of the ith package. The suppliers are given as a 2D integer array boxes, where boxes[j] is an array of box sizes that the jth supplier produces.

    \n\n

    You want to choose a single supplier and use boxes from them such that the total wasted space is minimized. For each package in a box, we define the space wasted to be size of the box - size of the package. The total wasted space is the sum of the space wasted in all the boxes.

    \n\n
      \n\t
    • For example, if you have to fit packages with sizes [2,3,5] and the supplier offers boxes of sizes [4,8], you can fit the packages of size-2 and size-3 into two boxes of size-4 and the package with size-5 into a box of size-8. This would result in a waste of (4-2) + (4-3) + (8-5) = 6.
    • \n
    \n\n

    Return the minimum total wasted space by choosing the box supplier optimally, or -1 if it is impossible to fit all the packages inside boxes. Since the answer may be large, return it modulo 109 + 7.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: packages = [2,3,5], boxes = [[4,8],[2,8]]\nOutput: 6\nExplanation: It is optimal to choose the first supplier, using two size-4 boxes and one size-8 box.\nThe total waste is (4-2) + (4-3) + (8-5) = 6.\n
    \n\n

    Example 2:

    \n\n
    \nInput: packages = [2,3,5], boxes = [[1,4],[2,3],[3,4]]\nOutput: -1\nExplanation: There is no box that the package of size 5 can fit in.\n
    \n\n

    Example 3:

    \n\n
    \nInput: packages = [3,5,8,10,11,12], boxes = [[12],[11,9],[10,5,14]]\nOutput: 9\nExplanation: It is optimal to choose the third supplier, using two size-5 boxes, two size-10 boxes, and two size-14 boxes.\nThe total waste is (5-3) + (5-5) + (10-8) + (10-10) + (14-11) + (14-12) = 9.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == packages.length
    • \n\t
    • m == boxes.length
    • \n\t
    • 1 <= n <= 105
    • \n\t
    • 1 <= m <= 105
    • \n\t
    • 1 <= packages[i] <= 105
    • \n\t
    • 1 <= boxes[j].length <= 105
    • \n\t
    • 1 <= boxes[j][k] <= 105
    • \n\t
    • sum(boxes[j].length) <= 105
    • \n\t
    • The elements in boxes[j] are distinct.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u00a0n\u00a0\u4e2a\u5305\u88f9\uff0c\u4f60\u9700\u8981\u628a\u5b83\u4eec\u88c5\u5728\u7bb1\u5b50\u91cc\uff0c\u6bcf\u4e2a\u7bb1\u5b50\u88c5\u4e00\u4e2a\u5305\u88f9\u3002\u603b\u5171\u6709\u00a0m\u00a0\u4e2a\u4f9b\u5e94\u5546\u63d0\u4f9b \u4e0d\u540c\u5c3a\u5bf8\u00a0\u7684\u7bb1\u5b50\uff08\u6bcf\u4e2a\u89c4\u683c\u90fd\u6709\u65e0\u6570\u4e2a\u7bb1\u5b50\uff09\u3002\u5982\u679c\u4e00\u4e2a\u5305\u88f9\u7684\u5c3a\u5bf8 \u5c0f\u4e8e\u7b49\u4e8e\u00a0\u4e00\u4e2a\u7bb1\u5b50\u7684\u5c3a\u5bf8\uff0c\u90a3\u4e48\u8fd9\u4e2a\u5305\u88f9\u5c31\u53ef\u4ee5\u653e\u5165\u8fd9\u4e2a\u7bb1\u5b50\u4e4b\u4e2d\u3002

    \n\n

    \u5305\u88f9\u7684\u5c3a\u5bf8\u7528\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0packages\u00a0\u8868\u793a\uff0c\u5176\u4e2d\u00a0packages[i]\u00a0\u662f\u7b2c\u00a0i\u00a0\u4e2a\u5305\u88f9\u7684\u5c3a\u5bf8\u3002\u4f9b\u5e94\u5546\u7528\u4e8c\u7ef4\u6570\u7ec4\u00a0boxes\u00a0\u8868\u793a\uff0c\u5176\u4e2d\u00a0boxes[j]\u00a0\u662f\u7b2c j\u00a0\u4e2a\u4f9b\u5e94\u5546\u63d0\u4f9b\u7684\u6240\u6709\u7bb1\u5b50\u5c3a\u5bf8\u7684\u6570\u7ec4\u3002

    \n\n

    \u4f60\u60f3\u8981\u9009\u62e9 \u4e00\u4e2a\u4f9b\u5e94\u5546\u00a0\u5e76\u53ea\u4f7f\u7528\u8be5\u4f9b\u5e94\u5546\u63d0\u4f9b\u7684\u7bb1\u5b50\uff0c\u4f7f\u5f97 \u603b\u6d6a\u8d39\u7a7a\u95f4\u6700\u5c0f\u00a0\u3002\u5bf9\u4e8e\u6bcf\u4e2a\u88c5\u4e86\u5305\u88f9\u7684\u7bb1\u5b50\uff0c\u6211\u4eec\u5b9a\u4e49 \u6d6a\u8d39\u7684\u00a0\u7a7a\u95f4\u7b49\u4e8e \u7bb1\u5b50\u7684\u5c3a\u5bf8 - \u5305\u88f9\u7684\u5c3a\u5bf8\u00a0\u3002\u603b\u6d6a\u8d39\u7a7a\u95f4\u00a0\u4e3a\u00a0\u6240\u6709\u00a0\u7bb1\u5b50\u4e2d\u6d6a\u8d39\u7a7a\u95f4\u7684\u603b\u548c\u3002

    \n\n
      \n\t
    • \u6bd4\u65b9\u8bf4\uff0c\u5982\u679c\u4f60\u60f3\u8981\u7528\u5c3a\u5bf8\u6570\u7ec4\u4e3a\u00a0[4,8]\u00a0\u7684\u7bb1\u5b50\u88c5\u4e0b\u5c3a\u5bf8\u4e3a\u00a0[2,3,5]\u00a0\u7684\u5305\u88f9\uff0c\u4f60\u53ef\u4ee5\u5c06\u5c3a\u5bf8\u4e3a 2\u00a0\u548c 3\u00a0\u7684\u4e24\u4e2a\u5305\u88f9\u88c5\u5165\u4e24\u4e2a\u5c3a\u5bf8\u4e3a 4\u00a0\u7684\u7bb1\u5b50\u4e2d\uff0c\u540c\u65f6\u628a\u5c3a\u5bf8\u4e3a 5\u00a0\u7684\u5305\u88f9\u88c5\u5165\u5c3a\u5bf8\u4e3a 8\u00a0\u7684\u7bb1\u5b50\u4e2d\u3002\u603b\u6d6a\u8d39\u7a7a\u95f4\u4e3a\u00a0(4-2) + (4-3) + (8-5) = 6\u00a0\u3002
    • \n
    \n\n

    \u8bf7\u4f60\u9009\u62e9 \u6700\u4f18\u00a0\u7bb1\u5b50\u4f9b\u5e94\u5546\uff0c\u4f7f\u5f97 \u603b\u6d6a\u8d39\u7a7a\u95f4\u6700\u5c0f\u00a0\u3002\u5982\u679c \u65e0\u6cd5 \u5c06\u6240\u6709\u5305\u88f9\u653e\u5165\u7bb1\u5b50\u4e2d\uff0c\u8bf7\u4f60\u8fd4\u56de -1\u00a0\u3002\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u4f1a \u5f88\u5927\u00a0\uff0c\u8bf7\u8fd4\u56de\u5b83\u5bf9\u00a0109 + 7\u00a0\u53d6\u4f59\u00a0\u7684\u7ed3\u679c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1apackages = [2,3,5], boxes = [[4,8],[2,8]]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u9009\u62e9\u7b2c\u4e00\u4e2a\u4f9b\u5e94\u5546\u6700\u4f18\uff0c\u7528\u4e24\u4e2a\u5c3a\u5bf8\u4e3a 4 \u7684\u7bb1\u5b50\u548c\u4e00\u4e2a\u5c3a\u5bf8\u4e3a 8 \u7684\u7bb1\u5b50\u3002\n\u603b\u6d6a\u8d39\u7a7a\u95f4\u4e3a (4-2) + (4-3) + (8-5) = 6 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1apackages = [2,3,5], boxes = [[1,4],[2,3],[3,4]]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u6ca1\u6709\u7bb1\u5b50\u80fd\u88c5\u4e0b\u5c3a\u5bf8\u4e3a 5 \u7684\u5305\u88f9\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1apackages = [3,5,8,10,11,12], boxes = [[12],[11,9],[10,5,14]]\n\u8f93\u51fa\uff1a9\n\u89e3\u91ca\uff1a\u9009\u62e9\u7b2c\u4e09\u4e2a\u4f9b\u5e94\u5546\u6700\u4f18\uff0c\u7528\u4e24\u4e2a\u5c3a\u5bf8\u4e3a 5 \u7684\u7bb1\u5b50\uff0c\u4e24\u4e2a\u5c3a\u5bf8\u4e3a 10 \u7684\u7bb1\u5b50\u548c\u4e24\u4e2a\u5c3a\u5bf8\u4e3a 14 \u7684\u7bb1\u5b50\u3002\n\u603b\u6d6a\u8d39\u7a7a\u95f4\u4e3a (5-3) + (5-5) + (10-8) + (10-10) + (14-11) + (14-12) = 9 \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == packages.length
    • \n\t
    • m == boxes.length
    • \n\t
    • 1 <= n <= 105
    • \n\t
    • 1 <= m <= 105
    • \n\t
    • 1 <= packages[i] <= 105
    • \n\t
    • 1 <= boxes[j].length <= 105
    • \n\t
    • 1 <= boxes[j][k] <= 105
    • \n\t
    • sum(boxes[j].length) <= 105
    • \n\t
    • boxes[j]\u00a0\u4e2d\u7684\u5143\u7d20 \u4e92\u4e0d\u76f8\u540c\u00a0\u3002
    • \n
    \n", "tags_en": ["Binary Search"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minWastedSpace(vector& packages, vector>& boxes) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minWastedSpace(int[] packages, int[][] boxes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minWastedSpace(self, packages, boxes):\n \"\"\"\n :type packages: List[int]\n :type boxes: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minWastedSpace(self, packages: List[int], boxes: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minWastedSpace(int* packages, int packagesSize, int** boxes, int boxesSize, int* boxesColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinWastedSpace(int[] packages, int[][] boxes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} packages\n * @param {number[][]} boxes\n * @return {number}\n */\nvar minWastedSpace = function(packages, boxes) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} packages\n# @param {Integer[][]} boxes\n# @return {Integer}\ndef min_wasted_space(packages, boxes)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minWastedSpace(_ packages: [Int], _ boxes: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minWastedSpace(packages []int, boxes [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minWastedSpace(packages: Array[Int], boxes: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minWastedSpace(packages: IntArray, boxes: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_wasted_space(packages: Vec, boxes: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $packages\n * @param Integer[][] $boxes\n * @return Integer\n */\n function minWastedSpace($packages, $boxes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minWastedSpace(packages: number[], boxes: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-wasted-space packages boxes)\n (-> (listof exact-integer?) (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1889](https://leetcode-cn.com/problems/minimum-space-wasted-from-packaging)", "[\u88c5\u5305\u88f9\u7684\u6700\u5c0f\u6d6a\u8d39\u7a7a\u95f4](/solution/1800-1899/1889.Minimum%20Space%20Wasted%20From%20Packaging/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u56f0\u96be", ""], "md_table_row_en": ["[1889](https://leetcode.com/problems/minimum-space-wasted-from-packaging)", "[Minimum Space Wasted From Packaging](/solution/1800-1899/1889.Minimum%20Space%20Wasted%20From%20Packaging/README_EN.md)", "`Binary Search`", "Hard", ""]}, {"question_id": "2017", "frontend_question_id": "1888", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-number-of-flips-to-make-the-binary-string-alternating", "url_en": "https://leetcode.com/problems/minimum-number-of-flips-to-make-the-binary-string-alternating", "relative_path_cn": "/solution/1800-1899/1888.Minimum%20Number%20of%20Flips%20to%20Make%20the%20Binary%20String%20Alternating/README.md", "relative_path_en": "/solution/1800-1899/1888.Minimum%20Number%20of%20Flips%20to%20Make%20the%20Binary%20String%20Alternating/README_EN.md", "title_cn": "\u4f7f\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32\u5b57\u7b26\u4ea4\u66ff\u7684\u6700\u5c11\u53cd\u8f6c\u6b21\u6570", "title_en": "Minimum Number of Flips to Make the Binary String Alternating", "question_title_slug": "minimum-number-of-flips-to-make-the-binary-string-alternating", "content_en": "

    You are given a binary string s. You are allowed to perform two types of operations on the string in any sequence:

    \n\n
      \n\t
    • Type-1: Remove the character at the start of the string s and append it to the end of the string.
    • \n\t
    • Type-2: Pick any character in s and flip its value, i.e., if its value is '0' it becomes '1' and vice-versa.
    • \n
    \n\n

    Return the minimum number of type-2 operations you need to perform such that s becomes alternating.

    \n\n

    The string is called alternating if no two adjacent characters are equal.

    \n\n
      \n\t
    • For example, the strings "010" and "1010" are alternating, while the string "0100" is not.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "111000"\nOutput: 2\nExplanation: Use the first operation two times to make s = "100011".\nThen, use the second operation on the third and sixth elements to make s = "101010".\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "010"\nOutput: 0\nExplanation: The string is already alternating.\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "1110"\nOutput: 1\nExplanation: Use the second operation on the second element to make s = "1010".\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 105
    • \n\t
    • s[i] is either '0' or '1'.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32\u00a0s\u00a0\u3002\u4f60\u53ef\u4ee5\u6309\u4efb\u610f\u987a\u5e8f\u6267\u884c\u4ee5\u4e0b\u4e24\u79cd\u64cd\u4f5c\u4efb\u610f\u6b21\uff1a

    \n\n
      \n\t
    • \u7c7b\u578b 1 \uff1a\u5220\u9664 \u5b57\u7b26\u4e32\u00a0s\u00a0\u7684\u7b2c\u4e00\u4e2a\u5b57\u7b26\u5e76\u5c06\u5b83 \u6dfb\u52a0\u00a0\u5230\u5b57\u7b26\u4e32\u7ed3\u5c3e\u3002
    • \n\t
    • \u7c7b\u578b 2 \uff1a\u9009\u62e9 \u5b57\u7b26\u4e32\u00a0s\u00a0\u4e2d\u4efb\u610f\u4e00\u4e2a\u5b57\u7b26\u5e76\u5c06\u8be5\u5b57\u7b26\u00a0\u53cd\u8f6c\u00a0\uff0c\u4e5f\u5c31\u662f\u5982\u679c\u503c\u4e3a\u00a0'0'\u00a0\uff0c\u5219\u53cd\u8f6c\u5f97\u5230\u00a0'1'\u00a0\uff0c\u53cd\u4e4b\u4ea6\u7136\u3002
    • \n
    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u4f7f s\u00a0\u53d8\u6210 \u4ea4\u66ff \u5b57\u7b26\u4e32\u7684\u524d\u63d0\u4e0b\uff0c\u00a0\u7c7b\u578b 2\u00a0\u7684 \u6700\u5c11\u00a0\u64cd\u4f5c\u6b21\u6570\u00a0\u3002

    \n\n

    \u6211\u4eec\u79f0\u4e00\u4e2a\u5b57\u7b26\u4e32\u662f \u4ea4\u66ff\u00a0\u7684\uff0c\u9700\u8981\u6ee1\u8db3\u4efb\u610f\u76f8\u90bb\u5b57\u7b26\u90fd\u4e0d\u540c\u3002

    \n\n
      \n\t
    • \u6bd4\u65b9\u8bf4\uff0c\u5b57\u7b26\u4e32\u00a0\"010\" \u548c\u00a0\"1010\"\u00a0\u90fd\u662f\u4ea4\u66ff\u7684\uff0c\u4f46\u662f\u5b57\u7b26\u4e32\u00a0\"0100\"\u00a0\u4e0d\u662f\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1as = \"111000\"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6267\u884c\u7b2c\u4e00\u79cd\u64cd\u4f5c\u4e24\u6b21\uff0c\u5f97\u5230 s = \"100011\" \u3002\n\u7136\u540e\u5bf9\u7b2c\u4e09\u4e2a\u548c\u7b2c\u516d\u4e2a\u5b57\u7b26\u6267\u884c\u7b2c\u4e8c\u79cd\u64cd\u4f5c\uff0c\u5f97\u5230 s = \"101010\" \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1as = \"010\"\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u5b57\u7b26\u4e32\u5df2\u7ecf\u662f\u4ea4\u66ff\u7684\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1as = \"1110\"\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u5bf9\u7b2c\u4e8c\u4e2a\u5b57\u7b26\u6267\u884c\u7b2c\u4e8c\u79cd\u64cd\u4f5c\uff0c\u5f97\u5230 s = \"1010\" \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 105
    • \n\t
    • s[i]\u00a0\u8981\u4e48\u662f\u00a0'0'\u00a0\uff0c\u8981\u4e48\u662f\u00a0'1'\u00a0\u3002
    • \n
    \n", "tags_en": ["Greedy", "Array"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minFlips(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minFlips(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minFlips(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minFlips(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minFlips(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinFlips(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar minFlips = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef min_flips(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minFlips(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minFlips(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minFlips(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minFlips(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_flips(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function minFlips($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minFlips(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-flips s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1888](https://leetcode-cn.com/problems/minimum-number-of-flips-to-make-the-binary-string-alternating)", "[\u4f7f\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32\u5b57\u7b26\u4ea4\u66ff\u7684\u6700\u5c11\u53cd\u8f6c\u6b21\u6570](/solution/1800-1899/1888.Minimum%20Number%20of%20Flips%20to%20Make%20the%20Binary%20String%20Alternating/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1888](https://leetcode.com/problems/minimum-number-of-flips-to-make-the-binary-string-alternating)", "[Minimum Number of Flips to Make the Binary String Alternating](/solution/1800-1899/1888.Minimum%20Number%20of%20Flips%20to%20Make%20the%20Binary%20String%20Alternating/README_EN.md)", "`Greedy`,`Array`", "Medium", ""]}, {"question_id": "2016", "frontend_question_id": "1887", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reduction-operations-to-make-the-array-elements-equal", "url_en": "https://leetcode.com/problems/reduction-operations-to-make-the-array-elements-equal", "relative_path_cn": "/solution/1800-1899/1887.Reduction%20Operations%20to%20Make%20the%20Array%20Elements%20Equal/README.md", "relative_path_en": "/solution/1800-1899/1887.Reduction%20Operations%20to%20Make%20the%20Array%20Elements%20Equal/README_EN.md", "title_cn": "\u4f7f\u6570\u7ec4\u5143\u7d20\u76f8\u7b49\u7684\u51cf\u5c11\u64cd\u4f5c\u6b21\u6570", "title_en": "Reduction Operations to Make the Array Elements Equal", "question_title_slug": "reduction-operations-to-make-the-array-elements-equal", "content_en": "

    Given an integer array nums, your goal is to make all elements in nums equal. To complete one operation, follow these steps:

    \n\n
      \n\t
    1. Find the largest value in nums. Let its index be i (0-indexed) and its value be largest. If there are multiple elements with the largest value, pick the smallest i.
    2. \n\t
    3. Find the next largest value in nums strictly smaller than largest. Let its value be nextLargest.
    4. \n\t
    5. Reduce nums[i] to nextLargest.
    6. \n
    \n\n

    Return the number of operations to make all elements in nums equal.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [5,1,3]\nOutput: 3\nExplanation: It takes 3 operations to make all elements in nums equal:\n1. largest = 5 at index 0. nextLargest = 3. Reduce nums[0] to 3. nums = [3,1,3].\n2. largest = 3 at index 0. nextLargest = 1. Reduce nums[0] to 1. nums = [1,1,3].\n3. largest = 3 at index 2. nextLargest = 1. Reduce nums[2] to 1. nums = [1,1,1].\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,1,1]\nOutput: 0\nExplanation: All elements in nums are already equal.\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [1,1,2,2,3]\nOutput: 4\nExplanation: It takes 4 operations to make all elements in nums equal:\n1. largest = 3 at index 4. nextLargest = 2. Reduce nums[4] to 2. nums = [1,1,2,2,2].\n2. largest = 2 at index 2. nextLargest = 1. Reduce nums[2] to 1. nums = [1,1,1,2,2].\n3. largest = 2 at index 3. nextLargest = 1. Reduce nums[3] to 1. nums = [1,1,1,1,2].\n4. largest = 2 at index 4. nextLargest = 1. Reduce nums[4] to 1. nums = [1,1,1,1,1].\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 5 * 104
    • \n\t
    • 1 <= nums[i] <= 5 * 104
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \uff0c\u4f60\u7684\u76ee\u6807\u662f\u4ee4 nums \u4e2d\u7684\u6240\u6709\u5143\u7d20\u76f8\u7b49\u3002\u5b8c\u6210\u4e00\u6b21\u51cf\u5c11\u64cd\u4f5c\u9700\u8981\u9075\u7167\u4e0b\u9762\u7684\u51e0\u4e2a\u6b65\u9aa4\uff1a

    \n\n
      \n\t
    1. \u627e\u51fa nums \u4e2d\u7684 \u6700\u5927 \u503c\u3002\u8bb0\u8fd9\u4e2a\u503c\u4e3a largest \u5e76\u53d6\u5176\u4e0b\u6807 i \uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\u8ba1\u6570\uff09\u3002\u5982\u679c\u6709\u591a\u4e2a\u5143\u7d20\u90fd\u662f\u6700\u5927\u503c\uff0c\u5219\u53d6\u6700\u5c0f\u7684 i \u3002
    2. \n\t
    3. \u627e\u51fa nums \u4e2d\u7684 \u4e0b\u4e00\u4e2a\u6700\u5927 \u503c\uff0c\u8fd9\u4e2a\u503c \u4e25\u683c\u5c0f\u4e8e largest \uff0c\u8bb0\u4e3a nextLargest \u3002
    4. \n\t
    5. \u5c06 nums[i] \u51cf\u5c11\u5230 nextLargest \u3002
    6. \n
    \n\n

    \u8fd4\u56de\u4f7f nums \u4e2d\u7684\u6240\u6709\u5143\u7d20\u76f8\u7b49\u7684\u64cd\u4f5c\u6b21\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [5,1,3]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u9700\u8981 3 \u6b21\u64cd\u4f5c\u4f7f nums \u4e2d\u7684\u6240\u6709\u5143\u7d20\u76f8\u7b49\uff1a\n1. largest = 5 \u4e0b\u6807\u4e3a 0 \u3002nextLargest = 3 \u3002\u5c06 nums[0] \u51cf\u5c11\u5230 3 \u3002nums = [3,1,3] \u3002\n2. largest = 3 \u4e0b\u6807\u4e3a 0 \u3002nextLargest = 1 \u3002\u5c06 nums[0] \u51cf\u5c11\u5230 1 \u3002nums = [1,1,3] \u3002\n3. largest = 3 \u4e0b\u6807\u4e3a 2 \u3002nextLargest = 1 \u3002\u5c06 nums[2] \u51cf\u5c11\u5230 1 \u3002nums = [1,1,1] \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,1,1]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1anums \u4e2d\u7684\u6240\u6709\u5143\u7d20\u5df2\u7ecf\u662f\u76f8\u7b49\u7684\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,1,2,2,3]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u9700\u8981 4 \u6b21\u64cd\u4f5c\u4f7f nums \u4e2d\u7684\u6240\u6709\u5143\u7d20\u76f8\u7b49\uff1a\n1. largest = 3 \u4e0b\u6807\u4e3a 4 \u3002nextLargest = 2 \u3002\u5c06 nums[4] \u51cf\u5c11\u5230 2 \u3002nums = [1,1,2,2,2] \u3002\n2. largest = 2 \u4e0b\u6807\u4e3a 2 \u3002nextLargest = 1 \u3002\u5c06 nums[2] \u51cf\u5c11\u5230 1 \u3002nums = [1,1,1,2,2] \u3002 \n3. largest = 2 \u4e0b\u6807\u4e3a 3 \u3002nextLargest = 1 \u3002\u5c06 nums[3] \u51cf\u5c11\u5230 1 \u3002nums = [1,1,1,1,2] \u3002 \n4. largest = 2 \u4e0b\u6807\u4e3a 4 \u3002nextLargest = 1 \u3002\u5c06 nums[4] \u51cf\u5c11\u5230 1 \u3002nums = [1,1,1,1,1] \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 5 * 104
    • \n\t
    • 1 <= nums[i] <= 5 * 104
    • \n
    \n", "tags_en": ["Greedy", "Sort"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6392\u5e8f"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int reductionOperations(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int reductionOperations(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def reductionOperations(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def reductionOperations(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint reductionOperations(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ReductionOperations(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar reductionOperations = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef reduction_operations(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func reductionOperations(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func reductionOperations(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def reductionOperations(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun reductionOperations(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn reduction_operations(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function reductionOperations($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function reductionOperations(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (reduction-operations nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1887](https://leetcode-cn.com/problems/reduction-operations-to-make-the-array-elements-equal)", "[\u4f7f\u6570\u7ec4\u5143\u7d20\u76f8\u7b49\u7684\u51cf\u5c11\u64cd\u4f5c\u6b21\u6570](/solution/1800-1899/1887.Reduction%20Operations%20to%20Make%20the%20Array%20Elements%20Equal/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6392\u5e8f`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1887](https://leetcode.com/problems/reduction-operations-to-make-the-array-elements-equal)", "[Reduction Operations to Make the Array Elements Equal](/solution/1800-1899/1887.Reduction%20Operations%20to%20Make%20the%20Array%20Elements%20Equal/README_EN.md)", "`Greedy`,`Sort`", "Medium", ""]}, {"question_id": "2015", "frontend_question_id": "1886", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/determine-whether-matrix-can-be-obtained-by-rotation", "url_en": "https://leetcode.com/problems/determine-whether-matrix-can-be-obtained-by-rotation", "relative_path_cn": "/solution/1800-1899/1886.Determine%20Whether%20Matrix%20Can%20Be%20Obtained%20By%20Rotation/README.md", "relative_path_en": "/solution/1800-1899/1886.Determine%20Whether%20Matrix%20Can%20Be%20Obtained%20By%20Rotation/README_EN.md", "title_cn": "\u5224\u65ad\u77e9\u9635\u7ecf\u8f6e\u8f6c\u540e\u662f\u5426\u4e00\u81f4", "title_en": "Determine Whether Matrix Can Be Obtained By Rotation", "question_title_slug": "determine-whether-matrix-can-be-obtained-by-rotation", "content_en": "

    Given two n x n binary matrices mat and target, return true if it is possible to make mat equal to target by rotating mat in 90-degree increments, or false otherwise.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: mat = [[0,1],[1,0]], target = [[1,0],[0,1]]\nOutput: true\nExplanation: We can rotate mat 90 degrees clockwise to make mat equal target.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: mat = [[0,1],[1,1]], target = [[1,0],[0,1]]\nOutput: false\nExplanation: It is impossible to make mat equal to target by rotating mat.\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: mat = [[0,0,0],[0,1,0],[1,1,1]], target = [[1,1,1],[0,1,0],[0,0,0]]\nOutput: true\nExplanation: We can rotate mat 90 degrees clockwise two times to make mat equal target.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == mat.length == target.length
    • \n\t
    • n == mat[i].length == target[i].length
    • \n\t
    • 1 <= n <= 10
    • \n\t
    • mat[i][j] and target[i][j] are either 0 or 1.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u5927\u5c0f\u4e3a n x n \u7684\u4e8c\u8fdb\u5236\u77e9\u9635 mat \u548c target \u3002\u73b0 \u4ee5 90 \u5ea6\u987a\u65f6\u9488\u8f6e\u8f6c \u77e9\u9635 mat \u4e2d\u7684\u5143\u7d20 \u82e5\u5e72\u6b21 \uff0c\u5982\u679c\u80fd\u591f\u4f7f mat \u4e0e\u00a0target \u4e00\u81f4\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1amat = [[0,1],[1,0]], target = [[1,0],[0,1]]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u987a\u65f6\u9488\u8f6e\u8f6c 90 \u5ea6\u4e00\u6b21\u53ef\u4ee5\u4f7f mat \u548c target \u4e00\u81f4\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1amat = [[0,1],[1,1]], target = [[1,0],[0,1]]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u65e0\u6cd5\u901a\u8fc7\u8f6e\u8f6c\u77e9\u9635\u4e2d\u7684\u5143\u7d20\u4f7f equal \u4e0e target \u4e00\u81f4\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1amat = [[0,0,0],[0,1,0],[1,1,1]], target = [[1,1,1],[0,1,0],[0,0,0]]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u987a\u65f6\u9488\u8f6e\u8f6c 90 \u5ea6\u4e24\u6b21\u53ef\u4ee5\u4f7f mat \u548c target \u4e00\u81f4\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == mat.length == target.length
    • \n\t
    • n == mat[i].length == target[i].length
    • \n\t
    • 1 <= n <= 10
    • \n\t
    • mat[i][j] \u548c target[i][j] \u4e0d\u662f 0 \u5c31\u662f 1
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool findRotation(vector>& mat, vector>& target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean findRotation(int[][] mat, int[][] target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findRotation(self, mat, target):\n \"\"\"\n :type mat: List[List[int]]\n :type target: List[List[int]]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findRotation(self, mat: List[List[int]], target: List[List[int]]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool findRotation(int** mat, int matSize, int* matColSize, int** target, int targetSize, int* targetColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool FindRotation(int[][] mat, int[][] target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} mat\n * @param {number[][]} target\n * @return {boolean}\n */\nvar findRotation = function(mat, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} mat\n# @param {Integer[][]} target\n# @return {Boolean}\ndef find_rotation(mat, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findRotation(_ mat: [[Int]], _ target: [[Int]]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findRotation(mat [][]int, target [][]int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findRotation(mat: Array[Array[Int]], target: Array[Array[Int]]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findRotation(mat: Array, target: Array): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_rotation(mat: Vec>, target: Vec>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $mat\n * @param Integer[][] $target\n * @return Boolean\n */\n function findRotation($mat, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findRotation(mat: number[][], target: number[][]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-rotation mat target)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1886](https://leetcode-cn.com/problems/determine-whether-matrix-can-be-obtained-by-rotation)", "[\u5224\u65ad\u77e9\u9635\u7ecf\u8f6e\u8f6c\u540e\u662f\u5426\u4e00\u81f4](/solution/1800-1899/1886.Determine%20Whether%20Matrix%20Can%20Be%20Obtained%20By%20Rotation/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1886](https://leetcode.com/problems/determine-whether-matrix-can-be-obtained-by-rotation)", "[Determine Whether Matrix Can Be Obtained By Rotation](/solution/1800-1899/1886.Determine%20Whether%20Matrix%20Can%20Be%20Obtained%20By%20Rotation/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "2014", "frontend_question_id": "1867", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/orders-with-maximum-quantity-above-average", "url_en": "https://leetcode.com/problems/orders-with-maximum-quantity-above-average", "relative_path_cn": "/solution/1800-1899/1867.Orders%20With%20Maximum%20Quantity%20Above%20Average/README.md", "relative_path_en": "/solution/1800-1899/1867.Orders%20With%20Maximum%20Quantity%20Above%20Average/README_EN.md", "title_cn": "", "title_en": "Orders With Maximum Quantity Above Average", "question_title_slug": "orders-with-maximum-quantity-above-average", "content_en": "

    Table: OrdersDetails

    \n\n
    \n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| order_id    | int  |\n| product_id  | int  |\n| quantity    | int  |\n+-------------+------+\n(order_id, product_id) is the primary key for this table.\nA single order is represented as multiple rows, one row for each product in the order.\nEach row of this table contains the quantity ordered of the product product_id in the order order_id.\n
    \n\n

     

    \n\n

    You are running an ecommerce site that is looking for imbalanced orders. An imbalanced order is one whose maximum quantity is strictly greater than the average quantity of every order (including itself).

    \n\n

    The average quantity of an order is calculated as (total quantity of all products in the order) / (number of different products in the order). The maximum quantity of an order is the highest quantity of any single product in the order.

    \n\n

    Write an SQL query to find the order_id of all imbalanced orders.

    \n\n

    Return the result table in any order.

    \n\n

    The query result format is in the following example:

    \n\n

     

    \n\n
    \nOrdersDetails table:\n+----------+------------+----------+\n| order_id | product_id | quantity |\n+----------+------------+----------+\n| 1        | 1          | 12       |\n| 1        | 2          | 10       |\n| 1        | 3          | 15       |\n| 2        | 1          | 8        |\n| 2        | 4          | 4        |\n| 2        | 5          | 6        |\n| 3        | 3          | 5        |\n| 3        | 4          | 18       |\n| 4        | 5          | 2        |\n| 4        | 6          | 8        |\n| 5        | 7          | 9        |\n| 5        | 8          | 9        |\n| 3        | 9          | 20       |\n| 2        | 9          | 4        |\n+----------+------------+----------+\n\nResult table:\n+----------+\n| order_id |\n+----------+\n| 1        |\n| 3        |\n+----------+\n\nThe average quantity of each order is:\n- order_id=1: (12+10+15)/3 = 12.3333333\n- order_id=2: (8+4+6+4)/4 = 5.5\n- order_id=3: (5+18+20)/3 = 14.333333\n- order_id=4: (2+8)/2 = 5\n- order_id=5: (9+9)/2 = 9\n\nThe maximum quantity of each order is:\n- order_id=1: max(12, 10, 15) = 15\n- order_id=2: max(8, 4, 6, 4) = 8\n- order_id=3: max(5, 18, 20) = 20\n- order_id=4: max(2, 8) = 8\n- order_id=5: max(9, 9) = 9\n\nOrders 1 and 3 are imbalanced because they have a maximum quantity that exceeds the average quantity of every order.\n
    \n", "content_cn": null, "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1867](https://leetcode-cn.com/problems/orders-with-maximum-quantity-above-average)", "[Orders With Maximum Quantity Above Average](/solution/1800-1899/1867.Orders%20With%20Maximum%20Quantity%20Above%20Average/README_EN.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1867](https://leetcode.com/problems/orders-with-maximum-quantity-above-average)", "[Orders With Maximum Quantity Above Average](/solution/1800-1899/1867.Orders%20With%20Maximum%20Quantity%20Above%20Average/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "2013", "frontend_question_id": "1883", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-skips-to-arrive-at-meeting-on-time", "url_en": "https://leetcode.com/problems/minimum-skips-to-arrive-at-meeting-on-time", "relative_path_cn": "/solution/1800-1899/1883.Minimum%20Skips%20to%20Arrive%20at%20Meeting%20On%20Time/README.md", "relative_path_en": "/solution/1800-1899/1883.Minimum%20Skips%20to%20Arrive%20at%20Meeting%20On%20Time/README_EN.md", "title_cn": "\u51c6\u65f6\u62b5\u8fbe\u4f1a\u8bae\u73b0\u573a\u7684\u6700\u5c0f\u8df3\u8fc7\u4f11\u606f\u6b21\u6570", "title_en": "Minimum Skips to Arrive at Meeting On Time", "question_title_slug": "minimum-skips-to-arrive-at-meeting-on-time", "content_en": "

    You are given an integer hoursBefore, the number of hours you have to travel to your meeting. To arrive at your meeting, you have to travel through n roads. The road lengths are given as an integer array dist of length n, where dist[i] describes the length of the ith road in kilometers. In addition, you are given an integer speed, which is the speed (in km/h) you will travel at.

    \n\n

    After you travel road i, you must rest and wait for the next integer hour before you can begin traveling on the next road. Note that you do not have to rest after traveling the last road because you are already at the meeting.

    \n\n
      \n\t
    • For example, if traveling a road takes 1.4 hours, you must wait until the 2 hour mark before traveling the next road. If traveling a road takes exactly 2 hours, you do not need to wait.
    • \n
    \n\n

    However, you are allowed to skip some rests to be able to arrive on time, meaning you do not need to wait for the next integer hour. Note that this means you may finish traveling future roads at different hour marks.

    \n\n
      \n\t
    • For example, suppose traveling the first road takes 1.4 hours and traveling the second road takes 0.6 hours. Skipping the rest after the first road will mean you finish traveling the second road right at the 2 hour mark, letting you start traveling the third road immediately.
    • \n
    \n\n

    Return the minimum number of skips required to arrive at the meeting on time, or -1 if it is impossible.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: dist = [1,3,2], speed = 4, hoursBefore = 2\nOutput: 1\nExplanation:\nWithout skipping any rests, you will arrive in (1/4 + 3/4) + (3/4 + 1/4) + (2/4) = 2.5 hours.\nYou can skip the first rest to arrive in ((1/4 + 0) + (3/4 + 0)) + (2/4) = 1.5 hours.\nNote that the second rest is shortened because you finish traveling the second road at an integer hour due to skipping the first rest.\n
    \n\n

    Example 2:

    \n\n
    \nInput: dist = [7,3,5,5], speed = 2, hoursBefore = 10\nOutput: 2\nExplanation:\nWithout skipping any rests, you will arrive in (7/2 + 1/2) + (3/2 + 1/2) + (5/2 + 1/2) + (5/2) = 11.5 hours.\nYou can skip the first and third rest to arrive in ((7/2 + 0) + (3/2 + 0)) + ((5/2 + 0) + (5/2)) = 10 hours.\n
    \n\n

    Example 3:

    \n\n
    \nInput: dist = [7,3,5,5], speed = 1, hoursBefore = 10\nOutput: -1\nExplanation: It is impossible to arrive at the meeting on time even if you skip all the rests.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == dist.length
    • \n\t
    • 1 <= n <= 1000
    • \n\t
    • 1 <= dist[i] <= 105
    • \n\t
    • 1 <= speed <= 106
    • \n\t
    • 1 <= hoursBefore <= 107
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 hoursBefore \uff0c\u8868\u793a\u4f60\u8981\u524d\u5f80\u4f1a\u8bae\u6240\u5269\u4e0b\u7684\u53ef\u7528\u5c0f\u65f6\u6570\u3002\u8981\u60f3\u6210\u529f\u62b5\u8fbe\u4f1a\u8bae\u73b0\u573a\uff0c\u4f60\u5fc5\u987b\u9014\u7ecf n \u6761\u9053\u8def\u3002\u9053\u8def\u7684\u957f\u5ea6\u7528\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u6574\u6570\u6570\u7ec4 dist \u8868\u793a\uff0c\u5176\u4e2d dist[i] \u8868\u793a\u7b2c i \u6761\u9053\u8def\u7684\u957f\u5ea6\uff08\u5355\u4f4d\uff1a\u5343\u7c73\uff09\u3002\u53e6\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 speed \uff0c\u8868\u793a\u4f60\u5728\u9053\u8def\u4e0a\u524d\u8fdb\u7684\u901f\u5ea6\uff08\u5355\u4f4d\uff1a\u5343\u7c73\u6bcf\u5c0f\u65f6\uff09\u3002

    \n\n

    \u5f53\u4f60\u901a\u8fc7\u7b2c i \u6761\u8def\u4e4b\u540e\uff0c\u5c31\u5fc5\u987b\u4f11\u606f\u5e76\u7b49\u5f85\uff0c\u76f4\u5230 \u4e0b\u4e00\u4e2a\u6574\u6570\u5c0f\u65f6 \u624d\u80fd\u5f00\u59cb\u7ee7\u7eed\u901a\u8fc7\u4e0b\u4e00\u6761\u9053\u8def\u3002\u6ce8\u610f\uff1a\u4f60\u4e0d\u9700\u8981\u5728\u901a\u8fc7\u6700\u540e\u4e00\u6761\u9053\u8def\u540e\u4f11\u606f\uff0c\u56e0\u4e3a\u90a3\u65f6\u4f60\u5df2\u7ecf\u62b5\u8fbe\u4f1a\u8bae\u73b0\u573a\u3002

    \n\n
      \n\t
    • \u4f8b\u5982\uff0c\u5982\u679c\u4f60\u901a\u8fc7\u4e00\u6761\u9053\u8def\u7528\u53bb 1.4 \u5c0f\u65f6\uff0c\u90a3\u4f60\u5fc5\u987b\u505c\u4e0b\u6765\u7b49\u5f85\uff0c\u5230\u00a02 \u5c0f\u65f6\u624d\u53ef\u4ee5\u7ee7\u7eed\u901a\u8fc7\u4e0b\u4e00\u6761\u9053\u8def\u3002\u5982\u679c\u901a\u8fc7\u4e00\u6761\u9053\u8def\u6070\u597d\u7528\u53bb 2 \u5c0f\u65f6\uff0c\u5c31\u65e0\u9700\u7b49\u5f85\uff0c\u53ef\u4ee5\u76f4\u63a5\u7ee7\u7eed\u3002
    • \n
    \n\n

    \u7136\u800c\uff0c\u4e3a\u4e86\u80fd\u51c6\u65f6\u5230\u8fbe\uff0c\u4f60\u53ef\u4ee5\u9009\u62e9 \u8df3\u8fc7 \u4e00\u4e9b\u8def\u7684\u4f11\u606f\u65f6\u95f4\uff0c\u8fd9\u610f\u5473\u7740\u4f60\u4e0d\u5fc5\u7b49\u5f85\u4e0b\u4e00\u4e2a\u6574\u6570\u5c0f\u65f6\u3002\u6ce8\u610f\uff0c\u8fd9\u610f\u5473\u7740\u4e0e\u4e0d\u8df3\u8fc7\u4efb\u4f55\u4f11\u606f\u65f6\u95f4\u76f8\u6bd4\uff0c\u4f60\u53ef\u80fd\u5728\u4e0d\u540c\u65f6\u523b\u5230\u8fbe\u63a5\u4e0b\u6765\u7684\u9053\u8def\u3002

    \n\n
      \n\t
    • \u4f8b\u5982\uff0c\u5047\u8bbe\u901a\u8fc7\u7b2c 1 \u6761\u9053\u8def\u7528\u53bb 1.4 \u5c0f\u65f6\uff0c\u4e14\u901a\u8fc7\u7b2c 2 \u6761\u9053\u8def\u7528\u53bb 0.6 \u5c0f\u65f6\u3002\u8df3\u8fc7\u7b2c 1 \u6761\u9053\u8def\u7684\u4f11\u606f\u65f6\u95f4\u610f\u5473\u7740\u4f60\u5c06\u4f1a\u5728\u6070\u597d\u00a02 \u5c0f\u65f6\u5b8c\u6210\u901a\u8fc7\u7b2c 2 \u6761\u9053\u8def\uff0c\u4e14\u4f60\u80fd\u591f\u7acb\u5373\u5f00\u59cb\u901a\u8fc7\u7b2c 3 \u6761\u9053\u8def\u3002
    • \n
    \n\n

    \u8fd4\u56de\u51c6\u65f6\u62b5\u8fbe\u4f1a\u8bae\u73b0\u573a\u6240\u9700\u8981\u7684 \u6700\u5c0f\u8df3\u8fc7\u6b21\u6570 \uff0c\u5982\u679c \u65e0\u6cd5\u51c6\u65f6\u53c2\u4f1a \uff0c\u8fd4\u56de -1 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1adist = [1,3,2], speed = 4, hoursBefore = 2\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\n\u4e0d\u8df3\u8fc7\u4efb\u4f55\u4f11\u606f\u65f6\u95f4\uff0c\u4f60\u5c06\u7528 (1/4 + 3/4) + (3/4 + 1/4) + (2/4) = 2.5 \u5c0f\u65f6\u624d\u80fd\u62b5\u8fbe\u4f1a\u8bae\u73b0\u573a\u3002\n\u53ef\u4ee5\u8df3\u8fc7\u7b2c 1 \u6b21\u4f11\u606f\u65f6\u95f4\uff0c\u5171\u7528 ((1/4 + 0) + (3/4 + 0)) + (2/4) = 1.5 \u5c0f\u65f6\u62b5\u8fbe\u4f1a\u8bae\u73b0\u573a\u3002\n\u6ce8\u610f\uff0c\u7b2c 2 \u6b21\u4f11\u606f\u65f6\u95f4\u7f29\u77ed\u4e3a 0 \uff0c\u7531\u4e8e\u8df3\u8fc7\u7b2c 1 \u6b21\u4f11\u606f\u65f6\u95f4\uff0c\u4f60\u662f\u5728\u6574\u6570\u5c0f\u65f6\u5904\u5b8c\u6210\u901a\u8fc7\u7b2c 2 \u6761\u9053\u8def\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1adist = [7,3,5,5], speed = 2, hoursBefore = 10\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n\u4e0d\u8df3\u8fc7\u4efb\u4f55\u4f11\u606f\u65f6\u95f4\uff0c\u4f60\u5c06\u7528 (7/2 + 1/2) + (3/2 + 1/2) + (5/2 + 1/2) + (5/2) = 11.5 \u5c0f\u65f6\u624d\u80fd\u62b5\u8fbe\u4f1a\u8bae\u73b0\u573a\u3002\n\u53ef\u4ee5\u8df3\u8fc7\u7b2c 1 \u6b21\u548c\u7b2c 3 \u6b21\u4f11\u606f\u65f6\u95f4\uff0c\u5171\u7528 ((7/2 + 0) + (3/2 + 0)) + ((5/2 + 0) + (5/2)) = 10 \u5c0f\u65f6\u62b5\u8fbe\u4f1a\u8bae\u73b0\u573a\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1adist = [7,3,5,5], speed = 1, hoursBefore = 10\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u5373\u4f7f\u8df3\u8fc7\u6240\u6709\u7684\u4f11\u606f\u65f6\u95f4\uff0c\u4e5f\u65e0\u6cd5\u51c6\u65f6\u53c2\u52a0\u4f1a\u8bae\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == dist.length
    • \n\t
    • 1 <= n <= 1000
    • \n\t
    • 1 <= dist[i] <= 105
    • \n\t
    • 1 <= speed <= 106
    • \n\t
    • 1 <= hoursBefore <= 107
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minSkips(vector& dist, int speed, int hoursBefore) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minSkips(int[] dist, int speed, int hoursBefore) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minSkips(self, dist, speed, hoursBefore):\n \"\"\"\n :type dist: List[int]\n :type speed: int\n :type hoursBefore: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minSkips(self, dist: List[int], speed: int, hoursBefore: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minSkips(int* dist, int distSize, int speed, int hoursBefore){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinSkips(int[] dist, int speed, int hoursBefore) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} dist\n * @param {number} speed\n * @param {number} hoursBefore\n * @return {number}\n */\nvar minSkips = function(dist, speed, hoursBefore) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} dist\n# @param {Integer} speed\n# @param {Integer} hours_before\n# @return {Integer}\ndef min_skips(dist, speed, hours_before)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minSkips(_ dist: [Int], _ speed: Int, _ hoursBefore: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minSkips(dist []int, speed int, hoursBefore int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minSkips(dist: Array[Int], speed: Int, hoursBefore: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minSkips(dist: IntArray, speed: Int, hoursBefore: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_skips(dist: Vec, speed: i32, hours_before: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $dist\n * @param Integer $speed\n * @param Integer $hoursBefore\n * @return Integer\n */\n function minSkips($dist, $speed, $hoursBefore) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minSkips(dist: number[], speed: number, hoursBefore: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-skips dist speed hoursBefore)\n (-> (listof exact-integer?) exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1883](https://leetcode-cn.com/problems/minimum-skips-to-arrive-at-meeting-on-time)", "[\u51c6\u65f6\u62b5\u8fbe\u4f1a\u8bae\u73b0\u573a\u7684\u6700\u5c0f\u8df3\u8fc7\u4f11\u606f\u6b21\u6570](/solution/1800-1899/1883.Minimum%20Skips%20to%20Arrive%20at%20Meeting%20On%20Time/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1883](https://leetcode.com/problems/minimum-skips-to-arrive-at-meeting-on-time)", "[Minimum Skips to Arrive at Meeting On Time](/solution/1800-1899/1883.Minimum%20Skips%20to%20Arrive%20at%20Meeting%20On%20Time/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "2012", "frontend_question_id": "1882", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/process-tasks-using-servers", "url_en": "https://leetcode.com/problems/process-tasks-using-servers", "relative_path_cn": "/solution/1800-1899/1882.Process%20Tasks%20Using%20Servers/README.md", "relative_path_en": "/solution/1800-1899/1882.Process%20Tasks%20Using%20Servers/README_EN.md", "title_cn": "\u4f7f\u7528\u670d\u52a1\u5668\u5904\u7406\u4efb\u52a1", "title_en": "Process Tasks Using Servers", "question_title_slug": "process-tasks-using-servers", "content_en": "

    You are given two 0-indexed integer arrays servers and tasks of lengths n\u200b\u200b\u200b\u200b\u200b\u200b and m\u200b\u200b\u200b\u200b\u200b\u200b respectively. servers[i] is the weight of the i\u200b\u200b\u200b\u200b\u200b\u200bth\u200b\u200b\u200b\u200b server, and tasks[j] is the time needed to process the j\u200b\u200b\u200b\u200b\u200b\u200bth\u200b\u200b\u200b\u200b task in seconds.

    \n\n

    Tasks are assigned to the servers using a task queue. Initially, all servers are free, and the queue is empty.

    \n\n

    At second j, the jth task is inserted into the queue (starting with the 0th task being inserted at second 0). As long as there are free servers and the queue is not empty, the task in the front of the queue will be assigned to a free server with the smallest weight, and in case of a tie, it is assigned to a free server with the smallest index.

    \n\n

    If there are no free servers and the queue is not empty, we wait until a server becomes free and immediately assign the next task. If multiple servers become free at the same time, then multiple tasks from the queue will be assigned in order of insertion following the weight and index priorities above.

    \n\n

    A server that is assigned task j at second t will be free again at second t + tasks[j].

    \n\n

    Build an array ans\u200b\u200b\u200b\u200b of length m, where ans[j] is the index of the server the j\u200b\u200b\u200b\u200b\u200b\u200bth task will be assigned to.

    \n\n

    Return the array ans\u200b\u200b\u200b\u200b.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: servers = [3,3,2], tasks = [1,2,3,2,1,2]\nOutput: [2,2,0,2,1,2]\nExplanation: Events in chronological order go as follows:\n- At second 0, task 0 is added and processed using server 2 until second 1.\n- At second 1, server 2 becomes free. Task 1 is added and processed using server 2 until second 3.\n- At second 2, task 2 is added and processed using server 0 until second 5.\n- At second 3, server 2 becomes free. Task 3 is added and processed using server 2 until second 5.\n- At second 4, task 4 is added and processed using server 1 until second 5.\n- At second 5, all servers become free. Task 5 is added and processed using server 2 until second 7.
    \n\n

    Example 2:

    \n\n
    \nInput: servers = [5,1,4,3,2], tasks = [2,1,2,4,5,2,1]\nOutput: [1,4,1,4,1,3,2]\nExplanation: Events in chronological order go as follows: \n- At second 0, task 0 is added and processed using server 1 until second 2.\n- At second 1, task 1 is added and processed using server 4 until second 2.\n- At second 2, servers 1 and 4 become free. Task 2 is added and processed using server 1 until second 4. \n- At second 3, task 3 is added and processed using server 4 until second 7.\n- At second 4, server 1 becomes free. Task 4 is added and processed using server 1 until second 9. \n- At second 5, task 5 is added and processed using server 3 until second 7.\n- At second 6, task 6 is added and processed using server 2 until second 7.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • servers.length == n
    • \n\t
    • tasks.length == m
    • \n\t
    • 1 <= n, m <= 2 * 105
    • \n\t
    • 1 <= servers[i], tasks[j] <= 2 * 105
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a \u4e0b\u6807\u4ece 0 \u5f00\u59cb \u7684\u6574\u6570\u6570\u7ec4 servers \u548c tasks \uff0c\u957f\u5ea6\u5206\u522b\u4e3a n\u200b\u200b\u200b\u200b\u200b\u200b \u548c m\u200b\u200b\u200b\u200b\u200b\u200b \u3002servers[i] \u662f\u7b2c i\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b \u53f0\u670d\u52a1\u5668\u7684 \u6743\u91cd \uff0c\u800c tasks[j] \u662f\u5904\u7406\u7b2c j\u200b\u200b\u200b\u200b\u200b\u200b \u9879\u4efb\u52a1 \u6240\u9700\u8981\u7684\u65f6\u95f4\uff08\u5355\u4f4d\uff1a\u79d2\uff09\u3002

    \n\n

    \u4f60\u6b63\u5728\u8fd0\u884c\u4e00\u4e2a\u4eff\u771f\u7cfb\u7edf\uff0c\u5728\u5904\u7406\u5b8c\u6240\u6709\u4efb\u52a1\u540e\uff0c\u8be5\u7cfb\u7edf\u5c06\u4f1a\u5173\u95ed\u3002\u6bcf\u53f0\u670d\u52a1\u5668\u53ea\u80fd\u540c\u65f6\u5904\u7406\u4e00\u9879\u4efb\u52a1\u3002\u7b2c 0 \u9879\u4efb\u52a1\u5728\u7b2c 0 \u79d2\u53ef\u4ee5\u5f00\u59cb\u5904\u7406\uff0c\u76f8\u5e94\u5730\uff0c\u7b2c j \u9879\u4efb\u52a1\u5728\u7b2c j\u00a0\u79d2\u53ef\u4ee5\u5f00\u59cb\u5904\u7406\u3002\u5904\u7406\u7b2c j \u9879\u4efb\u52a1\u65f6\uff0c\u4f60\u9700\u8981\u4e3a\u5b83\u5206\u914d\u4e00\u53f0 \u6743\u91cd\u6700\u5c0f \u7684\u7a7a\u95f2\u670d\u52a1\u5668\u3002\u5982\u679c\u5b58\u5728\u591a\u53f0\u76f8\u540c\u6743\u91cd\u7684\u7a7a\u95f2\u670d\u52a1\u5668\uff0c\u8bf7\u9009\u62e9 \u4e0b\u6807\u6700\u5c0f \u7684\u670d\u52a1\u5668\u3002\u5982\u679c\u4e00\u53f0\u7a7a\u95f2\u670d\u52a1\u5668\u5728\u7b2c t \u79d2\u5206\u914d\u5230\u7b2c j \u9879\u4efb\u52a1\uff0c\u90a3\u4e48\u5728 t + tasks[j] \u65f6\u5b83\u5c06\u6062\u590d\u7a7a\u95f2\u72b6\u6001\u3002

    \n\n

    \u5982\u679c\u6ca1\u6709\u7a7a\u95f2\u670d\u52a1\u5668\uff0c\u5219\u5fc5\u987b\u7b49\u5f85\uff0c\u76f4\u5230\u51fa\u73b0\u4e00\u53f0\u7a7a\u95f2\u670d\u52a1\u5668\uff0c\u5e76 \u5c3d\u53ef\u80fd\u65e9\u00a0\u5730\u5904\u7406\u5269\u4f59\u4efb\u52a1\u3002 \u5982\u679c\u6709\u591a\u9879\u4efb\u52a1\u7b49\u5f85\u5206\u914d\uff0c\u5219\u6309\u7167 \u4e0b\u6807\u9012\u589e \u7684\u987a\u5e8f\u5b8c\u6210\u5206\u914d\u3002

    \n\n

    \u5982\u679c\u540c\u4e00\u65f6\u523b\u5b58\u5728\u591a\u53f0\u7a7a\u95f2\u670d\u52a1\u5668\uff0c\u53ef\u4ee5\u540c\u65f6\u5c06\u591a\u9879\u4efb\u52a1\u5206\u522b\u5206\u914d\u7ed9\u5b83\u4eec\u3002

    \n\n

    \u6784\u5efa\u957f\u5ea6\u4e3a\u00a0m \u7684\u7b54\u6848\u6570\u7ec4 ans \uff0c\u5176\u4e2d ans[j] \u662f\u7b2c j \u9879\u4efb\u52a1\u5206\u914d\u7684\u670d\u52a1\u5668\u7684\u4e0b\u6807\u3002

    \n\n

    \u8fd4\u56de\u7b54\u6848\u6570\u7ec4 ans\u200b\u200b\u200b\u200b \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aservers = [3,3,2], tasks = [1,2,3,2,1,2]\n\u8f93\u51fa\uff1a[2,2,0,2,1,2]\n\u89e3\u91ca\uff1a\u4e8b\u4ef6\u6309\u65f6\u95f4\u987a\u5e8f\u5982\u4e0b\uff1a\n- 0 \u79d2\u65f6\uff0c\u7b2c 0 \u9879\u4efb\u52a1\u52a0\u5165\u5230\u4efb\u52a1\u961f\u5217\uff0c\u4f7f\u7528\u7b2c 2 \u53f0\u670d\u52a1\u5668\u5904\u7406\u5230 1 \u79d2\u3002\n- 1 \u79d2\u65f6\uff0c\u7b2c 2 \u53f0\u670d\u52a1\u5668\u7a7a\u95f2\uff0c\u7b2c 1 \u9879\u4efb\u52a1\u52a0\u5165\u5230\u4efb\u52a1\u961f\u5217\uff0c\u4f7f\u7528\u7b2c 2 \u53f0\u670d\u52a1\u5668\u5904\u7406\u5230 3 \u79d2\u3002\n- 2 \u79d2\u65f6\uff0c\u7b2c 2 \u9879\u4efb\u52a1\u52a0\u5165\u5230\u4efb\u52a1\u961f\u5217\uff0c\u4f7f\u7528\u7b2c 0 \u53f0\u670d\u52a1\u5668\u5904\u7406\u5230 5 \u79d2\u3002\n- 3 \u79d2\u65f6\uff0c\u7b2c 2 \u53f0\u670d\u52a1\u5668\u7a7a\u95f2\uff0c\u7b2c 3 \u9879\u4efb\u52a1\u52a0\u5165\u5230\u4efb\u52a1\u961f\u5217\uff0c\u4f7f\u7528\u7b2c 2 \u53f0\u670d\u52a1\u5668\u5904\u7406\u5230 5 \u79d2\u3002\n- 4 \u79d2\u65f6\uff0c\u7b2c 4 \u9879\u4efb\u52a1\u52a0\u5165\u5230\u4efb\u52a1\u961f\u5217\uff0c\u4f7f\u7528\u7b2c 1 \u53f0\u670d\u52a1\u5668\u5904\u7406\u5230 5 \u79d2\u3002\n- 5 \u79d2\u65f6\uff0c\u6240\u6709\u670d\u52a1\u5668\u90fd\u7a7a\u95f2\uff0c\u7b2c 5 \u9879\u4efb\u52a1\u52a0\u5165\u5230\u4efb\u52a1\u961f\u5217\uff0c\u4f7f\u7528\u7b2c 2 \u53f0\u670d\u52a1\u5668\u5904\u7406\u5230 7 \u79d2\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aservers = [5,1,4,3,2], tasks = [2,1,2,4,5,2,1]\n\u8f93\u51fa\uff1a[1,4,1,4,1,3,2]\n\u89e3\u91ca\uff1a\u4e8b\u4ef6\u6309\u65f6\u95f4\u987a\u5e8f\u5982\u4e0b\uff1a\n- 0 \u79d2\u65f6\uff0c\u7b2c 0 \u9879\u4efb\u52a1\u52a0\u5165\u5230\u4efb\u52a1\u961f\u5217\uff0c\u4f7f\u7528\u7b2c 1 \u53f0\u670d\u52a1\u5668\u5904\u7406\u5230 2 \u79d2\u3002\n- 1 \u79d2\u65f6\uff0c\u7b2c 1 \u9879\u4efb\u52a1\u52a0\u5165\u5230\u4efb\u52a1\u961f\u5217\uff0c\u4f7f\u7528\u7b2c 4 \u53f0\u670d\u52a1\u5668\u5904\u7406\u5230 2 \u79d2\u3002\n- 2 \u79d2\u65f6\uff0c\u7b2c 1 \u53f0\u548c\u7b2c 4 \u53f0\u670d\u52a1\u5668\u7a7a\u95f2\uff0c\u7b2c 2 \u9879\u4efb\u52a1\u52a0\u5165\u5230\u4efb\u52a1\u961f\u5217\uff0c\u4f7f\u7528\u7b2c 1 \u53f0\u670d\u52a1\u5668\u5904\u7406\u5230 4 \u79d2\u3002\n- 3 \u79d2\u65f6\uff0c\u7b2c 3 \u9879\u4efb\u52a1\u52a0\u5165\u5230\u4efb\u52a1\u961f\u5217\uff0c\u4f7f\u7528\u7b2c 4 \u53f0\u670d\u52a1\u5668\u5904\u7406\u5230 7 \u79d2\u3002\n- 4 \u79d2\u65f6\uff0c\u7b2c 1 \u53f0\u670d\u52a1\u5668\u7a7a\u95f2\uff0c\u7b2c 4 \u9879\u4efb\u52a1\u52a0\u5165\u5230\u4efb\u52a1\u961f\u5217\uff0c\u4f7f\u7528\u7b2c 1 \u53f0\u670d\u52a1\u5668\u5904\u7406\u5230 9 \u79d2\u3002\n- 5 \u79d2\u65f6\uff0c\u7b2c 5 \u9879\u4efb\u52a1\u52a0\u5165\u5230\u4efb\u52a1\u961f\u5217\uff0c\u4f7f\u7528\u7b2c 3 \u53f0\u670d\u52a1\u5668\u5904\u7406\u5230 7 \u79d2\u3002\n- 6 \u79d2\u65f6\uff0c\u7b2c 6 \u9879\u4efb\u52a1\u52a0\u5165\u5230\u4efb\u52a1\u961f\u5217\uff0c\u4f7f\u7528\u7b2c 2 \u53f0\u670d\u52a1\u5668\u5904\u7406\u5230 7 \u79d2\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • servers.length == n
    • \n\t
    • tasks.length == m
    • \n\t
    • 1 <= n, m <= 2 * 105
    • \n\t
    • 1 <= servers[i], tasks[j] <= 2 * 105
    • \n
    \n", "tags_en": ["Heap"], "tags_cn": ["\u5806"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector assignTasks(vector& servers, vector& tasks) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] assignTasks(int[] servers, int[] tasks) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def assignTasks(self, servers, tasks):\n \"\"\"\n :type servers: List[int]\n :type tasks: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def assignTasks(self, servers: List[int], tasks: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* assignTasks(int* servers, int serversSize, int* tasks, int tasksSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] AssignTasks(int[] servers, int[] tasks) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} servers\n * @param {number[]} tasks\n * @return {number[]}\n */\nvar assignTasks = function(servers, tasks) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} servers\n# @param {Integer[]} tasks\n# @return {Integer[]}\ndef assign_tasks(servers, tasks)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func assignTasks(_ servers: [Int], _ tasks: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func assignTasks(servers []int, tasks []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def assignTasks(servers: Array[Int], tasks: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun assignTasks(servers: IntArray, tasks: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn assign_tasks(servers: Vec, tasks: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $servers\n * @param Integer[] $tasks\n * @return Integer[]\n */\n function assignTasks($servers, $tasks) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function assignTasks(servers: number[], tasks: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (assign-tasks servers tasks)\n (-> (listof exact-integer?) (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1882](https://leetcode-cn.com/problems/process-tasks-using-servers)", "[\u4f7f\u7528\u670d\u52a1\u5668\u5904\u7406\u4efb\u52a1](/solution/1800-1899/1882.Process%20Tasks%20Using%20Servers/README.md)", "`\u5806`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1882](https://leetcode.com/problems/process-tasks-using-servers)", "[Process Tasks Using Servers](/solution/1800-1899/1882.Process%20Tasks%20Using%20Servers/README_EN.md)", "`Heap`", "Medium", ""]}, {"question_id": "2011", "frontend_question_id": "1881", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-value-after-insertion", "url_en": "https://leetcode.com/problems/maximum-value-after-insertion", "relative_path_cn": "/solution/1800-1899/1881.Maximum%20Value%20after%20Insertion/README.md", "relative_path_en": "/solution/1800-1899/1881.Maximum%20Value%20after%20Insertion/README_EN.md", "title_cn": "\u63d2\u5165\u540e\u7684\u6700\u5927\u503c", "title_en": "Maximum Value after Insertion", "question_title_slug": "maximum-value-after-insertion", "content_en": "

    You are given a very large integer n, represented as a string,\u200b\u200b\u200b\u200b\u200b\u200b and an integer digit x. The digits in n and the digit x are in the inclusive range [1, 9], and n may represent a negative number.

    \n\n

    You want to maximize n's numerical value by inserting x anywhere in the decimal representation of n\u200b\u200b\u200b\u200b\u200b\u200b. You cannot insert x to the left of the negative sign.

    \n\n
      \n\t
    • For example, if n = 73 and x = 6, it would be best to insert it between 7 and 3, making n = 763.
    • \n\t
    • If n = -55 and x = 2, it would be best to insert it before the first 5, making n = -255.
    • \n
    \n\n

    Return a string representing the maximum value of n\u200b\u200b\u200b\u200b\u200b\u200b after the insertion.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = "99", x = 9\nOutput: "999"\nExplanation: The result is the same regardless of where you insert 9.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = "-13", x = 2\nOutput: "-123"\nExplanation: You can make n one of {-213, -123, -132}, and the largest of those three is -123.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n.length <= 105
    • \n\t
    • 1 <= x <= 9
    • \n\t
    • The digits in n\u200b\u200b\u200b are in the range [1, 9].
    • \n\t
    • n is a valid representation of an integer.
    • \n\t
    • In the case of a negative n,\u200b\u200b\u200b\u200b\u200b\u200b it will begin with '-'.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u975e\u5e38\u5927\u7684\u6574\u6570 n \u548c\u4e00\u4e2a\u6574\u6570\u6570\u5b57 x \uff0c\u5927\u6574\u6570 n\u00a0\u7528\u4e00\u4e2a\u5b57\u7b26\u4e32\u8868\u793a\u3002n \u4e2d\u6bcf\u4e00\u4f4d\u6570\u5b57\u548c\u6570\u5b57 x \u90fd\u5904\u4e8e\u95ed\u533a\u95f4 [1, 9] \u4e2d\uff0c\u4e14 n \u53ef\u80fd\u8868\u793a\u4e00\u4e2a \u8d1f\u6570 \u3002

    \n\n

    \u4f60\u6253\u7b97\u901a\u8fc7\u5728 n \u7684\u5341\u8fdb\u5236\u8868\u793a\u7684\u4efb\u610f\u4f4d\u7f6e\u63d2\u5165 x \u6765 \u6700\u5927\u5316 n \u7684 \u6570\u503c \u200b\u200b\u200b\u200b\u200b\u200b\u3002\u4f46 \u4e0d\u80fd \u5728\u8d1f\u53f7\u7684\u5de6\u8fb9\u63d2\u5165 x \u3002

    \n\n
      \n\t
    • \u4f8b\u5982\uff0c\u5982\u679c n = 73 \u4e14 x = 6 \uff0c\u90a3\u4e48\u6700\u4f73\u65b9\u6848\u662f\u5c06 6 \u63d2\u5165 7 \u548c 3 \u4e4b\u95f4\uff0c\u4f7f n = 763 \u3002
    • \n\t
    • \u5982\u679c n = -55 \u4e14 x = 2 \uff0c\u90a3\u4e48\u6700\u4f73\u65b9\u6848\u662f\u5c06 2 \u63d2\u5728\u7b2c\u4e00\u4e2a 5 \u4e4b\u524d\uff0c\u4f7f n = -255 \u3002
    • \n
    \n\n

    \u8fd4\u56de\u63d2\u5165\u64cd\u4f5c\u540e\uff0c\u7528\u5b57\u7b26\u4e32\u8868\u793a\u7684\u00a0n \u7684\u6700\u5927\u503c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = \"99\", x = 9\n\u8f93\u51fa\uff1a\"999\"\n\u89e3\u91ca\uff1a\u4e0d\u7ba1\u5728\u54ea\u91cc\u63d2\u5165 9 \uff0c\u7ed3\u679c\u90fd\u662f\u76f8\u540c\u7684\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = \"-13\", x = 2\n\u8f93\u51fa\uff1a\"-123\"\n\u89e3\u91ca\uff1a\u5411 n \u4e2d\u63d2\u5165 x \u53ef\u4ee5\u5f97\u5230 -213\u3001-123 \u6216\u8005 -132 \uff0c\u4e09\u8005\u4e2d\u6700\u5927\u7684\u662f -123 \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n.length <= 105
    • \n\t
    • 1 <= x <= 9
    • \n\t
    • n\u200b\u200b\u200b \u4e2d\u6bcf\u4e00\u4f4d\u7684\u6570\u5b57\u90fd\u5728\u95ed\u533a\u95f4 [1, 9] \u4e2d\u3002
    • \n\t
    • n\u00a0\u4ee3\u8868\u4e00\u4e2a\u6709\u6548\u7684\u6574\u6570\u3002
    • \n\t
    • \u5f53 n \u8868\u793a\u8d1f\u6570\u65f6\uff0c\u5c06\u4f1a\u4ee5\u5b57\u7b26 '-' \u5f00\u59cb\u3002
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string maxValue(string n, int x) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String maxValue(String n, int x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxValue(self, n, x):\n \"\"\"\n :type n: str\n :type x: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxValue(self, n: str, x: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * maxValue(char * n, int x){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string MaxValue(string n, int x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} n\n * @param {number} x\n * @return {string}\n */\nvar maxValue = function(n, x) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} n\n# @param {Integer} x\n# @return {String}\ndef max_value(n, x)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxValue(_ n: String, _ x: Int) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxValue(n string, x int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxValue(n: String, x: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxValue(n: String, x: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_value(n: String, x: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $n\n * @param Integer $x\n * @return String\n */\n function maxValue($n, $x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxValue(n: string, x: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-value n x)\n (-> string? exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1881](https://leetcode-cn.com/problems/maximum-value-after-insertion)", "[\u63d2\u5165\u540e\u7684\u6700\u5927\u503c](/solution/1800-1899/1881.Maximum%20Value%20after%20Insertion/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1881](https://leetcode.com/problems/maximum-value-after-insertion)", "[Maximum Value after Insertion](/solution/1800-1899/1881.Maximum%20Value%20after%20Insertion/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "2010", "frontend_question_id": "1880", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/check-if-word-equals-summation-of-two-words", "url_en": "https://leetcode.com/problems/check-if-word-equals-summation-of-two-words", "relative_path_cn": "/solution/1800-1899/1880.Check%20if%20Word%20Equals%20Summation%20of%20Two%20Words/README.md", "relative_path_en": "/solution/1800-1899/1880.Check%20if%20Word%20Equals%20Summation%20of%20Two%20Words/README_EN.md", "title_cn": "\u68c0\u67e5\u67d0\u5355\u8bcd\u662f\u5426\u7b49\u4e8e\u4e24\u5355\u8bcd\u4e4b\u548c", "title_en": "Check if Word Equals Summation of Two Words", "question_title_slug": "check-if-word-equals-summation-of-two-words", "content_en": "

    The letter value of a letter is its position in the alphabet starting from 0 (i.e. 'a' -> 0, 'b' -> 1, 'c' -> 2, etc.).

    \n\n

    The numerical value of some string of lowercase English letters s is the concatenation of the letter values of each letter in s, which is then converted into an integer.

    \n\n
      \n\t
    • For example, if s = "acb", we concatenate each letter's letter value, resulting in "021". After converting it, we get 21.
    • \n
    \n\n

    You are given three strings firstWord, secondWord, and targetWord, each consisting of lowercase English letters 'a' through 'j' inclusive.

    \n\n

    Return true if the summation of the numerical values of firstWord and secondWord equals the numerical value of targetWord, or false otherwise.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: firstWord = "acb", secondWord = "cba", targetWord = "cdb"\nOutput: true\nExplanation:\nThe numerical value of firstWord is "acb" -> "021" -> 21.\nThe numerical value of secondWord is "cba" -> "210" -> 210.\nThe numerical value of targetWord is "cdb" -> "231" -> 231.\nWe return true because 21 + 210 == 231.\n
    \n\n

    Example 2:

    \n\n
    \nInput: firstWord = "aaa", secondWord = "a", targetWord = "aab"\nOutput: false\nExplanation: \nThe numerical value of firstWord is "aaa" -> "000" -> 0.\nThe numerical value of secondWord is "a" -> "0" -> 0.\nThe numerical value of targetWord is "aab" -> "001" -> 1.\nWe return false because 0 + 0 != 1.\n
    \n\n

    Example 3:

    \n\n
    \nInput: firstWord = "aaa", secondWord = "a", targetWord = "aaaa"\nOutput: true\nExplanation: \nThe numerical value of firstWord is "aaa" -> "000" -> 0.\nThe numerical value of secondWord is "a" -> "0" -> 0.\nThe numerical value of targetWord is "aaaa" -> "0000" -> 0.\nWe return true because 0 + 0 == 0.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= firstWord.length, secondWord.length, targetWord.length <= 8
    • \n\t
    • firstWord, secondWord, and targetWord consist of lowercase English letters from 'a' to 'j' inclusive.
    • \n
    \n", "content_cn": "

    \u5b57\u6bcd\u7684 \u5b57\u6bcd\u503c \u53d6\u51b3\u4e8e\u5b57\u6bcd\u5728\u5b57\u6bcd\u8868\u4e2d\u7684\u4f4d\u7f6e\uff0c\u4ece 0 \u5f00\u59cb \u8ba1\u6570\u3002\u5373\uff0c'a' -> 0\u3001'b' -> 1\u3001'c' -> 2\uff0c\u4ee5\u6b64\u7c7b\u63a8\u3002

    \n\n

    \u5bf9\u67d0\u4e2a\u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210\u7684\u5b57\u7b26\u4e32\u00a0s \u800c\u8a00\uff0c\u5176 \u6570\u503c \u5c31\u7b49\u4e8e\u5c06 s \u4e2d\u6bcf\u4e2a\u5b57\u6bcd\u7684 \u5b57\u6bcd\u503c \u6309\u987a\u5e8f \u8fde\u63a5 \u5e76 \u8f6c\u6362 \u6210\u5bf9\u5e94\u6574\u6570\u3002

    \n\n
      \n\t
    • \u4f8b\u5982\uff0cs = \"acb\" \uff0c\u4f9d\u6b21\u8fde\u63a5\u6bcf\u4e2a\u5b57\u6bcd\u7684\u5b57\u6bcd\u503c\u53ef\u4ee5\u5f97\u5230 \"021\" \uff0c\u8f6c\u6362\u4e3a\u6574\u6570\u5f97\u5230 21 \u3002
    • \n
    \n\n

    \u7ed9\u4f60\u4e09\u4e2a\u5b57\u7b26\u4e32 firstWord\u3001secondWord \u548c targetWord \uff0c\u6bcf\u4e2a\u5b57\u7b26\u4e32\u90fd\u7531\u4ece 'a' \u5230 'j' \uff08\u542b\u00a0'a' \u548c 'j' \uff09\u7684\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\u3002

    \n\n

    \u5982\u679c\u00a0firstWord \u548c secondWord \u7684 \u6570\u503c\u4e4b\u548c \u7b49\u4e8e targetWord \u7684\u6570\u503c\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1afirstWord = \"acb\", secondWord = \"cba\", targetWord = \"cdb\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\nfirstWord \u7684\u6570\u503c\u4e3a \"acb\" -> \"021\" -> 21\nsecondWord \u7684\u6570\u503c\u4e3a \"cba\" -> \"210\" -> 210\ntargetWord \u7684\u6570\u503c\u4e3a \"cdb\" -> \"231\" -> 231\n\u7531\u4e8e 21 + 210 == 231 \uff0c\u8fd4\u56de true\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1afirstWord = \"aaa\", secondWord = \"a\", targetWord = \"aab\"\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\nfirstWord \u7684\u6570\u503c\u4e3a \"aaa\" -> \"000\" -> 0\nsecondWord \u7684\u6570\u503c\u4e3a \"a\" -> \"0\" -> 0\ntargetWord \u7684\u6570\u503c\u4e3a \"aab\" -> \"001\" -> 1\n\u7531\u4e8e 0 + 0 != 1 \uff0c\u8fd4\u56de false
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1afirstWord = \"aaa\", secondWord = \"a\", targetWord = \"aaaa\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\nfirstWord \u7684\u6570\u503c\u4e3a \"aaa\" -> \"000\" -> 0\nsecondWord \u7684\u6570\u503c\u4e3a \"a\" -> \"0\" -> 0\ntargetWord \u7684\u6570\u503c\u4e3a \"aaaa\" -> \"0000\" -> 0\n\u7531\u4e8e 0 + 0 == 0 \uff0c\u8fd4\u56de true\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= firstWord.length, secondWord.length, targetWord.length <= 8
    • \n\t
    • firstWord\u3001secondWord \u548c targetWord \u4ec5\u7531\u4ece 'a' \u5230 'j' \uff08\u542b\u00a0'a' \u548c 'j' \uff09\u7684\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\u3002
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isSumEqual(string firstWord, string secondWord, string targetWord) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isSumEqual(String firstWord, String secondWord, String targetWord) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isSumEqual(self, firstWord, secondWord, targetWord):\n \"\"\"\n :type firstWord: str\n :type secondWord: str\n :type targetWord: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isSumEqual(char * firstWord, char * secondWord, char * targetWord){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsSumEqual(string firstWord, string secondWord, string targetWord) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} firstWord\n * @param {string} secondWord\n * @param {string} targetWord\n * @return {boolean}\n */\nvar isSumEqual = function(firstWord, secondWord, targetWord) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} first_word\n# @param {String} second_word\n# @param {String} target_word\n# @return {Boolean}\ndef is_sum_equal(first_word, second_word, target_word)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isSumEqual(_ firstWord: String, _ secondWord: String, _ targetWord: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isSumEqual(firstWord string, secondWord string, targetWord string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isSumEqual(firstWord: String, secondWord: String, targetWord: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isSumEqual(firstWord: String, secondWord: String, targetWord: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_sum_equal(first_word: String, second_word: String, target_word: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $firstWord\n * @param String $secondWord\n * @param String $targetWord\n * @return Boolean\n */\n function isSumEqual($firstWord, $secondWord, $targetWord) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isSumEqual(firstWord: string, secondWord: string, targetWord: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-sum-equal firstWord secondWord targetWord)\n (-> string? string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1880](https://leetcode-cn.com/problems/check-if-word-equals-summation-of-two-words)", "[\u68c0\u67e5\u67d0\u5355\u8bcd\u662f\u5426\u7b49\u4e8e\u4e24\u5355\u8bcd\u4e4b\u548c](/solution/1800-1899/1880.Check%20if%20Word%20Equals%20Summation%20of%20Two%20Words/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1880](https://leetcode.com/problems/check-if-word-equals-summation-of-two-words)", "[Check if Word Equals Summation of Two Words](/solution/1800-1899/1880.Check%20if%20Word%20Equals%20Summation%20of%20Two%20Words/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "2009", "frontend_question_id": "1858", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/longest-word-with-all-prefixes", "url_en": "https://leetcode.com/problems/longest-word-with-all-prefixes", "relative_path_cn": "/solution/1800-1899/1858.Longest%20Word%20With%20All%20Prefixes/README.md", "relative_path_en": "/solution/1800-1899/1858.Longest%20Word%20With%20All%20Prefixes/README_EN.md", "title_cn": "", "title_en": "Longest Word With All Prefixes", "question_title_slug": "longest-word-with-all-prefixes", "content_en": "

    Given an array of strings words, find the longest string in words such that every prefix of it is also in words.

    \r\n\r\n
      \r\n\t
    • For example, let words = ["a", "app", "ap"]. The string "app" has prefixes "ap" and "a", all of which are in words.
    • \r\n
    \r\n\r\n

    Return the string described above. If there is more than one string with the same length, return the lexicographically smallest one, and if no string exists, return "".

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: words = ["k","ki","kir","kira", "kiran"]\r\nOutput: "kiran"\r\nExplanation: "kiran" has prefixes "kira", "kir", "ki", and "k", and all of them appear in words.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: words = ["a", "banana", "app", "appl", "ap", "apply", "apple"]\r\nOutput: "apple"\r\nExplanation: Both "apple" and "apply" have all their prefixes in words.\r\nHowever, "apple" is lexicographically smaller, so we return that.\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: words = ["abc", "bc", "ab", "qwe"]\r\nOutput: ""\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= words.length <= 105
    • \r\n\t
    • 1 <= words[i].length <= 105
    • \r\n\t
    • 1 <= sum(words[i].length) <= 105
    • \r\n
    ", "content_cn": null, "tags_en": ["Depth-first Search", "Trie", "Hash Table"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5b57\u5178\u6811", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string longestWord(vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String longestWord(String[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestWord(self, words):\n \"\"\"\n :type words: List[str]\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestWord(self, words: List[str]) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * longestWord(char ** words, int wordsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string LongestWord(string[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @return {string}\n */\nvar longestWord = function(words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @return {String}\ndef longest_word(words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestWord(_ words: [String]) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestWord(words []string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestWord(words: Array[String]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestWord(words: Array): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_word(words: Vec) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @return String\n */\n function longestWord($words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestWord(words: string[]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-word words)\n (-> (listof string?) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1858](https://leetcode-cn.com/problems/longest-word-with-all-prefixes)", "[Longest Word With All Prefixes](/solution/1800-1899/1858.Longest%20Word%20With%20All%20Prefixes/README_EN.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5b57\u5178\u6811`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1858](https://leetcode.com/problems/longest-word-with-all-prefixes)", "[Longest Word With All Prefixes](/solution/1800-1899/1858.Longest%20Word%20With%20All%20Prefixes/README_EN.md)", "`Depth-first Search`,`Trie`,`Hash Table`", "Medium", "\ud83d\udd12"]}, {"question_id": "2004", "frontend_question_id": "1853", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/convert-date-format", "url_en": "https://leetcode.com/problems/convert-date-format", "relative_path_cn": "/solution/1800-1899/1853.Convert%20Date%20Format/README.md", "relative_path_en": "/solution/1800-1899/1853.Convert%20Date%20Format/README_EN.md", "title_cn": "", "title_en": "Convert Date Format", "question_title_slug": "convert-date-format", "content_en": "

    Table: Days

    \n\n
    \n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| day         | date |\n+-------------+------+\nday is the primary key for this table.\n
    \n\n

     

    \n\n

    Write an SQL query to convert each date in Days into a string formatted as "day_name, month_name day, year".

    \n\n

    Return the result table in any order.

    \n\n

    The query result format is in the following example:

    \n\n

     

    \n\n
    \nDays table:\n+------------+\n| day        |\n+------------+\n| 2022-04-12 |\n| 2021-08-09 |\n| 2020-06-26 |\n+------------+\n\nResult table:\n+-------------------------+\n| day                     |\n+-------------------------+\n| Tuesday, April 12, 2022 |\n| Monday, August 9, 2021  |\n| Friday, June 26, 2020   |\n+-------------------------+\nPlease note that the output is case-sensitive.\n
    \n", "content_cn": null, "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1853](https://leetcode-cn.com/problems/convert-date-format)", "[Convert Date Format](/solution/1800-1899/1853.Convert%20Date%20Format/README_EN.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1853](https://leetcode.com/problems/convert-date-format)", "[Convert Date Format](/solution/1800-1899/1853.Convert%20Date%20Format/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "2003", "frontend_question_id": "1852", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/distinct-numbers-in-each-subarray", "url_en": "https://leetcode.com/problems/distinct-numbers-in-each-subarray", "relative_path_cn": "/solution/1800-1899/1852.Distinct%20Numbers%20in%20Each%20Subarray/README.md", "relative_path_en": "/solution/1800-1899/1852.Distinct%20Numbers%20in%20Each%20Subarray/README_EN.md", "title_cn": "", "title_en": "Distinct Numbers in Each Subarray", "question_title_slug": "distinct-numbers-in-each-subarray", "content_en": "

    Given an integer array nums and an integer k, you are asked to construct the array ans of size n-k+1 where ans[i] is the number of distinct numbers in the subarray nums[i:i+k-1] = [nums[i], nums[i+1], ..., nums[i+k-1]].

    \r\n\r\n

    Return the array ans.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: nums = [1,2,3,2,2,1,3], k = 3\r\nOutput: [3,2,2,2,3]\r\nExplanation: The number of distinct elements in each subarray goes as follows:\r\n- nums[0:2] = [1,2,3] so ans[0] = 3\r\n- nums[1:3] = [2,3,2] so ans[1] = 2\r\n- nums[2:4] = [3,2,2] so ans[2] = 2\r\n- nums[3:5] = [2,2,1] so ans[3] = 2\r\n- nums[4:6] = [2,1,3] so ans[4] = 3\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: nums = [1,1,1,1,2,3,4], k = 4\r\nOutput: [1,2,3,4]\r\nExplanation: The number of distinct elements in each subarray goes as follows:\r\n- nums[0:3] = [1,1,1,1] so ans[0] = 1\r\n- nums[1:4] = [1,1,1,2] so ans[1] = 2\r\n- nums[2:5] = [1,1,2,3] so ans[2] = 3\r\n- nums[3:6] = [1,2,3,4] so ans[3] = 4\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= k <= nums.length <= 105
    • \r\n\t
    • 1 <= nums[i] <= 105
    • \r\n
    ", "content_cn": null, "tags_en": ["Array", "Hash Table", "Line Sweep"], "tags_cn": ["\u6570\u7ec4", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector distinctNumbers(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] distinctNumbers(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def distinctNumbers(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def distinctNumbers(self, nums: List[int], k: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* distinctNumbers(int* nums, int numsSize, int k, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] DistinctNumbers(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number[]}\n */\nvar distinctNumbers = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer[]}\ndef distinct_numbers(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func distinctNumbers(_ nums: [Int], _ k: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func distinctNumbers(nums []int, k int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def distinctNumbers(nums: Array[Int], k: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun distinctNumbers(nums: IntArray, k: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn distinct_numbers(nums: Vec, k: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer[]\n */\n function distinctNumbers($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function distinctNumbers(nums: number[], k: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (distinct-numbers nums k)\n (-> (listof exact-integer?) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1852](https://leetcode-cn.com/problems/distinct-numbers-in-each-subarray)", "[Distinct Numbers in Each Subarray](/solution/1800-1899/1852.Distinct%20Numbers%20in%20Each%20Subarray/README_EN.md)", "`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1852](https://leetcode.com/problems/distinct-numbers-in-each-subarray)", "[Distinct Numbers in Each Subarray](/solution/1800-1899/1852.Distinct%20Numbers%20in%20Each%20Subarray/README_EN.md)", "`Array`,`Hash Table`,`Line Sweep`", "Medium", "\ud83d\udd12"]}, {"question_id": "2002", "frontend_question_id": "1872", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/stone-game-viii", "url_en": "https://leetcode.com/problems/stone-game-viii", "relative_path_cn": "/solution/1800-1899/1872.Stone%20Game%20VIII/README.md", "relative_path_en": "/solution/1800-1899/1872.Stone%20Game%20VIII/README_EN.md", "title_cn": "\u77f3\u5b50\u6e38\u620f VIII", "title_en": "Stone Game VIII", "question_title_slug": "stone-game-viii", "content_en": "

    Alice and Bob take turns playing a game, with Alice starting first.

    \r\n\r\n

    There are n stones arranged in a row. On each player's turn, while the number of stones is more than one, they will do the following:

    \r\n\r\n
      \r\n\t
    1. Choose an integer x > 1, and remove the leftmost x stones from the row.
    2. \r\n\t
    3. Add the sum of the removed stones' values to the player's score.
    4. \r\n\t
    5. Place a new stone, whose value is equal to that sum, on the left side of the row.
    6. \r\n
    \r\n\r\n

    The game stops when only one stone is left in the row.

    \r\n\r\n

    The score difference between Alice and Bob is (Alice's score - Bob's score). Alice's goal is to maximize the score difference, and Bob's goal is the minimize the score difference.

    \r\n\r\n

    Given an integer array stones of length n where stones[i] represents the value of the ith stone from the left, return the score difference between Alice and Bob if they both play optimally.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: stones = [-1,2,-3,4,-5]\r\nOutput: 5\r\nExplanation:\r\n- Alice removes the first 4 stones, adds (-1) + 2 + (-3) + 4 = 2 to her score, and places a stone of\r\n  value 2 on the left. stones = [2,-5].\r\n- Bob removes the first 2 stones, adds 2 + (-5) = -3 to his score, and places a stone of value -3 on\r\n  the left. stones = [-3].\r\nThe difference between their scores is 2 - (-3) = 5.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: stones = [7,-6,5,10,5,-2,-6]\r\nOutput: 13\r\nExplanation:\r\n- Alice removes all stones, adds 7 + (-6) + 5 + 10 + 5 + (-2) + (-6) = 13 to her score, and places a\r\n  stone of value 13 on the left. stones = [13].\r\nThe difference between their scores is 13 - 0 = 13.\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: stones = [-10,-12]\r\nOutput: -22\r\nExplanation:\r\n- Alice can only make one move, which is to remove both stones. She adds (-10) + (-12) = -22 to her\r\n  score and places a stone of value -22 on the left. stones = [-22].\r\nThe difference between their scores is (-22) - 0 = -22.\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • n == stones.length
    • \r\n\t
    • 2 <= n <= 105
    • \r\n\t
    • -104 <= stones[i] <= 104
    • \r\n
    ", "content_cn": "

    Alice \u548c Bob \u73a9\u4e00\u4e2a\u6e38\u620f\uff0c\u4e24\u4eba\u8f6e\u6d41\u64cd\u4f5c\uff0c Alice \u5148\u624b\u00a0\u3002

    \n\n

    \u603b\u5171\u6709\u00a0n\u00a0\u4e2a\u77f3\u5b50\u6392\u6210\u4e00\u884c\u3002\u8f6e\u5230\u67d0\u4e2a\u73a9\u5bb6\u7684\u56de\u5408\u65f6\uff0c\u5982\u679c\u77f3\u5b50\u7684\u6570\u76ee \u5927\u4e8e 1\u00a0\uff0c\u4ed6\u5c06\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\uff1a

    \n\n
      \n\t
    1. \u9009\u62e9\u4e00\u4e2a\u6574\u6570\u00a0x > 1\u00a0\uff0c\u5e76\u4e14 \u79fb\u9664\u00a0\u6700\u5de6\u8fb9\u7684\u00a0x\u00a0\u4e2a\u77f3\u5b50\u3002
    2. \n\t
    3. \u5c06\u00a0\u79fb\u9664\u00a0\u7684\u77f3\u5b50\u4ef7\u503c\u4e4b \u548c\u00a0\u7d2f\u52a0\u5230\u8be5\u73a9\u5bb6\u7684\u5206\u6570\u4e2d\u3002
    4. \n\t
    5. \u5c06\u4e00\u4e2a \u65b0\u7684\u77f3\u5b50\u00a0\u653e\u5728\u6700\u5de6\u8fb9\uff0c\u4e14\u65b0\u77f3\u5b50\u7684\u503c\u4e3a\u88ab\u79fb\u9664\u77f3\u5b50\u503c\u4e4b\u548c\u3002
    6. \n
    \n\n

    \u5f53\u53ea\u5269\u4e0b \u4e00\u4e2a\u00a0\u77f3\u5b50\u65f6\uff0c\u6e38\u620f\u7ed3\u675f\u3002

    \n\n

    Alice \u548c Bob \u7684 \u5206\u6570\u4e4b\u5dee\u00a0\u4e3a\u00a0(Alice \u7684\u5206\u6570\u00a0- Bob \u7684\u5206\u6570)\u00a0\u3002\u00a0Alice \u7684\u76ee\u6807\u662f\u00a0\u6700\u5927\u5316\u00a0\u5206\u6570\u5dee\uff0cBob \u7684\u76ee\u6807\u662f \u6700\u5c0f\u5316\u00a0\u5206\u6570\u5dee\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u4e3a n\u00a0\u7684\u6574\u6570\u6570\u7ec4\u00a0stones\u00a0\uff0c\u5176\u4e2d\u00a0stones[i]\u00a0\u662f \u4ece\u5de6\u8fb9\u8d77\u00a0\u7b2c\u00a0i\u00a0\u4e2a\u77f3\u5b50\u7684\u4ef7\u503c\u3002\u8bf7\u4f60\u8fd4\u56de\u5728\u53cc\u65b9\u90fd\u91c7\u7528 \u6700\u4f18 \u7b56\u7565\u7684\u60c5\u51b5\u4e0b\uff0cAlice \u548c Bob \u7684 \u5206\u6570\u4e4b\u5dee \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1astones = [-1,2,-3,4,-5]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\n- Alice \u79fb\u9664\u6700\u5de6\u8fb9\u7684 4 \u4e2a\u77f3\u5b50\uff0c\u5f97\u5206\u589e\u52a0 (-1) + 2 + (-3) + 4 = 2 \uff0c\u5e76\u4e14\u5c06\u4e00\u4e2a\u4ef7\u503c\u4e3a 2 \u7684\u77f3\u5b50\u653e\u5728\u6700\u5de6\u8fb9\u3002stones = [2,-5] \u3002\n- Bob \u79fb\u9664\u6700\u5de6\u8fb9\u7684 2 \u4e2a\u77f3\u5b50\uff0c\u5f97\u5206\u589e\u52a0 2 + (-5) = -3 \uff0c\u5e76\u4e14\u5c06\u4e00\u4e2a\u4ef7\u503c\u4e3a -3 \u7684\u77f3\u5b50\u653e\u5728\u6700\u5de6\u8fb9\u3002stones = [-3] \u3002\n\u4e24\u8005\u5206\u6570\u4e4b\u5dee\u4e3a 2 - (-3) = 5 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1astones = [7,-6,5,10,5,-2,-6]\n\u8f93\u51fa\uff1a13\n\u89e3\u91ca\uff1a\n- Alice \u79fb\u9664\u6240\u6709\u77f3\u5b50\uff0c\u5f97\u5206\u589e\u52a0 7 + (-6) + 5 + 10 + 5 + (-2) + (-6) = 13 \uff0c\u5e76\u4e14\u5c06\u4e00\u4e2a\u4ef7\u503c\u4e3a 13 \u7684\u77f3\u5b50\u653e\u5728\u6700\u5de6\u8fb9\u3002stones = [13] \u3002\n\u4e24\u8005\u5206\u6570\u4e4b\u5dee\u4e3a 13 - 0 = 13 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1astones = [-10,-12]\n\u8f93\u51fa\uff1a-22\n\u89e3\u91ca\uff1a\n- Alice \u53ea\u6709\u4e00\u79cd\u64cd\u4f5c\uff0c\u5c31\u662f\u79fb\u9664\u6240\u6709\u77f3\u5b50\u3002\u5f97\u5206\u589e\u52a0 (-10) + (-12) = -22 \uff0c\u5e76\u4e14\u5c06\u4e00\u4e2a\u4ef7\u503c\u4e3a -22 \u7684\u77f3\u5b50\u653e\u5728\u6700\u5de6\u8fb9\u3002stones = [-22] \u3002\n\u4e24\u8005\u5206\u6570\u4e4b\u5dee\u4e3a (-22) - 0 = -22 \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == stones.length
    • \n\t
    • 2 <= n <= 105
    • \n\t
    • -104 <= stones[i] <= 104
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int stoneGameVIII(vector& stones) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int stoneGameVIII(int[] stones) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def stoneGameVIII(self, stones):\n \"\"\"\n :type stones: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def stoneGameVIII(self, stones: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint stoneGameVIII(int* stones, int stonesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int StoneGameVIII(int[] stones) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} stones\n * @return {number}\n */\nvar stoneGameVIII = function(stones) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} stones\n# @return {Integer}\ndef stone_game_viii(stones)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func stoneGameVIII(_ stones: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func stoneGameVIII(stones []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def stoneGameVIII(stones: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun stoneGameVIII(stones: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn stone_game_viii(stones: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $stones\n * @return Integer\n */\n function stoneGameVIII($stones) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function stoneGameVIII(stones: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (stone-game-viii stones)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1872](https://leetcode-cn.com/problems/stone-game-viii)", "[\u77f3\u5b50\u6e38\u620f VIII](/solution/1800-1899/1872.Stone%20Game%20VIII/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1872](https://leetcode.com/problems/stone-game-viii)", "[Stone Game VIII](/solution/1800-1899/1872.Stone%20Game%20VIII/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "2001", "frontend_question_id": "1871", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/jump-game-vii", "url_en": "https://leetcode.com/problems/jump-game-vii", "relative_path_cn": "/solution/1800-1899/1871.Jump%20Game%20VII/README.md", "relative_path_en": "/solution/1800-1899/1871.Jump%20Game%20VII/README_EN.md", "title_cn": "\u8df3\u8dc3\u6e38\u620f VII", "title_en": "Jump Game VII", "question_title_slug": "jump-game-vii", "content_en": "

    You are given a 0-indexed binary string s and two integers minJump and maxJump. In the beginning, you are standing at index 0, which is equal to '0'. You can move from index i to index j if the following conditions are fulfilled:

    \n\n
      \n\t
    • i + minJump <= j <= min(i + maxJump, s.length - 1), and
    • \n\t
    • s[j] == '0'.
    • \n
    \n\n

    Return true if you can reach index s.length - 1 in s, or false otherwise.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "011010", minJump = 2, maxJump = 3\nOutput: true\nExplanation:\nIn the first step, move from index 0 to index 3. \nIn the second step, move from index 3 to index 5.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "01101110", minJump = 2, maxJump = 3\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= s.length <= 105
    • \n\t
    • s[i] is either '0' or '1'.
    • \n\t
    • s[0] == '0'
    • \n\t
    • 1 <= minJump <= maxJump < s.length
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u4e0b\u6807\u4ece 0 \u5f00\u59cb\u7684\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32\u00a0s\u00a0\u548c\u4e24\u4e2a\u6574\u6570\u00a0minJump \u548c\u00a0maxJump\u00a0\u3002\u4e00\u5f00\u59cb\uff0c\u4f60\u5728\u4e0b\u6807\u00a00\u00a0\u5904\uff0c\u4e14\u8be5\u4f4d\u7f6e\u7684\u503c\u4e00\u5b9a\u4e3a\u00a0'0'\u00a0\u3002\u5f53\u540c\u65f6\u6ee1\u8db3\u5982\u4e0b\u6761\u4ef6\u65f6\uff0c\u4f60\u53ef\u4ee5\u4ece\u4e0b\u6807\u00a0i\u00a0\u79fb\u52a8\u5230\u4e0b\u6807\u00a0j\u00a0\u5904\uff1a

    \n\n
      \n\t
    • i + minJump <= j <= min(i + maxJump, s.length - 1)\u00a0\u4e14
    • \n\t
    • s[j] == '0'.
    • \n
    \n\n

    \u5982\u679c\u4f60\u53ef\u4ee5\u5230\u8fbe s\u00a0\u7684\u4e0b\u6807\u00a0s.length - 1\u00a0\u5904\uff0c\u8bf7\u4f60\u8fd4\u56de\u00a0true\u00a0\uff0c\u5426\u5219\u8fd4\u56de\u00a0false\u00a0\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"011010\", minJump = 2, maxJump = 3\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\n\u7b2c\u4e00\u6b65\uff0c\u4ece\u4e0b\u6807 0 \u79fb\u52a8\u5230\u4e0b\u6807 3 \u3002\n\u7b2c\u4e8c\u6b65\uff0c\u4ece\u4e0b\u6807 3 \u79fb\u52a8\u5230\u4e0b\u6807 5 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"01101110\", minJump = 2, maxJump = 3\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= s.length <= 105
    • \n\t
    • s[i]\u00a0\u8981\u4e48\u662f\u00a0'0'\u00a0\uff0c\u8981\u4e48\u662f\u00a0'1'
    • \n\t
    • s[0] == '0'
    • \n\t
    • 1 <= minJump <= maxJump < s.length
    • \n
    \n", "tags_en": ["Greedy", "Breadth-first Search", "Line Sweep"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canReach(string s, int minJump, int maxJump) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canReach(String s, int minJump, int maxJump) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canReach(self, s, minJump, maxJump):\n \"\"\"\n :type s: str\n :type minJump: int\n :type maxJump: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canReach(self, s: str, minJump: int, maxJump: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canReach(char * s, int minJump, int maxJump){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanReach(string s, int minJump, int maxJump) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number} minJump\n * @param {number} maxJump\n * @return {boolean}\n */\nvar canReach = function(s, minJump, maxJump) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer} min_jump\n# @param {Integer} max_jump\n# @return {Boolean}\ndef can_reach(s, min_jump, max_jump)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canReach(_ s: String, _ minJump: Int, _ maxJump: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canReach(s string, minJump int, maxJump int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canReach(s: String, minJump: Int, maxJump: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canReach(s: String, minJump: Int, maxJump: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_reach(s: String, min_jump: i32, max_jump: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer $minJump\n * @param Integer $maxJump\n * @return Boolean\n */\n function canReach($s, $minJump, $maxJump) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canReach(s: string, minJump: number, maxJump: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-reach s minJump maxJump)\n (-> string? exact-integer? exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1871](https://leetcode-cn.com/problems/jump-game-vii)", "[\u8df3\u8dc3\u6e38\u620f VII](/solution/1800-1899/1871.Jump%20Game%20VII/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1871](https://leetcode.com/problems/jump-game-vii)", "[Jump Game VII](/solution/1800-1899/1871.Jump%20Game%20VII/README_EN.md)", "`Greedy`,`Breadth-first Search`,`Line Sweep`", "Medium", ""]}, {"question_id": "2000", "frontend_question_id": "1870", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-speed-to-arrive-on-time", "url_en": "https://leetcode.com/problems/minimum-speed-to-arrive-on-time", "relative_path_cn": "/solution/1800-1899/1870.Minimum%20Speed%20to%20Arrive%20on%20Time/README.md", "relative_path_en": "/solution/1800-1899/1870.Minimum%20Speed%20to%20Arrive%20on%20Time/README_EN.md", "title_cn": "\u51c6\u65f6\u5230\u8fbe\u7684\u5217\u8f66\u6700\u5c0f\u65f6\u901f", "title_en": "Minimum Speed to Arrive on Time", "question_title_slug": "minimum-speed-to-arrive-on-time", "content_en": "

    You are given a floating-point number hour, representing the amount of time you have to reach the office. To commute to the office, you must take n trains in sequential order. You are also given an integer array dist of length n, where dist[i] describes the distance (in kilometers) of the ith train ride.

    \n\n

    Each train can only depart at an integer hour, so you may need to wait in between each train ride.

    \n\n
      \n\t
    • For example, if the 1st train ride takes 1.5 hours, you must wait for an additional 0.5 hours before you can depart on the 2nd train ride at the 2 hour mark.
    • \n
    \n\n

    Return the minimum positive integer speed (in kilometers per hour) that all the trains must travel at for you to reach the office on time, or -1 if it is impossible to be on time.

    \n\n

    Tests are generated such that the answer will not exceed 107 and hour will have at most two digits after the decimal point.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: dist = [1,3,2], hour = 6\nOutput: 1\nExplanation: At speed 1:\n- The first train ride takes 1/1 = 1 hour.\n- Since we are already at an integer hour, we depart immediately at the 1 hour mark. The second train takes 3/1 = 3 hours.\n- Since we are already at an integer hour, we depart immediately at the 4 hour mark. The third train takes 2/1 = 2 hours.\n- You will arrive at exactly the 6 hour mark.\n
    \n\n

    Example 2:

    \n\n
    \nInput: dist = [1,3,2], hour = 2.7\nOutput: 3\nExplanation: At speed 3:\n- The first train ride takes 1/3 = 0.33333 hours.\n- Since we are not at an integer hour, we wait until the 1 hour mark to depart. The second train ride takes 3/3 = 1 hour.\n- Since we are already at an integer hour, we depart immediately at the 2 hour mark. The third train takes 2/3 = 0.66667 hours.\n- You will arrive at the 2.66667 hour mark.\n
    \n\n

    Example 3:

    \n\n
    \nInput: dist = [1,3,2], hour = 1.9\nOutput: -1\nExplanation: It is impossible because the earliest the third train can depart is at the 2 hour mark.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == dist.length
    • \n\t
    • 1 <= n <= 105
    • \n\t
    • 1 <= dist[i] <= 105
    • \n\t
    • 1 <= hour <= 109
    • \n\t
    • There will be at most two digits after the decimal point in hour.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6d6e\u70b9\u6570 hour \uff0c\u8868\u793a\u4f60\u5230\u8fbe\u529e\u516c\u5ba4\u53ef\u7528\u7684\u603b\u901a\u52e4\u65f6\u95f4\u3002\u8981\u5230\u8fbe\u529e\u516c\u5ba4\uff0c\u4f60\u5fc5\u987b\u6309\u7ed9\u5b9a\u6b21\u5e8f\u4e58\u5750 n \u8d9f\u5217\u8f66\u3002\u53e6\u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u6574\u6570\u6570\u7ec4 dist \uff0c\u5176\u4e2d dist[i] \u8868\u793a\u7b2c i \u8d9f\u5217\u8f66\u7684\u884c\u9a76\u8ddd\u79bb\uff08\u5355\u4f4d\u662f\u5343\u7c73\uff09\u3002

    \n\n

    \u6bcf\u8d9f\u5217\u8f66\u5747\u53ea\u80fd\u5728\u6574\u70b9\u53d1\u8f66\uff0c\u6240\u4ee5\u4f60\u53ef\u80fd\u9700\u8981\u5728\u4e24\u8d9f\u5217\u8f66\u4e4b\u95f4\u7b49\u5f85\u4e00\u6bb5\u65f6\u95f4\u3002

    \n\n
      \n\t
    • \u4f8b\u5982\uff0c\u7b2c 1 \u8d9f\u5217\u8f66\u9700\u8981 1.5 \u5c0f\u65f6\uff0c\u90a3\u4f60\u5fc5\u987b\u518d\u7b49\u5f85 0.5 \u5c0f\u65f6\uff0c\u642d\u4e58\u5728\u7b2c 2 \u5c0f\u65f6\u53d1\u8f66\u7684\u7b2c 2 \u8d9f\u5217\u8f66\u3002
    • \n
    \n\n

    \u8fd4\u56de\u80fd\u6ee1\u8db3\u4f60\u51c6\u65f6\u5230\u8fbe\u529e\u516c\u5ba4\u6240\u8981\u6c42\u5168\u90e8\u5217\u8f66\u7684 \u6700\u5c0f\u6b63\u6574\u6570 \u65f6\u901f\uff08\u5355\u4f4d\uff1a\u5343\u7c73\u6bcf\u5c0f\u65f6\uff09\uff0c\u5982\u679c\u65e0\u6cd5\u51c6\u65f6\u5230\u8fbe\uff0c\u5219\u8fd4\u56de -1 \u3002

    \n\n

    \u751f\u6210\u7684\u6d4b\u8bd5\u7528\u4f8b\u4fdd\u8bc1\u7b54\u6848\u4e0d\u8d85\u8fc7 107 \uff0c\u4e14 hour \u7684 \u5c0f\u6570\u70b9\u540e\u6700\u591a\u5b58\u5728\u4e24\u4f4d\u6570\u5b57 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1adist = [1,3,2], hour = 6\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u901f\u5ea6\u4e3a 1 \u65f6\uff1a\n- \u7b2c 1 \u8d9f\u5217\u8f66\u8fd0\u884c\u9700\u8981 1/1 = 1 \u5c0f\u65f6\u3002\n- \u7531\u4e8e\u662f\u5728\u6574\u6570\u65f6\u95f4\u5230\u8fbe\uff0c\u53ef\u4ee5\u7acb\u5373\u6362\u4e58\u5728\u7b2c 1 \u5c0f\u65f6\u53d1\u8f66\u7684\u5217\u8f66\u3002\u7b2c 2 \u8d9f\u5217\u8f66\u8fd0\u884c\u9700\u8981 3/1 = 3 \u5c0f\u65f6\u3002\n- \u7531\u4e8e\u662f\u5728\u6574\u6570\u65f6\u95f4\u5230\u8fbe\uff0c\u53ef\u4ee5\u7acb\u5373\u6362\u4e58\u5728\u7b2c 4 \u5c0f\u65f6\u53d1\u8f66\u7684\u5217\u8f66\u3002\u7b2c 3 \u8d9f\u5217\u8f66\u8fd0\u884c\u9700\u8981 2/1 = 2 \u5c0f\u65f6\u3002\n- \u4f60\u5c06\u4f1a\u6070\u597d\u5728\u7b2c 6 \u5c0f\u65f6\u5230\u8fbe\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1adist = [1,3,2], hour = 2.7\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u901f\u5ea6\u4e3a 3 \u65f6\uff1a\n- \u7b2c 1 \u8d9f\u5217\u8f66\u8fd0\u884c\u9700\u8981 1/3 = 0.33333 \u5c0f\u65f6\u3002\n- \u7531\u4e8e\u4e0d\u662f\u5728\u6574\u6570\u65f6\u95f4\u5230\u8fbe\uff0c\u6545\u9700\u8981\u7b49\u5f85\u81f3\u7b2c 1 \u5c0f\u65f6\u624d\u80fd\u642d\u4e58\u5217\u8f66\u3002\u7b2c 2 \u8d9f\u5217\u8f66\u8fd0\u884c\u9700\u8981 3/3 = 1 \u5c0f\u65f6\u3002\n- \u7531\u4e8e\u662f\u5728\u6574\u6570\u65f6\u95f4\u5230\u8fbe\uff0c\u53ef\u4ee5\u7acb\u5373\u6362\u4e58\u5728\u7b2c 2 \u5c0f\u65f6\u53d1\u8f66\u7684\u5217\u8f66\u3002\u7b2c 3 \u8d9f\u5217\u8f66\u8fd0\u884c\u9700\u8981 2/3 = 0.66667 \u5c0f\u65f6\u3002\n- \u4f60\u5c06\u4f1a\u5728\u7b2c 2.66667 \u5c0f\u65f6\u5230\u8fbe\u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1adist = [1,3,2], hour = 1.9\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u4e0d\u53ef\u80fd\u51c6\u65f6\u5230\u8fbe\uff0c\u56e0\u4e3a\u7b2c 3 \u8d9f\u5217\u8f66\u6700\u65e9\u662f\u5728\u7b2c 2 \u5c0f\u65f6\u53d1\u8f66\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == dist.length
    • \n\t
    • 1 <= n <= 105
    • \n\t
    • 1 <= dist[i] <= 105
    • \n\t
    • 1 <= hour <= 109
    • \n\t
    • hours \u4e2d\uff0c\u5c0f\u6570\u70b9\u540e\u6700\u591a\u5b58\u5728\u4e24\u4f4d\u6570\u5b57
    • \n
    \n", "tags_en": ["Math", "Binary Search"], "tags_cn": ["\u6570\u5b66", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minSpeedOnTime(vector& dist, double hour) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minSpeedOnTime(int[] dist, double hour) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minSpeedOnTime(self, dist, hour):\n \"\"\"\n :type dist: List[int]\n :type hour: float\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minSpeedOnTime(self, dist: List[int], hour: float) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minSpeedOnTime(int* dist, int distSize, double hour){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinSpeedOnTime(int[] dist, double hour) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} dist\n * @param {number} hour\n * @return {number}\n */\nvar minSpeedOnTime = function(dist, hour) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} dist\n# @param {Float} hour\n# @return {Integer}\ndef min_speed_on_time(dist, hour)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minSpeedOnTime(_ dist: [Int], _ hour: Double) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minSpeedOnTime(dist []int, hour float64) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minSpeedOnTime(dist: Array[Int], hour: Double): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minSpeedOnTime(dist: IntArray, hour: Double): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_speed_on_time(dist: Vec, hour: f64) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $dist\n * @param Float $hour\n * @return Integer\n */\n function minSpeedOnTime($dist, $hour) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minSpeedOnTime(dist: number[], hour: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-speed-on-time dist hour)\n (-> (listof exact-integer?) flonum? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1870](https://leetcode-cn.com/problems/minimum-speed-to-arrive-on-time)", "[\u51c6\u65f6\u5230\u8fbe\u7684\u5217\u8f66\u6700\u5c0f\u65f6\u901f](/solution/1800-1899/1870.Minimum%20Speed%20to%20Arrive%20on%20Time/README.md)", "`\u6570\u5b66`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1870](https://leetcode.com/problems/minimum-speed-to-arrive-on-time)", "[Minimum Speed to Arrive on Time](/solution/1800-1899/1870.Minimum%20Speed%20to%20Arrive%20on%20Time/README_EN.md)", "`Math`,`Binary Search`", "Medium", ""]}, {"question_id": "1999", "frontend_question_id": "1869", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longer-contiguous-segments-of-ones-than-zeros", "url_en": "https://leetcode.com/problems/longer-contiguous-segments-of-ones-than-zeros", "relative_path_cn": "/solution/1800-1899/1869.Longer%20Contiguous%20Segments%20of%20Ones%20than%20Zeros/README.md", "relative_path_en": "/solution/1800-1899/1869.Longer%20Contiguous%20Segments%20of%20Ones%20than%20Zeros/README_EN.md", "title_cn": "\u54ea\u79cd\u8fde\u7eed\u5b50\u5b57\u7b26\u4e32\u66f4\u957f", "title_en": "Longer Contiguous Segments of Ones than Zeros", "question_title_slug": "longer-contiguous-segments-of-ones-than-zeros", "content_en": "

    Given a binary string s, return true if the longest contiguous segment of 1s is strictly longer than the longest contiguous segment of 0s in s. Return false otherwise.

    \n\n
      \n\t
    • For example, in s = "110100010" the longest contiguous segment of 1s has length 2, and the longest contiguous segment of 0s has length 3.
    • \n
    \n\n

    Note that if there are no 0s, then the longest contiguous segment of 0s is considered to have length 0. The same applies if there are no 1s.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "1101"\nOutput: true\nExplanation:\nThe longest contiguous segment of 1s has length 2: "1101"\nThe longest contiguous segment of 0s has length 1: "1101"\nThe segment of 1s is longer, so return true.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "111000"\nOutput: false\nExplanation:\nThe longest contiguous segment of 1s has length 3: "111000"\nThe longest contiguous segment of 0s has length 3: "111000"\nThe segment of 1s is not longer, so return false.\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "110100010"\nOutput: false\nExplanation:\nThe longest contiguous segment of 1s has length 2: "110100010"\nThe longest contiguous segment of 0s has length 3: "110100010"\nThe segment of 1s is not longer, so return false.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 100
    • \n\t
    • s[i] is either '0' or '1'.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32 s \u3002\u5982\u679c\u5b57\u7b26\u4e32\u4e2d\u7531 1 \u7ec4\u6210\u7684 \u6700\u957f \u8fde\u7eed\u5b50\u5b57\u7b26\u4e32 \u4e25\u683c\u957f\u4e8e \u7531 0 \u7ec4\u6210\u7684 \u6700\u957f \u8fde\u7eed\u5b50\u5b57\u7b26\u4e32\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n
      \n\t
    • \u4f8b\u5982\uff0cs = \"110100010\" \u4e2d\uff0c\u7531 1 \u7ec4\u6210\u7684\u6700\u957f\u8fde\u7eed\u5b50\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u662f 2 \uff0c\u7531 0 \u7ec4\u6210\u7684\u6700\u957f\u8fde\u7eed\u5b50\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u662f 3 \u3002
    • \n
    \n\n

    \u6ce8\u610f\uff0c\u5982\u679c\u5b57\u7b26\u4e32\u4e2d\u4e0d\u5b58\u5728 0 \uff0c\u6b64\u65f6\u8ba4\u4e3a\u7531 0 \u7ec4\u6210\u7684\u6700\u957f\u8fde\u7eed\u5b50\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u662f 0 \u3002\u5b57\u7b26\u4e32\u4e2d\u4e0d\u5b58\u5728 1 \u7684\u60c5\u51b5\u4e5f\u9002\u7528\u6b64\u89c4\u5219\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"1101\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\n\u7531 1 \u7ec4\u6210\u7684\u6700\u957f\u8fde\u7eed\u5b50\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u662f 2\uff1a\"1101\"\n\u7531 0 \u7ec4\u6210\u7684\u6700\u957f\u8fde\u7eed\u5b50\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u662f 1\uff1a\"1101\"\n\u7531 1 \u7ec4\u6210\u7684\u5b50\u5b57\u7b26\u4e32\u66f4\u957f\uff0c\u6545\u8fd4\u56de true \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"111000\"\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\n\u7531 1 \u7ec4\u6210\u7684\u6700\u957f\u8fde\u7eed\u5b50\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u662f 3\uff1a\"111000\"\n\u7531 0 \u7ec4\u6210\u7684\u6700\u957f\u8fde\u7eed\u5b50\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u662f 3\uff1a\"111000\"\n\u7531 1 \u7ec4\u6210\u7684\u5b50\u5b57\u7b26\u4e32\u4e0d\u6bd4\u7531 0 \u7ec4\u6210\u7684\u5b50\u5b57\u7b26\u4e32\u957f\uff0c\u6545\u8fd4\u56de false \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"110100010\"\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\n\u7531 1 \u7ec4\u6210\u7684\u6700\u957f\u8fde\u7eed\u5b50\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u662f 2\uff1a\"110100010\"\n\u7531 0 \u7ec4\u6210\u7684\u6700\u957f\u8fde\u7eed\u5b50\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u662f 3\uff1a\"110100010\"\n\u7531 1 \u7ec4\u6210\u7684\u5b50\u5b57\u7b26\u4e32\u4e0d\u6bd4\u7531 0 \u7ec4\u6210\u7684\u5b50\u5b57\u7b26\u4e32\u957f\uff0c\u6545\u8fd4\u56de false \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 100
    • \n\t
    • s[i] \u4e0d\u662f '0' \u5c31\u662f '1'
    • \n
    \n", "tags_en": ["Array", "Two Pointers"], "tags_cn": ["\u6570\u7ec4", "\u53cc\u6307\u9488"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool checkZeroOnes(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean checkZeroOnes(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def checkZeroOnes(self, s):\n \"\"\"\n :type s: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def checkZeroOnes(self, s: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool checkZeroOnes(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CheckZeroOnes(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {boolean}\n */\nvar checkZeroOnes = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Boolean}\ndef check_zero_ones(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func checkZeroOnes(_ s: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func checkZeroOnes(s string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def checkZeroOnes(s: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun checkZeroOnes(s: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn check_zero_ones(s: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Boolean\n */\n function checkZeroOnes($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function checkZeroOnes(s: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (check-zero-ones s)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1869](https://leetcode-cn.com/problems/longer-contiguous-segments-of-ones-than-zeros)", "[\u54ea\u79cd\u8fde\u7eed\u5b50\u5b57\u7b26\u4e32\u66f4\u957f](/solution/1800-1899/1869.Longer%20Contiguous%20Segments%20of%20Ones%20than%20Zeros/README.md)", "`\u6570\u7ec4`,`\u53cc\u6307\u9488`", "\u7b80\u5355", ""], "md_table_row_en": ["[1869](https://leetcode.com/problems/longer-contiguous-segments-of-ones-than-zeros)", "[Longer Contiguous Segments of Ones than Zeros](/solution/1800-1899/1869.Longer%20Contiguous%20Segments%20of%20Ones%20than%20Zeros/README_EN.md)", "`Array`,`Two Pointers`", "Easy", ""]}, {"question_id": "1998", "frontend_question_id": "1843", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/suspicious-bank-accounts", "url_en": "https://leetcode.com/problems/suspicious-bank-accounts", "relative_path_cn": "/solution/1800-1899/1843.Suspicious%20Bank%20Accounts/README.md", "relative_path_en": "/solution/1800-1899/1843.Suspicious%20Bank%20Accounts/README_EN.md", "title_cn": "", "title_en": "Suspicious Bank Accounts", "question_title_slug": "suspicious-bank-accounts", "content_en": "

    Table: Accounts

    \r\n\r\n
    \r\n+----------------+------+\r\n| Column Name    | Type |\r\n+----------------+------+\r\n| account_id     | int  |\r\n| max_income     | int  |\r\n+----------------+------+\r\naccount_id is the primary key for this table.\r\nEach row contains information about the maximum monthly income for one bank account.\r\n
    \r\n\r\n

     

    \r\n\r\n

    Table: Transactions

    \r\n\r\n
    \r\n+----------------+----------+\r\n| Column Name    | Type     |\r\n+----------------+----------+\r\n| transaction_id | int      |\r\n| account_id     | int      |\r\n| type           | ENUM     |\r\n| amount         | int      |\r\n| day            | datetime |\r\n+----------------+----------+\r\ntransaction_id is the primary key for this table.\r\nEach row contains information about one transaction.\r\ntype is ENUM ('Creditor','Debtor') where 'Creditor' means the user deposited money into their account and 'Debtor' means the user withdrew money from their account.\r\namount is the amount of money depositied/withdrawn during the transaction.\r\n
    \r\n\r\n

     

    \r\n\r\n

    Write an SQL query to report the IDs of all suspicious bank accounts.

    \r\n\r\n

    A bank account is suspicious if the total income exceeds the max_income for this account for two or more consecutive months. The total income of an account in some month is the sum of all its deposits in that month (i.e., transactions of the type 'Creditor').

    \r\n\r\n

    Return the result table in ascending order by transaction_id.

    \r\n\r\n

    The query result format is in the following example:

    \r\n\r\n

     

    \r\n\r\n
    \r\nAccounts table:\r\n+------------+------------+\r\n| account_id | max_income |\r\n+------------+------------+\r\n| 3          | 21000      |\r\n| 4          | 10400      |\r\n+------------+------------+\r\n\r\nTransactions table:\r\n+----------------+------------+----------+--------+---------------------+\r\n| transaction_id | account_id | type     | amount | day                 |\r\n+----------------+------------+----------+--------+---------------------+\r\n| 2              | 3          | Creditor | 107100 | 2021-06-02 11:38:14 |\r\n| 4              | 4          | Creditor | 10400  | 2021-06-20 12:39:18 |\r\n| 11             | 4          | Debtor   | 58800  | 2021-07-23 12:41:55 |\r\n| 1              | 4          | Creditor | 49300  | 2021-05-03 16:11:04 |\r\n| 15             | 3          | Debtor   | 75500  | 2021-05-23 14:40:20 |\r\n| 10             | 3          | Creditor | 102100 | 2021-06-15 10:37:16 |\r\n| 14             | 4          | Creditor | 56300  | 2021-07-21 12:12:25 |\r\n| 19             | 4          | Debtor   | 101100 | 2021-05-09 15:21:49 |\r\n| 8              | 3          | Creditor | 64900  | 2021-07-26 15:09:56 |\r\n| 7              | 3          | Creditor | 90900  | 2021-06-14 11:23:07 |\r\n+----------------+------------+----------+--------+---------------------+\r\n\r\nResult table:\r\n+------------+\r\n| account_id |\r\n+------------+\r\n| 3          |\r\n+------------+\r\n\r\nFor account 3:\r\n- In 6-2021, the user had an income of 107100 + 102100 + 90900 = 300100.\r\n- In 7-2021, the user had an income of 64900.\r\nWe can see that the income exceeded the max income of 21000 for two consecutive months, so we include 3 in the result table.\r\n\r\nFor account 4:\r\n- In 5-2021, the user had an income of 49300.\r\n- In 6-2021, the user had an income of 10400.\r\n- In 7-2021, the user had an income of 56300.\r\nWe can see that the income exceeded the max income in May and July, but not in June. Since the account did not exceed the max income for two consecutive months, we do not include it in the result table.\r\n
    ", "content_cn": null, "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1843](https://leetcode-cn.com/problems/suspicious-bank-accounts)", "[Suspicious Bank Accounts](/solution/1800-1899/1843.Suspicious%20Bank%20Accounts/README_EN.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1843](https://leetcode.com/problems/suspicious-bank-accounts)", "[Suspicious Bank Accounts](/solution/1800-1899/1843.Suspicious%20Bank%20Accounts/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1997", "frontend_question_id": "1842", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/next-palindrome-using-same-digits", "url_en": "https://leetcode.com/problems/next-palindrome-using-same-digits", "relative_path_cn": "/solution/1800-1899/1842.Next%20Palindrome%20Using%20Same%20Digits/README.md", "relative_path_en": "/solution/1800-1899/1842.Next%20Palindrome%20Using%20Same%20Digits/README_EN.md", "title_cn": "", "title_en": "Next Palindrome Using Same Digits", "question_title_slug": "next-palindrome-using-same-digits", "content_en": "

    You are given a numeric string num, representing a very large palindrome.

    \r\n\r\n

    Return the smallest palindrome larger than num that can be created by rearranging its digits. If no such palindrome exists, return an empty string "".

    \r\n\r\n

    A palindrome is a number that reads the same backward as forward.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: num = "1221"\r\nOutput: "2112"\r\nExplanation: The next palindrome larger than "1221" is "2112".\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: num = "32123"\r\nOutput: ""\r\nExplanation: No palindromes larger than "32123" can be made by rearranging the digits.\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: num = "45544554"\r\nOutput: "54455445"\r\nExplanation: The next palindrome larger than "45544554" is "54455445".\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= num.length <= 105
    • \r\n\t
    • num is a palindrome.
    • \r\n
    ", "content_cn": null, "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string nextPalindrome(string num) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String nextPalindrome(String num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def nextPalindrome(self, num):\n \"\"\"\n :type num: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def nextPalindrome(self, num: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * nextPalindrome(char * num){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string NextPalindrome(string num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} num\n * @return {string}\n */\nvar nextPalindrome = function(num) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} num\n# @return {String}\ndef next_palindrome(num)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func nextPalindrome(_ num: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func nextPalindrome(num string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def nextPalindrome(num: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun nextPalindrome(num: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn next_palindrome(num: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $num\n * @return String\n */\n function nextPalindrome($num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function nextPalindrome(num: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (next-palindrome num)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1842](https://leetcode-cn.com/problems/next-palindrome-using-same-digits)", "[Next Palindrome Using Same Digits](/solution/1800-1899/1842.Next%20Palindrome%20Using%20Same%20Digits/README_EN.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1842](https://leetcode.com/problems/next-palindrome-using-same-digits)", "[Next Palindrome Using Same Digits](/solution/1800-1899/1842.Next%20Palindrome%20Using%20Same%20Digits/README_EN.md)", "`Greedy`", "Hard", "\ud83d\udd12"]}, {"question_id": "1996", "frontend_question_id": "1866", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-ways-to-rearrange-sticks-with-k-sticks-visible", "url_en": "https://leetcode.com/problems/number-of-ways-to-rearrange-sticks-with-k-sticks-visible", "relative_path_cn": "/solution/1800-1899/1866.Number%20of%20Ways%20to%20Rearrange%20Sticks%20With%20K%20Sticks%20Visible/README.md", "relative_path_en": "/solution/1800-1899/1866.Number%20of%20Ways%20to%20Rearrange%20Sticks%20With%20K%20Sticks%20Visible/README_EN.md", "title_cn": "\u6070\u6709 K \u6839\u6728\u68cd\u53ef\u4ee5\u770b\u5230\u7684\u6392\u5217\u6570\u76ee", "title_en": "Number of Ways to Rearrange Sticks With K Sticks Visible", "question_title_slug": "number-of-ways-to-rearrange-sticks-with-k-sticks-visible", "content_en": "

    There are n uniquely-sized sticks whose lengths are integers from 1 to n. You want to arrange the sticks such that exactly k sticks are visible from the left. A stick is visible from the left if there are no longer sticks to the left of it.

    \n\n
      \n\t
    • For example, if the sticks are arranged [1,3,2,5,4], then the sticks with lengths 1, 3, and 5 are visible from the left.
    • \n
    \n\n

    Given n and k, return the number of such arrangements. Since the answer may be large, return it modulo 109 + 7.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 3, k = 2\nOutput: 3\nExplanation: [1,3,2], [2,3,1], and [2,1,3] are the only arrangements such that exactly 2 sticks are visible.\nThe visible sticks are underlined.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 5, k = 5\nOutput: 1\nExplanation: [1,2,3,4,5] is the only arrangement such that all 5 sticks are visible.\nThe visible sticks are underlined.\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 20, k = 11\nOutput: 647427950\nExplanation: There are 647427950 (mod 109 + 7) ways to rearrange the sticks such that exactly 11 sticks are visible.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 1000
    • \n\t
    • 1 <= k <= n
    • \n
    \n", "content_cn": "

    \u6709 n \u6839\u957f\u5ea6\u4e92\u4e0d\u76f8\u540c\u7684\u6728\u68cd\uff0c\u957f\u5ea6\u4e3a\u4ece 1 \u5230 n \u7684\u6574\u6570\u3002\u8bf7\u4f60\u5c06\u8fd9\u4e9b\u6728\u68cd\u6392\u6210\u4e00\u6392\uff0c\u5e76\u6ee1\u8db3\u4ece\u5de6\u4fa7 \u53ef\u4ee5\u770b\u5230\u00a0\u6070\u597d k \u6839\u6728\u68cd\u3002\u4ece\u5de6\u4fa7 \u53ef\u4ee5\u770b\u5230 \u6728\u68cd\u7684\u524d\u63d0\u662f\u8fd9\u4e2a\u6728\u68cd\u7684 \u5de6\u4fa7 \u4e0d\u5b58\u5728\u6bd4\u5b83 \u66f4\u957f\u7684 \u6728\u68cd\u3002

    \n\n
      \n\t
    • \u4f8b\u5982\uff0c\u5982\u679c\u6728\u68cd\u6392\u5217\u4e3a [1,3,2,5,4] \uff0c\u90a3\u4e48\u4ece\u5de6\u4fa7\u53ef\u4ee5\u770b\u5230\u7684\u5c31\u662f\u957f\u5ea6\u5206\u522b\u4e3a 1\u30013 \u30015 \u7684\u6728\u68cd\u3002
    • \n
    \n\n

    \u7ed9\u4f60 n \u548c k \uff0c\u8fd4\u56de\u7b26\u5408\u9898\u76ee\u8981\u6c42\u7684\u6392\u5217 \u6570\u76ee \u3002\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u5f88\u5927\uff0c\u8bf7\u8fd4\u56de\u5bf9 109 + 7 \u53d6\u4f59 \u7684\u7ed3\u679c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1an = 3, k = 2\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a[1,3,2], [2,3,1] \u548c [2,1,3] \u662f\u4ec5\u6709\u7684\u80fd\u6ee1\u8db3\u6070\u597d 2 \u6839\u6728\u68cd\u53ef\u4ee5\u770b\u5230\u7684\u6392\u5217\u3002\n\u53ef\u4ee5\u770b\u5230\u7684\u6728\u68cd\u5df2\u7ecf\u7528\u7c97\u4f53+\u659c\u4f53\u6807\u8bc6\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1an = 5, k = 5\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a[1,2,3,4,5] \u662f\u552f\u4e00\u4e00\u79cd\u80fd\u6ee1\u8db3\u5168\u90e8 5 \u6839\u6728\u68cd\u53ef\u4ee5\u770b\u5230\u7684\u6392\u5217\u3002\n\u53ef\u4ee5\u770b\u5230\u7684\u6728\u68cd\u5df2\u7ecf\u7528\u7c97\u4f53+\u659c\u4f53\u6807\u8bc6\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1an = 20, k = 11\n\u8f93\u51fa\uff1a647427950\n\u89e3\u91ca\uff1a\u603b\u5171\u6709 647427950 (mod 109 + 7) \u79cd\u80fd\u6ee1\u8db3\u6070\u597d\u6709 11 \u6839\u6728\u68cd\u53ef\u4ee5\u770b\u5230\u7684\u6392\u5217\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 1000
    • \n\t
    • 1 <= k <= n
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int rearrangeSticks(int n, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int rearrangeSticks(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def rearrangeSticks(self, n, k):\n \"\"\"\n :type n: int\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def rearrangeSticks(self, n: int, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint rearrangeSticks(int n, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int RearrangeSticks(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} k\n * @return {number}\n */\nvar rearrangeSticks = function(n, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} k\n# @return {Integer}\ndef rearrange_sticks(n, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func rearrangeSticks(_ n: Int, _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func rearrangeSticks(n int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def rearrangeSticks(n: Int, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun rearrangeSticks(n: Int, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn rearrange_sticks(n: i32, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $k\n * @return Integer\n */\n function rearrangeSticks($n, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function rearrangeSticks(n: number, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (rearrange-sticks n k)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1866](https://leetcode-cn.com/problems/number-of-ways-to-rearrange-sticks-with-k-sticks-visible)", "[\u6070\u6709 K \u6839\u6728\u68cd\u53ef\u4ee5\u770b\u5230\u7684\u6392\u5217\u6570\u76ee](/solution/1800-1899/1866.Number%20of%20Ways%20to%20Rearrange%20Sticks%20With%20K%20Sticks%20Visible/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1866](https://leetcode.com/problems/number-of-ways-to-rearrange-sticks-with-k-sticks-visible)", "[Number of Ways to Rearrange Sticks With K Sticks Visible](/solution/1800-1899/1866.Number%20of%20Ways%20to%20Rearrange%20Sticks%20With%20K%20Sticks%20Visible/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1995", "frontend_question_id": "1865", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/finding-pairs-with-a-certain-sum", "url_en": "https://leetcode.com/problems/finding-pairs-with-a-certain-sum", "relative_path_cn": "/solution/1800-1899/1865.Finding%20Pairs%20With%20a%20Certain%20Sum/README.md", "relative_path_en": "/solution/1800-1899/1865.Finding%20Pairs%20With%20a%20Certain%20Sum/README_EN.md", "title_cn": "\u627e\u51fa\u548c\u4e3a\u6307\u5b9a\u503c\u7684\u4e0b\u6807\u5bf9", "title_en": "Finding Pairs With a Certain Sum", "question_title_slug": "finding-pairs-with-a-certain-sum", "content_en": "

    You are given two integer arrays nums1 and nums2. You are tasked to implement a data structure that supports queries of two types:

    \n\n
      \n\t
    1. Add a positive integer to an element of a given index in the array nums2.
    2. \n\t
    3. Count the number of pairs (i, j) such that nums1[i] + nums2[j] equals a given value (0 <= i < nums1.length and 0 <= j < nums2.length).
    4. \n
    \n\n

    Implement the FindSumPairs class:

    \n\n
      \n\t
    • FindSumPairs(int[] nums1, int[] nums2) Initializes the FindSumPairs object with two integer arrays nums1 and nums2.
    • \n\t
    • void add(int index, int val) Adds val to nums2[index], i.e., apply nums2[index] += val.
    • \n\t
    • int count(int tot) Returns the number of pairs (i, j) such that nums1[i] + nums2[j] == tot.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["FindSumPairs", "count", "add", "count", "count", "add", "add", "count"]\n[[[1, 1, 2, 2, 2, 3], [1, 4, 5, 2, 5, 4]], [7], [3, 2], [8], [4], [0, 1], [1, 1], [7]]\nOutput\n[null, 8, null, 2, 1, null, null, 11]\n\nExplanation\nFindSumPairs findSumPairs = new FindSumPairs([1, 1, 2, 2, 2, 3], [1, 4, 5, 2, 5, 4]);\nfindSumPairs.count(7);  // return 8; pairs (2,2), (3,2), (4,2), (2,4), (3,4), (4,4) make 2 + 5 and pairs (5,1), (5,5) make 3 + 4\nfindSumPairs.add(3, 2); // now nums2 = [1,4,5,4,5,4]\nfindSumPairs.count(8);  // return 2; pairs (5,2), (5,4) make 3 + 5\nfindSumPairs.count(4);  // return 1; pair (5,0) makes 3 + 1\nfindSumPairs.add(0, 1); // now nums2 = [2,4,5,4,5,4]\nfindSumPairs.add(1, 1); // now nums2 = [2,5,5,4,5,4]\nfindSumPairs.count(7);  // return 11; pairs (2,1), (2,2), (2,4), (3,1), (3,2), (3,4), (4,1), (4,2), (4,4) make 2 + 5 and pairs (5,3), (5,5) make 3 + 4\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums1.length <= 1000
    • \n\t
    • 1 <= nums2.length <= 105
    • \n\t
    • 1 <= nums1[i] <= 109
    • \n\t
    • 1 <= nums2[i] <= 105
    • \n\t
    • 0 <= index < nums2.length
    • \n\t
    • 1 <= val <= 105
    • \n\t
    • 1 <= tot <= 109
    • \n\t
    • At most 1000 calls are made to add and count each.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u6574\u6570\u6570\u7ec4 nums1 \u548c nums2 \uff0c\u8bf7\u4f60\u5b9e\u73b0\u4e00\u4e2a\u652f\u6301\u4e0b\u8ff0\u4e24\u7c7b\u67e5\u8be2\u7684\u6570\u636e\u7ed3\u6784\uff1a

    \n\n
      \n\t
    1. \u7d2f\u52a0 \uff0c\u5c06\u4e00\u4e2a\u6b63\u6574\u6570\u52a0\u5230 nums2 \u4e2d\u6307\u5b9a\u4e0b\u6807\u5bf9\u5e94\u5143\u7d20\u4e0a\u3002
    2. \n\t
    3. \u8ba1\u6570 \uff0c\u7edf\u8ba1\u6ee1\u8db3 nums1[i] + nums2[j] \u7b49\u4e8e\u6307\u5b9a\u503c\u7684\u4e0b\u6807\u5bf9 (i, j) \u6570\u76ee\uff080 <= i < nums1.length \u4e14 0 <= j < nums2.length\uff09\u3002
    4. \n
    \n\n

    \u5b9e\u73b0 FindSumPairs \u7c7b\uff1a

    \n\n
      \n\t
    • FindSumPairs(int[] nums1, int[] nums2) \u4f7f\u7528\u6574\u6570\u6570\u7ec4\u00a0nums1 \u548c nums2 \u521d\u59cb\u5316 FindSumPairs \u5bf9\u8c61\u3002
    • \n\t
    • void add(int index, int val) \u5c06 val \u52a0\u5230 nums2[index] \u4e0a\uff0c\u5373\uff0c\u6267\u884c nums2[index] += val \u3002
    • \n\t
    • int count(int tot) \u8fd4\u56de\u6ee1\u8db3\u00a0nums1[i] + nums2[j] == tot \u7684\u4e0b\u6807\u5bf9 (i, j) \u6570\u76ee\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\n[\"FindSumPairs\", \"count\", \"add\", \"count\", \"count\", \"add\", \"add\", \"count\"]\n[[[1, 1, 2, 2, 2, 3], [1, 4, 5, 2, 5, 4]], [7], [3, 2], [8], [4], [0, 1], [1, 1], [7]]\n\u8f93\u51fa\uff1a\n[null, 8, null, 2, 1, null, null, 11]\n\n\u89e3\u91ca\uff1a\nFindSumPairs findSumPairs = new FindSumPairs([1, 1, 2, 2, 2, 3], [1, 4, 5, 2, 5, 4]);\nfindSumPairs.count(7);  // \u8fd4\u56de 8 ; \u4e0b\u6807\u5bf9 (2,2), (3,2), (4,2), (2,4), (3,4), (4,4) \u6ee1\u8db3 2 + 5 = 7 \uff0c\u4e0b\u6807\u5bf9 (5,1), (5,5) \u6ee1\u8db3 3 + 4 = 7\nfindSumPairs.add(3, 2); // \u6b64\u65f6 nums2 = [1,4,5,4,5,4]\nfindSumPairs.count(8);  // \u8fd4\u56de 2 \uff1b\u4e0b\u6807\u5bf9 (5,2), (5,4) \u6ee1\u8db3 3 + 5 = 8\nfindSumPairs.count(4);  // \u8fd4\u56de 1 \uff1b\u4e0b\u6807\u5bf9 (5,0) \u6ee1\u8db3 3 + 1 = 4\nfindSumPairs.add(0, 1); // \u6b64\u65f6 nums2 = [2,4,5,4,5,4]\nfindSumPairs.add(1, 1); // \u6b64\u65f6 nums2 = [2,5,5,4,5,4]\nfindSumPairs.count(7);  // \u8fd4\u56de 11 \uff1b\u4e0b\u6807\u5bf9 (2,1), (2,2), (2,4), (3,1), (3,2), (3,4), (4,1), (4,2), (4,4) \u6ee1\u8db3 2 + 5 = 7 \uff0c\u4e0b\u6807\u5bf9 (5,3), (5,5) \u6ee1\u8db3 3 + 4 = 7\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums1.length <= 1000
    • \n\t
    • 1 <= nums2.length <= 105
    • \n\t
    • 1 <= nums1[i] <= 109
    • \n\t
    • 1 <= nums2[i] <= 105
    • \n\t
    • 0 <= index < nums2.length
    • \n\t
    • 1 <= val <= 105
    • \n\t
    • 1 <= tot <= 109
    • \n\t
    • \u6700\u591a\u8c03\u7528\u00a0add \u548c count \u51fd\u6570\u5404 1000 \u6b21
    • \n
    \n", "tags_en": ["Design", "Hash Table", "Ordered Map"], "tags_cn": ["\u8bbe\u8ba1", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class FindSumPairs {\npublic:\n FindSumPairs(vector& nums1, vector& nums2) {\n\n }\n \n void add(int index, int val) {\n\n }\n \n int count(int tot) {\n\n }\n};\n\n/**\n * Your FindSumPairs object will be instantiated and called as such:\n * FindSumPairs* obj = new FindSumPairs(nums1, nums2);\n * obj->add(index,val);\n * int param_2 = obj->count(tot);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class FindSumPairs {\n\n public FindSumPairs(int[] nums1, int[] nums2) {\n\n }\n \n public void add(int index, int val) {\n\n }\n \n public int count(int tot) {\n\n }\n}\n\n/**\n * Your FindSumPairs object will be instantiated and called as such:\n * FindSumPairs obj = new FindSumPairs(nums1, nums2);\n * obj.add(index,val);\n * int param_2 = obj.count(tot);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class FindSumPairs(object):\n\n def __init__(self, nums1, nums2):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n \"\"\"\n\n\n def add(self, index, val):\n \"\"\"\n :type index: int\n :type val: int\n :rtype: None\n \"\"\"\n\n\n def count(self, tot):\n \"\"\"\n :type tot: int\n :rtype: int\n \"\"\"\n\n\n\n# Your FindSumPairs object will be instantiated and called as such:\n# obj = FindSumPairs(nums1, nums2)\n# obj.add(index,val)\n# param_2 = obj.count(tot)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class FindSumPairs:\n\n def __init__(self, nums1: List[int], nums2: List[int]):\n\n\n def add(self, index: int, val: int) -> None:\n\n\n def count(self, tot: int) -> int:\n\n\n\n# Your FindSumPairs object will be instantiated and called as such:\n# obj = FindSumPairs(nums1, nums2)\n# obj.add(index,val)\n# param_2 = obj.count(tot)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} FindSumPairs;\n\n\nFindSumPairs* findSumPairsCreate(int* nums1, int nums1Size, int* nums2, int nums2Size) {\n\n}\n\nvoid findSumPairsAdd(FindSumPairs* obj, int index, int val) {\n\n}\n\nint findSumPairsCount(FindSumPairs* obj, int tot) {\n\n}\n\nvoid findSumPairsFree(FindSumPairs* obj) {\n\n}\n\n/**\n * Your FindSumPairs struct will be instantiated and called as such:\n * FindSumPairs* obj = findSumPairsCreate(nums1, nums1Size, nums2, nums2Size);\n * findSumPairsAdd(obj, index, val);\n \n * int param_2 = findSumPairsCount(obj, tot);\n \n * findSumPairsFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class FindSumPairs {\n\n public FindSumPairs(int[] nums1, int[] nums2) {\n\n }\n \n public void Add(int index, int val) {\n\n }\n \n public int Count(int tot) {\n\n }\n}\n\n/**\n * Your FindSumPairs object will be instantiated and called as such:\n * FindSumPairs obj = new FindSumPairs(nums1, nums2);\n * obj.Add(index,val);\n * int param_2 = obj.Count(tot);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums1\n * @param {number[]} nums2\n */\nvar FindSumPairs = function(nums1, nums2) {\n\n};\n\n/** \n * @param {number} index \n * @param {number} val\n * @return {void}\n */\nFindSumPairs.prototype.add = function(index, val) {\n\n};\n\n/** \n * @param {number} tot\n * @return {number}\n */\nFindSumPairs.prototype.count = function(tot) {\n\n};\n\n/**\n * Your FindSumPairs object will be instantiated and called as such:\n * var obj = new FindSumPairs(nums1, nums2)\n * obj.add(index,val)\n * var param_2 = obj.count(tot)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class FindSumPairs\n\n=begin\n :type nums1: Integer[]\n :type nums2: Integer[]\n=end\n def initialize(nums1, nums2)\n\n end\n\n\n=begin\n :type index: Integer\n :type val: Integer\n :rtype: Void\n=end\n def add(index, val)\n\n end\n\n\n=begin\n :type tot: Integer\n :rtype: Integer\n=end\n def count(tot)\n\n end\n\n\nend\n\n# Your FindSumPairs object will be instantiated and called as such:\n# obj = FindSumPairs.new(nums1, nums2)\n# obj.add(index, val)\n# param_2 = obj.count(tot)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass FindSumPairs {\n\n init(_ nums1: [Int], _ nums2: [Int]) {\n\n }\n \n func add(_ index: Int, _ val: Int) {\n\n }\n \n func count(_ tot: Int) -> Int {\n\n }\n}\n\n/**\n * Your FindSumPairs object will be instantiated and called as such:\n * let obj = FindSumPairs(nums1, nums2)\n * obj.add(index, val)\n * let ret_2: Int = obj.count(tot)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type FindSumPairs struct {\n\n}\n\n\nfunc Constructor(nums1 []int, nums2 []int) FindSumPairs {\n\n}\n\n\nfunc (this *FindSumPairs) Add(index int, val int) {\n\n}\n\n\nfunc (this *FindSumPairs) Count(tot int) int {\n\n}\n\n\n/**\n * Your FindSumPairs object will be instantiated and called as such:\n * obj := Constructor(nums1, nums2);\n * obj.Add(index,val);\n * param_2 := obj.Count(tot);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class FindSumPairs(_nums1: Array[Int], _nums2: Array[Int]) {\n\n def add(index: Int, `val`: Int) {\n \n }\n\n def count(tot: Int): Int = {\n \n }\n\n}\n\n/**\n * Your FindSumPairs object will be instantiated and called as such:\n * var obj = new FindSumPairs(nums1, nums2)\n * obj.add(index,`val`)\n * var param_2 = obj.count(tot)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class FindSumPairs(nums1: IntArray, nums2: IntArray) {\n\n fun add(index: Int, `val`: Int) {\n\n }\n\n fun count(tot: Int): Int {\n\n }\n\n}\n\n/**\n * Your FindSumPairs object will be instantiated and called as such:\n * var obj = FindSumPairs(nums1, nums2)\n * obj.add(index,`val`)\n * var param_2 = obj.count(tot)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct FindSumPairs {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl FindSumPairs {\n\n fn new(nums1: Vec, nums2: Vec) -> Self {\n\n }\n \n fn add(&self, index: i32, val: i32) {\n\n }\n \n fn count(&self, tot: i32) -> i32 {\n\n }\n}\n\n/**\n * Your FindSumPairs object will be instantiated and called as such:\n * let obj = FindSumPairs::new(nums1, nums2);\n * obj.add(index, val);\n * let ret_2: i32 = obj.count(tot);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class FindSumPairs {\n /**\n * @param Integer[] $nums1\n * @param Integer[] $nums2\n */\n function __construct($nums1, $nums2) {\n\n }\n\n /**\n * @param Integer $index\n * @param Integer $val\n * @return NULL\n */\n function add($index, $val) {\n\n }\n\n /**\n * @param Integer $tot\n * @return Integer\n */\n function count($tot) {\n\n }\n}\n\n/**\n * Your FindSumPairs object will be instantiated and called as such:\n * $obj = FindSumPairs($nums1, $nums2);\n * $obj->add($index, $val);\n * $ret_2 = $obj->count($tot);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class FindSumPairs {\n constructor(nums1: number[], nums2: number[]) {\n\n }\n\n add(index: number, val: number): void {\n\n }\n\n count(tot: number): number {\n\n }\n}\n\n/**\n * Your FindSumPairs object will be instantiated and called as such:\n * var obj = new FindSumPairs(nums1, nums2)\n * obj.add(index,val)\n * var param_2 = obj.count(tot)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define find-sum-pairs%\n (class object%\n (super-new)\n\n ; nums1 : (listof exact-integer?)\n\n ; nums2 : (listof exact-integer?)\n (init-field\n nums1\n nums2)\n \n ; add : exact-integer? exact-integer? -> void?\n (define/public (add index val)\n\n )\n ; count : exact-integer? -> exact-integer?\n (define/public (count tot)\n\n )))\n\n;; Your find-sum-pairs% object will be instantiated and called as such:\n;; (define obj (new find-sum-pairs% [nums1 nums1] [nums2 nums2]))\n;; (send obj add index val)\n;; (define param_2 (send obj count tot))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1865](https://leetcode-cn.com/problems/finding-pairs-with-a-certain-sum)", "[\u627e\u51fa\u548c\u4e3a\u6307\u5b9a\u503c\u7684\u4e0b\u6807\u5bf9](/solution/1800-1899/1865.Finding%20Pairs%20With%20a%20Certain%20Sum/README.md)", "`\u8bbe\u8ba1`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1865](https://leetcode.com/problems/finding-pairs-with-a-certain-sum)", "[Finding Pairs With a Certain Sum](/solution/1800-1899/1865.Finding%20Pairs%20With%20a%20Certain%20Sum/README_EN.md)", "`Design`,`Hash Table`,`Ordered Map`", "Medium", ""]}, {"question_id": "1994", "frontend_question_id": "1864", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-number-of-swaps-to-make-the-binary-string-alternating", "url_en": "https://leetcode.com/problems/minimum-number-of-swaps-to-make-the-binary-string-alternating", "relative_path_cn": "/solution/1800-1899/1864.Minimum%20Number%20of%20Swaps%20to%20Make%20the%20Binary%20String%20Alternating/README.md", "relative_path_en": "/solution/1800-1899/1864.Minimum%20Number%20of%20Swaps%20to%20Make%20the%20Binary%20String%20Alternating/README_EN.md", "title_cn": "\u6784\u6210\u4ea4\u66ff\u5b57\u7b26\u4e32\u9700\u8981\u7684\u6700\u5c0f\u4ea4\u6362\u6b21\u6570", "title_en": "Minimum Number of Swaps to Make the Binary String Alternating", "question_title_slug": "minimum-number-of-swaps-to-make-the-binary-string-alternating", "content_en": "

    Given a binary string s, return the minimum number of character swaps to make it alternating, or -1 if it is impossible.

    \n\n

    The string is called alternating if no two adjacent characters are equal. For example, the strings "010" and "1010" are alternating, while the string "0100" is not.

    \n\n

    Any two characters may be swapped, even if they are not adjacent.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "111000"\nOutput: 1\nExplanation: Swap positions 1 and 4: "111000" -> "101010"\nThe string is now alternating.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "010"\nOutput: 0\nExplanation: The string is already alternating, no swaps are needed.\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "1110"\nOutput: -1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 1000
    • \n\t
    • s[i] is either '0' or '1'.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32 s \uff0c\u73b0\u9700\u8981\u5c06\u5176\u8f6c\u5316\u4e3a\u4e00\u4e2a \u4ea4\u66ff\u5b57\u7b26\u4e32 \u3002\u8bf7\u4f60\u8ba1\u7b97\u5e76\u8fd4\u56de\u8f6c\u5316\u6240\u9700\u7684 \u6700\u5c0f \u5b57\u7b26\u4ea4\u6362\u6b21\u6570\uff0c\u5982\u679c\u65e0\u6cd5\u5b8c\u6210\u8f6c\u5316\uff0c\u8fd4\u56de -1 \u3002

    \n\n

    \u4ea4\u66ff\u5b57\u7b26\u4e32 \u662f\u6307\uff1a\u76f8\u90bb\u5b57\u7b26\u4e4b\u95f4\u4e0d\u5b58\u5728\u76f8\u7b49\u60c5\u51b5\u7684\u5b57\u7b26\u4e32\u3002\u4f8b\u5982\uff0c\u5b57\u7b26\u4e32 \"010\" \u548c \"1010\" \u5c5e\u4e8e\u4ea4\u66ff\u5b57\u7b26\u4e32\uff0c\u4f46 \"0100\" \u4e0d\u662f\u3002

    \n\n

    \u4efb\u610f\u4e24\u4e2a\u5b57\u7b26\u90fd\u53ef\u4ee5\u8fdb\u884c\u4ea4\u6362\uff0c\u4e0d\u5fc5\u76f8\u90bb \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"111000\"\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u4ea4\u6362\u4f4d\u7f6e 1 \u548c 4\uff1a\"111000\" -> \"101010\" \uff0c\u5b57\u7b26\u4e32\u53d8\u4e3a\u4ea4\u66ff\u5b57\u7b26\u4e32\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"010\"\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u5b57\u7b26\u4e32\u5df2\u7ecf\u662f\u4ea4\u66ff\u5b57\u7b26\u4e32\u4e86\uff0c\u4e0d\u9700\u8981\u4ea4\u6362\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"1110\"\n\u8f93\u51fa\uff1a-1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 1000
    • \n\t
    • s[i] \u7684\u503c\u4e3a '0' \u6216 '1'
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minSwaps(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minSwaps(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minSwaps(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minSwaps(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minSwaps(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinSwaps(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar minSwaps = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef min_swaps(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minSwaps(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minSwaps(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minSwaps(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minSwaps(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_swaps(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function minSwaps($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minSwaps(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-swaps s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1864](https://leetcode-cn.com/problems/minimum-number-of-swaps-to-make-the-binary-string-alternating)", "[\u6784\u6210\u4ea4\u66ff\u5b57\u7b26\u4e32\u9700\u8981\u7684\u6700\u5c0f\u4ea4\u6362\u6b21\u6570](/solution/1800-1899/1864.Minimum%20Number%20of%20Swaps%20to%20Make%20the%20Binary%20String%20Alternating/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1864](https://leetcode.com/problems/minimum-number-of-swaps-to-make-the-binary-string-alternating)", "[Minimum Number of Swaps to Make the Binary String Alternating](/solution/1800-1899/1864.Minimum%20Number%20of%20Swaps%20to%20Make%20the%20Binary%20String%20Alternating/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1993", "frontend_question_id": "1863", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sum-of-all-subset-xor-totals", "url_en": "https://leetcode.com/problems/sum-of-all-subset-xor-totals", "relative_path_cn": "/solution/1800-1899/1863.Sum%20of%20All%20Subset%20XOR%20Totals/README.md", "relative_path_en": "/solution/1800-1899/1863.Sum%20of%20All%20Subset%20XOR%20Totals/README_EN.md", "title_cn": "\u627e\u51fa\u6240\u6709\u5b50\u96c6\u7684\u5f02\u6216\u603b\u548c\u518d\u6c42\u548c", "title_en": "Sum of All Subset XOR Totals", "question_title_slug": "sum-of-all-subset-xor-totals", "content_en": "

    The XOR total of an array is defined as the bitwise XOR of all its elements, or 0 if the array is empty.

    \n\n
      \n\t
    • For example, the XOR total of the array [2,5,6] is 2 XOR 5 XOR 6 = 1.
    • \n
    \n\n

    Given an array nums, return the sum of all XOR totals for every subset of nums

    \n\n

    Note: Subsets with the same elements should be counted multiple times.

    \n\n

    An array a is a subset of an array b if a can be obtained from b by deleting some (possibly zero) elements of b.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,3]\nOutput: 6\nExplanation: The 4 subsets of [1,3] are:\n- The empty subset has an XOR total of 0.\n- [1] has an XOR total of 1.\n- [3] has an XOR total of 3.\n- [1,3] has an XOR total of 1 XOR 3 = 2.\n0 + 1 + 3 + 2 = 6\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [5,1,6]\nOutput: 28\nExplanation: The 8 subsets of [5,1,6] are:\n- The empty subset has an XOR total of 0.\n- [5] has an XOR total of 5.\n- [1] has an XOR total of 1.\n- [6] has an XOR total of 6.\n- [5,1] has an XOR total of 5 XOR 1 = 4.\n- [5,6] has an XOR total of 5 XOR 6 = 3.\n- [1,6] has an XOR total of 1 XOR 6 = 7.\n- [5,1,6] has an XOR total of 5 XOR 1 XOR 6 = 2.\n0 + 5 + 1 + 6 + 4 + 3 + 7 + 2 = 28\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [3,4,5,6,7,8]\nOutput: 480\nExplanation: The sum of all XOR totals for every subset is 480.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 12
    • \n\t
    • 1 <= nums[i] <= 20
    • \n
    \n", "content_cn": "

    \u4e00\u4e2a\u6570\u7ec4\u7684 \u5f02\u6216\u603b\u548c \u5b9a\u4e49\u4e3a\u6570\u7ec4\u4e2d\u6240\u6709\u5143\u7d20\u6309\u4f4d XOR \u7684\u7ed3\u679c\uff1b\u5982\u679c\u6570\u7ec4\u4e3a \u7a7a \uff0c\u5219\u5f02\u6216\u603b\u548c\u4e3a 0 \u3002

    \n\n
      \n\t
    • \u4f8b\u5982\uff0c\u6570\u7ec4\u00a0[2,5,6] \u7684 \u5f02\u6216\u603b\u548c \u4e3a 2 XOR 5 XOR 6 = 1 \u3002
    • \n
    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 nums \uff0c\u8bf7\u4f60\u6c42\u51fa nums \u4e2d\u6bcf\u4e2a \u5b50\u96c6 \u7684 \u5f02\u6216\u603b\u548c \uff0c\u8ba1\u7b97\u5e76\u8fd4\u56de\u8fd9\u4e9b\u503c\u76f8\u52a0\u4e4b \u548c \u3002

    \n\n

    \u6ce8\u610f\uff1a\u5728\u672c\u9898\u4e2d\uff0c\u5143\u7d20 \u76f8\u540c \u7684\u4e0d\u540c\u5b50\u96c6\u5e94 \u591a\u6b21 \u8ba1\u6570\u3002

    \n\n

    \u6570\u7ec4 a \u662f\u6570\u7ec4 b \u7684\u4e00\u4e2a \u5b50\u96c6 \u7684\u524d\u63d0\u6761\u4ef6\u662f\uff1a\u4ece b \u5220\u9664\u51e0\u4e2a\uff08\u4e5f\u53ef\u80fd\u4e0d\u5220\u9664\uff09\u5143\u7d20\u80fd\u591f\u5f97\u5230 a \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,3]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a[1,3] \u5171\u6709 4 \u4e2a\u5b50\u96c6\uff1a\n- \u7a7a\u5b50\u96c6\u7684\u5f02\u6216\u603b\u548c\u662f 0 \u3002\n- [1] \u7684\u5f02\u6216\u603b\u548c\u4e3a 1 \u3002\n- [3] \u7684\u5f02\u6216\u603b\u548c\u4e3a 3 \u3002\n- [1,3] \u7684\u5f02\u6216\u603b\u548c\u4e3a 1 XOR 3 = 2 \u3002\n0 + 1 + 3 + 2 = 6\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [5,1,6]\n\u8f93\u51fa\uff1a28\n\u89e3\u91ca\uff1a[5,1,6] \u5171\u6709 8 \u4e2a\u5b50\u96c6\uff1a\n- \u7a7a\u5b50\u96c6\u7684\u5f02\u6216\u603b\u548c\u662f 0 \u3002\n- [5] \u7684\u5f02\u6216\u603b\u548c\u4e3a 5 \u3002\n- [1] \u7684\u5f02\u6216\u603b\u548c\u4e3a 1 \u3002\n- [6] \u7684\u5f02\u6216\u603b\u548c\u4e3a 6 \u3002\n- [5,1] \u7684\u5f02\u6216\u603b\u548c\u4e3a 5 XOR 1 = 4 \u3002\n- [5,6] \u7684\u5f02\u6216\u603b\u548c\u4e3a 5 XOR 6 = 3 \u3002\n- [1,6] \u7684\u5f02\u6216\u603b\u548c\u4e3a 1 XOR 6 = 7 \u3002\n- [5,1,6] \u7684\u5f02\u6216\u603b\u548c\u4e3a 5 XOR 1 XOR 6 = 2 \u3002\n0 + 5 + 1 + 6 + 4 + 3 + 7 + 2 = 28\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [3,4,5,6,7,8]\n\u8f93\u51fa\uff1a480\n\u89e3\u91ca\uff1a\u6bcf\u4e2a\u5b50\u96c6\u7684\u5168\u90e8\u5f02\u6216\u603b\u548c\u503c\u4e4b\u548c\u4e3a 480 \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 12
    • \n\t
    • 1 <= nums[i] <= 20
    • \n
    \n", "tags_en": ["Recursion", "Backtracking"], "tags_cn": ["\u9012\u5f52", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int subsetXORSum(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int subsetXORSum(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def subsetXORSum(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def subsetXORSum(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint subsetXORSum(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SubsetXORSum(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar subsetXORSum = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef subset_xor_sum(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func subsetXORSum(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func subsetXORSum(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def subsetXORSum(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun subsetXORSum(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn subset_xor_sum(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function subsetXORSum($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function subsetXORSum(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (subset-xor-sum nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1863](https://leetcode-cn.com/problems/sum-of-all-subset-xor-totals)", "[\u627e\u51fa\u6240\u6709\u5b50\u96c6\u7684\u5f02\u6216\u603b\u548c\u518d\u6c42\u548c](/solution/1800-1899/1863.Sum%20of%20All%20Subset%20XOR%20Totals/README.md)", "`\u9012\u5f52`,`\u56de\u6eaf\u7b97\u6cd5`", "\u7b80\u5355", ""], "md_table_row_en": ["[1863](https://leetcode.com/problems/sum-of-all-subset-xor-totals)", "[Sum of All Subset XOR Totals](/solution/1800-1899/1863.Sum%20of%20All%20Subset%20XOR%20Totals/README_EN.md)", "`Recursion`,`Backtracking`", "Easy", ""]}, {"question_id": "1991", "frontend_question_id": "1841", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/league-statistics", "url_en": "https://leetcode.com/problems/league-statistics", "relative_path_cn": "/solution/1800-1899/1841.League%20Statistics/README.md", "relative_path_en": "/solution/1800-1899/1841.League%20Statistics/README_EN.md", "title_cn": "", "title_en": "League Statistics", "question_title_slug": "league-statistics", "content_en": "

    Table: Teams

    \r\n\r\n
    \r\n+----------------+---------+\r\n| Column Name    | Type    |\r\n+----------------+---------+\r\n| team_id        | int     |\r\n| team_name      | varchar |\r\n+----------------+---------+\r\nteam_id is the primary key for this table.\r\nEach row contains information about one team in the league.\r\n
    \r\n\r\n

     

    \r\n\r\n

    Table: Matches

    \r\n\r\n
    \r\n+-----------------+---------+\r\n| Column Name     | Type    |\r\n+-----------------+---------+\r\n| home_team_id    | int     |\r\n| away_team_id    | int     |\r\n| home_team_goals | int     |\r\n| away_team_goals | int     |\r\n+-----------------+---------+\r\n(home_team_id, away_team_id) is the primary key for this table.\r\nEach row contains information about one match.\r\nhome_team_goals is the number of goals scored by the home team.\r\naway_team_goals is the number of goals scored by the away team.\r\nThe winner of the match is the team with the higher number of goals.\r\n
    \r\n\r\n

     

    \r\n\r\n

    Write an SQL query to report the statistics of the league. The statistics should be built using the played matches where the winning team gets three points and the losing team gets no points. If a match ends with a draw, both teams get one point.

    \r\n\r\n

    Each row of the result table should contain:

    \r\n\r\n
      \r\n\t
    • team_name - The name of the team in the Teams table.
    • \r\n\t
    • matches_played - The number of matches played as either a home or away team.
    • \r\n\t
    • points - The total points the team has so far.
    • \r\n\t
    • goal_for - The total number of goals scored by the team across all matches.
    • \r\n\t
    • goal_against - The total number of goals scored by opponent teams against this team across all matches.
    • \r\n\t
    • goal_diff - The result of goal_for - goal_against.
    • \r\n
    \r\n\r\n

    Return the result table in descending order by points. If two or more teams have the same points, order them in descending order by goal_diff. If there is still a tie, order them by team_name in lexicographical order.

    \r\n\r\n

    The query result format is in the following example:

    \r\n\r\n

     

    \r\n\r\n
    \r\nTeams table:\r\n+---------+-----------+\r\n| team_id | team_name |\r\n+---------+-----------+\r\n| 1       | Ajax      |\r\n| 4       | Dortmund  |\r\n| 6       | Arsenal   |\r\n+---------+-----------+\r\n\r\nMatches table:\r\n+--------------+--------------+-----------------+-----------------+\r\n| home_team_id | away_team_id | home_team_goals | away_team_goals |\r\n+--------------+--------------+-----------------+-----------------+\r\n| 1            | 4            | 0               | 1               |\r\n| 1            | 6            | 3               | 3               |\r\n| 4            | 1            | 5               | 2               |\r\n| 6            | 1            | 0               | 0               |\r\n+--------------+--------------+-----------------+-----------------+\r\n\r\n\r\nResult table:\r\n+-----------+----------------+--------+----------+--------------+-----------+\r\n| team_name | matches_played | points | goal_for | goal_against | goal_diff |\r\n+-----------+----------------+--------+----------+--------------+-----------+\r\n| Dortmund  | 2              | 6      | 6        | 2            | 4         |\r\n| Arsenal   | 2              | 2      | 3        | 3            | 0         |\r\n| Ajax      | 4              | 2      | 5        | 9            | -4        |\r\n+-----------+----------------+--------+----------+--------------+-----------+\r\n\r\nAjax (team_id=1) played 4 matches: 2 losses and 2 draws. Total points = 0 + 0 + 1 + 1 = 2.\r\nDortmund (team_id=4) played 2 matches: 2 wins. Total points = 3 + 3 = 6.\r\nArsenal (team_id=6) played 2 matches: 2 draws. Total points = 1 + 1 = 2.\r\nDortmund is the first team in the table. Ajax and Arsenal have the same points, but since Arsenal has a higher goal_diff than Ajax, Arsenal comes before Ajax in the table.\r\n
    ", "content_cn": null, "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1841](https://leetcode-cn.com/problems/league-statistics)", "[League Statistics](/solution/1800-1899/1841.League%20Statistics/README_EN.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1841](https://leetcode.com/problems/league-statistics)", "[League Statistics](/solution/1800-1899/1841.League%20Statistics/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1990", "frontend_question_id": "1878", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/get-biggest-three-rhombus-sums-in-a-grid", "url_en": "https://leetcode.com/problems/get-biggest-three-rhombus-sums-in-a-grid", "relative_path_cn": "/solution/1800-1899/1878.Get%20Biggest%20Three%20Rhombus%20Sums%20in%20a%20Grid/README.md", "relative_path_en": "/solution/1800-1899/1878.Get%20Biggest%20Three%20Rhombus%20Sums%20in%20a%20Grid/README_EN.md", "title_cn": "\u77e9\u9635\u4e2d\u6700\u5927\u7684\u4e09\u4e2a\u83f1\u5f62\u548c", "title_en": "Get Biggest Three Rhombus Sums in a Grid", "question_title_slug": "get-biggest-three-rhombus-sums-in-a-grid", "content_en": "

    You are given an m x n integer matrix grid\u200b\u200b\u200b.

    \n\n

    A rhombus sum is the sum of the elements that form the border of a regular rhombus shape in grid\u200b\u200b\u200b. The rhombus must have the shape of a square rotated 45 degrees with each of the corners centered in a grid cell. Below is an image of four valid rhombus shapes with the corresponding colored cells that should be included in each rhombus sum:

    \n\"\"\n

    Note that the rhombus can have an area of 0, which is depicted by the purple rhombus in the bottom right corner.

    \n\n

    Return the biggest three distinct rhombus sums in the grid in descending order. If there are less than three distinct values, return all of them.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: grid = [[3,4,5,1,3],[3,3,4,2,3],[20,30,200,40,10],[1,5,5,4,1],[4,3,2,2,5]]\nOutput: [228,216,211]\nExplanation: The rhombus shapes for the three biggest distinct rhombus sums are depicted above.\n- Blue: 20 + 3 + 200 + 5 = 228\n- Red: 200 + 2 + 10 + 4 = 216\n- Green: 5 + 200 + 4 + 2 = 211\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: grid = [[1,2,3],[4,5,6],[7,8,9]]\nOutput: [20,9,8]\nExplanation: The rhombus shapes for the three biggest distinct rhombus sums are depicted above.\n- Blue: 4 + 2 + 6 + 8 = 20\n- Red: 9 (area 0 rhombus in the bottom right corner)\n- Green: 8 (area 0 rhombus in the bottom middle)\n
    \n\n

    Example 3:

    \n\n
    \nInput: grid = [[7,7,7]]\nOutput: [7]\nExplanation: All three possible rhombus sums are the same, so return [7].\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= m, n <= 50
    • \n\t
    • 1 <= grid[i][j] <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u00a0m x n\u00a0\u7684\u6574\u6570\u77e9\u9635\u00a0grid\u00a0\u3002

    \n\n

    \u83f1\u5f62\u548c \u6307\u7684\u662f grid\u00a0\u4e2d\u4e00\u4e2a\u6b63\u83f1\u5f62 \u8fb9\u754c\u00a0\u4e0a\u7684\u5143\u7d20\u4e4b\u548c\u3002\u672c\u9898\u4e2d\u7684\u83f1\u5f62\u5fc5\u987b\u4e3a\u6b63\u65b9\u5f62\u65cb\u8f6c45\u5ea6\uff0c\u4e14\u56db\u4e2a\u89d2\u90fd\u5728\u4e00\u4e2a\u683c\u5b50\u5f53\u4e2d\u3002\u4e0b\u56fe\u662f\u56db\u4e2a\u53ef\u884c\u7684\u83f1\u5f62\uff0c\u6bcf\u4e2a\u83f1\u5f62\u548c\u5e94\u8be5\u5305\u542b\u7684\u683c\u5b50\u90fd\u7528\u4e86\u76f8\u5e94\u989c\u8272\u6807\u6ce8\u5728\u56fe\u4e2d\u3002

    \n\"\"\n

    \u00a0

    \n\n

    \u6ce8\u610f\uff0c\u83f1\u5f62\u53ef\u4ee5\u662f\u4e00\u4e2a\u9762\u79ef\u4e3a 0 \u7684\u533a\u57df\uff0c\u5982\u4e0a\u56fe\u4e2d\u53f3\u4e0b\u89d2\u7684\u7d2b\u8272\u83f1\u5f62\u6240\u793a\u3002

    \n\n

    \u8bf7\u4f60\u6309\u7167 \u964d\u5e8f\u00a0\u8fd4\u56de grid\u00a0\u4e2d\u4e09\u4e2a\u6700\u5927\u7684\u00a0\u4e92\u4e0d\u76f8\u540c\u7684\u83f1\u5f62\u548c\u00a0\u3002\u5982\u679c\u4e0d\u540c\u7684\u548c\u5c11\u4e8e\u4e09\u4e2a\uff0c\u5219\u5c06\u5b83\u4eec\u5168\u90e8\u8fd4\u56de\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1agrid = [[3,4,5,1,3],[3,3,4,2,3],[20,30,200,40,10],[1,5,5,4,1],[4,3,2,2,5]]\n\u8f93\u51fa\uff1a[228,216,211]\n\u89e3\u91ca\uff1a\u6700\u5927\u7684\u4e09\u4e2a\u83f1\u5f62\u548c\u5982\u4e0a\u56fe\u6240\u793a\u3002\n- \u84dd\u8272\uff1a20 + 3 + 200 + 5 = 228\n- \u7ea2\u8272\uff1a200 + 2 + 10 + 4 = 216\n- \u7eff\u8272\uff1a5 + 200 + 4 + 2 = 211\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1agrid = [[1,2,3],[4,5,6],[7,8,9]]\n\u8f93\u51fa\uff1a[20,9,8]\n\u89e3\u91ca\uff1a\u6700\u5927\u7684\u4e09\u4e2a\u83f1\u5f62\u548c\u5982\u4e0a\u56fe\u6240\u793a\u3002\n- \u84dd\u8272\uff1a4 + 2 + 6 + 8 = 20\n- \u7ea2\u8272\uff1a9 \uff08\u53f3\u4e0b\u89d2\u7ea2\u8272\u7684\u9762\u79ef\u4e3a 0 \u7684\u83f1\u5f62\uff09\n- \u7eff\u8272\uff1a8 \uff08\u4e0b\u65b9\u4e2d\u592e\u9762\u79ef\u4e3a 0 \u7684\u83f1\u5f62\uff09\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1agrid = [[7,7,7]]\n\u8f93\u51fa\uff1a[7]\n\u89e3\u91ca\uff1a\u6240\u6709\u4e09\u4e2a\u53ef\u80fd\u7684\u83f1\u5f62\u548c\u90fd\u76f8\u540c\uff0c\u6240\u4ee5\u8fd4\u56de [7] \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= m, n <= 100
    • \n\t
    • 1 <= grid[i][j] <= 105
    • \n
    \n", "tags_en": ["Array", "Math"], "tags_cn": ["\u6570\u7ec4", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector getBiggestThree(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] getBiggestThree(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getBiggestThree(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getBiggestThree(self, grid: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* getBiggestThree(int** grid, int gridSize, int* gridColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] GetBiggestThree(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number[]}\n */\nvar getBiggestThree = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer[]}\ndef get_biggest_three(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getBiggestThree(_ grid: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getBiggestThree(grid [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getBiggestThree(grid: Array[Array[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getBiggestThree(grid: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_biggest_three(grid: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer[]\n */\n function getBiggestThree($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getBiggestThree(grid: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-biggest-three grid)\n (-> (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1878](https://leetcode-cn.com/problems/get-biggest-three-rhombus-sums-in-a-grid)", "[\u77e9\u9635\u4e2d\u6700\u5927\u7684\u4e09\u4e2a\u83f1\u5f62\u548c](/solution/1800-1899/1878.Get%20Biggest%20Three%20Rhombus%20Sums%20in%20a%20Grid/README.md)", "`\u6570\u7ec4`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1878](https://leetcode.com/problems/get-biggest-three-rhombus-sums-in-a-grid)", "[Get Biggest Three Rhombus Sums in a Grid](/solution/1800-1899/1878.Get%20Biggest%20Three%20Rhombus%20Sums%20in%20a%20Grid/README_EN.md)", "`Array`,`Math`", "Medium", ""]}, {"question_id": "1989", "frontend_question_id": "1879", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-xor-sum-of-two-arrays", "url_en": "https://leetcode.com/problems/minimum-xor-sum-of-two-arrays", "relative_path_cn": "/solution/1800-1899/1879.Minimum%20XOR%20Sum%20of%20Two%20Arrays/README.md", "relative_path_en": "/solution/1800-1899/1879.Minimum%20XOR%20Sum%20of%20Two%20Arrays/README_EN.md", "title_cn": "\u4e24\u4e2a\u6570\u7ec4\u6700\u5c0f\u7684\u5f02\u6216\u503c\u4e4b\u548c", "title_en": "Minimum XOR Sum of Two Arrays", "question_title_slug": "minimum-xor-sum-of-two-arrays", "content_en": "

    You are given two integer arrays nums1 and nums2 of length n.

    \n\n

    The XOR sum of the two integer arrays is (nums1[0] XOR nums2[0]) + (nums1[1] XOR nums2[1]) + ... + (nums1[n - 1] XOR nums2[n - 1]) (0-indexed).

    \n\n
      \n\t
    • For example, the XOR sum of [1,2,3] and [3,2,1] is equal to (1 XOR 3) + (2 XOR 2) + (3 XOR 1) = 2 + 0 + 2 = 4.
    • \n
    \n\n

    Rearrange the elements of nums2 such that the resulting XOR sum is minimized.

    \n\n

    Return the XOR sum after the rearrangement.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums1 = [1,2], nums2 = [2,3]\nOutput: 2\nExplanation: Rearrange nums2 so that it becomes [3,2].\nThe XOR sum is (1 XOR 3) + (2 XOR 2) = 2 + 0 = 2.
    \n\n

    Example 2:

    \n\n
    \nInput: nums1 = [1,0,3], nums2 = [5,3,4]\nOutput: 8\nExplanation: Rearrange nums2 so that it becomes [5,4,3]. \nThe XOR sum is (1 XOR 5) + (0 XOR 4) + (3 XOR 3) = 4 + 4 + 0 = 8.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == nums1.length
    • \n\t
    • n == nums2.length
    • \n\t
    • 1 <= n <= 14
    • \n\t
    • 0 <= nums1[i], nums2[i] <= 107
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u6574\u6570\u6570\u7ec4\u00a0nums1 \u548c\u00a0nums2\u00a0\uff0c\u5b83\u4eec\u957f\u5ea6\u90fd\u4e3a\u00a0n\u00a0\u3002

    \n\n

    \u4e24\u4e2a\u6570\u7ec4\u7684 \u5f02\u6216\u503c\u4e4b\u548c\u00a0\u4e3a\u00a0(nums1[0] XOR nums2[0]) + (nums1[1] XOR nums2[1]) + ... + (nums1[n - 1] XOR nums2[n - 1])\u00a0\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\u3002

    \n\n
      \n\t
    • \u6bd4\u65b9\u8bf4\uff0c[1,2,3] \u548c\u00a0[3,2,1]\u00a0\u7684 \u5f02\u6216\u503c\u4e4b\u548c\u00a0\u7b49\u4e8e\u00a0(1 XOR 3) + (2 XOR 2) + (3 XOR 1) = 2 + 0 + 2 = 4\u00a0\u3002
    • \n
    \n\n

    \u8bf7\u4f60\u5c06\u00a0nums2\u00a0\u4e2d\u7684\u5143\u7d20\u91cd\u65b0\u6392\u5217\uff0c\u4f7f\u5f97 \u5f02\u6216\u503c\u4e4b\u548c\u00a0\u6700\u5c0f\u00a0\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u91cd\u65b0\u6392\u5217\u4e4b\u540e\u7684 \u5f02\u6216\u503c\u4e4b\u548c\u00a0\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anums1 = [1,2], nums2 = [2,3]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5c06 nums2 \u91cd\u65b0\u6392\u5217\u5f97\u5230 [3,2] \u3002\n\u5f02\u6216\u503c\u4e4b\u548c\u4e3a (1 XOR 3) + (2 XOR 2) = 2 + 0 = 2 \u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anums1 = [1,0,3], nums2 = [5,3,4]\n\u8f93\u51fa\uff1a8\n\u89e3\u91ca\uff1a\u5c06 nums2 \u91cd\u65b0\u6392\u5217\u5f97\u5230 [5,4,3] \u3002\n\u5f02\u6216\u503c\u4e4b\u548c\u4e3a (1 XOR 5) + (0 XOR 4) + (3 XOR 3) = 4 + 4 + 0 = 8 \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == nums1.length
    • \n\t
    • n == nums2.length
    • \n\t
    • 1 <= n <= 14
    • \n\t
    • 0 <= nums1[i], nums2[i] <= 107
    • \n
    \n", "tags_en": ["Bit Manipulation", "Dynamic Programming"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minimumXORSum(vector& nums1, vector& nums2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minimumXORSum(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimumXORSum(self, nums1, nums2):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimumXORSum(self, nums1: List[int], nums2: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minimumXORSum(int* nums1, int nums1Size, int* nums2, int nums2Size){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinimumXORSum(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums1\n * @param {number[]} nums2\n * @return {number}\n */\nvar minimumXORSum = function(nums1, nums2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums1\n# @param {Integer[]} nums2\n# @return {Integer}\ndef minimum_xor_sum(nums1, nums2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimumXORSum(_ nums1: [Int], _ nums2: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimumXORSum(nums1 []int, nums2 []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimumXORSum(nums1: Array[Int], nums2: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimumXORSum(nums1: IntArray, nums2: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimum_xor_sum(nums1: Vec, nums2: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums1\n * @param Integer[] $nums2\n * @return Integer\n */\n function minimumXORSum($nums1, $nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimumXORSum(nums1: number[], nums2: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimum-xor-sum nums1 nums2)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1879](https://leetcode-cn.com/problems/minimum-xor-sum-of-two-arrays)", "[\u4e24\u4e2a\u6570\u7ec4\u6700\u5c0f\u7684\u5f02\u6216\u503c\u4e4b\u548c](/solution/1800-1899/1879.Minimum%20XOR%20Sum%20of%20Two%20Arrays/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1879](https://leetcode.com/problems/minimum-xor-sum-of-two-arrays)", "[Minimum XOR Sum of Two Arrays](/solution/1800-1899/1879.Minimum%20XOR%20Sum%20of%20Two%20Arrays/README_EN.md)", "`Bit Manipulation`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "1988", "frontend_question_id": "1877", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimize-maximum-pair-sum-in-array", "url_en": "https://leetcode.com/problems/minimize-maximum-pair-sum-in-array", "relative_path_cn": "/solution/1800-1899/1877.Minimize%20Maximum%20Pair%20Sum%20in%20Array/README.md", "relative_path_en": "/solution/1800-1899/1877.Minimize%20Maximum%20Pair%20Sum%20in%20Array/README_EN.md", "title_cn": "\u6570\u7ec4\u4e2d\u6700\u5927\u6570\u5bf9\u548c\u7684\u6700\u5c0f\u503c", "title_en": "Minimize Maximum Pair Sum in Array", "question_title_slug": "minimize-maximum-pair-sum-in-array", "content_en": "

    The pair sum of a pair (a,b) is equal to a + b. The maximum pair sum is the largest pair sum in a list of pairs.

    \r\n\r\n
      \r\n\t
    • For example, if we have pairs (1,5), (2,3), and (4,4), the maximum pair sum would be max(1+5, 2+3, 4+4) = max(6, 5, 8) = 8.
    • \r\n
    \r\n\r\n

    Given an array nums of even length n, pair up the elements of nums into n / 2 pairs such that:

    \r\n\r\n
      \r\n\t
    • Each element of nums is in exactly one pair, and
    • \r\n\t
    • The maximum pair sum is minimized.
    • \r\n
    \r\n\r\n

    Return the minimized maximum pair sum after optimally pairing up the elements.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: nums = [3,5,2,3]\r\nOutput: 7\r\nExplanation: The elements can be paired up into pairs (3,3) and (5,2).\r\nThe maximum pair sum is max(3+3, 5+2) = max(6, 7) = 7.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: nums = [3,5,4,2,4,6]\r\nOutput: 8\r\nExplanation: The elements can be paired up into pairs (3,5), (4,4), and (6,2).\r\nThe maximum pair sum is max(3+5, 4+4, 6+2) = max(8, 8, 8) = 8.\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • n == nums.length
    • \r\n\t
    • 2 <= n <= 105
    • \r\n\t
    • n is even.
    • \r\n\t
    • 1 <= nums[i] <= 105
    • \r\n
    ", "content_cn": "

    \u4e00\u4e2a\u6570\u5bf9\u00a0(a,b)\u00a0\u7684 \u6570\u5bf9\u548c\u00a0\u7b49\u4e8e\u00a0a + b\u00a0\u3002\u6700\u5927\u6570\u5bf9\u548c\u00a0\u662f\u4e00\u4e2a\u6570\u5bf9\u6570\u7ec4\u4e2d\u6700\u5927\u7684\u00a0\u6570\u5bf9\u548c\u00a0\u3002

    \n\n
      \n\t
    • \u6bd4\u65b9\u8bf4\uff0c\u5982\u679c\u6211\u4eec\u6709\u6570\u5bf9\u00a0(1,5)\u00a0\uff0c(2,3)\u00a0\u548c\u00a0(4,4)\uff0c\u6700\u5927\u6570\u5bf9\u548c\u00a0\u4e3a\u00a0max(1+5, 2+3, 4+4) = max(6, 5, 8) = 8\u00a0\u3002
    • \n
    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u4e3a \u5076\u6570\u00a0n\u00a0\u7684\u6570\u7ec4\u00a0nums\u00a0\uff0c\u8bf7\u4f60\u5c06 nums\u00a0\u4e2d\u7684\u5143\u7d20\u5206\u6210 n / 2\u00a0\u4e2a\u6570\u5bf9\uff0c\u4f7f\u5f97\uff1a

    \n\n
      \n\t
    • nums\u00a0\u4e2d\u6bcf\u4e2a\u5143\u7d20\u00a0\u6070\u597d\u00a0\u5728 \u4e00\u4e2a\u00a0\u6570\u5bf9\u4e2d\uff0c\u4e14
    • \n\t
    • \u6700\u5927\u6570\u5bf9\u548c\u00a0\u7684\u503c \u6700\u5c0f\u00a0\u3002
    • \n
    \n\n

    \u8bf7\u4f60\u5728\u6700\u4f18\u6570\u5bf9\u5212\u5206\u7684\u65b9\u6848\u4e0b\uff0c\u8fd4\u56de\u6700\u5c0f\u7684 \u6700\u5927\u6570\u5bf9\u548c\u00a0\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [3,5,2,3]\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u53ef\u4ee5\u5206\u4e3a\u6570\u5bf9 (3,3) \u548c (5,2) \u3002\n\u6700\u5927\u6570\u5bf9\u548c\u4e3a max(3+3, 5+2) = max(6, 7) = 7 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [3,5,4,2,4,6]\n\u8f93\u51fa\uff1a8\n\u89e3\u91ca\uff1a\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u53ef\u4ee5\u5206\u4e3a\u6570\u5bf9 (3,5)\uff0c(4,4) \u548c (6,2) \u3002\n\u6700\u5927\u6570\u5bf9\u548c\u4e3a max(3+5, 4+4, 6+2) = max(8, 8, 8) = 8 \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 2 <= n <= 105
    • \n\t
    • n\u00a0\u662f \u5076\u6570\u00a0\u3002
    • \n\t
    • 1 <= nums[i] <= 105
    • \n
    \n", "tags_en": ["Greedy", "Sort"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6392\u5e8f"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minPairSum(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minPairSum(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minPairSum(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minPairSum(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minPairSum(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinPairSum(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar minPairSum = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef min_pair_sum(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minPairSum(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minPairSum(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minPairSum(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minPairSum(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_pair_sum(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function minPairSum($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minPairSum(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-pair-sum nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1877](https://leetcode-cn.com/problems/minimize-maximum-pair-sum-in-array)", "[\u6570\u7ec4\u4e2d\u6700\u5927\u6570\u5bf9\u548c\u7684\u6700\u5c0f\u503c](/solution/1800-1899/1877.Minimize%20Maximum%20Pair%20Sum%20in%20Array/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6392\u5e8f`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1877](https://leetcode.com/problems/minimize-maximum-pair-sum-in-array)", "[Minimize Maximum Pair Sum in Array](/solution/1800-1899/1877.Minimize%20Maximum%20Pair%20Sum%20in%20Array/README_EN.md)", "`Greedy`,`Sort`", "Medium", ""]}, {"question_id": "1987", "frontend_question_id": "1876", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/substrings-of-size-three-with-distinct-characters", "url_en": "https://leetcode.com/problems/substrings-of-size-three-with-distinct-characters", "relative_path_cn": "/solution/1800-1899/1876.Substrings%20of%20Size%20Three%20with%20Distinct%20Characters/README.md", "relative_path_en": "/solution/1800-1899/1876.Substrings%20of%20Size%20Three%20with%20Distinct%20Characters/README_EN.md", "title_cn": "\u957f\u5ea6\u4e3a\u4e09\u4e14\u5404\u5b57\u7b26\u4e0d\u540c\u7684\u5b50\u5b57\u7b26\u4e32", "title_en": "Substrings of Size Three with Distinct Characters", "question_title_slug": "substrings-of-size-three-with-distinct-characters", "content_en": "

    A string is good if there are no repeated characters.

    \n\n

    Given a string s\u200b\u200b\u200b\u200b\u200b, return the number of good substrings of length three in s\u200b\u200b\u200b\u200b\u200b\u200b.

    \n\n

    Note that if there are multiple occurrences of the same substring, every occurrence should be counted.

    \n\n

    A substring is a contiguous sequence of characters in a string.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "xyzzaz"\nOutput: 1\nExplanation: There are 4 substrings of size 3: "xyz", "yzz", "zza", and "zaz". \nThe only good substring of length 3 is "xyz".\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "aababcabc"\nOutput: 4\nExplanation: There are 7 substrings of size 3: "aab", "aba", "bab", "abc", "bca", "cab", and "abc".\nThe good substrings are "abc", "bca", "cab", and "abc".\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 100
    • \n\t
    • s\u200b\u200b\u200b\u200b\u200b\u200b consists of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u5982\u679c\u4e00\u4e2a\u5b57\u7b26\u4e32\u4e0d\u542b\u6709\u4efb\u4f55\u91cd\u590d\u5b57\u7b26\uff0c\u6211\u4eec\u79f0\u8fd9\u4e2a\u5b57\u7b26\u4e32\u4e3a \u597d\u00a0\u5b57\u7b26\u4e32\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s\u00a0\uff0c\u8bf7\u4f60\u8fd4\u56de s\u00a0\u4e2d\u957f\u5ea6\u4e3a 3\u00a0\u7684 \u597d\u5b50\u5b57\u7b26\u4e32 \u7684\u6570\u91cf\u3002

    \n\n

    \u6ce8\u610f\uff0c\u5982\u679c\u76f8\u540c\u7684\u597d\u5b50\u5b57\u7b26\u4e32\u51fa\u73b0\u591a\u6b21\uff0c\u6bcf\u4e00\u6b21\u90fd\u5e94\u8be5\u88ab\u8bb0\u5165\u7b54\u6848\u4e4b\u4e2d\u3002

    \n\n

    \u5b50\u5b57\u7b26\u4e32 \u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\u4e2d\u8fde\u7eed\u7684\u5b57\u7b26\u5e8f\u5217\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"xyzzaz\"\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u603b\u5171\u6709 4 \u4e2a\u957f\u5ea6\u4e3a 3 \u7684\u5b50\u5b57\u7b26\u4e32\uff1a\"xyz\"\uff0c\"yzz\"\uff0c\"zza\" \u548c \"zaz\" \u3002\n\u552f\u4e00\u7684\u957f\u5ea6\u4e3a 3 \u7684\u597d\u5b50\u5b57\u7b26\u4e32\u662f \"xyz\" \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"aababcabc\"\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u603b\u5171\u6709 7 \u4e2a\u957f\u5ea6\u4e3a 3 \u7684\u5b50\u5b57\u7b26\u4e32\uff1a\"aab\"\uff0c\"aba\"\uff0c\"bab\"\uff0c\"abc\"\uff0c\"bca\"\uff0c\"cab\" \u548c \"abc\" \u3002\n\u597d\u5b50\u5b57\u7b26\u4e32\u5305\u62ec \"abc\"\uff0c\"bca\"\uff0c\"cab\" \u548c \"abc\" \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 100
    • \n\t
    • s\u200b\u200b\u200b\u200b\u200b\u200b \u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countGoodSubstrings(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countGoodSubstrings(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countGoodSubstrings(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countGoodSubstrings(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countGoodSubstrings(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountGoodSubstrings(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar countGoodSubstrings = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef count_good_substrings(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countGoodSubstrings(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countGoodSubstrings(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countGoodSubstrings(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countGoodSubstrings(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_good_substrings(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function countGoodSubstrings($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countGoodSubstrings(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-good-substrings s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1876](https://leetcode-cn.com/problems/substrings-of-size-three-with-distinct-characters)", "[\u957f\u5ea6\u4e3a\u4e09\u4e14\u5404\u5b57\u7b26\u4e0d\u540c\u7684\u5b50\u5b57\u7b26\u4e32](/solution/1800-1899/1876.Substrings%20of%20Size%20Three%20with%20Distinct%20Characters/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1876](https://leetcode.com/problems/substrings-of-size-three-with-distinct-characters)", "[Substrings of Size Three with Distinct Characters](/solution/1800-1899/1876.Substrings%20of%20Size%20Three%20with%20Distinct%20Characters/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1986", "frontend_question_id": "1857", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/largest-color-value-in-a-directed-graph", "url_en": "https://leetcode.com/problems/largest-color-value-in-a-directed-graph", "relative_path_cn": "/solution/1800-1899/1857.Largest%20Color%20Value%20in%20a%20Directed%20Graph/README.md", "relative_path_en": "/solution/1800-1899/1857.Largest%20Color%20Value%20in%20a%20Directed%20Graph/README_EN.md", "title_cn": "\u6709\u5411\u56fe\u4e2d\u6700\u5927\u989c\u8272\u503c", "title_en": "Largest Color Value in a Directed Graph", "question_title_slug": "largest-color-value-in-a-directed-graph", "content_en": "

    There is a directed graph of n colored nodes and m edges. The nodes are numbered from 0 to n - 1.

    \n\n

    You are given a string colors where colors[i] is a lowercase English letter representing the color of the ith node in this graph (0-indexed). You are also given a 2D array edges where edges[j] = [aj, bj] indicates that there is a directed edge from node aj to node bj.

    \n\n

    A valid path in the graph is a sequence of nodes x1 -> x2 -> x3 -> ... -> xk such that there is a directed edge from xi to xi+1 for every 1 <= i < k. The color value of the path is the number of nodes that are colored the most frequently occurring color along that path.

    \n\n

    Return the largest color value of any valid path in the given graph, or -1 if the graph contains a cycle.

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: colors = "abaca", edges = [[0,1],[0,2],[2,3],[3,4]]\nOutput: 3\nExplanation: The path 0 -> 2 -> 3 -> 4 contains 3 nodes that are colored "a" (red in the above image).\n
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: colors = "a", edges = [[0,0]]\nOutput: -1\nExplanation: There is a cycle from 0 to 0.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == colors.length
    • \n\t
    • m == edges.length
    • \n\t
    • 1 <= n <= 105
    • \n\t
    • 0 <= m <= 105
    • \n\t
    • colors consists of lowercase English letters.
    • \n\t
    • 0 <= aj, bj < n
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u00a0\u6709\u5411\u56fe\u00a0\uff0c\u5b83\u542b\u6709\u00a0n\u00a0\u4e2a\u8282\u70b9\u548c m\u00a0\u6761\u8fb9\u3002\u8282\u70b9\u7f16\u53f7\u4ece\u00a00 \u5230\u00a0n - 1\u00a0\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32\u00a0colors \uff0c\u5176\u4e2d\u00a0colors[i]\u00a0\u662f\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\uff0c\u8868\u793a\u56fe\u4e2d\u7b2c i\u00a0\u4e2a\u8282\u70b9\u7684 \u989c\u8272\u00a0\uff08\u4e0b\u6807\u4ece 0\u00a0\u5f00\u59cb\uff09\u3002\u540c\u65f6\u7ed9\u4f60\u4e00\u4e2a\u4e8c\u7ef4\u6570\u7ec4\u00a0edges\u00a0\uff0c\u5176\u4e2d\u00a0edges[j] = [aj, bj]\u00a0\u8868\u793a\u4ece\u8282\u70b9\u00a0aj\u00a0\u5230\u8282\u70b9\u00a0bj\u00a0\u6709\u4e00\u6761\u00a0\u6709\u5411\u8fb9\u00a0\u3002

    \n\n

    \u56fe\u4e2d\u4e00\u6761\u6709\u6548 \u8def\u5f84\u00a0\u662f\u4e00\u4e2a\u70b9\u5e8f\u5217\u00a0x1 -> x2 -> x3 -> ... -> xk\u00a0\uff0c\u5bf9\u4e8e\u6240\u6709\u00a01 <= i < k\u00a0\uff0c\u4ece\u00a0xi \u5230\u00a0xi+1\u00a0\u5728\u56fe\u4e2d\u6709\u4e00\u6761\u6709\u5411\u8fb9\u3002\u8def\u5f84\u7684 \u989c\u8272\u503c\u00a0\u662f\u8def\u5f84\u4e2d \u51fa\u73b0\u6b21\u6570\u6700\u591a \u989c\u8272\u7684\u8282\u70b9\u6570\u76ee\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u7ed9\u5b9a\u56fe\u4e2d\u6709\u6548\u8def\u5f84\u91cc\u9762\u7684\u00a0\u6700\u5927\u989c\u8272\u503c\u00a0\u3002\u5982\u679c\u56fe\u4e2d\u542b\u6709\u73af\uff0c\u8bf7\u8fd4\u56de -1\u00a0\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1acolors = \"abaca\", edges = [[0,1],[0,2],[2,3],[3,4]]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u8def\u5f84 0 -> 2 -> 3 -> 4 \u542b\u6709 3 \u4e2a\u989c\u8272\u4e3a \"a\" \u7684\u8282\u70b9\uff08\u4e0a\u56fe\u4e2d\u7684\u7ea2\u8272\u8282\u70b9\uff09\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1acolors = \"a\", edges = [[0,0]]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u4ece 0 \u5230 0 \u6709\u4e00\u4e2a\u73af\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == colors.length
    • \n\t
    • m == edges.length
    • \n\t
    • 1 <= n <= 105
    • \n\t
    • 0 <= m <= 105
    • \n\t
    • colors\u00a0\u53ea\u542b\u6709\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    • \n\t
    • 0 <= aj, bj\u00a0< n
    • \n
    \n", "tags_en": ["Topological Sort", "Dynamic Programming"], "tags_cn": ["\u62d3\u6251\u6392\u5e8f", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int largestPathValue(string colors, vector>& edges) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int largestPathValue(String colors, int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def largestPathValue(self, colors, edges):\n \"\"\"\n :type colors: str\n :type edges: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def largestPathValue(self, colors: str, edges: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint largestPathValue(char * colors, int** edges, int edgesSize, int* edgesColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LargestPathValue(string colors, int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} colors\n * @param {number[][]} edges\n * @return {number}\n */\nvar largestPathValue = function(colors, edges) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} colors\n# @param {Integer[][]} edges\n# @return {Integer}\ndef largest_path_value(colors, edges)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func largestPathValue(_ colors: String, _ edges: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func largestPathValue(colors string, edges [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def largestPathValue(colors: String, edges: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun largestPathValue(colors: String, edges: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn largest_path_value(colors: String, edges: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $colors\n * @param Integer[][] $edges\n * @return Integer\n */\n function largestPathValue($colors, $edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function largestPathValue(colors: string, edges: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (largest-path-value colors edges)\n (-> string? (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1857](https://leetcode-cn.com/problems/largest-color-value-in-a-directed-graph)", "[\u6709\u5411\u56fe\u4e2d\u6700\u5927\u989c\u8272\u503c](/solution/1800-1899/1857.Largest%20Color%20Value%20in%20a%20Directed%20Graph/README.md)", "`\u62d3\u6251\u6392\u5e8f`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1857](https://leetcode.com/problems/largest-color-value-in-a-directed-graph)", "[Largest Color Value in a Directed Graph](/solution/1800-1899/1857.Largest%20Color%20Value%20in%20a%20Directed%20Graph/README_EN.md)", "`Topological Sort`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "1985", "frontend_question_id": "1856", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-subarray-min-product", "url_en": "https://leetcode.com/problems/maximum-subarray-min-product", "relative_path_cn": "/solution/1800-1899/1856.Maximum%20Subarray%20Min-Product/README.md", "relative_path_en": "/solution/1800-1899/1856.Maximum%20Subarray%20Min-Product/README_EN.md", "title_cn": "\u5b50\u6570\u7ec4\u6700\u5c0f\u4e58\u79ef\u7684\u6700\u5927\u503c", "title_en": "Maximum Subarray Min-Product", "question_title_slug": "maximum-subarray-min-product", "content_en": "

    The min-product of an array is equal to the minimum value in the array multiplied by the array's sum.

    \n\n
      \n\t
    • For example, the array [3,2,5] (minimum value is 2) has a min-product of 2 * (3+2+5) = 2 * 10 = 20.
    • \n
    \n\n

    Given an array of integers nums, return the maximum min-product of any non-empty subarray of nums. Since the answer may be large, return it modulo 109 + 7.

    \n\n

    Note that the min-product should be maximized before performing the modulo operation. Testcases are generated such that the maximum min-product without modulo will fit in a 64-bit signed integer.

    \n\n

    A subarray is a contiguous part of an array.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,3,2]\nOutput: 14\nExplanation: The maximum min-product is achieved with the subarray [2,3,2] (minimum value is 2).\n2 * (2+3+2) = 2 * 7 = 14.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [2,3,3,1,2]\nOutput: 18\nExplanation: The maximum min-product is achieved with the subarray [3,3] (minimum value is 3).\n3 * (3+3) = 3 * 6 = 18.\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [3,1,5,6,4,2]\nOutput: 60\nExplanation: The maximum min-product is achieved with the subarray [5,6,4] (minimum value is 4).\n4 * (5+6+4) = 4 * 15 = 60.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • 1 <= nums[i] <= 107
    • \n
    \n", "content_cn": "

    \u4e00\u4e2a\u6570\u7ec4\u7684 \u6700\u5c0f\u4e58\u79ef\u00a0\u5b9a\u4e49\u4e3a\u8fd9\u4e2a\u6570\u7ec4\u4e2d \u6700\u5c0f\u503c\u00a0\u4e58\u4ee5\u00a0\u6570\u7ec4\u7684 \u548c\u00a0\u3002

    \n\n
      \n\t
    • \u6bd4\u65b9\u8bf4\uff0c\u6570\u7ec4\u00a0[3,2,5]\u00a0\uff08\u6700\u5c0f\u503c\u662f\u00a02\uff09\u7684\u6700\u5c0f\u4e58\u79ef\u4e3a\u00a02 * (3+2+5) = 2 * 10 = 20\u00a0\u3002
    • \n
    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6b63\u6574\u6570\u6570\u7ec4\u00a0nums\u00a0\uff0c\u8bf7\u4f60\u8fd4\u56de\u00a0nums\u00a0\u4efb\u610f\u00a0\u975e\u7a7a\u5b50\u6570\u7ec4\u00a0\u7684\u6700\u5c0f\u4e58\u79ef\u00a0\u7684\u00a0\u6700\u5927\u503c\u00a0\u3002\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u5f88\u5927\uff0c\u8bf7\u4f60\u8fd4\u56de\u7b54\u6848\u5bf9\u00a0\u00a0109 + 7\u00a0\u53d6\u4f59\u00a0\u7684\u7ed3\u679c\u3002

    \n\n

    \u8bf7\u6ce8\u610f\uff0c\u6700\u5c0f\u4e58\u79ef\u7684\u6700\u5927\u503c\u8003\u8651\u7684\u662f\u53d6\u4f59\u64cd\u4f5c \u4e4b\u524d\u00a0\u7684\u7ed3\u679c\u3002\u9898\u76ee\u4fdd\u8bc1\u6700\u5c0f\u4e58\u79ef\u7684\u6700\u5927\u503c\u5728 \u4e0d\u53d6\u4f59 \u7684\u60c5\u51b5\u4e0b\u53ef\u4ee5\u7528 64 \u4f4d\u6709\u7b26\u53f7\u6574\u6570\u00a0\u4fdd\u5b58\u3002

    \n\n

    \u5b50\u6570\u7ec4\u00a0\u5b9a\u4e49\u4e3a\u4e00\u4e2a\u6570\u7ec4\u7684 \u8fde\u7eed\u00a0\u90e8\u5206\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,3,2]\n\u8f93\u51fa\uff1a14\n\u89e3\u91ca\uff1a\u6700\u5c0f\u4e58\u79ef\u7684\u6700\u5927\u503c\u7531\u5b50\u6570\u7ec4 [2,3,2] \uff08\u6700\u5c0f\u503c\u662f 2\uff09\u5f97\u5230\u3002\n2 * (2+3+2) = 2 * 7 = 14 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [2,3,3,1,2]\n\u8f93\u51fa\uff1a18\n\u89e3\u91ca\uff1a\u6700\u5c0f\u4e58\u79ef\u7684\u6700\u5927\u503c\u7531\u5b50\u6570\u7ec4 [3,3] \uff08\u6700\u5c0f\u503c\u662f 3\uff09\u5f97\u5230\u3002\n3 * (3+3) = 3 * 6 = 18 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [3,1,5,6,4,2]\n\u8f93\u51fa\uff1a60\n\u89e3\u91ca\uff1a\u6700\u5c0f\u4e58\u79ef\u7684\u6700\u5927\u503c\u7531\u5b50\u6570\u7ec4 [5,6,4] \uff08\u6700\u5c0f\u503c\u662f 4\uff09\u5f97\u5230\u3002\n4 * (5+6+4) = 4 * 15 = 60 \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • 1 <= nums[i] <= 107
    • \n
    \n", "tags_en": ["Sort", "Union Find", "Queue", "Binary Search", "Dynamic Programming"], "tags_cn": ["\u6392\u5e8f", "\u5e76\u67e5\u96c6", "\u961f\u5217", "\u4e8c\u5206\u67e5\u627e", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxSumMinProduct(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxSumMinProduct(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxSumMinProduct(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxSumMinProduct(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxSumMinProduct(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxSumMinProduct(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar maxSumMinProduct = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef max_sum_min_product(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxSumMinProduct(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxSumMinProduct(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxSumMinProduct(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxSumMinProduct(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_sum_min_product(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function maxSumMinProduct($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxSumMinProduct(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-sum-min-product nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1856](https://leetcode-cn.com/problems/maximum-subarray-min-product)", "[\u5b50\u6570\u7ec4\u6700\u5c0f\u4e58\u79ef\u7684\u6700\u5927\u503c](/solution/1800-1899/1856.Maximum%20Subarray%20Min-Product/README.md)", "`\u6392\u5e8f`,`\u5e76\u67e5\u96c6`,`\u961f\u5217`,`\u4e8c\u5206\u67e5\u627e`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1856](https://leetcode.com/problems/maximum-subarray-min-product)", "[Maximum Subarray Min-Product](/solution/1800-1899/1856.Maximum%20Subarray%20Min-Product/README_EN.md)", "`Sort`,`Union Find`,`Queue`,`Binary Search`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "1984", "frontend_question_id": "1855", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-distance-between-a-pair-of-values", "url_en": "https://leetcode.com/problems/maximum-distance-between-a-pair-of-values", "relative_path_cn": "/solution/1800-1899/1855.Maximum%20Distance%20Between%20a%20Pair%20of%20Values/README.md", "relative_path_en": "/solution/1800-1899/1855.Maximum%20Distance%20Between%20a%20Pair%20of%20Values/README_EN.md", "title_cn": "\u4e0b\u6807\u5bf9\u4e2d\u7684\u6700\u5927\u8ddd\u79bb", "title_en": "Maximum Distance Between a Pair of Values", "question_title_slug": "maximum-distance-between-a-pair-of-values", "content_en": "

    You are given two non-increasing 0-indexed integer arrays nums1\u200b\u200b\u200b\u200b\u200b\u200b and nums2\u200b\u200b\u200b\u200b\u200b\u200b.

    \n\n

    A pair of indices (i, j), where 0 <= i < nums1.length and 0 <= j < nums2.length, is valid if both i <= j and nums1[i] <= nums2[j]. The distance of the pair is j - i\u200b\u200b\u200b\u200b.

    \n\n

    Return the maximum distance of any valid pair (i, j). If there are no valid pairs, return 0.

    \n\n

    An array arr is non-increasing if arr[i-1] >= arr[i] for every 1 <= i < arr.length.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums1 = [55,30,5,4,2], nums2 = [100,20,10,10,5]\nOutput: 2\nExplanation: The valid pairs are (0,0), (2,2), (2,3), (2,4), (3,3), (3,4), and (4,4).\nThe maximum distance is 2 with pair (2,4).\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums1 = [2,2,2], nums2 = [10,10,1]\nOutput: 1\nExplanation: The valid pairs are (0,0), (0,1), and (1,1).\nThe maximum distance is 1 with pair (0,1).\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums1 = [30,29,19,5], nums2 = [25,25,25,25,25]\nOutput: 2\nExplanation: The valid pairs are (2,2), (2,3), (2,4), (3,3), and (3,4).\nThe maximum distance is 2 with pair (2,4).\n
    \n\n

    Example 4:

    \n\n
    \nInput: nums1 = [5,4], nums2 = [3,2]\nOutput: 0\nExplanation: There are no valid pairs, so return 0.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums1.length <= 105
    • \n\t
    • 1 <= nums2.length <= 105
    • \n\t
    • 1 <= nums1[i], nums2[j] <= 105
    • \n\t
    • Both nums1 and nums2 are non-increasing.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a \u975e\u9012\u589e \u7684\u6574\u6570\u6570\u7ec4 nums1\u200b\u200b\u200b\u200b\u200b\u200b \u548c nums2\u200b\u200b\u200b\u200b\u200b\u200b \uff0c\u6570\u7ec4\u4e0b\u6807\u5747 \u4ece 0 \u5f00\u59cb \u8ba1\u6570\u3002

    \n\n

    \u4e0b\u6807\u5bf9 (i, j) \u4e2d 0 <= i < nums1.length \u4e14 0 <= j < nums2.length \u3002\u5982\u679c\u8be5\u4e0b\u6807\u5bf9\u540c\u65f6\u6ee1\u8db3 i <= j \u4e14 nums1[i] <= nums2[j] \uff0c\u5219\u79f0\u4e4b\u4e3a \u6709\u6548 \u4e0b\u6807\u5bf9\uff0c\u8be5\u4e0b\u6807\u5bf9\u7684 \u8ddd\u79bb \u4e3a j - i\u200b\u200b \u3002\u200b\u200b

    \n\n

    \u8fd4\u56de\u6240\u6709 \u6709\u6548 \u4e0b\u6807\u5bf9 (i, j) \u4e2d\u7684 \u6700\u5927\u8ddd\u79bb \u3002\u5982\u679c\u4e0d\u5b58\u5728\u6709\u6548\u4e0b\u6807\u5bf9\uff0c\u8fd4\u56de 0 \u3002

    \n\n

    \u4e00\u4e2a\u6570\u7ec4 arr \uff0c\u5982\u679c\u6bcf\u4e2a 1 <= i < arr.length \u5747\u6709 arr[i-1] >= arr[i] \u6210\u7acb\uff0c\u90a3\u4e48\u8be5\u6570\u7ec4\u662f\u4e00\u4e2a \u975e\u9012\u589e \u6570\u7ec4\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums1 = [55,30,5,4,2], nums2 = [100,20,10,10,5]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6709\u6548\u4e0b\u6807\u5bf9\u662f (0,0), (2,2), (2,3), (2,4), (3,3), (3,4) \u548c (4,4) \u3002\n\u6700\u5927\u8ddd\u79bb\u662f 2 \uff0c\u5bf9\u5e94\u4e0b\u6807\u5bf9 (2,4) \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums1 = [2,2,2], nums2 = [10,10,1]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u6709\u6548\u4e0b\u6807\u5bf9\u662f (0,0), (0,1) \u548c (1,1) \u3002\n\u6700\u5927\u8ddd\u79bb\u662f 1 \uff0c\u5bf9\u5e94\u4e0b\u6807\u5bf9 (0,1) \u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums1 = [30,29,19,5], nums2 = [25,25,25,25,25]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6709\u6548\u4e0b\u6807\u5bf9\u662f (2,2), (2,3), (2,4), (3,3) \u548c (3,4) \u3002\n\u6700\u5927\u8ddd\u79bb\u662f 2 \uff0c\u5bf9\u5e94\u4e0b\u6807\u5bf9 (2,4) \u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums1 = [5,4], nums2 = [3,2]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u4e0d\u5b58\u5728\u6709\u6548\u4e0b\u6807\u5bf9\uff0c\u6240\u4ee5\u8fd4\u56de 0 \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums1.length <= 105
    • \n\t
    • 1 <= nums2.length <= 105
    • \n\t
    • 1 <= nums1[i], nums2[j] <= 105
    • \n\t
    • nums1 \u548c nums2 \u90fd\u662f \u975e\u9012\u589e \u6570\u7ec4
    • \n
    \n", "tags_en": ["Greedy", "Two Pointers", "Binary Search"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u53cc\u6307\u9488", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxDistance(vector& nums1, vector& nums2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxDistance(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxDistance(self, nums1, nums2):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxDistance(self, nums1: List[int], nums2: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxDistance(int* nums1, int nums1Size, int* nums2, int nums2Size){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxDistance(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums1\n * @param {number[]} nums2\n * @return {number}\n */\nvar maxDistance = function(nums1, nums2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums1\n# @param {Integer[]} nums2\n# @return {Integer}\ndef max_distance(nums1, nums2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxDistance(_ nums1: [Int], _ nums2: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxDistance(nums1 []int, nums2 []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxDistance(nums1: Array[Int], nums2: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxDistance(nums1: IntArray, nums2: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_distance(nums1: Vec, nums2: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums1\n * @param Integer[] $nums2\n * @return Integer\n */\n function maxDistance($nums1, $nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxDistance(nums1: number[], nums2: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-distance nums1 nums2)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1855](https://leetcode-cn.com/problems/maximum-distance-between-a-pair-of-values)", "[\u4e0b\u6807\u5bf9\u4e2d\u7684\u6700\u5927\u8ddd\u79bb](/solution/1800-1899/1855.Maximum%20Distance%20Between%20a%20Pair%20of%20Values/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u53cc\u6307\u9488`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1855](https://leetcode.com/problems/maximum-distance-between-a-pair-of-values)", "[Maximum Distance Between a Pair of Values](/solution/1800-1899/1855.Maximum%20Distance%20Between%20a%20Pair%20of%20Values/README_EN.md)", "`Greedy`,`Two Pointers`,`Binary Search`", "Medium", ""]}, {"question_id": "1983", "frontend_question_id": "1854", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-population-year", "url_en": "https://leetcode.com/problems/maximum-population-year", "relative_path_cn": "/solution/1800-1899/1854.Maximum%20Population%20Year/README.md", "relative_path_en": "/solution/1800-1899/1854.Maximum%20Population%20Year/README_EN.md", "title_cn": "\u4eba\u53e3\u6700\u591a\u7684\u5e74\u4efd", "title_en": "Maximum Population Year", "question_title_slug": "maximum-population-year", "content_en": "

    You are given a 2D integer array logs where each logs[i] = [birthi, deathi] indicates the birth and death years of the ith person.

    \n\n

    The population of some year x is the number of people alive during that year. The ith person is counted in year x's population if x is in the inclusive range [birthi, deathi - 1]. Note that the person is not counted in the year that they die.

    \n\n

    Return the earliest year with the maximum population.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: logs = [[1993,1999],[2000,2010]]\nOutput: 1993\nExplanation: The maximum population is 1, and 1993 is the earliest year with this population.\n
    \n\n

    Example 2:

    \n\n
    \nInput: logs = [[1950,1961],[1960,1971],[1970,1981]]\nOutput: 1960\nExplanation: \nThe maximum population is 2, and it had happened in years 1960 and 1970.\nThe earlier year between them is 1960.
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= logs.length <= 100
    • \n\t
    • 1950 <= birthi < deathi <= 2050
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u4e8c\u7ef4\u6574\u6570\u6570\u7ec4 logs \uff0c\u5176\u4e2d\u6bcf\u4e2a logs[i] = [birthi, deathi] \u8868\u793a\u7b2c i \u4e2a\u4eba\u7684\u51fa\u751f\u548c\u6b7b\u4ea1\u5e74\u4efd\u3002

    \n\n

    \u5e74\u4efd x \u7684 \u4eba\u53e3 \u5b9a\u4e49\u4e3a\u8fd9\u4e00\u5e74\u671f\u95f4\u6d3b\u7740\u7684\u4eba\u7684\u6570\u76ee\u3002\u7b2c i \u4e2a\u4eba\u88ab\u8ba1\u5165\u5e74\u4efd x \u7684\u4eba\u53e3\u9700\u8981\u6ee1\u8db3\uff1ax \u5728\u95ed\u533a\u95f4 [birthi, deathi - 1] \u5185\u3002\u6ce8\u610f\uff0c\u4eba\u4e0d\u5e94\u5f53\u8ba1\u5165\u4ed6\u4eec\u6b7b\u4ea1\u5f53\u5e74\u7684\u4eba\u53e3\u4e2d\u3002

    \n\n

    \u8fd4\u56de \u4eba\u53e3\u6700\u591a \u4e14 \u6700\u65e9 \u7684\u5e74\u4efd\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1alogs = [[1993,1999],[2000,2010]]\n\u8f93\u51fa\uff1a1993\n\u89e3\u91ca\uff1a\u4eba\u53e3\u6700\u591a\u4e3a 1 \uff0c\u800c 1993 \u662f\u4eba\u53e3\u4e3a 1 \u7684\u6700\u65e9\u5e74\u4efd\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1alogs = [[1950,1961],[1960,1971],[1970,1981]]\n\u8f93\u51fa\uff1a1960\n\u89e3\u91ca\uff1a \n\u4eba\u53e3\u6700\u591a\u4e3a 2 \uff0c\u5206\u522b\u51fa\u73b0\u5728 1960 \u548c 1970 \u3002\n\u5176\u4e2d\u6700\u65e9\u5e74\u4efd\u662f 1960 \u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= logs.length <= 100
    • \n\t
    • 1950 <= birthi < deathi <= 2050
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maximumPopulation(vector>& logs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maximumPopulation(int[][] logs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximumPopulation(self, logs):\n \"\"\"\n :type logs: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximumPopulation(self, logs: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maximumPopulation(int** logs, int logsSize, int* logsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaximumPopulation(int[][] logs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} logs\n * @return {number}\n */\nvar maximumPopulation = function(logs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} logs\n# @return {Integer}\ndef maximum_population(logs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximumPopulation(_ logs: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximumPopulation(logs [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximumPopulation(logs: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximumPopulation(logs: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximum_population(logs: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $logs\n * @return Integer\n */\n function maximumPopulation($logs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximumPopulation(logs: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximum-population logs)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1854](https://leetcode-cn.com/problems/maximum-population-year)", "[\u4eba\u53e3\u6700\u591a\u7684\u5e74\u4efd](/solution/1800-1899/1854.Maximum%20Population%20Year/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1854](https://leetcode.com/problems/maximum-population-year)", "[Maximum Population Year](/solution/1800-1899/1854.Maximum%20Population%20Year/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1982", "frontend_question_id": "1836", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/remove-duplicates-from-an-unsorted-linked-list", "url_en": "https://leetcode.com/problems/remove-duplicates-from-an-unsorted-linked-list", "relative_path_cn": "/solution/1800-1899/1836.Remove%20Duplicates%20From%20an%20Unsorted%20Linked%20List/README.md", "relative_path_en": "/solution/1800-1899/1836.Remove%20Duplicates%20From%20an%20Unsorted%20Linked%20List/README_EN.md", "title_cn": "", "title_en": "Remove Duplicates From an Unsorted Linked List", "question_title_slug": "remove-duplicates-from-an-unsorted-linked-list", "content_en": "

    Given the head of a linked list, find all the values that appear more than once in the list and delete the nodes that have any of those values.

    \r\n\r\n

    Return the linked list after the deletions.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\"\"\r\n
    \r\nInput: head = [1,2,3,2]\r\nOutput: [1,3]\r\nExplanation: 2 appears twice in the linked list, so all 2's should be deleted. After deleting all 2's, we are left with [1,3].\r\n
    \r\n\r\n

    Example 2:

    \r\n\"\"\r\n
    \r\nInput: head = [2,1,1,2]\r\nOutput: []\r\nExplanation: 2 and 1 both appear twice. All the elements should be deleted.\r\n
    \r\n\r\n

    Example 3:

    \r\n\"\"\r\n
    \r\nInput: head = [3,2,2,1,3,2,4]\r\nOutput: [1,4]\r\nExplanation: 3 appears twice and 2 appears three times. After deleting all 3's and 2's, we are left with [1,4].\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • The number of nodes in the list is in the range [1, 105]
    • \r\n\t
    • 1 <= Node.val <= 105
    • \r\n
    ", "content_cn": null, "tags_en": ["Linked List"], "tags_cn": ["\u94fe\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n ListNode* deleteDuplicatesUnsorted(ListNode* head) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public ListNode deleteDuplicatesUnsorted(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def deleteDuplicatesUnsorted(self, head):\n \"\"\"\n :type head: ListNode\n :rtype: ListNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def deleteDuplicatesUnsorted(self, head: ListNode) -> ListNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nstruct ListNode* deleteDuplicatesUnsorted(struct ListNode* head){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public ListNode DeleteDuplicatesUnsorted(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} head\n * @return {ListNode}\n */\nvar deleteDuplicatesUnsorted = function(head) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode} head\n# @return {ListNode}\ndef delete_duplicates_unsorted(head)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func deleteDuplicatesUnsorted(_ head: ListNode?) -> ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc deleteDuplicatesUnsorted(head *ListNode) *ListNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def deleteDuplicatesUnsorted(head: ListNode): ListNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun deleteDuplicatesUnsorted(head: ListNode?): ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn delete_duplicates_unsorted(head: Option>) -> Option> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @return ListNode\n */\n function deleteDuplicatesUnsorted($head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction deleteDuplicatesUnsorted(head: ListNode | null): ListNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (delete-duplicates-unsorted head)\n (-> (or/c list-node? #f) (or/c list-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1836](https://leetcode-cn.com/problems/remove-duplicates-from-an-unsorted-linked-list)", "[Remove Duplicates From an Unsorted Linked List](/solution/1800-1899/1836.Remove%20Duplicates%20From%20an%20Unsorted%20Linked%20List/README_EN.md)", "`\u94fe\u8868`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1836](https://leetcode.com/problems/remove-duplicates-from-an-unsorted-linked-list)", "[Remove Duplicates From an Unsorted Linked List](/solution/1800-1899/1836.Remove%20Duplicates%20From%20an%20Unsorted%20Linked%20List/README_EN.md)", "`Linked List`", "Medium", "\ud83d\udd12"]}, {"question_id": "1981", "frontend_question_id": "1831", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/maximum-transaction-each-day", "url_en": "https://leetcode.com/problems/maximum-transaction-each-day", "relative_path_cn": "/solution/1800-1899/1831.Maximum%20Transaction%20Each%20Day/README.md", "relative_path_en": "/solution/1800-1899/1831.Maximum%20Transaction%20Each%20Day/README_EN.md", "title_cn": "", "title_en": "Maximum Transaction Each Day", "question_title_slug": "maximum-transaction-each-day", "content_en": "

    Table: Transactions

    \r\n\r\n
    \r\n+----------------+----------+\r\n| Column Name    | Type     |\r\n+----------------+----------+\r\n| transaction_id | int      |\r\n| day            | datetime |\r\n| amount         | int      |\r\n+----------------+----------+\r\ntransaction_id is the primary key for this table.\r\nEach row contains information about one transaction.\r\n
    \r\n\r\n

     

    \r\n\r\n

    Write an SQL query to report the IDs of the transactions with the maximum amount on their respective day. If in one day there are multiple such transactions, return all of them.

    \r\n\r\n

    Return the result table in ascending order by transaction_id.

    \r\n\r\n

    The query result format is in the following example:

    \r\n\r\n

     

    \r\n\r\n
    \r\nTransactions table:\r\n+----------------+--------------------+--------+\r\n| transaction_id | day                | amount |\r\n+----------------+--------------------+--------+\r\n| 8              | 2021-4-3 15:57:28  | 57     |\r\n| 9              | 2021-4-28 08:47:25 | 21     |\r\n| 1              | 2021-4-29 13:28:30 | 58     |\r\n| 5              | 2021-4-28 16:39:59 | 40     |\r\n| 6              | 2021-4-29 23:39:28 | 58     |\r\n+----------------+--------------------+--------+\r\n\r\nResult table:\r\n+----------------+\r\n| transaction_id |\r\n+----------------+\r\n| 1              |\r\n| 5              |\r\n| 6              |\r\n| 8              |\r\n+----------------+\r\n"2021-4-3"  --> We have one transaction with ID 8, so we add 8 to the result table.\r\n"2021-4-28" --> We have two transactions with IDs 5 and 9. The transaction with ID 5 has an amount of 40, while the transaction with ID 9 has an amount of 21. We only include the transaction with ID 5 as it has the maximum amount this day.\r\n"2021-4-29" --> We have two transactions with IDs 1 and 6. Both transactions have the same amount of 58, so we include both in the result table.\r\nWe order the result table by transaction_id after collecting these IDs.
    \r\n\r\n

     

    \r\n

    Follow up: Could you solve it without using the MAX() function?

    ", "content_cn": null, "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1831](https://leetcode-cn.com/problems/maximum-transaction-each-day)", "[Maximum Transaction Each Day](/solution/1800-1899/1831.Maximum%20Transaction%20Each%20Day/README_EN.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1831](https://leetcode.com/problems/maximum-transaction-each-day)", "[Maximum Transaction Each Day](/solution/1800-1899/1831.Maximum%20Transaction%20Each%20Day/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1980", "frontend_question_id": "1826", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/faulty-sensor", "url_en": "https://leetcode.com/problems/faulty-sensor", "relative_path_cn": "/solution/1800-1899/1826.Faulty%20Sensor/README.md", "relative_path_en": "/solution/1800-1899/1826.Faulty%20Sensor/README_EN.md", "title_cn": "\u6709\u7f3a\u9677\u7684\u4f20\u611f\u5668", "title_en": "Faulty Sensor", "question_title_slug": "faulty-sensor", "content_en": "

    An experiment is being conducted in a lab. To ensure accuracy, there are two sensors collecting data simultaneously. You are given two arrays sensor1 and sensor2, where sensor1[i] and sensor2[i] are the ith data points collected by the two sensors.

    \n\n

    However, this type of sensor has a chance of being defective, which causes exactly one data point to be dropped. After the data is dropped, all the data points to the right of the dropped data are shifted one place to the left, and the last data point is replaced with some random value. It is guaranteed that this random value will not be equal to the dropped value.

    \n\n
      \n\t
    • For example, if the correct data is [1,2,3,4,5] and 3 is dropped, the sensor could return [1,2,4,5,7] (the last position can be any value, not just 7).
    • \n
    \n\n

    We know that there is a defect in at most one of the sensors. Return the sensor number (1 or 2) with the defect. If there is no defect in either sensor or if it is impossible to determine the defective sensor, return -1.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: sensor1 = [2,3,4,5], sensor2 = [2,1,3,4]\nOutput: 1\nExplanation: Sensor 2 has the correct values.\nThe second data point from sensor 2 is dropped, and the last value of sensor 1 is replaced by a 5.\n
    \n\n

    Example 2:

    \n\n
    \nInput: sensor1 = [2,2,2,2,2], sensor2 = [2,2,2,2,5]\nOutput: -1\nExplanation: It is impossible to determine which sensor has a defect.\nDropping the last value for either sensor could produce the output for the other sensor.\n
    \n\n

    Example 3:

    \n\n
    \nInput: sensor1 = [2,3,2,2,3,2], sensor2 = [2,3,2,3,2,7]\nOutput: 2\nExplanation: Sensor 1 has the correct values.\nThe fourth data point from sensor 1 is dropped, and the last value of sensor 1 is replaced by a 7.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • sensor1.length == sensor2.length
    • \n\t
    • 1 <= sensor1.length <= 100
    • \n\t
    • 1 <= sensor1[i], sensor2[i] <= 100
    • \n
    \n", "content_cn": "

    \u5b9e\u9a8c\u5ba4\u91cc\u6b63\u5728\u8fdb\u884c\u4e00\u9879\u5b9e\u9a8c\u3002\u4e3a\u4e86\u786e\u4fdd\u6570\u636e\u7684\u51c6\u786e\u6027\uff0c\u540c\u65f6\u4f7f\u7528 \u4e24\u4e2a \u4f20\u611f\u5668\u6765\u91c7\u96c6\u6570\u636e\u3002\u60a8\u5c06\u83b7\u5f972\u4e2a\u6570\u7ec4 sensor1 and sensor2\uff0c\u5176\u4e2d sensor1[i]\u00a0\u548c\u00a0sensor2[i]\u00a0\u5206\u522b\u662f\u4e24\u4e2a\u4f20\u611f\u5668\u5bf9\u7b2c i \u4e2a\u6570\u636e\u70b9\u91c7\u96c6\u5230\u7684\u6570\u636e\u3002

    \n\n

    \u4f46\u662f\uff0c\u8fd9\u79cd\u7c7b\u578b\u7684\u4f20\u611f\u5668\u6709\u53ef\u80fd\u5b58\u5728\u7f3a\u9677\uff0c\u5b83\u4f1a\u5bfc\u81f4 \u67d0\u4e00\u4e2a \u6570\u636e\u70b9\u91c7\u96c6\u7684\u6570\u636e\uff08\u6389\u843d\u503c\uff09\u88ab\u4e22\u5f03\u3002

    \n\n

    \u6570\u636e\u88ab\u4e22\u5f03\u540e\uff0c\u6240\u6709\u5728\u5176\u53f3\u4fa7\u7684\u6570\u636e\u70b9\u91c7\u96c6\u7684\u6570\u636e\uff0c\u90fd\u4f1a\u88ab\u5411\u5de6\u79fb\u52a8\u4e00\u4e2a\u4f4d\u7f6e\uff0c\u6700\u540e\u4e00\u4e2a\u6570\u636e\u70b9\u91c7\u96c6\u7684\u6570\u636e\u4f1a\u88ab\u4e00\u4e9b\u968f\u673a\u503c\u66ff\u6362\u3002\u53ef\u4ee5\u4fdd\u8bc1\u6b64\u968f\u673a\u503c\u4e0d\u7b49\u4e8e\u6389\u843d\u503c\u3002

    \n\n
      \n\t
    • \u4e3e\u4e2a\u4f8b\u5b50, \u5982\u679c\u6b63\u786e\u7684\u6570\u636e\u662f\u00a0[1,2,3,4,5]\u00a0\uff0c\u00a0\u6b64\u65f6 3 \u88ab\u4e22\u5f03\u4e86, \u4f20\u611f\u5668\u4f1a\u8fd4\u56de\u00a0[1,2,4,5,7] (\u6700\u540e\u7684\u4f4d\u7f6e\u53ef\u4ee5\u662f\u4efb\u4f55\u503c, \u4e0d\u4ec5\u4ec5\u662f\u00a07).
    • \n
    \n\n

    \u53ef\u4ee5\u786e\u5b9a\u7684\u662f\uff0c\u6700\u591a\u6709\u4e00\u4e2a \u4f20\u611f\u5668\u6709\u7f3a\u9677\u3002\u8bf7\u8fd4\u56de\u8fd9\u4e2a\u6709\u7f3a\u9677\u7684\u4f20\u611f\u5668\u7684\u7f16\u53f7 \uff081 \u6216 2\uff09\u3002\u5982\u679c\u4efb\u4e00\u4f20\u611f\u5668 \u6ca1\u6709\u7f3a\u9677 \uff0c\u6216\u8005 \u65e0\u6cd5 \u786e\u5b9a\u6709\u7f3a\u9677\u7684\u4f20\u611f\u5668\uff0c\u5219\u8fd4\u56de -1 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1asensor1 = [2,3,4,5], sensor2 = [2,1,3,4]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u4f20\u611f\u5668 2 \u8fd4\u56de\u4e86\u6240\u6709\u6b63\u786e\u7684\u6570\u636e.\n\u4f20\u611f\u56682\u5bf9\u7b2c\u4e8c\u4e2a\u6570\u636e\u70b9\u91c7\u96c6\u7684\u6570\u636e\uff0c\u88ab\u4f20\u611f\u56681\u4e22\u5f03\u4e86\uff0c\u4f20\u611f\u56681\u8fd4\u56de\u7684\u6700\u540e\u4e00\u4e2a\u6570\u636e\u88ab\u66ff\u6362\u4e3a 5 \u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1asensor1 = [2,2,2,2,2], sensor2 = [2,2,2,2,5]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u65e0\u6cd5\u5224\u5b9a\u62ff\u4e2a\u4f20\u611f\u5668\u662f\u6709\u7f3a\u9677\u7684\u3002\n\u5047\u8bbe\u4efb\u4e00\u4f20\u611f\u5668\u4e22\u5f03\u7684\u6570\u636e\u662f\u6700\u540e\u4e00\u4f4d\uff0c\u90a3\u4e48\uff0c\u53e6\u4e00\u4e2a\u4f20\u611f\u5668\u5c31\u80fd\u7ed9\u51fa\u4e0e\u4e4b\u5bf9\u5e94\u7684\u8f93\u51fa\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1asensor1 = [2,3,2,2,3,2], sensor2 = [2,3,2,3,2,7]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u4f20\u611f\u5668 1 \u8fd4\u56de\u4e86\u6240\u6709\u6b63\u786e\u7684\u6570\u636e.\n\u4f20\u611f\u5668 1 \u5bf9\u7b2c\u56db\u4e2a\u6570\u636e\u70b9\u7684\u91c7\u96c6\u6570\u636e\uff0c\u88ab\u4f20\u611f\u56682\u4e22\u5931\u4e86, \u4f20\u611f\u5668 2 \u8fd4\u56de\u7684\u6700\u540e\u4e00\u4e2a\u6570\u636e\u88ab\u66ff\u6362\u4e3a 7 \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • sensor1.length == sensor2.length
    • \n\t
    • 1 <= sensor1.length <= 100
    • \n\t
    • 1 <= sensor1[i], sensor2[i] <= 100
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int badSensor(vector& sensor1, vector& sensor2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int badSensor(int[] sensor1, int[] sensor2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def badSensor(self, sensor1, sensor2):\n \"\"\"\n :type sensor1: List[int]\n :type sensor2: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def badSensor(self, sensor1: List[int], sensor2: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint badSensor(int* sensor1, int sensor1Size, int* sensor2, int sensor2Size){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int BadSensor(int[] sensor1, int[] sensor2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} sensor1\n * @param {number[]} sensor2\n * @return {number}\n */\nvar badSensor = function(sensor1, sensor2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} sensor1\n# @param {Integer[]} sensor2\n# @return {Integer}\ndef bad_sensor(sensor1, sensor2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func badSensor(_ sensor1: [Int], _ sensor2: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func badSensor(sensor1 []int, sensor2 []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def badSensor(sensor1: Array[Int], sensor2: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun badSensor(sensor1: IntArray, sensor2: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn bad_sensor(sensor1: Vec, sensor2: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $sensor1\n * @param Integer[] $sensor2\n * @return Integer\n */\n function badSensor($sensor1, $sensor2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function badSensor(sensor1: number[], sensor2: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (bad-sensor sensor1 sensor2)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1826](https://leetcode-cn.com/problems/faulty-sensor)", "[\u6709\u7f3a\u9677\u7684\u4f20\u611f\u5668](/solution/1800-1899/1826.Faulty%20Sensor/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1826](https://leetcode.com/problems/faulty-sensor)", "[Faulty Sensor](/solution/1800-1899/1826.Faulty%20Sensor/README_EN.md)", "`Array`", "Easy", "\ud83d\udd12"]}, {"question_id": "1978", "frontend_question_id": "1850", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-adjacent-swaps-to-reach-the-kth-smallest-number", "url_en": "https://leetcode.com/problems/minimum-adjacent-swaps-to-reach-the-kth-smallest-number", "relative_path_cn": "/solution/1800-1899/1850.Minimum%20Adjacent%20Swaps%20to%20Reach%20the%20Kth%20Smallest%20Number/README.md", "relative_path_en": "/solution/1800-1899/1850.Minimum%20Adjacent%20Swaps%20to%20Reach%20the%20Kth%20Smallest%20Number/README_EN.md", "title_cn": "\u90bb\u4f4d\u4ea4\u6362\u7684\u6700\u5c0f\u6b21\u6570", "title_en": "Minimum Adjacent Swaps to Reach the Kth Smallest Number", "question_title_slug": "minimum-adjacent-swaps-to-reach-the-kth-smallest-number", "content_en": "

    You are given a string num, representing a large integer, and an integer k.

    \n\n

    We call some integer wonderful if it is a permutation of the digits in num and is greater in value than num. There can be many wonderful integers. However, we only care about the smallest-valued ones.

    \n\n
      \n\t
    • For example, when num = "5489355142":\n\n\t
        \n\t\t
      • The 1st smallest wonderful integer is "5489355214".
      • \n\t\t
      • The 2nd smallest wonderful integer is "5489355241".
      • \n\t\t
      • The 3rd smallest wonderful integer is "5489355412".
      • \n\t\t
      • The 4th smallest wonderful integer is "5489355421".
      • \n\t
      \n\t
    • \n
    \n\n

    Return the minimum number of adjacent digit swaps that needs to be applied to num to reach the kth smallest wonderful integer.

    \n\n

    The tests are generated in such a way that kth smallest wonderful integer exists.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: num = "5489355142", k = 4\nOutput: 2\nExplanation: The 4th smallest wonderful number is "5489355421". To get this number:\n- Swap index 7 with index 8: "5489355142" -> "5489355412"\n- Swap index 8 with index 9: "5489355412" -> "5489355421"\n
    \n\n

    Example 2:

    \n\n
    \nInput: num = "11112", k = 4\nOutput: 4\nExplanation: The 4th smallest wonderful number is "21111". To get this number:\n- Swap index 3 with index 4: "11112" -> "11121"\n- Swap index 2 with index 3: "11121" -> "11211"\n- Swap index 1 with index 2: "11211" -> "12111"\n- Swap index 0 with index 1: "12111" -> "21111"\n
    \n\n

    Example 3:

    \n\n
    \nInput: num = "00123", k = 1\nOutput: 1\nExplanation: The 1st smallest wonderful number is "00132". To get this number:\n- Swap index 3 with index 4: "00123" -> "00132"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= num.length <= 1000
    • \n\t
    • 1 <= k <= 1000
    • \n\t
    • num only consists of digits.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u8868\u793a\u5927\u6574\u6570\u7684\u5b57\u7b26\u4e32 num \uff0c\u548c\u4e00\u4e2a\u6574\u6570 k \u3002

    \n\n

    \u5982\u679c\u67d0\u4e2a\u6574\u6570\u662f num \u4e2d\u5404\u4f4d\u6570\u5b57\u7684\u4e00\u4e2a \u6392\u5217 \u4e14\u5b83\u7684 \u503c\u5927\u4e8e num \uff0c\u5219\u79f0\u8fd9\u4e2a\u6574\u6570\u4e3a \u5999\u6570 \u3002\u53ef\u80fd\u5b58\u5728\u5f88\u591a\u5999\u6570\uff0c\u4f46\u662f\u53ea\u9700\u8981\u5173\u6ce8 \u503c\u6700\u5c0f \u7684\u90a3\u4e9b\u3002

    \n\n
      \n\t
    • \u4f8b\u5982\uff0cnum = \"5489355142\" \uff1a\n\n\t
        \n\t\t
      • \u7b2c 1 \u4e2a\u6700\u5c0f\u5999\u6570\u662f \"5489355214\"
      • \n\t\t
      • \u7b2c 2 \u4e2a\u6700\u5c0f\u5999\u6570\u662f \"5489355241\"
      • \n\t\t
      • \u7b2c 3 \u4e2a\u6700\u5c0f\u5999\u6570\u662f \"5489355412\"
      • \n\t\t
      • \u7b2c 4 \u4e2a\u6700\u5c0f\u5999\u6570\u662f \"5489355421\"
      • \n\t
      \n\t
    • \n
    \n\n

    \u8fd4\u56de\u8981\u5f97\u5230\u7b2c k \u4e2a \u6700\u5c0f\u5999\u6570 \u9700\u8981\u5bf9 num \u6267\u884c\u7684 \u76f8\u90bb\u4f4d\u6570\u5b57\u4ea4\u6362\u7684\u6700\u5c0f\u6b21\u6570 \u3002

    \n\n

    \u6d4b\u8bd5\u7528\u4f8b\u662f\u6309\u5b58\u5728\u7b2c k \u4e2a\u6700\u5c0f\u5999\u6570\u800c\u751f\u6210\u7684\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anum = \"5489355142\", k = 4\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u7b2c 4 \u4e2a\u6700\u5c0f\u5999\u6570\u662f \"5489355421\" \uff0c\u8981\u60f3\u5f97\u5230\u8fd9\u4e2a\u6570\u5b57\uff1a\n- \u4ea4\u6362\u4e0b\u6807 7 \u548c\u4e0b\u6807 8 \u5bf9\u5e94\u7684\u4f4d\uff1a\"5489355142\" -> \"5489355412\"\n- \u4ea4\u6362\u4e0b\u6807 8 \u548c\u4e0b\u6807 9 \u5bf9\u5e94\u7684\u4f4d\uff1a\"5489355412\" -> \"5489355421\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anum = \"11112\", k = 4\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u7b2c 4 \u4e2a\u6700\u5c0f\u5999\u6570\u662f \"21111\" \uff0c\u8981\u60f3\u5f97\u5230\u8fd9\u4e2a\u6570\u5b57\uff1a\n- \u4ea4\u6362\u4e0b\u6807 3 \u548c\u4e0b\u6807 4 \u5bf9\u5e94\u7684\u4f4d\uff1a\"11112\" -> \"11121\"\n- \u4ea4\u6362\u4e0b\u6807 2 \u548c\u4e0b\u6807 3 \u5bf9\u5e94\u7684\u4f4d\uff1a\"11121\" -> \"11211\"\n- \u4ea4\u6362\u4e0b\u6807 1 \u548c\u4e0b\u6807 2 \u5bf9\u5e94\u7684\u4f4d\uff1a\"11211\" -> \"12111\"\n- \u4ea4\u6362\u4e0b\u6807 0 \u548c\u4e0b\u6807 1 \u5bf9\u5e94\u7684\u4f4d\uff1a\"12111\" -> \"21111\"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1anum = \"00123\", k = 1\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u7b2c 1 \u4e2a\u6700\u5c0f\u5999\u6570\u662f \"00132\" \uff0c\u8981\u60f3\u5f97\u5230\u8fd9\u4e2a\u6570\u5b57\uff1a\n- \u4ea4\u6362\u4e0b\u6807 3 \u548c\u4e0b\u6807 4 \u5bf9\u5e94\u7684\u4f4d\uff1a\"00123\" -> \"00132\"\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= num.length <= 1000
    • \n\t
    • 1 <= k <= 1000
    • \n\t
    • num \u4ec5\u7531\u6570\u5b57\u7ec4\u6210
    • \n
    \n", "tags_en": ["Greedy", "String"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int getMinSwaps(string num, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int getMinSwaps(String num, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getMinSwaps(self, num, k):\n \"\"\"\n :type num: str\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getMinSwaps(self, num: str, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint getMinSwaps(char * num, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int GetMinSwaps(string num, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} num\n * @param {number} k\n * @return {number}\n */\nvar getMinSwaps = function(num, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} num\n# @param {Integer} k\n# @return {Integer}\ndef get_min_swaps(num, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getMinSwaps(_ num: String, _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getMinSwaps(num string, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getMinSwaps(num: String, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getMinSwaps(num: String, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_min_swaps(num: String, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $num\n * @param Integer $k\n * @return Integer\n */\n function getMinSwaps($num, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getMinSwaps(num: string, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-min-swaps num k)\n (-> string? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1850](https://leetcode-cn.com/problems/minimum-adjacent-swaps-to-reach-the-kth-smallest-number)", "[\u90bb\u4f4d\u4ea4\u6362\u7684\u6700\u5c0f\u6b21\u6570](/solution/1800-1899/1850.Minimum%20Adjacent%20Swaps%20to%20Reach%20the%20Kth%20Smallest%20Number/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1850](https://leetcode.com/problems/minimum-adjacent-swaps-to-reach-the-kth-smallest-number)", "[Minimum Adjacent Swaps to Reach the Kth Smallest Number](/solution/1800-1899/1850.Minimum%20Adjacent%20Swaps%20to%20Reach%20the%20Kth%20Smallest%20Number/README_EN.md)", "`Greedy`,`String`", "Medium", ""]}, {"question_id": "1977", "frontend_question_id": "1851", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-interval-to-include-each-query", "url_en": "https://leetcode.com/problems/minimum-interval-to-include-each-query", "relative_path_cn": "/solution/1800-1899/1851.Minimum%20Interval%20to%20Include%20Each%20Query/README.md", "relative_path_en": "/solution/1800-1899/1851.Minimum%20Interval%20to%20Include%20Each%20Query/README_EN.md", "title_cn": "\u5305\u542b\u6bcf\u4e2a\u67e5\u8be2\u7684\u6700\u5c0f\u533a\u95f4", "title_en": "Minimum Interval to Include Each Query", "question_title_slug": "minimum-interval-to-include-each-query", "content_en": "

    You are given a 2D integer array intervals, where intervals[i] = [lefti, righti] describes the ith interval starting at lefti and ending at righti (inclusive). The size of an interval is defined as the number of integers it contains, or more formally righti - lefti + 1.

    \n\n

    You are also given an integer array queries. The answer to the jth query is the size of the smallest interval i such that lefti <= queries[j] <= righti. If no such interval exists, the answer is -1.

    \n\n

    Return an array containing the answers to the queries.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: intervals = [[1,4],[2,4],[3,6],[4,4]], queries = [2,3,4,5]\nOutput: [3,3,1,4]\nExplanation: The queries are processed as follows:\n- Query = 2: The interval [2,4] is the smallest interval containing 2. The answer is 4 - 2 + 1 = 3.\n- Query = 3: The interval [2,4] is the smallest interval containing 3. The answer is 4 - 2 + 1 = 3.\n- Query = 4: The interval [4,4] is the smallest interval containing 4. The answer is 4 - 4 + 1 = 1.\n- Query = 5: The interval [3,6] is the smallest interval containing 5. The answer is 6 - 3 + 1 = 4.\n
    \n\n

    Example 2:

    \n\n
    \nInput: intervals = [[2,3],[2,5],[1,8],[20,25]], queries = [2,19,5,22]\nOutput: [2,-1,4,6]\nExplanation: The queries are processed as follows:\n- Query = 2: The interval [2,3] is the smallest interval containing 2. The answer is 3 - 2 + 1 = 2.\n- Query = 19: None of the intervals contain 19. The answer is -1.\n- Query = 5: The interval [2,5] is the smallest interval containing 5. The answer is 5 - 2 + 1 = 4.\n- Query = 22: The interval [20,25] is the smallest interval containing 22. The answer is 25 - 20 + 1 = 6.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= intervals.length <= 105
    • \n\t
    • 1 <= queries.length <= 105
    • \n\t
    • intervals[i].length == 2
    • \n\t
    • 1 <= lefti <= righti <= 107
    • \n\t
    • 1 <= queries[j] <= 107
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u4e8c\u7ef4\u6574\u6570\u6570\u7ec4 intervals \uff0c\u5176\u4e2d intervals[i] = [lefti, righti] \u8868\u793a\u7b2c i \u4e2a\u533a\u95f4\u5f00\u59cb\u4e8e lefti \u3001\u7ed3\u675f\u4e8e righti\uff08\u5305\u542b\u4e24\u4fa7\u53d6\u503c\uff0c\u95ed\u533a\u95f4\uff09\u3002\u533a\u95f4\u7684 \u957f\u5ea6 \u5b9a\u4e49\u4e3a\u533a\u95f4\u4e2d\u5305\u542b\u7684\u6574\u6570\u6570\u76ee\uff0c\u66f4\u6b63\u5f0f\u5730\u8868\u8fbe\u662f righti - lefti + 1 \u3002

    \n\n

    \u518d\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 queries \u3002\u7b2c j \u4e2a\u67e5\u8be2\u7684\u7b54\u6848\u662f\u6ee1\u8db3\u00a0lefti <= queries[j] <= righti \u7684 \u957f\u5ea6\u6700\u5c0f\u533a\u95f4 i \u7684\u957f\u5ea6 \u3002\u5982\u679c\u4e0d\u5b58\u5728\u8fd9\u6837\u7684\u533a\u95f4\uff0c\u90a3\u4e48\u7b54\u6848\u662f -1 \u3002

    \n\n

    \u4ee5\u6570\u7ec4\u5f62\u5f0f\u8fd4\u56de\u5bf9\u5e94\u67e5\u8be2\u7684\u6240\u6709\u7b54\u6848\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aintervals = [[1,4],[2,4],[3,6],[4,4]], queries = [2,3,4,5]\n\u8f93\u51fa\uff1a[3,3,1,4]\n\u89e3\u91ca\uff1a\u67e5\u8be2\u5904\u7406\u5982\u4e0b\uff1a\n- Query = 2 \uff1a\u533a\u95f4 [2,4] \u662f\u5305\u542b 2 \u7684\u6700\u5c0f\u533a\u95f4\uff0c\u7b54\u6848\u4e3a 4 - 2 + 1 = 3 \u3002\n- Query = 3 \uff1a\u533a\u95f4 [2,4] \u662f\u5305\u542b 3 \u7684\u6700\u5c0f\u533a\u95f4\uff0c\u7b54\u6848\u4e3a 4 - 2 + 1 = 3 \u3002\n- Query = 4 \uff1a\u533a\u95f4 [4,4] \u662f\u5305\u542b 4 \u7684\u6700\u5c0f\u533a\u95f4\uff0c\u7b54\u6848\u4e3a 4 - 4 + 1 = 1 \u3002\n- Query = 5 \uff1a\u533a\u95f4 [3,6] \u662f\u5305\u542b 5 \u7684\u6700\u5c0f\u533a\u95f4\uff0c\u7b54\u6848\u4e3a 6 - 3 + 1 = 4 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aintervals = [[2,3],[2,5],[1,8],[20,25]], queries = [2,19,5,22]\n\u8f93\u51fa\uff1a[2,-1,4,6]\n\u89e3\u91ca\uff1a\u67e5\u8be2\u5904\u7406\u5982\u4e0b\uff1a\n- Query = 2 \uff1a\u533a\u95f4 [2,3] \u662f\u5305\u542b 2 \u7684\u6700\u5c0f\u533a\u95f4\uff0c\u7b54\u6848\u4e3a 3 - 2 + 1 = 2 \u3002\n- Query = 19\uff1a\u4e0d\u5b58\u5728\u5305\u542b 19 \u7684\u533a\u95f4\uff0c\u7b54\u6848\u4e3a -1 \u3002\n- Query = 5 \uff1a\u533a\u95f4 [2,5] \u662f\u5305\u542b 5 \u7684\u6700\u5c0f\u533a\u95f4\uff0c\u7b54\u6848\u4e3a 5 - 2 + 1 = 4 \u3002\n- Query = 22\uff1a\u533a\u95f4 [20,25] \u662f\u5305\u542b 22 \u7684\u6700\u5c0f\u533a\u95f4\uff0c\u7b54\u6848\u4e3a 25 - 20 + 1 = 6 \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= intervals.length <= 105
    • \n\t
    • 1 <= queries.length <= 105
    • \n\t
    • queries[i].length == 2
    • \n\t
    • 1 <= lefti <= righti <= 107
    • \n\t
    • 1 <= queries[j] <= 107
    • \n
    \n", "tags_en": ["Line Sweep"], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector minInterval(vector>& intervals, vector& queries) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] minInterval(int[][] intervals, int[] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minInterval(self, intervals, queries):\n \"\"\"\n :type intervals: List[List[int]]\n :type queries: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minInterval(self, intervals: List[List[int]], queries: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* minInterval(int** intervals, int intervalsSize, int* intervalsColSize, int* queries, int queriesSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] MinInterval(int[][] intervals, int[] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} intervals\n * @param {number[]} queries\n * @return {number[]}\n */\nvar minInterval = function(intervals, queries) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} intervals\n# @param {Integer[]} queries\n# @return {Integer[]}\ndef min_interval(intervals, queries)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minInterval(_ intervals: [[Int]], _ queries: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minInterval(intervals [][]int, queries []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minInterval(intervals: Array[Array[Int]], queries: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minInterval(intervals: Array, queries: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_interval(intervals: Vec>, queries: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $intervals\n * @param Integer[] $queries\n * @return Integer[]\n */\n function minInterval($intervals, $queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minInterval(intervals: number[][], queries: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-interval intervals queries)\n (-> (listof (listof exact-integer?)) (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1851](https://leetcode-cn.com/problems/minimum-interval-to-include-each-query)", "[\u5305\u542b\u6bcf\u4e2a\u67e5\u8be2\u7684\u6700\u5c0f\u533a\u95f4](/solution/1800-1899/1851.Minimum%20Interval%20to%20Include%20Each%20Query/README.md)", "", "\u56f0\u96be", ""], "md_table_row_en": ["[1851](https://leetcode.com/problems/minimum-interval-to-include-each-query)", "[Minimum Interval to Include Each Query](/solution/1800-1899/1851.Minimum%20Interval%20to%20Include%20Each%20Query/README_EN.md)", "`Line Sweep`", "Hard", ""]}, {"question_id": "1976", "frontend_question_id": "1849", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/splitting-a-string-into-descending-consecutive-values", "url_en": "https://leetcode.com/problems/splitting-a-string-into-descending-consecutive-values", "relative_path_cn": "/solution/1800-1899/1849.Splitting%20a%20String%20Into%20Descending%20Consecutive%20Values/README.md", "relative_path_en": "/solution/1800-1899/1849.Splitting%20a%20String%20Into%20Descending%20Consecutive%20Values/README_EN.md", "title_cn": "\u5c06\u5b57\u7b26\u4e32\u62c6\u5206\u4e3a\u9012\u51cf\u7684\u8fde\u7eed\u503c", "title_en": "Splitting a String Into Descending Consecutive Values", "question_title_slug": "splitting-a-string-into-descending-consecutive-values", "content_en": "

    You are given a string s that consists of only digits.

    \n\n

    Check if we can split s into two or more non-empty substrings such that the numerical values of the substrings are in descending order and the difference between numerical values of every two adjacent substrings is equal to 1.

    \n\n
      \n\t
    • For example, the string s = "0090089" can be split into ["0090", "089"] with numerical values [90,89]. The values are in descending order and adjacent values differ by 1, so this way is valid.
    • \n\t
    • Another example, the string s = "001" can be split into ["0", "01"], ["00", "1"], or ["0", "0", "1"]. However all the ways are invalid because they have numerical values [0,1], [0,1], and [0,0,1] respectively, all of which are not in descending order.
    • \n
    \n\n

    Return true if it is possible to split s\u200b\u200b\u200b\u200b\u200b\u200b as described above, or false otherwise.

    \n\n

    A substring is a contiguous sequence of characters in a string.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "1234"\nOutput: false\nExplanation: There is no valid way to split s.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "050043"\nOutput: true\nExplanation: s can be split into ["05", "004", "3"] with numerical values [5,4,3].\nThe values are in descending order with adjacent values differing by 1.\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "9080701"\nOutput: false\nExplanation: There is no valid way to split s.\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "10009998"\nOutput: true\nExplanation: s can be split into ["100", "099", "98"] with numerical values [100,99,98].\nThe values are in descending order with adjacent values differing by 1.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 20
    • \n\t
    • s only consists of digits.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u4ec5\u7531\u6570\u5b57\u7ec4\u6210\u7684\u5b57\u7b26\u4e32 s \u3002

    \n\n

    \u8bf7\u4f60\u5224\u65ad\u80fd\u5426\u5c06 s \u62c6\u5206\u6210\u4e24\u4e2a\u6216\u8005\u591a\u4e2a \u975e\u7a7a\u5b50\u5b57\u7b26\u4e32 \uff0c\u4f7f\u5b50\u5b57\u7b26\u4e32\u7684 \u6570\u503c \u6309 \u964d\u5e8f \u6392\u5217\uff0c\u4e14\u6bcf\u4e24\u4e2a \u76f8\u90bb\u5b50\u5b57\u7b26\u4e32 \u7684\u6570\u503c\u4e4b \u5dee \u7b49\u4e8e 1 \u3002

    \n\n
      \n\t
    • \u4f8b\u5982\uff0c\u5b57\u7b26\u4e32 s = \"0090089\" \u53ef\u4ee5\u62c6\u5206\u6210 [\"0090\", \"089\"] \uff0c\u6570\u503c\u4e3a [90,89] \u3002\u8fd9\u4e9b\u6570\u503c\u6ee1\u8db3\u6309\u964d\u5e8f\u6392\u5217\uff0c\u4e14\u76f8\u90bb\u503c\u76f8\u5dee 1 \uff0c\u8fd9\u79cd\u62c6\u5206\u65b9\u6cd5\u53ef\u884c\u3002
    • \n\t
    • \u53e6\u4e00\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u5b57\u7b26\u4e32 s = \"001\" \u53ef\u4ee5\u62c6\u5206\u6210 [\"0\", \"01\"]\u3001[\"00\", \"1\"] \u6216 [\"0\", \"0\", \"1\"] \u3002\u7136\u800c\uff0c\u6240\u6709\u8fd9\u4e9b\u62c6\u5206\u65b9\u6cd5\u90fd\u4e0d\u53ef\u884c\uff0c\u56e0\u4e3a\u5bf9\u5e94\u6570\u503c\u5206\u522b\u662f [0,1]\u3001[0,1] \u548c [0,0,1] \uff0c\u90fd\u4e0d\u6ee1\u8db3\u6309\u964d\u5e8f\u6392\u5217\u7684\u8981\u6c42\u3002
    • \n
    \n\n

    \u5982\u679c\u53ef\u4ee5\u6309\u8981\u6c42\u62c6\u5206 s \uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n

    \u5b50\u5b57\u7b26\u4e32 \u662f\u5b57\u7b26\u4e32\u4e2d\u7684\u4e00\u4e2a\u8fde\u7eed\u5b57\u7b26\u5e8f\u5217\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"1234\"\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u4e0d\u5b58\u5728\u62c6\u5206 s \u7684\u53ef\u884c\u65b9\u6cd5\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"050043\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1as \u53ef\u4ee5\u62c6\u5206\u4e3a [\"05\", \"004\", \"3\"] \uff0c\u5bf9\u5e94\u6570\u503c\u4e3a [5,4,3] \u3002\n\u6ee1\u8db3\u6309\u964d\u5e8f\u6392\u5217\uff0c\u4e14\u76f8\u90bb\u503c\u76f8\u5dee 1 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"9080701\"\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u4e0d\u5b58\u5728\u62c6\u5206 s \u7684\u53ef\u884c\u65b9\u6cd5\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"10009998\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1as \u53ef\u4ee5\u62c6\u5206\u4e3a [\"100\", \"099\", \"98\"] \uff0c\u5bf9\u5e94\u6570\u503c\u4e3a [100,99,98] \u3002\n\u6ee1\u8db3\u6309\u964d\u5e8f\u6392\u5217\uff0c\u4e14\u76f8\u90bb\u503c\u76f8\u5dee 1 \u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 20
    • \n\t
    • s \u4ec5\u7531\u6570\u5b57\u7ec4\u6210
    • \n
    \n", "tags_en": ["Recursion", "String", "Backtracking"], "tags_cn": ["\u9012\u5f52", "\u5b57\u7b26\u4e32", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool splitString(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean splitString(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def splitString(self, s):\n \"\"\"\n :type s: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def splitString(self, s: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool splitString(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool SplitString(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {boolean}\n */\nvar splitString = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Boolean}\ndef split_string(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func splitString(_ s: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func splitString(s string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def splitString(s: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun splitString(s: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn split_string(s: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Boolean\n */\n function splitString($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function splitString(s: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (split-string s)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1849](https://leetcode-cn.com/problems/splitting-a-string-into-descending-consecutive-values)", "[\u5c06\u5b57\u7b26\u4e32\u62c6\u5206\u4e3a\u9012\u51cf\u7684\u8fde\u7eed\u503c](/solution/1800-1899/1849.Splitting%20a%20String%20Into%20Descending%20Consecutive%20Values/README.md)", "`\u9012\u5f52`,`\u5b57\u7b26\u4e32`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1849](https://leetcode.com/problems/splitting-a-string-into-descending-consecutive-values)", "[Splitting a String Into Descending Consecutive Values](/solution/1800-1899/1849.Splitting%20a%20String%20Into%20Descending%20Consecutive%20Values/README_EN.md)", "`Recursion`,`String`,`Backtracking`", "Medium", ""]}, {"question_id": "1975", "frontend_question_id": "1848", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-distance-to-the-target-element", "url_en": "https://leetcode.com/problems/minimum-distance-to-the-target-element", "relative_path_cn": "/solution/1800-1899/1848.Minimum%20Distance%20to%20the%20Target%20Element/README.md", "relative_path_en": "/solution/1800-1899/1848.Minimum%20Distance%20to%20the%20Target%20Element/README_EN.md", "title_cn": "\u5230\u76ee\u6807\u5143\u7d20\u7684\u6700\u5c0f\u8ddd\u79bb", "title_en": "Minimum Distance to the Target Element", "question_title_slug": "minimum-distance-to-the-target-element", "content_en": "

    Given an integer array nums (0-indexed) and two integers target and start, find an index i such that nums[i] == target and abs(i - start) is minimized. Note that abs(x) is the absolute value of x.

    \n\n

    Return abs(i - start).

    \n\n

    It is guaranteed that target exists in nums.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,3,4,5], target = 5, start = 3\nOutput: 1\nExplanation: nums[4] = 5 is the only value equal to target, so the answer is abs(4 - 3) = 1.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1], target = 1, start = 0\nOutput: 0\nExplanation: nums[0] = 1 is the only value equal to target, so the answer is abs(0 - 0) = 0.\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [1,1,1,1,1,1,1,1,1,1], target = 1, start = 0\nOutput: 0\nExplanation: Every value of nums is 1, but nums[0] minimizes abs(i - start), which is abs(0 - 0) = 0.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 1000
    • \n\t
    • 1 <= nums[i] <= 104
    • \n\t
    • 0 <= start < nums.length
    • \n\t
    • target is in nums.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \uff08\u4e0b\u6807 \u4ece 0 \u5f00\u59cb \u8ba1\u6570\uff09\u4ee5\u53ca\u4e24\u4e2a\u6574\u6570 target \u548c start \uff0c\u8bf7\u4f60\u627e\u51fa\u4e00\u4e2a\u4e0b\u6807 i \uff0c\u6ee1\u8db3 nums[i] == target \u4e14 abs(i - start) \u6700\u5c0f\u5316 \u3002\u6ce8\u610f\uff1aabs(x) \u8868\u793a x \u7684\u7edd\u5bf9\u503c\u3002

    \n\n

    \u8fd4\u56de abs(i - start) \u3002

    \n\n

    \u9898\u76ee\u6570\u636e\u4fdd\u8bc1 target \u5b58\u5728\u4e8e nums \u4e2d\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,3,4,5], target = 5, start = 3\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1anums[4] = 5 \u662f\u552f\u4e00\u4e00\u4e2a\u7b49\u4e8e target \u7684\u503c\uff0c\u6240\u4ee5\u7b54\u6848\u662f abs(4 - 3) = 1 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1], target = 1, start = 0\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1anums[0] = 1 \u662f\u552f\u4e00\u4e00\u4e2a\u7b49\u4e8e target \u7684\u503c\uff0c\u6240\u4ee5\u7b54\u6848\u662f abs(0 - 0) = 0 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,1,1,1,1,1,1,1,1,1], target = 1, start = 0\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1anums \u4e2d\u7684\u6bcf\u4e2a\u503c\u90fd\u662f 1 \uff0c\u4f46 nums[0] \u4f7f abs(i - start) \u7684\u7ed3\u679c\u5f97\u4ee5\u6700\u5c0f\u5316\uff0c\u6240\u4ee5\u7b54\u6848\u662f abs(0 - 0) = 0 \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 1000
    • \n\t
    • 1 <= nums[i] <= 104
    • \n\t
    • 0 <= start < nums.length
    • \n\t
    • target \u5b58\u5728\u4e8e nums \u4e2d
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int getMinDistance(vector& nums, int target, int start) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int getMinDistance(int[] nums, int target, int start) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getMinDistance(self, nums, target, start):\n \"\"\"\n :type nums: List[int]\n :type target: int\n :type start: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getMinDistance(self, nums: List[int], target: int, start: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint getMinDistance(int* nums, int numsSize, int target, int start){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int GetMinDistance(int[] nums, int target, int start) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} target\n * @param {number} start\n * @return {number}\n */\nvar getMinDistance = function(nums, target, start) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} target\n# @param {Integer} start\n# @return {Integer}\ndef get_min_distance(nums, target, start)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getMinDistance(_ nums: [Int], _ target: Int, _ start: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getMinDistance(nums []int, target int, start int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getMinDistance(nums: Array[Int], target: Int, start: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getMinDistance(nums: IntArray, target: Int, start: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_min_distance(nums: Vec, target: i32, start: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $target\n * @param Integer $start\n * @return Integer\n */\n function getMinDistance($nums, $target, $start) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getMinDistance(nums: number[], target: number, start: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-min-distance nums target start)\n (-> (listof exact-integer?) exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1848](https://leetcode-cn.com/problems/minimum-distance-to-the-target-element)", "[\u5230\u76ee\u6807\u5143\u7d20\u7684\u6700\u5c0f\u8ddd\u79bb](/solution/1800-1899/1848.Minimum%20Distance%20to%20the%20Target%20Element/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1848](https://leetcode.com/problems/minimum-distance-to-the-target-element)", "[Minimum Distance to the Target Element](/solution/1800-1899/1848.Minimum%20Distance%20to%20the%20Target%20Element/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1974", "frontend_question_id": "1821", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/find-customers-with-positive-revenue-this-year", "url_en": "https://leetcode.com/problems/find-customers-with-positive-revenue-this-year", "relative_path_cn": "/solution/1800-1899/1821.Find%20Customers%20With%20Positive%20Revenue%20this%20Year/README.md", "relative_path_en": "/solution/1800-1899/1821.Find%20Customers%20With%20Positive%20Revenue%20this%20Year/README_EN.md", "title_cn": "\u5bfb\u627e\u4eca\u5e74\u5177\u6709\u6b63\u6536\u5165\u7684\u5ba2\u6237", "title_en": "Find Customers With Positive Revenue this Year", "question_title_slug": "find-customers-with-positive-revenue-this-year", "content_en": "

    Table: Customers

    \n\n
    \n+--------------+------+\n| Column Name  | Type |\n+--------------+------+\n| customer_id  | int  |\n| year         | int  |\n| revenue      | int  |\n+--------------+------+\n(customer_id, year) is the primary key for this table.\nThis table contains the customer ID and the revenue of customers in different years.\nNote that this revenue can be negative.\n
    \n\n

     

    \n\n

    Write an SQL query to report the customers with postive revenue in the year 2021.

    \n\n

    Return the result table in any order.

    \n\n

    The query result format is in the following example:

    \n\n

     

    \n\n
    \nCustomers\n+-------------+------+---------+\n| customer_id | year | revenue |\n+-------------+------+---------+\n| 1           | 2018 | 50      |\n| 1           | 2021 | 30      |\n| 1           | 2020 | 70      |\n| 2           | 2021 | -50     |\n| 3           | 2018 | 10      |\n| 3           | 2016 | 50      |\n| 4           | 2021 | 20      |\n+-------------+------+---------+\n\nResult table:\n+-------------+\n| customer_id |\n+-------------+\n| 1           |\n| 4           |\n+-------------+\n\nCustomer 1 has revenue equal to 30 in year 2021.\nCustomer 2 has revenue equal to -50 in year 2021.\nCustomer 3 has no revenue in year 2021.\nCustomer 4 has revenue equal to 20 in year 2021.\nThus only customers 1 and 4 have postive revenue in year 2021.
    \n", "content_cn": "

    \u8868\uff1aCustomers

    \n\n
    \n+--------------+------+\n| Column Name  | Type |\n+--------------+------+\n| customer_id  | int  |\n| year         | int  |\n| revenue      | int  |\n+--------------+------+\n(customer_id, year) \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\u3002\n\u8fd9\u4e2a\u8868\u5305\u542b\u5ba2\u6237 ID \u548c\u4e0d\u540c\u5e74\u4efd\u7684\u5ba2\u6237\u6536\u5165\u3002\n\u6ce8\u610f\uff0c\u8fd9\u4e2a\u6536\u5165\u53ef\u80fd\u662f\u8d1f\u6570\u3002\n
    \n\n

    \u00a0

    \n\n

    \u5199\u4e00\u4e2a SQL \u67e5\u8be2\u6765\u67e5\u8be2 2021 \u5e74\u5177\u6709 \u6b63\u6536\u5165 \u7684\u5ba2\u6237\u3002

    \n\n

    \u53ef\u4ee5\u6309 \u4efb\u610f\u987a\u5e8f \u8fd4\u56de\u7ed3\u679c\u8868\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u3002

    \n\n

    \u00a0

    \n\n
    \nCustomers\n+-------------+------+---------+\n| customer_id | year | revenue |\n+-------------+------+---------+\n| 1           | 2018 | 50      |\n| 1           | 2021 | 30      |\n| 1           | 2020 | 70      |\n| 2           | 2021 | -50     |\n| 3           | 2018 | 10      |\n| 3           | 2016 | 50      |\n| 4           | 2021 | 20      |\n+-------------+------+---------+\n\nResult table:\n+-------------+\n| customer_id |\n+-------------+\n| 1           |\n| 4           |\n+-------------+\n\u5ba2\u6237 1 \u5728 2021 \u5e74\u7684\u6536\u5165\u7b49\u4e8e 30 \u3002\n\u5ba2\u6237 2 \u5728 2021 \u5e74\u7684\u6536\u5165\u7b49\u4e8e -50 \u3002\n\u5ba2\u6237 3 \u5728 2021 \u5e74\u6ca1\u6709\u6536\u5165\u3002\n\u5ba2\u6237 4 \u5728 2021 \u5e74\u7684\u6536\u5165\u7b49\u4e8e 20 \u3002\n\u56e0\u6b64\uff0c\u53ea\u6709\u5ba2\u6237 1 \u548c 4 \u5728 2021 \u5e74\u6709\u6b63\u6536\u5165\u3002
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1821](https://leetcode-cn.com/problems/find-customers-with-positive-revenue-this-year)", "[\u5bfb\u627e\u4eca\u5e74\u5177\u6709\u6b63\u6536\u5165\u7684\u5ba2\u6237](/solution/1800-1899/1821.Find%20Customers%20With%20Positive%20Revenue%20this%20Year/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1821](https://leetcode.com/problems/find-customers-with-positive-revenue-this-year)", "[Find Customers With Positive Revenue this Year](/solution/1800-1899/1821.Find%20Customers%20With%20Positive%20Revenue%20this%20Year/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1972", "frontend_question_id": "1861", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/rotating-the-box", "url_en": "https://leetcode.com/problems/rotating-the-box", "relative_path_cn": "/solution/1800-1899/1861.Rotating%20the%20Box/README.md", "relative_path_en": "/solution/1800-1899/1861.Rotating%20the%20Box/README_EN.md", "title_cn": "\u65cb\u8f6c\u76d2\u5b50", "title_en": "Rotating the Box", "question_title_slug": "rotating-the-box", "content_en": "

    You are given an m x n matrix of characters box representing a side-view of a box. Each cell of the box is one of the following:

    \r\n\r\n
      \r\n\t
    • A stone '#'
    • \r\n\t
    • A stationary obstacle '*'
    • \r\n\t
    • Empty '.'
    • \r\n
    \r\n\r\n

    The box is rotated 90 degrees clockwise, causing some of the stones to fall due to gravity. Each stone falls down until it lands on an obstacle, another stone, or the bottom of the box. Gravity does not affect the obstacles' positions, and the inertia from the box's rotation does not affect the stones' horizontal positions.

    \r\n\r\n

    It is guaranteed that each stone in box rests on an obstacle, another stone, or the bottom of the box.

    \r\n\r\n

    Return an n x m matrix representing the box after the rotation described above.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n

    \"\"

    \r\n\r\n
    \r\nInput: box = [["#",".","#"]]\r\nOutput: [["."],\r\n         ["#"],\r\n         ["#"]]\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n

    \"\"

    \r\n\r\n
    \r\nInput: box = [["#",".","*","."],\r\n              ["#","#","*","."]]\r\nOutput: [["#","."],\r\n         ["#","#"],\r\n         ["*","*"],\r\n         [".","."]]\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n

    \"\"

    \r\n\r\n
    \r\nInput: box = [["#","#","*",".","*","."],\r\n              ["#","#","#","*",".","."],\r\n              ["#","#","#",".","#","."]]\r\nOutput: [[".","#","#"],\r\n         [".","#","#"],\r\n         ["#","#","*"],\r\n         ["#","*","."],\r\n         ["#",".","*"],\r\n         ["#",".","."]]\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • m == box.length
    • \r\n\t
    • n == box[i].length
    • \r\n\t
    • 1 <= m, n <= 500
    • \r\n\t
    • box[i][j] is either '#', '*', or '.'.
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u00a0m x n\u00a0\u7684\u5b57\u7b26\u77e9\u9635\u00a0box\u00a0\uff0c\u5b83\u8868\u793a\u4e00\u4e2a\u7bb1\u5b50\u7684\u4fa7\u89c6\u56fe\u3002\u7bb1\u5b50\u7684\u6bcf\u4e00\u4e2a\u683c\u5b50\u53ef\u80fd\u4e3a\uff1a

    \n\n
      \n\t
    • '#'\u00a0\u8868\u793a\u77f3\u5934
    • \n\t
    • '*'\u00a0\u8868\u793a\u56fa\u5b9a\u7684\u969c\u788d\u7269
    • \n\t
    • '.'\u00a0\u8868\u793a\u7a7a\u4f4d\u7f6e
    • \n
    \n\n

    \u8fd9\u4e2a\u7bb1\u5b50\u88ab \u987a\u65f6\u9488\u65cb\u8f6c 90 \u5ea6\u00a0\uff0c\u7531\u4e8e\u91cd\u529b\u539f\u56e0\uff0c\u90e8\u5206\u77f3\u5934\u7684\u4f4d\u7f6e\u4f1a\u53d1\u751f\u6539\u53d8\u3002\u6bcf\u4e2a\u77f3\u5934\u4f1a\u5782\u76f4\u6389\u843d\uff0c\u76f4\u5230\u5b83\u9047\u5230\u969c\u788d\u7269\uff0c\u53e6\u4e00\u4e2a\u77f3\u5934\u6216\u8005\u7bb1\u5b50\u7684\u5e95\u90e8\u3002\u91cd\u529b \u4e0d\u4f1a\u00a0\u5f71\u54cd\u969c\u788d\u7269\u7684\u4f4d\u7f6e\uff0c\u540c\u65f6\u7bb1\u5b50\u65cb\u8f6c\u4e0d\u4f1a\u4ea7\u751f\u60ef\u6027\u00a0\uff0c\u4e5f\u5c31\u662f\u8bf4\u77f3\u5934\u7684\u6c34\u5e73\u4f4d\u7f6e\u4e0d\u4f1a\u53d1\u751f\u6539\u53d8\u3002

    \n\n

    \u9898\u76ee\u4fdd\u8bc1\u521d\u59cb\u65f6\u00a0box\u00a0\u4e2d\u7684\u77f3\u5934\u8981\u4e48\u5728\u4e00\u4e2a\u969c\u788d\u7269\u4e0a\uff0c\u8981\u4e48\u5728\u53e6\u4e00\u4e2a\u77f3\u5934\u4e0a\uff0c\u8981\u4e48\u5728\u7bb1\u5b50\u7684\u5e95\u90e8\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u4e00\u4e2a\u00a0n x m\u7684\u77e9\u9635\uff0c\u8868\u793a\u6309\u7167\u4e0a\u8ff0\u65cb\u8f6c\u540e\uff0c\u7bb1\u5b50\u5185\u7684\u7ed3\u679c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1abox = [[\"#\",\".\",\"#\"]]\n\u8f93\u51fa\uff1a[[\".\"],\n\u00a0     [\"#\"],\n\u00a0     [\"#\"]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1abox = [[\"#\",\".\",\"*\",\".\"],\n\u00a0           [\"#\",\"#\",\"*\",\".\"]]\n\u8f93\u51fa\uff1a[[\"#\",\".\"],\n\u00a0     [\"#\",\"#\"],\n\u00a0     [\"*\",\"*\"],\n\u00a0     [\".\",\".\"]]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1abox = [[\"#\",\"#\",\"*\",\".\",\"*\",\".\"],\n\u00a0           [\"#\",\"#\",\"#\",\"*\",\".\",\".\"],\n\u00a0           [\"#\",\"#\",\"#\",\".\",\"#\",\".\"]]\n\u8f93\u51fa\uff1a[[\".\",\"#\",\"#\"],\n\u00a0     [\".\",\"#\",\"#\"],\n\u00a0     [\"#\",\"#\",\"*\"],\n\u00a0     [\"#\",\"*\",\".\"],\n\u00a0     [\"#\",\".\",\"*\"],\n\u00a0     [\"#\",\".\",\".\"]]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == box.length
    • \n\t
    • n == box[i].length
    • \n\t
    • 1 <= m, n <= 500
    • \n\t
    • box[i][j]\u00a0\u53ea\u53ef\u80fd\u662f\u00a0'#'\u00a0\uff0c'*'\u00a0\u6216\u8005\u00a0'.'\u00a0\u3002
    • \n
    \n", "tags_en": ["Array", "Two Pointers"], "tags_cn": ["\u6570\u7ec4", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> rotateTheBox(vector>& box) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public char[][] rotateTheBox(char[][] box) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def rotateTheBox(self, box):\n \"\"\"\n :type box: List[List[str]]\n :rtype: List[List[str]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def rotateTheBox(self, box: List[List[str]]) -> List[List[str]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nchar** rotateTheBox(char** box, int boxSize, int* boxColSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public char[][] RotateTheBox(char[][] box) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {character[][]} box\n * @return {character[][]}\n */\nvar rotateTheBox = function(box) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Character[][]} box\n# @return {Character[][]}\ndef rotate_the_box(box)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func rotateTheBox(_ box: [[Character]]) -> [[Character]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func rotateTheBox(box [][]byte) [][]byte {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def rotateTheBox(box: Array[Array[Char]]): Array[Array[Char]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun rotateTheBox(box: Array): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn rotate_the_box(box: Vec>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $box\n * @return String[][]\n */\n function rotateTheBox($box) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function rotateTheBox(box: string[][]): string[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (rotate-the-box box)\n (-> (listof (listof char?)) (listof (listof char?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1861](https://leetcode-cn.com/problems/rotating-the-box)", "[\u65cb\u8f6c\u76d2\u5b50](/solution/1800-1899/1861.Rotating%20the%20Box/README.md)", "`\u6570\u7ec4`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1861](https://leetcode.com/problems/rotating-the-box)", "[Rotating the Box](/solution/1800-1899/1861.Rotating%20the%20Box/README_EN.md)", "`Array`,`Two Pointers`", "Medium", ""]}, {"question_id": "1971", "frontend_question_id": "1860", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/incremental-memory-leak", "url_en": "https://leetcode.com/problems/incremental-memory-leak", "relative_path_cn": "/solution/1800-1899/1860.Incremental%20Memory%20Leak/README.md", "relative_path_en": "/solution/1800-1899/1860.Incremental%20Memory%20Leak/README_EN.md", "title_cn": "\u589e\u957f\u7684\u5185\u5b58\u6cc4\u9732", "title_en": "Incremental Memory Leak", "question_title_slug": "incremental-memory-leak", "content_en": "

    You are given two integers memory1 and memory2 representing the available memory in bits on two memory sticks. There is currently a faulty program running that consumes an increasing amount of memory every second.

    \n\n

    At the ith second (starting from 1), i bits of memory are allocated to the stick with more available memory (or from the first memory stick if both have the same available memory). If neither stick has at least i bits of available memory, the program crashes.

    \n\n

    Return an array containing [crashTime, memory1crash, memory2crash], where crashTime is the time (in seconds) when the program crashed and memory1crash and memory2crash are the available bits of memory in the first and second sticks respectively.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: memory1 = 2, memory2 = 2\nOutput: [3,1,0]\nExplanation: The memory is allocated as follows:\n- At the 1st second, 1 bit of memory is allocated to stick 1. The first stick now has 1 bit of available memory.\n- At the 2nd second, 2 bits of memory are allocated to stick 2. The second stick now has 0 bits of available memory.\n- At the 3rd second, the program crashes. The sticks have 1 and 0 bits available respectively.\n
    \n\n

    Example 2:

    \n\n
    \nInput: memory1 = 8, memory2 = 11\nOutput: [6,0,4]\nExplanation: The memory is allocated as follows:\n- At the 1st second, 1 bit of memory is allocated to stick 2. The second stick now has 10 bit of available memory.\n- At the 2nd second, 2 bits of memory are allocated to stick 2. The second stick now has 8 bits of available memory.\n- At the 3rd second, 3 bits of memory are allocated to stick 1. The first stick now has 5 bits of available memory.\n- At the 4th second, 4 bits of memory are allocated to stick 2. The second stick now has 4 bits of available memory.\n- At the 5th second, 5 bits of memory are allocated to stick 1. The first stick now has 0 bits of available memory.\n- At the 6th second, the program crashes. The sticks have 0 and 4 bits available respectively.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= memory1, memory2 <= 231 - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u6574\u6570\u00a0memory1 \u548c\u00a0memory2\u00a0\u5206\u522b\u8868\u793a\u4e24\u4e2a\u5185\u5b58\u6761\u5269\u4f59\u53ef\u7528\u5185\u5b58\u7684\u4f4d\u6570\u3002\u73b0\u5728\u6709\u4e00\u4e2a\u7a0b\u5e8f\u6bcf\u79d2\u9012\u589e\u7684\u901f\u5ea6\u6d88\u8017\u7740\u5185\u5b58\u3002

    \n\n

    \u5728\u7b2c\u00a0i\u00a0\u79d2\uff08\u79d2\u6570\u4ece 1 \u5f00\u59cb\uff09\uff0c\u6709 i\u00a0\u4f4d\u5185\u5b58\u88ab\u5206\u914d\u5230\u00a0\u5269\u4f59\u5185\u5b58\u8f83\u591a\u00a0\u7684\u5185\u5b58\u6761\uff08\u5982\u679c\u4e24\u8005\u4e00\u6837\u591a\uff0c\u5219\u5206\u914d\u5230\u7b2c\u4e00\u4e2a\u5185\u5b58\u6761\uff09\u3002\u5982\u679c\u4e24\u8005\u5269\u4f59\u5185\u5b58\u90fd\u4e0d\u8db3 i\u00a0\u4f4d\uff0c\u90a3\u4e48\u7a0b\u5e8f\u5c06 \u610f\u5916\u9000\u51fa\u00a0\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u4e00\u4e2a\u6570\u7ec4\uff0c\u5305\u542b [crashTime, memory1crash, memory2crash]\u00a0\uff0c\u5176\u4e2d\u00a0crashTime\u662f\u7a0b\u5e8f\u610f\u5916\u9000\u51fa\u7684\u65f6\u95f4\uff08\u5355\u4f4d\u4e3a\u79d2\uff09\uff0c\u00a0memory1crash \u548c\u00a0memory2crash\u00a0\u5206\u522b\u662f\u4e24\u4e2a\u5185\u5b58\u6761\u6700\u540e\u5269\u4f59\u5185\u5b58\u7684\u4f4d\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1amemory1 = 2, memory2 = 2\n\u8f93\u51fa\uff1a[3,1,0]\n\u89e3\u91ca\uff1a\u5185\u5b58\u5206\u914d\u5982\u4e0b\uff1a\n- \u7b2c 1 \u79d2\uff0c\u5185\u5b58\u6761 1 \u88ab\u5360\u7528 1 \u4f4d\u5185\u5b58\u3002\u5185\u5b58\u6761 1 \u73b0\u5728\u6709 1 \u4f4d\u5269\u4f59\u53ef\u7528\u5185\u5b58\u3002\n- \u7b2c 2 \u79d2\uff0c\u5185\u5b58\u6761 2 \u88ab\u5360\u7528 2 \u4f4d\u5185\u5b58\u3002\u5185\u5b58\u6761 2 \u73b0\u5728\u6709 0 \u4f4d\u5269\u4f59\u53ef\u7528\u5185\u5b58\u3002\n- \u7b2c 3 \u79d2\uff0c\u7a0b\u5e8f\u610f\u5916\u9000\u51fa\uff0c\u4e24\u4e2a\u5185\u5b58\u6761\u5206\u522b\u6709 1 \u4f4d\u548c 0 \u4f4d\u5269\u4f59\u53ef\u7528\u5185\u5b58\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1amemory1 = 8, memory2 = 11\n\u8f93\u51fa\uff1a[6,0,4]\n\u89e3\u91ca\uff1a\u5185\u5b58\u5206\u914d\u5982\u4e0b\uff1a\n- \u7b2c 1 \u79d2\uff0c\u5185\u5b58\u6761 2 \u88ab\u5360\u7528 1 \u4f4d\u5185\u5b58\uff0c\u5185\u5b58\u6761 2 \u73b0\u5728\u6709 10 \u4f4d\u5269\u4f59\u53ef\u7528\u5185\u5b58\u3002\n- \u7b2c 2 \u79d2\uff0c\u5185\u5b58\u6761 2 \u88ab\u5360\u7528 2 \u4f4d\u5185\u5b58\uff0c\u5185\u5b58\u6761 2 \u73b0\u5728\u6709 8 \u4f4d\u5269\u4f59\u53ef\u7528\u5185\u5b58\u3002\n- \u7b2c 3 \u79d2\uff0c\u5185\u5b58\u6761 1 \u88ab\u5360\u7528 3 \u4f4d\u5185\u5b58\uff0c\u5185\u5b58\u6761 1 \u73b0\u5728\u6709 5 \u4f4d\u5269\u4f59\u53ef\u7528\u5185\u5b58\u3002\n- \u7b2c 4 \u79d2\uff0c\u5185\u5b58\u6761 2 \u88ab\u5360\u7528 4 \u4f4d\u5185\u5b58\uff0c\u5185\u5b58\u6761 2 \u73b0\u5728\u6709 4 \u4f4d\u5269\u4f59\u53ef\u7528\u5185\u5b58\u3002\n- \u7b2c 5 \u79d2\uff0c\u5185\u5b58\u6761 1 \u88ab\u5360\u7528 5 \u4f4d\u5185\u5b58\uff0c\u5185\u5b58\u6761 1 \u73b0\u5728\u6709 0 \u4f4d\u5269\u4f59\u53ef\u7528\u5185\u5b58\u3002\n- \u7b2c 6 \u79d2\uff0c\u7a0b\u5e8f\u610f\u5916\u9000\u51fa\uff0c\u4e24\u4e2a\u5185\u5b58\u6761\u5206\u522b\u6709 0 \u4f4d\u548c 4 \u4f4d\u5269\u4f59\u53ef\u7528\u5185\u5b58\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= memory1, memory2 <= 231 - 1
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector memLeak(int memory1, int memory2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] memLeak(int memory1, int memory2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def memLeak(self, memory1, memory2):\n \"\"\"\n :type memory1: int\n :type memory2: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def memLeak(self, memory1: int, memory2: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* memLeak(int memory1, int memory2, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] MemLeak(int memory1, int memory2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} memory1\n * @param {number} memory2\n * @return {number[]}\n */\nvar memLeak = function(memory1, memory2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} memory1\n# @param {Integer} memory2\n# @return {Integer[]}\ndef mem_leak(memory1, memory2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func memLeak(_ memory1: Int, _ memory2: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func memLeak(memory1 int, memory2 int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def memLeak(memory1: Int, memory2: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun memLeak(memory1: Int, memory2: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn mem_leak(memory1: i32, memory2: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $memory1\n * @param Integer $memory2\n * @return Integer[]\n */\n function memLeak($memory1, $memory2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function memLeak(memory1: number, memory2: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (mem-leak memory1 memory2)\n (-> exact-integer? exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1860](https://leetcode-cn.com/problems/incremental-memory-leak)", "[\u589e\u957f\u7684\u5185\u5b58\u6cc4\u9732](/solution/1800-1899/1860.Incremental%20Memory%20Leak/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1860](https://leetcode.com/problems/incremental-memory-leak)", "[Incremental Memory Leak](/solution/1800-1899/1860.Incremental%20Memory%20Leak/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "1970", "frontend_question_id": "1859", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sorting-the-sentence", "url_en": "https://leetcode.com/problems/sorting-the-sentence", "relative_path_cn": "/solution/1800-1899/1859.Sorting%20the%20Sentence/README.md", "relative_path_en": "/solution/1800-1899/1859.Sorting%20the%20Sentence/README_EN.md", "title_cn": "\u5c06\u53e5\u5b50\u6392\u5e8f", "title_en": "Sorting the Sentence", "question_title_slug": "sorting-the-sentence", "content_en": "

    A sentence is a list of words that are separated by a single space with no leading or trailing spaces. Each word consists of lowercase and uppercase English letters.

    \r\n\r\n

    A sentence can be shuffled by appending the 1-indexed word position to each word then rearranging the words in the sentence.

    \r\n\r\n
      \r\n\t
    • For example, the sentence "This is a sentence" can be shuffled as "sentence4 a3 is2 This1" or "is2 sentence4 This1 a3".
    • \r\n
    \r\n\r\n

    Given a shuffled sentence s containing no more than 9 words, reconstruct and return the original sentence.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: s = "is2 sentence4 This1 a3"\r\nOutput: "This is a sentence"\r\nExplanation: Sort the words in s to their original positions "This1 is2 a3 sentence4", then remove the numbers.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: s = "Myself2 Me1 I4 and3"\r\nOutput: "Me Myself and I"\r\nExplanation: Sort the words in s to their original positions "Me1 Myself2 and3 I4", then remove the numbers.\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 2 <= s.length <= 200
    • \r\n\t
    • s consists of lowercase and uppercase English letters, spaces, and digits from 1 to 9.
    • \r\n\t
    • The number of words in s is between 1 and 9.
    • \r\n\t
    • The words in s are separated by a single space.
    • \r\n\t
    • s contains no leading or trailing spaces.
    • \r\n
    ", "content_cn": "

    \u4e00\u4e2a \u53e5\u5b50\u00a0\u6307\u7684\u662f\u4e00\u4e2a\u5e8f\u5217\u7684\u5355\u8bcd\u7528\u5355\u4e2a\u7a7a\u683c\u8fde\u63a5\u8d77\u6765\uff0c\u4e14\u5f00\u5934\u548c\u7ed3\u5c3e\u6ca1\u6709\u4efb\u4f55\u7a7a\u683c\u3002\u6bcf\u4e2a\u5355\u8bcd\u90fd\u53ea\u5305\u542b\u5c0f\u5199\u6216\u5927\u5199\u82f1\u6587\u5b57\u6bcd\u3002

    \n\n

    \u6211\u4eec\u53ef\u4ee5\u7ed9\u4e00\u4e2a\u53e5\u5b50\u6dfb\u52a0 \u4ece 1 \u5f00\u59cb\u7684\u5355\u8bcd\u4f4d\u7f6e\u7d22\u5f15 \uff0c\u5e76\u4e14\u5c06\u53e5\u5b50\u4e2d\u6240\u6709\u5355\u8bcd\u00a0\u6253\u4e71\u987a\u5e8f\u00a0\u3002

    \n\n
      \n\t
    • \u6bd4\u65b9\u8bf4\uff0c\u53e5\u5b50\u00a0\"This is a sentence\"\u00a0\u53ef\u4ee5\u88ab\u6253\u4e71\u987a\u5e8f\u5f97\u5230\u00a0\"sentence4 a3 is2 This1\"\u00a0\u6216\u8005\u00a0\"is2 sentence4 This1 a3\"\u00a0\u3002
    • \n
    \n\n

    \u7ed9\u4f60\u4e00\u4e2a \u6253\u4e71\u987a\u5e8f\u00a0\u7684\u53e5\u5b50\u00a0s\u00a0\uff0c\u5b83\u5305\u542b\u7684\u5355\u8bcd\u4e0d\u8d85\u8fc7\u00a09\u00a0\u4e2a\uff0c\u8bf7\u4f60\u91cd\u65b0\u6784\u9020\u5e76\u5f97\u5230\u539f\u672c\u987a\u5e8f\u7684\u53e5\u5b50\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"is2 sentence4 This1 a3\"\n\u8f93\u51fa\uff1a\"This is a sentence\"\n\u89e3\u91ca\uff1a\u5c06 s \u4e2d\u7684\u5355\u8bcd\u6309\u7167\u521d\u59cb\u4f4d\u7f6e\u6392\u5e8f\uff0c\u5f97\u5230 \"This1 is2 a3 sentence4\" \uff0c\u7136\u540e\u5220\u9664\u6570\u5b57\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"Myself2 Me1 I4 and3\"\n\u8f93\u51fa\uff1a\"Me Myself and I\"\n\u89e3\u91ca\uff1a\u5c06 s \u4e2d\u7684\u5355\u8bcd\u6309\u7167\u521d\u59cb\u4f4d\u7f6e\u6392\u5e8f\uff0c\u5f97\u5230 \"Me1 Myself2 and3 I4\" \uff0c\u7136\u540e\u5220\u9664\u6570\u5b57\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= s.length <= 200
    • \n\t
    • s\u00a0\u53ea\u5305\u542b\u5c0f\u5199\u548c\u5927\u5199\u82f1\u6587\u5b57\u6bcd\u3001\u7a7a\u683c\u4ee5\u53ca\u4ece\u00a01\u00a0\u5230\u00a09\u00a0\u7684\u6570\u5b57\u3002
    • \n\t
    • s\u00a0\u4e2d\u5355\u8bcd\u6570\u76ee\u4e3a\u00a01\u00a0\u5230\u00a09\u00a0\u4e2a\u3002
    • \n\t
    • s\u00a0\u4e2d\u7684\u5355\u8bcd\u7531\u5355\u4e2a\u7a7a\u683c\u5206\u9694\u3002
    • \n\t
    • s\u00a0\u4e0d\u5305\u542b\u4efb\u4f55\u524d\u5bfc\u6216\u8005\u540e\u7f00\u7a7a\u683c\u3002
    • \n
    \n", "tags_en": ["Sort", "String"], "tags_cn": ["\u6392\u5e8f", "\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string sortSentence(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String sortSentence(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def sortSentence(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def sortSentence(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * sortSentence(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string SortSentence(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar sortSentence = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef sort_sentence(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func sortSentence(_ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func sortSentence(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def sortSentence(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun sortSentence(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sort_sentence(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function sortSentence($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function sortSentence(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (sort-sentence s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1859](https://leetcode-cn.com/problems/sorting-the-sentence)", "[\u5c06\u53e5\u5b50\u6392\u5e8f](/solution/1800-1899/1859.Sorting%20the%20Sentence/README.md)", "`\u6392\u5e8f`,`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1859](https://leetcode.com/problems/sorting-the-sentence)", "[Sorting the Sentence](/solution/1800-1899/1859.Sorting%20the%20Sentence/README_EN.md)", "`Sort`,`String`", "Easy", ""]}, {"question_id": "1969", "frontend_question_id": "1820", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/maximum-number-of-accepted-invitations", "url_en": "https://leetcode.com/problems/maximum-number-of-accepted-invitations", "relative_path_cn": "/solution/1800-1899/1820.Maximum%20Number%20of%20Accepted%20Invitations/README.md", "relative_path_en": "/solution/1800-1899/1820.Maximum%20Number%20of%20Accepted%20Invitations/README_EN.md", "title_cn": "", "title_en": "Maximum Number of Accepted Invitations", "question_title_slug": "maximum-number-of-accepted-invitations", "content_en": "

    There are m boys and n girls in a class attending an upcoming party.

    \n\n

    You are given an m x n integer matrix grid, where grid[i][j] equals 0 or 1. If grid[i][j] == 1, then that means the ith boy can invite the jth girl to the party. A boy can invite at most one girl, and a girl can accept at most one invitation from a boy.

    \n\n

    Return the maximum possible number of accepted invitations.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: grid = [[1,1,1],\n               [1,0,1],\n               [0,0,1]]\nOutput: 3\nExplanation: The invitations are sent as follows:\n- The 1st boy invites the 2nd girl.\n- The 2nd boy invites the 1st girl.\n- The 3rd boy invites the 3rd girl.
    \n\n

    Example 2:

    \n\n
    \nInput: grid = [[1,0,1,0],\n               [1,0,0,0],\n               [0,0,1,0],\n               [1,1,1,0]]\nOutput: 3\nExplanation: The invitations are sent as follows:\n-The 1st boy invites the 3rd girl.\n-The 2nd boy invites the 1st girl.\n-The 3rd boy invites no one.\n-The 4th boy invites the 2nd girl.
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • grid.length == m
    • \n\t
    • grid[i].length == n
    • \n\t
    • 1 <= m, n <= 200
    • \n\t
    • grid[i][j] is either 0 or 1.
    • \n
    \n", "content_cn": null, "tags_en": ["Graph"], "tags_cn": ["\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maximumInvitations(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maximumInvitations(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximumInvitations(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximumInvitations(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maximumInvitations(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaximumInvitations(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar maximumInvitations = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef maximum_invitations(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximumInvitations(_ grid: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximumInvitations(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximumInvitations(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximumInvitations(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximum_invitations(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function maximumInvitations($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximumInvitations(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximum-invitations grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1820](https://leetcode-cn.com/problems/maximum-number-of-accepted-invitations)", "[Maximum Number of Accepted Invitations](/solution/1800-1899/1820.Maximum%20Number%20of%20Accepted%20Invitations/README_EN.md)", "`\u56fe`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1820](https://leetcode.com/problems/maximum-number-of-accepted-invitations)", "[Maximum Number of Accepted Invitations](/solution/1800-1899/1820.Maximum%20Number%20of%20Accepted%20Invitations/README_EN.md)", "`Graph`", "Medium", "\ud83d\udd12"]}, {"question_id": "1968", "frontend_question_id": "1840", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-building-height", "url_en": "https://leetcode.com/problems/maximum-building-height", "relative_path_cn": "/solution/1800-1899/1840.Maximum%20Building%20Height/README.md", "relative_path_en": "/solution/1800-1899/1840.Maximum%20Building%20Height/README_EN.md", "title_cn": "\u6700\u9ad8\u5efa\u7b51\u9ad8\u5ea6", "title_en": "Maximum Building Height", "question_title_slug": "maximum-building-height", "content_en": "

    You want to build n new buildings in a city. The new buildings will be built in a line and are labeled from 1 to n.

    \n\n

    However, there are city restrictions on the heights of the new buildings:

    \n\n
      \n\t
    • The height of each building must be a non-negative integer.
    • \n\t
    • The height of the first building must be 0.
    • \n\t
    • The height difference between any two adjacent buildings cannot exceed 1.
    • \n
    \n\n

    Additionally, there are city restrictions on the maximum height of specific buildings. These restrictions are given as a 2D integer array restrictions where restrictions[i] = [idi, maxHeighti] indicates that building idi must have a height less than or equal to maxHeighti.

    \n\n

    It is guaranteed that each building will appear at most once in restrictions, and building 1 will not be in restrictions.

    \n\n

    Return the maximum possible height of the tallest building.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: n = 5, restrictions = [[2,1],[4,1]]\nOutput: 2\nExplanation: The green area in the image indicates the maximum allowed height for each building.\nWe can build the buildings with heights [0,1,2,1,2], and the tallest building has a height of 2.
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: n = 6, restrictions = []\nOutput: 5\nExplanation: The green area in the image indicates the maximum allowed height for each building.\nWe can build the buildings with heights [0,1,2,3,4,5], and the tallest building has a height of 5.\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: n = 10, restrictions = [[5,3],[2,5],[7,4],[10,3]]\nOutput: 5\nExplanation: The green area in the image indicates the maximum allowed height for each building.\nWe can build the buildings with heights [0,1,2,3,3,4,4,5,4,3], and the tallest building has a height of 5.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= n <= 109
    • \n\t
    • 0 <= restrictions.length <= min(n - 1, 105)
    • \n\t
    • 2 <= idi <= n
    • \n\t
    • idi is unique.
    • \n\t
    • 0 <= maxHeighti <= 109
    • \n
    \n", "content_cn": "

    \u5728\u4e00\u5ea7\u57ce\u5e02\u91cc\uff0c\u4f60\u9700\u8981\u5efa\u00a0n\u00a0\u680b\u65b0\u7684\u5efa\u7b51\u3002\u8fd9\u4e9b\u65b0\u7684\u5efa\u7b51\u4f1a\u4ece 1\u00a0\u5230 n\u00a0\u7f16\u53f7\u6392\u6210\u4e00\u5217\u3002

    \n\n

    \u8fd9\u5ea7\u57ce\u5e02\u5bf9\u8fd9\u4e9b\u65b0\u5efa\u7b51\u6709\u4e00\u4e9b\u89c4\u5b9a\uff1a

    \n\n
      \n\t
    • \u6bcf\u680b\u5efa\u7b51\u7684\u9ad8\u5ea6\u5fc5\u987b\u662f\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\u3002
    • \n\t
    • \u7b2c\u4e00\u680b\u5efa\u7b51\u7684\u9ad8\u5ea6 \u5fc5\u987b\u00a0\u662f\u00a00\u00a0\u3002
    • \n\t
    • \u4efb\u610f\u4e24\u680b\u76f8\u90bb\u5efa\u7b51\u7684\u9ad8\u5ea6\u5dee \u4e0d\u80fd\u8d85\u8fc7\u00a0\u00a01\u00a0\u3002
    • \n
    \n\n

    \u9664\u6b64\u4ee5\u5916\uff0c\u67d0\u4e9b\u5efa\u7b51\u8fd8\u6709\u989d\u5916\u7684\u6700\u9ad8\u9ad8\u5ea6\u9650\u5236\u3002\u8fd9\u4e9b\u9650\u5236\u4f1a\u4ee5\u4e8c\u7ef4\u6574\u6570\u6570\u7ec4\u00a0restrictions\u00a0\u7684\u5f62\u5f0f\u7ed9\u51fa\uff0c\u5176\u4e2d\u00a0restrictions[i] = [idi, maxHeighti]\u00a0\uff0c\u8868\u793a\u5efa\u7b51\u00a0idi\u00a0\u7684\u9ad8\u5ea6 \u4e0d\u80fd\u8d85\u8fc7\u00a0maxHeighti\u00a0\u3002

    \n\n

    \u9898\u76ee\u4fdd\u8bc1\u6bcf\u680b\u5efa\u7b51\u5728 restrictions\u00a0\u4e2d\u00a0\u81f3\u591a\u51fa\u73b0\u4e00\u6b21\u00a0\uff0c\u540c\u65f6\u5efa\u7b51 1\u00a0\u4e0d\u4f1a\u00a0\u51fa\u73b0\u5728\u00a0restrictions\u00a0\u4e2d\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de \u6700\u9ad8\u00a0\u5efa\u7b51\u80fd\u8fbe\u5230\u7684 \u6700\u9ad8\u9ad8\u5ea6\u00a0\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1an = 5, restrictions = [[2,1],[4,1]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u4e0a\u56fe\u4e2d\u7684\u7eff\u8272\u533a\u57df\u4e3a\u6bcf\u680b\u5efa\u7b51\u88ab\u5141\u8bb8\u7684\u6700\u9ad8\u9ad8\u5ea6\u3002\n\u6211\u4eec\u53ef\u4ee5\u4f7f\u5efa\u7b51\u9ad8\u5ea6\u5206\u522b\u4e3a [0,1,2,1,2] \uff0c\u6700\u9ad8\u5efa\u7b51\u7684\u9ad8\u5ea6\u4e3a 2 \u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1an = 6, restrictions = []\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u4e0a\u56fe\u4e2d\u7684\u7eff\u8272\u533a\u57df\u4e3a\u6bcf\u680b\u5efa\u7b51\u88ab\u5141\u8bb8\u7684\u6700\u9ad8\u9ad8\u5ea6\u3002\n\u6211\u4eec\u53ef\u4ee5\u4f7f\u5efa\u7b51\u9ad8\u5ea6\u5206\u522b\u4e3a [0,1,2,3,4,5] \uff0c\u6700\u9ad8\u5efa\u7b51\u7684\u9ad8\u5ea6\u4e3a 5 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1an = 10, restrictions = [[5,3],[2,5],[7,4],[10,3]]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u4e0a\u56fe\u4e2d\u7684\u7eff\u8272\u533a\u57df\u4e3a\u6bcf\u680b\u5efa\u7b51\u88ab\u5141\u8bb8\u7684\u6700\u9ad8\u9ad8\u5ea6\u3002\n\u6211\u4eec\u53ef\u4ee5\u4f7f\u5efa\u7b51\u9ad8\u5ea6\u5206\u522b\u4e3a [0,1,2,3,3,4,4,5,4,3] \uff0c\u6700\u9ad8\u5efa\u7b51\u7684\u9ad8\u5ea6\u4e3a 5 \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= n <= 109
    • \n\t
    • 0 <= restrictions.length <= min(n - 1, 105)
    • \n\t
    • 2 <= idi <= n
    • \n\t
    • idi\u00a0\u662f \u552f\u4e00\u7684\u00a0\u3002
    • \n\t
    • 0 <= maxHeighti <= 109
    • \n
    \n", "tags_en": ["Greedy", "Binary Search"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxBuilding(int n, vector>& restrictions) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxBuilding(int n, int[][] restrictions) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxBuilding(self, n, restrictions):\n \"\"\"\n :type n: int\n :type restrictions: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxBuilding(self, n: int, restrictions: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxBuilding(int n, int** restrictions, int restrictionsSize, int* restrictionsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxBuilding(int n, int[][] restrictions) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} restrictions\n * @return {number}\n */\nvar maxBuilding = function(n, restrictions) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} restrictions\n# @return {Integer}\ndef max_building(n, restrictions)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxBuilding(_ n: Int, _ restrictions: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxBuilding(n int, restrictions [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxBuilding(n: Int, restrictions: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxBuilding(n: Int, restrictions: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_building(n: i32, restrictions: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $restrictions\n * @return Integer\n */\n function maxBuilding($n, $restrictions) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxBuilding(n: number, restrictions: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-building n restrictions)\n (-> exact-integer? (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1840](https://leetcode-cn.com/problems/maximum-building-height)", "[\u6700\u9ad8\u5efa\u7b51\u9ad8\u5ea6](/solution/1800-1899/1840.Maximum%20Building%20Height/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u4e8c\u5206\u67e5\u627e`", "\u56f0\u96be", ""], "md_table_row_en": ["[1840](https://leetcode.com/problems/maximum-building-height)", "[Maximum Building Height](/solution/1800-1899/1840.Maximum%20Building%20Height/README_EN.md)", "`Greedy`,`Binary Search`", "Hard", ""]}, {"question_id": "1967", "frontend_question_id": "1839", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-substring-of-all-vowels-in-order", "url_en": "https://leetcode.com/problems/longest-substring-of-all-vowels-in-order", "relative_path_cn": "/solution/1800-1899/1839.Longest%20Substring%20Of%20All%20Vowels%20in%20Order/README.md", "relative_path_en": "/solution/1800-1899/1839.Longest%20Substring%20Of%20All%20Vowels%20in%20Order/README_EN.md", "title_cn": "\u6240\u6709\u5143\u97f3\u6309\u987a\u5e8f\u6392\u5e03\u7684\u6700\u957f\u5b50\u5b57\u7b26\u4e32", "title_en": "Longest Substring Of All Vowels in Order", "question_title_slug": "longest-substring-of-all-vowels-in-order", "content_en": "

    A string is considered beautiful if it satisfies the following conditions:

    \n\n
      \n\t
    • Each of the 5 English vowels ('a', 'e', 'i', 'o', 'u') must appear at least once in it.
    • \n\t
    • The letters must be sorted in alphabetical order (i.e. all 'a's before 'e's, all 'e's before 'i's, etc.).
    • \n
    \n\n

    For example, strings "aeiou" and "aaaaaaeiiiioou" are considered beautiful, but "uaeio", "aeoiu", and "aaaeeeooo" are not beautiful.

    \n\n

    Given a string word consisting of English vowels, return the length of the longest beautiful substring of word. If no such substring exists, return 0.

    \n\n

    A substring is a contiguous sequence of characters in a string.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: word = "aeiaaioaaaaeiiiiouuuooaauuaeiu"\nOutput: 13\nExplanation: The longest beautiful substring in word is "aaaaeiiiiouuu" of length 13.
    \n\n

    Example 2:

    \n\n
    \nInput: word = "aeeeiiiioooauuuaeiou"\nOutput: 5\nExplanation: The longest beautiful substring in word is "aeiou" of length 5.\n
    \n\n

    Example 3:

    \n\n
    \nInput: word = "a"\nOutput: 0\nExplanation: There is no beautiful substring, so return 0.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= word.length <= 5 * 105
    • \n\t
    • word consists of characters 'a', 'e', 'i', 'o', and 'u'.
    • \n
    \n", "content_cn": "

    \u5f53\u4e00\u4e2a\u5b57\u7b26\u4e32\u6ee1\u8db3\u5982\u4e0b\u6761\u4ef6\u65f6\uff0c\u6211\u4eec\u79f0\u5b83\u662f \u7f8e\u4e3d\u7684\u00a0\uff1a

    \n\n
      \n\t
    • \u6240\u6709 5 \u4e2a\u82f1\u6587\u5143\u97f3\u5b57\u6bcd\uff08'a'\u00a0\uff0c'e'\u00a0\uff0c'i'\u00a0\uff0c'o'\u00a0\uff0c'u'\uff09\u90fd\u5fc5\u987b\u00a0\u81f3\u5c11\u00a0\u51fa\u73b0\u4e00\u6b21\u3002
    • \n\t
    • \u8fd9\u4e9b\u5143\u97f3\u5b57\u6bcd\u7684\u987a\u5e8f\u90fd\u5fc5\u987b\u6309\u7167 \u5b57\u5178\u5e8f\u00a0\u5347\u5e8f\u6392\u5e03\uff08\u4e5f\u5c31\u662f\u8bf4\u6240\u6709\u7684 'a'\u00a0\u90fd\u5728 'e'\u00a0\u524d\u9762\uff0c\u6240\u6709\u7684 'e'\u00a0\u90fd\u5728 'i'\u00a0\u524d\u9762\uff0c\u4ee5\u6b64\u7c7b\u63a8\uff09
    • \n
    \n\n

    \u6bd4\u65b9\u8bf4\uff0c\u5b57\u7b26\u4e32\u00a0\"aeiou\" \u548c\u00a0\"aaaaaaeiiiioou\"\u00a0\u90fd\u662f \u7f8e\u4e3d\u7684\u00a0\uff0c\u4f46\u662f\u00a0\"uaeio\"\u00a0\uff0c\"aeoiu\"\u00a0\u548c\u00a0\"aaaeeeooo\"\u00a0\u4e0d\u662f\u7f8e\u4e3d\u7684\u00a0\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u53ea\u5305\u542b\u82f1\u6587\u5143\u97f3\u5b57\u6bcd\u7684\u5b57\u7b26\u4e32\u00a0word\u00a0\uff0c\u8bf7\u4f60\u8fd4\u56de\u00a0word \u4e2d \u6700\u957f\u7f8e\u4e3d\u5b50\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u00a0\u3002\u5982\u679c\u4e0d\u5b58\u5728\u8fd9\u6837\u7684\u5b50\u5b57\u7b26\u4e32\uff0c\u8bf7\u8fd4\u56de 0\u00a0\u3002

    \n\n

    \u5b50\u5b57\u7b26\u4e32 \u662f\u5b57\u7b26\u4e32\u4e2d\u4e00\u4e2a\u8fde\u7eed\u7684\u5b57\u7b26\u5e8f\u5217\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aword = \"aeiaaioaaaaeiiiiouuuooaauuaeiu\"\n\u8f93\u51fa\uff1a13\n\u89e3\u91ca\uff1a\u6700\u957f\u5b50\u5b57\u7b26\u4e32\u662f \"aaaaeiiiiouuu\" \uff0c\u957f\u5ea6\u4e3a 13 \u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aword = \"aeeeiiiioooauuuaeiou\"\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u6700\u957f\u5b50\u5b57\u7b26\u4e32\u662f \"aeiou\" \uff0c\u957f\u5ea6\u4e3a 5 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aword = \"a\"\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6ca1\u6709\u7f8e\u4e3d\u5b50\u5b57\u7b26\u4e32\uff0c\u6240\u4ee5\u8fd4\u56de 0 \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= word.length <= 5 * 105
    • \n\t
    • word\u00a0\u53ea\u5305\u542b\u5b57\u7b26\u00a0'a'\uff0c'e'\uff0c'i'\uff0c'o'\u00a0\u548c\u00a0'u'\u00a0\u3002
    • \n
    \n", "tags_en": ["Two Pointers", "String"], "tags_cn": ["\u53cc\u6307\u9488", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int longestBeautifulSubstring(string word) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int longestBeautifulSubstring(String word) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestBeautifulSubstring(self, word):\n \"\"\"\n :type word: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestBeautifulSubstring(self, word: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint longestBeautifulSubstring(char * word){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LongestBeautifulSubstring(string word) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} word\n * @return {number}\n */\nvar longestBeautifulSubstring = function(word) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} word\n# @return {Integer}\ndef longest_beautiful_substring(word)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestBeautifulSubstring(_ word: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestBeautifulSubstring(word string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestBeautifulSubstring(word: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestBeautifulSubstring(word: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_beautiful_substring(word: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $word\n * @return Integer\n */\n function longestBeautifulSubstring($word) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestBeautifulSubstring(word: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-beautiful-substring word)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1839](https://leetcode-cn.com/problems/longest-substring-of-all-vowels-in-order)", "[\u6240\u6709\u5143\u97f3\u6309\u987a\u5e8f\u6392\u5e03\u7684\u6700\u957f\u5b50\u5b57\u7b26\u4e32](/solution/1800-1899/1839.Longest%20Substring%20Of%20All%20Vowels%20in%20Order/README.md)", "`\u53cc\u6307\u9488`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1839](https://leetcode.com/problems/longest-substring-of-all-vowels-in-order)", "[Longest Substring Of All Vowels in Order](/solution/1800-1899/1839.Longest%20Substring%20Of%20All%20Vowels%20in%20Order/README_EN.md)", "`Two Pointers`,`String`", "Medium", ""]}, {"question_id": "1966", "frontend_question_id": "1838", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/frequency-of-the-most-frequent-element", "url_en": "https://leetcode.com/problems/frequency-of-the-most-frequent-element", "relative_path_cn": "/solution/1800-1899/1838.Frequency%20of%20the%20Most%20Frequent%20Element/README.md", "relative_path_en": "/solution/1800-1899/1838.Frequency%20of%20the%20Most%20Frequent%20Element/README_EN.md", "title_cn": "\u6700\u9ad8\u9891\u5143\u7d20\u7684\u9891\u6570", "title_en": "Frequency of the Most Frequent Element", "question_title_slug": "frequency-of-the-most-frequent-element", "content_en": "

    The frequency of an element is the number of times it occurs in an array.

    \n\n

    You are given an integer array nums and an integer k. In one operation, you can choose an index of nums and increment the element at that index by 1.

    \n\n

    Return the maximum possible frequency of an element after performing at most k operations.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,4], k = 5\nOutput: 3\nExplanation: Increment the first element three times and the second element two times to make nums = [4,4,4].\n4 has a frequency of 3.
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,4,8,13], k = 5\nOutput: 2\nExplanation: There are multiple optimal solutions:\n- Increment the first element three times to make nums = [4,4,8,13]. 4 has a frequency of 2.\n- Increment the second element four times to make nums = [1,8,8,13]. 8 has a frequency of 2.\n- Increment the third element five times to make nums = [1,4,13,13]. 13 has a frequency of 2.\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [3,9,6], k = 2\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • 1 <= nums[i] <= 105
    • \n\t
    • 1 <= k <= 105
    • \n
    \n", "content_cn": "

    \u5143\u7d20\u7684 \u9891\u6570 \u662f\u8be5\u5143\u7d20\u5728\u4e00\u4e2a\u6570\u7ec4\u4e2d\u51fa\u73b0\u7684\u6b21\u6570\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \u548c\u4e00\u4e2a\u6574\u6570 k \u3002\u5728\u4e00\u6b65\u64cd\u4f5c\u4e2d\uff0c\u4f60\u53ef\u4ee5\u9009\u62e9 nums \u7684\u4e00\u4e2a\u4e0b\u6807\uff0c\u5e76\u5c06\u8be5\u4e0b\u6807\u5bf9\u5e94\u5143\u7d20\u7684\u503c\u589e\u52a0 1 \u3002

    \n\n

    \u6267\u884c\u6700\u591a k \u6b21\u64cd\u4f5c\u540e\uff0c\u8fd4\u56de\u6570\u7ec4\u4e2d\u6700\u9ad8\u9891\u5143\u7d20\u7684 \u6700\u5927\u53ef\u80fd\u9891\u6570 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,4], k = 5\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u5bf9\u7b2c\u4e00\u4e2a\u5143\u7d20\u6267\u884c 3 \u6b21\u9012\u589e\u64cd\u4f5c\uff0c\u5bf9\u7b2c\u4e8c\u4e2a\u5143\u7d20\u6267 2 \u6b21\u9012\u589e\u64cd\u4f5c\uff0c\u6b64\u65f6 nums = [4,4,4] \u3002\n4 \u662f\u6570\u7ec4\u4e2d\u6700\u9ad8\u9891\u5143\u7d20\uff0c\u9891\u6570\u662f 3 \u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,4,8,13], k = 5\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5b58\u5728\u591a\u79cd\u6700\u4f18\u89e3\u51b3\u65b9\u6848\uff1a\n- \u5bf9\u7b2c\u4e00\u4e2a\u5143\u7d20\u6267\u884c 3 \u6b21\u9012\u589e\u64cd\u4f5c\uff0c\u6b64\u65f6 nums = [4,4,8,13] \u30024 \u662f\u6570\u7ec4\u4e2d\u6700\u9ad8\u9891\u5143\u7d20\uff0c\u9891\u6570\u662f 2 \u3002\n- \u5bf9\u7b2c\u4e8c\u4e2a\u5143\u7d20\u6267\u884c 4 \u6b21\u9012\u589e\u64cd\u4f5c\uff0c\u6b64\u65f6 nums = [1,8,8,13] \u30028 \u662f\u6570\u7ec4\u4e2d\u6700\u9ad8\u9891\u5143\u7d20\uff0c\u9891\u6570\u662f 2 \u3002\n- \u5bf9\u7b2c\u4e09\u4e2a\u5143\u7d20\u6267\u884c 5 \u6b21\u9012\u589e\u64cd\u4f5c\uff0c\u6b64\u65f6 nums = [1,4,13,13] \u300213 \u662f\u6570\u7ec4\u4e2d\u6700\u9ad8\u9891\u5143\u7d20\uff0c\u9891\u6570\u662f 2 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [3,9,6], k = 2\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • 1 <= nums[i] <= 105
    • \n\t
    • 1 <= k <= 105
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxFrequency(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxFrequency(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxFrequency(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxFrequency(self, nums: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxFrequency(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxFrequency(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar maxFrequency = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef max_frequency(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxFrequency(_ nums: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxFrequency(nums []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxFrequency(nums: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxFrequency(nums: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_frequency(nums: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer\n */\n function maxFrequency($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxFrequency(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-frequency nums k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1838](https://leetcode-cn.com/problems/frequency-of-the-most-frequent-element)", "[\u6700\u9ad8\u9891\u5143\u7d20\u7684\u9891\u6570](/solution/1800-1899/1838.Frequency%20of%20the%20Most%20Frequent%20Element/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1838](https://leetcode.com/problems/frequency-of-the-most-frequent-element)", "[Frequency of the Most Frequent Element](/solution/1800-1899/1838.Frequency%20of%20the%20Most%20Frequent%20Element/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1965", "frontend_question_id": "1837", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sum-of-digits-in-base-k", "url_en": "https://leetcode.com/problems/sum-of-digits-in-base-k", "relative_path_cn": "/solution/1800-1899/1837.Sum%20of%20Digits%20in%20Base%20K/README.md", "relative_path_en": "/solution/1800-1899/1837.Sum%20of%20Digits%20in%20Base%20K/README_EN.md", "title_cn": "K \u8fdb\u5236\u8868\u793a\u4e0b\u7684\u5404\u4f4d\u6570\u5b57\u603b\u548c", "title_en": "Sum of Digits in Base K", "question_title_slug": "sum-of-digits-in-base-k", "content_en": "

    Given an integer n (in base 10) and a base k, return the sum of the digits of n after converting n from base 10 to base k.

    \n\n

    After converting, each digit should be interpreted as a base 10 number, and the sum should be returned in base 10.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 34, k = 6\nOutput: 9\nExplanation: 34 (base 10) expressed in base 6 is 54. 5 + 4 = 9.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 10, k = 10\nOutput: 1\nExplanation: n is already in base 10. 1 + 0 = 1.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 100
    • \n\t
    • 2 <= k <= 10
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n\uff0810 \u8fdb\u5236\uff09\u548c\u4e00\u4e2a\u57fa\u6570 k \uff0c\u8bf7\u4f60\u5c06 n \u4ece 10 \u8fdb\u5236\u8868\u793a\u8f6c\u6362\u4e3a k \u8fdb\u5236\u8868\u793a\uff0c\u8ba1\u7b97\u5e76\u8fd4\u56de\u8f6c\u6362\u540e\u5404\u4f4d\u6570\u5b57\u7684 \u603b\u548c \u3002

    \n\n

    \u8f6c\u6362\u540e\uff0c\u5404\u4f4d\u6570\u5b57\u5e94\u5f53\u89c6\u4f5c\u662f 10 \u8fdb\u5236\u6570\u5b57\uff0c\u4e14\u5b83\u4eec\u7684\u603b\u548c\u4e5f\u5e94\u5f53\u6309 10 \u8fdb\u5236\u8868\u793a\u8fd4\u56de\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 34, k = 6\n\u8f93\u51fa\uff1a9\n\u89e3\u91ca\uff1a34 (10 \u8fdb\u5236) \u5728 6 \u8fdb\u5236\u4e0b\u8868\u793a\u4e3a 54 \u30025 + 4 = 9 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 10, k = 10\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1an \u672c\u8eab\u5c31\u662f 10 \u8fdb\u5236\u3002 1 + 0 = 1 \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 100
    • \n\t
    • 2 <= k <= 10
    • \n
    \n", "tags_en": ["Bit Manipulation", "Math"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int sumBase(int n, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int sumBase(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def sumBase(self, n, k):\n \"\"\"\n :type n: int\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def sumBase(self, n: int, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint sumBase(int n, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SumBase(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} k\n * @return {number}\n */\nvar sumBase = function(n, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} k\n# @return {Integer}\ndef sum_base(n, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func sumBase(_ n: Int, _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func sumBase(n int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def sumBase(n: Int, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun sumBase(n: Int, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sum_base(n: i32, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $k\n * @return Integer\n */\n function sumBase($n, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function sumBase(n: number, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (sum-base n k)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1837](https://leetcode-cn.com/problems/sum-of-digits-in-base-k)", "[K \u8fdb\u5236\u8868\u793a\u4e0b\u7684\u5404\u4f4d\u6570\u5b57\u603b\u548c](/solution/1800-1899/1837.Sum%20of%20Digits%20in%20Base%20K/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[1837](https://leetcode.com/problems/sum-of-digits-in-base-k)", "[Sum of Digits in Base K](/solution/1800-1899/1837.Sum%20of%20Digits%20in%20Base%20K/README_EN.md)", "`Bit Manipulation`,`Math`", "Easy", ""]}, {"question_id": "1964", "frontend_question_id": "1811", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/find-interview-candidates", "url_en": "https://leetcode.com/problems/find-interview-candidates", "relative_path_cn": "/solution/1800-1899/1811.Find%20Interview%20Candidates/README.md", "relative_path_en": "/solution/1800-1899/1811.Find%20Interview%20Candidates/README_EN.md", "title_cn": "", "title_en": "Find Interview Candidates", "question_title_slug": "find-interview-candidates", "content_en": "

    Table: Contests

    \n\n
    \n+--------------+------+\n| Column Name  | Type |\n+--------------+------+\n| contest_id   | int  |\n| gold_medal   | int  |\n| silver_medal | int  |\n| bronze_medal | int  |\n+--------------+------+\ncontest_id is the primary key for this table.\nThis table contains the LeetCode contest ID and the user IDs of the gold, silver, and bronze medalists.\nIt is guaranteed that any consecutive contests have consecutive IDs and that no ID is skipped.
    \n\n

     

    \n\n

    Table: Users

    \n\n
    \n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| user_id     | int     |\n| mail        | varchar |\n| name        | varchar |\n+-------------+---------+\nuser_id is the primary key for this table.\nThis table contains information about the users.\n
    \n\n

     

    \n\n

    Write an SQL query to report the name and the mail of all interview candidates. A user is an interview candidate if at least one of these two conditions is true:

    \n\n
      \n\t
    • The user won any medal in three or more consecutive contests.
    • \n\t
    • The user won the gold medal in three or more different contests (not necessarily consecutive).
    • \n
    \n\n

    Return the result table in any order.

    \n\n

    The query result format is in the following example:

    \n\n

     

    \n\n
    \nContests table:\n+------------+------------+--------------+--------------+\n| contest_id | gold_medal | silver_medal | bronze_medal |\n+------------+------------+--------------+--------------+\n| 190        | 1          | 5            | 2            |\n| 191        | 2          | 3            | 5            |\n| 192        | 5          | 2            | 3            |\n| 193        | 1          | 3            | 5            |\n| 194        | 4          | 5            | 2            |\n| 195        | 4          | 2            | 1            |\n| 196        | 1          | 5            | 2            |\n+------------+------------+--------------+--------------+\n\nUsers table:\n+---------+--------------------+-------+\n| user_id | mail               | name  |\n+---------+--------------------+-------+\n| 1       | sarah@leetcode.com | Sarah |\n| 2       | bob@leetcode.com   | Bob   |\n| 3       | alice@leetcode.com | Alice |\n| 4       | hercy@leetcode.com | Hercy |\n| 5       | quarz@leetcode.com | Quarz |\n+---------+--------------------+-------+\n\nResult table:\n+-------+--------------------+\n| name  | mail               |\n+-------+--------------------+\n| Sarah | sarah@leetcode.com |\n| Bob   | bob@leetcode.com   |\n| Alice | alice@leetcode.com |\n| Quarz | quarz@leetcode.com |\n+-------+--------------------+\n\nSarah won 3 gold medals (190, 193, and 196), so we include her in the result table.\nBob won a medal in 3 consecutive contests (190, 191, and 192), so we include him in the result table.\n    - Note that he also won a medal in 3 other consecutive contests (194, 195, and 196).\nAlice won a medal in 3 consecutive contests (191, 192, and 193), so we include her in the result table.\nQuarz won a medal in 5 consecutive contests (190, 191, 192, 193, and 194), so we include them in the result table.\n
    \n\n

     

    \n

    Follow up:

    \n\n
      \n\t
    • What if the first condition changed to be "any medal in n or more consecutive contests"? How would you change your solution to get the interview candidates? Imagine that n is the parameter of a stored procedure.
    • \n\t
    • Some users may not participate in every contest but still perform well in the ones they do. How would you change your solution to only consider contests where the user was a participant? Suppose the registered users for each contest are given in another table.
    • \n
    \n", "content_cn": null, "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1811](https://leetcode-cn.com/problems/find-interview-candidates)", "[Find Interview Candidates](/solution/1800-1899/1811.Find%20Interview%20Candidates/README_EN.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1811](https://leetcode.com/problems/find-interview-candidates)", "[Find Interview Candidates](/solution/1800-1899/1811.Find%20Interview%20Candidates/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1963", "frontend_question_id": "1835", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-xor-sum-of-all-pairs-bitwise-and", "url_en": "https://leetcode.com/problems/find-xor-sum-of-all-pairs-bitwise-and", "relative_path_cn": "/solution/1800-1899/1835.Find%20XOR%20Sum%20of%20All%20Pairs%20Bitwise%20AND/README.md", "relative_path_en": "/solution/1800-1899/1835.Find%20XOR%20Sum%20of%20All%20Pairs%20Bitwise%20AND/README_EN.md", "title_cn": "\u6240\u6709\u6570\u5bf9\u6309\u4f4d\u4e0e\u7ed3\u679c\u7684\u5f02\u6216\u548c", "title_en": "Find XOR Sum of All Pairs Bitwise AND", "question_title_slug": "find-xor-sum-of-all-pairs-bitwise-and", "content_en": "

    The XOR sum of a list is the bitwise XOR of all its elements. If the list only contains one element, then its XOR sum will be equal to this element.

    \n\n
      \n\t
    • For example, the XOR sum of [1,2,3,4] is equal to 1 XOR 2 XOR 3 XOR 4 = 4, and the XOR sum of [3] is equal to 3.
    • \n
    \n\n

    You are given two 0-indexed arrays arr1 and arr2 that consist only of non-negative integers.

    \n\n

    Consider the list containing the result of arr1[i] AND arr2[j] (bitwise AND) for every (i, j) pair where 0 <= i < arr1.length and 0 <= j < arr2.length.

    \n\n

    Return the XOR sum of the aforementioned list.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr1 = [1,2,3], arr2 = [6,5]\nOutput: 0\nExplanation: The list = [1 AND 6, 1 AND 5, 2 AND 6, 2 AND 5, 3 AND 6, 3 AND 5] = [0,1,2,0,2,1].\nThe XOR sum = 0 XOR 1 XOR 2 XOR 0 XOR 2 XOR 1 = 0.\n
    \n\n

    Example 2:

    \n\n
    \nInput: arr1 = [12], arr2 = [4]\nOutput: 4\nExplanation: The list = [12 AND 4] = [4]. The XOR sum = 4.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= arr1.length, arr2.length <= 105
    • \n\t
    • 0 <= arr1[i], arr2[j] <= 109
    • \n
    \n", "content_cn": "

    \u5217\u8868\u7684 \u5f02\u6216\u548c\uff08XOR sum\uff09\u6307\u5bf9\u6240\u6709\u5143\u7d20\u8fdb\u884c\u6309\u4f4d XOR \u8fd0\u7b97\u7684\u7ed3\u679c\u3002\u5982\u679c\u5217\u8868\u4e2d\u4ec5\u6709\u4e00\u4e2a\u5143\u7d20\uff0c\u90a3\u4e48\u5176 \u5f02\u6216\u548c \u5c31\u7b49\u4e8e\u8be5\u5143\u7d20\u3002

    \n\n
      \n\t
    • \u4f8b\u5982\uff0c[1,2,3,4] \u7684 \u5f02\u6216\u548c \u7b49\u4e8e 1 XOR 2 XOR 3 XOR 4 = 4 \uff0c\u800c [3] \u7684 \u5f02\u6216\u548c \u7b49\u4e8e 3 \u3002
    • \n
    \n\n

    \u7ed9\u4f60\u4e24\u4e2a\u4e0b\u6807 \u4ece 0 \u5f00\u59cb \u8ba1\u6570\u7684\u6570\u7ec4 arr1 \u548c arr2 \uff0c\u4e24\u6570\u7ec4\u5747\u7531\u975e\u8d1f\u6574\u6570\u7ec4\u6210\u3002

    \n\n

    \u6839\u636e\u6bcf\u4e2a\u00a0(i, j) \u6570\u5bf9\uff0c\u6784\u9020\u4e00\u4e2a\u7531 arr1[i] AND arr2[j]\uff08\u6309\u4f4d AND \u8fd0\u7b97\uff09\u7ed3\u679c\u7ec4\u6210\u7684\u5217\u8868\u3002\u5176\u4e2d 0 <= i < arr1.length \u4e14 0 <= j < arr2.length \u3002

    \n\n

    \u8fd4\u56de\u4e0a\u8ff0\u5217\u8868\u7684 \u5f02\u6216\u548c \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aarr1 = [1,2,3], arr2 = [6,5]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u5217\u8868 = [1 AND 6, 1 AND 5, 2 AND 6, 2 AND 5, 3 AND 6, 3 AND 5] = [0,1,2,0,2,1] \uff0c\n\u5f02\u6216\u548c = 0 XOR 1 XOR 2 XOR 0 XOR 2 XOR 1 = 0 \u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aarr1 = [12], arr2 = [4]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u5217\u8868 = [12 AND 4] = [4] \uff0c\u5f02\u6216\u548c = 4 \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= arr1.length, arr2.length <= 105
    • \n\t
    • 0 <= arr1[i], arr2[j] <= 109
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int getXORSum(vector& arr1, vector& arr2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int getXORSum(int[] arr1, int[] arr2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getXORSum(self, arr1, arr2):\n \"\"\"\n :type arr1: List[int]\n :type arr2: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getXORSum(self, arr1: List[int], arr2: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint getXORSum(int* arr1, int arr1Size, int* arr2, int arr2Size){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int GetXORSum(int[] arr1, int[] arr2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr1\n * @param {number[]} arr2\n * @return {number}\n */\nvar getXORSum = function(arr1, arr2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr1\n# @param {Integer[]} arr2\n# @return {Integer}\ndef get_xor_sum(arr1, arr2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getXORSum(_ arr1: [Int], _ arr2: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getXORSum(arr1 []int, arr2 []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getXORSum(arr1: Array[Int], arr2: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getXORSum(arr1: IntArray, arr2: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_xor_sum(arr1: Vec, arr2: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr1\n * @param Integer[] $arr2\n * @return Integer\n */\n function getXORSum($arr1, $arr2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getXORSum(arr1: number[], arr2: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-xor-sum arr1 arr2)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1835](https://leetcode-cn.com/problems/find-xor-sum-of-all-pairs-bitwise-and)", "[\u6240\u6709\u6570\u5bf9\u6309\u4f4d\u4e0e\u7ed3\u679c\u7684\u5f02\u6216\u548c](/solution/1800-1899/1835.Find%20XOR%20Sum%20of%20All%20Pairs%20Bitwise%20AND/README.md)", "`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[1835](https://leetcode.com/problems/find-xor-sum-of-all-pairs-bitwise-and)", "[Find XOR Sum of All Pairs Bitwise AND](/solution/1800-1899/1835.Find%20XOR%20Sum%20of%20All%20Pairs%20Bitwise%20AND/README_EN.md)", "`Math`", "Hard", ""]}, {"question_id": "1962", "frontend_question_id": "1834", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/single-threaded-cpu", "url_en": "https://leetcode.com/problems/single-threaded-cpu", "relative_path_cn": "/solution/1800-1899/1834.Single-Threaded%20CPU/README.md", "relative_path_en": "/solution/1800-1899/1834.Single-Threaded%20CPU/README_EN.md", "title_cn": "\u5355\u7ebf\u7a0b CPU", "title_en": "Single-Threaded CPU", "question_title_slug": "single-threaded-cpu", "content_en": "

    You are given n\u200b\u200b\u200b\u200b\u200b\u200b tasks labeled from 0 to n - 1 represented by a 2D integer array tasks, where tasks[i] = [enqueueTimei, processingTimei] means that the i\u200b\u200b\u200b\u200b\u200b\u200bth\u200b\u200b\u200b\u200b task will be available to process at enqueueTimei and will take processingTimei to finish processing.

    \n\n

    You have a single-threaded CPU that can process at most one task at a time and will act in the following way:

    \n\n
      \n\t
    • If the CPU is idle and there are no available tasks to process, the CPU remains idle.
    • \n\t
    • If the CPU is idle and there are available tasks, the CPU will choose the one with the shortest processing time. If multiple tasks have the same shortest processing time, it will choose the task with the smallest index.
    • \n\t
    • Once a task is started, the CPU will process the entire task without stopping.
    • \n\t
    • The CPU can finish a task then start a new one instantly.
    • \n
    \n\n

    Return the order in which the CPU will process the tasks.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: tasks = [[1,2],[2,4],[3,2],[4,1]]\nOutput: [0,2,3,1]\nExplanation: The events go as follows: \n- At time = 1, task 0 is available to process. Available tasks = {0}.\n- Also at time = 1, the idle CPU starts processing task 0. Available tasks = {}.\n- At time = 2, task 1 is available to process. Available tasks = {1}.\n- At time = 3, task 2 is available to process. Available tasks = {1, 2}.\n- Also at time = 3, the CPU finishes task 0 and starts processing task 2 as it is the shortest. Available tasks = {1}.\n- At time = 4, task 3 is available to process. Available tasks = {1, 3}.\n- At time = 5, the CPU finishes task 2 and starts processing task 3 as it is the shortest. Available tasks = {1}.\n- At time = 6, the CPU finishes task 3 and starts processing task 1. Available tasks = {}.\n- At time = 10, the CPU finishes task 1 and becomes idle.\n
    \n\n

    Example 2:

    \n\n
    \nInput: tasks = [[7,10],[7,12],[7,5],[7,4],[7,2]]\nOutput: [4,3,2,0,1]\nExplanation: The events go as follows:\n- At time = 7, all the tasks become available. Available tasks = {0,1,2,3,4}.\n- Also at time = 7, the idle CPU starts processing task 4. Available tasks = {0,1,2,3}.\n- At time = 9, the CPU finishes task 4 and starts processing task 3. Available tasks = {0,1,2}.\n- At time = 13, the CPU finishes task 3 and starts processing task 2. Available tasks = {0,1}.\n- At time = 18, the CPU finishes task 2 and starts processing task 0. Available tasks = {1}.\n- At time = 28, the CPU finishes task 0 and starts processing task 1. Available tasks = {}.\n- At time = 40, the CPU finishes task 1 and becomes idle.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • tasks.length == n
    • \n\t
    • 1 <= n <= 105
    • \n\t
    • 1 <= enqueueTimei, processingTimei <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u4e8c\u7ef4\u6570\u7ec4 tasks \uff0c\u7528\u4e8e\u8868\u793a n\u200b\u200b\u200b\u200b\u200b\u200b \u9879\u4ece 0 \u5230 n - 1 \u7f16\u53f7\u7684\u4efb\u52a1\u3002\u5176\u4e2d tasks[i] = [enqueueTimei, processingTimei] \u610f\u5473\u7740\u7b2c i\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b \u9879\u4efb\u52a1\u5c06\u4f1a\u4e8e enqueueTimei \u65f6\u8fdb\u5165\u4efb\u52a1\u961f\u5217\uff0c\u9700\u8981 processingTimei \u7684\u65f6\u957f\u5b8c\u6210\u6267\u884c\u3002

    \n\n

    \u73b0\u6709\u4e00\u4e2a\u5355\u7ebf\u7a0b CPU \uff0c\u540c\u4e00\u65f6\u95f4\u53ea\u80fd\u6267\u884c \u6700\u591a\u4e00\u9879 \u4efb\u52a1\uff0c\u8be5 CPU \u5c06\u4f1a\u6309\u7167\u4e0b\u8ff0\u65b9\u5f0f\u8fd0\u884c\uff1a

    \n\n
      \n\t
    • \u5982\u679c CPU \u7a7a\u95f2\uff0c\u4e14\u4efb\u52a1\u961f\u5217\u4e2d\u6ca1\u6709\u9700\u8981\u6267\u884c\u7684\u4efb\u52a1\uff0c\u5219 CPU \u4fdd\u6301\u7a7a\u95f2\u72b6\u6001\u3002
    • \n\t
    • \u5982\u679c CPU \u7a7a\u95f2\uff0c\u4f46\u4efb\u52a1\u961f\u5217\u4e2d\u6709\u9700\u8981\u6267\u884c\u7684\u4efb\u52a1\uff0c\u5219 CPU \u5c06\u4f1a\u9009\u62e9 \u6267\u884c\u65f6\u95f4\u6700\u77ed \u7684\u4efb\u52a1\u5f00\u59cb\u6267\u884c\u3002\u5982\u679c\u591a\u4e2a\u4efb\u52a1\u5177\u6709\u540c\u6837\u7684\u6700\u77ed\u6267\u884c\u65f6\u95f4\uff0c\u5219\u9009\u62e9\u4e0b\u6807\u6700\u5c0f\u7684\u4efb\u52a1\u5f00\u59cb\u6267\u884c\u3002
    • \n\t
    • \u4e00\u65e6\u67d0\u9879\u4efb\u52a1\u5f00\u59cb\u6267\u884c\uff0cCPU \u5728 \u6267\u884c\u5b8c\u6574\u4e2a\u4efb\u52a1 \u524d\u90fd\u4e0d\u4f1a\u505c\u6b62\u3002
    • \n\t
    • CPU \u53ef\u4ee5\u5728\u5b8c\u6210\u4e00\u9879\u4efb\u52a1\u540e\uff0c\u7acb\u5373\u5f00\u59cb\u6267\u884c\u4e00\u9879\u65b0\u4efb\u52a1\u3002
    • \n
    \n\n

    \u8fd4\u56de CPU \u5904\u7406\u4efb\u52a1\u7684\u987a\u5e8f\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1atasks = [[1,2],[2,4],[3,2],[4,1]]\n\u8f93\u51fa\uff1a[0,2,3,1]\n\u89e3\u91ca\uff1a\u4e8b\u4ef6\u6309\u4e0b\u8ff0\u6d41\u7a0b\u8fd0\u884c\uff1a \n- time = 1 \uff0c\u4efb\u52a1 0 \u8fdb\u5165\u4efb\u52a1\u961f\u5217\uff0c\u53ef\u6267\u884c\u4efb\u52a1\u9879 = {0}\n- \u540c\u6837\u5728 time = 1 \uff0c\u7a7a\u95f2\u72b6\u6001\u7684 CPU \u5f00\u59cb\u6267\u884c\u4efb\u52a1 0 \uff0c\u53ef\u6267\u884c\u4efb\u52a1\u9879 = {}\n- time = 2 \uff0c\u4efb\u52a1 1 \u8fdb\u5165\u4efb\u52a1\u961f\u5217\uff0c\u53ef\u6267\u884c\u4efb\u52a1\u9879 = {1}\n- time = 3 \uff0c\u4efb\u52a1 2 \u8fdb\u5165\u4efb\u52a1\u961f\u5217\uff0c\u53ef\u6267\u884c\u4efb\u52a1\u9879 = {1, 2}\n- \u540c\u6837\u5728 time = 3 \uff0cCPU \u5b8c\u6210\u4efb\u52a1 0 \u5e76\u5f00\u59cb\u6267\u884c\u961f\u5217\u4e2d\u7528\u65f6\u6700\u77ed\u7684\u4efb\u52a1 2 \uff0c\u53ef\u6267\u884c\u4efb\u52a1\u9879 = {1}\n- time = 4 \uff0c\u4efb\u52a1 3 \u8fdb\u5165\u4efb\u52a1\u961f\u5217\uff0c\u53ef\u6267\u884c\u4efb\u52a1\u9879 = {1, 3}\n- time = 5 \uff0cCPU \u5b8c\u6210\u4efb\u52a1 2 \u5e76\u5f00\u59cb\u6267\u884c\u961f\u5217\u4e2d\u7528\u65f6\u6700\u77ed\u7684\u4efb\u52a1 3 \uff0c\u53ef\u6267\u884c\u4efb\u52a1\u9879 = {1}\n- time = 6 \uff0cCPU \u5b8c\u6210\u4efb\u52a1 3 \u5e76\u5f00\u59cb\u6267\u884c\u4efb\u52a1 1 \uff0c\u53ef\u6267\u884c\u4efb\u52a1\u9879 = {}\n- time = 10 \uff0cCPU \u5b8c\u6210\u4efb\u52a1 1 \u5e76\u8fdb\u5165\u7a7a\u95f2\u72b6\u6001\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1atasks = [[7,10],[7,12],[7,5],[7,4],[7,2]]\n\u8f93\u51fa\uff1a[4,3,2,0,1]\n\u89e3\u91ca\uff1a\u4e8b\u4ef6\u6309\u4e0b\u8ff0\u6d41\u7a0b\u8fd0\u884c\uff1a \n- time = 7 \uff0c\u6240\u6709\u4efb\u52a1\u540c\u65f6\u8fdb\u5165\u4efb\u52a1\u961f\u5217\uff0c\u53ef\u6267\u884c\u4efb\u52a1\u9879  = {0,1,2,3,4}\n- \u540c\u6837\u5728 time = 7 \uff0c\u7a7a\u95f2\u72b6\u6001\u7684 CPU \u5f00\u59cb\u6267\u884c\u4efb\u52a1 4 \uff0c\u53ef\u6267\u884c\u4efb\u52a1\u9879 = {0,1,2,3}\n- time = 9 \uff0cCPU \u5b8c\u6210\u4efb\u52a1 4 \u5e76\u5f00\u59cb\u6267\u884c\u4efb\u52a1 3 \uff0c\u53ef\u6267\u884c\u4efb\u52a1\u9879 = {0,1,2}\n- time = 13 \uff0cCPU \u5b8c\u6210\u4efb\u52a1 3 \u5e76\u5f00\u59cb\u6267\u884c\u4efb\u52a1 2 \uff0c\u53ef\u6267\u884c\u4efb\u52a1\u9879 = {0,1}\n- time = 18 \uff0cCPU \u5b8c\u6210\u4efb\u52a1 2 \u5e76\u5f00\u59cb\u6267\u884c\u4efb\u52a1 0 \uff0c\u53ef\u6267\u884c\u4efb\u52a1\u9879 = {1}\n- time = 28 \uff0cCPU \u5b8c\u6210\u4efb\u52a1 0 \u5e76\u5f00\u59cb\u6267\u884c\u4efb\u52a1 1 \uff0c\u53ef\u6267\u884c\u4efb\u52a1\u9879 = {}\n- time = 40 \uff0cCPU \u5b8c\u6210\u4efb\u52a1 1 \u5e76\u8fdb\u5165\u7a7a\u95f2\u72b6\u6001
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • tasks.length == n
    • \n\t
    • 1 <= n <= 105
    • \n\t
    • 1 <= enqueueTimei, processingTimei <= 109
    • \n
    \n", "tags_en": ["Heap"], "tags_cn": ["\u5806"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector getOrder(vector>& tasks) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] getOrder(int[][] tasks) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getOrder(self, tasks):\n \"\"\"\n :type tasks: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getOrder(self, tasks: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* getOrder(int** tasks, int tasksSize, int* tasksColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] GetOrder(int[][] tasks) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} tasks\n * @return {number[]}\n */\nvar getOrder = function(tasks) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} tasks\n# @return {Integer[]}\ndef get_order(tasks)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getOrder(_ tasks: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getOrder(tasks [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getOrder(tasks: Array[Array[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getOrder(tasks: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_order(tasks: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $tasks\n * @return Integer[]\n */\n function getOrder($tasks) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getOrder(tasks: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-order tasks)\n (-> (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1834](https://leetcode-cn.com/problems/single-threaded-cpu)", "[\u5355\u7ebf\u7a0b CPU](/solution/1800-1899/1834.Single-Threaded%20CPU/README.md)", "`\u5806`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1834](https://leetcode.com/problems/single-threaded-cpu)", "[Single-Threaded CPU](/solution/1800-1899/1834.Single-Threaded%20CPU/README_EN.md)", "`Heap`", "Medium", ""]}, {"question_id": "1961", "frontend_question_id": "1833", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-ice-cream-bars", "url_en": "https://leetcode.com/problems/maximum-ice-cream-bars", "relative_path_cn": "/solution/1800-1899/1833.Maximum%20Ice%20Cream%20Bars/README.md", "relative_path_en": "/solution/1800-1899/1833.Maximum%20Ice%20Cream%20Bars/README_EN.md", "title_cn": "\u96ea\u7cd5\u7684\u6700\u5927\u6570\u91cf", "title_en": "Maximum Ice Cream Bars", "question_title_slug": "maximum-ice-cream-bars", "content_en": "

    It is a sweltering summer day, and a boy wants to buy some ice cream bars.

    \r\n\r\n

    At the store, there are n ice cream bars. You are given an array costs of length n, where costs[i] is the price of the ith ice cream bar in coins. The boy initially has coins coins to spend, and he wants to buy as many ice cream bars as possible. 

    \r\n\r\n

    Return the maximum number of ice cream bars the boy can buy with coins coins.

    \r\n\r\n

    Note: The boy can buy the ice cream bars in any order.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: costs = [1,3,2,4,1], coins = 7\r\nOutput: 4\r\nExplanation: The boy can buy ice cream bars at indices 0,1,2,4 for a total price of 1 + 3 + 2 + 1 = 7.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: costs = [10,6,8,7,7,8], coins = 5\r\nOutput: 0\r\nExplanation: The boy cannot afford any of the ice cream bars.\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: costs = [1,6,3,1,2,5], coins = 20\r\nOutput: 6\r\nExplanation: The boy can buy all the ice cream bars for a total price of 1 + 6 + 3 + 1 + 2 + 5 = 18.\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • costs.length == n
    • \r\n\t
    • 1 <= n <= 105
    • \r\n\t
    • 1 <= costs[i] <= 105
    • \r\n\t
    • 1 <= coins <= 108
    • \r\n
    ", "content_cn": "

    \u590f\u65e5\u708e\u708e\uff0c\u5c0f\u7537\u5b69 Tony \u60f3\u4e70\u4e00\u4e9b\u96ea\u7cd5\u6d88\u6d88\u6691\u3002

    \n\n

    \u5546\u5e97\u4e2d\u65b0\u5230 n \u652f\u96ea\u7cd5\uff0c\u7528\u957f\u5ea6\u4e3a n \u7684\u6570\u7ec4 costs \u8868\u793a\u96ea\u7cd5\u7684\u5b9a\u4ef7\uff0c\u5176\u4e2d costs[i] \u8868\u793a\u7b2c i \u652f\u96ea\u7cd5\u7684\u73b0\u91d1\u4ef7\u683c\u3002Tony \u4e00\u5171\u6709 coins \u73b0\u91d1\u53ef\u4ee5\u7528\u4e8e\u6d88\u8d39\uff0c\u4ed6\u60f3\u8981\u4e70\u5c3d\u53ef\u80fd\u591a\u7684\u96ea\u7cd5\u3002

    \n\n

    \u7ed9\u4f60\u4ef7\u683c\u6570\u7ec4 costs \u548c\u73b0\u91d1\u91cf coins \uff0c\u8bf7\u4f60\u8ba1\u7b97\u5e76\u8fd4\u56de Tony \u7528 coins \u73b0\u91d1\u80fd\u591f\u4e70\u5230\u7684\u96ea\u7cd5\u7684 \u6700\u5927\u6570\u91cf \u3002

    \n\n

    \u6ce8\u610f\uff1aTony \u53ef\u4ee5\u6309\u4efb\u610f\u987a\u5e8f\u8d2d\u4e70\u96ea\u7cd5\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1acosts = [1,3,2,4,1], coins = 7\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1aTony \u53ef\u4ee5\u4e70\u4e0b\u6807\u4e3a 0\u30011\u30012\u30014 \u7684\u96ea\u7cd5\uff0c\u603b\u4ef7\u4e3a 1 + 3 + 2 + 1 = 7\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1acosts = [10,6,8,7,7,8], coins = 5\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1aTony \u6ca1\u6709\u8db3\u591f\u7684\u94b1\u4e70\u4efb\u4f55\u4e00\u652f\u96ea\u7cd5\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1acosts = [1,6,3,1,2,5], coins = 20\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1aTony \u53ef\u4ee5\u4e70\u4e0b\u6240\u6709\u7684\u96ea\u7cd5\uff0c\u603b\u4ef7\u4e3a 1 + 6 + 3 + 1 + 2 + 5 = 18 \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • costs.length == n
    • \n\t
    • 1 <= n <= 105
    • \n\t
    • 1 <= costs[i] <= 105
    • \n\t
    • 1 <= coins <= 108
    • \n
    \n", "tags_en": ["Sort", "Array"], "tags_cn": ["\u6392\u5e8f", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxIceCream(vector& costs, int coins) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxIceCream(int[] costs, int coins) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxIceCream(self, costs, coins):\n \"\"\"\n :type costs: List[int]\n :type coins: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxIceCream(self, costs: List[int], coins: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxIceCream(int* costs, int costsSize, int coins){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxIceCream(int[] costs, int coins) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} costs\n * @param {number} coins\n * @return {number}\n */\nvar maxIceCream = function(costs, coins) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} costs\n# @param {Integer} coins\n# @return {Integer}\ndef max_ice_cream(costs, coins)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxIceCream(_ costs: [Int], _ coins: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxIceCream(costs []int, coins int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxIceCream(costs: Array[Int], coins: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxIceCream(costs: IntArray, coins: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_ice_cream(costs: Vec, coins: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $costs\n * @param Integer $coins\n * @return Integer\n */\n function maxIceCream($costs, $coins) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxIceCream(costs: number[], coins: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-ice-cream costs coins)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1833](https://leetcode-cn.com/problems/maximum-ice-cream-bars)", "[\u96ea\u7cd5\u7684\u6700\u5927\u6570\u91cf](/solution/1800-1899/1833.Maximum%20Ice%20Cream%20Bars/README.md)", "`\u6392\u5e8f`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1833](https://leetcode.com/problems/maximum-ice-cream-bars)", "[Maximum Ice Cream Bars](/solution/1800-1899/1833.Maximum%20Ice%20Cream%20Bars/README_EN.md)", "`Sort`,`Array`", "Medium", ""]}, {"question_id": "1960", "frontend_question_id": "1832", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/check-if-the-sentence-is-pangram", "url_en": "https://leetcode.com/problems/check-if-the-sentence-is-pangram", "relative_path_cn": "/solution/1800-1899/1832.Check%20if%20the%20Sentence%20Is%20Pangram/README.md", "relative_path_en": "/solution/1800-1899/1832.Check%20if%20the%20Sentence%20Is%20Pangram/README_EN.md", "title_cn": "\u5224\u65ad\u53e5\u5b50\u662f\u5426\u4e3a\u5168\u5b57\u6bcd\u53e5", "title_en": "Check if the Sentence Is Pangram", "question_title_slug": "check-if-the-sentence-is-pangram", "content_en": "

    A pangram is a sentence where every letter of the English alphabet appears at least once.

    \n\n

    Given a string sentence containing only lowercase English letters, return true if sentence is a pangram, or false otherwise.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: sentence = "thequickbrownfoxjumpsoverthelazydog"\nOutput: true\nExplanation: sentence contains at least one of every letter of the English alphabet.\n
    \n\n

    Example 2:

    \n\n
    \nInput: sentence = "leetcode"\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= sentence.length <= 1000
    • \n\t
    • sentence consists of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u5168\u5b57\u6bcd\u53e5 \u6307\u5305\u542b\u82f1\u8bed\u5b57\u6bcd\u8868\u4e2d\u6bcf\u4e2a\u5b57\u6bcd\u81f3\u5c11\u4e00\u6b21\u7684\u53e5\u5b50\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\u7684\u5b57\u7b26\u4e32 sentence \uff0c\u8bf7\u4f60\u5224\u65ad\u00a0sentence \u662f\u5426\u4e3a \u5168\u5b57\u6bcd\u53e5 \u3002

    \n\n

    \u5982\u679c\u662f\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1asentence = \"thequickbrownfoxjumpsoverthelazydog\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1asentence \u5305\u542b\u82f1\u8bed\u5b57\u6bcd\u8868\u4e2d\u6bcf\u4e2a\u5b57\u6bcd\u81f3\u5c11\u4e00\u6b21\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1asentence = \"leetcode\"\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= sentence.length <= 1000
    • \n\t
    • sentence \u7531\u5c0f\u5199\u82f1\u8bed\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool checkIfPangram(string sentence) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean checkIfPangram(String sentence) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def checkIfPangram(self, sentence):\n \"\"\"\n :type sentence: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def checkIfPangram(self, sentence: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool checkIfPangram(char * sentence){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CheckIfPangram(string sentence) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} sentence\n * @return {boolean}\n */\nvar checkIfPangram = function(sentence) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} sentence\n# @return {Boolean}\ndef check_if_pangram(sentence)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func checkIfPangram(_ sentence: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func checkIfPangram(sentence string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def checkIfPangram(sentence: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun checkIfPangram(sentence: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn check_if_pangram(sentence: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $sentence\n * @return Boolean\n */\n function checkIfPangram($sentence) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function checkIfPangram(sentence: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (check-if-pangram sentence)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1832](https://leetcode-cn.com/problems/check-if-the-sentence-is-pangram)", "[\u5224\u65ad\u53e5\u5b50\u662f\u5426\u4e3a\u5168\u5b57\u6bcd\u53e5](/solution/1800-1899/1832.Check%20if%20the%20Sentence%20Is%20Pangram/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1832](https://leetcode.com/problems/check-if-the-sentence-is-pangram)", "[Check if the Sentence Is Pangram](/solution/1800-1899/1832.Check%20if%20the%20Sentence%20Is%20Pangram/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1959", "frontend_question_id": "1810", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/minimum-path-cost-in-a-hidden-grid", "url_en": "https://leetcode.com/problems/minimum-path-cost-in-a-hidden-grid", "relative_path_cn": "/solution/1800-1899/1810.Minimum%20Path%20Cost%20in%20a%20Hidden%20Grid/README.md", "relative_path_en": "/solution/1800-1899/1810.Minimum%20Path%20Cost%20in%20a%20Hidden%20Grid/README_EN.md", "title_cn": "", "title_en": "Minimum Path Cost in a Hidden Grid", "question_title_slug": "minimum-path-cost-in-a-hidden-grid", "content_en": "

    This is an interactive problem.

    \n\n

    There is a robot in a hidden grid, and you are trying to get it from its starting cell to the target cell in this grid. The grid is of size m x n, and each cell in the grid is either empty or blocked. It is guaranteed that the starting cell and the target cell are different, and neither of them is blocked.

    \n\n

    Each cell has a cost that you need to pay each time you move to the cell. The starting cell's cost is not applied before the robot moves.

    \n\n

    You want to find the minimum total cost to move the robot to the target cell. However, you do not know the grid's dimensions, the starting cell, nor the target cell. You are only allowed to ask queries to the GridMaster object.

    \n\n

    The GridMaster class has the following functions:

    \n\n
      \n\t
    • boolean canMove(char direction) Returns true if the robot can move in that direction. Otherwise, it returns false.
    • \n\t
    • int move(char direction) Moves the robot in that direction and returns the cost of moving to that cell. If this move would move the robot to a blocked cell or off the grid, the move will be ignored, the robot will remain in the same position, and the function will return -1.
    • \n\t
    • boolean isTarget() Returns true if the robot is currently on the target cell. Otherwise, it returns false.
    • \n
    \n\n

    Note that direction in the above functions should be a character from {'U','D','L','R'}, representing the directions up, down, left, and right, respectively.

    \n\n

    Return the minimum total cost to get the robot from its initial starting cell to the target cell. If there is no valid path between the cells, return -1.

    \n\n

    Custom testing:

    \n\n

    The test input is read as a 2D matrix grid of size m x n and four integers r1, c1, r2, and c2 where:

    \n\n
      \n\t
    • grid[i][j] == 0 indicates that the cell (i, j) is blocked.
    • \n\t
    • grid[i][j] >= 1 indicates that the cell (i, j) is empty and grid[i][j] is the cost to move to that cell.
    • \n\t
    • (r1, c1) is the starting cell of the robot.
    • \n\t
    • (r2, c2) is the target cell of the robot.
    • \n
    \n\n

    Remember that you will not have this information in your code.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: grid = [[2,3],[1,1]], r1 = 0, c1 = 1, r2 = 1, c2 = 0\nOutput: 2\nExplanation: One possible interaction is described below:\nThe robot is initially standing on cell (0, 1), denoted by the 3.\n- master.canMove('U') returns false.\n- master.canMove('D') returns true.\n- master.canMove('L') returns true.\n- master.canMove('R') returns false.\n- master.move('L') moves the robot to the cell (0, 0) and returns 2.\n- master.isTarget() returns false.\n- master.canMove('U') returns false.\n- master.canMove('D') returns true.\n- master.canMove('L') returns false.\n- master.canMove('R') returns true.\n- master.move('D') moves the robot to the cell (1, 0) and returns 1.\n- master.isTarget() returns true.\n- master.move('L') doesn't move the robot and returns -1.\n- master.move('R') moves the robot to the cell (1, 1) and returns 1.\nWe now know that the target is the cell (0, 1), and the minimum total cost to reach it is 2. 
    \n\n

    Example 2:

    \n\n
    \nInput: grid = [[0,3,1],[3,4,2],[1,2,0]], r1 = 2, c1 = 0, r2 = 0, c2 = 2\nOutput: 9\nExplanation: The minimum cost path is (2,0) -> (2,1) -> (1,1) -> (1,2) -> (0,2).\n
    \n\n

    Example 3:

    \n\n
    \nInput: grid = [[1,0],[0,1]], r1 = 0, c1 = 0, r2 = 1, c2 = 1\nOutput: -1\nExplanation: There is no path from the robot to the target cell.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n, m <= 100
    • \n\t
    • m == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 0 <= grid[i][j] <= 100
    • \n
    \n", "content_cn": null, "tags_en": ["Heap", "Depth-first Search", "Graph"], "tags_cn": ["\u5806", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * // This is the GridMaster's API interface.\n * // You should not implement it, or speculate about its implementation\n * class GridMaster {\n * public:\n * bool canMove(char direction);\n * int move(char direction);\n * boolean isTarget();\n * };\n */\n\nclass Solution {\npublic:\n int findShortestPath(GridMaster &master) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * // This is the GridMaster's API interface.\n * // You should not implement it, or speculate about its implementation\n * class GridMaster {\n * boolean canMove(char direction);\n * int move(char direction);\n * boolean isTarget();\n * }\n */\n\nclass Solution {\n public int findShortestPath(GridMaster master) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# \"\"\"\n# This is GridMaster's API interface.\n# You should not implement it, or speculate about it's implementation\n# \"\"\"\n#class GridMaster(object):\n# def canMove(self, direction):\n# \"\"\"\n# :type direction: str\n# :rtype bool\n# \"\"\"\n#\n# def move(self, direction):\n# \"\"\"\n# :type direction: str\n#. :rtype int\n# \"\"\"\n#\n# def isTarget(self):\n# \"\"\"\n# :rtype bool\n# \"\"\"\n#\n\nclass Solution(object):\n def findShortestPath(self, master):\n \"\"\"\n :type master: GridMaster\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# \"\"\"\n# This is GridMaster's API interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class GridMaster(object):\n# def canMove(self, direction: str) -> bool:\n# \n#\n# def move(self, direction: str) -> int:\n# \n#\n# def isTarget(self) -> None:\n# \n#\n\nclass Solution(object):\n def findShortestPath(self, master: 'GridMaster') -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * // This is the GridMaster's API interface.\n * // You should not implement it, or speculate about its implementation\n * class GridMaster {\n * bool canMove(char direction);\n * int move(char direction);\n * bool isTarget();\n * };\n */\n\nclass Solution {\n public int FindShortestPath(GridMaster master) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // This is the GridMaster's API interface.\n * // You should not implement it, or speculate about its implementation\n * function GridMaster() {\n *\n * @param {character} direction\n * @return {boolean}\n * this.canMove = function(direction) {\n * ...\n * };\n * @param {character} direction\n * @return {integer}\n * this.move = function(direction) {\n * ...\n * };\n * @return {boolean}\n * this.isTarget = function() {\n * ...\n * };\n * };\n */\n\n/**\n * @param {GridMaster} master\n * @return {integer}\n */\nvar findShortestPath = function(master) {\n \n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1810](https://leetcode-cn.com/problems/minimum-path-cost-in-a-hidden-grid)", "[Minimum Path Cost in a Hidden Grid](/solution/1800-1899/1810.Minimum%20Path%20Cost%20in%20a%20Hidden%20Grid/README_EN.md)", "`\u5806`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u56fe`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1810](https://leetcode.com/problems/minimum-path-cost-in-a-hidden-grid)", "[Minimum Path Cost in a Hidden Grid](/solution/1800-1899/1810.Minimum%20Path%20Cost%20in%20a%20Hidden%20Grid/README_EN.md)", "`Heap`,`Depth-first Search`,`Graph`", "Medium", "\ud83d\udd12"]}, {"question_id": "1958", "frontend_question_id": "1809", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/ad-free-sessions", "url_en": "https://leetcode.com/problems/ad-free-sessions", "relative_path_cn": "/solution/1800-1899/1809.Ad-Free%20Sessions/README.md", "relative_path_en": "/solution/1800-1899/1809.Ad-Free%20Sessions/README_EN.md", "title_cn": "\u6ca1\u6709\u5e7f\u544a\u7684\u5267\u96c6", "title_en": "Ad-Free Sessions", "question_title_slug": "ad-free-sessions", "content_en": "

    Table: Playback

    \n\n
    \n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| session_id  | int  |\n| customer_id | int  |\n| start_time  | int  |\n| end_time    | int  |\n+-------------+------+\nsession_id is the primary key for this table.\ncustomer_id is the ID of the customer watching this session.\nThe session runs during the inclusive interval between start_time and end_time.\nIt is guaranteed that start_time <= end_time and that two sessions for the same customer do not intersect.
    \n\n

     

    \n\n

    Table: Ads

    \n\n
    \n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| ad_id       | int  |\n| customer_id | int  |\n| timestamp   | int  |\n+-------------+------+\nad_id is the primary key for this table.\ncustomer_id is the ID of the customer viewing this ad.\ntimestamp is the moment of time at which the ad was shown.\n
    \n\n

     

    \n\n

    Write an SQL query to report all the sessions that did not get shown any ads.

    \n\n

    Return the result table in any order.

    \n\n

    The query result format is in the following example:

    \n\n

     

    \n\n
    \nPlayback table:\n+------------+-------------+------------+----------+\n| session_id | customer_id | start_time | end_time |\n+------------+-------------+------------+----------+\n| 1          | 1           | 1          | 5        |\n| 2          | 1           | 15         | 23       |\n| 3          | 2           | 10         | 12       |\n| 4          | 2           | 17         | 28       |\n| 5          | 2           | 2          | 8        |\n+------------+-------------+------------+----------+\n\nAds table:\n+-------+-------------+-----------+\n| ad_id | customer_id | timestamp |\n+-------+-------------+-----------+\n| 1     | 1           | 5         |\n| 2     | 2           | 17        |\n| 3     | 2           | 20        |\n+-------+-------------+-----------+\n\nResult table:\n+------------+\n| session_id |\n+------------+\n| 2          |\n| 3          |\n| 5          |\n+------------+\nThe ad with ID 1 was shown to user 1 at time 5 while they were in session 1.\nThe ad with ID 2 was shown to user 2 at time 17 while they were in session 4.\nThe ad with ID 3 was shown to user 2 at time 20 while they were in session 4.\nWe can see that sessions 1 and 4 had at least one ad. Sessions 2, 3, and 5 did not have any ads, so we return them.
    \n", "content_cn": "

    Table: Playback

    \n\n
    +-------------+------+\n| Column Name | Type |\n+-------------+------+\n| session_id  | int  |\n| customer_id | int  |\n| start_time  | int  |\n| end_time    | int  |\n+-------------+------+\n\u8be5\u8868\u4e3b\u952e\u4e3a\uff1asession_id \uff08\u5267\u96c6id\uff09\ncustomer_id \u662f\u89c2\u770b\u8be5\u5267\u96c6\u7684\u89c2\u4f17id\n\u5267\u96c6\u64ad\u653e\u65f6\u95f4\u5305\u542bstart_time\uff08\u5f00\u59cb\u65f6\u95f4\uff09 \u53ca end_time\uff08\u7ed3\u675f\u65f6\u95f4\uff09\n\u53ef\u4ee5\u4fdd\u8bc1\u7684\u662f\uff0cstart_time\uff08\u5f00\u59cb\u65f6\u95f4\uff09<= end_time\uff08\u7ed3\u675f\u65f6\u95f4\uff09\uff0c\u4e00\u4e2a\u89c2\u4f17\u89c2\u770b\u7684\u4e24\u4e2a\u5267\u96c6\u7684\u65f6\u95f4\u4e0d\u4f1a\u51fa\u73b0\u91cd\u53e0\u3002
    \n\n

    \u00a0

    \n\n

    Table: Ads

    \n\n
    +-------------+------+\n| Column Name | Type |\n+-------------+------+\n| ad_id       | int  |\n| customer_id | int  |\n| timestamp   | int  |\n+-------------+------+\n\u8be5\u8868\u7684\u4e3b\u952e\u4e3a\uff1aad_id\uff08\u5e7f\u544aid\uff09\ncustomer_id \u4e3a \u89c2\u770b\u5e7f\u544a\u7684\u7528\u6237id\ntimestamp \u8868\u793a\u5e7f\u544a\u51fa\u73b0\u7684\u65f6\u95f4\u70b9\n
    \n\n

    \u00a0

    \n\n

    \u8bf7\u67e5\u51fa\uff0c\u6240\u6709\u6ca1\u6709\u5e7f\u544a\u51fa\u73b0\u8fc7\u7684\u5267\u96c6\u3002

    \n\n

    \u5982\u679c\u89c2\u4f17\u89c2\u770b\u4e86\u5267\u96c6\uff0c\u5e76\u4e14\u5267\u96c6\u91cc\u51fa\u73b0\u4e86\u5e7f\u544a\uff0c\u5c31\u4e00\u5b9a\u4f1a\u6709\u89c2\u4f17\u89c2\u770b\u5e7f\u544a\u7684\u8bb0\u5f55\u3002

    \n\n

    \u8fd4\u56de\u7ed3\u679c\u6ca1\u6709\u987a\u5e8f\u8981\u6c42\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    Playback table:\n+------------+-------------+------------+----------+\n| session_id | customer_id | start_time | end_time |\n+------------+-------------+------------+----------+\n| 1          | 1           | 1          | 5        |\n| 2          | 1           | 15         | 23       |\n| 3          | 2           | 10         | 12       |\n| 4          | 2           | 17         | 28       |\n| 5          | 2           | 2          | 8        |\n+------------+-------------+------------+----------+\n\nAds table:\n+-------+-------------+-----------+\n| ad_id | customer_id | timestamp |\n+-------+-------------+-----------+\n| 1     | 1           | 5         |\n| 2     | 2           | 17        |\n| 3     | 2           | 20        |\n+-------+-------------+-----------+\n\nResult table:\n+------------+\n| session_id |\n+------------+\n| 2          |\n| 3          |\n| 5          |\n+------------+\n\u5e7f\u544a1\u51fa\u73b0\u5728\u4e86\u5267\u96c61\u7684\u65f6\u95f4\u6bb5\uff0c\u88ab\u89c2\u4f171\u770b\u5230\u4e86\u3002\n\u5e7f\u544a2\u51fa\u73b0\u5728\u4e86\u5267\u96c64\u7684\u65f6\u95f4\u6bb5\uff0c\u88ab\u89c2\u4f172\u770b\u5230\u4e86\u3002\n\u5e7f\u544a3\u51fa\u73b0\u5728\u4e86\u5267\u96c64\u7684\u65f6\u95f4\u6bb5\uff0c\u88ab\u89c2\u4f172\u770b\u5230\u4e86\u3002\n\u6211\u4eec\u53ef\u4ee5\u5f97\u51fa\u7ed3\u8bba\uff0c\u5267\u96c61 \u30014 \u5185\uff0c\u8d77\u7801\u67091\u5904\u5e7f\u544a\u3002 \u5267\u96c62 \u30013 \u30015 \u6ca1\u6709\u5e7f\u544a\u3002
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1809](https://leetcode-cn.com/problems/ad-free-sessions)", "[\u6ca1\u6709\u5e7f\u544a\u7684\u5267\u96c6](/solution/1800-1899/1809.Ad-Free%20Sessions/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1809](https://leetcode.com/problems/ad-free-sessions)", "[Ad-Free Sessions](/solution/1800-1899/1809.Ad-Free%20Sessions/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1957", "frontend_question_id": "1847", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/closest-room", "url_en": "https://leetcode.com/problems/closest-room", "relative_path_cn": "/solution/1800-1899/1847.Closest%20Room/README.md", "relative_path_en": "/solution/1800-1899/1847.Closest%20Room/README_EN.md", "title_cn": "\u6700\u8fd1\u7684\u623f\u95f4", "title_en": "Closest Room", "question_title_slug": "closest-room", "content_en": "

    There is a hotel with n rooms. The rooms are represented by a 2D integer array rooms where rooms[i] = [roomIdi, sizei] denotes that there is a room with room number roomIdi and size equal to sizei. Each roomIdi is guaranteed to be unique.

    \n\n

    You are also given k queries in a 2D array queries where queries[j] = [preferredj, minSizej]. The answer to the jth query is the room number id of a room such that:

    \n\n
      \n\t
    • The room has a size of at least minSizej, and
    • \n\t
    • abs(id - preferredj) is minimized, where abs(x) is the absolute value of x.
    • \n
    \n\n

    If there is a tie in the absolute difference, then use the room with the smallest such id. If there is no such room, the answer is -1.

    \n\n

    Return an array answer of length k where answer[j] contains the answer to the jth query.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: rooms = [[2,2],[1,2],[3,2]], queries = [[3,1],[3,3],[5,2]]\nOutput: [3,-1,3]\nExplanation: The answers to the queries are as follows:\nQuery = [3,1]: Room number 3 is the closest as abs(3 - 3) = 0, and its size of 2 is at least 1. The answer is 3.\nQuery = [3,3]: There are no rooms with a size of at least 3, so the answer is -1.\nQuery = [5,2]: Room number 3 is the closest as abs(3 - 5) = 2, and its size of 2 is at least 2. The answer is 3.
    \n\n

    Example 2:

    \n\n
    \nInput: rooms = [[1,4],[2,3],[3,5],[4,1],[5,2]], queries = [[2,3],[2,4],[2,5]]\nOutput: [2,1,3]\nExplanation: The answers to the queries are as follows:\nQuery = [2,3]: Room number 2 is the closest as abs(2 - 2) = 0, and its size of 3 is at least 3. The answer is 2.\nQuery = [2,4]: Room numbers 1 and 3 both have sizes of at least 4. The answer is 1 since it is smaller.\nQuery = [2,5]: Room number 3 is the only room with a size of at least 5. The answer is 3.
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == rooms.length
    • \n\t
    • 1 <= n <= 105
    • \n\t
    • k == queries.length
    • \n\t
    • 1 <= k <= 104
    • \n\t
    • 1 <= roomIdi, preferredj <= 107
    • \n\t
    • 1 <= sizei, minSizej <= 107
    • \n\t
    •  
    • \n
    \n", "content_cn": "

    \u4e00\u4e2a\u9152\u5e97\u91cc\u6709\u00a0n\u00a0\u4e2a\u623f\u95f4\uff0c\u8fd9\u4e9b\u623f\u95f4\u7528\u4e8c\u7ef4\u6574\u6570\u6570\u7ec4\u00a0rooms\u00a0\u8868\u793a\uff0c\u5176\u4e2d\u00a0rooms[i] = [roomIdi, sizei]\u00a0\u8868\u793a\u6709\u4e00\u4e2a\u623f\u95f4\u53f7\u4e3a\u00a0roomIdi\u00a0\u7684\u623f\u95f4\u4e14\u5b83\u7684\u9762\u79ef\u4e3a\u00a0sizei\u00a0\u3002\u6bcf\u4e00\u4e2a\u623f\u95f4\u53f7\u00a0roomIdi\u00a0\u4fdd\u8bc1\u662f \u72ec\u4e00\u65e0\u4e8c\u00a0\u7684\u3002

    \n\n

    \u540c\u65f6\u7ed9\u4f60 k\u00a0\u4e2a\u67e5\u8be2\uff0c\u7528\u4e8c\u7ef4\u6570\u7ec4\u00a0queries\u00a0\u8868\u793a\uff0c\u5176\u4e2d\u00a0queries[j] = [preferredj, minSizej]\u00a0\u3002\u7b2c\u00a0j\u00a0\u4e2a\u67e5\u8be2\u7684\u7b54\u6848\u662f\u6ee1\u8db3\u5982\u4e0b\u6761\u4ef6\u7684\u623f\u95f4\u00a0id\u00a0\uff1a

    \n\n
      \n\t
    • \u623f\u95f4\u7684\u9762\u79ef\u00a0\u81f3\u5c11\u00a0\u4e3a\u00a0minSizej\u00a0\uff0c\u4e14
    • \n\t
    • abs(id - preferredj)\u00a0\u7684\u503c \u6700\u5c0f\u00a0\uff0c\u5176\u4e2d\u00a0abs(x)\u00a0\u662f\u00a0x\u00a0\u7684\u7edd\u5bf9\u503c\u3002
    • \n
    \n\n

    \u5982\u679c\u5dee\u7684\u7edd\u5bf9\u503c\u6709 \u76f8\u7b49\u00a0\u7684\uff0c\u9009\u62e9 \u6700\u5c0f\u00a0\u7684\u00a0id\u00a0\u3002\u5982\u679c \u6ca1\u6709\u6ee1\u8db3\u6761\u4ef6\u7684\u623f\u95f4\u00a0\uff0c\u7b54\u6848\u4e3a -1\u00a0\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u957f\u5ea6\u4e3a k\u00a0\u7684\u6570\u7ec4\u00a0answer\u00a0\uff0c\u5176\u4e2d\u00a0answer[j]\u00a0\u4e3a\u7b2c j\u00a0\u4e2a\u67e5\u8be2\u7684\u7ed3\u679c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1arooms = [[2,2],[1,2],[3,2]], queries = [[3,1],[3,3],[5,2]]\n\u8f93\u51fa\uff1a[3,-1,3]\n\u89e3\u91ca\uff1a\u67e5\u8be2\u7684\u7b54\u6848\u5982\u4e0b\uff1a\n\u67e5\u8be2 [3,1] \uff1a\u623f\u95f4 3 \u7684\u9762\u79ef\u4e3a 2 \uff0c\u5927\u4e8e\u7b49\u4e8e 1 \uff0c\u4e14\u53f7\u7801\u662f\u6700\u63a5\u8fd1 3 \u7684\uff0c\u4e3a abs(3 - 3) = 0 \uff0c\u6240\u4ee5\u7b54\u6848\u4e3a 3 \u3002\n\u67e5\u8be2 [3,3] \uff1a\u6ca1\u6709\u623f\u95f4\u7684\u9762\u79ef\u81f3\u5c11\u4e3a 3 \uff0c\u6240\u4ee5\u7b54\u6848\u4e3a -1 \u3002\n\u67e5\u8be2 [5,2] \uff1a\u623f\u95f4 3 \u7684\u9762\u79ef\u4e3a 2 \uff0c\u5927\u4e8e\u7b49\u4e8e 2 \uff0c\u4e14\u53f7\u7801\u662f\u6700\u63a5\u8fd1 5 \u7684\uff0c\u4e3a abs(3 - 5) = 2 \uff0c\u6240\u4ee5\u7b54\u6848\u4e3a 3 \u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1arooms = [[1,4],[2,3],[3,5],[4,1],[5,2]], queries = [[2,3],[2,4],[2,5]]\n\u8f93\u51fa\uff1a[2,1,3]\n\u89e3\u91ca\uff1a\u67e5\u8be2\u7684\u7b54\u6848\u5982\u4e0b\uff1a\n\u67e5\u8be2 [2,3] \uff1a\u623f\u95f4 2 \u7684\u9762\u79ef\u4e3a 3 \uff0c\u5927\u4e8e\u7b49\u4e8e 3 \uff0c\u4e14\u53f7\u7801\u662f\u6700\u63a5\u8fd1\u7684\uff0c\u4e3a abs(2 - 2) = 0 \uff0c\u6240\u4ee5\u7b54\u6848\u4e3a 2 \u3002\n\u67e5\u8be2 [2,4] \uff1a\u623f\u95f4 1 \u548c 3 \u7684\u9762\u79ef\u90fd\u81f3\u5c11\u4e3a 4 \uff0c\u7b54\u6848\u4e3a 1 \u56e0\u4e3a\u5b83\u623f\u95f4\u7f16\u53f7\u66f4\u5c0f\u3002\n\u67e5\u8be2 [2,5] \uff1a\u623f\u95f4 3 \u662f\u552f\u4e00\u9762\u79ef\u5927\u4e8e\u7b49\u4e8e 5 \u7684\uff0c\u6240\u4ee5\u7b54\u6848\u4e3a 3 \u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == rooms.length
    • \n\t
    • 1 <= n <= 105
    • \n\t
    • k == queries.length
    • \n\t
    • 1 <= k <= 104
    • \n\t
    • 1 <= roomIdi, preferredj <= 107
    • \n\t
    • 1 <= sizei, minSizej <= 107
    • \n
    \n", "tags_en": ["Sort", "Binary Search"], "tags_cn": ["\u6392\u5e8f", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector closestRoom(vector>& rooms, vector>& queries) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] closestRoom(int[][] rooms, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def closestRoom(self, rooms, queries):\n \"\"\"\n :type rooms: List[List[int]]\n :type queries: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def closestRoom(self, rooms: List[List[int]], queries: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* closestRoom(int** rooms, int roomsSize, int* roomsColSize, int** queries, int queriesSize, int* queriesColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] ClosestRoom(int[][] rooms, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} rooms\n * @param {number[][]} queries\n * @return {number[]}\n */\nvar closestRoom = function(rooms, queries) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} rooms\n# @param {Integer[][]} queries\n# @return {Integer[]}\ndef closest_room(rooms, queries)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func closestRoom(_ rooms: [[Int]], _ queries: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func closestRoom(rooms [][]int, queries [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def closestRoom(rooms: Array[Array[Int]], queries: Array[Array[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun closestRoom(rooms: Array, queries: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn closest_room(rooms: Vec>, queries: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $rooms\n * @param Integer[][] $queries\n * @return Integer[]\n */\n function closestRoom($rooms, $queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function closestRoom(rooms: number[][], queries: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (closest-room rooms queries)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1847](https://leetcode-cn.com/problems/closest-room)", "[\u6700\u8fd1\u7684\u623f\u95f4](/solution/1800-1899/1847.Closest%20Room/README.md)", "`\u6392\u5e8f`,`\u4e8c\u5206\u67e5\u627e`", "\u56f0\u96be", ""], "md_table_row_en": ["[1847](https://leetcode.com/problems/closest-room)", "[Closest Room](/solution/1800-1899/1847.Closest%20Room/README_EN.md)", "`Sort`,`Binary Search`", "Hard", ""]}, {"question_id": "1956", "frontend_question_id": "1846", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-element-after-decreasing-and-rearranging", "url_en": "https://leetcode.com/problems/maximum-element-after-decreasing-and-rearranging", "relative_path_cn": "/solution/1800-1899/1846.Maximum%20Element%20After%20Decreasing%20and%20Rearranging/README.md", "relative_path_en": "/solution/1800-1899/1846.Maximum%20Element%20After%20Decreasing%20and%20Rearranging/README_EN.md", "title_cn": "\u51cf\u5c0f\u548c\u91cd\u65b0\u6392\u5217\u6570\u7ec4\u540e\u7684\u6700\u5927\u5143\u7d20", "title_en": "Maximum Element After Decreasing and Rearranging", "question_title_slug": "maximum-element-after-decreasing-and-rearranging", "content_en": "

    You are given an array of positive integers arr. Perform some operations (possibly none) on arr so that it satisfies these conditions:

    \n\n
      \n\t
    • The value of the first element in arr must be 1.
    • \n\t
    • The absolute difference between any 2 adjacent elements must be less than or equal to 1. In other words, abs(arr[i] - arr[i - 1]) <= 1 for each i where 1 <= i < arr.length (0-indexed). abs(x) is the absolute value of x.
    • \n
    \n\n

    There are 2 types of operations that you can perform any number of times:

    \n\n
      \n\t
    • Decrease the value of any element of arr to a smaller positive integer.
    • \n\t
    • Rearrange the elements of arr to be in any order.
    • \n
    \n\n

    Return the maximum possible value of an element in arr after performing the operations to satisfy the conditions.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr = [2,2,1,2,1]\nOutput: 2\nExplanation: \nWe can satisfy the conditions by rearranging arr so it becomes [1,2,2,2,1].\nThe largest element in arr is 2.\n
    \n\n

    Example 2:

    \n\n
    \nInput: arr = [100,1,1000]\nOutput: 3\nExplanation: \nOne possible way to satisfy the conditions is by doing the following:\n1. Rearrange arr so it becomes [1,100,1000].\n2. Decrease the value of the second element to 2.\n3. Decrease the value of the third element to 3.\nNow arr = [1,2,3], which satisfies the conditions.\nThe largest element in arr is 3.\n
    \n\n

    Example 3:

    \n\n
    \nInput: arr = [1,2,3,4,5]\nOutput: 5\nExplanation: The array already satisfies the conditions, and the largest element is 5.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= arr.length <= 105
    • \n\t
    • 1 <= arr[i] <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6b63\u6574\u6570\u6570\u7ec4\u00a0arr\u00a0\u3002\u8bf7\u4f60\u5bf9 arr\u00a0\u6267\u884c\u4e00\u4e9b\u64cd\u4f5c\uff08\u4e5f\u53ef\u4ee5\u4e0d\u8fdb\u884c\u4efb\u4f55\u64cd\u4f5c\uff09\uff0c\u4f7f\u5f97\u6570\u7ec4\u6ee1\u8db3\u4ee5\u4e0b\u6761\u4ef6\uff1a

    \n\n
      \n\t
    • arr\u00a0\u4e2d \u7b2c\u4e00\u4e2a\u00a0\u5143\u7d20\u5fc5\u987b\u4e3a\u00a01\u00a0\u3002
    • \n\t
    • \u4efb\u610f\u76f8\u90bb\u4e24\u4e2a\u5143\u7d20\u7684\u5dee\u7684\u7edd\u5bf9\u503c \u5c0f\u4e8e\u7b49\u4e8e\u00a01\u00a0\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u5bf9\u4e8e\u4efb\u610f\u7684 1 <= i < arr.length\u00a0\uff08\u6570\u7ec4\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\uff0c\u90fd\u6ee1\u8db3\u00a0abs(arr[i] - arr[i - 1]) <= 1\u00a0\u3002abs(x)\u00a0\u4e3a\u00a0x\u00a0\u7684\u7edd\u5bf9\u503c\u3002
    • \n
    \n\n

    \u4f60\u53ef\u4ee5\u6267\u884c\u4ee5\u4e0b 2 \u79cd\u64cd\u4f5c\u4efb\u610f\u6b21\uff1a

    \n\n
      \n\t
    • \u51cf\u5c0f arr\u00a0\u4e2d\u4efb\u610f\u5143\u7d20\u7684\u503c\uff0c\u4f7f\u5176\u53d8\u4e3a\u4e00\u4e2a \u66f4\u5c0f\u7684\u6b63\u6574\u6570\u00a0\u3002
    • \n\t
    • \u91cd\u65b0\u6392\u5217\u00a0arr\u00a0\u4e2d\u7684\u5143\u7d20\uff0c\u4f60\u53ef\u4ee5\u4ee5\u4efb\u610f\u987a\u5e8f\u91cd\u65b0\u6392\u5217\u3002
    • \n
    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u6267\u884c\u4ee5\u4e0a\u64cd\u4f5c\u540e\uff0c\u5728\u6ee1\u8db3\u524d\u6587\u6240\u8ff0\u7684\u6761\u4ef6\u4e0b\uff0carr\u00a0\u4e2d\u53ef\u80fd\u7684 \u6700\u5927\u503c\u00a0\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [2,2,1,2,1]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n\u6211\u4eec\u53ef\u4ee5\u91cd\u65b0\u6392\u5217 arr \u5f97\u5230 [1,2,2,2,1] \uff0c\u8be5\u6570\u7ec4\u6ee1\u8db3\u6240\u6709\u6761\u4ef6\u3002\narr \u4e2d\u6700\u5927\u5143\u7d20\u4e3a 2 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [100,1,1000]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\n\u4e00\u4e2a\u53ef\u884c\u7684\u65b9\u6848\u5982\u4e0b\uff1a\n1. \u91cd\u65b0\u6392\u5217 arr \u5f97\u5230 [1,100,1000] \u3002\n2. \u5c06\u7b2c\u4e8c\u4e2a\u5143\u7d20\u51cf\u5c0f\u4e3a 2 \u3002\n3. \u5c06\u7b2c\u4e09\u4e2a\u5143\u7d20\u51cf\u5c0f\u4e3a 3 \u3002\n\u73b0\u5728 arr = [1,2,3] \uff0c\u6ee1\u8db3\u6240\u6709\u6761\u4ef6\u3002\narr \u4e2d\u6700\u5927\u5143\u7d20\u4e3a 3 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [1,2,3,4,5]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u6570\u7ec4\u5df2\u7ecf\u6ee1\u8db3\u6240\u6709\u6761\u4ef6\uff0c\u6700\u5927\u5143\u7d20\u4e3a 5 \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= arr.length <= 105
    • \n\t
    • 1 <= arr[i] <= 109
    • \n
    \n", "tags_en": ["Greedy", "Sort"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6392\u5e8f"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maximumElementAfterDecrementingAndRearranging(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maximumElementAfterDecrementingAndRearranging(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximumElementAfterDecrementingAndRearranging(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximumElementAfterDecrementingAndRearranging(self, arr: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maximumElementAfterDecrementingAndRearranging(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaximumElementAfterDecrementingAndRearranging(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar maximumElementAfterDecrementingAndRearranging = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef maximum_element_after_decrementing_and_rearranging(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximumElementAfterDecrementingAndRearranging(_ arr: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximumElementAfterDecrementingAndRearranging(arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximumElementAfterDecrementingAndRearranging(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximumElementAfterDecrementingAndRearranging(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximum_element_after_decrementing_and_rearranging(arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function maximumElementAfterDecrementingAndRearranging($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximumElementAfterDecrementingAndRearranging(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximum-element-after-decrementing-and-rearranging arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1846](https://leetcode-cn.com/problems/maximum-element-after-decreasing-and-rearranging)", "[\u51cf\u5c0f\u548c\u91cd\u65b0\u6392\u5217\u6570\u7ec4\u540e\u7684\u6700\u5927\u5143\u7d20](/solution/1800-1899/1846.Maximum%20Element%20After%20Decreasing%20and%20Rearranging/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6392\u5e8f`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1846](https://leetcode.com/problems/maximum-element-after-decreasing-and-rearranging)", "[Maximum Element After Decreasing and Rearranging](/solution/1800-1899/1846.Maximum%20Element%20After%20Decreasing%20and%20Rearranging/README_EN.md)", "`Greedy`,`Sort`", "Medium", ""]}, {"question_id": "1955", "frontend_question_id": "1845", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/seat-reservation-manager", "url_en": "https://leetcode.com/problems/seat-reservation-manager", "relative_path_cn": "/solution/1800-1899/1845.Seat%20Reservation%20Manager/README.md", "relative_path_en": "/solution/1800-1899/1845.Seat%20Reservation%20Manager/README_EN.md", "title_cn": "\u5ea7\u4f4d\u9884\u7ea6\u7ba1\u7406\u7cfb\u7edf", "title_en": "Seat Reservation Manager", "question_title_slug": "seat-reservation-manager", "content_en": "

    Design a system that manages the reservation state of n seats that are numbered from 1 to n.

    \n\n

    Implement the SeatManager class:

    \n\n
      \n\t
    • SeatManager(int n) Initializes a SeatManager object that will manage n seats numbered from 1 to n. All seats are initially available.
    • \n\t
    • int reserve() Fetches the smallest-numbered unreserved seat, reserves it, and returns its number.
    • \n\t
    • void unreserve(int seatNumber) Unreserves the seat with the given seatNumber.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["SeatManager", "reserve", "reserve", "unreserve", "reserve", "reserve", "reserve", "reserve", "unreserve"]\n[[5], [], [], [2], [], [], [], [], [5]]\nOutput\n[null, 1, 2, null, 2, 3, 4, 5, null]\n\nExplanation\nSeatManager seatManager = new SeatManager(5); // Initializes a SeatManager with 5 seats.\nseatManager.reserve();    // All seats are available, so return the lowest numbered seat, which is 1.\nseatManager.reserve();    // The available seats are [2,3,4,5], so return the lowest of them, which is 2.\nseatManager.unreserve(2); // Unreserve seat 2, so now the available seats are [2,3,4,5].\nseatManager.reserve();    // The available seats are [2,3,4,5], so return the lowest of them, which is 2.\nseatManager.reserve();    // The available seats are [3,4,5], so return the lowest of them, which is 3.\nseatManager.reserve();    // The available seats are [4,5], so return the lowest of them, which is 4.\nseatManager.reserve();    // The only available seat is seat 5, so return 5.\nseatManager.unreserve(5); // Unreserve seat 5, so now the available seats are [5].\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 105
    • \n\t
    • 1 <= seatNumber <= n
    • \n\t
    • For each call to reserve, it is guaranteed that there will be at least one unreserved seat.
    • \n\t
    • For each call to unreserve, it is guaranteed that seatNumber will be reserved.
    • \n\t
    • At most 105 calls in total will be made to reserve and unreserve.
    • \n
    \n", "content_cn": "

    \u8bf7\u4f60\u8bbe\u8ba1\u4e00\u4e2a\u7ba1\u7406 n\u00a0\u4e2a\u5ea7\u4f4d\u9884\u7ea6\u7684\u7cfb\u7edf\uff0c\u5ea7\u4f4d\u7f16\u53f7\u4ece\u00a01\u00a0\u5230\u00a0n\u00a0\u3002

    \n\n

    \u8bf7\u4f60\u5b9e\u73b0\u00a0SeatManager\u00a0\u7c7b\uff1a

    \n\n
      \n\t
    • SeatManager(int n)\u00a0\u521d\u59cb\u5316\u4e00\u4e2a\u00a0SeatManager\u00a0\u5bf9\u8c61\uff0c\u5b83\u7ba1\u7406\u4ece 1\u00a0\u5230 n\u00a0\u7f16\u53f7\u7684\u00a0n\u00a0\u4e2a\u5ea7\u4f4d\u3002\u6240\u6709\u5ea7\u4f4d\u521d\u59cb\u90fd\u662f\u53ef\u9884\u7ea6\u7684\u3002
    • \n\t
    • int reserve()\u00a0\u8fd4\u56de\u53ef\u4ee5\u9884\u7ea6\u5ea7\u4f4d\u7684\u00a0\u6700\u5c0f\u7f16\u53f7\u00a0\uff0c\u6b64\u5ea7\u4f4d\u53d8\u4e3a\u4e0d\u53ef\u9884\u7ea6\u3002
    • \n\t
    • void unreserve(int seatNumber)\u00a0\u5c06\u7ed9\u5b9a\u7f16\u53f7\u00a0seatNumber\u00a0\u5bf9\u5e94\u7684\u5ea7\u4f4d\u53d8\u6210\u53ef\u4ee5\u9884\u7ea6\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a\n[\"SeatManager\", \"reserve\", \"reserve\", \"unreserve\", \"reserve\", \"reserve\", \"reserve\", \"reserve\", \"unreserve\"]\n[[5], [], [], [2], [], [], [], [], [5]]\n\u8f93\u51fa\uff1a\n[null, 1, 2, null, 2, 3, 4, 5, null]\n\n\u89e3\u91ca\uff1a\nSeatManager seatManager = new SeatManager(5); // \u521d\u59cb\u5316 SeatManager \uff0c\u6709 5 \u4e2a\u5ea7\u4f4d\u3002\nseatManager.reserve();    // \u6240\u6709\u5ea7\u4f4d\u90fd\u53ef\u4ee5\u9884\u7ea6\uff0c\u6240\u4ee5\u8fd4\u56de\u6700\u5c0f\u7f16\u53f7\u7684\u5ea7\u4f4d\uff0c\u4e5f\u5c31\u662f 1 \u3002\nseatManager.reserve();    // \u53ef\u4ee5\u9884\u7ea6\u7684\u5ea7\u4f4d\u4e3a [2,3,4,5] \uff0c\u8fd4\u56de\u6700\u5c0f\u7f16\u53f7\u7684\u5ea7\u4f4d\uff0c\u4e5f\u5c31\u662f 2 \u3002\nseatManager.unreserve(2); // \u5c06\u5ea7\u4f4d 2 \u53d8\u4e3a\u53ef\u4ee5\u9884\u7ea6\uff0c\u73b0\u5728\u53ef\u9884\u7ea6\u7684\u5ea7\u4f4d\u4e3a [2,3,4,5] \u3002\nseatManager.reserve();    // \u53ef\u4ee5\u9884\u7ea6\u7684\u5ea7\u4f4d\u4e3a [2,3,4,5] \uff0c\u8fd4\u56de\u6700\u5c0f\u7f16\u53f7\u7684\u5ea7\u4f4d\uff0c\u4e5f\u5c31\u662f 2 \u3002\nseatManager.reserve();    // \u53ef\u4ee5\u9884\u7ea6\u7684\u5ea7\u4f4d\u4e3a [3,4,5] \uff0c\u8fd4\u56de\u6700\u5c0f\u7f16\u53f7\u7684\u5ea7\u4f4d\uff0c\u4e5f\u5c31\u662f 3 \u3002\nseatManager.reserve();    // \u53ef\u4ee5\u9884\u7ea6\u7684\u5ea7\u4f4d\u4e3a [4,5] \uff0c\u8fd4\u56de\u6700\u5c0f\u7f16\u53f7\u7684\u5ea7\u4f4d\uff0c\u4e5f\u5c31\u662f 4 \u3002\nseatManager.reserve();    // \u552f\u4e00\u53ef\u4ee5\u9884\u7ea6\u7684\u662f\u5ea7\u4f4d 5 \uff0c\u6240\u4ee5\u8fd4\u56de 5 \u3002\nseatManager.unreserve(5); // \u5c06\u5ea7\u4f4d 5 \u53d8\u4e3a\u53ef\u4ee5\u9884\u7ea6\uff0c\u73b0\u5728\u53ef\u9884\u7ea6\u7684\u5ea7\u4f4d\u4e3a [5] \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 105
    • \n\t
    • 1 <= seatNumber <= n
    • \n\t
    • \u6bcf\u4e00\u6b21\u5bf9\u00a0reserve\u00a0\u7684\u8c03\u7528\uff0c\u9898\u76ee\u4fdd\u8bc1\u81f3\u5c11\u5b58\u5728\u4e00\u4e2a\u53ef\u4ee5\u9884\u7ea6\u7684\u5ea7\u4f4d\u3002
    • \n\t
    • \u6bcf\u4e00\u6b21\u5bf9\u00a0unreserve\u00a0\u7684\u8c03\u7528\uff0c\u9898\u76ee\u4fdd\u8bc1\u00a0seatNumber\u00a0\u5728\u8c03\u7528\u51fd\u6570\u524d\u90fd\u662f\u88ab\u9884\u7ea6\u72b6\u6001\u3002
    • \n\t
    • \u5bf9\u00a0reserve \u548c\u00a0unreserve\u00a0\u7684\u8c03\u7528\u00a0\u603b\u5171\u00a0\u4e0d\u8d85\u8fc7\u00a0105\u00a0\u6b21\u3002
    • \n
    \n", "tags_en": ["Heap", "Design"], "tags_cn": ["\u5806", "\u8bbe\u8ba1"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class SeatManager {\npublic:\n SeatManager(int n) {\n\n }\n \n int reserve() {\n\n }\n \n void unreserve(int seatNumber) {\n\n }\n};\n\n/**\n * Your SeatManager object will be instantiated and called as such:\n * SeatManager* obj = new SeatManager(n);\n * int param_1 = obj->reserve();\n * obj->unreserve(seatNumber);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class SeatManager {\n\n public SeatManager(int n) {\n\n }\n \n public int reserve() {\n\n }\n \n public void unreserve(int seatNumber) {\n\n }\n}\n\n/**\n * Your SeatManager object will be instantiated and called as such:\n * SeatManager obj = new SeatManager(n);\n * int param_1 = obj.reserve();\n * obj.unreserve(seatNumber);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class SeatManager(object):\n\n def __init__(self, n):\n \"\"\"\n :type n: int\n \"\"\"\n\n\n def reserve(self):\n \"\"\"\n :rtype: int\n \"\"\"\n\n\n def unreserve(self, seatNumber):\n \"\"\"\n :type seatNumber: int\n :rtype: None\n \"\"\"\n\n\n\n# Your SeatManager object will be instantiated and called as such:\n# obj = SeatManager(n)\n# param_1 = obj.reserve()\n# obj.unreserve(seatNumber)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class SeatManager:\n\n def __init__(self, n: int):\n\n\n def reserve(self) -> int:\n\n\n def unreserve(self, seatNumber: int) -> None:\n\n\n\n# Your SeatManager object will be instantiated and called as such:\n# obj = SeatManager(n)\n# param_1 = obj.reserve()\n# obj.unreserve(seatNumber)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} SeatManager;\n\n\nSeatManager* seatManagerCreate(int n) {\n\n}\n\nint seatManagerReserve(SeatManager* obj) {\n\n}\n\nvoid seatManagerUnreserve(SeatManager* obj, int seatNumber) {\n\n}\n\nvoid seatManagerFree(SeatManager* obj) {\n\n}\n\n/**\n * Your SeatManager struct will be instantiated and called as such:\n * SeatManager* obj = seatManagerCreate(n);\n * int param_1 = seatManagerReserve(obj);\n \n * seatManagerUnreserve(obj, seatNumber);\n \n * seatManagerFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class SeatManager {\n\n public SeatManager(int n) {\n\n }\n \n public int Reserve() {\n\n }\n \n public void Unreserve(int seatNumber) {\n\n }\n}\n\n/**\n * Your SeatManager object will be instantiated and called as such:\n * SeatManager obj = new SeatManager(n);\n * int param_1 = obj.Reserve();\n * obj.Unreserve(seatNumber);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n */\nvar SeatManager = function(n) {\n\n};\n\n/**\n * @return {number}\n */\nSeatManager.prototype.reserve = function() {\n\n};\n\n/** \n * @param {number} seatNumber\n * @return {void}\n */\nSeatManager.prototype.unreserve = function(seatNumber) {\n\n};\n\n/**\n * Your SeatManager object will be instantiated and called as such:\n * var obj = new SeatManager(n)\n * var param_1 = obj.reserve()\n * obj.unreserve(seatNumber)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class SeatManager\n\n=begin\n :type n: Integer\n=end\n def initialize(n)\n\n end\n\n\n=begin\n :rtype: Integer\n=end\n def reserve()\n\n end\n\n\n=begin\n :type seat_number: Integer\n :rtype: Void\n=end\n def unreserve(seat_number)\n\n end\n\n\nend\n\n# Your SeatManager object will be instantiated and called as such:\n# obj = SeatManager.new(n)\n# param_1 = obj.reserve()\n# obj.unreserve(seat_number)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass SeatManager {\n\n init(_ n: Int) {\n\n }\n \n func reserve() -> Int {\n\n }\n \n func unreserve(_ seatNumber: Int) {\n\n }\n}\n\n/**\n * Your SeatManager object will be instantiated and called as such:\n * let obj = SeatManager(n)\n * let ret_1: Int = obj.reserve()\n * obj.unreserve(seatNumber)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type SeatManager struct {\n\n}\n\n\nfunc Constructor(n int) SeatManager {\n\n}\n\n\nfunc (this *SeatManager) Reserve() int {\n\n}\n\n\nfunc (this *SeatManager) Unreserve(seatNumber int) {\n\n}\n\n\n/**\n * Your SeatManager object will be instantiated and called as such:\n * obj := Constructor(n);\n * param_1 := obj.Reserve();\n * obj.Unreserve(seatNumber);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class SeatManager(_n: Int) {\n\n def reserve(): Int = {\n\n }\n\n def unreserve(seatNumber: Int) {\n\n }\n\n}\n\n/**\n * Your SeatManager object will be instantiated and called as such:\n * var obj = new SeatManager(n)\n * var param_1 = obj.reserve()\n * obj.unreserve(seatNumber)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class SeatManager(n: Int) {\n\n fun reserve(): Int {\n\n }\n\n fun unreserve(seatNumber: Int) {\n\n }\n\n}\n\n/**\n * Your SeatManager object will be instantiated and called as such:\n * var obj = SeatManager(n)\n * var param_1 = obj.reserve()\n * obj.unreserve(seatNumber)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct SeatManager {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl SeatManager {\n\n fn new(n: i32) -> Self {\n\n }\n \n fn reserve(&self) -> i32 {\n\n }\n \n fn unreserve(&self, seat_number: i32) {\n\n }\n}\n\n/**\n * Your SeatManager object will be instantiated and called as such:\n * let obj = SeatManager::new(n);\n * let ret_1: i32 = obj.reserve();\n * obj.unreserve(seatNumber);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class SeatManager {\n /**\n * @param Integer $n\n */\n function __construct($n) {\n\n }\n\n /**\n * @return Integer\n */\n function reserve() {\n\n }\n\n /**\n * @param Integer $seatNumber\n * @return NULL\n */\n function unreserve($seatNumber) {\n\n }\n}\n\n/**\n * Your SeatManager object will be instantiated and called as such:\n * $obj = SeatManager($n);\n * $ret_1 = $obj->reserve();\n * $obj->unreserve($seatNumber);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class SeatManager {\n constructor(n: number) {\n\n }\n\n reserve(): number {\n\n }\n\n unreserve(seatNumber: number): void {\n\n }\n}\n\n/**\n * Your SeatManager object will be instantiated and called as such:\n * var obj = new SeatManager(n)\n * var param_1 = obj.reserve()\n * obj.unreserve(seatNumber)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define seat-manager%\n (class object%\n (super-new)\n\n ; n : exact-integer?\n (init-field\n n)\n \n ; reserve : -> exact-integer?\n (define/public (reserve)\n\n )\n ; unreserve : exact-integer? -> void?\n (define/public (unreserve seatNumber)\n\n )))\n\n;; Your seat-manager% object will be instantiated and called as such:\n;; (define obj (new seat-manager% [n n]))\n;; (define param_1 (send obj reserve))\n;; (send obj unreserve seat-number)", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1845](https://leetcode-cn.com/problems/seat-reservation-manager)", "[\u5ea7\u4f4d\u9884\u7ea6\u7ba1\u7406\u7cfb\u7edf](/solution/1800-1899/1845.Seat%20Reservation%20Manager/README.md)", "`\u5806`,`\u8bbe\u8ba1`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1845](https://leetcode.com/problems/seat-reservation-manager)", "[Seat Reservation Manager](/solution/1800-1899/1845.Seat%20Reservation%20Manager/README_EN.md)", "`Heap`,`Design`", "Medium", ""]}, {"question_id": "1954", "frontend_question_id": "1844", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/replace-all-digits-with-characters", "url_en": "https://leetcode.com/problems/replace-all-digits-with-characters", "relative_path_cn": "/solution/1800-1899/1844.Replace%20All%20Digits%20with%20Characters/README.md", "relative_path_en": "/solution/1800-1899/1844.Replace%20All%20Digits%20with%20Characters/README_EN.md", "title_cn": "\u5c06\u6240\u6709\u6570\u5b57\u7528\u5b57\u7b26\u66ff\u6362", "title_en": "Replace All Digits with Characters", "question_title_slug": "replace-all-digits-with-characters", "content_en": "

    You are given a 0-indexed string s that has lowercase English letters in its even indices and digits in its odd indices.

    \n\n

    There is a function shift(c, x), where c is a character and x is a digit, that returns the xth character after c.

    \n\n
      \n\t
    • For example, shift('a', 5) = 'f' and shift('x', 0) = 'x'.
    • \n
    \n\n

    For every odd index i, you want to replace the digit s[i] with shift(s[i-1], s[i]).

    \n\n

    Return s after replacing all digits. It is guaranteed that shift(s[i-1], s[i]) will never exceed 'z'.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "a1c1e1"\nOutput: "abcdef"\nExplanation: The digits are replaced as follows:\n- s[1] -> shift('a',1) = 'b'\n- s[3] -> shift('c',1) = 'd'\n- s[5] -> shift('e',1) = 'f'
    \n\n

    Example 2:

    \n\n
    \nInput: s = "a1b2c3d4e"\nOutput: "abbdcfdhe"\nExplanation: The digits are replaced as follows:\n- s[1] -> shift('a',1) = 'b'\n- s[3] -> shift('b',2) = 'd'\n- s[5] -> shift('c',3) = 'f'\n- s[7] -> shift('d',4) = 'h'
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 100
    • \n\t
    • s consists only of lowercase English letters and digits.
    • \n\t
    • shift(s[i-1], s[i]) <= 'z' for all odd indices i.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u4e0b\u6807\u4ece 0\u00a0\u5f00\u59cb\u7684\u5b57\u7b26\u4e32 s\u00a0\uff0c\u5b83\u7684 \u5076\u6570 \u4e0b\u6807\u5904\u4e3a\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\uff0c\u5947\u6570\u00a0\u4e0b\u6807\u5904\u4e3a\u6570\u5b57\u3002

    \n\n

    \u5b9a\u4e49\u4e00\u4e2a\u51fd\u6570\u00a0shift(c, x)\u00a0\uff0c\u5176\u4e2d\u00a0c\u00a0\u662f\u4e00\u4e2a\u5b57\u7b26\u4e14\u00a0x\u00a0\u662f\u4e00\u4e2a\u6570\u5b57\uff0c\u51fd\u6570\u8fd4\u56de\u5b57\u6bcd\u8868\u4e2d\u00a0c\u00a0\u540e\u9762\u7b2c x\u00a0\u4e2a\u5b57\u7b26\u3002

    \n\n
      \n\t
    • \u6bd4\u65b9\u8bf4\uff0cshift('a', 5) = 'f'\u00a0\u548c\u00a0shift('x', 0) = 'x'\u00a0\u3002
    • \n
    \n\n

    \u5bf9\u4e8e\u6bcf\u4e2a \u5947\u6570\u00a0\u4e0b\u6807\u00a0i\u00a0\uff0c\u4f60\u9700\u8981\u5c06\u6570\u5b57\u00a0s[i] \u7528\u00a0shift(s[i-1], s[i])\u00a0\u66ff\u6362\u3002

    \n\n

    \u8bf7\u4f60\u66ff\u6362\u6240\u6709\u6570\u5b57\u4ee5\u540e\uff0c\u5c06\u5b57\u7b26\u4e32 s\u00a0\u8fd4\u56de\u3002\u9898\u76ee \u4fdd\u8bc1\u00a0shift(s[i-1], s[i])\u00a0\u4e0d\u4f1a\u8d85\u8fc7 'z'\u00a0\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1as = \"a1c1e1\"\n\u8f93\u51fa\uff1a\"abcdef\"\n\u89e3\u91ca\uff1a\u6570\u5b57\u88ab\u66ff\u6362\u7ed3\u679c\u5982\u4e0b\uff1a\n- s[1] -> shift('a',1) = 'b'\n- s[3] -> shift('c',1) = 'd'\n- s[5] -> shift('e',1) = 'f'
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1as = \"a1b2c3d4e\"\n\u8f93\u51fa\uff1a\"abbdcfdhe\"\n\u89e3\u91ca\uff1a\u6570\u5b57\u88ab\u66ff\u6362\u7ed3\u679c\u5982\u4e0b\uff1a\n- s[1] -> shift('a',1) = 'b'\n- s[3] -> shift('b',2) = 'd'\n- s[5] -> shift('c',3) = 'f'\n- s[7] -> shift('d',4) = 'h'
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 100
    • \n\t
    • s\u00a0\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u548c\u6570\u5b57\u3002
    • \n\t
    • \u5bf9\u6240\u6709 \u5947\u6570 \u4e0b\u6807\u5904\u7684\u00a0i\u00a0\uff0c\u6ee1\u8db3\u00a0shift(s[i-1], s[i]) <= 'z'\u00a0\u3002
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string replaceDigits(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String replaceDigits(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def replaceDigits(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def replaceDigits(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * replaceDigits(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ReplaceDigits(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar replaceDigits = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef replace_digits(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func replaceDigits(_ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func replaceDigits(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def replaceDigits(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun replaceDigits(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn replace_digits(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function replaceDigits($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function replaceDigits(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (replace-digits s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1844](https://leetcode-cn.com/problems/replace-all-digits-with-characters)", "[\u5c06\u6240\u6709\u6570\u5b57\u7528\u5b57\u7b26\u66ff\u6362](/solution/1800-1899/1844.Replace%20All%20Digits%20with%20Characters/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1844](https://leetcode.com/problems/replace-all-digits-with-characters)", "[Replace All Digits with Characters](/solution/1800-1899/1844.Replace%20All%20Digits%20with%20Characters/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1953", "frontend_question_id": "1825", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/finding-mk-average", "url_en": "https://leetcode.com/problems/finding-mk-average", "relative_path_cn": "/solution/1800-1899/1825.Finding%20MK%20Average/README.md", "relative_path_en": "/solution/1800-1899/1825.Finding%20MK%20Average/README_EN.md", "title_cn": "\u6c42\u51fa MK \u5e73\u5747\u503c", "title_en": "Finding MK Average", "question_title_slug": "finding-mk-average", "content_en": "

    You are given two integers, m and k, and a stream of integers. You are tasked to implement a data structure that calculates the MKAverage for the stream.

    \n\n

    The MKAverage can be calculated using these steps:

    \n\n
      \n\t
    1. If the number of the elements in the stream is less than m you should consider the MKAverage to be -1. Otherwise, copy the last m elements of the stream to a separate container.
    2. \n\t
    3. Remove the smallest k elements and the largest k elements from the container.
    4. \n\t
    5. Calculate the average value for the rest of the elements rounded down to the nearest integer.
    6. \n
    \n\n

    Implement the MKAverage class:

    \n\n
      \n\t
    • MKAverage(int m, int k) Initializes the MKAverage object with an empty stream and the two integers m and k.
    • \n\t
    • void addElement(int num) Inserts a new element num into the stream.
    • \n\t
    • int calculateMKAverage() Calculates and returns the MKAverage for the current stream rounded down to the nearest integer.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["MKAverage", "addElement", "addElement", "calculateMKAverage", "addElement", "calculateMKAverage", "addElement", "addElement", "addElement", "calculateMKAverage"]\n[[3, 1], [3], [1], [], [10], [], [5], [5], [5], []]\nOutput\n[null, null, null, -1, null, 3, null, null, null, 5]\n\nExplanation\nMKAverage obj = new MKAverage(3, 1); \nobj.addElement(3);        // current elements are [3]\nobj.addElement(1);        // current elements are [3,1]\nobj.calculateMKAverage(); // return -1, because m = 3 and only 2 elements exist.\nobj.addElement(10);       // current elements are [3,1,10]\nobj.calculateMKAverage(); // The last 3 elements are [3,1,10].\n                          // After removing smallest and largest 1 element the container will be [3].\n                          // The average of [3] equals 3/1 = 3, return 3\nobj.addElement(5);        // current elements are [3,1,10,5]\nobj.addElement(5);        // current elements are [3,1,10,5,5]\nobj.addElement(5);        // current elements are [3,1,10,5,5,5]\nobj.calculateMKAverage(); // The last 3 elements are [5,5,5].\n                          // After removing smallest and largest 1 element the container will be [5].\n                          // The average of [5] equals 5/1 = 5, return 5\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 3 <= m <= 105
    • \n\t
    • 1 <= k*2 < m
    • \n\t
    • 1 <= num <= 105
    • \n\t
    • At most 105 calls will be made to addElement and calculateMKAverage.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u6574\u6570\u00a0m\u00a0\u548c\u00a0k\u00a0\uff0c\u4ee5\u53ca\u6570\u636e\u6d41\u5f62\u5f0f\u7684\u82e5\u5e72\u6574\u6570\u3002\u4f60\u9700\u8981\u5b9e\u73b0\u4e00\u4e2a\u6570\u636e\u7ed3\u6784\uff0c\u8ba1\u7b97\u8fd9\u4e2a\u6570\u636e\u6d41\u7684 MK \u5e73\u5747\u503c\u00a0\u3002

    \n\n

    MK \u5e73\u5747\u503c\u00a0\u6309\u7167\u5982\u4e0b\u6b65\u9aa4\u8ba1\u7b97\uff1a

    \n\n
      \n\t
    1. \u5982\u679c\u6570\u636e\u6d41\u4e2d\u7684\u6574\u6570\u5c11\u4e8e m\u00a0\u4e2a\uff0cMK \u5e73\u5747\u503c\u00a0\u4e3a -1\u00a0\uff0c\u5426\u5219\u5c06\u6570\u636e\u6d41\u4e2d\u6700\u540e m\u00a0\u4e2a\u5143\u7d20\u62f7\u8d1d\u5230\u4e00\u4e2a\u72ec\u7acb\u7684\u5bb9\u5668\u4e2d\u3002
    2. \n\t
    3. \u4ece\u8fd9\u4e2a\u5bb9\u5668\u4e2d\u5220\u9664\u6700\u5c0f\u7684 k\u00a0\u4e2a\u6570\u548c\u6700\u5927\u7684 k\u00a0\u4e2a\u6570\u3002
    4. \n\t
    5. \u8ba1\u7b97\u5269\u4f59\u5143\u7d20\u7684\u5e73\u5747\u503c\uff0c\u5e76 \u5411\u4e0b\u53d6\u6574\u5230\u6700\u8fd1\u7684\u6574\u6570\u00a0\u3002
    6. \n
    \n\n

    \u8bf7\u4f60\u5b9e\u73b0\u00a0MKAverage\u00a0\u7c7b\uff1a

    \n\n
      \n\t
    • MKAverage(int m, int k)\u00a0\u7528\u4e00\u4e2a\u7a7a\u7684\u6570\u636e\u6d41\u548c\u4e24\u4e2a\u6574\u6570 m\u00a0\u548c k\u00a0\u521d\u59cb\u5316\u00a0MKAverage\u00a0\u5bf9\u8c61\u3002
    • \n\t
    • void addElement(int num)\u00a0\u5f80\u6570\u636e\u6d41\u4e2d\u63d2\u5165\u4e00\u4e2a\u65b0\u7684\u5143\u7d20\u00a0num\u00a0\u3002
    • \n\t
    • int calculateMKAverage()\u00a0\u5bf9\u5f53\u524d\u7684\u6570\u636e\u6d41\u8ba1\u7b97\u5e76\u8fd4\u56de MK \u5e73\u5747\u6570\u00a0\uff0c\u7ed3\u679c\u9700 \u5411\u4e0b\u53d6\u6574\u5230\u6700\u8fd1\u7684\u6574\u6570 \u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\n[\"MKAverage\", \"addElement\", \"addElement\", \"calculateMKAverage\", \"addElement\", \"calculateMKAverage\", \"addElement\", \"addElement\", \"addElement\", \"calculateMKAverage\"]\n[[3, 1], [3], [1], [], [10], [], [5], [5], [5], []]\n\u8f93\u51fa\uff1a\n[null, null, null, -1, null, 3, null, null, null, 5]\n\n\u89e3\u91ca\uff1a\nMKAverage obj = new MKAverage(3, 1); \nobj.addElement(3);        // \u5f53\u524d\u5143\u7d20\u4e3a [3]\nobj.addElement(1);        // \u5f53\u524d\u5143\u7d20\u4e3a [3,1]\nobj.calculateMKAverage(); // \u8fd4\u56de -1 \uff0c\u56e0\u4e3a m = 3 \uff0c\u4f46\u6570\u636e\u6d41\u4e2d\u53ea\u6709 2 \u4e2a\u5143\u7d20\nobj.addElement(10);       // \u5f53\u524d\u5143\u7d20\u4e3a [3,1,10]\nobj.calculateMKAverage(); // \u6700\u540e 3 \u4e2a\u5143\u7d20\u4e3a [3,1,10]\n                          // \u5220\u9664\u6700\u5c0f\u4ee5\u53ca\u6700\u5927\u7684 1 \u4e2a\u5143\u7d20\u540e\uff0c\u5bb9\u5668\u4e3a [3]\n                          // [3] \u7684\u5e73\u5747\u503c\u7b49\u4e8e 3/1 = 3 \uff0c\u6545\u8fd4\u56de 3\nobj.addElement(5);        // \u5f53\u524d\u5143\u7d20\u4e3a [3,1,10,5]\nobj.addElement(5);        // \u5f53\u524d\u5143\u7d20\u4e3a [3,1,10,5,5]\nobj.addElement(5);        // \u5f53\u524d\u5143\u7d20\u4e3a [3,1,10,5,5,5]\nobj.calculateMKAverage(); // \u6700\u540e 3 \u4e2a\u5143\u7d20\u4e3a [5,5,5]\n                          // \u5220\u9664\u6700\u5c0f\u4ee5\u53ca\u6700\u5927\u7684 1 \u4e2a\u5143\u7d20\u540e\uff0c\u5bb9\u5668\u4e3a [5]\n                          // [5] \u7684\u5e73\u5747\u503c\u7b49\u4e8e 5/1 = 5 \uff0c\u6545\u8fd4\u56de 5\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 3 <= m <= 105
    • \n\t
    • 1 <= k*2 < m
    • \n\t
    • 1 <= num <= 105
    • \n\t
    • addElement \u4e0e\u00a0calculateMKAverage\u00a0\u603b\u64cd\u4f5c\u6b21\u6570\u4e0d\u8d85\u8fc7 105 \u6b21\u3002
    • \n
    \n", "tags_en": ["Heap", "Design", "Queue"], "tags_cn": ["\u5806", "\u8bbe\u8ba1", "\u961f\u5217"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class MKAverage {\npublic:\n MKAverage(int m, int k) {\n\n }\n \n void addElement(int num) {\n\n }\n \n int calculateMKAverage() {\n\n }\n};\n\n/**\n * Your MKAverage object will be instantiated and called as such:\n * MKAverage* obj = new MKAverage(m, k);\n * obj->addElement(num);\n * int param_2 = obj->calculateMKAverage();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class MKAverage {\n\n public MKAverage(int m, int k) {\n\n }\n \n public void addElement(int num) {\n\n }\n \n public int calculateMKAverage() {\n\n }\n}\n\n/**\n * Your MKAverage object will be instantiated and called as such:\n * MKAverage obj = new MKAverage(m, k);\n * obj.addElement(num);\n * int param_2 = obj.calculateMKAverage();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class MKAverage(object):\n\n def __init__(self, m, k):\n \"\"\"\n :type m: int\n :type k: int\n \"\"\"\n\n\n def addElement(self, num):\n \"\"\"\n :type num: int\n :rtype: None\n \"\"\"\n\n\n def calculateMKAverage(self):\n \"\"\"\n :rtype: int\n \"\"\"\n\n\n\n# Your MKAverage object will be instantiated and called as such:\n# obj = MKAverage(m, k)\n# obj.addElement(num)\n# param_2 = obj.calculateMKAverage()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class MKAverage:\n\n def __init__(self, m: int, k: int):\n\n\n def addElement(self, num: int) -> None:\n\n\n def calculateMKAverage(self) -> int:\n\n\n\n# Your MKAverage object will be instantiated and called as such:\n# obj = MKAverage(m, k)\n# obj.addElement(num)\n# param_2 = obj.calculateMKAverage()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} MKAverage;\n\n\nMKAverage* mKAverageCreate(int m, int k) {\n\n}\n\nvoid mKAverageAddElement(MKAverage* obj, int num) {\n\n}\n\nint mKAverageCalculateMKAverage(MKAverage* obj) {\n\n}\n\nvoid mKAverageFree(MKAverage* obj) {\n\n}\n\n/**\n * Your MKAverage struct will be instantiated and called as such:\n * MKAverage* obj = mKAverageCreate(m, k);\n * mKAverageAddElement(obj, num);\n \n * int param_2 = mKAverageCalculateMKAverage(obj);\n \n * mKAverageFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class MKAverage {\n\n public MKAverage(int m, int k) {\n\n }\n \n public void AddElement(int num) {\n\n }\n \n public int CalculateMKAverage() {\n\n }\n}\n\n/**\n * Your MKAverage object will be instantiated and called as such:\n * MKAverage obj = new MKAverage(m, k);\n * obj.AddElement(num);\n * int param_2 = obj.CalculateMKAverage();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} m\n * @param {number} k\n */\nvar MKAverage = function(m, k) {\n\n};\n\n/** \n * @param {number} num\n * @return {void}\n */\nMKAverage.prototype.addElement = function(num) {\n\n};\n\n/**\n * @return {number}\n */\nMKAverage.prototype.calculateMKAverage = function() {\n\n};\n\n/**\n * Your MKAverage object will be instantiated and called as such:\n * var obj = new MKAverage(m, k)\n * obj.addElement(num)\n * var param_2 = obj.calculateMKAverage()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class MKAverage\n\n=begin\n :type m: Integer\n :type k: Integer\n=end\n def initialize(m, k)\n\n end\n\n\n=begin\n :type num: Integer\n :rtype: Void\n=end\n def add_element(num)\n\n end\n\n\n=begin\n :rtype: Integer\n=end\n def calculate_mk_average()\n\n end\n\n\nend\n\n# Your MKAverage object will be instantiated and called as such:\n# obj = MKAverage.new(m, k)\n# obj.add_element(num)\n# param_2 = obj.calculate_mk_average()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass MKAverage {\n\n init(_ m: Int, _ k: Int) {\n\n }\n \n func addElement(_ num: Int) {\n\n }\n \n func calculateMKAverage() -> Int {\n\n }\n}\n\n/**\n * Your MKAverage object will be instantiated and called as such:\n * let obj = MKAverage(m, k)\n * obj.addElement(num)\n * let ret_2: Int = obj.calculateMKAverage()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type MKAverage struct {\n\n}\n\n\nfunc Constructor(m int, k int) MKAverage {\n\n}\n\n\nfunc (this *MKAverage) AddElement(num int) {\n\n}\n\n\nfunc (this *MKAverage) CalculateMKAverage() int {\n\n}\n\n\n/**\n * Your MKAverage object will be instantiated and called as such:\n * obj := Constructor(m, k);\n * obj.AddElement(num);\n * param_2 := obj.CalculateMKAverage();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class MKAverage(_m: Int, _k: Int) {\n\n def addElement(num: Int) {\n \n }\n\n def calculateMKAverage(): Int = {\n \n }\n\n}\n\n/**\n * Your MKAverage object will be instantiated and called as such:\n * var obj = new MKAverage(m, k)\n * obj.addElement(num)\n * var param_2 = obj.calculateMKAverage()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class MKAverage(m: Int, k: Int) {\n\n fun addElement(num: Int) {\n\n }\n\n fun calculateMKAverage(): Int {\n\n }\n\n}\n\n/**\n * Your MKAverage object will be instantiated and called as such:\n * var obj = MKAverage(m, k)\n * obj.addElement(num)\n * var param_2 = obj.calculateMKAverage()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct MKAverage {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl MKAverage {\n\n fn new(m: i32, k: i32) -> Self {\n\n }\n \n fn add_element(&self, num: i32) {\n\n }\n \n fn calculate_mk_average(&self) -> i32 {\n\n }\n}\n\n/**\n * Your MKAverage object will be instantiated and called as such:\n * let obj = MKAverage::new(m, k);\n * obj.add_element(num);\n * let ret_2: i32 = obj.calculate_mk_average();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class MKAverage {\n /**\n * @param Integer $m\n * @param Integer $k\n */\n function __construct($m, $k) {\n\n }\n\n /**\n * @param Integer $num\n * @return NULL\n */\n function addElement($num) {\n\n }\n\n /**\n * @return Integer\n */\n function calculateMKAverage() {\n\n }\n}\n\n/**\n * Your MKAverage object will be instantiated and called as such:\n * $obj = MKAverage($m, $k);\n * $obj->addElement($num);\n * $ret_2 = $obj->calculateMKAverage();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class MKAverage {\n constructor(m: number, k: number) {\n\n }\n\n addElement(num: number): void {\n\n }\n\n calculateMKAverage(): number {\n\n }\n}\n\n/**\n * Your MKAverage object will be instantiated and called as such:\n * var obj = new MKAverage(m, k)\n * obj.addElement(num)\n * var param_2 = obj.calculateMKAverage()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define mk-average%\n (class object%\n (super-new)\n\n ; m : exact-integer?\n\n ; k : exact-integer?\n (init-field\n m\n k)\n \n ; add-element : exact-integer? -> void?\n (define/public (add-element num)\n\n )\n ; calculate-mk-average : -> exact-integer?\n (define/public (calculate-mk-average)\n\n )))\n\n;; Your mk-average% object will be instantiated and called as such:\n;; (define obj (new mk-average% [m m] [k k]))\n;; (send obj add-element num)\n;; (define param_2 (send obj calculate-mk-average))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1825](https://leetcode-cn.com/problems/finding-mk-average)", "[\u6c42\u51fa MK \u5e73\u5747\u503c](/solution/1800-1899/1825.Finding%20MK%20Average/README.md)", "`\u5806`,`\u8bbe\u8ba1`,`\u961f\u5217`", "\u56f0\u96be", ""], "md_table_row_en": ["[1825](https://leetcode.com/problems/finding-mk-average)", "[Finding MK Average](/solution/1800-1899/1825.Finding%20MK%20Average/README_EN.md)", "`Heap`,`Design`,`Queue`", "Hard", ""]}, {"question_id": "1952", "frontend_question_id": "1824", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-sideway-jumps", "url_en": "https://leetcode.com/problems/minimum-sideway-jumps", "relative_path_cn": "/solution/1800-1899/1824.Minimum%20Sideway%20Jumps/README.md", "relative_path_en": "/solution/1800-1899/1824.Minimum%20Sideway%20Jumps/README_EN.md", "title_cn": "\u6700\u5c11\u4fa7\u8df3\u6b21\u6570", "title_en": "Minimum Sideway Jumps", "question_title_slug": "minimum-sideway-jumps", "content_en": "

    There is a 3 lane road of length n that consists of n + 1 points labeled from 0 to n. A frog starts at point 0 in the second lane and wants to jump to point n. However, there could be obstacles along the way.

    \n\n

    You are given an array obstacles of length n + 1 where each obstacles[i] (ranging from 0 to 3) describes an obstacle on the lane obstacles[i] at point i. If obstacles[i] == 0, there are no obstacles at point i. There will be at most one obstacle in the 3 lanes at each point.

    \n\n
      \n\t
    • For example, if obstacles[2] == 1, then there is an obstacle on lane 1 at point 2.
    • \n
    \n\n

    The frog can only travel from point i to point i + 1 on the same lane if there is not an obstacle on the lane at point i + 1. To avoid obstacles, the frog can also perform a side jump to jump to another lane (even if they are not adjacent) at the same point if there is no obstacle on the new lane.

    \n\n
      \n\t
    • For example, the frog can jump from lane 3 at point 3 to lane 1 at point 3.
    • \n
    \n\n

    Return the minimum number of side jumps the frog needs to reach any lane at point n starting from lane 2 at point 0.

    \n\n

    Note: There will be no obstacles on points 0 and n.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: obstacles = [0,1,2,3,0]\nOutput: 2 \nExplanation: The optimal solution is shown by the arrows above. There are 2 side jumps (red arrows).\nNote that the frog can jump over obstacles only when making side jumps (as shown at point 2).\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: obstacles = [0,1,1,3,3,0]\nOutput: 0\nExplanation: There are no obstacles on lane 2. No side jumps are required.\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: obstacles = [0,2,1,0,3,0]\nOutput: 2\nExplanation: The optimal solution is shown by the arrows above. There are 2 side jumps.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • obstacles.length == n + 1
    • \n\t
    • 1 <= n <= 5 * 105
    • \n\t
    • 0 <= obstacles[i] <= 3
    • \n\t
    • obstacles[0] == obstacles[n] == 0
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u4e3a\u00a0n\u00a0\u7684\u00a03 \u8dd1\u9053\u9053\u8def\u00a0\uff0c\u5b83\u603b\u5171\u5305\u542b\u00a0n + 1\u00a0\u4e2a\u00a0\u70b9\u00a0\uff0c\u7f16\u53f7\u4e3a\u00a00\u00a0\u5230\u00a0n\u00a0\u3002\u4e00\u53ea\u9752\u86d9\u4ece\u00a00\u00a0\u53f7\u70b9\u7b2c\u4e8c\u6761\u8dd1\u9053\u00a0\u51fa\u53d1\u00a0\uff0c\u5b83\u60f3\u8981\u8df3\u5230\u70b9\u00a0n\u00a0\u5904\u3002\u7136\u800c\u9053\u8def\u4e0a\u53ef\u80fd\u6709\u4e00\u4e9b\u969c\u788d\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u4e3a n + 1\u00a0\u7684\u6570\u7ec4\u00a0obstacles\u00a0\uff0c\u5176\u4e2d\u00a0obstacles[i]\u00a0\uff08\u53d6\u503c\u8303\u56f4\u4ece 0 \u5230 3\uff09\u8868\u793a\u5728\u70b9 i\u00a0\u5904\u7684\u00a0obstacles[i]\u00a0\u8dd1\u9053\u4e0a\u6709\u4e00\u4e2a\u969c\u788d\u3002\u5982\u679c\u00a0obstacles[i] == 0\u00a0\uff0c\u90a3\u4e48\u70b9\u00a0i\u00a0\u5904\u6ca1\u6709\u969c\u788d\u3002\u4efb\u4f55\u4e00\u4e2a\u70b9\u7684\u4e09\u6761\u8dd1\u9053\u4e2d\u00a0\u6700\u591a\u6709\u4e00\u4e2a\u00a0\u969c\u788d\u3002

    \n\n
      \n\t
    • \u6bd4\u65b9\u8bf4\uff0c\u5982\u679c\u00a0obstacles[2] == 1\u00a0\uff0c\u90a3\u4e48\u8bf4\u660e\u5728\u70b9 2 \u5904\u8dd1\u9053 1 \u6709\u969c\u788d\u3002
    • \n
    \n\n

    \u8fd9\u53ea\u9752\u86d9\u4ece\u70b9 i\u00a0\u8df3\u5230\u70b9 i + 1\u00a0\u4e14\u8dd1\u9053\u4e0d\u53d8\u7684\u524d\u63d0\u662f\u70b9 i + 1\u00a0\u7684\u540c\u4e00\u8dd1\u9053\u4e0a\u6ca1\u6709\u969c\u788d\u3002\u4e3a\u4e86\u8eb2\u907f\u969c\u788d\uff0c\u8fd9\u53ea\u9752\u86d9\u4e5f\u53ef\u4ee5\u5728\u00a0\u540c\u4e00\u4e2a\u00a0\u70b9\u5904\u00a0\u4fa7\u8df3\u00a0\u5230 \u53e6\u5916\u4e00\u6761\u00a0\u8dd1\u9053\uff08\u8fd9\u4e24\u6761\u8dd1\u9053\u53ef\u4ee5\u4e0d\u76f8\u90bb\uff09\uff0c\u4f46\u524d\u63d0\u662f\u8df3\u8fc7\u53bb\u7684\u8dd1\u9053\u8be5\u70b9\u5904\u6ca1\u6709\u969c\u788d\u3002

    \n\n
      \n\t
    • \u6bd4\u65b9\u8bf4\uff0c\u8fd9\u53ea\u9752\u86d9\u53ef\u4ee5\u4ece\u70b9 3 \u5904\u7684\u8dd1\u9053 3 \u8df3\u5230\u70b9 3 \u5904\u7684\u8dd1\u9053 1 \u3002
    • \n
    \n\n

    \u8fd9\u53ea\u9752\u86d9\u4ece\u70b9 0 \u5904\u8dd1\u9053 2\u00a0\u51fa\u53d1\uff0c\u5e76\u60f3\u5230\u8fbe\u70b9 n\u00a0\u5904\u7684 \u4efb\u4e00\u8dd1\u9053 \uff0c\u8bf7\u4f60\u8fd4\u56de \u6700\u5c11\u4fa7\u8df3\u6b21\u6570\u00a0\u3002

    \n\n

    \u6ce8\u610f\uff1a\u70b9 0\u00a0\u5904\u548c\u70b9 n\u00a0\u5904\u7684\u4efb\u4e00\u8dd1\u9053\u90fd\u4e0d\u4f1a\u6709\u969c\u788d\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aobstacles = [0,1,2,3,0]\n\u8f93\u51fa\uff1a2 \n\u89e3\u91ca\uff1a\u6700\u4f18\u65b9\u6848\u5982\u4e0a\u56fe\u7bad\u5934\u6240\u793a\u3002\u603b\u5171\u6709 2 \u6b21\u4fa7\u8df3\uff08\u7ea2\u8272\u7bad\u5934\uff09\u3002\n\u6ce8\u610f\uff0c\u8fd9\u53ea\u9752\u86d9\u53ea\u6709\u5f53\u4fa7\u8df3\u65f6\u624d\u53ef\u4ee5\u8df3\u8fc7\u969c\u788d\uff08\u5982\u4e0a\u56fe\u70b9 2 \u5904\u6240\u793a\uff09\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aobstacles = [0,1,1,3,3,0]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u8dd1\u9053 2 \u6ca1\u6709\u4efb\u4f55\u969c\u788d\uff0c\u6240\u4ee5\u4e0d\u9700\u8981\u4efb\u4f55\u4fa7\u8df3\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aobstacles = [0,2,1,0,3,0]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6700\u4f18\u65b9\u6848\u5982\u4e0a\u56fe\u6240\u793a\u3002\u603b\u5171\u6709 2 \u6b21\u4fa7\u8df3\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • obstacles.length == n + 1
    • \n\t
    • 1 <= n <= 5 * 105
    • \n\t
    • 0 <= obstacles[i] <= 3
    • \n\t
    • obstacles[0] == obstacles[n] == 0
    • \n
    \n", "tags_en": ["Breadth-first Search", "Dynamic Programming"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minSideJumps(vector& obstacles) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minSideJumps(int[] obstacles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minSideJumps(self, obstacles):\n \"\"\"\n :type obstacles: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minSideJumps(self, obstacles: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minSideJumps(int* obstacles, int obstaclesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinSideJumps(int[] obstacles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} obstacles\n * @return {number}\n */\nvar minSideJumps = function(obstacles) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} obstacles\n# @return {Integer}\ndef min_side_jumps(obstacles)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minSideJumps(_ obstacles: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minSideJumps(obstacles []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minSideJumps(obstacles: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minSideJumps(obstacles: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_side_jumps(obstacles: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $obstacles\n * @return Integer\n */\n function minSideJumps($obstacles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minSideJumps(obstacles: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-side-jumps obstacles)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1824](https://leetcode-cn.com/problems/minimum-sideway-jumps)", "[\u6700\u5c11\u4fa7\u8df3\u6b21\u6570](/solution/1800-1899/1824.Minimum%20Sideway%20Jumps/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1824](https://leetcode.com/problems/minimum-sideway-jumps)", "[Minimum Sideway Jumps](/solution/1800-1899/1824.Minimum%20Sideway%20Jumps/README_EN.md)", "`Breadth-first Search`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "1951", "frontend_question_id": "1823", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-the-winner-of-the-circular-game", "url_en": "https://leetcode.com/problems/find-the-winner-of-the-circular-game", "relative_path_cn": "/solution/1800-1899/1823.Find%20the%20Winner%20of%20the%20Circular%20Game/README.md", "relative_path_en": "/solution/1800-1899/1823.Find%20the%20Winner%20of%20the%20Circular%20Game/README_EN.md", "title_cn": "\u627e\u51fa\u6e38\u620f\u7684\u83b7\u80dc\u8005", "title_en": "Find the Winner of the Circular Game", "question_title_slug": "find-the-winner-of-the-circular-game", "content_en": "

    There are n friends that are playing a game. The friends are sitting in a circle and are numbered from 1 to n in clockwise order. More formally, moving clockwise from the ith friend brings you to the (i+1)th friend for 1 <= i < n, and moving clockwise from the nth friend brings you to the 1st friend.

    \r\n\r\n

    The rules of the game are as follows:

    \r\n\r\n
      \r\n\t
    1. Start at the 1st friend.
    2. \r\n\t
    3. Count the next k friends in the clockwise direction including the friend you started at. The counting wraps around the circle and may count some friends more than once.
    4. \r\n\t
    5. The last friend you counted leaves the circle and loses the game.
    6. \r\n\t
    7. If there is still more than one friend in the circle, go back to step 2 starting from the friend immediately clockwise of the friend who just lost and repeat.
    8. \r\n\t
    9. Else, the last friend in the circle wins the game.
    10. \r\n
    \r\n\r\n

    Given the number of friends, n, and an integer k, return the winner of the game.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\"\"\r\n
    \r\nInput: n = 5, k = 2\r\nOutput: 3\r\nExplanation: Here are the steps of the game:\r\n1) Start at friend 1.\r\n2) Count 2 friends clockwise, which are friends 1 and 2.\r\n3) Friend 2 leaves the circle. Next start is friend 3.\r\n4) Count 2 friends clockwise, which are friends 3 and 4.\r\n5) Friend 4 leaves the circle. Next start is friend 5.\r\n6) Count 2 friends clockwise, which are friends 5 and 1.\r\n7) Friend 1 leaves the circle. Next start is friend 3.\r\n8) Count 2 friends clockwise, which are friends 3 and 5.\r\n9) Friend 5 leaves the circle. Only friend 3 is left, so they are the winner.
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: n = 6, k = 5\r\nOutput: 1\r\nExplanation: The friends leave in this order: 5, 4, 6, 2, 3. The winner is friend 1.\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= k <= n <= 500
    • \r\n
    ", "content_cn": "

    \u5171\u6709 n \u540d\u5c0f\u4f19\u4f34\u4e00\u8d77\u505a\u6e38\u620f\u3002\u5c0f\u4f19\u4f34\u4eec\u56f4\u6210\u4e00\u5708\uff0c\u6309 \u987a\u65f6\u9488\u987a\u5e8f \u4ece 1 \u5230 n \u7f16\u53f7\u3002\u786e\u5207\u5730\u8bf4\uff0c\u4ece\u7b2c i \u540d\u5c0f\u4f19\u4f34\u987a\u65f6\u9488\u79fb\u52a8\u4e00\u4f4d\u4f1a\u5230\u8fbe\u7b2c (i+1) \u540d\u5c0f\u4f19\u4f34\u7684\u4f4d\u7f6e\uff0c\u5176\u4e2d 1 <= i < n \uff0c\u4ece\u7b2c n \u540d\u5c0f\u4f19\u4f34\u987a\u65f6\u9488\u79fb\u52a8\u4e00\u4f4d\u4f1a\u56de\u5230\u7b2c 1 \u540d\u5c0f\u4f19\u4f34\u7684\u4f4d\u7f6e\u3002

    \n\n

    \u6e38\u620f\u9075\u5faa\u5982\u4e0b\u89c4\u5219\uff1a

    \n\n
      \n\t
    1. \u4ece\u7b2c 1 \u540d\u5c0f\u4f19\u4f34\u6240\u5728\u4f4d\u7f6e \u5f00\u59cb \u3002
    2. \n\t
    3. \u6cbf\u7740\u987a\u65f6\u9488\u65b9\u5411\u6570 k \u540d\u5c0f\u4f19\u4f34\uff0c\u8ba1\u6570\u65f6\u9700\u8981 \u5305\u542b \u8d77\u59cb\u65f6\u7684\u90a3\u4f4d\u5c0f\u4f19\u4f34\u3002\u9010\u4e2a\u7ed5\u5708\u8fdb\u884c\u8ba1\u6570\uff0c\u4e00\u4e9b\u5c0f\u4f19\u4f34\u53ef\u80fd\u4f1a\u88ab\u6570\u8fc7\u4e0d\u6b62\u4e00\u6b21\u3002
    4. \n\t
    5. \u4f60\u6570\u5230\u7684\u6700\u540e\u4e00\u540d\u5c0f\u4f19\u4f34\u9700\u8981\u79bb\u5f00\u5708\u5b50\uff0c\u5e76\u89c6\u4f5c\u8f93\u6389\u6e38\u620f\u3002
    6. \n\t
    7. \u5982\u679c\u5708\u5b50\u4e2d\u4ecd\u7136\u6709\u4e0d\u6b62\u4e00\u540d\u5c0f\u4f19\u4f34\uff0c\u4ece\u521a\u521a\u8f93\u6389\u7684\u5c0f\u4f19\u4f34\u7684 \u987a\u65f6\u9488\u4e0b\u4e00\u4f4d \u5c0f\u4f19\u4f34 \u5f00\u59cb\uff0c\u56de\u5230\u6b65\u9aa4 2 \u7ee7\u7eed\u6267\u884c\u3002
    8. \n\t
    9. \u5426\u5219\uff0c\u5708\u5b50\u4e2d\u6700\u540e\u4e00\u540d\u5c0f\u4f19\u4f34\u8d62\u5f97\u6e38\u620f\u3002
    10. \n
    \n\n

    \u7ed9\u4f60\u53c2\u4e0e\u6e38\u620f\u7684\u5c0f\u4f19\u4f34\u603b\u6570 n \uff0c\u548c\u4e00\u4e2a\u6574\u6570 k \uff0c\u8fd4\u56de\u6e38\u620f\u7684\u83b7\u80dc\u8005\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1an = 5, k = 2\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6e38\u620f\u8fd0\u884c\u6b65\u9aa4\u5982\u4e0b\uff1a\n1) \u4ece\u5c0f\u4f19\u4f34 1 \u5f00\u59cb\u3002\n2) \u987a\u65f6\u9488\u6570 2 \u540d\u5c0f\u4f19\u4f34\uff0c\u4e5f\u5c31\u662f\u5c0f\u4f19\u4f34 1 \u548c 2 \u3002\n3) \u5c0f\u4f19\u4f34 2 \u79bb\u5f00\u5708\u5b50\u3002\u4e0b\u4e00\u6b21\u4ece\u5c0f\u4f19\u4f34 3 \u5f00\u59cb\u3002\n4) \u987a\u65f6\u9488\u6570 2 \u540d\u5c0f\u4f19\u4f34\uff0c\u4e5f\u5c31\u662f\u5c0f\u4f19\u4f34 3 \u548c 4 \u3002\n5) \u5c0f\u4f19\u4f34 4 \u79bb\u5f00\u5708\u5b50\u3002\u4e0b\u4e00\u6b21\u4ece\u5c0f\u4f19\u4f34 5 \u5f00\u59cb\u3002\n6) \u987a\u65f6\u9488\u6570 2 \u540d\u5c0f\u4f19\u4f34\uff0c\u4e5f\u5c31\u662f\u5c0f\u4f19\u4f34 5 \u548c 1 \u3002\n7) \u5c0f\u4f19\u4f34 1 \u79bb\u5f00\u5708\u5b50\u3002\u4e0b\u4e00\u6b21\u4ece\u5c0f\u4f19\u4f34 3 \u5f00\u59cb\u3002\n8) \u987a\u65f6\u9488\u6570 2 \u540d\u5c0f\u4f19\u4f34\uff0c\u4e5f\u5c31\u662f\u5c0f\u4f19\u4f34 3 \u548c 5 \u3002\n9) \u5c0f\u4f19\u4f34 5 \u79bb\u5f00\u5708\u5b50\u3002\u53ea\u5269\u4e0b\u5c0f\u4f19\u4f34 3 \u3002\u6240\u4ee5\u5c0f\u4f19\u4f34 3 \u662f\u6e38\u620f\u7684\u83b7\u80dc\u8005\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 6, k = 5\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u5c0f\u4f19\u4f34\u79bb\u5f00\u5708\u5b50\u7684\u987a\u5e8f\uff1a5\u30014\u30016\u30012\u30013 \u3002\u5c0f\u4f19\u4f34 1 \u662f\u6e38\u620f\u7684\u83b7\u80dc\u8005\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= k <= n <= 500
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findTheWinner(int n, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findTheWinner(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findTheWinner(self, n, k):\n \"\"\"\n :type n: int\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findTheWinner(self, n: int, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findTheWinner(int n, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindTheWinner(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} k\n * @return {number}\n */\nvar findTheWinner = function(n, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} k\n# @return {Integer}\ndef find_the_winner(n, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findTheWinner(_ n: Int, _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findTheWinner(n int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findTheWinner(n: Int, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findTheWinner(n: Int, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_the_winner(n: i32, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $k\n * @return Integer\n */\n function findTheWinner($n, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findTheWinner(n: number, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-the-winner n k)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1823](https://leetcode-cn.com/problems/find-the-winner-of-the-circular-game)", "[\u627e\u51fa\u6e38\u620f\u7684\u83b7\u80dc\u8005](/solution/1800-1899/1823.Find%20the%20Winner%20of%20the%20Circular%20Game/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1823](https://leetcode.com/problems/find-the-winner-of-the-circular-game)", "[Find the Winner of the Circular Game](/solution/1800-1899/1823.Find%20the%20Winner%20of%20the%20Circular%20Game/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "1950", "frontend_question_id": "1822", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sign-of-the-product-of-an-array", "url_en": "https://leetcode.com/problems/sign-of-the-product-of-an-array", "relative_path_cn": "/solution/1800-1899/1822.Sign%20of%20the%20Product%20of%20an%20Array/README.md", "relative_path_en": "/solution/1800-1899/1822.Sign%20of%20the%20Product%20of%20an%20Array/README_EN.md", "title_cn": "\u6570\u7ec4\u5143\u7d20\u79ef\u7684\u7b26\u53f7", "title_en": "Sign of the Product of an Array", "question_title_slug": "sign-of-the-product-of-an-array", "content_en": "

    There is a function signFunc(x) that returns:

    \n\n
      \n\t
    • 1 if x is positive.
    • \n\t
    • -1 if x is negative.
    • \n\t
    • 0 if x is equal to 0.
    • \n
    \n\n

    You are given an integer array nums. Let product be the product of all values in the array nums.

    \n\n

    Return signFunc(product).

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [-1,-2,-3,-4,3,2,1]\nOutput: 1\nExplanation: The product of all values in the array is 144, and signFunc(144) = 1\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,5,0,2,-3]\nOutput: 0\nExplanation: The product of all values in the array is 0, and signFunc(0) = 0\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [-1,1,-1,1,-1]\nOutput: -1\nExplanation: The product of all values in the array is -1, and signFunc(-1) = -1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 1000
    • \n\t
    • -100 <= nums[i] <= 100
    • \n
    \n", "content_cn": "

    \u5df2\u77e5\u51fd\u6570\u00a0signFunc(x) \u5c06\u4f1a\u6839\u636e x \u7684\u6b63\u8d1f\u8fd4\u56de\u7279\u5b9a\u503c\uff1a

    \n\n
      \n\t
    • \u5982\u679c x \u662f\u6b63\u6570\uff0c\u8fd4\u56de 1 \u3002
    • \n\t
    • \u5982\u679c x \u662f\u8d1f\u6570\uff0c\u8fd4\u56de -1 \u3002
    • \n\t
    • \u5982\u679c x \u662f\u7b49\u4e8e 0 \uff0c\u8fd4\u56de 0 \u3002
    • \n
    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \u3002\u4ee4 product \u4e3a\u6570\u7ec4 nums \u4e2d\u6240\u6709\u5143\u7d20\u503c\u7684\u4e58\u79ef\u3002

    \n\n

    \u8fd4\u56de signFunc(product) \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [-1,-2,-3,-4,3,2,1]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u6570\u7ec4\u4e2d\u6240\u6709\u503c\u7684\u4e58\u79ef\u662f 144 \uff0c\u4e14 signFunc(144) = 1\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,5,0,2,-3]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6570\u7ec4\u4e2d\u6240\u6709\u503c\u7684\u4e58\u79ef\u662f 0 \uff0c\u4e14 signFunc(0) = 0\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [-1,1,-1,1,-1]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u6570\u7ec4\u4e2d\u6240\u6709\u503c\u7684\u4e58\u79ef\u662f -1 \uff0c\u4e14 signFunc(-1) = -1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 1000
    • \n\t
    • -100 <= nums[i] <= 100
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int arraySign(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int arraySign(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def arraySign(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def arraySign(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint arraySign(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ArraySign(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar arraySign = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef array_sign(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func arraySign(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func arraySign(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def arraySign(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun arraySign(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn array_sign(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function arraySign($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function arraySign(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (array-sign nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1822](https://leetcode-cn.com/problems/sign-of-the-product-of-an-array)", "[\u6570\u7ec4\u5143\u7d20\u79ef\u7684\u7b26\u53f7](/solution/1800-1899/1822.Sign%20of%20the%20Product%20of%20an%20Array/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[1822](https://leetcode.com/problems/sign-of-the-product-of-an-array)", "[Sign of the Product of an Array](/solution/1800-1899/1822.Sign%20of%20the%20Product%20of%20an%20Array/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "1949", "frontend_question_id": "1804", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/implement-trie-ii-prefix-tree", "url_en": "https://leetcode.com/problems/implement-trie-ii-prefix-tree", "relative_path_cn": "/solution/1800-1899/1804.Implement%20Trie%20II%20%28Prefix%20Tree%29/README.md", "relative_path_en": "/solution/1800-1899/1804.Implement%20Trie%20II%20%28Prefix%20Tree%29/README_EN.md", "title_cn": "\u5b9e\u73b0 Trie \uff08\u524d\u7f00\u6811\uff09 II", "title_en": "Implement Trie II (Prefix Tree)", "question_title_slug": "implement-trie-ii-prefix-tree", "content_en": "

    A trie (pronounced as "try") or prefix tree is a tree data structure used to efficiently store and retrieve keys in a dataset of strings. There are various applications of this data structure, such as autocomplete and spellchecker.

    \n\n

    Implement the Trie class:

    \n\n
      \n\t
    • Trie() Initializes the trie object.
    • \n\t
    • void insert(String word) Inserts the string word into the trie.
    • \n\t
    • int countWordsEqualTo(String word) Returns the number of instances of the string word in the trie.
    • \n\t
    • int countWordsStartingWith(String prefix) Returns the number of strings in the trie that have the string prefix as a prefix.
    • \n\t
    • void erase(String word) Erases the string word from the trie.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["Trie", "insert", "insert", "countWordsEqualTo", "countWordsStartingWith", "erase", "countWordsEqualTo", "countWordsStartingWith", "erase", "countWordsStartingWith"]\n[[], ["apple"], ["apple"], ["apple"], ["app"], ["apple"], ["apple"], ["app"], ["apple"], ["app"]]\nOutput\n[null, null, null, 2, 2, null, 1, 1, null, 0]\n\nExplanation\nTrie trie = new Trie();\ntrie.insert("apple");               // Inserts "apple".\ntrie.insert("apple");               // Inserts another "apple".\ntrie.countWordsEqualTo("apple");    // There are two instances of "apple" so return 2.\ntrie.countWordsStartingWith("app"); // "app" is a prefix of "apple" so return 2.\ntrie.erase("apple");                // Erases one "apple".\ntrie.countWordsEqualTo("apple");    // Now there is only one instance of "apple" so return 1.\ntrie.countWordsStartingWith("app"); // return 1\ntrie.erase("apple");                // Erases "apple". Now the trie is empty.\ntrie.countWordsStartingWith("app"); // return 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= word.length, prefix.length <= 2000
    • \n\t
    • word and prefix consist only of lowercase English letters.
    • \n\t
    • At most 3 * 104 calls in total will be made to insert, countWordsEqualTo, countWordsStartingWith, and erase.
    • \n\t
    • It is guaranteed that for any function call to erase, the string word will exist in the trie.
    • \n
    \n", "content_cn": "

    \u524d\u7f00\u6811\uff08trie\u00a0\uff0c\u53d1\u97f3\u4e3a \"try\"\uff09\u662f\u4e00\u4e2a\u6811\u72b6\u7684\u6570\u636e\u7ed3\u6784\uff0c\u7528\u4e8e\u9ad8\u6548\u5730\u5b58\u50a8\u548c\u68c0\u7d22\u4e00\u7cfb\u5217\u5b57\u7b26\u4e32\u7684\u524d\u7f00\u3002\u524d\u7f00\u6811\u6709\u8bb8\u591a\u5e94\u7528\uff0c\u5982\u81ea\u52a8\u8865\u5168\u548c\u62fc\u5199\u68c0\u67e5\u3002

    \n\n

    \u5b9e\u73b0\u524d\u7f00\u6811 Trie \u7c7b\uff1a

    \n\n
      \n\t
    • Trie()\u00a0\u521d\u59cb\u5316\u524d\u7f00\u6811\u5bf9\u8c61\u3002
    • \n\t
    • void insert(String word)\u00a0\u5c06\u5b57\u7b26\u4e32\u00a0word\u00a0\u63d2\u5165\u524d\u7f00\u6811\u4e2d\u3002
    • \n\t
    • int countWordsEqualTo(String word)\u00a0\u8fd4\u56de\u524d\u7f00\u6811\u4e2d\u5b57\u7b26\u4e32\u00a0word\u00a0\u7684\u5b9e\u4f8b\u4e2a\u6570\u3002
    • \n\t
    • int countWordsStartingWith(String prefix)\u00a0\u8fd4\u56de\u524d\u7f00\u6811\u4e2d\u4ee5\u00a0prefix\u00a0\u4e3a\u524d\u7f00\u7684\u5b57\u7b26\u4e32\u4e2a\u6570\u3002
    • \n\t
    • void erase(String word)\u00a0\u4ece\u524d\u7f00\u6811\u4e2d\u79fb\u9664\u5b57\u7b26\u4e32\u00a0word \u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165\n[\"Trie\", \"insert\", \"insert\", \"countWordsEqualTo\", \"countWordsStartingWith\", \"erase\", \"countWordsEqualTo\", \"countWordsStartingWith\", \"erase\", \"countWordsStartingWith\"]\n[[], [\"apple\"], [\"apple\"], [\"apple\"], [\"app\"], [\"apple\"], [\"apple\"], [\"app\"], [\"apple\"], [\"app\"]]\n\u8f93\u51fa\n[null, null, null, 2, 2, null, 1, 1, null, 0]\n\n\u89e3\u91ca\nTrie trie = new Trie();\ntrie.insert(\"apple\");               // \u63d2\u5165 \"apple\"\u3002\ntrie.insert(\"apple\");               // \u63d2\u5165\u53e6\u4e00\u4e2a \"apple\"\u3002\ntrie.countWordsEqualTo(\"apple\");    // \u6709\u4e24\u4e2a \"apple\" \u5b9e\u4f8b\uff0c\u6240\u4ee5\u8fd4\u56de 2\u3002\ntrie.countWordsStartingWith(\"app\"); // \"app\" \u662f \"apple\" \u7684\u524d\u7f00\uff0c\u6240\u4ee5\u8fd4\u56de 2\u3002\ntrie.erase(\"apple\");                // \u79fb\u9664\u4e00\u4e2a \"apple\"\u3002\ntrie.countWordsEqualTo(\"apple\");    // \u73b0\u5728\u53ea\u6709\u4e00\u4e2a \"apple\" \u5b9e\u4f8b\uff0c\u6240\u4ee5\u8fd4\u56de 1\u3002\ntrie.countWordsStartingWith(\"app\"); // \u8fd4\u56de 1\ntrie.erase(\"apple\");                // \u79fb\u9664 \"apple\"\u3002\u73b0\u5728\u524d\u7f00\u6811\u662f\u7a7a\u7684\u3002\ntrie.countWordsStartingWith(\"app\"); // \u8fd4\u56de 0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= word.length, prefix.length <= 2000
    • \n\t
    • word\u00a0\u548c\u00a0prefix\u00a0\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    • \n\t
    • insert\u3001\u00a0countWordsEqualTo\u3001\u00a0countWordsStartingWith\u00a0\u548c\u00a0erase\u00a0\u603b\u5171\u8c03\u7528\u6700\u591a\u00a03 * 104\u00a0\u6b21\u3002
    • \n\t
    • \u4fdd\u8bc1\u6bcf\u6b21\u8c03\u7528\u00a0erase\u00a0\u65f6\uff0c\u5b57\u7b26\u4e32\u00a0word\u00a0\u603b\u662f\u5b58\u5728\u4e8e\u524d\u7f00\u6811\u4e2d\u3002
    • \n
    \n", "tags_en": ["Trie", "String"], "tags_cn": ["\u5b57\u5178\u6811", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Trie {\npublic:\n Trie() {\n\n }\n \n void insert(string word) {\n\n }\n \n int countWordsEqualTo(string word) {\n\n }\n \n int countWordsStartingWith(string prefix) {\n\n }\n \n void erase(string word) {\n\n }\n};\n\n/**\n * Your Trie object will be instantiated and called as such:\n * Trie* obj = new Trie();\n * obj->insert(word);\n * int param_2 = obj->countWordsEqualTo(word);\n * int param_3 = obj->countWordsStartingWith(prefix);\n * obj->erase(word);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Trie {\n\n public Trie() {\n\n }\n \n public void insert(String word) {\n\n }\n \n public int countWordsEqualTo(String word) {\n\n }\n \n public int countWordsStartingWith(String prefix) {\n\n }\n \n public void erase(String word) {\n\n }\n}\n\n/**\n * Your Trie object will be instantiated and called as such:\n * Trie obj = new Trie();\n * obj.insert(word);\n * int param_2 = obj.countWordsEqualTo(word);\n * int param_3 = obj.countWordsStartingWith(prefix);\n * obj.erase(word);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Trie(object):\n\n def __init__(self):\n\n\n def insert(self, word):\n \"\"\"\n :type word: str\n :rtype: None\n \"\"\"\n\n\n def countWordsEqualTo(self, word):\n \"\"\"\n :type word: str\n :rtype: int\n \"\"\"\n\n\n def countWordsStartingWith(self, prefix):\n \"\"\"\n :type prefix: str\n :rtype: int\n \"\"\"\n\n\n def erase(self, word):\n \"\"\"\n :type word: str\n :rtype: None\n \"\"\"\n\n\n\n# Your Trie object will be instantiated and called as such:\n# obj = Trie()\n# obj.insert(word)\n# param_2 = obj.countWordsEqualTo(word)\n# param_3 = obj.countWordsStartingWith(prefix)\n# obj.erase(word)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Trie:\n\n def __init__(self):\n\n\n def insert(self, word: str) -> None:\n\n\n def countWordsEqualTo(self, word: str) -> int:\n\n\n def countWordsStartingWith(self, prefix: str) -> int:\n\n\n def erase(self, word: str) -> None:\n\n\n\n# Your Trie object will be instantiated and called as such:\n# obj = Trie()\n# obj.insert(word)\n# param_2 = obj.countWordsEqualTo(word)\n# param_3 = obj.countWordsStartingWith(prefix)\n# obj.erase(word)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} Trie;\n\n\nTrie* trieCreate() {\n \n}\n\nvoid trieInsert(Trie* obj, char * word) {\n \n}\n\nint trieCountWordsEqualTo(Trie* obj, char * word) {\n \n}\n\nint trieCountWordsStartingWith(Trie* obj, char * prefix) {\n \n}\n\nvoid trieErase(Trie* obj, char * word) {\n \n}\n\nvoid trieFree(Trie* obj) {\n \n}\n\n/**\n * Your Trie struct will be instantiated and called as such:\n * Trie* obj = trieCreate();\n * trieInsert(obj, word);\n \n * int param_2 = trieCountWordsEqualTo(obj, word);\n \n * int param_3 = trieCountWordsStartingWith(obj, prefix);\n \n * trieErase(obj, word);\n \n * trieFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Trie {\n\n public Trie() {\n\n }\n \n public void Insert(string word) {\n\n }\n \n public int CountWordsEqualTo(string word) {\n\n }\n \n public int CountWordsStartingWith(string prefix) {\n\n }\n \n public void Erase(string word) {\n\n }\n}\n\n/**\n * Your Trie object will be instantiated and called as such:\n * Trie obj = new Trie();\n * obj.Insert(word);\n * int param_2 = obj.CountWordsEqualTo(word);\n * int param_3 = obj.CountWordsStartingWith(prefix);\n * obj.Erase(word);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "\nvar Trie = function() {\n\n};\n\n/** \n * @param {string} word\n * @return {void}\n */\nTrie.prototype.insert = function(word) {\n\n};\n\n/** \n * @param {string} word\n * @return {number}\n */\nTrie.prototype.countWordsEqualTo = function(word) {\n\n};\n\n/** \n * @param {string} prefix\n * @return {number}\n */\nTrie.prototype.countWordsStartingWith = function(prefix) {\n\n};\n\n/** \n * @param {string} word\n * @return {void}\n */\nTrie.prototype.erase = function(word) {\n\n};\n\n/**\n * Your Trie object will be instantiated and called as such:\n * var obj = new Trie()\n * obj.insert(word)\n * var param_2 = obj.countWordsEqualTo(word)\n * var param_3 = obj.countWordsStartingWith(prefix)\n * obj.erase(word)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class Trie\n def initialize()\n\n end\n\n\n=begin\n :type word: String\n :rtype: Void\n=end\n def insert(word)\n\n end\n\n\n=begin\n :type word: String\n :rtype: Integer\n=end\n def count_words_equal_to(word)\n\n end\n\n\n=begin\n :type prefix: String\n :rtype: Integer\n=end\n def count_words_starting_with(prefix)\n\n end\n\n\n=begin\n :type word: String\n :rtype: Void\n=end\n def erase(word)\n\n end\n\n\nend\n\n# Your Trie object will be instantiated and called as such:\n# obj = Trie.new()\n# obj.insert(word)\n# param_2 = obj.count_words_equal_to(word)\n# param_3 = obj.count_words_starting_with(prefix)\n# obj.erase(word)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass Trie {\n\n init() {\n\n }\n \n func insert(_ word: String) {\n\n }\n \n func countWordsEqualTo(_ word: String) -> Int {\n\n }\n \n func countWordsStartingWith(_ prefix: String) -> Int {\n\n }\n \n func erase(_ word: String) {\n\n }\n}\n\n/**\n * Your Trie object will be instantiated and called as such:\n * let obj = Trie()\n * obj.insert(word)\n * let ret_2: Int = obj.countWordsEqualTo(word)\n * let ret_3: Int = obj.countWordsStartingWith(prefix)\n * obj.erase(word)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type Trie struct {\n\n}\n\n\nfunc Constructor() Trie {\n\n}\n\n\nfunc (this *Trie) Insert(word string) {\n\n}\n\n\nfunc (this *Trie) CountWordsEqualTo(word string) int {\n\n}\n\n\nfunc (this *Trie) CountWordsStartingWith(prefix string) int {\n\n}\n\n\nfunc (this *Trie) Erase(word string) {\n\n}\n\n\n/**\n * Your Trie object will be instantiated and called as such:\n * obj := Constructor();\n * obj.Insert(word);\n * param_2 := obj.CountWordsEqualTo(word);\n * param_3 := obj.CountWordsStartingWith(prefix);\n * obj.Erase(word);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class Trie() {\n\n def insert(word: String) {\n \n }\n\n def countWordsEqualTo(word: String): Int = {\n \n }\n\n def countWordsStartingWith(prefix: String): Int = {\n \n }\n\n def erase(word: String) {\n \n }\n\n}\n\n/**\n * Your Trie object will be instantiated and called as such:\n * var obj = new Trie()\n * obj.insert(word)\n * var param_2 = obj.countWordsEqualTo(word)\n * var param_3 = obj.countWordsStartingWith(prefix)\n * obj.erase(word)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Trie() {\n\n fun insert(word: String) {\n\n }\n\n fun countWordsEqualTo(word: String): Int {\n\n }\n\n fun countWordsStartingWith(prefix: String): Int {\n\n }\n\n fun erase(word: String) {\n\n }\n\n}\n\n/**\n * Your Trie object will be instantiated and called as such:\n * var obj = Trie()\n * obj.insert(word)\n * var param_2 = obj.countWordsEqualTo(word)\n * var param_3 = obj.countWordsStartingWith(prefix)\n * obj.erase(word)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct Trie {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl Trie {\n\n fn new() -> Self {\n\n }\n \n fn insert(&self, word: String) {\n\n }\n \n fn count_words_equal_to(&self, word: String) -> i32 {\n\n }\n \n fn count_words_starting_with(&self, prefix: String) -> i32 {\n\n }\n \n fn erase(&self, word: String) {\n\n }\n}\n\n/**\n * Your Trie object will be instantiated and called as such:\n * let obj = Trie::new();\n * obj.insert(word);\n * let ret_2: i32 = obj.count_words_equal_to(word);\n * let ret_3: i32 = obj.count_words_starting_with(prefix);\n * obj.erase(word);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Trie {\n /**\n */\n function __construct() {\n\n }\n\n /**\n * @param String $word\n * @return NULL\n */\n function insert($word) {\n\n }\n\n /**\n * @param String $word\n * @return Integer\n */\n function countWordsEqualTo($word) {\n\n }\n\n /**\n * @param String $prefix\n * @return Integer\n */\n function countWordsStartingWith($prefix) {\n\n }\n\n /**\n * @param String $word\n * @return NULL\n */\n function erase($word) {\n\n }\n}\n\n/**\n * Your Trie object will be instantiated and called as such:\n * $obj = Trie();\n * $obj->insert($word);\n * $ret_2 = $obj->countWordsEqualTo($word);\n * $ret_3 = $obj->countWordsStartingWith($prefix);\n * $obj->erase($word);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class Trie {\n constructor() {\n\n }\n\n insert(word: string): void {\n\n }\n\n countWordsEqualTo(word: string): number {\n\n }\n\n countWordsStartingWith(prefix: string): number {\n\n }\n\n erase(word: string): void {\n\n }\n}\n\n/**\n * Your Trie object will be instantiated and called as such:\n * var obj = new Trie()\n * obj.insert(word)\n * var param_2 = obj.countWordsEqualTo(word)\n * var param_3 = obj.countWordsStartingWith(prefix)\n * obj.erase(word)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define trie%\n (class object%\n (super-new)\n (init-field)\n \n ; insert : string? -> void?\n (define/public (insert word)\n\n )\n ; count-words-equal-to : string? -> exact-integer?\n (define/public (count-words-equal-to word)\n\n )\n ; count-words-starting-with : string? -> exact-integer?\n (define/public (count-words-starting-with prefix)\n\n )\n ; erase : string? -> void?\n (define/public (erase word)\n\n )))\n\n;; Your trie% object will be instantiated and called as such:\n;; (define obj (new trie%))\n;; (send obj insert word)\n;; (define param_2 (send obj count-words-equal-to word))\n;; (define param_3 (send obj count-words-starting-with prefix))\n;; (send obj erase word)", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1804](https://leetcode-cn.com/problems/implement-trie-ii-prefix-tree)", "[\u5b9e\u73b0 Trie \uff08\u524d\u7f00\u6811\uff09 II](/solution/1800-1899/1804.Implement%20Trie%20II%20%28Prefix%20Tree%29/README.md)", "`\u5b57\u5178\u6811`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1804](https://leetcode.com/problems/implement-trie-ii-prefix-tree)", "[Implement Trie II (Prefix Tree)](/solution/1800-1899/1804.Implement%20Trie%20II%20%28Prefix%20Tree%29/README_EN.md)", "`Trie`,`String`", "Medium", "\ud83d\udd12"]}, {"question_id": "1948", "frontend_question_id": "1795", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/rearrange-products-table", "url_en": "https://leetcode.com/problems/rearrange-products-table", "relative_path_cn": "/solution/1700-1799/1795.Rearrange%20Products%20Table/README.md", "relative_path_en": "/solution/1700-1799/1795.Rearrange%20Products%20Table/README_EN.md", "title_cn": "\u6bcf\u4e2a\u4ea7\u54c1\u5728\u4e0d\u540c\u5546\u5e97\u7684\u4ef7\u683c", "title_en": "Rearrange Products Table", "question_title_slug": "rearrange-products-table", "content_en": "

    Table: Products

    \r\n\r\n
    \r\n+-------------+---------+\r\n| Column Name | Type    |\r\n+-------------+---------+\r\n| product_id  | int     |\r\n| store1      | int     |\r\n| store2      | int     |\r\n| store3      | int     |\r\n+-------------+---------+\r\nproduct_id is the primary key for this table.\r\nEach row in this table indicates the product's price in 3 different stores: store1, store2, and store3.\r\nIf the product is not available in a store, the price will be null in that store's column.\r\n
    \r\n\r\n

     

    \r\n\r\n

    Write an SQL query to rearrange the Products table so that each row has (product_id, store, price). If a product is not available in a store, do not include a row with that product_id and store combination in the result table.

    \r\n\r\n

    Return the result table in any order.

    \r\n\r\n

    The query result format is in the following example:

    \r\n\r\n

     

    \r\n\r\n
    \r\nProducts table:\r\n+------------+--------+--------+--------+\r\n| product_id | store1 | store2 | store3 |\r\n+------------+--------+--------+--------+\r\n| 0          | 95     | 100    | 105    |\r\n| 1          | 70     | null   | 80     |\r\n+------------+--------+--------+--------+\r\n\r\nResult table:\r\n+------------+--------+-------+\r\n| product_id | store  | price |\r\n+------------+--------+-------+\r\n| 0          | store1 | 95    |\r\n| 0          | store2 | 100   |\r\n| 0          | store3 | 105   |\r\n| 1          | store1 | 70    |\r\n| 1          | store3 | 80    |\r\n+------------+--------+-------+\r\n\r\nProduct 0 is available in all three stores with prices 95, 100, and 105 respectively.\r\nProduct 1 is available in store1 with price 70 and store3 with price 80. The product is not available in store2.\r\n
    ", "content_cn": "

    \u8868\uff1aProducts

    \n\n
    \n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| product_id  | int     |\n| store1      | int     |\n| store2      | int     |\n| store3      | int     |\n+-------------+---------+\n\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\u662fproduct_id\uff08\u4ea7\u54c1Id\uff09\u3002\n\u6bcf\u884c\u5b58\u50a8\u4e86\u8fd9\u4e00\u4ea7\u54c1\u5728\u4e0d\u540c\u5546\u5e97store1, store2, store3\u7684\u4ef7\u683c\u3002\n\u5982\u679c\u8fd9\u4e00\u4ea7\u54c1\u5728\u5546\u5e97\u91cc\u6ca1\u6709\u51fa\u552e\uff0c\u5219\u503c\u5c06\u4e3anull\u3002\n
    \n\n

    \u00a0

    \n\n

    \u8bf7\u4f60\u91cd\u6784 Products \u8868\uff0c\u67e5\u8be2\u6bcf\u4e2a\u4ea7\u54c1\u5728\u4e0d\u540c\u5546\u5e97\u7684\u4ef7\u683c\uff0c\u4f7f\u5f97\u8f93\u51fa\u7684\u683c\u5f0f\u53d8\u4e3a(product_id, store, price) \u3002\u5982\u679c\u8fd9\u4e00\u4ea7\u54c1\u5728\u5546\u5e97\u91cc\u6ca1\u6709\u51fa\u552e\uff0c\u5219\u4e0d\u8f93\u51fa\u8fd9\u4e00\u884c\u3002

    \n\n

    \u8f93\u51fa\u7ed3\u679c\u8868\u4e2d\u7684\u987a\u5e8f\u4e0d\u4f5c\u8981\u6c42\u3002

    \n\n

    \u67e5\u8be2\u8f93\u51fa\u683c\u5f0f\u8bf7\u53c2\u8003\u4e0b\u9762\u793a\u4f8b\u3002

    \n\n

    \u00a0

    \n\n
    \nProducts table:\n+------------+--------+--------+--------+\n| product_id | store1 | store2 | store3 |\n+------------+--------+--------+--------+\n| 0          | 95     | 100    | 105    |\n| 1          | 70     | null   | 80     |\n+------------+--------+--------+--------+\n\nResult table:\n+------------+--------+-------+\n| product_id | store  | price |\n+------------+--------+-------+\n| 0          | store1 | 95    |\n| 0          | store2 | 100   |\n| 0          | store3 | 105   |\n| 1          | store1 | 70    |\n| 1          | store3 | 80    |\n+------------+--------+-------+\n\n\u4ea7\u54c10\u5728store1\uff0cstore2,store3\u7684\u4ef7\u683c\u5206\u522b\u4e3a95,100,105\u3002\n\u4ea7\u54c11\u5728store1\uff0cstore3\u7684\u4ef7\u683c\u5206\u522b\u4e3a70,80\u3002\u5728store2\u65e0\u6cd5\u4e70\u5230\u3002\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1795](https://leetcode-cn.com/problems/rearrange-products-table)", "[\u6bcf\u4e2a\u4ea7\u54c1\u5728\u4e0d\u540c\u5546\u5e97\u7684\u4ef7\u683c](/solution/1700-1799/1795.Rearrange%20Products%20Table/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1795](https://leetcode.com/problems/rearrange-products-table)", "[Rearrange Products Table](/solution/1700-1799/1795.Rearrange%20Products%20Table/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1947", "frontend_question_id": "1819", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-different-subsequences-gcds", "url_en": "https://leetcode.com/problems/number-of-different-subsequences-gcds", "relative_path_cn": "/solution/1800-1899/1819.Number%20of%20Different%20Subsequences%20GCDs/README.md", "relative_path_en": "/solution/1800-1899/1819.Number%20of%20Different%20Subsequences%20GCDs/README_EN.md", "title_cn": "\u5e8f\u5217\u4e2d\u4e0d\u540c\u6700\u5927\u516c\u7ea6\u6570\u7684\u6570\u76ee", "title_en": "Number of Different Subsequences GCDs", "question_title_slug": "number-of-different-subsequences-gcds", "content_en": "

    You are given an array nums that consists of positive integers.

    \n\n

    The GCD of a sequence of numbers is defined as the greatest integer that divides all the numbers in the sequence evenly.

    \n\n
      \n\t
    • For example, the GCD of the sequence [4,6,16] is 2.
    • \n
    \n\n

    A subsequence of an array is a sequence that can be formed by removing some elements (possibly none) of the array.

    \n\n
      \n\t
    • For example, [2,5,10] is a subsequence of [1,2,1,2,4,1,5,10].
    • \n
    \n\n

    Return the number of different GCDs among all non-empty subsequences of nums.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: nums = [6,10,3]\nOutput: 5\nExplanation: The figure shows all the non-empty subsequences and their GCDs.\nThe different GCDs are 6, 10, 3, 2, and 1.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [5,15,40,5,6]\nOutput: 7\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • 1 <= nums[i] <= 2 * 105
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u7531\u6b63\u6574\u6570\u7ec4\u6210\u7684\u6570\u7ec4 nums \u3002

    \n\n

    \u6570\u5b57\u5e8f\u5217\u7684 \u6700\u5927\u516c\u7ea6\u6570 \u5b9a\u4e49\u4e3a\u5e8f\u5217\u4e2d\u6240\u6709\u6574\u6570\u7684\u5171\u6709\u7ea6\u6570\u4e2d\u7684\u6700\u5927\u6574\u6570\u3002

    \n\n
      \n\t
    • \u4f8b\u5982\uff0c\u5e8f\u5217 [4,6,16] \u7684\u6700\u5927\u516c\u7ea6\u6570\u662f 2 \u3002
    • \n
    \n\n

    \u6570\u7ec4\u7684\u4e00\u4e2a \u5b50\u5e8f\u5217 \u672c\u8d28\u662f\u4e00\u4e2a\u5e8f\u5217\uff0c\u53ef\u4ee5\u901a\u8fc7\u5220\u9664\u6570\u7ec4\u4e2d\u7684\u67d0\u4e9b\u5143\u7d20\uff08\u6216\u8005\u4e0d\u5220\u9664\uff09\u5f97\u5230\u3002

    \n\n
      \n\t
    • \u4f8b\u5982\uff0c[2,5,10] \u662f [1,2,1,2,4,1,5,10] \u7684\u4e00\u4e2a\u5b50\u5e8f\u5217\u3002
    • \n
    \n\n

    \u8ba1\u7b97\u5e76\u8fd4\u56de nums \u7684\u6240\u6709 \u975e\u7a7a \u5b50\u5e8f\u5217\u4e2d \u4e0d\u540c \u6700\u5927\u516c\u7ea6\u6570\u7684 \u6570\u76ee \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1anums = [6,10,3]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u4e0a\u56fe\u663e\u793a\u4e86\u6240\u6709\u7684\u975e\u7a7a\u5b50\u5e8f\u5217\u4e0e\u5404\u81ea\u7684\u6700\u5927\u516c\u7ea6\u6570\u3002\n\u4e0d\u540c\u7684\u6700\u5927\u516c\u7ea6\u6570\u4e3a 6 \u300110 \u30013 \u30012 \u548c 1 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [5,15,40,5,6]\n\u8f93\u51fa\uff1a7\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • 1 <= nums[i] <= 2 * 105
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countDifferentSubsequenceGCDs(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countDifferentSubsequenceGCDs(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countDifferentSubsequenceGCDs(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countDifferentSubsequenceGCDs(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countDifferentSubsequenceGCDs(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountDifferentSubsequenceGCDs(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar countDifferentSubsequenceGCDs = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef count_different_subsequence_gc_ds(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countDifferentSubsequenceGCDs(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countDifferentSubsequenceGCDs(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countDifferentSubsequenceGCDs(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countDifferentSubsequenceGCDs(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_different_subsequence_gc_ds(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function countDifferentSubsequenceGCDs($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countDifferentSubsequenceGCDs(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-different-subsequence-gc-ds nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1819](https://leetcode-cn.com/problems/number-of-different-subsequences-gcds)", "[\u5e8f\u5217\u4e2d\u4e0d\u540c\u6700\u5927\u516c\u7ea6\u6570\u7684\u6570\u76ee](/solution/1800-1899/1819.Number%20of%20Different%20Subsequences%20GCDs/README.md)", "`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[1819](https://leetcode.com/problems/number-of-different-subsequences-gcds)", "[Number of Different Subsequences GCDs](/solution/1800-1899/1819.Number%20of%20Different%20Subsequences%20GCDs/README_EN.md)", "`Math`", "Hard", ""]}, {"question_id": "1946", "frontend_question_id": "1818", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-absolute-sum-difference", "url_en": "https://leetcode.com/problems/minimum-absolute-sum-difference", "relative_path_cn": "/solution/1800-1899/1818.Minimum%20Absolute%20Sum%20Difference/README.md", "relative_path_en": "/solution/1800-1899/1818.Minimum%20Absolute%20Sum%20Difference/README_EN.md", "title_cn": "\u7edd\u5bf9\u5dee\u503c\u548c", "title_en": "Minimum Absolute Sum Difference", "question_title_slug": "minimum-absolute-sum-difference", "content_en": "

    You are given two positive integer arrays nums1 and nums2, both of length n.

    \n\n

    The absolute sum difference of arrays nums1 and nums2 is defined as the sum of |nums1[i] - nums2[i]| for each 0 <= i < n (0-indexed).

    \n\n

    You can replace at most one element of nums1 with any other element in nums1 to minimize the absolute sum difference.

    \n\n

    Return the minimum absolute sum difference after replacing at most one element in the array nums1. Since the answer may be large, return it modulo 109 + 7.

    \n\n

    |x| is defined as:

    \n\n
      \n\t
    • x if x >= 0, or
    • \n\t
    • -x if x < 0.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums1 = [1,7,5], nums2 = [2,3,5]\nOutput: 3\nExplanation: There are two possible optimal solutions:\n- Replace the second element with the first: [1,7,5] => [1,1,5], or\n- Replace the second element with the third: [1,7,5] => [1,5,5].\nBoth will yield an absolute sum difference of |1-2| + (|1-3| or |5-3|) + |5-5| = 3.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums1 = [2,4,6,8,10], nums2 = [2,4,6,8,10]\nOutput: 0\nExplanation: nums1 is equal to nums2 so no replacement is needed. This will result in an \nabsolute sum difference of 0.\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums1 = [1,10,4,4,2,7], nums2 = [9,3,5,1,7,4]\nOutput: 20\nExplanation: Replace the first element with the second: [1,10,4,4,2,7] => [10,10,4,4,2,7].\nThis yields an absolute sum difference of |10-9| + |10-3| + |4-5| + |4-1| + |2-7| + |7-4| = 20\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == nums1.length
    • \n\t
    • n == nums2.length
    • \n\t
    • 1 <= n <= 105
    • \n\t
    • 1 <= nums1[i], nums2[i] <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u6b63\u6574\u6570\u6570\u7ec4 nums1 \u548c nums2 \uff0c\u6570\u7ec4\u7684\u957f\u5ea6\u90fd\u662f n \u3002

    \n\n

    \u6570\u7ec4 nums1 \u548c nums2 \u7684 \u7edd\u5bf9\u5dee\u503c\u548c \u5b9a\u4e49\u4e3a\u6240\u6709 |nums1[i] - nums2[i]|\uff080 <= i < n\uff09\u7684 \u603b\u548c\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u9009\u7528 nums1 \u4e2d\u7684 \u4efb\u610f\u4e00\u4e2a \u5143\u7d20\u6765\u66ff\u6362 nums1 \u4e2d\u7684 \u81f3\u591a \u4e00\u4e2a\u5143\u7d20\uff0c\u4ee5 \u6700\u5c0f\u5316 \u7edd\u5bf9\u5dee\u503c\u548c\u3002

    \n\n

    \u5728\u66ff\u6362\u6570\u7ec4 nums1 \u4e2d\u6700\u591a\u4e00\u4e2a\u5143\u7d20 \u4e4b\u540e \uff0c\u8fd4\u56de\u6700\u5c0f\u7edd\u5bf9\u5dee\u503c\u548c\u3002\u56e0\u4e3a\u7b54\u6848\u53ef\u80fd\u5f88\u5927\uff0c\u6240\u4ee5\u9700\u8981\u5bf9 109 + 7 \u53d6\u4f59 \u540e\u8fd4\u56de\u3002

    \n\n

    |x| \u5b9a\u4e49\u4e3a\uff1a

    \n\n
      \n\t
    • \u5982\u679c x >= 0 \uff0c\u503c\u4e3a x \uff0c\u6216\u8005
    • \n\t
    • \u5982\u679c x <= 0 \uff0c\u503c\u4e3a -x
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums1 = [1,7,5], nums2 = [2,3,5]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6709\u4e24\u79cd\u53ef\u80fd\u7684\u6700\u4f18\u65b9\u6848\uff1a\n- \u5c06\u7b2c\u4e8c\u4e2a\u5143\u7d20\u66ff\u6362\u4e3a\u7b2c\u4e00\u4e2a\u5143\u7d20\uff1a[1,7,5] => [1,1,5] \uff0c\u6216\u8005\n- \u5c06\u7b2c\u4e8c\u4e2a\u5143\u7d20\u66ff\u6362\u4e3a\u7b2c\u4e09\u4e2a\u5143\u7d20\uff1a[1,7,5] => [1,5,5]\n\u4e24\u79cd\u65b9\u6848\u7684\u7edd\u5bf9\u5dee\u503c\u548c\u90fd\u662f |1-2| + (|1-3| \u6216\u8005 |5-3|) + |5-5| = 3\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums1 = [2,4,6,8,10], nums2 = [2,4,6,8,10]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1anums1 \u548c nums2 \u76f8\u7b49\uff0c\u6240\u4ee5\u4e0d\u7528\u66ff\u6362\u5143\u7d20\u3002\u7edd\u5bf9\u5dee\u503c\u548c\u4e3a 0\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums1 = [1,10,4,4,2,7], nums2 = [9,3,5,1,7,4]\n\u8f93\u51fa\uff1a20\n\u89e3\u91ca\uff1a\u5c06\u7b2c\u4e00\u4e2a\u5143\u7d20\u66ff\u6362\u4e3a\u7b2c\u4e8c\u4e2a\u5143\u7d20\uff1a[1,10,4,4,2,7] => [10,10,4,4,2,7]\n\u7edd\u5bf9\u5dee\u503c\u548c\u4e3a |10-9| + |10-3| + |4-5| + |4-1| + |2-7| + |7-4| = 20\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == nums1.length
    • \n\t
    • n == nums2.length
    • \n\t
    • 1 <= n <= 105
    • \n\t
    • 1 <= nums1[i], nums2[i] <= 105
    • \n
    \n", "tags_en": ["Greedy", "Binary Search"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minAbsoluteSumDiff(vector& nums1, vector& nums2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minAbsoluteSumDiff(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minAbsoluteSumDiff(self, nums1, nums2):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minAbsoluteSumDiff(self, nums1: List[int], nums2: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minAbsoluteSumDiff(int* nums1, int nums1Size, int* nums2, int nums2Size){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinAbsoluteSumDiff(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums1\n * @param {number[]} nums2\n * @return {number}\n */\nvar minAbsoluteSumDiff = function(nums1, nums2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums1\n# @param {Integer[]} nums2\n# @return {Integer}\ndef min_absolute_sum_diff(nums1, nums2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minAbsoluteSumDiff(_ nums1: [Int], _ nums2: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minAbsoluteSumDiff(nums1 []int, nums2 []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minAbsoluteSumDiff(nums1: Array[Int], nums2: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minAbsoluteSumDiff(nums1: IntArray, nums2: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_absolute_sum_diff(nums1: Vec, nums2: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums1\n * @param Integer[] $nums2\n * @return Integer\n */\n function minAbsoluteSumDiff($nums1, $nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minAbsoluteSumDiff(nums1: number[], nums2: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-absolute-sum-diff nums1 nums2)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1818](https://leetcode-cn.com/problems/minimum-absolute-sum-difference)", "[\u7edd\u5bf9\u5dee\u503c\u548c](/solution/1800-1899/1818.Minimum%20Absolute%20Sum%20Difference/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1818](https://leetcode.com/problems/minimum-absolute-sum-difference)", "[Minimum Absolute Sum Difference](/solution/1800-1899/1818.Minimum%20Absolute%20Sum%20Difference/README_EN.md)", "`Greedy`,`Binary Search`", "Medium", ""]}, {"question_id": "1945", "frontend_question_id": "1817", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/finding-the-users-active-minutes", "url_en": "https://leetcode.com/problems/finding-the-users-active-minutes", "relative_path_cn": "/solution/1800-1899/1817.Finding%20the%20Users%20Active%20Minutes/README.md", "relative_path_en": "/solution/1800-1899/1817.Finding%20the%20Users%20Active%20Minutes/README_EN.md", "title_cn": "\u67e5\u627e\u7528\u6237\u6d3b\u8dc3\u5206\u949f\u6570", "title_en": "Finding the Users Active Minutes", "question_title_slug": "finding-the-users-active-minutes", "content_en": "

    You are given the logs for users' actions on LeetCode, and an integer k. The logs are represented by a 2D integer array logs where each logs[i] = [IDi, timei] indicates that the user with IDi performed an action at the minute timei.

    \n\n

    Multiple users can perform actions simultaneously, and a single user can perform multiple actions in the same minute.

    \n\n

    The user active minutes (UAM) for a given user is defined as the number of unique minutes in which the user performed an action on LeetCode. A minute can only be counted once, even if multiple actions occur during it.

    \n\n

    You are to calculate a 1-indexed array answer of size k such that, for each j (1 <= j <= k), answer[j] is the number of users whose UAM equals j.

    \n\n

    Return the array answer as described above.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: logs = [[0,5],[1,2],[0,2],[0,5],[1,3]], k = 5\nOutput: [0,2,0,0,0]\nExplanation:\nThe user with ID=0 performed actions at minutes 5, 2, and 5 again. Hence, they have a UAM of 2 (minute 5 is only counted once).\nThe user with ID=1 performed actions at minutes 2 and 3. Hence, they have a UAM of 2.\nSince both users have a UAM of 2, answer[2] is 2, and the remaining answer[j] values are 0.\n
    \n\n

    Example 2:

    \n\n
    \nInput: logs = [[1,1],[2,2],[2,3]], k = 4\nOutput: [1,1,0,0]\nExplanation:\nThe user with ID=1 performed a single action at minute 1. Hence, they have a UAM of 1.\nThe user with ID=2 performed actions at minutes 2 and 3. Hence, they have a UAM of 2.\nThere is one user with a UAM of 1 and one with a UAM of 2.\nHence, answer[1] = 1, answer[2] = 1, and the remaining values are 0.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= logs.length <= 104
    • \n\t
    • 0 <= IDi <= 109
    • \n\t
    • 1 <= timei <= 105
    • \n\t
    • k is in the range [The maximum UAM for a user, 105].
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u7528\u6237\u5728 LeetCode \u7684\u64cd\u4f5c\u65e5\u5fd7\uff0c\u548c\u4e00\u4e2a\u6574\u6570 k \u3002\u65e5\u5fd7\u7528\u4e00\u4e2a\u4e8c\u7ef4\u6574\u6570\u6570\u7ec4 logs \u8868\u793a\uff0c\u5176\u4e2d\u6bcf\u4e2a logs[i] = [IDi, timei] \u8868\u793a ID \u4e3a IDi \u7684\u7528\u6237\u5728 timei \u5206\u949f\u65f6\u6267\u884c\u4e86\u67d0\u4e2a\u64cd\u4f5c\u3002

    \n\n

    \u591a\u4e2a\u7528\u6237 \u53ef\u4ee5\u540c\u65f6\u6267\u884c\u64cd\u4f5c\uff0c\u5355\u4e2a\u7528\u6237\u53ef\u4ee5\u5728\u540c\u4e00\u5206\u949f\u5185\u6267\u884c \u591a\u4e2a\u64cd\u4f5c \u3002

    \n\n

    \u6307\u5b9a\u7528\u6237\u7684 \u7528\u6237\u6d3b\u8dc3\u5206\u949f\u6570\uff08user active minutes\uff0cUAM\uff09 \u5b9a\u4e49\u4e3a\u7528\u6237\u5bf9 LeetCode \u6267\u884c\u64cd\u4f5c\u7684 \u552f\u4e00\u5206\u949f\u6570 \u3002 \u5373\u4f7f\u4e00\u5206\u949f\u5185\u6267\u884c\u591a\u4e2a\u64cd\u4f5c\uff0c\u4e5f\u53ea\u80fd\u6309\u4e00\u5206\u949f\u8ba1\u6570\u3002

    \n\n

    \u8bf7\u4f60\u7edf\u8ba1\u7528\u6237\u6d3b\u8dc3\u5206\u949f\u6570\u7684\u5206\u5e03\u60c5\u51b5\uff0c\u7edf\u8ba1\u7ed3\u679c\u662f\u4e00\u4e2a\u957f\u5ea6\u4e3a k \u4e14 \u4e0b\u6807\u4ece 1 \u5f00\u59cb\u8ba1\u6570 \u7684\u6570\u7ec4 answer \uff0c\u5bf9\u4e8e\u6bcf\u4e2a j\uff081 <= j <= k\uff09\uff0canswer[j] \u8868\u793a \u7528\u6237\u6d3b\u8dc3\u5206\u949f\u6570 \u7b49\u4e8e j \u7684\u7528\u6237\u6570\u3002

    \n\n

    \u8fd4\u56de\u4e0a\u9762\u63cf\u8ff0\u7684\u7b54\u6848\u6570\u7ec4 answer \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1alogs = [[0,5],[1,2],[0,2],[0,5],[1,3]], k = 5\n\u8f93\u51fa\uff1a[0,2,0,0,0]\n\u89e3\u91ca\uff1a\nID=0 \u7684\u7528\u6237\u6267\u884c\u64cd\u4f5c\u7684\u5206\u949f\u5206\u522b\u662f\uff1a5 \u30012 \u548c 5 \u3002\u56e0\u6b64\uff0c\u8be5\u7528\u6237\u7684\u7528\u6237\u6d3b\u8dc3\u5206\u949f\u6570\u4e3a 2\uff08\u5206\u949f 5 \u53ea\u8ba1\u6570\u4e00\u6b21\uff09\nID=1 \u7684\u7528\u6237\u6267\u884c\u64cd\u4f5c\u7684\u5206\u949f\u5206\u522b\u662f\uff1a2 \u548c 3 \u3002\u56e0\u6b64\uff0c\u8be5\u7528\u6237\u7684\u7528\u6237\u6d3b\u8dc3\u5206\u949f\u6570\u4e3a 2\n2 \u4e2a\u7528\u6237\u7684\u7528\u6237\u6d3b\u8dc3\u5206\u949f\u6570\u90fd\u662f 2 \uff0canswer[2] \u4e3a 2 \uff0c\u5176\u4f59 answer[j] \u7684\u503c\u90fd\u662f 0\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1alogs = [[1,1],[2,2],[2,3]], k = 4\n\u8f93\u51fa\uff1a[1,1,0,0]\n\u89e3\u91ca\uff1a\nID=1 \u7684\u7528\u6237\u4ec5\u5728\u5206\u949f 1 \u6267\u884c\u5355\u4e2a\u64cd\u4f5c\u3002\u56e0\u6b64\uff0c\u8be5\u7528\u6237\u7684\u7528\u6237\u6d3b\u8dc3\u5206\u949f\u6570\u4e3a 1\nID=2 \u7684\u7528\u6237\u6267\u884c\u64cd\u4f5c\u7684\u5206\u949f\u5206\u522b\u662f\uff1a2 \u548c 3 \u3002\u56e0\u6b64\uff0c\u8be5\u7528\u6237\u7684\u7528\u6237\u6d3b\u8dc3\u5206\u949f\u6570\u4e3a 2\n1 \u4e2a\u7528\u6237\u7684\u7528\u6237\u6d3b\u8dc3\u5206\u949f\u6570\u662f 1 \uff0c1 \u4e2a\u7528\u6237\u7684\u7528\u6237\u6d3b\u8dc3\u5206\u949f\u6570\u662f 2 \n\u56e0\u6b64\uff0canswer[1] = 1 \uff0canswer[2] = 1 \uff0c\u5176\u4f59\u7684\u503c\u90fd\u662f 0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= logs.length <= 104
    • \n\t
    • 0 <= IDi <= 109
    • \n\t
    • 1 <= timei <= 105
    • \n\t
    • k \u7684\u53d6\u503c\u8303\u56f4\u662f [\u7528\u6237\u7684\u6700\u5927\u7528\u6237\u6d3b\u8dc3\u5206\u949f\u6570, 105]
    • \n
    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findingUsersActiveMinutes(vector>& logs, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] findingUsersActiveMinutes(int[][] logs, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findingUsersActiveMinutes(self, logs, k):\n \"\"\"\n :type logs: List[List[int]]\n :type k: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findingUsersActiveMinutes(self, logs: List[List[int]], k: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* findingUsersActiveMinutes(int** logs, int logsSize, int* logsColSize, int k, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] FindingUsersActiveMinutes(int[][] logs, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} logs\n * @param {number} k\n * @return {number[]}\n */\nvar findingUsersActiveMinutes = function(logs, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} logs\n# @param {Integer} k\n# @return {Integer[]}\ndef finding_users_active_minutes(logs, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findingUsersActiveMinutes(_ logs: [[Int]], _ k: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findingUsersActiveMinutes(logs [][]int, k int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findingUsersActiveMinutes(logs: Array[Array[Int]], k: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findingUsersActiveMinutes(logs: Array, k: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn finding_users_active_minutes(logs: Vec>, k: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $logs\n * @param Integer $k\n * @return Integer[]\n */\n function findingUsersActiveMinutes($logs, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findingUsersActiveMinutes(logs: number[][], k: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (finding-users-active-minutes logs k)\n (-> (listof (listof exact-integer?)) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1817](https://leetcode-cn.com/problems/finding-the-users-active-minutes)", "[\u67e5\u627e\u7528\u6237\u6d3b\u8dc3\u5206\u949f\u6570](/solution/1800-1899/1817.Finding%20the%20Users%20Active%20Minutes/README.md)", "`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1817](https://leetcode.com/problems/finding-the-users-active-minutes)", "[Finding the Users Active Minutes](/solution/1800-1899/1817.Finding%20the%20Users%20Active%20Minutes/README_EN.md)", "`Hash Table`", "Medium", ""]}, {"question_id": "1944", "frontend_question_id": "1816", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/truncate-sentence", "url_en": "https://leetcode.com/problems/truncate-sentence", "relative_path_cn": "/solution/1800-1899/1816.Truncate%20Sentence/README.md", "relative_path_en": "/solution/1800-1899/1816.Truncate%20Sentence/README_EN.md", "title_cn": "\u622a\u65ad\u53e5\u5b50", "title_en": "Truncate Sentence", "question_title_slug": "truncate-sentence", "content_en": "

    A sentence is a list of words that are separated by a single space with no leading or trailing spaces. Each of the words consists of only uppercase and lowercase English letters (no punctuation).

    \n\n
      \n\t
    • For example, "Hello World", "HELLO", and "hello world hello world" are all sentences.
    • \n
    \n\n

    You are given a sentence s\u200b\u200b\u200b\u200b\u200b\u200b and an integer k\u200b\u200b\u200b\u200b\u200b\u200b. You want to truncate s\u200b\u200b\u200b\u200b\u200b\u200b such that it contains only the first k\u200b\u200b\u200b\u200b\u200b\u200b words. Return s\u200b\u200b\u200b\u200b\u200b\u200b after truncating it.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "Hello how are you Contestant", k = 4\nOutput: "Hello how are you"\nExplanation:\nThe words in s are ["Hello", "how" "are", "you", "Contestant"].\nThe first 4 words are ["Hello", "how", "are", "you"].\nHence, you should return "Hello how are you".\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "What is the solution to this problem", k = 4\nOutput: "What is the solution"\nExplanation:\nThe words in s are ["What", "is" "the", "solution", "to", "this", "problem"].\nThe first 4 words are ["What", "is", "the", "solution"].\nHence, you should return "What is the solution".
    \n\n

    Example 3:

    \n\n
    \nInput: s = "chopper is not a tanuki", k = 5\nOutput: "chopper is not a tanuki"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 500
    • \n\t
    • k is in the range [1, the number of words in s].
    • \n\t
    • s consist of only lowercase and uppercase English letters and spaces.
    • \n\t
    • The words in s are separated by a single space.
    • \n\t
    • There are no leading or trailing spaces.
    • \n
    \n", "content_cn": "

    \u53e5\u5b50 \u662f\u4e00\u4e2a\u5355\u8bcd\u5217\u8868\uff0c\u5217\u8868\u4e2d\u7684\u5355\u8bcd\u4e4b\u95f4\u7528\u5355\u4e2a\u7a7a\u683c\u9694\u5f00\uff0c\u4e14\u4e0d\u5b58\u5728\u524d\u5bfc\u6216\u5c3e\u968f\u7a7a\u683c\u3002\u6bcf\u4e2a\u5355\u8bcd\u4ec5\u7531\u5927\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\uff08\u4e0d\u542b\u6807\u70b9\u7b26\u53f7\uff09\u3002

    \n\n
      \n\t
    • \u4f8b\u5982\uff0c\"Hello World\"\u3001\"HELLO\" \u548c \"hello world hello world\" \u90fd\u662f\u53e5\u5b50\u3002
    • \n
    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u53e5\u5b50 s\u200b\u200b\u200b\u200b\u200b\u200b \u548c\u4e00\u4e2a\u6574\u6570 k\u200b\u200b\u200b\u200b\u200b\u200b \uff0c\u8bf7\u4f60\u5c06 s\u200b\u200b \u622a\u65ad \u200b\uff0c\u200b\u200b\u200b\u4f7f\u622a\u65ad\u540e\u7684\u53e5\u5b50\u4ec5\u542b \u524d k\u200b\u200b\u200b\u200b\u200b\u200b \u4e2a\u5355\u8bcd\u3002\u8fd4\u56de \u622a\u65ad s\u200b\u200b\u200b\u200b\u200b\u200b \u540e\u5f97\u5230\u7684\u53e5\u5b50\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1as = \"Hello how are you Contestant\", k = 4\n\u8f93\u51fa\uff1a\"Hello how are you\"\n\u89e3\u91ca\uff1a\ns \u4e2d\u7684\u5355\u8bcd\u4e3a [\"Hello\", \"how\" \"are\", \"you\", \"Contestant\"]\n\u524d 4 \u4e2a\u5355\u8bcd\u4e3a [\"Hello\", \"how\", \"are\", \"you\"]\n\u56e0\u6b64\uff0c\u5e94\u5f53\u8fd4\u56de \"Hello how are you\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1as = \"What is the solution to this problem\", k = 4\n\u8f93\u51fa\uff1a\"What is the solution\"\n\u89e3\u91ca\uff1a\ns \u4e2d\u7684\u5355\u8bcd\u4e3a [\"What\", \"is\" \"the\", \"solution\", \"to\", \"this\", \"problem\"]\n\u524d 4 \u4e2a\u5355\u8bcd\u4e3a [\"What\", \"is\", \"the\", \"solution\"]\n\u56e0\u6b64\uff0c\u5e94\u5f53\u8fd4\u56de \"What is the solution\"
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1as = \"chopper is not a tanuki\", k = 5\n\u8f93\u51fa\uff1a\"chopper is not a tanuki\"\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 500
    • \n\t
    • k \u7684\u53d6\u503c\u8303\u56f4\u662f [1,\u00a0 s \u4e2d\u5355\u8bcd\u7684\u6570\u76ee]
    • \n\t
    • s \u4ec5\u7531\u5927\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u548c\u7a7a\u683c\u7ec4\u6210
    • \n\t
    • s \u4e2d\u7684\u5355\u8bcd\u4e4b\u95f4\u7531\u5355\u4e2a\u7a7a\u683c\u9694\u5f00
    • \n\t
    • \u4e0d\u5b58\u5728\u524d\u5bfc\u6216\u5c3e\u968f\u7a7a\u683c
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string truncateSentence(string s, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String truncateSentence(String s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def truncateSentence(self, s, k):\n \"\"\"\n :type s: str\n :type k: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def truncateSentence(self, s: str, k: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * truncateSentence(char * s, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string TruncateSentence(string s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number} k\n * @return {string}\n */\nvar truncateSentence = function(s, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer} k\n# @return {String}\ndef truncate_sentence(s, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func truncateSentence(_ s: String, _ k: Int) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func truncateSentence(s string, k int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def truncateSentence(s: String, k: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun truncateSentence(s: String, k: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn truncate_sentence(s: String, k: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer $k\n * @return String\n */\n function truncateSentence($s, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function truncateSentence(s: string, k: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (truncate-sentence s k)\n (-> string? exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1816](https://leetcode-cn.com/problems/truncate-sentence)", "[\u622a\u65ad\u53e5\u5b50](/solution/1800-1899/1816.Truncate%20Sentence/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1816](https://leetcode.com/problems/truncate-sentence)", "[Truncate Sentence](/solution/1800-1899/1816.Truncate%20Sentence/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1943", "frontend_question_id": "1794", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/count-pairs-of-equal-substrings-with-minimum-difference", "url_en": "https://leetcode.com/problems/count-pairs-of-equal-substrings-with-minimum-difference", "relative_path_cn": "/solution/1700-1799/1794.Count%20Pairs%20of%20Equal%20Substrings%20With%20Minimum%20Difference/README.md", "relative_path_en": "/solution/1700-1799/1794.Count%20Pairs%20of%20Equal%20Substrings%20With%20Minimum%20Difference/README_EN.md", "title_cn": "\u7edf\u8ba1\u8ddd\u79bb\u6700\u5c0f\u7684\u5b50\u4e32\u5bf9\u4e2a\u6570", "title_en": "Count Pairs of Equal Substrings With Minimum Difference", "question_title_slug": "count-pairs-of-equal-substrings-with-minimum-difference", "content_en": "

    You are given two strings firstString and secondString that are 0-indexed and consist only of lowercase English letters. Count the number of index quadruples (i,j,a,b) that satisfy the following conditions:

    \r\n\r\n
      \r\n\t
    • 0 <= i <= j < firstString.length
    • \r\n\t
    • 0 <= a <= b < secondString.length
    • \r\n\t
    • The substring of firstString that starts at the ith character and ends at the jth character (inclusive) is equal to the substring of secondString that starts at the ath character and ends at the bth character (inclusive).
    • \r\n\t
    • j - a is the minimum possible value among all quadruples that satisfy the previous conditions.
    • \r\n
    \r\n\r\n

    Return the number of such quadruples.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: firstString = "abcd", secondString = "bccda"\r\nOutput: 1\r\nExplanation: The quadruple (0,0,4,4) is the only one that satisfies all the conditions and minimizes j - a.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: firstString = "ab", secondString = "cd"\r\nOutput: 0\r\nExplanation: There are no quadruples satisfying all the conditions.\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= firstString.length, secondString.length <= 2 * 105
    • \r\n\t
    • Both strings consist only of lowercase English letters.
    • \r\n
    ", "content_cn": "

    \u8f93\u5165\u6570\u636e\u4e3a\u4e24\u4e2a\u5b57\u7b26\u4e32firstString \u548c secondString\uff0c\u4e24\u4e2a\u5b57\u7b26\u4e32\u4e0b\u6807\u5747\u4ece0\u5f00\u59cb\uff0c\u4e14\u5747\u53ea\u5305\u542b\u5c0f\u5199\u7684\u82f1\u6587\u5b57\u7b26\uff0c\u8bf7\u8ba1\u7b97\u6ee1\u8db3\u4e0b\u5217\u8981\u6c42\u7684\u4e0b\u6807\u56db\u5143\u7ec4(i,j,a,b)\u7684\u4e2a\u6570\uff1a

    \n\n
      \n\t
    • 0 <= i <= j < firstString.length
    • \n\t
    • 0 <= a <= b < secondString.length
    • \n\t
    • firstString\u5b57\u7b26\u4e32\u4e2d\u4ecei\u4f4d\u7f6e\u5230j\u4f4d\u7f6e\u7684\u5b50\u4e32(\u5305\u62ecj\u4f4d\u7f6e\u7684\u5b57\u7b26)\u548csecondString\u5b57\u7b26\u4e32\u4ecea\u4f4d\u7f6e\u5230b\u4f4d\u7f6e\u7684\u5b50\u4e32(\u5305\u62ecb\u4f4d\u7f6e\u5b57\u7b26)\u76f8\u7b49
    • \n\t
    • j-a\u7684\u6570\u503c\u662f\u6240\u6709\u7b26\u5408\u524d\u9762\u4e09\u4e2a\u6761\u4ef6\u7684\u56db\u5143\u7ec4\u4e2d\u53ef\u80fd\u7684\u6700\u5c0f\u503c
    • \n
    \n\n

    \u8fd4\u56de\u7b26\u5408\u4e0a\u8ff0 4 \u4e2a\u6761\u4ef6\u7684\u56db\u5143\u7ec4\u7684 \u4e2a\u6570 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b1\uff1a

    \n\n
    \n\u8f93\u5165\uff1afirstString = \"abcd\", secondString = \"bccda\"\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a(0,0,4,4)\u662f\u552f\u4e00\u7b26\u5408\u6761\u4ef6\u7684\u56db\u5143\u7ec4\u4e14\u5176j-a\u7684\u6570\u503c\u662f\u6700\u5c0f\u7684.\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1afirstString = \"ab\", secondString = \"cd\"\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6ca1\u6709\u4efb\u4f55\u4e00\u4e2a\u56db\u5143\u7ec4\u80fd\u6ee1\u8db3\u4e0a\u8ff04\u4e2a\u8981\u6c42.\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= firstString.length, secondString.length <= 2 * 105
    • \n\t
    • \u4e24\u4e2a\u8f93\u5165\u5b57\u7b26\u4e32\u5747\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u7b26.
    • \n
    \n", "tags_en": ["Greedy", "String"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countQuadruples(string firstString, string secondString) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countQuadruples(String firstString, String secondString) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countQuadruples(self, firstString, secondString):\n \"\"\"\n :type firstString: str\n :type secondString: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countQuadruples(self, firstString: str, secondString: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countQuadruples(char * firstString, char * secondString){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountQuadruples(string firstString, string secondString) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} firstString\n * @param {string} secondString\n * @return {number}\n */\nvar countQuadruples = function(firstString, secondString) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} first_string\n# @param {String} second_string\n# @return {Integer}\ndef count_quadruples(first_string, second_string)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countQuadruples(_ firstString: String, _ secondString: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countQuadruples(firstString string, secondString string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countQuadruples(firstString: String, secondString: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countQuadruples(firstString: String, secondString: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_quadruples(first_string: String, second_string: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $firstString\n * @param String $secondString\n * @return Integer\n */\n function countQuadruples($firstString, $secondString) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countQuadruples(firstString: string, secondString: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-quadruples firstString secondString)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1794](https://leetcode-cn.com/problems/count-pairs-of-equal-substrings-with-minimum-difference)", "[\u7edf\u8ba1\u8ddd\u79bb\u6700\u5c0f\u7684\u5b50\u4e32\u5bf9\u4e2a\u6570](/solution/1700-1799/1794.Count%20Pairs%20of%20Equal%20Substrings%20With%20Minimum%20Difference/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1794](https://leetcode.com/problems/count-pairs-of-equal-substrings-with-minimum-difference)", "[Count Pairs of Equal Substrings With Minimum Difference](/solution/1700-1799/1794.Count%20Pairs%20of%20Equal%20Substrings%20With%20Minimum%20Difference/README_EN.md)", "`Greedy`,`String`", "Medium", "\ud83d\udd12"]}, {"question_id": "1942", "frontend_question_id": "1789", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/primary-department-for-each-employee", "url_en": "https://leetcode.com/problems/primary-department-for-each-employee", "relative_path_cn": "/solution/1700-1799/1789.Primary%20Department%20for%20Each%20Employee/README.md", "relative_path_en": "/solution/1700-1799/1789.Primary%20Department%20for%20Each%20Employee/README_EN.md", "title_cn": "\u5458\u5de5\u7684\u76f4\u5c5e\u90e8\u95e8", "title_en": "Primary Department for Each Employee", "question_title_slug": "primary-department-for-each-employee", "content_en": "

    Table: Employee

    \n\n
    \n+---------------+---------+\n| Column Name   |  Type   |\n+---------------+---------+\n| employee_id   | int     |\n| department_id | int     |\n| primary_flag  | varchar |\n+---------------+---------+\n(employee_id, department_id) is the primary key for this table.\nemployee_id is the id of the employee.\ndepartment_id is the id of the department to which the employee belongs.\nprimary_flag is an ENUM of type ('Y', 'N'). If the flag is 'Y', the department is the primary department for the employee. If the flag is 'N', the department is not the primary.\n
    \n\n

     

    \n\n

    Employees can belong to multiple departments. When the employee joins other departments, they need to decide which department is their primary department. Note that when an employee belongs to only one department, their primary column is 'N'.

    \n\n

    Write an SQL query to report all the employees with their primary department. For employees who belong to one department, report their only department.

    \n\n

    Return the result table in any order.

    \n\n

    The query result format is in the following example.

    \n\n

     

    \n\n
    \nEmployee table:\n+-------------+---------------+--------------+\n| employee_id | department_id | primary_flag |\n+-------------+---------------+--------------+\n| 1           | 1             | N            |\n| 2           | 1             | Y            |\n| 2           | 2             | N            |\n| 3           | 3             | N            |\n| 4           | 2             | N            |\n| 4           | 3             | Y            |\n| 4           | 4             | N            |\n+-------------+---------------+--------------+\n\nResult table:\n+-------------+---------------+\n| employee_id | department_id |\n+-------------+---------------+\n| 1           | 1             |\n| 2           | 1             |\n| 3           | 3             |\n| 4           | 3             |\n+-------------+---------------+\n- The Primary department for employee 1 is 1.\n- The Primary department for employee 2 is 1.\n- The Primary department for employee 3 is 3.\n- The Primary department for employee 4 is 3.
    \n\n

     

    \n", "content_cn": "

    Table: Employee

    \n\n
    +---------------+---------+\n| Column Name   |  Type   |\n+---------------+---------+\n| employee_id   | int     |\n| department_id | int     |\n| primary_flag  | varchar |\n+---------------+---------+\n\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\u4e3a employee_id, department_id\nemployee_id \u662f\u5458\u5de5\u7684ID\ndepartment_id \u662f\u90e8\u95e8\u7684ID\uff0c\u8868\u793a\u5458\u5de5\u4e0e\u8be5\u90e8\u95e8\u6709\u5173\u7cfb\nprimary_flag \u662f\u4e00\u4e2a\u679a\u4e3e\u7c7b\u578b\uff0c\u503c\u5206\u522b\u4e3a('Y', 'N'). \u5982\u679c\u503c\u4e3a'Y',\u8868\u793a\u8be5\u90e8\u95e8\u662f\u5458\u5de5\u7684\u76f4\u5c5e\u90e8\u95e8\u3002 \u5982\u679c\u503c\u662f'N',\u5219\u5426\n
    \n\n

    \u00a0

    \n\n

    \u4e00\u4e2a\u5458\u5de5\u53ef\u4ee5\u5c5e\u4e8e\u591a\u4e2a\u90e8\u95e8\u3002

    \n\n

    \u5f53\u4e00\u4e2a\u5458\u5de5\u52a0\u5165\u8d85\u8fc7\u4e00\u4e2a\u90e8\u95e8\u7684\u65f6\u5019\uff0c\u4ed6\u9700\u8981\u51b3\u5b9a\u54ea\u4e2a\u90e8\u95e8\u662f\u4ed6\u7684\u76f4\u5c5e\u90e8\u95e8\u3002

    \n\n

    \u8bf7\u6ce8\u610f\uff0c\u5f53\u5458\u5de5\u53ea\u52a0\u5165\u4e00\u4e2a\u90e8\u95e8\u7684\u65f6\u5019\uff0c\u90a3\u8fd9\u4e2a\u90e8\u95e8\u5c06\u9ed8\u8ba4\u4e3a\u4ed6\u7684\u76f4\u5c5e\u90e8\u95e8\uff0c\u867d\u7136\u8868\u8bb0\u5f55\u7684\u503c\u4e3a'N'.

    \n\n

    \u8bf7\u7f16\u5199\u4e00\u6bb5SQL\uff0c\u67e5\u51fa\u5458\u5de5\u6240\u5c5e\u7684\u76f4\u5c5e\u90e8\u95e8\u3002

    \n\n

    \u8fd4\u56de\u7ed3\u679c\u6ca1\u6709\u987a\u5e8f\u8981\u6c42\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    Employee table:\n+-------------+---------------+--------------+\n| employee_id | department_id | primary_flag |\n+-------------+---------------+--------------+\n| 1           | 1             | N            |\n| 2           | 1             | Y            |\n| 2           | 2             | N            |\n| 3           | 3             | N            |\n| 4           | 2             | N            |\n| 4           | 3             | Y            |\n| 4           | 4             | N            |\n+-------------+---------------+--------------+\n\nResult table:\n+-------------+---------------+\n| employee_id | department_id |\n+-------------+---------------+\n| 1           | 1             |\n| 2           | 1             |\n| 3           | 3             |\n| 4           | 3             |\n+-------------+---------------+\n- \u5458\u5de51\u7684\u76f4\u5c5e\u90e8\u95e8\u662f1\n- \u5458\u5de52\u7684\u76f4\u5c5e\u90e8\u95e8\u662f1\n- \u5458\u5de53\u7684\u76f4\u5c5e\u90e8\u95e8\u662f3\n- \u5458\u5de54\u7684\u76f4\u5c5e\u90e8\u95e8\u662f3
    \n\n

    \u00a0

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1789](https://leetcode-cn.com/problems/primary-department-for-each-employee)", "[\u5458\u5de5\u7684\u76f4\u5c5e\u90e8\u95e8](/solution/1700-1799/1789.Primary%20Department%20for%20Each%20Employee/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1789](https://leetcode.com/problems/primary-department-for-each-employee)", "[Primary Department for Each Employee](/solution/1700-1799/1789.Primary%20Department%20for%20Each%20Employee/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1941", "frontend_question_id": "1830", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-number-of-operations-to-make-string-sorted", "url_en": "https://leetcode.com/problems/minimum-number-of-operations-to-make-string-sorted", "relative_path_cn": "/solution/1800-1899/1830.Minimum%20Number%20of%20Operations%20to%20Make%20String%20Sorted/README.md", "relative_path_en": "/solution/1800-1899/1830.Minimum%20Number%20of%20Operations%20to%20Make%20String%20Sorted/README_EN.md", "title_cn": "\u4f7f\u5b57\u7b26\u4e32\u6709\u5e8f\u7684\u6700\u5c11\u64cd\u4f5c\u6b21\u6570", "title_en": "Minimum Number of Operations to Make String Sorted", "question_title_slug": "minimum-number-of-operations-to-make-string-sorted", "content_en": "

    You are given a string s (0-indexed)\u200b\u200b\u200b\u200b\u200b\u200b. You are asked to perform the following operation on s\u200b\u200b\u200b\u200b\u200b\u200b until you get a sorted string:

    \n\n
      \n\t
    1. Find the largest index i such that 1 <= i < s.length and s[i] < s[i - 1].
    2. \n\t
    3. Find the largest index j such that i <= j < s.length and s[k] < s[i - 1] for all the possible values of k in the range [i, j] inclusive.
    4. \n\t
    5. Swap the two characters at indices i - 1\u200b\u200b\u200b\u200b and j\u200b\u200b\u200b\u200b\u200b.
    6. \n\t
    7. Reverse the suffix starting at index i\u200b\u200b\u200b\u200b\u200b\u200b.
    8. \n
    \n\n

    Return the number of operations needed to make the string sorted. Since the answer can be too large, return it modulo 109 + 7.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "cba"\nOutput: 5\nExplanation: The simulation goes as follows:\nOperation 1: i=2, j=2. Swap s[1] and s[2] to get s="cab", then reverse the suffix starting at 2. Now, s="cab".\nOperation 2: i=1, j=2. Swap s[0] and s[2] to get s="bac", then reverse the suffix starting at 1. Now, s="bca".\nOperation 3: i=2, j=2. Swap s[1] and s[2] to get s="bac", then reverse the suffix starting at 2. Now, s="bac".\nOperation 4: i=1, j=1. Swap s[0] and s[1] to get s="abc", then reverse the suffix starting at 1. Now, s="acb".\nOperation 5: i=2, j=2. Swap s[1] and s[2] to get s="abc", then reverse the suffix starting at 2. Now, s="abc".\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "aabaa"\nOutput: 2\nExplanation: The simulation goes as follows:\nOperation 1: i=3, j=4. Swap s[2] and s[4] to get s="aaaab", then reverse the substring starting at 3. Now, s="aaaba".\nOperation 2: i=4, j=4. Swap s[3] and s[4] to get s="aaaab", then reverse the substring starting at 4. Now, s="aaaab".\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "cdbea"\nOutput: 63
    \n\n

    Example 4:

    \n\n
    \nInput: s = "leetcodeleetcodeleetcode"\nOutput: 982157772\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 3000
    • \n\t
    • s\u200b\u200b\u200b\u200b\u200b\u200b consists only of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32\u00a0s\u00a0\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\u3002\u4f60\u9700\u8981\u5bf9 s\u00a0\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\u76f4\u5230\u5b83\u53d8\u4e3a\u4e00\u4e2a\u6709\u5e8f\u5b57\u7b26\u4e32\uff1a

    \n\n
      \n\t
    1. \u627e\u5230 \u6700\u5927\u4e0b\u6807\u00a0i\u00a0\uff0c\u4f7f\u5f97\u00a01 <= i < s.length \u4e14\u00a0s[i] < s[i - 1]\u00a0\u3002
    2. \n\t
    3. \u627e\u5230 \u6700\u5927\u4e0b\u6807\u00a0j\u00a0\uff0c\u4f7f\u5f97\u00a0i <= j < s.length \u4e14\u5bf9\u4e8e\u6240\u6709\u5728\u95ed\u533a\u95f4\u00a0[i, j]\u00a0\u4e4b\u95f4\u7684\u00a0k\u00a0\u90fd\u6709\u00a0s[k] < s[i - 1]\u00a0\u3002
    4. \n\t
    5. \u4ea4\u6362\u4e0b\u6807\u4e3a\u00a0i - 1\u200b\u200b\u200b\u200b \u548c\u00a0j\u200b\u200b\u200b\u200b \u5904\u7684\u4e24\u4e2a\u5b57\u7b26\u3002
    6. \n\t
    7. \u5c06\u4e0b\u6807 i\u00a0\u5f00\u59cb\u7684\u5b57\u7b26\u4e32\u540e\u7f00\u53cd\u8f6c\u3002
    8. \n
    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u5c06\u5b57\u7b26\u4e32\u53d8\u6210\u6709\u5e8f\u7684\u6700\u5c11\u64cd\u4f5c\u6b21\u6570\u3002\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u4f1a\u5f88\u5927\uff0c\u8bf7\u8fd4\u56de\u5b83\u5bf9\u00a0109 + 7\u00a0\u53d6\u4f59\u00a0\u7684\u7ed3\u679c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1as = \"cba\"\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u6a21\u62df\u8fc7\u7a0b\u5982\u4e0b\u6240\u793a\uff1a\n\u64cd\u4f5c 1\uff1ai=2\uff0cj=2\u3002\u4ea4\u6362 s[1] \u548c s[2] \u5f97\u5230 s=\"cab\" \uff0c\u7136\u540e\u53cd\u8f6c\u4e0b\u6807\u4ece 2 \u5f00\u59cb\u7684\u540e\u7f00\u5b57\u7b26\u4e32\uff0c\u5f97\u5230 s=\"cab\" \u3002\n\u64cd\u4f5c 2\uff1ai=1\uff0cj=2\u3002\u4ea4\u6362 s[0] \u548c s[2] \u5f97\u5230 s=\"bac\" \uff0c\u7136\u540e\u53cd\u8f6c\u4e0b\u6807\u4ece 1 \u5f00\u59cb\u7684\u540e\u7f00\u5b57\u7b26\u4e32\uff0c\u5f97\u5230 s=\"bca\" \u3002\n\u64cd\u4f5c 3\uff1ai=2\uff0cj=2\u3002\u4ea4\u6362 s[1] \u548c s[2] \u5f97\u5230 s=\"bac\" \uff0c\u7136\u540e\u53cd\u8f6c\u4e0b\u6807\u4ece 2 \u5f00\u59cb\u7684\u540e\u7f00\u5b57\u7b26\u4e32\uff0c\u5f97\u5230 s=\"bac\" \u3002\n\u64cd\u4f5c 4\uff1ai=1\uff0cj=1\u3002\u4ea4\u6362 s[0] \u548c s[1] \u5f97\u5230 s=\"abc\" \uff0c\u7136\u540e\u53cd\u8f6c\u4e0b\u6807\u4ece 1 \u5f00\u59cb\u7684\u540e\u7f00\u5b57\u7b26\u4e32\uff0c\u5f97\u5230 s=\"acb\" \u3002\n\u64cd\u4f5c 5\uff1ai=2\uff0cj=2\u3002\u4ea4\u6362 s[1] \u548c s[2] \u5f97\u5230 s=\"abc\" \uff0c\u7136\u540e\u53cd\u8f6c\u4e0b\u6807\u4ece 2 \u5f00\u59cb\u7684\u540e\u7f00\u5b57\u7b26\u4e32\uff0c\u5f97\u5230 s=\"abc\" \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1as = \"aabaa\"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6a21\u62df\u8fc7\u7a0b\u5982\u4e0b\u6240\u793a\uff1a\n\u64cd\u4f5c 1\uff1ai=3\uff0cj=4\u3002\u4ea4\u6362 s[2] \u548c s[4] \u5f97\u5230 s=\"aaaab\" \uff0c\u7136\u540e\u53cd\u8f6c\u4e0b\u6807\u4ece 3 \u5f00\u59cb\u7684\u540e\u7f00\u5b57\u7b26\u4e32\uff0c\u5f97\u5230 s=\"aaaba\" \u3002\n\u64cd\u4f5c 2\uff1ai=4\uff0cj=4\u3002\u4ea4\u6362 s[3] \u548c s[4] \u5f97\u5230 s=\"aaaab\" \uff0c\u7136\u540e\u53cd\u8f6c\u4e0b\u6807\u4ece 4 \u5f00\u59cb\u7684\u540e\u7f00\u5b57\u7b26\u4e32\uff0c\u5f97\u5230 s=\"aaaab\" \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1as = \"cdbea\"\n\u8f93\u51fa\uff1a63
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1as = \"leetcodeleetcodeleetcode\"\n\u8f93\u51fa\uff1a982157772\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 3000
    • \n\t
    • s\u200b \u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    • \n
    \n", "tags_en": ["Math", "String"], "tags_cn": ["\u6570\u5b66", "\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int makeStringSorted(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int makeStringSorted(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def makeStringSorted(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def makeStringSorted(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint makeStringSorted(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MakeStringSorted(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar makeStringSorted = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef make_string_sorted(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func makeStringSorted(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func makeStringSorted(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def makeStringSorted(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun makeStringSorted(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn make_string_sorted(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function makeStringSorted($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function makeStringSorted(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (make-string-sorted s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1830](https://leetcode-cn.com/problems/minimum-number-of-operations-to-make-string-sorted)", "[\u4f7f\u5b57\u7b26\u4e32\u6709\u5e8f\u7684\u6700\u5c11\u64cd\u4f5c\u6b21\u6570](/solution/1800-1899/1830.Minimum%20Number%20of%20Operations%20to%20Make%20String%20Sorted/README.md)", "`\u6570\u5b66`,`\u5b57\u7b26\u4e32`", "\u56f0\u96be", ""], "md_table_row_en": ["[1830](https://leetcode.com/problems/minimum-number-of-operations-to-make-string-sorted)", "[Minimum Number of Operations to Make String Sorted](/solution/1800-1899/1830.Minimum%20Number%20of%20Operations%20to%20Make%20String%20Sorted/README_EN.md)", "`Math`,`String`", "Hard", ""]}, {"question_id": "1940", "frontend_question_id": "1829", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-xor-for-each-query", "url_en": "https://leetcode.com/problems/maximum-xor-for-each-query", "relative_path_cn": "/solution/1800-1899/1829.Maximum%20XOR%20for%20Each%20Query/README.md", "relative_path_en": "/solution/1800-1899/1829.Maximum%20XOR%20for%20Each%20Query/README_EN.md", "title_cn": "\u6bcf\u4e2a\u67e5\u8be2\u7684\u6700\u5927\u5f02\u6216\u503c", "title_en": "Maximum XOR for Each Query", "question_title_slug": "maximum-xor-for-each-query", "content_en": "

    You are given a sorted array nums of n non-negative integers and an integer maximumBit. You want to perform the following query n times:

    \n\n
      \n\t
    1. Find a non-negative integer k < 2maximumBit such that nums[0] XOR nums[1] XOR ... XOR nums[nums.length-1] XOR k is maximized. k is the answer to the ith query.
    2. \n\t
    3. Remove the last element from the current array nums.
    4. \n
    \n\n

    Return an array answer, where answer[i] is the answer to the ith query.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [0,1,1,3], maximumBit = 2\nOutput: [0,3,2,3]\nExplanation: The queries are answered as follows:\n1st query: nums = [0,1,1,3], k = 0 since 0 XOR 1 XOR 1 XOR 3 XOR 0 = 3.\n2nd query: nums = [0,1,1], k = 3 since 0 XOR 1 XOR 1 XOR 3 = 3.\n3rd query: nums = [0,1], k = 2 since 0 XOR 1 XOR 2 = 3.\n4th query: nums = [0], k = 3 since 0 XOR 3 = 3.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [2,3,4,7], maximumBit = 3\nOutput: [5,2,6,5]\nExplanation: The queries are answered as follows:\n1st query: nums = [2,3,4,7], k = 5 since 2 XOR 3 XOR 4 XOR 7 XOR 5 = 7.\n2nd query: nums = [2,3,4], k = 2 since 2 XOR 3 XOR 4 XOR 2 = 7.\n3rd query: nums = [2,3], k = 6 since 2 XOR 3 XOR 6 = 7.\n4th query: nums = [2], k = 5 since 2 XOR 5 = 7.\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [0,1,2,2,5,7], maximumBit = 3\nOutput: [4,3,6,4,6,7]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • nums.length == n
    • \n\t
    • 1 <= n <= 105
    • \n\t
    • 1 <= maximumBit <= 20
    • \n\t
    • 0 <= nums[i] < 2maximumBit
    • \n\t
    • nums\u200b\u200b\u200b is sorted in ascending order.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a \u6709\u5e8f\u00a0\u6570\u7ec4\u00a0nums\u00a0\uff0c\u5b83\u7531\u00a0n\u00a0\u4e2a\u975e\u8d1f\u6574\u6570\u7ec4\u6210\uff0c\u540c\u65f6\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u00a0maximumBit\u00a0\u3002\u4f60\u9700\u8981\u6267\u884c\u4ee5\u4e0b\u67e5\u8be2 n\u00a0\u6b21\uff1a

    \n\n
      \n\t
    1. \u627e\u5230\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\u00a0k < 2maximumBit\u00a0\uff0c\u4f7f\u5f97\u00a0nums[0] XOR nums[1] XOR ... XOR nums[nums.length-1] XOR k\u00a0\u7684\u7ed3\u679c \u6700\u5927\u5316\u00a0\u3002k\u00a0\u662f\u7b2c i\u00a0\u4e2a\u67e5\u8be2\u7684\u7b54\u6848\u3002
    2. \n\t
    3. \u4ece\u5f53\u524d\u6570\u7ec4\u00a0nums\u00a0\u5220\u9664\u00a0\u6700\u540e\u00a0\u4e00\u4e2a\u5143\u7d20\u3002
    4. \n
    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u4e00\u4e2a\u6570\u7ec4\u00a0answer\u00a0\uff0c\u5176\u4e2d\u00a0answer[i]\u662f\u7b2c\u00a0i\u00a0\u4e2a\u67e5\u8be2\u7684\u7ed3\u679c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [0,1,1,3], maximumBit = 2\n\u8f93\u51fa\uff1a[0,3,2,3]\n\u89e3\u91ca\uff1a\u67e5\u8be2\u7684\u7b54\u6848\u5982\u4e0b\uff1a\n\u7b2c\u4e00\u4e2a\u67e5\u8be2\uff1anums = [0,1,1,3]\uff0ck = 0\uff0c\u56e0\u4e3a 0 XOR 1 XOR 1 XOR 3 XOR 0 = 3 \u3002\n\u7b2c\u4e8c\u4e2a\u67e5\u8be2\uff1anums = [0,1,1]\uff0ck = 3\uff0c\u56e0\u4e3a 0 XOR 1 XOR 1 XOR 3 = 3 \u3002\n\u7b2c\u4e09\u4e2a\u67e5\u8be2\uff1anums = [0,1]\uff0ck = 2\uff0c\u56e0\u4e3a 0 XOR 1 XOR 2 = 3 \u3002\n\u7b2c\u56db\u4e2a\u67e5\u8be2\uff1anums = [0]\uff0ck = 3\uff0c\u56e0\u4e3a 0 XOR 3 = 3 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [2,3,4,7], maximumBit = 3\n\u8f93\u51fa\uff1a[5,2,6,5]\n\u89e3\u91ca\uff1a\u67e5\u8be2\u7684\u7b54\u6848\u5982\u4e0b\uff1a\n\u7b2c\u4e00\u4e2a\u67e5\u8be2\uff1anums = [2,3,4,7]\uff0ck = 5\uff0c\u56e0\u4e3a 2 XOR 3 XOR 4 XOR 7 XOR 5 = 7\u3002\n\u7b2c\u4e8c\u4e2a\u67e5\u8be2\uff1anums = [2,3,4]\uff0ck = 2\uff0c\u56e0\u4e3a 2 XOR 3 XOR 4 XOR 2 = 7 \u3002\n\u7b2c\u4e09\u4e2a\u67e5\u8be2\uff1anums = [2,3]\uff0ck = 6\uff0c\u56e0\u4e3a 2 XOR 3 XOR 6 = 7 \u3002\n\u7b2c\u56db\u4e2a\u67e5\u8be2\uff1anums = [2]\uff0ck = 5\uff0c\u56e0\u4e3a 2 XOR 5 = 7 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [0,1,2,2,5,7], maximumBit = 3\n\u8f93\u51fa\uff1a[4,3,6,4,6,7]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • nums.length == n
    • \n\t
    • 1 <= n <= 105
    • \n\t
    • 1 <= maximumBit <= 20
    • \n\t
    • 0 <= nums[i] < 2maximumBit
    • \n\t
    • nums\u200b\u200b\u200b \u4e2d\u7684\u6570\u5b57\u5df2\u7ecf\u6309\u00a0\u5347\u5e8f\u00a0\u6392\u597d\u5e8f\u3002
    • \n
    \n", "tags_en": ["Bit Manipulation"], "tags_cn": ["\u4f4d\u8fd0\u7b97"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector getMaximumXor(vector& nums, int maximumBit) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] getMaximumXor(int[] nums, int maximumBit) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getMaximumXor(self, nums, maximumBit):\n \"\"\"\n :type nums: List[int]\n :type maximumBit: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getMaximumXor(self, nums: List[int], maximumBit: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* getMaximumXor(int* nums, int numsSize, int maximumBit, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] GetMaximumXor(int[] nums, int maximumBit) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} maximumBit\n * @return {number[]}\n */\nvar getMaximumXor = function(nums, maximumBit) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} maximum_bit\n# @return {Integer[]}\ndef get_maximum_xor(nums, maximum_bit)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getMaximumXor(_ nums: [Int], _ maximumBit: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getMaximumXor(nums []int, maximumBit int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getMaximumXor(nums: Array[Int], maximumBit: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getMaximumXor(nums: IntArray, maximumBit: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_maximum_xor(nums: Vec, maximum_bit: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $maximumBit\n * @return Integer[]\n */\n function getMaximumXor($nums, $maximumBit) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getMaximumXor(nums: number[], maximumBit: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-maximum-xor nums maximumBit)\n (-> (listof exact-integer?) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1829](https://leetcode-cn.com/problems/maximum-xor-for-each-query)", "[\u6bcf\u4e2a\u67e5\u8be2\u7684\u6700\u5927\u5f02\u6216\u503c](/solution/1800-1899/1829.Maximum%20XOR%20for%20Each%20Query/README.md)", "`\u4f4d\u8fd0\u7b97`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1829](https://leetcode.com/problems/maximum-xor-for-each-query)", "[Maximum XOR for Each Query](/solution/1800-1899/1829.Maximum%20XOR%20for%20Each%20Query/README_EN.md)", "`Bit Manipulation`", "Medium", ""]}, {"question_id": "1939", "frontend_question_id": "1828", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/queries-on-number-of-points-inside-a-circle", "url_en": "https://leetcode.com/problems/queries-on-number-of-points-inside-a-circle", "relative_path_cn": "/solution/1800-1899/1828.Queries%20on%20Number%20of%20Points%20Inside%20a%20Circle/README.md", "relative_path_en": "/solution/1800-1899/1828.Queries%20on%20Number%20of%20Points%20Inside%20a%20Circle/README_EN.md", "title_cn": "\u7edf\u8ba1\u4e00\u4e2a\u5706\u4e2d\u70b9\u7684\u6570\u76ee", "title_en": "Queries on Number of Points Inside a Circle", "question_title_slug": "queries-on-number-of-points-inside-a-circle", "content_en": "

    You are given an array points where points[i] = [xi, yi] is the coordinates of the ith point on a 2D plane. Multiple points can have the same coordinates.

    \n\n

    You are also given an array queries where queries[j] = [xj, yj, rj] describes a circle centered at (xj, yj) with a radius of rj.

    \n\n

    For each query queries[j], compute the number of points inside the jth circle. Points on the border of the circle are considered inside.

    \n\n

    Return an array answer, where answer[j] is the answer to the jth query.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: points = [[1,3],[3,3],[5,3],[2,2]], queries = [[2,3,1],[4,3,1],[1,1,2]]\nOutput: [3,2,2]\nExplanation: The points and circles are shown above.\nqueries[0] is the green circle, queries[1] is the red circle, and queries[2] is the blue circle.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: points = [[1,1],[2,2],[3,3],[4,4],[5,5]], queries = [[1,2,2],[2,2,2],[4,3,2],[4,3,3]]\nOutput: [2,3,2,4]\nExplanation: The points and circles are shown above.\nqueries[0] is green, queries[1] is red, queries[2] is blue, and queries[3] is purple.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= points.length <= 500
    • \n\t
    • points[i].length == 2
    • \n\t
    • 0 <= x\u200b\u200b\u200b\u200b\u200b\u200bi, y\u200b\u200b\u200b\u200b\u200b\u200bi <= 500
    • \n\t
    • 1 <= queries.length <= 500
    • \n\t
    • queries[j].length == 3
    • \n\t
    • 0 <= xj, yj <= 500
    • \n\t
    • 1 <= rj <= 500
    • \n\t
    • All coordinates are integers.
    • \n
    \n\n

     

    \n

    Follow up: Could you find the answer for each query in better complexity than O(n)?

    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4\u00a0points\u00a0\uff0c\u5176\u4e2d\u00a0points[i] = [xi, yi]\u00a0\uff0c\u8868\u793a\u7b2c\u00a0i\u00a0\u4e2a\u70b9\u5728\u4e8c\u7ef4\u5e73\u9762\u4e0a\u7684\u5750\u6807\u3002\u591a\u4e2a\u70b9\u53ef\u80fd\u4f1a\u6709 \u76f8\u540c\u00a0\u7684\u5750\u6807\u3002

    \n\n

    \u540c\u65f6\u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4\u00a0queries\u00a0\uff0c\u5176\u4e2d\u00a0queries[j] = [xj, yj, rj]\u00a0\uff0c\u8868\u793a\u4e00\u4e2a\u5706\u5fc3\u5728\u00a0(xj, yj)\u00a0\u4e14\u534a\u5f84\u4e3a\u00a0rj\u00a0\u7684\u5706\u3002

    \n\n

    \u5bf9\u4e8e\u6bcf\u4e00\u4e2a\u67e5\u8be2\u00a0queries[j]\u00a0\uff0c\u8ba1\u7b97\u5728\u7b2c j\u00a0\u4e2a\u5706 \u5185\u00a0\u70b9\u7684\u6570\u76ee\u3002\u5982\u679c\u4e00\u4e2a\u70b9\u5728\u5706\u7684 \u8fb9\u754c\u4e0a\u00a0\uff0c\u6211\u4eec\u540c\u6837\u8ba4\u4e3a\u5b83\u5728\u5706\u00a0\u5185\u00a0\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u4e00\u4e2a\u6570\u7ec4\u00a0answer\u00a0\uff0c\u5176\u4e2d\u00a0answer[j]\u662f\u7b2c\u00a0j\u00a0\u4e2a\u67e5\u8be2\u7684\u7b54\u6848\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \u8f93\u5165\uff1apoints = [[1,3],[3,3],[5,3],[2,2]], queries = [[2,3,1],[4,3,1],[1,1,2]]\n\u8f93\u51fa\uff1a[3,2,2]\n\u89e3\u91ca\uff1a\u6240\u6709\u7684\u70b9\u548c\u5706\u5982\u4e0a\u56fe\u6240\u793a\u3002\nqueries[0] \u662f\u7eff\u8272\u7684\u5706\uff0cqueries[1] \u662f\u7ea2\u8272\u7684\u5706\uff0cqueries[2] \u662f\u84dd\u8272\u7684\u5706\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \u8f93\u5165\uff1apoints = [[1,1],[2,2],[3,3],[4,4],[5,5]], queries = [[1,2,2],[2,2,2],[4,3,2],[4,3,3]]\n\u8f93\u51fa\uff1a[2,3,2,4]\n\u89e3\u91ca\uff1a\u6240\u6709\u7684\u70b9\u548c\u5706\u5982\u4e0a\u56fe\u6240\u793a\u3002\nqueries[0] \u662f\u7eff\u8272\u7684\u5706\uff0cqueries[1] \u662f\u7ea2\u8272\u7684\u5706\uff0cqueries[2] \u662f\u84dd\u8272\u7684\u5706\uff0cqueries[3] \u662f\u7d2b\u8272\u7684\u5706\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= points.length <= 500
    • \n\t
    • points[i].length == 2
    • \n\t
    • 0 <= x\u200b\u200b\u200b\u200b\u200b\u200bi, y\u200b\u200b\u200b\u200b\u200b\u200bi <= 500
    • \n\t
    • 1 <= queries.length <= 500
    • \n\t
    • queries[j].length == 3
    • \n\t
    • 0 <= xj, yj <= 500
    • \n\t
    • 1 <= rj <= 500
    • \n\t
    • \u6240\u6709\u7684\u5750\u6807\u90fd\u662f\u6574\u6570\u3002
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector countPoints(vector>& points, vector>& queries) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] countPoints(int[][] points, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countPoints(self, points, queries):\n \"\"\"\n :type points: List[List[int]]\n :type queries: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countPoints(self, points: List[List[int]], queries: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* countPoints(int** points, int pointsSize, int* pointsColSize, int** queries, int queriesSize, int* queriesColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] CountPoints(int[][] points, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} points\n * @param {number[][]} queries\n * @return {number[]}\n */\nvar countPoints = function(points, queries) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} points\n# @param {Integer[][]} queries\n# @return {Integer[]}\ndef count_points(points, queries)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countPoints(_ points: [[Int]], _ queries: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countPoints(points [][]int, queries [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countPoints(points: Array[Array[Int]], queries: Array[Array[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countPoints(points: Array, queries: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_points(points: Vec>, queries: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $points\n * @param Integer[][] $queries\n * @return Integer[]\n */\n function countPoints($points, $queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countPoints(points: number[][], queries: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-points points queries)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1828](https://leetcode-cn.com/problems/queries-on-number-of-points-inside-a-circle)", "[\u7edf\u8ba1\u4e00\u4e2a\u5706\u4e2d\u70b9\u7684\u6570\u76ee](/solution/1800-1899/1828.Queries%20on%20Number%20of%20Points%20Inside%20a%20Circle/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1828](https://leetcode.com/problems/queries-on-number-of-points-inside-a-circle)", "[Queries on Number of Points Inside a Circle](/solution/1800-1899/1828.Queries%20on%20Number%20of%20Points%20Inside%20a%20Circle/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "1938", "frontend_question_id": "1827", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-operations-to-make-the-array-increasing", "url_en": "https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing", "relative_path_cn": "/solution/1800-1899/1827.Minimum%20Operations%20to%20Make%20the%20Array%20Increasing/README.md", "relative_path_en": "/solution/1800-1899/1827.Minimum%20Operations%20to%20Make%20the%20Array%20Increasing/README_EN.md", "title_cn": "\u6700\u5c11\u64cd\u4f5c\u4f7f\u6570\u7ec4\u9012\u589e", "title_en": "Minimum Operations to Make the Array Increasing", "question_title_slug": "minimum-operations-to-make-the-array-increasing", "content_en": "

    You are given an integer array nums (0-indexed). In one operation, you can choose an element of the array and increment it by 1.

    \r\n\r\n
      \r\n\t
    • For example, if nums = [1,2,3], you can choose to increment nums[1] to make nums = [1,3,3].
    • \r\n
    \r\n\r\n

    Return the minimum number of operations needed to make nums strictly increasing.

    \r\n\r\n

    An array nums is strictly increasing if nums[i] < nums[i+1] for all 0 <= i < nums.length - 1. An array of length 1 is trivially strictly increasing.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: nums = [1,1,1]\r\nOutput: 3\r\nExplanation: You can do the following operations:\r\n1) Increment nums[2], so nums becomes [1,1,2].\r\n2) Increment nums[1], so nums becomes [1,2,2].\r\n3) Increment nums[2], so nums becomes [1,2,3].\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: nums = [1,5,2,4,1]\r\nOutput: 14\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: nums = [8]\r\nOutput: 0\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= nums.length <= 5000
    • \r\n\t
    • 1 <= nums[i] <= 104
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0nums\u00a0\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\u3002\u6bcf\u4e00\u6b21\u64cd\u4f5c\u4e2d\uff0c\u4f60\u53ef\u4ee5\u9009\u62e9\u6570\u7ec4\u4e2d\u4e00\u4e2a\u5143\u7d20\uff0c\u5e76\u5c06\u5b83\u589e\u52a0\u00a01\u00a0\u3002

    \n\n
      \n\t
    • \u6bd4\u65b9\u8bf4\uff0c\u5982\u679c\u00a0nums = [1,2,3]\u00a0\uff0c\u4f60\u53ef\u4ee5\u9009\u62e9\u589e\u52a0\u00a0nums[1]\u00a0\u5f97\u5230\u00a0nums = [1,3,3]\u00a0\u3002
    • \n
    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u4f7f nums\u00a0\u4e25\u683c\u9012\u589e\u00a0\u7684 \u6700\u5c11\u00a0\u64cd\u4f5c\u6b21\u6570\u3002

    \n\n

    \u6211\u4eec\u79f0\u6570\u7ec4\u00a0nums\u00a0\u662f \u4e25\u683c\u9012\u589e\u7684\u00a0\uff0c\u5f53\u5b83\u6ee1\u8db3\u5bf9\u4e8e\u6240\u6709\u7684\u00a00 <= i < nums.length - 1\u00a0\u90fd\u6709\u00a0nums[i] < nums[i+1]\u00a0\u3002\u4e00\u4e2a\u957f\u5ea6\u4e3a 1\u00a0\u7684\u6570\u7ec4\u662f\u4e25\u683c\u9012\u589e\u7684\u4e00\u79cd\u7279\u6b8a\u60c5\u51b5\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,1,1]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u8fdb\u884c\u5982\u4e0b\u64cd\u4f5c\uff1a\n1) \u589e\u52a0 nums[2] \uff0c\u6570\u7ec4\u53d8\u4e3a [1,1,2] \u3002\n2) \u589e\u52a0 nums[1] \uff0c\u6570\u7ec4\u53d8\u4e3a [1,2,2] \u3002\n3) \u589e\u52a0 nums[2] \uff0c\u6570\u7ec4\u53d8\u4e3a [1,2,3] \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,5,2,4,1]\n\u8f93\u51fa\uff1a14\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [8]\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 5000
    • \n\t
    • 1 <= nums[i] <= 104
    • \n
    \n", "tags_en": ["Greedy", "Array"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minOperations(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minOperations(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minOperations(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minOperations(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minOperations(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinOperations(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar minOperations = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef min_operations(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minOperations(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minOperations(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minOperations(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minOperations(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_operations(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function minOperations($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minOperations(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-operations nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1827](https://leetcode-cn.com/problems/minimum-operations-to-make-the-array-increasing)", "[\u6700\u5c11\u64cd\u4f5c\u4f7f\u6570\u7ec4\u9012\u589e](/solution/1800-1899/1827.Minimum%20Operations%20to%20Make%20the%20Array%20Increasing/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1827](https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing)", "[Minimum Operations to Make the Array Increasing](/solution/1800-1899/1827.Minimum%20Operations%20to%20Make%20the%20Array%20Increasing/README_EN.md)", "`Greedy`,`Array`", "Easy", ""]}, {"question_id": "1937", "frontend_question_id": "1788", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/maximize-the-beauty-of-the-garden", "url_en": "https://leetcode.com/problems/maximize-the-beauty-of-the-garden", "relative_path_cn": "/solution/1700-1799/1788.Maximize%20the%20Beauty%20of%20the%20Garden/README.md", "relative_path_en": "/solution/1700-1799/1788.Maximize%20the%20Beauty%20of%20the%20Garden/README_EN.md", "title_cn": "", "title_en": "Maximize the Beauty of the Garden", "question_title_slug": "maximize-the-beauty-of-the-garden", "content_en": "

    There is a garden of n flowers, and each flower has an integer beauty value. The flowers are arranged in a line. You are given an integer array flowers of size n and each flowers[i] represents the beauty of the ith flower.

    \r\n\r\n

    A garden is valid if it meets these conditions:

    \r\n\r\n
      \r\n\t
    • The garden has at least two flowers.
    • \r\n\t
    • The first and the last flower of the garden have the same beauty value.
    • \r\n
    \r\n\r\n

    As the appointed gardener, you have the ability to remove any (possibly none) flowers from the garden. You want to remove flowers in a way that makes the remaining garden valid. The beauty of the garden is the sum of the beauty of all the remaining flowers.

    \r\n\r\n

    Return the maximum possible beauty of some valid garden after you have removed any (possibly none) flowers.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: flowers = [1,2,3,1,2]\r\nOutput: 8\r\nExplanation: You can produce the valid garden [2,3,1,2] to have a total beauty of 2 + 3 + 1 + 2 = 8.
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: flowers = [100,1,1,-3,1]\r\nOutput: 3\r\nExplanation: You can produce the valid garden [1,1,1] to have a total beauty of 1 + 1 + 1 = 3.\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: flowers = [-1,-2,0,-1]\r\nOutput: -2\r\nExplanation: You can produce the valid garden [-1,-1] to have a total beauty of -1 + -1 = -2.\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 2 <= flowers.length <= 105
    • \r\n\t
    • -104 <= flowers[i] <= 104
    • \r\n\t
    • It is possible to create a valid garden by removing some (possibly none) flowers.
    • \r\n
    ", "content_cn": null, "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maximumBeauty(vector& flowers) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maximumBeauty(int[] flowers) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximumBeauty(self, flowers):\n \"\"\"\n :type flowers: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximumBeauty(self, flowers: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maximumBeauty(int* flowers, int flowersSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaximumBeauty(int[] flowers) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} flowers\n * @return {number}\n */\nvar maximumBeauty = function(flowers) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} flowers\n# @return {Integer}\ndef maximum_beauty(flowers)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximumBeauty(_ flowers: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximumBeauty(flowers []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximumBeauty(flowers: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximumBeauty(flowers: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximum_beauty(flowers: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $flowers\n * @return Integer\n */\n function maximumBeauty($flowers) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximumBeauty(flowers: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximum-beauty flowers)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1788](https://leetcode-cn.com/problems/maximize-the-beauty-of-the-garden)", "[Maximize the Beauty of the Garden](/solution/1700-1799/1788.Maximize%20the%20Beauty%20of%20the%20Garden/README_EN.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1788](https://leetcode.com/problems/maximize-the-beauty-of-the-garden)", "[Maximize the Beauty of the Garden](/solution/1700-1799/1788.Maximize%20the%20Beauty%20of%20the%20Garden/README_EN.md)", "`Greedy`", "Hard", "\ud83d\udd12"]}, {"question_id": "1936", "frontend_question_id": "1808", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximize-number-of-nice-divisors", "url_en": "https://leetcode.com/problems/maximize-number-of-nice-divisors", "relative_path_cn": "/solution/1800-1899/1808.Maximize%20Number%20of%20Nice%20Divisors/README.md", "relative_path_en": "/solution/1800-1899/1808.Maximize%20Number%20of%20Nice%20Divisors/README_EN.md", "title_cn": "\u597d\u56e0\u5b50\u7684\u6700\u5927\u6570\u76ee", "title_en": "Maximize Number of Nice Divisors", "question_title_slug": "maximize-number-of-nice-divisors", "content_en": "

    You are given a positive integer primeFactors. You are asked to construct a positive integer n that satisfies the following conditions:

    \r\n\r\n
      \r\n
    • The number of prime factors of n (not necessarily distinct) is at most primeFactors.
    • \r\n
    • The number of nice divisors of n is maximized. Note that a divisor of n is nice if it is divisible by every prime factor of n. For example, if n = 12, then its prime factors are [2,2,3], then 6 and 12 are nice divisors, while 3 and 4 are not.
    • \r\n
    \r\n\r\n

    Return the number of nice divisors of n. Since that number can be too large, return it modulo 109 + 7.

    \r\n\r\n

    Note that a prime number is a natural number greater than 1 that is not a product of two smaller natural numbers. The prime factors of a number n is a list of prime numbers such that their product equals n.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: primeFactors = 5\r\nOutput: 6\r\nExplanation: 200 is a valid value of n.\r\nIt has 5 prime factors: [2,2,2,5,5], and it has 6 nice divisors: [10,20,40,50,100,200].\r\nThere is not other value of n that has at most 5 prime factors and more nice divisors.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: primeFactors = 8\r\nOutput: 18\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= primeFactors <= 109
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6b63\u6574\u6570\u00a0primeFactors\u00a0\u3002\u4f60\u9700\u8981\u6784\u9020\u4e00\u4e2a\u6b63\u6574\u6570\u00a0n\u00a0\uff0c\u5b83\u6ee1\u8db3\u4ee5\u4e0b\u6761\u4ef6\uff1a

    \n\n
      \n\t
    • n\u00a0\u8d28\u56e0\u6570\uff08\u8d28\u56e0\u6570\u9700\u8981\u8003\u8651\u91cd\u590d\u7684\u60c5\u51b5\uff09\u7684\u6570\u76ee \u4e0d\u8d85\u8fc7\u00a0primeFactors\u00a0\u4e2a\u3002
    • \n\t
    • n\u00a0\u597d\u56e0\u5b50\u7684\u6570\u76ee\u6700\u5927\u5316\u3002\u5982\u679c n\u00a0\u7684\u4e00\u4e2a\u56e0\u5b50\u53ef\u4ee5\u88ab n\u00a0\u7684\u6bcf\u4e00\u4e2a\u8d28\u56e0\u6570\u6574\u9664\uff0c\u6211\u4eec\u79f0\u8fd9\u4e2a\u56e0\u5b50\u662f \u597d\u56e0\u5b50 \u3002\u6bd4\u65b9\u8bf4\uff0c\u5982\u679c\u00a0n = 12\u00a0\uff0c\u90a3\u4e48\u5b83\u7684\u8d28\u56e0\u6570\u4e3a\u00a0[2,2,3]\u00a0\uff0c\u90a3\u4e48\u00a06\u00a0\u548c\u00a012\u00a0\u662f\u597d\u56e0\u5b50\uff0c\u4f46\u00a03 \u548c\u00a04\u00a0\u4e0d\u662f\u3002
    • \n
    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u00a0n\u00a0\u7684\u597d\u56e0\u5b50\u7684\u6570\u76ee\u3002\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u4f1a\u5f88\u5927\uff0c\u8bf7\u8fd4\u56de\u7b54\u6848\u5bf9\u00a0109 + 7\u00a0\u53d6\u4f59\u00a0\u7684\u7ed3\u679c\u3002

    \n\n

    \u8bf7\u6ce8\u610f\uff0c\u4e00\u4e2a\u8d28\u6570\u7684\u5b9a\u4e49\u662f\u5927\u4e8e 1\u00a0\uff0c\u4e14\u4e0d\u80fd\u88ab\u5206\u89e3\u4e3a\u4e24\u4e2a\u5c0f\u4e8e\u8be5\u6570\u7684\u81ea\u7136\u6570\u76f8\u4e58\u3002\u4e00\u4e2a\u6570 n\u00a0\u7684\u8d28\u56e0\u5b50\u662f\u5c06 n\u00a0\u5206\u89e3\u4e3a\u82e5\u5e72\u4e2a\u8d28\u56e0\u5b50\uff0c\u4e14\u5b83\u4eec\u7684\u4e58\u79ef\u4e3a n\u00a0\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aprimeFactors = 5\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a200 \u662f\u4e00\u4e2a\u53ef\u884c\u7684 n \u3002\n\u5b83\u6709 5 \u4e2a\u8d28\u56e0\u5b50\uff1a[2,2,2,5,5] \uff0c\u4e14\u6709 6 \u4e2a\u597d\u56e0\u5b50\uff1a[10,20,40,50,100,200] \u3002\n\u4e0d\u5b58\u5728\u522b\u7684 n \u6709\u81f3\u591a 5 \u4e2a\u8d28\u56e0\u5b50\uff0c\u4e14\u540c\u65f6\u6709\u66f4\u591a\u7684\u597d\u56e0\u5b50\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aprimeFactors = 8\n\u8f93\u51fa\uff1a18\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= primeFactors <= 109
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxNiceDivisors(int primeFactors) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxNiceDivisors(int primeFactors) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxNiceDivisors(self, primeFactors):\n \"\"\"\n :type primeFactors: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxNiceDivisors(self, primeFactors: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxNiceDivisors(int primeFactors){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxNiceDivisors(int primeFactors) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} primeFactors\n * @return {number}\n */\nvar maxNiceDivisors = function(primeFactors) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} prime_factors\n# @return {Integer}\ndef max_nice_divisors(prime_factors)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxNiceDivisors(_ primeFactors: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxNiceDivisors(primeFactors int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxNiceDivisors(primeFactors: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxNiceDivisors(primeFactors: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_nice_divisors(prime_factors: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $primeFactors\n * @return Integer\n */\n function maxNiceDivisors($primeFactors) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxNiceDivisors(primeFactors: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-nice-divisors primeFactors)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1808](https://leetcode-cn.com/problems/maximize-number-of-nice-divisors)", "[\u597d\u56e0\u5b50\u7684\u6700\u5927\u6570\u76ee](/solution/1800-1899/1808.Maximize%20Number%20of%20Nice%20Divisors/README.md)", "`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[1808](https://leetcode.com/problems/maximize-number-of-nice-divisors)", "[Maximize Number of Nice Divisors](/solution/1800-1899/1808.Maximize%20Number%20of%20Nice%20Divisors/README_EN.md)", "`Math`", "Hard", ""]}, {"question_id": "1935", "frontend_question_id": "1806", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-number-of-operations-to-reinitialize-a-permutation", "url_en": "https://leetcode.com/problems/minimum-number-of-operations-to-reinitialize-a-permutation", "relative_path_cn": "/solution/1800-1899/1806.Minimum%20Number%20of%20Operations%20to%20Reinitialize%20a%20Permutation/README.md", "relative_path_en": "/solution/1800-1899/1806.Minimum%20Number%20of%20Operations%20to%20Reinitialize%20a%20Permutation/README_EN.md", "title_cn": "\u8fd8\u539f\u6392\u5217\u7684\u6700\u5c11\u64cd\u4f5c\u6b65\u6570", "title_en": "Minimum Number of Operations to Reinitialize a Permutation", "question_title_slug": "minimum-number-of-operations-to-reinitialize-a-permutation", "content_en": "

    You are given an even integer n\u200b\u200b\u200b\u200b\u200b\u200b. You initially have a permutation perm of size n\u200b\u200b where perm[i] == i\u200b (0-indexed)\u200b\u200b\u200b\u200b.

    \n\n

    In one operation, you will create a new array arr, and for each i:

    \n\n
      \n\t
    • If i % 2 == 0, then arr[i] = perm[i / 2].
    • \n\t
    • If i % 2 == 1, then arr[i] = perm[n / 2 + (i - 1) / 2].
    • \n
    \n\n

    You will then assign arr\u200b\u200b\u200b\u200b to perm.

    \n\n

    Return the minimum non-zero number of operations you need to perform on perm to return the permutation to its initial value.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 2\nOutput: 1\nExplanation: perm = [0,1] initially.\nAfter the 1st operation, perm = [0,1]\nSo it takes only 1 operation.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 4\nOutput: 2\nExplanation: perm = [0,1,2,3] initially.\nAfter the 1st operation, perm = [0,2,1,3]\nAfter the 2nd operation, perm = [0,1,2,3]\nSo it takes only 2 operations.\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 6\nOutput: 4\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= n <= 1000
    • \n\t
    • n\u200b\u200b\u200b\u200b\u200b\u200b is even.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5076\u6570 n\u200b\u200b\u200b\u200b\u200b\u200b \uff0c\u5df2\u77e5\u5b58\u5728\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u6392\u5217 perm \uff0c\u5176\u4e2d perm[i] == i\u200b\uff08\u4e0b\u6807 \u4ece 0 \u5f00\u59cb \u8ba1\u6570\uff09\u3002

    \n\n

    \u4e00\u6b65\u64cd\u4f5c\u4e2d\uff0c\u4f60\u5c06\u521b\u5efa\u4e00\u4e2a\u65b0\u6570\u7ec4 arr \uff0c\u5bf9\u4e8e\u6bcf\u4e2a i \uff1a

    \n\n
      \n\t
    • \u5982\u679c i % 2 == 0 \uff0c\u90a3\u4e48 arr[i] = perm[i / 2]
    • \n\t
    • \u5982\u679c i % 2 == 1 \uff0c\u90a3\u4e48 arr[i] = perm[n / 2 + (i - 1) / 2]
    • \n
    \n\n

    \u7136\u540e\u5c06 arr\u200b\u200b \u8d4b\u503c\u200b\u200b\u7ed9 perm \u3002

    \n\n

    \u8981\u60f3\u4f7f perm \u56de\u5230\u6392\u5217\u521d\u59cb\u503c\uff0c\u81f3\u5c11\u9700\u8981\u6267\u884c\u591a\u5c11\u6b65\u64cd\u4f5c\uff1f\u8fd4\u56de\u6700\u5c0f\u7684 \u975e\u96f6 \u64cd\u4f5c\u6b65\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 2\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u6700\u521d\uff0cperm = [0,1]\n\u7b2c 1\u00a0\u6b65\u64cd\u4f5c\u540e\uff0cperm = [0,1]\n\u6240\u4ee5\uff0c\u4ec5\u9700\u6267\u884c 1 \u6b65\u64cd\u4f5c
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 4\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6700\u521d\uff0cperm = [0,1,2,3]\n\u7b2c 1\u00a0\u6b65\u64cd\u4f5c\u540e\uff0cperm = [0,2,1,3]\n\u7b2c 2\u00a0\u6b65\u64cd\u4f5c\u540e\uff0cperm = [0,1,2,3]\n\u6240\u4ee5\uff0c\u4ec5\u9700\u6267\u884c 2 \u6b65\u64cd\u4f5c
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 6\n\u8f93\u51fa\uff1a4\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= n <= 1000
    • \n\t
    • n\u200b\u200b\u200b\u200b\u200b\u200b \u662f\u4e00\u4e2a\u5076\u6570
    • \n
    \n", "tags_en": ["Greedy", "Array"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int reinitializePermutation(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int reinitializePermutation(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def reinitializePermutation(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def reinitializePermutation(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint reinitializePermutation(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ReinitializePermutation(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar reinitializePermutation = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef reinitialize_permutation(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func reinitializePermutation(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func reinitializePermutation(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def reinitializePermutation(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun reinitializePermutation(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn reinitialize_permutation(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function reinitializePermutation($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function reinitializePermutation(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (reinitialize-permutation n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1806](https://leetcode-cn.com/problems/minimum-number-of-operations-to-reinitialize-a-permutation)", "[\u8fd8\u539f\u6392\u5217\u7684\u6700\u5c11\u64cd\u4f5c\u6b65\u6570](/solution/1800-1899/1806.Minimum%20Number%20of%20Operations%20to%20Reinitialize%20a%20Permutation/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1806](https://leetcode.com/problems/minimum-number-of-operations-to-reinitialize-a-permutation)", "[Minimum Number of Operations to Reinitialize a Permutation](/solution/1800-1899/1806.Minimum%20Number%20of%20Operations%20to%20Reinitialize%20a%20Permutation/README_EN.md)", "`Greedy`,`Array`", "Medium", ""]}, {"question_id": "1934", "frontend_question_id": "1807", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/evaluate-the-bracket-pairs-of-a-string", "url_en": "https://leetcode.com/problems/evaluate-the-bracket-pairs-of-a-string", "relative_path_cn": "/solution/1800-1899/1807.Evaluate%20the%20Bracket%20Pairs%20of%20a%20String/README.md", "relative_path_en": "/solution/1800-1899/1807.Evaluate%20the%20Bracket%20Pairs%20of%20a%20String/README_EN.md", "title_cn": "\u66ff\u6362\u5b57\u7b26\u4e32\u4e2d\u7684\u62ec\u53f7\u5185\u5bb9", "title_en": "Evaluate the Bracket Pairs of a String", "question_title_slug": "evaluate-the-bracket-pairs-of-a-string", "content_en": "

    You are given a string s that contains some bracket pairs, with each pair containing a non-empty key.

    \n\n
      \n\t
    • For example, in the string "(name)is(age)yearsold", there are two bracket pairs that contain the keys "name" and "age".
    • \n
    \n\n

    You know the values of a wide range of keys. This is represented by a 2D string array knowledge where each knowledge[i] = [keyi, valuei] indicates that key keyi has a value of valuei.

    \n\n

    You are tasked to evaluate all of the bracket pairs. When you evaluate a bracket pair that contains some key keyi, you will:

    \n\n
      \n\t
    • Replace keyi and the bracket pair with the key's corresponding valuei.
    • \n\t
    • If you do not know the value of the key, you will replace keyi and the bracket pair with a question mark "?" (without the quotation marks).
    • \n
    \n\n

    Each key will appear at most once in your knowledge. There will not be any nested brackets in s.

    \n\n

    Return the resulting string after evaluating all of the bracket pairs.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "(name)is(age)yearsold", knowledge = [["name","bob"],["age","two"]]\nOutput: "bobistwoyearsold"\nExplanation:\nThe key "name" has a value of "bob", so replace "(name)" with "bob".\nThe key "age" has a value of "two", so replace "(age)" with "two".\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "hi(name)", knowledge = [["a","b"]]\nOutput: "hi?"\nExplanation: As you do not know the value of the key "name", replace "(name)" with "?".\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "(a)(a)(a)aaa", knowledge = [["a","yes"]]\nOutput: "yesyesyesaaa"\nExplanation: The same key can appear multiple times.\nThe key "a" has a value of "yes", so replace all occurrences of "(a)" with "yes".\nNotice that the "a"s not in a bracket pair are not evaluated.\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "(a)(b)", knowledge = [["a","b"],["b","a"]]\nOutput: "ba"
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 105
    • \n\t
    • 0 <= knowledge.length <= 105
    • \n\t
    • knowledge[i].length == 2
    • \n\t
    • 1 <= keyi.length, valuei.length <= 10
    • \n\t
    • s consists of lowercase English letters and round brackets '(' and ')'.
    • \n\t
    • Every open bracket '(' in s will have a corresponding close bracket ')'.
    • \n\t
    • The key in each bracket pair of s will be non-empty.
    • \n\t
    • There will not be any nested bracket pairs in s.
    • \n\t
    • keyi and valuei consist of lowercase English letters.
    • \n\t
    • Each keyi in knowledge is unique.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32\u00a0s\u00a0\uff0c\u5b83\u5305\u542b\u4e00\u4e9b\u62ec\u53f7\u5bf9\uff0c\u6bcf\u4e2a\u62ec\u53f7\u4e2d\u5305\u542b\u4e00\u4e2a \u975e\u7a7a\u00a0\u7684\u952e\u3002

    \n\n
      \n\t
    • \u6bd4\u65b9\u8bf4\uff0c\u5b57\u7b26\u4e32\u00a0\"(name)is(age)yearsold\"\u00a0\u4e2d\uff0c\u6709\u00a0\u4e24\u4e2a\u00a0\u62ec\u53f7\u5bf9\uff0c\u5206\u522b\u5305\u542b\u952e\u00a0\"name\" \u548c\u00a0\"age\"\u00a0\u3002
    • \n
    \n\n

    \u4f60\u77e5\u9053\u8bb8\u591a\u952e\u5bf9\u5e94\u7684\u503c\uff0c\u8fd9\u4e9b\u5173\u7cfb\u7531\u4e8c\u7ef4\u5b57\u7b26\u4e32\u6570\u7ec4\u00a0knowledge\u00a0\u8868\u793a\uff0c\u5176\u4e2d\u00a0knowledge[i] = [keyi, valuei]\u00a0\uff0c\u8868\u793a\u952e\u00a0keyi\u00a0\u5bf9\u5e94\u7684\u503c\u4e3a\u00a0valuei\u00a0\u3002

    \n\n

    \u4f60\u9700\u8981\u66ff\u6362 \u6240\u6709\u00a0\u7684\u62ec\u53f7\u5bf9\u3002\u5f53\u4f60\u66ff\u6362\u4e00\u4e2a\u62ec\u53f7\u5bf9\uff0c\u4e14\u5b83\u5305\u542b\u7684\u952e\u4e3a\u00a0keyi\u00a0\u65f6\uff0c\u4f60\u9700\u8981\uff1a

    \n\n
      \n\t
    • \u5c06\u00a0keyi\u00a0\u548c\u62ec\u53f7\u7528\u5bf9\u5e94\u7684\u503c\u00a0valuei\u00a0\u66ff\u6362\u3002
    • \n\t
    • \u5982\u679c\u4ece knowledge\u00a0\u4e2d\u65e0\u6cd5\u5f97\u77e5\u67d0\u4e2a\u952e\u5bf9\u5e94\u7684\u503c\uff0c\u4f60\u9700\u8981\u5c06\u00a0keyi\u00a0\u548c\u62ec\u53f7\u7528\u95ee\u53f7\u00a0\"?\"\u00a0\u66ff\u6362\uff08\u4e0d\u9700\u8981\u5f15\u53f7\uff09\u3002
    • \n
    \n\n

    knowledge\u00a0\u4e2d\u6bcf\u4e2a\u952e\u6700\u591a\u53ea\u4f1a\u51fa\u73b0\u4e00\u6b21\u3002s\u00a0\u4e2d\u4e0d\u4f1a\u6709\u5d4c\u5957\u7684\u62ec\u53f7\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u66ff\u6362 \u6240\u6709\u00a0\u62ec\u53f7\u5bf9\u540e\u7684\u7ed3\u679c\u5b57\u7b26\u4e32\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1as = \"(name)is(age)yearsold\", knowledge = [[\"name\",\"bob\"],[\"age\",\"two\"]]\n\u8f93\u51fa\uff1a\"bobistwoyearsold\"\n\u89e3\u91ca\uff1a\n\u952e \"name\" \u5bf9\u5e94\u7684\u503c\u4e3a \"bob\" \uff0c\u6240\u4ee5\u5c06 \"(name)\" \u66ff\u6362\u4e3a \"bob\" \u3002\n\u952e \"age\" \u5bf9\u5e94\u7684\u503c\u4e3a \"two\" \uff0c\u6240\u4ee5\u5c06 \"(age)\" \u66ff\u6362\u4e3a \"two\" \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1as = \"hi(name)\", knowledge = [[\"a\",\"b\"]]\n\u8f93\u51fa\uff1a\"hi?\"\n\u89e3\u91ca\uff1a\u7531\u4e8e\u4e0d\u77e5\u9053\u952e \"name\" \u5bf9\u5e94\u7684\u503c\uff0c\u6240\u4ee5\u7528 \"?\" \u66ff\u6362 \"(name)\" \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1as = \"(a)(a)(a)aaa\", knowledge = [[\"a\",\"yes\"]]\n\u8f93\u51fa\uff1a\"yesyesyesaaa\"\n\u89e3\u91ca\uff1a\u76f8\u540c\u7684\u952e\u5728 s \u4e2d\u53ef\u80fd\u4f1a\u51fa\u73b0\u591a\u6b21\u3002\n\u952e \"a\" \u5bf9\u5e94\u7684\u503c\u4e3a \"yes\" \uff0c\u6240\u4ee5\u5c06\u6240\u6709\u7684 \"(a)\" \u66ff\u6362\u4e3a \"yes\" \u3002\n\u6ce8\u610f\uff0c\u4e0d\u5728\u62ec\u53f7\u91cc\u7684 \"a\" \u4e0d\u9700\u8981\u88ab\u66ff\u6362\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1as = \"(a)(b)\", knowledge = [[\"a\",\"b\"],[\"b\",\"a\"]]\n\u8f93\u51fa\uff1a\"ba\"
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 105
    • \n\t
    • 0 <= knowledge.length <= 105
    • \n\t
    • knowledge[i].length == 2
    • \n\t
    • 1 <= keyi.length, valuei.length <= 10
    • \n\t
    • s\u00a0\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u548c\u5706\u62ec\u53f7\u00a0'('\u00a0\u548c\u00a0')'\u00a0\u3002
    • \n\t
    • s\u00a0\u4e2d\u6bcf\u4e00\u4e2a\u5de6\u5706\u62ec\u53f7\u00a0'('\u00a0\u90fd\u6709\u5bf9\u5e94\u7684\u53f3\u5706\u62ec\u53f7\u00a0')'\u00a0\u3002
    • \n\t
    • s\u00a0\u4e2d\u6bcf\u5bf9\u62ec\u53f7\u5185\u7684\u952e\u90fd\u4e0d\u4f1a\u4e3a\u7a7a\u3002
    • \n\t
    • s\u00a0\u4e2d\u4e0d\u4f1a\u6709\u5d4c\u5957\u62ec\u53f7\u5bf9\u3002
    • \n\t
    • keyi\u00a0\u548c\u00a0valuei\u00a0\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    • \n\t
    • knowledge\u00a0\u4e2d\u7684\u00a0keyi\u00a0\u4e0d\u4f1a\u91cd\u590d\u3002
    • \n
    \n", "tags_en": ["Hash Table", "String"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string evaluate(string s, vector>& knowledge) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String evaluate(String s, List> knowledge) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def evaluate(self, s, knowledge):\n \"\"\"\n :type s: str\n :type knowledge: List[List[str]]\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def evaluate(self, s: str, knowledge: List[List[str]]) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * evaluate(char * s, char *** knowledge, int knowledgeSize, int* knowledgeColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string Evaluate(string s, IList> knowledge) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string[][]} knowledge\n * @return {string}\n */\nvar evaluate = function(s, knowledge) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String[][]} knowledge\n# @return {String}\ndef evaluate(s, knowledge)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func evaluate(_ s: String, _ knowledge: [[String]]) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func evaluate(s string, knowledge [][]string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def evaluate(s: String, knowledge: List[List[String]]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun evaluate(s: String, knowledge: List>): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn evaluate(s: String, knowledge: Vec>) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String[][] $knowledge\n * @return String\n */\n function evaluate($s, $knowledge) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function evaluate(s: string, knowledge: string[][]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (evaluate s knowledge)\n (-> string? (listof (listof string?)) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1807](https://leetcode-cn.com/problems/evaluate-the-bracket-pairs-of-a-string)", "[\u66ff\u6362\u5b57\u7b26\u4e32\u4e2d\u7684\u62ec\u53f7\u5185\u5bb9](/solution/1800-1899/1807.Evaluate%20the%20Bracket%20Pairs%20of%20a%20String/README.md)", "`\u54c8\u5e0c\u8868`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1807](https://leetcode.com/problems/evaluate-the-bracket-pairs-of-a-string)", "[Evaluate the Bracket Pairs of a String](/solution/1800-1899/1807.Evaluate%20the%20Bracket%20Pairs%20of%20a%20String/README_EN.md)", "`Hash Table`,`String`", "Medium", ""]}, {"question_id": "1933", "frontend_question_id": "1805", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-different-integers-in-a-string", "url_en": "https://leetcode.com/problems/number-of-different-integers-in-a-string", "relative_path_cn": "/solution/1800-1899/1805.Number%20of%20Different%20Integers%20in%20a%20String/README.md", "relative_path_en": "/solution/1800-1899/1805.Number%20of%20Different%20Integers%20in%20a%20String/README_EN.md", "title_cn": "\u5b57\u7b26\u4e32\u4e2d\u4e0d\u540c\u6574\u6570\u7684\u6570\u76ee", "title_en": "Number of Different Integers in a String", "question_title_slug": "number-of-different-integers-in-a-string", "content_en": "

    You are given a string word that consists of digits and lowercase English letters.

    \n\n

    You will replace every non-digit character with a space. For example, "a123bc34d8ef34" will become " 123  34 8  34". Notice that you are left with some integers that are separated by at least one space: "123", "34", "8", and "34".

    \n\n

    Return the number of different integers after performing the replacement operations on word.

    \n\n

    Two integers are considered different if their decimal representations without any leading zeros are different.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: word = "a123bc34d8ef34"\nOutput: 3\nExplanation: The three different integers are "123", "34", and "8". Notice that "34" is only counted once.\n
    \n\n

    Example 2:

    \n\n
    \nInput: word = "leet1234code234"\nOutput: 2\n
    \n\n

    Example 3:

    \n\n
    \nInput: word = "a1b01c001"\nOutput: 1\nExplanation: The three integers "1", "01", and "001" all represent the same integer because\nthe leading zeros are ignored when comparing their decimal values.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= word.length <= 1000
    • \n\t
    • word consists of digits and lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 word \uff0c\u8be5\u5b57\u7b26\u4e32\u7531\u6570\u5b57\u548c\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\u3002

    \n\n

    \u8bf7\u4f60\u7528\u7a7a\u683c\u66ff\u6362\u6bcf\u4e2a\u4e0d\u662f\u6570\u5b57\u7684\u5b57\u7b26\u3002\u4f8b\u5982\uff0c\"a123bc34d8ef34\" \u5c06\u4f1a\u53d8\u6210 \" 123\u00a0 34 8\u00a0 34\" \u3002\u6ce8\u610f\uff0c\u5269\u4e0b\u7684\u8fd9\u4e9b\u6574\u6570\u4e3a\uff08\u76f8\u90bb\u5f7c\u6b64\u81f3\u5c11\u6709\u4e00\u4e2a\u7a7a\u683c\u9694\u5f00\uff09\uff1a\"123\"\u3001\"34\"\u3001\"8\" \u548c \"34\" \u3002

    \n\n

    \u8fd4\u56de\u5bf9 word \u5b8c\u6210\u66ff\u6362\u540e\u5f62\u6210\u7684 \u4e0d\u540c \u6574\u6570\u7684\u6570\u76ee\u3002

    \n\n

    \u53ea\u6709\u5f53\u4e24\u4e2a\u6574\u6570\u7684 \u4e0d\u542b\u524d\u5bfc\u96f6 \u7684\u5341\u8fdb\u5236\u8868\u793a\u4e0d\u540c\uff0c \u624d\u8ba4\u4e3a\u8fd9\u4e24\u4e2a\u6574\u6570\u4e5f\u4e0d\u540c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aword = \"a123bc34d8ef34\"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u4e0d\u540c\u7684\u6574\u6570\u6709 \"123\"\u3001\"34\" \u548c \"8\" \u3002\u6ce8\u610f\uff0c\"34\" \u53ea\u8ba1\u6570\u4e00\u6b21\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aword = \"leet1234code234\"\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aword = \"a1b01c001\"\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\"1\"\u3001\"01\" \u548c \"001\" \u89c6\u4e3a\u540c\u4e00\u4e2a\u6574\u6570\u7684\u5341\u8fdb\u5236\u8868\u793a\uff0c\u56e0\u4e3a\u5728\u6bd4\u8f83\u5341\u8fdb\u5236\u503c\u65f6\u4f1a\u5ffd\u7565\u524d\u5bfc\u96f6\u7684\u5b58\u5728\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= word.length <= 1000
    • \n\t
    • word \u7531\u6570\u5b57\u548c\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numDifferentIntegers(string word) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numDifferentIntegers(String word) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numDifferentIntegers(self, word):\n \"\"\"\n :type word: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numDifferentIntegers(self, word: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numDifferentIntegers(char * word){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumDifferentIntegers(string word) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} word\n * @return {number}\n */\nvar numDifferentIntegers = function(word) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} word\n# @return {Integer}\ndef num_different_integers(word)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numDifferentIntegers(_ word: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numDifferentIntegers(word string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numDifferentIntegers(word: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numDifferentIntegers(word: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_different_integers(word: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $word\n * @return Integer\n */\n function numDifferentIntegers($word) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numDifferentIntegers(word: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-different-integers word)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1805](https://leetcode-cn.com/problems/number-of-different-integers-in-a-string)", "[\u5b57\u7b26\u4e32\u4e2d\u4e0d\u540c\u6574\u6570\u7684\u6570\u76ee](/solution/1800-1899/1805.Number%20of%20Different%20Integers%20in%20a%20String/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1805](https://leetcode.com/problems/number-of-different-integers-in-a-string)", "[Number of Different Integers in a String](/solution/1800-1899/1805.Number%20of%20Different%20Integers%20in%20a%20String/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1932", "frontend_question_id": "1783", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/grand-slam-titles", "url_en": "https://leetcode.com/problems/grand-slam-titles", "relative_path_cn": "/solution/1700-1799/1783.Grand%20Slam%20Titles/README.md", "relative_path_en": "/solution/1700-1799/1783.Grand%20Slam%20Titles/README_EN.md", "title_cn": "\u5927\u6ee1\u8d2f\u6570\u91cf", "title_en": "Grand Slam Titles", "question_title_slug": "grand-slam-titles", "content_en": "

    Table: Players

    \r\n\r\n
    \r\n+----------------+---------+\r\n| Column Name    | Type    |\r\n+----------------+---------+\r\n| player_id      | int     |\r\n| player_name    | varchar |\r\n+----------------+---------+\r\nplayer_id is the primary key for this table.\r\nEach row in this table contains the name and the ID of a tennis player.\r\n
    \r\n\r\n

     

    \r\n\r\n

    Table: Championships

    \r\n\r\n
    \r\n+---------------+---------+\r\n| Column Name   | Type    |\r\n+---------------+---------+\r\n| year          | int     |\r\n| Wimbledon     | int     |\r\n| Fr_open       | int     |\r\n| US_open       | int     |\r\n| Au_open       | int     |\r\n+---------------+---------+\r\nyear is the primary key for this table.\r\nEach row of this table containts the IDs of the players who won one each tennis tournament of the grand slam.\r\n
    \r\n\r\n

     

    \r\n\r\n

    Write an SQL query to report the number of grand slam tournaments won by each player. Do not include the players who did not win any tournament.

    \r\n\r\n

    Return the result table in any order.

    \r\n\r\n

    The query result format is in the following example:

    \r\n\r\n

     

    \r\n\r\n
    \r\nPlayers table:\r\n+-----------+-------------+\r\n| player_id | player_name |\r\n+-----------+-------------+\r\n| 1         | Nadal       |\r\n| 2         | Federer     |\r\n| 3         | Novak       |\r\n+-----------+-------------+\r\n\r\nChampionships table:\r\n+------+-----------+---------+---------+---------+\r\n| year | Wimbledon | Fr_open | US_open | Au_open |\r\n+------+-----------+---------+---------+---------+\r\n| 2018 | 1         | 1       | 1       | 1       |\r\n| 2019 | 1         | 1       | 2       | 2       |\r\n| 2020 | 2         | 1       | 2       | 2       |\r\n+------+-----------+---------+---------+---------+\r\n\r\nResult table:\r\n+-----------+-------------+-------------------+\r\n| player_id | player_name | grand_slams_count |\r\n+-----------+-------------+-------------------+\r\n| 2         | Federer     | 5                 |\r\n| 1         | Nadal       | 7                 |\r\n+-----------+-------------+-------------------+\r\n\r\nPlayer 1 (Nadal) won 7 titles: Wimbledon (2018, 2019), Fr_open (2018, 2019, 2020), US_open (2018), and Au_open (2018).\r\nPlayer 2 (Federer) won 5 titles: Wimbledon (2020), US_open (2019, 2020), and Au_open (2019, 2020).\r\nPlayer 3 (Novak) did not win anything, we did not include them in the result table.\r\n
    ", "content_cn": "

    \u8868\uff1aPlayers

    \n\n
    \n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| player_id      | int     |\n| player_name    | varchar |\n+----------------+---------+\nplayer_id \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\n\u8fd9\u4e2a\u8868\u7684\u6bcf\u4e00\u884c\u7ed9\u51fa\u4e00\u4e2a\u7f51\u7403\u8fd0\u52a8\u5458\u7684 ID \u548c \u59d3\u540d\n
    \n\n

    \u8868\uff1aChampionships

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| year          | int     |\n| Wimbledon     | int     |\n| Fr_open       | int     |\n| US_open       | int     |\n| Au_open       | int     |\n+---------------+---------+\nyear \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\n\u8be5\u8868\u7684\u6bcf\u4e00\u884c\u90fd\u5305\u542b\u5728\u6bcf\u573a\u5927\u6ee1\u8d2f\u7f51\u7403\u6bd4\u8d5b\u4e2d\u8d62\u5f97\u6bd4\u8d5b\u7684\u7403\u5458\u7684 ID\n
    \n\n

    \u00a0

    \n\n

    \u8bf7\u5199\u51fa\u67e5\u8be2\u8bed\u53e5\uff0c\u67e5\u8be2\u51fa\u6bcf\u4e00\u4e2a\u7403\u5458\u8d62\u5f97\u5927\u6ee1\u8d2f\u6bd4\u8d5b\u7684\u6b21\u6570\u3002\u7ed3\u679c\u4e0d\u5305\u542b\u6ca1\u6709\u8d62\u5f97\u6bd4\u8d5b\u7684\u7403\u5458\u7684ID \u3002

    \n\n

    \u7ed3\u679c\u96c6\u65e0\u987a\u5e8f\u8981\u6c42\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u7684\u683c\u5f0f\uff0c\u5982\u4e0b\u6240\u793a\uff1a

    \n\n

    \u00a0

    \n\n
    \nPlayers \u8868\uff1a\n+-----------+-------------+\n| player_id | player_name |\n+-----------+-------------+\n| 1         | Nadal       |\n| 2         | Federer     |\n| 3         | Novak       |\n+-----------+-------------+\n\nChampionships \u8868\uff1a\n+------+-----------+---------+---------+---------+\n| year | Wimbledon | Fr_open | US_open | Au_open |\n+------+-----------+---------+---------+---------+\n| 2018 | 1         | 1       | 1       | 1       |\n| 2019 | 1         | 1       | 2       | 2       |\n| 2020 | 2         | 1       | 2       | 2       |\n+------+-----------+---------+---------+---------+\n\nResult \u8868\uff1a\n+-----------+-------------+-------------------+\n| player_id | player_name | grand_slams_count |\n+-----------+-------------+-------------------+\n| 2         | Federer     | 5                 |\n| 1         | Nadal       | 7                 |\n+-----------+-------------+-------------------+\n\nPlayer 1 (Nadal) \u83b7\u5f97\u4e86 7 \u6b21\u5927\u6ee1\u8d2f\uff1a\u5176\u4e2d\u6e29\u7f51 2 \u6b21(2018, 2019), \u6cd5\u56fd\u516c\u5f00\u8d5b 3 \u6b21 (2018, 2019, 2020), \u7f8e\u56fd\u516c\u5f00\u8d5b 1 \u6b21 (2018)\u4ee5\u53ca\u6fb3\u7f51\u516c\u5f00\u8d5b 1 \u6b21 (2018) \u3002\nPlayer 2 (Federer) \u83b7\u5f97\u4e86 5 \u6b21\u5927\u6ee1\u8d2f\uff1a\u5176\u4e2d\u6e29\u7f51 1 \u6b21 (2020), \u7f8e\u56fd\u516c\u5f00\u8d5b 2 \u6b21 (2019, 2020) \u4ee5\u53ca\u6fb3\u7f51\u516c\u5f00\u8d5b 2 \u6b21 (2019, 2020) \u3002\nPlayer 3 (Novak)  \u6ca1\u6709\u8d62\u5f97\uff0c\u56e0\u6b64\u4e0d\u5305\u542b\u5728\u7ed3\u679c\u96c6\u4e2d\u3002\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1783](https://leetcode-cn.com/problems/grand-slam-titles)", "[\u5927\u6ee1\u8d2f\u6570\u91cf](/solution/1700-1799/1783.Grand%20Slam%20Titles/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1783](https://leetcode.com/problems/grand-slam-titles)", "[Grand Slam Titles](/solution/1700-1799/1783.Grand%20Slam%20Titles/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1931", "frontend_question_id": "1778", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/shortest-path-in-a-hidden-grid", "url_en": "https://leetcode.com/problems/shortest-path-in-a-hidden-grid", "relative_path_cn": "/solution/1700-1799/1778.Shortest%20Path%20in%20a%20Hidden%20Grid/README.md", "relative_path_en": "/solution/1700-1799/1778.Shortest%20Path%20in%20a%20Hidden%20Grid/README_EN.md", "title_cn": "", "title_en": "Shortest Path in a Hidden Grid", "question_title_slug": "shortest-path-in-a-hidden-grid", "content_en": "

    This is an interactive problem.

    \n\n

    There is a robot in a hidden grid, and you are trying to get it from its starting cell to the target cell in this grid. The grid is of size m x n, and each cell in the grid is either empty or blocked. It is guaranteed that the starting cell and the target cell are different, and neither of them is blocked.

    \n\n

    You want to find the minimum distance to the target cell. However, you do not know the grid's dimensions, the starting cell, nor the target cell. You are only allowed to ask queries to the GridMaster object.

    \n\n

    Thr GridMaster class has the following functions:

    \n\n
      \n\t
    • boolean canMove(char direction) Returns true if the robot can move in that direction. Otherwise, it returns false.
    • \n\t
    • void move(char direction) Moves the robot in that direction. If this move would move the robot to a blocked cell or off the grid, the move will be ignored, and the robot will remain in the same position.
    • \n\t
    • boolean isTarget() Returns true if the robot is currently on the target cell. Otherwise, it returns false.
    • \n
    \n\n

    Note that direction in the above functions should be a character from {'U','D','L','R'}, representing the directions up, down, left, and right, respectively.

    \n\n

    Return the minimum distance between the robot's initial starting cell and the target cell. If there is no valid path between the cells, return -1.

    \n\n

    Custom testing:

    \n\n

    The test input is read as a 2D matrix grid of size m x n where:

    \n\n
      \n\t
    • grid[i][j] == -1 indicates that the robot is in cell (i, j) (the starting cell).
    • \n\t
    • grid[i][j] == 0 indicates that the cell (i, j) is blocked.
    • \n\t
    • grid[i][j] == 1 indicates that the cell (i, j) is empty.
    • \n\t
    • grid[i][j] == 2 indicates that the cell (i, j) is the target cell.
    • \n
    \n\n

    There is exactly one -1 and 2 in grid. Remember that you will not have this information in your code.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: grid = [[1,2],[-1,0]]\nOutput: 2\nExplanation: One possible interaction is described below:\nThe robot is initially standing on cell (1, 0), denoted by the -1.\n- master.canMove('U') returns true.\n- master.canMove('D') returns false.\n- master.canMove('L') returns false.\n- master.canMove('R') returns false.\n- master.move('U') moves the robot to the cell (0, 0).\n- master.isTarget() returns false.\n- master.canMove('U') returns false.\n- master.canMove('D') returns true.\n- master.canMove('L') returns false.\n- master.canMove('R') returns true.\n- master.move('R') moves the robot to the cell (0, 1).\n- master.isTarget() returns true. \nWe now know that the target is the cell (0, 1), and the shortest path to the target cell is 2.\n
    \n\n

    Example 2:

    \n\n
    \nInput: grid = [[0,0,-1],[1,1,1],[2,0,0]]\nOutput: 4\nExplanation: The minimum distance between the robot and the target cell is 4.
    \n\n

    Example 3:

    \n\n
    \nInput: grid = [[-1,0],[0,2]]\nOutput: -1\nExplanation: There is no path from the robot to the target cell.
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n, m <= 500
    • \n\t
    • m == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • grid[i][j] is either -1, 0, 1, or 2.
    • \n\t
    • There is exactly one -1 in grid.
    • \n\t
    • There is exactly one 2 in grid.
    • \n
    \n", "content_cn": null, "tags_en": ["Depth-first Search", "Breadth-first Search", "Graph"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * // This is the GridMaster's API interface.\n * // You should not implement it, or speculate about its implementation\n * class GridMaster {\n * public:\n * bool canMove(char direction);\n * void move(char direction);\n * boolean isTarget();\n * };\n */\n\nclass Solution {\npublic:\n int findShortestPath(GridMaster &master) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * // This is the GridMaster's API interface.\n * // You should not implement it, or speculate about its implementation\n * class GridMaster {\n * boolean canMove(char direction);\n * void move(char direction);\n * boolean isTarget();\n * }\n */\n\nclass Solution {\n public int findShortestPath(GridMaster master) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# \"\"\"\n# This is GridMaster's API interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class GridMaster(object):\n# def canMove(self, direction):\n# \"\"\"\n# :type direction: str\n# :rtype bool\n# \"\"\"\n#\n# def move(self, direction):\n# \"\"\"\n# :type direction: str\n# \"\"\"\n#\n# def isTarget(self):\n# \"\"\"\n# :rtype bool\n# \"\"\"\n#\n\nclass Solution(object):\n def findShortestPath(self, master):\n \"\"\"\n :type master: GridMaster\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# \"\"\"\n# This is GridMaster's API interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class GridMaster(object):\n# def canMove(self, direction: str) -> bool:\n# \n#\n# def move(self, direction: str) -> bool:\n# \n#\n# def isTarget(self) -> None:\n# \n#\n\nclass Solution(object):\n def findShortestPath(self, master: 'GridMaster') -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * // This is the GridMaster's API interface.\n * // You should not implement it, or speculate about its implementation\n * class GridMaster {\n * bool canMove(char direction);\n * void move(char direction);\n * bool isTarget();\n * };\n */\n\nclass Solution {\n public void FindShortestPath(GridMaster master) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // This is the GridMaster's API interface.\n * // You should not implement it, or speculate about its implementation\n * function GridMaster() {\n *\n * @param {character} direction\n * @return {boolean}\n * this.canMove = function(direction) {\n * ...\n * };\n * @param {character} direction\n * @return {void}\n * this.move = function(direction) {\n * ...\n * };\n * @return {boolean}\n * this.isTarget = function() {\n * ...\n * };\n * };\n */\n\n/**\n * @param {GridMaster} master\n * @return {integer}\n */\nvar findShortestPath = function(master) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * // This is the GridMaster's API interface.\n * // You should not implement it, or speculate about its implementation\n * class GridMaster {\n * public func canMove(direction: Character) -> Bool {}\n * public func move(direction: Character) {}\n * public func isTarget() -> Bool {}\n * }\n */\n\nclass Solution {\n func findShortestPath( _ master: gridMaster) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * // This is the master's API interface.\n * // You should not implement it, or speculate about its implementation\n * function gridMaster() {\n *\n * @param {gridMaster} master\n * @return {boolean}\n * this.canMove = function(direction) {\n * ...\n * };\n * @return {void}\n * this.move = function(direction) {\n * ...\n * };\n * @return {boolean}\n * this.isTarget = function() {\n * ...\n * };\n * };\n */\n\n/**\n * @param {gridMaster} master\n * @return {integer}\n */\nvar findShortestPath = function(master) {\n \n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1778](https://leetcode-cn.com/problems/shortest-path-in-a-hidden-grid)", "[Shortest Path in a Hidden Grid](/solution/1700-1799/1778.Shortest%20Path%20in%20a%20Hidden%20Grid/README_EN.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u56fe`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1778](https://leetcode.com/problems/shortest-path-in-a-hidden-grid)", "[Shortest Path in a Hidden Grid](/solution/1700-1799/1778.Shortest%20Path%20in%20a%20Hidden%20Grid/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`,`Graph`", "Medium", "\ud83d\udd12"]}, {"question_id": "1930", "frontend_question_id": "1798", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-number-of-consecutive-values-you-can-make", "url_en": "https://leetcode.com/problems/maximum-number-of-consecutive-values-you-can-make", "relative_path_cn": "/solution/1700-1799/1798.Maximum%20Number%20of%20Consecutive%20Values%20You%20Can%20Make/README.md", "relative_path_en": "/solution/1700-1799/1798.Maximum%20Number%20of%20Consecutive%20Values%20You%20Can%20Make/README_EN.md", "title_cn": "\u4f60\u80fd\u6784\u9020\u51fa\u8fde\u7eed\u503c\u7684\u6700\u5927\u6570\u76ee", "title_en": "Maximum Number of Consecutive Values You Can Make", "question_title_slug": "maximum-number-of-consecutive-values-you-can-make", "content_en": "

    You are given an integer array coins of length n which represents the n coins that you own. The value of the ith coin is coins[i]. You can make some value x if you can choose some of your n coins such that their values sum up to x.

    \n\n

    Return the maximum number of consecutive integer values that you can make with your coins starting from and including 0.

    \n\n

    Note that you may have multiple coins of the same value.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: coins = [1,3]\nOutput: 2\nExplanation: You can make the following values:\n- 0: take []\n- 1: take [1]\nYou can make 2 consecutive integer values starting from 0.
    \n\n

    Example 2:

    \n\n
    \nInput: coins = [1,1,1,4]\nOutput: 8\nExplanation: You can make the following values:\n- 0: take []\n- 1: take [1]\n- 2: take [1,1]\n- 3: take [1,1,1]\n- 4: take [4]\n- 5: take [4,1]\n- 6: take [4,1,1]\n- 7: take [4,1,1,1]\nYou can make 8 consecutive integer values starting from 0.
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [1,4,10,3,1]\nOutput: 20
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • coins.length == n
    • \n\t
    • 1 <= n <= 4 * 104
    • \n\t
    • 1 <= coins[i] <= 4 * 104
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u4e3a n\u00a0\u7684\u6574\u6570\u6570\u7ec4\u00a0coins\u00a0\uff0c\u5b83\u4ee3\u8868\u4f60\u62e5\u6709\u7684\u00a0n\u00a0\u4e2a\u786c\u5e01\u3002\u7b2c\u00a0i\u00a0\u4e2a\u786c\u5e01\u7684\u503c\u4e3a\u00a0coins[i]\u00a0\u3002\u5982\u679c\u4f60\u4ece\u8fd9\u4e9b\u786c\u5e01\u4e2d\u9009\u51fa\u4e00\u90e8\u5206\u786c\u5e01\uff0c\u5b83\u4eec\u7684\u548c\u4e3a\u00a0x\u00a0\uff0c\u90a3\u4e48\u79f0\uff0c\u4f60\u53ef\u4ee5\u00a0\u6784\u9020\u00a0\u51fa\u00a0x\u00a0\u3002

    \n\n

    \u8bf7\u8fd4\u56de\u4ece 0\u00a0\u5f00\u59cb\uff08\u5305\u62ec\u00a00\u00a0\uff09\uff0c\u4f60\u6700\u591a\u80fd\u00a0\u6784\u9020\u00a0\u51fa\u591a\u5c11\u4e2a\u8fde\u7eed\u6574\u6570\u3002

    \n\n

    \u4f60\u53ef\u80fd\u6709\u591a\u4e2a\u76f8\u540c\u503c\u7684\u786c\u5e01\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1acoins = [1,3]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u5f97\u5230\u4ee5\u4e0b\u8fd9\u4e9b\u503c\uff1a\n- 0\uff1a\u4ec0\u4e48\u90fd\u4e0d\u53d6 []\n- 1\uff1a\u53d6 [1]\n\u4ece 0 \u5f00\u59cb\uff0c\u4f60\u53ef\u4ee5\u6784\u9020\u51fa 2 \u4e2a\u8fde\u7eed\u6574\u6570\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1acoins = [1,1,1,4]\n\u8f93\u51fa\uff1a8\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u5f97\u5230\u4ee5\u4e0b\u8fd9\u4e9b\u503c\uff1a\n- 0\uff1a\u4ec0\u4e48\u90fd\u4e0d\u53d6 []\n- 1\uff1a\u53d6 [1]\n- 2\uff1a\u53d6 [1,1]\n- 3\uff1a\u53d6 [1,1,1]\n- 4\uff1a\u53d6 [4]\n- 5\uff1a\u53d6 [4,1]\n- 6\uff1a\u53d6 [4,1,1]\n- 7\uff1a\u53d6 [4,1,1,1]\n\u4ece 0 \u5f00\u59cb\uff0c\u4f60\u53ef\u4ee5\u6784\u9020\u51fa 8 \u4e2a\u8fde\u7eed\u6574\u6570\u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,4,10,3,1]\n\u8f93\u51fa\uff1a20
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • coins.length == n
    • \n\t
    • 1 <= n <= 4 * 104
    • \n\t
    • 1 <= coins[i] <= 4 * 104
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int getMaximumConsecutive(vector& coins) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int getMaximumConsecutive(int[] coins) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getMaximumConsecutive(self, coins):\n \"\"\"\n :type coins: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getMaximumConsecutive(self, coins: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint getMaximumConsecutive(int* coins, int coinsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int GetMaximumConsecutive(int[] coins) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} coins\n * @return {number}\n */\nvar getMaximumConsecutive = function(coins) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} coins\n# @return {Integer}\ndef get_maximum_consecutive(coins)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getMaximumConsecutive(_ coins: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getMaximumConsecutive(coins []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getMaximumConsecutive(coins: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getMaximumConsecutive(coins: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_maximum_consecutive(coins: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $coins\n * @return Integer\n */\n function getMaximumConsecutive($coins) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getMaximumConsecutive(coins: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-maximum-consecutive coins)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1798](https://leetcode-cn.com/problems/maximum-number-of-consecutive-values-you-can-make)", "[\u4f60\u80fd\u6784\u9020\u51fa\u8fde\u7eed\u503c\u7684\u6700\u5927\u6570\u76ee](/solution/1700-1799/1798.Maximum%20Number%20of%20Consecutive%20Values%20You%20Can%20Make/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1798](https://leetcode.com/problems/maximum-number-of-consecutive-values-you-can-make)", "[Maximum Number of Consecutive Values You Can Make](/solution/1700-1799/1798.Maximum%20Number%20of%20Consecutive%20Values%20You%20Can%20Make/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1929", "frontend_question_id": "1802", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-value-at-a-given-index-in-a-bounded-array", "url_en": "https://leetcode.com/problems/maximum-value-at-a-given-index-in-a-bounded-array", "relative_path_cn": "/solution/1800-1899/1802.Maximum%20Value%20at%20a%20Given%20Index%20in%20a%20Bounded%20Array/README.md", "relative_path_en": "/solution/1800-1899/1802.Maximum%20Value%20at%20a%20Given%20Index%20in%20a%20Bounded%20Array/README_EN.md", "title_cn": "\u6709\u754c\u6570\u7ec4\u4e2d\u6307\u5b9a\u4e0b\u6807\u5904\u7684\u6700\u5927\u503c", "title_en": "Maximum Value at a Given Index in a Bounded Array", "question_title_slug": "maximum-value-at-a-given-index-in-a-bounded-array", "content_en": "

    You are given three positive integers: n, index, and maxSum. You want to construct an array nums (0-indexed) that satisfies the following conditions:

    \n\n
      \n\t
    • nums.length == n
    • \n\t
    • nums[i] is a positive integer where 0 <= i < n.
    • \n\t
    • abs(nums[i] - nums[i+1]) <= 1 where 0 <= i < n-1.
    • \n\t
    • The sum of all the elements of nums does not exceed maxSum.
    • \n\t
    • nums[index] is maximized.
    • \n
    \n\n

    Return nums[index] of the constructed array.

    \n\n

    Note that abs(x) equals x if x >= 0, and -x otherwise.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 4, index = 2,  maxSum = 6\nOutput: 2\nExplanation: nums = [1,2,2,1] is one array that satisfies all the conditions.\nThere are no arrays that satisfy all the conditions and have nums[2] == 3, so 2 is the maximum nums[2].\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 6, index = 1,  maxSum = 10\nOutput: 3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= maxSum <= 109
    • \n\t
    • 0 <= index < n
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e09\u4e2a\u6b63\u6574\u6570 n\u3001index \u548c maxSum \u3002\u4f60\u9700\u8981\u6784\u9020\u4e00\u4e2a\u540c\u65f6\u6ee1\u8db3\u4e0b\u8ff0\u6240\u6709\u6761\u4ef6\u7684\u6570\u7ec4 nums\uff08\u4e0b\u6807 \u4ece 0 \u5f00\u59cb \u8ba1\u6570\uff09\uff1a

    \n\n
      \n\t
    • nums.length == n
    • \n\t
    • nums[i] \u662f \u6b63\u6574\u6570 \uff0c\u5176\u4e2d 0 <= i < n
    • \n\t
    • abs(nums[i] - nums[i+1]) <= 1 \uff0c\u5176\u4e2d 0 <= i < n-1
    • \n\t
    • nums \u4e2d\u6240\u6709\u5143\u7d20\u4e4b\u548c\u4e0d\u8d85\u8fc7 maxSum
    • \n\t
    • nums[index] \u7684\u503c\u88ab \u6700\u5927\u5316
    • \n
    \n\n

    \u8fd4\u56de\u4f60\u6240\u6784\u9020\u7684\u6570\u7ec4\u4e2d\u7684 nums[index] \u3002

    \n\n

    \u6ce8\u610f\uff1aabs(x) \u7b49\u4e8e x \u7684\u524d\u63d0\u662f x >= 0 \uff1b\u5426\u5219\uff0cabs(x) \u7b49\u4e8e -x \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1an = 4, index = 2,  maxSum = 6\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6570\u7ec4 [1,1,2,1] \u548c [1,2,2,1] \u6ee1\u8db3\u6240\u6709\u6761\u4ef6\u3002\u4e0d\u5b58\u5728\u5176\u4ed6\u5728\u6307\u5b9a\u4e0b\u6807\u5904\u5177\u6709\u66f4\u5927\u503c\u7684\u6709\u6548\u6570\u7ec4\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1an = 6, index = 1,  maxSum = 10\n\u8f93\u51fa\uff1a3\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= maxSum <= 109
    • \n\t
    • 0 <= index < n
    • \n
    \n", "tags_en": ["Greedy", "Binary Search"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxValue(int n, int index, int maxSum) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxValue(int n, int index, int maxSum) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxValue(self, n, index, maxSum):\n \"\"\"\n :type n: int\n :type index: int\n :type maxSum: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxValue(self, n: int, index: int, maxSum: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxValue(int n, int index, int maxSum){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxValue(int n, int index, int maxSum) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} index\n * @param {number} maxSum\n * @return {number}\n */\nvar maxValue = function(n, index, maxSum) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} index\n# @param {Integer} max_sum\n# @return {Integer}\ndef max_value(n, index, max_sum)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxValue(_ n: Int, _ index: Int, _ maxSum: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxValue(n int, index int, maxSum int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxValue(n: Int, index: Int, maxSum: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxValue(n: Int, index: Int, maxSum: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_value(n: i32, index: i32, max_sum: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $index\n * @param Integer $maxSum\n * @return Integer\n */\n function maxValue($n, $index, $maxSum) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxValue(n: number, index: number, maxSum: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-value n index maxSum)\n (-> exact-integer? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1802](https://leetcode-cn.com/problems/maximum-value-at-a-given-index-in-a-bounded-array)", "[\u6709\u754c\u6570\u7ec4\u4e2d\u6307\u5b9a\u4e0b\u6807\u5904\u7684\u6700\u5927\u503c](/solution/1800-1899/1802.Maximum%20Value%20at%20a%20Given%20Index%20in%20a%20Bounded%20Array/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1802](https://leetcode.com/problems/maximum-value-at-a-given-index-in-a-bounded-array)", "[Maximum Value at a Given Index in a Bounded Array](/solution/1800-1899/1802.Maximum%20Value%20at%20a%20Given%20Index%20in%20a%20Bounded%20Array/README_EN.md)", "`Greedy`,`Binary Search`", "Medium", ""]}, {"question_id": "1928", "frontend_question_id": "1801", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-orders-in-the-backlog", "url_en": "https://leetcode.com/problems/number-of-orders-in-the-backlog", "relative_path_cn": "/solution/1800-1899/1801.Number%20of%20Orders%20in%20the%20Backlog/README.md", "relative_path_en": "/solution/1800-1899/1801.Number%20of%20Orders%20in%20the%20Backlog/README_EN.md", "title_cn": "\u79ef\u538b\u8ba2\u5355\u4e2d\u7684\u8ba2\u5355\u603b\u6570", "title_en": "Number of Orders in the Backlog", "question_title_slug": "number-of-orders-in-the-backlog", "content_en": "

    You are given a 2D integer array orders, where each orders[i] = [pricei, amounti, orderTypei] denotes that amounti orders have been placed of type orderTypei at the price pricei. The orderTypei is:

    \r\n\r\n
      \r\n\t
    • 0 if it is a batch of buy orders, or
    • \r\n\t
    • 1 if it is a batch of sell orders.
    • \r\n
    \r\n\r\n

    Note that orders[i] represents a batch of amounti independent orders with the same price and order type. All orders represented by orders[i] will be placed before all orders represented by orders[i+1] for all valid i.

    \r\n\r\n

    There is a backlog that consists of orders that have not been executed. The backlog is initially empty. When an order is placed, the following happens:

    \r\n\r\n
      \r\n\t
    • If the order is a buy order, you look at the sell order with the smallest price in the backlog. If that sell order's price is smaller than or equal to the current buy order's price, they will match and be executed, and that sell order will be removed from the backlog. Else, the buy order is added to the backlog.
    • \r\n\t
    • Vice versa, if the order is a sell order, you look at the buy order with the largest price in the backlog. If that buy order's price is larger than or equal to the current sell order's price, they will match and be executed, and that buy order will be removed from the backlog. Else, the sell order is added to the backlog.
    • \r\n
    \r\n\r\n

    Return the total amount of orders in the backlog after placing all the orders from the input. Since this number can be large, return it modulo 109 + 7.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\"\"\r\n
    \r\nInput: orders = [[10,5,0],[15,2,1],[25,1,1],[30,4,0]]\r\nOutput: 6\r\nExplanation: Here is what happens with the orders:\r\n- 5 orders of type buy with price 10 are placed. There are no sell orders, so the 5 orders are added to the backlog.\r\n- 2 orders of type sell with price 15 are placed. There are no buy orders with prices larger than or equal to 15, so the 2 orders are added to the backlog.\r\n- 1 order of type sell with price 25 is placed. There are no buy orders with prices larger than or equal to 25 in the backlog, so this order is added to the backlog.\r\n- 4 orders of type buy with price 30 are placed. The first 2 orders are matched with the 2 sell orders of the least price, which is 15 and these 2 sell orders are removed from the backlog. The 3rd order is matched with the sell order of the least price, which is 25 and this sell order is removed from the backlog. Then, there are no more sell orders in the backlog, so the 4th order is added to the backlog.\r\nFinally, the backlog has 5 buy orders with price 10, and 1 buy order with price 30. So the total number of orders in the backlog is 6.\r\n
    \r\n\r\n

    Example 2:

    \r\n\"\"\r\n
    \r\nInput: orders = [[7,1000000000,1],[15,3,0],[5,999999995,0],[5,1,1]]\r\nOutput: 999999984\r\nExplanation: Here is what happens with the orders:\r\n- 109 orders of type sell with price 7 are placed. There are no buy orders, so the 109 orders are added to the backlog.\r\n- 3 orders of type buy with price 15 are placed. They are matched with the 3 sell orders with the least price which is 7, and those 3 sell orders are removed from the backlog.\r\n- 999999995 orders of type buy with price 5 are placed. The least price of a sell order is 7, so the 999999995 orders are added to the backlog.\r\n- 1 order of type sell with price 5 is placed. It is matched with the buy order of the highest price, which is 5, and that buy order is removed from the backlog.\r\nFinally, the backlog has (1000000000-3) sell orders with price 7, and (999999995-1) buy orders with price 5. So the total number of orders = 1999999991, which is equal to 999999984 % (109 + 7).\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= orders.length <= 105
    • \r\n\t
    • orders[i].length == 3
    • \r\n\t
    • 1 <= pricei, amounti <= 109
    • \r\n\t
    • orderTypei is either 0 or 1.
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u4e8c\u7ef4\u6574\u6570\u6570\u7ec4 orders \uff0c\u5176\u4e2d\u6bcf\u4e2a orders[i] = [pricei, amounti, orderTypei] \u8868\u793a\u6709 amounti \u7b14\u7c7b\u578b\u4e3a\u00a0orderTypei \u3001\u4ef7\u683c\u4e3a\u00a0pricei \u7684\u8ba2\u5355\u3002

    \n\n

    \u8ba2\u5355\u7c7b\u578b orderTypei \u53ef\u4ee5\u5206\u4e3a\u4e24\u79cd\uff1a

    \n\n
      \n\t
    • 0 \u8868\u793a\u8fd9\u662f\u4e00\u6279\u91c7\u8d2d\u8ba2\u5355 buy
    • \n\t
    • 1 \u8868\u793a\u8fd9\u662f\u4e00\u6279\u9500\u552e\u8ba2\u5355 sell
    • \n
    \n\n

    \u6ce8\u610f\uff0corders[i] \u8868\u793a\u4e00\u6279\u5171\u8ba1 amounti \u7b14\u7684\u72ec\u7acb\u8ba2\u5355\uff0c\u8fd9\u4e9b\u8ba2\u5355\u7684\u4ef7\u683c\u548c\u7c7b\u578b\u76f8\u540c\u3002\u5bf9\u4e8e\u6240\u6709\u6709\u6548\u7684 i \uff0c\u7531 orders[i] \u8868\u793a\u7684\u6240\u6709\u8ba2\u5355\u63d0\u4ea4\u65f6\u95f4\u5747\u65e9\u4e8e orders[i+1] \u8868\u793a\u7684\u6240\u6709\u8ba2\u5355\u3002

    \n\n

    \u5b58\u5728\u7531\u672a\u6267\u884c\u8ba2\u5355\u7ec4\u6210\u7684 \u79ef\u538b\u8ba2\u5355 \u3002\u79ef\u538b\u8ba2\u5355\u6700\u521d\u662f\u7a7a\u7684\u3002\u63d0\u4ea4\u8ba2\u5355\u65f6\uff0c\u4f1a\u53d1\u751f\u4ee5\u4e0b\u60c5\u51b5\uff1a

    \n\n
      \n\t
    • \u5982\u679c\u8be5\u8ba2\u5355\u662f\u4e00\u7b14\u91c7\u8d2d\u8ba2\u5355 buy \uff0c\u5219\u53ef\u4ee5\u67e5\u770b\u79ef\u538b\u8ba2\u5355\u4e2d\u4ef7\u683c \u6700\u4f4e \u7684\u9500\u552e\u8ba2\u5355 sell \u3002\u5982\u679c\u8be5\u9500\u552e\u8ba2\u5355 sell \u7684\u4ef7\u683c \u4f4e\u4e8e\u6216\u7b49\u4e8e \u5f53\u524d\u91c7\u8d2d\u8ba2\u5355 buy \u7684\u4ef7\u683c\uff0c\u5219\u5339\u914d\u5e76\u6267\u884c\u8fd9\u4e24\u7b14\u8ba2\u5355\uff0c\u5e76\u5c06\u9500\u552e\u8ba2\u5355 sell \u4ece\u79ef\u538b\u8ba2\u5355\u4e2d\u5220\u9664\u3002\u5426\u5219\uff0c\u91c7\u8d2d\u8ba2\u5355 buy \u5c06\u4f1a\u6dfb\u52a0\u5230\u79ef\u538b\u8ba2\u5355\u4e2d\u3002
    • \n\t
    • \u53cd\u4e4b\u4ea6\u7136\uff0c\u5982\u679c\u8be5\u8ba2\u5355\u662f\u4e00\u7b14\u9500\u552e\u8ba2\u5355 sell \uff0c\u5219\u53ef\u4ee5\u67e5\u770b\u79ef\u538b\u8ba2\u5355\u4e2d\u4ef7\u683c \u6700\u9ad8 \u7684\u91c7\u8d2d\u8ba2\u5355 buy \u3002\u5982\u679c\u8be5\u91c7\u8d2d\u8ba2\u5355 buy \u7684\u4ef7\u683c \u9ad8\u4e8e\u6216\u7b49\u4e8e \u5f53\u524d\u9500\u552e\u8ba2\u5355 sell \u7684\u4ef7\u683c\uff0c\u5219\u5339\u914d\u5e76\u6267\u884c\u8fd9\u4e24\u7b14\u8ba2\u5355\uff0c\u5e76\u5c06\u91c7\u8d2d\u8ba2\u5355 buy \u4ece\u79ef\u538b\u8ba2\u5355\u4e2d\u5220\u9664\u3002\u5426\u5219\uff0c\u9500\u552e\u8ba2\u5355 sell \u5c06\u4f1a\u6dfb\u52a0\u5230\u79ef\u538b\u8ba2\u5355\u4e2d\u3002
    • \n
    \n\n

    \u8f93\u5165\u6240\u6709\u8ba2\u5355\u540e\uff0c\u8fd4\u56de\u79ef\u538b\u8ba2\u5355\u4e2d\u7684 \u8ba2\u5355\u603b\u6570 \u3002\u7531\u4e8e\u6570\u5b57\u53ef\u80fd\u5f88\u5927\uff0c\u6240\u4ee5\u9700\u8981\u8fd4\u56de\u5bf9 109 + 7 \u53d6\u4f59\u7684\u7ed3\u679c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aorders = [[10,5,0],[15,2,1],[25,1,1],[30,4,0]]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u8f93\u5165\u8ba2\u5355\u540e\u4f1a\u53d1\u751f\u4e0b\u8ff0\u60c5\u51b5\uff1a\n- \u63d0\u4ea4 5 \u7b14\u91c7\u8d2d\u8ba2\u5355\uff0c\u4ef7\u683c\u4e3a 10 \u3002\u6ca1\u6709\u9500\u552e\u8ba2\u5355\uff0c\u6240\u4ee5\u8fd9 5 \u7b14\u8ba2\u5355\u6dfb\u52a0\u5230\u79ef\u538b\u8ba2\u5355\u4e2d\u3002\n- \u63d0\u4ea4 2 \u7b14\u9500\u552e\u8ba2\u5355\uff0c\u4ef7\u683c\u4e3a 15 \u3002\u6ca1\u6709\u91c7\u8d2d\u8ba2\u5355\u7684\u4ef7\u683c\u5927\u4e8e\u6216\u7b49\u4e8e 15 \uff0c\u6240\u4ee5\u8fd9 2 \u7b14\u8ba2\u5355\u6dfb\u52a0\u5230\u79ef\u538b\u8ba2\u5355\u4e2d\u3002\n- \u63d0\u4ea4 1 \u7b14\u9500\u552e\u8ba2\u5355\uff0c\u4ef7\u683c\u4e3a 25 \u3002\u6ca1\u6709\u91c7\u8d2d\u8ba2\u5355\u7684\u4ef7\u683c\u5927\u4e8e\u6216\u7b49\u4e8e 25 \uff0c\u6240\u4ee5\u8fd9 1 \u7b14\u8ba2\u5355\u6dfb\u52a0\u5230\u79ef\u538b\u8ba2\u5355\u4e2d\u3002\n- \u63d0\u4ea4 4 \u7b14\u91c7\u8d2d\u8ba2\u5355\uff0c\u4ef7\u683c\u4e3a 30 \u3002\u524d 2 \u7b14\u91c7\u8d2d\u8ba2\u5355\u4e0e\u4ef7\u683c\u6700\u4f4e\uff08\u4ef7\u683c\u4e3a 15\uff09\u7684 2 \u7b14\u9500\u552e\u8ba2\u5355\u5339\u914d\uff0c\u4ece\u79ef\u538b\u8ba2\u5355\u4e2d\u5220\u9664\u8fd9 2 \u7b14\u9500\u552e\u8ba2\u5355\u3002\u7b2c 3 \u7b14\u91c7\u8d2d\u8ba2\u5355\u4e0e\u4ef7\u683c\u6700\u4f4e\u7684 1 \u7b14\u9500\u552e\u8ba2\u5355\u5339\u914d\uff0c\u9500\u552e\u8ba2\u5355\u4ef7\u683c\u4e3a 25 \uff0c\u4ece\u79ef\u538b\u8ba2\u5355\u4e2d\u5220\u9664\u8fd9 1 \u7b14\u9500\u552e\u8ba2\u5355\u3002\u79ef\u538b\u8ba2\u5355\u4e2d\u4e0d\u5b58\u5728\u66f4\u591a\u9500\u552e\u8ba2\u5355\uff0c\u6240\u4ee5\u7b2c 4 \u7b14\u91c7\u8d2d\u8ba2\u5355\u9700\u8981\u6dfb\u52a0\u5230\u79ef\u538b\u8ba2\u5355\u4e2d\u3002\n\u6700\u7ec8\uff0c\u79ef\u538b\u8ba2\u5355\u4e2d\u6709 5 \u7b14\u4ef7\u683c\u4e3a 10 \u7684\u91c7\u8d2d\u8ba2\u5355\uff0c\u548c 1 \u7b14\u4ef7\u683c\u4e3a 30 \u7684\u91c7\u8d2d\u8ba2\u5355\u3002\u6240\u4ee5\u79ef\u538b\u8ba2\u5355\u4e2d\u7684\u8ba2\u5355\u603b\u6570\u4e3a 6 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aorders = [[7,1000000000,1],[15,3,0],[5,999999995,0],[5,1,1]]\n\u8f93\u51fa\uff1a999999984\n\u89e3\u91ca\uff1a\u8f93\u5165\u8ba2\u5355\u540e\u4f1a\u53d1\u751f\u4e0b\u8ff0\u60c5\u51b5\uff1a\n- \u63d0\u4ea4 109 \u7b14\u9500\u552e\u8ba2\u5355\uff0c\u4ef7\u683c\u4e3a 7 \u3002\u6ca1\u6709\u91c7\u8d2d\u8ba2\u5355\uff0c\u6240\u4ee5\u8fd9 109 \u7b14\u8ba2\u5355\u6dfb\u52a0\u5230\u79ef\u538b\u8ba2\u5355\u4e2d\u3002\n- \u63d0\u4ea4 3 \u7b14\u91c7\u8d2d\u8ba2\u5355\uff0c\u4ef7\u683c\u4e3a 15 \u3002\u8fd9\u4e9b\u91c7\u8d2d\u8ba2\u5355\u4e0e\u4ef7\u683c\u6700\u4f4e\uff08\u4ef7\u683c\u4e3a 7 \uff09\u7684 3 \u7b14\u9500\u552e\u8ba2\u5355\u5339\u914d\uff0c\u4ece\u79ef\u538b\u8ba2\u5355\u4e2d\u5220\u9664\u8fd9 3 \u7b14\u9500\u552e\u8ba2\u5355\u3002\n- \u63d0\u4ea4 999999995 \u7b14\u91c7\u8d2d\u8ba2\u5355\uff0c\u4ef7\u683c\u4e3a 5 \u3002\u9500\u552e\u8ba2\u5355\u7684\u6700\u4f4e\u4ef7\u4e3a 7 \uff0c\u6240\u4ee5\u8fd9 999999995 \u7b14\u8ba2\u5355\u6dfb\u52a0\u5230\u79ef\u538b\u8ba2\u5355\u4e2d\u3002\n- \u63d0\u4ea4 1 \u7b14\u9500\u552e\u8ba2\u5355\uff0c\u4ef7\u683c\u4e3a 5 \u3002\u8fd9\u7b14\u9500\u552e\u8ba2\u5355\u4e0e\u4ef7\u683c\u6700\u9ad8\uff08\u4ef7\u683c\u4e3a 5 \uff09\u7684 1 \u7b14\u91c7\u8d2d\u8ba2\u5355\u5339\u914d\uff0c\u4ece\u79ef\u538b\u8ba2\u5355\u4e2d\u5220\u9664\u8fd9 1 \u7b14\u91c7\u8d2d\u8ba2\u5355\u3002\n\u6700\u7ec8\uff0c\u79ef\u538b\u8ba2\u5355\u4e2d\u6709 (1000000000-3) \u7b14\u4ef7\u683c\u4e3a 7 \u7684\u9500\u552e\u8ba2\u5355\uff0c\u548c (999999995-1) \u7b14\u4ef7\u683c\u4e3a 5 \u7684\u91c7\u8d2d\u8ba2\u5355\u3002\u6240\u4ee5\u79ef\u538b\u8ba2\u5355\u4e2d\u7684\u8ba2\u5355\u603b\u6570\u4e3a 1999999991 \uff0c\u7b49\u4e8e 999999984 % (109 + 7) \u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= orders.length <= 105
    • \n\t
    • orders[i].length == 3
    • \n\t
    • 1 <= pricei, amounti <= 109
    • \n\t
    • orderTypei \u4e3a 0 \u6216 1
    • \n
    \n", "tags_en": ["Heap", "Greedy"], "tags_cn": ["\u5806", "\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int getNumberOfBacklogOrders(vector>& orders) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int getNumberOfBacklogOrders(int[][] orders) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getNumberOfBacklogOrders(self, orders):\n \"\"\"\n :type orders: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getNumberOfBacklogOrders(self, orders: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint getNumberOfBacklogOrders(int** orders, int ordersSize, int* ordersColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int GetNumberOfBacklogOrders(int[][] orders) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} orders\n * @return {number}\n */\nvar getNumberOfBacklogOrders = function(orders) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} orders\n# @return {Integer}\ndef get_number_of_backlog_orders(orders)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getNumberOfBacklogOrders(_ orders: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getNumberOfBacklogOrders(orders [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getNumberOfBacklogOrders(orders: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getNumberOfBacklogOrders(orders: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_number_of_backlog_orders(orders: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $orders\n * @return Integer\n */\n function getNumberOfBacklogOrders($orders) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getNumberOfBacklogOrders(orders: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-number-of-backlog-orders orders)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1801](https://leetcode-cn.com/problems/number-of-orders-in-the-backlog)", "[\u79ef\u538b\u8ba2\u5355\u4e2d\u7684\u8ba2\u5355\u603b\u6570](/solution/1800-1899/1801.Number%20of%20Orders%20in%20the%20Backlog/README.md)", "`\u5806`,`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1801](https://leetcode.com/problems/number-of-orders-in-the-backlog)", "[Number of Orders in the Backlog](/solution/1800-1899/1801.Number%20of%20Orders%20in%20the%20Backlog/README_EN.md)", "`Heap`,`Greedy`", "Medium", ""]}, {"question_id": "1927", "frontend_question_id": "1800", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-ascending-subarray-sum", "url_en": "https://leetcode.com/problems/maximum-ascending-subarray-sum", "relative_path_cn": "/solution/1800-1899/1800.Maximum%20Ascending%20Subarray%20Sum/README.md", "relative_path_en": "/solution/1800-1899/1800.Maximum%20Ascending%20Subarray%20Sum/README_EN.md", "title_cn": "\u6700\u5927\u5347\u5e8f\u5b50\u6570\u7ec4\u548c", "title_en": "Maximum Ascending Subarray Sum", "question_title_slug": "maximum-ascending-subarray-sum", "content_en": "

    Given an array of positive integers nums, return the maximum possible sum of an ascending subarray in nums.

    \n\n

    A subarray is defined as a contiguous sequence of numbers in an array.

    \n\n

    A subarray [numsl, numsl+1, ..., numsr-1, numsr] is ascending if for all i where l <= i < r, numsi < numsi+1. Note that a subarray of size 1 is ascending.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [10,20,30,5,10,50]\nOutput: 65\nExplanation: [5,10,50] is the ascending subarray with the maximum sum of 65.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [10,20,30,40,50]\nOutput: 150\nExplanation: [10,20,30,40,50] is the ascending subarray with the maximum sum of 150.\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [12,17,15,13,10,11,12]\nOutput: 33\nExplanation: [10,11,12] is the ascending subarray with the maximum sum of 33.\n
    \n\n

    Example 4:

    \n\n
    \nInput: nums = [100,10,1]\nOutput: 100\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 100
    • \n\t
    • 1 <= nums[i] <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6b63\u6574\u6570\u7ec4\u6210\u7684\u6570\u7ec4 nums \uff0c\u8fd4\u56de nums \u4e2d\u4e00\u4e2a \u5347\u5e8f \u5b50\u6570\u7ec4\u7684\u6700\u5927\u53ef\u80fd\u5143\u7d20\u548c\u3002

    \n\n

    \u5b50\u6570\u7ec4\u662f\u6570\u7ec4\u4e2d\u7684\u4e00\u4e2a\u8fde\u7eed\u6570\u5b57\u5e8f\u5217\u3002

    \n\n

    \u5df2\u77e5\u5b50\u6570\u7ec4 [numsl, numsl+1, ..., numsr-1, numsr] \uff0c\u82e5\u5bf9\u6240\u6709 i\uff08l <= i < r\uff09\uff0cnumsi < numsi+1 \u90fd\u6210\u7acb\uff0c\u5219\u79f0\u8fd9\u4e00\u5b50\u6570\u7ec4\u4e3a \u5347\u5e8f \u5b50\u6570\u7ec4\u3002\u6ce8\u610f\uff0c\u5927\u5c0f\u4e3a 1 \u7684\u5b50\u6570\u7ec4\u4e5f\u89c6\u4f5c \u5347\u5e8f \u5b50\u6570\u7ec4\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [10,20,30,5,10,50]\n\u8f93\u51fa\uff1a65\n\u89e3\u91ca\uff1a[5,10,50] \u662f\u5143\u7d20\u548c\u6700\u5927\u7684\u5347\u5e8f\u5b50\u6570\u7ec4\uff0c\u6700\u5927\u5143\u7d20\u548c\u4e3a 65 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [10,20,30,40,50]\n\u8f93\u51fa\uff1a150\n\u89e3\u91ca\uff1a[10,20,30,40,50] \u662f\u5143\u7d20\u548c\u6700\u5927\u7684\u5347\u5e8f\u5b50\u6570\u7ec4\uff0c\u6700\u5927\u5143\u7d20\u548c\u4e3a 150 \u3002 \n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [12,17,15,13,10,11,12]\n\u8f93\u51fa\uff1a33\n\u89e3\u91ca\uff1a[10,11,12] \u662f\u5143\u7d20\u548c\u6700\u5927\u7684\u5347\u5e8f\u5b50\u6570\u7ec4\uff0c\u6700\u5927\u5143\u7d20\u548c\u4e3a 33 \u3002 \n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [100,10,1]\n\u8f93\u51fa\uff1a100\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 100
    • \n\t
    • 1 <= nums[i] <= 100
    • \n
    \n", "tags_en": ["Two Pointers"], "tags_cn": ["\u53cc\u6307\u9488"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxAscendingSum(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxAscendingSum(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxAscendingSum(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxAscendingSum(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxAscendingSum(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxAscendingSum(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar maxAscendingSum = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef max_ascending_sum(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxAscendingSum(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxAscendingSum(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxAscendingSum(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxAscendingSum(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_ascending_sum(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function maxAscendingSum($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxAscendingSum(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-ascending-sum nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1800](https://leetcode-cn.com/problems/maximum-ascending-subarray-sum)", "[\u6700\u5927\u5347\u5e8f\u5b50\u6570\u7ec4\u548c](/solution/1800-1899/1800.Maximum%20Ascending%20Subarray%20Sum/README.md)", "`\u53cc\u6307\u9488`", "\u7b80\u5355", ""], "md_table_row_en": ["[1800](https://leetcode.com/problems/maximum-ascending-subarray-sum)", "[Maximum Ascending Subarray Sum](/solution/1800-1899/1800.Maximum%20Ascending%20Subarray%20Sum/README_EN.md)", "`Two Pointers`", "Easy", ""]}, {"question_id": "1926", "frontend_question_id": "1777", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/products-price-for-each-store", "url_en": "https://leetcode.com/problems/products-price-for-each-store", "relative_path_cn": "/solution/1700-1799/1777.Product%27s%20Price%20for%20Each%20Store/README.md", "relative_path_en": "/solution/1700-1799/1777.Product%27s%20Price%20for%20Each%20Store/README_EN.md", "title_cn": "\u6bcf\u5bb6\u5546\u5e97\u7684\u4ea7\u54c1\u4ef7\u683c", "title_en": "Product's Price for Each Store", "question_title_slug": "products-price-for-each-store", "content_en": "

    Table: Products

    \r\n\r\n
    \r\n+-------------+---------+\r\n| Column Name | Type    |\r\n+-------------+---------+\r\n| product_id  | int     |\r\n| store       | enum    |\r\n| price       | int     |\r\n+-------------+---------+\r\n(product_id,store) is the primary key for this table.\r\nstore is an ENUM of type ('store1', 'store2', 'store3') where each represents the store this product is available at.\r\nprice is the price of the product at this store.
    \r\n\r\n

     

    \r\n\r\n

    Write an SQL query to find the price of each product in each store.

    \r\n\r\n

    Return the result table in any order.

    \r\n\r\n

    The query result format is in the following example:

    \r\n\r\n

     

    \r\n\r\n
    \r\nProducts table:\r\n+-------------+--------+-------+\r\n| product_id  | store  | price |\r\n+-------------+--------+-------+\r\n| 0           | store1 | 95    |\r\n| 0           | store3 | 105   |\r\n| 0           | store2 | 100   |\r\n| 1           | store1 | 70    |\r\n| 1           | store3 | 80    |\r\n+-------------+--------+-------+\r\nResult table:\r\n+-------------+--------+--------+--------+\r\n| product_id  | store1 | store2 | store3 |\r\n+-------------+--------+--------+--------+\r\n| 0           | 95     | 100    | 105    |\r\n| 1           | 70     | null   | 80     |\r\n+-------------+--------+--------+--------+\r\nProduct 0 price's are 95 for store1, 100 for store2 and, 105 for store3.\r\nProduct 1 price's are 70 for store1, 80 for store3 and, it's not sold in store2.\r\n
    ", "content_cn": "

    \u8868\uff1aProducts

    \n\n
    \n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| product_id  | int     |\n| store       | enum    |\n| price       | int     |\n+-------------+---------+\n(product_id,store) \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\u3002\nstore \u5b57\u6bb5\u662f\u679a\u4e3e\u7c7b\u578b\uff0c\u5b83\u7684\u53d6\u503c\u4e3a\u4ee5\u4e0b\u4e09\u79cd ('store1', 'store2', 'store3') \u3002\nprice \u662f\u8be5\u5546\u54c1\u5728\u8fd9\u5bb6\u5546\u5e97\u4e2d\u7684\u4ef7\u683c\u3002
    \n\n

    \u00a0

    \n\n

    \u5199\u51fa\u4e00\u4e2a SQL \u67e5\u8be2\u8bed\u53e5\uff0c\u67e5\u627e\u6bcf\u79cd\u4ea7\u54c1\u5728\u5404\u4e2a\u5546\u5e97\u4e2d\u7684\u4ef7\u683c\u3002

    \n\n

    \u53ef\u4ee5\u4ee5 \u4efb\u4f55\u987a\u5e8f \u8f93\u51fa\u7ed3\u679c\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a\uff1a

    \n\n
    \nProducts \u8868\uff1a\n+-------------+--------+-------+\n| product_id  | store  | price |\n+-------------+--------+-------+\n| 0           | store1 | 95    |\n| 0           | store3 | 105   |\n| 0           | store2 | 100   |\n| 1           | store1 | 70    |\n| 1           | store3 | 80    |\n+-------------+--------+-------+\nResult \u8868\uff1a\n+-------------+--------+--------+--------+\n| product_id  | store1 | store2 | store3 |\n+-------------+--------+--------+--------+\n| 0           | 95     | 100    | 105    |\n| 1           | 70     | null   | 80     |\n+-------------+--------+--------+--------+\n\u4ea7\u54c1 0 \u7684\u4ef7\u683c\u5728\u5546\u5e97 1 \u4e3a 95 \uff0c\u5546\u5e97 2 \u4e3a 100 \uff0c\u5546\u5e97 3 \u4e3a 105 \u3002\n\u4ea7\u54c1 1 \u7684\u4ef7\u683c\u5728\u5546\u5e97 1 \u4e3a 70 \uff0c\u5546\u5e97 3 \u7684\u4ea7\u54c1 1 \u4ef7\u683c\u4e3a 80 \uff0c\u4f46\u5728\u5546\u5e97 2 \u4e2d\u6ca1\u6709\u9500\u552e\u3002\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1777](https://leetcode-cn.com/problems/products-price-for-each-store)", "[\u6bcf\u5bb6\u5546\u5e97\u7684\u4ea7\u54c1\u4ef7\u683c](/solution/1700-1799/1777.Product%27s%20Price%20for%20Each%20Store/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1777](https://leetcode.com/problems/products-price-for-each-store)", "[Product's Price for Each Store](/solution/1700-1799/1777.Product%27s%20Price%20for%20Each%20Store/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1925", "frontend_question_id": "1814", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-nice-pairs-in-an-array", "url_en": "https://leetcode.com/problems/count-nice-pairs-in-an-array", "relative_path_cn": "/solution/1800-1899/1814.Count%20Nice%20Pairs%20in%20an%20Array/README.md", "relative_path_en": "/solution/1800-1899/1814.Count%20Nice%20Pairs%20in%20an%20Array/README_EN.md", "title_cn": "\u7edf\u8ba1\u4e00\u4e2a\u6570\u7ec4\u4e2d\u597d\u5bf9\u5b50\u7684\u6570\u76ee", "title_en": "Count Nice Pairs in an Array", "question_title_slug": "count-nice-pairs-in-an-array", "content_en": "

    You are given an array nums that consists of non-negative integers. Let us define rev(x) as the reverse of the non-negative integer x. For example, rev(123) = 321, and rev(120) = 21. A pair of indices (i, j) is nice if it satisfies all of the following conditions:

    \n\n
      \n\t
    • 0 <= i < j < nums.length
    • \n\t
    • nums[i] + rev(nums[j]) == nums[j] + rev(nums[i])
    • \n
    \n\n

    Return the number of nice pairs of indices. Since that number can be too large, return it modulo 109 + 7.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [42,11,1,97]\nOutput: 2\nExplanation: The two pairs are:\n - (0,3) : 42 + rev(97) = 42 + 79 = 121, 97 + rev(42) = 97 + 24 = 121.\n - (1,2) : 11 + rev(1) = 11 + 1 = 12, 1 + rev(11) = 1 + 11 = 12.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [13,10,35,24,76]\nOutput: 4\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • 0 <= nums[i] <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4\u00a0nums\u00a0\uff0c\u6570\u7ec4\u4e2d\u53ea\u5305\u542b\u975e\u8d1f\u6574\u6570\u3002\u5b9a\u4e49\u00a0rev(x)\u00a0\u7684\u503c\u4e3a\u5c06\u6574\u6570\u00a0x\u00a0\u5404\u4e2a\u6570\u5b57\u4f4d\u53cd\u8f6c\u5f97\u5230\u7684\u7ed3\u679c\u3002\u6bd4\u65b9\u8bf4\u00a0rev(123) = 321\u00a0\uff0c\u00a0rev(120) = 21\u00a0\u3002\u6211\u4eec\u79f0\u6ee1\u8db3\u4e0b\u9762\u6761\u4ef6\u7684\u4e0b\u6807\u5bf9\u00a0(i, j) \u662f\u00a0\u597d\u7684\u00a0\uff1a

    \n\n
      \n\t
    • 0 <= i < j < nums.length
    • \n\t
    • nums[i] + rev(nums[j]) == nums[j] + rev(nums[i])
    • \n
    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u597d\u4e0b\u6807\u5bf9\u7684\u6570\u76ee\u3002\u7531\u4e8e\u7ed3\u679c\u53ef\u80fd\u4f1a\u5f88\u5927\uff0c\u8bf7\u5c06\u7ed3\u679c\u5bf9\u00a0109 + 7\u00a0\u53d6\u4f59\u00a0\u540e\u8fd4\u56de\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [42,11,1,97]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u4e24\u4e2a\u5750\u6807\u5bf9\u4e3a\uff1a\n - (0,3)\uff1a42 + rev(97) = 42 + 79 = 121, 97 + rev(42) = 97 + 24 = 121 \u3002\n - (1,2)\uff1a11 + rev(1) = 11 + 1 = 12, 1 + rev(11) = 1 + 11 = 12 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [13,10,35,24,76]\n\u8f93\u51fa\uff1a4\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • 0 <= nums[i] <= 109
    • \n
    \n", "tags_en": ["Array", "Hash Table"], "tags_cn": ["\u6570\u7ec4", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countNicePairs(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countNicePairs(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countNicePairs(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countNicePairs(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countNicePairs(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountNicePairs(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar countNicePairs = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef count_nice_pairs(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countNicePairs(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countNicePairs(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countNicePairs(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countNicePairs(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_nice_pairs(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function countNicePairs($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countNicePairs(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-nice-pairs nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1814](https://leetcode-cn.com/problems/count-nice-pairs-in-an-array)", "[\u7edf\u8ba1\u4e00\u4e2a\u6570\u7ec4\u4e2d\u597d\u5bf9\u5b50\u7684\u6570\u76ee](/solution/1800-1899/1814.Count%20Nice%20Pairs%20in%20an%20Array/README.md)", "`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1814](https://leetcode.com/problems/count-nice-pairs-in-an-array)", "[Count Nice Pairs in an Array](/solution/1800-1899/1814.Count%20Nice%20Pairs%20in%20an%20Array/README_EN.md)", "`Array`,`Hash Table`", "Medium", ""]}, {"question_id": "1924", "frontend_question_id": "1815", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-number-of-groups-getting-fresh-donuts", "url_en": "https://leetcode.com/problems/maximum-number-of-groups-getting-fresh-donuts", "relative_path_cn": "/solution/1800-1899/1815.Maximum%20Number%20of%20Groups%20Getting%20Fresh%20Donuts/README.md", "relative_path_en": "/solution/1800-1899/1815.Maximum%20Number%20of%20Groups%20Getting%20Fresh%20Donuts/README_EN.md", "title_cn": "\u5f97\u5230\u65b0\u9c9c\u751c\u751c\u5708\u7684\u6700\u591a\u7ec4\u6570", "title_en": "Maximum Number of Groups Getting Fresh Donuts", "question_title_slug": "maximum-number-of-groups-getting-fresh-donuts", "content_en": "

    There is a donuts shop that bakes donuts in batches of batchSize. They have a rule where they must serve all of the donuts of a batch before serving any donuts of the next batch. You are given an integer batchSize and an integer array groups, where groups[i] denotes that there is a group of groups[i] customers that will visit the shop. Each customer will get exactly one donut.

    \n\n

    When a group visits the shop, all customers of the group must be served before serving any of the following groups. A group will be happy if they all get fresh donuts. That is, the first customer of the group does not receive a donut that was left over from the previous group.

    \n\n

    You can freely rearrange the ordering of the groups. Return the maximum possible number of happy groups after rearranging the groups.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: batchSize = 3, groups = [1,2,3,4,5,6]\nOutput: 4\nExplanation: You can arrange the groups as [6,2,4,5,1,3]. Then the 1st, 2nd, 4th, and 6th groups will be happy.\n
    \n\n

    Example 2:

    \n\n
    \nInput: batchSize = 4, groups = [1,3,2,5,2,2,1,6]\nOutput: 4\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= batchSize <= 9
    • \n\t
    • 1 <= groups.length <= 30
    • \n\t
    • 1 <= groups[i] <= 109
    • \n
    \n", "content_cn": "

    \u6709\u4e00\u4e2a\u751c\u751c\u5708\u5546\u5e97\uff0c\u6bcf\u6279\u6b21\u90fd\u70e4\u00a0batchSize\u00a0\u4e2a\u751c\u751c\u5708\u3002\u8fd9\u4e2a\u5e97\u94fa\u6709\u4e2a\u89c4\u5219\uff0c\u5c31\u662f\u5728\u70e4\u4e00\u6279\u65b0\u7684\u751c\u751c\u5708\u65f6\uff0c\u4e4b\u524d \u6240\u6709\u00a0\u751c\u751c\u5708\u90fd\u5fc5\u987b\u5df2\u7ecf\u5168\u90e8\u9500\u552e\u5b8c\u6bd5\u3002\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 batchSize\u00a0\u548c\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 groups\u00a0\uff0c\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u6574\u6570\u90fd\u4ee3\u8868\u4e00\u6279\u524d\u6765\u8d2d\u4e70\u751c\u751c\u5708\u7684\u987e\u5ba2\uff0c\u5176\u4e2d groups[i]\u00a0\u8868\u793a\u8fd9\u4e00\u6279\u987e\u5ba2\u7684\u4eba\u6570\u3002\u6bcf\u4e00\u4f4d\u987e\u5ba2\u90fd\u6070\u597d\u53ea\u8981\u4e00\u4e2a\u751c\u751c\u5708\u3002

    \n\n

    \u5f53\u6709\u4e00\u6279\u987e\u5ba2\u6765\u5230\u5546\u5e97\u65f6\uff0c\u4ed6\u4eec\u6240\u6709\u4eba\u90fd\u5fc5\u987b\u5728\u4e0b\u4e00\u6279\u987e\u5ba2\u6765\u4e4b\u524d\u8d2d\u4e70\u5b8c\u751c\u751c\u5708\u3002\u5982\u679c\u4e00\u6279\u987e\u5ba2\u4e2d\u7b2c\u4e00\u4f4d\u987e\u5ba2\u5f97\u5230\u7684\u751c\u751c\u5708\u4e0d\u662f\u4e0a\u4e00\u7ec4\u5269\u4e0b\u7684\uff0c\u90a3\u4e48\u8fd9\u4e00\u7ec4\u4eba\u90fd\u4f1a\u5f88\u5f00\u5fc3\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u968f\u610f\u5b89\u6392\u6bcf\u6279\u987e\u5ba2\u5230\u6765\u7684\u987a\u5e8f\u3002\u8bf7\u4f60\u8fd4\u56de\u5728\u6b64\u524d\u63d0\u4e0b\uff0c\u6700\u591a\u00a0\u6709\u591a\u5c11\u7ec4\u4eba\u4f1a\u611f\u5230\u5f00\u5fc3\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1abatchSize = 3, groups = [1,2,3,4,5,6]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u5c06\u8fd9\u4e9b\u6279\u6b21\u7684\u987e\u5ba2\u987a\u5e8f\u5b89\u6392\u4e3a [6,2,4,5,1,3] \u3002\u90a3\u4e48\u7b2c 1\uff0c2\uff0c4\uff0c6 \u7ec4\u90fd\u4f1a\u611f\u5230\u5f00\u5fc3\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1abatchSize = 4, groups = [1,3,2,5,2,2,1,6]\n\u8f93\u51fa\uff1a4\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= batchSize <= 9
    • \n\t
    • 1 <= groups.length <= 30
    • \n\t
    • 1 <= groups[i] <= 109
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxHappyGroups(int batchSize, vector& groups) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxHappyGroups(int batchSize, int[] groups) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxHappyGroups(self, batchSize, groups):\n \"\"\"\n :type batchSize: int\n :type groups: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxHappyGroups(self, batchSize: int, groups: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxHappyGroups(int batchSize, int* groups, int groupsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxHappyGroups(int batchSize, int[] groups) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} batchSize\n * @param {number[]} groups\n * @return {number}\n */\nvar maxHappyGroups = function(batchSize, groups) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} batch_size\n# @param {Integer[]} groups\n# @return {Integer}\ndef max_happy_groups(batch_size, groups)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxHappyGroups(_ batchSize: Int, _ groups: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxHappyGroups(batchSize int, groups []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxHappyGroups(batchSize: Int, groups: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxHappyGroups(batchSize: Int, groups: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_happy_groups(batch_size: i32, groups: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $batchSize\n * @param Integer[] $groups\n * @return Integer\n */\n function maxHappyGroups($batchSize, $groups) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxHappyGroups(batchSize: number, groups: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-happy-groups batchSize groups)\n (-> exact-integer? (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1815](https://leetcode-cn.com/problems/maximum-number-of-groups-getting-fresh-donuts)", "[\u5f97\u5230\u65b0\u9c9c\u751c\u751c\u5708\u7684\u6700\u591a\u7ec4\u6570](/solution/1800-1899/1815.Maximum%20Number%20of%20Groups%20Getting%20Fresh%20Donuts/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1815](https://leetcode.com/problems/maximum-number-of-groups-getting-fresh-donuts)", "[Maximum Number of Groups Getting Fresh Donuts](/solution/1800-1899/1815.Maximum%20Number%20of%20Groups%20Getting%20Fresh%20Donuts/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1923", "frontend_question_id": "1813", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sentence-similarity-iii", "url_en": "https://leetcode.com/problems/sentence-similarity-iii", "relative_path_cn": "/solution/1800-1899/1813.Sentence%20Similarity%20III/README.md", "relative_path_en": "/solution/1800-1899/1813.Sentence%20Similarity%20III/README_EN.md", "title_cn": "\u53e5\u5b50\u76f8\u4f3c\u6027 III", "title_en": "Sentence Similarity III", "question_title_slug": "sentence-similarity-iii", "content_en": "

    A sentence is a list of words that are separated by a single space with no leading or trailing spaces. For example, "Hello World", "HELLO", "hello world hello world" are all sentences. Words consist of only uppercase and lowercase English letters.

    \n\n

    Two sentences sentence1 and sentence2 are similar if it is possible to insert an arbitrary sentence (possibly empty) inside one of these sentences such that the two sentences become equal. For example, sentence1 = "Hello my name is Jane" and sentence2 = "Hello Jane" can be made equal by inserting "my name is" between "Hello" and "Jane" in sentence2.

    \n\n

    Given two sentences sentence1 and sentence2, return true if sentence1 and sentence2 are similar. Otherwise, return false.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: sentence1 = "My name is Haley", sentence2 = "My Haley"\nOutput: true\nExplanation: sentence2 can be turned to sentence1 by inserting "name is" between "My" and "Haley".\n
    \n\n

    Example 2:

    \n\n
    \nInput: sentence1 = "of", sentence2 = "A lot of words"\nOutput: false\nExplanation: No single sentence can be inserted inside one of the sentences to make it equal to the other.\n
    \n\n

    Example 3:

    \n\n
    \nInput: sentence1 = "Eating right now", sentence2 = "Eating"\nOutput: true\nExplanation: sentence2 can be turned to sentence1 by inserting "right now" at the end of the sentence.\n
    \n\n

    Example 4:

    \n\n
    \nInput: sentence1 = "Luky", sentence2 = "Lucccky"\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= sentence1.length, sentence2.length <= 100
    • \n\t
    • sentence1 and sentence2 consist of lowercase and uppercase English letters and spaces.
    • \n\t
    • The words in sentence1 and sentence2 are separated by a single space.
    • \n
    \n", "content_cn": "

    \u4e00\u4e2a\u53e5\u5b50\u662f\u7531\u4e00\u4e9b\u5355\u8bcd\u4e0e\u5b83\u4eec\u4e4b\u95f4\u7684\u5355\u4e2a\u7a7a\u683c\u7ec4\u6210\uff0c\u4e14\u53e5\u5b50\u7684\u5f00\u5934\u548c\u7ed3\u5c3e\u6ca1\u6709\u591a\u4f59\u7a7a\u683c\u3002\u6bd4\u65b9\u8bf4\uff0c\"Hello World\"\u00a0\uff0c\"HELLO\"\u00a0\uff0c\"hello world hello world\"\u00a0\u90fd\u662f\u53e5\u5b50\u3002\u6bcf\u4e2a\u5355\u8bcd\u90fd \u53ea\u00a0\u5305\u542b\u5927\u5199\u548c\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002

    \n\n

    \u5982\u679c\u4e24\u4e2a\u53e5\u5b50\u00a0sentence1 \u548c\u00a0sentence2\u00a0\uff0c\u53ef\u4ee5\u901a\u8fc7\u5f80\u5176\u4e2d\u4e00\u4e2a\u53e5\u5b50\u63d2\u5165\u4e00\u4e2a\u4efb\u610f\u7684\u53e5\u5b50\uff08\u53ef\u4ee5\u662f\u7a7a\u53e5\u5b50\uff09\u800c\u5f97\u5230\u53e6\u4e00\u4e2a\u53e5\u5b50\uff0c\u90a3\u4e48\u6211\u4eec\u79f0\u8fd9\u4e24\u4e2a\u53e5\u5b50\u662f \u76f8\u4f3c\u7684\u00a0\u3002\u6bd4\u65b9\u8bf4\uff0csentence1 = \"Hello my name is Jane\" \u4e14\u00a0sentence2 = \"Hello Jane\"\u00a0\uff0c\u6211\u4eec\u53ef\u4ee5\u5f80 sentence2\u00a0\u4e2d\u00a0\"Hello\" \u548c\u00a0\"Jane\"\u00a0\u4e4b\u95f4\u63d2\u5165\u00a0\"my name is\"\u00a0\u5f97\u5230 sentence1\u00a0\u3002

    \n\n

    \u7ed9\u4f60\u4e24\u4e2a\u53e5\u5b50\u00a0sentence1 \u548c\u00a0sentence2\u00a0\uff0c\u5982\u679c\u00a0sentence1 \u548c\u00a0sentence2 \u662f\u76f8\u4f3c\u7684\uff0c\u8bf7\u4f60\u8fd4\u56de\u00a0true\u00a0\uff0c\u5426\u5219\u8fd4\u56de\u00a0false\u00a0\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1asentence1 = \"My name is Haley\", sentence2 = \"My Haley\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u53ef\u4ee5\u5f80 sentence2 \u4e2d \"My\" \u548c \"Haley\" \u4e4b\u95f4\u63d2\u5165 \"name is\" \uff0c\u5f97\u5230 sentence1 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1asentence1 = \"of\", sentence2 = \"A lot of words\"\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u6ca1\u6cd5\u5f80\u8fd9\u4e24\u4e2a\u53e5\u5b50\u4e2d\u7684\u4e00\u4e2a\u53e5\u5b50\u53ea\u63d2\u5165\u4e00\u4e2a\u53e5\u5b50\u5c31\u5f97\u5230\u53e6\u4e00\u4e2a\u53e5\u5b50\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1asentence1 = \"Eating right now\", sentence2 = \"Eating\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u53ef\u4ee5\u5f80 sentence2 \u7684\u7ed3\u5c3e\u63d2\u5165 \"right now\" \u5f97\u5230 sentence1 \u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1asentence1 = \"Luky\", sentence2 = \"Lucccky\"\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= sentence1.length, sentence2.length <= 100
    • \n\t
    • sentence1\u00a0\u548c\u00a0sentence2\u00a0\u90fd\u53ea\u5305\u542b\u5927\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u548c\u7a7a\u683c\u3002
    • \n\t
    • sentence1\u00a0\u548c\u00a0sentence2\u00a0\u4e2d\u7684\u5355\u8bcd\u90fd\u53ea\u7531\u5355\u4e2a\u7a7a\u683c\u9694\u5f00\u3002
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool areSentencesSimilar(string sentence1, string sentence2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean areSentencesSimilar(String sentence1, String sentence2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def areSentencesSimilar(self, sentence1, sentence2):\n \"\"\"\n :type sentence1: str\n :type sentence2: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def areSentencesSimilar(self, sentence1: str, sentence2: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool areSentencesSimilar(char * sentence1, char * sentence2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool AreSentencesSimilar(string sentence1, string sentence2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} sentence1\n * @param {string} sentence2\n * @return {boolean}\n */\nvar areSentencesSimilar = function(sentence1, sentence2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} sentence1\n# @param {String} sentence2\n# @return {Boolean}\ndef are_sentences_similar(sentence1, sentence2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func areSentencesSimilar(_ sentence1: String, _ sentence2: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func areSentencesSimilar(sentence1 string, sentence2 string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def areSentencesSimilar(sentence1: String, sentence2: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun areSentencesSimilar(sentence1: String, sentence2: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn are_sentences_similar(sentence1: String, sentence2: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $sentence1\n * @param String $sentence2\n * @return Boolean\n */\n function areSentencesSimilar($sentence1, $sentence2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function areSentencesSimilar(sentence1: string, sentence2: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (are-sentences-similar sentence1 sentence2)\n (-> string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1813](https://leetcode-cn.com/problems/sentence-similarity-iii)", "[\u53e5\u5b50\u76f8\u4f3c\u6027 III](/solution/1800-1899/1813.Sentence%20Similarity%20III/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1813](https://leetcode.com/problems/sentence-similarity-iii)", "[Sentence Similarity III](/solution/1800-1899/1813.Sentence%20Similarity%20III/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "1920", "frontend_question_id": "1812", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/determine-color-of-a-chessboard-square", "url_en": "https://leetcode.com/problems/determine-color-of-a-chessboard-square", "relative_path_cn": "/solution/1800-1899/1812.Determine%20Color%20of%20a%20Chessboard%20Square/README.md", "relative_path_en": "/solution/1800-1899/1812.Determine%20Color%20of%20a%20Chessboard%20Square/README_EN.md", "title_cn": "\u5224\u65ad\u56fd\u9645\u8c61\u68cb\u68cb\u76d8\u4e2d\u4e00\u4e2a\u683c\u5b50\u7684\u989c\u8272", "title_en": "Determine Color of a Chessboard Square", "question_title_slug": "determine-color-of-a-chessboard-square", "content_en": "

    You are given coordinates, a string that represents the coordinates of a square of the chessboard. Below is a chessboard for your reference.

    \n\n

    \"\"

    \n\n

    Return true if the square is white, and false if the square is black.

    \n\n

    The coordinate will always represent a valid chessboard square. The coordinate will always have the letter first, and the number second.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: coordinates = "a1"\nOutput: false\nExplanation: From the chessboard above, the square with coordinates "a1" is black, so return false.\n
    \n\n

    Example 2:

    \n\n
    \nInput: coordinates = "h3"\nOutput: true\nExplanation: From the chessboard above, the square with coordinates "h3" is white, so return true.\n
    \n\n

    Example 3:

    \n\n
    \nInput: coordinates = "c7"\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • coordinates.length == 2
    • \n\t
    • 'a' <= coordinates[0] <= 'h'
    • \n\t
    • '1' <= coordinates[1] <= '8'
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5750\u6807\u00a0coordinates\u00a0\uff0c\u5b83\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u8868\u793a\u56fd\u9645\u8c61\u68cb\u68cb\u76d8\u4e2d\u4e00\u4e2a\u683c\u5b50\u7684\u5750\u6807\u3002\u4e0b\u56fe\u662f\u56fd\u9645\u8c61\u68cb\u68cb\u76d8\u793a\u610f\u56fe\u3002

    \n\n

    \"\"

    \n\n

    \u5982\u679c\u6240\u7ed9\u683c\u5b50\u7684\u989c\u8272\u662f\u767d\u8272\uff0c\u8bf7\u4f60\u8fd4\u56de\u00a0true\uff0c\u5982\u679c\u662f\u9ed1\u8272\uff0c\u8bf7\u8fd4\u56de\u00a0false\u00a0\u3002

    \n\n

    \u7ed9\u5b9a\u5750\u6807\u4e00\u5b9a\u4ee3\u8868\u56fd\u9645\u8c61\u68cb\u68cb\u76d8\u4e0a\u4e00\u4e2a\u5b58\u5728\u7684\u683c\u5b50\u3002\u5750\u6807\u7b2c\u4e00\u4e2a\u5b57\u7b26\u662f\u5b57\u6bcd\uff0c\u7b2c\u4e8c\u4e2a\u5b57\u7b26\u662f\u6570\u5b57\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1acoordinates = \"a1\"\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u5982\u4e0a\u56fe\u68cb\u76d8\u6240\u793a\uff0c\"a1\" \u5750\u6807\u7684\u683c\u5b50\u662f\u9ed1\u8272\u7684\uff0c\u6240\u4ee5\u8fd4\u56de false \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1acoordinates = \"h3\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u5982\u4e0a\u56fe\u68cb\u76d8\u6240\u793a\uff0c\"h3\" \u5750\u6807\u7684\u683c\u5b50\u662f\u767d\u8272\u7684\uff0c\u6240\u4ee5\u8fd4\u56de true \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1acoordinates = \"c7\"\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • coordinates.length == 2
    • \n\t
    • 'a' <= coordinates[0] <= 'h'
    • \n\t
    • '1' <= coordinates[1] <= '8'
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool squareIsWhite(string coordinates) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean squareIsWhite(String coordinates) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def squareIsWhite(self, coordinates):\n \"\"\"\n :type coordinates: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def squareIsWhite(self, coordinates: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool squareIsWhite(char * coordinates){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool SquareIsWhite(string coordinates) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} coordinates\n * @return {boolean}\n */\nvar squareIsWhite = function(coordinates) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} coordinates\n# @return {Boolean}\ndef square_is_white(coordinates)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func squareIsWhite(_ coordinates: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func squareIsWhite(coordinates string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def squareIsWhite(coordinates: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun squareIsWhite(coordinates: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn square_is_white(coordinates: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $coordinates\n * @return Boolean\n */\n function squareIsWhite($coordinates) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function squareIsWhite(coordinates: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (square-is-white coordinates)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1812](https://leetcode-cn.com/problems/determine-color-of-a-chessboard-square)", "[\u5224\u65ad\u56fd\u9645\u8c61\u68cb\u68cb\u76d8\u4e2d\u4e00\u4e2a\u683c\u5b50\u7684\u989c\u8272](/solution/1800-1899/1812.Determine%20Color%20of%20a%20Chessboard%20Square/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1812](https://leetcode.com/problems/determine-color-of-a-chessboard-square)", "[Determine Color of a Chessboard Square](/solution/1800-1899/1812.Determine%20Color%20of%20a%20Chessboard%20Square/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1919", "frontend_question_id": "1772", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/sort-features-by-popularity", "url_en": "https://leetcode.com/problems/sort-features-by-popularity", "relative_path_cn": "/solution/1700-1799/1772.Sort%20Features%20by%20Popularity/README.md", "relative_path_en": "/solution/1700-1799/1772.Sort%20Features%20by%20Popularity/README_EN.md", "title_cn": "\u6309\u53d7\u6b22\u8fce\u7a0b\u5ea6\u6392\u5217\u529f\u80fd", "title_en": "Sort Features by Popularity", "question_title_slug": "sort-features-by-popularity", "content_en": "

    You are given a string array features where features[i] is a single word that represents the name of a feature of the latest product you are working on. You have made a survey where users have reported which features they like. You are given a string array responses, where each responses[i] is a string containing space-separated words.

    \n\n

    The popularity of a feature is the number of responses[i] that contain the feature. You want to sort the features in non-increasing order by their popularity. If two features have the same popularity, order them by their original index in features. Notice that one response could contain the same feature multiple times; this feature is only counted once in its popularity.

    \n\n

    Return the features in sorted order.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: features = ["cooler","lock","touch"], responses = ["i like cooler cooler","lock touch cool","locker like touch"]\nOutput: ["touch","cooler","lock"]\nExplanation: appearances("cooler") = 1, appearances("lock") = 1, appearances("touch") = 2. Since "cooler" and "lock" both had 1 appearance, "cooler" comes first because "cooler" came first in the features array.\n
    \n\n

    Example 2:

    \n\n
    \nInput: features = ["a","aa","b","c"], responses = ["a","a aa","a a a a a","b a"]\nOutput: ["a","aa","b","c"]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= features.length <= 104
    • \n\t
    • 1 <= features[i].length <= 10
    • \n\t
    • features contains no duplicates.
    • \n\t
    • features[i] consists of lowercase letters.
    • \n\t
    • 1 <= responses.length <= 102
    • \n\t
    • 1 <= responses[i].length <= 103
    • \n\t
    • responses[i] consists of lowercase letters and spaces.
    • \n\t
    • responses[i] contains no two consecutive spaces.
    • \n\t
    • responses[i] has no leading or trailing spaces.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4\u00a0features\u00a0\uff0c\u5176\u4e2d\u00a0features[i]\u00a0\u662f\u4e00\u4e2a\u5355\u8bcd\uff0c\u63cf\u8ff0\u4f60\u6700\u8fd1\u53c2\u4e0e\u5f00\u53d1\u7684\u9879\u76ee\u4e2d\u4e00\u4e2a\u529f\u80fd\u7684\u540d\u79f0\u3002\u4f60\u8c03\u67e5\u4e86\u7528\u6237\u559c\u6b22\u54ea\u4e9b\u529f\u80fd\u3002\u53e6\u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4\u00a0responses\uff0c\u5176\u4e2d\u00a0responses[i]\u00a0\u662f\u4e00\u4e2a\u5305\u542b\u4ee5\u7a7a\u683c\u5206\u9694\u7684\u4e00\u7cfb\u5217\u5355\u8bcd\u7684\u5b57\u7b26\u4e32\u3002

    \n\n

    \u4f60\u60f3\u8981\u6309\u7167\u53d7\u6b22\u8fce\u7a0b\u5ea6\u6392\u5217\u8fd9\u4e9b\u529f\u80fd\u3002\u00a0\u4e25\u683c\u5730\u8bf4\uff0c\u4ee4\u00a0appearances(word)\u00a0\u662f\u6ee1\u8db3 responses[i]\u00a0\u4e2d\u5305\u542b\u5355\u8bcd\u00a0word\u00a0\u7684\u00a0i\u00a0\u7684\u4e2a\u6570\uff0c\u5219\u5f53\u00a0appearances(features[x]) > appearances(features[y])\u00a0\u65f6\uff0c\u7b2c\u00a0x\u00a0\u4e2a\u529f\u80fd\u6bd4\u7b2c\u00a0y\u00a0\u4e2a\u529f\u80fd\u66f4\u53d7\u6b22\u8fce\u3002

    \n\n

    \u8fd4\u56de\u4e00\u4e2a\u6570\u7ec4\u00a0sortedFeatures\u00a0\uff0c\u5305\u542b\u6309\u53d7\u6b22\u8fce\u7a0b\u5ea6\u6392\u5217\u7684\u529f\u80fd\u540d\u79f0\u3002\u5f53\u7b2c\u00a0x\u00a0 \u4e2a\u529f\u80fd\u548c\u7b2c\u00a0y\u00a0\u4e2a\u529f\u80fd\u7684\u53d7\u6b22\u8fce\u7a0b\u5ea6\u76f8\u540c\u4e14\u00a0x < y\u00a0\u65f6\uff0c\u4f60\u5e94\u5f53\u5c06\u7b2c\u00a0x\u00a0\u4e2a\u529f\u80fd\u653e\u5728\u7b2c\u00a0y\u00a0\u4e2a\u529f\u80fd\u4e4b\u524d\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1afeatures = [\"cooler\",\"lock\",\"touch\"], responses = [\"i like cooler cooler\",\"lock touch cool\",\"locker like touch\"]\n\u8f93\u51fa\uff1a[\"touch\",\"cooler\",\"lock\"]\n\u89e3\u91ca\uff1aappearances(\"cooler\") = 1\uff0cappearances(\"lock\") = 1\uff0cappearances(\"touch\") = 2\u3002\u7531\u4e8e \"cooler\" \u548c \"lock\" \u90fd\u51fa\u73b0\u4e86 1 \u6b21\uff0c\u4e14 \"cooler\" \u5728\u539f\u6570\u7ec4\u7684\u524d\u9762\uff0c\u6240\u4ee5 \"cooler\" \u4e5f\u5e94\u8be5\u5728\u7ed3\u679c\u6570\u7ec4\u7684\u524d\u9762\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1afeatures = [\"a\",\"aa\",\"b\",\"c\"], responses = [\"a\",\"a aa\",\"a a a a a\",\"b a\"]\n\u8f93\u51fa\uff1a[\"a\",\"aa\",\"b\",\"c\"]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= features.length\u00a0<= 104
    • \n\t
    • 1 <= features[i].length <= 10
    • \n\t
    • features\u00a0\u4e0d\u5305\u542b\u91cd\u590d\u9879\u3002
    • \n\t
    • features[i]\u00a0\u7531\u5c0f\u5199\u5b57\u6bcd\u6784\u6210\u3002
    • \n\t
    • 1 <= responses.length <= 102
    • \n\t
    • 1 <= responses[i].length <= 103
    • \n\t
    • responses[i]\u00a0\u7531\u5c0f\u5199\u5b57\u6bcd\u548c\u7a7a\u683c\u7ec4\u6210\u3002
    • \n\t
    • responses[i]\u00a0\u4e0d\u5305\u542b\u4e24\u4e2a\u8fde\u7eed\u7684\u7a7a\u683c\u3002
    • \n\t
    • responses[i]\u00a0\u6ca1\u6709\u524d\u7f6e\u6216\u540e\u7f6e\u7a7a\u683c\u3002
    • \n
    \n", "tags_en": ["Sort", "Hash Table"], "tags_cn": ["\u6392\u5e8f", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector sortFeatures(vector& features, vector& responses) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String[] sortFeatures(String[] features, String[] responses) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def sortFeatures(self, features, responses):\n \"\"\"\n :type features: List[str]\n :type responses: List[str]\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def sortFeatures(self, features: List[str], responses: List[str]) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** sortFeatures(char ** features, int featuresSize, char ** responses, int responsesSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string[] SortFeatures(string[] features, string[] responses) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} features\n * @param {string[]} responses\n * @return {string[]}\n */\nvar sortFeatures = function(features, responses) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} features\n# @param {String[]} responses\n# @return {String[]}\ndef sort_features(features, responses)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func sortFeatures(_ features: [String], _ responses: [String]) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func sortFeatures(features []string, responses []string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def sortFeatures(features: Array[String], responses: Array[String]): Array[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun sortFeatures(features: Array, responses: Array): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sort_features(features: Vec, responses: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $features\n * @param String[] $responses\n * @return String[]\n */\n function sortFeatures($features, $responses) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function sortFeatures(features: string[], responses: string[]): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (sort-features features responses)\n (-> (listof string?) (listof string?) (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1772](https://leetcode-cn.com/problems/sort-features-by-popularity)", "[\u6309\u53d7\u6b22\u8fce\u7a0b\u5ea6\u6392\u5217\u529f\u80fd](/solution/1700-1799/1772.Sort%20Features%20by%20Popularity/README.md)", "`\u6392\u5e8f`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1772](https://leetcode.com/problems/sort-features-by-popularity)", "[Sort Features by Popularity](/solution/1700-1799/1772.Sort%20Features%20by%20Popularity/README_EN.md)", "`Sort`,`Hash Table`", "Medium", "\ud83d\udd12"]}, {"question_id": "1918", "frontend_question_id": "1793", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-score-of-a-good-subarray", "url_en": "https://leetcode.com/problems/maximum-score-of-a-good-subarray", "relative_path_cn": "/solution/1700-1799/1793.Maximum%20Score%20of%20a%20Good%20Subarray/README.md", "relative_path_en": "/solution/1700-1799/1793.Maximum%20Score%20of%20a%20Good%20Subarray/README_EN.md", "title_cn": "\u597d\u5b50\u6570\u7ec4\u7684\u6700\u5927\u5206\u6570", "title_en": "Maximum Score of a Good Subarray", "question_title_slug": "maximum-score-of-a-good-subarray", "content_en": "

    You are given an array of integers nums (0-indexed) and an integer k.

    \n\n

    The score of a subarray (i, j) is defined as min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1). A good subarray is a subarray where i <= k <= j.

    \n\n

    Return the maximum possible score of a good subarray.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,4,3,7,4,5], k = 3\nOutput: 15\nExplanation: The optimal subarray is (1, 5) with a score of min(4,3,7,4,5) * (5-1+1) = 3 * 5 = 15. \n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [5,5,4,5,4,1,1,1], k = 0\nOutput: 20\nExplanation: The optimal subarray is (0, 4) with a score of min(5,5,4,5,4) * (4-0+1) = 4 * 5 = 20.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • 1 <= nums[i] <= 2 * 104
    • \n\t
    • 0 <= k < nums.length
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0nums\u00a0\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\u548c\u4e00\u4e2a\u6574\u6570\u00a0k\u00a0\u3002

    \n\n

    \u4e00\u4e2a\u5b50\u6570\u7ec4 (i, j)\u00a0\u7684 \u5206\u6570\u00a0\u5b9a\u4e49\u4e3a\u00a0min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)\u00a0\u3002\u4e00\u4e2a\u00a0\u597d\u00a0\u5b50\u6570\u7ec4\u7684\u4e24\u4e2a\u7aef\u70b9\u4e0b\u6807\u9700\u8981\u6ee1\u8db3\u00a0i <= k <= j\u00a0\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de \u597d\u00a0\u5b50\u6570\u7ec4\u7684\u6700\u5927\u53ef\u80fd \u5206\u6570\u00a0\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,4,3,7,4,5], k = 3\n\u8f93\u51fa\uff1a15\n\u89e3\u91ca\uff1a\u6700\u4f18\u5b50\u6570\u7ec4\u7684\u5de6\u53f3\u7aef\u70b9\u4e0b\u6807\u662f (1, 5) \uff0c\u5206\u6570\u4e3a min(4,3,7,4,5) * (5-1+1) = 3 * 5 = 15 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [5,5,4,5,4,1,1,1], k = 0\n\u8f93\u51fa\uff1a20\n\u89e3\u91ca\uff1a\u6700\u4f18\u5b50\u6570\u7ec4\u7684\u5de6\u53f3\u7aef\u70b9\u4e0b\u6807\u662f (0, 4) \uff0c\u5206\u6570\u4e3a min(5,5,4,5,4) * (4-0+1) = 4 * 5 = 20 \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • 1 <= nums[i] <= 2 * 104
    • \n\t
    • 0 <= k < nums.length
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maximumScore(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maximumScore(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximumScore(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximumScore(self, nums: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maximumScore(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaximumScore(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar maximumScore = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef maximum_score(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximumScore(_ nums: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximumScore(nums []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximumScore(nums: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximumScore(nums: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximum_score(nums: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer\n */\n function maximumScore($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximumScore(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximum-score nums k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1793](https://leetcode-cn.com/problems/maximum-score-of-a-good-subarray)", "[\u597d\u5b50\u6570\u7ec4\u7684\u6700\u5927\u5206\u6570](/solution/1700-1799/1793.Maximum%20Score%20of%20a%20Good%20Subarray/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[1793](https://leetcode.com/problems/maximum-score-of-a-good-subarray)", "[Maximum Score of a Good Subarray](/solution/1700-1799/1793.Maximum%20Score%20of%20a%20Good%20Subarray/README_EN.md)", "`Greedy`", "Hard", ""]}, {"question_id": "1917", "frontend_question_id": "1792", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-average-pass-ratio", "url_en": "https://leetcode.com/problems/maximum-average-pass-ratio", "relative_path_cn": "/solution/1700-1799/1792.Maximum%20Average%20Pass%20Ratio/README.md", "relative_path_en": "/solution/1700-1799/1792.Maximum%20Average%20Pass%20Ratio/README_EN.md", "title_cn": "\u6700\u5927\u5e73\u5747\u901a\u8fc7\u7387", "title_en": "Maximum Average Pass Ratio", "question_title_slug": "maximum-average-pass-ratio", "content_en": "

    There is a school that has classes of students and each class will be having a final exam. You are given a 2D integer array classes, where classes[i] = [passi, totali]. You know beforehand that in the ith class, there are totali total students, but only passi number of students will pass the exam.

    \n\n

    You are also given an integer extraStudents. There are another extraStudents brilliant students that are guaranteed to pass the exam of any class they are assigned to. You want to assign each of the extraStudents students to a class in a way that maximizes the average pass ratio across all the classes.

    \n\n

    The pass ratio of a class is equal to the number of students of the class that will pass the exam divided by the total number of students of the class. The average pass ratio is the sum of pass ratios of all the classes divided by the number of the classes.

    \n\n

    Return the maximum possible average pass ratio after assigning the extraStudents students. Answers within 10-5 of the actual answer will be accepted.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: classes = [[1,2],[3,5],[2,2]], extraStudents = 2\nOutput: 0.78333\nExplanation: You can assign the two extra students to the first class. The average pass ratio will be equal to (3/4 + 3/5 + 2/2) / 3 = 0.78333.\n
    \n\n

    Example 2:

    \n\n
    \nInput: classes = [[2,4],[3,9],[4,5],[2,10]], extraStudents = 4\nOutput: 0.53485\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= classes.length <= 105
    • \n\t
    • classes[i].length == 2
    • \n\t
    • 1 <= passi <= totali <= 105
    • \n\t
    • 1 <= extraStudents <= 105
    • \n
    \n", "content_cn": "

    \u4e00\u6240\u5b66\u6821\u91cc\u6709\u4e00\u4e9b\u73ed\u7ea7\uff0c\u6bcf\u4e2a\u73ed\u7ea7\u91cc\u6709\u4e00\u4e9b\u5b66\u751f\uff0c\u73b0\u5728\u6bcf\u4e2a\u73ed\u90fd\u4f1a\u8fdb\u884c\u4e00\u573a\u671f\u672b\u8003\u8bd5\u3002\u7ed9\u4f60\u4e00\u4e2a\u4e8c\u7ef4\u6570\u7ec4 classes\u00a0\uff0c\u5176\u4e2d\u00a0classes[i] = [passi, totali]\u00a0\uff0c\u8868\u793a\u4f60\u63d0\u524d\u77e5\u9053\u4e86\u7b2c\u00a0i\u00a0\u4e2a\u73ed\u7ea7\u603b\u5171\u6709\u00a0totali\u00a0\u4e2a\u5b66\u751f\uff0c\u5176\u4e2d\u53ea\u6709\u00a0passi\u00a0\u4e2a\u5b66\u751f\u53ef\u4ee5\u901a\u8fc7\u8003\u8bd5\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u00a0extraStudents\u00a0\uff0c\u8868\u793a\u989d\u5916\u6709\u00a0extraStudents\u00a0\u4e2a\u806a\u660e\u7684\u5b66\u751f\uff0c\u4ed6\u4eec \u4e00\u5b9a\u00a0\u80fd\u901a\u8fc7\u4efb\u4f55\u73ed\u7ea7\u7684\u671f\u672b\u8003\u3002\u4f60\u9700\u8981\u7ed9\u8fd9\u00a0extraStudents\u00a0\u4e2a\u5b66\u751f\u6bcf\u4eba\u90fd\u5b89\u6392\u4e00\u4e2a\u73ed\u7ea7\uff0c\u4f7f\u5f97 \u6240\u6709\u00a0\u73ed\u7ea7\u7684 \u5e73\u5747\u00a0\u901a\u8fc7\u7387 \u6700\u5927\u00a0\u3002

    \n\n

    \u4e00\u4e2a\u73ed\u7ea7\u7684\u00a0\u901a\u8fc7\u7387\u00a0\u7b49\u4e8e\u8fd9\u4e2a\u73ed\u7ea7\u901a\u8fc7\u8003\u8bd5\u7684\u5b66\u751f\u4eba\u6570\u9664\u4ee5\u8fd9\u4e2a\u73ed\u7ea7\u7684\u603b\u4eba\u6570\u3002\u5e73\u5747\u901a\u8fc7\u7387\u00a0\u662f\u6240\u6709\u73ed\u7ea7\u7684\u901a\u8fc7\u7387\u4e4b\u548c\u9664\u4ee5\u73ed\u7ea7\u6570\u76ee\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u5728\u5b89\u6392\u8fd9 extraStudents \u4e2a\u5b66\u751f\u53bb\u5bf9\u5e94\u73ed\u7ea7\u540e\u7684 \u6700\u5927\u00a0\u5e73\u5747\u901a\u8fc7\u7387\u3002\u4e0e\u6807\u51c6\u7b54\u6848\u8bef\u5dee\u8303\u56f4\u5728\u00a010-5\u00a0\u4ee5\u5185\u7684\u7ed3\u679c\u90fd\u4f1a\u89c6\u4e3a\u6b63\u786e\u7ed3\u679c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aclasses = [[1,2],[3,5],[2,2]], extraStudents = 2\n\u8f93\u51fa\uff1a0.78333\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u5c06\u989d\u5916\u7684\u4e24\u4e2a\u5b66\u751f\u90fd\u5b89\u6392\u5230\u7b2c\u4e00\u4e2a\u73ed\u7ea7\uff0c\u5e73\u5747\u901a\u8fc7\u7387\u4e3a (3/4 + 3/5 + 2/2) / 3 = 0.78333 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aclasses = [[2,4],[3,9],[4,5],[2,10]], extraStudents = 4\n\u8f93\u51fa\uff1a0.53485\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= classes.length <= 105
    • \n\t
    • classes[i].length == 2
    • \n\t
    • 1 <= passi <= totali <= 105
    • \n\t
    • 1 <= extraStudents <= 105
    • \n
    \n", "tags_en": ["Heap"], "tags_cn": ["\u5806"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n double maxAverageRatio(vector>& classes, int extraStudents) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double maxAverageRatio(int[][] classes, int extraStudents) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxAverageRatio(self, classes, extraStudents):\n \"\"\"\n :type classes: List[List[int]]\n :type extraStudents: int\n :rtype: float\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxAverageRatio(self, classes: List[List[int]], extraStudents: int) -> float:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\ndouble maxAverageRatio(int** classes, int classesSize, int* classesColSize, int extraStudents){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double MaxAverageRatio(int[][] classes, int extraStudents) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} classes\n * @param {number} extraStudents\n * @return {number}\n */\nvar maxAverageRatio = function(classes, extraStudents) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} classes\n# @param {Integer} extra_students\n# @return {Float}\ndef max_average_ratio(classes, extra_students)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxAverageRatio(_ classes: [[Int]], _ extraStudents: Int) -> Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxAverageRatio(classes [][]int, extraStudents int) float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxAverageRatio(classes: Array[Array[Int]], extraStudents: Int): Double = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxAverageRatio(classes: Array, extraStudents: Int): Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_average_ratio(classes: Vec>, extra_students: i32) -> f64 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $classes\n * @param Integer $extraStudents\n * @return Float\n */\n function maxAverageRatio($classes, $extraStudents) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxAverageRatio(classes: number[][], extraStudents: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-average-ratio classes extraStudents)\n (-> (listof (listof exact-integer?)) exact-integer? flonum?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1792](https://leetcode-cn.com/problems/maximum-average-pass-ratio)", "[\u6700\u5927\u5e73\u5747\u901a\u8fc7\u7387](/solution/1700-1799/1792.Maximum%20Average%20Pass%20Ratio/README.md)", "`\u5806`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1792](https://leetcode.com/problems/maximum-average-pass-ratio)", "[Maximum Average Pass Ratio](/solution/1700-1799/1792.Maximum%20Average%20Pass%20Ratio/README_EN.md)", "`Heap`", "Medium", ""]}, {"question_id": "1916", "frontend_question_id": "1791", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-center-of-star-graph", "url_en": "https://leetcode.com/problems/find-center-of-star-graph", "relative_path_cn": "/solution/1700-1799/1791.Find%20Center%20of%20Star%20Graph/README.md", "relative_path_en": "/solution/1700-1799/1791.Find%20Center%20of%20Star%20Graph/README_EN.md", "title_cn": "\u627e\u51fa\u661f\u578b\u56fe\u7684\u4e2d\u5fc3\u8282\u70b9", "title_en": "Find Center of Star Graph", "question_title_slug": "find-center-of-star-graph", "content_en": "

    There is an undirected star graph consisting of n nodes labeled from 1 to n. A star graph is a graph where there is one center node and exactly n - 1 edges that connect the center node with every other node.

    \r\n\r\n

    You are given a 2D integer array edges where each edges[i] = [ui, vi] indicates that there is an edge between the nodes ui and vi. Return the center of the given star graph.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\"\"\r\n
    \r\nInput: edges = [[1,2],[2,3],[4,2]]\r\nOutput: 2\r\nExplanation: As shown in the figure above, node 2 is connected to every other node, so 2 is the center.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: edges = [[1,2],[5,1],[1,3],[1,4]]\r\nOutput: 1\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 3 <= n <= 105
    • \r\n\t
    • edges.length == n - 1
    • \r\n\t
    • edges[i].length == 2
    • \r\n\t
    • 1 <= ui, vi <= n
    • \r\n\t
    • ui != vi
    • \r\n\t
    • The given edges represent a valid star graph.
    • \r\n
    ", "content_cn": "

    \u6709\u4e00\u4e2a\u65e0\u5411\u7684 \u661f\u578b \u56fe\uff0c\u7531 n \u4e2a\u7f16\u53f7\u4ece 1 \u5230 n \u7684\u8282\u70b9\u7ec4\u6210\u3002\u661f\u578b\u56fe\u6709\u4e00\u4e2a \u4e2d\u5fc3 \u8282\u70b9\uff0c\u5e76\u4e14\u6070\u6709 n - 1 \u6761\u8fb9\u5c06\u4e2d\u5fc3\u8282\u70b9\u4e0e\u5176\u4ed6\u6bcf\u4e2a\u8282\u70b9\u8fde\u63a5\u8d77\u6765\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u4e8c\u7ef4\u6574\u6570\u6570\u7ec4 edges \uff0c\u5176\u4e2d\u00a0edges[i] = [ui, vi] \u8868\u793a\u5728\u8282\u70b9 ui \u548c vi \u4e4b\u95f4\u5b58\u5728\u4e00\u6761\u8fb9\u3002\u8bf7\u4f60\u627e\u51fa\u5e76\u8fd4\u56de\u00a0edges \u6240\u8868\u793a\u661f\u578b\u56fe\u7684\u4e2d\u5fc3\u8282\u70b9\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aedges = [[1,2],[2,3],[4,2]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5982\u4e0a\u56fe\u6240\u793a\uff0c\u8282\u70b9 2 \u4e0e\u5176\u4ed6\u6bcf\u4e2a\u8282\u70b9\u90fd\u76f8\u8fde\uff0c\u6240\u4ee5\u8282\u70b9 2 \u662f\u4e2d\u5fc3\u8282\u70b9\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aedges = [[1,2],[5,1],[1,3],[1,4]]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 3 <= n <= 105
    • \n\t
    • edges.length == n - 1
    • \n\t
    • edges[i].length == 2
    • \n\t
    • 1 <= ui, vi <= n
    • \n\t
    • ui != vi
    • \n\t
    • \u9898\u76ee\u6570\u636e\u7ed9\u51fa\u7684 edges \u8868\u793a\u4e00\u4e2a\u6709\u6548\u7684\u661f\u578b\u56fe
    • \n
    \n", "tags_en": ["Graph"], "tags_cn": ["\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findCenter(vector>& edges) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findCenter(int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findCenter(self, edges):\n \"\"\"\n :type edges: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findCenter(self, edges: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findCenter(int** edges, int edgesSize, int* edgesColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindCenter(int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} edges\n * @return {number}\n */\nvar findCenter = function(edges) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} edges\n# @return {Integer}\ndef find_center(edges)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findCenter(_ edges: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findCenter(edges [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findCenter(edges: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findCenter(edges: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_center(edges: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $edges\n * @return Integer\n */\n function findCenter($edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findCenter(edges: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-center edges)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1791](https://leetcode-cn.com/problems/find-center-of-star-graph)", "[\u627e\u51fa\u661f\u578b\u56fe\u7684\u4e2d\u5fc3\u8282\u70b9](/solution/1700-1799/1791.Find%20Center%20of%20Star%20Graph/README.md)", "`\u56fe`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1791](https://leetcode.com/problems/find-center-of-star-graph)", "[Find Center of Star Graph](/solution/1700-1799/1791.Find%20Center%20of%20Star%20Graph/README_EN.md)", "`Graph`", "Medium", ""]}, {"question_id": "1915", "frontend_question_id": "1790", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/check-if-one-string-swap-can-make-strings-equal", "url_en": "https://leetcode.com/problems/check-if-one-string-swap-can-make-strings-equal", "relative_path_cn": "/solution/1700-1799/1790.Check%20if%20One%20String%20Swap%20Can%20Make%20Strings%20Equal/README.md", "relative_path_en": "/solution/1700-1799/1790.Check%20if%20One%20String%20Swap%20Can%20Make%20Strings%20Equal/README_EN.md", "title_cn": "\u4ec5\u6267\u884c\u4e00\u6b21\u5b57\u7b26\u4e32\u4ea4\u6362\u80fd\u5426\u4f7f\u4e24\u4e2a\u5b57\u7b26\u4e32\u76f8\u7b49", "title_en": "Check if One String Swap Can Make Strings Equal", "question_title_slug": "check-if-one-string-swap-can-make-strings-equal", "content_en": "

    You are given two strings s1 and s2 of equal length. A string swap is an operation where you choose two indices in a string (not necessarily different) and swap the characters at these indices.

    \n\n

    Return true if it is possible to make both strings equal by performing at most one string swap on exactly one of the strings. Otherwise, return false.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s1 = "bank", s2 = "kanb"\nOutput: true\nExplanation: For example, swap the first character with the last character of s2 to make "bank".\n
    \n\n

    Example 2:

    \n\n
    \nInput: s1 = "attack", s2 = "defend"\nOutput: false\nExplanation: It is impossible to make them equal with one string swap.\n
    \n\n

    Example 3:

    \n\n
    \nInput: s1 = "kelb", s2 = "kelb"\nOutput: true\nExplanation: The two strings are already equal, so no string swap operation is required.\n
    \n\n

    Example 4:

    \n\n
    \nInput: s1 = "abcd", s2 = "dcba"\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s1.length, s2.length <= 100
    • \n\t
    • s1.length == s2.length
    • \n\t
    • s1 and s2 consist of only lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u957f\u5ea6\u76f8\u7b49\u7684\u4e24\u4e2a\u5b57\u7b26\u4e32 s1 \u548c s2 \u3002\u4e00\u6b21 \u5b57\u7b26\u4e32\u4ea4\u6362 \u64cd\u4f5c\u7684\u6b65\u9aa4\u5982\u4e0b\uff1a\u9009\u51fa\u67d0\u4e2a\u5b57\u7b26\u4e32\u4e2d\u7684\u4e24\u4e2a\u4e0b\u6807\uff08\u4e0d\u5fc5\u4e0d\u540c\uff09\uff0c\u5e76\u4ea4\u6362\u8fd9\u4e24\u4e2a\u4e0b\u6807\u6240\u5bf9\u5e94\u7684\u5b57\u7b26\u3002

    \n\n

    \u5982\u679c\u5bf9 \u5176\u4e2d\u4e00\u4e2a\u5b57\u7b26\u4e32 \u6267\u884c \u6700\u591a\u4e00\u6b21\u5b57\u7b26\u4e32\u4ea4\u6362 \u5c31\u53ef\u4ee5\u4f7f\u4e24\u4e2a\u5b57\u7b26\u4e32\u76f8\u7b49\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1as1 = \"bank\", s2 = \"kanb\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u4f8b\u5982\uff0c\u4ea4\u6362 s2 \u4e2d\u7684\u7b2c\u4e00\u4e2a\u548c\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\u53ef\u4ee5\u5f97\u5230 \"bank\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1as1 = \"attack\", s2 = \"defend\"\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u4e00\u6b21\u5b57\u7b26\u4e32\u4ea4\u6362\u65e0\u6cd5\u4f7f\u4e24\u4e2a\u5b57\u7b26\u4e32\u76f8\u7b49\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1as1 = \"kelb\", s2 = \"kelb\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u4e24\u4e2a\u5b57\u7b26\u4e32\u5df2\u7ecf\u76f8\u7b49\uff0c\u6240\u4ee5\u4e0d\u9700\u8981\u8fdb\u884c\u5b57\u7b26\u4e32\u4ea4\u6362\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1as1 = \"abcd\", s2 = \"dcba\"\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s1.length, s2.length <= 100
    • \n\t
    • s1.length == s2.length
    • \n\t
    • s1 \u548c s2 \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool areAlmostEqual(string s1, string s2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean areAlmostEqual(String s1, String s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def areAlmostEqual(self, s1, s2):\n \"\"\"\n :type s1: str\n :type s2: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def areAlmostEqual(self, s1: str, s2: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool areAlmostEqual(char * s1, char * s2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool AreAlmostEqual(string s1, string s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s1\n * @param {string} s2\n * @return {boolean}\n */\nvar areAlmostEqual = function(s1, s2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s1\n# @param {String} s2\n# @return {Boolean}\ndef are_almost_equal(s1, s2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func areAlmostEqual(_ s1: String, _ s2: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func areAlmostEqual(s1 string, s2 string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def areAlmostEqual(s1: String, s2: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun areAlmostEqual(s1: String, s2: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn are_almost_equal(s1: String, s2: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s1\n * @param String $s2\n * @return Boolean\n */\n function areAlmostEqual($s1, $s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function areAlmostEqual(s1: string, s2: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (are-almost-equal s1 s2)\n (-> string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1790](https://leetcode-cn.com/problems/check-if-one-string-swap-can-make-strings-equal)", "[\u4ec5\u6267\u884c\u4e00\u6b21\u5b57\u7b26\u4e32\u4ea4\u6362\u80fd\u5426\u4f7f\u4e24\u4e2a\u5b57\u7b26\u4e32\u76f8\u7b49](/solution/1700-1799/1790.Check%20if%20One%20String%20Swap%20Can%20Make%20Strings%20Equal/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1790](https://leetcode.com/problems/check-if-one-string-swap-can-make-strings-equal)", "[Check if One String Swap Can Make Strings Equal](/solution/1700-1799/1790.Check%20if%20One%20String%20Swap%20Can%20Make%20Strings%20Equal/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1914", "frontend_question_id": "1767", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/find-the-subtasks-that-did-not-execute", "url_en": "https://leetcode.com/problems/find-the-subtasks-that-did-not-execute", "relative_path_cn": "/solution/1700-1799/1767.Find%20the%20Subtasks%20That%20Did%20Not%20Execute/README.md", "relative_path_en": "/solution/1700-1799/1767.Find%20the%20Subtasks%20That%20Did%20Not%20Execute/README_EN.md", "title_cn": "\u5bfb\u627e\u6ca1\u6709\u88ab\u6267\u884c\u7684\u4efb\u52a1\u5bf9", "title_en": "Find the Subtasks That Did Not Execute", "question_title_slug": "find-the-subtasks-that-did-not-execute", "content_en": "

    Table: Tasks

    \n\n
    \n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| task_id        | int     |\n| subtasks_count | int     |\n+----------------+---------+\ntask_id is the primary key for this table.\nEach row in this table indicates that task_id was divided into subtasks_count subtasks labelled from 1 to subtasks_count.\nIt is guaranteed that 2 <= subtasks_count <= 20.\n
    \n\n

     

    \n\n

    Table: Executed

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| task_id       | int     |\n| subtask_id    | int     |\n+---------------+---------+\n(task_id, subtask_id) is the primary key for this table.\nEach row in this table indicates that for the task task_id, the subtask with ID subtask_id was executed successfully.\nIt is guaranteed that subtask_id <= subtasks_count for each task_id.
    \n\n

     

    \n\n

    Write an SQL query to report the IDs of the missing subtasks for each task_id.

    \n\n

    Return the result table in any order.

    \n\n

    The query result format is in the following example:

    \n\n

     

    \n\n
    \nTasks table:\n+---------+----------------+\n| task_id | subtasks_count |\n+---------+----------------+\n| 1       | 3              |\n| 2       | 2              |\n| 3       | 4              |\n+---------+----------------+\n\nExecuted table:\n+---------+------------+\n| task_id | subtask_id |\n+---------+------------+\n| 1       | 2          |\n| 3       | 1          |\n| 3       | 2          |\n| 3       | 3          |\n| 3       | 4          |\n+---------+------------+\n\nResult table:\n+---------+------------+\n| task_id | subtask_id |\n+---------+------------+\n| 1       | 1          |\n| 1       | 3          |\n| 2       | 1          |\n| 2       | 2          |\n+---------+------------+\nTask 1 was divided into 3 subtasks (1, 2, 3). Only subtask 2 was executed successfully, so we include (1, 1) and (1, 3) in the answer.\nTask 2 was divided into 2 subtasks (1, 2). No subtask was executed successfully, so we include (2, 1) and (2, 2) in the answer.\nTask 3 was divided into 4 subtasks (1, 2, 3, 4). All of the subtasks were executed successfully.\n
    \n", "content_cn": "

    \u8868\uff1aTasks

    \n\n
    \n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| task_id        | int     |\n| subtasks_count | int     |\n+----------------+---------+\ntask_id \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\u3002\ntask_id \u8868\u793a\u7684\u4e3a\u4e3b\u4efb\u52a1\u7684id,\u6bcf\u4e00\u4e2atask_id\u88ab\u5206\u4e3a\u4e86\u591a\u4e2a\u5b50\u4efb\u52a1(subtasks)\uff0csubtasks_count\u8868\u793a\u4e3a\u5b50\u4efb\u52a1\u7684\u4e2a\u6570\uff08n\uff09\uff0c\u5b83\u7684\u503c\u8868\u793a\u4e86\u5b50\u4efb\u52a1\u7684\u7d22\u5f15\u4ece1\u5230n\u3002\n\u672c\u8868\u4fdd\u8bc12 <=subtasks_count<= 20\u3002\n
    \n\n

    \u8868\uff1a Executed

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| task_id       | int     |\n| subtask_id    | int     |\n+---------------+---------+\n(task_id, subtask_id) \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\u3002\n\u6bcf\u4e00\u884c\u8868\u793a\u6807\u8bb0\u4e3atask_id\u7684\u4e3b\u4efb\u52a1\u4e0e\u6807\u8bb0\u4e3asubtask_id\u7684\u5b50\u4efb\u52a1\u88ab\u6210\u529f\u6267\u884c\u3002\n\u672c\u8868\u4fdd\u8bc1\uff0c\u5bf9\u4e8e\u6bcf\u4e00\u4e2atask_id\uff0csubtask_id <= subtasks_count\u3002\n
    \n\n

    \u00a0

    \n\n

    \u8bf7\u8bd5\u5199\u4e00\u4e2aSQL\u67e5\u8be2\u8bed\u53e5\u62a5\u544a\u6ca1\u6709\u88ab\u6267\u884c\u7684\uff08\u4e3b\u4efb\u52a1\uff0c\u5b50\u4efb\u52a1\uff09\u5bf9\uff0c\u5373\u6ca1\u6709\u88ab\u6267\u884c\u7684\uff08task_id, subtask_id\uff09\u3002

    \n\n

    \u4ee5 \u4efb\u4f55\u987a\u5e8f \u8fd4\u56de\u5373\u53ef\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\uff1a

    \n\n

    \u00a0

    \n\n
    \nTasks table:\n+---------+----------------+\n| task_id | subtasks_count |\n+---------+----------------+\n| 1       | 3              |\n| 2       | 2              |\n| 3       | 4              |\n+---------+----------------+\n\nExecuted table:\n+---------+------------+\n| task_id | subtask_id |\n+---------+------------+\n| 1       | 2          |\n| 3       | 1          |\n| 3       | 2          |\n| 3       | 3          |\n| 3       | 4          |\n+---------+------------+\n\nResult table:\n+---------+------------+\n| task_id | subtask_id |\n+---------+------------+\n| 1       | 1          |\n| 1       | 3          |\n| 2       | 1          |\n| 2       | 2          |\n+---------+------------+\nTask 1 \u88ab\u5206\u6210\u4e86 3 subtasks (1, 2, 3)\u3002\u53ea\u6709 subtask 2 \u88ab\u6210\u529f\u6267\u884c, \u6240\u4ee5\u6211\u4eec\u8fd4\u56de (1, 1) \u548c (1, 3) \u8fd9\u4e24\u4e2a\u4e3b\u4efb\u52a1\u5b50\u4efb\u52a1\u5bf9\u3002\nTask 2 \u88ab\u5206\u6210\u4e86 2 subtasks (1, 2)\u3002\u6ca1\u6709\u4e00\u4e2asubtask\u88ab\u6210\u529f\u6267\u884c, \u56e0\u6b64\u6211\u4eec\u8fd4\u56de(2, 1)\u548c(2, 2)\u3002\nTask 3 \u88ab\u5206\u6210\u4e86 4 subtasks (1, 2, 3, 4)\u3002\u6240\u6709\u7684subtask\u90fd\u88ab\u6210\u529f\u6267\u884c\uff0c\u56e0\u6b64\u5bf9\u4e8eTask 3,\u6211\u4eec\u4e0d\u8fd4\u56de\u4efb\u4f55\u503c\u3002\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1767](https://leetcode-cn.com/problems/find-the-subtasks-that-did-not-execute)", "[\u5bfb\u627e\u6ca1\u6709\u88ab\u6267\u884c\u7684\u4efb\u52a1\u5bf9](/solution/1700-1799/1767.Find%20the%20Subtasks%20That%20Did%20Not%20Execute/README.md)", "", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1767](https://leetcode.com/problems/find-the-subtasks-that-did-not-execute)", "[Find the Subtasks That Did Not Execute](/solution/1700-1799/1767.Find%20the%20Subtasks%20That%20Did%20Not%20Execute/README_EN.md)", "", "Hard", "\ud83d\udd12"]}, {"question_id": "1913", "frontend_question_id": "1787", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/make-the-xor-of-all-segments-equal-to-zero", "url_en": "https://leetcode.com/problems/make-the-xor-of-all-segments-equal-to-zero", "relative_path_cn": "/solution/1700-1799/1787.Make%20the%20XOR%20of%20All%20Segments%20Equal%20to%20Zero/README.md", "relative_path_en": "/solution/1700-1799/1787.Make%20the%20XOR%20of%20All%20Segments%20Equal%20to%20Zero/README_EN.md", "title_cn": "\u4f7f\u6240\u6709\u533a\u95f4\u7684\u5f02\u6216\u7ed3\u679c\u4e3a\u96f6", "title_en": "Make the XOR of All Segments Equal to Zero", "question_title_slug": "make-the-xor-of-all-segments-equal-to-zero", "content_en": "

    You are given an array nums\u200b\u200b\u200b and an integer k\u200b\u200b\u200b\u200b\u200b. The XOR of a segment [left, right] where left <= right is the XOR of all the elements with indices between left and right, inclusive: nums[left] XOR nums[left+1] XOR ... XOR nums[right].

    \n\n

    Return the minimum number of elements to change in the array such that the XOR of all segments of size k\u200b\u200b\u200b\u200b\u200b\u200b is equal to zero.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,0,3,0], k = 1\nOutput: 3\nExplanation: Modify the array from [1,2,0,3,0] to from [0,0,0,0,0].\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [3,4,5,2,1,7,3,4,7], k = 3\nOutput: 3\nExplanation: Modify the array from [3,4,5,2,1,7,3,4,7] to [3,4,7,3,4,7,3,4,7].\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [1,2,4,1,2,5,1,2,6], k = 3\nOutput: 3\nExplanation: Modify the array from [1,2,4,1,2,5,1,2,6] to [1,2,3,1,2,3,1,2,3].
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= k <= nums.length <= 2000
    • \n\t
    • \u200b\u200b\u200b\u200b\u200b\u200b0 <= nums[i] < 210
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums\u200b\u200b\u200b \u548c\u4e00\u4e2a\u6574\u6570 k\u200b\u200b\u200b\u200b\u200b \u3002\u533a\u95f4 [left, right]\uff08left <= right\uff09\u7684 \u5f02\u6216\u7ed3\u679c \u662f\u5bf9\u4e0b\u6807\u4f4d\u4e8e\u00a0left \u548c right\uff08\u5305\u62ec left \u548c right \uff09\u4e4b\u95f4\u6240\u6709\u5143\u7d20\u8fdb\u884c XOR \u8fd0\u7b97\u7684\u7ed3\u679c\uff1anums[left] XOR nums[left+1] XOR ... XOR nums[right] \u3002

    \n\n

    \u8fd4\u56de\u6570\u7ec4\u4e2d \u8981\u66f4\u6539\u7684\u6700\u5c0f\u5143\u7d20\u6570 \uff0c\u4ee5\u4f7f\u6240\u6709\u957f\u5ea6\u4e3a k \u7684\u533a\u95f4\u5f02\u6216\u7ed3\u679c\u7b49\u4e8e\u96f6\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,0,3,0], k = 1\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u5c06\u6570\u7ec4 [1,2,0,3,0] \u4fee\u6539\u4e3a [0,0,0,0,0]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [3,4,5,2,1,7,3,4,7], k = 3\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u5c06\u6570\u7ec4 [3,4,5,2,1,7,3,4,7] \u4fee\u6539\u4e3a [3,4,7,3,4,7,3,4,7]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,4,1,2,5,1,2,6], k = 3\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u5c06\u6570\u7ec4[1,2,4,1,2,5,1,2,6] \u4fee\u6539\u4e3a [1,2,3,1,2,3,1,2,3]
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= k <= nums.length <= 2000
    • \n\t
    • \u200b\u200b\u200b\u200b\u200b\u200b0 <= nums[i] < 210
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minChanges(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minChanges(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minChanges(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minChanges(self, nums: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minChanges(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinChanges(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar minChanges = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef min_changes(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minChanges(_ nums: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minChanges(nums []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minChanges(nums: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minChanges(nums: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_changes(nums: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer\n */\n function minChanges($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minChanges(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-changes nums k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1787](https://leetcode-cn.com/problems/make-the-xor-of-all-segments-equal-to-zero)", "[\u4f7f\u6240\u6709\u533a\u95f4\u7684\u5f02\u6216\u7ed3\u679c\u4e3a\u96f6](/solution/1700-1799/1787.Make%20the%20XOR%20of%20All%20Segments%20Equal%20to%20Zero/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1787](https://leetcode.com/problems/make-the-xor-of-all-segments-equal-to-zero)", "[Make the XOR of All Segments Equal to Zero](/solution/1700-1799/1787.Make%20the%20XOR%20of%20All%20Segments%20Equal%20to%20Zero/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1912", "frontend_question_id": "1786", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-restricted-paths-from-first-to-last-node", "url_en": "https://leetcode.com/problems/number-of-restricted-paths-from-first-to-last-node", "relative_path_cn": "/solution/1700-1799/1786.Number%20of%20Restricted%20Paths%20From%20First%20to%20Last%20Node/README.md", "relative_path_en": "/solution/1700-1799/1786.Number%20of%20Restricted%20Paths%20From%20First%20to%20Last%20Node/README_EN.md", "title_cn": "\u4ece\u7b2c\u4e00\u4e2a\u8282\u70b9\u51fa\u53d1\u5230\u6700\u540e\u4e00\u4e2a\u8282\u70b9\u7684\u53d7\u9650\u8def\u5f84\u6570", "title_en": "Number of Restricted Paths From First to Last Node", "question_title_slug": "number-of-restricted-paths-from-first-to-last-node", "content_en": "

    There is an undirected weighted connected graph. You are given a positive integer n which denotes that the graph has n nodes labeled from 1 to n, and an array edges where each edges[i] = [ui, vi, weighti] denotes that there is an edge between nodes ui and vi with weight equal to weighti.

    \n\n

    A path from node start to node end is a sequence of nodes [z0, z1, z2, ..., zk] such that z0 = start and zk = end and there is an edge between zi and zi+1 where 0 <= i <= k-1.

    \n\n

    The distance of a path is the sum of the weights on the edges of the path. Let distanceToLastNode(x) denote the shortest distance of a path between node n and node x. A restricted path is a path that also satisfies that distanceToLastNode(zi) > distanceToLastNode(zi+1) where 0 <= i <= k-1.

    \n\n

    Return the number of restricted paths from node 1 to node n. Since that number may be too large, return it modulo 109 + 7.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: n = 5, edges = [[1,2,3],[1,3,3],[2,3,1],[1,4,2],[5,2,2],[3,5,1],[5,4,10]]\nOutput: 3\nExplanation: Each circle contains the node number in black and its distanceToLastNode value in blue. The three restricted paths are:\n1) 1 --> 2 --> 5\n2) 1 --> 2 --> 3 --> 5\n3) 1 --> 3 --> 5\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: n = 7, edges = [[1,3,1],[4,1,2],[7,3,4],[2,5,3],[5,6,1],[6,7,2],[7,5,3],[2,6,4]]\nOutput: 1\nExplanation: Each circle contains the node number in black and its distanceToLastNode value in blue. The only restricted path is 1 --> 3 --> 7.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 2 * 104
    • \n\t
    • n - 1 <= edges.length <= 4 * 104
    • \n\t
    • edges[i].length == 3
    • \n\t
    • 1 <= ui, vi <= n
    • \n\t
    • ui != vi
    • \n\t
    • 1 <= weighti <= 105
    • \n\t
    • There is at most one edge between any two nodes.
    • \n\t
    • There is at least one path between any two nodes.
    • \n
    \n", "content_cn": "

    \u73b0\u6709\u4e00\u4e2a\u52a0\u6743\u65e0\u5411\u8fde\u901a\u56fe\u3002\u7ed9\u4f60\u4e00\u4e2a\u6b63\u6574\u6570 n \uff0c\u8868\u793a\u56fe\u4e2d\u6709 n \u4e2a\u8282\u70b9\uff0c\u5e76\u6309\u4ece 1 \u5230 n \u7ed9\u8282\u70b9\u7f16\u53f7\uff1b\u53e6\u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 edges \uff0c\u5176\u4e2d\u6bcf\u4e2a edges[i] = [ui, vi, weighti] \u8868\u793a\u5b58\u5728\u4e00\u6761\u4f4d\u4e8e\u8282\u70b9 ui \u548c vi \u4e4b\u95f4\u7684\u8fb9\uff0c\u8fd9\u6761\u8fb9\u7684\u6743\u91cd\u4e3a weighti \u3002

    \n\n

    \u4ece\u8282\u70b9 start \u51fa\u53d1\u5230\u8282\u70b9 end \u7684\u8def\u5f84\u662f\u4e00\u4e2a\u5f62\u5982 [z0, z1, z2, ..., zk] \u7684\u8282\u70b9\u5e8f\u5217\uff0c\u6ee1\u8db3 z0 = start \u3001zk = end \u4e14\u5728\u6240\u6709\u7b26\u5408 0 <= i <= k-1 \u7684\u8282\u70b9 zi \u548c zi+1 \u4e4b\u95f4\u5b58\u5728\u4e00\u6761\u8fb9\u3002

    \n\n

    \u8def\u5f84\u7684\u8ddd\u79bb\u5b9a\u4e49\u4e3a\u8fd9\u6761\u8def\u5f84\u4e0a\u6240\u6709\u8fb9\u7684\u6743\u91cd\u603b\u548c\u3002\u7528 distanceToLastNode(x) \u8868\u793a\u8282\u70b9 n \u548c x \u4e4b\u95f4\u8def\u5f84\u7684\u6700\u77ed\u8ddd\u79bb\u3002\u53d7\u9650\u8def\u5f84 \u4e3a\u6ee1\u8db3 distanceToLastNode(zi) > distanceToLastNode(zi+1) \u7684\u4e00\u6761\u8def\u5f84\uff0c\u5176\u4e2d 0 <= i <= k-1 \u3002

    \n\n

    \u8fd4\u56de\u4ece\u8282\u70b9 1 \u51fa\u53d1\u5230\u8282\u70b9 n \u7684 \u53d7\u9650\u8def\u5f84\u6570 \u3002\u7531\u4e8e\u6570\u5b57\u53ef\u80fd\u5f88\u5927\uff0c\u8bf7\u8fd4\u56de\u5bf9 109 + 7 \u53d6\u4f59 \u7684\u7ed3\u679c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1an = 5, edges = [[1,2,3],[1,3,3],[2,3,1],[1,4,2],[5,2,2],[3,5,1],[5,4,10]]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6bcf\u4e2a\u5706\u5305\u542b\u9ed1\u8272\u7684\u8282\u70b9\u7f16\u53f7\u548c\u84dd\u8272\u7684 distanceToLastNode \u503c\u3002\u4e09\u6761\u53d7\u9650\u8def\u5f84\u5206\u522b\u662f\uff1a\n1) 1 --> 2 --> 5\n2) 1 --> 2 --> 3 --> 5\n3) 1 --> 3 --> 5\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1an = 7, edges = [[1,3,1],[4,1,2],[7,3,4],[2,5,3],[5,6,1],[6,7,2],[7,5,3],[2,6,4]]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u6bcf\u4e2a\u5706\u5305\u542b\u9ed1\u8272\u7684\u8282\u70b9\u7f16\u53f7\u548c\u84dd\u8272\u7684 distanceToLastNode \u503c\u3002\u552f\u4e00\u4e00\u6761\u53d7\u9650\u8def\u5f84\u662f\uff1a1 --> 3 --> 7 \u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 2 * 104
    • \n\t
    • n - 1 <= edges.length <= 4 * 104
    • \n\t
    • edges[i].length == 3
    • \n\t
    • 1 <= ui, vi <= n
    • \n\t
    • ui != vi
    • \n\t
    • 1 <= weighti <= 105
    • \n\t
    • \u4efb\u610f\u4e24\u4e2a\u8282\u70b9\u4e4b\u95f4\u81f3\u591a\u5b58\u5728\u4e00\u6761\u8fb9
    • \n\t
    • \u4efb\u610f\u4e24\u4e2a\u8282\u70b9\u4e4b\u95f4\u81f3\u5c11\u5b58\u5728\u4e00\u6761\u8def\u5f84
    • \n
    \n", "tags_en": ["Graph", "Dynamic Programming"], "tags_cn": ["\u56fe", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countRestrictedPaths(int n, vector>& edges) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countRestrictedPaths(int n, int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countRestrictedPaths(self, n, edges):\n \"\"\"\n :type n: int\n :type edges: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countRestrictedPaths(self, n: int, edges: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countRestrictedPaths(int n, int** edges, int edgesSize, int* edgesColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountRestrictedPaths(int n, int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} edges\n * @return {number}\n */\nvar countRestrictedPaths = function(n, edges) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} edges\n# @return {Integer}\ndef count_restricted_paths(n, edges)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countRestrictedPaths(_ n: Int, _ edges: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countRestrictedPaths(n int, edges [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countRestrictedPaths(n: Int, edges: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countRestrictedPaths(n: Int, edges: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_restricted_paths(n: i32, edges: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $edges\n * @return Integer\n */\n function countRestrictedPaths($n, $edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countRestrictedPaths(n: number, edges: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-restricted-paths n edges)\n (-> exact-integer? (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1786](https://leetcode-cn.com/problems/number-of-restricted-paths-from-first-to-last-node)", "[\u4ece\u7b2c\u4e00\u4e2a\u8282\u70b9\u51fa\u53d1\u5230\u6700\u540e\u4e00\u4e2a\u8282\u70b9\u7684\u53d7\u9650\u8def\u5f84\u6570](/solution/1700-1799/1786.Number%20of%20Restricted%20Paths%20From%20First%20to%20Last%20Node/README.md)", "`\u56fe`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1786](https://leetcode.com/problems/number-of-restricted-paths-from-first-to-last-node)", "[Number of Restricted Paths From First to Last Node](/solution/1700-1799/1786.Number%20of%20Restricted%20Paths%20From%20First%20to%20Last%20Node/README_EN.md)", "`Graph`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "1911", "frontend_question_id": "1785", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-elements-to-add-to-form-a-given-sum", "url_en": "https://leetcode.com/problems/minimum-elements-to-add-to-form-a-given-sum", "relative_path_cn": "/solution/1700-1799/1785.Minimum%20Elements%20to%20Add%20to%20Form%20a%20Given%20Sum/README.md", "relative_path_en": "/solution/1700-1799/1785.Minimum%20Elements%20to%20Add%20to%20Form%20a%20Given%20Sum/README_EN.md", "title_cn": "\u6784\u6210\u7279\u5b9a\u548c\u9700\u8981\u6dfb\u52a0\u7684\u6700\u5c11\u5143\u7d20", "title_en": "Minimum Elements to Add to Form a Given Sum", "question_title_slug": "minimum-elements-to-add-to-form-a-given-sum", "content_en": "

    You are given an integer array nums and two integers limit and goal. The array nums has an interesting property that abs(nums[i]) <= limit.

    \n\n

    Return the minimum number of elements you need to add to make the sum of the array equal to goal. The array must maintain its property that abs(nums[i]) <= limit.

    \n\n

    Note that abs(x) equals x if x >= 0, and -x otherwise.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,-1,1], limit = 3, goal = -4\nOutput: 2\nExplanation: You can add -2 and -3, then the sum of the array will be 1 - 1 + 1 - 2 - 3 = -4.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,-10,9,1], limit = 100, goal = 0\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • 1 <= limit <= 106
    • \n\t
    • -limit <= nums[i] <= limit
    • \n\t
    • -109 <= goal <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \uff0c\u548c\u4e24\u4e2a\u6574\u6570 limit \u4e0e goal \u3002\u6570\u7ec4 nums \u6709\u4e00\u6761\u91cd\u8981\u5c5e\u6027\uff1aabs(nums[i]) <= limit \u3002

    \n\n

    \u8fd4\u56de\u4f7f\u6570\u7ec4\u5143\u7d20\u603b\u548c\u7b49\u4e8e goal \u6240\u9700\u8981\u5411\u6570\u7ec4\u4e2d\u6dfb\u52a0\u7684 \u6700\u5c11\u5143\u7d20\u6570\u91cf \uff0c\u6dfb\u52a0\u5143\u7d20 \u4e0d\u5e94\u6539\u53d8 \u6570\u7ec4\u4e2d abs(nums[i]) <= limit \u8fd9\u4e00\u5c5e\u6027\u3002

    \n\n

    \u6ce8\u610f\uff0c\u5982\u679c x >= 0 \uff0c\u90a3\u4e48 abs(x) \u7b49\u4e8e x \uff1b\u5426\u5219\uff0c\u7b49\u4e8e -x \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,-1,1], limit = 3, goal = -4\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u53ef\u4ee5\u5c06 -2 \u548c -3 \u6dfb\u52a0\u5230\u6570\u7ec4\u4e2d\uff0c\u6570\u7ec4\u7684\u5143\u7d20\u603b\u548c\u53d8\u4e3a 1 - 1 + 1 - 2 - 3 = -4 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,-10,9,1], limit = 100, goal = 0\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • 1 <= limit <= 106
    • \n\t
    • -limit <= nums[i] <= limit
    • \n\t
    • -109 <= goal <= 109
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minElements(vector& nums, int limit, int goal) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minElements(int[] nums, int limit, int goal) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minElements(self, nums, limit, goal):\n \"\"\"\n :type nums: List[int]\n :type limit: int\n :type goal: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minElements(self, nums: List[int], limit: int, goal: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minElements(int* nums, int numsSize, int limit, int goal){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinElements(int[] nums, int limit, int goal) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} limit\n * @param {number} goal\n * @return {number}\n */\nvar minElements = function(nums, limit, goal) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} limit\n# @param {Integer} goal\n# @return {Integer}\ndef min_elements(nums, limit, goal)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minElements(_ nums: [Int], _ limit: Int, _ goal: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minElements(nums []int, limit int, goal int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minElements(nums: Array[Int], limit: Int, goal: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minElements(nums: IntArray, limit: Int, goal: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_elements(nums: Vec, limit: i32, goal: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $limit\n * @param Integer $goal\n * @return Integer\n */\n function minElements($nums, $limit, $goal) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minElements(nums: number[], limit: number, goal: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-elements nums limit goal)\n (-> (listof exact-integer?) exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1785](https://leetcode-cn.com/problems/minimum-elements-to-add-to-form-a-given-sum)", "[\u6784\u6210\u7279\u5b9a\u548c\u9700\u8981\u6dfb\u52a0\u7684\u6700\u5c11\u5143\u7d20](/solution/1700-1799/1785.Minimum%20Elements%20to%20Add%20to%20Form%20a%20Given%20Sum/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1785](https://leetcode.com/problems/minimum-elements-to-add-to-form-a-given-sum)", "[Minimum Elements to Add to Form a Given Sum](/solution/1700-1799/1785.Minimum%20Elements%20to%20Add%20to%20Form%20a%20Given%20Sum/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1910", "frontend_question_id": "1784", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/check-if-binary-string-has-at-most-one-segment-of-ones", "url_en": "https://leetcode.com/problems/check-if-binary-string-has-at-most-one-segment-of-ones", "relative_path_cn": "/solution/1700-1799/1784.Check%20if%20Binary%20String%20Has%20at%20Most%20One%20Segment%20of%20Ones/README.md", "relative_path_en": "/solution/1700-1799/1784.Check%20if%20Binary%20String%20Has%20at%20Most%20One%20Segment%20of%20Ones/README_EN.md", "title_cn": "\u68c0\u67e5\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32\u5b57\u6bb5", "title_en": "Check if Binary String Has at Most One Segment of Ones", "question_title_slug": "check-if-binary-string-has-at-most-one-segment-of-ones", "content_en": "

    Given a binary string s \u200b\u200b\u200b\u200b\u200bwithout leading zeros, return true\u200b\u200b\u200b if s contains at most one contiguous segment of ones. Otherwise, return false.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "1001"\nOutput: false\nExplanation: The ones do not form a contiguous segment.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "110"\nOutput: true
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 100
    • \n\t
    • s[i]\u200b\u200b\u200b\u200b is either '0' or '1'.
    • \n\t
    • s[0] is '1'.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32 s \uff0c\u8be5\u5b57\u7b26\u4e32 \u4e0d\u542b\u524d\u5bfc\u96f6 \u3002

    \n\n

    \u5982\u679c s \u6700\u591a\u5305\u542b \u4e00\u4e2a\u7531\u8fde\u7eed\u7684 '1' \u7ec4\u6210\u7684\u5b57\u6bb5 \uff0c\u8fd4\u56de true\u200b\u200b\u200b \u3002\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"1001\"\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u5b57\u7b26\u4e32\u4e2d\u7684 1 \u6ca1\u6709\u5f62\u6210\u4e00\u4e2a\u8fde\u7eed\u5b57\u6bb5\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"110\"\n\u8f93\u51fa\uff1atrue
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 100
    • \n\t
    • s[i]\u200b\u200b\u200b\u200b \u4e3a '0' \u6216 '1'
    • \n\t
    • s[0] \u4e3a '1'
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool checkOnesSegment(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean checkOnesSegment(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def checkOnesSegment(self, s):\n \"\"\"\n :type s: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def checkOnesSegment(self, s: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool checkOnesSegment(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CheckOnesSegment(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {boolean}\n */\nvar checkOnesSegment = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Boolean}\ndef check_ones_segment(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func checkOnesSegment(_ s: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func checkOnesSegment(s string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def checkOnesSegment(s: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun checkOnesSegment(s: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn check_ones_segment(s: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Boolean\n */\n function checkOnesSegment($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function checkOnesSegment(s: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (check-ones-segment s)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1784](https://leetcode-cn.com/problems/check-if-binary-string-has-at-most-one-segment-of-ones)", "[\u68c0\u67e5\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32\u5b57\u6bb5](/solution/1700-1799/1784.Check%20if%20Binary%20String%20Has%20at%20Most%20One%20Segment%20of%20Ones/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u7b80\u5355", ""], "md_table_row_en": ["[1784](https://leetcode.com/problems/check-if-binary-string-has-at-most-one-segment-of-ones)", "[Check if Binary String Has at Most One Segment of Ones](/solution/1700-1799/1784.Check%20if%20Binary%20String%20Has%20at%20Most%20One%20Segment%20of%20Ones/README_EN.md)", "`Greedy`", "Easy", ""]}, {"question_id": "1909", "frontend_question_id": "1762", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/buildings-with-an-ocean-view", "url_en": "https://leetcode.com/problems/buildings-with-an-ocean-view", "relative_path_cn": "/solution/1700-1799/1762.Buildings%20With%20an%20Ocean%20View/README.md", "relative_path_en": "/solution/1700-1799/1762.Buildings%20With%20an%20Ocean%20View/README_EN.md", "title_cn": "\u80fd\u770b\u5230\u6d77\u666f\u7684\u5efa\u7b51\u7269", "title_en": "Buildings With an Ocean View", "question_title_slug": "buildings-with-an-ocean-view", "content_en": "

    There are n buildings in a line. You are given an integer array heights of size n that represents the heights of the buildings in the line.

    \r\n\r\n

    The ocean is to the right of the buildings. A building has an ocean view if the building can see the ocean without obstructions. Formally, a building has an ocean view if all the buildings to its right have a smaller height.

    \r\n\r\n

    Return a list of indices (0-indexed) of buildings that have an ocean view, sorted in increasing order.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: heights = [4,2,3,1]\r\nOutput: [0,2,3]\r\nExplanation: Building 1 (0-indexed) does not have an ocean view because building 2 is taller.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: heights = [4,3,2,1]\r\nOutput: [0,1,2,3]\r\nExplanation: All the buildings have an ocean view.
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: heights = [1,3,2,4]\r\nOutput: [3]\r\nExplanation: Only building 3 has an ocean view.
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: heights = [2,2,2,2]\r\nOutput: [3]\r\nExplanation: Buildings cannot see the ocean if there are buildings of the same height to its right.
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= heights.length <= 105
    • \r\n\t
    • 1 <= heights[i] <= 109
    • \r\n
    ", "content_cn": "

    \u6709 n \u5ea7\u5efa\u7b51\u7269\u3002\u7ed9\u4f60\u4e00\u4e2a\u5927\u5c0f\u4e3a n \u7684\u6574\u6570\u6570\u7ec4 heights \u8868\u793a\u6bcf\u4e00\u4e2a\u5efa\u7b51\u7269\u7684\u9ad8\u5ea6\u3002

    \n\n

    \u5efa\u7b51\u7269\u7684\u53f3\u8fb9\u662f\u6d77\u6d0b\u3002\u5982\u679c\u5efa\u7b51\u7269\u53ef\u4ee5\u65e0\u969c\u788d\u5730\u770b\u5230\u6d77\u6d0b\uff0c\u5219\u5efa\u7b51\u7269\u80fd\u770b\u5230\u6d77\u666f\u3002\u786e\u5207\u5730\u8bf4\uff0c\u5982\u679c\u4e00\u5ea7\u5efa\u7b51\u7269\u53f3\u8fb9\u7684\u6240\u6709\u5efa\u7b51\u90fd\u6bd4\u5b83 \u77ee \u65f6\uff0c\u5c31\u8ba4\u4e3a\u5b83\u80fd\u770b\u5230\u6d77\u666f\u3002

    \n\n

    \u8fd4\u56de\u80fd\u770b\u5230\u6d77\u666f\u5efa\u7b51\u7269\u7684\u4e0b\u6807\u5217\u8868\uff08\u4e0b\u6807 \u4ece 0 \u5f00\u59cb \uff09\uff0c\u5e76\u6309\u5347\u5e8f\u6392\u5217\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aheights = [4,2,3,1]\n\u8f93\u51fa\uff1a[0,2,3]\n\u89e3\u91ca\uff1a1 \u53f7\u5efa\u7b51\u7269\u770b\u4e0d\u5230\u6d77\u666f\uff0c\u56e0\u4e3a 2 \u53f7\u5efa\u7b51\u7269\u6bd4\u5b83\u9ad8\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aheights = [4,3,2,1]\n\u8f93\u51fa\uff1a[0,1,2,3]\n\u89e3\u91ca\uff1a\u6240\u6709\u7684\u5efa\u7b51\u7269\u90fd\u80fd\u770b\u5230\u6d77\u666f\u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aheights = [1,3,2,4]\n\u8f93\u51fa\uff1a[3]\n\u89e3\u91ca\uff1a\u53ea\u6709 3 \u53f7\u5efa\u7b51\u7269\u80fd\u770b\u5230\u6d77\u666f\u3002
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1aheights = [2,2,2,2]\n\u8f93\u51fa\uff1a[3]\n\u89e3\u91ca\uff1a\u5982\u679c\u5efa\u7b51\u7269\u53f3\u8fb9\u6709\u76f8\u540c\u9ad8\u5ea6\u7684\u5efa\u7b51\u7269\u5219\u65e0\u6cd5\u770b\u5230\u6d77\u666f\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= heights.length <= 105
    • \n\t
    • 1 <= heights[i] <= 109
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findBuildings(vector& heights) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] findBuildings(int[] heights) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findBuildings(self, heights):\n \"\"\"\n :type heights: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findBuildings(self, heights: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* findBuildings(int* heights, int heightsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] FindBuildings(int[] heights) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} heights\n * @return {number[]}\n */\nvar findBuildings = function(heights) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} heights\n# @return {Integer[]}\ndef find_buildings(heights)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findBuildings(_ heights: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findBuildings(heights []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findBuildings(heights: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findBuildings(heights: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_buildings(heights: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $heights\n * @return Integer[]\n */\n function findBuildings($heights) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findBuildings(heights: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-buildings heights)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1762](https://leetcode-cn.com/problems/buildings-with-an-ocean-view)", "[\u80fd\u770b\u5230\u6d77\u666f\u7684\u5efa\u7b51\u7269](/solution/1700-1799/1762.Buildings%20With%20an%20Ocean%20View/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1762](https://leetcode.com/problems/buildings-with-an-ocean-view)", "[Buildings With an Ocean View](/solution/1700-1799/1762.Buildings%20With%20an%20Ocean%20View/README_EN.md)", "`Greedy`", "Medium", "\ud83d\udd12"]}, {"question_id": "1908", "frontend_question_id": "1757", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/recyclable-and-low-fat-products", "url_en": "https://leetcode.com/problems/recyclable-and-low-fat-products", "relative_path_cn": "/solution/1700-1799/1757.Recyclable%20and%20Low%20Fat%20Products/README.md", "relative_path_en": "/solution/1700-1799/1757.Recyclable%20and%20Low%20Fat%20Products/README_EN.md", "title_cn": "\u53ef\u56de\u6536\u4e14\u4f4e\u8102\u7684\u4ea7\u54c1", "title_en": "Recyclable and Low Fat Products", "question_title_slug": "recyclable-and-low-fat-products", "content_en": "

    Table: Products

    \n\n
    \n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| product_id  | int     |\n| low_fats    | enum    |\n| recyclable  | enum    |\n+-------------+---------+\nproduct_id is the primary key for this table.\nlow_fats is an ENUM of type ('Y', 'N') where 'Y' means this product is low fat and 'N' means it is not.\nrecyclable is an ENUM of types ('Y', 'N') where 'Y' means this product is recyclable and 'N' means it is not.
    \n\n

     

    \n\n

    Write an SQL query to find the ids of products that are both low fat and recyclable.

    \n\n

    Return the result table in any order.

    \n\n

    The query result format is in the following example:

    \n\n

     

    \n\n
    \nProducts table:\n+-------------+----------+------------+\n| product_id  | low_fats | recyclable |\n+-------------+----------+------------+\n| 0           | Y        | N          |\n| 1           | Y        | Y          |\n| 2           | N        | Y          |\n| 3           | Y        | Y          |\n| 4           | N        | N          |\n+-------------+----------+------------+\nResult table:\n+-------------+\n| product_id  |\n+-------------+\n| 1           |\n| 3           |\n+-------------+\nOnly products 1 and 3 are both low fat and recyclable.\n
    \n", "content_cn": "

    \u8868\uff1aProducts

    \n\n
    \n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| product_id  | int     |\n| low_fats    | enum    |\n| recyclable  | enum    |\n+-------------+---------+\nproduct_id \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\u3002\nlow_fats \u662f\u679a\u4e3e\u7c7b\u578b\uff0c\u53d6\u503c\u4e3a\u4ee5\u4e0b\u4e24\u79cd ('Y', 'N')\uff0c\u5176\u4e2d 'Y' \u8868\u793a\u8be5\u4ea7\u54c1\u662f\u4f4e\u8102\u4ea7\u54c1\uff0c'N' \u8868\u793a\u4e0d\u662f\u4f4e\u8102\u4ea7\u54c1\u3002\nrecyclable \u662f\u679a\u4e3e\u7c7b\u578b\uff0c\u53d6\u503c\u4e3a\u4ee5\u4e0b\u4e24\u79cd ('Y', 'N')\uff0c\u5176\u4e2d 'Y' \u8868\u793a\u8be5\u4ea7\u54c1\u53ef\u56de\u6536\uff0c\u800c 'N' \u8868\u793a\u4e0d\u53ef\u56de\u6536\u3002
    \n\n

    \u00a0

    \n\n

    \u5199\u51fa SQL \u8bed\u53e5\uff0c\u67e5\u627e\u65e2\u662f\u4f4e\u8102\u53c8\u662f\u53ef\u56de\u6536\u7684\u4ea7\u54c1\u7f16\u53f7\u3002

    \n\n

    \u8fd4\u56de\u7ed3\u679c \u65e0\u987a\u5e8f\u8981\u6c42 \u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a\uff1a

    \n\n
    \nProducts \u8868\uff1a\n+-------------+----------+------------+\n| product_id  | low_fats | recyclable |\n+-------------+----------+------------+\n| 0           | Y        | N          |\n| 1           | Y        | Y          |\n| 2           | N        | Y          |\n| 3           | Y        | Y          |\n| 4           | N        | N          |\n+-------------+----------+------------+\nResult \u8868\uff1a\n+-------------+\n| product_id  |\n+-------------+\n| 1           |\n| 3           |\n+-------------+\n\u53ea\u6709\u4ea7\u54c1 id \u4e3a 1 \u548c 3 \u7684\u4ea7\u54c1\uff0c\u65e2\u662f\u4f4e\u8102\u53c8\u662f\u53ef\u56de\u6536\u7684\u4ea7\u54c1\u3002\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1757](https://leetcode-cn.com/problems/recyclable-and-low-fat-products)", "[\u53ef\u56de\u6536\u4e14\u4f4e\u8102\u7684\u4ea7\u54c1](/solution/1700-1799/1757.Recyclable%20and%20Low%20Fat%20Products/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1757](https://leetcode.com/problems/recyclable-and-low-fat-products)", "[Recyclable and Low Fat Products](/solution/1700-1799/1757.Recyclable%20and%20Low%20Fat%20Products/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1907", "frontend_question_id": "1803", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-pairs-with-xor-in-a-range", "url_en": "https://leetcode.com/problems/count-pairs-with-xor-in-a-range", "relative_path_cn": "/solution/1800-1899/1803.Count%20Pairs%20With%20XOR%20in%20a%20Range/README.md", "relative_path_en": "/solution/1800-1899/1803.Count%20Pairs%20With%20XOR%20in%20a%20Range/README_EN.md", "title_cn": "\u7edf\u8ba1\u5f02\u6216\u503c\u5728\u8303\u56f4\u5185\u7684\u6570\u5bf9\u6709\u591a\u5c11", "title_en": "Count Pairs With XOR in a Range", "question_title_slug": "count-pairs-with-xor-in-a-range", "content_en": "

    Given a (0-indexed) integer array nums and two integers low and high, return the number of nice pairs.

    \r\n\r\n

    A nice pair is a pair (i, j) where 0 <= i < j < nums.length and low <= (nums[i] XOR nums[j]) <= high.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: nums = [1,4,2,7], low = 2, high = 6\r\nOutput: 6\r\nExplanation: All nice pairs (i, j) are as follows:\r\n    - (0, 1): nums[0] XOR nums[1] = 5 \r\n    - (0, 2): nums[0] XOR nums[2] = 3\r\n    - (0, 3): nums[0] XOR nums[3] = 6\r\n    - (1, 2): nums[1] XOR nums[2] = 6\r\n    - (1, 3): nums[1] XOR nums[3] = 3\r\n    - (2, 3): nums[2] XOR nums[3] = 5\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: nums = [9,8,4,2,1], low = 5, high = 14\r\nOutput: 8\r\nExplanation: All nice pairs (i, j) are as follows:\r\n\u200b\u200b\u200b\u200b\u200b    - (0, 2): nums[0] XOR nums[2] = 13\r\n    - (0, 3): nums[0] XOR nums[3] = 11\r\n    - (0, 4): nums[0] XOR nums[4] = 8\r\n    - (1, 2): nums[1] XOR nums[2] = 12\r\n    - (1, 3): nums[1] XOR nums[3] = 10\r\n    - (1, 4): nums[1] XOR nums[4] = 9\r\n    - (2, 3): nums[2] XOR nums[3] = 6\r\n    - (2, 4): nums[2] XOR nums[4] = 5
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= nums.length <= 2 * 104
    • \r\n\t
    • 1 <= nums[i] <= 2 * 104
    • \r\n\t
    • 1 <= low <= high <= 2 * 104
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \uff08\u4e0b\u6807 \u4ece 0 \u5f00\u59cb \u8ba1\u6570\uff09\u4ee5\u53ca\u4e24\u4e2a\u6574\u6570\uff1alow \u548c high \uff0c\u8bf7\u8fd4\u56de \u6f02\u4eae\u6570\u5bf9 \u7684\u6570\u76ee\u3002

    \n\n

    \u6f02\u4eae\u6570\u5bf9 \u662f\u4e00\u4e2a\u5f62\u5982 (i, j) \u7684\u6570\u5bf9\uff0c\u5176\u4e2d 0 <= i < j < nums.length \u4e14 low <= (nums[i] XOR nums[j]) <= high \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,4,2,7], low = 2, high = 6\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u6240\u6709\u6f02\u4eae\u6570\u5bf9 (i, j) \u5217\u51fa\u5982\u4e0b\uff1a\n    - (0, 1): nums[0] XOR nums[1] = 5 \n    - (0, 2): nums[0] XOR nums[2] = 3\n    - (0, 3): nums[0] XOR nums[3] = 6\n    - (1, 2): nums[1] XOR nums[2] = 6\n    - (1, 3): nums[1] XOR nums[3] = 3\n    - (2, 3): nums[2] XOR nums[3] = 5\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [9,8,4,2,1], low = 5, high = 14\n\u8f93\u51fa\uff1a8\n\u89e3\u91ca\uff1a\u6240\u6709\u6f02\u4eae\u6570\u5bf9 (i, j) \u5217\u51fa\u5982\u4e0b\uff1a\n\u200b\u200b\u200b\u200b\u200b    - (0, 2): nums[0] XOR nums[2] = 13\n\u00a0   - (0, 3): nums[0] XOR nums[3] = 11\n\u00a0   - (0, 4): nums[0] XOR nums[4] = 8\n\u00a0   - (1, 2): nums[1] XOR nums[2] = 12\n\u00a0   - (1, 3): nums[1] XOR nums[3] = 10\n\u00a0   - (1, 4): nums[1] XOR nums[4] = 9\n\u00a0   - (2, 3): nums[2] XOR nums[3] = 6\n\u00a0   - (2, 4): nums[2] XOR nums[4] = 5
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 2 * 104
    • \n\t
    • 1 <= nums[i] <= 2 * 104
    • \n\t
    • 1 <= low <= high <= 2 * 104
    • \n
    \n", "tags_en": ["Trie"], "tags_cn": ["\u5b57\u5178\u6811"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countPairs(vector& nums, int low, int high) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countPairs(int[] nums, int low, int high) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countPairs(self, nums, low, high):\n \"\"\"\n :type nums: List[int]\n :type low: int\n :type high: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countPairs(self, nums: List[int], low: int, high: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countPairs(int* nums, int numsSize, int low, int high){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountPairs(int[] nums, int low, int high) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} low\n * @param {number} high\n * @return {number}\n */\nvar countPairs = function(nums, low, high) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} low\n# @param {Integer} high\n# @return {Integer}\ndef count_pairs(nums, low, high)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countPairs(_ nums: [Int], _ low: Int, _ high: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countPairs(nums []int, low int, high int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countPairs(nums: Array[Int], low: Int, high: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countPairs(nums: IntArray, low: Int, high: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_pairs(nums: Vec, low: i32, high: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $low\n * @param Integer $high\n * @return Integer\n */\n function countPairs($nums, $low, $high) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countPairs(nums: number[], low: number, high: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-pairs nums low high)\n (-> (listof exact-integer?) exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1803](https://leetcode-cn.com/problems/count-pairs-with-xor-in-a-range)", "[\u7edf\u8ba1\u5f02\u6216\u503c\u5728\u8303\u56f4\u5185\u7684\u6570\u5bf9\u6709\u591a\u5c11](/solution/1800-1899/1803.Count%20Pairs%20With%20XOR%20in%20a%20Range/README.md)", "`\u5b57\u5178\u6811`", "\u56f0\u96be", ""], "md_table_row_en": ["[1803](https://leetcode.com/problems/count-pairs-with-xor-in-a-range)", "[Count Pairs With XOR in a Range](/solution/1800-1899/1803.Count%20Pairs%20With%20XOR%20in%20a%20Range/README_EN.md)", "`Trie`", "Hard", ""]}, {"question_id": "1906", "frontend_question_id": "1799", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximize-score-after-n-operations", "url_en": "https://leetcode.com/problems/maximize-score-after-n-operations", "relative_path_cn": "/solution/1700-1799/1799.Maximize%20Score%20After%20N%20Operations/README.md", "relative_path_en": "/solution/1700-1799/1799.Maximize%20Score%20After%20N%20Operations/README_EN.md", "title_cn": "N \u6b21\u64cd\u4f5c\u540e\u7684\u6700\u5927\u5206\u6570\u548c", "title_en": "Maximize Score After N Operations", "question_title_slug": "maximize-score-after-n-operations", "content_en": "

    You are given nums, an array of positive integers of size 2 * n. You must perform n operations on this array.

    \n\n

    In the ith operation (1-indexed), you will:

    \n\n
      \n\t
    • Choose two elements, x and y.
    • \n\t
    • Receive a score of i * gcd(x, y).
    • \n\t
    • Remove x and y from nums.
    • \n
    \n\n

    Return the maximum score you can receive after performing n operations.

    \n\n

    The function gcd(x, y) is the greatest common divisor of x and y.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2]\nOutput: 1\nExplanation: The optimal choice of operations is:\n(1 * gcd(1, 2)) = 1\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [3,4,6,8]\nOutput: 11\nExplanation: The optimal choice of operations is:\n(1 * gcd(3, 6)) + (2 * gcd(4, 8)) = 3 + 8 = 11\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [1,2,3,4,5,6]\nOutput: 14\nExplanation: The optimal choice of operations is:\n(1 * gcd(1, 5)) + (2 * gcd(2, 4)) + (3 * gcd(3, 6)) = 1 + 4 + 9 = 14\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 7
    • \n\t
    • nums.length == 2 * n
    • \n\t
    • 1 <= nums[i] <= 106
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u00a0nums\u00a0\uff0c\u5b83\u662f\u4e00\u4e2a\u5927\u5c0f\u4e3a\u00a02 * n\u00a0\u7684\u6b63\u6574\u6570\u6570\u7ec4\u3002\u4f60\u5fc5\u987b\u5bf9\u8fd9\u4e2a\u6570\u7ec4\u6267\u884c n\u00a0\u6b21\u64cd\u4f5c\u3002

    \n\n

    \u5728\u7b2c\u00a0i\u00a0\u6b21\u64cd\u4f5c\u65f6\uff08\u64cd\u4f5c\u7f16\u53f7\u4ece 1\u00a0\u5f00\u59cb\uff09\uff0c\u4f60\u9700\u8981\uff1a

    \n\n
      \n\t
    • \u9009\u62e9\u4e24\u4e2a\u5143\u7d20\u00a0x \u548c\u00a0y\u00a0\u3002
    • \n\t
    • \u83b7\u5f97\u5206\u6570\u00a0i * gcd(x, y)\u00a0\u3002
    • \n\t
    • \u5c06\u00a0x\u00a0\u548c\u00a0y \u4ece\u00a0nums\u00a0\u4e2d\u5220\u9664\u3002
    • \n
    \n\n

    \u8bf7\u4f60\u8fd4\u56de n\u00a0\u6b21\u64cd\u4f5c\u540e\u4f60\u80fd\u83b7\u5f97\u7684\u5206\u6570\u548c\u6700\u5927\u4e3a\u591a\u5c11\u3002

    \n\n

    \u51fd\u6570\u00a0gcd(x, y)\u00a0\u662f\u00a0x \u548c\u00a0y\u00a0\u7684\u6700\u5927\u516c\u7ea6\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,2]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u6700\u4f18\u64cd\u4f5c\u662f\uff1a\n(1 * gcd(1, 2)) = 1\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [3,4,6,8]\n\u8f93\u51fa\uff1a11\n\u89e3\u91ca\uff1a\u6700\u4f18\u64cd\u4f5c\u662f\uff1a\n(1 * gcd(3, 6)) + (2 * gcd(4, 8)) = 3 + 8 = 11\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,2,3,4,5,6]\n\u8f93\u51fa\uff1a14\n\u89e3\u91ca\uff1a\u6700\u4f18\u64cd\u4f5c\u662f\uff1a\n(1 * gcd(1, 5)) + (2 * gcd(2, 4)) + (3 * gcd(3, 6)) = 1 + 4 + 9 = 14\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 7
    • \n\t
    • nums.length == 2 * n
    • \n\t
    • 1 <= nums[i] <= 106
    • \n
    \n", "tags_en": ["Recursion", "Dynamic Programming", "Backtracking"], "tags_cn": ["\u9012\u5f52", "\u52a8\u6001\u89c4\u5212", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxScore(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxScore(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxScore(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxScore(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxScore(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxScore(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar maxScore = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef max_score(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxScore(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxScore(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxScore(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxScore(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_score(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function maxScore($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxScore(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-score nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1799](https://leetcode-cn.com/problems/maximize-score-after-n-operations)", "[N \u6b21\u64cd\u4f5c\u540e\u7684\u6700\u5927\u5206\u6570\u548c](/solution/1700-1799/1799.Maximize%20Score%20After%20N%20Operations/README.md)", "`\u9012\u5f52`,`\u52a8\u6001\u89c4\u5212`,`\u56de\u6eaf\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[1799](https://leetcode.com/problems/maximize-score-after-n-operations)", "[Maximize Score After N Operations](/solution/1700-1799/1799.Maximize%20Score%20After%20N%20Operations/README_EN.md)", "`Recursion`,`Dynamic Programming`,`Backtracking`", "Hard", ""]}, {"question_id": "1905", "frontend_question_id": "1797", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/design-authentication-manager", "url_en": "https://leetcode.com/problems/design-authentication-manager", "relative_path_cn": "/solution/1700-1799/1797.Design%20Authentication%20Manager/README.md", "relative_path_en": "/solution/1700-1799/1797.Design%20Authentication%20Manager/README_EN.md", "title_cn": "\u8bbe\u8ba1\u4e00\u4e2a\u9a8c\u8bc1\u7cfb\u7edf", "title_en": "Design Authentication Manager", "question_title_slug": "design-authentication-manager", "content_en": "

    There is an authentication system that works with authentication tokens. For each session, the user will receive a new authentication token that will expire timeToLive seconds after the currentTime. If the token is renewed, the expiry time will be extended to expire timeToLive seconds after the (potentially different) currentTime.

    \n\n

    Implement the AuthenticationManager class:

    \n\n
      \n\t
    • AuthenticationManager(int timeToLive) constructs the AuthenticationManager and sets the timeToLive.
    • \n\t
    • generate(string tokenId, int currentTime) generates a new token with the given tokenId at the given currentTime in seconds.
    • \n\t
    • renew(string tokenId, int currentTime) renews the unexpired token with the given tokenId at the given currentTime in seconds. If there are no unexpired tokens with the given tokenId, the request is ignored, and nothing happens.
    • \n\t
    • countUnexpiredTokens(int currentTime) returns the number of unexpired tokens at the given currentTime.
    • \n
    \n\n

    Note that if a token expires at time t, and another action happens on time t (renew or countUnexpiredTokens), the expiration takes place before the other actions.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput\n["AuthenticationManager", "renew", "generate", "countUnexpiredTokens", "generate", "renew", "renew", "countUnexpiredTokens"]\n[[5], ["aaa", 1], ["aaa", 2], [6], ["bbb", 7], ["aaa", 8], ["bbb", 10], [15]]\nOutput\n[null, null, null, 1, null, null, null, 0]\n\nExplanation\nAuthenticationManager authenticationManager = new AuthenticationManager(5); // Constructs the AuthenticationManager with timeToLive = 5 seconds.\nauthenticationManager.renew("aaa", 1); // No token exists with tokenId "aaa" at time 1, so nothing happens.\nauthenticationManager.generate("aaa", 2); // Generates a new token with tokenId "aaa" at time 2.\nauthenticationManager.countUnexpiredTokens(6); // The token with tokenId "aaa" is the only unexpired one at time 6, so return 1.\nauthenticationManager.generate("bbb", 7); // Generates a new token with tokenId "bbb" at time 7.\nauthenticationManager.renew("aaa", 8); // The token with tokenId "aaa" expired at time 7, and 8 >= 7, so at time 8 the renew request is ignored, and nothing happens.\nauthenticationManager.renew("bbb", 10); // The token with tokenId "bbb" is unexpired at time 10, so the renew request is fulfilled and now the token will expire at time 15.\nauthenticationManager.countUnexpiredTokens(15); // The token with tokenId "bbb" expires at time 15, and the token with tokenId "aaa" expired at time 7, so currently no token is unexpired, so return 0.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= timeToLive <= 108
    • \n\t
    • 1 <= currentTime <= 108
    • \n\t
    • 1 <= tokenId.length <= 5
    • \n\t
    • tokenId consists only of lowercase letters.
    • \n\t
    • All calls to generate will contain unique values of tokenId.
    • \n\t
    • The values of currentTime across all the function calls will be strictly increasing.
    • \n\t
    • At most 2000 calls will be made to all functions combined.
    • \n
    \n", "content_cn": "

    \u4f60\u9700\u8981\u8bbe\u8ba1\u4e00\u4e2a\u5305\u542b\u9a8c\u8bc1\u7801\u7684\u9a8c\u8bc1\u7cfb\u7edf\u3002\u6bcf\u4e00\u6b21\u9a8c\u8bc1\u4e2d\uff0c\u7528\u6237\u4f1a\u6536\u5230\u4e00\u4e2a\u65b0\u7684\u9a8c\u8bc1\u7801\uff0c\u8fd9\u4e2a\u9a8c\u8bc1\u7801\u5728 currentTime\u00a0\u65f6\u523b\u4e4b\u540e timeToLive\u00a0\u79d2\u8fc7\u671f\u3002\u5982\u679c\u9a8c\u8bc1\u7801\u88ab\u66f4\u65b0\u4e86\uff0c\u90a3\u4e48\u5b83\u4f1a\u5728 currentTime\u00a0\uff08\u53ef\u80fd\u4e0e\u4e4b\u524d\u7684 currentTime\u00a0\u4e0d\u540c\uff09\u65f6\u523b\u5ef6\u957f\u00a0timeToLive\u00a0\u79d2\u3002

    \n\n

    \u8bf7\u4f60\u5b9e\u73b0\u00a0AuthenticationManager\u00a0\u7c7b\uff1a

    \n\n
      \n\t
    • AuthenticationManager(int timeToLive)\u00a0\u6784\u9020\u00a0AuthenticationManager\u00a0\u5e76\u8bbe\u7f6e\u00a0timeToLive\u00a0\u53c2\u6570\u3002
    • \n\t
    • generate(string tokenId, int currentTime)\u00a0\u7ed9\u5b9a tokenId\u00a0\uff0c\u5728\u5f53\u524d\u65f6\u95f4\u00a0currentTime \u751f\u6210\u4e00\u4e2a\u65b0\u7684\u9a8c\u8bc1\u7801\u3002
    • \n\t
    • renew(string tokenId, int currentTime)\u00a0\u5c06\u7ed9\u5b9a tokenId\u00a0\u4e14 \u672a\u8fc7\u671f\u00a0\u7684\u9a8c\u8bc1\u7801\u5728 currentTime\u00a0\u65f6\u523b\u66f4\u65b0\u3002\u5982\u679c\u7ed9\u5b9a\u00a0tokenId\u00a0\u5bf9\u5e94\u7684\u9a8c\u8bc1\u7801\u4e0d\u5b58\u5728\u6216\u5df2\u8fc7\u671f\uff0c\u8bf7\u4f60\u5ffd\u7565\u8be5\u64cd\u4f5c\uff0c\u4e0d\u4f1a\u6709\u4efb\u4f55\u66f4\u65b0\u64cd\u4f5c\u53d1\u751f\u3002
    • \n\t
    • countUnexpiredTokens(int currentTime)\u00a0\u8bf7\u8fd4\u56de\u5728\u7ed9\u5b9a\u00a0currentTime\u00a0\u65f6\u523b\uff0c\u672a\u8fc7\u671f\u00a0\u7684\u9a8c\u8bc1\u7801\u6570\u76ee\u3002
    • \n
    \n\n

    \u5982\u679c\u4e00\u4e2a\u9a8c\u8bc1\u7801\u5728\u65f6\u523b\u00a0t\u00a0\u8fc7\u671f\uff0c\u4e14\u53e6\u4e00\u4e2a\u64cd\u4f5c\u6070\u597d\u5728\u65f6\u523b\u00a0t\u00a0\u53d1\u751f\uff08renew\u00a0\u6216\u8005\u00a0countUnexpiredTokens\u00a0\u64cd\u4f5c\uff09\uff0c\u8fc7\u671f\u4e8b\u4ef6\u00a0\u4f18\u5148\u4e8e\u00a0\u5176\u4ed6\u64cd\u4f5c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1a\n[\"AuthenticationManager\", \"renew\", \"generate\", \"countUnexpiredTokens\", \"generate\", \"renew\", \"renew\", \"countUnexpiredTokens\"]\n[[5], [\"aaa\", 1], [\"aaa\", 2], [6], [\"bbb\", 7], [\"aaa\", 8], [\"bbb\", 10], [15]]\n\u8f93\u51fa\uff1a\n[null, null, null, 1, null, null, null, 0]\n\n\u89e3\u91ca\uff1a\nAuthenticationManager authenticationManager = new AuthenticationManager(5); // \u6784\u9020 AuthenticationManager \uff0c\u8bbe\u7f6e timeToLive = 5 \u79d2\u3002\nauthenticationManager.renew(\"aaa\", 1); // \u65f6\u523b 1 \u65f6\uff0c\u6ca1\u6709\u9a8c\u8bc1\u7801\u7684 tokenId \u4e3a \"aaa\" \uff0c\u6ca1\u6709\u9a8c\u8bc1\u7801\u88ab\u66f4\u65b0\u3002\nauthenticationManager.generate(\"aaa\", 2); // \u65f6\u523b 2 \u65f6\uff0c\u751f\u6210\u4e00\u4e2a tokenId \u4e3a \"aaa\" \u7684\u65b0\u9a8c\u8bc1\u7801\u3002\nauthenticationManager.countUnexpiredTokens(6); // \u65f6\u523b 6 \u65f6\uff0c\u53ea\u6709 tokenId \u4e3a \"aaa\" \u7684\u9a8c\u8bc1\u7801\u672a\u8fc7\u671f\uff0c\u6240\u4ee5\u8fd4\u56de 1 \u3002\nauthenticationManager.generate(\"bbb\", 7); // \u65f6\u523b 7 \u65f6\uff0c\u751f\u6210\u4e00\u4e2a tokenId \u4e3a \"bbb\" \u7684\u65b0\u9a8c\u8bc1\u7801\u3002\nauthenticationManager.renew(\"aaa\", 8); // tokenId \u4e3a \"aaa\" \u7684\u9a8c\u8bc1\u7801\u5728\u65f6\u523b 7 \u8fc7\u671f\uff0c\u4e14 8 >= 7 \uff0c\u6240\u4ee5\u65f6\u523b 8 \u7684renew \u64cd\u4f5c\u88ab\u5ffd\u7565\uff0c\u6ca1\u6709\u9a8c\u8bc1\u7801\u88ab\u66f4\u65b0\u3002\nauthenticationManager.renew(\"bbb\", 10); // tokenId \u4e3a \"bbb\" \u7684\u9a8c\u8bc1\u7801\u5728\u65f6\u523b 10 \u6ca1\u6709\u8fc7\u671f\uff0c\u6240\u4ee5 renew \u64cd\u4f5c\u4f1a\u6267\u884c\uff0c\u8be5 token \u5c06\u5728\u65f6\u523b 15 \u8fc7\u671f\u3002\nauthenticationManager.countUnexpiredTokens(15); // tokenId \u4e3a \"bbb\" \u7684\u9a8c\u8bc1\u7801\u5728\u65f6\u523b 15 \u8fc7\u671f\uff0ctokenId \u4e3a \"aaa\" \u7684\u9a8c\u8bc1\u7801\u5728\u65f6\u523b 7 \u8fc7\u671f\uff0c\u6240\u6709\u9a8c\u8bc1\u7801\u5747\u5df2\u8fc7\u671f\uff0c\u6240\u4ee5\u8fd4\u56de 0 \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= timeToLive <= 108
    • \n\t
    • 1 <= currentTime <= 108
    • \n\t
    • 1 <= tokenId.length <= 5
    • \n\t
    • tokenId\u00a0\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    • \n\t
    • \u6240\u6709\u00a0generate\u00a0\u51fd\u6570\u7684\u8c03\u7528\u90fd\u4f1a\u5305\u542b\u72ec\u4e00\u65e0\u4e8c\u7684\u00a0tokenId\u00a0\u503c\u3002
    • \n\t
    • \u6240\u6709\u51fd\u6570\u8c03\u7528\u4e2d\uff0ccurrentTime\u00a0\u7684\u503c \u4e25\u683c\u9012\u589e\u00a0\u3002
    • \n\t
    • \u6240\u6709\u51fd\u6570\u7684\u8c03\u7528\u6b21\u6570\u603b\u5171\u4e0d\u8d85\u8fc7\u00a02000\u00a0\u6b21\u3002
    • \n
    \n", "tags_en": ["Design", "Hash Table"], "tags_cn": ["\u8bbe\u8ba1", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class AuthenticationManager {\npublic:\n AuthenticationManager(int timeToLive) {\n\n }\n \n void generate(string tokenId, int currentTime) {\n\n }\n \n void renew(string tokenId, int currentTime) {\n\n }\n \n int countUnexpiredTokens(int currentTime) {\n\n }\n};\n\n/**\n * Your AuthenticationManager object will be instantiated and called as such:\n * AuthenticationManager* obj = new AuthenticationManager(timeToLive);\n * obj->generate(tokenId,currentTime);\n * obj->renew(tokenId,currentTime);\n * int param_3 = obj->countUnexpiredTokens(currentTime);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class AuthenticationManager {\n\n public AuthenticationManager(int timeToLive) {\n\n }\n \n public void generate(String tokenId, int currentTime) {\n\n }\n \n public void renew(String tokenId, int currentTime) {\n\n }\n \n public int countUnexpiredTokens(int currentTime) {\n\n }\n}\n\n/**\n * Your AuthenticationManager object will be instantiated and called as such:\n * AuthenticationManager obj = new AuthenticationManager(timeToLive);\n * obj.generate(tokenId,currentTime);\n * obj.renew(tokenId,currentTime);\n * int param_3 = obj.countUnexpiredTokens(currentTime);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class AuthenticationManager(object):\n\n def __init__(self, timeToLive):\n \"\"\"\n :type timeToLive: int\n \"\"\"\n\n\n def generate(self, tokenId, currentTime):\n \"\"\"\n :type tokenId: str\n :type currentTime: int\n :rtype: None\n \"\"\"\n\n\n def renew(self, tokenId, currentTime):\n \"\"\"\n :type tokenId: str\n :type currentTime: int\n :rtype: None\n \"\"\"\n\n\n def countUnexpiredTokens(self, currentTime):\n \"\"\"\n :type currentTime: int\n :rtype: int\n \"\"\"\n\n\n\n# Your AuthenticationManager object will be instantiated and called as such:\n# obj = AuthenticationManager(timeToLive)\n# obj.generate(tokenId,currentTime)\n# obj.renew(tokenId,currentTime)\n# param_3 = obj.countUnexpiredTokens(currentTime)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class AuthenticationManager:\n\n def __init__(self, timeToLive: int):\n\n\n def generate(self, tokenId: str, currentTime: int) -> None:\n\n\n def renew(self, tokenId: str, currentTime: int) -> None:\n\n\n def countUnexpiredTokens(self, currentTime: int) -> int:\n\n\n\n# Your AuthenticationManager object will be instantiated and called as such:\n# obj = AuthenticationManager(timeToLive)\n# obj.generate(tokenId,currentTime)\n# obj.renew(tokenId,currentTime)\n# param_3 = obj.countUnexpiredTokens(currentTime)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} AuthenticationManager;\n\n\nAuthenticationManager* authenticationManagerCreate(int timeToLive) {\n \n}\n\nvoid authenticationManagerGenerate(AuthenticationManager* obj, char * tokenId, int currentTime) {\n \n}\n\nvoid authenticationManagerRenew(AuthenticationManager* obj, char * tokenId, int currentTime) {\n \n}\n\nint authenticationManagerCountUnexpiredTokens(AuthenticationManager* obj, int currentTime) {\n \n}\n\nvoid authenticationManagerFree(AuthenticationManager* obj) {\n \n}\n\n/**\n * Your AuthenticationManager struct will be instantiated and called as such:\n * AuthenticationManager* obj = authenticationManagerCreate(timeToLive);\n * authenticationManagerGenerate(obj, tokenId, currentTime);\n \n * authenticationManagerRenew(obj, tokenId, currentTime);\n \n * int param_3 = authenticationManagerCountUnexpiredTokens(obj, currentTime);\n \n * authenticationManagerFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class AuthenticationManager {\n\n public AuthenticationManager(int timeToLive) {\n\n }\n \n public void Generate(string tokenId, int currentTime) {\n\n }\n \n public void Renew(string tokenId, int currentTime) {\n\n }\n \n public int CountUnexpiredTokens(int currentTime) {\n\n }\n}\n\n/**\n * Your AuthenticationManager object will be instantiated and called as such:\n * AuthenticationManager obj = new AuthenticationManager(timeToLive);\n * obj.Generate(tokenId,currentTime);\n * obj.Renew(tokenId,currentTime);\n * int param_3 = obj.CountUnexpiredTokens(currentTime);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} timeToLive\n */\nvar AuthenticationManager = function(timeToLive) {\n\n};\n\n/** \n * @param {string} tokenId \n * @param {number} currentTime\n * @return {void}\n */\nAuthenticationManager.prototype.generate = function(tokenId, currentTime) {\n\n};\n\n/** \n * @param {string} tokenId \n * @param {number} currentTime\n * @return {void}\n */\nAuthenticationManager.prototype.renew = function(tokenId, currentTime) {\n\n};\n\n/** \n * @param {number} currentTime\n * @return {number}\n */\nAuthenticationManager.prototype.countUnexpiredTokens = function(currentTime) {\n\n};\n\n/**\n * Your AuthenticationManager object will be instantiated and called as such:\n * var obj = new AuthenticationManager(timeToLive)\n * obj.generate(tokenId,currentTime)\n * obj.renew(tokenId,currentTime)\n * var param_3 = obj.countUnexpiredTokens(currentTime)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class AuthenticationManager\n\n=begin\n :type time_to_live: Integer\n=end\n def initialize(time_to_live)\n\n end\n\n\n=begin\n :type token_id: String\n :type current_time: Integer\n :rtype: Void\n=end\n def generate(token_id, current_time)\n\n end\n\n\n=begin\n :type token_id: String\n :type current_time: Integer\n :rtype: Void\n=end\n def renew(token_id, current_time)\n\n end\n\n\n=begin\n :type current_time: Integer\n :rtype: Integer\n=end\n def count_unexpired_tokens(current_time)\n\n end\n\n\nend\n\n# Your AuthenticationManager object will be instantiated and called as such:\n# obj = AuthenticationManager.new(time_to_live)\n# obj.generate(token_id, current_time)\n# obj.renew(token_id, current_time)\n# param_3 = obj.count_unexpired_tokens(current_time)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass AuthenticationManager {\n\n init(_ timeToLive: Int) {\n\n }\n \n func generate(_ tokenId: String, _ currentTime: Int) {\n\n }\n \n func renew(_ tokenId: String, _ currentTime: Int) {\n\n }\n \n func countUnexpiredTokens(_ currentTime: Int) -> Int {\n\n }\n}\n\n/**\n * Your AuthenticationManager object will be instantiated and called as such:\n * let obj = AuthenticationManager(timeToLive)\n * obj.generate(tokenId, currentTime)\n * obj.renew(tokenId, currentTime)\n * let ret_3: Int = obj.countUnexpiredTokens(currentTime)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type AuthenticationManager struct {\n\n}\n\n\nfunc Constructor(timeToLive int) AuthenticationManager {\n\n}\n\n\nfunc (this *AuthenticationManager) Generate(tokenId string, currentTime int) {\n\n}\n\n\nfunc (this *AuthenticationManager) Renew(tokenId string, currentTime int) {\n\n}\n\n\nfunc (this *AuthenticationManager) CountUnexpiredTokens(currentTime int) int {\n\n}\n\n\n/**\n * Your AuthenticationManager object will be instantiated and called as such:\n * obj := Constructor(timeToLive);\n * obj.Generate(tokenId,currentTime);\n * obj.Renew(tokenId,currentTime);\n * param_3 := obj.CountUnexpiredTokens(currentTime);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class AuthenticationManager(_timeToLive: Int) {\n\n def generate(tokenId: String, currentTime: Int) {\n \n }\n\n def renew(tokenId: String, currentTime: Int) {\n \n }\n\n def countUnexpiredTokens(currentTime: Int): Int = {\n \n }\n\n}\n\n/**\n * Your AuthenticationManager object will be instantiated and called as such:\n * var obj = new AuthenticationManager(timeToLive)\n * obj.generate(tokenId,currentTime)\n * obj.renew(tokenId,currentTime)\n * var param_3 = obj.countUnexpiredTokens(currentTime)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class AuthenticationManager(timeToLive: Int) {\n\n fun generate(tokenId: String, currentTime: Int) {\n\n }\n\n fun renew(tokenId: String, currentTime: Int) {\n\n }\n\n fun countUnexpiredTokens(currentTime: Int): Int {\n\n }\n\n}\n\n/**\n * Your AuthenticationManager object will be instantiated and called as such:\n * var obj = AuthenticationManager(timeToLive)\n * obj.generate(tokenId,currentTime)\n * obj.renew(tokenId,currentTime)\n * var param_3 = obj.countUnexpiredTokens(currentTime)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct AuthenticationManager {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl AuthenticationManager {\n\n fn new(timeToLive: i32) -> Self {\n\n }\n \n fn generate(&self, token_id: String, current_time: i32) {\n\n }\n \n fn renew(&self, token_id: String, current_time: i32) {\n\n }\n \n fn count_unexpired_tokens(&self, current_time: i32) -> i32 {\n\n }\n}\n\n/**\n * Your AuthenticationManager object will be instantiated and called as such:\n * let obj = AuthenticationManager::new(timeToLive);\n * obj.generate(tokenId, currentTime);\n * obj.renew(tokenId, currentTime);\n * let ret_3: i32 = obj.count_unexpired_tokens(currentTime);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class AuthenticationManager {\n /**\n * @param Integer $timeToLive\n */\n function __construct($timeToLive) {\n\n }\n\n /**\n * @param String $tokenId\n * @param Integer $currentTime\n * @return NULL\n */\n function generate($tokenId, $currentTime) {\n\n }\n\n /**\n * @param String $tokenId\n * @param Integer $currentTime\n * @return NULL\n */\n function renew($tokenId, $currentTime) {\n\n }\n\n /**\n * @param Integer $currentTime\n * @return Integer\n */\n function countUnexpiredTokens($currentTime) {\n\n }\n}\n\n/**\n * Your AuthenticationManager object will be instantiated and called as such:\n * $obj = AuthenticationManager($timeToLive);\n * $obj->generate($tokenId, $currentTime);\n * $obj->renew($tokenId, $currentTime);\n * $ret_3 = $obj->countUnexpiredTokens($currentTime);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class AuthenticationManager {\n constructor(timeToLive: number) {\n\n }\n\n generate(tokenId: string, currentTime: number): void {\n\n }\n\n renew(tokenId: string, currentTime: number): void {\n\n }\n\n countUnexpiredTokens(currentTime: number): number {\n\n }\n}\n\n/**\n * Your AuthenticationManager object will be instantiated and called as such:\n * var obj = new AuthenticationManager(timeToLive)\n * obj.generate(tokenId,currentTime)\n * obj.renew(tokenId,currentTime)\n * var param_3 = obj.countUnexpiredTokens(currentTime)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define authentication-manager%\n (class object%\n (super-new)\n\n ; time-to-live : exact-integer?\n (init-field\n time-to-live)\n \n ; generate : string? exact-integer? -> void?\n (define/public (generate tokenId currentTime)\n\n )\n ; renew : string? exact-integer? -> void?\n (define/public (renew tokenId currentTime)\n\n )\n ; count-unexpired-tokens : exact-integer? -> exact-integer?\n (define/public (count-unexpired-tokens currentTime)\n\n )))\n\n;; Your authentication-manager% object will be instantiated and called as such:\n;; (define obj (new authentication-manager% [timeToLive timeToLive]))\n;; (send obj generate token-id current-time)\n;; (send obj renew token-id current-time)\n;; (define param_3 (send obj count-unexpired-tokens current-time))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1797](https://leetcode-cn.com/problems/design-authentication-manager)", "[\u8bbe\u8ba1\u4e00\u4e2a\u9a8c\u8bc1\u7cfb\u7edf](/solution/1700-1799/1797.Design%20Authentication%20Manager/README.md)", "`\u8bbe\u8ba1`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1797](https://leetcode.com/problems/design-authentication-manager)", "[Design Authentication Manager](/solution/1700-1799/1797.Design%20Authentication%20Manager/README_EN.md)", "`Design`,`Hash Table`", "Medium", ""]}, {"question_id": "1904", "frontend_question_id": "1796", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/second-largest-digit-in-a-string", "url_en": "https://leetcode.com/problems/second-largest-digit-in-a-string", "relative_path_cn": "/solution/1700-1799/1796.Second%20Largest%20Digit%20in%20a%20String/README.md", "relative_path_en": "/solution/1700-1799/1796.Second%20Largest%20Digit%20in%20a%20String/README_EN.md", "title_cn": "\u5b57\u7b26\u4e32\u4e2d\u7b2c\u4e8c\u5927\u7684\u6570\u5b57", "title_en": "Second Largest Digit in a String", "question_title_slug": "second-largest-digit-in-a-string", "content_en": "

    Given an alphanumeric string s, return the second largest numerical digit that appears in s, or -1 if it does not exist.

    \n\n

    An alphanumeric string is a string consisting of lowercase English letters and digits.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "dfa12321afd"\nOutput: 2\nExplanation: The digits that appear in s are [1, 2, 3]. The second largest digit is 2.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "abc1111"\nOutput: -1\nExplanation: The digits that appear in s are [1]. There is no second largest digit. \n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 500
    • \n\t
    • s consists of only lowercase English letters and/or digits.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6df7\u5408\u5b57\u7b26\u4e32\u00a0s\u00a0\uff0c\u8bf7\u4f60\u8fd4\u56de s\u00a0\u4e2d \u7b2c\u4e8c\u5927 \u7684\u6570\u5b57\uff0c\u5982\u679c\u4e0d\u5b58\u5728\u7b2c\u4e8c\u5927\u7684\u6570\u5b57\uff0c\u8bf7\u4f60\u8fd4\u56de -1\u00a0\u3002

    \n\n

    \u6df7\u5408\u5b57\u7b26\u4e32 \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u548c\u6570\u5b57\u7ec4\u6210\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"dfa12321afd\"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u51fa\u73b0\u5728 s \u4e2d\u7684\u6570\u5b57\u5305\u62ec [1, 2, 3] \u3002\u7b2c\u4e8c\u5927\u7684\u6570\u5b57\u662f 2 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"abc1111\"\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u51fa\u73b0\u5728 s \u4e2d\u7684\u6570\u5b57\u53ea\u5305\u542b [1] \u3002\u6ca1\u6709\u7b2c\u4e8c\u5927\u7684\u6570\u5b57\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 500
    • \n\t
    • s\u00a0\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u548c\uff08\u6216\uff09\u6570\u5b57\u3002
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int secondHighest(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int secondHighest(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def secondHighest(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def secondHighest(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint secondHighest(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SecondHighest(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar secondHighest = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef second_highest(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func secondHighest(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func secondHighest(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def secondHighest(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun secondHighest(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn second_highest(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function secondHighest($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function secondHighest(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (second-highest s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1796](https://leetcode-cn.com/problems/second-largest-digit-in-a-string)", "[\u5b57\u7b26\u4e32\u4e2d\u7b2c\u4e8c\u5927\u7684\u6570\u5b57](/solution/1700-1799/1796.Second%20Largest%20Digit%20in%20a%20String/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1796](https://leetcode.com/problems/second-largest-digit-in-a-string)", "[Second Largest Digit in a String](/solution/1700-1799/1796.Second%20Largest%20Digit%20in%20a%20String/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1903", "frontend_question_id": "1756", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/design-most-recently-used-queue", "url_en": "https://leetcode.com/problems/design-most-recently-used-queue", "relative_path_cn": "/solution/1700-1799/1756.Design%20Most%20Recently%20Used%20Queue/README.md", "relative_path_en": "/solution/1700-1799/1756.Design%20Most%20Recently%20Used%20Queue/README_EN.md", "title_cn": "\u8bbe\u8ba1\u6700\u8fd1\u4f7f\u7528\uff08MRU\uff09\u961f\u5217", "title_en": "Design Most Recently Used Queue", "question_title_slug": "design-most-recently-used-queue", "content_en": "

    Design a queue-like data structure that moves the most recently used element to the end of the queue.

    \n\n

    Implement the MRUQueue class:

    \n\n
      \n\t
    • MRUQueue(int n) constructs the MRUQueue with n elements: [1,2,3,...,n].
    • \n\t
    • int fetch(int k) moves the kth element (1-indexed) to the end of the queue and returns it.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput:\n["MRUQueue", "fetch", "fetch", "fetch", "fetch"]\n[[8], [3], [5], [2], [8]]\nOutput:\n[null, 3, 6, 2, 2]\n\nExplanation:\nMRUQueue mRUQueue = new MRUQueue(8); // Initializes the queue to [1,2,3,4,5,6,7,8].\nmRUQueue.fetch(3); // Moves the 3rd element (3) to the end of the queue to become [1,2,4,5,6,7,8,3] and returns it.\nmRUQueue.fetch(5); // Moves the 5th element (6) to the end of the queue to become [1,2,4,5,7,8,3,6] and returns it.\nmRUQueue.fetch(2); // Moves the 2nd element (2) to the end of the queue to become [1,4,5,7,8,3,6,2] and returns it.\nmRUQueue.fetch(8); // The 8th element (2) is already at the end of the queue so just return it.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 2000
    • \n\t
    • 1 <= k <= n
    • \n\t
    • At most 2000 calls will be made to fetch.
    • \n
    \n\n

     

    \nFollow up: Finding an O(n) algorithm per fetch is a bit easy. Can you find an algorithm with a better complexity for each fetch call?", "content_cn": "

    \u8bbe\u8ba1\u4e00\u79cd\u7c7b\u4f3c\u961f\u5217\u7684\u6570\u636e\u7ed3\u6784\uff0c\u8be5\u6570\u636e\u7ed3\u6784\u5c06\u6700\u8fd1\u4f7f\u7528\u7684\u5143\u7d20\u79fb\u5230\u961f\u5217\u5c3e\u90e8\u3002

    \n\n

    \u5b9e\u73b0\u00a0MRUQueue\u00a0\u7c7b\uff1a

    \n\n
      \n\t
    • MRUQueue(int n)\u00a0\u00a0\u4f7f\u7528\u00a0n\u00a0\u4e2a\u5143\u7d20\uff1a\u00a0[1,2,3,...,n]\u00a0\u6784\u9020\u00a0MRUQueue\u00a0\u3002
    • \n\t
    • fetch(int k)\u00a0\u5c06\u7b2c\u00a0k\u00a0\u4e2a\u5143\u7d20\uff08\u4ece 1 \u5f00\u59cb\u7d22\u5f15\uff09\u79fb\u5230\u961f\u5c3e\uff0c\u5e76\u8fd4\u56de\u8be5\u5143\u7d20\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\n[\"MRUQueue\", \"fetch\", \"fetch\", \"fetch\", \"fetch\"]\n[[8], [3], [5], [2], [8]]\n\u8f93\u51fa\uff1a\n[null, 3, 6, 2, 2]\n\n\u89e3\u91ca\uff1a\nMRUQueue mRUQueue = new MRUQueue(8); // \u521d\u59cb\u5316\u961f\u5217\u4e3a [1,2,3,4,5,6,7,8]\u3002\nmRUQueue.fetch(3); // \u5c06\u7b2c 3 \u4e2a\u5143\u7d20 (3) \u79fb\u5230\u961f\u5c3e\uff0c\u4f7f\u961f\u5217\u53d8\u4e3a [1,2,4,5,6,7,8,3] \u5e76\u8fd4\u56de\u8be5\u5143\u7d20\u3002\nmRUQueue.fetch(5); // \u5c06\u7b2c 5 \u4e2a\u5143\u7d20 (6) \u79fb\u5230\u961f\u5c3e\uff0c\u4f7f\u961f\u5217\u53d8\u4e3a [1,2,4,5,7,8,3,6] \u5e76\u8fd4\u56de\u8be5\u5143\u7d20\u3002\nmRUQueue.fetch(2); // \u5c06\u7b2c 2 \u4e2a\u5143\u7d20 (2) \u79fb\u5230\u961f\u5c3e\uff0c\u4f7f\u961f\u5217\u53d8\u4e3a [1,4,5,7,8,3,6,2] \u5e76\u8fd4\u56de\u8be5\u5143\u7d20\u3002\nmRUQueue.fetch(8); // \u7b2c 8 \u4e2a\u5143\u7d20 (2) \u5df2\u7ecf\u5728\u961f\u5217\u5c3e\u90e8\u4e86\uff0c\u6240\u4ee5\u76f4\u63a5\u8fd4\u56de\u8be5\u5143\u7d20\u5373\u53ef\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 2000
    • \n\t
    • 1 <= k <= n
    • \n\t
    • \u6700\u591a\u8c03\u7528\u00a02000\u00a0\u6b21\u00a0fetch
    • \n
    \n\n

    \u00a0

    \n\u8fdb\u9636\uff1a\u627e\u5230\u6bcf\u6b21\u00a0fetch\u00a0\u7684\u590d\u6742\u5ea6\u4e3a\u00a0O(n)\u00a0\u7684\u7b97\u6cd5\u6bd4\u8f83\u7b80\u5355\u3002\u4f60\u53ef\u4ee5\u627e\u5230\u6bcf\u6b21\u00a0fetch\u00a0\u7684\u590d\u6742\u5ea6\u66f4\u4f73\u7684\u7b97\u6cd5\u5417\uff1f", "tags_en": ["Design", "Array"], "tags_cn": ["\u8bbe\u8ba1", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class MRUQueue {\npublic:\n MRUQueue(int n) {\n\n }\n \n int fetch(int k) {\n\n }\n};\n\n/**\n * Your MRUQueue object will be instantiated and called as such:\n * MRUQueue* obj = new MRUQueue(n);\n * int param_1 = obj->fetch(k);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class MRUQueue {\n\n public MRUQueue(int n) {\n\n }\n \n public int fetch(int k) {\n\n }\n}\n\n/**\n * Your MRUQueue object will be instantiated and called as such:\n * MRUQueue obj = new MRUQueue(n);\n * int param_1 = obj.fetch(k);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class MRUQueue(object):\n\n def __init__(self, n):\n \"\"\"\n :type n: int\n \"\"\"\n\n\n def fetch(self, k):\n \"\"\"\n :type k: int\n :rtype: int\n \"\"\"\n\n\n\n# Your MRUQueue object will be instantiated and called as such:\n# obj = MRUQueue(n)\n# param_1 = obj.fetch(k)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class MRUQueue:\n\n def __init__(self, n: int):\n\n\n def fetch(self, k: int) -> int:\n\n\n\n# Your MRUQueue object will be instantiated and called as such:\n# obj = MRUQueue(n)\n# param_1 = obj.fetch(k)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} MRUQueue;\n\n\nMRUQueue* mRUQueueCreate(int n) {\n\n}\n\nint mRUQueueFetch(MRUQueue* obj, int k) {\n\n}\n\nvoid mRUQueueFree(MRUQueue* obj) {\n\n}\n\n/**\n * Your MRUQueue struct will be instantiated and called as such:\n * MRUQueue* obj = mRUQueueCreate(n);\n * int param_1 = mRUQueueFetch(obj, k);\n \n * mRUQueueFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class MRUQueue {\n\n public MRUQueue(int n) {\n\n }\n \n public int Fetch(int k) {\n\n }\n}\n\n/**\n * Your MRUQueue object will be instantiated and called as such:\n * MRUQueue obj = new MRUQueue(n);\n * int param_1 = obj.Fetch(k);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n */\nvar MRUQueue = function(n) {\n\n};\n\n/** \n * @param {number} k\n * @return {number}\n */\nMRUQueue.prototype.fetch = function(k) {\n\n};\n\n/**\n * Your MRUQueue object will be instantiated and called as such:\n * var obj = new MRUQueue(n)\n * var param_1 = obj.fetch(k)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class MRUQueue\n\n=begin\n :type n: Integer\n=end\n def initialize(n)\n\n end\n\n\n=begin\n :type k: Integer\n :rtype: Integer\n=end\n def fetch(k)\n\n end\n\n\nend\n\n# Your MRUQueue object will be instantiated and called as such:\n# obj = MRUQueue.new(n)\n# param_1 = obj.fetch(k)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass MRUQueue {\n\n init(_ n: Int) {\n\n }\n \n func fetch(_ k: Int) -> Int {\n\n }\n}\n\n/**\n * Your MRUQueue object will be instantiated and called as such:\n * let obj = MRUQueue(n)\n * let ret_1: Int = obj.fetch(k)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type MRUQueue struct {\n\n}\n\n\nfunc Constructor(n int) MRUQueue {\n\n}\n\n\nfunc (this *MRUQueue) Fetch(k int) int {\n\n}\n\n\n/**\n * Your MRUQueue object will be instantiated and called as such:\n * obj := Constructor(n);\n * param_1 := obj.Fetch(k);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class MRUQueue(_n: Int) {\n\n def fetch(k: Int): Int = {\n \n }\n\n}\n\n/**\n * Your MRUQueue object will be instantiated and called as such:\n * var obj = new MRUQueue(n)\n * var param_1 = obj.fetch(k)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class MRUQueue(n: Int) {\n\n fun fetch(k: Int): Int {\n\n }\n\n}\n\n/**\n * Your MRUQueue object will be instantiated and called as such:\n * var obj = MRUQueue(n)\n * var param_1 = obj.fetch(k)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct MRUQueue {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl MRUQueue {\n\n fn new(n: i32) -> Self {\n\n }\n \n fn fetch(&self, k: i32) -> i32 {\n\n }\n}\n\n/**\n * Your MRUQueue object will be instantiated and called as such:\n * let obj = MRUQueue::new(n);\n * let ret_1: i32 = obj.fetch(k);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class MRUQueue {\n /**\n * @param Integer $n\n */\n function __construct($n) {\n\n }\n\n /**\n * @param Integer $k\n * @return Integer\n */\n function fetch($k) {\n\n }\n}\n\n/**\n * Your MRUQueue object will be instantiated and called as such:\n * $obj = MRUQueue($n);\n * $ret_1 = $obj->fetch($k);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class MRUQueue {\n constructor(n: number) {\n\n }\n\n fetch(k: number): number {\n\n }\n}\n\n/**\n * Your MRUQueue object will be instantiated and called as such:\n * var obj = new MRUQueue(n)\n * var param_1 = obj.fetch(k)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define mru-queue%\n (class object%\n (super-new)\n\n ; n : exact-integer?\n (init-field\n n)\n \n ; fetch : exact-integer? -> exact-integer?\n (define/public (fetch k)\n\n )))\n\n;; Your mru-queue% object will be instantiated and called as such:\n;; (define obj (new mru-queue% [n n]))\n;; (define param_1 (send obj fetch k))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1756](https://leetcode-cn.com/problems/design-most-recently-used-queue)", "[\u8bbe\u8ba1\u6700\u8fd1\u4f7f\u7528\uff08MRU\uff09\u961f\u5217](/solution/1700-1799/1756.Design%20Most%20Recently%20Used%20Queue/README.md)", "`\u8bbe\u8ba1`,`\u6570\u7ec4`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1756](https://leetcode.com/problems/design-most-recently-used-queue)", "[Design Most Recently Used Queue](/solution/1700-1799/1756.Design%20Most%20Recently%20Used%20Queue/README_EN.md)", "`Design`,`Array`", "Medium", "\ud83d\udd12"]}, {"question_id": "1902", "frontend_question_id": "1776", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/car-fleet-ii", "url_en": "https://leetcode.com/problems/car-fleet-ii", "relative_path_cn": "/solution/1700-1799/1776.Car%20Fleet%20II/README.md", "relative_path_en": "/solution/1700-1799/1776.Car%20Fleet%20II/README_EN.md", "title_cn": "\u8f66\u961f II", "title_en": "Car Fleet II", "question_title_slug": "car-fleet-ii", "content_en": "

    There are n cars traveling at different speeds in the same direction along a one-lane road. You are given an array cars of length n, where cars[i] = [positioni, speedi] represents:

    \n\n
      \n\t
    • positioni is the distance between the ith car and the beginning of the road in meters. It is guaranteed that positioni < positioni+1.
    • \n\t
    • speedi is the initial speed of the ith car in meters per second.
    • \n
    \n\n

    For simplicity, cars can be considered as points moving along the number line. Two cars collide when they occupy the same position. Once a car collides with another car, they unite and form a single car fleet. The cars in the formed fleet will have the same position and the same speed, which is the initial speed of the slowest car in the fleet.

    \n\n

    Return an array answer, where answer[i] is the time, in seconds, at which the ith car collides with the next car, or -1 if the car does not collide with the next car. Answers within 10-5 of the actual answers are accepted.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: cars = [[1,2],[2,1],[4,3],[7,2]]\nOutput: [1.00000,-1.00000,3.00000,-1.00000]\nExplanation: After exactly one second, the first car will collide with the second car, and form a car fleet with speed 1 m/s. After exactly 3 seconds, the third car will collide with the fourth car, and form a car fleet with speed 2 m/s.\n
    \n\n

    Example 2:

    \n\n
    \nInput: cars = [[3,4],[5,4],[6,3],[9,1]]\nOutput: [2.00000,1.00000,1.50000,-1.00000]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= cars.length <= 105
    • \n\t
    • 1 <= positioni, speedi <= 106
    • \n\t
    • positioni < positioni+1
    • \n
    \n", "content_cn": "

    \u5728\u4e00\u6761\u5355\u8f66\u9053\u4e0a\u6709 n\u00a0\u8f86\u8f66\uff0c\u5b83\u4eec\u671d\u7740\u540c\u6837\u7684\u65b9\u5411\u884c\u9a76\u3002\u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u4e3a n\u00a0\u7684\u6570\u7ec4 cars\u00a0\uff0c\u5176\u4e2d\u00a0cars[i] = [positioni, speedi]\u00a0\uff0c\u5b83\u8868\u793a\uff1a

    \n\n
      \n\t
    • positioni\u00a0\u662f\u7b2c i\u00a0\u8f86\u8f66\u548c\u9053\u8def\u8d77\u70b9\u4e4b\u95f4\u7684\u8ddd\u79bb\uff08\u5355\u4f4d\uff1a\u7c73\uff09\u3002\u9898\u76ee\u4fdd\u8bc1\u00a0positioni < positioni+1\u00a0\u3002
    • \n\t
    • speedi\u00a0\u662f\u7b2c i\u00a0\u8f86\u8f66\u7684\u521d\u59cb\u901f\u5ea6\uff08\u5355\u4f4d\uff1a\u7c73/\u79d2\uff09\u3002
    • \n
    \n\n

    \u7b80\u5355\u8d77\u89c1\uff0c\u6240\u6709\u8f66\u5b50\u53ef\u4ee5\u89c6\u4e3a\u5728\u6570\u8f74\u4e0a\u79fb\u52a8\u7684\u70b9\u3002\u5f53\u4e24\u8f86\u8f66\u5360\u636e\u540c\u4e00\u4e2a\u4f4d\u7f6e\u65f6\uff0c\u6211\u4eec\u79f0\u5b83\u4eec\u76f8\u9047\u4e86\u3002\u4e00\u65e6\u4e24\u8f86\u8f66\u76f8\u9047\uff0c\u5b83\u4eec\u4f1a\u5408\u5e76\u6210\u4e00\u4e2a\u8f66\u961f\uff0c\u8fd9\u4e2a\u8f66\u961f\u91cc\u7684\u8f66\u6709\u7740\u540c\u6837\u7684\u4f4d\u7f6e\u548c\u76f8\u540c\u7684\u901f\u5ea6\uff0c\u901f\u5ea6\u4e3a\u8fd9\u4e2a\u8f66\u961f\u91cc\u00a0\u6700\u6162\u00a0\u4e00\u8f86\u8f66\u7684\u901f\u5ea6\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u4e00\u4e2a\u6570\u7ec4\u00a0answer\u00a0\uff0c\u5176\u4e2d\u00a0answer[i]\u00a0\u662f\u7b2c i\u00a0\u8f86\u8f66\u4e0e\u4e0b\u4e00\u8f86\u8f66\u76f8\u9047\u7684\u65f6\u95f4\uff08\u5355\u4f4d\uff1a\u79d2\uff09\uff0c\u5982\u679c\u8fd9\u8f86\u8f66\u4e0d\u4f1a\u4e0e\u4e0b\u4e00\u8f86\u8f66\u76f8\u9047\uff0c\u5219 answer[i]\u00a0\u4e3a -1\u00a0\u3002\u7b54\u6848\u7cbe\u5ea6\u8bef\u5dee\u9700\u5728 10-5\u00a0\u4ee5\u5185\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1acars = [[1,2],[2,1],[4,3],[7,2]]\n\u8f93\u51fa\uff1a[1.00000,-1.00000,3.00000,-1.00000]\n\u89e3\u91ca\uff1a\u7ecf\u8fc7\u6070\u597d 1 \u79d2\u4ee5\u540e\uff0c\u7b2c\u4e00\u8f86\u8f66\u4f1a\u4e0e\u7b2c\u4e8c\u8f86\u8f66\u76f8\u9047\uff0c\u5e76\u5f62\u6210\u4e00\u4e2a 1 m/s \u7684\u8f66\u961f\u3002\u7ecf\u8fc7\u6070\u597d 3 \u79d2\u4ee5\u540e\uff0c\u7b2c\u4e09\u8f86\u8f66\u4f1a\u4e0e\u7b2c\u56db\u8f86\u8f66\u76f8\u9047\uff0c\u5e76\u5f62\u6210\u4e00\u4e2a 2 m/s \u7684\u8f66\u961f\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1acars = [[3,4],[5,4],[6,3],[9,1]]\n\u8f93\u51fa\uff1a[2.00000,1.00000,1.50000,-1.00000]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= cars.length <= 105
    • \n\t
    • 1 <= positioni, speedi <= 106
    • \n\t
    • positioni < positioni+1
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector getCollisionTimes(vector>& cars) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double[] getCollisionTimes(int[][] cars) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getCollisionTimes(self, cars):\n \"\"\"\n :type cars: List[List[int]]\n :rtype: List[float]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getCollisionTimes(self, cars: List[List[int]]) -> List[float]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\ndouble* getCollisionTimes(int** cars, int carsSize, int* carsColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double[] GetCollisionTimes(int[][] cars) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} cars\n * @return {number[]}\n */\nvar getCollisionTimes = function(cars) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} cars\n# @return {Float[]}\ndef get_collision_times(cars)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getCollisionTimes(_ cars: [[Int]]) -> [Double] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getCollisionTimes(cars [][]int) []float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getCollisionTimes(cars: Array[Array[Int]]): Array[Double] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getCollisionTimes(cars: Array): DoubleArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_collision_times(cars: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $cars\n * @return Float[]\n */\n function getCollisionTimes($cars) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getCollisionTimes(cars: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-collision-times cars)\n (-> (listof (listof exact-integer?)) (listof flonum?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1776](https://leetcode-cn.com/problems/car-fleet-ii)", "[\u8f66\u961f II](/solution/1700-1799/1776.Car%20Fleet%20II/README.md)", "`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[1776](https://leetcode.com/problems/car-fleet-ii)", "[Car Fleet II](/solution/1700-1799/1776.Car%20Fleet%20II/README_EN.md)", "`Math`", "Hard", ""]}, {"question_id": "1901", "frontend_question_id": "1775", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/equal-sum-arrays-with-minimum-number-of-operations", "url_en": "https://leetcode.com/problems/equal-sum-arrays-with-minimum-number-of-operations", "relative_path_cn": "/solution/1700-1799/1775.Equal%20Sum%20Arrays%20With%20Minimum%20Number%20of%20Operations/README.md", "relative_path_en": "/solution/1700-1799/1775.Equal%20Sum%20Arrays%20With%20Minimum%20Number%20of%20Operations/README_EN.md", "title_cn": "\u901a\u8fc7\u6700\u5c11\u64cd\u4f5c\u6b21\u6570\u4f7f\u6570\u7ec4\u7684\u548c\u76f8\u7b49", "title_en": "Equal Sum Arrays With Minimum Number of Operations", "question_title_slug": "equal-sum-arrays-with-minimum-number-of-operations", "content_en": "

    You are given two arrays of integers nums1 and nums2, possibly of different lengths. The values in the arrays are between 1 and 6, inclusive.

    \n\n

    In one operation, you can change any integer's value in any of the arrays to any value between 1 and 6, inclusive.

    \n\n

    Return the minimum number of operations required to make the sum of values in nums1 equal to the sum of values in nums2. Return -1\u200b\u200b\u200b\u200b\u200b if it is not possible to make the sum of the two arrays equal.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums1 = [1,2,3,4,5,6], nums2 = [1,1,2,2,2,2]\nOutput: 3\nExplanation: You can make the sums of nums1 and nums2 equal with 3 operations. All indices are 0-indexed.\n- Change nums2[0] to 6. nums1 = [1,2,3,4,5,6], nums2 = [6,1,2,2,2,2].\n- Change nums1[5] to 1. nums1 = [1,2,3,4,5,1], nums2 = [6,1,2,2,2,2].\n- Change nums1[2] to 2. nums1 = [1,2,2,4,5,1], nums2 = [6,1,2,2,2,2].\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums1 = [1,1,1,1,1,1,1], nums2 = [6]\nOutput: -1\nExplanation: There is no way to decrease the sum of nums1 or to increase the sum of nums2 to make them equal.\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums1 = [6,6], nums2 = [1]\nOutput: 3\nExplanation: You can make the sums of nums1 and nums2 equal with 3 operations. All indices are 0-indexed. \n- Change nums1[0] to 2. nums1 = [2,6], nums2 = [1].\n- Change nums1[1] to 2. nums1 = [2,2], nums2 = [1].\n- Change nums2[0] to 4. nums1 = [2,2], nums2 = [4].\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums1.length, nums2.length <= 105
    • \n\t
    • 1 <= nums1[i], nums2[i] <= 6
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u957f\u5ea6\u53ef\u80fd\u4e0d\u7b49\u7684\u6574\u6570\u6570\u7ec4\u00a0nums1 \u548c\u00a0nums2\u00a0\u3002\u4e24\u4e2a\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u503c\u90fd\u5728\u00a01\u00a0\u5230\u00a06\u00a0\u4e4b\u95f4\uff08\u5305\u542b\u00a01\u00a0\u548c\u00a06\uff09\u3002

    \n\n

    \u6bcf\u6b21\u64cd\u4f5c\u4e2d\uff0c\u4f60\u53ef\u4ee5\u9009\u62e9 \u4efb\u610f\u00a0\u6570\u7ec4\u4e2d\u7684\u4efb\u610f\u4e00\u4e2a\u6574\u6570\uff0c\u5c06\u5b83\u53d8\u6210 1\u00a0\u5230 6\u00a0\u4e4b\u95f4 \u4efb\u610f\u00a0\u7684\u503c\uff08\u5305\u542b 1\u00a0\u548c 6\uff09\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u4f7f nums1\u00a0\u4e2d\u6240\u6709\u6570\u7684\u548c\u4e0e\u00a0nums2\u00a0\u4e2d\u6240\u6709\u6570\u7684\u548c\u76f8\u7b49\u7684\u6700\u5c11\u64cd\u4f5c\u6b21\u6570\u3002\u5982\u679c\u65e0\u6cd5\u4f7f\u4e24\u4e2a\u6570\u7ec4\u7684\u548c\u76f8\u7b49\uff0c\u8bf7\u8fd4\u56de -1\u00a0\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anums1 = [1,2,3,4,5,6], nums2 = [1,1,2,2,2,2]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u901a\u8fc7 3 \u6b21\u64cd\u4f5c\u4f7f nums1 \u4e2d\u6240\u6709\u6570\u7684\u548c\u4e0e nums2 \u4e2d\u6240\u6709\u6570\u7684\u548c\u76f8\u7b49\u3002\u4ee5\u4e0b\u6570\u7ec4\u4e0b\u6807\u90fd\u4ece 0 \u5f00\u59cb\u3002\n- \u5c06 nums2[0] \u53d8\u4e3a 6 \u3002 nums1 = [1,2,3,4,5,6], nums2 = [6,1,2,2,2,2] \u3002\n- \u5c06 nums1[5] \u53d8\u4e3a 1 \u3002 nums1 = [1,2,3,4,5,1], nums2 = [6,1,2,2,2,2] \u3002\n- \u5c06 nums1[2] \u53d8\u4e3a 2 \u3002 nums1 = [1,2,2,4,5,1], nums2 = [6,1,2,2,2,2] \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anums1 = [1,1,1,1,1,1,1], nums2 = [6]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u6ca1\u6709\u529e\u6cd5\u51cf\u5c11 nums1 \u7684\u548c\u6216\u8005\u589e\u52a0 nums2 \u7684\u548c\u4f7f\u4e8c\u8005\u76f8\u7b49\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1anums1 = [6,6], nums2 = [1]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u901a\u8fc7 3 \u6b21\u64cd\u4f5c\u4f7f nums1 \u4e2d\u6240\u6709\u6570\u7684\u548c\u4e0e nums2 \u4e2d\u6240\u6709\u6570\u7684\u548c\u76f8\u7b49\u3002\u4ee5\u4e0b\u6570\u7ec4\u4e0b\u6807\u90fd\u4ece 0 \u5f00\u59cb\u3002\n- \u5c06 nums1[0] \u53d8\u4e3a 2 \u3002 nums1 = [2,6], nums2 = [1] \u3002\n- \u5c06 nums1[1] \u53d8\u4e3a 2 \u3002 nums1 = [2,2], nums2 = [1] \u3002\n- \u5c06 nums2[0] \u53d8\u4e3a 4 \u3002 nums1 = [2,2], nums2 = [4] \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums1.length, nums2.length <= 105
    • \n\t
    • 1 <= nums1[i], nums2[i] <= 6
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minOperations(vector& nums1, vector& nums2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minOperations(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minOperations(self, nums1, nums2):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minOperations(self, nums1: List[int], nums2: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minOperations(int* nums1, int nums1Size, int* nums2, int nums2Size){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinOperations(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums1\n * @param {number[]} nums2\n * @return {number}\n */\nvar minOperations = function(nums1, nums2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums1\n# @param {Integer[]} nums2\n# @return {Integer}\ndef min_operations(nums1, nums2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minOperations(_ nums1: [Int], _ nums2: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minOperations(nums1 []int, nums2 []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minOperations(nums1: Array[Int], nums2: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minOperations(nums1: IntArray, nums2: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_operations(nums1: Vec, nums2: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums1\n * @param Integer[] $nums2\n * @return Integer\n */\n function minOperations($nums1, $nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minOperations(nums1: number[], nums2: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-operations nums1 nums2)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1775](https://leetcode-cn.com/problems/equal-sum-arrays-with-minimum-number-of-operations)", "[\u901a\u8fc7\u6700\u5c11\u64cd\u4f5c\u6b21\u6570\u4f7f\u6570\u7ec4\u7684\u548c\u76f8\u7b49](/solution/1700-1799/1775.Equal%20Sum%20Arrays%20With%20Minimum%20Number%20of%20Operations/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1775](https://leetcode.com/problems/equal-sum-arrays-with-minimum-number-of-operations)", "[Equal Sum Arrays With Minimum Number of Operations](/solution/1700-1799/1775.Equal%20Sum%20Arrays%20With%20Minimum%20Number%20of%20Operations/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1900", "frontend_question_id": "1774", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/closest-dessert-cost", "url_en": "https://leetcode.com/problems/closest-dessert-cost", "relative_path_cn": "/solution/1700-1799/1774.Closest%20Dessert%20Cost/README.md", "relative_path_en": "/solution/1700-1799/1774.Closest%20Dessert%20Cost/README_EN.md", "title_cn": "\u6700\u63a5\u8fd1\u76ee\u6807\u4ef7\u683c\u7684\u751c\u70b9\u6210\u672c", "title_en": "Closest Dessert Cost", "question_title_slug": "closest-dessert-cost", "content_en": "

    You would like to make dessert and are preparing to buy the ingredients. You have n ice cream base flavors and m types of toppings to choose from. You must follow these rules when making your dessert:

    \n\n
      \n\t
    • There must be exactly one ice cream base.
    • \n\t
    • You can add one or more types of topping or have no toppings at all.
    • \n\t
    • There are at most two of each type of topping.
    • \n
    \n\n

    You are given three inputs:

    \n\n
      \n\t
    • baseCosts, an integer array of length n, where each baseCosts[i] represents the price of the ith ice cream base flavor.
    • \n\t
    • toppingCosts, an integer array of length m, where each toppingCosts[i] is the price of one of the ith topping.
    • \n\t
    • target, an integer representing your target price for dessert.
    • \n
    \n\n

    You want to make a dessert with a total cost as close to target as possible.

    \n\n

    Return the closest possible cost of the dessert to target. If there are multiple, return the lower one.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: baseCosts = [1,7], toppingCosts = [3,4], target = 10\nOutput: 10\nExplanation: Consider the following combination (all 0-indexed):\n- Choose base 1: cost 7\n- Take 1 of topping 0: cost 1 x 3 = 3\n- Take 0 of topping 1: cost 0 x 4 = 0\nTotal: 7 + 3 + 0 = 10.\n
    \n\n

    Example 2:

    \n\n
    \nInput: baseCosts = [2,3], toppingCosts = [4,5,100], target = 18\nOutput: 17\nExplanation: Consider the following combination (all 0-indexed):\n- Choose base 1: cost 3\n- Take 1 of topping 0: cost 1 x 4 = 4\n- Take 2 of topping 1: cost 2 x 5 = 10\n- Take 0 of topping 2: cost 0 x 100 = 0\nTotal: 3 + 4 + 10 + 0 = 17. You cannot make a dessert with a total cost of 18.\n
    \n\n

    Example 3:

    \n\n
    \nInput: baseCosts = [3,10], toppingCosts = [2,5], target = 9\nOutput: 8\nExplanation: It is possible to make desserts with cost 8 and 10. Return 8 as it is the lower cost.\n
    \n\n

    Example 4:

    \n\n
    \nInput: baseCosts = [10], toppingCosts = [1], target = 1\nOutput: 10\nExplanation: Notice that you don't have to have any toppings, but you must have exactly one base.
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == baseCosts.length
    • \n\t
    • m == toppingCosts.length
    • \n\t
    • 1 <= n, m <= 10
    • \n\t
    • 1 <= baseCosts[i], toppingCosts[i] <= 104
    • \n\t
    • 1 <= target <= 104
    • \n
    \n", "content_cn": "

    \u4f60\u6253\u7b97\u505a\u751c\u70b9\uff0c\u73b0\u5728\u9700\u8981\u8d2d\u4e70\u914d\u6599\u3002\u76ee\u524d\u5171\u6709 n \u79cd\u51b0\u6fc0\u51cc\u57fa\u6599\u548c m \u79cd\u914d\u6599\u53ef\u4f9b\u9009\u8d2d\u3002\u800c\u5236\u4f5c\u751c\u70b9\u9700\u8981\u9075\u5faa\u4ee5\u4e0b\u51e0\u6761\u89c4\u5219\uff1a

    \n\n
      \n\t
    • \u5fc5\u987b\u9009\u62e9 \u4e00\u79cd \u51b0\u6fc0\u51cc\u57fa\u6599\u3002
    • \n\t
    • \u53ef\u4ee5\u6dfb\u52a0 \u4e00\u79cd\u6216\u591a\u79cd \u914d\u6599\uff0c\u4e5f\u53ef\u4ee5\u4e0d\u6dfb\u52a0\u4efb\u4f55\u914d\u6599\u3002
    • \n\t
    • \u6bcf\u79cd\u7c7b\u578b\u7684\u914d\u6599 \u6700\u591a\u4e24\u4efd \u3002
    • \n
    \n\n

    \u7ed9\u4f60\u4ee5\u4e0b\u4e09\u4e2a\u8f93\u5165\uff1a

    \n\n
      \n\t
    • baseCosts \uff0c\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u6574\u6570\u6570\u7ec4\uff0c\u5176\u4e2d\u6bcf\u4e2a baseCosts[i] \u8868\u793a\u7b2c i \u79cd\u51b0\u6fc0\u51cc\u57fa\u6599\u7684\u4ef7\u683c\u3002
    • \n\t
    • toppingCosts\uff0c\u4e00\u4e2a\u957f\u5ea6\u4e3a m \u7684\u6574\u6570\u6570\u7ec4\uff0c\u5176\u4e2d\u6bcf\u4e2a toppingCosts[i] \u8868\u793a \u4e00\u4efd \u7b2c i \u79cd\u51b0\u6fc0\u51cc\u914d\u6599\u7684\u4ef7\u683c\u3002
    • \n\t
    • target \uff0c\u4e00\u4e2a\u6574\u6570\uff0c\u8868\u793a\u4f60\u5236\u4f5c\u751c\u70b9\u7684\u76ee\u6807\u4ef7\u683c\u3002
    • \n
    \n\n

    \u4f60\u5e0c\u671b\u81ea\u5df1\u505a\u7684\u751c\u70b9\u603b\u6210\u672c\u5c3d\u53ef\u80fd\u63a5\u8fd1\u76ee\u6807\u4ef7\u683c target \u3002

    \n\n

    \u8fd4\u56de\u6700\u63a5\u8fd1 target \u7684\u751c\u70b9\u6210\u672c\u3002\u5982\u679c\u6709\u591a\u79cd\u65b9\u6848\uff0c\u8fd4\u56de\u00a0\u6210\u672c\u76f8\u5bf9\u8f83\u4f4e \u7684\u4e00\u79cd\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1abaseCosts = [1,7], toppingCosts = [3,4], target = 10\n\u8f93\u51fa\uff1a10\n\u89e3\u91ca\uff1a\u8003\u8651\u4e0b\u9762\u7684\u65b9\u6848\u7ec4\u5408\uff08\u6240\u6709\u4e0b\u6807\u5747\u4ece 0 \u5f00\u59cb\uff09\uff1a\n- \u9009\u62e9 1 \u53f7\u57fa\u6599\uff1a\u6210\u672c 7\n- \u9009\u62e9 1 \u4efd 0 \u53f7\u914d\u6599\uff1a\u6210\u672c 1 x 3 = 3\n- \u9009\u62e9 0 \u4efd 1 \u53f7\u914d\u6599\uff1a\u6210\u672c 0 x 4 = 0\n\u603b\u6210\u672c\uff1a7 + 3 + 0 = 10 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1abaseCosts = [2,3], toppingCosts = [4,5,100], target = 18\n\u8f93\u51fa\uff1a17\n\u89e3\u91ca\uff1a\u8003\u8651\u4e0b\u9762\u7684\u65b9\u6848\u7ec4\u5408\uff08\u6240\u6709\u4e0b\u6807\u5747\u4ece 0 \u5f00\u59cb\uff09\uff1a\n- \u9009\u62e9 1 \u53f7\u57fa\u6599\uff1a\u6210\u672c 3\n- \u9009\u62e9 1 \u4efd 0 \u53f7\u914d\u6599\uff1a\u6210\u672c 1 x 4 = 4\n- \u9009\u62e9 2 \u4efd 1 \u53f7\u914d\u6599\uff1a\u6210\u672c 2 x 5 = 10\n- \u9009\u62e9 0 \u4efd 2 \u53f7\u914d\u6599\uff1a\u6210\u672c 0 x 100 = 0\n\u603b\u6210\u672c\uff1a3 + 4 + 10 + 0 = 17 \u3002\u4e0d\u5b58\u5728\u603b\u6210\u672c\u4e3a 18 \u7684\u751c\u70b9\u5236\u4f5c\u65b9\u6848\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1abaseCosts = [3,10], toppingCosts = [2,5], target = 9\n\u8f93\u51fa\uff1a8\n\u89e3\u91ca\uff1a\u53ef\u4ee5\u5236\u4f5c\u603b\u6210\u672c\u4e3a 8 \u548c 10 \u7684\u751c\u70b9\u3002\u8fd4\u56de 8 \uff0c\u56e0\u4e3a\u8fd9\u662f\u6210\u672c\u66f4\u4f4e\u7684\u65b9\u6848\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1abaseCosts = [10], toppingCosts = [1], target = 1\n\u8f93\u51fa\uff1a10\n\u89e3\u91ca\uff1a\u6ce8\u610f\uff0c\u4f60\u53ef\u4ee5\u9009\u62e9\u4e0d\u6dfb\u52a0\u4efb\u4f55\u914d\u6599\uff0c\u4f46\u4f60\u5fc5\u987b\u9009\u62e9\u4e00\u79cd\u57fa\u6599\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == baseCosts.length
    • \n\t
    • m == toppingCosts.length
    • \n\t
    • 1 <= n, m <= 10
    • \n\t
    • 1 <= baseCosts[i], toppingCosts[i] <= 104
    • \n\t
    • 1 <= target <= 104
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int closestCost(vector& baseCosts, vector& toppingCosts, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int closestCost(int[] baseCosts, int[] toppingCosts, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def closestCost(self, baseCosts, toppingCosts, target):\n \"\"\"\n :type baseCosts: List[int]\n :type toppingCosts: List[int]\n :type target: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def closestCost(self, baseCosts: List[int], toppingCosts: List[int], target: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint closestCost(int* baseCosts, int baseCostsSize, int* toppingCosts, int toppingCostsSize, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ClosestCost(int[] baseCosts, int[] toppingCosts, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} baseCosts\n * @param {number[]} toppingCosts\n * @param {number} target\n * @return {number}\n */\nvar closestCost = function(baseCosts, toppingCosts, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} base_costs\n# @param {Integer[]} topping_costs\n# @param {Integer} target\n# @return {Integer}\ndef closest_cost(base_costs, topping_costs, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func closestCost(_ baseCosts: [Int], _ toppingCosts: [Int], _ target: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func closestCost(baseCosts []int, toppingCosts []int, target int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def closestCost(baseCosts: Array[Int], toppingCosts: Array[Int], target: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun closestCost(baseCosts: IntArray, toppingCosts: IntArray, target: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn closest_cost(base_costs: Vec, topping_costs: Vec, target: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $baseCosts\n * @param Integer[] $toppingCosts\n * @param Integer $target\n * @return Integer\n */\n function closestCost($baseCosts, $toppingCosts, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function closestCost(baseCosts: number[], toppingCosts: number[], target: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (closest-cost baseCosts toppingCosts target)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1774](https://leetcode-cn.com/problems/closest-dessert-cost)", "[\u6700\u63a5\u8fd1\u76ee\u6807\u4ef7\u683c\u7684\u751c\u70b9\u6210\u672c](/solution/1700-1799/1774.Closest%20Dessert%20Cost/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1774](https://leetcode.com/problems/closest-dessert-cost)", "[Closest Dessert Cost](/solution/1700-1799/1774.Closest%20Dessert%20Cost/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1899", "frontend_question_id": "1773", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-items-matching-a-rule", "url_en": "https://leetcode.com/problems/count-items-matching-a-rule", "relative_path_cn": "/solution/1700-1799/1773.Count%20Items%20Matching%20a%20Rule/README.md", "relative_path_en": "/solution/1700-1799/1773.Count%20Items%20Matching%20a%20Rule/README_EN.md", "title_cn": "\u7edf\u8ba1\u5339\u914d\u68c0\u7d22\u89c4\u5219\u7684\u7269\u54c1\u6570\u91cf", "title_en": "Count Items Matching a Rule", "question_title_slug": "count-items-matching-a-rule", "content_en": "

    You are given an array items, where each items[i] = [typei, colori, namei] describes the type, color, and name of the ith item. You are also given a rule represented by two strings, ruleKey and ruleValue.

    \n\n

    The ith item is said to match the rule if one of the following is true:

    \n\n
      \n\t
    • ruleKey == "type" and ruleValue == typei.
    • \n\t
    • ruleKey == "color" and ruleValue == colori.
    • \n\t
    • ruleKey == "name" and ruleValue == namei.
    • \n
    \n\n

    Return the number of items that match the given rule.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: items = [["phone","blue","pixel"],["computer","silver","lenovo"],["phone","gold","iphone"]], ruleKey = "color", ruleValue = "silver"\nOutput: 1\nExplanation: There is only one item matching the given rule, which is ["computer","silver","lenovo"].\n
    \n\n

    Example 2:

    \n\n
    \nInput: items = [["phone","blue","pixel"],["computer","silver","phone"],["phone","gold","iphone"]], ruleKey = "type", ruleValue = "phone"\nOutput: 2\nExplanation: There are only two items matching the given rule, which are ["phone","blue","pixel"] and ["phone","gold","iphone"]. Note that the item ["computer","silver","phone"] does not match.
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= items.length <= 104
    • \n\t
    • 1 <= typei.length, colori.length, namei.length, ruleValue.length <= 10
    • \n\t
    • ruleKey is equal to either "type", "color", or "name".
    • \n\t
    • All strings consist only of lowercase letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 items \uff0c\u5176\u4e2d\u00a0items[i] = [typei, colori, namei] \uff0c\u63cf\u8ff0\u7b2c i \u4ef6\u7269\u54c1\u7684\u7c7b\u578b\u3001\u989c\u8272\u4ee5\u53ca\u540d\u79f0\u3002

    \n\n

    \u53e6\u7ed9\u4f60\u4e00\u6761\u7531\u4e24\u4e2a\u5b57\u7b26\u4e32\u00a0ruleKey \u548c ruleValue \u8868\u793a\u7684\u68c0\u7d22\u89c4\u5219\u3002

    \n\n

    \u5982\u679c\u7b2c i \u4ef6\u7269\u54c1\u80fd\u6ee1\u8db3\u4e0b\u8ff0\u6761\u4ef6\u4e4b\u4e00\uff0c\u5219\u8ba4\u4e3a\u8be5\u7269\u54c1\u4e0e\u7ed9\u5b9a\u7684\u68c0\u7d22\u89c4\u5219 \u5339\u914d \uff1a

    \n\n
      \n\t
    • ruleKey == \"type\" \u4e14 ruleValue == typei \u3002
    • \n\t
    • ruleKey == \"color\" \u4e14 ruleValue == colori \u3002
    • \n\t
    • ruleKey == \"name\" \u4e14 ruleValue == namei \u3002
    • \n
    \n\n

    \u7edf\u8ba1\u5e76\u8fd4\u56de \u5339\u914d\u68c0\u7d22\u89c4\u5219\u7684\u7269\u54c1\u6570\u91cf \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aitems = [[\"phone\",\"blue\",\"pixel\"],[\"computer\",\"silver\",\"lenovo\"],[\"phone\",\"gold\",\"iphone\"]], ruleKey = \"color\", ruleValue = \"silver\"\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u53ea\u6709\u4e00\u4ef6\u7269\u54c1\u5339\u914d\u68c0\u7d22\u89c4\u5219\uff0c\u8fd9\u4ef6\u7269\u54c1\u662f [\"computer\",\"silver\",\"lenovo\"] \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aitems = [[\"phone\",\"blue\",\"pixel\"],[\"computer\",\"silver\",\"phone\"],[\"phone\",\"gold\",\"iphone\"]], ruleKey = \"type\", ruleValue = \"phone\"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u53ea\u6709\u4e24\u4ef6\u7269\u54c1\u5339\u914d\u68c0\u7d22\u89c4\u5219\uff0c\u8fd9\u4e24\u4ef6\u7269\u54c1\u5206\u522b\u662f [\"phone\",\"blue\",\"pixel\"] \u548c [\"phone\",\"gold\",\"iphone\"] \u3002\u6ce8\u610f\uff0c[\"computer\",\"silver\",\"phone\"] \u672a\u5339\u914d\u68c0\u7d22\u89c4\u5219\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= items.length <= 104
    • \n\t
    • 1 <= typei.length, colori.length, namei.length, ruleValue.length <= 10
    • \n\t
    • ruleKey \u7b49\u4e8e \"type\"\u3001\"color\" \u6216 \"name\"
    • \n\t
    • \u6240\u6709\u5b57\u7b26\u4e32\u4ec5\u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n", "tags_en": ["Array", "String"], "tags_cn": ["\u6570\u7ec4", "\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countMatches(vector>& items, string ruleKey, string ruleValue) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countMatches(List> items, String ruleKey, String ruleValue) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countMatches(self, items, ruleKey, ruleValue):\n \"\"\"\n :type items: List[List[str]]\n :type ruleKey: str\n :type ruleValue: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countMatches(self, items: List[List[str]], ruleKey: str, ruleValue: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countMatches(char *** items, int itemsSize, int* itemsColSize, char * ruleKey, char * ruleValue){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountMatches(IList> items, string ruleKey, string ruleValue) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[][]} items\n * @param {string} ruleKey\n * @param {string} ruleValue\n * @return {number}\n */\nvar countMatches = function(items, ruleKey, ruleValue) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[][]} items\n# @param {String} rule_key\n# @param {String} rule_value\n# @return {Integer}\ndef count_matches(items, rule_key, rule_value)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countMatches(_ items: [[String]], _ ruleKey: String, _ ruleValue: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countMatches(items [][]string, ruleKey string, ruleValue string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countMatches(items: List[List[String]], ruleKey: String, ruleValue: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countMatches(items: List>, ruleKey: String, ruleValue: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_matches(items: Vec>, rule_key: String, rule_value: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $items\n * @param String $ruleKey\n * @param String $ruleValue\n * @return Integer\n */\n function countMatches($items, $ruleKey, $ruleValue) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countMatches(items: string[][], ruleKey: string, ruleValue: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-matches items ruleKey ruleValue)\n (-> (listof (listof string?)) string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1773](https://leetcode-cn.com/problems/count-items-matching-a-rule)", "[\u7edf\u8ba1\u5339\u914d\u68c0\u7d22\u89c4\u5219\u7684\u7269\u54c1\u6570\u91cf](/solution/1700-1799/1773.Count%20Items%20Matching%20a%20Rule/README.md)", "`\u6570\u7ec4`,`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1773](https://leetcode.com/problems/count-items-matching-a-rule)", "[Count Items Matching a Rule](/solution/1700-1799/1773.Count%20Items%20Matching%20a%20Rule/README_EN.md)", "`Array`,`String`", "Easy", ""]}, {"question_id": "1898", "frontend_question_id": "1747", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/leetflex-banned-accounts", "url_en": "https://leetcode.com/problems/leetflex-banned-accounts", "relative_path_cn": "/solution/1700-1799/1747.Leetflex%20Banned%20Accounts/README.md", "relative_path_en": "/solution/1700-1799/1747.Leetflex%20Banned%20Accounts/README_EN.md", "title_cn": "\u5e94\u8be5\u88ab\u7981\u6b62\u7684Leetflex\u8d26\u6237", "title_en": "Leetflex Banned Accounts", "question_title_slug": "leetflex-banned-accounts", "content_en": "

    Table: LogInfo

    \r\n\r\n
    \r\n+-------------+----------+\r\n| Column Name | Type     |\r\n+-------------+----------+\r\n| account_id  | int      |\r\n| ip_address  | int      |\r\n| login       | datetime |\r\n| logout      | datetime |\r\n+-------------+----------+\r\nThere is no primary key for this table, and it may contain duplicates.\r\nThe table contains information about the login and logout dates of Leetflex accounts. It also contains the IP address from which the account logged in and out.\r\nIt is guaranteed that the logout time is after the login time.\r\n
    \r\n\r\n

     

    \r\n\r\n

    Write an SQL query to find the account_id of the accounts that should be banned from Leetflex. An account should be banned if it was logged in at some moment from two different IP addresses.

    \r\n\r\n

    Return the result table in any order.

    \r\n\r\n

    The query result format is in the following example:

    \r\n\r\n

     

    \r\n\r\n
    \r\nLogInfo table:\r\n+------------+------------+---------------------+---------------------+\r\n| account_id | ip_address | login               | logout              |\r\n+------------+------------+---------------------+---------------------+\r\n| 1          | 1          | 2021-02-01 09:00:00 | 2021-02-01 09:30:00 |\r\n| 1          | 2          | 2021-02-01 08:00:00 | 2021-02-01 11:30:00 |\r\n| 2          | 6          | 2021-02-01 20:30:00 | 2021-02-01 22:00:00 |\r\n| 2          | 7          | 2021-02-02 20:30:00 | 2021-02-02 22:00:00 |\r\n| 3          | 9          | 2021-02-01 16:00:00 | 2021-02-01 16:59:59 |\r\n| 3          | 13         | 2021-02-01 17:00:00 | 2021-02-01 17:59:59 |\r\n| 4          | 10         | 2021-02-01 16:00:00 | 2021-02-01 17:00:00 |\r\n| 4          | 11         | 2021-02-01 17:00:00 | 2021-02-01 17:59:59 |\r\n+------------+------------+---------------------+---------------------+\r\n\r\nResult table:\r\n+------------+\r\n| account_id |\r\n+------------+\r\n| 1          |\r\n| 4          |\r\n+------------+\r\nAccount ID 1 --> The account was active from "2021-02-01 09:00:00" to "2021-02-01 09:30:00" with two different IP addresses (1 and 2). It should be banned.\r\nAccount ID 2 --> The account was active from two different addresses (6, 7) but in two different times.\r\nAccount ID 3 --> The account was active from two different addresses (9, 13) on the same day but they do not intersect at any moment.\r\nAccount ID 4 --> The account was active from "2021-02-01 17:00:00" to "2021-02-01 17:00:00" with two different IP addresses (10 and 11). It should be banned.\r\n
    ", "content_cn": "

    \u8868: LogInfo

    \n\n
    +-------------+----------+\n| Column Name | Type     |\n+-------------+----------+\n| account_id  | int      |\n| ip_address  | int      |\n| login       | datetime |\n| logout      | datetime |\n+-------------+----------+\n\u8be5\u8868\u662f\u6ca1\u6709\u4e3b\u952e\u7684\uff0c\u5b83\u53ef\u80fd\u5305\u542b\u91cd\u590d\u9879\u3002\n\u8be5\u8868\u5305\u542b\u6709\u5173Leetflex\u5e10\u6237\u7684\u767b\u5f55\u548c\u6ce8\u9500\u65e5\u671f\u7684\u4fe1\u606f\u3002 \u5b83\u8fd8\u5305\u542b\u4e86\u8be5\u8d26\u6237\u7528\u4e8e\u767b\u5f55\u548c\u6ce8\u9500\u7684\u7f51\u7edc\u5730\u5740\u7684\u4fe1\u606f\u3002\n\u9898\u76ee\u786e\u4fdd\u6bcf\u4e00\u4e2a\u6ce8\u9500\u65f6\u95f4\u90fd\u5728\u767b\u5f55\u65f6\u95f4\u4e4b\u540e\u3002\n
    \n\n

    \u00a0

    \n\n

    \u7f16\u5199\u4e00\u4e2aSQL\u67e5\u8be2\u8bed\u53e5\uff0c\u67e5\u627e\u90a3\u4e9b\u5e94\u8be5\u88ab\u7981\u6b62\u7684Leetflex\u5e10\u6237\u7f16\u53f7account_id\u3002 \u5982\u679c\u67d0\u4e2a\u5e10\u6237\u5728\u67d0\u4e00\u65f6\u523b\u4ece\u4e24\u4e2a\u4e0d\u540c\u7684\u7f51\u7edc\u5730\u5740\u767b\u5f55\u4e86\uff0c\u5219\u8fd9\u4e2a\u5e10\u6237\u5e94\u8be5\u88ab\u7981\u6b62\u3002

    \n\n

    \u53ef\u4ee5\u4ee5\u4efb\u4f55\u987a\u5e8f\u8fd4\u56de\u7ed3\u679c\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a:

    \n\n

    \u00a0

    \n\n
    LogInfo table:\n+------------+------------+---------------------+---------------------+\n| account_id | ip_address | login               | logout              |\n+------------+------------+---------------------+---------------------+\n| 1          | 1          | 2021-02-01 09:00:00 | 2021-02-01 09:30:00 |\n| 1          | 2          | 2021-02-01 08:00:00 | 2021-02-01 11:30:00 |\n| 2          | 6          | 2021-02-01 20:30:00 | 2021-02-01 22:00:00 |\n| 2          | 7          | 2021-02-02 20:30:00 | 2021-02-02 22:00:00 |\n| 3          | 9          | 2021-02-01 16:00:00 | 2021-02-01 16:59:59 |\n| 3          | 13         | 2021-02-01 17:00:00 | 2021-02-01 17:59:59 |\n| 4          | 10         | 2021-02-01 16:00:00 | 2021-02-01 17:00:00 |\n| 4          | 11         | 2021-02-01 17:00:00 | 2021-02-01 17:59:59 |\n+------------+------------+---------------------+---------------------+\n\nResult table:\n+------------+\n| account_id |\n+------------+\n| 1          |\n| 4          |\n+------------+\nAccount ID 1 --> \u8be5\u8d26\u6237\u4ece \"2021-02-01 09:00:00\" \u5230 \"2021-02-01 09:30:00\" \u5728\u4e24\u4e2a\u4e0d\u540c\u7684\u7f51\u7edc\u5730\u5740(1 and 2)\u4e0a\u6fc0\u6d3b\u4e86\u3002\u5b83\u5e94\u8be5\u88ab\u7981\u6b62.\nAccount ID 2 --> \u8be5\u8d26\u6237\u5728\u4e24\u4e2a\u4e0d\u540c\u7684\u7f51\u7edc\u5730\u5740 (6, 7) \u6fc0\u6d3b\u4e86\uff0c\u4f46\u5728\u4e0d\u540c\u7684\u65f6\u95f4\u4e0a.\nAccount ID 3 --> \u8be5\u8d26\u6237\u5728\u4e24\u4e2a\u4e0d\u540c\u7684\u7f51\u7edc\u5730\u5740 (9, 13) \u6fc0\u6d3b\u4e86\uff0c\u867d\u7136\u662f\u540c\u4e00\u5929\uff0c\u4f46\u65f6\u95f4\u4e0a\u6ca1\u6709\u4ea4\u96c6.\nAccount ID 4 --> \u8be5\u8d26\u6237\u4ece \"2021-02-01 17:00:00\" \u5230 \"2021-02-01 17:00:00\" \u5728\u4e24\u4e2a\u4e0d\u540c\u7684\u7f51\u7edc\u5730\u5740 (10 and 11)\u4e0a\u6fc0\u6d3b\u4e86\u3002\u5b83\u5e94\u8be5\u88ab\u7981\u6b62.\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1747](https://leetcode-cn.com/problems/leetflex-banned-accounts)", "[\u5e94\u8be5\u88ab\u7981\u6b62\u7684Leetflex\u8d26\u6237](/solution/1700-1799/1747.Leetflex%20Banned%20Accounts/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1747](https://leetcode.com/problems/leetflex-banned-accounts)", "[Leetflex Banned Accounts](/solution/1700-1799/1747.Leetflex%20Banned%20Accounts/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1897", "frontend_question_id": "1771", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximize-palindrome-length-from-subsequences", "url_en": "https://leetcode.com/problems/maximize-palindrome-length-from-subsequences", "relative_path_cn": "/solution/1700-1799/1771.Maximize%20Palindrome%20Length%20From%20Subsequences/README.md", "relative_path_en": "/solution/1700-1799/1771.Maximize%20Palindrome%20Length%20From%20Subsequences/README_EN.md", "title_cn": "\u7531\u5b50\u5e8f\u5217\u6784\u9020\u7684\u6700\u957f\u56de\u6587\u4e32\u7684\u957f\u5ea6", "title_en": "Maximize Palindrome Length From Subsequences", "question_title_slug": "maximize-palindrome-length-from-subsequences", "content_en": "

    You are given two strings, word1 and word2. You want to construct a string in the following manner:

    \n\n
      \n\t
    • Choose some non-empty subsequence subsequence1 from word1.
    • \n\t
    • Choose some non-empty subsequence subsequence2 from word2.
    • \n\t
    • Concatenate the subsequences: subsequence1 + subsequence2, to make the string.
    • \n
    \n\n

    Return the length of the longest palindrome that can be constructed in the described manner. If no palindromes can be constructed, return 0.

    \n\n

    A subsequence of a string s is a string that can be made by deleting some (possibly none) characters from s without changing the order of the remaining characters.

    \n\n

    A palindrome is a string that reads the same forward as well as backward.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: word1 = "cacb", word2 = "cbba"\nOutput: 5\nExplanation: Choose "ab" from word1 and "cba" from word2 to make "abcba", which is a palindrome.
    \n\n

    Example 2:

    \n\n
    \nInput: word1 = "ab", word2 = "ab"\nOutput: 3\nExplanation: Choose "ab" from word1 and "a" from word2 to make "aba", which is a palindrome.
    \n\n

    Example 3:

    \n\n
    \nInput: word1 = "aa", word2 = "bb"\nOutput: 0\nExplanation: You cannot construct a palindrome from the described method, so return 0.
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= word1.length, word2.length <= 1000
    • \n\t
    • word1 and word2 consist of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u5b57\u7b26\u4e32 word1 \u548c word2 \uff0c\u8bf7\u4f60\u6309\u4e0b\u8ff0\u65b9\u6cd5\u6784\u9020\u4e00\u4e2a\u5b57\u7b26\u4e32\uff1a

    \n\n
      \n\t
    • \u4ece word1 \u4e2d\u9009\u51fa\u67d0\u4e2a \u975e\u7a7a \u5b50\u5e8f\u5217 subsequence1 \u3002
    • \n\t
    • \u4ece word2 \u4e2d\u9009\u51fa\u67d0\u4e2a \u975e\u7a7a \u5b50\u5e8f\u5217 subsequence2 \u3002
    • \n\t
    • \u8fde\u63a5\u4e24\u4e2a\u5b50\u5e8f\u5217 subsequence1 + subsequence2 \uff0c\u5f97\u5230\u5b57\u7b26\u4e32\u3002
    • \n
    \n\n

    \u8fd4\u56de\u53ef\u6309\u4e0a\u8ff0\u65b9\u6cd5\u6784\u9020\u7684\u6700\u957f \u56de\u6587\u4e32 \u7684 \u957f\u5ea6 \u3002\u5982\u679c\u65e0\u6cd5\u6784\u9020\u56de\u6587\u4e32\uff0c\u8fd4\u56de 0 \u3002

    \n\n

    \u5b57\u7b26\u4e32 s \u7684\u4e00\u4e2a \u5b50\u5e8f\u5217 \u662f\u901a\u8fc7\u4ece s \u4e2d\u5220\u9664\u4e00\u4e9b\uff08\u4e5f\u53ef\u80fd\u4e0d\u5220\u9664\uff09\u5b57\u7b26\u800c\u4e0d\u66f4\u6539\u5176\u4f59\u5b57\u7b26\u7684\u987a\u5e8f\u751f\u6210\u7684\u5b57\u7b26\u4e32\u3002

    \n\n

    \u56de\u6587\u4e32 \u662f\u6b63\u7740\u8bfb\u548c\u53cd\u7740\u8bfb\u7ed3\u679c\u4e00\u81f4\u7684\u5b57\u7b26\u4e32\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aword1 = \"cacb\", word2 = \"cbba\"\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u4ece word1 \u4e2d\u9009\u51fa \"ab\" \uff0c\u4ece word2 \u4e2d\u9009\u51fa \"cba\" \uff0c\u5f97\u5230\u56de\u6587\u4e32 \"abcba\" \u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aword1 = \"ab\", word2 = \"ab\"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u4ece word1 \u4e2d\u9009\u51fa \"ab\" \uff0c\u4ece word2 \u4e2d\u9009\u51fa \"a\" \uff0c\u5f97\u5230\u56de\u6587\u4e32 \"aba\" \u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aword1 = \"aa\", word2 = \"bb\"\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u65e0\u6cd5\u6309\u9898\u9762\u6240\u8ff0\u65b9\u6cd5\u6784\u9020\u56de\u6587\u4e32\uff0c\u6240\u4ee5\u8fd4\u56de 0 \u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= word1.length, word2.length <= 1000
    • \n\t
    • word1 \u548c word2 \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int longestPalindrome(string word1, string word2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int longestPalindrome(String word1, String word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestPalindrome(self, word1, word2):\n \"\"\"\n :type word1: str\n :type word2: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestPalindrome(self, word1: str, word2: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint longestPalindrome(char * word1, char * word2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LongestPalindrome(string word1, string word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} word1\n * @param {string} word2\n * @return {number}\n */\nvar longestPalindrome = function(word1, word2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} word1\n# @param {String} word2\n# @return {Integer}\ndef longest_palindrome(word1, word2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestPalindrome(_ word1: String, _ word2: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestPalindrome(word1 string, word2 string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestPalindrome(word1: String, word2: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestPalindrome(word1: String, word2: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_palindrome(word1: String, word2: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $word1\n * @param String $word2\n * @return Integer\n */\n function longestPalindrome($word1, $word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestPalindrome(word1: string, word2: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-palindrome word1 word2)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1771](https://leetcode-cn.com/problems/maximize-palindrome-length-from-subsequences)", "[\u7531\u5b50\u5e8f\u5217\u6784\u9020\u7684\u6700\u957f\u56de\u6587\u4e32\u7684\u957f\u5ea6](/solution/1700-1799/1771.Maximize%20Palindrome%20Length%20From%20Subsequences/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1771](https://leetcode.com/problems/maximize-palindrome-length-from-subsequences)", "[Maximize Palindrome Length From Subsequences](/solution/1700-1799/1771.Maximize%20Palindrome%20Length%20From%20Subsequences/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1896", "frontend_question_id": "1770", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-score-from-performing-multiplication-operations", "url_en": "https://leetcode.com/problems/maximum-score-from-performing-multiplication-operations", "relative_path_cn": "/solution/1700-1799/1770.Maximum%20Score%20from%20Performing%20Multiplication%20Operations/README.md", "relative_path_en": "/solution/1700-1799/1770.Maximum%20Score%20from%20Performing%20Multiplication%20Operations/README_EN.md", "title_cn": "\u6267\u884c\u4e58\u6cd5\u8fd0\u7b97\u7684\u6700\u5927\u5206\u6570", "title_en": "Maximum Score from Performing Multiplication Operations", "question_title_slug": "maximum-score-from-performing-multiplication-operations", "content_en": "

    You are given two integer arrays nums and multipliers of size n and m respectively, where n >= m. The arrays are 1-indexed.

    \n\n

    You begin with a score of 0. You want to perform exactly m operations. On the ith operation (1-indexed), you will:

    \n\n
      \n\t
    • Choose one integer x from either the start or the end of the array nums.
    • \n\t
    • Add multipliers[i] * x to your score.
    • \n\t
    • Remove x from the array nums.
    • \n
    \n\n

    Return the maximum score after performing m operations.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,3], multipliers = [3,2,1]\nOutput: 14\nExplanation: An optimal solution is as follows:\n- Choose from the end, [1,2,3], adding 3 * 3 = 9 to the score.\n- Choose from the end, [1,2], adding 2 * 2 = 4 to the score.\n- Choose from the end, [1], adding 1 * 1 = 1 to the score.\nThe total score is 9 + 4 + 1 = 14.
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [-5,-3,-3,-2,7,1], multipliers = [-10,-5,3,4,6]\nOutput: 102\nExplanation: An optimal solution is as follows:\n- Choose from the start, [-5,-3,-3,-2,7,1], adding -5 * -10 = 50 to the score.\n- Choose from the start, [-3,-3,-2,7,1], adding -3 * -5 = 15 to the score.\n- Choose from the start, [-3,-2,7,1], adding -3 * 3 = -9 to the score.\n- Choose from the end, [-2,7,1], adding 1 * 4 = 4 to the score.\n- Choose from the end, [-2,7], adding 7 * 6 = 42 to the score. \nThe total score is 50 + 15 - 9 + 4 + 42 = 102.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • m == multipliers.length
    • \n\t
    • 1 <= m <= 103
    • \n\t
    • m <= n <= 105
    • \n\t
    • -1000 <= nums[i], multipliers[i] <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u957f\u5ea6\u5206\u522b n \u548c m \u7684\u6574\u6570\u6570\u7ec4 nums \u548c multipliers \uff0c\u5176\u4e2d n >= m \uff0c\u6570\u7ec4\u4e0b\u6807 \u4ece 1 \u5f00\u59cb \u8ba1\u6570\u3002

    \n\n

    \u521d\u59cb\u65f6\uff0c\u4f60\u7684\u5206\u6570\u4e3a 0 \u3002\u4f60\u9700\u8981\u6267\u884c\u6070\u597d m \u6b65\u64cd\u4f5c\u3002\u5728\u7b2c i \u6b65\u64cd\u4f5c\uff08\u4ece 1 \u5f00\u59cb \u8ba1\u6570\uff09\u4e2d\uff0c\u9700\u8981\uff1a

    \n\n
      \n\t
    • \u9009\u62e9\u6570\u7ec4 nums \u5f00\u5934\u5904\u6216\u8005\u672b\u5c3e\u5904 \u7684\u6574\u6570 x \u3002
    • \n\t
    • \u4f60\u83b7\u5f97 multipliers[i] * x \u5206\uff0c\u5e76\u7d2f\u52a0\u5230\u4f60\u7684\u5206\u6570\u4e2d\u3002
    • \n\t
    • \u5c06 x \u4ece\u6570\u7ec4 nums \u4e2d\u79fb\u9664\u3002
    • \n
    \n\n

    \u5728\u6267\u884c m \u6b65\u64cd\u4f5c\u540e\uff0c\u8fd4\u56de \u6700\u5927 \u5206\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,2,3], multipliers = [3,2,1]\n\u8f93\u51fa\uff1a14\n\u89e3\u91ca\uff1a\u4e00\u79cd\u6700\u4f18\u89e3\u51b3\u65b9\u6848\u5982\u4e0b\uff1a\n- \u9009\u62e9\u672b\u5c3e\u5904\u7684\u6574\u6570 3 \uff0c[1,2,3] \uff0c\u5f97 3 * 3 = 9 \u5206\uff0c\u7d2f\u52a0\u5230\u5206\u6570\u4e2d\u3002\n- \u9009\u62e9\u672b\u5c3e\u5904\u7684\u6574\u6570 2 \uff0c[1,2] \uff0c\u5f97 2 * 2 = 4 \u5206\uff0c\u7d2f\u52a0\u5230\u5206\u6570\u4e2d\u3002\n- \u9009\u62e9\u672b\u5c3e\u5904\u7684\u6574\u6570 1 \uff0c[1] \uff0c\u5f97 1 * 1 = 1 \u5206\uff0c\u7d2f\u52a0\u5230\u5206\u6570\u4e2d\u3002\n\u603b\u5206\u6570\u4e3a 9 + 4 + 1 = 14 \u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [-5,-3,-3,-2,7,1], multipliers = [-10,-5,3,4,6]\n\u8f93\u51fa\uff1a102\n\u89e3\u91ca\uff1a\u4e00\u79cd\u6700\u4f18\u89e3\u51b3\u65b9\u6848\u5982\u4e0b\uff1a\n- \u9009\u62e9\u5f00\u5934\u5904\u7684\u6574\u6570 -5 \uff0c[-5,-3,-3,-2,7,1] \uff0c\u5f97 -5 * -10 = 50 \u5206\uff0c\u7d2f\u52a0\u5230\u5206\u6570\u4e2d\u3002\n- \u9009\u62e9\u5f00\u5934\u5904\u7684\u6574\u6570 -3 \uff0c[-3,-3,-2,7,1] \uff0c\u5f97 -3 * -5 = 15 \u5206\uff0c\u7d2f\u52a0\u5230\u5206\u6570\u4e2d\u3002\n- \u9009\u62e9\u5f00\u5934\u5904\u7684\u6574\u6570 -3 \uff0c[-3,-2,7,1] \uff0c\u5f97 -3 * 3 = -9 \u5206\uff0c\u7d2f\u52a0\u5230\u5206\u6570\u4e2d\u3002\n- \u9009\u62e9\u672b\u5c3e\u5904\u7684\u6574\u6570 1 \uff0c[-2,7,1] \uff0c\u5f97 1 * 4 = 4 \u5206\uff0c\u7d2f\u52a0\u5230\u5206\u6570\u4e2d\u3002\n- \u9009\u62e9\u672b\u5c3e\u5904\u7684\u6574\u6570 7 \uff0c[-2,7] \uff0c\u5f97 7 * 6 = 42 \u5206\uff0c\u7d2f\u52a0\u5230\u5206\u6570\u4e2d\u3002\n\u603b\u5206\u6570\u4e3a 50 + 15 - 9 + 4 + 42 = 102 \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • m == multipliers.length
    • \n\t
    • 1 <= m <= 103
    • \n\t
    • m <= n <= 105
    • \n\t
    • -1000 <= nums[i], multipliers[i] <= 1000
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maximumScore(vector& nums, vector& multipliers) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maximumScore(int[] nums, int[] multipliers) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximumScore(self, nums, multipliers):\n \"\"\"\n :type nums: List[int]\n :type multipliers: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximumScore(self, nums: List[int], multipliers: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maximumScore(int* nums, int numsSize, int* multipliers, int multipliersSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaximumScore(int[] nums, int[] multipliers) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number[]} multipliers\n * @return {number}\n */\nvar maximumScore = function(nums, multipliers) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer[]} multipliers\n# @return {Integer}\ndef maximum_score(nums, multipliers)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximumScore(_ nums: [Int], _ multipliers: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximumScore(nums []int, multipliers []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximumScore(nums: Array[Int], multipliers: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximumScore(nums: IntArray, multipliers: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximum_score(nums: Vec, multipliers: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer[] $multipliers\n * @return Integer\n */\n function maximumScore($nums, $multipliers) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximumScore(nums: number[], multipliers: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximum-score nums multipliers)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1770](https://leetcode-cn.com/problems/maximum-score-from-performing-multiplication-operations)", "[\u6267\u884c\u4e58\u6cd5\u8fd0\u7b97\u7684\u6700\u5927\u5206\u6570](/solution/1700-1799/1770.Maximum%20Score%20from%20Performing%20Multiplication%20Operations/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1770](https://leetcode.com/problems/maximum-score-from-performing-multiplication-operations)", "[Maximum Score from Performing Multiplication Operations](/solution/1700-1799/1770.Maximum%20Score%20from%20Performing%20Multiplication%20Operations/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "1895", "frontend_question_id": "1769", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-number-of-operations-to-move-all-balls-to-each-box", "url_en": "https://leetcode.com/problems/minimum-number-of-operations-to-move-all-balls-to-each-box", "relative_path_cn": "/solution/1700-1799/1769.Minimum%20Number%20of%20Operations%20to%20Move%20All%20Balls%20to%20Each%20Box/README.md", "relative_path_en": "/solution/1700-1799/1769.Minimum%20Number%20of%20Operations%20to%20Move%20All%20Balls%20to%20Each%20Box/README_EN.md", "title_cn": "\u79fb\u52a8\u6240\u6709\u7403\u5230\u6bcf\u4e2a\u76d2\u5b50\u6240\u9700\u7684\u6700\u5c0f\u64cd\u4f5c\u6570", "title_en": "Minimum Number of Operations to Move All Balls to Each Box", "question_title_slug": "minimum-number-of-operations-to-move-all-balls-to-each-box", "content_en": "

    You have n boxes. You are given a binary string boxes of length n, where boxes[i] is '0' if the ith box is empty, and '1' if it contains one ball.

    \n\n

    In one operation, you can move one ball from a box to an adjacent box. Box i is adjacent to box j if abs(i - j) == 1. Note that after doing so, there may be more than one ball in some boxes.

    \n\n

    Return an array answer of size n, where answer[i] is the minimum number of operations needed to move all the balls to the ith box.

    \n\n

    Each answer[i] is calculated considering the initial state of the boxes.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: boxes = "110"\nOutput: [1,1,3]\nExplanation: The answer for each box is as follows:\n1) First box: you will have to move one ball from the second box to the first box in one operation.\n2) Second box: you will have to move one ball from the first box to the second box in one operation.\n3) Third box: you will have to move one ball from the first box to the third box in two operations, and move one ball from the second box to the third box in one operation.\n
    \n\n

    Example 2:

    \n\n
    \nInput: boxes = "001011"\nOutput: [11,8,5,4,3,4]
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == boxes.length
    • \n\t
    • 1 <= n <= 2000
    • \n\t
    • boxes[i] is either '0' or '1'.
    • \n
    \n", "content_cn": "

    \u6709 n \u4e2a\u76d2\u5b50\u3002\u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32 boxes \uff0c\u5176\u4e2d boxes[i] \u7684\u503c\u4e3a '0' \u8868\u793a\u7b2c i \u4e2a\u76d2\u5b50\u662f \u7a7a \u7684\uff0c\u800c boxes[i] \u7684\u503c\u4e3a '1' \u8868\u793a\u76d2\u5b50\u91cc\u6709 \u4e00\u4e2a \u5c0f\u7403\u3002

    \n\n

    \u5728\u4e00\u6b65\u64cd\u4f5c\u4e2d\uff0c\u4f60\u53ef\u4ee5\u5c06 \u4e00\u4e2a \u5c0f\u7403\u4ece\u67d0\u4e2a\u76d2\u5b50\u79fb\u52a8\u5230\u4e00\u4e2a\u4e0e\u4e4b\u76f8\u90bb\u7684\u76d2\u5b50\u4e2d\u3002\u7b2c i \u4e2a\u76d2\u5b50\u548c\u7b2c j \u4e2a\u76d2\u5b50\u76f8\u90bb\u9700\u6ee1\u8db3 abs(i - j) == 1 \u3002\u6ce8\u610f\uff0c\u64cd\u4f5c\u6267\u884c\u540e\uff0c\u67d0\u4e9b\u76d2\u5b50\u4e2d\u53ef\u80fd\u4f1a\u5b58\u5728\u4e0d\u6b62\u4e00\u4e2a\u5c0f\u7403\u3002

    \n\n

    \u8fd4\u56de\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u6570\u7ec4 answer \uff0c\u5176\u4e2d answer[i] \u662f\u5c06\u6240\u6709\u5c0f\u7403\u79fb\u52a8\u5230\u7b2c i \u4e2a\u76d2\u5b50\u6240\u9700\u7684 \u6700\u5c0f \u64cd\u4f5c\u6570\u3002

    \n\n

    \u6bcf\u4e2a answer[i] \u90fd\u9700\u8981\u6839\u636e\u76d2\u5b50\u7684 \u521d\u59cb\u72b6\u6001 \u8fdb\u884c\u8ba1\u7b97\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aboxes = \"110\"\n\u8f93\u51fa\uff1a[1,1,3]\n\u89e3\u91ca\uff1a\u6bcf\u4e2a\u76d2\u5b50\u5bf9\u5e94\u7684\u6700\u5c0f\u64cd\u4f5c\u6570\u5982\u4e0b\uff1a\n1) \u7b2c 1 \u4e2a\u76d2\u5b50\uff1a\u5c06\u4e00\u4e2a\u5c0f\u7403\u4ece\u7b2c 2 \u4e2a\u76d2\u5b50\u79fb\u52a8\u5230\u7b2c 1 \u4e2a\u76d2\u5b50\uff0c\u9700\u8981 1 \u6b65\u64cd\u4f5c\u3002\n2) \u7b2c 2 \u4e2a\u76d2\u5b50\uff1a\u5c06\u4e00\u4e2a\u5c0f\u7403\u4ece\u7b2c 1 \u4e2a\u76d2\u5b50\u79fb\u52a8\u5230\u7b2c 2 \u4e2a\u76d2\u5b50\uff0c\u9700\u8981 1 \u6b65\u64cd\u4f5c\u3002\n3) \u7b2c 3 \u4e2a\u76d2\u5b50\uff1a\u5c06\u4e00\u4e2a\u5c0f\u7403\u4ece\u7b2c 1 \u4e2a\u76d2\u5b50\u79fb\u52a8\u5230\u7b2c 3 \u4e2a\u76d2\u5b50\uff0c\u9700\u8981 2 \u6b65\u64cd\u4f5c\u3002\u5c06\u4e00\u4e2a\u5c0f\u7403\u4ece\u7b2c 2 \u4e2a\u76d2\u5b50\u79fb\u52a8\u5230\u7b2c 3 \u4e2a\u76d2\u5b50\uff0c\u9700\u8981 1 \u6b65\u64cd\u4f5c\u3002\u5171\u8ba1 3 \u6b65\u64cd\u4f5c\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aboxes = \"001011\"\n\u8f93\u51fa\uff1a[11,8,5,4,3,4]
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == boxes.length
    • \n\t
    • 1 <= n <= 2000
    • \n\t
    • boxes[i] \u4e3a '0' \u6216 '1'
    • \n
    \n", "tags_en": ["Greedy", "Array"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector minOperations(string boxes) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] minOperations(String boxes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minOperations(self, boxes):\n \"\"\"\n :type boxes: str\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minOperations(self, boxes: str) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* minOperations(char * boxes, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] MinOperations(string boxes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} boxes\n * @return {number[]}\n */\nvar minOperations = function(boxes) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} boxes\n# @return {Integer[]}\ndef min_operations(boxes)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minOperations(_ boxes: String) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minOperations(boxes string) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minOperations(boxes: String): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minOperations(boxes: String): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_operations(boxes: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $boxes\n * @return Integer[]\n */\n function minOperations($boxes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minOperations(boxes: string): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-operations boxes)\n (-> string? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1769](https://leetcode-cn.com/problems/minimum-number-of-operations-to-move-all-balls-to-each-box)", "[\u79fb\u52a8\u6240\u6709\u7403\u5230\u6bcf\u4e2a\u76d2\u5b50\u6240\u9700\u7684\u6700\u5c0f\u64cd\u4f5c\u6570](/solution/1700-1799/1769.Minimum%20Number%20of%20Operations%20to%20Move%20All%20Balls%20to%20Each%20Box/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1769](https://leetcode.com/problems/minimum-number-of-operations-to-move-all-balls-to-each-box)", "[Minimum Number of Operations to Move All Balls to Each Box](/solution/1700-1799/1769.Minimum%20Number%20of%20Operations%20to%20Move%20All%20Balls%20to%20Each%20Box/README_EN.md)", "`Greedy`,`Array`", "Medium", ""]}, {"question_id": "1894", "frontend_question_id": "1768", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/merge-strings-alternately", "url_en": "https://leetcode.com/problems/merge-strings-alternately", "relative_path_cn": "/solution/1700-1799/1768.Merge%20Strings%20Alternately/README.md", "relative_path_en": "/solution/1700-1799/1768.Merge%20Strings%20Alternately/README_EN.md", "title_cn": "\u4ea4\u66ff\u5408\u5e76\u5b57\u7b26\u4e32", "title_en": "Merge Strings Alternately", "question_title_slug": "merge-strings-alternately", "content_en": "

    You are given two strings word1 and word2. Merge the strings by adding letters in alternating order, starting with word1. If a string is longer than the other, append the additional letters onto the end of the merged string.

    \r\n\r\n

    Return the merged string.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: word1 = "abc", word2 = "pqr"\r\nOutput: "apbqcr"\r\nExplanation: The merged string will be merged as so:\r\nword1:  a   b   c\r\nword2:    p   q   r\r\nmerged: a p b q c r\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: word1 = "ab", word2 = "pqrs"\r\nOutput: "apbqrs"\r\nExplanation: Notice that as word2 is longer, "rs" is appended to the end.\r\nword1:  a   b \r\nword2:    p   q   r   s\r\nmerged: a p b q   r   s\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: word1 = "abcd", word2 = "pq"\r\nOutput: "apbqcd"\r\nExplanation: Notice that as word1 is longer, "cd" is appended to the end.\r\nword1:  a   b   c   d\r\nword2:    p   q \r\nmerged: a p b q c   d\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= word1.length, word2.length <= 100
    • \r\n\t
    • word1 and word2 consist of lowercase English letters.
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u5b57\u7b26\u4e32 word1 \u548c word2 \u3002\u8bf7\u4f60\u4ece word1 \u5f00\u59cb\uff0c\u901a\u8fc7\u4ea4\u66ff\u6dfb\u52a0\u5b57\u6bcd\u6765\u5408\u5e76\u5b57\u7b26\u4e32\u3002\u5982\u679c\u4e00\u4e2a\u5b57\u7b26\u4e32\u6bd4\u53e6\u4e00\u4e2a\u5b57\u7b26\u4e32\u957f\uff0c\u5c31\u5c06\u591a\u51fa\u6765\u7684\u5b57\u6bcd\u8ffd\u52a0\u5230\u5408\u5e76\u540e\u5b57\u7b26\u4e32\u7684\u672b\u5c3e\u3002

    \n\n

    \u8fd4\u56de \u5408\u5e76\u540e\u7684\u5b57\u7b26\u4e32 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aword1 = \"abc\", word2 = \"pqr\"\n\u8f93\u51fa\uff1a\"apbqcr\"\n\u89e3\u91ca\uff1a\u5b57\u7b26\u4e32\u5408\u5e76\u60c5\u51b5\u5982\u4e0b\u6240\u793a\uff1a\nword1\uff1a  a   b   c\nword2\uff1a    p   q   r\n\u5408\u5e76\u540e\uff1a  a p b q c r\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aword1 = \"ab\", word2 = \"pqrs\"\n\u8f93\u51fa\uff1a\"apbqrs\"\n\u89e3\u91ca\uff1a\u6ce8\u610f\uff0cword2 \u6bd4 word1 \u957f\uff0c\"rs\" \u9700\u8981\u8ffd\u52a0\u5230\u5408\u5e76\u540e\u5b57\u7b26\u4e32\u7684\u672b\u5c3e\u3002\nword1\uff1a  a   b \nword2\uff1a    p   q   r   s\n\u5408\u5e76\u540e\uff1a  a p b q   r   s\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aword1 = \"abcd\", word2 = \"pq\"\n\u8f93\u51fa\uff1a\"apbqcd\"\n\u89e3\u91ca\uff1a\u6ce8\u610f\uff0cword1 \u6bd4 word2 \u957f\uff0c\"cd\" \u9700\u8981\u8ffd\u52a0\u5230\u5408\u5e76\u540e\u5b57\u7b26\u4e32\u7684\u672b\u5c3e\u3002\nword1\uff1a  a   b   c   d\nword2\uff1a    p   q \n\u5408\u5e76\u540e\uff1a  a p b q c   d\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= word1.length, word2.length <= 100
    • \n\t
    • word1 \u548c word2 \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string mergeAlternately(string word1, string word2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String mergeAlternately(String word1, String word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def mergeAlternately(self, word1, word2):\n \"\"\"\n :type word1: str\n :type word2: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def mergeAlternately(self, word1: str, word2: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * mergeAlternately(char * word1, char * word2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string MergeAlternately(string word1, string word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} word1\n * @param {string} word2\n * @return {string}\n */\nvar mergeAlternately = function(word1, word2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} word1\n# @param {String} word2\n# @return {String}\ndef merge_alternately(word1, word2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func mergeAlternately(_ word1: String, _ word2: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func mergeAlternately(word1 string, word2 string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def mergeAlternately(word1: String, word2: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun mergeAlternately(word1: String, word2: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn merge_alternately(word1: String, word2: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $word1\n * @param String $word2\n * @return String\n */\n function mergeAlternately($word1, $word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function mergeAlternately(word1: string, word2: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (merge-alternately word1 word2)\n (-> string? string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1768](https://leetcode-cn.com/problems/merge-strings-alternately)", "[\u4ea4\u66ff\u5408\u5e76\u5b57\u7b26\u4e32](/solution/1700-1799/1768.Merge%20Strings%20Alternately/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1768](https://leetcode.com/problems/merge-strings-alternately)", "[Merge Strings Alternately](/solution/1700-1799/1768.Merge%20Strings%20Alternately/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1893", "frontend_question_id": "1746", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/maximum-subarray-sum-after-one-operation", "url_en": "https://leetcode.com/problems/maximum-subarray-sum-after-one-operation", "relative_path_cn": "/solution/1700-1799/1746.Maximum%20Subarray%20Sum%20After%20One%20Operation/README.md", "relative_path_en": "/solution/1700-1799/1746.Maximum%20Subarray%20Sum%20After%20One%20Operation/README_EN.md", "title_cn": "\u7ecf\u8fc7\u4e00\u6b21\u64cd\u4f5c\u540e\u7684\u6700\u5927\u5b50\u6570\u7ec4\u548c", "title_en": "Maximum Subarray Sum After One Operation", "question_title_slug": "maximum-subarray-sum-after-one-operation", "content_en": "

    You are given an integer array nums. You must perform exactly one operation where you can replace one element nums[i] with nums[i] * nums[i]

    \r\n\r\n

    Return the maximum possible subarray sum after exactly one operation. The subarray must be non-empty.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: nums = [2,-1,-4,-3]\r\nOutput: 17\r\nExplanation: You can perform the operation on index 2 (0-indexed) to make nums = [2,-1,16,-3]. Now, the maximum subarray sum is 2 + -1 + 16 = 17.
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: nums = [1,-1,1,1,-1,-1,1]\r\nOutput: 4\r\nExplanation: You can perform the operation on index 1 (0-indexed) to make nums = [1,1,1,1,-1,-1,1]. Now, the maximum subarray sum is 1 + 1 + 1 + 1 = 4.
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= nums.length <= 105
    • \r\n\t
    • -104 <= nums[i] <= 104
    • \r\n
    ", "content_cn": "

    \u4f60\u6709\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0nums\u3002\u4f60\u53ea\u80fd\u5c06\u4e00\u4e2a\u5143\u7d20\u00a0nums[i] \u66ff\u6362\u4e3a\u00a0nums[i] * nums[i]\u3002

    \n\n

    \u8fd4\u56de\u66ff\u6362\u540e\u7684\u6700\u5927\u5b50\u6570\u7ec4\u548c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [2,-1,-4,-3]\n\u8f93\u51fa\uff1a17\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u628a-4\u66ff\u6362\u4e3a16(-4*(-4))\uff0c\u4f7fnums = [2,-1,16,-3]. \u73b0\u5728\uff0c\u6700\u5927\u5b50\u6570\u7ec4\u548c\u4e3a 2 + -1 + 16 = 17.
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,-1,1,1,-1,-1,1]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u628a\u7b2c\u4e00\u4e2a-1\u66ff\u6362\u4e3a1\uff0c\u4f7f nums = [1,1,1,1,-1,-1,1]. \u73b0\u5728\uff0c\u6700\u5927\u5b50\u6570\u7ec4\u548c\u4e3a 1 + 1 + 1 + 1 = 4.
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • -104\u00a0<= nums[i] <= 104
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxSumAfterOperation(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxSumAfterOperation(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxSumAfterOperation(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxSumAfterOperation(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxSumAfterOperation(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxSumAfterOperation(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar maxSumAfterOperation = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef max_sum_after_operation(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxSumAfterOperation(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxSumAfterOperation(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxSumAfterOperation(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxSumAfterOperation(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_sum_after_operation(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function maxSumAfterOperation($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxSumAfterOperation(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-sum-after-operation nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1746](https://leetcode-cn.com/problems/maximum-subarray-sum-after-one-operation)", "[\u7ecf\u8fc7\u4e00\u6b21\u64cd\u4f5c\u540e\u7684\u6700\u5927\u5b50\u6570\u7ec4\u548c](/solution/1700-1799/1746.Maximum%20Subarray%20Sum%20After%20One%20Operation/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1746](https://leetcode.com/problems/maximum-subarray-sum-after-one-operation)", "[Maximum Subarray Sum After One Operation](/solution/1700-1799/1746.Maximum%20Subarray%20Sum%20After%20One%20Operation/README_EN.md)", "`Dynamic Programming`", "Medium", "\ud83d\udd12"]}, {"question_id": "1892", "frontend_question_id": "1741", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/find-total-time-spent-by-each-employee", "url_en": "https://leetcode.com/problems/find-total-time-spent-by-each-employee", "relative_path_cn": "/solution/1700-1799/1741.Find%20Total%20Time%20Spent%20by%20Each%20Employee/README.md", "relative_path_en": "/solution/1700-1799/1741.Find%20Total%20Time%20Spent%20by%20Each%20Employee/README_EN.md", "title_cn": "\u67e5\u627e\u6bcf\u4e2a\u5458\u5de5\u82b1\u8d39\u7684\u603b\u65f6\u95f4", "title_en": "Find Total Time Spent by Each Employee", "question_title_slug": "find-total-time-spent-by-each-employee", "content_en": "

    Table: Employees

    \n\n
    \n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| emp_id      | int  |\n| event_day   | date |\n| in_time     | int  |\n| out_time    | int  |\n+-------------+------+\n(emp_id, event_day, in_time) is the primary key of this table.\nThe table shows the employees' entries and exits in an office.\nevent_day is the day at which this event happened, in_time is the minute at which the employee entered the office, and out_time is the minute at which they left the office.\nin_time and out_time are between 1 and 1440.\nIt is guaranteed that no two events on the same day intersect in time, and in_time < out_time.\n
    \n\n

     

    \n\n

    Write an SQL query to calculate the total time in minutes spent by each employee on each day at the office. Note that within one day, an employee can enter and leave more than once. The time spent in the office for a single entry is out_time - in_time.

    \n\n

    Return the result table in any order.

    \n\n

    The query result format is in the following example:

    \n\n
    \nEmployees table:\n+--------+------------+---------+----------+\n| emp_id | event_day  | in_time | out_time |\n+--------+------------+---------+----------+\n| 1      | 2020-11-28 | 4       | 32       |\n| 1      | 2020-11-28 | 55      | 200      |\n| 1      | 2020-12-03 | 1       | 42       |\n| 2      | 2020-11-28 | 3       | 33       |\n| 2      | 2020-12-09 | 47      | 74       |\n+--------+------------+---------+----------+\nResult table:\n+------------+--------+------------+\n| day        | emp_id | total_time |\n+------------+--------+------------+\n| 2020-11-28 | 1      | 173        |\n| 2020-11-28 | 2      | 30         |\n| 2020-12-03 | 1      | 41         |\n| 2020-12-09 | 2      | 27         |\n+------------+--------+------------+\nEmployee 1 has three events: two on day 2020-11-28 with a total of (32 - 4) + (200 - 55) = 173, and one on day 2020-12-03 with a total of (42 - 1) = 41.\nEmployee 2 has two events: one on day 2020-11-28 with a total of (33 - 3) = 30, and one on day 2020-12-09 with a total of (74 - 47) = 27.\n
    \n", "content_cn": "

    \u8868: Employees

    \n\n
    +-------------+------+\n| Column Name | Type |\n+-------------+------+\n| emp_id      | int  |\n| event_day   | date |\n| in_time     | int  |\n| out_time    | int  |\n+-------------+------+\n(emp_id, event_day, in_time) \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\u3002\n\u8be5\u8868\u663e\u793a\u4e86\u5458\u5de5\u5728\u529e\u516c\u5ba4\u7684\u51fa\u5165\u60c5\u51b5\u3002\nevent_day \u662f\u6b64\u4e8b\u4ef6\u53d1\u751f\u7684\u65e5\u671f\uff0cin_time \u662f\u5458\u5de5\u8fdb\u5165\u529e\u516c\u5ba4\u7684\u65f6\u95f4\uff0c\u800c out_time \u662f\u4ed6\u4eec\u79bb\u5f00\u529e\u516c\u5ba4\u7684\u65f6\u95f4\u3002\nin_time \u548c out_time \u7684\u53d6\u503c\u57281\u52301440\u4e4b\u95f4\u3002\n\u9898\u76ee\u4fdd\u8bc1\u540c\u4e00\u5929\u6ca1\u6709\u4e24\u4e2a\u4e8b\u4ef6\u5728\u65f6\u95f4\u4e0a\u662f\u76f8\u4ea4\u7684\uff0c\u5e76\u4e14\u4fdd\u8bc1 in_time \u5c0f\u4e8e out_time\u3002\n
    \n\n

    \u00a0

    \n\n

    \u7f16\u5199\u4e00\u4e2aSQL\u67e5\u8be2\u4ee5\u8ba1\u7b97\u6bcf\u4f4d\u5458\u5de5\u6bcf\u5929\u5728\u529e\u516c\u5ba4\u82b1\u8d39\u7684\u603b\u65f6\u95f4\uff08\u4ee5\u5206\u949f\u4e3a\u5355\u4f4d\uff09\u3002 \u8bf7\u6ce8\u610f\uff0c\u5728\u4e00\u5929\u4e4b\u5185\uff0c\u540c\u4e00\u5458\u5de5\u662f\u53ef\u4ee5\u591a\u6b21\u8fdb\u5165\u548c\u79bb\u5f00\u529e\u516c\u5ba4\u7684\u3002 \u5728\u529e\u516c\u5ba4\u91cc\u4e00\u6b21\u8fdb\u51fa\u6240\u82b1\u8d39\u7684\u65f6\u95f4\u4e3aout_time \u51cf\u53bb in_time\u3002

    \n\n

    \u8fd4\u56de\u7ed3\u679c\u8868\u5355\u7684\u987a\u5e8f\u65e0\u8981\u6c42\u3002
    \n\u67e5\u8be2\u7ed3\u679c\u7684\u683c\u5f0f\u5982\u4e0b\uff1a

    \n\n
    Employees table:\n+--------+------------+---------+----------+\n| emp_id | event_day  | in_time | out_time |\n+--------+------------+---------+----------+\n| 1      | 2020-11-28 | 4       | 32       |\n| 1      | 2020-11-28 | 55      | 200      |\n| 1      | 2020-12-03 | 1       | 42       |\n| 2      | 2020-11-28 | 3       | 33       |\n| 2      | 2020-12-09 | 47      | 74       |\n+--------+------------+---------+----------+\nResult table:\n+------------+--------+------------+\n| day        | emp_id | total_time |\n+------------+--------+------------+\n| 2020-11-28 | 1      | 173        |\n| 2020-11-28 | 2      | 30         |\n| 2020-12-03 | 1      | 41         |\n| 2020-12-09 | 2      | 27         |\n+------------+--------+------------+\n\u96c7\u5458 1 \u6709\u4e09\u6b21\u8fdb\u51fa: \u6709\u4e24\u6b21\u53d1\u751f\u5728 2020-11-28 \u82b1\u8d39\u7684\u65f6\u95f4\u4e3a (32 - 4) + (200 - 55) = 173, \u6709\u4e00\u6b21\u53d1\u751f\u5728 2020-12-03 \u82b1\u8d39\u7684\u65f6\u95f4\u4e3a (42 - 1) = 41\u3002\n\u96c7\u5458 2 \u6709\u4e24\u6b21\u8fdb\u51fa: \u6709\u4e00\u6b21\u53d1\u751f\u5728 2020-11-28 \u82b1\u8d39\u7684\u65f6\u95f4\u4e3a (33 - 3) = 30,  \u6709\u4e00\u6b21\u53d1\u751f\u5728 2020-12-09 \u82b1\u8d39\u7684\u65f6\u95f4\u4e3a (74 - 47) = 27\u3002\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1741](https://leetcode-cn.com/problems/find-total-time-spent-by-each-employee)", "[\u67e5\u627e\u6bcf\u4e2a\u5458\u5de5\u82b1\u8d39\u7684\u603b\u65f6\u95f4](/solution/1700-1799/1741.Find%20Total%20Time%20Spent%20by%20Each%20Employee/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1741](https://leetcode.com/problems/find-total-time-spent-by-each-employee)", "[Find Total Time Spent by Each Employee](/solution/1700-1799/1741.Find%20Total%20Time%20Spent%20by%20Each%20Employee/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1891", "frontend_question_id": "1782", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-pairs-of-nodes", "url_en": "https://leetcode.com/problems/count-pairs-of-nodes", "relative_path_cn": "/solution/1700-1799/1782.Count%20Pairs%20Of%20Nodes/README.md", "relative_path_en": "/solution/1700-1799/1782.Count%20Pairs%20Of%20Nodes/README_EN.md", "title_cn": "\u7edf\u8ba1\u70b9\u5bf9\u7684\u6570\u76ee", "title_en": "Count Pairs Of Nodes", "question_title_slug": "count-pairs-of-nodes", "content_en": "

    You are given an undirected graph represented by an integer n, which is the number of nodes, and edges, where edges[i] = [ui, vi] which indicates that there is an undirected edge between ui and vi. You are also given an integer array queries.

    \n\n

    The answer to the jth query is the number of pairs of nodes (a, b) that satisfy the following conditions:

    \n\n
      \n\t
    • a < b
    • \n\t
    • cnt is strictly greater than queries[j], where cnt is the number of edges incident to a or b.
    • \n
    \n\n

    Return an array answers such that answers.length == queries.length and answers[j] is the answer of the jth query.

    \n\n

    Note that there can be repeated edges.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: n = 4, edges = [[1,2],[2,4],[1,3],[2,3],[2,1]], queries = [2,3]\nOutput: [6,5]\nExplanation: The number of edges incident to at least one of each pair is shown above.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 5, edges = [[1,5],[1,5],[3,4],[2,5],[1,3],[5,1],[2,3],[2,5]], queries = [1,2,3,4,5]\nOutput: [10,10,9,8,6]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= n <= 2 * 104
    • \n\t
    • 1 <= edges.length <= 105
    • \n\t
    • 1 <= ui, vi <= n
    • \n\t
    • ui != vi
    • \n\t
    • 1 <= queries.length <= 20
    • \n\t
    • 0 <= queries[j] < edges.length
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u65e0\u5411\u56fe\uff0c\u65e0\u5411\u56fe\u7531\u6574\u6570\u00a0n\u00a0\u00a0\uff0c\u8868\u793a\u56fe\u4e2d\u8282\u70b9\u7684\u6570\u76ee\uff0c\u548c\u00a0edges\u00a0\u7ec4\u6210\uff0c\u5176\u4e2d\u00a0edges[i] = [ui, vi]\u00a0\u8868\u793a\u00a0ui \u548c\u00a0vi\u00a0\u4e4b\u95f4\u6709\u4e00\u6761\u65e0\u5411\u8fb9\u3002\u540c\u65f6\u7ed9\u4f60\u4e00\u4e2a\u4ee3\u8868\u67e5\u8be2\u7684\u6574\u6570\u6570\u7ec4\u00a0queries\u00a0\u3002

    \n\n

    \u7b2c j \u4e2a\u67e5\u8be2\u7684\u7b54\u6848\u662f\u6ee1\u8db3\u5982\u4e0b\u6761\u4ef6\u7684\u70b9\u5bf9 (a, b) \u7684\u6570\u76ee\uff1a

    \n\n
      \n\t
    • a < b
    • \n\t
    • cnt\u00a0\u662f\u4e0e a\u00a0\u6216\u8005\u00a0b\u00a0\u76f8\u8fde\u7684\u8fb9\u7684\u6570\u76ee\uff0c\u4e14 cnt\u00a0\u4e25\u683c\u5927\u4e8e\u00a0queries[j]\u00a0\u3002
    • \n
    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u4e00\u4e2a\u6570\u7ec4\u00a0answers\u00a0\uff0c\u5176\u4e2d\u00a0answers.length == queries.length \u4e14\u00a0answers[j]\u00a0\u662f\u7b2c j\u00a0\u4e2a\u67e5\u8be2\u7684\u7b54\u6848\u3002

    \n\n

    \u8bf7\u6ce8\u610f\uff0c\u56fe\u4e2d\u53ef\u80fd\u4f1a\u6709 \u91cd\u590d\u8fb9\u00a0\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1an = 4, edges = [[1,2],[2,4],[1,3],[2,3],[2,1]], queries = [2,3]\n\u8f93\u51fa\uff1a[6,5]\n\u89e3\u91ca\uff1a\u6bcf\u4e2a\u70b9\u5bf9\u4e2d\uff0c\u4e0e\u81f3\u5c11\u4e00\u4e2a\u70b9\u76f8\u8fde\u7684\u8fb9\u7684\u6570\u76ee\u5982\u4e0a\u56fe\u6240\u793a\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 5, edges = [[1,5],[1,5],[3,4],[2,5],[1,3],[5,1],[2,3],[2,5]], queries = [1,2,3,4,5]\n\u8f93\u51fa\uff1a[10,10,9,8,6]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= n <= 2 * 104
    • \n\t
    • 1 <= edges.length <= 105
    • \n\t
    • 1 <= ui, vi <= n
    • \n\t
    • ui != vi
    • \n\t
    • 1 <= queries.length <= 20
    • \n\t
    • 0 <= queries[j] < edges.length
    • \n
    \n", "tags_en": ["Graph"], "tags_cn": ["\u56fe"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector countPairs(int n, vector>& edges, vector& queries) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] countPairs(int n, int[][] edges, int[] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countPairs(self, n, edges, queries):\n \"\"\"\n :type n: int\n :type edges: List[List[int]]\n :type queries: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countPairs(self, n: int, edges: List[List[int]], queries: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* countPairs(int n, int** edges, int edgesSize, int* edgesColSize, int* queries, int queriesSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] CountPairs(int n, int[][] edges, int[] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} edges\n * @param {number[]} queries\n * @return {number[]}\n */\nvar countPairs = function(n, edges, queries) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} edges\n# @param {Integer[]} queries\n# @return {Integer[]}\ndef count_pairs(n, edges, queries)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countPairs(_ n: Int, _ edges: [[Int]], _ queries: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countPairs(n int, edges [][]int, queries []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countPairs(n: Int, edges: Array[Array[Int]], queries: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countPairs(n: Int, edges: Array, queries: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_pairs(n: i32, edges: Vec>, queries: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $edges\n * @param Integer[] $queries\n * @return Integer[]\n */\n function countPairs($n, $edges, $queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countPairs(n: number, edges: number[][], queries: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-pairs n edges queries)\n (-> exact-integer? (listof (listof exact-integer?)) (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1782](https://leetcode-cn.com/problems/count-pairs-of-nodes)", "[\u7edf\u8ba1\u70b9\u5bf9\u7684\u6570\u76ee](/solution/1700-1799/1782.Count%20Pairs%20Of%20Nodes/README.md)", "`\u56fe`", "\u56f0\u96be", ""], "md_table_row_en": ["[1782](https://leetcode.com/problems/count-pairs-of-nodes)", "[Count Pairs Of Nodes](/solution/1700-1799/1782.Count%20Pairs%20Of%20Nodes/README_EN.md)", "`Graph`", "Hard", ""]}, {"question_id": "1890", "frontend_question_id": "1781", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sum-of-beauty-of-all-substrings", "url_en": "https://leetcode.com/problems/sum-of-beauty-of-all-substrings", "relative_path_cn": "/solution/1700-1799/1781.Sum%20of%20Beauty%20of%20All%20Substrings/README.md", "relative_path_en": "/solution/1700-1799/1781.Sum%20of%20Beauty%20of%20All%20Substrings/README_EN.md", "title_cn": "\u6240\u6709\u5b50\u5b57\u7b26\u4e32\u7f8e\u4e3d\u503c\u4e4b\u548c", "title_en": "Sum of Beauty of All Substrings", "question_title_slug": "sum-of-beauty-of-all-substrings", "content_en": "

    The beauty of a string is the difference in frequencies between the most frequent and least frequent characters.

    \n\n
      \n\t
    • For example, the beauty of "abaacc" is 3 - 1 = 2.
    • \n
    \n\n

    Given a string s, return the sum of beauty of all of its substrings.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "aabcb"\nOutput: 5\nExplanation: The substrings with non-zero beauty are ["aab","aabc","aabcb","abcb","bcb"], each with beauty equal to 1.
    \n\n

    Example 2:

    \n\n
    \nInput: s = "aabcbaa"\nOutput: 17\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 500
    • \n\t
    • s consists of only lowercase English letters.
    • \n
    \n", "content_cn": "

    \u4e00\u4e2a\u5b57\u7b26\u4e32\u7684 \u7f8e\u4e3d\u503c\u00a0\u5b9a\u4e49\u4e3a\uff1a\u51fa\u73b0\u9891\u7387\u6700\u9ad8\u5b57\u7b26\u4e0e\u51fa\u73b0\u9891\u7387\u6700\u4f4e\u5b57\u7b26\u7684\u51fa\u73b0\u6b21\u6570\u4e4b\u5dee\u3002

    \n\n
      \n\t
    • \u6bd4\u65b9\u8bf4\uff0c\"abaacc\"\u00a0\u7684\u7f8e\u4e3d\u503c\u4e3a\u00a03 - 1 = 2\u00a0\u3002
    • \n
    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32\u00a0s\u00a0\uff0c\u8bf7\u4f60\u8fd4\u56de\u5b83\u6240\u6709\u5b50\u5b57\u7b26\u4e32\u7684\u00a0\u7f8e\u4e3d\u503c\u00a0\u4e4b\u548c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"aabcb\"\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u7f8e\u4e3d\u503c\u4e0d\u4e3a\u96f6\u7684\u5b57\u7b26\u4e32\u5305\u62ec [\"aab\",\"aabc\",\"aabcb\",\"abcb\",\"bcb\"] \uff0c\u6bcf\u4e00\u4e2a\u5b57\u7b26\u4e32\u7684\u7f8e\u4e3d\u503c\u90fd\u4e3a 1 \u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"aabcbaa\"\n\u8f93\u51fa\uff1a17\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 500
    • \n\t
    • s\u00a0\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    • \n
    \n", "tags_en": ["Hash Table", "String"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int beautySum(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int beautySum(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def beautySum(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def beautySum(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint beautySum(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int BeautySum(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar beautySum = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef beauty_sum(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func beautySum(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func beautySum(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def beautySum(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun beautySum(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn beauty_sum(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function beautySum($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function beautySum(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (beauty-sum s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1781](https://leetcode-cn.com/problems/sum-of-beauty-of-all-substrings)", "[\u6240\u6709\u5b50\u5b57\u7b26\u4e32\u7f8e\u4e3d\u503c\u4e4b\u548c](/solution/1700-1799/1781.Sum%20of%20Beauty%20of%20All%20Substrings/README.md)", "`\u54c8\u5e0c\u8868`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1781](https://leetcode.com/problems/sum-of-beauty-of-all-substrings)", "[Sum of Beauty of All Substrings](/solution/1700-1799/1781.Sum%20of%20Beauty%20of%20All%20Substrings/README_EN.md)", "`Hash Table`,`String`", "Medium", ""]}, {"question_id": "1889", "frontend_question_id": "1780", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/check-if-number-is-a-sum-of-powers-of-three", "url_en": "https://leetcode.com/problems/check-if-number-is-a-sum-of-powers-of-three", "relative_path_cn": "/solution/1700-1799/1780.Check%20if%20Number%20is%20a%20Sum%20of%20Powers%20of%20Three/README.md", "relative_path_en": "/solution/1700-1799/1780.Check%20if%20Number%20is%20a%20Sum%20of%20Powers%20of%20Three/README_EN.md", "title_cn": "\u5224\u65ad\u4e00\u4e2a\u6570\u5b57\u662f\u5426\u53ef\u4ee5\u8868\u793a\u6210\u4e09\u7684\u5e42\u7684\u548c", "title_en": "Check if Number is a Sum of Powers of Three", "question_title_slug": "check-if-number-is-a-sum-of-powers-of-three", "content_en": "

    Given an integer n, return true if it is possible to represent n as the sum of distinct powers of three. Otherwise, return false.

    \n\n

    An integer y is a power of three if there exists an integer x such that y == 3x.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 12\nOutput: true\nExplanation: 12 = 31 + 32\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 91\nOutput: true\nExplanation: 91 = 30 + 32 + 34\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 21\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 107
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u00a0n\u00a0\uff0c\u5982\u679c\u4f60\u53ef\u4ee5\u5c06\u00a0n\u00a0\u8868\u793a\u6210\u82e5\u5e72\u4e2a\u4e0d\u540c\u7684\u4e09\u7684\u5e42\u4e4b\u548c\uff0c\u8bf7\u4f60\u8fd4\u56de\u00a0true\u00a0\uff0c\u5426\u5219\u8bf7\u8fd4\u56de false\u00a0\u3002

    \n\n

    \u5bf9\u4e8e\u4e00\u4e2a\u6574\u6570 y\u00a0\uff0c\u5982\u679c\u5b58\u5728\u6574\u6570 x\u00a0\u6ee1\u8db3 y == 3x\u00a0\uff0c\u6211\u4eec\u79f0\u8fd9\u4e2a\u6574\u6570 y\u00a0\u662f\u4e09\u7684\u5e42\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1an = 12\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a12 = 31 + 32\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1an = 91\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a91 = 30 + 32 + 34\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1an = 21\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 107
    • \n
    \n", "tags_en": ["Recursion", "Math", "Backtracking"], "tags_cn": ["\u9012\u5f52", "\u6570\u5b66", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool checkPowersOfThree(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean checkPowersOfThree(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def checkPowersOfThree(self, n):\n \"\"\"\n :type n: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def checkPowersOfThree(self, n: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool checkPowersOfThree(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CheckPowersOfThree(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {boolean}\n */\nvar checkPowersOfThree = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Boolean}\ndef check_powers_of_three(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func checkPowersOfThree(_ n: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func checkPowersOfThree(n int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def checkPowersOfThree(n: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun checkPowersOfThree(n: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn check_powers_of_three(n: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Boolean\n */\n function checkPowersOfThree($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function checkPowersOfThree(n: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (check-powers-of-three n)\n (-> exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1780](https://leetcode-cn.com/problems/check-if-number-is-a-sum-of-powers-of-three)", "[\u5224\u65ad\u4e00\u4e2a\u6570\u5b57\u662f\u5426\u53ef\u4ee5\u8868\u793a\u6210\u4e09\u7684\u5e42\u7684\u548c](/solution/1700-1799/1780.Check%20if%20Number%20is%20a%20Sum%20of%20Powers%20of%20Three/README.md)", "`\u9012\u5f52`,`\u6570\u5b66`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1780](https://leetcode.com/problems/check-if-number-is-a-sum-of-powers-of-three)", "[Check if Number is a Sum of Powers of Three](/solution/1700-1799/1780.Check%20if%20Number%20is%20a%20Sum%20of%20Powers%20of%20Three/README_EN.md)", "`Recursion`,`Math`,`Backtracking`", "Medium", ""]}, {"question_id": "1888", "frontend_question_id": "1779", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-nearest-point-that-has-the-same-x-or-y-coordinate", "url_en": "https://leetcode.com/problems/find-nearest-point-that-has-the-same-x-or-y-coordinate", "relative_path_cn": "/solution/1700-1799/1779.Find%20Nearest%20Point%20That%20Has%20the%20Same%20X%20or%20Y%20Coordinate/README.md", "relative_path_en": "/solution/1700-1799/1779.Find%20Nearest%20Point%20That%20Has%20the%20Same%20X%20or%20Y%20Coordinate/README_EN.md", "title_cn": "\u627e\u5230\u6700\u8fd1\u7684\u6709\u76f8\u540c X \u6216 Y \u5750\u6807\u7684\u70b9", "title_en": "Find Nearest Point That Has the Same X or Y Coordinate", "question_title_slug": "find-nearest-point-that-has-the-same-x-or-y-coordinate", "content_en": "

    You are given two integers, x and y, which represent your current location on a Cartesian grid: (x, y). You are also given an array points where each points[i] = [ai, bi] represents that a point exists at (ai, bi). A point is valid if it shares the same x-coordinate or the same y-coordinate as your location.

    \n\n

    Return the index (0-indexed) of the valid point with the smallest Manhattan distance from your current location. If there are multiple, return the valid point with the smallest index. If there are no valid points, return -1.

    \n\n

    The Manhattan distance between two points (x1, y1) and (x2, y2) is abs(x1 - x2) + abs(y1 - y2).

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: x = 3, y = 4, points = [[1,2],[3,1],[2,4],[2,3],[4,4]]\nOutput: 2\nExplanation: Of all the points, only [3,1], [2,4] and [4,4] are valid. Of the valid points, [2,4] and [4,4] have the smallest Manhattan distance from your current location, with a distance of 1. [2,4] has the smallest index, so return 2.
    \n\n

    Example 2:

    \n\n
    \nInput: x = 3, y = 4, points = [[3,4]]\nOutput: 0\nExplanation: The answer is allowed to be on the same location as your current location.
    \n\n

    Example 3:

    \n\n
    \nInput: x = 3, y = 4, points = [[2,3]]\nOutput: -1\nExplanation: There are no valid points.
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= points.length <= 104
    • \n\t
    • points[i].length == 2
    • \n\t
    • 1 <= x, y, ai, bi <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u6574\u6570\u00a0x \u548c\u00a0y\u00a0\uff0c\u8868\u793a\u4f60\u5728\u4e00\u4e2a\u7b1b\u5361\u5c14\u5750\u6807\u7cfb\u4e0b\u7684\u00a0(x, y)\u00a0\u5904\u3002\u540c\u65f6\uff0c\u5728\u540c\u4e00\u4e2a\u5750\u6807\u7cfb\u4e0b\u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4\u00a0points\u00a0\uff0c\u5176\u4e2d\u00a0points[i] = [ai, bi]\u00a0\u8868\u793a\u5728\u00a0(ai, bi)\u00a0\u5904\u6709\u4e00\u4e2a\u70b9\u3002\u5f53\u4e00\u4e2a\u70b9\u4e0e\u4f60\u6240\u5728\u7684\u4f4d\u7f6e\u6709\u76f8\u540c\u7684 x \u5750\u6807\u6216\u8005\u76f8\u540c\u7684 y \u5750\u6807\u65f6\uff0c\u6211\u4eec\u79f0\u8fd9\u4e2a\u70b9\u662f \u6709\u6548\u7684\u00a0\u3002

    \n\n

    \u8bf7\u8fd4\u56de\u8ddd\u79bb\u4f60\u5f53\u524d\u4f4d\u7f6e\u00a0\u66fc\u54c8\u987f\u8ddd\u79bb\u00a0\u6700\u8fd1\u7684\u00a0\u6709\u6548\u00a0\u70b9\u7684\u4e0b\u6807\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\u3002\u5982\u679c\u6709\u591a\u4e2a\u6700\u8fd1\u7684\u6709\u6548\u70b9\uff0c\u8bf7\u8fd4\u56de\u4e0b\u6807\u00a0\u6700\u5c0f\u00a0\u7684\u4e00\u4e2a\u3002\u5982\u679c\u6ca1\u6709\u6709\u6548\u70b9\uff0c\u8bf7\u8fd4\u56de\u00a0-1\u00a0\u3002

    \n\n

    \u4e24\u4e2a\u70b9 (x1, y1)\u00a0\u548c (x2, y2)\u00a0\u4e4b\u95f4\u7684 \u66fc\u54c8\u987f\u8ddd\u79bb\u00a0\u4e3a\u00a0abs(x1 - x2) + abs(y1 - y2)\u00a0\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1ax = 3, y = 4, points = [[1,2],[3,1],[2,4],[2,3],[4,4]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6240\u6709\u70b9\u4e2d\uff0c[3,1]\uff0c[2,4] \u548c [4,4] \u662f\u6709\u6548\u70b9\u3002\u6709\u6548\u70b9\u4e2d\uff0c[2,4] \u548c [4,4] \u8ddd\u79bb\u4f60\u5f53\u524d\u4f4d\u7f6e\u7684\u66fc\u54c8\u987f\u8ddd\u79bb\u6700\u5c0f\uff0c\u90fd\u4e3a 1 \u3002[2,4] \u7684\u4e0b\u6807\u6700\u5c0f\uff0c\u6240\u4ee5\u8fd4\u56de 2 \u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1ax = 3, y = 4, points = [[3,4]]\n\u8f93\u51fa\uff1a0\n\u63d0\u793a\uff1a\u7b54\u6848\u53ef\u4ee5\u4e0e\u4f60\u5f53\u524d\u6240\u5728\u4f4d\u7f6e\u5750\u6807\u76f8\u540c\u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1ax = 3, y = 4, points = [[2,3]]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u6ca1\u6709\u6709\u6548\u70b9\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= points.length <= 104
    • \n\t
    • points[i].length == 2
    • \n\t
    • 1 <= x, y, ai, bi <= 104
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int nearestValidPoint(int x, int y, vector>& points) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int nearestValidPoint(int x, int y, int[][] points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def nearestValidPoint(self, x, y, points):\n \"\"\"\n :type x: int\n :type y: int\n :type points: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def nearestValidPoint(self, x: int, y: int, points: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint nearestValidPoint(int x, int y, int** points, int pointsSize, int* pointsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NearestValidPoint(int x, int y, int[][] points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} x\n * @param {number} y\n * @param {number[][]} points\n * @return {number}\n */\nvar nearestValidPoint = function(x, y, points) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} x\n# @param {Integer} y\n# @param {Integer[][]} points\n# @return {Integer}\ndef nearest_valid_point(x, y, points)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func nearestValidPoint(_ x: Int, _ y: Int, _ points: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func nearestValidPoint(x int, y int, points [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def nearestValidPoint(x: Int, y: Int, points: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun nearestValidPoint(x: Int, y: Int, points: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn nearest_valid_point(x: i32, y: i32, points: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $x\n * @param Integer $y\n * @param Integer[][] $points\n * @return Integer\n */\n function nearestValidPoint($x, $y, $points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function nearestValidPoint(x: number, y: number, points: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (nearest-valid-point x y points)\n (-> exact-integer? exact-integer? (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1779](https://leetcode-cn.com/problems/find-nearest-point-that-has-the-same-x-or-y-coordinate)", "[\u627e\u5230\u6700\u8fd1\u7684\u6709\u76f8\u540c X \u6216 Y \u5750\u6807\u7684\u70b9](/solution/1700-1799/1779.Find%20Nearest%20Point%20That%20Has%20the%20Same%20X%20or%20Y%20Coordinate/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1779](https://leetcode.com/problems/find-nearest-point-that-has-the-same-x-or-y-coordinate)", "[Find Nearest Point That Has the Same X or Y Coordinate](/solution/1700-1799/1779.Find%20Nearest%20Point%20That%20Has%20the%20Same%20X%20or%20Y%20Coordinate/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1887", "frontend_question_id": "1761", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-degree-of-a-connected-trio-in-a-graph", "url_en": "https://leetcode.com/problems/minimum-degree-of-a-connected-trio-in-a-graph", "relative_path_cn": "/solution/1700-1799/1761.Minimum%20Degree%20of%20a%20Connected%20Trio%20in%20a%20Graph/README.md", "relative_path_en": "/solution/1700-1799/1761.Minimum%20Degree%20of%20a%20Connected%20Trio%20in%20a%20Graph/README_EN.md", "title_cn": "\u4e00\u4e2a\u56fe\u4e2d\u8fde\u901a\u4e09\u5143\u7ec4\u7684\u6700\u5c0f\u5ea6\u6570", "title_en": "Minimum Degree of a Connected Trio in a Graph", "question_title_slug": "minimum-degree-of-a-connected-trio-in-a-graph", "content_en": "

    You are given an undirected graph. You are given an integer n which is the number of nodes in the graph and an array edges, where each edges[i] = [ui, vi] indicates that there is an undirected edge between ui and vi.

    \n\n

    A connected trio is a set of three nodes where there is an edge between every pair of them.

    \n\n

    The degree of a connected trio is the number of edges where one endpoint is in the trio, and the other is not.

    \n\n

    Return the minimum degree of a connected trio in the graph, or -1 if the graph has no connected trios.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: n = 6, edges = [[1,2],[1,3],[3,2],[4,1],[5,2],[3,6]]\nOutput: 3\nExplanation: There is exactly one trio, which is [1,2,3]. The edges that form its degree are bolded in the figure above.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: n = 7, edges = [[1,3],[4,1],[4,3],[2,5],[5,6],[6,7],[7,5],[2,6]]\nOutput: 0\nExplanation: There are exactly three trios:\n1) [1,4,3] with degree 0.\n2) [2,5,6] with degree 2.\n3) [5,6,7] with degree 2.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= n <= 400
    • \n\t
    • edges[i].length == 2
    • \n\t
    • 1 <= edges.length <= n * (n-1) / 2
    • \n\t
    • 1 <= ui, vi <= n
    • \n\t
    • ui != vi
    • \n\t
    • There are no repeated edges.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u65e0\u5411\u56fe\uff0c\u6574\u6570 n\u00a0\u8868\u793a\u56fe\u4e2d\u8282\u70b9\u7684\u6570\u76ee\uff0cedges\u00a0\u6570\u7ec4\u8868\u793a\u56fe\u4e2d\u7684\u8fb9\uff0c\u5176\u4e2d\u00a0edges[i] = [ui, vi]\u00a0\uff0c\u8868\u793a\u00a0ui \u548c\u00a0vi\u00a0\u4e4b\u95f4\u6709\u4e00\u6761\u65e0\u5411\u8fb9\u3002

    \n\n

    \u4e00\u4e2a \u8fde\u901a\u4e09\u5143\u7ec4\u00a0\u6307\u7684\u662f \u4e09\u4e2a\u00a0\u8282\u70b9\u7ec4\u6210\u7684\u96c6\u5408\u4e14\u8fd9\u4e09\u4e2a\u70b9\u4e4b\u95f4 \u4e24\u4e24\u00a0\u6709\u8fb9\u3002

    \n\n

    \u8fde\u901a\u4e09\u5143\u7ec4\u7684\u5ea6\u6570\u00a0\u662f\u6240\u6709\u6ee1\u8db3\u6b64\u6761\u4ef6\u7684\u8fb9\u7684\u6570\u76ee\uff1a\u4e00\u4e2a\u9876\u70b9\u5728\u8fd9\u4e2a\u4e09\u5143\u7ec4\u5185\uff0c\u800c\u53e6\u4e00\u4e2a\u9876\u70b9\u4e0d\u5728\u8fd9\u4e2a\u4e09\u5143\u7ec4\u5185\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u6240\u6709\u8fde\u901a\u4e09\u5143\u7ec4\u4e2d\u5ea6\u6570\u7684 \u6700\u5c0f\u503c\u00a0\uff0c\u5982\u679c\u56fe\u4e2d\u6ca1\u6709\u8fde\u901a\u4e09\u5143\u7ec4\uff0c\u90a3\u4e48\u8fd4\u56de -1\u00a0\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1an = 6, edges = [[1,2],[1,3],[3,2],[4,1],[5,2],[3,6]]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u53ea\u6709\u4e00\u4e2a\u4e09\u5143\u7ec4 [1,2,3] \u3002\u6784\u6210\u5ea6\u6570\u7684\u8fb9\u5728\u4e0a\u56fe\u4e2d\u5df2\u88ab\u52a0\u7c97\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1an = 7, edges = [[1,3],[4,1],[4,3],[2,5],[5,6],[6,7],[7,5],[2,6]]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6709 3 \u4e2a\u4e09\u5143\u7ec4\uff1a\n1) [1,4,3]\uff0c\u5ea6\u6570\u4e3a 0 \u3002\n2) [2,5,6]\uff0c\u5ea6\u6570\u4e3a 2 \u3002\n3) [5,6,7]\uff0c\u5ea6\u6570\u4e3a 2 \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= n <= 400
    • \n\t
    • edges[i].length == 2
    • \n\t
    • 1 <= edges.length <= n * (n-1) / 2
    • \n\t
    • 1 <= ui, vi <= n
    • \n\t
    • ui != vi
    • \n\t
    • \u56fe\u4e2d\u6ca1\u6709\u91cd\u590d\u7684\u8fb9\u3002
    • \n
    \n", "tags_en": ["Graph"], "tags_cn": ["\u56fe"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minTrioDegree(int n, vector>& edges) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minTrioDegree(int n, int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minTrioDegree(self, n, edges):\n \"\"\"\n :type n: int\n :type edges: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minTrioDegree(self, n: int, edges: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minTrioDegree(int n, int** edges, int edgesSize, int* edgesColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinTrioDegree(int n, int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} edges\n * @return {number}\n */\nvar minTrioDegree = function(n, edges) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} edges\n# @return {Integer}\ndef min_trio_degree(n, edges)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minTrioDegree(_ n: Int, _ edges: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minTrioDegree(n int, edges [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minTrioDegree(n: Int, edges: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minTrioDegree(n: Int, edges: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_trio_degree(n: i32, edges: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $edges\n * @return Integer\n */\n function minTrioDegree($n, $edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minTrioDegree(n: number, edges: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-trio-degree n edges)\n (-> exact-integer? (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1761](https://leetcode-cn.com/problems/minimum-degree-of-a-connected-trio-in-a-graph)", "[\u4e00\u4e2a\u56fe\u4e2d\u8fde\u901a\u4e09\u5143\u7ec4\u7684\u6700\u5c0f\u5ea6\u6570](/solution/1700-1799/1761.Minimum%20Degree%20of%20a%20Connected%20Trio%20in%20a%20Graph/README.md)", "`\u56fe`", "\u56f0\u96be", ""], "md_table_row_en": ["[1761](https://leetcode.com/problems/minimum-degree-of-a-connected-trio-in-a-graph)", "[Minimum Degree of a Connected Trio in a Graph](/solution/1700-1799/1761.Minimum%20Degree%20of%20a%20Connected%20Trio%20in%20a%20Graph/README_EN.md)", "`Graph`", "Hard", ""]}, {"question_id": "1886", "frontend_question_id": "1760", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-limit-of-balls-in-a-bag", "url_en": "https://leetcode.com/problems/minimum-limit-of-balls-in-a-bag", "relative_path_cn": "/solution/1700-1799/1760.Minimum%20Limit%20of%20Balls%20in%20a%20Bag/README.md", "relative_path_en": "/solution/1700-1799/1760.Minimum%20Limit%20of%20Balls%20in%20a%20Bag/README_EN.md", "title_cn": "\u888b\u5b50\u91cc\u6700\u5c11\u6570\u76ee\u7684\u7403", "title_en": "Minimum Limit of Balls in a Bag", "question_title_slug": "minimum-limit-of-balls-in-a-bag", "content_en": "

    You are given an integer array nums where the ith bag contains nums[i] balls. You are also given an integer maxOperations.

    \n\n

    You can perform the following operation at most maxOperations times:

    \n\n
      \n\t
    • Take any bag of balls and divide it into two new bags with a positive number of balls.\n\n\t
        \n\t\t
      • For example, a bag of 5 balls can become two new bags of 1 and 4 balls, or two new bags of 2 and 3 balls.
      • \n\t
      \n\t
    • \n
    \n\n

    Your penalty is the maximum number of balls in a bag. You want to minimize your penalty after the operations.

    \n\n

    Return the minimum possible penalty after performing the operations.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [9], maxOperations = 2\nOutput: 3\nExplanation: \n- Divide the bag with 9 balls into two bags of sizes 6 and 3. [9] -> [6,3].\n- Divide the bag with 6 balls into two bags of sizes 3 and 3. [6,3] -> [3,3,3].\nThe bag with the most number of balls has 3 balls, so your penalty is 3 and you should return 3.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [2,4,8,2], maxOperations = 4\nOutput: 2\nExplanation:\n- Divide the bag with 8 balls into two bags of sizes 4 and 4. [2,4,8,2] -> [2,4,4,4,2].\n- Divide the bag with 4 balls into two bags of sizes 2 and 2. [2,4,4,4,2] -> [2,2,2,4,4,2].\n- Divide the bag with 4 balls into two bags of sizes 2 and 2. [2,2,2,4,4,2] -> [2,2,2,2,2,4,2].\n- Divide the bag with 4 balls into two bags of sizes 2 and 2. [2,2,2,2,2,4,2] -> [2,2,2,2,2,2,2,2].\nThe bag with the most number of balls has 2 balls, so your penalty is 2 an you should return 2.\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [7,17], maxOperations = 2\nOutput: 7\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • 1 <= maxOperations, nums[i] <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0nums\u00a0\uff0c\u5176\u4e2d\u00a0nums[i]\u00a0\u8868\u793a\u7b2c\u00a0i\u00a0\u4e2a\u888b\u5b50\u91cc\u7403\u7684\u6570\u76ee\u3002\u540c\u65f6\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u00a0maxOperations\u00a0\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u8fdb\u884c\u5982\u4e0b\u64cd\u4f5c\u81f3\u591a\u00a0maxOperations\u00a0\u6b21\uff1a

    \n\n
      \n\t
    • \u9009\u62e9\u4efb\u610f\u4e00\u4e2a\u888b\u5b50\uff0c\u5e76\u5c06\u888b\u5b50\u91cc\u7684\u7403\u5206\u5230\u00a02 \u4e2a\u65b0\u7684\u888b\u5b50\u4e2d\uff0c\u6bcf\u4e2a\u888b\u5b50\u91cc\u90fd\u6709 \u6b63\u6574\u6570\u00a0\u4e2a\u7403\u3002\n\n\t
        \n\t\t
      • \u6bd4\u65b9\u8bf4\uff0c\u4e00\u4e2a\u888b\u5b50\u91cc\u6709\u00a05\u00a0\u4e2a\u7403\uff0c\u4f60\u53ef\u4ee5\u628a\u5b83\u4eec\u5206\u5230\u4e24\u4e2a\u65b0\u888b\u5b50\u91cc\uff0c\u5206\u522b\u6709 1\u00a0\u4e2a\u548c 4\u00a0\u4e2a\u7403\uff0c\u6216\u8005\u5206\u522b\u6709 2\u00a0\u4e2a\u548c 3\u00a0\u4e2a\u7403\u3002
      • \n\t
      \n\t
    • \n
    \n\n

    \u4f60\u7684\u5f00\u9500\u662f\u5355\u4e2a\u888b\u5b50\u91cc\u7403\u6570\u76ee\u7684 \u6700\u5927\u503c\u00a0\uff0c\u4f60\u60f3\u8981 \u6700\u5c0f\u5316\u00a0\u5f00\u9500\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u8fdb\u884c\u4e0a\u8ff0\u64cd\u4f5c\u540e\u7684\u6700\u5c0f\u5f00\u9500\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [9], maxOperations = 2\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\n- \u5c06\u88c5\u6709 9 \u4e2a\u7403\u7684\u888b\u5b50\u5206\u6210\u88c5\u6709 6 \u4e2a\u548c 3 \u4e2a\u7403\u7684\u888b\u5b50\u3002[9] -> [6,3] \u3002\n- \u5c06\u88c5\u6709 6 \u4e2a\u7403\u7684\u888b\u5b50\u5206\u6210\u88c5\u6709 3 \u4e2a\u548c 3 \u4e2a\u7403\u7684\u888b\u5b50\u3002[6,3] -> [3,3,3] \u3002\n\u88c5\u6709\u6700\u591a\u7403\u7684\u888b\u5b50\u91cc\u88c5\u6709 3 \u4e2a\u7403\uff0c\u6240\u4ee5\u5f00\u9500\u4e3a 3 \u5e76\u8fd4\u56de 3 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [2,4,8,2], maxOperations = 4\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n- \u5c06\u88c5\u6709 8 \u4e2a\u7403\u7684\u888b\u5b50\u5206\u6210\u88c5\u6709 4 \u4e2a\u548c 4 \u4e2a\u7403\u7684\u888b\u5b50\u3002[2,4,8,2] -> [2,4,4,4,2] \u3002\n- \u5c06\u88c5\u6709 4 \u4e2a\u7403\u7684\u888b\u5b50\u5206\u6210\u88c5\u6709 2 \u4e2a\u548c 2 \u4e2a\u7403\u7684\u888b\u5b50\u3002[2,4,4,4,2] -> [2,2,2,4,4,2] \u3002\n- \u5c06\u88c5\u6709 4 \u4e2a\u7403\u7684\u888b\u5b50\u5206\u6210\u88c5\u6709 2 \u4e2a\u548c 2 \u4e2a\u7403\u7684\u888b\u5b50\u3002[2,2,2,4,4,2] -> [2,2,2,2,2,4,2] \u3002\n- \u5c06\u88c5\u6709 4 \u4e2a\u7403\u7684\u888b\u5b50\u5206\u6210\u88c5\u6709 2 \u4e2a\u548c 2 \u4e2a\u7403\u7684\u888b\u5b50\u3002[2,2,2,2,2,4,2] -> [2,2,2,2,2,2,2,2] \u3002\n\u88c5\u6709\u6700\u591a\u7403\u7684\u888b\u5b50\u91cc\u88c5\u6709 2 \u4e2a\u7403\uff0c\u6240\u4ee5\u5f00\u9500\u4e3a 2 \u5e76\u8fd4\u56de 2 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [7,17], maxOperations = 2\n\u8f93\u51fa\uff1a7\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • 1 <= maxOperations, nums[i] <= 109
    • \n
    \n", "tags_en": ["Heap", "Binary Search"], "tags_cn": ["\u5806", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minimumSize(vector& nums, int maxOperations) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minimumSize(int[] nums, int maxOperations) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimumSize(self, nums, maxOperations):\n \"\"\"\n :type nums: List[int]\n :type maxOperations: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimumSize(self, nums: List[int], maxOperations: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minimumSize(int* nums, int numsSize, int maxOperations){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinimumSize(int[] nums, int maxOperations) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} maxOperations\n * @return {number}\n */\nvar minimumSize = function(nums, maxOperations) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} max_operations\n# @return {Integer}\ndef minimum_size(nums, max_operations)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimumSize(_ nums: [Int], _ maxOperations: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimumSize(nums []int, maxOperations int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimumSize(nums: Array[Int], maxOperations: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimumSize(nums: IntArray, maxOperations: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimum_size(nums: Vec, max_operations: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $maxOperations\n * @return Integer\n */\n function minimumSize($nums, $maxOperations) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimumSize(nums: number[], maxOperations: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimum-size nums maxOperations)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1760](https://leetcode-cn.com/problems/minimum-limit-of-balls-in-a-bag)", "[\u888b\u5b50\u91cc\u6700\u5c11\u6570\u76ee\u7684\u7403](/solution/1700-1799/1760.Minimum%20Limit%20of%20Balls%20in%20a%20Bag/README.md)", "`\u5806`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1760](https://leetcode.com/problems/minimum-limit-of-balls-in-a-bag)", "[Minimum Limit of Balls in a Bag](/solution/1700-1799/1760.Minimum%20Limit%20of%20Balls%20in%20a%20Bag/README_EN.md)", "`Heap`,`Binary Search`", "Medium", ""]}, {"question_id": "1885", "frontend_question_id": "1759", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-number-of-homogenous-substrings", "url_en": "https://leetcode.com/problems/count-number-of-homogenous-substrings", "relative_path_cn": "/solution/1700-1799/1759.Count%20Number%20of%20Homogenous%20Substrings/README.md", "relative_path_en": "/solution/1700-1799/1759.Count%20Number%20of%20Homogenous%20Substrings/README_EN.md", "title_cn": "\u7edf\u8ba1\u540c\u6784\u5b50\u5b57\u7b26\u4e32\u7684\u6570\u76ee", "title_en": "Count Number of Homogenous Substrings", "question_title_slug": "count-number-of-homogenous-substrings", "content_en": "

    Given a string s, return the number of homogenous substrings of s. Since the answer may be too large, return it modulo 109 + 7.

    \r\n\r\n

    A string is homogenous if all the characters of the string are the same.

    \r\n\r\n

    A substring is a contiguous sequence of characters within a string.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: s = "abbcccaa"\r\nOutput: 13\r\nExplanation: The homogenous substrings are listed as below:\r\n"a"   appears 3 times.\r\n"aa"  appears 1 time.\r\n"b"   appears 2 times.\r\n"bb"  appears 1 time.\r\n"c"   appears 3 times.\r\n"cc"  appears 2 times.\r\n"ccc" appears 1 time.\r\n3 + 1 + 2 + 1 + 3 + 2 + 1 = 13.
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: s = "xy"\r\nOutput: 2\r\nExplanation: The homogenous substrings are "x" and "y".
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: s = "zzzzz"\r\nOutput: 15\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= s.length <= 105
    • \r\n\t
    • s consists of lowercase letters.
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \uff0c\u8fd4\u56de s \u4e2d \u540c\u6784\u5b50\u5b57\u7b26\u4e32 \u7684\u6570\u76ee\u3002\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u5f88\u5927\uff0c\u53ea\u9700\u8fd4\u56de\u5bf9 109 + 7 \u53d6\u4f59 \u540e\u7684\u7ed3\u679c\u3002

    \n\n

    \u540c\u6784\u5b57\u7b26\u4e32 \u7684\u5b9a\u4e49\u4e3a\uff1a\u5982\u679c\u4e00\u4e2a\u5b57\u7b26\u4e32\u4e2d\u7684\u6240\u6709\u5b57\u7b26\u90fd\u76f8\u540c\uff0c\u90a3\u4e48\u8be5\u5b57\u7b26\u4e32\u5c31\u662f\u540c\u6784\u5b57\u7b26\u4e32\u3002

    \n\n

    \u5b50\u5b57\u7b26\u4e32 \u662f\u5b57\u7b26\u4e32\u4e2d\u7684\u4e00\u4e2a\u8fde\u7eed\u5b57\u7b26\u5e8f\u5217\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1as = \"abbcccaa\"\n\u8f93\u51fa\uff1a13\n\u89e3\u91ca\uff1a\u540c\u6784\u5b50\u5b57\u7b26\u4e32\u5982\u4e0b\u6240\u5217\uff1a\n\"a\"   \u51fa\u73b0 3 \u6b21\u3002\n\"aa\"  \u51fa\u73b0 1 \u6b21\u3002\n\"b\"   \u51fa\u73b0 2 \u6b21\u3002\n\"bb\"  \u51fa\u73b0 1 \u6b21\u3002\n\"c\"   \u51fa\u73b0 3 \u6b21\u3002\n\"cc\"  \u51fa\u73b0 2 \u6b21\u3002\n\"ccc\" \u51fa\u73b0 1 \u6b21\u3002\n3 + 1 + 2 + 1 + 3 + 2 + 1 = 13
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1as = \"xy\"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u540c\u6784\u5b50\u5b57\u7b26\u4e32\u662f \"x\" \u548c \"y\" \u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1as = \"zzzzz\"\n\u8f93\u51fa\uff1a15\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 105
    • \n\t
    • s \u7531\u5c0f\u5199\u5b57\u7b26\u4e32\u7ec4\u6210
    • \n
    \n", "tags_en": ["Greedy", "String"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countHomogenous(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countHomogenous(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countHomogenous(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countHomogenous(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countHomogenous(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountHomogenous(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar countHomogenous = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef count_homogenous(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countHomogenous(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countHomogenous(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countHomogenous(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countHomogenous(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_homogenous(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function countHomogenous($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countHomogenous(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-homogenous s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1759](https://leetcode-cn.com/problems/count-number-of-homogenous-substrings)", "[\u7edf\u8ba1\u540c\u6784\u5b50\u5b57\u7b26\u4e32\u7684\u6570\u76ee](/solution/1700-1799/1759.Count%20Number%20of%20Homogenous%20Substrings/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1759](https://leetcode.com/problems/count-number-of-homogenous-substrings)", "[Count Number of Homogenous Substrings](/solution/1700-1799/1759.Count%20Number%20of%20Homogenous%20Substrings/README_EN.md)", "`Greedy`,`String`", "Medium", ""]}, {"question_id": "1884", "frontend_question_id": "1758", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-changes-to-make-alternating-binary-string", "url_en": "https://leetcode.com/problems/minimum-changes-to-make-alternating-binary-string", "relative_path_cn": "/solution/1700-1799/1758.Minimum%20Changes%20To%20Make%20Alternating%20Binary%20String/README.md", "relative_path_en": "/solution/1700-1799/1758.Minimum%20Changes%20To%20Make%20Alternating%20Binary%20String/README_EN.md", "title_cn": "\u751f\u6210\u4ea4\u66ff\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32\u7684\u6700\u5c11\u64cd\u4f5c\u6570", "title_en": "Minimum Changes To Make Alternating Binary String", "question_title_slug": "minimum-changes-to-make-alternating-binary-string", "content_en": "

    You are given a string s consisting only of the characters '0' and '1'. In one operation, you can change any '0' to '1' or vice versa.

    \n\n

    The string is called alternating if no two adjacent characters are equal. For example, the string "010" is alternating, while the string "0100" is not.

    \n\n

    Return the minimum number of operations needed to make s alternating.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "0100"\nOutput: 1\nExplanation: If you change the last character to '1', s will be "0101", which is alternating.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "10"\nOutput: 0\nExplanation: s is already alternating.\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "1111"\nOutput: 2\nExplanation: You need two operations to reach "0101" or "1010".\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 104
    • \n\t
    • s[i] is either '0' or '1'.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u4ec5\u7531\u5b57\u7b26 '0' \u548c '1' \u7ec4\u6210\u7684\u5b57\u7b26\u4e32 s \u3002\u4e00\u6b65\u64cd\u4f5c\u4e2d\uff0c\u4f60\u53ef\u4ee5\u5c06\u4efb\u4e00 '0' \u53d8\u6210 '1' \uff0c\u6216\u8005\u5c06 '1' \u53d8\u6210 '0' \u3002

    \n\n

    \u4ea4\u66ff\u5b57\u7b26\u4e32 \u5b9a\u4e49\u4e3a\uff1a\u5982\u679c\u5b57\u7b26\u4e32\u4e2d\u4e0d\u5b58\u5728\u76f8\u90bb\u4e24\u4e2a\u5b57\u7b26\u76f8\u7b49\u7684\u60c5\u51b5\uff0c\u90a3\u4e48\u8be5\u5b57\u7b26\u4e32\u5c31\u662f\u4ea4\u66ff\u5b57\u7b26\u4e32\u3002\u4f8b\u5982\uff0c\u5b57\u7b26\u4e32 \"010\" \u662f\u4ea4\u66ff\u5b57\u7b26\u4e32\uff0c\u800c\u5b57\u7b26\u4e32 \"0100\" \u4e0d\u662f\u3002

    \n\n

    \u8fd4\u56de\u4f7f s \u53d8\u6210 \u4ea4\u66ff\u5b57\u7b26\u4e32 \u6240\u9700\u7684 \u6700\u5c11 \u64cd\u4f5c\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1as = \"0100\"\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u5982\u679c\u5c06\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\u53d8\u4e3a '1' \uff0cs \u5c31\u53d8\u6210 \"0101\" \uff0c\u5373\u7b26\u5408\u4ea4\u66ff\u5b57\u7b26\u4e32\u5b9a\u4e49\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1as = \"10\"\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1as \u5df2\u7ecf\u662f\u4ea4\u66ff\u5b57\u7b26\u4e32\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1as = \"1111\"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u9700\u8981 2 \u6b65\u64cd\u4f5c\u5f97\u5230 \"0101\" \u6216 \"1010\" \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 104
    • \n\t
    • s[i] \u662f '0' \u6216 '1'
    • \n
    \n", "tags_en": ["Greedy", "Array"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minOperations(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minOperations(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minOperations(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minOperations(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minOperations(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinOperations(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar minOperations = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef min_operations(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minOperations(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minOperations(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minOperations(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minOperations(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_operations(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function minOperations($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minOperations(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-operations s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1758](https://leetcode-cn.com/problems/minimum-changes-to-make-alternating-binary-string)", "[\u751f\u6210\u4ea4\u66ff\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32\u7684\u6700\u5c11\u64cd\u4f5c\u6570](/solution/1700-1799/1758.Minimum%20Changes%20To%20Make%20Alternating%20Binary%20String/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1758](https://leetcode.com/problems/minimum-changes-to-make-alternating-binary-string)", "[Minimum Changes To Make Alternating Binary String](/solution/1700-1799/1758.Minimum%20Changes%20To%20Make%20Alternating%20Binary%20String/README_EN.md)", "`Greedy`,`Array`", "Easy", ""]}, {"question_id": "1883", "frontend_question_id": "1740", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/find-distance-in-a-binary-tree", "url_en": "https://leetcode.com/problems/find-distance-in-a-binary-tree", "relative_path_cn": "/solution/1700-1799/1740.Find%20Distance%20in%20a%20Binary%20Tree/README.md", "relative_path_en": "/solution/1700-1799/1740.Find%20Distance%20in%20a%20Binary%20Tree/README_EN.md", "title_cn": "\u627e\u5230\u4e8c\u53c9\u6811\u4e2d\u7684\u8ddd\u79bb", "title_en": "Find Distance in a Binary Tree", "question_title_slug": "find-distance-in-a-binary-tree", "content_en": "

    Given the root of a binary tree and two integers p and q, return the distance between the nodes of value p and value q in the tree.

    \n\n

    The distance between two nodes is the number of edges on the path from one to the other.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 0\nOutput: 3\nExplanation: There are 3 edges between 5 and 0: 5-3-1-0.
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 7\nOutput: 2\nExplanation: There are 2 edges between 5 and 7: 5-2-7.
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 5\nOutput: 0\nExplanation: The distance between a node and itself is 0.
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 104].
    • \n\t
    • 0 <= Node.val <= 109
    • \n\t
    • All Node.val are unique.
    • \n\t
    • p and q are values in the tree.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u68f5\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9 root \u4ee5\u53ca\u4e24\u4e2a\u6574\u6570 p \u548c q \uff0c\u8fd4\u56de\u8be5\u4e8c\u53c9\u6811\u4e2d\u503c\u4e3a p \u7684\u7ed3\u70b9\u4e0e\u503c\u4e3a q \u7684\u7ed3\u70b9\u95f4\u7684 \u8ddd\u79bb \u3002

    \n\n

    \u4e24\u4e2a\u7ed3\u70b9\u95f4\u7684 \u8ddd\u79bb \u5c31\u662f\u4ece\u4e00\u4e2a\u7ed3\u70b9\u5230\u53e6\u4e00\u4e2a\u7ed3\u70b9\u7684\u8def\u5f84\u4e0a\u8fb9\u7684\u6570\u76ee\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 0\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u5728 5 \u548c 0 \u4e4b\u95f4\u6709 3 \u6761\u8fb9\uff1a5-3-1-0
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 7\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5728 5 \u548c 7 \u4e4b\u95f4\u6709 2 \u6761\u8fb9\uff1a5-2-7
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 5\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u4e00\u4e2a\u7ed3\u70b9\u4e0e\u5b83\u672c\u8eab\u4e4b\u95f4\u7684\u8ddd\u79bb\u4e3a 0
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u7ed3\u70b9\u4e2a\u6570\u7684\u8303\u56f4\u5728\u00a0[1, 104].
    • \n\t
    • 0 <= Node.val <= 109
    • \n\t
    • \u6811\u4e2d\u6240\u6709\u7ed3\u70b9\u7684\u503c\u90fd\u662f\u552f\u4e00\u7684.
    • \n\t
    • p \u548cq \u662f\u6811\u4e2d\u7ed3\u70b9\u7684\u503c.
    • \n
    \n", "tags_en": ["Tree", "Depth-first Search", "Breadth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int findDistance(TreeNode* root, int p, int q) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int findDistance(TreeNode root, int p, int q) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def findDistance(self, root, p, q):\n \"\"\"\n :type root: TreeNode\n :type p: int\n :type q: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def findDistance(self, root: TreeNode, p: int, q: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint findDistance(struct TreeNode* root, int p, int q){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int FindDistance(TreeNode root, int p, int q) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number} p\n * @param {number} q\n * @return {number}\n */\nvar findDistance = function(root, p, q) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @param {Integer} p\n# @param {Integer} q\n# @return {Integer}\ndef find_distance(root, p, q)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func findDistance(_ root: TreeNode?, _ p: Int, _ q: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc findDistance(root *TreeNode, p int, q int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def findDistance(root: TreeNode, p: Int, q: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun findDistance(root: TreeNode?, p: Int, q: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn find_distance(root: Option>>, p: i32, q: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param Integer $p\n * @param Integer $q\n * @return Integer\n */\n function findDistance($root, $p, $q) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction findDistance(root: TreeNode | null, p: number, q: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (find-distance root p q)\n (-> (or/c tree-node? #f) exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1740](https://leetcode-cn.com/problems/find-distance-in-a-binary-tree)", "[\u627e\u5230\u4e8c\u53c9\u6811\u4e2d\u7684\u8ddd\u79bb](/solution/1700-1799/1740.Find%20Distance%20in%20a%20Binary%20Tree/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1740](https://leetcode.com/problems/find-distance-in-a-binary-tree)", "[Find Distance in a Binary Tree](/solution/1700-1799/1740.Find%20Distance%20in%20a%20Binary%20Tree/README_EN.md)", "`Tree`,`Depth-first Search`,`Breadth-first Search`", "Medium", "\ud83d\udd12"]}, {"question_id": "1882", "frontend_question_id": "1731", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/the-number-of-employees-which-report-to-each-employee", "url_en": "https://leetcode.com/problems/the-number-of-employees-which-report-to-each-employee", "relative_path_cn": "/solution/1700-1799/1731.The%20Number%20of%20Employees%20Which%20Report%20to%20Each%20Employee/README.md", "relative_path_en": "/solution/1700-1799/1731.The%20Number%20of%20Employees%20Which%20Report%20to%20Each%20Employee/README_EN.md", "title_cn": "\u6bcf\u4f4d\u7ecf\u7406\u7684\u4e0b\u5c5e\u5458\u5de5\u6570\u91cf", "title_en": "The Number of Employees Which Report to Each Employee", "question_title_slug": "the-number-of-employees-which-report-to-each-employee", "content_en": "

    Table: Employees

    \n\n
    \n+-------------+----------+\n| Column Name | Type     |\n+-------------+----------+\n| employee_id | int      |\n| name        | varchar  |\n| reports_to  | int      |\n| age         | int      |\n+-------------+----------+\nemployee_id is the primary key for this table.\nThis table contains information about the employees and the id of the manager they report to. Some employees do not report to anyone (reports_to is null). \n
    \n\n

     

    \n\n

    For this problem, we will consider a manager an employee who has at least 1 other employee reporting to them.

    \n\n

    Write an SQL query to report the ids and the names of all managers, the number of employees who report directly to them, and the average age of the reports rounded to the nearest integer.

    \n\n

    Return the result table ordered by employee_id.

    \n\n

    The query result format is in the following example:

    \n\n

     

    \n\n
    \nEmployees table:\n+-------------+---------+------------+-----+\n| employee_id | name    | reports_to | age |\n+-------------+---------+------------+-----+\n| 9           | Hercy   | null       | 43  |\n| 6           | Alice   | 9          | 41  |\n| 4           | Bob     | 9          | 36  |\n| 2           | Winston | null       | 37  |\n+-------------+---------+------------+-----+\n\nResult table:\n+-------------+-------+---------------+-------------+\n| employee_id | name  | reports_count | average_age |\n+-------------+-------+---------------+-------------+\n| 9           | Hercy | 2             | 39          |\n+-------------+-------+---------------+-------------+\nHercy has 2 people report directly to him, Alice and Bob. Their average age is (41+36)/2 = 38.5, which is 39 after rounding it to the nearest integer.\n
    \n", "content_cn": "

    Table: Employees

    \n\n
    +-------------+----------+\n| Column Name | Type     |\n+-------------+----------+\n| employee_id | int      |\n| name        | varchar  |\n| reports_to  | int      |\n| age         | int      |\n+-------------+----------+\nemployee_id \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e.\n\u8be5\u8868\u5305\u542b\u5458\u5de5\u4ee5\u53ca\u9700\u8981\u542c\u53d6\u4ed6\u4eec\u6c47\u62a5\u7684\u4e0a\u7ea7\u7ecf\u7406\u7684ID\u7684\u4fe1\u606f\u3002 \u6709\u4e9b\u5458\u5de5\u4e0d\u9700\u8981\u5411\u4efb\u4f55\u4eba\u6c47\u62a5\uff08reports_to \u4e3a\u7a7a\uff09\u3002\n
    \n\n

    \u00a0

    \n\n

    \u5bf9\u4e8e\u6b64\u95ee\u9898\uff0c\u6211\u4eec\u5c06\u81f3\u5c11\u6709\u4e00\u4e2a\u5176\u4ed6\u5458\u5de5\u9700\u8981\u5411\u4ed6\u6c47\u62a5\u7684\u5458\u5de5\uff0c\u89c6\u4e3a\u4e00\u4e2a\u7ecf\u7406\u3002

    \n\n

    \u7f16\u5199SQL\u67e5\u8be2\u9700\u8981\u542c\u53d6\u6c47\u62a5\u7684\u6240\u6709\u7ecf\u7406\u7684ID\u3001\u540d\u79f0\u3001\u76f4\u63a5\u5411\u8be5\u7ecf\u7406\u6c47\u62a5\u7684\u5458\u5de5\u4eba\u6570\uff0c\u4ee5\u53ca\u8fd9\u4e9b\u5458\u5de5\u7684\u5e73\u5747\u5e74\u9f84\uff0c\u5176\u4e2d\u8be5\u5e73\u5747\u5e74\u9f84\u9700\u8981\u56db\u820d\u4e94\u5165\u5230\u6700\u63a5\u8fd1\u7684\u6574\u6570\u3002

    \n\n

    \u8fd4\u56de\u7684\u7ed3\u679c\u96c6\u9700\u8981\u6309\u7167\u00a0employee_id \u8fdb\u884c\u6392\u5e8f\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u7684\u683c\u5f0f\u5982\u4e0b\uff1a

    \n\n

    \u00a0

    \n\n
    Employees table:\n+-------------+---------+------------+-----+\n| employee_id | name    | reports_to | age |\n+-------------+---------+------------+-----+\n| 9           | Hercy   | null       | 43  |\n| 6           | Alice   | 9          | 41  |\n| 4           | Bob     | 9          | 36  |\n| 2           | Winston | null       | 37  |\n+-------------+---------+------------+-----+\n\nResult table:\n+-------------+-------+---------------+-------------+\n| employee_id | name  | reports_count | average_age |\n+-------------+-------+---------------+-------------+\n| 9           | Hercy | 2             | 39          |\n+-------------+-------+---------------+-------------+\nHercy \u6709\u4e24\u4e2a\u9700\u8981\u5411\u4ed6\u6c47\u62a5\u7684\u5458\u5de5, \u4ed6\u4eec\u662f Alice and Bob. \u4ed6\u4eec\u7684\u5e73\u5747\u5e74\u9f84\u662f (41+36)/2 = 38.5, \u56db\u820d\u4e94\u5165\u7684\u7ed3\u679c\u662f 39.\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1731](https://leetcode-cn.com/problems/the-number-of-employees-which-report-to-each-employee)", "[\u6bcf\u4f4d\u7ecf\u7406\u7684\u4e0b\u5c5e\u5458\u5de5\u6570\u91cf](/solution/1700-1799/1731.The%20Number%20of%20Employees%20Which%20Report%20to%20Each%20Employee/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1731](https://leetcode.com/problems/the-number-of-employees-which-report-to-each-employee)", "[The Number of Employees Which Report to Each Employee](/solution/1700-1799/1731.The%20Number%20of%20Employees%20Which%20Report%20to%20Each%20Employee/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1881", "frontend_question_id": "1755", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/closest-subsequence-sum", "url_en": "https://leetcode.com/problems/closest-subsequence-sum", "relative_path_cn": "/solution/1700-1799/1755.Closest%20Subsequence%20Sum/README.md", "relative_path_en": "/solution/1700-1799/1755.Closest%20Subsequence%20Sum/README_EN.md", "title_cn": "\u6700\u63a5\u8fd1\u76ee\u6807\u503c\u7684\u5b50\u5e8f\u5217\u548c", "title_en": "Closest Subsequence Sum", "question_title_slug": "closest-subsequence-sum", "content_en": "

    You are given an integer array nums and an integer goal.

    \n\n

    You want to choose a subsequence of nums such that the sum of its elements is the closest possible to goal. That is, if the sum of the subsequence's elements is sum, then you want to minimize the absolute difference abs(sum - goal).

    \n\n

    Return the minimum possible value of abs(sum - goal).

    \n\n

    Note that a subsequence of an array is an array formed by removing some elements (possibly all or none) of the original array.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [5,-7,3,5], goal = 6\nOutput: 0\nExplanation: Choose the whole array as a subsequence, with a sum of 6.\nThis is equal to the goal, so the absolute difference is 0.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [7,-9,15,-2], goal = -5\nOutput: 1\nExplanation: Choose the subsequence [7,-9,-2], with a sum of -4.\nThe absolute difference is abs(-4 - (-5)) = abs(1) = 1, which is the minimum.\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [1,2,3], goal = -7\nOutput: 7\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 40
    • \n\t
    • -107 <= nums[i] <= 107
    • \n\t
    • -109 <= goal <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \u548c\u4e00\u4e2a\u76ee\u6807\u503c goal \u3002

    \n\n

    \u4f60\u9700\u8981\u4ece nums \u4e2d\u9009\u51fa\u4e00\u4e2a\u5b50\u5e8f\u5217\uff0c\u4f7f\u5b50\u5e8f\u5217\u5143\u7d20\u603b\u548c\u6700\u63a5\u8fd1 goal \u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u5982\u679c\u5b50\u5e8f\u5217\u5143\u7d20\u548c\u4e3a sum \uff0c\u4f60\u9700\u8981 \u6700\u5c0f\u5316\u7edd\u5bf9\u5dee abs(sum - goal) \u3002

    \n\n

    \u8fd4\u56de abs(sum - goal) \u53ef\u80fd\u7684 \u6700\u5c0f\u503c \u3002

    \n\n

    \u6ce8\u610f\uff0c\u6570\u7ec4\u7684\u5b50\u5e8f\u5217\u662f\u901a\u8fc7\u79fb\u9664\u539f\u59cb\u6570\u7ec4\u4e2d\u7684\u67d0\u4e9b\u5143\u7d20\uff08\u53ef\u80fd\u5168\u90e8\u6216\u65e0\uff09\u800c\u5f62\u6210\u7684\u6570\u7ec4\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [5,-7,3,5], goal = 6\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u9009\u62e9\u6574\u4e2a\u6570\u7ec4\u4f5c\u4e3a\u9009\u51fa\u7684\u5b50\u5e8f\u5217\uff0c\u5143\u7d20\u548c\u4e3a 6 \u3002\n\u5b50\u5e8f\u5217\u548c\u4e0e\u76ee\u6807\u503c\u76f8\u7b49\uff0c\u6240\u4ee5\u7edd\u5bf9\u5dee\u4e3a 0 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [7,-9,15,-2], goal = -5\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u9009\u51fa\u5b50\u5e8f\u5217 [7,-9,-2] \uff0c\u5143\u7d20\u548c\u4e3a -4 \u3002\n\u7edd\u5bf9\u5dee\u4e3a abs(-4 - (-5)) = abs(1) = 1 \uff0c\u662f\u53ef\u80fd\u7684\u6700\u5c0f\u503c\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,2,3], goal = -7\n\u8f93\u51fa\uff1a7\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 40
    • \n\t
    • -107 <= nums[i] <= 107
    • \n\t
    • -109 <= goal <= 109
    • \n
    \n", "tags_en": ["Divide and Conquer"], "tags_cn": ["\u5206\u6cbb\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minAbsDifference(vector& nums, int goal) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minAbsDifference(int[] nums, int goal) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minAbsDifference(self, nums, goal):\n \"\"\"\n :type nums: List[int]\n :type goal: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minAbsDifference(self, nums: List[int], goal: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minAbsDifference(int* nums, int numsSize, int goal){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinAbsDifference(int[] nums, int goal) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} goal\n * @return {number}\n */\nvar minAbsDifference = function(nums, goal) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} goal\n# @return {Integer}\ndef min_abs_difference(nums, goal)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minAbsDifference(_ nums: [Int], _ goal: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minAbsDifference(nums []int, goal int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minAbsDifference(nums: Array[Int], goal: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minAbsDifference(nums: IntArray, goal: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_abs_difference(nums: Vec, goal: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $goal\n * @return Integer\n */\n function minAbsDifference($nums, $goal) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minAbsDifference(nums: number[], goal: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-abs-difference nums goal)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1755](https://leetcode-cn.com/problems/closest-subsequence-sum)", "[\u6700\u63a5\u8fd1\u76ee\u6807\u503c\u7684\u5b50\u5e8f\u5217\u548c](/solution/1700-1799/1755.Closest%20Subsequence%20Sum/README.md)", "`\u5206\u6cbb\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[1755](https://leetcode.com/problems/closest-subsequence-sum)", "[Closest Subsequence Sum](/solution/1700-1799/1755.Closest%20Subsequence%20Sum/README_EN.md)", "`Divide and Conquer`", "Hard", ""]}, {"question_id": "1880", "frontend_question_id": "1754", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/largest-merge-of-two-strings", "url_en": "https://leetcode.com/problems/largest-merge-of-two-strings", "relative_path_cn": "/solution/1700-1799/1754.Largest%20Merge%20Of%20Two%20Strings/README.md", "relative_path_en": "/solution/1700-1799/1754.Largest%20Merge%20Of%20Two%20Strings/README_EN.md", "title_cn": "\u6784\u9020\u5b57\u5178\u5e8f\u6700\u5927\u7684\u5408\u5e76\u5b57\u7b26\u4e32", "title_en": "Largest Merge Of Two Strings", "question_title_slug": "largest-merge-of-two-strings", "content_en": "

    You are given two strings word1 and word2. You want to construct a string merge in the following way: while either word1 or word2 are non-empty, choose one of the following options:

    \n\n
      \n\t
    • If word1 is non-empty, append the first character in word1 to merge and delete it from word1.\n\n\t
        \n\t\t
      • For example, if word1 = "abc" and merge = "dv", then after choosing this operation, word1 = "bc" and merge = "dva".
      • \n\t
      \n\t
    • \n\t
    • If word2 is non-empty, append the first character in word2 to merge and delete it from word2.\n\t
        \n\t\t
      • For example, if word2 = "abc" and merge = "", then after choosing this operation, word2 = "bc" and merge = "a".
      • \n\t
      \n\t
    • \n
    \n\n

    Return the lexicographically largest merge you can construct.

    \n\n

    A string a is lexicographically larger than a string b (of the same length) if in the first position where a and b differ, a has a character strictly larger than the corresponding character in b. For example, "abcd" is lexicographically larger than "abcc" because the first position they differ is at the fourth character, and d is greater than c.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: word1 = "cabaa", word2 = "bcaaa"\nOutput: "cbcabaaaaa"\nExplanation: One way to get the lexicographically largest merge is:\n- Take from word1: merge = "c", word1 = "abaa", word2 = "bcaaa"\n- Take from word2: merge = "cb", word1 = "abaa", word2 = "caaa"\n- Take from word2: merge = "cbc", word1 = "abaa", word2 = "aaa"\n- Take from word1: merge = "cbca", word1 = "baa", word2 = "aaa"\n- Take from word1: merge = "cbcab", word1 = "aa", word2 = "aaa"\n- Append the remaining 5 a's from word1 and word2 at the end of merge.\n
    \n\n

    Example 2:

    \n\n
    \nInput: word1 = "abcabc", word2 = "abdcaba"\nOutput: "abdcabcabcaba"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= word1.length, word2.length <= 3000
    • \n\t
    • word1 and word2 consist only of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u5b57\u7b26\u4e32 word1 \u548c word2 \u3002\u4f60\u9700\u8981\u6309\u4e0b\u8ff0\u65b9\u5f0f\u6784\u9020\u4e00\u4e2a\u65b0\u5b57\u7b26\u4e32 merge \uff1a\u5982\u679c word1 \u6216 word2 \u975e\u7a7a\uff0c\u9009\u62e9 \u4e0b\u9762\u9009\u9879\u4e4b\u4e00 \u7ee7\u7eed\u64cd\u4f5c\uff1a

    \n\n
      \n\t
    • \u5982\u679c word1 \u975e\u7a7a\uff0c\u5c06 word1 \u4e2d\u7684\u7b2c\u4e00\u4e2a\u5b57\u7b26\u9644\u52a0\u5230 merge \u7684\u672b\u5c3e\uff0c\u5e76\u5c06\u5176\u4ece word1 \u4e2d\u79fb\u9664\u3002\n\n\t
        \n\t\t
      • \u4f8b\u5982\uff0cword1 = \"abc\" \u4e14 merge = \"dv\" \uff0c\u5728\u6267\u884c\u6b64\u9009\u9879\u64cd\u4f5c\u4e4b\u540e\uff0cword1 = \"bc\" \uff0c\u540c\u65f6 merge = \"dva\" \u3002
      • \n\t
      \n\t
    • \n\t
    • \u5982\u679c word2 \u975e\u7a7a\uff0c\u5c06 word2 \u4e2d\u7684\u7b2c\u4e00\u4e2a\u5b57\u7b26\u9644\u52a0\u5230 merge \u7684\u672b\u5c3e\uff0c\u5e76\u5c06\u5176\u4ece word2 \u4e2d\u79fb\u9664\u3002\n\t
        \n\t\t
      • \u4f8b\u5982\uff0cword2 = \"abc\" \u4e14 merge = \"\" \uff0c\u5728\u6267\u884c\u6b64\u9009\u9879\u64cd\u4f5c\u4e4b\u540e\uff0cword2 = \"bc\" \uff0c\u540c\u65f6 merge = \"a\" \u3002
      • \n\t
      \n\t
    • \n
    \n\n

    \u8fd4\u56de\u4f60\u53ef\u4ee5\u6784\u9020\u7684\u5b57\u5178\u5e8f \u6700\u5927 \u7684\u5408\u5e76\u5b57\u7b26\u4e32 merge \u3002

    \n\n

    \u957f\u5ea6\u76f8\u540c\u7684\u4e24\u4e2a\u5b57\u7b26\u4e32 a \u548c b \u6bd4\u8f83\u5b57\u5178\u5e8f\u5927\u5c0f\uff0c\u5982\u679c\u5728 a \u548c b \u51fa\u73b0\u4e0d\u540c\u7684\u7b2c\u4e00\u4e2a\u4f4d\u7f6e\uff0ca \u4e2d\u5b57\u7b26\u5728\u5b57\u6bcd\u8868\u4e2d\u7684\u51fa\u73b0\u987a\u5e8f\u4f4d\u4e8e b \u4e2d\u76f8\u5e94\u5b57\u7b26\u4e4b\u540e\uff0c\u5c31\u8ba4\u4e3a\u5b57\u7b26\u4e32 a \u6309\u5b57\u5178\u5e8f\u6bd4\u5b57\u7b26\u4e32 b \u66f4\u5927\u3002\u4f8b\u5982\uff0c\"abcd\" \u6309\u5b57\u5178\u5e8f\u6bd4 \"abcc\" \u66f4\u5927\uff0c\u56e0\u4e3a\u4e24\u4e2a\u5b57\u7b26\u4e32\u51fa\u73b0\u4e0d\u540c\u7684\u7b2c\u4e00\u4e2a\u4f4d\u7f6e\u662f\u7b2c\u56db\u4e2a\u5b57\u7b26\uff0c\u800c d \u5728\u5b57\u6bcd\u8868\u4e2d\u7684\u51fa\u73b0\u987a\u5e8f\u4f4d\u4e8e c \u4e4b\u540e\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aword1 = \"cabaa\", word2 = \"bcaaa\"\n\u8f93\u51fa\uff1a\"cbcabaaaaa\"\n\u89e3\u91ca\uff1a\u6784\u9020\u5b57\u5178\u5e8f\u6700\u5927\u7684\u5408\u5e76\u5b57\u7b26\u4e32\uff0c\u53ef\u884c\u7684\u4e00\u79cd\u65b9\u6cd5\u5982\u4e0b\u6240\u793a\uff1a\n- \u4ece word1 \u4e2d\u53d6\u7b2c\u4e00\u4e2a\u5b57\u7b26\uff1amerge = \"c\"\uff0cword1 = \"abaa\"\uff0cword2 = \"bcaaa\"\n- \u4ece word2 \u4e2d\u53d6\u7b2c\u4e00\u4e2a\u5b57\u7b26\uff1amerge = \"cb\"\uff0cword1 = \"abaa\"\uff0cword2 = \"caaa\"\n- \u4ece word2 \u4e2d\u53d6\u7b2c\u4e00\u4e2a\u5b57\u7b26\uff1amerge = \"cbc\"\uff0cword1 = \"abaa\"\uff0cword2 = \"aaa\"\n- \u4ece word1 \u4e2d\u53d6\u7b2c\u4e00\u4e2a\u5b57\u7b26\uff1amerge = \"cbca\"\uff0cword1 = \"baa\"\uff0cword2 = \"aaa\"\n- \u4ece word1 \u4e2d\u53d6\u7b2c\u4e00\u4e2a\u5b57\u7b26\uff1amerge = \"cbcab\"\uff0cword1 = \"aa\"\uff0cword2 = \"aaa\"\n- \u5c06 word1 \u548c word2 \u4e2d\u5269\u4e0b\u7684 5 \u4e2a a \u9644\u52a0\u5230 merge \u7684\u672b\u5c3e\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aword1 = \"abcabc\", word2 = \"abdcaba\"\n\u8f93\u51fa\uff1a\"abdcabcabcaba\"\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= word1.length, word2.length <= 3000
    • \n\t
    • word1 \u548c word2 \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u7ec4\u6210
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string largestMerge(string word1, string word2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String largestMerge(String word1, String word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def largestMerge(self, word1, word2):\n \"\"\"\n :type word1: str\n :type word2: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def largestMerge(self, word1: str, word2: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * largestMerge(char * word1, char * word2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string LargestMerge(string word1, string word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} word1\n * @param {string} word2\n * @return {string}\n */\nvar largestMerge = function(word1, word2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} word1\n# @param {String} word2\n# @return {String}\ndef largest_merge(word1, word2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func largestMerge(_ word1: String, _ word2: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func largestMerge(word1 string, word2 string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def largestMerge(word1: String, word2: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun largestMerge(word1: String, word2: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn largest_merge(word1: String, word2: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $word1\n * @param String $word2\n * @return String\n */\n function largestMerge($word1, $word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function largestMerge(word1: string, word2: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (largest-merge word1 word2)\n (-> string? string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1754](https://leetcode-cn.com/problems/largest-merge-of-two-strings)", "[\u6784\u9020\u5b57\u5178\u5e8f\u6700\u5927\u7684\u5408\u5e76\u5b57\u7b26\u4e32](/solution/1700-1799/1754.Largest%20Merge%20Of%20Two%20Strings/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1754](https://leetcode.com/problems/largest-merge-of-two-strings)", "[Largest Merge Of Two Strings](/solution/1700-1799/1754.Largest%20Merge%20Of%20Two%20Strings/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1879", "frontend_question_id": "1753", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-score-from-removing-stones", "url_en": "https://leetcode.com/problems/maximum-score-from-removing-stones", "relative_path_cn": "/solution/1700-1799/1753.Maximum%20Score%20From%20Removing%20Stones/README.md", "relative_path_en": "/solution/1700-1799/1753.Maximum%20Score%20From%20Removing%20Stones/README_EN.md", "title_cn": "\u79fb\u9664\u77f3\u5b50\u7684\u6700\u5927\u5f97\u5206", "title_en": "Maximum Score From Removing Stones", "question_title_slug": "maximum-score-from-removing-stones", "content_en": "

    You are playing a solitaire game with three piles of stones of sizes a\u200b\u200b\u200b\u200b\u200b\u200b, b,\u200b\u200b\u200b\u200b\u200b\u200b and c\u200b\u200b\u200b\u200b\u200b\u200b respectively. Each turn you choose two different non-empty piles, take one stone from each, and add 1 point to your score. The game stops when there are fewer than two non-empty piles (meaning there are no more available moves).

    \n\n

    Given three integers a\u200b\u200b\u200b\u200b\u200b, b,\u200b\u200b\u200b\u200b\u200b and c\u200b\u200b\u200b\u200b\u200b, return the maximum score you can get.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: a = 2, b = 4, c = 6\nOutput: 6\nExplanation: The starting state is (2, 4, 6). One optimal set of moves is:\n- Take from 1st and 3rd piles, state is now (1, 4, 5)\n- Take from 1st and 3rd piles, state is now (0, 4, 4)\n- Take from 2nd and 3rd piles, state is now (0, 3, 3)\n- Take from 2nd and 3rd piles, state is now (0, 2, 2)\n- Take from 2nd and 3rd piles, state is now (0, 1, 1)\n- Take from 2nd and 3rd piles, state is now (0, 0, 0)\nThere are fewer than two non-empty piles, so the game ends. Total: 6 points.\n
    \n\n

    Example 2:

    \n\n
    \nInput: a = 4, b = 4, c = 6\nOutput: 7\nExplanation: The starting state is (4, 4, 6). One optimal set of moves is:\n- Take from 1st and 2nd piles, state is now (3, 3, 6)\n- Take from 1st and 3rd piles, state is now (2, 3, 5)\n- Take from 1st and 3rd piles, state is now (1, 3, 4)\n- Take from 1st and 3rd piles, state is now (0, 3, 3)\n- Take from 2nd and 3rd piles, state is now (0, 2, 2)\n- Take from 2nd and 3rd piles, state is now (0, 1, 1)\n- Take from 2nd and 3rd piles, state is now (0, 0, 0)\nThere are fewer than two non-empty piles, so the game ends. Total: 7 points.\n
    \n\n

    Example 3:

    \n\n
    \nInput: a = 1, b = 8, c = 8\nOutput: 8\nExplanation: One optimal set of moves is to take from the 2nd and 3rd piles for 8 turns until they are empty.\nAfter that, there are fewer than two non-empty piles, so the game ends.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= a, b, c <= 105
    • \n
    \n", "content_cn": "

    \u4f60\u6b63\u5728\u73a9\u4e00\u4e2a\u5355\u4eba\u6e38\u620f\uff0c\u9762\u524d\u653e\u7f6e\u7740\u5927\u5c0f\u5206\u522b\u4e3a a\u200b\u200b\u200b\u200b\u200b\u200b\u3001b \u548c c\u200b\u200b\u200b\u200b\u200b\u200b \u7684 \u4e09\u5806 \u77f3\u5b50\u3002

    \n\n

    \u6bcf\u56de\u5408\u4f60\u90fd\u8981\u4ece\u4e24\u4e2a \u4e0d\u540c\u7684\u975e\u7a7a\u5806 \u4e2d\u53d6\u51fa\u4e00\u9897\u77f3\u5b50\uff0c\u5e76\u5728\u5f97\u5206\u4e0a\u52a0 1 \u5206\u3002\u5f53\u5b58\u5728 \u4e24\u4e2a\u6216\u66f4\u591a \u7684\u7a7a\u5806\u65f6\uff0c\u6e38\u620f\u505c\u6b62\u3002

    \n\n

    \u7ed9\u4f60\u4e09\u4e2a\u6574\u6570 a \u3001b \u548c c \uff0c\u8fd4\u56de\u53ef\u4ee5\u5f97\u5230\u7684 \u6700\u5927\u5206\u6570 \u3002

    \n\u00a0\n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aa = 2, b = 4, c = 6\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u77f3\u5b50\u8d77\u59cb\u72b6\u6001\u662f (2, 4, 6) \uff0c\u6700\u4f18\u7684\u4e00\u7ec4\u64cd\u4f5c\u662f\uff1a\n- \u4ece\u7b2c\u4e00\u548c\u7b2c\u4e09\u5806\u53d6\uff0c\u77f3\u5b50\u72b6\u6001\u73b0\u5728\u662f (1, 4, 5)\n- \u4ece\u7b2c\u4e00\u548c\u7b2c\u4e09\u5806\u53d6\uff0c\u77f3\u5b50\u72b6\u6001\u73b0\u5728\u662f (0, 4, 4)\n- \u4ece\u7b2c\u4e8c\u548c\u7b2c\u4e09\u5806\u53d6\uff0c\u77f3\u5b50\u72b6\u6001\u73b0\u5728\u662f (0, 3, 3)\n- \u4ece\u7b2c\u4e8c\u548c\u7b2c\u4e09\u5806\u53d6\uff0c\u77f3\u5b50\u72b6\u6001\u73b0\u5728\u662f (0, 2, 2)\n- \u4ece\u7b2c\u4e8c\u548c\u7b2c\u4e09\u5806\u53d6\uff0c\u77f3\u5b50\u72b6\u6001\u73b0\u5728\u662f (0, 1, 1)\n- \u4ece\u7b2c\u4e8c\u548c\u7b2c\u4e09\u5806\u53d6\uff0c\u77f3\u5b50\u72b6\u6001\u73b0\u5728\u662f (0, 0, 0)\n\u603b\u5206\uff1a6 \u5206 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aa = 4, b = 4, c = 6\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\u77f3\u5b50\u8d77\u59cb\u72b6\u6001\u662f (4, 4, 6) \uff0c\u6700\u4f18\u7684\u4e00\u7ec4\u64cd\u4f5c\u662f\uff1a\n- \u4ece\u7b2c\u4e00\u548c\u7b2c\u4e8c\u5806\u53d6\uff0c\u77f3\u5b50\u72b6\u6001\u73b0\u5728\u662f (3, 3, 6)\n- \u4ece\u7b2c\u4e00\u548c\u7b2c\u4e09\u5806\u53d6\uff0c\u77f3\u5b50\u72b6\u6001\u73b0\u5728\u662f (2, 3, 5)\n- \u4ece\u7b2c\u4e00\u548c\u7b2c\u4e09\u5806\u53d6\uff0c\u77f3\u5b50\u72b6\u6001\u73b0\u5728\u662f (1, 3, 4)\n- \u4ece\u7b2c\u4e00\u548c\u7b2c\u4e09\u5806\u53d6\uff0c\u77f3\u5b50\u72b6\u6001\u73b0\u5728\u662f (0, 3, 3)\n- \u4ece\u7b2c\u4e8c\u548c\u7b2c\u4e09\u5806\u53d6\uff0c\u77f3\u5b50\u72b6\u6001\u73b0\u5728\u662f (0, 2, 2)\n- \u4ece\u7b2c\u4e8c\u548c\u7b2c\u4e09\u5806\u53d6\uff0c\u77f3\u5b50\u72b6\u6001\u73b0\u5728\u662f (0, 1, 1)\n- \u4ece\u7b2c\u4e8c\u548c\u7b2c\u4e09\u5806\u53d6\uff0c\u77f3\u5b50\u72b6\u6001\u73b0\u5728\u662f (0, 0, 0)\n\u603b\u5206\uff1a7 \u5206 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aa = 1, b = 8, c = 8\n\u8f93\u51fa\uff1a8\n\u89e3\u91ca\uff1a\u6700\u4f18\u7684\u4e00\u7ec4\u64cd\u4f5c\u662f\u8fde\u7eed\u4ece\u7b2c\u4e8c\u548c\u7b2c\u4e09\u5806\u53d6 8 \u56de\u5408\uff0c\u76f4\u5230\u5c06\u5b83\u4eec\u53d6\u7a7a\u3002\n\u6ce8\u610f\uff0c\u7531\u4e8e\u7b2c\u4e8c\u548c\u7b2c\u4e09\u5806\u5df2\u7ecf\u7a7a\u4e86\uff0c\u6e38\u620f\u7ed3\u675f\uff0c\u4e0d\u80fd\u7ee7\u7eed\u4ece\u7b2c\u4e00\u5806\u4e2d\u53d6\u77f3\u5b50\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= a, b, c <= 105
    • \n
    \n", "tags_en": ["Heap", "Math"], "tags_cn": ["\u5806", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maximumScore(int a, int b, int c) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maximumScore(int a, int b, int c) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximumScore(self, a, b, c):\n \"\"\"\n :type a: int\n :type b: int\n :type c: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximumScore(self, a: int, b: int, c: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maximumScore(int a, int b, int c){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaximumScore(int a, int b, int c) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} a\n * @param {number} b\n * @param {number} c\n * @return {number}\n */\nvar maximumScore = function(a, b, c) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} a\n# @param {Integer} b\n# @param {Integer} c\n# @return {Integer}\ndef maximum_score(a, b, c)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximumScore(_ a: Int, _ b: Int, _ c: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximumScore(a int, b int, c int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximumScore(a: Int, b: Int, c: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximumScore(a: Int, b: Int, c: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximum_score(a: i32, b: i32, c: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $a\n * @param Integer $b\n * @param Integer $c\n * @return Integer\n */\n function maximumScore($a, $b, $c) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximumScore(a: number, b: number, c: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximum-score a b c)\n (-> exact-integer? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1753](https://leetcode-cn.com/problems/maximum-score-from-removing-stones)", "[\u79fb\u9664\u77f3\u5b50\u7684\u6700\u5927\u5f97\u5206](/solution/1700-1799/1753.Maximum%20Score%20From%20Removing%20Stones/README.md)", "`\u5806`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1753](https://leetcode.com/problems/maximum-score-from-removing-stones)", "[Maximum Score From Removing Stones](/solution/1700-1799/1753.Maximum%20Score%20From%20Removing%20Stones/README_EN.md)", "`Heap`,`Math`", "Medium", ""]}, {"question_id": "1878", "frontend_question_id": "1752", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/check-if-array-is-sorted-and-rotated", "url_en": "https://leetcode.com/problems/check-if-array-is-sorted-and-rotated", "relative_path_cn": "/solution/1700-1799/1752.Check%20if%20Array%20Is%20Sorted%20and%20Rotated/README.md", "relative_path_en": "/solution/1700-1799/1752.Check%20if%20Array%20Is%20Sorted%20and%20Rotated/README_EN.md", "title_cn": "\u68c0\u67e5\u6570\u7ec4\u662f\u5426\u7ecf\u6392\u5e8f\u548c\u8f6e\u8f6c\u5f97\u5230", "title_en": "Check if Array Is Sorted and Rotated", "question_title_slug": "check-if-array-is-sorted-and-rotated", "content_en": "

    Given an array nums, return true if the array was originally sorted in non-decreasing order, then rotated some number of positions (including zero). Otherwise, return false.

    \n\n

    There may be duplicates in the original array.

    \n\n

    Note: An array A rotated by x positions results in an array B of the same length such that A[i] == B[(i+x) % A.length], where % is the modulo operation.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [3,4,5,1,2]\nOutput: true\nExplanation: [1,2,3,4,5] is the original sorted array.\nYou can rotate the array by x = 3 positions to begin on the the element of value 3: [3,4,5,1,2].\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [2,1,3,4]\nOutput: false\nExplanation: There is no sorted array once rotated that can make nums.\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [1,2,3]\nOutput: true\nExplanation: [1,2,3] is the original sorted array.\nYou can rotate the array by x = 0 positions (i.e. no rotation) to make nums.\n
    \n\n

    Example 4:

    \n\n
    \nInput: nums = [1,1,1]\nOutput: true\nExplanation: [1,1,1] is the original sorted array.\nYou can rotate any number of positions to make nums.\n
    \n\n

    Example 5:

    \n\n
    \nInput: nums = [2,1]\nOutput: true\nExplanation: [1,2] is the original sorted array.\nYou can rotate the array by x = 5 positions to begin on the element of value 2: [2,1].\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 100
    • \n\t
    • 1 <= nums[i] <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 nums \u3002nums \u7684\u6e90\u6570\u7ec4\u4e2d\uff0c\u6240\u6709\u5143\u7d20\u4e0e nums \u76f8\u540c\uff0c\u4f46\u6309\u975e\u9012\u51cf\u987a\u5e8f\u6392\u5217\u3002

    \n\n

    \u5982\u679c\u00a0nums \u80fd\u591f\u7531\u6e90\u6570\u7ec4\u8f6e\u8f6c\u82e5\u5e72\u4f4d\u7f6e\uff08\u5305\u62ec 0 \u4e2a\u4f4d\u7f6e\uff09\u5f97\u5230\uff0c\u5219\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n

    \u6e90\u6570\u7ec4\u4e2d\u53ef\u80fd\u5b58\u5728 \u91cd\u590d\u9879 \u3002

    \n\n

    \u6ce8\u610f\uff1a\u6211\u4eec\u79f0\u6570\u7ec4 A \u5728\u8f6e\u8f6c x \u4e2a\u4f4d\u7f6e\u540e\u5f97\u5230\u957f\u5ea6\u76f8\u540c\u7684\u6570\u7ec4 B \uff0c\u5f53\u5b83\u4eec\u6ee1\u8db3 A[i] == B[(i+x) % A.length] \uff0c\u5176\u4e2d % \u4e3a\u53d6\u4f59\u8fd0\u7b97\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [3,4,5,1,2]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a[1,2,3,4,5] \u4e3a\u6709\u5e8f\u7684\u6e90\u6570\u7ec4\u3002\n\u53ef\u4ee5\u8f6e\u8f6c x = 3 \u4e2a\u4f4d\u7f6e\uff0c\u4f7f\u65b0\u6570\u7ec4\u4ece\u503c\u4e3a 3 \u7684\u5143\u7d20\u5f00\u59cb\uff1a[3,4,5,1,2] \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [2,1,3,4]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u6e90\u6570\u7ec4\u65e0\u6cd5\u7ecf\u8f6e\u8f6c\u5f97\u5230 nums \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,3]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a[1,2,3] \u4e3a\u6709\u5e8f\u7684\u6e90\u6570\u7ec4\u3002\n\u53ef\u4ee5\u8f6e\u8f6c x = 0 \u4e2a\u4f4d\u7f6e\uff08\u5373\u4e0d\u8f6e\u8f6c\uff09\u5f97\u5230 nums \u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,1,1]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a[1,1,1] \u4e3a\u6709\u5e8f\u7684\u6e90\u6570\u7ec4\u3002\n\u8f6e\u8f6c\u4efb\u610f\u4e2a\u4f4d\u7f6e\u90fd\u53ef\u4ee5\u5f97\u5230 nums \u3002\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [2,1]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a[1,2] \u4e3a\u6709\u5e8f\u7684\u6e90\u6570\u7ec4\u3002\n\u53ef\u4ee5\u8f6e\u8f6c x = 5 \u4e2a\u4f4d\u7f6e\uff0c\u4f7f\u65b0\u6570\u7ec4\u4ece\u503c\u4e3a 2 \u7684\u5143\u7d20\u5f00\u59cb\uff1a[2,1] \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 100
    • \n\t
    • 1 <= nums[i] <= 100
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool check(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean check(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def check(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def check(self, nums: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool check(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool Check(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {boolean}\n */\nvar check = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Boolean}\ndef check(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func check(_ nums: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func check(nums []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def check(nums: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun check(nums: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn check(nums: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Boolean\n */\n function check($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function check(nums: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (check nums)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1752](https://leetcode-cn.com/problems/check-if-array-is-sorted-and-rotated)", "[\u68c0\u67e5\u6570\u7ec4\u662f\u5426\u7ecf\u6392\u5e8f\u548c\u8f6e\u8f6c\u5f97\u5230](/solution/1700-1799/1752.Check%20if%20Array%20Is%20Sorted%20and%20Rotated/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1752](https://leetcode.com/problems/check-if-array-is-sorted-and-rotated)", "[Check if Array Is Sorted and Rotated](/solution/1700-1799/1752.Check%20if%20Array%20Is%20Sorted%20and%20Rotated/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1877", "frontend_question_id": "1729", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/find-followers-count", "url_en": "https://leetcode.com/problems/find-followers-count", "relative_path_cn": "/solution/1700-1799/1729.Find%20Followers%20Count/README.md", "relative_path_en": "/solution/1700-1799/1729.Find%20Followers%20Count/README_EN.md", "title_cn": "\u6c42\u5173\u6ce8\u8005\u7684\u6570\u91cf", "title_en": "Find Followers Count", "question_title_slug": "find-followers-count", "content_en": "

    Table: Followers

    \n\n
    \n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| user_id     | int  |\n| follower_id | int  |\n+-------------+------+\n(user_id, follower_id) is the primary key for this table.\nThis table contains the IDs of a user and a follower in a social media app where the follower follows the user.
    \n\n

    Write an SQL query that will, for each user, return the number of followers.

    \n\n

    Return the result table ordered by user_id.

    \n\n

    The query result format is in the following example:

    \n\n

     

    \n\n
    \nFollowers table:\n+---------+-------------+\n| user_id | follower_id |\n+---------+-------------+\n| 0       | 1           |\n| 1       | 0           |\n| 2       | 0           |\n| 2       | 1           |\n+---------+-------------+\nResult table:\n+---------+----------------+\n| user_id | followers_count|\n+---------+----------------+\n| 0       | 1              |\n| 1       | 1              |\n| 2       | 2              |\n+---------+----------------+\nThe followers of 0 are {1}\nThe followers of 1 are {0}\nThe followers of 2 are {0,1}\n
    \n\n

     

    \n", "content_cn": "

    \u8868\uff1a\u00a0Followers

    \n\n
    +-------------+------+\n| Column Name | Type |\n+-------------+------+\n| user_id     | int  |\n| follower_id | int  |\n+-------------+------+\n(user_id, follower_id) \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\u3002\n\u8be5\u8868\u5305\u542b\u4e00\u4e2a\u5173\u6ce8\u5173\u7cfb\u4e2d\u5173\u6ce8\u8005\u548c\u7528\u6237\u7684\u7f16\u53f7\uff0c\u5176\u4e2d\u5173\u6ce8\u8005\u5173\u6ce8\u7528\u6237\u3002
    \n\n

    \u5199\u51fa SQL \u8bed\u53e5\uff0c\u5bf9\u4e8e\u6bcf\u4e00\u4e2a\u7528\u6237\uff0c\u8fd4\u56de\u8be5\u7528\u6237\u7684\u5173\u6ce8\u8005\u6570\u91cf\u3002

    \n\n

    \u6309\u00a0user_id\u00a0\u7684\u987a\u5e8f\u8fd4\u56de\u7ed3\u679c\u8868\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u7684\u683c\u5f0f\u5982\u4e0b\u793a\u4f8b\u6240\u793a\uff1a

    \n\n

    \u00a0

    \n\n
    Followers \u8868\uff1a\n+---------+-------------+\n| user_id | follower_id |\n+---------+-------------+\n| 0       | 1           |\n| 1       | 0           |\n| 2       | 0           |\n| 2       | 1           |\n+---------+-------------+\n\u7ed3\u679c\u8868\uff1a\n+---------+----------------+\n| user_id | followers_count|\n+---------+----------------+\n| 0       | 1              |\n| 1       | 1              |\n| 2       | 2              |\n+---------+----------------+\n0 \u7684\u5173\u6ce8\u8005\u6709 {1}\n1 \u7684\u5173\u6ce8\u8005\u6709 {0}\n2 \u7684\u5173\u6ce8\u8005\u6709 {0,1}\n
    \n\n

    \u00a0

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1729](https://leetcode-cn.com/problems/find-followers-count)", "[\u6c42\u5173\u6ce8\u8005\u7684\u6570\u91cf](/solution/1700-1799/1729.Find%20Followers%20Count/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1729](https://leetcode.com/problems/find-followers-count)", "[Find Followers Count](/solution/1700-1799/1729.Find%20Followers%20Count/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1876", "frontend_question_id": "1765", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/map-of-highest-peak", "url_en": "https://leetcode.com/problems/map-of-highest-peak", "relative_path_cn": "/solution/1700-1799/1765.Map%20of%20Highest%20Peak/README.md", "relative_path_en": "/solution/1700-1799/1765.Map%20of%20Highest%20Peak/README_EN.md", "title_cn": "\u5730\u56fe\u4e2d\u7684\u6700\u9ad8\u70b9", "title_en": "Map of Highest Peak", "question_title_slug": "map-of-highest-peak", "content_en": "

    You are given an integer matrix isWater of size m x n that represents a map of land and water cells.

    \n\n
      \n\t
    • If isWater[i][j] == 0, cell (i, j) is a land cell.
    • \n\t
    • If isWater[i][j] == 1, cell (i, j) is a water cell.
    • \n
    \n\n

    You must assign each cell a height in a way that follows these rules:

    \n\n
      \n\t
    • The height of each cell must be non-negative.
    • \n\t
    • If the cell is a water cell, its height must be 0.
    • \n\t
    • Any two adjacent cells must have an absolute height difference of at most 1. A cell is adjacent to another cell if the former is directly north, east, south, or west of the latter (i.e., their sides are touching).
    • \n
    \n\n

    Find an assignment of heights such that the maximum height in the matrix is maximized.

    \n\n

    Return an integer matrix height of size m x n where height[i][j] is cell (i, j)'s height. If there are multiple solutions, return any of them.

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: isWater = [[0,1],[0,0]]\nOutput: [[1,0],[2,1]]\nExplanation: The image shows the assigned heights of each cell.\nThe blue cell is the water cell, and the green cells are the land cells.\n
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: isWater = [[0,0,1],[1,0,0],[0,0,0]]\nOutput: [[1,1,0],[0,1,1],[1,2,2]]\nExplanation: A height of 2 is the maximum possible height of any assignment.\nAny height assignment that has a maximum height of 2 while still meeting the rules will also be accepted.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == isWater.length
    • \n\t
    • n == isWater[i].length
    • \n\t
    • 1 <= m, n <= 1000
    • \n\t
    • isWater[i][j] is 0 or 1.
    • \n\t
    • There is at least one water cell.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5927\u5c0f\u4e3a\u00a0m x n\u00a0\u7684\u6574\u6570\u77e9\u9635\u00a0isWater\u00a0\uff0c\u5b83\u4ee3\u8868\u4e86\u4e00\u4e2a\u7531 \u9646\u5730\u00a0\u548c \u6c34\u57df\u00a0\u5355\u5143\u683c\u7ec4\u6210\u7684\u5730\u56fe\u3002

    \n\n
      \n\t
    • \u5982\u679c\u00a0isWater[i][j] == 0\u00a0\uff0c\u683c\u5b50\u00a0(i, j)\u00a0\u662f\u4e00\u4e2a \u9646\u5730\u00a0\u683c\u5b50\u3002
    • \n\t
    • \u5982\u679c\u00a0isWater[i][j] == 1\u00a0\uff0c\u683c\u5b50\u00a0(i, j)\u00a0\u662f\u4e00\u4e2a \u6c34\u57df\u00a0\u683c\u5b50\u3002
    • \n
    \n\n

    \u4f60\u9700\u8981\u6309\u7167\u5982\u4e0b\u89c4\u5219\u7ed9\u6bcf\u4e2a\u5355\u5143\u683c\u5b89\u6392\u9ad8\u5ea6\uff1a

    \n\n
      \n\t
    • \u6bcf\u4e2a\u683c\u5b50\u7684\u9ad8\u5ea6\u90fd\u5fc5\u987b\u662f\u975e\u8d1f\u7684\u3002
    • \n\t
    • \u5982\u679c\u4e00\u4e2a\u683c\u5b50\u662f\u662f \u6c34\u57df\u00a0\uff0c\u90a3\u4e48\u5b83\u7684\u9ad8\u5ea6\u5fc5\u987b\u4e3a 0\u00a0\u3002
    • \n\t
    • \u4efb\u610f\u76f8\u90bb\u7684\u683c\u5b50\u9ad8\u5ea6\u5dee \u81f3\u591a\u00a0\u4e3a 1\u00a0\u3002\u5f53\u4e24\u4e2a\u683c\u5b50\u5728\u6b63\u4e1c\u3001\u5357\u3001\u897f\u3001\u5317\u65b9\u5411\u4e0a\u76f8\u4e92\u7d27\u6328\u7740\uff0c\u5c31\u79f0\u5b83\u4eec\u4e3a\u76f8\u90bb\u7684\u683c\u5b50\u3002\uff08\u4e5f\u5c31\u662f\u8bf4\u5b83\u4eec\u6709\u4e00\u6761\u516c\u5171\u8fb9\uff09
    • \n
    \n\n

    \u627e\u5230\u4e00\u79cd\u5b89\u6392\u9ad8\u5ea6\u7684\u65b9\u6848\uff0c\u4f7f\u5f97\u77e9\u9635\u4e2d\u7684\u6700\u9ad8\u9ad8\u5ea6\u503c\u00a0\u6700\u5927\u00a0\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u4e00\u4e2a\u5927\u5c0f\u4e3a\u00a0m x n\u00a0\u7684\u6574\u6570\u77e9\u9635 height\u00a0\uff0c\u5176\u4e2d height[i][j]\u00a0\u662f\u683c\u5b50 (i, j)\u00a0\u7684\u9ad8\u5ea6\u3002\u5982\u679c\u6709\u591a\u79cd\u89e3\u6cd5\uff0c\u8bf7\u8fd4\u56de\u00a0\u4efb\u610f\u4e00\u4e2a\u00a0\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aisWater = [[0,1],[0,0]]\n\u8f93\u51fa\uff1a[[1,0],[2,1]]\n\u89e3\u91ca\uff1a\u4e0a\u56fe\u5c55\u793a\u4e86\u7ed9\u5404\u4e2a\u683c\u5b50\u5b89\u6392\u7684\u9ad8\u5ea6\u3002\n\u84dd\u8272\u683c\u5b50\u662f\u6c34\u57df\u683c\uff0c\u7eff\u8272\u683c\u5b50\u662f\u9646\u5730\u683c\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aisWater = [[0,0,1],[1,0,0],[0,0,0]]\n\u8f93\u51fa\uff1a[[1,1,0],[0,1,1],[1,2,2]]\n\u89e3\u91ca\uff1a\u6240\u6709\u5b89\u6392\u65b9\u6848\u4e2d\uff0c\u6700\u9ad8\u53ef\u884c\u9ad8\u5ea6\u4e3a 2 \u3002\n\u4efb\u610f\u5b89\u6392\u65b9\u6848\u4e2d\uff0c\u53ea\u8981\u6700\u9ad8\u9ad8\u5ea6\u4e3a 2 \u4e14\u7b26\u5408\u4e0a\u8ff0\u89c4\u5219\u7684\uff0c\u90fd\u4e3a\u53ef\u884c\u65b9\u6848\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == isWater.length
    • \n\t
    • n == isWater[i].length
    • \n\t
    • 1 <= m, n <= 1000
    • \n\t
    • isWater[i][j]\u00a0\u8981\u4e48\u662f\u00a00\u00a0\uff0c\u8981\u4e48\u662f\u00a01\u00a0\u3002
    • \n\t
    • \u81f3\u5c11\u6709 1\u00a0\u4e2a\u6c34\u57df\u683c\u5b50\u3002
    • \n
    \n", "tags_en": ["Breadth-first Search", "Graph"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> highestPeak(vector>& isWater) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[][] highestPeak(int[][] isWater) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def highestPeak(self, isWater):\n \"\"\"\n :type isWater: List[List[int]]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def highestPeak(self, isWater: List[List[int]]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** highestPeak(int** isWater, int isWaterSize, int* isWaterColSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[][] HighestPeak(int[][] isWater) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} isWater\n * @return {number[][]}\n */\nvar highestPeak = function(isWater) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} is_water\n# @return {Integer[][]}\ndef highest_peak(is_water)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func highestPeak(_ isWater: [[Int]]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func highestPeak(isWater [][]int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def highestPeak(isWater: Array[Array[Int]]): Array[Array[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun highestPeak(isWater: Array): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn highest_peak(is_water: Vec>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $isWater\n * @return Integer[][]\n */\n function highestPeak($isWater) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function highestPeak(isWater: number[][]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (highest-peak isWater)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1765](https://leetcode-cn.com/problems/map-of-highest-peak)", "[\u5730\u56fe\u4e2d\u7684\u6700\u9ad8\u70b9](/solution/1700-1799/1765.Map%20of%20Highest%20Peak/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u56fe`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1765](https://leetcode.com/problems/map-of-highest-peak)", "[Map of Highest Peak](/solution/1700-1799/1765.Map%20of%20Highest%20Peak/README_EN.md)", "`Breadth-first Search`,`Graph`", "Medium", ""]}, {"question_id": "1875", "frontend_question_id": "1766", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/tree-of-coprimes", "url_en": "https://leetcode.com/problems/tree-of-coprimes", "relative_path_cn": "/solution/1700-1799/1766.Tree%20of%20Coprimes/README.md", "relative_path_en": "/solution/1700-1799/1766.Tree%20of%20Coprimes/README_EN.md", "title_cn": "\u4e92\u8d28\u6811", "title_en": "Tree of Coprimes", "question_title_slug": "tree-of-coprimes", "content_en": "

    There is a tree (i.e., a connected, undirected graph that has no cycles) consisting of n nodes numbered from 0 to n - 1 and exactly n - 1 edges. Each node has a value associated with it, and the root of the tree is node 0.

    \n\n

    To represent this tree, you are given an integer array nums and a 2D array edges. Each nums[i] represents the ith node's value, and each edges[j] = [uj, vj] represents an edge between nodes uj and vj in the tree.

    \n\n

    Two values x and y are coprime if gcd(x, y) == 1 where gcd(x, y) is the greatest common divisor of x and y.

    \n\n

    An ancestor of a node i is any other node on the shortest path from node i to the root. A node is not considered an ancestor of itself.

    \n\n

    Return an array ans of size n, where ans[i] is the closest ancestor to node i such that nums[i] and nums[ans[i]] are coprime, or -1 if there is no such ancestor.

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: nums = [2,3,3,2], edges = [[0,1],[1,2],[1,3]]\nOutput: [-1,0,0,1]\nExplanation: In the above figure, each node's value is in parentheses.\n- Node 0 has no coprime ancestors.\n- Node 1 has only one ancestor, node 0. Their values are coprime (gcd(2,3) == 1).\n- Node 2 has two ancestors, nodes 1 and 0. Node 1's value is not coprime (gcd(3,3) == 3), but node 0's\n  value is (gcd(2,3) == 1), so node 0 is the closest valid ancestor.\n- Node 3 has two ancestors, nodes 1 and 0. It is coprime with node 1 (gcd(3,2) == 1), so node 1 is its\n  closest valid ancestor.\n
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: nums = [5,6,10,2,3,6,15], edges = [[0,1],[0,2],[1,3],[1,4],[2,5],[2,6]]\nOutput: [-1,0,-1,0,0,0,-1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • nums.length == n
    • \n\t
    • 1 <= nums[i] <= 50
    • \n\t
    • 1 <= n <= 105
    • \n\t
    • edges.length == n - 1
    • \n\t
    • edges[j].length == 2
    • \n\t
    • 0 <= uj, vj < n
    • \n\t
    • uj != vj
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a n\u00a0\u4e2a\u8282\u70b9\u7684\u6811\uff08\u4e5f\u5c31\u662f\u4e00\u4e2a\u65e0\u73af\u8fde\u901a\u65e0\u5411\u56fe\uff09\uff0c\u8282\u70b9\u7f16\u53f7\u4ece 0\u00a0\u5230 n - 1\u00a0\uff0c\u4e14\u6070\u597d\u6709 n - 1\u00a0\u6761\u8fb9\uff0c\u6bcf\u4e2a\u8282\u70b9\u6709\u4e00\u4e2a\u503c\u3002\u6811\u7684 \u6839\u8282\u70b9\u00a0\u4e3a 0 \u53f7\u70b9\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0nums\u00a0\u548c\u4e00\u4e2a\u4e8c\u7ef4\u6570\u7ec4\u00a0edges\u00a0\u6765\u8868\u793a\u8fd9\u68f5\u6811\u3002nums[i]\u00a0\u8868\u793a\u7b2c\u00a0i\u00a0\u4e2a\u70b9\u7684\u503c\uff0cedges[j] = [uj, vj]\u00a0\u8868\u793a\u8282\u70b9\u00a0uj\u00a0\u548c\u8282\u70b9\u00a0vj\u00a0\u5728\u6811\u4e2d\u6709\u4e00\u6761\u8fb9\u3002

    \n\n

    \u5f53\u00a0gcd(x, y) == 1\u00a0\uff0c\u6211\u4eec\u79f0\u4e24\u4e2a\u6570\u00a0x \u548c\u00a0y\u00a0\u662f \u4e92\u8d28\u7684\u00a0\uff0c\u5176\u4e2d\u00a0gcd(x, y)\u00a0\u662f x\u00a0\u548c y\u00a0\u7684 \u6700\u5927\u516c\u7ea6\u6570\u00a0\u3002

    \n\n

    \u4ece\u8282\u70b9\u00a0i\u00a0\u5230 \u6839\u00a0\u6700\u77ed\u8def\u5f84\u4e0a\u7684\u70b9\u90fd\u662f\u8282\u70b9 i\u00a0\u7684\u7956\u5148\u8282\u70b9\u3002\u4e00\u4e2a\u8282\u70b9 \u4e0d\u662f \u5b83\u81ea\u5df1\u7684\u7956\u5148\u8282\u70b9\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u4e00\u4e2a\u5927\u5c0f\u4e3a n\u00a0\u7684\u6570\u7ec4 ans\u00a0\uff0c\u5176\u4e2d\u00a0ans[i]\u662f\u79bb\u8282\u70b9\u00a0i\u00a0\u6700\u8fd1\u7684\u7956\u5148\u8282\u70b9\u4e14\u6ee1\u8db3\u00a0nums[i] \u548c\u00a0nums[ans[i]]\u00a0\u662f \u4e92\u8d28\u7684\u00a0\uff0c\u5982\u679c\u4e0d\u5b58\u5728\u8fd9\u6837\u7684\u7956\u5148\u8282\u70b9\uff0cans[i]\u00a0\u4e3a -1\u00a0\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1anums = [2,3,3,2], edges = [[0,1],[1,2],[1,3]]\n\u8f93\u51fa\uff1a[-1,0,0,1]\n\u89e3\u91ca\uff1a\u4e0a\u56fe\u4e2d\uff0c\u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u5728\u62ec\u53f7\u4e2d\u8868\u793a\u3002\n- \u8282\u70b9 0 \u6ca1\u6709\u4e92\u8d28\u7956\u5148\u3002\n- \u8282\u70b9 1 \u53ea\u6709\u4e00\u4e2a\u7956\u5148\u8282\u70b9 0 \u3002\u5b83\u4eec\u7684\u503c\u662f\u4e92\u8d28\u7684\uff08gcd(2,3) == 1\uff09\u3002\n- \u8282\u70b9 2 \u6709\u4e24\u4e2a\u7956\u5148\u8282\u70b9\uff0c\u5206\u522b\u662f\u8282\u70b9 1 \u548c\u8282\u70b9 0 \u3002\u8282\u70b9 1 \u7684\u503c\u4e0e\u5b83\u7684\u503c\u4e0d\u662f\u4e92\u8d28\u7684\uff08gcd(3,3) == 3\uff09\u4f46\u8282\u70b9 0 \u7684\u503c\u662f\u4e92\u8d28\u7684(gcd(2,3) == 1)\uff0c\u6240\u4ee5\u8282\u70b9 0 \u662f\u6700\u8fd1\u7684\u7b26\u5408\u8981\u6c42\u7684\u7956\u5148\u8282\u70b9\u3002\n- \u8282\u70b9 3 \u6709\u4e24\u4e2a\u7956\u5148\u8282\u70b9\uff0c\u5206\u522b\u662f\u8282\u70b9 1 \u548c\u8282\u70b9 0 \u3002\u5b83\u4e0e\u8282\u70b9 1 \u4e92\u8d28\uff08gcd(3,2) == 1\uff09\uff0c\u6240\u4ee5\u8282\u70b9 1 \u662f\u79bb\u5b83\u6700\u8fd1\u7684\u7b26\u5408\u8981\u6c42\u7684\u7956\u5148\u8282\u70b9\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1anums = [5,6,10,2,3,6,15], edges = [[0,1],[0,2],[1,3],[1,4],[2,5],[2,6]]\n\u8f93\u51fa\uff1a[-1,0,-1,0,0,0,-1]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • nums.length == n
    • \n\t
    • 1 <= nums[i] <= 50
    • \n\t
    • 1 <= n <= 105
    • \n\t
    • edges.length == n - 1
    • \n\t
    • edges[j].length == 2
    • \n\t
    • 0 <= uj, vj < n
    • \n\t
    • uj != vj
    • \n
    \n", "tags_en": ["Tree", "Depth-first Search", "Breadth-first Search", "Math"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector getCoprimes(vector& nums, vector>& edges) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] getCoprimes(int[] nums, int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getCoprimes(self, nums, edges):\n \"\"\"\n :type nums: List[int]\n :type edges: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getCoprimes(self, nums: List[int], edges: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* getCoprimes(int* nums, int numsSize, int** edges, int edgesSize, int* edgesColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] GetCoprimes(int[] nums, int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number[][]} edges\n * @return {number[]}\n */\nvar getCoprimes = function(nums, edges) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer[][]} edges\n# @return {Integer[]}\ndef get_coprimes(nums, edges)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getCoprimes(_ nums: [Int], _ edges: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getCoprimes(nums []int, edges [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getCoprimes(nums: Array[Int], edges: Array[Array[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getCoprimes(nums: IntArray, edges: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_coprimes(nums: Vec, edges: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer[][] $edges\n * @return Integer[]\n */\n function getCoprimes($nums, $edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getCoprimes(nums: number[], edges: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-coprimes nums edges)\n (-> (listof exact-integer?) (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1766](https://leetcode-cn.com/problems/tree-of-coprimes)", "[\u4e92\u8d28\u6811](/solution/1700-1799/1766.Tree%20of%20Coprimes/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[1766](https://leetcode.com/problems/tree-of-coprimes)", "[Tree of Coprimes](/solution/1700-1799/1766.Tree%20of%20Coprimes/README_EN.md)", "`Tree`,`Depth-first Search`,`Breadth-first Search`,`Math`", "Hard", ""]}, {"question_id": "1874", "frontend_question_id": "1764", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/form-array-by-concatenating-subarrays-of-another-array", "url_en": "https://leetcode.com/problems/form-array-by-concatenating-subarrays-of-another-array", "relative_path_cn": "/solution/1700-1799/1764.Form%20Array%20by%20Concatenating%20Subarrays%20of%20Another%20Array/README.md", "relative_path_en": "/solution/1700-1799/1764.Form%20Array%20by%20Concatenating%20Subarrays%20of%20Another%20Array/README_EN.md", "title_cn": "\u901a\u8fc7\u8fde\u63a5\u53e6\u4e00\u4e2a\u6570\u7ec4\u7684\u5b50\u6570\u7ec4\u5f97\u5230\u4e00\u4e2a\u6570\u7ec4", "title_en": "Form Array by Concatenating Subarrays of Another Array", "question_title_slug": "form-array-by-concatenating-subarrays-of-another-array", "content_en": "

    You are given a 2D integer array groups of length n. You are also given an integer array nums.

    \n\n

    You are asked if you can choose n disjoint subarrays from the array nums such that the ith subarray is equal to groups[i] (0-indexed), and if i > 0, the (i-1)th subarray appears before the ith subarray in nums (i.e. the subarrays must be in the same order as groups).

    \n\n

    Return true if you can do this task, and false otherwise.

    \n\n

    Note that the subarrays are disjoint if and only if there is no index k such that nums[k] belongs to more than one subarray. A subarray is a contiguous sequence of elements within an array.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: groups = [[1,-1,-1],[3,-2,0]], nums = [1,-1,0,1,-1,-1,3,-2,0]\nOutput: true\nExplanation: You can choose the 0th subarray as [1,-1,0,1,-1,-1,3,-2,0] and the 1st one as [1,-1,0,1,-1,-1,3,-2,0].\nThese subarrays are disjoint as they share no common nums[k] element.\n
    \n\n

    Example 2:

    \n\n
    \nInput: groups = [[10,-2],[1,2,3,4]], nums = [1,2,3,4,10,-2]\nOutput: false\nExplanation: Note that choosing the subarrays [1,2,3,4,10,-2] and [1,2,3,4,10,-2] is incorrect because they are not in the same order as in groups.\n[10,-2] must come before [1,2,3,4].\n
    \n\n

    Example 3:

    \n\n
    \nInput: groups = [[1,2,3],[3,4]], nums = [7,7,1,2,3,4,7,7]\nOutput: false\nExplanation: Note that choosing the subarrays [7,7,1,2,3,4,7,7] and [7,7,1,2,3,4,7,7] is invalid because they are not disjoint.\nThey share a common elements nums[4] (0-indexed).\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • groups.length == n
    • \n\t
    • 1 <= n <= 103
    • \n\t
    • 1 <= groups[i].length, sum(groups[i].length) <= 103
    • \n\t
    • 1 <= nums.length <= 103
    • \n\t
    • -107 <= groups[i][j], nums[k] <= 107
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u4e3a n\u00a0\u7684\u4e8c\u7ef4\u6574\u6570\u6570\u7ec4\u00a0groups\u00a0\uff0c\u540c\u65f6\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0nums\u00a0\u3002

    \n\n

    \u4f60\u662f\u5426\u53ef\u4ee5\u4ece nums\u00a0\u4e2d\u9009\u51fa n\u00a0\u4e2a \u4e0d\u76f8\u4ea4 \u7684\u5b50\u6570\u7ec4\uff0c\u4f7f\u5f97\u7b2c i\u00a0\u4e2a\u5b50\u6570\u7ec4\u4e0e groups[i]\u00a0\uff08\u4e0b\u6807\u4ece 0\u00a0\u5f00\u59cb\uff09\u5b8c\u5168\u76f8\u540c\uff0c\u4e14\u5982\u679c\u00a0i > 0\u00a0\uff0c\u90a3\u4e48\u7b2c\u00a0(i-1)\u00a0\u4e2a\u5b50\u6570\u7ec4\u5728 nums\u00a0\u4e2d\u51fa\u73b0\u7684\u4f4d\u7f6e\u5728\u7b2c i\u00a0\u4e2a\u5b50\u6570\u7ec4\u524d\u9762\u3002\uff08\u4e5f\u5c31\u662f\u8bf4\uff0c\u8fd9\u4e9b\u5b50\u6570\u7ec4\u5728 nums\u00a0\u4e2d\u51fa\u73b0\u7684\u987a\u5e8f\u9700\u8981\u4e0e groups \u987a\u5e8f\u76f8\u540c\uff09

    \n\n

    \u5982\u679c\u4f60\u53ef\u4ee5\u627e\u51fa\u8fd9\u6837\u7684 n \u4e2a\u5b50\u6570\u7ec4\uff0c\u8bf7\u4f60\u8fd4\u56de\u00a0true \uff0c\u5426\u5219\u8fd4\u56de\u00a0false\u00a0\u3002

    \n\n

    \u5982\u679c\u4e0d\u5b58\u5728\u4e0b\u6807\u4e3a k\u00a0\u7684\u5143\u7d20 nums[k]\u00a0\u5c5e\u4e8e\u4e0d\u6b62\u4e00\u4e2a\u5b50\u6570\u7ec4\uff0c\u5c31\u79f0\u8fd9\u4e9b\u5b50\u6570\u7ec4\u662f \u4e0d\u76f8\u4ea4 \u7684\u3002\u5b50\u6570\u7ec4\u6307\u7684\u662f\u539f\u6570\u7ec4\u4e2d\u8fde\u7eed\u5143\u7d20\u7ec4\u6210\u7684\u4e00\u4e2a\u5e8f\u5217\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1agroups = [[1,-1,-1],[3,-2,0]], nums = [1,-1,0,1,-1,-1,3,-2,0]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u5206\u522b\u5728 nums \u4e2d\u9009\u51fa\u7b2c 0 \u4e2a\u5b50\u6570\u7ec4 [1,-1,0,1,-1,-1,3,-2,0] \u548c\u7b2c 1 \u4e2a\u5b50\u6570\u7ec4 [1,-1,0,1,-1,-1,3,-2,0] \u3002\n\u8fd9\u4e24\u4e2a\u5b50\u6570\u7ec4\u662f\u4e0d\u76f8\u4ea4\u7684\uff0c\u56e0\u4e3a\u5b83\u4eec\u6ca1\u6709\u4efb\u4f55\u5171\u540c\u7684\u5143\u7d20\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1agroups = [[10,-2],[1,2,3,4]], nums = [1,2,3,4,10,-2]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u9009\u62e9\u5b50\u6570\u7ec4 [1,2,3,4,10,-2] \u548c [1,2,3,4,10,-2] \u662f\u4e0d\u6b63\u786e\u7684\uff0c\u56e0\u4e3a\u5b83\u4eec\u51fa\u73b0\u7684\u987a\u5e8f\u4e0e groups \u4e2d\u987a\u5e8f\u4e0d\u540c\u3002\n[10,-2] \u5fc5\u987b\u51fa\u73b0\u5728 [1,2,3,4] \u4e4b\u524d\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1agroups = [[1,2,3],[3,4]], nums = [7,7,1,2,3,4,7,7]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u9009\u62e9\u5b50\u6570\u7ec4 [7,7,1,2,3,4,7,7] \u548c [7,7,1,2,3,4,7,7] \u662f\u4e0d\u6b63\u786e\u7684\uff0c\u56e0\u4e3a\u5b83\u4eec\u4e0d\u662f\u4e0d\u76f8\u4ea4\u5b50\u6570\u7ec4\u3002\n\u5b83\u4eec\u6709\u4e00\u4e2a\u5171\u540c\u7684\u5143\u7d20 nums[4] \uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • groups.length == n
    • \n\t
    • 1 <= n <= 103
    • \n\t
    • 1 <= groups[i].length, sum(groups[i].length) <= 103
    • \n\t
    • 1 <= nums.length <= 103
    • \n\t
    • -107 <= groups[i][j], nums[k] <= 107
    • \n
    \n", "tags_en": ["Greedy", "Array"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canChoose(vector>& groups, vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canChoose(int[][] groups, int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canChoose(self, groups, nums):\n \"\"\"\n :type groups: List[List[int]]\n :type nums: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canChoose(self, groups: List[List[int]], nums: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canChoose(int** groups, int groupsSize, int* groupsColSize, int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanChoose(int[][] groups, int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} groups\n * @param {number[]} nums\n * @return {boolean}\n */\nvar canChoose = function(groups, nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} groups\n# @param {Integer[]} nums\n# @return {Boolean}\ndef can_choose(groups, nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canChoose(_ groups: [[Int]], _ nums: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canChoose(groups [][]int, nums []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canChoose(groups: Array[Array[Int]], nums: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canChoose(groups: Array, nums: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_choose(groups: Vec>, nums: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $groups\n * @param Integer[] $nums\n * @return Boolean\n */\n function canChoose($groups, $nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canChoose(groups: number[][], nums: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-choose groups nums)\n (-> (listof (listof exact-integer?)) (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1764](https://leetcode-cn.com/problems/form-array-by-concatenating-subarrays-of-another-array)", "[\u901a\u8fc7\u8fde\u63a5\u53e6\u4e00\u4e2a\u6570\u7ec4\u7684\u5b50\u6570\u7ec4\u5f97\u5230\u4e00\u4e2a\u6570\u7ec4](/solution/1700-1799/1764.Form%20Array%20by%20Concatenating%20Subarrays%20of%20Another%20Array/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1764](https://leetcode.com/problems/form-array-by-concatenating-subarrays-of-another-array)", "[Form Array by Concatenating Subarrays of Another Array](/solution/1700-1799/1764.Form%20Array%20by%20Concatenating%20Subarrays%20of%20Another%20Array/README_EN.md)", "`Greedy`,`Array`", "Medium", ""]}, {"question_id": "1873", "frontend_question_id": "1763", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-nice-substring", "url_en": "https://leetcode.com/problems/longest-nice-substring", "relative_path_cn": "/solution/1700-1799/1763.Longest%20Nice%20Substring/README.md", "relative_path_en": "/solution/1700-1799/1763.Longest%20Nice%20Substring/README_EN.md", "title_cn": "\u6700\u957f\u7684\u7f8e\u597d\u5b50\u5b57\u7b26\u4e32", "title_en": "Longest Nice Substring", "question_title_slug": "longest-nice-substring", "content_en": "

    A string s is nice if, for every letter of the alphabet that s contains, it appears both in uppercase and lowercase. For example, "abABB" is nice because 'A' and 'a' appear, and 'B' and 'b' appear. However, "abA" is not because 'b' appears, but 'B' does not.

    \n\n

    Given a string s, return the longest substring of s that is nice. If there are multiple, return the substring of the earliest occurrence. If there are none, return an empty string.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "YazaAay"\nOutput: "aAa"\nExplanation: "aAa" is a nice string because 'A/a' is the only letter of the alphabet in s, and both 'A' and 'a' appear.\n"aAa" is the longest nice substring.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "Bb"\nOutput: "Bb"\nExplanation: "Bb" is a nice string because both 'B' and 'b' appear. The whole string is a substring.
    \n\n

    Example 3:

    \n\n
    \nInput: s = "c"\nOutput: ""\nExplanation: There are no nice substrings.
    \n\n

    Example 4:

    \n\n
    \nInput: s = "dDzeE"\nOutput: "dD"\nExplanation: Both "dD" and "eE" are the longest nice substrings.\nAs there are multiple longest nice substrings, return "dD" since it occurs earlier.
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 100
    • \n\t
    • s consists of uppercase and lowercase English letters.
    • \n
    \n", "content_cn": "

    \u5f53\u4e00\u4e2a\u5b57\u7b26\u4e32 s\u00a0\u5305\u542b\u7684\u6bcf\u4e00\u79cd\u5b57\u6bcd\u7684\u5927\u5199\u548c\u5c0f\u5199\u5f62\u5f0f \u540c\u65f6\u00a0\u51fa\u73b0\u5728 s\u00a0\u4e2d\uff0c\u5c31\u79f0\u8fd9\u4e2a\u5b57\u7b26\u4e32\u00a0s\u00a0\u662f \u7f8e\u597d \u5b57\u7b26\u4e32\u3002\u6bd4\u65b9\u8bf4\uff0c\"abABB\"\u00a0\u662f\u7f8e\u597d\u5b57\u7b26\u4e32\uff0c\u56e0\u4e3a\u00a0'A' \u548c\u00a0'a'\u00a0\u540c\u65f6\u51fa\u73b0\u4e86\uff0c\u4e14\u00a0'B' \u548c\u00a0'b'\u00a0\u4e5f\u540c\u65f6\u51fa\u73b0\u4e86\u3002\u7136\u800c\uff0c\"abA\"\u00a0\u4e0d\u662f\u7f8e\u597d\u5b57\u7b26\u4e32\u56e0\u4e3a\u00a0'b'\u00a0\u51fa\u73b0\u4e86\uff0c\u800c\u00a0'B'\u00a0\u6ca1\u6709\u51fa\u73b0\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32\u00a0s\u00a0\uff0c\u8bf7\u4f60\u8fd4\u56de\u00a0s\u00a0\u6700\u957f\u7684\u00a0\u7f8e\u597d\u5b50\u5b57\u7b26\u4e32\u00a0\u3002\u5982\u679c\u6709\u591a\u4e2a\u7b54\u6848\uff0c\u8bf7\u4f60\u8fd4\u56de\u00a0\u6700\u65e9\u00a0\u51fa\u73b0\u7684\u4e00\u4e2a\u3002\u5982\u679c\u4e0d\u5b58\u5728\u7f8e\u597d\u5b50\u5b57\u7b26\u4e32\uff0c\u8bf7\u4f60\u8fd4\u56de\u4e00\u4e2a\u7a7a\u5b57\u7b26\u4e32\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"YazaAay\"\n\u8f93\u51fa\uff1a\"aAa\"\n\u89e3\u91ca\uff1a\"aAa\" \u662f\u4e00\u4e2a\u7f8e\u597d\u5b57\u7b26\u4e32\uff0c\u56e0\u4e3a\u8fd9\u4e2a\u5b50\u4e32\u4e2d\u4ec5\u542b\u4e00\u79cd\u5b57\u6bcd\uff0c\u5176\u5c0f\u5199\u5f62\u5f0f 'a' \u548c\u5927\u5199\u5f62\u5f0f 'A' \u4e5f\u540c\u65f6\u51fa\u73b0\u4e86\u3002\n\"aAa\" \u662f\u6700\u957f\u7684\u7f8e\u597d\u5b50\u5b57\u7b26\u4e32\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"Bb\"\n\u8f93\u51fa\uff1a\"Bb\"\n\u89e3\u91ca\uff1a\"Bb\" \u662f\u7f8e\u597d\u5b57\u7b26\u4e32\uff0c\u56e0\u4e3a 'B' \u548c 'b' \u90fd\u51fa\u73b0\u4e86\u3002\u6574\u4e2a\u5b57\u7b26\u4e32\u4e5f\u662f\u539f\u5b57\u7b26\u4e32\u7684\u5b50\u5b57\u7b26\u4e32\u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"c\"\n\u8f93\u51fa\uff1a\"\"\n\u89e3\u91ca\uff1a\u6ca1\u6709\u7f8e\u597d\u5b50\u5b57\u7b26\u4e32\u3002
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"dDzeE\"\n\u8f93\u51fa\uff1a\"dD\"\n\u89e3\u91ca\uff1a\"dD\" \u548c \"eE\" \u90fd\u662f\u6700\u957f\u7f8e\u597d\u5b50\u5b57\u7b26\u4e32\u3002\n\u7531\u4e8e\u6709\u591a\u4e2a\u7f8e\u597d\u5b50\u5b57\u7b26\u4e32\uff0c\u8fd4\u56de \"dD\" \uff0c\u56e0\u4e3a\u5b83\u51fa\u73b0\u5f97\u6700\u65e9\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 100
    • \n\t
    • s\u00a0\u53ea\u5305\u542b\u5927\u5199\u548c\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string longestNiceSubstring(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String longestNiceSubstring(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestNiceSubstring(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestNiceSubstring(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * longestNiceSubstring(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string LongestNiceSubstring(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar longestNiceSubstring = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef longest_nice_substring(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestNiceSubstring(_ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestNiceSubstring(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestNiceSubstring(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestNiceSubstring(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_nice_substring(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function longestNiceSubstring($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestNiceSubstring(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-nice-substring s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1763](https://leetcode-cn.com/problems/longest-nice-substring)", "[\u6700\u957f\u7684\u7f8e\u597d\u5b50\u5b57\u7b26\u4e32](/solution/1700-1799/1763.Longest%20Nice%20Substring/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1763](https://leetcode.com/problems/longest-nice-substring)", "[Longest Nice Substring](/solution/1700-1799/1763.Longest%20Nice%20Substring/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1872", "frontend_question_id": "1744", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/can-you-eat-your-favorite-candy-on-your-favorite-day", "url_en": "https://leetcode.com/problems/can-you-eat-your-favorite-candy-on-your-favorite-day", "relative_path_cn": "/solution/1700-1799/1744.Can%20You%20Eat%20Your%20Favorite%20Candy%20on%20Your%20Favorite%20Day/README.md", "relative_path_en": "/solution/1700-1799/1744.Can%20You%20Eat%20Your%20Favorite%20Candy%20on%20Your%20Favorite%20Day/README_EN.md", "title_cn": "\u4f60\u80fd\u5728\u4f60\u6700\u559c\u6b22\u7684\u90a3\u5929\u5403\u5230\u4f60\u6700\u559c\u6b22\u7684\u7cd6\u679c\u5417\uff1f", "title_en": "Can You Eat Your Favorite Candy on Your Favorite Day", "question_title_slug": "can-you-eat-your-favorite-candy-on-your-favorite-day", "content_en": "

    You are given a (0-indexed) array of positive integers candiesCount where candiesCount[i] represents the number of candies of the ith type you have. You are also given a 2D array queries where queries[i] = [favoriteTypei, favoriteDayi, dailyCapi].

    \n\n

    You play a game with the following rules:

    \n\n
      \n\t
    • You start eating candies on day 0.
    • \n\t
    • You cannot eat any candy of type i unless you have eaten all candies of type i - 1.
    • \n\t
    • You must eat at least one candy per day until you have eaten all the candies.
    • \n
    \n\n

    Construct a boolean array answer such that answer.length == queries.length and answer[i] is true if you can eat a candy of type favoriteTypei on day favoriteDayi without eating more than dailyCapi candies on any day, and false otherwise. Note that you can eat different types of candy on the same day, provided that you follow rule 2.

    \n\n

    Return the constructed array answer.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: candiesCount = [7,4,5,3,8], queries = [[0,2,2],[4,2,4],[2,13,1000000000]]\nOutput: [true,false,true]\nExplanation:\n1- If you eat 2 candies (type 0) on day 0 and 2 candies (type 0) on day 1, you will eat a candy of type 0 on day 2.\n2- You can eat at most 4 candies each day.\n   If you eat 4 candies every day, you will eat 4 candies (type 0) on day 0 and 4 candies (type 0 and type 1) on day 1.\n   On day 2, you can only eat 4 candies (type 1 and type 2), so you cannot eat a candy of type 4 on day 2.\n3- If you eat 1 candy each day, you will eat a candy of type 2 on day 13.\n
    \n\n

    Example 2:

    \n\n
    \nInput: candiesCount = [5,2,6,4,1], queries = [[3,1,2],[4,10,3],[3,10,100],[4,100,30],[1,3,1]]\nOutput: [false,true,true,false,false]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= candiesCount.length <= 105
    • \n\t
    • 1 <= candiesCount[i] <= 105
    • \n\t
    • 1 <= queries.length <= 105
    • \n\t
    • queries[i].length == 3
    • \n\t
    • 0 <= favoriteTypei < candiesCount.length
    • \n\t
    • 0 <= favoriteDayi <= 109
    • \n\t
    • 1 <= dailyCapi <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u4e0b\u6807\u4ece 0 \u5f00\u59cb\u7684\u6b63\u6574\u6570\u6570\u7ec4\u00a0candiesCount\u00a0\uff0c\u5176\u4e2d\u00a0candiesCount[i]\u00a0\u8868\u793a\u4f60\u62e5\u6709\u7684\u7b2c\u00a0i\u00a0\u7c7b\u7cd6\u679c\u7684\u6570\u76ee\u3002\u540c\u65f6\u7ed9\u4f60\u4e00\u4e2a\u4e8c\u7ef4\u6570\u7ec4\u00a0queries\u00a0\uff0c\u5176\u4e2d\u00a0queries[i] = [favoriteTypei, favoriteDayi, dailyCapi]\u00a0\u3002

    \n\n

    \u4f60\u6309\u7167\u5982\u4e0b\u89c4\u5219\u8fdb\u884c\u4e00\u573a\u6e38\u620f\uff1a

    \n\n
      \n\t
    • \u4f60\u4ece\u7b2c\u00a00\u00a0\u5929\u5f00\u59cb\u5403\u7cd6\u679c\u3002
    • \n\t
    • \u4f60\u5728\u5403\u5b8c \u6240\u6709\u00a0\u7b2c i - 1\u00a0\u7c7b\u7cd6\u679c\u4e4b\u524d\uff0c\u4e0d\u80fd\u00a0\u5403\u4efb\u4f55\u4e00\u9897\u7b2c i\u00a0\u7c7b\u7cd6\u679c\u3002
    • \n\t
    • \u5728\u5403\u5b8c\u6240\u6709\u7cd6\u679c\u4e4b\u524d\uff0c\u4f60\u5fc5\u987b\u6bcf\u5929 \u81f3\u5c11\u00a0\u5403 \u4e00\u9897\u00a0\u7cd6\u679c\u3002
    • \n
    \n\n

    \u8bf7\u4f60\u6784\u5efa\u4e00\u4e2a\u5e03\u5c14\u578b\u6570\u7ec4\u00a0answer\u00a0\uff0c\u6ee1\u8db3\u00a0answer.length == queries.length \u3002answer[i]\u00a0\u4e3a\u00a0true\u00a0\u7684\u6761\u4ef6\u662f\uff1a\u5728\u6bcf\u5929\u5403 \u4e0d\u8d85\u8fc7 dailyCapi\u00a0\u9897\u7cd6\u679c\u7684\u524d\u63d0\u4e0b\uff0c\u4f60\u53ef\u4ee5\u5728\u7b2c\u00a0favoriteDayi\u00a0\u5929\u5403\u5230\u7b2c\u00a0favoriteTypei\u00a0\u7c7b\u7cd6\u679c\uff1b\u5426\u5219 answer[i]\u00a0\u4e3a false\u00a0\u3002\u6ce8\u610f\uff0c\u53ea\u8981\u6ee1\u8db3\u4e0a\u9762 3 \u6761\u89c4\u5219\u4e2d\u7684\u7b2c\u4e8c\u6761\u89c4\u5219\uff0c\u4f60\u5c31\u53ef\u4ee5\u5728\u540c\u4e00\u5929\u5403\u4e0d\u540c\u7c7b\u578b\u7684\u7cd6\u679c\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u5f97\u5230\u7684\u6570\u7ec4\u00a0answer\u00a0\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1acandiesCount = [7,4,5,3,8], queries = [[0,2,2],[4,2,4],[2,13,1000000000]]\n\u8f93\u51fa\uff1a[true,false,true]\n\u63d0\u793a\uff1a\n1- \u5728\u7b2c 0 \u5929\u5403 2 \u9897\u7cd6\u679c(\u7c7b\u578b 0\uff09\uff0c\u7b2c 1 \u5929\u5403 2 \u9897\u7cd6\u679c\uff08\u7c7b\u578b 0\uff09\uff0c\u7b2c 2 \u5929\u4f60\u53ef\u4ee5\u5403\u5230\u7c7b\u578b 0 \u7684\u7cd6\u679c\u3002\n2- \u6bcf\u5929\u4f60\u6700\u591a\u5403 4 \u9897\u7cd6\u679c\u3002\u5373\u4f7f\u7b2c 0 \u5929\u5403 4 \u9897\u7cd6\u679c\uff08\u7c7b\u578b 0\uff09\uff0c\u7b2c 1 \u5929\u5403 4 \u9897\u7cd6\u679c\uff08\u7c7b\u578b 0 \u548c\u7c7b\u578b 1\uff09\uff0c\u4f60\u4e5f\u6ca1\u529e\u6cd5\u5728\u7b2c 2 \u5929\u5403\u5230\u7c7b\u578b 4 \u7684\u7cd6\u679c\u3002\u6362\u8a00\u4e4b\uff0c\u4f60\u6ca1\u6cd5\u5728\u6bcf\u5929\u5403 4 \u9897\u7cd6\u679c\u7684\u9650\u5236\u4e0b\u5728\u7b2c 2 \u5929\u5403\u5230\u7b2c 4 \u7c7b\u7cd6\u679c\u3002\n3- \u5982\u679c\u4f60\u6bcf\u5929\u5403 1 \u9897\u7cd6\u679c\uff0c\u4f60\u53ef\u4ee5\u5728\u7b2c 13 \u5929\u5403\u5230\u7c7b\u578b 2 \u7684\u7cd6\u679c\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1acandiesCount = [5,2,6,4,1], queries = [[3,1,2],[4,10,3],[3,10,100],[4,100,30],[1,3,1]]\n\u8f93\u51fa\uff1a[false,true,true,false,false]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= candiesCount.length <= 105
    • \n\t
    • 1 <= candiesCount[i] <= 105
    • \n\t
    • 1 <= queries.length <= 105
    • \n\t
    • queries[i].length == 3
    • \n\t
    • 0 <= favoriteTypei < candiesCount.length
    • \n\t
    • 0 <= favoriteDayi <= 109
    • \n\t
    • 1 <= dailyCapi <= 109
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector canEat(vector& candiesCount, vector>& queries) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean[] canEat(int[] candiesCount, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canEat(self, candiesCount, queries):\n \"\"\"\n :type candiesCount: List[int]\n :type queries: List[List[int]]\n :rtype: List[bool]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canEat(self, candiesCount: List[int], queries: List[List[int]]) -> List[bool]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nbool* canEat(int* candiesCount, int candiesCountSize, int** queries, int queriesSize, int* queriesColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool[] CanEat(int[] candiesCount, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} candiesCount\n * @param {number[][]} queries\n * @return {boolean[]}\n */\nvar canEat = function(candiesCount, queries) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} candies_count\n# @param {Integer[][]} queries\n# @return {Boolean[]}\ndef can_eat(candies_count, queries)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canEat(_ candiesCount: [Int], _ queries: [[Int]]) -> [Bool] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canEat(candiesCount []int, queries [][]int) []bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canEat(candiesCount: Array[Int], queries: Array[Array[Int]]): Array[Boolean] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canEat(candiesCount: IntArray, queries: Array): BooleanArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_eat(candies_count: Vec, queries: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $candiesCount\n * @param Integer[][] $queries\n * @return Boolean[]\n */\n function canEat($candiesCount, $queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canEat(candiesCount: number[], queries: number[][]): boolean[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-eat candiesCount queries)\n (-> (listof exact-integer?) (listof (listof exact-integer?)) (listof boolean?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1744](https://leetcode-cn.com/problems/can-you-eat-your-favorite-candy-on-your-favorite-day)", "[\u4f60\u80fd\u5728\u4f60\u6700\u559c\u6b22\u7684\u90a3\u5929\u5403\u5230\u4f60\u6700\u559c\u6b22\u7684\u7cd6\u679c\u5417\uff1f](/solution/1700-1799/1744.Can%20You%20Eat%20Your%20Favorite%20Candy%20on%20Your%20Favorite%20Day/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1744](https://leetcode.com/problems/can-you-eat-your-favorite-candy-on-your-favorite-day)", "[Can You Eat Your Favorite Candy on Your Favorite Day](/solution/1700-1799/1744.Can%20You%20Eat%20Your%20Favorite%20Candy%20on%20Your%20Favorite%20Day/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "1871", "frontend_question_id": "1745", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/palindrome-partitioning-iv", "url_en": "https://leetcode.com/problems/palindrome-partitioning-iv", "relative_path_cn": "/solution/1700-1799/1745.Palindrome%20Partitioning%20IV/README.md", "relative_path_en": "/solution/1700-1799/1745.Palindrome%20Partitioning%20IV/README_EN.md", "title_cn": "\u56de\u6587\u4e32\u5206\u5272 IV", "title_en": "Palindrome Partitioning IV", "question_title_slug": "palindrome-partitioning-iv", "content_en": "

    Given a string s, return true if it is possible to split the string s into three non-empty palindromic substrings. Otherwise, return false.\u200b\u200b\u200b\u200b\u200b

    \n\n

    A string is said to be palindrome if it the same string when reversed.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "abcbdd"\nOutput: true\nExplanation: "abcbdd" = "a" + "bcb" + "dd", and all three substrings are palindromes.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "bcbddxy"\nOutput: false\nExplanation: s cannot be split into 3 palindromes.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 3 <= s.length <= 2000
    • \n\t
    • s\u200b\u200b\u200b\u200b\u200b\u200b consists only of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32\u00a0s\u00a0\uff0c\u5982\u679c\u53ef\u4ee5\u5c06\u5b83\u5206\u5272\u6210\u4e09\u4e2a\u00a0\u975e\u7a7a\u00a0\u56de\u6587\u5b50\u5b57\u7b26\u4e32\uff0c\u90a3\u4e48\u8fd4\u56de\u00a0true\u00a0\uff0c\u5426\u5219\u8fd4\u56de\u00a0false\u00a0\u3002

    \n\n

    \u5f53\u4e00\u4e2a\u5b57\u7b26\u4e32\u6b63\u7740\u8bfb\u548c\u53cd\u7740\u8bfb\u662f\u4e00\u6a21\u4e00\u6837\u7684\uff0c\u5c31\u79f0\u5176\u4e3a \u56de\u6587\u5b57\u7b26\u4e32 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"abcbdd\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\"abcbdd\" = \"a\" + \"bcb\" + \"dd\"\uff0c\u4e09\u4e2a\u5b50\u5b57\u7b26\u4e32\u90fd\u662f\u56de\u6587\u7684\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"bcbddxy\"\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1as \u6ca1\u529e\u6cd5\u88ab\u5206\u5272\u6210 3 \u4e2a\u56de\u6587\u5b50\u5b57\u7b26\u4e32\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 3 <= s.length <= 2000
    • \n\t
    • s\u200b\u200b\u200b\u200b\u200b\u200b \u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    • \n
    \n", "tags_en": ["String", "Dynamic Programming"], "tags_cn": ["\u5b57\u7b26\u4e32", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool checkPartitioning(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean checkPartitioning(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def checkPartitioning(self, s):\n \"\"\"\n :type s: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def checkPartitioning(self, s: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool checkPartitioning(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CheckPartitioning(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {boolean}\n */\nvar checkPartitioning = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Boolean}\ndef check_partitioning(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func checkPartitioning(_ s: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func checkPartitioning(s string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def checkPartitioning(s: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun checkPartitioning(s: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn check_partitioning(s: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Boolean\n */\n function checkPartitioning($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function checkPartitioning(s: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (check-partitioning s)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1745](https://leetcode-cn.com/problems/palindrome-partitioning-iv)", "[\u56de\u6587\u4e32\u5206\u5272 IV](/solution/1700-1799/1745.Palindrome%20Partitioning%20IV/README.md)", "`\u5b57\u7b26\u4e32`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1745](https://leetcode.com/problems/palindrome-partitioning-iv)", "[Palindrome Partitioning IV](/solution/1700-1799/1745.Palindrome%20Partitioning%20IV/README_EN.md)", "`String`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "1866", "frontend_question_id": "1743", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/restore-the-array-from-adjacent-pairs", "url_en": "https://leetcode.com/problems/restore-the-array-from-adjacent-pairs", "relative_path_cn": "/solution/1700-1799/1743.Restore%20the%20Array%20From%20Adjacent%20Pairs/README.md", "relative_path_en": "/solution/1700-1799/1743.Restore%20the%20Array%20From%20Adjacent%20Pairs/README_EN.md", "title_cn": "\u4ece\u76f8\u90bb\u5143\u7d20\u5bf9\u8fd8\u539f\u6570\u7ec4", "title_en": "Restore the Array From Adjacent Pairs", "question_title_slug": "restore-the-array-from-adjacent-pairs", "content_en": "

    There is an integer array nums that consists of n unique elements, but you have forgotten it. However, you do remember every pair of adjacent elements in nums.

    \n\n

    You are given a 2D integer array adjacentPairs of size n - 1 where each adjacentPairs[i] = [ui, vi] indicates that the elements ui and vi are adjacent in nums.

    \n\n

    It is guaranteed that every adjacent pair of elements nums[i] and nums[i+1] will exist in adjacentPairs, either as [nums[i], nums[i+1]] or [nums[i+1], nums[i]]. The pairs can appear in any order.

    \n\n

    Return the original array nums. If there are multiple solutions, return any of them.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: adjacentPairs = [[2,1],[3,4],[3,2]]\nOutput: [1,2,3,4]\nExplanation: This array has all its adjacent pairs in adjacentPairs.\nNotice that adjacentPairs[i] may not be in left-to-right order.\n
    \n\n

    Example 2:

    \n\n
    \nInput: adjacentPairs = [[4,-2],[1,4],[-3,1]]\nOutput: [-2,4,1,-3]\nExplanation: There can be negative numbers.\nAnother solution is [-3,1,4,-2], which would also be accepted.\n
    \n\n

    Example 3:

    \n\n
    \nInput: adjacentPairs = [[100000,-100000]]\nOutput: [100000,-100000]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • nums.length == n
    • \n\t
    • adjacentPairs.length == n - 1
    • \n\t
    • adjacentPairs[i].length == 2
    • \n\t
    • 2 <= n <= 105
    • \n\t
    • -105 <= nums[i], ui, vi <= 105
    • \n\t
    • There exists some nums that has adjacentPairs as its pairs.
    • \n
    \n", "content_cn": "

    \u5b58\u5728\u4e00\u4e2a\u7531 n \u4e2a\u4e0d\u540c\u5143\u7d20\u7ec4\u6210\u7684\u6574\u6570\u6570\u7ec4 nums \uff0c\u4f46\u4f60\u5df2\u7ecf\u8bb0\u4e0d\u6e05\u5177\u4f53\u5185\u5bb9\u3002\u597d\u5728\u4f60\u8fd8\u8bb0\u5f97 nums \u4e2d\u7684\u6bcf\u4e00\u5bf9\u76f8\u90bb\u5143\u7d20\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u4e8c\u7ef4\u6574\u6570\u6570\u7ec4 adjacentPairs \uff0c\u5927\u5c0f\u4e3a n - 1 \uff0c\u5176\u4e2d\u6bcf\u4e2a adjacentPairs[i] = [ui, vi] \u8868\u793a\u5143\u7d20 ui \u548c vi \u5728 nums \u4e2d\u76f8\u90bb\u3002

    \n\n

    \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u6240\u6709\u7531\u5143\u7d20 nums[i] \u548c nums[i+1] \u7ec4\u6210\u7684\u76f8\u90bb\u5143\u7d20\u5bf9\u90fd\u5b58\u5728\u4e8e adjacentPairs \u4e2d\uff0c\u5b58\u5728\u5f62\u5f0f\u53ef\u80fd\u662f [nums[i], nums[i+1]] \uff0c\u4e5f\u53ef\u80fd\u662f [nums[i+1], nums[i]] \u3002\u8fd9\u4e9b\u76f8\u90bb\u5143\u7d20\u5bf9\u53ef\u4ee5 \u6309\u4efb\u610f\u987a\u5e8f \u51fa\u73b0\u3002

    \n\n

    \u8fd4\u56de \u539f\u59cb\u6570\u7ec4 nums \u3002\u5982\u679c\u5b58\u5728\u591a\u79cd\u89e3\u7b54\uff0c\u8fd4\u56de \u5176\u4e2d\u4efb\u610f\u4e00\u4e2a \u5373\u53ef\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aadjacentPairs = [[2,1],[3,4],[3,2]]\n\u8f93\u51fa\uff1a[1,2,3,4]\n\u89e3\u91ca\uff1a\u6570\u7ec4\u7684\u6240\u6709\u76f8\u90bb\u5143\u7d20\u5bf9\u90fd\u5728 adjacentPairs \u4e2d\u3002\n\u7279\u522b\u8981\u6ce8\u610f\u7684\u662f\uff0cadjacentPairs[i] \u53ea\u8868\u793a\u4e24\u4e2a\u5143\u7d20\u76f8\u90bb\uff0c\u5e76\u4e0d\u4fdd\u8bc1\u5176 \u5de6-\u53f3 \u987a\u5e8f\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aadjacentPairs = [[4,-2],[1,4],[-3,1]]\n\u8f93\u51fa\uff1a[-2,4,1,-3]\n\u89e3\u91ca\uff1a\u6570\u7ec4\u4e2d\u53ef\u80fd\u5b58\u5728\u8d1f\u6570\u3002\n\u53e6\u4e00\u79cd\u89e3\u7b54\u662f [-3,1,4,-2] \uff0c\u4e5f\u4f1a\u88ab\u89c6\u4f5c\u6b63\u786e\u7b54\u6848\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aadjacentPairs = [[100000,-100000]]\n\u8f93\u51fa\uff1a[100000,-100000]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • nums.length == n
    • \n\t
    • adjacentPairs.length == n - 1
    • \n\t
    • adjacentPairs[i].length == 2
    • \n\t
    • 2 <= n <= 105
    • \n\t
    • -105 <= nums[i], ui, vi <= 105
    • \n\t
    • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u5b58\u5728\u4e00\u4e9b\u4ee5\u00a0adjacentPairs \u4f5c\u4e3a\u5143\u7d20\u5bf9\u7684\u6570\u7ec4 nums
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector restoreArray(vector>& adjacentPairs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] restoreArray(int[][] adjacentPairs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def restoreArray(self, adjacentPairs):\n \"\"\"\n :type adjacentPairs: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def restoreArray(self, adjacentPairs: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* restoreArray(int** adjacentPairs, int adjacentPairsSize, int* adjacentPairsColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] RestoreArray(int[][] adjacentPairs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} adjacentPairs\n * @return {number[]}\n */\nvar restoreArray = function(adjacentPairs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} adjacent_pairs\n# @return {Integer[]}\ndef restore_array(adjacent_pairs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func restoreArray(_ adjacentPairs: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func restoreArray(adjacentPairs [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def restoreArray(adjacentPairs: Array[Array[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun restoreArray(adjacentPairs: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn restore_array(adjacent_pairs: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $adjacentPairs\n * @return Integer[]\n */\n function restoreArray($adjacentPairs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function restoreArray(adjacentPairs: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (restore-array adjacentPairs)\n (-> (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1743](https://leetcode-cn.com/problems/restore-the-array-from-adjacent-pairs)", "[\u4ece\u76f8\u90bb\u5143\u7d20\u5bf9\u8fd8\u539f\u6570\u7ec4](/solution/1700-1799/1743.Restore%20the%20Array%20From%20Adjacent%20Pairs/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1743](https://leetcode.com/problems/restore-the-array-from-adjacent-pairs)", "[Restore the Array From Adjacent Pairs](/solution/1700-1799/1743.Restore%20the%20Array%20From%20Adjacent%20Pairs/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1865", "frontend_question_id": "1724", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/checking-existence-of-edge-length-limited-paths-ii", "url_en": "https://leetcode.com/problems/checking-existence-of-edge-length-limited-paths-ii", "relative_path_cn": "/solution/1700-1799/1724.Checking%20Existence%20of%20Edge%20Length%20Limited%20Paths%20II/README.md", "relative_path_en": "/solution/1700-1799/1724.Checking%20Existence%20of%20Edge%20Length%20Limited%20Paths%20II/README_EN.md", "title_cn": "\u68c0\u67e5\u8fb9\u957f\u5ea6\u9650\u5236\u7684\u8def\u5f84\u662f\u5426\u5b58\u5728 II", "title_en": "Checking Existence of Edge Length Limited Paths II", "question_title_slug": "checking-existence-of-edge-length-limited-paths-ii", "content_en": "

    An undirected graph of n nodes is defined by edgeList, where edgeList[i] = [ui, vi, disi] denotes an edge between nodes ui and vi with distance disi. Note that there may be multiple edges between two nodes, and the graph may not be connected.

    \n\n

    Implement the DistanceLimitedPathsExist class:

    \n\n
      \n\t
    • DistanceLimitedPathsExist(int n, int[][] edgeList) Initializes the class with an undirected graph.
    • \n\t
    • boolean query(int p, int q, int limit) Returns true if there exists a path from p to q such that each edge on the path has a distance strictly less than limit, and otherwise false.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput\n["DistanceLimitedPathsExist", "query", "query", "query", "query"]\n[[6, [[0, 2, 4], [0, 3, 2], [1, 2, 3], [2, 3, 1], [4, 5, 5]]], [2, 3, 2], [1, 3, 3], [2, 0, 3], [0, 5, 6]]\nOutput\n[null, true, false, true, false]\n\nExplanation\nDistanceLimitedPathsExist distanceLimitedPathsExist = new DistanceLimitedPathsExist(6, [[0, 2, 4], [0, 3, 2], [1, 2, 3], [2, 3, 1], [4, 5, 5]]);\ndistanceLimitedPathsExist.query(2, 3, 2); // return true. There is an edge from 2 to 3 of distance 1, which is less than 2.\ndistanceLimitedPathsExist.query(1, 3, 3); // return false. There is no way to go from 1 to 3 with distances strictly less than 3.\ndistanceLimitedPathsExist.query(2, 0, 3); // return true. There is a way to go from 2 to 0 with distance < 3: travel from 2 to 3 to 0.\ndistanceLimitedPathsExist.query(0, 5, 6); // return false. There are no paths from 0 to 5.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= n <= 104
    • \n\t
    • 0 <= edgeList.length <= 104
    • \n\t
    • edgeList[i].length == 3
    • \n\t
    • 0 <= ui, vi, p, q <= n-1
    • \n\t
    • ui != vi
    • \n\t
    • p != q
    • \n\t
    • 1 <= disi, limit <= 109
    • \n\t
    • At most 104 calls will be made to query.
    • \n
    \n", "content_cn": "

    \u4e00\u5f20\u6709\u00a0n\u00a0\u4e2a\u8282\u70b9\u7684\u65e0\u5411\u56fe\u4ee5\u8fb9\u7684\u5217\u8868\u00a0edgeList\u00a0\u7684\u5f62\u5f0f\u5b9a\u4e49\uff0c\u5176\u4e2d\u00a0edgeList[i] = [ui, vi, disi]\u00a0\u8868\u793a\u4e00\u6761\u8fde\u63a5\u00a0ui\u00a0\u548c\u00a0vi\u00a0\uff0c\u8ddd\u79bb\u4e3a\u00a0disi\u00a0\u7684\u8fb9\u3002\u6ce8\u610f\uff0c\u540c\u4e00\u5bf9\u8282\u70b9\u95f4\u53ef\u80fd\u6709\u591a\u6761\u8fb9\uff0c\u4e14\u8be5\u56fe\u53ef\u80fd\u4e0d\u662f\u8fde\u901a\u7684\u3002

    \n\n

    \u5b9e\u73b0\u00a0DistanceLimitedPathsExist\u00a0\u7c7b\uff1a

    \n\n
      \n\t
    • DistanceLimitedPathsExist(int n, int[][] edgeList)\u00a0\u4ee5\u7ed9\u5b9a\u7684\u65e0\u5411\u56fe\u521d\u59cb\u5316\u5bf9\u8c61\u3002
    • \n\t
    • boolean query(int p, int q, int limit)\u00a0\u5f53\u5b58\u5728\u4e00\u6761\u4ece\u00a0p\u00a0\u5230 q \u7684\u8def\u5f84\uff0c\u4e14\u8def\u5f84\u4e2d\u6bcf\u6761\u8fb9\u7684\u8ddd\u79bb\u90fd\u4e25\u683c\u5c0f\u4e8e limit \u65f6\uff0c\u8fd4\u56de true \uff0c\u5426\u5219\u8fd4\u56de false \u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1:

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1a\n[\"DistanceLimitedPathsExist\", \"query\", \"query\", \"query\", \"query\"]\n[[6, [[0, 2, 4], [0, 3, 2], [1, 2, 3], [2, 3, 1], [4, 5, 5]]], [2, 3, 2], [1, 3, 3], [2, 0, 3], [0, 5, 6]]\n\u8f93\u51fa\uff1a\n[null, true, false, true, false]\n\n\u89e3\u91ca\uff1a\nDistanceLimitedPathsExist distanceLimitedPathsExist = new DistanceLimitedPathsExist(6, [[0, 2, 4], [0, 3, 2], [1, 2, 3], [2, 3, 1], [4, 5, 5]]);\ndistanceLimitedPathsExist.query(2, 3, 2); // \u8fd4\u56de true\u3002\u5b58\u5728\u4e00\u6761\u4ece 2 \u5230 3 \uff0c\u8ddd\u79bb\u4e3a 1 \u7684\u8fb9\uff0c\n\u00a0                                         // \u8fd9\u6761\u8fb9\u7684\u8ddd\u79bb\u5c0f\u4e8e 2\u3002\ndistanceLimitedPathsExist.query(1, 3, 3); // \u8fd4\u56de false\u3002\u4ece 1 \u5230 3 \u4e4b\u95f4\u4e0d\u5b58\u5728\u6bcf\u6761\u8fb9\u7684\u8ddd\u79bb\u90fd\n                                          // \u4e25\u683c\u5c0f\u4e8e 3 \u7684\u8def\u5f84\u3002\ndistanceLimitedPathsExist.query(2, 0, 3); // \u8fd4\u56de true\u3002\u5b58\u5728\u4e00\u6761\u4ece 2 \u5230 0 \u7684\u8def\u5f84\uff0c\u4f7f\u5f97\u6bcf\u6761\u8fb9\u7684\n                                          // \u8ddd\u79bb < 3\uff1a\u4ece 2 \u5230 3 \u5230 0 \u884c\u8fdb\u5373\u53ef\u3002\ndistanceLimitedPathsExist.query(0, 5, 6); // \u8fd4\u56de false\u3002\u4ece 0 \u5230 5 \u4e4b\u95f4\u4e0d\u5b58\u5728\u8def\u5f84\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= n <= 104
    • \n\t
    • 0 <= edgeList.length <= 104
    • \n\t
    • edgeList[i].length == 3
    • \n\t
    • 0 <= ui, vi, p, q <= n-1
    • \n\t
    • ui != vi
    • \n\t
    • p != q
    • \n\t
    • 1 <= disi, limit <= 109
    • \n\t
    • \u6700\u591a\u8c03\u7528\u00a0104\u00a0\u6b21\u00a0query\u00a0\u3002
    • \n
    \n", "tags_en": ["Union Find", "Graph", "Dynamic Programming"], "tags_cn": ["\u5e76\u67e5\u96c6", "\u56fe", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class DistanceLimitedPathsExist {\npublic:\n DistanceLimitedPathsExist(int n, vector>& edgeList) {\n\n }\n \n bool query(int p, int q, int limit) {\n\n }\n};\n\n/**\n * Your DistanceLimitedPathsExist object will be instantiated and called as such:\n * DistanceLimitedPathsExist* obj = new DistanceLimitedPathsExist(n, edgeList);\n * bool param_1 = obj->query(p,q,limit);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class DistanceLimitedPathsExist {\n\n public DistanceLimitedPathsExist(int n, int[][] edgeList) {\n\n }\n \n public boolean query(int p, int q, int limit) {\n\n }\n}\n\n/**\n * Your DistanceLimitedPathsExist object will be instantiated and called as such:\n * DistanceLimitedPathsExist obj = new DistanceLimitedPathsExist(n, edgeList);\n * boolean param_1 = obj.query(p,q,limit);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class DistanceLimitedPathsExist(object):\n\n def __init__(self, n, edgeList):\n \"\"\"\n :type n: int\n :type edgeList: List[List[int]]\n \"\"\"\n\n\n def query(self, p, q, limit):\n \"\"\"\n :type p: int\n :type q: int\n :type limit: int\n :rtype: bool\n \"\"\"\n\n\n\n# Your DistanceLimitedPathsExist object will be instantiated and called as such:\n# obj = DistanceLimitedPathsExist(n, edgeList)\n# param_1 = obj.query(p,q,limit)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class DistanceLimitedPathsExist:\n\n def __init__(self, n: int, edgeList: List[List[int]]):\n\n\n def query(self, p: int, q: int, limit: int) -> bool:\n\n\n\n# Your DistanceLimitedPathsExist object will be instantiated and called as such:\n# obj = DistanceLimitedPathsExist(n, edgeList)\n# param_1 = obj.query(p,q,limit)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} DistanceLimitedPathsExist;\n\n\nDistanceLimitedPathsExist* distanceLimitedPathsExistCreate(int n, int** edgeList, int edgeListSize, int* edgeListColSize) {\n\n}\n\nbool distanceLimitedPathsExistQuery(DistanceLimitedPathsExist* obj, int p, int q, int limit) {\n\n}\n\nvoid distanceLimitedPathsExistFree(DistanceLimitedPathsExist* obj) {\n\n}\n\n/**\n * Your DistanceLimitedPathsExist struct will be instantiated and called as such:\n * DistanceLimitedPathsExist* obj = distanceLimitedPathsExistCreate(n, edgeList, edgeListSize, edgeListColSize);\n * bool param_1 = distanceLimitedPathsExistQuery(obj, p, q, limit);\n \n * distanceLimitedPathsExistFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class DistanceLimitedPathsExist {\n\n public DistanceLimitedPathsExist(int n, int[][] edgeList) {\n\n }\n \n public bool Query(int p, int q, int limit) {\n\n }\n}\n\n/**\n * Your DistanceLimitedPathsExist object will be instantiated and called as such:\n * DistanceLimitedPathsExist obj = new DistanceLimitedPathsExist(n, edgeList);\n * bool param_1 = obj.Query(p,q,limit);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} edgeList\n */\nvar DistanceLimitedPathsExist = function(n, edgeList) {\n\n};\n\n/** \n * @param {number} p \n * @param {number} q \n * @param {number} limit\n * @return {boolean}\n */\nDistanceLimitedPathsExist.prototype.query = function(p, q, limit) {\n\n};\n\n/**\n * Your DistanceLimitedPathsExist object will be instantiated and called as such:\n * var obj = new DistanceLimitedPathsExist(n, edgeList)\n * var param_1 = obj.query(p,q,limit)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class DistanceLimitedPathsExist\n\n=begin\n :type n: Integer\n :type edge_list: Integer[][]\n=end\n def initialize(n, edge_list)\n\n end\n\n\n=begin\n :type p: Integer\n :type q: Integer\n :type limit: Integer\n :rtype: Boolean\n=end\n def query(p, q, limit)\n\n end\n\n\nend\n\n# Your DistanceLimitedPathsExist object will be instantiated and called as such:\n# obj = DistanceLimitedPathsExist.new(n, edge_list)\n# param_1 = obj.query(p, q, limit)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass DistanceLimitedPathsExist {\n\n init(_ n: Int, _ edgeList: [[Int]]) {\n\n }\n \n func query(_ p: Int, _ q: Int, _ limit: Int) -> Bool {\n\n }\n}\n\n/**\n * Your DistanceLimitedPathsExist object will be instantiated and called as such:\n * let obj = DistanceLimitedPathsExist(n, edgeList)\n * let ret_1: Bool = obj.query(p, q, limit)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type DistanceLimitedPathsExist struct {\n\n}\n\n\nfunc Constructor(n int, edgeList [][]int) DistanceLimitedPathsExist {\n\n}\n\n\nfunc (this *DistanceLimitedPathsExist) Query(p int, q int, limit int) bool {\n\n}\n\n\n/**\n * Your DistanceLimitedPathsExist object will be instantiated and called as such:\n * obj := Constructor(n, edgeList);\n * param_1 := obj.Query(p,q,limit);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class DistanceLimitedPathsExist(_n: Int, _edgeList: Array[Array[Int]]) {\n\n def query(p: Int, q: Int, limit: Int): Boolean = {\n \n }\n\n}\n\n/**\n * Your DistanceLimitedPathsExist object will be instantiated and called as such:\n * var obj = new DistanceLimitedPathsExist(n, edgeList)\n * var param_1 = obj.query(p,q,limit)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class DistanceLimitedPathsExist(n: Int, edgeList: Array) {\n\n fun query(p: Int, q: Int, limit: Int): Boolean {\n\n }\n\n}\n\n/**\n * Your DistanceLimitedPathsExist object will be instantiated and called as such:\n * var obj = DistanceLimitedPathsExist(n, edgeList)\n * var param_1 = obj.query(p,q,limit)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct DistanceLimitedPathsExist {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl DistanceLimitedPathsExist {\n\n fn new(n: i32, edgeList: Vec>) -> Self {\n\n }\n \n fn query(&self, p: i32, q: i32, limit: i32) -> bool {\n\n }\n}\n\n/**\n * Your DistanceLimitedPathsExist object will be instantiated and called as such:\n * let obj = DistanceLimitedPathsExist::new(n, edgeList);\n * let ret_1: bool = obj.query(p, q, limit);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class DistanceLimitedPathsExist {\n /**\n * @param Integer $n\n * @param Integer[][] $edgeList\n */\n function __construct($n, $edgeList) {\n\n }\n\n /**\n * @param Integer $p\n * @param Integer $q\n * @param Integer $limit\n * @return Boolean\n */\n function query($p, $q, $limit) {\n\n }\n}\n\n/**\n * Your DistanceLimitedPathsExist object will be instantiated and called as such:\n * $obj = DistanceLimitedPathsExist($n, $edgeList);\n * $ret_1 = $obj->query($p, $q, $limit);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class DistanceLimitedPathsExist {\n constructor(n: number, edgeList: number[][]) {\n\n }\n\n query(p: number, q: number, limit: number): boolean {\n\n }\n}\n\n/**\n * Your DistanceLimitedPathsExist object will be instantiated and called as such:\n * var obj = new DistanceLimitedPathsExist(n, edgeList)\n * var param_1 = obj.query(p,q,limit)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define distance-limited-paths-exist%\n (class object%\n (super-new)\n\n ; n : exact-integer?\n\n ; edge-list : (listof (listof exact-integer?))\n (init-field\n n\n edge-list)\n \n ; query : exact-integer? exact-integer? exact-integer? -> boolean?\n (define/public (query p q limit)\n\n )))\n\n;; Your distance-limited-paths-exist% object will be instantiated and called as such:\n;; (define obj (new distance-limited-paths-exist% [n n] [edgeList edgeList]))\n;; (define param_1 (send obj query p q limit))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1724](https://leetcode-cn.com/problems/checking-existence-of-edge-length-limited-paths-ii)", "[\u68c0\u67e5\u8fb9\u957f\u5ea6\u9650\u5236\u7684\u8def\u5f84\u662f\u5426\u5b58\u5728 II](/solution/1700-1799/1724.Checking%20Existence%20of%20Edge%20Length%20Limited%20Paths%20II/README.md)", "`\u5e76\u67e5\u96c6`,`\u56fe`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1724](https://leetcode.com/problems/checking-existence-of-edge-length-limited-paths-ii)", "[Checking Existence of Edge Length Limited Paths II](/solution/1700-1799/1724.Checking%20Existence%20of%20Edge%20Length%20Limited%20Paths%20II/README_EN.md)", "`Union Find`,`Graph`,`Dynamic Programming`", "Hard", "\ud83d\udd12"]}, {"question_id": "1862", "frontend_question_id": "1715", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/count-apples-and-oranges", "url_en": "https://leetcode.com/problems/count-apples-and-oranges", "relative_path_cn": "/solution/1700-1799/1715.Count%20Apples%20and%20Oranges/README.md", "relative_path_en": "/solution/1700-1799/1715.Count%20Apples%20and%20Oranges/README_EN.md", "title_cn": "\u82f9\u679c\u548c\u6a58\u5b50\u7684\u4e2a\u6570", "title_en": "Count Apples and Oranges", "question_title_slug": "count-apples-and-oranges", "content_en": "

    Table: Boxes

    \n\n
    \n+--------------+------+\n| Column Name  | Type |\n+--------------+------+\n| box_id       | int  |\n| chest_id     | int  |\n| apple_count  | int  |\n| orange_count | int  |\n+--------------+------+\nbox_id is the primary key for this table.\nchest_id is a foreign key of the chests table.\nThis table contains information about the boxes and the number of oranges and apples they contain. Each box may contain a chest, which also can contain oranges and apples.\n
    \n\n

     

    \n\n

    Table: Chests

    \n\n
    \n+--------------+------+\n| Column Name  | Type |\n+--------------+------+\n| chest_id     | int  |\n| apple_count  | int  |\n| orange_count | int  |\n+--------------+------+\nchest_id is the primary key for this table.\nThis table contains information about the chests we have, and the corresponding number if oranges and apples they contain.\n
    \n\n

     

    \n\n

    Write an SQL query to count the number of apples and oranges in all the boxes. If a box contains a chest, you should also include the number of apples and oranges it has.

    \n\n

    Return the result table in any order.

    \n\n

    The query result format is in the following example:

    \n\n

     

    \n\n
    \nBoxes table:\n+--------+----------+-------------+--------------+\n| box_id | chest_id | apple_count | orange_count |\n+--------+----------+-------------+--------------+\n| 2      | null     | 6           | 15           |\n| 18     | 14       | 4           | 15           |\n| 19     | 3        | 8           | 4            |\n| 12     | 2        | 19          | 20           |\n| 20     | 6        | 12          | 9            |\n| 8      | 6        | 9           | 9            |\n| 3      | 14       | 16          | 7            |\n+--------+----------+-------------+--------------+\n\nChests table:\n+----------+-------------+--------------+\n| chest_id | apple_count | orange_count |\n+----------+-------------+--------------+\n| 6        | 5           | 6            |\n| 14       | 20          | 10           |\n| 2        | 8           | 8            |\n| 3        | 19          | 4            |\n| 16       | 19          | 19           |\n+----------+-------------+--------------+\n\nResult table:\n+-------------+--------------+\n| apple_count | orange_count |\n+-------------+--------------+\n| 151         | 123          |\n+-------------+--------------+\nbox 2 has 6 apples and 15 oranges.\nbox 18 has 4 + 20 (from the chest) = 24 apples and 15 + 10 (from the chest) = 25 oranges.\nbox 19 has 8 + 19 (from the chest) = 27 apples and 4 + 4 (from the chest) = 8 oranges.\nbox 12 has 19 + 8 (from the chest) = 27 apples and 20 + 8 (from the chest) = 28 oranges.\nbox 20 has 12 + 5 (from the chest) = 17 apples and 9 + 6 (from the chest) = 15 oranges.\nbox 8 has 9 + 5 (from the chest) = 14 apples and 9 + 6 (from the chest) = 15 oranges.\nbox 3 has 16 + 20 (from the chest) = 36 apples and 7 + 10 (from the chest) = 17 oranges.\nTotal number of apples = 6 + 24 + 27 + 27 + 17 + 14 + 36 = 151\nTotal number of oranges = 15 + 25 + 8 + 28 + 15 + 15 + 17 = 123\n
    \n", "content_cn": "

    \u8868\uff1a\u00a0Boxes

    \n\n
    +--------------+------+\n| Column Name  | Type |\n+--------------+------+\n| box_id       | int  |\n| chest_id     | int  |\n| apple_count  | int  |\n| orange_count | int  |\n+--------------+------+\nbox_id \u662f\u8be5\u8868\u7684\u4e3b\u952e\u3002\nchest_id \u662f chests \u8868\u7684\u5916\u952e\u3002\n\u8be5\u8868\u5305\u542b\u5927\u7bb1\u5b50 (box) \u4e2d\u5305\u542b\u7684\u82f9\u679c\u548c\u6a58\u5b50\u7684\u4e2a\u6570\u3002\u6bcf\u4e2a\u5927\u7bb1\u5b50\u4e2d\u53ef\u80fd\u5305\u542b\u4e00\u4e2a\u5c0f\u76d2\u5b50 (chest) \uff0c\u5c0f\u76d2\u5b50\u4e2d\u4e5f\u5305\u542b\u82e5\u5e72\u82f9\u679c\u548c\u6a58\u5b50\u3002
    \n\n

    \u00a0

    \n\n

    \u8868\uff1a\u00a0Chests

    \n\n
    +--------------+------+\n| Column Name  | Type |\n+--------------+------+\n| chest_id     | int  |\n| apple_count  | int  |\n| orange_count | int  |\n+--------------+------+\nchest_id \u662f\u8be5\u8868\u7684\u4e3b\u952e\u3002\n\u8be5\u8868\u5305\u542b\u5c0f\u76d2\u5b50\u7684\u4fe1\u606f\uff0c\u4ee5\u53ca\u5c0f\u76d2\u5b50\u4e2d\u5305\u542b\u7684\u82f9\u679c\u548c\u6a58\u5b50\u7684\u4e2a\u6570\u3002
    \n\n

    \u00a0

    \n\n

    \u7f16\u5199 SQL \u8bed\u53e5\uff0c\u67e5\u8be2\u6bcf\u4e2a\u5927\u7bb1\u5b50\u4e2d\u82f9\u679c\u548c\u6a58\u5b50\u7684\u4e2a\u6570\u3002\u5982\u679c\u5927\u7bb1\u5b50\u4e2d\u5305\u542b\u5c0f\u76d2\u5b50\uff0c\u8fd8\u5e94\u5f53\u5305\u542b\u5c0f\u76d2\u5b50\u4e2d\u82f9\u679c\u548c\u6a58\u5b50\u7684\u4e2a\u6570\u3002

    \n\n

    \u4ee5\u4efb\u610f\u987a\u5e8f\u8fd4\u56de\u7ed3\u679c\u8868\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u7684\u683c\u5f0f\u5982\u4e0b\u793a\u4f8b\u6240\u793a\uff1a

    \n\n

    \u00a0

    \n\n
    Boxes \u8868\uff1a\n+--------+----------+-------------+--------------+\n| box_id | chest_id | apple_count | orange_count |\n+--------+----------+-------------+--------------+\n| 2      | null     | 6           | 15           |\n| 18     | 14       | 4           | 15           |\n| 19     | 3        | 8           | 4            |\n| 12     | 2        | 19          | 20           |\n| 20     | 6        | 12          | 9            |\n| 8      | 6        | 9           | 9            |\n| 3      | 14       | 16          | 7            |\n+--------+----------+-------------+--------------+\n\nChests \u8868\uff1a\n+----------+-------------+--------------+\n| chest_id | apple_count | orange_count |\n+----------+-------------+--------------+\n| 6        | 5           | 6            |\n| 14       | 20          | 10           |\n| 2        | 8           | 8            |\n| 3        | 19          | 4            |\n| 16       | 19          | 19           |\n+----------+-------------+--------------+\n\n\u7ed3\u679c\u8868\uff1a\n+-------------+--------------+\n| apple_count | orange_count |\n+-------------+--------------+\n| 151         | 123          |\n+-------------+--------------+\n\u5927\u7bb1\u5b50 2 \u4e2d\u6709 6 \u4e2a\u82f9\u679c\u548c 15 \u4e2a\u6a58\u5b50\u3002\n\u5927\u7bb1\u5b50 18 \u4e2d\u6709 4 + 20 (\u5728\u5c0f\u76d2\u5b50\u4e2d) = 24 \u4e2a\u82f9\u679c\u548c 15 + 10 (\u5728\u5c0f\u76d2\u5b50\u4e2d) = 25 \u4e2a\u6a58\u5b50\u3002\n\u5927\u7bb1\u5b50 19 \u4e2d\u6709 8 + 19 (\u5728\u5c0f\u76d2\u5b50\u4e2d) = 27 \u4e2a\u82f9\u679c\u548c 4 + 4 (\u5728\u5c0f\u76d2\u5b50\u4e2d) = 8 \u4e2a\u6a58\u5b50\u3002\n\u5927\u7bb1\u5b50 12 \u4e2d\u6709 19 + 8 (\u5728\u5c0f\u76d2\u5b50\u4e2d) = 27 \u4e2a\u82f9\u679c\u548c 20 + 8 (\u5728\u5c0f\u76d2\u5b50\u4e2d) = 28 \u4e2a\u6a58\u5b50\u3002\n\u5927\u7bb1\u5b50 20 \u4e2d\u6709 12 + 5 (\u5728\u5c0f\u76d2\u5b50\u4e2d) = 17 \u4e2a\u82f9\u679c\u548c 9 + 6 (\u5728\u5c0f\u76d2\u5b50\u4e2d) = 15 \u4e2a\u6a58\u5b50\u3002\n\u5927\u7bb1\u5b50 8 \u4e2d\u6709 9 + 5 (\u5728\u5c0f\u76d2\u5b50\u4e2d) = 14 \u4e2a\u82f9\u679c\u548c 9 + 6 (\u5728\u5c0f\u76d2\u5b50\u4e2d) = 15 \u4e2a\u6a58\u5b50\u3002\n\u5927\u7bb1\u5b50 3 \u4e2d\u6709 16 + 20 (\u5728\u5c0f\u76d2\u5b50\u4e2d) = 36 \u4e2a\u82f9\u679c\u548c 7 + 10 (\u5728\u5c0f\u76d2\u5b50\u4e2d) = 17 \u4e2a\u6a58\u5b50\u3002\n\u82f9\u679c\u7684\u603b\u4e2a\u6570 = 6 + 24 + 27 + 27 + 17 + 14 + 36 = 151\n\u6a58\u5b50\u7684\u603b\u4e2a\u6570 = 15 + 25 + 8 + 28 + 15 + 15 + 17 = 123\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1715](https://leetcode-cn.com/problems/count-apples-and-oranges)", "[\u82f9\u679c\u548c\u6a58\u5b50\u7684\u4e2a\u6570](/solution/1700-1799/1715.Count%20Apples%20and%20Oranges/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1715](https://leetcode.com/problems/count-apples-and-oranges)", "[Count Apples and Oranges](/solution/1700-1799/1715.Count%20Apples%20and%20Oranges/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1861", "frontend_question_id": "1739", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/building-boxes", "url_en": "https://leetcode.com/problems/building-boxes", "relative_path_cn": "/solution/1700-1799/1739.Building%20Boxes/README.md", "relative_path_en": "/solution/1700-1799/1739.Building%20Boxes/README_EN.md", "title_cn": "\u653e\u7f6e\u76d2\u5b50", "title_en": "Building Boxes", "question_title_slug": "building-boxes", "content_en": "

    You have a cubic storeroom where the width, length, and height of the room are all equal to n units. You are asked to place n boxes in this room where each box is a cube of unit side length. There are however some rules to placing the boxes:

    \n\n
      \n\t
    • You can place the boxes anywhere on the floor.
    • \n\t
    • If box x is placed on top of the box y, then each side of the four vertical sides of the box y must either be adjacent to another box or to a wall.
    • \n
    \n\n

    Given an integer n, return the minimum possible number of boxes touching the floor.

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: n = 3\nOutput: 3\nExplanation: The figure above is for the placement of the three boxes.\nThese boxes are placed in the corner of the room, where the corner is on the left side.\n
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: n = 4\nOutput: 3\nExplanation: The figure above is for the placement of the four boxes.\nThese boxes are placed in the corner of the room, where the corner is on the left side.\n
    \n\n

    Example 3:

    \n\n

    \"\"

    \n\n
    \nInput: n = 10\nOutput: 6\nExplanation: The figure above is for the placement of the ten boxes.\nThese boxes are placed in the corner of the room, where the corner is on the back side.
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 109
    • \n
    \n", "content_cn": "

    \u6709\u4e00\u4e2a\u7acb\u65b9\u4f53\u623f\u95f4\uff0c\u5176\u957f\u5ea6\u3001\u5bbd\u5ea6\u548c\u9ad8\u5ea6\u90fd\u7b49\u4e8e n \u4e2a\u5355\u4f4d\u3002\u8bf7\u4f60\u5728\u623f\u95f4\u91cc\u653e\u7f6e n \u4e2a\u76d2\u5b50\uff0c\u6bcf\u4e2a\u76d2\u5b50\u90fd\u662f\u4e00\u4e2a\u5355\u4f4d\u8fb9\u957f\u7684\u7acb\u65b9\u4f53\u3002\u653e\u7f6e\u89c4\u5219\u5982\u4e0b\uff1a

    \n\n
      \n\t
    • \u4f60\u53ef\u4ee5\u628a\u76d2\u5b50\u653e\u5728\u5730\u677f\u4e0a\u7684\u4efb\u4f55\u5730\u65b9\u3002
    • \n\t
    • \u5982\u679c\u76d2\u5b50 x \u9700\u8981\u653e\u7f6e\u5728\u76d2\u5b50 y \u7684\u9876\u90e8\uff0c\u90a3\u4e48\u76d2\u5b50 y \u7ad6\u76f4\u7684\u56db\u4e2a\u4fa7\u9762\u90fd \u5fc5\u987b \u4e0e\u53e6\u4e00\u4e2a\u76d2\u5b50\u6216\u5899\u76f8\u90bb\u3002
    • \n
    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n \uff0c\u8fd4\u56de\u63a5\u89e6\u5730\u9762\u7684\u76d2\u5b50\u7684 \u6700\u5c11 \u53ef\u80fd\u6570\u91cf\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1an = 3\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u4e0a\u56fe\u662f 3 \u4e2a\u76d2\u5b50\u7684\u6446\u653e\u4f4d\u7f6e\u3002\n\u8fd9\u4e9b\u76d2\u5b50\u653e\u5728\u623f\u95f4\u7684\u4e00\u89d2\uff0c\u5bf9\u5e94\u5de6\u4fa7\u4f4d\u7f6e\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1an = 4\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u4e0a\u56fe\u662f 3 \u4e2a\u76d2\u5b50\u7684\u6446\u653e\u4f4d\u7f6e\u3002\n\u8fd9\u4e9b\u76d2\u5b50\u653e\u5728\u623f\u95f4\u7684\u4e00\u89d2\uff0c\u5bf9\u5e94\u5de6\u4fa7\u4f4d\u7f6e\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1an = 10\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u4e0a\u56fe\u662f 10 \u4e2a\u76d2\u5b50\u7684\u6446\u653e\u4f4d\u7f6e\u3002\n\u8fd9\u4e9b\u76d2\u5b50\u653e\u5728\u623f\u95f4\u7684\u4e00\u89d2\uff0c\u5bf9\u5e94\u540e\u65b9\u4f4d\u7f6e\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 109
    • \n
    \n", "tags_en": ["Math", "Binary Search"], "tags_cn": ["\u6570\u5b66", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minimumBoxes(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minimumBoxes(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimumBoxes(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimumBoxes(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minimumBoxes(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinimumBoxes(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar minimumBoxes = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef minimum_boxes(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimumBoxes(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimumBoxes(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimumBoxes(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimumBoxes(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimum_boxes(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function minimumBoxes($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimumBoxes(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimum-boxes n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1739](https://leetcode-cn.com/problems/building-boxes)", "[\u653e\u7f6e\u76d2\u5b50](/solution/1700-1799/1739.Building%20Boxes/README.md)", "`\u6570\u5b66`,`\u4e8c\u5206\u67e5\u627e`", "\u56f0\u96be", ""], "md_table_row_en": ["[1739](https://leetcode.com/problems/building-boxes)", "[Building Boxes](/solution/1700-1799/1739.Building%20Boxes/README_EN.md)", "`Math`,`Binary Search`", "Hard", ""]}, {"question_id": "1860", "frontend_question_id": "1738", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-kth-largest-xor-coordinate-value", "url_en": "https://leetcode.com/problems/find-kth-largest-xor-coordinate-value", "relative_path_cn": "/solution/1700-1799/1738.Find%20Kth%20Largest%20XOR%20Coordinate%20Value/README.md", "relative_path_en": "/solution/1700-1799/1738.Find%20Kth%20Largest%20XOR%20Coordinate%20Value/README_EN.md", "title_cn": "\u627e\u51fa\u7b2c K \u5927\u7684\u5f02\u6216\u5750\u6807\u503c", "title_en": "Find Kth Largest XOR Coordinate Value", "question_title_slug": "find-kth-largest-xor-coordinate-value", "content_en": "

    You are given a 2D matrix of size m x n, consisting of non-negative integers. You are also given an integer k.

    \n\n

    The value of coordinate (a, b) of the matrix is the XOR of all matrix[i][j] where 0 <= i <= a < m and 0 <= j <= b < n (0-indexed).

    \n\n

    Find the kth largest value (1-indexed) of all the coordinates of matrix.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: matrix = [[5,2],[1,6]], k = 1\nOutput: 7\nExplanation: The value of coordinate (0,1) is 5 XOR 2 = 7, which is the largest value.
    \n\n

    Example 2:

    \n\n
    \nInput: matrix = [[5,2],[1,6]], k = 2\nOutput: 5\nExplanation: The value of coordinate (0,0) is 5 = 5, which is the 2nd largest value.
    \n\n

    Example 3:

    \n\n
    \nInput: matrix = [[5,2],[1,6]], k = 3\nOutput: 4\nExplanation: The value of coordinate (1,0) is 5 XOR 1 = 4, which is the 3rd largest value.
    \n\n

    Example 4:

    \n\n
    \nInput: matrix = [[5,2],[1,6]], k = 4\nOutput: 0\nExplanation: The value of coordinate (1,1) is 5 XOR 2 XOR 1 XOR 6 = 0, which is the 4th largest value.
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == matrix.length
    • \n\t
    • n == matrix[i].length
    • \n\t
    • 1 <= m, n <= 1000
    • \n\t
    • 0 <= matrix[i][j] <= 106
    • \n\t
    • 1 <= k <= m * n
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u4e8c\u7ef4\u77e9\u9635 matrix \u548c\u4e00\u4e2a\u6574\u6570 k \uff0c\u77e9\u9635\u5927\u5c0f\u4e3a\u00a0m x n \u7531\u975e\u8d1f\u6574\u6570\u7ec4\u6210\u3002

    \n\n

    \u77e9\u9635\u4e2d\u5750\u6807 (a, b) \u7684 \u503c \u53ef\u7531\u5bf9\u6240\u6709\u6ee1\u8db3 0 <= i <= a < m \u4e14 0 <= j <= b < n \u7684\u5143\u7d20 matrix[i][j]\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\u8ba1\u6570\uff09\u6267\u884c\u5f02\u6216\u8fd0\u7b97\u5f97\u5230\u3002

    \n\n

    \u8bf7\u4f60\u627e\u51fa\u00a0matrix \u7684\u6240\u6709\u5750\u6807\u4e2d\u7b2c k \u5927\u7684\u503c\uff08k \u7684\u503c\u4ece 1 \u5f00\u59cb\u8ba1\u6570\uff09\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1amatrix = [[5,2],[1,6]], k = 1\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\u5750\u6807 (0,1) \u7684\u503c\u662f 5 XOR 2 = 7 \uff0c\u4e3a\u6700\u5927\u7684\u503c\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1amatrix = [[5,2],[1,6]], k = 2\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u5750\u6807 (0,0) \u7684\u503c\u662f 5 = 5 \uff0c\u4e3a\u7b2c 2 \u5927\u7684\u503c\u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1amatrix = [[5,2],[1,6]], k = 3\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u5750\u6807 (1,0) \u7684\u503c\u662f 5 XOR 1 = 4 \uff0c\u4e3a\u7b2c 3 \u5927\u7684\u503c\u3002
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1amatrix = [[5,2],[1,6]], k = 4\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u5750\u6807 (1,1) \u7684\u503c\u662f 5 XOR 2 XOR 1 XOR 6 = 0 \uff0c\u4e3a\u7b2c 4 \u5927\u7684\u503c\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == matrix.length
    • \n\t
    • n == matrix[i].length
    • \n\t
    • 1 <= m, n <= 1000
    • \n\t
    • 0 <= matrix[i][j] <= 106
    • \n\t
    • 1 <= k <= m * n
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int kthLargestValue(vector>& matrix, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int kthLargestValue(int[][] matrix, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def kthLargestValue(self, matrix, k):\n \"\"\"\n :type matrix: List[List[int]]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def kthLargestValue(self, matrix: List[List[int]], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint kthLargestValue(int** matrix, int matrixSize, int* matrixColSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int KthLargestValue(int[][] matrix, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} matrix\n * @param {number} k\n * @return {number}\n */\nvar kthLargestValue = function(matrix, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} matrix\n# @param {Integer} k\n# @return {Integer}\ndef kth_largest_value(matrix, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func kthLargestValue(_ matrix: [[Int]], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func kthLargestValue(matrix [][]int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def kthLargestValue(matrix: Array[Array[Int]], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun kthLargestValue(matrix: Array, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn kth_largest_value(matrix: Vec>, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $matrix\n * @param Integer $k\n * @return Integer\n */\n function kthLargestValue($matrix, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function kthLargestValue(matrix: number[][], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (kth-largest-value matrix k)\n (-> (listof (listof exact-integer?)) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1738](https://leetcode-cn.com/problems/find-kth-largest-xor-coordinate-value)", "[\u627e\u51fa\u7b2c K \u5927\u7684\u5f02\u6216\u5750\u6807\u503c](/solution/1700-1799/1738.Find%20Kth%20Largest%20XOR%20Coordinate%20Value/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1738](https://leetcode.com/problems/find-kth-largest-xor-coordinate-value)", "[Find Kth Largest XOR Coordinate Value](/solution/1700-1799/1738.Find%20Kth%20Largest%20XOR%20Coordinate%20Value/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "1859", "frontend_question_id": "1737", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/change-minimum-characters-to-satisfy-one-of-three-conditions", "url_en": "https://leetcode.com/problems/change-minimum-characters-to-satisfy-one-of-three-conditions", "relative_path_cn": "/solution/1700-1799/1737.Change%20Minimum%20Characters%20to%20Satisfy%20One%20of%20Three%20Conditions/README.md", "relative_path_en": "/solution/1700-1799/1737.Change%20Minimum%20Characters%20to%20Satisfy%20One%20of%20Three%20Conditions/README_EN.md", "title_cn": "\u6ee1\u8db3\u4e09\u6761\u4ef6\u4e4b\u4e00\u9700\u6539\u53d8\u7684\u6700\u5c11\u5b57\u7b26\u6570", "title_en": "Change Minimum Characters to Satisfy One of Three Conditions", "question_title_slug": "change-minimum-characters-to-satisfy-one-of-three-conditions", "content_en": "

    You are given two strings a and b that consist of lowercase letters. In one operation, you can change any character in a or b to any lowercase letter.

    \n\n

    Your goal is to satisfy one of the following three conditions:

    \n\n
      \n\t
    • Every letter in a is strictly less than every letter in b in the alphabet.
    • \n\t
    • Every letter in b is strictly less than every letter in a in the alphabet.
    • \n\t
    • Both a and b consist of only one distinct letter.
    • \n
    \n\n

    Return the minimum number of operations needed to achieve your goal.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: a = "aba", b = "caa"\nOutput: 2\nExplanation: Consider the best way to make each condition true:\n1) Change b to "ccc" in 2 operations, then every letter in a is less than every letter in b.\n2) Change a to "bbb" and b to "aaa" in 3 operations, then every letter in b is less than every letter in a.\n3) Change a to "aaa" and b to "aaa" in 2 operations, then a and b consist of one distinct letter.\nThe best way was done in 2 operations (either condition 1 or condition 3).\n
    \n\n

    Example 2:

    \n\n
    \nInput: a = "dabadd", b = "cda"\nOutput: 3\nExplanation: The best way is to make condition 1 true by changing b to "eee".\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= a.length, b.length <= 105
    • \n\t
    • a and b consist only of lowercase letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u5b57\u7b26\u4e32 a \u548c b \uff0c\u4e8c\u8005\u5747\u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210\u3002\u4e00\u6b65\u64cd\u4f5c\u4e2d\uff0c\u4f60\u53ef\u4ee5\u5c06 a \u6216 b \u4e2d\u7684 \u4efb\u4e00\u5b57\u7b26 \u6539\u53d8\u4e3a \u4efb\u4e00\u5c0f\u5199\u5b57\u6bcd \u3002

    \n\n

    \u64cd\u4f5c\u7684\u6700\u7ec8\u76ee\u6807\u662f\u6ee1\u8db3\u4e0b\u5217\u4e09\u4e2a\u6761\u4ef6 \u4e4b\u4e00 \uff1a

    \n\n
      \n\t
    • a \u4e2d\u7684 \u6bcf\u4e2a\u5b57\u6bcd \u5728\u5b57\u6bcd\u8868\u4e2d \u4e25\u683c\u5c0f\u4e8e b \u4e2d\u7684 \u6bcf\u4e2a\u5b57\u6bcd \u3002
    • \n\t
    • b \u4e2d\u7684 \u6bcf\u4e2a\u5b57\u6bcd \u5728\u5b57\u6bcd\u8868\u4e2d \u4e25\u683c\u5c0f\u4e8e a \u4e2d\u7684 \u6bcf\u4e2a\u5b57\u6bcd \u3002
    • \n\t
    • a \u548c b \u90fd \u7531 \u540c\u4e00\u4e2a \u5b57\u6bcd\u7ec4\u6210\u3002
    • \n
    \n\n

    \u8fd4\u56de\u8fbe\u6210\u76ee\u6807\u6240\u9700\u7684 \u6700\u5c11 \u64cd\u4f5c\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aa = \"aba\", b = \"caa\"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6ee1\u8db3\u6bcf\u4e2a\u6761\u4ef6\u7684\u6700\u4f73\u65b9\u6848\u5206\u522b\u662f\uff1a\n1) \u5c06 b \u53d8\u4e3a \"ccc\"\uff0c2 \u6b21\u64cd\u4f5c\uff0c\u6ee1\u8db3 a \u4e2d\u7684\u6bcf\u4e2a\u5b57\u6bcd\u90fd\u5c0f\u4e8e b \u4e2d\u7684\u6bcf\u4e2a\u5b57\u6bcd\uff1b\n2) \u5c06 a \u53d8\u4e3a \"bbb\" \u5e76\u5c06 b \u53d8\u4e3a \"aaa\"\uff0c3 \u6b21\u64cd\u4f5c\uff0c\u6ee1\u8db3 b \u4e2d\u7684\u6bcf\u4e2a\u5b57\u6bcd\u90fd\u5c0f\u4e8e a \u4e2d\u7684\u6bcf\u4e2a\u5b57\u6bcd\uff1b\n3) \u5c06 a \u53d8\u4e3a \"aaa\" \u5e76\u5c06 b \u53d8\u4e3a \"aaa\"\uff0c2 \u6b21\u64cd\u4f5c\uff0c\u6ee1\u8db3 a \u548c b \u7531\u540c\u4e00\u4e2a\u5b57\u6bcd\u7ec4\u6210\u3002\n\u6700\u4f73\u7684\u65b9\u6848\u53ea\u9700\u8981 2 \u6b21\u64cd\u4f5c\uff08\u6ee1\u8db3\u6761\u4ef6 1 \u6216\u8005\u6761\u4ef6 3\uff09\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aa = \"dabadd\", b = \"cda\"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6ee1\u8db3\u6761\u4ef6 1 \u7684\u6700\u4f73\u65b9\u6848\u662f\u5c06 b \u53d8\u4e3a \"eee\" \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= a.length, b.length <= 105
    • \n\t
    • a \u548c b \u53ea\u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n", "tags_en": ["Greedy", "String"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minCharacters(string a, string b) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minCharacters(String a, String b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minCharacters(self, a, b):\n \"\"\"\n :type a: str\n :type b: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minCharacters(self, a: str, b: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minCharacters(char * a, char * b){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinCharacters(string a, string b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} a\n * @param {string} b\n * @return {number}\n */\nvar minCharacters = function(a, b) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} a\n# @param {String} b\n# @return {Integer}\ndef min_characters(a, b)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minCharacters(_ a: String, _ b: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minCharacters(a string, b string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minCharacters(a: String, b: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minCharacters(a: String, b: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_characters(a: String, b: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $a\n * @param String $b\n * @return Integer\n */\n function minCharacters($a, $b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minCharacters(a: string, b: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-characters a b)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1737](https://leetcode-cn.com/problems/change-minimum-characters-to-satisfy-one-of-three-conditions)", "[\u6ee1\u8db3\u4e09\u6761\u4ef6\u4e4b\u4e00\u9700\u6539\u53d8\u7684\u6700\u5c11\u5b57\u7b26\u6570](/solution/1700-1799/1737.Change%20Minimum%20Characters%20to%20Satisfy%20One%20of%20Three%20Conditions/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1737](https://leetcode.com/problems/change-minimum-characters-to-satisfy-one-of-three-conditions)", "[Change Minimum Characters to Satisfy One of Three Conditions](/solution/1700-1799/1737.Change%20Minimum%20Characters%20to%20Satisfy%20One%20of%20Three%20Conditions/README_EN.md)", "`Greedy`,`String`", "Medium", ""]}, {"question_id": "1858", "frontend_question_id": "1736", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/latest-time-by-replacing-hidden-digits", "url_en": "https://leetcode.com/problems/latest-time-by-replacing-hidden-digits", "relative_path_cn": "/solution/1700-1799/1736.Latest%20Time%20by%20Replacing%20Hidden%20Digits/README.md", "relative_path_en": "/solution/1700-1799/1736.Latest%20Time%20by%20Replacing%20Hidden%20Digits/README_EN.md", "title_cn": "\u66ff\u6362\u9690\u85cf\u6570\u5b57\u5f97\u5230\u7684\u6700\u665a\u65f6\u95f4", "title_en": "Latest Time by Replacing Hidden Digits", "question_title_slug": "latest-time-by-replacing-hidden-digits", "content_en": "

    You are given a string time in the form of hh:mm, where some of the digits in the string are hidden (represented by ?).

    \n\n

    The valid times are those inclusively between 00:00 and 23:59.

    \n\n

    Return the latest valid time you can get from time by replacing the hidden digits.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: time = "2?:?0"\nOutput: "23:50"\nExplanation: The latest hour beginning with the digit '2' is 23 and the latest minute ending with the digit '0' is 50.\n
    \n\n

    Example 2:

    \n\n
    \nInput: time = "0?:3?"\nOutput: "09:39"\n
    \n\n

    Example 3:

    \n\n
    \nInput: time = "1?:22"\nOutput: "19:22"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • time is in the format hh:mm.
    • \n\t
    • It is guaranteed that you can produce a valid time from the given string.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 time \uff0c\u683c\u5f0f\u4e3a hh:mm\uff08\u5c0f\u65f6\uff1a\u5206\u949f\uff09\uff0c\u5176\u4e2d\u67d0\u51e0\u4f4d\u6570\u5b57\u88ab\u9690\u85cf\uff08\u7528 ? \u8868\u793a\uff09\u3002

    \n\n

    \u6709\u6548\u7684\u65f6\u95f4\u4e3a 00:00 \u5230 23:59 \u4e4b\u95f4\u7684\u6240\u6709\u65f6\u95f4\uff0c\u5305\u62ec 00:00 \u548c 23:59 \u3002

    \n\n

    \u66ff\u6362\u00a0time \u4e2d\u9690\u85cf\u7684\u6570\u5b57\uff0c\u8fd4\u56de\u4f60\u53ef\u4ee5\u5f97\u5230\u7684\u6700\u665a\u6709\u6548\u65f6\u95f4\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1atime = \"2?:?0\"\n\u8f93\u51fa\uff1a\"23:50\"\n\u89e3\u91ca\uff1a\u4ee5\u6570\u5b57 '2' \u5f00\u5934\u7684\u6700\u665a\u4e00\u5c0f\u65f6\u662f 23 \uff0c\u4ee5 '0' \u7ed3\u5c3e\u7684\u6700\u665a\u4e00\u5206\u949f\u662f 50 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1atime = \"0?:3?\"\n\u8f93\u51fa\uff1a\"09:39\"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1atime = \"1?:22\"\n\u8f93\u51fa\uff1a\"19:22\"\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • time \u7684\u683c\u5f0f\u4e3a hh:mm
    • \n\t
    • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u4f60\u53ef\u4ee5\u7531\u8f93\u5165\u7684\u5b57\u7b26\u4e32\u751f\u6210\u6709\u6548\u7684\u65f6\u95f4
    • \n
    \n", "tags_en": ["Greedy", "String"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string maximumTime(string time) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String maximumTime(String time) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximumTime(self, time):\n \"\"\"\n :type time: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximumTime(self, time: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * maximumTime(char * time){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string MaximumTime(string time) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} time\n * @return {string}\n */\nvar maximumTime = function(time) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} time\n# @return {String}\ndef maximum_time(time)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximumTime(_ time: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximumTime(time string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximumTime(time: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximumTime(time: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximum_time(time: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $time\n * @return String\n */\n function maximumTime($time) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximumTime(time: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximum-time time)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1736](https://leetcode-cn.com/problems/latest-time-by-replacing-hidden-digits)", "[\u66ff\u6362\u9690\u85cf\u6570\u5b57\u5f97\u5230\u7684\u6700\u665a\u65f6\u95f4](/solution/1700-1799/1736.Latest%20Time%20by%20Replacing%20Hidden%20Digits/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1736](https://leetcode.com/problems/latest-time-by-replacing-hidden-digits)", "[Latest Time by Replacing Hidden Digits](/solution/1700-1799/1736.Latest%20Time%20by%20Replacing%20Hidden%20Digits/README_EN.md)", "`Greedy`,`String`", "Easy", ""]}, {"question_id": "1852", "frontend_question_id": "1709", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/biggest-window-between-visits", "url_en": "https://leetcode.com/problems/biggest-window-between-visits", "relative_path_cn": "/solution/1700-1799/1709.Biggest%20Window%20Between%20Visits/README.md", "relative_path_en": "/solution/1700-1799/1709.Biggest%20Window%20Between%20Visits/README_EN.md", "title_cn": "\u8bbf\u95ee\u65e5\u671f\u4e4b\u95f4\u6700\u5927\u7684\u7a7a\u6863\u671f", "title_en": "Biggest Window Between Visits", "question_title_slug": "biggest-window-between-visits", "content_en": "

    Table: UserVisits

    \n\n
    \n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| user_id     | int  |\n| visit_date  | date |\n+-------------+------+\nThis table does not have a primary key.\nThis table contains logs of the dates that users vistied a certain retailer.\n
    \n\n

     

    \n\n

    Assume today's date is '2021-1-1'.

    \n\n

    Write an SQL query that will, for each user_id, find out the largest window of days between each visit and the one right after it (or today if you are considering the last visit).

    \n\n

    Return the result table ordered by user_id.

    \n\n

    The query result format is in the following example:

    \n\n

     

    \n\n
    \nUserVisits table:\n+---------+------------+\n| user_id | visit_date |\n+---------+------------+\n| 1       | 2020-11-28 |\n| 1       | 2020-10-20 |\n| 1       | 2020-12-3  |\n| 2       | 2020-10-5  |\n| 2       | 2020-12-9  |\n| 3       | 2020-11-11 |\n+---------+------------+\nResult table:\n+---------+---------------+\n| user_id | biggest_window|\n+---------+---------------+\n| 1       | 39            |\n| 2       | 65            |\n| 3       | 51            |\n+---------+---------------+\nFor the first user, the windows in question are between dates:\n    - 2020-10-20 and 2020-11-28 with a total of 39 days. \n    - 2020-11-28 and 2020-12-3 with a total of 5 days. \n    - 2020-12-3 and 2021-1-1 with a total of 29 days.\nMaking the biggest window the one with 39 days.\nFor the second user, the windows in question are between dates:\n    - 2020-10-5 and 2020-12-9 with a total of 65 days.\n    - 2020-12-9 and 2021-1-1 with a total of 23 days.\nMaking the biggest window the one with 65 days.\nFor the third user, the only window in question is between dates 2020-11-11 and 2021-1-1 with a total of 51 days.
    \n", "content_cn": "

    \u8868\uff1a\u00a0UserVisits

    \n\n
    +-------------+------+\n| Column Name | Type |\n+-------------+------+\n| user_id     | int  |\n| visit_date  | date |\n+-------------+------+\n\u8be5\u8868\u6ca1\u6709\u4e3b\u952e\u3002\n\u8be5\u8868\u5305\u542b\u7528\u6237\u8bbf\u95ee\u67d0\u7279\u5b9a\u96f6\u552e\u5546\u7684\u65e5\u671f\u65e5\u5fd7\u3002
    \n\n

    \u00a0

    \n\n

    \u5047\u8bbe\u4eca\u5929\u7684\u65e5\u671f\u662f\u00a0'2021-1-1'\u00a0\u3002

    \n\n

    \u7f16\u5199 SQL \u8bed\u53e5\uff0c\u5bf9\u4e8e\u6bcf\u4e2a\u00a0user_id\u00a0\uff0c\u6c42\u51fa\u6bcf\u6b21\u8bbf\u95ee\u53ca\u5176\u4e0b\u4e00\u4e2a\u8bbf\u95ee\uff08\u82e5\u8be5\u6b21\u8bbf\u95ee\u662f\u6700\u540e\u4e00\u6b21\uff0c\u5219\u4e3a\u4eca\u5929\uff09\u4e4b\u95f4\u6700\u5927\u7684\u7a7a\u6863\u671f\u5929\u6570\u00a0window\u00a0\u3002

    \n\n

    \u8fd4\u56de\u7ed3\u679c\u8868\uff0c\u6309\u7528\u6237\u7f16\u53f7\u00a0user_id\u00a0\u6392\u5e8f\u3002

    \n\n

    \u67e5\u8be2\u683c\u5f0f\u5982\u4e0b\u793a\u4f8b\u6240\u793a\uff1a

    \n\n

    \u00a0

    \n\n
    UserVisits \u8868\uff1a\n+---------+------------+\n| user_id | visit_date |\n+---------+------------+\n| 1       | 2020-11-28 |\n| 1       | 2020-10-20 |\n| 1       | 2020-12-3  |\n| 2       | 2020-10-5  |\n| 2       | 2020-12-9  |\n| 3       | 2020-11-11 |\n+---------+------------+\n\u7ed3\u679c\u8868\uff1a\n+---------+---------------+\n| user_id | biggest_window|\n+---------+---------------+\n| 1       | 39            |\n| 2       | 65            |\n| 3       | 51            |\n+---------+---------------+\n\u5bf9\u4e8e\u7b2c\u4e00\u4e2a\u7528\u6237\uff0c\u95ee\u9898\u4e2d\u7684\u7a7a\u6863\u671f\u5728\u4ee5\u4e0b\u65e5\u671f\u4e4b\u95f4\uff1a\n    - 2020-10-20 \u81f3 2020-11-28 \uff0c\u5171\u8ba1 39 \u5929\u3002\n    - 2020-11-28 \u81f3 2020-12-3 \uff0c\u5171\u8ba1 5 \u5929\u3002\n    - 2020-12-3 \u81f3 2021-1-1 \uff0c\u5171\u8ba1 29 \u5929\u3002\n\u7531\u6b64\u5f97\u51fa\uff0c\u6700\u5927\u7684\u7a7a\u6863\u671f\u4e3a 39 \u5929\u3002\n\u5bf9\u4e8e\u7b2c\u4e8c\u4e2a\u7528\u6237\uff0c\u95ee\u9898\u4e2d\u7684\u7a7a\u6863\u671f\u5728\u4ee5\u4e0b\u65e5\u671f\u4e4b\u95f4\uff1a\n    - 2020-10-5 \u81f3 2020-12-9 \uff0c\u5171\u8ba1 65 \u5929\u3002\n    - 2020-12-9 \u81f3 2021-1-1 \uff0c\u5171\u8ba1 23 \u5929\u3002\n\u7531\u6b64\u5f97\u51fa\uff0c\u6700\u5927\u7684\u7a7a\u6863\u671f\u4e3a 65 \u5929\u3002\n\u5bf9\u4e8e\u7b2c\u4e09\u4e2a\u7528\u6237\uff0c\u95ee\u9898\u4e2d\u7684\u552f\u4e00\u7a7a\u6863\u671f\u5728 2020-11-11 \u81f3 2021-1-1 \u4e4b\u95f4\uff0c\u5171\u8ba1 51 \u5929\u3002
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1709](https://leetcode-cn.com/problems/biggest-window-between-visits)", "[\u8bbf\u95ee\u65e5\u671f\u4e4b\u95f4\u6700\u5927\u7684\u7a7a\u6863\u671f](/solution/1700-1799/1709.Biggest%20Window%20Between%20Visits/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1709](https://leetcode.com/problems/biggest-window-between-visits)", "[Biggest Window Between Visits](/solution/1700-1799/1709.Biggest%20Window%20Between%20Visits/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1851", "frontend_question_id": "1751", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-number-of-events-that-can-be-attended-ii", "url_en": "https://leetcode.com/problems/maximum-number-of-events-that-can-be-attended-ii", "relative_path_cn": "/solution/1700-1799/1751.Maximum%20Number%20of%20Events%20That%20Can%20Be%20Attended%20II/README.md", "relative_path_en": "/solution/1700-1799/1751.Maximum%20Number%20of%20Events%20That%20Can%20Be%20Attended%20II/README_EN.md", "title_cn": "\u6700\u591a\u53ef\u4ee5\u53c2\u52a0\u7684\u4f1a\u8bae\u6570\u76ee II", "title_en": "Maximum Number of Events That Can Be Attended II", "question_title_slug": "maximum-number-of-events-that-can-be-attended-ii", "content_en": "

    You are given an array of events where events[i] = [startDayi, endDayi, valuei]. The ith event starts at startDayi and ends at endDayi, and if you attend this event, you will receive a value of valuei. You are also given an integer k which represents the maximum number of events you can attend.

    \n\n

    You can only attend one event at a time. If you choose to attend an event, you must attend the entire event. Note that the end day is inclusive: that is, you cannot attend two events where one of them starts and the other ends on the same day.

    \n\n

    Return the maximum sum of values that you can receive by attending events.

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: events = [[1,2,4],[3,4,3],[2,3,1]], k = 2\nOutput: 7\nExplanation: Choose the green events, 0 and 1 (0-indexed) for a total value of 4 + 3 = 7.
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: events = [[1,2,4],[3,4,3],[2,3,10]], k = 2\nOutput: 10\nExplanation: Choose event 2 for a total value of 10.\nNotice that you cannot attend any other event as they overlap, and that you do not have to attend k events.
    \n\n

    Example 3:

    \n\n

    \"\"

    \n\n
    \nInput: events = [[1,1,1],[2,2,2],[3,3,3],[4,4,4]], k = 3\nOutput: 9\nExplanation: Although the events do not overlap, you can only attend 3 events. Pick the highest valued three.
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= k <= events.length
    • \n\t
    • 1 <= k * events.length <= 106
    • \n\t
    • 1 <= startDayi <= endDayi <= 109
    • \n\t
    • 1 <= valuei <= 106
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u00a0events\u00a0\u6570\u7ec4\uff0c\u5176\u4e2d\u00a0events[i] = [startDayi, endDayi, valuei]\u00a0\uff0c\u8868\u793a\u7b2c\u00a0i\u00a0\u4e2a\u4f1a\u8bae\u5728\u00a0startDayi\u00a0\u5929\u5f00\u59cb\uff0c\u7b2c\u00a0endDayi\u00a0\u5929\u7ed3\u675f\uff0c\u5982\u679c\u4f60\u53c2\u52a0\u8fd9\u4e2a\u4f1a\u8bae\uff0c\u4f60\u80fd\u5f97\u5230\u4ef7\u503c\u00a0valuei\u00a0\u3002\u540c\u65f6\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u00a0k\u00a0\u8868\u793a\u4f60\u80fd\u53c2\u52a0\u7684\u6700\u591a\u4f1a\u8bae\u6570\u76ee\u3002

    \n\n

    \u4f60\u540c\u4e00\u65f6\u95f4\u53ea\u80fd\u53c2\u52a0\u4e00\u4e2a\u4f1a\u8bae\u3002\u5982\u679c\u4f60\u9009\u62e9\u53c2\u52a0\u67d0\u4e2a\u4f1a\u8bae\uff0c\u90a3\u4e48\u4f60\u5fc5\u987b \u5b8c\u6574\u00a0\u5730\u53c2\u52a0\u5b8c\u8fd9\u4e2a\u4f1a\u8bae\u3002\u4f1a\u8bae\u7ed3\u675f\u65e5\u671f\u662f\u5305\u542b\u5728\u4f1a\u8bae\u5185\u7684\uff0c\u4e5f\u5c31\u662f\u8bf4\u4f60\u4e0d\u80fd\u540c\u65f6\u53c2\u52a0\u4e00\u4e2a\u5f00\u59cb\u65e5\u671f\u4e0e\u53e6\u4e00\u4e2a\u7ed3\u675f\u65e5\u671f\u76f8\u540c\u7684\u4e24\u4e2a\u4f1a\u8bae\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u80fd\u5f97\u5230\u7684\u4f1a\u8bae\u4ef7\u503c\u00a0\u6700\u5927\u548c\u00a0\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aevents = [[1,2,4],[3,4,3],[2,3,1]], k = 2\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\u9009\u62e9\u7eff\u8272\u7684\u6d3b\u52a8\u4f1a\u8bae 0 \u548c 1\uff0c\u5f97\u5230\u603b\u4ef7\u503c\u548c\u4e3a 4 + 3 = 7 \u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aevents = [[1,2,4],[3,4,3],[2,3,10]], k = 2\n\u8f93\u51fa\uff1a10\n\u89e3\u91ca\uff1a\u53c2\u52a0\u4f1a\u8bae 2 \uff0c\u5f97\u5230\u4ef7\u503c\u548c\u4e3a 10 \u3002\n\u4f60\u6ca1\u6cd5\u518d\u53c2\u52a0\u522b\u7684\u4f1a\u8bae\u4e86\uff0c\u56e0\u4e3a\u8ddf\u4f1a\u8bae 2 \u6709\u91cd\u53e0\u3002\u4f60 \u4e0d\u00a0\u9700\u8981\u53c2\u52a0\u6ee1 k \u4e2a\u4f1a\u8bae\u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aevents = [[1,1,1],[2,2,2],[3,3,3],[4,4,4]], k = 3\n\u8f93\u51fa\uff1a9\n\u89e3\u91ca\uff1a\u5c3d\u7ba1\u4f1a\u8bae\u4e92\u4e0d\u91cd\u53e0\uff0c\u4f60\u53ea\u80fd\u53c2\u52a0 3 \u4e2a\u4f1a\u8bae\uff0c\u6240\u4ee5\u9009\u62e9\u4ef7\u503c\u6700\u5927\u7684 3 \u4e2a\u4f1a\u8bae\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= k <= events.length
    • \n\t
    • 1 <= k * events.length <= 106
    • \n\t
    • 1 <= startDayi <= endDayi <= 109
    • \n\t
    • 1 <= valuei <= 106
    • \n
    \n", "tags_en": ["Binary Search", "Dynamic Programming"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxValue(vector>& events, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxValue(int[][] events, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxValue(self, events, k):\n \"\"\"\n :type events: List[List[int]]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxValue(self, events: List[List[int]], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxValue(int** events, int eventsSize, int* eventsColSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxValue(int[][] events, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} events\n * @param {number} k\n * @return {number}\n */\nvar maxValue = function(events, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} events\n# @param {Integer} k\n# @return {Integer}\ndef max_value(events, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxValue(_ events: [[Int]], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxValue(events [][]int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxValue(events: Array[Array[Int]], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxValue(events: Array, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_value(events: Vec>, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $events\n * @param Integer $k\n * @return Integer\n */\n function maxValue($events, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxValue(events: number[][], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-value events k)\n (-> (listof (listof exact-integer?)) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1751](https://leetcode-cn.com/problems/maximum-number-of-events-that-can-be-attended-ii)", "[\u6700\u591a\u53ef\u4ee5\u53c2\u52a0\u7684\u4f1a\u8bae\u6570\u76ee II](/solution/1700-1799/1751.Maximum%20Number%20of%20Events%20That%20Can%20Be%20Attended%20II/README.md)", "`\u4e8c\u5206\u67e5\u627e`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1751](https://leetcode.com/problems/maximum-number-of-events-that-can-be-attended-ii)", "[Maximum Number of Events That Can Be Attended II](/solution/1700-1799/1751.Maximum%20Number%20of%20Events%20That%20Can%20Be%20Attended%20II/README_EN.md)", "`Binary Search`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "1850", "frontend_question_id": "1750", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-length-of-string-after-deleting-similar-ends", "url_en": "https://leetcode.com/problems/minimum-length-of-string-after-deleting-similar-ends", "relative_path_cn": "/solution/1700-1799/1750.Minimum%20Length%20of%20String%20After%20Deleting%20Similar%20Ends/README.md", "relative_path_en": "/solution/1700-1799/1750.Minimum%20Length%20of%20String%20After%20Deleting%20Similar%20Ends/README_EN.md", "title_cn": "\u5220\u9664\u5b57\u7b26\u4e32\u4e24\u7aef\u76f8\u540c\u5b57\u7b26\u540e\u7684\u6700\u77ed\u957f\u5ea6", "title_en": "Minimum Length of String After Deleting Similar Ends", "question_title_slug": "minimum-length-of-string-after-deleting-similar-ends", "content_en": "

    Given a string s consisting only of characters 'a', 'b', and 'c'. You are asked to apply the following algorithm on the string any number of times:

    \n\n
      \n\t
    1. Pick a non-empty prefix from the string s where all the characters in the prefix are equal.
    2. \n\t
    3. Pick a non-empty suffix from the string s where all the characters in this suffix are equal.
    4. \n\t
    5. The prefix and the suffix should not intersect at any index.
    6. \n\t
    7. The characters from the prefix and suffix must be the same.
    8. \n\t
    9. Delete both the prefix and the suffix.
    10. \n
    \n\n

    Return the minimum length of s after performing the above operation any number of times (possibly zero times).

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "ca"\nOutput: 2\nExplanation: You can't remove any characters, so the string stays as is.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "cabaabac"\nOutput: 0\nExplanation: An optimal sequence of operations is:\n- Take prefix = "c" and suffix = "c" and remove them, s = "abaaba".\n- Take prefix = "a" and suffix = "a" and remove them, s = "baab".\n- Take prefix = "b" and suffix = "b" and remove them, s = "aa".\n- Take prefix = "a" and suffix = "a" and remove them, s = "".
    \n\n

    Example 3:

    \n\n
    \nInput: s = "aabccabba"\nOutput: 3\nExplanation: An optimal sequence of operations is:\n- Take prefix = "aa" and suffix = "a" and remove them, s = "bccabb".\n- Take prefix = "b" and suffix = "bb" and remove them, s = "cca".\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 105
    • \n\t
    • s only consists of characters 'a', 'b', and 'c'.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u53ea\u5305\u542b\u5b57\u7b26 'a'\uff0c'b'\u00a0\u548c 'c'\u00a0\u7684\u5b57\u7b26\u4e32\u00a0s\u00a0\uff0c\u4f60\u53ef\u4ee5\u6267\u884c\u4e0b\u9762\u8fd9\u4e2a\u64cd\u4f5c\uff085 \u4e2a\u6b65\u9aa4\uff09\u4efb\u610f\u6b21\uff1a

    \n\n
      \n\t
    1. \u9009\u62e9\u5b57\u7b26\u4e32 s\u00a0\u4e00\u4e2a \u975e\u7a7a \u7684\u524d\u7f00\uff0c\u8fd9\u4e2a\u524d\u7f00\u7684\u6240\u6709\u5b57\u7b26\u90fd\u76f8\u540c\u3002
    2. \n\t
    3. \u9009\u62e9\u5b57\u7b26\u4e32 s\u00a0\u4e00\u4e2a \u975e\u7a7a \u7684\u540e\u7f00\uff0c\u8fd9\u4e2a\u540e\u7f00\u7684\u6240\u6709\u5b57\u7b26\u90fd\u76f8\u540c\u3002
    4. \n\t
    5. \u524d\u7f00\u548c\u540e\u7f00\u5728\u5b57\u7b26\u4e32\u4e2d\u4efb\u610f\u4f4d\u7f6e\u90fd\u4e0d\u80fd\u6709\u4ea4\u96c6\u3002
    6. \n\t
    7. \u524d\u7f00\u548c\u540e\u7f00\u5305\u542b\u7684\u6240\u6709\u5b57\u7b26\u90fd\u8981\u76f8\u540c\u3002
    8. \n\t
    9. \u540c\u65f6\u5220\u9664\u524d\u7f00\u548c\u540e\u7f00\u3002
    10. \n
    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u5bf9\u5b57\u7b26\u4e32 s\u00a0\u6267\u884c\u4e0a\u9762\u64cd\u4f5c\u4efb\u610f\u6b21\u4ee5\u540e\uff08\u53ef\u80fd 0 \u6b21\uff09\uff0c\u80fd\u5f97\u5230\u7684 \u6700\u77ed\u957f\u5ea6\u00a0\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"ca\"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u4f60\u6ca1\u6cd5\u5220\u9664\u4efb\u4f55\u4e00\u4e2a\u5b57\u7b26\uff0c\u6240\u4ee5\u5b57\u7b26\u4e32\u957f\u5ea6\u4ecd\u7136\u4fdd\u6301\u4e0d\u53d8\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"cabaabac\"\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6700\u4f18\u64cd\u4f5c\u5e8f\u5217\u4e3a\uff1a\n- \u9009\u62e9\u524d\u7f00 \"c\" \u548c\u540e\u7f00 \"c\" \u5e76\u5220\u9664\u5b83\u4eec\uff0c\u5f97\u5230 s = \"abaaba\" \u3002\n- \u9009\u62e9\u524d\u7f00 \"a\" \u548c\u540e\u7f00 \"a\" \u5e76\u5220\u9664\u5b83\u4eec\uff0c\u5f97\u5230 s = \"baab\" \u3002\n- \u9009\u62e9\u524d\u7f00 \"b\" \u548c\u540e\u7f00 \"b\" \u5e76\u5220\u9664\u5b83\u4eec\uff0c\u5f97\u5230 s = \"aa\" \u3002\n- \u9009\u62e9\u524d\u7f00 \"a\" \u548c\u540e\u7f00 \"a\" \u5e76\u5220\u9664\u5b83\u4eec\uff0c\u5f97\u5230 s = \"\" \u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"aabccabba\"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6700\u4f18\u64cd\u4f5c\u5e8f\u5217\u4e3a\uff1a\n- \u9009\u62e9\u524d\u7f00 \"aa\" \u548c\u540e\u7f00 \"a\" \u5e76\u5220\u9664\u5b83\u4eec\uff0c\u5f97\u5230 s = \"bccabb\" \u3002\n- \u9009\u62e9\u524d\u7f00 \"b\" \u548c\u540e\u7f00 \"bb\" \u5e76\u5220\u9664\u5b83\u4eec\uff0c\u5f97\u5230 s = \"cca\" \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 105
    • \n\t
    • s\u00a0\u53ea\u5305\u542b\u5b57\u7b26\u00a0'a'\uff0c'b'\u00a0\u548c\u00a0'c'\u00a0\u3002
    • \n
    \n", "tags_en": ["Two Pointers"], "tags_cn": ["\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minimumLength(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minimumLength(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimumLength(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimumLength(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minimumLength(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinimumLength(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar minimumLength = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef minimum_length(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimumLength(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimumLength(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimumLength(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimumLength(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimum_length(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function minimumLength($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimumLength(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimum-length s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1750](https://leetcode-cn.com/problems/minimum-length-of-string-after-deleting-similar-ends)", "[\u5220\u9664\u5b57\u7b26\u4e32\u4e24\u7aef\u76f8\u540c\u5b57\u7b26\u540e\u7684\u6700\u77ed\u957f\u5ea6](/solution/1700-1799/1750.Minimum%20Length%20of%20String%20After%20Deleting%20Similar%20Ends/README.md)", "`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1750](https://leetcode.com/problems/minimum-length-of-string-after-deleting-similar-ends)", "[Minimum Length of String After Deleting Similar Ends](/solution/1700-1799/1750.Minimum%20Length%20of%20String%20After%20Deleting%20Similar%20Ends/README_EN.md)", "`Two Pointers`", "Medium", ""]}, {"question_id": "1849", "frontend_question_id": "1749", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-absolute-sum-of-any-subarray", "url_en": "https://leetcode.com/problems/maximum-absolute-sum-of-any-subarray", "relative_path_cn": "/solution/1700-1799/1749.Maximum%20Absolute%20Sum%20of%20Any%20Subarray/README.md", "relative_path_en": "/solution/1700-1799/1749.Maximum%20Absolute%20Sum%20of%20Any%20Subarray/README_EN.md", "title_cn": "\u4efb\u610f\u5b50\u6570\u7ec4\u548c\u7684\u7edd\u5bf9\u503c\u7684\u6700\u5927\u503c", "title_en": "Maximum Absolute Sum of Any Subarray", "question_title_slug": "maximum-absolute-sum-of-any-subarray", "content_en": "

    You are given an integer array nums. The absolute sum of a subarray [numsl, numsl+1, ..., numsr-1, numsr] is abs(numsl + numsl+1 + ... + numsr-1 + numsr).

    \n\n

    Return the maximum absolute sum of any (possibly empty) subarray of nums.

    \n\n

    Note that abs(x) is defined as follows:

    \n\n
      \n\t
    • If x is a negative integer, then abs(x) = -x.
    • \n\t
    • If x is a non-negative integer, then abs(x) = x.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,-3,2,3,-4]\nOutput: 5\nExplanation: The subarray [2,3] has absolute sum = abs(2+3) = abs(5) = 5.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [2,-5,1,-4,3,-2]\nOutput: 8\nExplanation: The subarray [-5,1,-4] has absolute sum = abs(-5+1-4) = abs(-8) = 8.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • -104 <= nums[i] <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0nums\u00a0\u3002\u4e00\u4e2a\u5b50\u6570\u7ec4\u00a0[numsl, numsl+1, ..., numsr-1, numsr]\u00a0\u7684 \u548c\u7684\u7edd\u5bf9\u503c\u00a0\u4e3a\u00a0abs(numsl + numsl+1 + ... + numsr-1 + numsr)\u00a0\u3002

    \n\n

    \u8bf7\u4f60\u627e\u51fa nums\u00a0\u4e2d \u548c\u7684\u7edd\u5bf9\u503c \u6700\u5927\u7684\u4efb\u610f\u5b50\u6570\u7ec4\uff08\u53ef\u80fd\u4e3a\u7a7a\uff09\uff0c\u5e76\u8fd4\u56de\u8be5 \u6700\u5927\u503c\u00a0\u3002

    \n\n

    abs(x)\u00a0\u5b9a\u4e49\u5982\u4e0b\uff1a

    \n\n
      \n\t
    • \u5982\u679c\u00a0x\u00a0\u662f\u8d1f\u6574\u6570\uff0c\u90a3\u4e48\u00a0abs(x) = -x\u00a0\u3002
    • \n\t
    • \u5982\u679c\u00a0x\u00a0\u662f\u975e\u8d1f\u6574\u6570\uff0c\u90a3\u4e48\u00a0abs(x) = x\u00a0\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,-3,2,3,-4]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u5b50\u6570\u7ec4 [2,3] \u548c\u7684\u7edd\u5bf9\u503c\u6700\u5927\uff0c\u4e3a abs(2+3) = abs(5) = 5 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [2,-5,1,-4,3,-2]\n\u8f93\u51fa\uff1a8\n\u89e3\u91ca\uff1a\u5b50\u6570\u7ec4 [-5,1,-4] \u548c\u7684\u7edd\u5bf9\u503c\u6700\u5927\uff0c\u4e3a abs(-5+1-4) = abs(-8) = 8 \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • -104 <= nums[i] <= 104
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxAbsoluteSum(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxAbsoluteSum(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxAbsoluteSum(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxAbsoluteSum(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxAbsoluteSum(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxAbsoluteSum(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar maxAbsoluteSum = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef max_absolute_sum(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxAbsoluteSum(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxAbsoluteSum(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxAbsoluteSum(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxAbsoluteSum(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_absolute_sum(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function maxAbsoluteSum($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxAbsoluteSum(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-absolute-sum nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1749](https://leetcode-cn.com/problems/maximum-absolute-sum-of-any-subarray)", "[\u4efb\u610f\u5b50\u6570\u7ec4\u548c\u7684\u7edd\u5bf9\u503c\u7684\u6700\u5927\u503c](/solution/1700-1799/1749.Maximum%20Absolute%20Sum%20of%20Any%20Subarray/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1749](https://leetcode.com/problems/maximum-absolute-sum-of-any-subarray)", "[Maximum Absolute Sum of Any Subarray](/solution/1700-1799/1749.Maximum%20Absolute%20Sum%20of%20Any%20Subarray/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1848", "frontend_question_id": "1748", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sum-of-unique-elements", "url_en": "https://leetcode.com/problems/sum-of-unique-elements", "relative_path_cn": "/solution/1700-1799/1748.Sum%20of%20Unique%20Elements/README.md", "relative_path_en": "/solution/1700-1799/1748.Sum%20of%20Unique%20Elements/README_EN.md", "title_cn": "\u552f\u4e00\u5143\u7d20\u7684\u548c", "title_en": "Sum of Unique Elements", "question_title_slug": "sum-of-unique-elements", "content_en": "

    You are given an integer array nums. The unique elements of an array are the elements that appear exactly once in the array.

    \n\n

    Return the sum of all the unique elements of nums.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,3,2]\nOutput: 4\nExplanation: The unique elements are [1,3], and the sum is 4.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,1,1,1,1]\nOutput: 0\nExplanation: There are no unique elements, and the sum is 0.\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [1,2,3,4,5]\nOutput: 15\nExplanation: The unique elements are [1,2,3,4,5], and the sum is 15.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 100
    • \n\t
    • 1 <= nums[i] <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0nums\u00a0\u3002\u6570\u7ec4\u4e2d\u552f\u4e00\u5143\u7d20\u662f\u90a3\u4e9b\u53ea\u51fa\u73b0\u00a0\u6070\u597d\u4e00\u6b21\u00a0\u7684\u5143\u7d20\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de nums\u00a0\u4e2d\u552f\u4e00\u5143\u7d20\u7684 \u548c\u00a0\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,2,3,2]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u552f\u4e00\u5143\u7d20\u4e3a [1,3] \uff0c\u548c\u4e3a 4 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,1,1,1,1]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6ca1\u6709\u552f\u4e00\u5143\u7d20\uff0c\u548c\u4e3a 0 \u3002\n
    \n\n

    \u793a\u4f8b 3 \uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,2,3,4,5]\n\u8f93\u51fa\uff1a15\n\u89e3\u91ca\uff1a\u552f\u4e00\u5143\u7d20\u4e3a [1,2,3,4,5] \uff0c\u548c\u4e3a 15 \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 100
    • \n\t
    • 1 <= nums[i] <= 100
    • \n
    \n", "tags_en": ["Array", "Hash Table"], "tags_cn": ["\u6570\u7ec4", "\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int sumOfUnique(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int sumOfUnique(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def sumOfUnique(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def sumOfUnique(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint sumOfUnique(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SumOfUnique(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar sumOfUnique = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef sum_of_unique(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func sumOfUnique(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func sumOfUnique(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def sumOfUnique(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun sumOfUnique(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sum_of_unique(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function sumOfUnique($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function sumOfUnique(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (sum-of-unique nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1748](https://leetcode-cn.com/problems/sum-of-unique-elements)", "[\u552f\u4e00\u5143\u7d20\u7684\u548c](/solution/1700-1799/1748.Sum%20of%20Unique%20Elements/README.md)", "`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[1748](https://leetcode.com/problems/sum-of-unique-elements)", "[Sum of Unique Elements](/solution/1700-1799/1748.Sum%20of%20Unique%20Elements/README_EN.md)", "`Array`,`Hash Table`", "Easy", ""]}, {"question_id": "1847", "frontend_question_id": "1708", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/largest-subarray-length-k", "url_en": "https://leetcode.com/problems/largest-subarray-length-k", "relative_path_cn": "/solution/1700-1799/1708.Largest%20Subarray%20Length%20K/README.md", "relative_path_en": "/solution/1700-1799/1708.Largest%20Subarray%20Length%20K/README_EN.md", "title_cn": "\u957f\u5ea6\u4e3a K \u7684\u6700\u5927\u5b50\u6570\u7ec4", "title_en": "Largest Subarray Length K", "question_title_slug": "largest-subarray-length-k", "content_en": "

    An array A is larger than some array B if for the first index i where A[i] != B[i], A[i] > B[i].

    \n\n

    For example, consider 0-indexing:

    \n\n
      \n\t
    • [1,3,2,4] > [1,2,2,4], since at index 1, 3 > 2.
    • \n\t
    • [1,4,4,4] < [2,1,1,1], since at index 0, 1 < 2.
    • \n
    \n\n

    A subarray is a contiguous subsequence of the array.

    \n\n

    Given an integer array nums of distinct integers, return the largest subarray of nums of length k.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,4,5,2,3], k = 3\nOutput: [5,2,3]\nExplanation: The subarrays of size 3 are: [1,4,5], [4,5,2], and [5,2,3].\nOf these, [5,2,3] is the largest.
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,4,5,2,3], k = 4\nOutput: [4,5,2,3]\nExplanation: The subarrays of size 4 are: [1,4,5,2], and [4,5,2,3].\nOf these, [4,5,2,3] is the largest.
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [1,4,5,2,3], k = 1\nOutput: [5]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= k <= nums.length <= 105
    • \n\t
    • 1 <= nums[i] <= 109
    • \n\t
    • All the integers of nums are unique.
    • \n
    \n\n

     

    \nFollow up: What if the integers in nums are not distinct?", "content_cn": "

    \u5728\u6570\u7ec4\u00a0A\u00a0\u548c\u6570\u7ec4 B\u00a0\u4e2d\uff0c\u5bf9\u4e8e\u7b2c\u4e00\u4e2a\u6ee1\u8db3 A[i] != B[i]\u00a0\u7684\u7d22\u5f15\u00a0i\u00a0\uff0c\u5f53 A[i] > B[i]\u00a0\u65f6\uff0c\u6570\u7ec4 A \u5927\u4e8e\u6570\u7ec4 B\u3002

    \n\n

    \u4f8b\u5982\uff0c\u5bf9\u4e8e\u7d22\u5f15\u4ece 0 \u5f00\u59cb\u7684\u6570\u7ec4\uff1a

    \n\n
      \n\t
    • [1,3,2,4] > [1,2,2,4]\u00a0\uff0c\u56e0\u4e3a\u5728\u7d22\u5f15\u00a01\u00a0\u4e0a\uff0c\u00a03 > 2\u3002
    • \n\t
    • [1,4,4,4] < [2,1,1,1]\u00a0\uff0c\u56e0\u4e3a\u5728\u7d22\u5f15 0 \u4e0a\uff0c\u00a01 < 2\u3002
    • \n
    \n\n

    \u4e00\u4e2a\u6570\u7ec4\u7684\u5b50\u6570\u7ec4\u662f\u539f\u6570\u7ec4\u4e0a\u7684\u4e00\u4e2a\u8fde\u7eed\u5b50\u5e8f\u5217\u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u5305\u542b\u4e0d\u540c\u6574\u6570\u7684\u6574\u6570\u7c7b\u578b\u6570\u7ec4\u00a0nums\u00a0\uff0c\u8fd4\u56de\u00a0nums\u00a0\u4e2d\u957f\u5ea6\u4e3a k \u7684\u6700\u5927\u5b50\u6570\u7ec4\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: nums = [1,4,5,2,3], k = 3\n\u8f93\u51fa: [5,2,3]\n\u89e3\u91ca: \u957f\u5ea6\u4e3a 3 \u7684\u5b50\u6570\u7ec4\u6709\uff1a [1,4,5]\u3001 [4,5,2] \u548c [5,2,3]\u3002\n\u5728\u8fd9\u4e9b\u6570\u7ec4\u4e2d\uff0c [5,2,3] \u662f\u6700\u5927\u7684\u3002
    \n\n

    Example 2:

    \n\n
    \u8f93\u5165: nums = [1,4,5,2,3], k = 4\n\u8f93\u51fa: [4,5,2,3]\n\u89e3\u91ca: \u957f\u5ea6\u4e3a 4 \u7684\u5b50\u6570\u7ec4\u6709\uff1a [1,4,5,2] \u548c [4,5,2,3]\u3002\n\u5728\u8fd9\u4e9b\u6570\u7ec4\u4e2d\uff0c [4,5,2,3] \u662f\u6700\u5927\u7684\u3002
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u8f93\u5165: nums = [1,4,5,2,3], k = 1\n\u8f93\u51fa: [5]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= k <= nums.length <= 105
    • \n\t
    • 1 <= nums[i] <= 109
    • \n\t
    • nums\u00a0\u4e2d\u7684\u6240\u6709\u6574\u6570\u90fd\u662f\u4e0d\u540c\u7684\u3002
    • \n
    \n\n

    \u00a0

    \n\u8fdb\u9636\uff1a\u5982\u679c\u5141\u8bb8\u00a0nums\u00a0\u4e2d\u5b58\u5728\u76f8\u540c\u5143\u7d20\uff0c\u4f60\u8be5\u5982\u4f55\u89e3\u51b3\u8be5\u95ee\u9898\uff1f", "tags_en": ["Greedy", "Array"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector largestSubarray(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] largestSubarray(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def largestSubarray(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def largestSubarray(self, nums: List[int], k: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* largestSubarray(int* nums, int numsSize, int k, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] LargestSubarray(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number[]}\n */\nvar largestSubarray = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer[]}\ndef largest_subarray(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func largestSubarray(_ nums: [Int], _ k: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func largestSubarray(nums []int, k int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def largestSubarray(nums: Array[Int], k: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun largestSubarray(nums: IntArray, k: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn largest_subarray(nums: Vec, k: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer[]\n */\n function largestSubarray($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function largestSubarray(nums: number[], k: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (largest-subarray nums k)\n (-> (listof exact-integer?) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1708](https://leetcode-cn.com/problems/largest-subarray-length-k)", "[\u957f\u5ea6\u4e3a K \u7684\u6700\u5927\u5b50\u6570\u7ec4](/solution/1700-1799/1708.Largest%20Subarray%20Length%20K/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u7ec4`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1708](https://leetcode.com/problems/largest-subarray-length-k)", "[Largest Subarray Length K](/solution/1700-1799/1708.Largest%20Subarray%20Length%20K/README_EN.md)", "`Greedy`,`Array`", "Easy", "\ud83d\udd12"]}, {"question_id": "1845", "frontend_question_id": "1727", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/largest-submatrix-with-rearrangements", "url_en": "https://leetcode.com/problems/largest-submatrix-with-rearrangements", "relative_path_cn": "/solution/1700-1799/1727.Largest%20Submatrix%20With%20Rearrangements/README.md", "relative_path_en": "/solution/1700-1799/1727.Largest%20Submatrix%20With%20Rearrangements/README_EN.md", "title_cn": "\u91cd\u65b0\u6392\u5217\u540e\u7684\u6700\u5927\u5b50\u77e9\u9635", "title_en": "Largest Submatrix With Rearrangements", "question_title_slug": "largest-submatrix-with-rearrangements", "content_en": "

    You are given a binary matrix matrix of size m x n, and you are allowed to rearrange the columns of the matrix in any order.

    \n\n

    Return the area of the largest submatrix within matrix where every element of the submatrix is 1 after reordering the columns optimally.

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: matrix = [[0,0,1],[1,1,1],[1,0,1]]\nOutput: 4\nExplanation: You can rearrange the columns as shown above.\nThe largest submatrix of 1s, in bold, has an area of 4.\n
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: matrix = [[1,0,1,0,1]]\nOutput: 3\nExplanation: You can rearrange the columns as shown above.\nThe largest submatrix of 1s, in bold, has an area of 3.\n
    \n\n

    Example 3:

    \n\n
    \nInput: matrix = [[1,1,0],[1,0,1]]\nOutput: 2\nExplanation: Notice that you must rearrange entire columns, and there is no way to make a submatrix of 1s larger than an area of 2.
    \n\n

    Example 4:

    \n\n
    \nInput: matrix = [[0,0],[0,0]]\nOutput: 0\nExplanation: As there are no 1s, no submatrix of 1s can be formed and the area is 0.
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == matrix.length
    • \n\t
    • n == matrix[i].length
    • \n\t
    • 1 <= m * n <= 105
    • \n\t
    • matrix[i][j] is 0 or 1.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u4e8c\u8fdb\u5236\u77e9\u9635\u00a0matrix\u00a0\uff0c\u5b83\u7684\u5927\u5c0f\u4e3a\u00a0m x n\u00a0\uff0c\u4f60\u53ef\u4ee5\u5c06 matrix\u00a0\u4e2d\u7684 \u5217\u00a0\u6309\u4efb\u610f\u987a\u5e8f\u91cd\u65b0\u6392\u5217\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u6700\u4f18\u65b9\u6848\u4e0b\u5c06 matrix\u00a0\u91cd\u65b0\u6392\u5217\u540e\uff0c\u5168\u662f 1\u00a0\u7684\u5b50\u77e9\u9635\u9762\u79ef\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1amatrix = [[0,0,1],[1,1,1],[1,0,1]]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u6309\u7167\u4e0a\u56fe\u65b9\u5f0f\u91cd\u65b0\u6392\u5217\u77e9\u9635\u7684\u6bcf\u4e00\u5217\u3002\n\u6700\u5927\u7684\u5168 1 \u5b50\u77e9\u9635\u662f\u4e0a\u56fe\u4e2d\u52a0\u7c97\u7684\u90e8\u5206\uff0c\u9762\u79ef\u4e3a 4 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1amatrix = [[1,0,1,0,1]]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u6309\u7167\u4e0a\u56fe\u65b9\u5f0f\u91cd\u65b0\u6392\u5217\u77e9\u9635\u7684\u6bcf\u4e00\u5217\u3002\n\u6700\u5927\u7684\u5168 1 \u5b50\u77e9\u9635\u662f\u4e0a\u56fe\u4e2d\u52a0\u7c97\u7684\u90e8\u5206\uff0c\u9762\u79ef\u4e3a 3 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1amatrix = [[1,1,0],[1,0,1]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u7531\u4e8e\u4f60\u53ea\u80fd\u6574\u5217\u6574\u5217\u91cd\u65b0\u6392\u5e03\uff0c\u6240\u4ee5\u6ca1\u6709\u6bd4\u9762\u79ef\u4e3a 2 \u66f4\u5927\u7684\u5168 1 \u5b50\u77e9\u5f62\u3002
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1amatrix = [[0,0],[0,0]]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u7531\u4e8e\u77e9\u9635\u4e2d\u6ca1\u6709 1 \uff0c\u6ca1\u6709\u4efb\u4f55\u5168 1 \u7684\u5b50\u77e9\u9635\uff0c\u6240\u4ee5\u9762\u79ef\u4e3a 0 \u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == matrix.length
    • \n\t
    • n == matrix[i].length
    • \n\t
    • 1 <= m * n <= 105
    • \n\t
    • matrix[i][j]\u00a0\u8981\u4e48\u662f\u00a00\u00a0\uff0c\u8981\u4e48\u662f\u00a01 \u3002
    • \n
    \n", "tags_en": ["Greedy", "Sort"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6392\u5e8f"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int largestSubmatrix(vector>& matrix) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int largestSubmatrix(int[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def largestSubmatrix(self, matrix):\n \"\"\"\n :type matrix: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def largestSubmatrix(self, matrix: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint largestSubmatrix(int** matrix, int matrixSize, int* matrixColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LargestSubmatrix(int[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} matrix\n * @return {number}\n */\nvar largestSubmatrix = function(matrix) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} matrix\n# @return {Integer}\ndef largest_submatrix(matrix)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func largestSubmatrix(_ matrix: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func largestSubmatrix(matrix [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def largestSubmatrix(matrix: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun largestSubmatrix(matrix: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn largest_submatrix(matrix: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $matrix\n * @return Integer\n */\n function largestSubmatrix($matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function largestSubmatrix(matrix: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (largest-submatrix matrix)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1727](https://leetcode-cn.com/problems/largest-submatrix-with-rearrangements)", "[\u91cd\u65b0\u6392\u5217\u540e\u7684\u6700\u5927\u5b50\u77e9\u9635](/solution/1700-1799/1727.Largest%20Submatrix%20With%20Rearrangements/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6392\u5e8f`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1727](https://leetcode.com/problems/largest-submatrix-with-rearrangements)", "[Largest Submatrix With Rearrangements](/solution/1700-1799/1727.Largest%20Submatrix%20With%20Rearrangements/README_EN.md)", "`Greedy`,`Sort`", "Medium", ""]}, {"question_id": "1844", "frontend_question_id": "1742", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-number-of-balls-in-a-box", "url_en": "https://leetcode.com/problems/maximum-number-of-balls-in-a-box", "relative_path_cn": "/solution/1700-1799/1742.Maximum%20Number%20of%20Balls%20in%20a%20Box/README.md", "relative_path_en": "/solution/1700-1799/1742.Maximum%20Number%20of%20Balls%20in%20a%20Box/README_EN.md", "title_cn": "\u76d2\u5b50\u4e2d\u5c0f\u7403\u7684\u6700\u5927\u6570\u91cf", "title_en": "Maximum Number of Balls in a Box", "question_title_slug": "maximum-number-of-balls-in-a-box", "content_en": "

    You are working in a ball factory where you have n balls numbered from lowLimit up to highLimit inclusive (i.e., n == highLimit - lowLimit + 1), and an infinite number of boxes numbered from 1 to infinity.

    \n\n

    Your job at this factory is to put each ball in the box with a number equal to the sum of digits of the ball's number. For example, the ball number 321 will be put in the box number 3 + 2 + 1 = 6 and the ball number 10 will be put in the box number 1 + 0 = 1.

    \n\n

    Given two integers lowLimit and highLimit, return the number of balls in the box with the most balls.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: lowLimit = 1, highLimit = 10\nOutput: 2\nExplanation:\nBox Number:  1 2 3 4 5 6 7 8 9 10 11 ...\nBall Count:  2 1 1 1 1 1 1 1 1 0  0  ...\nBox 1 has the most number of balls with 2 balls.
    \n\n

    Example 2:

    \n\n
    \nInput: lowLimit = 5, highLimit = 15\nOutput: 2\nExplanation:\nBox Number:  1 2 3 4 5 6 7 8 9 10 11 ...\nBall Count:  1 1 1 1 2 2 1 1 1 0  0  ...\nBoxes 5 and 6 have the most number of balls with 2 balls in each.\n
    \n\n

    Example 3:

    \n\n
    \nInput: lowLimit = 19, highLimit = 28\nOutput: 2\nExplanation:\nBox Number:  1 2 3 4 5 6 7 8 9 10 11 12 ...\nBall Count:  0 1 1 1 1 1 1 1 1 2  0  0  ...\nBox 10 has the most number of balls with 2 balls.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= lowLimit <= highLimit <= 105
    • \n
    \n", "content_cn": "

    \u4f60\u5728\u4e00\u5bb6\u751f\u4ea7\u5c0f\u7403\u7684\u73a9\u5177\u5382\u5de5\u4f5c\uff0c\u6709 n \u4e2a\u5c0f\u7403\uff0c\u7f16\u53f7\u4ece lowLimit \u5f00\u59cb\uff0c\u5230 highLimit \u7ed3\u675f\uff08\u5305\u62ec lowLimit \u548c\u00a0highLimit \uff0c\u5373\u00a0n == highLimit - lowLimit + 1\uff09\u3002\u53e6\u6709\u65e0\u9650\u6570\u91cf\u7684\u76d2\u5b50\uff0c\u7f16\u53f7\u4ece 1 \u5230 infinity \u3002

    \n\n

    \u4f60\u7684\u5de5\u4f5c\u662f\u5c06\u6bcf\u4e2a\u5c0f\u7403\u653e\u5165\u76d2\u5b50\u4e2d\uff0c\u5176\u4e2d\u76d2\u5b50\u7684\u7f16\u53f7\u5e94\u5f53\u7b49\u4e8e\u5c0f\u7403\u7f16\u53f7\u4e0a\u6bcf\u4f4d\u6570\u5b57\u7684\u548c\u3002\u4f8b\u5982\uff0c\u7f16\u53f7 321 \u7684\u5c0f\u7403\u5e94\u5f53\u653e\u5165\u7f16\u53f7 3 + 2 + 1 = 6 \u7684\u76d2\u5b50\uff0c\u800c\u7f16\u53f7 10 \u7684\u5c0f\u7403\u5e94\u5f53\u653e\u5165\u7f16\u53f7 1 + 0 = 1 \u7684\u76d2\u5b50\u3002

    \n\n

    \u7ed9\u4f60\u4e24\u4e2a\u6574\u6570 lowLimit \u548c highLimit \uff0c\u8fd4\u56de\u653e\u6709\u6700\u591a\u5c0f\u7403\u7684\u76d2\u5b50\u4e2d\u7684\u5c0f\u7403\u6570\u91cf\u3002\u5982\u679c\u6709\u591a\u4e2a\u76d2\u5b50\u90fd\u6ee1\u8db3\u653e\u6709\u6700\u591a\u5c0f\u7403\uff0c\u53ea\u9700\u8fd4\u56de\u5176\u4e2d\u4efb\u4e00\u76d2\u5b50\u7684\u5c0f\u7403\u6570\u91cf\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1alowLimit = 1, highLimit = 10\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n\u76d2\u5b50\u7f16\u53f7\uff1a1 2 3 4 5 6 7 8 9 10 11 ...\n\u5c0f\u7403\u6570\u91cf\uff1a2 1 1 1 1 1 1 1 1 0  0  ...\n\u7f16\u53f7 1 \u7684\u76d2\u5b50\u653e\u6709\u6700\u591a\u5c0f\u7403\uff0c\u5c0f\u7403\u6570\u91cf\u4e3a 2 \u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1alowLimit = 5, highLimit = 15\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n\u76d2\u5b50\u7f16\u53f7\uff1a1 2 3 4 5 6 7 8 9 10 11 ...\n\u5c0f\u7403\u6570\u91cf\uff1a1 1 1 1 2 2 1 1 1 0  0  ...\n\u7f16\u53f7 5 \u548c 6 \u7684\u76d2\u5b50\u653e\u6709\u6700\u591a\u5c0f\u7403\uff0c\u6bcf\u4e2a\u76d2\u5b50\u4e2d\u7684\u5c0f\u7403\u6570\u91cf\u90fd\u662f 2 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1alowLimit = 19, highLimit = 28\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n\u76d2\u5b50\u7f16\u53f7\uff1a1 2 3 4 5 6 7 8 9 10 11 12 ...\n\u5c0f\u7403\u6570\u91cf\uff1a0 1 1 1 1 1 1 1 1 2  0  0  ...\n\u7f16\u53f7 10 \u7684\u76d2\u5b50\u653e\u6709\u6700\u591a\u5c0f\u7403\uff0c\u5c0f\u7403\u6570\u91cf\u4e3a 2 \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= lowLimit <= highLimit <= 105
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countBalls(int lowLimit, int highLimit) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countBalls(int lowLimit, int highLimit) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countBalls(self, lowLimit, highLimit):\n \"\"\"\n :type lowLimit: int\n :type highLimit: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countBalls(self, lowLimit: int, highLimit: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countBalls(int lowLimit, int highLimit){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountBalls(int lowLimit, int highLimit) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} lowLimit\n * @param {number} highLimit\n * @return {number}\n */\nvar countBalls = function(lowLimit, highLimit) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} low_limit\n# @param {Integer} high_limit\n# @return {Integer}\ndef count_balls(low_limit, high_limit)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countBalls(_ lowLimit: Int, _ highLimit: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countBalls(lowLimit int, highLimit int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countBalls(lowLimit: Int, highLimit: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countBalls(lowLimit: Int, highLimit: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_balls(low_limit: i32, high_limit: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $lowLimit\n * @param Integer $highLimit\n * @return Integer\n */\n function countBalls($lowLimit, $highLimit) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countBalls(lowLimit: number, highLimit: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-balls lowLimit highLimit)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1742](https://leetcode-cn.com/problems/maximum-number-of-balls-in-a-box)", "[\u76d2\u5b50\u4e2d\u5c0f\u7403\u7684\u6700\u5927\u6570\u91cf](/solution/1700-1799/1742.Maximum%20Number%20of%20Balls%20in%20a%20Box/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1742](https://leetcode.com/problems/maximum-number-of-balls-in-a-box)", "[Maximum Number of Balls in a Box](/solution/1700-1799/1742.Maximum%20Number%20of%20Balls%20in%20a%20Box/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1843", "frontend_question_id": "1725", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-rectangles-that-can-form-the-largest-square", "url_en": "https://leetcode.com/problems/number-of-rectangles-that-can-form-the-largest-square", "relative_path_cn": "/solution/1700-1799/1725.Number%20Of%20Rectangles%20That%20Can%20Form%20The%20Largest%20Square/README.md", "relative_path_en": "/solution/1700-1799/1725.Number%20Of%20Rectangles%20That%20Can%20Form%20The%20Largest%20Square/README_EN.md", "title_cn": "\u53ef\u4ee5\u5f62\u6210\u6700\u5927\u6b63\u65b9\u5f62\u7684\u77e9\u5f62\u6570\u76ee", "title_en": "Number Of Rectangles That Can Form The Largest Square", "question_title_slug": "number-of-rectangles-that-can-form-the-largest-square", "content_en": "

    You are given an array rectangles where rectangles[i] = [li, wi] represents the ith rectangle of length li and width wi.

    \r\n\r\n

    You can cut the ith rectangle to form a square with a side length of k if both k <= li and k <= wi. For example, if you have a rectangle [4,6], you can cut it to get a square with a side length of at most 4.

    \r\n\r\n

    Let maxLen be the side length of the largest square you can obtain from any of the given rectangles.

    \r\n\r\n

    Return the number of rectangles that can make a square with a side length of maxLen.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: rectangles = [[5,8],[3,9],[5,12],[16,5]]\r\nOutput: 3\r\nExplanation: The largest squares you can get from each rectangle are of lengths [5,3,5,5].\r\nThe largest possible square is of length 5, and you can get it out of 3 rectangles.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: rectangles = [[2,3],[3,7],[4,3],[3,7]]\r\nOutput: 3\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= rectangles.length <= 1000
    • \r\n\t
    • rectangles[i].length == 2
    • \r\n\t
    • 1 <= li, wi <= 109
    • \r\n\t
    • li != wi
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 rectangles \uff0c\u5176\u4e2d rectangles[i] = [li, wi] \u8868\u793a\u7b2c i \u4e2a\u77e9\u5f62\u7684\u957f\u5ea6\u4e3a li \u3001\u5bbd\u5ea6\u4e3a wi \u3002

    \n\n

    \u5982\u679c\u5b58\u5728 k \u540c\u65f6\u6ee1\u8db3 k <= li \u548c k <= wi \uff0c\u5c31\u53ef\u4ee5\u5c06\u7b2c i \u4e2a\u77e9\u5f62\u5207\u6210\u8fb9\u957f\u4e3a k \u7684\u6b63\u65b9\u5f62\u3002\u4f8b\u5982\uff0c\u77e9\u5f62 [4,6] \u53ef\u4ee5\u5207\u6210\u8fb9\u957f\u6700\u5927\u4e3a 4 \u7684\u6b63\u65b9\u5f62\u3002

    \n\n

    \u8bbe maxLen \u4e3a\u53ef\u4ee5\u4ece\u77e9\u5f62\u6570\u7ec4\u00a0rectangles \u5207\u5206\u5f97\u5230\u7684 \u6700\u5927\u6b63\u65b9\u5f62 \u7684\u8fb9\u957f\u3002

    \n\n

    \u8bf7\u4f60\u7edf\u8ba1\u6709\u591a\u5c11\u4e2a\u77e9\u5f62\u80fd\u591f\u5207\u51fa\u8fb9\u957f\u4e3a maxLen \u7684\u6b63\u65b9\u5f62\uff0c\u5e76\u8fd4\u56de\u77e9\u5f62 \u6570\u76ee \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1arectangles = [[5,8],[3,9],[5,12],[16,5]]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u80fd\u4ece\u6bcf\u4e2a\u77e9\u5f62\u4e2d\u5207\u51fa\u7684\u6700\u5927\u6b63\u65b9\u5f62\u8fb9\u957f\u5206\u522b\u662f [5,3,5,5] \u3002\n\u6700\u5927\u6b63\u65b9\u5f62\u7684\u8fb9\u957f\u4e3a 5 \uff0c\u53ef\u4ee5\u7531 3 \u4e2a\u77e9\u5f62\u5207\u5206\u5f97\u5230\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1arectangles = [[2,3],[3,7],[4,3],[3,7]]\n\u8f93\u51fa\uff1a3\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= rectangles.length <= 1000
    • \n\t
    • rectangles[i].length == 2
    • \n\t
    • 1 <= li, wi <= 109
    • \n\t
    • li != wi
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countGoodRectangles(vector>& rectangles) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countGoodRectangles(int[][] rectangles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countGoodRectangles(self, rectangles):\n \"\"\"\n :type rectangles: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countGoodRectangles(self, rectangles: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countGoodRectangles(int** rectangles, int rectanglesSize, int* rectanglesColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountGoodRectangles(int[][] rectangles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} rectangles\n * @return {number}\n */\nvar countGoodRectangles = function(rectangles) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} rectangles\n# @return {Integer}\ndef count_good_rectangles(rectangles)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countGoodRectangles(_ rectangles: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countGoodRectangles(rectangles [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countGoodRectangles(rectangles: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countGoodRectangles(rectangles: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_good_rectangles(rectangles: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $rectangles\n * @return Integer\n */\n function countGoodRectangles($rectangles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countGoodRectangles(rectangles: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-good-rectangles rectangles)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1725](https://leetcode-cn.com/problems/number-of-rectangles-that-can-form-the-largest-square)", "[\u53ef\u4ee5\u5f62\u6210\u6700\u5927\u6b63\u65b9\u5f62\u7684\u77e9\u5f62\u6570\u76ee](/solution/1700-1799/1725.Number%20Of%20Rectangles%20That%20Can%20Form%20The%20Largest%20Square/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u7b80\u5355", ""], "md_table_row_en": ["[1725](https://leetcode.com/problems/number-of-rectangles-that-can-form-the-largest-square)", "[Number Of Rectangles That Can Form The Largest Square](/solution/1700-1799/1725.Number%20Of%20Rectangles%20That%20Can%20Form%20The%20Largest%20Square/README_EN.md)", "`Greedy`", "Easy", ""]}, {"question_id": "1842", "frontend_question_id": "1699", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/number-of-calls-between-two-persons", "url_en": "https://leetcode.com/problems/number-of-calls-between-two-persons", "relative_path_cn": "/solution/1600-1699/1699.Number%20of%20Calls%20Between%20Two%20Persons/README.md", "relative_path_en": "/solution/1600-1699/1699.Number%20of%20Calls%20Between%20Two%20Persons/README_EN.md", "title_cn": "\u4e24\u4eba\u4e4b\u95f4\u7684\u901a\u8bdd\u6b21\u6570", "title_en": "Number of Calls Between Two Persons", "question_title_slug": "number-of-calls-between-two-persons", "content_en": "

    Table: Calls

    \n\n
    \n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| from_id     | int     |\n| to_id       | int     |\n| duration    | int     |\n+-------------+---------+\nThis table does not have a primary key, it may contain duplicates.\nThis table contains the duration of a phone call between from_id and to_id.\nfrom_id != to_id\n
    \n\n

     

    \n\n

    Write an SQL query to report the number of calls and the total call duration between each pair of distinct persons (person1, person2) where person1 < person2.

    \n\n

    Return the result table in any order.

    \n\n

    The query result format is in the following example:

    \n\n

     

    \n\n
    \nCalls table:\n+---------+-------+----------+\n| from_id | to_id | duration |\n+---------+-------+----------+\n| 1       | 2     | 59       |\n| 2       | 1     | 11       |\n| 1       | 3     | 20       |\n| 3       | 4     | 100      |\n| 3       | 4     | 200      |\n| 3       | 4     | 200      |\n| 4       | 3     | 499      |\n+---------+-------+----------+\n\nResult table:\n+---------+---------+------------+----------------+\n| person1 | person2 | call_count | total_duration |\n+---------+---------+------------+----------------+\n| 1       | 2       | 2          | 70             |\n| 1       | 3       | 1          | 20             |\n| 3       | 4       | 4          | 999            |\n+---------+---------+------------+----------------+\nUsers 1 and 2 had 2 calls and the total duration is 70 (59 + 11).\nUsers 1 and 3 had 1 call and the total duration is 20.\nUsers 3 and 4 had 4 calls and the total duration is 999 (100 + 200 + 200 + 499).\n
    \n", "content_cn": "

    \u8868\uff1a\u00a0Calls

    \n\n
    +-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| from_id     | int     |\n| to_id       | int     |\n| duration    | int     |\n+-------------+---------+\n\u8be5\u8868\u6ca1\u6709\u4e3b\u952e\uff0c\u53ef\u80fd\u5b58\u5728\u91cd\u590d\u9879\u3002\n\u8be5\u8868\u5305\u542b from_id \u4e0e to_id \u95f4\u7684\u4e00\u6b21\u7535\u8bdd\u7684\u65f6\u957f\u3002\nfrom_id != to_id\n
    \n\n

    \u00a0

    \n\n

    \u7f16\u5199 SQL \u8bed\u53e5\uff0c\u67e5\u8be2\u6bcf\u4e00\u5bf9\u7528\u6237\u00a0(person1, person2)\u00a0\u4e4b\u95f4\u7684\u901a\u8bdd\u6b21\u6570\u548c\u901a\u8bdd\u603b\u65f6\u957f\uff0c\u5176\u4e2d\u00a0person1 < person2\u00a0\u3002

    \n\n

    \u4ee5\u4efb\u610f\u987a\u5e8f\u8fd4\u56de\u7ed3\u679c\u8868\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u793a\u4f8b\u6240\u793a\uff1a

    \n\n

    \u00a0

    \n\n
    Calls \u8868\uff1a\n+---------+-------+----------+\n| from_id | to_id | duration |\n+---------+-------+----------+\n| 1       | 2     | 59       |\n| 2       | 1     | 11       |\n| 1       | 3     | 20       |\n| 3       | 4     | 100      |\n| 3       | 4     | 200      |\n| 3       | 4     | 200      |\n| 4       | 3     | 499      |\n+---------+-------+----------+\n\n\u7ed3\u679c\u8868\uff1a\n+---------+---------+------------+----------------+\n| person1 | person2 | call_count | total_duration |\n+---------+---------+------------+----------------+\n| 1       | 2       | 2          | 70             |\n| 1       | 3       | 1          | 20             |\n| 3       | 4       | 4          | 999            |\n+---------+---------+------------+----------------+\n\u7528\u6237 1 \u548c 2 \u6253\u8fc7 2 \u6b21\u7535\u8bdd\uff0c\u603b\u65f6\u957f\u4e3a 70 (59 + 11)\u3002\n\u7528\u6237 1 \u548c 3 \u6253\u8fc7 1 \u6b21\u7535\u8bdd\uff0c\u603b\u65f6\u957f\u4e3a 20\u3002\n\u7528\u6237 3 \u548c 4 \u6253\u8fc7 4 \u6b21\u7535\u8bdd\uff0c\u603b\u65f6\u957f\u4e3a 999 (100 + 200 + 200 + 499)\u3002\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1699](https://leetcode-cn.com/problems/number-of-calls-between-two-persons)", "[\u4e24\u4eba\u4e4b\u95f4\u7684\u901a\u8bdd\u6b21\u6570](/solution/1600-1699/1699.Number%20of%20Calls%20Between%20Two%20Persons/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1699](https://leetcode.com/problems/number-of-calls-between-two-persons)", "[Number of Calls Between Two Persons](/solution/1600-1699/1699.Number%20of%20Calls%20Between%20Two%20Persons/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1840", "frontend_question_id": "1722", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimize-hamming-distance-after-swap-operations", "url_en": "https://leetcode.com/problems/minimize-hamming-distance-after-swap-operations", "relative_path_cn": "/solution/1700-1799/1722.Minimize%20Hamming%20Distance%20After%20Swap%20Operations/README.md", "relative_path_en": "/solution/1700-1799/1722.Minimize%20Hamming%20Distance%20After%20Swap%20Operations/README_EN.md", "title_cn": "\u6267\u884c\u4ea4\u6362\u64cd\u4f5c\u540e\u7684\u6700\u5c0f\u6c49\u660e\u8ddd\u79bb", "title_en": "Minimize Hamming Distance After Swap Operations", "question_title_slug": "minimize-hamming-distance-after-swap-operations", "content_en": "

    You are given two integer arrays, source and target, both of length n. You are also given an array allowedSwaps where each allowedSwaps[i] = [ai, bi] indicates that you are allowed to swap the elements at index ai and index bi (0-indexed) of array source. Note that you can swap elements at a specific pair of indices multiple times and in any order.

    \n\n

    The Hamming distance of two arrays of the same length, source and target, is the number of positions where the elements are different. Formally, it is the number of indices i for 0 <= i <= n-1 where source[i] != target[i] (0-indexed).

    \n\n

    Return the minimum Hamming distance of source and target after performing any amount of swap operations on array source.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: source = [1,2,3,4], target = [2,1,4,5], allowedSwaps = [[0,1],[2,3]]\nOutput: 1\nExplanation: source can be transformed the following way:\n- Swap indices 0 and 1: source = [2,1,3,4]\n- Swap indices 2 and 3: source = [2,1,4,3]\nThe Hamming distance of source and target is 1 as they differ in 1 position: index 3.\n
    \n\n

    Example 2:

    \n\n
    \nInput: source = [1,2,3,4], target = [1,3,2,4], allowedSwaps = []\nOutput: 2\nExplanation: There are no allowed swaps.\nThe Hamming distance of source and target is 2 as they differ in 2 positions: index 1 and index 2.\n
    \n\n

    Example 3:

    \n\n
    \nInput: source = [5,1,2,4,3], target = [1,5,4,2,3], allowedSwaps = [[0,4],[4,2],[1,3],[1,4]]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == source.length == target.length
    • \n\t
    • 1 <= n <= 105
    • \n\t
    • 1 <= source[i], target[i] <= 105
    • \n\t
    • 0 <= allowedSwaps.length <= 105
    • \n\t
    • allowedSwaps[i].length == 2
    • \n\t
    • 0 <= ai, bi <= n - 1
    • \n\t
    • ai != bi
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u6574\u6570\u6570\u7ec4 source \u548c target \uff0c\u957f\u5ea6\u90fd\u662f n \u3002\u8fd8\u6709\u4e00\u4e2a\u6570\u7ec4 allowedSwaps \uff0c\u5176\u4e2d\u6bcf\u4e2a allowedSwaps[i] = [ai, bi] \u8868\u793a\u4f60\u53ef\u4ee5\u4ea4\u6362\u6570\u7ec4 source \u4e2d\u4e0b\u6807\u4e3a ai \u548c bi\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\u7684\u4e24\u4e2a\u5143\u7d20\u3002\u6ce8\u610f\uff0c\u4f60\u53ef\u4ee5\u6309 \u4efb\u610f \u987a\u5e8f \u591a\u6b21 \u4ea4\u6362\u4e00\u5bf9\u7279\u5b9a\u4e0b\u6807\u6307\u5411\u7684\u5143\u7d20\u3002

    \n\n

    \u76f8\u540c\u957f\u5ea6\u7684\u4e24\u4e2a\u6570\u7ec4\u00a0source \u548c target \u95f4\u7684 \u6c49\u660e\u8ddd\u79bb \u662f\u5143\u7d20\u4e0d\u540c\u7684\u4e0b\u6807\u6570\u91cf\u3002\u5f62\u5f0f\u4e0a\uff0c\u5176\u503c\u7b49\u4e8e\u6ee1\u8db3\u00a0source[i] != target[i] \uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\u7684\u4e0b\u6807 i\uff080 <= i <= n-1\uff09\u7684\u6570\u91cf\u3002

    \n\n

    \u5728\u5bf9\u6570\u7ec4 source \u6267\u884c \u4efb\u610f \u6570\u91cf\u7684\u4ea4\u6362\u64cd\u4f5c\u540e\uff0c\u8fd4\u56de source \u548c target \u95f4\u7684 \u6700\u5c0f\u6c49\u660e\u8ddd\u79bb \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1asource = [1,2,3,4], target = [2,1,4,5], allowedSwaps = [[0,1],[2,3]]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1asource \u53ef\u4ee5\u6309\u4e0b\u8ff0\u65b9\u5f0f\u8f6c\u6362\uff1a\n- \u4ea4\u6362\u4e0b\u6807 0 \u548c 1 \u6307\u5411\u7684\u5143\u7d20\uff1asource = [2,1,3,4]\n- \u4ea4\u6362\u4e0b\u6807 2 \u548c 3 \u6307\u5411\u7684\u5143\u7d20\uff1asource = [2,1,4,3]\nsource \u548c target \u95f4\u7684\u6c49\u660e\u8ddd\u79bb\u662f 1 \uff0c\u4e8c\u8005\u6709 1 \u5904\u5143\u7d20\u4e0d\u540c\uff0c\u5728\u4e0b\u6807 3 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1asource = [1,2,3,4], target = [1,3,2,4], allowedSwaps = []\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u4e0d\u80fd\u5bf9 source \u6267\u884c\u4ea4\u6362\u64cd\u4f5c\u3002\nsource \u548c target \u95f4\u7684\u6c49\u660e\u8ddd\u79bb\u662f 2 \uff0c\u4e8c\u8005\u6709 2 \u5904\u5143\u7d20\u4e0d\u540c\uff0c\u5728\u4e0b\u6807 1 \u548c\u4e0b\u6807 2 \u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1asource = [5,1,2,4,3], target = [1,5,4,2,3], allowedSwaps = [[0,4],[4,2],[1,3],[1,4]]\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == source.length == target.length
    • \n\t
    • 1 <= n <= 105
    • \n\t
    • 1 <= source[i], target[i] <= 105
    • \n\t
    • 0 <= allowedSwaps.length <= 105
    • \n\t
    • allowedSwaps[i].length == 2
    • \n\t
    • 0 <= ai, bi <= n - 1
    • \n\t
    • ai != bi
    • \n
    \n", "tags_en": ["Greedy", "Depth-first Search", "Union Find"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e76\u67e5\u96c6"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minimumHammingDistance(vector& source, vector& target, vector>& allowedSwaps) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minimumHammingDistance(int[] source, int[] target, int[][] allowedSwaps) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimumHammingDistance(self, source, target, allowedSwaps):\n \"\"\"\n :type source: List[int]\n :type target: List[int]\n :type allowedSwaps: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimumHammingDistance(self, source: List[int], target: List[int], allowedSwaps: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minimumHammingDistance(int* source, int sourceSize, int* target, int targetSize, int** allowedSwaps, int allowedSwapsSize, int* allowedSwapsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinimumHammingDistance(int[] source, int[] target, int[][] allowedSwaps) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} source\n * @param {number[]} target\n * @param {number[][]} allowedSwaps\n * @return {number}\n */\nvar minimumHammingDistance = function(source, target, allowedSwaps) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} source\n# @param {Integer[]} target\n# @param {Integer[][]} allowed_swaps\n# @return {Integer}\ndef minimum_hamming_distance(source, target, allowed_swaps)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimumHammingDistance(_ source: [Int], _ target: [Int], _ allowedSwaps: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimumHammingDistance(source []int, target []int, allowedSwaps [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimumHammingDistance(source: Array[Int], target: Array[Int], allowedSwaps: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimumHammingDistance(source: IntArray, target: IntArray, allowedSwaps: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimum_hamming_distance(source: Vec, target: Vec, allowed_swaps: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $source\n * @param Integer[] $target\n * @param Integer[][] $allowedSwaps\n * @return Integer\n */\n function minimumHammingDistance($source, $target, $allowedSwaps) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimumHammingDistance(source: number[], target: number[], allowedSwaps: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimum-hamming-distance source target allowedSwaps)\n (-> (listof exact-integer?) (listof exact-integer?) (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1722](https://leetcode-cn.com/problems/minimize-hamming-distance-after-swap-operations)", "[\u6267\u884c\u4ea4\u6362\u64cd\u4f5c\u540e\u7684\u6700\u5c0f\u6c49\u660e\u8ddd\u79bb](/solution/1700-1799/1722.Minimize%20Hamming%20Distance%20After%20Swap%20Operations/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e76\u67e5\u96c6`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1722](https://leetcode.com/problems/minimize-hamming-distance-after-swap-operations)", "[Minimize Hamming Distance After Swap Operations](/solution/1700-1799/1722.Minimize%20Hamming%20Distance%20After%20Swap%20Operations/README_EN.md)", "`Greedy`,`Depth-first Search`,`Union Find`", "Medium", ""]}, {"question_id": "1839", "frontend_question_id": "1720", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/decode-xored-array", "url_en": "https://leetcode.com/problems/decode-xored-array", "relative_path_cn": "/solution/1700-1799/1720.Decode%20XORed%20Array/README.md", "relative_path_en": "/solution/1700-1799/1720.Decode%20XORed%20Array/README_EN.md", "title_cn": "\u89e3\u7801\u5f02\u6216\u540e\u7684\u6570\u7ec4", "title_en": "Decode XORed Array", "question_title_slug": "decode-xored-array", "content_en": "

    There is a hidden integer array arr that consists of n non-negative integers.

    \n\n

    It was encoded into another integer array encoded of length n - 1, such that encoded[i] = arr[i] XOR arr[i + 1]. For example, if arr = [1,0,2,1], then encoded = [1,2,3].

    \n\n

    You are given the encoded array. You are also given an integer first, that is the first element of arr, i.e. arr[0].

    \n\n

    Return the original array arr. It can be proved that the answer exists and is unique.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: encoded = [1,2,3], first = 1\nOutput: [1,0,2,1]\nExplanation: If arr = [1,0,2,1], then first = 1 and encoded = [1 XOR 0, 0 XOR 2, 2 XOR 1] = [1,2,3]\n
    \n\n

    Example 2:

    \n\n
    \nInput: encoded = [6,2,7,3], first = 4\nOutput: [4,2,0,7,4]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= n <= 104
    • \n\t
    • encoded.length == n - 1
    • \n\t
    • 0 <= encoded[i] <= 105
    • \n\t
    • 0 <= first <= 105
    • \n
    \n", "content_cn": "

    \u672a\u77e5 \u6574\u6570\u6570\u7ec4 arr \u7531 n \u4e2a\u975e\u8d1f\u6574\u6570\u7ec4\u6210\u3002

    \n\n

    \u7ecf\u7f16\u7801\u540e\u53d8\u4e3a\u957f\u5ea6\u4e3a n - 1 \u7684\u53e6\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 encoded \uff0c\u5176\u4e2d encoded[i] = arr[i] XOR arr[i + 1] \u3002\u4f8b\u5982\uff0carr = [1,0,2,1] \u7ecf\u7f16\u7801\u540e\u5f97\u5230 encoded = [1,2,3] \u3002

    \n\n

    \u7ed9\u4f60\u7f16\u7801\u540e\u7684\u6570\u7ec4 encoded \u548c\u539f\u6570\u7ec4 arr \u7684\u7b2c\u4e00\u4e2a\u5143\u7d20 first\uff08arr[0]\uff09\u3002

    \n\n

    \u8bf7\u89e3\u7801\u8fd4\u56de\u539f\u6570\u7ec4 arr \u3002\u53ef\u4ee5\u8bc1\u660e\u7b54\u6848\u5b58\u5728\u5e76\u4e14\u662f\u552f\u4e00\u7684\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aencoded = [1,2,3], first = 1\n\u8f93\u51fa\uff1a[1,0,2,1]\n\u89e3\u91ca\uff1a\u82e5 arr = [1,0,2,1] \uff0c\u90a3\u4e48 first = 1 \u4e14 encoded = [1 XOR 0, 0 XOR 2, 2 XOR 1] = [1,2,3]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aencoded = [6,2,7,3], first = 4\n\u8f93\u51fa\uff1a[4,2,0,7,4]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= n <= 104
    • \n\t
    • encoded.length == n - 1
    • \n\t
    • 0 <= encoded[i] <= 105
    • \n\t
    • 0 <= first <= 105
    • \n
    \n", "tags_en": ["Bit Manipulation"], "tags_cn": ["\u4f4d\u8fd0\u7b97"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector decode(vector& encoded, int first) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] decode(int[] encoded, int first) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def decode(self, encoded, first):\n \"\"\"\n :type encoded: List[int]\n :type first: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def decode(self, encoded: List[int], first: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* decode(int* encoded, int encodedSize, int first, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] Decode(int[] encoded, int first) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} encoded\n * @param {number} first\n * @return {number[]}\n */\nvar decode = function(encoded, first) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} encoded\n# @param {Integer} first\n# @return {Integer[]}\ndef decode(encoded, first)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func decode(_ encoded: [Int], _ first: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func decode(encoded []int, first int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def decode(encoded: Array[Int], first: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun decode(encoded: IntArray, first: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn decode(encoded: Vec, first: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $encoded\n * @param Integer $first\n * @return Integer[]\n */\n function decode($encoded, $first) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function decode(encoded: number[], first: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (decode encoded first)\n (-> (listof exact-integer?) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1720](https://leetcode-cn.com/problems/decode-xored-array)", "[\u89e3\u7801\u5f02\u6216\u540e\u7684\u6570\u7ec4](/solution/1700-1799/1720.Decode%20XORed%20Array/README.md)", "`\u4f4d\u8fd0\u7b97`", "\u7b80\u5355", ""], "md_table_row_en": ["[1720](https://leetcode.com/problems/decode-xored-array)", "[Decode XORed Array](/solution/1700-1799/1720.Decode%20XORed%20Array/README_EN.md)", "`Bit Manipulation`", "Easy", ""]}, {"question_id": "1838", "frontend_question_id": "1698", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/number-of-distinct-substrings-in-a-string", "url_en": "https://leetcode.com/problems/number-of-distinct-substrings-in-a-string", "relative_path_cn": "/solution/1600-1699/1698.Number%20of%20Distinct%20Substrings%20in%20a%20String/README.md", "relative_path_en": "/solution/1600-1699/1698.Number%20of%20Distinct%20Substrings%20in%20a%20String/README_EN.md", "title_cn": "\u5b57\u7b26\u4e32\u7684\u4e0d\u540c\u5b50\u5b57\u7b26\u4e32\u4e2a\u6570", "title_en": "Number of Distinct Substrings in a String", "question_title_slug": "number-of-distinct-substrings-in-a-string", "content_en": "

    Given a string s, return the number of distinct substrings of s.

    \n\n

    A substring of a string is obtained by deleting any number of characters (possibly zero) from the front of the string and any number (possibly zero) from the back of the string.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "aabbaba"\nOutput: 21\nExplanation: The set of distinct strings is ["a","b","aa","bb","ab","ba","aab","abb","bab","bba","aba","aabb","abba","bbab","baba","aabba","abbab","bbaba","aabbab","abbaba","aabbaba"]\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "abcdefg"\nOutput: 28\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 500
    • \n\t
    • s consists of lowercase English letters.
    • \n
    \n\n

     

    \nFollow up: Can you solve this problem in O(n) time complexity?", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\u00a0s\uff0c\u8fd4\u56de\u00a0s\u00a0\u7684\u4e0d\u540c\u5b50\u5b57\u7b26\u4e32\u7684\u4e2a\u6570\u3002

    \n\n

    \u5b57\u7b26\u4e32\u7684 \u5b50\u5b57\u7b26\u4e32 \u662f\u7531\u539f\u5b57\u7b26\u4e32\u5220\u9664\u5f00\u5934\u82e5\u5e72\u4e2a\u5b57\u7b26\uff08\u53ef\u80fd\u662f 0 \u4e2a\uff09\u5e76\u5220\u9664\u7ed3\u5c3e\u82e5\u5e72\u4e2a\u5b57\u7b26\uff08\u53ef\u80fd\u662f 0 \u4e2a\uff09\u5f62\u6210\u7684\u5b57\u7b26\u4e32\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"aabbaba\"\n\u8f93\u51fa\uff1a21\n\u89e3\u91ca\uff1a\u4e0d\u540c\u5b50\u5b57\u7b26\u4e32\u7684\u96c6\u5408\u662f [\"a\",\"b\",\"aa\",\"bb\",\"ab\",\"ba\",\"aab\",\"abb\",\"bab\",\"bba\",\"aba\",\"aabb\",\"abba\",\"bbab\",\"baba\",\"aabba\",\"abbab\",\"bbaba\",\"aabbab\",\"abbaba\",\"aabbaba\"]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"abcdefg\"\n\u8f93\u51fa\uff1a28\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 500
    • \n\t
    • s\u00a0\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\u3002
    • \n
    \n\n

    \u8fdb\u9636\uff1a\u4f60\u53ef\u4ee5\u4ee5\u00a0O(n)\u00a0\u65f6\u95f4\u590d\u6742\u5ea6\u89e3\u51b3\u6b64\u95ee\u9898\u5417\uff1f

    \n", "tags_en": ["Trie", "String"], "tags_cn": ["\u5b57\u5178\u6811", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countDistinct(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countDistinct(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countDistinct(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countDistinct(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countDistinct(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountDistinct(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar countDistinct = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef count_distinct(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countDistinct(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countDistinct(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countDistinct(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countDistinct(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_distinct(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function countDistinct($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countDistinct(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-distinct s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1698](https://leetcode-cn.com/problems/number-of-distinct-substrings-in-a-string)", "[\u5b57\u7b26\u4e32\u7684\u4e0d\u540c\u5b50\u5b57\u7b26\u4e32\u4e2a\u6570](/solution/1600-1699/1698.Number%20of%20Distinct%20Substrings%20in%20a%20String/README.md)", "`\u5b57\u5178\u6811`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1698](https://leetcode.com/problems/number-of-distinct-substrings-in-a-string)", "[Number of Distinct Substrings in a String](/solution/1600-1699/1698.Number%20of%20Distinct%20Substrings%20in%20a%20String/README_EN.md)", "`Trie`,`String`", "Medium", "\ud83d\udd12"]}, {"question_id": "1837", "frontend_question_id": "1693", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/daily-leads-and-partners", "url_en": "https://leetcode.com/problems/daily-leads-and-partners", "relative_path_cn": "/solution/1600-1699/1693.Daily%20Leads%20and%20Partners/README.md", "relative_path_en": "/solution/1600-1699/1693.Daily%20Leads%20and%20Partners/README_EN.md", "title_cn": "\u6bcf\u5929\u7684\u9886\u5bfc\u548c\u5408\u4f19\u4eba", "title_en": "Daily Leads and Partners", "question_title_slug": "daily-leads-and-partners", "content_en": "

    Table: DailySales

    \n\n
    \n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| date_id     | date    |\n| make_name   | varchar |\n| lead_id     | int     |\n| partner_id  | int     |\n+-------------+---------+\nThis table does not have a primary key.\nThis table contains the date and the name of the product sold and the IDs of the lead and partner it was sold to.\nThe name consists of only lowercase English letters.\n
    \n\n

     

    \n\n

    Write an SQL query that will, for each date_id and make_name, return the number of distinct lead_id's and distinct partner_id's.

    \n\n

    Return the result table in any order.

    \n\n

    The query result format is in the following example:

    \n\n

     

    \n\n
    \nDailySales table:\n+-----------+-----------+---------+------------+\n| date_id   | make_name | lead_id | partner_id |\n+-----------+-----------+---------+------------+\n| 2020-12-8 | toyota    | 0       | 1          |\n| 2020-12-8 | toyota    | 1       | 0          |\n| 2020-12-8 | toyota    | 1       | 2          |\n| 2020-12-7 | toyota    | 0       | 2          |\n| 2020-12-7 | toyota    | 0       | 1          |\n| 2020-12-8 | honda     | 1       | 2          |\n| 2020-12-8 | honda     | 2       | 1          |\n| 2020-12-7 | honda     | 0       | 1          |\n| 2020-12-7 | honda     | 1       | 2          |\n| 2020-12-7 | honda     | 2       | 1          |\n+-----------+-----------+---------+------------+\nResult table:\n+-----------+-----------+--------------+-----------------+\n| date_id   | make_name | unique_leads | unique_partners |\n+-----------+-----------+--------------+-----------------+\n| 2020-12-8 | toyota    | 2            | 3               |\n| 2020-12-7 | toyota    | 1            | 2               |\n| 2020-12-8 | honda     | 2            | 2               |\n| 2020-12-7 | honda     | 3            | 2               |\n+-----------+-----------+--------------+-----------------+\nFor 2020-12-8, toyota gets leads = [0, 1] and partners = [0, 1, 2] while honda gets leads = [1, 2] and partners = [1, 2].\nFor 2020-12-7, toyota gets leads = [0] and partners = [1, 2] while honda gets leads = [0, 1, 2] and partners = [1, 2].\n
    \n", "content_cn": "

    \u8868\uff1aDailySales

    \n\n
    +-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| date_id     | date    |\n| make_name   | varchar |\n| lead_id     | int     |\n| partner_id  | int     |\n+-------------+---------+\n\u8be5\u8868\u6ca1\u6709\u4e3b\u952e\u3002\n\u8be5\u8868\u5305\u542b\u65e5\u671f\u3001\u4ea7\u54c1\u7684\u540d\u79f0\uff0c\u4ee5\u53ca\u552e\u7ed9\u7684\u9886\u5bfc\u548c\u5408\u4f19\u4eba\u7684\u7f16\u53f7\u3002\n\u540d\u79f0\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    \n\n

    \u00a0

    \n\n

    \u5199\u4e00\u6761 SQL \u8bed\u53e5\uff0c\u4f7f\u5f97\u5bf9\u4e8e\u6bcf\u4e00\u4e2a\u00a0date_id\u00a0\u548c\u00a0make_name\uff0c\u8fd4\u56de\u4e0d\u540c\u7684\u00a0lead_id\u00a0\u4ee5\u53ca\u4e0d\u540c\u7684\u00a0partner_id\u00a0\u7684\u6570\u91cf\u3002

    \n\n

    \u6309\u4efb\u610f\u987a\u5e8f\u8fd4\u56de\u7ed3\u679c\u8868\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u793a\u4f8b\u6240\u793a\uff1a

    \n\n

    \u00a0

    \n\n
    DailySales \u8868\uff1a\n+-----------+-----------+---------+------------+\n| date_id   | make_name | lead_id | partner_id |\n+-----------+-----------+---------+------------+\n| 2020-12-8 | toyota    | 0       | 1          |\n| 2020-12-8 | toyota    | 1       | 0          |\n| 2020-12-8 | toyota    | 1       | 2          |\n| 2020-12-7 | toyota    | 0       | 2          |\n| 2020-12-7 | toyota    | 0       | 1          |\n| 2020-12-8 | honda     | 1       | 2          |\n| 2020-12-8 | honda     | 2       | 1          |\n| 2020-12-7 | honda     | 0       | 1          |\n| 2020-12-7 | honda     | 1       | 2          |\n| 2020-12-7 | honda     | 2       | 1          |\n+-----------+-----------+---------+------------+\n\u7ed3\u679c\u8868\uff1a\n+-----------+-----------+--------------+-----------------+\n| date_id   | make_name | unique_leads | unique_partners |\n+-----------+-----------+--------------+-----------------+\n| 2020-12-8 | toyota    | 2            | 3               |\n| 2020-12-7 | toyota    | 1            | 2               |\n| 2020-12-8 | honda     | 2            | 2               |\n| 2020-12-7 | honda     | 3            | 2               |\n+-----------+-----------+--------------+-----------------+\n\u5728 2020-12-8\uff0c\u4e30\u7530\uff08toyota\uff09\u6709\u9886\u5bfc\u8005 = [0, 1] \u548c\u5408\u4f19\u4eba = [0, 1, 2] \uff0c\u540c\u65f6\u672c\u7530\uff08honda\uff09\u6709\u9886\u5bfc\u8005 = [1, 2] \u548c\u5408\u4f19\u4eba = [1, 2]\u3002\n\u5728 2020-12-7\uff0c\u4e30\u7530\uff08toyota\uff09\u6709\u9886\u5bfc\u8005 = [0] \u548c\u5408\u4f19\u4eba = [1, 2] \uff0c\u540c\u65f6\u672c\u7530\uff08honda\uff09\u6709\u9886\u5bfc\u8005 = [0, 1, 2] \u548c\u5408\u4f19\u4eba = [1, 2]\u3002
    \n\n

    \u00a0

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1693](https://leetcode-cn.com/problems/daily-leads-and-partners)", "[\u6bcf\u5929\u7684\u9886\u5bfc\u548c\u5408\u4f19\u4eba](/solution/1600-1699/1693.Daily%20Leads%20and%20Partners/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1693](https://leetcode.com/problems/daily-leads-and-partners)", "[Daily Leads and Partners](/solution/1600-1699/1693.Daily%20Leads%20and%20Partners/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1836", "frontend_question_id": "1735", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-ways-to-make-array-with-product", "url_en": "https://leetcode.com/problems/count-ways-to-make-array-with-product", "relative_path_cn": "/solution/1700-1799/1735.Count%20Ways%20to%20Make%20Array%20With%20Product/README.md", "relative_path_en": "/solution/1700-1799/1735.Count%20Ways%20to%20Make%20Array%20With%20Product/README_EN.md", "title_cn": "\u751f\u6210\u4e58\u79ef\u6570\u7ec4\u7684\u65b9\u6848\u6570", "title_en": "Count Ways to Make Array With Product", "question_title_slug": "count-ways-to-make-array-with-product", "content_en": "

    You are given a 2D integer array, queries. For each queries[i], where queries[i] = [ni, ki], find the number of different ways you can place positive integers into an array of size ni such that the product of the integers is ki. As the number of ways may be too large, the answer to the ith query is the number of ways modulo 109 + 7.

    \n\n

    Return an integer array answer where answer.length == queries.length, and answer[i] is the answer to the ith query.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: queries = [[2,6],[5,1],[73,660]]\nOutput: [4,1,50734910]\nExplanation: Each query is independent.\n[2,6]: There are 4 ways to fill an array of size 2 that multiply to 6: [1,6], [2,3], [3,2], [6,1].\n[5,1]: There is 1 way to fill an array of size 5 that multiply to 1: [1,1,1,1,1].\n[73,660]: There are 1050734917 ways to fill an array of size 73 that multiply to 660. 1050734917 modulo 109 + 7 = 50734910.\n
    \n\n

    Example 2:

    \n\n
    \nInput: queries = [[1,1],[2,2],[3,3],[4,4],[5,5]]\nOutput: [1,2,3,10,5]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= queries.length <= 104
    • \n\t
    • 1 <= ni, ki <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u4e8c\u7ef4\u6574\u6570\u6570\u7ec4\u00a0queries\u00a0\uff0c\u5176\u4e2d queries[i] = [ni, ki] \u3002\u7b2c\u00a0i\u00a0\u4e2a\u67e5\u8be2\u00a0queries[i] \u8981\u6c42\u6784\u9020\u957f\u5ea6\u4e3a\u00a0ni \u3001\u6bcf\u4e2a\u5143\u7d20\u90fd\u662f\u6b63\u6574\u6570\u7684\u6570\u7ec4\uff0c\u4e14\u6ee1\u8db3\u6240\u6709\u5143\u7d20\u7684\u4e58\u79ef\u4e3a\u00a0ki\u00a0\uff0c\u8bf7\u4f60\u627e\u51fa\u6709\u591a\u5c11\u79cd\u53ef\u884c\u7684\u65b9\u6848\u3002\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u4f1a\u5f88\u5927\uff0c\u65b9\u6848\u6570\u9700\u8981\u5bf9 109 + 7\u00a0\u53d6\u4f59 \u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0answer\uff0c\u6ee1\u8db3\u00a0answer.length == queries.length\u00a0\uff0c\u5176\u4e2d\u00a0answer[i]\u662f\u7b2c\u00a0i\u00a0\u4e2a\u67e5\u8be2\u7684\u7ed3\u679c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aqueries = [[2,6],[5,1],[73,660]]\n\u8f93\u51fa\uff1a[4,1,50734910]\n\u89e3\u91ca\uff1a\u6bcf\u4e2a\u67e5\u8be2\u4e4b\u95f4\u5f7c\u6b64\u72ec\u7acb\u3002\n[2,6]\uff1a\u603b\u5171\u6709 4 \u79cd\u65b9\u6848\u5f97\u5230\u957f\u5ea6\u4e3a 2 \u4e14\u4e58\u79ef\u4e3a 6 \u7684\u6570\u7ec4\uff1a[1,6]\uff0c[2,3]\uff0c[3,2]\uff0c[6,1]\u3002\n[5,1]\uff1a\u603b\u5171\u6709 1 \u79cd\u65b9\u6848\u5f97\u5230\u957f\u5ea6\u4e3a 5 \u4e14\u4e58\u79ef\u4e3a 1 \u7684\u6570\u7ec4\uff1a[1,1,1,1,1]\u3002\n[73,660]\uff1a\u603b\u5171\u6709 1050734917 \u79cd\u65b9\u6848\u5f97\u5230\u957f\u5ea6\u4e3a 73 \u4e14\u4e58\u79ef\u4e3a 660 \u7684\u6570\u7ec4\u30021050734917 \u5bf9 109 + 7 \u53d6\u4f59\u5f97\u5230 50734910 \u3002\n
    \n\n

    \u793a\u4f8b 2\u00a0\uff1a

    \n\n
    \n\u8f93\u5165\uff1aqueries = [[1,1],[2,2],[3,3],[4,4],[5,5]]\n\u8f93\u51fa\uff1a[1,2,3,10,5]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= queries.length <= 104
    • \n\t
    • 1 <= ni, ki <= 104
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector waysToFillArray(vector>& queries) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] waysToFillArray(int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def waysToFillArray(self, queries):\n \"\"\"\n :type queries: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def waysToFillArray(self, queries: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* waysToFillArray(int** queries, int queriesSize, int* queriesColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] WaysToFillArray(int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} queries\n * @return {number[]}\n */\nvar waysToFillArray = function(queries) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} queries\n# @return {Integer[]}\ndef ways_to_fill_array(queries)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func waysToFillArray(_ queries: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func waysToFillArray(queries [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def waysToFillArray(queries: Array[Array[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun waysToFillArray(queries: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn ways_to_fill_array(queries: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $queries\n * @return Integer[]\n */\n function waysToFillArray($queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function waysToFillArray(queries: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (ways-to-fill-array queries)\n (-> (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1735](https://leetcode-cn.com/problems/count-ways-to-make-array-with-product)", "[\u751f\u6210\u4e58\u79ef\u6570\u7ec4\u7684\u65b9\u6848\u6570](/solution/1700-1799/1735.Count%20Ways%20to%20Make%20Array%20With%20Product/README.md)", "`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[1735](https://leetcode.com/problems/count-ways-to-make-array-with-product)", "[Count Ways to Make Array With Product](/solution/1700-1799/1735.Count%20Ways%20to%20Make%20Array%20With%20Product/README_EN.md)", "`Math`", "Hard", ""]}, {"question_id": "1835", "frontend_question_id": "1734", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/decode-xored-permutation", "url_en": "https://leetcode.com/problems/decode-xored-permutation", "relative_path_cn": "/solution/1700-1799/1734.Decode%20XORed%20Permutation/README.md", "relative_path_en": "/solution/1700-1799/1734.Decode%20XORed%20Permutation/README_EN.md", "title_cn": "\u89e3\u7801\u5f02\u6216\u540e\u7684\u6392\u5217", "title_en": "Decode XORed Permutation", "question_title_slug": "decode-xored-permutation", "content_en": "

    There is an integer array perm that is a permutation of the first n positive integers, where n is always odd.

    \n\n

    It was encoded into another integer array encoded of length n - 1, such that encoded[i] = perm[i] XOR perm[i + 1]. For example, if perm = [1,3,2], then encoded = [2,1].

    \n\n

    Given the encoded array, return the original array perm. It is guaranteed that the answer exists and is unique.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: encoded = [3,1]\nOutput: [1,2,3]\nExplanation: If perm = [1,2,3], then encoded = [1 XOR 2,2 XOR 3] = [3,1]\n
    \n\n

    Example 2:

    \n\n
    \nInput: encoded = [6,5,4,6]\nOutput: [2,4,1,5,3]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 3 <= n < 105
    • \n\t
    • n is odd.
    • \n\t
    • encoded.length == n - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0perm\u00a0\uff0c\u5b83\u662f\u524d\u00a0n\u00a0\u4e2a\u6b63\u6574\u6570\u7684\u6392\u5217\uff0c\u4e14\u00a0n\u00a0\u662f\u4e2a \u5947\u6570\u00a0\u3002

    \n\n

    \u5b83\u88ab\u52a0\u5bc6\u6210\u53e6\u4e00\u4e2a\u957f\u5ea6\u4e3a n - 1\u00a0\u7684\u6574\u6570\u6570\u7ec4\u00a0encoded\u00a0\uff0c\u6ee1\u8db3\u00a0encoded[i] = perm[i] XOR perm[i + 1]\u00a0\u3002\u6bd4\u65b9\u8bf4\uff0c\u5982\u679c\u00a0perm = [1,3,2]\u00a0\uff0c\u90a3\u4e48\u00a0encoded = [2,1]\u00a0\u3002

    \n\n

    \u7ed9\u4f60\u00a0encoded\u00a0\u6570\u7ec4\uff0c\u8bf7\u4f60\u8fd4\u56de\u539f\u59cb\u6570\u7ec4\u00a0perm\u00a0\u3002\u9898\u76ee\u4fdd\u8bc1\u7b54\u6848\u5b58\u5728\u4e14\u552f\u4e00\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aencoded = [3,1]\n\u8f93\u51fa\uff1a[1,2,3]\n\u89e3\u91ca\uff1a\u5982\u679c perm = [1,2,3] \uff0c\u90a3\u4e48 encoded = [1 XOR 2,2 XOR 3] = [3,1]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aencoded = [6,5,4,6]\n\u8f93\u51fa\uff1a[2,4,1,5,3]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 3 <= n <\u00a0105
    • \n\t
    • n\u00a0\u662f\u5947\u6570\u3002
    • \n\t
    • encoded.length == n - 1
    • \n
    \n", "tags_en": ["Bit Manipulation"], "tags_cn": ["\u4f4d\u8fd0\u7b97"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector decode(vector& encoded) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] decode(int[] encoded) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def decode(self, encoded):\n \"\"\"\n :type encoded: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def decode(self, encoded: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* decode(int* encoded, int encodedSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] Decode(int[] encoded) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} encoded\n * @return {number[]}\n */\nvar decode = function(encoded) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} encoded\n# @return {Integer[]}\ndef decode(encoded)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func decode(_ encoded: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func decode(encoded []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def decode(encoded: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun decode(encoded: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn decode(encoded: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $encoded\n * @return Integer[]\n */\n function decode($encoded) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function decode(encoded: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (decode encoded)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1734](https://leetcode-cn.com/problems/decode-xored-permutation)", "[\u89e3\u7801\u5f02\u6216\u540e\u7684\u6392\u5217](/solution/1700-1799/1734.Decode%20XORed%20Permutation/README.md)", "`\u4f4d\u8fd0\u7b97`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1734](https://leetcode.com/problems/decode-xored-permutation)", "[Decode XORed Permutation](/solution/1700-1799/1734.Decode%20XORed%20Permutation/README_EN.md)", "`Bit Manipulation`", "Medium", ""]}, {"question_id": "1834", "frontend_question_id": "1733", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-number-of-people-to-teach", "url_en": "https://leetcode.com/problems/minimum-number-of-people-to-teach", "relative_path_cn": "/solution/1700-1799/1733.Minimum%20Number%20of%20People%20to%20Teach/README.md", "relative_path_en": "/solution/1700-1799/1733.Minimum%20Number%20of%20People%20to%20Teach/README_EN.md", "title_cn": "\u9700\u8981\u6559\u8bed\u8a00\u7684\u6700\u5c11\u4eba\u6570", "title_en": "Minimum Number of People to Teach", "question_title_slug": "minimum-number-of-people-to-teach", "content_en": "

    On a social network consisting of m users and some friendships between users, two users can communicate with each other if they know a common language.

    \n\n

    You are given an integer n, an array languages, and an array friendships where:

    \n\n
      \n\t
    • There are n languages numbered 1 through n,
    • \n\t
    • languages[i] is the set of languages the i\u200b\u200b\u200b\u200b\u200b\u200bth\u200b\u200b\u200b\u200b user knows, and
    • \n\t
    • friendships[i] = [u\u200b\u200b\u200b\u200b\u200b\u200bi\u200b\u200b\u200b, v\u200b\u200b\u200b\u200b\u200b\u200bi] denotes a friendship between the users u\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200bi\u200b\u200b\u200b\u200b\u200b and vi.
    • \n
    \n\n

    You can choose one language and teach it to some users so that all friends can communicate with each other. Return the minimum number of users you need to teach.

    \nNote that friendships are not transitive, meaning if x is a friend of y and y is a friend of z, this doesn't guarantee that x is a friend of z.\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 2, languages = [[1],[2],[1,2]], friendships = [[1,2],[1,3],[2,3]]\nOutput: 1\nExplanation: You can either teach user 1 the second language or user 2 the first language.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 3, languages = [[2],[1,3],[1,2],[3]], friendships = [[1,4],[1,2],[3,4],[2,3]]\nOutput: 2\nExplanation: Teach the third language to users 1 and 3, yielding two users to teach.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= n <= 500
    • \n\t
    • languages.length == m
    • \n\t
    • 1 <= m <= 500
    • \n\t
    • 1 <= languages[i].length <= n
    • \n\t
    • 1 <= languages[i][j] <= n
    • \n\t
    • 1 <= u\u200b\u200b\u200b\u200b\u200b\u200bi < v\u200b\u200b\u200b\u200b\u200b\u200bi <= languages.length
    • \n\t
    • 1 <= friendships.length <= 500
    • \n\t
    • All tuples (u\u200b\u200b\u200b\u200b\u200bi, v\u200b\u200b\u200b\u200b\u200b\u200bi) are unique
    • \n\t
    • languages[i] contains only unique values
    • \n
    \n", "content_cn": "

    \u5728\u4e00\u4e2a\u7531\u00a0m\u00a0\u4e2a\u7528\u6237\u7ec4\u6210\u7684\u793e\u4ea4\u7f51\u7edc\u91cc\uff0c\u6211\u4eec\u83b7\u53d6\u5230\u4e00\u4e9b\u7528\u6237\u4e4b\u95f4\u7684\u597d\u53cb\u5173\u7cfb\u3002\u4e24\u4e2a\u7528\u6237\u4e4b\u95f4\u53ef\u4ee5\u76f8\u4e92\u6c9f\u901a\u7684\u6761\u4ef6\u662f\u4ed6\u4eec\u90fd\u638c\u63e1\u540c\u4e00\u95e8\u8bed\u8a00\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u00a0n\u00a0\uff0c\u6570\u7ec4\u00a0languages\u00a0\u548c\u6570\u7ec4\u00a0friendships\u00a0\uff0c\u5b83\u4eec\u7684\u542b\u4e49\u5982\u4e0b\uff1a

    \n\n
      \n\t
    • \u603b\u5171\u6709\u00a0n\u00a0\u79cd\u8bed\u8a00\uff0c\u7f16\u53f7\u4ece\u00a01 \u5230\u00a0n\u00a0\u3002
    • \n\t
    • languages[i]\u00a0\u662f\u7b2c i\u00a0\u4f4d\u7528\u6237\u638c\u63e1\u7684\u8bed\u8a00\u96c6\u5408\u3002
    • \n\t
    • friendships[i] = [u\u200b\u200b\u200b\u200b\u200b\u200bi\u200b\u200b\u200b, v\u200b\u200b\u200b\u200b\u200b\u200bi]\u00a0\u8868\u793a\u00a0u\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200bi\u200b\u200b\u200b\u200b\u200b \u548c\u00a0vi\u00a0\u4e3a\u597d\u53cb\u5173\u7cfb\u3002
    • \n
    \n\n

    \u4f60\u53ef\u4ee5\u9009\u62e9 \u4e00\u95e8\u00a0\u8bed\u8a00\u5e76\u6559\u4f1a\u4e00\u4e9b\u7528\u6237\uff0c\u4f7f\u5f97\u6240\u6709\u597d\u53cb\u4e4b\u95f4\u90fd\u53ef\u4ee5\u76f8\u4e92\u6c9f\u901a\u3002\u8bf7\u8fd4\u56de\u4f60 \u6700\u5c11\u00a0\u9700\u8981\u6559\u4f1a\u591a\u5c11\u540d\u7528\u6237\u3002

    \n\u8bf7\u6ce8\u610f\uff0c\u597d\u53cb\u5173\u7cfb\u6ca1\u6709\u4f20\u9012\u6027\uff0c\u4e5f\u5c31\u662f\u8bf4\u5982\u679c\u00a0x \u548c\u00a0y\u00a0\u662f\u597d\u53cb\uff0c\u4e14\u00a0y\u00a0\u548c\u00a0z\u00a0\u662f\u597d\u53cb\uff0c\u00a0x \u548c\u00a0z\u00a0\u4e0d\u4e00\u5b9a\u662f\u597d\u53cb\u3002\n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 2, languages = [[1],[2],[1,2]], friendships = [[1,2],[1,3],[2,3]]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u9009\u62e9\u6559\u7528\u6237 1 \u7b2c\u4e8c\u95e8\u8bed\u8a00\uff0c\u4e5f\u53ef\u4ee5\u9009\u62e9\u6559\u7528\u6237 2 \u7b2c\u4e00\u95e8\u8bed\u8a00\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 3, languages = [[2],[1,3],[1,2],[3]], friendships = [[1,4],[1,2],[3,4],[2,3]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6559\u7528\u6237 1 \u548c\u7528\u6237 3 \u7b2c\u4e09\u95e8\u8bed\u8a00\uff0c\u9700\u8981\u6559 2 \u540d\u7528\u6237\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= n <= 500
    • \n\t
    • languages.length == m
    • \n\t
    • 1 <= m <= 500
    • \n\t
    • 1 <= languages[i].length <= n
    • \n\t
    • 1 <= languages[i][j] <= n
    • \n\t
    • 1 <= u\u200b\u200b\u200b\u200b\u200b\u200bi < v\u200b\u200b\u200b\u200b\u200b\u200bi <= languages.length
    • \n\t
    • 1 <= friendships.length <= 500
    • \n\t
    • \u6240\u6709\u7684\u597d\u53cb\u5173\u7cfb\u00a0(u\u200b\u200b\u200b\u200b\u200bi, v\u200b\u200b\u200b\u200b\u200b\u200bi)\u00a0\u90fd\u662f\u552f\u4e00\u7684\u3002
    • \n\t
    • languages[i]\u00a0\u4e2d\u5305\u542b\u7684\u503c\u4e92\u4e0d\u76f8\u540c\u3002
    • \n
    \n", "tags_en": ["Greedy", "Array"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minimumTeachings(int n, vector>& languages, vector>& friendships) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minimumTeachings(int n, int[][] languages, int[][] friendships) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimumTeachings(self, n, languages, friendships):\n \"\"\"\n :type n: int\n :type languages: List[List[int]]\n :type friendships: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimumTeachings(self, n: int, languages: List[List[int]], friendships: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minimumTeachings(int n, int** languages, int languagesSize, int* languagesColSize, int** friendships, int friendshipsSize, int* friendshipsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinimumTeachings(int n, int[][] languages, int[][] friendships) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} languages\n * @param {number[][]} friendships\n * @return {number}\n */\nvar minimumTeachings = function(n, languages, friendships) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} languages\n# @param {Integer[][]} friendships\n# @return {Integer}\ndef minimum_teachings(n, languages, friendships)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimumTeachings(_ n: Int, _ languages: [[Int]], _ friendships: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimumTeachings(n int, languages [][]int, friendships [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimumTeachings(n: Int, languages: Array[Array[Int]], friendships: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimumTeachings(n: Int, languages: Array, friendships: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimum_teachings(n: i32, languages: Vec>, friendships: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $languages\n * @param Integer[][] $friendships\n * @return Integer\n */\n function minimumTeachings($n, $languages, $friendships) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimumTeachings(n: number, languages: number[][], friendships: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimum-teachings n languages friendships)\n (-> exact-integer? (listof (listof exact-integer?)) (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1733](https://leetcode-cn.com/problems/minimum-number-of-people-to-teach)", "[\u9700\u8981\u6559\u8bed\u8a00\u7684\u6700\u5c11\u4eba\u6570](/solution/1700-1799/1733.Minimum%20Number%20of%20People%20to%20Teach/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1733](https://leetcode.com/problems/minimum-number-of-people-to-teach)", "[Minimum Number of People to Teach](/solution/1700-1799/1733.Minimum%20Number%20of%20People%20to%20Teach/README_EN.md)", "`Greedy`,`Array`", "Medium", ""]}, {"question_id": "1833", "frontend_question_id": "1732", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-the-highest-altitude", "url_en": "https://leetcode.com/problems/find-the-highest-altitude", "relative_path_cn": "/solution/1700-1799/1732.Find%20the%20Highest%20Altitude/README.md", "relative_path_en": "/solution/1700-1799/1732.Find%20the%20Highest%20Altitude/README_EN.md", "title_cn": "\u627e\u5230\u6700\u9ad8\u6d77\u62d4", "title_en": "Find the Highest Altitude", "question_title_slug": "find-the-highest-altitude", "content_en": "

    There is a biker going on a road trip. The road trip consists of n + 1 points at different altitudes. The biker starts his trip on point 0 with altitude equal 0.

    \n\n

    You are given an integer array gain of length n where gain[i] is the net gain in altitude between points i\u200b\u200b\u200b\u200b\u200b\u200b and i + 1 for all (0 <= i < n). Return the highest altitude of a point.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: gain = [-5,1,5,0,-7]\nOutput: 1\nExplanation: The altitudes are [0,-5,-4,1,1,-6]. The highest is 1.\n
    \n\n

    Example 2:

    \n\n
    \nInput: gain = [-4,-3,-2,-1,4,3,2]\nOutput: 0\nExplanation: The altitudes are [0,-4,-7,-9,-10,-6,-3,-1]. The highest is 0.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == gain.length
    • \n\t
    • 1 <= n <= 100
    • \n\t
    • -100 <= gain[i] <= 100
    • \n
    \n", "content_cn": "

    \u6709\u4e00\u4e2a\u81ea\u884c\u8f66\u624b\u6253\u7b97\u8fdb\u884c\u4e00\u573a\u516c\u8def\u9a91\u884c\uff0c\u8fd9\u6761\u8def\u7ebf\u603b\u5171\u7531\u00a0n + 1\u00a0\u4e2a\u4e0d\u540c\u6d77\u62d4\u7684\u70b9\u7ec4\u6210\u3002\u81ea\u884c\u8f66\u624b\u4ece\u6d77\u62d4\u4e3a 0\u00a0\u7684\u70b9\u00a00\u00a0\u5f00\u59cb\u9a91\u884c\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u4e3a n\u00a0\u7684\u6574\u6570\u6570\u7ec4\u00a0gain\u00a0\uff0c\u5176\u4e2d gain[i]\u00a0\u662f\u70b9 i\u00a0\u548c\u70b9 i + 1\u00a0\u7684 \u51c0\u6d77\u62d4\u9ad8\u5ea6\u5dee\uff080 <= i < n\uff09\u3002\u8bf7\u4f60\u8fd4\u56de \u6700\u9ad8\u70b9\u7684\u6d77\u62d4 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1again = [-5,1,5,0,-7]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u6d77\u62d4\u9ad8\u5ea6\u4f9d\u6b21\u4e3a [0,-5,-4,1,1,-6] \u3002\u6700\u9ad8\u6d77\u62d4\u4e3a 1 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1again = [-4,-3,-2,-1,4,3,2]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6d77\u62d4\u9ad8\u5ea6\u4f9d\u6b21\u4e3a [0,-4,-7,-9,-10,-6,-3,-1] \u3002\u6700\u9ad8\u6d77\u62d4\u4e3a 0 \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == gain.length
    • \n\t
    • 1 <= n <= 100
    • \n\t
    • -100 <= gain[i] <= 100
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int largestAltitude(vector& gain) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int largestAltitude(int[] gain) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def largestAltitude(self, gain):\n \"\"\"\n :type gain: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def largestAltitude(self, gain: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint largestAltitude(int* gain, int gainSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LargestAltitude(int[] gain) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} gain\n * @return {number}\n */\nvar largestAltitude = function(gain) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} gain\n# @return {Integer}\ndef largest_altitude(gain)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func largestAltitude(_ gain: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func largestAltitude(gain []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def largestAltitude(gain: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun largestAltitude(gain: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn largest_altitude(gain: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $gain\n * @return Integer\n */\n function largestAltitude($gain) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function largestAltitude(gain: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (largest-altitude gain)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1732](https://leetcode-cn.com/problems/find-the-highest-altitude)", "[\u627e\u5230\u6700\u9ad8\u6d77\u62d4](/solution/1700-1799/1732.Find%20the%20Highest%20Altitude/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1732](https://leetcode.com/problems/find-the-highest-altitude)", "[Find the Highest Altitude](/solution/1700-1799/1732.Find%20the%20Highest%20Altitude/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1832", "frontend_question_id": "1713", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-operations-to-make-a-subsequence", "url_en": "https://leetcode.com/problems/minimum-operations-to-make-a-subsequence", "relative_path_cn": "/solution/1700-1799/1713.Minimum%20Operations%20to%20Make%20a%20Subsequence/README.md", "relative_path_en": "/solution/1700-1799/1713.Minimum%20Operations%20to%20Make%20a%20Subsequence/README_EN.md", "title_cn": "\u5f97\u5230\u5b50\u5e8f\u5217\u7684\u6700\u5c11\u64cd\u4f5c\u6b21\u6570", "title_en": "Minimum Operations to Make a Subsequence", "question_title_slug": "minimum-operations-to-make-a-subsequence", "content_en": "

    You are given an array target that consists of distinct integers and another integer array arr that can have duplicates.

    \n\n

    In one operation, you can insert any integer at any position in arr. For example, if arr = [1,4,1,2], you can add 3 in the middle and make it [1,4,3,1,2]. Note that you can insert the integer at the very beginning or end of the array.

    \n\n

    Return the minimum number of operations needed to make target a subsequence of arr.

    \n\n

    A subsequence of an array is a new array generated from the original array by deleting some elements (possibly none) without changing the remaining elements' relative order. For example, [2,7,4] is a subsequence of [4,2,3,7,2,1,4] (the underlined elements), while [2,4,2] is not.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: target = [5,1,3], arr = [9,4,2,3,4]\nOutput: 2\nExplanation: You can add 5 and 1 in such a way that makes arr = [5,9,4,1,2,3,4], then target will be a subsequence of arr.\n
    \n\n

    Example 2:

    \n\n
    \nInput: target = [6,4,8,1,3,2], arr = [4,7,6,2,3,8,6,1]\nOutput: 3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= target.length, arr.length <= 105
    • \n\t
    • 1 <= target[i], arr[i] <= 109
    • \n\t
    • target contains no duplicates.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4\u00a0target\u00a0\uff0c\u5305\u542b\u82e5\u5e72 \u4e92\u4e0d\u76f8\u540c\u00a0\u7684\u6574\u6570\uff0c\u4ee5\u53ca\u53e6\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0arr\u00a0\uff0carr\u00a0\u53ef\u80fd \u5305\u542b\u91cd\u590d\u5143\u7d20\u3002

    \n\n

    \u6bcf\u4e00\u6b21\u64cd\u4f5c\u4e2d\uff0c\u4f60\u53ef\u4ee5\u5728 arr\u00a0\u7684\u4efb\u610f\u4f4d\u7f6e\u63d2\u5165\u4efb\u4e00\u6574\u6570\u3002\u6bd4\u65b9\u8bf4\uff0c\u5982\u679c\u00a0arr = [1,4,1,2]\u00a0\uff0c\u90a3\u4e48\u4f60\u53ef\u4ee5\u5728\u4e2d\u95f4\u6dfb\u52a0 3\u00a0\u5f97\u5230\u00a0[1,4,3,1,2]\u00a0\u3002\u4f60\u53ef\u4ee5\u5728\u6570\u7ec4\u6700\u5f00\u59cb\u6216\u6700\u540e\u9762\u6dfb\u52a0\u6574\u6570\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de \u6700\u5c11\u00a0\u64cd\u4f5c\u6b21\u6570\uff0c\u4f7f\u5f97\u00a0target\u00a0\u6210\u4e3a\u00a0arr\u00a0\u7684\u4e00\u4e2a\u5b50\u5e8f\u5217\u3002

    \n\n

    \u4e00\u4e2a\u6570\u7ec4\u7684 \u5b50\u5e8f\u5217\u00a0\u6307\u7684\u662f\u5220\u9664\u539f\u6570\u7ec4\u7684\u67d0\u4e9b\u5143\u7d20\uff08\u53ef\u80fd\u4e00\u4e2a\u5143\u7d20\u90fd\u4e0d\u5220\u9664\uff09\uff0c\u540c\u65f6\u4e0d\u6539\u53d8\u5176\u4f59\u5143\u7d20\u7684\u76f8\u5bf9\u987a\u5e8f\u5f97\u5230\u7684\u6570\u7ec4\u3002\u6bd4\u65b9\u8bf4\uff0c[2,7,4]\u00a0\u662f\u00a0[4,2,3,7,2,1,4]\u00a0\u7684\u5b50\u5e8f\u5217\uff08\u52a0\u7c97\u5143\u7d20\uff09\uff0c\u4f46\u00a0[2,4,2]\u00a0\u4e0d\u662f\u5b50\u5e8f\u5217\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1atarget = [5,1,3], arr = [9,4,2,3,4]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u6dfb\u52a0 5 \u548c 1 \uff0c\u4f7f\u5f97 arr \u53d8\u4e3a [5,9,4,1,2,3,4] \uff0ctarget \u4e3a arr \u7684\u5b50\u5e8f\u5217\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1atarget = [6,4,8,1,3,2], arr = [4,7,6,2,3,8,6,1]\n\u8f93\u51fa\uff1a3\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= target.length, arr.length <= 105
    • \n\t
    • 1 <= target[i], arr[i] <= 109
    • \n\t
    • target\u00a0\u4e0d\u5305\u542b\u4efb\u4f55\u91cd\u590d\u5143\u7d20\u3002
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minOperations(vector& target, vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minOperations(int[] target, int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minOperations(self, target, arr):\n \"\"\"\n :type target: List[int]\n :type arr: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minOperations(self, target: List[int], arr: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minOperations(int* target, int targetSize, int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinOperations(int[] target, int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} target\n * @param {number[]} arr\n * @return {number}\n */\nvar minOperations = function(target, arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} target\n# @param {Integer[]} arr\n# @return {Integer}\ndef min_operations(target, arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minOperations(_ target: [Int], _ arr: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minOperations(target []int, arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minOperations(target: Array[Int], arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minOperations(target: IntArray, arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_operations(target: Vec, arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $target\n * @param Integer[] $arr\n * @return Integer\n */\n function minOperations($target, $arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minOperations(target: number[], arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-operations target arr)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1713](https://leetcode-cn.com/problems/minimum-operations-to-make-a-subsequence)", "[\u5f97\u5230\u5b50\u5e8f\u5217\u7684\u6700\u5c11\u64cd\u4f5c\u6b21\u6570](/solution/1700-1799/1713.Minimum%20Operations%20to%20Make%20a%20Subsequence/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[1713](https://leetcode.com/problems/minimum-operations-to-make-a-subsequence)", "[Minimum Operations to Make a Subsequence](/solution/1700-1799/1713.Minimum%20Operations%20to%20Make%20a%20Subsequence/README_EN.md)", "`Greedy`", "Hard", ""]}, {"question_id": "1831", "frontend_question_id": "1712", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/ways-to-split-array-into-three-subarrays", "url_en": "https://leetcode.com/problems/ways-to-split-array-into-three-subarrays", "relative_path_cn": "/solution/1700-1799/1712.Ways%20to%20Split%20Array%20Into%20Three%20Subarrays/README.md", "relative_path_en": "/solution/1700-1799/1712.Ways%20to%20Split%20Array%20Into%20Three%20Subarrays/README_EN.md", "title_cn": "\u5c06\u6570\u7ec4\u5206\u6210\u4e09\u4e2a\u5b50\u6570\u7ec4\u7684\u65b9\u6848\u6570", "title_en": "Ways to Split Array Into Three Subarrays", "question_title_slug": "ways-to-split-array-into-three-subarrays", "content_en": "

    A split of an integer array is good if:

    \r\n\r\n
      \r\n\t
    • The array is split into three non-empty contiguous subarrays - named left, mid, right respectively from left to right.
    • \r\n\t
    • The sum of the elements in left is less than or equal to the sum of the elements in mid, and the sum of the elements in mid is less than or equal to the sum of the elements in right.
    • \r\n
    \r\n\r\n

    Given nums, an array of non-negative integers, return the number of good ways to split nums. As the number may be too large, return it modulo 109 + 7.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: nums = [1,1,1]\r\nOutput: 1\r\nExplanation: The only good way to split nums is [1] [1] [1].
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: nums = [1,2,2,2,5,0]\r\nOutput: 3\r\nExplanation: There are three good ways of splitting nums:\r\n[1] [2] [2,2,5,0]\r\n[1] [2,2] [2,5,0]\r\n[1,2] [2,2] [5,0]\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: nums = [3,2,1]\r\nOutput: 0\r\nExplanation: There is no good way to split nums.
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 3 <= nums.length <= 105
    • \r\n\t
    • 0 <= nums[i] <= 104
    • \r\n
    ", "content_cn": "

    \u6211\u4eec\u79f0\u4e00\u4e2a\u5206\u5272\u6574\u6570\u6570\u7ec4\u7684\u65b9\u6848\u662f \u597d\u7684\u00a0\uff0c\u5f53\u5b83\u6ee1\u8db3\uff1a

    \n\n
      \n\t
    • \u6570\u7ec4\u88ab\u5206\u6210\u4e09\u4e2a \u975e\u7a7a\u00a0\u8fde\u7eed\u5b50\u6570\u7ec4\uff0c\u4ece\u5de6\u81f3\u53f3\u5206\u522b\u547d\u540d\u4e3a\u00a0left\u00a0\uff0c\u00a0mid\u00a0\uff0c\u00a0right\u00a0\u3002
    • \n\t
    • left\u00a0\u4e2d\u5143\u7d20\u548c\u5c0f\u4e8e\u7b49\u4e8e\u00a0mid\u00a0\u4e2d\u5143\u7d20\u548c\uff0cmid\u00a0\u4e2d\u5143\u7d20\u548c\u5c0f\u4e8e\u7b49\u4e8e\u00a0right\u00a0\u4e2d\u5143\u7d20\u548c\u3002
    • \n
    \n\n

    \u7ed9\u4f60\u4e00\u4e2a \u975e\u8d1f \u6574\u6570\u6570\u7ec4\u00a0nums\u00a0\uff0c\u8bf7\u4f60\u8fd4\u56de\u00a0\u597d\u7684 \u5206\u5272 nums\u00a0\u65b9\u6848\u6570\u76ee\u3002\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u4f1a\u5f88\u5927\uff0c\u8bf7\u4f60\u5c06\u7ed3\u679c\u5bf9 109\u00a0+ 7\u00a0\u53d6\u4f59\u540e\u8fd4\u56de\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,1,1]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u552f\u4e00\u4e00\u79cd\u597d\u7684\u5206\u5272\u65b9\u6848\u662f\u5c06 nums \u5206\u6210 [1] [1] [1] \u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,2,2,5,0]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1anums \u603b\u5171\u6709 3 \u79cd\u597d\u7684\u5206\u5272\u65b9\u6848\uff1a\n[1] [2] [2,2,5,0]\n[1] [2,2] [2,5,0]\n[1,2] [2,2] [5,0]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [3,2,1]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6ca1\u6709\u597d\u7684\u5206\u5272\u65b9\u6848\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 3 <= nums.length <= 105
    • \n\t
    • 0 <= nums[i] <= 104
    • \n
    \n", "tags_en": ["Two Pointers", "Binary Search"], "tags_cn": ["\u53cc\u6307\u9488", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int waysToSplit(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int waysToSplit(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def waysToSplit(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def waysToSplit(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint waysToSplit(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int WaysToSplit(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar waysToSplit = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef ways_to_split(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func waysToSplit(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func waysToSplit(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def waysToSplit(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun waysToSplit(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn ways_to_split(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function waysToSplit($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function waysToSplit(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (ways-to-split nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1712](https://leetcode-cn.com/problems/ways-to-split-array-into-three-subarrays)", "[\u5c06\u6570\u7ec4\u5206\u6210\u4e09\u4e2a\u5b50\u6570\u7ec4\u7684\u65b9\u6848\u6570](/solution/1700-1799/1712.Ways%20to%20Split%20Array%20Into%20Three%20Subarrays/README.md)", "`\u53cc\u6307\u9488`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1712](https://leetcode.com/problems/ways-to-split-array-into-three-subarrays)", "[Ways to Split Array Into Three Subarrays](/solution/1700-1799/1712.Ways%20to%20Split%20Array%20Into%20Three%20Subarrays/README_EN.md)", "`Two Pointers`,`Binary Search`", "Medium", ""]}, {"question_id": "1830", "frontend_question_id": "1711", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-good-meals", "url_en": "https://leetcode.com/problems/count-good-meals", "relative_path_cn": "/solution/1700-1799/1711.Count%20Good%20Meals/README.md", "relative_path_en": "/solution/1700-1799/1711.Count%20Good%20Meals/README_EN.md", "title_cn": "\u5927\u9910\u8ba1\u6570", "title_en": "Count Good Meals", "question_title_slug": "count-good-meals", "content_en": "

    A good meal is a meal that contains exactly two different food items with a sum of deliciousness equal to a power of two.

    \n\n

    You can pick any two different foods to make a good meal.

    \n\n

    Given an array of integers deliciousness where deliciousness[i] is the deliciousness of the i\u200b\u200b\u200b\u200b\u200b\u200bth\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b item of food, return the number of different good meals you can make from this list modulo 109 + 7.

    \n\n

    Note that items with different indices are considered different even if they have the same deliciousness value.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: deliciousness = [1,3,5,7,9]\nOutput: 4\nExplanation: The good meals are (1,3), (1,7), (3,5) and, (7,9).\nTheir respective sums are 4, 8, 8, and 16, all of which are powers of 2.\n
    \n\n

    Example 2:

    \n\n
    \nInput: deliciousness = [1,1,1,3,3,3,7]\nOutput: 15\nExplanation: The good meals are (1,1) with 3 ways, (1,3) with 9 ways, and (1,7) with 3 ways.
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= deliciousness.length <= 105
    • \n\t
    • 0 <= deliciousness[i] <= 220
    • \n
    \n", "content_cn": "

    \u5927\u9910 \u662f\u6307 \u6070\u597d\u5305\u542b\u4e24\u9053\u4e0d\u540c\u9910\u54c1 \u7684\u4e00\u9910\uff0c\u5176\u7f8e\u5473\u7a0b\u5ea6\u4e4b\u548c\u7b49\u4e8e 2 \u7684\u5e42\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u642d\u914d \u4efb\u610f \u4e24\u9053\u9910\u54c1\u505a\u4e00\u987f\u5927\u9910\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 deliciousness \uff0c\u5176\u4e2d deliciousness[i] \u662f\u7b2c i\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b \u9053\u9910\u54c1\u7684\u7f8e\u5473\u7a0b\u5ea6\uff0c\u8fd4\u56de\u4f60\u53ef\u4ee5\u7528\u6570\u7ec4\u4e2d\u7684\u9910\u54c1\u505a\u51fa\u7684\u4e0d\u540c \u5927\u9910 \u7684\u6570\u91cf\u3002\u7ed3\u679c\u9700\u8981\u5bf9 109 + 7 \u53d6\u4f59\u3002

    \n\n

    \u6ce8\u610f\uff0c\u53ea\u8981\u9910\u54c1\u4e0b\u6807\u4e0d\u540c\uff0c\u5c31\u53ef\u4ee5\u8ba4\u4e3a\u662f\u4e0d\u540c\u7684\u9910\u54c1\uff0c\u5373\u4fbf\u5b83\u4eec\u7684\u7f8e\u5473\u7a0b\u5ea6\u76f8\u540c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1adeliciousness = [1,3,5,7,9]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u5927\u9910\u7684\u7f8e\u5473\u7a0b\u5ea6\u7ec4\u5408\u4e3a (1,3) \u3001(1,7) \u3001(3,5) \u548c (7,9) \u3002\n\u5b83\u4eec\u5404\u81ea\u7684\u7f8e\u5473\u7a0b\u5ea6\u4e4b\u548c\u5206\u522b\u4e3a 4 \u30018 \u30018 \u548c 16 \uff0c\u90fd\u662f 2 \u7684\u5e42\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1adeliciousness = [1,1,1,3,3,3,7]\n\u8f93\u51fa\uff1a15\n\u89e3\u91ca\uff1a\u5927\u9910\u7684\u7f8e\u5473\u7a0b\u5ea6\u7ec4\u5408\u4e3a 3 \u79cd (1,1) \uff0c9 \u79cd (1,3) \uff0c\u548c 3 \u79cd (1,7) \u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= deliciousness.length <= 105
    • \n\t
    • 0 <= deliciousness[i] <= 220
    • \n
    \n", "tags_en": ["Array", "Hash Table", "Two Pointers"], "tags_cn": ["\u6570\u7ec4", "\u54c8\u5e0c\u8868", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countPairs(vector& deliciousness) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countPairs(int[] deliciousness) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countPairs(self, deliciousness):\n \"\"\"\n :type deliciousness: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countPairs(self, deliciousness: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countPairs(int* deliciousness, int deliciousnessSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountPairs(int[] deliciousness) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} deliciousness\n * @return {number}\n */\nvar countPairs = function(deliciousness) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} deliciousness\n# @return {Integer}\ndef count_pairs(deliciousness)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countPairs(_ deliciousness: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countPairs(deliciousness []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countPairs(deliciousness: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countPairs(deliciousness: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_pairs(deliciousness: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $deliciousness\n * @return Integer\n */\n function countPairs($deliciousness) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countPairs(deliciousness: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-pairs deliciousness)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1711](https://leetcode-cn.com/problems/count-good-meals)", "[\u5927\u9910\u8ba1\u6570](/solution/1700-1799/1711.Count%20Good%20Meals/README.md)", "`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1711](https://leetcode.com/problems/count-good-meals)", "[Count Good Meals](/solution/1700-1799/1711.Count%20Good%20Meals/README_EN.md)", "`Array`,`Hash Table`,`Two Pointers`", "Medium", ""]}, {"question_id": "1829", "frontend_question_id": "1710", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-units-on-a-truck", "url_en": "https://leetcode.com/problems/maximum-units-on-a-truck", "relative_path_cn": "/solution/1700-1799/1710.Maximum%20Units%20on%20a%20Truck/README.md", "relative_path_en": "/solution/1700-1799/1710.Maximum%20Units%20on%20a%20Truck/README_EN.md", "title_cn": "\u5361\u8f66\u4e0a\u7684\u6700\u5927\u5355\u5143\u6570", "title_en": "Maximum Units on a Truck", "question_title_slug": "maximum-units-on-a-truck", "content_en": "

    You are assigned to put some amount of boxes onto one truck. You are given a 2D array boxTypes, where boxTypes[i] = [numberOfBoxesi, numberOfUnitsPerBoxi]:

    \n\n
      \n\t
    • numberOfBoxesi is the number of boxes of type i.
    • \n\t
    • numberOfUnitsPerBoxi is the number of units in each box of the type i.
    • \n
    \n\n

    You are also given an integer truckSize, which is the maximum number of boxes that can be put on the truck. You can choose any boxes to put on the truck as long as the number of boxes does not exceed truckSize.

    \n\n

    Return the maximum total number of units that can be put on the truck.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: boxTypes = [[1,3],[2,2],[3,1]], truckSize = 4\nOutput: 8\nExplanation: There are:\n- 1 box of the first type that contains 3 units.\n- 2 boxes of the second type that contain 2 units each.\n- 3 boxes of the third type that contain 1 unit each.\nYou can take all the boxes of the first and second types, and one box of the third type.\nThe total number of units will be = (1 * 3) + (2 * 2) + (1 * 1) = 8.\n
    \n\n

    Example 2:

    \n\n
    \nInput: boxTypes = [[5,10],[2,5],[4,7],[3,9]], truckSize = 10\nOutput: 91\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= boxTypes.length <= 1000
    • \n\t
    • 1 <= numberOfBoxesi, numberOfUnitsPerBoxi <= 1000
    • \n\t
    • 1 <= truckSize <= 106
    • \n
    \n", "content_cn": "

    \u8bf7\u4f60\u5c06\u4e00\u4e9b\u7bb1\u5b50\u88c5\u5728 \u4e00\u8f86\u5361\u8f66 \u4e0a\u3002\u7ed9\u4f60\u4e00\u4e2a\u4e8c\u7ef4\u6570\u7ec4 boxTypes \uff0c\u5176\u4e2d boxTypes[i] = [numberOfBoxesi, numberOfUnitsPerBoxi] \uff1a

    \n\n
      \n\t
    • numberOfBoxesi \u662f\u7c7b\u578b i \u7684\u7bb1\u5b50\u7684\u6570\u91cf\u3002
    • \n\t
    • numberOfUnitsPerBoxi \u662f\u7c7b\u578b i\u00a0\u6bcf\u4e2a\u7bb1\u5b50\u53ef\u4ee5\u88c5\u8f7d\u7684\u5355\u5143\u6570\u91cf\u3002
    • \n
    \n\n

    \u6574\u6570 truckSize \u8868\u793a\u5361\u8f66\u4e0a\u53ef\u4ee5\u88c5\u8f7d \u7bb1\u5b50 \u7684 \u6700\u5927\u6570\u91cf \u3002\u53ea\u8981\u7bb1\u5b50\u6570\u91cf\u4e0d\u8d85\u8fc7 truckSize \uff0c\u4f60\u5c31\u53ef\u4ee5\u9009\u62e9\u4efb\u610f\u7bb1\u5b50\u88c5\u5230\u5361\u8f66\u4e0a\u3002

    \n\n

    \u8fd4\u56de\u5361\u8f66\u53ef\u4ee5\u88c5\u8f7d\u00a0\u5355\u5143 \u7684 \u6700\u5927 \u603b\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aboxTypes = [[1,3],[2,2],[3,1]], truckSize = 4\n\u8f93\u51fa\uff1a8\n\u89e3\u91ca\uff1a\u7bb1\u5b50\u7684\u60c5\u51b5\u5982\u4e0b\uff1a\n- 1 \u4e2a\u7b2c\u4e00\u7c7b\u7684\u7bb1\u5b50\uff0c\u91cc\u9762\u542b 3 \u4e2a\u5355\u5143\u3002\n- 2 \u4e2a\u7b2c\u4e8c\u7c7b\u7684\u7bb1\u5b50\uff0c\u6bcf\u4e2a\u91cc\u9762\u542b 2 \u4e2a\u5355\u5143\u3002\n- 3 \u4e2a\u7b2c\u4e09\u7c7b\u7684\u7bb1\u5b50\uff0c\u6bcf\u4e2a\u91cc\u9762\u542b 1 \u4e2a\u5355\u5143\u3002\n\u53ef\u4ee5\u9009\u62e9\u7b2c\u4e00\u7c7b\u548c\u7b2c\u4e8c\u7c7b\u7684\u6240\u6709\u7bb1\u5b50\uff0c\u4ee5\u53ca\u7b2c\u4e09\u7c7b\u7684\u4e00\u4e2a\u7bb1\u5b50\u3002\n\u5355\u5143\u603b\u6570 = (1 * 3) + (2 * 2) + (1 * 1) = 8
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aboxTypes = [[5,10],[2,5],[4,7],[3,9]], truckSize = 10\n\u8f93\u51fa\uff1a91\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= boxTypes.length <= 1000
    • \n\t
    • 1 <= numberOfBoxesi, numberOfUnitsPerBoxi <= 1000
    • \n\t
    • 1 <= truckSize <= 106
    • \n
    \n", "tags_en": ["Greedy", "Sort"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6392\u5e8f"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maximumUnits(vector>& boxTypes, int truckSize) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maximumUnits(int[][] boxTypes, int truckSize) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximumUnits(self, boxTypes, truckSize):\n \"\"\"\n :type boxTypes: List[List[int]]\n :type truckSize: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximumUnits(self, boxTypes: List[List[int]], truckSize: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maximumUnits(int** boxTypes, int boxTypesSize, int* boxTypesColSize, int truckSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaximumUnits(int[][] boxTypes, int truckSize) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} boxTypes\n * @param {number} truckSize\n * @return {number}\n */\nvar maximumUnits = function(boxTypes, truckSize) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} box_types\n# @param {Integer} truck_size\n# @return {Integer}\ndef maximum_units(box_types, truck_size)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximumUnits(_ boxTypes: [[Int]], _ truckSize: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximumUnits(boxTypes [][]int, truckSize int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximumUnits(boxTypes: Array[Array[Int]], truckSize: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximumUnits(boxTypes: Array, truckSize: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximum_units(box_types: Vec>, truck_size: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $boxTypes\n * @param Integer $truckSize\n * @return Integer\n */\n function maximumUnits($boxTypes, $truckSize) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximumUnits(boxTypes: number[][], truckSize: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximum-units boxTypes truckSize)\n (-> (listof (listof exact-integer?)) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1710](https://leetcode-cn.com/problems/maximum-units-on-a-truck)", "[\u5361\u8f66\u4e0a\u7684\u6700\u5927\u5355\u5143\u6570](/solution/1700-1799/1710.Maximum%20Units%20on%20a%20Truck/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6392\u5e8f`", "\u7b80\u5355", ""], "md_table_row_en": ["[1710](https://leetcode.com/problems/maximum-units-on-a-truck)", "[Maximum Units on a Truck](/solution/1700-1799/1710.Maximum%20Units%20on%20a%20Truck/README_EN.md)", "`Greedy`,`Sort`", "Easy", ""]}, {"question_id": "1828", "frontend_question_id": "1692", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/count-ways-to-distribute-candies", "url_en": "https://leetcode.com/problems/count-ways-to-distribute-candies", "relative_path_cn": "/solution/1600-1699/1692.Count%20Ways%20to%20Distribute%20Candies/README.md", "relative_path_en": "/solution/1600-1699/1692.Count%20Ways%20to%20Distribute%20Candies/README_EN.md", "title_cn": "\u8ba1\u7b97\u5206\u914d\u7cd6\u679c\u7684\u4e0d\u540c\u65b9\u5f0f", "title_en": "Count Ways to Distribute Candies", "question_title_slug": "count-ways-to-distribute-candies", "content_en": "

    There are n unique candies (labeled 1 through n) and k bags. You are asked to distribute all the candies into the bags such that every bag has at least one candy.

    \n\n

    There can be multiple ways to distribute the candies. Two ways are considered different if the candies in one bag in the first way are not all in the same bag in the second way. The order of the bags and the order of the candies within each bag do not matter.

    \n\n

    For example, (1), (2,3) and (2), (1,3) are considered different because candies 2 and 3 in the bag (2,3) in the first way are not in the same bag in the second way (they are split between the bags (2) and (1,3)). However, (1), (2,3) and (3,2), (1) are considered the same because the candies in each bag are all in the same bags in both ways.

    \n\n

    Given two integers, n and k, return the number of different ways to distribute the candies. As the answer may be too large, return it modulo 109 + 7.

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: n = 3, k = 2\nOutput: 3\nExplanation: You can distribute 3 candies into 2 bags in 3 ways:\n(1), (2,3)\n(1,2), (3)\n(1,3), (2)\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 4, k = 2\nOutput: 7\nExplanation: You can distribute 4 candies into 2 bags in 7 ways:\n(1), (2,3,4)\n(1,2), (3,4)\n(1,3), (2,4)\n(1,4), (2,3)\n(1,2,3), (4)\n(1,2,4), (3)\n(1,3,4), (2)\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 20, k = 5\nOutput: 206085257\nExplanation: You can distribute 20 candies into 5 bags in 1881780996 ways. 1881780996 modulo 109 + 7 = 206085257.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= k <= n <= 1000
    • \n
    \n", "content_cn": "

    \u73b0\u6709 n \u9897 \u4e0d\u540c \u7cd6\u679c\uff08\u5206\u522b\u6807\u8bb0\u4e3a 1 \u5230 n \uff09\u548c k \u4e2a\u76f8\u540c\u7684\u624b\u888b\u3002\u8bf7\u628a\u7cd6\u679c\u5206\u914d\u5230\u5404\u4e2a\u624b\u888b\u4e2d\u5e76\u4fdd\u8bc1\u6bcf\u4e2a\u624b\u888b\u91cc\u81f3\u5c11\u6709\u4e00\u9897\u7cd6\u679c\u3002

    \n\n

    \u4e0d\u8003\u8651\u624b\u888b\u548c\u7cd6\u679c\u7684\u6446\u653e\u987a\u5e8f\uff0c\u4f1a\u6709\u591a\u79cd\u4e0d\u540c\u7684\u5206\u914d\u65b9\u5f0f\u3002\u5982\u679c\u67d0\u79cd\u5206\u914d\u65b9\u5f0f\u4e2d\u5176\u4e2d\u4e00\u4e2a\u624b\u888b\u91cc\u7684\u7cd6\u679c\u4e0e\u53e6\u4e00\u79cd\u5206\u914d\u65b9\u5f0f\u4e2d\u6240\u6709\u624b\u888b\u91cc\u7684\u7cd6\u679c\u90fd\u4e0d\u76f8\u540c\uff0c\u5219\u8ba4\u4e3a\u8fd9\u4e24\u79cd\u5206\u914d\u65b9\u5f0f\u4e0d\u540c\u3002

    \n\n

    \u4f8b\u5982\uff0c(1), (2,3)\u00a0\u4e0e(2), (1,3)\u7684\u5206\u914d\u65b9\u5f0f\u662f\u4e0d\u540c\u7684\uff0c\u56e0\u4e3a\u7b2c\u4e00\u79cd\u5206\u914d\u65b9\u5f0f\u4e2d\u624b\u888b(2,3)\u91cc\u7684\u7cd6\u679c2\u548c3\uff0c\u5728\u7b2c\u4e8c\u79cd\u5206\u914d\u65b9\u5f0f\u4e2d\u88ab\u5206\u914d\u5230\u4e86\u624b\u888b(2)\u548c(1,3)\u00a0\u4e2d\u3002

    \n\n

    \u5df2\u77e5\u6574\u6570\u00a0n\u00a0\u548c\u00a0k, \u8bf7\u8fd4\u56de\u5206\u914d\u7cd6\u679c\u7684\u4e0d\u540c\u65b9\u5f0f\u3002\u8fd4\u56de\u7684\u7b54\u6848\u5982\u679c\u6570\u503c\u592a\u5927\uff0c\u8bf7\u53d6109 + 7\u7684\u6a21\uff0c\u5e76\u8fd4\u56de\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\u00a01\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1an = 3, k = 2\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u628a\u7cd6\u679c 3 \u5206\u914d\u5230 2 \u4e2a\u624b\u888b\u4e2d\u7684\u4e00\u4e2a\uff0c\u5171\u6709 3 \u79cd\u65b9\u5f0f:\n(1), (2,3)\n(1,2), (3)\n(1,3), (2)\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 4, k = 2\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u628a\u7cd6\u679c 4 \u5206\u914d\u5230 2 \u4e2a\u624b\u888b\u4e2d\u7684\u4e00\u4e2a\uff0c\u5171\u6709 7 \u79cd\u65b9\u5f0f:\n(1), (2,3,4)s\n(1,2), (3,4)\n(1,3), (2,4)\n(1,4), (2,3)\n(1,2,3), (4)\n(1,2,4), (3)\n(1,3,4), (2)\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 20, k = 5\n\u8f93\u51fa\uff1a206085257\n\u89e3\u91ca\uff1a\u628a 20 \u9897\u7cd6\u679c\u5206\u914d\u5230 5 \u4e2a\u624b\u888b\u79cd\uff0c\u5171\u6709 1881780996 \u79cd\u65b9\u5f0f\u30021881780996 \u53d6 109 + 7\u7684\u6a21\uff0c\u7b49\u4e8e 206085257\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= k <= n <= 1000
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int waysToDistribute(int n, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int waysToDistribute(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def waysToDistribute(self, n, k):\n \"\"\"\n :type n: int\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def waysToDistribute(self, n: int, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint waysToDistribute(int n, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int WaysToDistribute(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} k\n * @return {number}\n */\nvar waysToDistribute = function(n, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} k\n# @return {Integer}\ndef ways_to_distribute(n, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func waysToDistribute(_ n: Int, _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func waysToDistribute(n int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def waysToDistribute(n: Int, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun waysToDistribute(n: Int, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn ways_to_distribute(n: i32, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $k\n * @return Integer\n */\n function waysToDistribute($n, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function waysToDistribute(n: number, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (ways-to-distribute n k)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1692](https://leetcode-cn.com/problems/count-ways-to-distribute-candies)", "[\u8ba1\u7b97\u5206\u914d\u7cd6\u679c\u7684\u4e0d\u540c\u65b9\u5f0f](/solution/1600-1699/1692.Count%20Ways%20to%20Distribute%20Candies/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1692](https://leetcode.com/problems/count-ways-to-distribute-candies)", "[Count Ways to Distribute Candies](/solution/1600-1699/1692.Count%20Ways%20to%20Distribute%20Candies/README_EN.md)", "`Dynamic Programming`", "Hard", "\ud83d\udd12"]}, {"question_id": "1827", "frontend_question_id": "1683", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/invalid-tweets", "url_en": "https://leetcode.com/problems/invalid-tweets", "relative_path_cn": "/solution/1600-1699/1683.Invalid%20Tweets/README.md", "relative_path_en": "/solution/1600-1699/1683.Invalid%20Tweets/README_EN.md", "title_cn": "\u65e0\u6548\u7684\u63a8\u6587", "title_en": "Invalid Tweets", "question_title_slug": "invalid-tweets", "content_en": "

    Table: Tweets

    \n\n
    \n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| tweet_id       | int     |\n| content        | varchar |\n+----------------+---------+\ntweet_id is the primary key for this table.\nThis table contains all the tweets in a social media app.\n
    \n\n

     

    \n\n

    Write an SQL query to find the IDs of the invalid tweets. The tweet is invalid if the number of characters used in the content of the tweet is strictly greater than 15.

    \n\n

    Return the result table in any order.

    \n\n

    The query result format is in the following example:

    \n\n

     

    \n\n
    \nTweets table:\n+----------+----------------------------------+\n| tweet_id | content                          |\n+----------+----------------------------------+\n| 1        | Vote for Biden                   |\n| 2        | Let us make America great again! |\n+----------+----------------------------------+\n\nResult table:\n+----------+\n| tweet_id |\n+----------+\n| 2        |\n+----------+\nTweet 1 has length = 14. It is a valid tweet.\nTweet 2 has length = 32. It is an invalid tweet.\n
    \n", "content_cn": "

    \u8868\uff1aTweets

    \n\n
    +----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| tweet_id       | int     |\n| content        | varchar |\n+----------------+---------+\ntweet_id \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\u3002\n\u8fd9\u4e2a\u8868\u5305\u542b\u67d0\u793e\u4ea4\u5a92\u4f53 App \u4e2d\u6240\u6709\u7684\u63a8\u6587\u3002
    \n\n

    \u00a0

    \n\n

    \u5199\u4e00\u6761\u00a0SQL \u8bed\u53e5\uff0c\u67e5\u8be2\u6240\u6709\u65e0\u6548\u63a8\u6587\u7684\u7f16\u53f7\uff08ID\uff09\u3002\u5f53\u63a8\u6587\u5185\u5bb9\u4e2d\u7684\u5b57\u7b26\u6570\u4e25\u683c\u5927\u4e8e 15 \u65f6\uff0c\u8be5\u63a8\u6587\u662f\u65e0\u6548\u7684\u3002

    \n\n

    \u4ee5\u4efb\u610f\u987a\u5e8f\u8fd4\u56de\u7ed3\u679c\u8868\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u793a\u4f8b\u6240\u793a\uff1a

    \n\n

    \u00a0

    \n\n
    Tweets \u8868\uff1a\n+----------+----------------------------------+\n| tweet_id | content                          |\n+----------+----------------------------------+\n| 1        | Vote for Biden                   |\n| 2        | Let us make America great again! |\n+----------+----------------------------------+\n\n\u7ed3\u679c\u8868\uff1a\n+----------+\n| tweet_id |\n+----------+\n| 2        |\n+----------+\n\u63a8\u6587 1 \u7684\u957f\u5ea6 length = 14\u3002\u8be5\u63a8\u6587\u662f\u6709\u6548\u7684\u3002\n\u63a8\u6587 2 \u7684\u957f\u5ea6 length = 32\u3002\u8be5\u63a8\u6587\u662f\u65e0\u6548\u7684\u3002\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1683](https://leetcode-cn.com/problems/invalid-tweets)", "[\u65e0\u6548\u7684\u63a8\u6587](/solution/1600-1699/1683.Invalid%20Tweets/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1683](https://leetcode.com/problems/invalid-tweets)", "[Invalid Tweets](/solution/1600-1699/1683.Invalid%20Tweets/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1826", "frontend_question_id": "1707", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-xor-with-an-element-from-array", "url_en": "https://leetcode.com/problems/maximum-xor-with-an-element-from-array", "relative_path_cn": "/solution/1700-1799/1707.Maximum%20XOR%20With%20an%20Element%20From%20Array/README.md", "relative_path_en": "/solution/1700-1799/1707.Maximum%20XOR%20With%20an%20Element%20From%20Array/README_EN.md", "title_cn": "\u4e0e\u6570\u7ec4\u4e2d\u5143\u7d20\u7684\u6700\u5927\u5f02\u6216\u503c", "title_en": "Maximum XOR With an Element From Array", "question_title_slug": "maximum-xor-with-an-element-from-array", "content_en": "

    You are given an array nums consisting of non-negative integers. You are also given a queries array, where queries[i] = [xi, mi].

    \n\n

    The answer to the ith query is the maximum bitwise XOR value of xi and any element of nums that does not exceed mi. In other words, the answer is max(nums[j] XOR xi) for all j such that nums[j] <= mi. If all elements in nums are larger than mi, then the answer is -1.

    \n\n

    Return an integer array answer where answer.length == queries.length and answer[i] is the answer to the ith query.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [0,1,2,3,4], queries = [[3,1],[1,3],[5,6]]\nOutput: [3,3,7]\nExplanation:\n1) 0 and 1 are the only two integers not greater than 1. 0 XOR 3 = 3 and 1 XOR 3 = 2. The larger of the two is 3.\n2) 1 XOR 2 = 3.\n3) 5 XOR 2 = 7.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [5,2,4,6,6,3], queries = [[12,4],[8,1],[6,3]]\nOutput: [15,-1,5]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length, queries.length <= 105
    • \n\t
    • queries[i].length == 2
    • \n\t
    • 0 <= nums[j], xi, mi <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u7531\u975e\u8d1f\u6574\u6570\u7ec4\u6210\u7684\u6570\u7ec4 nums \u3002\u53e6\u6709\u4e00\u4e2a\u67e5\u8be2\u6570\u7ec4 queries \uff0c\u5176\u4e2d queries[i] = [xi, mi] \u3002

    \n\n

    \u7b2c i \u4e2a\u67e5\u8be2\u7684\u7b54\u6848\u662f xi \u548c\u4efb\u4f55 nums \u6570\u7ec4\u4e2d\u4e0d\u8d85\u8fc7 mi \u7684\u5143\u7d20\u6309\u4f4d\u5f02\u6216\uff08XOR\uff09\u5f97\u5230\u7684\u6700\u5927\u503c\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u7b54\u6848\u662f max(nums[j] XOR xi) \uff0c\u5176\u4e2d\u6240\u6709 j \u5747\u6ee1\u8db3 nums[j] <= mi \u3002\u5982\u679c nums \u4e2d\u7684\u6240\u6709\u5143\u7d20\u90fd\u5927\u4e8e mi\uff0c\u6700\u7ec8\u7b54\u6848\u5c31\u662f -1 \u3002

    \n\n

    \u8fd4\u56de\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 answer \u4f5c\u4e3a\u67e5\u8be2\u7684\u7b54\u6848\uff0c\u5176\u4e2d answer.length == queries.length \u4e14 answer[i] \u662f\u7b2c i \u4e2a\u67e5\u8be2\u7684\u7b54\u6848\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [0,1,2,3,4], queries = [[3,1],[1,3],[5,6]]\n\u8f93\u51fa\uff1a[3,3,7]\n\u89e3\u91ca\uff1a\n1) 0 \u548c 1 \u662f\u4ec5\u6709\u7684\u4e24\u4e2a\u4e0d\u8d85\u8fc7 1 \u7684\u6574\u6570\u30020 XOR 3 = 3 \u800c 1 XOR 3 = 2 \u3002\u4e8c\u8005\u4e2d\u7684\u66f4\u5927\u503c\u662f 3 \u3002\n2) 1 XOR 2 = 3.\n3) 5 XOR 2 = 7.\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [5,2,4,6,6,3], queries = [[12,4],[8,1],[6,3]]\n\u8f93\u51fa\uff1a[15,-1,5]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length, queries.length <= 105
    • \n\t
    • queries[i].length == 2
    • \n\t
    • 0 <= nums[j], xi, mi <= 109
    • \n
    \n", "tags_en": ["Bit Manipulation", "Trie"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u5b57\u5178\u6811"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector maximizeXor(vector& nums, vector>& queries) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] maximizeXor(int[] nums, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximizeXor(self, nums, queries):\n \"\"\"\n :type nums: List[int]\n :type queries: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximizeXor(self, nums: List[int], queries: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* maximizeXor(int* nums, int numsSize, int** queries, int queriesSize, int* queriesColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] MaximizeXor(int[] nums, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number[][]} queries\n * @return {number[]}\n */\nvar maximizeXor = function(nums, queries) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer[][]} queries\n# @return {Integer[]}\ndef maximize_xor(nums, queries)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximizeXor(_ nums: [Int], _ queries: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximizeXor(nums []int, queries [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximizeXor(nums: Array[Int], queries: Array[Array[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximizeXor(nums: IntArray, queries: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximize_xor(nums: Vec, queries: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer[][] $queries\n * @return Integer[]\n */\n function maximizeXor($nums, $queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximizeXor(nums: number[], queries: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximize-xor nums queries)\n (-> (listof exact-integer?) (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1707](https://leetcode-cn.com/problems/maximum-xor-with-an-element-from-array)", "[\u4e0e\u6570\u7ec4\u4e2d\u5143\u7d20\u7684\u6700\u5927\u5f02\u6216\u503c](/solution/1700-1799/1707.Maximum%20XOR%20With%20an%20Element%20From%20Array/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u5b57\u5178\u6811`", "\u56f0\u96be", ""], "md_table_row_en": ["[1707](https://leetcode.com/problems/maximum-xor-with-an-element-from-array)", "[Maximum XOR With an Element From Array](/solution/1700-1799/1707.Maximum%20XOR%20With%20an%20Element%20From%20Array/README_EN.md)", "`Bit Manipulation`,`Trie`", "Hard", ""]}, {"question_id": "1825", "frontend_question_id": "1723", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-minimum-time-to-finish-all-jobs", "url_en": "https://leetcode.com/problems/find-minimum-time-to-finish-all-jobs", "relative_path_cn": "/solution/1700-1799/1723.Find%20Minimum%20Time%20to%20Finish%20All%20Jobs/README.md", "relative_path_en": "/solution/1700-1799/1723.Find%20Minimum%20Time%20to%20Finish%20All%20Jobs/README_EN.md", "title_cn": "\u5b8c\u6210\u6240\u6709\u5de5\u4f5c\u7684\u6700\u77ed\u65f6\u95f4", "title_en": "Find Minimum Time to Finish All Jobs", "question_title_slug": "find-minimum-time-to-finish-all-jobs", "content_en": "

    You are given an integer array jobs, where jobs[i] is the amount of time it takes to complete the ith job.

    \n\n

    There are k workers that you can assign jobs to. Each job should be assigned to exactly one worker. The working time of a worker is the sum of the time it takes to complete all jobs assigned to them. Your goal is to devise an optimal assignment such that the maximum working time of any worker is minimized.

    \n\n

    Return the minimum possible maximum working time of any assignment.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: jobs = [3,2,3], k = 3\nOutput: 3\nExplanation: By assigning each person one job, the maximum time is 3.\n
    \n\n

    Example 2:

    \n\n
    \nInput: jobs = [1,2,4,7,8], k = 2\nOutput: 11\nExplanation: Assign the jobs the following way:\nWorker 1: 1, 2, 8 (working time = 1 + 2 + 8 = 11)\nWorker 2: 4, 7 (working time = 4 + 7 = 11)\nThe maximum working time is 11.
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= k <= jobs.length <= 12
    • \n\t
    • 1 <= jobs[i] <= 107
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 jobs \uff0c\u5176\u4e2d jobs[i] \u662f\u5b8c\u6210\u7b2c i \u9879\u5de5\u4f5c\u8981\u82b1\u8d39\u7684\u65f6\u95f4\u3002

    \n\n

    \u8bf7\u4f60\u5c06\u8fd9\u4e9b\u5de5\u4f5c\u5206\u914d\u7ed9 k \u4f4d\u5de5\u4eba\u3002\u6240\u6709\u5de5\u4f5c\u90fd\u5e94\u8be5\u5206\u914d\u7ed9\u5de5\u4eba\uff0c\u4e14\u6bcf\u9879\u5de5\u4f5c\u53ea\u80fd\u5206\u914d\u7ed9\u4e00\u4f4d\u5de5\u4eba\u3002\u5de5\u4eba\u7684 \u5de5\u4f5c\u65f6\u95f4 \u662f\u5b8c\u6210\u5206\u914d\u7ed9\u4ed6\u4eec\u7684\u6240\u6709\u5de5\u4f5c\u82b1\u8d39\u65f6\u95f4\u7684\u603b\u548c\u3002\u8bf7\u4f60\u8bbe\u8ba1\u4e00\u5957\u6700\u4f73\u7684\u5de5\u4f5c\u5206\u914d\u65b9\u6848\uff0c\u4f7f\u5de5\u4eba\u7684 \u6700\u5927\u5de5\u4f5c\u65f6\u95f4 \u5f97\u4ee5 \u6700\u5c0f\u5316 \u3002

    \n\n

    \u8fd4\u56de\u5206\u914d\u65b9\u6848\u4e2d\u5c3d\u53ef\u80fd \u6700\u5c0f \u7684 \u6700\u5927\u5de5\u4f5c\u65f6\u95f4 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1ajobs = [3,2,3], k = 3\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u7ed9\u6bcf\u4f4d\u5de5\u4eba\u5206\u914d\u4e00\u9879\u5de5\u4f5c\uff0c\u6700\u5927\u5de5\u4f5c\u65f6\u95f4\u662f 3 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1ajobs = [1,2,4,7,8], k = 2\n\u8f93\u51fa\uff1a11\n\u89e3\u91ca\uff1a\u6309\u4e0b\u8ff0\u65b9\u5f0f\u5206\u914d\u5de5\u4f5c\uff1a\n1 \u53f7\u5de5\u4eba\uff1a1\u30012\u30018\uff08\u5de5\u4f5c\u65f6\u95f4 = 1 + 2 + 8 = 11\uff09\n2 \u53f7\u5de5\u4eba\uff1a4\u30017\uff08\u5de5\u4f5c\u65f6\u95f4 = 4 + 7 = 11\uff09\n\u6700\u5927\u5de5\u4f5c\u65f6\u95f4\u662f 11 \u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= k <= jobs.length <= 12
    • \n\t
    • 1 <= jobs[i] <= 107
    • \n
    \n", "tags_en": ["Recursion", "Backtracking"], "tags_cn": ["\u9012\u5f52", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minimumTimeRequired(vector& jobs, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minimumTimeRequired(int[] jobs, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimumTimeRequired(self, jobs, k):\n \"\"\"\n :type jobs: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimumTimeRequired(self, jobs: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minimumTimeRequired(int* jobs, int jobsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinimumTimeRequired(int[] jobs, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} jobs\n * @param {number} k\n * @return {number}\n */\nvar minimumTimeRequired = function(jobs, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} jobs\n# @param {Integer} k\n# @return {Integer}\ndef minimum_time_required(jobs, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimumTimeRequired(_ jobs: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimumTimeRequired(jobs []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimumTimeRequired(jobs: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimumTimeRequired(jobs: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimum_time_required(jobs: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $jobs\n * @param Integer $k\n * @return Integer\n */\n function minimumTimeRequired($jobs, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimumTimeRequired(jobs: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimum-time-required jobs k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1723](https://leetcode-cn.com/problems/find-minimum-time-to-finish-all-jobs)", "[\u5b8c\u6210\u6240\u6709\u5de5\u4f5c\u7684\u6700\u77ed\u65f6\u95f4](/solution/1700-1799/1723.Find%20Minimum%20Time%20to%20Finish%20All%20Jobs/README.md)", "`\u9012\u5f52`,`\u56de\u6eaf\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[1723](https://leetcode.com/problems/find-minimum-time-to-finish-all-jobs)", "[Find Minimum Time to Finish All Jobs](/solution/1700-1799/1723.Find%20Minimum%20Time%20to%20Finish%20All%20Jobs/README_EN.md)", "`Recursion`,`Backtracking`", "Hard", ""]}, {"question_id": "1824", "frontend_question_id": "1705", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-number-of-eaten-apples", "url_en": "https://leetcode.com/problems/maximum-number-of-eaten-apples", "relative_path_cn": "/solution/1700-1799/1705.Maximum%20Number%20of%20Eaten%20Apples/README.md", "relative_path_en": "/solution/1700-1799/1705.Maximum%20Number%20of%20Eaten%20Apples/README_EN.md", "title_cn": "\u5403\u82f9\u679c\u7684\u6700\u5927\u6570\u76ee", "title_en": "Maximum Number of Eaten Apples", "question_title_slug": "maximum-number-of-eaten-apples", "content_en": "

    There is a special kind of apple tree that grows apples every day for n days. On the ith day, the tree grows apples[i] apples that will rot after days[i] days, that is on day i + days[i] the apples will be rotten and cannot be eaten. On some days, the apple tree does not grow any apples, which are denoted by apples[i] == 0 and days[i] == 0.

    \n\n

    You decided to eat at most one apple a day (to keep the doctors away). Note that you can keep eating after the first n days.

    \n\n

    Given two integer arrays days and apples of length n, return the maximum number of apples you can eat.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: apples = [1,2,3,5,2], days = [3,2,1,4,2]\nOutput: 7\nExplanation: You can eat 7 apples:\n- On the first day, you eat an apple that grew on the first day.\n- On the second day, you eat an apple that grew on the second day.\n- On the third day, you eat an apple that grew on the second day. After this day, the apples that grew on the third day rot.\n- On the fourth to the seventh days, you eat apples that grew on the fourth day.\n
    \n\n

    Example 2:

    \n\n
    \nInput: apples = [3,0,0,0,0,2], days = [3,0,0,0,0,2]\nOutput: 5\nExplanation: You can eat 5 apples:\n- On the first to the third day you eat apples that grew on the first day.\n- Do nothing on the fouth and fifth days.\n- On the sixth and seventh days you eat apples that grew on the sixth day.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • apples.length == n
    • \n\t
    • days.length == n
    • \n\t
    • 1 <= n <= 2 * 104
    • \n\t
    • 0 <= apples[i], days[i] <= 2 * 104
    • \n\t
    • days[i] = 0 if and only if apples[i] = 0.
    • \n
    \n", "content_cn": "

    \u6709\u4e00\u68f5\u7279\u6b8a\u7684\u82f9\u679c\u6811\uff0c\u4e00\u8fde n \u5929\uff0c\u6bcf\u5929\u90fd\u53ef\u4ee5\u957f\u51fa\u82e5\u5e72\u4e2a\u82f9\u679c\u3002\u5728\u7b2c i \u5929\uff0c\u6811\u4e0a\u4f1a\u957f\u51fa apples[i] \u4e2a\u82f9\u679c\uff0c\u8fd9\u4e9b\u82f9\u679c\u5c06\u4f1a\u5728 days[i] \u5929\u540e\uff08\u4e5f\u5c31\u662f\u8bf4\uff0c\u7b2c i + days[i] \u5929\u65f6\uff09\u8150\u70c2\uff0c\u53d8\u5f97\u65e0\u6cd5\u98df\u7528\u3002\u4e5f\u53ef\u80fd\u6709\u90a3\u4e48\u51e0\u5929\uff0c\u6811\u4e0a\u4e0d\u4f1a\u957f\u51fa\u65b0\u7684\u82f9\u679c\uff0c\u6b64\u65f6\u7528 apples[i] == 0 \u4e14 days[i] == 0 \u8868\u793a\u3002

    \n\n

    \u4f60\u6253\u7b97\u6bcf\u5929 \u6700\u591a \u5403\u4e00\u4e2a\u82f9\u679c\u6765\u4fdd\u8bc1\u8425\u517b\u5747\u8861\u3002\u6ce8\u610f\uff0c\u4f60\u53ef\u4ee5\u5728\u8fd9 n \u5929\u4e4b\u540e\u7ee7\u7eed\u5403\u82f9\u679c\u3002

    \n\n

    \u7ed9\u4f60\u4e24\u4e2a\u957f\u5ea6\u4e3a n \u7684\u6574\u6570\u6570\u7ec4 days \u548c apples \uff0c\u8fd4\u56de\u4f60\u53ef\u4ee5\u5403\u6389\u7684\u82f9\u679c\u7684\u6700\u5927\u6570\u76ee\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aapples = [1,2,3,5,2], days = [3,2,1,4,2]\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u5403\u6389 7 \u4e2a\u82f9\u679c\uff1a\n- \u7b2c\u4e00\u5929\uff0c\u4f60\u5403\u6389\u7b2c\u4e00\u5929\u957f\u51fa\u6765\u7684\u82f9\u679c\u3002\n- \u7b2c\u4e8c\u5929\uff0c\u4f60\u5403\u6389\u4e00\u4e2a\u7b2c\u4e8c\u5929\u957f\u51fa\u6765\u7684\u82f9\u679c\u3002\n- \u7b2c\u4e09\u5929\uff0c\u4f60\u5403\u6389\u4e00\u4e2a\u7b2c\u4e8c\u5929\u957f\u51fa\u6765\u7684\u82f9\u679c\u3002\u8fc7\u4e86\u8fd9\u4e00\u5929\uff0c\u7b2c\u4e09\u5929\u957f\u51fa\u6765\u7684\u82f9\u679c\u5c31\u5df2\u7ecf\u8150\u70c2\u4e86\u3002\n- \u7b2c\u56db\u5929\u5230\u7b2c\u4e03\u5929\uff0c\u4f60\u5403\u7684\u90fd\u662f\u7b2c\u56db\u5929\u957f\u51fa\u6765\u7684\u82f9\u679c\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aapples = [3,0,0,0,0,2], days = [3,0,0,0,0,2]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u5403\u6389 5 \u4e2a\u82f9\u679c\uff1a\n- \u7b2c\u4e00\u5929\u5230\u7b2c\u4e09\u5929\uff0c\u4f60\u5403\u7684\u90fd\u662f\u7b2c\u4e00\u5929\u957f\u51fa\u6765\u7684\u82f9\u679c\u3002\n- \u7b2c\u56db\u5929\u548c\u7b2c\u4e94\u5929\u4e0d\u5403\u82f9\u679c\u3002\n- \u7b2c\u516d\u5929\u548c\u7b2c\u4e03\u5929\uff0c\u4f60\u5403\u7684\u90fd\u662f\u7b2c\u516d\u5929\u957f\u51fa\u6765\u7684\u82f9\u679c\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • apples.length == n
    • \n\t
    • days.length == n
    • \n\t
    • 1 <= n <= 2 * 104
    • \n\t
    • 0 <= apples[i], days[i] <= 2 * 104
    • \n\t
    • \u53ea\u6709\u5728 apples[i] = 0 \u65f6\uff0cdays[i] = 0 \u624d\u6210\u7acb
    • \n
    \n", "tags_en": ["Heap", "Greedy"], "tags_cn": ["\u5806", "\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int eatenApples(vector& apples, vector& days) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int eatenApples(int[] apples, int[] days) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def eatenApples(self, apples, days):\n \"\"\"\n :type apples: List[int]\n :type days: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def eatenApples(self, apples: List[int], days: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint eatenApples(int* apples, int applesSize, int* days, int daysSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int EatenApples(int[] apples, int[] days) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} apples\n * @param {number[]} days\n * @return {number}\n */\nvar eatenApples = function(apples, days) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} apples\n# @param {Integer[]} days\n# @return {Integer}\ndef eaten_apples(apples, days)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func eatenApples(_ apples: [Int], _ days: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func eatenApples(apples []int, days []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def eatenApples(apples: Array[Int], days: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun eatenApples(apples: IntArray, days: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn eaten_apples(apples: Vec, days: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $apples\n * @param Integer[] $days\n * @return Integer\n */\n function eatenApples($apples, $days) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function eatenApples(apples: number[], days: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (eaten-apples apples days)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1705](https://leetcode-cn.com/problems/maximum-number-of-eaten-apples)", "[\u5403\u82f9\u679c\u7684\u6700\u5927\u6570\u76ee](/solution/1700-1799/1705.Maximum%20Number%20of%20Eaten%20Apples/README.md)", "`\u5806`,`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1705](https://leetcode.com/problems/maximum-number-of-eaten-apples)", "[Maximum Number of Eaten Apples](/solution/1700-1799/1705.Maximum%20Number%20of%20Eaten%20Apples/README_EN.md)", "`Heap`,`Greedy`", "Medium", ""]}, {"question_id": "1823", "frontend_question_id": "1704", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/determine-if-string-halves-are-alike", "url_en": "https://leetcode.com/problems/determine-if-string-halves-are-alike", "relative_path_cn": "/solution/1700-1799/1704.Determine%20if%20String%20Halves%20Are%20Alike/README.md", "relative_path_en": "/solution/1700-1799/1704.Determine%20if%20String%20Halves%20Are%20Alike/README_EN.md", "title_cn": "\u5224\u65ad\u5b57\u7b26\u4e32\u7684\u4e24\u534a\u662f\u5426\u76f8\u4f3c", "title_en": "Determine if String Halves Are Alike", "question_title_slug": "determine-if-string-halves-are-alike", "content_en": "

    You are given a string s of even length. Split this string into two halves of equal lengths, and let a be the first half and b be the second half.

    \n\n

    Two strings are alike if they have the same number of vowels ('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'). Notice that s contains uppercase and lowercase letters.

    \n\n

    Return true if a and b are alike. Otherwise, return false.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "book"\nOutput: true\nExplanation: a = "bo" and b = "ok". a has 1 vowel and b has 1 vowel. Therefore, they are alike.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "textbook"\nOutput: false\nExplanation: a = "text" and b = "book". a has 1 vowel whereas b has 2. Therefore, they are not alike.\nNotice that the vowel o is counted twice.\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "MerryChristmas"\nOutput: false\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "AbCdEfGh"\nOutput: true\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= s.length <= 1000
    • \n\t
    • s.length is even.
    • \n\t
    • s consists of uppercase and lowercase letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5076\u6570\u957f\u5ea6\u7684\u5b57\u7b26\u4e32 s \u3002\u5c06\u5176\u62c6\u5206\u6210\u957f\u5ea6\u76f8\u540c\u7684\u4e24\u534a\uff0c\u524d\u4e00\u534a\u4e3a a \uff0c\u540e\u4e00\u534a\u4e3a b \u3002

    \n\n

    \u4e24\u4e2a\u5b57\u7b26\u4e32 \u76f8\u4f3c \u7684\u524d\u63d0\u662f\u5b83\u4eec\u90fd\u542b\u6709\u76f8\u540c\u6570\u76ee\u7684\u5143\u97f3\uff08'a'\uff0c'e'\uff0c'i'\uff0c'o'\uff0c'u'\uff0c'A'\uff0c'E'\uff0c'I'\uff0c'O'\uff0c'U'\uff09\u3002\u6ce8\u610f\uff0cs \u53ef\u80fd\u540c\u65f6\u542b\u6709\u5927\u5199\u548c\u5c0f\u5199\u5b57\u6bcd\u3002

    \n\n

    \u5982\u679c a \u548c b \u76f8\u4f3c\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1as = \"book\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1aa = \"bo\" \u4e14 b = \"ok\" \u3002a \u4e2d\u6709 1 \u4e2a\u5143\u97f3\uff0cb \u4e5f\u6709 1 \u4e2a\u5143\u97f3\u3002\u6240\u4ee5\uff0ca \u548c b \u76f8\u4f3c\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1as = \"textbook\"\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1aa = \"text\" \u4e14 b = \"book\" \u3002a \u4e2d\u6709 1 \u4e2a\u5143\u97f3\uff0cb \u4e2d\u6709 2 \u4e2a\u5143\u97f3\u3002\u56e0\u6b64\uff0ca \u548c b \u4e0d\u76f8\u4f3c\u3002\n\u6ce8\u610f\uff0c\u5143\u97f3 o \u5728 b \u4e2d\u51fa\u73b0\u4e24\u6b21\uff0c\u8bb0\u4e3a 2 \u4e2a\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1as = \"MerryChristmas\"\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1as = \"AbCdEfGh\"\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= s.length <= 1000
    • \n\t
    • s.length \u662f\u5076\u6570
    • \n\t
    • s \u7531 \u5927\u5199\u548c\u5c0f\u5199 \u5b57\u6bcd\u7ec4\u6210
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool halvesAreAlike(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean halvesAreAlike(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def halvesAreAlike(self, s):\n \"\"\"\n :type s: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def halvesAreAlike(self, s: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool halvesAreAlike(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool HalvesAreAlike(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {boolean}\n */\nvar halvesAreAlike = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Boolean}\ndef halves_are_alike(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func halvesAreAlike(_ s: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func halvesAreAlike(s string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def halvesAreAlike(s: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun halvesAreAlike(s: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn halves_are_alike(s: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Boolean\n */\n function halvesAreAlike($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function halvesAreAlike(s: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (halves-are-alike s)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1704](https://leetcode-cn.com/problems/determine-if-string-halves-are-alike)", "[\u5224\u65ad\u5b57\u7b26\u4e32\u7684\u4e24\u534a\u662f\u5426\u76f8\u4f3c](/solution/1700-1799/1704.Determine%20if%20String%20Halves%20Are%20Alike/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1704](https://leetcode.com/problems/determine-if-string-halves-are-alike)", "[Determine if String Halves Are Alike](/solution/1700-1799/1704.Determine%20if%20String%20Halves%20Are%20Alike/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1822", "frontend_question_id": "1682", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/longest-palindromic-subsequence-ii", "url_en": "https://leetcode.com/problems/longest-palindromic-subsequence-ii", "relative_path_cn": "/solution/1600-1699/1682.Longest%20Palindromic%20Subsequence%20II/README.md", "relative_path_en": "/solution/1600-1699/1682.Longest%20Palindromic%20Subsequence%20II/README_EN.md", "title_cn": "\u6700\u957f\u56de\u6587\u5b50\u5e8f\u5217 II", "title_en": "Longest Palindromic Subsequence II", "question_title_slug": "longest-palindromic-subsequence-ii", "content_en": "

    A subsequence of a string s is considered a good palindromic subsequence if:

    \r\n\r\n
      \r\n\t
    • It is a subsequence of s.
    • \r\n\t
    • It is a palindrome (has the same value if reversed).
    • \r\n\t
    • It has an even length.
    • \r\n\t
    • No two consecutive characters are equal, except the two middle ones.
    • \r\n
    \r\n\r\n

    For example, if s = "abcabcabb", then "abba" is considered a good palindromic subsequence, while "bcb" (not even length) and "bbbb" (has equal consecutive characters) are not.

    \r\n\r\n

    Given a string s, return the length of the longest good palindromic subsequence in s.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: s = "bbabab"\r\nOutput: 4\r\nExplanation: The longest good palindromic subsequence of s is "baab".\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: s = "dcbccacdb"\r\nOutput: 4\r\nExplanation: The longest good palindromic subsequence of s is "dccd".\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= s.length <= 250
    • \r\n\t
    • s consists of lowercase English letters.
    • \r\n
    ", "content_cn": "

    \u5b57\u7b26\u4e32\u00a0s\u00a0\u7684\u67d0\u4e2a\u5b50\u5e8f\u5217\u7b26\u5408\u4e0b\u5217\u6761\u4ef6\u65f6\uff0c\u79f0\u4e3a\u201c\u597d\u7684\u56de\u6587\u5b50\u5e8f\u5217\u201d\uff1a

    \n\n
      \n\t
    • \u5b83\u662f\u00a0s\u00a0\u7684\u5b50\u5e8f\u5217\u3002
    • \n\t
    • \u5b83\u662f\u56de\u6587\u5e8f\u5217\uff08\u53cd\u8f6c\u540e\u4e0e\u539f\u5e8f\u5217\u76f8\u7b49\uff09\u3002
    • \n\t
    • \u957f\u5ea6\u4e3a\u5076\u6570\u3002
    • \n\t
    • \u9664\u4e2d\u95f4\u7684\u4e24\u4e2a\u5b57\u7b26\u5916\uff0c\u5176\u4f59\u4efb\u610f\u4e24\u4e2a\u8fde\u7eed\u5b57\u7b26\u4e0d\u76f8\u7b49\u3002
    • \n
    \n\n

    \u4f8b\u5982\uff0c\u82e5\u00a0s = \"abcabcabb\"\uff0c\u5219\u00a0\"abba\"\u00a0\u53ef\u79f0\u4e3a\u201c\u597d\u7684\u56de\u6587\u5b50\u5e8f\u5217\u201d\uff0c\u800c\u00a0\"bcb\"\u00a0\uff08\u957f\u5ea6\u4e0d\u662f\u5076\u6570\uff09\u548c\u00a0\"bbbb\"\u00a0\uff08\u542b\u6709\u76f8\u7b49\u7684\u8fde\u7eed\u5b57\u7b26\uff09\u4e0d\u80fd\u79f0\u4e3a\u201c\u597d\u7684\u56de\u6587\u5b50\u5e8f\u5217\u201d\u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\u00a0s\uff0c \u8fd4\u56de\u00a0s\u00a0\u7684\u6700\u957f\u201c\u597d\u7684\u56de\u6587\u5b50\u5e8f\u5217\u201d\u7684\u957f\u5ea6\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: s = \"bbabab\"\n\u8f93\u51fa: 4\n\u89e3\u91ca: s \u7684\u6700\u957f\u201c\u597d\u7684\u56de\u6587\u5b50\u5e8f\u5217\u201d\u662f \"baab\"\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: s = \"dcbccacdb\"\n\u8f93\u51fa: 4\n\u89e3\u91ca: The longest good palindromic subsequence of s is \"dccd\".\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a:

    \n\n
      \n\t
    • 1 <= s.length <= 250
    • \n\t
    • s\u00a0\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    • \n
    \n", "tags_en": ["String", "Dynamic Programming"], "tags_cn": ["\u5b57\u7b26\u4e32", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int longestPalindromeSubseq(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int longestPalindromeSubseq(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestPalindromeSubseq(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestPalindromeSubseq(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint longestPalindromeSubseq(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LongestPalindromeSubseq(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar longestPalindromeSubseq = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef longest_palindrome_subseq(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestPalindromeSubseq(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestPalindromeSubseq(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestPalindromeSubseq(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestPalindromeSubseq(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_palindrome_subseq(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function longestPalindromeSubseq($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestPalindromeSubseq(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-palindrome-subseq s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1682](https://leetcode-cn.com/problems/longest-palindromic-subsequence-ii)", "[\u6700\u957f\u56de\u6587\u5b50\u5e8f\u5217 II](/solution/1600-1699/1682.Longest%20Palindromic%20Subsequence%20II/README.md)", "`\u5b57\u7b26\u4e32`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1682](https://leetcode.com/problems/longest-palindromic-subsequence-ii)", "[Longest Palindromic Subsequence II](/solution/1600-1699/1682.Longest%20Palindromic%20Subsequence%20II/README_EN.md)", "`String`,`Dynamic Programming`", "Medium", "\ud83d\udd12"]}, {"question_id": "1821", "frontend_question_id": "1677", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/products-worth-over-invoices", "url_en": "https://leetcode.com/problems/products-worth-over-invoices", "relative_path_cn": "/solution/1600-1699/1677.Product%27s%20Worth%20Over%20Invoices/README.md", "relative_path_en": "/solution/1600-1699/1677.Product%27s%20Worth%20Over%20Invoices/README_EN.md", "title_cn": "\u53d1\u7968\u4e2d\u7684\u4ea7\u54c1\u91d1\u989d", "title_en": "Product's Worth Over Invoices", "question_title_slug": "products-worth-over-invoices", "content_en": "

    Table: Product

    \n\n
    \n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| product_id  | int     |\n| name        | varchar |\n+-------------+---------+\nproduct_id is the primary key for this table.\nThis table contains the ID and the name of the product. The name consists of only lowercase English letters. No two products have the same name.\n
    \n\n

     

    \n\n

    Table: Invoice

    \n\n
    \n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| invoice_id  | int  |\n| product_id  | int  |\n| rest        | int  |\n| paid        | int  |\n| canceled    | int  |\n| refunded    | int  |\n+-------------+------+\ninvoice_id is the primary key for this table and the id of this invoice.\nproduct_id is the id of the product for this invoice.\nrest is the amount left to pay for this invoice.\npaid is the amount paid for this invoice.\ncanceled is the amount canceled for this invoice.\nrefunded is the amount refunded for this invoice.\n
    \n\n

     

    \n\n

    Write an SQL query that will, for all products, return each product name with total amount due, paid, canceled, and refunded across all invoices.

    \n\n

    Return the result table ordered by product_name.

    \n\n

    The query result format is in the following example:

    \n\n

     

    \n\n
    \nProduct table:\n+------------+-------+\n| product_id | name  |\n+------------+-------+\n| 0          | ham   |\n| 1          | bacon |\n+------------+-------+\nInvoice table:\n+------------+------------+------+------+----------+----------+\n| invoice_id | product_id | rest | paid | canceled | refunded |\n+------------+------------+------+------+----------+----------+\n| 23         | 0          | 2    | 0    | 5        | 0        |\n| 12         | 0          | 0    | 4    | 0        | 3        |\n| 1          | 1          | 1    | 1    | 0        | 1        |\n| 2          | 1          | 1    | 0    | 1        | 1        |\n| 3          | 1          | 0    | 1    | 1        | 1        |\n| 4          | 1          | 1    | 1    | 1        | 0        |\n+------------+------------+------+------+----------+----------+\nResult table:\n+-------+------+------+----------+----------+\n| name  | rest | paid | canceled | refunded |\n+-------+------+------+----------+----------+\n| bacon | 3    | 3    | 3        | 3        |\n| ham   | 2    | 4    | 5        | 3        |\n+-------+------+------+----------+----------+\n- The amount of money left to pay for bacon is 1 + 1 + 0 + 1 = 3\n- The amount of money paid for bacon is 1 + 0 + 1 + 1 = 3\n- The amount of money canceled for bacon is 0 + 1 + 1 + 1 = 3\n- The amount of money refunded for bacon is 1 + 1 + 1 + 0 = 3\n- The amount of money left to pay for ham is 2 + 0 = 2\n- The amount of money paid for ham is 0 + 4 = 4\n- The amount of money canceled for ham is 5 + 0 = 5\n- The amount of money refunded for ham is 0 + 3 = 3\n
    \n", "content_cn": "

    Product \u8868\uff1a

    \n\n
    \n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| product_id  | int     |\n| name        | varchar |\n+-------------+---------+\nproduct_id \u662f\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\n\u8868\u4e2d\u542b\u6709\u4ea7\u54c1 id \u3001\u4ea7\u54c1\u540d\u79f0\u3002\u4ea7\u54c1\u540d\u79f0\u90fd\u662f\u5c0f\u5199\u7684\u82f1\u6587\u5b57\u6bcd\uff0c\u4ea7\u54c1\u540d\u79f0\u90fd\u662f\u552f\u4e00\u7684\n
    \n\n

    \u00a0

    \n\n

    Invoice \u8868\uff1a

    \n\n
    \n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| invoice_id  | int  |\n| product_id  | int  |\n| rest        | int  |\n| paid        | int  |\n| canceled    | int  |\n| refunded    | int  |\n+-------------+------+\ninvoice_id \u53d1\u7968 id \uff0c\u662f\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\nproduct_id \u4ea7\u54c1 id\nrest \u5e94\u7f34\u6b3e\u9879\npaid \u5df2\u652f\u4ed8\u91d1\u989d\ncanceled \u5df2\u53d6\u6d88\u91d1\u989d\nrefunded \u5df2\u9000\u6b3e\u91d1\u989d\n
    \n\n

    \u00a0

    \n\n

    \u8981\u6c42\u5199\u4e00\u4e2aSQL\u67e5\u8be2\uff0c\u8fd4\u56de\u5168\u90e8\u53d1\u7968\u4e2d\u6bcf\u4e2a\u4ea7\u54c1\u7684\u4ea7\u54c1\u540d\u79f0\u3001\u603b\u5e94\u7f34\u6b3e\u9879\u3001\u603b\u5df2\u652f\u4ed8\u91d1\u989d\u3001\u603b\u5df2\u53d6\u6d88\u91d1\u989d\u3001\u603b\u5df2\u9000\u6b3e\u91d1\u989d

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u6309 product_name\u6392\u5e8f

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \nProduct \u8868\uff1a\n+------------+-------+\n| product_id | name  |\n+------------+-------+\n| 0          | ham   |\n| 1          | bacon |\n+------------+-------+\nInvoice table:\n+------------+------------+------+------+----------+----------+\n| invoice_id | product_id | rest | paid | canceled | refunded |\n+------------+------------+------+------+----------+----------+\n| 23         | 0          | 2    | 0    | 5        | 0        |\n| 12         | 0          | 0    | 4    | 0        | 3        |\n| 1          | 1          | 1    | 1    | 0        | 1        |\n| 2          | 1          | 1    | 0    | 1        | 1        |\n| 3          | 1          | 0    | 1    | 1        | 1        |\n| 4          | 1          | 1    | 1    | 1        | 0        |\n+------------+------------+------+------+----------+----------+\nResult \u8868\uff1a\n+-------+------+------+----------+----------+\n| name  | rest | paid | canceled | refunded |\n+-------+------+------+----------+----------+\n| bacon | 3    | 3    | 3        | 3        |\n| ham   | 2    | 4    | 5        | 3        |\n+-------+------+------+----------+----------+\n- bacon \u7684\u603b\u5e94\u7f34\u6b3e\u9879\u4e3a 1 + 1 + 0 + 1 = 3\n- bacon \u7684\u603b\u5df2\u652f\u4ed8\u91d1\u989d\u4e3a 1 + 0 + 1 + 1 = 3\n- bacon \u7684\u603b\u5df2\u53d6\u6d88\u91d1\u989d\u4e3a 0 + 1 + 1 + 1 = 3\n- bacon \u7684\u603b\u5df2\u9000\u6b3e\u91d1\u989d\u4e3a 1 + 1 + 1 + 0 = 3\n- ham \u7684\u603b\u5e94\u7f34\u6b3e\u9879\u4e3a 2 + 0 = 2\n- ham \u7684\u603b\u5df2\u652f\u4ed8\u91d1\u989d\u4e3a 0 + 4 = 4\n- ham \u7684\u603b\u5df2\u53d6\u6d88\u91d1\u989d\u4e3a 5 + 0 = 5\n- ham \u7684\u603b\u5df2\u9000\u6b3e\u91d1\u989d\u4e3a 0 + 3 = 3\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1677](https://leetcode-cn.com/problems/products-worth-over-invoices)", "[\u53d1\u7968\u4e2d\u7684\u4ea7\u54c1\u91d1\u989d](/solution/1600-1699/1677.Product%27s%20Worth%20Over%20Invoices/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1677](https://leetcode.com/problems/products-worth-over-invoices)", "[Product's Worth Over Invoices](/solution/1600-1699/1677.Product%27s%20Worth%20Over%20Invoices/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1820", "frontend_question_id": "1719", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-ways-to-reconstruct-a-tree", "url_en": "https://leetcode.com/problems/number-of-ways-to-reconstruct-a-tree", "relative_path_cn": "/solution/1700-1799/1719.Number%20Of%20Ways%20To%20Reconstruct%20A%20Tree/README.md", "relative_path_en": "/solution/1700-1799/1719.Number%20Of%20Ways%20To%20Reconstruct%20A%20Tree/README_EN.md", "title_cn": "\u91cd\u6784\u4e00\u68f5\u6811\u7684\u65b9\u6848\u6570", "title_en": "Number Of Ways To Reconstruct A Tree", "question_title_slug": "number-of-ways-to-reconstruct-a-tree", "content_en": "

    You are given an array pairs, where pairs[i] = [xi, yi], and:

    \n\n
      \n\t
    • There are no duplicates.
    • \n\t
    • xi < yi
    • \n
    \n\n

    Let ways be the number of rooted trees that satisfy the following conditions:

    \n\n
      \n\t
    • The tree consists of nodes whose values appeared in pairs.
    • \n\t
    • A pair [xi, yi] exists in pairs if and only if xi is an ancestor of yi or yi is an ancestor of xi.
    • \n\t
    • Note: the tree does not have to be a binary tree.
    • \n
    \n\n

    Two ways are considered to be different if there is at least one node that has different parents in both ways.

    \n\n

    Return:

    \n\n
      \n\t
    • 0 if ways == 0
    • \n\t
    • 1 if ways == 1
    • \n\t
    • 2 if ways > 1
    • \n
    \n\n

    A rooted tree is a tree that has a single root node, and all edges are oriented to be outgoing from the root.

    \n\n

    An ancestor of a node is any node on the path from the root to that node (excluding the node itself). The root has no ancestors.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: pairs = [[1,2],[2,3]]\nOutput: 1\nExplanation: There is exactly one valid rooted tree, which is shown in the above figure.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: pairs = [[1,2],[2,3],[1,3]]\nOutput: 2\nExplanation: There are multiple valid rooted trees. Three of them are shown in the above figures.\n
    \n\n

    Example 3:

    \n\n
    \nInput: pairs = [[1,2],[2,3],[2,4],[1,5]]\nOutput: 0\nExplanation: There are no valid rooted trees.
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= pairs.length <= 105
    • \n\t
    • 1 <= xi < yi <= 500
    • \n\t
    • The elements in pairs are unique.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4\u00a0pairs \uff0c\u5176\u4e2d\u00a0pairs[i] = [xi, yi]\u00a0\uff0c\u5e76\u4e14\u6ee1\u8db3\uff1a

    \n\n
      \n\t
    • pairs\u00a0\u4e2d\u6ca1\u6709\u91cd\u590d\u5143\u7d20
    • \n\t
    • xi < yi
    • \n
    \n\n

    \u4ee4\u00a0ways\u00a0\u4e3a\u6ee1\u8db3\u4e0b\u9762\u6761\u4ef6\u7684\u6709\u6839\u6811\u7684\u65b9\u6848\u6570\uff1a

    \n\n
      \n\t
    • \u6811\u6240\u5305\u542b\u7684\u6240\u6709\u8282\u70b9\u503c\u90fd\u5728 pairs\u00a0\u4e2d\u3002
    • \n\t
    • \u4e00\u4e2a\u6570\u5bf9\u00a0[xi, yi] \u51fa\u73b0\u5728\u00a0pairs\u00a0\u4e2d\u00a0\u5f53\u4e14\u4ec5\u5f53\u00a0xi\u00a0\u662f\u00a0yi\u00a0\u7684\u7956\u5148\u6216\u8005\u00a0yi\u00a0\u662f\u00a0xi\u00a0\u7684\u7956\u5148\u3002
    • \n\t
    • \u6ce8\u610f\uff1a\u6784\u9020\u51fa\u6765\u7684\u6811\u4e0d\u4e00\u5b9a\u662f\u4e8c\u53c9\u6811\u3002
    • \n
    \n\n

    \u4e24\u68f5\u6811\u88ab\u89c6\u4e3a\u4e0d\u540c\u7684\u65b9\u6848\u5f53\u5b58\u5728\u81f3\u5c11\u4e00\u4e2a\u8282\u70b9\u5728\u4e24\u68f5\u6811\u4e2d\u6709\u4e0d\u540c\u7684\u7236\u8282\u70b9\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\uff1a

    \n\n
      \n\t
    • \u5982\u679c\u00a0ways == 0\u00a0\uff0c\u8fd4\u56de\u00a00\u00a0\u3002
    • \n\t
    • \u5982\u679c\u00a0ways == 1\u00a0\uff0c\u8fd4\u56de 1\u00a0\u3002
    • \n\t
    • \u5982\u679c\u00a0ways > 1\u00a0\uff0c\u8fd4\u56de\u00a02\u00a0\u3002
    • \n
    \n\n

    \u4e00\u68f5 \u6709\u6839\u6811\u00a0\u6307\u7684\u662f\u53ea\u6709\u4e00\u4e2a\u6839\u8282\u70b9\u7684\u6811\uff0c\u6240\u6709\u8fb9\u90fd\u662f\u4ece\u6839\u5f80\u5916\u7684\u65b9\u5411\u3002

    \n\n

    \u6211\u4eec\u79f0\u4ece\u6839\u5230\u4e00\u4e2a\u8282\u70b9\u8def\u5f84\u4e0a\u7684\u4efb\u610f\u4e00\u4e2a\u8282\u70b9\uff08\u9664\u53bb\u8282\u70b9\u672c\u8eab\uff09\u90fd\u662f\u8be5\u8282\u70b9\u7684 \u7956\u5148\u00a0\u3002\u6839\u8282\u70b9\u6ca1\u6709\u7956\u5148\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1apairs = [[1,2],[2,3]]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u5982\u4e0a\u56fe\u6240\u793a\uff0c\u6709\u4e14\u53ea\u6709\u4e00\u4e2a\u7b26\u5408\u89c4\u5b9a\u7684\u6709\u6839\u6811\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1apairs = [[1,2],[2,3],[1,3]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6709\u591a\u4e2a\u7b26\u5408\u89c4\u5b9a\u7684\u6709\u6839\u6811\uff0c\u5176\u4e2d\u4e09\u4e2a\u5982\u4e0a\u56fe\u6240\u793a\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1apairs = [[1,2],[2,3],[2,4],[1,5]]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6ca1\u6709\u7b26\u5408\u89c4\u5b9a\u7684\u6709\u6839\u6811\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= pairs.length <= 105
    • \n\t
    • 1 <= xi < yi <= 500
    • \n\t
    • pairs\u00a0\u4e2d\u7684\u5143\u7d20\u4e92\u4e0d\u76f8\u540c\u3002
    • \n
    \n", "tags_en": ["Tree", "Graph"], "tags_cn": ["\u6811", "\u56fe"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int checkWays(vector>& pairs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int checkWays(int[][] pairs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def checkWays(self, pairs):\n \"\"\"\n :type pairs: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def checkWays(self, pairs: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint checkWays(int** pairs, int pairsSize, int* pairsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CheckWays(int[][] pairs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} pairs\n * @return {number}\n */\nvar checkWays = function(pairs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} pairs\n# @return {Integer}\ndef check_ways(pairs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func checkWays(_ pairs: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func checkWays(pairs [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def checkWays(pairs: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun checkWays(pairs: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn check_ways(pairs: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $pairs\n * @return Integer\n */\n function checkWays($pairs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function checkWays(pairs: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (check-ways pairs)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1719](https://leetcode-cn.com/problems/number-of-ways-to-reconstruct-a-tree)", "[\u91cd\u6784\u4e00\u68f5\u6811\u7684\u65b9\u6848\u6570](/solution/1700-1799/1719.Number%20Of%20Ways%20To%20Reconstruct%20A%20Tree/README.md)", "`\u6811`,`\u56fe`", "\u56f0\u96be", ""], "md_table_row_en": ["[1719](https://leetcode.com/problems/number-of-ways-to-reconstruct-a-tree)", "[Number Of Ways To Reconstruct A Tree](/solution/1700-1799/1719.Number%20Of%20Ways%20To%20Reconstruct%20A%20Tree/README_EN.md)", "`Tree`,`Graph`", "Hard", ""]}, {"question_id": "1819", "frontend_question_id": "1718", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/construct-the-lexicographically-largest-valid-sequence", "url_en": "https://leetcode.com/problems/construct-the-lexicographically-largest-valid-sequence", "relative_path_cn": "/solution/1700-1799/1718.Construct%20the%20Lexicographically%20Largest%20Valid%20Sequence/README.md", "relative_path_en": "/solution/1700-1799/1718.Construct%20the%20Lexicographically%20Largest%20Valid%20Sequence/README_EN.md", "title_cn": "\u6784\u5efa\u5b57\u5178\u5e8f\u6700\u5927\u7684\u53ef\u884c\u5e8f\u5217", "title_en": "Construct the Lexicographically Largest Valid Sequence", "question_title_slug": "construct-the-lexicographically-largest-valid-sequence", "content_en": "

    Given an integer n, find a sequence that satisfies all of the following:

    \n\n
      \n\t
    • The integer 1 occurs once in the sequence.
    • \n\t
    • Each integer between 2 and n occurs twice in the sequence.
    • \n\t
    • For every integer i between 2 and n, the distance between the two occurrences of i is exactly i.
    • \n
    \n\n

    The distance between two numbers on the sequence, a[i] and a[j], is the absolute difference of their indices, |j - i|.

    \n\n

    Return the lexicographically largest sequence. It is guaranteed that under the given constraints, there is always a solution.

    \n\n

    A sequence a is lexicographically larger than a sequence b (of the same length) if in the first position where a and b differ, sequence a has a number greater than the corresponding number in b. For example, [0,1,9,0] is lexicographically larger than [0,1,5,6] because the first position they differ is at the third number, and 9 is greater than 5.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 3\nOutput: [3,1,2,3,2]\nExplanation: [2,3,2,1,3] is also a valid sequence, but [3,1,2,3,2] is the lexicographically largest valid sequence.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 5\nOutput: [5,3,1,4,3,5,2,4,2]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 20
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u00a0n\u00a0\uff0c\u8bf7\u4f60\u627e\u5230\u6ee1\u8db3\u4e0b\u9762\u6761\u4ef6\u7684\u4e00\u4e2a\u5e8f\u5217\uff1a

    \n\n
      \n\t
    • \u6574\u6570\u00a01\u00a0\u5728\u5e8f\u5217\u4e2d\u53ea\u51fa\u73b0\u4e00\u6b21\u3002
    • \n\t
    • 2\u00a0\u5230\u00a0n\u00a0\u4e4b\u95f4\u6bcf\u4e2a\u6574\u6570\u90fd\u6070\u597d\u51fa\u73b0\u4e24\u6b21\u3002
    • \n\t
    • \u5bf9\u4e8e\u6bcf\u4e2a\u00a02\u00a0\u5230\u00a0n\u00a0\u4e4b\u95f4\u7684\u6574\u6570\u00a0i\u00a0\uff0c\u4e24\u4e2a\u00a0i\u00a0\u4e4b\u95f4\u51fa\u73b0\u7684\u8ddd\u79bb\u6070\u597d\u4e3a\u00a0i\u00a0\u3002
    • \n
    \n\n

    \u5e8f\u5217\u91cc\u9762\u4e24\u4e2a\u6570 a[i]\u00a0\u548c a[j]\u00a0\u4e4b\u95f4\u7684 \u8ddd\u79bb\u00a0\uff0c\u6211\u4eec\u5b9a\u4e49\u4e3a\u5b83\u4eec\u4e0b\u6807\u7edd\u5bf9\u503c\u4e4b\u5dee\u00a0|j - i|\u00a0\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u6ee1\u8db3\u4e0a\u8ff0\u6761\u4ef6\u4e2d\u00a0\u5b57\u5178\u5e8f\u6700\u5927\u00a0\u7684\u5e8f\u5217\u3002\u9898\u76ee\u4fdd\u8bc1\u5728\u7ed9\u5b9a\u9650\u5236\u6761\u4ef6\u4e0b\uff0c\u4e00\u5b9a\u5b58\u5728\u89e3\u3002

    \n\n

    \u4e00\u4e2a\u5e8f\u5217\u00a0a\u00a0\u88ab\u8ba4\u4e3a\u6bd4\u5e8f\u5217\u00a0b\u00a0\uff08\u4e24\u8005\u957f\u5ea6\u76f8\u540c\uff09\u5b57\u5178\u5e8f\u66f4\u5927\u7684\u6761\u4ef6\u662f\uff1a\u00a0a \u548c\u00a0b\u00a0\u4e2d\u7b2c\u4e00\u4e2a\u4e0d\u4e00\u6837\u7684\u6570\u5b57\u5904\uff0ca\u00a0\u5e8f\u5217\u7684\u6570\u5b57\u6bd4\u00a0b\u00a0\u5e8f\u5217\u7684\u6570\u5b57\u5927\u3002\u6bd4\u65b9\u8bf4\uff0c[0,1,9,0]\u00a0\u6bd4\u00a0[0,1,5,6]\u00a0\u5b57\u5178\u5e8f\u66f4\u5927\uff0c\u56e0\u4e3a\u7b2c\u4e00\u4e2a\u4e0d\u540c\u7684\u4f4d\u7f6e\u662f\u7b2c\u4e09\u4e2a\u6570\u5b57\uff0c\u4e14\u00a09\u00a0\u6bd4\u00a05\u00a0\u5927\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1an = 3\n\u8f93\u51fa\uff1a[3,1,2,3,2]\n\u89e3\u91ca\uff1a[2,3,2,1,3] \u4e5f\u662f\u4e00\u4e2a\u53ef\u884c\u7684\u5e8f\u5217\uff0c\u4f46\u662f [3,1,2,3,2] \u662f\u5b57\u5178\u5e8f\u6700\u5927\u7684\u5e8f\u5217\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1an = 5\n\u8f93\u51fa\uff1a[5,3,1,4,3,5,2,4,2]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 20
    • \n
    \n", "tags_en": ["Recursion", "Backtracking"], "tags_cn": ["\u9012\u5f52", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector constructDistancedSequence(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] constructDistancedSequence(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def constructDistancedSequence(self, n):\n \"\"\"\n :type n: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def constructDistancedSequence(self, n: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* constructDistancedSequence(int n, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] ConstructDistancedSequence(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number[]}\n */\nvar constructDistancedSequence = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer[]}\ndef construct_distanced_sequence(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func constructDistancedSequence(_ n: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func constructDistancedSequence(n int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def constructDistancedSequence(n: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun constructDistancedSequence(n: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn construct_distanced_sequence(n: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer[]\n */\n function constructDistancedSequence($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function constructDistancedSequence(n: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (construct-distanced-sequence n)\n (-> exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1718](https://leetcode-cn.com/problems/construct-the-lexicographically-largest-valid-sequence)", "[\u6784\u5efa\u5b57\u5178\u5e8f\u6700\u5927\u7684\u53ef\u884c\u5e8f\u5217](/solution/1700-1799/1718.Construct%20the%20Lexicographically%20Largest%20Valid%20Sequence/README.md)", "`\u9012\u5f52`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1718](https://leetcode.com/problems/construct-the-lexicographically-largest-valid-sequence)", "[Construct the Lexicographically Largest Valid Sequence](/solution/1700-1799/1718.Construct%20the%20Lexicographically%20Largest%20Valid%20Sequence/README_EN.md)", "`Recursion`,`Backtracking`", "Medium", ""]}, {"question_id": "1818", "frontend_question_id": "1717", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-score-from-removing-substrings", "url_en": "https://leetcode.com/problems/maximum-score-from-removing-substrings", "relative_path_cn": "/solution/1700-1799/1717.Maximum%20Score%20From%20Removing%20Substrings/README.md", "relative_path_en": "/solution/1700-1799/1717.Maximum%20Score%20From%20Removing%20Substrings/README_EN.md", "title_cn": "\u5220\u9664\u5b50\u5b57\u7b26\u4e32\u7684\u6700\u5927\u5f97\u5206", "title_en": "Maximum Score From Removing Substrings", "question_title_slug": "maximum-score-from-removing-substrings", "content_en": "

    You are given a string s and two integers x and y. You can perform two types of operations any number of times.

    \n\n
      \n\t
    • Remove substring "ab" and gain x points.\n\n\t
        \n\t\t
      • For example, when removing "ab" from "cabxbae" it becomes "cxbae".
      • \n\t
      \n\t
    • \n\t
    • Remove substring "ba" and gain y points.\n\t
        \n\t\t
      • For example, when removing "ba" from "cabxbae" it becomes "cabxe".
      • \n\t
      \n\t
    • \n
    \n\n

    Return the maximum points you can gain after applying the above operations on s.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "cdbcbbaaabab", x = 4, y = 5\nOutput: 19\nExplanation:\n- Remove the "ba" underlined in "cdbcbbaaabab". Now, s = "cdbcbbaaab" and 5 points are added to the score.\n- Remove the "ab" underlined in "cdbcbbaaab". Now, s = "cdbcbbaa" and 4 points are added to the score.\n- Remove the "ba" underlined in "cdbcbbaa". Now, s = "cdbcba" and 5 points are added to the score.\n- Remove the "ba" underlined in "cdbcba". Now, s = "cdbc" and 5 points are added to the score.\nTotal score = 5 + 4 + 5 + 5 = 19.
    \n\n

    Example 2:

    \n\n
    \nInput: s = "aabbaaxybbaabb", x = 5, y = 4\nOutput: 20\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 105
    • \n\t
    • 1 <= x, y <= 104
    • \n\t
    • s consists of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32\u00a0s\u00a0\u548c\u4e24\u4e2a\u6574\u6570\u00a0x \u548c\u00a0y\u00a0\u3002\u4f60\u53ef\u4ee5\u6267\u884c\u4e0b\u9762\u4e24\u79cd\u64cd\u4f5c\u4efb\u610f\u6b21\u3002

    \n\n
      \n\t
    • \u5220\u9664\u5b50\u5b57\u7b26\u4e32\u00a0\"ab\"\u00a0\u5e76\u5f97\u5230\u00a0x\u00a0\u5206\u3002\n\n\t
        \n\t\t
      • \u6bd4\u65b9\u8bf4\uff0c\u4ece\u00a0\"cabxbae\"\u00a0\u5220\u9664 ab\u00a0\uff0c\u5f97\u5230\u00a0\"cxbae\"\u00a0\u3002
      • \n\t
      \n\t
    • \n\t
    • \u5220\u9664\u5b50\u5b57\u7b26\u4e32\"ba\"\u00a0\u5e76\u5f97\u5230\u00a0y\u00a0\u5206\u3002\n\t
        \n\t\t
      • \u6bd4\u65b9\u8bf4\uff0c\u4ece\u00a0\"cabxbae\"\u00a0\u5220\u9664 ba\u00a0\uff0c\u5f97\u5230\u00a0\"cabxe\"\u00a0\u3002
      • \n\t
      \n\t
    • \n
    \n\n

    \u8bf7\u8fd4\u56de\u5bf9 s\u00a0\u5b57\u7b26\u4e32\u6267\u884c\u4e0a\u9762\u64cd\u4f5c\u82e5\u5e72\u6b21\u80fd\u5f97\u5230\u7684\u6700\u5927\u5f97\u5206\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1as = \"cdbcbbaaabab\", x = 4, y = 5\n\u8f93\u51fa\uff1a19\n\u89e3\u91ca\uff1a\n- \u5220\u9664 \"cdbcbbaaabab\" \u4e2d\u52a0\u7c97\u7684 \"ba\" \uff0c\u5f97\u5230 s = \"cdbcbbaaab\" \uff0c\u52a0 5 \u5206\u3002\n- \u5220\u9664 \"cdbcbbaaab\" \u4e2d\u52a0\u7c97\u7684 \"ab\" \uff0c\u5f97\u5230 s = \"cdbcbbaa\" \uff0c\u52a0 4 \u5206\u3002\n- \u5220\u9664 \"cdbcbbaa\" \u4e2d\u52a0\u7c97\u7684 \"ba\" \uff0c\u5f97\u5230 s = \"cdbcba\" \uff0c\u52a0 5 \u5206\u3002\n- \u5220\u9664 \"cdbcba\" \u4e2d\u52a0\u7c97\u7684 \"ba\" \uff0c\u5f97\u5230 s = \"cdbc\" \uff0c\u52a0 5 \u5206\u3002\n\u603b\u5f97\u5206\u4e3a 5 + 4 + 5 + 5 = 19 \u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1as = \"aabbaaxybbaabb\", x = 5, y = 4\n\u8f93\u51fa\uff1a20\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 105
    • \n\t
    • 1 <= x, y <= 104
    • \n\t
    • s\u00a0\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maximumGain(string s, int x, int y) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maximumGain(String s, int x, int y) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximumGain(self, s, x, y):\n \"\"\"\n :type s: str\n :type x: int\n :type y: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximumGain(self, s: str, x: int, y: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maximumGain(char * s, int x, int y){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaximumGain(string s, int x, int y) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number} x\n * @param {number} y\n * @return {number}\n */\nvar maximumGain = function(s, x, y) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer} x\n# @param {Integer} y\n# @return {Integer}\ndef maximum_gain(s, x, y)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximumGain(_ s: String, _ x: Int, _ y: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximumGain(s string, x int, y int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximumGain(s: String, x: Int, y: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximumGain(s: String, x: Int, y: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximum_gain(s: String, x: i32, y: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer $x\n * @param Integer $y\n * @return Integer\n */\n function maximumGain($s, $x, $y) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximumGain(s: string, x: number, y: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximum-gain s x y)\n (-> string? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1717](https://leetcode-cn.com/problems/maximum-score-from-removing-substrings)", "[\u5220\u9664\u5b50\u5b57\u7b26\u4e32\u7684\u6700\u5927\u5f97\u5206](/solution/1700-1799/1717.Maximum%20Score%20From%20Removing%20Substrings/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1717](https://leetcode.com/problems/maximum-score-from-removing-substrings)", "[Maximum Score From Removing Substrings](/solution/1700-1799/1717.Maximum%20Score%20From%20Removing%20Substrings/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1817", "frontend_question_id": "1716", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/calculate-money-in-leetcode-bank", "url_en": "https://leetcode.com/problems/calculate-money-in-leetcode-bank", "relative_path_cn": "/solution/1700-1799/1716.Calculate%20Money%20in%20Leetcode%20Bank/README.md", "relative_path_en": "/solution/1700-1799/1716.Calculate%20Money%20in%20Leetcode%20Bank/README_EN.md", "title_cn": "\u8ba1\u7b97\u529b\u6263\u94f6\u884c\u7684\u94b1", "title_en": "Calculate Money in Leetcode Bank", "question_title_slug": "calculate-money-in-leetcode-bank", "content_en": "

    Hercy wants to save money for his first car. He puts money in the Leetcode bank every day.

    \n\n

    He starts by putting in $1 on Monday, the first day. Every day from Tuesday to Sunday, he will put in $1 more than the day before. On every subsequent Monday, he will put in $1 more than the previous Monday.

    \n\n

    Given n, return the total amount of money he will have in the Leetcode bank at the end of the nth day.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 4\nOutput: 10\nExplanation: After the 4th day, the total is 1 + 2 + 3 + 4 = 10.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 10\nOutput: 37\nExplanation: After the 10th day, the total is (1 + 2 + 3 + 4 + 5 + 6 + 7) + (2 + 3 + 4) = 37. Notice that on the 2nd Monday, Hercy only puts in $2.\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 20\nOutput: 96\nExplanation: After the 20th day, the total is (1 + 2 + 3 + 4 + 5 + 6 + 7) + (2 + 3 + 4 + 5 + 6 + 7 + 8) + (3 + 4 + 5 + 6 + 7 + 8) = 96.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 1000
    • \n
    \n", "content_cn": "

    Hercy \u60f3\u8981\u4e3a\u8d2d\u4e70\u7b2c\u4e00\u8f86\u8f66\u5b58\u94b1\u3002\u4ed6 \u6bcf\u5929 \u90fd\u5f80\u529b\u6263\u94f6\u884c\u91cc\u5b58\u94b1\u3002

    \n\n

    \u6700\u5f00\u59cb\uff0c\u4ed6\u5728\u5468\u4e00\u7684\u65f6\u5019\u5b58\u5165 1\u00a0\u5757\u94b1\u3002\u4ece\u5468\u4e8c\u5230\u5468\u65e5\uff0c\u4ed6\u6bcf\u5929\u90fd\u6bd4\u524d\u4e00\u5929\u591a\u5b58\u5165 1\u00a0\u5757\u94b1\u3002\u5728\u63a5\u4e0b\u6765\u6bcf\u4e00\u4e2a\u5468\u4e00\uff0c\u4ed6\u90fd\u4f1a\u6bd4 \u524d\u4e00\u4e2a\u5468\u4e00 \u591a\u5b58\u5165 1\u00a0\u5757\u94b1\u3002

    \n\n

    \u7ed9\u4f60\u00a0n\u00a0\uff0c\u8bf7\u4f60\u8fd4\u56de\u5728\u7b2c n\u00a0\u5929\u7ed3\u675f\u7684\u65f6\u5019\u4ed6\u5728\u529b\u6263\u94f6\u884c\u603b\u5171\u5b58\u4e86\u591a\u5c11\u5757\u94b1\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1an = 4\n\u8f93\u51fa\uff1a10\n\u89e3\u91ca\uff1a\u7b2c 4 \u5929\u540e\uff0c\u603b\u989d\u4e3a 1 + 2 + 3 + 4 = 10 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1an = 10\n\u8f93\u51fa\uff1a37\n\u89e3\u91ca\uff1a\u7b2c 10 \u5929\u540e\uff0c\u603b\u989d\u4e3a (1 + 2 + 3 + 4 + 5 + 6 + 7) + (2 + 3 + 4) = 37 \u3002\u6ce8\u610f\u5230\u7b2c\u4e8c\u4e2a\u661f\u671f\u4e00\uff0cHercy \u5b58\u5165 2 \u5757\u94b1\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1an = 20\n\u8f93\u51fa\uff1a96\n\u89e3\u91ca\uff1a\u7b2c 20 \u5929\u540e\uff0c\u603b\u989d\u4e3a (1 + 2 + 3 + 4 + 5 + 6 + 7) + (2 + 3 + 4 + 5 + 6 + 7 + 8) + (3 + 4 + 5 + 6 + 7 + 8) = 96 \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 1000
    • \n
    \n", "tags_en": ["Greedy", "Math"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int totalMoney(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int totalMoney(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def totalMoney(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def totalMoney(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint totalMoney(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int TotalMoney(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar totalMoney = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef total_money(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func totalMoney(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func totalMoney(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def totalMoney(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun totalMoney(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn total_money(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function totalMoney($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function totalMoney(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (total-money n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1716](https://leetcode-cn.com/problems/calculate-money-in-leetcode-bank)", "[\u8ba1\u7b97\u529b\u6263\u94f6\u884c\u7684\u94b1](/solution/1700-1799/1716.Calculate%20Money%20in%20Leetcode%20Bank/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[1716](https://leetcode.com/problems/calculate-money-in-leetcode-bank)", "[Calculate Money in Leetcode Bank](/solution/1700-1799/1716.Calculate%20Money%20in%20Leetcode%20Bank/README_EN.md)", "`Greedy`,`Math`", "Easy", ""]}, {"question_id": "1816", "frontend_question_id": "1676", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-tree-iv", "url_en": "https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree-iv", "relative_path_cn": "/solution/1600-1699/1676.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree%20IV/README.md", "relative_path_en": "/solution/1600-1699/1676.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree%20IV/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148 IV", "title_en": "Lowest Common Ancestor of a Binary Tree IV", "question_title_slug": "lowest-common-ancestor-of-a-binary-tree-iv", "content_en": "

    Given the root of a binary tree and an array of TreeNode objects nodes, return the lowest common ancestor (LCA) of all the nodes in nodes. All the nodes will exist in the tree, and all values of the tree's nodes are unique.

    \n\n

    Extending the definition of LCA on Wikipedia: "The lowest common ancestor of n nodes p1, p2, ..., pn in a binary tree T is the lowest node that has every pi as a descendant (where we allow a node to be a descendant of itself) for every valid i". A descendant of a node x is a node y that is on the path from node x to some leaf node.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [3,5,1,6,2,0,8,null,null,7,4], nodes = [4,7]\nOutput: 2\nExplanation: The lowest common ancestor of nodes 4 and 7 is node 2.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [3,5,1,6,2,0,8,null,null,7,4], nodes = [1]\nOutput: 1\nExplanation: The lowest common ancestor of a single node is the node itself.\n\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: root = [3,5,1,6,2,0,8,null,null,7,4], nodes = [7,6,2,4]\nOutput: 5\nExplanation: The lowest common ancestor of the nodes 7, 6, 2, and 4 is node 5.\n
    \n\n

    Example 4:

    \n\"\"\n
    \nInput: root = [3,5,1,6,2,0,8,null,null,7,4], nodes = [0,1,2,3,4,5,6,7,8]\nOutput: 3\nExplanation: The lowest common ancestor of all the nodes is the root node.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 104].
    • \n\t
    • -109 <= Node.val <= 109
    • \n\t
    • All Node.val are unique.
    • \n\t
    • All nodes[i] will exist in the tree.
    • \n\t
    • All nodes[i] are distinct.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u68f5\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9\u00a0root\u00a0\u548c\u00a0TreeNode\u00a0\u7c7b\u5bf9\u8c61\u7684\u6570\u7ec4\uff08\u5217\u8868\uff09\u00a0nodes\uff0c\u8fd4\u56de\u00a0nodes\u00a0\u4e2d\u6240\u6709\u8282\u70b9\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148\uff08LCA\uff09\u3002\u6570\u7ec4\uff08\u5217\u8868\uff09\u4e2d\u6240\u6709\u8282\u70b9\u90fd\u5b58\u5728\u4e8e\u8be5\u4e8c\u53c9\u6811\u4e2d\uff0c\u4e14\u4e8c\u53c9\u6811\u4e2d\u6240\u6709\u8282\u70b9\u7684\u503c\u90fd\u662f\u4e92\u4e0d\u76f8\u540c\u7684\u3002

    \n\n

    \u6211\u4eec\u6269\u5c55\u4e8c\u53c9\u6811\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148\u8282\u70b9\u5728\u7ef4\u57fa\u767e\u79d1\u4e0a\u7684\u5b9a\u4e49\uff1a\u201c\u5bf9\u4e8e\u4efb\u610f\u5408\u7406\u7684 i \u503c\uff0c\u00a0n\u00a0\u4e2a\u8282\u70b9\u00a0p1\u00a0\u3001\u00a0p2\u3001...\u3001\u00a0pn\u00a0\u5728\u4e8c\u53c9\u6811\u00a0T\u00a0\u4e2d\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148\u8282\u70b9\u662f\u540e\u4ee3\u4e2d\u5305\u542b\u6240\u6709\u8282\u70b9\u00a0pi\u00a0\u7684\u6700\u6df1\u8282\u70b9\uff08\u6211\u4eec\u5141\u8bb8\u4e00\u4e2a\u8282\u70b9\u662f\u5176\u81ea\u8eab\u7684\u540e\u4ee3\uff09\u201d\u3002\u4e00\u4e2a\u8282\u70b9 x\u00a0\u7684\u540e\u4ee3\u8282\u70b9\u662f\u8282\u70b9\u00a0x \u5230\u67d0\u4e00\u53f6\u8282\u70b9\u95f4\u7684\u8def\u5f84\u4e2d\u7684\u8282\u70b9 y\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1:

    \n\"\"\n
    \u8f93\u5165: root = [3,5,1,6,2,0,8,null,null,7,4], nodes = [4,7]\n\u8f93\u51fa: 2\n\u89e3\u91ca:\u00a0\u8282\u70b9 4 \u548c 7 \u7684\u6700\u8fd1\u516c\u5171\u7956\u5148\u662f 2\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\"\"\n
    \u8f93\u5165: root = [3,5,1,6,2,0,8,null,null,7,4], nodes = [1]\n\u8f93\u51fa: 1\n\u89e3\u91ca:\u00a0\u5355\u4e2a\u8282\u70b9\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148\u662f\u8be5\u8282\u70b9\u672c\u8eab\u3002\n\n
    \n\n

    \u793a\u4f8b 3:

    \n\"\"\n
    \u8f93\u5165: root = [3,5,1,6,2,0,8,null,null,7,4], nodes = [7,6,2,4]\n\u8f93\u51fa: 5\n\u89e3\u91ca:\u00a0\u8282\u70b9 7\u30016\u30012 \u548c 4 \u7684\u6700\u8fd1\u516c\u5171\u7956\u5148\u8282\u70b9\u662f 5\u3002\n
    \n\n

    \u793a\u4f8b 4:

    \n\"\"\n
    \u8f93\u5165: root = [3,5,1,6,2,0,8,null,null,7,4], nodes = [0,1,2,3,4,5,6,7,8]\n\u8f93\u51fa: 3\n\u89e3\u91ca:\u00a0\u6811\u4e2d\u6240\u6709\u8282\u70b9\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148\u662f\u6839\u8282\u70b9\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a:

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u4e2a\u6570\u7684\u8303\u56f4\u662f\u00a0[1, 104]\u00a0\u3002
    • \n\t
    • -109 <= Node.val <= 109
    • \n\t
    • \u6240\u6709\u7684\u00a0Node.val\u00a0\u90fd\u662f\u4e92\u4e0d\u76f8\u540c\u7684\u3002
    • \n\t
    • \u6240\u6709\u7684\u00a0nodes[i]\u00a0\u90fd\u5b58\u5728\u4e8e\u8be5\u6811\u4e2d\u3002
    • \n\t
    • \u6240\u6709\u7684\u00a0nodes[i]\u00a0\u90fd\u662f\u4e92\u4e0d\u76f8\u540c\u7684\u3002
    • \n
    \n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* lowestCommonAncestor(TreeNode* root, vector &nodes) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode(int x) { val = x; }\n * }\n */\nclass Solution {\n public TreeNode lowestCommonAncestor(TreeNode root, TreeNode[] nodes) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution(object):\n def lowestCommonAncestor(self, root, nodes):\n \"\"\"\n :type root: TreeNode\n :type nodes: List[TreeNode]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution:\n def lowestCommonAncestor(self, root: 'TreeNode', nodes: 'List[TreeNode]') -> 'TreeNode':\n ", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int x) { val = x; }\n * }\n */\npublic class Solution {\n public TreeNode LowestCommonAncestor(TreeNode root, TreeNode[] nodes) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val) {\n * this.val = val;\n * this.left = this.right = null;\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {TreeNode[]} nodes\n * @return {TreeNode}\n */\nvar lowestCommonAncestor = function(root, nodes) {\n \n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1676](https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-tree-iv)", "[\u4e8c\u53c9\u6811\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148 IV](/solution/1600-1699/1676.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree%20IV/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1676](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree-iv)", "[Lowest Common Ancestor of a Binary Tree IV](/solution/1600-1699/1676.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree%20IV/README_EN.md)", "`Tree`,`Depth-first Search`", "Medium", "\ud83d\udd12"]}, {"question_id": "1815", "frontend_question_id": "1697", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/checking-existence-of-edge-length-limited-paths", "url_en": "https://leetcode.com/problems/checking-existence-of-edge-length-limited-paths", "relative_path_cn": "/solution/1600-1699/1697.Checking%20Existence%20of%20Edge%20Length%20Limited%20Paths/README.md", "relative_path_en": "/solution/1600-1699/1697.Checking%20Existence%20of%20Edge%20Length%20Limited%20Paths/README_EN.md", "title_cn": "\u68c0\u67e5\u8fb9\u957f\u5ea6\u9650\u5236\u7684\u8def\u5f84\u662f\u5426\u5b58\u5728", "title_en": "Checking Existence of Edge Length Limited Paths", "question_title_slug": "checking-existence-of-edge-length-limited-paths", "content_en": "

    An undirected graph of n nodes is defined by edgeList, where edgeList[i] = [ui, vi, disi] denotes an edge between nodes ui and vi with distance disi. Note that there may be multiple edges between two nodes.

    \n\n

    Given an array queries, where queries[j] = [pj, qj, limitj], your task is to determine for each queries[j] whether there is a path between pj and qj such that each edge on the path has a distance strictly less than limitj .

    \n\n

    Return a boolean array answer, where answer.length == queries.length and the jth value of answer is true if there is a path for queries[j] is true, and false otherwise.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: n = 3, edgeList = [[0,1,2],[1,2,4],[2,0,8],[1,0,16]], queries = [[0,1,2],[0,2,5]]\nOutput: [false,true]\nExplanation: The above figure shows the given graph. Note that there are two overlapping edges between 0 and 1 with distances 2 and 16.\nFor the first query, between 0 and 1 there is no path where each distance is less than 2, thus we return false for this query.\nFor the second query, there is a path (0 -> 1 -> 2) of two edges with distances less than 5, thus we return true for this query.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: n = 5, edgeList = [[0,1,10],[1,2,5],[2,3,9],[3,4,13]], queries = [[0,4,14],[1,4,13]]\nOutput: [true,false]\nExaplanation: The above figure shows the given graph.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= n <= 105
    • \n\t
    • 1 <= edgeList.length, queries.length <= 105
    • \n\t
    • edgeList[i].length == 3
    • \n\t
    • queries[j].length == 3
    • \n\t
    • 0 <= ui, vi, pj, qj <= n - 1
    • \n\t
    • ui != vi
    • \n\t
    • pj != qj
    • \n\t
    • 1 <= disi, limitj <= 109
    • \n\t
    • There may be multiple edges between two nodes.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a n\u00a0\u4e2a\u70b9\u7ec4\u6210\u7684\u65e0\u5411\u56fe\u8fb9\u96c6\u00a0edgeList\u00a0\uff0c\u5176\u4e2d\u00a0edgeList[i] = [ui, vi, disi]\u00a0\u8868\u793a\u70b9\u00a0ui \u548c\u70b9\u00a0vi\u00a0\u4e4b\u95f4\u6709\u4e00\u6761\u957f\u5ea6\u4e3a\u00a0disi\u00a0\u7684\u8fb9\u3002\u8bf7\u6ce8\u610f\uff0c\u4e24\u4e2a\u70b9\u4e4b\u95f4\u53ef\u80fd\u6709 \u8d85\u8fc7\u4e00\u6761\u8fb9\u00a0\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u67e5\u8be2\u6570\u7ec4queries\u00a0\uff0c\u5176\u4e2d\u00a0queries[j] = [pj, qj, limitj]\u00a0\uff0c\u4f60\u7684\u4efb\u52a1\u662f\u5bf9\u4e8e\u6bcf\u4e2a\u67e5\u8be2\u00a0queries[j]\u00a0\uff0c\u5224\u65ad\u662f\u5426\u5b58\u5728\u4ece\u00a0pj\u00a0\u5230\u00a0qj\u00a0\u7684\u8def\u5f84\uff0c\u4e14\u8fd9\u6761\u8def\u5f84\u4e0a\u7684\u6bcf\u4e00\u6761\u8fb9\u90fd \u4e25\u683c\u5c0f\u4e8e\u00a0limitj\u00a0\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u4e00\u4e2a \u5e03\u5c14\u6570\u7ec4\u00a0answer\u00a0\uff0c\u5176\u4e2d\u00a0answer.length == queries.length\u00a0\uff0c\u5f53\u00a0queries[j]\u00a0\u7684\u67e5\u8be2\u7ed3\u679c\u4e3a\u00a0true\u00a0\u65f6\uff0c\u00a0answer \u7b2c\u00a0j\u00a0\u4e2a\u503c\u4e3a\u00a0true\u00a0\uff0c\u5426\u5219\u4e3a\u00a0false\u00a0\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1an = 3, edgeList = [[0,1,2],[1,2,4],[2,0,8],[1,0,16]], queries = [[0,1,2],[0,2,5]]\n\u8f93\u51fa\uff1a[false,true]\n\u89e3\u91ca\uff1a\u4e0a\u56fe\u4e3a\u7ed9\u5b9a\u7684\u8f93\u5165\u6570\u636e\u3002\u6ce8\u610f\u5230 0 \u548c 1 \u4e4b\u95f4\u6709\u4e24\u6761\u91cd\u8fb9\uff0c\u5206\u522b\u4e3a 2 \u548c 16 \u3002\n\u5bf9\u4e8e\u7b2c\u4e00\u4e2a\u67e5\u8be2\uff0c0 \u548c 1 \u4e4b\u95f4\u6ca1\u6709\u5c0f\u4e8e 2 \u7684\u8fb9\uff0c\u6240\u4ee5\u6211\u4eec\u8fd4\u56de false \u3002\n\u5bf9\u4e8e\u7b2c\u4e8c\u4e2a\u67e5\u8be2\uff0c\u6709\u4e00\u6761\u8def\u5f84\uff080 -> 1 -> 2\uff09\u4e24\u6761\u8fb9\u90fd\u5c0f\u4e8e 5 \uff0c\u6240\u4ee5\u8fd9\u4e2a\u67e5\u8be2\u6211\u4eec\u8fd4\u56de true \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1an = 5, edgeList = [[0,1,10],[1,2,5],[2,3,9],[3,4,13]], queries = [[0,4,14],[1,4,13]]\n\u8f93\u51fa\uff1a[true,false]\n\u89e3\u91ca\uff1a\u4e0a\u56fe\u4e3a\u7ed9\u5b9a\u6570\u636e\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= n <= 105
    • \n\t
    • 1 <= edgeList.length, queries.length <= 105
    • \n\t
    • edgeList[i].length == 3
    • \n\t
    • queries[j].length == 3
    • \n\t
    • 0 <= ui, vi, pj, qj <= n - 1
    • \n\t
    • ui != vi
    • \n\t
    • pj != qj
    • \n\t
    • 1 <= disi, limitj <= 109
    • \n\t
    • \u4e24\u4e2a\u70b9\u4e4b\u95f4\u53ef\u80fd\u6709 \u591a\u6761\u00a0\u8fb9\u3002
    • \n
    \n", "tags_en": ["Sort", "Union Find"], "tags_cn": ["\u6392\u5e8f", "\u5e76\u67e5\u96c6"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector distanceLimitedPathsExist(int n, vector>& edgeList, vector>& queries) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean[] distanceLimitedPathsExist(int n, int[][] edgeList, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def distanceLimitedPathsExist(self, n, edgeList, queries):\n \"\"\"\n :type n: int\n :type edgeList: List[List[int]]\n :type queries: List[List[int]]\n :rtype: List[bool]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def distanceLimitedPathsExist(self, n: int, edgeList: List[List[int]], queries: List[List[int]]) -> List[bool]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nbool* distanceLimitedPathsExist(int n, int** edgeList, int edgeListSize, int* edgeListColSize, int** queries, int queriesSize, int* queriesColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool[] DistanceLimitedPathsExist(int n, int[][] edgeList, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} edgeList\n * @param {number[][]} queries\n * @return {boolean[]}\n */\nvar distanceLimitedPathsExist = function(n, edgeList, queries) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} edge_list\n# @param {Integer[][]} queries\n# @return {Boolean[]}\ndef distance_limited_paths_exist(n, edge_list, queries)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func distanceLimitedPathsExist(_ n: Int, _ edgeList: [[Int]], _ queries: [[Int]]) -> [Bool] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func distanceLimitedPathsExist(n int, edgeList [][]int, queries [][]int) []bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def distanceLimitedPathsExist(n: Int, edgeList: Array[Array[Int]], queries: Array[Array[Int]]): Array[Boolean] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun distanceLimitedPathsExist(n: Int, edgeList: Array, queries: Array): BooleanArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn distance_limited_paths_exist(n: i32, edge_list: Vec>, queries: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $edgeList\n * @param Integer[][] $queries\n * @return Boolean[]\n */\n function distanceLimitedPathsExist($n, $edgeList, $queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function distanceLimitedPathsExist(n: number, edgeList: number[][], queries: number[][]): boolean[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (distance-limited-paths-exist n edgeList queries)\n (-> exact-integer? (listof (listof exact-integer?)) (listof (listof exact-integer?)) boolean[])\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1697](https://leetcode-cn.com/problems/checking-existence-of-edge-length-limited-paths)", "[\u68c0\u67e5\u8fb9\u957f\u5ea6\u9650\u5236\u7684\u8def\u5f84\u662f\u5426\u5b58\u5728](/solution/1600-1699/1697.Checking%20Existence%20of%20Edge%20Length%20Limited%20Paths/README.md)", "`\u6392\u5e8f`,`\u5e76\u67e5\u96c6`", "\u56f0\u96be", ""], "md_table_row_en": ["[1697](https://leetcode.com/problems/checking-existence-of-edge-length-limited-paths)", "[Checking Existence of Edge Length Limited Paths](/solution/1600-1699/1697.Checking%20Existence%20of%20Edge%20Length%20Limited%20Paths/README_EN.md)", "`Sort`,`Union Find`", "Hard", ""]}, {"question_id": "1814", "frontend_question_id": "1696", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/jump-game-vi", "url_en": "https://leetcode.com/problems/jump-game-vi", "relative_path_cn": "/solution/1600-1699/1696.Jump%20Game%20VI/README.md", "relative_path_en": "/solution/1600-1699/1696.Jump%20Game%20VI/README_EN.md", "title_cn": "\u8df3\u8dc3\u6e38\u620f VI", "title_en": "Jump Game VI", "question_title_slug": "jump-game-vi", "content_en": "

    You are given a 0-indexed integer array nums and an integer k.

    \n\n

    You are initially standing at index 0. In one move, you can jump at most k steps forward without going outside the boundaries of the array. That is, you can jump from index i to any index in the range [i + 1, min(n - 1, i + k)] inclusive.

    \n\n

    You want to reach the last index of the array (index n - 1). Your score is the sum of all nums[j] for each index j you visited in the array.

    \n\n

    Return the maximum score you can get.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,-1,-2,4,-7,3], k = 2\nOutput: 7\nExplanation: You can choose your jumps forming the subsequence [1,-1,4,3] (underlined above). The sum is 7.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [10,-5,-2,4,0,3], k = 3\nOutput: 17\nExplanation: You can choose your jumps forming the subsequence [10,4,3] (underlined above). The sum is 17.\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [1,-5,-20,4,-1,3,-6,-3], k = 2\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    •  1 <= nums.length, k <= 105
    • \n\t
    • -104 <= nums[i] <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u4e0b\u6807\u4ece 0 \u5f00\u59cb\u7684\u6574\u6570\u6570\u7ec4 nums\u00a0\u548c\u4e00\u4e2a\u6574\u6570 k\u00a0\u3002

    \n\n

    \u4e00\u5f00\u59cb\u4f60\u5728\u4e0b\u6807\u00a00\u00a0\u5904\u3002\u6bcf\u4e00\u6b65\uff0c\u4f60\u6700\u591a\u53ef\u4ee5\u5f80\u524d\u8df3\u00a0k\u00a0\u6b65\uff0c\u4f46\u4f60\u4e0d\u80fd\u8df3\u51fa\u6570\u7ec4\u7684\u8fb9\u754c\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u4f60\u53ef\u4ee5\u4ece\u4e0b\u6807\u00a0i\u00a0\u8df3\u5230\u00a0[i + 1\uff0c min(n - 1, i + k)]\u00a0\u5305\u542b \u4e24\u4e2a\u7aef\u70b9\u7684\u4efb\u610f\u4f4d\u7f6e\u3002

    \n\n

    \u4f60\u7684\u76ee\u6807\u662f\u5230\u8fbe\u6570\u7ec4\u6700\u540e\u4e00\u4e2a\u4f4d\u7f6e\uff08\u4e0b\u6807\u4e3a n - 1\u00a0\uff09\uff0c\u4f60\u7684 \u5f97\u5206\u00a0\u4e3a\u7ecf\u8fc7\u7684\u6240\u6709\u6570\u5b57\u4e4b\u548c\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u4f60\u80fd\u5f97\u5230\u7684 \u6700\u5927\u5f97\u5206\u00a0\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,-1,-2,4,-7,3], k = 2\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u9009\u62e9\u5b50\u5e8f\u5217 [1,-1,4,3] \uff08\u4e0a\u9762\u52a0\u7c97\u7684\u6570\u5b57\uff09\uff0c\u548c\u4e3a 7 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [10,-5,-2,4,0,3], k = 3\n\u8f93\u51fa\uff1a17\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u9009\u62e9\u5b50\u5e8f\u5217 [10,4,3] \uff08\u4e0a\u9762\u52a0\u7c97\u6570\u5b57\uff09\uff0c\u548c\u4e3a 17 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,-5,-20,4,-1,3,-6,-3], k = 2\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u00a01 <= nums.length, k <= 105
    • \n\t
    • -104\u00a0<= nums[i]\u00a0<= 104
    • \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxResult(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxResult(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxResult(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxResult(self, nums: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxResult(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxResult(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar maxResult = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef max_result(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxResult(_ nums: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxResult(nums []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxResult(nums: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxResult(nums: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_result(nums: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer\n */\n function maxResult($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxResult(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-result nums k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1696](https://leetcode-cn.com/problems/jump-game-vi)", "[\u8df3\u8dc3\u6e38\u620f VI](/solution/1600-1699/1696.Jump%20Game%20VI/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1696](https://leetcode.com/problems/jump-game-vi)", "[Jump Game VI](/solution/1600-1699/1696.Jump%20Game%20VI/README_EN.md)", "", "Medium", ""]}, {"question_id": "1813", "frontend_question_id": "1695", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-erasure-value", "url_en": "https://leetcode.com/problems/maximum-erasure-value", "relative_path_cn": "/solution/1600-1699/1695.Maximum%20Erasure%20Value/README.md", "relative_path_en": "/solution/1600-1699/1695.Maximum%20Erasure%20Value/README_EN.md", "title_cn": "\u5220\u9664\u5b50\u6570\u7ec4\u7684\u6700\u5927\u5f97\u5206", "title_en": "Maximum Erasure Value", "question_title_slug": "maximum-erasure-value", "content_en": "

    You are given an array of positive integers nums and want to erase a subarray containing unique elements. The score you get by erasing the subarray is equal to the sum of its elements.

    \n\n

    Return the maximum score you can get by erasing exactly one subarray.

    \n\n

    An array b is called to be a subarray of a if it forms a contiguous subsequence of a, that is, if it is equal to a[l],a[l+1],...,a[r] for some (l,r).

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [4,2,4,5,6]\nOutput: 17\nExplanation: The optimal subarray here is [2,4,5,6].\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [5,2,1,2,5,2,1,2,5]\nOutput: 8\nExplanation: The optimal subarray here is [5,2,1] or [1,2,5].\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • 1 <= nums[i] <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6b63\u6574\u6570\u6570\u7ec4 nums \uff0c\u8bf7\u4f60\u4ece\u4e2d\u5220\u9664\u4e00\u4e2a\u542b\u6709 \u82e5\u5e72\u4e0d\u540c\u5143\u7d20 \u7684\u5b50\u6570\u7ec4\u3002\u5220\u9664\u5b50\u6570\u7ec4\u7684 \u5f97\u5206 \u5c31\u662f\u5b50\u6570\u7ec4\u5404\u5143\u7d20\u4e4b \u548c \u3002

    \n\n

    \u8fd4\u56de \u53ea\u5220\u9664\u4e00\u4e2a \u5b50\u6570\u7ec4\u53ef\u83b7\u5f97\u7684 \u6700\u5927\u5f97\u5206 \u3002

    \n\n

    \u5982\u679c\u6570\u7ec4 b \u662f\u6570\u7ec4 a \u7684\u4e00\u4e2a\u8fde\u7eed\u5b50\u5e8f\u5217\uff0c\u5373\u5982\u679c\u5b83\u7b49\u4e8e a[l],a[l+1],...,a[r] \uff0c\u90a3\u4e48\u5b83\u5c31\u662f\u00a0a \u7684\u4e00\u4e2a\u5b50\u6570\u7ec4\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [4,2,4,5,6]\n\u8f93\u51fa\uff1a17\n\u89e3\u91ca\uff1a\u6700\u4f18\u5b50\u6570\u7ec4\u662f [2,4,5,6]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [5,2,1,2,5,2,1,2,5]\n\u8f93\u51fa\uff1a8\n\u89e3\u91ca\uff1a\u6700\u4f18\u5b50\u6570\u7ec4\u662f [5,2,1] \u6216 [1,2,5]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • 1 <= nums[i] <= 104
    • \n
    \n", "tags_en": ["Two Pointers"], "tags_cn": ["\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maximumUniqueSubarray(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maximumUniqueSubarray(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximumUniqueSubarray(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximumUniqueSubarray(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maximumUniqueSubarray(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaximumUniqueSubarray(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar maximumUniqueSubarray = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef maximum_unique_subarray(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximumUniqueSubarray(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximumUniqueSubarray(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximumUniqueSubarray(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximumUniqueSubarray(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximum_unique_subarray(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function maximumUniqueSubarray($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximumUniqueSubarray(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximum-unique-subarray nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1695](https://leetcode-cn.com/problems/maximum-erasure-value)", "[\u5220\u9664\u5b50\u6570\u7ec4\u7684\u6700\u5927\u5f97\u5206](/solution/1600-1699/1695.Maximum%20Erasure%20Value/README.md)", "`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1695](https://leetcode.com/problems/maximum-erasure-value)", "[Maximum Erasure Value](/solution/1600-1699/1695.Maximum%20Erasure%20Value/README_EN.md)", "`Two Pointers`", "Medium", ""]}, {"question_id": "1812", "frontend_question_id": "1694", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reformat-phone-number", "url_en": "https://leetcode.com/problems/reformat-phone-number", "relative_path_cn": "/solution/1600-1699/1694.Reformat%20Phone%20Number/README.md", "relative_path_en": "/solution/1600-1699/1694.Reformat%20Phone%20Number/README_EN.md", "title_cn": "\u91cd\u65b0\u683c\u5f0f\u5316\u7535\u8bdd\u53f7\u7801", "title_en": "Reformat Phone Number", "question_title_slug": "reformat-phone-number", "content_en": "

    You are given a phone number as a string number. number consists of digits, spaces ' ', and/or dashes '-'.

    \n\n

    You would like to reformat the phone number in a certain manner. Firstly, remove all spaces and dashes. Then, group the digits from left to right into blocks of length 3 until there are 4 or fewer digits. The final digits are then grouped as follows:

    \n\n
      \n\t
    • 2 digits: A single block of length 2.
    • \n\t
    • 3 digits: A single block of length 3.
    • \n\t
    • 4 digits: Two blocks of length 2 each.
    • \n
    \n\n

    The blocks are then joined by dashes. Notice that the reformatting process should never produce any blocks of length 1 and produce at most two blocks of length 2.

    \n\n

    Return the phone number after formatting.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: number = "1-23-45 6"\nOutput: "123-456"\nExplanation: The digits are "123456".\nStep 1: There are more than 4 digits, so group the next 3 digits. The 1st block is "123".\nStep 2: There are 3 digits remaining, so put them in a single block of length 3. The 2nd block is "456".\nJoining the blocks gives "123-456".\n
    \n\n

    Example 2:

    \n\n
    \nInput: number = "123 4-567"\nOutput: "123-45-67"\nExplanation: The digits are "1234567".\nStep 1: There are more than 4 digits, so group the next 3 digits. The 1st block is "123".\nStep 2: There are 4 digits left, so split them into two blocks of length 2. The blocks are "45" and "67".\nJoining the blocks gives "123-45-67".\n
    \n\n

    Example 3:

    \n\n
    \nInput: number = "123 4-5678"\nOutput: "123-456-78"\nExplanation: The digits are "12345678".\nStep 1: The 1st block is "123".\nStep 2: The 2nd block is "456".\nStep 3: There are 2 digits left, so put them in a single block of length 2. The 3rd block is "78".\nJoining the blocks gives "123-456-78".\n
    \n\n

    Example 4:

    \n\n
    \nInput: number = "12"\nOutput: "12"\n
    \n\n

    Example 5:

    \n\n
    \nInput: number = "--17-5 229 35-39475 "\nOutput: "175-229-353-94-75"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= number.length <= 100
    • \n\t
    • number consists of digits and the characters '-' and ' '.
    • \n\t
    • There are at least two digits in number.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32\u5f62\u5f0f\u7684\u7535\u8bdd\u53f7\u7801 number \u3002number \u7531\u6570\u5b57\u3001\u7a7a\u683c ' '\u3001\u548c\u7834\u6298\u53f7 '-' \u7ec4\u6210\u3002

    \n\n

    \u8bf7\u4f60\u6309\u4e0b\u8ff0\u65b9\u5f0f\u91cd\u65b0\u683c\u5f0f\u5316\u7535\u8bdd\u53f7\u7801\u3002

    \n\n
      \n\t
    • \u9996\u5148\uff0c\u5220\u9664 \u6240\u6709\u7684\u7a7a\u683c\u548c\u7834\u6298\u53f7\u3002
    • \n\t
    • \u5176\u6b21\uff0c\u5c06\u6570\u7ec4\u4ece\u5de6\u5230\u53f3 \u6bcf 3 \u4e2a\u4e00\u7ec4 \u5206\u5757\uff0c\u76f4\u5230 \u5269\u4e0b 4 \u4e2a\u6216\u66f4\u5c11\u6570\u5b57\u3002\u5269\u4e0b\u7684\u6570\u5b57\u5c06\u6309\u4e0b\u8ff0\u89c4\u5b9a\u518d\u5206\u5757\uff1a\n\t
        \n\t\t
      • 2 \u4e2a\u6570\u5b57\uff1a\u5355\u4e2a\u542b 2 \u4e2a\u6570\u5b57\u7684\u5757\u3002
      • \n\t\t
      • 3 \u4e2a\u6570\u5b57\uff1a\u5355\u4e2a\u542b 3 \u4e2a\u6570\u5b57\u7684\u5757\u3002
      • \n\t\t
      • 4 \u4e2a\u6570\u5b57\uff1a\u4e24\u4e2a\u5206\u522b\u542b 2 \u4e2a\u6570\u5b57\u7684\u5757\u3002
      • \n\t
      \n\t
    • \n
    \n\n

    \u6700\u540e\u7528\u7834\u6298\u53f7\u5c06\u8fd9\u4e9b\u5757\u8fde\u63a5\u8d77\u6765\u3002\u6ce8\u610f\uff0c\u91cd\u65b0\u683c\u5f0f\u5316\u8fc7\u7a0b\u4e2d \u4e0d\u5e94\u8be5 \u751f\u6210\u4ec5\u542b 1 \u4e2a\u6570\u5b57\u7684\u5757\uff0c\u5e76\u4e14 \u6700\u591a \u751f\u6210\u4e24\u4e2a\u542b 2 \u4e2a\u6570\u5b57\u7684\u5757\u3002

    \n\n

    \u8fd4\u56de\u683c\u5f0f\u5316\u540e\u7684\u7535\u8bdd\u53f7\u7801\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anumber = \"1-23-45 6\"\n\u8f93\u51fa\uff1a\"123-456\"\n\u89e3\u91ca\uff1a\u6570\u5b57\u662f \"123456\"\n\u6b65\u9aa4 1\uff1a\u5171\u6709\u8d85\u8fc7 4 \u4e2a\u6570\u5b57\uff0c\u6240\u4ee5\u5148\u53d6 3 \u4e2a\u6570\u5b57\u5206\u4e3a\u4e00\u7ec4\u3002\u7b2c 1 \u4e2a\u5757\u662f \"123\" \u3002\n\u6b65\u9aa4 2\uff1a\u5269\u4e0b 3 \u4e2a\u6570\u5b57\uff0c\u5c06\u5b83\u4eec\u653e\u5165\u5355\u4e2a\u542b 3 \u4e2a\u6570\u5b57\u7684\u5757\u3002\u7b2c 2 \u4e2a\u5757\u662f \"456\" \u3002\n\u8fde\u63a5\u8fd9\u4e9b\u5757\u540e\u5f97\u5230 \"123-456\" \u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anumber = \"123 4-567\"\n\u8f93\u51fa\uff1a\"123-45-67\"\n\u89e3\u91ca\uff1a\u6570\u5b57\u662f \"1234567\".\n\u6b65\u9aa4 1\uff1a\u5171\u6709\u8d85\u8fc7 4 \u4e2a\u6570\u5b57\uff0c\u6240\u4ee5\u5148\u53d6 3 \u4e2a\u6570\u5b57\u5206\u4e3a\u4e00\u7ec4\u3002\u7b2c 1 \u4e2a\u5757\u662f \"123\" \u3002\n\u6b65\u9aa4 2\uff1a\u5269\u4e0b 4 \u4e2a\u6570\u5b57\uff0c\u6240\u4ee5\u5c06\u5b83\u4eec\u5206\u6210\u4e24\u4e2a\u542b 2 \u4e2a\u6570\u5b57\u7684\u5757\u3002\u8fd9 2 \u5757\u5206\u522b\u662f \"45\" \u548c \"67\" \u3002\n\u8fde\u63a5\u8fd9\u4e9b\u5757\u540e\u5f97\u5230 \"123-45-67\" \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anumber = \"123 4-5678\"\n\u8f93\u51fa\uff1a\"123-456-78\"\n\u89e3\u91ca\uff1a\u6570\u5b57\u662f \"12345678\" \u3002\n\u6b65\u9aa4 1\uff1a\u7b2c 1 \u4e2a\u5757 \"123\" \u3002\n\u6b65\u9aa4 2\uff1a\u7b2c 2 \u4e2a\u5757 \"456\" \u3002\n\u6b65\u9aa4 3\uff1a\u5269\u4e0b 2 \u4e2a\u6570\u5b57\uff0c\u5c06\u5b83\u4eec\u653e\u5165\u5355\u4e2a\u542b 2 \u4e2a\u6570\u5b57\u7684\u5757\u3002\u7b2c 3 \u4e2a\u5757\u662f \"78\" \u3002\n\u8fde\u63a5\u8fd9\u4e9b\u5757\u540e\u5f97\u5230 \"123-456-78\" \u3002
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1anumber = \"12\"\n\u8f93\u51fa\uff1a\"12\"\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1anumber = \"--17-5 229 35-39475 \"\n\u8f93\u51fa\uff1a\"175-229-353-94-75\"\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= number.length <= 100
    • \n\t
    • number \u7531\u6570\u5b57\u548c\u5b57\u7b26 '-' \u53ca ' ' \u7ec4\u6210\u3002
    • \n\t
    • number \u4e2d\u81f3\u5c11\u542b 2 \u4e2a\u6570\u5b57\u3002
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string reformatNumber(string number) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String reformatNumber(String number) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def reformatNumber(self, number):\n \"\"\"\n :type number: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def reformatNumber(self, number: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * reformatNumber(char * number){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ReformatNumber(string number) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} number\n * @return {string}\n */\nvar reformatNumber = function(number) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} number\n# @return {String}\ndef reformat_number(number)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func reformatNumber(_ number: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func reformatNumber(number string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def reformatNumber(number: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun reformatNumber(number: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn reformat_number(number: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $number\n * @return String\n */\n function reformatNumber($number) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function reformatNumber(number: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (reformat-number number)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1694](https://leetcode-cn.com/problems/reformat-phone-number)", "[\u91cd\u65b0\u683c\u5f0f\u5316\u7535\u8bdd\u53f7\u7801](/solution/1600-1699/1694.Reformat%20Phone%20Number/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1694](https://leetcode.com/problems/reformat-phone-number)", "[Reformat Phone Number](/solution/1600-1699/1694.Reformat%20Phone%20Number/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1811", "frontend_question_id": "1667", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/fix-names-in-a-table", "url_en": "https://leetcode.com/problems/fix-names-in-a-table", "relative_path_cn": "/solution/1600-1699/1667.Fix%20Names%20in%20a%20Table/README.md", "relative_path_en": "/solution/1600-1699/1667.Fix%20Names%20in%20a%20Table/README_EN.md", "title_cn": "\u4fee\u590d\u8868\u4e2d\u7684\u540d\u5b57", "title_en": "Fix Names in a Table", "question_title_slug": "fix-names-in-a-table", "content_en": "

    Table: Users

    \n\n
    \n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| user_id        | int     |\n| name           | varchar |\n+----------------+---------+\nuser_id is the primary key for this table.\nThis table contains the ID and the name of the user. The name consists of only lowercase and uppercase characters.\n
    \n\n

     

    \n\n

    Write an SQL query to fix the names so that only the first character is uppercase and the rest are lowercase.

    \n\n

    Return the result table ordered by user_id.

    \n\n

    The query result format is in the following example:

    \n\n

     

    \n\n
    \nUsers table:\n+---------+-------+\n| user_id | name  |\n+---------+-------+\n| 1       | aLice |\n| 2       | bOB   |\n+---------+-------+\n\nResult table:\n+---------+-------+\n| user_id | name  |\n+---------+-------+\n| 1       | Alice |\n| 2       | Bob   |\n+---------+-------+\n
    \n", "content_cn": "

    \u8868\uff1a Users

    \n\n
    \n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| user_id        | int     |\n| name           | varchar |\n+----------------+---------+\nuser_id \u662f\u8be5\u8868\u7684\u4e3b\u952e\u3002\n\u8be5\u8868\u5305\u542b\u7528\u6237\u7684 ID \u548c\u540d\u5b57\u3002\u540d\u5b57\u4ec5\u7531\u5c0f\u5199\u548c\u5927\u5199\u5b57\u7b26\u7ec4\u6210\u3002\n
    \n\n

    \u00a0

    \n\n

    \u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\u6765\u4fee\u590d\u540d\u5b57\uff0c\u4f7f\u5f97\u53ea\u6709\u7b2c\u4e00\u4e2a\u5b57\u7b26\u662f\u5927\u5199\u7684\uff0c\u5176\u4f59\u90fd\u662f\u5c0f\u5199\u7684\u3002

    \n\n

    \u8fd4\u56de\u6309 user_id \u6392\u5e8f\u7684\u7ed3\u679c\u8868\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u793a\u4f8b\u5982\u4e0b\uff1a

    \n\n
    \nUsers table:\n+---------+-------+\n| user_id | name  |\n+---------+-------+\n| 1       | aLice |\n| 2       | bOB   |\n+---------+-------+\n\nResult table:\n+---------+-------+\n| user_id | name  |\n+---------+-------+\n| 1       | Alice |\n| 2       | Bob   |\n+---------+-------+\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1667](https://leetcode-cn.com/problems/fix-names-in-a-table)", "[\u4fee\u590d\u8868\u4e2d\u7684\u540d\u5b57](/solution/1600-1699/1667.Fix%20Names%20in%20a%20Table/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1667](https://leetcode.com/problems/fix-names-in-a-table)", "[Fix Names in a Table](/solution/1600-1699/1667.Fix%20Names%20in%20a%20Table/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1810", "frontend_question_id": "1666", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/change-the-root-of-a-binary-tree", "url_en": "https://leetcode.com/problems/change-the-root-of-a-binary-tree", "relative_path_cn": "/solution/1600-1699/1666.Change%20the%20Root%20of%20a%20Binary%20Tree/README.md", "relative_path_en": "/solution/1600-1699/1666.Change%20the%20Root%20of%20a%20Binary%20Tree/README_EN.md", "title_cn": "\u6539\u53d8\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9", "title_en": "Change the Root of a Binary Tree", "question_title_slug": "change-the-root-of-a-binary-tree", "content_en": "

    Given the root of a binary tree and a leaf node, reroot the tree so that the leaf is the new root.

    \n\n

    You can reroot the tree with the following steps for each node cur on the path starting from the leaf up to the root\u200b\u200b\u200b excluding the root:

    \n\n
      \n\t
    1. If cur has a left child, then that child becomes cur's right child.
    2. \n\t
    3. cur's original parent becomes cur's left child. Note that in this process the original parent's pointer to cur becomes null, making it have at most one child.
    4. \n
    \n\n

    Return the new root of the rerooted tree.

    \n\n

    Note: Ensure that your solution sets the Node.parent pointers correctly after rerooting or you will receive "Wrong Answer".

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [3,5,1,6,2,0,8,null,null,7,4], leaf = 7\nOutput: [7,2,null,5,4,3,6,null,null,null,1,null,null,0,8]\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = [3,5,1,6,2,0,8,null,null,7,4], leaf = 0\nOutput: [0,1,null,3,8,5,null,null,null,6,2,null,null,7,4]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [2, 100].
    • \n\t
    • -109 <= Node.val <= 109
    • \n\t
    • All Node.val are unique.
    • \n\t
    • leaf exist in the tree.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u68f5\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9\u00a0root\u00a0\u548c\u4e00\u4e2a\u53f6\u8282\u70b9\u00a0leaf \uff0c\u66f4\u6539\u4e8c\u53c9\u6811\uff0c\u4f7f\u5f97\u00a0leaf\u00a0\u4e3a\u65b0\u7684\u6839\u8282\u70b9\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u6309\u7167\u4e0b\u5217\u6b65\u9aa4\u4fee\u6539\u4ece leaf\u00a0\u5230 root\u00a0\u7684\u8def\u5f84\u4e2d\u9664 root \u5916\u7684\u6bcf\u4e2a\u8282\u70b9 cur\u00a0\uff1a

    \n\n
      \n\t
    1. \u5982\u679c\u00a0cur\u00a0\u6709\u5de6\u5b50\u8282\u70b9\uff0c\u5219\u8be5\u5b50\u8282\u70b9\u53d8\u4e3a\u00a0cur\u00a0\u7684\u53f3\u5b50\u8282\u70b9\u3002\u6ce8\u610f\u6211\u4eec\u4fdd\u8bc1\u00a0cur\u00a0\u81f3\u591a\u6709\u4e00\u4e2a\u5b50\u8282\u70b9\u3002
    2. \n\t
    3. cur\u00a0\u7684\u539f\u7236\u8282\u70b9\u53d8\u4e3a\u00a0cur\u00a0\u7684\u5de6\u5b50\u8282\u70b9\u3002
    4. \n
    \n\n

    \u8fd4\u56de\u4fee\u6539\u540e\u65b0\u6811\u7684\u6839\u8282\u70b9\u3002

    \n\n

    \u6ce8\u610f\uff1a\u786e\u4fdd\u4f60\u7684\u7b54\u6848\u5728\u64cd\u4f5c\u540e\u6b63\u786e\u5730\u8bbe\u5b9a\u4e86\u00a0Node.parent\u00a0\uff08\u7236\u8282\u70b9\uff09\u6307\u9488\uff0c\u5426\u5219\u4f1a\u88ab\u5224\u4e3a\u9519\u8bef\u7b54\u6848\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1:

    \n\"\"\n
    \u8f93\u5165: root = [3,5,1,6,2,0,8,null,null,7,4], leaf = 7\n\u8f93\u51fa: [7,2,null,5,4,3,6,null,null,null,1,null,null,0,8]\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: root = [3,5,1,6,2,0,8,null,null,7,4], leaf = 0\n\u8f93\u51fa: [0,1,null,3,8,5,null,null,null,6,2,null,null,7,4]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a:

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u7684\u4e2a\u6570\u5728\u8303\u56f4\u00a0[2, 100]\u00a0\u5185\u3002
    • \n\t
    • -109 <= Node.val <= 109
    • \n\t
    • \u6240\u6709\u7684\u00a0Node.val\u00a0\u90fd\u662f\u552f\u4e00\u7684\u3002
    • \n\t
    • leaf\u00a0\u5b58\u5728\u4e8e\u6811\u4e2d\u3002
    • \n
    \n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* parent;\n};\n*/\n\nclass Solution {\npublic:\n Node* flipBinaryTree(Node* root, Node * leaf) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/*\n// Definition for a Node.\nclass Node {\n public int val;\n public Node left;\n public Node right;\n public Node parent;\n};\n*/\n\nclass Solution {\n public Node flipBinaryTree(Node root, Node leaf) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "\"\"\"\n# Definition for a Node.\nclass Node:\n def __init__(self, val):\n self.val = val\n self.left = None\n self.right = None\n self.parent = None\n\"\"\"\n\nclass Solution(object):\n def flipBinaryTree(self, root, leaf):\n \"\"\"\n :type node: Node\n :rtype: Node\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "\"\"\"\n# Definition for a Node.\nclass Node:\n def __init__(self, val):\n self.val = val\n self.left = None\n self.right = None\n self.parent = None\n\"\"\"\n\nclass Solution:\n def flipBinaryTree(self, root: 'Node', leaf: 'Node') -> 'Node':\n ", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/*\n// Definition for a Node.\npublic class Node {\n public int val;\n public Node left;\n public Node right;\n public Node parent;\n}\n*/\n\npublic class Solution {\n public Node FlipBinaryTree(Node root, Node leaf) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // Definition for a Node.\n * function Node(val) {\n * this.val = val;\n * this.left = null;\n * this.right = null;\n * this.parent = null;\n * };\n */\n\n/**\n * @param {Node} node\n * @return {Node}\n */\nvar flipBinaryTree = function(root, leaf) {\n \n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1666](https://leetcode-cn.com/problems/change-the-root-of-a-binary-tree)", "[\u6539\u53d8\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9](/solution/1600-1699/1666.Change%20the%20Root%20of%20a%20Binary%20Tree/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1666](https://leetcode.com/problems/change-the-root-of-a-binary-tree)", "[Change the Root of a Binary Tree](/solution/1600-1699/1666.Change%20the%20Root%20of%20a%20Binary%20Tree/README_EN.md)", "`Tree`,`Depth-first Search`", "Medium", "\ud83d\udd12"]}, {"question_id": "1809", "frontend_question_id": "1714", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/sum-of-special-evenly-spaced-elements-in-array", "url_en": "https://leetcode.com/problems/sum-of-special-evenly-spaced-elements-in-array", "relative_path_cn": "/solution/1700-1799/1714.Sum%20Of%20Special%20Evenly-Spaced%20Elements%20In%20Array/README.md", "relative_path_en": "/solution/1700-1799/1714.Sum%20Of%20Special%20Evenly-Spaced%20Elements%20In%20Array/README_EN.md", "title_cn": "\u6570\u7ec4\u4e2d\u7279\u6b8a\u7b49\u95f4\u8ddd\u5143\u7d20\u7684\u548c", "title_en": "Sum Of Special Evenly-Spaced Elements In Array", "question_title_slug": "sum-of-special-evenly-spaced-elements-in-array", "content_en": "

    You are given a 0-indexed integer array nums consisting of n non-negative integers.

    \n\n

    You are also given an array queries, where queries[i] = [xi, yi]. The answer to the ith query is the sum of all nums[j] where xi <= j < n and (j - xi) is divisible by yi.

    \n\n

    Return an array answer where answer.length == queries.length and answer[i] is the answer to the ith query modulo 109 + 7.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [0,1,2,3,4,5,6,7], queries = [[0,3],[5,1],[4,2]]\nOutput: [9,18,10]\nExplanation: The answers of the queries are as follows:\n1) The j indices that satisfy this query are 0, 3, and 6. nums[0] + nums[3] + nums[6] = 9\n2) The j indices that satisfy this query are 5, 6, and 7. nums[5] + nums[6] + nums[7] = 18\n3) The j indices that satisfy this query are 4 and 6. nums[4] + nums[6] = 10\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [100,200,101,201,102,202,103,203], queries = [[0,7]]\nOutput: [303]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= n <= 5 * 104
    • \n\t
    • 0 <= nums[i] <= 109
    • \n\t
    • 1 <= queries.length <= 1.5 * 105
    • \n\t
    • 0 <= xi < n
    • \n\t
    • 1 <= yi <= 5 * 104
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u7d22\u5f15\u4ece 0 \u5f00\u59cb\u7684\u6574\u6570\u7c7b\u578b\u6570\u7ec4\u00a0nums\u00a0\uff0c\u5305\u542b\u00a0n\u00a0\u4e2a\u975e\u8d1f\u6574\u6570\u3002

    \n\n

    \u53e6\u5916\u7ed9\u5b9a\u4e00\u4e2a\uff08\u5305\u542b\u67e5\u8be2\u6307\u4ee4\u7684\uff09\u6570\u7ec4\u00a0queries\u00a0\uff0c\u5176\u4e2d\u00a0queries[i] = [xi, yi]\u3002 \u7b2c\u00a0i\u00a0\u4e2a\u67e5\u8be2\u6307\u4ee4\u7684\u7b54\u6848\u662f\u00a0nums[j]\u00a0\u4e2d\u6ee1\u8db3\u8be5\u6761\u4ef6\u7684\u6240\u6709\u5143\u7d20\u7684\u548c\uff1a\u00a0xi <= j < n\u00a0\u4e14\u00a0(j - xi)\u00a0\u80fd\u88ab\u00a0yi\u00a0\u6574\u9664\u3002

    \n\n

    \u8fd4\u56de\u4e00\u4e2a\u6570\u7ec4\u00a0answer\uff0c\u5176\u4e2d\u00a0\u00a0answer.length == queries.length\u00a0\u4e14\u00a0answer[i]\u00a0\u662f\u7b2c\u00a0i\u00a0\u4e2a\u67e5\u8be2\u6307\u4ee4\u7684\u7b54\u6848\u5bf9\u00a0109 + 7\u00a0\u53d6\u6a21\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: nums = [0,1,2,3,4,5,6,7], queries = [[0,3],[5,1],[4,2]]\n\u8f93\u51fa: [9,18,10]\n\u89e3\u91ca: \u6bcf\u6b21\u67e5\u8be2\u7684\u7b54\u6848\u5982\u4e0b\uff1a\n1) \u7b26\u5408\u67e5\u8be2\u6761\u4ef6\u7684\u7d22\u5f15 j \u6709 0\u3001 3 \u548c 6\u3002 nums[0] + nums[3] + nums[6] = 9\n2) \u7b26\u5408\u67e5\u8be2\u6761\u4ef6\u7684\u7d22\u5f15 j \u6709 5\u3001 6 \u548c 7\u3002 nums[5] + nums[6] + nums[7] = 18\n3) \u7b26\u5408\u67e5\u8be2\u6761\u4ef6\u7684\u7d22\u5f15 j \u6709 4 \u548c 6\u3002 nums[4] + nums[6] = 10\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: nums = [100,200,101,201,102,202,103,203], queries = [[0,7]]\n\u8f93\u51fa: [303]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= n <= 5 * 104
    • \n\t
    • 0 <= nums[i] <= 109
    • \n\t
    • 1 <= queries.length <= 1.5 * 105
    • \n\t
    • 0 <= xi < n
    • \n\t
    • 1 <= yi <= 5 * 104
    • \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector solve(vector& nums, vector>& queries) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] solve(int[] nums, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def solve(self, nums, queries):\n \"\"\"\n :type nums: List[int]\n :type queries: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def solve(self, nums: List[int], queries: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* solve(int* nums, int numsSize, int** queries, int queriesSize, int* queriesColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] Solve(int[] nums, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number[][]} queries\n * @return {number[]}\n */\nvar solve = function(nums, queries) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer[][]} queries\n# @return {Integer[]}\ndef solve(nums, queries)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func solve(_ nums: [Int], _ queries: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func solve(nums []int, queries [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def solve(nums: Array[Int], queries: Array[Array[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun solve(nums: IntArray, queries: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn solve(nums: Vec, queries: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer[][] $queries\n * @return Integer[]\n */\n function solve($nums, $queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function solve(nums: number[], queries: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (solve nums queries)\n (-> (listof exact-integer?) (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1714](https://leetcode-cn.com/problems/sum-of-special-evenly-spaced-elements-in-array)", "[\u6570\u7ec4\u4e2d\u7279\u6b8a\u7b49\u95f4\u8ddd\u5143\u7d20\u7684\u548c](/solution/1700-1799/1714.Sum%20Of%20Special%20Evenly-Spaced%20Elements%20In%20Array/README.md)", "", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1714](https://leetcode.com/problems/sum-of-special-evenly-spaced-elements-in-array)", "[Sum Of Special Evenly-Spaced Elements In Array](/solution/1700-1799/1714.Sum%20Of%20Special%20Evenly-Spaced%20Elements%20In%20Array/README_EN.md)", "", "Hard", "\ud83d\udd12"]}, {"question_id": "1808", "frontend_question_id": "1690", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/stone-game-vii", "url_en": "https://leetcode.com/problems/stone-game-vii", "relative_path_cn": "/solution/1600-1699/1690.Stone%20Game%20VII/README.md", "relative_path_en": "/solution/1600-1699/1690.Stone%20Game%20VII/README_EN.md", "title_cn": "\u77f3\u5b50\u6e38\u620f VII", "title_en": "Stone Game VII", "question_title_slug": "stone-game-vii", "content_en": "

    Alice and Bob take turns playing a game, with Alice starting first.

    \n\n

    There are n stones arranged in a row. On each player's turn, they can remove either the leftmost stone or the rightmost stone from the row and receive points equal to the sum of the remaining stones' values in the row. The winner is the one with the higher score when there are no stones left to remove.

    \n\n

    Bob found that he will always lose this game (poor Bob, he always loses), so he decided to minimize the score's difference. Alice's goal is to maximize the difference in the score.

    \n\n

    Given an array of integers stones where stones[i] represents the value of the ith stone from the left, return the difference in Alice and Bob's score if they both play optimally.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: stones = [5,3,1,4,2]\nOutput: 6\nExplanation: \n- Alice removes 2 and gets 5 + 3 + 1 + 4 = 13 points. Alice = 13, Bob = 0, stones = [5,3,1,4].\n- Bob removes 5 and gets 3 + 1 + 4 = 8 points. Alice = 13, Bob = 8, stones = [3,1,4].\n- Alice removes 3 and gets 1 + 4 = 5 points. Alice = 18, Bob = 8, stones = [1,4].\n- Bob removes 1 and gets 4 points. Alice = 18, Bob = 12, stones = [4].\n- Alice removes 4 and gets 0 points. Alice = 18, Bob = 12, stones = [].\nThe score difference is 18 - 12 = 6.\n
    \n\n

    Example 2:

    \n\n
    \nInput: stones = [7,90,5,1,100,10,10,2]\nOutput: 122
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == stones.length
    • \n\t
    • 2 <= n <= 1000
    • \n\t
    • 1 <= stones[i] <= 1000
    • \n
    \n", "content_cn": "

    \u77f3\u5b50\u6e38\u620f\u4e2d\uff0c\u7231\u4e3d\u4e1d\u548c\u9c8d\u52c3\u8f6e\u6d41\u8fdb\u884c\u81ea\u5df1\u7684\u56de\u5408\uff0c\u7231\u4e3d\u4e1d\u5148\u5f00\u59cb \u3002

    \n\n

    \u6709 n \u5757\u77f3\u5b50\u6392\u6210\u4e00\u6392\u3002\u6bcf\u4e2a\u73a9\u5bb6\u7684\u56de\u5408\u4e2d\uff0c\u53ef\u4ee5\u4ece\u884c\u4e2d \u79fb\u9664 \u6700\u5de6\u8fb9\u7684\u77f3\u5934\u6216\u6700\u53f3\u8fb9\u7684\u77f3\u5934\uff0c\u5e76\u83b7\u5f97\u4e0e\u8be5\u884c\u4e2d\u5269\u4f59\u77f3\u5934\u503c\u4e4b \u548c \u76f8\u7b49\u7684\u5f97\u5206\u3002\u5f53\u6ca1\u6709\u77f3\u5934\u53ef\u79fb\u9664\u65f6\uff0c\u5f97\u5206\u8f83\u9ad8\u8005\u83b7\u80dc\u3002

    \n\n

    \u9c8d\u52c3\u53d1\u73b0\u4ed6\u603b\u662f\u8f93\u6389\u6e38\u620f\uff08\u53ef\u601c\u7684\u9c8d\u52c3\uff0c\u4ed6\u603b\u662f\u8f93\uff09\uff0c\u6240\u4ee5\u4ed6\u51b3\u5b9a\u5c3d\u529b \u51cf\u5c0f\u5f97\u5206\u7684\u5dee\u503c \u3002\u7231\u4e3d\u4e1d\u7684\u76ee\u6807\u662f\u6700\u5927\u9650\u5ea6\u5730 \u6269\u5927\u5f97\u5206\u7684\u5dee\u503c \u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0stones \uff0c\u5176\u4e2d stones[i] \u8868\u793a \u4ece\u5de6\u8fb9\u5f00\u59cb \u7684\u7b2c i \u4e2a\u77f3\u5934\u7684\u503c\uff0c\u5982\u679c\u7231\u4e3d\u4e1d\u548c\u9c8d\u52c3\u90fd \u53d1\u6325\u51fa\u6700\u4f73\u6c34\u5e73 \uff0c\u8bf7\u8fd4\u56de\u4ed6\u4eec \u5f97\u5206\u7684\u5dee\u503c \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1astones = [5,3,1,4,2]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\n- \u7231\u4e3d\u4e1d\u79fb\u9664 2 \uff0c\u5f97\u5206 5 + 3 + 1 + 4 = 13 \u3002\u6e38\u620f\u60c5\u51b5\uff1a\u7231\u4e3d\u4e1d = 13 \uff0c\u9c8d\u52c3 = 0 \uff0c\u77f3\u5b50 = [5,3,1,4] \u3002\n- \u9c8d\u52c3\u79fb\u9664 5 \uff0c\u5f97\u5206 3 + 1 + 4 = 8 \u3002\u6e38\u620f\u60c5\u51b5\uff1a\u7231\u4e3d\u4e1d = 13 \uff0c\u9c8d\u52c3 = 8 \uff0c\u77f3\u5b50 = [3,1,4] \u3002\n- \u7231\u4e3d\u4e1d\u79fb\u9664 3 \uff0c\u5f97\u5206 1 + 4 = 5 \u3002\u6e38\u620f\u60c5\u51b5\uff1a\u7231\u4e3d\u4e1d = 18 \uff0c\u9c8d\u52c3 = 8 \uff0c\u77f3\u5b50 = [1,4] \u3002\n- \u9c8d\u52c3\u79fb\u9664 1 \uff0c\u5f97\u5206 4 \u3002\u6e38\u620f\u60c5\u51b5\uff1a\u7231\u4e3d\u4e1d = 18 \uff0c\u9c8d\u52c3 = 12 \uff0c\u77f3\u5b50 = [4] \u3002\n- \u7231\u4e3d\u4e1d\u79fb\u9664 4 \uff0c\u5f97\u5206 0 \u3002\u6e38\u620f\u60c5\u51b5\uff1a\u7231\u4e3d\u4e1d = 18 \uff0c\u9c8d\u52c3 = 12 \uff0c\u77f3\u5b50 = [] \u3002\n\u5f97\u5206\u7684\u5dee\u503c 18 - 12 = 6 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1astones = [7,90,5,1,100,10,10,2]\n\u8f93\u51fa\uff1a122
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == stones.length
    • \n\t
    • 2 <= n <= 1000
    • \n\t
    • 1 <= stones[i] <= 1000
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int stoneGameVII(vector& stones) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int stoneGameVII(int[] stones) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def stoneGameVII(self, stones):\n \"\"\"\n :type stones: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def stoneGameVII(self, stones: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint stoneGameVII(int* stones, int stonesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int StoneGameVII(int[] stones) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} stones\n * @return {number}\n */\nvar stoneGameVII = function(stones) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} stones\n# @return {Integer}\ndef stone_game_vii(stones)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func stoneGameVII(_ stones: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func stoneGameVII(stones []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def stoneGameVII(stones: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun stoneGameVII(stones: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn stone_game_vii(stones: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $stones\n * @return Integer\n */\n function stoneGameVII($stones) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function stoneGameVII(stones: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (stone-game-vii stones)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1690](https://leetcode-cn.com/problems/stone-game-vii)", "[\u77f3\u5b50\u6e38\u620f VII](/solution/1600-1699/1690.Stone%20Game%20VII/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1690](https://leetcode.com/problems/stone-game-vii)", "[Stone Game VII](/solution/1600-1699/1690.Stone%20Game%20VII/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "1807", "frontend_question_id": "1689", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers", "url_en": "https://leetcode.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers", "relative_path_cn": "/solution/1600-1699/1689.Partitioning%20Into%20Minimum%20Number%20Of%20Deci-Binary%20Numbers/README.md", "relative_path_en": "/solution/1600-1699/1689.Partitioning%20Into%20Minimum%20Number%20Of%20Deci-Binary%20Numbers/README_EN.md", "title_cn": "\u5341-\u4e8c\u8fdb\u5236\u6570\u7684\u6700\u5c11\u6570\u76ee", "title_en": "Partitioning Into Minimum Number Of Deci-Binary Numbers", "question_title_slug": "partitioning-into-minimum-number-of-deci-binary-numbers", "content_en": "

    A decimal number is called deci-binary if each of its digits is either 0 or 1 without any leading zeros. For example, 101 and 1100 are deci-binary, while 112 and 3001 are not.

    \n\n

    Given a string n that represents a positive decimal integer, return the minimum number of positive deci-binary numbers needed so that they sum up to n.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = "32"\nOutput: 3\nExplanation: 10 + 11 + 11 = 32\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = "82734"\nOutput: 8\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = "27346209830709182346"\nOutput: 9\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n.length <= 105
    • \n\t
    • n consists of only digits.
    • \n\t
    • n does not contain any leading zeros and represents a positive integer.
    • \n
    \n", "content_cn": "

    \u5982\u679c\u4e00\u4e2a\u5341\u8fdb\u5236\u6570\u5b57\u4e0d\u542b\u4efb\u4f55\u524d\u5bfc\u96f6\uff0c\u4e14\u6bcf\u4e00\u4f4d\u4e0a\u7684\u6570\u5b57\u4e0d\u662f 0 \u5c31\u662f 1 \uff0c\u90a3\u4e48\u8be5\u6570\u5b57\u5c31\u662f\u4e00\u4e2a \u5341-\u4e8c\u8fdb\u5236\u6570 \u3002\u4f8b\u5982\uff0c101 \u548c 1100 \u90fd\u662f \u5341-\u4e8c\u8fdb\u5236\u6570\uff0c\u800c 112 \u548c 3001 \u4e0d\u662f\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u8868\u793a\u5341\u8fdb\u5236\u6574\u6570\u7684\u5b57\u7b26\u4e32 n \uff0c\u8fd4\u56de\u548c\u4e3a n \u7684 \u5341-\u4e8c\u8fdb\u5236\u6570 \u7684\u6700\u5c11\u6570\u76ee\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1an = \"32\"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a10 + 11 + 11 = 32\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1an = \"82734\"\n\u8f93\u51fa\uff1a8\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1an = \"27346209830709182346\"\n\u8f93\u51fa\uff1a9\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n.length <= 105
    • \n\t
    • n \u4ec5\u7531\u6570\u5b57\u7ec4\u6210
    • \n\t
    • n \u4e0d\u542b\u4efb\u4f55\u524d\u5bfc\u96f6\u5e76\u603b\u662f\u8868\u793a\u6b63\u6574\u6570
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minPartitions(string n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minPartitions(String n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minPartitions(self, n):\n \"\"\"\n :type n: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minPartitions(self, n: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minPartitions(char * n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinPartitions(string n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} n\n * @return {number}\n */\nvar minPartitions = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} n\n# @return {Integer}\ndef min_partitions(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minPartitions(_ n: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minPartitions(n string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minPartitions(n: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minPartitions(n: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_partitions(n: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $n\n * @return Integer\n */\n function minPartitions($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minPartitions(n: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-partitions n)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1689](https://leetcode-cn.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers)", "[\u5341-\u4e8c\u8fdb\u5236\u6570\u7684\u6700\u5c11\u6570\u76ee](/solution/1600-1699/1689.Partitioning%20Into%20Minimum%20Number%20Of%20Deci-Binary%20Numbers/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1689](https://leetcode.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers)", "[Partitioning Into Minimum Number Of Deci-Binary Numbers](/solution/1600-1699/1689.Partitioning%20Into%20Minimum%20Number%20Of%20Deci-Binary%20Numbers/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1806", "frontend_question_id": "1688", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-of-matches-in-tournament", "url_en": "https://leetcode.com/problems/count-of-matches-in-tournament", "relative_path_cn": "/solution/1600-1699/1688.Count%20of%20Matches%20in%20Tournament/README.md", "relative_path_en": "/solution/1600-1699/1688.Count%20of%20Matches%20in%20Tournament/README_EN.md", "title_cn": "\u6bd4\u8d5b\u4e2d\u7684\u914d\u5bf9\u6b21\u6570", "title_en": "Count of Matches in Tournament", "question_title_slug": "count-of-matches-in-tournament", "content_en": "

    You are given an integer n, the number of teams in a tournament that has strange rules:

    \n\n
      \n\t
    • If the current number of teams is even, each team gets paired with another team. A total of n / 2 matches are played, and n / 2 teams advance to the next round.
    • \n\t
    • If the current number of teams is odd, one team randomly advances in the tournament, and the rest gets paired. A total of (n - 1) / 2 matches are played, and (n - 1) / 2 + 1 teams advance to the next round.
    • \n
    \n\n

    Return the number of matches played in the tournament until a winner is decided.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 7\nOutput: 6\nExplanation: Details of the tournament: \n- 1st Round: Teams = 7, Matches = 3, and 4 teams advance.\n- 2nd Round: Teams = 4, Matches = 2, and 2 teams advance.\n- 3rd Round: Teams = 2, Matches = 1, and 1 team is declared the winner.\nTotal number of matches = 3 + 2 + 1 = 6.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 14\nOutput: 13\nExplanation: Details of the tournament:\n- 1st Round: Teams = 14, Matches = 7, and 7 teams advance.\n- 2nd Round: Teams = 7, Matches = 3, and 4 teams advance.\n- 3rd Round: Teams = 4, Matches = 2, and 2 teams advance.\n- 4th Round: Teams = 2, Matches = 1, and 1 team is declared the winner.\nTotal number of matches = 7 + 3 + 2 + 1 = 13.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 200
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n \uff0c\u8868\u793a\u6bd4\u8d5b\u4e2d\u7684\u961f\u4f0d\u6570\u3002\u6bd4\u8d5b\u9075\u5faa\u4e00\u79cd\u72ec\u7279\u7684\u8d5b\u5236\uff1a

    \n\n
      \n\t
    • \u5982\u679c\u5f53\u524d\u961f\u4f0d\u6570\u662f \u5076\u6570 \uff0c\u90a3\u4e48\u6bcf\u652f\u961f\u4f0d\u90fd\u4f1a\u4e0e\u53e6\u4e00\u652f\u961f\u4f0d\u914d\u5bf9\u3002\u603b\u5171\u8fdb\u884c n / 2 \u573a\u6bd4\u8d5b\uff0c\u4e14\u4ea7\u751f n / 2 \u652f\u961f\u4f0d\u8fdb\u5165\u4e0b\u4e00\u8f6e\u3002
    • \n\t
    • \u5982\u679c\u5f53\u524d\u961f\u4f0d\u6570\u4e3a \u5947\u6570 \uff0c\u90a3\u4e48\u5c06\u4f1a\u968f\u673a\u8f6e\u7a7a\u5e76\u664b\u7ea7\u4e00\u652f\u961f\u4f0d\uff0c\u5176\u4f59\u7684\u961f\u4f0d\u914d\u5bf9\u3002\u603b\u5171\u8fdb\u884c (n - 1) / 2 \u573a\u6bd4\u8d5b\uff0c\u4e14\u4ea7\u751f (n - 1) / 2 + 1 \u652f\u961f\u4f0d\u8fdb\u5165\u4e0b\u4e00\u8f6e\u3002
    • \n
    \n\n

    \u8fd4\u56de\u5728\u6bd4\u8d5b\u4e2d\u8fdb\u884c\u7684\u914d\u5bf9\u6b21\u6570\uff0c\u76f4\u5230\u51b3\u51fa\u83b7\u80dc\u961f\u4f0d\u4e3a\u6b62\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1an = 7\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u6bd4\u8d5b\u8be6\u60c5\uff1a\n- \u7b2c 1 \u8f6e\uff1a\u961f\u4f0d\u6570 = 7 \uff0c\u914d\u5bf9\u6b21\u6570 = 3 \uff0c4 \u652f\u961f\u4f0d\u664b\u7ea7\u3002\n- \u7b2c 2 \u8f6e\uff1a\u961f\u4f0d\u6570 = 4 \uff0c\u914d\u5bf9\u6b21\u6570 = 2 \uff0c2 \u652f\u961f\u4f0d\u664b\u7ea7\u3002\n- \u7b2c 3 \u8f6e\uff1a\u961f\u4f0d\u6570 = 2 \uff0c\u914d\u5bf9\u6b21\u6570 = 1 \uff0c\u51b3\u51fa 1 \u652f\u83b7\u80dc\u961f\u4f0d\u3002\n\u603b\u914d\u5bf9\u6b21\u6570 = 3 + 2 + 1 = 6\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1an = 14\n\u8f93\u51fa\uff1a13\n\u89e3\u91ca\uff1a\u6bd4\u8d5b\u8be6\u60c5\uff1a\n- \u7b2c 1 \u8f6e\uff1a\u961f\u4f0d\u6570 = 14 \uff0c\u914d\u5bf9\u6b21\u6570 = 7 \uff0c7 \u652f\u961f\u4f0d\u664b\u7ea7\u3002\n- \u7b2c 2 \u8f6e\uff1a\u961f\u4f0d\u6570 = 7 \uff0c\u914d\u5bf9\u6b21\u6570 = 3 \uff0c4 \u652f\u961f\u4f0d\u664b\u7ea7\u3002 \n- \u7b2c 3 \u8f6e\uff1a\u961f\u4f0d\u6570 = 4 \uff0c\u914d\u5bf9\u6b21\u6570 = 2 \uff0c2 \u652f\u961f\u4f0d\u664b\u7ea7\u3002\n- \u7b2c 4 \u8f6e\uff1a\u961f\u4f0d\u6570 = 2 \uff0c\u914d\u5bf9\u6b21\u6570 = 1 \uff0c\u51b3\u51fa 1 \u652f\u83b7\u80dc\u961f\u4f0d\u3002\n\u603b\u914d\u5bf9\u6b21\u6570 = 7 + 3 + 2 + 1 = 13\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 200
    • \n
    \n", "tags_en": ["Backtracking"], "tags_cn": ["\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numberOfMatches(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numberOfMatches(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numberOfMatches(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numberOfMatches(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numberOfMatches(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumberOfMatches(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar numberOfMatches = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef number_of_matches(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numberOfMatches(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numberOfMatches(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numberOfMatches(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numberOfMatches(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn number_of_matches(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function numberOfMatches($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numberOfMatches(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (number-of-matches n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1688](https://leetcode-cn.com/problems/count-of-matches-in-tournament)", "[\u6bd4\u8d5b\u4e2d\u7684\u914d\u5bf9\u6b21\u6570](/solution/1600-1699/1688.Count%20of%20Matches%20in%20Tournament/README.md)", "`\u56de\u6eaf\u7b97\u6cd5`", "\u7b80\u5355", ""], "md_table_row_en": ["[1688](https://leetcode.com/problems/count-of-matches-in-tournament)", "[Count of Matches in Tournament](/solution/1600-1699/1688.Count%20of%20Matches%20in%20Tournament/README_EN.md)", "`Backtracking`", "Easy", ""]}, {"question_id": "1805", "frontend_question_id": "1703", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-adjacent-swaps-for-k-consecutive-ones", "url_en": "https://leetcode.com/problems/minimum-adjacent-swaps-for-k-consecutive-ones", "relative_path_cn": "/solution/1700-1799/1703.Minimum%20Adjacent%20Swaps%20for%20K%20Consecutive%20Ones/README.md", "relative_path_en": "/solution/1700-1799/1703.Minimum%20Adjacent%20Swaps%20for%20K%20Consecutive%20Ones/README_EN.md", "title_cn": "\u5f97\u5230\u8fde\u7eed K \u4e2a 1 \u7684\u6700\u5c11\u76f8\u90bb\u4ea4\u6362\u6b21\u6570", "title_en": "Minimum Adjacent Swaps for K Consecutive Ones", "question_title_slug": "minimum-adjacent-swaps-for-k-consecutive-ones", "content_en": "

    You are given an integer array, nums, and an integer k. nums comprises of only 0's and 1's. In one move, you can choose two adjacent indices and swap their values.

    \n\n

    Return the minimum number of moves required so that nums has k consecutive 1's.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,0,0,1,0,1], k = 2\nOutput: 1\nExplanation: In 1 move, nums could be [1,0,0,0,1,1] and have 2 consecutive 1's.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,0,0,0,0,0,1,1], k = 3\nOutput: 5\nExplanation: In 5 moves, the leftmost 1 can be shifted right until nums = [0,0,0,0,0,1,1,1].\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [1,1,0,1], k = 2\nOutput: 0\nExplanation: nums already has 2 consecutive 1's.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • nums[i] is 0 or 1.
    • \n\t
    • 1 <= k <= sum(nums)
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0nums\u00a0\u548c\u4e00\u4e2a\u6574\u6570\u00a0k\u00a0\u3002\u00a0nums \u4ec5\u5305\u542b\u00a00\u00a0\u548c\u00a01\u00a0\u3002\u6bcf\u4e00\u6b21\u79fb\u52a8\uff0c\u4f60\u53ef\u4ee5\u9009\u62e9 \u76f8\u90bb\u00a0\u4e24\u4e2a\u6570\u5b57\u5e76\u5c06\u5b83\u4eec\u4ea4\u6362\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u4f7f\u00a0nums\u00a0\u4e2d\u5305\u542b\u00a0k\u00a0\u4e2a \u8fde\u7eed\u00a01\u00a0\u7684 \u6700\u5c11\u00a0\u4ea4\u6362\u6b21\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,0,0,1,0,1], k = 2\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u5728\u7b2c\u4e00\u6b21\u64cd\u4f5c\u65f6\uff0cnums \u53ef\u4ee5\u53d8\u6210 [1,0,0,0,1,1] \u5f97\u5230\u8fde\u7eed\u4e24\u4e2a 1 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,0,0,0,0,0,1,1], k = 3\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u901a\u8fc7 5 \u6b21\u64cd\u4f5c\uff0c\u6700\u5de6\u8fb9\u7684 1 \u53ef\u4ee5\u79fb\u5230\u53f3\u8fb9\u76f4\u5230 nums \u53d8\u4e3a [0,0,0,0,0,1,1,1] \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,1,0,1], k = 2\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1anums \u5df2\u7ecf\u6709\u8fde\u7eed 2 \u4e2a 1 \u4e86\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • nums[i] \u8981\u4e48\u662f\u00a00\u00a0\uff0c\u8981\u4e48\u662f\u00a01\u00a0\u3002
    • \n\t
    • 1 <= k <= sum(nums)
    • \n
    \n", "tags_en": ["Stack"], "tags_cn": ["\u6808"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minMoves(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minMoves(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minMoves(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minMoves(self, nums: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minMoves(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinMoves(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar minMoves = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef min_moves(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minMoves(_ nums: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minMoves(nums []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minMoves(nums: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minMoves(nums: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_moves(nums: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer\n */\n function minMoves($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minMoves(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-moves nums k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1703](https://leetcode-cn.com/problems/minimum-adjacent-swaps-for-k-consecutive-ones)", "[\u5f97\u5230\u8fde\u7eed K \u4e2a 1 \u7684\u6700\u5c11\u76f8\u90bb\u4ea4\u6362\u6b21\u6570](/solution/1700-1799/1703.Minimum%20Adjacent%20Swaps%20for%20K%20Consecutive%20Ones/README.md)", "`\u6808`", "\u56f0\u96be", ""], "md_table_row_en": ["[1703](https://leetcode.com/problems/minimum-adjacent-swaps-for-k-consecutive-ones)", "[Minimum Adjacent Swaps for K Consecutive Ones](/solution/1700-1799/1703.Minimum%20Adjacent%20Swaps%20for%20K%20Consecutive%20Ones/README_EN.md)", "`Stack`", "Hard", ""]}, {"question_id": "1804", "frontend_question_id": "1702", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-binary-string-after-change", "url_en": "https://leetcode.com/problems/maximum-binary-string-after-change", "relative_path_cn": "/solution/1700-1799/1702.Maximum%20Binary%20String%20After%20Change/README.md", "relative_path_en": "/solution/1700-1799/1702.Maximum%20Binary%20String%20After%20Change/README_EN.md", "title_cn": "\u4fee\u6539\u540e\u7684\u6700\u5927\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32", "title_en": "Maximum Binary String After Change", "question_title_slug": "maximum-binary-string-after-change", "content_en": "

    You are given a binary string binary consisting of only 0's or 1's. You can apply each of the following operations any number of times:

    \n\n
      \n\t
    • Operation 1: If the number contains the substring "00", you can replace it with "10".\n\n\t
        \n\t\t
      • For example, "00010" -> "10010"
      • \n\t
      \n\t
    • \n\t
    • Operation 2: If the number contains the substring "10", you can replace it with "01".\n\t
        \n\t\t
      • For example, "00010" -> "00001"
      • \n\t
      \n\t
    • \n
    \n\n

    Return the maximum binary string you can obtain after any number of operations. Binary string x is greater than binary string y if x's decimal representation is greater than y's decimal representation.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: binary = "000110"\nOutput: "111011"\nExplanation: A valid transformation sequence can be:\n"000110" -> "000101" \n"000101" -> "100101" \n"100101" -> "110101" \n"110101" -> "110011" \n"110011" -> "111011"\n
    \n\n

    Example 2:

    \n\n
    \nInput: binary = "01"\nOutput: "01"\nExplanation: "01" cannot be transformed any further.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= binary.length <= 105
    • \n\t
    • binary consist of '0' and '1'.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32\u00a0binary\u00a0\uff0c\u5b83\u4ec5\u6709\u00a00\u00a0\u6216\u8005\u00a01\u00a0\u7ec4\u6210\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u4e0b\u9762\u7684\u64cd\u4f5c\u4efb\u610f\u6b21\u5bf9\u5b83\u8fdb\u884c\u4fee\u6539\uff1a

    \n\n
      \n\t
    • \u64cd\u4f5c 1 \uff1a\u5982\u679c\u4e8c\u8fdb\u5236\u4e32\u5305\u542b\u5b50\u5b57\u7b26\u4e32\u00a0\"00\"\u00a0\uff0c\u4f60\u53ef\u4ee5\u7528\u00a0\"10\"\u00a0\u5c06\u5176\u66ff\u6362\u3002\n\n\t
        \n\t\t
      • \u6bd4\u65b9\u8bf4\uff0c\u00a0\"00010\" -> \"10010\"
      • \n\t
      \n\t
    • \n\t
    • \u64cd\u4f5c 2 \uff1a\u5982\u679c\u4e8c\u8fdb\u5236\u4e32\u5305\u542b\u5b50\u5b57\u7b26\u4e32\u00a0\"10\"\u00a0\uff0c\u4f60\u53ef\u4ee5\u7528\u00a0\"01\"\u00a0\u5c06\u5176\u66ff\u6362\u3002\n\t
        \n\t\t
      • \u6bd4\u65b9\u8bf4\uff0c\u00a0\"00010\" -> \"00001\"
      • \n\t
      \n\t
    • \n
    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u6267\u884c\u4e0a\u8ff0\u64cd\u4f5c\u4efb\u610f\u6b21\u4ee5\u540e\u80fd\u5f97\u5230\u7684 \u6700\u5927\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32\u00a0\u3002\u5982\u679c\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32 x\u00a0\u5bf9\u5e94\u7684\u5341\u8fdb\u5236\u6570\u5b57\u5927\u4e8e\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32 y\u00a0\u5bf9\u5e94\u7684\u5341\u8fdb\u5236\u6570\u5b57\uff0c\u90a3\u4e48\u6211\u4eec\u79f0\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32\u00a0x\u00a0\u5927\u4e8e\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32\u00a0y\u00a0\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1abinary = \"000110\"\n\u8f93\u51fa\uff1a\"111011\"\n\u89e3\u91ca\uff1a\u4e00\u4e2a\u53ef\u884c\u7684\u8f6c\u6362\u4e3a\uff1a\n\"000110\" -> \"000101\" \n\"000101\" -> \"100101\" \n\"100101\" -> \"110101\" \n\"110101\" -> \"110011\" \n\"110011\" -> \"111011\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1abinary = \"01\"\n\u8f93\u51fa\uff1a\"01\"\n\u89e3\u91ca\uff1a\"01\" \u6ca1\u529e\u6cd5\u8fdb\u884c\u4efb\u4f55\u8f6c\u6362\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= binary.length <= 105
    • \n\t
    • binary \u4ec5\u5305\u542b\u00a0'0' \u548c\u00a0'1' \u3002
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string maximumBinaryString(string binary) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String maximumBinaryString(String binary) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximumBinaryString(self, binary):\n \"\"\"\n :type binary: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximumBinaryString(self, binary: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * maximumBinaryString(char * binary){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string MaximumBinaryString(string binary) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} binary\n * @return {string}\n */\nvar maximumBinaryString = function(binary) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} binary\n# @return {String}\ndef maximum_binary_string(binary)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximumBinaryString(_ binary: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximumBinaryString(binary string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximumBinaryString(binary: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximumBinaryString(binary: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximum_binary_string(binary: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $binary\n * @return String\n */\n function maximumBinaryString($binary) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximumBinaryString(binary: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximum-binary-string binary)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1702](https://leetcode-cn.com/problems/maximum-binary-string-after-change)", "[\u4fee\u6539\u540e\u7684\u6700\u5927\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32](/solution/1700-1799/1702.Maximum%20Binary%20String%20After%20Change/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1702](https://leetcode.com/problems/maximum-binary-string-after-change)", "[Maximum Binary String After Change](/solution/1700-1799/1702.Maximum%20Binary%20String%20After%20Change/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1803", "frontend_question_id": "1701", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/average-waiting-time", "url_en": "https://leetcode.com/problems/average-waiting-time", "relative_path_cn": "/solution/1700-1799/1701.Average%20Waiting%20Time/README.md", "relative_path_en": "/solution/1700-1799/1701.Average%20Waiting%20Time/README_EN.md", "title_cn": "\u5e73\u5747\u7b49\u5f85\u65f6\u95f4", "title_en": "Average Waiting Time", "question_title_slug": "average-waiting-time", "content_en": "

    There is a restaurant with a single chef. You are given an array customers, where customers[i] = [arrivali, timei]:

    \n\n
      \n\t
    • arrivali is the arrival time of the ith customer. The arrival times are sorted in non-decreasing order.
    • \n\t
    • timei is the time needed to prepare the order of the ith customer.
    • \n
    \n\n

    When a customer arrives, he gives the chef his order, and the chef starts preparing it once he is idle. The customer waits till the chef finishes preparing his order. The chef does not prepare food for more than one customer at a time. The chef prepares food for customers in the order they were given in the input.

    \n\n

    Return the average waiting time of all customers. Solutions within 10-5 from the actual answer are considered accepted.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: customers = [[1,2],[2,5],[4,3]]\nOutput: 5.00000\nExplanation:\n1) The first customer arrives at time 1, the chef takes his order and starts preparing it immediately at time 1, and finishes at time 3, so the waiting time of the first customer is 3 - 1 = 2.\n2) The second customer arrives at time 2, the chef takes his order and starts preparing it at time 3, and finishes at time 8, so the waiting time of the second customer is 8 - 2 = 6.\n3) The third customer arrives at time 4, the chef takes his order and starts preparing it at time 8, and finishes at time 11, so the waiting time of the third customer is 11 - 4 = 7.\nSo the average waiting time = (2 + 6 + 7) / 3 = 5.\n
    \n\n

    Example 2:

    \n\n
    \nInput: customers = [[5,2],[5,4],[10,3],[20,1]]\nOutput: 3.25000\nExplanation:\n1) The first customer arrives at time 5, the chef takes his order and starts preparing it immediately at time 5, and finishes at time 7, so the waiting time of the first customer is 7 - 5 = 2.\n2) The second customer arrives at time 5, the chef takes his order and starts preparing it at time 7, and finishes at time 11, so the waiting time of the second customer is 11 - 5 = 6.\n3) The third customer arrives at time 10, the chef takes his order and starts preparing it at time 11, and finishes at time 14, so the waiting time of the third customer is 14 - 10 = 4.\n4) The fourth customer arrives at time 20, the chef takes his order and starts preparing it immediately at time 20, and finishes at time 21, so the waiting time of the fourth customer is 21 - 20 = 1.\nSo the average waiting time = (2 + 6 + 4 + 1) / 4 = 3.25.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= customers.length <= 105
    • \n\t
    • 1 <= arrivali, timei <= 104
    • \n\t
    • arrival<= arrivali+1
    • \n
    \n", "content_cn": "

    \u6709\u4e00\u4e2a\u9910\u5385\uff0c\u53ea\u6709\u4e00\u4f4d\u53a8\u5e08\u3002\u4f60\u6709\u4e00\u4e2a\u987e\u5ba2\u6570\u7ec4\u00a0customers\u00a0\uff0c\u5176\u4e2d\u00a0customers[i] = [arrivali, timei]\u00a0\uff1a

    \n\n
      \n\t
    • arrivali\u00a0\u662f\u7b2c\u00a0i\u00a0\u4f4d\u987e\u5ba2\u5230\u8fbe\u7684\u65f6\u95f4\uff0c\u5230\u8fbe\u65f6\u95f4\u6309 \u975e\u9012\u51cf \u987a\u5e8f\u6392\u5217\u3002
    • \n\t
    • timei\u00a0\u662f\u7ed9\u7b2c i\u00a0\u4f4d\u987e\u5ba2\u505a\u83dc\u9700\u8981\u7684\u65f6\u95f4\u3002
    • \n
    \n\n

    \u5f53\u4e00\u4f4d\u987e\u5ba2\u5230\u8fbe\u65f6\uff0c\u4ed6\u5c06\u4ed6\u7684\u8ba2\u5355\u7ed9\u53a8\u5e08\uff0c\u53a8\u5e08\u4e00\u65e6\u7a7a\u95f2\u7684\u65f6\u5019\u5c31\u5f00\u59cb\u505a\u8fd9\u4f4d\u987e\u5ba2\u7684\u83dc\u3002\u6bcf\u4f4d\u987e\u5ba2\u4f1a\u4e00\u76f4\u7b49\u5f85\u5230\u53a8\u5e08\u5b8c\u6210\u4ed6\u7684\u8ba2\u5355\u3002\u53a8\u5e08\u540c\u65f6\u53ea\u80fd\u505a\u4e00\u4e2a\u4eba\u7684\u8ba2\u5355\u3002\u53a8\u5e08\u4f1a\u4e25\u683c\u6309\u7167 \u8ba2\u5355\u7ed9\u4ed6\u7684\u987a\u5e8f\u00a0\u505a\u83dc\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u6240\u6709\u987e\u5ba2\u9700\u8981\u7b49\u5f85\u7684 \u5e73\u5747\u00a0\u65f6\u95f4\u3002\u4e0e\u6807\u51c6\u7b54\u6848\u8bef\u5dee\u5728\u00a010-5\u00a0\u8303\u56f4\u4ee5\u5185\uff0c\u90fd\u89c6\u4e3a\u6b63\u786e\u7ed3\u679c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1acustomers = [[1,2],[2,5],[4,3]]\n\u8f93\u51fa\uff1a5.00000\n\u89e3\u91ca\uff1a\n1) \u7b2c\u4e00\u4f4d\u987e\u5ba2\u5728\u65f6\u523b 1 \u5230\u8fbe\uff0c\u53a8\u5e08\u62ff\u5230\u4ed6\u7684\u8ba2\u5355\u5e76\u5728\u65f6\u523b 1 \u7acb\u9a6c\u5f00\u59cb\u505a\u83dc\uff0c\u5e76\u5728\u65f6\u523b 3 \u5b8c\u6210\uff0c\u7b2c\u4e00\u4f4d\u987e\u5ba2\u7b49\u5f85\u65f6\u95f4\u4e3a 3 - 1 = 2 \u3002\n2) \u7b2c\u4e8c\u4f4d\u987e\u5ba2\u5728\u65f6\u523b 2 \u5230\u8fbe\uff0c\u53a8\u5e08\u5728\u65f6\u523b 3 \u5f00\u59cb\u4e3a\u4ed6\u505a\u83dc\uff0c\u5e76\u5728\u65f6\u523b 8 \u5b8c\u6210\uff0c\u7b2c\u4e8c\u4f4d\u987e\u5ba2\u7b49\u5f85\u65f6\u95f4\u4e3a 8 - 2 = 6 \u3002\n3) \u7b2c\u4e09\u4f4d\u987e\u5ba2\u5728\u65f6\u523b 4 \u5230\u8fbe\uff0c\u53a8\u5e08\u5728\u65f6\u523b 8 \u5f00\u59cb\u4e3a\u4ed6\u505a\u83dc\uff0c\u5e76\u5728\u65f6\u523b 11 \u5b8c\u6210\uff0c\u7b2c\u4e09\u4f4d\u987e\u5ba2\u7b49\u5f85\u65f6\u95f4\u4e3a 11 - 4 = 7 \u3002\n\u5e73\u5747\u7b49\u5f85\u65f6\u95f4\u4e3a (2 + 6 + 7) / 3 = 5 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1acustomers = [[5,2],[5,4],[10,3],[20,1]]\n\u8f93\u51fa\uff1a3.25000\n\u89e3\u91ca\uff1a\n1) \u7b2c\u4e00\u4f4d\u987e\u5ba2\u5728\u65f6\u523b 5 \u5230\u8fbe\uff0c\u53a8\u5e08\u62ff\u5230\u4ed6\u7684\u8ba2\u5355\u5e76\u5728\u65f6\u523b 5 \u7acb\u9a6c\u5f00\u59cb\u505a\u83dc\uff0c\u5e76\u5728\u65f6\u523b 7 \u5b8c\u6210\uff0c\u7b2c\u4e00\u4f4d\u987e\u5ba2\u7b49\u5f85\u65f6\u95f4\u4e3a 7 - 5 = 2 \u3002\n2) \u7b2c\u4e8c\u4f4d\u987e\u5ba2\u5728\u65f6\u523b 5 \u5230\u8fbe\uff0c\u53a8\u5e08\u5728\u65f6\u523b 7 \u5f00\u59cb\u4e3a\u4ed6\u505a\u83dc\uff0c\u5e76\u5728\u65f6\u523b 11 \u5b8c\u6210\uff0c\u7b2c\u4e8c\u4f4d\u987e\u5ba2\u7b49\u5f85\u65f6\u95f4\u4e3a 11 - 5 = 6 \u3002\n3) \u7b2c\u4e09\u4f4d\u987e\u5ba2\u5728\u65f6\u523b 10 \u5230\u8fbe\uff0c\u53a8\u5e08\u5728\u65f6\u523b 11 \u5f00\u59cb\u4e3a\u4ed6\u505a\u83dc\uff0c\u5e76\u5728\u65f6\u523b 14 \u5b8c\u6210\uff0c\u7b2c\u4e09\u4f4d\u987e\u5ba2\u7b49\u5f85\u65f6\u95f4\u4e3a 14 - 10 = 4 \u3002\n4) \u7b2c\u56db\u4f4d\u987e\u5ba2\u5728\u65f6\u523b 20 \u5230\u8fbe\uff0c\u53a8\u5e08\u62ff\u5230\u4ed6\u7684\u8ba2\u5355\u5e76\u5728\u65f6\u523b 20 \u7acb\u9a6c\u5f00\u59cb\u505a\u83dc\uff0c\u5e76\u5728\u65f6\u523b 21 \u5b8c\u6210\uff0c\u7b2c\u56db\u4f4d\u987e\u5ba2\u7b49\u5f85\u65f6\u95f4\u4e3a 21 - 20 = 1 \u3002\n\u5e73\u5747\u7b49\u5f85\u65f6\u95f4\u4e3a (2 + 6 + 4 + 1) / 4 = 3.25 \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= customers.length <= 105
    • \n\t
    • 1 <= arrivali, timei <= 104
    • \n\t
    • arrivali\u00a0<= arrivali+1
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n double averageWaitingTime(vector>& customers) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double averageWaitingTime(int[][] customers) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def averageWaitingTime(self, customers):\n \"\"\"\n :type customers: List[List[int]]\n :rtype: float\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def averageWaitingTime(self, customers: List[List[int]]) -> float:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\ndouble averageWaitingTime(int** customers, int customersSize, int* customersColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double AverageWaitingTime(int[][] customers) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} customers\n * @return {number}\n */\nvar averageWaitingTime = function(customers) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} customers\n# @return {Float}\ndef average_waiting_time(customers)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func averageWaitingTime(_ customers: [[Int]]) -> Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func averageWaitingTime(customers [][]int) float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def averageWaitingTime(customers: Array[Array[Int]]): Double = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun averageWaitingTime(customers: Array): Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn average_waiting_time(customers: Vec>) -> f64 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $customers\n * @return Float\n */\n function averageWaitingTime($customers) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function averageWaitingTime(customers: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (average-waiting-time customers)\n (-> (listof (listof exact-integer?)) flonum?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1701](https://leetcode-cn.com/problems/average-waiting-time)", "[\u5e73\u5747\u7b49\u5f85\u65f6\u95f4](/solution/1700-1799/1701.Average%20Waiting%20Time/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1701](https://leetcode.com/problems/average-waiting-time)", "[Average Waiting Time](/solution/1700-1799/1701.Average%20Waiting%20Time/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "1802", "frontend_question_id": "1700", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-students-unable-to-eat-lunch", "url_en": "https://leetcode.com/problems/number-of-students-unable-to-eat-lunch", "relative_path_cn": "/solution/1700-1799/1700.Number%20of%20Students%20Unable%20to%20Eat%20Lunch/README.md", "relative_path_en": "/solution/1700-1799/1700.Number%20of%20Students%20Unable%20to%20Eat%20Lunch/README_EN.md", "title_cn": "\u65e0\u6cd5\u5403\u5348\u9910\u7684\u5b66\u751f\u6570\u91cf", "title_en": "Number of Students Unable to Eat Lunch", "question_title_slug": "number-of-students-unable-to-eat-lunch", "content_en": "

    The school cafeteria offers circular and square sandwiches at lunch break, referred to by numbers 0 and 1 respectively. All students stand in a queue. Each student either prefers square or circular sandwiches.

    \n\n

    The number of sandwiches in the cafeteria is equal to the number of students. The sandwiches are placed in a stack. At each step:

    \n\n
      \n\t
    • If the student at the front of the queue prefers the sandwich on the top of the stack, they will take it and leave the queue.
    • \n\t
    • Otherwise, they will leave it and go to the queue's end.
    • \n
    \n\n

    This continues until none of the queue students want to take the top sandwich and are thus unable to eat.

    \n\n

    You are given two integer arrays students and sandwiches where sandwiches[i] is the type of the i\u200b\u200b\u200b\u200b\u200b\u200bth sandwich in the stack (i = 0 is the top of the stack) and students[j] is the preference of the j\u200b\u200b\u200b\u200b\u200b\u200bth student in the initial queue (j = 0 is the front of the queue). Return the number of students that are unable to eat.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: students = [1,1,0,0], sandwiches = [0,1,0,1]\nOutput: 0 \nExplanation:\n- Front student leaves the top sandwich and returns to the end of the line making students = [1,0,0,1].\n- Front student leaves the top sandwich and returns to the end of the line making students = [0,0,1,1].\n- Front student takes the top sandwich and leaves the line making students = [0,1,1] and sandwiches = [1,0,1].\n- Front student leaves the top sandwich and returns to the end of the line making students = [1,1,0].\n- Front student takes the top sandwich and leaves the line making students = [1,0] and sandwiches = [0,1].\n- Front student leaves the top sandwich and returns to the end of the line making students = [0,1].\n- Front student takes the top sandwich and leaves the line making students = [1] and sandwiches = [1].\n- Front student takes the top sandwich and leaves the line making students = [] and sandwiches = [].\nHence all students are able to eat.\n
    \n\n

    Example 2:

    \n\n
    \nInput: students = [1,1,1,0,0,1], sandwiches = [1,0,0,0,1,1]\nOutput: 3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= students.length, sandwiches.length <= 100
    • \n\t
    • students.length == sandwiches.length
    • \n\t
    • sandwiches[i] is 0 or 1.
    • \n\t
    • students[i] is 0 or 1.
    • \n
    \n", "content_cn": "

    \u5b66\u6821\u7684\u81ea\u52a9\u5348\u9910\u63d0\u4f9b\u5706\u5f62\u548c\u65b9\u5f62\u7684\u4e09\u660e\u6cbb\uff0c\u5206\u522b\u7528\u6570\u5b57\u00a00\u00a0\u548c\u00a01\u00a0\u8868\u793a\u3002\u6240\u6709\u5b66\u751f\u7ad9\u5728\u4e00\u4e2a\u961f\u5217\u91cc\uff0c\u6bcf\u4e2a\u5b66\u751f\u8981\u4e48\u559c\u6b22\u5706\u5f62\u7684\u8981\u4e48\u559c\u6b22\u65b9\u5f62\u7684\u3002
    \n\u9910\u5385\u91cc\u4e09\u660e\u6cbb\u7684\u6570\u91cf\u4e0e\u5b66\u751f\u7684\u6570\u91cf\u76f8\u540c\u3002\u6240\u6709\u4e09\u660e\u6cbb\u90fd\u653e\u5728\u4e00\u4e2a\u00a0\u6808\u00a0\u91cc\uff0c\u6bcf\u4e00\u8f6e\uff1a

    \n\n
      \n\t
    • \u5982\u679c\u961f\u5217\u6700\u524d\u9762\u7684\u5b66\u751f\u00a0\u559c\u6b22\u00a0\u6808\u9876\u7684\u4e09\u660e\u6cbb\uff0c\u90a3\u4e48\u4f1a\u00a0\u62ff\u8d70\u5b83\u00a0\u5e76\u79bb\u5f00\u961f\u5217\u3002
    • \n\t
    • \u5426\u5219\uff0c\u8fd9\u540d\u5b66\u751f\u4f1a\u00a0\u653e\u5f03\u8fd9\u4e2a\u4e09\u660e\u6cbb\u00a0\u5e76\u56de\u5230\u961f\u5217\u7684\u5c3e\u90e8\u3002
    • \n
    \n\n

    \u8fd9\u4e2a\u8fc7\u7a0b\u4f1a\u4e00\u76f4\u6301\u7eed\u5230\u961f\u5217\u91cc\u6240\u6709\u5b66\u751f\u90fd\u4e0d\u559c\u6b22\u6808\u9876\u7684\u4e09\u660e\u6cbb\u4e3a\u6b62\u3002

    \n\n

    \u7ed9\u4f60\u4e24\u4e2a\u6574\u6570\u6570\u7ec4\u00a0students \u548c\u00a0sandwiches\u00a0\uff0c\u5176\u4e2d\u00a0sandwiches[i]\u00a0\u662f\u6808\u91cc\u9762\u7b2c\u00a0i\u200b\u200b\u200b\u200b\u200b\u200b\u00a0\u4e2a\u4e09\u660e\u6cbb\u7684\u7c7b\u578b\uff08i = 0\u00a0\u662f\u6808\u7684\u9876\u90e8\uff09\uff0c\u00a0students[j]\u00a0\u662f\u521d\u59cb\u961f\u5217\u91cc\u7b2c\u00a0j\u200b\u200b\u200b\u200b\u200b\u200b\u00a0\u540d\u5b66\u751f\u5bf9\u4e09\u660e\u6cbb\u7684\u559c\u597d\uff08j = 0\u00a0\u662f\u961f\u5217\u7684\u6700\u5f00\u59cb\u4f4d\u7f6e\uff09\u3002\u8bf7\u4f60\u8fd4\u56de\u65e0\u6cd5\u5403\u5348\u9910\u7684\u5b66\u751f\u6570\u91cf\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1astudents = [1,1,0,0], sandwiches = [0,1,0,1]\n\u8f93\u51fa\uff1a0 \n\u89e3\u91ca\uff1a\n- \u6700\u524d\u9762\u7684\u5b66\u751f\u653e\u5f03\u6700\u9876\u4e0a\u7684\u4e09\u660e\u6cbb\uff0c\u5e76\u56de\u5230\u961f\u5217\u7684\u672b\u5c3e\uff0c\u5b66\u751f\u961f\u5217\u53d8\u4e3a students = [1,0,0,1]\u3002\n- \u6700\u524d\u9762\u7684\u5b66\u751f\u653e\u5f03\u6700\u9876\u4e0a\u7684\u4e09\u660e\u6cbb\uff0c\u5e76\u56de\u5230\u961f\u5217\u7684\u672b\u5c3e\uff0c\u5b66\u751f\u961f\u5217\u53d8\u4e3a students = [0,0,1,1]\u3002\n- \u6700\u524d\u9762\u7684\u5b66\u751f\u62ff\u8d70\u6700\u9876\u4e0a\u7684\u4e09\u660e\u6cbb\uff0c\u5269\u4f59\u5b66\u751f\u961f\u5217\u4e3a students = [0,1,1]\uff0c\u4e09\u660e\u6cbb\u6808\u4e3a sandwiches = [1,0,1]\u3002\n- \u6700\u524d\u9762\u7684\u5b66\u751f\u653e\u5f03\u6700\u9876\u4e0a\u7684\u4e09\u660e\u6cbb\uff0c\u5e76\u56de\u5230\u961f\u5217\u7684\u672b\u5c3e\uff0c\u5b66\u751f\u961f\u5217\u53d8\u4e3a students = [1,1,0]\u3002\n- \u6700\u524d\u9762\u7684\u5b66\u751f\u62ff\u8d70\u6700\u9876\u4e0a\u7684\u4e09\u660e\u6cbb\uff0c\u5269\u4f59\u5b66\u751f\u961f\u5217\u4e3a students = [1,0]\uff0c\u4e09\u660e\u6cbb\u6808\u4e3a sandwiches = [0,1]\u3002\n- \u6700\u524d\u9762\u7684\u5b66\u751f\u653e\u5f03\u6700\u9876\u4e0a\u7684\u4e09\u660e\u6cbb\uff0c\u5e76\u56de\u5230\u961f\u5217\u7684\u672b\u5c3e\uff0c\u5b66\u751f\u961f\u5217\u53d8\u4e3a students = [0,1]\u3002\n- \u6700\u524d\u9762\u7684\u5b66\u751f\u62ff\u8d70\u6700\u9876\u4e0a\u7684\u4e09\u660e\u6cbb\uff0c\u5269\u4f59\u5b66\u751f\u961f\u5217\u4e3a students = [1]\uff0c\u4e09\u660e\u6cbb\u6808\u4e3a sandwiches = [1]\u3002\n- \u6700\u524d\u9762\u7684\u5b66\u751f\u62ff\u8d70\u6700\u9876\u4e0a\u7684\u4e09\u660e\u6cbb\uff0c\u5269\u4f59\u5b66\u751f\u961f\u5217\u4e3a students = []\uff0c\u4e09\u660e\u6cbb\u6808\u4e3a sandwiches = []\u3002\n\u6240\u4ee5\u6240\u6709\u5b66\u751f\u90fd\u6709\u4e09\u660e\u6cbb\u5403\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1astudents = [1,1,1,0,0,1], sandwiches = [1,0,0,0,1,1]\n\u8f93\u51fa\uff1a3\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= students.length, sandwiches.length <= 100
    • \n\t
    • students.length == sandwiches.length
    • \n\t
    • sandwiches[i]\u00a0\u8981\u4e48\u662f\u00a00\u00a0\uff0c\u8981\u4e48\u662f\u00a01\u00a0\u3002
    • \n\t
    • students[i]\u00a0\u8981\u4e48\u662f\u00a00\u00a0\uff0c\u8981\u4e48\u662f\u00a01\u00a0\u3002
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countStudents(vector& students, vector& sandwiches) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countStudents(int[] students, int[] sandwiches) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countStudents(self, students, sandwiches):\n \"\"\"\n :type students: List[int]\n :type sandwiches: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countStudents(self, students: List[int], sandwiches: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countStudents(int* students, int studentsSize, int* sandwiches, int sandwichesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountStudents(int[] students, int[] sandwiches) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} students\n * @param {number[]} sandwiches\n * @return {number}\n */\nvar countStudents = function(students, sandwiches) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} students\n# @param {Integer[]} sandwiches\n# @return {Integer}\ndef count_students(students, sandwiches)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countStudents(_ students: [Int], _ sandwiches: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countStudents(students []int, sandwiches []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countStudents(students: Array[Int], sandwiches: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countStudents(students: IntArray, sandwiches: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_students(students: Vec, sandwiches: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $students\n * @param Integer[] $sandwiches\n * @return Integer\n */\n function countStudents($students, $sandwiches) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countStudents(students: number[], sandwiches: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-students students sandwiches)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1700](https://leetcode-cn.com/problems/number-of-students-unable-to-eat-lunch)", "[\u65e0\u6cd5\u5403\u5348\u9910\u7684\u5b66\u751f\u6570\u91cf](/solution/1700-1799/1700.Number%20of%20Students%20Unable%20to%20Eat%20Lunch/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1700](https://leetcode.com/problems/number-of-students-unable-to-eat-lunch)", "[Number of Students Unable to Eat Lunch](/solution/1700-1799/1700.Number%20of%20Students%20Unable%20to%20Eat%20Lunch/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1801", "frontend_question_id": "1661", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/average-time-of-process-per-machine", "url_en": "https://leetcode.com/problems/average-time-of-process-per-machine", "relative_path_cn": "/solution/1600-1699/1661.Average%20Time%20of%20Process%20per%20Machine/README.md", "relative_path_en": "/solution/1600-1699/1661.Average%20Time%20of%20Process%20per%20Machine/README_EN.md", "title_cn": "\u6bcf\u53f0\u673a\u5668\u7684\u8fdb\u7a0b\u5e73\u5747\u8fd0\u884c\u65f6\u95f4", "title_en": "Average Time of Process per Machine", "question_title_slug": "average-time-of-process-per-machine", "content_en": "

    Table: Activity

    \n\n
    \n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| machine_id     | int     |\n| process_id     | int     |\n| activity_type  | enum    |\n| timestamp      | float   |\n+----------------+---------+\nThe table shows the user activities for a factory website.\n(machine_id, process_id, activity_type) is the primary key of this table.\nmachine_id is the ID of a machine.\nprocess_id is the ID of a process running on the machine with ID machine_id.\nactivity_type is an ENUM of type ('start', 'end').\ntimestamp is a float representing the current time in seconds.\n'start' means the machine starts the process at the given timestamp and 'end' means the machine ends the process at the given timestamp.\nThe 'start' timestamp will always be before the 'end' timestamp for every (machine_id, process_id) pair.
    \n\n

     

    \n\n

    There is a factory website that has several machines each running the same number of processes. Write an SQL query to find the average time each machine takes to complete a process.

    \n\n

    The time to complete a process is the 'end' timestamp minus the 'start' timestamp. The average time is calculated by the total time to complete every process on the machine divided by the number of processes that were run.

    \n\n

    The resulting table should have the machine_id along with the average time as processing_time, which should be rounded to 3 decimal places.

    \n\n

    The query result format is in the following example:

    \n\n

     

    \n\n
    \nActivity table:\n+------------+------------+---------------+-----------+\n| machine_id | process_id | activity_type | timestamp |\n+------------+------------+---------------+-----------+\n| 0          | 0          | start         | 0.712     |\n| 0          | 0          | end           | 1.520     |\n| 0          | 1          | start         | 3.140     |\n| 0          | 1          | end           | 4.120     |\n| 1          | 0          | start         | 0.550     |\n| 1          | 0          | end           | 1.550     |\n| 1          | 1          | start         | 0.430     |\n| 1          | 1          | end           | 1.420     |\n| 2          | 0          | start         | 4.100     |\n| 2          | 0          | end           | 4.512     |\n| 2          | 1          | start         | 2.500     |\n| 2          | 1          | end           | 5.000     |\n+------------+------------+---------------+-----------+\n\nResult table:\n+------------+-----------------+\n| machine_id | processing_time |\n+------------+-----------------+\n| 0          | 0.894           |\n| 1          | 0.995           |\n| 2          | 1.456           |\n+------------+-----------------+\n\nThere are 3 machines running 2 processes each.\nMachine 0's average time is ((1.520 - 0.712) + (4.120 - 3.140)) / 2 = 0.894\nMachine 1's average time is ((1.550 - 0.550) + (1.420 - 0.430)) / 2 = 0.995\nMachine 2's average time is ((4.512 - 4.100) + (5.000 - 2.500)) / 2 = 1.456\n
    \n", "content_cn": "

    \u8868: Activity

    \n\n
    +----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| machine_id     | int     |\n| process_id     | int     |\n| activity_type  | enum    |\n| timestamp      | float   |\n+----------------+---------+\n\u8be5\u8868\u5c55\u793a\u4e86\u4e00\u5bb6\u5de5\u5382\u7f51\u7ad9\u7684\u7528\u6237\u6d3b\u52a8.\n(machine_id, process_id, activity_type) \u662f\u5f53\u524d\u8868\u7684\u4e3b\u952e.\nmachine_id \u662f\u4e00\u53f0\u673a\u5668\u7684ID\u53f7.\nprocess_id \u662f\u8fd0\u884c\u5728\u5404\u673a\u5668\u4e0a\u7684\u8fdb\u7a0bID\u53f7.\nactivity_type \u662f\u679a\u4e3e\u7c7b\u578b ('start', 'end').\ntimestamp \u662f\u6d6e\u70b9\u7c7b\u578b,\u4ee3\u8868\u5f53\u524d\u65f6\u95f4(\u4ee5\u79d2\u4e3a\u5355\u4f4d).\n'start' \u4ee3\u8868\u8be5\u8fdb\u7a0b\u5728\u8fd9\u53f0\u673a\u5668\u4e0a\u7684\u5f00\u59cb\u8fd0\u884c\u65f6\u95f4\u6233 , 'end' \u4ee3\u8868\u8be5\u8fdb\u7a0b\u5728\u8fd9\u53f0\u673a\u5668\u4e0a\u7684\u7ec8\u6b62\u8fd0\u884c\u65f6\u95f4\u6233.\n\u540c\u4e00\u53f0\u673a\u5668\uff0c\u540c\u4e00\u4e2a\u8fdb\u7a0b\u90fd\u6709\u4e00\u5bf9\u5f00\u59cb\u65f6\u95f4\u6233\u548c\u7ed3\u675f\u65f6\u95f4\u6233\uff0c\u800c\u4e14\u5f00\u59cb\u65f6\u95f4\u6233\u6c38\u8fdc\u5728\u7ed3\u675f\u65f6\u95f4\u6233\u524d\u9762.
    \n\n

    \u00a0

    \n\n

    \u73b0\u5728\u6709\u4e00\u4e2a\u5de5\u5382\u7f51\u7ad9\u7531\u51e0\u53f0\u673a\u5668\u8fd0\u884c\uff0c\u6bcf\u53f0\u673a\u5668\u4e0a\u8fd0\u884c\u7740\u76f8\u540c\u6570\u91cf\u7684\u8fdb\u7a0b. \u8bf7\u5199\u51fa\u4e00\u6761SQL\u8ba1\u7b97\u6bcf\u53f0\u673a\u5668\u5404\u81ea\u5b8c\u6210\u4e00\u4e2a\u8fdb\u7a0b\u4efb\u52a1\u7684\u5e73\u5747\u8017\u65f6.

    \n\n

    \u5b8c\u6210\u4e00\u4e2a\u8fdb\u7a0b\u4efb\u52a1\u7684\u65f6\u95f4\u6307\u8fdb\u7a0b\u7684'end' \u65f6\u95f4\u6233 \u51cf\u53bb\u00a0'start' \u65f6\u95f4\u6233. \u5e73\u5747\u8017\u65f6\u901a\u8fc7\u8ba1\u7b97\u6bcf\u53f0\u673a\u5668\u4e0a\u6240\u6709\u8fdb\u7a0b\u4efb\u52a1\u7684\u603b\u8017\u8d39\u65f6\u95f4\u9664\u4ee5\u673a\u5668\u4e0a\u7684\u603b\u8fdb\u7a0b\u6570\u91cf\u83b7\u5f97.

    \n\n

    \u7ed3\u679c\u8868\u5fc5\u987b\u5305\u542bmachine_id\uff08\u673a\u5668ID\uff09 \u548c\u5bf9\u5e94\u7684\u00a0average time\uff08\u5e73\u5747\u8017\u65f6\uff09\u00a0\u522b\u540d\u00a0processing_time, \u4e14\u56db\u820d\u4e94\u5165\u4fdd\u75593\u4f4d\u5c0f\u6570.

    \n\n

    \u5177\u4f53\u53c2\u8003\u4f8b\u5b50\u5982\u4e0b:

    \n\n

    \u00a0

    \n\n
    Activity table:\n+------------+------------+---------------+-----------+\n| machine_id | process_id | activity_type | timestamp |\n+------------+------------+---------------+-----------+\n| 0          | 0          | start         | 0.712     |\n| 0          | 0          | end           | 1.520     |\n| 0          | 1          | start         | 3.140     |\n| 0          | 1          | end           | 4.120     |\n| 1          | 0          | start         | 0.550     |\n| 1          | 0          | end           | 1.550     |\n| 1          | 1          | start         | 0.430     |\n| 1          | 1          | end           | 1.420     |\n| 2          | 0          | start         | 4.100     |\n| 2          | 0          | end           | 4.512     |\n| 2          | 1          | start         | 2.500     |\n| 2          | 1          | end           | 5.000     |\n+------------+------------+---------------+-----------+\n\nResult table:\n+------------+-----------------+\n| machine_id | processing_time |\n+------------+-----------------+\n| 0          | 0.894           |\n| 1          | 0.995           |\n| 2          | 1.456           |\n+------------+-----------------+\n\n\u4e00\u5171\u67093\u53f0\u673a\u5668,\u6bcf\u53f0\u673a\u5668\u8fd0\u884c\u7740\u4e24\u4e2a\u8fdb\u7a0b.\n\u673a\u5668 0 \u7684\u5e73\u5747\u8017\u65f6: ((1.520 - 0.712) + (4.120 - 3.140)) / 2 = 0.894\n\u673a\u5668 1 \u7684\u5e73\u5747\u8017\u65f6: ((1.550 - 0.550) + (1.420 - 0.430)) / 2 = 0.995\n\u673a\u5668 2 \u7684\u5e73\u5747\u8017\u65f6: ((4.512 - 4.100) + (5.000 - 2.500)) / 2 = 1.456\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1661](https://leetcode-cn.com/problems/average-time-of-process-per-machine)", "[\u6bcf\u53f0\u673a\u5668\u7684\u8fdb\u7a0b\u5e73\u5747\u8fd0\u884c\u65f6\u95f4](/solution/1600-1699/1661.Average%20Time%20of%20Process%20per%20Machine/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1661](https://leetcode.com/problems/average-time-of-process-per-machine)", "[Average Time of Process per Machine](/solution/1600-1699/1661.Average%20Time%20of%20Process%20per%20Machine/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1800", "frontend_question_id": "1680", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/concatenation-of-consecutive-binary-numbers", "url_en": "https://leetcode.com/problems/concatenation-of-consecutive-binary-numbers", "relative_path_cn": "/solution/1600-1699/1680.Concatenation%20of%20Consecutive%20Binary%20Numbers/README.md", "relative_path_en": "/solution/1600-1699/1680.Concatenation%20of%20Consecutive%20Binary%20Numbers/README_EN.md", "title_cn": "\u8fde\u63a5\u8fde\u7eed\u4e8c\u8fdb\u5236\u6570\u5b57", "title_en": "Concatenation of Consecutive Binary Numbers", "question_title_slug": "concatenation-of-consecutive-binary-numbers", "content_en": "

    Given an integer n, return the decimal value of the binary string formed by concatenating the binary representations of 1 to n in order, modulo 109 + 7.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 1\nOutput: 1\nExplanation: "1" in binary corresponds to the decimal value 1. \n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 3\nOutput: 27\nExplanation: In binary, 1, 2, and 3 corresponds to "1", "10", and "11".\nAfter concatenating them, we have "11011", which corresponds to the decimal value 27.\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 12\nOutput: 505379714\nExplanation: The concatenation results in "1101110010111011110001001101010111100".\nThe decimal value of that is 118505380540.\nAfter modulo 109 + 7, the result is 505379714.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u00a0n\u00a0\uff0c\u8bf7\u4f60\u5c06\u00a01\u00a0\u5230 n\u00a0\u7684\u4e8c\u8fdb\u5236\u8868\u793a\u8fde\u63a5\u8d77\u6765\uff0c\u5e76\u8fd4\u56de\u8fde\u63a5\u7ed3\u679c\u5bf9\u5e94\u7684 \u5341\u8fdb\u5236\u00a0\u6570\u5b57\u5bf9 109\u00a0+ 7\u00a0\u53d6\u4f59\u7684\u7ed3\u679c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u4e8c\u8fdb\u5236\u7684 \"1\" \u5bf9\u5e94\u7740\u5341\u8fdb\u5236\u7684 1 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1an = 3\n\u8f93\u51fa\uff1a27\n\u89e3\u91ca\uff1a\u4e8c\u8fdb\u5236\u4e0b\uff0c1\uff0c2 \u548c 3 \u5206\u522b\u5bf9\u5e94 \"1\" \uff0c\"10\" \u548c \"11\" \u3002\n\u5c06\u5b83\u4eec\u4f9d\u6b21\u8fde\u63a5\uff0c\u6211\u4eec\u5f97\u5230 \"11011\" \uff0c\u5bf9\u5e94\u7740\u5341\u8fdb\u5236\u7684 27 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1an = 12\n\u8f93\u51fa\uff1a505379714\n\u89e3\u91ca\uff1a\u8fde\u63a5\u7ed3\u679c\u4e3a \"1101110010111011110001001101010111100\" \u3002\n\u5bf9\u5e94\u7684\u5341\u8fdb\u5236\u6570\u5b57\u4e3a 118505380540 \u3002\n\u5bf9 109 + 7 \u53d6\u4f59\u540e\uff0c\u7ed3\u679c\u4e3a 505379714 \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 105
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int concatenatedBinary(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int concatenatedBinary(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def concatenatedBinary(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def concatenatedBinary(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint concatenatedBinary(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ConcatenatedBinary(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar concatenatedBinary = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef concatenated_binary(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func concatenatedBinary(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func concatenatedBinary(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def concatenatedBinary(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun concatenatedBinary(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn concatenated_binary(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function concatenatedBinary($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function concatenatedBinary(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (concatenated-binary n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1680](https://leetcode-cn.com/problems/concatenation-of-consecutive-binary-numbers)", "[\u8fde\u63a5\u8fde\u7eed\u4e8c\u8fdb\u5236\u6570\u5b57](/solution/1600-1699/1680.Concatenation%20of%20Consecutive%20Binary%20Numbers/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1680](https://leetcode.com/problems/concatenation-of-consecutive-binary-numbers)", "[Concatenation of Consecutive Binary Numbers](/solution/1600-1699/1680.Concatenation%20of%20Consecutive%20Binary%20Numbers/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "1799", "frontend_question_id": "1681", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-incompatibility", "url_en": "https://leetcode.com/problems/minimum-incompatibility", "relative_path_cn": "/solution/1600-1699/1681.Minimum%20Incompatibility/README.md", "relative_path_en": "/solution/1600-1699/1681.Minimum%20Incompatibility/README_EN.md", "title_cn": "\u6700\u5c0f\u4e0d\u517c\u5bb9\u6027", "title_en": "Minimum Incompatibility", "question_title_slug": "minimum-incompatibility", "content_en": "

    You are given an integer array nums\u200b\u200b\u200b and an integer k. You are asked to distribute this array into k subsets of equal size such that there are no two equal elements in the same subset.

    \n\n

    A subset's incompatibility is the difference between the maximum and minimum elements in that array.

    \n\n

    Return the minimum possible sum of incompatibilities of the k subsets after distributing the array optimally, or return -1 if it is not possible.

    \n\n

    A subset is a group integers that appear in the array with no particular order.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,1,4], k = 2\nOutput: 4\nExplanation: The optimal distribution of subsets is [1,2] and [1,4].\nThe incompatibility is (2-1) + (4-1) = 4.\nNote that [1,1] and [2,4] would result in a smaller sum, but the first subset contains 2 equal elements.
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [6,3,8,1,3,1,2,2], k = 4\nOutput: 6\nExplanation: The optimal distribution of subsets is [1,2], [2,3], [6,8], and [1,3].\nThe incompatibility is (2-1) + (3-2) + (8-6) + (3-1) = 6.\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [5,3,3,6,3,3], k = 3\nOutput: -1\nExplanation: It is impossible to distribute nums into 3 subsets where no two elements are equal in the same subset.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= k <= nums.length <= 16
    • \n\t
    • nums.length is divisible by k
    • \n\t
    • 1 <= nums[i] <= nums.length
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0nums\u200b\u200b\u200b \u548c\u4e00\u4e2a\u6574\u6570\u00a0k\u00a0\u3002\u4f60\u9700\u8981\u5c06\u8fd9\u4e2a\u6570\u7ec4\u5212\u5206\u5230\u00a0k\u00a0\u4e2a\u76f8\u540c\u5927\u5c0f\u7684\u5b50\u96c6\u4e2d\uff0c\u4f7f\u5f97\u540c\u4e00\u4e2a\u5b50\u96c6\u91cc\u9762\u6ca1\u6709\u4e24\u4e2a\u76f8\u540c\u7684\u5143\u7d20\u3002

    \n\n

    \u4e00\u4e2a\u5b50\u96c6\u7684 \u4e0d\u517c\u5bb9\u6027\u00a0\u662f\u8be5\u5b50\u96c6\u91cc\u9762\u6700\u5927\u503c\u548c\u6700\u5c0f\u503c\u7684\u5dee\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u5c06\u6570\u7ec4\u5206\u6210 k\u00a0\u4e2a\u5b50\u96c6\u540e\uff0c\u5404\u5b50\u96c6 \u4e0d\u517c\u5bb9\u6027 \u7684 \u548c\u00a0\u7684 \u6700\u5c0f\u503c\u00a0\uff0c\u5982\u679c\u65e0\u6cd5\u5206\u6210\u5206\u6210 k\u00a0\u4e2a\u5b50\u96c6\uff0c\u8fd4\u56de -1\u00a0\u3002

    \n\n

    \u5b50\u96c6\u7684\u5b9a\u4e49\u662f\u6570\u7ec4\u4e2d\u4e00\u4e9b\u6570\u5b57\u7684\u96c6\u5408\uff0c\u5bf9\u6570\u5b57\u987a\u5e8f\u6ca1\u6709\u8981\u6c42\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,1,4], k = 2\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u6700\u4f18\u7684\u5206\u914d\u662f [1,2] \u548c [1,4] \u3002\n\u4e0d\u517c\u5bb9\u6027\u548c\u4e3a (2-1) + (4-1) = 4 \u3002\n\u6ce8\u610f\u5230 [1,1] \u548c [2,4] \u53ef\u4ee5\u5f97\u5230\u66f4\u5c0f\u7684\u548c\uff0c\u4f46\u662f\u7b2c\u4e00\u4e2a\u96c6\u5408\u6709 2 \u4e2a\u76f8\u540c\u7684\u5143\u7d20\uff0c\u6240\u4ee5\u4e0d\u53ef\u884c\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [6,3,8,1,3,1,2,2], k = 4\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u6700\u4f18\u7684\u5b50\u96c6\u5206\u914d\u4e3a [1,2]\uff0c[2,3]\uff0c[6,8] \u548c [1,3] \u3002\n\u4e0d\u517c\u5bb9\u6027\u548c\u4e3a (2-1) + (3-2) + (8-6) + (3-1) = 6 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [5,3,3,6,3,3], k = 3\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u6ca1\u529e\u6cd5\u5c06\u8fd9\u4e9b\u6570\u5b57\u5206\u914d\u5230 3 \u4e2a\u5b50\u96c6\u4e14\u6ee1\u8db3\u6bcf\u4e2a\u5b50\u96c6\u91cc\u6ca1\u6709\u76f8\u540c\u6570\u5b57\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= k <= nums.length <= 16
    • \n\t
    • nums.length \u80fd\u88ab\u00a0k \u6574\u9664\u3002
    • \n\t
    • 1 <= nums[i] <= nums.length
    • \n
    \n", "tags_en": ["Greedy", "Backtracking"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minimumIncompatibility(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minimumIncompatibility(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimumIncompatibility(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimumIncompatibility(self, nums: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minimumIncompatibility(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinimumIncompatibility(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar minimumIncompatibility = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef minimum_incompatibility(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimumIncompatibility(_ nums: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimumIncompatibility(nums []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimumIncompatibility(nums: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimumIncompatibility(nums: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimum_incompatibility(nums: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer\n */\n function minimumIncompatibility($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimumIncompatibility(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimum-incompatibility nums k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1681](https://leetcode-cn.com/problems/minimum-incompatibility)", "[\u6700\u5c0f\u4e0d\u517c\u5bb9\u6027](/solution/1600-1699/1681.Minimum%20Incompatibility/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u56de\u6eaf\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[1681](https://leetcode.com/problems/minimum-incompatibility)", "[Minimum Incompatibility](/solution/1600-1699/1681.Minimum%20Incompatibility/README_EN.md)", "`Greedy`,`Backtracking`", "Hard", ""]}, {"question_id": "1798", "frontend_question_id": "1679", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/max-number-of-k-sum-pairs", "url_en": "https://leetcode.com/problems/max-number-of-k-sum-pairs", "relative_path_cn": "/solution/1600-1699/1679.Max%20Number%20of%20K-Sum%20Pairs/README.md", "relative_path_en": "/solution/1600-1699/1679.Max%20Number%20of%20K-Sum%20Pairs/README_EN.md", "title_cn": "K \u548c\u6570\u5bf9\u7684\u6700\u5927\u6570\u76ee", "title_en": "Max Number of K-Sum Pairs", "question_title_slug": "max-number-of-k-sum-pairs", "content_en": "

    You are given an integer array nums and an integer k.

    \n\n

    In one operation, you can pick two numbers from the array whose sum equals k and remove them from the array.

    \n\n

    Return the maximum number of operations you can perform on the array.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,3,4], k = 5\nOutput: 2\nExplanation: Starting with nums = [1,2,3,4]:\n- Remove numbers 1 and 4, then nums = [2,3]\n- Remove numbers 2 and 3, then nums = []\nThere are no more pairs that sum up to 5, hence a total of 2 operations.
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [3,1,3,4,3], k = 6\nOutput: 1\nExplanation: Starting with nums = [3,1,3,4,3]:\n- Remove the first two 3's, then nums = [1,4,3]\nThere are no more pairs that sum up to 6, hence a total of 1 operation.
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • 1 <= nums[i] <= 109
    • \n\t
    • 1 <= k <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \u548c\u4e00\u4e2a\u6574\u6570 k \u3002

    \n\n

    \u6bcf\u4e00\u6b65\u64cd\u4f5c\u4e2d\uff0c\u4f60\u9700\u8981\u4ece\u6570\u7ec4\u4e2d\u9009\u51fa\u548c\u4e3a k \u7684\u4e24\u4e2a\u6574\u6570\uff0c\u5e76\u5c06\u5b83\u4eec\u79fb\u51fa\u6570\u7ec4\u3002

    \n\n

    \u8fd4\u56de\u4f60\u53ef\u4ee5\u5bf9\u6570\u7ec4\u6267\u884c\u7684\u6700\u5927\u64cd\u4f5c\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,3,4], k = 5\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5f00\u59cb\u65f6 nums = [1,2,3,4]\uff1a\n- \u79fb\u51fa 1 \u548c 4 \uff0c\u4e4b\u540e nums = [2,3]\n- \u79fb\u51fa 2 \u548c 3 \uff0c\u4e4b\u540e nums = []\n\u4e0d\u518d\u6709\u548c\u4e3a 5 \u7684\u6570\u5bf9\uff0c\u56e0\u6b64\u6700\u591a\u6267\u884c 2 \u6b21\u64cd\u4f5c\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [3,1,3,4,3], k = 6\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u5f00\u59cb\u65f6 nums = [3,1,3,4,3]\uff1a\n- \u79fb\u51fa\u524d\u4e24\u4e2a 3 \uff0c\u4e4b\u540enums = [1,4,3]\n\u4e0d\u518d\u6709\u548c\u4e3a 6 \u7684\u6570\u5bf9\uff0c\u56e0\u6b64\u6700\u591a\u6267\u884c 1 \u6b21\u64cd\u4f5c\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • 1 <= nums[i] <= 109
    • \n\t
    • 1 <= k <= 109
    • \n
    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxOperations(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxOperations(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxOperations(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxOperations(self, nums: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxOperations(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxOperations(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar maxOperations = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef max_operations(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxOperations(_ nums: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxOperations(nums []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxOperations(nums: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxOperations(nums: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_operations(nums: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer\n */\n function maxOperations($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxOperations(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-operations nums k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1679](https://leetcode-cn.com/problems/max-number-of-k-sum-pairs)", "[K \u548c\u6570\u5bf9\u7684\u6700\u5927\u6570\u76ee](/solution/1600-1699/1679.Max%20Number%20of%20K-Sum%20Pairs/README.md)", "`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1679](https://leetcode.com/problems/max-number-of-k-sum-pairs)", "[Max Number of K-Sum Pairs](/solution/1600-1699/1679.Max%20Number%20of%20K-Sum%20Pairs/README_EN.md)", "`Hash Table`", "Medium", ""]}, {"question_id": "1797", "frontend_question_id": "1678", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/goal-parser-interpretation", "url_en": "https://leetcode.com/problems/goal-parser-interpretation", "relative_path_cn": "/solution/1600-1699/1678.Goal%20Parser%20Interpretation/README.md", "relative_path_en": "/solution/1600-1699/1678.Goal%20Parser%20Interpretation/README_EN.md", "title_cn": "\u8bbe\u8ba1 Goal \u89e3\u6790\u5668", "title_en": "Goal Parser Interpretation", "question_title_slug": "goal-parser-interpretation", "content_en": "

    You own a Goal Parser that can interpret a string command. The command consists of an alphabet of "G", "()" and/or "(al)" in some order. The Goal Parser will interpret "G" as the string "G", "()" as the string "o", and "(al)" as the string "al". The interpreted strings are then concatenated in the original order.

    \n\n

    Given the string command, return the Goal Parser's interpretation of command.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: command = "G()(al)"\nOutput: "Goal"\nExplanation: The Goal Parser interprets the command as follows:\nG -> G\n() -> o\n(al) -> al\nThe final concatenated result is "Goal".\n
    \n\n

    Example 2:

    \n\n
    \nInput: command = "G()()()()(al)"\nOutput: "Gooooal"\n
    \n\n

    Example 3:

    \n\n
    \nInput: command = "(al)G(al)()()G"\nOutput: "alGalooG"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= command.length <= 100
    • \n\t
    • command consists of "G", "()", and/or "(al)" in some order.
    • \n
    \n", "content_cn": "

    \u8bf7\u4f60\u8bbe\u8ba1\u4e00\u4e2a\u53ef\u4ee5\u89e3\u91ca\u5b57\u7b26\u4e32 command \u7684 Goal \u89e3\u6790\u5668 \u3002command \u7531 \"G\"\u3001\"()\" \u548c/\u6216 \"(al)\" \u6309\u67d0\u79cd\u987a\u5e8f\u7ec4\u6210\u3002Goal \u89e3\u6790\u5668\u4f1a\u5c06 \"G\" \u89e3\u91ca\u4e3a\u5b57\u7b26\u4e32 \"G\"\u3001\"()\" \u89e3\u91ca\u4e3a\u5b57\u7b26\u4e32 \"o\" \uff0c\"(al)\" \u89e3\u91ca\u4e3a\u5b57\u7b26\u4e32 \"al\" \u3002\u7136\u540e\uff0c\u6309\u539f\u987a\u5e8f\u5c06\u7ecf\u89e3\u91ca\u5f97\u5230\u7684\u5b57\u7b26\u4e32\u8fde\u63a5\u6210\u4e00\u4e2a\u5b57\u7b26\u4e32\u3002

    \n\n

    \u7ed9\u4f60\u5b57\u7b26\u4e32 command \uff0c\u8fd4\u56de Goal \u89e3\u6790\u5668 \u5bf9 command \u7684\u89e3\u91ca\u7ed3\u679c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1acommand = \"G()(al)\"\n\u8f93\u51fa\uff1a\"Goal\"\n\u89e3\u91ca\uff1aGoal \u89e3\u6790\u5668\u89e3\u91ca\u547d\u4ee4\u7684\u6b65\u9aa4\u5982\u4e0b\u6240\u793a\uff1a\nG -> G\n() -> o\n(al) -> al\n\u6700\u540e\u8fde\u63a5\u5f97\u5230\u7684\u7ed3\u679c\u662f \"Goal\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1acommand = \"G()()()()(al)\"\n\u8f93\u51fa\uff1a\"Gooooal\"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1acommand = \"(al)G(al)()()G\"\n\u8f93\u51fa\uff1a\"alGalooG\"\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= command.length <= 100
    • \n\t
    • command \u7531 \"G\"\u3001\"()\" \u548c/\u6216 \"(al)\" \u6309\u67d0\u79cd\u987a\u5e8f\u7ec4\u6210
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string interpret(string command) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String interpret(String command) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def interpret(self, command):\n \"\"\"\n :type command: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def interpret(self, command: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * interpret(char * command){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string Interpret(string command) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} command\n * @return {string}\n */\nvar interpret = function(command) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} command\n# @return {String}\ndef interpret(command)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func interpret(_ command: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func interpret(command string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def interpret(command: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun interpret(command: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn interpret(command: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $command\n * @return String\n */\n function interpret($command) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function interpret(command: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (interpret command)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1678](https://leetcode-cn.com/problems/goal-parser-interpretation)", "[\u8bbe\u8ba1 Goal \u89e3\u6790\u5668](/solution/1600-1699/1678.Goal%20Parser%20Interpretation/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1678](https://leetcode.com/problems/goal-parser-interpretation)", "[Goal Parser Interpretation](/solution/1600-1699/1678.Goal%20Parser%20Interpretation/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1796", "frontend_question_id": "1660", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/correct-a-binary-tree", "url_en": "https://leetcode.com/problems/correct-a-binary-tree", "relative_path_cn": "/solution/1600-1699/1660.Correct%20a%20Binary%20Tree/README.md", "relative_path_en": "/solution/1600-1699/1660.Correct%20a%20Binary%20Tree/README_EN.md", "title_cn": "\u7ea0\u6b63\u4e8c\u53c9\u6811", "title_en": "Correct a Binary Tree", "question_title_slug": "correct-a-binary-tree", "content_en": "

    You have a binary tree with a small defect. There is exactly one invalid node where its right child incorrectly points to another node at the same depth but to the invalid node's right.

    \r\n\r\n

    Given the root of the binary tree with this defect, root, return the root of the binary tree after removing this invalid node and every node underneath it (minus the node it incorrectly points to).

    \r\n\r\n

    Custom testing:

    \r\n\r\n

    The test input is read as 3 lines:

    \r\n\r\n
      \r\n\t
    • TreeNode root
    • \r\n\t
    • int fromNode (not available to correctBinaryTree)
    • \r\n\t
    • int toNode (not available to correctBinaryTree)
    • \r\n
    \r\n\r\n

    After the binary tree rooted at root is parsed, the TreeNode with value of fromNode will have its right child pointer pointing to the TreeNode with a value of toNode. Then, root is passed to correctBinaryTree.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n

    \"\"

    \r\n\r\n
    \r\nInput: root = [1,2,3], fromNode = 2, toNode = 3\r\nOutput: [1,null,3]\r\nExplanation: The node with value 2 is invalid, so remove it.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n

    \"\"

    \r\n\r\n
    \r\nInput: root = [8,3,1,7,null,9,4,2,null,null,null,5,6], fromNode = 7, toNode = 4\r\nOutput: [8,3,1,null,null,9,4,null,null,5,6]\r\nExplanation: The node with value 7 is invalid, so remove it and the node underneath it, node 2.\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • The number of nodes in the tree is in the range [3, 104].
    • \r\n\t
    • -109 <= Node.val <= 109
    • \r\n\t
    • All Node.val are unique.
    • \r\n\t
    • fromNode != toNode
    • \r\n\t
    • fromNode and toNode will exist in the tree and will be on the same depth.
    • \r\n\t
    • toNode is to the right of fromNode.
    • \r\n\t
    • fromNode.right is null in the initial tree from the test data.
    • \r\n
    ", "content_cn": "

    \u4f60\u6709\u4e00\u68f5\u4e8c\u53c9\u6811\uff0c\u8fd9\u68f5\u4e8c\u53c9\u6811\u6709\u4e2a\u5c0f\u95ee\u9898\uff0c\u5176\u4e2d\u6709\u4e14\u53ea\u6709\u4e00\u4e2a\u65e0\u6548\u8282\u70b9\uff0c\u5b83\u7684\u53f3\u5b50\u8282\u70b9\u9519\u8bef\u5730\u6307\u5411\u4e86\u4e0e\u5176\u5728\u540c\u4e00\u5c42\u4e14\u5728\u5176\u53f3\u4fa7\u7684\u4e00\u4e2a\u5176\u4ed6\u8282\u70b9\u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u68f5\u8fd9\u6837\u7684\u95ee\u9898\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9\u00a0root\u00a0\uff0c\u5c06\u8be5\u65e0\u6548\u8282\u70b9\u53ca\u5176\u6240\u6709\u5b50\u8282\u70b9\u79fb\u9664\uff08\u9664\u88ab\u9519\u8bef\u6307\u5411\u7684\u8282\u70b9\u5916\uff09\uff0c\u7136\u540e\u8fd4\u56de\u65b0\u4e8c\u53c9\u6811\u7684\u6839\u7ed3\u70b9\u3002

    \n\n

    \u81ea\u5b9a\u4e49\u6d4b\u8bd5\u7528\u4f8b\uff1a

    \n\n

    \u6d4b\u8bd5\u7528\u4f8b\u7684\u8f93\u5165\u7531\u4e09\u884c\u7ec4\u6210\uff1a

    \n\n
      \n\t
    • TreeNode root
    • \n\t
    • int fromNode\u00a0\uff08\u5728\u00a0correctBinaryTree\u00a0\u4e2d\u4e0d\u53ef\u89c1\uff09
    • \n\t
    • int toNode\u00a0\uff08\u5728\u00a0correctBinaryTree\u00a0\u4e2d\u4e0d\u53ef\u89c1\uff09
    • \n
    \n\n

    \u5f53\u4ee5\u00a0root\u00a0\u4e3a\u6839\u7684\u4e8c\u53c9\u6811\u88ab\u89e3\u6790\u540e\uff0c\u503c\u4e3a\u00a0fromNode\u00a0\u7684\u8282\u70b9\u00a0TreeNode\u00a0\u5c06\u5176\u53f3\u5b50\u8282\u70b9\u6307\u5411\u503c\u4e3a\u00a0toNode\u00a0\u7684\u8282\u70b9\u00a0TreeNode\u00a0\u3002\u7136\u540e\uff0c\u00a0root\u00a0\u4f20\u5165\u00a0correctBinaryTree\u00a0\u7684\u53c2\u6570\u4e2d\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1:

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165: root = [1,2,3], fromNode = 2, toNode = 3\n\u8f93\u51fa: [1,null,3]\n\u89e3\u91ca: \u503c\u4e3a 2 \u7684\u8282\u70b9\u662f\u65e0\u6548\u7684\uff0c\u6240\u4ee5\u79fb\u9664\u4e4b\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165: root = [8,3,1,7,null,9,4,2,null,null,null,5,6], fromNode = 7, toNode = 4\n\u8f93\u51fa: [8,3,1,null,null,9,4,null,null,5,6]\n\u89e3\u91ca: \u503c\u4e3a 7 \u7684\u8282\u70b9\u662f\u65e0\u6548\u7684\uff0c\u6240\u4ee5\u79fb\u9664\u8fd9\u4e2a\u8282\u70b9\u53ca\u5176\u5b50\u8282\u70b9 2\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a:

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u4e2a\u6570\u7684\u8303\u56f4\u662f\u00a0[3, 104]\u00a0\u3002
    • \n\t
    • -109 <= Node.val <= 109
    • \n\t
    • \u6240\u6709\u7684\u00a0Node.val\u00a0\u90fd\u662f\u4e92\u4e0d\u76f8\u540c\u7684\u3002
    • \n\t
    • fromNode != toNode
    • \n\t
    • fromNode\u00a0\u548c\u00a0toNode\u00a0\u5c06\u51fa\u73b0\u5728\u6811\u4e2d\u7684\u540c\u4e00\u5c42\u3002
    • \n\t
    • toNode\u00a0\u5728\u00a0fromNode\u00a0\u7684\u53f3\u4fa7\u3002
    • \n\t
    • fromNode.right\u00a0\u5728\u6d4b\u8bd5\u7528\u4f8b\u7684\u6811\u4e2d\u5efa\u7acb\u540e\u4e3a\u00a0null\u00a0\u3002
    • \n
    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* correctBinaryTree(TreeNode* root) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode correctBinaryTree(TreeNode root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def correctBinaryTree(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: TreeNode\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def correctBinaryTree(self, root: TreeNode) -> TreeNode:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode CorrectBinaryTree(TreeNode root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number} from\n * @param {number} to\n * @return {TreeNode}\n */\nvar correctBinaryTree = function(root) {\n \n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1660](https://leetcode-cn.com/problems/correct-a-binary-tree)", "[\u7ea0\u6b63\u4e8c\u53c9\u6811](/solution/1600-1699/1660.Correct%20a%20Binary%20Tree/README.md)", "`\u6811`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1660](https://leetcode.com/problems/correct-a-binary-tree)", "[Correct a Binary Tree](/solution/1600-1699/1660.Correct%20a%20Binary%20Tree/README_EN.md)", "`Tree`", "Medium", "\ud83d\udd12"]}, {"question_id": "1795", "frontend_question_id": "1651", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/hopper-company-queries-iii", "url_en": "https://leetcode.com/problems/hopper-company-queries-iii", "relative_path_cn": "/solution/1600-1699/1651.Hopper%20Company%20Queries%20III/README.md", "relative_path_en": "/solution/1600-1699/1651.Hopper%20Company%20Queries%20III/README_EN.md", "title_cn": "", "title_en": "Hopper Company Queries III", "question_title_slug": "hopper-company-queries-iii", "content_en": "

    Table: Drivers

    \n\n
    \n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| driver_id   | int     |\n| join_date   | date    |\n+-------------+---------+\ndriver_id is the primary key for this table.\nEach row of this table contains the driver's ID and the date they joined the Hopper company.\n
    \n\n

     

    \n\n

    Table: Rides

    \n\n
    \n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| ride_id      | int     |\n| user_id      | int     |\n| requested_at | date    |\n+--------------+---------+\nride_id is the primary key for this table.\nEach row of this table contains the ID of a ride, the user's ID that requested it, and the day they requested it.\nThere may be some ride requests in this table that were not accepted.\n
    \n\n

     

    \n\n

    Table: AcceptedRides

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| ride_id       | int     |\n| driver_id     | int     |\n| ride_distance | int     |\n| ride_duration | int     |\n+---------------+---------+\nride_id is the primary key for this table.\nEach row of this table contains some information about an accepted ride.\nIt is guaranteed that each accepted ride exists in the Rides table.\n
    \n\n

     

    \n\n

    Write an SQL query to compute the average_ride_distance and average_ride_duration of every 3-month window starting from January - March 2020 to October - December 2020. Round average_ride_distance and average_ride_duration to the nearest two decimal places.

    \n\n

    The average_ride_distance is calculated by summing up the total ride_distance values from the three months and dividing it by 3. The average_ride_duration is calculated in a similar way.

    \n\n

    Return the result table ordered by month in ascending order, where month is the starting month's number (January is 1, February is 2, etc.).

    \n\n

    The query result format is in the following example.

    \n\n

     

    \n\n
    \nDrivers table:\n+-----------+------------+\n| driver_id | join_date  |\n+-----------+------------+\n| 10        | 2019-12-10 |\n| 8         | 2020-1-13  |\n| 5         | 2020-2-16  |\n| 7         | 2020-3-8   |\n| 4         | 2020-5-17  |\n| 1         | 2020-10-24 |\n| 6         | 2021-1-5   |\n+-----------+------------+\n\nRides table:\n+---------+---------+--------------+\n| ride_id | user_id | requested_at |\n+---------+---------+--------------+\n| 6       | 75      | 2019-12-9    |\n| 1       | 54      | 2020-2-9     |\n| 10      | 63      | 2020-3-4     |\n| 19      | 39      | 2020-4-6     |\n| 3       | 41      | 2020-6-3     |\n| 13      | 52      | 2020-6-22    |\n| 7       | 69      | 2020-7-16    |\n| 17      | 70      | 2020-8-25    |\n| 20      | 81      | 2020-11-2    |\n| 5       | 57      | 2020-11-9    |\n| 2       | 42      | 2020-12-9    |\n| 11      | 68      | 2021-1-11    |\n| 15      | 32      | 2021-1-17    |\n| 12      | 11      | 2021-1-19    |\n| 14      | 18      | 2021-1-27    |\n+---------+---------+--------------+\n\nAcceptedRides table:\n+---------+-----------+---------------+---------------+\n| ride_id | driver_id | ride_distance | ride_duration |\n+---------+-----------+---------------+---------------+\n| 10      | 10        | 63            | 38            |\n| 13      | 10        | 73            | 96            |\n| 7       | 8         | 100           | 28            |\n| 17      | 7         | 119           | 68            |\n| 20      | 1         | 121           | 92            |\n| 5       | 7         | 42            | 101           |\n| 2       | 4         | 6             | 38            |\n| 11      | 8         | 37            | 43            |\n| 15      | 8         | 108           | 82            |\n| 12      | 8         | 38            | 34            |\n| 14      | 1         | 90            | 74            |\n+---------+-----------+---------------+---------------+\n\nResult table:\n+-------+-----------------------+-----------------------+\n| month | average_ride_distance | average_ride_duration |\n+-------+-----------------------+-----------------------+\n| 1     | 21.00                 | 12.67                 |\n| 2     | 21.00                 | 12.67                 |\n| 3     | 21.00                 | 12.67                 |\n| 4     | 24.33                 | 32.00                 |\n| 5     | 57.67                 | 41.33                 |\n| 6     | 97.33                 | 64.00                 |\n| 7     | 73.00                 | 32.00                 |\n| 8     | 39.67                 | 22.67                 |\n| 9     | 54.33                 | 64.33                 |\n| 10    | 56.33                 | 77.00                 |\n+-------+-----------------------+-----------------------+\n\nBy the end of January --> average_ride_distance = (0+0+63)/3=21, average_ride_duration = (0+0+38)/3=12.67\nBy the end of February --> average_ride_distance = (0+63+0)/3=21, average_ride_duration = (0+38+0)/3=12.67\nBy the end of March --> average_ride_distance = (63+0+0)/3=21, average_ride_duration = (38+0+0)/3=12.67\nBy the end of April --> average_ride_distance = (0+0+73)/3=24.33, average_ride_duration = (0+0+96)/3=32.00\nBy the end of May --> average_ride_distance = (0+73+100)/3=57.67, average_ride_duration = (0+96+28)/3=41.33\nBy the end of June --> average_ride_distance = (73+100+119)/3=97.33, average_ride_duration = (96+28+68)/3=64.00\nBy the end of July --> average_ride_distance = (100+119+0)/3=73.00, average_ride_duration = (28+68+0)/3=32.00\nBy the end of August --> average_ride_distance = (119+0+0)/3=39.67, average_ride_duration = (68+0+0)/3=22.67\nBy the end of Septemeber --> average_ride_distance = (0+0+163)/3=54.33, average_ride_duration = (0+0+193)/3=64.33\nBy the end of October --> average_ride_distance = (0+163+6)/3=56.33, average_ride_duration = (0+193+38)/3=77.00\n
    \n", "content_cn": null, "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1651](https://leetcode-cn.com/problems/hopper-company-queries-iii)", "[Hopper Company Queries III](/solution/1600-1699/1651.Hopper%20Company%20Queries%20III/README_EN.md)", "", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1651](https://leetcode.com/problems/hopper-company-queries-iii)", "[Hopper Company Queries III](/solution/1600-1699/1651.Hopper%20Company%20Queries%20III/README_EN.md)", "", "Hard", "\ud83d\udd12"]}, {"question_id": "1794", "frontend_question_id": "1675", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimize-deviation-in-array", "url_en": "https://leetcode.com/problems/minimize-deviation-in-array", "relative_path_cn": "/solution/1600-1699/1675.Minimize%20Deviation%20in%20Array/README.md", "relative_path_en": "/solution/1600-1699/1675.Minimize%20Deviation%20in%20Array/README_EN.md", "title_cn": "\u6570\u7ec4\u7684\u6700\u5c0f\u504f\u79fb\u91cf", "title_en": "Minimize Deviation in Array", "question_title_slug": "minimize-deviation-in-array", "content_en": "

    You are given an array nums of n positive integers.

    \n\n

    You can perform two types of operations on any element of the array any number of times:

    \n\n
      \n\t
    • If the element is even, divide it by 2.\n\n\t
        \n\t\t
      • For example, if the array is [1,2,3,4], then you can do this operation on the last element, and the array will be [1,2,3,2].
      • \n\t
      \n\t
    • \n\t
    • If the element is odd, multiply it by 2.\n\t
        \n\t\t
      • For example, if the array is [1,2,3,4], then you can do this operation on the first element, and the array will be [2,2,3,4].
      • \n\t
      \n\t
    • \n
    \n\n

    The deviation of the array is the maximum difference between any two elements in the array.

    \n\n

    Return the minimum deviation the array can have after performing some number of operations.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,3,4]\nOutput: 1\nExplanation: You can transform the array to [1,2,3,2], then to [2,2,3,2], then the deviation will be 3 - 2 = 1.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [4,1,5,20,3]\nOutput: 3\nExplanation: You can transform the array after two operations to [4,2,5,5,3], then the deviation will be 5 - 2 = 3.\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [2,10,8]\nOutput: 3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 2 <= n <= 105
    • \n\t
    • 1 <= nums[i] <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u7531 n \u4e2a\u6b63\u6574\u6570\u7ec4\u6210\u7684\u6570\u7ec4 nums \u3002

    \n\n

    \u4f60\u53ef\u4ee5\u5bf9\u6570\u7ec4\u7684\u4efb\u610f\u5143\u7d20\u6267\u884c\u4efb\u610f\u6b21\u6570\u7684\u4e24\u7c7b\u64cd\u4f5c\uff1a

    \n\n
      \n\t
    • \u5982\u679c\u5143\u7d20\u662f \u5076\u6570 \uff0c\u9664\u4ee5 2\n\n\t
        \n\t\t
      • \u4f8b\u5982\uff0c\u5982\u679c\u6570\u7ec4\u662f [1,2,3,4] \uff0c\u90a3\u4e48\u4f60\u53ef\u4ee5\u5bf9\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u6267\u884c\u6b64\u64cd\u4f5c\uff0c\u4f7f\u5176\u53d8\u6210 [1,2,3,2]
      • \n\t
      \n\t
    • \n\t
    • \u5982\u679c\u5143\u7d20\u662f \u5947\u6570 \uff0c\u4e58\u4e0a 2\n\t
        \n\t\t
      • \u4f8b\u5982\uff0c\u5982\u679c\u6570\u7ec4\u662f [1,2,3,4] \uff0c\u90a3\u4e48\u4f60\u53ef\u4ee5\u5bf9\u7b2c\u4e00\u4e2a\u5143\u7d20\u6267\u884c\u6b64\u64cd\u4f5c\uff0c\u4f7f\u5176\u53d8\u6210 [2,2,3,4]
      • \n\t
      \n\t
    • \n
    \n\n

    \u6570\u7ec4\u7684 \u504f\u79fb\u91cf \u662f\u6570\u7ec4\u4e2d\u4efb\u610f\u4e24\u4e2a\u5143\u7d20\u4e4b\u95f4\u7684 \u6700\u5927\u5dee\u503c \u3002

    \n\n

    \u8fd4\u56de\u6570\u7ec4\u5728\u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\u4e4b\u540e\u53ef\u4ee5\u62e5\u6709\u7684 \u6700\u5c0f\u504f\u79fb\u91cf \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,2,3,4]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u5c06\u6570\u7ec4\u8f6c\u6362\u4e3a [1,2,3,2]\uff0c\u7136\u540e\u8f6c\u6362\u6210 [2,2,3,2]\uff0c\u504f\u79fb\u91cf\u662f 3 - 2 = 1\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [4,1,5,20,3]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u4e24\u6b21\u64cd\u4f5c\u540e\uff0c\u4f60\u53ef\u4ee5\u5c06\u6570\u7ec4\u8f6c\u6362\u4e3a [4,2,5,5,3]\uff0c\u504f\u79fb\u91cf\u662f 5 - 2 = 3\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [2,10,8]\n\u8f93\u51fa\uff1a3\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 2 <= n <= 105
    • \n\t
    • 1 <= nums[i] <= 109
    • \n
    \n", "tags_en": ["Heap", "Ordered Map"], "tags_cn": ["\u5806"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minimumDeviation(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minimumDeviation(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimumDeviation(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimumDeviation(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minimumDeviation(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinimumDeviation(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar minimumDeviation = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef minimum_deviation(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimumDeviation(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimumDeviation(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimumDeviation(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimumDeviation(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimum_deviation(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function minimumDeviation($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimumDeviation(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimum-deviation nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1675](https://leetcode-cn.com/problems/minimize-deviation-in-array)", "[\u6570\u7ec4\u7684\u6700\u5c0f\u504f\u79fb\u91cf](/solution/1600-1699/1675.Minimize%20Deviation%20in%20Array/README.md)", "`\u5806`", "\u56f0\u96be", ""], "md_table_row_en": ["[1675](https://leetcode.com/problems/minimize-deviation-in-array)", "[Minimize Deviation in Array](/solution/1600-1699/1675.Minimize%20Deviation%20in%20Array/README_EN.md)", "`Heap`,`Ordered Map`", "Hard", ""]}, {"question_id": "1793", "frontend_question_id": "1674", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-moves-to-make-array-complementary", "url_en": "https://leetcode.com/problems/minimum-moves-to-make-array-complementary", "relative_path_cn": "/solution/1600-1699/1674.Minimum%20Moves%20to%20Make%20Array%20Complementary/README.md", "relative_path_en": "/solution/1600-1699/1674.Minimum%20Moves%20to%20Make%20Array%20Complementary/README_EN.md", "title_cn": "\u4f7f\u6570\u7ec4\u4e92\u8865\u7684\u6700\u5c11\u64cd\u4f5c\u6b21\u6570", "title_en": "Minimum Moves to Make Array Complementary", "question_title_slug": "minimum-moves-to-make-array-complementary", "content_en": "

    You are given an integer array nums of even length n and an integer limit. In one move, you can replace any integer from nums with another integer between 1 and limit, inclusive.

    \n\n

    The array nums is complementary if for all indices i (0-indexed), nums[i] + nums[n - 1 - i] equals the same number. For example, the array [1,2,3,4] is complementary because for all indices i, nums[i] + nums[n - 1 - i] = 5.

    \n\n

    Return the minimum number of moves required to make nums complementary.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,4,3], limit = 4\nOutput: 1\nExplanation: In 1 move, you can change nums to [1,2,2,3] (underlined elements are changed).\nnums[0] + nums[3] = 1 + 3 = 4.\nnums[1] + nums[2] = 2 + 2 = 4.\nnums[2] + nums[1] = 2 + 2 = 4.\nnums[3] + nums[0] = 3 + 1 = 4.\nTherefore, nums[i] + nums[n-1-i] = 4 for every i, so nums is complementary.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,2,2,1], limit = 2\nOutput: 2\nExplanation: In 2 moves, you can change nums to [2,2,2,2]. You cannot change any number to 3 since 3 > limit.\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [1,2,1,2], limit = 2\nOutput: 0\nExplanation: nums is already complementary.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 2 <= n <= 105
    • \n\t
    • 1 <= nums[i] <= limit <= 105
    • \n\t
    • n is even.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u4e3a \u5076\u6570 n \u7684\u6574\u6570\u6570\u7ec4 nums \u548c\u4e00\u4e2a\u6574\u6570 limit \u3002\u6bcf\u4e00\u6b21\u64cd\u4f5c\uff0c\u4f60\u53ef\u4ee5\u5c06 nums \u4e2d\u7684\u4efb\u4f55\u6574\u6570\u66ff\u6362\u4e3a\u00a01\u00a0\u5230\u00a0limit \u4e4b\u95f4\u7684\u53e6\u4e00\u4e2a\u6574\u6570\u3002

    \n\n

    \u5982\u679c\u5bf9\u4e8e\u6240\u6709\u4e0b\u6807 i\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\uff0cnums[i] + nums[n - 1 - i]\u00a0\u90fd\u7b49\u4e8e\u540c\u4e00\u4e2a\u6570\uff0c\u5219\u6570\u7ec4 nums \u662f \u4e92\u8865\u7684 \u3002\u4f8b\u5982\uff0c\u6570\u7ec4 [1,2,3,4] \u662f\u4e92\u8865\u7684\uff0c\u56e0\u4e3a\u5bf9\u4e8e\u6240\u6709\u4e0b\u6807\u00a0i \uff0cnums[i] + nums[n - 1 - i] = 5 \u3002

    \n\n

    \u8fd4\u56de\u4f7f\u6570\u7ec4 \u4e92\u8865 \u7684 \u6700\u5c11\u00a0\u64cd\u4f5c\u6b21\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,4,3], limit = 4\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u7ecf\u8fc7 1 \u6b21\u64cd\u4f5c\uff0c\u4f60\u53ef\u4ee5\u5c06\u6570\u7ec4 nums \u53d8\u6210 [1,2,2,3]\uff08\u52a0\u7c97\u5143\u7d20\u662f\u53d8\u66f4\u7684\u6570\u5b57\uff09\uff1a\nnums[0] + nums[3] = 1 + 3 = 4.\nnums[1] + nums[2] = 2 + 2 = 4.\nnums[2] + nums[1] = 2 + 2 = 4.\nnums[3] + nums[0] = 3 + 1 = 4.\n\u5bf9\u4e8e\u6bcf\u4e2a i \uff0cnums[i] + nums[n-1-i] = 4 \uff0c\u6240\u4ee5 nums \u662f\u4e92\u8865\u7684\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,2,1], limit = 2\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u7ecf\u8fc7 2 \u6b21\u64cd\u4f5c\uff0c\u4f60\u53ef\u4ee5\u5c06\u6570\u7ec4 nums \u53d8\u6210 [2,2,2,2] \u3002\u4f60\u4e0d\u80fd\u5c06\u4efb\u4f55\u6570\u5b57\u53d8\u66f4\u4e3a 3 \uff0c\u56e0\u4e3a 3 > limit \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,1,2], limit = 2\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1anums \u5df2\u7ecf\u662f\u4e92\u8865\u7684\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 2 <= n\u00a0<=\u00a0105
    • \n\t
    • 1 <= nums[i]\u00a0<= limit <=\u00a0105
    • \n\t
    • n \u662f\u5076\u6570\u3002
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minMoves(vector& nums, int limit) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minMoves(int[] nums, int limit) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minMoves(self, nums, limit):\n \"\"\"\n :type nums: List[int]\n :type limit: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minMoves(self, nums: List[int], limit: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minMoves(int* nums, int numsSize, int limit){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinMoves(int[] nums, int limit) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} limit\n * @return {number}\n */\nvar minMoves = function(nums, limit) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} limit\n# @return {Integer}\ndef min_moves(nums, limit)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minMoves(_ nums: [Int], _ limit: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minMoves(nums []int, limit int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minMoves(nums: Array[Int], limit: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minMoves(nums: IntArray, limit: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_moves(nums: Vec, limit: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $limit\n * @return Integer\n */\n function minMoves($nums, $limit) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minMoves(nums: number[], limit: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-moves nums limit)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1674](https://leetcode-cn.com/problems/minimum-moves-to-make-array-complementary)", "[\u4f7f\u6570\u7ec4\u4e92\u8865\u7684\u6700\u5c11\u64cd\u4f5c\u6b21\u6570](/solution/1600-1699/1674.Minimum%20Moves%20to%20Make%20Array%20Complementary/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1674](https://leetcode.com/problems/minimum-moves-to-make-array-complementary)", "[Minimum Moves to Make Array Complementary](/solution/1600-1699/1674.Minimum%20Moves%20to%20Make%20Array%20Complementary/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1792", "frontend_question_id": "1673", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-the-most-competitive-subsequence", "url_en": "https://leetcode.com/problems/find-the-most-competitive-subsequence", "relative_path_cn": "/solution/1600-1699/1673.Find%20the%20Most%20Competitive%20Subsequence/README.md", "relative_path_en": "/solution/1600-1699/1673.Find%20the%20Most%20Competitive%20Subsequence/README_EN.md", "title_cn": "\u627e\u51fa\u6700\u5177\u7ade\u4e89\u529b\u7684\u5b50\u5e8f\u5217", "title_en": "Find the Most Competitive Subsequence", "question_title_slug": "find-the-most-competitive-subsequence", "content_en": "

    Given an integer array nums and a positive integer k, return the most competitive subsequence of nums of size k.

    \n\n

    An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the array.

    \n\n

    We define that a subsequence a is more competitive than a subsequence b (of the same length) if in the first position where a and b differ, subsequence a has a number less than the corresponding number in b. For example, [1,3,4] is more competitive than [1,3,5] because the first position they differ is at the final number, and 4 is less than 5.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [3,5,2,6], k = 2\nOutput: [2,6]\nExplanation: Among the set of every possible subsequence: {[3,5], [3,2], [3,6], [5,2], [5,6], [2,6]}, [2,6] is the most competitive.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [2,4,3,3,5,4,9,6], k = 4\nOutput: [2,3,3,4]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • 0 <= nums[i] <= 109
    • \n\t
    • 1 <= k <= nums.length
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \u548c\u4e00\u4e2a\u6b63\u6574\u6570 k \uff0c\u8fd4\u56de\u957f\u5ea6\u4e3a k \u4e14\u6700\u5177 \u7ade\u4e89\u529b \u7684 nums \u5b50\u5e8f\u5217\u3002

    \n\n

    \u6570\u7ec4\u7684\u5b50\u5e8f\u5217\u662f\u4ece\u6570\u7ec4\u4e2d\u5220\u9664\u4e00\u4e9b\u5143\u7d20\uff08\u53ef\u80fd\u4e0d\u5220\u9664\u5143\u7d20\uff09\u5f97\u5230\u7684\u5e8f\u5217\u3002

    \n\n

    \u5728\u5b50\u5e8f\u5217\u00a0a \u548c\u5b50\u5e8f\u5217\u00a0b \u7b2c\u4e00\u4e2a\u4e0d\u76f8\u540c\u7684\u4f4d\u7f6e\u4e0a\uff0c\u5982\u679c\u00a0a\u00a0\u4e2d\u7684\u6570\u5b57\u5c0f\u4e8e b \u4e2d\u5bf9\u5e94\u7684\u6570\u5b57\uff0c\u90a3\u4e48\u6211\u4eec\u79f0\u5b50\u5e8f\u5217 a \u6bd4\u5b50\u5e8f\u5217 b\uff08\u76f8\u540c\u957f\u5ea6\u4e0b\uff09\u66f4\u5177 \u7ade\u4e89\u529b \u3002 \u4f8b\u5982\uff0c[1,3,4] \u6bd4 [1,3,5] \u66f4\u5177\u7ade\u4e89\u529b\uff0c\u5728\u7b2c\u4e00\u4e2a\u4e0d\u76f8\u540c\u7684\u4f4d\u7f6e\uff0c\u4e5f\u5c31\u662f\u6700\u540e\u4e00\u4e2a\u4f4d\u7f6e\u4e0a\uff0c\u00a04 \u5c0f\u4e8e 5 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [3,5,2,6], k = 2\n\u8f93\u51fa\uff1a[2,6]\n\u89e3\u91ca\uff1a\u5728\u6240\u6709\u53ef\u80fd\u7684\u5b50\u5e8f\u5217\u96c6\u5408 {[3,5], [3,2], [3,6], [5,2], [5,6], [2,6]} \u4e2d\uff0c[2,6] \u6700\u5177\u7ade\u4e89\u529b\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [2,4,3,3,5,4,9,6], k = 4\n\u8f93\u51fa\uff1a[2,3,3,4]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • 0 <= nums[i] <= 109
    • \n\t
    • 1 <= k <= nums.length
    • \n
    \n", "tags_en": ["Stack", "Heap", "Greedy", "Queue"], "tags_cn": ["\u6808", "\u5806", "\u8d2a\u5fc3\u7b97\u6cd5", "\u961f\u5217"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector mostCompetitive(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] mostCompetitive(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def mostCompetitive(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def mostCompetitive(self, nums: List[int], k: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* mostCompetitive(int* nums, int numsSize, int k, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] MostCompetitive(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number[]}\n */\nvar mostCompetitive = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer[]}\ndef most_competitive(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func mostCompetitive(_ nums: [Int], _ k: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func mostCompetitive(nums []int, k int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def mostCompetitive(nums: Array[Int], k: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun mostCompetitive(nums: IntArray, k: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn most_competitive(nums: Vec, k: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer[]\n */\n function mostCompetitive($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function mostCompetitive(nums: number[], k: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (most-competitive nums k)\n (-> (listof exact-integer?) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1673](https://leetcode-cn.com/problems/find-the-most-competitive-subsequence)", "[\u627e\u51fa\u6700\u5177\u7ade\u4e89\u529b\u7684\u5b50\u5e8f\u5217](/solution/1600-1699/1673.Find%20the%20Most%20Competitive%20Subsequence/README.md)", "`\u6808`,`\u5806`,`\u8d2a\u5fc3\u7b97\u6cd5`,`\u961f\u5217`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1673](https://leetcode.com/problems/find-the-most-competitive-subsequence)", "[Find the Most Competitive Subsequence](/solution/1600-1699/1673.Find%20the%20Most%20Competitive%20Subsequence/README_EN.md)", "`Stack`,`Heap`,`Greedy`,`Queue`", "Medium", ""]}, {"question_id": "1791", "frontend_question_id": "1672", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/richest-customer-wealth", "url_en": "https://leetcode.com/problems/richest-customer-wealth", "relative_path_cn": "/solution/1600-1699/1672.Richest%20Customer%20Wealth/README.md", "relative_path_en": "/solution/1600-1699/1672.Richest%20Customer%20Wealth/README_EN.md", "title_cn": "\u6700\u5bcc\u6709\u5ba2\u6237\u7684\u8d44\u4ea7\u603b\u91cf", "title_en": "Richest Customer Wealth", "question_title_slug": "richest-customer-wealth", "content_en": "

    You are given an m x n integer grid accounts where accounts[i][j] is the amount of money the i\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200bth\u200b\u200b\u200b\u200b customer has in the j\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200bth\u200b\u200b\u200b\u200b bank. Return the wealth that the richest customer has.

    \n\n

    A customer's wealth is the amount of money they have in all their bank accounts. The richest customer is the customer that has the maximum wealth.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: accounts = [[1,2,3],[3,2,1]]\nOutput: 6\nExplanation:\n1st customer has wealth = 1 + 2 + 3 = 6\n2nd customer has wealth = 3 + 2 + 1 = 6\nBoth customers are considered the richest with a wealth of 6 each, so return 6.\n
    \n\n

    Example 2:

    \n\n
    \nInput: accounts = [[1,5],[7,3],[3,5]]\nOutput: 10\nExplanation: \n1st customer has wealth = 6\n2nd customer has wealth = 10 \n3rd customer has wealth = 8\nThe 2nd customer is the richest with a wealth of 10.
    \n\n

    Example 3:

    \n\n
    \nInput: accounts = [[2,8,7],[7,1,3],[1,9,5]]\nOutput: 17\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == accounts.length
    • \n\t
    • n == accounts[i].length
    • \n\t
    • 1 <= m, n <= 50
    • \n\t
    • 1 <= accounts[i][j] <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a m x n \u7684\u6574\u6570\u7f51\u683c accounts \uff0c\u5176\u4e2d accounts[i][j] \u662f\u7b2c i\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b \u4f4d\u5ba2\u6237\u5728\u7b2c j \u5bb6\u94f6\u884c\u6258\u7ba1\u7684\u8d44\u4ea7\u6570\u91cf\u3002\u8fd4\u56de\u6700\u5bcc\u6709\u5ba2\u6237\u6240\u62e5\u6709\u7684 \u8d44\u4ea7\u603b\u91cf \u3002

    \n\n

    \u5ba2\u6237\u7684 \u8d44\u4ea7\u603b\u91cf \u5c31\u662f\u4ed6\u4eec\u5728\u5404\u5bb6\u94f6\u884c\u6258\u7ba1\u7684\u8d44\u4ea7\u6570\u91cf\u4e4b\u548c\u3002\u6700\u5bcc\u6709\u5ba2\u6237\u5c31\u662f \u8d44\u4ea7\u603b\u91cf \u6700\u5927\u7684\u5ba2\u6237\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aaccounts = [[1,2,3],[3,2,1]]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\n\u7b2c 1 \u4f4d\u5ba2\u6237\u7684\u8d44\u4ea7\u603b\u91cf = 1 + 2 + 3 = 6\n\u7b2c 2 \u4f4d\u5ba2\u6237\u7684\u8d44\u4ea7\u603b\u91cf = 3 + 2 + 1 = 6\n\u4e24\u4f4d\u5ba2\u6237\u90fd\u662f\u6700\u5bcc\u6709\u7684\uff0c\u8d44\u4ea7\u603b\u91cf\u90fd\u662f 6 \uff0c\u6240\u4ee5\u8fd4\u56de 6 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aaccounts = [[1,5],[7,3],[3,5]]\n\u8f93\u51fa\uff1a10\n\u89e3\u91ca\uff1a\n\u7b2c 1 \u4f4d\u5ba2\u6237\u7684\u8d44\u4ea7\u603b\u91cf = 6\n\u7b2c 2 \u4f4d\u5ba2\u6237\u7684\u8d44\u4ea7\u603b\u91cf = 10 \n\u7b2c 3 \u4f4d\u5ba2\u6237\u7684\u8d44\u4ea7\u603b\u91cf = 8\n\u7b2c 2 \u4f4d\u5ba2\u6237\u662f\u6700\u5bcc\u6709\u7684\uff0c\u8d44\u4ea7\u603b\u91cf\u662f 10
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aaccounts = [[2,8,7],[7,1,3],[1,9,5]]\n\u8f93\u51fa\uff1a17\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m ==\u00a0accounts.length
    • \n\t
    • n ==\u00a0accounts[i].length
    • \n\t
    • 1 <= m, n <= 50
    • \n\t
    • 1 <= accounts[i][j] <= 100
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maximumWealth(vector>& accounts) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maximumWealth(int[][] accounts) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximumWealth(self, accounts):\n \"\"\"\n :type accounts: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximumWealth(self, accounts: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maximumWealth(int** accounts, int accountsSize, int* accountsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaximumWealth(int[][] accounts) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} accounts\n * @return {number}\n */\nvar maximumWealth = function(accounts) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} accounts\n# @return {Integer}\ndef maximum_wealth(accounts)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximumWealth(_ accounts: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximumWealth(accounts [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximumWealth(accounts: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximumWealth(accounts: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximum_wealth(accounts: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $accounts\n * @return Integer\n */\n function maximumWealth($accounts) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximumWealth(accounts: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximum-wealth accounts)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1672](https://leetcode-cn.com/problems/richest-customer-wealth)", "[\u6700\u5bcc\u6709\u5ba2\u6237\u7684\u8d44\u4ea7\u603b\u91cf](/solution/1600-1699/1672.Richest%20Customer%20Wealth/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1672](https://leetcode.com/problems/richest-customer-wealth)", "[Richest Customer Wealth](/solution/1600-1699/1672.Richest%20Customer%20Wealth/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1790", "frontend_question_id": "1650", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-tree-iii", "url_en": "https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree-iii", "relative_path_cn": "/solution/1600-1699/1650.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree%20III/README.md", "relative_path_en": "/solution/1600-1699/1650.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree%20III/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148 III", "title_en": "Lowest Common Ancestor of a Binary Tree III", "question_title_slug": "lowest-common-ancestor-of-a-binary-tree-iii", "content_en": "

    Given two nodes of a binary tree p and q, return their lowest common ancestor (LCA).

    \n\n

    Each node will have a reference to its parent node. The definition for Node is below:

    \n\n
    \nclass Node {\n    public int val;\n    public Node left;\n    public Node right;\n    public Node parent;\n}\n
    \n\n

    According to the definition of LCA on Wikipedia: "The lowest common ancestor of two nodes p and q in a tree T is the lowest node that has both p and q as descendants (where we allow a node to be a descendant of itself)."

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 1\nOutput: 3\nExplanation: The LCA of nodes 5 and 1 is 3.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 4\nOutput: 5\nExplanation: The LCA of nodes 5 and 4 is 5 since a node can be a descendant of itself according to the LCA definition.\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = [1,2], p = 1, q = 2\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [2, 105].
    • \n\t
    • -109 <= Node.val <= 109
    • \n\t
    • All Node.val are unique.
    • \n\t
    • p != q
    • \n\t
    • p and q exist in the tree.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u68f5\u4e8c\u53c9\u6811\u4e2d\u7684\u4e24\u4e2a\u8282\u70b9 p \u548c q\uff0c\u8fd4\u56de\u5b83\u4eec\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148\u8282\u70b9\uff08LCA\uff09\u3002

    \n\n

    \u6bcf\u4e2a\u8282\u70b9\u90fd\u5305\u542b\u5176\u7236\u8282\u70b9\u7684\u5f15\u7528\uff08\u6307\u9488\uff09\u3002Node\u00a0\u7684\u5b9a\u4e49\u5982\u4e0b\uff1a

    \n\n
    class Node {\n    public int val;\n    public Node left;\n    public Node right;\n    public Node parent;\n}\n
    \n\n

    \u6839\u636e\u7ef4\u57fa\u767e\u79d1\u4e2d\u5bf9\u6700\u8fd1\u516c\u5171\u7956\u5148\u8282\u70b9\u7684\u5b9a\u4e49\uff1a\u201c\u4e24\u4e2a\u8282\u70b9 p \u548c q \u5728\u4e8c\u53c9\u6811 T \u4e2d\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148\u8282\u70b9\u662f\u540e\u4ee3\u8282\u70b9\u4e2d\u65e2\u5305\u62ec p\u00a0\u53c8\u5305\u62ec\u00a0q\u00a0\u7684\u6700\u6df1\u8282\u70b9\uff08\u6211\u4eec\u5141\u8bb8\u4e00\u4e2a\u8282\u70b9\u4e3a\u81ea\u8eab\u7684\u4e00\u4e2a\u540e\u4ee3\u8282\u70b9\uff09\u201d\u3002\u4e00\u4e2a\u8282\u70b9 x\u00a0\u7684\u540e\u4ee3\u8282\u70b9\u662f\u8282\u70b9\u00a0x \u5230\u67d0\u4e00\u53f6\u8282\u70b9\u95f4\u7684\u8def\u5f84\u4e2d\u7684\u8282\u70b9 y\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1:

    \n\"\"\n
    \u8f93\u5165: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 1\n\u8f93\u51fa: 3\n\u89e3\u91ca: \u8282\u70b9 5 \u548c 1 \u7684\u6700\u8fd1\u516c\u5171\u7956\u5148\u662f 3\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\"\"\n
    \u8f93\u5165: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 4\n\u8f93\u51fa: 5\n\u89e3\u91ca: \u8282\u70b9 5 \u548c 4 \u7684\u6700\u8fd1\u516c\u5171\u7956\u5148\u662f 5\uff0c\u6839\u636e\u5b9a\u4e49\uff0c\u4e00\u4e2a\u8282\u70b9\u53ef\u4ee5\u662f\u81ea\u8eab\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148\u3002\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u8f93\u5165: root = [1,2], p = 1, q = 2\n\u8f93\u51fa: 1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a:

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u4e2a\u6570\u7684\u8303\u56f4\u662f\u00a0[2, 105]\u3002
    • \n\t
    • -109 <= Node.val <= 109
    • \n\t
    • \u6240\u6709\u7684\u00a0Node.val\u00a0\u90fd\u662f\u4e92\u4e0d\u76f8\u540c\u7684\u3002
    • \n\t
    • p != q
    • \n\t
    • p\u00a0\u548c\u00a0q\u00a0\u5b58\u5728\u4e8e\u6811\u4e2d\u3002
    • \n
    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* parent;\n};\n*/\n\nclass Solution {\npublic:\n Node* lowestCommonAncestor(Node* p, Node * q) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/*\n// Definition for a Node.\nclass Node {\n public int val;\n public Node left;\n public Node right;\n public Node parent;\n};\n*/\n\nclass Solution {\n public Node lowestCommonAncestor(Node p, Node q) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "\"\"\"\n# Definition for a Node.\nclass Node:\n def __init__(self, val):\n self.val = val\n self.left = None\n self.right = None\n self.parent = None\n\"\"\"\n\nclass Solution(object):\n def lowestCommonAncestor(self, p, q):\n \"\"\"\n :type node: Node\n :rtype: Node\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "\"\"\"\n# Definition for a Node.\nclass Node:\n def __init__(self, val):\n self.val = val\n self.left = None\n self.right = None\n self.parent = None\n\"\"\"\n\nclass Solution:\n def lowestCommonAncestor(self, p: 'Node', q: 'Node') -> 'Node':\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/*\n// Definition for a Node.\nstruct Node {\n int val;\n struct Node* left;\n struct Node* right;\n struct Node* parent;\n};\n*/\n\nstruct Node* lowestCommonAncestor(struct Node* p,struct Node* q) {\n\t\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/*\n// Definition for a Node.\npublic class Node {\n public int val;\n public Node left;\n public Node right;\n public Node parent;\n}\n*/\n\npublic class Solution {\n public Node LowestCommonAncestor(Node p, Node q) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // Definition for a Node.\n * function Node(val) {\n * this.val = val;\n * this.left = null;\n * this.right = null;\n * this.parent = null;\n * };\n */\n\n/**\n * @param {Node} node\n * @return {Node}\n */\nvar lowestCommonAncestor = function(p, q) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a Node.\n# class Node\n# attr_accessor :val, :left, :right, :parent\n# def initialize(val=0)\n# @val = val\n# @left, @right, parent = nil, nil, nil\n# end\n# end\n\n# @param {Node} root\n# @return {Node}\ndef lowest_common_ancestor(p, q)\n\t\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a Node.\n * public class Node {\n * public var val: Int\n * public var left: Node?\n * public var right: Node?\n * public var parent: Node?\n * public init(_ val: Int) {\n * self.val = val\n * self.left = nil\n * self.right = nil\n * self.parent = nil\n * }\n * }\n */\n\nclass Solution {\n func lowestCommonAncestor(_ p: Node?,_ q: Node?) -> Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for Node.\n * type Node struct {\n * Val int\n * Left *Node\n * Right *Node\n * Parent *Node\n * }\n */\n\nfunc lowestCommonAncestor(p *Node, q *Node) *Node {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a Node.\n * class Node(var _value: Int) {\n * var value: Int = _value\n * var left: Node = null\n * var right: Node = null\n * var parent: Node = null\n * }\n */\n\nobject Solution {\n def lowestCommonAncestor(p: Node, q: Node): Node = {\n\t\t\n\t}\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a Node.\n * class Node(var `val`: Int) {\n *\t\tvar left: TreeNode? = null\n *\t\tvar right: TreeNode? = null\n *\t\tvar parent: Node? = null\n * }\n */\n\nclass Solution {\n fun lowestCommonAncestor(p: Node?, q: Node?): Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a Node.\n * class Node {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * public $parent = null;\n * function __construct($val = 0) {\n * $this->val = $val;\n * $this->left = null;\n * $this->right = null;\n * $this->parent = null;\n * }\n * }\n */\n\nclass Solution {\n /**\n * @param Node $node\n * @return Node\n */\n function lowestCommonAncestor($p, $q) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class Node {\n * val: number\n * left: Node | null\n * right: Node | null\n * parent: Node | null\n * constructor(val?: number, left?: Node | null, right?: Node | null, parent?: Node | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * this.parent = (parent===undefined ? null : parent)\n * }\n * }\n */\n\nfunction lowestCommonAncestor(p: Node | null, q: Node | null): Node | null {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1650](https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-tree-iii)", "[\u4e8c\u53c9\u6811\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148 III](/solution/1600-1699/1650.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree%20III/README.md)", "`\u6811`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1650](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree-iii)", "[Lowest Common Ancestor of a Binary Tree III](/solution/1600-1699/1650.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree%20III/README_EN.md)", "`Tree`", "Medium", "\ud83d\udd12"]}, {"question_id": "1789", "frontend_question_id": "1687", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/delivering-boxes-from-storage-to-ports", "url_en": "https://leetcode.com/problems/delivering-boxes-from-storage-to-ports", "relative_path_cn": "/solution/1600-1699/1687.Delivering%20Boxes%20from%20Storage%20to%20Ports/README.md", "relative_path_en": "/solution/1600-1699/1687.Delivering%20Boxes%20from%20Storage%20to%20Ports/README_EN.md", "title_cn": "\u4ece\u4ed3\u5e93\u5230\u7801\u5934\u8fd0\u8f93\u7bb1\u5b50", "title_en": "Delivering Boxes from Storage to Ports", "question_title_slug": "delivering-boxes-from-storage-to-ports", "content_en": "

    You have the task of delivering some boxes from storage to their ports using only one ship. However, this ship has a limit on the number of boxes and the total weight that it can carry.

    \n\n

    You are given an array boxes, where boxes[i] = [ports\u200b\u200bi\u200b, weighti], and three integers portsCount, maxBoxes, and maxWeight.

    \n\n
      \n\t
    • ports\u200b\u200bi is the port where you need to deliver the ith box and weightsi is the weight of the ith box.
    • \n\t
    • portsCount is the number of ports.
    • \n\t
    • maxBoxes and maxWeight are the respective box and weight limits of the ship.
    • \n
    \n\n

    The boxes need to be delivered in the order they are given. The ship will follow these steps:

    \n\n
      \n\t
    • The ship will take some number of boxes from the boxes queue, not violating the maxBoxes and maxWeight constraints.
    • \n\t
    • For each loaded box in order, the ship will make a trip to the port the box needs to be delivered to and deliver it. If the ship is already at the correct port, no trip is needed, and the box can immediately be delivered.
    • \n\t
    • The ship then makes a return trip to storage to take more boxes from the queue.
    • \n
    \n\n

    The ship must end at storage after all the boxes have been delivered.

    \n\n

    Return the minimum number of trips the ship needs to make to deliver all boxes to their respective ports.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: boxes = [[1,1],[2,1],[1,1]], portsCount = 2, maxBoxes = 3, maxWeight = 3\nOutput: 4\nExplanation: The optimal strategy is as follows: \n- The ship takes all the boxes in the queue, goes to port 1, then port 2, then port 1 again, then returns to storage. 4 trips.\nSo the total number of trips is 4.\nNote that the first and third boxes cannot be delivered together because the boxes need to be delivered in order (i.e. the second box needs to be delivered at port 2 before the third box).\n
    \n\n

    Example 2:

    \n\n
    \nInput: boxes = [[1,2],[3,3],[3,1],[3,1],[2,4]], portsCount = 3, maxBoxes = 3, maxWeight = 6\nOutput: 6\nExplanation: The optimal strategy is as follows: \n- The ship takes the first box, goes to port 1, then returns to storage. 2 trips.\n- The ship takes the second, third and fourth boxes, goes to port 3, then returns to storage. 2 trips.\n- The ship takes the fifth box, goes to port 3, then returns to storage. 2 trips.\nSo the total number of trips is 2 + 2 + 2 = 6.\n
    \n\n

    Example 3:

    \n\n
    \nInput: boxes = [[1,4],[1,2],[2,1],[2,1],[3,2],[3,4]], portsCount = 3, maxBoxes = 6, maxWeight = 7\nOutput: 6\nExplanation: The optimal strategy is as follows:\n- The ship takes the first and second boxes, goes to port 1, then returns to storage. 2 trips.\n- The ship takes the third and fourth boxes, goes to port 2, then returns to storage. 2 trips.\n- The ship takes the fifth and sixth boxes, goes to port 3, then returns to storage. 2 trips.\nSo the total number of trips is 2 + 2 + 2 = 6.\n
    \n\n

    Example 4:

    \n\n
    \nInput: boxes = [[2,4],[2,5],[3,1],[3,2],[3,7],[3,1],[4,4],[1,3],[5,2]], portsCount = 5, maxBoxes = 5, maxWeight = 7\nOutput: 14\nExplanation: The optimal strategy is as follows:\n- The ship takes the first box, goes to port 2, then storage. 2 trips.\n- The ship takes the second box, goes to port 2, then storage. 2 trips.\n- The ship takes the third and fourth boxes, goes to port 3, then storage. 2 trips.\n- The ship takes the fifth box, goes to port 3, then storage. 2 trips.\n- The ship takes the sixth and seventh boxes, goes to port 3, then port 4, then storage. 3 trips. \n- The ship takes the eighth and ninth boxes, goes to port 1, then port 5, then storage. 3 trips.\nSo the total number of trips is 2 + 2 + 2 + 2 + 3 + 3 = 14.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= boxes.length <= 105
    • \n\t
    • 1 <= portsCount, maxBoxes, maxWeight <= 105
    • \n\t
    • 1 <= ports\u200b\u200bi <= portsCount
    • \n\t
    • 1 <= weightsi <= maxWeight
    • \n
    \n", "content_cn": "

    \u4f60\u6709\u4e00\u8f86\u8d27\u8fd0\u5361\u8f66\uff0c\u4f60\u9700\u8981\u7528\u8fd9\u4e00\u8f86\u8f66\u628a\u4e00\u4e9b\u7bb1\u5b50\u4ece\u4ed3\u5e93\u8fd0\u9001\u5230\u7801\u5934\u3002\u8fd9\u8f86\u5361\u8f66\u6bcf\u6b21\u8fd0\u8f93\u6709\u00a0\u7bb1\u5b50\u6570\u76ee\u7684\u9650\u5236\u00a0\u548c \u603b\u91cd\u91cf\u7684\u9650\u5236\u00a0\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u7bb1\u5b50\u6570\u7ec4\u00a0boxes\u00a0\u548c\u4e09\u4e2a\u6574\u6570 portsCount, maxBoxes\u00a0\u548c\u00a0maxWeight\u00a0\uff0c\u5176\u4e2d\u00a0boxes[i] = [ports\u200b\u200bi\u200b, weighti]\u00a0\u3002

    \n\n
      \n\t
    • ports\u200b\u200bi\u00a0\u8868\u793a\u7b2c\u00a0i\u00a0\u4e2a\u7bb1\u5b50\u9700\u8981\u9001\u8fbe\u7684\u7801\u5934\uff0c\u00a0weightsi\u00a0\u662f\u7b2c\u00a0i\u00a0\u4e2a\u7bb1\u5b50\u7684\u91cd\u91cf\u3002
    • \n\t
    • portsCount\u00a0\u662f\u7801\u5934\u7684\u6570\u76ee\u3002
    • \n\t
    • maxBoxes \u548c\u00a0maxWeight\u00a0\u5206\u522b\u662f\u5361\u8f66\u6bcf\u8d9f\u8fd0\u8f93\u7bb1\u5b50\u6570\u76ee\u548c\u91cd\u91cf\u7684\u9650\u5236\u3002
    • \n
    \n\n

    \u7bb1\u5b50\u9700\u8981\u6309\u7167 \u6570\u7ec4\u987a\u5e8f\u00a0\u8fd0\u8f93\uff0c\u540c\u65f6\u6bcf\u6b21\u8fd0\u8f93\u9700\u8981\u9075\u5faa\u4ee5\u4e0b\u6b65\u9aa4\uff1a

    \n\n
      \n\t
    • \u5361\u8f66\u4ece\u00a0boxes\u00a0\u961f\u5217\u4e2d\u6309\u987a\u5e8f\u53d6\u51fa\u82e5\u5e72\u4e2a\u7bb1\u5b50\uff0c\u4f46\u4e0d\u80fd\u8fdd\u53cd\u00a0maxBoxes \u548c\u00a0maxWeight\u00a0\u9650\u5236\u3002
    • \n\t
    • \u5bf9\u4e8e\u5728\u5361\u8f66\u4e0a\u7684\u7bb1\u5b50\uff0c\u6211\u4eec\u9700\u8981 \u6309\u987a\u5e8f\u00a0\u5904\u7406\u5b83\u4eec\uff0c\u5361\u8f66\u4f1a\u901a\u8fc7 \u4e00\u8d9f\u884c\u7a0b\u00a0\u5c06\u6700\u524d\u9762\u7684\u7bb1\u5b50\u9001\u5230\u76ee\u7684\u5730\u7801\u5934\u5e76\u5378\u8d27\u3002\u5982\u679c\u5361\u8f66\u5df2\u7ecf\u5728\u5bf9\u5e94\u7684\u7801\u5934\uff0c\u90a3\u4e48\u4e0d\u9700\u8981 \u989d\u5916\u884c\u7a0b\u00a0\uff0c\u7bb1\u5b50\u4e5f\u4f1a\u7acb\u9a6c\u88ab\u5378\u8d27\u3002
    • \n\t
    • \u5361\u8f66\u4e0a\u6240\u6709\u7bb1\u5b50\u90fd\u88ab\u5378\u8d27\u540e\uff0c\u5361\u8f66\u9700\u8981 \u4e00\u8d9f\u884c\u7a0b\u00a0\u56de\u5230\u4ed3\u5e93\uff0c\u4ece\u7bb1\u5b50\u961f\u5217\u91cc\u518d\u53d6\u51fa\u4e00\u4e9b\u7bb1\u5b50\u3002
    • \n
    \n\n

    \u5361\u8f66\u5728\u5c06\u6240\u6709\u7bb1\u5b50\u8fd0\u8f93\u5e76\u5378\u8d27\u540e\uff0c\u6700\u540e\u5fc5\u987b\u56de\u5230\u4ed3\u5e93\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u5c06\u6240\u6709\u7bb1\u5b50\u9001\u5230\u76f8\u5e94\u7801\u5934\u7684\u00a0\u6700\u5c11\u884c\u7a0b\u00a0\u6b21\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aboxes = [[1,1],[2,1],[1,1]], portsCount = 2, maxBoxes = 3, maxWeight = 3\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u6700\u4f18\u7b56\u7565\u5982\u4e0b\uff1a\n- \u5361\u8f66\u5c06\u6240\u6709\u7bb1\u5b50\u88c5\u4e0a\u8f66\uff0c\u5230\u8fbe\u7801\u5934 1 \uff0c\u7136\u540e\u53bb\u7801\u5934 2 \uff0c\u7136\u540e\u518d\u56de\u5230\u7801\u5934 1 \uff0c\u6700\u540e\u56de\u5230\u4ed3\u5e93\uff0c\u603b\u5171\u9700\u8981 4 \u8d9f\u884c\u7a0b\u3002\n\u6240\u4ee5\u603b\u884c\u7a0b\u6570\u4e3a 4 \u3002\n\u6ce8\u610f\u5230\u7b2c\u4e00\u4e2a\u548c\u7b2c\u4e09\u4e2a\u7bb1\u5b50\u4e0d\u80fd\u540c\u65f6\u88ab\u5378\u8d27\uff0c\u56e0\u4e3a\u7bb1\u5b50\u9700\u8981\u6309\u987a\u5e8f\u5904\u7406\uff08\u4e5f\u5c31\u662f\u7b2c\u4e8c\u4e2a\u7bb1\u5b50\u9700\u8981\u5148\u88ab\u9001\u5230\u7801\u5934 2 \uff0c\u7136\u540e\u624d\u80fd\u5904\u7406\u7b2c\u4e09\u4e2a\u7bb1\u5b50\uff09\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aboxes = [[1,2],[3,3],[3,1],[3,1],[2,4]], portsCount = 3, maxBoxes = 3, maxWeight = 6\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u6700\u4f18\u7b56\u7565\u5982\u4e0b\uff1a\n- \u5361\u8f66\u9996\u5148\u8fd0\u8f93\u7b2c\u4e00\u4e2a\u7bb1\u5b50\uff0c\u5230\u8fbe\u7801\u5934 1 \uff0c\u7136\u540e\u56de\u5230\u4ed3\u5e93\uff0c\u603b\u5171 2 \u8d9f\u884c\u7a0b\u3002\n- \u5361\u8f66\u8fd0\u8f93\u7b2c\u4e8c\u3001\u7b2c\u4e09\u3001\u7b2c\u56db\u4e2a\u7bb1\u5b50\uff0c\u5230\u8fbe\u7801\u5934 3 \uff0c\u7136\u540e\u56de\u5230\u4ed3\u5e93\uff0c\u603b\u5171 2 \u8d9f\u884c\u7a0b\u3002\n- \u5361\u8f66\u8fd0\u8f93\u7b2c\u4e94\u4e2a\u7bb1\u5b50\uff0c\u5230\u8fbe\u7801\u5934 3 \uff0c\u56de\u5230\u4ed3\u5e93\uff0c\u603b\u5171 2 \u8d9f\u884c\u7a0b\u3002\n\u603b\u884c\u7a0b\u6570\u4e3a 2 + 2 + 2 = 6 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aboxes = [[1,4],[1,2],[2,1],[2,1],[3,2],[3,4]], portsCount = 3, maxBoxes = 6, maxWeight = 7\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u6700\u4f18\u7b56\u7565\u5982\u4e0b\uff1a\n- \u5361\u8f66\u8fd0\u8f93\u7b2c\u4e00\u548c\u7b2c\u4e8c\u4e2a\u7bb1\u5b50\uff0c\u5230\u8fbe\u7801\u5934 1 \uff0c\u7136\u540e\u56de\u5230\u4ed3\u5e93\uff0c\u603b\u5171 2 \u8d9f\u884c\u7a0b\u3002\n- \u5361\u8f66\u8fd0\u8f93\u7b2c\u4e09\u548c\u7b2c\u56db\u4e2a\u7bb1\u5b50\uff0c\u5230\u8fbe\u7801\u5934 2 \uff0c\u7136\u540e\u56de\u5230\u4ed3\u5e93\uff0c\u603b\u5171 2 \u8d9f\u884c\u7a0b\u3002\n- \u5361\u8f66\u8fd0\u8f93\u7b2c\u4e94\u548c\u7b2c\u516d\u4e2a\u7bb1\u5b50\uff0c\u5230\u8fbe\u7801\u5934 3 \uff0c\u7136\u540e\u56de\u5230\u4ed3\u5e93\uff0c\u603b\u5171 2 \u8d9f\u884c\u7a0b\u3002\n\u603b\u884c\u7a0b\u6570\u4e3a 2 + 2 + 2 = 6 \u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1aboxes = [[2,4],[2,5],[3,1],[3,2],[3,7],[3,1],[4,4],[1,3],[5,2]], portsCount = 5, maxBoxes = 5, maxWeight = 7\n\u8f93\u51fa\uff1a14\n\u89e3\u91ca\uff1a\u6700\u4f18\u7b56\u7565\u5982\u4e0b\uff1a\n- \u5361\u8f66\u8fd0\u8f93\u7b2c\u4e00\u4e2a\u7bb1\u5b50\uff0c\u5230\u8fbe\u7801\u5934 2 \uff0c\u7136\u540e\u56de\u5230\u4ed3\u5e93\uff0c\u603b\u5171 2 \u8d9f\u884c\u7a0b\u3002\n- \u5361\u8f66\u8fd0\u8f93\u7b2c\u4e8c\u4e2a\u7bb1\u5b50\uff0c\u5230\u8fbe\u7801\u5934 2 \uff0c\u7136\u540e\u56de\u5230\u4ed3\u5e93\uff0c\u603b\u5171 2 \u8d9f\u884c\u7a0b\u3002\n- \u5361\u8f66\u8fd0\u8f93\u7b2c\u4e09\u548c\u7b2c\u56db\u4e2a\u7bb1\u5b50\uff0c\u5230\u8fbe\u7801\u5934 3 \uff0c\u7136\u540e\u56de\u5230\u4ed3\u5e93\uff0c\u603b\u5171 2 \u8d9f\u884c\u7a0b\u3002\n- \u5361\u8f66\u8fd0\u8f93\u7b2c\u4e94\u4e2a\u7bb1\u5b50\uff0c\u5230\u8fbe\u7801\u5934 3 \uff0c\u7136\u540e\u56de\u5230\u4ed3\u5e93\uff0c\u603b\u5171 2 \u8d9f\u884c\u7a0b\u3002\n- \u5361\u8f66\u8fd0\u8f93\u7b2c\u516d\u548c\u7b2c\u4e03\u4e2a\u7bb1\u5b50\uff0c\u5230\u8fbe\u7801\u5934 3 \uff0c\u7136\u540e\u53bb\u7801\u5934 4 \uff0c\u7136\u540e\u56de\u5230\u4ed3\u5e93\uff0c\u603b\u5171 3 \u8d9f\u884c\u7a0b\u3002\n- \u5361\u8f66\u8fd0\u8f93\u7b2c\u516b\u548c\u7b2c\u4e5d\u4e2a\u7bb1\u5b50\uff0c\u5230\u8fbe\u7801\u5934 1 \uff0c\u7136\u540e\u53bb\u7801\u5934 5 \uff0c\u7136\u540e\u56de\u5230\u4ed3\u5e93\uff0c\u603b\u5171 3 \u8d9f\u884c\u7a0b\u3002\n\u603b\u884c\u7a0b\u6570\u4e3a 2 + 2 + 2 + 2 + 3 + 3 = 14 \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= boxes.length <= 105
    • \n\t
    • 1 <= portsCount, maxBoxes, maxWeight <= 105
    • \n\t
    • 1 <= ports\u200b\u200bi <= portsCount
    • \n\t
    • 1 <= weightsi <= maxWeight
    • \n
    \n", "tags_en": ["Segment Tree", "Two Pointers", "Dynamic Programming"], "tags_cn": ["\u7ebf\u6bb5\u6811", "\u53cc\u6307\u9488", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int boxDelivering(vector>& boxes, int portsCount, int maxBoxes, int maxWeight) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int boxDelivering(int[][] boxes, int portsCount, int maxBoxes, int maxWeight) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def boxDelivering(self, boxes, portsCount, maxBoxes, maxWeight):\n \"\"\"\n :type boxes: List[List[int]]\n :type portsCount: int\n :type maxBoxes: int\n :type maxWeight: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def boxDelivering(self, boxes: List[List[int]], portsCount: int, maxBoxes: int, maxWeight: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint boxDelivering(int** boxes, int boxesSize, int* boxesColSize, int portsCount, int maxBoxes, int maxWeight){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int BoxDelivering(int[][] boxes, int portsCount, int maxBoxes, int maxWeight) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} boxes\n * @param {number} portsCount\n * @param {number} maxBoxes\n * @param {number} maxWeight\n * @return {number}\n */\nvar boxDelivering = function(boxes, portsCount, maxBoxes, maxWeight) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} boxes\n# @param {Integer} ports_count\n# @param {Integer} max_boxes\n# @param {Integer} max_weight\n# @return {Integer}\ndef box_delivering(boxes, ports_count, max_boxes, max_weight)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func boxDelivering(_ boxes: [[Int]], _ portsCount: Int, _ maxBoxes: Int, _ maxWeight: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func boxDelivering(boxes [][]int, portsCount int, maxBoxes int, maxWeight int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def boxDelivering(boxes: Array[Array[Int]], portsCount: Int, maxBoxes: Int, maxWeight: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun boxDelivering(boxes: Array, portsCount: Int, maxBoxes: Int, maxWeight: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn box_delivering(boxes: Vec>, ports_count: i32, max_boxes: i32, max_weight: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $boxes\n * @param Integer $portsCount\n * @param Integer $maxBoxes\n * @param Integer $maxWeight\n * @return Integer\n */\n function boxDelivering($boxes, $portsCount, $maxBoxes, $maxWeight) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function boxDelivering(boxes: number[][], portsCount: number, maxBoxes: number, maxWeight: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (box-delivering boxes portsCount maxBoxes maxWeight)\n (-> (listof (listof exact-integer?)) exact-integer? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1687](https://leetcode-cn.com/problems/delivering-boxes-from-storage-to-ports)", "[\u4ece\u4ed3\u5e93\u5230\u7801\u5934\u8fd0\u8f93\u7bb1\u5b50](/solution/1600-1699/1687.Delivering%20Boxes%20from%20Storage%20to%20Ports/README.md)", "`\u7ebf\u6bb5\u6811`,`\u53cc\u6307\u9488`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1687](https://leetcode.com/problems/delivering-boxes-from-storage-to-ports)", "[Delivering Boxes from Storage to Ports](/solution/1600-1699/1687.Delivering%20Boxes%20from%20Storage%20to%20Ports/README_EN.md)", "`Segment Tree`,`Two Pointers`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "1788", "frontend_question_id": "1686", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/stone-game-vi", "url_en": "https://leetcode.com/problems/stone-game-vi", "relative_path_cn": "/solution/1600-1699/1686.Stone%20Game%20VI/README.md", "relative_path_en": "/solution/1600-1699/1686.Stone%20Game%20VI/README_EN.md", "title_cn": "\u77f3\u5b50\u6e38\u620f VI", "title_en": "Stone Game VI", "question_title_slug": "stone-game-vi", "content_en": "

    Alice and Bob take turns playing a game, with Alice starting first.

    \n\n

    There are n stones in a pile. On each player's turn, they can remove a stone from the pile and receive points based on the stone's value. Alice and Bob may value the stones differently.

    \n\n

    You are given two integer arrays of length n, aliceValues and bobValues. Each aliceValues[i] and bobValues[i] represents how Alice and Bob, respectively, value the ith stone.

    \n\n

    The winner is the person with the most points after all the stones are chosen. If both players have the same amount of points, the game results in a draw. Both players will play optimally. Both players know the other's values.

    \n\n

    Determine the result of the game, and:

    \n\n
      \n\t
    • If Alice wins, return 1.
    • \n\t
    • If Bob wins, return -1.
    • \n\t
    • If the game results in a draw, return 0.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: aliceValues = [1,3], bobValues = [2,1]\nOutput: 1\nExplanation:\nIf Alice takes stone 1 (0-indexed) first, Alice will receive 3 points.\nBob can only choose stone 0, and will only receive 2 points.\nAlice wins.\n
    \n\n

    Example 2:

    \n\n
    \nInput: aliceValues = [1,2], bobValues = [3,1]\nOutput: 0\nExplanation:\nIf Alice takes stone 0, and Bob takes stone 1, they will both have 1 point.\nDraw.\n
    \n\n

    Example 3:

    \n\n
    \nInput: aliceValues = [2,4,3], bobValues = [1,6,7]\nOutput: -1\nExplanation:\nRegardless of how Alice plays, Bob will be able to have more points than Alice.\nFor example, if Alice takes stone 1, Bob can take stone 2, and Alice takes stone 0, Alice will have 6 points to Bob's 7.\nBob wins.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == aliceValues.length == bobValues.length
    • \n\t
    • 1 <= n <= 105
    • \n\t
    • 1 <= aliceValues[i], bobValues[i] <= 100
    • \n
    \n", "content_cn": "

    Alice \u548c\u00a0Bob \u8f6e\u6d41\u73a9\u4e00\u4e2a\u6e38\u620f\uff0cAlice \u5148\u624b\u3002

    \n\n

    \u4e00\u5806\u77f3\u5b50\u91cc\u603b\u5171\u6709\u00a0n\u00a0\u4e2a\u77f3\u5b50\uff0c\u8f6e\u5230\u67d0\u4e2a\u73a9\u5bb6\u65f6\uff0c\u4ed6\u53ef\u4ee5 \u79fb\u51fa\u00a0\u4e00\u4e2a\u77f3\u5b50\u5e76\u5f97\u5230\u8fd9\u4e2a\u77f3\u5b50\u7684\u4ef7\u503c\u3002Alice \u548c Bob \u5bf9\u77f3\u5b50\u4ef7\u503c\u6709 \u4e0d\u4e00\u6837\u7684\u7684\u8bc4\u5224\u6807\u51c6\u00a0\u3002\u53cc\u65b9\u90fd\u77e5\u9053\u5bf9\u65b9\u7684\u8bc4\u5224\u6807\u51c6\u3002

    \n\n

    \u7ed9\u4f60\u4e24\u4e2a\u957f\u5ea6\u4e3a n\u00a0\u7684\u6574\u6570\u6570\u7ec4\u00a0aliceValues \u548c\u00a0bobValues\u00a0\u3002aliceValues[i] \u548c\u00a0bobValues[i]\u00a0\u5206\u522b\u8868\u793a Alice \u548c Bob \u8ba4\u4e3a\u7b2c\u00a0i\u00a0\u4e2a\u77f3\u5b50\u7684\u4ef7\u503c\u3002

    \n\n

    \u6240\u6709\u77f3\u5b50\u90fd\u88ab\u53d6\u5b8c\u540e\uff0c\u5f97\u5206\u8f83\u9ad8\u7684\u4eba\u4e3a\u80dc\u8005\u3002\u5982\u679c\u4e24\u4e2a\u73a9\u5bb6\u5f97\u5206\u76f8\u540c\uff0c\u90a3\u4e48\u4e3a\u5e73\u5c40\u3002\u4e24\u4f4d\u73a9\u5bb6\u90fd\u4f1a\u91c7\u7528 \u6700\u4f18\u7b56\u7565\u00a0\u8fdb\u884c\u6e38\u620f\u3002

    \n\n

    \u8bf7\u4f60\u63a8\u65ad\u6e38\u620f\u7684\u7ed3\u679c\uff0c\u7528\u5982\u4e0b\u7684\u65b9\u5f0f\u8868\u793a\uff1a

    \n\n
      \n\t
    • \u5982\u679c Alice \u8d62\uff0c\u8fd4\u56de\u00a01\u00a0\u3002
    • \n\t
    • \u5982\u679c Bob \u8d62\uff0c\u8fd4\u56de\u00a0-1\u00a0\u3002
    • \n\t
    • \u5982\u679c\u6e38\u620f\u5e73\u5c40\uff0c\u8fd4\u56de\u00a00\u00a0\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aaliceValues = [1,3], bobValues = [2,1]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\n\u5982\u679c Alice \u62ff\u77f3\u5b50 1 \uff08\u4e0b\u6807\u4ece 0\u5f00\u59cb\uff09\uff0c\u90a3\u4e48 Alice \u53ef\u4ee5\u5f97\u5230 3 \u5206\u3002\nBob \u53ea\u80fd\u9009\u62e9\u77f3\u5b50 0 \uff0c\u5f97\u5230 2 \u5206\u3002\nAlice \u83b7\u80dc\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aaliceValues = [1,2], bobValues = [3,1]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\nAlice \u62ff\u77f3\u5b50 0 \uff0c Bob \u62ff\u77f3\u5b50 1 \uff0c\u4ed6\u4eec\u5f97\u5206\u90fd\u4e3a 1 \u5206\u3002\n\u6253\u5e73\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aaliceValues = [2,4,3], bobValues = [1,6,7]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\n\u4e0d\u7ba1 Alice \u600e\u4e48\u64cd\u4f5c\uff0cBob \u90fd\u53ef\u4ee5\u5f97\u5230\u6bd4 Alice \u66f4\u9ad8\u7684\u5f97\u5206\u3002\n\u6bd4\u65b9\u8bf4\uff0cAlice \u62ff\u77f3\u5b50 1 \uff0cBob \u62ff\u77f3\u5b50 2 \uff0c Alice \u62ff\u77f3\u5b50 0 \uff0cAlice \u4f1a\u5f97\u5230 6 \u5206\u800c Bob \u5f97\u5206\u4e3a 7 \u5206\u3002\nBob \u4f1a\u83b7\u80dc\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == aliceValues.length == bobValues.length
    • \n\t
    • 1 <= n <= 105
    • \n\t
    • 1 <= aliceValues[i], bobValues[i] <= 100
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int stoneGameVI(vector& aliceValues, vector& bobValues) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int stoneGameVI(int[] aliceValues, int[] bobValues) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def stoneGameVI(self, aliceValues, bobValues):\n \"\"\"\n :type aliceValues: List[int]\n :type bobValues: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def stoneGameVI(self, aliceValues: List[int], bobValues: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint stoneGameVI(int* aliceValues, int aliceValuesSize, int* bobValues, int bobValuesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int StoneGameVI(int[] aliceValues, int[] bobValues) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} aliceValues\n * @param {number[]} bobValues\n * @return {number}\n */\nvar stoneGameVI = function(aliceValues, bobValues) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} alice_values\n# @param {Integer[]} bob_values\n# @return {Integer}\ndef stone_game_vi(alice_values, bob_values)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func stoneGameVI(_ aliceValues: [Int], _ bobValues: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func stoneGameVI(aliceValues []int, bobValues []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def stoneGameVI(aliceValues: Array[Int], bobValues: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun stoneGameVI(aliceValues: IntArray, bobValues: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn stone_game_vi(alice_values: Vec, bob_values: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $aliceValues\n * @param Integer[] $bobValues\n * @return Integer\n */\n function stoneGameVI($aliceValues, $bobValues) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function stoneGameVI(aliceValues: number[], bobValues: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (stone-game-vi aliceValues bobValues)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1686](https://leetcode-cn.com/problems/stone-game-vi)", "[\u77f3\u5b50\u6e38\u620f VI](/solution/1600-1699/1686.Stone%20Game%20VI/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1686](https://leetcode.com/problems/stone-game-vi)", "[Stone Game VI](/solution/1600-1699/1686.Stone%20Game%20VI/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1787", "frontend_question_id": "1685", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sum-of-absolute-differences-in-a-sorted-array", "url_en": "https://leetcode.com/problems/sum-of-absolute-differences-in-a-sorted-array", "relative_path_cn": "/solution/1600-1699/1685.Sum%20of%20Absolute%20Differences%20in%20a%20Sorted%20Array/README.md", "relative_path_en": "/solution/1600-1699/1685.Sum%20of%20Absolute%20Differences%20in%20a%20Sorted%20Array/README_EN.md", "title_cn": "\u6709\u5e8f\u6570\u7ec4\u4e2d\u5dee\u7edd\u5bf9\u503c\u4e4b\u548c", "title_en": "Sum of Absolute Differences in a Sorted Array", "question_title_slug": "sum-of-absolute-differences-in-a-sorted-array", "content_en": "

    You are given an integer array nums sorted in non-decreasing order.

    \n\n

    Build and return an integer array result with the same length as nums such that result[i] is equal to the summation of absolute differences between nums[i] and all the other elements in the array.

    \n\n

    In other words, result[i] is equal to sum(|nums[i]-nums[j]|) where 0 <= j < nums.length and j != i (0-indexed).

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [2,3,5]\nOutput: [4,3,5]\nExplanation: Assuming the arrays are 0-indexed, then\nresult[0] = |2-2| + |2-3| + |2-5| = 0 + 1 + 3 = 4,\nresult[1] = |3-2| + |3-3| + |3-5| = 1 + 0 + 2 = 3,\nresult[2] = |5-2| + |5-3| + |5-5| = 3 + 2 + 0 = 5.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,4,6,8,10]\nOutput: [24,15,13,15,21]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= nums.length <= 105
    • \n\t
    • 1 <= nums[i] <= nums[i + 1] <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a \u975e\u9012\u51cf\u00a0\u6709\u5e8f\u6574\u6570\u6570\u7ec4\u00a0nums\u00a0\u3002

    \n\n

    \u8bf7\u4f60\u5efa\u7acb\u5e76\u8fd4\u56de\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0result\uff0c\u5b83\u8ddf\u00a0nums\u00a0\u957f\u5ea6\u76f8\u540c\uff0c\u4e14result[i]\u00a0\u7b49\u4e8e\u00a0nums[i]\u00a0\u4e0e\u6570\u7ec4\u4e2d\u6240\u6709\u5176\u4ed6\u5143\u7d20\u5dee\u7684\u7edd\u5bf9\u503c\u4e4b\u548c\u3002

    \n\n

    \u6362\u53e5\u8bdd\u8bf4\uff0c\u00a0result[i]\u00a0\u7b49\u4e8e\u00a0sum(|nums[i]-nums[j]|) \uff0c\u5176\u4e2d\u00a00 <= j < nums.length \u4e14\u00a0j != i\u00a0\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [2,3,5]\n\u8f93\u51fa\uff1a[4,3,5]\n\u89e3\u91ca\uff1a\u5047\u8bbe\u6570\u7ec4\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff0c\u90a3\u4e48\nresult[0] = |2-2| + |2-3| + |2-5| = 0 + 1 + 3 = 4\uff0c\nresult[1] = |3-2| + |3-3| + |3-5| = 1 + 0 + 2 = 3\uff0c\nresult[2] = |5-2| + |5-3| + |5-5| = 3 + 2 + 0 = 5\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,4,6,8,10]\n\u8f93\u51fa\uff1a[24,15,13,15,21]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= nums.length <= 105
    • \n\t
    • 1 <= nums[i] <= nums[i + 1] <= 104
    • \n
    \n", "tags_en": ["Greedy", "Math"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector getSumAbsoluteDifferences(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] getSumAbsoluteDifferences(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getSumAbsoluteDifferences(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getSumAbsoluteDifferences(self, nums: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* getSumAbsoluteDifferences(int* nums, int numsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] GetSumAbsoluteDifferences(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar getSumAbsoluteDifferences = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer[]}\ndef get_sum_absolute_differences(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getSumAbsoluteDifferences(_ nums: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getSumAbsoluteDifferences(nums []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getSumAbsoluteDifferences(nums: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getSumAbsoluteDifferences(nums: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_sum_absolute_differences(nums: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer[]\n */\n function getSumAbsoluteDifferences($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getSumAbsoluteDifferences(nums: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-sum-absolute-differences nums)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1685](https://leetcode-cn.com/problems/sum-of-absolute-differences-in-a-sorted-array)", "[\u6709\u5e8f\u6570\u7ec4\u4e2d\u5dee\u7edd\u5bf9\u503c\u4e4b\u548c](/solution/1600-1699/1685.Sum%20of%20Absolute%20Differences%20in%20a%20Sorted%20Array/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1685](https://leetcode.com/problems/sum-of-absolute-differences-in-a-sorted-array)", "[Sum of Absolute Differences in a Sorted Array](/solution/1600-1699/1685.Sum%20of%20Absolute%20Differences%20in%20a%20Sorted%20Array/README_EN.md)", "`Greedy`,`Math`", "Medium", ""]}, {"question_id": "1786", "frontend_question_id": "1684", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-the-number-of-consistent-strings", "url_en": "https://leetcode.com/problems/count-the-number-of-consistent-strings", "relative_path_cn": "/solution/1600-1699/1684.Count%20the%20Number%20of%20Consistent%20Strings/README.md", "relative_path_en": "/solution/1600-1699/1684.Count%20the%20Number%20of%20Consistent%20Strings/README_EN.md", "title_cn": "\u7edf\u8ba1\u4e00\u81f4\u5b57\u7b26\u4e32\u7684\u6570\u76ee", "title_en": "Count the Number of Consistent Strings", "question_title_slug": "count-the-number-of-consistent-strings", "content_en": "

    You are given a string allowed consisting of distinct characters and an array of strings words. A string is consistent if all characters in the string appear in the string allowed.

    \n\n

    Return the number of consistent strings in the array words.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: allowed = "ab", words = ["ad","bd","aaab","baa","badab"]\nOutput: 2\nExplanation: Strings "aaab" and "baa" are consistent since they only contain characters 'a' and 'b'.\n
    \n\n

    Example 2:

    \n\n
    \nInput: allowed = "abc", words = ["a","b","c","ab","ac","bc","abc"]\nOutput: 7\nExplanation: All strings are consistent.\n
    \n\n

    Example 3:

    \n\n
    \nInput: allowed = "cad", words = ["cc","acd","b","ba","bac","bad","ac","d"]\nOutput: 4\nExplanation: Strings "cc", "acd", "ac", and "d" are consistent.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= words.length <= 104
    • \n\t
    • 1 <= allowed.length <= 26
    • \n\t
    • 1 <= words[i].length <= 10
    • \n\t
    • The characters in allowed are distinct.
    • \n\t
    • words[i] and allowed contain only lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u7531\u4e0d\u540c\u5b57\u7b26\u7ec4\u6210\u7684\u5b57\u7b26\u4e32\u00a0allowed\u00a0\u548c\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4\u00a0words\u00a0\u3002\u5982\u679c\u4e00\u4e2a\u5b57\u7b26\u4e32\u7684\u6bcf\u4e00\u4e2a\u5b57\u7b26\u90fd\u5728 allowed\u00a0\u4e2d\uff0c\u5c31\u79f0\u8fd9\u4e2a\u5b57\u7b26\u4e32\u662f \u4e00\u81f4\u5b57\u7b26\u4e32 \u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u00a0words\u00a0\u6570\u7ec4\u4e2d\u00a0\u4e00\u81f4\u5b57\u7b26\u4e32 \u7684\u6570\u76ee\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aallowed = \"ab\", words = [\"ad\",\"bd\",\"aaab\",\"baa\",\"badab\"]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5b57\u7b26\u4e32 \"aaab\" \u548c \"baa\" \u90fd\u662f\u4e00\u81f4\u5b57\u7b26\u4e32\uff0c\u56e0\u4e3a\u5b83\u4eec\u53ea\u5305\u542b\u5b57\u7b26 'a' \u548c 'b' \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aallowed = \"abc\", words = [\"a\",\"b\",\"c\",\"ab\",\"ac\",\"bc\",\"abc\"]\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\u6240\u6709\u5b57\u7b26\u4e32\u90fd\u662f\u4e00\u81f4\u7684\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aallowed = \"cad\", words = [\"cc\",\"acd\",\"b\",\"ba\",\"bac\",\"bad\",\"ac\",\"d\"]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u5b57\u7b26\u4e32 \"cc\"\uff0c\"acd\"\uff0c\"ac\" \u548c \"d\" \u662f\u4e00\u81f4\u5b57\u7b26\u4e32\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= words.length <= 104
    • \n\t
    • 1 <= allowed.length <= 26
    • \n\t
    • 1 <= words[i].length <= 10
    • \n\t
    • allowed\u00a0\u4e2d\u7684\u5b57\u7b26 \u4e92\u4e0d\u76f8\u540c\u00a0\u3002
    • \n\t
    • words[i] \u548c\u00a0allowed\u00a0\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countConsistentStrings(string allowed, vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countConsistentStrings(String allowed, String[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countConsistentStrings(self, allowed, words):\n \"\"\"\n :type allowed: str\n :type words: List[str]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countConsistentStrings(self, allowed: str, words: List[str]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countConsistentStrings(char * allowed, char ** words, int wordsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountConsistentStrings(string allowed, string[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} allowed\n * @param {string[]} words\n * @return {number}\n */\nvar countConsistentStrings = function(allowed, words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} allowed\n# @param {String[]} words\n# @return {Integer}\ndef count_consistent_strings(allowed, words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countConsistentStrings(_ allowed: String, _ words: [String]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countConsistentStrings(allowed string, words []string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countConsistentStrings(allowed: String, words: Array[String]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countConsistentStrings(allowed: String, words: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_consistent_strings(allowed: String, words: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $allowed\n * @param String[] $words\n * @return Integer\n */\n function countConsistentStrings($allowed, $words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countConsistentStrings(allowed: string, words: string[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-consistent-strings allowed words)\n (-> string? (listof string?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1684](https://leetcode-cn.com/problems/count-the-number-of-consistent-strings)", "[\u7edf\u8ba1\u4e00\u81f4\u5b57\u7b26\u4e32\u7684\u6570\u76ee](/solution/1600-1699/1684.Count%20the%20Number%20of%20Consistent%20Strings/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1684](https://leetcode.com/problems/count-the-number-of-consistent-strings)", "[Count the Number of Consistent Strings](/solution/1600-1699/1684.Count%20the%20Number%20of%20Consistent%20Strings/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1785", "frontend_question_id": "1645", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/hopper-company-queries-ii", "url_en": "https://leetcode.com/problems/hopper-company-queries-ii", "relative_path_cn": "/solution/1600-1699/1645.Hopper%20Company%20Queries%20II/README.md", "relative_path_en": "/solution/1600-1699/1645.Hopper%20Company%20Queries%20II/README_EN.md", "title_cn": "", "title_en": "Hopper Company Queries II", "question_title_slug": "hopper-company-queries-ii", "content_en": "

    Table: Drivers

    \n\n
    \n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| driver_id   | int     |\n| join_date   | date    |\n+-------------+---------+\ndriver_id is the primary key for this table.\nEach row of this table contains the driver's ID and the date they joined the Hopper company.\n
    \n\n

     

    \n\n

    Table: Rides

    \n\n
    \n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| ride_id      | int     |\n| user_id      | int     |\n| requested_at | date    |\n+--------------+---------+\nride_id is the primary key for this table.\nEach row of this table contains the ID of a ride, the user's ID that requested it, and the day they requested it.\nThere may be some ride requests in this table that were not accepted.\n
    \n\n

     

    \n\n

    Table: AcceptedRides

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| ride_id       | int     |\n| driver_id     | int     |\n| ride_distance | int     |\n| ride_duration | int     |\n+---------------+---------+\nride_id is the primary key for this table.\nEach row of this table contains some information about an accepted ride.\nIt is guaranteed that each accepted ride exists in the Rides table.\n
    \n\n

     

    \n\n

    Write an SQL query to report the percentage of working drivers (working_percentage) for each month of 2020 where:

    \n\"\"\n

    Note that if the number of available drivers during a month is zero, we consider the working_percentage to be 0.

    \n\n

    Return the result table ordered by month in ascending order, where month is the month's number (January is 1, February is 2, etc.). Round working_percentage to the nearest 2 decimal places.

    \n\n

    The query result format is in the following example.

    \n\n

     

    \n\n
    \nDrivers table:\n+-----------+------------+\n| driver_id | join_date  |\n+-----------+------------+\n| 10        | 2019-12-10 |\n| 8         | 2020-1-13  |\n| 5         | 2020-2-16  |\n| 7         | 2020-3-8   |\n| 4         | 2020-5-17  |\n| 1         | 2020-10-24 |\n| 6         | 2021-1-5   |\n+-----------+------------+\n\nRides table:\n+---------+---------+--------------+\n| ride_id | user_id | requested_at |\n+---------+---------+--------------+\n| 6       | 75      | 2019-12-9    |\n| 1       | 54      | 2020-2-9     |\n| 10      | 63      | 2020-3-4     |\n| 19      | 39      | 2020-4-6     |\n| 3       | 41      | 2020-6-3     |\n| 13      | 52      | 2020-6-22    |\n| 7       | 69      | 2020-7-16    |\n| 17      | 70      | 2020-8-25    |\n| 20      | 81      | 2020-11-2    |\n| 5       | 57      | 2020-11-9    |\n| 2       | 42      | 2020-12-9    |\n| 11      | 68      | 2021-1-11    |\n| 15      | 32      | 2021-1-17    |\n| 12      | 11      | 2021-1-19    |\n| 14      | 18      | 2021-1-27    |\n+---------+---------+--------------+\n\nAcceptedRides table:\n+---------+-----------+---------------+---------------+\n| ride_id | driver_id | ride_distance | ride_duration |\n+---------+-----------+---------------+---------------+\n| 10      | 10        | 63            | 38            |\n| 13      | 10        | 73            | 96            |\n| 7       | 8         | 100           | 28            |\n| 17      | 7         | 119           | 68            |\n| 20      | 1         | 121           | 92            |\n| 5       | 7         | 42            | 101           |\n| 2       | 4         | 6             | 38            |\n| 11      | 8         | 37            | 43            |\n| 15      | 8         | 108           | 82            |\n| 12      | 8         | 38            | 34            |\n| 14      | 1         | 90            | 74            |\n+---------+-----------+---------------+---------------+\n\nResult table:\n+-------+--------------------+\n| month | working_percentage |\n+-------+--------------------+\n| 1     | 0.00               |\n| 2     | 0.00               |\n| 3     | 25.00              |\n| 4     | 0.00               |\n| 5     | 0.00               |\n| 6     | 20.00              |\n| 7     | 20.00              |\n| 8     | 20.00              |\n| 9     | 0.00               |\n| 10    | 0.00               |\n| 11    | 33.33              |\n| 12    | 16.67              |\n+-------+--------------------+\n\nBy the end of January --> two active drivers (10, 8) and no accepted rides. The percentage is 0%.\nBy the end of February --> three active drivers (10, 8, 5) and no accepted rides. The percentage is 0%.\nBy the end of March --> four active drivers (10, 8, 5, 7) and one accepted ride by driver (10). The percentage is (1 / 4) * 100 = 25%.\nBy the end of April --> four active drivers (10, 8, 5, 7) and no accepted rides. The percentage is 0%.\nBy the end of May --> five active drivers (10, 8, 5, 7, 4) and no accepted rides. The percentage is 0%.\nBy the end of June --> five active drivers (10, 8, 5, 7, 4) and one accepted ride by driver (10). The percentage is (1 / 5) * 100 = 20%.\nBy the end of July --> five active drivers (10, 8, 5, 7, 4) and one accepted ride by driver (8). The percentage is (1 / 5) * 100 = 20%.\nBy the end of August --> five active drivers (10, 8, 5, 7, 4) and one accepted ride by driver (7). The percentage is (1 / 5) * 100 = 20%.\nBy the end of Septemeber --> five active drivers (10, 8, 5, 7, 4) and no accepted rides. The percentage is 0%.\nBy the end of October --> six active drivers (10, 8, 5, 7, 4, 1) and no accepted rides. The percentage is 0%.\nBy the end of November --> six active drivers (10, 8, 5, 7, 4, 1) and two accepted rides by two different drivers (1, 7). The percentage is (2 / 6) * 100 = 33.33%.\nBy the end of December --> six active drivers (10, 8, 5, 7, 4, 1) and one accepted ride by driver (4). The percentage is (1 / 6) * 100 = 16.67%.\n
    \n", "content_cn": null, "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1645](https://leetcode-cn.com/problems/hopper-company-queries-ii)", "[Hopper Company Queries II](/solution/1600-1699/1645.Hopper%20Company%20Queries%20II/README_EN.md)", "", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1645](https://leetcode.com/problems/hopper-company-queries-ii)", "[Hopper Company Queries II](/solution/1600-1699/1645.Hopper%20Company%20Queries%20II/README_EN.md)", "", "Hard", "\ud83d\udd12"]}, {"question_id": "1784", "frontend_question_id": "1665", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-initial-energy-to-finish-tasks", "url_en": "https://leetcode.com/problems/minimum-initial-energy-to-finish-tasks", "relative_path_cn": "/solution/1600-1699/1665.Minimum%20Initial%20Energy%20to%20Finish%20Tasks/README.md", "relative_path_en": "/solution/1600-1699/1665.Minimum%20Initial%20Energy%20to%20Finish%20Tasks/README_EN.md", "title_cn": "\u5b8c\u6210\u6240\u6709\u4efb\u52a1\u7684\u6700\u5c11\u521d\u59cb\u80fd\u91cf", "title_en": "Minimum Initial Energy to Finish Tasks", "question_title_slug": "minimum-initial-energy-to-finish-tasks", "content_en": "

    You are given an array tasks where tasks[i] = [actuali, minimumi]:

    \n\n
      \n\t
    • actuali is the actual amount of energy you spend to finish the ith task.
    • \n\t
    • minimumi is the minimum amount of energy you require to begin the ith task.
    • \n
    \n\n

    For example, if the task is [10, 12] and your current energy is 11, you cannot start this task. However, if your current energy is 13, you can complete this task, and your energy will be 3 after finishing it.

    \n\n

    You can finish the tasks in any order you like.

    \n\n

    Return the minimum initial amount of energy you will need to finish all the tasks.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: tasks = [[1,2],[2,4],[4,8]]\nOutput: 8\nExplanation:\nStarting with 8 energy, we finish the tasks in the following order:\n    - 3rd task. Now energy = 8 - 4 = 4.\n    - 2nd task. Now energy = 4 - 2 = 2.\n    - 1st task. Now energy = 2 - 1 = 1.\nNotice that even though we have leftover energy, starting with 7 energy does not work because we cannot do the 3rd task.
    \n\n

    Example 2:

    \n\n
    \nInput: tasks = [[1,3],[2,4],[10,11],[10,12],[8,9]]\nOutput: 32\nExplanation:\nStarting with 32 energy, we finish the tasks in the following order:\n    - 1st task. Now energy = 32 - 1 = 31.\n    - 2nd task. Now energy = 31 - 2 = 29.\n    - 3rd task. Now energy = 29 - 10 = 19.\n    - 4th task. Now energy = 19 - 10 = 9.\n    - 5th task. Now energy = 9 - 8 = 1.
    \n\n

    Example 3:

    \n\n
    \nInput: tasks = [[1,7],[2,8],[3,9],[4,10],[5,11],[6,12]]\nOutput: 27\nExplanation:\nStarting with 27 energy, we finish the tasks in the following order:\n    - 5th task. Now energy = 27 - 5 = 22.\n    - 2nd task. Now energy = 22 - 2 = 20.\n    - 3rd task. Now energy = 20 - 3 = 17.\n    - 1st task. Now energy = 17 - 1 = 16.\n    - 4th task. Now energy = 16 - 4 = 12.\n    - 6th task. Now energy = 12 - 6 = 6.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= tasks.length <= 105
    • \n\t
    • 1 <= actual\u200bi <= minimumi <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u4efb\u52a1\u6570\u7ec4\u00a0tasks \uff0c\u5176\u4e2d\u00a0tasks[i] = [actuali, minimumi]\u00a0\uff1a

    \n\n
      \n\t
    • actuali\u00a0\u662f\u5b8c\u6210\u7b2c i\u00a0\u4e2a\u4efb\u52a1 \u9700\u8981\u8017\u8d39\u00a0\u7684\u5b9e\u9645\u80fd\u91cf\u3002
    • \n\t
    • minimumi\u00a0\u662f\u5f00\u59cb\u7b2c i\u00a0\u4e2a\u4efb\u52a1\u524d\u9700\u8981\u8fbe\u5230\u7684\u6700\u4f4e\u80fd\u91cf\u3002
    • \n
    \n\n

    \u6bd4\u65b9\u8bf4\uff0c\u5982\u679c\u4efb\u52a1\u4e3a\u00a0[10, 12]\u00a0\u4e14\u4f60\u5f53\u524d\u7684\u80fd\u91cf\u4e3a\u00a011\u00a0\uff0c\u90a3\u4e48\u4f60\u4e0d\u80fd\u5f00\u59cb\u8fd9\u4e2a\u4efb\u52a1\u3002\u5982\u679c\u4f60\u5f53\u524d\u7684\u80fd\u91cf\u4e3a\u00a013\u00a0\uff0c\u4f60\u53ef\u4ee5\u5b8c\u6210\u8fd9\u4e2a\u4efb\u52a1\uff0c\u4e14\u5b8c\u6210\u5b83\u540e\u5269\u4f59\u80fd\u91cf\u4e3a 3\u00a0\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u6309\u7167 \u4efb\u610f\u987a\u5e8f\u00a0\u5b8c\u6210\u4efb\u52a1\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u5b8c\u6210\u6240\u6709\u4efb\u52a1\u7684 \u6700\u5c11\u00a0\u521d\u59cb\u80fd\u91cf\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1atasks = [[1,2],[2,4],[4,8]]\n\u8f93\u51fa\uff1a8\n\u89e3\u91ca\uff1a\n\u4e00\u5f00\u59cb\u6709 8 \u80fd\u91cf\uff0c\u6211\u4eec\u6309\u7167\u5982\u4e0b\u987a\u5e8f\u5b8c\u6210\u4efb\u52a1\uff1a\n    - \u5b8c\u6210\u7b2c 3 \u4e2a\u4efb\u52a1\uff0c\u5269\u4f59\u80fd\u91cf\u4e3a 8 - 4 = 4 \u3002\n    - \u5b8c\u6210\u7b2c 2 \u4e2a\u4efb\u52a1\uff0c\u5269\u4f59\u80fd\u91cf\u4e3a 4 - 2 = 2 \u3002\n    - \u5b8c\u6210\u7b2c 1 \u4e2a\u4efb\u52a1\uff0c\u5269\u4f59\u80fd\u91cf\u4e3a 2 - 1 = 1 \u3002\n\u6ce8\u610f\u5230\u5c3d\u7ba1\u6211\u4eec\u6709\u80fd\u91cf\u5269\u4f59\uff0c\u4f46\u662f\u5982\u679c\u4e00\u5f00\u59cb\u53ea\u6709 7 \u80fd\u91cf\u662f\u4e0d\u80fd\u5b8c\u6210\u6240\u6709\u4efb\u52a1\u7684\uff0c\u56e0\u4e3a\u6211\u4eec\u65e0\u6cd5\u5f00\u59cb\u7b2c 3 \u4e2a\u4efb\u52a1\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1atasks = [[1,3],[2,4],[10,11],[10,12],[8,9]]\n\u8f93\u51fa\uff1a32\n\u89e3\u91ca\uff1a\n\u4e00\u5f00\u59cb\u6709 32 \u80fd\u91cf\uff0c\u6211\u4eec\u6309\u7167\u5982\u4e0b\u987a\u5e8f\u5b8c\u6210\u4efb\u52a1\uff1a\n    - \u5b8c\u6210\u7b2c 1 \u4e2a\u4efb\u52a1\uff0c\u5269\u4f59\u80fd\u91cf\u4e3a 32 - 1 = 31 \u3002\n    - \u5b8c\u6210\u7b2c 2 \u4e2a\u4efb\u52a1\uff0c\u5269\u4f59\u80fd\u91cf\u4e3a 31 - 2 = 29 \u3002\n    - \u5b8c\u6210\u7b2c 3 \u4e2a\u4efb\u52a1\uff0c\u5269\u4f59\u80fd\u91cf\u4e3a 29 - 10 = 19 \u3002\n    - \u5b8c\u6210\u7b2c 4 \u4e2a\u4efb\u52a1\uff0c\u5269\u4f59\u80fd\u91cf\u4e3a 19 - 10 = 9 \u3002\n    - \u5b8c\u6210\u7b2c 5 \u4e2a\u4efb\u52a1\uff0c\u5269\u4f59\u80fd\u91cf\u4e3a 9 - 8 = 1 \u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1atasks = [[1,7],[2,8],[3,9],[4,10],[5,11],[6,12]]\n\u8f93\u51fa\uff1a27\n\u89e3\u91ca\uff1a\n\u4e00\u5f00\u59cb\u6709 27 \u80fd\u91cf\uff0c\u6211\u4eec\u6309\u7167\u5982\u4e0b\u987a\u5e8f\u5b8c\u6210\u4efb\u52a1\uff1a\n    - \u5b8c\u6210\u7b2c 5 \u4e2a\u4efb\u52a1\uff0c\u5269\u4f59\u80fd\u91cf\u4e3a 27 - 5 = 22 \u3002\n    - \u5b8c\u6210\u7b2c 2 \u4e2a\u4efb\u52a1\uff0c\u5269\u4f59\u80fd\u91cf\u4e3a 22 - 2 = 20 \u3002\n    - \u5b8c\u6210\u7b2c 3 \u4e2a\u4efb\u52a1\uff0c\u5269\u4f59\u80fd\u91cf\u4e3a 20 - 3 = 17 \u3002\n    - \u5b8c\u6210\u7b2c 1 \u4e2a\u4efb\u52a1\uff0c\u5269\u4f59\u80fd\u91cf\u4e3a 17 - 1 = 16 \u3002\n    - \u5b8c\u6210\u7b2c 4 \u4e2a\u4efb\u52a1\uff0c\u5269\u4f59\u80fd\u91cf\u4e3a 16 - 4 = 12 \u3002\n    - \u5b8c\u6210\u7b2c 6 \u4e2a\u4efb\u52a1\uff0c\u5269\u4f59\u80fd\u91cf\u4e3a 12 - 6 = 6 \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= tasks.length <= 105
    • \n\t
    • 1 <= actual\u200bi\u00a0<= minimumi\u00a0<= 104
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minimumEffort(vector>& tasks) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minimumEffort(int[][] tasks) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimumEffort(self, tasks):\n \"\"\"\n :type tasks: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimumEffort(self, tasks: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minimumEffort(int** tasks, int tasksSize, int* tasksColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinimumEffort(int[][] tasks) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} tasks\n * @return {number}\n */\nvar minimumEffort = function(tasks) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} tasks\n# @return {Integer}\ndef minimum_effort(tasks)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimumEffort(_ tasks: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimumEffort(tasks [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimumEffort(tasks: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimumEffort(tasks: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimum_effort(tasks: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $tasks\n * @return Integer\n */\n function minimumEffort($tasks) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimumEffort(tasks: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimum-effort tasks)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1665](https://leetcode-cn.com/problems/minimum-initial-energy-to-finish-tasks)", "[\u5b8c\u6210\u6240\u6709\u4efb\u52a1\u7684\u6700\u5c11\u521d\u59cb\u80fd\u91cf](/solution/1600-1699/1665.Minimum%20Initial%20Energy%20to%20Finish%20Tasks/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[1665](https://leetcode.com/problems/minimum-initial-energy-to-finish-tasks)", "[Minimum Initial Energy to Finish Tasks](/solution/1600-1699/1665.Minimum%20Initial%20Energy%20to%20Finish%20Tasks/README_EN.md)", "`Greedy`", "Hard", ""]}, {"question_id": "1783", "frontend_question_id": "1664", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/ways-to-make-a-fair-array", "url_en": "https://leetcode.com/problems/ways-to-make-a-fair-array", "relative_path_cn": "/solution/1600-1699/1664.Ways%20to%20Make%20a%20Fair%20Array/README.md", "relative_path_en": "/solution/1600-1699/1664.Ways%20to%20Make%20a%20Fair%20Array/README_EN.md", "title_cn": "\u751f\u6210\u5e73\u8861\u6570\u7ec4\u7684\u65b9\u6848\u6570", "title_en": "Ways to Make a Fair Array", "question_title_slug": "ways-to-make-a-fair-array", "content_en": "

    You are given an integer array nums. You can choose exactly one index (0-indexed) and remove the element. Notice that the index of the elements may change after the removal.

    \n\n

    For example, if nums = [6,1,7,4,1]:

    \n\n
      \n\t
    • Choosing to remove index 1 results in nums = [6,7,4,1].
    • \n\t
    • Choosing to remove index 2 results in nums = [6,1,4,1].
    • \n\t
    • Choosing to remove index 4 results in nums = [6,1,7,4].
    • \n
    \n\n

    An array is fair if the sum of the odd-indexed values equals the sum of the even-indexed values.

    \n\n

    Return the number of indices that you could choose such that after the removal, nums is fair.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [2,1,6,4]\nOutput: 1\nExplanation:\nRemove index 0: [1,6,4] -> Even sum: 1 + 4 = 5. Odd sum: 6. Not fair.\nRemove index 1: [2,6,4] -> Even sum: 2 + 4 = 6. Odd sum: 6. Fair.\nRemove index 2: [2,1,4] -> Even sum: 2 + 4 = 6. Odd sum: 1. Not fair.\nRemove index 3: [2,1,6] -> Even sum: 2 + 6 = 8. Odd sum: 1. Not fair.\nThere is 1 index that you can remove to make nums fair.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,1,1]\nOutput: 3\nExplanation: You can remove any index and the remaining array is fair.\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [1,2,3]\nOutput: 0\nExplanation: You cannot make a fair array after removing any index.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • 1 <= nums[i] <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0nums\u00a0\u3002\u4f60\u9700\u8981\u9009\u62e9 \u6070\u597d\u00a0\u4e00\u4e2a\u4e0b\u6807\uff08\u4e0b\u6807\u4ece 0\u00a0\u5f00\u59cb\uff09\u5e76\u5220\u9664\u5bf9\u5e94\u7684\u5143\u7d20\u3002\u8bf7\u6ce8\u610f\u5269\u4e0b\u5143\u7d20\u7684\u4e0b\u6807\u53ef\u80fd\u4f1a\u56e0\u4e3a\u5220\u9664\u64cd\u4f5c\u800c\u53d1\u751f\u6539\u53d8\u3002

    \n\n

    \u6bd4\u65b9\u8bf4\uff0c\u5982\u679c\u00a0nums = [6,1,7,4,1]\u00a0\uff0c\u90a3\u4e48\uff1a

    \n\n
      \n\t
    • \u9009\u62e9\u5220\u9664\u4e0b\u6807 1 \uff0c\u5269\u4e0b\u7684\u6570\u7ec4\u4e3a\u00a0nums = [6,7,4,1]\u00a0\u3002
    • \n\t
    • \u9009\u62e9\u5220\u9664\u4e0b\u6807\u00a02\u00a0\uff0c\u5269\u4e0b\u7684\u6570\u7ec4\u4e3a\u00a0nums = [6,1,4,1]\u00a0\u3002
    • \n\t
    • \u9009\u62e9\u5220\u9664\u4e0b\u6807\u00a04\u00a0\uff0c\u5269\u4e0b\u7684\u6570\u7ec4\u4e3a\u00a0nums = [6,1,7,4]\u00a0\u3002
    • \n
    \n\n

    \u5982\u679c\u4e00\u4e2a\u6570\u7ec4\u6ee1\u8db3\u5947\u6570\u4e0b\u6807\u5143\u7d20\u7684\u548c\u4e0e\u5076\u6570\u4e0b\u6807\u5143\u7d20\u7684\u548c\u76f8\u7b49\uff0c\u8be5\u6570\u7ec4\u5c31\u662f\u4e00\u4e2a \u5e73\u8861\u6570\u7ec4 \u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u5220\u9664\u64cd\u4f5c\u540e\uff0c\u5269\u4e0b\u7684\u6570\u7ec4\u00a0nums\u00a0\u662f\u00a0\u5e73\u8861\u6570\u7ec4 \u7684\u00a0\u65b9\u6848\u6570\u00a0\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [2,1,6,4]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\n\u5220\u9664\u4e0b\u6807 0 \uff1a[1,6,4] -> \u5076\u6570\u5143\u7d20\u4e0b\u6807\u4e3a\uff1a1 + 4 = 5 \u3002\u5947\u6570\u5143\u7d20\u4e0b\u6807\u4e3a\uff1a6 \u3002\u4e0d\u5e73\u8861\u3002\n\u5220\u9664\u4e0b\u6807 1 \uff1a[2,6,4] -> \u5076\u6570\u5143\u7d20\u4e0b\u6807\u4e3a\uff1a2 + 4 = 6 \u3002\u5947\u6570\u5143\u7d20\u4e0b\u6807\u4e3a\uff1a6 \u3002\u5e73\u8861\u3002\n\u5220\u9664\u4e0b\u6807 2 \uff1a[2,1,4] -> \u5076\u6570\u5143\u7d20\u4e0b\u6807\u4e3a\uff1a2 + 4 = 6 \u3002\u5947\u6570\u5143\u7d20\u4e0b\u6807\u4e3a\uff1a1 \u3002\u4e0d\u5e73\u8861\u3002\n\u5220\u9664\u4e0b\u6807 3 \uff1a[2,1,6] -> \u5076\u6570\u5143\u7d20\u4e0b\u6807\u4e3a\uff1a2 + 6 = 8 \u3002\u5947\u6570\u5143\u7d20\u4e0b\u6807\u4e3a\uff1a1 \u3002\u4e0d\u5e73\u8861\u3002\n\u53ea\u6709\u4e00\u79cd\u8ba9\u5269\u4f59\u6570\u7ec4\u6210\u4e3a\u5e73\u8861\u6570\u7ec4\u7684\u65b9\u6848\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,1,1]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u5220\u9664\u4efb\u610f\u5143\u7d20\uff0c\u5269\u4f59\u6570\u7ec4\u90fd\u662f\u5e73\u8861\u6570\u7ec4\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,3]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u4e0d\u7ba1\u5220\u9664\u54ea\u4e2a\u5143\u7d20\uff0c\u5269\u4e0b\u6570\u7ec4\u90fd\u4e0d\u662f\u5e73\u8861\u6570\u7ec4\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • 1 <= nums[i] <= 104
    • \n
    \n", "tags_en": ["Greedy", "Dynamic Programming"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int waysToMakeFair(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int waysToMakeFair(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def waysToMakeFair(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def waysToMakeFair(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint waysToMakeFair(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int WaysToMakeFair(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar waysToMakeFair = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef ways_to_make_fair(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func waysToMakeFair(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func waysToMakeFair(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def waysToMakeFair(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun waysToMakeFair(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn ways_to_make_fair(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function waysToMakeFair($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function waysToMakeFair(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (ways-to-make-fair nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1664](https://leetcode-cn.com/problems/ways-to-make-a-fair-array)", "[\u751f\u6210\u5e73\u8861\u6570\u7ec4\u7684\u65b9\u6848\u6570](/solution/1600-1699/1664.Ways%20to%20Make%20a%20Fair%20Array/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1664](https://leetcode.com/problems/ways-to-make-a-fair-array)", "[Ways to Make a Fair Array](/solution/1600-1699/1664.Ways%20to%20Make%20a%20Fair%20Array/README_EN.md)", "`Greedy`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "1782", "frontend_question_id": "1663", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/smallest-string-with-a-given-numeric-value", "url_en": "https://leetcode.com/problems/smallest-string-with-a-given-numeric-value", "relative_path_cn": "/solution/1600-1699/1663.Smallest%20String%20With%20A%20Given%20Numeric%20Value/README.md", "relative_path_en": "/solution/1600-1699/1663.Smallest%20String%20With%20A%20Given%20Numeric%20Value/README_EN.md", "title_cn": "\u5177\u6709\u7ed9\u5b9a\u6570\u503c\u7684\u6700\u5c0f\u5b57\u7b26\u4e32", "title_en": "Smallest String With A Given Numeric Value", "question_title_slug": "smallest-string-with-a-given-numeric-value", "content_en": "

    The numeric value of a lowercase character is defined as its position (1-indexed) in the alphabet, so the numeric value of a is 1, the numeric value of b is 2, the numeric value of c is 3, and so on.

    \n\n

    The numeric value of a string consisting of lowercase characters is defined as the sum of its characters' numeric values. For example, the numeric value of the string "abe" is equal to 1 + 2 + 5 = 8.

    \n\n

    You are given two integers n and k. Return the lexicographically smallest string with length equal to n and numeric value equal to k.

    \n\n

    Note that a string x is lexicographically smaller than string y if x comes before y in dictionary order, that is, either x is a prefix of y, or if i is the first position such that x[i] != y[i], then x[i] comes before y[i] in alphabetic order.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 3, k = 27\nOutput: "aay"\nExplanation: The numeric value of the string is 1 + 1 + 25 = 27, and it is the smallest string with such a value and length equal to 3.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 5, k = 73\nOutput: "aaszz"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 105
    • \n\t
    • n <= k <= 26 * n
    • \n
    \n", "content_cn": "

    \u5c0f\u5199\u5b57\u7b26 \u7684 \u6570\u503c \u662f\u5b83\u5728\u5b57\u6bcd\u8868\u4e2d\u7684\u4f4d\u7f6e\uff08\u4ece 1 \u5f00\u59cb\uff09\uff0c\u56e0\u6b64 a \u7684\u6570\u503c\u4e3a 1 \uff0cb \u7684\u6570\u503c\u4e3a 2 \uff0cc \u7684\u6570\u503c\u4e3a 3 \uff0c\u4ee5\u6b64\u7c7b\u63a8\u3002

    \n\n

    \u5b57\u7b26\u4e32\u7531\u82e5\u5e72\u5c0f\u5199\u5b57\u7b26\u7ec4\u6210\uff0c\u5b57\u7b26\u4e32\u7684\u6570\u503c \u4e3a\u5404\u5b57\u7b26\u7684\u6570\u503c\u4e4b\u548c\u3002\u4f8b\u5982\uff0c\u5b57\u7b26\u4e32 \"abe\" \u7684\u6570\u503c\u7b49\u4e8e 1 + 2 + 5 = 8 \u3002

    \n\n

    \u7ed9\u4f60\u4e24\u4e2a\u6574\u6570 n \u548c k \u3002\u8fd4\u56de \u957f\u5ea6 \u7b49\u4e8e n \u4e14 \u6570\u503c \u7b49\u4e8e k \u7684 \u5b57\u5178\u5e8f\u6700\u5c0f \u7684\u5b57\u7b26\u4e32\u3002

    \n\n

    \u6ce8\u610f\uff0c\u5982\u679c\u5b57\u7b26\u4e32 x \u5728\u5b57\u5178\u6392\u5e8f\u4e2d\u4f4d\u4e8e y \u4e4b\u524d\uff0c\u5c31\u8ba4\u4e3a x \u5b57\u5178\u5e8f\u6bd4 y \u5c0f\uff0c\u6709\u4ee5\u4e0b\u4e24\u79cd\u60c5\u51b5\uff1a

    \n\n
      \n\t
    • x \u662f y \u7684\u4e00\u4e2a\u524d\u7f00\uff1b
    • \n\t
    • \u5982\u679c i \u662f\u00a0x[i] != y[i] \u7684\u7b2c\u4e00\u4e2a\u4f4d\u7f6e\uff0c\u4e14 x[i]\u00a0\u5728\u5b57\u6bcd\u8868\u4e2d\u7684\u4f4d\u7f6e\u6bd4\u00a0y[i]\u00a0\u9760\u524d\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 3, k = 27\n\u8f93\u51fa\uff1a\"aay\"\n\u89e3\u91ca\uff1a\u5b57\u7b26\u4e32\u7684\u6570\u503c\u4e3a 1 + 1 + 25 = 27\uff0c\u5b83\u662f\u6570\u503c\u6ee1\u8db3\u8981\u6c42\u4e14\u957f\u5ea6\u7b49\u4e8e 3 \u5b57\u5178\u5e8f\u6700\u5c0f\u7684\u5b57\u7b26\u4e32\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 5, k = 73\n\u8f93\u51fa\uff1a\"aaszz\"\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 105
    • \n\t
    • n <= k <= 26 * n
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string getSmallestString(int n, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String getSmallestString(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getSmallestString(self, n, k):\n \"\"\"\n :type n: int\n :type k: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getSmallestString(self, n: int, k: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * getSmallestString(int n, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string GetSmallestString(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} k\n * @return {string}\n */\nvar getSmallestString = function(n, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} k\n# @return {String}\ndef get_smallest_string(n, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getSmallestString(_ n: Int, _ k: Int) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getSmallestString(n int, k int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getSmallestString(n: Int, k: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getSmallestString(n: Int, k: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_smallest_string(n: i32, k: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $k\n * @return String\n */\n function getSmallestString($n, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getSmallestString(n: number, k: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-smallest-string n k)\n (-> exact-integer? exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1663](https://leetcode-cn.com/problems/smallest-string-with-a-given-numeric-value)", "[\u5177\u6709\u7ed9\u5b9a\u6570\u503c\u7684\u6700\u5c0f\u5b57\u7b26\u4e32](/solution/1600-1699/1663.Smallest%20String%20With%20A%20Given%20Numeric%20Value/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1663](https://leetcode.com/problems/smallest-string-with-a-given-numeric-value)", "[Smallest String With A Given Numeric Value](/solution/1600-1699/1663.Smallest%20String%20With%20A%20Given%20Numeric%20Value/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1781", "frontend_question_id": "1662", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/check-if-two-string-arrays-are-equivalent", "url_en": "https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent", "relative_path_cn": "/solution/1600-1699/1662.Check%20If%20Two%20String%20Arrays%20are%20Equivalent/README.md", "relative_path_en": "/solution/1600-1699/1662.Check%20If%20Two%20String%20Arrays%20are%20Equivalent/README_EN.md", "title_cn": "\u68c0\u67e5\u4e24\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4\u662f\u5426\u76f8\u7b49", "title_en": "Check If Two String Arrays are Equivalent", "question_title_slug": "check-if-two-string-arrays-are-equivalent", "content_en": "

    Given two string arrays word1 and word2, return true if the two arrays represent the same string, and false otherwise.

    \n\n

    A string is represented by an array if the array elements concatenated in order forms the string.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: word1 = ["ab", "c"], word2 = ["a", "bc"]\nOutput: true\nExplanation:\nword1 represents string "ab" + "c" -> "abc"\nword2 represents string "a" + "bc" -> "abc"\nThe strings are the same, so return true.
    \n\n

    Example 2:

    \n\n
    \nInput: word1 = ["a", "cb"], word2 = ["ab", "c"]\nOutput: false\n
    \n\n

    Example 3:

    \n\n
    \nInput: word1  = ["abc", "d", "defg"], word2 = ["abcddefg"]\nOutput: true\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= word1.length, word2.length <= 103
    • \n\t
    • 1 <= word1[i].length, word2[i].length <= 103
    • \n\t
    • 1 <= sum(word1[i].length), sum(word2[i].length) <= 103
    • \n\t
    • word1[i] and word2[i] consist of lowercase letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4 word1 \u548c word2 \u3002\u5982\u679c\u4e24\u4e2a\u6570\u7ec4\u8868\u793a\u7684\u5b57\u7b26\u4e32\u76f8\u540c\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n

    \u6570\u7ec4\u8868\u793a\u7684\u5b57\u7b26\u4e32\u00a0\u662f\u7531\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20 \u6309\u987a\u5e8f \u8fde\u63a5\u5f62\u6210\u7684\u5b57\u7b26\u4e32\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aword1 = [\"ab\", \"c\"], word2 = [\"a\", \"bc\"]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\nword1 \u8868\u793a\u7684\u5b57\u7b26\u4e32\u4e3a \"ab\" + \"c\" -> \"abc\"\nword2 \u8868\u793a\u7684\u5b57\u7b26\u4e32\u4e3a \"a\" + \"bc\" -> \"abc\"\n\u4e24\u4e2a\u5b57\u7b26\u4e32\u76f8\u540c\uff0c\u8fd4\u56de true
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aword1 = [\"a\", \"cb\"], word2 = [\"ab\", \"c\"]\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aword1  = [\"abc\", \"d\", \"defg\"], word2 = [\"abcddefg\"]\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= word1.length, word2.length <= 103
    • \n\t
    • 1 <= word1[i].length, word2[i].length <= 103
    • \n\t
    • 1 <= sum(word1[i].length), sum(word2[i].length) <= 103
    • \n\t
    • word1[i] \u548c word2[i] \u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool arrayStringsAreEqual(vector& word1, vector& word2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean arrayStringsAreEqual(String[] word1, String[] word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def arrayStringsAreEqual(self, word1, word2):\n \"\"\"\n :type word1: List[str]\n :type word2: List[str]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool arrayStringsAreEqual(char ** word1, int word1Size, char ** word2, int word2Size){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool ArrayStringsAreEqual(string[] word1, string[] word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} word1\n * @param {string[]} word2\n * @return {boolean}\n */\nvar arrayStringsAreEqual = function(word1, word2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} word1\n# @param {String[]} word2\n# @return {Boolean}\ndef array_strings_are_equal(word1, word2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func arrayStringsAreEqual(_ word1: [String], _ word2: [String]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func arrayStringsAreEqual(word1 []string, word2 []string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def arrayStringsAreEqual(word1: Array[String], word2: Array[String]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun arrayStringsAreEqual(word1: Array, word2: Array): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn array_strings_are_equal(word1: Vec, word2: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $word1\n * @param String[] $word2\n * @return Boolean\n */\n function arrayStringsAreEqual($word1, $word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function arrayStringsAreEqual(word1: string[], word2: string[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (array-strings-are-equal word1 word2)\n (-> (listof string?) (listof string?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1662](https://leetcode-cn.com/problems/check-if-two-string-arrays-are-equivalent)", "[\u68c0\u67e5\u4e24\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4\u662f\u5426\u76f8\u7b49](/solution/1600-1699/1662.Check%20If%20Two%20String%20Arrays%20are%20Equivalent/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1662](https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent)", "[Check If Two String Arrays are Equivalent](/solution/1600-1699/1662.Check%20If%20Two%20String%20Arrays%20are%20Equivalent/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1780", "frontend_question_id": "1644", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-tree-ii", "url_en": "https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree-ii", "relative_path_cn": "/solution/1600-1699/1644.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree%20II/README.md", "relative_path_en": "/solution/1600-1699/1644.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree%20II/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148 II", "title_en": "Lowest Common Ancestor of a Binary Tree II", "question_title_slug": "lowest-common-ancestor-of-a-binary-tree-ii", "content_en": "

    Given the root of a binary tree, return the lowest common ancestor (LCA) of two given nodes, p and q. If either node p or q does not exist in the tree, return null. All values of the nodes in the tree are unique.

    \n\n

    According to the definition of LCA on Wikipedia: "The lowest common ancestor of two nodes p and q in a binary tree T is the lowest node that has both p and q as descendants (where we allow a node to be a descendant of itself)". A descendant of a node x is a node y that is on the path from node x to some leaf node.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 1\nOutput: 3\nExplanation: The LCA of nodes 5 and 1 is 3.
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 4\nOutput: 5\nExplanation: The LCA of nodes 5 and 4 is 5. A node can be a descendant of itself according to the definition of LCA.
    \n\n

    Example 3:

    \n\n

    \"\"

    \n\n
    \nInput: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 10\nOutput: null\nExplanation: Node 10 does not exist in the tree, so return null.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 104].
    • \n\t
    • -109 <= Node.val <= 109
    • \n\t
    • All Node.val are unique.
    • \n\t
    • p != q
    • \n
    \n\n

     

    \nFollow up: Can you find the LCA traversing the tree, without checking nodes existence?", "content_cn": "

    \u7ed9\u5b9a\u4e00\u68f5\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9 root\uff0c\u8fd4\u56de\u7ed9\u5b9a\u8282\u70b9 p \u548c q \u7684\u6700\u8fd1\u516c\u5171\u7956\u5148\uff08LCA\uff09\u8282\u70b9\u3002\u5982\u679c p \u6216 q \u4e4b\u4e00\u4e0d\u5b58\u5728\u4e8e\u8be5\u4e8c\u53c9\u6811\u4e2d\uff0c\u8fd4\u56de null\u3002\u6811\u4e2d\u7684\u6bcf\u4e2a\u8282\u70b9\u503c\u90fd\u662f\u4e92\u4e0d\u76f8\u540c\u7684\u3002

    \n\n

    \u6839\u636e\u7ef4\u57fa\u767e\u79d1\u4e2d\u5bf9\u6700\u8fd1\u516c\u5171\u7956\u5148\u8282\u70b9\u7684\u5b9a\u4e49\uff1a\u201c\u4e24\u4e2a\u8282\u70b9 p \u548c q \u5728\u4e8c\u53c9\u6811 T \u4e2d\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148\u8282\u70b9\u662f\u540e\u4ee3\u8282\u70b9\u4e2d\u65e2\u5305\u62ec p\u00a0\u53c8\u5305\u62ec\u00a0q\u00a0\u7684\u6700\u6df1\u8282\u70b9\uff08\u6211\u4eec\u5141\u8bb8\u4e00\u4e2a\u8282\u70b9\u4e3a\u81ea\u8eab\u7684\u4e00\u4e2a\u540e\u4ee3\u8282\u70b9\uff09\u201d\u3002\u4e00\u4e2a\u8282\u70b9 x\u00a0\u7684\u540e\u4ee3\u8282\u70b9\u662f\u8282\u70b9\u00a0x \u5230\u67d0\u4e00\u53f6\u8282\u70b9\u95f4\u7684\u8def\u5f84\u4e2d\u7684\u8282\u70b9 y\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1:

    \n\"\"\n
    \u8f93\u5165\uff1a root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 1\n\u8f93\u51fa\uff1a 3\n\u89e3\u91ca\uff1a \u8282\u70b9 5 \u548c 1 \u7684\u5171\u540c\u7956\u5148\u8282\u70b9\u662f 3\u3002
    \n\n

    \u793a\u4f8b 2:

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1a root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 4\n\u8f93\u51fa\uff1a 5\n\u89e3\u91ca\uff1a \u8282\u70b9 5 \u548c 4 \u7684\u5171\u540c\u7956\u5148\u8282\u70b9\u662f 5\u3002\u6839\u636e\u5171\u540c\u7956\u5148\u8282\u70b9\u7684\u5b9a\u4e49\uff0c\u4e00\u4e2a\u8282\u70b9\u53ef\u4ee5\u662f\u81ea\u8eab\u7684\u540e\u4ee3\u8282\u70b9\u3002
    \n\n

    \u793a\u4f8b 3:

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1a root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 10\n\u8f93\u51fa\uff1a null\n\u89e3\u91ca\uff1a \u8282\u70b9 10 \u4e0d\u5b58\u5728\u4e8e\u6811\u4e2d\uff0c\u6240\u4ee5\u8fd4\u56de null\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a:

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u4e2a\u6570\u7684\u8303\u56f4\u662f\u00a0[1, 104]\u3002
    • \n\t
    • -109 <= Node.val <= 109
    • \n\t
    • \u6240\u6709\u8282\u70b9\u7684\u503c\u00a0Node.val\u00a0\u662f\u4e92\u4e0d\u76f8\u540c\u7684\u3002
    • \n\t
    • p != q
    • \n
    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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 */\nclass Solution {\npublic:\n TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode(int x) { val = x; }\n * }\n */\nclass Solution {\n public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution(object):\n def lowestCommonAncestor(self, root, p, q):\n \"\"\"\n :type root: TreeNode\n :type p: TreeNode\n :type q: TreeNode\n :rtype: TreeNode\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution:\n def lowestCommonAncestor(self, root: 'TreeNode', p: 'TreeNode', q: 'TreeNode') -> 'TreeNode':\n ", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int x) { val = x; }\n * }\n */\npublic class Solution {\n public TreeNode LowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val) {\n * this.val = val;\n * this.left = this.right = null;\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {TreeNode} p\n * @param {TreeNode} q\n * @return {TreeNode}\n */\nvar lowestCommonAncestor = function(root, p, q) {\n \n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1644](https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-tree-ii)", "[\u4e8c\u53c9\u6811\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148 II](/solution/1600-1699/1644.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree%20II/README.md)", "`\u6811`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1644](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree-ii)", "[Lowest Common Ancestor of a Binary Tree II](/solution/1600-1699/1644.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree%20II/README_EN.md)", "`Tree`", "Medium", "\ud83d\udd12"]}, {"question_id": "1779", "frontend_question_id": "1635", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/hopper-company-queries-i", "url_en": "https://leetcode.com/problems/hopper-company-queries-i", "relative_path_cn": "/solution/1600-1699/1635.Hopper%20Company%20Queries%20I/README.md", "relative_path_en": "/solution/1600-1699/1635.Hopper%20Company%20Queries%20I/README_EN.md", "title_cn": "Hopper \u516c\u53f8\u67e5\u8be2 I", "title_en": "Hopper Company Queries I", "question_title_slug": "hopper-company-queries-i", "content_en": "

    Table: Drivers

    \n\n
    \n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| driver_id   | int     |\n| join_date   | date    |\n+-------------+---------+\ndriver_id is the primary key for this table.\nEach row of this table contains the driver's ID and the date they joined the Hopper company.\n
    \n\n

     

    \n\n

    Table: Rides

    \n\n
    \n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| ride_id      | int     |\n| user_id      | int     |\n| requested_at | date    |\n+--------------+---------+\nride_id is the primary key for this table.\nEach row of this table contains the ID of a ride, the user's ID that requested it, and the day they requested it.\nThere may be some ride requests in this table that were not accepted.\n
    \n\n

     

    \n\n

    Table: AcceptedRides

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| ride_id       | int     |\n| driver_id     | int     |\n| ride_distance | int     |\n| ride_duration | int     |\n+---------------+---------+\nride_id is the primary key for this table.\nEach row of this table contains some information about an accepted ride.\nIt is guaranteed that each accepted ride exists in the Rides table.\n
    \n\n

     

    \n\n

    Write an SQL query to report the following statistics for each month of 2020:

    \n\n
      \n\t
    • The number of drivers currently with the Hopper company by the end of the month (active_drivers).
    • \n\t
    • The number of accepted rides in that month (accepted_rides).
    • \n
    \n\n

    Return the result table ordered by month in ascending order, where month is the month's number (January is 1, February is 2, etc.).

    \n\n

    The query result format is in the following example.

    \n\n

     

    \n\n
    \nDrivers table:\n+-----------+------------+\n| driver_id | join_date  |\n+-----------+------------+\n| 10        | 2019-12-10 |\n| 8         | 2020-1-13  |\n| 5         | 2020-2-16  |\n| 7         | 2020-3-8   |\n| 4         | 2020-5-17  |\n| 1         | 2020-10-24 |\n| 6         | 2021-1-5   |\n+-----------+------------+\n\nRides table:\n+---------+---------+--------------+\n| ride_id | user_id | requested_at |\n+---------+---------+--------------+\n| 6       | 75      | 2019-12-9    |\n| 1       | 54      | 2020-2-9     |\n| 10      | 63      | 2020-3-4     |\n| 19      | 39      | 2020-4-6     |\n| 3       | 41      | 2020-6-3     |\n| 13      | 52      | 2020-6-22    |\n| 7       | 69      | 2020-7-16    |\n| 17      | 70      | 2020-8-25    |\n| 20      | 81      | 2020-11-2    |\n| 5       | 57      | 2020-11-9    |\n| 2       | 42      | 2020-12-9    |\n| 11      | 68      | 2021-1-11    |\n| 15      | 32      | 2021-1-17    |\n| 12      | 11      | 2021-1-19    |\n| 14      | 18      | 2021-1-27    |\n+---------+---------+--------------+\n\nAcceptedRides table:\n+---------+-----------+---------------+---------------+\n| ride_id | driver_id | ride_distance | ride_duration |\n+---------+-----------+---------------+---------------+\n| 10      | 10        | 63            | 38            |\n| 13      | 10        | 73            | 96            |\n| 7       | 8         | 100           | 28            |\n| 17      | 7         | 119           | 68            |\n| 20      | 1         | 121           | 92            |\n| 5       | 7         | 42            | 101           |\n| 2       | 4         | 6             | 38            |\n| 11      | 8         | 37            | 43            |\n| 15      | 8         | 108           | 82            |\n| 12      | 8         | 38            | 34            |\n| 14      | 1         | 90            | 74            |\n+---------+-----------+---------------+---------------+\n\nResult table:\n+-------+----------------+----------------+\n| month | active_drivers | accepted_rides |\n+-------+----------------+----------------+\n| 1     | 2              | 0              |\n| 2     | 3              | 0              |\n| 3     | 4              | 1              |\n| 4     | 4              | 0              |\n| 5     | 5              | 0              |\n| 6     | 5              | 1              |\n| 7     | 5              | 1              |\n| 8     | 5              | 1              |\n| 9     | 5              | 0              |\n| 10    | 6              | 0              |\n| 11    | 6              | 2              |\n| 12    | 6              | 1              |\n+-------+----------------+----------------+\n\nBy the end of January --> two active drivers (10, 8) and no accepted rides.\nBy the end of February --> three active drivers (10, 8, 5) and no accepted rides.\nBy the end of March --> four active drivers (10, 8, 5, 7) and one accepted ride (10).\nBy the end of April --> four active drivers (10, 8, 5, 7) and no accepted rides.\nBy the end of May --> five active drivers (10, 8, 5, 7, 4) and no accepted rides.\nBy the end of June --> five active drivers (10, 8, 5, 7, 4) and one accepted ride (13).\nBy the end of July --> five active drivers (10, 8, 5, 7, 4) and one accepted ride (7).\nBy the end of August --> five active drivers (10, 8, 5, 7, 4) and one accepted ride (17).\nBy the end of Septemeber --> five active drivers (10, 8, 5, 7, 4) and no accepted rides.\nBy the end of October --> six active drivers (10, 8, 5, 7, 4, 1) and no accepted rides.\nBy the end of November --> six active drivers (10, 8, 5, 7, 4, 1) and two accepted rides (20, 5).\nBy the end of December --> six active drivers (10, 8, 5, 7, 4, 1) and one accepted ride (2).\n
    \n", "content_cn": "

    \u8868: Drivers

    \n\n
    +-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| driver_id   | int     |\n| join_date   | date    |\n+-------------+---------+\ndriver_id\u662f\u8be5\u8868\u7684\u4e3b\u952e\u3002\n\u8be5\u8868\u7684\u6bcf\u4e00\u884c\u5747\u5305\u542b\u9a7e\u9a76\u5458\u7684ID\u4ee5\u53ca\u4ed6\u4eec\u52a0\u5165Hopper\u516c\u53f8\u7684\u65e5\u671f\u3002\n
    \n\n

    \u00a0

    \n\n

    \u8868: Rides

    \n\n
    +--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| ride_id      | int     |\n| user_id      | int     |\n| requested_at | date    |\n+--------------+---------+\nride_id\u662f\u8be5\u8868\u7684\u4e3b\u952e\u3002\n\u8be5\u8868\u7684\u6bcf\u4e00\u884c\u5747\u5305\u542b\u884c\u7a0bID(ride_id)\uff0c\u7528\u6237ID(user_id)\u4ee5\u53ca\u8be5\u884c\u7a0b\u7684\u65e5\u671f(requested_at)\u3002\n\u8be5\u8868\u4e2d\u53ef\u80fd\u6709\u4e00\u4e9b\u4e0d\u88ab\u63a5\u53d7\u7684\u4e58\u8f66\u8bf7\u6c42\u3002\n
    \n\n

    \u00a0

    \n\n

    \u8868: AcceptedRides

    \n\n
    +---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| ride_id       | int     |\n| driver_id     | int     |\n| ride_distance | int     |\n| ride_duration | int     |\n+---------------+---------+\nride_id\u662f\u8be5\u8868\u7684\u4e3b\u952e\u3002\n\u8be5\u8868\u7684\u6bcf\u4e00\u884c\u90fd\u5305\u542b\u5df2\u63a5\u53d7\u7684\u884c\u7a0b\u4fe1\u606f\u3002\n\u8868\u4e2d\u7684\u884c\u7a0b\u4fe1\u606f\u90fd\u5728\u201cRides\u201d\u8868\u4e2d\u5b58\u5728\u3002\n
    \n\n

    \u00a0

    \n\n

    \u7f16\u5199SQL\u67e5\u8be2\u4ee5\u62a5\u544a2020\u5e74\u6bcf\u4e2a\u6708\u7684\u4ee5\u4e0b\u7edf\u8ba1\u4fe1\u606f\uff1a

    \n\n
      \n\t
    • \u622a\u81f3\u67d0\u6708\u5e95\uff0c\u5f53\u524d\u5728Hopper\u516c\u53f8\u5de5\u4f5c\u7684\u9a7e\u9a76\u5458\u6570\u91cf\uff08active_drivers\uff09\u3002
    • \n\t
    • \u8be5\u6708\u63a5\u53d7\u7684\u4e58\u8f66\u6b21\u6570\uff08accepted_rides\uff09\u3002
    • \n
    \n\n

    \u8fd4\u56de\u6309month \u5347\u5e8f\u6392\u5217\u7684\u7ed3\u679c\u8868\uff0c\u5176\u4e2dmonth \u662f\u6708\u4efd\u7684\u6570\u5b57\uff08\u4e00\u6708\u662f1\uff0c\u4e8c\u6708\u662f2\uff0c\u4f9d\u6b64\u7c7b\u63a8\uff09\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a\u3002

    \n\n
    \u8868 Drivers:\n+-----------+------------+\n| driver_id | join_date  |\n+-----------+------------+\n| 10        | 2019-12-10 |\n| 8         | 2020-1-13  |\n| 5         | 2020-2-16  |\n| 7         | 2020-3-8   |\n| 4         | 2020-5-17  |\n| 1         | 2020-10-24 |\n| 6         | 2021-1-5   |\n+-----------+------------+\n\n\u8868 Rides:\n+---------+---------+--------------+\n| ride_id | user_id | requested_at |\n+---------+---------+--------------+\n| 6       | 75      | 2019-12-9    |\n| 1       | 54      | 2020-2-9     |\n| 10      | 63      | 2020-3-4     |\n| 19      | 39      | 2020-4-6     |\n| 3       | 41      | 2020-6-3     |\n| 13      | 52      | 2020-6-22    |\n| 7       | 69      | 2020-7-16    |\n| 17      | 70      | 2020-8-25    |\n| 20      | 81      | 2020-11-2    |\n| 5       | 57      | 2020-11-9    |\n| 2       | 42      | 2020-12-9    |\n| 11      | 68      | 2021-1-11    |\n| 15      | 32      | 2021-1-17    |\n| 12      | 11      | 2021-1-19    |\n| 14      | 18      | 2021-1-27    |\n+---------+---------+--------------+\n\n\u8868 AcceptedRides:\n+---------+-----------+---------------+---------------+\n| ride_id | driver_id | ride_distance | ride_duration |\n+---------+-----------+---------------+---------------+\n| 10      | 10        | 63            | 38            |\n| 13      | 10        | 73            | 96            |\n| 7       | 8         | 100           | 28            |\n| 17      | 7         | 119           | 68            |\n| 20      | 1         | 121           | 92            |\n| 5       | 7         | 42            | 101           |\n| 2       | 4         | 6             | 38            |\n| 11      | 8         | 37            | 43            |\n| 15      | 8         | 108           | 82            |\n| 12      | 8         | 38            | 34            |\n| 14      | 1         | 90            | 74            |\n+---------+-----------+---------------+---------------+\n\n\u7ed3\u679c\u8868:\n+-------+----------------+----------------+\n| month | active_drivers | accepted_rides |\n+-------+----------------+----------------+\n| 1     | 2              | 0              |\n| 2     | 3              | 0              |\n| 3     | 4              | 1              |\n| 4     | 4              | 0              |\n| 5     | 5              | 0              |\n| 6     | 5              | 1              |\n| 7     | 5              | 1              |\n| 8     | 5              | 1              |\n| 9     | 5              | 0              |\n| 10    | 6              | 0              |\n| 11    | 6              | 2              |\n| 12    | 6              | 1              |\n+-------+----------------+----------------+\n\n\u622a\u81f31\u6708\u5e95->\u4e24\u4e2a\u6d3b\u8dc3\u7684\u9a7e\u9a76\u5458\uff0810,8\uff09\uff0c\u6ca1\u6709\u88ab\u63a5\u53d7\u7684\u884c\u7a0b\u3002\n\u622a\u81f32\u6708\u5e95->\u4e09\u4e2a\u6d3b\u8dc3\u7684\u9a7e\u9a76\u5458\uff0810,8,5\uff09\uff0c\u6ca1\u6709\u88ab\u63a5\u53d7\u7684\u884c\u7a0b\u3002\n\u622a\u81f33\u6708\u5e95->\u56db\u4e2a\u6d3b\u8dc3\u7684\u9a7e\u9a76\u5458\uff0810,8,5,7\uff09\uff0c\u4e00\u4e2a\u88ab\u63a5\u53d7\u7684\u884c\u7a0b\uff0810\uff09\u3002\n\u622a\u81f34\u6708\u5e95->\u56db\u4e2a\u6d3b\u8dc3\u7684\u9a7e\u9a76\u5458\uff0810,8,5,7\uff09\uff0c\u6ca1\u6709\u88ab\u63a5\u53d7\u7684\u884c\u7a0b\u3002\n\u622a\u81f35\u6708\u5e95->\u4e94\u4e2a\u6d3b\u8dc3\u7684\u9a7e\u9a76\u5458\uff0810,8,5,7,4\uff09\uff0c\u6ca1\u6709\u88ab\u63a5\u53d7\u7684\u884c\u7a0b\u3002\n\u622a\u81f36\u6708\u5e95->\u4e94\u4e2a\u6d3b\u8dc3\u7684\u9a7e\u9a76\u5458\uff0810,8,5,7,4\uff09\uff0c\u4e00\u4e2a\u88ab\u63a5\u53d7\u7684\u884c\u7a0b\uff0813\uff09\u3002\n\u622a\u81f37\u6708\u5e95->\u4e94\u4e2a\u6d3b\u8dc3\u7684\u9a7e\u9a76\u5458\uff0810,8,5,7,4\uff09\uff0c\u4e00\u4e2a\u88ab\u63a5\u53d7\u7684\u884c\u7a0b\uff087\uff09\u3002\n\u622a\u81f38\u6708\u5e95->\u4e94\u4e2a\u6d3b\u8dc3\u7684\u9a7e\u9a76\u5458\uff0810,8,5,7,4\uff09\uff0c\u4e00\u4f4d\u63a5\u53d7\u7684\u884c\u7a0b\uff0817\uff09\u3002\n\u622a\u81f39\u6708\u5e95->\u4e94\u4e2a\u6d3b\u8dc3\u7684\u9a7e\u9a76\u5458\uff0810,8,5,7,4\uff09\uff0c\u6ca1\u6709\u88ab\u63a5\u53d7\u7684\u884c\u7a0b\u3002\n\u622a\u81f310\u6708\u5e95->\u516d\u4e2a\u6d3b\u8dc3\u7684\u9a7e\u9a76\u5458\uff0810,8,5,7,4,1\uff09\uff0c\u6ca1\u6709\u88ab\u63a5\u53d7\u7684\u884c\u7a0b\u3002\n\u622a\u81f311\u6708\u5e95->\u516d\u4e2a\u6d3b\u8dc3\u7684\u9a7e\u9a76\u5458\uff0810,8,5,7,4,1\uff09\uff0c\u4e24\u4e2a\u88ab\u63a5\u53d7\u7684\u884c\u7a0b\uff0820,5\uff09\u3002\n\u622a\u81f312\u6708\u5e95->\u516d\u4e2a\u6d3b\u8dc3\u7684\u9a7e\u9a76\u5458\uff0810,8,5,7,4,1\uff09\uff0c\u4e00\u4e2a\u88ab\u63a5\u53d7\u7684\u884c\u7a0b\uff082\uff09\u3002\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1635](https://leetcode-cn.com/problems/hopper-company-queries-i)", "[Hopper \u516c\u53f8\u67e5\u8be2 I](/solution/1600-1699/1635.Hopper%20Company%20Queries%20I/README.md)", "", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1635](https://leetcode.com/problems/hopper-company-queries-i)", "[Hopper Company Queries I](/solution/1600-1699/1635.Hopper%20Company%20Queries%20I/README_EN.md)", "", "Hard", "\ud83d\udd12"]}, {"question_id": "1778", "frontend_question_id": "1659", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximize-grid-happiness", "url_en": "https://leetcode.com/problems/maximize-grid-happiness", "relative_path_cn": "/solution/1600-1699/1659.Maximize%20Grid%20Happiness/README.md", "relative_path_en": "/solution/1600-1699/1659.Maximize%20Grid%20Happiness/README_EN.md", "title_cn": "\u6700\u5927\u5316\u7f51\u683c\u5e78\u798f\u611f", "title_en": "Maximize Grid Happiness", "question_title_slug": "maximize-grid-happiness", "content_en": "

    You are given four integers, m, n, introvertsCount, and extrovertsCount. You have an m x n grid, and there are two types of people: introverts and extroverts. There are introvertsCount introverts and extrovertsCount extroverts.

    \n\n

    You should decide how many people you want to live in the grid and assign each of them one grid cell. Note that you do not have to have all the people living in the grid.

    \n\n

    The happiness of each person is calculated as follows:

    \n\n
      \n\t
    • Introverts start with 120 happiness and lose 30 happiness for each neighbor (introvert or extrovert).
    • \n\t
    • Extroverts start with 40 happiness and gain 20 happiness for each neighbor (introvert or extrovert).
    • \n
    \n\n

    Neighbors live in the directly adjacent cells north, east, south, and west of a person's cell.

    \n\n

    The grid happiness is the sum of each person's happiness. Return the maximum possible grid happiness.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: m = 2, n = 3, introvertsCount = 1, extrovertsCount = 2\nOutput: 240\nExplanation: Assume the grid is 1-indexed with coordinates (row, column).\nWe can put the introvert in cell (1,1) and put the extroverts in cells (1,3) and (2,3).\n- Introvert at (1,1) happiness: 120 (starting happiness) - (0 * 30) (0 neighbors) = 120\n- Extrovert at (1,3) happiness: 40 (starting happiness) + (1 * 20) (1 neighbor) = 60\n- Extrovert at (2,3) happiness: 40 (starting happiness) + (1 * 20) (1 neighbor) = 60\nThe grid happiness is 120 + 60 + 60 = 240.\nThe above figure shows the grid in this example with each person's happiness. The introvert stays in the light green cell while the extroverts live on the light purple cells.\n
    \n\n

    Example 2:

    \n\n
    \nInput: m = 3, n = 1, introvertsCount = 2, extrovertsCount = 1\nOutput: 260\nExplanation: Place the two introverts in (1,1) and (3,1) and the extrovert at (2,1).\n- Introvert at (1,1) happiness: 120 (starting happiness) - (1 * 30) (1 neighbor) = 90\n- Extrovert at (2,1) happiness: 40 (starting happiness) + (2 * 20) (2 neighbors) = 80\n- Introvert at (3,1) happiness: 120 (starting happiness) - (1 * 30) (1 neighbor) = 90\nThe grid happiness is 90 + 80 + 90 = 260.\n
    \n\n

    Example 3:

    \n\n
    \nInput: m = 2, n = 2, introvertsCount = 4, extrovertsCount = 0\nOutput: 240\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= m, n <= 5
    • \n\t
    • 0 <= introvertsCount, extrovertsCount <= min(m * n, 6)
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u56db\u4e2a\u6574\u6570 m\u3001n\u3001introvertsCount \u548c extrovertsCount \u3002\u6709\u4e00\u4e2a m x n \u7f51\u683c\uff0c\u548c\u4e24\u79cd\u7c7b\u578b\u7684\u4eba\uff1a\u5185\u5411\u7684\u4eba\u548c\u5916\u5411\u7684\u4eba\u3002\u603b\u5171\u6709\u00a0introvertsCount \u4e2a\u5185\u5411\u7684\u4eba\u548c extrovertsCount \u4e2a\u5916\u5411\u7684\u4eba\u3002

    \n\n

    \u8bf7\u4f60\u51b3\u5b9a\u7f51\u683c\u4e2d\u5e94\u5f53\u5c45\u4f4f\u591a\u5c11\u4eba\uff0c\u5e76\u4e3a\u6bcf\u4e2a\u4eba\u5206\u914d\u4e00\u4e2a\u7f51\u683c\u5355\u5143\u3002 \u6ce8\u610f\uff0c\u4e0d\u5fc5 \u8ba9\u6240\u6709\u4eba\u90fd\u751f\u6d3b\u5728\u7f51\u683c\u4e2d\u3002

    \n\n

    \u6bcf\u4e2a\u4eba\u7684 \u5e78\u798f\u611f \u8ba1\u7b97\u5982\u4e0b\uff1a

    \n\n
      \n\t
    • \u5185\u5411\u7684\u4eba \u5f00\u59cb \u65f6\u6709 120 \u4e2a\u5e78\u798f\u611f\uff0c\u4f46\u6bcf\u5b58\u5728\u4e00\u4e2a\u90bb\u5c45\uff08\u5185\u5411\u7684\u6216\u5916\u5411\u7684\uff09\u4ed6\u90fd\u4f1a \u5931\u53bb\u00a0\u00a030 \u4e2a\u5e78\u798f\u611f\u3002
    • \n\t
    • \u5916\u5411\u7684\u4eba \u5f00\u59cb \u65f6\u6709 40 \u4e2a\u5e78\u798f\u611f\uff0c\u6bcf\u5b58\u5728\u4e00\u4e2a\u90bb\u5c45\uff08\u5185\u5411\u7684\u6216\u5916\u5411\u7684\uff09\u4ed6\u90fd\u4f1a \u5f97\u5230\u00a0\u00a020 \u4e2a\u5e78\u798f\u611f\u3002
    • \n
    \n\n

    \u90bb\u5c45\u662f\u6307\u5c45\u4f4f\u5728\u4e00\u4e2a\u4eba\u6240\u5728\u5355\u5143\u7684\u4e0a\u3001\u4e0b\u3001\u5de6\u3001\u53f3\u56db\u4e2a\u76f4\u63a5\u76f8\u90bb\u7684\u5355\u5143\u4e2d\u7684\u5176\u4ed6\u4eba\u3002

    \n\n

    \u7f51\u683c\u5e78\u798f\u611f\u00a0\u662f\u6bcf\u4e2a\u4eba\u5e78\u798f\u611f\u7684 \u603b\u548c \u3002 \u8fd4\u56de \u6700\u5927\u53ef\u80fd\u7684\u7f51\u683c\u5e78\u798f\u611f \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1am = 2, n = 3, introvertsCount = 1, extrovertsCount = 2\n\u8f93\u51fa\uff1a240\n\u89e3\u91ca\uff1a\u5047\u8bbe\u7f51\u683c\u5750\u6807 (row, column) \u4ece 1 \u5f00\u59cb\u7f16\u53f7\u3002\n\u5c06\u5185\u5411\u7684\u4eba\u653e\u7f6e\u5728\u5355\u5143 (1,1) \uff0c\u5c06\u5916\u5411\u7684\u4eba\u653e\u7f6e\u5728\u5355\u5143 (1,3) \u548c (2,3) \u3002\n- \u4f4d\u4e8e (1,1) \u7684\u5185\u5411\u7684\u4eba\u7684\u5e78\u798f\u611f\uff1a120\uff08\u521d\u59cb\u5e78\u798f\u611f\uff09- (0 * 30)\uff080 \u4f4d\u90bb\u5c45\uff09= 120\n- \u4f4d\u4e8e (1,3) \u7684\u5916\u5411\u7684\u4eba\u7684\u5e78\u798f\u611f\uff1a40\uff08\u521d\u59cb\u5e78\u798f\u611f\uff09+ (1 * 20)\uff081 \u4f4d\u90bb\u5c45\uff09= 60\n- \u4f4d\u4e8e (2,3) \u7684\u5916\u5411\u7684\u4eba\u7684\u5e78\u798f\u611f\uff1a40\uff08\u521d\u59cb\u5e78\u798f\u611f\uff09+ (1 * 20)\uff081 \u4f4d\u90bb\u5c45\uff09= 60\n\u7f51\u683c\u5e78\u798f\u611f\u4e3a\uff1a120 + 60 + 60 = 240\n\u4e0a\u56fe\u5c55\u793a\u8be5\u793a\u4f8b\u5bf9\u5e94\u7f51\u683c\u4e2d\u6bcf\u4e2a\u4eba\u7684\u5e78\u798f\u611f\u3002\u5185\u5411\u7684\u4eba\u5728\u6d45\u7eff\u8272\u5355\u5143\u4e2d\uff0c\u800c\u5916\u5411\u7684\u4eba\u5728\u6d45\u7d2b\u8272\u5355\u5143\u4e2d\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1am = 3, n = 1, introvertsCount = 2, extrovertsCount = 1\n\u8f93\u51fa\uff1a260\n\u89e3\u91ca\uff1a\u5c06\u5185\u5411\u7684\u4eba\u653e\u7f6e\u5728\u5355\u5143 (1,1) \u548c (3,1) \uff0c\u5c06\u5916\u5411\u7684\u4eba\u653e\u7f6e\u5728\u5355\u5143 (2,1) \u3002\n- \u4f4d\u4e8e (1,1) \u7684\u5185\u5411\u7684\u4eba\u7684\u5e78\u798f\u611f\uff1a120\uff08\u521d\u59cb\u5e78\u798f\u611f\uff09- (1 * 30)\uff081 \u4f4d\u90bb\u5c45\uff09= 90\n- \u4f4d\u4e8e (2,1) \u7684\u5916\u5411\u7684\u4eba\u7684\u5e78\u798f\u611f\uff1a40\uff08\u521d\u59cb\u5e78\u798f\u611f\uff09+ (2 * 20)\uff082 \u4f4d\u90bb\u5c45\uff09= 80\n- \u4f4d\u4e8e (3,1) \u7684\u5185\u5411\u7684\u4eba\u7684\u5e78\u798f\u611f\uff1a120\uff08\u521d\u59cb\u5e78\u798f\u611f\uff09- (1 * 30)\uff081 \u4f4d\u90bb\u5c45\uff09= 90\n\u7f51\u683c\u5e78\u798f\u611f\u4e3a 90 + 80 + 90 = 260\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1am = 2, n = 2, introvertsCount = 4, extrovertsCount = 0\n\u8f93\u51fa\uff1a240\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= m, n <= 5
    • \n\t
    • 0 <= introvertsCount, extrovertsCount <= min(m * n, 6)
    • \n
    \n", "tags_en": ["Dynamic Programming", "Backtracking"], "tags_cn": ["\u52a8\u6001\u89c4\u5212", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int getMaxGridHappiness(int m, int n, int introvertsCount, int extrovertsCount) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int getMaxGridHappiness(int m, int n, int introvertsCount, int extrovertsCount) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getMaxGridHappiness(self, m, n, introvertsCount, extrovertsCount):\n \"\"\"\n :type m: int\n :type n: int\n :type introvertsCount: int\n :type extrovertsCount: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getMaxGridHappiness(self, m: int, n: int, introvertsCount: int, extrovertsCount: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint getMaxGridHappiness(int m, int n, int introvertsCount, int extrovertsCount){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int GetMaxGridHappiness(int m, int n, int introvertsCount, int extrovertsCount) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} m\n * @param {number} n\n * @param {number} introvertsCount\n * @param {number} extrovertsCount\n * @return {number}\n */\nvar getMaxGridHappiness = function(m, n, introvertsCount, extrovertsCount) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} m\n# @param {Integer} n\n# @param {Integer} introverts_count\n# @param {Integer} extroverts_count\n# @return {Integer}\ndef get_max_grid_happiness(m, n, introverts_count, extroverts_count)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getMaxGridHappiness(_ m: Int, _ n: Int, _ introvertsCount: Int, _ extrovertsCount: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getMaxGridHappiness(m int, n int, introvertsCount int, extrovertsCount int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getMaxGridHappiness(m: Int, n: Int, introvertsCount: Int, extrovertsCount: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getMaxGridHappiness(m: Int, n: Int, introvertsCount: Int, extrovertsCount: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_max_grid_happiness(m: i32, n: i32, introverts_count: i32, extroverts_count: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $m\n * @param Integer $n\n * @param Integer $introvertsCount\n * @param Integer $extrovertsCount\n * @return Integer\n */\n function getMaxGridHappiness($m, $n, $introvertsCount, $extrovertsCount) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getMaxGridHappiness(m: number, n: number, introvertsCount: number, extrovertsCount: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-max-grid-happiness m n introvertsCount extrovertsCount)\n (-> exact-integer? exact-integer? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1659](https://leetcode-cn.com/problems/maximize-grid-happiness)", "[\u6700\u5927\u5316\u7f51\u683c\u5e78\u798f\u611f](/solution/1600-1699/1659.Maximize%20Grid%20Happiness/README.md)", "`\u52a8\u6001\u89c4\u5212`,`\u56de\u6eaf\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[1659](https://leetcode.com/problems/maximize-grid-happiness)", "[Maximize Grid Happiness](/solution/1600-1699/1659.Maximize%20Grid%20Happiness/README_EN.md)", "`Dynamic Programming`,`Backtracking`", "Hard", ""]}, {"question_id": "1777", "frontend_question_id": "1657", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/determine-if-two-strings-are-close", "url_en": "https://leetcode.com/problems/determine-if-two-strings-are-close", "relative_path_cn": "/solution/1600-1699/1657.Determine%20if%20Two%20Strings%20Are%20Close/README.md", "relative_path_en": "/solution/1600-1699/1657.Determine%20if%20Two%20Strings%20Are%20Close/README_EN.md", "title_cn": "\u786e\u5b9a\u4e24\u4e2a\u5b57\u7b26\u4e32\u662f\u5426\u63a5\u8fd1", "title_en": "Determine if Two Strings Are Close", "question_title_slug": "determine-if-two-strings-are-close", "content_en": "

    Two strings are considered close if you can attain one from the other using the following operations:

    \n\n
      \n\t
    • Operation 1: Swap any two existing characters.\n\n\t
        \n\t\t
      • For example, abcde -> aecdb
      • \n\t
      \n\t
    • \n\t
    • Operation 2: Transform every occurrence of one existing character into another existing character, and do the same with the other character.\n\t
        \n\t\t
      • For example, aacabb -> bbcbaa (all a's turn into b's, and all b's turn into a's)
      • \n\t
      \n\t
    • \n
    \n\n

    You can use the operations on either string as many times as necessary.

    \n\n

    Given two strings, word1 and word2, return true if word1 and word2 are close, and false otherwise.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: word1 = "abc", word2 = "bca"\nOutput: true\nExplanation: You can attain word2 from word1 in 2 operations.\nApply Operation 1: "abc" -> "acb"\nApply Operation 1: "acb" -> "bca"\n
    \n\n

    Example 2:

    \n\n
    \nInput: word1 = "a", word2 = "aa"\nOutput: false\nExplanation: It is impossible to attain word2 from word1, or vice versa, in any number of operations.\n
    \n\n

    Example 3:

    \n\n
    \nInput: word1 = "cabbba", word2 = "abbccc"\nOutput: true\nExplanation: You can attain word2 from word1 in 3 operations.\nApply Operation 1: "cabbba" -> "caabbb"\nApply Operation 2: "caabbb" -> "baaccc"\nApply Operation 2: "baaccc" -> "abbccc"\n
    \n\n

    Example 4:

    \n\n
    \nInput: word1 = "cabbba", word2 = "aabbss"\nOutput: false\nExplanation: It is impossible to attain word2 from word1, or vice versa, in any amount of operations.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= word1.length, word2.length <= 105
    • \n\t
    • word1 and word2 contain only lowercase English letters.
    • \n
    \n", "content_cn": "

    \u5982\u679c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u64cd\u4f5c\u4ece\u4e00\u4e2a\u5b57\u7b26\u4e32\u5f97\u5230\u53e6\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u5219\u8ba4\u4e3a\u4e24\u4e2a\u5b57\u7b26\u4e32 \u63a5\u8fd1 \uff1a

    \n\n
      \n\t
    • \u64cd\u4f5c 1\uff1a\u4ea4\u6362\u4efb\u610f\u4e24\u4e2a \u73b0\u6709 \u5b57\u7b26\u3002\n\n\t
        \n\t\t
      • \u4f8b\u5982\uff0cabcde -> aecdb
      • \n\t
      \n\t
    • \n\t
    • \u64cd\u4f5c 2\uff1a\u5c06\u4e00\u4e2a \u73b0\u6709 \u5b57\u7b26\u7684\u6bcf\u6b21\u51fa\u73b0\u8f6c\u6362\u4e3a\u53e6\u4e00\u4e2a \u73b0\u6709 \u5b57\u7b26\uff0c\u5e76\u5bf9\u53e6\u4e00\u4e2a\u5b57\u7b26\u6267\u884c\u76f8\u540c\u7684\u64cd\u4f5c\u3002\n\t
        \n\t\t
      • \u4f8b\u5982\uff0caacabb -> bbcbaa\uff08\u6240\u6709 a \u8f6c\u5316\u4e3a b \uff0c\u800c\u6240\u6709\u7684 b \u8f6c\u6362\u4e3a a \uff09
      • \n\t
      \n\t
    • \n
    \n\n

    \u4f60\u53ef\u4ee5\u6839\u636e\u9700\u8981\u5bf9\u4efb\u610f\u4e00\u4e2a\u5b57\u7b26\u4e32\u591a\u6b21\u4f7f\u7528\u8fd9\u4e24\u79cd\u64cd\u4f5c\u3002

    \n\n

    \u7ed9\u4f60\u4e24\u4e2a\u5b57\u7b26\u4e32\uff0cword1 \u548c word2 \u3002\u5982\u679c word1 \u548c word2 \u63a5\u8fd1 \uff0c\u5c31\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aword1 = \"abc\", word2 = \"bca\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a2 \u6b21\u64cd\u4f5c\u4ece word1 \u83b7\u5f97 word2 \u3002\n\u6267\u884c\u64cd\u4f5c 1\uff1a\"abc\" -> \"acb\"\n\u6267\u884c\u64cd\u4f5c 1\uff1a\"acb\" -> \"bca\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aword1 = \"a\", word2 = \"aa\"\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u4e0d\u7ba1\u6267\u884c\u591a\u5c11\u6b21\u64cd\u4f5c\uff0c\u90fd\u65e0\u6cd5\u4ece word1 \u5f97\u5230 word2 \uff0c\u53cd\u4e4b\u4ea6\u7136\u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aword1 = \"cabbba\", word2 = \"abbccc\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a3 \u6b21\u64cd\u4f5c\u4ece word1 \u83b7\u5f97 word2 \u3002\n\u6267\u884c\u64cd\u4f5c 1\uff1a\"cabbba\" -> \"caabbb\"\n\u6267\u884c\u64cd\u4f5c 2\uff1a\"caabbb\" -> \"baaccc\"\n\u6267\u884c\u64cd\u4f5c 2\uff1a\"baaccc\" -> \"abbccc\"\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1aword1 = \"cabbba\", word2 = \"aabbss\"\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u4e0d\u7ba1\u6267\u884c\u591a\u5c11\u6b21\u64cd\u4f5c\uff0c\u90fd\u65e0\u6cd5\u4ece word1 \u5f97\u5230 word2 \uff0c\u53cd\u4e4b\u4ea6\u7136\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= word1.length, word2.length <= 105
    • \n\t
    • word1 \u548c word2 \u4ec5\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool closeStrings(string word1, string word2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean closeStrings(String word1, String word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def closeStrings(self, word1, word2):\n \"\"\"\n :type word1: str\n :type word2: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def closeStrings(self, word1: str, word2: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool closeStrings(char * word1, char * word2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CloseStrings(string word1, string word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} word1\n * @param {string} word2\n * @return {boolean}\n */\nvar closeStrings = function(word1, word2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} word1\n# @param {String} word2\n# @return {Boolean}\ndef close_strings(word1, word2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func closeStrings(_ word1: String, _ word2: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func closeStrings(word1 string, word2 string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def closeStrings(word1: String, word2: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun closeStrings(word1: String, word2: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn close_strings(word1: String, word2: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $word1\n * @param String $word2\n * @return Boolean\n */\n function closeStrings($word1, $word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function closeStrings(word1: string, word2: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (close-strings word1 word2)\n (-> string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1657](https://leetcode-cn.com/problems/determine-if-two-strings-are-close)", "[\u786e\u5b9a\u4e24\u4e2a\u5b57\u7b26\u4e32\u662f\u5426\u63a5\u8fd1](/solution/1600-1699/1657.Determine%20if%20Two%20Strings%20Are%20Close/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1657](https://leetcode.com/problems/determine-if-two-strings-are-close)", "[Determine if Two Strings Are Close](/solution/1600-1699/1657.Determine%20if%20Two%20Strings%20Are%20Close/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1776", "frontend_question_id": "1658", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-operations-to-reduce-x-to-zero", "url_en": "https://leetcode.com/problems/minimum-operations-to-reduce-x-to-zero", "relative_path_cn": "/solution/1600-1699/1658.Minimum%20Operations%20to%20Reduce%20X%20to%20Zero/README.md", "relative_path_en": "/solution/1600-1699/1658.Minimum%20Operations%20to%20Reduce%20X%20to%20Zero/README_EN.md", "title_cn": "\u5c06 x \u51cf\u5230 0 \u7684\u6700\u5c0f\u64cd\u4f5c\u6570", "title_en": "Minimum Operations to Reduce X to Zero", "question_title_slug": "minimum-operations-to-reduce-x-to-zero", "content_en": "

    You are given an integer array nums and an integer x. In one operation, you can either remove the leftmost or the rightmost element from the array nums and subtract its value from x. Note that this modifies the array for future operations.

    \n\n

    Return the minimum number of operations to reduce x to exactly 0 if it is possible, otherwise, return -1.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,1,4,2,3], x = 5\nOutput: 2\nExplanation: The optimal solution is to remove the last two elements to reduce x to zero.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [5,6,7,8,9], x = 4\nOutput: -1\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [3,2,20,1,1,3], x = 10\nOutput: 5\nExplanation: The optimal solution is to remove the last three elements and the first two elements (5 operations in total) to reduce x to zero.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • 1 <= nums[i] <= 104
    • \n\t
    • 1 <= x <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \u548c\u4e00\u4e2a\u6574\u6570 x \u3002\u6bcf\u4e00\u6b21\u64cd\u4f5c\u65f6\uff0c\u4f60\u5e94\u5f53\u79fb\u9664\u6570\u7ec4 nums \u6700\u5de6\u8fb9\u6216\u6700\u53f3\u8fb9\u7684\u5143\u7d20\uff0c\u7136\u540e\u4ece x \u4e2d\u51cf\u53bb\u8be5\u5143\u7d20\u7684\u503c\u3002\u8bf7\u6ce8\u610f\uff0c\u9700\u8981 \u4fee\u6539 \u6570\u7ec4\u4ee5\u4f9b\u63a5\u4e0b\u6765\u7684\u64cd\u4f5c\u4f7f\u7528\u3002

    \n\n

    \u5982\u679c\u53ef\u4ee5\u5c06 x\u00a0\u6070\u597d \u51cf\u5230\u00a00 \uff0c\u8fd4\u56de \u6700\u5c0f\u64cd\u4f5c\u6570 \uff1b\u5426\u5219\uff0c\u8fd4\u56de -1 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,1,4,2,3], x = 5\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6700\u4f73\u89e3\u51b3\u65b9\u6848\u662f\u79fb\u9664\u540e\u4e24\u4e2a\u5143\u7d20\uff0c\u5c06 x \u51cf\u5230 0 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [5,6,7,8,9], x = 4\n\u8f93\u51fa\uff1a-1\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [3,2,20,1,1,3], x = 10\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u6700\u4f73\u89e3\u51b3\u65b9\u6848\u662f\u79fb\u9664\u540e\u4e09\u4e2a\u5143\u7d20\u548c\u524d\u4e24\u4e2a\u5143\u7d20\uff08\u603b\u5171 5 \u6b21\u64cd\u4f5c\uff09\uff0c\u5c06 x \u51cf\u5230 0 \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • 1 <= nums[i] <= 104
    • \n\t
    • 1 <= x <= 109
    • \n
    \n", "tags_en": ["Greedy", "Two Pointers", "Binary Search", "Sliding Window"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u53cc\u6307\u9488", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minOperations(vector& nums, int x) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minOperations(int[] nums, int x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minOperations(self, nums, x):\n \"\"\"\n :type nums: List[int]\n :type x: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minOperations(self, nums: List[int], x: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minOperations(int* nums, int numsSize, int x){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinOperations(int[] nums, int x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} x\n * @return {number}\n */\nvar minOperations = function(nums, x) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} x\n# @return {Integer}\ndef min_operations(nums, x)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minOperations(_ nums: [Int], _ x: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minOperations(nums []int, x int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minOperations(nums: Array[Int], x: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minOperations(nums: IntArray, x: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_operations(nums: Vec, x: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $x\n * @return Integer\n */\n function minOperations($nums, $x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minOperations(nums: number[], x: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-operations nums x)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1658](https://leetcode-cn.com/problems/minimum-operations-to-reduce-x-to-zero)", "[\u5c06 x \u51cf\u5230 0 \u7684\u6700\u5c0f\u64cd\u4f5c\u6570](/solution/1600-1699/1658.Minimum%20Operations%20to%20Reduce%20X%20to%20Zero/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u53cc\u6307\u9488`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1658](https://leetcode.com/problems/minimum-operations-to-reduce-x-to-zero)", "[Minimum Operations to Reduce X to Zero](/solution/1600-1699/1658.Minimum%20Operations%20to%20Reduce%20X%20to%20Zero/README_EN.md)", "`Greedy`,`Two Pointers`,`Binary Search`,`Sliding Window`", "Medium", ""]}, {"question_id": "1775", "frontend_question_id": "1656", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/design-an-ordered-stream", "url_en": "https://leetcode.com/problems/design-an-ordered-stream", "relative_path_cn": "/solution/1600-1699/1656.Design%20an%20Ordered%20Stream/README.md", "relative_path_en": "/solution/1600-1699/1656.Design%20an%20Ordered%20Stream/README_EN.md", "title_cn": "\u8bbe\u8ba1\u6709\u5e8f\u6d41", "title_en": "Design an Ordered Stream", "question_title_slug": "design-an-ordered-stream", "content_en": "

    There is a stream of n (idKey, value) pairs arriving in an arbitrary order, where idKey is an integer between 1 and n and value is a string. No two pairs have the same id.

    \n\n

    Design a stream that returns the values in increasing order of their IDs by returning a chunk (list) of values after each insertion. The concatenation of all the chunks should result in a list of the sorted values.

    \n\n

    Implement the OrderedStream class:

    \n\n
      \n\t
    • OrderedStream(int n) Constructs the stream to take n values.
    • \n\t
    • String[] insert(int idKey, String value) Inserts the pair (idKey, value) into the stream, then returns the largest possible chunk of currently inserted values that appear next in the order.
    • \n
    \n\n

     

    \n

    Example:

    \n\n

    \"\"

    \n\n
    \nInput\n["OrderedStream", "insert", "insert", "insert", "insert", "insert"]\n[[5], [3, "ccccc"], [1, "aaaaa"], [2, "bbbbb"], [5, "eeeee"], [4, "ddddd"]]\nOutput\n[null, [], ["aaaaa"], ["bbbbb", "ccccc"], [], ["ddddd", "eeeee"]]\n\nExplanation\n// Note that the values ordered by ID is ["aaaaa", "bbbbb", "ccccc", "ddddd", "eeeee"].\nOrderedStream os = new OrderedStream(5);\nos.insert(3, "ccccc"); // Inserts (3, "ccccc"), returns [].\nos.insert(1, "aaaaa"); // Inserts (1, "aaaaa"), returns ["aaaaa"].\nos.insert(2, "bbbbb"); // Inserts (2, "bbbbb"), returns ["bbbbb", "ccccc"].\nos.insert(5, "eeeee"); // Inserts (5, "eeeee"), returns [].\nos.insert(4, "ddddd"); // Inserts (4, "ddddd"), returns ["ddddd", "eeeee"].\n// Concatentating all the chunks returned:\n// [] + ["aaaaa"] + ["bbbbb", "ccccc"] + [] + ["ddddd", "eeeee"] = ["aaaaa", "bbbbb", "ccccc", "ddddd", "eeeee"]\n// The resulting order is the same as the order above.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 1000
    • \n\t
    • 1 <= id <= n
    • \n\t
    • value.length == 5
    • \n\t
    • value consists only of lowercase letters.
    • \n\t
    • Each call to insert will have a unique id.
    • \n\t
    • Exactly n calls will be made to insert.
    • \n
    \n", "content_cn": "

    \u6709 n \u4e2a (id, value) \u5bf9\uff0c\u5176\u4e2d id \u662f 1 \u5230 n \u4e4b\u95f4\u7684\u4e00\u4e2a\u6574\u6570\uff0cvalue \u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\u3002\u4e0d\u5b58\u5728 id \u76f8\u540c\u7684\u4e24\u4e2a\u00a0(id, value) \u5bf9\u3002

    \n\n

    \u8bbe\u8ba1\u4e00\u4e2a\u6d41\uff0c\u4ee5 \u4efb\u610f \u987a\u5e8f\u83b7\u53d6 n\u00a0\u4e2a\u00a0(id, value)\u00a0\u5bf9\uff0c\u5e76\u5728\u591a\u6b21\u8c03\u7528\u65f6 \u6309 id \u9012\u589e\u7684\u987a\u5e8f \u8fd4\u56de\u4e00\u4e9b\u503c\u3002

    \n\n

    \u5b9e\u73b0 OrderedStream \u7c7b\uff1a

    \n\n
      \n\t
    • OrderedStream(int n) \u6784\u9020\u4e00\u4e2a\u80fd\u63a5\u6536 n \u4e2a\u503c\u7684\u6d41\uff0c\u5e76\u5c06\u5f53\u524d\u6307\u9488 ptr \u8bbe\u4e3a 1 \u3002
    • \n\t
    • String[] insert(int id, String value) \u5411\u6d41\u4e2d\u5b58\u50a8\u65b0\u7684 (id, value) \u5bf9\u3002\u5b58\u50a8\u540e\uff1a\n\t
        \n\t\t
      • \u5982\u679c\u6d41\u5b58\u50a8\u6709 id = ptr \u7684 (id, value) \u5bf9\uff0c\u5219\u627e\u51fa\u4ece id = ptr \u5f00\u59cb\u7684 \u6700\u957f id \u8fde\u7eed\u9012\u589e\u5e8f\u5217 \uff0c\u5e76 \u6309\u987a\u5e8f \u8fd4\u56de\u4e0e\u8fd9\u4e9b id \u5173\u8054\u7684\u503c\u7684\u5217\u8868\u3002\u7136\u540e\uff0c\u5c06 ptr \u66f4\u65b0\u4e3a\u6700\u540e\u90a3\u4e2a\u00a0 id + 1\u00a0\u3002
      • \n\t\t
      • \n\t\t

        \u5426\u5219\uff0c\u8fd4\u56de\u4e00\u4e2a\u7a7a\u5217\u8868\u3002

        \n\t\t
      • \n\t
      \n\t
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\n[\"OrderedStream\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\"]\n[[5], [3, \"ccccc\"], [1, \"aaaaa\"], [2, \"bbbbb\"], [5, \"eeeee\"], [4, \"ddddd\"]]\n\u8f93\u51fa\n[null, [], [\"aaaaa\"], [\"bbbbb\", \"ccccc\"], [], [\"ddddd\", \"eeeee\"]]\n\n\u89e3\u91ca\nOrderedStream os= new OrderedStream(5);\nos.insert(3, \"ccccc\"); // \u63d2\u5165 (3, \"ccccc\")\uff0c\u8fd4\u56de []\nos.insert(1, \"aaaaa\"); // \u63d2\u5165 (1, \"aaaaa\")\uff0c\u8fd4\u56de [\"aaaaa\"]\nos.insert(2, \"bbbbb\"); // \u63d2\u5165 (2, \"bbbbb\")\uff0c\u8fd4\u56de [\"bbbbb\", \"ccccc\"]\nos.insert(5, \"eeeee\"); // \u63d2\u5165 (5, \"eeeee\")\uff0c\u8fd4\u56de []\nos.insert(4, \"ddddd\"); // \u63d2\u5165 (4, \"ddddd\")\uff0c\u8fd4\u56de [\"ddddd\", \"eeeee\"]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 1000
    • \n\t
    • 1 <= id <= n
    • \n\t
    • value.length == 5
    • \n\t
    • value \u4ec5\u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210
    • \n\t
    • \u6bcf\u6b21\u8c03\u7528 insert \u90fd\u4f1a\u4f7f\u7528\u4e00\u4e2a\u552f\u4e00\u7684 id
    • \n\t
    • \u6070\u597d\u8c03\u7528 n \u6b21 insert
    • \n
    \n", "tags_en": ["Design", "Array"], "tags_cn": ["\u8bbe\u8ba1", "\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class OrderedStream {\npublic:\n OrderedStream(int n) {\n\n }\n \n vector insert(int idKey, string value) {\n\n }\n};\n\n/**\n * Your OrderedStream object will be instantiated and called as such:\n * OrderedStream* obj = new OrderedStream(n);\n * vector param_1 = obj->insert(idKey,value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class OrderedStream {\n\n public OrderedStream(int n) {\n\n }\n \n public List insert(int idKey, String value) {\n\n }\n}\n\n/**\n * Your OrderedStream object will be instantiated and called as such:\n * OrderedStream obj = new OrderedStream(n);\n * List param_1 = obj.insert(idKey,value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class OrderedStream(object):\n\n def __init__(self, n):\n \"\"\"\n :type n: int\n \"\"\"\n\n\n def insert(self, idKey, value):\n \"\"\"\n :type idKey: int\n :type value: str\n :rtype: List[str]\n \"\"\"\n\n\n\n# Your OrderedStream object will be instantiated and called as such:\n# obj = OrderedStream(n)\n# param_1 = obj.insert(idKey,value)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class OrderedStream:\n\n def __init__(self, n: int):\n\n\n def insert(self, idKey: int, value: str) -> List[str]:\n\n\n\n# Your OrderedStream object will be instantiated and called as such:\n# obj = OrderedStream(n)\n# param_1 = obj.insert(idKey,value)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} OrderedStream;\n\n\nOrderedStream* orderedStreamCreate(int n) {\n \n}\n\nchar ** orderedStreamInsert(OrderedStream* obj, int idKey, char * value, int* retSize) {\n \n}\n\nvoid orderedStreamFree(OrderedStream* obj) {\n \n}\n\n/**\n * Your OrderedStream struct will be instantiated and called as such:\n * OrderedStream* obj = orderedStreamCreate(n);\n * char ** param_1 = orderedStreamInsert(obj, idKey, value, retSize);\n \n * orderedStreamFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class OrderedStream {\n\n public OrderedStream(int n) {\n\n }\n \n public IList Insert(int idKey, string value) {\n\n }\n}\n\n/**\n * Your OrderedStream object will be instantiated and called as such:\n * OrderedStream obj = new OrderedStream(n);\n * IList param_1 = obj.Insert(idKey,value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n */\nvar OrderedStream = function(n) {\n\n};\n\n/** \n * @param {number} idKey \n * @param {string} value\n * @return {string[]}\n */\nOrderedStream.prototype.insert = function(idKey, value) {\n\n};\n\n/**\n * Your OrderedStream object will be instantiated and called as such:\n * var obj = new OrderedStream(n)\n * var param_1 = obj.insert(idKey,value)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class OrderedStream\n\n=begin\n :type n: Integer\n=end\n def initialize(n)\n\n end\n\n\n=begin\n :type id_key: Integer\n :type value: String\n :rtype: String[]\n=end\n def insert(id_key, value)\n\n end\n\n\nend\n\n# Your OrderedStream object will be instantiated and called as such:\n# obj = OrderedStream.new(n)\n# param_1 = obj.insert(id_key, value)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass OrderedStream {\n\n init(_ n: Int) {\n\n }\n \n func insert(_ idKey: Int, _ value: String) -> [String] {\n\n }\n}\n\n/**\n * Your OrderedStream object will be instantiated and called as such:\n * let obj = OrderedStream(n)\n * let ret_1: [String] = obj.insert(idKey, value)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type OrderedStream struct {\n\n}\n\n\nfunc Constructor(n int) OrderedStream {\n\n}\n\n\nfunc (this *OrderedStream) Insert(idKey int, value string) []string {\n\n}\n\n\n/**\n * Your OrderedStream object will be instantiated and called as such:\n * obj := Constructor(n);\n * param_1 := obj.Insert(idKey,value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class OrderedStream(_n: Int) {\n\n def insert(idKey: Int, value: String): List[String] = {\n \n }\n\n}\n\n/**\n * Your OrderedStream object will be instantiated and called as such:\n * var obj = new OrderedStream(n)\n * var param_1 = obj.insert(idKey,value)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class OrderedStream(n: Int) {\n\n fun insert(idKey: Int, value: String): List {\n\n }\n\n}\n\n/**\n * Your OrderedStream object will be instantiated and called as such:\n * var obj = OrderedStream(n)\n * var param_1 = obj.insert(idKey,value)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct OrderedStream {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl OrderedStream {\n\n fn new(n: i32) -> Self {\n\n }\n \n fn insert(&self, id_key: i32, value: String) -> Vec {\n\n }\n}\n\n/**\n * Your OrderedStream object will be instantiated and called as such:\n * let obj = OrderedStream::new(n);\n * let ret_1: Vec = obj.insert(idKey, value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class OrderedStream {\n /**\n * @param Integer $n\n */\n function __construct($n) {\n\n }\n\n /**\n * @param Integer $idKey\n * @param String $value\n * @return String[]\n */\n function insert($idKey, $value) {\n\n }\n}\n\n/**\n * Your OrderedStream object will be instantiated and called as such:\n * $obj = OrderedStream($n);\n * $ret_1 = $obj->insert($idKey, $value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class OrderedStream {\n constructor(n: number) {\n\n }\n\n insert(idKey: number, value: string): string[] {\n\n }\n}\n\n/**\n * Your OrderedStream object will be instantiated and called as such:\n * var obj = new OrderedStream(n)\n * var param_1 = obj.insert(idKey,value)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define ordered-stream%\n (class object%\n (super-new)\n\n ; n : exact-integer?\n (init-field\n n)\n \n ; insert : exact-integer? string? -> (listof string?)\n (define/public (insert idKey value)\n\n )))\n\n;; Your ordered-stream% object will be instantiated and called as such:\n;; (define obj (new ordered-stream% [n n]))\n;; (define param_1 (send obj insert id-key value))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1656](https://leetcode-cn.com/problems/design-an-ordered-stream)", "[\u8bbe\u8ba1\u6709\u5e8f\u6d41](/solution/1600-1699/1656.Design%20an%20Ordered%20Stream/README.md)", "`\u8bbe\u8ba1`,`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1656](https://leetcode.com/problems/design-an-ordered-stream)", "[Design an Ordered Stream](/solution/1600-1699/1656.Design%20an%20Ordered%20Stream/README_EN.md)", "`Design`,`Array`", "Easy", ""]}, {"question_id": "1774", "frontend_question_id": "1634", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/add-two-polynomials-represented-as-linked-lists", "url_en": "https://leetcode.com/problems/add-two-polynomials-represented-as-linked-lists", "relative_path_cn": "/solution/1600-1699/1634.Add%20Two%20Polynomials%20Represented%20as%20Linked%20Lists/README.md", "relative_path_en": "/solution/1600-1699/1634.Add%20Two%20Polynomials%20Represented%20as%20Linked%20Lists/README_EN.md", "title_cn": "\u6c42\u4e24\u4e2a\u591a\u9879\u5f0f\u94fe\u8868\u7684\u548c", "title_en": "Add Two Polynomials Represented as Linked Lists", "question_title_slug": "add-two-polynomials-represented-as-linked-lists", "content_en": "

    A polynomial linked list is a special type of linked list where every node represents a term in a polynomial expression.

    \r\n\r\n

    Each node has three attributes:

    \r\n\r\n
      \r\n\t
    • coefficient: an integer representing the number multiplier of the term. The coefficient of the term 9x4 is 9.
    • \r\n\t
    • power: an integer representing the exponent. The power of the term 9x4 is 4.
    • \r\n\t
    • next: a pointer to the next node in the list, or null if it is the last node of the list.
    • \r\n
    \r\n\r\n

    For example, the polynomial 5x3 + 4x - 7 is represented by the polynomial linked list illustrated below:

    \r\n\r\n

    \"\"

    \r\n\r\n

    The polynomial linked list must be in its standard form: the polynomial must be in strictly descending order by its power value. Also, terms with a coefficient of 0 are omitted.

    \r\n\r\n

    Given two polynomial linked list heads, poly1 and poly2, add the polynomials together and return the head of the sum of the polynomials.

    \r\n\r\n

    PolyNode format:

    \r\n\r\n

    The input/output format is as a list of n nodes, where each node is represented as its [coefficient, power]. For example, the polynomial 5x3 + 4x - 7 would be represented as: [[5,3],[4,1],[-7,0]].

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n

    \"\"

    \r\n\r\n
    \r\nInput: poly1 = [[1,1]], poly2 = [[1,0]]\r\nOutput: [[1,1],[1,0]]\r\nExplanation: poly1 = x. poly2 = 1. The sum is x + 1.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: poly1 = [[2,2],[4,1],[3,0]], poly2 = [[3,2],[-4,1],[-1,0]]\r\nOutput: [[5,2],[2,0]]\r\nExplanation: poly1 = 2x2 + 4x + 3. poly2 = 3x2 - 4x - 1. The sum is 5x2 + 2. Notice that we omit the "0x" term.\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: poly1 = [[1,2]], poly2 = [[-1,2]]\r\nOutput: []\r\nExplanation: The sum is 0. We return an empty list.\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 0 <= n <= 104
    • \r\n\t
    • -109 <= PolyNode.coefficient <= 109
    • \r\n\t
    • PolyNode.coefficient != 0
    • \r\n\t
    • 0 <= PolyNode.power <= 109
    • \r\n\t
    • PolyNode.power > PolyNode.next.power
    • \r\n
    ", "content_cn": "

    \u591a\u9879\u5f0f\u94fe\u8868\u662f\u4e00\u79cd\u7279\u6b8a\u5f62\u5f0f\u7684\u94fe\u8868\uff0c\u6bcf\u4e2a\u8282\u70b9\u8868\u793a\u591a\u9879\u5f0f\u7684\u4e00\u9879\u3002

    \n\n

    \u6bcf\u4e2a\u8282\u70b9\u6709\u4e09\u4e2a\u5c5e\u6027\uff1a

    \n\n
      \n\t
    • coefficient\uff1a\u8be5\u9879\u7684\u7cfb\u6570\u3002\u9879\u00a09x4\u00a0\u7684\u7cfb\u6570\u662f\u00a09\u00a0\u3002
    • \n\t
    • power\uff1a\u8be5\u9879\u7684\u6307\u6570\u3002\u9879\u00a09x4\u00a0\u7684\u6307\u6570\u662f\u00a04\u00a0\u3002
    • \n\t
    • next\uff1a\u6307\u5411\u4e0b\u4e00\u4e2a\u8282\u70b9\u7684\u6307\u9488\uff08\u5f15\u7528\uff09\uff0c\u5982\u679c\u5f53\u524d\u8282\u70b9\u4e3a\u94fe\u8868\u7684\u6700\u540e\u4e00\u4e2a\u8282\u70b9\u5219\u4e3a\u00a0null \u3002
    • \n
    \n\n

    \u4f8b\u5982\uff0c\u591a\u9879\u5f0f\u00a05x3 + 4x - 7\u00a0\u53ef\u4ee5\u8868\u793a\u6210\u5982\u4e0b\u56fe\u6240\u793a\u7684\u591a\u9879\u5f0f\u94fe\u8868\uff1a

    \n\n

    \"\"

    \n\n

    \u591a\u9879\u5f0f\u94fe\u8868\u5fc5\u987b\u662f\u6807\u51c6\u5f62\u5f0f\u7684\uff0c\u5373\u591a\u9879\u5f0f\u5fc5\u987b \u4e25\u683c \u6309\u6307\u6570\u00a0power\u00a0\u7684\u9012\u51cf\u987a\u5e8f\u6392\u5217\uff08\u5373\u964d\u5e42\u6392\u5217\uff09\u3002\u53e6\u5916\uff0c\u7cfb\u6570\u00a0coefficient\u00a0\u4e3a\u00a00\u00a0\u7684\u9879\u9700\u8981\u7701\u7565\u3002

    \n\n

    \u7ed9\u5b9a\u4e24\u4e2a\u591a\u9879\u5f0f\u94fe\u8868\u7684\u5934\u8282\u70b9\u00a0poly1\u00a0\u548c\u00a0poly2\uff0c\u8fd4\u56de\u5b83\u4eec\u7684\u548c\u7684\u5934\u8282\u70b9\u3002

    \n\n

    PolyNode\u00a0\u683c\u5f0f\uff1a

    \n\n

    \u8f93\u5165/\u8f93\u51fa\u683c\u5f0f\u8868\u793a\u4e3a\u00a0n\u00a0\u4e2a\u8282\u70b9\u7684\u5217\u8868\uff0c\u5176\u4e2d\u6bcf\u4e2a\u8282\u70b9\u8868\u793a\u4e3a\u00a0[coefficient, power]\u00a0\u3002\u4f8b\u5982\uff0c\u591a\u9879\u5f0f\u00a05x3 + 4x - 7\u00a0\u8868\u793a\u4e3a\uff1a\u00a0[[5,3],[4,1],[-7,0]]\u00a0\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1apoly1 = [[1,1]], poly2 = [[1,0]]\n\u8f93\u51fa\uff1a[[1,1],[1,0]]\n\u89e3\u91ca\uff1apoly1 = x. poly2 = 1. \u548c\u4e3a x + 1.\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1apoly1 = [[2,2],[4,1],[3,0]], poly2 = [[3,2],[-4,1],[-1,0]]\n\u8f93\u51fa\uff1a[[5,2],[2,0]]\n\u89e3\u91ca\uff1apoly1 = 2x2 + 4x + 3. poly2 = 3x2 - 4x - 1. \u548c\u4e3a 5x2 + 2. \u6ce8\u610f\uff0c\u6211\u4eec\u7701\u7565 \"0x\" \u9879\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1apoly1 = [[1,2]], poly2 = [[-1,2]]\n\u8f93\u51fa\uff1a[]\n\u89e3\u91ca\uff1a\u548c\u4e3a 0\u3002\u6211\u4eec\u8fd4\u56de\u7a7a\u94fe\u8868\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= n <= 104
    • \n\t
    • -109\u00a0<= PolyNode.coefficient <= 109
    • \n\t
    • PolyNode.coefficient != 0
    • \n\t
    • 0\u00a0<= PolyNode.power <= 109
    • \n\t
    • PolyNode.power > PolyNode.next.power
    • \n
    \n", "tags_en": ["Linked List"], "tags_cn": ["\u94fe\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for polynomial singly-linked list.\n * struct PolyNode {\n * int coefficient, power;\n * PolyNode *next;\n * PolyNode(): coefficient(0), power(0), next(nullptr) {};\n * PolyNode(int x, int y): coefficient(x), power(y), next(nullptr) {};\n * PolyNode(int x, int y, PolyNode* next): coefficient(x), power(y), next(next) {};\n * };\n */\n\nclass Solution {\npublic:\n PolyNode* addPoly(PolyNode* poly1, PolyNode* poly2) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for polynomial singly-linked list.\n * class PolyNode {\n * int coefficient, power;\n * PolyNode next = null;\n \n * PolyNode() {}\n * PolyNode(int x, int y) { this.coefficient = x; this.power = y; }\n * PolyNode(int x, int y, PolyNode next) { this.coefficient = x; this.power = y; this.next = next; }\n * }\n */\n\nclass Solution {\n public PolyNode addPoly(PolyNode poly1, PolyNode poly2) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for polynomial singly-linked list.\n# class PolyNode:\n# def __init__(self, x=0, y=0, next=None):\n# self.coefficient = x\n# self.power = y\n# self.next = next\n\nclass Solution:\n def addPoly(self, poly1, poly2):\n \"\"\"\n :type poly1: PolyNode\n :type poly2: PolyNode\n :rtype: PolyNode\n \"\"\"\n \n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for polynomial singly-linked list.\n# class PolyNode:\n# def __init__(self, x=0, y=0, next=None):\n# self.coefficient = x\n# self.power = y\n# self.next = next\n\nclass Solution:\n def addPoly(self, poly1: 'PolyNode', poly2: 'PolyNode') -> 'PolyNode':\n \n ", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for polynomial singly-linked list.\n * public class PolyNode {\n * public int coefficient, power;\n * public PolyNode next;\n *\n * public PolyNode(int x=0, int y=0, PolyNode next=null) {\n * this.coefficient = x;\n * this.power = y;\n * this.next = next;\n * }\n * }\n */\n\npublic class Solution {\n public PolyNode AddPoly(PolyNode poly1, PolyNode poly2) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for polynomial singly-linked list.\n * function PolyNode(x=0, y=0, next=null) {\n * this.coefficient = x;\n * this.power = y;\n * this.next = next;\n * }\n */\n\n/**\n * @param {PolyNode} poly1\n * @param {PolyNode} poly2\n * @return {PolyNode}\n */\nvar addPoly = function(poly1, poly2) {\n \n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1634](https://leetcode-cn.com/problems/add-two-polynomials-represented-as-linked-lists)", "[\u6c42\u4e24\u4e2a\u591a\u9879\u5f0f\u94fe\u8868\u7684\u548c](/solution/1600-1699/1634.Add%20Two%20Polynomials%20Represented%20as%20Linked%20Lists/README.md)", "`\u94fe\u8868`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1634](https://leetcode.com/problems/add-two-polynomials-represented-as-linked-lists)", "[Add Two Polynomials Represented as Linked Lists](/solution/1600-1699/1634.Add%20Two%20Polynomials%20Represented%20as%20Linked%20Lists/README_EN.md)", "`Linked List`", "Medium", "\ud83d\udd12"]}, {"question_id": "1773", "frontend_question_id": "1633", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/percentage-of-users-attended-a-contest", "url_en": "https://leetcode.com/problems/percentage-of-users-attended-a-contest", "relative_path_cn": "/solution/1600-1699/1633.Percentage%20of%20Users%20Attended%20a%20Contest/README.md", "relative_path_en": "/solution/1600-1699/1633.Percentage%20of%20Users%20Attended%20a%20Contest/README_EN.md", "title_cn": "\u5404\u8d5b\u4e8b\u7684\u7528\u6237\u6ce8\u518c\u7387", "title_en": "Percentage of Users Attended a Contest", "question_title_slug": "percentage-of-users-attended-a-contest", "content_en": "

    Table: Users

    \n\n
    \n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| user_id     | int     |\n| user_name   | varchar |\n+-------------+---------+\nuser_id is the primary key for this table.\nEach row of this table contains the name and the id of a user.\n
    \n\n

     

    \n\n

    Table: Register

    \n\n
    \n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| contest_id  | int     |\n| user_id     | int     |\n+-------------+---------+\n(contest_id, user_id) is the primary key for this table.\nEach row of this table contains the id of a user and the contest they registered into.\n
    \n\n

     

    \n\n

    Write an SQL query to find the percentage of the users registered in each contest rounded to two decimals.

    \n\n

    Return the result table ordered by percentage in descending order. In case of a tie, order it by contest_id in ascending order.

    \n\n

    The query result format is in the following example.

    \n\n

     

    \n\n
    \nUsers table:\n+---------+-----------+\n| user_id | user_name |\n+---------+-----------+\n| 6       | Alice     |\n| 2       | Bob       |\n| 7       | Alex      |\n+---------+-----------+\n\nRegister table:\n+------------+---------+\n| contest_id | user_id |\n+------------+---------+\n| 215        | 6       |\n| 209        | 2       |\n| 208        | 2       |\n| 210        | 6       |\n| 208        | 6       |\n| 209        | 7       |\n| 209        | 6       |\n| 215        | 7       |\n| 208        | 7       |\n| 210        | 2       |\n| 207        | 2       |\n| 210        | 7       |\n+------------+---------+\n\nResult table:\n+------------+------------+\n| contest_id | percentage |\n+------------+------------+\n| 208        | 100.0      |\n| 209        | 100.0      |\n| 210        | 100.0      |\n| 215        | 66.67      |\n| 207        | 33.33      |\n+------------+------------+\nAll the users registered in contests 208, 209, and 210. The percentage is 100% and we sort them in the answer table by contest_id in ascending order.\nAlice and Alex registered in contest 215 and the percentage is ((2/3) * 100) = 66.67%\nBob registered in contest 207 and the percentage is ((1/3) * 100) = 33.33%\n
    \n", "content_cn": "

    \u7528\u6237\u8868\uff1a\u00a0Users

    \n\n
    +-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| user_id     | int     |\n| user_name   | varchar |\n+-------------+---------+\nuser_id \u662f\u8be5\u8868\u7684\u4e3b\u952e\u3002\n\u8be5\u8868\u4e2d\u7684\u6bcf\u884c\u5305\u62ec\u7528\u6237 ID \u548c\u7528\u6237\u540d\u3002
    \n\n

    \u00a0

    \n\n

    \u6ce8\u518c\u8868\uff1a\u00a0Register

    \n\n
    +-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| contest_id  | int     |\n| user_id     | int     |\n+-------------+---------+\n(contest_id, user_id) \u662f\u8be5\u8868\u7684\u4e3b\u952e\u3002\n\u8be5\u8868\u4e2d\u7684\u6bcf\u884c\u5305\u542b\u7528\u6237\u7684 ID \u548c\u4ed6\u4eec\u6ce8\u518c\u7684\u8d5b\u4e8b\u3002
    \n\n

    \u00a0

    \n\n

    \u5199\u4e00\u6761 SQL \u8bed\u53e5\uff0c\u67e5\u8be2\u5404\u8d5b\u4e8b\u7684\u7528\u6237\u6ce8\u518c\u767e\u5206\u7387\uff0c\u4fdd\u7559\u4e24\u4f4d\u5c0f\u6570\u3002

    \n\n

    \u8fd4\u56de\u7684\u7ed3\u679c\u8868\u6309\u00a0percentage\u00a0\u7684\u964d\u5e8f\u6392\u5e8f\uff0c\u82e5\u76f8\u540c\u5219\u6309\u00a0contest_id\u00a0\u7684\u5347\u5e8f\u6392\u5e8f\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u5982\u4e0b\u793a\u4f8b\u6240\u793a\uff1a

    \n\n

    \u00a0

    \n\n
    Users \u8868\uff1a\n+---------+-----------+\n| user_id | user_name |\n+---------+-----------+\n| 6       | Alice     |\n| 2       | Bob       |\n| 7       | Alex      |\n+---------+-----------+\n\nRegister \u8868\uff1a\n+------------+---------+\n| contest_id | user_id |\n+------------+---------+\n| 215        | 6       |\n| 209        | 2       |\n| 208        | 2       |\n| 210        | 6       |\n| 208        | 6       |\n| 209        | 7       |\n| 209        | 6       |\n| 215        | 7       |\n| 208        | 7       |\n| 210        | 2       |\n| 207        | 2       |\n| 210        | 7       |\n+------------+---------+\n\n\u7ed3\u679c\u8868\uff1a\n+------------+------------+\n| contest_id | percentage |\n+------------+------------+\n| 208        | 100.0      |\n| 209        | 100.0      |\n| 210        | 100.0      |\n| 215        | 66.67      |\n| 207        | 33.33      |\n+------------+------------+\n\u6240\u6709\u7528\u6237\u90fd\u6ce8\u518c\u4e86 208\u3001209 \u548c 210 \u8d5b\u4e8b\uff0c\u56e0\u6b64\u8fd9\u4e9b\u8d5b\u4e8b\u7684\u6ce8\u518c\u7387\u4e3a 100% \uff0c\u6211\u4eec\u6309 contest_id \u7684\u964d\u5e8f\u6392\u5e8f\u52a0\u5165\u7ed3\u679c\u8868\u4e2d\u3002\nAlice \u548c Alex \u6ce8\u518c\u4e86 215 \u8d5b\u4e8b\uff0c\u6ce8\u518c\u7387\u4e3a ((2/3) * 100) = 66.67%\nBob \u6ce8\u518c\u4e86 207 \u8d5b\u4e8b\uff0c\u6ce8\u518c\u7387\u4e3a ((1/3) * 100) = 33.33%\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1633](https://leetcode-cn.com/problems/percentage-of-users-attended-a-contest)", "[\u5404\u8d5b\u4e8b\u7684\u7528\u6237\u6ce8\u518c\u7387](/solution/1600-1699/1633.Percentage%20of%20Users%20Attended%20a%20Contest/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1633](https://leetcode.com/problems/percentage-of-users-attended-a-contest)", "[Percentage of Users Attended a Contest](/solution/1600-1699/1633.Percentage%20of%20Users%20Attended%20a%20Contest/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1772", "frontend_question_id": "1649", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/create-sorted-array-through-instructions", "url_en": "https://leetcode.com/problems/create-sorted-array-through-instructions", "relative_path_cn": "/solution/1600-1699/1649.Create%20Sorted%20Array%20through%20Instructions/README.md", "relative_path_en": "/solution/1600-1699/1649.Create%20Sorted%20Array%20through%20Instructions/README_EN.md", "title_cn": "\u901a\u8fc7\u6307\u4ee4\u521b\u5efa\u6709\u5e8f\u6570\u7ec4", "title_en": "Create Sorted Array through Instructions", "question_title_slug": "create-sorted-array-through-instructions", "content_en": "

    Given an integer array instructions, you are asked to create a sorted array from the elements in instructions. You start with an empty container nums. For each element from left to right in instructions, insert it into nums. The cost of each insertion is the minimum of the following:

    \r\n\r\n
      \r\n\t
    • The number of elements currently in nums that are strictly less than instructions[i].
    • \r\n\t
    • The number of elements currently in nums that are strictly greater than instructions[i].
    • \r\n
    \r\n\r\n

    For example, if inserting element 3 into nums = [1,2,3,5], the cost of insertion is min(2, 1) (elements 1 and 2 are less than 3, element 5 is greater than 3) and nums will become [1,2,3,3,5].

    \r\n\r\n

    Return the total cost to insert all elements from instructions into nums. Since the answer may be large, return it modulo 109 + 7

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: instructions = [1,5,6,2]\r\nOutput: 1\r\nExplanation: Begin with nums = [].\r\nInsert 1 with cost min(0, 0) = 0, now nums = [1].\r\nInsert 5 with cost min(1, 0) = 0, now nums = [1,5].\r\nInsert 6 with cost min(2, 0) = 0, now nums = [1,5,6].\r\nInsert 2 with cost min(1, 2) = 1, now nums = [1,2,5,6].\r\nThe total cost is 0 + 0 + 0 + 1 = 1.
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: instructions = [1,2,3,6,5,4]\r\nOutput: 3\r\nExplanation: Begin with nums = [].\r\nInsert 1 with cost min(0, 0) = 0, now nums = [1].\r\nInsert 2 with cost min(1, 0) = 0, now nums = [1,2].\r\nInsert 3 with cost min(2, 0) = 0, now nums = [1,2,3].\r\nInsert 6 with cost min(3, 0) = 0, now nums = [1,2,3,6].\r\nInsert 5 with cost min(3, 1) = 1, now nums = [1,2,3,5,6].\r\nInsert 4 with cost min(3, 2) = 2, now nums = [1,2,3,4,5,6].\r\nThe total cost is 0 + 0 + 0 + 0 + 1 + 2 = 3.\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: instructions = [1,3,3,3,2,4,2,1,2]\r\nOutput: 4\r\nExplanation: Begin with nums = [].\r\nInsert 1 with cost min(0, 0) = 0, now nums = [1].\r\nInsert 3 with cost min(1, 0) = 0, now nums = [1,3].\r\nInsert 3 with cost min(1, 0) = 0, now nums = [1,3,3].\r\nInsert 3 with cost min(1, 0) = 0, now nums = [1,3,3,3].\r\nInsert 2 with cost min(1, 3) = 1, now nums = [1,2,3,3,3].\r\nInsert 4 with cost min(5, 0) = 0, now nums = [1,2,3,3,3,4].\r\n\u200b\u200b\u200b\u200b\u200b\u200b\u200bInsert 2 with cost min(1, 4) = 1, now nums = [1,2,2,3,3,3,4].\r\n\u200b\u200b\u200b\u200b\u200b\u200b\u200bInsert 1 with cost min(0, 6) = 0, now nums = [1,1,2,2,3,3,3,4].\r\n\u200b\u200b\u200b\u200b\u200b\u200b\u200bInsert 2 with cost min(2, 4) = 2, now nums = [1,1,2,2,2,3,3,3,4].\r\nThe total cost is 0 + 0 + 0 + 0 + 1 + 0 + 1 + 0 + 2 = 4.\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= instructions.length <= 105
    • \r\n\t
    • 1 <= instructions[i] <= 105
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0instructions\u00a0\uff0c\u4f60\u9700\u8981\u6839\u636e\u00a0instructions\u00a0\u4e2d\u7684\u5143\u7d20\u521b\u5efa\u4e00\u4e2a\u6709\u5e8f\u6570\u7ec4\u3002\u4e00\u5f00\u59cb\u4f60\u6709\u4e00\u4e2a\u7a7a\u7684\u6570\u7ec4\u00a0nums\u00a0\uff0c\u4f60\u9700\u8981\u00a0\u4ece\u5de6\u5230\u53f3\u00a0\u904d\u5386\u00a0instructions\u00a0\u4e2d\u7684\u5143\u7d20\uff0c\u5c06\u5b83\u4eec\u4f9d\u6b21\u63d2\u5165\u00a0nums\u00a0\u6570\u7ec4\u4e2d\u3002\u6bcf\u4e00\u6b21\u63d2\u5165\u64cd\u4f5c\u7684\u00a0\u4ee3\u4ef7\u00a0\u662f\u4ee5\u4e0b\u4e24\u8005\u7684 \u8f83\u5c0f\u503c\u00a0\uff1a

    \n\n
      \n\t
    • nums\u00a0\u4e2d \u4e25\u683c\u5c0f\u4e8e\u00a0\u00a0instructions[i]\u00a0\u7684\u6570\u5b57\u6570\u76ee\u3002
    • \n\t
    • nums\u00a0\u4e2d \u4e25\u683c\u5927\u4e8e\u00a0\u00a0instructions[i]\u00a0\u7684\u6570\u5b57\u6570\u76ee\u3002
    • \n
    \n\n

    \u6bd4\u65b9\u8bf4\uff0c\u5982\u679c\u8981\u5c06\u00a03 \u63d2\u5165\u5230\u00a0nums = [1,2,3,5]\u00a0\uff0c\u90a3\u4e48\u63d2\u5165\u64cd\u4f5c\u7684\u00a0\u4ee3\u4ef7\u00a0\u4e3a\u00a0min(2, 1) (\u5143\u7d20\u00a01\u00a0\u548c\u00a0\u00a02\u00a0\u5c0f\u4e8e\u00a03\u00a0\uff0c\u5143\u7d20\u00a05\u00a0\u5927\u4e8e\u00a03\u00a0\uff09\uff0c\u63d2\u5165\u540e\u00a0nums \u53d8\u6210\u00a0[1,2,3,3,5]\u00a0\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u5c06\u00a0instructions\u00a0\u4e2d\u6240\u6709\u5143\u7d20\u4f9d\u6b21\u63d2\u5165\u00a0nums\u00a0\u540e\u7684 \u603b\u6700\u5c0f\u4ee3\u4ef7\u00a0\u3002\u7531\u4e8e\u7b54\u6848\u4f1a\u5f88\u5927\uff0c\u8bf7\u5c06\u5b83\u5bf9\u00a0109 + 7\u00a0\u53d6\u4f59\u00a0\u540e\u8fd4\u56de\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1ainstructions = [1,5,6,2]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u4e00\u5f00\u59cb nums = [] \u3002\n\u63d2\u5165 1 \uff0c\u4ee3\u4ef7\u4e3a min(0, 0) = 0 \uff0c\u73b0\u5728 nums = [1] \u3002\n\u63d2\u5165 5 \uff0c\u4ee3\u4ef7\u4e3a min(1, 0) = 0 \uff0c\u73b0\u5728 nums = [1,5] \u3002\n\u63d2\u5165 6 \uff0c\u4ee3\u4ef7\u4e3a min(2, 0) = 0 \uff0c\u73b0\u5728 nums = [1,5,6] \u3002\n\u63d2\u5165 2 \uff0c\u4ee3\u4ef7\u4e3a min(1, 2) = 1 \uff0c\u73b0\u5728 nums = [1,2,5,6] \u3002\n\u603b\u4ee3\u4ef7\u4e3a 0 + 0 + 0 + 1 = 1 \u3002
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165\uff1ainstructions = [1,2,3,6,5,4]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u4e00\u5f00\u59cb nums = [] \u3002\n\u63d2\u5165 1 \uff0c\u4ee3\u4ef7\u4e3a min(0, 0) = 0 \uff0c\u73b0\u5728 nums = [1] \u3002\n\u63d2\u5165 2 \uff0c\u4ee3\u4ef7\u4e3a min(1, 0) = 0 \uff0c\u73b0\u5728 nums = [1,2] \u3002\n\u63d2\u5165 3 \uff0c\u4ee3\u4ef7\u4e3a min(2, 0) = 0 \uff0c\u73b0\u5728 nums = [1,2,3] \u3002\n\u63d2\u5165 6 \uff0c\u4ee3\u4ef7\u4e3a min(3, 0) = 0 \uff0c\u73b0\u5728 nums = [1,2,3,6] \u3002\n\u63d2\u5165 5 \uff0c\u4ee3\u4ef7\u4e3a min(3, 1) = 1 \uff0c\u73b0\u5728 nums = [1,2,3,5,6] \u3002\n\u63d2\u5165 4 \uff0c\u4ee3\u4ef7\u4e3a min(3, 2) = 2 \uff0c\u73b0\u5728 nums = [1,2,3,4,5,6] \u3002\n\u603b\u4ee3\u4ef7\u4e3a 0 + 0 + 0 + 0 + 1 + 2 = 3 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1ainstructions = [1,3,3,3,2,4,2,1,2]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u4e00\u5f00\u59cb nums = [] \u3002\n\u63d2\u5165 1 \uff0c\u4ee3\u4ef7\u4e3a min(0, 0) = 0 \uff0c\u73b0\u5728 nums = [1] \u3002\n\u63d2\u5165 3 \uff0c\u4ee3\u4ef7\u4e3a min(1, 0) = 0 \uff0c\u73b0\u5728 nums = [1,3] \u3002\n\u63d2\u5165 3 \uff0c\u4ee3\u4ef7\u4e3a min(1, 0) = 0 \uff0c\u73b0\u5728 nums = [1,3,3] \u3002\n\u63d2\u5165 3 \uff0c\u4ee3\u4ef7\u4e3a min(1, 0) = 0 \uff0c\u73b0\u5728 nums = [1,3,3,3] \u3002\n\u63d2\u5165 2 \uff0c\u4ee3\u4ef7\u4e3a min(1, 3) = 1 \uff0c\u73b0\u5728 nums = [1,2,3,3,3] \u3002\n\u63d2\u5165 4 \uff0c\u4ee3\u4ef7\u4e3a min(5, 0) = 0 \uff0c\u73b0\u5728 nums = [1,2,3,3,3,4] \u3002\n\u200b\u200b\u200b\u200b\u200b\u63d2\u5165 2 \uff0c\u4ee3\u4ef7\u4e3a min(1, 4) = 1 \uff0c\u73b0\u5728 nums = [1,2,2,3,3,3,4] \u3002\n\u63d2\u5165 1 \uff0c\u4ee3\u4ef7\u4e3a min(0, 6) = 0 \uff0c\u73b0\u5728 nums = [1,1,2,2,3,3,3,4] \u3002\n\u63d2\u5165 2 \uff0c\u4ee3\u4ef7\u4e3a min(2, 4) = 2 \uff0c\u73b0\u5728 nums = [1,1,2,2,2,3,3,3,4] \u3002\n\u603b\u4ee3\u4ef7\u4e3a 0 + 0 + 0 + 0 + 1 + 0 + 1 + 0 + 2 = 4 \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= instructions.length <= 105
    • \n\t
    • 1 <= instructions[i] <= 105
    • \n
    \n", "tags_en": ["Binary Indexed Tree", "Segment Tree", "Binary Search", "Ordered Map"], "tags_cn": ["\u6811\u72b6\u6570\u7ec4", "\u7ebf\u6bb5\u6811", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int createSortedArray(vector& instructions) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int createSortedArray(int[] instructions) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def createSortedArray(self, instructions):\n \"\"\"\n :type instructions: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def createSortedArray(self, instructions: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint createSortedArray(int* instructions, int instructionsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CreateSortedArray(int[] instructions) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} instructions\n * @return {number}\n */\nvar createSortedArray = function(instructions) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} instructions\n# @return {Integer}\ndef create_sorted_array(instructions)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func createSortedArray(_ instructions: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func createSortedArray(instructions []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def createSortedArray(instructions: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun createSortedArray(instructions: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn create_sorted_array(instructions: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $instructions\n * @return Integer\n */\n function createSortedArray($instructions) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function createSortedArray(instructions: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (create-sorted-array instructions)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1649](https://leetcode-cn.com/problems/create-sorted-array-through-instructions)", "[\u901a\u8fc7\u6307\u4ee4\u521b\u5efa\u6709\u5e8f\u6570\u7ec4](/solution/1600-1699/1649.Create%20Sorted%20Array%20through%20Instructions/README.md)", "`\u6811\u72b6\u6570\u7ec4`,`\u7ebf\u6bb5\u6811`,`\u4e8c\u5206\u67e5\u627e`", "\u56f0\u96be", ""], "md_table_row_en": ["[1649](https://leetcode.com/problems/create-sorted-array-through-instructions)", "[Create Sorted Array through Instructions](/solution/1600-1699/1649.Create%20Sorted%20Array%20through%20Instructions/README_EN.md)", "`Binary Indexed Tree`,`Segment Tree`,`Binary Search`,`Ordered Map`", "Hard", ""]}, {"question_id": "1771", "frontend_question_id": "1648", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sell-diminishing-valued-colored-balls", "url_en": "https://leetcode.com/problems/sell-diminishing-valued-colored-balls", "relative_path_cn": "/solution/1600-1699/1648.Sell%20Diminishing-Valued%20Colored%20Balls/README.md", "relative_path_en": "/solution/1600-1699/1648.Sell%20Diminishing-Valued%20Colored%20Balls/README_EN.md", "title_cn": "\u9500\u552e\u4ef7\u503c\u51cf\u5c11\u7684\u989c\u8272\u7403", "title_en": "Sell Diminishing-Valued Colored Balls", "question_title_slug": "sell-diminishing-valued-colored-balls", "content_en": "

    You have an inventory of different colored balls, and there is a customer that wants orders balls of any color.

    \n\n

    The customer weirdly values the colored balls. Each colored ball's value is the number of balls of that color you currently have in your inventory. For example, if you own 6 yellow balls, the customer would pay 6 for the first yellow ball. After the transaction, there are only 5 yellow balls left, so the next yellow ball is then valued at 5 (i.e., the value of the balls decreases as you sell more to the customer).

    \n\n

    You are given an integer array, inventory, where inventory[i] represents the number of balls of the ith color that you initially own. You are also given an integer orders, which represents the total number of balls that the customer wants. You can sell the balls in any order.

    \n\n

    Return the maximum total value that you can attain after selling orders colored balls. As the answer may be too large, return it modulo 109 + 7.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: inventory = [2,5], orders = 4\nOutput: 14\nExplanation: Sell the 1st color 1 time (2) and the 2nd color 3 times (5 + 4 + 3).\nThe maximum total value is 2 + 5 + 4 + 3 = 14.\n
    \n\n

    Example 2:

    \n\n
    \nInput: inventory = [3,5], orders = 6\nOutput: 19\nExplanation: Sell the 1st color 2 times (3 + 2) and the 2nd color 4 times (5 + 4 + 3 + 2).\nThe maximum total value is 3 + 2 + 5 + 4 + 3 + 2 = 19.\n
    \n\n

    Example 3:

    \n\n
    \nInput: inventory = [2,8,4,10,6], orders = 20\nOutput: 110\n
    \n\n

    Example 4:

    \n\n
    \nInput: inventory = [1000000000], orders = 1000000000\nOutput: 21\nExplanation: Sell the 1st color 1000000000 times for a total value of 500000000500000000. 500000000500000000 modulo 109 + 7 = 21.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= inventory.length <= 105
    • \n\t
    • 1 <= inventory[i] <= 109
    • \n\t
    • 1 <= orders <= min(sum(inventory[i]), 109)
    • \n
    \n", "content_cn": "

    \u4f60\u6709\u4e00\u4e9b\u7403\u7684\u5e93\u5b58\u00a0inventory\u00a0\uff0c\u91cc\u9762\u5305\u542b\u7740\u4e0d\u540c\u989c\u8272\u7684\u7403\u3002\u4e00\u4e2a\u987e\u5ba2\u60f3\u8981\u00a0\u4efb\u610f\u989c\u8272 \u603b\u6570\u4e3a\u00a0orders\u00a0\u7684\u7403\u3002

    \n\n

    \u8fd9\u4f4d\u987e\u5ba2\u6709\u4e00\u79cd\u7279\u6b8a\u7684\u65b9\u5f0f\u8861\u91cf\u7403\u7684\u4ef7\u503c\uff1a\u6bcf\u4e2a\u7403\u7684\u4ef7\u503c\u662f\u76ee\u524d\u5269\u4e0b\u7684\u00a0\u540c\u8272\u7403\u00a0\u7684\u6570\u76ee\u3002\u6bd4\u65b9\u8bf4\u8fd8\u5269\u4e0b\u00a06\u00a0\u4e2a\u9ec4\u7403\uff0c\u90a3\u4e48\u987e\u5ba2\u4e70\u7b2c\u4e00\u4e2a\u9ec4\u7403\u7684\u65f6\u5019\u8be5\u9ec4\u7403\u7684\u4ef7\u503c\u4e3a\u00a06\u00a0\u3002\u8fd9\u7b14\u4ea4\u6613\u4ee5\u540e\uff0c\u53ea\u5269\u4e0b\u00a05\u00a0\u4e2a\u9ec4\u7403\u4e86\uff0c\u6240\u4ee5\u4e0b\u4e00\u4e2a\u9ec4\u7403\u7684\u4ef7\u503c\u4e3a\u00a05\u00a0\uff08\u4e5f\u5c31\u662f\u7403\u7684\u4ef7\u503c\u968f\u7740\u987e\u5ba2\u8d2d\u4e70\u540c\u8272\u7403\u662f\u9012\u51cf\u7684\uff09

    \n\n

    \u7ed9\u4f60\u6574\u6570\u6570\u7ec4\u00a0inventory\u00a0\uff0c\u5176\u4e2d\u00a0inventory[i]\u00a0\u8868\u793a\u7b2c\u00a0i\u00a0\u79cd\u989c\u8272\u7403\u4e00\u5f00\u59cb\u7684\u6570\u76ee\u3002\u540c\u65f6\u7ed9\u4f60\u6574\u6570\u00a0orders\u00a0\uff0c\u8868\u793a\u987e\u5ba2\u603b\u5171\u60f3\u4e70\u7684\u7403\u6570\u76ee\u3002\u4f60\u53ef\u4ee5\u6309\u7167 \u4efb\u610f\u987a\u5e8f\u00a0\u5356\u7403\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u5356\u4e86 orders\u00a0\u4e2a\u7403\u4ee5\u540e \u6700\u5927\u00a0\u603b\u4ef7\u503c\u4e4b\u548c\u3002\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u4f1a\u5f88\u5927\uff0c\u8bf7\u4f60\u8fd4\u56de\u7b54\u6848\u5bf9 109\u00a0+ 7\u00a0\u53d6\u4f59\u6570\u00a0\u7684\u7ed3\u679c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1ainventory = [2,5], orders = 4\n\u8f93\u51fa\uff1a14\n\u89e3\u91ca\uff1a\u5356 1 \u4e2a\u7b2c\u4e00\u79cd\u989c\u8272\u7684\u7403\uff08\u4ef7\u503c\u4e3a 2 )\uff0c\u5356 3 \u4e2a\u7b2c\u4e8c\u79cd\u989c\u8272\u7684\u7403\uff08\u4ef7\u503c\u4e3a 5 + 4 + 3\uff09\u3002\n\u6700\u5927\u603b\u548c\u4e3a 2 + 5 + 4 + 3 = 14 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1ainventory = [3,5], orders = 6\n\u8f93\u51fa\uff1a19\n\u89e3\u91ca\uff1a\u5356 2 \u4e2a\u7b2c\u4e00\u79cd\u989c\u8272\u7684\u7403\uff08\u4ef7\u503c\u4e3a 3 + 2\uff09\uff0c\u5356 4 \u4e2a\u7b2c\u4e8c\u79cd\u989c\u8272\u7684\u7403\uff08\u4ef7\u503c\u4e3a 5 + 4 + 3 + 2\uff09\u3002\n\u6700\u5927\u603b\u548c\u4e3a 3 + 2 + 5 + 4 + 3 + 2 = 19 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1ainventory = [2,8,4,10,6], orders = 20\n\u8f93\u51fa\uff1a110\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1ainventory = [1000000000], orders = 1000000000\n\u8f93\u51fa\uff1a21\n\u89e3\u91ca\uff1a\u5356 1000000000 \u6b21\u7b2c\u4e00\u79cd\u989c\u8272\u7684\u7403\uff0c\u603b\u4ef7\u503c\u4e3a 500000000500000000 \u3002 500000000500000000 \u5bf9 109 + 7 \u53d6\u4f59\u4e3a 21 \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= inventory.length <= 105
    • \n\t
    • 1 <= inventory[i] <= 109
    • \n\t
    • 1 <= orders <= min(sum(inventory[i]), 109)
    • \n
    \n", "tags_en": ["Greedy", "Sort", "Math"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6392\u5e8f", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxProfit(vector& inventory, int orders) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxProfit(int[] inventory, int orders) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxProfit(self, inventory, orders):\n \"\"\"\n :type inventory: List[int]\n :type orders: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxProfit(self, inventory: List[int], orders: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxProfit(int* inventory, int inventorySize, int orders){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxProfit(int[] inventory, int orders) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} inventory\n * @param {number} orders\n * @return {number}\n */\nvar maxProfit = function(inventory, orders) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} inventory\n# @param {Integer} orders\n# @return {Integer}\ndef max_profit(inventory, orders)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxProfit(_ inventory: [Int], _ orders: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxProfit(inventory []int, orders int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxProfit(inventory: Array[Int], orders: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxProfit(inventory: IntArray, orders: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_profit(inventory: Vec, orders: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $inventory\n * @param Integer $orders\n * @return Integer\n */\n function maxProfit($inventory, $orders) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxProfit(inventory: number[], orders: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-profit inventory orders)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1648](https://leetcode-cn.com/problems/sell-diminishing-valued-colored-balls)", "[\u9500\u552e\u4ef7\u503c\u51cf\u5c11\u7684\u989c\u8272\u7403](/solution/1600-1699/1648.Sell%20Diminishing-Valued%20Colored%20Balls/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6392\u5e8f`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1648](https://leetcode.com/problems/sell-diminishing-valued-colored-balls)", "[Sell Diminishing-Valued Colored Balls](/solution/1600-1699/1648.Sell%20Diminishing-Valued%20Colored%20Balls/README_EN.md)", "`Greedy`,`Sort`,`Math`", "Medium", ""]}, {"question_id": "1770", "frontend_question_id": "1647", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-deletions-to-make-character-frequencies-unique", "url_en": "https://leetcode.com/problems/minimum-deletions-to-make-character-frequencies-unique", "relative_path_cn": "/solution/1600-1699/1647.Minimum%20Deletions%20to%20Make%20Character%20Frequencies%20Unique/README.md", "relative_path_en": "/solution/1600-1699/1647.Minimum%20Deletions%20to%20Make%20Character%20Frequencies%20Unique/README_EN.md", "title_cn": "\u5b57\u7b26\u9891\u6b21\u552f\u4e00\u7684\u6700\u5c0f\u5220\u9664\u6b21\u6570", "title_en": "Minimum Deletions to Make Character Frequencies Unique", "question_title_slug": "minimum-deletions-to-make-character-frequencies-unique", "content_en": "

    A string s is called good if there are no two different characters in s that have the same frequency.

    \n\n

    Given a string s, return the minimum number of characters you need to delete to make s good.

    \n\n

    The frequency of a character in a string is the number of times it appears in the string. For example, in the string "aab", the frequency of 'a' is 2, while the frequency of 'b' is 1.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "aab"\nOutput: 0\nExplanation: s is already good.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "aaabbbcc"\nOutput: 2\nExplanation: You can delete two 'b's resulting in the good string "aaabcc".\nAnother way it to delete one 'b' and one 'c' resulting in the good string "aaabbc".
    \n\n

    Example 3:

    \n\n
    \nInput: s = "ceabaacb"\nOutput: 2\nExplanation: You can delete both 'c's resulting in the good string "eabaab".\nNote that we only care about characters that are still in the string at the end (i.e. frequency of 0 is ignored).\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 105
    • \n\t
    • s contains only lowercase English letters.
    • \n
    \n", "content_cn": "

    \u5982\u679c\u5b57\u7b26\u4e32 s \u4e2d \u4e0d\u5b58\u5728 \u4e24\u4e2a\u4e0d\u540c\u5b57\u7b26 \u9891\u6b21 \u76f8\u540c\u7684\u60c5\u51b5\uff0c\u5c31\u79f0 s \u662f \u4f18\u8d28\u5b57\u7b26\u4e32 \u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s\uff0c\u8fd4\u56de\u4f7f s \u6210\u4e3a \u4f18\u8d28\u5b57\u7b26\u4e32 \u9700\u8981\u5220\u9664\u7684 \u6700\u5c0f \u5b57\u7b26\u6570\u3002

    \n\n

    \u5b57\u7b26\u4e32\u4e2d\u5b57\u7b26\u7684 \u9891\u6b21 \u662f\u8be5\u5b57\u7b26\u5728\u5b57\u7b26\u4e32\u4e2d\u7684\u51fa\u73b0\u6b21\u6570\u3002\u4f8b\u5982\uff0c\u5728\u5b57\u7b26\u4e32 \"aab\" \u4e2d\uff0c'a' \u7684\u9891\u6b21\u662f 2\uff0c\u800c 'b' \u7684\u9891\u6b21\u662f 1 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"aab\"\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1as \u5df2\u7ecf\u662f\u4f18\u8d28\u5b57\u7b26\u4e32\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"aaabbbcc\"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u53ef\u4ee5\u5220\u9664\u4e24\u4e2a 'b' , \u5f97\u5230\u4f18\u8d28\u5b57\u7b26\u4e32 \"aaabcc\" \u3002\n\u53e6\u4e00\u79cd\u65b9\u5f0f\u662f\u5220\u9664\u4e00\u4e2a 'b' \u548c\u4e00\u4e2a 'c' \uff0c\u5f97\u5230\u4f18\u8d28\u5b57\u7b26\u4e32 \"aaabbc\" \u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"ceabaacb\"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u53ef\u4ee5\u5220\u9664\u4e24\u4e2a 'c' \u5f97\u5230\u4f18\u8d28\u5b57\u7b26\u4e32 \"eabaab\" \u3002\n\u6ce8\u610f\uff0c\u53ea\u9700\u8981\u5173\u6ce8\u7ed3\u679c\u5b57\u7b26\u4e32\u4e2d\u4ecd\u7136\u5b58\u5728\u7684\u5b57\u7b26\u3002\uff08\u5373\uff0c\u9891\u6b21\u4e3a 0 \u7684\u5b57\u7b26\u4f1a\u5ffd\u7565\u4e0d\u8ba1\u3002\uff09\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 105
    • \n\t
    • s \u4ec5\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd
    • \n
    \n", "tags_en": ["Greedy", "Sort"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6392\u5e8f"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minDeletions(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minDeletions(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minDeletions(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minDeletions(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minDeletions(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinDeletions(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar minDeletions = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef min_deletions(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minDeletions(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minDeletions(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minDeletions(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minDeletions(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_deletions(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function minDeletions($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minDeletions(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-deletions s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1647](https://leetcode-cn.com/problems/minimum-deletions-to-make-character-frequencies-unique)", "[\u5b57\u7b26\u9891\u6b21\u552f\u4e00\u7684\u6700\u5c0f\u5220\u9664\u6b21\u6570](/solution/1600-1699/1647.Minimum%20Deletions%20to%20Make%20Character%20Frequencies%20Unique/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6392\u5e8f`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1647](https://leetcode.com/problems/minimum-deletions-to-make-character-frequencies-unique)", "[Minimum Deletions to Make Character Frequencies Unique](/solution/1600-1699/1647.Minimum%20Deletions%20to%20Make%20Character%20Frequencies%20Unique/README_EN.md)", "`Greedy`,`Sort`", "Medium", ""]}, {"question_id": "1769", "frontend_question_id": "1646", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/get-maximum-in-generated-array", "url_en": "https://leetcode.com/problems/get-maximum-in-generated-array", "relative_path_cn": "/solution/1600-1699/1646.Get%20Maximum%20in%20Generated%20Array/README.md", "relative_path_en": "/solution/1600-1699/1646.Get%20Maximum%20in%20Generated%20Array/README_EN.md", "title_cn": "\u83b7\u53d6\u751f\u6210\u6570\u7ec4\u4e2d\u7684\u6700\u5927\u503c", "title_en": "Get Maximum in Generated Array", "question_title_slug": "get-maximum-in-generated-array", "content_en": "

    You are given an integer n. An array nums of length n + 1 is generated in the following way:

    \n\n
      \n\t
    • nums[0] = 0
    • \n\t
    • nums[1] = 1
    • \n\t
    • nums[2 * i] = nums[i] when 2 <= 2 * i <= n
    • \n\t
    • nums[2 * i + 1] = nums[i] + nums[i + 1] when 2 <= 2 * i + 1 <= n
    • \n
    \n\n

    Return the maximum integer in the array nums\u200b\u200b\u200b.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 7\nOutput: 3\nExplanation: According to the given rules:\n  nums[0] = 0\n  nums[1] = 1\n  nums[(1 * 2) = 2] = nums[1] = 1\n  nums[(1 * 2) + 1 = 3] = nums[1] + nums[2] = 1 + 1 = 2\n  nums[(2 * 2) = 4] = nums[2] = 1\n  nums[(2 * 2) + 1 = 5] = nums[2] + nums[3] = 1 + 2 = 3\n  nums[(3 * 2) = 6] = nums[3] = 2\n  nums[(3 * 2) + 1 = 7] = nums[3] + nums[4] = 2 + 1 = 3\nHence, nums = [0,1,1,2,1,3,2,3], and the maximum is 3.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 2\nOutput: 1\nExplanation: According to the given rules, the maximum between nums[0], nums[1], and nums[2] is 1.\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 3\nOutput: 2\nExplanation: According to the given rules, the maximum between nums[0], nums[1], nums[2], and nums[3] is 2.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= n <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n \u3002\u6309\u4e0b\u8ff0\u89c4\u5219\u751f\u6210\u4e00\u4e2a\u957f\u5ea6\u4e3a n + 1 \u7684\u6570\u7ec4 nums \uff1a

    \n\n
      \n\t
    • nums[0] = 0
    • \n\t
    • nums[1] = 1
    • \n\t
    • \u5f53 2 <= 2 * i <= n \u65f6\uff0cnums[2 * i] = nums[i]
    • \n\t
    • \u5f53 2 <= 2 * i + 1 <= n \u65f6\uff0cnums[2 * i + 1] = nums[i] + nums[i + 1]
    • \n
    \n\n

    \u8fd4\u56de\u751f\u6210\u6570\u7ec4 nums \u4e2d\u7684 \u6700\u5927 \u503c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 7\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6839\u636e\u89c4\u5219\uff1a\n  nums[0] = 0\n  nums[1] = 1\n  nums[(1 * 2) = 2] = nums[1] = 1\n  nums[(1 * 2) + 1 = 3] = nums[1] + nums[2] = 1 + 1 = 2\n  nums[(2 * 2) = 4] = nums[2] = 1\n  nums[(2 * 2) + 1 = 5] = nums[2] + nums[3] = 1 + 2 = 3\n  nums[(3 * 2) = 6] = nums[3] = 2\n  nums[(3 * 2) + 1 = 7] = nums[3] + nums[4] = 2 + 1 = 3\n\u56e0\u6b64\uff0cnums = [0,1,1,2,1,3,2,3]\uff0c\u6700\u5927\u503c 3\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 2\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u6839\u636e\u89c4\u5219\uff0cnums[0]\u3001nums[1] \u548c nums[2] \u4e4b\u4e2d\u7684\u6700\u5927\u503c\u662f 1\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 3\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6839\u636e\u89c4\u5219\uff0cnums[0]\u3001nums[1]\u3001nums[2] \u548c nums[3] \u4e4b\u4e2d\u7684\u6700\u5927\u503c\u662f 2\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= n <= 100
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int getMaximumGenerated(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int getMaximumGenerated(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getMaximumGenerated(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getMaximumGenerated(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint getMaximumGenerated(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int GetMaximumGenerated(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar getMaximumGenerated = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef get_maximum_generated(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getMaximumGenerated(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getMaximumGenerated(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getMaximumGenerated(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getMaximumGenerated(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_maximum_generated(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function getMaximumGenerated($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getMaximumGenerated(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-maximum-generated n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1646](https://leetcode-cn.com/problems/get-maximum-in-generated-array)", "[\u83b7\u53d6\u751f\u6210\u6570\u7ec4\u4e2d\u7684\u6700\u5927\u503c](/solution/1600-1699/1646.Get%20Maximum%20in%20Generated%20Array/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1646](https://leetcode.com/problems/get-maximum-in-generated-array)", "[Get Maximum in Generated Array](/solution/1600-1699/1646.Get%20Maximum%20in%20Generated%20Array/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1768", "frontend_question_id": "1628", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/design-an-expression-tree-with-evaluate-function", "url_en": "https://leetcode.com/problems/design-an-expression-tree-with-evaluate-function", "relative_path_cn": "/solution/1600-1699/1628.Design%20an%20Expression%20Tree%20With%20Evaluate%20Function/README.md", "relative_path_en": "/solution/1600-1699/1628.Design%20an%20Expression%20Tree%20With%20Evaluate%20Function/README_EN.md", "title_cn": "\u8bbe\u8ba1\u5e26\u89e3\u6790\u51fd\u6570\u7684\u8868\u8fbe\u5f0f\u6811", "title_en": "Design an Expression Tree With Evaluate Function", "question_title_slug": "design-an-expression-tree-with-evaluate-function", "content_en": "

    Given the postfix tokens of an arithmetic expression, build and return the binary expression tree that represents this expression.

    \r\n\r\n

    Postfix notation is a notation for writing arithmetic expressions in which the operands (numbers) appear before their operators. For example, the postfix tokens of the expression 4*(5-(7+2)) are represented in the array postfix = ["4","5","7","2","+","-","*"].

    \r\n\r\n

    The class Node is an interface you should use to implement the binary expression tree. The returned tree will be tested using the evaluate function, which is supposed to evaluate the tree's value. You should not remove the Node class; however, you can modify it as you wish, and you can define other classes to implement it if needed.

    \r\n\r\n

    A binary expression tree is a kind of binary tree used to represent arithmetic expressions. Each node of a binary expression tree has either zero or two children. Leaf nodes (nodes with 0 children) correspond to operands (numbers), and internal nodes (nodes with two children) correspond to the operators '+' (addition), '-' (subtraction), '*' (multiplication), and '/' (division).

    \r\n\r\n

    It's guaranteed that no subtree will yield a value that exceeds 109 in absolute value, and all the operations are valid (i.e., no division by zero).

    \r\n\r\n

    Follow up: Could you design the expression tree such that it is more modular? For example, is your design able to support additional operators without making changes to your existing evaluate implementation?

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n

    \"\"

    \r\n\r\n
    \r\nInput: s = ["3","4","+","2","*","7","/"]\r\nOutput: 2\r\nExplanation: this expression evaluates to the above binary tree with expression ((3+4)*2)/7) = 14/7 = 2.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n

    \"\"

    \r\n\r\n
    \r\nInput: s = ["4","5","7","2","+","-","*"]\r\nOutput: -16\r\nExplanation: this expression evaluates to the above binary tree with expression 4*(5-(2+7)) = 4*(-4) = -16.\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: s = ["4","2","+","3","5","1","-","*","+"]\r\nOutput: 18\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: s = ["100","200","+","2","/","5","*","7","+"]\r\nOutput: 757\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= s.length < 100
    • \r\n\t
    • s.length is odd.
    • \r\n\t
    • s consists of numbers and the characters '+', '-', '*', and '/'.
    • \r\n\t
    • If s[i] is a number, its integer representation is no more than 105.
    • \r\n\t
    • It is guaranteed that s is a valid expression.
    • \r\n\t
    • The absolute value of the result and intermediate values will not exceed 109.
    • \r\n\t
    • It is guaranteed that no expression will include division by zero.
    • \r\n
    ", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u7b97\u672f\u8868\u8fbe\u5f0f\u7684\u540e\u7f00\u8868\u793a\u6cd5\u7684\u6807\u8bb0\uff08token\uff09\u00a0postfix\u00a0\uff0c\u6784\u9020\u5e76\u8fd4\u56de\u8be5\u8868\u8fbe\u5f0f\u5bf9\u5e94\u7684\u4e8c\u53c9\u8868\u8fbe\u5f0f\u6811\u3002

    \n\n

    \u540e\u7f00\u8868\u793a\u6cd5\u662f\u4e00\u79cd\u5c06\u64cd\u4f5c\u6570\u5199\u5728\u8fd0\u7b97\u7b26\u4e4b\u524d\u7684\u8868\u793a\u6cd5\u3002\u4f8b\u5982\uff0c\u8868\u8fbe\u5f0f\u00a04*(5-(2+7))\u00a0\u7684\u540e\u7f00\u8868\u793a\u6cd5\u8868\u793a\u4e3a\u6570\u7ec4\u00a0postfix = [\"4\",\"5\",\"7\",\"2\",\"+\",\"-\",\"*\"]\u00a0\u3002

    \n\n

    \u62bd\u8c61\u7c7b\u00a0Node\u00a0\u9700\u8981\u7528\u4e8e\u5b9e\u73b0\u4e8c\u53c9\u8868\u8fbe\u5f0f\u6811\u3002\u6211\u4eec\u5c06\u901a\u8fc7\u00a0evaluate\u00a0\u51fd\u6570\u6765\u6d4b\u8bd5\u8fd4\u56de\u7684\u6811\u662f\u5426\u80fd\u591f\u89e3\u6790\u6811\u4e2d\u7684\u503c\u3002\u4f60\u4e0d\u53ef\u4ee5\u79fb\u9664 Node \u7c7b\uff0c\u4f46\u4f60\u53ef\u4ee5\u6309\u9700\u4fee\u6539\u6b64\u7c7b\uff0c\u4e5f\u53ef\u4ee5\u5b9a\u4e49\u5176\u4ed6\u7c7b\u6765\u5b9e\u73b0\u5b83\u3002

    \n\n

    \u4e8c\u53c9\u8868\u8fbe\u5f0f\u6811\u662f\u4e00\u79cd\u8868\u8fbe\u7b97\u672f\u8868\u8fbe\u5f0f\u7684\u4e8c\u53c9\u6811\u3002\u4e8c\u53c9\u8868\u8fbe\u5f0f\u6811\u4e2d\u7684\u6bcf\u4e00\u4e2a\u8282\u70b9\u90fd\u6709\u96f6\u4e2a\u6216\u4e24\u4e2a\u5b50\u8282\u70b9\u3002\u00a0\u53f6\u8282\u70b9\uff08\u6709 0 \u4e2a\u5b50\u8282\u70b9\u7684\u8282\u70b9\uff09\u8868\u793a\u64cd\u4f5c\u6570\uff0c\u975e\u53f6\u8282\u70b9\uff08\u6709 2 \u4e2a\u5b50\u8282\u70b9\u7684\u8282\u70b9\uff09\u8868\u793a\u8fd0\u7b97\u7b26\uff1a\u00a0'+'\u00a0\uff08\u52a0\uff09\u3001\u00a0'-' \uff08\u51cf\uff09\u3001\u00a0'*' \uff08\u4e58\uff09\u548c\u00a0'/' \uff08\u9664\uff09\u3002

    \n\n

    \u6211\u4eec\u4fdd\u8bc1\u4efb\u4f55\u5b50\u6811\u5bf9\u5e94\u503c\u7684\u7edd\u5bf9\u503c\u4e0d\u8d85\u8fc7\u00a0109\u00a0\uff0c\u4e14\u6240\u6709\u64cd\u4f5c\u90fd\u662f\u6709\u6548\u7684\uff08\u5373\u6ca1\u6709\u9664\u4ee5\u96f6\u7684\u64cd\u4f5c\uff09

    \n\n

    \u8fdb\u9636\uff1a\u00a0\u4f60\u53ef\u4ee5\u5c06\u8868\u8fbe\u5f0f\u6811\u8bbe\u8ba1\u5f97\u66f4\u6a21\u5757\u5316\u5417\uff1f\u4f8b\u5982\uff0c\u4f60\u7684\u8bbe\u8ba1\u80fd\u591f\u4e0d\u4fee\u6539\u73b0\u6709\u7684\u00a0evaluate\u00a0\u7684\u5b9e\u73b0\u5c31\u80fd\u652f\u6301\u66f4\u591a\u7684\u64cd\u4f5c\u7b26\u5417\uff1f

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1:

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1a s = [\"3\",\"4\",\"+\",\"2\",\"*\",\"7\",\"/\"]\n\u8f93\u51fa\uff1a 2\n\u89e3\u91ca\uff1a \u6b64\u8868\u8fbe\u5f0f\u53ef\u89e3\u6790\u4e3a\u4e0a\u8ff0\u4e8c\u53c9\u6811\uff0c\u5176\u5bf9\u5e94\u8868\u8fbe\u5f0f\u4e3a ((3+4)*2)/7) = 14/7 = 2.\n
    \n\n

    \u793a\u4f8b 2:

    \n\n

    \"\"

    \n\n
    \u8f93\u5165: s = [\"4\",\"5\",\"7\",\"2\",\"+\",\"-\",\"*\"]\n\u8f93\u51fa: -16\n\u89e3\u91ca: \u6b64\u8868\u8fbe\u5f0f\u53ef\u89e3\u6790\u4e3a\u4e0a\u8ff0\u4e8c\u53c9\u6811\uff0c\u5176\u5bf9\u5e94\u8868\u8fbe\u5f0f\u4e3a 4*(5-(2+7)) = 4*(-4) = -16.\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u8f93\u5165: s = [\"4\",\"2\",\"+\",\"3\",\"5\",\"1\",\"-\",\"*\",\"+\"]\n\u8f93\u51fa: 18\n
    \n\n

    \u793a\u4f8b 4:

    \n\n
    \u8f93\u5165: s = [\"100\",\"200\",\"+\",\"2\",\"/\",\"5\",\"*\",\"7\",\"+\"]\n\u8f93\u51fa: 757\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a:

    \n\n
      \n\t
    • 1 <= s.length < 100
    • \n\t
    • s.length\u00a0\u662f\u5947\u6570\u3002
    • \n\t
    • s\u00a0\u5305\u542b\u6570\u5b57\u548c\u5b57\u7b26\u00a0'+'\u00a0\u3001\u00a0'-'\u00a0\u3001\u00a0'*'\u00a0\u4ee5\u53ca\u00a0'/'\u00a0\u3002
    • \n\t
    • \u5982\u679c\u00a0s[i]\u00a0\u662f\u6570\uff0c\u5219\u5bf9\u5e94\u7684\u6574\u6570\u4e0d\u8d85\u8fc7\u00a0105\u00a0\u3002
    • \n\t
    • s\u00a0\u4fdd\u8bc1\u662f\u4e00\u4e2a\u6709\u6548\u7684\u8868\u8fbe\u5f0f\u3002
    • \n\t
    • \u7ed3\u679c\u503c\u548c\u6240\u6709\u8fc7\u7a0b\u503c\u7684\u7edd\u5bf9\u503c\u5747\u4e0d\u8d85\u8fc7\u00a0109\u00a0\u3002
    • \n\t
    • \u4fdd\u8bc1\u8868\u8fbe\u5f0f\u4e0d\u5305\u542b\u9664\u4ee5\u96f6\u7684\u64cd\u4f5c\u3002
    • \n
    \n", "tags_en": ["Tree", "Design"], "tags_cn": ["\u6811", "\u8bbe\u8ba1"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * This is the interface for the expression tree Node.\n * You should not remove it, and you can define some classes to implement it.\n */\n\nclass Node {\npublic:\n virtual ~Node () {};\n virtual int evaluate() const = 0;\nprotected:\n // define your fields here\n};\n\n\n/**\n * This is the TreeBuilder class.\n * You can treat it as the driver code that takes the postinfix input \n * and returns the expression tree represnting it as a Node.\n */\n\nclass TreeBuilder {\npublic:\n Node* buildTree(vector& postfix) {\n \n }\n};\n\n\n/**\n * Your TreeBuilder object will be instantiated and called as such:\n * TreeBuilder* obj = new TreeBuilder();\n * Node* expTree = obj->buildTree(postfix);\n * int ans = expTree->evaluate();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * This is the interface for the expression tree Node.\n * You should not remove it, and you can define some classes to implement it.\n */\n\nabstract class Node {\n public abstract int evaluate();\n // define your fields here\n};\n\n\n/**\n * This is the TreeBuilder class.\n * You can treat it as the driver code that takes the postinfix input \n * and returns the expression tree represnting it as a Node.\n */\n\nclass TreeBuilder {\n Node buildTree(String[] postfix) {\n \n }\n};\n\n\n/**\n * Your TreeBuilder object will be instantiated and called as such:\n * TreeBuilder obj = new TreeBuilder();\n * Node expTree = obj.buildTree(postfix);\n * int ans = expTree.evaluate();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "import abc \nfrom abc import ABCMeta, abstractmethod \n\"\"\"\nThis is the interface for the expression tree Node.\nYou should not remove it, and you can define some classes to implement it.\n\"\"\"\n\nclass Node:\n __metaclass__ = ABCMeta\n # define your fields here\n @abstractmethod\n def evaluate(self):\n pass\n\n\n\"\"\" \nThis is the TreeBuilder class.\nYou can treat it as the driver code that takes the postinfix input\nand returns the expression tree represnting it as a Node.\n\"\"\"\n\nclass TreeBuilder(object):\n def buildTree(self, postfix):\n \"\"\"\n :type s: List[str]\n :rtype: int\n \"\"\"\n\n\"\"\"\nYour TreeBuilder object will be instantiated and called as such:\nobj = TreeBuilder();\nexpTree = obj.buildTree(postfix);\nans = expTree.evaluate();\n\"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "import abc \nfrom abc import ABC, abstractmethod \n\"\"\"\nThis is the interface for the expression tree Node.\nYou should not remove it, and you can define some classes to implement it.\n\"\"\"\n\nclass Node(ABC):\n @abstractmethod\n # define your fields here\n def evaluate(self) -> int:\n pass\n\n\n\"\"\" \nThis is the TreeBuilder class.\nYou can treat it as the driver code that takes the postinfix input\nand returns the expression tree represnting it as a Node.\n\"\"\"\n\nclass TreeBuilder(object):\n def buildTree(self, postfix: List[str]) -> 'Node':\n \n\t\t\n\"\"\"\nYour TreeBuilder object will be instantiated and called as such:\nobj = TreeBuilder();\nexpTree = obj.buildTree(postfix);\nans = expTree.evaluate();\n\"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * This is the interface for the expression tree Node.\n * You should not remove it, and you can define some classes to implement it.\n */\n\npublic abstract class Node {\n public abstract int evaluate();\n // define your fields here\n};\n\n\n/**\n * This is the TreeBuilder class.\n * You can treat it as the driver code that takes the postinfix input \n * and returns the expression tree represnting it as a Node.\n */\n\npublic class TreeBuilder {\n public Node buildTree(string[] postfix) {\n \n }\n}\n\n\n/**\n * Your TreeBuilder object will be instantiated and called as such:\n * TreeBuilder obj = new TreeBuilder();\n * Node expTree = obj.buildTree(postfix);\n * int ans = expTree.evaluate();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * This is the interface for the expression tree Node.\n * You should not remove it, and you can define some classes to implement it.\n */\n\nvar Node = function () {\n if (this.constructor === Node) {\n throw new Error('Cannot instanciate abstract class');\n }\n};\n\nNode.prototype.evaluate = function () {\n throw new Error('Cannot call abstract method')\n};\n\n/**\n * This is the TreeBuilder class.\n * You can treat it as the driver code that takes the postinfix input \n * and returns the expression tree represnting it as a Node.\n */\n\nclass TreeBuilder{\n\t/**\n * @param {string[]} s\n * @return {Node}\n */\n\tbuildTree(postfix) {\n \t\n\t}\n \n}\n\n/**\n * Your TreeBuilder object will be instantiated and called as such:\n * var obj = new TreeBuilder();\n * var expTree = obj.buildTree(postfix);\n * var ans = expTree.evaluate();\n */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1628](https://leetcode-cn.com/problems/design-an-expression-tree-with-evaluate-function)", "[\u8bbe\u8ba1\u5e26\u89e3\u6790\u51fd\u6570\u7684\u8868\u8fbe\u5f0f\u6811](/solution/1600-1699/1628.Design%20an%20Expression%20Tree%20With%20Evaluate%20Function/README.md)", "`\u6811`,`\u8bbe\u8ba1`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1628](https://leetcode.com/problems/design-an-expression-tree-with-evaluate-function)", "[Design an Expression Tree With Evaluate Function](/solution/1600-1699/1628.Design%20an%20Expression%20Tree%20With%20Evaluate%20Function/README_EN.md)", "`Tree`,`Design`", "Medium", "\ud83d\udd12"]}, {"question_id": "1767", "frontend_question_id": "1670", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/design-front-middle-back-queue", "url_en": "https://leetcode.com/problems/design-front-middle-back-queue", "relative_path_cn": "/solution/1600-1699/1670.Design%20Front%20Middle%20Back%20Queue/README.md", "relative_path_en": "/solution/1600-1699/1670.Design%20Front%20Middle%20Back%20Queue/README_EN.md", "title_cn": "\u8bbe\u8ba1\u524d\u4e2d\u540e\u961f\u5217", "title_en": "Design Front Middle Back Queue", "question_title_slug": "design-front-middle-back-queue", "content_en": "

    Design a queue that supports push and pop operations in the front, middle, and back.

    \n\n

    Implement the FrontMiddleBack class:

    \n\n
      \n\t
    • FrontMiddleBack() Initializes the queue.
    • \n\t
    • void pushFront(int val) Adds val to the front of the queue.
    • \n\t
    • void pushMiddle(int val) Adds val to the middle of the queue.
    • \n\t
    • void pushBack(int val) Adds val to the back of the queue.
    • \n\t
    • int popFront() Removes the front element of the queue and returns it. If the queue is empty, return -1.
    • \n\t
    • int popMiddle() Removes the middle element of the queue and returns it. If the queue is empty, return -1.
    • \n\t
    • int popBack() Removes the back element of the queue and returns it. If the queue is empty, return -1.
    • \n
    \n\n

    Notice that when there are two middle position choices, the operation is performed on the frontmost middle position choice. For example:

    \n\n
      \n\t
    • Pushing 6 into the middle of [1, 2, 3, 4, 5] results in [1, 2, 6, 3, 4, 5].
    • \n\t
    • Popping the middle from [1, 2, 3, 4, 5, 6] returns 3 and results in [1, 2, 4, 5, 6].
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput:\n["FrontMiddleBackQueue", "pushFront", "pushBack", "pushMiddle", "pushMiddle", "popFront", "popMiddle", "popMiddle", "popBack", "popFront"]\n[[], [1], [2], [3], [4], [], [], [], [], []]\nOutput:\n[null, null, null, null, null, 1, 3, 4, 2, -1]\n\nExplanation:\nFrontMiddleBackQueue q = new FrontMiddleBackQueue();\nq.pushFront(1);   // [1]\nq.pushBack(2);    // [1, 2]\nq.pushMiddle(3);  // [1, 3, 2]\nq.pushMiddle(4);  // [1, 4, 3, 2]\nq.popFront();     // return 1 -> [4, 3, 2]\nq.popMiddle();    // return 3 -> [4, 2]\nq.popMiddle();    // return 4 -> [2]\nq.popBack();      // return 2 -> []\nq.popFront();     // return -1 -> [] (The queue is empty)\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= val <= 109
    • \n\t
    • At most 1000 calls will be made to pushFrontpushMiddlepushBack, popFront, popMiddle, and popBack.
    • \n
    \n", "content_cn": "

    \u8bf7\u4f60\u8bbe\u8ba1\u4e00\u4e2a\u961f\u5217\uff0c\u652f\u6301\u5728\u524d\uff0c\u4e2d\uff0c\u540e\u4e09\u4e2a\u4f4d\u7f6e\u7684 push\u00a0\u548c pop\u00a0\u64cd\u4f5c\u3002

    \n\n

    \u8bf7\u4f60\u5b8c\u6210\u00a0FrontMiddleBack\u00a0\u7c7b\uff1a

    \n\n
      \n\t
    • FrontMiddleBack()\u00a0\u521d\u59cb\u5316\u961f\u5217\u3002
    • \n\t
    • void pushFront(int val) \u5c06\u00a0val\u00a0\u6dfb\u52a0\u5230\u961f\u5217\u7684 \u6700\u524d\u9762\u00a0\u3002
    • \n\t
    • void pushMiddle(int val) \u5c06\u00a0val\u00a0\u6dfb\u52a0\u5230\u961f\u5217\u7684 \u6b63\u4e2d\u95f4\u00a0\u3002
    • \n\t
    • void pushBack(int val)\u00a0\u5c06\u00a0val\u00a0\u6dfb\u52a0\u5230\u961f\u91cc\u7684 \u6700\u540e\u9762\u00a0\u3002
    • \n\t
    • int popFront()\u00a0\u5c06 \u6700\u524d\u9762 \u7684\u5143\u7d20\u4ece\u961f\u5217\u4e2d\u5220\u9664\u5e76\u8fd4\u56de\u503c\uff0c\u5982\u679c\u5220\u9664\u4e4b\u524d\u961f\u5217\u4e3a\u7a7a\uff0c\u90a3\u4e48\u8fd4\u56de -1\u00a0\u3002
    • \n\t
    • int popMiddle() \u5c06 \u6b63\u4e2d\u95f4\u00a0\u7684\u5143\u7d20\u4ece\u961f\u5217\u4e2d\u5220\u9664\u5e76\u8fd4\u56de\u503c\uff0c\u5982\u679c\u5220\u9664\u4e4b\u524d\u961f\u5217\u4e3a\u7a7a\uff0c\u90a3\u4e48\u8fd4\u56de -1\u00a0\u3002
    • \n\t
    • int popBack() \u5c06 \u6700\u540e\u9762 \u7684\u5143\u7d20\u4ece\u961f\u5217\u4e2d\u5220\u9664\u5e76\u8fd4\u56de\u503c\uff0c\u5982\u679c\u5220\u9664\u4e4b\u524d\u961f\u5217\u4e3a\u7a7a\uff0c\u90a3\u4e48\u8fd4\u56de -1\u00a0\u3002
    • \n
    \n\n

    \u8bf7\u6ce8\u610f\u5f53\u6709\u00a0\u4e24\u4e2a\u00a0\u4e2d\u95f4\u4f4d\u7f6e\u7684\u65f6\u5019\uff0c\u9009\u62e9\u9760\u524d\u9762\u7684\u4f4d\u7f6e\u8fdb\u884c\u64cd\u4f5c\u3002\u6bd4\u65b9\u8bf4\uff1a

    \n\n
      \n\t
    • \u5c06 6\u00a0\u6dfb\u52a0\u5230\u00a0[1, 2, 3, 4, 5]\u00a0\u7684\u4e2d\u95f4\u4f4d\u7f6e\uff0c\u7ed3\u679c\u6570\u7ec4\u4e3a\u00a0[1, 2, 6, 3, 4, 5]\u00a0\u3002
    • \n\t
    • \u4ece\u00a0[1, 2, 3, 4, 5, 6]\u00a0\u7684\u4e2d\u95f4\u4f4d\u7f6e\u5f39\u51fa\u5143\u7d20\uff0c\u8fd4\u56de\u00a03\u00a0\uff0c\u6570\u7ec4\u53d8\u4e3a\u00a0[1, 2, 4, 5, 6]\u00a0\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\n[\"FrontMiddleBackQueue\", \"pushFront\", \"pushBack\", \"pushMiddle\", \"pushMiddle\", \"popFront\", \"popMiddle\", \"popMiddle\", \"popBack\", \"popFront\"]\n[[], [1], [2], [3], [4], [], [], [], [], []]\n\u8f93\u51fa\uff1a\n[null, null, null, null, null, 1, 3, 4, 2, -1]\n\n\u89e3\u91ca\uff1a\nFrontMiddleBackQueue q = new FrontMiddleBackQueue();\nq.pushFront(1);   // [1]\nq.pushBack(2);    // [1, 2]\nq.pushMiddle(3);  // [1, 3, 2]\nq.pushMiddle(4);  // [1, 4, 3, 2]\nq.popFront();     // \u8fd4\u56de 1 -> [4, 3, 2]\nq.popMiddle();    // \u8fd4\u56de 3 -> [4, 2]\nq.popMiddle();    // \u8fd4\u56de 4 -> [2]\nq.popBack();      // \u8fd4\u56de 2 -> []\nq.popFront();     // \u8fd4\u56de -1 -> [] \uff08\u961f\u5217\u4e3a\u7a7a\uff09\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= val <= 109
    • \n\t
    • \u6700\u591a\u8c03\u7528\u00a01000\u00a0\u6b21\u00a0pushFront\uff0c\u00a0pushMiddle\uff0c\u00a0pushBack\uff0c\u00a0popFront\uff0c\u00a0popMiddle\u00a0\u548c\u00a0popBack \u3002
    • \n
    \n", "tags_en": ["Design", "Linked List"], "tags_cn": ["\u8bbe\u8ba1", "\u94fe\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class FrontMiddleBackQueue {\npublic:\n FrontMiddleBackQueue() {\n\n }\n \n void pushFront(int val) {\n\n }\n \n void pushMiddle(int val) {\n\n }\n \n void pushBack(int val) {\n\n }\n \n int popFront() {\n\n }\n \n int popMiddle() {\n\n }\n \n int popBack() {\n\n }\n};\n\n/**\n * Your FrontMiddleBackQueue object will be instantiated and called as such:\n * FrontMiddleBackQueue* obj = new FrontMiddleBackQueue();\n * obj->pushFront(val);\n * obj->pushMiddle(val);\n * obj->pushBack(val);\n * int param_4 = obj->popFront();\n * int param_5 = obj->popMiddle();\n * int param_6 = obj->popBack();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class FrontMiddleBackQueue {\n\n public FrontMiddleBackQueue() {\n\n }\n \n public void pushFront(int val) {\n\n }\n \n public void pushMiddle(int val) {\n\n }\n \n public void pushBack(int val) {\n\n }\n \n public int popFront() {\n\n }\n \n public int popMiddle() {\n\n }\n \n public int popBack() {\n\n }\n}\n\n/**\n * Your FrontMiddleBackQueue object will be instantiated and called as such:\n * FrontMiddleBackQueue obj = new FrontMiddleBackQueue();\n * obj.pushFront(val);\n * obj.pushMiddle(val);\n * obj.pushBack(val);\n * int param_4 = obj.popFront();\n * int param_5 = obj.popMiddle();\n * int param_6 = obj.popBack();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class FrontMiddleBackQueue(object):\n\n def __init__(self):\n\n\n def pushFront(self, val):\n \"\"\"\n :type val: int\n :rtype: None\n \"\"\"\n\n\n def pushMiddle(self, val):\n \"\"\"\n :type val: int\n :rtype: None\n \"\"\"\n\n\n def pushBack(self, val):\n \"\"\"\n :type val: int\n :rtype: None\n \"\"\"\n\n\n def popFront(self):\n \"\"\"\n :rtype: int\n \"\"\"\n\n\n def popMiddle(self):\n \"\"\"\n :rtype: int\n \"\"\"\n\n\n def popBack(self):\n \"\"\"\n :rtype: int\n \"\"\"\n\n\n\n# Your FrontMiddleBackQueue object will be instantiated and called as such:\n# obj = FrontMiddleBackQueue()\n# obj.pushFront(val)\n# obj.pushMiddle(val)\n# obj.pushBack(val)\n# param_4 = obj.popFront()\n# param_5 = obj.popMiddle()\n# param_6 = obj.popBack()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class FrontMiddleBackQueue:\n\n def __init__(self):\n\n\n def pushFront(self, val: int) -> None:\n\n\n def pushMiddle(self, val: int) -> None:\n\n\n def pushBack(self, val: int) -> None:\n\n\n def popFront(self) -> int:\n\n\n def popMiddle(self) -> int:\n\n\n def popBack(self) -> int:\n\n\n\n# Your FrontMiddleBackQueue object will be instantiated and called as such:\n# obj = FrontMiddleBackQueue()\n# obj.pushFront(val)\n# obj.pushMiddle(val)\n# obj.pushBack(val)\n# param_4 = obj.popFront()\n# param_5 = obj.popMiddle()\n# param_6 = obj.popBack()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} FrontMiddleBackQueue;\n\n\nFrontMiddleBackQueue* frontMiddleBackQueueCreate() {\n\n}\n\nvoid frontMiddleBackQueuePushFront(FrontMiddleBackQueue* obj, int val) {\n\n}\n\nvoid frontMiddleBackQueuePushMiddle(FrontMiddleBackQueue* obj, int val) {\n\n}\n\nvoid frontMiddleBackQueuePushBack(FrontMiddleBackQueue* obj, int val) {\n\n}\n\nint frontMiddleBackQueuePopFront(FrontMiddleBackQueue* obj) {\n\n}\n\nint frontMiddleBackQueuePopMiddle(FrontMiddleBackQueue* obj) {\n\n}\n\nint frontMiddleBackQueuePopBack(FrontMiddleBackQueue* obj) {\n\n}\n\nvoid frontMiddleBackQueueFree(FrontMiddleBackQueue* obj) {\n\n}\n\n/**\n * Your FrontMiddleBackQueue struct will be instantiated and called as such:\n * FrontMiddleBackQueue* obj = frontMiddleBackQueueCreate();\n * frontMiddleBackQueuePushFront(obj, val);\n \n * frontMiddleBackQueuePushMiddle(obj, val);\n \n * frontMiddleBackQueuePushBack(obj, val);\n \n * int param_4 = frontMiddleBackQueuePopFront(obj);\n \n * int param_5 = frontMiddleBackQueuePopMiddle(obj);\n \n * int param_6 = frontMiddleBackQueuePopBack(obj);\n \n * frontMiddleBackQueueFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class FrontMiddleBackQueue {\n\n public FrontMiddleBackQueue() {\n\n }\n \n public void PushFront(int val) {\n\n }\n \n public void PushMiddle(int val) {\n\n }\n \n public void PushBack(int val) {\n\n }\n \n public int PopFront() {\n\n }\n \n public int PopMiddle() {\n\n }\n \n public int PopBack() {\n\n }\n}\n\n/**\n * Your FrontMiddleBackQueue object will be instantiated and called as such:\n * FrontMiddleBackQueue obj = new FrontMiddleBackQueue();\n * obj.PushFront(val);\n * obj.PushMiddle(val);\n * obj.PushBack(val);\n * int param_4 = obj.PopFront();\n * int param_5 = obj.PopMiddle();\n * int param_6 = obj.PopBack();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "\nvar FrontMiddleBackQueue = function() {\n\n};\n\n/** \n * @param {number} val\n * @return {void}\n */\nFrontMiddleBackQueue.prototype.pushFront = function(val) {\n\n};\n\n/** \n * @param {number} val\n * @return {void}\n */\nFrontMiddleBackQueue.prototype.pushMiddle = function(val) {\n\n};\n\n/** \n * @param {number} val\n * @return {void}\n */\nFrontMiddleBackQueue.prototype.pushBack = function(val) {\n\n};\n\n/**\n * @return {number}\n */\nFrontMiddleBackQueue.prototype.popFront = function() {\n\n};\n\n/**\n * @return {number}\n */\nFrontMiddleBackQueue.prototype.popMiddle = function() {\n\n};\n\n/**\n * @return {number}\n */\nFrontMiddleBackQueue.prototype.popBack = function() {\n\n};\n\n/**\n * Your FrontMiddleBackQueue object will be instantiated and called as such:\n * var obj = new FrontMiddleBackQueue()\n * obj.pushFront(val)\n * obj.pushMiddle(val)\n * obj.pushBack(val)\n * var param_4 = obj.popFront()\n * var param_5 = obj.popMiddle()\n * var param_6 = obj.popBack()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class FrontMiddleBackQueue\n def initialize()\n\n end\n\n\n=begin\n :type val: Integer\n :rtype: Void\n=end\n def push_front(val)\n\n end\n\n\n=begin\n :type val: Integer\n :rtype: Void\n=end\n def push_middle(val)\n\n end\n\n\n=begin\n :type val: Integer\n :rtype: Void\n=end\n def push_back(val)\n\n end\n\n\n=begin\n :rtype: Integer\n=end\n def pop_front()\n\n end\n\n\n=begin\n :rtype: Integer\n=end\n def pop_middle()\n\n end\n\n\n=begin\n :rtype: Integer\n=end\n def pop_back()\n\n end\n\n\nend\n\n# Your FrontMiddleBackQueue object will be instantiated and called as such:\n# obj = FrontMiddleBackQueue.new()\n# obj.push_front(val)\n# obj.push_middle(val)\n# obj.push_back(val)\n# param_4 = obj.pop_front()\n# param_5 = obj.pop_middle()\n# param_6 = obj.pop_back()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass FrontMiddleBackQueue {\n\n init() {\n\n }\n \n func pushFront(_ val: Int) {\n\n }\n \n func pushMiddle(_ val: Int) {\n\n }\n \n func pushBack(_ val: Int) {\n\n }\n \n func popFront() -> Int {\n\n }\n \n func popMiddle() -> Int {\n\n }\n \n func popBack() -> Int {\n\n }\n}\n\n/**\n * Your FrontMiddleBackQueue object will be instantiated and called as such:\n * let obj = FrontMiddleBackQueue()\n * obj.pushFront(val)\n * obj.pushMiddle(val)\n * obj.pushBack(val)\n * let ret_4: Int = obj.popFront()\n * let ret_5: Int = obj.popMiddle()\n * let ret_6: Int = obj.popBack()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type FrontMiddleBackQueue struct {\n\n}\n\n\nfunc Constructor() FrontMiddleBackQueue {\n\n}\n\n\nfunc (this *FrontMiddleBackQueue) PushFront(val int) {\n\n}\n\n\nfunc (this *FrontMiddleBackQueue) PushMiddle(val int) {\n\n}\n\n\nfunc (this *FrontMiddleBackQueue) PushBack(val int) {\n\n}\n\n\nfunc (this *FrontMiddleBackQueue) PopFront() int {\n\n}\n\n\nfunc (this *FrontMiddleBackQueue) PopMiddle() int {\n\n}\n\n\nfunc (this *FrontMiddleBackQueue) PopBack() int {\n\n}\n\n\n/**\n * Your FrontMiddleBackQueue object will be instantiated and called as such:\n * obj := Constructor();\n * obj.PushFront(val);\n * obj.PushMiddle(val);\n * obj.PushBack(val);\n * param_4 := obj.PopFront();\n * param_5 := obj.PopMiddle();\n * param_6 := obj.PopBack();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class FrontMiddleBackQueue() {\n\n def pushFront(`val`: Int) {\n \n }\n\n def pushMiddle(`val`: Int) {\n \n }\n\n def pushBack(`val`: Int) {\n \n }\n\n def popFront(): Int = {\n \n }\n\n def popMiddle(): Int = {\n \n }\n\n def popBack(): Int = {\n \n }\n\n}\n\n/**\n * Your FrontMiddleBackQueue object will be instantiated and called as such:\n * var obj = new FrontMiddleBackQueue()\n * obj.pushFront(`val`)\n * obj.pushMiddle(`val`)\n * obj.pushBack(`val`)\n * var param_4 = obj.popFront()\n * var param_5 = obj.popMiddle()\n * var param_6 = obj.popBack()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class FrontMiddleBackQueue() {\n\n fun pushFront(`val`: Int) {\n\n }\n\n fun pushMiddle(`val`: Int) {\n\n }\n\n fun pushBack(`val`: Int) {\n\n }\n\n fun popFront(): Int {\n\n }\n\n fun popMiddle(): Int {\n\n }\n\n fun popBack(): Int {\n\n }\n\n}\n\n/**\n * Your FrontMiddleBackQueue object will be instantiated and called as such:\n * var obj = FrontMiddleBackQueue()\n * obj.pushFront(`val`)\n * obj.pushMiddle(`val`)\n * obj.pushBack(`val`)\n * var param_4 = obj.popFront()\n * var param_5 = obj.popMiddle()\n * var param_6 = obj.popBack()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct FrontMiddleBackQueue {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl FrontMiddleBackQueue {\n\n fn new() -> Self {\n\n }\n \n fn push_front(&self, val: i32) {\n\n }\n \n fn push_middle(&self, val: i32) {\n\n }\n \n fn push_back(&self, val: i32) {\n\n }\n \n fn pop_front(&self) -> i32 {\n\n }\n \n fn pop_middle(&self) -> i32 {\n\n }\n \n fn pop_back(&self) -> i32 {\n\n }\n}\n\n/**\n * Your FrontMiddleBackQueue object will be instantiated and called as such:\n * let obj = FrontMiddleBackQueue::new();\n * obj.push_front(val);\n * obj.push_middle(val);\n * obj.push_back(val);\n * let ret_4: i32 = obj.pop_front();\n * let ret_5: i32 = obj.pop_middle();\n * let ret_6: i32 = obj.pop_back();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class FrontMiddleBackQueue {\n /**\n */\n function __construct() {\n\n }\n\n /**\n * @param Integer $val\n * @return NULL\n */\n function pushFront($val) {\n\n }\n\n /**\n * @param Integer $val\n * @return NULL\n */\n function pushMiddle($val) {\n\n }\n\n /**\n * @param Integer $val\n * @return NULL\n */\n function pushBack($val) {\n\n }\n\n /**\n * @return Integer\n */\n function popFront() {\n\n }\n\n /**\n * @return Integer\n */\n function popMiddle() {\n\n }\n\n /**\n * @return Integer\n */\n function popBack() {\n\n }\n}\n\n/**\n * Your FrontMiddleBackQueue object will be instantiated and called as such:\n * $obj = FrontMiddleBackQueue();\n * $obj->pushFront($val);\n * $obj->pushMiddle($val);\n * $obj->pushBack($val);\n * $ret_4 = $obj->popFront();\n * $ret_5 = $obj->popMiddle();\n * $ret_6 = $obj->popBack();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class FrontMiddleBackQueue {\n constructor() {\n\n }\n\n pushFront(val: number): void {\n\n }\n\n pushMiddle(val: number): void {\n\n }\n\n pushBack(val: number): void {\n\n }\n\n popFront(): number {\n\n }\n\n popMiddle(): number {\n\n }\n\n popBack(): number {\n\n }\n}\n\n/**\n * Your FrontMiddleBackQueue object will be instantiated and called as such:\n * var obj = new FrontMiddleBackQueue()\n * obj.pushFront(val)\n * obj.pushMiddle(val)\n * obj.pushBack(val)\n * var param_4 = obj.popFront()\n * var param_5 = obj.popMiddle()\n * var param_6 = obj.popBack()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define front-middle-back-queue%\n (class object%\n (super-new)\n (init-field)\n \n ; push-front : exact-integer? -> void?\n (define/public (push-front val)\n\n )\n ; push-middle : exact-integer? -> void?\n (define/public (push-middle val)\n\n )\n ; push-back : exact-integer? -> void?\n (define/public (push-back val)\n\n )\n ; pop-front : -> exact-integer?\n (define/public (pop-front)\n\n )\n ; pop-middle : -> exact-integer?\n (define/public (pop-middle)\n\n )\n ; pop-back : -> exact-integer?\n (define/public (pop-back)\n\n )))\n\n;; Your front-middle-back-queue% object will be instantiated and called as such:\n;; (define obj (new front-middle-back-queue%))\n;; (send obj push-front val)\n;; (send obj push-middle val)\n;; (send obj push-back val)\n;; (define param_4 (send obj pop-front))\n;; (define param_5 (send obj pop-middle))\n;; (define param_6 (send obj pop-back))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1670](https://leetcode-cn.com/problems/design-front-middle-back-queue)", "[\u8bbe\u8ba1\u524d\u4e2d\u540e\u961f\u5217](/solution/1600-1699/1670.Design%20Front%20Middle%20Back%20Queue/README.md)", "`\u8bbe\u8ba1`,`\u94fe\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1670](https://leetcode.com/problems/design-front-middle-back-queue)", "[Design Front Middle Back Queue](/solution/1600-1699/1670.Design%20Front%20Middle%20Back%20Queue/README_EN.md)", "`Design`,`Linked List`", "Medium", ""]}, {"question_id": "1766", "frontend_question_id": "1671", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-number-of-removals-to-make-mountain-array", "url_en": "https://leetcode.com/problems/minimum-number-of-removals-to-make-mountain-array", "relative_path_cn": "/solution/1600-1699/1671.Minimum%20Number%20of%20Removals%20to%20Make%20Mountain%20Array/README.md", "relative_path_en": "/solution/1600-1699/1671.Minimum%20Number%20of%20Removals%20to%20Make%20Mountain%20Array/README_EN.md", "title_cn": "\u5f97\u5230\u5c71\u5f62\u6570\u7ec4\u7684\u6700\u5c11\u5220\u9664\u6b21\u6570", "title_en": "Minimum Number of Removals to Make Mountain Array", "question_title_slug": "minimum-number-of-removals-to-make-mountain-array", "content_en": "

    You may recall that an array arr is a mountain array if and only if:

    \n\n
      \n\t
    • arr.length >= 3
    • \n\t
    • There exists some index i (0-indexed) with 0 < i < arr.length - 1 such that:\n\t
        \n\t\t
      • arr[0] < arr[1] < ... < arr[i - 1] < arr[i]
      • \n\t\t
      • arr[i] > arr[i + 1] > ... > arr[arr.length - 1]
      • \n\t
      \n\t
    • \n
    \n\n

    Given an integer array nums\u200b\u200b\u200b, return the minimum number of elements to remove to make nums\u200b\u200b\u200b a mountain array.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,3,1]\nOutput: 0\nExplanation: The array itself is a mountain array so we do not need to remove any elements.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [2,1,1,5,6,2,3,1]\nOutput: 3\nExplanation: One solution is to remove the elements at indices 0, 1, and 5, making the array nums = [1,5,6,3,1].\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [4,3,2,1,1,2,3,1]\nOutput: 4\n
    \n\n

    Example 4:

    \n\n
    \nInput: nums = [1,2,3,4,4,3,2,1]\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 3 <= nums.length <= 1000
    • \n\t
    • 1 <= nums[i] <= 109
    • \n\t
    • It is guaranteed that you can make a mountain array out of nums.
    • \n
    \n", "content_cn": "

    \u6211\u4eec\u5b9a\u4e49\u00a0arr\u00a0\u662f \u5c71\u5f62\u6570\u7ec4\u00a0\u5f53\u4e14\u4ec5\u5f53\u5b83\u6ee1\u8db3\uff1a

    \n\n
      \n\t
    • arr.length >= 3
    • \n\t
    • \u5b58\u5728\u67d0\u4e2a\u4e0b\u6807\u00a0i\u00a0\uff08\u4ece 0 \u5f00\u59cb\uff09\u00a0\u6ee1\u8db3\u00a00 < i < arr.length - 1\u00a0\u4e14\uff1a\n\t
        \n\t\t
      • arr[0] < arr[1] < ... < arr[i - 1] < arr[i]
      • \n\t\t
      • arr[i] > arr[i + 1] > ... > arr[arr.length - 1]
      • \n\t
      \n\t
    • \n
    \n\n

    \u7ed9\u4f60\u6574\u6570\u6570\u7ec4\u00a0nums\u200b \uff0c\u8bf7\u4f60\u8fd4\u56de\u5c06 nums\u00a0\u53d8\u6210 \u5c71\u5f62\u72b6\u6570\u7ec4\u00a0\u7684\u200b \u6700\u5c11\u00a0\u5220\u9664\u6b21\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,3,1]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6570\u7ec4\u672c\u8eab\u5c31\u662f\u5c71\u5f62\u6570\u7ec4\uff0c\u6240\u4ee5\u6211\u4eec\u4e0d\u9700\u8981\u5220\u9664\u4efb\u4f55\u5143\u7d20\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [2,1,1,5,6,2,3,1]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u4e00\u79cd\u65b9\u6cd5\u662f\u5c06\u4e0b\u6807\u4e3a 0\uff0c1 \u548c 5 \u7684\u5143\u7d20\u5220\u9664\uff0c\u5269\u4f59\u5143\u7d20\u4e3a [1,5,6,3,1] \uff0c\u662f\u5c71\u5f62\u6570\u7ec4\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [4,3,2,1,1,2,3,1]\n\u8f93\u51fa\uff1a4\n
    \n\n

    \u63d0\u793a\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,2,3,4,4,3,2,1]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 3 <= nums.length <= 1000
    • \n\t
    • 1 <= nums[i] <= 109
    • \n\t
    • \u9898\u76ee\u4fdd\u8bc1\u00a0nums \u5220\u9664\u4e00\u4e9b\u5143\u7d20\u540e\u4e00\u5b9a\u80fd\u5f97\u5230\u5c71\u5f62\u6570\u7ec4\u3002
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minimumMountainRemovals(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minimumMountainRemovals(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimumMountainRemovals(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimumMountainRemovals(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minimumMountainRemovals(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinimumMountainRemovals(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar minimumMountainRemovals = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef minimum_mountain_removals(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimumMountainRemovals(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimumMountainRemovals(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimumMountainRemovals(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimumMountainRemovals(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimum_mountain_removals(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function minimumMountainRemovals($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimumMountainRemovals(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimum-mountain-removals nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1671](https://leetcode-cn.com/problems/minimum-number-of-removals-to-make-mountain-array)", "[\u5f97\u5230\u5c71\u5f62\u6570\u7ec4\u7684\u6700\u5c11\u5220\u9664\u6b21\u6570](/solution/1600-1699/1671.Minimum%20Number%20of%20Removals%20to%20Make%20Mountain%20Array/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1671](https://leetcode.com/problems/minimum-number-of-removals-to-make-mountain-array)", "[Minimum Number of Removals to Make Mountain Array](/solution/1600-1699/1671.Minimum%20Number%20of%20Removals%20to%20Make%20Mountain%20Array/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1765", "frontend_question_id": "1669", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/merge-in-between-linked-lists", "url_en": "https://leetcode.com/problems/merge-in-between-linked-lists", "relative_path_cn": "/solution/1600-1699/1669.Merge%20In%20Between%20Linked%20Lists/README.md", "relative_path_en": "/solution/1600-1699/1669.Merge%20In%20Between%20Linked%20Lists/README_EN.md", "title_cn": "\u5408\u5e76\u4e24\u4e2a\u94fe\u8868", "title_en": "Merge In Between Linked Lists", "question_title_slug": "merge-in-between-linked-lists", "content_en": "

    You are given two linked lists: list1 and list2 of sizes n and m respectively.

    \n\n

    Remove list1's nodes from the ath node to the bth node, and put list2 in their place.

    \n\n

    The blue edges and nodes in the following figure incidate the result:

    \n\"\"\n

    Build the result list and return its head.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: list1 = [0,1,2,3,4,5], a = 3, b = 4, list2 = [1000000,1000001,1000002]\nOutput: [0,1,2,1000000,1000001,1000002,5]\nExplanation: We remove the nodes 3 and 4 and put the entire list2 in their place. The blue edges and nodes in the above figure indicate the result.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: list1 = [0,1,2,3,4,5,6], a = 2, b = 5, list2 = [1000000,1000001,1000002,1000003,1000004]\nOutput: [0,1,1000000,1000001,1000002,1000003,1000004,6]\nExplanation: The blue edges and nodes in the above figure indicate the result.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 3 <= list1.length <= 104
    • \n\t
    • 1 <= a <= b < list1.length - 1
    • \n\t
    • 1 <= list2.length <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u94fe\u8868\u00a0list1 \u548c\u00a0list2\u00a0\uff0c\u5b83\u4eec\u5305\u542b\u7684\u5143\u7d20\u5206\u522b\u4e3a\u00a0n \u4e2a\u548c\u00a0m \u4e2a\u3002

    \n\n

    \u8bf7\u4f60\u5c06\u00a0list1\u00a0\u4e2d\u7b2c\u00a0a\u00a0\u4e2a\u8282\u70b9\u5230\u7b2c\u00a0b\u00a0\u4e2a\u8282\u70b9\u5220\u9664\uff0c\u5e76\u5c06list2\u00a0\u63a5\u5728\u88ab\u5220\u9664\u8282\u70b9\u7684\u4f4d\u7f6e\u3002

    \n\n

    \u4e0b\u56fe\u4e2d\u84dd\u8272\u8fb9\u548c\u8282\u70b9\u5c55\u793a\u4e86\u64cd\u4f5c\u540e\u7684\u7ed3\u679c\uff1a

    \n\"\"\n

    \u8bf7\u4f60\u8fd4\u56de\u7ed3\u679c\u94fe\u8868\u7684\u5934\u6307\u9488\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1alist1 = [0,1,2,3,4,5], a = 3, b = 4, list2 = [1000000,1000001,1000002]\n\u8f93\u51fa\uff1a[0,1,2,1000000,1000001,1000002,5]\n\u89e3\u91ca\uff1a\u6211\u4eec\u5220\u9664 list1 \u4e2d\u7b2c\u4e09\u548c\u7b2c\u56db\u4e2a\u8282\u70b9\uff0c\u5e76\u5c06 list2 \u63a5\u5728\u8be5\u4f4d\u7f6e\u3002\u4e0a\u56fe\u4e2d\u84dd\u8272\u7684\u8fb9\u548c\u8282\u70b9\u4e3a\u7b54\u6848\u94fe\u8868\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1alist1 = [0,1,2,3,4,5,6], a = 2, b = 5, list2 = [1000000,1000001,1000002,1000003,1000004]\n\u8f93\u51fa\uff1a[0,1,1000000,1000001,1000002,1000003,1000004,6]\n\u89e3\u91ca\uff1a\u4e0a\u56fe\u4e2d\u84dd\u8272\u7684\u8fb9\u548c\u8282\u70b9\u4e3a\u7b54\u6848\u94fe\u8868\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 3 <= list1.length <= 104
    • \n\t
    • 1 <= a <= b < list1.length - 1
    • \n\t
    • 1 <= list2.length <= 104
    • \n
    \n", "tags_en": ["Linked List"], "tags_cn": ["\u94fe\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n ListNode* mergeInBetween(ListNode* list1, int a, int b, ListNode* list2) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public ListNode mergeInBetween(ListNode list1, int a, int b, ListNode list2) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def mergeInBetween(self, list1, a, b, list2):\n \"\"\"\n :type list1: ListNode\n :type a: int\n :type b: int\n :type list2: ListNode\n :rtype: ListNode\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def mergeInBetween(self, list1: ListNode, a: int, b: int, list2: ListNode) -> ListNode:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nstruct ListNode* mergeInBetween(struct ListNode* list1, int a, int b, struct ListNode* list2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public ListNode MergeInBetween(ListNode list1, int a, int b, ListNode list2) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} list1\n * @param {number} a\n * @param {number} b\n * @param {ListNode} list2\n * @return {ListNode}\n */\nvar mergeInBetween = function(list1, a, b, list2) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode} list1\n# @param {Integer} a\n# @param {Integer} b\n# @param {ListNode} list2\n# @return {ListNode}\ndef merge_in_between(list1, a, b, list2)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func mergeInBetween(_ list1: ListNode?, _ a: Int, _ b: Int, _ list2: ListNode?) -> ListNode? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc mergeInBetween(list1 *ListNode, a int, b int, list2 *ListNode) *ListNode {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def mergeInBetween(list1: ListNode, a: Int, b: Int, list2: ListNode): ListNode = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun mergeInBetween(list1: ListNode?, a: Int, b: Int, list2: ListNode?): ListNode? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n// \n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn merge_in_between(list1: Option>, a: i32, b: i32, list2: Option>) -> Option> {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $list1\n * @param Integer $a\n * @param Integer $b\n * @param ListNode $list2\n * @return ListNode\n */\n function mergeInBetween($list1, $a, $b, $list2) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction mergeInBetween(list1: ListNode | null, a: number, b: number, list2: ListNode | null): ListNode | null {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1669](https://leetcode-cn.com/problems/merge-in-between-linked-lists)", "[\u5408\u5e76\u4e24\u4e2a\u94fe\u8868](/solution/1600-1699/1669.Merge%20In%20Between%20Linked%20Lists/README.md)", "`\u94fe\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1669](https://leetcode.com/problems/merge-in-between-linked-lists)", "[Merge In Between Linked Lists](/solution/1600-1699/1669.Merge%20In%20Between%20Linked%20Lists/README_EN.md)", "`Linked List`", "Medium", ""]}, {"question_id": "1764", "frontend_question_id": "1668", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-repeating-substring", "url_en": "https://leetcode.com/problems/maximum-repeating-substring", "relative_path_cn": "/solution/1600-1699/1668.Maximum%20Repeating%20Substring/README.md", "relative_path_en": "/solution/1600-1699/1668.Maximum%20Repeating%20Substring/README_EN.md", "title_cn": "\u6700\u5927\u91cd\u590d\u5b50\u5b57\u7b26\u4e32", "title_en": "Maximum Repeating Substring", "question_title_slug": "maximum-repeating-substring", "content_en": "

    For a string sequence, a string word is k-repeating if word concatenated k times is a substring of sequence. The word's maximum k-repeating value is the highest value k where word is k-repeating in sequence. If word is not a substring of sequence, word's maximum k-repeating value is 0.

    \n\n

    Given strings sequence and word, return the maximum k-repeating value of word in sequence.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: sequence = "ababc", word = "ab"\nOutput: 2\nExplanation: "abab" is a substring in "ababc".\n
    \n\n

    Example 2:

    \n\n
    \nInput: sequence = "ababc", word = "ba"\nOutput: 1\nExplanation: "ba" is a substring in "ababc". "baba" is not a substring in "ababc".\n
    \n\n

    Example 3:

    \n\n
    \nInput: sequence = "ababc", word = "ac"\nOutput: 0\nExplanation: "ac" is not a substring in "ababc". \n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= sequence.length <= 100
    • \n\t
    • 1 <= word.length <= 100
    • \n\t
    • sequence and word contains only lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32\u00a0sequence\u00a0\uff0c\u5982\u679c\u5b57\u7b26\u4e32 word\u00a0\u8fde\u7eed\u91cd\u590d\u00a0k\u00a0\u6b21\u5f62\u6210\u7684\u5b57\u7b26\u4e32\u662f\u00a0sequence\u00a0\u7684\u4e00\u4e2a\u5b50\u5b57\u7b26\u4e32\uff0c\u90a3\u4e48\u5355\u8bcd\u00a0word \u7684 \u91cd\u590d\u503c\u4e3a k \u3002\u5355\u8bcd word\u00a0\u7684 \u6700\u5927\u91cd\u590d\u503c\u00a0\u662f\u5355\u8bcd\u00a0word\u00a0\u5728\u00a0sequence\u00a0\u4e2d\u6700\u5927\u7684\u91cd\u590d\u503c\u3002\u5982\u679c\u00a0word\u00a0\u4e0d\u662f\u00a0sequence\u00a0\u7684\u5b50\u4e32\uff0c\u90a3\u4e48\u91cd\u590d\u503c\u00a0k\u00a0\u4e3a 0 \u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 sequence\u00a0\u548c word\u00a0\uff0c\u8bf7\u4f60\u8fd4\u56de \u6700\u5927\u91cd\u590d\u503c\u00a0k \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1asequence = \"ababc\", word = \"ab\"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\"abab\" \u662f \"ababc\" \u7684\u5b50\u5b57\u7b26\u4e32\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1asequence = \"ababc\", word = \"ba\"\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\"ba\" \u662f \"ababc\" \u7684\u5b50\u5b57\u7b26\u4e32\uff0c\u4f46 \"baba\" \u4e0d\u662f \"ababc\" \u7684\u5b50\u5b57\u7b26\u4e32\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1asequence = \"ababc\", word = \"ac\"\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\"ac\" \u4e0d\u662f \"ababc\" \u7684\u5b50\u5b57\u7b26\u4e32\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= sequence.length <= 100
    • \n\t
    • 1 <= word.length <= 100
    • \n\t
    • sequence \u548c\u00a0word\u00a0\u90fd\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxRepeating(string sequence, string word) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxRepeating(String sequence, String word) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxRepeating(self, sequence, word):\n \"\"\"\n :type sequence: str\n :type word: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxRepeating(self, sequence: str, word: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxRepeating(char * sequence, char * word){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxRepeating(string sequence, string word) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} sequence\n * @param {string} word\n * @return {number}\n */\nvar maxRepeating = function(sequence, word) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} sequence\n# @param {String} word\n# @return {Integer}\ndef max_repeating(sequence, word)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxRepeating(_ sequence: String, _ word: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxRepeating(sequence string, word string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxRepeating(sequence: String, word: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxRepeating(sequence: String, word: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_repeating(sequence: String, word: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $sequence\n * @param String $word\n * @return Integer\n */\n function maxRepeating($sequence, $word) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxRepeating(sequence: string, word: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-repeating sequence word)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1668](https://leetcode-cn.com/problems/maximum-repeating-substring)", "[\u6700\u5927\u91cd\u590d\u5b50\u5b57\u7b26\u4e32](/solution/1600-1699/1668.Maximum%20Repeating%20Substring/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1668](https://leetcode.com/problems/maximum-repeating-substring)", "[Maximum Repeating Substring](/solution/1600-1699/1668.Maximum%20Repeating%20Substring/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1763", "frontend_question_id": "1623", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/all-valid-triplets-that-can-represent-a-country", "url_en": "https://leetcode.com/problems/all-valid-triplets-that-can-represent-a-country", "relative_path_cn": "/solution/1600-1699/1623.All%20Valid%20Triplets%20That%20Can%20Represent%20a%20Country/README.md", "relative_path_en": "/solution/1600-1699/1623.All%20Valid%20Triplets%20That%20Can%20Represent%20a%20Country/README_EN.md", "title_cn": "\u4e09\u4eba\u56fd\u5bb6\u4ee3\u8868\u961f", "title_en": "All Valid Triplets That Can Represent a Country", "question_title_slug": "all-valid-triplets-that-can-represent-a-country", "content_en": "

    Table: SchoolA

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| student_id    | int     |\n| student_name  | varchar |\n+---------------+---------+\nstudent_id is the primary key for this table.\nEach row of this table contains the name and the id of a student in school A.\nAll student_name are distinct.\n
    \n\n

     

    \n\n

    Table: SchoolB

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| student_id    | int     |\n| student_name  | varchar |\n+---------------+---------+\nstudent_id is the primary key for this table.\nEach row of this table contains the name and the id of a student in school B.\nAll student_name are distinct.\n
    \n\n

     

    \n\n

    Table: SchoolC

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| student_id    | int     |\n| student_name  | varchar |\n+---------------+---------+\nstudent_id is the primary key for this table.\nEach row of this table contains the name and the id of a student in school C.\nAll student_name are distinct.\n
    \n\n

     

    \n\n

    There is a country with three schools, where each student is enrolled in exactly one school. The country is joining a competition and wants to select one student from each school to represent the country such that:

    \n\n
      \n\t
    • member_A is selected from SchoolA,
    • \n\t
    • member_B is selected from SchoolB,
    • \n\t
    • member_C is selected from SchoolC, and
    • \n\t
    • The selected students' names and IDs are pairwise distinct (i.e. no two students share the same name, and no two students share the same ID).
    • \n
    \n\n

    Write an SQL query to find all the possible triplets representing the country under the given constraints.

    \n\n

    Return the result table in any order.

    \n\n

    The query result format is in the following example.

    \n\n

     

    \n\n
    \nSchoolA table:\n+------------+--------------+\n| student_id | student_name |\n+------------+--------------+\n| 1          | Alice        |\n| 2          | Bob          |\n+------------+--------------+\n\nSchoolB table:\n+------------+--------------+\n| student_id | student_name |\n+------------+--------------+\n| 3          | Tom          |\n+------------+--------------+\n\nSchoolC table:\n+------------+--------------+\n| student_id | student_name |\n+------------+--------------+\n| 3          | Tom          |\n| 2          | Jerry        |\n| 10         | Alice        |\n+------------+--------------+\n\nResult table:\n+----------+----------+----------+\n| member_A | member_B | member_C |\n+----------+----------+----------+\n| Alice    | Tom      | Jerry    |\n| Bob      | Tom      | Alice    |\n+----------+----------+----------+\nLet us see all the possible triplets.\n- (Alice, Tom, Tom) --> Rejected because member_B and member_C have the same name and the same ID.\n- (Alice, Tom, Jerry) --> Valid triplet.\n- (Alice, Tom, Alice) --> Rejected because member_A and member_C have the same name.\n- (Bob, Tom, Tom) --> Rejected because member_B and member_C have the same name and the same ID.\n- (Bob, Tom, Jerry) --> Rejected because member_A and member_C have the same ID.\n- (Bob, Tom, Alice) --> Valid triplet.\n
    \n", "content_cn": "

    \u8868: SchoolA

    \n\n
    +---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| student_id    | int     |\n| student_name  | varchar |\n+---------------+---------+\nstudent_id \u662f\u8868\u7684\u4e3b\u952e\n\u8868\u4e2d\u7684\u6bcf\u4e00\u884c\u5305\u542b\u4e86\u5b66\u6821A\u4e2d\u6bcf\u4e00\u4e2a\u5b66\u751f\u7684\u540d\u5b57\u548cID\n\u6240\u6709student_name\u5728\u8868\u4e2d\u90fd\u662f\u72ec\u4e00\u65e0\u4e8c\u7684\n
    \n\n

    \u00a0

    \n\n

    \u8868: SchoolB

    \n\n
    +---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| student_id    | int     |\n| student_name  | varchar |\n+---------------+---------+\nstudent_id \u662f\u8868\u7684\u4e3b\u952e\n\u8868\u4e2d\u7684\u6bcf\u4e00\u884c\u5305\u542b\u4e86\u5b66\u6821B\u4e2d\u6bcf\u4e00\u4e2a\u5b66\u751f\u7684\u540d\u5b57\u548cID\n\u6240\u6709student_name\u5728\u8868\u4e2d\u90fd\u662f\u72ec\u4e00\u65e0\u4e8c\u7684\n
    \n\n

    \u00a0

    \n\n

    \u8868: SchoolC

    \n\n
    +---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| student_id    | int     |\n| student_name  | varchar |\n+---------------+---------+\nstudent_id \u662f\u8868\u7684\u4e3b\u952e\n\u8868\u4e2d\u7684\u6bcf\u4e00\u884c\u5305\u542b\u4e86\u5b66\u6821C\u4e2d\u6bcf\u4e00\u4e2a\u5b66\u751f\u7684\u540d\u5b57\u548cID\n\u6240\u6709student_name\u5728\u8868\u4e2d\u90fd\u662f\u72ec\u4e00\u65e0\u4e8c\u7684\n
    \n\n

    \u00a0

    \n\n

    \u6709\u4e00\u4e2a\u56fd\u5bb6\u53ea\u6709\u4e09\u6240\u5b66\u6821\uff0c\u8fd9\u4e2a\u56fd\u5bb6\u7684\u6bcf\u4e00\u4e2a\u5b66\u751f\u53ea\u4f1a\u6ce8\u518c\u4e00\u6240\u5b66\u6821\u3002

    \n\n

    \u8fd9\u4e2a\u56fd\u5bb6\u6b63\u5728\u53c2\u52a0\u4e00\u4e2a\u7ade\u8d5b\uff0c\u4ed6\u4eec\u5e0c\u671b\u4ece\u8fd9\u4e09\u6240\u5b66\u6821\u4e2d\u5404\u9009\u51fa\u4e00\u4e2a\u5b66\u751f\u6765\u7ec4\u5efa\u4e00\u652f\u4e09\u4eba\u7684\u4ee3\u8868\u961f\u3002

    \n\n

    \u4f8b\u5982\uff1a

    \n\n
      \n\t
    • member_A\u662f\u4ece SchoolA\u4e2d\u9009\u51fa\u7684
    • \n\t
    • member_B\u662f\u4ece SchoolB\u4e2d\u9009\u51fa\u7684
    • \n\t
    • member_C\u662f\u4ece SchoolC\u4e2d\u9009\u51fa\u7684
    • \n\t
    • \u88ab\u9009\u4e2d\u7684\u5b66\u751f\u5177\u6709\u4e0d\u540c\u7684\u540d\u5b57\u548cID\uff08\u6ca1\u6709\u4efb\u4f55\u4e24\u4e2a\u5b66\u751f\u62e5\u6709\u76f8\u540c\u7684\u540d\u5b57\u3001\u6ca1\u6709\u4efb\u4f55\u4e24\u4e2a\u5b66\u751f\u62e5\u6709\u76f8\u540c\u7684ID\uff09
    • \n
    \n\n

    \u4f7f\u7528\u4e0a\u8ff0\u6761\u4ef6\uff0c\u7f16\u5199SQL\u67e5\u8be2\u8bed\u53e5\u6765\u627e\u5230\u6240\u6709\u53ef\u80fd\u7684\u4e09\u4eba\u56fd\u5bb6\u4ee3\u8868\u961f\u7ec4\u5408\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u63a5\u53d7\u4efb\u4f55\u987a\u5e8f\u3002

    \n\n

    \u00a0

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u6837\u4f8b\uff1a

    \n\n
    SchoolA table:\n+------------+--------------+\n| student_id | student_name |\n+------------+--------------+\n| 1          | Alice        |\n| 2          | Bob          |\n+------------+--------------+\n\nSchoolB table:\n+------------+--------------+\n| student_id | student_name |\n+------------+--------------+\n| 3          | Tom          |\n+------------+--------------+\n\nSchoolC table:\n+------------+--------------+\n| student_id | student_name |\n+------------+--------------+\n| 3          | Tom          |\n| 2          | Jerry        |\n| 10         | Alice        |\n+------------+--------------+\n\n\u9884\u671f\u7ed3\u679c:\n+----------+----------+----------+\n| member_A | member_B | member_C |\n+----------+----------+----------+\n| Alice    | Tom      | Jerry    |\n| Bob      | Tom      | Alice    |\n+----------+----------+----------+\n\n\u8ba9\u6211\u4eec\u770b\u770b\u6709\u54ea\u4e9b\u53ef\u80fd\u7684\u7ec4\u5408\uff1a\n- (Alice, Tom, Tom) --> \u4e0d\u9002\u7528\uff0c\u56e0\u4e3amember_B\uff08Tom\uff09\u548cmember_C\uff08Tom\uff09\u6709\u76f8\u540c\u7684\u540d\u5b57\u548cID\n- (Alice, Tom, Jerry) --> \u53ef\u80fd\u7684\u7ec4\u5408\n- (Alice, Tom, Alice) --> \u4e0d\u9002\u7528\uff0c\u56e0\u4e3amember_A\u548cmember_C\u6709\u76f8\u540c\u7684\u540d\u5b57\n- (Bob, Tom, Tom) --> \u4e0d\u9002\u7528\uff0c\u56e0\u4e3amember_B\u548cmember_C\u6709\u76f8\u540c\u7684\u540d\u5b57\u548cID\n- (Bob, Tom, Jerry) --> \u4e0d\u9002\u7528\uff0c\u56e0\u4e3amember_A\u548cmember_C\u6709\u76f8\u540c\u7684ID\n- (Bob, Tom, Alice) --> \u53ef\u80fd\u7684\u7ec4\u5408.\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1623](https://leetcode-cn.com/problems/all-valid-triplets-that-can-represent-a-country)", "[\u4e09\u4eba\u56fd\u5bb6\u4ee3\u8868\u961f](/solution/1600-1699/1623.All%20Valid%20Triplets%20That%20Can%20Represent%20a%20Country/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1623](https://leetcode.com/problems/all-valid-triplets-that-can-represent-a-country)", "[All Valid Triplets That Can Represent a Country](/solution/1600-1699/1623.All%20Valid%20Triplets%20That%20Can%20Represent%20a%20Country/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1762", "frontend_question_id": "1642", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/furthest-building-you-can-reach", "url_en": "https://leetcode.com/problems/furthest-building-you-can-reach", "relative_path_cn": "/solution/1600-1699/1642.Furthest%20Building%20You%20Can%20Reach/README.md", "relative_path_en": "/solution/1600-1699/1642.Furthest%20Building%20You%20Can%20Reach/README_EN.md", "title_cn": "\u53ef\u4ee5\u5230\u8fbe\u7684\u6700\u8fdc\u5efa\u7b51", "title_en": "Furthest Building You Can Reach", "question_title_slug": "furthest-building-you-can-reach", "content_en": "

    You are given an integer array heights representing the heights of buildings, some bricks, and some ladders.

    \n\n

    You start your journey from building 0 and move to the next building by possibly using bricks or ladders.

    \n\n

    While moving from building i to building i+1 (0-indexed),

    \n\n
      \n\t
    • If the current building's height is greater than or equal to the next building's height, you do not need a ladder or bricks.
    • \n\t
    • If the current building's height is less than the next building's height, you can either use one ladder or (h[i+1] - h[i]) bricks.
    • \n
    \n\n

    Return the furthest building index (0-indexed) you can reach if you use the given ladders and bricks optimally.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: heights = [4,2,7,6,9,14,12], bricks = 5, ladders = 1\nOutput: 4\nExplanation: Starting at building 0, you can follow these steps:\n- Go to building 1 without using ladders nor bricks since 4 >= 2.\n- Go to building 2 using 5 bricks. You must use either bricks or ladders because 2 < 7.\n- Go to building 3 without using ladders nor bricks since 7 >= 6.\n- Go to building 4 using your only ladder. You must use either bricks or ladders because 6 < 9.\nIt is impossible to go beyond building 4 because you do not have any more bricks or ladders.\n
    \n\n

    Example 2:

    \n\n
    \nInput: heights = [4,12,2,7,3,18,20,3,19], bricks = 10, ladders = 2\nOutput: 7\n
    \n\n

    Example 3:

    \n\n
    \nInput: heights = [14,3,19,3], bricks = 17, ladders = 0\nOutput: 3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= heights.length <= 105
    • \n\t
    • 1 <= heights[i] <= 106
    • \n\t
    • 0 <= bricks <= 109
    • \n\t
    • 0 <= ladders <= heights.length
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 heights \uff0c\u8868\u793a\u5efa\u7b51\u7269\u7684\u9ad8\u5ea6\u3002\u53e6\u6709\u4e00\u4e9b\u7816\u5757 bricks \u548c\u68af\u5b50 ladders \u3002

    \n\n

    \u4f60\u4ece\u5efa\u7b51\u7269 0 \u5f00\u59cb\u65c5\u7a0b\uff0c\u4e0d\u65ad\u5411\u540e\u9762\u7684\u5efa\u7b51\u7269\u79fb\u52a8\uff0c\u671f\u95f4\u53ef\u80fd\u4f1a\u7528\u5230\u7816\u5757\u6216\u68af\u5b50\u3002

    \n\n

    \u5f53\u4ece\u5efa\u7b51\u7269 i \u79fb\u52a8\u5230\u5efa\u7b51\u7269 i+1\uff08\u4e0b\u6807 \u4ece 0 \u5f00\u59cb \uff09\u65f6\uff1a

    \n\n
      \n\t
    • \u5982\u679c\u5f53\u524d\u5efa\u7b51\u7269\u7684\u9ad8\u5ea6 \u5927\u4e8e\u6216\u7b49\u4e8e \u4e0b\u4e00\u5efa\u7b51\u7269\u7684\u9ad8\u5ea6\uff0c\u5219\u4e0d\u9700\u8981\u68af\u5b50\u6216\u7816\u5757
    • \n\t
    • \u5982\u679c\u5f53\u524d\u5efa\u7b51\u7684\u9ad8\u5ea6 \u5c0f\u4e8e \u4e0b\u4e00\u4e2a\u5efa\u7b51\u7684\u9ad8\u5ea6\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 \u4e00\u67b6\u68af\u5b50 \u6216 (h[i+1] - h[i]) \u4e2a\u7816\u5757
    • \n
    \n\u5982\u679c\u4ee5\u6700\u4f73\u65b9\u5f0f\u4f7f\u7528\u7ed9\u5b9a\u7684\u68af\u5b50\u548c\u7816\u5757\uff0c\u8fd4\u56de\u4f60\u53ef\u4ee5\u5230\u8fbe\u7684\u6700\u8fdc\u5efa\u7b51\u7269\u7684\u4e0b\u6807\uff08\u4e0b\u6807 \u4ece 0 \u5f00\u59cb \uff09\u3002\n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aheights = [4,2,7,6,9,14,12], bricks = 5, ladders = 1\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u4ece\u5efa\u7b51\u7269 0 \u51fa\u53d1\uff0c\u4f60\u53ef\u4ee5\u6309\u6b64\u65b9\u6848\u5b8c\u6210\u65c5\u7a0b\uff1a\n- \u4e0d\u4f7f\u7528\u7816\u5757\u6216\u68af\u5b50\u5230\u8fbe\u5efa\u7b51\u7269 1 \uff0c\u56e0\u4e3a 4 >= 2\n- \u4f7f\u7528 5 \u4e2a\u7816\u5757\u5230\u8fbe\u5efa\u7b51\u7269 2 \u3002\u4f60\u5fc5\u987b\u4f7f\u7528\u7816\u5757\u6216\u68af\u5b50\uff0c\u56e0\u4e3a 2 < 7\n- \u4e0d\u4f7f\u7528\u7816\u5757\u6216\u68af\u5b50\u5230\u8fbe\u5efa\u7b51\u7269 3 \uff0c\u56e0\u4e3a 7 >= 6\n- \u4f7f\u7528\u552f\u4e00\u7684\u68af\u5b50\u5230\u8fbe\u5efa\u7b51\u7269 4 \u3002\u4f60\u5fc5\u987b\u4f7f\u7528\u7816\u5757\u6216\u68af\u5b50\uff0c\u56e0\u4e3a 6 < 9\n\u65e0\u6cd5\u8d8a\u8fc7\u5efa\u7b51\u7269 4 \uff0c\u56e0\u4e3a\u6ca1\u6709\u66f4\u591a\u7816\u5757\u6216\u68af\u5b50\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aheights = [4,12,2,7,3,18,20,3,19], bricks = 10, ladders = 2\n\u8f93\u51fa\uff1a7\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aheights = [14,3,19,3], bricks = 17, ladders = 0\n\u8f93\u51fa\uff1a3\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= heights.length <= 105
    • \n\t
    • 1 <= heights[i] <= 106
    • \n\t
    • 0 <= bricks <= 109
    • \n\t
    • 0 <= ladders <= heights.length
    • \n
    \n", "tags_en": ["Heap", "Binary Search"], "tags_cn": ["\u5806", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int furthestBuilding(vector& heights, int bricks, int ladders) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int furthestBuilding(int[] heights, int bricks, int ladders) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def furthestBuilding(self, heights, bricks, ladders):\n \"\"\"\n :type heights: List[int]\n :type bricks: int\n :type ladders: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def furthestBuilding(self, heights: List[int], bricks: int, ladders: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint furthestBuilding(int* heights, int heightsSize, int bricks, int ladders){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FurthestBuilding(int[] heights, int bricks, int ladders) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} heights\n * @param {number} bricks\n * @param {number} ladders\n * @return {number}\n */\nvar furthestBuilding = function(heights, bricks, ladders) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} heights\n# @param {Integer} bricks\n# @param {Integer} ladders\n# @return {Integer}\ndef furthest_building(heights, bricks, ladders)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func furthestBuilding(_ heights: [Int], _ bricks: Int, _ ladders: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func furthestBuilding(heights []int, bricks int, ladders int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def furthestBuilding(heights: Array[Int], bricks: Int, ladders: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun furthestBuilding(heights: IntArray, bricks: Int, ladders: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn furthest_building(heights: Vec, bricks: i32, ladders: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $heights\n * @param Integer $bricks\n * @param Integer $ladders\n * @return Integer\n */\n function furthestBuilding($heights, $bricks, $ladders) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function furthestBuilding(heights: number[], bricks: number, ladders: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (furthest-building heights bricks ladders)\n (-> (listof exact-integer?) exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1642](https://leetcode-cn.com/problems/furthest-building-you-can-reach)", "[\u53ef\u4ee5\u5230\u8fbe\u7684\u6700\u8fdc\u5efa\u7b51](/solution/1600-1699/1642.Furthest%20Building%20You%20Can%20Reach/README.md)", "`\u5806`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1642](https://leetcode.com/problems/furthest-building-you-can-reach)", "[Furthest Building You Can Reach](/solution/1600-1699/1642.Furthest%20Building%20You%20Can%20Reach/README_EN.md)", "`Heap`,`Binary Search`", "Medium", ""]}, {"question_id": "1761", "frontend_question_id": "1641", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-sorted-vowel-strings", "url_en": "https://leetcode.com/problems/count-sorted-vowel-strings", "relative_path_cn": "/solution/1600-1699/1641.Count%20Sorted%20Vowel%20Strings/README.md", "relative_path_en": "/solution/1600-1699/1641.Count%20Sorted%20Vowel%20Strings/README_EN.md", "title_cn": "\u7edf\u8ba1\u5b57\u5178\u5e8f\u5143\u97f3\u5b57\u7b26\u4e32\u7684\u6570\u76ee", "title_en": "Count Sorted Vowel Strings", "question_title_slug": "count-sorted-vowel-strings", "content_en": "

    Given an integer n, return the number of strings of length n that consist only of vowels (a, e, i, o, u) and are lexicographically sorted.

    \n\n

    A string s is lexicographically sorted if for all valid i, s[i] is the same as or comes before s[i+1] in the alphabet.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 1\nOutput: 5\nExplanation: The 5 sorted strings that consist of vowels only are ["a","e","i","o","u"].\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 2\nOutput: 15\nExplanation: The 15 sorted strings that consist of vowels only are\n["aa","ae","ai","ao","au","ee","ei","eo","eu","ii","io","iu","oo","ou","uu"].\nNote that "ea" is not a valid string since 'e' comes after 'a' in the alphabet.\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 33\nOutput: 66045\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 50 
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n\uff0c\u8bf7\u8fd4\u56de\u957f\u5ea6\u4e3a n \u3001\u4ec5\u7531\u5143\u97f3 (a, e, i, o, u) \u7ec4\u6210\u4e14\u6309 \u5b57\u5178\u5e8f\u6392\u5217 \u7684\u5b57\u7b26\u4e32\u6570\u91cf\u3002

    \n\n

    \u5b57\u7b26\u4e32 s \u6309 \u5b57\u5178\u5e8f\u6392\u5217 \u9700\u8981\u6ee1\u8db3\uff1a\u5bf9\u4e8e\u6240\u6709\u6709\u6548\u7684 i\uff0cs[i] \u5728\u5b57\u6bcd\u8868\u4e2d\u7684\u4f4d\u7f6e\u603b\u662f\u4e0e s[i+1] \u76f8\u540c\u6216\u5728 s[i+1] \u4e4b\u524d\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u4ec5\u7531\u5143\u97f3\u7ec4\u6210\u7684 5 \u4e2a\u5b57\u5178\u5e8f\u5b57\u7b26\u4e32\u4e3a [\"a\",\"e\",\"i\",\"o\",\"u\"]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 2\n\u8f93\u51fa\uff1a15\n\u89e3\u91ca\uff1a\u4ec5\u7531\u5143\u97f3\u7ec4\u6210\u7684 15 \u4e2a\u5b57\u5178\u5e8f\u5b57\u7b26\u4e32\u4e3a\n[\"aa\",\"ae\",\"ai\",\"ao\",\"au\",\"ee\",\"ei\",\"eo\",\"eu\",\"ii\",\"io\",\"iu\",\"oo\",\"ou\",\"uu\"]\n\u6ce8\u610f\uff0c\"ea\" \u4e0d\u662f\u7b26\u5408\u9898\u610f\u7684\u5b57\u7b26\u4e32\uff0c\u56e0\u4e3a 'e' \u5728\u5b57\u6bcd\u8868\u4e2d\u7684\u4f4d\u7f6e\u6bd4 'a' \u9760\u540e\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 33\n\u8f93\u51fa\uff1a66045\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 50\u00a0
    • \n
    \n", "tags_en": ["Math", "Dynamic Programming", "Backtracking"], "tags_cn": ["\u6570\u5b66", "\u52a8\u6001\u89c4\u5212", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countVowelStrings(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countVowelStrings(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countVowelStrings(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countVowelStrings(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countVowelStrings(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountVowelStrings(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar countVowelStrings = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef count_vowel_strings(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countVowelStrings(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countVowelStrings(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countVowelStrings(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countVowelStrings(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_vowel_strings(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function countVowelStrings($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countVowelStrings(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-vowel-strings n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1641](https://leetcode-cn.com/problems/count-sorted-vowel-strings)", "[\u7edf\u8ba1\u5b57\u5178\u5e8f\u5143\u97f3\u5b57\u7b26\u4e32\u7684\u6570\u76ee](/solution/1600-1699/1641.Count%20Sorted%20Vowel%20Strings/README.md)", "`\u6570\u5b66`,`\u52a8\u6001\u89c4\u5212`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1641](https://leetcode.com/problems/count-sorted-vowel-strings)", "[Count Sorted Vowel Strings](/solution/1600-1699/1641.Count%20Sorted%20Vowel%20Strings/README_EN.md)", "`Math`,`Dynamic Programming`,`Backtracking`", "Medium", ""]}, {"question_id": "1760", "frontend_question_id": "1640", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/check-array-formation-through-concatenation", "url_en": "https://leetcode.com/problems/check-array-formation-through-concatenation", "relative_path_cn": "/solution/1600-1699/1640.Check%20Array%20Formation%20Through%20Concatenation/README.md", "relative_path_en": "/solution/1600-1699/1640.Check%20Array%20Formation%20Through%20Concatenation/README_EN.md", "title_cn": "\u80fd\u5426\u8fde\u63a5\u5f62\u6210\u6570\u7ec4", "title_en": "Check Array Formation Through Concatenation", "question_title_slug": "check-array-formation-through-concatenation", "content_en": "

    You are given an array of distinct integers arr and an array of integer arrays pieces, where the integers in pieces are distinct. Your goal is to form arr by concatenating the arrays in pieces in any order. However, you are not allowed to reorder the integers in each array pieces[i].

    \n\n

    Return true if it is possible to form the array arr from pieces. Otherwise, return false.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr = [85], pieces = [[85]]\nOutput: true\n
    \n\n

    Example 2:

    \n\n
    \nInput: arr = [15,88], pieces = [[88],[15]]\nOutput: true\nExplanation: Concatenate [15] then [88]\n
    \n\n

    Example 3:

    \n\n
    \nInput: arr = [49,18,16], pieces = [[16,18,49]]\nOutput: false\nExplanation: Even though the numbers match, we cannot reorder pieces[0].\n
    \n\n

    Example 4:

    \n\n
    \nInput: arr = [91,4,64,78], pieces = [[78],[4,64],[91]]\nOutput: true\nExplanation: Concatenate [91] then [4,64] then [78]
    \n\n

    Example 5:

    \n\n
    \nInput: arr = [1,3,5,7], pieces = [[2,4,6,8]]\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= pieces.length <= arr.length <= 100
    • \n\t
    • sum(pieces[i].length) == arr.length
    • \n\t
    • 1 <= pieces[i].length <= arr.length
    • \n\t
    • 1 <= arr[i], pieces[i][j] <= 100
    • \n\t
    • The integers in arr are distinct.
    • \n\t
    • The integers in pieces are distinct (i.e., If we flatten pieces in a 1D array, all the integers in this array are distinct).
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr \uff0c\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u6574\u6570 \u4e92\u4e0d\u76f8\u540c \u3002\u53e6\u6709\u4e00\u4e2a\u7531\u6574\u6570\u6570\u7ec4\u6784\u6210\u7684\u6570\u7ec4 pieces\uff0c\u5176\u4e2d\u7684\u6574\u6570\u4e5f \u4e92\u4e0d\u76f8\u540c \u3002\u8bf7\u4f60\u4ee5 \u4efb\u610f\u987a\u5e8f \u8fde\u63a5 pieces \u4e2d\u7684\u6570\u7ec4\u4ee5\u5f62\u6210 arr \u3002\u4f46\u662f\uff0c\u4e0d\u5141\u8bb8 \u5bf9\u6bcf\u4e2a\u6570\u7ec4 pieces[i] \u4e2d\u7684\u6574\u6570\u91cd\u65b0\u6392\u5e8f\u3002

    \n\n

    \u5982\u679c\u53ef\u4ee5\u8fde\u63a5 pieces \u4e2d\u7684\u6570\u7ec4\u5f62\u6210 arr \uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [85], pieces = [[85]]\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [15,88], pieces = [[88],[15]]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u4f9d\u6b21\u8fde\u63a5 [15] \u548c [88]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [49,18,16], pieces = [[16,18,49]]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u5373\u4fbf\u6570\u5b57\u76f8\u7b26\uff0c\u4e5f\u4e0d\u80fd\u91cd\u65b0\u6392\u5217 pieces[0]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [91,4,64,78], pieces = [[78],[4,64],[91]]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u4f9d\u6b21\u8fde\u63a5 [91]\u3001[4,64] \u548c [78]
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [1,3,5,7], pieces = [[2,4,6,8]]\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= pieces.length <= arr.length <= 100
    • \n\t
    • sum(pieces[i].length) == arr.length
    • \n\t
    • 1 <= pieces[i].length <= arr.length
    • \n\t
    • 1 <= arr[i], pieces[i][j] <= 100
    • \n\t
    • arr \u4e2d\u7684\u6574\u6570 \u4e92\u4e0d\u76f8\u540c
    • \n\t
    • pieces \u4e2d\u7684\u6574\u6570 \u4e92\u4e0d\u76f8\u540c\uff08\u4e5f\u5c31\u662f\u8bf4\uff0c\u5982\u679c\u5c06 pieces \u6241\u5e73\u5316\u6210\u4e00\u7ef4\u6570\u7ec4\uff0c\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u6574\u6570\u4e92\u4e0d\u76f8\u540c\uff09
    • \n
    \n", "tags_en": ["Sort", "Array", "Hash Table"], "tags_cn": ["\u6392\u5e8f", "\u6570\u7ec4", "\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canFormArray(vector& arr, vector>& pieces) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canFormArray(int[] arr, int[][] pieces) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canFormArray(self, arr, pieces):\n \"\"\"\n :type arr: List[int]\n :type pieces: List[List[int]]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canFormArray(self, arr: List[int], pieces: List[List[int]]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canFormArray(int* arr, int arrSize, int** pieces, int piecesSize, int* piecesColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanFormArray(int[] arr, int[][] pieces) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @param {number[][]} pieces\n * @return {boolean}\n */\nvar canFormArray = function(arr, pieces) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @param {Integer[][]} pieces\n# @return {Boolean}\ndef can_form_array(arr, pieces)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canFormArray(_ arr: [Int], _ pieces: [[Int]]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canFormArray(arr []int, pieces [][]int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canFormArray(arr: Array[Int], pieces: Array[Array[Int]]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canFormArray(arr: IntArray, pieces: Array): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_form_array(arr: Vec, pieces: Vec>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @param Integer[][] $pieces\n * @return Boolean\n */\n function canFormArray($arr, $pieces) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canFormArray(arr: number[], pieces: number[][]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-form-array arr pieces)\n (-> (listof exact-integer?) (listof (listof exact-integer?)) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1640](https://leetcode-cn.com/problems/check-array-formation-through-concatenation)", "[\u80fd\u5426\u8fde\u63a5\u5f62\u6210\u6570\u7ec4](/solution/1600-1699/1640.Check%20Array%20Formation%20Through%20Concatenation/README.md)", "`\u6392\u5e8f`,`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[1640](https://leetcode.com/problems/check-array-formation-through-concatenation)", "[Check Array Formation Through Concatenation](/solution/1600-1699/1640.Check%20Array%20Formation%20Through%20Concatenation/README_EN.md)", "`Sort`,`Array`,`Hash Table`", "Easy", ""]}, {"question_id": "1759", "frontend_question_id": "1613", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/find-the-missing-ids", "url_en": "https://leetcode.com/problems/find-the-missing-ids", "relative_path_cn": "/solution/1600-1699/1613.Find%20the%20Missing%20IDs/README.md", "relative_path_en": "/solution/1600-1699/1613.Find%20the%20Missing%20IDs/README_EN.md", "title_cn": "\u627e\u5230\u9057\u5931\u7684ID", "title_en": "Find the Missing IDs", "question_title_slug": "find-the-missing-ids", "content_en": "

    Table: Customers

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| customer_id   | int     |\n| customer_name | varchar |\n+---------------+---------+\ncustomer_id is the primary key for this table.\nEach row of this table contains the name and the id customer.\n
    \n\n

     

    \n\n

    Write an SQL query to find the missing customer IDs. The missing IDs are ones that are not in the Customers table but are in the range between 1 and the maximum customer_id present in the table.

    \n\n

    Notice that the maximum customer_id will not exceed 100.

    \n\n

    Return the result table ordered by ids in ascending order.

    \n\n

    The query result format is in the following example.

    \n\n

     

    \n\n
    \nCustomers table:\n+-------------+---------------+\n| customer_id | customer_name |\n+-------------+---------------+\n| 1           | Alice         |\n| 4           | Bob           |\n| 5           | Charlie       |\n+-------------+---------------+\n\nResult table:\n+-----+\n| ids |\n+-----+\n| 2   |\n| 3   |\n+-----+\nThe maximum customer_id present in the table is 5, so in the range [1,5], IDs 2 and 3 are missing from the table.
    \n", "content_cn": "

    \u8868: Customers

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| customer_id   | int     |\n| customer_name | varchar |\n+---------------+---------+\ncustomer_id \u662f\u8be5\u8868\u4e3b\u952e.\n\u8be5\u8868\u7b2c\u4e00\u884c\u5305\u542b\u4e86\u987e\u5ba2\u7684\u540d\u5b57\u548cid.\n
    \n\n

    \u00a0

    \n\n

    \u5199\u4e00\u4e2a SQL \u8bed\u53e5,\u00a0\u627e\u5230\u6240\u6709\u9057\u5931\u7684\u987e\u5ba2id.\u00a0\u9057\u5931\u7684\u987e\u5ba2id\u662f\u6307\u90a3\u4e9b\u4e0d\u5728\u00a0Customers\u00a0\u8868\u4e2d,\u00a0\u503c\u5374\u5904\u4e8e\u00a01\u00a0\u548c\u8868\u4e2d\u6700\u5927\u00a0customer_id\u00a0\u4e4b\u95f4\u7684id.

    \n\n

    \u6ce8\u610f:\u00a0\u6700\u5927\u7684\u00a0customer_id\u00a0\u503c\u4e0d\u4f1a\u8d85\u8fc7\u00a0100.

    \n\n

    \u8fd4\u56de\u7ed3\u679c\u6309\u00a0ids \u5347\u5e8f\u6392\u5217

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a.

    \n\n

    \u00a0

    \n\n
    \nCustomers \u8868:\n+-------------+---------------+\n| customer_id | customer_name |\n+-------------+---------------+\n| 1           | Alice         |\n| 4           | Bob           |\n| 5           | Charlie       |\n+-------------+---------------+\n\nResult \u8868:\n+-----+\n| ids |\n+-----+\n| 2   |\n| 3   |\n+-----+\n\u8868\u4e2d\u6700\u5927\u7684customer_id\u662f5, \u6240\u4ee5\u5728\u8303\u56f4[1,5]\u5185, ID2\u548c3\u4ece\u8868\u4e2d\u9057\u5931.
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1613](https://leetcode-cn.com/problems/find-the-missing-ids)", "[\u627e\u5230\u9057\u5931\u7684ID](/solution/1600-1699/1613.Find%20the%20Missing%20IDs/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1613](https://leetcode.com/problems/find-the-missing-ids)", "[Find the Missing IDs](/solution/1600-1699/1613.Find%20the%20Missing%20IDs/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1758", "frontend_question_id": "1655", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/distribute-repeating-integers", "url_en": "https://leetcode.com/problems/distribute-repeating-integers", "relative_path_cn": "/solution/1600-1699/1655.Distribute%20Repeating%20Integers/README.md", "relative_path_en": "/solution/1600-1699/1655.Distribute%20Repeating%20Integers/README_EN.md", "title_cn": "\u5206\u914d\u91cd\u590d\u6574\u6570", "title_en": "Distribute Repeating Integers", "question_title_slug": "distribute-repeating-integers", "content_en": "

    You are given an array of n integers, nums, where there are at most 50 unique values in the array. You are also given an array of m customer order quantities, quantity, where quantity[i] is the amount of integers the ith customer ordered. Determine if it is possible to distribute nums such that:

    \n\n
      \n\t
    • The ith customer gets exactly quantity[i] integers,
    • \n\t
    • The integers the ith customer gets are all equal, and
    • \n\t
    • Every customer is satisfied.
    • \n
    \n\n

    Return true if it is possible to distribute nums according to the above conditions.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,3,4], quantity = [2]\nOutput: false\nExplanation: The 0th customer cannot be given two different integers.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,2,3,3], quantity = [2]\nOutput: true\nExplanation: The 0th customer is given [3,3]. The integers [1,2] are not used.\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [1,1,2,2], quantity = [2,2]\nOutput: true\nExplanation: The 0th customer is given [1,1], and the 1st customer is given [2,2].\n
    \n\n

    Example 4:

    \n\n
    \nInput: nums = [1,1,2,3], quantity = [2,2]\nOutput: false\nExplanation: Although the 0th customer could be given [1,1], the 1st customer cannot be satisfied.
    \n\n

    Example 5:

    \n\n
    \nInput: nums = [1,1,1,1,1], quantity = [2,3]\nOutput: true\nExplanation: The 0th customer is given [1,1], and the 1st customer is given [1,1,1].\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= n <= 105
    • \n\t
    • 1 <= nums[i] <= 1000
    • \n\t
    • m == quantity.length
    • \n\t
    • 1 <= m <= 10
    • \n\t
    • 1 <= quantity[i] <= 105
    • \n\t
    • There are at most 50 unique values in nums.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u4e3a\u00a0n\u00a0\u7684\u6574\u6570\u6570\u7ec4\u00a0nums\u00a0\uff0c\u8fd9\u4e2a\u6570\u7ec4\u4e2d\u81f3\u591a\u6709\u00a050\u00a0\u4e2a\u4e0d\u540c\u7684\u503c\u3002\u540c\u65f6\u4f60\u6709 m\u00a0\u4e2a\u987e\u5ba2\u7684\u8ba2\u5355 quantity\u00a0\uff0c\u5176\u4e2d\uff0c\u6574\u6570\u00a0quantity[i]\u00a0\u662f\u7b2c\u00a0i\u00a0\u4f4d\u987e\u5ba2\u8ba2\u5355\u7684\u6570\u76ee\u3002\u8bf7\u4f60\u5224\u65ad\u662f\u5426\u80fd\u5c06 nums\u00a0\u4e2d\u7684\u6574\u6570\u5206\u914d\u7ed9\u8fd9\u4e9b\u987e\u5ba2\uff0c\u4e14\u6ee1\u8db3\uff1a

    \n\n
      \n\t
    • \u7b2c\u00a0i\u00a0\u4f4d\u987e\u5ba2 \u6070\u597d\u00a0\u6709\u00a0quantity[i]\u00a0\u4e2a\u6574\u6570\u3002
    • \n\t
    • \u7b2c\u00a0i\u00a0\u4f4d\u987e\u5ba2\u62ff\u5230\u7684\u6574\u6570\u90fd\u662f \u76f8\u540c\u7684\u00a0\u3002
    • \n\t
    • \u6bcf\u4f4d\u987e\u5ba2\u90fd\u6ee1\u8db3\u4e0a\u8ff0\u4e24\u4e2a\u8981\u6c42\u3002
    • \n
    \n\n

    \u5982\u679c\u4f60\u53ef\u4ee5\u5206\u914d nums\u00a0\u4e2d\u7684\u6574\u6570\u6ee1\u8db3\u4e0a\u9762\u7684\u8981\u6c42\uff0c\u90a3\u4e48\u8bf7\u8fd4\u56de\u00a0true\u00a0\uff0c\u5426\u5219\u8fd4\u56de false\u00a0\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,2,3,4], quantity = [2]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u7b2c 0 \u4f4d\u987e\u5ba2\u6ca1\u529e\u6cd5\u5f97\u5230\u4e24\u4e2a\u76f8\u540c\u7684\u6574\u6570\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,2,3,3], quantity = [2]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u7b2c 0 \u4f4d\u987e\u5ba2\u5f97\u5230 [3,3] \u3002\u6574\u6570 [1,2] \u90fd\u6ca1\u6709\u88ab\u4f7f\u7528\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,1,2,2], quantity = [2,2]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u7b2c 0 \u4f4d\u987e\u5ba2\u5f97\u5230 [1,1] \uff0c\u7b2c 1 \u4f4d\u987e\u5ba2\u5f97\u5230 [2,2] \u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,1,2,3], quantity = [2,2]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u5c3d\u7ba1\u7b2c 0 \u4f4d\u987e\u5ba2\u53ef\u4ee5\u5f97\u5230 [1,1] \uff0c\u7b2c 1 \u4f4d\u987e\u5ba2\u6ca1\u6cd5\u5f97\u5230 2 \u4e2a\u4e00\u6837\u7684\u6574\u6570\u3002
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,1,1,1,1], quantity = [2,3]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u7b2c 0 \u4f4d\u987e\u5ba2\u5f97\u5230 [1,1] \uff0c\u7b2c 1 \u4f4d\u987e\u5ba2\u5f97\u5230 [1,1,1] \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= n <= 105
    • \n\t
    • 1 <= nums[i] <= 1000
    • \n\t
    • m == quantity.length
    • \n\t
    • 1 <= m <= 10
    • \n\t
    • 1 <= quantity[i] <= 105
    • \n\t
    • nums\u00a0\u4e2d\u81f3\u591a\u6709\u00a050\u00a0\u4e2a\u4e0d\u540c\u7684\u6570\u5b57\u3002
    • \n
    \n", "tags_en": ["Dynamic Programming", "Backtracking"], "tags_cn": ["\u52a8\u6001\u89c4\u5212", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canDistribute(vector& nums, vector& quantity) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canDistribute(int[] nums, int[] quantity) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canDistribute(self, nums, quantity):\n \"\"\"\n :type nums: List[int]\n :type quantity: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canDistribute(self, nums: List[int], quantity: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canDistribute(int* nums, int numsSize, int* quantity, int quantitySize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanDistribute(int[] nums, int[] quantity) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number[]} quantity\n * @return {boolean}\n */\nvar canDistribute = function(nums, quantity) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer[]} quantity\n# @return {Boolean}\ndef can_distribute(nums, quantity)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canDistribute(_ nums: [Int], _ quantity: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canDistribute(nums []int, quantity []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canDistribute(nums: Array[Int], quantity: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canDistribute(nums: IntArray, quantity: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_distribute(nums: Vec, quantity: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer[] $quantity\n * @return Boolean\n */\n function canDistribute($nums, $quantity) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canDistribute(nums: number[], quantity: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-distribute nums quantity)\n (-> (listof exact-integer?) (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1655](https://leetcode-cn.com/problems/distribute-repeating-integers)", "[\u5206\u914d\u91cd\u590d\u6574\u6570](/solution/1600-1699/1655.Distribute%20Repeating%20Integers/README.md)", "`\u52a8\u6001\u89c4\u5212`,`\u56de\u6eaf\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[1655](https://leetcode.com/problems/distribute-repeating-integers)", "[Distribute Repeating Integers](/solution/1600-1699/1655.Distribute%20Repeating%20Integers/README_EN.md)", "`Dynamic Programming`,`Backtracking`", "Hard", ""]}, {"question_id": "1757", "frontend_question_id": "1654", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-jumps-to-reach-home", "url_en": "https://leetcode.com/problems/minimum-jumps-to-reach-home", "relative_path_cn": "/solution/1600-1699/1654.Minimum%20Jumps%20to%20Reach%20Home/README.md", "relative_path_en": "/solution/1600-1699/1654.Minimum%20Jumps%20to%20Reach%20Home/README_EN.md", "title_cn": "\u5230\u5bb6\u7684\u6700\u5c11\u8df3\u8dc3\u6b21\u6570", "title_en": "Minimum Jumps to Reach Home", "question_title_slug": "minimum-jumps-to-reach-home", "content_en": "

    A certain bug's home is on the x-axis at position x. Help them get there from position 0.

    \n\n

    The bug jumps according to the following rules:

    \n\n
      \n\t
    • It can jump exactly a positions forward (to the right).
    • \n\t
    • It can jump exactly b positions backward (to the left).
    • \n\t
    • It cannot jump backward twice in a row.
    • \n\t
    • It cannot jump to any forbidden positions.
    • \n
    \n\n

    The bug may jump forward beyond its home, but it cannot jump to positions numbered with negative integers.

    \n\n

    Given an array of integers forbidden, where forbidden[i] means that the bug cannot jump to the position forbidden[i], and integers a, b, and x, return the minimum number of jumps needed for the bug to reach its home. If there is no possible sequence of jumps that lands the bug on position x, return -1.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: forbidden = [14,4,18,1,15], a = 3, b = 15, x = 9\nOutput: 3\nExplanation: 3 jumps forward (0 -> 3 -> 6 -> 9) will get the bug home.\n
    \n\n

    Example 2:

    \n\n
    \nInput: forbidden = [8,3,16,6,12,20], a = 15, b = 13, x = 11\nOutput: -1\n
    \n\n

    Example 3:

    \n\n
    \nInput: forbidden = [1,6,2,14,5,17,4], a = 16, b = 9, x = 7\nOutput: 2\nExplanation: One jump forward (0 -> 16) then one jump backward (16 -> 7) will get the bug home.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= forbidden.length <= 1000
    • \n\t
    • 1 <= a, b, forbidden[i] <= 2000
    • \n\t
    • 0 <= x <= 2000
    • \n\t
    • All the elements in forbidden are distinct.
    • \n\t
    • Position x is not forbidden.
    • \n
    \n", "content_cn": "

    \u6709\u4e00\u53ea\u8df3\u86a4\u7684\u5bb6\u5728\u6570\u8f74\u4e0a\u7684\u4f4d\u7f6e\u00a0x\u00a0\u5904\u3002\u8bf7\u4f60\u5e2e\u52a9\u5b83\u4ece\u4f4d\u7f6e\u00a00\u00a0\u51fa\u53d1\uff0c\u5230\u8fbe\u5b83\u7684\u5bb6\u3002

    \n\n

    \u8df3\u86a4\u8df3\u8dc3\u7684\u89c4\u5219\u5982\u4e0b\uff1a

    \n\n
      \n\t
    • \u5b83\u53ef\u4ee5 \u5f80\u524d \u8df3\u6070\u597d a\u00a0\u4e2a\u4f4d\u7f6e\uff08\u5373\u5f80\u53f3\u8df3\uff09\u3002
    • \n\t
    • \u5b83\u53ef\u4ee5 \u5f80\u540e\u00a0\u8df3\u6070\u597d b\u00a0\u4e2a\u4f4d\u7f6e\uff08\u5373\u5f80\u5de6\u8df3\uff09\u3002
    • \n\t
    • \u5b83\u4e0d\u80fd \u8fde\u7eed \u5f80\u540e\u8df3 2 \u6b21\u3002
    • \n\t
    • \u5b83\u4e0d\u80fd\u8df3\u5230\u4efb\u4f55\u00a0forbidden\u00a0\u6570\u7ec4\u4e2d\u7684\u4f4d\u7f6e\u3002
    • \n
    \n\n

    \u8df3\u86a4\u53ef\u4ee5\u5f80\u524d\u8df3 \u8d85\u8fc7\u00a0\u5b83\u7684\u5bb6\u7684\u4f4d\u7f6e\uff0c\u4f46\u662f\u5b83 \u4e0d\u80fd\u8df3\u5230\u8d1f\u6574\u6570\u00a0\u7684\u4f4d\u7f6e\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0forbidden\u00a0\uff0c\u5176\u4e2d\u00a0forbidden[i]\u00a0\u662f\u8df3\u86a4\u4e0d\u80fd\u8df3\u5230\u7684\u4f4d\u7f6e\uff0c\u540c\u65f6\u7ed9\u4f60\u6574\u6570\u00a0a\uff0c\u00a0b\u00a0\u548c\u00a0x\u00a0\uff0c\u8bf7\u4f60\u8fd4\u56de\u8df3\u86a4\u5230\u5bb6\u7684\u6700\u5c11\u8df3\u8dc3\u6b21\u6570\u3002\u5982\u679c\u6ca1\u6709\u6070\u597d\u5230\u8fbe x\u00a0\u7684\u53ef\u884c\u65b9\u6848\uff0c\u8bf7\u4f60\u8fd4\u56de -1 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aforbidden = [14,4,18,1,15], a = 3, b = 15, x = 9\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u5f80\u524d\u8df3 3 \u6b21\uff080 -> 3 -> 6 -> 9\uff09\uff0c\u8df3\u86a4\u5c31\u5230\u5bb6\u4e86\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aforbidden = [8,3,16,6,12,20], a = 15, b = 13, x = 11\n\u8f93\u51fa\uff1a-1\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aforbidden = [1,6,2,14,5,17,4], a = 16, b = 9, x = 7\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5f80\u524d\u8df3\u4e00\u6b21\uff080 -> 16\uff09\uff0c\u7136\u540e\u5f80\u56de\u8df3\u4e00\u6b21\uff0816 -> 7\uff09\uff0c\u8df3\u86a4\u5c31\u5230\u5bb6\u4e86\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= forbidden.length <= 1000
    • \n\t
    • 1 <= a, b, forbidden[i] <= 2000
    • \n\t
    • 0 <= x <= 2000
    • \n\t
    • forbidden\u00a0\u4e2d\u6240\u6709\u4f4d\u7f6e\u4e92\u4e0d\u76f8\u540c\u3002
    • \n\t
    • \u4f4d\u7f6e\u00a0x\u00a0\u4e0d\u5728 forbidden\u00a0\u4e2d\u3002
    • \n
    \n", "tags_en": ["Breadth-first Search", "Dynamic Programming"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minimumJumps(vector& forbidden, int a, int b, int x) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minimumJumps(int[] forbidden, int a, int b, int x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimumJumps(self, forbidden, a, b, x):\n \"\"\"\n :type forbidden: List[int]\n :type a: int\n :type b: int\n :type x: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimumJumps(self, forbidden: List[int], a: int, b: int, x: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minimumJumps(int* forbidden, int forbiddenSize, int a, int b, int x){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinimumJumps(int[] forbidden, int a, int b, int x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} forbidden\n * @param {number} a\n * @param {number} b\n * @param {number} x\n * @return {number}\n */\nvar minimumJumps = function(forbidden, a, b, x) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} forbidden\n# @param {Integer} a\n# @param {Integer} b\n# @param {Integer} x\n# @return {Integer}\ndef minimum_jumps(forbidden, a, b, x)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimumJumps(_ forbidden: [Int], _ a: Int, _ b: Int, _ x: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimumJumps(forbidden []int, a int, b int, x int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimumJumps(forbidden: Array[Int], a: Int, b: Int, x: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimumJumps(forbidden: IntArray, a: Int, b: Int, x: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimum_jumps(forbidden: Vec, a: i32, b: i32, x: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $forbidden\n * @param Integer $a\n * @param Integer $b\n * @param Integer $x\n * @return Integer\n */\n function minimumJumps($forbidden, $a, $b, $x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimumJumps(forbidden: number[], a: number, b: number, x: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimum-jumps forbidden a b x)\n (-> (listof exact-integer?) exact-integer? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1654](https://leetcode-cn.com/problems/minimum-jumps-to-reach-home)", "[\u5230\u5bb6\u7684\u6700\u5c11\u8df3\u8dc3\u6b21\u6570](/solution/1600-1699/1654.Minimum%20Jumps%20to%20Reach%20Home/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1654](https://leetcode.com/problems/minimum-jumps-to-reach-home)", "[Minimum Jumps to Reach Home](/solution/1600-1699/1654.Minimum%20Jumps%20to%20Reach%20Home/README_EN.md)", "`Breadth-first Search`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "1756", "frontend_question_id": "1653", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-deletions-to-make-string-balanced", "url_en": "https://leetcode.com/problems/minimum-deletions-to-make-string-balanced", "relative_path_cn": "/solution/1600-1699/1653.Minimum%20Deletions%20to%20Make%20String%20Balanced/README.md", "relative_path_en": "/solution/1600-1699/1653.Minimum%20Deletions%20to%20Make%20String%20Balanced/README_EN.md", "title_cn": "\u4f7f\u5b57\u7b26\u4e32\u5e73\u8861\u7684\u6700\u5c11\u5220\u9664\u6b21\u6570", "title_en": "Minimum Deletions to Make String Balanced", "question_title_slug": "minimum-deletions-to-make-string-balanced", "content_en": "

    You are given a string s consisting only of characters 'a' and 'b'\u200b\u200b\u200b\u200b.

    \n\n

    You can delete any number of characters in s to make s balanced. s is balanced if there is no pair of indices (i,j) such that i < j and s[i] = 'b' and s[j]= 'a'.

    \n\n

    Return the minimum number of deletions needed to make s balanced.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "aababbab"\nOutput: 2\nExplanation: You can either:\nDelete the characters at 0-indexed positions 2 and 6 ("aababbab" -> "aaabbb"), or\nDelete the characters at 0-indexed positions 3 and 6 ("aababbab" -> "aabbbb").\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "bbaaaaabb"\nOutput: 2\nExplanation: The only solution is to delete the first two characters.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 105
    • \n\t
    • s[i] is 'a' or 'b'\u200b\u200b.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32\u00a0s\u00a0\uff0c\u5b83\u4ec5\u5305\u542b\u5b57\u7b26\u00a0'a' \u548c\u00a0'b'\u200b\u200b\u200b\u200b \u3002

    \n\n

    \u4f60\u53ef\u4ee5\u5220\u9664\u00a0s\u00a0\u4e2d\u4efb\u610f\u6570\u76ee\u7684\u5b57\u7b26\uff0c\u4f7f\u5f97\u00a0s \u5e73\u8861\u00a0\u3002\u6211\u4eec\u79f0\u00a0s\u00a0\u5e73\u8861\u7684\u00a0\u5f53\u4e0d\u5b58\u5728\u4e0b\u6807\u5bf9\u00a0(i,j)\u00a0\u6ee1\u8db3\u00a0i < j \u4e14\u00a0s[i] = 'b'\u00a0\u540c\u65f6\u00a0s[j]= 'a'\u00a0\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u4f7f s\u00a0\u5e73\u8861\u00a0\u7684 \u6700\u5c11\u00a0\u5220\u9664\u6b21\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"aababbab\"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u9009\u62e9\u4ee5\u4e0b\u4efb\u610f\u4e00\u79cd\u65b9\u6848\uff1a\n\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff0c\u5220\u9664\u7b2c 2 \u548c\u7b2c 6 \u4e2a\u5b57\u7b26\uff08\"aababbab\" -> \"aaabbb\"\uff09\uff0c\n\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff0c\u5220\u9664\u7b2c 3 \u548c\u7b2c 6 \u4e2a\u5b57\u7b26\uff08\"aababbab\" -> \"aabbbb\"\uff09\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"bbaaaaabb\"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u552f\u4e00\u7684\u6700\u4f18\u89e3\u662f\u5220\u9664\u6700\u524d\u9762\u4e24\u4e2a\u5b57\u7b26\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 105
    • \n\t
    • s[i]\u00a0\u8981\u4e48\u662f\u00a0'a' \u8981\u4e48\u662f\u00a0'b'\u200b\u00a0\u3002\u200b
    • \n
    \n", "tags_en": ["Greedy", "String"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minimumDeletions(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minimumDeletions(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimumDeletions(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimumDeletions(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minimumDeletions(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinimumDeletions(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar minimumDeletions = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef minimum_deletions(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimumDeletions(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimumDeletions(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimumDeletions(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimumDeletions(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimum_deletions(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function minimumDeletions($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimumDeletions(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimum-deletions s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1653](https://leetcode-cn.com/problems/minimum-deletions-to-make-string-balanced)", "[\u4f7f\u5b57\u7b26\u4e32\u5e73\u8861\u7684\u6700\u5c11\u5220\u9664\u6b21\u6570](/solution/1600-1699/1653.Minimum%20Deletions%20to%20Make%20String%20Balanced/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1653](https://leetcode.com/problems/minimum-deletions-to-make-string-balanced)", "[Minimum Deletions to Make String Balanced](/solution/1600-1699/1653.Minimum%20Deletions%20to%20Make%20String%20Balanced/README_EN.md)", "`Greedy`,`String`", "Medium", ""]}, {"question_id": "1755", "frontend_question_id": "1652", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/defuse-the-bomb", "url_en": "https://leetcode.com/problems/defuse-the-bomb", "relative_path_cn": "/solution/1600-1699/1652.Defuse%20the%20Bomb/README.md", "relative_path_en": "/solution/1600-1699/1652.Defuse%20the%20Bomb/README_EN.md", "title_cn": "\u62c6\u70b8\u5f39", "title_en": "Defuse the Bomb", "question_title_slug": "defuse-the-bomb", "content_en": "

    You have a bomb to defuse, and your time is running out! Your informer will provide you with a circular array code of length of n and a key k.

    \n\n

    To decrypt the code, you must replace every number. All the numbers are replaced simultaneously.

    \n\n
      \n\t
    • If k > 0, replace the ith number with the sum of the next k numbers.
    • \n\t
    • If k < 0, replace the ith number with the sum of the previous k numbers.
    • \n\t
    • If k == 0, replace the ith number with 0.
    • \n
    \n\n

    As code is circular, the next element of code[n-1] is code[0], and the previous element of code[0] is code[n-1].

    \n\n

    Given the circular array code and an integer key k, return the decrypted code to defuse the bomb!

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: code = [5,7,1,4], k = 3\nOutput: [12,10,16,13]\nExplanation: Each number is replaced by the sum of the next 3 numbers. The decrypted code is [7+1+4, 1+4+5, 4+5+7, 5+7+1]. Notice that the numbers wrap around.\n
    \n\n

    Example 2:

    \n\n
    \nInput: code = [1,2,3,4], k = 0\nOutput: [0,0,0,0]\nExplanation: When k is zero, the numbers are replaced by 0. \n
    \n\n

    Example 3:

    \n\n
    \nInput: code = [2,4,9,3], k = -2\nOutput: [12,5,6,13]\nExplanation: The decrypted code is [3+9, 2+3, 4+2, 9+4]. Notice that the numbers wrap around again. If k is negative, the sum is of the previous numbers.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == code.length
    • \n\t
    • 1 <= n <= 100
    • \n\t
    • 1 <= code[i] <= 100
    • \n\t
    • -(n - 1) <= k <= n - 1
    • \n
    \n", "content_cn": "

    \u4f60\u6709\u4e00\u4e2a\u70b8\u5f39\u9700\u8981\u62c6\u9664\uff0c\u65f6\u95f4\u7d27\u8feb\uff01\u4f60\u7684\u60c5\u62a5\u5458\u4f1a\u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u4e3a\u00a0n\u00a0\u7684\u00a0\u5faa\u73af\u00a0\u6570\u7ec4\u00a0code\u00a0\u4ee5\u53ca\u4e00\u4e2a\u5bc6\u94a5\u00a0k\u00a0\u3002

    \n\n

    \u4e3a\u4e86\u83b7\u5f97\u6b63\u786e\u7684\u5bc6\u7801\uff0c\u4f60\u9700\u8981\u66ff\u6362\u6389\u6bcf\u4e00\u4e2a\u6570\u5b57\u3002\u6240\u6709\u6570\u5b57\u4f1a\u00a0\u540c\u65f6\u00a0\u88ab\u66ff\u6362\u3002

    \n\n
      \n\t
    • \u5982\u679c\u00a0k > 0\u00a0\uff0c\u5c06\u7b2c\u00a0i\u00a0\u4e2a\u6570\u5b57\u7528 \u63a5\u4e0b\u6765\u00a0k\u00a0\u4e2a\u6570\u5b57\u4e4b\u548c\u66ff\u6362\u3002
    • \n\t
    • \u5982\u679c\u00a0k < 0\u00a0\uff0c\u5c06\u7b2c\u00a0i\u00a0\u4e2a\u6570\u5b57\u7528 \u4e4b\u524d\u00a0k\u00a0\u4e2a\u6570\u5b57\u4e4b\u548c\u66ff\u6362\u3002
    • \n\t
    • \u5982\u679c\u00a0k == 0\u00a0\uff0c\u5c06\u7b2c\u00a0i\u00a0\u4e2a\u6570\u5b57\u7528\u00a00\u00a0\u66ff\u6362\u3002
    • \n
    \n\n

    \u7531\u4e8e\u00a0code\u00a0\u662f\u5faa\u73af\u7684\uff0c\u00a0code[n-1]\u00a0\u4e0b\u4e00\u4e2a\u5143\u7d20\u662f\u00a0code[0]\u00a0\uff0c\u4e14\u00a0code[0]\u00a0\u524d\u4e00\u4e2a\u5143\u7d20\u662f\u00a0code[n-1]\u00a0\u3002

    \n\n

    \u7ed9\u4f60 \u5faa\u73af\u00a0\u6570\u7ec4\u00a0code\u00a0\u548c\u6574\u6570\u5bc6\u94a5\u00a0k\u00a0\uff0c\u8bf7\u4f60\u8fd4\u56de\u89e3\u5bc6\u540e\u7684\u7ed3\u679c\u6765\u62c6\u9664\u70b8\u5f39\uff01

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1acode = [5,7,1,4], k = 3\n\u8f93\u51fa\uff1a[12,10,16,13]\n\u89e3\u91ca\uff1a\u6bcf\u4e2a\u6570\u5b57\u90fd\u88ab\u63a5\u4e0b\u6765 3 \u4e2a\u6570\u5b57\u4e4b\u548c\u66ff\u6362\u3002\u89e3\u5bc6\u540e\u7684\u5bc6\u7801\u4e3a [7+1+4, 1+4+5, 4+5+7, 5+7+1]\u3002\u6ce8\u610f\u5230\u6570\u7ec4\u662f\u5faa\u73af\u8fde\u63a5\u7684\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1acode = [1,2,3,4], k = 0\n\u8f93\u51fa\uff1a[0,0,0,0]\n\u89e3\u91ca\uff1a\u5f53 k \u4e3a 0 \u65f6\uff0c\u6240\u6709\u6570\u5b57\u90fd\u88ab 0 \u66ff\u6362\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1acode = [2,4,9,3], k = -2\n\u8f93\u51fa\uff1a[12,5,6,13]\n\u89e3\u91ca\uff1a\u89e3\u5bc6\u540e\u7684\u5bc6\u7801\u4e3a [3+9, 2+3, 4+2, 9+4] \u3002\u6ce8\u610f\u5230\u6570\u7ec4\u662f\u5faa\u73af\u8fde\u63a5\u7684\u3002\u5982\u679c k \u662f\u8d1f\u6570\uff0c\u90a3\u4e48\u548c\u4e3a \u4e4b\u524d \u7684\u6570\u5b57\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == code.length
    • \n\t
    • 1 <= n\u00a0<= 100
    • \n\t
    • 1 <= code[i] <= 100
    • \n\t
    • -(n - 1) <= k <= n - 1
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector decrypt(vector& code, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] decrypt(int[] code, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def decrypt(self, code, k):\n \"\"\"\n :type code: List[int]\n :type k: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def decrypt(self, code: List[int], k: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* decrypt(int* code, int codeSize, int k, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] Decrypt(int[] code, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} code\n * @param {number} k\n * @return {number[]}\n */\nvar decrypt = function(code, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} code\n# @param {Integer} k\n# @return {Integer[]}\ndef decrypt(code, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func decrypt(_ code: [Int], _ k: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func decrypt(code []int, k int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def decrypt(code: Array[Int], k: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun decrypt(code: IntArray, k: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn decrypt(code: Vec, k: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $code\n * @param Integer $k\n * @return Integer[]\n */\n function decrypt($code, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function decrypt(code: number[], k: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (decrypt code k)\n (-> (listof exact-integer?) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1652](https://leetcode-cn.com/problems/defuse-the-bomb)", "[\u62c6\u70b8\u5f39](/solution/1600-1699/1652.Defuse%20the%20Bomb/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1652](https://leetcode.com/problems/defuse-the-bomb)", "[Defuse the Bomb](/solution/1600-1699/1652.Defuse%20the%20Bomb/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1753", "frontend_question_id": "1631", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/path-with-minimum-effort", "url_en": "https://leetcode.com/problems/path-with-minimum-effort", "relative_path_cn": "/solution/1600-1699/1631.Path%20With%20Minimum%20Effort/README.md", "relative_path_en": "/solution/1600-1699/1631.Path%20With%20Minimum%20Effort/README_EN.md", "title_cn": "\u6700\u5c0f\u4f53\u529b\u6d88\u8017\u8def\u5f84", "title_en": "Path With Minimum Effort", "question_title_slug": "path-with-minimum-effort", "content_en": "

    You are a hiker preparing for an upcoming hike. You are given heights, a 2D array of size rows x columns, where heights[row][col] represents the height of cell (row, col). You are situated in the top-left cell, (0, 0), and you hope to travel to the bottom-right cell, (rows-1, columns-1) (i.e., 0-indexed). You can move up, down, left, or right, and you wish to find a route that requires the minimum effort.

    \n\n

    A route's effort is the maximum absolute difference in heights between two consecutive cells of the route.

    \n\n

    Return the minimum effort required to travel from the top-left cell to the bottom-right cell.

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: heights = [[1,2,2],[3,8,2],[5,3,5]]\nOutput: 2\nExplanation: The route of [1,3,5,3,5] has a maximum absolute difference of 2 in consecutive cells.\nThis is better than the route of [1,2,2,2,5], where the maximum absolute difference is 3.\n
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: heights = [[1,2,3],[3,8,4],[5,3,5]]\nOutput: 1\nExplanation: The route of [1,2,3,4,5] has a maximum absolute difference of 1 in consecutive cells, which is better than route [1,3,5,3,5].\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: heights = [[1,2,1,1,1],[1,2,1,2,1],[1,2,1,2,1],[1,2,1,2,1],[1,1,1,2,1]]\nOutput: 0\nExplanation: This route does not require any effort.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • rows == heights.length
    • \n\t
    • columns == heights[i].length
    • \n\t
    • 1 <= rows, columns <= 100
    • \n\t
    • 1 <= heights[i][j] <= 106
    • \n
    \n", "content_cn": "

    \u4f60\u51c6\u5907\u53c2\u52a0\u4e00\u573a\u8fdc\u8db3\u6d3b\u52a8\u3002\u7ed9\u4f60\u4e00\u4e2a\u4e8c\u7ef4\u00a0rows x columns\u00a0\u7684\u5730\u56fe\u00a0heights\u00a0\uff0c\u5176\u4e2d\u00a0heights[row][col]\u00a0\u8868\u793a\u683c\u5b50\u00a0(row, col)\u00a0\u7684\u9ad8\u5ea6\u3002\u4e00\u5f00\u59cb\u4f60\u5728\u6700\u5de6\u4e0a\u89d2\u7684\u683c\u5b50\u00a0(0, 0)\u00a0\uff0c\u4e14\u4f60\u5e0c\u671b\u53bb\u6700\u53f3\u4e0b\u89d2\u7684\u683c\u5b50\u00a0(rows-1, columns-1)\u00a0\uff08\u6ce8\u610f\u4e0b\u6807\u4ece 0 \u5f00\u59cb\u7f16\u53f7\uff09\u3002\u4f60\u6bcf\u6b21\u53ef\u4ee5\u5f80 \u4e0a\uff0c\u4e0b\uff0c\u5de6\uff0c\u53f3\u00a0\u56db\u4e2a\u65b9\u5411\u4e4b\u4e00\u79fb\u52a8\uff0c\u4f60\u60f3\u8981\u627e\u5230\u8017\u8d39 \u4f53\u529b \u6700\u5c0f\u7684\u4e00\u6761\u8def\u5f84\u3002

    \n\n

    \u4e00\u6761\u8def\u5f84\u8017\u8d39\u7684 \u4f53\u529b\u503c\u00a0\u662f\u8def\u5f84\u4e0a\u76f8\u90bb\u683c\u5b50\u4e4b\u95f4 \u9ad8\u5ea6\u5dee\u7edd\u5bf9\u503c\u00a0\u7684 \u6700\u5927\u503c\u00a0\u51b3\u5b9a\u7684\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u4ece\u5de6\u4e0a\u89d2\u8d70\u5230\u53f3\u4e0b\u89d2\u7684\u6700\u5c0f\u00a0\u4f53\u529b\u6d88\u8017\u503c\u00a0\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aheights = [[1,2,2],[3,8,2],[5,3,5]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u8def\u5f84 [1,3,5,3,5] \u8fde\u7eed\u683c\u5b50\u7684\u5dee\u503c\u7edd\u5bf9\u503c\u6700\u5927\u4e3a 2 \u3002\n\u8fd9\u6761\u8def\u5f84\u6bd4\u8def\u5f84 [1,2,2,2,5] \u66f4\u4f18\uff0c\u56e0\u4e3a\u53e6\u4e00\u6761\u8def\u5f84\u5dee\u503c\u6700\u5927\u503c\u4e3a 3 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aheights = [[1,2,3],[3,8,4],[5,3,5]]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u8def\u5f84 [1,2,3,4,5] \u7684\u76f8\u90bb\u683c\u5b50\u5dee\u503c\u7edd\u5bf9\u503c\u6700\u5927\u4e3a 1 \uff0c\u6bd4\u8def\u5f84 [1,3,5,3,5] \u66f4\u4f18\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aheights = [[1,2,1,1,1],[1,2,1,2,1],[1,2,1,2,1],[1,2,1,2,1],[1,1,1,2,1]]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u4e0a\u56fe\u6240\u793a\u8def\u5f84\u4e0d\u9700\u8981\u6d88\u8017\u4efb\u4f55\u4f53\u529b\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • rows == heights.length
    • \n\t
    • columns == heights[i].length
    • \n\t
    • 1 <= rows, columns <= 100
    • \n\t
    • 1 <= heights[i][j] <= 106
    • \n
    \n", "tags_en": ["Depth-first Search", "Union Find", "Graph", "Binary Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e76\u67e5\u96c6", "\u56fe", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minimumEffortPath(vector>& heights) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minimumEffortPath(int[][] heights) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimumEffortPath(self, heights):\n \"\"\"\n :type heights: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimumEffortPath(self, heights: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minimumEffortPath(int** heights, int heightsSize, int* heightsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinimumEffortPath(int[][] heights) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} heights\n * @return {number}\n */\nvar minimumEffortPath = function(heights) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} heights\n# @return {Integer}\ndef minimum_effort_path(heights)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimumEffortPath(_ heights: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimumEffortPath(heights [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimumEffortPath(heights: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimumEffortPath(heights: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimum_effort_path(heights: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $heights\n * @return Integer\n */\n function minimumEffortPath($heights) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimumEffortPath(heights: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimum-effort-path heights)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1631](https://leetcode-cn.com/problems/path-with-minimum-effort)", "[\u6700\u5c0f\u4f53\u529b\u6d88\u8017\u8def\u5f84](/solution/1600-1699/1631.Path%20With%20Minimum%20Effort/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e76\u67e5\u96c6`,`\u56fe`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1631](https://leetcode.com/problems/path-with-minimum-effort)", "[Path With Minimum Effort](/solution/1600-1699/1631.Path%20With%20Minimum%20Effort/README_EN.md)", "`Depth-first Search`,`Union Find`,`Graph`,`Binary Search`", "Medium", ""]}, {"question_id": "1752", "frontend_question_id": "1630", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/arithmetic-subarrays", "url_en": "https://leetcode.com/problems/arithmetic-subarrays", "relative_path_cn": "/solution/1600-1699/1630.Arithmetic%20Subarrays/README.md", "relative_path_en": "/solution/1600-1699/1630.Arithmetic%20Subarrays/README_EN.md", "title_cn": "\u7b49\u5dee\u5b50\u6570\u7ec4", "title_en": "Arithmetic Subarrays", "question_title_slug": "arithmetic-subarrays", "content_en": "

    A sequence of numbers is called arithmetic if it consists of at least two elements, and the difference between every two consecutive elements is the same. More formally, a sequence s is arithmetic if and only if s[i+1] - s[i] == s[1] - s[0] for all valid i.

    \n\n

    For example, these are arithmetic sequences:

    \n\n
    \n1, 3, 5, 7, 9\n7, 7, 7, 7\n3, -1, -5, -9
    \n\n

    The following sequence is not arithmetic:

    \n\n
    \n1, 1, 2, 5, 7
    \n\n

    You are given an array of n integers, nums, and two arrays of m integers each, l and r, representing the m range queries, where the ith query is the range [l[i], r[i]]. All the arrays are 0-indexed.

    \n\n

    Return a list of boolean elements answer, where answer[i] is true if the subarray nums[l[i]], nums[l[i]+1], ... , nums[r[i]] can be rearranged to form an arithmetic sequence, and false otherwise.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [4,6,5,9,3,7], l = [0,0,2], r = [2,3,5]\nOutput: [true,false,true]\nExplanation:\nIn the 0th query, the subarray is [4,6,5]. This can be rearranged as [6,5,4], which is an arithmetic sequence.\nIn the 1st query, the subarray is [4,6,5,9]. This cannot be rearranged as an arithmetic sequence.\nIn the 2nd query, the subarray is [5,9,3,7]. This can be rearranged as [3,5,7,9], which is an arithmetic sequence.
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [-12,-9,-3,-12,-6,15,20,-25,-20,-15,-10], l = [0,1,6,4,8,7], r = [4,4,9,7,9,10]\nOutput: [false,true,false,false,true,true]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • m == l.length
    • \n\t
    • m == r.length
    • \n\t
    • 2 <= n <= 500
    • \n\t
    • 1 <= m <= 500
    • \n\t
    • 0 <= l[i] < r[i] < n
    • \n\t
    • -105 <= nums[i] <= 105
    • \n
    \n", "content_cn": "

    \u5982\u679c\u4e00\u4e2a\u6570\u5217\u7531\u81f3\u5c11\u4e24\u4e2a\u5143\u7d20\u7ec4\u6210\uff0c\u4e14\u6bcf\u4e24\u4e2a\u8fde\u7eed\u5143\u7d20\u4e4b\u95f4\u7684\u5dee\u503c\u90fd\u76f8\u540c\uff0c\u90a3\u4e48\u8fd9\u4e2a\u5e8f\u5217\u5c31\u662f \u7b49\u5dee\u6570\u5217 \u3002\u66f4\u6b63\u5f0f\u5730\uff0c\u6570\u5217 s \u662f\u7b49\u5dee\u6570\u5217\uff0c\u53ea\u9700\u8981\u6ee1\u8db3\uff1a\u5bf9\u4e8e\u6bcf\u4e2a\u6709\u6548\u7684 i \uff0c s[i+1] - s[i] == s[1] - s[0] \u90fd\u6210\u7acb\u3002

    \n\n

    \u4f8b\u5982\uff0c\u4e0b\u9762\u8fd9\u4e9b\u90fd\u662f \u7b49\u5dee\u6570\u5217 \uff1a

    \n\n
    1, 3, 5, 7, 9\n7, 7, 7, 7\n3, -1, -5, -9
    \n\n

    \u4e0b\u9762\u7684\u6570\u5217 \u4e0d\u662f\u7b49\u5dee\u6570\u5217 \uff1a

    \n\n
    1, 1, 2, 5, 7
    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u7531 n \u4e2a\u6574\u6570\u7ec4\u6210\u7684\u6570\u7ec4 nums\uff0c\u548c\u4e24\u4e2a\u7531 m \u4e2a\u6574\u6570\u7ec4\u6210\u7684\u6570\u7ec4 l \u548c r\uff0c\u540e\u4e24\u4e2a\u6570\u7ec4\u8868\u793a m \u7ec4\u8303\u56f4\u67e5\u8be2\uff0c\u5176\u4e2d\u7b2c i \u4e2a\u67e5\u8be2\u5bf9\u5e94\u8303\u56f4 [l[i], r[i]] \u3002\u6240\u6709\u6570\u7ec4\u7684\u4e0b\u6807\u90fd\u662f \u4ece 0 \u5f00\u59cb \u7684\u3002

    \n\n

    \u8fd4\u56de boolean \u5143\u7d20\u6784\u6210\u7684\u7b54\u6848\u5217\u8868 answer \u3002\u5982\u679c\u5b50\u6570\u7ec4 nums[l[i]], nums[l[i]+1], ... , nums[r[i]] \u53ef\u4ee5 \u91cd\u65b0\u6392\u5217 \u5f62\u6210 \u7b49\u5dee\u6570\u5217 \uff0canswer[i] \u7684\u503c\u5c31\u662f true\uff1b\u5426\u5219answer[i] \u7684\u503c\u5c31\u662f false \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [4,6,5,9,3,7], l = [0,0,2], r = [2,3,5]\n\u8f93\u51fa\uff1a[true,false,true]\n\u89e3\u91ca\uff1a\n\u7b2c 0 \u4e2a\u67e5\u8be2\uff0c\u5bf9\u5e94\u5b50\u6570\u7ec4 [4,6,5] \u3002\u53ef\u4ee5\u91cd\u65b0\u6392\u5217\u4e3a\u7b49\u5dee\u6570\u5217 [6,5,4] \u3002\n\u7b2c 1 \u4e2a\u67e5\u8be2\uff0c\u5bf9\u5e94\u5b50\u6570\u7ec4 [4,6,5,9] \u3002\u65e0\u6cd5\u91cd\u65b0\u6392\u5217\u5f62\u6210\u7b49\u5dee\u6570\u5217\u3002\n\u7b2c 2 \u4e2a\u67e5\u8be2\uff0c\u5bf9\u5e94\u5b50\u6570\u7ec4 [5,9,3,7] \u3002\u53ef\u4ee5\u91cd\u65b0\u6392\u5217\u4e3a\u7b49\u5dee\u6570\u5217 [3,5,7,9] \u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [-12,-9,-3,-12,-6,15,20,-25,-20,-15,-10], l = [0,1,6,4,8,7], r = [4,4,9,7,9,10]\n\u8f93\u51fa\uff1a[false,true,false,false,true,true]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • m == l.length
    • \n\t
    • m == r.length
    • \n\t
    • 2 <= n <= 500
    • \n\t
    • 1 <= m <= 500
    • \n\t
    • 0 <= l[i] < r[i] < n
    • \n\t
    • -105 <= nums[i] <= 105
    • \n
    \n", "tags_en": ["Sort"], "tags_cn": ["\u6392\u5e8f"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector checkArithmeticSubarrays(vector& nums, vector& l, vector& r) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List checkArithmeticSubarrays(int[] nums, int[] l, int[] r) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def checkArithmeticSubarrays(self, nums, l, r):\n \"\"\"\n :type nums: List[int]\n :type l: List[int]\n :type r: List[int]\n :rtype: List[bool]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def checkArithmeticSubarrays(self, nums: List[int], l: List[int], r: List[int]) -> List[bool]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nbool* checkArithmeticSubarrays(int* nums, int numsSize, int* l, int lSize, int* r, int rSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList CheckArithmeticSubarrays(int[] nums, int[] l, int[] r) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number[]} l\n * @param {number[]} r\n * @return {boolean[]}\n */\nvar checkArithmeticSubarrays = function(nums, l, r) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer[]} l\n# @param {Integer[]} r\n# @return {Boolean[]}\ndef check_arithmetic_subarrays(nums, l, r)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func checkArithmeticSubarrays(_ nums: [Int], _ l: [Int], _ r: [Int]) -> [Bool] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func checkArithmeticSubarrays(nums []int, l []int, r []int) []bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def checkArithmeticSubarrays(nums: Array[Int], l: Array[Int], r: Array[Int]): List[Boolean] = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun checkArithmeticSubarrays(nums: IntArray, l: IntArray, r: IntArray): List {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn check_arithmetic_subarrays(nums: Vec, l: Vec, r: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer[] $l\n * @param Integer[] $r\n * @return Boolean[]\n */\n function checkArithmeticSubarrays($nums, $l, $r) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function checkArithmeticSubarrays(nums: number[], l: number[], r: number[]): boolean[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (check-arithmetic-subarrays nums l r)\n (-> (listof exact-integer?) (listof exact-integer?) (listof exact-integer?) (listof boolean?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1630](https://leetcode-cn.com/problems/arithmetic-subarrays)", "[\u7b49\u5dee\u5b50\u6570\u7ec4](/solution/1600-1699/1630.Arithmetic%20Subarrays/README.md)", "`\u6392\u5e8f`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1630](https://leetcode.com/problems/arithmetic-subarrays)", "[Arithmetic Subarrays](/solution/1600-1699/1630.Arithmetic%20Subarrays/README_EN.md)", "`Sort`", "Medium", ""]}, {"question_id": "1751", "frontend_question_id": "1629", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/slowest-key", "url_en": "https://leetcode.com/problems/slowest-key", "relative_path_cn": "/solution/1600-1699/1629.Slowest%20Key/README.md", "relative_path_en": "/solution/1600-1699/1629.Slowest%20Key/README_EN.md", "title_cn": "\u6309\u952e\u6301\u7eed\u65f6\u95f4\u6700\u957f\u7684\u952e", "title_en": "Slowest Key", "question_title_slug": "slowest-key", "content_en": "

    A newly designed keypad was tested, where a tester pressed a sequence of n keys, one at a time.

    \n\n

    You are given a string keysPressed of length n, where keysPressed[i] was the ith key pressed in the testing sequence, and a sorted list releaseTimes, where releaseTimes[i] was the time the ith key was released. Both arrays are 0-indexed. The 0th key was pressed at the time 0, and every subsequent key was pressed at the exact time the previous key was released.

    \n\n

    The tester wants to know the key of the keypress that had the longest duration. The ith keypress had a duration of releaseTimes[i] - releaseTimes[i - 1], and the 0th keypress had a duration of releaseTimes[0].

    \n\n

    Note that the same key could have been pressed multiple times during the test, and these multiple presses of the same key may not have had the same duration.

    \n\n

    Return the key of the keypress that had the longest duration. If there are multiple such keypresses, return the lexicographically largest key of the keypresses.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: releaseTimes = [9,29,49,50], keysPressed = "cbcd"\nOutput: "c"\nExplanation: The keypresses were as follows:\nKeypress for 'c' had a duration of 9 (pressed at time 0 and released at time 9).\nKeypress for 'b' had a duration of 29 - 9 = 20 (pressed at time 9 right after the release of the previous character and released at time 29).\nKeypress for 'c' had a duration of 49 - 29 = 20 (pressed at time 29 right after the release of the previous character and released at time 49).\nKeypress for 'd' had a duration of 50 - 49 = 1 (pressed at time 49 right after the release of the previous character and released at time 50).\nThe longest of these was the keypress for 'b' and the second keypress for 'c', both with duration 20.\n'c' is lexicographically larger than 'b', so the answer is 'c'.\n
    \n\n

    Example 2:

    \n\n
    \nInput: releaseTimes = [12,23,36,46,62], keysPressed = "spuda"\nOutput: "a"\nExplanation: The keypresses were as follows:\nKeypress for 's' had a duration of 12.\nKeypress for 'p' had a duration of 23 - 12 = 11.\nKeypress for 'u' had a duration of 36 - 23 = 13.\nKeypress for 'd' had a duration of 46 - 36 = 10.\nKeypress for 'a' had a duration of 62 - 46 = 16.\nThe longest of these was the keypress for 'a' with duration 16.
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • releaseTimes.length == n
    • \n\t
    • keysPressed.length == n
    • \n\t
    • 2 <= n <= 1000
    • \n\t
    • 1 <= releaseTimes[i] <= 109
    • \n\t
    • releaseTimes[i] < releaseTimes[i+1]
    • \n\t
    • keysPressed contains only lowercase English letters.
    • \n
    \n", "content_cn": "

    LeetCode \u8bbe\u8ba1\u4e86\u4e00\u6b3e\u65b0\u5f0f\u952e\u76d8\uff0c\u6b63\u5728\u6d4b\u8bd5\u5176\u53ef\u7528\u6027\u3002\u6d4b\u8bd5\u4eba\u5458\u5c06\u4f1a\u70b9\u51fb\u4e00\u7cfb\u5217\u952e\uff08\u603b\u8ba1 n \u4e2a\uff09\uff0c\u6bcf\u6b21\u4e00\u4e2a\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u5b57\u7b26\u4e32 keysPressed \uff0c\u5176\u4e2d keysPressed[i] \u8868\u793a\u6d4b\u8bd5\u5e8f\u5217\u4e2d\u7b2c i \u4e2a\u88ab\u6309\u4e0b\u7684\u952e\u3002releaseTimes \u662f\u4e00\u4e2a\u5347\u5e8f\u6392\u5217\u7684\u5217\u8868\uff0c\u5176\u4e2d releaseTimes[i] \u8868\u793a\u677e\u5f00\u7b2c i \u4e2a\u952e\u7684\u65f6\u95f4\u3002\u5b57\u7b26\u4e32\u548c\u6570\u7ec4\u7684 \u4e0b\u6807\u90fd\u4ece 0 \u5f00\u59cb \u3002\u7b2c 0 \u4e2a\u952e\u5728\u65f6\u95f4\u4e3a 0 \u65f6\u88ab\u6309\u4e0b\uff0c\u63a5\u4e0b\u6765\u6bcf\u4e2a\u952e\u90fd \u6070\u597d \u5728\u524d\u4e00\u4e2a\u952e\u677e\u5f00\u65f6\u88ab\u6309\u4e0b\u3002

    \n\n

    \u6d4b\u8bd5\u4eba\u5458\u60f3\u8981\u627e\u51fa\u6309\u952e \u6301\u7eed\u65f6\u95f4\u6700\u957f \u7684\u952e\u3002\u7b2c i \u6b21\u6309\u952e\u7684\u6301\u7eed\u65f6\u95f4\u4e3a releaseTimes[i] - releaseTimes[i - 1] \uff0c\u7b2c 0 \u6b21\u6309\u952e\u7684\u6301\u7eed\u65f6\u95f4\u4e3a releaseTimes[0] \u3002

    \n\n

    \u6ce8\u610f\uff0c\u6d4b\u8bd5\u671f\u95f4\uff0c\u540c\u4e00\u4e2a\u952e\u53ef\u4ee5\u5728\u4e0d\u540c\u65f6\u523b\u88ab\u591a\u6b21\u6309\u4e0b\uff0c\u800c\u6bcf\u6b21\u7684\u6301\u7eed\u65f6\u95f4\u90fd\u53ef\u80fd\u4e0d\u540c\u3002

    \n\n

    \u8bf7\u8fd4\u56de\u6309\u952e \u6301\u7eed\u65f6\u95f4\u6700\u957f \u7684\u952e\uff0c\u5982\u679c\u6709\u591a\u4e2a\u8fd9\u6837\u7684\u952e\uff0c\u5219\u8fd4\u56de \u6309\u5b57\u6bcd\u987a\u5e8f\u6392\u5217\u6700\u5927 \u7684\u90a3\u4e2a\u952e\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1areleaseTimes = [9,29,49,50], keysPressed = \"cbcd\"\n\u8f93\u51fa\uff1a\"c\"\n\u89e3\u91ca\uff1a\u6309\u952e\u987a\u5e8f\u548c\u6301\u7eed\u65f6\u95f4\u5982\u4e0b\uff1a\n\u6309\u4e0b 'c' \uff0c\u6301\u7eed\u65f6\u95f4 9\uff08\u65f6\u95f4 0 \u6309\u4e0b\uff0c\u65f6\u95f4 9 \u677e\u5f00\uff09\n\u6309\u4e0b 'b' \uff0c\u6301\u7eed\u65f6\u95f4 29 - 9 = 20\uff08\u677e\u5f00\u4e0a\u4e00\u4e2a\u952e\u7684\u65f6\u95f4 9 \u6309\u4e0b\uff0c\u65f6\u95f4 29 \u677e\u5f00\uff09\n\u6309\u4e0b 'c' \uff0c\u6301\u7eed\u65f6\u95f4 49 - 29 = 20\uff08\u677e\u5f00\u4e0a\u4e00\u4e2a\u952e\u7684\u65f6\u95f4 29 \u6309\u4e0b\uff0c\u65f6\u95f4 49 \u677e\u5f00\uff09\n\u6309\u4e0b 'd' \uff0c\u6301\u7eed\u65f6\u95f4 50 - 49 = 1\uff08\u677e\u5f00\u4e0a\u4e00\u4e2a\u952e\u7684\u65f6\u95f4 49 \u6309\u4e0b\uff0c\u65f6\u95f4 50 \u677e\u5f00\uff09\n\u6309\u952e\u6301\u7eed\u65f6\u95f4\u6700\u957f\u7684\u952e\u662f 'b' \u548c 'c'\uff08\u7b2c\u4e8c\u6b21\u6309\u4e0b\u65f6\uff09\uff0c\u6301\u7eed\u65f6\u95f4\u90fd\u662f 20\n'c' \u6309\u5b57\u6bcd\u987a\u5e8f\u6392\u5217\u6bd4 'b' \u5927\uff0c\u6240\u4ee5\u7b54\u6848\u662f 'c'\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1areleaseTimes = [12,23,36,46,62], keysPressed = \"spuda\"\n\u8f93\u51fa\uff1a\"a\"\n\u89e3\u91ca\uff1a\u6309\u952e\u987a\u5e8f\u548c\u6301\u7eed\u65f6\u95f4\u5982\u4e0b\uff1a\n\u6309\u4e0b 's' \uff0c\u6301\u7eed\u65f6\u95f4 12\n\u6309\u4e0b 'p' \uff0c\u6301\u7eed\u65f6\u95f4 23 - 12 = 11\n\u6309\u4e0b 'u' \uff0c\u6301\u7eed\u65f6\u95f4 36 - 23 = 13\n\u6309\u4e0b 'd' \uff0c\u6301\u7eed\u65f6\u95f4 46 - 36 = 10\n\u6309\u4e0b 'a' \uff0c\u6301\u7eed\u65f6\u95f4 62 - 46 = 16\n\u6309\u952e\u6301\u7eed\u65f6\u95f4\u6700\u957f\u7684\u952e\u662f 'a' \uff0c\u6301\u7eed\u65f6\u95f4 16
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • releaseTimes.length == n
    • \n\t
    • keysPressed.length == n
    • \n\t
    • 2 <= n <= 1000
    • \n\t
    • 1 <= releaseTimes[i] <= 109
    • \n\t
    • releaseTimes[i] < releaseTimes[i+1]
    • \n\t
    • keysPressed \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n char slowestKey(vector& releaseTimes, string keysPressed) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public char slowestKey(int[] releaseTimes, String keysPressed) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def slowestKey(self, releaseTimes, keysPressed):\n \"\"\"\n :type releaseTimes: List[int]\n :type keysPressed: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def slowestKey(self, releaseTimes: List[int], keysPressed: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar slowestKey(int* releaseTimes, int releaseTimesSize, char * keysPressed){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public char SlowestKey(int[] releaseTimes, string keysPressed) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} releaseTimes\n * @param {string} keysPressed\n * @return {character}\n */\nvar slowestKey = function(releaseTimes, keysPressed) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} release_times\n# @param {String} keys_pressed\n# @return {Character}\ndef slowest_key(release_times, keys_pressed)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func slowestKey(_ releaseTimes: [Int], _ keysPressed: String) -> Character {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func slowestKey(releaseTimes []int, keysPressed string) byte {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def slowestKey(releaseTimes: Array[Int], keysPressed: String): Char = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun slowestKey(releaseTimes: IntArray, keysPressed: String): Char {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn slowest_key(release_times: Vec, keys_pressed: String) -> char {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $releaseTimes\n * @param String $keysPressed\n * @return String\n */\n function slowestKey($releaseTimes, $keysPressed) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function slowestKey(releaseTimes: number[], keysPressed: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (slowest-key releaseTimes keysPressed)\n (-> (listof exact-integer?) string? char?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1629](https://leetcode-cn.com/problems/slowest-key)", "[\u6309\u952e\u6301\u7eed\u65f6\u95f4\u6700\u957f\u7684\u952e](/solution/1600-1699/1629.Slowest%20Key/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1629](https://leetcode.com/problems/slowest-key)", "[Slowest Key](/solution/1600-1699/1629.Slowest%20Key/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1750", "frontend_question_id": "1612", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/check-if-two-expression-trees-are-equivalent", "url_en": "https://leetcode.com/problems/check-if-two-expression-trees-are-equivalent", "relative_path_cn": "/solution/1600-1699/1612.Check%20If%20Two%20Expression%20Trees%20are%20Equivalent/README.md", "relative_path_en": "/solution/1600-1699/1612.Check%20If%20Two%20Expression%20Trees%20are%20Equivalent/README_EN.md", "title_cn": "\u68c0\u67e5\u4e24\u68f5\u4e8c\u53c9\u8868\u8fbe\u5f0f\u6811\u662f\u5426\u7b49\u4ef7", "title_en": "Check If Two Expression Trees are Equivalent", "question_title_slug": "check-if-two-expression-trees-are-equivalent", "content_en": "

    A binary expression tree is a kind of binary tree used to represent arithmetic expressions. Each node of a binary expression tree has either zero or two children. Leaf nodes (nodes with 0 children) correspond to operands (variables), and internal nodes (nodes with two children) correspond to the operators. In this problem, we only consider the '+' operator (i.e. addition).

    \n\n

    You are given the roots of two binary expression trees, root1 and root2. Return true if the two binary expression trees are equivalent. Otherwise, return false.

    \n\n

    Two binary expression trees are equivalent if they evaluate to the same value regardless of what the variables are set to.

    \n\n

    Follow up: What will you change in your solution if the tree also supports the '-' operator (i.e. subtraction)?

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: root1 = [x], root2 = [x]\nOutput: true\n
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: root1 = [+,a,+,null,null,b,c], root2 = [+,+,a,b,c]\nOutput: true\nExplaination: a + (b + c) == (b + c) + a
    \n\n

    Example 3:

    \n\n

    \"\"

    \n\n
    \nInput: root1 = [+,a,+,null,null,b,c], root2 = [+,+,a,b,d]\nOutput: false\nExplaination: a + (b + c) != (b + d) + a\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in both trees are equal, odd and, in the range [1, 4999].
    • \n\t
    • Node.val is '+' or a lower-case English letter.
    • \n\t
    • It's guaranteed that the tree given is a valid binary expression tree.
    • \n
    \n", "content_cn": "

    \u4e8c\u53c9\u8868\u8fbe\u5f0f\u6811\u662f\u4e00\u79cd\u8868\u8fbe\u7b97\u672f\u8868\u8fbe\u5f0f\u7684\u4e8c\u53c9\u6811\u3002\u4e8c\u53c9\u8868\u8fbe\u5f0f\u6811\u4e2d\u7684\u6bcf\u4e00\u4e2a\u8282\u70b9\u90fd\u6709\u96f6\u4e2a\u6216\u4e24\u4e2a\u5b50\u8282\u70b9\u3002\u00a0\u53f6\u8282\u70b9\uff08\u6709 0 \u4e2a\u5b50\u8282\u70b9\u7684\u8282\u70b9\uff09\u8868\u793a\u64cd\u4f5c\u6570\uff0c\u975e\u53f6\u8282\u70b9\uff08\u6709 2 \u4e2a\u5b50\u8282\u70b9\u7684\u8282\u70b9\uff09\u8868\u793a\u8fd0\u7b97\u7b26\u3002\u5728\u672c\u9898\u4e2d\uff0c\u6211\u4eec\u53ea\u8003\u8651 '+' \u8fd0\u7b97\u7b26\uff08\u5373\u52a0\u6cd5\uff09\u3002

    \n\n

    \u7ed9\u5b9a\u4e24\u68f5\u4e8c\u53c9\u8868\u8fbe\u5f0f\u6811\u7684\u6839\u8282\u70b9\u00a0root1\u00a0\u548c\u00a0root2\u00a0\u3002\u5982\u679c\u4e24\u68f5\u4e8c\u53c9\u8868\u8fbe\u5f0f\u6811\u7b49\u4ef7\uff0c\u8fd4\u56de\u00a0true\u00a0\uff0c\u5426\u5219\u8fd4\u56de\u00a0false\u00a0\u3002

    \n\n

    \u5f53\u4e24\u68f5\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u7684\u53d8\u91cf\u53d6\u4efb\u610f\u503c\uff0c\u5206\u522b\u6c42\u5f97\u7684\u503c\u90fd\u76f8\u7b49\u65f6\uff0c\u6211\u4eec\u79f0\u8fd9\u4e24\u68f5\u4e8c\u53c9\u8868\u8fbe\u5f0f\u6811\u662f\u7b49\u4ef7\u7684\u3002

    \n\n

    \u8fdb\u9636\uff1a\u5f53\u4f60\u7684\u7b54\u6848\u9700\u540c\u65f6\u652f\u6301\u00a0'-'\u00a0\u8fd0\u7b97\u7b26\uff08\u51cf\u6cd5\uff09\u65f6\uff0c\u4f60\u8be5\u5982\u4f55\u4fee\u6539\u4f60\u7684\u7b54\u6848\uff1f

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165\uff1a root1 = [x], root2 = [x]\n\u8f93\u51fa\uff1a true\n
    \n\n

    \u793a\u4f8b 2:

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aroot1 = [+,a,+,null,null,b,c], root2 = [+,+,a,b,c]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1aa + (b + c) == (b + c) + a
    \n\n

    \u793a\u4f8b 3:

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1a root1 = [+,a,+,null,null,b,c], root2 = [+,+,a,b,d]\n\u8f93\u51fa\uff1a false\n\u89e3\u91ca\uff1a a + (b + c) != (b + d) + a\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u4e24\u68f5\u6811\u4e2d\u7684\u8282\u70b9\u4e2a\u6570\u76f8\u7b49\uff0c\u4e14\u8282\u70b9\u4e2a\u6570\u4e3a\u8303\u56f4\u00a0[1, 4999]\u00a0\u5185\u7684\u5947\u6570\u3002
    • \n\t
    • Node.val\u00a0\u662f\u00a0'+'\u00a0\u6216\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    • \n\t
    • \u7ed9\u5b9a\u7684\u6811\u4fdd\u8bc1\u662f\u6709\u6548\u7684\u4e8c\u53c9\u8868\u8fbe\u5f0f\u6811\u3002
    • \n
    \n", "tags_en": ["Tree", "Hash Table"], "tags_cn": ["\u6811", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for a binary tree node.\n * struct Node {\n * char val;\n * Node *left;\n * Node *right;\n * Node() : val(' '), left(nullptr), right(nullptr) {}\n * Node(char x) : val(x), left(nullptr), right(nullptr) {}\n * Node(char x, Node *left, Node *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n bool checkEquivalence(Node* root1, Node* root2) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * class Node {\n * char val;\n * Node left;\n * Node right;\n * Node() {this.val = ' ';}\n * Node(char val) { this.val = val; }\n * Node(char val, Node left, Node right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public boolean checkEquivalence(Node root1, Node root2) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class Node(object):\n# def __init__(self, val=\" \", left=None, right=None):\n# self.val = val\n# self.left = None\n# self.right = None\nclass Solution(object):\n def checkEquivalence(self, root1, root2):\n \"\"\"\n :type root1: Node\n :type root2: Node\n :rtype: bool\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class Node(object):\n# def __init__(self, val=\" \", left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def checkEquivalence(self, root1: 'Node', root2: 'Node') -> bool:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class Node {\n * public char val;\n * public Node left;\n * public Node right;\n * public Node(char val=' ', TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public bool CheckEquivalence(Node root1, Node root2) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function Node(val, left, right) {\n * this.val = (val===undefined ? \" \" : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {Node} root1\n * @param {Node} root2\n * @return {boolean}\n */\nvar checkEquivalence = function(root1, root2) {\n \n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1612](https://leetcode-cn.com/problems/check-if-two-expression-trees-are-equivalent)", "[\u68c0\u67e5\u4e24\u68f5\u4e8c\u53c9\u8868\u8fbe\u5f0f\u6811\u662f\u5426\u7b49\u4ef7](/solution/1600-1699/1612.Check%20If%20Two%20Expression%20Trees%20are%20Equivalent/README.md)", "`\u6811`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1612](https://leetcode.com/problems/check-if-two-expression-trees-are-equivalent)", "[Check If Two Expression Trees are Equivalent](/solution/1600-1699/1612.Check%20If%20Two%20Expression%20Trees%20are%20Equivalent/README_EN.md)", "`Tree`,`Hash Table`", "Medium", "\ud83d\udd12"]}, {"question_id": "1749", "frontend_question_id": "1607", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/sellers-with-no-sales", "url_en": "https://leetcode.com/problems/sellers-with-no-sales", "relative_path_cn": "/solution/1600-1699/1607.Sellers%20With%20No%20Sales/README.md", "relative_path_en": "/solution/1600-1699/1607.Sellers%20With%20No%20Sales/README_EN.md", "title_cn": "\u6ca1\u6709\u5356\u51fa\u7684\u5356\u5bb6", "title_en": "Sellers With No Sales", "question_title_slug": "sellers-with-no-sales", "content_en": "

    Table: Customer

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| customer_id   | int     |\n| customer_name | varchar |\n+---------------+---------+\ncustomer_id is the primary key for this table.\nEach row of this table contains the information of each customer in the WebStore.\n
    \n\n

     

    \n\n

    Table: Orders

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| order_id      | int     |\n| sale_date     | date    |\n| order_cost    | int     |\n| customer_id   | int     |\n| seller_id     | int     |\n+---------------+---------+\norder_id is the primary key for this table.\nEach row of this table contains all orders made in the webstore.\nsale_date is the date when the transaction was made between the customer (customer_id) and the seller (seller_id).\n
    \n\n

     

    \n\n

    Table: Seller

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| seller_id     | int     |\n| seller_name   | varchar |\n+---------------+---------+\nseller_id is the primary key for this table.\nEach row of this table contains the information of each seller.\n
    \n\n

     

    \n\n

    Write an SQL query to report the names of all sellers who did not make any sales in 2020.

    \n\n

    Return the result table ordered by seller_name in ascending order.

    \n\n

    The query result format is in the following example.

    \n\n
    \nCustomer table:\n+--------------+---------------+\n| customer_id  | customer_name |\n+--------------+---------------+\n| 101          | Alice         |\n| 102          | Bob           |\n| 103          | Charlie       |\n+--------------+---------------+\n\nOrders table:\n+-------------+------------+--------------+-------------+-------------+\n| order_id    | sale_date  | order_cost   | customer_id | seller_id   |\n+-------------+------------+--------------+-------------+-------------+\n| 1           | 2020-03-01 | 1500         | 101         | 1           |\n| 2           | 2020-05-25 | 2400         | 102         | 2           |\n| 3           | 2019-05-25 | 800          | 101         | 3           |\n| 4           | 2020-09-13 | 1000         | 103         | 2           |\n| 5           | 2019-02-11 | 700          | 101         | 2           |\n+-------------+------------+--------------+-------------+-------------+\n\nSeller table:\n+-------------+-------------+\n| seller_id   | seller_name |\n+-------------+-------------+\n| 1           | Daniel      |\n| 2           | Elizabeth   |\n| 3           | Frank       |\n+-------------+-------------+\n\nResult table:\n+-------------+\n| seller_name |\n+-------------+\n| Frank       |\n+-------------+\nDaniel made 1 sale in March 2020.\nElizabeth made 2 sales in 2020 and 1 sale in 2019.\nFrank made 1 sale in 2019 but no sales in 2020.\n
    \n", "content_cn": "

    \u8868: Customer

    \n\n
    +---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| customer_id   | int     |\n| customer_name | varchar |\n+---------------+---------+\ncustomer_id \u662f\u8be5\u8868\u4e3b\u952e.\n\u8be5\u8868\u7684\u6bcf\u884c\u5305\u542b\u7f51\u4e0a\u5546\u57ce\u7684\u6bcf\u4e00\u4f4d\u987e\u5ba2\u7684\u4fe1\u606f.\n
    \n\n

    \u00a0

    \n\n

    \u8868: Orders

    \n\n
    +---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| order_id      | int     |\n| sale_date     | date    |\n| order_cost    | int     |\n| customer_id   | int     |\n| seller_id     | int     |\n+---------------+---------+\norder_id \u662f\u8be5\u8868\u4e3b\u952e.\n\u8be5\u8868\u7684\u6bcf\u884c\u5305\u542b\u7f51\u4e0a\u5546\u57ce\u7684\u6240\u6709\u8ba2\u5355\u7684\u4fe1\u606f.\nsale_date \u662f\u987e\u5ba2customer_id\u548c\u5356\u5bb6seller_id\u4e4b\u95f4\u4ea4\u6613\u7684\u65e5\u671f.\n
    \n\n

    \u00a0

    \n\n

    \u8868: Seller

    \n\n
    +---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| seller_id     | int     |\n| seller_name   | varchar |\n+---------------+---------+\nseller_id \u662f\u8be5\u8868\u4e3b\u952e.\n\u8be5\u8868\u7684\u6bcf\u884c\u5305\u542b\u6bcf\u4e00\u4f4d\u5356\u5bb6\u7684\u4fe1\u606f.\n
    \n\n

    \u00a0

    \n\n

    \u5199\u4e00\u4e2aSQL\u8bed\u53e5,\u00a0\u62a5\u544a\u6240\u6709\u57282020\u5e74\u5ea6\u6ca1\u6709\u4efb\u4f55\u5356\u51fa\u7684\u5356\u5bb6\u7684\u540d\u5b57.

    \n\n

    \u8fd4\u56de\u7ed3\u679c\u6309\u7167\u00a0seller_name\u00a0\u5347\u5e8f\u6392\u5217.

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a.

    \n\n

    \u00a0

    \n\n
    Customer \u8868:\n+--------------+---------------+\n| customer_id  | customer_name |\n+--------------+---------------+\n| 101          | Alice         |\n| 102          | Bob           |\n| 103          | Charlie       |\n+--------------+---------------+\n\nOrders \u8868:\n+-------------+------------+--------------+-------------+-------------+\n| order_id    | sale_date  | order_cost   | customer_id | seller_id   |\n+-------------+------------+--------------+-------------+-------------+\n| 1           | 2020-03-01 | 1500         | 101         | 1           |\n| 2           | 2020-05-25 | 2400         | 102         | 2           |\n| 3           | 2019-05-25 | 800          | 101         | 3           |\n| 4           | 2020-09-13 | 1000         | 103         | 2           |\n| 5           | 2019-02-11 | 700          | 101         | 2           |\n+-------------+------------+--------------+-------------+-------------+\n\nSeller \u8868:\n+-------------+-------------+\n| seller_id   | seller_name |\n+-------------+-------------+\n| 1           | Daniel      |\n| 2           | Elizabeth   |\n| 3           | Frank       |\n+-------------+-------------+\n\nResult \u8868:\n+-------------+\n| seller_name |\n+-------------+\n| Frank       |\n+-------------+\nDaniel\u57282020\u5e743\u6708\u5356\u51fa1\u6b21.\nElizabeth\u57282020\u5e74\u5356\u51fa2\u6b21, \u57282019\u5e74\u5356\u51fa1\u6b21.\nFrank\u57282019\u5e74\u5356\u51fa1\u6b21, \u57282020\u5e74\u6ca1\u6709\u5356\u51fa.\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1607](https://leetcode-cn.com/problems/sellers-with-no-sales)", "[\u6ca1\u6709\u5356\u51fa\u7684\u5356\u5bb6](/solution/1600-1699/1607.Sellers%20With%20No%20Sales/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1607](https://leetcode.com/problems/sellers-with-no-sales)", "[Sellers With No Sales](/solution/1600-1699/1607.Sellers%20With%20No%20Sales/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1748", "frontend_question_id": "1626", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/best-team-with-no-conflicts", "url_en": "https://leetcode.com/problems/best-team-with-no-conflicts", "relative_path_cn": "/solution/1600-1699/1626.Best%20Team%20With%20No%20Conflicts/README.md", "relative_path_en": "/solution/1600-1699/1626.Best%20Team%20With%20No%20Conflicts/README_EN.md", "title_cn": "\u65e0\u77db\u76fe\u7684\u6700\u4f73\u7403\u961f", "title_en": "Best Team With No Conflicts", "question_title_slug": "best-team-with-no-conflicts", "content_en": "

    You are the manager of a basketball team. For the upcoming tournament, you want to choose the team with the highest overall score. The score of the team is the sum of scores of all the players in the team.

    \n\n

    However, the basketball team is not allowed to have conflicts. A conflict exists if a younger player has a strictly higher score than an older player. A conflict does not occur between players of the same age.

    \n\n

    Given two lists, scores and ages, where each scores[i] and ages[i] represents the score and age of the ith player, respectively, return the highest overall score of all possible basketball teams.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: scores = [1,3,5,10,15], ages = [1,2,3,4,5]\nOutput: 34\nExplanation: You can choose all the players.\n
    \n\n

    Example 2:

    \n\n
    \nInput: scores = [4,5,6,5], ages = [2,1,2,1]\nOutput: 16\nExplanation: It is best to choose the last 3 players. Notice that you are allowed to choose multiple people of the same age.\n
    \n\n

    Example 3:

    \n\n
    \nInput: scores = [1,2,3,5], ages = [8,9,10,1]\nOutput: 6\nExplanation: It is best to choose the first 3 players. \n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= scores.length, ages.length <= 1000
    • \n\t
    • scores.length == ages.length
    • \n\t
    • 1 <= scores[i] <= 106
    • \n\t
    • 1 <= ages[i] <= 1000
    • \n
    \n", "content_cn": "

    \u5047\u8bbe\u4f60\u662f\u7403\u961f\u7684\u7ecf\u7406\u3002\u5bf9\u4e8e\u5373\u5c06\u5230\u6765\u7684\u9526\u6807\u8d5b\uff0c\u4f60\u60f3\u7ec4\u5408\u4e00\u652f\u603b\u4f53\u5f97\u5206\u6700\u9ad8\u7684\u7403\u961f\u3002\u7403\u961f\u7684\u5f97\u5206\u662f\u7403\u961f\u4e2d\u6240\u6709\u7403\u5458\u7684\u5206\u6570 \u603b\u548c \u3002

    \n\n

    \u7136\u800c\uff0c\u7403\u961f\u4e2d\u7684\u77db\u76fe\u4f1a\u9650\u5236\u7403\u5458\u7684\u53d1\u6325\uff0c\u6240\u4ee5\u5fc5\u987b\u9009\u51fa\u4e00\u652f \u6ca1\u6709\u77db\u76fe \u7684\u7403\u961f\u3002\u5982\u679c\u4e00\u540d\u5e74\u9f84\u8f83\u5c0f\u7403\u5458\u7684\u5206\u6570 \u4e25\u683c\u5927\u4e8e \u4e00\u540d\u5e74\u9f84\u8f83\u5927\u7684\u7403\u5458\uff0c\u5219\u5b58\u5728\u77db\u76fe\u3002\u540c\u9f84\u7403\u5458\u4e4b\u95f4\u4e0d\u4f1a\u53d1\u751f\u77db\u76fe\u3002

    \n\n

    \u7ed9\u4f60\u4e24\u4e2a\u5217\u8868 scores \u548c ages\uff0c\u5176\u4e2d\u6bcf\u7ec4 scores[i] \u548c ages[i] \u8868\u793a\u7b2c i \u540d\u7403\u5458\u7684\u5206\u6570\u548c\u5e74\u9f84\u3002\u8bf7\u4f60\u8fd4\u56de \u6240\u6709\u53ef\u80fd\u7684\u65e0\u77db\u76fe\u7403\u961f\u4e2d\u5f97\u5206\u6700\u9ad8\u90a3\u652f\u7684\u5206\u6570 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1ascores = [1,3,5,10,15], ages = [1,2,3,4,5]\n\u8f93\u51fa\uff1a34\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u9009\u4e2d\u6240\u6709\u7403\u5458\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1ascores = [4,5,6,5], ages = [2,1,2,1]\n\u8f93\u51fa\uff1a16\n\u89e3\u91ca\uff1a\u6700\u4f73\u7684\u9009\u62e9\u662f\u540e 3 \u540d\u7403\u5458\u3002\u6ce8\u610f\uff0c\u4f60\u53ef\u4ee5\u9009\u4e2d\u591a\u4e2a\u540c\u9f84\u7403\u5458\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1ascores = [1,2,3,5], ages = [8,9,10,1]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u6700\u4f73\u7684\u9009\u62e9\u662f\u524d 3 \u540d\u7403\u5458\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= scores.length, ages.length <= 1000
    • \n\t
    • scores.length == ages.length
    • \n\t
    • 1 <= scores[i] <= 106
    • \n\t
    • 1 <= ages[i] <= 1000
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int bestTeamScore(vector& scores, vector& ages) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int bestTeamScore(int[] scores, int[] ages) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def bestTeamScore(self, scores, ages):\n \"\"\"\n :type scores: List[int]\n :type ages: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def bestTeamScore(self, scores: List[int], ages: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint bestTeamScore(int* scores, int scoresSize, int* ages, int agesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int BestTeamScore(int[] scores, int[] ages) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} scores\n * @param {number[]} ages\n * @return {number}\n */\nvar bestTeamScore = function(scores, ages) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} scores\n# @param {Integer[]} ages\n# @return {Integer}\ndef best_team_score(scores, ages)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func bestTeamScore(_ scores: [Int], _ ages: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func bestTeamScore(scores []int, ages []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def bestTeamScore(scores: Array[Int], ages: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun bestTeamScore(scores: IntArray, ages: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn best_team_score(scores: Vec, ages: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $scores\n * @param Integer[] $ages\n * @return Integer\n */\n function bestTeamScore($scores, $ages) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function bestTeamScore(scores: number[], ages: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (best-team-score scores ages)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1626](https://leetcode-cn.com/problems/best-team-with-no-conflicts)", "[\u65e0\u77db\u76fe\u7684\u6700\u4f73\u7403\u961f](/solution/1600-1699/1626.Best%20Team%20With%20No%20Conflicts/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1626](https://leetcode.com/problems/best-team-with-no-conflicts)", "[Best Team With No Conflicts](/solution/1600-1699/1626.Best%20Team%20With%20No%20Conflicts/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "1747", "frontend_question_id": "1625", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/lexicographically-smallest-string-after-applying-operations", "url_en": "https://leetcode.com/problems/lexicographically-smallest-string-after-applying-operations", "relative_path_cn": "/solution/1600-1699/1625.Lexicographically%20Smallest%20String%20After%20Applying%20Operations/README.md", "relative_path_en": "/solution/1600-1699/1625.Lexicographically%20Smallest%20String%20After%20Applying%20Operations/README_EN.md", "title_cn": "\u6267\u884c\u64cd\u4f5c\u540e\u5b57\u5178\u5e8f\u6700\u5c0f\u7684\u5b57\u7b26\u4e32", "title_en": "Lexicographically Smallest String After Applying Operations", "question_title_slug": "lexicographically-smallest-string-after-applying-operations", "content_en": "

    You are given a string s of even length consisting of digits from 0 to 9, and two integers a and b.

    \r\n\r\n

    You can apply either of the following two operations any number of times and in any order on s:

    \r\n\r\n
      \r\n\t
    • Add a to all odd indices of s (0-indexed). Digits post 9 are cycled back to 0. For example, if s = "3456" and a = 5, s becomes "3951".
    • \r\n\t
    • Rotate s to the right by b positions. For example, if s = "3456" and b = 1, s becomes "6345".
    • \r\n
    \r\n\r\n

    Return the lexicographically smallest string you can obtain by applying the above operations any number of times on s.

    \r\n\r\n

    A string a is lexicographically smaller than a string b (of the same length) if in the first position where a and b differ, string a has a letter that appears earlier in the alphabet than the corresponding letter in b. For example, "0158" is lexicographically smaller than "0190" because the first position they differ is at the third letter, and '5' comes before '9'.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: s = "5525", a = 9, b = 2\r\nOutput: "2050"\r\nExplanation: We can apply the following operations:\r\nStart:  "5525"\r\nRotate: "2555"\r\nAdd:    "2454"\r\nAdd:    "2353"\r\nRotate: "5323"\r\nAdd:    "5222"\r\n\u200b\u200b\u200b\u200b\u200b\u200b\u200bAdd:    "5121"\r\n\u200b\u200b\u200b\u200b\u200b\u200b\u200bRotate: "2151"\r\n\u200b\u200b\u200b\u200b\u200b\u200b\u200bAdd:    "2050"\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\r\nThere is no way to obtain a string that is lexicographically smaller then "2050".\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: s = "74", a = 5, b = 1\r\nOutput: "24"\r\nExplanation: We can apply the following operations:\r\nStart:  "74"\r\nRotate: "47"\r\n\u200b\u200b\u200b\u200b\u200b\u200b\u200bAdd:    "42"\r\n\u200b\u200b\u200b\u200b\u200b\u200b\u200bRotate: "24"\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\r\nThere is no way to obtain a string that is lexicographically smaller then "24".\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: s = "0011", a = 4, b = 2\r\nOutput: "0011"\r\nExplanation: There are no sequence of operations that will give us a lexicographically smaller string than "0011".\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: s = "43987654", a = 7, b = 3\r\nOutput: "00553311"\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 2 <= s.length <= 100
    • \r\n\t
    • s.length is even.
    • \r\n\t
    • s consists of digits from 0 to 9 only.
    • \r\n\t
    • 1 <= a <= 9
    • \r\n\t
    • 1 <= b <= s.length - 1
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \u4ee5\u53ca\u4e24\u4e2a\u6574\u6570 a \u548c b \u3002\u5176\u4e2d\uff0c\u5b57\u7b26\u4e32 s \u7684\u957f\u5ea6\u4e3a\u5076\u6570\uff0c\u4e14\u4ec5\u7531\u6570\u5b57 0 \u5230 9 \u7ec4\u6210\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u5728 s \u4e0a\u6309\u4efb\u610f\u987a\u5e8f\u591a\u6b21\u6267\u884c\u4e0b\u9762\u4e24\u4e2a\u64cd\u4f5c\u4e4b\u4e00\uff1a

    \n\n
      \n\t
    • \u7d2f\u52a0\uff1a\u5c06\u00a0 a \u52a0\u5230 s \u4e2d\u6240\u6709\u4e0b\u6807\u4e3a\u5947\u6570\u7684\u5143\u7d20\u4e0a\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\u3002\u6570\u5b57\u4e00\u65e6\u8d85\u8fc7 9 \u5c31\u4f1a\u53d8\u6210 0\uff0c\u5982\u6b64\u5faa\u73af\u5f80\u590d\u3002\u4f8b\u5982\uff0cs = \"3456\" \u4e14 a = 5\uff0c\u5219\u6267\u884c\u6b64\u64cd\u4f5c\u540e s \u53d8\u6210 \"3951\"\u3002
    • \n\t
    • \u8f6e\u8f6c\uff1a\u5c06 s \u5411\u53f3\u8f6e\u8f6c b \u4f4d\u3002\u4f8b\u5982\uff0cs = \"3456\" \u4e14 b = 1\uff0c\u5219\u6267\u884c\u6b64\u64cd\u4f5c\u540e s \u53d8\u6210 \"6345\"\u3002
    • \n
    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u5728 s \u4e0a\u6267\u884c\u4e0a\u8ff0\u64cd\u4f5c\u4efb\u610f\u6b21\u540e\u53ef\u4ee5\u5f97\u5230\u7684 \u5b57\u5178\u5e8f\u6700\u5c0f \u7684\u5b57\u7b26\u4e32\u3002

    \n\n

    \u5982\u679c\u4e24\u4e2a\u5b57\u7b26\u4e32\u957f\u5ea6\u76f8\u540c\uff0c\u90a3\u4e48\u5b57\u7b26\u4e32 a \u5b57\u5178\u5e8f\u6bd4\u5b57\u7b26\u4e32 b \u5c0f\u53ef\u4ee5\u8fd9\u6837\u5b9a\u4e49\uff1a\u5728 a \u548c b \u51fa\u73b0\u4e0d\u540c\u7684\u7b2c\u4e00\u4e2a\u4f4d\u7f6e\u4e0a\uff0c\u5b57\u7b26\u4e32 a \u4e2d\u7684\u5b57\u7b26\u51fa\u73b0\u5728\u5b57\u6bcd\u8868\u4e2d\u7684\u65f6\u95f4\u65e9\u4e8e b \u4e2d\u7684\u5bf9\u5e94\u5b57\u7b26\u3002\u4f8b\u5982\uff0c\"0158\u201d \u5b57\u5178\u5e8f\u6bd4 \"0190\" \u5c0f\uff0c\u56e0\u4e3a\u4e0d\u540c\u7684\u7b2c\u4e00\u4e2a\u4f4d\u7f6e\u662f\u5728\u7b2c\u4e09\u4e2a\u5b57\u7b26\uff0c\u663e\u7136 '5' \u51fa\u73b0\u5728 '9' \u4e4b\u524d\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"5525\", a = 9, b = 2\n\u8f93\u51fa\uff1a\"2050\"\n\u89e3\u91ca\uff1a\u6267\u884c\u64cd\u4f5c\u5982\u4e0b\uff1a\n\u521d\u6001\uff1a\"5525\"\n\u8f6e\u8f6c\uff1a\"2555\"\n\u7d2f\u52a0\uff1a\"2454\"\n\u7d2f\u52a0\uff1a\"2353\"\n\u8f6e\u8f6c\uff1a\"5323\"\n\u7d2f\u52a0\uff1a\"5222\"\n\u7d2f\u52a0\uff1a\"5121\"\n\u8f6e\u8f6c\uff1a\"2151\"\n\u7d2f\u52a0\uff1a\"2050\"\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\n\u65e0\u6cd5\u83b7\u5f97\u5b57\u5178\u5e8f\u5c0f\u4e8e \"2050\" \u7684\u5b57\u7b26\u4e32\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"74\", a = 5, b = 1\n\u8f93\u51fa\uff1a\"24\"\n\u89e3\u91ca\uff1a\u6267\u884c\u64cd\u4f5c\u5982\u4e0b\uff1a\n\u521d\u6001\uff1a\"74\"\n\u8f6e\u8f6c\uff1a\"47\"\n\u7d2f\u52a0\uff1a\"42\"\n\u8f6e\u8f6c\uff1a\"24\"\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\n\u65e0\u6cd5\u83b7\u5f97\u5b57\u5178\u5e8f\u5c0f\u4e8e \"24\" \u7684\u5b57\u7b26\u4e32\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"0011\", a = 4, b = 2\n\u8f93\u51fa\uff1a\"0011\"\n\u89e3\u91ca\uff1a\u65e0\u6cd5\u83b7\u5f97\u5b57\u5178\u5e8f\u5c0f\u4e8e \"0011\" \u7684\u5b57\u7b26\u4e32\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"43987654\", a = 7, b = 3\n\u8f93\u51fa\uff1a\"00553311\"\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= s.length <= 100
    • \n\t
    • s.length \u662f\u5076\u6570
    • \n\t
    • s \u4ec5\u7531\u6570\u5b57 0 \u5230 9 \u7ec4\u6210
    • \n\t
    • 1 <= a <= 9
    • \n\t
    • 1 <= b <= s.length - 1
    • \n
    \n", "tags_en": ["Depth-first Search", "Breadth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string findLexSmallestString(string s, int a, int b) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String findLexSmallestString(String s, int a, int b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findLexSmallestString(self, s, a, b):\n \"\"\"\n :type s: str\n :type a: int\n :type b: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findLexSmallestString(self, s: str, a: int, b: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "char * findLexSmallestString(char * s, int a, int b){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string FindLexSmallestString(string s, int a, int b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number} a\n * @param {number} b\n * @return {string}\n */\nvar findLexSmallestString = function(s, a, b) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer} a\n# @param {Integer} b\n# @return {String}\ndef find_lex_smallest_string(s, a, b)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findLexSmallestString(_ s: String, _ a: Int, _ b: Int) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findLexSmallestString(s string, a int, b int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findLexSmallestString(s: String, a: Int, b: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findLexSmallestString(s: String, a: Int, b: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_lex_smallest_string(s: String, a: i32, b: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer $a\n * @param Integer $b\n * @return String\n */\n function findLexSmallestString($s, $a, $b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findLexSmallestString(s: string, a: number, b: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-lex-smallest-string s a b)\n (-> string? exact-integer? exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1625](https://leetcode-cn.com/problems/lexicographically-smallest-string-after-applying-operations)", "[\u6267\u884c\u64cd\u4f5c\u540e\u5b57\u5178\u5e8f\u6700\u5c0f\u7684\u5b57\u7b26\u4e32](/solution/1600-1699/1625.Lexicographically%20Smallest%20String%20After%20Applying%20Operations/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1625](https://leetcode.com/problems/lexicographically-smallest-string-after-applying-operations)", "[Lexicographically Smallest String After Applying Operations](/solution/1600-1699/1625.Lexicographically%20Smallest%20String%20After%20Applying%20Operations/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`", "Medium", ""]}, {"question_id": "1746", "frontend_question_id": "1624", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/largest-substring-between-two-equal-characters", "url_en": "https://leetcode.com/problems/largest-substring-between-two-equal-characters", "relative_path_cn": "/solution/1600-1699/1624.Largest%20Substring%20Between%20Two%20Equal%20Characters/README.md", "relative_path_en": "/solution/1600-1699/1624.Largest%20Substring%20Between%20Two%20Equal%20Characters/README_EN.md", "title_cn": "\u4e24\u4e2a\u76f8\u540c\u5b57\u7b26\u4e4b\u95f4\u7684\u6700\u957f\u5b50\u5b57\u7b26\u4e32", "title_en": "Largest Substring Between Two Equal Characters", "question_title_slug": "largest-substring-between-two-equal-characters", "content_en": "

    Given a string s, return the length of the longest substring between two equal characters, excluding the two characters. If there is no such substring return -1.

    \n\n

    A substring is a contiguous sequence of characters within a string.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "aa"\nOutput: 0\nExplanation: The optimal substring here is an empty substring between the two 'a's.
    \n\n

    Example 2:

    \n\n
    \nInput: s = "abca"\nOutput: 2\nExplanation: The optimal substring here is "bc".\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "cbzxy"\nOutput: -1\nExplanation: There are no characters that appear twice in s.\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "cabbac"\nOutput: 4\nExplanation: The optimal substring here is "abba". Other non-optimal substrings include "bb" and "".\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 300
    • \n\t
    • s contains only lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s\uff0c\u8bf7\u4f60\u8fd4\u56de \u4e24\u4e2a\u76f8\u540c\u5b57\u7b26\u4e4b\u95f4\u7684\u6700\u957f\u5b50\u5b57\u7b26\u4e32\u7684\u957f\u5ea6 \uff0c\u8ba1\u7b97\u957f\u5ea6\u65f6\u4e0d\u542b\u8fd9\u4e24\u4e2a\u5b57\u7b26\u3002\u5982\u679c\u4e0d\u5b58\u5728\u8fd9\u6837\u7684\u5b50\u5b57\u7b26\u4e32\uff0c\u8fd4\u56de -1 \u3002

    \n\n

    \u5b50\u5b57\u7b26\u4e32 \u662f\u5b57\u7b26\u4e32\u4e2d\u7684\u4e00\u4e2a\u8fde\u7eed\u5b57\u7b26\u5e8f\u5217\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1as = \"aa\"\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6700\u4f18\u7684\u5b50\u5b57\u7b26\u4e32\u662f\u4e24\u4e2a 'a' \u4e4b\u95f4\u7684\u7a7a\u5b50\u5b57\u7b26\u4e32\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1as = \"abca\"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6700\u4f18\u7684\u5b50\u5b57\u7b26\u4e32\u662f \"bc\" \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1as = \"cbzxy\"\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1as \u4e2d\u4e0d\u5b58\u5728\u51fa\u73b0\u51fa\u73b0\u4e24\u6b21\u7684\u5b57\u7b26\uff0c\u6240\u4ee5\u8fd4\u56de -1 \u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1as = \"cabbac\"\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u6700\u4f18\u7684\u5b50\u5b57\u7b26\u4e32\u662f \"abba\" \uff0c\u5176\u4ed6\u7684\u975e\u6700\u4f18\u89e3\u5305\u62ec \"bb\" \u548c \"\" \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 300
    • \n\t
    • s \u53ea\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxLengthBetweenEqualCharacters(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxLengthBetweenEqualCharacters(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxLengthBetweenEqualCharacters(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxLengthBetweenEqualCharacters(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxLengthBetweenEqualCharacters(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxLengthBetweenEqualCharacters(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar maxLengthBetweenEqualCharacters = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef max_length_between_equal_characters(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxLengthBetweenEqualCharacters(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxLengthBetweenEqualCharacters(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxLengthBetweenEqualCharacters(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxLengthBetweenEqualCharacters(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_length_between_equal_characters(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function maxLengthBetweenEqualCharacters($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxLengthBetweenEqualCharacters(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-length-between-equal-characters s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1624](https://leetcode-cn.com/problems/largest-substring-between-two-equal-characters)", "[\u4e24\u4e2a\u76f8\u540c\u5b57\u7b26\u4e4b\u95f4\u7684\u6700\u957f\u5b50\u5b57\u7b26\u4e32](/solution/1600-1699/1624.Largest%20Substring%20Between%20Two%20Equal%20Characters/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1624](https://leetcode.com/problems/largest-substring-between-two-equal-characters)", "[Largest Substring Between Two Equal Characters](/solution/1600-1699/1624.Largest%20Substring%20Between%20Two%20Equal%20Characters/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1745", "frontend_question_id": "1602", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/find-nearest-right-node-in-binary-tree", "url_en": "https://leetcode.com/problems/find-nearest-right-node-in-binary-tree", "relative_path_cn": "/solution/1600-1699/1602.Find%20Nearest%20Right%20Node%20in%20Binary%20Tree/README.md", "relative_path_en": "/solution/1600-1699/1602.Find%20Nearest%20Right%20Node%20in%20Binary%20Tree/README_EN.md", "title_cn": "\u627e\u5230\u4e8c\u53c9\u6811\u4e2d\u6700\u8fd1\u7684\u53f3\u4fa7\u8282\u70b9", "title_en": "Find Nearest Right Node in Binary Tree", "question_title_slug": "find-nearest-right-node-in-binary-tree", "content_en": "

    Given the root of a binary tree and a node u in the tree, return the nearest node on the same level that is to the right of u, or return null if u is the rightmost node in its level.

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: root = [1,2,3,null,4,5,6], u = 4\nOutput: 5\nExplanation: The nearest node on the same level to the right of node 4 is node 5.\n
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: root = [3,null,4,2], u = 2\nOutput: null\nExplanation: There are no nodes to the right of 2.\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = [1], u = 1\nOutput: null\n
    \n\n

    Example 4:

    \n\n
    \nInput: root = [3,4,2,null,null,null,1], u = 4\nOutput: 2\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 105].
    • \n\t
    • 1 <= Node.val <= 105
    • \n\t
    • All values in the tree are distinct.
    • \n\t
    • u is a node in the binary tree rooted at root.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u68f5\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9\u00a0root\u00a0\u548c\u6811\u4e2d\u7684\u4e00\u4e2a\u8282\u70b9\u00a0u\u00a0\uff0c\u8fd4\u56de\u4e0e\u00a0u\u00a0\u6240\u5728\u5c42\u4e2d\u8ddd\u79bb\u6700\u8fd1\u7684\u53f3\u4fa7\u8282\u70b9\uff0c\u5f53\u00a0u\u00a0\u662f\u6240\u5728\u5c42\u4e2d\u6700\u53f3\u4fa7\u7684\u8282\u70b9\uff0c\u8fd4\u56de\u00a0null\u00a0\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aroot = [1,2,3,null,4,5,6], u = 4\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u8282\u70b9 4 \u6240\u5728\u5c42\u4e2d\uff0c\u6700\u8fd1\u7684\u53f3\u4fa7\u8282\u70b9\u662f\u8282\u70b9 5\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aroot = [3,null,4,2], u = 2\n\u8f93\u51fa\uff1anull\n\u89e3\u91ca\uff1a2 \u7684\u53f3\u4fa7\u6ca1\u6709\u8282\u70b9\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [1], u = 1\n\u8f93\u51fa\uff1anull\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [3,4,2,null,null,null,1], u = 4\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a:

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u4e2a\u6570\u7684\u8303\u56f4\u662f\u00a0[1, 105]\u00a0\u3002
    • \n\t
    • 1 <= Node.val <= 105
    • \n\t
    • \u6811\u4e2d\u6240\u6709\u8282\u70b9\u7684\u503c\u662f\u552f\u4e00\u7684\u3002
    • \n\t
    • u\u00a0\u662f\u4ee5\u00a0root\u00a0\u4e3a\u6839\u7684\u4e8c\u53c9\u6811\u7684\u4e00\u4e2a\u8282\u70b9\u3002
    • \n
    \n", "tags_en": ["Tree", "Breadth-first Search"], "tags_cn": ["\u6811", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* findNearestRightNode(TreeNode* root, TreeNode* u) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode findNearestRightNode(TreeNode root, TreeNode u) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def findNearestRightNode(self, root, u):\n \"\"\"\n :type root: TreeNode\n :type u: TreeNode\n :rtype: TreeNode\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def findNearestRightNode(self, root: TreeNode, u: TreeNode) -> TreeNode:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* findNearestRightNode(struct TreeNode* root, struct TreeNode* u){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode FindNearestRightNode(TreeNode root, TreeNode u) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {TreeNode} u\n * @return {TreeNode}\n */\nvar findNearestRightNode = function(root, u) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @param {TreeNode} u\n# @return {TreeNode}\ndef find_nearest_right_node(root, u)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func findNearestRightNode(_ root: TreeNode?, _ u: TreeNode?) -> TreeNode? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc findNearestRightNode(root *TreeNode, u *TreeNode) *TreeNode {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def findNearestRightNode(root: TreeNode, u: TreeNode): TreeNode = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun findNearestRightNode(root: TreeNode?, u: TreeNode?): TreeNode? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param TreeNode $u\n * @return TreeNode\n */\n function findNearestRightNode($root, $u) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {TreeNode} u\n * @return {TreeNode}\n */\nfunction findNearestRightNode(root: TreeNode, u: TreeNode): TreeNode | null {\n \n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1602](https://leetcode-cn.com/problems/find-nearest-right-node-in-binary-tree)", "[\u627e\u5230\u4e8c\u53c9\u6811\u4e2d\u6700\u8fd1\u7684\u53f3\u4fa7\u8282\u70b9](/solution/1600-1699/1602.Find%20Nearest%20Right%20Node%20in%20Binary%20Tree/README.md)", "`\u6811`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1602](https://leetcode.com/problems/find-nearest-right-node-in-binary-tree)", "[Find Nearest Right Node in Binary Tree](/solution/1600-1699/1602.Find%20Nearest%20Right%20Node%20in%20Binary%20Tree/README_EN.md)", "`Tree`,`Breadth-first Search`", "Medium", "\ud83d\udd12"]}, {"question_id": "1744", "frontend_question_id": "1639", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-ways-to-form-a-target-string-given-a-dictionary", "url_en": "https://leetcode.com/problems/number-of-ways-to-form-a-target-string-given-a-dictionary", "relative_path_cn": "/solution/1600-1699/1639.Number%20of%20Ways%20to%20Form%20a%20Target%20String%20Given%20a%20Dictionary/README.md", "relative_path_en": "/solution/1600-1699/1639.Number%20of%20Ways%20to%20Form%20a%20Target%20String%20Given%20a%20Dictionary/README_EN.md", "title_cn": "\u901a\u8fc7\u7ed9\u5b9a\u8bcd\u5178\u6784\u9020\u76ee\u6807\u5b57\u7b26\u4e32\u7684\u65b9\u6848\u6570", "title_en": "Number of Ways to Form a Target String Given a Dictionary", "question_title_slug": "number-of-ways-to-form-a-target-string-given-a-dictionary", "content_en": "

    You are given a list of strings of the same length words and a string target.

    \n\n

    Your task is to form target using the given words under the following rules:

    \n\n
      \n\t
    • target should be formed from left to right.
    • \n\t
    • To form the ith character (0-indexed) of target, you can choose the kth character of the jth string in words if target[i] = words[j][k].
    • \n\t
    • Once you use the kth character of the jth string of words, you can no longer use the xth character of any string in words where x <= k. In other words, all characters to the left of or at index k become unusuable for every string.
    • \n\t
    • Repeat the process until you form the string target.
    • \n
    \n\n

    Notice that you can use multiple characters from the same string in words provided the conditions above are met.

    \n\n

    Return the number of ways to form target from words. Since the answer may be too large, return it modulo 109 + 7.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: words = ["acca","bbbb","caca"], target = "aba"\nOutput: 6\nExplanation: There are 6 ways to form target.\n"aba" -> index 0 ("acca"), index 1 ("bbbb"), index 3 ("caca")\n"aba" -> index 0 ("acca"), index 2 ("bbbb"), index 3 ("caca")\n"aba" -> index 0 ("acca"), index 1 ("bbbb"), index 3 ("acca")\n"aba" -> index 0 ("acca"), index 2 ("bbbb"), index 3 ("acca")\n"aba" -> index 1 ("caca"), index 2 ("bbbb"), index 3 ("acca")\n"aba" -> index 1 ("caca"), index 2 ("bbbb"), index 3 ("caca")\n
    \n\n

    Example 2:

    \n\n
    \nInput: words = ["abba","baab"], target = "bab"\nOutput: 4\nExplanation: There are 4 ways to form target.\n"bab" -> index 0 ("baab"), index 1 ("baab"), index 2 ("abba")\n"bab" -> index 0 ("baab"), index 1 ("baab"), index 3 ("baab")\n"bab" -> index 0 ("baab"), index 2 ("baab"), index 3 ("baab")\n"bab" -> index 1 ("abba"), index 2 ("baab"), index 3 ("baab")\n
    \n\n

    Example 3:

    \n\n
    \nInput: words = ["abcd"], target = "abcd"\nOutput: 1\n
    \n\n

    Example 4:

    \n\n
    \nInput: words = ["abab","baba","abba","baab"], target = "abba"\nOutput: 16\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= words.length <= 1000
    • \n\t
    • 1 <= words[i].length <= 1000
    • \n\t
    • All strings in words have the same length.
    • \n\t
    • 1 <= target.length <= 1000
    • \n\t
    • words[i] and target contain only lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32\u5217\u8868 words\u00a0\u548c\u4e00\u4e2a\u76ee\u6807\u5b57\u7b26\u4e32\u00a0target \u3002words \u4e2d\u6240\u6709\u5b57\u7b26\u4e32\u90fd\u00a0\u957f\u5ea6\u76f8\u540c\u00a0\u00a0\u3002

    \n\n

    \u4f60\u7684\u76ee\u6807\u662f\u4f7f\u7528\u7ed9\u5b9a\u7684 words\u00a0\u5b57\u7b26\u4e32\u5217\u8868\u6309\u7167\u4e0b\u8ff0\u89c4\u5219\u6784\u9020\u00a0target\u00a0\uff1a

    \n\n
      \n\t
    • \u4ece\u5de6\u5230\u53f3\u4f9d\u6b21\u6784\u9020\u00a0target\u00a0\u7684\u6bcf\u4e00\u4e2a\u5b57\u7b26\u3002
    • \n\t
    • \u4e3a\u4e86\u5f97\u5230\u00a0target \u7b2c\u00a0i\u00a0\u4e2a\u5b57\u7b26\uff08\u4e0b\u6807\u4ece 0\u00a0\u5f00\u59cb\uff09\uff0c\u5f53\u00a0target[i] = words[j][k]\u00a0\u65f6\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u00a0words\u00a0\u5217\u8868\u4e2d\u7b2c j\u00a0\u4e2a\u5b57\u7b26\u4e32\u7684\u7b2c k\u00a0\u4e2a\u5b57\u7b26\u3002
    • \n\t
    • \u4e00\u65e6\u4f60\u4f7f\u7528\u4e86 words\u00a0\u4e2d\u7b2c j\u00a0\u4e2a\u5b57\u7b26\u4e32\u7684\u7b2c k\u00a0\u4e2a\u5b57\u7b26\uff0c\u4f60\u4e0d\u80fd\u518d\u4f7f\u7528 words\u00a0\u5b57\u7b26\u4e32\u5217\u8868\u4e2d\u4efb\u610f\u5355\u8bcd\u7684\u7b2c x\u00a0\u4e2a\u5b57\u7b26\uff08x <= k\uff09\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u6240\u6709\u5355\u8bcd\u4e0b\u6807\u5c0f\u4e8e\u7b49\u4e8e k\u00a0\u7684\u5b57\u7b26\u90fd\u4e0d\u80fd\u518d\u88ab\u4f7f\u7528\u3002
    • \n\t
    • \u8bf7\u4f60\u91cd\u590d\u6b64\u8fc7\u7a0b\u76f4\u5230\u5f97\u5230\u76ee\u6807\u5b57\u7b26\u4e32\u00a0target\u00a0\u3002
    • \n
    \n\n

    \u8bf7\u6ce8\u610f\uff0c \u5728\u6784\u9020\u76ee\u6807\u5b57\u7b26\u4e32\u7684\u8fc7\u7a0b\u4e2d\uff0c\u4f60\u53ef\u4ee5\u6309\u7167\u4e0a\u8ff0\u89c4\u5b9a\u4f7f\u7528 words\u00a0\u5217\u8868\u4e2d \u540c\u4e00\u4e2a\u5b57\u7b26\u4e32\u00a0\u7684 \u591a\u4e2a\u5b57\u7b26\u00a0\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u4f7f\u7528 words\u00a0\u6784\u9020 target\u00a0\u7684\u65b9\u6848\u6570\u3002\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u4f1a\u5f88\u5927\uff0c\u8bf7\u5bf9 109 + 7\u00a0\u53d6\u4f59\u00a0\u540e\u8fd4\u56de\u3002

    \n\n

    \uff08\u8bd1\u8005\u6ce8\uff1a\u6b64\u9898\u76ee\u6c42\u7684\u662f\u6709\u591a\u5c11\u4e2a\u4e0d\u540c\u7684 k\u00a0\u5e8f\u5217\uff0c\u8be6\u60c5\u8bf7\u89c1\u793a\u4f8b\u3002\uff09

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1awords = [\"acca\",\"bbbb\",\"caca\"], target = \"aba\"\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u603b\u5171\u6709 6 \u79cd\u65b9\u6cd5\u6784\u9020\u76ee\u6807\u4e32\u3002\n\"aba\" -> \u4e0b\u6807\u4e3a 0 (\"acca\")\uff0c\u4e0b\u6807\u4e3a 1 (\"bbbb\")\uff0c\u4e0b\u6807\u4e3a 3 (\"caca\")\n\"aba\" -> \u4e0b\u6807\u4e3a 0 (\"acca\")\uff0c\u4e0b\u6807\u4e3a 2 (\"bbbb\")\uff0c\u4e0b\u6807\u4e3a 3 (\"caca\")\n\"aba\" -> \u4e0b\u6807\u4e3a 0 (\"acca\")\uff0c\u4e0b\u6807\u4e3a 1 (\"bbbb\")\uff0c\u4e0b\u6807\u4e3a 3 (\"acca\")\n\"aba\" -> \u4e0b\u6807\u4e3a 0 (\"acca\")\uff0c\u4e0b\u6807\u4e3a 2 (\"bbbb\")\uff0c\u4e0b\u6807\u4e3a 3 (\"acca\")\n\"aba\" -> \u4e0b\u6807\u4e3a 1 (\"caca\")\uff0c\u4e0b\u6807\u4e3a 2 (\"bbbb\")\uff0c\u4e0b\u6807\u4e3a 3 (\"acca\")\n\"aba\" -> \u4e0b\u6807\u4e3a 1 (\"caca\")\uff0c\u4e0b\u6807\u4e3a 2 (\"bbbb\")\uff0c\u4e0b\u6807\u4e3a 3 (\"caca\")\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1awords = [\"abba\",\"baab\"], target = \"bab\"\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u603b\u5171\u6709 4 \u79cd\u4e0d\u540c\u5f62\u6210 target \u7684\u65b9\u6cd5\u3002\n\"bab\" -> \u4e0b\u6807\u4e3a 0 (\"baab\")\uff0c\u4e0b\u6807\u4e3a 1 (\"baab\")\uff0c\u4e0b\u6807\u4e3a 2 (\"abba\")\n\"bab\" -> \u4e0b\u6807\u4e3a 0 (\"baab\")\uff0c\u4e0b\u6807\u4e3a 1 (\"baab\")\uff0c\u4e0b\u6807\u4e3a 3 (\"baab\")\n\"bab\" -> \u4e0b\u6807\u4e3a 0 (\"baab\")\uff0c\u4e0b\u6807\u4e3a 2 (\"baab\")\uff0c\u4e0b\u6807\u4e3a 3 (\"baab\")\n\"bab\" -> \u4e0b\u6807\u4e3a 1 (\"abba\")\uff0c\u4e0b\u6807\u4e3a 2 (\"baab\")\uff0c\u4e0b\u6807\u4e3a 3 (\"baab\")\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1awords = [\"abcd\"], target = \"abcd\"\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1awords = [\"abab\",\"baba\",\"abba\",\"baab\"], target = \"abba\"\n\u8f93\u51fa\uff1a16\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= words.length <= 1000
    • \n\t
    • 1 <= words[i].length <= 1000
    • \n\t
    • words\u00a0\u4e2d\u6240\u6709\u5355\u8bcd\u957f\u5ea6\u76f8\u540c\u3002
    • \n\t
    • 1 <= target.length <= 1000
    • \n\t
    • words[i]\u00a0\u548c\u00a0target\u00a0\u90fd\u4ec5\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numWays(vector& words, string target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numWays(String[] words, String target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numWays(self, words, target):\n \"\"\"\n :type words: List[str]\n :type target: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numWays(self, words: List[str], target: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numWays(char ** words, int wordsSize, char * target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumWays(string[] words, string target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @param {string} target\n * @return {number}\n */\nvar numWays = function(words, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @param {String} target\n# @return {Integer}\ndef num_ways(words, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numWays(_ words: [String], _ target: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numWays(words []string, target string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numWays(words: Array[String], target: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numWays(words: Array, target: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_ways(words: Vec, target: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @param String $target\n * @return Integer\n */\n function numWays($words, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numWays(words: string[], target: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-ways words target)\n (-> (listof string?) string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1639](https://leetcode-cn.com/problems/number-of-ways-to-form-a-target-string-given-a-dictionary)", "[\u901a\u8fc7\u7ed9\u5b9a\u8bcd\u5178\u6784\u9020\u76ee\u6807\u5b57\u7b26\u4e32\u7684\u65b9\u6848\u6570](/solution/1600-1699/1639.Number%20of%20Ways%20to%20Form%20a%20Target%20String%20Given%20a%20Dictionary/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1639](https://leetcode.com/problems/number-of-ways-to-form-a-target-string-given-a-dictionary)", "[Number of Ways to Form a Target String Given a Dictionary](/solution/1600-1699/1639.Number%20of%20Ways%20to%20Form%20a%20Target%20String%20Given%20a%20Dictionary/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1743", "frontend_question_id": "1638", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-substrings-that-differ-by-one-character", "url_en": "https://leetcode.com/problems/count-substrings-that-differ-by-one-character", "relative_path_cn": "/solution/1600-1699/1638.Count%20Substrings%20That%20Differ%20by%20One%20Character/README.md", "relative_path_en": "/solution/1600-1699/1638.Count%20Substrings%20That%20Differ%20by%20One%20Character/README_EN.md", "title_cn": "\u7edf\u8ba1\u53ea\u5dee\u4e00\u4e2a\u5b57\u7b26\u7684\u5b50\u4e32\u6570\u76ee", "title_en": "Count Substrings That Differ by One Character", "question_title_slug": "count-substrings-that-differ-by-one-character", "content_en": "

    Given two strings s and t, find the number of ways you can choose a non-empty substring of s and replace a single character by a different character such that the resulting substring is a substring of t. In other words, find the number of substrings in s that differ from some substring in t by exactly one character.

    \n\n

    For example, the underlined substrings in "computer" and "computation" only differ by the 'e'/'a', so this is a valid way.

    \n\n

    Return the number of substrings that satisfy the condition above.

    \n\n

    A substring is a contiguous sequence of characters within a string.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "aba", t = "baba"\nOutput: 6\nExplanation: The following are the pairs of substrings from s and t that differ by exactly 1 character:\n("aba", "baba")\n("aba", "baba")\n("aba", "baba")\n("aba", "baba")\n("aba", "baba")\n("aba", "baba")\nThe underlined portions are the substrings that are chosen from s and t.\n
    \n\u200b\u200bExample 2:\n\n
    \nInput: s = "ab", t = "bb"\nOutput: 3\nExplanation: The following are the pairs of substrings from s and t that differ by 1 character:\n("ab", "bb")\n("ab", "bb")\n("ab", "bb")\n\u200b\u200b\u200b\u200bThe underlined portions are the substrings that are chosen from s and t.\n
    \nExample 3:\n\n
    \nInput: s = "a", t = "a"\nOutput: 0\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "abe", t = "bbc"\nOutput: 10\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length, t.length <= 100
    • \n\t
    • s and t consist of lowercase English letters only.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u5b57\u7b26\u4e32\u00a0s \u548c\u00a0t\u00a0\uff0c\u8bf7\u4f60\u627e\u51fa s\u00a0\u4e2d\u7684\u975e\u7a7a\u5b50\u4e32\u7684\u6570\u76ee\uff0c\u8fd9\u4e9b\u5b50\u4e32\u6ee1\u8db3\u66ff\u6362 \u4e00\u4e2a\u4e0d\u540c\u5b57\u7b26\u00a0\u4ee5\u540e\uff0c\u662f t\u00a0\u4e32\u7684\u5b50\u4e32\u3002\u6362\u8a00\u4e4b\uff0c\u8bf7\u4f60\u627e\u5230 s\u00a0\u548c t\u00a0\u4e32\u4e2d \u6070\u597d\u00a0\u53ea\u6709\u4e00\u4e2a\u5b57\u7b26\u4e0d\u540c\u7684\u5b50\u5b57\u7b26\u4e32\u5bf9\u7684\u6570\u76ee\u3002

    \n\n

    \u6bd4\u65b9\u8bf4\uff0c\u00a0\"computer\" \u548c\u00a0\"computation\" \u52a0\u7c97\u90e8\u5206\u53ea\u6709\u4e00\u4e2a\u5b57\u7b26\u4e0d\u540c\uff1a\u00a0'e'/'a'\u00a0\uff0c\u6240\u4ee5\u8fd9\u4e00\u5bf9\u5b50\u5b57\u7b26\u4e32\u4f1a\u7ed9\u7b54\u6848\u52a0 1 \u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u6ee1\u8db3\u4e0a\u8ff0\u6761\u4ef6\u7684\u4e0d\u540c\u5b50\u5b57\u7b26\u4e32\u5bf9\u6570\u76ee\u3002

    \n\n

    \u4e00\u4e2a \u5b50\u5b57\u7b26\u4e32\u00a0\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\u4e2d\u8fde\u7eed\u7684\u5b57\u7b26\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"aba\", t = \"baba\"\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u4ee5\u4e0b\u4e3a\u53ea\u76f8\u5dee 1 \u4e2a\u5b57\u7b26\u7684 s \u548c t \u4e32\u7684\u5b50\u5b57\u7b26\u4e32\u5bf9\uff1a\n(\"aba\", \"baba\")\n(\"aba\", \"baba\")\n(\"aba\", \"baba\")\n(\"aba\", \"baba\")\n(\"aba\", \"baba\")\n(\"aba\", \"baba\")\n\u52a0\u7c97\u90e8\u5206\u5206\u522b\u8868\u793a s \u548c t \u4e32\u9009\u51fa\u6765\u7684\u5b50\u5b57\u7b26\u4e32\u3002\n
    \n\u793a\u4f8b 2\uff1a\n\n
    \n\u8f93\u5165\uff1as = \"ab\", t = \"bb\"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u4ee5\u4e0b\u4e3a\u53ea\u76f8\u5dee 1 \u4e2a\u5b57\u7b26\u7684 s \u548c t \u4e32\u7684\u5b50\u5b57\u7b26\u4e32\u5bf9\uff1a\n(\"ab\", \"bb\")\n(\"ab\", \"bb\")\n(\"ab\", \"bb\")\n\u52a0\u7c97\u90e8\u5206\u5206\u522b\u8868\u793a s \u548c t \u4e32\u9009\u51fa\u6765\u7684\u5b50\u5b57\u7b26\u4e32\u3002\n
    \n\u793a\u4f8b 3\uff1a\n\n
    \n\u8f93\u5165\uff1as = \"a\", t = \"a\"\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"abe\", t = \"bbc\"\n\u8f93\u51fa\uff1a10\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length, t.length <= 100
    • \n\t
    • s \u548c\u00a0t\u00a0\u90fd\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    • \n
    \n", "tags_en": ["Trie", "Hash Table", "String"], "tags_cn": ["\u5b57\u5178\u6811", "\u54c8\u5e0c\u8868", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countSubstrings(string s, string t) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countSubstrings(String s, String t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countSubstrings(self, s, t):\n \"\"\"\n :type s: str\n :type t: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countSubstrings(self, s: str, t: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countSubstrings(char * s, char * t){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountSubstrings(string s, string t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string} t\n * @return {number}\n */\nvar countSubstrings = function(s, t) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String} t\n# @return {Integer}\ndef count_substrings(s, t)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countSubstrings(_ s: String, _ t: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countSubstrings(s string, t string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countSubstrings(s: String, t: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countSubstrings(s: String, t: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_substrings(s: String, t: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String $t\n * @return Integer\n */\n function countSubstrings($s, $t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countSubstrings(s: string, t: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-substrings s t)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1638](https://leetcode-cn.com/problems/count-substrings-that-differ-by-one-character)", "[\u7edf\u8ba1\u53ea\u5dee\u4e00\u4e2a\u5b57\u7b26\u7684\u5b50\u4e32\u6570\u76ee](/solution/1600-1699/1638.Count%20Substrings%20That%20Differ%20by%20One%20Character/README.md)", "`\u5b57\u5178\u6811`,`\u54c8\u5e0c\u8868`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1638](https://leetcode.com/problems/count-substrings-that-differ-by-one-character)", "[Count Substrings That Differ by One Character](/solution/1600-1699/1638.Count%20Substrings%20That%20Differ%20by%20One%20Character/README_EN.md)", "`Trie`,`Hash Table`,`String`", "Medium", ""]}, {"question_id": "1742", "frontend_question_id": "1637", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/widest-vertical-area-between-two-points-containing-no-points", "url_en": "https://leetcode.com/problems/widest-vertical-area-between-two-points-containing-no-points", "relative_path_cn": "/solution/1600-1699/1637.Widest%20Vertical%20Area%20Between%20Two%20Points%20Containing%20No%20Points/README.md", "relative_path_en": "/solution/1600-1699/1637.Widest%20Vertical%20Area%20Between%20Two%20Points%20Containing%20No%20Points/README_EN.md", "title_cn": "\u4e24\u70b9\u4e4b\u95f4\u4e0d\u5305\u542b\u4efb\u4f55\u70b9\u7684\u6700\u5bbd\u5782\u76f4\u9762\u79ef", "title_en": "Widest Vertical Area Between Two Points Containing No Points", "question_title_slug": "widest-vertical-area-between-two-points-containing-no-points", "content_en": "

    Given n points on a 2D plane where points[i] = [xi, yi], Return the widest vertical area between two points such that no points are inside the area.

    \n\n

    A vertical area is an area of fixed-width extending infinitely along the y-axis (i.e., infinite height). The widest vertical area is the one with the maximum width.

    \n\n

    Note that points on the edge of a vertical area are not considered included in the area.

    \n\n

     

    \n

    Example 1:

    \n\"\"\u200b\n
    \nInput: points = [[8,7],[9,9],[7,4],[9,7]]\nOutput: 1\nExplanation: Both the red and the blue area are optimal.\n
    \n\n

    Example 2:

    \n\n
    \nInput: points = [[3,1],[9,0],[1,0],[1,4],[5,3],[8,8]]\nOutput: 3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == points.length
    • \n\t
    • 2 <= n <= 105
    • \n\t
    • points[i].length == 2
    • \n\t
    • 0 <= xi, yi <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u00a0n\u00a0\u4e2a\u4e8c\u7ef4\u5e73\u9762\u4e0a\u7684\u70b9 points \uff0c\u5176\u4e2d\u00a0points[i] = [xi, yi]\u00a0\uff0c\u8bf7\u4f60\u8fd4\u56de\u4e24\u70b9\u4e4b\u95f4\u5185\u90e8\u4e0d\u5305\u542b\u4efb\u4f55\u70b9\u7684\u00a0\u6700\u5bbd\u5782\u76f4\u9762\u79ef\u00a0\u7684\u5bbd\u5ea6\u3002

    \n\n

    \u5782\u76f4\u9762\u79ef \u7684\u5b9a\u4e49\u662f\u56fa\u5b9a\u5bbd\u5ea6\uff0c\u800c y \u8f74\u4e0a\u65e0\u9650\u5ef6\u4f38\u7684\u4e00\u5757\u533a\u57df\uff08\u4e5f\u5c31\u662f\u9ad8\u5ea6\u4e3a\u65e0\u7a77\u5927\uff09\u3002 \u6700\u5bbd\u5782\u76f4\u9762\u79ef\u00a0\u4e3a\u5bbd\u5ea6\u6700\u5927\u7684\u4e00\u4e2a\u5782\u76f4\u9762\u79ef\u3002

    \n\n

    \u8bf7\u6ce8\u610f\uff0c\u5782\u76f4\u533a\u57df\u00a0\u8fb9\u4e0a\u00a0\u7684\u70b9\u00a0\u4e0d\u5728\u00a0\u533a\u57df\u5185\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\u200b\n
    \n\u8f93\u5165\uff1apoints = [[8,7],[9,9],[7,4],[9,7]]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u7ea2\u8272\u533a\u57df\u548c\u84dd\u8272\u533a\u57df\u90fd\u662f\u6700\u4f18\u533a\u57df\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1apoints = [[3,1],[9,0],[1,0],[1,4],[5,3],[8,8]]\n\u8f93\u51fa\uff1a3\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == points.length
    • \n\t
    • 2 <= n <= 105
    • \n\t
    • points[i].length == 2
    • \n\t
    • 0 <= xi, yi\u00a0<= 109
    • \n
    \n", "tags_en": ["Sort"], "tags_cn": ["\u6392\u5e8f"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxWidthOfVerticalArea(vector>& points) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxWidthOfVerticalArea(int[][] points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxWidthOfVerticalArea(self, points):\n \"\"\"\n :type points: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxWidthOfVerticalArea(int** points, int pointsSize, int* pointsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxWidthOfVerticalArea(int[][] points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} points\n * @return {number}\n */\nvar maxWidthOfVerticalArea = function(points) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} points\n# @return {Integer}\ndef max_width_of_vertical_area(points)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxWidthOfVerticalArea(_ points: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxWidthOfVerticalArea(points [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxWidthOfVerticalArea(points: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxWidthOfVerticalArea(points: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_width_of_vertical_area(points: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $points\n * @return Integer\n */\n function maxWidthOfVerticalArea($points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxWidthOfVerticalArea(points: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-width-of-vertical-area points)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1637](https://leetcode-cn.com/problems/widest-vertical-area-between-two-points-containing-no-points)", "[\u4e24\u70b9\u4e4b\u95f4\u4e0d\u5305\u542b\u4efb\u4f55\u70b9\u7684\u6700\u5bbd\u5782\u76f4\u9762\u79ef](/solution/1600-1699/1637.Widest%20Vertical%20Area%20Between%20Two%20Points%20Containing%20No%20Points/README.md)", "`\u6392\u5e8f`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1637](https://leetcode.com/problems/widest-vertical-area-between-two-points-containing-no-points)", "[Widest Vertical Area Between Two Points Containing No Points](/solution/1600-1699/1637.Widest%20Vertical%20Area%20Between%20Two%20Points%20Containing%20No%20Points/README_EN.md)", "`Sort`", "Medium", ""]}, {"question_id": "1741", "frontend_question_id": "1636", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sort-array-by-increasing-frequency", "url_en": "https://leetcode.com/problems/sort-array-by-increasing-frequency", "relative_path_cn": "/solution/1600-1699/1636.Sort%20Array%20by%20Increasing%20Frequency/README.md", "relative_path_en": "/solution/1600-1699/1636.Sort%20Array%20by%20Increasing%20Frequency/README_EN.md", "title_cn": "\u6309\u7167\u9891\u7387\u5c06\u6570\u7ec4\u5347\u5e8f\u6392\u5e8f", "title_en": "Sort Array by Increasing Frequency", "question_title_slug": "sort-array-by-increasing-frequency", "content_en": "

    Given an array of integers nums, sort the array in increasing order based on the frequency of the values. If multiple values have the same frequency, sort them in decreasing order.

    \n\n

    Return the sorted array.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,1,2,2,2,3]\nOutput: [3,1,1,2,2,2]\nExplanation: '3' has a frequency of 1, '1' has a frequency of 2, and '2' has a frequency of 3.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [2,3,1,3,2]\nOutput: [1,3,3,2,2]\nExplanation: '2' and '3' both have a frequency of 2, so they are sorted in decreasing order.\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [-1,1,-6,4,5,-6,1,4,1]\nOutput: [5,-1,4,4,-6,-6,1,1,1]
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 100
    • \n\t
    • -100 <= nums[i] <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0nums\u00a0\uff0c\u8bf7\u4f60\u5c06\u6570\u7ec4\u6309\u7167\u6bcf\u4e2a\u503c\u7684\u9891\u7387 \u5347\u5e8f \u6392\u5e8f\u3002\u5982\u679c\u6709\u591a\u4e2a\u503c\u7684\u9891\u7387\u76f8\u540c\uff0c\u8bf7\u4f60\u6309\u7167\u6570\u503c\u672c\u8eab\u5c06\u5b83\u4eec \u964d\u5e8f \u6392\u5e8f\u3002\u00a0

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u6392\u5e8f\u540e\u7684\u6570\u7ec4\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,1,2,2,2,3]\n\u8f93\u51fa\uff1a[3,1,1,2,2,2]\n\u89e3\u91ca\uff1a'3' \u9891\u7387\u4e3a 1\uff0c'1' \u9891\u7387\u4e3a 2\uff0c'2' \u9891\u7387\u4e3a 3 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [2,3,1,3,2]\n\u8f93\u51fa\uff1a[1,3,3,2,2]\n\u89e3\u91ca\uff1a'2' \u548c '3' \u9891\u7387\u90fd\u4e3a 2 \uff0c\u6240\u4ee5\u5b83\u4eec\u4e4b\u95f4\u6309\u7167\u6570\u503c\u672c\u8eab\u964d\u5e8f\u6392\u5e8f\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [-1,1,-6,4,5,-6,1,4,1]\n\u8f93\u51fa\uff1a[5,-1,4,4,-6,-6,1,1,1]
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 100
    • \n\t
    • -100 <= nums[i] <= 100
    • \n
    \n", "tags_en": ["Sort", "Array"], "tags_cn": ["\u6392\u5e8f", "\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector frequencySort(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] frequencySort(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def frequencySort(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def frequencySort(self, nums: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* frequencySort(int* nums, int numsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] FrequencySort(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar frequencySort = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer[]}\ndef frequency_sort(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func frequencySort(_ nums: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func frequencySort(nums []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def frequencySort(nums: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun frequencySort(nums: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn frequency_sort(nums: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer[]\n */\n function frequencySort($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function frequencySort(nums: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (frequency-sort nums)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1636](https://leetcode-cn.com/problems/sort-array-by-increasing-frequency)", "[\u6309\u7167\u9891\u7387\u5c06\u6570\u7ec4\u5347\u5e8f\u6392\u5e8f](/solution/1600-1699/1636.Sort%20Array%20by%20Increasing%20Frequency/README.md)", "`\u6392\u5e8f`,`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1636](https://leetcode.com/problems/sort-array-by-increasing-frequency)", "[Sort Array by Increasing Frequency](/solution/1600-1699/1636.Sort%20Array%20by%20Increasing%20Frequency/README_EN.md)", "`Sort`,`Array`", "Easy", ""]}, {"question_id": "1740", "frontend_question_id": "1617", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-subtrees-with-max-distance-between-cities", "url_en": "https://leetcode.com/problems/count-subtrees-with-max-distance-between-cities", "relative_path_cn": "/solution/1600-1699/1617.Count%20Subtrees%20With%20Max%20Distance%20Between%20Cities/README.md", "relative_path_en": "/solution/1600-1699/1617.Count%20Subtrees%20With%20Max%20Distance%20Between%20Cities/README_EN.md", "title_cn": "\u7edf\u8ba1\u5b50\u6811\u4e2d\u57ce\u5e02\u4e4b\u95f4\u6700\u5927\u8ddd\u79bb", "title_en": "Count Subtrees With Max Distance Between Cities", "question_title_slug": "count-subtrees-with-max-distance-between-cities", "content_en": "

    There are n cities numbered from 1 to n. You are given an array edges of size n-1, where edges[i] = [ui, vi] represents a bidirectional edge between cities ui and vi. There exists a unique path between each pair of cities. In other words, the cities form a tree.

    \r\n\r\n

    A subtree is a subset of cities where every city is reachable from every other city in the subset, where the path between each pair passes through only the cities from the subset. Two subtrees are different if there is a city in one subtree that is not present in the other.

    \r\n\r\n

    For each d from 1 to n-1, find the number of subtrees in which the maximum distance between any two cities in the subtree is equal to d.

    \r\n\r\n

    Return an array of size n-1 where the dth element (1-indexed) is the number of subtrees in which the maximum distance between any two cities is equal to d.

    \r\n\r\n

    Notice that the distance between the two cities is the number of edges in the path between them.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n

    \"\"

    \r\n\r\n
    \r\nInput: n = 4, edges = [[1,2],[2,3],[2,4]]\r\nOutput: [3,4,0]\r\nExplanation:\r\nThe subtrees with subsets {1,2}, {2,3} and {2,4} have a max distance of 1.\r\nThe subtrees with subsets {1,2,3}, {1,2,4}, {2,3,4} and {1,2,3,4} have a max distance of 2.\r\nNo subtree has two nodes where the max distance between them is 3.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: n = 2, edges = [[1,2]]\r\nOutput: [1]\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: n = 3, edges = [[1,2],[2,3]]\r\nOutput: [2,1]\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 2 <= n <= 15
    • \r\n\t
    • edges.length == n-1
    • \r\n\t
    • edges[i].length == 2
    • \r\n\t
    • 1 <= ui, vi <= n
    • \r\n\t
    • All pairs (ui, vi) are distinct.
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u00a0n\u00a0\u4e2a\u57ce\u5e02\uff0c\u7f16\u53f7\u4e3a\u4ece\u00a01 \u5230\u00a0n\u00a0\u3002\u540c\u65f6\u7ed9\u4f60\u4e00\u4e2a\u5927\u5c0f\u4e3a\u00a0n-1\u00a0\u7684\u6570\u7ec4\u00a0edges\u00a0\uff0c\u5176\u4e2d\u00a0edges[i] = [ui, vi]\u00a0\u8868\u793a\u57ce\u5e02\u00a0ui\u00a0\u548c\u00a0vi\u00a0\u4e4b\u95f4\u6709\u4e00\u6761\u53cc\u5411\u8fb9\u3002\u9898\u76ee\u4fdd\u8bc1\u4efb\u610f\u57ce\u5e02\u4e4b\u95f4\u53ea\u6709\u552f\u4e00\u7684\u4e00\u6761\u8def\u5f84\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u6240\u6709\u57ce\u5e02\u5f62\u6210\u4e86\u4e00\u68f5\u00a0\u6811\u00a0\u3002

    \n\n

    \u4e00\u68f5\u00a0\u5b50\u6811\u00a0\u662f\u57ce\u5e02\u7684\u4e00\u4e2a\u5b50\u96c6\uff0c\u4e14\u5b50\u96c6\u4e2d\u4efb\u610f\u57ce\u5e02\u4e4b\u95f4\u53ef\u4ee5\u901a\u8fc7\u5b50\u96c6\u4e2d\u7684\u5176\u4ed6\u57ce\u5e02\u548c\u8fb9\u5230\u8fbe\u3002\u4e24\u4e2a\u5b50\u6811\u88ab\u8ba4\u4e3a\u4e0d\u4e00\u6837\u7684\u6761\u4ef6\u662f\u81f3\u5c11\u6709\u4e00\u4e2a\u57ce\u5e02\u5728\u5176\u4e2d\u4e00\u68f5\u5b50\u6811\u4e2d\u5b58\u5728\uff0c\u4f46\u5728\u53e6\u4e00\u68f5\u5b50\u6811\u4e2d\u4e0d\u5b58\u5728\u3002

    \n\n

    \u5bf9\u4e8e\u00a0d\u00a0\u4ece\u00a01 \u5230\u00a0n-1\u00a0\uff0c\u8bf7\u4f60\u627e\u5230\u57ce\u5e02\u95f4\u00a0\u6700\u5927\u8ddd\u79bb\u00a0\u6070\u597d\u4e3a d\u00a0\u7684\u6240\u6709\u5b50\u6811\u6570\u76ee\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u4e00\u4e2a\u5927\u5c0f\u4e3a\u00a0n-1\u00a0\u7684\u6570\u7ec4\uff0c\u5176\u4e2d\u7b2c\u00a0d\u00a0\u4e2a\u5143\u7d20\uff08\u4e0b\u6807\u4ece 1 \u5f00\u59cb\uff09\u662f\u57ce\u5e02\u95f4 \u6700\u5927\u8ddd\u79bb \u6070\u597d\u7b49\u4e8e\u00a0d\u00a0\u7684\u5b50\u6811\u6570\u76ee\u3002

    \n\n

    \u8bf7\u6ce8\u610f\uff0c\u4e24\u4e2a\u57ce\u5e02\u95f4\u8ddd\u79bb\u5b9a\u4e49\u4e3a\u5b83\u4eec\u4e4b\u95f4\u9700\u8981\u7ecf\u8fc7\u7684\u8fb9\u7684\u6570\u76ee\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1an = 4, edges = [[1,2],[2,3],[2,4]]\n\u8f93\u51fa\uff1a[3,4,0]\n\u89e3\u91ca\uff1a\n\u5b50\u6811 {1,2}, {2,3} \u548c {2,4} \u6700\u5927\u8ddd\u79bb\u90fd\u662f 1 \u3002\n\u5b50\u6811 {1,2,3}, {1,2,4}, {2,3,4} \u548c {1,2,3,4} \u6700\u5927\u8ddd\u79bb\u90fd\u4e3a 2 \u3002\n\u4e0d\u5b58\u5728\u57ce\u5e02\u95f4\u6700\u5927\u8ddd\u79bb\u4e3a 3 \u7684\u5b50\u6811\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 2, edges = [[1,2]]\n\u8f93\u51fa\uff1a[1]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 3, edges = [[1,2],[2,3]]\n\u8f93\u51fa\uff1a[2,1]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= n <= 15
    • \n\t
    • edges.length == n-1
    • \n\t
    • edges[i].length == 2
    • \n\t
    • 1 <= ui, vi <= n
    • \n\t
    • \u9898\u76ee\u4fdd\u8bc1\u00a0(ui, vi)\u00a0\u6240\u8868\u793a\u7684\u8fb9\u4e92\u4e0d\u76f8\u540c\u3002
    • \n
    \n", "tags_en": ["Backtracking"], "tags_cn": ["\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector countSubgraphsForEachDiameter(int n, vector>& edges) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] countSubgraphsForEachDiameter(int n, int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countSubgraphsForEachDiameter(self, n, edges):\n \"\"\"\n :type n: int\n :type edges: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countSubgraphsForEachDiameter(self, n: int, edges: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* countSubgraphsForEachDiameter(int n, int** edges, int edgesSize, int* edgesColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] CountSubgraphsForEachDiameter(int n, int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} edges\n * @return {number[]}\n */\nvar countSubgraphsForEachDiameter = function(n, edges) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} edges\n# @return {Integer[]}\ndef count_subgraphs_for_each_diameter(n, edges)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countSubgraphsForEachDiameter(_ n: Int, _ edges: [[Int]]) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countSubgraphsForEachDiameter(n int, edges [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countSubgraphsForEachDiameter(n: Int, edges: Array[Array[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countSubgraphsForEachDiameter(n: Int, edges: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_subgraphs_for_each_diameter(n: i32, edges: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $edges\n * @return Integer[]\n */\n function countSubgraphsForEachDiameter($n, $edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countSubgraphsForEachDiameter(n: number, edges: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-subgraphs-for-each-diameter n edges)\n (-> exact-integer? (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1617](https://leetcode-cn.com/problems/count-subtrees-with-max-distance-between-cities)", "[\u7edf\u8ba1\u5b50\u6811\u4e2d\u57ce\u5e02\u4e4b\u95f4\u6700\u5927\u8ddd\u79bb](/solution/1600-1699/1617.Count%20Subtrees%20With%20Max%20Distance%20Between%20Cities/README.md)", "`\u56de\u6eaf\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[1617](https://leetcode.com/problems/count-subtrees-with-max-distance-between-cities)", "[Count Subtrees With Max Distance Between Cities](/solution/1600-1699/1617.Count%20Subtrees%20With%20Max%20Distance%20Between%20Cities/README_EN.md)", "`Backtracking`", "Hard", ""]}, {"question_id": "1739", "frontend_question_id": "1616", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/split-two-strings-to-make-palindrome", "url_en": "https://leetcode.com/problems/split-two-strings-to-make-palindrome", "relative_path_cn": "/solution/1600-1699/1616.Split%20Two%20Strings%20to%20Make%20Palindrome/README.md", "relative_path_en": "/solution/1600-1699/1616.Split%20Two%20Strings%20to%20Make%20Palindrome/README_EN.md", "title_cn": "\u5206\u5272\u4e24\u4e2a\u5b57\u7b26\u4e32\u5f97\u5230\u56de\u6587\u4e32", "title_en": "Split Two Strings to Make Palindrome", "question_title_slug": "split-two-strings-to-make-palindrome", "content_en": "

    You are given two strings a and b of the same length. Choose an index and split both strings at the same index, splitting a into two strings: aprefix and asuffix where a = aprefix + asuffix, and splitting b into two strings: bprefix and bsuffix where b = bprefix + bsuffix. Check if aprefix + bsuffix or bprefix + asuffix forms a palindrome.

    \n\n

    When you split a string s into sprefix and ssuffix, either ssuffix or sprefix is allowed to be empty. For example, if s = "abc", then "" + "abc", "a" + "bc", "ab" + "c" , and "abc" + "" are valid splits.

    \n\n

    Return true if it is possible to form a palindrome string, otherwise return false.

    \n\n

    Notice that x + y denotes the concatenation of strings x and y.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: a = "x", b = "y"\nOutput: true\nExplaination: If either a or b are palindromes the answer is true since you can split in the following way:\naprefix = "", asuffix = "x"\nbprefix = "", bsuffix = "y"\nThen, aprefix + bsuffix = "" + "y" = "y", which is a palindrome.\n
    \n\n

    Example 2:

    \n\n
    \nInput: a = "abdef", b = "fecab"\nOutput: true\n
    \n\n

    Example 3:

    \n\n
    \nInput: a = "ulacfd", b = "jizalu"\nOutput: true\nExplaination: Split them at index 3:\naprefix = "ula", asuffix = "cfd"\nbprefix = "jiz", bsuffix = "alu"\nThen, aprefix + bsuffix = "ula" + "alu" = "ulaalu", which is a palindrome.\n
    \n\n

    Example 4:

    \n\n
    \nInput: a = "xbdef", b = "xecab"\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= a.length, b.length <= 105
    • \n\t
    • a.length == b.length
    • \n\t
    • a and b consist of lowercase English letters
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u5b57\u7b26\u4e32\u00a0a \u548c\u00a0b\u00a0\uff0c\u5b83\u4eec\u957f\u5ea6\u76f8\u540c\u3002\u8bf7\u4f60\u9009\u62e9\u4e00\u4e2a\u4e0b\u6807\uff0c\u5c06\u4e24\u4e2a\u5b57\u7b26\u4e32\u90fd\u5728\u00a0\u76f8\u540c\u7684\u4e0b\u6807 \u5206\u5272\u5f00\u3002\u7531\u00a0a\u00a0\u53ef\u4ee5\u5f97\u5230\u4e24\u4e2a\u5b57\u7b26\u4e32\uff1a\u00a0aprefix\u00a0\u548c\u00a0asuffix\u00a0\uff0c\u6ee1\u8db3\u00a0a = aprefix + asuffix\u00a0\uff0c\u540c\u7406\uff0c\u7531\u00a0b \u53ef\u4ee5\u5f97\u5230\u4e24\u4e2a\u5b57\u7b26\u4e32\u00a0bprefix \u548c\u00a0bsuffix\u00a0\uff0c\u6ee1\u8db3\u00a0b = bprefix + bsuffix\u00a0\u3002\u8bf7\u4f60\u5224\u65ad\u00a0aprefix + bsuffix \u6216\u8005\u00a0bprefix + asuffix\u00a0\u80fd\u5426\u6784\u6210\u56de\u6587\u4e32\u3002

    \n\n

    \u5f53\u4f60\u5c06\u4e00\u4e2a\u5b57\u7b26\u4e32\u00a0s\u00a0\u5206\u5272\u6210\u00a0sprefix \u548c\u00a0ssuffix\u00a0\u65f6\uff0c\u00a0ssuffix \u6216\u8005\u00a0sprefix \u53ef\u4ee5\u4e3a\u7a7a\u3002\u6bd4\u65b9\u8bf4\uff0c\u00a0s = \"abc\"\u00a0\u90a3\u4e48\u00a0\"\" + \"abc\"\u00a0\uff0c\u00a0\"a\" + \"bc\"\u00a0\uff0c\u00a0\"ab\" + \"c\"\u00a0\u548c\u00a0\"abc\" + \"\"\u00a0\u90fd\u662f\u5408\u6cd5\u5206\u5272\u3002

    \n\n

    \u5982\u679c \u80fd\u6784\u6210\u56de\u6587\u5b57\u7b26\u4e32 \uff0c\u90a3\u4e48\u8bf7\u8fd4\u56de\u00a0true\uff0c\u5426\u5219\u8fd4\u56de\u00a0false\u00a0\u3002

    \n\n

    \u6ce8\u610f\uff0c\u00a0x + y\u00a0\u8868\u793a\u8fde\u63a5\u5b57\u7b26\u4e32\u00a0x \u548c\u00a0y\u00a0\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aa = \"x\", b = \"y\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u5982\u679c a \u6216\u8005 b \u662f\u56de\u6587\u4e32\uff0c\u90a3\u4e48\u7b54\u6848\u4e00\u5b9a\u4e3a true \uff0c\u56e0\u4e3a\u4f60\u53ef\u4ee5\u5982\u4e0b\u5206\u5272\uff1a\naprefix = \"\", asuffix = \"x\"\nbprefix = \"\", bsuffix = \"y\"\n\u90a3\u4e48 aprefix + bsuffix = \"\" + \"y\" = \"y\" \u662f\u56de\u6587\u4e32\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aa = \"abdef\", b = \"fecab\"\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aa = \"ulacfd\", b = \"jizalu\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u5728\u4e0b\u6807\u4e3a 3 \u5904\u5206\u5272\uff1a\naprefix = \"ula\", asuffix = \"cfd\"\nbprefix = \"jiz\", bsuffix = \"alu\"\n\u90a3\u4e48 aprefix + bsuffix = \"ula\" + \"alu\" = \"ulaalu\" \u662f\u56de\u6587\u4e32\u3002
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1aa = \"xbdef\", b = \"xecab\"\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= a.length, b.length <= 105
    • \n\t
    • a.length == b.length
    • \n\t
    • a \u548c\u00a0b\u00a0\u90fd\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd
    • \n
    \n", "tags_en": ["Greedy", "Two Pointers", "String"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u53cc\u6307\u9488", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool checkPalindromeFormation(string a, string b) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean checkPalindromeFormation(String a, String b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def checkPalindromeFormation(self, a, b):\n \"\"\"\n :type a: str\n :type b: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def checkPalindromeFormation(self, a: str, b: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool checkPalindromeFormation(char * a, char * b){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CheckPalindromeFormation(string a, string b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} a\n * @param {string} b\n * @return {boolean}\n */\nvar checkPalindromeFormation = function(a, b) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} a\n# @param {String} b\n# @return {Boolean}\ndef check_palindrome_formation(a, b)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func checkPalindromeFormation(_ a: String, _ b: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func checkPalindromeFormation(a string, b string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def checkPalindromeFormation(a: String, b: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun checkPalindromeFormation(a: String, b: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn check_palindrome_formation(a: String, b: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $a\n * @param String $b\n * @return Boolean\n */\n function checkPalindromeFormation($a, $b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function checkPalindromeFormation(a: string, b: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (check-palindrome-formation a b)\n (-> string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1616](https://leetcode-cn.com/problems/split-two-strings-to-make-palindrome)", "[\u5206\u5272\u4e24\u4e2a\u5b57\u7b26\u4e32\u5f97\u5230\u56de\u6587\u4e32](/solution/1600-1699/1616.Split%20Two%20Strings%20to%20Make%20Palindrome/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u53cc\u6307\u9488`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1616](https://leetcode.com/problems/split-two-strings-to-make-palindrome)", "[Split Two Strings to Make Palindrome](/solution/1600-1699/1616.Split%20Two%20Strings%20to%20Make%20Palindrome/README_EN.md)", "`Greedy`,`Two Pointers`,`String`", "Medium", ""]}, {"question_id": "1738", "frontend_question_id": "1615", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximal-network-rank", "url_en": "https://leetcode.com/problems/maximal-network-rank", "relative_path_cn": "/solution/1600-1699/1615.Maximal%20Network%20Rank/README.md", "relative_path_en": "/solution/1600-1699/1615.Maximal%20Network%20Rank/README_EN.md", "title_cn": "\u6700\u5927\u7f51\u7edc\u79e9", "title_en": "Maximal Network Rank", "question_title_slug": "maximal-network-rank", "content_en": "

    There is an infrastructure of n cities with some number of roads connecting these cities. Each roads[i] = [ai, bi] indicates that there is a bidirectional road between cities ai and bi.

    \n\n

    The network rank of two different cities is defined as the total number of directly connected roads to either city. If a road is directly connected to both cities, it is only counted once.

    \n\n

    The maximal network rank of the infrastructure is the maximum network rank of all pairs of different cities.

    \n\n

    Given the integer n and the array roads, return the maximal network rank of the entire infrastructure.

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: n = 4, roads = [[0,1],[0,3],[1,2],[1,3]]\nOutput: 4\nExplanation: The network rank of cities 0 and 1 is 4 as there are 4 roads that are connected to either 0 or 1. The road between 0 and 1 is only counted once.\n
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: n = 5, roads = [[0,1],[0,3],[1,2],[1,3],[2,3],[2,4]]\nOutput: 5\nExplanation: There are 5 roads that are connected to cities 1 or 2.\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 8, roads = [[0,1],[1,2],[2,3],[2,4],[5,6],[5,7]]\nOutput: 5\nExplanation: The network rank of 2 and 5 is 5. Notice that all the cities do not have to be connected.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= n <= 100
    • \n\t
    • 0 <= roads.length <= n * (n - 1) / 2
    • \n\t
    • roads[i].length == 2
    • \n\t
    • 0 <= ai, bi <= n-1
    • \n\t
    • ai != bi
    • \n\t
    • Each pair of cities has at most one road connecting them.
    • \n
    \n", "content_cn": "

    n \u5ea7\u57ce\u5e02\u548c\u4e00\u4e9b\u8fde\u63a5\u8fd9\u4e9b\u57ce\u5e02\u7684\u9053\u8def roads \u5171\u540c\u7ec4\u6210\u4e00\u4e2a\u57fa\u7840\u8bbe\u65bd\u7f51\u7edc\u3002\u6bcf\u4e2a roads[i] = [ai, bi] \u90fd\u8868\u793a\u5728\u57ce\u5e02 ai \u548c bi \u4e4b\u95f4\u6709\u4e00\u6761\u53cc\u5411\u9053\u8def\u3002

    \n\n

    \u4e24\u5ea7\u4e0d\u540c\u57ce\u5e02\u6784\u6210\u7684 \u57ce\u5e02\u5bf9 \u7684 \u7f51\u7edc\u79e9 \u5b9a\u4e49\u4e3a\uff1a\u4e0e\u8fd9\u4e24\u5ea7\u57ce\u5e02 \u76f4\u63a5 \u76f8\u8fde\u7684\u9053\u8def\u603b\u6570\u3002\u5982\u679c\u5b58\u5728\u4e00\u6761\u9053\u8def\u76f4\u63a5\u8fde\u63a5\u8fd9\u4e24\u5ea7\u57ce\u5e02\uff0c\u5219\u8fd9\u6761\u9053\u8def\u53ea\u8ba1\u7b97 \u4e00\u6b21 \u3002

    \n\n

    \u6574\u4e2a\u57fa\u7840\u8bbe\u65bd\u7f51\u7edc\u7684 \u6700\u5927\u7f51\u7edc\u79e9 \u662f\u6240\u6709\u4e0d\u540c\u57ce\u5e02\u5bf9\u4e2d\u7684 \u6700\u5927\u7f51\u7edc\u79e9 \u3002

    \n\n

    \u7ed9\u4f60\u6574\u6570 n \u548c\u6570\u7ec4 roads\uff0c\u8fd4\u56de\u6574\u4e2a\u57fa\u7840\u8bbe\u65bd\u7f51\u7edc\u7684 \u6700\u5927\u7f51\u7edc\u79e9 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1an = 4, roads = [[0,1],[0,3],[1,2],[1,3]]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u57ce\u5e02 0 \u548c 1 \u7684\u7f51\u7edc\u79e9\u662f 4\uff0c\u56e0\u4e3a\u5171\u6709 4 \u6761\u9053\u8def\u4e0e\u57ce\u5e02 0 \u6216 1 \u76f8\u8fde\u3002\u4f4d\u4e8e 0 \u548c 1 \u4e4b\u95f4\u7684\u9053\u8def\u53ea\u8ba1\u7b97\u4e00\u6b21\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1an = 5, roads = [[0,1],[0,3],[1,2],[1,3],[2,3],[2,4]]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u5171\u6709 5 \u6761\u9053\u8def\u4e0e\u57ce\u5e02 1 \u6216 2 \u76f8\u8fde\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 8, roads = [[0,1],[1,2],[2,3],[2,4],[5,6],[5,7]]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a2 \u548c 5 \u7684\u7f51\u7edc\u79e9\u4e3a 5\uff0c\u6ce8\u610f\u5e76\u975e\u6240\u6709\u7684\u57ce\u5e02\u90fd\u9700\u8981\u8fde\u63a5\u8d77\u6765\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= n <= 100
    • \n\t
    • 0 <= roads.length <= n * (n - 1) / 2
    • \n\t
    • roads[i].length == 2
    • \n\t
    • 0 <= ai, bi\u00a0<= n-1
    • \n\t
    • ai\u00a0!=\u00a0bi
    • \n\t
    • \u6bcf\u5bf9\u57ce\u5e02\u4e4b\u95f4 \u6700\u591a\u53ea\u6709\u4e00\u6761\u00a0\u9053\u8def\u76f8\u8fde
    • \n
    \n", "tags_en": ["Graph"], "tags_cn": ["\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maximalNetworkRank(int n, vector>& roads) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maximalNetworkRank(int n, int[][] roads) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximalNetworkRank(self, n, roads):\n \"\"\"\n :type n: int\n :type roads: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximalNetworkRank(self, n: int, roads: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maximalNetworkRank(int n, int** roads, int roadsSize, int* roadsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaximalNetworkRank(int n, int[][] roads) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} roads\n * @return {number}\n */\nvar maximalNetworkRank = function(n, roads) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} roads\n# @return {Integer}\ndef maximal_network_rank(n, roads)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximalNetworkRank(_ n: Int, _ roads: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximalNetworkRank(n int, roads [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximalNetworkRank(n: Int, roads: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximalNetworkRank(n: Int, roads: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximal_network_rank(n: i32, roads: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $roads\n * @return Integer\n */\n function maximalNetworkRank($n, $roads) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximalNetworkRank(n: number, roads: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximal-network-rank n roads)\n (-> exact-integer? (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1615](https://leetcode-cn.com/problems/maximal-network-rank)", "[\u6700\u5927\u7f51\u7edc\u79e9](/solution/1600-1699/1615.Maximal%20Network%20Rank/README.md)", "`\u56fe`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1615](https://leetcode.com/problems/maximal-network-rank)", "[Maximal Network Rank](/solution/1600-1699/1615.Maximal%20Network%20Rank/README_EN.md)", "`Graph`", "Medium", ""]}, {"question_id": "1737", "frontend_question_id": "1614", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-nesting-depth-of-the-parentheses", "url_en": "https://leetcode.com/problems/maximum-nesting-depth-of-the-parentheses", "relative_path_cn": "/solution/1600-1699/1614.Maximum%20Nesting%20Depth%20of%20the%20Parentheses/README.md", "relative_path_en": "/solution/1600-1699/1614.Maximum%20Nesting%20Depth%20of%20the%20Parentheses/README_EN.md", "title_cn": "\u62ec\u53f7\u7684\u6700\u5927\u5d4c\u5957\u6df1\u5ea6", "title_en": "Maximum Nesting Depth of the Parentheses", "question_title_slug": "maximum-nesting-depth-of-the-parentheses", "content_en": "

    A string is a valid parentheses string (denoted VPS) if it meets one of the following:

    \n\n
      \n\t
    • It is an empty string "", or a single character not equal to "(" or ")",
    • \n\t
    • It can be written as AB (A concatenated with B), where A and B are VPS's, or
    • \n\t
    • It can be written as (A), where A is a VPS.
    • \n
    \n\n

    We can similarly define the nesting depth depth(S) of any VPS S as follows:

    \n\n
      \n\t
    • depth("") = 0
    • \n\t
    • depth(C) = 0, where C is a string with a single character not equal to "(" or ")".
    • \n\t
    • depth(A + B) = max(depth(A), depth(B)), where A and B are VPS's.
    • \n\t
    • depth("(" + A + ")") = 1 + depth(A), where A is a VPS.
    • \n
    \n\n

    For example, "", "()()", and "()(()())" are VPS's (with nesting depths 0, 1, and 2), and ")(" and "(()" are not VPS's.

    \n\n

    Given a VPS represented as string s, return the nesting depth of s.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "(1+(2*3)+((8)/4))+1"\nOutput: 3\nExplanation: Digit 8 is inside of 3 nested parentheses in the string.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "(1)+((2))+(((3)))"\nOutput: 3\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "1+(2*3)/(2-1)"\nOutput: 1\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "1"\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 100
    • \n\t
    • s consists of digits 0-9 and characters '+', '-', '*', '/', '(', and ')'.
    • \n\t
    • It is guaranteed that parentheses expression s is a VPS.
    • \n
    \n", "content_cn": "

    \u5982\u679c\u5b57\u7b26\u4e32\u6ee1\u8db3\u4ee5\u4e0b\u6761\u4ef6\u4e4b\u4e00\uff0c\u5219\u53ef\u4ee5\u79f0\u4e4b\u4e3a \u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32\uff08valid parentheses string\uff0c\u53ef\u4ee5\u7b80\u5199\u4e3a VPS\uff09\uff1a

    \n\n
      \n\t
    • \u5b57\u7b26\u4e32\u662f\u4e00\u4e2a\u7a7a\u5b57\u7b26\u4e32 \"\"\uff0c\u6216\u8005\u662f\u4e00\u4e2a\u4e0d\u4e3a \"(\" \u6216 \")\" \u7684\u5355\u5b57\u7b26\u3002
    • \n\t
    • \u5b57\u7b26\u4e32\u53ef\u4ee5\u5199\u4e3a AB\uff08A \u4e0e B\u00a0\u5b57\u7b26\u4e32\u8fde\u63a5\uff09\uff0c\u5176\u4e2d A \u548c B \u90fd\u662f \u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32 \u3002
    • \n\t
    • \u5b57\u7b26\u4e32\u53ef\u4ee5\u5199\u4e3a (A)\uff0c\u5176\u4e2d A \u662f\u4e00\u4e2a \u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32 \u3002
    • \n
    \n\n

    \u7c7b\u4f3c\u5730\uff0c\u53ef\u4ee5\u5b9a\u4e49\u4efb\u4f55\u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32\u00a0S \u7684 \u5d4c\u5957\u6df1\u5ea6 depth(S)\uff1a

    \n\n
      \n\t
    • depth(\"\") = 0
    • \n\t
    • depth(C) = 0\uff0c\u5176\u4e2d C \u662f\u5355\u4e2a\u5b57\u7b26\u7684\u5b57\u7b26\u4e32\uff0c\u4e14\u8be5\u5b57\u7b26\u4e0d\u662f \"(\" \u6216\u8005 \")\"
    • \n\t
    • depth(A + B) = max(depth(A), depth(B))\uff0c\u5176\u4e2d A \u548c B \u90fd\u662f \u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32
    • \n\t
    • depth(\"(\" + A + \")\") = 1 + depth(A)\uff0c\u5176\u4e2d A \u662f\u4e00\u4e2a \u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32
    • \n
    \n\n

    \u4f8b\u5982\uff1a\"\"\u3001\"()()\"\u3001\"()(()())\" \u90fd\u662f \u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32\uff08\u5d4c\u5957\u6df1\u5ea6\u5206\u522b\u4e3a 0\u30011\u30012\uff09\uff0c\u800c \")(\" \u3001\"(()\" \u90fd\u4e0d\u662f \u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32 \u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a \u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32 s\uff0c\u8fd4\u56de\u8be5\u5b57\u7b26\u4e32\u7684 s \u5d4c\u5957\u6df1\u5ea6 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"(1+(2*3)+((8)/4))+1\"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6570\u5b57 8 \u5728\u5d4c\u5957\u7684 3 \u5c42\u62ec\u53f7\u4e2d\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"(1)+((2))+(((3)))\"\n\u8f93\u51fa\uff1a3\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"1+(2*3)/(2-1)\"\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"1\"\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 100
    • \n\t
    • s \u7531\u6570\u5b57 0-9 \u548c\u5b57\u7b26 '+'\u3001'-'\u3001'*'\u3001'/'\u3001'('\u3001')' \u7ec4\u6210
    • \n\t
    • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u62ec\u53f7\u8868\u8fbe\u5f0f s \u662f \u6709\u6548\u7684\u62ec\u53f7\u8868\u8fbe\u5f0f
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxDepth(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxDepth(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxDepth(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxDepth(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxDepth(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxDepth(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar maxDepth = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef max_depth(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxDepth(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxDepth(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxDepth(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxDepth(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_depth(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function maxDepth($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxDepth(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-depth s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1614](https://leetcode-cn.com/problems/maximum-nesting-depth-of-the-parentheses)", "[\u62ec\u53f7\u7684\u6700\u5927\u5d4c\u5957\u6df1\u5ea6](/solution/1600-1699/1614.Maximum%20Nesting%20Depth%20of%20the%20Parentheses/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1614](https://leetcode.com/problems/maximum-nesting-depth-of-the-parentheses)", "[Maximum Nesting Depth of the Parentheses](/solution/1600-1699/1614.Maximum%20Nesting%20Depth%20of%20the%20Parentheses/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1736", "frontend_question_id": "1597", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/build-binary-expression-tree-from-infix-expression", "url_en": "https://leetcode.com/problems/build-binary-expression-tree-from-infix-expression", "relative_path_cn": "/solution/1500-1599/1597.Build%20Binary%20Expression%20Tree%20From%20Infix%20Expression/README.md", "relative_path_en": "/solution/1500-1599/1597.Build%20Binary%20Expression%20Tree%20From%20Infix%20Expression/README_EN.md", "title_cn": "\u6839\u636e\u4e2d\u7f00\u8868\u8fbe\u5f0f\u6784\u9020\u4e8c\u53c9\u8868\u8fbe\u5f0f\u6811", "title_en": "Build Binary Expression Tree From Infix Expression", "question_title_slug": "build-binary-expression-tree-from-infix-expression", "content_en": "

    A binary expression tree is a kind of binary tree used to represent arithmetic expressions. Each node of a binary expression tree has either zero or two children. Leaf nodes (nodes with 0 children) correspond to operands (numbers), and internal nodes (nodes with 2 children) correspond to the operators '+' (addition), '-' (subtraction), '*' (multiplication), and '/' (division).

    \n\n

    For each internal node with operator o, the infix expression that it represents is (A o B), where A is the expression the left subtree represents and B is the expression the right subtree represents.

    \n\n

    You are given a string s, an infix expression containing operands, the operators described above, and parentheses '(' and ')'.

    \n\n

    Return any valid binary expression tree, which its in-order traversal reproduces s after omitting the parenthesis from it (see examples below).

    \n\n

    Please note that order of operations applies in s. That is, expressions in parentheses are evaluated first, and multiplication and division happen before addition and subtraction.

    \n\n

    Operands must also appear in the same order in both s and the in-order traversal of the tree.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: s = "3*4-2*5"\nOutput: [-,*,*,3,4,2,5]\nExplanation: The tree above is the only valid tree whose inorder traversal produces s.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: s = "2-3/(5*2)+1"\nOutput: [+,-,1,2,/,null,null,null,null,3,*,null,null,5,2]\nExplanation: The inorder traversal of the tree above is 2-3/5*2+1 which is the same as s without the parenthesis. The tree also produces the correct result and its operands are in the same order as they appear in s.\nThe tree below is also a valid binary expression tree with the same inorder traversal as s, but it not a valid answer because it does not evaluate to the same value.\n\"\"\nThe third tree below is also not valid. Although it produces the same result and is equivalent to the above trees, its inorder traversal does not produce s and its operands are not in the same order as s.\n\"\"\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "1+2+3+4+5"\nOutput: [+,+,5,+,4,null,null,+,3,null,null,1,2]\nExplanation: The tree [+,+,5,+,+,null,null,1,2,3,4] is also one of many other valid trees.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 1000
    • \n\t
    • s consists of digits and the characters '+', '-', '*', and '/'.
    • \n\t
    • Operands in s are exactly 1 digit.
    • \n\t
    • It is guaranteed that s is a valid expression.
    • \n
    \n", "content_cn": "

    \u4e8c\u53c9\u8868\u8fbe\u5f0f\u6811 \u662f\u4e00\u79cd\u8868\u8fbe\u7b97\u672f\u8868\u8fbe\u5f0f\u7684\u4e8c\u53c9\u6811\u3002\u4e8c\u53c9\u8868\u8fbe\u5f0f\u6811\u4e2d\u7684\u6bcf\u4e00\u4e2a\u8282\u70b9\u90fd\u6709\u96f6\u4e2a\u6216\u4e24\u4e2a\u5b50\u8282\u70b9\u3002\u00a0\u53f6\u8282\u70b9\uff08\u6709 0 \u4e2a\u5b50\u8282\u70b9\u7684\u8282\u70b9\uff09\u8868\u793a\u64cd\u4f5c\u6570\uff0c\u975e\u53f6\u8282\u70b9\uff08\u6709 2 \u4e2a\u5b50\u8282\u70b9\u7684\u8282\u70b9\uff09\u8868\u793a\u8fd0\u7b97\u7b26\uff1a\u00a0'+'\u00a0\uff08\u52a0\uff09\u3001\u00a0'-' \uff08\u51cf\uff09\u3001\u00a0'*' \uff08\u4e58\uff09\u548c\u00a0'/' \uff08\u9664\uff09\u3002

    \n\n

    \u5bf9\u4e8e\u6bcf\u4e00\u4e2a\u8fd0\u7b97\u7b26\u4e3a o \u7684\u975e\u53f6\u8282\u70b9\uff0c\u5bf9\u5e94\u7684 \u4e2d\u7f00\u8868\u8fbe\u5f0f \u4e3a\u00a0(A o B)\uff0c\u5176\u4e2d\u00a0A\u00a0\u662f\u5de6\u5b50\u6811\u6240\u8868\u8fbe\u7684\u8868\u8fbe\u5f0f\uff0c\u00a0B\u00a0\u662f\u53f3\u5b50\u6811\u6240\u8868\u8fbe\u7684\u8868\u8fbe\u5f0f\u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a \u4e2d\u7f00\u8868\u8fbe\u5f0f \u5b57\u7b26\u4e32\u00a0s\uff0c\u5176\u4e2d\u5305\u542b\u64cd\u4f5c\u6570\u3001\u4e0a\u9762\u63d0\u5230\u7684\u8fd0\u7b97\u7b26\uff0c\u4ee5\u53ca\u62ec\u53f7\u00a0'('\u00a0\u4e0e\u00a0')'\u00a0\u3002

    \n\n

    \u8fd4\u56de\u4e00\u4e2a\u6709\u6548\u7684 \u4e8c\u53c9\u8868\u8fbe\u5f0f\u6811\uff0c\u5176 \u4e2d\u5e8f\u904d\u5386 \u5e8f\u5217\u5bf9\u5e94\u8868\u8fbe\u5f0f s \u6d88\u9664\u62ec\u53f7\u540e\u7684\u5e8f\u5217\uff08\u8be6\u60c5\u53c2\u89c1\u4e0b\u9762\u7684\u793a\u4f8b\uff09\u3002

    \n\n

    \u6ce8\u610f\uff0c\u8868\u8fbe\u5f0f\u7684\u4e00\u822c\u89e3\u6790\u987a\u5e8f\u9002\u7528\u4e8e\u00a0s\uff0c\u5373\u4f18\u5148\u89e3\u6790\u62ec\u53f7\u5185\u7684\u8868\u8fbe\u5f0f\uff0c\u7136\u540e\u89e3\u6790\u4e58\u9664\u6cd5\uff0c\u6700\u540e\u89e3\u6790\u52a0\u51cf\u6cd5\u3002

    \n\n

    \u540c\u65f6\uff0c\u64cd\u4f5c\u6570\u5728 s \u548c\u6811\u7684\u4e2d\u5e8f\u904d\u5386\u4e2d \u51fa\u73b0\u987a\u5e8f\u76f8\u540c \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1as = \"3*4-2*5\"\n\u8f93\u51fa\uff1a[-,*,*,3,4,2,5]\n\u89e3\u91ca\uff1a\u4e0a\u9762\u662f\u552f\u4e00\u4e00\u79cd\u6709\u6548\u7684\u4e8c\u53c9\u8868\u8fbe\u5f0f\u6811\uff0c\u5176\u4e2d\u5e8f\u904d\u5386\u751f\u6210 s \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1as = \"2-3/(5*2)+1\"\n\u8f93\u51fa\uff1a[+,-,1,2,/,null,null,null,null,3,*,null,null,5,2]\n\u89e3\u91ca\uff1a\u4e0a\u9762\u7684\u6811\u7684\u4e2d\u5e8f\u904d\u5386\u4e3a 2-3/5*2+1 \uff0c\u4e0e s \u6d88\u9664\u62ec\u53f7\u540e\u76f8\u540c\u3002\u8be5\u6811\u8fd8\u4f1a\u751f\u6210\u6b63\u786e\u7684\u7ed3\u679c\uff0c\u5176\u64cd\u4f5c\u6570\u7684\u987a\u5e8f\u4e0e s \u4e2d\u51fa\u73b0\u7684\u987a\u5e8f\u76f8\u540c\u3002\n\u4e0b\u9762\u7684\u6811\u4e5f\u662f\u4e00\u4e2a\u6709\u6548\u7684\u4e8c\u53c9\u8868\u8fbe\u5f0f\u6811\uff0c\u5177\u6709\u4e0e s \u76f8\u540c\u7684\u4e2d\u5e8f\u904d\u5386\uff0c\u4f46\u5b83\u4e0d\u662f\u4e00\u4e2a\u6709\u6548\u7684\u7b54\u6848\uff0c\u56e0\u4e3a\u5b83\u7684\u6c42\u503c\u7ed3\u679c\u4e0d\u540c\u3002\n\"\"\n\u4e0b\u9762\u7684\u6811\u4e5f\u662f\u65e0\u6548\u7684\u3002\u5c3d\u7ba1\u5b83\u7684\u8ba1\u7b97\u7ed3\u679c\u76f8\u7b49\u5e76\u4e0e\u4e0a\u8ff0\u6811\u7b49\u6548\uff0c\u4f46\u5176\u4e2d\u5e8f\u904d\u5386\u4e0d\u4f1a\u4ea7\u751f s \uff0c\u5e76\u4e14\u5176\u64cd\u4f5c\u6570\u4e0e s \u4e2d\u7684\u987a\u5e8f\u4e5f\u4e0d\u76f8\u540c\u3002\n\"\"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"1+2+3+4+5\"\n\u8f93\u51fa\uff1a[+,+,5,+,4,null,null,+,3,null,null,1,2]\n\u89e3\u91ca\uff1a\u4e8c\u53c9\u6811 [+,+,5,+,+,null,null,1,2,3,4] \u4e5f\u662f\u8bf8\u591a\u6709\u6548\u7684\u4e8c\u53c9\u8868\u8fbe\u5f0f\u6811\u4e4b\u4e00\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a:

    \n\n
      \n\t
    • 1 <= s.length <= 105
    • \n\t
    • s\u00a0\u4e2d\u5305\u542b\u6570\u5b57\u548c\u5b57\u7b26\u00a0'+'\u3001\u00a0'-'\u3001\u00a0'*'\u3001\u00a0'/' \u3002
    • \n\t
    • s\u00a0\u4e2d\u7684\u64cd\u4f5c\u6570 \u6070\u597d \u662f\u4e00\u4f4d\u6570\u5b57\u3002
    • \n\t
    • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1 s \u662f\u4e00\u4e2a\u6709\u6548\u7684\u8868\u8fbe\u5f0f\u3002
    • \n
    \n", "tags_en": ["Tree", "String"], "tags_cn": ["\u6811", "\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for a binary tree node.\n * struct Node {\n * char val;\n * Node *left;\n * Node *right;\n * Node() : val(' '), left(nullptr), right(nullptr) {}\n * Node(char x) : val(x), left(nullptr), right(nullptr) {}\n * Node(char x, Node *left, Node *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n Node* expTree(string s) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * class Node {\n * char val;\n * Node left;\n * Node right;\n * Node() {this.val = ' ';}\n * Node(char val) { this.val = val; }\n * Node(char val, Node left, Node right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public Node expTree(String s) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class Node(object):\n# def __init__(self, val=\" \", left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def expTree(self, s):\n \"\"\"\n :type s: str\n :rtype: Node\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class Node(object):\n# def __init__(self, val=\" \", left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def expTree(self, s: str) -> 'Node':\n ", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class Node {\n * public char val;\n * public Node left;\n * public Node right;\n * public Node(char val=' ', TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public Node ExpTree(string s) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function Node(val, left, right) {\n * this.val = (val===undefined ? \" \" : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {string} s\n * @return {Node}\n */\nvar expTree = function(s) {\n \n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1597](https://leetcode-cn.com/problems/build-binary-expression-tree-from-infix-expression)", "[\u6839\u636e\u4e2d\u7f00\u8868\u8fbe\u5f0f\u6784\u9020\u4e8c\u53c9\u8868\u8fbe\u5f0f\u6811](/solution/1500-1599/1597.Build%20Binary%20Expression%20Tree%20From%20Infix%20Expression/README.md)", "`\u6811`,`\u5b57\u7b26\u4e32`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1597](https://leetcode.com/problems/build-binary-expression-tree-from-infix-expression)", "[Build Binary Expression Tree From Infix Expression](/solution/1500-1599/1597.Build%20Binary%20Expression%20Tree%20From%20Infix%20Expression/README_EN.md)", "`Tree`,`String`", "Hard", "\ud83d\udd12"]}, {"question_id": "1735", "frontend_question_id": "1596", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/the-most-frequently-ordered-products-for-each-customer", "url_en": "https://leetcode.com/problems/the-most-frequently-ordered-products-for-each-customer", "relative_path_cn": "/solution/1500-1599/1596.The%20Most%20Frequently%20Ordered%20Products%20for%20Each%20Customer/README.md", "relative_path_en": "/solution/1500-1599/1596.The%20Most%20Frequently%20Ordered%20Products%20for%20Each%20Customer/README_EN.md", "title_cn": "\u6bcf\u4f4d\u987e\u5ba2\u6700\u7ecf\u5e38\u8ba2\u8d2d\u7684\u5546\u54c1", "title_en": "The Most Frequently Ordered Products for Each Customer", "question_title_slug": "the-most-frequently-ordered-products-for-each-customer", "content_en": "

    Table: Customers

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| customer_id   | int     |\n| name          | varchar |\n+---------------+---------+\ncustomer_id is the primary key for this table.\nThis table contains information about the customers.\n
    \n\n

     

    \n\n

    Table: Orders

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| order_id      | int     |\n| order_date    | date    |\n| customer_id   | int     |\n| product_id    | int     |\n+---------------+---------+\norder_id is the primary key for this table.\nThis table contains information about the orders made by customer_id.\nNo customer will order the same product more than once in a single day.
    \n\n

     

    \n\n

    Table: Products

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| product_id    | int     |\n| product_name  | varchar |\n| price         | int     |\n+---------------+---------+\nproduct_id is the primary key for this table.\nThis table contains information about the products.\n
    \n\n

     

    \n\n

    Write an SQL query to find the most frequently ordered product(s) for each customer.

    \n\n

    The result table should have the product_id and product_name for each customer_id who ordered at least one order. Return the result table in any order.

    \n\n

    The query result format is in the following example:

    \n\n
    \nCustomers\n+-------------+-------+\n| customer_id | name  |\n+-------------+-------+\n| 1           | Alice |\n| 2           | Bob   |\n| 3           | Tom   |\n| 4           | Jerry |\n| 5           | John  |\n+-------------+-------+\n\nOrders\n+----------+------------+-------------+------------+\n| order_id | order_date | customer_id | product_id |\n+----------+------------+-------------+------------+\n| 1        | 2020-07-31 | 1           | 1          |\n| 2        | 2020-07-30 | 2           | 2          |\n| 3        | 2020-08-29 | 3           | 3          |\n| 4        | 2020-07-29 | 4           | 1          |\n| 5        | 2020-06-10 | 1           | 2          |\n| 6        | 2020-08-01 | 2           | 1          |\n| 7        | 2020-08-01 | 3           | 3          |\n| 8        | 2020-08-03 | 1           | 2          |\n| 9        | 2020-08-07 | 2           | 3          |\n| 10       | 2020-07-15 | 1           | 2          |\n+----------+------------+-------------+------------+\n\nProducts\n+------------+--------------+-------+\n| product_id | product_name | price |\n+------------+--------------+-------+\n| 1          | keyboard     | 120   |\n| 2          | mouse        | 80    |\n| 3          | screen       | 600   |\n| 4          | hard disk    | 450   |\n+------------+--------------+-------+\nResult table:\n+-------------+------------+--------------+\n| customer_id | product_id | product_name |\n+-------------+------------+--------------+\n| 1           | 2          | mouse        |\n| 2           | 1          | keyboard     |\n| 2           | 2          | mouse        |\n| 2           | 3          | screen       |\n| 3           | 3          | screen       |\n| 4           | 1          | keyboard     |\n+-------------+------------+--------------+\n\nAlice (customer 1) ordered the mouse three times and the keyboard one time, so the mouse is the most frquently ordered product for them.\nBob (customer 2) ordered the keyboard, the mouse, and the screen one time, so those are the most frquently ordered products for them.\nTom (customer 3) only ordered the screen (two times), so that is the most frquently ordered product for them.\nJerry (customer 4) only ordered the keyboard (one time), so that is the most frquently ordered product for them.\nJohn (customer 5) did not order anything, so we do not include them in the result table.\n
    \n", "content_cn": "

    \u8868\uff1aCustomers

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| customer_id   | int     |\n| name          | varchar |\n+---------------+---------+\ncustomer_id \u662f\u8be5\u8868\u4e3b\u952e\n\u8be5\u8868\u5305\u542b\u6240\u6709\u987e\u5ba2\u7684\u4fe1\u606f\n
    \n\n

    \u00a0

    \n\n

    \u8868\uff1aOrders

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| order_id      | int     |\n| order_date    | date    |\n| customer_id   | int     |\n| product_id    | int     |\n+---------------+---------+\norder_id \u662f\u8be5\u8868\u4e3b\u952e\n\u8be5\u8868\u5305\u542b\u987e\u5ba2 customer_id \u7684\u8ba2\u5355\u4fe1\u606f\n\u6ca1\u6709\u987e\u5ba2\u4f1a\u5728\u4e00\u5929\u5185\u8ba2\u8d2d\u76f8\u540c\u7684\u5546\u54c1 \u591a\u4e8e\u4e00\u6b21
    \n\n

    \u00a0

    \n\n

    \u8868\uff1aProducts

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| product_id    | int     |\n| product_name  | varchar |\n| price         | int     |\n+---------------+---------+\nproduct_id \u662f\u8be5\u8868\u4e3b\u952e\n\u8be5\u8868\u5305\u542b\u4e86\u6240\u6709\u5546\u54c1\u7684\u4fe1\u606f\n
    \n\n

    \u00a0

    \n\n

    \u5199\u4e00\u4e2a SQL \u8bed\u53e5\uff0c\u627e\u5230\u6bcf\u4e00\u4e2a\u987e\u5ba2\u6700\u7ecf\u5e38\u8ba2\u8d2d\u7684\u5546\u54c1\u3002

    \n\n

    \u7ed3\u679c\u8868\u5355\u5e94\u8be5\u6709\u6bcf\u4e00\u4f4d\u81f3\u5c11\u4e0b\u8fc7\u4e00\u6b21\u5355\u7684\u987e\u5ba2 customer_id\u00a0,\u00a0\u4ed6\u6700\u7ecf\u5e38\u8ba2\u8d2d\u7684\u5546\u54c1\u7684\u00a0product_id\u00a0\u548c\u00a0product_name\u3002

    \n\n

    \u8fd4\u56de\u7ed3\u679c \u6ca1\u6709\u987a\u5e8f\u8981\u6c42\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a\uff1a

    \n\n
    \nCustomers\n+-------------+-------+\n| customer_id | name  |\n+-------------+-------+\n| 1           | Alice |\n| 2           | Bob   |\n| 3           | Tom   |\n| 4           | Jerry |\n| 5           | John  |\n+-------------+-------+\n\nOrders\n+----------+------------+-------------+------------+\n| order_id | order_date | customer_id | product_id |\n+----------+------------+-------------+------------+\n| 1        | 2020-07-31 | 1           | 1          |\n| 2        | 2020-07-30 | 2           | 2          |\n| 3        | 2020-08-29 | 3           | 3          |\n| 4        | 2020-07-29 | 4           | 1          |\n| 5        | 2020-06-10 | 1           | 2          |\n| 6        | 2020-08-01 | 2           | 1          |\n| 7        | 2020-08-01 | 3           | 3          |\n| 8        | 2020-08-03 | 1           | 2          |\n| 9        | 2020-08-07 | 2           | 3          |\n| 10       | 2020-07-15 | 1           | 2          |\n+----------+------------+-------------+------------+\n\nProducts\n+------------+--------------+-------+\n| product_id | product_name | price |\n+------------+--------------+-------+\n| 1          | keyboard     | 120   |\n| 2          | mouse        | 80    |\n| 3          | screen       | 600   |\n| 4          | hard disk    | 450   |\n+------------+--------------+-------+\nResult \u8868\uff1a\n+-------------+------------+--------------+\n| customer_id | product_id | product_name |\n+-------------+------------+--------------+\n| 1           | 2          | mouse        |\n| 2           | 1          | keyboard     |\n| 2           | 2          | mouse        |\n| 2           | 3          | screen       |\n| 3           | 3          | screen       |\n| 4           | 1          | keyboard     |\n+-------------+------------+--------------+\n\nAlice (customer 1) \u4e09\u6b21\u8ba2\u8d2d\u9f20\u6807, \u4e00\u6b21\u8ba2\u8d2d\u952e\u76d8, \u6240\u4ee5\u9f20\u6807\u662f Alice \u6700\u7ecf\u5e38\u8ba2\u8d2d\u7684\u5546\u54c1.\nBob (customer 2) \u4e00\u6b21\u8ba2\u8d2d\u952e\u76d8, \u4e00\u6b21\u8ba2\u8d2d\u9f20\u6807, \u4e00\u6b21\u8ba2\u8d2d\u663e\u793a\u5668, \u6240\u4ee5\u8fd9\u4e9b\u90fd\u662f Bob \u6700\u7ecf\u5e38\u8ba2\u8d2d\u7684\u5546\u54c1.\nTom (customer 3) \u53ea\u4e24\u6b21\u8ba2\u8d2d\u663e\u793a\u5668, \u6240\u4ee5\u663e\u793a\u5668\u662f Tom \u6700\u7ecf\u5e38\u8ba2\u8d2d\u7684\u5546\u54c1.\nJerry (customer 4) \u53ea\u4e00\u6b21\u8ba2\u8d2d\u952e\u76d8, \u6240\u4ee5\u952e\u76d8\u662f Jerry \u6700\u7ecf\u5e38\u8ba2\u8d2d\u7684\u5546\u54c1.\nJohn (customer 5) \u6ca1\u6709\u8ba2\u8d2d\u8fc7\u5546\u54c1, \u6240\u4ee5\u6211\u4eec\u5e76\u6ca1\u6709\u628a John \u5305\u542b\u5728\u7ed3\u679c\u8868\u4e2d.\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1596](https://leetcode-cn.com/problems/the-most-frequently-ordered-products-for-each-customer)", "[\u6bcf\u4f4d\u987e\u5ba2\u6700\u7ecf\u5e38\u8ba2\u8d2d\u7684\u5546\u54c1](/solution/1500-1599/1596.The%20Most%20Frequently%20Ordered%20Products%20for%20Each%20Customer/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1596](https://leetcode.com/problems/the-most-frequently-ordered-products-for-each-customer)", "[The Most Frequently Ordered Products for Each Customer](/solution/1500-1599/1596.The%20Most%20Frequently%20Ordered%20Products%20for%20Each%20Customer/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1734", "frontend_question_id": "1587", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/bank-account-summary-ii", "url_en": "https://leetcode.com/problems/bank-account-summary-ii", "relative_path_cn": "/solution/1500-1599/1587.Bank%20Account%20Summary%20II/README.md", "relative_path_en": "/solution/1500-1599/1587.Bank%20Account%20Summary%20II/README_EN.md", "title_cn": "\u94f6\u884c\u8d26\u6237\u6982\u8981 II", "title_en": "Bank Account Summary II", "question_title_slug": "bank-account-summary-ii", "content_en": "

    Table: Users

    \n\n
    \n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| account      | int     |\n| name         | varchar |\n+--------------+---------+\naccount is the primary key for this table.\nEach row of this table contains the account number of each user in the bank.\n
    \n\n

     

    \n\n

    Table: Transactions

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| trans_id      | int     |\n| account       | int     |\n| amount        | int     |\n| transacted_on | date    |\n+---------------+---------+\ntrans_id is the primary key for this table.\nEach row of this table contains all changes made to all accounts.\namount is positive if the user received money and negative if they transferred money.\nAll accounts start with a balance 0.\n
    \n\n

     

    \n\n

    Write an SQL query to report the name and balance of users with a balance higher than 10000. The balance of an account is equal to the sum of the amounts of all transactions involving that account.

    \n\n

    Return the result table in any order.

    \n\n

    The query result format is in the following example.

    \n\n

     

    \n\n
    \nUsers table:\n+------------+--------------+\n| account    | name         |\n+------------+--------------+\n| 900001     | Alice        |\n| 900002     | Bob          |\n| 900003     | Charlie      |\n+------------+--------------+\n\nTransactions table:\n+------------+------------+------------+---------------+\n| trans_id   | account    | amount     | transacted_on |\n+------------+------------+------------+---------------+\n| 1          | 900001     | 7000       |  2020-08-01   |\n| 2          | 900001     | 7000       |  2020-09-01   |\n| 3          | 900001     | -3000      |  2020-09-02   |\n| 4          | 900002     | 1000       |  2020-09-12   |\n| 5          | 900003     | 6000       |  2020-08-07   |\n| 6          | 900003     | 6000       |  2020-09-07   |\n| 7          | 900003     | -4000      |  2020-09-11   |\n+------------+------------+------------+---------------+\n\nResult table:\n+------------+------------+\n| name       | balance    |\n+------------+------------+\n| Alice      | 11000      |\n+------------+------------+\nAlice's balance is (7000 + 7000 - 3000) = 11000.\nBob's balance is 1000.\nCharlie's balance is (6000 + 6000 - 4000) = 8000.\n
    \n", "content_cn": "

    \u8868: Users

    \n\n
    +--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| account      | int     |\n| name         | varchar |\n+--------------+---------+\naccount \u662f\u8be5\u8868\u7684\u4e3b\u952e.\n\u8868\u4e2d\u7684\u6bcf\u4e00\u884c\u5305\u542b\u94f6\u884c\u91cc\u4e2d\u6bcf\u4e00\u4e2a\u7528\u6237\u7684\u8d26\u53f7.\n
    \n\n

     

    \n\n

    \u8868: Transactions

    \n\n
    +---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| trans_id      | int     |\n| account       | int     |\n| amount        | int     |\n| transacted_on | date    |\n+---------------+---------+\ntrans_id \u662f\u8be5\u8868\u4e3b\u952e.\n\u8be5\u8868\u7684\u6bcf\u4e00\u884c\u5305\u542b\u4e86\u6240\u6709\u8d26\u6237\u7684\u4ea4\u6613\u6539\u53d8\u60c5\u51b5.\n\u5982\u679c\u7528\u6237\u6536\u5230\u4e86\u94b1, \u90a3\u4e48\u91d1\u989d\u662f\u6b63\u7684; \u5982\u679c\u7528\u6237\u8f6c\u4e86\u94b1, \u90a3\u4e48\u91d1\u989d\u662f\u8d1f\u7684.\n\u6240\u6709\u8d26\u6237\u7684\u8d77\u59cb\u4f59\u989d\u4e3a 0.\n
    \n\n

     

    \n\n

    \u5199\u4e00\u4e2a SQL,  \u62a5\u544a\u4f59\u989d\u9ad8\u4e8e 10000 \u7684\u6240\u6709\u7528\u6237\u7684\u540d\u5b57\u548c\u4f59\u989d. \u8d26\u6237\u7684\u4f59\u989d\u7b49\u4e8e\u5305\u542b\u8be5\u8d26\u6237\u7684\u6240\u6709\u4ea4\u6613\u7684\u603b\u548c.

    \n\n

    \u8fd4\u56de\u7ed3\u679c\u8868\u5355\u6ca1\u6709\u987a\u5e8f\u8981\u6c42.

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a.

    \n\n

     

    \n\n
    Users table:\n+------------+--------------+\n| account    | name         |\n+------------+--------------+\n| 900001     | Alice        |\n| 900002     | Bob          |\n| 900003     | Charlie      |\n+------------+--------------+\n\nTransactions table:\n+------------+------------+------------+---------------+\n| trans_id   | account    | amount     | transacted_on |\n+------------+------------+------------+---------------+\n| 1          | 900001     | 7000       |  2020-08-01   |\n| 2          | 900001     | 7000       |  2020-09-01   |\n| 3          | 900001     | -3000      |  2020-09-02   |\n| 4          | 900002     | 1000       |  2020-09-12   |\n| 5          | 900003     | 6000       |  2020-08-07   |\n| 6          | 900003     | 6000       |  2020-09-07   |\n| 7          | 900003     | -4000      |  2020-09-11   |\n+------------+------------+------------+---------------+\n\nResult table:\n+------------+------------+\n| name       | balance    |\n+------------+------------+\n| Alice      | 11000      |\n+------------+------------+\nAlice \u7684\u4f59\u989d\u4e3a(7000 + 7000 - 3000) = 11000.\nBob \u7684\u4f59\u989d\u4e3a1000.\nCharlie \u7684\u4f59\u989d\u4e3a(6000 + 6000 - 4000) = 8000.\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1587](https://leetcode-cn.com/problems/bank-account-summary-ii)", "[\u94f6\u884c\u8d26\u6237\u6982\u8981 II](/solution/1500-1599/1587.Bank%20Account%20Summary%20II/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1587](https://leetcode.com/problems/bank-account-summary-ii)", "[Bank Account Summary II](/solution/1500-1599/1587.Bank%20Account%20Summary%20II/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1733", "frontend_question_id": "1610", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-number-of-visible-points", "url_en": "https://leetcode.com/problems/maximum-number-of-visible-points", "relative_path_cn": "/solution/1600-1699/1610.Maximum%20Number%20of%20Visible%20Points/README.md", "relative_path_en": "/solution/1600-1699/1610.Maximum%20Number%20of%20Visible%20Points/README_EN.md", "title_cn": "\u53ef\u89c1\u70b9\u7684\u6700\u5927\u6570\u76ee", "title_en": "Maximum Number of Visible Points", "question_title_slug": "maximum-number-of-visible-points", "content_en": "

    You are given an array points, an integer angle, and your location, where location = [posx, posy] and points[i] = [xi, yi] both denote integral coordinates on the X-Y plane.

    \n\n

    Initially, you are facing directly east from your position. You cannot move from your position, but you can rotate. In other words, posx and posy cannot be changed. Your field of view in degrees is represented by angle, determining how wide you can see from any given view direction. Let d be the amount in degrees that you rotate counterclockwise. Then, your field of view is the inclusive range of angles [d - angle/2, d + angle/2].

    \n\n

    \n\n

    \n\n

    You can see some set of points if, for each point, the angle formed by the point, your position, and the immediate east direction from your position is in your field of view.

    \n\n

    There can be multiple points at one coordinate. There may be points at your location, and you can always see these points regardless of your rotation. Points do not obstruct your vision to other points.

    \n\n

    Return the maximum number of points you can see.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: points = [[2,1],[2,2],[3,3]], angle = 90, location = [1,1]\nOutput: 3\nExplanation: The shaded region represents your field of view. All points can be made visible in your field of view, including [3,3] even though [2,2] is in front and in the same line of sight.\n
    \n\n

    Example 2:

    \n\n
    \nInput: points = [[2,1],[2,2],[3,4],[1,1]], angle = 90, location = [1,1]\nOutput: 4\nExplanation: All points can be made visible in your field of view, including the one at your location.\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: points = [[1,0],[2,1]], angle = 13, location = [1,1]\nOutput: 1\nExplanation: You can only see one of the two points, as shown above.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= points.length <= 105
    • \n\t
    • points[i].length == 2
    • \n\t
    • location.length == 2
    • \n\t
    • 0 <= angle < 360
    • \n\t
    • 0 <= posx, posy, xi, yi <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u70b9\u6570\u7ec4 points \u548c\u4e00\u4e2a\u8868\u793a\u89d2\u5ea6\u7684\u6574\u6570 angle \uff0c\u4f60\u7684\u4f4d\u7f6e\u662f location \uff0c\u5176\u4e2d location = [posx, posy] \u4e14 points[i] = [xi, yi] \u90fd\u8868\u793a X-Y \u5e73\u9762\u4e0a\u7684\u6574\u6570\u5750\u6807\u3002

    \n\n

    \u6700\u5f00\u59cb\uff0c\u4f60\u9762\u5411\u4e1c\u65b9\u8fdb\u884c\u89c2\u6d4b\u3002\u4f60 \u4e0d\u80fd \u8fdb\u884c\u79fb\u52a8\u6539\u53d8\u4f4d\u7f6e\uff0c\u4f46\u53ef\u4ee5\u901a\u8fc7 \u81ea\u8f6c \u8c03\u6574\u89c2\u6d4b\u89d2\u5ea6\u3002\u6362\u53e5\u8bdd\u8bf4\uff0cposx \u548c posy \u4e0d\u80fd\u6539\u53d8\u3002\u4f60\u7684\u89c6\u91ce\u8303\u56f4\u7684\u89d2\u5ea6\u7528 angle \u8868\u793a\uff0c \u8fd9\u51b3\u5b9a\u4e86\u4f60\u89c2\u6d4b\u4efb\u610f\u65b9\u5411\u65f6\u53ef\u4ee5\u591a\u5bbd\u3002\u8bbe d \u4e3a\u4f60\u9006\u65f6\u9488\u81ea\u8f6c\u65cb\u8f6c\u7684\u5ea6\u6570\uff0c\u90a3\u4e48\u4f60\u7684\u89c6\u91ce\u5c31\u662f\u89d2\u5ea6\u8303\u56f4 [d - angle/2, d + angle/2] \u6240\u6307\u793a\u7684\u90a3\u7247\u533a\u57df\u3002

    \n\n\n\n

    \u5bf9\u4e8e\u6bcf\u4e2a\u70b9\uff0c\u5982\u679c\u7531\u8be5\u70b9\u3001\u4f60\u7684\u4f4d\u7f6e\u4ee5\u53ca\u4ece\u4f60\u7684\u4f4d\u7f6e\u76f4\u63a5\u5411\u4e1c\u7684\u65b9\u5411\u5f62\u6210\u7684\u89d2\u5ea6 \u4f4d\u4e8e\u4f60\u7684\u89c6\u91ce\u4e2d \uff0c\u90a3\u4e48\u4f60\u5c31\u53ef\u4ee5\u770b\u5230\u5b83\u3002

    \n\n

    \u540c\u4e00\u4e2a\u5750\u6807\u4e0a\u53ef\u4ee5\u6709\u591a\u4e2a\u70b9\u3002\u4f60\u6240\u5728\u7684\u4f4d\u7f6e\u4e5f\u53ef\u80fd\u5b58\u5728\u4e00\u4e9b\u70b9\uff0c\u4f46\u4e0d\u7ba1\u4f60\u7684\u600e\u4e48\u65cb\u8f6c\uff0c\u603b\u662f\u53ef\u4ee5\u770b\u5230\u8fd9\u4e9b\u70b9\u3002\u540c\u65f6\uff0c\u70b9\u4e0d\u4f1a\u963b\u788d\u4f60\u770b\u5230\u5176\u4ed6\u70b9\u3002

    \n\n

    \u8fd4\u56de\u4f60\u80fd\u770b\u5230\u7684\u70b9\u7684\u6700\u5927\u6570\u76ee\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1apoints = [[2,1],[2,2],[3,3]], angle = 90, location = [1,1]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u9634\u5f71\u533a\u57df\u4ee3\u8868\u4f60\u7684\u89c6\u91ce\u3002\u5728\u4f60\u7684\u89c6\u91ce\u4e2d\uff0c\u6240\u6709\u7684\u70b9\u90fd\u6e05\u6670\u53ef\u89c1\uff0c\u5c3d\u7ba1 [2,2] \u548c [3,3]\u5728\u540c\u4e00\u6761\u76f4\u7ebf\u4e0a\uff0c\u4f60\u4ecd\u7136\u53ef\u4ee5\u770b\u5230 [3,3] \u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1apoints = [[2,1],[2,2],[3,4],[1,1]], angle = 90, location = [1,1]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u5728\u4f60\u7684\u89c6\u91ce\u4e2d\uff0c\u6240\u6709\u7684\u70b9\u90fd\u6e05\u6670\u53ef\u89c1\uff0c\u5305\u62ec\u4f60\u6240\u5728\u4f4d\u7f6e\u7684\u90a3\u4e2a\u70b9\u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1apoints = [[1,0],[2,1]], angle = 13, location = [1,1]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u5982\u56fe\u6240\u793a\uff0c\u4f60\u53ea\u80fd\u770b\u5230\u4e24\u70b9\u4e4b\u4e00\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= points.length <= 105
    • \n\t
    • points[i].length == 2
    • \n\t
    • location.length == 2
    • \n\t
    • 0 <= angle < 360
    • \n\t
    • 0 <= posx, posy, xi, yi <= 100
    • \n
    \n", "tags_en": ["Geometry", "Two Pointers"], "tags_cn": ["\u51e0\u4f55", "\u53cc\u6307\u9488"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int visiblePoints(vector>& points, int angle, vector& location) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int visiblePoints(List> points, int angle, List location) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def visiblePoints(self, points, angle, location):\n \"\"\"\n :type points: List[List[int]]\n :type angle: int\n :type location: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def visiblePoints(self, points: List[List[int]], angle: int, location: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint visiblePoints(int** points, int pointsSize, int* pointsColSize, int angle, int* location, int locationSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int VisiblePoints(IList> points, int angle, IList location) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} points\n * @param {number} angle\n * @param {number[]} location\n * @return {number}\n */\nvar visiblePoints = function(points, angle, location) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} points\n# @param {Integer} angle\n# @param {Integer[]} location\n# @return {Integer}\ndef visible_points(points, angle, location)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func visiblePoints(_ points: [[Int]], _ angle: Int, _ location: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func visiblePoints(points [][]int, angle int, location []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def visiblePoints(points: List[List[Int]], angle: Int, location: List[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun visiblePoints(points: List>, angle: Int, location: List): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn visible_points(points: Vec>, angle: i32, location: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $points\n * @param Integer $angle\n * @param Integer[] $location\n * @return Integer\n */\n function visiblePoints($points, $angle, $location) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function visiblePoints(points: number[][], angle: number, location: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (visible-points points angle location)\n (-> (listof (listof exact-integer?)) exact-integer? (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1610](https://leetcode-cn.com/problems/maximum-number-of-visible-points)", "[\u53ef\u89c1\u70b9\u7684\u6700\u5927\u6570\u76ee](/solution/1600-1699/1610.Maximum%20Number%20of%20Visible%20Points/README.md)", "`\u51e0\u4f55`,`\u53cc\u6307\u9488`", "\u56f0\u96be", ""], "md_table_row_en": ["[1610](https://leetcode.com/problems/maximum-number-of-visible-points)", "[Maximum Number of Visible Points](/solution/1600-1699/1610.Maximum%20Number%20of%20Visible%20Points/README_EN.md)", "`Geometry`,`Two Pointers`", "Hard", ""]}, {"question_id": "1732", "frontend_question_id": "1611", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-one-bit-operations-to-make-integers-zero", "url_en": "https://leetcode.com/problems/minimum-one-bit-operations-to-make-integers-zero", "relative_path_cn": "/solution/1600-1699/1611.Minimum%20One%20Bit%20Operations%20to%20Make%20Integers%20Zero/README.md", "relative_path_en": "/solution/1600-1699/1611.Minimum%20One%20Bit%20Operations%20to%20Make%20Integers%20Zero/README_EN.md", "title_cn": "\u4f7f\u6574\u6570\u53d8\u4e3a 0 \u7684\u6700\u5c11\u64cd\u4f5c\u6b21\u6570", "title_en": "Minimum One Bit Operations to Make Integers Zero", "question_title_slug": "minimum-one-bit-operations-to-make-integers-zero", "content_en": "

    Given an integer n, you must transform it into 0 using the following operations any number of times:

    \n\n
      \n\t
    • Change the rightmost (0th) bit in the binary representation of n.
    • \n\t
    • Change the ith bit in the binary representation of n if the (i-1)th bit is set to 1 and the (i-2)th through 0th bits are set to 0.
    • \n
    \n\n

    Return the minimum number of operations to transform n into 0.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 0\nOutput: 0\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 3\nOutput: 2\nExplanation: The binary representation of 3 is "11".\n"11" -> "01" with the 2nd operation since the 0th bit is 1.\n"01" -> "00" with the 1st operation.\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 6\nOutput: 4\nExplanation: The binary representation of 6 is "110".\n"110" -> "010" with the 2nd operation since the 1st bit is 1 and 0th through 0th bits are 0.\n"010" -> "011" with the 1st operation.\n"011" -> "001" with the 2nd operation since the 0th bit is 1.\n"001" -> "000" with the 1st operation.\n
    \n\n

    Example 4:

    \n\n
    \nInput: n = 9\nOutput: 14\n
    \n\n

    Example 5:

    \n\n
    \nInput: n = 333\nOutput: 393\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= n <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n\uff0c\u4f60\u9700\u8981\u91cd\u590d\u6267\u884c\u591a\u6b21\u4e0b\u8ff0\u64cd\u4f5c\u5c06\u5176\u8f6c\u6362\u4e3a 0 \uff1a

    \n\n
      \n\t
    • \u7ffb\u8f6c n \u7684\u4e8c\u8fdb\u5236\u8868\u793a\u4e2d\u6700\u53f3\u4fa7\u4f4d\uff08\u7b2c 0 \u4f4d\uff09\u3002
    • \n\t
    • \u5982\u679c\u7b2c (i-1) \u4f4d\u4e3a 1 \u4e14\u4ece\u7b2c (i-2) \u4f4d\u5230\u7b2c 0 \u4f4d\u90fd\u4e3a 0\uff0c\u5219\u7ffb\u8f6c n \u7684\u4e8c\u8fdb\u5236\u8868\u793a\u4e2d\u7684\u7b2c i \u4f4d\u3002
    • \n
    \n\n

    \u8fd4\u56de\u5c06 n \u8f6c\u6362\u4e3a 0 \u7684\u6700\u5c0f\u64cd\u4f5c\u6b21\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 0\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 3\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a3 \u7684\u4e8c\u8fdb\u5236\u8868\u793a\u4e3a \"11\"\n\"11\" -> \"01\" \uff0c\u6267\u884c\u7684\u662f\u7b2c 2 \u79cd\u64cd\u4f5c\uff0c\u56e0\u4e3a\u7b2c 0 \u4f4d\u4e3a 1 \u3002\n\"01\" -> \"00\" \uff0c\u6267\u884c\u7684\u662f\u7b2c 1 \u79cd\u64cd\u4f5c\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 6\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a6 \u7684\u4e8c\u8fdb\u5236\u8868\u793a\u4e3a \"110\".\n\"110\" -> \"010\" \uff0c\u6267\u884c\u7684\u662f\u7b2c 2 \u79cd\u64cd\u4f5c\uff0c\u56e0\u4e3a\u7b2c 1 \u4f4d\u4e3a 1 \uff0c\u7b2c 0 \u5230 0 \u4f4d\u4e3a 0 \u3002\n\"010\" -> \"011\" \uff0c\u6267\u884c\u7684\u662f\u7b2c 1 \u79cd\u64cd\u4f5c\u3002\n\"011\" -> \"001\" \uff0c\u6267\u884c\u7684\u662f\u7b2c 2 \u79cd\u64cd\u4f5c\uff0c\u56e0\u4e3a\u7b2c 0 \u4f4d\u4e3a 1 \u3002\n\"001\" -> \"000\" \uff0c\u6267\u884c\u7684\u662f\u7b2c 1 \u79cd\u64cd\u4f5c\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 9\n\u8f93\u51fa\uff1a14\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 333\n\u8f93\u51fa\uff1a393\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= n <= 109
    • \n
    \n", "tags_en": ["Bit Manipulation", "Dynamic Programming"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minimumOneBitOperations(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minimumOneBitOperations(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimumOneBitOperations(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimumOneBitOperations(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minimumOneBitOperations(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinimumOneBitOperations(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar minimumOneBitOperations = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef minimum_one_bit_operations(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimumOneBitOperations(_ n: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimumOneBitOperations(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimumOneBitOperations(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimumOneBitOperations(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimum_one_bit_operations(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function minimumOneBitOperations($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimumOneBitOperations(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimum-one-bit-operations n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1611](https://leetcode-cn.com/problems/minimum-one-bit-operations-to-make-integers-zero)", "[\u4f7f\u6574\u6570\u53d8\u4e3a 0 \u7684\u6700\u5c11\u64cd\u4f5c\u6b21\u6570](/solution/1600-1699/1611.Minimum%20One%20Bit%20Operations%20to%20Make%20Integers%20Zero/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1611](https://leetcode.com/problems/minimum-one-bit-operations-to-make-integers-zero)", "[Minimum One Bit Operations to Make Integers Zero](/solution/1600-1699/1611.Minimum%20One%20Bit%20Operations%20to%20Make%20Integers%20Zero/README_EN.md)", "`Bit Manipulation`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "1731", "frontend_question_id": "1609", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/even-odd-tree", "url_en": "https://leetcode.com/problems/even-odd-tree", "relative_path_cn": "/solution/1600-1699/1609.Even%20Odd%20Tree/README.md", "relative_path_en": "/solution/1600-1699/1609.Even%20Odd%20Tree/README_EN.md", "title_cn": "\u5947\u5076\u6811", "title_en": "Even Odd Tree", "question_title_slug": "even-odd-tree", "content_en": "

    A binary tree is named Even-Odd if it meets the following conditions:

    \n\n
      \n\t
    • The root of the binary tree is at level index 0, its children are at level index 1, their children are at level index 2, etc.
    • \n\t
    • For every even-indexed level, all nodes at the level have odd integer values in strictly increasing order (from left to right).
    • \n\t
    • For every odd-indexed level, all nodes at the level have even integer values in strictly decreasing order (from left to right).
    • \n
    \n\n

    Given the root of a binary tree, return true if the binary tree is Even-Odd, otherwise return false.

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: root = [1,10,4,3,null,7,9,12,8,6,null,null,2]\nOutput: true\nExplanation: The node values on each level are:\nLevel 0: [1]\nLevel 1: [10,4]\nLevel 2: [3,7,9]\nLevel 3: [12,8,6,2]\nSince levels 0 and 2 are all odd and increasing, and levels 1 and 3 are all even and decreasing, the tree is Even-Odd.\n
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: root = [5,4,2,3,3,7]\nOutput: false\nExplanation: The node values on each level are:\nLevel 0: [5]\nLevel 1: [4,2]\nLevel 2: [3,3,7]\nNode values in the level 2 must be in strictly increasing order, so the tree is not Even-Odd.\n
    \n\n

    Example 3:

    \n\n

    \"\"

    \n\n
    \nInput: root = [5,9,1,3,5,7]\nOutput: false\nExplanation: Node values in the level 1 should be even integers.\n
    \n\n

    Example 4:

    \n\n
    \nInput: root = [1]\nOutput: true\n
    \n\n

    Example 5:

    \n\n
    \nInput: root = [11,8,6,1,3,9,11,30,20,18,16,12,10,4,2,17]\nOutput: true\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 105].
    • \n\t
    • 1 <= Node.val <= 106
    • \n
    \n", "content_cn": "

    \u5982\u679c\u4e00\u68f5\u4e8c\u53c9\u6811\u6ee1\u8db3\u4e0b\u8ff0\u51e0\u4e2a\u6761\u4ef6\uff0c\u5219\u53ef\u4ee5\u79f0\u4e3a \u5947\u5076\u6811 \uff1a

    \n\n
      \n\t
    • \u4e8c\u53c9\u6811\u6839\u8282\u70b9\u6240\u5728\u5c42\u4e0b\u6807\u4e3a 0 \uff0c\u6839\u7684\u5b50\u8282\u70b9\u6240\u5728\u5c42\u4e0b\u6807\u4e3a 1 \uff0c\u6839\u7684\u5b59\u8282\u70b9\u6240\u5728\u5c42\u4e0b\u6807\u4e3a 2 \uff0c\u4f9d\u6b64\u7c7b\u63a8\u3002
    • \n\t
    • \u5076\u6570\u4e0b\u6807 \u5c42\u4e0a\u7684\u6240\u6709\u8282\u70b9\u7684\u503c\u90fd\u662f \u5947 \u6574\u6570\uff0c\u4ece\u5de6\u5230\u53f3\u6309\u987a\u5e8f \u4e25\u683c\u9012\u589e
    • \n\t
    • \u5947\u6570\u4e0b\u6807 \u5c42\u4e0a\u7684\u6240\u6709\u8282\u70b9\u7684\u503c\u90fd\u662f \u5076 \u6574\u6570\uff0c\u4ece\u5de6\u5230\u53f3\u6309\u987a\u5e8f \u4e25\u683c\u9012\u51cf
    • \n
    \n\n

    \u7ed9\u4f60\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9\uff0c\u5982\u679c\u4e8c\u53c9\u6811\u4e3a \u5947\u5076\u6811 \uff0c\u5219\u8fd4\u56de true \uff0c\u5426\u5219\u8fd4\u56de false \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aroot = [1,10,4,3,null,7,9,12,8,6,null,null,2]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u6bcf\u4e00\u5c42\u7684\u8282\u70b9\u503c\u5206\u522b\u662f\uff1a\n0 \u5c42\uff1a[1]\n1 \u5c42\uff1a[10,4]\n2 \u5c42\uff1a[3,7,9]\n3 \u5c42\uff1a[12,8,6,2]\n\u7531\u4e8e 0 \u5c42\u548c 2 \u5c42\u4e0a\u7684\u8282\u70b9\u503c\u90fd\u662f\u5947\u6570\u4e14\u4e25\u683c\u9012\u589e\uff0c\u800c 1 \u5c42\u548c 3 \u5c42\u4e0a\u7684\u8282\u70b9\u503c\u90fd\u662f\u5076\u6570\u4e14\u4e25\u683c\u9012\u51cf\uff0c\u56e0\u6b64\u8fd9\u662f\u4e00\u68f5\u5947\u5076\u6811\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aroot = [5,4,2,3,3,7]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u6bcf\u4e00\u5c42\u7684\u8282\u70b9\u503c\u5206\u522b\u662f\uff1a\n0 \u5c42\uff1a[5]\n1 \u5c42\uff1a[4,2]\n2 \u5c42\uff1a[3,3,7]\n2 \u5c42\u4e0a\u7684\u8282\u70b9\u503c\u4e0d\u6ee1\u8db3\u4e25\u683c\u9012\u589e\u7684\u6761\u4ef6\uff0c\u6240\u4ee5\u8fd9\u4e0d\u662f\u4e00\u68f5\u5947\u5076\u6811\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aroot = [5,9,1,3,5,7]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a1 \u5c42\u4e0a\u7684\u8282\u70b9\u503c\u5e94\u4e3a\u5076\u6570\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [1]\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [11,8,6,1,3,9,11,30,20,18,16,12,10,4,2,17]\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u6570\u5728\u8303\u56f4 [1, 105] \u5185
    • \n\t
    • 1 <= Node.val <= 106
    • \n
    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n bool isEvenOddTree(TreeNode* root) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public boolean isEvenOddTree(TreeNode root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def isEvenOddTree(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: bool\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def isEvenOddTree(self, root: TreeNode) -> bool:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nbool isEvenOddTree(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public bool IsEvenOddTree(TreeNode root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {boolean}\n */\nvar isEvenOddTree = function(root) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Boolean}\ndef is_even_odd_tree(root)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func isEvenOddTree(_ root: TreeNode?) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc isEvenOddTree(root *TreeNode) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def isEvenOddTree(root: TreeNode): Boolean = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun isEvenOddTree(root: TreeNode?): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn is_even_odd_tree(root: Option>>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Boolean\n */\n function isEvenOddTree($root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction isEvenOddTree(root: TreeNode | null): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (is-even-odd-tree root)\n (-> (or/c tree-node? #f) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1609](https://leetcode-cn.com/problems/even-odd-tree)", "[\u5947\u5076\u6811](/solution/1600-1699/1609.Even%20Odd%20Tree/README.md)", "`\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1609](https://leetcode.com/problems/even-odd-tree)", "[Even Odd Tree](/solution/1600-1699/1609.Even%20Odd%20Tree/README_EN.md)", "`Tree`", "Medium", ""]}, {"question_id": "1730", "frontend_question_id": "1608", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/special-array-with-x-elements-greater-than-or-equal-x", "url_en": "https://leetcode.com/problems/special-array-with-x-elements-greater-than-or-equal-x", "relative_path_cn": "/solution/1600-1699/1608.Special%20Array%20With%20X%20Elements%20Greater%20Than%20or%20Equal%20X/README.md", "relative_path_en": "/solution/1600-1699/1608.Special%20Array%20With%20X%20Elements%20Greater%20Than%20or%20Equal%20X/README_EN.md", "title_cn": "\u7279\u6b8a\u6570\u7ec4\u7684\u7279\u5f81\u503c", "title_en": "Special Array With X Elements Greater Than or Equal X", "question_title_slug": "special-array-with-x-elements-greater-than-or-equal-x", "content_en": "

    You are given an array nums of non-negative integers. nums is considered special if there exists a number x such that there are exactly x numbers in nums that are greater than or equal to x.

    \n\n

    Notice that x does not have to be an element in nums.

    \n\n

    Return x if the array is special, otherwise, return -1. It can be proven that if nums is special, the value for x is unique.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [3,5]\nOutput: 2\nExplanation: There are 2 values (3 and 5) that are greater than or equal to 2.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [0,0]\nOutput: -1\nExplanation: No numbers fit the criteria for x.\nIf x = 0, there should be 0 numbers >= x, but there are 2.\nIf x = 1, there should be 1 number >= x, but there are 0.\nIf x = 2, there should be 2 numbers >= x, but there are 0.\nx cannot be greater since there are only 2 numbers in nums.\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [0,4,3,0,4]\nOutput: 3\nExplanation: There are 3 values that are greater than or equal to 3.\n
    \n\n

    Example 4:

    \n\n
    \nInput: nums = [3,6,7,7,0]\nOutput: -1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 100
    • \n\t
    • 0 <= nums[i] <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\u6570\u7ec4 nums \u3002\u5982\u679c\u5b58\u5728\u4e00\u4e2a\u6570 x \uff0c\u4f7f\u5f97 nums \u4e2d\u6070\u597d\u6709 x \u4e2a\u5143\u7d20 \u5927\u4e8e\u6216\u8005\u7b49\u4e8e x \uff0c\u90a3\u4e48\u5c31\u79f0 nums \u662f\u4e00\u4e2a \u7279\u6b8a\u6570\u7ec4 \uff0c\u800c x \u662f\u8be5\u6570\u7ec4\u7684 \u7279\u5f81\u503c \u3002

    \n\n

    \u6ce8\u610f\uff1a x \u4e0d\u5fc5 \u662f nums \u7684\u4e2d\u7684\u5143\u7d20\u3002

    \n\n

    \u5982\u679c\u6570\u7ec4 nums \u662f\u4e00\u4e2a \u7279\u6b8a\u6570\u7ec4 \uff0c\u8bf7\u8fd4\u56de\u5b83\u7684\u7279\u5f81\u503c x \u3002\u5426\u5219\uff0c\u8fd4\u56de -1 \u3002\u53ef\u4ee5\u8bc1\u660e\u7684\u662f\uff0c\u5982\u679c nums \u662f\u7279\u6b8a\u6570\u7ec4\uff0c\u90a3\u4e48\u5176\u7279\u5f81\u503c x \u662f \u552f\u4e00\u7684 \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [3,5]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6709 2 \u4e2a\u5143\u7d20\uff083 \u548c 5\uff09\u5927\u4e8e\u6216\u7b49\u4e8e 2 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [0,0]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u6ca1\u6709\u6ee1\u8db3\u9898\u76ee\u8981\u6c42\u7684\u7279\u6b8a\u6570\u7ec4\uff0c\u6545\u800c\u4e5f\u4e0d\u5b58\u5728\u7279\u5f81\u503c x \u3002\n\u5982\u679c x = 0\uff0c\u5e94\u8be5\u6709 0 \u4e2a\u5143\u7d20 >= x\uff0c\u4f46\u5b9e\u9645\u6709 2 \u4e2a\u3002\n\u5982\u679c x = 1\uff0c\u5e94\u8be5\u6709 1 \u4e2a\u5143\u7d20 >= x\uff0c\u4f46\u5b9e\u9645\u6709 0 \u4e2a\u3002\n\u5982\u679c x = 2\uff0c\u5e94\u8be5\u6709 2 \u4e2a\u5143\u7d20 >= x\uff0c\u4f46\u5b9e\u9645\u6709 0 \u4e2a\u3002\nx \u4e0d\u80fd\u53d6\u66f4\u5927\u7684\u503c\uff0c\u56e0\u4e3a nums \u4e2d\u53ea\u6709\u4e24\u4e2a\u5143\u7d20\u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [0,4,3,0,4]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6709 3 \u4e2a\u5143\u7d20\u5927\u4e8e\u6216\u7b49\u4e8e 3 \u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [3,6,7,7,0]\n\u8f93\u51fa\uff1a-1\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 100
    • \n\t
    • 0 <= nums[i] <= 1000
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int specialArray(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int specialArray(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def specialArray(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def specialArray(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint specialArray(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SpecialArray(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar specialArray = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef special_array(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func specialArray(_ nums: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func specialArray(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def specialArray(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun specialArray(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn special_array(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function specialArray($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function specialArray(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (special-array nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1608](https://leetcode-cn.com/problems/special-array-with-x-elements-greater-than-or-equal-x)", "[\u7279\u6b8a\u6570\u7ec4\u7684\u7279\u5f81\u503c](/solution/1600-1699/1608.Special%20Array%20With%20X%20Elements%20Greater%20Than%20or%20Equal%20X/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1608](https://leetcode.com/problems/special-array-with-x-elements-greater-than-or-equal-x)", "[Special Array With X Elements Greater Than or Equal X](/solution/1600-1699/1608.Special%20Array%20With%20X%20Elements%20Greater%20Than%20or%20Equal%20X/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1729", "frontend_question_id": "1586", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/binary-search-tree-iterator-ii", "url_en": "https://leetcode.com/problems/binary-search-tree-iterator-ii", "relative_path_cn": "/solution/1500-1599/1586.Binary%20Search%20Tree%20Iterator%20II/README.md", "relative_path_en": "/solution/1500-1599/1586.Binary%20Search%20Tree%20Iterator%20II/README_EN.md", "title_cn": "\u4e8c\u53c9\u641c\u7d22\u6811\u8fed\u4ee3\u5668 II", "title_en": "Binary Search Tree Iterator II", "question_title_slug": "binary-search-tree-iterator-ii", "content_en": "

    Implement the BSTIterator class that represents an iterator over the in-order traversal of a binary search tree (BST):

    \n\n
      \n\t
    • BSTIterator(TreeNode root) Initializes an object of the BSTIterator class. The root of the BST is given as part of the constructor. The pointer should be initialized to a non-existent number smaller than any element in the BST.
    • \n\t
    • boolean hasNext() Returns true if there exists a number in the traversal to the right of the pointer, otherwise returns false.
    • \n\t
    • int next() Moves the pointer to the right, then returns the number at the pointer.
    • \n\t
    • boolean hasPrev() Returns true if there exists a number in the traversal to the left of the pointer, otherwise returns false.
    • \n\t
    • int prev() Moves the pointer to the left, then returns the number at the pointer.
    • \n
    \n\n

    Notice that by initializing the pointer to a non-existent smallest number, the first call to next() will return the smallest element in the BST.

    \n\n

    You may assume that next() and prev() calls will always be valid. That is, there will be at least a next/previous number in the in-order traversal when next()/prev() is called.

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput\n["BSTIterator", "next", "next", "prev", "next", "hasNext", "next", "next", "next", "hasNext", "hasPrev", "prev", "prev"]\n[[[7, 3, 15, null, null, 9, 20]], [null], [null], [null], [null], [null], [null], [null], [null], [null], [null], [null], [null]]\nOutput\n[null, 3, 7, 3, 7, true, 9, 15, 20, false, true, 15, 9]\n\nExplanation\n// The underlined element is where the pointer currently is.\nBSTIterator bSTIterator = new BSTIterator([7, 3, 15, null, null, 9, 20]); // state is   [3, 7, 9, 15, 20]\nbSTIterator.next(); // state becomes [3, 7, 9, 15, 20], return 3\nbSTIterator.next(); // state becomes [3, 7, 9, 15, 20], return 7\nbSTIterator.prev(); // state becomes [3, 7, 9, 15, 20], return 3\nbSTIterator.next(); // state becomes [3, 7, 9, 15, 20], return 7\nbSTIterator.hasNext(); // return true\nbSTIterator.next(); // state becomes [3, 7, 9, 15, 20], return 9\nbSTIterator.next(); // state becomes [3, 7, 9, 15, 20], return 15\nbSTIterator.next(); // state becomes [3, 7, 9, 15, 20], return 20\nbSTIterator.hasNext(); // return false\nbSTIterator.hasPrev(); // return true\nbSTIterator.prev(); // state becomes [3, 7, 9, 15, 20], return 15\nbSTIterator.prev(); // state becomes [3, 7, 9, 15, 20], return 9\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 105].
    • \n\t
    • 0 <= Node.val <= 106
    • \n\t
    • At most 105 calls will be made to hasNext, next, hasPrev, and prev.
    • \n
    \n\n

     

    \nFollow up: Could you solve the problem without precalculating the values of the tree?", "content_cn": "

    \u5b9e\u73b0\u4e8c\u53c9\u641c\u7d22\u6811\uff08BST\uff09\u7684\u4e2d\u5e8f\u904d\u5386\u8fed\u4ee3\u5668 BSTIterator \u7c7b\uff1a

    \n\n
      \n\t
    • BSTIterator(TreeNode root) \u521d\u59cb\u5316 BSTIterator \u7c7b\u7684\u5b9e\u4f8b\u3002\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6839\u8282\u70b9 root \u4f5c\u4e3a\u6784\u9020\u51fd\u6570\u7684\u53c2\u6570\u4f20\u5165\u3002\u5185\u90e8\u6307\u9488\u4f7f\u7528\u4e00\u4e2a\u4e0d\u5b58\u5728\u4e8e\u6811\u4e2d\u4e14\u5c0f\u4e8e\u6811\u4e2d\u4efb\u610f\u503c\u7684\u6570\u503c\u6765\u521d\u59cb\u5316\u3002
    • \n\t
    • boolean hasNext() \u5982\u679c\u5f53\u524d\u6307\u9488\u5728\u4e2d\u5e8f\u904d\u5386\u5e8f\u5217\u4e2d\uff0c\u5b58\u5728\u53f3\u4fa7\u6570\u503c\uff0c\u8fd4\u56de true \uff0c\u5426\u5219\u8fd4\u56de false \u3002
    • \n\t
    • int next() \u5c06\u6307\u9488\u5728\u4e2d\u5e8f\u904d\u5386\u5e8f\u5217\u4e2d\u5411\u53f3\u79fb\u52a8\uff0c\u7136\u540e\u8fd4\u56de\u79fb\u52a8\u540e\u6307\u9488\u6240\u6307\u6570\u503c\u3002
    • \n\t
    • boolean hasPrev() \u5982\u679c\u5f53\u524d\u6307\u9488\u5728\u4e2d\u5e8f\u904d\u5386\u5e8f\u5217\u4e2d\uff0c\u5b58\u5728\u5de6\u4fa7\u6570\u503c\uff0c\u8fd4\u56de true \uff0c\u5426\u5219\u8fd4\u56de false \u3002
    • \n\t
    • int prev() \u5c06\u6307\u9488\u5728\u4e2d\u5e8f\u904d\u5386\u5e8f\u5217\u4e2d\u5411\u5de6\u79fb\u52a8\uff0c\u7136\u540e\u8fd4\u56de\u79fb\u52a8\u540e\u6307\u9488\u6240\u6307\u6570\u503c\u3002
    • \n
    \n\n

    \u6ce8\u610f\uff0c\u867d\u7136\u6211\u4eec\u4f7f\u7528\u6811\u4e2d\u4e0d\u5b58\u5728\u7684\u6700\u5c0f\u503c\u6765\u521d\u59cb\u5316\u5185\u90e8\u6307\u9488\uff0c\u7b2c\u4e00\u6b21\u8c03\u7528 next() \u9700\u8981\u8fd4\u56de\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u6700\u5c0f\u7684\u5143\u7d20\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u5047\u8bbe next() \u548c prev() \u7684\u8c03\u7528\u603b\u662f\u6709\u6548\u7684\u3002\u5373\uff0c\u5f53 next()/prev() \u88ab\u8c03\u7528\u7684\u65f6\u5019\uff0c\u5728\u4e2d\u5e8f\u904d\u5386\u5e8f\u5217\u4e2d\u4e00\u5b9a\u5b58\u5728\u4e0b\u4e00\u4e2a/\u4e0a\u4e00\u4e2a\u5143\u7d20\u3002

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u53ef\u4ee5\u4e0d\u63d0\u524d\u904d\u5386\u6811\u4e2d\u7684\u503c\u6765\u89e3\u51b3\u95ee\u9898\u5417\uff1f

    \n\n

     

    \n\n

    \u793a\u4f8b 1:

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\n["BSTIterator", "next", "next", "prev", "next", "hasNext", "next", "next", "next", "hasNext", "hasPrev", "prev", "prev"]\n[[[7, 3, 15, null, null, 9, 20]], [null], [null], [null], [null], [null], [null], [null], [null], [null], [null], [null], [null]]\n\u8f93\u51fa\n[null, 3, 7, 3, 7, true, 9, 15, 20, false, true, 15, 9]\n\n\u89e3\u91ca\n// \u5212\u7ebf\u7684\u5143\u7d20\u8868\u793a\u6307\u9488\u5f53\u524d\u7684\u4f4d\u7f6e\u3002\nBSTIterator bSTIterator = new BSTIterator([7, 3, 15, null, null, 9, 20]); // \u5f53\u524d\u72b6\u6001\u4e3a <u> </u> [3, 7, 9, 15, 20]\nbSTIterator.next(); // \u72b6\u6001\u53d8\u4e3a [<u>3</u>, 7, 9, 15, 20], \u8fd4\u56de 3\nbSTIterator.next(); // \u72b6\u6001\u53d8\u4e3a [3, <u>7</u>, 9, 15, 20], \u8fd4\u56de 7\nbSTIterator.prev(); // \u72b6\u6001\u53d8\u4e3a [<u>3</u>, 7, 9, 15, 20], \u8fd4\u56de 3\nbSTIterator.next(); // \u72b6\u6001\u53d8\u4e3a [3, <u>7</u>, 9, 15, 20], \u8fd4\u56de 7\nbSTIterator.hasNext(); // \u8fd4\u56de true\nbSTIterator.next(); // \u72b6\u6001\u53d8\u4e3a [3, 7, <u>9</u>, 15, 20], \u8fd4\u56de 9\nbSTIterator.next(); // \u72b6\u6001\u53d8\u4e3a [3, 7, 9, <u>15</u>, 20], \u8fd4\u56de 15\nbSTIterator.next(); // \u72b6\u6001\u53d8\u4e3a [3, 7, 9, 15, <u>20</u>], \u8fd4\u56de 20\nbSTIterator.hasNext(); // \u8fd4\u56de false\nbSTIterator.hasPrev(); // \u8fd4\u56de true\nbSTIterator.prev(); // \u72b6\u6001\u53d8\u4e3a [3, 7, 9, <u>15</u>, 20], \u8fd4\u56de 15\nbSTIterator.prev(); // \u72b6\u6001\u53d8\u4e3a [3, 7, <u>9</u>, 15, 20], \u8fd4\u56de 9\n
    \n\n

     

    \n\n

    \u63d0\u793a:

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u4e2a\u6570\u7684\u8303\u56f4\u662f [1, 105] \u3002
    • \n\t
    • 0 <= Node.val <= 106
    • \n\t
    • \u6700\u591a\u8c03\u7528 105 \u6b21 hasNext\u3001 next\u3001 hasPrev \u548c prev \u3002
    • \n
    \n", "tags_en": ["Tree", "Design"], "tags_cn": ["\u6811", "\u8bbe\u8ba1"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass BSTIterator {\npublic:\n BSTIterator(TreeNode* root) {\n\n }\n \n bool hasNext() {\n\n }\n \n int next() {\n\n }\n \n bool hasPrev() {\n\n }\n \n int prev() {\n\n }\n};\n\n/**\n * Your BSTIterator object will be instantiated and called as such:\n * BSTIterator* obj = new BSTIterator(root);\n * bool param_1 = obj->hasNext();\n * int param_2 = obj->next();\n * bool param_3 = obj->hasPrev();\n * int param_4 = obj->prev();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass BSTIterator {\n\n public BSTIterator(TreeNode root) {\n\n }\n \n public boolean hasNext() {\n\n }\n \n public int next() {\n\n }\n \n public boolean hasPrev() {\n\n }\n \n public int prev() {\n\n }\n}\n\n/**\n * Your BSTIterator object will be instantiated and called as such:\n * BSTIterator obj = new BSTIterator(root);\n * boolean param_1 = obj.hasNext();\n * int param_2 = obj.next();\n * boolean param_3 = obj.hasPrev();\n * int param_4 = obj.prev();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass BSTIterator(object):\n\n def __init__(self, root):\n \"\"\"\n :type root: TreeNode\n \"\"\"\n\n\n def hasNext(self):\n \"\"\"\n :rtype: bool\n \"\"\"\n\n\n def next(self):\n \"\"\"\n :rtype: int\n \"\"\"\n\n\n def hasPrev(self):\n \"\"\"\n :rtype: bool\n \"\"\"\n\n\n def prev(self):\n \"\"\"\n :rtype: int\n \"\"\"\n\n\n\n# Your BSTIterator object will be instantiated and called as such:\n# obj = BSTIterator(root)\n# param_1 = obj.hasNext()\n# param_2 = obj.next()\n# param_3 = obj.hasPrev()\n# param_4 = obj.prev()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass BSTIterator:\n\n def __init__(self, root: TreeNode):\n\n\n def hasNext(self) -> bool:\n\n\n def next(self) -> int:\n\n\n def hasPrev(self) -> bool:\n\n\n def prev(self) -> int:\n\n\n\n# Your BSTIterator object will be instantiated and called as such:\n# obj = BSTIterator(root)\n# param_1 = obj.hasNext()\n# param_2 = obj.next()\n# param_3 = obj.hasPrev()\n# param_4 = obj.prev()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n\ntypedef struct {\n\n} BSTIterator;\n\n\nBSTIterator* bSTIteratorCreate(struct TreeNode* root) {\n\n}\n\nbool bSTIteratorHasNext(BSTIterator* obj) {\n\n}\n\nint bSTIteratorNext(BSTIterator* obj) {\n\n}\n\nbool bSTIteratorHasPrev(BSTIterator* obj) {\n\n}\n\nint bSTIteratorPrev(BSTIterator* obj) {\n\n}\n\nvoid bSTIteratorFree(BSTIterator* obj) {\n\n}\n\n/**\n * Your BSTIterator struct will be instantiated and called as such:\n * BSTIterator* obj = bSTIteratorCreate(root);\n * bool param_1 = bSTIteratorHasNext(obj);\n \n * int param_2 = bSTIteratorNext(obj);\n \n * bool param_3 = bSTIteratorHasPrev(obj);\n \n * int param_4 = bSTIteratorPrev(obj);\n \n * bSTIteratorFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class BSTIterator {\n\n public BSTIterator(TreeNode root) {\n\n }\n \n public bool HasNext() {\n\n }\n \n public int Next() {\n\n }\n \n public bool HasPrev() {\n\n }\n \n public int Prev() {\n\n }\n}\n\n/**\n * Your BSTIterator object will be instantiated and called as such:\n * BSTIterator obj = new BSTIterator(root);\n * bool param_1 = obj.HasNext();\n * int param_2 = obj.Next();\n * bool param_3 = obj.HasPrev();\n * int param_4 = obj.Prev();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n */\nvar BSTIterator = function(root) {\n\n};\n\n/**\n * @return {boolean}\n */\nBSTIterator.prototype.hasNext = function() {\n\n};\n\n/**\n * @return {number}\n */\nBSTIterator.prototype.next = function() {\n\n};\n\n/**\n * @return {boolean}\n */\nBSTIterator.prototype.hasPrev = function() {\n\n};\n\n/**\n * @return {number}\n */\nBSTIterator.prototype.prev = function() {\n\n};\n\n/**\n * Your BSTIterator object will be instantiated and called as such:\n * var obj = new BSTIterator(root)\n * var param_1 = obj.hasNext()\n * var param_2 = obj.next()\n * var param_3 = obj.hasPrev()\n * var param_4 = obj.prev()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\nclass BSTIterator\n\n=begin\n :type root: TreeNode\n=end\n def initialize(root)\n\n end\n\n\n=begin\n :rtype: Boolean\n=end\n def has_next()\n\n end\n\n\n=begin\n :rtype: Integer\n=end\n def next()\n\n end\n\n\n=begin\n :rtype: Boolean\n=end\n def has_prev()\n\n end\n\n\n=begin\n :rtype: Integer\n=end\n def prev()\n\n end\n\n\nend\n\n# Your BSTIterator object will be instantiated and called as such:\n# obj = BSTIterator.new(root)\n# param_1 = obj.has_next()\n# param_2 = obj.next()\n# param_3 = obj.has_prev()\n# param_4 = obj.prev()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\n\nclass BSTIterator {\n\n init(_ root: TreeNode?) {\n\n }\n \n func hasNext() -> Bool {\n\n }\n \n func next() -> Int {\n\n }\n \n func hasPrev() -> Bool {\n\n }\n \n func prev() -> Int {\n\n }\n}\n\n/**\n * Your BSTIterator object will be instantiated and called as such:\n * let obj = BSTIterator(root)\n * let ret_1: Bool = obj.hasNext()\n * let ret_2: Int = obj.next()\n * let ret_3: Bool = obj.hasPrev()\n * let ret_4: Int = obj.prev()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\ntype BSTIterator struct {\n\n}\n\n\nfunc Constructor(root *TreeNode) BSTIterator {\n\n}\n\n\nfunc (this *BSTIterator) HasNext() bool {\n\n}\n\n\nfunc (this *BSTIterator) Next() int {\n\n}\n\n\nfunc (this *BSTIterator) HasPrev() bool {\n\n}\n\n\nfunc (this *BSTIterator) Prev() int {\n\n}\n\n\n/**\n * Your BSTIterator object will be instantiated and called as such:\n * obj := Constructor(root);\n * param_1 := obj.HasNext();\n * param_2 := obj.Next();\n * param_3 := obj.HasPrev();\n * param_4 := obj.Prev();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nclass BSTIterator(_root: TreeNode) {\n\n def hasNext(): Boolean = {\n\n }\n\n def next(): Int = {\n\n }\n\n def hasPrev(): Boolean = {\n\n }\n\n def prev(): Int = {\n\n }\n\n}\n\n/**\n * Your BSTIterator object will be instantiated and called as such:\n * var obj = new BSTIterator(root)\n * var param_1 = obj.hasNext()\n * var param_2 = obj.next()\n * var param_3 = obj.hasPrev()\n * var param_4 = obj.prev()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass BSTIterator(root: TreeNode?) {\n\n fun hasNext(): Boolean {\n\n }\n\n fun next(): Int {\n\n }\n\n fun hasPrev(): Boolean {\n\n }\n\n fun prev(): Int {\n\n }\n\n}\n\n/**\n * Your BSTIterator object will be instantiated and called as such:\n * var obj = BSTIterator(root)\n * var param_1 = obj.hasNext()\n * var param_2 = obj.next()\n * var param_3 = obj.hasPrev()\n * var param_4 = obj.prev()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nstruct BSTIterator {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl BSTIterator {\n\n fn new(root: Option>>) -> Self {\n\n }\n \n fn has_next(&self) -> bool {\n\n }\n \n fn next(&self) -> i32 {\n\n }\n \n fn has_prev(&self) -> bool {\n\n }\n \n fn prev(&self) -> i32 {\n\n }\n}\n\n/**\n * Your BSTIterator object will be instantiated and called as such:\n * let obj = BSTIterator::new(root);\n * let ret_1: bool = obj.has_next();\n * let ret_2: i32 = obj.next();\n * let ret_3: bool = obj.has_prev();\n * let ret_4: i32 = obj.prev();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass BSTIterator {\n /**\n * @param TreeNode $root\n */\n function __construct($root) {\n\n }\n\n /**\n * @return Boolean\n */\n function hasNext() {\n\n }\n\n /**\n * @return Integer\n */\n function next() {\n\n }\n\n /**\n * @return Boolean\n */\n function hasPrev() {\n\n }\n\n /**\n * @return Integer\n */\n function prev() {\n\n }\n}\n\n/**\n * Your BSTIterator object will be instantiated and called as such:\n * $obj = BSTIterator($root);\n * $ret_1 = $obj->hasNext();\n * $ret_2 = $obj->next();\n * $ret_3 = $obj->hasPrev();\n * $ret_4 = $obj->prev();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nclass BSTIterator {\n constructor(root: TreeNode | null) {\n\n }\n\n hasNext(): boolean {\n\n }\n\n next(): number {\n\n }\n\n hasPrev(): boolean {\n\n }\n\n prev(): number {\n\n }\n}\n\n/**\n * Your BSTIterator object will be instantiated and called as such:\n * var obj = new BSTIterator(root)\n * var param_1 = obj.hasNext()\n * var param_2 = obj.next()\n * var param_3 = obj.hasPrev()\n * var param_4 = obj.prev()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define bst-iterator%\n (class object%\n (super-new)\n\n ; root : (or/c tree-node? #f)\n (init-field\n root)\n \n ; has-next : -> boolean?\n (define/public (has-next)\n\n )\n ; next : -> exact-integer?\n (define/public (next)\n\n )\n ; has-prev : -> boolean?\n (define/public (has-prev)\n\n )\n ; prev : -> exact-integer?\n (define/public (prev)\n\n )))\n\n;; Your bst-iterator% object will be instantiated and called as such:\n;; (define obj (new bst-iterator% [root root]))\n;; (define param_1 (send obj has-next))\n;; (define param_2 (send obj next))\n;; (define param_3 (send obj has-prev))\n;; (define param_4 (send obj prev))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1586](https://leetcode-cn.com/problems/binary-search-tree-iterator-ii)", "[\u4e8c\u53c9\u641c\u7d22\u6811\u8fed\u4ee3\u5668 II](/solution/1500-1599/1586.Binary%20Search%20Tree%20Iterator%20II/README.md)", "`\u6811`,`\u8bbe\u8ba1`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1586](https://leetcode.com/problems/binary-search-tree-iterator-ii)", "[Binary Search Tree Iterator II](/solution/1500-1599/1586.Binary%20Search%20Tree%20Iterator%20II/README_EN.md)", "`Tree`,`Design`", "Medium", "\ud83d\udd12"]}, {"question_id": "1728", "frontend_question_id": "1622", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/fancy-sequence", "url_en": "https://leetcode.com/problems/fancy-sequence", "relative_path_cn": "/solution/1600-1699/1622.Fancy%20Sequence/README.md", "relative_path_en": "/solution/1600-1699/1622.Fancy%20Sequence/README_EN.md", "title_cn": "\u5947\u5999\u5e8f\u5217", "title_en": "Fancy Sequence", "question_title_slug": "fancy-sequence", "content_en": "

    Write an API that generates fancy sequences using the append, addAll, and multAll operations.

    \n\n

    Implement the Fancy class:

    \n\n
      \n\t
    • Fancy() Initializes the object with an empty sequence.
    • \n\t
    • void append(val) Appends an integer val to the end of the sequence.
    • \n\t
    • void addAll(inc) Increments all existing values in the sequence by an integer inc.
    • \n\t
    • void multAll(m) Multiplies all existing values in the sequence by an integer m.
    • \n\t
    • int getIndex(idx) Gets the current value at index idx (0-indexed) of the sequence modulo 109 + 7. If the index is greater or equal than the length of the sequence, return -1.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["Fancy", "append", "addAll", "append", "multAll", "getIndex", "addAll", "append", "multAll", "getIndex", "getIndex", "getIndex"]\n[[], [2], [3], [7], [2], [0], [3], [10], [2], [0], [1], [2]]\nOutput\n[null, null, null, null, null, 10, null, null, null, 26, 34, 20]\n\nExplanation\nFancy fancy = new Fancy();\nfancy.append(2);   // fancy sequence: [2]\nfancy.addAll(3);   // fancy sequence: [2+3] -> [5]\nfancy.append(7);   // fancy sequence: [5, 7]\nfancy.multAll(2);  // fancy sequence: [5*2, 7*2] -> [10, 14]\nfancy.getIndex(0); // return 10\nfancy.addAll(3);   // fancy sequence: [10+3, 14+3] -> [13, 17]\nfancy.append(10);  // fancy sequence: [13, 17, 10]\nfancy.multAll(2);  // fancy sequence: [13*2, 17*2, 10*2] -> [26, 34, 20]\nfancy.getIndex(0); // return 26\nfancy.getIndex(1); // return 34\nfancy.getIndex(2); // return 20\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= val, inc, m <= 100
    • \n\t
    • 0 <= idx <= 105
    • \n\t
    • At most 105 calls total will be made to append, addAll, multAll, and getIndex.
    • \n
    \n", "content_cn": "

    \u8bf7\u4f60\u5b9e\u73b0\u4e09\u4e2a API append\uff0caddAll\u00a0\u548c\u00a0multAll\u00a0\u6765\u5b9e\u73b0\u5947\u5999\u5e8f\u5217\u3002

    \n\n

    \u8bf7\u5b9e\u73b0\u00a0Fancy\u00a0\u7c7b \uff1a

    \n\n
      \n\t
    • Fancy()\u00a0\u521d\u59cb\u5316\u4e00\u4e2a\u7a7a\u5e8f\u5217\u5bf9\u8c61\u3002
    • \n\t
    • void append(val) \u5c06\u6574\u6570\u00a0val\u00a0\u6dfb\u52a0\u5728\u5e8f\u5217\u672b\u5c3e\u3002
    • \n\t
    • void addAll(inc)\u00a0\u5c06\u6240\u6709\u5e8f\u5217\u4e2d\u7684\u73b0\u6709\u6570\u503c\u90fd\u589e\u52a0\u00a0inc\u00a0\u3002
    • \n\t
    • void multAll(m)\u00a0\u5c06\u5e8f\u5217\u4e2d\u7684\u6240\u6709\u73b0\u6709\u6570\u503c\u90fd\u4e58\u4ee5\u6574\u6570\u00a0m\u00a0\u3002
    • \n\t
    • int getIndex(idx) \u5f97\u5230\u4e0b\u6807\u4e3a\u00a0idx\u00a0\u5904\u7684\u6570\u503c\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\uff0c\u5e76\u5c06\u7ed3\u679c\u5bf9\u00a0109 + 7\u00a0\u53d6\u4f59\u3002\u5982\u679c\u4e0b\u6807\u5927\u4e8e\u7b49\u4e8e\u5e8f\u5217\u7684\u957f\u5ea6\uff0c\u8bf7\u8fd4\u56de\u00a0-1\u00a0\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\n[\"Fancy\", \"append\", \"addAll\", \"append\", \"multAll\", \"getIndex\", \"addAll\", \"append\", \"multAll\", \"getIndex\", \"getIndex\", \"getIndex\"]\n[[], [2], [3], [7], [2], [0], [3], [10], [2], [0], [1], [2]]\n\u8f93\u51fa\uff1a\n[null, null, null, null, null, 10, null, null, null, 26, 34, 20]\n\n\u89e3\u91ca\uff1a\nFancy fancy = new Fancy();\nfancy.append(2);   // \u5947\u5999\u5e8f\u5217\uff1a[2]\nfancy.addAll(3);   // \u5947\u5999\u5e8f\u5217\uff1a[2+3] -> [5]\nfancy.append(7);   // \u5947\u5999\u5e8f\u5217\uff1a[5, 7]\nfancy.multAll(2);  // \u5947\u5999\u5e8f\u5217\uff1a[5*2, 7*2] -> [10, 14]\nfancy.getIndex(0); // \u8fd4\u56de 10\nfancy.addAll(3);   // \u5947\u5999\u5e8f\u5217\uff1a[10+3, 14+3] -> [13, 17]\nfancy.append(10);  // \u5947\u5999\u5e8f\u5217\uff1a[13, 17, 10]\nfancy.multAll(2);  // \u5947\u5999\u5e8f\u5217\uff1a[13*2, 17*2, 10*2] -> [26, 34, 20]\nfancy.getIndex(0); // \u8fd4\u56de 26\nfancy.getIndex(1); // \u8fd4\u56de 34\nfancy.getIndex(2); // \u8fd4\u56de 20\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= val, inc, m <= 100
    • \n\t
    • 0 <= idx <= 105
    • \n\t
    • \u603b\u5171\u6700\u591a\u4f1a\u6709\u00a0105\u00a0\u6b21\u5bf9\u00a0append\uff0caddAll\uff0cmultAll\u00a0\u548c\u00a0getIndex\u00a0\u7684\u8c03\u7528\u3002
    • \n
    \n", "tags_en": ["Design", "Math"], "tags_cn": ["\u8bbe\u8ba1", "\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Fancy {\npublic:\n Fancy() {\n\n }\n \n void append(int val) {\n\n }\n \n void addAll(int inc) {\n\n }\n \n void multAll(int m) {\n\n }\n \n int getIndex(int idx) {\n\n }\n};\n\n/**\n * Your Fancy object will be instantiated and called as such:\n * Fancy* obj = new Fancy();\n * obj->append(val);\n * obj->addAll(inc);\n * obj->multAll(m);\n * int param_4 = obj->getIndex(idx);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Fancy {\n\n public Fancy() {\n\n }\n \n public void append(int val) {\n\n }\n \n public void addAll(int inc) {\n\n }\n \n public void multAll(int m) {\n\n }\n \n public int getIndex(int idx) {\n\n }\n}\n\n/**\n * Your Fancy object will be instantiated and called as such:\n * Fancy obj = new Fancy();\n * obj.append(val);\n * obj.addAll(inc);\n * obj.multAll(m);\n * int param_4 = obj.getIndex(idx);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Fancy(object):\n\n def __init__(self):\n\n\n def append(self, val):\n \"\"\"\n :type val: int\n :rtype: None\n \"\"\"\n\n\n def addAll(self, inc):\n \"\"\"\n :type inc: int\n :rtype: None\n \"\"\"\n\n\n def multAll(self, m):\n \"\"\"\n :type m: int\n :rtype: None\n \"\"\"\n\n\n def getIndex(self, idx):\n \"\"\"\n :type idx: int\n :rtype: int\n \"\"\"\n\n\n\n# Your Fancy object will be instantiated and called as such:\n# obj = Fancy()\n# obj.append(val)\n# obj.addAll(inc)\n# obj.multAll(m)\n# param_4 = obj.getIndex(idx)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Fancy:\n\n def __init__(self):\n\n\n def append(self, val: int) -> None:\n\n\n def addAll(self, inc: int) -> None:\n\n\n def multAll(self, m: int) -> None:\n\n\n def getIndex(self, idx: int) -> int:\n\n\n\n# Your Fancy object will be instantiated and called as such:\n# obj = Fancy()\n# obj.append(val)\n# obj.addAll(inc)\n# obj.multAll(m)\n# param_4 = obj.getIndex(idx)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} Fancy;\n\n\nFancy* fancyCreate() {\n\n}\n\nvoid fancyAppend(Fancy* obj, int val) {\n\n}\n\nvoid fancyAddAll(Fancy* obj, int inc) {\n\n}\n\nvoid fancyMultAll(Fancy* obj, int m) {\n\n}\n\nint fancyGetIndex(Fancy* obj, int idx) {\n\n}\n\nvoid fancyFree(Fancy* obj) {\n\n}\n\n/**\n * Your Fancy struct will be instantiated and called as such:\n * Fancy* obj = fancyCreate();\n * fancyAppend(obj, val);\n \n * fancyAddAll(obj, inc);\n \n * fancyMultAll(obj, m);\n \n * int param_4 = fancyGetIndex(obj, idx);\n \n * fancyFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Fancy {\n\n public Fancy() {\n\n }\n \n public void Append(int val) {\n\n }\n \n public void AddAll(int inc) {\n\n }\n \n public void MultAll(int m) {\n\n }\n \n public int GetIndex(int idx) {\n\n }\n}\n\n/**\n * Your Fancy object will be instantiated and called as such:\n * Fancy obj = new Fancy();\n * obj.Append(val);\n * obj.AddAll(inc);\n * obj.MultAll(m);\n * int param_4 = obj.GetIndex(idx);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "\nvar Fancy = function() {\n\n};\n\n/** \n * @param {number} val\n * @return {void}\n */\nFancy.prototype.append = function(val) {\n\n};\n\n/** \n * @param {number} inc\n * @return {void}\n */\nFancy.prototype.addAll = function(inc) {\n\n};\n\n/** \n * @param {number} m\n * @return {void}\n */\nFancy.prototype.multAll = function(m) {\n\n};\n\n/** \n * @param {number} idx\n * @return {number}\n */\nFancy.prototype.getIndex = function(idx) {\n\n};\n\n/**\n * Your Fancy object will be instantiated and called as such:\n * var obj = new Fancy()\n * obj.append(val)\n * obj.addAll(inc)\n * obj.multAll(m)\n * var param_4 = obj.getIndex(idx)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class Fancy\n def initialize()\n\n end\n\n\n=begin\n :type val: Integer\n :rtype: Void\n=end\n def append(val)\n\n end\n\n\n=begin\n :type inc: Integer\n :rtype: Void\n=end\n def add_all(inc)\n\n end\n\n\n=begin\n :type m: Integer\n :rtype: Void\n=end\n def mult_all(m)\n\n end\n\n\n=begin\n :type idx: Integer\n :rtype: Integer\n=end\n def get_index(idx)\n\n end\n\n\nend\n\n# Your Fancy object will be instantiated and called as such:\n# obj = Fancy.new()\n# obj.append(val)\n# obj.add_all(inc)\n# obj.mult_all(m)\n# param_4 = obj.get_index(idx)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass Fancy {\n\n init() {\n\n }\n \n func append(_ val: Int) {\n\n }\n \n func addAll(_ inc: Int) {\n\n }\n \n func multAll(_ m: Int) {\n\n }\n \n func getIndex(_ idx: Int) -> Int {\n\n }\n}\n\n/**\n * Your Fancy object will be instantiated and called as such:\n * let obj = Fancy()\n * obj.append(val)\n * obj.addAll(inc)\n * obj.multAll(m)\n * let ret_4: Int = obj.getIndex(idx)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type Fancy struct {\n\n}\n\n\nfunc Constructor() Fancy {\n\n}\n\n\nfunc (this *Fancy) Append(val int) {\n\n}\n\n\nfunc (this *Fancy) AddAll(inc int) {\n\n}\n\n\nfunc (this *Fancy) MultAll(m int) {\n\n}\n\n\nfunc (this *Fancy) GetIndex(idx int) int {\n\n}\n\n\n/**\n * Your Fancy object will be instantiated and called as such:\n * obj := Constructor();\n * obj.Append(val);\n * obj.AddAll(inc);\n * obj.MultAll(m);\n * param_4 := obj.GetIndex(idx);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class Fancy() {\n\n def append(`val`: Int) {\n\n }\n\n def addAll(inc: Int) {\n\n }\n\n def multAll(m: Int) {\n\n }\n\n def getIndex(idx: Int): Int = {\n\n }\n\n}\n\n/**\n * Your Fancy object will be instantiated and called as such:\n * var obj = new Fancy()\n * obj.append(`val`)\n * obj.addAll(inc)\n * obj.multAll(m)\n * var param_4 = obj.getIndex(idx)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Fancy() {\n\n fun append(`val`: Int) {\n\n }\n\n fun addAll(inc: Int) {\n\n }\n\n fun multAll(m: Int) {\n\n }\n\n fun getIndex(idx: Int): Int {\n\n }\n\n}\n\n/**\n * Your Fancy object will be instantiated and called as such:\n * var obj = Fancy()\n * obj.append(`val`)\n * obj.addAll(inc)\n * obj.multAll(m)\n * var param_4 = obj.getIndex(idx)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct Fancy {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl Fancy {\n\n fn new() -> Self {\n\n }\n \n fn append(&self, val: i32) {\n\n }\n \n fn add_all(&self, inc: i32) {\n\n }\n \n fn mult_all(&self, m: i32) {\n\n }\n \n fn get_index(&self, idx: i32) -> i32 {\n\n }\n}\n\n/**\n * Your Fancy object will be instantiated and called as such:\n * let obj = Fancy::new();\n * obj.append(val);\n * obj.add_all(inc);\n * obj.mult_all(m);\n * let ret_4: i32 = obj.get_index(idx);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Fancy {\n /**\n */\n function __construct() {\n\n }\n\n /**\n * @param Integer $val\n * @return NULL\n */\n function append($val) {\n\n }\n\n /**\n * @param Integer $inc\n * @return NULL\n */\n function addAll($inc) {\n\n }\n\n /**\n * @param Integer $m\n * @return NULL\n */\n function multAll($m) {\n\n }\n\n /**\n * @param Integer $idx\n * @return Integer\n */\n function getIndex($idx) {\n\n }\n}\n\n/**\n * Your Fancy object will be instantiated and called as such:\n * $obj = Fancy();\n * $obj->append($val);\n * $obj->addAll($inc);\n * $obj->multAll($m);\n * $ret_4 = $obj->getIndex($idx);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class Fancy {\n constructor() {\n\n }\n\n append(val: number): void {\n\n }\n\n addAll(inc: number): void {\n\n }\n\n multAll(m: number): void {\n\n }\n\n getIndex(idx: number): number {\n\n }\n}\n\n/**\n * Your Fancy object will be instantiated and called as such:\n * var obj = new Fancy()\n * obj.append(val)\n * obj.addAll(inc)\n * obj.multAll(m)\n * var param_4 = obj.getIndex(idx)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define fancy%\n (class object%\n (super-new)\n (init-field)\n \n ; append : exact-integer? -> void?\n (define/public (append val)\n\n )\n ; add-all : exact-integer? -> void?\n (define/public (add-all inc)\n\n )\n ; mult-all : exact-integer? -> void?\n (define/public (mult-all m)\n\n )\n ; get-index : exact-integer? -> exact-integer?\n (define/public (get-index idx)\n\n )))\n\n;; Your fancy% object will be instantiated and called as such:\n;; (define obj (new fancy%))\n;; (send obj append val)\n;; (send obj add-all inc)\n;; (send obj mult-all m)\n;; (define param_4 (send obj get-index idx))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1622](https://leetcode-cn.com/problems/fancy-sequence)", "[\u5947\u5999\u5e8f\u5217](/solution/1600-1699/1622.Fancy%20Sequence/README.md)", "`\u8bbe\u8ba1`,`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[1622](https://leetcode.com/problems/fancy-sequence)", "[Fancy Sequence](/solution/1600-1699/1622.Fancy%20Sequence/README_EN.md)", "`Design`,`Math`", "Hard", ""]}, {"question_id": "1727", "frontend_question_id": "1728", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/cat-and-mouse-ii", "url_en": "https://leetcode.com/problems/cat-and-mouse-ii", "relative_path_cn": "/solution/1700-1799/1728.Cat%20and%20Mouse%20II/README.md", "relative_path_en": "/solution/1700-1799/1728.Cat%20and%20Mouse%20II/README_EN.md", "title_cn": "\u732b\u548c\u8001\u9f20 II", "title_en": "Cat and Mouse II", "question_title_slug": "cat-and-mouse-ii", "content_en": "

    A game is played by a cat and a mouse named Cat and Mouse.

    \n\n

    The environment is represented by a grid of size rows x cols, where each element is a wall, floor, player (Cat, Mouse), or food.

    \n\n
      \n\t
    • Players are represented by the characters 'C'(Cat),'M'(Mouse).
    • \n\t
    • Floors are represented by the character '.' and can be walked on.
    • \n\t
    • Walls are represented by the character '#' and cannot be walked on.
    • \n\t
    • Food is represented by the character 'F' and can be walked on.
    • \n\t
    • There is only one of each character 'C', 'M', and 'F' in grid.
    • \n
    \n\n

    Mouse and Cat play according to the following rules:

    \n\n
      \n\t
    • Mouse moves first, then they take turns to move.
    • \n\t
    • During each turn, Cat and Mouse can jump in one of the four directions (left, right, up, down). They cannot jump over the wall nor outside of the grid.
    • \n\t
    • catJump, mouseJump are the maximum lengths Cat and Mouse can jump at a time, respectively. Cat and Mouse can jump less than the maximum length.
    • \n\t
    • Staying in the same position is allowed.
    • \n\t
    • Mouse can jump over Cat.
    • \n
    \n\n

    The game can end in 4 ways:

    \n\n
      \n\t
    • If Cat occupies the same position as Mouse, Cat wins.
    • \n\t
    • If Cat reaches the food first, Cat wins.
    • \n\t
    • If Mouse reaches the food first, Mouse wins.
    • \n\t
    • If Mouse cannot get to the food within 1000 turns, Cat wins.
    • \n
    \n\n

    Given a rows x cols matrix grid and two integers catJump and mouseJump, return true if Mouse can win the game if both Cat and Mouse play optimally, otherwise return false.

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: grid = ["####F","#C...","M...."], catJump = 1, mouseJump = 2\nOutput: true\nExplanation: Cat cannot catch Mouse on its turn nor can it get the food before Mouse.\n
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: grid = ["M.C...F"], catJump = 1, mouseJump = 4\nOutput: true\n
    \n\n

    Example 3:

    \n\n
    \nInput: grid = ["M.C...F"], catJump = 1, mouseJump = 3\nOutput: false\n
    \n\n

    Example 4:

    \n\n
    \nInput: grid = ["C...#","...#F","....#","M...."], catJump = 2, mouseJump = 5\nOutput: false\n
    \n\n

    Example 5:

    \n\n
    \nInput: grid = [".M...","..#..","#..#.","C#.#.","...#F"], catJump = 3, mouseJump = 1\nOutput: true\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • rows == grid.length
    • \n\t
    • cols = grid[i].length
    • \n\t
    • 1 <= rows, cols <= 8
    • \n\t
    • grid[i][j] consist only of characters 'C', 'M', 'F', '.', and '#'.
    • \n\t
    • There is only one of each character 'C', 'M', and 'F' in grid.
    • \n\t
    • 1 <= catJump, mouseJump <= 8
    • \n
    \n", "content_cn": "

    \u4e00\u53ea\u732b\u548c\u4e00\u53ea\u8001\u9f20\u5728\u73a9\u4e00\u4e2a\u53eb\u505a\u732b\u548c\u8001\u9f20\u7684\u6e38\u620f\u3002

    \n\n

    \u5b83\u4eec\u6240\u5904\u7684\u73af\u5883\u8bbe\u5b9a\u662f\u4e00\u4e2a\u00a0rows x cols\u00a0\u7684\u65b9\u683c grid\u00a0\uff0c\u5176\u4e2d\u6bcf\u4e2a\u683c\u5b50\u53ef\u80fd\u662f\u4e00\u5835\u5899\u3001\u4e00\u5757\u5730\u677f\u3001\u4e00\u4f4d\u73a9\u5bb6\uff08\u732b\u6216\u8005\u8001\u9f20\uff09\u6216\u8005\u98df\u7269\u3002

    \n\n
      \n\t
    • \u73a9\u5bb6\u7531\u5b57\u7b26\u00a0'C'\u00a0\uff08\u4ee3\u8868\u732b\uff09\u548c\u00a0'M'\u00a0\uff08\u4ee3\u8868\u8001\u9f20\uff09\u8868\u793a\u3002
    • \n\t
    • \u5730\u677f\u7531\u5b57\u7b26\u00a0'.'\u00a0\u8868\u793a\uff0c\u73a9\u5bb6\u53ef\u4ee5\u901a\u8fc7\u8fd9\u4e2a\u683c\u5b50\u3002
    • \n\t
    • \u5899\u7528\u5b57\u7b26\u00a0'#'\u00a0\u8868\u793a\uff0c\u73a9\u5bb6\u4e0d\u80fd\u901a\u8fc7\u8fd9\u4e2a\u683c\u5b50\u3002
    • \n\t
    • \u98df\u7269\u7528\u5b57\u7b26\u00a0'F'\u00a0\u8868\u793a\uff0c\u73a9\u5bb6\u53ef\u4ee5\u901a\u8fc7\u8fd9\u4e2a\u683c\u5b50\u3002
    • \n\t
    • \u5b57\u7b26\u00a0'C'\u00a0\uff0c\u00a0'M'\u00a0\u548c\u00a0'F'\u00a0\u5728\u00a0grid\u00a0\u4e2d\u90fd\u53ea\u4f1a\u51fa\u73b0\u4e00\u6b21\u3002
    • \n
    \n\n

    \u732b\u548c\u8001\u9f20\u6309\u7167\u5982\u4e0b\u89c4\u5219\u79fb\u52a8\uff1a

    \n\n
      \n\t
    • \u8001\u9f20 \u5148\u79fb\u52a8\u00a0\uff0c\u7136\u540e\u4e24\u540d\u73a9\u5bb6\u8f6e\u6d41\u79fb\u52a8\u3002
    • \n\t
    • \u6bcf\u4e00\u6b21\u64cd\u4f5c\u65f6\uff0c\u732b\u548c\u8001\u9f20\u53ef\u4ee5\u8df3\u5230\u4e0a\u4e0b\u5de6\u53f3\u56db\u4e2a\u65b9\u5411\u4e4b\u4e00\u7684\u683c\u5b50\uff0c\u4ed6\u4eec\u4e0d\u80fd\u8df3\u8fc7\u5899\u4e5f\u4e0d\u80fd\u8df3\u51fa\u00a0grid\u00a0\u3002
    • \n\t
    • catJump \u548c\u00a0mouseJump\u00a0\u662f\u732b\u548c\u8001\u9f20\u5206\u522b\u8df3\u4e00\u6b21\u80fd\u5230\u8fbe\u7684\u6700\u8fdc\u8ddd\u79bb\uff0c\u5b83\u4eec\u4e5f\u53ef\u4ee5\u8df3\u5c0f\u4e8e\u6700\u5927\u8ddd\u79bb\u7684\u957f\u5ea6\u3002
    • \n\t
    • \u5b83\u4eec\u53ef\u4ee5\u505c\u7559\u5728\u539f\u5730\u3002
    • \n\t
    • \u8001\u9f20\u53ef\u4ee5\u8df3\u8dc3\u8fc7\u732b\u7684\u4f4d\u7f6e\u3002
    • \n
    \n\n

    \u6e38\u620f\u6709 4 \u79cd\u65b9\u5f0f\u4f1a\u7ed3\u675f\uff1a

    \n\n
      \n\t
    • \u5982\u679c\u732b\u8ddf\u8001\u9f20\u5904\u5728\u76f8\u540c\u7684\u4f4d\u7f6e\uff0c\u90a3\u4e48\u732b\u83b7\u80dc\u3002
    • \n\t
    • \u5982\u679c\u732b\u5148\u5230\u8fbe\u98df\u7269\uff0c\u90a3\u4e48\u732b\u83b7\u80dc\u3002
    • \n\t
    • \u5982\u679c\u8001\u9f20\u5148\u5230\u8fbe\u98df\u7269\uff0c\u90a3\u4e48\u8001\u9f20\u83b7\u80dc\u3002
    • \n\t
    • \u5982\u679c\u8001\u9f20\u4e0d\u80fd\u5728 1000 \u6b21\u64cd\u4f5c\u4ee5\u5185\u5230\u8fbe\u98df\u7269\uff0c\u90a3\u4e48\u732b\u83b7\u80dc\u3002
    • \n
    \n\n

    \u7ed9\u4f60\u00a0rows x cols\u00a0\u7684\u77e9\u9635\u00a0grid\u00a0\u548c\u4e24\u4e2a\u6574\u6570\u00a0catJump\u00a0\u548c\u00a0mouseJump\u00a0\uff0c\u53cc\u65b9\u90fd\u91c7\u53d6\u6700\u4f18\u7b56\u7565\uff0c\u5982\u679c\u8001\u9f20\u83b7\u80dc\uff0c\u90a3\u4e48\u8bf7\u4f60\u8fd4\u56de\u00a0true\u00a0\uff0c\u5426\u5219\u8fd4\u56de false\u00a0\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1agrid = [\"####F\",\"#C...\",\"M....\"], catJump = 1, mouseJump = 2\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u732b\u65e0\u6cd5\u6293\u5230\u8001\u9f20\uff0c\u4e5f\u6ca1\u6cd5\u6bd4\u8001\u9f20\u5148\u5230\u8fbe\u98df\u7269\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1agrid = [\"M.C...F\"], catJump = 1, mouseJump = 4\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1agrid = [\"M.C...F\"], catJump = 1, mouseJump = 3\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1agrid = [\"C...#\",\"...#F\",\"....#\",\"M....\"], catJump = 2, mouseJump = 5\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1agrid = [\".M...\",\"..#..\",\"#..#.\",\"C#.#.\",\"...#F\"], catJump = 3, mouseJump = 1\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • rows == grid.length
    • \n\t
    • cols = grid[i].length
    • \n\t
    • 1 <= rows, cols <= 8
    • \n\t
    • grid[i][j] \u53ea\u5305\u542b\u5b57\u7b26\u00a0'C'\u00a0\uff0c'M'\u00a0\uff0c'F'\u00a0\uff0c'.'\u00a0\u548c\u00a0'#'\u00a0\u3002
    • \n\t
    • grid\u00a0\u4e2d\u53ea\u5305\u542b\u4e00\u4e2a\u00a0'C'\u00a0\uff0c'M'\u00a0\u548c\u00a0'F'\u00a0\u3002
    • \n\t
    • 1 <= catJump, mouseJump <= 8
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canMouseWin(vector& grid, int catJump, int mouseJump) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canMouseWin(String[] grid, int catJump, int mouseJump) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canMouseWin(self, grid, catJump, mouseJump):\n \"\"\"\n :type grid: List[str]\n :type catJump: int\n :type mouseJump: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canMouseWin(self, grid: List[str], catJump: int, mouseJump: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canMouseWin(char ** grid, int gridSize, int catJump, int mouseJump){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanMouseWin(string[] grid, int catJump, int mouseJump) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} grid\n * @param {number} catJump\n * @param {number} mouseJump\n * @return {boolean}\n */\nvar canMouseWin = function(grid, catJump, mouseJump) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} grid\n# @param {Integer} cat_jump\n# @param {Integer} mouse_jump\n# @return {Boolean}\ndef can_mouse_win(grid, cat_jump, mouse_jump)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canMouseWin(_ grid: [String], _ catJump: Int, _ mouseJump: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canMouseWin(grid []string, catJump int, mouseJump int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canMouseWin(grid: Array[String], catJump: Int, mouseJump: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canMouseWin(grid: Array, catJump: Int, mouseJump: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_mouse_win(grid: Vec, cat_jump: i32, mouse_jump: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $grid\n * @param Integer $catJump\n * @param Integer $mouseJump\n * @return Boolean\n */\n function canMouseWin($grid, $catJump, $mouseJump) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canMouseWin(grid: string[], catJump: number, mouseJump: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-mouse-win grid catJump mouseJump)\n (-> (listof string?) exact-integer? exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1728](https://leetcode-cn.com/problems/cat-and-mouse-ii)", "[\u732b\u548c\u8001\u9f20 II](/solution/1700-1799/1728.Cat%20and%20Mouse%20II/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1728](https://leetcode.com/problems/cat-and-mouse-ii)", "[Cat and Mouse II](/solution/1700-1799/1728.Cat%20and%20Mouse%20II/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1726", "frontend_question_id": "1620", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/coordinate-with-maximum-network-quality", "url_en": "https://leetcode.com/problems/coordinate-with-maximum-network-quality", "relative_path_cn": "/solution/1600-1699/1620.Coordinate%20With%20Maximum%20Network%20Quality/README.md", "relative_path_en": "/solution/1600-1699/1620.Coordinate%20With%20Maximum%20Network%20Quality/README_EN.md", "title_cn": "\u7f51\u7edc\u4fe1\u53f7\u6700\u597d\u7684\u5750\u6807", "title_en": "Coordinate With Maximum Network Quality", "question_title_slug": "coordinate-with-maximum-network-quality", "content_en": "

    You are given an array of network towers towers and an integer radius, where towers[i] = [xi, yi, qi] denotes the ith network tower with location (xi, yi) and quality factor qi. All the coordinates are integral coordinates on the X-Y plane, and the distance between two coordinates is the Euclidean distance.

    \n\n

    The integer radius denotes the maximum distance in which the tower is reachable. The tower is reachable if the distance is less than or equal to radius. Outside that distance, the signal becomes garbled, and the tower is not reachable.

    \n\n

    The signal quality of the ith tower at a coordinate (x, y) is calculated with the formula ⌊qi / (1 + d)⌋, where d is the distance between the tower and the coordinate. The network quality at a coordinate is the sum of the signal qualities from all the reachable towers.

    \n\n

    Return the integral coordinate where the network quality is maximum. If there are multiple coordinates with the same network quality, return the lexicographically minimum coordinate.

    \n\n

    Note:

    \n\n
      \n\t
    • A coordinate (x1, y1) is lexicographically smaller than (x2, y2) if either x1 < x2 or x1 == x2 and y1 < y2.
    • \n\t
    • ⌊val⌋ is the greatest integer less than or equal to val (the floor function).
    • \n
    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: towers = [[1,2,5],[2,1,7],[3,1,9]], radius = 2\nOutput: [2,1]\nExplanation: \nAt coordinate (2, 1) the total quality is 13\n- Quality of 7 from (2, 1) results in ⌊7 / (1 + sqrt(0)⌋ = ⌊7⌋ = 7\n- Quality of 5 from (1, 2) results in ⌊5 / (1 + sqrt(2)⌋ = ⌊2.07⌋ = 2\n- Quality of 9 from (3, 1) results in ⌊9 / (1 + sqrt(1)⌋ = ⌊4.5⌋ = 4\nNo other coordinate has higher quality.
    \n\n

    Example 2:

    \n\n
    \nInput: towers = [[23,11,21]], radius = 9\nOutput: [23,11]\n
    \n\n

    Example 3:

    \n\n
    \nInput: towers = [[1,2,13],[2,1,7],[0,1,9]], radius = 2\nOutput: [1,2]\n
    \n\n

    Example 4:

    \n\n
    \nInput: towers = [[2,1,9],[0,1,9]], radius = 2\nOutput: [0,1]\nExplanation: Both (0, 1) and (2, 1) are optimal in terms of quality but (0, 1) is lexicograpically minimal.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= towers.length <= 50
    • \n\t
    • towers[i].length == 3
    • \n\t
    • 0 <= xi, yi, qi <= 50
    • \n\t
    • 1 <= radius <= 50
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 towers\u00a0\u548c\u4e00\u4e2a\u6574\u6570 radius\u00a0\uff0c\u6570\u7ec4\u4e2d\u5305\u542b\u4e00\u4e9b\u7f51\u7edc\u4fe1\u53f7\u5854\uff0c\u5176\u4e2d\u00a0towers[i] = [xi, yi, qi]\u00a0\u8868\u793a\u7b2c\u00a0i\u00a0\u4e2a\u7f51\u7edc\u4fe1\u53f7\u5854\u7684\u5750\u6807\u662f\u00a0(xi, yi)\u00a0\u4e14\u4fe1\u53f7\u5f3a\u5ea6\u53c2\u6570\u4e3a\u00a0qi\u00a0\u3002\u6240\u6709\u5750\u6807\u90fd\u662f\u5728\u00a0 X-Y \u5750\u6807\u7cfb\u5185\u7684\u00a0\u6574\u6570\u00a0\u5750\u6807\u3002\u4e24\u4e2a\u5750\u6807\u4e4b\u95f4\u7684\u8ddd\u79bb\u7528 \u6b27\u51e0\u91cc\u5f97\u8ddd\u79bb\u00a0\u8ba1\u7b97\u3002

    \n\n

    \u6574\u6570\u00a0radius\u00a0\u8868\u793a\u4e00\u4e2a\u5854 \u80fd\u5230\u8fbe\u00a0\u7684 \u6700\u8fdc\u8ddd\u79bb\u00a0\u3002\u5982\u679c\u4e00\u4e2a\u5750\u6807\u8ddf\u5854\u7684\u8ddd\u79bb\u5728 radius\u00a0\u4ee5\u5185\uff0c\u90a3\u4e48\u8be5\u5854\u7684\u4fe1\u53f7\u53ef\u4ee5\u5230\u8fbe\u8be5\u5750\u6807\u3002\u5728\u8fd9\u4e2a\u8303\u56f4\u4ee5\u5916\u4fe1\u53f7\u4f1a\u5f88\u5fae\u5f31\uff0c\u6240\u4ee5 radius\u00a0\u4ee5\u5916\u7684\u8ddd\u79bb\u8be5\u5854\u662f \u4e0d\u80fd\u5230\u8fbe\u7684\u00a0\u3002

    \n\n

    \u5982\u679c\u7b2c i\u00a0\u4e2a\u5854\u80fd\u5230\u8fbe (x, y)\u00a0\uff0c\u90a3\u4e48\u8be5\u5854\u5728\u6b64\u5904\u7684\u4fe1\u53f7\u4e3a\u00a0\u230aqi / (1 + d)\u230b\u00a0\uff0c\u5176\u4e2d\u00a0d\u00a0\u662f\u5854\u8ddf\u6b64\u5750\u6807\u7684\u8ddd\u79bb\u3002\u4e00\u4e2a\u5750\u6807\u7684 \u7f51\u7edc\u4fe1\u53f7\u00a0\u662f\u6240\u6709 \u80fd\u5230\u8fbe\u00a0\u8be5\u5750\u6807\u7684\u5854\u7684\u4fe1\u53f7\u5f3a\u5ea6\u4e4b\u548c\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de \u7f51\u7edc\u4fe1\u53f7\u00a0\u6700\u5927\u7684\u6574\u6570\u5750\u6807\u70b9\u3002\u5982\u679c\u6709\u591a\u4e2a\u5750\u6807\u7f51\u7edc\u4fe1\u53f7\u4e00\u6837\u5927\uff0c\u8bf7\u4f60\u8fd4\u56de\u5b57\u5178\u5e8f\u6700\u5c0f\u7684\u4e00\u4e2a\u5750\u6807\u3002

    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    • \u5750\u6807\u00a0(x1, y1)\u00a0\u5b57\u5178\u5e8f\u6bd4\u53e6\u4e00\u4e2a\u5750\u6807\u00a0(x2, y2)\u00a0\u5c0f\uff1a\u8981\u4e48\u00a0x1 < x2\u00a0\uff0c\u8981\u4e48\u00a0x1 == x2 \u4e14\u00a0y1 < y2\u00a0\u3002
    • \n\t
    • \u230aval\u230b\u00a0\u8868\u793a\u5c0f\u4e8e\u7b49\u4e8e\u00a0val\u00a0\u7684\u6700\u5927\u6574\u6570\uff08\u5411\u4e0b\u53d6\u6574\u51fd\u6570\uff09\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1atowers = [[1,2,5],[2,1,7],[3,1,9]], radius = 2\n\u8f93\u51fa\uff1a[2,1]\n\u89e3\u91ca\uff1a\n\u5750\u6807 (2, 1) \u4fe1\u53f7\u5f3a\u5ea6\u4e4b\u548c\u4e3a 13\n- \u5854 (2, 1) \u5f3a\u5ea6\u53c2\u6570\u4e3a 7 \uff0c\u5728\u8be5\u70b9\u5f3a\u5ea6\u4e3a \u230a7 / (1 + sqrt(0)\u230b = \u230a7\u230b = 7\n- \u5854 (1, 2) \u5f3a\u5ea6\u53c2\u6570\u4e3a 5 \uff0c\u5728\u8be5\u70b9\u5f3a\u5ea6\u4e3a \u230a5 / (1 + sqrt(2)\u230b = \u230a2.07\u230b = 2\n- \u5854 (3, 1) \u5f3a\u5ea6\u53c2\u6570\u4e3a 9 \uff0c\u5728\u8be5\u70b9\u5f3a\u5ea6\u4e3a \u230a9 / (1 + sqrt(1)\u230b = \u230a4.5\u230b = 4\n\u6ca1\u6709\u522b\u7684\u5750\u6807\u6709\u66f4\u5927\u7684\u4fe1\u53f7\u5f3a\u5ea6\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1atowers = [[23,11,21]], radius = 9\n\u8f93\u51fa\uff1a[23,11]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1atowers = [[1,2,13],[2,1,7],[0,1,9]], radius = 2\n\u8f93\u51fa\uff1a[1,2]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1atowers = [[2,1,9],[0,1,9]], radius = 2\n\u8f93\u51fa\uff1a[0,1]\n\u89e3\u91ca\uff1a\u5750\u6807 (0, 1) \u548c\u5750\u6807 (2, 1) \u90fd\u662f\u5f3a\u5ea6\u6700\u5927\u7684\u4f4d\u7f6e\uff0c\u4f46\u662f (0, 1) \u5b57\u5178\u5e8f\u66f4\u5c0f\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= towers.length <= 50
    • \n\t
    • towers[i].length == 3
    • \n\t
    • 0 <= xi, yi, qi <= 50
    • \n\t
    • 1 <= radius <= 50
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector bestCoordinate(vector>& towers, int radius) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] bestCoordinate(int[][] towers, int radius) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def bestCoordinate(self, towers, radius):\n \"\"\"\n :type towers: List[List[int]]\n :type radius: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def bestCoordinate(self, towers: List[List[int]], radius: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* bestCoordinate(int** towers, int towersSize, int* towersColSize, int radius, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] BestCoordinate(int[][] towers, int radius) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} towers\n * @param {number} radius\n * @return {number[]}\n */\nvar bestCoordinate = function(towers, radius) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} towers\n# @param {Integer} radius\n# @return {Integer[]}\ndef best_coordinate(towers, radius)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func bestCoordinate(_ towers: [[Int]], _ radius: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func bestCoordinate(towers [][]int, radius int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def bestCoordinate(towers: Array[Array[Int]], radius: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun bestCoordinate(towers: Array, radius: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn best_coordinate(towers: Vec>, radius: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $towers\n * @param Integer $radius\n * @return Integer[]\n */\n function bestCoordinate($towers, $radius) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function bestCoordinate(towers: number[][], radius: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (best-coordinate towers radius)\n (-> (listof (listof exact-integer?)) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1620](https://leetcode-cn.com/problems/coordinate-with-maximum-network-quality)", "[\u7f51\u7edc\u4fe1\u53f7\u6700\u597d\u7684\u5750\u6807](/solution/1600-1699/1620.Coordinate%20With%20Maximum%20Network%20Quality/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1620](https://leetcode.com/problems/coordinate-with-maximum-network-quality)", "[Coordinate With Maximum Network Quality](/solution/1600-1699/1620.Coordinate%20With%20Maximum%20Network%20Quality/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1725", "frontend_question_id": "1621", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-sets-of-k-non-overlapping-line-segments", "url_en": "https://leetcode.com/problems/number-of-sets-of-k-non-overlapping-line-segments", "relative_path_cn": "/solution/1600-1699/1621.Number%20of%20Sets%20of%20K%20Non-Overlapping%20Line%20Segments/README.md", "relative_path_en": "/solution/1600-1699/1621.Number%20of%20Sets%20of%20K%20Non-Overlapping%20Line%20Segments/README_EN.md", "title_cn": "\u5927\u5c0f\u4e3a K \u7684\u4e0d\u91cd\u53e0\u7ebf\u6bb5\u7684\u6570\u76ee", "title_en": "Number of Sets of K Non-Overlapping Line Segments", "question_title_slug": "number-of-sets-of-k-non-overlapping-line-segments", "content_en": "

    Given n points on a 1-D plane, where the ith point (from 0 to n-1) is at x = i, find the number of ways we can draw exactly k non-overlapping line segments such that each segment covers two or more points. The endpoints of each segment must have integral coordinates. The k line segments do not have to cover all n points, and they are allowed to share endpoints.

    \n\n

    Return the number of ways we can draw k non-overlapping line segments. Since this number can be huge, return it modulo 109 + 7.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: n = 4, k = 2\nOutput: 5\nExplanation: \nThe two line segments are shown in red and blue.\nThe image above shows the 5 different ways {(0,2),(2,3)}, {(0,1),(1,3)}, {(0,1),(2,3)}, {(1,2),(2,3)}, {(0,1),(1,2)}.
    \n\n

    Example 2:

    \n\n
    \nInput: n = 3, k = 1\nOutput: 3\nExplanation: The 3 ways are {(0,1)}, {(0,2)}, {(1,2)}.\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 30, k = 7\nOutput: 796297179\nExplanation: The total number of possible ways to draw 7 line segments is 3796297200. Taking this number modulo 109 + 7 gives us 796297179.\n
    \n\n

    Example 4:

    \n\n
    \nInput: n = 5, k = 3\nOutput: 7\n
    \n\n

    Example 5:

    \n\n
    \nInput: n = 3, k = 2\nOutput: 1
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= n <= 1000
    • \n\t
    • 1 <= k <= n-1
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u7ef4\u7a7a\u95f4\u7684\u00a0n\u00a0\u4e2a\u70b9\uff0c\u5176\u4e2d\u7b2c\u00a0i\u00a0\u4e2a\u70b9\uff08\u7f16\u53f7\u4ece\u00a00 \u5230\u00a0n-1\uff09\u4f4d\u4e8e\u00a0x = i\u00a0\u5904\uff0c\u8bf7\u4f60\u627e\u5230\u00a0\u6070\u597d\u00a0k\u00a0\u4e2a\u4e0d\u91cd\u53e0\u00a0\u7ebf\u6bb5\u4e14\u6bcf\u4e2a\u7ebf\u6bb5\u81f3\u5c11\u8986\u76d6\u4e24\u4e2a\u70b9\u7684\u65b9\u6848\u6570\u3002\u7ebf\u6bb5\u7684\u4e24\u4e2a\u7aef\u70b9\u5fc5\u987b\u90fd\u662f\u00a0\u6574\u6570\u5750\u6807\u00a0\u3002\u8fd9\u00a0k\u00a0\u4e2a\u7ebf\u6bb5\u4e0d\u9700\u8981\u5168\u90e8\u8986\u76d6\u5168\u90e8\u00a0n\u00a0\u4e2a\u70b9\uff0c\u4e14\u5b83\u4eec\u7684\u7aef\u70b9\u00a0\u53ef\u4ee5\u00a0\u91cd\u5408\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de k\u00a0\u4e2a\u4e0d\u91cd\u53e0\u7ebf\u6bb5\u7684\u65b9\u6848\u6570\u3002\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u5f88\u5927\uff0c\u8bf7\u5c06\u7ed3\u679c\u5bf9\u00a0109 + 7\u00a0\u53d6\u4f59 \u540e\u8fd4\u56de\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1an = 4, k = 2\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\n\u5982\u56fe\u6240\u793a\uff0c\u4e24\u4e2a\u7ebf\u6bb5\u5206\u522b\u7528\u7ea2\u8272\u548c\u84dd\u8272\u6807\u51fa\u3002\n\u4e0a\u56fe\u5c55\u793a\u4e86 5 \u79cd\u4e0d\u540c\u7684\u65b9\u6848 {(0,2),(2,3)}\uff0c{(0,1),(1,3)}\uff0c{(0,1),(2,3)}\uff0c{(1,2),(2,3)}\uff0c{(0,1),(1,2)} \u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 3, k = 1\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u603b\u5171\u6709 3 \u79cd\u4e0d\u540c\u7684\u65b9\u6848 {(0,1)}, {(0,2)}, {(1,2)} \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 30, k = 7\n\u8f93\u51fa\uff1a796297179\n\u89e3\u91ca\uff1a\u753b 7 \u6761\u7ebf\u6bb5\u7684\u603b\u65b9\u6848\u6570\u4e3a 3796297200 \u79cd\u3002\u5c06\u8fd9\u4e2a\u6570\u5bf9 109 + 7 \u53d6\u4f59\u5f97\u5230 796297179 \u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 5, k = 3\n\u8f93\u51fa\uff1a7\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 3, k = 2\n\u8f93\u51fa\uff1a1
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= n <= 1000
    • \n\t
    • 1 <= k <= n-1
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numberOfSets(int n, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numberOfSets(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numberOfSets(self, n, k):\n \"\"\"\n :type n: int\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numberOfSets(self, n: int, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numberOfSets(int n, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumberOfSets(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} k\n * @return {number}\n */\nvar numberOfSets = function(n, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} k\n# @return {Integer}\ndef number_of_sets(n, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numberOfSets(_ n: Int, _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numberOfSets(n int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numberOfSets(n: Int, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numberOfSets(n: Int, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn number_of_sets(n: i32, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $k\n * @return Integer\n */\n function numberOfSets($n, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numberOfSets(n: number, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (number-of-sets n k)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1621](https://leetcode-cn.com/problems/number-of-sets-of-k-non-overlapping-line-segments)", "[\u5927\u5c0f\u4e3a K \u7684\u4e0d\u91cd\u53e0\u7ebf\u6bb5\u7684\u6570\u76ee](/solution/1600-1699/1621.Number%20of%20Sets%20of%20K%20Non-Overlapping%20Line%20Segments/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1621](https://leetcode.com/problems/number-of-sets-of-k-non-overlapping-line-segments)", "[Number of Sets of K Non-Overlapping Line Segments](/solution/1600-1699/1621.Number%20of%20Sets%20of%20K%20Non-Overlapping%20Line%20Segments/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "1724", "frontend_question_id": "1581", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/customer-who-visited-but-did-not-make-any-transactions", "url_en": "https://leetcode.com/problems/customer-who-visited-but-did-not-make-any-transactions", "relative_path_cn": "/solution/1500-1599/1581.Customer%20Who%20Visited%20but%20Did%20Not%20Make%20Any%20Transactions/README.md", "relative_path_en": "/solution/1500-1599/1581.Customer%20Who%20Visited%20but%20Did%20Not%20Make%20Any%20Transactions/README_EN.md", "title_cn": "\u8fdb\u5e97\u5374\u672a\u8fdb\u884c\u8fc7\u4ea4\u6613\u7684\u987e\u5ba2", "title_en": "Customer Who Visited but Did Not Make Any Transactions", "question_title_slug": "customer-who-visited-but-did-not-make-any-transactions", "content_en": "

    Table: Visits

    \n\n
    \n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| visit_id    | int     |\n| customer_id | int     |\n+-------------+---------+\nvisit_id is the primary key for this table.\nThis table contains information about the customers who visited the mall.\n
    \n\n

     

    \n\n

    Table: Transactions

    \n\n
    \n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| transaction_id | int     |\n| visit_id       | int     |\n| amount         | int     |\n+----------------+---------+\ntransaction_id is the primary key for this table.\nThis table contains information about the transactions made during the visit_id.\n
    \n\n

     

    \n\n

    Write an SQL query to find the IDs of the users who visited without making any transactions and the number of times they made these types of visits.

    \n\n

    Return the result table sorted in any order.

    \n\n

    The query result format is in the following example:

    \n\n
    \nVisits\n+----------+-------------+\n| visit_id | customer_id |\n+----------+-------------+\n| 1        | 23          |\n| 2        | 9           |\n| 4        | 30          |\n| 5        | 54          |\n| 6        | 96          |\n| 7        | 54          |\n| 8        | 54          |\n+----------+-------------+\n\nTransactions\n+----------------+----------+--------+\n| transaction_id | visit_id | amount |\n+----------------+----------+--------+\n| 2              | 5        | 310    |\n| 3              | 5        | 300    |\n| 9              | 5        | 200    |\n| 12             | 1        | 910    |\n| 13             | 2        | 970    |\n+----------------+----------+--------+\n\nResult table:\n+-------------+----------------+\n| customer_id | count_no_trans |\n+-------------+----------------+\n| 54          | 2              |\n| 30          | 1              |\n| 96          | 1              |\n+-------------+----------------+\nCustomer with id = 23 visited the mall once and made one transaction during the visit with id = 12.\nCustomer with id = 9 visited the mall once and made one transaction during the visit with id = 13.\nCustomer with id = 30 visited the mall once and did not make any transactions.\nCustomer with id = 54 visited the mall three times. During 2 visits they did not make any transactions, and during one visit they made 3 transactions.\nCustomer with id = 96 visited the mall once and did not make any transactions.\nAs we can see, users with IDs 30 and 96 visited the mall one time without making any transactions. Also user 54 visited the mall twice and did not make any transactions.\n
    \n", "content_cn": "

    \u8868\uff1aVisits

    \n\n
    \n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| visit_id    | int     |\n| customer_id | int     |\n+-------------+---------+\nvisit_id \u662f\u8be5\u8868\u7684\u4e3b\u952e\u3002\n\u8be5\u8868\u5305\u542b\u6709\u5173\u5149\u4e34\u8fc7\u8d2d\u7269\u4e2d\u5fc3\u7684\u987e\u5ba2\u7684\u4fe1\u606f\u3002\n
    \n\n

    \u00a0

    \n\n

    \u8868\uff1aTransactions

    \n\n
    \n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| transaction_id | int     |\n| visit_id       | int     |\n| amount         | int     |\n+----------------+---------+\ntransaction_id \u662f\u6b64\u8868\u7684\u4e3b\u952e\u3002\n\u6b64\u8868\u5305\u542b visit_id \u671f\u95f4\u8fdb\u884c\u7684\u4ea4\u6613\u7684\u4fe1\u606f\u3002\n
    \n\n

    \u6709\u4e00\u4e9b\u987e\u5ba2\u53ef\u80fd\u5149\u987e\u4e86\u8d2d\u7269\u4e2d\u5fc3\u4f46\u6ca1\u6709\u8fdb\u884c\u4ea4\u6613\u3002\u8bf7\u4f60\u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\uff0c\u6765\u67e5\u627e\u8fd9\u4e9b\u987e\u5ba2\u7684 ID \uff0c\u4ee5\u53ca\u4ed6\u4eec\u53ea\u5149\u987e\u4e0d\u4ea4\u6613\u7684\u6b21\u6570\u3002

    \n\n

    \u8fd4\u56de\u4ee5\u4efb\u4f55\u987a\u5e8f\u6392\u5e8f\u7684\u7ed3\u679c\u8868\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a\uff1a

    \n\n
    \nVisits\n+----------+-------------+\n| visit_id | customer_id |\n+----------+-------------+\n| 1        | 23          |\n| 2        | 9           |\n| 4        | 30          |\n| 5        | 54          |\n| 6        | 96          |\n| 7        | 54          |\n| 8        | 54          |\n+----------+-------------+\n\nTransactions\n+----------------+----------+--------+\n| transaction_id | visit_id | amount |\n+----------------+----------+--------+\n| 2              | 5        | 310    |\n| 3              | 5        | 300    |\n| 9              | 5        | 200    |\n| 12             | 1        | 910    |\n| 13             | 2        | 970    |\n+----------------+----------+--------+\n\nResult \u8868\uff1a\n+-------------+----------------+\n| customer_id | count_no_trans |\n+-------------+----------------+\n| 54          | 2              |\n| 30          | 1              |\n| 96          | 1              |\n+-------------+----------------+\nID = 23 \u7684\u987e\u5ba2\u66fe\u7ecf\u901b\u8fc7\u4e00\u6b21\u8d2d\u7269\u4e2d\u5fc3\uff0c\u5e76\u5728 ID = 12 \u7684\u8bbf\u95ee\u671f\u95f4\u8fdb\u884c\u4e86\u4e00\u7b14\u4ea4\u6613\u3002\nID = 9 \u7684\u987e\u5ba2\u66fe\u7ecf\u901b\u8fc7\u4e00\u6b21\u8d2d\u7269\u4e2d\u5fc3\uff0c\u5e76\u5728 ID = 13 \u7684\u8bbf\u95ee\u671f\u95f4\u8fdb\u884c\u4e86\u4e00\u7b14\u4ea4\u6613\u3002\nID = 30 \u7684\u987e\u5ba2\u66fe\u7ecf\u53bb\u8fc7\u8d2d\u7269\u4e2d\u5fc3\uff0c\u5e76\u4e14\u6ca1\u6709\u8fdb\u884c\u4efb\u4f55\u4ea4\u6613\u3002\nID = 54 \u7684\u987e\u5ba2\u4e09\u5ea6\u9020\u8bbf\u4e86\u8d2d\u7269\u4e2d\u5fc3\u3002\u5728 2 \u6b21\u8bbf\u95ee\u4e2d\uff0c\u4ed6\u4eec\u6ca1\u6709\u8fdb\u884c\u4efb\u4f55\u4ea4\u6613\uff0c\u5728 1 \u6b21\u8bbf\u95ee\u4e2d\uff0c\u4ed6\u4eec\u8fdb\u884c\u4e86 3 \u6b21\u4ea4\u6613\u3002\nID = 96 \u7684\u987e\u5ba2\u66fe\u7ecf\u53bb\u8fc7\u8d2d\u7269\u4e2d\u5fc3\uff0c\u5e76\u4e14\u6ca1\u6709\u8fdb\u884c\u4efb\u4f55\u4ea4\u6613\u3002\n\u5982\u6211\u4eec\u6240\u89c1\uff0cID \u4e3a 30 \u548c 96 \u7684\u987e\u5ba2\u4e00\u6b21\u6ca1\u6709\u8fdb\u884c\u4efb\u4f55\u4ea4\u6613\u5c31\u53bb\u4e86\u8d2d\u7269\u4e2d\u5fc3\u3002\u987e\u5ba2 54 \u4e5f\u4e24\u6b21\u8bbf\u95ee\u4e86\u8d2d\u7269\u4e2d\u5fc3\u5e76\u4e14\u6ca1\u6709\u8fdb\u884c\u4efb\u4f55\u4ea4\u6613\u3002\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1581](https://leetcode-cn.com/problems/customer-who-visited-but-did-not-make-any-transactions)", "[\u8fdb\u5e97\u5374\u672a\u8fdb\u884c\u8fc7\u4ea4\u6613\u7684\u987e\u5ba2](/solution/1500-1599/1581.Customer%20Who%20Visited%20but%20Did%20Not%20Make%20Any%20Transactions/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1581](https://leetcode.com/problems/customer-who-visited-but-did-not-make-any-transactions)", "[Customer Who Visited but Did Not Make Any Transactions](/solution/1500-1599/1581.Customer%20Who%20Visited%20but%20Did%20Not%20Make%20Any%20Transactions/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1723", "frontend_question_id": "1601", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-number-of-achievable-transfer-requests", "url_en": "https://leetcode.com/problems/maximum-number-of-achievable-transfer-requests", "relative_path_cn": "/solution/1600-1699/1601.Maximum%20Number%20of%20Achievable%20Transfer%20Requests/README.md", "relative_path_en": "/solution/1600-1699/1601.Maximum%20Number%20of%20Achievable%20Transfer%20Requests/README_EN.md", "title_cn": "\u6700\u591a\u53ef\u8fbe\u6210\u7684\u6362\u697c\u8bf7\u6c42\u6570\u76ee", "title_en": "Maximum Number of Achievable Transfer Requests", "question_title_slug": "maximum-number-of-achievable-transfer-requests", "content_en": "

    We have n buildings numbered from 0 to n - 1. Each building has a number of employees. It's transfer season, and some employees want to change the building they reside in.

    \n\n

    You are given an array requests where requests[i] = [fromi, toi] represents an employee's request to transfer from building fromi to building toi.

    \n\n

    All buildings are full, so a list of requests is achievable only if for each building, the net change in employee transfers is zero. This means the number of employees leaving is equal to the number of employees moving in. For example if n = 3 and two employees are leaving building 0, one is leaving building 1, and one is leaving building 2, there should be two employees moving to building 0, one employee moving to building 1, and one employee moving to building 2.

    \n\n

    Return the maximum number of achievable requests.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: n = 5, requests = [[0,1],[1,0],[0,1],[1,2],[2,0],[3,4]]\nOutput: 5\nExplantion: Let's see the requests:\nFrom building 0 we have employees x and y and both want to move to building 1.\nFrom building 1 we have employees a and b and they want to move to buildings 2 and 0 respectively.\nFrom building 2 we have employee z and they want to move to building 0.\nFrom building 3 we have employee c and they want to move to building 4.\nFrom building 4 we don't have any requests.\nWe can achieve the requests of users x and b by swapping their places.\nWe can achieve the requests of users y, a and z by swapping the places in the 3 buildings.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: n = 3, requests = [[0,0],[1,2],[2,1]]\nOutput: 3\nExplantion: Let's see the requests:\nFrom building 0 we have employee x and they want to stay in the same building 0.\nFrom building 1 we have employee y and they want to move to building 2.\nFrom building 2 we have employee z and they want to move to building 1.\nWe can achieve all the requests. 
    \n\n

    Example 3:

    \n\n
    \nInput: n = 4, requests = [[0,3],[3,1],[1,2],[2,0]]\nOutput: 4\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 20
    • \n\t
    • 1 <= requests.length <= 16
    • \n\t
    • requests[i].length == 2
    • \n\t
    • 0 <= fromi, toi < n
    • \n
    \n", "content_cn": "

    \u6211\u4eec\u6709 n \u680b\u697c\uff0c\u7f16\u53f7\u4ece 0 \u5230 n - 1 \u3002\u6bcf\u680b\u697c\u6709\u82e5\u5e72\u5458\u5de5\u3002\u7531\u4e8e\u73b0\u5728\u662f\u6362\u697c\u7684\u5b63\u8282\uff0c\u90e8\u5206\u5458\u5de5\u60f3\u8981\u6362\u4e00\u680b\u697c\u5c45\u4f4f\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 requests \uff0c\u5176\u4e2d requests[i] = [fromi, toi] \uff0c\u8868\u793a\u4e00\u4e2a\u5458\u5de5\u8bf7\u6c42\u4ece\u7f16\u53f7\u4e3a fromi \u7684\u697c\u642c\u5230\u7f16\u53f7\u4e3a toi \u7684\u697c\u3002

    \n\n

    \u4e00\u5f00\u59cb \u6240\u6709\u697c\u90fd\u662f\u6ee1\u7684\uff0c\u6240\u4ee5\u4ece\u8bf7\u6c42\u5217\u8868\u4e2d\u9009\u51fa\u7684\u82e5\u5e72\u4e2a\u8bf7\u6c42\u662f\u53ef\u884c\u7684\u9700\u8981\u6ee1\u8db3 \u6bcf\u680b\u697c\u5458\u5de5\u51c0\u53d8\u5316\u4e3a 0 \u3002\u610f\u601d\u662f\u6bcf\u680b\u697c \u79bb\u5f00 \u7684\u5458\u5de5\u6570\u76ee \u7b49\u4e8e \u8be5\u697c \u642c\u5165 \u7684\u5458\u5de5\u6570\u6570\u76ee\u3002\u6bd4\u65b9\u8bf4 n = 3 \u4e14\u4e24\u4e2a\u5458\u5de5\u8981\u79bb\u5f00\u697c 0 \uff0c\u4e00\u4e2a\u5458\u5de5\u8981\u79bb\u5f00\u697c 1 \uff0c\u4e00\u4e2a\u5458\u5de5\u8981\u79bb\u5f00\u697c 2 \uff0c\u5982\u679c\u8be5\u8bf7\u6c42\u5217\u8868\u53ef\u884c\uff0c\u5e94\u8be5\u8981\u6709\u4e24\u4e2a\u5458\u5de5\u642c\u5165\u697c 0 \uff0c\u4e00\u4e2a\u5458\u5de5\u642c\u5165\u697c 1 \uff0c\u4e00\u4e2a\u5458\u5de5\u642c\u5165\u697c 2 \u3002

    \n\n

    \u8bf7\u4f60\u4ece\u539f\u8bf7\u6c42\u5217\u8868\u4e2d\u9009\u51fa\u82e5\u5e72\u4e2a\u8bf7\u6c42\uff0c\u4f7f\u5f97\u5b83\u4eec\u662f\u4e00\u4e2a\u53ef\u884c\u7684\u8bf7\u6c42\u5217\u8868\uff0c\u5e76\u8fd4\u56de\u6240\u6709\u53ef\u884c\u5217\u8868\u4e2d\u6700\u5927\u8bf7\u6c42\u6570\u76ee\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 5, requests = [[0,1],[1,0],[0,1],[1,2],[2,0],[3,4]]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u8bf7\u6c42\u5217\u8868\u5982\u4e0b\uff1a\n\u4ece\u697c 0 \u79bb\u5f00\u7684\u5458\u5de5\u4e3a x \u548c y \uff0c\u4e14\u4ed6\u4eec\u90fd\u60f3\u8981\u642c\u5230\u697c 1 \u3002\n\u4ece\u697c 1 \u79bb\u5f00\u7684\u5458\u5de5\u4e3a a \u548c b \uff0c\u4e14\u4ed6\u4eec\u5206\u522b\u60f3\u8981\u642c\u5230\u697c 2 \u548c 0 \u3002\n\u4ece\u697c 2 \u79bb\u5f00\u7684\u5458\u5de5\u4e3a z \uff0c\u4e14\u4ed6\u60f3\u8981\u642c\u5230\u697c 0 \u3002\n\u4ece\u697c 3 \u79bb\u5f00\u7684\u5458\u5de5\u4e3a c \uff0c\u4e14\u4ed6\u60f3\u8981\u642c\u5230\u697c 4 \u3002\n\u6ca1\u6709\u5458\u5de5\u4ece\u697c 4 \u79bb\u5f00\u3002\n\u6211\u4eec\u53ef\u4ee5\u8ba9 x \u548c b \u4ea4\u6362\u4ed6\u4eec\u7684\u697c\uff0c\u4ee5\u6ee1\u8db3\u4ed6\u4eec\u7684\u8bf7\u6c42\u3002\n\u6211\u4eec\u53ef\u4ee5\u8ba9 y\uff0ca \u548c z \u4e09\u4eba\u5728\u4e09\u680b\u697c\u95f4\u4ea4\u6362\u4f4d\u7f6e\uff0c\u6ee1\u8db3\u4ed6\u4eec\u7684\u8981\u6c42\u3002\n\u6240\u4ee5\u6700\u591a\u53ef\u4ee5\u6ee1\u8db3 5 \u4e2a\u8bf7\u6c42\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 3, requests = [[0,0],[1,2],[2,1]]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u8bf7\u6c42\u5217\u8868\u5982\u4e0b\uff1a\n\u4ece\u697c 0 \u79bb\u5f00\u7684\u5458\u5de5\u4e3a x \uff0c\u4e14\u4ed6\u60f3\u8981\u56de\u5230\u539f\u6765\u7684\u697c 0 \u3002\n\u4ece\u697c 1 \u79bb\u5f00\u7684\u5458\u5de5\u4e3a y \uff0c\u4e14\u4ed6\u60f3\u8981\u642c\u5230\u697c 2 \u3002\n\u4ece\u697c 2 \u79bb\u5f00\u7684\u5458\u5de5\u4e3a z \uff0c\u4e14\u4ed6\u60f3\u8981\u642c\u5230\u697c 1 \u3002\n\u6211\u4eec\u53ef\u4ee5\u6ee1\u8db3\u6240\u6709\u7684\u8bf7\u6c42\u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1an = 4, requests = [[0,3],[3,1],[1,2],[2,0]]\n\u8f93\u51fa\uff1a4\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 20
    • \n\t
    • 1 <= requests.length <= 16
    • \n\t
    • requests[i].length == 2
    • \n\t
    • 0 <= fromi, toi < n
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maximumRequests(int n, vector>& requests) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maximumRequests(int n, int[][] requests) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximumRequests(self, n, requests):\n \"\"\"\n :type n: int\n :type requests: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximumRequests(self, n: int, requests: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maximumRequests(int n, int** requests, int requestsSize, int* requestsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaximumRequests(int n, int[][] requests) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} requests\n * @return {number}\n */\nvar maximumRequests = function(n, requests) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} requests\n# @return {Integer}\ndef maximum_requests(n, requests)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximumRequests(_ n: Int, _ requests: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximumRequests(n int, requests [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximumRequests(n: Int, requests: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximumRequests(n: Int, requests: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximum_requests(n: i32, requests: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $requests\n * @return Integer\n */\n function maximumRequests($n, $requests) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximumRequests(n: number, requests: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximum-requests n requests)\n (-> exact-integer? (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1601](https://leetcode-cn.com/problems/maximum-number-of-achievable-transfer-requests)", "[\u6700\u591a\u53ef\u8fbe\u6210\u7684\u6362\u697c\u8bf7\u6c42\u6570\u76ee](/solution/1600-1699/1601.Maximum%20Number%20of%20Achievable%20Transfer%20Requests/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1601](https://leetcode.com/problems/maximum-number-of-achievable-transfer-requests)", "[Maximum Number of Achievable Transfer Requests](/solution/1600-1699/1601.Maximum%20Number%20of%20Achievable%20Transfer%20Requests/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1722", "frontend_question_id": "1600", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/throne-inheritance", "url_en": "https://leetcode.com/problems/throne-inheritance", "relative_path_cn": "/solution/1600-1699/1600.Throne%20Inheritance/README.md", "relative_path_en": "/solution/1600-1699/1600.Throne%20Inheritance/README_EN.md", "title_cn": "\u7687\u4f4d\u7ee7\u627f\u987a\u5e8f", "title_en": "Throne Inheritance", "question_title_slug": "throne-inheritance", "content_en": "

    A kingdom consists of a king, his children, his grandchildren, and so on. Every once in a while, someone in the family dies or a child is born.

    \n\n

    The kingdom has a well-defined order of inheritance that consists of the king as the first member. Let's define the recursive function Successor(x, curOrder), which given a person x and the inheritance order so far, returns who should be the next person after x in the order of inheritance.

    \n\n
    \nSuccessor(x, curOrder):\n    if x has no children or all of x's children are in curOrder:\n        if x is the king return null\n        else return Successor(x's parent, curOrder)\n    else return x's oldest child who's not in curOrder\n
    \n\n

    For example, assume we have a kingdom that consists of the king, his children Alice and Bob (Alice is older than Bob), and finally Alice's son Jack.

    \n\n
      \n\t
    1. In the beginning, curOrder will be ["king"].
    2. \n\t
    3. Calling Successor(king, curOrder) will return Alice, so we append to curOrder to get ["king", "Alice"].
    4. \n\t
    5. Calling Successor(Alice, curOrder) will return Jack, so we append to curOrder to get ["king", "Alice", "Jack"].
    6. \n\t
    7. Calling Successor(Jack, curOrder) will return Bob, so we append to curOrder to get ["king", "Alice", "Jack", "Bob"].
    8. \n\t
    9. Calling Successor(Bob, curOrder) will return null. Thus the order of inheritance will be ["king", "Alice", "Jack", "Bob"].
    10. \n
    \n\n

    Using the above function, we can always obtain a unique order of inheritance.

    \n\n

    Implement the ThroneInheritance class:

    \n\n
      \n\t
    • ThroneInheritance(string kingName) Initializes an object of the ThroneInheritance class. The name of the king is given as part of the constructor.
    • \n\t
    • void birth(string parentName, string childName) Indicates that parentName gave birth to childName.
    • \n\t
    • void death(string name) Indicates the death of name. The death of the person doesn't affect the Successor function nor the current inheritance order. You can treat it as just marking the person as dead.
    • \n\t
    • string[] getInheritanceOrder() Returns a list representing the current order of inheritance excluding dead people.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["ThroneInheritance", "birth", "birth", "birth", "birth", "birth", "birth", "getInheritanceOrder", "death", "getInheritanceOrder"]\n[["king"], ["king", "andy"], ["king", "bob"], ["king", "catherine"], ["andy", "matthew"], ["bob", "alex"], ["bob", "asha"], [null], ["bob"], [null]]\nOutput\n[null, null, null, null, null, null, null, ["king", "andy", "matthew", "bob", "alex", "asha", "catherine"], null, ["king", "andy", "matthew", "alex", "asha", "catherine"]]\n\nExplanation\nThroneInheritance t= new ThroneInheritance("king"); // order: king\nt.birth("king", "andy"); // order: king > andy\nt.birth("king", "bob"); // order: king > andy > bob\nt.birth("king", "catherine"); // order: king > andy > bob > catherine\nt.birth("andy", "matthew"); // order: king > andy > matthew > bob > catherine\nt.birth("bob", "alex"); // order: king > andy > matthew > bob > alex > catherine\nt.birth("bob", "asha"); // order: king > andy > matthew > bob > alex > asha > catherine\nt.getInheritanceOrder(); // return ["king", "andy", "matthew", "bob", "alex", "asha", "catherine"]\nt.death("bob"); // order: king > andy > matthew > bob > alex > asha > catherine\nt.getInheritanceOrder(); // return ["king", "andy", "matthew", "alex", "asha", "catherine"]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= kingName.length, parentName.length, childName.length, name.length <= 15
    • \n\t
    • kingName, parentName, childName, and name consist of lowercase English letters only.
    • \n\t
    • All arguments childName and kingName are distinct.
    • \n\t
    • All name arguments of death will be passed to either the constructor or as childName to birth first.
    • \n\t
    • For each call to birth(parentName, childName), it is guaranteed that parentName is alive.
    • \n\t
    • At most 105 calls will be made to birth and death.
    • \n\t
    • At most 10 calls will be made to getInheritanceOrder.
    • \n
    \n", "content_cn": "

    \u4e00\u4e2a\u738b\u56fd\u91cc\u4f4f\u7740\u56fd\u738b\u3001\u4ed6\u7684\u5b69\u5b50\u4eec\u3001\u4ed6\u7684\u5b59\u5b50\u4eec\u7b49\u7b49\u3002\u6bcf\u4e00\u4e2a\u65f6\u95f4\u70b9\uff0c\u8fd9\u4e2a\u5bb6\u5ead\u91cc\u6709\u4eba\u51fa\u751f\u4e5f\u6709\u4eba\u6b7b\u4ea1\u3002

    \n\n

    \u8fd9\u4e2a\u738b\u56fd\u6709\u4e00\u4e2a\u660e\u786e\u89c4\u5b9a\u7684\u7687\u4f4d\u7ee7\u627f\u987a\u5e8f\uff0c\u7b2c\u4e00\u7ee7\u627f\u4eba\u603b\u662f\u56fd\u738b\u81ea\u5df1\u3002\u6211\u4eec\u5b9a\u4e49\u9012\u5f52\u51fd\u6570 Successor(x, curOrder) \uff0c\u7ed9\u5b9a\u4e00\u4e2a\u4eba x \u548c\u5f53\u524d\u7684\u7ee7\u627f\u987a\u5e8f\uff0c\u8be5\u51fd\u6570\u8fd4\u56de x \u7684\u4e0b\u4e00\u7ee7\u627f\u4eba\u3002

    \n\n
    Successor(x, curOrder):\n    \u5982\u679c x \u6ca1\u6709\u5b69\u5b50\u6216\u8005\u6240\u6709 x \u7684\u5b69\u5b50\u90fd\u5728 curOrder \u4e2d\uff1a\n        \u5982\u679c x \u662f\u56fd\u738b\uff0c\u90a3\u4e48\u8fd4\u56de null\n        \u5426\u5219\uff0c\u8fd4\u56de Successor(x \u7684\u7236\u4eb2, curOrder)\n    \u5426\u5219\uff0c\u8fd4\u56de x \u4e0d\u5728 curOrder \u4e2d\u6700\u5e74\u957f\u7684\u5b69\u5b50\n
    \n\n

    \u6bd4\u65b9\u8bf4\uff0c\u5047\u8bbe\u738b\u56fd\u7531\u56fd\u738b\uff0c\u4ed6\u7684\u5b69\u5b50 Alice \u548c Bob \uff08Alice \u6bd4 Bob \u5e74\u957f\uff09\u548c Alice \u7684\u5b69\u5b50 Jack \u7ec4\u6210\u3002

    \n\n
      \n\t
    1. \u4e00\u5f00\u59cb\uff0c curOrder \u4e3a ["king"].
    2. \n\t
    3. \u8c03\u7528 Successor(king, curOrder) \uff0c\u8fd4\u56de Alice \uff0c\u6240\u4ee5\u6211\u4eec\u5c06 Alice \u653e\u5165 curOrder \u4e2d\uff0c\u5f97\u5230 ["king", "Alice"] \u3002
    4. \n\t
    5. \u8c03\u7528 Successor(Alice, curOrder) \uff0c\u8fd4\u56de Jack \uff0c\u6240\u4ee5\u6211\u4eec\u5c06 Jack \u653e\u5165 curOrder \u4e2d\uff0c\u5f97\u5230 ["king", "Alice", "Jack"] \u3002
    6. \n\t
    7. \u8c03\u7528 Successor(Jack, curOrder) \uff0c\u8fd4\u56de Bob \uff0c\u6240\u4ee5\u6211\u4eec\u5c06 Bob \u653e\u5165 curOrder \u4e2d\uff0c\u5f97\u5230 ["king", "Alice", "Jack", "Bob"] \u3002
    8. \n\t
    9. \u8c03\u7528 Successor(Bob, curOrder) \uff0c\u8fd4\u56de null \u3002\u6700\u7ec8\u5f97\u5230\u7ee7\u627f\u987a\u5e8f\u4e3a ["king", "Alice", "Jack", "Bob"] \u3002
    10. \n
    \n\n

    \u901a\u8fc7\u4ee5\u4e0a\u7684\u51fd\u6570\uff0c\u6211\u4eec\u603b\u662f\u80fd\u5f97\u5230\u4e00\u4e2a\u552f\u4e00\u7684\u7ee7\u627f\u987a\u5e8f\u3002

    \n\n

    \u8bf7\u4f60\u5b9e\u73b0 ThroneInheritance \u7c7b\uff1a

    \n\n
      \n\t
    • ThroneInheritance(string kingName) \u521d\u59cb\u5316\u4e00\u4e2a ThroneInheritance \u7c7b\u7684\u5bf9\u8c61\u3002\u56fd\u738b\u7684\u540d\u5b57\u4f5c\u4e3a\u6784\u9020\u51fd\u6570\u7684\u53c2\u6570\u4f20\u5165\u3002
    • \n\t
    • void birth(string parentName, string childName) \u8868\u793a parentName \u65b0\u62e5\u6709\u4e86\u4e00\u4e2a\u540d\u4e3a childName \u7684\u5b69\u5b50\u3002
    • \n\t
    • void death(string name) \u8868\u793a\u540d\u4e3a name \u7684\u4eba\u6b7b\u4ea1\u3002\u4e00\u4e2a\u4eba\u7684\u6b7b\u4ea1\u4e0d\u4f1a\u5f71\u54cd Successor \u51fd\u6570\uff0c\u4e5f\u4e0d\u4f1a\u5f71\u54cd\u5f53\u524d\u7684\u7ee7\u627f\u987a\u5e8f\u3002\u4f60\u53ef\u4ee5\u53ea\u5c06\u8fd9\u4e2a\u4eba\u6807\u8bb0\u4e3a\u6b7b\u4ea1\u72b6\u6001\u3002
    • \n\t
    • string[] getInheritanceOrder() \u8fd4\u56de \u9664\u53bb \u6b7b\u4ea1\u4eba\u5458\u7684\u5f53\u524d\u7ee7\u627f\u987a\u5e8f\u5217\u8868\u3002
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1a\n["ThroneInheritance", "birth", "birth", "birth", "birth", "birth", "birth", "getInheritanceOrder", "death", "getInheritanceOrder"]\n[["king"], ["king", "andy"], ["king", "bob"], ["king", "catherine"], ["andy", "matthew"], ["bob", "alex"], ["bob", "asha"], [null], ["bob"], [null]]\n\u8f93\u51fa\uff1a\n[null, null, null, null, null, null, null, ["king", "andy", "matthew", "bob", "alex", "asha", "catherine"], null, ["king", "andy", "matthew", "alex", "asha", "catherine"]]\n\n\u89e3\u91ca\uff1a\nThroneInheritance t= new ThroneInheritance("king"); // \u7ee7\u627f\u987a\u5e8f\uff1aking\nt.birth("king", "andy"); // \u7ee7\u627f\u987a\u5e8f\uff1aking > andy\nt.birth("king", "bob"); // \u7ee7\u627f\u987a\u5e8f\uff1aking > andy > bob\nt.birth("king", "catherine"); // \u7ee7\u627f\u987a\u5e8f\uff1aking > andy > bob > catherine\nt.birth("andy", "matthew"); // \u7ee7\u627f\u987a\u5e8f\uff1aking > andy > matthew > bob > catherine\nt.birth("bob", "alex"); // \u7ee7\u627f\u987a\u5e8f\uff1aking > andy > matthew > bob > alex > catherine\nt.birth("bob", "asha"); // \u7ee7\u627f\u987a\u5e8f\uff1aking > andy > matthew > bob > alex > asha > catherine\nt.getInheritanceOrder(); // \u8fd4\u56de ["king", "andy", "matthew", "bob", "alex", "asha", "catherine"]\nt.death("bob"); // \u7ee7\u627f\u987a\u5e8f\uff1aking > andy > matthew > bob\uff08\u5df2\u7ecf\u53bb\u4e16\uff09> alex > asha > catherine\nt.getInheritanceOrder(); // \u8fd4\u56de ["king", "andy", "matthew", "alex", "asha", "catherine"]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= kingName.length, parentName.length, childName.length, name.length <= 15
    • \n\t
    • kingName\uff0cparentName\uff0c childName \u548c name \u4ec5\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    • \n\t
    • \u6240\u6709\u7684\u53c2\u6570 childName \u548c kingName \u4e92\u4e0d\u76f8\u540c\u3002
    • \n\t
    • \u6240\u6709 death \u51fd\u6570\u4e2d\u7684\u6b7b\u4ea1\u540d\u5b57 name \u8981\u4e48\u662f\u56fd\u738b\uff0c\u8981\u4e48\u662f\u5df2\u7ecf\u51fa\u751f\u4e86\u7684\u4eba\u5458\u540d\u5b57\u3002
    • \n\t
    • \u6bcf\u6b21\u8c03\u7528 birth(parentName, childName) \u65f6\uff0c\u6d4b\u8bd5\u7528\u4f8b\u90fd\u4fdd\u8bc1 parentName \u5bf9\u5e94\u7684\u4eba\u5458\u662f\u6d3b\u7740\u7684\u3002
    • \n\t
    • \u6700\u591a\u8c03\u7528 105 \u6b21birth \u548c death \u3002
    • \n\t
    • \u6700\u591a\u8c03\u7528 10 \u6b21 getInheritanceOrder \u3002
    • \n
    \n", "tags_en": ["Tree", "Design"], "tags_cn": ["\u6811", "\u8bbe\u8ba1"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class ThroneInheritance {\npublic:\n ThroneInheritance(string kingName) {\n\n }\n \n void birth(string parentName, string childName) {\n\n }\n \n void death(string name) {\n\n }\n \n vector getInheritanceOrder() {\n\n }\n};\n\n/**\n * Your ThroneInheritance object will be instantiated and called as such:\n * ThroneInheritance* obj = new ThroneInheritance(kingName);\n * obj->birth(parentName,childName);\n * obj->death(name);\n * vector param_3 = obj->getInheritanceOrder();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class ThroneInheritance {\n\n public ThroneInheritance(String kingName) {\n\n }\n \n public void birth(String parentName, String childName) {\n\n }\n \n public void death(String name) {\n\n }\n \n public List getInheritanceOrder() {\n\n }\n}\n\n/**\n * Your ThroneInheritance object will be instantiated and called as such:\n * ThroneInheritance obj = new ThroneInheritance(kingName);\n * obj.birth(parentName,childName);\n * obj.death(name);\n * List param_3 = obj.getInheritanceOrder();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class ThroneInheritance(object):\n\n def __init__(self, kingName):\n \"\"\"\n :type kingName: str\n \"\"\"\n\n\n def birth(self, parentName, childName):\n \"\"\"\n :type parentName: str\n :type childName: str\n :rtype: None\n \"\"\"\n\n\n def death(self, name):\n \"\"\"\n :type name: str\n :rtype: None\n \"\"\"\n\n\n def getInheritanceOrder(self):\n \"\"\"\n :rtype: List[str]\n \"\"\"\n\n\n\n# Your ThroneInheritance object will be instantiated and called as such:\n# obj = ThroneInheritance(kingName)\n# obj.birth(parentName,childName)\n# obj.death(name)\n# param_3 = obj.getInheritanceOrder()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class ThroneInheritance:\n\n def __init__(self, kingName: str):\n\n\n def birth(self, parentName: str, childName: str) -> None:\n\n\n def death(self, name: str) -> None:\n\n\n def getInheritanceOrder(self) -> List[str]:\n\n\n\n# Your ThroneInheritance object will be instantiated and called as such:\n# obj = ThroneInheritance(kingName)\n# obj.birth(parentName,childName)\n# obj.death(name)\n# param_3 = obj.getInheritanceOrder()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} ThroneInheritance;\n\n\nThroneInheritance* throneInheritanceCreate(char * kingName) {\n \n}\n\nvoid throneInheritanceBirth(ThroneInheritance* obj, char * parentName, char * childName) {\n \n}\n\nvoid throneInheritanceDeath(ThroneInheritance* obj, char * name) {\n \n}\n\nchar ** throneInheritanceGetInheritanceOrder(ThroneInheritance* obj, int* retSize) {\n \n}\n\nvoid throneInheritanceFree(ThroneInheritance* obj) {\n \n}\n\n/**\n * Your ThroneInheritance struct will be instantiated and called as such:\n * ThroneInheritance* obj = throneInheritanceCreate(kingName);\n * throneInheritanceBirth(obj, parentName, childName);\n \n * throneInheritanceDeath(obj, name);\n \n * char ** param_3 = throneInheritanceGetInheritanceOrder(obj, retSize);\n \n * throneInheritanceFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class ThroneInheritance {\n\n public ThroneInheritance(string kingName) {\n\n }\n \n public void Birth(string parentName, string childName) {\n\n }\n \n public void Death(string name) {\n\n }\n \n public IList GetInheritanceOrder() {\n\n }\n}\n\n/**\n * Your ThroneInheritance object will be instantiated and called as such:\n * ThroneInheritance obj = new ThroneInheritance(kingName);\n * obj.Birth(parentName,childName);\n * obj.Death(name);\n * IList param_3 = obj.GetInheritanceOrder();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} kingName\n */\nvar ThroneInheritance = function(kingName) {\n\n};\n\n/** \n * @param {string} parentName \n * @param {string} childName\n * @return {void}\n */\nThroneInheritance.prototype.birth = function(parentName, childName) {\n\n};\n\n/** \n * @param {string} name\n * @return {void}\n */\nThroneInheritance.prototype.death = function(name) {\n\n};\n\n/**\n * @return {string[]}\n */\nThroneInheritance.prototype.getInheritanceOrder = function() {\n\n};\n\n/**\n * Your ThroneInheritance object will be instantiated and called as such:\n * var obj = new ThroneInheritance(kingName)\n * obj.birth(parentName,childName)\n * obj.death(name)\n * var param_3 = obj.getInheritanceOrder()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class ThroneInheritance\n\n=begin\n :type king_name: String\n=end\n def initialize(king_name)\n\n end\n\n\n=begin\n :type parent_name: String\n :type child_name: String\n :rtype: Void\n=end\n def birth(parent_name, child_name)\n\n end\n\n\n=begin\n :type name: String\n :rtype: Void\n=end\n def death(name)\n\n end\n\n\n=begin\n :rtype: String[]\n=end\n def get_inheritance_order()\n\n end\n\n\nend\n\n# Your ThroneInheritance object will be instantiated and called as such:\n# obj = ThroneInheritance.new(king_name)\n# obj.birth(parent_name, child_name)\n# obj.death(name)\n# param_3 = obj.get_inheritance_order()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass ThroneInheritance {\n\n init(_ kingName: String) {\n \n }\n \n func birth(_ parentName: String, _ childName: String) {\n \n }\n \n func death(_ name: String) {\n \n }\n \n func getInheritanceOrder() -> [String] {\n \n }\n}\n\n/**\n * Your ThroneInheritance object will be instantiated and called as such:\n * let obj = ThroneInheritance(kingName)\n * obj.birth(parentName, childName)\n * obj.death(name)\n * let ret_3: [String] = obj.getInheritanceOrder()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type ThroneInheritance struct {\n\n}\n\n\nfunc Constructor(kingName string) ThroneInheritance {\n\n}\n\n\nfunc (this *ThroneInheritance) Birth(parentName string, childName string) {\n\n}\n\n\nfunc (this *ThroneInheritance) Death(name string) {\n\n}\n\n\nfunc (this *ThroneInheritance) GetInheritanceOrder() []string {\n\n}\n\n\n/**\n * Your ThroneInheritance object will be instantiated and called as such:\n * obj := Constructor(kingName);\n * obj.Birth(parentName,childName);\n * obj.Death(name);\n * param_3 := obj.GetInheritanceOrder();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class ThroneInheritance(_kingName: String) {\n\n def birth(parentName: String, childName: String) {\n\n }\n\n def death(name: String) {\n\n }\n\n def getInheritanceOrder(): List[String] = {\n\n }\n\n}\n\n/**\n * Your ThroneInheritance object will be instantiated and called as such:\n * var obj = new ThroneInheritance(kingName)\n * obj.birth(parentName,childName)\n * obj.death(name)\n * var param_3 = obj.getInheritanceOrder()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class ThroneInheritance(kingName: String) {\n\n fun birth(parentName: String, childName: String) {\n\n }\n\n fun death(name: String) {\n\n }\n\n fun getInheritanceOrder(): List {\n\n }\n\n}\n\n/**\n * Your ThroneInheritance object will be instantiated and called as such:\n * var obj = ThroneInheritance(kingName)\n * obj.birth(parentName,childName)\n * obj.death(name)\n * var param_3 = obj.getInheritanceOrder()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct ThroneInheritance {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl ThroneInheritance {\n\n fn new(kingName: String) -> Self {\n\n }\n \n fn birth(&self, parent_name: String, child_name: String) {\n\n }\n \n fn death(&self, name: String) {\n\n }\n \n fn get_inheritance_order(&self) -> Vec {\n\n }\n}\n\n/**\n * Your ThroneInheritance object will be instantiated and called as such:\n * let obj = ThroneInheritance::new(kingName);\n * obj.birth(parentName, childName);\n * obj.death(name);\n * let ret_3: Vec = obj.get_inheritance_order();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class ThroneInheritance {\n /**\n * @param String $kingName\n */\n function __construct($kingName) {\n\n }\n\n /**\n * @param String $parentName\n * @param String $childName\n * @return NULL\n */\n function birth($parentName, $childName) {\n\n }\n\n /**\n * @param String $name\n * @return NULL\n */\n function death($name) {\n\n }\n\n /**\n * @return String[]\n */\n function getInheritanceOrder() {\n\n }\n}\n\n/**\n * Your ThroneInheritance object will be instantiated and called as such:\n * $obj = ThroneInheritance($kingName);\n * $obj->birth($parentName, $childName);\n * $obj->death($name);\n * $ret_3 = $obj->getInheritanceOrder();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class ThroneInheritance {\n constructor(kingName: string) {\n\n }\n\n birth(parentName: string, childName: string): void {\n\n }\n\n death(name: string): void {\n\n }\n\n getInheritanceOrder(): string[] {\n\n }\n}\n\n/**\n * Your ThroneInheritance object will be instantiated and called as such:\n * var obj = new ThroneInheritance(kingName)\n * obj.birth(parentName,childName)\n * obj.death(name)\n * var param_3 = obj.getInheritanceOrder()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define throne-inheritance%\n (class object%\n (super-new)\n\n ; king-name : string?\n (init-field\n king-name)\n \n ; birth : string? string? -> void?\n (define/public (birth parentName childName)\n\n )\n ; death : string? -> void?\n (define/public (death name)\n\n )\n ; get-inheritance-order : -> (listof string?)\n (define/public (get-inheritance-order)\n\n )))\n\n;; Your throne-inheritance% object will be instantiated and called as such:\n;; (define obj (new throne-inheritance% [kingName kingName]))\n;; (send obj birth parent-name child-name)\n;; (send obj death name)\n;; (define param_3 (send obj get-inheritance-order))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1600](https://leetcode-cn.com/problems/throne-inheritance)", "[\u7687\u4f4d\u7ee7\u627f\u987a\u5e8f](/solution/1600-1699/1600.Throne%20Inheritance/README.md)", "`\u6811`,`\u8bbe\u8ba1`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1600](https://leetcode.com/problems/throne-inheritance)", "[Throne Inheritance](/solution/1600-1699/1600.Throne%20Inheritance/README_EN.md)", "`Tree`,`Design`", "Medium", ""]}, {"question_id": "1721", "frontend_question_id": "1599", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-profit-of-operating-a-centennial-wheel", "url_en": "https://leetcode.com/problems/maximum-profit-of-operating-a-centennial-wheel", "relative_path_cn": "/solution/1500-1599/1599.Maximum%20Profit%20of%20Operating%20a%20Centennial%20Wheel/README.md", "relative_path_en": "/solution/1500-1599/1599.Maximum%20Profit%20of%20Operating%20a%20Centennial%20Wheel/README_EN.md", "title_cn": "\u7ecf\u8425\u6469\u5929\u8f6e\u7684\u6700\u5927\u5229\u6da6", "title_en": "Maximum Profit of Operating a Centennial Wheel", "question_title_slug": "maximum-profit-of-operating-a-centennial-wheel", "content_en": "

    You are the operator of a Centennial Wheel that has four gondolas, and each gondola has room for up to four people. You have the ability to rotate the gondolas counterclockwise, which costs you runningCost dollars.

    \n\n

    You are given an array customers of length n where customers[i] is the number of new customers arriving just before the ith rotation (0-indexed). This means you must rotate the wheel i times before the customers[i] customers arrive. You cannot make customers wait if there is room in the gondola. Each customer pays boardingCost dollars when they board on the gondola closest to the ground and will exit once that gondola reaches the ground again.

    \n\n

    You can stop the wheel at any time, including before serving all customers. If you decide to stop serving customers, all subsequent rotations are free in order to get all the customers down safely. Note that if there are currently more than four customers waiting at the wheel, only four will board the gondola, and the rest will wait for the next rotation.

    \n\n

    Return the minimum number of rotations you need to perform to maximize your profit. If there is no scenario where the profit is positive, return -1.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: customers = [8,3], boardingCost = 5, runningCost = 6\nOutput: 3\nExplanation: The numbers written on the gondolas are the number of people currently there.\n1. 8 customers arrive, 4 board and 4 wait for the next gondola, the wheel rotates. Current profit is 4 * $5 - 1 * $6 = $14.\n2. 3 customers arrive, the 4 waiting board the wheel and the other 3 wait, the wheel rotates. Current profit is 8 * $5 - 2 * $6 = $28.\n3. The final 3 customers board the gondola, the wheel rotates. Current profit is 11 * $5 - 3 * $6 = $37.\nThe highest profit was $37 after rotating the wheel 3 times.
    \n\n

    Example 2:

    \n\n
    \nInput: customers = [10,9,6], boardingCost = 6, runningCost = 4\nOutput: 7\nExplanation:\n1. 10 customers arrive, 4 board and 6 wait for the next gondola, the wheel rotates. Current profit is 4 * $6 - 1 * $4 = $20.\n2. 9 customers arrive, 4 board and 11 wait (2 originally waiting, 9 newly waiting), the wheel rotates. Current profit is 8 * $6 - 2 * $4 = $40.\n3. The final 6 customers arrive, 4 board and 13 wait, the wheel rotates. Current profit is 12 * $6 - 3 * $4 = $60.\n4. 4 board and 9 wait, the wheel rotates. Current profit is 16 * $6 - 4 * $4 = $80.\n5. 4 board and 5 wait, the wheel rotates. Current profit is 20 * $6 - 5 * $4 = $100.\n6. 4 board and 1 waits, the wheel rotates. Current profit is 24 * $6 - 6 * $4 = $120.\n7. 1 boards, the wheel rotates. Current profit is 25 * $6 - 7 * $4 = $122.\nThe highest profit was $122 after rotating the wheel 7 times.\n\n
    \n\n

    Example 3:

    \n\n
    \nInput: customers = [3,4,0,5,1], boardingCost = 1, runningCost = 92\nOutput: -1\nExplanation:\n1. 3 customers arrive, 3 board and 0 wait, the wheel rotates. Current profit is 3 * $1 - 1 * $92 = -$89.\n2. 4 customers arrive, 4 board and 0 wait, the wheel rotates. Current profit is 7 * $1 - 2 * $92 = -$177.\n3. 0 customers arrive, 0 board and 0 wait, the wheel rotates. Current profit is 7 * $1 - 3 * $92 = -$269.\n4. 5 customers arrive, 4 board and 1 waits, the wheel rotates. Current profit is 11 * $1 - 4 * $92 = -$357.\n5. 1 customer arrives, 2 board and 0 wait, the wheel rotates. Current profit is 13 * $1 - 5 * $92 = -$447.\nThe profit was never positive, so return -1.\n
    \n\n

    Example 4:

    \n\n
    \nInput: customers = [10,10,6,4,7], boardingCost = 3, runningCost = 8\nOutput: 9\nExplanation:\n1. 10 customers arrive, 4 board and 6 wait, the wheel rotates. Current profit is 4 * $3 - 1 * $8 = $4.\n2. 10 customers arrive, 4 board and 12 wait, the wheel rotates. Current profit is 8 * $3 - 2 * $8 = $8.\n3. 6 customers arrive, 4 board and 14 wait, the wheel rotates. Current profit is 12 * $3 - 3 * $8 = $12.\n4. 4 customers arrive, 4 board and 14 wait, the wheel rotates. Current profit is 16 * $3 - 4 * $8 = $16.\n5. 7 customers arrive, 4 board and 17 wait, the wheel rotates. Current profit is 20 * $3 - 5 * $8 = $20.\n6. 4 board and 13 wait, the wheel rotates. Current profit is 24 * $3 - 6 * $8 = $24.\n7. 4 board and 9 wait, the wheel rotates. Current profit is 28 * $3 - 7 * $8 = $28.\n8. 4 board and 5 wait, the wheel rotates. Current profit is 32 * $3 - 8 * $8 = $32.\n9. 4 board and 1 waits, the wheel rotates. Current profit is 36 * $3 - 9 * $8 = $36.\n10. 1 board and 0 wait, the wheel rotates. Current profit is 37 * $3 - 10 * $8 = $31.\nThe highest profit was $36 after rotating the wheel 9 times.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == customers.length
    • \n\t
    • 1 <= n <= 105
    • \n\t
    • 0 <= customers[i] <= 50
    • \n\t
    • 1 <= boardingCost, runningCost <= 100
    • \n
    \n", "content_cn": "

    \u4f60\u6b63\u5728\u7ecf\u8425\u4e00\u5ea7\u6469\u5929\u8f6e\uff0c\u8be5\u6469\u5929\u8f6e\u5171\u6709 4 \u4e2a\u5ea7\u8231 \uff0c\u6bcf\u4e2a\u5ea7\u8231 \u6700\u591a\u53ef\u4ee5\u5bb9\u7eb3 4 \u4f4d\u6e38\u5ba2 \u3002\u4f60\u53ef\u4ee5 \u9006\u65f6\u9488 \u8f6e\u8f6c\u5ea7\u8231\uff0c\u4f46\u6bcf\u6b21\u8f6e\u8f6c\u90fd\u9700\u8981\u652f\u4ed8\u4e00\u5b9a\u7684\u8fd0\u884c\u6210\u672c runningCost \u3002\u6469\u5929\u8f6e\u6bcf\u6b21\u8f6e\u8f6c\u90fd\u6070\u597d\u8f6c\u52a8 1 / 4 \u5468\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u6570\u7ec4 customers \uff0c customers[i] \u662f\u5728\u7b2c i \u6b21\u8f6e\u8f6c\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\u4e4b\u524d\u5230\u8fbe\u7684\u65b0\u6e38\u5ba2\u7684\u6570\u91cf\u3002\u8fd9\u4e5f\u610f\u5473\u7740\u4f60\u5fc5\u987b\u5728\u65b0\u6e38\u5ba2\u5230\u6765\u524d\u8f6e\u8f6c i \u6b21\u3002\u6bcf\u4f4d\u6e38\u5ba2\u5728\u767b\u4e0a\u79bb\u5730\u9762\u6700\u8fd1\u7684\u5ea7\u8231\u524d\u90fd\u4f1a\u652f\u4ed8\u767b\u8231\u6210\u672c boardingCost \uff0c\u4e00\u65e6\u8be5\u5ea7\u8231\u518d\u6b21\u62b5\u8fbe\u5730\u9762\uff0c\u4ed6\u4eec\u5c31\u4f1a\u79bb\u5f00\u5ea7\u8231\u7ed3\u675f\u6e38\u73a9\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u968f\u65f6\u505c\u4e0b\u6469\u5929\u8f6e\uff0c\u5373\u4fbf\u662f \u5728\u670d\u52a1\u6240\u6709\u6e38\u5ba2\u4e4b\u524d \u3002\u5982\u679c\u4f60\u51b3\u5b9a\u505c\u6b62\u8fd0\u8425\u6469\u5929\u8f6e\uff0c\u4e3a\u4e86\u4fdd\u8bc1\u6240\u6709\u6e38\u5ba2\u5b89\u5168\u7740\u9646\uff0c\u5c06\u514d\u8d39\u8fdb\u884c\u6240\u6709\u540e\u7eed\u8f6e\u8f6c \u3002\u6ce8\u610f\uff0c\u5982\u679c\u6709\u8d85\u8fc7 4 \u4f4d\u6e38\u5ba2\u5728\u7b49\u6469\u5929\u8f6e\uff0c\u90a3\u4e48\u53ea\u6709 4 \u4f4d\u6e38\u5ba2\u53ef\u4ee5\u767b\u4e0a\u6469\u5929\u8f6e\uff0c\u5176\u4f59\u7684\u9700\u8981\u7b49\u5f85 \u4e0b\u4e00\u6b21\u8f6e\u8f6c \u3002

    \n\n

    \u8fd4\u56de\u6700\u5927\u5316\u5229\u6da6\u6240\u9700\u6267\u884c\u7684 \u6700\u5c0f\u8f6e\u8f6c\u6b21\u6570 \u3002 \u5982\u679c\u4e0d\u5b58\u5728\u5229\u6da6\u4e3a\u6b63\u7684\u65b9\u6848\uff0c\u5219\u8fd4\u56de -1 \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1acustomers = [8,3], boardingCost = 5, runningCost = 6\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u5ea7\u8231\u4e0a\u6807\u6ce8\u7684\u6570\u5b57\u662f\u8be5\u5ea7\u8231\u7684\u5f53\u524d\u6e38\u5ba2\u6570\u3002\n1. 8 \u4f4d\u6e38\u5ba2\u62b5\u8fbe\uff0c4 \u4f4d\u767b\u8231\uff0c4 \u4f4d\u7b49\u5f85\u4e0b\u4e00\u8231\uff0c\u6469\u5929\u8f6e\u8f6e\u8f6c\u3002\u5f53\u524d\u5229\u6da6\u4e3a 4 * $5 - 1 * $6 = $14 \u3002\n2. 3 \u4f4d\u6e38\u5ba2\u62b5\u8fbe\uff0c4 \u4f4d\u5728\u7b49\u5f85\u7684\u6e38\u5ba2\u767b\u8231\uff0c\u5176\u4ed6 3 \u4f4d\u7b49\u5f85\uff0c\u6469\u5929\u8f6e\u8f6e\u8f6c\u3002\u5f53\u524d\u5229\u6da6\u4e3a 8 * $5 - 2 * $6 = $28 \u3002\n3. \u6700\u540e 3 \u4f4d\u6e38\u5ba2\u767b\u8231\uff0c\u6469\u5929\u8f6e\u8f6e\u8f6c\u3002\u5f53\u524d\u5229\u6da6\u4e3a 11 * $5 - 3 * $6 = $37 \u3002\n\u8f6e\u8f6c 3 \u6b21\u5f97\u5230\u6700\u5927\u5229\u6da6\uff0c\u6700\u5927\u5229\u6da6\u4e3a $37 \u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1acustomers = [10,9,6], boardingCost = 6, runningCost = 4\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\n1. 10 \u4f4d\u6e38\u5ba2\u62b5\u8fbe\uff0c4 \u4f4d\u767b\u8231\uff0c6 \u4f4d\u7b49\u5f85\u4e0b\u4e00\u8231\uff0c\u6469\u5929\u8f6e\u8f6e\u8f6c\u3002\u5f53\u524d\u5229\u6da6\u4e3a 4 * $6 - 1 * $4 = $20 \u3002\n2. 9 \u4f4d\u6e38\u5ba2\u62b5\u8fbe\uff0c4 \u4f4d\u767b\u8231\uff0c11 \u4f4d\u7b49\u5f85\uff082 \u4f4d\u662f\u5148\u524d\u5c31\u5728\u7b49\u5f85\u7684\uff0c9 \u4f4d\u65b0\u52a0\u5165\u7b49\u5f85\u7684\uff09\uff0c\u6469\u5929\u8f6e\u8f6e\u8f6c\u3002\u5f53\u524d\u5229\u6da6\u4e3a 8 * $6 - 2 * $4 = $40 \u3002\n3. \u6700\u540e 6 \u4f4d\u6e38\u5ba2\u62b5\u8fbe\uff0c4 \u4f4d\u767b\u8231\uff0c13 \u4f4d\u7b49\u5f85\uff0c\u6469\u5929\u8f6e\u8f6e\u8f6c\u3002\u5f53\u524d\u5229\u6da6\u4e3a 12 * $6 - 3 * $4 = $60 \u3002\n4. 4 \u4f4d\u767b\u8231\uff0c9 \u4f4d\u7b49\u5f85\uff0c\u6469\u5929\u8f6e\u8f6e\u8f6c\u3002\u5f53\u524d\u5229\u6da6\u4e3a * $6 - 4 * $4 = $80 \u3002\n5. 4 \u4f4d\u767b\u8231\uff0c5 \u4f4d\u7b49\u5f85\uff0c\u6469\u5929\u8f6e\u8f6e\u8f6c\u3002\u5f53\u524d\u5229\u6da6\u4e3a 20 * $6 - 5 * $4 = $100 \u3002\n6. 4 \u4f4d\u767b\u8231\uff0c1 \u4f4d\u7b49\u5f85\uff0c\u6469\u5929\u8f6e\u8f6e\u8f6c\u3002\u5f53\u524d\u5229\u6da6\u4e3a 24 * $6 - 6 * $4 = $120 \u3002\n7. 1 \u4f4d\u767b\u8231\uff0c\u6469\u5929\u8f6e\u8f6e\u8f6c\u3002\u5f53\u524d\u5229\u6da6\u4e3a 25 * $6 - 7 * $4 = $122 \u3002\n\u8f6e\u8f6c 7 \u6b21\u5f97\u5230\u6700\u5927\u5229\u6da6\uff0c\u6700\u5927\u5229\u6da6\u4e3a$122 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1acustomers = [3,4,0,5,1], boardingCost = 1, runningCost = 92\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\n1. 3 \u4f4d\u6e38\u5ba2\u62b5\u8fbe\uff0c3 \u4f4d\u767b\u8231\uff0c0 \u4f4d\u7b49\u5f85\uff0c\u6469\u5929\u8f6e\u8f6e\u8f6c\u3002\u5f53\u524d\u5229\u6da6\u4e3a 3 * $1 - 1 * $92 = -$89 \u3002\n2. 4 \u4f4d\u6e38\u5ba2\u62b5\u8fbe\uff0c4 \u4f4d\u767b\u8231\uff0c0 \u4f4d\u7b49\u5f85\uff0c\u6469\u5929\u8f6e\u8f6e\u8f6c\u3002\u5f53\u524d\u5229\u6da6\u4e3a is 7 * $1 - 2 * $92 = -$177 \u3002\n3. 0 \u4f4d\u6e38\u5ba2\u62b5\u8fbe\uff0c0 \u4f4d\u767b\u8231\uff0c0 \u4f4d\u7b49\u5f85\uff0c\u6469\u5929\u8f6e\u8f6e\u8f6c\u3002\u5f53\u524d\u5229\u6da6\u4e3a 7 * $1 - 3 * $92 = -$269 \u3002\n4. 5 \u4f4d\u6e38\u5ba2\u62b5\u8fbe\uff0c4 \u4f4d\u767b\u8231\uff0c1 \u4f4d\u7b49\u5f85\uff0c\u6469\u5929\u8f6e\u8f6e\u8f6c\u3002\u5f53\u524d\u5229\u6da6\u4e3a 12 * $1 - 4 * $92 = -$356 \u3002\n5. 1 \u4f4d\u6e38\u5ba2\u62b5\u8fbe\uff0c2 \u4f4d\u767b\u8231\uff0c0 \u4f4d\u7b49\u5f85\uff0c\u6469\u5929\u8f6e\u8f6e\u8f6c\u3002\u5f53\u524d\u5229\u6da6\u4e3a 13 * $1 - 5 * $92 = -$447 \u3002\n\u5229\u6da6\u6c38\u4e0d\u4e3a\u6b63\uff0c\u6240\u4ee5\u8fd4\u56de -1 \u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1acustomers = [10,10,6,4,7], boardingCost = 3, runningCost = 8\n\u8f93\u51fa\uff1a9\n\u89e3\u91ca\uff1a\n1. 10 \u4f4d\u6e38\u5ba2\u62b5\u8fbe\uff0c4 \u4f4d\u767b\u8231\uff0c6 \u4f4d\u7b49\u5f85\uff0c\u6469\u5929\u8f6e\u8f6e\u8f6c\u3002\u5f53\u524d\u5229\u6da6\u4e3a 4 * $3 - 1 * $8 = $4 \u3002\n2. 10 \u4f4d\u6e38\u5ba2\u62b5\u8fbe\uff0c4 \u4f4d\u767b\u8231\uff0c12 \u4f4d\u7b49\u5f85\uff0c\u6469\u5929\u8f6e\u8f6e\u8f6c\u3002\u5f53\u524d\u5229\u6da6\u4e3a 8 * $3 - 2 * $8 = $8 \u3002\n3. 6 \u4f4d\u6e38\u5ba2\u62b5\u8fbe\uff0c4 \u4f4d\u767b\u8231\uff0c14 \u4f4d\u7b49\u5f85\uff0c\u6469\u5929\u8f6e\u8f6e\u8f6c\u3002\u5f53\u524d\u5229\u6da6\u4e3a 12 * $3 - 3 * $8 = $12 \u3002\n4. 4 \u4f4d\u6e38\u5ba2\u62b5\u8fbe\uff0c4 \u4f4d\u767b\u8231\uff0c14 \u4f4d\u7b49\u5f85\uff0c\u6469\u5929\u8f6e\u8f6e\u8f6c\u3002\u5f53\u524d\u5229\u6da6\u4e3a 16 * $3 - 4 * $8 = $16 \u3002\n5. 7 \u4f4d\u6e38\u5ba2\u62b5\u8fbe\uff0c4 \u4f4d\u767b\u8231\uff0c17 \u4f4d\u7b49\u5f85\uff0c\u6469\u5929\u8f6e\u8f6e\u8f6c\u3002\u5f53\u524d\u5229\u6da6\u4e3a 20 * $3 - 5 * $8 = $20 \u3002\n6. 4 \u4f4d\u767b\u8231\uff0c13 \u4f4d\u7b49\u5f85\uff0c\u6469\u5929\u8f6e\u8f6e\u8f6c\u3002\u5f53\u524d\u5229\u6da6\u4e3a 24 * $3 - 6 * $8 = $24 \u3002\n7. 4 \u4f4d\u767b\u8231\uff0c9 \u4f4d\u7b49\u5f85\uff0c\u6469\u5929\u8f6e\u8f6e\u8f6c\u3002\u5f53\u524d\u5229\u6da6\u4e3a 28 * $3 - 7 * $8 = $28 \u3002\n8. 4 \u4f4d\u767b\u8231\uff0c5 \u4f4d\u7b49\u5f85\uff0c\u6469\u5929\u8f6e\u8f6e\u8f6c\u3002\u5f53\u524d\u5229\u6da6\u4e3a 32 * $3 - 8 * $8 = $32 \u3002\n9. 4 \u4f4d\u767b\u8231\uff0c1 \u4f4d\u7b49\u5f85\uff0c\u6469\u5929\u8f6e\u8f6e\u8f6c\u3002\u5f53\u524d\u5229\u6da6\u4e3a 36 * $3 - 9 * $8 = $36 \u3002\n\u200b\u200b\u200b\u200b\u200b\u200b\u200b10. 1 \u4f4d\u767b\u8231\uff0c0 \u4f4d\u7b49\u5f85\uff0c\u6469\u5929\u8f6e\u8f6e\u8f6c\u3002\u5f53\u524d\u5229\u6da6\u4e3a 37 * $3 - 10 * $8 = $31 \u3002\n\u8f6e\u8f6c 9 \u6b21\u5f97\u5230\u6700\u5927\u5229\u6da6\uff0c\u6700\u5927\u5229\u6da6\u4e3a $36 \u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == customers.length
    • \n\t
    • 1 <= n <= 105
    • \n\t
    • 0 <= customers[i] <= 50
    • \n\t
    • 1 <= boardingCost, runningCost <= 100
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minOperationsMaxProfit(vector& customers, int boardingCost, int runningCost) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minOperationsMaxProfit(int[] customers, int boardingCost, int runningCost) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minOperationsMaxProfit(self, customers, boardingCost, runningCost):\n \"\"\"\n :type customers: List[int]\n :type boardingCost: int\n :type runningCost: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minOperationsMaxProfit(self, customers: List[int], boardingCost: int, runningCost: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minOperationsMaxProfit(int* customers, int customersSize, int boardingCost, int runningCost){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinOperationsMaxProfit(int[] customers, int boardingCost, int runningCost) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} customers\n * @param {number} boardingCost\n * @param {number} runningCost\n * @return {number}\n */\nvar minOperationsMaxProfit = function(customers, boardingCost, runningCost) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} customers\n# @param {Integer} boarding_cost\n# @param {Integer} running_cost\n# @return {Integer}\ndef min_operations_max_profit(customers, boarding_cost, running_cost)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minOperationsMaxProfit(_ customers: [Int], _ boardingCost: Int, _ runningCost: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minOperationsMaxProfit(customers []int, boardingCost int, runningCost int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minOperationsMaxProfit(customers: Array[Int], boardingCost: Int, runningCost: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minOperationsMaxProfit(customers: IntArray, boardingCost: Int, runningCost: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_operations_max_profit(customers: Vec, boarding_cost: i32, running_cost: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $customers\n * @param Integer $boardingCost\n * @param Integer $runningCost\n * @return Integer\n */\n function minOperationsMaxProfit($customers, $boardingCost, $runningCost) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minOperationsMaxProfit(customers: number[], boardingCost: number, runningCost: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-operations-max-profit customers boardingCost runningCost)\n (-> (listof exact-integer?) exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1599](https://leetcode-cn.com/problems/maximum-profit-of-operating-a-centennial-wheel)", "[\u7ecf\u8425\u6469\u5929\u8f6e\u7684\u6700\u5927\u5229\u6da6](/solution/1500-1599/1599.Maximum%20Profit%20of%20Operating%20a%20Centennial%20Wheel/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1599](https://leetcode.com/problems/maximum-profit-of-operating-a-centennial-wheel)", "[Maximum Profit of Operating a Centennial Wheel](/solution/1500-1599/1599.Maximum%20Profit%20of%20Operating%20a%20Centennial%20Wheel/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1720", "frontend_question_id": "1598", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/crawler-log-folder", "url_en": "https://leetcode.com/problems/crawler-log-folder", "relative_path_cn": "/solution/1500-1599/1598.Crawler%20Log%20Folder/README.md", "relative_path_en": "/solution/1500-1599/1598.Crawler%20Log%20Folder/README_EN.md", "title_cn": "\u6587\u4ef6\u5939\u64cd\u4f5c\u65e5\u5fd7\u641c\u96c6\u5668", "title_en": "Crawler Log Folder", "question_title_slug": "crawler-log-folder", "content_en": "

    The Leetcode file system keeps a log each time some user performs a change folder operation.

    \n\n

    The operations are described below:

    \n\n
      \n\t
    • "../" : Move to the parent folder of the current folder. (If you are already in the main folder, remain in the same folder).
    • \n\t
    • "./" : Remain in the same folder.
    • \n\t
    • "x/" : Move to the child folder named x (This folder is guaranteed to always exist).
    • \n
    \n\n

    You are given a list of strings logs where logs[i] is the operation performed by the user at the ith step.

    \n\n

    The file system starts in the main folder, then the operations in logs are performed.

    \n\n

    Return the minimum number of operations needed to go back to the main folder after the change folder operations.

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: logs = ["d1/","d2/","../","d21/","./"]\nOutput: 2\nExplanation: Use this change folder operation "../" 2 times and go back to the main folder.\n
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: logs = ["d1/","d2/","./","d3/","../","d31/"]\nOutput: 3\n
    \n\n

    Example 3:

    \n\n
    \nInput: logs = ["d1/","../","../","../"]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= logs.length <= 103
    • \n\t
    • 2 <= logs[i].length <= 10
    • \n\t
    • logs[i] contains lowercase English letters, digits, '.', and '/'.
    • \n\t
    • logs[i] follows the format described in the statement.
    • \n\t
    • Folder names consist of lowercase English letters and digits.
    • \n
    \n", "content_cn": "

    \u6bcf\u5f53\u7528\u6237\u6267\u884c\u53d8\u66f4\u6587\u4ef6\u5939\u64cd\u4f5c\u65f6\uff0cLeetCode \u6587\u4ef6\u7cfb\u7edf\u90fd\u4f1a\u4fdd\u5b58\u4e00\u6761\u65e5\u5fd7\u8bb0\u5f55\u3002

    \n\n

    \u4e0b\u9762\u7ed9\u51fa\u5bf9\u53d8\u66f4\u64cd\u4f5c\u7684\u8bf4\u660e\uff1a

    \n\n
      \n\t
    • "../" \uff1a\u79fb\u52a8\u5230\u5f53\u524d\u6587\u4ef6\u5939\u7684\u7236\u6587\u4ef6\u5939\u3002\u5982\u679c\u5df2\u7ecf\u5728\u4e3b\u6587\u4ef6\u5939\u4e0b\uff0c\u5219 \u7ee7\u7eed\u505c\u7559\u5728\u5f53\u524d\u6587\u4ef6\u5939 \u3002
    • \n\t
    • "./" \uff1a\u7ee7\u7eed\u505c\u7559\u5728\u5f53\u524d\u6587\u4ef6\u5939\u3002
    • \n\t
    • "x/" \uff1a\u79fb\u52a8\u5230\u540d\u4e3a x \u7684\u5b50\u6587\u4ef6\u5939\u4e2d\u3002\u9898\u76ee\u6570\u636e \u4fdd\u8bc1\u603b\u662f\u5b58\u5728\u6587\u4ef6\u5939 x \u3002
    • \n
    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32\u5217\u8868 logs \uff0c\u5176\u4e2d logs[i] \u662f\u7528\u6237\u5728 ith \u6b65\u6267\u884c\u7684\u64cd\u4f5c\u3002

    \n\n

    \u6587\u4ef6\u7cfb\u7edf\u542f\u52a8\u65f6\u4f4d\u4e8e\u4e3b\u6587\u4ef6\u5939\uff0c\u7136\u540e\u6267\u884c logs \u4e2d\u7684\u64cd\u4f5c\u3002

    \n\n

    \u6267\u884c\u5b8c\u6240\u6709\u53d8\u66f4\u6587\u4ef6\u5939\u64cd\u4f5c\u540e\uff0c\u8bf7\u4f60\u627e\u51fa \u8fd4\u56de\u4e3b\u6587\u4ef6\u5939\u6240\u9700\u7684\u6700\u5c0f\u6b65\u6570 \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1alogs = ["d1/","d2/","../","d21/","./"]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6267\u884c "../" \u64cd\u4f5c\u53d8\u66f4\u6587\u4ef6\u5939 2 \u6b21\uff0c\u5373\u53ef\u56de\u5230\u4e3b\u6587\u4ef6\u5939\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1alogs = ["d1/","d2/","./","d3/","../","d31/"]\n\u8f93\u51fa\uff1a3\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1alogs = ["d1/","../","../","../"]\n\u8f93\u51fa\uff1a0\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= logs.length <= 103
    • \n\t
    • 2 <= logs[i].length <= 10
    • \n\t
    • logs[i] \u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\uff0c\u6570\u5b57\uff0c'.' \u548c '/'
    • \n\t
    • logs[i] \u7b26\u5408\u8bed\u53e5\u4e2d\u63cf\u8ff0\u7684\u683c\u5f0f
    • \n\t
    • \u6587\u4ef6\u5939\u540d\u79f0\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u548c\u6570\u5b57\u7ec4\u6210
    • \n
    \n", "tags_en": ["Stack"], "tags_cn": ["\u6808"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minOperations(vector& logs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minOperations(String[] logs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minOperations(self, logs):\n \"\"\"\n :type logs: List[str]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minOperations(self, logs: List[str]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minOperations(char ** logs, int logsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinOperations(string[] logs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} logs\n * @return {number}\n */\nvar minOperations = function(logs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} logs\n# @return {Integer}\ndef min_operations(logs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minOperations(_ logs: [String]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minOperations(logs []string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minOperations(logs: Array[String]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minOperations(logs: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_operations(logs: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $logs\n * @return Integer\n */\n function minOperations($logs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minOperations(logs: string[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-operations logs)\n (-> (listof string?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1598](https://leetcode-cn.com/problems/crawler-log-folder)", "[\u6587\u4ef6\u5939\u64cd\u4f5c\u65e5\u5fd7\u641c\u96c6\u5668](/solution/1500-1599/1598.Crawler%20Log%20Folder/README.md)", "`\u6808`", "\u7b80\u5355", ""], "md_table_row_en": ["[1598](https://leetcode.com/problems/crawler-log-folder)", "[Crawler Log Folder](/solution/1500-1599/1598.Crawler%20Log%20Folder/README_EN.md)", "`Stack`", "Easy", ""]}, {"question_id": "1719", "frontend_question_id": "1580", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/put-boxes-into-the-warehouse-ii", "url_en": "https://leetcode.com/problems/put-boxes-into-the-warehouse-ii", "relative_path_cn": "/solution/1500-1599/1580.Put%20Boxes%20Into%20the%20Warehouse%20II/README.md", "relative_path_en": "/solution/1500-1599/1580.Put%20Boxes%20Into%20the%20Warehouse%20II/README_EN.md", "title_cn": "\u628a\u7bb1\u5b50\u653e\u8fdb\u4ed3\u5e93\u91cc II", "title_en": "Put Boxes Into the Warehouse II", "question_title_slug": "put-boxes-into-the-warehouse-ii", "content_en": "

    You are given two arrays of positive integers, boxes and warehouse, representing the heights of some boxes of unit width and the heights of n rooms in a warehouse respectively. The warehouse's rooms are labeled from 0 to n - 1 from left to right where warehouse[i] (0-indexed) is the height of the ith room.

    \n\n

    Boxes are put into the warehouse by the following rules:

    \n\n
      \n\t
    • Boxes cannot be stacked.
    • \n\t
    • You can rearrange the insertion order of the boxes.
    • \n\t
    • Boxes can be pushed into the warehouse from either side (left or right)
    • \n\t
    • If the height of some room in the warehouse is less than the height of a box, then that box and all other boxes behind it will be stopped before that room.
    • \n
    \n\n

    Return the maximum number of boxes you can put into the warehouse.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: boxes = [1,2,2,3,4], warehouse = [3,4,1,2]\nOutput: 4\nExplanation:\n\"\"\nWe can store the boxes in the following order:\n1- Put the yellow box in room 2 from either the left or right side.\n2- Put the orange box in room 3 from the right side.\n3- Put the green box in room 1 from the left side.\n4- Put the red box in room 0 from the left side.\nNotice that there are other valid ways to put 4 boxes such as swapping the red and green boxes or the red and orange boxes.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: boxes = [3,5,5,2], warehouse = [2,1,3,4,5]\nOutput: 3\nExplanation:\n\"\"\nIt's not possible to put the two boxes of height 5 in the warehouse since there's only 1 room of height >= 5.\nOther valid solutions are to put the green box in room 2 or to put the orange box first in room 2 before putting the green and red boxes.\n
    \n\n

    Example 3:

    \n\n
    \nInput: boxes = [1,2,3], warehouse = [1,2,3,4]\nOutput: 3\n
    \n\n

    Example 4:

    \n\n
    \nInput: boxes = [4,5,6], warehouse = [3,3,3,3,3]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == warehouse.length
    • \n\t
    • 1 <= boxes.length, warehouse.length <= 105
    • \n\t
    • 1 <= boxes[i], warehouse[i] <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u6b63\u6574\u6570\u6570\u7ec4\u00a0boxes \u548c warehouse\u00a0\uff0c\u5206\u522b\u5305\u542b\u5355\u4f4d\u5bbd\u5ea6\u7684\u7bb1\u5b50\u7684\u9ad8\u5ea6\uff0c\u4ee5\u53ca\u4ed3\u5e93\u4e2dn\u4e2a\u623f\u95f4\u5404\u81ea\u7684\u9ad8\u5ea6\u3002\u4ed3\u5e93\u7684\u623f\u95f4\u5206\u522b\u4ece0\u00a0\u5230 n - 1\u81ea\u5de6\u5411\u53f3\u7f16\u53f7\uff0cwarehouse[i]\uff08\u7d22\u5f15\u4ece 0 \u5f00\u59cb\uff09\u662f\u7b2c\u00a0i\u00a0\u4e2a\u623f\u95f4\u7684\u9ad8\u5ea6\u3002

    \n\n

    \u7bb1\u5b50\u653e\u8fdb\u4ed3\u5e93\u65f6\u9075\u5faa\u4e0b\u5217\u89c4\u5219\uff1a

    \n\n
      \n\t
    • \u7bb1\u5b50\u4e0d\u53ef\u53e0\u653e\u3002
    • \n\t
    • \u4f60\u53ef\u4ee5\u91cd\u65b0\u8c03\u6574\u7bb1\u5b50\u7684\u987a\u5e8f\u3002
    • \n\t
    • \u7bb1\u5b50\u53ef\u4ee5\u4ece\u4efb\u610f\u65b9\u5411\uff08\u5de6\u8fb9\u6216\u53f3\u8fb9\uff09\u63a8\u5165\u4ed3\u5e93\u4e2d\u3002
    • \n\t
    • \u5982\u679c\u4ed3\u5e93\u4e2d\u67d0\u623f\u95f4\u7684\u9ad8\u5ea6\u5c0f\u4e8e\u67d0\u7bb1\u5b50\u7684\u9ad8\u5ea6\uff0c\u5219\u8fd9\u4e2a\u7bb1\u5b50\u548c\u4e4b\u540e\u7684\u7bb1\u5b50\u90fd\u4f1a\u505c\u5728\u8fd9\u4e2a\u623f\u95f4\u7684\u524d\u9762\u3002
    • \n
    \n\n

    \u4f60\u6700\u591a\u53ef\u4ee5\u5728\u4ed3\u5e93\u4e2d\u653e\u8fdb\u591a\u5c11\u4e2a\u7bb1\u5b50\uff1f

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1:

    \n\"\"\n
    \n\u8f93\u5165: boxes = [1,2,2,3,4], warehouse = [3,4,1,2]\n\u8f93\u51fa: 4\n\u89e3\u91ca:\n\"\"\n\u6211\u4eec\u53ef\u4ee5\u6309\u5982\u4e0b\u987a\u5e8f\u63a8\u5165\u7bb1\u5b50:\n1- \u4ece\u5de6\u8fb9\u6216\u53f3\u8fb9\u628a\u9ec4\u8272\u7bb1\u5b50\u63a8\u51652\u53f7\u623f\u95f4\uff1b\n2- \u4ece\u53f3\u8fb9\u628a\u6a59\u8272\u7bb1\u5b50\u63a8\u51653\u53f7\u623f\u95f4\uff1b\n3- \u4ece\u5de6\u8fb9\u628a\u7eff\u8272\u7bb1\u5b50\u63a8\u51651\u53f7\u623f\u95f4\uff1b\n4- \u4ece\u5de6\u8fb9\u628a\u7ea2\u8272\u7bb1\u5b50\u63a8\u51650\u53f7\u623f\u95f4\uff1b\n\u8fd8\u6709\u5176\u4ed6\u65b9\u5f0f\u63a8\u51654\u4e2a\u7bb1\u5b50\uff0c\u6bd4\u5982\u4ea4\u6362\u7ea2\u8272\u4e0e\u7eff\u8272\u7bb1\u5b50\uff0c\u6216\u8005\u4ea4\u6362\u7ea2\u8272\u4e0e\u6a59\u8272\u7bb1\u5b50\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\"\"\n
    \n\u8f93\u5165: boxes = [3,5,5,2], warehouse = [2,1,3,4,5]\n\u8f93\u51fa: 3\n\u89e3\u91ca:\n\"\"\n\u56e0\u4e3a\u53ea\u6709\u4e00\u4e2a\u9ad8\u5ea6\u5927\u4e8e\u7b49\u4e8e5\u7684\u623f\u95f4\uff0c\u6240\u4ee5\u65e0\u6cd5\u5c06\u4e24\u4e2a\u9ad8\u5ea6\u4e3a5\u7684\u7bb1\u5b50\u90fd\u63a8\u5165\u4ed3\u5e93\u3002\n\u8fd8\u6709\u5176\u4ed6\u65b9\u5f0f\u63a8\u5165\u7bb1\u5b50\uff0c\u6bd4\u5982\u5c06\u7eff\u8272\u7bb1\u5b50\u63a8\u51652\u53f7\u623f\u95f4\uff0c\u6216\u8005\u5728\u7eff\u8272\u53ca\u7ea2\u8272\u7bb1\u5b50\u4e4b\u524d\u5c06\u6a59\u8272\u7bb1\u5b50\u63a8\u51652\u53f7\u623f\u95f4\u3002\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \n\u8f93\u5165: boxes = [1,2,3], warehouse = [1,2,3,4]\n\u8f93\u51fa: 3\n
    \n\n

    \u793a\u4f8b 4:

    \n\n
    \n\u8f93\u5165: boxes = [4,5,6], warehouse = [3,3,3,3,3]\n\u8f93\u51fa: 0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a:

    \n\n
      \n\t
    • n == warehouse.length
    • \n\t
    • 1 <= boxes.length, warehouse.length <= 105
    • \n\t
    • 1 <= boxes[i], warehouse[i] <= 109
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxBoxesInWarehouse(vector& boxes, vector& warehouse) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxBoxesInWarehouse(int[] boxes, int[] warehouse) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxBoxesInWarehouse(self, boxes, warehouse):\n \"\"\"\n :type boxes: List[int]\n :type warehouse: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxBoxesInWarehouse(self, boxes: List[int], warehouse: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxBoxesInWarehouse(int* boxes, int boxesSize, int* warehouse, int warehouseSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxBoxesInWarehouse(int[] boxes, int[] warehouse) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} boxes\n * @param {number[]} warehouse\n * @return {number}\n */\nvar maxBoxesInWarehouse = function(boxes, warehouse) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} boxes\n# @param {Integer[]} warehouse\n# @return {Integer}\ndef max_boxes_in_warehouse(boxes, warehouse)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxBoxesInWarehouse(_ boxes: [Int], _ warehouse: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxBoxesInWarehouse(boxes []int, warehouse []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxBoxesInWarehouse(boxes: Array[Int], warehouse: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxBoxesInWarehouse(boxes: IntArray, warehouse: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_boxes_in_warehouse(boxes: Vec, warehouse: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $boxes\n * @param Integer[] $warehouse\n * @return Integer\n */\n function maxBoxesInWarehouse($boxes, $warehouse) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxBoxesInWarehouse(boxes: number[], warehouse: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-boxes-in-warehouse boxes warehouse)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1580](https://leetcode-cn.com/problems/put-boxes-into-the-warehouse-ii)", "[\u628a\u7bb1\u5b50\u653e\u8fdb\u4ed3\u5e93\u91cc II](/solution/1500-1599/1580.Put%20Boxes%20Into%20the%20Warehouse%20II/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1580](https://leetcode.com/problems/put-boxes-into-the-warehouse-ii)", "[Put Boxes Into the Warehouse II](/solution/1500-1599/1580.Put%20Boxes%20Into%20the%20Warehouse%20II/README_EN.md)", "`Greedy`", "Medium", "\ud83d\udd12"]}, {"question_id": "1718", "frontend_question_id": "1571", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/warehouse-manager", "url_en": "https://leetcode.com/problems/warehouse-manager", "relative_path_cn": "/solution/1500-1599/1571.Warehouse%20Manager/README.md", "relative_path_en": "/solution/1500-1599/1571.Warehouse%20Manager/README_EN.md", "title_cn": "\u4ed3\u5e93\u7ecf\u7406", "title_en": "Warehouse Manager", "question_title_slug": "warehouse-manager", "content_en": "

    Table: Warehouse

    \n\n
    \n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| name         | varchar |\n| product_id   | int     |\n| units        | int     |\n+--------------+---------+\n(name, product_id) is the primary key for this table.\nEach row of this table contains the information of the products in each warehouse.\n
    \n\n

     

    \n\n

    Table: Products

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| product_id    | int     |\n| product_name  | varchar |\n| Width         | int     |\n| Length        | int     |\n| Height        | int     |\n+---------------+---------+\nproduct_id is the primary key for this table.\nEach row of this table contains the information about the product dimensions (Width, Lenght and Height) in feets of each product.\n
    \n\n

     

    \n\n

    Write an SQL query to report, How much cubic feet of volume does the inventory occupy in each warehouse.

    \n\n
      \n\t
    • warehouse_name
    • \n\t
    • volume
    • \n
    \n\n

    Return the result table in any order.

    \n\n

    The query result format is in the following example.

    \n\n

     

    \n\n
    \nWarehouse table:\n+------------+--------------+-------------+\n| name       | product_id   | units       |\n+------------+--------------+-------------+\n| LCHouse1   | 1            | 1           |\n| LCHouse1   | 2            | 10          |\n| LCHouse1   | 3            | 5           |\n| LCHouse2   | 1            | 2           |\n| LCHouse2   | 2            | 2           |\n| LCHouse3   | 4            | 1           |\n+------------+--------------+-------------+\n\nProducts table:\n+------------+--------------+------------+----------+-----------+\n| product_id | product_name | Width      | Length   | Height    |\n+------------+--------------+------------+----------+-----------+\n| 1          | LC-TV        | 5          | 50       | 40        |\n| 2          | LC-KeyChain  | 5          | 5        | 5         |\n| 3          | LC-Phone     | 2          | 10       | 10        |\n| 4          | LC-T-Shirt   | 4          | 10       | 20        |\n+------------+--------------+------------+----------+-----------+\n\nResult table:\n+----------------+------------+\n| warehouse_name | volume     | \n+----------------+------------+\n| LCHouse1       | 12250      | \n| LCHouse2       | 20250      |\n| LCHouse3       | 800        |\n+----------------+------------+\nVolume of product_id = 1 (LC-TV), 5x50x40 = 10000\nVolume of product_id = 2 (LC-KeyChain), 5x5x5 = 125 \nVolume of product_id = 3 (LC-Phone), 2x10x10 = 200\nVolume of product_id = 4 (LC-T-Shirt), 4x10x20 = 800\nLCHouse1: 1 unit of LC-TV + 10 units of LC-KeyChain + 5 units of LC-Phone.\n          Total volume: 1*10000 + 10*125  + 5*200 = 12250 cubic feet\nLCHouse2: 2 units of LC-TV + 2 units of LC-KeyChain.\n          Total volume: 2*10000 + 2*125 = 20250 cubic feet\nLCHouse3: 1 unit of LC-T-Shirt.\n          Total volume: 1*800 = 800 cubic feet.\n
    \n", "content_cn": "

    \u8868:\u00a0Warehouse

    \n\n
    \n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| name         | varchar |\n| product_id   | int     |\n| units        | int     |\n+--------------+---------+\n(name, product_id) \u662f\u8be5\u8868\u4e3b\u952e.\n\u8be5\u8868\u7684\u884c\u5305\u542b\u4e86\u6bcf\u4e2a\u4ed3\u5e93\u7684\u6240\u6709\u5546\u54c1\u4fe1\u606f.\n
    \n\n

    \u00a0

    \n\n

    \u8868: Products

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| product_id    | int     |\n| product_name  | varchar |\n| Width         | int     |\n| Length        | int     |\n| Height        | int     |\n+---------------+---------+\nproduct_id \u662f\u8be5\u8868\u4e3b\u952e.\n\u8be5\u8868\u7684\u884c\u5305\u542b\u4e86\u6bcf\u4ef6\u5546\u54c1\u4ee5\u82f1\u5c3a\u4e3a\u5355\u4f4d\u7684\u5c3a\u5bf8(\u5bbd\u5ea6, \u957f\u5ea6\u548c\u9ad8\u5ea6)\u4fe1\u606f.\n
    \n\n

    \u00a0

    \n\n

    \u5199\u4e00\u4e2a SQL\u00a0\u67e5\u8be2\u6765\u62a5\u544a,\u00a0\u6bcf\u4e2a\u4ed3\u5e93\u7684\u5b58\u8d27\u91cf\u662f\u591a\u5c11\u7acb\u65b9\u82f1\u5c3a.

    \n\n
      \n\t
    • \u4ed3\u5e93\u540d
    • \n\t
    • \u5b58\u8d27\u91cf
    • \n
    \n\n

    \u8fd4\u56de\u7ed3\u679c\u6ca1\u6709\u987a\u5e8f\u8981\u6c42.

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u5982\u4e0b\u4f8b\u6240\u793a.

    \n\n

    \u00a0

    \n\n
    \nWarehouse \u8868:\n+------------+--------------+-------------+\n| name       | product_id   | units       |\n+------------+--------------+-------------+\n| LCHouse1   | 1            | 1           |\n| LCHouse1   | 2            | 10          |\n| LCHouse1   | 3            | 5           |\n| LCHouse2   | 1            | 2           |\n| LCHouse2   | 2            | 2           |\n| LCHouse3   | 4            | 1           |\n+------------+--------------+-------------+\n\nProducts \u8868:\n+------------+--------------+------------+----------+-----------+\n| product_id | product_name | Width      | Length   | Height    |\n+------------+--------------+------------+----------+-----------+\n| 1          | LC-TV        | 5          | 50       | 40        |\n| 2          | LC-KeyChain  | 5          | 5        | 5         |\n| 3          | LC-Phone     | 2          | 10       | 10        |\n| 4          | LC-T-Shirt   | 4          | 10       | 20        |\n+------------+--------------+------------+----------+-----------+\n\nResult \u8868:\n+----------------+------------+\n| WAREHOUSE_NAME | VOLUME     | \n+----------------+------------+\n| LCHouse1       | 12250      | \n| LCHouse2       | 20250      |\n| LCHouse3       | 800        |\n+----------------+------------+\nId\u4e3a1\u7684\u5546\u54c1(LC-TV)\u7684\u5b58\u8d27\u91cf\u4e3a 5x50x40 = 10000\nId\u4e3a2\u7684\u5546\u54c1(LC-KeyChain)\u7684\u5b58\u8d27\u91cf\u4e3a 5x5x5 = 125 \nId\u4e3a3\u7684\u5546\u54c1(LC-Phone)\u7684\u5b58\u8d27\u91cf\u4e3a 2x10x10 = 200\nId\u4e3a4\u7684\u5546\u54c1(LC-T-Shirt)\u7684\u5b58\u8d27\u91cf\u4e3a 4x10x20 = 800\n\u4ed3\u5e93LCHouse1: 1\u4e2a\u5355\u4f4d\u7684LC-TV + 10\u4e2a\u5355\u4f4d\u7684LC-KeyChain + 5\u4e2a\u5355\u4f4d\u7684LC-Phone.\n\u00a0         \u603b\u5b58\u8d27\u91cf\u4e3a: 1*10000 + 10*125  + 5*200 = 12250 \u7acb\u65b9\u82f1\u5c3a\n\u4ed3\u5e93LCHouse2: 2\u4e2a\u5355\u4f4d\u7684LC-TV + 2\u4e2a\u5355\u4f4d\u7684LC-KeyChain.\n\u00a0         \u603b\u5b58\u8d27\u91cf\u4e3a: 2*10000 + 2*125 = 20250 \u7acb\u65b9\u82f1\u5c3a\n\u4ed3\u5e93LCHouse3: 1\u4e2a\u5355\u4f4d\u7684LC-T-Shirt.\n          \u603b\u5b58\u8d27\u91cf\u4e3a: 1*800 = 800 \u7acb\u65b9\u82f1\u5c3a.\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1571](https://leetcode-cn.com/problems/warehouse-manager)", "[\u4ed3\u5e93\u7ecf\u7406](/solution/1500-1599/1571.Warehouse%20Manager/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1571](https://leetcode.com/problems/warehouse-manager)", "[Warehouse Manager](/solution/1500-1599/1571.Warehouse%20Manager/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1717", "frontend_question_id": "1595", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-cost-to-connect-two-groups-of-points", "url_en": "https://leetcode.com/problems/minimum-cost-to-connect-two-groups-of-points", "relative_path_cn": "/solution/1500-1599/1595.Minimum%20Cost%20to%20Connect%20Two%20Groups%20of%20Points/README.md", "relative_path_en": "/solution/1500-1599/1595.Minimum%20Cost%20to%20Connect%20Two%20Groups%20of%20Points/README_EN.md", "title_cn": "\u8fde\u901a\u4e24\u7ec4\u70b9\u7684\u6700\u5c0f\u6210\u672c", "title_en": "Minimum Cost to Connect Two Groups of Points", "question_title_slug": "minimum-cost-to-connect-two-groups-of-points", "content_en": "

    You are given two groups of points where the first group has size1 points, the second group has size2 points, and size1 >= size2.

    \n\n

    The cost of the connection between any two points are given in an size1 x size2 matrix where cost[i][j] is the cost of connecting point i of the first group and point j of the second group. The groups are connected if each point in both groups is connected to one or more points in the opposite group. In other words, each point in the first group must be connected to at least one point in the second group, and each point in the second group must be connected to at least one point in the first group.

    \n\n

    Return the minimum cost it takes to connect the two groups.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: cost = [[15, 96], [36, 2]]\nOutput: 17\nExplanation: The optimal way of connecting the groups is:\n1--A\n2--B\nThis results in a total cost of 17.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: cost = [[1, 3, 5], [4, 1, 1], [1, 5, 3]]\nOutput: 4\nExplanation: The optimal way of connecting the groups is:\n1--A\n2--B\n2--C\n3--A\nThis results in a total cost of 4.\nNote that there are multiple points connected to point 2 in the first group and point A in the second group. This does not matter as there is no limit to the number of points that can be connected. We only care about the minimum total cost.\n
    \n\n

    Example 3:

    \n\n
    \nInput: cost = [[2, 5, 1], [3, 4, 7], [8, 1, 2], [6, 2, 4], [3, 8, 8]]\nOutput: 10\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • size1 == cost.length
    • \n\t
    • size2 == cost[i].length
    • \n\t
    • 1 <= size1, size2 <= 12
    • \n\t
    • size1 >= size2
    • \n\t
    • 0 <= cost[i][j] <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u7ec4\u70b9\uff0c\u5176\u4e2d\u7b2c\u4e00\u7ec4\u4e2d\u6709 size1 \u4e2a\u70b9\uff0c\u7b2c\u4e8c\u7ec4\u4e2d\u6709 size2 \u4e2a\u70b9\uff0c\u4e14 size1 >= size2 \u3002

    \n\n

    \u4efb\u610f\u4e24\u70b9\u95f4\u7684\u8fde\u63a5\u6210\u672c cost \u7531\u5927\u5c0f\u4e3a size1 x size2 \u77e9\u9635\u7ed9\u51fa\uff0c\u5176\u4e2d cost[i][j] \u662f\u7b2c\u4e00\u7ec4\u4e2d\u7684\u70b9 i \u548c\u7b2c\u4e8c\u7ec4\u4e2d\u7684\u70b9 j \u7684\u8fde\u63a5\u6210\u672c\u3002\u5982\u679c\u4e24\u4e2a\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u70b9\u90fd\u4e0e\u53e6\u4e00\u7ec4\u4e2d\u7684\u4e00\u4e2a\u6216\u591a\u4e2a\u70b9\u8fde\u63a5\uff0c\u5219\u79f0\u8fd9\u4e24\u7ec4\u70b9\u662f\u8fde\u901a\u7684\u3002\u6362\u8a00\u4e4b\uff0c\u7b2c\u4e00\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u70b9\u5fc5\u987b\u81f3\u5c11\u4e0e\u7b2c\u4e8c\u7ec4\u4e2d\u7684\u4e00\u4e2a\u70b9\u8fde\u63a5\uff0c\u4e14\u7b2c\u4e8c\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u70b9\u5fc5\u987b\u81f3\u5c11\u4e0e\u7b2c\u4e00\u7ec4\u4e2d\u7684\u4e00\u4e2a\u70b9\u8fde\u63a5\u3002

    \n\n

    \u8fd4\u56de\u8fde\u901a\u4e24\u7ec4\u70b9\u6240\u9700\u7684\u6700\u5c0f\u6210\u672c\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1acost = [[15, 96], [36, 2]]\n\u8f93\u51fa\uff1a17\n\u89e3\u91ca\uff1a\u8fde\u901a\u4e24\u7ec4\u70b9\u7684\u6700\u4f73\u65b9\u6cd5\u662f\uff1a\n1--A\n2--B\n\u603b\u6210\u672c\u4e3a 17 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1acost = [[1, 3, 5], [4, 1, 1], [1, 5, 3]]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u8fde\u901a\u4e24\u7ec4\u70b9\u7684\u6700\u4f73\u65b9\u6cd5\u662f\uff1a\n1--A\n2--B\n2--C\n3--A\n\u6700\u5c0f\u6210\u672c\u4e3a 4 \u3002\n\u8bf7\u6ce8\u610f\uff0c\u867d\u7136\u6709\u591a\u4e2a\u70b9\u8fde\u63a5\u5230\u7b2c\u4e00\u7ec4\u4e2d\u7684\u70b9 2 \u548c\u7b2c\u4e8c\u7ec4\u4e2d\u7684\u70b9 A \uff0c\u4f46\u7531\u4e8e\u9898\u76ee\u5e76\u4e0d\u9650\u5236\u8fde\u63a5\u70b9\u7684\u6570\u76ee\uff0c\u6240\u4ee5\u53ea\u9700\u8981\u5173\u5fc3\u6700\u4f4e\u603b\u6210\u672c\u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1acost = [[2, 5, 1], [3, 4, 7], [8, 1, 2], [6, 2, 4], [3, 8, 8]]\n\u8f93\u51fa\uff1a10\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • size1 == cost.length
    • \n\t
    • size2 == cost[i].length
    • \n\t
    • 1 <= size1, size2 <= 12
    • \n\t
    • size1 >= size2
    • \n\t
    • 0 <= cost[i][j] <= 100
    • \n
    \n", "tags_en": ["Graph", "Dynamic Programming"], "tags_cn": ["\u56fe", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int connectTwoGroups(vector>& cost) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int connectTwoGroups(List> cost) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def connectTwoGroups(self, cost):\n \"\"\"\n :type cost: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def connectTwoGroups(self, cost: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint connectTwoGroups(int** cost, int costSize, int* costColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ConnectTwoGroups(IList> cost) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} cost\n * @return {number}\n */\nvar connectTwoGroups = function(cost) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} cost\n# @return {Integer}\ndef connect_two_groups(cost)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func connectTwoGroups(_ cost: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func connectTwoGroups(cost [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def connectTwoGroups(cost: List[List[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun connectTwoGroups(cost: List>): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn connect_two_groups(cost: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $cost\n * @return Integer\n */\n function connectTwoGroups($cost) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function connectTwoGroups(cost: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (connect-two-groups cost)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1595](https://leetcode-cn.com/problems/minimum-cost-to-connect-two-groups-of-points)", "[\u8fde\u901a\u4e24\u7ec4\u70b9\u7684\u6700\u5c0f\u6210\u672c](/solution/1500-1599/1595.Minimum%20Cost%20to%20Connect%20Two%20Groups%20of%20Points/README.md)", "`\u56fe`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1595](https://leetcode.com/problems/minimum-cost-to-connect-two-groups-of-points)", "[Minimum Cost to Connect Two Groups of Points](/solution/1500-1599/1595.Minimum%20Cost%20to%20Connect%20Two%20Groups%20of%20Points/README_EN.md)", "`Graph`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "1716", "frontend_question_id": "1594", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-non-negative-product-in-a-matrix", "url_en": "https://leetcode.com/problems/maximum-non-negative-product-in-a-matrix", "relative_path_cn": "/solution/1500-1599/1594.Maximum%20Non%20Negative%20Product%20in%20a%20Matrix/README.md", "relative_path_en": "/solution/1500-1599/1594.Maximum%20Non%20Negative%20Product%20in%20a%20Matrix/README_EN.md", "title_cn": "\u77e9\u9635\u7684\u6700\u5927\u975e\u8d1f\u79ef", "title_en": "Maximum Non Negative Product in a Matrix", "question_title_slug": "maximum-non-negative-product-in-a-matrix", "content_en": "

    You are given a rows x cols matrix grid. Initially, you are located at the top-left corner (0, 0), and in each step, you can only move right or down in the matrix.

    \n\n

    Among all possible paths starting from the top-left corner (0, 0) and ending in the bottom-right corner (rows - 1, cols - 1), find the path with the maximum non-negative product. The product of a path is the product of all integers in the grid cells visited along the path.

    \n\n

    Return the maximum non-negative product modulo 109 + 7If the maximum product is negative return -1.

    \n\n

    Notice that the modulo is performed after getting the maximum product.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: grid = [[-1,-2,-3],\n               [-2,-3,-3],\n               [-3,-3,-2]]\nOutput: -1\nExplanation: It's not possible to get non-negative product in the path from (0, 0) to (2, 2), so return -1.\n
    \n\n

    Example 2:

    \n\n
    \nInput: grid = [[1,-2,1],\n               [1,-2,1],\n               [3,-4,1]]\nOutput: 8\nExplanation: Maximum non-negative product is in bold (1 * 1 * -2 * -4 * 1 = 8).\n
    \n\n

    Example 3:

    \n\n
    \nInput: grid = [[1, 3],\n               [0,-4]]\nOutput: 0\nExplanation: Maximum non-negative product is in bold (1 * 0 * -4 = 0).\n
    \n\n

    Example 4:

    \n\n
    \nInput: grid = [[ 1, 4,4,0],\n               [-2, 0,0,1],\n               [ 1,-1,1,1]]\nOutput: 2\nExplanation: Maximum non-negative product is in bold (1 * -2 * 1 * -1 * 1 * 1 = 2).\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= rows, cols <= 15
    • \n\t
    • -4 <= grid[i][j] <= 4
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5927\u5c0f\u4e3a rows x cols \u7684\u77e9\u9635 grid \u3002\u6700\u521d\uff0c\u4f60\u4f4d\u4e8e\u5de6\u4e0a\u89d2 (0, 0) \uff0c\u6bcf\u4e00\u6b65\uff0c\u4f60\u53ef\u4ee5\u5728\u77e9\u9635\u4e2d \u5411\u53f3 \u6216 \u5411\u4e0b \u79fb\u52a8\u3002

    \n\n

    \u5728\u4ece\u5de6\u4e0a\u89d2 (0, 0) \u5f00\u59cb\u5230\u53f3\u4e0b\u89d2 (rows - 1, cols - 1) \u7ed3\u675f\u7684\u6240\u6709\u8def\u5f84\u4e2d\uff0c\u627e\u51fa\u5177\u6709 \u6700\u5927\u975e\u8d1f\u79ef \u7684\u8def\u5f84\u3002\u8def\u5f84\u7684\u79ef\u662f\u6cbf\u8def\u5f84\u8bbf\u95ee\u7684\u5355\u5143\u683c\u4e2d\u6240\u6709\u6574\u6570\u7684\u4e58\u79ef\u3002

    \n\n

    \u8fd4\u56de \u6700\u5927\u975e\u8d1f\u79ef \u5bf9 109 + 7 \u53d6\u4f59 \u7684\u7ed3\u679c\u3002\u5982\u679c\u6700\u5927\u79ef\u4e3a\u8d1f\u6570\uff0c\u5219\u8fd4\u56de -1 \u3002

    \n\n

    \u6ce8\u610f\uff0c\u53d6\u4f59\u662f\u5728\u5f97\u5230\u6700\u5927\u79ef\u4e4b\u540e\u6267\u884c\u7684\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1agrid = [[-1,-2,-3],\n             [-2,-3,-3],\n             [-3,-3,-2]]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u4ece (0, 0) \u5230 (2, 2) \u7684\u8def\u5f84\u4e2d\u65e0\u6cd5\u5f97\u5230\u975e\u8d1f\u79ef\uff0c\u6240\u4ee5\u8fd4\u56de -1\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1agrid = [[1,-2,1],\n             [1,-2,1],\n             [3,-4,1]]\n\u8f93\u51fa\uff1a8\n\u89e3\u91ca\uff1a\u6700\u5927\u975e\u8d1f\u79ef\u5bf9\u5e94\u7684\u8def\u5f84\u5df2\u7ecf\u7528\u7c97\u4f53\u6807\u51fa (1 * 1 * -2 * -4 * 1 = 8)\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1agrid = [[1, 3],\n             [0,-4]]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6700\u5927\u975e\u8d1f\u79ef\u5bf9\u5e94\u7684\u8def\u5f84\u5df2\u7ecf\u7528\u7c97\u4f53\u6807\u51fa (1 * 0 * -4 = 0)\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1agrid = [[ 1, 4,4,0],\n             [-2, 0,0,1],\n             [ 1,-1,1,1]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6700\u5927\u975e\u8d1f\u79ef\u5bf9\u5e94\u7684\u8def\u5f84\u5df2\u7ecf\u7528\u7c97\u4f53\u6807\u51fa (1 * -2 * 1 * -1 * 1 * 1 = 2)\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= rows, cols <= 15
    • \n\t
    • -4 <= grid[i][j] <= 4
    • \n
    \n", "tags_en": ["Greedy", "Dynamic Programming"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxProductPath(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxProductPath(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxProductPath(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxProductPath(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxProductPath(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxProductPath(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar maxProductPath = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef max_product_path(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxProductPath(_ grid: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxProductPath(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxProductPath(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxProductPath(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_product_path(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function maxProductPath($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxProductPath(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-product-path grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1594](https://leetcode-cn.com/problems/maximum-non-negative-product-in-a-matrix)", "[\u77e9\u9635\u7684\u6700\u5927\u975e\u8d1f\u79ef](/solution/1500-1599/1594.Maximum%20Non%20Negative%20Product%20in%20a%20Matrix/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1594](https://leetcode.com/problems/maximum-non-negative-product-in-a-matrix)", "[Maximum Non Negative Product in a Matrix](/solution/1500-1599/1594.Maximum%20Non%20Negative%20Product%20in%20a%20Matrix/README_EN.md)", "`Greedy`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "1715", "frontend_question_id": "1593", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/split-a-string-into-the-max-number-of-unique-substrings", "url_en": "https://leetcode.com/problems/split-a-string-into-the-max-number-of-unique-substrings", "relative_path_cn": "/solution/1500-1599/1593.Split%20a%20String%20Into%20the%20Max%20Number%20of%20Unique%20Substrings/README.md", "relative_path_en": "/solution/1500-1599/1593.Split%20a%20String%20Into%20the%20Max%20Number%20of%20Unique%20Substrings/README_EN.md", "title_cn": "\u62c6\u5206\u5b57\u7b26\u4e32\u4f7f\u552f\u4e00\u5b50\u5b57\u7b26\u4e32\u7684\u6570\u76ee\u6700\u5927", "title_en": "Split a String Into the Max Number of Unique Substrings", "question_title_slug": "split-a-string-into-the-max-number-of-unique-substrings", "content_en": "

    Given a string s, return the maximum number of unique substrings that the given string can be split into.

    \n\n

    You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.

    \n\n

    A substring is a contiguous sequence of characters within a string.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "ababccc"\nOutput: 5\nExplanation: One way to split maximally is ['a', 'b', 'ab', 'c', 'cc']. Splitting like ['a', 'b', 'a', 'b', 'c', 'cc'] is not valid as you have 'a' and 'b' multiple times.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "aba"\nOutput: 2\nExplanation: One way to split maximally is ['a', 'ba'].\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "aa"\nOutput: 1\nExplanation: It is impossible to split the string any further.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • \n\t

      1 <= s.length <= 16

      \n\t
    • \n\t
    • \n\t

      s contains only lower case English letters.

      \n\t
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \uff0c\u8bf7\u4f60\u62c6\u5206\u8be5\u5b57\u7b26\u4e32\uff0c\u5e76\u8fd4\u56de\u62c6\u5206\u540e\u552f\u4e00\u5b50\u5b57\u7b26\u4e32\u7684\u6700\u5927\u6570\u76ee\u3002

    \n\n

    \u5b57\u7b26\u4e32 s \u62c6\u5206\u540e\u53ef\u4ee5\u5f97\u5230\u82e5\u5e72 \u975e\u7a7a\u5b50\u5b57\u7b26\u4e32 \uff0c\u8fd9\u4e9b\u5b50\u5b57\u7b26\u4e32\u8fde\u63a5\u540e\u5e94\u5f53\u80fd\u591f\u8fd8\u539f\u4e3a\u539f\u5b57\u7b26\u4e32\u3002\u4f46\u662f\u62c6\u5206\u51fa\u6765\u7684\u6bcf\u4e2a\u5b50\u5b57\u7b26\u4e32\u90fd\u5fc5\u987b\u662f \u552f\u4e00\u7684 \u3002

    \n\n

    \u6ce8\u610f\uff1a\u5b50\u5b57\u7b26\u4e32 \u662f\u5b57\u7b26\u4e32\u4e2d\u7684\u4e00\u4e2a\u8fde\u7eed\u5b57\u7b26\u5e8f\u5217\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1as = "ababccc"\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u4e00\u79cd\u6700\u5927\u62c6\u5206\u65b9\u6cd5\u4e3a ['a', 'b', 'ab', 'c', 'cc'] \u3002\u50cf ['a', 'b', 'a', 'b', 'c', 'cc'] \u8fd9\u6837\u62c6\u5206\u4e0d\u6ee1\u8db3\u9898\u76ee\u8981\u6c42\uff0c\u56e0\u4e3a\u5176\u4e2d\u7684 'a' \u548c 'b' \u90fd\u51fa\u73b0\u4e86\u4e0d\u6b62\u4e00\u6b21\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1as = "aba"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u4e00\u79cd\u6700\u5927\u62c6\u5206\u65b9\u6cd5\u4e3a ['a', 'ba'] \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1as = "aa"\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u65e0\u6cd5\u8fdb\u4e00\u6b65\u62c6\u5206\u5b57\u7b26\u4e32\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \n\t

      1 <= s.length <= 16

      \n\t
    • \n\t
    • \n\t

      s \u4ec5\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd

      \n\t
    • \n
    \n", "tags_en": ["Backtracking"], "tags_cn": ["\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxUniqueSplit(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxUniqueSplit(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxUniqueSplit(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxUniqueSplit(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxUniqueSplit(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxUniqueSplit(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar maxUniqueSplit = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef max_unique_split(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxUniqueSplit(_ s: String) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxUniqueSplit(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxUniqueSplit(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxUniqueSplit(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_unique_split(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function maxUniqueSplit($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxUniqueSplit(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-unique-split s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1593](https://leetcode-cn.com/problems/split-a-string-into-the-max-number-of-unique-substrings)", "[\u62c6\u5206\u5b57\u7b26\u4e32\u4f7f\u552f\u4e00\u5b50\u5b57\u7b26\u4e32\u7684\u6570\u76ee\u6700\u5927](/solution/1500-1599/1593.Split%20a%20String%20Into%20the%20Max%20Number%20of%20Unique%20Substrings/README.md)", "`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1593](https://leetcode.com/problems/split-a-string-into-the-max-number-of-unique-substrings)", "[Split a String Into the Max Number of Unique Substrings](/solution/1500-1599/1593.Split%20a%20String%20Into%20the%20Max%20Number%20of%20Unique%20Substrings/README_EN.md)", "`Backtracking`", "Medium", ""]}, {"question_id": "1714", "frontend_question_id": "1592", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/rearrange-spaces-between-words", "url_en": "https://leetcode.com/problems/rearrange-spaces-between-words", "relative_path_cn": "/solution/1500-1599/1592.Rearrange%20Spaces%20Between%20Words/README.md", "relative_path_en": "/solution/1500-1599/1592.Rearrange%20Spaces%20Between%20Words/README_EN.md", "title_cn": "\u91cd\u65b0\u6392\u5217\u5355\u8bcd\u95f4\u7684\u7a7a\u683c", "title_en": "Rearrange Spaces Between Words", "question_title_slug": "rearrange-spaces-between-words", "content_en": "

    You are given a string text of words that are placed among some number of spaces. Each word consists of one or more lowercase English letters and are separated by at least one space. It's guaranteed that text contains at least one word.

    \n\n

    Rearrange the spaces so that there is an equal number of spaces between every pair of adjacent words and that number is maximized. If you cannot redistribute all the spaces equally, place the extra spaces at the end, meaning the returned string should be the same length as text.

    \n\n

    Return the string after rearranging the spaces.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: text = "  this   is  a sentence "\nOutput: "this   is   a   sentence"\nExplanation: There are a total of 9 spaces and 4 words. We can evenly divide the 9 spaces between the words: 9 / (4-1) = 3 spaces.\n
    \n\n

    Example 2:

    \n\n
    \nInput: text = " practice   makes   perfect"\nOutput: "practice   makes   perfect "\nExplanation: There are a total of 7 spaces and 3 words. 7 / (3-1) = 3 spaces plus 1 extra space. We place this extra space at the end of the string.\n
    \n\n

    Example 3:

    \n\n
    \nInput: text = "hello   world"\nOutput: "hello   world"\n
    \n\n

    Example 4:

    \n\n
    \nInput: text = "  walks  udp package   into  bar a"\nOutput: "walks  udp  package  into  bar  a "\n
    \n\n

    Example 5:

    \n\n
    \nInput: text = "a"\nOutput: "a"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= text.length <= 100
    • \n\t
    • text consists of lowercase English letters and ' '.
    • \n\t
    • text contains at least one word.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 text \uff0c\u8be5\u5b57\u7b26\u4e32\u7531\u82e5\u5e72\u88ab\u7a7a\u683c\u5305\u56f4\u7684\u5355\u8bcd\u7ec4\u6210\u3002\u6bcf\u4e2a\u5355\u8bcd\u7531\u4e00\u4e2a\u6216\u8005\u591a\u4e2a\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\uff0c\u5e76\u4e14\u4e24\u4e2a\u5355\u8bcd\u4e4b\u95f4\u81f3\u5c11\u5b58\u5728\u4e00\u4e2a\u7a7a\u683c\u3002\u9898\u76ee\u6d4b\u8bd5\u7528\u4f8b\u4fdd\u8bc1 text \u81f3\u5c11\u5305\u542b\u4e00\u4e2a\u5355\u8bcd \u3002

    \n\n

    \u8bf7\u4f60\u91cd\u65b0\u6392\u5217\u7a7a\u683c\uff0c\u4f7f\u6bcf\u5bf9\u76f8\u90bb\u5355\u8bcd\u4e4b\u95f4\u7684\u7a7a\u683c\u6570\u76ee\u90fd \u76f8\u7b49 \uff0c\u5e76\u5c3d\u53ef\u80fd \u6700\u5927\u5316 \u8be5\u6570\u76ee\u3002\u5982\u679c\u4e0d\u80fd\u91cd\u65b0\u5e73\u5747\u5206\u914d\u6240\u6709\u7a7a\u683c\uff0c\u8bf7 \u5c06\u591a\u4f59\u7684\u7a7a\u683c\u653e\u7f6e\u5728\u5b57\u7b26\u4e32\u672b\u5c3e \uff0c\u8fd9\u4e5f\u610f\u5473\u7740\u8fd4\u56de\u7684\u5b57\u7b26\u4e32\u5e94\u5f53\u4e0e\u539f text \u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u76f8\u7b49\u3002

    \n\n

    \u8fd4\u56de \u91cd\u65b0\u6392\u5217\u7a7a\u683c\u540e\u7684\u5b57\u7b26\u4e32 \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1atext = "  this   is  a sentence "\n\u8f93\u51fa\uff1a"this   is   a   sentence"\n\u89e3\u91ca\uff1a\u603b\u5171\u6709 9 \u4e2a\u7a7a\u683c\u548c 4 \u4e2a\u5355\u8bcd\u3002\u53ef\u4ee5\u5c06 9 \u4e2a\u7a7a\u683c\u5e73\u5747\u5206\u914d\u5230\u76f8\u90bb\u5355\u8bcd\u4e4b\u95f4\uff0c\u76f8\u90bb\u5355\u8bcd\u95f4\u7a7a\u683c\u6570\u4e3a\uff1a9 / (4-1) = 3 \u4e2a\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1atext = " practice   makes   perfect"\n\u8f93\u51fa\uff1a"practice   makes   perfect "\n\u89e3\u91ca\uff1a\u603b\u5171\u6709 7 \u4e2a\u7a7a\u683c\u548c 3 \u4e2a\u5355\u8bcd\u30027 / (3-1) = 3 \u4e2a\u7a7a\u683c\u52a0\u4e0a 1 \u4e2a\u591a\u4f59\u7684\u7a7a\u683c\u3002\u591a\u4f59\u7684\u7a7a\u683c\u9700\u8981\u653e\u5728\u5b57\u7b26\u4e32\u7684\u672b\u5c3e\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1atext = "hello   world"\n\u8f93\u51fa\uff1a"hello   world"\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1atext = "  walks  udp package   into  bar a"\n\u8f93\u51fa\uff1a"walks  udp  package  into  bar  a "\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1atext = "a"\n\u8f93\u51fa\uff1a"a"\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= text.length <= 100
    • \n\t
    • text \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u548c ' ' \u7ec4\u6210
    • \n\t
    • text \u4e2d\u81f3\u5c11\u5305\u542b\u4e00\u4e2a\u5355\u8bcd
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string reorderSpaces(string text) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String reorderSpaces(String text) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def reorderSpaces(self, text):\n \"\"\"\n :type text: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def reorderSpaces(self, text: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * reorderSpaces(char * text){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ReorderSpaces(string text) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} text\n * @return {string}\n */\nvar reorderSpaces = function(text) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} text\n# @return {String}\ndef reorder_spaces(text)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func reorderSpaces(_ text: String) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func reorderSpaces(text string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def reorderSpaces(text: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun reorderSpaces(text: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn reorder_spaces(text: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $text\n * @return String\n */\n function reorderSpaces($text) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function reorderSpaces(text: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (reorder-spaces text)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1592](https://leetcode-cn.com/problems/rearrange-spaces-between-words)", "[\u91cd\u65b0\u6392\u5217\u5355\u8bcd\u95f4\u7684\u7a7a\u683c](/solution/1500-1599/1592.Rearrange%20Spaces%20Between%20Words/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1592](https://leetcode.com/problems/rearrange-spaces-between-words)", "[Rearrange Spaces Between Words](/solution/1500-1599/1592.Rearrange%20Spaces%20Between%20Words/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1713", "frontend_question_id": "1570", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/dot-product-of-two-sparse-vectors", "url_en": "https://leetcode.com/problems/dot-product-of-two-sparse-vectors", "relative_path_cn": "/solution/1500-1599/1570.Dot%20Product%20of%20Two%20Sparse%20Vectors/README.md", "relative_path_en": "/solution/1500-1599/1570.Dot%20Product%20of%20Two%20Sparse%20Vectors/README_EN.md", "title_cn": "\u4e24\u4e2a\u7a00\u758f\u5411\u91cf\u7684\u70b9\u79ef", "title_en": "Dot Product of Two Sparse Vectors", "question_title_slug": "dot-product-of-two-sparse-vectors", "content_en": "

    Given two sparse vectors, compute their dot product.

    \n\n

    Implement class SparseVector:

    \n\n
      \n\t
    • SparseVector(nums) Initializes the object with the vector nums
    • \n\t
    • dotProduct(vec) Compute the dot product between the instance of SparseVector and vec
    • \n
    \n\n

    A sparse vector is a vector that has mostly zero values, you should store the sparse vector efficiently and compute the dot product between two SparseVector.

    \n\n

    Follow up: What if only one of the vectors is sparse?

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums1 = [1,0,0,2,3], nums2 = [0,3,0,4,0]\nOutput: 8\nExplanation: v1 = SparseVector(nums1) , v2 = SparseVector(nums2)\nv1.dotProduct(v2) = 1*0 + 0*3 + 0*0 + 2*4 + 3*0 = 8\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums1 = [0,1,0,0,0], nums2 = [0,0,0,0,2]\nOutput: 0\nExplanation: v1 = SparseVector(nums1) , v2 = SparseVector(nums2)\nv1.dotProduct(v2) = 0*0 + 1*0 + 0*0 + 0*0 + 0*2 = 0\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums1 = [0,1,0,0,2,0,0], nums2 = [1,0,0,0,3,0,4]\nOutput: 6\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == nums1.length == nums2.length
    • \n\t
    • 1 <= n <= 10^5
    • \n\t
    • 0 <= nums1[i], nums2[i] <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u7a00\u758f\u5411\u91cf\uff0c\u8ba1\u7b97\u5b83\u4eec\u7684\u70b9\u79ef\uff08\u6570\u91cf\u79ef\uff09\u3002

    \n\n

    \u5b9e\u73b0\u7c7b\u00a0SparseVector\uff1a

    \n\n
      \n\t
    • SparseVector(nums)\u00a0\u4ee5\u5411\u91cf\u00a0nums\u00a0\u521d\u59cb\u5316\u5bf9\u8c61\u3002
    • \n\t
    • dotProduct(vec)\u00a0\u8ba1\u7b97\u6b64\u5411\u91cf\u4e0e\u00a0vec\u00a0\u7684\u70b9\u79ef\u3002
    • \n
    \n\n

    \u7a00\u758f\u5411\u91cf \u662f\u6307\u7edd\u5927\u591a\u6570\u5206\u91cf\u4e3a 0 \u7684\u5411\u91cf\u3002\u4f60\u9700\u8981 \u9ad8\u6548 \u5730\u5b58\u50a8\u8fd9\u4e2a\u5411\u91cf\uff0c\u5e76\u8ba1\u7b97\u4e24\u4e2a\u7a00\u758f\u5411\u91cf\u7684\u70b9\u79ef\u3002

    \n\n

    \u8fdb\u9636\uff1a\u5f53\u5176\u4e2d\u53ea\u6709\u4e00\u4e2a\u5411\u91cf\u662f\u7a00\u758f\u5411\u91cf\u65f6\uff0c\u4f60\u8be5\u5982\u4f55\u89e3\u51b3\u6b64\u95ee\u9898\uff1f

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums1 = [1,0,0,2,3], nums2 = [0,3,0,4,0]\n\u8f93\u51fa\uff1a8\n\u89e3\u91ca\uff1av1 = SparseVector(nums1) , v2 = SparseVector(nums2)\nv1.dotProduct(v2) = 1*0 + 0*3 + 0*0 + 2*4 + 3*0 = 8\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums1 = [0,1,0,0,0], nums2 = [0,0,0,0,2]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1av1 = SparseVector(nums1) , v2 = SparseVector(nums2)\nv1.dotProduct(v2) = 0*0 + 1*0 + 0*0 + 0*0 + 0*2 = 0\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums1 = [0,1,0,0,2,0,0], nums2 = [1,0,0,0,3,0,4]\n\u8f93\u51fa\uff1a6\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == nums1.length == nums2.length
    • \n\t
    • 1 <= n <= 10^5
    • \n\t
    • 0 <= nums1[i], nums2[i]\u00a0<= 100
    • \n
    \n", "tags_en": ["Array", "Hash Table", "Two Pointers"], "tags_cn": ["\u6570\u7ec4", "\u54c8\u5e0c\u8868", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class SparseVector {\npublic:\n \n SparseVector(vector &nums) {\n \n }\n \n // Return the dotProduct of two sparse vectors\n int dotProduct(SparseVector& vec) {\n \n }\n};\n\n// Your SparseVector object will be instantiated and called as such:\n// SparseVector v1(nums1);\n// SparseVector v2(nums2);\n// int ans = v1.dotProduct(v2);", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class SparseVector {\n \n SparseVector(int[] nums) {\n \n }\n \n\t// Return the dotProduct of two sparse vectors\n public int dotProduct(SparseVector vec) {\n \n }\n}\n\n// Your SparseVector object will be instantiated and called as such:\n// SparseVector v1 = new SparseVector(nums1);\n// SparseVector v2 = new SparseVector(nums2);\n// int ans = v1.dotProduct(v2);", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class SparseVector:\n def __init__(self, nums):\n \"\"\"\n :type nums: List[int]\n \"\"\"\n \n\n # Return the dotProduct of two sparse vectors\n def dotProduct(self, vec):\n \"\"\"\n :type vec: 'SparseVector'\n :rtype: int\n \"\"\"\n \n\n# Your SparseVector object will be instantiated and called as such:\n# v1 = SparseVector(nums1)\n# v2 = SparseVector(nums2)\n# ans = v1.dotProduct(v2)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class SparseVector:\n def __init__(self, nums: List[int]):\n \n\n # Return the dotProduct of two sparse vectors\n def dotProduct(self, vec: 'SparseVector') -> int:\n \n\n# Your SparseVector object will be instantiated and called as such:\n# v1 = SparseVector(nums1)\n# v2 = SparseVector(nums2)\n# ans = v1.dotProduct(v2)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} SparseVector;\n\n\nSparseVector* sparseVectorCreate(int* nums, int numsSize) {\n \n}\n\n// Return the dotProduct of two sparse vectors\nint sparseVectordotProduct(SparseVector* obj, SparseVector* vec) {\n \n}\n\n/**\n * Your SparseVector struct will be instantiated and called as such:\n * SparseVector* v1 = sparseVectorCreate(nums1, nums1Size);\n * SparseVector* v2 = sparseVectorCreate(nums2, nums2Size);\n * int ans = sparseVectordotProduct(v1, v2);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class SparseVector {\n \n SparseVector(int[] nums) {\n \n }\n \n // Return the dotProduct of two sparse vectors\n public int DotProduct(SparseVector vec) {\n \n }\n}\n\n// Your SparseVector object will be instantiated and called as such:\n// SparseVector v1 = new SparseVector(nums1);\n// SparseVector v2 = new SparseVector(nums2);\n// int ans = v1.DotProduct(v2);", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {SparseVector}\n */\nvar SparseVector = function(nums) {\n \n};\n\n// Return the dotProduct of two sparse vectors\n/**\n * @param {SparseVector} vec\n * @return {number}\n */\nSparseVector.prototype.dotProduct = function(vec) {\n \n};\n\n// Your SparseVector object will be instantiated and called as such:\n// let v1 = new SparseVector(nums1);\n// let v2 = new SparseVector(nums2);\n// let ans = v1.dotProduct(v2);", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class SparseVector\n\n=begin\n :type nums: Integer[]\n=end\n def initialize(nums)\n \n end\n\n# Return the dotProduct of two sparse vectors\n=begin\n :type vec: SparseVector\n :rtype: Integer\n=end\n def dotProduct(vec)\n \n end\nend\n\n# Your SparseVector object will be instantiated and called as such:\n# v1 = SparseVector.new(nums1)\n# v2 = SparseVector.new(nums2)\n# ans = v1.dotProduct(v2)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass SparseVector {\n \n init(_ nums: [Int]) {\n \n }\n\n // Return the dotProduct of two sparse vectors\n func dotProduct(_ vec: SparseVector) -> Int {\n \n }\n}\n\n/**\n * Your SparseVector object will be instantiated and called as such:\n * let v1 = SparseVector(nums1)\n * let v2 = SparseVector(nums2)\n * let ans = v1.dotProduct(v2)\n*/", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type SparseVector struct {\n \n}\n\nfunc Constructor(nums []int) SparseVector {\n \n}\n\n// Return the dotProduct of two sparse vectors\nfunc (this *SparseVector) dotProduct(vec SparseVector) int {\n \n}\n\n/**\n * Your SparseVector object will be instantiated and called as such:\n * v1 := Constructor(nums1);\n * v2 := Constructor(nums2);\n * ans := v1.dotProduct(v2);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class SparseVector(nums: Array[Int]) {\n // Return the dotProduct of two sparse vectors\n def dotProduct(vec: SparseVector): Int = {\n \n }\n}\n\n/**\n * Your SparseVector object will be instantiated and called as such:\n * var v1 = new SparseVector(nums1)\n * var v2 = new SparseVector(nums2)\n * val ans = v1.dotProduct(v2)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class SparseVector(nums: IntArray) {\n // Return the dotProduct of two sparse vectors\n fun dotProduct(vec: SparseVector): Int {\n \n }\n}\n\n/**\n * Your SparseVector object will be instantiated and called as such:\n * var v1 = SparseVector(nums1)\n * var v2 = SparseVector(nums2)\n * val ans = v1.dotProduct(v2)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct SparseVector {\n\t\n}\n\n/** \n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl SparseVector {\n fn new(nums: Vec) -> Self {\n \n }\n\t\n // Return the dotProduct of two sparse vectors\n fn dot_product(&self, vec: SparseVector) -> i32 {\n \n }\n}\n\n/**\n * Your SparseVector object will be instantiated and called as such:\n * let v1 = SparseVector::new(nums1);\n * let v2 = SparseVector::new(nums2);\n * let ans = v1.dot_product(v2);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class SparseVector {\n /**\n * @param Integer[] $nums\n */\n function __construct($nums) {\n \n }\n \n // Return the dotProduct of two sparse vectors\n /**\n * @param SparseVector $vec\n * @return Integer\n */\n function dotProduct($vec) {\n \n }\n}\n\n/**\n * Your SparseVector object will be instantiated and called as such:\n * $v1 = new SparseVector($nums1);\n * $v2 = new SparseVector($nums2);\n * $ans = $v1->dotProduct($v2);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class SparseVector {\n constructor(nums: number[]) {\n\t\t\n }\n\n\t// Return the dotProduct of two sparse vectors\n dotProduct(vec: SparseVector): number {\n\t\t\n }\n}\n\n/**\n * Your SparseVector object will be instantiated and called as such:\n * var v1 = new SparseVector(nums1)\n * var v2 = new SparseVector(nums1)\n * var ans = v1.dotProduct(v2)\n */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1570](https://leetcode-cn.com/problems/dot-product-of-two-sparse-vectors)", "[\u4e24\u4e2a\u7a00\u758f\u5411\u91cf\u7684\u70b9\u79ef](/solution/1500-1599/1570.Dot%20Product%20of%20Two%20Sparse%20Vectors/README.md)", "`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1570](https://leetcode.com/problems/dot-product-of-two-sparse-vectors)", "[Dot Product of Two Sparse Vectors](/solution/1500-1599/1570.Dot%20Product%20of%20Two%20Sparse%20Vectors/README_EN.md)", "`Array`,`Hash Table`,`Two Pointers`", "Medium", "\ud83d\udd12"]}, {"question_id": "1712", "frontend_question_id": "1565", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/unique-orders-and-customers-per-month", "url_en": "https://leetcode.com/problems/unique-orders-and-customers-per-month", "relative_path_cn": "/solution/1500-1599/1565.Unique%20Orders%20and%20Customers%20Per%20Month/README.md", "relative_path_en": "/solution/1500-1599/1565.Unique%20Orders%20and%20Customers%20Per%20Month/README_EN.md", "title_cn": "\u6309\u6708\u7edf\u8ba1\u8ba2\u5355\u6570\u4e0e\u987e\u5ba2\u6570", "title_en": "Unique Orders and Customers Per Month", "question_title_slug": "unique-orders-and-customers-per-month", "content_en": "

    Table: Orders

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| order_id      | int     |\n| order_date    | date    |\n| customer_id   | int     |\n| invoice       | int     |\n+---------------+---------+\norder_id is the primary key for this table.\nThis table contains information about the orders made by customer_id.\n
    \n\n

     

    \n\n

    Write an SQL query to find the number of unique orders and the number of unique customers with invoices > $20 for each different month.

    \n\n

    Return the result table sorted in any order.

    \n\n

    The query result format is in the following example:

    \n\n
    \nOrders\n+----------+------------+-------------+------------+\n| order_id | order_date | customer_id | invoice    |\n+----------+------------+-------------+------------+\n| 1        | 2020-09-15 | 1           | 30         |\n| 2        | 2020-09-17 | 2           | 90         |\n| 3        | 2020-10-06 | 3           | 20         |\n| 4        | 2020-10-20 | 3           | 21         |\n| 5        | 2020-11-10 | 1           | 10         |\n| 6        | 2020-11-21 | 2           | 15         |\n| 7        | 2020-12-01 | 4           | 55         |\n| 8        | 2020-12-03 | 4           | 77         |\n| 9        | 2021-01-07 | 3           | 31         |\n| 10       | 2021-01-15 | 2           | 20         |\n+----------+------------+-------------+------------+\n\nResult table:\n+---------+-------------+----------------+\n| month   | order_count | customer_count |\n+---------+-------------+----------------+\n| 2020-09 | 2           | 2              |\n| 2020-10 | 1           | 1              |\n| 2020-12 | 2           | 1              |\n| 2021-01 | 1           | 1              |\n+---------+-------------+----------------+\nIn September 2020 we have two orders from 2 different customers with invoices > $20.\nIn October 2020 we have two orders from 1 customer, and only one of the two orders has invoice > $20.\nIn November 2020 we have two orders from 2 different customers but invoices < $20, so we don't include that month.\nIn December 2020 we have two orders from 1 customer both with invoices > $20.\nIn January 2021 we have two orders from 2 different customers, but only one of them with invoice > $20.\n
    \n", "content_cn": "

    \u8868\uff1aOrders

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| order_id      | int     |\n| order_date    | date    |\n| customer_id   | int     |\n| invoice       | int     |\n+---------------+---------+\norder_id \u662f Orders \u8868\u7684\u4e3b\u952e\u3002\n\u8fd9\u5f20\u8868\u5305\u542b\u987e\u5ba2(customer_id)\u6240\u4e0b\u8ba2\u5355\u7684\u4fe1\u606f\u3002\n
    \n\n

    \u5199\u4e00\u4e2a\u67e5\u8be2\u8bed\u53e5\u6765 \u6309\u6708 \u7edf\u8ba1 \u91d1\u989d\u5927\u4e8e $20 \u7684\u552f\u4e00 \u8ba2\u5355\u6570 \u548c\u552f\u4e00 \u987e\u5ba2\u6570 \u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u65e0\u6392\u5e8f\u8981\u6c42\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u9762\u4f8b\u5b50\u6240\u793a\uff1a

    \n\n
    \nOrders\n+----------+------------+-------------+------------+\n| order_id | order_date | customer_id | invoice    |\n+----------+------------+-------------+------------+\n| 1        | 2020-09-15 | 1           | 30         |\n| 2        | 2020-09-17 | 2           | 90         |\n| 3        | 2020-10-06 | 3           | 20         |\n| 4        | 2020-10-20 | 3           | 21         |\n| 5        | 2020-11-10 | 1           | 10         |\n| 6        | 2020-11-21 | 2           | 15         |\n| 7        | 2020-12-01 | 4           | 55         |\n| 8        | 2020-12-03 | 4           | 77         |\n| 9        | 2021-01-07 | 3           | 31         |\n| 10       | 2021-01-15 | 2           | 20         |\n+----------+------------+-------------+------------+\n\nResult \u8868\uff1a\n+---------+-------------+----------------+\n| month   | order_count | customer_count |\n+---------+-------------+----------------+\n| 2020-09 | 2           | 2              |\n| 2020-10 | 1           | 1              |\n| 2020-12 | 2           | 1              |\n| 2021-01 | 1           | 1              |\n+---------+-------------+----------------+\n\u5728 2020 \u5e74 09 \u6708\uff0c\u6709 2 \u4efd\u6765\u81ea 2 \u4f4d\u4e0d\u540c\u987e\u5ba2\u7684\u91d1\u989d\u5927\u4e8e $20 \u7684\u8ba2\u5355\u3002\n\u5728 2020 \u5e74 10 \u6708\uff0c\u6709 2 \u4efd\u6765\u81ea 1 \u4f4d\u987e\u5ba2\u7684\u8ba2\u5355\uff0c\u5e76\u4e14\u53ea\u6709\u5176\u4e2d\u7684 1 \u4efd\u8ba2\u5355\u91d1\u989d\u5927\u4e8e $20 \u3002\n\u5728 2020 \u5e74 11 \u6708\uff0c\u6709 2 \u4efd\u6765\u81ea 2 \u4f4d\u4e0d\u540c\u987e\u5ba2\u7684\u8ba2\u5355\uff0c\u4f46\u7531\u4e8e\u91d1\u989d\u90fd\u5c0f\u4e8e $20 \uff0c\u6240\u4ee5\u6211\u4eec\u7684\u67e5\u8be2\u7ed3\u679c\u4e2d\u4e0d\u5305\u542b\u8fd9\u4e2a\u6708\u7684\u6570\u636e\u3002\n\u5728 2020 \u5e74 12 \u6708\uff0c\u6709 2 \u4efd\u6765\u81ea 1 \u4f4d\u987e\u5ba2\u7684\u8ba2\u5355\uff0c\u4e14 2 \u4efd\u8ba2\u5355\u91d1\u989d\u90fd\u5927\u4e8e $20 \u3002\n\u5728 2021 \u5e74 01 \u6708\uff0c\u6709 2 \u4efd\u6765\u81ea 2 \u4f4d\u4e0d\u540c\u987e\u5ba2\u7684\u8ba2\u5355\uff0c\u4f46\u53ea\u6709\u5176\u4e2d\u4e00\u4efd\u8ba2\u5355\u91d1\u989d\u5927\u4e8e $20 \u3002\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1565](https://leetcode-cn.com/problems/unique-orders-and-customers-per-month)", "[\u6309\u6708\u7edf\u8ba1\u8ba2\u5355\u6570\u4e0e\u987e\u5ba2\u6570](/solution/1500-1599/1565.Unique%20Orders%20and%20Customers%20Per%20Month/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1565](https://leetcode.com/problems/unique-orders-and-customers-per-month)", "[Unique Orders and Customers Per Month](/solution/1500-1599/1565.Unique%20Orders%20and%20Customers%20Per%20Month/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1711", "frontend_question_id": "1605", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-valid-matrix-given-row-and-column-sums", "url_en": "https://leetcode.com/problems/find-valid-matrix-given-row-and-column-sums", "relative_path_cn": "/solution/1600-1699/1605.Find%20Valid%20Matrix%20Given%20Row%20and%20Column%20Sums/README.md", "relative_path_en": "/solution/1600-1699/1605.Find%20Valid%20Matrix%20Given%20Row%20and%20Column%20Sums/README_EN.md", "title_cn": "\u7ed9\u5b9a\u884c\u548c\u5217\u7684\u548c\u6c42\u53ef\u884c\u77e9\u9635", "title_en": "Find Valid Matrix Given Row and Column Sums", "question_title_slug": "find-valid-matrix-given-row-and-column-sums", "content_en": "

    You are given two arrays rowSum and colSum of non-negative integers where rowSum[i] is the sum of the elements in the ith row and colSum[j] is the sum of the elements of the jth column of a 2D matrix. In other words, you do not know the elements of the matrix, but you do know the sums of each row and column.

    \n\n

    Find any matrix of non-negative integers of size rowSum.length x colSum.length that satisfies the rowSum and colSum requirements.

    \n\n

    Return a 2D array representing any matrix that fulfills the requirements. It's guaranteed that at least one matrix that fulfills the requirements exists.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: rowSum = [3,8], colSum = [4,7]\nOutput: [[3,0],\n         [1,7]]\nExplanation:\n0th row: 3 + 0 = 3 == rowSum[0]\n1st row: 1 + 7 = 8 == rowSum[1]\n0th column: 3 + 1 = 4 == colSum[0]\n1st column: 0 + 7 = 7 == colSum[1]\nThe row and column sums match, and all matrix elements are non-negative.\nAnother possible matrix is: [[1,2],\n                             [3,5]]\n
    \n\n

    Example 2:

    \n\n
    \nInput: rowSum = [5,7,10], colSum = [8,6,8]\nOutput: [[0,5,0],\n         [6,1,0],\n         [2,0,8]]\n
    \n\n

    Example 3:

    \n\n
    \nInput: rowSum = [14,9], colSum = [6,9,8]\nOutput: [[0,9,5],\n         [6,0,3]]\n
    \n\n

    Example 4:

    \n\n
    \nInput: rowSum = [1,0], colSum = [1]\nOutput: [[1],\n         [0]]\n
    \n\n

    Example 5:

    \n\n
    \nInput: rowSum = [0], colSum = [0]\nOutput: [[0]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= rowSum.length, colSum.length <= 500
    • \n\t
    • 0 <= rowSum[i], colSum[i] <= 108
    • \n\t
    • sum(rows) == sum(columns)
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u975e\u8d1f\u6574\u6570\u6570\u7ec4\u00a0rowSum \u548c\u00a0colSum\u00a0\uff0c\u5176\u4e2d\u00a0rowSum[i]\u00a0\u662f\u4e8c\u7ef4\u77e9\u9635\u4e2d\u7b2c i\u00a0\u884c\u5143\u7d20\u7684\u548c\uff0c colSum[j]\u00a0\u662f\u7b2c j\u00a0\u5217\u5143\u7d20\u7684\u548c\u3002\u6362\u8a00\u4e4b\u4f60\u4e0d\u77e5\u9053\u77e9\u9635\u91cc\u7684\u6bcf\u4e2a\u5143\u7d20\uff0c\u4f46\u662f\u4f60\u77e5\u9053\u6bcf\u4e00\u884c\u548c\u6bcf\u4e00\u5217\u7684\u548c\u3002

    \n\n

    \u8bf7\u627e\u5230\u5927\u5c0f\u4e3a\u00a0rowSum.length x colSum.length\u00a0\u7684\u4efb\u610f \u975e\u8d1f\u6574\u6570\u00a0\u77e9\u9635\uff0c\u4e14\u8be5\u77e9\u9635\u6ee1\u8db3\u00a0rowSum \u548c\u00a0colSum\u00a0\u7684\u8981\u6c42\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u4efb\u610f\u4e00\u4e2a\u6ee1\u8db3\u9898\u76ee\u8981\u6c42\u7684\u4e8c\u7ef4\u77e9\u9635\uff0c\u9898\u76ee\u4fdd\u8bc1\u5b58\u5728 \u81f3\u5c11\u4e00\u4e2a\u00a0\u53ef\u884c\u77e9\u9635\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1arowSum = [3,8], colSum = [4,7]\n\u8f93\u51fa\uff1a[[3,0],\n      [1,7]]\n\u89e3\u91ca\uff1a\n\u7b2c 0 \u884c\uff1a3 + 0 = 3 == rowSum[0]\n\u7b2c 1 \u884c\uff1a1 + 7 = 8 == rowSum[1]\n\u7b2c 0 \u5217\uff1a3 + 1 = 4 == colSum[0]\n\u7b2c 1 \u5217\uff1a0 + 7 = 7 == colSum[1]\n\u884c\u548c\u5217\u7684\u548c\u90fd\u6ee1\u8db3\u9898\u76ee\u8981\u6c42\uff0c\u4e14\u6240\u6709\u77e9\u9635\u5143\u7d20\u90fd\u662f\u975e\u8d1f\u7684\u3002\n\u53e6\u4e00\u4e2a\u53ef\u884c\u7684\u77e9\u9635\u4e3a\uff1a[[1,2],\n                  [3,5]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1arowSum = [5,7,10], colSum = [8,6,8]\n\u8f93\u51fa\uff1a[[0,5,0],\n      [6,1,0],\n      [2,0,8]]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1arowSum = [14,9], colSum = [6,9,8]\n\u8f93\u51fa\uff1a[[0,9,5],\n      [6,0,3]]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1arowSum = [1,0], colSum = [1]\n\u8f93\u51fa\uff1a[[1],\n      [0]]\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1arowSum = [0], colSum = [0]\n\u8f93\u51fa\uff1a[[0]]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= rowSum.length, colSum.length <= 500
    • \n\t
    • 0 <= rowSum[i], colSum[i] <= 108
    • \n\t
    • sum(rows) == sum(columns)
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> restoreMatrix(vector& rowSum, vector& colSum) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[][] restoreMatrix(int[] rowSum, int[] colSum) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def restoreMatrix(self, rowSum, colSum):\n \"\"\"\n :type rowSum: List[int]\n :type colSum: List[int]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def restoreMatrix(self, rowSum: List[int], colSum: List[int]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** restoreMatrix(int* rowSum, int rowSumSize, int* colSum, int colSumSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[][] RestoreMatrix(int[] rowSum, int[] colSum) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} rowSum\n * @param {number[]} colSum\n * @return {number[][]}\n */\nvar restoreMatrix = function(rowSum, colSum) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} row_sum\n# @param {Integer[]} col_sum\n# @return {Integer[][]}\ndef restore_matrix(row_sum, col_sum)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func restoreMatrix(_ rowSum: [Int], _ colSum: [Int]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func restoreMatrix(rowSum []int, colSum []int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def restoreMatrix(rowSum: Array[Int], colSum: Array[Int]): Array[Array[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun restoreMatrix(rowSum: IntArray, colSum: IntArray): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn restore_matrix(row_sum: Vec, col_sum: Vec) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $rowSum\n * @param Integer[] $colSum\n * @return Integer[][]\n */\n function restoreMatrix($rowSum, $colSum) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function restoreMatrix(rowSum: number[], colSum: number[]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (restore-matrix rowSum colSum)\n (-> (listof exact-integer?) (listof exact-integer?) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1605](https://leetcode-cn.com/problems/find-valid-matrix-given-row-and-column-sums)", "[\u7ed9\u5b9a\u884c\u548c\u5217\u7684\u548c\u6c42\u53ef\u884c\u77e9\u9635](/solution/1600-1699/1605.Find%20Valid%20Matrix%20Given%20Row%20and%20Column%20Sums/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1605](https://leetcode.com/problems/find-valid-matrix-given-row-and-column-sums)", "[Find Valid Matrix Given Row and Column Sums](/solution/1600-1699/1605.Find%20Valid%20Matrix%20Given%20Row%20and%20Column%20Sums/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1710", "frontend_question_id": "1606", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-servers-that-handled-most-number-of-requests", "url_en": "https://leetcode.com/problems/find-servers-that-handled-most-number-of-requests", "relative_path_cn": "/solution/1600-1699/1606.Find%20Servers%20That%20Handled%20Most%20Number%20of%20Requests/README.md", "relative_path_en": "/solution/1600-1699/1606.Find%20Servers%20That%20Handled%20Most%20Number%20of%20Requests/README_EN.md", "title_cn": "\u627e\u5230\u5904\u7406\u6700\u591a\u8bf7\u6c42\u7684\u670d\u52a1\u5668", "title_en": "Find Servers That Handled Most Number of Requests", "question_title_slug": "find-servers-that-handled-most-number-of-requests", "content_en": "

    You have k servers numbered from 0 to k-1 that are being used to handle multiple requests simultaneously. Each server has infinite computational capacity but cannot handle more than one request at a time. The requests are assigned to servers according to a specific algorithm:

    \n\n
      \n\t
    • The ith (0-indexed) request arrives.
    • \n\t
    • If all servers are busy, the request is dropped (not handled at all).
    • \n\t
    • If the (i % k)th server is available, assign the request to that server.
    • \n\t
    • Otherwise, assign the request to the next available server (wrapping around the list of servers and starting from 0 if necessary). For example, if the ith server is busy, try to assign the request to the (i+1)th server, then the (i+2)th server, and so on.
    • \n
    \n\n

    You are given a strictly increasing array arrival of positive integers, where arrival[i] represents the arrival time of the ith request, and another array load, where load[i] represents the load of the ith request (the time it takes to complete). Your goal is to find the busiest server(s). A server is considered busiest if it handled the most number of requests successfully among all the servers.

    \n\n

    Return a list containing the IDs (0-indexed) of the busiest server(s). You may return the IDs in any order.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: k = 3, arrival = [1,2,3,4,5], load = [5,2,3,3,3] \nOutput: [1] \nExplanation:\nAll of the servers start out available.\nThe first 3 requests are handled by the first 3 servers in order.\nRequest 3 comes in. Server 0 is busy, so it's assigned to the next available server, which is 1.\nRequest 4 comes in. It cannot be handled since all servers are busy, so it is dropped.\nServers 0 and 2 handled one request each, while server 1 handled two requests. Hence server 1 is the busiest server.\n
    \n\n

    Example 2:

    \n\n
    \nInput: k = 3, arrival = [1,2,3,4], load = [1,2,1,2]\nOutput: [0]\nExplanation:\nThe first 3 requests are handled by first 3 servers.\nRequest 3 comes in. It is handled by server 0 since the server is available.\nServer 0 handled two requests, while servers 1 and 2 handled one request each. Hence server 0 is the busiest server.\n
    \n\n

    Example 3:

    \n\n
    \nInput: k = 3, arrival = [1,2,3], load = [10,12,11]\nOutput: [0,1,2]\nExplanation: Each server handles a single request, so they are all considered the busiest.\n
    \n\n

    Example 4:

    \n\n
    \nInput: k = 3, arrival = [1,2,3,4,8,9,10], load = [5,2,10,3,1,2,2]\nOutput: [1]\n
    \n\n

    Example 5:

    \n\n
    \nInput: k = 1, arrival = [1], load = [1]\nOutput: [0]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= k <= 105
    • \n\t
    • 1 <= arrival.length, load.length <= 105
    • \n\t
    • arrival.length == load.length
    • \n\t
    • 1 <= arrival[i], load[i] <= 109
    • \n\t
    • arrival is strictly increasing.
    • \n
    \n", "content_cn": "

    \u4f60\u6709 k\u00a0\u4e2a\u670d\u52a1\u5668\uff0c\u7f16\u53f7\u4e3a 0\u00a0\u5230 k-1\u00a0\uff0c\u5b83\u4eec\u53ef\u4ee5\u540c\u65f6\u5904\u7406\u591a\u4e2a\u8bf7\u6c42\u7ec4\u3002\u6bcf\u4e2a\u670d\u52a1\u5668\u6709\u65e0\u7a77\u7684\u8ba1\u7b97\u80fd\u529b\u4f46\u662f \u4e0d\u80fd\u540c\u65f6\u5904\u7406\u8d85\u8fc7\u4e00\u4e2a\u8bf7\u6c42\u00a0\u3002\u8bf7\u6c42\u5206\u914d\u5230\u670d\u52a1\u5668\u7684\u89c4\u5219\u5982\u4e0b\uff1a

    \n\n
      \n\t
    • \u7b2c\u00a0i\u00a0\uff08\u5e8f\u53f7\u4ece 0 \u5f00\u59cb\uff09\u4e2a\u8bf7\u6c42\u5230\u8fbe\u3002
    • \n\t
    • \u5982\u679c\u6240\u6709\u670d\u52a1\u5668\u90fd\u5df2\u88ab\u5360\u636e\uff0c\u90a3\u4e48\u8be5\u8bf7\u6c42\u88ab\u820d\u5f03\uff08\u5b8c\u5168\u4e0d\u5904\u7406\uff09\u3002
    • \n\t
    • \u5982\u679c\u7b2c\u00a0(i % k)\u00a0\u4e2a\u670d\u52a1\u5668\u7a7a\u95f2\uff0c\u90a3\u4e48\u5bf9\u5e94\u670d\u52a1\u5668\u4f1a\u5904\u7406\u8be5\u8bf7\u6c42\u3002
    • \n\t
    • \u5426\u5219\uff0c\u5c06\u8bf7\u6c42\u5b89\u6392\u7ed9\u4e0b\u4e00\u4e2a\u7a7a\u95f2\u7684\u670d\u52a1\u5668\uff08\u670d\u52a1\u5668\u6784\u6210\u4e00\u4e2a\u73af\uff0c\u5fc5\u8981\u7684\u8bdd\u53ef\u80fd\u4ece\u7b2c 0 \u4e2a\u670d\u52a1\u5668\u5f00\u59cb\u7ee7\u7eed\u627e\u4e0b\u4e00\u4e2a\u7a7a\u95f2\u7684\u670d\u52a1\u5668\uff09\u3002\u6bd4\u65b9\u8bf4\uff0c\u5982\u679c\u7b2c i\u00a0\u4e2a\u670d\u52a1\u5668\u5728\u5fd9\uff0c\u90a3\u4e48\u4f1a\u67e5\u770b\u7b2c (i+1)\u00a0\u4e2a\u670d\u52a1\u5668\uff0c\u7b2c (i+2)\u00a0\u4e2a\u670d\u52a1\u5668\u7b49\u7b49\u3002
    • \n
    \n\n

    \u7ed9\u4f60\u4e00\u4e2a \u4e25\u683c\u9012\u589e\u00a0\u7684\u6b63\u6574\u6570\u6570\u7ec4\u00a0arrival\u00a0\uff0c\u8868\u793a\u7b2c\u00a0i\u00a0\u4e2a\u4efb\u52a1\u7684\u5230\u8fbe\u65f6\u95f4\uff0c\u548c\u53e6\u4e00\u4e2a\u6570\u7ec4\u00a0load\u00a0\uff0c\u5176\u4e2d\u00a0load[i]\u00a0\u8868\u793a\u7b2c\u00a0i\u00a0\u4e2a\u8bf7\u6c42\u7684\u5de5\u4f5c\u91cf\uff08\u4e5f\u5c31\u662f\u670d\u52a1\u5668\u5b8c\u6210\u5b83\u6240\u9700\u8981\u7684\u65f6\u95f4\uff09\u3002\u4f60\u7684\u4efb\u52a1\u662f\u627e\u5230 \u6700\u7e41\u5fd9\u7684\u670d\u52a1\u5668\u00a0\u3002\u6700\u7e41\u5fd9\u5b9a\u4e49\u4e3a\u4e00\u4e2a\u670d\u52a1\u5668\u5904\u7406\u7684\u8bf7\u6c42\u6570\u662f\u6240\u6709\u670d\u52a1\u5668\u91cc\u6700\u591a\u7684\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u5305\u542b\u6240\u6709\u00a0\u6700\u7e41\u5fd9\u670d\u52a1\u5668\u00a0\u5e8f\u53f7\u7684\u5217\u8868\uff0c\u4f60\u53ef\u4ee5\u4ee5\u4efb\u610f\u987a\u5e8f\u8fd4\u56de\u8fd9\u4e2a\u5217\u8868\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1ak = 3, arrival = [1,2,3,4,5], load = [5,2,3,3,3] \n\u8f93\u51fa\uff1a[1] \n\u89e3\u91ca\uff1a\n\u6240\u6709\u670d\u52a1\u5668\u4e00\u5f00\u59cb\u90fd\u662f\u7a7a\u95f2\u7684\u3002\n\u524d 3 \u4e2a\u8bf7\u6c42\u5206\u522b\u7531\u524d 3 \u53f0\u670d\u52a1\u5668\u4f9d\u6b21\u5904\u7406\u3002\n\u8bf7\u6c42 3 \u8fdb\u6765\u7684\u65f6\u5019\uff0c\u670d\u52a1\u5668 0 \u88ab\u5360\u636e\uff0c\u6240\u4ee5\u5b83\u5457\u5b89\u6392\u5230\u4e0b\u4e00\u53f0\u7a7a\u95f2\u7684\u670d\u52a1\u5668\uff0c\u4e5f\u5c31\u662f\u670d\u52a1\u5668 1 \u3002\n\u8bf7\u6c42 4 \u8fdb\u6765\u7684\u65f6\u5019\uff0c\u7531\u4e8e\u6240\u6709\u670d\u52a1\u5668\u90fd\u88ab\u5360\u636e\uff0c\u8be5\u8bf7\u6c42\u88ab\u820d\u5f03\u3002\n\u670d\u52a1\u5668 0 \u548c 2 \u5206\u522b\u90fd\u5904\u7406\u4e86\u4e00\u4e2a\u8bf7\u6c42\uff0c\u670d\u52a1\u5668 1 \u5904\u7406\u4e86\u4e24\u4e2a\u8bf7\u6c42\u3002\u6240\u4ee5\u670d\u52a1\u5668 1 \u662f\u6700\u5fd9\u7684\u670d\u52a1\u5668\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1ak = 3, arrival = [1,2,3,4], load = [1,2,1,2]\n\u8f93\u51fa\uff1a[0]\n\u89e3\u91ca\uff1a\n\u524d 3 \u4e2a\u8bf7\u6c42\u5206\u522b\u88ab\u524d 3 \u4e2a\u670d\u52a1\u5668\u5904\u7406\u3002\n\u8bf7\u6c42 3 \u8fdb\u6765\uff0c\u7531\u4e8e\u670d\u52a1\u5668 0 \u7a7a\u95f2\uff0c\u5b83\u88ab\u670d\u52a1\u5668 0 \u5904\u7406\u3002\n\u670d\u52a1\u5668 0 \u5904\u7406\u4e86\u4e24\u4e2a\u8bf7\u6c42\uff0c\u670d\u52a1\u5668 1 \u548c 2 \u5206\u522b\u5904\u7406\u4e86\u4e00\u4e2a\u8bf7\u6c42\u3002\u6240\u4ee5\u670d\u52a1\u5668 0 \u662f\u6700\u5fd9\u7684\u670d\u52a1\u5668\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1ak = 3, arrival = [1,2,3], load = [10,12,11]\n\u8f93\u51fa\uff1a[0,1,2]\n\u89e3\u91ca\uff1a\u6bcf\u4e2a\u670d\u52a1\u5668\u5206\u522b\u5904\u7406\u4e86\u4e00\u4e2a\u8bf7\u6c42\uff0c\u6240\u4ee5\u5b83\u4eec\u90fd\u662f\u6700\u5fd9\u7684\u670d\u52a1\u5668\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1ak = 3, arrival = [1,2,3,4,8,9,10], load = [5,2,10,3,1,2,2]\n\u8f93\u51fa\uff1a[1]\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1ak = 1, arrival = [1], load = [1]\n\u8f93\u51fa\uff1a[0]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= k <= 105
    • \n\t
    • 1 <= arrival.length, load.length <= 105
    • \n\t
    • arrival.length == load.length
    • \n\t
    • 1 <= arrival[i], load[i] <= 109
    • \n\t
    • arrival\u00a0\u4fdd\u8bc1 \u4e25\u683c\u9012\u589e\u00a0\u3002
    • \n
    \n", "tags_en": ["Ordered Map"], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector busiestServers(int k, vector& arrival, vector& load) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List busiestServers(int k, int[] arrival, int[] load) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def busiestServers(self, k, arrival, load):\n \"\"\"\n :type k: int\n :type arrival: List[int]\n :type load: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def busiestServers(self, k: int, arrival: List[int], load: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* busiestServers(int k, int* arrival, int arrivalSize, int* load, int loadSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList BusiestServers(int k, int[] arrival, int[] load) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} k\n * @param {number[]} arrival\n * @param {number[]} load\n * @return {number[]}\n */\nvar busiestServers = function(k, arrival, load) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} k\n# @param {Integer[]} arrival\n# @param {Integer[]} load\n# @return {Integer[]}\ndef busiest_servers(k, arrival, load)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func busiestServers(_ k: Int, _ arrival: [Int], _ load: [Int]) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func busiestServers(k int, arrival []int, load []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def busiestServers(k: Int, arrival: Array[Int], load: Array[Int]): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun busiestServers(k: Int, arrival: IntArray, load: IntArray): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn busiest_servers(k: i32, arrival: Vec, load: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $k\n * @param Integer[] $arrival\n * @param Integer[] $load\n * @return Integer[]\n */\n function busiestServers($k, $arrival, $load) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function busiestServers(k: number, arrival: number[], load: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (busiest-servers k arrival load)\n (-> exact-integer? (listof exact-integer?) (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1606](https://leetcode-cn.com/problems/find-servers-that-handled-most-number-of-requests)", "[\u627e\u5230\u5904\u7406\u6700\u591a\u8bf7\u6c42\u7684\u670d\u52a1\u5668](/solution/1600-1699/1606.Find%20Servers%20That%20Handled%20Most%20Number%20of%20Requests/README.md)", "", "\u56f0\u96be", ""], "md_table_row_en": ["[1606](https://leetcode.com/problems/find-servers-that-handled-most-number-of-requests)", "[Find Servers That Handled Most Number of Requests](/solution/1600-1699/1606.Find%20Servers%20That%20Handled%20Most%20Number%20of%20Requests/README_EN.md)", "`Ordered Map`", "Hard", ""]}, {"question_id": "1709", "frontend_question_id": "1604", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/alert-using-same-key-card-three-or-more-times-in-a-one-hour-period", "url_en": "https://leetcode.com/problems/alert-using-same-key-card-three-or-more-times-in-a-one-hour-period", "relative_path_cn": "/solution/1600-1699/1604.Alert%20Using%20Same%20Key-Card%20Three%20or%20More%20Times%20in%20a%20One%20Hour%20Period/README.md", "relative_path_en": "/solution/1600-1699/1604.Alert%20Using%20Same%20Key-Card%20Three%20or%20More%20Times%20in%20a%20One%20Hour%20Period/README_EN.md", "title_cn": "\u8b66\u544a\u4e00\u5c0f\u65f6\u5185\u4f7f\u7528\u76f8\u540c\u5458\u5de5\u5361\u5927\u4e8e\u7b49\u4e8e\u4e09\u6b21\u7684\u4eba", "title_en": "Alert Using Same Key-Card Three or More Times in a One Hour Period", "question_title_slug": "alert-using-same-key-card-three-or-more-times-in-a-one-hour-period", "content_en": "

    LeetCode company workers use key-cards to unlock office doors. Each time a worker uses their key-card, the security system saves the worker's name and the time when it was used. The system emits an alert if any worker uses the key-card three or more times in a one-hour period.

    \n\n

    You are given a list of strings keyName and keyTime where [keyName[i], keyTime[i]] corresponds to a person's name and the time when their key-card was used in a single day.

    \n\n

    Access times are given in the 24-hour time format "HH:MM", such as "23:51" and "09:49".

    \n\n

    Return a list of unique worker names who received an alert for frequent keycard use. Sort the names in ascending order alphabetically.

    \n\n

    Notice that "10:00" - "11:00" is considered to be within a one-hour period, while "22:51" - "23:52" is not considered to be within a one-hour period.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: keyName = ["daniel","daniel","daniel","luis","luis","luis","luis"], keyTime = ["10:00","10:40","11:00","09:00","11:00","13:00","15:00"]\nOutput: ["daniel"]\nExplanation: "daniel" used the keycard 3 times in a one-hour period ("10:00","10:40", "11:00").\n
    \n\n

    Example 2:

    \n\n
    \nInput: keyName = ["alice","alice","alice","bob","bob","bob","bob"], keyTime = ["12:01","12:00","18:00","21:00","21:20","21:30","23:00"]\nOutput: ["bob"]\nExplanation: "bob" used the keycard 3 times in a one-hour period ("21:00","21:20", "21:30").\n
    \n\n

    Example 3:

    \n\n
    \nInput: keyName = ["john","john","john"], keyTime = ["23:58","23:59","00:01"]\nOutput: []\n
    \n\n

    Example 4:

    \n\n
    \nInput: keyName = ["leslie","leslie","leslie","clare","clare","clare","clare"], keyTime = ["13:00","13:20","14:00","18:00","18:51","19:30","19:49"]\nOutput: ["clare","leslie"]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= keyName.length, keyTime.length <= 105
    • \n\t
    • keyName.length == keyTime.length
    • \n\t
    • keyTime[i] is in the format "HH:MM".
    • \n\t
    • [keyName[i], keyTime[i]] is unique.
    • \n\t
    • 1 <= keyName[i].length <= 10
    • \n\t
    • keyName[i] contains only lowercase English letters.
    • \n
    \n", "content_cn": "

    \u529b\u6263\u516c\u53f8\u7684\u5458\u5de5\u90fd\u4f7f\u7528\u5458\u5de5\u5361\u6765\u5f00\u529e\u516c\u5ba4\u7684\u95e8\u3002\u6bcf\u5f53\u4e00\u4e2a\u5458\u5de5\u4f7f\u7528\u4e00\u6b21\u4ed6\u7684\u5458\u5de5\u5361\uff0c\u5b89\u4fdd\u7cfb\u7edf\u4f1a\u8bb0\u5f55\u4e0b\u5458\u5de5\u7684\u540d\u5b57\u548c\u4f7f\u7528\u65f6\u95f4\u3002\u5982\u679c\u4e00\u4e2a\u5458\u5de5\u5728\u4e00\u5c0f\u65f6\u65f6\u95f4\u5185\u4f7f\u7528\u5458\u5de5\u5361\u7684\u6b21\u6570\u5927\u4e8e\u7b49\u4e8e\u4e09\u6b21\uff0c\u8fd9\u4e2a\u7cfb\u7edf\u4f1a\u81ea\u52a8\u53d1\u5e03\u4e00\u4e2a \u8b66\u544a\u00a0\u3002

    \n\n

    \u7ed9\u4f60\u5b57\u7b26\u4e32\u6570\u7ec4\u00a0keyName\u00a0\u548c\u00a0keyTime \uff0c\u5176\u4e2d\u00a0[keyName[i], keyTime[i]]\u00a0\u5bf9\u5e94\u4e00\u4e2a\u4eba\u7684\u540d\u5b57\u548c\u4ed6\u5728\u00a0\u67d0\u4e00\u5929 \u5185\u4f7f\u7528\u5458\u5de5\u5361\u7684\u65f6\u95f4\u3002

    \n\n

    \u4f7f\u7528\u65f6\u95f4\u7684\u683c\u5f0f\u662f 24\u5c0f\u65f6\u5236\u00a0\uff0c\u5f62\u5982\u00a0\"HH:MM\"\u00a0\uff0c\u6bd4\u65b9\u8bf4\u00a0\"23:51\" \u548c\u00a0\"09:49\"\u00a0\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u53bb\u91cd\u540e\u7684\u6536\u5230\u7cfb\u7edf\u8b66\u544a\u7684\u5458\u5de5\u540d\u5b57\uff0c\u5c06\u5b83\u4eec\u6309 \u5b57\u5178\u5e8f\u5347\u5e8f\u00a0\u6392\u5e8f\u540e\u8fd4\u56de\u3002

    \n\n

    \u8bf7\u6ce8\u610f\u00a0\"10:00\" - \"11:00\"\u00a0\u89c6\u4e3a\u4e00\u4e2a\u5c0f\u65f6\u65f6\u95f4\u8303\u56f4\u5185\uff0c\u800c\u00a0\"23:51\" - \"00:10\"\u00a0\u4e0d\u88ab\u89c6\u4e3a\u4e00\u5c0f\u65f6\u5185\uff0c\u56e0\u4e3a\u7cfb\u7edf\u8bb0\u5f55\u7684\u662f\u67d0\u4e00\u5929\u5185\u7684\u4f7f\u7528\u60c5\u51b5\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1akeyName = [\"daniel\",\"daniel\",\"daniel\",\"luis\",\"luis\",\"luis\",\"luis\"], keyTime = [\"10:00\",\"10:40\",\"11:00\",\"09:00\",\"11:00\",\"13:00\",\"15:00\"]\n\u8f93\u51fa\uff1a[\"daniel\"]\n\u89e3\u91ca\uff1a\"daniel\" \u5728\u4e00\u5c0f\u65f6\u5185\u4f7f\u7528\u4e86 3 \u6b21\u5458\u5de5\u5361\uff08\"10:00\"\uff0c\"10:40\"\uff0c\"11:00\"\uff09\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1akeyName = [\"alice\",\"alice\",\"alice\",\"bob\",\"bob\",\"bob\",\"bob\"], keyTime = [\"12:01\",\"12:00\",\"18:00\",\"21:00\",\"21:20\",\"21:30\",\"23:00\"]\n\u8f93\u51fa\uff1a[\"bob\"]\n\u89e3\u91ca\uff1a\"bob\" \u5728\u4e00\u5c0f\u65f6\u5185\u4f7f\u7528\u4e86 3 \u6b21\u5458\u5de5\u5361\uff08\"21:00\"\uff0c\"21:20\"\uff0c\"21:30\"\uff09\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1akeyName = [\"john\",\"john\",\"john\"], keyTime = [\"23:58\",\"23:59\",\"00:01\"]\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1akeyName = [\"leslie\",\"leslie\",\"leslie\",\"clare\",\"clare\",\"clare\",\"clare\"], keyTime = [\"13:00\",\"13:20\",\"14:00\",\"18:00\",\"18:51\",\"19:30\",\"19:49\"]\n\u8f93\u51fa\uff1a[\"clare\",\"leslie\"]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= keyName.length, keyTime.length <= 105
    • \n\t
    • keyName.length == keyTime.length
    • \n\t
    • keyTime \u683c\u5f0f\u4e3a\u00a0\"HH:MM\"\u00a0\u3002
    • \n\t
    • \u4fdd\u8bc1\u00a0[keyName[i], keyTime[i]]\u00a0\u5f62\u6210\u7684\u4e8c\u5143\u5bf9\u00a0\u4e92\u4e0d\u76f8\u540c\u00a0\u3002
    • \n\t
    • 1 <= keyName[i].length <= 10
    • \n\t
    • keyName[i]\u00a0\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    • \n
    \n", "tags_en": ["String", "Ordered Map"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector alertNames(vector& keyName, vector& keyTime) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List alertNames(String[] keyName, String[] keyTime) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def alertNames(self, keyName, keyTime):\n \"\"\"\n :type keyName: List[str]\n :type keyTime: List[str]\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def alertNames(self, keyName: List[str], keyTime: List[str]) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** alertNames(char ** keyName, int keyNameSize, char ** keyTime, int keyTimeSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList AlertNames(string[] keyName, string[] keyTime) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} keyName\n * @param {string[]} keyTime\n * @return {string[]}\n */\nvar alertNames = function(keyName, keyTime) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} key_name\n# @param {String[]} key_time\n# @return {String[]}\ndef alert_names(key_name, key_time)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func alertNames(_ keyName: [String], _ keyTime: [String]) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func alertNames(keyName []string, keyTime []string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def alertNames(keyName: Array[String], keyTime: Array[String]): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun alertNames(keyName: Array, keyTime: Array): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn alert_names(key_name: Vec, key_time: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $keyName\n * @param String[] $keyTime\n * @return String[]\n */\n function alertNames($keyName, $keyTime) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function alertNames(keyName: string[], keyTime: string[]): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (alert-names keyName keyTime)\n (-> (listof string?) (listof string?) (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1604](https://leetcode-cn.com/problems/alert-using-same-key-card-three-or-more-times-in-a-one-hour-period)", "[\u8b66\u544a\u4e00\u5c0f\u65f6\u5185\u4f7f\u7528\u76f8\u540c\u5458\u5de5\u5361\u5927\u4e8e\u7b49\u4e8e\u4e09\u6b21\u7684\u4eba](/solution/1600-1699/1604.Alert%20Using%20Same%20Key-Card%20Three%20or%20More%20Times%20in%20a%20One%20Hour%20Period/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1604](https://leetcode.com/problems/alert-using-same-key-card-three-or-more-times-in-a-one-hour-period)", "[Alert Using Same Key-Card Three or More Times in a One Hour Period](/solution/1600-1699/1604.Alert%20Using%20Same%20Key-Card%20Three%20or%20More%20Times%20in%20a%20One%20Hour%20Period/README_EN.md)", "`String`,`Ordered Map`", "Medium", ""]}, {"question_id": "1708", "frontend_question_id": "1603", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/design-parking-system", "url_en": "https://leetcode.com/problems/design-parking-system", "relative_path_cn": "/solution/1600-1699/1603.Design%20Parking%20System/README.md", "relative_path_en": "/solution/1600-1699/1603.Design%20Parking%20System/README_EN.md", "title_cn": "\u8bbe\u8ba1\u505c\u8f66\u7cfb\u7edf", "title_en": "Design Parking System", "question_title_slug": "design-parking-system", "content_en": "

    Design a parking system for a parking lot. The parking lot has three kinds of parking spaces: big, medium, and small, with a fixed number of slots for each size.

    \n\n

    Implement the ParkingSystem class:

    \n\n
      \n\t
    • ParkingSystem(int big, int medium, int small) Initializes object of the ParkingSystem class. The number of slots for each parking space are given as part of the constructor.
    • \n\t
    • bool addCar(int carType) Checks whether there is a parking space of carType for the car that wants to get into the parking lot. carType can be of three kinds: big, medium, or small, which are represented by 1, 2, and 3 respectively. A car can only park in a parking space of its carType. If there is no space available, return false, else park the car in that size space and return true.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["ParkingSystem", "addCar", "addCar", "addCar", "addCar"]\n[[1, 1, 0], [1], [2], [3], [1]]\nOutput\n[null, true, true, false, false]\n\nExplanation\nParkingSystem parkingSystem = new ParkingSystem(1, 1, 0);\nparkingSystem.addCar(1); // return true because there is 1 available slot for a big car\nparkingSystem.addCar(2); // return true because there is 1 available slot for a medium car\nparkingSystem.addCar(3); // return false because there is no available slot for a small car\nparkingSystem.addCar(1); // return false because there is no available slot for a big car. It is already occupied.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= big, medium, small <= 1000
    • \n\t
    • carType is 1, 2, or 3
    • \n\t
    • At most 1000 calls will be made to addCar
    • \n
    \n", "content_cn": "

    \u8bf7\u4f60\u7ed9\u4e00\u4e2a\u505c\u8f66\u573a\u8bbe\u8ba1\u4e00\u4e2a\u505c\u8f66\u7cfb\u7edf\u3002\u505c\u8f66\u573a\u603b\u5171\u6709\u4e09\u79cd\u4e0d\u540c\u5927\u5c0f\u7684\u8f66\u4f4d\uff1a\u5927\uff0c\u4e2d\u548c\u5c0f\uff0c\u6bcf\u79cd\u5c3a\u5bf8\u5206\u522b\u6709\u56fa\u5b9a\u6570\u76ee\u7684\u8f66\u4f4d\u3002

    \n\n

    \u8bf7\u4f60\u5b9e\u73b0\u00a0ParkingSystem\u00a0\u7c7b\uff1a

    \n\n
      \n\t
    • ParkingSystem(int big, int medium, int small)\u00a0\u521d\u59cb\u5316\u00a0ParkingSystem\u00a0\u7c7b\uff0c\u4e09\u4e2a\u53c2\u6570\u5206\u522b\u5bf9\u5e94\u6bcf\u79cd\u505c\u8f66\u4f4d\u7684\u6570\u76ee\u3002
    • \n\t
    • bool addCar(int carType)\u00a0\u68c0\u67e5\u662f\u5426\u6709\u00a0carType\u00a0\u5bf9\u5e94\u7684\u505c\u8f66\u4f4d\u3002\u00a0carType\u00a0\u6709\u4e09\u79cd\u7c7b\u578b\uff1a\u5927\uff0c\u4e2d\uff0c\u5c0f\uff0c\u5206\u522b\u7528\u6570\u5b57\u00a01\uff0c\u00a02\u00a0\u548c\u00a03\u00a0\u8868\u793a\u3002\u4e00\u8f86\u8f66\u53ea\u80fd\u505c\u5728\u00a0\u00a0carType\u00a0\u5bf9\u5e94\u5c3a\u5bf8\u7684\u505c\u8f66\u4f4d\u4e2d\u3002\u5982\u679c\u6ca1\u6709\u7a7a\u8f66\u4f4d\uff0c\u8bf7\u8fd4\u56de\u00a0false\u00a0\uff0c\u5426\u5219\u5c06\u8be5\u8f66\u505c\u5165\u8f66\u4f4d\u5e76\u8fd4\u56de\u00a0true\u00a0\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\n[\"ParkingSystem\", \"addCar\", \"addCar\", \"addCar\", \"addCar\"]\n[[1, 1, 0], [1], [2], [3], [1]]\n\u8f93\u51fa\uff1a\n[null, true, true, false, false]\n\n\u89e3\u91ca\uff1a\nParkingSystem parkingSystem = new ParkingSystem(1, 1, 0);\nparkingSystem.addCar(1); // \u8fd4\u56de true \uff0c\u56e0\u4e3a\u6709 1 \u4e2a\u7a7a\u7684\u5927\u8f66\u4f4d\nparkingSystem.addCar(2); // \u8fd4\u56de true \uff0c\u56e0\u4e3a\u6709 1 \u4e2a\u7a7a\u7684\u4e2d\u8f66\u4f4d\nparkingSystem.addCar(3); // \u8fd4\u56de false \uff0c\u56e0\u4e3a\u6ca1\u6709\u7a7a\u7684\u5c0f\u8f66\u4f4d\nparkingSystem.addCar(1); // \u8fd4\u56de false \uff0c\u56e0\u4e3a\u6ca1\u6709\u7a7a\u7684\u5927\u8f66\u4f4d\uff0c\u552f\u4e00\u4e00\u4e2a\u5927\u8f66\u4f4d\u5df2\u7ecf\u88ab\u5360\u636e\u4e86\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= big, medium, small <= 1000
    • \n\t
    • carType\u00a0\u53d6\u503c\u4e3a\u00a01\uff0c\u00a02\u00a0\u6216\u00a03
    • \n\t
    • \u6700\u591a\u4f1a\u8c03\u7528\u00a0addCar\u00a0\u51fd\u6570\u00a01000\u00a0\u6b21
    • \n
    \n", "tags_en": ["Design"], "tags_cn": ["\u8bbe\u8ba1"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class ParkingSystem {\npublic:\n ParkingSystem(int big, int medium, int small) {\n\n }\n \n bool addCar(int carType) {\n\n }\n};\n\n/**\n * Your ParkingSystem object will be instantiated and called as such:\n * ParkingSystem* obj = new ParkingSystem(big, medium, small);\n * bool param_1 = obj->addCar(carType);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class ParkingSystem {\n\n public ParkingSystem(int big, int medium, int small) {\n\n }\n \n public boolean addCar(int carType) {\n\n }\n}\n\n/**\n * Your ParkingSystem object will be instantiated and called as such:\n * ParkingSystem obj = new ParkingSystem(big, medium, small);\n * boolean param_1 = obj.addCar(carType);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class ParkingSystem(object):\n\n def __init__(self, big, medium, small):\n \"\"\"\n :type big: int\n :type medium: int\n :type small: int\n \"\"\"\n\n\n def addCar(self, carType):\n \"\"\"\n :type carType: int\n :rtype: bool\n \"\"\"\n\n\n\n# Your ParkingSystem object will be instantiated and called as such:\n# obj = ParkingSystem(big, medium, small)\n# param_1 = obj.addCar(carType)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class ParkingSystem:\n\n def __init__(self, big: int, medium: int, small: int):\n\n\n def addCar(self, carType: int) -> bool:\n\n\n\n# Your ParkingSystem object will be instantiated and called as such:\n# obj = ParkingSystem(big, medium, small)\n# param_1 = obj.addCar(carType)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} ParkingSystem;\n\n\nParkingSystem* parkingSystemCreate(int big, int medium, int small) {\n\n}\n\nbool parkingSystemAddCar(ParkingSystem* obj, int carType) {\n\n}\n\nvoid parkingSystemFree(ParkingSystem* obj) {\n\n}\n\n/**\n * Your ParkingSystem struct will be instantiated and called as such:\n * ParkingSystem* obj = parkingSystemCreate(big, medium, small);\n * bool param_1 = parkingSystemAddCar(obj, carType);\n \n * parkingSystemFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class ParkingSystem {\n\n public ParkingSystem(int big, int medium, int small) {\n\n }\n \n public bool AddCar(int carType) {\n\n }\n}\n\n/**\n * Your ParkingSystem object will be instantiated and called as such:\n * ParkingSystem obj = new ParkingSystem(big, medium, small);\n * bool param_1 = obj.AddCar(carType);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} big\n * @param {number} medium\n * @param {number} small\n */\nvar ParkingSystem = function(big, medium, small) {\n\n};\n\n/** \n * @param {number} carType\n * @return {boolean}\n */\nParkingSystem.prototype.addCar = function(carType) {\n\n};\n\n/**\n * Your ParkingSystem object will be instantiated and called as such:\n * var obj = new ParkingSystem(big, medium, small)\n * var param_1 = obj.addCar(carType)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class ParkingSystem\n\n=begin\n :type big: Integer\n :type medium: Integer\n :type small: Integer\n=end\n def initialize(big, medium, small)\n\n end\n\n\n=begin\n :type car_type: Integer\n :rtype: Boolean\n=end\n def add_car(car_type)\n\n end\n\n\nend\n\n# Your ParkingSystem object will be instantiated and called as such:\n# obj = ParkingSystem.new(big, medium, small)\n# param_1 = obj.add_car(car_type)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass ParkingSystem {\n\n init(_ big: Int, _ medium: Int, _ small: Int) {\n \n }\n \n func addCar(_ carType: Int) -> Bool {\n \n }\n}\n\n/**\n * Your ParkingSystem object will be instantiated and called as such:\n * let obj = ParkingSystem(big, medium, small)\n * let ret_1: Bool = obj.addCar(carType)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type ParkingSystem struct {\n\n}\n\n\nfunc Constructor(big int, medium int, small int) ParkingSystem {\n\n}\n\n\nfunc (this *ParkingSystem) AddCar(carType int) bool {\n\n}\n\n\n/**\n * Your ParkingSystem object will be instantiated and called as such:\n * obj := Constructor(big, medium, small);\n * param_1 := obj.AddCar(carType);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class ParkingSystem(_big: Int, _medium: Int, _small: Int) {\n\n def addCar(carType: Int): Boolean = {\n\n }\n\n}\n\n/**\n * Your ParkingSystem object will be instantiated and called as such:\n * var obj = new ParkingSystem(big, medium, small)\n * var param_1 = obj.addCar(carType)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class ParkingSystem(big: Int, medium: Int, small: Int) {\n\n fun addCar(carType: Int): Boolean {\n\n }\n\n}\n\n/**\n * Your ParkingSystem object will be instantiated and called as such:\n * var obj = ParkingSystem(big, medium, small)\n * var param_1 = obj.addCar(carType)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct ParkingSystem {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl ParkingSystem {\n\n fn new(big: i32, medium: i32, small: i32) -> Self {\n\n }\n \n fn add_car(&self, car_type: i32) -> bool {\n\n }\n}\n\n/**\n * Your ParkingSystem object will be instantiated and called as such:\n * let obj = ParkingSystem::new(big, medium, small);\n * let ret_1: bool = obj.add_car(carType);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class ParkingSystem {\n /**\n * @param Integer $big\n * @param Integer $medium\n * @param Integer $small\n */\n function __construct($big, $medium, $small) {\n\n }\n\n /**\n * @param Integer $carType\n * @return Boolean\n */\n function addCar($carType) {\n\n }\n}\n\n/**\n * Your ParkingSystem object will be instantiated and called as such:\n * $obj = ParkingSystem($big, $medium, $small);\n * $ret_1 = $obj->addCar($carType);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class ParkingSystem {\n constructor(big: number, medium: number, small: number) {\n\n }\n\n addCar(carType: number): boolean {\n\n }\n}\n\n/**\n * Your ParkingSystem object will be instantiated and called as such:\n * var obj = new ParkingSystem(big, medium, small)\n * var param_1 = obj.addCar(carType)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define parking-system%\n (class object%\n (super-new)\n\n ; big : exact-integer?\n\n ; medium : exact-integer?\n\n ; small : exact-integer?\n (init-field\n big\n medium\n small)\n \n ; add-car : exact-integer? -> boolean?\n (define/public (add-car carType)\n\n )))\n\n;; Your parking-system% object will be instantiated and called as such:\n;; (define obj (new parking-system% [big big] [medium medium] [small small]))\n;; (define param_1 (send obj add-car car-type))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1603](https://leetcode-cn.com/problems/design-parking-system)", "[\u8bbe\u8ba1\u505c\u8f66\u7cfb\u7edf](/solution/1600-1699/1603.Design%20Parking%20System/README.md)", "`\u8bbe\u8ba1`", "\u7b80\u5355", ""], "md_table_row_en": ["[1603](https://leetcode.com/problems/design-parking-system)", "[Design Parking System](/solution/1600-1699/1603.Design%20Parking%20System/README_EN.md)", "`Design`", "Easy", ""]}, {"question_id": "1707", "frontend_question_id": "1585", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/check-if-string-is-transformable-with-substring-sort-operations", "url_en": "https://leetcode.com/problems/check-if-string-is-transformable-with-substring-sort-operations", "relative_path_cn": "/solution/1500-1599/1585.Check%20If%20String%20Is%20Transformable%20With%20Substring%20Sort%20Operations/README.md", "relative_path_en": "/solution/1500-1599/1585.Check%20If%20String%20Is%20Transformable%20With%20Substring%20Sort%20Operations/README_EN.md", "title_cn": "\u68c0\u67e5\u5b57\u7b26\u4e32\u662f\u5426\u53ef\u4ee5\u901a\u8fc7\u6392\u5e8f\u5b50\u5b57\u7b26\u4e32\u5f97\u5230\u53e6\u4e00\u4e2a\u5b57\u7b26\u4e32", "title_en": "Check If String Is Transformable With Substring Sort Operations", "question_title_slug": "check-if-string-is-transformable-with-substring-sort-operations", "content_en": "

    Given two strings s and t, you want to transform string s into string t using the following operation any number of times:

    \n\n
      \n\t
    • Choose a non-empty substring in s and sort it in-place so the characters are in ascending order.
    • \n
    \n\n

    For example, applying the operation on the underlined substring in "14234" results in "12344".

    \n\n

    Return true if it is possible to transform string s into string t. Otherwise, return false.

    \n\n

    A substring is a contiguous sequence of characters within a string.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "84532", t = "34852"\nOutput: true\nExplanation: You can transform s into t using the following sort operations:\n"84532" (from index 2 to 3) -> "84352"\n"84352" (from index 0 to 2) -> "34852"\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "34521", t = "23415"\nOutput: true\nExplanation: You can transform s into t using the following sort operations:\n"34521" -> "23451"\n"23451" -> "23415"\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "12345", t = "12435"\nOutput: false\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "1", t = "2"\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • s.length == t.length
    • \n\t
    • 1 <= s.length <= 105
    • \n\t
    • s and t only contain digits from '0' to '9'.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u5b57\u7b26\u4e32 s \u548c t \uff0c\u8bf7\u4f60\u901a\u8fc7\u82e5\u5e72\u6b21\u4ee5\u4e0b\u64cd\u4f5c\u5c06\u5b57\u7b26\u4e32 s \u8f6c\u5316\u6210\u5b57\u7b26\u4e32 t \uff1a

    \n\n
      \n\t
    • \u9009\u62e9 s \u4e2d\u4e00\u4e2a \u975e\u7a7a \u5b50\u5b57\u7b26\u4e32\u5e76\u5c06\u5b83\u5305\u542b\u7684\u5b57\u7b26\u5c31\u5730 \u5347\u5e8f \u6392\u5e8f\u3002
    • \n
    \n\n

    \u6bd4\u65b9\u8bf4\uff0c\u5bf9\u4e0b\u5212\u7ebf\u6240\u793a\u7684\u5b50\u5b57\u7b26\u4e32\u8fdb\u884c\u64cd\u4f5c\u53ef\u4ee5\u7531 "14234" \u5f97\u5230 "12344" \u3002

    \n\n

    \u5982\u679c\u53ef\u4ee5\u5c06\u5b57\u7b26\u4e32 s \u53d8\u6210 t \uff0c\u8fd4\u56de true \u3002\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n

    \u4e00\u4e2a \u5b50\u5b57\u7b26\u4e32 \u5b9a\u4e49\u4e3a\u4e00\u4e2a\u5b57\u7b26\u4e32\u4e2d\u8fde\u7eed\u7684\u82e5\u5e72\u5b57\u7b26\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = "84532", t = "34852"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u6309\u4ee5\u4e0b\u64cd\u4f5c\u5c06 s \u8f6c\u53d8\u4e3a t \uff1a\n"84532" \uff08\u4ece\u4e0b\u6807 2 \u5230\u4e0b\u6807 3\uff09-> "84352"\n"84352" \uff08\u4ece\u4e0b\u6807 0 \u5230\u4e0b\u6807 2\uff09 -> "34852"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = "34521", t = "23415"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u6309\u4ee5\u4e0b\u64cd\u4f5c\u5c06 s \u8f6c\u53d8\u4e3a t \uff1a\n"34521" -> "23451"\n"23451" -> "23415"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = "12345", t = "12435"\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = "1", t = "2"\n\u8f93\u51fa\uff1afalse\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • s.length == t.length
    • \n\t
    • 1 <= s.length <= 105
    • \n\t
    • s \u548c t \u90fd\u53ea\u5305\u542b\u6570\u5b57\u5b57\u7b26\uff0c\u5373 '0' \u5230 '9' \u3002
    • \n
    \n", "tags_en": ["Greedy", "String"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isTransformable(string s, string t) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isTransformable(String s, String t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isTransformable(self, s, t):\n \"\"\"\n :type s: str\n :type t: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isTransformable(self, s: str, t: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isTransformable(char * s, char * t){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsTransformable(string s, string t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string} t\n * @return {boolean}\n */\nvar isTransformable = function(s, t) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String} t\n# @return {Boolean}\ndef is_transformable(s, t)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isTransformable(_ s: String, _ t: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isTransformable(s string, t string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isTransformable(s: String, t: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isTransformable(s: String, t: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_transformable(s: String, t: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String $t\n * @return Boolean\n */\n function isTransformable($s, $t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isTransformable(s: string, t: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-transformable s t)\n (-> string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1585](https://leetcode-cn.com/problems/check-if-string-is-transformable-with-substring-sort-operations)", "[\u68c0\u67e5\u5b57\u7b26\u4e32\u662f\u5426\u53ef\u4ee5\u901a\u8fc7\u6392\u5e8f\u5b50\u5b57\u7b26\u4e32\u5f97\u5230\u53e6\u4e00\u4e2a\u5b57\u7b26\u4e32](/solution/1500-1599/1585.Check%20If%20String%20Is%20Transformable%20With%20Substring%20Sort%20Operations/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u5b57\u7b26\u4e32`", "\u56f0\u96be", ""], "md_table_row_en": ["[1585](https://leetcode.com/problems/check-if-string-is-transformable-with-substring-sort-operations)", "[Check If String Is Transformable With Substring Sort Operations](/solution/1500-1599/1585.Check%20If%20String%20Is%20Transformable%20With%20Substring%20Sort%20Operations/README_EN.md)", "`Greedy`,`String`", "Hard", ""]}, {"question_id": "1706", "frontend_question_id": "1584", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/min-cost-to-connect-all-points", "url_en": "https://leetcode.com/problems/min-cost-to-connect-all-points", "relative_path_cn": "/solution/1500-1599/1584.Min%20Cost%20to%20Connect%20All%20Points/README.md", "relative_path_en": "/solution/1500-1599/1584.Min%20Cost%20to%20Connect%20All%20Points/README_EN.md", "title_cn": "\u8fde\u63a5\u6240\u6709\u70b9\u7684\u6700\u5c0f\u8d39\u7528", "title_en": "Min Cost to Connect All Points", "question_title_slug": "min-cost-to-connect-all-points", "content_en": "

    You are given an array points representing integer coordinates of some points on a 2D-plane, where points[i] = [xi, yi].

    \n\n

    The cost of connecting two points [xi, yi] and [xj, yj] is the manhattan distance between them: |xi - xj| + |yi - yj|, where |val| denotes the absolute value of val.

    \n\n

    Return the minimum cost to make all points connected. All points are connected if there is exactly one simple path between any two points.

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: points = [[0,0],[2,2],[3,10],[5,2],[7,0]]\nOutput: 20\nExplanation:\n\"\"\nWe can connect the points as shown above to get the minimum cost of 20.\nNotice that there is a unique path between every pair of points.\n
    \n\n

    Example 2:

    \n\n
    \nInput: points = [[3,12],[-2,5],[-4,1]]\nOutput: 18\n
    \n\n

    Example 3:

    \n\n
    \nInput: points = [[0,0],[1,1],[1,0],[-1,1]]\nOutput: 4\n
    \n\n

    Example 4:

    \n\n
    \nInput: points = [[-1000000,-1000000],[1000000,1000000]]\nOutput: 4000000\n
    \n\n

    Example 5:

    \n\n
    \nInput: points = [[0,0]]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= points.length <= 1000
    • \n\t
    • -106 <= xi, yi <= 106
    • \n\t
    • All pairs (xi, yi) are distinct.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2apoints \u6570\u7ec4\uff0c\u8868\u793a 2D \u5e73\u9762\u4e0a\u7684\u4e00\u4e9b\u70b9\uff0c\u5176\u4e2d points[i] = [xi, yi] \u3002

    \n\n

    \u8fde\u63a5\u70b9 [xi, yi] \u548c\u70b9 [xj, yj] \u7684\u8d39\u7528\u4e3a\u5b83\u4eec\u4e4b\u95f4\u7684 \u66fc\u54c8\u987f\u8ddd\u79bb \uff1a|xi - xj| + |yi - yj| \uff0c\u5176\u4e2d |val| \u8868\u793a val \u7684\u7edd\u5bf9\u503c\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u5c06\u6240\u6709\u70b9\u8fde\u63a5\u7684\u6700\u5c0f\u603b\u8d39\u7528\u3002\u53ea\u6709\u4efb\u610f\u4e24\u70b9\u4e4b\u95f4 \u6709\u4e14\u4ec5\u6709 \u4e00\u6761\u7b80\u5355\u8def\u5f84\u65f6\uff0c\u624d\u8ba4\u4e3a\u6240\u6709\u70b9\u90fd\u5df2\u8fde\u63a5\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1apoints = [[0,0],[2,2],[3,10],[5,2],[7,0]]\n\u8f93\u51fa\uff1a20\n\u89e3\u91ca\uff1a\n\"\"\n\u6211\u4eec\u53ef\u4ee5\u6309\u7167\u4e0a\u56fe\u6240\u793a\u8fde\u63a5\u6240\u6709\u70b9\u5f97\u5230\u6700\u5c0f\u603b\u8d39\u7528\uff0c\u603b\u8d39\u7528\u4e3a 20 \u3002\n\u6ce8\u610f\u5230\u4efb\u610f\u4e24\u4e2a\u70b9\u4e4b\u95f4\u53ea\u6709\u552f\u4e00\u4e00\u6761\u8def\u5f84\u4e92\u76f8\u5230\u8fbe\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1apoints = [[3,12],[-2,5],[-4,1]]\n\u8f93\u51fa\uff1a18\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1apoints = [[0,0],[1,1],[1,0],[-1,1]]\n\u8f93\u51fa\uff1a4\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1apoints = [[-1000000,-1000000],[1000000,1000000]]\n\u8f93\u51fa\uff1a4000000\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1apoints = [[0,0]]\n\u8f93\u51fa\uff1a0\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= points.length <= 1000
    • \n\t
    • -106 <= xi, yi <= 106
    • \n\t
    • \u6240\u6709\u70b9 (xi, yi) \u4e24\u4e24\u4e0d\u540c\u3002
    • \n
    \n", "tags_en": ["Union Find"], "tags_cn": ["\u5e76\u67e5\u96c6"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minCostConnectPoints(vector>& points) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minCostConnectPoints(int[][] points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minCostConnectPoints(self, points):\n \"\"\"\n :type points: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minCostConnectPoints(self, points: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minCostConnectPoints(int** points, int pointsSize, int* pointsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinCostConnectPoints(int[][] points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} points\n * @return {number}\n */\nvar minCostConnectPoints = function(points) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} points\n# @return {Integer}\ndef min_cost_connect_points(points)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minCostConnectPoints(_ points: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minCostConnectPoints(points [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minCostConnectPoints(points: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minCostConnectPoints(points: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_cost_connect_points(points: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $points\n * @return Integer\n */\n function minCostConnectPoints($points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minCostConnectPoints(points: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-cost-connect-points points)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1584](https://leetcode-cn.com/problems/min-cost-to-connect-all-points)", "[\u8fde\u63a5\u6240\u6709\u70b9\u7684\u6700\u5c0f\u8d39\u7528](/solution/1500-1599/1584.Min%20Cost%20to%20Connect%20All%20Points/README.md)", "`\u5e76\u67e5\u96c6`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1584](https://leetcode.com/problems/min-cost-to-connect-all-points)", "[Min Cost to Connect All Points](/solution/1500-1599/1584.Min%20Cost%20to%20Connect%20All%20Points/README_EN.md)", "`Union Find`", "Medium", ""]}, {"question_id": "1705", "frontend_question_id": "1583", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-unhappy-friends", "url_en": "https://leetcode.com/problems/count-unhappy-friends", "relative_path_cn": "/solution/1500-1599/1583.Count%20Unhappy%20Friends/README.md", "relative_path_en": "/solution/1500-1599/1583.Count%20Unhappy%20Friends/README_EN.md", "title_cn": "\u7edf\u8ba1\u4e0d\u5f00\u5fc3\u7684\u670b\u53cb", "title_en": "Count Unhappy Friends", "question_title_slug": "count-unhappy-friends", "content_en": "

    You are given a list of preferences for n friends, where n is always even.

    \n\n

    For each person ipreferences[i] contains a list of friends sorted in the order of preference. In other words, a friend earlier in the list is more preferred than a friend later in the list. Friends in each list are denoted by integers from 0 to n-1.

    \n\n

    All the friends are divided into pairs. The pairings are given in a list pairs, where pairs[i] = [xi, yi] denotes xi is paired with yi and yi is paired with xi.

    \n\n

    However, this pairing may cause some of the friends to be unhappy. A friend x is unhappy if x is paired with y and there exists a friend u who is paired with v but:

    \n\n
      \n\t
    • x prefers u over y, and
    • \n\t
    • u prefers x over v.
    • \n
    \n\n

    Return the number of unhappy friends.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 4, preferences = [[1, 2, 3], [3, 2, 0], [3, 1, 0], [1, 2, 0]], pairs = [[0, 1], [2, 3]]\nOutput: 2\nExplanation:\nFriend 1 is unhappy because:\n- 1 is paired with 0 but prefers 3 over 0, and\n- 3 prefers 1 over 2.\nFriend 3 is unhappy because:\n- 3 is paired with 2 but prefers 1 over 2, and\n- 1 prefers 3 over 0.\nFriends 0 and 2 are happy.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 2, preferences = [[1], [0]], pairs = [[1, 0]]\nOutput: 0\nExplanation: Both friends 0 and 1 are happy.\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 4, preferences = [[1, 3, 2], [2, 3, 0], [1, 3, 0], [0, 2, 1]], pairs = [[1, 3], [0, 2]]\nOutput: 4\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= n <= 500
    • \n\t
    • n is even.
    • \n\t
    • preferences.length == n
    • \n\t
    • preferences[i].length == n - 1
    • \n\t
    • 0 <= preferences[i][j] <= n - 1
    • \n\t
    • preferences[i] does not contain i.
    • \n\t
    • All values in preferences[i] are unique.
    • \n\t
    • pairs.length == n/2
    • \n\t
    • pairs[i].length == 2
    • \n\t
    • xi != yi
    • \n\t
    • 0 <= xi, yi <= n - 1
    • \n\t
    • Each person is contained in exactly one pair.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4efd n \u4f4d\u670b\u53cb\u7684\u4eb2\u8fd1\u7a0b\u5ea6\u5217\u8868\uff0c\u5176\u4e2d n \u603b\u662f \u5076\u6570 \u3002

    \n\n

    \u5bf9\u6bcf\u4f4d\u670b\u53cb i\uff0cpreferences[i] \u5305\u542b\u4e00\u4efd \u6309\u4eb2\u8fd1\u7a0b\u5ea6\u4ece\u9ad8\u5230\u4f4e\u6392\u5217 \u7684\u670b\u53cb\u5217\u8868\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u6392\u5728\u5217\u8868\u524d\u9762\u7684\u670b\u53cb\u4e0e i \u7684\u4eb2\u8fd1\u7a0b\u5ea6\u6bd4\u6392\u5728\u5217\u8868\u540e\u9762\u7684\u670b\u53cb\u66f4\u9ad8\u3002\u6bcf\u4e2a\u5217\u8868\u4e2d\u7684\u670b\u53cb\u5747\u4ee5 0 \u5230 n-1 \u4e4b\u95f4\u7684\u6574\u6570\u8868\u793a\u3002

    \n\n

    \u6240\u6709\u7684\u670b\u53cb\u88ab\u5206\u6210\u51e0\u5bf9\uff0c\u914d\u5bf9\u60c5\u51b5\u4ee5\u5217\u8868 pairs \u7ed9\u51fa\uff0c\u5176\u4e2d pairs[i] = [xi, yi] \u8868\u793a xi \u4e0e yi \u914d\u5bf9\uff0c\u4e14 yi \u4e0e xi \u914d\u5bf9\u3002

    \n\n

    \u4f46\u662f\uff0c\u8fd9\u6837\u7684\u914d\u5bf9\u60c5\u51b5\u53ef\u80fd\u4f1a\u662f\u5176\u4e2d\u90e8\u5206\u670b\u53cb\u611f\u5230\u4e0d\u5f00\u5fc3\u3002\u5728 x \u4e0e y \u914d\u5bf9\u4e14 u \u4e0e v \u914d\u5bf9\u7684\u60c5\u51b5\u4e0b\uff0c\u5982\u679c\u540c\u65f6\u6ee1\u8db3\u4e0b\u8ff0\u4e24\u4e2a\u6761\u4ef6\uff0cx \u5c31\u4f1a\u4e0d\u5f00\u5fc3\uff1a

    \n\n
      \n\t
    • x \u4e0e u \u7684\u4eb2\u8fd1\u7a0b\u5ea6\u80dc\u8fc7 x \u4e0e y\uff0c\u4e14
    • \n\t
    • u \u4e0e x \u7684\u4eb2\u8fd1\u7a0b\u5ea6\u80dc\u8fc7 u \u4e0e v
    • \n
    \n\n

    \u8fd4\u56de \u4e0d\u5f00\u5fc3\u7684\u670b\u53cb\u7684\u6570\u76ee \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1an = 4, preferences = [[1, 2, 3], [3, 2, 0], [3, 1, 0], [1, 2, 0]], pairs = [[0, 1], [2, 3]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n\u670b\u53cb 1 \u4e0d\u5f00\u5fc3\uff0c\u56e0\u4e3a\uff1a\n- 1 \u4e0e 0 \u914d\u5bf9\uff0c\u4f46 1 \u4e0e 3 \u7684\u4eb2\u8fd1\u7a0b\u5ea6\u6bd4 1 \u4e0e 0 \u9ad8\uff0c\u4e14\n- 3 \u4e0e 1 \u7684\u4eb2\u8fd1\u7a0b\u5ea6\u6bd4 3 \u4e0e 2 \u9ad8\u3002\n\u670b\u53cb 3 \u4e0d\u5f00\u5fc3\uff0c\u56e0\u4e3a\uff1a\n- 3 \u4e0e 2 \u914d\u5bf9\uff0c\u4f46 3 \u4e0e 1 \u7684\u4eb2\u8fd1\u7a0b\u5ea6\u6bd4 3 \u4e0e 2 \u9ad8\uff0c\u4e14\n- 1 \u4e0e 3 \u7684\u4eb2\u8fd1\u7a0b\u5ea6\u6bd4 1 \u4e0e 0 \u9ad8\u3002\n\u670b\u53cb 0 \u548c 2 \u90fd\u662f\u5f00\u5fc3\u7684\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1an = 2, preferences = [[1], [0]], pairs = [[1, 0]]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u670b\u53cb 0 \u548c 1 \u90fd\u5f00\u5fc3\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1an = 4, preferences = [[1, 3, 2], [2, 3, 0], [1, 3, 0], [0, 2, 1]], pairs = [[1, 3], [0, 2]]\n\u8f93\u51fa\uff1a4\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= n <= 500
    • \n\t
    • n \u662f\u5076\u6570
    • \n\t
    • preferences.length == n
    • \n\t
    • preferences[i].length == n - 1
    • \n\t
    • 0 <= preferences[i][j] <= n - 1
    • \n\t
    • preferences[i] \u4e0d\u5305\u542b i
    • \n\t
    • preferences[i] \u4e2d\u7684\u6240\u6709\u503c\u90fd\u662f\u72ec\u4e00\u65e0\u4e8c\u7684
    • \n\t
    • pairs.length == n/2
    • \n\t
    • pairs[i].length == 2
    • \n\t
    • xi != yi
    • \n\t
    • 0 <= xi, yi <= n - 1
    • \n\t
    • \u6bcf\u4f4d\u670b\u53cb\u90fd \u6070\u597d \u88ab\u5305\u542b\u5728\u4e00\u5bf9\u4e2d
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int unhappyFriends(int n, vector>& preferences, vector>& pairs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int unhappyFriends(int n, int[][] preferences, int[][] pairs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def unhappyFriends(self, n, preferences, pairs):\n \"\"\"\n :type n: int\n :type preferences: List[List[int]]\n :type pairs: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def unhappyFriends(self, n: int, preferences: List[List[int]], pairs: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint unhappyFriends(int n, int** preferences, int preferencesSize, int* preferencesColSize, int** pairs, int pairsSize, int* pairsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int UnhappyFriends(int n, int[][] preferences, int[][] pairs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} preferences\n * @param {number[][]} pairs\n * @return {number}\n */\nvar unhappyFriends = function(n, preferences, pairs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} preferences\n# @param {Integer[][]} pairs\n# @return {Integer}\ndef unhappy_friends(n, preferences, pairs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func unhappyFriends(_ n: Int, _ preferences: [[Int]], _ pairs: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func unhappyFriends(n int, preferences [][]int, pairs [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def unhappyFriends(n: Int, preferences: Array[Array[Int]], pairs: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun unhappyFriends(n: Int, preferences: Array, pairs: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn unhappy_friends(n: i32, preferences: Vec>, pairs: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $preferences\n * @param Integer[][] $pairs\n * @return Integer\n */\n function unhappyFriends($n, $preferences, $pairs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function unhappyFriends(n: number, preferences: number[][], pairs: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (unhappy-friends n preferences pairs)\n (-> exact-integer? (listof (listof exact-integer?)) (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1583](https://leetcode-cn.com/problems/count-unhappy-friends)", "[\u7edf\u8ba1\u4e0d\u5f00\u5fc3\u7684\u670b\u53cb](/solution/1500-1599/1583.Count%20Unhappy%20Friends/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1583](https://leetcode.com/problems/count-unhappy-friends)", "[Count Unhappy Friends](/solution/1500-1599/1583.Count%20Unhappy%20Friends/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "1704", "frontend_question_id": "1582", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/special-positions-in-a-binary-matrix", "url_en": "https://leetcode.com/problems/special-positions-in-a-binary-matrix", "relative_path_cn": "/solution/1500-1599/1582.Special%20Positions%20in%20a%20Binary%20Matrix/README.md", "relative_path_en": "/solution/1500-1599/1582.Special%20Positions%20in%20a%20Binary%20Matrix/README_EN.md", "title_cn": "\u4e8c\u8fdb\u5236\u77e9\u9635\u4e2d\u7684\u7279\u6b8a\u4f4d\u7f6e", "title_en": "Special Positions in a Binary Matrix", "question_title_slug": "special-positions-in-a-binary-matrix", "content_en": "

    Given a rows x cols matrix mat, where mat[i][j] is either 0 or 1, return the number of special positions in mat.

    \n\n

    A position (i,j) is called special if mat[i][j] == 1 and all other elements in row i and column j are 0 (rows and columns are 0-indexed).

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: mat = [[1,0,0],\n              [0,0,1],\n              [1,0,0]]\nOutput: 1\nExplanation: (1,2) is a special position because mat[1][2] == 1 and all other elements in row 1 and column 2 are 0.\n
    \n\n

    Example 2:

    \n\n
    \nInput: mat = [[1,0,0],\n              [0,1,0],\n              [0,0,1]]\nOutput: 3\nExplanation: (0,0), (1,1) and (2,2) are special positions. \n
    \n\n

    Example 3:

    \n\n
    \nInput: mat = [[0,0,0,1],\n              [1,0,0,0],\n              [0,1,1,0],\n              [0,0,0,0]]\nOutput: 2\n
    \n\n

    Example 4:

    \n\n
    \nInput: mat = [[0,0,0,0,0],\n              [1,0,0,0,0],\n              [0,1,0,0,0],\n              [0,0,1,0,0],\n              [0,0,0,1,1]]\nOutput: 3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • rows == mat.length
    • \n\t
    • cols == mat[i].length
    • \n\t
    • 1 <= rows, cols <= 100
    • \n\t
    • mat[i][j] is 0 or 1.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5927\u5c0f\u4e3a rows x cols \u7684\u77e9\u9635 mat\uff0c\u5176\u4e2d mat[i][j] \u662f 0 \u6216 1\uff0c\u8bf7\u8fd4\u56de \u77e9\u9635 mat \u4e2d\u7279\u6b8a\u4f4d\u7f6e\u7684\u6570\u76ee \u3002

    \n\n

    \u7279\u6b8a\u4f4d\u7f6e \u5b9a\u4e49\uff1a\u5982\u679c mat[i][j] == 1 \u5e76\u4e14\u7b2c i \u884c\u548c\u7b2c j \u5217\u4e2d\u7684\u6240\u6709\u5176\u4ed6\u5143\u7d20\u5747\u4e3a 0\uff08\u884c\u548c\u5217\u7684\u4e0b\u6807\u5747 \u4ece 0 \u5f00\u59cb \uff09\uff0c\u5219\u4f4d\u7f6e (i, j) \u88ab\u79f0\u4e3a\u7279\u6b8a\u4f4d\u7f6e\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1amat = [[1,0,0],\n            [0,0,1],\n            [1,0,0]]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a(1,2) \u662f\u4e00\u4e2a\u7279\u6b8a\u4f4d\u7f6e\uff0c\u56e0\u4e3a mat[1][2] == 1 \u4e14\u6240\u5904\u7684\u884c\u548c\u5217\u4e0a\u6240\u6709\u5176\u4ed6\u5143\u7d20\u90fd\u662f 0\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1amat = [[1,0,0],\n            [0,1,0],\n            [0,0,1]]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a(0,0), (1,1) \u548c (2,2) \u90fd\u662f\u7279\u6b8a\u4f4d\u7f6e\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1amat = [[0,0,0,1],\n            [1,0,0,0],\n            [0,1,1,0],\n            [0,0,0,0]]\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1amat = [[0,0,0,0,0],\n            [1,0,0,0,0],\n            [0,1,0,0,0],\n            [0,0,1,0,0],\n            [0,0,0,1,1]]\n\u8f93\u51fa\uff1a3\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • rows == mat.length
    • \n\t
    • cols == mat[i].length
    • \n\t
    • 1 <= rows, cols <= 100
    • \n\t
    • mat[i][j] \u662f 0 \u6216 1
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numSpecial(vector>& mat) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numSpecial(int[][] mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numSpecial(self, mat):\n \"\"\"\n :type mat: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numSpecial(self, mat: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numSpecial(int** mat, int matSize, int* matColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumSpecial(int[][] mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} mat\n * @return {number}\n */\nvar numSpecial = function(mat) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} mat\n# @return {Integer}\ndef num_special(mat)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numSpecial(_ mat: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numSpecial(mat [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numSpecial(mat: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numSpecial(mat: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_special(mat: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $mat\n * @return Integer\n */\n function numSpecial($mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numSpecial(mat: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-special mat)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1582](https://leetcode-cn.com/problems/special-positions-in-a-binary-matrix)", "[\u4e8c\u8fdb\u5236\u77e9\u9635\u4e2d\u7684\u7279\u6b8a\u4f4d\u7f6e](/solution/1500-1599/1582.Special%20Positions%20in%20a%20Binary%20Matrix/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1582](https://leetcode.com/problems/special-positions-in-a-binary-matrix)", "[Special Positions in a Binary Matrix](/solution/1500-1599/1582.Special%20Positions%20in%20a%20Binary%20Matrix/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1703", "frontend_question_id": "1564", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/put-boxes-into-the-warehouse-i", "url_en": "https://leetcode.com/problems/put-boxes-into-the-warehouse-i", "relative_path_cn": "/solution/1500-1599/1564.Put%20Boxes%20Into%20the%20Warehouse%20I/README.md", "relative_path_en": "/solution/1500-1599/1564.Put%20Boxes%20Into%20the%20Warehouse%20I/README_EN.md", "title_cn": "\u628a\u7bb1\u5b50\u653e\u8fdb\u4ed3\u5e93\u91cc I", "title_en": "Put Boxes Into the Warehouse I", "question_title_slug": "put-boxes-into-the-warehouse-i", "content_en": "

    You are given two arrays of positive integers, boxes and warehouse, representing the heights of some boxes of unit width and the heights of n rooms in a warehouse respectively. The warehouse's rooms are labelled from 0 to n - 1 from left to right where warehouse[i] (0-indexed) is the height of the ith room.

    \n\n

    Boxes are put into the warehouse by the following rules:

    \n\n
      \n\t
    • Boxes cannot be stacked.
    • \n\t
    • You can rearrange the insertion order of the boxes.
    • \n\t
    • Boxes can only be pushed into the warehouse from left to right only.
    • \n\t
    • If the height of some room in the warehouse is less than the height of a box, then that box and all other boxes behind it will be stopped before that room.
    • \n
    \n\n

    Return the maximum number of boxes you can put into the warehouse.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: boxes = [4,3,4,1], warehouse = [5,3,3,4,1]\nOutput: 3\nExplanation: \n\"\"\nWe can first put the box of height 1 in room 4. Then we can put the box of height 3 in either of the 3 rooms 1, 2, or 3. Lastly, we can put one box of height 4 in room 0.\nThere is no way we can fit all 4 boxes in the warehouse.
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: boxes = [1,2,2,3,4], warehouse = [3,4,1,2]\nOutput: 3\nExplanation: \n\"\"\nNotice that it's not possible to put the box of height 4 into the warehouse since it cannot pass the first room of height 3.\nAlso, for the last two rooms, 2 and 3, only boxes of height 1 can fit.\nWe can fit 3 boxes maximum as shown above. The yellow box can also be put in room 2 instead.\nSwapping the orange and green boxes is also valid, or swapping one of them with the red box.
    \n\n

    Example 3:

    \n\n
    \nInput: boxes = [1,2,3], warehouse = [1,2,3,4]\nOutput: 1\nExplanation: Since the first room in the warehouse is of height 1, we can only put boxes of height 1.\n
    \n\n

    Example 4:

    \n\n
    \nInput: boxes = [4,5,6], warehouse = [3,3,3,3,3]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == warehouse.length
    • \n\t
    • 1 <= boxes.length, warehouse.length <= 10^5
    • \n\t
    • 1 <= boxes[i], warehouse[i] <= 10^9
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u6b63\u6574\u6570\u6570\u7ec4\u00a0boxes\u00a0\u548c\u00a0warehouse\u00a0\uff0c\u5206\u522b\u5305\u542b\u5355\u4f4d\u5bbd\u5ea6\u7684\u7bb1\u5b50\u7684\u9ad8\u5ea6\uff0c\u4ee5\u53ca\u4ed3\u5e93\u4e2d n \u4e2a\u623f\u95f4\u5404\u81ea\u7684\u9ad8\u5ea6\u3002\u4ed3\u5e93\u7684\u623f\u95f4\u5206\u522b\u4ece\u00a00\u00a0\u5230\u00a0n - 1\u00a0\u81ea\u5de6\u5411\u53f3\u7f16\u53f7\uff0c\u00a0warehouse[i]\u00a0\uff08\u7d22\u5f15\u4ece 0 \u5f00\u59cb\uff09\u662f\u7b2c\u00a0i\u00a0\u4e2a\u623f\u95f4\u7684\u9ad8\u5ea6\u3002

    \n\n

    \u7bb1\u5b50\u653e\u8fdb\u4ed3\u5e93\u65f6\u9075\u5faa\u4e0b\u5217\u89c4\u5219\uff1a

    \n\n
      \n\t
    • \u7bb1\u5b50\u4e0d\u53ef\u53e0\u653e\u3002
    • \n\t
    • \u4f60\u53ef\u4ee5\u91cd\u65b0\u8c03\u6574\u7bb1\u5b50\u7684\u987a\u5e8f\u3002
    • \n\t
    • \u7bb1\u5b50\u53ea\u80fd\u4ece\u5de6\u5411\u53f3\u63a8\u8fdb\u4ed3\u5e93\u4e2d\u3002
    • \n\t
    • \u5982\u679c\u4ed3\u5e93\u4e2d\u67d0\u623f\u95f4\u7684\u9ad8\u5ea6\u5c0f\u4e8e\u67d0\u7bb1\u5b50\u7684\u9ad8\u5ea6\uff0c\u5219\u8fd9\u4e2a\u7bb1\u5b50\u548c\u4e4b\u540e\u7684\u7bb1\u5b50\u90fd\u4f1a\u505c\u5728\u8fd9\u4e2a\u623f\u95f4\u7684\u524d\u9762\u3002
    • \n
    \n\n

    \u4f60\u6700\u591a\u53ef\u4ee5\u5728\u4ed3\u5e93\u4e2d\u653e\u8fdb\u591a\u5c11\u4e2a\u7bb1\u5b50\uff1f

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aboxes = [4,3,4,1], warehouse = [5,3,3,4,1]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\n\"\"\n\u6211\u4eec\u53ef\u4ee5\u5148\u628a\u9ad8\u5ea6\u4e3a 1 \u7684\u7bb1\u5b50\u653e\u5165 4 \u53f7\u623f\u95f4\uff0c\u7136\u540e\u518d\u628a\u9ad8\u5ea6\u4e3a 3 \u7684\u7bb1\u5b50\u653e\u5165 1 \u53f7\u3001 2 \u53f7\u6216 3 \u53f7\u623f\u95f4\uff0c\u6700\u540e\u518d\u628a\u9ad8\u5ea6\u4e3a 4 \u7684\u7bb1\u5b50\u653e\u5165 0 \u53f7\u623f\u95f4\u3002\n\u6211\u4eec\u4e0d\u53ef\u80fd\u628a\u6240\u6709 4 \u4e2a\u7bb1\u5b50\u5168\u90e8\u653e\u8fdb\u4ed3\u5e93\u91cc\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aboxes = [1,2,2,3,4], warehouse = [3,4,1,2]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\n\"\"\n\u6211\u4eec\u6ce8\u610f\u5230\uff0c\u4e0d\u53ef\u80fd\u628a\u9ad8\u5ea6\u4e3a 4 \u7684\u7bb1\u5b50\u653e\u5165\u4ed3\u5e93\u4e2d\uff0c\u56e0\u4e3a\u5b83\u4e0d\u80fd\u901a\u8fc7\u9ad8\u5ea6\u4e3a 3 \u7684\u623f\u95f4\u3002\n\u800c\u4e14\uff0c\u5bf9\u4e8e\u6700\u540e\u4e24\u4e2a\u623f\u95f4 2 \u53f7\u548c 3 \u53f7\u6765\u8bf4\uff0c\u53ea\u6709\u9ad8\u5ea6\u4e3a 1 \u7684\u7bb1\u5b50\u53ef\u4ee5\u653e\u8fdb\u53bb\u3002\n\u6211\u4eec\u6700\u591a\u53ef\u4ee5\u653e\u8fdb 3 \u4e2a\u7bb1\u5b50\uff0c\u5982\u4e0a\u56fe\u6240\u793a\u3002\u9ec4\u8272\u7684\u7bb1\u5b50\u4e5f\u53ef\u4ee5\u653e\u5165 2 \u53f7\u623f\u95f4\u3002\n\u4ea4\u6362\u6a59\u8272\u548c\u7eff\u8272\u7bb1\u5b50\u7684\u4f4d\u7f6e\uff0c\u6216\u662f\u5c06\u8fd9\u4e24\u4e2a\u7bb1\u5b50\u4e0e\u7ea2\u8272\u7bb1\u5b50\u4ea4\u6362\u4f4d\u7f6e\uff0c\u4e5f\u662f\u53ef\u4ee5\u7684\u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aboxes = [1,2,3], warehouse = [1,2,3,4]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u7531\u4e8e\u7b2c\u4e00\u4e2a\u623f\u95f4\u7684\u9ad8\u5ea6\u4e3a 1\uff0c\u6211\u4eec\u53ea\u80fd\u653e\u8fdb\u9ad8\u5ea6\u4e3a 1 \u7684\u7bb1\u5b50\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1aboxes = [4,5,6], warehouse = [3,3,3,3,3]\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == warehouse.length
    • \n\t
    • 1 <= boxes.length, warehouse.length <= 10^5
    • \n\t
    • 1 <= boxes[i], warehouse[i] <= 10^9
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxBoxesInWarehouse(vector& boxes, vector& warehouse) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxBoxesInWarehouse(int[] boxes, int[] warehouse) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxBoxesInWarehouse(self, boxes, warehouse):\n \"\"\"\n :type boxes: List[int]\n :type warehouse: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxBoxesInWarehouse(self, boxes: List[int], warehouse: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxBoxesInWarehouse(int* boxes, int boxesSize, int* warehouse, int warehouseSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxBoxesInWarehouse(int[] boxes, int[] warehouse) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} boxes\n * @param {number[]} warehouse\n * @return {number}\n */\nvar maxBoxesInWarehouse = function(boxes, warehouse) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} boxes\n# @param {Integer[]} warehouse\n# @return {Integer}\ndef max_boxes_in_warehouse(boxes, warehouse)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxBoxesInWarehouse(_ boxes: [Int], _ warehouse: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxBoxesInWarehouse(boxes []int, warehouse []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxBoxesInWarehouse(boxes: Array[Int], warehouse: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxBoxesInWarehouse(boxes: IntArray, warehouse: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_boxes_in_warehouse(boxes: Vec, warehouse: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $boxes\n * @param Integer[] $warehouse\n * @return Integer\n */\n function maxBoxesInWarehouse($boxes, $warehouse) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxBoxesInWarehouse(boxes: number[], warehouse: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-boxes-in-warehouse boxes warehouse)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1564](https://leetcode-cn.com/problems/put-boxes-into-the-warehouse-i)", "[\u628a\u7bb1\u5b50\u653e\u8fdb\u4ed3\u5e93\u91cc I](/solution/1500-1599/1564.Put%20Boxes%20Into%20the%20Warehouse%20I/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1564](https://leetcode.com/problems/put-boxes-into-the-warehouse-i)", "[Put Boxes Into the Warehouse I](/solution/1500-1599/1564.Put%20Boxes%20Into%20the%20Warehouse%20I/README_EN.md)", "`Greedy`", "Medium", "\ud83d\udd12"]}, {"question_id": "1702", "frontend_question_id": "1555", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/bank-account-summary", "url_en": "https://leetcode.com/problems/bank-account-summary", "relative_path_cn": "/solution/1500-1599/1555.Bank%20Account%20Summary/README.md", "relative_path_en": "/solution/1500-1599/1555.Bank%20Account%20Summary/README_EN.md", "title_cn": "\u94f6\u884c\u8d26\u6237\u6982\u8981", "title_en": "Bank Account Summary", "question_title_slug": "bank-account-summary", "content_en": "

    Table: Users

    \n\n
    \n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| user_id      | int     |\n| user_name    | varchar |\n| credit       | int     |\n+--------------+---------+\nuser_id is the primary key for this table.\nEach row of this table contains the current credit information for each user.\n
    \n\n

     

    \n\n

    Table: Transactions

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| trans_id      | int     |\n| paid_by       | int     |\n| paid_to       | int     |\n| amount        | int     |\n| transacted_on | date    |\n+---------------+---------+\ntrans_id is the primary key for this table.\nEach row of this table contains the information about the transaction in the bank.\nUser with id (paid_by) transfer money to user with id (paid_to).\n
    \n\n

     

    \n\n

    Leetcode Bank (LCB) helps its coders in making virtual payments. Our bank records all transactions in the table Transaction, we want to find out the current balance of all users and check wheter they have breached their credit limit (If their current credit is less than 0).

    \n\n

    Write an SQL query to report.

    \n\n
      \n\t
    • user_id
    • \n\t
    • user_name
    • \n\t
    • credit, current balance after performing transactions.  
    • \n\t
    • credit_limit_breached, check credit_limit ("Yes" or "No")
    • \n
    \n\n

    Return the result table in any order.

    \n\n

    The query result format is in the following example.

    \n\n

     

    \n\n
    \nUsers table:\n+------------+--------------+-------------+\n| user_id    | user_name    | credit      |\n+------------+--------------+-------------+\n| 1          | Moustafa     | 100         |\n| 2          | Jonathan     | 200         |\n| 3          | Winston      | 10000       |\n| 4          | Luis         | 800         | \n+------------+--------------+-------------+\n\nTransactions table:\n+------------+------------+------------+----------+---------------+\n| trans_id   | paid_by    | paid_to    | amount   | transacted_on |\n+------------+------------+------------+----------+---------------+\n| 1          | 1          | 3          | 400      | 2020-08-01    |\n| 2          | 3          | 2          | 500      | 2020-08-02    |\n| 3          | 2          | 1          | 200      | 2020-08-03    |\n+------------+------------+------------+----------+---------------+\n\nResult table:\n+------------+------------+------------+-----------------------+\n| user_id    | user_name  | credit     | credit_limit_breached |\n+------------+------------+------------+-----------------------+\n| 1          | Moustafa   | -100       | Yes                   | \n| 2          | Jonathan   | 500        | No                    |\n| 3          | Winston    | 9900       | No                    |\n| 4          | Luis       | 800        | No                    |\n+------------+------------+------------+-----------------------+\nMoustafa paid $400 on "2020-08-01" and received $200 on "2020-08-03", credit (100 -400 +200) = -$100\nJonathan received $500 on "2020-08-02" and paid $200 on "2020-08-08", credit (200 +500 -200) = $500\nWinston received $400 on "2020-08-01" and paid $500 on "2020-08-03", credit (10000 +400 -500) = $9990\nLuis didn't received any transfer, credit = $800
    \n", "content_cn": "

    \u7528\u6237\u8868\uff1a\u00a0Users

    \n\n
    \n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| user_id      | int     |\n| user_name    | varchar |\n| credit       | int     |\n+--------------+---------+\nuser_id \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\u3002\n\u8868\u4e2d\u7684\u6bcf\u4e00\u5217\u5305\u542b\u6bcf\u4e00\u4e2a\u7528\u6237\u5f53\u524d\u7684\u989d\u5ea6\u4fe1\u606f\u3002
    \n\n

    \u00a0

    \n\n

    \u4ea4\u6613\u8868\uff1aTransactions

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| trans_id      | int     |\n| paid_by       | int     |\n| paid_to       | int     |\n| amount        | int     |\n| transacted_on | date    |\n+---------------+---------+\ntrans_id \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\u3002\n\u8868\u4e2d\u7684\u6bcf\u4e00\u5217\u5305\u542b\u94f6\u884c\u7684\u4ea4\u6613\u4fe1\u606f\u3002\nID \u4e3a paid_by \u7684\u7528\u6237\u7ed9 ID \u4e3a paid_to \u7684\u7528\u6237\u8f6c\u8d26\u3002\n
    \n\n

    \u00a0

    \n\n

    \u529b\u6263\u94f6\u884c (LCB) \u5e2e\u52a9\u7a0b\u5e8f\u5458\u4eec\u5b8c\u6210\u865a\u62df\u652f\u4ed8\u3002\u6211\u4eec\u7684\u94f6\u884c\u5728\u8868\u00a0Transaction\u00a0\u4e2d\u8bb0\u5f55\u6bcf\u6761\u4ea4\u6613\u4fe1\u606f\uff0c\u6211\u4eec\u8981\u67e5\u8be2\u6bcf\u4e2a\u7528\u6237\u7684\u5f53\u524d\u4f59\u989d\uff0c\u5e76\u68c0\u67e5\u4ed6\u4eec\u662f\u5426\u5df2\u900f\u652f\uff08\u5f53\u524d\u989d\u5ea6\u5c0f\u4e8e 0\uff09\u3002

    \n\n

    \u5199\u4e00\u6761 SQL \u8bed\u53e5\uff0c\u67e5\u8be2\uff1a

    \n\n
      \n\t
    • user_id\u00a0\u7528\u6237 ID
    • \n\t
    • user_name\u00a0\u7528\u6237\u540d
    • \n\t
    • credit\u00a0\u5b8c\u6210\u4ea4\u6613\u540e\u7684\u4f59\u989d
    • \n\t
    • credit_limit_breached\u00a0\u68c0\u67e5\u662f\u5426\u900f\u652f \uff08\"Yes\" \u6216\u00a0\"No\"\uff09
    • \n
    \n\n

    \u4ee5\u4efb\u610f\u987a\u5e8f\u8fd4\u56de\u7ed3\u679c\u8868\u3002

    \n\n

    \u00a0

    \n\n

    \u67e5\u8be2\u683c\u5f0f\u89c1\u5982\u4e0b\u793a\u4f8b\uff1a

    \n\n
    \nUsers \u8868\uff1a\n+------------+--------------+-------------+\n| user_id    | user_name    | credit      |\n+------------+--------------+-------------+\n| 1          | Moustafa     | 100         |\n| 2          | Jonathan     | 200         |\n| 3          | Winston      | 10000       |\n| 4          | Luis         | 800         | \n+------------+--------------+-------------+\n\nTransactions \u8868\uff1a\n+------------+------------+------------+----------+---------------+\n| trans_id   | paid_by    | paid_to    | amount   | transacted_on |\n+------------+------------+------------+----------+---------------+\n| 1          | 1          | 3          | 400      | 2020-08-01    |\n| 2          | 3          | 2          | 500      | 2020-08-02    |\n| 3          | 2          | 1          | 200      | 2020-08-03    |\n+------------+------------+------------+----------+---------------+\n\n\u7ed3\u679c\u8868\uff1a\n+------------+------------+------------+-----------------------+\n| user_id    | user_name  | credit     | credit_limit_breached |\n+------------+------------+------------+-----------------------+\n| 1          | Moustafa   | -100       | Yes                   | \n| 2          | Jonathan   | 500        | No                    |\n| 3          | Winston    | 9900       | No                    |\n| 4          | Luis       | 800        | No                    |\n+------------+------------+------------+-----------------------+\nMoustafa \u5728 \"2020-08-01\" \u652f\u4ed8\u4e86 $400 \u5e76\u5728 \"2020-08-03\" \u6536\u5230\u4e86 $200 \uff0c\u5f53\u524d\u989d\u5ea6 (100 -400 +200) = -$100\nJonathan \u5728 \"2020-08-02\" \u6536\u5230\u4e86 $500 \u5e76\u5728 \"2020-08-08\" \u652f\u4ed8\u4e86 $200 \uff0c\u5f53\u524d\u989d\u5ea6 (200 +500 -200) = $500\nWinston \u5728 \"2020-08-01\" \u6536\u5230\u4e86 $400 \u5e76\u5728 \"2020-08-03\" \u652f\u4ed8\u4e86 $500 \uff0c\u5f53\u524d\u989d\u5ea6 (10000 +400 -500) = $9900\nLuis \u672a\u6536\u5230\u4efb\u4f55\u8f6c\u8d26\u4fe1\u606f\uff0c\u989d\u5ea6 = $800
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1555](https://leetcode-cn.com/problems/bank-account-summary)", "[\u94f6\u884c\u8d26\u6237\u6982\u8981](/solution/1500-1599/1555.Bank%20Account%20Summary/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1555](https://leetcode.com/problems/bank-account-summary)", "[Bank Account Summary](/solution/1500-1599/1555.Bank%20Account%20Summary/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1701", "frontend_question_id": "1579", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/remove-max-number-of-edges-to-keep-graph-fully-traversable", "url_en": "https://leetcode.com/problems/remove-max-number-of-edges-to-keep-graph-fully-traversable", "relative_path_cn": "/solution/1500-1599/1579.Remove%20Max%20Number%20of%20Edges%20to%20Keep%20Graph%20Fully%20Traversable/README.md", "relative_path_en": "/solution/1500-1599/1579.Remove%20Max%20Number%20of%20Edges%20to%20Keep%20Graph%20Fully%20Traversable/README_EN.md", "title_cn": "\u4fdd\u8bc1\u56fe\u53ef\u5b8c\u5168\u904d\u5386", "title_en": "Remove Max Number of Edges to Keep Graph Fully Traversable", "question_title_slug": "remove-max-number-of-edges-to-keep-graph-fully-traversable", "content_en": "

    Alice and Bob have an undirected graph of n nodes and 3 types of edges:

    \n\n
      \n\t
    • Type 1: Can be traversed by Alice only.
    • \n\t
    • Type 2: Can be traversed by Bob only.
    • \n\t
    • Type 3: Can by traversed by both Alice and Bob.
    • \n
    \n\n

    Given an array edges where edges[i] = [typei, ui, vi] represents a bidirectional edge of type typei between nodes ui and vi, find the maximum number of edges you can remove so that after removing the edges, the graph can still be fully traversed by both Alice and Bob. The graph is fully traversed by Alice and Bob if starting from any node, they can reach all other nodes.

    \n\n

    Return the maximum number of edges you can remove, or return -1 if it's impossible for the graph to be fully traversed by Alice and Bob.

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: n = 4, edges = [[3,1,2],[3,2,3],[1,1,3],[1,2,4],[1,1,2],[2,3,4]]\nOutput: 2\nExplanation: If we remove the 2 edges [1,1,2] and [1,1,3]. The graph will still be fully traversable by Alice and Bob. Removing any additional edge will not make it so. So the maximum number of edges we can remove is 2.\n
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: n = 4, edges = [[3,1,2],[3,2,3],[1,1,4],[2,1,4]]\nOutput: 0\nExplanation: Notice that removing any edge will not make the graph fully traversable by Alice and Bob.\n
    \n\n

    Example 3:

    \n\n

    \"\"

    \n\n
    \nInput: n = 4, edges = [[3,2,3],[1,1,2],[2,3,4]]\nOutput: -1\nExplanation: In the current graph, Alice cannot reach node 4 from the other nodes. Likewise, Bob cannot reach 1. Therefore it's impossible to make the graph fully traversable.
    \n\n

     

    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 10^5
    • \n\t
    • 1 <= edges.length <= min(10^5, 3 * n * (n-1) / 2)
    • \n\t
    • edges[i].length == 3
    • \n\t
    • 1 <= edges[i][0] <= 3
    • \n\t
    • 1 <= edges[i][1] < edges[i][2] <= n
    • \n\t
    • All tuples (typei, ui, vi) are distinct.
    • \n
    \n", "content_cn": "

    Alice \u548c Bob \u5171\u6709\u4e00\u4e2a\u65e0\u5411\u56fe\uff0c\u5176\u4e2d\u5305\u542b n \u4e2a\u8282\u70b9\u548c 3  \u79cd\u7c7b\u578b\u7684\u8fb9\uff1a

    \n\n
      \n\t
    • \u7c7b\u578b 1\uff1a\u53ea\u80fd\u7531 Alice \u904d\u5386\u3002
    • \n\t
    • \u7c7b\u578b 2\uff1a\u53ea\u80fd\u7531 Bob \u904d\u5386\u3002
    • \n\t
    • \u7c7b\u578b 3\uff1aAlice \u548c Bob \u90fd\u53ef\u4ee5\u904d\u5386\u3002
    • \n
    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 edges \uff0c\u5176\u4e2d edges[i] = [typei, ui, vi] \u8868\u793a\u8282\u70b9 ui \u548c vi \u4e4b\u95f4\u5b58\u5728\u7c7b\u578b\u4e3a typei \u7684\u53cc\u5411\u8fb9\u3002\u8bf7\u4f60\u5728\u4fdd\u8bc1\u56fe\u4ecd\u80fd\u591f\u88ab Alice\u548c Bob \u5b8c\u5168\u904d\u5386\u7684\u524d\u63d0\u4e0b\uff0c\u627e\u51fa\u53ef\u4ee5\u5220\u9664\u7684\u6700\u5927\u8fb9\u6570\u3002\u5982\u679c\u4ece\u4efb\u4f55\u8282\u70b9\u5f00\u59cb\uff0cAlice \u548c Bob \u90fd\u53ef\u4ee5\u5230\u8fbe\u6240\u6709\u5176\u4ed6\u8282\u70b9\uff0c\u5219\u8ba4\u4e3a\u56fe\u662f\u53ef\u4ee5\u5b8c\u5168\u904d\u5386\u7684\u3002

    \n\n

    \u8fd4\u56de\u53ef\u4ee5\u5220\u9664\u7684\u6700\u5927\u8fb9\u6570\uff0c\u5982\u679c Alice \u548c Bob \u65e0\u6cd5\u5b8c\u5168\u904d\u5386\u56fe\uff0c\u5219\u8fd4\u56de -1 \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 4, edges = [[3,1,2],[3,2,3],[1,1,3],[1,2,4],[1,1,2],[2,3,4]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5982\u679c\u5220\u9664 [1,1,2] \u548c [1,1,3] \u8fd9\u4e24\u6761\u8fb9\uff0cAlice \u548c Bob \u4ecd\u7136\u53ef\u4ee5\u5b8c\u5168\u904d\u5386\u8fd9\u4e2a\u56fe\u3002\u518d\u5220\u9664\u4efb\u4f55\u5176\u4ed6\u7684\u8fb9\u90fd\u65e0\u6cd5\u4fdd\u8bc1\u56fe\u53ef\u4ee5\u5b8c\u5168\u904d\u5386\u3002\u6240\u4ee5\u53ef\u4ee5\u5220\u9664\u7684\u6700\u5927\u8fb9\u6570\u662f 2 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 4, edges = [[3,1,2],[3,2,3],[1,1,4],[2,1,4]]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6ce8\u610f\uff0c\u5220\u9664\u4efb\u4f55\u4e00\u6761\u8fb9\u90fd\u4f1a\u4f7f Alice \u548c Bob \u65e0\u6cd5\u5b8c\u5168\u904d\u5386\u8fd9\u4e2a\u56fe\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 4, edges = [[3,2,3],[1,1,2],[2,3,4]]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u5728\u5f53\u524d\u56fe\u4e2d\uff0cAlice \u65e0\u6cd5\u4ece\u5176\u4ed6\u8282\u70b9\u5230\u8fbe\u8282\u70b9 4 \u3002\u7c7b\u4f3c\u5730\uff0cBob \u4e5f\u4e0d\u80fd\u8fbe\u5230\u8282\u70b9 1 \u3002\u56e0\u6b64\uff0c\u56fe\u65e0\u6cd5\u5b8c\u5168\u904d\u5386\u3002
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 10^5
    • \n\t
    • 1 <= edges.length <= min(10^5, 3 * n * (n-1) / 2)
    • \n\t
    • edges[i].length == 3
    • \n\t
    • 1 <= edges[i][0] <= 3
    • \n\t
    • 1 <= edges[i][1] < edges[i][2] <= n
    • \n\t
    • \u6240\u6709\u5143\u7ec4 (typei, ui, vi) \u4e92\u4e0d\u76f8\u540c
    • \n
    \n", "tags_en": ["Union Find"], "tags_cn": ["\u5e76\u67e5\u96c6"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxNumEdgesToRemove(int n, vector>& edges) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxNumEdgesToRemove(int n, int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxNumEdgesToRemove(self, n, edges):\n \"\"\"\n :type n: int\n :type edges: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxNumEdgesToRemove(self, n: int, edges: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxNumEdgesToRemove(int n, int** edges, int edgesSize, int* edgesColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxNumEdgesToRemove(int n, int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} edges\n * @return {number}\n */\nvar maxNumEdgesToRemove = function(n, edges) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} edges\n# @return {Integer}\ndef max_num_edges_to_remove(n, edges)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxNumEdgesToRemove(_ n: Int, _ edges: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxNumEdgesToRemove(n int, edges [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxNumEdgesToRemove(n: Int, edges: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxNumEdgesToRemove(n: Int, edges: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_num_edges_to_remove(n: i32, edges: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $edges\n * @return Integer\n */\n function maxNumEdgesToRemove($n, $edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxNumEdgesToRemove(n: number, edges: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-num-edges-to-remove n edges)\n (-> exact-integer? (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1579](https://leetcode-cn.com/problems/remove-max-number-of-edges-to-keep-graph-fully-traversable)", "[\u4fdd\u8bc1\u56fe\u53ef\u5b8c\u5168\u904d\u5386](/solution/1500-1599/1579.Remove%20Max%20Number%20of%20Edges%20to%20Keep%20Graph%20Fully%20Traversable/README.md)", "`\u5e76\u67e5\u96c6`", "\u56f0\u96be", ""], "md_table_row_en": ["[1579](https://leetcode.com/problems/remove-max-number-of-edges-to-keep-graph-fully-traversable)", "[Remove Max Number of Edges to Keep Graph Fully Traversable](/solution/1500-1599/1579.Remove%20Max%20Number%20of%20Edges%20to%20Keep%20Graph%20Fully%20Traversable/README_EN.md)", "`Union Find`", "Hard", ""]}, {"question_id": "1700", "frontend_question_id": "1578", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-deletion-cost-to-avoid-repeating-letters", "url_en": "https://leetcode.com/problems/minimum-deletion-cost-to-avoid-repeating-letters", "relative_path_cn": "/solution/1500-1599/1578.Minimum%20Deletion%20Cost%20to%20Avoid%20Repeating%20Letters/README.md", "relative_path_en": "/solution/1500-1599/1578.Minimum%20Deletion%20Cost%20to%20Avoid%20Repeating%20Letters/README_EN.md", "title_cn": "\u907f\u514d\u91cd\u590d\u5b57\u6bcd\u7684\u6700\u5c0f\u5220\u9664\u6210\u672c", "title_en": "Minimum Deletion Cost to Avoid Repeating Letters", "question_title_slug": "minimum-deletion-cost-to-avoid-repeating-letters", "content_en": "

    Given a string s and an array of integers cost where cost[i] is the cost of deleting the ith character in s.

    \n\n

    Return the minimum cost of deletions such that there are no two identical letters next to each other.

    \n\n

    Notice that you will delete the chosen characters at the same time, in other words, after deleting a character, the costs of deleting other characters will not change.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "abaac", cost = [1,2,3,4,5]\nOutput: 3\nExplanation: Delete the letter "a" with cost 3 to get "abac" (String without two identical letters next to each other).\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "abc", cost = [1,2,3]\nOutput: 0\nExplanation: You don't need to delete any character because there are no identical letters next to each other.\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "aabaa", cost = [1,2,3,4,1]\nOutput: 2\nExplanation: Delete the first and the last character, getting the string ("aba").\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • s.length == cost.length
    • \n\t
    • 1 <= s.length, cost.length <= 10^5
    • \n\t
    • 1 <= cost[i] <= 10^4
    • \n\t
    • s contains only lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \u548c\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 cost \uff0c\u5176\u4e2d cost[i] \u662f\u4ece s \u4e2d\u5220\u9664\u5b57\u7b26 i \u7684\u4ee3\u4ef7\u3002

    \n\n

    \u8fd4\u56de\u4f7f\u5b57\u7b26\u4e32\u4efb\u610f\u76f8\u90bb\u4e24\u4e2a\u5b57\u6bcd\u4e0d\u76f8\u540c\u7684\u6700\u5c0f\u5220\u9664\u6210\u672c\u3002

    \n\n

    \u8bf7\u6ce8\u610f\uff0c\u5220\u9664\u4e00\u4e2a\u5b57\u7b26\u540e\uff0c\u5220\u9664\u5176\u4ed6\u5b57\u7b26\u7684\u6210\u672c\u4e0d\u4f1a\u6539\u53d8\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = "abaac", cost = [1,2,3,4,5]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u5220\u9664\u5b57\u6bcd "a" \u7684\u6210\u672c\u4e3a 3\uff0c\u7136\u540e\u5f97\u5230 "abac"\uff08\u5b57\u7b26\u4e32\u4e2d\u76f8\u90bb\u4e24\u4e2a\u5b57\u6bcd\u4e0d\u76f8\u540c\uff09\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = "abc", cost = [1,2,3]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u65e0\u9700\u5220\u9664\u4efb\u4f55\u5b57\u6bcd\uff0c\u56e0\u4e3a\u5b57\u7b26\u4e32\u4e2d\u4e0d\u5b58\u5728\u76f8\u90bb\u4e24\u4e2a\u5b57\u6bcd\u76f8\u540c\u7684\u60c5\u51b5\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = "aabaa", cost = [1,2,3,4,1]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5220\u9664\u7b2c\u4e00\u4e2a\u548c\u6700\u540e\u4e00\u4e2a\u5b57\u6bcd\uff0c\u5f97\u5230\u5b57\u7b26\u4e32 ("aba") \u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • s.length == cost.length
    • \n\t
    • 1 <= s.length, cost.length <= 10^5
    • \n\t
    • 1 <= cost[i] <= 10^4
    • \n\t
    • s \u4e2d\u53ea\u542b\u6709\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minCost(string s, vector& cost) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minCost(String s, int[] cost) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minCost(self, s, cost):\n \"\"\"\n :type s: str\n :type cost: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minCost(self, s: str, cost: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minCost(char * s, int* cost, int costSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinCost(string s, int[] cost) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number[]} cost\n * @return {number}\n */\nvar minCost = function(s, cost) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer[]} cost\n# @return {Integer}\ndef min_cost(s, cost)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minCost(_ s: String, _ cost: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minCost(s string, cost []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minCost(s: String, cost: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minCost(s: String, cost: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_cost(s: String, cost: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer[] $cost\n * @return Integer\n */\n function minCost($s, $cost) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minCost(s: string, cost: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-cost s cost)\n (-> string? (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1578](https://leetcode-cn.com/problems/minimum-deletion-cost-to-avoid-repeating-letters)", "[\u907f\u514d\u91cd\u590d\u5b57\u6bcd\u7684\u6700\u5c0f\u5220\u9664\u6210\u672c](/solution/1500-1599/1578.Minimum%20Deletion%20Cost%20to%20Avoid%20Repeating%20Letters/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1578](https://leetcode.com/problems/minimum-deletion-cost-to-avoid-repeating-letters)", "[Minimum Deletion Cost to Avoid Repeating Letters](/solution/1500-1599/1578.Minimum%20Deletion%20Cost%20to%20Avoid%20Repeating%20Letters/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1699", "frontend_question_id": "1577", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers", "url_en": "https://leetcode.com/problems/number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers", "relative_path_cn": "/solution/1500-1599/1577.Number%20of%20Ways%20Where%20Square%20of%20Number%20Is%20Equal%20to%20Product%20of%20Two%20Numbers/README.md", "relative_path_en": "/solution/1500-1599/1577.Number%20of%20Ways%20Where%20Square%20of%20Number%20Is%20Equal%20to%20Product%20of%20Two%20Numbers/README_EN.md", "title_cn": "\u6570\u7684\u5e73\u65b9\u7b49\u4e8e\u4e24\u6570\u4e58\u79ef\u7684\u65b9\u6cd5\u6570", "title_en": "Number of Ways Where Square of Number Is Equal to Product of Two Numbers", "question_title_slug": "number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers", "content_en": "

    Given two arrays of integers nums1 and nums2, return the number of triplets formed (type 1 and type 2) under the following rules:

    \n\n
      \n\t
    • Type 1: Triplet (i, j, k) if nums1[i]2 == nums2[j] * nums2[k] where 0 <= i < nums1.length and 0 <= j < k < nums2.length.
    • \n\t
    • Type 2: Triplet (i, j, k) if nums2[i]2 == nums1[j] * nums1[k] where 0 <= i < nums2.length and 0 <= j < k < nums1.length.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums1 = [7,4], nums2 = [5,2,8,9]\nOutput: 1\nExplanation: Type 1: (1,1,2), nums1[1]^2 = nums2[1] * nums2[2]. (4^2 = 2 * 8). \n
    \n\n

    Example 2:

    \n\n
    \nInput: nums1 = [1,1], nums2 = [1,1,1]\nOutput: 9\nExplanation: All Triplets are valid, because 1^2 = 1 * 1.\nType 1: (0,0,1), (0,0,2), (0,1,2), (1,0,1), (1,0,2), (1,1,2).  nums1[i]^2 = nums2[j] * nums2[k].\nType 2: (0,0,1), (1,0,1), (2,0,1). nums2[i]^2 = nums1[j] * nums1[k].\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums1 = [7,7,8,3], nums2 = [1,2,9,7]\nOutput: 2\nExplanation: There are 2 valid triplets.\nType 1: (3,0,2).  nums1[3]^2 = nums2[0] * nums2[2].\nType 2: (3,0,1).  nums2[3]^2 = nums1[0] * nums1[1].\n
    \n\n

    Example 4:

    \n\n
    \nInput: nums1 = [4,7,9,11,23], nums2 = [3,5,1024,12,18]\nOutput: 0\nExplanation: There are no valid triplets.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums1.length, nums2.length <= 1000
    • \n\t
    • 1 <= nums1[i], nums2[i] <= 10^5
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u6574\u6570\u6570\u7ec4 nums1 \u548c nums2 \uff0c\u8bf7\u4f60\u8fd4\u56de\u6839\u636e\u4ee5\u4e0b\u89c4\u5219\u5f62\u6210\u7684\u4e09\u5143\u7ec4\u7684\u6570\u76ee\uff08\u7c7b\u578b 1 \u548c\u7c7b\u578b 2 \uff09\uff1a

    \n\n
      \n\t
    • \u7c7b\u578b 1\uff1a\u4e09\u5143\u7ec4 (i, j, k) \uff0c\u5982\u679c nums1[i]2 == nums2[j] * nums2[k] \u5176\u4e2d 0 <= i < nums1.length \u4e14 0 <= j < k < nums2.length
    • \n\t
    • \u7c7b\u578b 2\uff1a\u4e09\u5143\u7ec4 (i, j, k) \uff0c\u5982\u679c nums2[i]2 == nums1[j] * nums1[k] \u5176\u4e2d 0 <= i < nums2.length \u4e14 0 <= j < k < nums1.length
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anums1 = [7,4], nums2 = [5,2,8,9]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u7c7b\u578b 1\uff1a(1,1,2), nums1[1]^2 = nums2[1] * nums2[2] (4^2 = 2 * 8)
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anums1 = [1,1], nums2 = [1,1,1]\n\u8f93\u51fa\uff1a9\n\u89e3\u91ca\uff1a\u6240\u6709\u4e09\u5143\u7ec4\u90fd\u7b26\u5408\u9898\u76ee\u8981\u6c42\uff0c\u56e0\u4e3a 1^2 = 1 * 1\n\u7c7b\u578b 1\uff1a(0,0,1), (0,0,2), (0,1,2), (1,0,1), (1,0,2), (1,1,2), nums1[i]^2 = nums2[j] * nums2[k]\n\u7c7b\u578b 2\uff1a(0,0,1), (1,0,1), (2,0,1), nums2[i]^2 = nums1[j] * nums1[k]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1anums1 = [7,7,8,3], nums2 = [1,2,9,7]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6709\u4e24\u4e2a\u7b26\u5408\u9898\u76ee\u8981\u6c42\u7684\u4e09\u5143\u7ec4\n\u7c7b\u578b 1\uff1a(3,0,2), nums1[3]^2 = nums2[0] * nums2[2]\n\u7c7b\u578b 2\uff1a(3,0,1), nums2[3]^2 = nums1[0] * nums1[1]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1anums1 = [4,7,9,11,23], nums2 = [3,5,1024,12,18]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u4e0d\u5b58\u5728\u7b26\u5408\u9898\u76ee\u8981\u6c42\u7684\u4e09\u5143\u7ec4\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums1.length, nums2.length <= 1000
    • \n\t
    • 1 <= nums1[i], nums2[i] <= 10^5
    • \n
    \n", "tags_en": ["Hash Table", "Math"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numTriplets(vector& nums1, vector& nums2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numTriplets(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numTriplets(self, nums1, nums2):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numTriplets(self, nums1: List[int], nums2: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numTriplets(int* nums1, int nums1Size, int* nums2, int nums2Size){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumTriplets(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums1\n * @param {number[]} nums2\n * @return {number}\n */\nvar numTriplets = function(nums1, nums2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums1\n# @param {Integer[]} nums2\n# @return {Integer}\ndef num_triplets(nums1, nums2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numTriplets(_ nums1: [Int], _ nums2: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numTriplets(nums1 []int, nums2 []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numTriplets(nums1: Array[Int], nums2: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numTriplets(nums1: IntArray, nums2: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_triplets(nums1: Vec, nums2: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums1\n * @param Integer[] $nums2\n * @return Integer\n */\n function numTriplets($nums1, $nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numTriplets(nums1: number[], nums2: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-triplets nums1 nums2)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1577](https://leetcode-cn.com/problems/number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers)", "[\u6570\u7684\u5e73\u65b9\u7b49\u4e8e\u4e24\u6570\u4e58\u79ef\u7684\u65b9\u6cd5\u6570](/solution/1500-1599/1577.Number%20of%20Ways%20Where%20Square%20of%20Number%20Is%20Equal%20to%20Product%20of%20Two%20Numbers/README.md)", "`\u54c8\u5e0c\u8868`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1577](https://leetcode.com/problems/number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers)", "[Number of Ways Where Square of Number Is Equal to Product of Two Numbers](/solution/1500-1599/1577.Number%20of%20Ways%20Where%20Square%20of%20Number%20Is%20Equal%20to%20Product%20of%20Two%20Numbers/README_EN.md)", "`Hash Table`,`Math`", "Medium", ""]}, {"question_id": "1698", "frontend_question_id": "1576", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/replace-all-s-to-avoid-consecutive-repeating-characters", "url_en": "https://leetcode.com/problems/replace-all-s-to-avoid-consecutive-repeating-characters", "relative_path_cn": "/solution/1500-1599/1576.Replace%20All%20%27s%20to%20Avoid%20Consecutive%20Repeating%20Characters/README.md", "relative_path_en": "/solution/1500-1599/1576.Replace%20All%20%27s%20to%20Avoid%20Consecutive%20Repeating%20Characters/README_EN.md", "title_cn": "\u66ff\u6362\u6240\u6709\u7684\u95ee\u53f7", "title_en": "Replace All 's to Avoid Consecutive Repeating Characters", "question_title_slug": "replace-all-s-to-avoid-consecutive-repeating-characters", "content_en": "

    Given a string s containing only lower case English letters and the '?' character, convert all the '?' characters into lower case letters such that the final string does not contain any consecutive repeating characters. You cannot modify the non '?' characters.

    \n\n

    It is guaranteed that there are no consecutive repeating characters in the given string except for '?'.

    \n\n

    Return the final string after all the conversions (possibly zero) have been made. If there is more than one solution, return any of them. It can be shown that an answer is always possible with the given constraints.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "?zs"\nOutput: "azs"\nExplanation: There are 25 solutions for this problem. From "azs" to "yzs", all are valid. Only "z" is an invalid modification as the string will consist of consecutive repeating characters in "zzs".
    \n\n

    Example 2:

    \n\n
    \nInput: s = "ubv?w"\nOutput: "ubvaw"\nExplanation: There are 24 solutions for this problem. Only "v" and "w" are invalid modifications as the strings will consist of consecutive repeating characters in "ubvvw" and "ubvww".\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "j?qg??b"\nOutput: "jaqgacb"\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "??yw?ipkj?"\nOutput: "acywaipkja"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 100
    • \n\t
    • s contains only lower case English letters and '?'.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u4ec5\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u548c '?' \u5b57\u7b26\u7684\u5b57\u7b26\u4e32 s\uff0c\u8bf7\u4f60\u5c06\u6240\u6709\u7684 '?' \u8f6c\u6362\u4e3a\u82e5\u5e72\u5c0f\u5199\u5b57\u6bcd\uff0c\u4f7f\u6700\u7ec8\u7684\u5b57\u7b26\u4e32\u4e0d\u5305\u542b\u4efb\u4f55 \u8fde\u7eed\u91cd\u590d \u7684\u5b57\u7b26\u3002

    \n\n

    \u6ce8\u610f\uff1a\u4f60 \u4e0d\u80fd \u4fee\u6539\u975e '?' \u5b57\u7b26\u3002

    \n\n

    \u9898\u76ee\u6d4b\u8bd5\u7528\u4f8b\u4fdd\u8bc1 \u9664 '?' \u5b57\u7b26 \u4e4b\u5916\uff0c\u4e0d\u5b58\u5728\u8fde\u7eed\u91cd\u590d\u7684\u5b57\u7b26\u3002

    \n\n

    \u5728\u5b8c\u6210\u6240\u6709\u8f6c\u6362\uff08\u53ef\u80fd\u65e0\u9700\u8f6c\u6362\uff09\u540e\u8fd4\u56de\u6700\u7ec8\u7684\u5b57\u7b26\u4e32\u3002\u5982\u679c\u6709\u591a\u4e2a\u89e3\u51b3\u65b9\u6848\uff0c\u8bf7\u8fd4\u56de\u5176\u4e2d\u4efb\u4f55\u4e00\u4e2a\u3002\u53ef\u4ee5\u8bc1\u660e\uff0c\u5728\u7ed9\u5b9a\u7684\u7ea6\u675f\u6761\u4ef6\u4e0b\uff0c\u7b54\u6848\u603b\u662f\u5b58\u5728\u7684\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1as = "?zs"\n\u8f93\u51fa\uff1a"azs"\n\u89e3\u91ca\uff1a\u8be5\u793a\u4f8b\u5171\u6709 25 \u79cd\u89e3\u51b3\u65b9\u6848\uff0c\u4ece "azs" \u5230 "yzs" \u90fd\u662f\u7b26\u5408\u9898\u76ee\u8981\u6c42\u7684\u3002\u53ea\u6709 "z" \u662f\u65e0\u6548\u7684\u4fee\u6539\uff0c\u56e0\u4e3a\u5b57\u7b26\u4e32 "zzs" \u4e2d\u6709\u8fde\u7eed\u91cd\u590d\u7684\u4e24\u4e2a 'z' \u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1as = "ubv?w"\n\u8f93\u51fa\uff1a"ubvaw"\n\u89e3\u91ca\uff1a\u8be5\u793a\u4f8b\u5171\u6709 24 \u79cd\u89e3\u51b3\u65b9\u6848\uff0c\u53ea\u6709\u66ff\u6362\u6210 "v" \u548c "w" \u4e0d\u7b26\u5408\u9898\u76ee\u8981\u6c42\u3002\u56e0\u4e3a "ubvvw" \u548c "ubvww" \u90fd\u5305\u542b\u8fde\u7eed\u91cd\u590d\u7684\u5b57\u7b26\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1as = "j?qg??b"\n\u8f93\u51fa\uff1a"jaqgacb"\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1as = "??yw?ipkj?"\n\u8f93\u51fa\uff1a"acywaipkja"\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \n\t

      1 <= s.length <= 100

      \n\t
    • \n\t
    • \n\t

      s \u4ec5\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u548c '?' \u5b57\u7b26

      \n\t
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string modifyString(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String modifyString(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def modifyString(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def modifyString(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * modifyString(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ModifyString(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar modifyString = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef modify_string(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func modifyString(_ s: String) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func modifyString(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def modifyString(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun modifyString(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn modify_string(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function modifyString($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function modifyString(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (modify-string s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1576](https://leetcode-cn.com/problems/replace-all-s-to-avoid-consecutive-repeating-characters)", "[\u66ff\u6362\u6240\u6709\u7684\u95ee\u53f7](/solution/1500-1599/1576.Replace%20All%20%27s%20to%20Avoid%20Consecutive%20Repeating%20Characters/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1576](https://leetcode.com/problems/replace-all-s-to-avoid-consecutive-repeating-characters)", "[Replace All 's to Avoid Consecutive Repeating Characters](/solution/1500-1599/1576.Replace%20All%20%27s%20to%20Avoid%20Consecutive%20Repeating%20Characters/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1697", "frontend_question_id": "1554", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/strings-differ-by-one-character", "url_en": "https://leetcode.com/problems/strings-differ-by-one-character", "relative_path_cn": "/solution/1500-1599/1554.Strings%20Differ%20by%20One%20Character/README.md", "relative_path_en": "/solution/1500-1599/1554.Strings%20Differ%20by%20One%20Character/README_EN.md", "title_cn": "\u53ea\u6709\u4e00\u4e2a\u4e0d\u540c\u5b57\u7b26\u7684\u5b57\u7b26\u4e32", "title_en": "Strings Differ by One Character", "question_title_slug": "strings-differ-by-one-character", "content_en": "

    Given a list of strings dict where all the strings are of the same length.

    \n\n

    Return True if there are 2 strings that only differ by 1 character in the same index, otherwise return False.

    \n\n

    Follow up: Could you solve this problem in O(n*m) where n is the length of dict and m is the length of each string.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: dict = ["abcd","acbd", "aacd"]\nOutput: true\nExplanation: Strings "abcd" and "aacd" differ only by one character in the index 1.\n
    \n\n

    Example 2:

    \n\n
    \nInput: dict = ["ab","cd","yz"]\nOutput: false\n
    \n\n

    Example 3:

    \n\n
    \nInput: dict = ["abcd","cccc","abyd","abab"]\nOutput: true\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • Number of characters in dict <= 10^5
    • \n\t
    • dict[i].length == dict[j].length
    • \n\t
    • dict[i] should be unique.
    • \n\t
    • dict[i] contains only lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\u5217\u8868 dict \uff0c\u5176\u4e2d\u6240\u6709\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u90fd\u76f8\u540c\u3002

    \n\n

    \u5f53\u5b58\u5728\u4e24\u4e2a\u5b57\u7b26\u4e32\u5728\u76f8\u540c\u7d22\u5f15\u5904\u53ea\u6709\u4e00\u4e2a\u5b57\u7b26\u4e0d\u540c\u65f6\uff0c\u8fd4\u56de True \uff0c\u5426\u5219\u8fd4\u56de False \u3002

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u53ef\u4ee5\u4ee5 O(n*m) \u7684\u590d\u6742\u5ea6\u89e3\u51b3\u95ee\u9898\u5417\uff1f\u5176\u4e2d n \u662f\u5217\u8868 dict \u7684\u957f\u5ea6\uff0cm \u662f\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1adict = ["abcd","acbd", "aacd"]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u5b57\u7b26\u4e32 "abcd" \u548c "aacd" \u53ea\u5728\u7d22\u5f15 1 \u5904\u6709\u4e00\u4e2a\u4e0d\u540c\u7684\u5b57\u7b26\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1adict = ["ab","cd","yz"]\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1adict = ["abcd","cccc","abyd","abab"]\n\u8f93\u51fa\uff1atrue\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • dict \u4e2d\u7684\u5b57\u7b26\u6570\u5c0f\u4e8e\u6216\u7b49\u4e8e 10^5 \u3002
    • \n\t
    • dict[i].length == dict[j].length
    • \n\t
    • dict[i] \u662f\u4e92\u4e0d\u76f8\u540c\u7684\u3002
    • \n\t
    • dict[i] \u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    • \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool differByOne(vector& dict) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean differByOne(String[] dict) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def differByOne(self, dict):\n \"\"\"\n :type dict: List[str]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def differByOne(self, dict: List[str]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool differByOne(char ** dict, int dictSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool DifferByOne(string[] dict) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} dict\n * @return {boolean}\n */\nvar differByOne = function(dict) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} dict\n# @return {Boolean}\ndef differ_by_one(dict)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func differByOne(_ dict: [String]) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func differByOne(dict []string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def differByOne(dict: Array[String]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun differByOne(dict: Array): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn differ_by_one(dict: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $dict\n * @return Boolean\n */\n function differByOne($dict) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function differByOne(dict: string[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (differ-by-one dict)\n (-> (listof string?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1554](https://leetcode-cn.com/problems/strings-differ-by-one-character)", "[\u53ea\u6709\u4e00\u4e2a\u4e0d\u540c\u5b57\u7b26\u7684\u5b57\u7b26\u4e32](/solution/1500-1599/1554.Strings%20Differ%20by%20One%20Character/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1554](https://leetcode.com/problems/strings-differ-by-one-character)", "[Strings Differ by One Character](/solution/1500-1599/1554.Strings%20Differ%20by%20One%20Character/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1696", "frontend_question_id": "1591", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/strange-printer-ii", "url_en": "https://leetcode.com/problems/strange-printer-ii", "relative_path_cn": "/solution/1500-1599/1591.Strange%20Printer%20II/README.md", "relative_path_en": "/solution/1500-1599/1591.Strange%20Printer%20II/README_EN.md", "title_cn": "\u5947\u602a\u7684\u6253\u5370\u673a II", "title_en": "Strange Printer II", "question_title_slug": "strange-printer-ii", "content_en": "

    There is a strange printer with the following two special requirements:

    \n\n
      \n\t
    • On each turn, the printer will print a solid rectangular pattern of a single color on the grid. This will cover up the existing colors in the rectangle.
    • \n\t
    • Once the printer has used a color for the above operation, the same color cannot be used again.
    • \n
    \n\n

    You are given a m x n matrix targetGrid, where targetGrid[row][col] is the color in the position (row, col) of the grid.

    \n\n

    Return true if it is possible to print the matrix targetGrid, otherwise, return false.

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: targetGrid = [[1,1,1,1],[1,2,2,1],[1,2,2,1],[1,1,1,1]]\nOutput: true\n
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: targetGrid = [[1,1,1,1],[1,1,3,3],[1,1,3,4],[5,5,1,4]]\nOutput: true\n
    \n\n

    Example 3:

    \n\n
    \nInput: targetGrid = [[1,2,1],[2,1,2],[1,2,1]]\nOutput: false\nExplanation: It is impossible to form targetGrid because it is not allowed to print the same color in different turns.
    \n\n

    Example 4:

    \n\n
    \nInput: targetGrid = [[1,1,1],[3,1,3]]\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == targetGrid.length
    • \n\t
    • n == targetGrid[i].length
    • \n\t
    • 1 <= m, n <= 60
    • \n\t
    • 1 <= targetGrid[row][col] <= 60
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5947\u602a\u7684\u6253\u5370\u673a\uff0c\u5b83\u6709\u5982\u4e0b\u4e24\u4e2a\u7279\u6b8a\u7684\u6253\u5370\u89c4\u5219\uff1a

    \n\n
      \n\t
    • \u6bcf\u4e00\u6b21\u64cd\u4f5c\u65f6\uff0c\u6253\u5370\u673a\u4f1a\u7528\u540c\u4e00\u79cd\u989c\u8272\u6253\u5370\u4e00\u4e2a\u77e9\u5f62\u7684\u5f62\u72b6\uff0c\u6bcf\u6b21\u6253\u5370\u4f1a\u8986\u76d6\u77e9\u5f62\u5bf9\u5e94\u683c\u5b50\u91cc\u539f\u672c\u7684\u989c\u8272\u3002
    • \n\t
    • \u4e00\u65e6\u77e9\u5f62\u6839\u636e\u4e0a\u9762\u7684\u89c4\u5219\u4f7f\u7528\u4e86\u4e00\u79cd\u989c\u8272\uff0c\u90a3\u4e48 \u76f8\u540c\u7684\u989c\u8272\u4e0d\u80fd\u518d\u88ab\u4f7f\u7528 \u3002
    • \n
    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u521d\u59cb\u6ca1\u6709\u989c\u8272\u7684 m x n \u7684\u77e9\u5f62 targetGrid \uff0c\u5176\u4e2d targetGrid[row][col] \u662f\u4f4d\u7f6e (row, col) \u7684\u989c\u8272\u3002

    \n\n

    \u5982\u679c\u4f60\u80fd\u6309\u7167\u4e0a\u8ff0\u89c4\u5219\u6253\u5370\u51fa\u77e9\u5f62 targetGrid \uff0c\u8bf7\u4f60\u8fd4\u56de true \uff0c\u5426\u5219\u8fd4\u56de false \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1atargetGrid = [[1,1,1,1],[1,2,2,1],[1,2,2,1],[1,1,1,1]]\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1atargetGrid = [[1,1,1,1],[1,1,3,3],[1,1,3,4],[5,5,1,4]]\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1atargetGrid = [[1,2,1],[2,1,2],[1,2,1]]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u6ca1\u6709\u529e\u6cd5\u5f97\u5230 targetGrid \uff0c\u56e0\u4e3a\u6bcf\u4e00\u8f6e\u64cd\u4f5c\u4f7f\u7528\u7684\u989c\u8272\u4e92\u4e0d\u76f8\u540c\u3002
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1atargetGrid = [[1,1,1],[3,1,3]]\n\u8f93\u51fa\uff1afalse\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == targetGrid.length
    • \n\t
    • n == targetGrid[i].length
    • \n\t
    • 1 <= m, n <= 60
    • \n\t
    • 1 <= targetGrid[row][col] <= 60
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isPrintable(vector>& targetGrid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isPrintable(int[][] targetGrid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isPrintable(self, targetGrid):\n \"\"\"\n :type targetGrid: List[List[int]]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isPrintable(self, targetGrid: List[List[int]]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isPrintable(int** targetGrid, int targetGridSize, int* targetGridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsPrintable(int[][] targetGrid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} targetGrid\n * @return {boolean}\n */\nvar isPrintable = function(targetGrid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} target_grid\n# @return {Boolean}\ndef is_printable(target_grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isPrintable(_ targetGrid: [[Int]]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isPrintable(targetGrid [][]int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isPrintable(targetGrid: Array[Array[Int]]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isPrintable(targetGrid: Array): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_printable(target_grid: Vec>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $targetGrid\n * @return Boolean\n */\n function isPrintable($targetGrid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isPrintable(targetGrid: number[][]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-printable targetGrid)\n (-> (listof (listof exact-integer?)) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1591](https://leetcode-cn.com/problems/strange-printer-ii)", "[\u5947\u602a\u7684\u6253\u5370\u673a II](/solution/1500-1599/1591.Strange%20Printer%20II/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[1591](https://leetcode.com/problems/strange-printer-ii)", "[Strange Printer II](/solution/1500-1599/1591.Strange%20Printer%20II/README_EN.md)", "`Greedy`", "Hard", ""]}, {"question_id": "1695", "frontend_question_id": "1589", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-sum-obtained-of-any-permutation", "url_en": "https://leetcode.com/problems/maximum-sum-obtained-of-any-permutation", "relative_path_cn": "/solution/1500-1599/1589.Maximum%20Sum%20Obtained%20of%20Any%20Permutation/README.md", "relative_path_en": "/solution/1500-1599/1589.Maximum%20Sum%20Obtained%20of%20Any%20Permutation/README_EN.md", "title_cn": "\u6240\u6709\u6392\u5217\u4e2d\u7684\u6700\u5927\u548c", "title_en": "Maximum Sum Obtained of Any Permutation", "question_title_slug": "maximum-sum-obtained-of-any-permutation", "content_en": "

    We have an array of integers, nums, and an array of requests where requests[i] = [starti, endi]. The ith request asks for the sum of nums[starti] + nums[starti + 1] + ... + nums[endi - 1] + nums[endi]. Both starti and endi are 0-indexed.

    \n\n

    Return the maximum total sum of all requests among all permutations of nums.

    \n\n

    Since the answer may be too large, return it modulo 109 + 7.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,3,4,5], requests = [[1,3],[0,1]]\nOutput: 19\nExplanation: One permutation of nums is [2,1,3,4,5] with the following result: \nrequests[0] -> nums[1] + nums[2] + nums[3] = 1 + 3 + 4 = 8\nrequests[1] -> nums[0] + nums[1] = 2 + 1 = 3\nTotal sum: 8 + 3 = 11.\nA permutation with a higher total sum is [3,5,4,2,1] with the following result:\nrequests[0] -> nums[1] + nums[2] + nums[3] = 5 + 4 + 2 = 11\nrequests[1] -> nums[0] + nums[1] = 3 + 5  = 8\nTotal sum: 11 + 8 = 19, which is the best that you can do.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,2,3,4,5,6], requests = [[0,1]]\nOutput: 11\nExplanation: A permutation with the max total sum is [6,5,4,3,2,1] with request sums [11].
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [1,2,3,4,5,10], requests = [[0,2],[1,3],[1,1]]\nOutput: 47\nExplanation: A permutation with the max total sum is [4,10,5,3,2,1] with request sums [19,18,10].
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= n <= 105
    • \n\t
    • 0 <= nums[i] <= 105
    • \n\t
    • 1 <= requests.length <= 105
    • \n\t
    • requests[i].length == 2
    • \n\t
    • 0 <= starti <= endi < n
    • \n
    \n", "content_cn": "

    \u6709\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \uff0c\u548c\u4e00\u4e2a\u67e5\u8be2\u6570\u7ec4 requests \uff0c\u5176\u4e2d requests[i] = [starti, endi] \u3002\u7b2c i \u4e2a\u67e5\u8be2\u6c42 nums[starti] + nums[starti + 1] + ... + nums[endi - 1] + nums[endi] \u7684\u7ed3\u679c \uff0cstarti \u548c endi \u6570\u7ec4\u7d22\u5f15\u90fd\u662f \u4ece 0 \u5f00\u59cb \u7684\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u4efb\u610f\u6392\u5217 nums \u4e2d\u7684\u6570\u5b57\uff0c\u8bf7\u4f60\u8fd4\u56de\u6240\u6709\u67e5\u8be2\u7ed3\u679c\u4e4b\u548c\u7684\u6700\u5927\u503c\u3002

    \n\n

    \u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u4f1a\u5f88\u5927\uff0c\u8bf7\u4f60\u5c06\u5b83\u5bf9 109 + 7 \u53d6\u4f59 \u540e\u8fd4\u56de\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,2,3,4,5], requests = [[1,3],[0,1]]\n\u8f93\u51fa\uff1a19\n\u89e3\u91ca\uff1a\u4e00\u4e2a\u53ef\u884c\u7684 nums \u6392\u5217\u4e3a [2,1,3,4,5]\uff0c\u5e76\u6709\u5982\u4e0b\u7ed3\u679c\uff1a\nrequests[0] -> nums[1] + nums[2] + nums[3] = 1 + 3 + 4 = 8\nrequests[1] -> nums[0] + nums[1] = 2 + 1 = 3\n\u603b\u548c\u4e3a\uff1a8 + 3 = 11\u3002\n\u4e00\u4e2a\u603b\u548c\u66f4\u5927\u7684\u6392\u5217\u4e3a [3,5,4,2,1]\uff0c\u5e76\u6709\u5982\u4e0b\u7ed3\u679c\uff1a\nrequests[0] -> nums[1] + nums[2] + nums[3] = 5 + 4 + 2 = 11\nrequests[1] -> nums[0] + nums[1] = 3 + 5  = 8\n\u603b\u548c\u4e3a\uff1a 11 + 8 = 19\uff0c\u8fd9\u4e2a\u65b9\u6848\u662f\u6240\u6709\u6392\u5217\u4e2d\u67e5\u8be2\u4e4b\u548c\u6700\u5927\u7684\u7ed3\u679c\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,2,3,4,5,6], requests = [[0,1]]\n\u8f93\u51fa\uff1a11\n\u89e3\u91ca\uff1a\u4e00\u4e2a\u603b\u548c\u6700\u5927\u7684\u6392\u5217\u4e3a [6,5,4,3,2,1] \uff0c\u67e5\u8be2\u548c\u4e3a [11]\u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,2,3,4,5,10], requests = [[0,2],[1,3],[1,1]]\n\u8f93\u51fa\uff1a47\n\u89e3\u91ca\uff1a\u4e00\u4e2a\u548c\u6700\u5927\u7684\u6392\u5217\u4e3a [4,10,5,3,2,1] \uff0c\u67e5\u8be2\u7ed3\u679c\u5206\u522b\u4e3a [19,18,10]\u3002
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= n <= 105
    • \n\t
    • 0 <= nums[i] <= 105
    • \n\t
    • 1 <= requests.length <= 105
    • \n\t
    • requests[i].length == 2
    • \n\t
    • 0 <= starti <= endi < n
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxSumRangeQuery(vector& nums, vector>& requests) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxSumRangeQuery(int[] nums, int[][] requests) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxSumRangeQuery(self, nums, requests):\n \"\"\"\n :type nums: List[int]\n :type requests: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxSumRangeQuery(self, nums: List[int], requests: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxSumRangeQuery(int* nums, int numsSize, int** requests, int requestsSize, int* requestsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxSumRangeQuery(int[] nums, int[][] requests) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number[][]} requests\n * @return {number}\n */\nvar maxSumRangeQuery = function(nums, requests) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer[][]} requests\n# @return {Integer}\ndef max_sum_range_query(nums, requests)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxSumRangeQuery(_ nums: [Int], _ requests: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxSumRangeQuery(nums []int, requests [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxSumRangeQuery(nums: Array[Int], requests: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxSumRangeQuery(nums: IntArray, requests: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_sum_range_query(nums: Vec, requests: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer[][] $requests\n * @return Integer\n */\n function maxSumRangeQuery($nums, $requests) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxSumRangeQuery(nums: number[], requests: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-sum-range-query nums requests)\n (-> (listof exact-integer?) (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1589](https://leetcode-cn.com/problems/maximum-sum-obtained-of-any-permutation)", "[\u6240\u6709\u6392\u5217\u4e2d\u7684\u6700\u5927\u548c](/solution/1500-1599/1589.Maximum%20Sum%20Obtained%20of%20Any%20Permutation/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1589](https://leetcode.com/problems/maximum-sum-obtained-of-any-permutation)", "[Maximum Sum Obtained of Any Permutation](/solution/1500-1599/1589.Maximum%20Sum%20Obtained%20of%20Any%20Permutation/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1694", "frontend_question_id": "1590", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/make-sum-divisible-by-p", "url_en": "https://leetcode.com/problems/make-sum-divisible-by-p", "relative_path_cn": "/solution/1500-1599/1590.Make%20Sum%20Divisible%20by%20P/README.md", "relative_path_en": "/solution/1500-1599/1590.Make%20Sum%20Divisible%20by%20P/README_EN.md", "title_cn": "\u4f7f\u6570\u7ec4\u548c\u80fd\u88ab P \u6574\u9664", "title_en": "Make Sum Divisible by P", "question_title_slug": "make-sum-divisible-by-p", "content_en": "

    Given an array of positive integers nums, remove the smallest subarray (possibly empty) such that the sum of the remaining elements is divisible by p. It is not allowed to remove the whole array.

    \n\n

    Return the length of the smallest subarray that you need to remove, or -1 if it's impossible.

    \n\n

    A subarray is defined as a contiguous block of elements in the array.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [3,1,4,2], p = 6\nOutput: 1\nExplanation: The sum of the elements in nums is 10, which is not divisible by 6. We can remove the subarray [4], and the sum of the remaining elements is 6, which is divisible by 6.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [6,3,5,2], p = 9\nOutput: 2\nExplanation: We cannot remove a single element to get a sum divisible by 9. The best way is to remove the subarray [5,2], leaving us with [6,3] with sum 9.\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [1,2,3], p = 3\nOutput: 0\nExplanation: Here the sum is 6. which is already divisible by 3. Thus we do not need to remove anything.\n
    \n\n

    Example 4:

    \n\n
    \nInput: nums = [1,2,3], p = 7\nOutput: -1\nExplanation: There is no way to remove a subarray in order to get a sum divisible by 7.\n
    \n\n

    Example 5:

    \n\n
    \nInput: nums = [1000000000,1000000000,1000000000], p = 3\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • 1 <= nums[i] <= 109
    • \n\t
    • 1 <= p <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6b63\u6574\u6570\u6570\u7ec4 nums\uff0c\u8bf7\u4f60\u79fb\u9664 \u6700\u77ed \u5b50\u6570\u7ec4\uff08\u53ef\u4ee5\u4e3a \u7a7a\uff09\uff0c\u4f7f\u5f97\u5269\u4f59\u5143\u7d20\u7684 \u548c \u80fd\u88ab p \u6574\u9664\u3002 \u4e0d\u5141\u8bb8 \u5c06\u6574\u4e2a\u6570\u7ec4\u90fd\u79fb\u9664\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u4f60\u9700\u8981\u79fb\u9664\u7684\u6700\u77ed\u5b50\u6570\u7ec4\u7684\u957f\u5ea6\uff0c\u5982\u679c\u65e0\u6cd5\u6ee1\u8db3\u9898\u76ee\u8981\u6c42\uff0c\u8fd4\u56de -1 \u3002

    \n\n

    \u5b50\u6570\u7ec4 \u5b9a\u4e49\u4e3a\u539f\u6570\u7ec4\u4e2d\u8fde\u7eed\u7684\u4e00\u7ec4\u5143\u7d20\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [3,1,4,2], p = 6\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1anums \u4e2d\u5143\u7d20\u548c\u4e3a 10\uff0c\u4e0d\u80fd\u88ab p \u6574\u9664\u3002\u6211\u4eec\u53ef\u4ee5\u79fb\u9664\u5b50\u6570\u7ec4 [4] \uff0c\u5269\u4f59\u5143\u7d20\u7684\u548c\u4e3a 6 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [6,3,5,2], p = 9\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6211\u4eec\u65e0\u6cd5\u79fb\u9664\u4efb\u4f55\u4e00\u4e2a\u5143\u7d20\u4f7f\u5f97\u548c\u88ab 9 \u6574\u9664\uff0c\u6700\u4f18\u65b9\u6848\u662f\u79fb\u9664\u5b50\u6570\u7ec4 [5,2] \uff0c\u5269\u4f59\u5143\u7d20\u4e3a [6,3]\uff0c\u548c\u4e3a 9 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,2,3], p = 3\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u548c\u6070\u597d\u4e3a 6 \uff0c\u5df2\u7ecf\u80fd\u88ab 3 \u6574\u9664\u4e86\u3002\u6240\u4ee5\u6211\u4eec\u4e0d\u9700\u8981\u79fb\u9664\u4efb\u4f55\u5143\u7d20\u3002\n
    \n\n

    \u793a\u4f8b  4\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,2,3], p = 7\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u6ca1\u6709\u4efb\u4f55\u65b9\u6848\u4f7f\u5f97\u79fb\u9664\u5b50\u6570\u7ec4\u540e\u5269\u4f59\u5143\u7d20\u7684\u548c\u88ab 7 \u6574\u9664\u3002\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1000000000,1000000000,1000000000], p = 3\n\u8f93\u51fa\uff1a0\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • 1 <= nums[i] <= 109
    • \n\t
    • 1 <= p <= 109
    • \n
    \n", "tags_en": ["Array", "Hash Table", "Math", "Binary Search"], "tags_cn": ["\u6570\u7ec4", "\u54c8\u5e0c\u8868", "\u6570\u5b66", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minSubarray(vector& nums, int p) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minSubarray(int[] nums, int p) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minSubarray(self, nums, p):\n \"\"\"\n :type nums: List[int]\n :type p: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minSubarray(self, nums: List[int], p: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minSubarray(int* nums, int numsSize, int p){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinSubarray(int[] nums, int p) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} p\n * @return {number}\n */\nvar minSubarray = function(nums, p) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} p\n# @return {Integer}\ndef min_subarray(nums, p)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minSubarray(_ nums: [Int], _ p: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minSubarray(nums []int, p int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minSubarray(nums: Array[Int], p: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minSubarray(nums: IntArray, p: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_subarray(nums: Vec, p: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $p\n * @return Integer\n */\n function minSubarray($nums, $p) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minSubarray(nums: number[], p: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-subarray nums p)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1590](https://leetcode-cn.com/problems/make-sum-divisible-by-p)", "[\u4f7f\u6570\u7ec4\u548c\u80fd\u88ab P \u6574\u9664](/solution/1500-1599/1590.Make%20Sum%20Divisible%20by%20P/README.md)", "`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`,`\u6570\u5b66`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1590](https://leetcode.com/problems/make-sum-divisible-by-p)", "[Make Sum Divisible by P](/solution/1500-1599/1590.Make%20Sum%20Divisible%20by%20P/README_EN.md)", "`Array`,`Hash Table`,`Math`,`Binary Search`", "Medium", ""]}, {"question_id": "1693", "frontend_question_id": "1588", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sum-of-all-odd-length-subarrays", "url_en": "https://leetcode.com/problems/sum-of-all-odd-length-subarrays", "relative_path_cn": "/solution/1500-1599/1588.Sum%20of%20All%20Odd%20Length%20Subarrays/README.md", "relative_path_en": "/solution/1500-1599/1588.Sum%20of%20All%20Odd%20Length%20Subarrays/README_EN.md", "title_cn": "\u6240\u6709\u5947\u6570\u957f\u5ea6\u5b50\u6570\u7ec4\u7684\u548c", "title_en": "Sum of All Odd Length Subarrays", "question_title_slug": "sum-of-all-odd-length-subarrays", "content_en": "

    Given an array of positive integers arr, calculate the sum of all possible odd-length subarrays.

    \n\n

    A subarray is a contiguous subsequence of the array.

    \n\n

    Return the sum of all odd-length subarrays of arr.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr = [1,4,2,5,3]\nOutput: 58\nExplanation: The odd-length subarrays of arr and their sums are:\n[1] = 1\n[4] = 4\n[2] = 2\n[5] = 5\n[3] = 3\n[1,4,2] = 7\n[4,2,5] = 11\n[2,5,3] = 10\n[1,4,2,5,3] = 15\nIf we add all these together we get 1 + 4 + 2 + 5 + 3 + 7 + 11 + 10 + 15 = 58
    \n\n

    Example 2:

    \n\n
    \nInput: arr = [1,2]\nOutput: 3\nExplanation: There are only 2 subarrays of odd length, [1] and [2]. Their sum is 3.
    \n\n

    Example 3:

    \n\n
    \nInput: arr = [10,11,12]\nOutput: 66\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= arr.length <= 100
    • \n\t
    • 1 <= arr[i] <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6b63\u6574\u6570\u6570\u7ec4 arr \uff0c\u8bf7\u4f60\u8ba1\u7b97\u6240\u6709\u53ef\u80fd\u7684\u5947\u6570\u957f\u5ea6\u5b50\u6570\u7ec4\u7684\u548c\u3002

    \n\n

    \u5b50\u6570\u7ec4 \u5b9a\u4e49\u4e3a\u539f\u6570\u7ec4\u4e2d\u7684\u4e00\u4e2a\u8fde\u7eed\u5b50\u5e8f\u5217\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de arr \u4e2d \u6240\u6709\u5947\u6570\u957f\u5ea6\u5b50\u6570\u7ec4\u7684\u548c \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [1,4,2,5,3]\n\u8f93\u51fa\uff1a58\n\u89e3\u91ca\uff1a\u6240\u6709\u5947\u6570\u957f\u5ea6\u5b50\u6570\u7ec4\u548c\u5b83\u4eec\u7684\u548c\u4e3a\uff1a\n[1] = 1\n[4] = 4\n[2] = 2\n[5] = 5\n[3] = 3\n[1,4,2] = 7\n[4,2,5] = 11\n[2,5,3] = 10\n[1,4,2,5,3] = 15\n\u6211\u4eec\u5c06\u6240\u6709\u503c\u6c42\u548c\u5f97\u5230 1 + 4 + 2 + 5 + 3 + 7 + 11 + 10 + 15 = 58
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [1,2]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u603b\u5171\u53ea\u6709 2 \u4e2a\u957f\u5ea6\u4e3a\u5947\u6570\u7684\u5b50\u6570\u7ec4\uff0c[1] \u548c [2]\u3002\u5b83\u4eec\u7684\u548c\u4e3a 3 \u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [10,11,12]\n\u8f93\u51fa\uff1a66\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= arr.length <= 100
    • \n\t
    • 1 <= arr[i] <= 1000
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int sumOddLengthSubarrays(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int sumOddLengthSubarrays(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def sumOddLengthSubarrays(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def sumOddLengthSubarrays(self, arr: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint sumOddLengthSubarrays(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SumOddLengthSubarrays(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar sumOddLengthSubarrays = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef sum_odd_length_subarrays(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func sumOddLengthSubarrays(_ arr: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func sumOddLengthSubarrays(arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def sumOddLengthSubarrays(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun sumOddLengthSubarrays(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sum_odd_length_subarrays(arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function sumOddLengthSubarrays($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function sumOddLengthSubarrays(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (sum-odd-length-subarrays arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1588](https://leetcode-cn.com/problems/sum-of-all-odd-length-subarrays)", "[\u6240\u6709\u5947\u6570\u957f\u5ea6\u5b50\u6570\u7ec4\u7684\u548c](/solution/1500-1599/1588.Sum%20of%20All%20Odd%20Length%20Subarrays/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1588](https://leetcode.com/problems/sum-of-all-odd-length-subarrays)", "[Sum of All Odd Length Subarrays](/solution/1500-1599/1588.Sum%20of%20All%20Odd%20Length%20Subarrays/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1692", "frontend_question_id": "1569", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-ways-to-reorder-array-to-get-same-bst", "url_en": "https://leetcode.com/problems/number-of-ways-to-reorder-array-to-get-same-bst", "relative_path_cn": "/solution/1500-1599/1569.Number%20of%20Ways%20to%20Reorder%20Array%20to%20Get%20Same%20BST/README.md", "relative_path_en": "/solution/1500-1599/1569.Number%20of%20Ways%20to%20Reorder%20Array%20to%20Get%20Same%20BST/README_EN.md", "title_cn": "\u5c06\u5b50\u6570\u7ec4\u91cd\u65b0\u6392\u5e8f\u5f97\u5230\u540c\u4e00\u4e2a\u4e8c\u53c9\u67e5\u627e\u6811\u7684\u65b9\u6848\u6570", "title_en": "Number of Ways to Reorder Array to Get Same BST", "question_title_slug": "number-of-ways-to-reorder-array-to-get-same-bst", "content_en": "

    Given an array nums that represents a permutation of integers from 1 to n. We are going to construct a binary search tree (BST) by inserting the elements of nums in order into an initially empty BST. Find the number of different ways to reorder nums so that the constructed BST is identical to that formed from the original array nums.

    \n\n

    For example, given nums = [2,1,3], we will have 2 as the root, 1 as a left child, and 3 as a right child. The array [2,3,1] also yields the same BST but [3,2,1] yields a different BST.

    \n\n

    Return the number of ways to reorder nums such that the BST formed is identical to the original BST formed from nums.

    \n\n

    Since the answer may be very large, return it modulo 10^9 + 7.

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: nums = [2,1,3]\nOutput: 1\nExplanation: We can reorder nums to be [2,3,1] which will yield the same BST. There are no other ways to reorder nums which will yield the same BST.\n
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: nums = [3,4,5,1,2]\nOutput: 5\nExplanation: The following 5 arrays will yield the same BST: \n[3,1,2,4,5]\n[3,1,4,2,5]\n[3,1,4,5,2]\n[3,4,1,2,5]\n[3,4,1,5,2]\n
    \n\n

    Example 3:

    \n\n

    \"\"

    \n\n
    \nInput: nums = [1,2,3]\nOutput: 0\nExplanation: There are no other orderings of nums that will yield the same BST.\n
    \n\n

    Example 4:

    \n\n

    \"\"

    \n\n
    \nInput: nums = [3,1,2,5,4,6]\nOutput: 19\n
    \n\n

    Example 5:

    \n\n
    \nInput: nums = [9,4,2,1,3,6,5,7,8,14,11,10,12,13,16,15,17,18]\nOutput: 216212978\nExplanation: The number of ways to reorder nums to get the same BST is 3216212999. Taking this number modulo 10^9 + 7 gives 216212978.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 1000
    • \n\t
    • 1 <= nums[i] <= nums.length
    • \n\t
    • All integers in nums are distinct.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 nums \u8868\u793a 1 \u5230 n \u7684\u4e00\u4e2a\u6392\u5217\u3002\u6211\u4eec\u6309\u7167\u5143\u7d20\u5728 nums \u4e2d\u7684\u987a\u5e8f\u4f9d\u6b21\u63d2\u5165\u4e00\u4e2a\u521d\u59cb\u4e3a\u7a7a\u7684\u4e8c\u53c9\u67e5\u627e\u6811\uff08BST\uff09\u3002\u8bf7\u4f60\u7edf\u8ba1\u5c06 nums \u91cd\u65b0\u6392\u5e8f\u540e\uff0c\u7edf\u8ba1\u6ee1\u8db3\u5982\u4e0b\u6761\u4ef6\u7684\u65b9\u6848\u6570\uff1a\u91cd\u6392\u540e\u5f97\u5230\u7684\u4e8c\u53c9\u67e5\u627e\u6811\u4e0e nums \u539f\u672c\u6570\u5b57\u987a\u5e8f\u5f97\u5230\u7684\u4e8c\u53c9\u67e5\u627e\u6811\u76f8\u540c\u3002

    \n\n

    \u6bd4\u65b9\u8bf4\uff0c\u7ed9\u4f60 nums = [2,1,3]\uff0c\u6211\u4eec\u5f97\u5230\u4e00\u68f5 2 \u4e3a\u6839\uff0c1 \u4e3a\u5de6\u5b69\u5b50\uff0c3 \u4e3a\u53f3\u5b69\u5b50\u7684\u6811\u3002\u6570\u7ec4 [2,3,1] \u4e5f\u80fd\u5f97\u5230\u76f8\u540c\u7684 BST\uff0c\u4f46 [3,2,1] \u4f1a\u5f97\u5230\u4e00\u68f5\u4e0d\u540c\u7684 BST \u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u91cd\u6392 nums \u540e\uff0c\u4e0e\u539f\u6570\u7ec4 nums \u5f97\u5230\u76f8\u540c\u4e8c\u53c9\u67e5\u627e\u6811\u7684\u65b9\u6848\u6570\u3002

    \n\n

    \u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u4f1a\u5f88\u5927\uff0c\u8bf7\u5c06\u7ed3\u679c\u5bf9 10^9 + 7 \u53d6\u4f59\u6570\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1anums = [2,1,3]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u6211\u4eec\u5c06 nums \u91cd\u6392\uff0c [2,3,1] \u80fd\u5f97\u5230\u76f8\u540c\u7684 BST \u3002\u6ca1\u6709\u5176\u4ed6\u5f97\u5230\u76f8\u540c BST \u7684\u65b9\u6848\u4e86\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1anums = [3,4,5,1,2]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u4e0b\u9762 5 \u4e2a\u6570\u7ec4\u4f1a\u5f97\u5230\u76f8\u540c\u7684 BST\uff1a\n[3,1,2,4,5]\n[3,1,4,2,5]\n[3,1,4,5,2]\n[3,4,1,2,5]\n[3,4,1,5,2]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1anums = [1,2,3]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6ca1\u6709\u522b\u7684\u6392\u5217\u987a\u5e8f\u80fd\u5f97\u5230\u76f8\u540c\u7684 BST \u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1anums = [3,1,2,5,4,6]\n\u8f93\u51fa\uff1a19\n
    \n\n

    \u793a\u4f8b  5\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [9,4,2,1,3,6,5,7,8,14,11,10,12,13,16,15,17,18]\n\u8f93\u51fa\uff1a216212978\n\u89e3\u91ca\uff1a\u5f97\u5230\u76f8\u540c BST \u7684\u65b9\u6848\u6570\u662f 3216212999\u3002\u5c06\u5b83\u5bf9 10^9 + 7 \u53d6\u4f59\u540e\u5f97\u5230 216212978\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 1000
    • \n\t
    • 1 <= nums[i] <= nums.length
    • \n\t
    • nums \u4e2d\u6240\u6709\u6570 \u4e92\u4e0d\u76f8\u540c \u3002
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numOfWays(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numOfWays(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numOfWays(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numOfWays(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numOfWays(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumOfWays(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar numOfWays = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef num_of_ways(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numOfWays(_ nums: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numOfWays(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numOfWays(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numOfWays(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_of_ways(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function numOfWays($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numOfWays(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-of-ways nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1569](https://leetcode-cn.com/problems/number-of-ways-to-reorder-array-to-get-same-bst)", "[\u5c06\u5b50\u6570\u7ec4\u91cd\u65b0\u6392\u5e8f\u5f97\u5230\u540c\u4e00\u4e2a\u4e8c\u53c9\u67e5\u627e\u6811\u7684\u65b9\u6848\u6570](/solution/1500-1599/1569.Number%20of%20Ways%20to%20Reorder%20Array%20to%20Get%20Same%20BST/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1569](https://leetcode.com/problems/number-of-ways-to-reorder-array-to-get-same-bst)", "[Number of Ways to Reorder Array to Get Same BST](/solution/1500-1599/1569.Number%20of%20Ways%20to%20Reorder%20Array%20to%20Get%20Same%20BST/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1691", "frontend_question_id": "1568", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-number-of-days-to-disconnect-island", "url_en": "https://leetcode.com/problems/minimum-number-of-days-to-disconnect-island", "relative_path_cn": "/solution/1500-1599/1568.Minimum%20Number%20of%20Days%20to%20Disconnect%20Island/README.md", "relative_path_en": "/solution/1500-1599/1568.Minimum%20Number%20of%20Days%20to%20Disconnect%20Island/README_EN.md", "title_cn": "\u4f7f\u9646\u5730\u5206\u79bb\u7684\u6700\u5c11\u5929\u6570", "title_en": "Minimum Number of Days to Disconnect Island", "question_title_slug": "minimum-number-of-days-to-disconnect-island", "content_en": "

    Given a 2D grid consisting of 1s (land) and 0s (water).  An island is a maximal 4-directionally (horizontal or vertical) connected group of 1s.

    \n\n

    The grid is said to be connected if we have exactly one island, otherwise is said disconnected.

    \n\n

    In one day, we are allowed to change any single land cell (1) into a water cell (0).

    \n\n

    Return the minimum number of days to disconnect the grid.

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: grid = [[0,1,1,0],[0,1,1,0],[0,0,0,0]]\nOutput: 2\nExplanation: We need at least 2 days to get a disconnected grid.\nChange land grid[1][1] and grid[0][2] to water and get 2 disconnected island.\n
    \n\n

    Example 2:

    \n\n
    \nInput: grid = [[1,1]]\nOutput: 2\nExplanation: Grid of full water is also disconnected ([[1,1]] -> [[0,0]]), 0 islands.\n
    \n\n

    Example 3:

    \n\n
    \nInput: grid = [[1,0,1,0]]\nOutput: 0\n
    \n\n

    Example 4:

    \n\n
    \nInput: grid = [[1,1,0,1,1],\n               [1,1,1,1,1],\n               [1,1,0,1,1],\n               [1,1,0,1,1]]\nOutput: 1\n
    \n\n

    Example 5:

    \n\n
    \nInput: grid = [[1,1,0,1,1],\n               [1,1,1,1,1],\n               [1,1,0,1,1],\n               [1,1,1,1,1]]\nOutput: 2\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= grid.length, grid[i].length <= 30
    • \n\t
    • grid[i][j] is 0 or 1.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u7531\u82e5\u5e72 0 \u548c 1 \u7ec4\u6210\u7684\u4e8c\u7ef4\u7f51\u683c grid \uff0c\u5176\u4e2d 0 \u8868\u793a\u6c34\uff0c\u800c 1 \u8868\u793a\u9646\u5730\u3002\u5c9b\u5c7f\u7531\u6c34\u5e73\u65b9\u5411\u6216\u7ad6\u76f4\u65b9\u5411\u4e0a\u76f8\u90bb\u7684 1 \uff08\u9646\u5730\uff09\u8fde\u63a5\u5f62\u6210\u3002

    \n\n

    \u5982\u679c \u6070\u597d\u53ea\u6709\u4e00\u5ea7\u5c9b\u5c7f \uff0c\u5219\u8ba4\u4e3a\u9646\u5730\u662f \u8fde\u901a\u7684 \uff1b\u5426\u5219\uff0c\u9646\u5730\u5c31\u662f \u5206\u79bb\u7684 \u3002

    \n\n

    \u4e00\u5929\u5185\uff0c\u53ef\u4ee5\u5c06\u4efb\u4f55\u5355\u4e2a\u9646\u5730\u5355\u5143\uff081\uff09\u66f4\u6539\u4e3a\u6c34\u5355\u5143\uff080\uff09\u3002

    \n\n

    \u8fd4\u56de\u4f7f\u9646\u5730\u5206\u79bb\u7684\u6700\u5c11\u5929\u6570\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1agrid = [[0,1,1,0],[0,1,1,0],[0,0,0,0]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u81f3\u5c11\u9700\u8981 2 \u5929\u624d\u80fd\u5f97\u5230\u5206\u79bb\u7684\u9646\u5730\u3002\n\u5c06\u9646\u5730 grid[1][1] \u548c grid[0][2] \u66f4\u6539\u4e3a\u6c34\uff0c\u5f97\u5230\u4e24\u4e2a\u5206\u79bb\u7684\u5c9b\u5c7f\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1agrid = [[1,1]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5982\u679c\u7f51\u683c\u4e2d\u90fd\u662f\u6c34\uff0c\u4e5f\u8ba4\u4e3a\u662f\u5206\u79bb\u7684 ([[1,1]] -> [[0,0]])\uff0c0 \u5c9b\u5c7f\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1agrid = [[1,0,1,0]]\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1agrid = [[1,1,0,1,1],\n             [1,1,1,1,1],\n             [1,1,0,1,1],\n             [1,1,0,1,1]]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1agrid = [[1,1,0,1,1],\n             [1,1,1,1,1],\n             [1,1,0,1,1],\n             [1,1,1,1,1]]\n\u8f93\u51fa\uff1a2\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= grid.length, grid[i].length <= 30
    • \n\t
    • grid[i][j] \u4e3a 0 \u6216 1
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minDays(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minDays(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minDays(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minDays(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minDays(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinDays(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar minDays = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef min_days(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minDays(_ grid: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minDays(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minDays(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minDays(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_days(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function minDays($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minDays(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-days grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1568](https://leetcode-cn.com/problems/minimum-number-of-days-to-disconnect-island)", "[\u4f7f\u9646\u5730\u5206\u79bb\u7684\u6700\u5c11\u5929\u6570](/solution/1500-1599/1568.Minimum%20Number%20of%20Days%20to%20Disconnect%20Island/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[1568](https://leetcode.com/problems/minimum-number-of-days-to-disconnect-island)", "[Minimum Number of Days to Disconnect Island](/solution/1500-1599/1568.Minimum%20Number%20of%20Days%20to%20Disconnect%20Island/README_EN.md)", "`Greedy`", "Hard", ""]}, {"question_id": "1690", "frontend_question_id": "1567", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-length-of-subarray-with-positive-product", "url_en": "https://leetcode.com/problems/maximum-length-of-subarray-with-positive-product", "relative_path_cn": "/solution/1500-1599/1567.Maximum%20Length%20of%20Subarray%20With%20Positive%20Product/README.md", "relative_path_en": "/solution/1500-1599/1567.Maximum%20Length%20of%20Subarray%20With%20Positive%20Product/README_EN.md", "title_cn": "\u4e58\u79ef\u4e3a\u6b63\u6570\u7684\u6700\u957f\u5b50\u6570\u7ec4\u957f\u5ea6", "title_en": "Maximum Length of Subarray With Positive Product", "question_title_slug": "maximum-length-of-subarray-with-positive-product", "content_en": "

    Given an array of integers nums, find the maximum length of a subarray where the product of all its elements is positive.

    \n\n

    A subarray of an array is a consecutive sequence of zero or more values taken out of that array.

    \n\n

    Return the maximum length of a subarray with positive product.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,-2,-3,4]\nOutput: 4\nExplanation: The array nums already has a positive product of 24.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [0,1,-2,-3,-4]\nOutput: 3\nExplanation: The longest subarray with positive product is [1,-2,-3] which has a product of 6.\nNotice that we cannot include 0 in the subarray since that'll make the product 0 which is not positive.
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [-1,-2,-3,0,1]\nOutput: 2\nExplanation: The longest subarray with positive product is [-1,-2] or [-2,-3].\n
    \n\n

    Example 4:

    \n\n
    \nInput: nums = [-1,2]\nOutput: 1\n
    \n\n

    Example 5:

    \n\n
    \nInput: nums = [1,2,3,5,-6,4,0,10]\nOutput: 4\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 10^5
    • \n\t
    • -10^9 <= nums[i] <= 10^9
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \uff0c\u8bf7\u4f60\u6c42\u51fa\u4e58\u79ef\u4e3a\u6b63\u6570\u7684\u6700\u957f\u5b50\u6570\u7ec4\u7684\u957f\u5ea6\u3002

    \n\n

    \u4e00\u4e2a\u6570\u7ec4\u7684\u5b50\u6570\u7ec4\u662f\u7531\u539f\u6570\u7ec4\u4e2d\u96f6\u4e2a\u6216\u8005\u66f4\u591a\u4e2a\u8fde\u7eed\u6570\u5b57\u7ec4\u6210\u7684\u6570\u7ec4\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u4e58\u79ef\u4e3a\u6b63\u6570\u7684\u6700\u957f\u5b50\u6570\u7ec4\u957f\u5ea6\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b  1\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,-2,-3,4]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u6570\u7ec4\u672c\u8eab\u4e58\u79ef\u5c31\u662f\u6b63\u6570\uff0c\u503c\u4e3a 24 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [0,1,-2,-3,-4]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6700\u957f\u4e58\u79ef\u4e3a\u6b63\u6570\u7684\u5b50\u6570\u7ec4\u4e3a [1,-2,-3] \uff0c\u4e58\u79ef\u4e3a 6 \u3002\n\u6ce8\u610f\uff0c\u6211\u4eec\u4e0d\u80fd\u628a 0 \u4e5f\u5305\u62ec\u5230\u5b50\u6570\u7ec4\u4e2d\uff0c\u56e0\u4e3a\u8fd9\u6837\u4e58\u79ef\u4e3a 0 \uff0c\u4e0d\u662f\u6b63\u6570\u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [-1,-2,-3,0,1]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u4e58\u79ef\u4e3a\u6b63\u6570\u7684\u6700\u957f\u5b50\u6570\u7ec4\u662f [-1,-2] \u6216\u8005 [-2,-3] \u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [-1,2]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,2,3,5,-6,4,0,10]\n\u8f93\u51fa\uff1a4\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 10^5
    • \n\t
    • -10^9 <= nums[i] <= 10^9
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int getMaxLen(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int getMaxLen(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getMaxLen(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getMaxLen(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint getMaxLen(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int GetMaxLen(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar getMaxLen = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef get_max_len(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getMaxLen(_ nums: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getMaxLen(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getMaxLen(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getMaxLen(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_max_len(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function getMaxLen($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getMaxLen(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-max-len nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1567](https://leetcode-cn.com/problems/maximum-length-of-subarray-with-positive-product)", "[\u4e58\u79ef\u4e3a\u6b63\u6570\u7684\u6700\u957f\u5b50\u6570\u7ec4\u957f\u5ea6](/solution/1500-1599/1567.Maximum%20Length%20of%20Subarray%20With%20Positive%20Product/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1567](https://leetcode.com/problems/maximum-length-of-subarray-with-positive-product)", "[Maximum Length of Subarray With Positive Product](/solution/1500-1599/1567.Maximum%20Length%20of%20Subarray%20With%20Positive%20Product/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1689", "frontend_question_id": "1566", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/detect-pattern-of-length-m-repeated-k-or-more-times", "url_en": "https://leetcode.com/problems/detect-pattern-of-length-m-repeated-k-or-more-times", "relative_path_cn": "/solution/1500-1599/1566.Detect%20Pattern%20of%20Length%20M%20Repeated%20K%20or%20More%20Times/README.md", "relative_path_en": "/solution/1500-1599/1566.Detect%20Pattern%20of%20Length%20M%20Repeated%20K%20or%20More%20Times/README_EN.md", "title_cn": "\u91cd\u590d\u81f3\u5c11 K \u6b21\u4e14\u957f\u5ea6\u4e3a M \u7684\u6a21\u5f0f", "title_en": "Detect Pattern of Length M Repeated K or More Times", "question_title_slug": "detect-pattern-of-length-m-repeated-k-or-more-times", "content_en": "

    Given an array of positive integers arr,  find a pattern of length m that is repeated k or more times.

    \n\n

    A pattern is a subarray (consecutive sub-sequence) that consists of one or more values, repeated multiple times consecutively without overlapping. A pattern is defined by its length and the number of repetitions.

    \n\n

    Return true if there exists a pattern of length m that is repeated k or more times, otherwise return false.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr = [1,2,4,4,4,4], m = 1, k = 3\nOutput: true\nExplanation: The pattern (4) of length 1 is repeated 4 consecutive times. Notice that pattern can be repeated k or more times but not less.\n
    \n\n

    Example 2:

    \n\n
    \nInput: arr = [1,2,1,2,1,1,1,3], m = 2, k = 2\nOutput: true\nExplanation: The pattern (1,2) of length 2 is repeated 2 consecutive times. Another valid pattern (2,1) is also repeated 2 times.\n
    \n\n

    Example 3:

    \n\n
    \nInput: arr = [1,2,1,2,1,3], m = 2, k = 3\nOutput: false\nExplanation: The pattern (1,2) is of length 2 but is repeated only 2 times. There is no pattern of length 2 that is repeated 3 or more times.\n
    \n\n

    Example 4:

    \n\n
    \nInput: arr = [1,2,3,1,2], m = 2, k = 2\nOutput: false\nExplanation: Notice that the pattern (1,2) exists twice but not consecutively, so it doesn't count.\n
    \n\n

    Example 5:

    \n\n
    \nInput: arr = [2,2,2,2], m = 2, k = 3\nOutput: false\nExplanation: The only pattern of length 2 is (2,2) however it's repeated only twice. Notice that we do not count overlapping repetitions.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= arr.length <= 100
    • \n\t
    • 1 <= arr[i] <= 100
    • \n\t
    • 1 <= m <= 100
    • \n\t
    • 2 <= k <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6b63\u6574\u6570\u6570\u7ec4 arr\uff0c\u8bf7\u4f60\u627e\u51fa\u4e00\u4e2a\u957f\u5ea6\u4e3a m \u4e14\u5728\u6570\u7ec4\u4e2d\u81f3\u5c11\u91cd\u590d k \u6b21\u7684\u6a21\u5f0f\u3002

    \n\n

    \u6a21\u5f0f \u662f\u7531\u4e00\u4e2a\u6216\u591a\u4e2a\u503c\u7ec4\u6210\u7684\u5b50\u6570\u7ec4\uff08\u8fde\u7eed\u7684\u5b50\u5e8f\u5217\uff09\uff0c\u8fde\u7eed \u91cd\u590d\u591a\u6b21\u4f46 \u4e0d\u91cd\u53e0 \u3002 \u6a21\u5f0f\u7531\u5176\u957f\u5ea6\u548c\u91cd\u590d\u6b21\u6570\u5b9a\u4e49\u3002

    \n\n

    \u5982\u679c\u6570\u7ec4\u4e2d\u5b58\u5728\u81f3\u5c11\u91cd\u590d k \u6b21\u4e14\u957f\u5ea6\u4e3a m \u7684\u6a21\u5f0f\uff0c\u5219\u8fd4\u56de true \uff0c\u5426\u5219\u8fd4\u56de  false \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [1,2,4,4,4,4], m = 1, k = 3\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u6a21\u5f0f (4) \u7684\u957f\u5ea6\u4e3a 1 \uff0c\u4e14\u8fde\u7eed\u91cd\u590d 4 \u6b21\u3002\u6ce8\u610f\uff0c\u6a21\u5f0f\u53ef\u4ee5\u91cd\u590d k \u6b21\u6216\u66f4\u591a\u6b21\uff0c\u4f46\u4e0d\u80fd\u5c11\u4e8e k \u6b21\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [1,2,1,2,1,1,1,3], m = 2, k = 2\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u6a21\u5f0f (1,2) \u957f\u5ea6\u4e3a 2 \uff0c\u4e14\u8fde\u7eed\u91cd\u590d 2 \u6b21\u3002\u53e6\u4e00\u4e2a\u7b26\u5408\u9898\u610f\u7684\u6a21\u5f0f\u662f (2,1) \uff0c\u540c\u6837\u91cd\u590d 2 \u6b21\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [1,2,1,2,1,3], m = 2, k = 3\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u6a21\u5f0f (1,2) \u957f\u5ea6\u4e3a 2 \uff0c\u4f46\u662f\u53ea\u8fde\u7eed\u91cd\u590d 2 \u6b21\u3002\u4e0d\u5b58\u5728\u957f\u5ea6\u4e3a 2 \u4e14\u81f3\u5c11\u91cd\u590d 3 \u6b21\u7684\u6a21\u5f0f\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [1,2,3,1,2], m = 2, k = 2\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u6a21\u5f0f (1,2) \u51fa\u73b0 2 \u6b21\u4f46\u5e76\u4e0d\u8fde\u7eed\uff0c\u6240\u4ee5\u4e0d\u80fd\u7b97\u4f5c\u8fde\u7eed\u91cd\u590d 2 \u6b21\u3002\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [2,2,2,2], m = 2, k = 3\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u957f\u5ea6\u4e3a 2 \u7684\u6a21\u5f0f\u53ea\u6709 (2,2) \uff0c\u4f46\u662f\u53ea\u8fde\u7eed\u91cd\u590d 2 \u6b21\u3002\u6ce8\u610f\uff0c\u4e0d\u80fd\u8ba1\u7b97\u91cd\u53e0\u7684\u91cd\u590d\u6b21\u6570\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= arr.length <= 100
    • \n\t
    • 1 <= arr[i] <= 100
    • \n\t
    • 1 <= m <= 100
    • \n\t
    • 2 <= k <= 100
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool containsPattern(vector& arr, int m, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean containsPattern(int[] arr, int m, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def containsPattern(self, arr, m, k):\n \"\"\"\n :type arr: List[int]\n :type m: int\n :type k: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def containsPattern(self, arr: List[int], m: int, k: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool containsPattern(int* arr, int arrSize, int m, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool ContainsPattern(int[] arr, int m, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @param {number} m\n * @param {number} k\n * @return {boolean}\n */\nvar containsPattern = function(arr, m, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @param {Integer} m\n# @param {Integer} k\n# @return {Boolean}\ndef contains_pattern(arr, m, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func containsPattern(_ arr: [Int], _ m: Int, _ k: Int) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func containsPattern(arr []int, m int, k int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def containsPattern(arr: Array[Int], m: Int, k: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun containsPattern(arr: IntArray, m: Int, k: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn contains_pattern(arr: Vec, m: i32, k: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @param Integer $m\n * @param Integer $k\n * @return Boolean\n */\n function containsPattern($arr, $m, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function containsPattern(arr: number[], m: number, k: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (contains-pattern arr m k)\n (-> (listof exact-integer?) exact-integer? exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1566](https://leetcode-cn.com/problems/detect-pattern-of-length-m-repeated-k-or-more-times)", "[\u91cd\u590d\u81f3\u5c11 K \u6b21\u4e14\u957f\u5ea6\u4e3a M \u7684\u6a21\u5f0f](/solution/1500-1599/1566.Detect%20Pattern%20of%20Length%20M%20Repeated%20K%20or%20More%20Times/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1566](https://leetcode.com/problems/detect-pattern-of-length-m-repeated-k-or-more-times)", "[Detect Pattern of Length M Repeated K or More Times](/solution/1500-1599/1566.Detect%20Pattern%20of%20Length%20M%20Repeated%20K%20or%20More%20Times/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1688", "frontend_question_id": "1549", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/the-most-recent-orders-for-each-product", "url_en": "https://leetcode.com/problems/the-most-recent-orders-for-each-product", "relative_path_cn": "/solution/1500-1599/1549.The%20Most%20Recent%20Orders%20for%20Each%20Product/README.md", "relative_path_en": "/solution/1500-1599/1549.The%20Most%20Recent%20Orders%20for%20Each%20Product/README_EN.md", "title_cn": "\u6bcf\u4ef6\u5546\u54c1\u7684\u6700\u65b0\u8ba2\u5355", "title_en": "The Most Recent Orders for Each Product", "question_title_slug": "the-most-recent-orders-for-each-product", "content_en": "

    Table: Customers

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| customer_id   | int     |\n| name          | varchar |\n+---------------+---------+\ncustomer_id is the primary key for this table.\nThis table contains information about the customers.\n
    \n\n

     

    \n\n

    Table: Orders

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| order_id      | int     |\n| order_date    | date    |\n| customer_id   | int     |\n| product_id    | int     |\n+---------------+---------+\norder_id is the primary key for this table.\nThis table contains information about the orders made by customer_id.\nThere will be no product ordered by the same user more than once in one day.
    \n\n

     

    \n\n

    Table: Products

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| product_id    | int     |\n| product_name  | varchar |\n| price         | int     |\n+---------------+---------+\nproduct_id is the primary key for this table.\nThis table contains information about the Products.\n
    \n\n

     

    \n\n

    Write an SQL query to find the most recent order(s) of each product.

    \n\n

    Return the result table sorted by product_name in ascending order and in case of a tie by the product_id in ascending order. If there still a tie, order them by the order_id in ascending order.

    \n\n

    The query result format is in the following example:

    \n\n
    \nCustomers\n+-------------+-----------+\n| customer_id | name      |\n+-------------+-----------+\n| 1           | Winston   |\n| 2           | Jonathan  |\n| 3           | Annabelle |\n| 4           | Marwan    |\n| 5           | Khaled    |\n+-------------+-----------+\n\nOrders\n+----------+------------+-------------+------------+\n| order_id | order_date | customer_id | product_id |\n+----------+------------+-------------+------------+\n| 1        | 2020-07-31 | 1           | 1          |\n| 2        | 2020-07-30 | 2           | 2          |\n| 3        | 2020-08-29 | 3           | 3          |\n| 4        | 2020-07-29 | 4           | 1          |\n| 5        | 2020-06-10 | 1           | 2          |\n| 6        | 2020-08-01 | 2           | 1          |\n| 7        | 2020-08-01 | 3           | 1          |\n| 8        | 2020-08-03 | 1           | 2          |\n| 9        | 2020-08-07 | 2           | 3          |\n| 10       | 2020-07-15 | 1           | 2          |\n+----------+------------+-------------+------------+\n\nProducts\n+------------+--------------+-------+\n| product_id | product_name | price |\n+------------+--------------+-------+\n| 1          | keyboard     | 120   |\n| 2          | mouse        | 80    |\n| 3          | screen       | 600   |\n| 4          | hard disk    | 450   |\n+------------+--------------+-------+\n\nResult table:\n+--------------+------------+----------+------------+\n| product_name | product_id | order_id | order_date |\n+--------------+------------+----------+------------+\n| keyboard     | 1          | 6        | 2020-08-01 |\n| keyboard     | 1          | 7        | 2020-08-01 |\n| mouse        | 2          | 8        | 2020-08-03 |\n| screen       | 3          | 3        | 2020-08-29 |\n+--------------+------------+----------+------------+\nkeyboard's most recent order is in 2020-08-01, it was ordered two times this day.\nmouse's most recent order is in 2020-08-03, it was ordered only once this day.\nscreen's most recent order is in 2020-08-29, it was ordered only once this day.\nThe hard disk was never ordered and we don't include it in the result table.\n
    \n", "content_cn": "

    \u8868: Customers

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| customer_id   | int     |\n| name          | varchar |\n+---------------+---------+\ncustomer_id \u662f\u8be5\u8868\u4e3b\u952e.\n\u8be5\u8868\u5305\u542b\u6d88\u8d39\u8005\u7684\u4fe1\u606f.\n
    \n\n

     

    \n\n

    \u8868: Orders

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| order_id      | int     |\n| order_date    | date    |\n| customer_id   | int     |\n| product_id    | int     |\n+---------------+---------+\norder_id \u662f\u8be5\u8868\u4e3b\u952e.\n\u8be5\u8868\u5305\u542b\u6d88\u8d39\u8005customer_id\u4ea7\u751f\u7684\u8ba2\u5355.\n\u4e0d\u4f1a\u6709\u5546\u54c1\u88ab\u76f8\u540c\u7684\u7528\u6237\u5728\u4e00\u5929\u5185\u4e0b\u5355\u8d85\u8fc7\u4e00\u6b21.
    \n\n

     

    \n\n

    \u8868: Products

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| product_id    | int     |\n| product_name  | varchar |\n| price         | int     |\n+---------------+---------+\nproduct_id \u662f\u8be5\u8868\u4e3b\u952e.\n\u8be5\u8868\u5305\u542b\u6240\u6709\u5546\u54c1\u7684\u4fe1\u606f.\n
    \n\n

     

    \n\n

    \u5199\u4e00\u4e2aSQL \u8bed\u53e5, \u627e\u5230\u6bcf\u4ef6\u5546\u54c1\u7684\u6700\u65b0\u8ba2\u5355(\u53ef\u80fd\u6709\u591a\u4e2a).

    \n\n

    \u8fd4\u56de\u7684\u7ed3\u679c\u4ee5 product_name \u5347\u5e8f\u6392\u5217, \u5982\u679c\u6709\u6392\u5e8f\u76f8\u540c, \u518d\u4ee5 product_id \u5347\u5e8f\u6392\u5217. \u5982\u679c\u8fd8\u6709\u6392\u5e8f\u76f8\u540c, \u518d\u4ee5 order_id \u5347\u5e8f\u6392\u5217.

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a:

    \n\n
    \nCustomers\n+-------------+-----------+\n| customer_id | name      |\n+-------------+-----------+\n| 1           | Winston   |\n| 2           | Jonathan  |\n| 3           | Annabelle |\n| 4           | Marwan    |\n| 5           | Khaled    |\n+-------------+-----------+\n\nOrders\n+----------+------------+-------------+------------+\n| order_id | order_date | customer_id | product_id |\n+----------+------------+-------------+------------+\n| 1        | 2020-07-31 | 1           | 1          |\n| 2        | 2020-07-30 | 2           | 2          |\n| 3        | 2020-08-29 | 3           | 3          |\n| 4        | 2020-07-29 | 4           | 1          |\n| 5        | 2020-06-10 | 1           | 2          |\n| 6        | 2020-08-01 | 2           | 1          |\n| 7        | 2020-08-01 | 3           | 1          |\n| 8        | 2020-08-03 | 1           | 2          |\n| 9        | 2020-08-07 | 2           | 3          |\n| 10       | 2020-07-15 | 1           | 2          |\n+----------+------------+-------------+------------+\n\nProducts\n+------------+--------------+-------+\n| product_id | product_name | price |\n+------------+--------------+-------+\n| 1          | keyboard     | 120   |\n| 2          | mouse        | 80    |\n| 3          | screen       | 600   |\n| 4          | hard disk    | 450   |\n+------------+--------------+-------+\n\nResult\n+--------------+------------+----------+------------+\n| product_name | product_id | order_id | order_date |\n+--------------+------------+----------+------------+\n| keyboard     | 1          | 6        | 2020-08-01 |\n| keyboard     | 1          | 7        | 2020-08-01 |\n| mouse        | 2          | 8        | 2020-08-03 |\n| screen       | 3          | 3        | 2020-08-29 |\n+--------------+------------+----------+------------+\nkeyboard \u7684\u6700\u65b0\u8ba2\u5355\u57282020-08-01, \u5728\u8fd9\u5929\u6709\u4e24\u6b21\u4e0b\u5355.\nmouse \u7684\u6700\u65b0\u8ba2\u5355\u57282020-08-03, \u5728\u8fd9\u5929\u53ea\u6709\u4e00\u6b21\u4e0b\u5355.\nscreen \u7684\u6700\u65b0\u8ba2\u5355\u57282020-08-29, \u5728\u8fd9\u5929\u53ea\u6709\u4e00\u6b21\u4e0b\u5355.\nhard disk \u6ca1\u6709\u88ab\u4e0b\u5355, \u6211\u4eec\u4e0d\u628a\u5b83\u5305\u542b\u5728\u7ed3\u679c\u8868\u4e2d.\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1549](https://leetcode-cn.com/problems/the-most-recent-orders-for-each-product)", "[\u6bcf\u4ef6\u5546\u54c1\u7684\u6700\u65b0\u8ba2\u5355](/solution/1500-1599/1549.The%20Most%20Recent%20Orders%20for%20Each%20Product/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1549](https://leetcode.com/problems/the-most-recent-orders-for-each-product)", "[The Most Recent Orders for Each Product](/solution/1500-1599/1549.The%20Most%20Recent%20Orders%20for%20Each%20Product/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1687", "frontend_question_id": "1548", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/the-most-similar-path-in-a-graph", "url_en": "https://leetcode.com/problems/the-most-similar-path-in-a-graph", "relative_path_cn": "/solution/1500-1599/1548.The%20Most%20Similar%20Path%20in%20a%20Graph/README.md", "relative_path_en": "/solution/1500-1599/1548.The%20Most%20Similar%20Path%20in%20a%20Graph/README_EN.md", "title_cn": "\u56fe\u4e2d\u6700\u76f8\u4f3c\u7684\u8def\u5f84", "title_en": "The Most Similar Path in a Graph", "question_title_slug": "the-most-similar-path-in-a-graph", "content_en": "

    We have n cities and m bi-directional roads where roads[i] = [ai, bi] connects city ai with city bi. Each city has a name consisting of exactly 3 upper-case English letters given in the string array names. Starting at any city x, you can reach any city y where y != x (i.e. the cities and the roads are forming an undirected connected graph).

    \n\n

    You will be given a string array targetPath. You should find a path in the graph of the same length and with the minimum edit distance to targetPath.

    \n\n

    You need to return the order of the nodes in the path with the minimum edit distance, The path should be of the same length of targetPath and should be valid (i.e. there should be a direct road between ans[i] and ans[i + 1]). If there are multiple answers return any one of them.

    \n\n

    The edit distance is defined as follows:

    \n\n

    \"\"

    \n\n

    Follow-up: If each node can be visited only once in the path, What should you change in your solution?

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: n = 5, roads = [[0,2],[0,3],[1,2],[1,3],[1,4],[2,4]], names = ["ATL","PEK","LAX","DXB","HND"], targetPath = ["ATL","DXB","HND","LAX"]\nOutput: [0,2,4,2]\nExplanation: [0,2,4,2], [0,3,0,2] and [0,3,1,2] are accepted answers.\n[0,2,4,2] is equivalent to ["ATL","LAX","HND","LAX"] which has edit distance = 1 with targetPath.\n[0,3,0,2] is equivalent to ["ATL","DXB","ATL","LAX"] which has edit distance = 1 with targetPath.\n[0,3,1,2] is equivalent to ["ATL","DXB","PEK","LAX"] which has edit distance = 1 with targetPath.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: n = 4, roads = [[1,0],[2,0],[3,0],[2,1],[3,1],[3,2]], names = ["ATL","PEK","LAX","DXB"], targetPath = ["ABC","DEF","GHI","JKL","MNO","PQR","STU","VWX"]\nOutput: [0,1,0,1,0,1,0,1]\nExplanation: Any path in this graph has edit distance = 8 with targetPath.\n
    \n\n

    Example 3:

    \n\n

    \"\"

    \n\n
    \nInput: n = 6, roads = [[0,1],[1,2],[2,3],[3,4],[4,5]], names = ["ATL","PEK","LAX","ATL","DXB","HND"], targetPath = ["ATL","DXB","HND","DXB","ATL","LAX","PEK"]\nOutput: [3,4,5,4,3,2,1]\nExplanation: [3,4,5,4,3,2,1] is the only path with edit distance = 0 with targetPath.\nIt's equivalent to ["ATL","DXB","HND","DXB","ATL","LAX","PEK"]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= n <= 100
    • \n\t
    • m == roads.length
    • \n\t
    • n - 1 <= m <= (n * (n - 1) / 2)
    • \n\t
    • 0 <= ai, bi <= n - 1
    • \n\t
    • ai != bi 
    • \n\t
    • The graph is guaranteed to be connected and each pair of nodes may have at most one direct road.
    • \n\t
    • names.length == n
    • \n\t
    • names[i].length == 3
    • \n\t
    • names[i] consists of upper-case English letters.
    • \n\t
    • There can be two cities with the same name.
    • \n\t
    • 1 <= targetPath.length <= 100
    • \n\t
    • targetPath[i].length == 3
    • \n\t
    • targetPath[i] consists of upper-case English letters.
    • \n
    \n", "content_cn": "

    \u6211\u4eec\u6709\u00a0n\u00a0\u5ea7\u57ce\u5e02\u548c\u00a0m\u00a0\u6761\u53cc\u5411\u9053\u8def\u00a0roads\u00a0\uff0c\u5176\u4e2d\u00a0roads[i] = [ai, bi]\u00a0\u8fde\u63a5\u57ce\u5e02\u00a0ai\u00a0\u548c\u57ce\u5e02\u00a0bi\u3002\u6bcf\u4e2a\u57ce\u5e02\u6709\u4e00\u4e2a\u6b63\u597d 3 \u4e2a\u5927\u5199\u5b57\u6bcd\u7684\u540d\u5b57\uff0c\u5728\u6570\u7ec4\u00a0names\u4e2d\u7ed9\u51fa\u3002\u4ece\u4efb\u610f\u57ce\u5e02\u00a0x\u00a0\u51fa\u53d1\uff0c\u4f60\u53ef\u4ee5\u5230\u8fbe\u4efb\u610f\u57ce\u5e02\u00a0y \uff0c\u5176\u4e2d\u00a0y != x\u00a0\uff08\u5373\uff1a\u57ce\u5e02\u548c\u9053\u8def\u5f62\u6210\u4e00\u5f20\u65e0\u5411\u8fde\u901a\u56fe\uff09\u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4\u00a0targetPath\uff0c\u4f60\u9700\u8981\u627e\u51fa\u56fe\u4e2d\u4e0e\u00a0targetPath\u00a0\u7684 \u957f\u5ea6\u76f8\u540c \u4e14 \u7f16\u8f91\u8ddd\u79bb\u6700\u5c0f \u7684\u8def\u5f84\u3002

    \n\n

    \u4f60\u9700\u8981\u8fd4\u56de \u7f16\u8f91\u8ddd\u79bb\u6700\u5c0f\u7684\u8def\u5f84\u4e2d\u8282\u70b9\u7684\u987a\u5e8f \u3002\u8be5\u8def\u5f84\u5e94\u5f53\u4e0e\u00a0targetPath\u00a0\u7684\u957f\u5ea6\u76f8\u7b49\uff0c\u4e14\u8def\u5f84\u9700\u6709\u6548\uff08\u5373\uff1a\u00a0ans[i]\u00a0\u548c\u00a0ans[i + 1]\u00a0\u95f4\u5e94\u5b58\u5728\u76f4\u63a5\u8fde\u901a\u7684\u9053\u8def\uff09\u3002\u5982\u679c\u6709\u591a\u4e2a\u7b54\u6848\uff0c\u8fd4\u56de\u4efb\u610f\u4e00\u4e2a\u3002

    \n\n

    \u7f16\u8f91\u8ddd\u79bb \u7684\u5b9a\u4e49\u5982\u4e0b\uff1a

    \n\n
    \ndefine editDistance(targetPath, myPath) {\n    dis := 0\n    a := targetPath.length\n    b := myPath.length\n    if a != b {\n        return 1000000000\n    }\n    for (i := 0; i < a; i += 1) {\n        if targetPath[i] != myPath[i] {\n            dis += 1\n        }\n    }\n    return dis\n}\n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u5982\u679c\u8def\u5f84\u4e2d\u6bcf\u4e2a\u8282\u70b9\u53ea\u53ef\u8bbf\u95ee\u4e00\u6b21\uff0c\u4f60\u8be5\u5982\u4f55\u4fee\u6539\u4f60\u7684\u7b54\u6848\uff1f

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1an = 5, roads = [[0,2],[0,3],[1,2],[1,3],[1,4],[2,4]], names = [\"ATL\",\"PEK\",\"LAX\",\"DXB\",\"HND\"], targetPath = [\"ATL\",\"DXB\",\"HND\",\"LAX\"]\n\u8f93\u51fa\uff1a[0,2,4,2]\n\u89e3\u91ca\uff1a[0,2,4,2], [0,3,0,2] \u548c [0,3,1,2] \u90fd\u662f\u6b63\u786e\u7b54\u6848\u3002\n[0,2,4,2] \u7b49\u4ef7\u4e8e [\"ATL\",\"LAX\",\"HND\",\"LAX\"] \uff0c\u4e0e targetPath \u7684\u7f16\u8f91\u8ddd\u79bb = 1\u3002\n[0,3,0,2] \u7b49\u4ef7\u4e8e [\"ATL\",\"DXB\",\"ATL\",\"LAX\"] \uff0c\u4e0e targetPath \u7684\u7f16\u8f91\u8ddd\u79bb = 1\u3002\n[0,3,1,2] \u7b49\u4ef7\u4e8e [\"ATL\",\"DXB\",\"PEK\",\"LAX\"] \uff0c\u4e0e targetPath \u7684\u7f16\u8f91\u8ddd\u79bb = 1\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1an = 4, roads = [[1,0],[2,0],[3,0],[2,1],[3,1],[3,2]], names = [\"ATL\",\"PEK\",\"LAX\",\"DXB\"], targetPath = [\"ABC\",\"DEF\",\"GHI\",\"JKL\",\"MNO\",\"PQR\",\"STU\",\"VWX\"]\n\u8f93\u51fa\uff1a[0,1,0,1,0,1,0,1]\n\u89e3\u91ca\uff1a\u4efb\u610f\u8def\u5f84\u4e0e targetPath \u7684\u7f16\u8f91\u8ddd\u79bb\u90fd\u7b49\u4e8e 8\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1an = 6, roads = [[0,1],[1,2],[2,3],[3,4],[4,5]], names = [\"ATL\",\"PEK\",\"LAX\",\"ATL\",\"DXB\",\"HND\"], targetPath = [\"ATL\",\"DXB\",\"HND\",\"DXB\",\"ATL\",\"LAX\",\"PEK\"]\n\u8f93\u51fa\uff1a[3,4,5,4,3,2,1]\n\u89e3\u91ca\uff1a[3,4,5,4,3,2,1] \u662f\u552f\u4e00\u4e0e targetPath \u7684\u7f16\u8f91\u8ddd\u79bb = 0 \u7684\u8def\u5f84\u3002\n\u8be5\u8def\u5f84\u7b49\u4ef7\u4e8e [\"ATL\",\"DXB\",\"HND\",\"DXB\",\"ATL\",\"LAX\",\"PEK\"]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= n <= 100
    • \n\t
    • m == roads.length
    • \n\t
    • n - 1 <= m <= (n * (n - 1) / 2)
    • \n\t
    • 0 <= ai, bi <= n - 1
    • \n\t
    • ai != bi\u00a0
    • \n\t
    • \u7ed9\u5b9a\u7684\u56fe\u4fdd\u8bc1\u662f\u8fde\u901a\u7684\uff0c\u4efb\u610f\u4e24\u4e2a\u8282\u70b9\u81f3\u591a\u6709\u4e00\u4e2a\u76f4\u63a5\u8fde\u901a\u7684\u9053\u8def\u3002
    • \n\t
    • names.length == n
    • \n\t
    • names[i].length == 3
    • \n\t
    • names[i]\u00a0\u5305\u542b\u5927\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    • \n\t
    • \u53ef\u80fd\u6709\u4e24\u4e2a\u540d\u79f0\u76f8\u540c\u7684\u57ce\u5e02\u3002
    • \n\t
    • 1 <= targetPath.length <= 100
    • \n\t
    • targetPath[i].length == 3
    • \n\t
    • targetPath[i] \u7531\u5927\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\u3002
    • \n
    \n", "tags_en": ["Graph", "Dynamic Programming"], "tags_cn": ["\u56fe", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector mostSimilar(int n, vector>& roads, vector& names, vector& targetPath) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List mostSimilar(int n, int[][] roads, String[] names, String[] targetPath) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def mostSimilar(self, n, roads, names, targetPath):\n \"\"\"\n :type n: int\n :type roads: List[List[int]]\n :type names: List[str]\n :type targetPath: List[str]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def mostSimilar(self, n: int, roads: List[List[int]], names: List[str], targetPath: List[str]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* mostSimilar(int n, int** roads, int roadsSize, int* roadsColSize, char ** names, int namesSize, char ** targetPath, int targetPathSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList MostSimilar(int n, int[][] roads, string[] names, string[] targetPath) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} roads\n * @param {string[]} names\n * @param {string[]} targetPath\n * @return {number[]}\n */\nvar mostSimilar = function(n, roads, names, targetPath) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} roads\n# @param {String[]} names\n# @param {String[]} target_path\n# @return {Integer[]}\ndef most_similar(n, roads, names, target_path)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func mostSimilar(_ n: Int, _ roads: [[Int]], _ names: [String], _ targetPath: [String]) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func mostSimilar(n int, roads [][]int, names []string, targetPath []string) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def mostSimilar(n: Int, roads: Array[Array[Int]], names: Array[String], targetPath: Array[String]): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun mostSimilar(n: Int, roads: Array, names: Array, targetPath: Array): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn most_similar(n: i32, roads: Vec>, names: Vec, target_path: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $roads\n * @param String[] $names\n * @param String[] $targetPath\n * @return Integer[]\n */\n function mostSimilar($n, $roads, $names, $targetPath) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function mostSimilar(n: number, roads: number[][], names: string[], targetPath: string[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (most-similar n roads names targetPath)\n (-> exact-integer? (listof (listof exact-integer?)) (listof string?) (listof string?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1548](https://leetcode-cn.com/problems/the-most-similar-path-in-a-graph)", "[\u56fe\u4e2d\u6700\u76f8\u4f3c\u7684\u8def\u5f84](/solution/1500-1599/1548.The%20Most%20Similar%20Path%20in%20a%20Graph/README.md)", "`\u56fe`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1548](https://leetcode.com/problems/the-most-similar-path-in-a-graph)", "[The Most Similar Path in a Graph](/solution/1500-1599/1548.The%20Most%20Similar%20Path%20in%20a%20Graph/README_EN.md)", "`Graph`,`Dynamic Programming`", "Hard", "\ud83d\udd12"]}, {"question_id": "1686", "frontend_question_id": "1543", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/fix-product-name-format", "url_en": "https://leetcode.com/problems/fix-product-name-format", "relative_path_cn": "/solution/1500-1599/1543.Fix%20Product%20Name%20Format/README.md", "relative_path_en": "/solution/1500-1599/1543.Fix%20Product%20Name%20Format/README_EN.md", "title_cn": "\u4ea7\u54c1\u540d\u79f0\u683c\u5f0f\u4fee\u590d", "title_en": "Fix Product Name Format", "question_title_slug": "fix-product-name-format", "content_en": "

    Table: Sales

    \n\n
    \n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| sale_id      | int     |\n| product_name | varchar |\n| sale_date    | date    |\n+--------------+---------+\nsale_id is the primary key for this table.\nEach row of this table contains the product name and the date it was sold.\n
    \n\n

     

    \n\n

    Since table Sales was filled manually in the year 2000, product_name may contain leading and/or trailing white spaces, also they are case-insensitive.

    \n\n

    Write an SQL query to report

    \n\n
      \n\t
    • product_name in lowercase without leading or trailing white spaces.
    • \n\t
    • sale_date in the format ('YYYY-MM').
    • \n\t
    • total the number of times the product was sold in this month.
    • \n
    \n\n

    Return the result table ordered by product_name in ascending order. In case of a tie, order it by sale_date in ascending order.

    \n\n

    The query result format is in the following example.

    \n\n

     

    \n\n
    \nSales\n+---------+--------------+------------+\n| sale_id | product_name | sale_date  |\n+---------+--------------+------------+\n| 1       | LCPHONE      | 2000-01-16 |\n| 2       | LCPhone      | 2000-01-17 |\n| 3       | LcPhOnE      | 2000-02-18 |\n| 4       | LCKeyCHAiN   | 2000-02-19 |\n| 5       | LCKeyChain   | 2000-02-28 |\n| 6       | Matryoshka   | 2000-03-31 |\n+---------+--------------+------------+\n\nResult table:\n+--------------+-----------+-------+\n| product_name | sale_date | total |\n+--------------+-----------+-------+\n| lckeychain   | 2000-02   | 2     |\n| lcphone      | 2000-01   | 2     |\n| lcphone      | 2000-02   | 1     |\n| matryoshka   | 2000-03   | 1     |\n+--------------+-----------+-------+\nIn January, 2 LcPhones were sold, please note that the product names are not case sensitive and may contain spaces.\nIn Februery, 2 LCKeychains and 1 LCPhone were sold.\nIn March, 1 matryoshka was sold.\n
    \n", "content_cn": "

    \u8868\uff1aSales

    \n\n
    \n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| sale_id      | int     |\n| product_name | varchar |\n| sale_date    | date    |\n+--------------+---------+\nsale_id \u662f\u8be5\u8868\u4e3b\u952e\n\u8be5\u8868\u7684\u6bcf\u4e00\u884c\u5305\u542b\u4e86\u4ea7\u54c1\u7684\u540d\u79f0\u53ca\u5176\u9500\u552e\u65e5\u671f\n
    \n\n

    \u56e0\u4e3a\u5728 2000 \u5e74\u8be5\u8868\u662f\u624b\u5de5\u586b\u5199\u7684\uff0cproduct_name\u00a0\u53ef\u80fd\u5305\u542b\u524d\u540e\u7a7a\u683c\uff0c\u800c\u4e14\u5305\u542b\u5927\u5c0f\u5199\u3002

    \n\n

    \u5199\u4e00\u4e2a SQL \u8bed\u53e5\u62a5\u544a\u6bcf\u4e2a\u6708\u7684\u9500\u552e\u60c5\u51b5\uff1a

    \n\n
      \n\t
    • product_name\u00a0\u662f\u5c0f\u5199\u5b57\u6bcd\u4e14\u4e0d\u5305\u542b\u524d\u540e\u7a7a\u683c
    • \n\t
    • sale_date\u00a0\u683c\u5f0f\u4e3a\u00a0('YYYY-MM')\u00a0
    • \n\t
    • total\u00a0\u662f\u4ea7\u54c1\u5728\u672c\u6708\u9500\u552e\u7684\u6b21\u6570
    • \n
    \n\n

    \u8fd4\u56de\u7ed3\u679c\u4ee5\u00a0product_name\u00a0\u5347\u5e8f \u6392\u5217\uff0c\u5982\u679c\u6709\u6392\u540d\u76f8\u540c\uff0c\u518d\u4ee5\u00a0sale_date \u5347\u5e8f \u6392\u5217\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u6240\u793a\uff1a

    \n\n
    \nSales \u8868\uff1a\n+------------+------------------+--------------+\n| sale_id    | product_name     | sale_date    |\n+------------+------------------+--------------+\n| 1          |      LCPHONE     | 2000-01-16   |\n| 2    \u00a0     |    LCPhone       | 2000-01-17   |\n| 3    \u00a0     |     LcPhOnE     \u00a0| 2000-02-18   |\n| 4 \u00a0        |      LCKeyCHAiN  | 2000-02-19   |\n| 5 \u00a0        |   LCKeyChain     | 2000-02-28   |\n| 6        \u00a0 | Matryoshka     \u00a0 | 2000-03-31   | \n+------------+------------------+--------------+\n\nResult \u8868\uff1a\n+--------------+--------------+----------+\n| product_name | sale_date    | total    |\n+--------------+--------------+----------+\n| lcphone   \u00a0  | 2000-01     \u00a0| 2       \u00a0|\n| lckeychain   | 2000-02  \u00a0   | 2       \u00a0| \n| lcphone      | 2000-02    \u00a0 | 1       \u00a0| \n| matryoshka   | 2000-03 \u00a0    | 1       \u00a0| \n+--------------+--------------+----------+\n\n1 \u6708\u4efd\uff0c\u5356\u4e86 2 \u4e2a LcPhones\uff0c\u8bf7\u6ce8\u610f\u4ea7\u54c1\u540d\u79f0\u662f\u5c0f\u5199\u7684\uff0c\u4e2d\u95f4\u53ef\u80fd\u5305\u542b\u7a7a\u683c\n2 \u6708\u4efd\uff0c\u5356\u4e86 2 \u4e2a LCKeychains \u548c 1 \u4e2a LCPhone\n3 \u6708\u4efd\uff0c\u5356\u4e86 1 \u4e2a matryoshka\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1543](https://leetcode-cn.com/problems/fix-product-name-format)", "[\u4ea7\u54c1\u540d\u79f0\u683c\u5f0f\u4fee\u590d](/solution/1500-1599/1543.Fix%20Product%20Name%20Format/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1543](https://leetcode.com/problems/fix-product-name-format)", "[Fix Product Name Format](/solution/1500-1599/1543.Fix%20Product%20Name%20Format/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1685", "frontend_question_id": "1563", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/stone-game-v", "url_en": "https://leetcode.com/problems/stone-game-v", "relative_path_cn": "/solution/1500-1599/1563.Stone%20Game%20V/README.md", "relative_path_en": "/solution/1500-1599/1563.Stone%20Game%20V/README_EN.md", "title_cn": "\u77f3\u5b50\u6e38\u620f V", "title_en": "Stone Game V", "question_title_slug": "stone-game-v", "content_en": "

    There are several stones arranged in a row, and each stone has an associated value which is an integer given in the array stoneValue.

    \n\n

    In each round of the game, Alice divides the row into two non-empty rows (i.e. left row and right row), then Bob calculates the value of each row which is the sum of the values of all the stones in this row. Bob throws away the row which has the maximum value, and Alice's score increases by the value of the remaining row. If the value of the two rows are equal, Bob lets Alice decide which row will be thrown away. The next round starts with the remaining row.

    \n\n

    The game ends when there is only one stone remaining. Alice's is initially zero.

    \n\n

    Return the maximum score that Alice can obtain.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: stoneValue = [6,2,3,4,5,5]\nOutput: 18\nExplanation: In the first round, Alice divides the row to [6,2,3], [4,5,5]. The left row has the value 11 and the right row has value 14. Bob throws away the right row and Alice's score is now 11.\nIn the second round Alice divides the row to [6], [2,3]. This time Bob throws away the left row and Alice's score becomes 16 (11 + 5).\nThe last round Alice has only one choice to divide the row which is [2], [3]. Bob throws away the right row and Alice's score is now 18 (16 + 2). The game ends because only one stone is remaining in the row.\n
    \n\n

    Example 2:

    \n\n
    \nInput: stoneValue = [7,7,7,7,7,7,7]\nOutput: 28\n
    \n\n

    Example 3:

    \n\n
    \nInput: stoneValue = [4]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= stoneValue.length <= 500
    • \n\t
    • 1 <= stoneValue[i] <= 10^6
    • \n
    \n", "content_cn": "

    \u51e0\u5757\u77f3\u5b50 \u6392\u6210\u4e00\u884c \uff0c\u6bcf\u5757\u77f3\u5b50\u90fd\u6709\u4e00\u4e2a\u5173\u8054\u503c\uff0c\u5173\u8054\u503c\u4e3a\u6574\u6570\uff0c\u7531\u6570\u7ec4 stoneValue \u7ed9\u51fa\u3002

    \n\n

    \u6e38\u620f\u4e2d\u7684\u6bcf\u4e00\u8f6e\uff1aAlice \u4f1a\u5c06\u8fd9\u884c\u77f3\u5b50\u5206\u6210\u4e24\u4e2a \u975e\u7a7a\u884c\uff08\u5373\uff0c\u5de6\u4fa7\u884c\u548c\u53f3\u4fa7\u884c\uff09\uff1bBob \u8d1f\u8d23\u8ba1\u7b97\u6bcf\u4e00\u884c\u7684\u503c\uff0c\u5373\u6b64\u884c\u4e2d\u6240\u6709\u77f3\u5b50\u7684\u503c\u7684\u603b\u548c\u3002Bob \u4f1a\u4e22\u5f03\u503c\u6700\u5927\u7684\u884c\uff0cAlice \u7684\u5f97\u5206\u4e3a\u5269\u4e0b\u90a3\u884c\u7684\u503c\uff08\u6bcf\u8f6e\u7d2f\u52a0\uff09\u3002\u5982\u679c\u4e24\u884c\u7684\u503c\u76f8\u7b49\uff0cBob \u8ba9 Alice \u51b3\u5b9a\u4e22\u5f03\u54ea\u4e00\u884c\u3002\u4e0b\u4e00\u8f6e\u4ece\u5269\u4e0b\u7684\u90a3\u4e00\u884c\u5f00\u59cb\u3002

    \n\n

    \u53ea \u5269\u4e0b\u4e00\u5757\u77f3\u5b50 \u65f6\uff0c\u6e38\u620f\u7ed3\u675f\u3002Alice \u7684\u5206\u6570\u6700\u521d\u4e3a 0 \u3002

    \n\n

    \u8fd4\u56de Alice \u80fd\u591f\u83b7\u5f97\u7684\u6700\u5927\u5206\u6570 \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1astoneValue = [6,2,3,4,5,5]\n\u8f93\u51fa\uff1a18\n\u89e3\u91ca\uff1a\u5728\u7b2c\u4e00\u8f6e\u4e2d\uff0cAlice \u5c06\u884c\u5212\u5206\u4e3a [6\uff0c2\uff0c3]\uff0c[4\uff0c5\uff0c5] \u3002\u5de6\u884c\u7684\u503c\u662f 11 \uff0c\u53f3\u884c\u7684\u503c\u662f 14 \u3002Bob \u4e22\u5f03\u4e86\u53f3\u884c\uff0cAlice \u7684\u5206\u6570\u73b0\u5728\u662f 11 \u3002\n\u5728\u7b2c\u4e8c\u8f6e\u4e2d\uff0cAlice \u5c06\u884c\u5206\u6210 [6]\uff0c[2\uff0c3] \u3002\u8fd9\u4e00\u6b21 Bob \u6254\u6389\u4e86\u5de6\u884c\uff0cAlice \u7684\u5206\u6570\u53d8\u6210\u4e86 16\uff0811 + 5\uff09\u3002\n\u6700\u540e\u4e00\u8f6e Alice \u53ea\u80fd\u5c06\u884c\u5206\u6210 [2]\uff0c[3] \u3002Bob \u6254\u6389\u53f3\u884c\uff0cAlice \u7684\u5206\u6570\u73b0\u5728\u662f 18\uff0816 + 2\uff09\u3002\u6e38\u620f\u7ed3\u675f\uff0c\u56e0\u4e3a\u8fd9\u884c\u53ea\u5269\u4e0b\u4e00\u5757\u77f3\u5934\u4e86\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1astoneValue = [7,7,7,7,7,7,7]\n\u8f93\u51fa\uff1a28\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1astoneValue = [4]\n\u8f93\u51fa\uff1a0\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= stoneValue.length <= 500
    • \n\t
    • 1 <= stoneValue[i] <= 10^6
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int stoneGameV(vector& stoneValue) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int stoneGameV(int[] stoneValue) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def stoneGameV(self, stoneValue):\n \"\"\"\n :type stoneValue: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def stoneGameV(self, stoneValue: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint stoneGameV(int* stoneValue, int stoneValueSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int StoneGameV(int[] stoneValue) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} stoneValue\n * @return {number}\n */\nvar stoneGameV = function(stoneValue) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} stone_value\n# @return {Integer}\ndef stone_game_v(stone_value)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func stoneGameV(_ stoneValue: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func stoneGameV(stoneValue []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def stoneGameV(stoneValue: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun stoneGameV(stoneValue: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn stone_game_v(stone_value: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $stoneValue\n * @return Integer\n */\n function stoneGameV($stoneValue) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function stoneGameV(stoneValue: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (stone-game-v stoneValue)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1563](https://leetcode-cn.com/problems/stone-game-v)", "[\u77f3\u5b50\u6e38\u620f V](/solution/1500-1599/1563.Stone%20Game%20V/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1563](https://leetcode.com/problems/stone-game-v)", "[Stone Game V](/solution/1500-1599/1563.Stone%20Game%20V/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1684", "frontend_question_id": "1562", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-latest-group-of-size-m", "url_en": "https://leetcode.com/problems/find-latest-group-of-size-m", "relative_path_cn": "/solution/1500-1599/1562.Find%20Latest%20Group%20of%20Size%20M/README.md", "relative_path_en": "/solution/1500-1599/1562.Find%20Latest%20Group%20of%20Size%20M/README_EN.md", "title_cn": "\u67e5\u627e\u5927\u5c0f\u4e3a M \u7684\u6700\u65b0\u5206\u7ec4", "title_en": "Find Latest Group of Size M", "question_title_slug": "find-latest-group-of-size-m", "content_en": "

    Given an array arr that represents a permutation of numbers from 1 to n. You have a binary string of size n that initially has all its bits set to zero.

    \n\n

    At each step i (assuming both the binary string and arr are 1-indexed) from 1 to n, the bit at position arr[i] is set to 1. You are given an integer m and you need to find the latest step at which there exists a group of ones of length m. A group of ones is a contiguous substring of 1s such that it cannot be extended in either direction.

    \n\n

    Return the latest step at which there exists a group of ones of length exactly m. If no such group exists, return -1.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr = [3,5,1,2,4], m = 1\nOutput: 4\nExplanation:\nStep 1: "00100", groups: ["1"]\nStep 2: "00101", groups: ["1", "1"]\nStep 3: "10101", groups: ["1", "1", "1"]\nStep 4: "11101", groups: ["111", "1"]\nStep 5: "11111", groups: ["11111"]\nThe latest step at which there exists a group of size 1 is step 4.
    \n\n

    Example 2:

    \n\n
    \nInput: arr = [3,1,5,4,2], m = 2\nOutput: -1\nExplanation:\nStep 1: "00100", groups: ["1"]\nStep 2: "10100", groups: ["1", "1"]\nStep 3: "10101", groups: ["1", "1", "1"]\nStep 4: "10111", groups: ["1", "111"]\nStep 5: "11111", groups: ["11111"]\nNo group of size 2 exists during any step.\n
    \n\n

    Example 3:

    \n\n
    \nInput: arr = [1], m = 1\nOutput: 1\n
    \n\n

    Example 4:

    \n\n
    \nInput: arr = [2,1], m = 2\nOutput: 2\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == arr.length
    • \n\t
    • 1 <= n <= 10^5
    • \n\t
    • 1 <= arr[i] <= n
    • \n\t
    • All integers in arr are distinct.
    • \n\t
    • 1 <= m <= arr.length
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 arr \uff0c\u8be5\u6570\u7ec4\u8868\u793a\u4e00\u4e2a\u4ece 1 \u5230 n \u7684\u6570\u5b57\u6392\u5217\u3002\u6709\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32\uff0c\u8be5\u5b57\u7b26\u4e32\u4e0a\u7684\u6240\u6709\u4f4d\u6700\u521d\u90fd\u8bbe\u7f6e\u4e3a 0 \u3002

    \n\n

    \u5728\u4ece 1 \u5230 n \u7684\u6bcf\u4e2a\u6b65\u9aa4 i \u4e2d\uff08\u5047\u8bbe\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32\u548c arr \u90fd\u662f\u4ece 1 \u5f00\u59cb\u7d22\u5f15\u7684\u60c5\u51b5\u4e0b\uff09\uff0c\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32\u4e0a\u4f4d\u4e8e\u4f4d\u7f6e arr[i] \u7684\u4f4d\u5c06\u4f1a\u8bbe\u4e3a 1 \u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 m \uff0c\u8bf7\u4f60\u627e\u51fa\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32\u4e0a\u5b58\u5728\u957f\u5ea6\u4e3a m \u7684\u4e00\u7ec4 1 \u7684\u6700\u540e\u6b65\u9aa4\u3002\u4e00\u7ec4 1 \u662f\u4e00\u4e2a\u8fde\u7eed\u7684\u3001\u7531 1 \u7ec4\u6210\u7684\u5b50\u4e32\uff0c\u4e14\u5de6\u53f3\u4e24\u8fb9\u4e0d\u518d\u6709\u53ef\u4ee5\u5ef6\u4f38\u7684 1 \u3002

    \n\n

    \u8fd4\u56de\u5b58\u5728\u957f\u5ea6 \u6070\u597d \u4e3a m \u7684 \u4e00\u7ec4 1  \u7684\u6700\u540e\u6b65\u9aa4\u3002\u5982\u679c\u4e0d\u5b58\u5728\u8fd9\u6837\u7684\u6b65\u9aa4\uff0c\u8bf7\u8fd4\u56de -1 \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [3,5,1,2,4], m = 1\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\n\u6b65\u9aa4 1\uff1a"00100"\uff0c\u7531 1 \u6784\u6210\u7684\u7ec4\uff1a["1"]\n\u6b65\u9aa4 2\uff1a"00101"\uff0c\u7531 1 \u6784\u6210\u7684\u7ec4\uff1a["1", "1"]\n\u6b65\u9aa4 3\uff1a"10101"\uff0c\u7531 1 \u6784\u6210\u7684\u7ec4\uff1a["1", "1", "1"]\n\u6b65\u9aa4 4\uff1a"11101"\uff0c\u7531 1 \u6784\u6210\u7684\u7ec4\uff1a["111", "1"]\n\u6b65\u9aa4 5\uff1a"11111"\uff0c\u7531 1 \u6784\u6210\u7684\u7ec4\uff1a["11111"]\n\u5b58\u5728\u957f\u5ea6\u4e3a 1 \u7684\u4e00\u7ec4 1 \u7684\u6700\u540e\u6b65\u9aa4\u662f\u6b65\u9aa4 4 \u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [3,1,5,4,2], m = 2\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\n\u6b65\u9aa4 1\uff1a"00100"\uff0c\u7531 1 \u6784\u6210\u7684\u7ec4\uff1a["1"]\n\u6b65\u9aa4 2\uff1a"10100"\uff0c\u7531 1 \u6784\u6210\u7684\u7ec4\uff1a["1", "1"]\n\u6b65\u9aa4 3\uff1a"10101"\uff0c\u7531 1 \u6784\u6210\u7684\u7ec4\uff1a["1", "1", "1"]\n\u6b65\u9aa4 4\uff1a"10111"\uff0c\u7531 1 \u6784\u6210\u7684\u7ec4\uff1a["1", "111"]\n\u6b65\u9aa4 5\uff1a"11111"\uff0c\u7531 1 \u6784\u6210\u7684\u7ec4\uff1a["11111"]\n\u4e0d\u7ba1\u662f\u54ea\u4e00\u6b65\u9aa4\u90fd\u65e0\u6cd5\u5f62\u6210\u957f\u5ea6\u4e3a 2 \u7684\u4e00\u7ec4 1 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [1], m = 1\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [2,1], m = 2\n\u8f93\u51fa\uff1a2\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == arr.length
    • \n\t
    • 1 <= n <= 10^5
    • \n\t
    • 1 <= arr[i] <= n
    • \n\t
    • arr \u4e2d\u7684\u6240\u6709\u6574\u6570 \u4e92\u4e0d\u76f8\u540c
    • \n\t
    • 1 <= m <= arr.length
    • \n
    \n", "tags_en": ["Binary Search"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findLatestStep(vector& arr, int m) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findLatestStep(int[] arr, int m) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findLatestStep(self, arr, m):\n \"\"\"\n :type arr: List[int]\n :type m: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findLatestStep(self, arr: List[int], m: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findLatestStep(int* arr, int arrSize, int m){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindLatestStep(int[] arr, int m) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @param {number} m\n * @return {number}\n */\nvar findLatestStep = function(arr, m) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @param {Integer} m\n# @return {Integer}\ndef find_latest_step(arr, m)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findLatestStep(_ arr: [Int], _ m: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findLatestStep(arr []int, m int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findLatestStep(arr: Array[Int], m: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findLatestStep(arr: IntArray, m: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_latest_step(arr: Vec, m: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @param Integer $m\n * @return Integer\n */\n function findLatestStep($arr, $m) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findLatestStep(arr: number[], m: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-latest-step arr m)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1562](https://leetcode-cn.com/problems/find-latest-group-of-size-m)", "[\u67e5\u627e\u5927\u5c0f\u4e3a M \u7684\u6700\u65b0\u5206\u7ec4](/solution/1500-1599/1562.Find%20Latest%20Group%20of%20Size%20M/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1562](https://leetcode.com/problems/find-latest-group-of-size-m)", "[Find Latest Group of Size M](/solution/1500-1599/1562.Find%20Latest%20Group%20of%20Size%20M/README_EN.md)", "`Binary Search`", "Medium", ""]}, {"question_id": "1683", "frontend_question_id": "1561", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-number-of-coins-you-can-get", "url_en": "https://leetcode.com/problems/maximum-number-of-coins-you-can-get", "relative_path_cn": "/solution/1500-1599/1561.Maximum%20Number%20of%20Coins%20You%20Can%20Get/README.md", "relative_path_en": "/solution/1500-1599/1561.Maximum%20Number%20of%20Coins%20You%20Can%20Get/README_EN.md", "title_cn": "\u4f60\u53ef\u4ee5\u83b7\u5f97\u7684\u6700\u5927\u786c\u5e01\u6570\u76ee", "title_en": "Maximum Number of Coins You Can Get", "question_title_slug": "maximum-number-of-coins-you-can-get", "content_en": "

    There are 3n piles of coins of varying size, you and your friends will take piles of coins as follows:

    \n\n
      \n\t
    • In each step, you will choose any 3 piles of coins (not necessarily consecutive).
    • \n\t
    • Of your choice, Alice will pick the pile with the maximum number of coins.
    • \n\t
    • You will pick the next pile with maximum number of coins.
    • \n\t
    • Your friend Bob will pick the last pile.
    • \n\t
    • Repeat until there are no more piles of coins.
    • \n
    \n\n

    Given an array of integers piles where piles[i] is the number of coins in the ith pile.

    \n\n

    Return the maximum number of coins which you can have.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: piles = [2,4,1,2,7,8]\nOutput: 9\nExplanation: Choose the triplet (2, 7, 8), Alice Pick the pile with 8 coins, you the pile with 7 coins and Bob the last one.\nChoose the triplet (1, 2, 4), Alice Pick the pile with 4 coins, you the pile with 2 coins and Bob the last one.\nThe maximum number of coins which you can have are: 7 + 2 = 9.\nOn the other hand if we choose this arrangement (1, 2, 8), (2, 4, 7) you only get 2 + 4 = 6 coins which is not optimal.\n
    \n\n

    Example 2:

    \n\n
    \nInput: piles = [2,4,5]\nOutput: 4\n
    \n\n

    Example 3:

    \n\n
    \nInput: piles = [9,8,7,6,5,1,2,3,4]\nOutput: 18\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 3 <= piles.length <= 10^5
    • \n\t
    • piles.length % 3 == 0
    • \n\t
    • 1 <= piles[i] <= 10^4
    • \n
    \n", "content_cn": "

    \u6709 3n \u5806\u6570\u76ee\u4e0d\u4e00\u7684\u786c\u5e01\uff0c\u4f60\u548c\u4f60\u7684\u670b\u53cb\u4eec\u6253\u7b97\u6309\u4ee5\u4e0b\u65b9\u5f0f\u5206\u786c\u5e01\uff1a

    \n\n
      \n\t
    • \u6bcf\u4e00\u8f6e\u4e2d\uff0c\u4f60\u5c06\u4f1a\u9009\u51fa \u4efb\u610f 3 \u5806\u786c\u5e01\uff08\u4e0d\u4e00\u5b9a\u8fde\u7eed\uff09\u3002
    • \n\t
    • Alice \u5c06\u4f1a\u53d6\u8d70\u786c\u5e01\u6570\u91cf\u6700\u591a\u7684\u90a3\u4e00\u5806\u3002
    • \n\t
    • \u4f60\u5c06\u4f1a\u53d6\u8d70\u786c\u5e01\u6570\u91cf\u7b2c\u4e8c\u591a\u7684\u90a3\u4e00\u5806\u3002
    • \n\t
    • Bob \u5c06\u4f1a\u53d6\u8d70\u6700\u540e\u4e00\u5806\u3002
    • \n\t
    • \u91cd\u590d\u8fd9\u4e2a\u8fc7\u7a0b\uff0c\u76f4\u5230\u6ca1\u6709\u66f4\u591a\u786c\u5e01\u3002
    • \n
    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 piles \uff0c\u5176\u4e2d piles[i] \u662f\u7b2c i \u5806\u4e2d\u786c\u5e01\u7684\u6570\u76ee\u3002

    \n\n

    \u8fd4\u56de\u4f60\u53ef\u4ee5\u83b7\u5f97\u7684\u6700\u5927\u786c\u5e01\u6570\u76ee\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1apiles = [2,4,1,2,7,8]\n\u8f93\u51fa\uff1a9\n\u89e3\u91ca\uff1a\u9009\u51fa (2, 7, 8) \uff0cAlice \u53d6\u8d70 8 \u679a\u786c\u5e01\u7684\u90a3\u5806\uff0c\u4f60\u53d6\u8d70 7 \u679a\u786c\u5e01\u7684\u90a3\u5806\uff0cBob \u53d6\u8d70\u6700\u540e\u4e00\u5806\u3002\n\u9009\u51fa (1, 2, 4) , Alice \u53d6\u8d70 4 \u679a\u786c\u5e01\u7684\u90a3\u5806\uff0c\u4f60\u53d6\u8d70 2 \u679a\u786c\u5e01\u7684\u90a3\u5806\uff0cBob \u53d6\u8d70\u6700\u540e\u4e00\u5806\u3002\n\u4f60\u53ef\u4ee5\u83b7\u5f97\u7684\u6700\u5927\u786c\u5e01\u6570\u76ee\uff1a7 + 2 = 9.\n\u8003\u8651\u53e6\u5916\u4e00\u79cd\u60c5\u51b5\uff0c\u5982\u679c\u9009\u51fa\u7684\u662f (1, 2, 8) \u548c (2, 4, 7) \uff0c\u4f60\u5c31\u53ea\u80fd\u5f97\u5230 2 + 4 = 6 \u679a\u786c\u5e01\uff0c\u8fd9\u4e0d\u662f\u6700\u4f18\u89e3\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1apiles = [2,4,5]\n\u8f93\u51fa\uff1a4\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1apiles = [9,8,7,6,5,1,2,3,4]\n\u8f93\u51fa\uff1a18\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 3 <= piles.length <= 10^5
    • \n\t
    • piles.length % 3 == 0
    • \n\t
    • 1 <= piles[i] <= 10^4
    • \n
    \n", "tags_en": ["Sort"], "tags_cn": ["\u6392\u5e8f"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxCoins(vector& piles) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxCoins(int[] piles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxCoins(self, piles):\n \"\"\"\n :type piles: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxCoins(self, piles: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxCoins(int* piles, int pilesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxCoins(int[] piles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} piles\n * @return {number}\n */\nvar maxCoins = function(piles) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} piles\n# @return {Integer}\ndef max_coins(piles)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxCoins(_ piles: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxCoins(piles []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxCoins(piles: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxCoins(piles: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_coins(piles: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $piles\n * @return Integer\n */\n function maxCoins($piles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxCoins(piles: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-coins piles)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1561](https://leetcode-cn.com/problems/maximum-number-of-coins-you-can-get)", "[\u4f60\u53ef\u4ee5\u83b7\u5f97\u7684\u6700\u5927\u786c\u5e01\u6570\u76ee](/solution/1500-1599/1561.Maximum%20Number%20of%20Coins%20You%20Can%20Get/README.md)", "`\u6392\u5e8f`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1561](https://leetcode.com/problems/maximum-number-of-coins-you-can-get)", "[Maximum Number of Coins You Can Get](/solution/1500-1599/1561.Maximum%20Number%20of%20Coins%20You%20Can%20Get/README_EN.md)", "`Sort`", "Medium", ""]}, {"question_id": "1682", "frontend_question_id": "1560", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/most-visited-sector-in-a-circular-track", "url_en": "https://leetcode.com/problems/most-visited-sector-in-a-circular-track", "relative_path_cn": "/solution/1500-1599/1560.Most%20Visited%20Sector%20in%20%20a%20Circular%20Track/README.md", "relative_path_en": "/solution/1500-1599/1560.Most%20Visited%20Sector%20in%20%20a%20Circular%20Track/README_EN.md", "title_cn": "\u5706\u5f62\u8d5b\u9053\u4e0a\u7ecf\u8fc7\u6b21\u6570\u6700\u591a\u7684\u6247\u533a", "title_en": "Most Visited Sector in a Circular Track", "question_title_slug": "most-visited-sector-in-a-circular-track", "content_en": "

    Given an integer n and an integer array rounds. We have a circular track which consists of n sectors labeled from 1 to n. A marathon will be held on this track, the marathon consists of m rounds. The ith round starts at sector rounds[i - 1] and ends at sector rounds[i]. For example, round 1 starts at sector rounds[0] and ends at sector rounds[1]

    \n\n

    Return an array of the most visited sectors sorted in ascending order.

    \n\n

    Notice that you circulate the track in ascending order of sector numbers in the counter-clockwise direction (See the first example).

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: n = 4, rounds = [1,3,1,2]\nOutput: [1,2]\nExplanation: The marathon starts at sector 1. The order of the visited sectors is as follows:\n1 --> 2 --> 3 (end of round 1) --> 4 --> 1 (end of round 2) --> 2 (end of round 3 and the marathon)\nWe can see that both sectors 1 and 2 are visited twice and they are the most visited sectors. Sectors 3 and 4 are visited only once.
    \n\n

    Example 2:

    \n\n
    \nInput: n = 2, rounds = [2,1,2,1,2,1,2,1,2]\nOutput: [2]\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 7, rounds = [1,3,5,7]\nOutput: [1,2,3,4,5,6,7]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= n <= 100
    • \n\t
    • 1 <= m <= 100
    • \n\t
    • rounds.length == m + 1
    • \n\t
    • 1 <= rounds[i] <= n
    • \n\t
    • rounds[i] != rounds[i + 1] for 0 <= i < m
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n \u548c\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 rounds \u3002\u6709\u4e00\u6761\u5706\u5f62\u8d5b\u9053\u7531 n \u4e2a\u6247\u533a\u7ec4\u6210\uff0c\u6247\u533a\u7f16\u53f7\u4ece 1 \u5230 n \u3002\u73b0\u5c06\u5728\u8fd9\u6761\u8d5b\u9053\u4e0a\u4e3e\u529e\u4e00\u573a\u9a6c\u62c9\u677e\u6bd4\u8d5b\uff0c\u8be5\u9a6c\u62c9\u677e\u5168\u7a0b\u7531 m \u4e2a\u9636\u6bb5\u7ec4\u6210\u3002\u5176\u4e2d\uff0c\u7b2c i \u4e2a\u9636\u6bb5\u5c06\u4f1a\u4ece\u6247\u533a rounds[i - 1] \u5f00\u59cb\uff0c\u5230\u6247\u533a rounds[i] \u7ed3\u675f\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u7b2c 1 \u9636\u6bb5\u4ece rounds[0] \u5f00\u59cb\uff0c\u5230 rounds[1] \u7ed3\u675f\u3002

    \n\n

    \u8bf7\u4f60\u4ee5\u6570\u7ec4\u5f62\u5f0f\u8fd4\u56de\u7ecf\u8fc7\u6b21\u6570\u6700\u591a\u7684\u90a3\u51e0\u4e2a\u6247\u533a\uff0c\u6309\u6247\u533a\u7f16\u53f7 \u5347\u5e8f \u6392\u5217\u3002

    \n\n

    \u6ce8\u610f\uff0c\u8d5b\u9053\u6309\u6247\u533a\u7f16\u53f7\u5347\u5e8f\u9006\u65f6\u9488\u5f62\u6210\u4e00\u4e2a\u5706\uff08\u8bf7\u53c2\u89c1\u7b2c\u4e00\u4e2a\u793a\u4f8b\uff09\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 4, rounds = [1,3,1,2]\n\u8f93\u51fa\uff1a[1,2]\n\u89e3\u91ca\uff1a\u672c\u573a\u9a6c\u62c9\u677e\u6bd4\u8d5b\u4ece\u6247\u533a 1 \u5f00\u59cb\u3002\u7ecf\u8fc7\u5404\u4e2a\u6247\u533a\u7684\u6b21\u5e8f\u5982\u4e0b\u6240\u793a\uff1a\n1 --> 2 --> 3\uff08\u9636\u6bb5 1 \u7ed3\u675f\uff09--> 4 --> 1\uff08\u9636\u6bb5 2 \u7ed3\u675f\uff09--> 2\uff08\u9636\u6bb5 3 \u7ed3\u675f\uff0c\u5373\u672c\u573a\u9a6c\u62c9\u677e\u7ed3\u675f\uff09\n\u5176\u4e2d\uff0c\u6247\u533a 1 \u548c 2 \u90fd\u7ecf\u8fc7\u4e86\u4e24\u6b21\uff0c\u5b83\u4eec\u662f\u7ecf\u8fc7\u6b21\u6570\u6700\u591a\u7684\u4e24\u4e2a\u6247\u533a\u3002\u6247\u533a 3 \u548c 4 \u90fd\u53ea\u7ecf\u8fc7\u4e86\u4e00\u6b21\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1an = 2, rounds = [2,1,2,1,2,1,2,1,2]\n\u8f93\u51fa\uff1a[2]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1an = 7, rounds = [1,3,5,7]\n\u8f93\u51fa\uff1a[1,2,3,4,5,6,7]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= n <= 100
    • \n\t
    • 1 <= m <= 100
    • \n\t
    • rounds.length == m + 1
    • \n\t
    • 1 <= rounds[i] <= n
    • \n\t
    • rounds[i] != rounds[i + 1] \uff0c\u5176\u4e2d 0 <= i < m
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector mostVisited(int n, vector& rounds) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List mostVisited(int n, int[] rounds) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def mostVisited(self, n, rounds):\n \"\"\"\n :type n: int\n :type rounds: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def mostVisited(self, n: int, rounds: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* mostVisited(int n, int* rounds, int roundsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList MostVisited(int n, int[] rounds) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[]} rounds\n * @return {number[]}\n */\nvar mostVisited = function(n, rounds) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[]} rounds\n# @return {Integer[]}\ndef most_visited(n, rounds)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func mostVisited(_ n: Int, _ rounds: [Int]) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func mostVisited(n int, rounds []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def mostVisited(n: Int, rounds: Array[Int]): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun mostVisited(n: Int, rounds: IntArray): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn most_visited(n: i32, rounds: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[] $rounds\n * @return Integer[]\n */\n function mostVisited($n, $rounds) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function mostVisited(n: number, rounds: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (most-visited n rounds)\n (-> exact-integer? (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1560](https://leetcode-cn.com/problems/most-visited-sector-in-a-circular-track)", "[\u5706\u5f62\u8d5b\u9053\u4e0a\u7ecf\u8fc7\u6b21\u6570\u6700\u591a\u7684\u6247\u533a](/solution/1500-1599/1560.Most%20Visited%20Sector%20in%20%20a%20Circular%20Track/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1560](https://leetcode.com/problems/most-visited-sector-in-a-circular-track)", "[Most Visited Sector in a Circular Track](/solution/1500-1599/1560.Most%20Visited%20Sector%20in%20%20a%20Circular%20Track/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1681", "frontend_question_id": "1538", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/guess-the-majority-in-a-hidden-array", "url_en": "https://leetcode.com/problems/guess-the-majority-in-a-hidden-array", "relative_path_cn": "/solution/1500-1599/1538.Guess%20the%20Majority%20in%20a%20Hidden%20Array/README.md", "relative_path_en": "/solution/1500-1599/1538.Guess%20the%20Majority%20in%20a%20Hidden%20Array/README_EN.md", "title_cn": "\u627e\u51fa\u9690\u85cf\u6570\u7ec4\u4e2d\u51fa\u73b0\u6b21\u6570\u6700\u591a\u7684\u5143\u7d20", "title_en": "Guess the Majority in a Hidden Array", "question_title_slug": "guess-the-majority-in-a-hidden-array", "content_en": "

    We have an integer array nums, where all the integers in nums are 0 or 1. You will not be given direct access to the array, instead, you will have an API ArrayReader which have the following functions:

    \n\n
      \n\t
    • int query(int a, int b, int c, int d): where 0 <= a < b < c < d < ArrayReader.length(). The function returns the distribution of the value of the 4 elements and returns:\n\n\t
        \n\t\t
      • 4 : if the values of the 4 elements are the same (0 or 1).
      • \n\t\t
      • 2 : if three elements have a value equal to 0 and one element has value equal to 1 or vice versa.
      • \n\t\t
      • : if two element have a value equal to 0 and two elements have a value equal to 1.
      • \n\t
      \n\t
    • \n\t
    • int length(): Returns the size of the array.
    • \n
    \n\n

    You are allowed to call query() 2 * n times at most where n is equal to ArrayReader.length().

    \n\n

    Return any index of the most frequent value in nums, in case of tie, return -1.

    \n\n

    Follow up: What is the minimum number of calls needed to find the majority element?

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [0,0,1,0,1,1,1,1]\nOutput: 5\nExplanation: The following calls to the API\nreader.length() // returns 8 because there are 8 elements in the hidden array.\nreader.query(0,1,2,3) // returns 2 this is a query that compares the elements nums[0], nums[1], nums[2], nums[3]\n// Three elements have a value equal to 0 and one element has value equal to 1 or viceversa.\nreader.query(4,5,6,7) // returns 4 because nums[4], nums[5], nums[6], nums[7] have the same value.\nwe can infer that the most frequent value is found in the last 4 elements.\nIndex 2, 4, 6, 7 is also a correct answer.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [0,0,1,1,0]\nOutput: 0\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [1,0,1,0,1,0,1,0]\nOutput: -1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 5 <= nums.length <= 10^5
    • \n\t
    • 0 <= nums[i] <= 1
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums\uff0c\u4e14 nums \u4e2d\u7684\u6240\u6709\u6574\u6570\u90fd\u4e3a 0 \u6216 1\u3002\u4f60\u4e0d\u80fd\u76f4\u63a5\u8bbf\u95ee\u8fd9\u4e2a\u6570\u7ec4\uff0c\u4f60\u9700\u8981\u4f7f\u7528 API ArrayReader \uff0c\u8be5 API \u542b\u6709\u4e0b\u5217\u6210\u5458\u51fd\u6570\uff1a

    \n\n
      \n\t
    • int query(int a, int b, int c, int d)\uff1a\u5176\u4e2d 0 <= a < b < c < d < ArrayReader.length() \u3002\u6b64\u51fd\u6570\u67e5\u8be2\u4ee5\u8fd9\u56db\u4e2a\u53c2\u6570\u4e3a\u4e0b\u6807\u7684\u5143\u7d20\u5e76\u8fd4\u56de\uff1a\n\n\t
        \n\t\t
      • 4 : \u5f53\u8fd9\u56db\u4e2a\u5143\u7d20\u76f8\u540c\uff080 \u6216 1\uff09\u65f6\u3002
      • \n\t\t
      • 2 : \u5f53\u5176\u4e2d\u4e09\u4e2a\u5143\u7d20\u7684\u503c\u7b49\u4e8e 0 \u4e14\u4e00\u4e2a\u5143\u7d20\u7b49\u4e8e 1 \u65f6\uff0c\u6216\u5f53\u5176\u4e2d\u4e09\u4e2a\u5143\u7d20\u7684\u503c\u7b49\u4e8e 1 \u4e14\u4e00\u4e2a\u5143\u7d20\u7b49\u4e8e 0 \u65f6\u3002
      • \n\t\t
      • : \u5f53\u5176\u4e2d\u4e24\u4e2a\u5143\u7d20\u7b49\u4e8e 0 \u4e14\u4e24\u4e2a\u5143\u7d20\u7b49\u4e8e 1 \u65f6\u3002
      • \n\t
      \n\t
    • \n\t
    • int length()\uff1a\u8fd4\u56de\u6570\u7ec4\u7684\u957f\u5ea6\u3002
    • \n
    \n\n

    \u4f60\u53ef\u4ee5\u8c03\u7528 query() \u6700\u591a 2 * n \u6b21\uff0c\u5176\u4e2d n \u7b49\u4e8e ArrayReader.length()\u3002

    \n\n

    \u8fd4\u56de nums \u4e2d\u51fa\u73b0\u6b21\u6570\u6700\u591a\u7684\u503c\u7684\u4efb\u610f\u7d22\u5f15\uff0c\u82e5\u6240\u6709\u7684\u503c\u51fa\u73b0\u6b21\u6570\u5747\u76f8\u540c\uff0c\u8fd4\u56de -1\u3002

    \n\n

    \u8fdb\u9636\uff1a\u8981\u627e\u5230\u51fa\u73b0\u6b21\u6570\u6700\u591a\u7684\u5143\u7d20\uff0c\u9700\u8981\u81f3\u5c11\u8c03\u7528 query() \u591a\u5c11\u6b21\uff1f

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165: nums = [0,0,1,0,1,1,1,1]\n\u8f93\u51fa: 5\n\u89e3\u91ca: API \u7684\u8c03\u7528\u60c5\u51b5\u5982\u4e0b\uff1a\nreader.length() // \u8fd4\u56de 8\uff0c\u56e0\u4e3a\u9690\u85cf\u6570\u7ec4\u4e2d\u6709 8 \u4e2a\u5143\u7d20\u3002\nreader.query(0,1,2,3) // \u8fd4\u56de 2\uff0c\u67e5\u8be2\u5143\u7d20 nums[0], nums[1], nums[2], nums[3] \u95f4\u7684\u6bd4\u8f83\u3002\n// \u4e09\u4e2a\u5143\u7d20\u7b49\u4e8e 0 \u4e14\u4e00\u4e2a\u5143\u7d20\u7b49\u4e8e 1 \u6216\u51fa\u73b0\u76f8\u53cd\u60c5\u51b5\u3002\nreader.query(4,5,6,7) // \u8fd4\u56de 4\uff0c\u56e0\u4e3a nums[4], nums[5], nums[6], nums[7] \u6709\u76f8\u540c\u503c\u3002\n\u6211\u4eec\u53ef\u4ee5\u63a8\u65ad\uff0c\u6700\u5e38\u51fa\u73b0\u7684\u503c\u5728\u6700\u540e 4 \u4e2a\u5143\u7d20\u4e2d\u3002\n\u7d22\u5f15 2, 4, 6, 7 \u4e5f\u662f\u6b63\u786e\u7b54\u6848\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: nums = [0,0,1,1,0]\n\u8f93\u51fa: 0\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u8f93\u5165: nums = [1,0,1,0,1,0,1,0]\n\u8f93\u51fa: -1\n
    \n\n

     

    \n\n

    \u63d0\u793a:

    \n\n
      \n\t
    • 5 <= nums.length <= 10^5
    • \n\t
    • 0 <= nums[i] <= 1
    • \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * // This is the ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * class ArrayReader {\n * public:\n * // Compares 4 different elements in the array\n * // return 4 if the values of the 4 elements are the same (0 or 1).\n * // return 2 if three\u00a0elements have a value\u00a0equal to 0\u00a0and one\u00a0element has value equal to 1\u00a0or vice versa.\n * // return 0 :\u00a0if two element have a value equal to 0 and two elements have a value equal to 1.\n * int query(int a, int b, int c, int d);\n *\n * // Returns the length of the array\n * int length();\n * };\n */\n\nclass Solution {\npublic:\n int guessMajority(ArrayReader &reader) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * // This is the ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * interface ArrayReader {\n * public:\n * // Compares 4 different elements in the array\n * // return 4 if the values of the 4 elements are the same (0 or 1).\n * // return 2 if three\u00a0elements have a value\u00a0equal to 0\u00a0and one\u00a0element has value equal to 1\u00a0or vice versa.\n * // return 0 :\u00a0if two element have a value equal to 0 and two elements have a value equal to 1.\n * public int query(int a, int b, int c, int d);\n *\n * // Returns the length of the array\n * public int length();\n * };\n */\n\nclass Solution {\n public int guessMajority(ArrayReader reader) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# \"\"\"\n# This is the ArrayReader's API interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class ArrayReader(object):\n#\t # Compares 4 different elements in the array\n#\t # return 4 if the values of the 4 elements are the same (0 or 1).\n#\t # return 2 if three\u00a0elements have a value\u00a0equal to 0\u00a0and one\u00a0element has value equal to 1\u00a0or vice versa.\n#\t # return 0 :\u00a0if two element have a value equal to 0 and two elements have a value equal to 1.\n# def query(self, a, b, c, d):\n# \"\"\"\n# :type a, b, c, d: int\n# :rtype int\n# \"\"\"\n#\n#\t # Returns the length of the array\n# def length(self):\n# \"\"\"\n# :rtype int\n# \n\nclass Solution(object):\n def guessMajority(self, reader):\n \"\"\"\n :type reader: ArrayReader\n :rtype: integer\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# \"\"\"\n# This is the ArrayReader's API interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class ArrayReader(object):\n#\t # Compares 4 different elements in the array\n#\t # return 4 if the values of the 4 elements are the same (0 or 1).\n#\t # return 2 if three\u00a0elements have a value\u00a0equal to 0\u00a0and one\u00a0element has value equal to 1\u00a0or vice versa.\n#\t # return 0 :\u00a0if two element have a value equal to 0 and two elements have a value equal to 1.\n# def query(self, a: int, b: int, c: int, d: int) -> int:\n#\n#\t # Returns the length of the array\n# def length(self) -> int:\n#\n\nclass Solution:\n def guessMajority(self, reader: 'ArrayReader') -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * *********************************************************************\n * // This is the ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * *********************************************************************\n *\n * // Compares 4 different elements in the array\n * // return 4 if the values of the 4 elements are the same (0 or 1).\n * // return 2 if three\u00a0elements have a value\u00a0equal to 0\u00a0and one\u00a0element has value equal to 1\u00a0or vice versa.\n * // return 0 :\u00a0if two element have a value equal to 0 and two elements have a value equal to 1.\n * int query(ArrayReader *, int a, int b, int c, int d);\n *\n * // Returns the length of the array\n * int length(ArrayReader *);\n */\n\nint guessMajority(ArrayReader* reader) {\n\t\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * // This is the ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * class ArrayReader {\n * public:\n * // Compares 4 different elements in the array\n * // return 4 if the values of the 4 elements are the same (0 or 1).\n * // return 2 if three\u00a0elements have a value\u00a0equal to 0\u00a0and one\u00a0element has value equal to 1\u00a0or vice versa.\n * // return 0 :\u00a0if two element have a value equal to 0 and two elements have a value equal to 1.\n * public int Query(int a, int b, int c, int d) {}\n *\n * // Returns the length of the array\n * public int Length() {}\n * };\n */\n\nclass Solution {\n public int GuessMajority(ArrayReader reader) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // This is the ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * function ArrayReader() {\n * // Compares 4 different elements in the array\n * // return 4 if the values of the 4 elements are the same (0 or 1).\n * // return 2 if three\u00a0elements have a value\u00a0equal to 0\u00a0and one\u00a0element has value equal to 1\u00a0or vice versa.\n * // return 0 :\u00a0if two element have a value equal to 0 and two elements have a value equal to 1.\n * @param {number} a, b, c, d\n * @return {number}\n * this.query = function(a, b, c, d) {\n * ...\n * }; \n *\n * // Returns the length of the array\n * @return {number}\n * this.length = function() {\n * ...\n * };\n * };\n */\n\n/**\n * @param {ArrayReader} reader\n * @return {number}\n */\nvar guessMajority = function(reader) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# This is ArrayReader's API interface.\n# You should not implement it, or speculate about its implementation\n# class ArrayReader\n#\t # Compares 4 different elements in the array\n#\t # return 4 if the values of the 4 elements are the same (0 or 1).\n#\t # return 2 if three\u00a0elements have a value\u00a0equal to 0\u00a0and one\u00a0element has value equal to 1\u00a0or vice versa.\n#\t # return 0 :\u00a0if two element have a value equal to 0 and two elements have a value equal to 1.\n# def query(a, b, c, d):\n# \n# end\n#\n#\t # Returns the length of the array\n# def length()\n#\t\t\n#\t end\n# end\n\n# @param {ArrayReader} reader\n# @return {int}\ndef guess_majority(reader)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * // This is ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * interface ArrayReader {\n * // Compares 4 different elements in the array\n * // return 4 if the values of the 4 elements are the same (0 or 1).\n * // return 2 if three\u00a0elements have a value\u00a0equal to 0\u00a0and one\u00a0element has value equal to 1\u00a0or vice versa.\n * // return 0 :\u00a0if two element have a value equal to 0 and two elements have a value equal to 1.\n * public func query(_ a: Int, _ b: Int, _ c: Int, _ d: Int) -> Int {}\n *\n * // Returns the length of the array\n * public func length() -> Int {}\n * }\n */\n\nclass Solution {\n func guessMajority(_ reader: ArrayReader) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * // This is the ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * type ArrayReader struct {\n * }\n * // Compares 4 different elements in the array\n * // return 4 if the values of the 4 elements are the same (0 or 1).\n * // return 2 if three\u00a0elements have a value\u00a0equal to 0\u00a0and one\u00a0element has value equal to 1\u00a0or vice versa.\n * // return 0 :\u00a0if two element have a value equal to 0 and two elements have a value equal to 1.\n * func (this *ArrayReader) query(a, b, c, d int) int {}\n * \n * // Returns the length of the array\n * func (this *ArrayReader) length() int {}\n */\n\nfunc guessMajority(reader *ArrayReader) int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * // This is ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * interface ArrayReader {\n * // Compares 4 different elements in the array\n * // return 4 if the values of the 4 elements are the same (0 or 1).\n * // return 2 if three\u00a0elements have a value\u00a0equal to 0\u00a0and one\u00a0element has value equal to 1\u00a0or vice versa.\n * // return 0 :\u00a0if two element have a value equal to 0 and two elements have a value equal to 1.\n * def query(a: Int, b: Int, c: Int, d: Int): Int {}\n *\n * // Returns the length of the array\n * def length(): Int {}\n * }\n */\n\nobject Solution {\n def guessMajority(reader: ArrayReader): Int = {\n \n\t}\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * // This is ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * interface ArrayReader {\n * // Compares 4 different elements in the array\n * // return 4 if the values of the 4 elements are the same (0 or 1).\n * // return 2 if three\u00a0elements have a value\u00a0equal to 0\u00a0and one\u00a0element has value equal to 1\u00a0or vice versa.\n * // return 0 :\u00a0if two element have a value equal to 0 and two elements have a value equal to 1.\n * fun query(a: Int, b: Int, c: Int, d: Int): Int {}\n *\n * // Returns the length of the array\n * fun length(): Int {}\n * }\n */\n\nclass Solution {\n fun guessMajority(reader: ArrayReader): Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "/**\n * // This is the ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * struct ArrayReader;\n * impl ArrayReader {\n * // Compares 4 different elements in the array\n * // return 4 if the values of the 4 elements are the same (0 or 1).\n * // return 2 if three elements have a value equal to 0 and one element has value equal to 1 or vice versa.\n * // return 0 : if two element have a value equal to 0 and two elements have a value equal to 1.\n * pub fn query(a: i32, b: i32, c: i32, d: i32) -> i32 {}\n *\n * // Returns the length of the array\n * pub fn length() -> i32 {}\n * };\n */\n\nimpl Solution {\n pub fn get_majority(reader: &ArrayReader) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * // This is ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * interface ArrayReader {\n * // Compares 4 different elements in the array\n * // return 4 if the values of the 4 elements are the same (0 or 1).\n * // return 2 if three\u00a0elements have a value\u00a0equal to 0\u00a0and one\u00a0element has value equal to 1\u00a0or vice versa.\n * // return 0 :\u00a0if two element have a value equal to 0 and two elements have a value equal to 1.\n * function query($a, $b, $c, $d) {}\n *\n * // Returns the length of the array\n * function length() {}\n * }\n */\n\nclass Solution {\n /**\n * @param ArrayReader $reader\n * @return Integer\n */\n function guessMajority($reader) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * // This is the ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * class ArrayReader {\n * // Compares 4 different elements in the array\n * // return 4 if the values of the 4 elements are the same (0 or 1).\n * // return 2 if three\u00a0elements have a value\u00a0equal to 0\u00a0and one\u00a0element has value equal to 1\u00a0or vice versa.\n * // return 0 :\u00a0if two element have a value equal to 0 and two elements have a value equal to 1.\n * query(a: number, b: number, c: number, d: number): number { };\n *\n * // Returns the length of the array\n * length(): number { };\n * };\n */\n\nfunction guessMajority(reader: ArrayReader): number {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1538](https://leetcode-cn.com/problems/guess-the-majority-in-a-hidden-array)", "[\u627e\u51fa\u9690\u85cf\u6570\u7ec4\u4e2d\u51fa\u73b0\u6b21\u6570\u6700\u591a\u7684\u5143\u7d20](/solution/1500-1599/1538.Guess%20the%20Majority%20in%20a%20Hidden%20Array/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1538](https://leetcode.com/problems/guess-the-majority-in-a-hidden-array)", "[Guess the Majority in a Hidden Array](/solution/1500-1599/1538.Guess%20the%20Majority%20in%20a%20Hidden%20Array/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1680", "frontend_question_id": "1575", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-all-possible-routes", "url_en": "https://leetcode.com/problems/count-all-possible-routes", "relative_path_cn": "/solution/1500-1599/1575.Count%20All%20Possible%20Routes/README.md", "relative_path_en": "/solution/1500-1599/1575.Count%20All%20Possible%20Routes/README_EN.md", "title_cn": "\u7edf\u8ba1\u6240\u6709\u53ef\u884c\u8def\u5f84", "title_en": "Count All Possible Routes", "question_title_slug": "count-all-possible-routes", "content_en": "

    You are given an array of distinct positive integers locations where locations[i] represents the position of city i. You are also given integers startfinish and fuel representing the starting city, ending city, and the initial amount of fuel you have, respectively.

    \n\n

    At each step, if you are at city i, you can pick any city j such that j != i and 0 <= j < locations.length and move to city j. Moving from city i to city j reduces the amount of fuel you have by |locations[i] - locations[j]|. Please notice that |x| denotes the absolute value of x.

    \n\n

    Notice that fuel cannot become negative at any point in time, and that you are allowed to visit any city more than once (including start and finish).

    \n\n

    Return the count of all possible routes from start to finish.

    \n\n

    Since the answer may be too large, return it modulo 10^9 + 7.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: locations = [2,3,6,8,4], start = 1, finish = 3, fuel = 5\nOutput: 4\nExplanation: The following are all possible routes, each uses 5 units of fuel:\n1 -> 3\n1 -> 2 -> 3\n1 -> 4 -> 3\n1 -> 4 -> 2 -> 3\n
    \n\n

    Example 2:

    \n\n
    \nInput: locations = [4,3,1], start = 1, finish = 0, fuel = 6\nOutput: 5\nExplanation: The following are all possible routes:\n1 -> 0, used fuel = 1\n1 -> 2 -> 0, used fuel = 5\n1 -> 2 -> 1 -> 0, used fuel = 5\n1 -> 0 -> 1 -> 0, used fuel = 3\n1 -> 0 -> 1 -> 0 -> 1 -> 0, used fuel = 5\n
    \n\n

    Example 3:

    \n\n
    \nInput: locations = [5,2,1], start = 0, finish = 2, fuel = 3\nOutput: 0\nExplanation: It's impossible to get from 0 to 2 using only 3 units of fuel since the shortest route needs 4 units of fuel.
    \n\n

    Example 4:

    \n\n
    \nInput: locations = [2,1,5], start = 0, finish = 0, fuel = 3\nOutput: 2\nExplanation: There are two possible routes, 0 and 0 -> 1 -> 0.
    \n\n

    Example 5:

    \n\n
    \nInput: locations = [1,2,3], start = 0, finish = 2, fuel = 40\nOutput: 615088286\nExplanation: The total number of possible routes is 2615088300. Taking this number modulo 10^9 + 7 gives us 615088286.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= locations.length <= 100
    • \n\t
    • 1 <= locations[i] <= 10^9
    • \n\t
    • All integers in locations are distinct.
    • \n\t
    • 0 <= start, finish < locations.length
    • \n\t
    • 1 <= fuel <= 200
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a \u4e92\u4e0d\u76f8\u540c \u7684\u6574\u6570\u6570\u7ec4\uff0c\u5176\u4e2d locations[i] \u8868\u793a\u7b2c i \u4e2a\u57ce\u5e02\u7684\u4f4d\u7f6e\u3002\u540c\u65f6\u7ed9\u4f60 start\uff0cfinish \u548c fuel \u5206\u522b\u8868\u793a\u51fa\u53d1\u57ce\u5e02\u3001\u76ee\u7684\u5730\u57ce\u5e02\u548c\u4f60\u521d\u59cb\u62e5\u6709\u7684\u6c7d\u6cb9\u603b\u91cf

    \n\n

    \u6bcf\u4e00\u6b65\u4e2d\uff0c\u5982\u679c\u4f60\u5728\u57ce\u5e02 i \uff0c\u4f60\u53ef\u4ee5\u9009\u62e9\u4efb\u610f\u4e00\u4e2a\u57ce\u5e02 j \uff0c\u6ee1\u8db3  j != i \u4e14 0 <= j < locations.length \uff0c\u5e76\u79fb\u52a8\u5230\u57ce\u5e02 j \u3002\u4ece\u57ce\u5e02 i \u79fb\u52a8\u5230 j \u6d88\u8017\u7684\u6c7d\u6cb9\u91cf\u4e3a |locations[i] - locations[j]|\uff0c|x| \u8868\u793a x \u7684\u7edd\u5bf9\u503c\u3002

    \n\n

    \u8bf7\u6ce8\u610f\uff0c fuel \u4efb\u4f55\u65f6\u523b\u90fd \u4e0d\u80fd \u4e3a\u8d1f\uff0c\u4e14\u4f60 \u53ef\u4ee5 \u7ecf\u8fc7\u4efb\u610f\u57ce\u5e02\u8d85\u8fc7\u4e00\u6b21\uff08\u5305\u62ec start \u548c finish \uff09\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u4ece start \u5230 finish \u6240\u6709\u53ef\u80fd\u8def\u5f84\u7684\u6570\u76ee\u3002

    \n\n

    \u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u5f88\u5927\uff0c \u8bf7\u5c06\u5b83\u5bf9 10^9 + 7 \u53d6\u4f59\u540e\u8fd4\u56de\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1alocations = [2,3,6,8,4], start = 1, finish = 3, fuel = 5\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u4ee5\u4e0b\u4e3a\u6240\u6709\u53ef\u80fd\u8def\u5f84\uff0c\u6bcf\u4e00\u6761\u90fd\u7528\u4e86 5 \u5355\u4f4d\u7684\u6c7d\u6cb9\uff1a\n1 -> 3\n1 -> 2 -> 3\n1 -> 4 -> 3\n1 -> 4 -> 2 -> 3\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1alocations = [4,3,1], start = 1, finish = 0, fuel = 6\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u4ee5\u4e0b\u4e3a\u6240\u6709\u53ef\u80fd\u7684\u8def\u5f84\uff1a\n1 -> 0\uff0c\u4f7f\u7528\u6c7d\u6cb9\u91cf\u4e3a fuel = 1\n1 -> 2 -> 0\uff0c\u4f7f\u7528\u6c7d\u6cb9\u91cf\u4e3a fuel = 5\n1 -> 2 -> 1 -> 0\uff0c\u4f7f\u7528\u6c7d\u6cb9\u91cf\u4e3a fuel = 5\n1 -> 0 -> 1 -> 0\uff0c\u4f7f\u7528\u6c7d\u6cb9\u91cf\u4e3a fuel = 3\n1 -> 0 -> 1 -> 0 -> 1 -> 0\uff0c\u4f7f\u7528\u6c7d\u6cb9\u91cf\u4e3a fuel = 5\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1alocations = [5,2,1], start = 0, finish = 2, fuel = 3\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6ca1\u6709\u529e\u6cd5\u53ea\u7528 3 \u5355\u4f4d\u7684\u6c7d\u6cb9\u4ece 0 \u5230\u8fbe 2 \u3002\u56e0\u4e3a\u6700\u77ed\u8def\u5f84\u9700\u8981 4 \u5355\u4f4d\u7684\u6c7d\u6cb9\u3002
    \n\n

    \u793a\u4f8b 4 \uff1a

    \n\n
    \n\u8f93\u5165\uff1alocations = [2,1,5], start = 0, finish = 0, fuel = 3\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u603b\u5171\u6709\u4e24\u6761\u53ef\u884c\u8def\u5f84\uff0c0 \u548c 0 -> 1 -> 0 \u3002
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1alocations = [1,2,3], start = 0, finish = 2, fuel = 40\n\u8f93\u51fa\uff1a615088286\n\u89e3\u91ca\uff1a\u8def\u5f84\u603b\u6570\u4e3a 2615088300 \u3002\u5c06\u7ed3\u679c\u5bf9 10^9 + 7 \u53d6\u4f59\uff0c\u5f97\u5230 615088286 \u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= locations.length <= 100
    • \n\t
    • 1 <= locations[i] <= 10^9
    • \n\t
    • \u6240\u6709 locations \u4e2d\u7684\u6574\u6570 \u4e92\u4e0d\u76f8\u540c \u3002
    • \n\t
    • 0 <= start, finish < locations.length
    • \n\t
    • 1 <= fuel <= 200
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countRoutes(vector& locations, int start, int finish, int fuel) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countRoutes(int[] locations, int start, int finish, int fuel) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countRoutes(self, locations, start, finish, fuel):\n \"\"\"\n :type locations: List[int]\n :type start: int\n :type finish: int\n :type fuel: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countRoutes(self, locations: List[int], start: int, finish: int, fuel: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countRoutes(int* locations, int locationsSize, int start, int finish, int fuel){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountRoutes(int[] locations, int start, int finish, int fuel) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} locations\n * @param {number} start\n * @param {number} finish\n * @param {number} fuel\n * @return {number}\n */\nvar countRoutes = function(locations, start, finish, fuel) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} locations\n# @param {Integer} start\n# @param {Integer} finish\n# @param {Integer} fuel\n# @return {Integer}\ndef count_routes(locations, start, finish, fuel)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countRoutes(_ locations: [Int], _ start: Int, _ finish: Int, _ fuel: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countRoutes(locations []int, start int, finish int, fuel int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countRoutes(locations: Array[Int], start: Int, finish: Int, fuel: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countRoutes(locations: IntArray, start: Int, finish: Int, fuel: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_routes(locations: Vec, start: i32, finish: i32, fuel: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $locations\n * @param Integer $start\n * @param Integer $finish\n * @param Integer $fuel\n * @return Integer\n */\n function countRoutes($locations, $start, $finish, $fuel) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countRoutes(locations: number[], start: number, finish: number, fuel: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-routes locations start finish fuel)\n (-> (listof exact-integer?) exact-integer? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1575](https://leetcode-cn.com/problems/count-all-possible-routes)", "[\u7edf\u8ba1\u6240\u6709\u53ef\u884c\u8def\u5f84](/solution/1500-1599/1575.Count%20All%20Possible%20Routes/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1575](https://leetcode.com/problems/count-all-possible-routes)", "[Count All Possible Routes](/solution/1500-1599/1575.Count%20All%20Possible%20Routes/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1679", "frontend_question_id": "1574", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/shortest-subarray-to-be-removed-to-make-array-sorted", "url_en": "https://leetcode.com/problems/shortest-subarray-to-be-removed-to-make-array-sorted", "relative_path_cn": "/solution/1500-1599/1574.Shortest%20Subarray%20to%20be%20Removed%20to%20Make%20Array%20Sorted/README.md", "relative_path_en": "/solution/1500-1599/1574.Shortest%20Subarray%20to%20be%20Removed%20to%20Make%20Array%20Sorted/README_EN.md", "title_cn": "\u5220\u9664\u6700\u77ed\u7684\u5b50\u6570\u7ec4\u4f7f\u5269\u4f59\u6570\u7ec4\u6709\u5e8f", "title_en": "Shortest Subarray to be Removed to Make Array Sorted", "question_title_slug": "shortest-subarray-to-be-removed-to-make-array-sorted", "content_en": "

    Given an integer array arr, remove a subarray (can be empty) from arr such that the remaining elements in arr are non-decreasing.

    \n\n

    A subarray is a contiguous subsequence of the array.

    \n\n

    Return the length of the shortest subarray to remove.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr = [1,2,3,10,4,2,3,5]\nOutput: 3\nExplanation: The shortest subarray we can remove is [10,4,2] of length 3. The remaining elements after that will be [1,2,3,3,5] which are sorted.\nAnother correct solution is to remove the subarray [3,10,4].
    \n\n

    Example 2:

    \n\n
    \nInput: arr = [5,4,3,2,1]\nOutput: 4\nExplanation: Since the array is strictly decreasing, we can only keep a single element. Therefore we need to remove a subarray of length 4, either [5,4,3,2] or [4,3,2,1].\n
    \n\n

    Example 3:

    \n\n
    \nInput: arr = [1,2,3]\nOutput: 0\nExplanation: The array is already non-decreasing. We do not need to remove any elements.\n
    \n\n

    Example 4:

    \n\n
    \nInput: arr = [1]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= arr.length <= 10^5
    • \n\t
    • 0 <= arr[i] <= 10^9
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr \uff0c\u8bf7\u4f60\u5220\u9664\u4e00\u4e2a\u5b50\u6570\u7ec4\uff08\u53ef\u4ee5\u4e3a\u7a7a\uff09\uff0c\u4f7f\u5f97 arr \u4e2d\u5269\u4e0b\u7684\u5143\u7d20\u662f \u975e\u9012\u51cf \u7684\u3002

    \n\n

    \u4e00\u4e2a\u5b50\u6570\u7ec4\u6307\u7684\u662f\u539f\u6570\u7ec4\u4e2d\u8fde\u7eed\u7684\u4e00\u4e2a\u5b50\u5e8f\u5217\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u6ee1\u8db3\u9898\u76ee\u8981\u6c42\u7684\u6700\u77ed\u5b50\u6570\u7ec4\u7684\u957f\u5ea6\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [1,2,3,10,4,2,3,5]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6211\u4eec\u9700\u8981\u5220\u9664\u7684\u6700\u77ed\u5b50\u6570\u7ec4\u662f [10,4,2] \uff0c\u957f\u5ea6\u4e3a 3 \u3002\u5269\u4f59\u5143\u7d20\u5f62\u6210\u975e\u9012\u51cf\u6570\u7ec4 [1,2,3,3,5] \u3002\n\u53e6\u4e00\u4e2a\u6b63\u786e\u7684\u89e3\u4e3a\u5220\u9664\u5b50\u6570\u7ec4 [3,10,4] \u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [5,4,3,2,1]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u7531\u4e8e\u6570\u7ec4\u662f\u4e25\u683c\u9012\u51cf\u7684\uff0c\u6211\u4eec\u53ea\u80fd\u4fdd\u7559\u4e00\u4e2a\u5143\u7d20\u3002\u6240\u4ee5\u6211\u4eec\u9700\u8981\u5220\u9664\u957f\u5ea6\u4e3a 4 \u7684\u5b50\u6570\u7ec4\uff0c\u8981\u4e48\u5220\u9664 [5,4,3,2]\uff0c\u8981\u4e48\u5220\u9664 [4,3,2,1]\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [1,2,3]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6570\u7ec4\u5df2\u7ecf\u662f\u975e\u9012\u51cf\u7684\u4e86\uff0c\u6211\u4eec\u4e0d\u9700\u8981\u5220\u9664\u4efb\u4f55\u5143\u7d20\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [1]\n\u8f93\u51fa\uff1a0\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= arr.length <= 10^5
    • \n\t
    • 0 <= arr[i] <= 10^9
    • \n
    \n", "tags_en": ["Array", "Binary Search"], "tags_cn": ["\u6570\u7ec4", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findLengthOfShortestSubarray(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findLengthOfShortestSubarray(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findLengthOfShortestSubarray(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findLengthOfShortestSubarray(self, arr: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findLengthOfShortestSubarray(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindLengthOfShortestSubarray(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar findLengthOfShortestSubarray = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef find_length_of_shortest_subarray(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findLengthOfShortestSubarray(_ arr: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findLengthOfShortestSubarray(arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findLengthOfShortestSubarray(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findLengthOfShortestSubarray(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_length_of_shortest_subarray(arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function findLengthOfShortestSubarray($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findLengthOfShortestSubarray(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-length-of-shortest-subarray arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1574](https://leetcode-cn.com/problems/shortest-subarray-to-be-removed-to-make-array-sorted)", "[\u5220\u9664\u6700\u77ed\u7684\u5b50\u6570\u7ec4\u4f7f\u5269\u4f59\u6570\u7ec4\u6709\u5e8f](/solution/1500-1599/1574.Shortest%20Subarray%20to%20be%20Removed%20to%20Make%20Array%20Sorted/README.md)", "`\u6570\u7ec4`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1574](https://leetcode.com/problems/shortest-subarray-to-be-removed-to-make-array-sorted)", "[Shortest Subarray to be Removed to Make Array Sorted](/solution/1500-1599/1574.Shortest%20Subarray%20to%20be%20Removed%20to%20Make%20Array%20Sorted/README_EN.md)", "`Array`,`Binary Search`", "Medium", ""]}, {"question_id": "1678", "frontend_question_id": "1573", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-ways-to-split-a-string", "url_en": "https://leetcode.com/problems/number-of-ways-to-split-a-string", "relative_path_cn": "/solution/1500-1599/1573.Number%20of%20Ways%20to%20Split%20a%20String/README.md", "relative_path_en": "/solution/1500-1599/1573.Number%20of%20Ways%20to%20Split%20a%20String/README_EN.md", "title_cn": "\u5206\u5272\u5b57\u7b26\u4e32\u7684\u65b9\u6848\u6570", "title_en": "Number of Ways to Split a String", "question_title_slug": "number-of-ways-to-split-a-string", "content_en": "

    Given a binary string s (a string consisting only of '0's and '1's), we can split s into 3 non-empty strings s1, s2, s3 (s1+ s2+ s3 = s).

    \n\n

    Return the number of ways s can be split such that the number of characters '1' is the same in s1, s2, and s3.

    \n\n

    Since the answer may be too large, return it modulo 10^9 + 7.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "10101"\nOutput: 4\nExplanation: There are four ways to split s in 3 parts where each part contain the same number of letters '1'.\n"1|010|1"\n"1|01|01"\n"10|10|1"\n"10|1|01"\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "1001"\nOutput: 0\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "0000"\nOutput: 3\nExplanation: There are three ways to split s in 3 parts.\n"0|0|00"\n"0|00|0"\n"00|0|0"\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "100100010100110"\nOutput: 12\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 3 <= s.length <= 10^5
    • \n\t
    • s[i] is '0' or '1'.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u4e8c\u8fdb\u5236\u4e32 s  \uff08\u4e00\u4e2a\u53ea\u5305\u542b 0 \u548c 1 \u7684\u5b57\u7b26\u4e32\uff09\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06 s \u5206\u5272\u6210 3 \u4e2a \u975e\u7a7a \u5b57\u7b26\u4e32 s1, s2, s3 \uff08s1 + s2 + s3 = s\uff09\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u5206\u5272 s \u7684\u65b9\u6848\u6570\uff0c\u6ee1\u8db3 s1\uff0cs2 \u548c s3 \u4e2d\u5b57\u7b26 '1' \u7684\u6570\u76ee\u76f8\u540c\u3002

    \n\n

    \u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u5f88\u5927\uff0c\u8bf7\u5c06\u5b83\u5bf9 10^9 + 7 \u53d6\u4f59\u540e\u8fd4\u56de\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1as = "10101"\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u603b\u5171\u6709 4 \u79cd\u65b9\u6cd5\u5c06 s \u5206\u5272\u6210\u542b\u6709 '1' \u6570\u76ee\u76f8\u540c\u7684\u4e09\u4e2a\u5b50\u5b57\u7b26\u4e32\u3002\n"1|010|1"\n"1|01|01"\n"10|10|1"\n"10|1|01"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1as = "1001"\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1as = "0000"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u603b\u5171\u6709 3 \u79cd\u5206\u5272 s \u7684\u65b9\u6cd5\u3002\n"0|0|00"\n"0|00|0"\n"00|0|0"\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1as = "100100010100110"\n\u8f93\u51fa\uff1a12\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • s[i] == '0' \u6216\u8005 s[i] == '1'
    • \n\t
    • 3 <= s.length <= 10^5
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numWays(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numWays(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numWays(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numWays(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numWays(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumWays(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar numWays = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef num_ways(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numWays(_ s: String) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numWays(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numWays(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numWays(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_ways(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function numWays($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numWays(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-ways s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1573](https://leetcode-cn.com/problems/number-of-ways-to-split-a-string)", "[\u5206\u5272\u5b57\u7b26\u4e32\u7684\u65b9\u6848\u6570](/solution/1500-1599/1573.Number%20of%20Ways%20to%20Split%20a%20String/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1573](https://leetcode.com/problems/number-of-ways-to-split-a-string)", "[Number of Ways to Split a String](/solution/1500-1599/1573.Number%20of%20Ways%20to%20Split%20a%20String/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "1677", "frontend_question_id": "1572", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/matrix-diagonal-sum", "url_en": "https://leetcode.com/problems/matrix-diagonal-sum", "relative_path_cn": "/solution/1500-1599/1572.Matrix%20Diagonal%20Sum/README.md", "relative_path_en": "/solution/1500-1599/1572.Matrix%20Diagonal%20Sum/README_EN.md", "title_cn": "\u77e9\u9635\u5bf9\u89d2\u7ebf\u5143\u7d20\u7684\u548c", "title_en": "Matrix Diagonal Sum", "question_title_slug": "matrix-diagonal-sum", "content_en": "

    Given a square matrix mat, return the sum of the matrix diagonals.

    \n\n

    Only include the sum of all the elements on the primary diagonal and all the elements on the secondary diagonal that are not part of the primary diagonal.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: mat = [[1,2,3],\n              [4,5,6],\n              [7,8,9]]\nOutput: 25\nExplanation: Diagonals sum: 1 + 5 + 9 + 3 + 7 = 25\nNotice that element mat[1][1] = 5 is counted only once.\n
    \n\n

    Example 2:

    \n\n
    \nInput: mat = [[1,1,1,1],\n              [1,1,1,1],\n              [1,1,1,1],\n              [1,1,1,1]]\nOutput: 8\n
    \n\n

    Example 3:

    \n\n
    \nInput: mat = [[5]]\nOutput: 5\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == mat.length == mat[i].length
    • \n\t
    • 1 <= n <= 100
    • \n\t
    • 1 <= mat[i][j] <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6b63\u65b9\u5f62\u77e9\u9635 mat\uff0c\u8bf7\u4f60\u8fd4\u56de\u77e9\u9635\u5bf9\u89d2\u7ebf\u5143\u7d20\u7684\u548c\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u5728\u77e9\u9635\u4e3b\u5bf9\u89d2\u7ebf\u4e0a\u7684\u5143\u7d20\u548c\u526f\u5bf9\u89d2\u7ebf\u4e0a\u4e14\u4e0d\u5728\u4e3b\u5bf9\u89d2\u7ebf\u4e0a\u5143\u7d20\u7684\u548c\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b  1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1amat = [[1,2,3],\n            [4,5,6],\n            [7,8,9]]\n\u8f93\u51fa\uff1a25\n\u89e3\u91ca\uff1a\u5bf9\u89d2\u7ebf\u7684\u548c\u4e3a\uff1a1 + 5 + 9 + 3 + 7 = 25\n\u8bf7\u6ce8\u610f\uff0c\u5143\u7d20 mat[1][1] = 5 \u53ea\u4f1a\u88ab\u8ba1\u7b97\u4e00\u6b21\u3002\n
    \n\n

    \u793a\u4f8b  2\uff1a

    \n\n
    \n\u8f93\u5165\uff1amat = [[1,1,1,1],\n            [1,1,1,1],\n            [1,1,1,1],\n            [1,1,1,1]]\n\u8f93\u51fa\uff1a8\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1amat = [[5]]\n\u8f93\u51fa\uff1a5\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == mat.length == mat[i].length
    • \n\t
    • 1 <= n <= 100
    • \n\t
    • 1 <= mat[i][j] <= 100
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int diagonalSum(vector>& mat) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int diagonalSum(int[][] mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def diagonalSum(self, mat):\n \"\"\"\n :type mat: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def diagonalSum(self, mat: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint diagonalSum(int** mat, int matSize, int* matColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int DiagonalSum(int[][] mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} mat\n * @return {number}\n */\nvar diagonalSum = function(mat) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} mat\n# @return {Integer}\ndef diagonal_sum(mat)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func diagonalSum(_ mat: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func diagonalSum(mat [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def diagonalSum(mat: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun diagonalSum(mat: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn diagonal_sum(mat: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $mat\n * @return Integer\n */\n function diagonalSum($mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function diagonalSum(mat: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (diagonal-sum mat)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1572](https://leetcode-cn.com/problems/matrix-diagonal-sum)", "[\u77e9\u9635\u5bf9\u89d2\u7ebf\u5143\u7d20\u7684\u548c](/solution/1500-1599/1572.Matrix%20Diagonal%20Sum/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1572](https://leetcode.com/problems/matrix-diagonal-sum)", "[Matrix Diagonal Sum](/solution/1500-1599/1572.Matrix%20Diagonal%20Sum/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1676", "frontend_question_id": "1553", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-number-of-days-to-eat-n-oranges", "url_en": "https://leetcode.com/problems/minimum-number-of-days-to-eat-n-oranges", "relative_path_cn": "/solution/1500-1599/1553.Minimum%20Number%20of%20Days%20to%20Eat%20N%20Oranges/README.md", "relative_path_en": "/solution/1500-1599/1553.Minimum%20Number%20of%20Days%20to%20Eat%20N%20Oranges/README_EN.md", "title_cn": "\u5403\u6389 N \u4e2a\u6a58\u5b50\u7684\u6700\u5c11\u5929\u6570", "title_en": "Minimum Number of Days to Eat N Oranges", "question_title_slug": "minimum-number-of-days-to-eat-n-oranges", "content_en": "

    There are n oranges in the kitchen and you decided to eat some of these oranges every day as follows:

    \r\n\r\n
      \r\n\t
    • Eat one orange.
    • \r\n\t
    • If the number of remaining oranges (n) is divisible by 2 then you can eat  n/2 oranges.
    • \r\n\t
    • If the number of remaining oranges (n) is divisible by 3 then you can eat  2*(n/3) oranges.
    • \r\n
    \r\n\r\n

    You can only choose one of the actions per day.

    \r\n\r\n

    Return the minimum number of days to eat n oranges.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: n = 10\r\nOutput: 4\r\nExplanation: You have 10 oranges.\r\nDay 1: Eat 1 orange,  10 - 1 = 9.  \r\nDay 2: Eat 6 oranges, 9 - 2*(9/3) = 9 - 6 = 3. (Since 9 is divisible by 3)\r\nDay 3: Eat 2 oranges, 3 - 2*(3/3) = 3 - 2 = 1. \r\nDay 4: Eat the last orange  1 - 1  = 0.\r\nYou need at least 4 days to eat the 10 oranges.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: n = 6\r\nOutput: 3\r\nExplanation: You have 6 oranges.\r\nDay 1: Eat 3 oranges, 6 - 6/2 = 6 - 3 = 3. (Since 6 is divisible by 2).\r\nDay 2: Eat 2 oranges, 3 - 2*(3/3) = 3 - 2 = 1. (Since 3 is divisible by 3)\r\nDay 3: Eat the last orange  1 - 1  = 0.\r\nYou need at least 3 days to eat the 6 oranges.\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: n = 1\r\nOutput: 1\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: n = 56\r\nOutput: 6\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= n <= 2*10^9
    • \r\n
    ", "content_cn": "

    \u53a8\u623f\u91cc\u603b\u5171\u6709 n \u4e2a\u6a58\u5b50\uff0c\u4f60\u51b3\u5b9a\u6bcf\u4e00\u5929\u9009\u62e9\u5982\u4e0b\u65b9\u5f0f\u4e4b\u4e00\u5403\u8fd9\u4e9b\u6a58\u5b50\uff1a

    \n\n
      \n\t
    • \u5403\u6389\u4e00\u4e2a\u6a58\u5b50\u3002
    • \n\t
    • \u5982\u679c\u5269\u4f59\u6a58\u5b50\u6570 n \u80fd\u88ab 2 \u6574\u9664\uff0c\u90a3\u4e48\u4f60\u53ef\u4ee5\u5403\u6389 n/2 \u4e2a\u6a58\u5b50\u3002
    • \n\t
    • \u5982\u679c\u5269\u4f59\u6a58\u5b50\u6570 n \u80fd\u88ab 3 \u6574\u9664\uff0c\u90a3\u4e48\u4f60\u53ef\u4ee5\u5403\u6389 2*(n/3) \u4e2a\u6a58\u5b50\u3002
    • \n
    \n\n

    \u6bcf\u5929\u4f60\u53ea\u80fd\u4ece\u4ee5\u4e0a 3 \u79cd\u65b9\u6848\u4e2d\u9009\u62e9\u4e00\u79cd\u65b9\u6848\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u5403\u6389\u6240\u6709 n \u4e2a\u6a58\u5b50\u7684\u6700\u5c11\u5929\u6570\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1an = 10\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u4f60\u603b\u5171\u6709 10 \u4e2a\u6a58\u5b50\u3002\n\u7b2c 1 \u5929\uff1a\u5403 1 \u4e2a\u6a58\u5b50\uff0c\u5269\u4f59\u6a58\u5b50\u6570 10 - 1 = 9\u3002\n\u7b2c 2 \u5929\uff1a\u5403 6 \u4e2a\u6a58\u5b50\uff0c\u5269\u4f59\u6a58\u5b50\u6570 9 - 2*(9/3) = 9 - 6 = 3\u3002\uff089 \u53ef\u4ee5\u88ab 3 \u6574\u9664\uff09\n\u7b2c 3 \u5929\uff1a\u5403 2 \u4e2a\u6a58\u5b50\uff0c\u5269\u4f59\u6a58\u5b50\u6570 3 - 2*(3/3) = 3 - 2 = 1\u3002\n\u7b2c 4 \u5929\uff1a\u5403\u6389\u6700\u540e 1 \u4e2a\u6a58\u5b50\uff0c\u5269\u4f59\u6a58\u5b50\u6570 1 - 1 = 0\u3002\n\u4f60\u9700\u8981\u81f3\u5c11 4 \u5929\u5403\u6389 10 \u4e2a\u6a58\u5b50\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1an = 6\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u4f60\u603b\u5171\u6709 6 \u4e2a\u6a58\u5b50\u3002\n\u7b2c 1 \u5929\uff1a\u5403 3 \u4e2a\u6a58\u5b50\uff0c\u5269\u4f59\u6a58\u5b50\u6570 6 - 6/2 = 6 - 3 = 3\u3002\uff086 \u53ef\u4ee5\u88ab 2 \u6574\u9664\uff09\n\u7b2c 2 \u5929\uff1a\u5403 2 \u4e2a\u6a58\u5b50\uff0c\u5269\u4f59\u6a58\u5b50\u6570 3 - 2*(3/3) = 3 - 2 = 1\u3002\uff083 \u53ef\u4ee5\u88ab 3 \u6574\u9664\uff09\n\u7b2c 3 \u5929\uff1a\u5403\u6389\u5269\u4f59 1 \u4e2a\u6a58\u5b50\uff0c\u5269\u4f59\u6a58\u5b50\u6570 1 - 1 = 0\u3002\n\u4f60\u81f3\u5c11\u9700\u8981 3 \u5929\u5403\u6389 6 \u4e2a\u6a58\u5b50\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1an = 56\n\u8f93\u51fa\uff1a6\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 2*10^9
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minDays(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minDays(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minDays(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minDays(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minDays(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinDays(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar minDays = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef min_days(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minDays(_ n: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minDays(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minDays(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minDays(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_days(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function minDays($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minDays(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-days n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1553](https://leetcode-cn.com/problems/minimum-number-of-days-to-eat-n-oranges)", "[\u5403\u6389 N \u4e2a\u6a58\u5b50\u7684\u6700\u5c11\u5929\u6570](/solution/1500-1599/1553.Minimum%20Number%20of%20Days%20to%20Eat%20N%20Oranges/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1553](https://leetcode.com/problems/minimum-number-of-days-to-eat-n-oranges)", "[Minimum Number of Days to Eat N Oranges](/solution/1500-1599/1553.Minimum%20Number%20of%20Days%20to%20Eat%20N%20Oranges/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1675", "frontend_question_id": "1552", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/magnetic-force-between-two-balls", "url_en": "https://leetcode.com/problems/magnetic-force-between-two-balls", "relative_path_cn": "/solution/1500-1599/1552.Magnetic%20Force%20Between%20Two%20Balls/README.md", "relative_path_en": "/solution/1500-1599/1552.Magnetic%20Force%20Between%20Two%20Balls/README_EN.md", "title_cn": "\u4e24\u7403\u4e4b\u95f4\u7684\u78c1\u529b", "title_en": "Magnetic Force Between Two Balls", "question_title_slug": "magnetic-force-between-two-balls", "content_en": "

    In universe Earth C-137, Rick discovered a special form of magnetic force between two balls if they are put in his new invented basket. Rick has n empty baskets, the ith basket is at position[i], Morty has m balls and needs to distribute the balls into the baskets such that the minimum magnetic force between any two balls is maximum.

    \n\n

    Rick stated that magnetic force between two different balls at positions x and y is |x - y|.

    \n\n

    Given the integer array position and the integer m. Return the required force.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: position = [1,2,3,4,7], m = 3\nOutput: 3\nExplanation: Distributing the 3 balls into baskets 1, 4 and 7 will make the magnetic force between ball pairs [3, 3, 6]. The minimum magnetic force is 3. We cannot achieve a larger minimum magnetic force than 3.\n
    \n\n

    Example 2:

    \n\n
    \nInput: position = [5,4,3,2,1,1000000000], m = 2\nOutput: 999999999\nExplanation: We can use baskets 1 and 1000000000.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == position.length
    • \n\t
    • 2 <= n <= 10^5
    • \n\t
    • 1 <= position[i] <= 10^9
    • \n\t
    • All integers in position are distinct.
    • \n\t
    • 2 <= m <= position.length
    • \n
    \n", "content_cn": "

    \u5728\u4ee3\u53f7\u4e3a C-137 \u7684\u5730\u7403\u4e0a\uff0cRick \u53d1\u73b0\u5982\u679c\u4ed6\u5c06\u4e24\u4e2a\u7403\u653e\u5728\u4ed6\u65b0\u53d1\u660e\u7684\u7bee\u5b50\u91cc\uff0c\u5b83\u4eec\u4e4b\u95f4\u4f1a\u5f62\u6210\u7279\u6b8a\u5f62\u5f0f\u7684\u78c1\u529b\u3002Rick \u6709 n \u4e2a\u7a7a\u7684\u7bee\u5b50\uff0c\u7b2c i \u4e2a\u7bee\u5b50\u7684\u4f4d\u7f6e\u5728 position[i] \uff0cMorty \u60f3\u628a m \u4e2a\u7403\u653e\u5230\u8fd9\u4e9b\u7bee\u5b50\u91cc\uff0c\u4f7f\u5f97\u4efb\u610f\u4e24\u7403\u95f4 \u6700\u5c0f\u78c1\u529b \u6700\u5927\u3002

    \n\n

    \u5df2\u77e5\u4e24\u4e2a\u7403\u5982\u679c\u5206\u522b\u4f4d\u4e8e x \u548c y \uff0c\u90a3\u4e48\u5b83\u4eec\u4e4b\u95f4\u7684\u78c1\u529b\u4e3a |x - y| \u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 position \u548c\u4e00\u4e2a\u6574\u6570 m \uff0c\u8bf7\u4f60\u8fd4\u56de\u6700\u5927\u5316\u7684\u6700\u5c0f\u78c1\u529b\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1aposition = [1,2,3,4,7], m = 3\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u5c06 3 \u4e2a\u7403\u5206\u522b\u653e\u5165\u4f4d\u4e8e 1\uff0c4 \u548c 7 \u7684\u4e09\u4e2a\u7bee\u5b50\uff0c\u4e24\u7403\u95f4\u7684\u78c1\u529b\u5206\u522b\u4e3a [3, 3, 6]\u3002\u6700\u5c0f\u78c1\u529b\u4e3a 3 \u3002\u6211\u4eec\u6ca1\u529e\u6cd5\u8ba9\u6700\u5c0f\u78c1\u529b\u5927\u4e8e 3 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aposition = [5,4,3,2,1,1000000000], m = 2\n\u8f93\u51fa\uff1a999999999\n\u89e3\u91ca\uff1a\u6211\u4eec\u4f7f\u7528\u4f4d\u4e8e 1 \u548c 1000000000 \u7684\u7bee\u5b50\u65f6\u6700\u5c0f\u78c1\u529b\u6700\u5927\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == position.length
    • \n\t
    • 2 <= n <= 10^5
    • \n\t
    • 1 <= position[i] <= 10^9
    • \n\t
    • \u6240\u6709 position \u4e2d\u7684\u6574\u6570 \u4e92\u4e0d\u76f8\u540c \u3002
    • \n\t
    • 2 <= m <= position.length
    • \n
    \n", "tags_en": ["Array", "Binary Search"], "tags_cn": ["\u6570\u7ec4", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxDistance(vector& position, int m) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxDistance(int[] position, int m) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxDistance(self, position, m):\n \"\"\"\n :type position: List[int]\n :type m: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxDistance(self, position: List[int], m: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxDistance(int* position, int positionSize, int m){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxDistance(int[] position, int m) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} position\n * @param {number} m\n * @return {number}\n */\nvar maxDistance = function(position, m) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} position\n# @param {Integer} m\n# @return {Integer}\ndef max_distance(position, m)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxDistance(_ position: [Int], _ m: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxDistance(position []int, m int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxDistance(position: Array[Int], m: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxDistance(position: IntArray, m: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_distance(position: Vec, m: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $position\n * @param Integer $m\n * @return Integer\n */\n function maxDistance($position, $m) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxDistance(position: number[], m: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-distance position m)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1552](https://leetcode-cn.com/problems/magnetic-force-between-two-balls)", "[\u4e24\u7403\u4e4b\u95f4\u7684\u78c1\u529b](/solution/1500-1599/1552.Magnetic%20Force%20Between%20Two%20Balls/README.md)", "`\u6570\u7ec4`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1552](https://leetcode.com/problems/magnetic-force-between-two-balls)", "[Magnetic Force Between Two Balls](/solution/1500-1599/1552.Magnetic%20Force%20Between%20Two%20Balls/README_EN.md)", "`Array`,`Binary Search`", "Medium", ""]}, {"question_id": "1674", "frontend_question_id": "1551", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-operations-to-make-array-equal", "url_en": "https://leetcode.com/problems/minimum-operations-to-make-array-equal", "relative_path_cn": "/solution/1500-1599/1551.Minimum%20Operations%20to%20Make%20Array%20Equal/README.md", "relative_path_en": "/solution/1500-1599/1551.Minimum%20Operations%20to%20Make%20Array%20Equal/README_EN.md", "title_cn": "\u4f7f\u6570\u7ec4\u4e2d\u6240\u6709\u5143\u7d20\u76f8\u7b49\u7684\u6700\u5c0f\u64cd\u4f5c\u6570", "title_en": "Minimum Operations to Make Array Equal", "question_title_slug": "minimum-operations-to-make-array-equal", "content_en": "

    You have an array arr of length n where arr[i] = (2 * i) + 1 for all valid values of i (i.e. 0 <= i < n).

    \r\n\r\n

    In one operation, you can select two indices x and y where 0 <= x, y < n and subtract 1 from arr[x] and add 1 to arr[y] (i.e. perform arr[x] -=1 and arr[y] += 1). The goal is to make all the elements of the array equal. It is guaranteed that all the elements of the array can be made equal using some operations.

    \r\n\r\n

    Given an integer n, the length of the array. Return the minimum number of operations needed to make all the elements of arr equal.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: n = 3\r\nOutput: 2\r\nExplanation: arr = [1, 3, 5]\r\nFirst operation choose x = 2 and y = 0, this leads arr to be [2, 3, 4]\r\nIn the second operation choose x = 2 and y = 0 again, thus arr = [3, 3, 3].\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: n = 6\r\nOutput: 9\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= n <= 10^4
    • \r\n
    ", "content_cn": "

    \u5b58\u5728\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u6570\u7ec4 arr \uff0c\u5176\u4e2d arr[i] = (2 * i) + 1 \uff08 0 <= i < n \uff09\u3002

    \n\n

    \u4e00\u6b21\u64cd\u4f5c\u4e2d\uff0c\u4f60\u53ef\u4ee5\u9009\u51fa\u4e24\u4e2a\u4e0b\u6807\uff0c\u8bb0\u4f5c x \u548c y \uff08 0 <= x, y < n \uff09\u5e76\u4f7f arr[x] \u51cf\u53bb 1 \u3001arr[y] \u52a0\u4e0a 1 \uff08\u5373 arr[x] -=1 \u4e14 arr[y] += 1 \uff09\u3002\u6700\u7ec8\u7684\u76ee\u6807\u662f\u4f7f\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u90fd \u76f8\u7b49 \u3002\u9898\u76ee\u6d4b\u8bd5\u7528\u4f8b\u5c06\u4f1a \u4fdd\u8bc1 \uff1a\u5728\u6267\u884c\u82e5\u5e72\u6b65\u64cd\u4f5c\u540e\uff0c\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u6700\u7ec8\u53ef\u4ee5\u5168\u90e8\u76f8\u7b49\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n\uff0c\u5373\u6570\u7ec4\u7684\u957f\u5ea6\u3002\u8bf7\u4f60\u8fd4\u56de\u4f7f\u6570\u7ec4 arr \u4e2d\u6240\u6709\u5143\u7d20\u76f8\u7b49\u6240\u9700\u7684 \u6700\u5c0f\u64cd\u4f5c\u6570 \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1an = 3\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1aarr = [1, 3, 5]\n\u7b2c\u4e00\u6b21\u64cd\u4f5c\u9009\u51fa x = 2 \u548c y = 0\uff0c\u4f7f\u6570\u7ec4\u53d8\u4e3a [2, 3, 4]\n\u7b2c\u4e8c\u6b21\u64cd\u4f5c\u7ee7\u7eed\u9009\u51fa x = 2 \u548c y = 0\uff0c\u6570\u7ec4\u5c06\u4f1a\u53d8\u6210 [3, 3, 3]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1an = 6\n\u8f93\u51fa\uff1a9\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 10^4
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minOperations(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minOperations(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minOperations(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minOperations(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minOperations(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinOperations(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar minOperations = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef min_operations(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minOperations(_ n: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minOperations(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minOperations(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minOperations(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_operations(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function minOperations($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minOperations(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-operations n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1551](https://leetcode-cn.com/problems/minimum-operations-to-make-array-equal)", "[\u4f7f\u6570\u7ec4\u4e2d\u6240\u6709\u5143\u7d20\u76f8\u7b49\u7684\u6700\u5c0f\u64cd\u4f5c\u6570](/solution/1500-1599/1551.Minimum%20Operations%20to%20Make%20Array%20Equal/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1551](https://leetcode.com/problems/minimum-operations-to-make-array-equal)", "[Minimum Operations to Make Array Equal](/solution/1500-1599/1551.Minimum%20Operations%20to%20Make%20Array%20Equal/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "1672", "frontend_question_id": "1533", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/find-the-index-of-the-large-integer", "url_en": "https://leetcode.com/problems/find-the-index-of-the-large-integer", "relative_path_cn": "/solution/1500-1599/1533.Find%20the%20Index%20of%20the%20Large%20Integer/README.md", "relative_path_en": "/solution/1500-1599/1533.Find%20the%20Index%20of%20the%20Large%20Integer/README_EN.md", "title_cn": "\u627e\u5230\u6700\u5927\u6574\u6570\u7684\u7d22\u5f15", "title_en": "Find the Index of the Large Integer", "question_title_slug": "find-the-index-of-the-large-integer", "content_en": "

    We have an integer array arr, where all the integers in arr are equal except for one integer which is larger than the rest of the integers. You will not be given direct access to the array, instead, you will have an API ArrayReader which have the following functions:

    \n\n
      \n\t
    • int compareSub(int l, int r, int x, int y): where 0 <= l, r, x, y < ArrayReader.length(), l <= r and x <= y. The function compares the sum of sub-array arr[l..r] with the sum of the sub-array arr[x..y] and returns:\n\n\t
        \n\t\t
      • 1 if arr[l]+arr[l+1]+...+arr[r] > arr[x]+arr[x+1]+...+arr[y].
      • \n\t\t
      • 0 if arr[l]+arr[l+1]+...+arr[r] == arr[x]+arr[x+1]+...+arr[y].
      • \n\t\t
      • -1 if arr[l]+arr[l+1]+...+arr[r] < arr[x]+arr[x+1]+...+arr[y].
      • \n\t
      \n\t
    • \n\t
    • int length(): Returns the size of the array.
    • \n
    \n\n

    You are allowed to call compareSub() 20 times at most. You can assume both functions work in O(1) time.

    \n\n

    Return the index of the array arr which has the largest integer.

    \n\n

    Follow-up:

    \n\n
      \n\t
    • What if there are two numbers in arr that are bigger than all other numbers?
    • \n\t
    • What if there is one number that is bigger than other numbers and one number that is smaller than other numbers?
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr = [7,7,7,7,10,7,7,7]\nOutput: 4\nExplanation: The following calls to the API\nreader.compareSub(0, 0, 1, 1) // returns 0 this is a query comparing the sub-array (0, 0) with the sub array (1, 1), (i.e. compares arr[0] with arr[1]).\nThus we know that arr[0] and arr[1] doesn't contain the largest element.\nreader.compareSub(2, 2, 3, 3) // returns 0, we can exclude arr[2] and arr[3].\nreader.compareSub(4, 4, 5, 5) // returns 1, thus for sure arr[4] is the largest element in the array.\nNotice that we made only 3 calls, so the answer is valid.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [6,6,12]\nOutput: 2\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= arr.length <= 5 * 10^5
    • \n\t
    • 1 <= arr[i] <= 100
    • \n\t
    • All elements of arr are equal except for one element which is larger than all other elements.
    • \n
    \n", "content_cn": "

    \u6211\u4eec\u6709\u8fd9\u6837\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr \uff0c\u9664\u4e86\u4e00\u4e2a\u6700\u5927\u7684\u6574\u6570\u5916\uff0c\u5176\u4ed6\u6240\u6709\u6574\u6570\u90fd\u76f8\u7b49\u3002\u4f60\u4e0d\u80fd\u76f4\u63a5\u8bbf\u95ee\u8be5\u6570\u7ec4\uff0c\u4f60\u9700\u8981\u901a\u8fc7 API ArrayReader \u6765\u95f4\u63a5\u8bbf\u95ee\uff0c\u8fd9\u4e2a API \u6709\u4ee5\u4e0b\u6210\u5458\u51fd\u6570\uff1a

    \n\n
      \n\t
    • int compareSub(int l, int r, int x, int y)\uff1a\u5176\u4e2d 0 <= l, r, x, y < ArrayReader.length()\uff0c l <= r \u4e14 x <= y\u3002\u8fd9\u4e2a\u51fd\u6570\u6bd4\u8f83\u5b50\u6570\u7ec4 arr[l..r] \u4e0e\u5b50\u6570\u7ec4 arr[x..y] \u7684\u548c\u3002\u8be5\u51fd\u6570\u8fd4\u56de\uff1a\n\n\t
        \n\t\t
      • 1 \u82e5 arr[l]+arr[l+1]+...+arr[r] > arr[x]+arr[x+1]+...+arr[y] \u3002
      • \n\t\t
      • 0 \u82e5 arr[l]+arr[l+1]+...+arr[r] == arr[x]+arr[x+1]+...+arr[y] \u3002
      • \n\t\t
      • -1 \u82e5 arr[l]+arr[l+1]+...+arr[r] < arr[x]+arr[x+1]+...+arr[y] \u3002
      • \n\t
      \n\t
    • \n\t
    • int length()\uff1a\u8fd4\u56de\u6570\u7ec4\u7684\u957f\u5ea6\u3002
    • \n
    \n\n

    \u4f60\u6700\u591a\u53ef\u4ee5\u8c03\u7528\u51fd\u6570 compareSub() 20 \u6b21\u3002\u4f60\u53ef\u4ee5\u8ba4\u4e3a\u8fd9\u4e24\u4e2a\u51fd\u6570\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u90fd\u4e3a O(1) \u3002

    \n\n

    \u8fd4\u56de arr \u4e2d\u6700\u5927\u6574\u6570\u7684\u7d22\u5f15\u3002

    \n\n

    \u8fdb\u9636

    \n\n
      \n\t
    • \u5982\u679c arr \u4e2d\u6709\u4e24\u4e2a\u6574\u6570\u6bd4\u5176\u4ed6\u6570\u5927\u5462\uff1f
    • \n\t
    • \u5982\u679c\u6709\u4e00\u4e2a\u6570\u6bd4\u5176\u4ed6\u6570\u5927\uff0c\u53e6\u4e00\u4e2a\u6570\u6bd4\u5176\u4ed6\u6570\u5c0f\u5462\uff1f
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165: arr = [7,7,7,7,10,7,7,7]\n\u8f93\u51fa: 4\n\u89e3\u91ca: API \u7684\u8c03\u7528\u5982\u4e0b\uff1a\nreader.compareSub(0, 0, 1, 1) // \u8fd4\u56de 0\u3002\u6bd4\u8f83\u5b50\u6570\u7ec4 (0, 0) \u4e0e\u5b50\u6570\u7ec4 (1, 1) \uff08\u5373\u6bd4\u8f83 arr[0] \u548c arr[1]\uff09\u3002\n\u56e0\u6b64\u6211\u4eec\u77e5\u9053 arr[0] \u548c arr[1] \u4e0d\u5305\u542b\u6700\u5927\u5143\u7d20\u3002\nreader.compareSub(2, 2, 3, 3) // \u8fd4\u56de 0\u3002\u6211\u4eec\u53ef\u4ee5\u6392\u9664 arr[2] \u548c arr[3]\u3002\nreader.compareSub(4, 4, 5, 5) // \u8fd4\u56de 1\u3002\u56e0\u6b64\uff0c\u53ef\u4ee5\u786e\u5b9a arr[4] \u662f\u6570\u7ec4\u4e2d\u6700\u5927\u7684\u5143\u7d20\u3002\n\u6ce8\u610f\uff0c\u6211\u4eec\u53ea\u8c03\u7528\u4e86 3 \u6b21 compareSub\uff0c\u6240\u4ee5\u8fd9\u4e2a\u7b54\u6848\u662f\u6709\u6548\u7684\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: nums = [6,6,12]\n\u8f93\u51fa: 2\n
    \n\n

     

    \n\n

    \u63d0\u793a:

    \n\n
      \n\t
    • 2 <= arr.length <= 5 * 10^5
    • \n\t
    • 1 <= arr[i] <= 100
    • \n\t
    • arr \u4e2d\u9664\u4e00\u4e2a\u6700\u5927\u5143\u7d20\u5916\uff0c\u5176\u4f59\u6240\u6709\u5143\u7d20\u90fd\u76f8\u7b49\u3002
    • \n
    \n", "tags_en": ["Binary Search"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * // This is the ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * class ArrayReader {\n * public:\n * // Compares the sum of arr[l..r] with the sum of arr[x..y] \n * // return 1 if sum(arr[l..r]) > sum(arr[x..y])\n * // return 0 if sum(arr[l..r]) == sum(arr[x..y])\n * // return -1 if sum(arr[l..r]) < sum(arr[x..y])\n * int compareSub(int l, int r, int x, int y);\n *\n * // Returns the length of the array\n * int length();\n * };\n */\n\nclass Solution {\npublic:\n int getIndex(ArrayReader &reader) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * // This is ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * interface ArrayReader {\n * // Compares the sum of arr[l..r] with the sum of arr[x..y] \n * // return 1 if sum(arr[l..r]) > sum(arr[x..y])\n * // return 0 if sum(arr[l..r]) == sum(arr[x..y])\n * // return -1 if sum(arr[l..r]) < sum(arr[x..y])\n * public int compareSub(int l, int r, int x, int y) {}\n *\n * // Returns the length of the array\n * public int length() {}\n * }\n */\n\nclass Solution {\n public int getIndex(ArrayReader reader) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# \"\"\"\n# This is ArrayReader's API interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class ArrayReader(object):\n#\t # Compares the sum of arr[l..r] with the sum of arr[x..y]\n#\t # return 1 if sum(arr[l..r]) > sum(arr[x..y])\n#\t # return 0 if sum(arr[l..r]) == sum(arr[x..y])\n#\t # return -1 if sum(arr[l..r]) < sum(arr[x..y])\n# def compareSub(self, l, r, x, y):\n# \"\"\"\n# :type l, r, x, y: int\n# :rtype int\n# \"\"\"\n#\n#\t # Returns the length of the array\n# def length(self):\n# \"\"\"\n# :rtype int\n# \"\"\"\n\nclass Solution(object):\n def getIndex(self, reader):\n \"\"\"\n :type reader: ArrayReader\n :rtype: integer\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# \"\"\"\n# This is ArrayReader's API interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class ArrayReader(object):\n#\t # Compares the sum of arr[l..r] with the sum of arr[x..y]\n#\t # return 1 if sum(arr[l..r]) > sum(arr[x..y])\n#\t # return 0 if sum(arr[l..r]) == sum(arr[x..y])\n#\t # return -1 if sum(arr[l..r]) < sum(arr[x..y])\n# def compareSub(self, l: int, r: int, x: int, y: int) -> int:\n#\n#\t # Returns the length of the array\n# def length(self) -> int:\n#\n\n\nclass Solution:\n def getIndex(self, reader: 'ArrayReader') -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * *********************************************************************\n * // This is the ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * *********************************************************************\n *\n * // Compares the sum of arr[l..r] with the sum of arr[x..y] \n * // return 1 if sum(arr[l..r]) > sum(arr[x..y])\n * // return 0 if sum(arr[l..r]) == sum(arr[x..y])\n * // return -1 if sum(arr[l..r]) < sum(arr[x..y])\n * int compareSub(ArrayReader *, int l, int r, int x, int y);\n *\n * // Returns the length of the array\n * int length(ArrayReader *);\n */\n\nint getIndex(ArrayReader* reader) {\n\t\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * // This is ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * class ArrayReader {\n * // Compares the sum of arr[l..r] with the sum of arr[x..y] \n * // return 1 if sum(arr[l..r]) > sum(arr[x..y])\n * // return 0 if sum(arr[l..r]) == sum(arr[x..y])\n * // return -1 if sum(arr[l..r]) < sum(arr[x..y])\n * public int CompareSub(int l, int r, int x, int y) {}\n *\n * // Returns the length of the array\n * public int Length() {}\n * }\n */\n\nclass Solution {\n public int GetIndex(ArrayReader reader) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // This is the ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * function ArrayReader() {\n * // Compares the sum of arr[l..r] with the sum of arr[x..y] \n * // return 1 if sum(arr[l..r]) > sum(arr[x..y])\n * // return 0 if sum(arr[l..r]) == sum(arr[x..y])\n * // return -1 if sum(arr[l..r]) < sum(arr[x..y])\n * @param {number} l, r, x, y\n * @return {number}\n * this.compareSub = function(l, r, x, y) {\n * ...\n * };\n *\n * // Returns the length of the array\n * @return {number}\n * this.length = function() {\n * ...\n * };\n * };\n */\n\n/**\n * @param {ArrayReader} reader\n * @return {number}\n */\nvar getIndex = function(reader) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# This is ArrayReader's API interface.\n# You should not implement it, or speculate about its implementation\n# class ArrayReader\n#\t # Compares the sum of arr[l..r] with the sum of arr[x..y]\n#\t # return 1 if sum(arr[l..r]) > sum(arr[x..y])\n#\t # return 0 if sum(arr[l..r]) == sum(arr[x..y])\n#\t # return -1 if sum(arr[l..r]) < sum(arr[x..y])\n# def compare_sub(l, r, x, y):\n# \n# end\n#\n#\t # Returns the length of the array\n# def length()\n#\t\t\n#\t end\n# end\n\n# @param {ArrayReader} reader\n# @return {int}\ndef get_index(reader)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * // This is ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * interface ArrayReader {\n * // Compares the sum of arr[l..r] with the sum of arr[x..y] \n * // return 1 if sum(arr[l..r]) > sum(arr[x..y])\n * // return 0 if sum(arr[l..r]) == sum(arr[x..y])\n * // return -1 if sum(arr[l..r]) < sum(arr[x..y])\n * public func compareSub(_ l: Int, _ r: Int, _ x: Int, _ y: Int) -> Int {}\n *\n * // Returns the length of the array\n * public func length() -> Int {}\n * }\n */\n\nclass Solution {\n func getIndex(_ reader: ArrayReader) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * // This is the ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * type ArrayReader struct {\n * }\n * // Compares the sum of arr[l..r] with the sum of arr[x..y] \n * // return 1 if sum(arr[l..r]) > sum(arr[x..y])\n * // return 0 if sum(arr[l..r]) == sum(arr[x..y])\n * // return -1 if sum(arr[l..r]) < sum(arr[x..y])\n * func (this *ArrayReader) compareSub(l, r, x, y int) int {}\n * \n * // Returns the length of the array\n * func (this *ArrayReader) length() int {}\n */\n\nfunc getIndex(reader *ArrayReader) int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * // This is ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * interface ArrayReader {\n * // Compares the sum of arr[l..r] with the sum of arr[x..y] \n * // return 1 if sum(arr[l..r]) > sum(arr[x..y])\n * // return 0 if sum(arr[l..r]) == sum(arr[x..y])\n * // return -1 if sum(arr[l..r]) < sum(arr[x..y])\n * def compareSub(l: Int, r: Int, x: Int, y: Int): Int {}\n *\n * // Returns the length of the array\n * def length(): Int {}\n * }\n */\n\nobject Solution {\n def getIndex(reader: ArrayReader): Int = {\n \n\t}\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * // This is ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * interface ArrayReader {\n * // Compares the sum of arr[l..r] with the sum of arr[x..y] \n * // return 1 if sum(arr[l..r]) > sum(arr[x..y])\n * // return 0 if sum(arr[l..r]) == sum(arr[x..y])\n * // return -1 if sum(arr[l..r]) < sum(arr[x..y])\n * fun compareSub(l: Int, r: Int, x: Int, y: Int): Int {}\n *\n * // Returns the length of the array\n * fun length(): Int {}\n * }\n */\n\nclass Solution {\n fun getIndex(reader: ArrayReader): Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "/**\n * // This is the ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * struct ArrayReader;\n * impl Array Reader {\n * pub fn compareSub(l: i32, r: i32, x: i32, y: i32) -> i32 {}\n * // Compares the sum of arr[l..r] with the sum of arr[x..y] \n * // return 1 if sum(arr[l..r]) > sum(arr[x..y])\n * // return 0 if sum(arr[l..r]) == sum(arr[x..y])\n * // return -1 if sum(arr[l..r]) < sum(arr[x..y])\n * // Returns the length of the array\n * }\n */\n\nimpl Solution {\n pub fn get_index(reader: &ArrayReader) -> i32 {\n\t\t\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * // This is ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * interface ArrayReader {\n * // Compares the sum of arr[l..r] with the sum of arr[x..y] \n * // return 1 if sum(arr[l..r]) > sum(arr[x..y])\n * // return 0 if sum(arr[l..r]) == sum(arr[x..y])\n * // return -1 if sum(arr[l..r]) < sum(arr[x..y])\n * function compareSub($l, $r, $x, $y) {}\n *\n * // Returns the length of the array\n * function length() {}\n * }\n */\n\nclass Solution {\n /**\n * @param ArrayReader $reader\n * @return Integer\n */\n function getIndex($reader) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * // This is the ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * class ArrayReader {\n * // Compares the sum of arr[l..r] with the sum of arr[x..y] \n * // return 1 if sum(arr[l..r]) > sum(arr[x..y])\n * // return 0 if sum(arr[l..r]) == sum(arr[x..y])\n * // return -1 if sum(arr[l..r]) < sum(arr[x..y])\n * compareSub(l: number, r: number, x: number, y: number): number { };\n *\n * // Returns the length of the array\n * length(): number { };\n * };\n */\n\nfunction getIndex(reader: ArrayReader): number {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1533](https://leetcode-cn.com/problems/find-the-index-of-the-large-integer)", "[\u627e\u5230\u6700\u5927\u6574\u6570\u7684\u7d22\u5f15](/solution/1500-1599/1533.Find%20the%20Index%20of%20the%20Large%20Integer/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1533](https://leetcode.com/problems/find-the-index-of-the-large-integer)", "[Find the Index of the Large Integer](/solution/1500-1599/1533.Find%20the%20Index%20of%20the%20Large%20Integer/README_EN.md)", "`Binary Search`", "Medium", "\ud83d\udd12"]}, {"question_id": "1671", "frontend_question_id": "1532", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/the-most-recent-three-orders", "url_en": "https://leetcode.com/problems/the-most-recent-three-orders", "relative_path_cn": "/solution/1500-1599/1532.The%20Most%20Recent%20Three%20Orders/README.md", "relative_path_en": "/solution/1500-1599/1532.The%20Most%20Recent%20Three%20Orders/README_EN.md", "title_cn": "\u6700\u8fd1\u7684\u4e09\u7b14\u8ba2\u5355", "title_en": "The Most Recent Three Orders", "question_title_slug": "the-most-recent-three-orders", "content_en": "

    Table: Customers

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| customer_id   | int     |\n| name          | varchar |\n+---------------+---------+\ncustomer_id is the primary key for this table.\nThis table contains information about customers.\n
    \n\n

     

    \n\n

    Table: Orders

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| order_id      | int     |\n| order_date    | date    |\n| customer_id   | int     |\n| cost          | int     |\n+---------------+---------+\norder_id is the primary key for this table.\nThis table contains information about the orders made by customer_id.\nEach customer has one order per day.\n
    \n\n

     

    \n\n

    Write an SQL query to find the most recent 3 orders of each user. If a user ordered less than 3 orders return all of their orders.

    \n\n

    Return the result table sorted by customer_name in ascending order and in case of a tie by the customer_id in ascending order. If there still a tie, order them by the order_date in descending order.

    \n\n

    The query result format is in the following example:

    \n\n
    \nCustomers\n+-------------+-----------+\n| customer_id | name      |\n+-------------+-----------+\n| 1           | Winston   |\n| 2           | Jonathan  |\n| 3           | Annabelle |\n| 4           | Marwan    |\n| 5           | Khaled    |\n+-------------+-----------+\n\nOrders\n+----------+------------+-------------+------+\n| order_id | order_date | customer_id | cost |\n+----------+------------+-------------+------+\n| 1        | 2020-07-31 | 1           | 30   |\n| 2        | 2020-07-30 | 2           | 40   |\n| 3        | 2020-07-31 | 3           | 70   |\n| 4        | 2020-07-29 | 4           | 100  |\n| 5        | 2020-06-10 | 1           | 1010 |\n| 6        | 2020-08-01 | 2           | 102  |\n| 7        | 2020-08-01 | 3           | 111  |\n| 8        | 2020-08-03 | 1           | 99   |\n| 9        | 2020-08-07 | 2           | 32   |\n| 10       | 2020-07-15 | 1           | 2    |\n+----------+------------+-------------+------+\n\nResult table:\n+---------------+-------------+----------+------------+\n| customer_name | customer_id | order_id | order_date |\n+---------------+-------------+----------+------------+\n| Annabelle     | 3           | 7        | 2020-08-01 |\n| Annabelle     | 3           | 3        | 2020-07-31 |\n| Jonathan      | 2           | 9        | 2020-08-07 |\n| Jonathan      | 2           | 6        | 2020-08-01 |\n| Jonathan      | 2           | 2        | 2020-07-30 |\n| Marwan        | 4           | 4        | 2020-07-29 |\n| Winston       | 1           | 8        | 2020-08-03 |\n| Winston       | 1           | 1        | 2020-07-31 |\n| Winston       | 1           | 10       | 2020-07-15 |\n+---------------+-------------+----------+------------+\nWinston has 4 orders, we discard the order of "2020-06-10" because it is the oldest order.\nAnnabelle has only 2 orders, we return them.\nJonathan has exactly 3 orders.\nMarwan ordered only one time.\nWe sort the result table by customer_name in ascending order, by customer_id in ascending order and by order_date in descending order in case of a tie.\n
    \n\n

    Follow-up:
    \nCan you write a general solution for the most recent n orders?

    \n", "content_cn": "

    \u8868\uff1aCustomers

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| customer_id   | int     |\n| name          | varchar |\n+---------------+---------+\ncustomer_id \u662f\u8be5\u8868\u4e3b\u952e\n\u8be5\u8868\u5305\u542b\u6d88\u8d39\u8005\u7684\u4fe1\u606f\n
    \n\n

    \u00a0

    \n\n

    \u8868\uff1aOrders

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| order_id      | int     |\n| order_date    | date    |\n| customer_id   | int     |\n| cost          | int     |\n+---------------+---------+\norder_id \u662f\u8be5\u8868\u4e3b\u952e\n\u8be5\u8868\u5305\u542bid\u4e3acustomer_id\u7684\u6d88\u8d39\u8005\u7684\u8ba2\u5355\u4fe1\u606f\n\u6bcf\u4e00\u4e2a\u6d88\u8d39\u8005 \u6bcf\u5929\u4e00\u7b14\u8ba2\u5355\n
    \n\n

    \u00a0

    \n\n

    \u5199\u4e00\u4e2a SQL \u8bed\u53e5\uff0c\u627e\u5230\u6bcf\u4e2a\u7528\u6237\u7684\u6700\u8fd1\u4e09\u7b14\u8ba2\u5355\u3002\u5982\u679c\u7528\u6237\u7684\u8ba2\u5355\u5c11\u4e8e 3 \u7b14\uff0c\u5219\u8fd4\u56de\u4ed6\u7684\u5168\u90e8\u8ba2\u5355\u3002

    \n\n

    \u8fd4\u56de\u7684\u7ed3\u679c\u6309\u7167 customer_name\u00a0\u5347\u5e8f\u6392\u5217\u3002\u5982\u679c\u6392\u540d\u6709\u76f8\u540c\uff0c\u5219\u7ee7\u7eed\u6309\u7167 customer_id \u5347\u5e8f\u6392\u5217\u3002\u5982\u679c\u6392\u540d\u8fd8\u6709\u76f8\u540c\uff0c\u5219\u7ee7\u7eed\u6309\u7167 order_date \u964d\u5e8f\u6392\u5217\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a\uff1a

    \n\n
    \nCustomers\n+-------------+-----------+\n| customer_id | name      |\n+-------------+-----------+\n| 1           | Winston   |\n| 2           | Jonathan  |\n| 3           | Annabelle |\n| 4           | Marwan    |\n| 5           | Khaled    |\n+-------------+-----------+\n\nOrders\n+----------+------------+-------------+------+\n| order_id | order_date | customer_id | cost |\n+----------+------------+-------------+------+\n| 1        | 2020-07-31 | 1           | 30   |\n| 2        | 2020-07-30 | 2           | 40   |\n| 3        | 2020-07-31 | 3           | 70   |\n| 4        | 2020-07-29 | 4           | 100  |\n| 5        | 2020-06-10 | 1           | 1010 |\n| 6        | 2020-08-01 | 2           | 102  |\n| 7        | 2020-08-01 | 3           | 111  |\n| 8        | 2020-08-03 | 1           | 99   |\n| 9        | 2020-08-07 | 2           | 32   |\n| 10       | 2020-07-15 | 1           | 2    |\n+----------+------------+-------------+------+\n\nResult table\uff1a\n+---------------+-------------+----------+------------+\n| customer_name | customer_id | order_id | order_date |\n+---------------+-------------+----------+------------+\n| Annabelle     | 3           | 7        | 2020-08-01 |\n| Annabelle     | 3           | 3        | 2020-07-31 |\n| Jonathan      | 2           | 9        | 2020-08-07 |\n| Jonathan      | 2           | 6        | 2020-08-01 |\n| Jonathan      | 2           | 2        | 2020-07-30 |\n| Marwan        | 4           | 4        | 2020-07-29 |\n| Winston       | 1           | 8        | 2020-08-03 |\n| Winston       | 1           | 1        | 2020-07-31 |\n| Winston       | 1           | 10       | 2020-07-15 |\n+---------------+-------------+----------+------------+\nWinston \u6709 4 \u7b14\u8ba2\u5355, \u6392\u9664\u4e86 \"2020-06-10\" \u7684\u8ba2\u5355, \u56e0\u4e3a\u5b83\u662f\u6700\u8001\u7684\u8ba2\u5355\u3002\nAnnabelle \u53ea\u6709 2 \u7b14\u8ba2\u5355, \u5168\u90e8\u8fd4\u56de\u3002\nJonathan \u6070\u597d\u6709 3 \u7b14\u8ba2\u5355\u3002\nMarwan \u53ea\u6709 1 \u7b14\u8ba2\u5355\u3002\n\u7ed3\u679c\u8868\u6211\u4eec\u6309\u7167 customer_name \u5347\u5e8f\u6392\u5217\uff0ccustomer_id \u5347\u5e8f\u6392\u5217\uff0corder_date \u964d\u5e8f\u6392\u5217\u3002\n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u4f60\u80fd\u5199\u51fa\u6765\u6700\u8fd1\u00a0n\u00a0\u7b14\u8ba2\u5355\u7684\u901a\u7528\u89e3\u51b3\u65b9\u6848\u5417?
    • \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1532](https://leetcode-cn.com/problems/the-most-recent-three-orders)", "[\u6700\u8fd1\u7684\u4e09\u7b14\u8ba2\u5355](/solution/1500-1599/1532.The%20Most%20Recent%20Three%20Orders/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1532](https://leetcode.com/problems/the-most-recent-three-orders)", "[The Most Recent Three Orders](/solution/1500-1599/1532.The%20Most%20Recent%20Three%20Orders/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1670", "frontend_question_id": "1527", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/patients-with-a-condition", "url_en": "https://leetcode.com/problems/patients-with-a-condition", "relative_path_cn": "/solution/1500-1599/1527.Patients%20With%20a%20Condition/README.md", "relative_path_en": "/solution/1500-1599/1527.Patients%20With%20a%20Condition/README_EN.md", "title_cn": "\u60a3\u67d0\u79cd\u75be\u75c5\u7684\u60a3\u8005", "title_en": "Patients With a Condition", "question_title_slug": "patients-with-a-condition", "content_en": "

    Table: Patients

    \n\n
    \n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| patient_id   | int     |\n| patient_name | varchar |\n| conditions   | varchar |\n+--------------+---------+\npatient_id is the primary key for this table.\n'conditions' contains 0 or more code separated by spaces. \nThis table contains information of the patients in the hospital.\n
    \n\n

     

    \n\n

    Write an SQL query to report the patient_id, patient_name all conditions of patients who have Type I Diabetes. Type I Diabetes always starts with DIAB1 prefix

    \n\n

    Return the result table in any order.

    \n\n

    The query result format is in the following example.

    \n\n

     

    \n\n
    \nPatients\n+------------+--------------+--------------+\n| patient_id | patient_name | conditions   |\n+------------+--------------+--------------+\n| 1          | Daniel       | YFEV COUGH   |\n| 2          | Alice        |              |\n| 3          | Bob          | DIAB100 MYOP |\n| 4          | George       | ACNE DIAB100 |\n| 5          | Alain        | DIAB201      |\n+------------+--------------+--------------+\n\nResult table:\n+------------+--------------+--------------+\n| patient_id | patient_name | conditions   |\n+------------+--------------+--------------+\n| 3          | Bob          | DIAB100 MYOP |\n| 4          | George       | ACNE DIAB100 | \n+------------+--------------+--------------+\nBob and George both have a condition that starts with DIAB1.\n
    \n", "content_cn": "

    \u60a3\u8005\u4fe1\u606f\u8868\uff1a Patients

    \n\n
    +--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| patient_id   | int     |\n| patient_name | varchar |\n| conditions   | varchar |\n+--------------+---------+\npatient_id \uff08\u60a3\u8005 ID\uff09\u662f\u8be5\u8868\u7684\u4e3b\u952e\u3002\n'conditions' \uff08\u75be\u75c5\uff09\u5305\u542b 0 \u4e2a\u6216\u4ee5\u4e0a\u7684\u75be\u75c5\u4ee3\u7801\uff0c\u4ee5\u7a7a\u683c\u5206\u9694\u3002\n\u8fd9\u4e2a\u8868\u5305\u542b\u533b\u9662\u4e2d\u60a3\u8005\u7684\u4fe1\u606f\u3002
    \n\n

     

    \n\n

    \u5199\u4e00\u6761 SQL \u8bed\u53e5\uff0c\u67e5\u8be2\u60a3\u6709 I \u7c7b\u7cd6\u5c3f\u75c5\u7684\u60a3\u8005 ID \uff08patient_id\uff09\u3001\u60a3\u8005\u59d3\u540d\uff08patient_name\uff09\u4ee5\u53ca\u5176\u60a3\u6709\u7684\u6240\u6709\u75be\u75c5\u4ee3\u7801\uff08conditions\uff09\u3002I \u7c7b\u7cd6\u5c3f\u75c5\u7684\u4ee3\u7801\u603b\u662f\u5305\u542b\u524d\u7f00 DIAB1 \u3002

    \n\n

    \u6309\u4efb\u610f\u987a\u5e8f\u8fd4\u56de\u7ed3\u679c\u8868\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u793a\u4f8b\u6240\u793a\uff1a

    \n\n

     

    \n\n
    Patients\n+------------+--------------+--------------+\n| patient_id | patient_name | conditions   |\n+------------+--------------+--------------+\n| 1          | Daniel       | YFEV COUGH   |\n| 2          | Alice        |              |\n| 3          | Bob          | DIAB100 MYOP |\n| 4          | George       | ACNE DIAB100 |\n| 5          | Alain        | DIAB201      |\n+------------+--------------+--------------+\n\n\u7ed3\u679c\u8868\uff1a\n+------------+--------------+--------------+\n| patient_id | patient_name | conditions   |\n+------------+--------------+--------------+\n| 3          | Bob          | DIAB100 MYOP |\n| 4          | George       | ACNE DIAB100 | \n+------------+--------------+--------------+\nBob \u548c George \u90fd\u60a3\u6709\u4ee3\u7801\u4ee5 DIAB1 \u5f00\u5934\u7684\u75be\u75c5\u3002\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1527](https://leetcode-cn.com/problems/patients-with-a-condition)", "[\u60a3\u67d0\u79cd\u75be\u75c5\u7684\u60a3\u8005](/solution/1500-1599/1527.Patients%20With%20a%20Condition/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1527](https://leetcode.com/problems/patients-with-a-condition)", "[Patients With a Condition](/solution/1500-1599/1527.Patients%20With%20a%20Condition/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1669", "frontend_question_id": "1547", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-cost-to-cut-a-stick", "url_en": "https://leetcode.com/problems/minimum-cost-to-cut-a-stick", "relative_path_cn": "/solution/1500-1599/1547.Minimum%20Cost%20to%20Cut%20a%20Stick/README.md", "relative_path_en": "/solution/1500-1599/1547.Minimum%20Cost%20to%20Cut%20a%20Stick/README_EN.md", "title_cn": "\u5207\u68cd\u5b50\u7684\u6700\u5c0f\u6210\u672c", "title_en": "Minimum Cost to Cut a Stick", "question_title_slug": "minimum-cost-to-cut-a-stick", "content_en": "

    Given a wooden stick of length n units. The stick is labelled from 0 to n. For example, a stick of length 6 is labelled as follows:

    \r\n\"\"\r\n

    Given an integer array cuts where cuts[i] denotes a position you should perform a cut at.

    \r\n\r\n

    You should perform the cuts in order, you can change the order of the cuts as you wish.

    \r\n\r\n

    The cost of one cut is the length of the stick to be cut, the total cost is the sum of costs of all cuts. When you cut a stick, it will be split into two smaller sticks (i.e. the sum of their lengths is the length of the stick before the cut). Please refer to the first example for a better explanation.

    \r\n\r\n

    Return the minimum total cost of the cuts.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\"\"\r\n
    \r\nInput: n = 7, cuts = [1,3,4,5]\r\nOutput: 16\r\nExplanation: Using cuts order = [1, 3, 4, 5] as in the input leads to the following scenario:\r\n\"\"\r\nThe first cut is done to a rod of length 7 so the cost is 7. The second cut is done to a rod of length 6 (i.e. the second part of the first cut), the third is done to a rod of length 4 and the last cut is to a rod of length 3. The total cost is 7 + 6 + 4 + 3 = 20.\r\nRearranging the cuts to be [3, 5, 1, 4] for example will lead to a scenario with total cost = 16 (as shown in the example photo 7 + 4 + 3 + 2 = 16).
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: n = 9, cuts = [5,6,1,4,2]\r\nOutput: 22\r\nExplanation: If you try the given cuts ordering the cost will be 25.\r\nThere are much ordering with total cost <= 25, for example, the order [4, 6, 5, 2, 1] has total cost = 22 which is the minimum possible.\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 2 <= n <= 10^6
    • \r\n\t
    • 1 <= cuts.length <= min(n - 1, 100)
    • \r\n\t
    • 1 <= cuts[i] <= n - 1
    • \r\n\t
    • All the integers in cuts array are distinct.
    • \r\n
    ", "content_cn": "

    \u6709\u4e00\u6839\u957f\u5ea6\u4e3a n \u4e2a\u5355\u4f4d\u7684\u6728\u68cd\uff0c\u68cd\u4e0a\u4ece 0 \u5230 n \u6807\u8bb0\u4e86\u82e5\u5e72\u4f4d\u7f6e\u3002\u4f8b\u5982\uff0c\u957f\u5ea6\u4e3a 6 \u7684\u68cd\u5b50\u53ef\u4ee5\u6807\u8bb0\u5982\u4e0b\uff1a

    \n\n

    \"\"

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 cuts \uff0c\u5176\u4e2d cuts[i] \u8868\u793a\u4f60\u9700\u8981\u5c06\u68cd\u5b50\u5207\u5f00\u7684\u4f4d\u7f6e\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u6309\u987a\u5e8f\u5b8c\u6210\u5207\u5272\uff0c\u4e5f\u53ef\u4ee5\u6839\u636e\u9700\u8981\u66f4\u6539\u5207\u5272\u7684\u987a\u5e8f\u3002

    \n\n

    \u6bcf\u6b21\u5207\u5272\u7684\u6210\u672c\u90fd\u662f\u5f53\u524d\u8981\u5207\u5272\u7684\u68cd\u5b50\u7684\u957f\u5ea6\uff0c\u5207\u68cd\u5b50\u7684\u603b\u6210\u672c\u662f\u5386\u6b21\u5207\u5272\u6210\u672c\u7684\u603b\u548c\u3002\u5bf9\u68cd\u5b50\u8fdb\u884c\u5207\u5272\u5c06\u4f1a\u628a\u4e00\u6839\u6728\u68cd\u5206\u6210\u4e24\u6839\u8f83\u5c0f\u7684\u6728\u68cd\uff08\u8fd9\u4e24\u6839\u6728\u68cd\u7684\u957f\u5ea6\u548c\u5c31\u662f\u5207\u5272\u524d\u6728\u68cd\u7684\u957f\u5ea6\uff09\u3002\u8bf7\u53c2\u9605\u7b2c\u4e00\u4e2a\u793a\u4f8b\u4ee5\u83b7\u5f97\u66f4\u76f4\u89c2\u7684\u89e3\u91ca\u3002

    \n\n

    \u8fd4\u56de\u5207\u68cd\u5b50\u7684 \u6700\u5c0f\u603b\u6210\u672c \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1an = 7, cuts = [1,3,4,5]\n\u8f93\u51fa\uff1a16\n\u89e3\u91ca\uff1a\u6309 [1, 3, 4, 5] \u7684\u987a\u5e8f\u5207\u5272\u7684\u60c5\u51b5\u5982\u4e0b\u6240\u793a\uff1a\n\"\"\n\u7b2c\u4e00\u6b21\u5207\u5272\u957f\u5ea6\u4e3a 7 \u7684\u68cd\u5b50\uff0c\u6210\u672c\u4e3a 7 \u3002\u7b2c\u4e8c\u6b21\u5207\u5272\u957f\u5ea6\u4e3a 6 \u7684\u68cd\u5b50\uff08\u5373\u7b2c\u4e00\u6b21\u5207\u5272\u5f97\u5230\u7684\u7b2c\u4e8c\u6839\u68cd\u5b50\uff09\uff0c\u7b2c\u4e09\u6b21\u5207\u5272\u4e3a\u957f\u5ea6 4 \u7684\u68cd\u5b50\uff0c\u6700\u540e\u5207\u5272\u957f\u5ea6\u4e3a 3 \u7684\u68cd\u5b50\u3002\u603b\u6210\u672c\u4e3a 7 + 6 + 4 + 3 = 20 \u3002\n\u800c\u5c06\u5207\u5272\u987a\u5e8f\u91cd\u65b0\u6392\u5217\u4e3a [3, 5, 1, 4] \u540e\uff0c\u603b\u6210\u672c = 16\uff08\u5982\u793a\u4f8b\u56fe\u4e2d 7 + 4 + 3 + 2 = 16\uff09\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 9, cuts = [5,6,1,4,2]\n\u8f93\u51fa\uff1a22\n\u89e3\u91ca\uff1a\u5982\u679c\u6309\u7ed9\u5b9a\u7684\u987a\u5e8f\u5207\u5272\uff0c\u5219\u603b\u6210\u672c\u4e3a 25 \u3002\u603b\u6210\u672c <= 25 \u7684\u5207\u5272\u987a\u5e8f\u5f88\u591a\uff0c\u4f8b\u5982\uff0c[4, 6, 5, 2, 1] \u7684\u603b\u6210\u672c = 22\uff0c\u662f\u6240\u6709\u53ef\u80fd\u65b9\u6848\u4e2d\u6210\u672c\u6700\u5c0f\u7684\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= n <= 10^6
    • \n\t
    • 1 <= cuts.length <= min(n - 1, 100)
    • \n\t
    • 1 <= cuts[i] <= n - 1
    • \n\t
    • cuts \u6570\u7ec4\u4e2d\u7684\u6240\u6709\u6574\u6570\u90fd \u4e92\u4e0d\u76f8\u540c
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minCost(int n, vector& cuts) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minCost(int n, int[] cuts) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minCost(self, n, cuts):\n \"\"\"\n :type n: int\n :type cuts: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minCost(self, n: int, cuts: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minCost(int n, int* cuts, int cutsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinCost(int n, int[] cuts) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[]} cuts\n * @return {number}\n */\nvar minCost = function(n, cuts) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[]} cuts\n# @return {Integer}\ndef min_cost(n, cuts)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minCost(_ n: Int, _ cuts: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minCost(n int, cuts []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minCost(n: Int, cuts: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minCost(n: Int, cuts: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_cost(n: i32, cuts: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[] $cuts\n * @return Integer\n */\n function minCost($n, $cuts) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minCost(n: number, cuts: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-cost n cuts)\n (-> exact-integer? (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1547](https://leetcode-cn.com/problems/minimum-cost-to-cut-a-stick)", "[\u5207\u68cd\u5b50\u7684\u6700\u5c0f\u6210\u672c](/solution/1500-1599/1547.Minimum%20Cost%20to%20Cut%20a%20Stick/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1547](https://leetcode.com/problems/minimum-cost-to-cut-a-stick)", "[Minimum Cost to Cut a Stick](/solution/1500-1599/1547.Minimum%20Cost%20to%20Cut%20a%20Stick/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1668", "frontend_question_id": "1542", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-longest-awesome-substring", "url_en": "https://leetcode.com/problems/find-longest-awesome-substring", "relative_path_cn": "/solution/1500-1599/1542.Find%20Longest%20Awesome%20Substring/README.md", "relative_path_en": "/solution/1500-1599/1542.Find%20Longest%20Awesome%20Substring/README_EN.md", "title_cn": "\u627e\u51fa\u6700\u957f\u7684\u8d85\u8d5e\u5b50\u5b57\u7b26\u4e32", "title_en": "Find Longest Awesome Substring", "question_title_slug": "find-longest-awesome-substring", "content_en": "

    Given a string s. An awesome substring is a non-empty substring of s such that we can make any number of swaps in order to make it palindrome.

    \n\n

    Return the length of the maximum length awesome substring of s.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "3242415"\nOutput: 5\nExplanation: "24241" is the longest awesome substring, we can form the palindrome "24142" with some swaps.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "12345678"\nOutput: 1\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "213123"\nOutput: 6\nExplanation: "213123" is the longest awesome substring, we can form the palindrome "231132" with some swaps.\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "00"\nOutput: 2\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 10^5
    • \n\t
    • s consists only of digits.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \u3002\u8bf7\u8fd4\u56de s \u4e2d\u6700\u957f\u7684 \u8d85\u8d5e\u5b50\u5b57\u7b26\u4e32 \u7684\u957f\u5ea6\u3002

    \n\n

    \u300c\u8d85\u8d5e\u5b50\u5b57\u7b26\u4e32\u300d\u9700\u6ee1\u8db3\u6ee1\u8db3\u4e0b\u8ff0\u4e24\u4e2a\u6761\u4ef6\uff1a

    \n\n
      \n\t
    • \u8be5\u5b57\u7b26\u4e32\u662f s \u7684\u4e00\u4e2a\u975e\u7a7a\u5b50\u5b57\u7b26\u4e32
    • \n\t
    • \u8fdb\u884c\u4efb\u610f\u6b21\u6570\u7684\u5b57\u7b26\u4ea4\u6362\u540e\uff0c\u8be5\u5b57\u7b26\u4e32\u53ef\u4ee5\u53d8\u6210\u4e00\u4e2a\u56de\u6587\u5b57\u7b26\u4e32
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1as = "3242415"\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a"24241" \u662f\u6700\u957f\u7684\u8d85\u8d5e\u5b50\u5b57\u7b26\u4e32\uff0c\u4ea4\u6362\u5176\u4e2d\u7684\u5b57\u7b26\u540e\uff0c\u53ef\u4ee5\u5f97\u5230\u56de\u6587 "24142"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1as = "12345678"\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1as = "213123"\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a"213123" \u662f\u6700\u957f\u7684\u8d85\u8d5e\u5b50\u5b57\u7b26\u4e32\uff0c\u4ea4\u6362\u5176\u4e2d\u7684\u5b57\u7b26\u540e\uff0c\u53ef\u4ee5\u5f97\u5230\u56de\u6587 "231132"\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1as = "00"\n\u8f93\u51fa\uff1a2\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 10^5
    • \n\t
    • s \u4ec5\u7531\u6570\u5b57\u7ec4\u6210
    • \n
    \n", "tags_en": ["Bit Manipulation", "String"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int longestAwesome(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int longestAwesome(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestAwesome(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestAwesome(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint longestAwesome(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LongestAwesome(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar longestAwesome = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef longest_awesome(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestAwesome(_ s: String) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestAwesome(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestAwesome(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestAwesome(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_awesome(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function longestAwesome($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestAwesome(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-awesome s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1542](https://leetcode-cn.com/problems/find-longest-awesome-substring)", "[\u627e\u51fa\u6700\u957f\u7684\u8d85\u8d5e\u5b50\u5b57\u7b26\u4e32](/solution/1500-1599/1542.Find%20Longest%20Awesome%20Substring/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u5b57\u7b26\u4e32`", "\u56f0\u96be", ""], "md_table_row_en": ["[1542](https://leetcode.com/problems/find-longest-awesome-substring)", "[Find Longest Awesome Substring](/solution/1500-1599/1542.Find%20Longest%20Awesome%20Substring/README_EN.md)", "`Bit Manipulation`,`String`", "Hard", ""]}, {"question_id": "1667", "frontend_question_id": "1545", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-kth-bit-in-nth-binary-string", "url_en": "https://leetcode.com/problems/find-kth-bit-in-nth-binary-string", "relative_path_cn": "/solution/1500-1599/1545.Find%20Kth%20Bit%20in%20Nth%20Binary%20String/README.md", "relative_path_en": "/solution/1500-1599/1545.Find%20Kth%20Bit%20in%20Nth%20Binary%20String/README_EN.md", "title_cn": "\u627e\u51fa\u7b2c N \u4e2a\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32\u4e2d\u7684\u7b2c K \u4f4d", "title_en": "Find Kth Bit in Nth Binary String", "question_title_slug": "find-kth-bit-in-nth-binary-string", "content_en": "

    Given two positive integers n and k, the binary string  Sn is formed as follows:

    \r\n\r\n
      \r\n\t
    • S1 = "0"
    • \r\n\t
    • Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1
    • \r\n
    \r\n\r\n

    Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0).

    \r\n\r\n

    For example, the first 4 strings in the above sequence are:

    \r\n\r\n
      \r\n\t
    • S= "0"
    • \r\n\t
    • S= "011"
    • \r\n\t
    • S= "0111001"
    • \r\n\t
    • S4 = "011100110110001"
    • \r\n
    \r\n\r\n

    Return the kth bit in Sn. It is guaranteed that k is valid for the given n.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: n = 3, k = 1\r\nOutput: "0"\r\nExplanation: S3 is "0111001". The first bit is "0".\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: n = 4, k = 11\r\nOutput: "1"\r\nExplanation: S4 is "011100110110001". The 11th bit is "1".\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: n = 1, k = 1\r\nOutput: "0"\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: n = 2, k = 3\r\nOutput: "1"\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= n <= 20
    • \r\n\t
    • 1 <= k <= 2n - 1
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u6b63\u6574\u6570 n \u548c k\uff0c\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32\u00a0 Sn \u7684\u5f62\u6210\u89c4\u5219\u5982\u4e0b\uff1a

    \n\n
      \n\t
    • S1\u00a0= \"0\"
    • \n\t
    • \u5f53 i > 1 \u65f6\uff0cSi\u00a0=\u00a0Si-1\u00a0+ \"1\" + reverse(invert(Si-1))
    • \n
    \n\n

    \u5176\u4e2d + \u8868\u793a\u4e32\u8054\u64cd\u4f5c\uff0creverse(x) \u8fd4\u56de\u53cd\u8f6c x \u540e\u5f97\u5230\u7684\u5b57\u7b26\u4e32\uff0c\u800c invert(x) \u5219\u4f1a\u7ffb\u8f6c x \u4e2d\u7684\u6bcf\u4e00\u4f4d\uff080 \u53d8\u4e3a 1\uff0c\u800c 1 \u53d8\u4e3a 0\uff09\u3002

    \n\n

    \u4f8b\u5982\uff0c\u7b26\u5408\u4e0a\u8ff0\u63cf\u8ff0\u7684\u5e8f\u5217\u7684\u524d 4 \u4e2a\u5b57\u7b26\u4e32\u4f9d\u6b21\u662f\uff1a

    \n\n
      \n\t
    • S1\u00a0= \"0\"
    • \n\t
    • S2\u00a0= \"011\"
    • \n\t
    • S3\u00a0= \"0111001\"
    • \n\t
    • S4 = \"011100110110001\"
    • \n
    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u00a0 Sn \u7684 \u7b2c k \u4f4d\u5b57\u7b26 \uff0c\u9898\u76ee\u6570\u636e\u4fdd\u8bc1 k \u4e00\u5b9a\u5728 Sn \u957f\u5ea6\u8303\u56f4\u4ee5\u5185\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 3, k = 1\n\u8f93\u51fa\uff1a\"0\"\n\u89e3\u91ca\uff1aS3 \u4e3a \"0111001\"\uff0c\u5176\u7b2c 1 \u4f4d\u4e3a \"0\" \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 4, k = 11\n\u8f93\u51fa\uff1a\"1\"\n\u89e3\u91ca\uff1aS4 \u4e3a \"011100110110001\"\uff0c\u5176\u7b2c 11 \u4f4d\u4e3a \"1\" \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 1, k = 1\n\u8f93\u51fa\uff1a\"0\"\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 2, k = 3\n\u8f93\u51fa\uff1a\"1\"\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 20
    • \n\t
    • 1 <= k <= 2n - 1
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n char findKthBit(int n, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public char findKthBit(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findKthBit(self, n, k):\n \"\"\"\n :type n: int\n :type k: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findKthBit(self, n: int, k: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar findKthBit(int n, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public char FindKthBit(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} k\n * @return {character}\n */\nvar findKthBit = function(n, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} k\n# @return {Character}\ndef find_kth_bit(n, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findKthBit(_ n: Int, _ k: Int) -> Character {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findKthBit(n int, k int) byte {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findKthBit(n: Int, k: Int): Char = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findKthBit(n: Int, k: Int): Char {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_kth_bit(n: i32, k: i32) -> char {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $k\n * @return String\n */\n function findKthBit($n, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findKthBit(n: number, k: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-kth-bit n k)\n (-> exact-integer? exact-integer? char?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1545](https://leetcode-cn.com/problems/find-kth-bit-in-nth-binary-string)", "[\u627e\u51fa\u7b2c N \u4e2a\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32\u4e2d\u7684\u7b2c K \u4f4d](/solution/1500-1599/1545.Find%20Kth%20Bit%20in%20Nth%20Binary%20String/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1545](https://leetcode.com/problems/find-kth-bit-in-nth-binary-string)", "[Find Kth Bit in Nth Binary String](/solution/1500-1599/1545.Find%20Kth%20Bit%20in%20Nth%20Binary%20String/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "1666", "frontend_question_id": "1544", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/make-the-string-great", "url_en": "https://leetcode.com/problems/make-the-string-great", "relative_path_cn": "/solution/1500-1599/1544.Make%20The%20String%20Great/README.md", "relative_path_en": "/solution/1500-1599/1544.Make%20The%20String%20Great/README_EN.md", "title_cn": "\u6574\u7406\u5b57\u7b26\u4e32", "title_en": "Make The String Great", "question_title_slug": "make-the-string-great", "content_en": "

    Given a string s of lower and upper case English letters.

    \r\n\r\n

    A good string is a string which doesn't have two adjacent characters s[i] and s[i + 1] where:

    \r\n\r\n
      \r\n\t
    • 0 <= i <= s.length - 2
    • \r\n\t
    • s[i] is a lower-case letter and s[i + 1] is the same letter but in upper-case or vice-versa.
    • \r\n
    \r\n\r\n

    To make the string good, you can choose two adjacent characters that make the string bad and remove them. You can keep doing this until the string becomes good.

    \r\n\r\n

    Return the string after making it good. The answer is guaranteed to be unique under the given constraints.

    \r\n\r\n

    Notice that an empty string is also good.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: s = "leEeetcode"\r\nOutput: "leetcode"\r\nExplanation: In the first step, either you choose i = 1 or i = 2, both will result "leEeetcode" to be reduced to "leetcode".\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: s = "abBAcC"\r\nOutput: ""\r\nExplanation: We have many possible scenarios, and all lead to the same answer. For example:\r\n"abBAcC" --> "aAcC" --> "cC" --> ""\r\n"abBAcC" --> "abBA" --> "aA" --> ""\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: s = "s"\r\nOutput: "s"\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= s.length <= 100
    • \r\n\t
    • s contains only lower and upper case English letters.
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u7531\u5927\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\u7684\u5b57\u7b26\u4e32 s \u3002

    \n\n

    \u4e00\u4e2a\u6574\u7406\u597d\u7684\u5b57\u7b26\u4e32\u4e2d\uff0c\u4e24\u4e2a\u76f8\u90bb\u5b57\u7b26 s[i] \u548c s[i+1]\uff0c\u5176\u4e2d 0<= i <= s.length-2 \uff0c\u8981\u6ee1\u8db3\u5982\u4e0b\u6761\u4ef6:

    \n\n
      \n\t
    • \u82e5 s[i] \u662f\u5c0f\u5199\u5b57\u7b26\uff0c\u5219 s[i+1] \u4e0d\u53ef\u4ee5\u662f\u76f8\u540c\u7684\u5927\u5199\u5b57\u7b26\u3002
    • \n\t
    • \u82e5 s[i] \u662f\u5927\u5199\u5b57\u7b26\uff0c\u5219 s[i+1] \u4e0d\u53ef\u4ee5\u662f\u76f8\u540c\u7684\u5c0f\u5199\u5b57\u7b26\u3002
    • \n
    \n\n

    \u8bf7\u4f60\u5c06\u5b57\u7b26\u4e32\u6574\u7406\u597d\uff0c\u6bcf\u6b21\u4f60\u90fd\u53ef\u4ee5\u4ece\u5b57\u7b26\u4e32\u4e2d\u9009\u51fa\u6ee1\u8db3\u4e0a\u8ff0\u6761\u4ef6\u7684 \u4e24\u4e2a\u76f8\u90bb \u5b57\u7b26\u5e76\u5220\u9664\uff0c\u76f4\u5230\u5b57\u7b26\u4e32\u6574\u7406\u597d\u4e3a\u6b62\u3002

    \n\n

    \u8bf7\u8fd4\u56de\u6574\u7406\u597d\u7684 \u5b57\u7b26\u4e32 \u3002\u9898\u76ee\u4fdd\u8bc1\u5728\u7ed9\u51fa\u7684\u7ea6\u675f\u6761\u4ef6\u4e0b\uff0c\u6d4b\u8bd5\u6837\u4f8b\u5bf9\u5e94\u7684\u7b54\u6848\u662f\u552f\u4e00\u7684\u3002

    \n\n

    \u6ce8\u610f\uff1a\u7a7a\u5b57\u7b26\u4e32\u4e5f\u5c5e\u4e8e\u6574\u7406\u597d\u7684\u5b57\u7b26\u4e32\uff0c\u5c3d\u7ba1\u5176\u4e2d\u6ca1\u6709\u4efb\u4f55\u5b57\u7b26\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"leEeetcode\"\n\u8f93\u51fa\uff1a\"leetcode\"\n\u89e3\u91ca\uff1a\u65e0\u8bba\u4f60\u7b2c\u4e00\u6b21\u9009\u7684\u662f i = 1 \u8fd8\u662f i = 2\uff0c\u90fd\u4f1a\u4f7f \"leEeetcode\" \u7f29\u51cf\u4e3a \"leetcode\" \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"abBAcC\"\n\u8f93\u51fa\uff1a\"\"\n\u89e3\u91ca\uff1a\u5b58\u5728\u591a\u79cd\u4e0d\u540c\u60c5\u51b5\uff0c\u4f46\u6240\u6709\u7684\u60c5\u51b5\u90fd\u4f1a\u5bfc\u81f4\u76f8\u540c\u7684\u7ed3\u679c\u3002\u4f8b\u5982\uff1a\n\"abBAcC\" --> \"aAcC\" --> \"cC\" --> \"\"\n\"abBAcC\" --> \"abBA\" --> \"aA\" --> \"\"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"s\"\n\u8f93\u51fa\uff1a\"s\"\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 100
    • \n\t
    • s \u53ea\u5305\u542b\u5c0f\u5199\u548c\u5927\u5199\u82f1\u6587\u5b57\u6bcd
    • \n
    \n", "tags_en": ["Stack", "String"], "tags_cn": ["\u6808", "\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string makeGood(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String makeGood(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def makeGood(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def makeGood(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * makeGood(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string MakeGood(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar makeGood = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef make_good(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func makeGood(_ s: String) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func makeGood(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def makeGood(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun makeGood(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn make_good(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function makeGood($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function makeGood(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (make-good s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1544](https://leetcode-cn.com/problems/make-the-string-great)", "[\u6574\u7406\u5b57\u7b26\u4e32](/solution/1500-1599/1544.Make%20The%20String%20Great/README.md)", "`\u6808`,`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1544](https://leetcode.com/problems/make-the-string-great)", "[Make The String Great](/solution/1500-1599/1544.Make%20The%20String%20Great/README_EN.md)", "`Stack`,`String`", "Easy", ""]}, {"question_id": "1665", "frontend_question_id": "1522", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/diameter-of-n-ary-tree", "url_en": "https://leetcode.com/problems/diameter-of-n-ary-tree", "relative_path_cn": "/solution/1500-1599/1522.Diameter%20of%20N-Ary%20Tree/README.md", "relative_path_en": "/solution/1500-1599/1522.Diameter%20of%20N-Ary%20Tree/README_EN.md", "title_cn": "N \u53c9\u6811\u7684\u76f4\u5f84", "title_en": "Diameter of N-Ary Tree", "question_title_slug": "diameter-of-n-ary-tree", "content_en": "

    Given a root of an N-ary tree, you need to compute the length of the diameter of the tree.

    \n\n

    The diameter of an N-ary tree is the length of the longest path between any two nodes in the tree. This path may or may not pass through the root.

    \n\n

    (Nary-Tree input serialization is represented in their level order traversal, each group of children is separated by the null value.)

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: root = [1,null,3,2,4,null,5,6]\nOutput: 3\nExplanation: Diameter is shown in red color.
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: root = [1,null,2,null,3,4,null,5,null,6]\nOutput: 4\n
    \n\n

    Example 3:

    \n\n

    \"\"

    \n\n
    \nInput: root = [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]\nOutput: 7\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The depth of the n-ary tree is less than or equal to 1000.
    • \n\t
    • The total number of nodes is between [1, 104].
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u68f5 N \u53c9\u6811\u7684\u6839\u8282\u70b9 root \uff0c\u8ba1\u7b97\u8fd9\u68f5\u6811\u7684\u76f4\u5f84\u957f\u5ea6\u3002

    \n\n

    N \u53c9\u6811\u7684\u76f4\u5f84\u6307\u7684\u662f\u6811\u4e2d\u4efb\u610f\u4e24\u4e2a\u8282\u70b9\u95f4\u8def\u5f84\u4e2d \u6700\u957f \u8def\u5f84\u7684\u957f\u5ea6\u3002\u8fd9\u6761\u8def\u5f84\u53ef\u80fd\u7ecf\u8fc7\u6839\u8282\u70b9\uff0c\u4e5f\u53ef\u80fd\u4e0d\u7ecf\u8fc7\u6839\u8282\u70b9\u3002

    \n\n

    \uff08N \u53c9\u6811\u7684\u8f93\u5165\u5e8f\u5217\u4ee5\u5c42\u5e8f\u904d\u5386\u7684\u5f62\u5f0f\u7ed9\u51fa\uff0c\u6bcf\u7ec4\u5b50\u8282\u70b9\u7528 null \u5206\u9694\uff09

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aroot = [1,null,3,2,4,null,5,6]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u76f4\u5f84\u5982\u56fe\u4e2d\u7ea2\u7ebf\u6240\u793a\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aroot = [1,null,2,null,3,4,null,5,null,6]\n\u8f93\u51fa\uff1a4\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165: root = [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]\n\u8f93\u51fa: 7\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • N \u53c9\u6811\u7684\u6df1\u5ea6\u5c0f\u4e8e\u6216\u7b49\u4e8e 1000 \u3002
    • \n\t
    • \u8282\u70b9\u7684\u603b\u4e2a\u6570\u5728 [0, 10^4] \u95f4\u3002
    • \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n vector children;\n\n Node() {}\n\n Node(int _val) {\n val = _val;\n }\n\n Node(int _val, vector _children) {\n val = _val;\n children = _children;\n }\n};\n*/\n\nclass Solution {\npublic:\n int diameter(Node* root) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/*\n// Definition for a Node.\nclass Node {\n public int val;\n public List children;\n\n \n public Node() {\n children = new ArrayList();\n }\n \n public Node(int _val) {\n val = _val;\n children = new ArrayList();\n }\n \n public Node(int _val,ArrayList _children) {\n val = _val;\n children = _children;\n }\n};\n*/\n\nclass Solution {\n public int diameter(Node root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "\"\"\"\n# Definition for a Node.\nclass Node(object):\n def __init__(self, val=None, children=None):\n self.val = val\n self.children = children if children is not None else []\n\"\"\"\n\nclass Solution(object):\n def diameter(self, root):\n \"\"\"\n :type root: 'Node'\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "\"\"\"\n# Definition for a Node.\nclass Node:\n def __init__(self, val=None, children=None):\n self.val = val\n self.children = children if children is not None else []\n\"\"\"\n\nclass Solution:\n def diameter(self, root: 'Node') -> int:\n \"\"\"\n :type root: 'Node'\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a Node.\n * struct Node {\n * int val;\n * int numChildren;\n * struct Node** children;\n * };\n */\n\nint* diameter(struct Node* root) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/*\n// Definition for a Node.\npublic class Node {\n public int val;\n public IList children;\n \n public Node() {\n val = 0;\n children = new List();\n }\n\n public Node(int _val) {\n val = _val;\n children = new List();\n }\n \n public Node(int _val, List _children) {\n val = _val;\n children = _children;\n }\n}\n*/\n\npublic class Solution {\n public int Diameter(Node root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // Definition for a Node.\n * function Node(val, children) {\n * this.val = val === undefined ? 0 : val;\n * this.children = children === undefined ? [] : children;\n * };\n */\n\n/**\n * @param {Node} root\n * @return {number}\n */\nvar diameter = function(root) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a Node.\n# class Node\n# attr_accessor :val, :children\n# def initialize(val=0, children=[])\n# @val = val\n# @children = children\n# end\n# end\n\n# @param {Node} root\n# @return {Integer}\ndef diameter(root)\n\t\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a Node.\n * public class Node {\n * public var val: Int\n * public var children: [Node]\n * public init(_ val: Int) {\n * self.val = val\n * self.children = []\n * }\n * }\n */\n\nclass Solution {\n func diameter(_ root: Node?) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a Node.\n * type Node struct {\n * Val int\n * Children []*Node\n * }\n */\n\nfunc diameter(root *Node) int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a Node.\n * class Node(var _value: Int) {\n * var value: Int = _value\n * var children: List[Node] = List()\n * }\n */\n\nobject Solution {\n def diameter(root: Node): Int = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a Node.\n * class Node(var `val`: Int) {\n * var children: List = listOf()\n * }\n */\n\nclass Solution {\n fun diameter(root: Node?): Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a Node.\n * class Node {\n * public $val = null;\n * public $children = null;\n * function __construct($val = 0) {\n * $this->val = $val;\n * $this->children = array();\n * }\n * }\n */\n\nclass Solution {\n /**\n * @param Node $root\n * @return Integer\n */\n function diameter($root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for Node.\n * class Node {\n * val: number\n * children: Node[]\n * constructor(val?: number, children?: Node[]) {\n * this.val = (val===undefined ? 0 : val)\n * this.children = (children===undefined ? [] : children)\n * }\n * }\n */\n\nfunction diameter(root: Node): number {\n \n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1522](https://leetcode-cn.com/problems/diameter-of-n-ary-tree)", "[N \u53c9\u6811\u7684\u76f4\u5f84](/solution/1500-1599/1522.Diameter%20of%20N-Ary%20Tree/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1522](https://leetcode.com/problems/diameter-of-n-ary-tree)", "[Diameter of N-Ary Tree](/solution/1500-1599/1522.Diameter%20of%20N-Ary%20Tree/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1664", "frontend_question_id": "1517", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/find-users-with-valid-e-mails", "url_en": "https://leetcode.com/problems/find-users-with-valid-e-mails", "relative_path_cn": "/solution/1500-1599/1517.Find%20Users%20With%20Valid%20E-Mails/README.md", "relative_path_en": "/solution/1500-1599/1517.Find%20Users%20With%20Valid%20E-Mails/README_EN.md", "title_cn": "\u67e5\u627e\u62e5\u6709\u6709\u6548\u90ae\u7bb1\u7684\u7528\u6237", "title_en": "Find Users With Valid E-Mails", "question_title_slug": "find-users-with-valid-e-mails", "content_en": "

    Table: Users

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| user_id       | int     |\n| name          | varchar |\n| mail          | varchar |\n+---------------+---------+\nuser_id is the primary key for this table.\nThis table contains information of the users signed up in a website. Some e-mails are invalid.\n
    \n\n

     

    \n\n

    Write an SQL query to find the users who have valid emails.

    \n\n

    A valid e-mail has a prefix name and a domain where: 

    \n\n
      \n\t
    • The prefix name is a string that may contain letters (upper or lower case), digits, underscore '_', period '.' and/or dash '-'. The prefix name must start with a letter.
    • \n\t
    • The domain is '@leetcode.com'.
    • \n
    \n\n

    Return the result table in any order.

    \n\n

    The query result format is in the following example.

    \n\n

     

    \n\n
    \nUsers\n+---------+-----------+-------------------------+\n| user_id | name      | mail                    |\n+---------+-----------+-------------------------+\n| 1       | Winston   | winston@leetcode.com    |\n| 2       | Jonathan  | jonathanisgreat         |\n| 3       | Annabelle | bella-@leetcode.com     |\n| 4       | Sally     | sally.come@leetcode.com |\n| 5       | Marwan    | quarz#2020@leetcode.com |\n| 6       | David     | david69@gmail.com       |\n| 7       | Shapiro   | .shapo@leetcode.com     |\n+---------+-----------+-------------------------+\n\nResult table:\n+---------+-----------+-------------------------+\n| user_id | name      | mail                    |\n+---------+-----------+-------------------------+\n| 1       | Winston   | winston@leetcode.com    |\n| 3       | Annabelle | bella-@leetcode.com     |\n| 4       | Sally     | sally.come@leetcode.com |\n+---------+-----------+-------------------------+\nThe mail of user 2 doesn't have a domain.\nThe mail of user 5 has # sign which is not allowed.\nThe mail of user 6 doesn't have leetcode domain.\nThe mail of user 7 starts with a period.\n
    \n", "content_cn": "

    \u7528\u6237\u8868\uff1a Users

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| user_id       | int     |\n| name          | varchar |\n| mail          | varchar | \n+---------------+---------+\nuser_id \uff08\u7528\u6237 ID\uff09\u662f\u8be5\u8868\u7684\u4e3b\u952e\u3002\n\u8fd9\u4e2a\u8868\u5305\u542b\u7528\u6237\u5728\u67d0\u7f51\u7ad9\u4e0a\u6ce8\u518c\u7684\u4fe1\u606f\u3002\u6709\u4e9b\u90ae\u7bb1\u662f\u65e0\u6548\u7684\u3002
    \n\n

     

    \n\n

    \u5199\u4e00\u6761 SQL \u8bed\u53e5\uff0c\u67e5\u8be2\u62e5\u6709\u6709\u6548\u90ae\u7bb1\u7684\u7528\u6237\u3002

    \n\n

    \u6709\u6548\u7684\u90ae\u7bb1\u5305\u542b\u7b26\u5408\u4e0b\u5217\u6761\u4ef6\u7684\u524d\u7f00\u540d\u548c\u57df\u540d\uff1a

    \n\n
      \n\t
    • \u524d\u7f00\u540d\u662f\u5305\u542b\u5b57\u6bcd\uff08\u5927\u5199\u6216\u5c0f\u5199\uff09\u3001\u6570\u5b57\u3001\u4e0b\u5212\u7ebf '_'\u3001\u53e5\u70b9 '.' \u548c/\u6216\u6a2a\u6760 '-' \u7684\u5b57\u7b26\u4e32\u3002\u524d\u7f00\u540d\u5fc5\u987b\u4ee5\u5b57\u6bcd\u5f00\u5934\u3002
    • \n\t
    • \u57df\u540d\u662f '@leetcode.com' \u3002
    • \n
    \n\n

    \u6309\u4efb\u610f\u987a\u5e8f\u8fd4\u56de\u7ed3\u679c\u8868\u3002

    \n\n

     

    \n\n

    \u67e5\u8be2\u683c\u5f0f\u5982\u4e0b\u6240\u793a\uff1a

    \n\n
    \nUsers\n+---------+-----------+-------------------------+\n| user_id | name      | mail                    |\n+---------+-----------+-------------------------+\n| 1       | Winston   | winston@leetcode.com    |\n| 2       | Jonathan  | jonathanisgreat         |\n| 3       | Annabelle | bella-@leetcode.com     |\n| 4       | Sally     | sally.come@leetcode.com |\n| 5       | Marwan    | quarz#2020@leetcode.com |\n| 6       | David     | david69@gmail.com       |\n| 7       | Shapiro   | .shapo@leetcode.com     |\n+---------+-----------+-------------------------+\n\n\u7ed3\u679c\u8868\uff1a\n+---------+-----------+-------------------------+\n| user_id | name      | mail                    |\n+---------+-----------+-------------------------+\n| 1       | Winston   | winston@leetcode.com    |\n| 3       | Annabelle | bella-@leetcode.com     |\n| 4       | Sally     | sally.come@leetcode.com |\n+---------+-----------+-------------------------+\n2 \u53f7\u7528\u6237\u7684\u90ae\u7bb1\u6ca1\u6709\u57df\u540d\u3002\n5 \u53f7\u7528\u6237\u7684\u90ae\u7bb1\u5305\u542b\u975e\u6cd5\u5b57\u7b26 #\u3002\n6 \u53f7\u7528\u6237\u7684\u90ae\u7bb1\u7684\u57df\u540d\u4e0d\u662f leetcode\u3002\n7 \u53f7\u7528\u6237\u7684\u90ae\u7bb1\u4ee5\u53e5\u70b9\uff08.\uff09\u5f00\u5934\u3002\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1517](https://leetcode-cn.com/problems/find-users-with-valid-e-mails)", "[\u67e5\u627e\u62e5\u6709\u6709\u6548\u90ae\u7bb1\u7684\u7528\u6237](/solution/1500-1599/1517.Find%20Users%20With%20Valid%20E-Mails/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1517](https://leetcode.com/problems/find-users-with-valid-e-mails)", "[Find Users With Valid E-Mails](/solution/1500-1599/1517.Find%20Users%20With%20Valid%20E-Mails/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1663", "frontend_question_id": "1559", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/detect-cycles-in-2d-grid", "url_en": "https://leetcode.com/problems/detect-cycles-in-2d-grid", "relative_path_cn": "/solution/1500-1599/1559.Detect%20Cycles%20in%202D%20Grid/README.md", "relative_path_en": "/solution/1500-1599/1559.Detect%20Cycles%20in%202D%20Grid/README_EN.md", "title_cn": "\u4e8c\u7ef4\u7f51\u683c\u56fe\u4e2d\u63a2\u6d4b\u73af", "title_en": "Detect Cycles in 2D Grid", "question_title_slug": "detect-cycles-in-2d-grid", "content_en": "

    Given a 2D array of characters grid of size m x n, you need to find if there exists any cycle consisting of the same value in grid.

    \n\n

    A cycle is a path of length 4 or more in the grid that starts and ends at the same cell. From a given cell, you can move to one of the cells adjacent to it - in one of the four directions (up, down, left, or right), if it has the same value of the current cell.

    \n\n

    Also, you cannot move to the cell that you visited in your last move. For example, the cycle (1, 1) -> (1, 2) -> (1, 1) is invalid because from (1, 2) we visited (1, 1) which was the last visited cell.

    \n\n

    Return true if any cycle of the same value exists in grid, otherwise, return false.

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: grid = [["a","a","a","a"],["a","b","b","a"],["a","b","b","a"],["a","a","a","a"]]\nOutput: true\nExplanation: There are two valid cycles shown in different colors in the image below:\n\"\"\n
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: grid = [["c","c","c","a"],["c","d","c","c"],["c","c","e","c"],["f","c","c","c"]]\nOutput: true\nExplanation: There is only one valid cycle highlighted in the image below:\n\"\"\n
    \n\n

    Example 3:

    \n\n

    \"\"

    \n\n
    \nInput: grid = [["a","b","b"],["b","z","b"],["b","b","a"]]\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= m <= 500
    • \n\t
    • 1 <= n <= 500
    • \n\t
    • grid consists only of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u4e8c\u7ef4\u5b57\u7b26\u7f51\u683c\u6570\u7ec4 grid \uff0c\u5927\u5c0f\u4e3a m x n \uff0c\u4f60\u9700\u8981\u68c0\u67e5 grid \u4e2d\u662f\u5426\u5b58\u5728 \u76f8\u540c\u503c \u5f62\u6210\u7684\u73af\u3002

    \n\n

    \u4e00\u4e2a\u73af\u662f\u4e00\u6761\u5f00\u59cb\u548c\u7ed3\u675f\u4e8e\u540c\u4e00\u4e2a\u683c\u5b50\u7684\u957f\u5ea6 \u5927\u4e8e\u7b49\u4e8e 4 \u7684\u8def\u5f84\u3002\u5bf9\u4e8e\u4e00\u4e2a\u7ed9\u5b9a\u7684\u683c\u5b50\uff0c\u4f60\u53ef\u4ee5\u79fb\u52a8\u5230\u5b83\u4e0a\u3001\u4e0b\u3001\u5de6\u3001\u53f3\u56db\u4e2a\u65b9\u5411\u76f8\u90bb\u7684\u683c\u5b50\u4e4b\u4e00\uff0c\u53ef\u4ee5\u79fb\u52a8\u7684\u524d\u63d0\u662f\u8fd9\u4e24\u4e2a\u683c\u5b50\u6709 \u76f8\u540c\u7684\u503c \u3002

    \n\n

    \u540c\u65f6\uff0c\u4f60\u4e5f\u4e0d\u80fd\u56de\u5230\u4e0a\u4e00\u6b21\u79fb\u52a8\u65f6\u6240\u5728\u7684\u683c\u5b50\u3002\u6bd4\u65b9\u8bf4\uff0c\u73af  (1, 1) -> (1, 2) -> (1, 1) \u662f\u4e0d\u5408\u6cd5\u7684\uff0c\u56e0\u4e3a\u4ece (1, 2) \u79fb\u52a8\u5230 (1, 1) \u56de\u5230\u4e86\u4e0a\u4e00\u6b21\u79fb\u52a8\u65f6\u7684\u683c\u5b50\u3002

    \n\n

    \u5982\u679c grid \u4e2d\u6709\u76f8\u540c\u503c\u5f62\u6210\u7684\u73af\uff0c\u8bf7\u4f60\u8fd4\u56de true \uff0c\u5426\u5219\u8fd4\u56de false \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1agrid = [["a","a","a","a"],["a","b","b","a"],["a","b","b","a"],["a","a","a","a"]]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u5982\u4e0b\u56fe\u6240\u793a\uff0c\u6709 2 \u4e2a\u7528\u4e0d\u540c\u989c\u8272\u6807\u51fa\u6765\u7684\u73af\uff1a\n\"\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1agrid = [["c","c","c","a"],["c","d","c","c"],["c","c","e","c"],["f","c","c","c"]]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u5982\u4e0b\u56fe\u6240\u793a\uff0c\u53ea\u6709\u9ad8\u4eae\u6240\u793a\u7684\u4e00\u4e2a\u5408\u6cd5\u73af\uff1a\n\"\"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1agrid = [["a","b","b"],["b","z","b"],["b","b","a"]]\n\u8f93\u51fa\uff1afalse\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= m <= 500
    • \n\t
    • 1 <= n <= 500
    • \n\t
    • grid \u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    • \n
    \n", "tags_en": ["Depth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool containsCycle(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean containsCycle(char[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def containsCycle(self, grid):\n \"\"\"\n :type grid: List[List[str]]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def containsCycle(self, grid: List[List[str]]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool containsCycle(char** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool ContainsCycle(char[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {character[][]} grid\n * @return {boolean}\n */\nvar containsCycle = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Character[][]} grid\n# @return {Boolean}\ndef contains_cycle(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func containsCycle(_ grid: [[Character]]) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func containsCycle(grid [][]byte) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def containsCycle(grid: Array[Array[Char]]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun containsCycle(grid: Array): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn contains_cycle(grid: Vec>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $grid\n * @return Boolean\n */\n function containsCycle($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function containsCycle(grid: string[][]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (contains-cycle grid)\n (-> (listof (listof char?)) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1559](https://leetcode-cn.com/problems/detect-cycles-in-2d-grid)", "[\u4e8c\u7ef4\u7f51\u683c\u56fe\u4e2d\u63a2\u6d4b\u73af](/solution/1500-1599/1559.Detect%20Cycles%20in%202D%20Grid/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[1559](https://leetcode.com/problems/detect-cycles-in-2d-grid)", "[Detect Cycles in 2D Grid](/solution/1500-1599/1559.Detect%20Cycles%20in%202D%20Grid/README_EN.md)", "`Depth-first Search`", "Hard", ""]}, {"question_id": "1662", "frontend_question_id": "1558", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-numbers-of-function-calls-to-make-target-array", "url_en": "https://leetcode.com/problems/minimum-numbers-of-function-calls-to-make-target-array", "relative_path_cn": "/solution/1500-1599/1558.Minimum%20Numbers%20of%20Function%20Calls%20to%20Make%20Target%20Array/README.md", "relative_path_en": "/solution/1500-1599/1558.Minimum%20Numbers%20of%20Function%20Calls%20to%20Make%20Target%20Array/README_EN.md", "title_cn": "\u5f97\u5230\u76ee\u6807\u6570\u7ec4\u7684\u6700\u5c11\u51fd\u6570\u8c03\u7528\u6b21\u6570", "title_en": "Minimum Numbers of Function Calls to Make Target Array", "question_title_slug": "minimum-numbers-of-function-calls-to-make-target-array", "content_en": "

    \"\"

    \n\n

    Your task is to form an integer array nums from an initial array of zeros arr that is the same size as nums.

    \n\n

    Return the minimum number of function calls to make nums from arr.

    \n\n

    The answer is guaranteed to fit in a 32-bit signed integer.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,5]\nOutput: 5\nExplanation: Increment by 1 (second element): [0, 0] to get [0, 1] (1 operation).\nDouble all the elements: [0, 1] -> [0, 2] -> [0, 4] (2 operations).\nIncrement by 1 (both elements)  [0, 4] -> [1, 4] -> [1, 5] (2 operations).\nTotal of operations: 1 + 2 + 2 = 5.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [2,2]\nOutput: 3\nExplanation: Increment by 1 (both elements) [0, 0] -> [0, 1] -> [1, 1] (2 operations).\nDouble all the elements: [1, 1] -> [2, 2] (1 operation).\nTotal of operations: 2 + 1 = 3.\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [4,2,5]\nOutput: 6\nExplanation: (initial)[0,0,0] -> [1,0,0] -> [1,0,1] -> [2,0,2] -> [2,1,2] -> [4,2,4] -> [4,2,5](nums).\n
    \n\n

    Example 4:

    \n\n
    \nInput: nums = [3,2,2,4]\nOutput: 7\n
    \n\n

    Example 5:

    \n\n
    \nInput: nums = [2,4,8,16]\nOutput: 8\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 10^5
    • \n\t
    • 0 <= nums[i] <= 10^9
    • \n
    \n", "content_cn": "

    \"\"

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u4e0e nums \u5927\u5c0f\u76f8\u540c\u4e14\u521d\u59cb\u503c\u5168\u4e3a 0 \u7684\u6570\u7ec4 arr \uff0c\u8bf7\u4f60\u8c03\u7528\u4ee5\u4e0a\u51fd\u6570\u5f97\u5230\u6574\u6570\u6570\u7ec4 nums \u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u5c06 arr \u53d8\u6210 nums \u7684\u6700\u5c11\u51fd\u6570\u8c03\u7528\u6b21\u6570\u3002

    \n\n

    \u7b54\u6848\u4fdd\u8bc1\u5728 32 \u4f4d\u6709\u7b26\u53f7\u6574\u6570\u4ee5\u5185\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,5]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u7ed9\u7b2c\u4e8c\u4e2a\u6570\u52a0 1 \uff1a[0, 0] \u53d8\u6210 [0, 1] \uff081 \u6b21\u64cd\u4f5c\uff09\u3002\n\u5c06\u6240\u6709\u6570\u5b57\u4e58\u4ee5 2 \uff1a[0, 1] -> [0, 2] -> [0, 4] \uff082 \u6b21\u64cd\u4f5c\uff09\u3002\n\u7ed9\u4e24\u4e2a\u6570\u5b57\u90fd\u52a0 1 \uff1a[0, 4] -> [1, 4] -> [1, 5] \uff082 \u6b21\u64cd\u4f5c\uff09\u3002\n\u603b\u64cd\u4f5c\u6b21\u6570\u4e3a\uff1a1 + 2 + 2 = 5 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [2,2]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u7ed9\u4e24\u4e2a\u6570\u5b57\u90fd\u52a0 1 \uff1a[0, 0] -> [0, 1] -> [1, 1] \uff082 \u6b21\u64cd\u4f5c\uff09\u3002\n\u5c06\u6240\u6709\u6570\u5b57\u4e58\u4ee5 2 \uff1a [1, 1] -> [2, 2] \uff081 \u6b21\u64cd\u4f5c\uff09\u3002\n\u603b\u64cd\u4f5c\u6b21\u6570\u4e3a\uff1a 2 + 1 = 3 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [4,2,5]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\uff08\u521d\u59cb\uff09[0,0,0] -> [1,0,0] -> [1,0,1] -> [2,0,2] -> [2,1,2] -> [4,2,4] -> [4,2,5] \uff08nums \u6570\u7ec4\uff09\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [3,2,2,4]\n\u8f93\u51fa\uff1a7\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [2,4,8,16]\n\u8f93\u51fa\uff1a8\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 10^5
    • \n\t
    • 0 <= nums[i] <= 10^9
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minOperations(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minOperations(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minOperations(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minOperations(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minOperations(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinOperations(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar minOperations = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef min_operations(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minOperations(_ nums: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minOperations(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minOperations(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minOperations(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_operations(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function minOperations($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minOperations(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-operations nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1558](https://leetcode-cn.com/problems/minimum-numbers-of-function-calls-to-make-target-array)", "[\u5f97\u5230\u76ee\u6807\u6570\u7ec4\u7684\u6700\u5c11\u51fd\u6570\u8c03\u7528\u6b21\u6570](/solution/1500-1599/1558.Minimum%20Numbers%20of%20Function%20Calls%20to%20Make%20Target%20Array/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1558](https://leetcode.com/problems/minimum-numbers-of-function-calls-to-make-target-array)", "[Minimum Numbers of Function Calls to Make Target Array](/solution/1500-1599/1558.Minimum%20Numbers%20of%20Function%20Calls%20to%20Make%20Target%20Array/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1661", "frontend_question_id": "1557", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-number-of-vertices-to-reach-all-nodes", "url_en": "https://leetcode.com/problems/minimum-number-of-vertices-to-reach-all-nodes", "relative_path_cn": "/solution/1500-1599/1557.Minimum%20Number%20of%20Vertices%20to%20Reach%20All%20Nodes/README.md", "relative_path_en": "/solution/1500-1599/1557.Minimum%20Number%20of%20Vertices%20to%20Reach%20All%20Nodes/README_EN.md", "title_cn": "\u53ef\u4ee5\u5230\u8fbe\u6240\u6709\u70b9\u7684\u6700\u5c11\u70b9\u6570\u76ee", "title_en": "Minimum Number of Vertices to Reach All Nodes", "question_title_slug": "minimum-number-of-vertices-to-reach-all-nodes", "content_en": "

    Given a directed acyclic graph, with n vertices numbered from 0 to n-1, and an array edges where edges[i] = [fromi, toi] represents a directed edge from node fromi to node toi.

    \r\n\r\n

    Find the smallest set of vertices from which all nodes in the graph are reachable. It's guaranteed that a unique solution exists.

    \r\n\r\n

    Notice that you can return the vertices in any order.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n

    \"\"

    \r\n\r\n
    \r\nInput: n = 6, edges = [[0,1],[0,2],[2,5],[3,4],[4,2]]\r\nOutput: [0,3]\r\nExplanation: It's not possible to reach all the nodes from a single vertex. From 0 we can reach [0,1,2,5]. From 3 we can reach [3,4,2,5]. So we output [0,3].
    \r\n\r\n

    Example 2:

    \r\n\r\n

    \"\"

    \r\n\r\n
    \r\nInput: n = 5, edges = [[0,1],[2,1],[3,1],[1,4],[2,4]]\r\nOutput: [0,2,3]\r\nExplanation: Notice that vertices 0, 3 and 2 are not reachable from any other node, so we must include them. Also any of these vertices can reach nodes 1 and 4.\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 2 <= n <= 10^5
    • \r\n\t
    • 1 <= edges.length <= min(10^5, n * (n - 1) / 2)
    • \r\n\t
    • edges[i].length == 2
    • \r\n\t
    • 0 <= fromi, toi < n
    • \r\n\t
    • All pairs (fromi, toi) are distinct.
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a \u6709\u5411\u65e0\u73af\u56fe \uff0c n \u4e2a\u8282\u70b9\u7f16\u53f7\u4e3a 0 \u5230 n-1 \uff0c\u4ee5\u53ca\u4e00\u4e2a\u8fb9\u6570\u7ec4 edges \uff0c\u5176\u4e2d edges[i] = [fromi, toi] \u8868\u793a\u4e00\u6761\u4ece\u70b9  fromi \u5230\u70b9 toi \u7684\u6709\u5411\u8fb9\u3002

    \n\n

    \u627e\u5230\u6700\u5c0f\u7684\u70b9\u96c6\u4f7f\u5f97\u4ece\u8fd9\u4e9b\u70b9\u51fa\u53d1\u80fd\u5230\u8fbe\u56fe\u4e2d\u6240\u6709\u70b9\u3002\u9898\u76ee\u4fdd\u8bc1\u89e3\u5b58\u5728\u4e14\u552f\u4e00\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u4ee5\u4efb\u610f\u987a\u5e8f\u8fd4\u56de\u8fd9\u4e9b\u8282\u70b9\u7f16\u53f7\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 6, edges = [[0,1],[0,2],[2,5],[3,4],[4,2]]\n\u8f93\u51fa\uff1a[0,3]\n\u89e3\u91ca\uff1a\u4ece\u5355\u4e2a\u8282\u70b9\u51fa\u53d1\u65e0\u6cd5\u5230\u8fbe\u6240\u6709\u8282\u70b9\u3002\u4ece 0 \u51fa\u53d1\u6211\u4eec\u53ef\u4ee5\u5230\u8fbe [0,1,2,5] \u3002\u4ece 3 \u51fa\u53d1\u6211\u4eec\u53ef\u4ee5\u5230\u8fbe [3,4,2,5] \u3002\u6240\u4ee5\u6211\u4eec\u8f93\u51fa [0,3] \u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 5, edges = [[0,1],[2,1],[3,1],[1,4],[2,4]]\n\u8f93\u51fa\uff1a[0,2,3]\n\u89e3\u91ca\uff1a\u6ce8\u610f\u5230\u8282\u70b9 0\uff0c3 \u548c 2 \u65e0\u6cd5\u4ece\u5176\u4ed6\u8282\u70b9\u5230\u8fbe\uff0c\u6240\u4ee5\u6211\u4eec\u5fc5\u987b\u5c06\u5b83\u4eec\u5305\u542b\u5728\u7ed3\u679c\u70b9\u96c6\u4e2d\uff0c\u8fd9\u4e9b\u70b9\u90fd\u80fd\u5230\u8fbe\u8282\u70b9 1 \u548c 4 \u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= n <= 10^5
    • \n\t
    • 1 <= edges.length <= min(10^5, n * (n - 1) / 2)
    • \n\t
    • edges[i].length == 2
    • \n\t
    • 0 <= fromi, toi < n
    • \n\t
    • \u6240\u6709\u70b9\u5bf9 (fromi, toi) \u4e92\u4e0d\u76f8\u540c\u3002
    • \n
    \n", "tags_en": ["Graph"], "tags_cn": ["\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findSmallestSetOfVertices(int n, vector>& edges) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List findSmallestSetOfVertices(int n, List> edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findSmallestSetOfVertices(self, n, edges):\n \"\"\"\n :type n: int\n :type edges: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findSmallestSetOfVertices(self, n: int, edges: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* findSmallestSetOfVertices(int n, int** edges, int edgesSize, int* edgesColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList FindSmallestSetOfVertices(int n, IList> edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} edges\n * @return {number[]}\n */\nvar findSmallestSetOfVertices = function(n, edges) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} edges\n# @return {Integer[]}\ndef find_smallest_set_of_vertices(n, edges)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findSmallestSetOfVertices(_ n: Int, _ edges: [[Int]]) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findSmallestSetOfVertices(n int, edges [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findSmallestSetOfVertices(n: Int, edges: List[List[Int]]): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findSmallestSetOfVertices(n: Int, edges: List>): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_smallest_set_of_vertices(n: i32, edges: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $edges\n * @return Integer[]\n */\n function findSmallestSetOfVertices($n, $edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findSmallestSetOfVertices(n: number, edges: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-smallest-set-of-vertices n edges)\n (-> exact-integer? (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1557](https://leetcode-cn.com/problems/minimum-number-of-vertices-to-reach-all-nodes)", "[\u53ef\u4ee5\u5230\u8fbe\u6240\u6709\u70b9\u7684\u6700\u5c11\u70b9\u6570\u76ee](/solution/1500-1599/1557.Minimum%20Number%20of%20Vertices%20to%20Reach%20All%20Nodes/README.md)", "`\u56fe`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1557](https://leetcode.com/problems/minimum-number-of-vertices-to-reach-all-nodes)", "[Minimum Number of Vertices to Reach All Nodes](/solution/1500-1599/1557.Minimum%20Number%20of%20Vertices%20to%20Reach%20All%20Nodes/README_EN.md)", "`Graph`", "Medium", ""]}, {"question_id": "1660", "frontend_question_id": "1556", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/thousand-separator", "url_en": "https://leetcode.com/problems/thousand-separator", "relative_path_cn": "/solution/1500-1599/1556.Thousand%20Separator/README.md", "relative_path_en": "/solution/1500-1599/1556.Thousand%20Separator/README_EN.md", "title_cn": "\u5343\u4f4d\u5206\u9694\u6570", "title_en": "Thousand Separator", "question_title_slug": "thousand-separator", "content_en": "

    Given an integer n, add a dot (".") as the thousands separator and return it in string format.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 987\nOutput: "987"\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 1234\nOutput: "1.234"\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 123456789\nOutput: "123.456.789"\n
    \n\n

    Example 4:

    \n\n
    \nInput: n = 0\nOutput: "0"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= n < 2^31
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n\uff0c\u8bf7\u4f60\u6bcf\u9694\u4e09\u4f4d\u6dfb\u52a0\u70b9\uff08\u5373 "." \u7b26\u53f7\uff09\u4f5c\u4e3a\u5343\u4f4d\u5206\u9694\u7b26\uff0c\u5e76\u5c06\u7ed3\u679c\u4ee5\u5b57\u7b26\u4e32\u683c\u5f0f\u8fd4\u56de\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1an = 987\n\u8f93\u51fa\uff1a"987"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1an = 1234\n\u8f93\u51fa\uff1a"1.234"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1an = 123456789\n\u8f93\u51fa\uff1a"123.456.789"\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1an = 0\n\u8f93\u51fa\uff1a"0"\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= n < 2^31
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string thousandSeparator(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String thousandSeparator(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def thousandSeparator(self, n):\n \"\"\"\n :type n: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def thousandSeparator(self, n: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * thousandSeparator(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ThousandSeparator(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {string}\n */\nvar thousandSeparator = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {String}\ndef thousand_separator(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func thousandSeparator(_ n: Int) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func thousandSeparator(n int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def thousandSeparator(n: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun thousandSeparator(n: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn thousand_separator(n: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return String\n */\n function thousandSeparator($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function thousandSeparator(n: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (thousand-separator n)\n (-> exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1556](https://leetcode-cn.com/problems/thousand-separator)", "[\u5343\u4f4d\u5206\u9694\u6570](/solution/1500-1599/1556.Thousand%20Separator/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1556](https://leetcode.com/problems/thousand-separator)", "[Thousand Separator](/solution/1500-1599/1556.Thousand%20Separator/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1659", "frontend_question_id": "1537", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/get-the-maximum-score", "url_en": "https://leetcode.com/problems/get-the-maximum-score", "relative_path_cn": "/solution/1500-1599/1537.Get%20the%20Maximum%20Score/README.md", "relative_path_en": "/solution/1500-1599/1537.Get%20the%20Maximum%20Score/README_EN.md", "title_cn": "\u6700\u5927\u5f97\u5206", "title_en": "Get the Maximum Score", "question_title_slug": "get-the-maximum-score", "content_en": "

    You are given two sorted arrays of distinct integers nums1 and nums2.

    \n\n

    A valid path is defined as follows:

    \n\n
      \n\t
    • Choose array nums1 or nums2 to traverse (from index-0).
    • \n\t
    • Traverse the current array from left to right.
    • \n\t
    • If you are reading any value that is present in nums1 and nums2 you are allowed to change your path to the other array. (Only one repeated value is considered in the valid path).
    • \n
    \n\n

    Score is defined as the sum of uniques values in a valid path.

    \n\n

    Return the maximum score you can obtain of all possible valid paths.

    \n\n

    Since the answer may be too large, return it modulo 10^9 + 7.

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: nums1 = [2,4,5,8,10], nums2 = [4,6,8,9]\nOutput: 30\nExplanation: Valid paths:\n[2,4,5,8,10], [2,4,5,8,9], [2,4,6,8,9], [2,4,6,8,10],  (starting from nums1)\n[4,6,8,9], [4,5,8,10], [4,5,8,9], [4,6,8,10]    (starting from nums2)\nThe maximum is obtained with the path in green [2,4,6,8,10].\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums1 = [1,3,5,7,9], nums2 = [3,5,100]\nOutput: 109\nExplanation: Maximum sum is obtained with the path [1,3,5,100].\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums1 = [1,2,3,4,5], nums2 = [6,7,8,9,10]\nOutput: 40\nExplanation: There are no common elements between nums1 and nums2.\nMaximum sum is obtained with the path [6,7,8,9,10].\n
    \n\n

    Example 4:

    \n\n
    \nInput: nums1 = [1,4,5,8,9,11,19], nums2 = [2,3,4,11,12]\nOutput: 61\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums1.length <= 10^5
    • \n\t
    • 1 <= nums2.length <= 10^5
    • \n\t
    • 1 <= nums1[i], nums2[i] <= 10^7
    • \n\t
    • nums1 and nums2 are strictly increasing.
    • \n
    \n", "content_cn": "

    \u4f60\u6709\u4e24\u4e2a \u6709\u5e8f \u4e14\u6570\u7ec4\u5185\u5143\u7d20\u4e92\u4e0d\u76f8\u540c\u7684\u6570\u7ec4 nums1 \u548c nums2 \u3002

    \n\n

    \u4e00\u6761 \u5408\u6cd5\u8def\u5f84 \u5b9a\u4e49\u5982\u4e0b\uff1a

    \n\n
      \n\t
    • \u9009\u62e9\u6570\u7ec4 nums1 \u6216\u8005 nums2 \u5f00\u59cb\u904d\u5386\uff08\u4ece\u4e0b\u6807 0 \u5904\u5f00\u59cb\uff09\u3002
    • \n\t
    • \u4ece\u5de6\u5230\u53f3\u904d\u5386\u5f53\u524d\u6570\u7ec4\u3002
    • \n\t
    • \u5982\u679c\u4f60\u9047\u5230\u4e86 nums1 \u548c nums2 \u4e2d\u90fd\u5b58\u5728\u7684\u503c\uff0c\u90a3\u4e48\u4f60\u53ef\u4ee5\u5207\u6362\u8def\u5f84\u5230\u53e6\u4e00\u4e2a\u6570\u7ec4\u5bf9\u5e94\u6570\u5b57\u5904\u7ee7\u7eed\u904d\u5386\uff08\u4f46\u5728\u5408\u6cd5\u8def\u5f84\u4e2d\u91cd\u590d\u6570\u5b57\u53ea\u4f1a\u88ab\u7edf\u8ba1\u4e00\u6b21\uff09\u3002
    • \n
    \n\n

    \u5f97\u5206\u5b9a\u4e49\u4e3a\u5408\u6cd5\u8def\u5f84\u4e2d\u4e0d\u540c\u6570\u5b57\u7684\u548c\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u6240\u6709\u53ef\u80fd\u5408\u6cd5\u8def\u5f84\u4e2d\u7684\u6700\u5927\u5f97\u5206\u3002

    \n\n

    \u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u5f88\u5927\uff0c\u8bf7\u4f60\u5c06\u5b83\u5bf9 10^9 + 7 \u53d6\u4f59\u540e\u8fd4\u56de\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1anums1 = [2,4,5,8,10], nums2 = [4,6,8,9]\n\u8f93\u51fa\uff1a30\n\u89e3\u91ca\uff1a\u5408\u6cd5\u8def\u5f84\u5305\u62ec\uff1a\n[2,4,5,8,10], [2,4,5,8,9], [2,4,6,8,9], [2,4,6,8,10],\uff08\u4ece nums1 \u5f00\u59cb\u904d\u5386\uff09\n[4,6,8,9], [4,5,8,10], [4,5,8,9], [4,6,8,10]  \uff08\u4ece nums2 \u5f00\u59cb\u904d\u5386\uff09\n\u6700\u5927\u5f97\u5206\u4e3a\u4e0a\u56fe\u4e2d\u7684\u7eff\u8272\u8def\u5f84 [2,4,6,8,10] \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anums1 = [1,3,5,7,9], nums2 = [3,5,100]\n\u8f93\u51fa\uff1a109\n\u89e3\u91ca\uff1a\u6700\u5927\u5f97\u5206\u7531\u8def\u5f84 [1,3,5,100] \u5f97\u5230\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1anums1 = [1,2,3,4,5], nums2 = [6,7,8,9,10]\n\u8f93\u51fa\uff1a40\n\u89e3\u91ca\uff1anums1 \u548c nums2 \u4e4b\u95f4\u65e0\u76f8\u540c\u6570\u5b57\u3002\n\u6700\u5927\u5f97\u5206\u7531\u8def\u5f84 [6,7,8,9,10] \u5f97\u5230\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1anums1 = [1,4,5,8,9,11,19], nums2 = [2,3,4,11,12]\n\u8f93\u51fa\uff1a61\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums1.length <= 10^5
    • \n\t
    • 1 <= nums2.length <= 10^5
    • \n\t
    • 1 <= nums1[i], nums2[i] <= 10^7
    • \n\t
    • nums1 \u548c nums2 \u90fd\u662f\u4e25\u683c\u9012\u589e\u7684\u6570\u7ec4\u3002
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxSum(vector& nums1, vector& nums2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxSum(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxSum(self, nums1, nums2):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxSum(self, nums1: List[int], nums2: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxSum(int* nums1, int nums1Size, int* nums2, int nums2Size){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxSum(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums1\n * @param {number[]} nums2\n * @return {number}\n */\nvar maxSum = function(nums1, nums2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums1\n# @param {Integer[]} nums2\n# @return {Integer}\ndef max_sum(nums1, nums2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxSum(_ nums1: [Int], _ nums2: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxSum(nums1 []int, nums2 []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxSum(nums1: Array[Int], nums2: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxSum(nums1: IntArray, nums2: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_sum(nums1: Vec, nums2: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums1\n * @param Integer[] $nums2\n * @return Integer\n */\n function maxSum($nums1, $nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxSum(nums1: number[], nums2: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-sum nums1 nums2)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1537](https://leetcode-cn.com/problems/get-the-maximum-score)", "[\u6700\u5927\u5f97\u5206](/solution/1500-1599/1537.Get%20the%20Maximum%20Score/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1537](https://leetcode.com/problems/get-the-maximum-score)", "[Get the Maximum Score](/solution/1500-1599/1537.Get%20the%20Maximum%20Score/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1658", "frontend_question_id": "1536", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-swaps-to-arrange-a-binary-grid", "url_en": "https://leetcode.com/problems/minimum-swaps-to-arrange-a-binary-grid", "relative_path_cn": "/solution/1500-1599/1536.Minimum%20Swaps%20to%20Arrange%20a%20Binary%20Grid/README.md", "relative_path_en": "/solution/1500-1599/1536.Minimum%20Swaps%20to%20Arrange%20a%20Binary%20Grid/README_EN.md", "title_cn": "\u6392\u5e03\u4e8c\u8fdb\u5236\u7f51\u683c\u7684\u6700\u5c11\u4ea4\u6362\u6b21\u6570", "title_en": "Minimum Swaps to Arrange a Binary Grid", "question_title_slug": "minimum-swaps-to-arrange-a-binary-grid", "content_en": "

    Given an n x n binary grid, in one step you can choose two adjacent rows of the grid and swap them.

    \n\n

    A grid is said to be valid if all the cells above the main diagonal are zeros.

    \n\n

    Return the minimum number of steps needed to make the grid valid, or -1 if the grid cannot be valid.

    \n\n

    The main diagonal of a grid is the diagonal that starts at cell (1, 1) and ends at cell (n, n).

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: grid = [[0,0,1],[1,1,0],[1,0,0]]\nOutput: 3\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: grid = [[0,1,1,0],[0,1,1,0],[0,1,1,0],[0,1,1,0]]\nOutput: -1\nExplanation: All rows are similar, swaps have no effect on the grid.\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: grid = [[1,0,0],[1,1,0],[1,1,1]]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= n <= 200
    • \n\t
    • grid[i][j] is 0 or 1
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a n x n \u7684\u4e8c\u8fdb\u5236\u7f51\u683c grid\uff0c\u6bcf\u4e00\u6b21\u64cd\u4f5c\u4e2d\uff0c\u4f60\u53ef\u4ee5\u9009\u62e9\u7f51\u683c\u7684 \u76f8\u90bb\u4e24\u884c \u8fdb\u884c\u4ea4\u6362\u3002

    \n\n

    \u4e00\u4e2a\u7b26\u5408\u8981\u6c42\u7684\u7f51\u683c\u9700\u8981\u6ee1\u8db3\u4e3b\u5bf9\u89d2\u7ebf\u4ee5\u4e0a\u7684\u683c\u5b50\u5168\u90e8\u90fd\u662f 0 \u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u4f7f\u7f51\u683c\u6ee1\u8db3\u8981\u6c42\u7684\u6700\u5c11\u64cd\u4f5c\u6b21\u6570\uff0c\u5982\u679c\u65e0\u6cd5\u4f7f\u7f51\u683c\u7b26\u5408\u8981\u6c42\uff0c\u8bf7\u4f60\u8fd4\u56de -1 \u3002

    \n\n

    \u4e3b\u5bf9\u89d2\u7ebf\u6307\u7684\u662f\u4ece (1, 1) \u5230 (n, n) \u7684\u8fd9\u4e9b\u683c\u5b50\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1agrid = [[0,0,1],[1,1,0],[1,0,0]]\n\u8f93\u51fa\uff1a3\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1agrid = [[0,1,1,0],[0,1,1,0],[0,1,1,0],[0,1,1,0]]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u6240\u6709\u884c\u90fd\u662f\u4e00\u6837\u7684\uff0c\u4ea4\u6362\u76f8\u90bb\u884c\u65e0\u6cd5\u4f7f\u7f51\u683c\u7b26\u5408\u8981\u6c42\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1agrid = [[1,0,0],[1,1,0],[1,1,1]]\n\u8f93\u51fa\uff1a0\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= n <= 200
    • \n\t
    • grid[i][j] \u8981\u4e48\u662f 0 \u8981\u4e48\u662f 1 \u3002
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minSwaps(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minSwaps(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minSwaps(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minSwaps(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minSwaps(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinSwaps(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar minSwaps = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef min_swaps(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minSwaps(_ grid: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minSwaps(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minSwaps(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minSwaps(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_swaps(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function minSwaps($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minSwaps(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-swaps grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1536](https://leetcode-cn.com/problems/minimum-swaps-to-arrange-a-binary-grid)", "[\u6392\u5e03\u4e8c\u8fdb\u5236\u7f51\u683c\u7684\u6700\u5c11\u4ea4\u6362\u6b21\u6570](/solution/1500-1599/1536.Minimum%20Swaps%20to%20Arrange%20a%20Binary%20Grid/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1536](https://leetcode.com/problems/minimum-swaps-to-arrange-a-binary-grid)", "[Minimum Swaps to Arrange a Binary Grid](/solution/1500-1599/1536.Minimum%20Swaps%20to%20Arrange%20a%20Binary%20Grid/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1657", "frontend_question_id": "1535", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-the-winner-of-an-array-game", "url_en": "https://leetcode.com/problems/find-the-winner-of-an-array-game", "relative_path_cn": "/solution/1500-1599/1535.Find%20the%20Winner%20of%20an%20Array%20Game/README.md", "relative_path_en": "/solution/1500-1599/1535.Find%20the%20Winner%20of%20an%20Array%20Game/README_EN.md", "title_cn": "\u627e\u51fa\u6570\u7ec4\u6e38\u620f\u7684\u8d62\u5bb6", "title_en": "Find the Winner of an Array Game", "question_title_slug": "find-the-winner-of-an-array-game", "content_en": "

    Given an integer array arr of distinct integers and an integer k.

    \r\n\r\n

    A game will be played between the first two elements of the array (i.e. arr[0] and arr[1]). In each round of the game, we compare arr[0] with arr[1], the larger integer wins and remains at position 0 and the smaller integer moves to the end of the array. The game ends when an integer wins k consecutive rounds.

    \r\n\r\n

    Return the integer which will win the game.

    \r\n\r\n

    It is guaranteed that there will be a winner of the game.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: arr = [2,1,3,5,4,6,7], k = 2\r\nOutput: 5\r\nExplanation: Let's see the rounds of the game:\r\nRound |       arr       | winner | win_count\r\n  1   | [2,1,3,5,4,6,7] | 2      | 1\r\n  2   | [2,3,5,4,6,7,1] | 3      | 1\r\n  3   | [3,5,4,6,7,1,2] | 5      | 1\r\n  4   | [5,4,6,7,1,2,3] | 5      | 2\r\nSo we can see that 4 rounds will be played and 5 is the winner because it wins 2 consecutive games.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: arr = [3,2,1], k = 10\r\nOutput: 3\r\nExplanation: 3 will win the first 10 rounds consecutively.\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: arr = [1,9,8,2,3,7,6,4,5], k = 7\r\nOutput: 9\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: arr = [1,11,22,33,44,55,66,77,88,99], k = 1000000000\r\nOutput: 99\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 2 <= arr.length <= 10^5
    • \r\n\t
    • 1 <= arr[i] <= 10^6
    • \r\n\t
    • arr contains distinct integers.
    • \r\n\t
    • 1 <= k <= 10^9
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u7531 \u4e0d\u540c \u6574\u6570\u7ec4\u6210\u7684\u6574\u6570\u6570\u7ec4 arr \u548c\u4e00\u4e2a\u6574\u6570 k \u3002

    \n\n

    \u6bcf\u56de\u5408\u6e38\u620f\u90fd\u5728\u6570\u7ec4\u7684\u524d\u4e24\u4e2a\u5143\u7d20\uff08\u5373 arr[0] \u548c arr[1] \uff09\u4e4b\u95f4\u8fdb\u884c\u3002\u6bd4\u8f83 arr[0] \u4e0e arr[1] \u7684\u5927\u5c0f\uff0c\u8f83\u5927\u7684\u6574\u6570\u5c06\u4f1a\u53d6\u5f97\u8fd9\u4e00\u56de\u5408\u7684\u80dc\u5229\u5e76\u4fdd\u7559\u5728\u4f4d\u7f6e 0 \uff0c\u8f83\u5c0f\u7684\u6574\u6570\u79fb\u81f3\u6570\u7ec4\u7684\u672b\u5c3e\u3002\u5f53\u4e00\u4e2a\u6574\u6570\u8d62\u5f97 k \u4e2a\u8fde\u7eed\u56de\u5408\u65f6\uff0c\u6e38\u620f\u7ed3\u675f\uff0c\u8be5\u6574\u6570\u5c31\u662f\u6bd4\u8d5b\u7684 \u8d62\u5bb6 \u3002

    \n\n

    \u8fd4\u56de\u8d62\u5f97\u6bd4\u8d5b\u7684\u6574\u6570\u3002

    \n\n

    \u9898\u76ee\u6570\u636e \u4fdd\u8bc1 \u6e38\u620f\u5b58\u5728\u8d62\u5bb6\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [2,1,3,5,4,6,7], k = 2\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u4e00\u8d77\u770b\u4e00\u4e0b\u672c\u573a\u6e38\u620f\u6bcf\u56de\u5408\u7684\u60c5\u51b5\uff1a\n\"\"\n\u56e0\u6b64\u5c06\u8fdb\u884c 4 \u56de\u5408\u6bd4\u8d5b\uff0c\u5176\u4e2d 5 \u662f\u8d62\u5bb6\uff0c\u56e0\u4e3a\u5b83\u8fde\u80dc 2 \u56de\u5408\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [3,2,1], k = 10\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a3 \u5c06\u4f1a\u5728\u524d 10 \u4e2a\u56de\u5408\u4e2d\u8fde\u7eed\u83b7\u80dc\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [1,9,8,2,3,7,6,4,5], k = 7\n\u8f93\u51fa\uff1a9\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [1,11,22,33,44,55,66,77,88,99], k = 1000000000\n\u8f93\u51fa\uff1a99\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= arr.length <= 10^5
    • \n\t
    • 1 <= arr[i] <= 10^6
    • \n\t
    • arr \u6240\u542b\u7684\u6574\u6570 \u5404\u4e0d\u76f8\u540c \u3002
    • \n\t
    • 1 <= k <= 10^9
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int getWinner(vector& arr, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int getWinner(int[] arr, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getWinner(self, arr, k):\n \"\"\"\n :type arr: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getWinner(self, arr: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint getWinner(int* arr, int arrSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int GetWinner(int[] arr, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @param {number} k\n * @return {number}\n */\nvar getWinner = function(arr, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @param {Integer} k\n# @return {Integer}\ndef get_winner(arr, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getWinner(_ arr: [Int], _ k: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getWinner(arr []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getWinner(arr: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getWinner(arr: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_winner(arr: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @param Integer $k\n * @return Integer\n */\n function getWinner($arr, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getWinner(arr: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-winner arr k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1535](https://leetcode-cn.com/problems/find-the-winner-of-an-array-game)", "[\u627e\u51fa\u6570\u7ec4\u6e38\u620f\u7684\u8d62\u5bb6](/solution/1500-1599/1535.Find%20the%20Winner%20of%20an%20Array%20Game/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1535](https://leetcode.com/problems/find-the-winner-of-an-array-game)", "[Find the Winner of an Array Game](/solution/1500-1599/1535.Find%20the%20Winner%20of%20an%20Array%20Game/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "1656", "frontend_question_id": "1534", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-good-triplets", "url_en": "https://leetcode.com/problems/count-good-triplets", "relative_path_cn": "/solution/1500-1599/1534.Count%20Good%20Triplets/README.md", "relative_path_en": "/solution/1500-1599/1534.Count%20Good%20Triplets/README_EN.md", "title_cn": "\u7edf\u8ba1\u597d\u4e09\u5143\u7ec4", "title_en": "Count Good Triplets", "question_title_slug": "count-good-triplets", "content_en": "

    Given an array of integers arr, and three integers ab and c. You need to find the number of good triplets.

    \r\n\r\n

    A triplet (arr[i], arr[j], arr[k]) is good if the following conditions are true:

    \r\n\r\n
      \r\n\t
    • 0 <= i < j < k < arr.length
    • \r\n\t
    • |arr[i] - arr[j]| <= a
    • \r\n\t
    • |arr[j] - arr[k]| <= b
    • \r\n\t
    • |arr[i] - arr[k]| <= c
    • \r\n
    \r\n\r\n

    Where |x| denotes the absolute value of x.

    \r\n\r\n

    Return the number of good triplets.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: arr = [3,0,1,1,9,7], a = 7, b = 2, c = 3\r\nOutput: 4\r\nExplanation: There are 4 good triplets: [(3,0,1), (3,0,1), (3,1,1), (0,1,1)].\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: arr = [1,1,2,2,3], a = 0, b = 0, c = 1\r\nOutput: 0\r\nExplanation: No triplet satisfies all conditions.\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 3 <= arr.length <= 100
    • \r\n\t
    • 0 <= arr[i] <= 1000
    • \r\n\t
    • 0 <= a, b, c <= 1000
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr \uff0c\u4ee5\u53ca a\u3001b \u3001c \u4e09\u4e2a\u6574\u6570\u3002\u8bf7\u4f60\u7edf\u8ba1\u5176\u4e2d\u597d\u4e09\u5143\u7ec4\u7684\u6570\u91cf\u3002

    \n\n

    \u5982\u679c\u4e09\u5143\u7ec4 (arr[i], arr[j], arr[k]) \u6ee1\u8db3\u4e0b\u5217\u5168\u90e8\u6761\u4ef6\uff0c\u5219\u8ba4\u4e3a\u5b83\u662f\u4e00\u4e2a \u597d\u4e09\u5143\u7ec4 \u3002

    \n\n
      \n\t
    • 0 <= i < j < k < arr.length
    • \n\t
    • |arr[i] - arr[j]| <= a
    • \n\t
    • |arr[j] - arr[k]| <= b
    • \n\t
    • |arr[i] - arr[k]| <= c
    • \n
    \n\n

    \u5176\u4e2d |x| \u8868\u793a x \u7684\u7edd\u5bf9\u503c\u3002

    \n\n

    \u8fd4\u56de \u597d\u4e09\u5143\u7ec4\u7684\u6570\u91cf \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [3,0,1,1,9,7], a = 7, b = 2, c = 3\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u4e00\u5171\u6709 4 \u4e2a\u597d\u4e09\u5143\u7ec4\uff1a[(3,0,1), (3,0,1), (3,1,1), (0,1,1)] \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [1,1,2,2,3], a = 0, b = 0, c = 1\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u4e0d\u5b58\u5728\u6ee1\u8db3\u6240\u6709\u6761\u4ef6\u7684\u4e09\u5143\u7ec4\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 3 <= arr.length <= 100
    • \n\t
    • 0 <= arr[i] <= 1000
    • \n\t
    • 0 <= a, b, c <= 1000
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countGoodTriplets(vector& arr, int a, int b, int c) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countGoodTriplets(int[] arr, int a, int b, int c) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countGoodTriplets(self, arr, a, b, c):\n \"\"\"\n :type arr: List[int]\n :type a: int\n :type b: int\n :type c: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countGoodTriplets(self, arr: List[int], a: int, b: int, c: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countGoodTriplets(int* arr, int arrSize, int a, int b, int c){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountGoodTriplets(int[] arr, int a, int b, int c) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @param {number} a\n * @param {number} b\n * @param {number} c\n * @return {number}\n */\nvar countGoodTriplets = function(arr, a, b, c) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @param {Integer} a\n# @param {Integer} b\n# @param {Integer} c\n# @return {Integer}\ndef count_good_triplets(arr, a, b, c)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countGoodTriplets(_ arr: [Int], _ a: Int, _ b: Int, _ c: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countGoodTriplets(arr []int, a int, b int, c int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countGoodTriplets(arr: Array[Int], a: Int, b: Int, c: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countGoodTriplets(arr: IntArray, a: Int, b: Int, c: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_good_triplets(arr: Vec, a: i32, b: i32, c: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @param Integer $a\n * @param Integer $b\n * @param Integer $c\n * @return Integer\n */\n function countGoodTriplets($arr, $a, $b, $c) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countGoodTriplets(arr: number[], a: number, b: number, c: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-good-triplets arr a b c)\n (-> (listof exact-integer?) exact-integer? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1534](https://leetcode-cn.com/problems/count-good-triplets)", "[\u7edf\u8ba1\u597d\u4e09\u5143\u7ec4](/solution/1500-1599/1534.Count%20Good%20Triplets/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1534](https://leetcode.com/problems/count-good-triplets)", "[Count Good Triplets](/solution/1500-1599/1534.Count%20Good%20Triplets/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1655", "frontend_question_id": "1516", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/move-sub-tree-of-n-ary-tree", "url_en": "https://leetcode.com/problems/move-sub-tree-of-n-ary-tree", "relative_path_cn": "/solution/1500-1599/1516.Move%20Sub-Tree%20of%20N-Ary%20Tree/README.md", "relative_path_en": "/solution/1500-1599/1516.Move%20Sub-Tree%20of%20N-Ary%20Tree/README_EN.md", "title_cn": "\u79fb\u52a8 N \u53c9\u6811\u7684\u5b50\u6811", "title_en": "Move Sub-Tree of N-Ary Tree", "question_title_slug": "move-sub-tree-of-n-ary-tree", "content_en": "

    Given the root of an N-ary tree of unique values, and two nodes of the tree p and q.

    \n\n

    You should move the subtree of the node p to become a direct child of node q. If p is already a direct child of q, don't change anything. Node p must be the last child in the children list of node q.

    \n\n

    Return the root of the tree after adjusting it.

    \n\n

     

    \n\n

    There are 3 cases for nodes p and q:

    \n\n
      \n\t
    1. Node q is in the sub-tree of node p.
    2. \n\t
    3. Node p is in the sub-tree of node q.
    4. \n\t
    5. Neither node p is in the sub-tree of node q nor node q is in the sub-tree of node p.
    6. \n
    \n\n

    In cases 2 and 3, you just need to move p (with its sub-tree) to be a child of q, but in case 1 the tree may be disconnected, thus you need to reconnect the tree again. Please read the examples carefully before solving this problem.

    \n\n

     

    \n\n

    Nary-Tree input serialization is represented in their level order traversal, each group of children is separated by the null value (See examples).

    \n\n

    \"\"

    \n\n

    For example, the above tree is serialized as [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14].

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,null,2,3,null,4,5,null,6,null,7,8], p = 4, q = 1\nOutput: [1,null,2,3,4,null,5,null,6,null,7,8]\nExplanation: This example follows the second case as node p is in the sub-tree of node q. We move node p with its sub-tree to be a direct child of node q.\nNotice that node 4 is the last child of node 1.
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [1,null,2,3,null,4,5,null,6,null,7,8], p = 7, q = 4\nOutput: [1,null,2,3,null,4,5,null,6,null,7,8]\nExplanation: Node 7 is already a direct child of node 4. We don't change anything.\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: root = [1,null,2,3,null,4,5,null,6,null,7,8], p = 3, q = 8\nOutput: [1,null,2,null,4,5,null,7,8,null,null,null,3,null,6]\nExplanation: This example follows case 3 because node p is not in the sub-tree of node q and vice-versa. We can move node 3 with its sub-tree and make it as node 8's child.\n
    \n\n

    Example 4:

    \n\"\"\n
    \nInput: root = [1,null,2,3,null,4,5,null,6,null,7,8], p = 2, q = 7\nOutput: [1,null,7,3,null,2,null,6,null,4,5,null,null,8]\nExplanation: Node q is in the sub-tree of node p, so this is case 1.\nThe first step, we move node p (with all of its sub-tree except for node q) and add it as a child to node q.\nThen we will see that the tree is disconnected, you need to reconnect node q to replace node p as shown.\n
    \n\n

    Example 5:

    \n\"\"\n
    \nInput: root = [1,null,2,3,null,4,5,null,6,null,7,8], p = 1, q = 2\nOutput: [2,null,4,5,1,null,7,8,null,null,3,null,null,null,6]\nExplanation: Node q is in the sub-tree of node p, so this is case 1.\nThe first step, we move node p (with all of its sub-tree except for node q) and add it as a child to node q.\nAs node p was the root of the tree, node q replaces it and becomes the root of the tree.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The total number of nodes is between [2, 1000].
    • \n\t
    • Each node has a unique value.
    • \n\t
    • p != null
    • \n\t
    • q != null
    • \n\t
    • p and q are two different nodes (i.e. p != q).
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u68f5\u6ca1\u6709\u91cd\u590d\u503c\u7684 N \u53c9\u6811\u7684\u6839\u8282\u70b9 root \uff0c\u4ee5\u53ca\u5176\u4e2d\u7684\u4e24\u4e2a\u8282\u70b9 p \u548c q\u3002

    \n\n

    \u79fb\u52a8\u8282\u70b9 p \u53ca\u5176\u5b50\u6811\uff0c\u4f7f\u8282\u70b9 p \u6210\u4e3a\u8282\u70b9 q \u7684\u76f4\u63a5\u5b50\u8282\u70b9\u3002\u5982\u679c p \u5df2\u7ecf\u662f q \u7684\u76f4\u63a5\u5b50\u8282\u70b9\uff0c\u5219\u8bf7\u52ff\u6539\u52a8\u4efb\u4f55\u8282\u70b9\u3002\u8282\u70b9 p \u5fc5\u987b\u662f\u8282\u70b9 q \u7684\u5b50\u8282\u70b9\u5217\u8868\u7684\u6700\u540e\u4e00\u9879\u3002

    \n\n

    \u8fd4\u56de\u6539\u52a8\u540e\u7684\u6811\u7684\u6839\u8282\u70b9\u3002

    \n\n

     

    \n\n

    \u8282\u70b9 p \u548c q \u53ef\u80fd\u662f\u4e0b\u5217\u4e09\u79cd\u60c5\u51b5\u4e4b\u4e00\uff1a

    \n\n
      \n\t
    1. \u8282\u70b9 q \u5728\u8282\u70b9 p \u7684\u5b50\u6811\u4e2d\u3002
    2. \n\t
    3. \u8282\u70b9 p \u5728\u8282\u70b9 q \u7684\u5b50\u6811\u4e2d\u3002
    4. \n\t
    5. \u8282\u70b9 p \u4e0d\u5728\u8282\u70b9 q \u7684\u5b50\u6811\u4e2d\uff0c\u4e14\u8282\u70b9 q \u4e5f\u4e0d\u5728\u8282\u70b9 p \u7684\u5b50\u6811\u4e2d\u3002
    6. \n
    \n\n

    \u5728\u7b2c 2 \u79cd\u548c\u7b2c 3 \u79cd\u60c5\u51b5\u4e2d\uff0c\u4f60\u53ea\u9700\u8981\u79fb\u52a8 p \uff08\u53ca\u5176\u5b50\u6811\uff09\uff0c\u4f7f p \u6210\u4e3a q \u7684\u5b50\u8282\u70b9\u3002\u4f46\u662f\u5728\u7b2c 1 \u79cd\u60c5\u51b5\u4e2d\uff0c\u6811\u7684\u8282\u70b9\u53ef\u80fd\u4f1a\u65ad\u8fde\uff0c\u56e0\u6b64\u4f60\u8fd8\u9700\u8981\u91cd\u65b0\u8fde\u63a5\u8fd9\u4e9b\u8282\u70b9\u3002\u8bf7\u5728\u89e3\u9898\u524d\u4ed4\u7ec6\u9605\u8bfb\u793a\u4f8b\u3002

    \n\n

     

    \n\n

    N \u53c9\u6811\u7684\u8f93\u5165\u5e8f\u5217\u4ee5\u5c42\u5e8f\u904d\u5386\u7684\u5f62\u5f0f\u7ed9\u51fa\uff0c\u6bcf\u7ec4\u5b50\u8282\u70b9\u7528 null \u5206\u9694\uff08\u89c1\u793a\u4f8b\uff09\u3002

    \n\n

    \"\"

    \n\n

    \u4f8b\u5982\uff0c\u4e0a\u9762\u7684\u6811\u4f1a\u88ab\u5e8f\u5217\u5316\u4e3a [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1:

    \n\n

    \"\"

    \n\n
    \u8f93\u5165: root = [1,null,2,3,null,4,5,null,6,null,7,8], p = 4, q = 1\n\u8f93\u51fa: [1,null,2,3,4,null,5,null,6,null,7,8]\n\u89e3\u91ca: \u8be5\u793a\u4f8b\u5c5e\u4e8e\u7b2c\u4e8c\u79cd\u60c5\u51b5\uff0c\u8282\u70b9 p \u5728\u8282\u70b9 q \u7684\u5b50\u6811\u4e2d\u3002\u6211\u4eec\u53ef\u4ee5\u79fb\u52a8\u8282\u70b9 p \u53ca\u5176\u5b50\u6811\uff0c\u4f7f p \u6210\u4e3a\u8282\u70b9 q \u7684\u76f4\u63a5\u5b50\u8282\u70b9\u3002\n\u6ce8\u610f\uff0c\u8282\u70b9 4 \u662f\u8282\u70b9 1 \u7684\u6700\u540e\u4e00\u4e2a\u5b50\u8282\u70b9\u3002
    \n\n

    \u793a\u4f8b 2:

    \n\n

    \"\"

    \n\n
    \u8f93\u5165: root = [1,null,2,3,null,4,5,null,6,null,7,8], p = 7, q = 4\n\u8f93\u51fa: [1,null,2,3,null,4,5,null,6,null,7,8]\n\u89e3\u91ca: \u8282\u70b9 7 \u5df2\u7ecf\u662f\u8282\u70b9 4 \u7684\u76f4\u63a5\u5b50\u8282\u70b9\uff0c\u56e0\u6b64\u6211\u4eec\u4e0d\u6539\u52a8\u4efb\u4f55\u8282\u70b9\u3002\n
    \n\n

    \u793a\u4f8b 3:

    \n\n

    \"\"

    \n\n
    \u8f93\u5165: root = [1,null,2,3,null,4,5,null,6,null,7,8], p = 3, q = 8\n\u8f93\u51fa: [1,null,2,null,4,5,null,7,8,null,null,null,3,null,6]\n\u89e3\u91ca: \u8be5\u793a\u4f8b\u5c5e\u4e8e\u7b2c\u4e09\u79cd\u60c5\u51b5\uff0c\u8282\u70b9 p \u4e0d\u5728\u8282\u70b9 q \u7684\u5b50\u6811\u4e2d\uff0c\u53cd\u4e4b\u4ea6\u7136\u3002\u6211\u4eec\u53ef\u4ee5\u79fb\u52a8\u8282\u70b9 3 \u53ca\u5176\u5b50\u6811\uff0c\u4f7f\u4e4b\u6210\u4e3a\u8282\u70b9 8 \u7684\u5b50\u8282\u70b9\u3002\n
    \n\n

    \u793a\u4f8b 4:

    \n\n

    \"\"

    \n\n
    \u8f93\u5165: root = [1,null,2,3,null,4,5,null,6,null,7,8], p = 2, q = 7\n\u8f93\u51fa: [1,null,7,3,null,2,null,6,null,4,5,null,null,8]\n\u89e3\u91ca: \u8282\u70b9 q \u5728\u8282\u70b9 p \u7684\u5b50\u6811\u4e2d\uff0c\u56e0\u6b64\u8be5\u793a\u4f8b\u5c5e\u4e8e\u7b2c\u4e00\u79cd\u60c5\u51b5\u3002\n\u7b2c\u4e00\u6b65\uff0c\u6211\u4eec\u79fb\u52a8\u8282\u70b9 p \uff08\u53ca\u5176\u6240\u6709\u5b50\u6811\uff0c\u9664\u8282\u70b9 q \u7684\u5b50\u6811\u5916\uff09\uff0c\u5e76\u5c06\u5176\u52a0\u5165\u8282\u70b9 q \u7684\u5b50\u8282\u70b9\u5217\u8868\u4e2d\u3002\n\u7136\u540e\u6211\u4eec\u53d1\u73b0\u6811\u5df2\u65ad\u8fde\uff0c\u4f60\u9700\u8981\u91cd\u65b0\u8fde\u63a5\u8282\u70b9 q \u6765\u4ee3\u66ff\u8282\u70b9 p\uff0c\u5982\u56fe\u6240\u793a\u3002\n
    \n\n

    \u793a\u4f8b 5:

    \n\n

    \"\"

    \n\n
    \u8f93\u5165: root = [1,null,2,3,null,4,5,null,6,null,7,8], p = 1, q = 2\n\u8f93\u51fa: [2,null,4,5,1,null,7,8,null,null,3,null,null,null,6]\n\u89e3\u91ca: \u8282\u70b9 q \u5728\u8282\u70b9 p \u7684\u5b50\u6811\u4e2d\uff0c\u56e0\u6b64\u8be5\u793a\u4f8b\u5c5e\u4e8e\u7b2c\u4e00\u79cd\u60c5\u51b5\u3002\n\u7b2c\u4e00\u6b65\uff0c\u6211\u4eec\u79fb\u52a8\u8282\u70b9 p \uff08\u53ca\u5176\u6240\u6709\u5b50\u6811\uff0c\u9664\u8282\u70b9 q \u7684\u5b50\u6811\u5916\uff09\uff0c\u5e76\u5c06\u5176\u52a0\u5165\u8282\u70b9 q \u7684\u5b50\u8282\u70b9\u5217\u8868\u4e2d\u3002\n\u56e0\u4e3a\u8282\u70b9 p \u662f\u539f\u6811\u7684\u6839\u8282\u70b9\uff0c\u56e0\u6b64\u8282\u70b9 q \u4ee3\u66ff\u4e4b\u6210\u4e3a\u65b0\u6811\u7684\u6839\u8282\u70b9\u3002
    \n\n

     

    \n\n

    \u63d0\u793a:

    \n\n
      \n\t
    • \u8282\u70b9\u7684\u603b\u6570\u5728 [2, 1000] \u95f4\u3002
    • \n\t
    • \u6bcf\u4e2a\u8282\u70b9\u90fd\u6709\u552f\u4e00\u7684\u503c\u3002
    • \n\t
    • p != null
    • \n\t
    • q != null
    • \n\t
    • p \u548c q \u662f\u4e24\u4e2a\u4e0d\u540c\u7684\u8282\u70b9\uff08\u5373 p != q \uff09\u3002
    • \n
    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n vector children;\n\n Node() {}\n\n Node(int _val) {\n val = _val;\n }\n\n Node(int _val, vector _children) {\n val = _val;\n children = _children;\n }\n};\n*/\n\nclass Solution {\npublic:\n Node* moveSubTree(Node* root, Node* p, Node* q) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/*\n// Definition for a Node.\nclass Node {\n public int val;\n public List children;\n\n \n public Node() {\n children = new ArrayList();\n }\n \n public Node(int _val) {\n val = _val;\n children = new ArrayList();\n }\n \n public Node(int _val,ArrayList _children) {\n val = _val;\n children = _children;\n }\n};\n*/\n\nclass Solution {\n public Node moveSubTree(Node root, Node p, Node q) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "\"\"\"\n# Definition for a Node.\nclass Node(object):\n def __init__(self, val=None, children=None):\n self.val = val\n self.children = children if children is not None else []\n\"\"\"\n\nclass Solution(object):\n def moveSubTree(self, root, p, q):\n \"\"\"\n :type root: Node\n :type p: Node\n :type q: Node\n :rtype: Node\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "\"\"\"\n# Definition for a Node.\nclass Node:\n def __init__(self, val=None, children=None):\n self.val = val\n self.children = children if children is not None else []\n\"\"\"\n\nclass Solution:\n def moveSubTree(self, root: 'Node', p: 'Node', q: 'Node') -> 'Node':\n ", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/*\n// Definition for a Node.\npublic class Node {\n public int val;\n public IList children;\n \n public Node() {\n val = 0;\n children = new List();\n }\n\n public Node(int _val) {\n val = _val;\n children = new List();\n }\n \n public Node(int _val, List _children) {\n val = _val;\n children = _children;\n }\n}\n*/\n\npublic class Solution {\n public Node MoveSubTree(Node root, Node p, Node q) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // Definition for a Node.\n * function Node(val, children) {\n * this.val = val === undefined ? 0 : val;\n * this.children = children === undefined ? [] : children;\n * };\n */\n\n/**\n * @param {Node} root\n * @param {Node} p\n * @param {Node} q\n * @return {Node}\n */\nvar moveSubTree = function(root, p, q) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a Node.\n# class Node\n# attr_accessor :val, :children\n# def initialize(val=0, children=[])\n# @val = val\n# @children = children\n# end\n# end\n\n# @param {TreeNode} root\n# @param {TreeNode} p\n# @param {TreeNode} q\n# @return {Integer}\ndef move_sub_tree(root, p, q)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a Node.\n * public class Node {\n * public var val: Int\n * public var children: [Node]\n * public init(_ val: Int) {\n * self.val = val\n * self.children = []\n * }\n * }\n */\n\nclass Solution {\n func moveSubTree(_ root: Node?, _ p: Node?, _ q: Node?) -> Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a Node.\n * type Node struct {\n * Val int\n * Children []*Node\n * }\n */\n\nfunc moveSubTree(root *Node, p *Node, q *Node) *Node {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a Node.\n * class Node(var _value: Int) {\n * var value: Int = _value\n * var children: List[Node] = List()\n * }\n */\n\nobject Solution {\n def moveSubTree(root: Node, p: Node, q: Node): Node = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a Node.\n * class Node(var `val`: Int) {\n * var children: List = listOf()\n * }\n */\n\nclass Solution {\n fun moveSubTree(root: Node?, p: Node?, q: Node?): Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a Node.\n * class Node {\n * public $val = null;\n * public $children = null;\n * function __construct($val = 0) {\n * $this->val = $val;\n * $this->children = array();\n * }\n * }\n */\n\nclass Solution {\n\n /**\n * @param Node $root\n * @param Node $p\n * @param Node $q\n * @return Node\n */\n function moveSubTree($root, $p, $q) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for Node.\n * class Node {\n * val: number\n * children: Node[]\n * constructor(val?: number, children?: Node[]) {\n * this.val = (val===undefined ? 0 : val)\n * this.children = (children===undefined ? [] : children)\n * }\n * }\n */\n\nfunction moveSubTree(root: Node | null, p: Node | null, q: Node | null): Node | null {\n\t\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1516](https://leetcode-cn.com/problems/move-sub-tree-of-n-ary-tree)", "[\u79fb\u52a8 N \u53c9\u6811\u7684\u5b50\u6811](/solution/1500-1599/1516.Move%20Sub-Tree%20of%20N-Ary%20Tree/README.md)", "`\u6811`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1516](https://leetcode.com/problems/move-sub-tree-of-n-ary-tree)", "[Move Sub-Tree of N-Ary Tree](/solution/1500-1599/1516.Move%20Sub-Tree%20of%20N-Ary%20Tree/README_EN.md)", "`Tree`", "Hard", "\ud83d\udd12"]}, {"question_id": "1654", "frontend_question_id": "1511", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/customer-order-frequency", "url_en": "https://leetcode.com/problems/customer-order-frequency", "relative_path_cn": "/solution/1500-1599/1511.Customer%20Order%20Frequency/README.md", "relative_path_en": "/solution/1500-1599/1511.Customer%20Order%20Frequency/README_EN.md", "title_cn": "\u6d88\u8d39\u8005\u4e0b\u5355\u9891\u7387", "title_en": "Customer Order Frequency", "question_title_slug": "customer-order-frequency", "content_en": "

    Table: Customers

    \r\n\r\n
    \r\n+---------------+---------+\r\n| Column Name   | Type    |\r\n+---------------+---------+\r\n| customer_id   | int     |\r\n| name          | varchar |\r\n| country       | varchar |\r\n+---------------+---------+\r\ncustomer_id is the primary key for this table.\r\nThis table contains information of the customers in the company.\r\n
    \r\n\r\n

     

    \r\n\r\n

    Table: Product

    \r\n\r\n
    \r\n+---------------+---------+\r\n| Column Name   | Type    |\r\n+---------------+---------+\r\n| product_id    | int     |\r\n| description   | varchar |\r\n| price         | int     |\r\n+---------------+---------+\r\nproduct_id is the primary key for this table.\r\nThis table contains information of the products in the company.\r\nprice is the product cost.
    \r\n\r\n

     

    \r\n\r\n

    Table: Orders

    \r\n\r\n
    \r\n+---------------+---------+\r\n| Column Name   | Type    |\r\n+---------------+---------+\r\n| order_id      | int     |\r\n| customer_id   | int     |\r\n| product_id    | int     |\r\n| order_date    | date    |\r\n| quantity      | int     |\r\n+---------------+---------+\r\norder_id is the primary key for this table.\r\nThis table contains information on customer orders.\r\ncustomer_id is the id of the customer who bought "quantity" products with id "product_id".\r\nOrder_date is the date in format ('YYYY-MM-DD') when the order was shipped.
    \r\n\r\n

     

    \r\n\r\n

    Write an SQL query to report the customer_id and customer_name of customers who have spent at least $100 in each month of June and July 2020.

    \r\n\r\n

    Return the result table in any order.

    \r\n\r\n

    The query result format is in the following example.

    \r\n\r\n

     

    \r\n\r\n
    \r\nCustomers\r\n+--------------+-----------+-------------+\r\n| customer_id  | name      | country     |\r\n+--------------+-----------+-------------+\r\n| 1            | Winston   | USA         |\r\n| 2            | Jonathan  | Peru        |\r\n| 3            | Moustafa  | Egypt       |\r\n+--------------+-----------+-------------+\r\n\r\nProduct\r\n+--------------+-------------+-------------+\r\n| product_id   | description | price       |\r\n+--------------+-------------+-------------+\r\n| 10           | LC Phone    | 300         |\r\n| 20           | LC T-Shirt  | 10          |\r\n| 30           | LC Book     | 45          |\r\n| 40           | LC Keychain | 2           |\r\n+--------------+-------------+-------------+\r\n\r\nOrders\r\n+--------------+-------------+-------------+-------------+-----------+\r\n| order_id     | customer_id | product_id  | order_date  | quantity  |\r\n+--------------+-------------+-------------+-------------+-----------+\r\n| 1            | 1           | 10          | 2020-06-10  | 1         |\r\n| 2            | 1           | 20          | 2020-07-01  | 1         |\r\n| 3            | 1           | 30          | 2020-07-08  | 2         |\r\n| 4            | 2           | 10          | 2020-06-15  | 2         |\r\n| 5            | 2           | 40          | 2020-07-01  | 10        |\r\n| 6            | 3           | 20          | 2020-06-24  | 2         |\r\n| 7            | 3           | 30          | 2020-06-25  | 2         |\r\n| 9            | 3           | 30          | 2020-05-08  | 3         |\r\n+--------------+-------------+-------------+-------------+-----------+\r\n\r\nResult table:\r\n+--------------+------------+\r\n| customer_id  | name       |  \r\n+--------------+------------+\r\n| 1            | Winston    |\r\n+--------------+------------+ \r\nWinston spent $300 (300 * 1) in June and $100 ( 10 * 1 + 45 * 2) in July 2020.\r\nJonathan spent $600 (300 * 2) in June and $20 ( 2 * 10) in July 2020.\r\nMoustafa spent $110 (10 * 2 + 45 * 2) in June and $0 in July 2020.\r\n
    ", "content_cn": "

    \u8868: Customers

    \n\n
    +---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| customer_id   | int     |\n| name          | varchar |\n| country       | varchar |\n+---------------+---------+\ncustomer_id \u662f\u8be5\u8868\u4e3b\u952e.\n\u8be5\u8868\u5305\u542b\u516c\u53f8\u6d88\u8d39\u8005\u7684\u4fe1\u606f.\n
    \n\n

     

    \n\n

    \u8868: Product

    \n\n
    +---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| product_id    | int     |\n| description   | varchar |\n| price         | int     |\n+---------------+---------+\nproduct_id \u662f\u8be5\u8868\u4e3b\u952e.\n\u8be5\u8868\u5305\u542b\u516c\u53f8\u4ea7\u54c1\u7684\u4fe1\u606f.\nprice \u662f\u672c\u4ea7\u54c1\u7684\u82b1\u9500.
    \n\n

     

    \n\n

    \u8868: Orders

    \n\n
    +---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| order_id      | int     |\n| customer_id   | int     |\n| product_id    | int     |\n| order_date    | date    |\n| quantity      | int     |\n+---------------+---------+\norder_id \u662f\u8be5\u8868\u4e3b\u952e.\n\u8be5\u8868\u5305\u542b\u6d88\u8d39\u8005\u4e0b\u5355\u7684\u4fe1\u606f.\ncustomer_id \u662f\u4e70\u4e86\u6570\u91cf\u4e3a"quantity", id\u4e3a"product_id"\u4ea7\u54c1\u7684\u6d88\u8d39\u8005\u7684 id.\nOrder_date \u662f\u8ba2\u5355\u53d1\u8d27\u7684\u65e5\u671f, \u683c\u5f0f\u4e3a('YYYY-MM-DD').
    \n\n

     

    \n\n

    \u5199\u4e00\u4e2a SQL \u8bed\u53e5,  \u62a5\u544a\u6d88\u8d39\u8005\u7684 id \u548c\u540d\u5b57, \u5176\u4e2d\u6d88\u8d39\u8005\u5728 2020 \u5e74 6 \u6708\u548c 7 \u6708, \u6bcf\u6708\u81f3\u5c11\u82b1\u8d39\u4e86$100.

    \n\n

    \u7ed3\u679c\u8868\u65e0\u987a\u5e8f\u8981\u6c42.

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a.

    \n\n

     

    \n\n
    Customers\n+--------------+-----------+-------------+\n| customer_id  | name      | country     |\n+--------------+-----------+-------------+\n| 1            | Winston   | USA         |\n| 2            | Jonathan  | Peru        |\n| 3            | Moustafa  | Egypt       |\n+--------------+-----------+-------------+\n\nProduct\n+--------------+-------------+-------------+\n| product_id   | description | price       |\n+--------------+-------------+-------------+\n| 10           | LC Phone    | 300         |\n| 20           | LC T-Shirt  | 10          |\n| 30           | LC Book     | 45          |\n| 40           | LC Keychain | 2           |\n+--------------+-------------+-------------+\n\nOrders\n+--------------+-------------+-------------+-------------+-----------+\n| order_id     | customer_id | product_id  | order_date  | quantity  |\n+--------------+-------------+-------------+-------------+-----------+\n| 1            | 1           | 10          | 2020-06-10  | 1         |\n| 2            | 1           | 20          | 2020-07-01  | 1         |\n| 3            | 1           | 30          | 2020-07-08  | 2         |\n| 4            | 2           | 10          | 2020-06-15  | 2         |\n| 5            | 2           | 40          | 2020-07-01  | 10        |\n| 6            | 3           | 20          | 2020-06-24  | 2         |\n| 7            | 3           | 30          | 2020-06-25  | 2         |\n| 9            | 3           | 30          | 2020-05-08  | 3         |\n+--------------+-------------+-------------+-------------+-----------+\n\nResult \u8868:\n+--------------+------------+\n| customer_id  | name       |  \n+--------------+------------+\n| 1            | Winston    |\n+--------------+------------+ \nWinston \u57282020\u5e746\u6708\u82b1\u8d39\u4e86$300(300 * 1), \u57287\u6708\u82b1\u8d39\u4e86$100(10 * 1 + 45 * 2).\nJonathan \u57282020\u5e746\u6708\u82b1\u8d39\u4e86$600(300 * 2), \u57287\u6708\u82b1\u8d39\u4e86$20(2 * 10).\nMoustafa \u57282020\u5e746\u6708\u82b1\u8d39\u4e86$110 (10 * 2 + 45 * 2), \u57287\u6708\u82b1\u8d39\u4e86$0.\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1511](https://leetcode-cn.com/problems/customer-order-frequency)", "[\u6d88\u8d39\u8005\u4e0b\u5355\u9891\u7387](/solution/1500-1599/1511.Customer%20Order%20Frequency/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1511](https://leetcode.com/problems/customer-order-frequency)", "[Customer Order Frequency](/solution/1500-1599/1511.Customer%20Order%20Frequency/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1653", "frontend_question_id": "1530", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-good-leaf-nodes-pairs", "url_en": "https://leetcode.com/problems/number-of-good-leaf-nodes-pairs", "relative_path_cn": "/solution/1500-1599/1530.Number%20of%20Good%20Leaf%20Nodes%20Pairs/README.md", "relative_path_en": "/solution/1500-1599/1530.Number%20of%20Good%20Leaf%20Nodes%20Pairs/README_EN.md", "title_cn": "\u597d\u53f6\u5b50\u8282\u70b9\u5bf9\u7684\u6570\u91cf", "title_en": "Number of Good Leaf Nodes Pairs", "question_title_slug": "number-of-good-leaf-nodes-pairs", "content_en": "

    Given the root of a binary tree and an integer distance. A pair of two different leaf nodes of a binary tree is said to be good if the length of the shortest path between them is less than or equal to distance.

    \r\n\r\n

    Return the number of good leaf node pairs in the tree.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\"\"\r\n
    \r\nInput: root = [1,2,3,null,4], distance = 3\r\nOutput: 1\r\nExplanation: The leaf nodes of the tree are 3 and 4 and the length of the shortest path between them is 3. This is the only good pair.\r\n
    \r\n\r\n

    Example 2:

    \r\n\"\"\r\n
    \r\nInput: root = [1,2,3,4,5,6,7], distance = 3\r\nOutput: 2\r\nExplanation: The good pairs are [4,5] and [6,7] with shortest path = 2. The pair [4,6] is not good because the length of ther shortest path between them is 4.\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: root = [7,1,4,6,null,5,3,null,null,null,null,null,2], distance = 3\r\nOutput: 1\r\nExplanation: The only good pair is [2,5].\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: root = [100], distance = 1\r\nOutput: 0\r\n
    \r\n\r\n

    Example 5:

    \r\n\r\n
    \r\nInput: root = [1,1,1], distance = 2\r\nOutput: 1\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • The number of nodes in the tree is in the range [1, 2^10].
    • \r\n\t
    • Each node's value is between [1, 100].
    • \r\n\t
    • 1 <= distance <= 10
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9 root \u548c\u4e00\u4e2a\u6574\u6570 distance \u3002

    \n\n

    \u5982\u679c\u4e8c\u53c9\u6811\u4e2d\u4e24\u4e2a \u53f6 \u8282\u70b9\u4e4b\u95f4\u7684 \u6700\u77ed\u8def\u5f84\u957f\u5ea6 \u5c0f\u4e8e\u6216\u8005\u7b49\u4e8e distance \uff0c\u90a3\u5b83\u4eec\u5c31\u53ef\u4ee5\u6784\u6210\u4e00\u7ec4 \u597d\u53f6\u5b50\u8282\u70b9\u5bf9 \u3002

    \n\n

    \u8fd4\u56de\u6811\u4e2d \u597d\u53f6\u5b50\u8282\u70b9\u5bf9\u7684\u6570\u91cf \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

     

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1aroot = [1,2,3,null,4], distance = 3\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u6811\u7684\u53f6\u8282\u70b9\u662f 3 \u548c 4 \uff0c\u5b83\u4eec\u4e4b\u95f4\u7684\u6700\u77ed\u8def\u5f84\u7684\u957f\u5ea6\u662f 3 \u3002\u8fd9\u662f\u552f\u4e00\u7684\u597d\u53f6\u5b50\u8282\u70b9\u5bf9\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1aroot = [1,2,3,4,5,6,7], distance = 3\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u597d\u53f6\u5b50\u8282\u70b9\u5bf9\u4e3a [4,5] \u548c [6,7] \uff0c\u6700\u77ed\u8def\u5f84\u957f\u5ea6\u90fd\u662f 2 \u3002\u4f46\u662f\u53f6\u5b50\u8282\u70b9\u5bf9 [4,6] \u4e0d\u6ee1\u8db3\u8981\u6c42\uff0c\u56e0\u4e3a\u5b83\u4eec\u4e4b\u95f4\u7684\u6700\u77ed\u8def\u5f84\u957f\u5ea6\u4e3a 4 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aroot = [7,1,4,6,null,5,3,null,null,null,null,null,2], distance = 3\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u552f\u4e00\u7684\u597d\u53f6\u5b50\u8282\u70b9\u5bf9\u662f [2,5] \u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1aroot = [100], distance = 1\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1aroot = [1,1,1], distance = 2\n\u8f93\u51fa\uff1a1\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • tree \u7684\u8282\u70b9\u6570\u5728 [1, 2^10] \u8303\u56f4\u5185\u3002
    • \n\t
    • \u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u90fd\u5728 [1, 100] \u4e4b\u95f4\u3002
    • \n\t
    • 1 <= distance <= 10
    • \n
    \n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int countPairs(TreeNode* root, int distance) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int countPairs(TreeNode root, int distance) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def countPairs(self, root, distance):\n \"\"\"\n :type root: TreeNode\n :type distance: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def countPairs(self, root: TreeNode, distance: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint countPairs(struct TreeNode* root, int distance){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int CountPairs(TreeNode root, int distance) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number} distance\n * @return {number}\n */\nvar countPairs = function(root, distance) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @param {Integer} distance\n# @return {Integer}\ndef count_pairs(root, distance)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func countPairs(_ root: TreeNode?, _ distance: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc countPairs(root *TreeNode, distance int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def countPairs(root: TreeNode, distance: Int): Int = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun countPairs(root: TreeNode?, distance: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn count_pairs(root: Option>>, distance: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param Integer $distance\n * @return Integer\n */\n function countPairs($root, $distance) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction countPairs(root: TreeNode | null, distance: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (count-pairs root distance)\n (-> (or/c tree-node? #f) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1530](https://leetcode-cn.com/problems/number-of-good-leaf-nodes-pairs)", "[\u597d\u53f6\u5b50\u8282\u70b9\u5bf9\u7684\u6570\u91cf](/solution/1500-1599/1530.Number%20of%20Good%20Leaf%20Nodes%20Pairs/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1530](https://leetcode.com/problems/number-of-good-leaf-nodes-pairs)", "[Number of Good Leaf Nodes Pairs](/solution/1500-1599/1530.Number%20of%20Good%20Leaf%20Nodes%20Pairs/README_EN.md)", "`Tree`,`Depth-first Search`", "Medium", ""]}, {"question_id": "1652", "frontend_question_id": "1529", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/bulb-switcher-iv", "url_en": "https://leetcode.com/problems/bulb-switcher-iv", "relative_path_cn": "/solution/1500-1599/1529.Bulb%20Switcher%20IV/README.md", "relative_path_en": "/solution/1500-1599/1529.Bulb%20Switcher%20IV/README_EN.md", "title_cn": "\u706f\u6ce1\u5f00\u5173 IV", "title_en": "Bulb Switcher IV", "question_title_slug": "bulb-switcher-iv", "content_en": "

    There is a room with n bulbs, numbered from 0 to n - 1, arranged in a row from left to right. Initially, all the bulbs are turned off.

    \n\n

    Your task is to obtain the configuration represented by target where target[i] is '1' if the ith bulb is turned on and is '0' if it is turned off.

    \n\n

    You have a switch to flip the state of the bulb, a flip operation is defined as follows:

    \n\n
      \n\t
    • Choose any bulb (index i) of your current configuration.
    • \n\t
    • Flip each bulb from index i to index n - 1.
    • \n
    \n\n

    When any bulb is flipped it means that if it is '0' it changes to '1' and if it is '1' it changes to '0'.

    \n\n

    Return the minimum number of flips required to form target.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: target = "10111"\nOutput: 3\nExplanation: Initial configuration "00000".\nflip from the third bulb:  "00000" -> "00111"\nflip from the first bulb:  "00111" -> "11000"\nflip from the second bulb:  "11000" -> "10111"\nWe need at least 3 flip operations to form target.
    \n\n

    Example 2:

    \n\n
    \nInput: target = "101"\nOutput: 3\nExplanation: "000" -> "111" -> "100" -> "101".\n
    \n\n

    Example 3:

    \n\n
    \nInput: target = "00000"\nOutput: 0\n
    \n\n

    Example 4:

    \n\n
    \nInput: target = "001011101"\nOutput: 5\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= target.length <= 105
    • \n\t
    • target[i] is either '0' or '1'.
    • \n
    \n", "content_cn": "

    \u623f\u95f4\u4e2d\u6709 n \u4e2a\u706f\u6ce1\uff0c\u7f16\u53f7\u4ece 0 \u5230 n-1 \uff0c\u81ea\u5de6\u5411\u53f3\u6392\u6210\u4e00\u884c\u3002\u6700\u5f00\u59cb\u7684\u65f6\u5019\uff0c\u6240\u6709\u7684\u706f\u6ce1\u90fd\u662f \u5173 \u7740\u7684\u3002

    \n\n

    \u8bf7\u4f60\u8bbe\u6cd5\u4f7f\u5f97\u706f\u6ce1\u7684\u5f00\u5173\u72b6\u6001\u548c target \u63cf\u8ff0\u7684\u72b6\u6001\u4e00\u81f4\uff0c\u5176\u4e2d target[i] \u7b49\u4e8e 1 \u7b2c i \u4e2a\u706f\u6ce1\u662f\u5f00\u7740\u7684\uff0c\u7b49\u4e8e 0 \u610f\u5473\u7740\u7b2c i \u4e2a\u706f\u662f\u5173\u7740\u7684\u3002

    \n\n

    \u6709\u4e00\u4e2a\u5f00\u5173\u53ef\u4ee5\u7528\u4e8e\u7ffb\u8f6c\u706f\u6ce1\u7684\u72b6\u6001\uff0c\u7ffb\u8f6c\u64cd\u4f5c\u5b9a\u4e49\u5982\u4e0b\uff1a

    \n\n
      \n\t
    • \u9009\u62e9\u5f53\u524d\u914d\u7f6e\u4e0b\u7684\u4efb\u610f\u4e00\u4e2a\u706f\u6ce1\uff08\u4e0b\u6807\u4e3a i \uff09
    • \n\t
    • \u7ffb\u8f6c\u4e0b\u6807\u4ece i \u5230 n-1 \u7684\u6bcf\u4e2a\u706f\u6ce1
    • \n
    \n\n

    \u7ffb\u8f6c\u65f6\uff0c\u5982\u679c\u706f\u6ce1\u7684\u72b6\u6001\u4e3a 0 \u5c31\u53d8\u4e3a 1\uff0c\u4e3a 1 \u5c31\u53d8\u4e3a 0 \u3002

    \n\n

    \u8fd4\u56de\u8fbe\u6210 target \u63cf\u8ff0\u7684\u72b6\u6001\u6240\u9700\u7684 \u6700\u5c11 \u7ffb\u8f6c\u6b21\u6570\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1atarget = "10111"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u521d\u59cb\u914d\u7f6e "00000".\n\u4ece\u7b2c 3 \u4e2a\u706f\u6ce1\uff08\u4e0b\u6807\u4e3a 2\uff09\u5f00\u59cb\u7ffb\u8f6c "00000" -> "00111"\n\u4ece\u7b2c 1 \u4e2a\u706f\u6ce1\uff08\u4e0b\u6807\u4e3a 0\uff09\u5f00\u59cb\u7ffb\u8f6c "00111" -> "11000"\n\u4ece\u7b2c 2 \u4e2a\u706f\u6ce1\uff08\u4e0b\u6807\u4e3a 1\uff09\u5f00\u59cb\u7ffb\u8f6c "11000" -> "10111"\n\u81f3\u5c11\u9700\u8981\u7ffb\u8f6c 3 \u6b21\u624d\u80fd\u8fbe\u6210 target \u63cf\u8ff0\u7684\u72b6\u6001
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1atarget = "101"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a"000" -> "111" -> "100" -> "101".\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1atarget = "00000"\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1atarget = "001011101"\n\u8f93\u51fa\uff1a5\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= target.length <= 10^5
    • \n\t
    • target[i] == '0' \u6216\u8005 target[i] == '1'
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minFlips(string target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minFlips(String target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minFlips(self, target):\n \"\"\"\n :type target: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minFlips(self, target: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minFlips(char * target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinFlips(string target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} target\n * @return {number}\n */\nvar minFlips = function(target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} target\n# @return {Integer}\ndef min_flips(target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minFlips(_ target: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minFlips(target string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minFlips(target: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minFlips(target: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_flips(target: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $target\n * @return Integer\n */\n function minFlips($target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minFlips(target: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-flips target)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1529](https://leetcode-cn.com/problems/bulb-switcher-iv)", "[\u706f\u6ce1\u5f00\u5173 IV](/solution/1500-1599/1529.Bulb%20Switcher%20IV/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1529](https://leetcode.com/problems/bulb-switcher-iv)", "[Bulb Switcher IV](/solution/1500-1599/1529.Bulb%20Switcher%20IV/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "1651", "frontend_question_id": "1528", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/shuffle-string", "url_en": "https://leetcode.com/problems/shuffle-string", "relative_path_cn": "/solution/1500-1599/1528.Shuffle%20String/README.md", "relative_path_en": "/solution/1500-1599/1528.Shuffle%20String/README_EN.md", "title_cn": "\u91cd\u65b0\u6392\u5217\u5b57\u7b26\u4e32", "title_en": "Shuffle String", "question_title_slug": "shuffle-string", "content_en": "

    Given a string s and an integer array indices of the same length.

    \r\n\r\n

    The string s will be shuffled such that the character at the ith position moves to indices[i] in the shuffled string.

    \r\n\r\n

    Return the shuffled string.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\"\"\r\n
    \r\nInput: s = "codeleet", indices = [4,5,6,7,0,2,1,3]\r\nOutput: "leetcode"\r\nExplanation: As shown, "codeleet" becomes "leetcode" after shuffling.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: s = "abc", indices = [0,1,2]\r\nOutput: "abc"\r\nExplanation: After shuffling, each character remains in its position.\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: s = "aiohn", indices = [3,1,4,2,0]\r\nOutput: "nihao"\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: s = "aaiougrt", indices = [4,0,2,6,7,3,1,5]\r\nOutput: "arigatou"\r\n
    \r\n\r\n

    Example 5:

    \r\n\r\n
    \r\nInput: s = "art", indices = [1,0,2]\r\nOutput: "rat"\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • s.length == indices.length == n
    • \r\n\t
    • 1 <= n <= 100
    • \r\n\t
    • s contains only lower-case English letters.
    • \r\n\t
    • 0 <= indices[i] < n
    • \r\n\t
    • All values of indices are unique (i.e. indices is a permutation of the integers from 0 to n - 1).
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \u548c\u4e00\u4e2a \u957f\u5ea6\u76f8\u540c \u7684\u6574\u6570\u6570\u7ec4 indices \u3002

    \n\n

    \u8bf7\u4f60\u91cd\u65b0\u6392\u5217\u5b57\u7b26\u4e32 s \uff0c\u5176\u4e2d\u7b2c i \u4e2a\u5b57\u7b26\u9700\u8981\u79fb\u52a8\u5230 indices[i] \u6307\u793a\u7684\u4f4d\u7f6e\u3002

    \n\n

    \u8fd4\u56de\u91cd\u65b0\u6392\u5217\u540e\u7684\u5b57\u7b26\u4e32\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1as = "codeleet", indices = [4,5,6,7,0,2,1,3]\n\u8f93\u51fa\uff1a"leetcode"\n\u89e3\u91ca\uff1a\u5982\u56fe\u6240\u793a\uff0c"codeleet" \u91cd\u65b0\u6392\u5217\u540e\u53d8\u4e3a "leetcode" \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1as = "abc", indices = [0,1,2]\n\u8f93\u51fa\uff1a"abc"\n\u89e3\u91ca\uff1a\u91cd\u65b0\u6392\u5217\u540e\uff0c\u6bcf\u4e2a\u5b57\u7b26\u90fd\u8fd8\u7559\u5728\u539f\u6765\u7684\u4f4d\u7f6e\u4e0a\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1as = "aiohn", indices = [3,1,4,2,0]\n\u8f93\u51fa\uff1a"nihao"\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1as = "aaiougrt", indices = [4,0,2,6,7,3,1,5]\n\u8f93\u51fa\uff1a"arigatou"\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1as = "art", indices = [1,0,2]\n\u8f93\u51fa\uff1a"rat"\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • s.length == indices.length == n
    • \n\t
    • 1 <= n <= 100
    • \n\t
    • s \u4ec5\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    • \n\t
    • 0 <= indices[i] < n
    • \n\t
    • indices \u7684\u6240\u6709\u7684\u503c\u90fd\u662f\u552f\u4e00\u7684\uff08\u4e5f\u5c31\u662f\u8bf4\uff0cindices \u662f\u6574\u6570 0 \u5230 n - 1 \u5f62\u6210\u7684\u4e00\u7ec4\u6392\u5217\uff09\u3002
    • \n
    \n", "tags_en": ["Sort"], "tags_cn": ["\u6392\u5e8f"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string restoreString(string s, vector& indices) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String restoreString(String s, int[] indices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def restoreString(self, s, indices):\n \"\"\"\n :type s: str\n :type indices: List[int]\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def restoreString(self, s: str, indices: List[int]) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * restoreString(char * s, int* indices, int indicesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string RestoreString(string s, int[] indices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number[]} indices\n * @return {string}\n */\nvar restoreString = function(s, indices) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer[]} indices\n# @return {String}\ndef restore_string(s, indices)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func restoreString(_ s: String, _ indices: [Int]) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func restoreString(s string, indices []int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def restoreString(s: String, indices: Array[Int]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun restoreString(s: String, indices: IntArray): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn restore_string(s: String, indices: Vec) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer[] $indices\n * @return String\n */\n function restoreString($s, $indices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function restoreString(s: string, indices: number[]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (restore-string s indices)\n (-> string? (listof exact-integer?) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1528](https://leetcode-cn.com/problems/shuffle-string)", "[\u91cd\u65b0\u6392\u5217\u5b57\u7b26\u4e32](/solution/1500-1599/1528.Shuffle%20String/README.md)", "`\u6392\u5e8f`", "\u7b80\u5355", ""], "md_table_row_en": ["[1528](https://leetcode.com/problems/shuffle-string)", "[Shuffle String](/solution/1500-1599/1528.Shuffle%20String/README_EN.md)", "`Sort`", "Easy", ""]}, {"question_id": "1650", "frontend_question_id": "1506", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/find-root-of-n-ary-tree", "url_en": "https://leetcode.com/problems/find-root-of-n-ary-tree", "relative_path_cn": "/solution/1500-1599/1506.Find%20Root%20of%20N-Ary%20Tree/README.md", "relative_path_en": "/solution/1500-1599/1506.Find%20Root%20of%20N-Ary%20Tree/README_EN.md", "title_cn": "\u627e\u5230 N \u53c9\u6811\u7684\u6839\u8282\u70b9", "title_en": "Find Root of N-Ary Tree", "question_title_slug": "find-root-of-n-ary-tree", "content_en": "

    You are given all the nodes of an N-ary tree as an array of Node objects, where each node has a unique value.

    \n\n

    Return the root of the N-ary tree.

    \n\n

    Custom testing:

    \n\n

    An N-ary tree can be serialized as represented in its level order traversal where each group of children is separated by the null value (see examples).

    \n\n

    \"\"

    \n\n

    For example, the above tree is serialized as [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14].

    \n\n

    The testing will be done in the following way:

    \n\n
      \n\t
    1. The input data should be provided as a serialization of the tree.
    2. \n\t
    3. The driver code will construct the tree from the serialized input data and put each Node object into an array in an arbitrary order.
    4. \n\t
    5. The driver code will pass the array to findRoot, and your function should find and return the root Node object in the array.
    6. \n\t
    7. The driver code will take the returned Node object and serialize it. If the serialized value and the input data are the same, the test passes.
    8. \n
    \n\n

     

    \n

    Example 1:

    \n\n

    \n\n
    \nInput: tree = [1,null,3,2,4,null,5,6]\nOutput: [1,null,3,2,4,null,5,6]\nExplanation: The tree from the input data is shown above.\nThe driver code creates the tree and gives findRoot the Node objects in an arbitrary order.\nFor example, the passed array could be [Node(5),Node(4),Node(3),Node(6),Node(2),Node(1)] or [Node(2),Node(6),Node(1),Node(3),Node(5),Node(4)].\nThe findRoot function should return the root Node(1), and the driver code will serialize it and compare with the input data.\nThe input data and serialized Node(1) are the same, so the test passes.\n
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: tree = [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]\nOutput: [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The total number of nodes is between [1, 5 * 104].
    • \n\t
    • Each node has a unique value.
    • \n
    \n\n

     

    \n

    Follow up:

    \n\n
      \n\t
    • Could you solve this problem in constant space complexity with a linear time algorithm?
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u68f5\u00a0N \u53c9\u6811\u00a0\u7684\u6240\u6709\u8282\u70b9\u5728\u4e00\u4e2a\u6570\u7ec4\u00a0\u00a0Node[] tree\u00a0\u4e2d\uff0c\u6811\u4e2d\u6bcf\u4e2a\u8282\u70b9\u90fd\u6709 \u552f\u4e00\u7684\u503c \u3002

    \n\n

    \u627e\u5230\u5e76\u8fd4\u56de N \u53c9\u6811\u7684 \u6839\u8282\u70b9 \u3002

    \n\n

    \u00a0

    \n\n

    \u81ea\u5b9a\u4e49\u6d4b\u8bd5\uff1a

    \n\n

    N \u53c9\u6811\u7684\u8f93\u5165\u5e8f\u5217\u4e3a\u5176\u5c42\u5e8f\u904d\u5386\u5e8f\u5217\uff0c\u6bcf\u7ec4\u5b50\u8282\u70b9\u7528 null \u5206\u9694\uff08\u89c1\u793a\u4f8b\uff09\u3002

    \n\n

    \"\"

    \n\n

    \u4e0a\u56fe\u4e2d\u7684 N \u53c9\u6811\u7684\u5e8f\u5217\u5316\u63cf\u8ff0\u4e3a [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14] \u3002

    \n\n

    \u6d4b\u8bd5\u5c06\u4ee5\u4e0b\u5217\u65b9\u5f0f\u8fdb\u884c\uff1a

    \n\n
      \n\t
    • \u8f93\u5165\u6570\u636e\u7684\u5f62\u5f0f\u4e3a\u6811\u7684\u5e8f\u5217\u5316\u63cf\u8ff0\u3002
    • \n\t
    • \u9a71\u52a8\u7a0b\u5e8f\u4ee3\u7801\u5c06\u6839\u636e\u5e8f\u5217\u5316\u7684\u8f93\u5165\u6570\u636e\u6784\u9020\u6811\uff0c\u5e76\u4ee5\u4efb\u610f\u987a\u5e8f\u5c06\u6bcf\u4e2a Node \u5bf9\u8c61\u653e\u5165\u4e00\u4e2a\u6570\u7ec4\u4e2d\u3002
    • \n\t
    • \u9a71\u52a8\u7a0b\u5e8f\u4ee3\u7801\u5c06\u628a\u6570\u7ec4\u4f20\u9012\u7ed9 findRoot \uff0c\u4f60\u6240\u7f16\u5199\u7684\u51fd\u6570\u5e94\u8be5\u5728\u6570\u7ec4\u4e2d\u67e5\u627e\u5e76\u8fd4\u56de\u6839 Node \u5bf9\u8c61\u3002
    • \n\t
    • \u9a71\u52a8\u7a0b\u5e8f\u4ee3\u7801\u5c06\u63a5\u53d7\u8fd4\u56de\u7684 Node \u5bf9\u8c61\u5e76\u5bf9\u5176\u8fdb\u884c\u5e8f\u5217\u5316\u3002\u5982\u679c\u5e8f\u5217\u5316\u7684\u7ed3\u679c\u548c\u8f93\u5165\u6570\u636e \u76f8\u540c \uff0c\u5219\u6d4b\u8bd5 \u901a\u8fc7 \u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \n\n
    \n\u8f93\u5165\uff1atree = [1,null,3,2,4,null,5,6]\n\u8f93\u51fa\uff1a[1,null,3,2,4,null,5,6]\n\u89e3\u91ca\uff1a\u6765\u81ea\u8f93\u5165\u6570\u636e\u7684\u6811\u5982\u4e0a\u6240\u793a\u3002\n\u9a71\u52a8\u7a0b\u5e8f\u4ee3\u7801\u521b\u5efa\u6811\uff0c\u5e76\u4ee5\u4efb\u610f\u987a\u5e8f\u5411 findRoot \u63d0\u4f9b Node \u5bf9\u8c61\u3002\n\u4f8b\u5982\uff0c\u4f20\u9012\u7684\u6570\u7ec4\u53ef\u4ee5\u662f [Node(5),Node(4),Node(3),Node(6),Node(2),Node(1)] \u6216 [Node(2),Node(6),Node(1),Node(3),Node(5),Node(4)] \u3002\nfindRoot \u51fd\u6570\u5e94\u8be5\u8fd4\u56de\u6839 Node(1) \uff0c\u9a71\u52a8\u7a0b\u5e8f\u4ee3\u7801\u5c06\u5e8f\u5217\u5316\u5b83\u5e76\u4e0e\u8f93\u5165\u6570\u636e\u8fdb\u884c\u6bd4\u8f83\u3002\n\u8f93\u5165\u6570\u636e\u548c\u5e8f\u5217\u5316\u7684 Node(1) \u76f8\u540c\uff0c\u56e0\u6b64\u6d4b\u8bd5\u901a\u8fc7\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1atree = [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]\n\u8f93\u51fa\uff1a[1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u8282\u70b9\u7684\u603b\u4e2a\u6570\u5728\u00a0[1,\u00a05*10^4]\u00a0\u4e4b\u95f4\u3002
    • \n\t
    • \u6bcf\u4e2a\u8282\u70b9\u90fd\u6709\u552f\u4e00\u7684\u503c\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u4f60\u53ef\u4ee5\u4f7f\u7528 O(1) \u989d\u5916\u5185\u5b58\u7a7a\u95f4\u4e14 O(n) \u65f6\u95f4\u590d\u6742\u5ea6\u7684\u7b97\u6cd5\u6765\u627e\u5230\u8be5\u6811\u7684\u6839\u8282\u70b9\u5417\uff1f
    • \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n vector children;\n\n Node() {}\n\n Node(int _val) {\n val = _val;\n }\n\n Node(int _val, vector _children) {\n val = _val;\n children = _children;\n }\n};\n*/\n\nclass Solution {\npublic:\n Node* findRoot(vector tree) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/*\n// Definition for a Node.\nclass Node {\n public int val;\n public List children;\n\n \n public Node() {\n children = new ArrayList();\n }\n \n public Node(int _val) {\n val = _val;\n children = new ArrayList();\n }\n \n public Node(int _val,ArrayList _children) {\n val = _val;\n children = _children;\n }\n};\n*/\n\nclass Solution {\n public Node findRoot(List tree) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "\"\"\"\n# Definition for a Node.\nclass Node(object):\n def __init__(self, val=None, children=None):\n self.val = val\n self.children = children if children is not None else []\n\"\"\"\n\nclass Solution(object):\n def findRoot(self, tree):\n \"\"\"\n :type tree: List['Node']\n :rtype: 'Node'\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "\"\"\"\n# Definition for a Node.\nclass Node:\n def __init__(self, val=None, children=None):\n self.val = val\n self.children = children if children is not None else []\n\"\"\"\n\nclass Solution:\n def findRoot(self, tree: List['Node']) -> 'Node':\n ", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/*\n// Definition for a Node.\npublic class Node {\n public int val;\n public IList children;\n \n public Node() {\n val = 0;\n children = new List();\n }\n\n public Node(int _val) {\n val = _val;\n children = new List();\n }\n \n public Node(int _val, List _children) {\n val = _val;\n children = _children;\n }\n}\n*/\n\npublic class Solution {\n public Node FindRoot(List tree) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // Definition for a Node.\n * function Node(val, children) {\n * this.val = val === undefined ? 0 : val;\n * this.children = children === undefined ? [] : children;\n * };\n */\n\n/**\n * @param {Node[]} tree\n * @return {Node}\n */\nvar findRoot = function(tree) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a Node.\n# class Node\n# attr_accessor :val, :children\n# def initialize(val=0, children=[])\n# @val = val\n# @children = children\n# end\n# end\n\n# @param {Node[]} tree\n# @return {Node}\ndef find_root(tree)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a Node.\n * public class Node {\n * public var val: Int\n * public var children: [Node]\n * public init(_ val: Int) {\n * self.val = val\n * self.children = []\n * }\n * }\n */\n\nclass Solution {\n func findRoot(_ tree: [Node]) -> Node? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a Node.\n * type Node struct {\n * Val int\n * Children []*Node\n * }\n */\n\nfunc findRoot(tree []*Node) *Node {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a Node.\n * class Node(var _value: Int) {\n * var value: Int = _value\n * var children: List[Node] = List()\n * }\n */\n\nobject Solution {\n def findRoot(tree: List[Node]): Node = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a Node.\n * class Node(var `val`: Int) {\n * var children: List = listOf()\n * }\n */\n\nclass Solution {\n fun findRoot(tree: List): Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a Node.\n * class Node {\n * public $val = null;\n * public $children = null;\n * function __construct($val = 0) {\n * $this->val = $val;\n * $this->children = array();\n * }\n * }\n */\n\nclass Solution {\n /**\n * @param Node[] $tree\n * @return Node\n */\n function findRoot($tree) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for Node.\n * class Node {\n * val: number\n * children: Node[]\n * constructor(val?: number, children?: Node[]) {\n * this.val = (val===undefined ? 0 : val)\n * this.children = (children===undefined ? [] : children)\n * }\n * }\n */\n\nfunction findRoot(tree: Node[]): Node | null {\n \n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1506](https://leetcode-cn.com/problems/find-root-of-n-ary-tree)", "[\u627e\u5230 N \u53c9\u6811\u7684\u6839\u8282\u70b9](/solution/1500-1599/1506.Find%20Root%20of%20N-Ary%20Tree/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1506](https://leetcode.com/problems/find-root-of-n-ary-tree)", "[Find Root of N-Ary Tree](/solution/1500-1599/1506.Find%20Root%20of%20N-Ary%20Tree/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1649", "frontend_question_id": "1546", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-number-of-non-overlapping-subarrays-with-sum-equals-target", "url_en": "https://leetcode.com/problems/maximum-number-of-non-overlapping-subarrays-with-sum-equals-target", "relative_path_cn": "/solution/1500-1599/1546.Maximum%20Number%20of%20Non-Overlapping%20Subarrays%20With%20Sum%20Equals%20Target/README.md", "relative_path_en": "/solution/1500-1599/1546.Maximum%20Number%20of%20Non-Overlapping%20Subarrays%20With%20Sum%20Equals%20Target/README_EN.md", "title_cn": "\u548c\u4e3a\u76ee\u6807\u503c\u4e14\u4e0d\u91cd\u53e0\u7684\u975e\u7a7a\u5b50\u6570\u7ec4\u7684\u6700\u5927\u6570\u76ee", "title_en": "Maximum Number of Non-Overlapping Subarrays With Sum Equals Target", "question_title_slug": "maximum-number-of-non-overlapping-subarrays-with-sum-equals-target", "content_en": "

    Given an array nums and an integer target.

    \n\n

    Return the maximum number of non-empty non-overlapping subarrays such that the sum of values in each subarray is equal to target.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,1,1,1,1], target = 2\nOutput: 2\nExplanation: There are 2 non-overlapping subarrays [1,1,1,1,1] with sum equals to target(2).\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [-1,3,5,1,4,2,-9], target = 6\nOutput: 2\nExplanation: There are 3 subarrays with sum equal to 6.\n([5,1], [4,2], [3,5,1,4,2,-9]) but only the first 2 are non-overlapping.
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [-2,6,6,3,5,4,1,2,8], target = 10\nOutput: 3\n
    \n\n

    Example 4:

    \n\n
    \nInput: nums = [0,0,0], target = 0\nOutput: 3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 10^5
    • \n\t
    • -10^4 <= nums[i] <= 10^4
    • \n\t
    • 0 <= target <= 10^6
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 nums \u548c\u4e00\u4e2a\u6574\u6570 target \u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de \u975e\u7a7a\u4e0d\u91cd\u53e0 \u5b50\u6570\u7ec4\u7684\u6700\u5927\u6570\u76ee\uff0c\u4e14\u6bcf\u4e2a\u5b50\u6570\u7ec4\u4e2d\u6570\u5b57\u548c\u90fd\u4e3a target \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,1,1,1,1], target = 2\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u603b\u5171\u6709 2 \u4e2a\u4e0d\u91cd\u53e0\u5b50\u6570\u7ec4\uff08\u52a0\u7c97\u6570\u5b57\u8868\u793a\uff09 [1,1,1,1,1] \uff0c\u5b83\u4eec\u7684\u548c\u4e3a\u76ee\u6807\u503c 2 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [-1,3,5,1,4,2,-9], target = 6\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u603b\u5171\u6709 3 \u4e2a\u5b50\u6570\u7ec4\u548c\u4e3a 6 \u3002\n([5,1], [4,2], [3,5,1,4,2,-9]) \u4f46\u53ea\u6709\u524d 2 \u4e2a\u662f\u4e0d\u91cd\u53e0\u7684\u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [-2,6,6,3,5,4,1,2,8], target = 10\n\u8f93\u51fa\uff1a3\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [0,0,0], target = 0\n\u8f93\u51fa\uff1a3\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 10^5
    • \n\t
    • -10^4 <= nums[i] <= 10^4
    • \n\t
    • 0 <= target <= 10^6
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxNonOverlapping(vector& nums, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxNonOverlapping(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxNonOverlapping(self, nums, target):\n \"\"\"\n :type nums: List[int]\n :type target: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxNonOverlapping(self, nums: List[int], target: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxNonOverlapping(int* nums, int numsSize, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxNonOverlapping(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} target\n * @return {number}\n */\nvar maxNonOverlapping = function(nums, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} target\n# @return {Integer}\ndef max_non_overlapping(nums, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxNonOverlapping(_ nums: [Int], _ target: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxNonOverlapping(nums []int, target int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxNonOverlapping(nums: Array[Int], target: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxNonOverlapping(nums: IntArray, target: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_non_overlapping(nums: Vec, target: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $target\n * @return Integer\n */\n function maxNonOverlapping($nums, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxNonOverlapping(nums: number[], target: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-non-overlapping nums target)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1546](https://leetcode-cn.com/problems/maximum-number-of-non-overlapping-subarrays-with-sum-equals-target)", "[\u548c\u4e3a\u76ee\u6807\u503c\u4e14\u4e0d\u91cd\u53e0\u7684\u975e\u7a7a\u5b50\u6570\u7ec4\u7684\u6700\u5927\u6570\u76ee](/solution/1500-1599/1546.Maximum%20Number%20of%20Non-Overlapping%20Subarrays%20With%20Sum%20Equals%20Target/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1546](https://leetcode.com/problems/maximum-number-of-non-overlapping-subarrays-with-sum-equals-target)", "[Maximum Number of Non-Overlapping Subarrays With Sum Equals Target](/solution/1500-1599/1546.Maximum%20Number%20of%20Non-Overlapping%20Subarrays%20With%20Sum%20Equals%20Target/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "1648", "frontend_question_id": "1541", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-insertions-to-balance-a-parentheses-string", "url_en": "https://leetcode.com/problems/minimum-insertions-to-balance-a-parentheses-string", "relative_path_cn": "/solution/1500-1599/1541.Minimum%20Insertions%20to%20Balance%20a%20Parentheses%20String/README.md", "relative_path_en": "/solution/1500-1599/1541.Minimum%20Insertions%20to%20Balance%20a%20Parentheses%20String/README_EN.md", "title_cn": "\u5e73\u8861\u62ec\u53f7\u5b57\u7b26\u4e32\u7684\u6700\u5c11\u63d2\u5165\u6b21\u6570", "title_en": "Minimum Insertions to Balance a Parentheses String", "question_title_slug": "minimum-insertions-to-balance-a-parentheses-string", "content_en": "

    Given a parentheses string s containing only the characters '(' and ')'. A parentheses string is balanced if:

    \n\n
      \n\t
    • Any left parenthesis '(' must have a corresponding two consecutive right parenthesis '))'.
    • \n\t
    • Left parenthesis '(' must go before the corresponding two consecutive right parenthesis '))'.
    • \n
    \n\n

    In other words, we treat '(' as openning parenthesis and '))' as closing parenthesis.

    \n\n

    For example, "())", "())(())))" and "(())())))" are balanced, ")()", "()))" and "(()))" are not balanced.

    \n\n

    You can insert the characters '(' and ')' at any position of the string to balance it if needed.

    \n\n

    Return the minimum number of insertions needed to make s balanced.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "(()))"\nOutput: 1\nExplanation: The second '(' has two matching '))', but the first '(' has only ')' matching. We need to to add one more ')' at the end of the string to be "(())))" which is balanced.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "())"\nOutput: 0\nExplanation: The string is already balanced.\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "))())("\nOutput: 3\nExplanation: Add '(' to match the first '))', Add '))' to match the last '('.\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "(((((("\nOutput: 12\nExplanation: Add 12 ')' to balance the string.\n
    \n\n

    Example 5:

    \n\n
    \nInput: s = ")))))))"\nOutput: 5\nExplanation: Add 4 '(' at the beginning of the string and one ')' at the end. The string becomes "(((())))))))".\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 10^5
    • \n\t
    • s consists of '(' and ')' only.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u62ec\u53f7\u5b57\u7b26\u4e32 s \uff0c\u5b83\u53ea\u5305\u542b\u5b57\u7b26 '(' \u548c ')' \u3002\u4e00\u4e2a\u62ec\u53f7\u5b57\u7b26\u4e32\u88ab\u79f0\u4e3a\u5e73\u8861\u7684\u5f53\u5b83\u6ee1\u8db3\uff1a

    \n\n
      \n\t
    • \u4efb\u4f55\u5de6\u62ec\u53f7 '(' \u5fc5\u987b\u5bf9\u5e94\u4e24\u4e2a\u8fde\u7eed\u7684\u53f3\u62ec\u53f7 '))' \u3002
    • \n\t
    • \u5de6\u62ec\u53f7 '(' \u5fc5\u987b\u5728\u5bf9\u5e94\u7684\u8fde\u7eed\u4e24\u4e2a\u53f3\u62ec\u53f7 '))' \u4e4b\u524d\u3002
    • \n
    \n\n

    \u6bd4\u65b9\u8bf4 "())"\uff0c "())(())))" \u548c "(())())))" \u90fd\u662f\u5e73\u8861\u7684\uff0c ")()"\uff0c "()))" \u548c "(()))" \u90fd\u662f\u4e0d\u5e73\u8861\u7684\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u5728\u4efb\u610f\u4f4d\u7f6e\u63d2\u5165\u5b57\u7b26 '(' \u548c ')' \u4f7f\u5b57\u7b26\u4e32\u5e73\u8861\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u8ba9 s \u5e73\u8861\u7684\u6700\u5c11\u63d2\u5165\u6b21\u6570\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1as = "(()))"\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u7b2c\u4e8c\u4e2a\u5de6\u62ec\u53f7\u6709\u4e0e\u4e4b\u5339\u914d\u7684\u4e24\u4e2a\u53f3\u62ec\u53f7\uff0c\u4f46\u662f\u7b2c\u4e00\u4e2a\u5de6\u62ec\u53f7\u53ea\u6709\u4e00\u4e2a\u53f3\u62ec\u53f7\u3002\u6211\u4eec\u9700\u8981\u5728\u5b57\u7b26\u4e32\u7ed3\u5c3e\u989d\u5916\u589e\u52a0\u4e00\u4e2a ')' \u4f7f\u5b57\u7b26\u4e32\u53d8\u6210\u5e73\u8861\u5b57\u7b26\u4e32 "(())))" \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1as = "())"\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u5b57\u7b26\u4e32\u5df2\u7ecf\u5e73\u8861\u4e86\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1as = "))())("\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6dfb\u52a0 '(' \u53bb\u5339\u914d\u6700\u5f00\u5934\u7684 '))' \uff0c\u7136\u540e\u6dfb\u52a0 '))' \u53bb\u5339\u914d\u6700\u540e\u4e00\u4e2a '(' \u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1as = "(((((("\n\u8f93\u51fa\uff1a12\n\u89e3\u91ca\uff1a\u6dfb\u52a0 12 \u4e2a ')' \u5f97\u5230\u5e73\u8861\u5b57\u7b26\u4e32\u3002\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1as = ")))))))"\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u5728\u5b57\u7b26\u4e32\u5f00\u5934\u6dfb\u52a0 4 \u4e2a '(' \u5e76\u5728\u7ed3\u5c3e\u6dfb\u52a0 1 \u4e2a ')' \uff0c\u5b57\u7b26\u4e32\u53d8\u6210\u5e73\u8861\u5b57\u7b26\u4e32 "(((())))))))" \u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 10^5
    • \n\t
    • s \u53ea\u5305\u542b '(' \u548c ')' \u3002
    • \n
    \n", "tags_en": ["Stack", "String"], "tags_cn": ["\u6808", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minInsertions(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minInsertions(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minInsertions(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minInsertions(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minInsertions(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinInsertions(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar minInsertions = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef min_insertions(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minInsertions(_ s: String) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minInsertions(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minInsertions(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minInsertions(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_insertions(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function minInsertions($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minInsertions(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-insertions s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1541](https://leetcode-cn.com/problems/minimum-insertions-to-balance-a-parentheses-string)", "[\u5e73\u8861\u62ec\u53f7\u5b57\u7b26\u4e32\u7684\u6700\u5c11\u63d2\u5165\u6b21\u6570](/solution/1500-1599/1541.Minimum%20Insertions%20to%20Balance%20a%20Parentheses%20String/README.md)", "`\u6808`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1541](https://leetcode.com/problems/minimum-insertions-to-balance-a-parentheses-string)", "[Minimum Insertions to Balance a Parentheses String](/solution/1500-1599/1541.Minimum%20Insertions%20to%20Balance%20a%20Parentheses%20String/README_EN.md)", "`Stack`,`String`", "Medium", ""]}, {"question_id": "1647", "frontend_question_id": "1540", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/can-convert-string-in-k-moves", "url_en": "https://leetcode.com/problems/can-convert-string-in-k-moves", "relative_path_cn": "/solution/1500-1599/1540.Can%20Convert%20String%20in%20K%20Moves/README.md", "relative_path_en": "/solution/1500-1599/1540.Can%20Convert%20String%20in%20K%20Moves/README_EN.md", "title_cn": "K \u6b21\u64cd\u4f5c\u8f6c\u53d8\u5b57\u7b26\u4e32", "title_en": "Can Convert String in K Moves", "question_title_slug": "can-convert-string-in-k-moves", "content_en": "

    Given two strings s and t, your goal is to convert s into t in k moves or less.

    \n\n

    During the ith (1 <= i <= kmove you can:

    \n\n
      \n\t
    • Choose any index j (1-indexed) from s, such that 1 <= j <= s.length and j has not been chosen in any previous move, and shift the character at that index i times.
    • \n\t
    • Do nothing.
    • \n
    \n\n

    Shifting a character means replacing it by the next letter in the alphabet (wrapping around so that 'z' becomes 'a'). Shifting a character by i means applying the shift operations i times.

    \n\n

    Remember that any index j can be picked at most once.

    \n\n

    Return true if it's possible to convert s into t in no more than k moves, otherwise return false.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "input", t = "ouput", k = 9\nOutput: true\nExplanation: In the 6th move, we shift 'i' 6 times to get 'o'. And in the 7th move we shift 'n' to get 'u'.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "abc", t = "bcd", k = 10\nOutput: false\nExplanation: We need to shift each character in s one time to convert it into t. We can shift 'a' to 'b' during the 1st move. However, there is no way to shift the other characters in the remaining moves to obtain t from s.\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "aab", t = "bbb", k = 27\nOutput: true\nExplanation: In the 1st move, we shift the first 'a' 1 time to get 'b'. In the 27th move, we shift the second 'a' 27 times to get 'b'.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length, t.length <= 10^5
    • \n\t
    • 0 <= k <= 10^9
    • \n\t
    • s, t contain only lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u5b57\u7b26\u4e32 s \u548c t \uff0c\u4f60\u7684\u76ee\u6807\u662f\u5728 k \u6b21\u64cd\u4f5c\u4ee5\u5185\u628a\u5b57\u7b26\u4e32 s \u8f6c\u53d8\u6210 t \u3002

    \n\n

    \u5728\u7b2c i \u6b21\u64cd\u4f5c\u65f6\uff081 <= i <= k\uff09\uff0c\u4f60\u53ef\u4ee5\u9009\u62e9\u8fdb\u884c\u5982\u4e0b\u64cd\u4f5c\uff1a

    \n\n
      \n\t
    • \u9009\u62e9\u5b57\u7b26\u4e32 s \u4e2d\u6ee1\u8db3 1 <= j <= s.length \u4e14\u4e4b\u524d\u672a\u88ab\u9009\u8fc7\u7684\u4efb\u610f\u4e0b\u6807 j \uff08\u4e0b\u6807\u4ece 1 \u5f00\u59cb\uff09\uff0c\u5e76\u5c06\u6b64\u4f4d\u7f6e\u7684\u5b57\u7b26\u5207\u6362 i \u6b21\u3002
    • \n\t
    • \u4e0d\u8fdb\u884c\u4efb\u4f55\u64cd\u4f5c\u3002
    • \n
    \n\n

    \u5207\u6362 1 \u6b21\u5b57\u7b26\u7684\u610f\u601d\u662f\u7528\u5b57\u6bcd\u8868\u4e2d\u8be5\u5b57\u6bcd\u7684\u4e0b\u4e00\u4e2a\u5b57\u6bcd\u66ff\u6362\u5b83\uff08\u5b57\u6bcd\u8868\u73af\u72b6\u63a5\u8d77\u6765\uff0c\u6240\u4ee5 'z' \u5207\u6362\u540e\u4f1a\u53d8\u6210 'a'\uff09\u3002

    \n\n

    \u8bf7\u8bb0\u4f4f\u4efb\u610f\u4e00\u4e2a\u4e0b\u6807 j \u6700\u591a\u53ea\u80fd\u88ab\u64cd\u4f5c 1 \u6b21\u3002

    \n\n

    \u5982\u679c\u5728\u4e0d\u8d85\u8fc7 k \u6b21\u64cd\u4f5c\u5185\u53ef\u4ee5\u628a\u5b57\u7b26\u4e32 s \u8f6c\u53d8\u6210 t \uff0c\u90a3\u4e48\u8bf7\u4f60\u8fd4\u56de true \uff0c\u5426\u5219\u8bf7\u4f60\u8fd4\u56de false \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1as = "input", t = "ouput", k = 9\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u7b2c 6 \u6b21\u64cd\u4f5c\u65f6\uff0c\u6211\u4eec\u5c06 'i' \u5207\u6362 6 \u6b21\u5f97\u5230 'o' \u3002\u7b2c 7 \u6b21\u64cd\u4f5c\u65f6\uff0c\u6211\u4eec\u5c06 'n' \u5207\u6362 7 \u6b21\u5f97\u5230 'u' \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1as = "abc", t = "bcd", k = 10\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u6211\u4eec\u9700\u8981\u5c06\u6bcf\u4e2a\u5b57\u7b26\u5207\u6362 1 \u6b21\u624d\u80fd\u5f97\u5230 t \u3002\u6211\u4eec\u53ef\u4ee5\u5728\u7b2c 1 \u6b21\u64cd\u4f5c\u65f6\u5c06 'a' \u5207\u6362\u6210 'b' \uff0c\u4f46\u53e6\u5916 2 \u4e2a\u5b57\u6bcd\u5728\u5269\u4f59\u64cd\u4f5c\u4e2d\u65e0\u6cd5\u518d\u8f6c\u53d8\u4e3a t \u4e2d\u5bf9\u5e94\u5b57\u6bcd\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1as = "aab", t = "bbb", k = 27\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u7b2c 1 \u6b21\u64cd\u4f5c\u65f6\uff0c\u6211\u4eec\u5c06\u7b2c\u4e00\u4e2a 'a' \u5207\u6362 1 \u6b21\u5f97\u5230 'b' \u3002\u5728\u7b2c 27 \u6b21\u64cd\u4f5c\u65f6\uff0c\u6211\u4eec\u5c06\u7b2c\u4e8c\u4e2a\u5b57\u6bcd 'a' \u5207\u6362 27 \u6b21\u5f97\u5230 'b' \u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length, t.length <= 10^5
    • \n\t
    • 0 <= k <= 10^9
    • \n\t
    • s \u548c t \u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    • \n
    \n", "tags_en": ["Greedy", "String"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canConvertString(string s, string t, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canConvertString(String s, String t, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canConvertString(self, s, t, k):\n \"\"\"\n :type s: str\n :type t: str\n :type k: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canConvertString(self, s: str, t: str, k: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canConvertString(char * s, char * t, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanConvertString(string s, string t, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string} t\n * @param {number} k\n * @return {boolean}\n */\nvar canConvertString = function(s, t, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String} t\n# @param {Integer} k\n# @return {Boolean}\ndef can_convert_string(s, t, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canConvertString(_ s: String, _ t: String, _ k: Int) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canConvertString(s string, t string, k int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canConvertString(s: String, t: String, k: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canConvertString(s: String, t: String, k: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_convert_string(s: String, t: String, k: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String $t\n * @param Integer $k\n * @return Boolean\n */\n function canConvertString($s, $t, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canConvertString(s: string, t: string, k: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-convert-string s t k)\n (-> string? string? exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1540](https://leetcode-cn.com/problems/can-convert-string-in-k-moves)", "[K \u6b21\u64cd\u4f5c\u8f6c\u53d8\u5b57\u7b26\u4e32](/solution/1500-1599/1540.Can%20Convert%20String%20in%20K%20Moves/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1540](https://leetcode.com/problems/can-convert-string-in-k-moves)", "[Can Convert String in K Moves](/solution/1500-1599/1540.Can%20Convert%20String%20in%20K%20Moves/README_EN.md)", "`Greedy`,`String`", "Medium", ""]}, {"question_id": "1646", "frontend_question_id": "1539", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/kth-missing-positive-number", "url_en": "https://leetcode.com/problems/kth-missing-positive-number", "relative_path_cn": "/solution/1500-1599/1539.Kth%20Missing%20Positive%20Number/README.md", "relative_path_en": "/solution/1500-1599/1539.Kth%20Missing%20Positive%20Number/README_EN.md", "title_cn": "\u7b2c k \u4e2a\u7f3a\u5931\u7684\u6b63\u6574\u6570", "title_en": "Kth Missing Positive Number", "question_title_slug": "kth-missing-positive-number", "content_en": "

    Given an array arr of positive integers sorted in a strictly increasing order, and an integer k.

    \n\n

    Find the kth positive integer that is missing from this array.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr = [2,3,4,7,11], k = 5\nOutput: 9\nExplanation: The missing positive integers are [1,5,6,8,9,10,12,13,...]. The 5th missing positive integer is 9.\n
    \n\n

    Example 2:

    \n\n
    \nInput: arr = [1,2,3,4], k = 2\nOutput: 6\nExplanation: The missing positive integers are [5,6,7,...]. The 2nd missing positive integer is 6.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= arr.length <= 1000
    • \n\t
    • 1 <= arr[i] <= 1000
    • \n\t
    • 1 <= k <= 1000
    • \n\t
    • arr[i] < arr[j] for 1 <= i < j <= arr.length
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a \u4e25\u683c\u5347\u5e8f\u6392\u5217 \u7684\u6b63\u6574\u6570\u6570\u7ec4 arr \u548c\u4e00\u4e2a\u6574\u6570 k \u3002

    \n\n

    \u8bf7\u4f60\u627e\u5230\u8fd9\u4e2a\u6570\u7ec4\u91cc\u7b2c k \u4e2a\u7f3a\u5931\u7684\u6b63\u6574\u6570\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [2,3,4,7,11], k = 5\n\u8f93\u51fa\uff1a9\n\u89e3\u91ca\uff1a\u7f3a\u5931\u7684\u6b63\u6574\u6570\u5305\u62ec [1,5,6,8,9,10,12,13,...] \u3002\u7b2c 5 \u4e2a\u7f3a\u5931\u7684\u6b63\u6574\u6570\u4e3a 9 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [1,2,3,4], k = 2\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u7f3a\u5931\u7684\u6b63\u6574\u6570\u5305\u62ec [5,6,7,...] \u3002\u7b2c 2 \u4e2a\u7f3a\u5931\u7684\u6b63\u6574\u6570\u4e3a 6 \u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= arr.length <= 1000
    • \n\t
    • 1 <= arr[i] <= 1000
    • \n\t
    • 1 <= k <= 1000
    • \n\t
    • \u5bf9\u4e8e\u6240\u6709 1 <= i < j <= arr.length \u7684 i \u548c j \u6ee1\u8db3 arr[i] < arr[j] 
    • \n
    \n", "tags_en": ["Array", "Hash Table"], "tags_cn": ["\u6570\u7ec4", "\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findKthPositive(vector& arr, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findKthPositive(int[] arr, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findKthPositive(self, arr, k):\n \"\"\"\n :type arr: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findKthPositive(self, arr: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findKthPositive(int* arr, int arrSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindKthPositive(int[] arr, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @param {number} k\n * @return {number}\n */\nvar findKthPositive = function(arr, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @param {Integer} k\n# @return {Integer}\ndef find_kth_positive(arr, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findKthPositive(_ arr: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findKthPositive(arr []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findKthPositive(arr: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findKthPositive(arr: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_kth_positive(arr: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @param Integer $k\n * @return Integer\n */\n function findKthPositive($arr, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findKthPositive(arr: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-kth-positive arr k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1539](https://leetcode-cn.com/problems/kth-missing-positive-number)", "[\u7b2c k \u4e2a\u7f3a\u5931\u7684\u6b63\u6574\u6570](/solution/1500-1599/1539.Kth%20Missing%20Positive%20Number/README.md)", "`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[1539](https://leetcode.com/problems/kth-missing-positive-number)", "[Kth Missing Positive Number](/solution/1500-1599/1539.Kth%20Missing%20Positive%20Number/README_EN.md)", "`Array`,`Hash Table`", "Easy", ""]}, {"question_id": "1645", "frontend_question_id": "1521", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-a-value-of-a-mysterious-function-closest-to-target", "url_en": "https://leetcode.com/problems/find-a-value-of-a-mysterious-function-closest-to-target", "relative_path_cn": "/solution/1500-1599/1521.Find%20a%20Value%20of%20a%20Mysterious%20Function%20Closest%20to%20Target/README.md", "relative_path_en": "/solution/1500-1599/1521.Find%20a%20Value%20of%20a%20Mysterious%20Function%20Closest%20to%20Target/README_EN.md", "title_cn": "\u627e\u5230\u6700\u63a5\u8fd1\u76ee\u6807\u503c\u7684\u51fd\u6570\u503c", "title_en": "Find a Value of a Mysterious Function Closest to Target", "question_title_slug": "find-a-value-of-a-mysterious-function-closest-to-target", "content_en": "

    \"\"

    \n\n

    Winston was given the above mysterious function func. He has an integer array arr and an integer target and he wants to find the values l and r that make the value |func(arr, l, r) - target| minimum possible.

    \n\n

    Return the minimum possible value of |func(arr, l, r) - target|.

    \n\n

    Notice that func should be called with the values l and r where 0 <= l, r < arr.length.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr = [9,12,3,7,15], target = 5\nOutput: 2\nExplanation: Calling func with all the pairs of [l,r] = [[0,0],[1,1],[2,2],[3,3],[4,4],[0,1],[1,2],[2,3],[3,4],[0,2],[1,3],[2,4],[0,3],[1,4],[0,4]], Winston got the following results [9,12,3,7,15,8,0,3,7,0,0,3,0,0,0]. The value closest to 5 is 7 and 3, thus the minimum difference is 2.\n
    \n\n

    Example 2:

    \n\n
    \nInput: arr = [1000000,1000000,1000000], target = 1\nOutput: 999999\nExplanation: Winston called the func with all possible values of [l,r] and he always got 1000000, thus the min difference is 999999.\n
    \n\n

    Example 3:

    \n\n
    \nInput: arr = [1,2,4,8,16], target = 0\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= arr.length <= 105
    • \n\t
    • 1 <= arr[i] <= 106
    • \n\t
    • 0 <= target <= 107
    • \n
    \n", "content_cn": "

    \"\"

    \n\n

    Winston \u6784\u9020\u4e86\u4e00\u4e2a\u5982\u4e0a\u6240\u793a\u7684\u51fd\u6570 func \u3002\u4ed6\u6709\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr \u548c\u4e00\u4e2a\u6574\u6570 target \uff0c\u4ed6\u60f3\u627e\u5230\u8ba9 |func(arr, l, r) - target| \u6700\u5c0f\u7684 l \u548c r \u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de |func(arr, l, r) - target| \u7684\u6700\u5c0f\u503c\u3002

    \n\n

    \u8bf7\u6ce8\u610f\uff0c func \u7684\u8f93\u5165\u53c2\u6570 l \u548c r \u9700\u8981\u6ee1\u8db3 0 <= l, r < arr.length \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [9,12,3,7,15], target = 5\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6240\u6709\u53ef\u80fd\u7684 [l,r] \u6570\u5bf9\u5305\u62ec [[0,0],[1,1],[2,2],[3,3],[4,4],[0,1],[1,2],[2,3],[3,4],[0,2],[1,3],[2,4],[0,3],[1,4],[0,4]]\uff0c Winston \u5f97\u5230\u7684\u76f8\u5e94\u7ed3\u679c\u4e3a [9,12,3,7,15,8,0,3,7,0,0,3,0,0,0] \u3002\u6700\u63a5\u8fd1 5 \u7684\u503c\u662f 7 \u548c 3\uff0c\u6240\u4ee5\u6700\u5c0f\u5dee\u503c\u4e3a 2 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [1000000,1000000,1000000], target = 1\n\u8f93\u51fa\uff1a999999\n\u89e3\u91ca\uff1aWinston \u8f93\u5165\u51fd\u6570\u7684\u6240\u6709\u53ef\u80fd [l,r] \u6570\u5bf9\u5f97\u5230\u7684\u51fd\u6570\u503c\u90fd\u4e3a 1000000 \uff0c\u6240\u4ee5\u6700\u5c0f\u5dee\u503c\u4e3a 999999 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [1,2,4,8,16], target = 0\n\u8f93\u51fa\uff1a0\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= arr.length <= 10^5
    • \n\t
    • 1 <= arr[i] <= 10^6
    • \n\t
    • 0 <= target <= 10^7
    • \n
    \n", "tags_en": ["Bit Manipulation", "Segment Tree", "Binary Search"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u7ebf\u6bb5\u6811", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int closestToTarget(vector& arr, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int closestToTarget(int[] arr, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def closestToTarget(self, arr, target):\n \"\"\"\n :type arr: List[int]\n :type target: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def closestToTarget(self, arr: List[int], target: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint closestToTarget(int* arr, int arrSize, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ClosestToTarget(int[] arr, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @param {number} target\n * @return {number}\n */\nvar closestToTarget = function(arr, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @param {Integer} target\n# @return {Integer}\ndef closest_to_target(arr, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func closestToTarget(_ arr: [Int], _ target: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func closestToTarget(arr []int, target int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def closestToTarget(arr: Array[Int], target: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun closestToTarget(arr: IntArray, target: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn closest_to_target(arr: Vec, target: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @param Integer $target\n * @return Integer\n */\n function closestToTarget($arr, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function closestToTarget(arr: number[], target: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (closest-to-target arr target)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1521](https://leetcode-cn.com/problems/find-a-value-of-a-mysterious-function-closest-to-target)", "[\u627e\u5230\u6700\u63a5\u8fd1\u76ee\u6807\u503c\u7684\u51fd\u6570\u503c](/solution/1500-1599/1521.Find%20a%20Value%20of%20a%20Mysterious%20Function%20Closest%20to%20Target/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u7ebf\u6bb5\u6811`,`\u4e8c\u5206\u67e5\u627e`", "\u56f0\u96be", ""], "md_table_row_en": ["[1521](https://leetcode.com/problems/find-a-value-of-a-mysterious-function-closest-to-target)", "[Find a Value of a Mysterious Function Closest to Target](/solution/1500-1599/1521.Find%20a%20Value%20of%20a%20Mysterious%20Function%20Closest%20to%20Target/README_EN.md)", "`Bit Manipulation`,`Segment Tree`,`Binary Search`", "Hard", ""]}, {"question_id": "1644", "frontend_question_id": "1520", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-number-of-non-overlapping-substrings", "url_en": "https://leetcode.com/problems/maximum-number-of-non-overlapping-substrings", "relative_path_cn": "/solution/1500-1599/1520.Maximum%20Number%20of%20Non-Overlapping%20Substrings/README.md", "relative_path_en": "/solution/1500-1599/1520.Maximum%20Number%20of%20Non-Overlapping%20Substrings/README_EN.md", "title_cn": "\u6700\u591a\u7684\u4e0d\u91cd\u53e0\u5b50\u5b57\u7b26\u4e32", "title_en": "Maximum Number of Non-Overlapping Substrings", "question_title_slug": "maximum-number-of-non-overlapping-substrings", "content_en": "

    Given a string s of lowercase letters, you need to find the maximum number of non-empty substrings of s that meet the following conditions:

    \n\n
      \n\t
    1. The substrings do not overlap, that is for any two substrings s[i..j] and s[k..l], either j < k or i > l is true.
    2. \n\t
    3. A substring that contains a certain character c must also contain all occurrences of c.
    4. \n
    \n\n

    Find the maximum number of substrings that meet the above conditions. If there are multiple solutions with the same number of substrings, return the one with minimum total length. It can be shown that there exists a unique solution of minimum total length.

    \n\n

    Notice that you can return the substrings in any order.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "adefaddaccc"\nOutput: ["e","f","ccc"]\nExplanation: The following are all the possible substrings that meet the conditions:\n[\n  "adefaddaccc"\n  "adefadda",\n  "ef",\n  "e",\n  "f",\n  "ccc",\n]\nIf we choose the first string, we cannot choose anything else and we'd get only 1. If we choose "adefadda", we are left with "ccc" which is the only one that doesn't overlap, thus obtaining 2 substrings. Notice also, that it's not optimal to choose "ef" since it can be split into two. Therefore, the optimal way is to choose ["e","f","ccc"] which gives us 3 substrings. No other solution of the same number of substrings exist.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "abbaccd"\nOutput: ["d","bb","cc"]\nExplanation: Notice that while the set of substrings ["d","abba","cc"] also has length 3, it's considered incorrect since it has larger total length.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 10^5
    • \n\t
    • s contains only lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd\u7684\u5b57\u7b26\u4e32 s \uff0c\u4f60\u9700\u8981\u627e\u5230 s \u4e2d\u6700\u591a\u6570\u76ee\u7684\u975e\u7a7a\u5b50\u5b57\u7b26\u4e32\uff0c\u6ee1\u8db3\u5982\u4e0b\u6761\u4ef6\uff1a

    \n\n
      \n\t
    1. \u8fd9\u4e9b\u5b57\u7b26\u4e32\u4e4b\u95f4\u4e92\u4e0d\u91cd\u53e0\uff0c\u4e5f\u5c31\u662f\u8bf4\u5bf9\u4e8e\u4efb\u610f\u4e24\u4e2a\u5b50\u5b57\u7b26\u4e32 s[i..j] \u548c s[k..l] \uff0c\u8981\u4e48 j < k \u8981\u4e48 i > l \u3002
    2. \n\t
    3. \u5982\u679c\u4e00\u4e2a\u5b50\u5b57\u7b26\u4e32\u5305\u542b\u5b57\u7b26 char \uff0c\u90a3\u4e48 s \u4e2d\u6240\u6709 char \u5b57\u7b26\u90fd\u5e94\u8be5\u5728\u8fd9\u4e2a\u5b50\u5b57\u7b26\u4e32\u4e2d\u3002
    4. \n
    \n\n

    \u8bf7\u4f60\u627e\u5230\u6ee1\u8db3\u4e0a\u8ff0\u6761\u4ef6\u7684\u6700\u591a\u5b50\u5b57\u7b26\u4e32\u6570\u76ee\u3002\u5982\u679c\u6709\u591a\u4e2a\u89e3\u6cd5\u6709\u76f8\u540c\u7684\u5b50\u5b57\u7b26\u4e32\u6570\u76ee\uff0c\u8bf7\u8fd4\u56de\u8fd9\u4e9b\u5b50\u5b57\u7b26\u4e32\u603b\u957f\u5ea6\u6700\u5c0f\u7684\u4e00\u4e2a\u89e3\u3002\u53ef\u4ee5\u8bc1\u660e\u6700\u5c0f\u603b\u957f\u5ea6\u89e3\u662f\u552f\u4e00\u7684\u3002

    \n\n

    \u8bf7\u6ce8\u610f\uff0c\u4f60\u53ef\u4ee5\u4ee5 \u4efb\u610f \u987a\u5e8f\u8fd4\u56de\u6700\u4f18\u89e3\u7684\u5b50\u5b57\u7b26\u4e32\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1as = "adefaddaccc"\n\u8f93\u51fa\uff1a["e","f","ccc"]\n\u89e3\u91ca\uff1a\u4e0b\u9762\u4e3a\u6240\u6709\u6ee1\u8db3\u7b2c\u4e8c\u4e2a\u6761\u4ef6\u7684\u5b50\u5b57\u7b26\u4e32\uff1a\n[\n  "adefaddaccc"\n  "adefadda",\n  "ef",\n  "e",\n  "f",\n  "ccc",\n]\n\u5982\u679c\u6211\u4eec\u9009\u62e9\u7b2c\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u90a3\u4e48\u6211\u4eec\u65e0\u6cd5\u518d\u9009\u62e9\u5176\u4ed6\u4efb\u4f55\u5b57\u7b26\u4e32\uff0c\u6240\u4ee5\u7b54\u6848\u4e3a 1 \u3002\u5982\u679c\u6211\u4eec\u9009\u62e9 "adefadda" \uff0c\u5269\u4e0b\u5b50\u5b57\u7b26\u4e32\u4e2d\u6211\u4eec\u53ea\u53ef\u4ee5\u9009\u62e9 "ccc" \uff0c\u5b83\u662f\u552f\u4e00\u4e0d\u91cd\u53e0\u7684\u5b50\u5b57\u7b26\u4e32\uff0c\u6240\u4ee5\u7b54\u6848\u4e3a 2 \u3002\u540c\u65f6\u6211\u4eec\u53ef\u4ee5\u53d1\u73b0\uff0c\u9009\u62e9 "ef" \u4e0d\u662f\u6700\u4f18\u7684\uff0c\u56e0\u4e3a\u5b83\u53ef\u4ee5\u88ab\u62c6\u5206\u6210 2 \u4e2a\u5b50\u5b57\u7b26\u4e32\u3002\u6240\u4ee5\u6700\u4f18\u89e3\u662f\u9009\u62e9 ["e","f","ccc"] \uff0c\u7b54\u6848\u4e3a 3 \u3002\u4e0d\u5b58\u5728\u522b\u7684\u76f8\u540c\u6570\u76ee\u5b50\u5b57\u7b26\u4e32\u89e3\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1as = "abbaccd"\n\u8f93\u51fa\uff1a["d","bb","cc"]\n\u89e3\u91ca\uff1a\u6ce8\u610f\u5230\u89e3 ["d","abba","cc"] \u7b54\u6848\u4e5f\u4e3a 3 \uff0c\u4f46\u5b83\u4e0d\u662f\u6700\u4f18\u89e3\uff0c\u56e0\u4e3a\u5b83\u7684\u603b\u957f\u5ea6\u66f4\u957f\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 10^5
    • \n\t
    • s \u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector maxNumOfSubstrings(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List maxNumOfSubstrings(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxNumOfSubstrings(self, s):\n \"\"\"\n :type s: str\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxNumOfSubstrings(self, s: str) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** maxNumOfSubstrings(char * s, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList MaxNumOfSubstrings(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string[]}\n */\nvar maxNumOfSubstrings = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String[]}\ndef max_num_of_substrings(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxNumOfSubstrings(_ s: String) -> [String] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxNumOfSubstrings(s string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxNumOfSubstrings(s: String): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxNumOfSubstrings(s: String): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_num_of_substrings(s: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String[]\n */\n function maxNumOfSubstrings($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxNumOfSubstrings(s: string): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-num-of-substrings s)\n (-> string? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1520](https://leetcode-cn.com/problems/maximum-number-of-non-overlapping-substrings)", "[\u6700\u591a\u7684\u4e0d\u91cd\u53e0\u5b50\u5b57\u7b26\u4e32](/solution/1500-1599/1520.Maximum%20Number%20of%20Non-Overlapping%20Substrings/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[1520](https://leetcode.com/problems/maximum-number-of-non-overlapping-substrings)", "[Maximum Number of Non-Overlapping Substrings](/solution/1500-1599/1520.Maximum%20Number%20of%20Non-Overlapping%20Substrings/README_EN.md)", "`Greedy`", "Hard", ""]}, {"question_id": "1643", "frontend_question_id": "1519", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-nodes-in-the-sub-tree-with-the-same-label", "url_en": "https://leetcode.com/problems/number-of-nodes-in-the-sub-tree-with-the-same-label", "relative_path_cn": "/solution/1500-1599/1519.Number%20of%20Nodes%20in%20the%20Sub-Tree%20With%20the%20Same%20Label/README.md", "relative_path_en": "/solution/1500-1599/1519.Number%20of%20Nodes%20in%20the%20Sub-Tree%20With%20the%20Same%20Label/README_EN.md", "title_cn": "\u5b50\u6811\u4e2d\u6807\u7b7e\u76f8\u540c\u7684\u8282\u70b9\u6570", "title_en": "Number of Nodes in the Sub-Tree With the Same Label", "question_title_slug": "number-of-nodes-in-the-sub-tree-with-the-same-label", "content_en": "

    Given a tree (i.e. a connected, undirected graph that has no cycles) consisting of n nodes numbered from 0 to n - 1 and exactly n - 1 edges. The root of the tree is the node 0, and each node of the tree has a label which is a lower-case character given in the string labels (i.e. The node with the number i has the label labels[i]).

    \r\n\r\n

    The edges array is given on the form edges[i] = [ai, bi], which means there is an edge between nodes ai and bi in the tree.

    \r\n\r\n

    Return an array of size n where ans[i] is the number of nodes in the subtree of the ith node which have the same label as node i.

    \r\n\r\n

    A subtree of a tree T is the tree consisting of a node in T and all of its descendant nodes.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\"\"\r\n
    \r\nInput: n = 7, edges = [[0,1],[0,2],[1,4],[1,5],[2,3],[2,6]], labels = "abaedcd"\r\nOutput: [2,1,1,1,1,1,1]\r\nExplanation: Node 0 has label 'a' and its sub-tree has node 2 with label 'a' as well, thus the answer is 2. Notice that any node is part of its sub-tree.\r\nNode 1 has a label 'b'. The sub-tree of node 1 contains nodes 1,4 and 5, as nodes 4 and 5 have different labels than node 1, the answer is just 1 (the node itself).\r\n
    \r\n\r\n

    Example 2:

    \r\n\"\"\r\n
    \r\nInput: n = 4, edges = [[0,1],[1,2],[0,3]], labels = "bbbb"\r\nOutput: [4,2,1,1]\r\nExplanation: The sub-tree of node 2 contains only node 2, so the answer is 1.\r\nThe sub-tree of node 3 contains only node 3, so the answer is 1.\r\nThe sub-tree of node 1 contains nodes 1 and 2, both have label 'b', thus the answer is 2.\r\nThe sub-tree of node 0 contains nodes 0, 1, 2 and 3, all with label 'b', thus the answer is 4.\r\n
    \r\n\r\n

    Example 3:

    \r\n\"\"\r\n
    \r\nInput: n = 5, edges = [[0,1],[0,2],[1,3],[0,4]], labels = "aabab"\r\nOutput: [3,2,1,1,1]\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: n = 6, edges = [[0,1],[0,2],[1,3],[3,4],[4,5]], labels = "cbabaa"\r\nOutput: [1,2,1,1,2,1]\r\n
    \r\n\r\n

    Example 5:

    \r\n\r\n
    \r\nInput: n = 7, edges = [[0,1],[1,2],[2,3],[3,4],[4,5],[5,6]], labels = "aaabaaa"\r\nOutput: [6,5,4,1,3,2,1]\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= n <= 10^5
    • \r\n\t
    • edges.length == n - 1
    • \r\n\t
    • edges[i].length == 2
    • \r\n\t
    • 0 <= ai, bi < n
    • \r\n\t
    • ai != bi
    • \r\n\t
    • labels.length == n
    • \r\n\t
    • labels is consisting of only of lower-case English letters.
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u68f5\u6811\uff08\u5373\uff0c\u4e00\u4e2a\u8fde\u901a\u7684\u65e0\u73af\u65e0\u5411\u56fe\uff09\uff0c\u8fd9\u68f5\u6811\u7531\u7f16\u53f7\u4ece 0  \u5230 n - 1 \u7684 n \u4e2a\u8282\u70b9\u7ec4\u6210\uff0c\u4e14\u6070\u597d\u6709 n - 1 \u6761 edges \u3002\u6811\u7684\u6839\u8282\u70b9\u4e3a\u8282\u70b9 0 \uff0c\u6811\u4e0a\u7684\u6bcf\u4e00\u4e2a\u8282\u70b9\u90fd\u6709\u4e00\u4e2a\u6807\u7b7e\uff0c\u4e5f\u5c31\u662f\u5b57\u7b26\u4e32 labels \u4e2d\u7684\u4e00\u4e2a\u5c0f\u5199\u5b57\u7b26\uff08\u7f16\u53f7\u4e3a i \u7684 \u8282\u70b9\u7684\u6807\u7b7e\u5c31\u662f labels[i] \uff09

    \n\n

    \u8fb9\u6570\u7ec4 edges \u4ee5 edges[i] = [ai, bi] \u7684\u5f62\u5f0f\u7ed9\u51fa\uff0c\u8be5\u683c\u5f0f\u8868\u793a\u8282\u70b9 ai \u548c bi \u4e4b\u95f4\u5b58\u5728\u4e00\u6761\u8fb9\u3002

    \n\n

    \u8fd4\u56de\u4e00\u4e2a\u5927\u5c0f\u4e3a n \u7684\u6570\u7ec4\uff0c\u5176\u4e2d ans[i] \u8868\u793a\u7b2c i \u4e2a\u8282\u70b9\u7684\u5b50\u6811\u4e2d\u4e0e\u8282\u70b9 i \u6807\u7b7e\u76f8\u540c\u7684\u8282\u70b9\u6570\u3002

    \n\n

    \u6811 T \u4e2d\u7684\u5b50\u6811\u662f\u7531 T \u4e2d\u7684\u67d0\u4e2a\u8282\u70b9\u53ca\u5176\u6240\u6709\u540e\u4ee3\u8282\u70b9\u7ec4\u6210\u7684\u6811\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 7, edges = [[0,1],[0,2],[1,4],[1,5],[2,3],[2,6]], labels = "abaedcd"\n\u8f93\u51fa\uff1a[2,1,1,1,1,1,1]\n\u89e3\u91ca\uff1a\u8282\u70b9 0 \u7684\u6807\u7b7e\u4e3a 'a' \uff0c\u4ee5 'a' \u4e3a\u6839\u8282\u70b9\u7684\u5b50\u6811\u4e2d\uff0c\u8282\u70b9 2 \u7684\u6807\u7b7e\u4e5f\u662f 'a' \uff0c\u56e0\u6b64\u7b54\u6848\u4e3a 2 \u3002\u6ce8\u610f\u6811\u4e2d\u7684\u6bcf\u4e2a\u8282\u70b9\u90fd\u662f\u8fd9\u68f5\u5b50\u6811\u7684\u4e00\u90e8\u5206\u3002\n\u8282\u70b9 1 \u7684\u6807\u7b7e\u4e3a 'b' \uff0c\u8282\u70b9 1 \u7684\u5b50\u6811\u5305\u542b\u8282\u70b9 1\u30014 \u548c 5\uff0c\u4f46\u662f\u8282\u70b9 4\u30015 \u7684\u6807\u7b7e\u4e0e\u8282\u70b9 1 \u4e0d\u540c\uff0c\u6545\u800c\u7b54\u6848\u4e3a 1\uff08\u5373\uff0c\u8be5\u8282\u70b9\u672c\u8eab\uff09\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 4, edges = [[0,1],[1,2],[0,3]], labels = "bbbb"\n\u8f93\u51fa\uff1a[4,2,1,1]\n\u89e3\u91ca\uff1a\u8282\u70b9 2 \u7684\u5b50\u6811\u4e2d\u53ea\u6709\u8282\u70b9 2 \uff0c\u6240\u4ee5\u7b54\u6848\u4e3a 1 \u3002\n\u8282\u70b9 3 \u7684\u5b50\u6811\u4e2d\u53ea\u6709\u8282\u70b9 3 \uff0c\u6240\u4ee5\u7b54\u6848\u4e3a 1 \u3002\n\u8282\u70b9 1 \u7684\u5b50\u6811\u4e2d\u5305\u542b\u8282\u70b9 1 \u548c 2 \uff0c\u6807\u7b7e\u90fd\u662f 'b' \uff0c\u56e0\u6b64\u7b54\u6848\u4e3a 2 \u3002\n\u8282\u70b9 0 \u7684\u5b50\u6811\u4e2d\u5305\u542b\u8282\u70b9 0\u30011\u30012 \u548c 3\uff0c\u6807\u7b7e\u90fd\u662f 'b'\uff0c\u56e0\u6b64\u7b54\u6848\u4e3a 4 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 5, edges = [[0,1],[0,2],[1,3],[0,4]], labels = "aabab"\n\u8f93\u51fa\uff1a[3,2,1,1,1]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1an = 6, edges = [[0,1],[0,2],[1,3],[3,4],[4,5]], labels = "cbabaa"\n\u8f93\u51fa\uff1a[1,2,1,1,2,1]\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1an = 7, edges = [[0,1],[1,2],[2,3],[3,4],[4,5],[5,6]], labels = "aaabaaa"\n\u8f93\u51fa\uff1a[6,5,4,1,3,2,1]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 10^5
    • \n\t
    • edges.length == n - 1
    • \n\t
    • edges[i].length == 2
    • \n\t
    • 0 <= ai, bi < n
    • \n\t
    • ai != bi
    • \n\t
    • labels.length == n
    • \n\t
    • labels \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n", "tags_en": ["Depth-first Search", "Breadth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector countSubTrees(int n, vector>& edges, string labels) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] countSubTrees(int n, int[][] edges, String labels) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countSubTrees(self, n, edges, labels):\n \"\"\"\n :type n: int\n :type edges: List[List[int]]\n :type labels: str\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countSubTrees(self, n: int, edges: List[List[int]], labels: str) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* countSubTrees(int n, int** edges, int edgesSize, int* edgesColSize, char * labels, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] CountSubTrees(int n, int[][] edges, string labels) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} edges\n * @param {string} labels\n * @return {number[]}\n */\nvar countSubTrees = function(n, edges, labels) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} edges\n# @param {String} labels\n# @return {Integer[]}\ndef count_sub_trees(n, edges, labels)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countSubTrees(_ n: Int, _ edges: [[Int]], _ labels: String) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countSubTrees(n int, edges [][]int, labels string) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countSubTrees(n: Int, edges: Array[Array[Int]], labels: String): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countSubTrees(n: Int, edges: Array, labels: String): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_sub_trees(n: i32, edges: Vec>, labels: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $edges\n * @param String $labels\n * @return Integer[]\n */\n function countSubTrees($n, $edges, $labels) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countSubTrees(n: number, edges: number[][], labels: string): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-sub-trees n edges labels)\n (-> exact-integer? (listof (listof exact-integer?)) string? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1519](https://leetcode-cn.com/problems/number-of-nodes-in-the-sub-tree-with-the-same-label)", "[\u5b50\u6811\u4e2d\u6807\u7b7e\u76f8\u540c\u7684\u8282\u70b9\u6570](/solution/1500-1599/1519.Number%20of%20Nodes%20in%20the%20Sub-Tree%20With%20the%20Same%20Label/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1519](https://leetcode.com/problems/number-of-nodes-in-the-sub-tree-with-the-same-label)", "[Number of Nodes in the Sub-Tree With the Same Label](/solution/1500-1599/1519.Number%20of%20Nodes%20in%20the%20Sub-Tree%20With%20the%20Same%20Label/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`", "Medium", ""]}, {"question_id": "1642", "frontend_question_id": "1518", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/water-bottles", "url_en": "https://leetcode.com/problems/water-bottles", "relative_path_cn": "/solution/1500-1599/1518.Water%20Bottles/README.md", "relative_path_en": "/solution/1500-1599/1518.Water%20Bottles/README_EN.md", "title_cn": "\u6362\u9152\u95ee\u9898", "title_en": "Water Bottles", "question_title_slug": "water-bottles", "content_en": "

    Given numBottles full water bottles, you can exchange numExchange empty water bottles for one full water bottle.

    \r\n\r\n

    The operation of drinking a full water bottle turns it into an empty bottle.

    \r\n\r\n

    Return the maximum number of water bottles you can drink.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n

    \"\"

    \r\n\r\n
    \r\nInput: numBottles = 9, numExchange = 3\r\nOutput: 13\r\nExplanation: You can exchange 3 empty bottles to get 1 full water bottle.\r\nNumber of water bottles you can drink: 9 + 3 + 1 = 13.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n

    \"\"

    \r\n\r\n
    \r\nInput: numBottles = 15, numExchange = 4\r\nOutput: 19\r\nExplanation: You can exchange 4 empty bottles to get 1 full water bottle. \r\nNumber of water bottles you can drink: 15 + 3 + 1 = 19.\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: numBottles = 5, numExchange = 5\r\nOutput: 6\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: numBottles = 2, numExchange = 3\r\nOutput: 2\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= numBottles <= 100
    • \r\n\t
    • 2 <= numExchange <= 100
    • \r\n
    ", "content_cn": "

    \u5c0f\u533a\u4fbf\u5229\u5e97\u6b63\u5728\u4fc3\u9500\uff0c\u7528 numExchange \u4e2a\u7a7a\u9152\u74f6\u53ef\u4ee5\u5151\u6362\u4e00\u74f6\u65b0\u9152\u3002\u4f60\u8d2d\u5165\u4e86 numBottles \u74f6\u9152\u3002

    \n\n

    \u5982\u679c\u559d\u6389\u4e86\u9152\u74f6\u4e2d\u7684\u9152\uff0c\u90a3\u4e48\u9152\u74f6\u5c31\u4f1a\u53d8\u6210\u7a7a\u7684\u3002

    \n\n

    \u8bf7\u4f60\u8ba1\u7b97 \u6700\u591a \u80fd\u559d\u5230\u591a\u5c11\u74f6\u9152\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1anumBottles = 9, numExchange = 3\n\u8f93\u51fa\uff1a13\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u7528 3 \u4e2a\u7a7a\u9152\u74f6\u5151\u6362 1 \u74f6\u9152\u3002\n\u6240\u4ee5\u6700\u591a\u80fd\u559d\u5230 9 + 3 + 1 = 13 \u74f6\u9152\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1anumBottles = 15, numExchange = 4\n\u8f93\u51fa\uff1a19\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u7528 4 \u4e2a\u7a7a\u9152\u74f6\u5151\u6362 1 \u74f6\u9152\u3002\n\u6240\u4ee5\u6700\u591a\u80fd\u559d\u5230 15 + 3 + 1 = 19 \u74f6\u9152\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1anumBottles = 5, numExchange = 5\n\u8f93\u51fa\uff1a6\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1anumBottles = 2, numExchange = 3\n\u8f93\u51fa\uff1a2\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= numBottles <= 100
    • \n\t
    • 2 <= numExchange <= 100
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numWaterBottles(int numBottles, int numExchange) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numWaterBottles(int numBottles, int numExchange) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numWaterBottles(self, numBottles, numExchange):\n \"\"\"\n :type numBottles: int\n :type numExchange: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numWaterBottles(self, numBottles: int, numExchange: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numWaterBottles(int numBottles, int numExchange){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumWaterBottles(int numBottles, int numExchange) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} numBottles\n * @param {number} numExchange\n * @return {number}\n */\nvar numWaterBottles = function(numBottles, numExchange) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} num_bottles\n# @param {Integer} num_exchange\n# @return {Integer}\ndef num_water_bottles(num_bottles, num_exchange)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numWaterBottles(_ numBottles: Int, _ numExchange: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numWaterBottles(numBottles int, numExchange int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numWaterBottles(numBottles: Int, numExchange: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numWaterBottles(numBottles: Int, numExchange: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_water_bottles(num_bottles: i32, num_exchange: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $numBottles\n * @param Integer $numExchange\n * @return Integer\n */\n function numWaterBottles($numBottles, $numExchange) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numWaterBottles(numBottles: number, numExchange: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-water-bottles numBottles numExchange)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1518](https://leetcode-cn.com/problems/water-bottles)", "[\u6362\u9152\u95ee\u9898](/solution/1500-1599/1518.Water%20Bottles/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u7b80\u5355", ""], "md_table_row_en": ["[1518](https://leetcode.com/problems/water-bottles)", "[Water Bottles](/solution/1500-1599/1518.Water%20Bottles/README_EN.md)", "`Greedy`", "Easy", ""]}, {"question_id": "1641", "frontend_question_id": "1501", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/countries-you-can-safely-invest-in", "url_en": "https://leetcode.com/problems/countries-you-can-safely-invest-in", "relative_path_cn": "/solution/1500-1599/1501.Countries%20You%20Can%20Safely%20Invest%20In/README.md", "relative_path_en": "/solution/1500-1599/1501.Countries%20You%20Can%20Safely%20Invest%20In/README_EN.md", "title_cn": "\u53ef\u4ee5\u653e\u5fc3\u6295\u8d44\u7684\u56fd\u5bb6", "title_en": "Countries You Can Safely Invest In", "question_title_slug": "countries-you-can-safely-invest-in", "content_en": "

    Table Person:

    \n\n
    \n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| id             | int     |\n| name           | varchar |\n| phone_number   | varchar |\n+----------------+---------+\nid is the primary key for this table.\nEach row of this table contains the name of a person and their phone number.\nPhone number will be in the form 'xxx-yyyyyyy' where xxx is the country code (3 characters) and yyyyyyy is the phone number (7 characters) where x and y are digits. Both can contain leading zeros.\n
    \n\n

     

    \n\n

    Table Country:

    \n\n
    \n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| name           | varchar |\n| country_code   | varchar |\n+----------------+---------+\ncountry_code is the primary key for this table.\nEach row of this table contains the country name and its code. country_code will be in the form 'xxx' where x is digits.\n
    \n\n

     

    \n\n

    Table Calls:

    \n\n
    \n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| caller_id   | int  |\n| callee_id   | int  |\n| duration    | int  |\n+-------------+------+\nThere is no primary key for this table, it may contain duplicates.\nEach row of this table contains the caller id, callee id and the duration of the call in minutes. caller_id != callee_id\n
    \n\n

     

    \n\n

    A telecommunications company wants to invest in new countries. The company intends to invest in the countries where the average call duration of the calls in this country is strictly greater than the global average call duration.

    \n\n

    Write an SQL query to find the countries where this company can invest.

    \n\n

    Return the result table in any order.

    \n\n

    The query result format is in the following example:

    \n\n

     

    \n\n
    \nPerson table:\n+----+----------+--------------+\n| id | name     | phone_number |\n+----+----------+--------------+\n| 3  | Jonathan | 051-1234567  |\n| 12 | Elvis    | 051-7654321  |\n| 1  | Moncef   | 212-1234567  |\n| 2  | Maroua   | 212-6523651  |\n| 7  | Meir     | 972-1234567  |\n| 9  | Rachel   | 972-0011100  |\n+----+----------+--------------+\n\nCountry table:\n+----------+--------------+\n| name     | country_code |\n+----------+--------------+\n| Peru     | 051          |\n| Israel   | 972          |\n| Morocco  | 212          |\n| Germany  | 049          |\n| Ethiopia | 251          |\n+----------+--------------+\n\nCalls table:\n+-----------+-----------+----------+\n| caller_id | callee_id | duration |\n+-----------+-----------+----------+\n| 1         | 9         | 33       |\n| 2         | 9         | 4        |\n| 1         | 2         | 59       |\n| 3         | 12        | 102      |\n| 3         | 12        | 330      |\n| 12        | 3         | 5        |\n| 7         | 9         | 13       |\n| 7         | 1         | 3        |\n| 9         | 7         | 1        |\n| 1         | 7         | 7        |\n+-----------+-----------+----------+\n\nResult table:\n+----------+\n| country  |\n+----------+\n| Peru     |\n+----------+\nThe average call duration for Peru is (102 + 102 + 330 + 330 + 5 + 5) / 6 = 145.666667\nThe average call duration for Israel is (33 + 4 + 13 + 13 + 3 + 1 + 1 + 7) / 8 = 9.37500\nThe average call duration for Morocco is (33 + 4 + 59 + 59 + 3 + 7) / 6 = 27.5000 \nGlobal call duration average = (2 * (33 + 4 + 59 + 102 + 330 + 5 + 13 + 3 + 1 + 7)) / 20 = 55.70000\nSince Peru is the only country where average call duration is greater than the global average, it's the only recommended country.\n
    \n", "content_cn": "

    \u8868\u00a0Person:

    \n\n
    \n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| id             | int     |\n| name           | varchar |\n| phone_number   | varchar |\n+----------------+---------+\nid \u662f\u8be5\u8868\u4e3b\u952e.\n\u8be5\u8868\u6bcf\u4e00\u884c\u5305\u542b\u4e00\u4e2a\u4eba\u7684\u540d\u5b57\u548c\u7535\u8bdd\u53f7\u7801.\n\u7535\u8bdd\u53f7\u7801\u7684\u683c\u5f0f\u662f:'xxx-yyyyyyy', \u5176\u4e2dxxx\u662f\u56fd\u5bb6\u7801(3\u4e2a\u5b57\u7b26), yyyyyyy\u662f\u7535\u8bdd\u53f7\u7801(7\u4e2a\u5b57\u7b26), x\u548cy\u90fd\u8868\u793a\u6570\u5b57. \u540c\u65f6, \u56fd\u5bb6\u7801\u548c\u7535\u8bdd\u53f7\u7801\u90fd\u53ef\u4ee5\u5305\u542b\u524d\u5bfc0.\n
    \n\n

    \u8868\u00a0Country:

    \n\n
    \n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| name           | varchar |\n| country_code   | varchar |\n+----------------+---------+\ncountry_code\u662f\u8be5\u8868\u4e3b\u952e.\n\u8be5\u8868\u6bcf\u4e00\u884c\u5305\u542b\u56fd\u5bb6\u540d\u548c\u56fd\u5bb6\u7801. country_code\u7684\u683c\u5f0f\u662f'xxx', x\u662f\u6570\u5b57.\n
    \n\n

    \u00a0

    \n\n

    \u8868\u00a0Calls:

    \n\n
    \n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| caller_id   | int  |\n| callee_id   | int  |\n| duration    | int  |\n+-------------+------+\n\u8be5\u8868\u65e0\u4e3b\u952e, \u53ef\u80fd\u5305\u542b\u91cd\u590d\u884c.\n\u6bcf\u4e00\u884c\u5305\u542b\u547c\u53eb\u65b9id, \u88ab\u547c\u53eb\u65b9id\u548c\u4ee5\u5206\u949f\u4e3a\u5355\u4f4d\u7684\u901a\u8bdd\u65f6\u957f. caller_id != callee_id\n
    \n\n

    \u4e00\u5bb6\u7535\u4fe1\u516c\u53f8\u60f3\u8981\u6295\u8d44\u65b0\u7684\u56fd\u5bb6. \u8be5\u516c\u53f8\u60f3\u8981\u6295\u8d44\u7684\u56fd\u5bb6\u662f:\u00a0 \u8be5\u56fd\u7684\u5e73\u5747\u901a\u8bdd\u65f6\u957f\u8981\u4e25\u683c\u5730\u5927\u4e8e\u5168\u7403\u5e73\u5747\u901a\u8bdd\u65f6\u957f.

    \n\n

    \u5199\u4e00\u6bb5 SQL,\u00a0\u00a0\u627e\u5230\u6240\u6709\u8be5\u516c\u53f8\u53ef\u4ee5\u6295\u8d44\u7684\u56fd\u5bb6.

    \n\n

    \u8fd4\u56de\u7684\u7ed3\u679c\u8868\u6ca1\u6709\u987a\u5e8f\u8981\u6c42.

    \n\n

    \u67e5\u8be2\u7684\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a.

    \n\n
    \nPerson \u8868:\n+----+----------+--------------+\n| id | name     | phone_number |\n+----+----------+--------------+\n| 3  | Jonathan | 051-1234567  |\n| 12 | Elvis    | 051-7654321  |\n| 1  | Moncef   | 212-1234567  |\n| 2  | Maroua   | 212-6523651  |\n| 7  | Meir     | 972-1234567  |\n| 9  | Rachel   | 972-0011100  |\n+----+----------+--------------+\n\nCountry \u8868:\n+----------+--------------+\n| name     | country_code |\n+----------+--------------+\n| Peru     | 051          |\n| Israel   | 972          |\n| Morocco  | 212          |\n| Germany  | 049          |\n| Ethiopia | 251          |\n+----------+--------------+\n\nCalls \u8868:\n+-----------+-----------+----------+\n| caller_id | callee_id | duration |\n+-----------+-----------+----------+\n| 1         | 9         | 33       |\n| 2         | 9         | 4        |\n| 1         | 2         | 59       |\n| 3         | 12        | 102      |\n| 3         | 12        | 330      |\n| 12        | 3         | 5        |\n| 7         | 9         | 13       |\n| 7         | 1         | 3        |\n| 9         | 7         | 1        |\n| 1         | 7         | 7        |\n+-----------+-----------+----------+\n\nResult \u8868:\n+----------+\n| country  |\n+----------+\n| Peru     |\n+----------+\n\u56fd\u5bb6Peru\u7684\u5e73\u5747\u901a\u8bdd\u65f6\u957f\u662f (102 + 102 + 330 + 330 + 5 + 5) / 6 = 145.666667\n\u56fd\u5bb6Israel\u7684\u5e73\u5747\u901a\u8bdd\u65f6\u957f\u662f (33 + 4 + 13 + 13 + 3 + 1 + 1 + 7) / 8 = 9.37500\n\u56fd\u5bb6Morocco\u7684\u5e73\u5747\u901a\u8bdd\u65f6\u957f\u662f (33 + 4 + 59 + 59 + 3 + 7) / 6 = 27.5000 \n\u5168\u7403\u5e73\u5747\u901a\u8bdd\u65f6\u957f = (2 * (33 + 4 + 59 + 102 + 330 + 5 + 13 + 3 + 1 + 7)) / 20 = 55.70000\n\u6240\u4ee5, Peru\u662f\u552f\u4e00\u7684\u5e73\u5747\u901a\u8bdd\u65f6\u957f\u5927\u4e8e\u5168\u7403\u5e73\u5747\u901a\u8bdd\u65f6\u957f\u7684\u56fd\u5bb6, \u4e5f\u662f\u552f\u4e00\u7684\u63a8\u8350\u6295\u8d44\u7684\u56fd\u5bb6.\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1501](https://leetcode-cn.com/problems/countries-you-can-safely-invest-in)", "[\u53ef\u4ee5\u653e\u5fc3\u6295\u8d44\u7684\u56fd\u5bb6](/solution/1500-1599/1501.Countries%20You%20Can%20Safely%20Invest%20In/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1501](https://leetcode.com/problems/countries-you-can-safely-invest-in)", "[Countries You Can Safely Invest In](/solution/1500-1599/1501.Countries%20You%20Can%20Safely%20Invest%20In/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1640", "frontend_question_id": "1500", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/design-a-file-sharing-system", "url_en": "https://leetcode.com/problems/design-a-file-sharing-system", "relative_path_cn": "/solution/1500-1599/1500.Design%20a%20File%20Sharing%20System/README.md", "relative_path_en": "/solution/1500-1599/1500.Design%20a%20File%20Sharing%20System/README_EN.md", "title_cn": "\u8bbe\u8ba1\u6587\u4ef6\u5206\u4eab\u7cfb\u7edf", "title_en": "Design a File Sharing System", "question_title_slug": "design-a-file-sharing-system", "content_en": "

    We will use a file-sharing system to share a very large file which consists of m small chunks with IDs from 1 to m.

    \n\n

    When users join the system, the system should assign a unique ID to them. The unique ID should be used once for each user, but when a user leaves the system, the ID can be reused again.

    \n\n

    Users can request a certain chunk of the file, the system should return a list of IDs of all the users who own this chunk. If the user receive a non-empty list of IDs, they receive the requested chunk successfully.

    \n\n


    \nImplement the FileSharing class:

    \n\n
      \n\t
    • FileSharing(int m) Initializes the object with a file of m chunks.
    • \n\t
    • int join(int[] ownedChunks): A new user joined the system owning some chunks of the file, the system should assign an id to the user which is the smallest positive integer not taken by any other user. Return the assigned id.
    • \n\t
    • void leave(int userID): The user with userID will leave the system, you cannot take file chunks from them anymore.
    • \n\t
    • int[] request(int userID, int chunkID): The user userID requested the file chunk with chunkID. Return a list of the IDs of all users that own this chunk sorted in ascending order.
    • \n
    \n\n

     

    \n\n

    Follow-ups:

    \n\n
      \n\t
    • What happens if the system identifies the user by their IP address instead of their unique ID and users disconnect and connect from the system with the same IP?
    • \n\t
    • If the users in the system join and leave the system frequently without requesting any chunks, will your solution still be efficient?
    • \n\t
    • If all each user join the system one time, request all files and then leave, will your solution still be efficient?
    • \n\t
    • If the system will be used to share n files where the ith file consists of m[i], what are the changes you have to do?
    • \n
    \n\n

     

    \n

    Example:

    \n\n
    \nInput:\n["FileSharing","join","join","join","request","request","leave","request","leave","join"]\n[[4],[[1,2]],[[2,3]],[[4]],[1,3],[2,2],[1],[2,1],[2],[[]]]\nOutput:\n[null,1,2,3,[2],[1,2],null,[],null,1]\nExplanation:\nFileSharing fileSharing = new FileSharing(4); // We use the system to share a file of 4 chunks.\n\nfileSharing.join([1, 2]);    // A user who has chunks [1,2] joined the system, assign id = 1 to them and return 1.\n\nfileSharing.join([2, 3]);    // A user who has chunks [2,3] joined the system, assign id = 2 to them and return 2.\n\nfileSharing.join([4]);       // A user who has chunk [4] joined the system, assign id = 3 to them and return 3.\n\nfileSharing.request(1, 3);   // The user with id = 1 requested the third file chunk, as only the user with id = 2 has the file, return [2] . Notice that user 1 now has chunks [1,2,3].\n\nfileSharing.request(2, 2);   // The user with id = 2 requested the second file chunk, users with ids [1,2] have this chunk, thus we return [1,2].\n\nfileSharing.leave(1);        // The user with id = 1 left the system, all the file chunks with them are no longer available for other users.\n\nfileSharing.request(2, 1);   // The user with id = 2 requested the first file chunk, no one in the system has this chunk, we return empty list [].\n\nfileSharing.leave(2);        // The user with id = 2 left the system.\n\nfileSharing.join([]);        // A user who doesn't have any chunks joined the system, assign id = 1 to them and return 1. Notice that ids 1 and 2 are free and we can reuse them.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= m <= 10^5
    • \n\t
    • 0 <= ownedChunks.length <= min(100, m)
    • \n\t
    • 1 <= ownedChunks[i] <= m
    • \n\t
    • Values of ownedChunks are unique.
    • \n\t
    • 1 <= chunkID <= m
    • \n\t
    • userID is guaranteed to be a user in the system if you assign the IDs correctly
    • \n\t
    • At most 10^4 calls will be made to joinleave and request.
    • \n\t
    • Each call to leave will have a matching call for join.
    • \n
    \n", "content_cn": "

    \u6211\u4eec\u9700\u8981\u4f7f\u7528\u4e00\u5957\u6587\u4ef6\u5206\u4eab\u7cfb\u7edf\u6765\u5206\u4eab\u4e00\u4e2a\u975e\u5e38\u5927\u7684\u6587\u4ef6\uff0c\u8be5\u6587\u4ef6\u7531 m \u4e2a\u4ece 1 \u5230 m \u7f16\u53f7\u7684\u6587\u4ef6\u5757\u7ec4\u6210\u3002

    \n\n

    \u5f53\u7528\u6237\u52a0\u5165\u7cfb\u7edf\u65f6\uff0c\u7cfb\u7edf\u5e94\u4e3a\u5176\u6ce8\u518c\u4e00\u4e2a\u72ec\u6709\u7684 ID\u3002\u8fd9\u4e2a\u72ec\u6709\u7684 ID \u5e94\u5f53\u88ab\u76f8\u5e94\u7684\u7528\u6237\u4f7f\u7528\u4e00\u6b21\uff0c\u4f46\u662f\u5f53\u7528\u6237\u79bb\u5f00\u7cfb\u7edf\u65f6\uff0c\u5176 ID \u5e94\u53ef\u4ee5\u88ab\uff08\u540e\u7eed\u65b0\u6ce8\u518c\u7684\u7528\u6237\uff09\u518d\u6b21\u4f7f\u7528\u3002

    \n\n

    \u7528\u6237\u53ef\u4ee5\u8bf7\u6c42\u6587\u4ef6\u4e2d\u7684\u67d0\u4e2a\u6307\u5b9a\u7684\u6587\u4ef6\u5757\uff0c\u7cfb\u7edf\u5e94\u5f53\u8fd4\u56de\u62e5\u6709\u8fd9\u4e2a\u6587\u4ef6\u5757\u7684\u6240\u6709\u7528\u6237\u7684 ID\u3002\u5982\u679c\u7528\u6237\u6536\u5230 ID \u7684\u975e\u7a7a\u5217\u8868\uff0c\u5c31\u8868\u793a\u6210\u529f\u63a5\u6536\u5230\u8bf7\u6c42\u7684\u6587\u4ef6\u5757\u3002

    \n\n


    \n\u5b9e\u73b0 FileSharing \u7c7b\uff1a

    \n\n
      \n\t
    • FileSharing(int m) \u521d\u59cb\u5316\u8be5\u5bf9\u8c61\uff0c\u6587\u4ef6\u6709 m \u4e2a\u6587\u4ef6\u5757\u3002
    • \n\t
    • int join(int[] ownedChunks)\uff1a\u4e00\u4e2a\u65b0\u7528\u6237\u52a0\u5165\u7cfb\u7edf\uff0c\u5e76\u62e5\u6709\u6587\u4ef6\u7684\u4e00\u4e9b\u6587\u4ef6\u5757\u3002\u7cfb\u7edf\u5e94\u5f53\u4e3a\u8be5\u7528\u6237\u6ce8\u518c\u4e00\u4e2a ID\uff0c\u8be5 ID \u5e94\u662f\u672a\u88ab\u5176\u4ed6\u7528\u6237\u5360\u7528\u7684\u6700\u5c0f\u6b63\u6574\u6570\u3002\u8fd4\u56de\u6ce8\u518c\u7684 ID\u3002
    • \n\t
    • void leave(int userID)\uff1aID \u4e3a userID \u7684\u7528\u6237\u5c06\u79bb\u5f00\u7cfb\u7edf\uff0c\u4f60\u4e0d\u80fd\u518d\u4ece\u8be5\u7528\u6237\u63d0\u53d6\u6587\u4ef6\u5757\u4e86\u3002
    • \n\t
    • int[] request(int userID, int chunkID)\uff1aID \u4e3a userID \u7684\u7528\u6237\u8bf7\u6c42\u7f16\u53f7\u4e3a chunkID \u7684\u6587\u4ef6\u5757\u3002\u8fd4\u56de\u62e5\u6709\u8fd9\u4e2a\u6587\u4ef6\u5757\u7684\u6240\u6709\u7528\u6237\u7684 ID \u6240\u6784\u6210\u7684\u5217\u8868\u6216\u6570\u7ec4\uff0c\u6309\u5347\u5e8f\u6392\u5217\u3002
    • \n
    \n\n

     

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u5f53\u7cfb\u7edf\u4ee5\u7528\u6237\u7684 IP \u5730\u5740\u800c\u4e0d\u662f\u72ec\u6709 ID \u6765\u8bc6\u522b\u7528\u6237\uff0c\u4e14\u7528\u6237\u65ad\u5f00\u8fde\u63a5\u540e\u4ee5\u76f8\u540c IP \u91cd\u65b0\u8fde\u63a5\u7cfb\u7edf\u65f6\uff0c\u4f1a\u53d1\u751f\u4ec0\u4e48\uff1f
    • \n\t
    • \u5f53\u7528\u6237\u9891\u7e41\u52a0\u5165\u5e76\u9000\u51fa\u7cfb\u7edf\uff0c\u4e14\u8be5\u7528\u6237\u4e0d\u8bf7\u6c42\u4efb\u4f55\u6587\u4ef6\u5757\u65f6\uff0c\u4f60\u7684\u89e3\u51b3\u65b9\u6848\u4ecd\u7136\u4fdd\u6301\u9ad8\u6548\u5417\uff1f
    • \n\t
    • \u5f53\u6240\u6709\u7528\u6237\u540c\u65f6\u52a0\u5165\u7cfb\u7edf\uff0c\u8bf7\u6c42\u6240\u6709\u6587\u4ef6\u5e76\u79bb\u5f00\u65f6\uff0c\u4f60\u7684\u89e3\u51b3\u65b9\u6848\u4ecd\u7136\u4fdd\u6301\u9ad8\u6548\u5417\uff1f
    • \n\t
    • \u5982\u679c\u7cfb\u7edf\u7528\u4e8e\u5206\u4eab n \u4e2a\u6587\u4ef6\uff0c\u5176\u4e2d\u7b2c  i \u4e2a\u6587\u4ef6\u7531 m[i] \u7ec4\u6210\uff0c\u4f60\u9700\u8981\u5982\u4f55\u4fee\u6539\uff1f
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165:\n["FileSharing","join","join","join","request","request","leave","request","leave","join"]\n[[4],[[1,2]],[[2,3]],[[4]],[1,3],[2,2],[1],[2,1],[2],[[]]]\n\u8f93\u51fa:\n[null,1,2,3,[2],[1,2],null,[],null,1]\n\u89e3\u91ca:\nFileSharing fileSharing = new FileSharing(4); // \u6211\u4eec\u7528\u8be5\u7cfb\u7edf\u5206\u4eab\u7531 4 \u4e2a\u6587\u4ef6\u5757\u7ec4\u6210\u7684\u6587\u4ef6\u3002\n\nfileSharing.join([1, 2]);    // \u4e00\u4e2a\u62e5\u6709\u6587\u4ef6\u5757 [1,2] \u7684\u7528\u6237\u52a0\u5165\u7cfb\u7edf\uff0c\u4e3a\u5176\u6ce8\u518c id = 1 \u5e76\u8fd4\u56de 1\u3002\n\nfileSharing.join([2, 3]);    // \u4e00\u4e2a\u62e5\u6709\u6587\u4ef6\u5757 [2,3] \u7684\u7528\u6237\u52a0\u5165\u7cfb\u7edf\uff0c\u4e3a\u5176\u6ce8\u518c id = 2 \u5e76\u8fd4\u56de 2\u3002\n\nfileSharing.join([4]);       // \u4e00\u4e2a\u62e5\u6709\u6587\u4ef6\u5757 [4] \u7684\u7528\u6237\u52a0\u5165\u7cfb\u7edf\uff0c\u4e3a\u5176\u6ce8\u518c id = 3 \u5e76\u8fd4\u56de 3\u3002\n\nfileSharing.request(1, 3);   // id = 1 \u7684\u7528\u6237\u8bf7\u6c42\u7b2c 3 \u4e2a\u6587\u4ef6\u5757\uff0c\u53ea\u6709 id = 2 \u7684\u7528\u6237\u62e5\u6709\u6587\u4ef6\u5757\uff0c\u8fd4\u56de [2] \u3002\u6ce8\u610f\uff0c\u73b0\u5728\u7528\u6237 1 \u73b0\u62e5\u6709\u6587\u4ef6\u5757 [1,2,3]\u3002\n\nfileSharing.request(2, 2);   // id = 2 \u7684\u7528\u6237\u8bf7\u6c42\u7b2c 2 \u4e2a\u6587\u4ef6\u5757\uff0cid \u4e3a [1,2] \u7684\u7528\u6237\u62e5\u6709\u8be5\u6587\u4ef6\u5757\uff0c\u6240\u4ee5\u6211\u4eec\u8fd4\u56de [1,2] \u3002\n\nfileSharing.leave(1);        // id = 1 \u7684\u7528\u6237\u79bb\u5f00\u7cfb\u7edf\uff0c\u5176\u6240\u62e5\u6709\u7684\u6240\u6709\u6587\u4ef6\u5757\u4e0d\u518d\u5bf9\u5176\u4ed6\u7528\u6237\u53ef\u7528\u3002\n\nfileSharing.request(2, 1);   // id = 2 \u7684\u7528\u6237\u8bf7\u6c42\u7b2c 1 \u4e2a\u6587\u4ef6\u5757\uff0c\u7cfb\u7edf\u4e2d\u6ca1\u6709\u7528\u6237\u62e5\u6709\u8be5\u6587\u4ef6\u5757\uff0c\u6240\u4ee5\u6211\u4eec\u8fd4\u56de\u7a7a\u5217\u8868 [] \u3002\n\nfileSharing.leave(2);        // id = 2 \u7684\u7528\u6237\u79bb\u5f00\u7cfb\u7edf\u3002\n\nfileSharing.join([]);        // \u4e00\u4e2a\u4e0d\u62e5\u6709\u4efb\u4f55\u6587\u4ef6\u5757\u7684\u7528\u6237\u52a0\u5165\u7cfb\u7edf\uff0c\u4e3a\u5176\u6ce8\u518c id = 1 \u5e76\u8fd4\u56de 1 \u3002\u6ce8\u610f\uff0cid 1 \u548c 2 \u7a7a\u95f2\uff0c\u53ef\u4ee5\u91cd\u65b0\u4f7f\u7528\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a:

    \n\n
      \n\t
    • 1 <= m <= 10^5
    • \n\t
    • 0 <= ownedChunks.length <= min(100, m)
    • \n\t
    • 1 <= ownedChunks[i] <= m
    • \n\t
    • ownedChunks \u7684\u503c\u662f\u4e92\u4e0d\u76f8\u540c\u7684\u3002
    • \n\t
    • 1 <= chunkID <= m
    • \n\t
    • \u5f53\u4f60\u6b63\u786e\u5730\u6ce8\u518c\u7528\u6237 ID \u65f6\uff0c\u9898\u76ee\u4fdd\u8bc1 userID \u662f\u7cfb\u7edf\u4e2d\u7684\u4e00\u4e2a\u5df2\u6ce8\u518c\u7528\u6237\u3002
    • \n\t
    • join\u3001 leave \u548c request \u6700\u591a\u88ab\u8c03\u7528 10^4 \u6b21\u3002
    • \n\t
    • \u6bcf\u6b21\u5bf9 leave \u7684\u8c03\u7528\u90fd\u6709\u5bf9\u5e94\u7684\u5bf9 join \u7684\u8c03\u7528\u3002
    • \n
    \n", "tags_en": ["Design", "Array"], "tags_cn": ["\u8bbe\u8ba1", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class FileSharing {\npublic:\n FileSharing(int m) {\n\n }\n \n int join(vector ownedChunks) {\n\n }\n \n void leave(int userID) {\n\n }\n \n vector request(int userID, int chunkID) {\n\n }\n};\n\n/**\n * Your FileSharing object will be instantiated and called as such:\n * FileSharing* obj = new FileSharing(m);\n * int param_1 = obj->join(ownedChunks);\n * obj->leave(userID);\n * vector param_3 = obj->request(userID,chunkID);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class FileSharing {\n\n public FileSharing(int m) {\n\n }\n \n public int join(List ownedChunks) {\n\n }\n \n public void leave(int userID) {\n\n }\n \n public List request(int userID, int chunkID) {\n\n }\n}\n\n/**\n * Your FileSharing object will be instantiated and called as such:\n * FileSharing obj = new FileSharing(m);\n * int param_1 = obj.join(ownedChunks);\n * obj.leave(userID);\n * List param_3 = obj.request(userID,chunkID);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class FileSharing(object):\n\n def __init__(self, m):\n \"\"\"\n :type m: int\n \"\"\"\n\n\n def join(self, ownedChunks):\n \"\"\"\n :type ownedChunks: List[int]\n :rtype: int\n \"\"\"\n\n\n def leave(self, userID):\n \"\"\"\n :type userID: int\n :rtype: None\n \"\"\"\n\n\n def request(self, userID, chunkID):\n \"\"\"\n :type userID: int\n :type chunkID: int\n :rtype: List[int]\n \"\"\"\n\n\n\n# Your FileSharing object will be instantiated and called as such:\n# obj = FileSharing(m)\n# param_1 = obj.join(ownedChunks)\n# obj.leave(userID)\n# param_3 = obj.request(userID,chunkID)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class FileSharing:\n\n def __init__(self, m: int):\n\n\n def join(self, ownedChunks: List[int]) -> int:\n\n\n def leave(self, userID: int) -> None:\n\n\n def request(self, userID: int, chunkID: int) -> List[int]:\n\n\n\n# Your FileSharing object will be instantiated and called as such:\n# obj = FileSharing(m)\n# param_1 = obj.join(ownedChunks)\n# obj.leave(userID)\n# param_3 = obj.request(userID,chunkID)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} FileSharing;\n\n\nFileSharing* fileSharingCreate(int m) {\n\n}\n\nint fileSharingJoin(FileSharing* obj, int* ownedChunks, int ownedChunksSize) {\n\n}\n\nvoid fileSharingLeave(FileSharing* obj, int userID) {\n\n}\n\nint* fileSharingRequest(FileSharing* obj, int userID, int chunkID, int* retSize) {\n\n}\n\nvoid fileSharingFree(FileSharing* obj) {\n\n}\n\n/**\n * Your FileSharing struct will be instantiated and called as such:\n * FileSharing* obj = fileSharingCreate(m);\n * int param_1 = fileSharingJoin(obj, ownedChunks, ownedChunksSize);\n \n * fileSharingLeave(obj, userID);\n \n * int* param_3 = fileSharingRequest(obj, userID, chunkID, retSize);\n \n * fileSharingFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class FileSharing {\n\n public FileSharing(int m) {\n\n }\n \n public int Join(IList ownedChunks) {\n\n }\n \n public void Leave(int userID) {\n\n }\n \n public IList Request(int userID, int chunkID) {\n\n }\n}\n\n/**\n * Your FileSharing object will be instantiated and called as such:\n * FileSharing obj = new FileSharing(m);\n * int param_1 = obj.Join(ownedChunks);\n * obj.Leave(userID);\n * IList param_3 = obj.Request(userID,chunkID);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} m\n */\nvar FileSharing = function(m) {\n\n};\n\n/** \n * @param {number[]} ownedChunks\n * @return {number}\n */\nFileSharing.prototype.join = function(ownedChunks) {\n\n};\n\n/** \n * @param {number} userID\n * @return {void}\n */\nFileSharing.prototype.leave = function(userID) {\n\n};\n\n/** \n * @param {number} userID \n * @param {number} chunkID\n * @return {number[]}\n */\nFileSharing.prototype.request = function(userID, chunkID) {\n\n};\n\n/**\n * Your FileSharing object will be instantiated and called as such:\n * var obj = new FileSharing(m)\n * var param_1 = obj.join(ownedChunks)\n * obj.leave(userID)\n * var param_3 = obj.request(userID,chunkID)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class FileSharing\n\n=begin\n :type m: Integer\n=end\n def initialize(m)\n\n end\n\n\n=begin\n :type owned_chunks: Integer[]\n :rtype: Integer\n=end\n def join(owned_chunks)\n\n end\n\n\n=begin\n :type user_id: Integer\n :rtype: Void\n=end\n def leave(user_id)\n\n end\n\n\n=begin\n :type user_id: Integer\n :type chunk_id: Integer\n :rtype: Integer[]\n=end\n def request(user_id, chunk_id)\n\n end\n\n\nend\n\n# Your FileSharing object will be instantiated and called as such:\n# obj = FileSharing.new(m)\n# param_1 = obj.join(owned_chunks)\n# obj.leave(user_id)\n# param_3 = obj.request(user_id, chunk_id)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass FileSharing {\n\n init(_ m: Int) {\n\n }\n \n func join(_ ownedChunks: [Int]) -> Int {\n\n }\n \n func leave(_ userID: Int) {\n\n }\n \n func request(_ userID: Int, _ chunkID: Int) -> [Int] {\n\n }\n}\n\n/**\n * Your FileSharing object will be instantiated and called as such:\n * let obj = FileSharing(m)\n * let ret_1: Int = obj.join(ownedChunks)\n * obj.leave(userID)\n * let ret_3: [Int] = obj.request(userID, chunkID)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type FileSharing struct {\n\n}\n\n\nfunc Constructor(m int) FileSharing {\n\n}\n\n\nfunc (this *FileSharing) Join(ownedChunks []int) int {\n\n}\n\n\nfunc (this *FileSharing) Leave(userID int) {\n\n}\n\n\nfunc (this *FileSharing) Request(userID int, chunkID int) []int {\n\n}\n\n\n/**\n * Your FileSharing object will be instantiated and called as such:\n * obj := Constructor(m);\n * param_1 := obj.Join(ownedChunks);\n * obj.Leave(userID);\n * param_3 := obj.Request(userID,chunkID);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class FileSharing(_m: Int) {\n\n def join(ownedChunks: List[Int]): Int = {\n\n }\n\n def leave(userID: Int) {\n\n }\n\n def request(userID: Int, chunkID: Int): List[Int] = {\n\n }\n\n}\n\n/**\n * Your FileSharing object will be instantiated and called as such:\n * var obj = new FileSharing(m)\n * var param_1 = obj.join(ownedChunks)\n * obj.leave(userID)\n * var param_3 = obj.request(userID,chunkID)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class FileSharing(m: Int) {\n\n fun join(ownedChunks: List): Int {\n\n }\n\n fun leave(userID: Int) {\n\n }\n\n fun request(userID: Int, chunkID: Int): List {\n\n }\n\n}\n\n/**\n * Your FileSharing object will be instantiated and called as such:\n * var obj = FileSharing(m)\n * var param_1 = obj.join(ownedChunks)\n * obj.leave(userID)\n * var param_3 = obj.request(userID,chunkID)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct FileSharing {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl FileSharing {\n\n fn new(m: i32) -> Self {\n\n }\n \n fn join(&self, owned_chunks: Vec) -> i32 {\n\n }\n \n fn leave(&self, user_id: i32) {\n\n }\n \n fn request(&self, user_id: i32, chunk_id: i32) -> Vec {\n\n }\n}\n\n/**\n * Your FileSharing object will be instantiated and called as such:\n * let obj = FileSharing::new(m);\n * let ret_1: i32 = obj.join(ownedChunks);\n * obj.leave(userID);\n * let ret_3: Vec = obj.request(userID, chunkID);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class FileSharing {\n /**\n * @param Integer $m\n */\n function __construct($m) {\n\n }\n\n /**\n * @param Integer[] $ownedChunks\n * @return Integer\n */\n function join($ownedChunks) {\n\n }\n\n /**\n * @param Integer $userID\n * @return NULL\n */\n function leave($userID) {\n\n }\n\n /**\n * @param Integer $userID\n * @param Integer $chunkID\n * @return Integer[]\n */\n function request($userID, $chunkID) {\n\n }\n}\n\n/**\n * Your FileSharing object will be instantiated and called as such:\n * $obj = FileSharing($m);\n * $ret_1 = $obj->join($ownedChunks);\n * $obj->leave($userID);\n * $ret_3 = $obj->request($userID, $chunkID);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class FileSharing {\n constructor(m: number) {\n\n }\n\n join(ownedChunks: number[]): number {\n\n }\n\n leave(userID: number): void {\n\n }\n\n request(userID: number, chunkID: number): number[] {\n\n }\n}\n\n/**\n * Your FileSharing object will be instantiated and called as such:\n * var obj = new FileSharing(m)\n * var param_1 = obj.join(ownedChunks)\n * obj.leave(userID)\n * var param_3 = obj.request(userID,chunkID)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define file-sharing%\n (class object%\n (super-new)\n\n ; m : exact-integer?\n (init-field\n m)\n \n ; join : (listof exact-integer?) -> exact-integer?\n (define/public (join ownedChunks)\n\n )\n ; leave : exact-integer? -> void?\n (define/public (leave userID)\n\n )\n ; request : exact-integer? exact-integer? -> (listof exact-integer?)\n (define/public (request userID chunkID)\n\n )))\n\n;; Your file-sharing% object will be instantiated and called as such:\n;; (define obj (new file-sharing% [m m]))\n;; (define param_1 (send obj join owned-chunks))\n;; (send obj leave user-id)\n;; (define param_3 (send obj request user-id chunk-id))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1500](https://leetcode-cn.com/problems/design-a-file-sharing-system)", "[\u8bbe\u8ba1\u6587\u4ef6\u5206\u4eab\u7cfb\u7edf](/solution/1500-1599/1500.Design%20a%20File%20Sharing%20System/README.md)", "`\u8bbe\u8ba1`,`\u6570\u7ec4`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1500](https://leetcode.com/problems/design-a-file-sharing-system)", "[Design a File Sharing System](/solution/1500-1599/1500.Design%20a%20File%20Sharing%20System/README_EN.md)", "`Design`,`Array`", "Medium", "\ud83d\udd12"]}, {"question_id": "1639", "frontend_question_id": "1495", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/friendly-movies-streamed-last-month", "url_en": "https://leetcode.com/problems/friendly-movies-streamed-last-month", "relative_path_cn": "/solution/1400-1499/1495.Friendly%20Movies%20Streamed%20Last%20Month/README.md", "relative_path_en": "/solution/1400-1499/1495.Friendly%20Movies%20Streamed%20Last%20Month/README_EN.md", "title_cn": "\u4e0a\u6708\u64ad\u653e\u7684\u513f\u7ae5\u9002\u5b9c\u7535\u5f71", "title_en": "Friendly Movies Streamed Last Month", "question_title_slug": "friendly-movies-streamed-last-month", "content_en": "

    Table: TVProgram

    \r\n\r\n
    \r\n+---------------+---------+\r\n| Column Name   | Type    |\r\n+---------------+---------+\r\n| program_date  | date    |\r\n| content_id    | int     |\r\n| channel       | varchar |\r\n+---------------+---------+\r\n(program_date, content_id) is the primary key for this table.\r\nThis table contains information of the programs on the TV.\r\ncontent_id is the id of the program in some channel on the TV.
    \r\n\r\n

     

    \r\n\r\n

    Table: Content

    \r\n\r\n
    \r\n+------------------+---------+\r\n| Column Name      | Type    |\r\n+------------------+---------+\r\n| content_id       | varchar |\r\n| title            | varchar |\r\n| Kids_content     | enum    |\r\n| content_type     | varchar |\r\n+------------------+---------+\r\ncontent_id is the primary key for this table.\r\nKids_content is an enum that takes one of the values ('Y', 'N') where: \r\n'Y' means is content for kids otherwise 'N' is not content for kids.\r\ncontent_type is the category of the content as movies, series, etc.\r\n
    \r\n\r\n

     

    \r\n\r\n

    Write an SQL query to report the distinct titles of the kid-friendly movies streamed in June 2020.

    \r\n\r\n

    Return the result table in any order.

    \r\n\r\n

    The query result format is in the following example.

    \r\n\r\n

     

    \r\n\r\n
    \r\nTVProgram table:\r\n+--------------------+--------------+-------------+\r\n| program_date       | content_id   | channel     |\r\n+--------------------+--------------+-------------+\r\n| 2020-06-10 08:00   | 1            | LC-Channel  |\r\n| 2020-05-11 12:00   | 2            | LC-Channel  |\r\n| 2020-05-12 12:00   | 3            | LC-Channel  |\r\n| 2020-05-13 14:00   | 4            | Disney Ch   |\r\n| 2020-06-18 14:00   | 4            | Disney Ch   |\r\n| 2020-07-15 16:00   | 5            | Disney Ch   |\r\n+--------------------+--------------+-------------+\r\n\r\nContent table:\r\n+------------+----------------+---------------+---------------+\r\n| content_id | title          | Kids_content  | content_type  |\r\n+------------+----------------+---------------+---------------+\r\n| 1          | Leetcode Movie | N             | Movies        |\r\n| 2          | Alg. for Kids  | Y             | Series        |\r\n| 3          | Database Sols  | N             | Series        |\r\n| 4          | Aladdin        | Y             | Movies        |\r\n| 5          | Cinderella     | Y             | Movies        |\r\n+------------+----------------+---------------+---------------+\r\n\r\nResult table:\r\n+--------------+\r\n| title        |\r\n+--------------+\r\n| Aladdin      |\r\n+--------------+\r\n"Leetcode Movie" is not a content for kids.\r\n"Alg. for Kids" is not a movie.\r\n"Database Sols" is not a movie\r\n"Alladin" is a movie, content for kids and was streamed in June 2020.\r\n"Cinderella" was not streamed in June 2020.\r\n
    ", "content_cn": "

    \u8868: TVProgram

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| program_date  | date    |\n| content_id    | int     |\n| channel       | varchar |\n+---------------+---------+\n(program_date, content_id) \u662f\u8be5\u8868\u4e3b\u952e.\n\u8be5\u8868\u5305\u542b\u7535\u89c6\u4e0a\u7684\u8282\u76ee\u4fe1\u606f.\ncontent_id \u662f\u7535\u89c6\u4e00\u4e9b\u9891\u9053\u4e0a\u7684\u8282\u76ee\u7684 id.
    \n\n

     

    \n\n

    \u8868: Content

    \n\n
    \n+------------------+---------+\n| Column Name      | Type    |\n+------------------+---------+\n| content_id       | varchar |\n| title            | varchar |\n| Kids_content     | enum    |\n| content_type     | varchar |\n+------------------+---------+\ncontent_id \u662f\u8be5\u8868\u4e3b\u952e.\nKids_content \u662f\u679a\u4e3e\u7c7b\u578b, \u53d6\u503c\u4e3a('Y', 'N'), \u5176\u4e2d: \n'Y' \u8868\u793a\u513f\u7ae5\u9002\u5b9c\u5185\u5bb9, \u800c'N'\u8868\u793a\u513f\u7ae5\u4e0d\u5b9c\u5185\u5bb9.\ncontent_type \u8868\u793a\u5185\u5bb9\u7684\u7c7b\u578b, \u6bd4\u5982\u7535\u5f71, \u7535\u89c6\u5267\u7b49.\n
    \n\n

     

    \n\n

    \u5199\u4e00\u4e2a SQL \u8bed\u53e5,  \u62a5\u544a\u5728 2020 \u5e74 6 \u6708\u4efd\u64ad\u653e\u7684\u513f\u7ae5\u9002\u5b9c\u7535\u5f71\u7684\u53bb\u91cd\u7535\u5f71\u540d.

    \n\n

    \u8fd4\u56de\u7684\u7ed3\u679c\u8868\u5355\u6ca1\u6709\u987a\u5e8f\u8981\u6c42.

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u7684\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a.

    \n\n

     

    \n\n
    \nTVProgram \u8868:\n+--------------------+--------------+-------------+\n| program_date       | content_id   | channel     |\n+--------------------+--------------+-------------+\n| 2020-06-10 08:00   | 1            | LC-Channel  |\n| 2020-05-11 12:00   | 2            | LC-Channel  |\n| 2020-05-12 12:00   | 3            | LC-Channel  |\n| 2020-05-13 14:00   | 4            | Disney Ch   |\n| 2020-06-18 14:00   | 4            | Disney Ch   |\n| 2020-07-15 16:00   | 5            | Disney Ch   |\n+--------------------+--------------+-------------+\n\nContent \u8868:\n+------------+----------------+---------------+---------------+\n| content_id | title          | Kids_content  | content_type  |\n+------------+----------------+---------------+---------------+\n| 1          | Leetcode Movie | N             | Movies        |\n| 2          | Alg. for Kids  | Y             | Series        |\n| 3          | Database Sols  | N             | Series        |\n| 4          | Aladdin        | Y             | Movies        |\n| 5          | Cinderella     | Y             | Movies        |\n+------------+----------------+---------------+---------------+\n\nResult \u8868:\n+--------------+\n| title        |\n+--------------+\n| Aladdin      |\n+--------------+\n"Leetcode Movie" \u662f\u513f\u7ae5\u4e0d\u5b9c\u7684\u7535\u5f71.\n"Alg. for Kids" \u4e0d\u662f\u7535\u5f71.\n"Database Sols" \u4e0d\u662f\u7535\u5f71\n"Alladin" \u662f\u7535\u5f71, \u513f\u7ae5\u9002\u5b9c, \u5e76\u4e14\u5728 2020 \u5e74 6 \u6708\u4efd\u64ad\u653e.\n"Cinderella" \u4e0d\u5728 2020 \u5e74 6 \u6708\u4efd\u64ad\u653e.\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1495](https://leetcode-cn.com/problems/friendly-movies-streamed-last-month)", "[\u4e0a\u6708\u64ad\u653e\u7684\u513f\u7ae5\u9002\u5b9c\u7535\u5f71](/solution/1400-1499/1495.Friendly%20Movies%20Streamed%20Last%20Month/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1495](https://leetcode.com/problems/friendly-movies-streamed-last-month)", "[Friendly Movies Streamed Last Month](/solution/1400-1499/1495.Friendly%20Movies%20Streamed%20Last%20Month/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1638", "frontend_question_id": "1515", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/best-position-for-a-service-centre", "url_en": "https://leetcode.com/problems/best-position-for-a-service-centre", "relative_path_cn": "/solution/1500-1599/1515.Best%20Position%20for%20a%20Service%20Centre/README.md", "relative_path_en": "/solution/1500-1599/1515.Best%20Position%20for%20a%20Service%20Centre/README_EN.md", "title_cn": "\u670d\u52a1\u4e2d\u5fc3\u7684\u6700\u4f73\u4f4d\u7f6e", "title_en": "Best Position for a Service Centre", "question_title_slug": "best-position-for-a-service-centre", "content_en": "

    A delivery company wants to build a new service centre in a new city. The company knows the positions of all the customers in this city on a 2D-Map and wants to build the new centre in a position such that the sum of the euclidean distances to all customers is minimum.

    \n\n

    Given an array positions where positions[i] = [xi, yi] is the position of the ith customer on the map, return the minimum sum of the euclidean distances to all customers.

    \n\n

    In other words, you need to choose the position of the service centre [xcentre, ycentre] such that the following formula is minimized:

    \n\"\"\n

    Answers within 10^-5 of the actual value will be accepted.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: positions = [[0,1],[1,0],[1,2],[2,1]]\nOutput: 4.00000\nExplanation: As shown, you can see that choosing [xcentre, ycentre] = [1, 1] will make the distance to each customer = 1, the sum of all distances is 4 which is the minimum possible we can achieve.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: positions = [[1,1],[3,3]]\nOutput: 2.82843\nExplanation: The minimum possible sum of distances = sqrt(2) + sqrt(2) = 2.82843\n
    \n\n

    Example 3:

    \n\n
    \nInput: positions = [[1,1]]\nOutput: 0.00000\n
    \n\n

    Example 4:

    \n\n
    \nInput: positions = [[1,1],[0,0],[2,0]]\nOutput: 2.73205\nExplanation: At the first glance, you may think that locating the centre at [1, 0] will achieve the minimum sum, but locating it at [1, 0] will make the sum of distances = 3.\nTry to locate the centre at [1.0, 0.5773502711] you will see that the sum of distances is 2.73205.\nBe careful with the precision!\n
    \n\n

    Example 5:

    \n\n
    \nInput: positions = [[0,1],[3,2],[4,5],[7,6],[8,9],[11,1],[2,12]]\nOutput: 32.94036\nExplanation: You can use [4.3460852395, 4.9813795505] as the position of the centre.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= positions.length <= 50
    • \n\t
    • positions[i].length == 2
    • \n\t
    • 0 <= positions[i][0], positions[i][1] <= 100
    • \n
    \n", "content_cn": "

    \u4e00\u5bb6\u5feb\u9012\u516c\u53f8\u5e0c\u671b\u5728\u65b0\u57ce\u5e02\u5efa\u7acb\u65b0\u7684\u670d\u52a1\u4e2d\u5fc3\u3002\u516c\u53f8\u7edf\u8ba1\u4e86\u8be5\u57ce\u5e02\u6240\u6709\u5ba2\u6237\u5728\u4e8c\u7ef4\u5730\u56fe\u4e0a\u7684\u5750\u6807\uff0c\u5e76\u5e0c\u671b\u80fd\u591f\u4ee5\u6b64\u4e3a\u4f9d\u636e\u4e3a\u65b0\u7684\u670d\u52a1\u4e2d\u5fc3\u9009\u5740\uff1a\u4f7f\u670d\u52a1\u4e2d\u5fc3 \u5230\u6240\u6709\u5ba2\u6237\u7684\u6b27\u51e0\u91cc\u5f97\u8ddd\u79bb\u7684\u603b\u548c\u6700\u5c0f \u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 positions \uff0c\u5176\u4e2d positions[i] = [xi, yi] \u8868\u793a\u7b2c i \u4e2a\u5ba2\u6237\u5728\u4e8c\u7ef4\u5730\u56fe\u4e0a\u7684\u4f4d\u7f6e\uff0c\u8fd4\u56de\u5230\u6240\u6709\u5ba2\u6237\u7684 \u6b27\u51e0\u91cc\u5f97\u8ddd\u79bb\u7684\u6700\u5c0f\u603b\u548c \u3002

    \n\n

    \u6362\u53e5\u8bdd\u8bf4\uff0c\u8bf7\u4f60\u4e3a\u670d\u52a1\u4e2d\u5fc3\u9009\u5740\uff0c\u8be5\u4f4d\u7f6e\u7684\u5750\u6807 [xcentre, ycentre] \u9700\u8981\u4f7f\u4e0b\u9762\u7684\u516c\u5f0f\u53d6\u5230\u6700\u5c0f\u503c\uff1a

    \n\n

    \"\"

    \n\n

    \u4e0e\u771f\u5b9e\u503c\u8bef\u5dee\u5728 10^-5 \u4e4b\u5185\u7684\u7b54\u6848\u5c06\u88ab\u89c6\u4f5c\u6b63\u786e\u7b54\u6848\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1apositions = [[0,1],[1,0],[1,2],[2,1]]\n\u8f93\u51fa\uff1a4.00000\n\u89e3\u91ca\uff1a\u5982\u56fe\u6240\u793a\uff0c\u4f60\u53ef\u4ee5\u9009 [xcentre, ycentre] = [1, 1] \u4f5c\u4e3a\u65b0\u4e2d\u5fc3\u7684\u4f4d\u7f6e\uff0c\u8fd9\u6837\u4e00\u6765\u5230\u6bcf\u4e2a\u5ba2\u6237\u7684\u8ddd\u79bb\u5c31\u90fd\u662f 1\uff0c\u6240\u6709\u8ddd\u79bb\u4e4b\u548c\u4e3a 4 \uff0c\u8fd9\u4e5f\u662f\u53ef\u4ee5\u627e\u5230\u7684\u6700\u5c0f\u503c\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1apositions = [[1,1],[3,3]]\n\u8f93\u51fa\uff1a2.82843\n\u89e3\u91ca\uff1a\u6b27\u51e0\u91cc\u5f97\u8ddd\u79bb\u53ef\u80fd\u7684\u6700\u5c0f\u603b\u548c\u4e3a sqrt(2) + sqrt(2) = 2.82843\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1apositions = [[1,1]]\n\u8f93\u51fa\uff1a0.00000\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1apositions = [[1,1],[0,0],[2,0]]\n\u8f93\u51fa\uff1a2.73205\n\u89e3\u91ca\uff1a\u4e4d\u4e00\u770b\uff0c\u4f60\u53ef\u80fd\u4f1a\u5c06\u4e2d\u5fc3\u5b9a\u5728 [1, 0] \u5e76\u671f\u5f85\u80fd\u591f\u5f97\u5230\u6700\u5c0f\u603b\u548c\uff0c\u4f46\u662f\u5982\u679c\u9009\u5740\u5728 [1, 0] \u8ddd\u79bb\u603b\u548c\u4e3a 3\n\u5982\u679c\u5c06\u4f4d\u7f6e\u9009\u5728 [1.0, 0.5773502711] \uff0c\u8ddd\u79bb\u603b\u548c\u5c06\u4f1a\u53d8\u4e3a 2.73205\n\u5f53\u5fc3\u7cbe\u5ea6\u95ee\u9898\uff01\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1apositions = [[0,1],[3,2],[4,5],[7,6],[8,9],[11,1],[2,12]]\n\u8f93\u51fa\uff1a32.94036\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u7528 [4.3460852395, 4.9813795505] \u4f5c\u4e3a\u65b0\u4e2d\u5fc3\u7684\u4f4d\u7f6e\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= positions.length <= 50
    • \n\t
    • positions[i].length == 2
    • \n\t
    • 0 <= positions[i][0], positions[i][1] <= 100
    • \n
    \n", "tags_en": ["Geometry"], "tags_cn": ["\u51e0\u4f55"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n double getMinDistSum(vector>& positions) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double getMinDistSum(int[][] positions) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getMinDistSum(self, positions):\n \"\"\"\n :type positions: List[List[int]]\n :rtype: float\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getMinDistSum(self, positions: List[List[int]]) -> float:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\ndouble getMinDistSum(int** positions, int positionsSize, int* positionsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double GetMinDistSum(int[][] positions) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} positions\n * @return {number}\n */\nvar getMinDistSum = function(positions) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} positions\n# @return {Float}\ndef get_min_dist_sum(positions)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getMinDistSum(_ positions: [[Int]]) -> Double {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getMinDistSum(positions [][]int) float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getMinDistSum(positions: Array[Array[Int]]): Double = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getMinDistSum(positions: Array): Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_min_dist_sum(positions: Vec>) -> f64 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $positions\n * @return Float\n */\n function getMinDistSum($positions) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getMinDistSum(positions: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-min-dist-sum positions)\n (-> (listof (listof exact-integer?)) flonum?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1515](https://leetcode-cn.com/problems/best-position-for-a-service-centre)", "[\u670d\u52a1\u4e2d\u5fc3\u7684\u6700\u4f73\u4f4d\u7f6e](/solution/1500-1599/1515.Best%20Position%20for%20a%20Service%20Centre/README.md)", "`\u51e0\u4f55`", "\u56f0\u96be", ""], "md_table_row_en": ["[1515](https://leetcode.com/problems/best-position-for-a-service-centre)", "[Best Position for a Service Centre](/solution/1500-1599/1515.Best%20Position%20for%20a%20Service%20Centre/README_EN.md)", "`Geometry`", "Hard", ""]}, {"question_id": "1637", "frontend_question_id": "1531", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/string-compression-ii", "url_en": "https://leetcode.com/problems/string-compression-ii", "relative_path_cn": "/solution/1500-1599/1531.String%20Compression%20II/README.md", "relative_path_en": "/solution/1500-1599/1531.String%20Compression%20II/README_EN.md", "title_cn": "\u538b\u7f29\u5b57\u7b26\u4e32 II", "title_en": "String Compression II", "question_title_slug": "string-compression-ii", "content_en": "

    Run-length encoding is a string compression method that works by replacing consecutive identical characters (repeated 2 or more times) with the concatenation of the character and the number marking the count of the characters (length of the run). For example, to compress the string "aabccc" we replace "aa" by "a2" and replace "ccc" by "c3". Thus the compressed string becomes "a2bc3".

    \n\n

    Notice that in this problem, we are not adding '1' after single characters.

    \n\n

    Given a string s and an integer k. You need to delete at most k characters from s such that the run-length encoded version of s has minimum length.

    \n\n

    Find the minimum length of the run-length encoded version of s after deleting at most k characters.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "aaabcccd", k = 2\nOutput: 4\nExplanation: Compressing s without deleting anything will give us "a3bc3d" of length 6. Deleting any of the characters 'a' or 'c' would at most decrease the length of the compressed string to 5, for instance delete 2 'a' then we will have s = "abcccd" which compressed is abc3d. Therefore, the optimal way is to delete 'b' and 'd', then the compressed version of s will be "a3c3" of length 4.
    \n\n

    Example 2:

    \n\n
    \nInput: s = "aabbaa", k = 2\nOutput: 2\nExplanation: If we delete both 'b' characters, the resulting compressed string would be "a4" of length 2.\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "aaaaaaaaaaa", k = 0\nOutput: 3\nExplanation: Since k is zero, we cannot delete anything. The compressed string is "a11" of length 3.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 100
    • \n\t
    • 0 <= k <= s.length
    • \n\t
    • s contains only lowercase English letters.
    • \n
    \n", "content_cn": "

    \u884c\u7a0b\u957f\u5ea6\u7f16\u7801 \u662f\u4e00\u79cd\u5e38\u7528\u7684\u5b57\u7b26\u4e32\u538b\u7f29\u65b9\u6cd5\uff0c\u5b83\u5c06\u8fde\u7eed\u7684\u76f8\u540c\u5b57\u7b26\uff08\u91cd\u590d 2 \u6b21\u6216\u66f4\u591a\u6b21\uff09\u66ff\u6362\u4e3a\u5b57\u7b26\u548c\u8868\u793a\u5b57\u7b26\u8ba1\u6570\u7684\u6570\u5b57\uff08\u884c\u7a0b\u957f\u5ea6\uff09\u3002\u4f8b\u5982\uff0c\u7528\u6b64\u65b9\u6cd5\u538b\u7f29\u5b57\u7b26\u4e32 "aabccc" \uff0c\u5c06 "aa" \u66ff\u6362\u4e3a "a2" \uff0c"ccc" \u66ff\u6362\u4e3a` "c3" \u3002\u56e0\u6b64\u538b\u7f29\u540e\u7684\u5b57\u7b26\u4e32\u53d8\u4e3a "a2bc3" \u3002

    \n\n

    \u6ce8\u610f\uff0c\u672c\u95ee\u9898\u4e2d\uff0c\u538b\u7f29\u65f6\u6ca1\u6709\u5728\u5355\u4e2a\u5b57\u7b26\u540e\u9644\u52a0\u8ba1\u6570 '1' \u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \u548c\u4e00\u4e2a\u6574\u6570 k \u3002\u4f60\u9700\u8981\u4ece\u5b57\u7b26\u4e32 s \u4e2d\u5220\u9664\u6700\u591a k \u4e2a\u5b57\u7b26\uff0c\u4ee5\u4f7f s \u7684\u884c\u7a0b\u957f\u5ea6\u7f16\u7801\u957f\u5ea6\u6700\u5c0f\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u5220\u9664\u6700\u591a k \u4e2a\u5b57\u7b26\u540e\uff0cs \u884c\u7a0b\u957f\u5ea6\u7f16\u7801\u7684\u6700\u5c0f\u957f\u5ea6 \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1as = "aaabcccd", k = 2\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u5728\u4e0d\u5220\u9664\u4efb\u4f55\u5185\u5bb9\u7684\u60c5\u51b5\u4e0b\uff0c\u538b\u7f29\u540e\u7684\u5b57\u7b26\u4e32\u662f "a3bc3d" \uff0c\u957f\u5ea6\u4e3a 6 \u3002\u6700\u4f18\u7684\u65b9\u6848\u662f\u5220\u9664 'b' \u548c 'd'\uff0c\u8fd9\u6837\u4e00\u6765\uff0c\u538b\u7f29\u540e\u7684\u5b57\u7b26\u4e32\u4e3a "a3c3" \uff0c\u957f\u5ea6\u662f 4 \u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1as = "aabbaa", k = 2\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5982\u679c\u5220\u53bb\u4e24\u4e2a 'b' \u5b57\u7b26\uff0c\u90a3\u4e48\u538b\u7f29\u540e\u7684\u5b57\u7b26\u4e32\u662f\u957f\u5ea6\u4e3a 2 \u7684 "a4" \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1as = "aaaaaaaaaaa", k = 0\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u7531\u4e8e k \u7b49\u4e8e 0 \uff0c\u4e0d\u80fd\u5220\u53bb\u4efb\u4f55\u5b57\u7b26\u3002\u538b\u7f29\u540e\u7684\u5b57\u7b26\u4e32\u662f "a11" \uff0c\u957f\u5ea6\u4e3a 3 \u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 100
    • \n\t
    • 0 <= k <= s.length
    • \n\t
    • s \u4ec5\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd
    • \n
    \n", "tags_en": ["String", "Dynamic Programming"], "tags_cn": ["\u5b57\u7b26\u4e32", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int getLengthOfOptimalCompression(string s, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int getLengthOfOptimalCompression(String s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getLengthOfOptimalCompression(self, s, k):\n \"\"\"\n :type s: str\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getLengthOfOptimalCompression(self, s: str, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint getLengthOfOptimalCompression(char * s, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int GetLengthOfOptimalCompression(string s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number} k\n * @return {number}\n */\nvar getLengthOfOptimalCompression = function(s, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer} k\n# @return {Integer}\ndef get_length_of_optimal_compression(s, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getLengthOfOptimalCompression(_ s: String, _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getLengthOfOptimalCompression(s string, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getLengthOfOptimalCompression(s: String, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getLengthOfOptimalCompression(s: String, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_length_of_optimal_compression(s: String, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer $k\n * @return Integer\n */\n function getLengthOfOptimalCompression($s, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getLengthOfOptimalCompression(s: string, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-length-of-optimal-compression s k)\n (-> string? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1531](https://leetcode-cn.com/problems/string-compression-ii)", "[\u538b\u7f29\u5b57\u7b26\u4e32 II](/solution/1500-1599/1531.String%20Compression%20II/README.md)", "`\u5b57\u7b26\u4e32`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1531](https://leetcode.com/problems/string-compression-ii)", "[String Compression II](/solution/1500-1599/1531.String%20Compression%20II/README_EN.md)", "`String`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "1636", "frontend_question_id": "1513", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-substrings-with-only-1s", "url_en": "https://leetcode.com/problems/number-of-substrings-with-only-1s", "relative_path_cn": "/solution/1500-1599/1513.Number%20of%20Substrings%20With%20Only%201s/README.md", "relative_path_en": "/solution/1500-1599/1513.Number%20of%20Substrings%20With%20Only%201s/README_EN.md", "title_cn": "\u4ec5\u542b 1 \u7684\u5b50\u4e32\u6570", "title_en": "Number of Substrings With Only 1s", "question_title_slug": "number-of-substrings-with-only-1s", "content_en": "

    Given a binary string s (a string consisting only of '0' and '1's).

    \r\n\r\n

    Return the number of substrings with all characters 1's.

    \r\n\r\n

    Since the answer may be too large, return it modulo 10^9 + 7.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: s = "0110111"\r\nOutput: 9\r\nExplanation: There are 9 substring in total with only 1's characters.\r\n"1" -> 5 times.\r\n"11" -> 3 times.\r\n"111" -> 1 time.
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: s = "101"\r\nOutput: 2\r\nExplanation: Substring "1" is shown 2 times in s.\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: s = "111111"\r\nOutput: 21\r\nExplanation: Each substring contains only 1's characters.\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: s = "000"\r\nOutput: 0\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • s[i] == '0' or s[i] == '1'
    • \r\n\t
    • 1 <= s.length <= 10^5
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32 s\uff08\u4ec5\u7531 '0' \u548c '1' \u7ec4\u6210\u7684\u5b57\u7b26\u4e32\uff09\u3002

    \n\n

    \u8fd4\u56de\u6240\u6709\u5b57\u7b26\u90fd\u4e3a 1 \u7684\u5b50\u5b57\u7b26\u4e32\u7684\u6570\u76ee\u3002

    \n\n

    \u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u5f88\u5927\uff0c\u8bf7\u4f60\u5c06\u5b83\u5bf9 10^9 + 7 \u53d6\u6a21\u540e\u8fd4\u56de\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1as = "0110111"\n\u8f93\u51fa\uff1a9\n\u89e3\u91ca\uff1a\u5171\u6709 9 \u4e2a\u5b50\u5b57\u7b26\u4e32\u4ec5\u7531 '1' \u7ec4\u6210\n"1" -> 5 \u6b21\n"11" -> 3 \u6b21\n"111" -> 1 \u6b21
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1as = "101"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5b50\u5b57\u7b26\u4e32 "1" \u5728 s \u4e2d\u5171\u51fa\u73b0 2 \u6b21\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1as = "111111"\n\u8f93\u51fa\uff1a21\n\u89e3\u91ca\uff1a\u6bcf\u4e2a\u5b50\u5b57\u7b26\u4e32\u90fd\u4ec5\u7531 '1' \u7ec4\u6210\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1as = "000"\n\u8f93\u51fa\uff1a0\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • s[i] == '0' \u6216 s[i] == '1'
    • \n\t
    • 1 <= s.length <= 10^5
    • \n
    \n", "tags_en": ["Math", "String"], "tags_cn": ["\u6570\u5b66", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numSub(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numSub(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numSub(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numSub(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numSub(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumSub(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar numSub = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef num_sub(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numSub(_ s: String) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numSub(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numSub(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numSub(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_sub(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function numSub($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numSub(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-sub s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1513](https://leetcode-cn.com/problems/number-of-substrings-with-only-1s)", "[\u4ec5\u542b 1 \u7684\u5b50\u4e32\u6570](/solution/1500-1599/1513.Number%20of%20Substrings%20With%20Only%201s/README.md)", "`\u6570\u5b66`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1513](https://leetcode.com/problems/number-of-substrings-with-only-1s)", "[Number of Substrings With Only 1s](/solution/1500-1599/1513.Number%20of%20Substrings%20With%20Only%201s/README_EN.md)", "`Math`,`String`", "Medium", ""]}, {"question_id": "1635", "frontend_question_id": "1512", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-good-pairs", "url_en": "https://leetcode.com/problems/number-of-good-pairs", "relative_path_cn": "/solution/1500-1599/1512.Number%20of%20Good%20Pairs/README.md", "relative_path_en": "/solution/1500-1599/1512.Number%20of%20Good%20Pairs/README_EN.md", "title_cn": "\u597d\u6570\u5bf9\u7684\u6570\u76ee", "title_en": "Number of Good Pairs", "question_title_slug": "number-of-good-pairs", "content_en": "

    Given an array of integers nums.

    \r\n\r\n

    A pair (i,j) is called good if nums[i] == nums[j] and i < j.

    \r\n\r\n

    Return the number of good pairs.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: nums = [1,2,3,1,1,3]\r\nOutput: 4\r\nExplanation: There are 4 good pairs (0,3), (0,4), (3,4), (2,5) 0-indexed.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: nums = [1,1,1,1]\r\nOutput: 6\r\nExplanation: Each pair in the array are good.\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: nums = [1,2,3]\r\nOutput: 0\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= nums.length <= 100
    • \r\n\t
    • 1 <= nums[i] <= 100
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \u3002

    \n\n

    \u5982\u679c\u4e00\u7ec4\u6570\u5b57 (i,j) \u6ee1\u8db3 nums[i] == nums[j] \u4e14 i < j \uff0c\u5c31\u53ef\u4ee5\u8ba4\u4e3a\u8fd9\u662f\u4e00\u7ec4 \u597d\u6570\u5bf9 \u3002

    \n\n

    \u8fd4\u56de\u597d\u6570\u5bf9\u7684\u6570\u76ee\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,2,3,1,1,3]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u6709 4 \u7ec4\u597d\u6570\u5bf9\uff0c\u5206\u522b\u662f (0,3), (0,4), (3,4), (2,5) \uff0c\u4e0b\u6807\u4ece 0 \u5f00\u59cb\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,1,1,1]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u6570\u7ec4\u4e2d\u7684\u6bcf\u7ec4\u6570\u5b57\u90fd\u662f\u597d\u6570\u5bf9
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,2,3]\n\u8f93\u51fa\uff1a0\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 100
    • \n\t
    • 1 <= nums[i] <= 100
    • \n
    \n", "tags_en": ["Array", "Hash Table", "Math"], "tags_cn": ["\u6570\u7ec4", "\u54c8\u5e0c\u8868", "\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numIdenticalPairs(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numIdenticalPairs(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numIdenticalPairs(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numIdenticalPairs(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numIdenticalPairs(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumIdenticalPairs(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar numIdenticalPairs = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef num_identical_pairs(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numIdenticalPairs(_ nums: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numIdenticalPairs(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numIdenticalPairs(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numIdenticalPairs(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_identical_pairs(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function numIdenticalPairs($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numIdenticalPairs(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-identical-pairs nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1512](https://leetcode-cn.com/problems/number-of-good-pairs)", "[\u597d\u6570\u5bf9\u7684\u6570\u76ee](/solution/1500-1599/1512.Number%20of%20Good%20Pairs/README.md)", "`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`,`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[1512](https://leetcode.com/problems/number-of-good-pairs)", "[Number of Good Pairs](/solution/1500-1599/1512.Number%20of%20Good%20Pairs/README_EN.md)", "`Array`,`Hash Table`,`Math`", "Easy", ""]}, {"question_id": "1634", "frontend_question_id": "1490", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/clone-n-ary-tree", "url_en": "https://leetcode.com/problems/clone-n-ary-tree", "relative_path_cn": "/solution/1400-1499/1490.Clone%20N-ary%20Tree/README.md", "relative_path_en": "/solution/1400-1499/1490.Clone%20N-ary%20Tree/README_EN.md", "title_cn": "\u514b\u9686 N \u53c9\u6811", "title_en": "Clone N-ary Tree", "question_title_slug": "clone-n-ary-tree", "content_en": "

    Given a root of an N-ary tree, return a deep copy (clone) of the tree.

    \n\n

    Each node in the n-ary tree contains a val (int) and a list (List[Node]) of its children.

    \n\n
    \nclass Node {\n    public int val;\n    public List<Node> children;\n}\n
    \n\n

    Nary-Tree input serialization is represented in their level order traversal, each group of children is separated by the null value (See examples).

    \n\n

     

    \n

    Example 1:

    \n\n

    \n\n
    \nInput: root = [1,null,3,2,4,null,5,6]\nOutput: [1,null,3,2,4,null,5,6]\n
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: root = [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]\nOutput: [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The depth of the n-ary tree is less than or equal to 1000.
    • \n\t
    • The total number of nodes is between [0, 104].
    • \n
    \n\n

     

    \nFollow up: Can your solution work for the graph problem?", "content_cn": "

    \u7ed9\u5b9a\u4e00\u68f5 N \u53c9\u6811\u7684\u6839\u8282\u70b9 root \uff0c\u8fd4\u56de\u8be5\u6811\u7684\u6df1\u62f7\u8d1d\uff08\u514b\u9686\uff09\u3002

    \n\n

    N \u53c9\u6811\u7684\u6bcf\u4e2a\u8282\u70b9\u90fd\u5305\u542b\u4e00\u4e2a\u503c\uff08 int \uff09\u548c\u5b50\u8282\u70b9\u7684\u5217\u8868\uff08 List[Node] \uff09\u3002

    \n\n
    \nclass Node {\n    public int val;\n    public List<Node> children;\n}\n
    \n\n

    N \u53c9\u6811\u7684\u8f93\u5165\u5e8f\u5217\u7528\u5c42\u5e8f\u904d\u5386\u8868\u793a\uff0c\u6bcf\u7ec4\u5b50\u8282\u70b9\u7528 null \u5206\u9694\uff08\u89c1\u793a\u4f8b\uff09\u3002

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u7684\u7b54\u6848\u53ef\u4ee5\u9002\u7528\u4e8e\u514b\u9686\u56fe\u95ee\u9898\u5417\uff1f

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \n\n
    \n\u8f93\u5165\uff1aroot = [1,null,3,2,4,null,5,6]\n\u8f93\u51fa\uff1a[1,null,3,2,4,null,5,6]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aroot = [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]\n\u8f93\u51fa\uff1a[1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u7ed9\u5b9a\u7684 N \u53c9\u6811\u7684\u6df1\u5ea6\u5c0f\u4e8e\u6216\u7b49\u4e8e 1000\u3002
    • \n\t
    • \u8282\u70b9\u7684\u603b\u4e2a\u6570\u5728 [0, 10^4] \u4e4b\u95f4
    • \n
    \n", "tags_en": ["Tree", "Depth-first Search", "Breadth-first Search", "Hash Table"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n vector children;\n\n Node() {}\n\n Node(int _val) {\n val = _val;\n }\n\n Node(int _val, vector _children) {\n val = _val;\n children = _children;\n }\n};\n*/\n\nclass Solution {\npublic:\n Node* cloneTree(Node* root) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/*\n// Definition for a Node.\nclass Node {\n public int val;\n public List children;\n\n \n public Node() {\n children = new ArrayList();\n }\n \n public Node(int _val) {\n val = _val;\n children = new ArrayList();\n }\n \n public Node(int _val,ArrayList _children) {\n val = _val;\n children = _children;\n }\n};\n*/\n\nclass Solution {\n public Node cloneTree(Node root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "\"\"\"\n# Definition for a Node.\nclass Node(object):\n def __init__(self, val=None, children=None):\n self.val = val\n self.children = children if children is not None else []\n\"\"\"\n\nclass Solution(object):\n def cloneTree(self, root):\n \"\"\"\n :type root: Node\n :rtype: Node\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "\"\"\"\n# Definition for a Node.\nclass Node:\n def __init__(self, val=None, children=None):\n self.val = val\n self.children = children if children is not None else []\n\"\"\"\n\nclass Solution:\n def cloneTree(self, root: 'Node') -> 'Node':", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/*\n// Definition for a Node.\npublic class Node {\n public int val;\n public IList children;\n \n public Node() {\n val = 0;\n children = new List();\n }\n\n public Node(int _val) {\n val = _val;\n children = new List();\n }\n \n public Node(int _val, List _children) {\n val = _val;\n children = _children;\n }\n}\n*/\n\n\npublic class Solution {\n public Node CloneTree(Node root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // Definition for a Node.\n * function Node(val, children) {\n * this.val = val === undefined ? 0 : val;\n * this.children = children === undefined ? [] : children;\n * };\n */\n\n/**\n * @param {Node|null} node\n * @return {Node|null}\n */\nvar cloneTree = function(root) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a Node.\n# class Node\n# attr_accessor :val, :children\n# def initialize(val=0, children=[])\n# @val = val\n# @children = children\n# end\n# end\n\n# @param {Node} root\n# @return {Node}\ndef clone_tree(root)\n\t\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a Node.\n * public class Node {\n * public var val: Int\n * public var children: [Node]\n * public init(_ val: Int) {\n * self.val = val\n * self.children = []\n * }\n * }\n */\n\nclass Solution {\n func cloneTree(_ root: Node?) -> Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a Node.\n * type Node struct {\n * Val int\n * Children []*Node\n * }\n */\n\nfunc cloneTree(root *Node) *Node {\n\t\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a Node.\n * class Node(var _value: Int) {\n * var value: Int = _value\n * var children: List[Node] = List()\n * }\n */\n\nobject Solution {\n def cloneTree(root: Node): Node = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a Node.\n * class Node(var `val`: Int) {\n * var children: List = listOf()\n * }\n */\n\nclass Solution {\n fun cloneTree(root: Node?): Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a Node.\n * class Node {\n * public $val = null;\n * public $children = null;\n * function __construct($val = 0) {\n * $this->val = $val;\n * $this->children = array();\n * }\n * }\n */\n\nclass Solution {\n /**\n * @param Node $root\n * @return Node\n */\n function cloneTree($root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for Node.\n * class Node {\n * val: number\n * children: Node[]\n * constructor(val?: number, children?: Node[]) {\n * this.val = (val===undefined ? 0 : val)\n * this.children = (children===undefined ? [] : children)\n * }\n * }\n */\n\nfunction cloneTree(root: Node | null): Node | null {\n \n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1490](https://leetcode-cn.com/problems/clone-n-ary-tree)", "[\u514b\u9686 N \u53c9\u6811](/solution/1400-1499/1490.Clone%20N-ary%20Tree/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1490](https://leetcode.com/problems/clone-n-ary-tree)", "[Clone N-ary Tree](/solution/1400-1499/1490.Clone%20N-ary%20Tree/README_EN.md)", "`Tree`,`Depth-first Search`,`Breadth-first Search`,`Hash Table`", "Medium", "\ud83d\udd12"]}, {"question_id": "1633", "frontend_question_id": "1526", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-number-of-increments-on-subarrays-to-form-a-target-array", "url_en": "https://leetcode.com/problems/minimum-number-of-increments-on-subarrays-to-form-a-target-array", "relative_path_cn": "/solution/1500-1599/1526.Minimum%20Number%20of%20Increments%20on%20Subarrays%20to%20Form%20a%20Target%20Array/README.md", "relative_path_en": "/solution/1500-1599/1526.Minimum%20Number%20of%20Increments%20on%20Subarrays%20to%20Form%20a%20Target%20Array/README_EN.md", "title_cn": "\u5f62\u6210\u76ee\u6807\u6570\u7ec4\u7684\u5b50\u6570\u7ec4\u6700\u5c11\u589e\u52a0\u6b21\u6570", "title_en": "Minimum Number of Increments on Subarrays to Form a Target Array", "question_title_slug": "minimum-number-of-increments-on-subarrays-to-form-a-target-array", "content_en": "

    Given an array of positive integers target and an array initial of same size with all zeros.

    \n\n

    Return the minimum number of operations to form a target array from initial if you are allowed to do the following operation:

    \n\n
      \n\t
    • Choose any subarray from initial and increment each value by one.
    • \n
    \nThe answer is guaranteed to fit within the range of a 32-bit signed integer.\n

     

    \n

    Example 1:

    \n\n
    \nInput: target = [1,2,3,2,1]\nOutput: 3\nExplanation: We need at least 3 operations to form the target array from the initial array.\n[0,0,0,0,0] increment 1 from index 0 to 4 (inclusive).\n[1,1,1,1,1] increment 1 from index 1 to 3 (inclusive).\n[1,2,2,2,1] increment 1 at index 2.\n[1,2,3,2,1] target array is formed.\n
    \n\n

    Example 2:

    \n\n
    \nInput: target = [3,1,1,2]\nOutput: 4\nExplanation: (initial)[0,0,0,0] -> [1,1,1,1] -> [1,1,1,2] -> [2,1,1,2] -> [3,1,1,2] (target).\n
    \n\n

    Example 3:

    \n\n
    \nInput: target = [3,1,5,4,2]\nOutput: 7\nExplanation: (initial)[0,0,0,0,0] -> [1,1,1,1,1] -> [2,1,1,1,1] -> [3,1,1,1,1] \n                                  -> [3,1,2,2,2] -> [3,1,3,3,2] -> [3,1,4,4,2] -> [3,1,5,4,2] (target).\n
    \n\n

    Example 4:

    \n\n
    \nInput: target = [1,1,1,1]\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= target.length <= 10^5
    • \n\t
    • 1 <= target[i] <= 10^5
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 target \u548c\u4e00\u4e2a\u6570\u7ec4 initial \uff0cinitial \u6570\u7ec4\u4e0e target  \u6570\u7ec4\u6709\u540c\u6837\u7684\u7ef4\u5ea6\uff0c\u4e14\u4e00\u5f00\u59cb\u5168\u90e8\u4e3a 0 \u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u4ece initial \u5f97\u5230  target \u7684\u6700\u5c11\u64cd\u4f5c\u6b21\u6570\uff0c\u6bcf\u6b21\u64cd\u4f5c\u9700\u9075\u5faa\u4ee5\u4e0b\u89c4\u5219\uff1a

    \n\n
      \n\t
    • \u5728 initial \u4e2d\u9009\u62e9 \u4efb\u610f \u5b50\u6570\u7ec4\uff0c\u5e76\u5c06\u5b50\u6570\u7ec4\u4e2d\u6bcf\u4e2a\u5143\u7d20\u589e\u52a0 1 \u3002
    • \n
    \n\n

    \u7b54\u6848\u4fdd\u8bc1\u5728 32 \u4f4d\u6709\u7b26\u53f7\u6574\u6570\u4ee5\u5185\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1atarget = [1,2,3,2,1]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6211\u4eec\u9700\u8981\u81f3\u5c11 3 \u6b21\u64cd\u4f5c\u4ece intial \u6570\u7ec4\u5f97\u5230 target \u6570\u7ec4\u3002\n[0,0,0,0,0] \u5c06\u4e0b\u6807\u4e3a 0 \u5230 4 \u7684\u5143\u7d20\uff08\u5305\u542b\u4e8c\u8005\uff09\u52a0 1 \u3002\n[1,1,1,1,1] \u5c06\u4e0b\u6807\u4e3a 1 \u5230 3 \u7684\u5143\u7d20\uff08\u5305\u542b\u4e8c\u8005\uff09\u52a0 1 \u3002\n[1,2,2,2,1] \u5c06\u4e0b\u8868\u4e3a 2 \u7684\u5143\u7d20\u589e\u52a0 1 \u3002\n[1,2,3,2,1] \u5f97\u5230\u4e86\u76ee\u6807\u6570\u7ec4\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1atarget = [3,1,1,2]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a(initial)[0,0,0,0] -> [1,1,1,1] -> [1,1,1,2] -> [2,1,1,2] -> [3,1,1,2] (target) \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1atarget = [3,1,5,4,2]\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a(initial)[0,0,0,0,0] -> [1,1,1,1,1] -> [2,1,1,1,1] -> [3,1,1,1,1] \n                                  -> [3,1,2,2,2] -> [3,1,3,3,2] -> [3,1,4,4,2] -> [3,1,5,4,2] (target)\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1atarget = [1,1,1,1]\n\u8f93\u51fa\uff1a1\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= target.length <= 10^5
    • \n\t
    • 1 <= target[i] <= 10^5
    • \n
    \n", "tags_en": ["Segment Tree"], "tags_cn": ["\u7ebf\u6bb5\u6811"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minNumberOperations(vector& target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minNumberOperations(int[] target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minNumberOperations(self, target):\n \"\"\"\n :type target: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minNumberOperations(self, target: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minNumberOperations(int* target, int targetSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinNumberOperations(int[] target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} target\n * @return {number}\n */\nvar minNumberOperations = function(target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} target\n# @return {Integer}\ndef min_number_operations(target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minNumberOperations(_ target: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minNumberOperations(target []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minNumberOperations(target: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minNumberOperations(target: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_number_operations(target: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $target\n * @return Integer\n */\n function minNumberOperations($target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minNumberOperations(target: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-number-operations target)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1526](https://leetcode-cn.com/problems/minimum-number-of-increments-on-subarrays-to-form-a-target-array)", "[\u5f62\u6210\u76ee\u6807\u6570\u7ec4\u7684\u5b50\u6570\u7ec4\u6700\u5c11\u589e\u52a0\u6b21\u6570](/solution/1500-1599/1526.Minimum%20Number%20of%20Increments%20on%20Subarrays%20to%20Form%20a%20Target%20Array/README.md)", "`\u7ebf\u6bb5\u6811`", "\u56f0\u96be", ""], "md_table_row_en": ["[1526](https://leetcode.com/problems/minimum-number-of-increments-on-subarrays-to-form-a-target-array)", "[Minimum Number of Increments on Subarrays to Form a Target Array](/solution/1500-1599/1526.Minimum%20Number%20of%20Increments%20on%20Subarrays%20to%20Form%20a%20Target%20Array/README_EN.md)", "`Segment Tree`", "Hard", ""]}, {"question_id": "1632", "frontend_question_id": "1525", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-good-ways-to-split-a-string", "url_en": "https://leetcode.com/problems/number-of-good-ways-to-split-a-string", "relative_path_cn": "/solution/1500-1599/1525.Number%20of%20Good%20Ways%20to%20Split%20a%20String/README.md", "relative_path_en": "/solution/1500-1599/1525.Number%20of%20Good%20Ways%20to%20Split%20a%20String/README_EN.md", "title_cn": "\u5b57\u7b26\u4e32\u7684\u597d\u5206\u5272\u6570\u76ee", "title_en": "Number of Good Ways to Split a String", "question_title_slug": "number-of-good-ways-to-split-a-string", "content_en": "

    You are given a string s, a split is called good if you can split s into 2 non-empty strings p and q where its concatenation is equal to s and the number of distinct letters in p and q are the same.

    \r\n\r\n

    Return the number of good splits you can make in s.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: s = "aacaba"\r\nOutput: 2\r\nExplanation: There are 5 ways to split "aacaba" and 2 of them are good. \r\n("a", "acaba") Left string and right string contains 1 and 3 different letters respectively.\r\n("aa", "caba") Left string and right string contains 1 and 3 different letters respectively.\r\n("aac", "aba") Left string and right string contains 2 and 2 different letters respectively (good split).\r\n("aaca", "ba") Left string and right string contains 2 and 2 different letters respectively (good split).\r\n("aacab", "a") Left string and right string contains 3 and 1 different letters respectively.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: s = "abcd"\r\nOutput: 1\r\nExplanation: Split the string as follows ("ab", "cd").\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: s = "aaaaa"\r\nOutput: 4\r\nExplanation: All possible splits are good.
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: s = "acbadbaada"\r\nOutput: 2\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • s contains only lowercase English letters.
    • \r\n\t
    • 1 <= s.length <= 10^5
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \uff0c\u4e00\u4e2a\u5206\u5272\u88ab\u79f0\u4e3a \u300c\u597d\u5206\u5272\u300d \u5f53\u5b83\u6ee1\u8db3\uff1a\u5c06 s \u5206\u5272\u6210 2 \u4e2a\u5b57\u7b26\u4e32 p \u548c q \uff0c\u5b83\u4eec\u8fde\u63a5\u8d77\u6765\u7b49\u4e8e s \u4e14 p \u548c q \u4e2d\u4e0d\u540c\u5b57\u7b26\u7684\u6570\u76ee\u76f8\u540c\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de s \u4e2d\u597d\u5206\u5272\u7684\u6570\u76ee\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1as = "aacaba"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u603b\u5171\u6709 5 \u79cd\u5206\u5272\u5b57\u7b26\u4e32 "aacaba" \u7684\u65b9\u6cd5\uff0c\u5176\u4e2d 2 \u79cd\u662f\u597d\u5206\u5272\u3002\n("a", "acaba") \u5de6\u8fb9\u5b57\u7b26\u4e32\u548c\u53f3\u8fb9\u5b57\u7b26\u4e32\u5206\u522b\u5305\u542b 1 \u4e2a\u548c 3 \u4e2a\u4e0d\u540c\u7684\u5b57\u7b26\u3002\n("aa", "caba") \u5de6\u8fb9\u5b57\u7b26\u4e32\u548c\u53f3\u8fb9\u5b57\u7b26\u4e32\u5206\u522b\u5305\u542b 1 \u4e2a\u548c 3 \u4e2a\u4e0d\u540c\u7684\u5b57\u7b26\u3002\n("aac", "aba") \u5de6\u8fb9\u5b57\u7b26\u4e32\u548c\u53f3\u8fb9\u5b57\u7b26\u4e32\u5206\u522b\u5305\u542b 2 \u4e2a\u548c 2 \u4e2a\u4e0d\u540c\u7684\u5b57\u7b26\u3002\u8fd9\u662f\u4e00\u4e2a\u597d\u5206\u5272\u3002\n("aaca", "ba") \u5de6\u8fb9\u5b57\u7b26\u4e32\u548c\u53f3\u8fb9\u5b57\u7b26\u4e32\u5206\u522b\u5305\u542b 2 \u4e2a\u548c 2 \u4e2a\u4e0d\u540c\u7684\u5b57\u7b26\u3002\u8fd9\u662f\u4e00\u4e2a\u597d\u5206\u5272\u3002\n("aacab", "a") \u5de6\u8fb9\u5b57\u7b26\u4e32\u548c\u53f3\u8fb9\u5b57\u7b26\u4e32\u5206\u522b\u5305\u542b 3 \u4e2a\u548c 1 \u4e2a\u4e0d\u540c\u7684\u5b57\u7b26\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1as = "abcd"\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u597d\u5206\u5272\u4e3a\u5c06\u5b57\u7b26\u4e32\u5206\u5272\u6210 ("ab", "cd") \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1as = "aaaaa"\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u6240\u6709\u5206\u5272\u90fd\u662f\u597d\u5206\u5272\u3002
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1as = "acbadbaada"\n\u8f93\u51fa\uff1a2\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • s \u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    • \n\t
    • 1 <= s.length <= 10^5
    • \n
    \n", "tags_en": ["Bit Manipulation", "String"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numSplits(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numSplits(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numSplits(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numSplits(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numSplits(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumSplits(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar numSplits = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef num_splits(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numSplits(_ s: String) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numSplits(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numSplits(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numSplits(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_splits(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function numSplits($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numSplits(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-splits s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1525](https://leetcode-cn.com/problems/number-of-good-ways-to-split-a-string)", "[\u5b57\u7b26\u4e32\u7684\u597d\u5206\u5272\u6570\u76ee](/solution/1500-1599/1525.Number%20of%20Good%20Ways%20to%20Split%20a%20String/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1525](https://leetcode.com/problems/number-of-good-ways-to-split-a-string)", "[Number of Good Ways to Split a String](/solution/1500-1599/1525.Number%20of%20Good%20Ways%20to%20Split%20a%20String/README_EN.md)", "`Bit Manipulation`,`String`", "Medium", ""]}, {"question_id": "1631", "frontend_question_id": "1524", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-sub-arrays-with-odd-sum", "url_en": "https://leetcode.com/problems/number-of-sub-arrays-with-odd-sum", "relative_path_cn": "/solution/1500-1599/1524.Number%20of%20Sub-arrays%20With%20Odd%20Sum/README.md", "relative_path_en": "/solution/1500-1599/1524.Number%20of%20Sub-arrays%20With%20Odd%20Sum/README_EN.md", "title_cn": "\u548c\u4e3a\u5947\u6570\u7684\u5b50\u6570\u7ec4\u6570\u76ee", "title_en": "Number of Sub-arrays With Odd Sum", "question_title_slug": "number-of-sub-arrays-with-odd-sum", "content_en": "

    Given an array of integers arr. Return the number of sub-arrays with odd sum.

    \r\n\r\n

    As the answer may grow large, the answer must be computed modulo 10^9 + 7.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: arr = [1,3,5]\r\nOutput: 4\r\nExplanation: All sub-arrays are [[1],[1,3],[1,3,5],[3],[3,5],[5]]\r\nAll sub-arrays sum are [1,4,9,3,8,5].\r\nOdd sums are [1,9,3,5] so the answer is 4.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: arr = [2,4,6]\r\nOutput: 0\r\nExplanation: All sub-arrays are [[2],[2,4],[2,4,6],[4],[4,6],[6]]\r\nAll sub-arrays sum are [2,6,12,4,10,6].\r\nAll sub-arrays have even sum and the answer is 0.\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: arr = [1,2,3,4,5,6,7]\r\nOutput: 16\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: arr = [100,100,99,99]\r\nOutput: 4\r\n
    \r\n\r\n

    Example 5:

    \r\n\r\n
    \r\nInput: arr = [7]\r\nOutput: 1\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= arr.length <= 10^5
    • \r\n\t
    • 1 <= arr[i] <= 100
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr \u3002\u8bf7\u4f60\u8fd4\u56de\u548c\u4e3a \u5947\u6570 \u7684\u5b50\u6570\u7ec4\u6570\u76ee\u3002

    \n\n

    \u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u4f1a\u5f88\u5927\uff0c\u8bf7\u4f60\u5c06\u7ed3\u679c\u5bf9 10^9 + 7 \u53d6\u4f59\u540e\u8fd4\u56de\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [1,3,5]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u6240\u6709\u7684\u5b50\u6570\u7ec4\u4e3a [[1],[1,3],[1,3,5],[3],[3,5],[5]] \u3002\n\u6240\u6709\u5b50\u6570\u7ec4\u7684\u548c\u4e3a [1,4,9,3,8,5].\n\u5947\u6570\u548c\u5305\u62ec [1,9,3,5] \uff0c\u6240\u4ee5\u7b54\u6848\u4e3a 4 \u3002\n
    \n\n

    \u793a\u4f8b 2 \uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [2,4,6]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6240\u6709\u5b50\u6570\u7ec4\u4e3a [[2],[2,4],[2,4,6],[4],[4,6],[6]] \u3002\n\u6240\u6709\u5b50\u6570\u7ec4\u548c\u4e3a [2,6,12,4,10,6] \u3002\n\u6240\u6709\u5b50\u6570\u7ec4\u548c\u90fd\u662f\u5076\u6570\uff0c\u6240\u4ee5\u7b54\u6848\u4e3a 0 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [1,2,3,4,5,6,7]\n\u8f93\u51fa\uff1a16\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [100,100,99,99]\n\u8f93\u51fa\uff1a4\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [7]\n\u8f93\u51fa\uff1a1\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= arr.length <= 10^5
    • \n\t
    • 1 <= arr[i] <= 100
    • \n
    \n", "tags_en": ["Array", "Math"], "tags_cn": ["\u6570\u7ec4", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numOfSubarrays(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numOfSubarrays(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numOfSubarrays(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numOfSubarrays(self, arr: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numOfSubarrays(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumOfSubarrays(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar numOfSubarrays = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef num_of_subarrays(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numOfSubarrays(_ arr: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numOfSubarrays(arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numOfSubarrays(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numOfSubarrays(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_of_subarrays(arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function numOfSubarrays($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numOfSubarrays(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-of-subarrays arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1524](https://leetcode-cn.com/problems/number-of-sub-arrays-with-odd-sum)", "[\u548c\u4e3a\u5947\u6570\u7684\u5b50\u6570\u7ec4\u6570\u76ee](/solution/1500-1599/1524.Number%20of%20Sub-arrays%20With%20Odd%20Sum/README.md)", "`\u6570\u7ec4`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1524](https://leetcode.com/problems/number-of-sub-arrays-with-odd-sum)", "[Number of Sub-arrays With Odd Sum](/solution/1500-1599/1524.Number%20of%20Sub-arrays%20With%20Odd%20Sum/README_EN.md)", "`Array`,`Math`", "Medium", ""]}, {"question_id": "1630", "frontend_question_id": "1523", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-odd-numbers-in-an-interval-range", "url_en": "https://leetcode.com/problems/count-odd-numbers-in-an-interval-range", "relative_path_cn": "/solution/1500-1599/1523.Count%20Odd%20Numbers%20in%20an%20Interval%20Range/README.md", "relative_path_en": "/solution/1500-1599/1523.Count%20Odd%20Numbers%20in%20an%20Interval%20Range/README_EN.md", "title_cn": "\u5728\u533a\u95f4\u8303\u56f4\u5185\u7edf\u8ba1\u5947\u6570\u6570\u76ee", "title_en": "Count Odd Numbers in an Interval Range", "question_title_slug": "count-odd-numbers-in-an-interval-range", "content_en": "

    Given two non-negative integers low and high. Return the count of odd numbers between low and high (inclusive).

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: low = 3, high = 7\r\nOutput: 3\r\nExplanation: The odd numbers between 3 and 7 are [3,5,7].
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: low = 8, high = 10\r\nOutput: 1\r\nExplanation: The odd numbers between 8 and 10 are [9].
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 0 <= low <= high <= 10^9
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u975e\u8d1f\u6574\u6570 low \u548c high \u3002\u8bf7\u4f60\u8fd4\u56de low \u548c high \u4e4b\u95f4\uff08\u5305\u62ec\u4e8c\u8005\uff09\u5947\u6570\u7684\u6570\u76ee\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1alow = 3, high = 7\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a3 \u5230 7 \u4e4b\u95f4\u5947\u6570\u6570\u5b57\u4e3a [3,5,7] \u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1alow = 8, high = 10\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a8 \u5230 10 \u4e4b\u95f4\u5947\u6570\u6570\u5b57\u4e3a [9] \u3002
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= low <= high <= 10^9
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countOdds(int low, int high) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countOdds(int low, int high) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countOdds(self, low, high):\n \"\"\"\n :type low: int\n :type high: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countOdds(self, low: int, high: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countOdds(int low, int high){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountOdds(int low, int high) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} low\n * @param {number} high\n * @return {number}\n */\nvar countOdds = function(low, high) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} low\n# @param {Integer} high\n# @return {Integer}\ndef count_odds(low, high)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countOdds(_ low: Int, _ high: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countOdds(low int, high int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countOdds(low: Int, high: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countOdds(low: Int, high: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_odds(low: i32, high: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $low\n * @param Integer $high\n * @return Integer\n */\n function countOdds($low, $high) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countOdds(low: number, high: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-odds low high)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1523](https://leetcode-cn.com/problems/count-odd-numbers-in-an-interval-range)", "[\u5728\u533a\u95f4\u8303\u56f4\u5185\u7edf\u8ba1\u5947\u6570\u6570\u76ee](/solution/1500-1599/1523.Count%20Odd%20Numbers%20in%20an%20Interval%20Range/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[1523](https://leetcode.com/problems/count-odd-numbers-in-an-interval-range)", "[Count Odd Numbers in an Interval Range](/solution/1500-1599/1523.Count%20Odd%20Numbers%20in%20an%20Interval%20Range/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "1629", "frontend_question_id": "1505", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-possible-integer-after-at-most-k-adjacent-swaps-on-digits", "url_en": "https://leetcode.com/problems/minimum-possible-integer-after-at-most-k-adjacent-swaps-on-digits", "relative_path_cn": "/solution/1500-1599/1505.Minimum%20Possible%20Integer%20After%20at%20Most%20K%20Adjacent%20Swaps%20On%20Digits/README.md", "relative_path_en": "/solution/1500-1599/1505.Minimum%20Possible%20Integer%20After%20at%20Most%20K%20Adjacent%20Swaps%20On%20Digits/README_EN.md", "title_cn": "\u6700\u591a K \u6b21\u4ea4\u6362\u76f8\u90bb\u6570\u4f4d\u540e\u5f97\u5230\u7684\u6700\u5c0f\u6574\u6570", "title_en": "Minimum Possible Integer After at Most K Adjacent Swaps On Digits", "question_title_slug": "minimum-possible-integer-after-at-most-k-adjacent-swaps-on-digits", "content_en": "

    Given a string num representing the digits of a very large integer and an integer k.

    \n\n

    You are allowed to swap any two adjacent digits of the integer at most k times.

    \n\n

    Return the minimum integer you can obtain also as a string.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: num = "4321", k = 4\nOutput: "1342"\nExplanation: The steps to obtain the minimum integer from 4321 with 4 adjacent swaps are shown.\n
    \n\n

    Example 2:

    \n\n
    \nInput: num = "100", k = 1\nOutput: "010"\nExplanation: It's ok for the output to have leading zeros, but the input is guaranteed not to have any leading zeros.\n
    \n\n

    Example 3:

    \n\n
    \nInput: num = "36789", k = 1000\nOutput: "36789"\nExplanation: We can keep the number without any swaps.\n
    \n\n

    Example 4:

    \n\n
    \nInput: num = "22", k = 22\nOutput: "22"\n
    \n\n

    Example 5:

    \n\n
    \nInput: num = "9438957234785635408", k = 23\nOutput: "0345989723478563548"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= num.length <= 30000
    • \n\t
    • num contains digits only and doesn't have leading zeros.
    • \n\t
    • 1 <= k <= 10^9
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 num \u548c\u4e00\u4e2a\u6574\u6570 k \u3002\u5176\u4e2d\uff0cnum \u8868\u793a\u4e00\u4e2a\u5f88\u5927\u7684\u6574\u6570\uff0c\u5b57\u7b26\u4e32\u4e2d\u7684\u6bcf\u4e2a\u5b57\u7b26\u4f9d\u6b21\u5bf9\u5e94\u6574\u6570\u4e0a\u7684\u5404\u4e2a \u6570\u4f4d \u3002

    \n\n

    \u4f60\u53ef\u4ee5\u4ea4\u6362\u8fd9\u4e2a\u6574\u6570\u76f8\u90bb\u6570\u4f4d\u7684\u6570\u5b57 \u6700\u591a k \u6b21\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u4f60\u80fd\u5f97\u5230\u7684\u6700\u5c0f\u6574\u6570\uff0c\u5e76\u4ee5\u5b57\u7b26\u4e32\u5f62\u5f0f\u8fd4\u56de\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1anum = "4321", k = 4\n\u8f93\u51fa\uff1a"1342"\n\u89e3\u91ca\uff1a4321 \u901a\u8fc7 4 \u6b21\u4ea4\u6362\u76f8\u90bb\u6570\u4f4d\u5f97\u5230\u6700\u5c0f\u6574\u6570\u7684\u6b65\u9aa4\u5982\u4e0a\u56fe\u6240\u793a\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anum = "100", k = 1\n\u8f93\u51fa\uff1a"010"\n\u89e3\u91ca\uff1a\u8f93\u51fa\u53ef\u4ee5\u5305\u542b\u524d\u5bfc 0 \uff0c\u4f46\u8f93\u5165\u4fdd\u8bc1\u4e0d\u4f1a\u6709\u524d\u5bfc 0 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anum = "36789", k = 1000\n\u8f93\u51fa\uff1a"36789"\n\u89e3\u91ca\uff1a\u4e0d\u9700\u8981\u505a\u4efb\u4f55\u4ea4\u6362\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1anum = "22", k = 22\n\u8f93\u51fa\uff1a"22"\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1anum = "9438957234785635408", k = 23\n\u8f93\u51fa\uff1a"0345989723478563548"\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= num.length <= 30000
    • \n\t
    • num \u53ea\u5305\u542b \u6570\u5b57 \u4e14\u4e0d\u542b\u6709 \u524d\u5bfc 0 \u3002
    • \n\t
    • 1 <= k <= 10^9
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string minInteger(string num, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String minInteger(String num, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minInteger(self, num, k):\n \"\"\"\n :type num: str\n :type k: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minInteger(self, num: str, k: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * minInteger(char * num, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string MinInteger(string num, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} num\n * @param {number} k\n * @return {string}\n */\nvar minInteger = function(num, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} num\n# @param {Integer} k\n# @return {String}\ndef min_integer(num, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minInteger(_ num: String, _ k: Int) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minInteger(num string, k int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minInteger(num: String, k: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minInteger(num: String, k: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_integer(num: String, k: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $num\n * @param Integer $k\n * @return String\n */\n function minInteger($num, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minInteger(num: string, k: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-integer num k)\n (-> string? exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1505](https://leetcode-cn.com/problems/minimum-possible-integer-after-at-most-k-adjacent-swaps-on-digits)", "[\u6700\u591a K \u6b21\u4ea4\u6362\u76f8\u90bb\u6570\u4f4d\u540e\u5f97\u5230\u7684\u6700\u5c0f\u6574\u6570](/solution/1500-1599/1505.Minimum%20Possible%20Integer%20After%20at%20Most%20K%20Adjacent%20Swaps%20On%20Digits/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[1505](https://leetcode.com/problems/minimum-possible-integer-after-at-most-k-adjacent-swaps-on-digits)", "[Minimum Possible Integer After at Most K Adjacent Swaps On Digits](/solution/1500-1599/1505.Minimum%20Possible%20Integer%20After%20at%20Most%20K%20Adjacent%20Swaps%20On%20Digits/README_EN.md)", "`Greedy`", "Hard", ""]}, {"question_id": "1628", "frontend_question_id": "1504", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-submatrices-with-all-ones", "url_en": "https://leetcode.com/problems/count-submatrices-with-all-ones", "relative_path_cn": "/solution/1500-1599/1504.Count%20Submatrices%20With%20All%20Ones/README.md", "relative_path_en": "/solution/1500-1599/1504.Count%20Submatrices%20With%20All%20Ones/README_EN.md", "title_cn": "\u7edf\u8ba1\u5168 1 \u5b50\u77e9\u5f62", "title_en": "Count Submatrices With All Ones", "question_title_slug": "count-submatrices-with-all-ones", "content_en": "

    Given a rows * columns matrix mat of ones and zeros, return how many submatrices have all ones.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: mat = [[1,0,1],\r\n              [1,1,0],\r\n              [1,1,0]]\r\nOutput: 13\r\nExplanation:\r\nThere are 6 rectangles of side 1x1.\r\nThere are 2 rectangles of side 1x2.\r\nThere are 3 rectangles of side 2x1.\r\nThere is 1 rectangle of side 2x2. \r\nThere is 1 rectangle of side 3x1.\r\nTotal number of rectangles = 6 + 2 + 3 + 1 + 1 = 13.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: mat = [[0,1,1,0],\r\n              [0,1,1,1],\r\n              [1,1,1,0]]\r\nOutput: 24\r\nExplanation:\r\nThere are 8 rectangles of side 1x1.\r\nThere are 5 rectangles of side 1x2.\r\nThere are 2 rectangles of side 1x3. \r\nThere are 4 rectangles of side 2x1.\r\nThere are 2 rectangles of side 2x2. \r\nThere are 2 rectangles of side 3x1. \r\nThere is 1 rectangle of side 3x2. \r\nTotal number of rectangles = 8 + 5 + 2 + 4 + 2 + 2 + 1 = 24.\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: mat = [[1,1,1,1,1,1]]\r\nOutput: 21\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: mat = [[1,0,1],[0,1,0],[1,0,1]]\r\nOutput: 5\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= rows <= 150
    • \r\n\t
    • 1 <= columns <= 150
    • \r\n\t
    • 0 <= mat[i][j] <= 1
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u53ea\u5305\u542b 0 \u548c 1 \u7684 rows * columns \u77e9\u9635 mat \uff0c\u8bf7\u4f60\u8fd4\u56de\u6709\u591a\u5c11\u4e2a \u5b50\u77e9\u5f62 \u7684\u5143\u7d20\u5168\u90e8\u90fd\u662f 1 \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1amat = [[1,0,1],\n            [1,1,0],\n            [1,1,0]]\n\u8f93\u51fa\uff1a13\n\u89e3\u91ca\uff1a\n\u6709 6 \u4e2a 1x1 \u7684\u77e9\u5f62\u3002\n\u6709 2 \u4e2a 1x2 \u7684\u77e9\u5f62\u3002\n\u6709 3 \u4e2a 2x1 \u7684\u77e9\u5f62\u3002\n\u6709 1 \u4e2a 2x2 \u7684\u77e9\u5f62\u3002\n\u6709 1 \u4e2a 3x1 \u7684\u77e9\u5f62\u3002\n\u77e9\u5f62\u6570\u76ee\u603b\u5171 = 6 + 2 + 3 + 1 + 1 = 13 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1amat = [[0,1,1,0],\n            [0,1,1,1],\n            [1,1,1,0]]\n\u8f93\u51fa\uff1a24\n\u89e3\u91ca\uff1a\n\u6709 8 \u4e2a 1x1 \u7684\u5b50\u77e9\u5f62\u3002\n\u6709 5 \u4e2a 1x2 \u7684\u5b50\u77e9\u5f62\u3002\n\u6709 2 \u4e2a 1x3 \u7684\u5b50\u77e9\u5f62\u3002\n\u6709 4 \u4e2a 2x1 \u7684\u5b50\u77e9\u5f62\u3002\n\u6709 2 \u4e2a 2x2 \u7684\u5b50\u77e9\u5f62\u3002\n\u6709 2 \u4e2a 3x1 \u7684\u5b50\u77e9\u5f62\u3002\n\u6709 1 \u4e2a 3x2 \u7684\u5b50\u77e9\u5f62\u3002\n\u77e9\u5f62\u6570\u76ee\u603b\u5171 = 8 + 5 + 2 + 4 + 2 + 2 + 1 = 24 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1amat = [[1,1,1,1,1,1]]\n\u8f93\u51fa\uff1a21\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1amat = [[1,0,1],[0,1,0],[1,0,1]]\n\u8f93\u51fa\uff1a5\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= rows <= 150
    • \n\t
    • 1 <= columns <= 150
    • \n\t
    • 0 <= mat[i][j] <= 1
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numSubmat(vector>& mat) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numSubmat(int[][] mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numSubmat(self, mat):\n \"\"\"\n :type mat: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numSubmat(self, mat: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numSubmat(int** mat, int matSize, int* matColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumSubmat(int[][] mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} mat\n * @return {number}\n */\nvar numSubmat = function(mat) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} mat\n# @return {Integer}\ndef num_submat(mat)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numSubmat(_ mat: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numSubmat(mat [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numSubmat(mat: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numSubmat(mat: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_submat(mat: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $mat\n * @return Integer\n */\n function numSubmat($mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numSubmat(mat: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-submat mat)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1504](https://leetcode-cn.com/problems/count-submatrices-with-all-ones)", "[\u7edf\u8ba1\u5168 1 \u5b50\u77e9\u5f62](/solution/1500-1599/1504.Count%20Submatrices%20With%20All%20Ones/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1504](https://leetcode.com/problems/count-submatrices-with-all-ones)", "[Count Submatrices With All Ones](/solution/1500-1599/1504.Count%20Submatrices%20With%20All%20Ones/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "1627", "frontend_question_id": "1503", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/last-moment-before-all-ants-fall-out-of-a-plank", "url_en": "https://leetcode.com/problems/last-moment-before-all-ants-fall-out-of-a-plank", "relative_path_cn": "/solution/1500-1599/1503.Last%20Moment%20Before%20All%20Ants%20Fall%20Out%20of%20a%20Plank/README.md", "relative_path_en": "/solution/1500-1599/1503.Last%20Moment%20Before%20All%20Ants%20Fall%20Out%20of%20a%20Plank/README_EN.md", "title_cn": "\u6240\u6709\u8682\u8681\u6389\u4e0b\u6765\u524d\u7684\u6700\u540e\u4e00\u523b", "title_en": "Last Moment Before All Ants Fall Out of a Plank", "question_title_slug": "last-moment-before-all-ants-fall-out-of-a-plank", "content_en": "

    We have a wooden plank of the length n units. Some ants are walking on the plank, each ant moves with speed 1 unit per second. Some of the ants move to the left, the other move to the right.

    \r\n\r\n

    When two ants moving in two different directions meet at some point, they change their directions and continue moving again. Assume changing directions doesn't take any additional time.

    \r\n\r\n

    When an ant reaches one end of the plank at a time t, it falls out of the plank imediately.

    \r\n\r\n

    Given an integer n and two integer arrays left and right, the positions of the ants moving to the left and the right. Return the moment when the last ant(s) fall out of the plank.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\"\"\r\n
    \r\nInput: n = 4, left = [4,3], right = [0,1]\r\nOutput: 4\r\nExplanation: In the image above:\r\n-The ant at index 0 is named A and going to the right.\r\n-The ant at index 1 is named B and going to the right.\r\n-The ant at index 3 is named C and going to the left.\r\n-The ant at index 4 is named D and going to the left.\r\nNote that the last moment when an ant was on the plank is t = 4 second, after that it falls imediately out of the plank. (i.e. We can say that at t = 4.0000000001, there is no ants on the plank).\r\n
    \r\n\r\n

    Example 2:

    \r\n\"\"\r\n
    \r\nInput: n = 7, left = [], right = [0,1,2,3,4,5,6,7]\r\nOutput: 7\r\nExplanation: All ants are going to the right, the ant at index 0 needs 7 seconds to fall.\r\n
    \r\n\r\n

    Example 3:

    \r\n\"\"\r\n
    \r\nInput: n = 7, left = [0,1,2,3,4,5,6,7], right = []\r\nOutput: 7\r\nExplanation: All ants are going to the left, the ant at index 7 needs 7 seconds to fall.\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: n = 9, left = [5], right = [4]\r\nOutput: 5\r\nExplanation: At t = 1 second, both ants will be at the same intial position but with different direction.\r\n
    \r\n\r\n

    Example 5:

    \r\n\r\n
    \r\nInput: n = 6, left = [6], right = [0]\r\nOutput: 6\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= n <= 10^4
    • \r\n\t
    • 0 <= left.length <= n + 1
    • \r\n\t
    • 0 <= left[i] <= n
    • \r\n\t
    • 0 <= right.length <= n + 1
    • \r\n\t
    • 0 <= right[i] <= n
    • \r\n\t
    • 1 <= left.length + right.length <= n + 1
    • \r\n\t
    • All values of left and right are unique, and each value can appear only in one of the two arrays.
    • \r\n
    ", "content_cn": "

    \u6709\u4e00\u5757\u6728\u677f\uff0c\u957f\u5ea6\u4e3a n \u4e2a \u5355\u4f4d \u3002\u4e00\u4e9b\u8682\u8681\u5728\u6728\u677f\u4e0a\u79fb\u52a8\uff0c\u6bcf\u53ea\u8682\u8681\u90fd\u4ee5 \u6bcf\u79d2\u4e00\u4e2a\u5355\u4f4d \u7684\u901f\u5ea6\u79fb\u52a8\u3002\u5176\u4e2d\uff0c\u4e00\u90e8\u5206\u8682\u8681\u5411 \u5de6 \u79fb\u52a8\uff0c\u5176\u4ed6\u8682\u8681\u5411 \u53f3 \u79fb\u52a8\u3002

    \n\n

    \u5f53\u4e24\u53ea\u5411 \u4e0d\u540c \u65b9\u5411\u79fb\u52a8\u7684\u8682\u8681\u5728\u67d0\u4e2a\u70b9\u76f8\u9047\u65f6\uff0c\u5b83\u4eec\u4f1a\u540c\u65f6\u6539\u53d8\u79fb\u52a8\u65b9\u5411\u5e76\u7ee7\u7eed\u79fb\u52a8\u3002\u5047\u8bbe\u66f4\u6539\u65b9\u5411\u4e0d\u4f1a\u82b1\u8d39\u4efb\u4f55\u989d\u5916\u65f6\u95f4\u3002

    \n\n

    \u800c\u5f53\u8682\u8681\u5728\u67d0\u4e00\u65f6\u523b t \u5230\u8fbe\u6728\u677f\u7684\u4e00\u7aef\u65f6\uff0c\u5b83\u7acb\u5373\u4ece\u6728\u677f\u4e0a\u6389\u4e0b\u6765\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n \u548c\u4e24\u4e2a\u6574\u6570\u6570\u7ec4 left \u4ee5\u53ca right \u3002\u4e24\u4e2a\u6570\u7ec4\u5206\u522b\u6807\u8bc6\u5411\u5de6\u6216\u8005\u5411\u53f3\u79fb\u52a8\u7684\u8682\u8681\u5728 t = 0 \u65f6\u7684\u4f4d\u7f6e\u3002\u8bf7\u4f60\u8fd4\u56de\u6700\u540e\u4e00\u53ea\u8682\u8681\u4ece\u6728\u677f\u4e0a\u6389\u4e0b\u6765\u7684\u65f6\u523b\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

     

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 4, left = [4,3], right = [0,1]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u5982\u4e0a\u56fe\u6240\u793a\uff1a\n-\u4e0b\u6807 0 \u5904\u7684\u8682\u8681\u547d\u540d\u4e3a A \u5e76\u5411\u53f3\u79fb\u52a8\u3002\n-\u4e0b\u6807 1 \u5904\u7684\u8682\u8681\u547d\u540d\u4e3a B \u5e76\u5411\u53f3\u79fb\u52a8\u3002\n-\u4e0b\u6807 3 \u5904\u7684\u8682\u8681\u547d\u540d\u4e3a C \u5e76\u5411\u5de6\u79fb\u52a8\u3002\n-\u4e0b\u6807 4 \u5904\u7684\u8682\u8681\u547d\u540d\u4e3a D \u5e76\u5411\u5de6\u79fb\u52a8\u3002\n\u8bf7\u6ce8\u610f\uff0c\u8682\u8681\u5728\u6728\u677f\u4e0a\u7684\u6700\u540e\u65f6\u523b\u662f t = 4 \u79d2\uff0c\u4e4b\u540e\u8682\u8681\u7acb\u5373\u4ece\u6728\u677f\u4e0a\u6389\u4e0b\u6765\u3002\uff08\u4e5f\u5c31\u662f\u8bf4\u5728 t = 4.0000000001 \u65f6\uff0c\u6728\u677f\u4e0a\u6ca1\u6709\u8682\u8681\uff09\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 7, left = [], right = [0,1,2,3,4,5,6,7]\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\u6240\u6709\u8682\u8681\u90fd\u5411\u53f3\u79fb\u52a8\uff0c\u4e0b\u6807\u4e3a 0 \u7684\u8682\u8681\u9700\u8981 7 \u79d2\u624d\u80fd\u4ece\u6728\u677f\u4e0a\u6389\u843d\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 7, left = [0,1,2,3,4,5,6,7], right = []\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\u6240\u6709\u8682\u8681\u90fd\u5411\u5de6\u79fb\u52a8\uff0c\u4e0b\u6807\u4e3a 7 \u7684\u8682\u8681\u9700\u8981 7 \u79d2\u624d\u80fd\u4ece\u6728\u677f\u4e0a\u6389\u843d\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1an = 9, left = [5], right = [4]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1at = 1 \u79d2\u65f6\uff0c\u4e24\u53ea\u8682\u8681\u5c06\u56de\u5230\u521d\u59cb\u4f4d\u7f6e\uff0c\u4f46\u79fb\u52a8\u65b9\u5411\u4e0e\u4e4b\u524d\u76f8\u53cd\u3002\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1an = 6, left = [6], right = [0]\n\u8f93\u51fa\uff1a6\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 10^4
    • \n\t
    • 0 <= left.length <= n + 1
    • \n\t
    • 0 <= left[i] <= n
    • \n\t
    • 0 <= right.length <= n + 1
    • \n\t
    • 0 <= right[i] <= n
    • \n\t
    • 1 <= left.length + right.length <= n + 1
    • \n\t
    • left \u548c right \u4e2d\u7684\u6240\u6709\u503c\u90fd\u662f\u552f\u4e00\u7684\uff0c\u5e76\u4e14\u6bcf\u4e2a\u503c \u53ea\u80fd\u51fa\u73b0\u5728\u4e8c\u8005\u4e4b\u4e00 \u4e2d\u3002
    • \n
    \n", "tags_en": ["Brainteaser", "Array"], "tags_cn": ["\u8111\u7b4b\u6025\u8f6c\u5f2f", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int getLastMoment(int n, vector& left, vector& right) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int getLastMoment(int n, int[] left, int[] right) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getLastMoment(self, n, left, right):\n \"\"\"\n :type n: int\n :type left: List[int]\n :type right: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getLastMoment(self, n: int, left: List[int], right: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint getLastMoment(int n, int* left, int leftSize, int* right, int rightSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int GetLastMoment(int n, int[] left, int[] right) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[]} left\n * @param {number[]} right\n * @return {number}\n */\nvar getLastMoment = function(n, left, right) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[]} left\n# @param {Integer[]} right\n# @return {Integer}\ndef get_last_moment(n, left, right)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getLastMoment(_ n: Int, _ left: [Int], _ right: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getLastMoment(n int, left []int, right []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getLastMoment(n: Int, left: Array[Int], right: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getLastMoment(n: Int, left: IntArray, right: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_last_moment(n: i32, left: Vec, right: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[] $left\n * @param Integer[] $right\n * @return Integer\n */\n function getLastMoment($n, $left, $right) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getLastMoment(n: number, left: number[], right: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-last-moment n left right)\n (-> exact-integer? (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1503](https://leetcode-cn.com/problems/last-moment-before-all-ants-fall-out-of-a-plank)", "[\u6240\u6709\u8682\u8681\u6389\u4e0b\u6765\u524d\u7684\u6700\u540e\u4e00\u523b](/solution/1500-1599/1503.Last%20Moment%20Before%20All%20Ants%20Fall%20Out%20of%20a%20Plank/README.md)", "`\u8111\u7b4b\u6025\u8f6c\u5f2f`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1503](https://leetcode.com/problems/last-moment-before-all-ants-fall-out-of-a-plank)", "[Last Moment Before All Ants Fall Out of a Plank](/solution/1500-1599/1503.Last%20Moment%20Before%20All%20Ants%20Fall%20Out%20of%20a%20Plank/README_EN.md)", "`Brainteaser`,`Array`", "Medium", ""]}, {"question_id": "1626", "frontend_question_id": "1502", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/can-make-arithmetic-progression-from-sequence", "url_en": "https://leetcode.com/problems/can-make-arithmetic-progression-from-sequence", "relative_path_cn": "/solution/1500-1599/1502.Can%20Make%20Arithmetic%20Progression%20From%20Sequence/README.md", "relative_path_en": "/solution/1500-1599/1502.Can%20Make%20Arithmetic%20Progression%20From%20Sequence/README_EN.md", "title_cn": "\u5224\u65ad\u80fd\u5426\u5f62\u6210\u7b49\u5dee\u6570\u5217", "title_en": "Can Make Arithmetic Progression From Sequence", "question_title_slug": "can-make-arithmetic-progression-from-sequence", "content_en": "

    A sequence of numbers is called an arithmetic progression if the difference between any two consecutive elements is the same.

    \n\n

    Given an array of numbers arr, return true if the array can be rearranged to form an arithmetic progression. Otherwise, return false.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr = [3,5,1]\nOutput: true\nExplanation: We can reorder the elements as [1,3,5] or [5,3,1] with differences 2 and -2 respectively, between each consecutive elements.\n
    \n\n

    Example 2:

    \n\n
    \nInput: arr = [1,2,4]\nOutput: false\nExplanation: There is no way to reorder the elements to obtain an arithmetic progression.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= arr.length <= 1000
    • \n\t
    • -106 <= arr[i] <= 106
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6570\u5b57\u6570\u7ec4 arr \u3002

    \n\n

    \u5982\u679c\u4e00\u4e2a\u6570\u5217\u4e2d\uff0c\u4efb\u610f\u76f8\u90bb\u4e24\u9879\u7684\u5dee\u603b\u7b49\u4e8e\u540c\u4e00\u4e2a\u5e38\u6570\uff0c\u90a3\u4e48\u8fd9\u4e2a\u6570\u5217\u5c31\u79f0\u4e3a \u7b49\u5dee\u6570\u5217 \u3002

    \n\n

    \u5982\u679c\u53ef\u4ee5\u91cd\u65b0\u6392\u5217\u6570\u7ec4\u5f62\u6210\u7b49\u5dee\u6570\u5217\uff0c\u8bf7\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [3,5,1]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u5bf9\u6570\u7ec4\u91cd\u65b0\u6392\u5e8f\u5f97\u5230 [1,3,5] \u6216\u8005 [5,3,1] \uff0c\u4efb\u610f\u76f8\u90bb\u4e24\u9879\u7684\u5dee\u5206\u522b\u4e3a 2 \u6216 -2 \uff0c\u53ef\u4ee5\u5f62\u6210\u7b49\u5dee\u6570\u5217\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [1,2,4]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u65e0\u6cd5\u901a\u8fc7\u91cd\u65b0\u6392\u5e8f\u5f97\u5230\u7b49\u5dee\u6570\u5217\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= arr.length <= 1000
    • \n\t
    • -10^6 <= arr[i] <= 10^6
    • \n
    \n", "tags_en": ["Sort", "Array"], "tags_cn": ["\u6392\u5e8f", "\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canMakeArithmeticProgression(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canMakeArithmeticProgression(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canMakeArithmeticProgression(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canMakeArithmeticProgression(self, arr: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canMakeArithmeticProgression(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanMakeArithmeticProgression(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {boolean}\n */\nvar canMakeArithmeticProgression = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Boolean}\ndef can_make_arithmetic_progression(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canMakeArithmeticProgression(_ arr: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canMakeArithmeticProgression(arr []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canMakeArithmeticProgression(arr: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canMakeArithmeticProgression(arr: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_make_arithmetic_progression(arr: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Boolean\n */\n function canMakeArithmeticProgression($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canMakeArithmeticProgression(arr: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-make-arithmetic-progression arr)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1502](https://leetcode-cn.com/problems/can-make-arithmetic-progression-from-sequence)", "[\u5224\u65ad\u80fd\u5426\u5f62\u6210\u7b49\u5dee\u6570\u5217](/solution/1500-1599/1502.Can%20Make%20Arithmetic%20Progression%20From%20Sequence/README.md)", "`\u6392\u5e8f`,`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1502](https://leetcode.com/problems/can-make-arithmetic-progression-from-sequence)", "[Can Make Arithmetic Progression From Sequence](/solution/1500-1599/1502.Can%20Make%20Arithmetic%20Progression%20From%20Sequence/README_EN.md)", "`Sort`,`Array`", "Easy", ""]}, {"question_id": "1625", "frontend_question_id": "1484", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/group-sold-products-by-the-date", "url_en": "https://leetcode.com/problems/group-sold-products-by-the-date", "relative_path_cn": "/solution/1400-1499/1484.Group%20Sold%20Products%20By%20The%20Date/README.md", "relative_path_en": "/solution/1400-1499/1484.Group%20Sold%20Products%20By%20The%20Date/README_EN.md", "title_cn": "\u6309\u65e5\u671f\u5206\u7ec4\u9500\u552e\u4ea7\u54c1", "title_en": "Group Sold Products By The Date", "question_title_slug": "group-sold-products-by-the-date", "content_en": "

    Table Activities:

    \r\n\r\n
    \r\n+-------------+---------+\r\n| Column Name | Type    |\r\n+-------------+---------+\r\n| sell_date   | date    |\r\n| product     | varchar |\r\n+-------------+---------+\r\nThere is no primary key for this table, it may contains duplicates.\r\nEach row of this table contains the product name and the date it was sold in a market.
    \r\n\r\n

     

    \r\n\r\n

    Write an SQL query to find for each date, the number of distinct products sold and their names.

    \r\n\r\n

    The sold-products names for each date should be sorted lexicographically. 

    \r\n\r\n

    Return the result table ordered by sell_date.

    \r\n\r\n

    The query result format is in the following example.

    \r\n\r\n
    \r\nActivities table:\r\n+------------+-------------+\r\n| sell_date  | product     |\r\n+------------+-------------+\r\n| 2020-05-30 | Headphone   |\r\n| 2020-06-01 | Pencil      |\r\n| 2020-06-02 | Mask        |\r\n| 2020-05-30 | Basketball  |\r\n| 2020-06-01 | Bible       |\r\n| 2020-06-02 | Mask        |\r\n| 2020-05-30 | T-Shirt     |\r\n+------------+-------------+\r\n\r\nResult table:\r\n+------------+----------+------------------------------+\r\n| sell_date  | num_sold | products                     |\r\n+------------+----------+------------------------------+\r\n| 2020-05-30 | 3        | Basketball,Headphone,T-shirt |\r\n| 2020-06-01 | 2        | Bible,Pencil                 |\r\n| 2020-06-02 | 1        | Mask                         |\r\n+------------+----------+------------------------------+\r\nFor 2020-05-30, Sold items were (Headphone, Basketball, T-shirt), we sort them lexicographically and separate them by comma.\r\nFor 2020-06-01, Sold items were (Pencil, Bible), we sort them lexicographically and separate them by comma.\r\nFor 2020-06-02, Sold item is (Masks), we just return it.\r\n\r\n
    ", "content_cn": "

    \u8868 Activities\uff1a

    \n\n
    +-------------+---------+\n| \u5217\u540d         | \u7c7b\u578b    |\n+-------------+---------+\n| sell_date   | date    |\n| product     | varchar |\n+-------------+---------+\n\u6b64\u8868\u6ca1\u6709\u4e3b\u952e\uff0c\u5b83\u53ef\u80fd\u5305\u542b\u91cd\u590d\u9879\u3002\n\u6b64\u8868\u7684\u6bcf\u4e00\u884c\u90fd\u5305\u542b\u4ea7\u54c1\u540d\u79f0\u548c\u5728\u5e02\u573a\u4e0a\u9500\u552e\u7684\u65e5\u671f\u3002\n
    \n\n

     

    \n\n

    \u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\u6765\u67e5\u627e\u6bcf\u4e2a\u65e5\u671f\u3001\u9500\u552e\u7684\u4e0d\u540c\u4ea7\u54c1\u7684\u6570\u91cf\u53ca\u5176\u540d\u79f0\u3002
    \n\u6bcf\u4e2a\u65e5\u671f\u7684\u9500\u552e\u4ea7\u54c1\u540d\u79f0\u5e94\u6309\u8bcd\u5178\u5e8f\u6392\u5217\u3002
    \n\u8fd4\u56de\u6309 sell_date \u6392\u5e8f\u7684\u7ed3\u679c\u8868\u3002

    \n\n


    \n\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a\u3002

    \n\n
    Activities \u8868\uff1a\n+------------+-------------+\n| sell_date  | product     |\n+------------+-------------+\n| 2020-05-30 | Headphone   |\n| 2020-06-01 | Pencil      |\n| 2020-06-02 | Mask        |\n| 2020-05-30 | Basketball  |\n| 2020-06-01 | Bible       |\n| 2020-06-02 | Mask        |\n| 2020-05-30 | T-Shirt     |\n+------------+-------------+\n\nResult \u8868\uff1a\n+------------+----------+------------------------------+\n| sell_date  | num_sold | products                     |\n+------------+----------+------------------------------+\n| 2020-05-30 | 3        | Basketball,Headphone,T-shirt |\n| 2020-06-01 | 2        | Bible,Pencil                 |\n| 2020-06-02 | 1        | Mask                         |\n+------------+----------+------------------------------+\n\u5bf9\u4e8e2020-05-30\uff0c\u51fa\u552e\u7684\u7269\u54c1\u662f (Headphone, Basketball, T-shirt)\uff0c\u6309\u8bcd\u5178\u5e8f\u6392\u5217\uff0c\u5e76\u7528\u9017\u53f7 ',' \u5206\u9694\u3002\n\u5bf9\u4e8e2020-06-01\uff0c\u51fa\u552e\u7684\u7269\u54c1\u662f (Pencil, Bible)\uff0c\u6309\u8bcd\u5178\u5e8f\u6392\u5217\uff0c\u5e76\u7528\u9017\u53f7\u5206\u9694\u3002\n\u5bf9\u4e8e2020-06-02\uff0c\u51fa\u552e\u7684\u7269\u54c1\u662f (Mask)\uff0c\u53ea\u9700\u8fd4\u56de\u8be5\u7269\u54c1\u540d\u3002\n
    \n\n

     

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1484](https://leetcode-cn.com/problems/group-sold-products-by-the-date)", "[\u6309\u65e5\u671f\u5206\u7ec4\u9500\u552e\u4ea7\u54c1](/solution/1400-1499/1484.Group%20Sold%20Products%20By%20The%20Date/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1484](https://leetcode.com/problems/group-sold-products-by-the-date)", "[Group Sold Products By The Date](/solution/1400-1499/1484.Group%20Sold%20Products%20By%20The%20Date/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1624", "frontend_question_id": "1485", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/clone-binary-tree-with-random-pointer", "url_en": "https://leetcode.com/problems/clone-binary-tree-with-random-pointer", "relative_path_cn": "/solution/1400-1499/1485.Clone%20Binary%20Tree%20With%20Random%20Pointer/README.md", "relative_path_en": "/solution/1400-1499/1485.Clone%20Binary%20Tree%20With%20Random%20Pointer/README_EN.md", "title_cn": "\u514b\u9686\u542b\u968f\u673a\u6307\u9488\u7684\u4e8c\u53c9\u6811", "title_en": "Clone Binary Tree With Random Pointer", "question_title_slug": "clone-binary-tree-with-random-pointer", "content_en": "

    A binary tree is given such that each node contains an additional random pointer which could point to any node in the tree or null.

    \n\n

    Return a deep copy of the tree.

    \n\n

    The tree is represented in the same input/output way as normal binary trees where each node is represented as a pair of [val, random_index] where:

    \n\n
      \n\t
    • val: an integer representing Node.val
    • \n\t
    • random_index: the index of the node (in the input) where the random pointer points to, or null if it does not point to any node.
    • \n
    \n\n

    You will be given the tree in class Node and you should return the cloned tree in class NodeCopy.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [[1,null],null,[4,3],[7,0]]\nOutput: [[1,null],null,[4,3],[7,0]]\nExplanation: The original binary tree is [1,null,4,7].\nThe random pointer of node one is null, so it is represented as [1, null].\nThe random pointer of node 4 is node 7, so it is represented as [4, 3] where 3 is the index of node 7 in the tree array.\nThe random pointer of node 7 is node 1, so it is represented as [7, 0] where 0 is the index of node 1 in the tree array\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [[1,4],null,[1,0],null,[1,5],[1,5]]\nOutput: [[1,4],null,[1,0],null,[1,5],[1,5]]\nExplanation: The random pointer of a node can be the node itself.\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: root = [[1,6],[2,5],[3,4],[4,3],[5,2],[6,1],[7,0]]\nOutput: [[1,6],[2,5],[3,4],[4,3],[5,2],[6,1],[7,0]]\n
    \n\n

    Example 4:

    \n\n
    \nInput: root = []\nOutput: []\n
    \n\n

    Example 5:

    \n\n
    \nInput: root = [[1,null],null,[2,null],null,[1,null]]\nOutput: [[1,null],null,[2,null],null,[1,null]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [0, 1000].
    • \n\t
    • Each node's value is between [1, 10^6].
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u4e8c\u53c9\u6811\uff0c\u6811\u4e2d\u6bcf\u4e2a\u8282\u70b9\u90fd\u542b\u6709\u4e00\u4e2a\u9644\u52a0\u7684\u968f\u673a\u6307\u9488\uff0c\u8be5\u6307\u9488\u53ef\u4ee5\u6307\u5411\u6811\u4e2d\u7684\u4efb\u4f55\u8282\u70b9\u6216\u8005\u6307\u5411\u7a7a\uff08null\uff09\u3002

    \n\n

    \u8bf7\u8fd4\u56de\u8be5\u6811\u7684 \u6df1\u62f7\u8d1d \u3002

    \n\n

    \u8be5\u6811\u7684\u8f93\u5165/\u8f93\u51fa\u5f62\u5f0f\u4e0e\u666e\u901a\u4e8c\u53c9\u6811\u76f8\u540c\uff0c\u6bcf\u4e2a\u8282\u70b9\u90fd\u7528 [val, random_index] \u8868\u793a\uff1a

    \n\n
      \n\t
    • val\uff1a\u8868\u793a Node.val \u7684\u6574\u6570
    • \n\t
    • random_index\uff1a\u968f\u673a\u6307\u9488\u6307\u5411\u7684\u8282\u70b9\uff08\u5728\u8f93\u5165\u7684\u6811\u6570\u7ec4\u4e2d\uff09\u7684\u4e0b\u6807\uff1b\u5982\u679c\u672a\u6307\u5411\u4efb\u4f55\u8282\u70b9\uff0c\u5219\u4e3a null \u3002
    • \n
    \n\n

    \u8be5\u6811\u4ee5 Node \u7c7b\u7684\u5f62\u5f0f\u7ed9\u51fa\uff0c\u800c\u4f60\u9700\u8981\u4ee5 NodeCopy \u7c7b\u7684\u5f62\u5f0f\u8fd4\u56de\u514b\u9686\u5f97\u5230\u7684\u6811\u3002NodeCopy \u7c7b\u548cNode \u7c7b\u5b9a\u4e49\u4e00\u81f4\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1aroot = [[1,null],null,[4,3],[7,0]]\n\u8f93\u51fa\uff1a[[1,null],null,[4,3],[7,0]]\n\u89e3\u91ca\uff1a\u521d\u59cb\u4e8c\u53c9\u6811\u4e3a [1,null,4,7] \u3002\n\u8282\u70b9 1 \u7684\u968f\u673a\u6307\u9488\u6307\u5411 null\uff0c\u6240\u4ee5\u8868\u793a\u4e3a [1, null] \u3002\n\u8282\u70b9 4 \u7684\u968f\u673a\u6307\u9488\u6307\u5411 7\uff0c\u6240\u4ee5\u8868\u793a\u4e3a [4, 3] \u5176\u4e2d 3 \u662f\u6811\u6570\u7ec4\u4e2d\u8282\u70b9 7 \u5bf9\u5e94\u7684\u4e0b\u6807\u3002\n\u8282\u70b9 7 \u7684\u968f\u673a\u6307\u9488\u6307\u5411 1\uff0c\u6240\u4ee5\u8868\u793a\u4e3a [7, 0] \u5176\u4e2d 0 \u662f\u6811\u6570\u7ec4\u4e2d\u8282\u70b9 1 \u5bf9\u5e94\u7684\u4e0b\u6807\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1aroot = [[1,4],null,[1,0],null,[1,5],[1,5]]\n\u8f93\u51fa\uff1a[[1,4],null,[1,0],null,[1,5],[1,5]]\n\u89e3\u91ca\uff1a\u8282\u70b9\u7684\u968f\u673a\u6307\u9488\u53ef\u4ee5\u6307\u5411\u5b83\u81ea\u8eab\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1aroot = [[1,6],[2,5],[3,4],[4,3],[5,2],[6,1],[7,0]]\n\u8f93\u51fa\uff1a[[1,6],[2,5],[3,4],[4,3],[5,2],[6,1],[7,0]]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1aroot = []\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1aroot = [[1,null],null,[2,null],null,[1,null]]\n\u8f93\u51fa\uff1a[[1,null],null,[2,null],null,[1,null]]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • tree \u4e2d\u8282\u70b9\u6570\u76ee\u8303\u56f4\u662f [0, 1000]
    • \n\t
    • \u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u7684\u8303\u56f4\u662f [1, 10^6]
    • \n
    \n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for a binary tree node.\n * struct Node {\n * int val;\n * Node *left;\n * Node *right;\n * Node *random;\n * Node() : val(0), left(nullptr), right(nullptr), random(nullptr) {}\n * Node(int x) : val(x), left(nullptr), right(nullptr), random(nullptr) {}\n * Node(int x, Node *left, Node *right, Node *random) : val(x), left(left), right(right), random(random) {}\n * };\n */\nclass Solution {\npublic:\n NodeCopy* copyRandomBinaryTree(Node* root) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class Node {\n * int val;\n * Node left;\n * Node right;\n * Node random;\n * Node() {}\n * Node(int val) { this.val = val; }\n * Node(int val, Node left, Node right, Node random) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * this.random = random;\n * }\n * }\n */\nclass Solution {\n public NodeCopy copyRandomBinaryTree(Node root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class Node(object):\n# def __init__(self, val=0, left=None, right=None, random=None):\n# self.val = val\n# self.left = left\n# self.right = right\n# self.random = random\nclass Solution(object):\n def copyRandomBinaryTree(self, root):\n \"\"\"\n :type root: Node\n :rtype: NodeCopy\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class Node:\n# def __init__(self, val=0, left=None, right=None, random=None):\n# self.val = val\n# self.left = left\n# self.right = right\n# self.random = random\nclass Solution:\n def copyRandomBinaryTree(self, root: 'Node') -> 'NodeCopy':\n ", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class Node {\n * public int val;\n * public Node left;\n * public Node right;\n * public Node random;\n * public Node(int val=0, Node left=null, Node right=null, Node random=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * this.random = random;\n * }\n * }\n */\npublic class Solution {\n public TreeNode CopyRandomBinaryTree(TreeNode root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // Definition for a Node.\n * function Node(val, left, right, random) {\n * this.val = val === undefined ? null : val;\n * this.left = left === undefined ? null : left;\n * this.right = right === undefined ? null : right;\n * this.random = next === undefined ? null : random;\n * };\n */\n\n/**\n * @param {Node} root\n * @return {NodeCopy}\n */\nvar copyRandomBinaryTree = function(root) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class Node\n# attr_accessor :val, :left, :right, :random\n# def initialize(val = 0, left = nil, right = nil, random = nil)\n# @val = val\n# @left = left\n# @right = right\n# @random = random\n# end\n# end\n# @param {Node} root\n# @return {NodeCopy}\ndef copy_random_binary_tree(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a Node.\n * public class Node {\n * public var val: Int\n * public var left: Node?\n * public var right: Node?\n *\t public var random: Node?\n * public init(_ val: Int) {\n * self.val = val\n * self.left = nil\n * self.right = nil\n * self.random = nil\n * }\n * }\n */\n\nclass Solution {\n func copyRandomBinaryTree(_ root: Node?) -> NodeCopy? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a Node.\n * type Node struct {\n * Val int\n * Left *Node\n * Right *Node\n * Random *Node\n * }\n */\n\nfunc copyRandomBinaryTree(root *Node) *NodeCopy {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a Node.\n * class Node(var _value: Int) {\n * var value: Int = _value\n * var left: Node = null\n * var right: Node = null\n * var random: Node = null\n * }\n */\n\nobject Solution {\n def copyRandomBinaryTree(root: Node): NodeCopy = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a Node.\n * class Node(var `val`: Int) {\n * var left: Node? = null\n * var right: Node? = null\n * var random: Node? = null\n * }\n */\n\nclass Solution {\n fun copyRandomBinaryTree(root: Node?): NodeCopy? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a Node.\n * class Node {\n * function __construct($val = 0) {\n * $this->val = $val;\n * $this->left = null;\n * $this->right = null;\n * $this->random = null;\n * }\n * }\n */\n\nclass Solution {\n /**\n * @param Node $root\n * @return NodeCopy\n */\n public function copyRandomBinaryTree($root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class Node {\n * val: number\n * left: Node | null\n * right: Node | null\n * random: Node | null\n * constructor(val?: number, left?: Node | null, right?: Node | null, random?: Node | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * this.random = (random===undefined ? null : random)\n * }\n * }\n */\n\nfunction copyRandomBinaryTree(root: Node | null): NodeCopy {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1485](https://leetcode-cn.com/problems/clone-binary-tree-with-random-pointer)", "[\u514b\u9686\u542b\u968f\u673a\u6307\u9488\u7684\u4e8c\u53c9\u6811](/solution/1400-1499/1485.Clone%20Binary%20Tree%20With%20Random%20Pointer/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1485](https://leetcode.com/problems/clone-binary-tree-with-random-pointer)", "[Clone Binary Tree With Random Pointer](/solution/1400-1499/1485.Clone%20Binary%20Tree%20With%20Random%20Pointer/README_EN.md)", "`Tree`,`Depth-first Search`", "Medium", "\ud83d\udd12"]}, {"question_id": "1623", "frontend_question_id": "1479", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/sales-by-day-of-the-week", "url_en": "https://leetcode.com/problems/sales-by-day-of-the-week", "relative_path_cn": "/solution/1400-1499/1479.Sales%20by%20Day%20of%20the%20Week/README.md", "relative_path_en": "/solution/1400-1499/1479.Sales%20by%20Day%20of%20the%20Week/README_EN.md", "title_cn": "\u5468\u5185\u6bcf\u5929\u7684\u9500\u552e\u60c5\u51b5", "title_en": "Sales by Day of the Week", "question_title_slug": "sales-by-day-of-the-week", "content_en": "

    Table: Orders

    \r\n\r\n
    \r\n+---------------+---------+\r\n| Column Name   | Type    |\r\n+---------------+---------+\r\n| order_id      | int     |\r\n| customer_id   | int     |\r\n| order_date    | date    | \r\n| item_id       | varchar |\r\n| quantity      | int     |\r\n+---------------+---------+\r\n(ordered_id, item_id) is the primary key for this table.\r\nThis table contains information of the orders placed.\r\norder_date is the date when item_id was ordered by the customer with id customer_id.\r\n
    \r\n\r\n

     

    \r\n\r\n

    Table: Items

    \r\n\r\n
    \r\n+---------------------+---------+\r\n| Column Name         | Type    |\r\n+---------------------+---------+\r\n| item_id             | varchar |\r\n| item_name           | varchar |\r\n| item_category       | varchar |\r\n+---------------------+---------+\r\nitem_id is the primary key for this table.\r\nitem_name is the name of the item.\r\nitem_category is the category of the item.\r\n
    \r\n\r\n

     

    \r\n\r\n

    You are the business owner and would like to obtain a sales report for category items and day of the week.

    \r\n\r\n

    Write an SQL query to report how many units in each category have been ordered on each day of the week.

    \r\n\r\n

    Return the result table ordered by category.

    \r\n\r\n

    The query result format is in the following example:

    \r\n\r\n

     

    \r\n\r\n
    \r\nOrders table:\r\n+------------+--------------+-------------+--------------+-------------+\r\n| order_id   | customer_id  | order_date  | item_id      | quantity    |\r\n+------------+--------------+-------------+--------------+-------------+\r\n| 1          | 1            | 2020-06-01  | 1            | 10          |\r\n| 2          | 1            | 2020-06-08  | 2            | 10          |\r\n| 3          | 2            | 2020-06-02  | 1            | 5           |\r\n| 4          | 3            | 2020-06-03  | 3            | 5           |\r\n| 5          | 4            | 2020-06-04  | 4            | 1           |\r\n| 6          | 4            | 2020-06-05  | 5            | 5           |\r\n| 7          | 5            | 2020-06-05  | 1            | 10          |\r\n| 8          | 5            | 2020-06-14  | 4            | 5           |\r\n| 9          | 5            | 2020-06-21  | 3            | 5           |\r\n+------------+--------------+-------------+--------------+-------------+\r\n\r\nItems table:\r\n+------------+----------------+---------------+\r\n| item_id    | item_name      | item_category |\r\n+------------+----------------+---------------+\r\n| 1          | LC Alg. Book   | Book          |\r\n| 2          | LC DB. Book    | Book          |\r\n| 3          | LC SmarthPhone | Phone         |\r\n| 4          | LC Phone 2020  | Phone         |\r\n| 5          | LC SmartGlass  | Glasses       |\r\n| 6          | LC T-Shirt XL  | T-Shirt       |\r\n+------------+----------------+---------------+\r\n\r\nResult table:\r\n+------------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+\r\n| Category   | Monday    | Tuesday   | Wednesday | Thursday  | Friday    | Saturday  | Sunday    |\r\n+------------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+\r\n| Book       | 20        | 5         | 0         | 0         | 10        | 0         | 0         |\r\n| Glasses    | 0         | 0         | 0         | 0         | 5         | 0         | 0         |\r\n| Phone      | 0         | 0         | 5         | 1         | 0         | 0         | 10        |\r\n| T-Shirt    | 0         | 0         | 0         | 0         | 0         | 0         | 0         |\r\n+------------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+\r\nOn Monday (2020-06-01, 2020-06-08) were sold a total of 20 units (10 + 10) in the category Book (ids: 1, 2).\r\nOn Tuesday (2020-06-02) were sold a total of 5 units  in the category Book (ids: 1, 2).\r\nOn Wednesday (2020-06-03) were sold a total of 5 units in the category Phone (ids: 3, 4).\r\nOn Thursday (2020-06-04) were sold a total of 1 unit in the category Phone (ids: 3, 4).\r\nOn Friday (2020-06-05) were sold 10 units in the category Book (ids: 1, 2) and 5 units in Glasses (ids: 5).\r\nOn Saturday there are no items sold.\r\nOn Sunday (2020-06-14, 2020-06-21) were sold a total of 10 units (5 +5) in the category Phone (ids: 3, 4).\r\nThere are no sales of T-Shirt.\r\n
    ", "content_cn": "

    \u8868\uff1aOrders

    \n\n
    +---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| order_id      | int     |\n| customer_id   | int     |\n| order_date    | date    | \n| item_id       | varchar |\n| quantity      | int     |\n+---------------+---------+\n(order_id, item_id) \u662f\u8be5\u8868\u4e3b\u952e\n\u8be5\u8868\u5305\u542b\u4e86\u8ba2\u5355\u4fe1\u606f\norder_date \u662fid\u4e3a item_id \u7684\u5546\u54c1\u88abid\u4e3a customer_id \u7684\u6d88\u8d39\u8005\u8ba2\u8d2d\u7684\u65e5\u671f.
    \n\n

    \u8868\uff1aItems

    \n\n
    +---------------------+---------+\n| Column Name         | Type    |\n+---------------------+---------+\n| item_id             | varchar |\n| item_name           | varchar |\n| item_category       | varchar |\n+---------------------+---------+\nitem_id \u662f\u8be5\u8868\u4e3b\u952e\nitem_name \u662f\u5546\u54c1\u7684\u540d\u5b57\nitem_category \u662f\u5546\u54c1\u7684\u7c7b\u522b\n
    \n\n

     

    \n\n

    \u4f60\u662f\u4f01\u4e1a\u4e3b\uff0c\u60f3\u8981\u83b7\u5f97\u5206\u7c7b\u5546\u54c1\u548c\u5468\u5185\u6bcf\u5929\u7684\u9500\u552e\u62a5\u544a\u3002

    \n\n

    \u5199\u4e00\u4e2aSQL\u8bed\u53e5\uff0c\u62a5\u544a \u5468\u5185\u6bcf\u5929 \u6bcf\u4e2a\u5546\u54c1\u7c7b\u522b\u4e0b\u8ba2\u8d2d\u4e86\u591a\u5c11\u5355\u4f4d\u3002

    \n\n

    \u8fd4\u56de\u7ed3\u679c\u8868\u5355 \u6309\u5546\u54c1\u7c7b\u522b\u6392\u5e8f \u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a\uff1a

    \n\n

     

    \n\n
    Orders \u8868\uff1a\n+------------+--------------+-------------+--------------+-------------+\n| order_id   | customer_id  | order_date  | item_id      | quantity    |\n+------------+--------------+-------------+--------------+-------------+\n| 1          | 1            | 2020-06-01  | 1            | 10          |\n| 2          | 1            | 2020-06-08  | 2            | 10          |\n| 3          | 2            | 2020-06-02  | 1            | 5           |\n| 4          | 3            | 2020-06-03  | 3            | 5           |\n| 5          | 4            | 2020-06-04  | 4            | 1           |\n| 6          | 4            | 2020-06-05  | 5            | 5           |\n| 7          | 5            | 2020-06-05  | 1            | 10          |\n| 8          | 5            | 2020-06-14  | 4            | 5           |\n| 9          | 5            | 2020-06-21  | 3            | 5           |\n+------------+--------------+-------------+--------------+-------------+\n\nItems \u8868\uff1a\n+------------+----------------+---------------+\n| item_id    | item_name      | item_category |\n+------------+----------------+---------------+\n| 1          | LC Alg. Book   | Book          |\n| 2          | LC DB. Book    | Book          |\n| 3          | LC SmarthPhone | Phone         |\n| 4          | LC Phone 2020  | Phone         |\n| 5          | LC SmartGlass  | Glasses       |\n| 6          | LC T-Shirt XL  | T-Shirt       |\n+------------+----------------+---------------+\n\nResult \u8868\uff1a\n+------------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+\n| Category   | Monday    | Tuesday   | Wednesday | Thursday  | Friday    | Saturday  | Sunday    |\n+------------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+\n| Book       | 20        | 5         | 0         | 0         | 10        | 0         | 0         |\n| Glasses    | 0         | 0         | 0         | 0         | 5         | 0         | 0         |\n| Phone      | 0         | 0         | 5         | 1         | 0         | 0         | 10        |\n| T-Shirt    | 0         | 0         | 0         | 0         | 0         | 0         | 0         |\n+------------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+\n\u5728\u5468\u4e00(2020-06-01, 2020-06-08)\uff0cBook\u5206\u7c7b(ids: 1, 2)\u4e0b\uff0c\u603b\u5171\u9500\u552e\u4e8620\u4e2a\u5355\u4f4d(10 + 10)\n\u5728\u5468\u4e8c(2020-06-02)\uff0cBook\u5206\u7c7b(ids: 1, 2)\u4e0b\uff0c\u603b\u5171\u9500\u552e\u4e865\u4e2a\u5355\u4f4d\n\u5728\u5468\u4e09(2020-06-03)\uff0cPhone\u5206\u7c7b(ids: 3, 4)\u4e0b\uff0c\u603b\u5171\u9500\u552e\u4e865\u4e2a\u5355\u4f4d\n\u5728\u5468\u56db(2020-06-04)\uff0cPhone\u5206\u7c7b(ids: 3, 4)\u4e0b\uff0c\u603b\u5171\u9500\u552e\u4e861\u4e2a\u5355\u4f4d\n\u5728\u5468\u4e94(2020-06-05)\uff0cBook\u5206\u7c7b(ids: 1, 2)\u4e0b\uff0c\u603b\u5171\u9500\u552e\u4e8610\u4e2a\u5355\u4f4d\uff0cGlasses\u5206\u7c7b(ids: 5)\u4e0b\uff0c\u603b\u5171\u9500\u552e\u4e865\u4e2a\u5355\u4f4d\n\u5728\u5468\u516d, \u6ca1\u6709\u5546\u54c1\u9500\u552e\n\u5728\u5468\u5929(2020-06-14, 2020-06-21)\uff0cPhone\u5206\u7c7b(ids: 3, 4)\u4e0b\uff0c\u603b\u5171\u9500\u552e\u4e8610\u4e2a\u5355\u4f4d(5 + 5)\n\u6ca1\u6709\u9500\u552e T-Shirt \u7c7b\u522b\u7684\u5546\u54c1\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1479](https://leetcode-cn.com/problems/sales-by-day-of-the-week)", "[\u5468\u5185\u6bcf\u5929\u7684\u9500\u552e\u60c5\u51b5](/solution/1400-1499/1479.Sales%20by%20Day%20of%20the%20Week/README.md)", "", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1479](https://leetcode.com/problems/sales-by-day-of-the-week)", "[Sales by Day of the Week](/solution/1400-1499/1479.Sales%20by%20Day%20of%20the%20Week/README_EN.md)", "", "Hard", "\ud83d\udd12"]}, {"question_id": "1622", "frontend_question_id": "1499", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/max-value-of-equation", "url_en": "https://leetcode.com/problems/max-value-of-equation", "relative_path_cn": "/solution/1400-1499/1499.Max%20Value%20of%20Equation/README.md", "relative_path_en": "/solution/1400-1499/1499.Max%20Value%20of%20Equation/README_EN.md", "title_cn": "\u6ee1\u8db3\u4e0d\u7b49\u5f0f\u7684\u6700\u5927\u503c", "title_en": "Max Value of Equation", "question_title_slug": "max-value-of-equation", "content_en": "

    You are given an array points containing the coordinates of points on a 2D plane, sorted by the x-values, where points[i] = [xi, yi] such that xi < xj for all 1 <= i < j <= points.length. You are also given an integer k.

    \n\n

    Return the maximum value of the equation yi + yj + |xi - xj| where |xi - xj| <= k and 1 <= i < j <= points.length.

    \n\n

    It is guaranteed that there exists at least one pair of points that satisfy the constraint |xi - xj| <= k.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: points = [[1,3],[2,0],[5,10],[6,-10]], k = 1\nOutput: 4\nExplanation: The first two points satisfy the condition |xi - xj| <= 1 and if we calculate the equation we get 3 + 0 + |1 - 2| = 4. Third and fourth points also satisfy the condition and give a value of 10 + -10 + |5 - 6| = 1.\nNo other pairs satisfy the condition, so we return the max of 4 and 1.\n
    \n\n

    Example 2:

    \n\n
    \nInput: points = [[0,0],[3,0],[9,2]], k = 3\nOutput: 3\nExplanation: Only the first two points have an absolute difference of 3 or less in the x-values, and give the value of 0 + 0 + |0 - 3| = 3.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= points.length <= 105
    • \n\t
    • points[i].length == 2
    • \n\t
    • -108 <= xi, yi <= 108
    • \n\t
    • 0 <= k <= 2 * 108
    • \n\t
    • xi < xj for all 1 <= i < j <= points.length
    • \n\t
    • xi form a strictly increasing sequence.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 points \u548c\u4e00\u4e2a\u6574\u6570 k \u3002\u6570\u7ec4\u4e2d\u6bcf\u4e2a\u5143\u7d20\u90fd\u8868\u793a\u4e8c\u7ef4\u5e73\u9762\u4e0a\u7684\u70b9\u7684\u5750\u6807\uff0c\u5e76\u6309\u7167\u6a2a\u5750\u6807 x \u7684\u503c\u4ece\u5c0f\u5230\u5927\u6392\u5e8f\u3002\u4e5f\u5c31\u662f\u8bf4 points[i] = [xi, yi] \uff0c\u5e76\u4e14\u5728 1 <= i < j <= points.length \u7684\u524d\u63d0\u4e0b\uff0c xi < xj \u603b\u6210\u7acb\u3002

    \n\n

    \u8bf7\u4f60\u627e\u51fa yi + yj + |xi - xj| \u7684 \u6700\u5927\u503c\uff0c\u5176\u4e2d |xi - xj| <= k \u4e14 1 <= i < j <= points.length\u3002

    \n\n

    \u9898\u76ee\u6d4b\u8bd5\u6570\u636e\u4fdd\u8bc1\u81f3\u5c11\u5b58\u5728\u4e00\u5bf9\u80fd\u591f\u6ee1\u8db3 |xi - xj| <= k \u7684\u70b9\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1apoints = [[1,3],[2,0],[5,10],[6,-10]], k = 1\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u524d\u4e24\u4e2a\u70b9\u6ee1\u8db3 |xi - xj| <= 1 \uff0c\u4ee3\u5165\u65b9\u7a0b\u8ba1\u7b97\uff0c\u5219\u5f97\u5230\u503c 3 + 0 + |1 - 2| = 4 \u3002\u7b2c\u4e09\u4e2a\u548c\u7b2c\u56db\u4e2a\u70b9\u4e5f\u6ee1\u8db3\u6761\u4ef6\uff0c\u5f97\u5230\u503c 10 + -10 + |5 - 6| = 1 \u3002\n\u6ca1\u6709\u5176\u4ed6\u6ee1\u8db3\u6761\u4ef6\u7684\u70b9\uff0c\u6240\u4ee5\u8fd4\u56de 4 \u548c 1 \u4e2d\u6700\u5927\u7684\u90a3\u4e2a\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1apoints = [[0,0],[3,0],[9,2]], k = 3\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u53ea\u6709\u524d\u4e24\u4e2a\u70b9\u6ee1\u8db3 |xi - xj| <= 3 \uff0c\u4ee3\u5165\u65b9\u7a0b\u540e\u5f97\u5230\u503c 0 + 0 + |0 - 3| = 3 \u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= points.length <= 10^5
    • \n\t
    • points[i].length == 2
    • \n\t
    • -10^8 <= points[i][0], points[i][1] <= 10^8
    • \n\t
    • 0 <= k <= 2 * 10^8
    • \n\t
    • \u5bf9\u4e8e\u6240\u6709\u76841 <= i < j <= points.length \uff0cpoints[i][0] < points[j][0] \u90fd\u6210\u7acb\u3002\u4e5f\u5c31\u662f\u8bf4\uff0cxi \u662f\u4e25\u683c\u9012\u589e\u7684\u3002
    • \n
    \n", "tags_en": ["Array", "Sliding Window"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findMaxValueOfEquation(vector>& points, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findMaxValueOfEquation(int[][] points, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findMaxValueOfEquation(self, points, k):\n \"\"\"\n :type points: List[List[int]]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findMaxValueOfEquation(self, points: List[List[int]], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findMaxValueOfEquation(int** points, int pointsSize, int* pointsColSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindMaxValueOfEquation(int[][] points, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} points\n * @param {number} k\n * @return {number}\n */\nvar findMaxValueOfEquation = function(points, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} points\n# @param {Integer} k\n# @return {Integer}\ndef find_max_value_of_equation(points, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findMaxValueOfEquation(_ points: [[Int]], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findMaxValueOfEquation(points [][]int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findMaxValueOfEquation(points: Array[Array[Int]], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findMaxValueOfEquation(points: Array, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_max_value_of_equation(points: Vec>, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $points\n * @param Integer $k\n * @return Integer\n */\n function findMaxValueOfEquation($points, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findMaxValueOfEquation(points: number[][], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-max-value-of-equation points k)\n (-> (listof (listof exact-integer?)) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1499](https://leetcode-cn.com/problems/max-value-of-equation)", "[\u6ee1\u8db3\u4e0d\u7b49\u5f0f\u7684\u6700\u5927\u503c](/solution/1400-1499/1499.Max%20Value%20of%20Equation/README.md)", "`\u6570\u7ec4`", "\u56f0\u96be", ""], "md_table_row_en": ["[1499](https://leetcode.com/problems/max-value-of-equation)", "[Max Value of Equation](/solution/1400-1499/1499.Max%20Value%20of%20Equation/README_EN.md)", "`Array`,`Sliding Window`", "Hard", ""]}, {"question_id": "1621", "frontend_question_id": "1498", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-subsequences-that-satisfy-the-given-sum-condition", "url_en": "https://leetcode.com/problems/number-of-subsequences-that-satisfy-the-given-sum-condition", "relative_path_cn": "/solution/1400-1499/1498.Number%20of%20Subsequences%20That%20Satisfy%20the%20Given%20Sum%20Condition/README.md", "relative_path_en": "/solution/1400-1499/1498.Number%20of%20Subsequences%20That%20Satisfy%20the%20Given%20Sum%20Condition/README_EN.md", "title_cn": "\u6ee1\u8db3\u6761\u4ef6\u7684\u5b50\u5e8f\u5217\u6570\u76ee", "title_en": "Number of Subsequences That Satisfy the Given Sum Condition", "question_title_slug": "number-of-subsequences-that-satisfy-the-given-sum-condition", "content_en": "

    Given an array of integers nums and an integer target.

    \n\n

    Return the number of non-empty subsequences of nums such that the sum of the minimum and maximum element on it is less or equal to target. Since the answer may be too large, return it modulo 109 + 7.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [3,5,6,7], target = 9\nOutput: 4\nExplanation: There are 4 subsequences that satisfy the condition.\n[3] -> Min value + max value <= target (3 + 3 <= 9)\n[3,5] -> (3 + 5 <= 9)\n[3,5,6] -> (3 + 6 <= 9)\n[3,6] -> (3 + 6 <= 9)\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [3,3,6,8], target = 10\nOutput: 6\nExplanation: There are 6 subsequences that satisfy the condition. (nums can have repeated numbers).\n[3] , [3] , [3,3], [3,6] , [3,6] , [3,3,6]
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [2,3,3,4,6,7], target = 12\nOutput: 61\nExplanation: There are 63 non-empty subsequences, two of them don't satisfy the condition ([6,7], [7]).\nNumber of valid subsequences (63 - 2 = 61).\n
    \n\n

    Example 4:

    \n\n
    \nInput: nums = [5,2,4,1,7,6,8], target = 16\nOutput: 127\nExplanation: All non-empty subset satisfy the condition (2^7 - 1) = 127
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • 1 <= nums[i] <= 106
    • \n\t
    • 1 <= target <= 106
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \u548c\u4e00\u4e2a\u6574\u6570 target \u3002

    \n\n

    \u8bf7\u4f60\u7edf\u8ba1\u5e76\u8fd4\u56de nums \u4e2d\u80fd\u6ee1\u8db3\u5176\u6700\u5c0f\u5143\u7d20\u4e0e\u6700\u5927\u5143\u7d20\u7684 \u548c \u5c0f\u4e8e\u6216\u7b49\u4e8e target \u7684 \u975e\u7a7a \u5b50\u5e8f\u5217\u7684\u6570\u76ee\u3002

    \n\n

    \u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u5f88\u5927\uff0c\u8bf7\u5c06\u7ed3\u679c\u5bf9 10^9 + 7 \u53d6\u4f59\u540e\u8fd4\u56de\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [3,5,6,7], target = 9\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u6709 4 \u4e2a\u5b50\u5e8f\u5217\u6ee1\u8db3\u8be5\u6761\u4ef6\u3002\n[3] -> \u6700\u5c0f\u5143\u7d20 + \u6700\u5927\u5143\u7d20 <= target (3 + 3 <= 9)\n[3,5] -> (3 + 5 <= 9)\n[3,5,6] -> (3 + 6 <= 9)\n[3,6] -> (3 + 6 <= 9)\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [3,3,6,8], target = 10\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u6709 6 \u4e2a\u5b50\u5e8f\u5217\u6ee1\u8db3\u8be5\u6761\u4ef6\u3002\uff08nums \u4e2d\u53ef\u4ee5\u6709\u91cd\u590d\u6570\u5b57\uff09\n[3] , [3] , [3,3], [3,6] , [3,6] , [3,3,6]
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [2,3,3,4,6,7], target = 12\n\u8f93\u51fa\uff1a61\n\u89e3\u91ca\uff1a\u5171\u6709 63 \u4e2a\u975e\u7a7a\u5b50\u5e8f\u5217\uff0c\u5176\u4e2d 2 \u4e2a\u4e0d\u6ee1\u8db3\u6761\u4ef6\uff08[6,7], [7]\uff09\n\u6709\u6548\u5e8f\u5217\u603b\u6570\u4e3a\uff0863 - 2 = 61\uff09\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [5,2,4,1,7,6,8], target = 16\n\u8f93\u51fa\uff1a127\n\u89e3\u91ca\uff1a\u6240\u6709\u975e\u7a7a\u5b50\u5e8f\u5217\u90fd\u6ee1\u8db3\u6761\u4ef6 (2^7 - 1) = 127
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 10^5
    • \n\t
    • 1 <= nums[i] <= 10^6
    • \n\t
    • 1 <= target <= 10^6
    • \n
    \n", "tags_en": ["Sort", "Sliding Window"], "tags_cn": ["\u6392\u5e8f"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numSubseq(vector& nums, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numSubseq(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numSubseq(self, nums, target):\n \"\"\"\n :type nums: List[int]\n :type target: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numSubseq(self, nums: List[int], target: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numSubseq(int* nums, int numsSize, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumSubseq(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} target\n * @return {number}\n */\nvar numSubseq = function(nums, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} target\n# @return {Integer}\ndef num_subseq(nums, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numSubseq(_ nums: [Int], _ target: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numSubseq(nums []int, target int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numSubseq(nums: Array[Int], target: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numSubseq(nums: IntArray, target: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_subseq(nums: Vec, target: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $target\n * @return Integer\n */\n function numSubseq($nums, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numSubseq(nums: number[], target: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-subseq nums target)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1498](https://leetcode-cn.com/problems/number-of-subsequences-that-satisfy-the-given-sum-condition)", "[\u6ee1\u8db3\u6761\u4ef6\u7684\u5b50\u5e8f\u5217\u6570\u76ee](/solution/1400-1499/1498.Number%20of%20Subsequences%20That%20Satisfy%20the%20Given%20Sum%20Condition/README.md)", "`\u6392\u5e8f`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1498](https://leetcode.com/problems/number-of-subsequences-that-satisfy-the-given-sum-condition)", "[Number of Subsequences That Satisfy the Given Sum Condition](/solution/1400-1499/1498.Number%20of%20Subsequences%20That%20Satisfy%20the%20Given%20Sum%20Condition/README_EN.md)", "`Sort`,`Sliding Window`", "Medium", ""]}, {"question_id": "1620", "frontend_question_id": "1497", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/check-if-array-pairs-are-divisible-by-k", "url_en": "https://leetcode.com/problems/check-if-array-pairs-are-divisible-by-k", "relative_path_cn": "/solution/1400-1499/1497.Check%20If%20Array%20Pairs%20Are%20Divisible%20by%20k/README.md", "relative_path_en": "/solution/1400-1499/1497.Check%20If%20Array%20Pairs%20Are%20Divisible%20by%20k/README_EN.md", "title_cn": "\u68c0\u67e5\u6570\u7ec4\u5bf9\u662f\u5426\u53ef\u4ee5\u88ab k \u6574\u9664", "title_en": "Check If Array Pairs Are Divisible by k", "question_title_slug": "check-if-array-pairs-are-divisible-by-k", "content_en": "

    Given an array of integers arr of even length n and an integer k.

    \n\n

    We want to divide the array into exactly n / 2 pairs such that the sum of each pair is divisible by k.

    \n\n

    Return True If you can find a way to do that or False otherwise.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr = [1,2,3,4,5,10,6,7,8,9], k = 5\nOutput: true\nExplanation: Pairs are (1,9),(2,8),(3,7),(4,6) and (5,10).\n
    \n\n

    Example 2:

    \n\n
    \nInput: arr = [1,2,3,4,5,6], k = 7\nOutput: true\nExplanation: Pairs are (1,6),(2,5) and(3,4).\n
    \n\n

    Example 3:

    \n\n
    \nInput: arr = [1,2,3,4,5,6], k = 10\nOutput: false\nExplanation: You can try all possible pairs to see that there is no way to divide arr into 3 pairs each with sum divisible by 10.\n
    \n\n

    Example 4:

    \n\n
    \nInput: arr = [-10,10], k = 2\nOutput: true\n
    \n\n

    Example 5:

    \n\n
    \nInput: arr = [-1,1,-2,2,-3,3,-4,4], k = 3\nOutput: true\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • arr.length == n
    • \n\t
    • 1 <= n <= 105
    • \n\t
    • n is even.
    • \n\t
    • -109 <= arr[i] <= 109
    • \n\t
    • 1 <= k <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr \u548c\u4e00\u4e2a\u6574\u6570 k \uff0c\u5176\u4e2d\u6570\u7ec4\u957f\u5ea6\u662f\u5076\u6570\uff0c\u503c\u4e3a n \u3002

    \n\n

    \u73b0\u5728\u9700\u8981\u628a\u6570\u7ec4\u6070\u597d\u5206\u6210 n / 2 \u5bf9\uff0c\u4ee5\u4f7f\u6bcf\u5bf9\u6570\u5b57\u7684\u548c\u90fd\u80fd\u591f\u88ab k \u6574\u9664\u3002

    \n\n

    \u5982\u679c\u5b58\u5728\u8fd9\u6837\u7684\u5206\u6cd5\uff0c\u8bf7\u8fd4\u56de True \uff1b\u5426\u5219\uff0c\u8fd4\u56de False \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [1,2,3,4,5,10,6,7,8,9], k = 5\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u5212\u5206\u540e\u7684\u6570\u5b57\u5bf9\u4e3a (1,9),(2,8),(3,7),(4,6) \u4ee5\u53ca (5,10) \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [1,2,3,4,5,6], k = 7\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u5212\u5206\u540e\u7684\u6570\u5b57\u5bf9\u4e3a (1,6),(2,5) \u4ee5\u53ca (3,4) \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [1,2,3,4,5,6], k = 10\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u65e0\u6cd5\u5728\u5c06\u6570\u7ec4\u4e2d\u7684\u6570\u5b57\u5206\u4e3a\u4e09\u5bf9\u7684\u540c\u65f6\u6ee1\u8db3\u6bcf\u5bf9\u6570\u5b57\u548c\u80fd\u591f\u88ab 10 \u6574\u9664\u7684\u6761\u4ef6\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [-10,10], k = 2\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [-1,1,-2,2,-3,3,-4,4], k = 3\n\u8f93\u51fa\uff1atrue\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • arr.length == n
    • \n\t
    • 1 <= n <= 10^5
    • \n\t
    • n \u4e3a\u5076\u6570
    • \n\t
    • -10^9 <= arr[i] <= 10^9
    • \n\t
    • 1 <= k <= 10^5
    • \n
    \n", "tags_en": ["Greedy", "Array", "Math"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u7ec4", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canArrange(vector& arr, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canArrange(int[] arr, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canArrange(self, arr, k):\n \"\"\"\n :type arr: List[int]\n :type k: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canArrange(self, arr: List[int], k: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canArrange(int* arr, int arrSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanArrange(int[] arr, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @param {number} k\n * @return {boolean}\n */\nvar canArrange = function(arr, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @param {Integer} k\n# @return {Boolean}\ndef can_arrange(arr, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canArrange(_ arr: [Int], _ k: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canArrange(arr []int, k int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canArrange(arr: Array[Int], k: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canArrange(arr: IntArray, k: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_arrange(arr: Vec, k: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @param Integer $k\n * @return Boolean\n */\n function canArrange($arr, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canArrange(arr: number[], k: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-arrange arr k)\n (-> (listof exact-integer?) exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1497](https://leetcode-cn.com/problems/check-if-array-pairs-are-divisible-by-k)", "[\u68c0\u67e5\u6570\u7ec4\u5bf9\u662f\u5426\u53ef\u4ee5\u88ab k \u6574\u9664](/solution/1400-1499/1497.Check%20If%20Array%20Pairs%20Are%20Divisible%20by%20k/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u7ec4`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1497](https://leetcode.com/problems/check-if-array-pairs-are-divisible-by-k)", "[Check If Array Pairs Are Divisible by k](/solution/1400-1499/1497.Check%20If%20Array%20Pairs%20Are%20Divisible%20by%20k/README_EN.md)", "`Greedy`,`Array`,`Math`", "Medium", ""]}, {"question_id": "1619", "frontend_question_id": "1496", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/path-crossing", "url_en": "https://leetcode.com/problems/path-crossing", "relative_path_cn": "/solution/1400-1499/1496.Path%20Crossing/README.md", "relative_path_en": "/solution/1400-1499/1496.Path%20Crossing/README_EN.md", "title_cn": "\u5224\u65ad\u8def\u5f84\u662f\u5426\u76f8\u4ea4", "title_en": "Path Crossing", "question_title_slug": "path-crossing", "content_en": "

    Given a string path, where path[i] = 'N', 'S', 'E' or 'W', each representing moving one unit north, south, east, or west, respectively. You start at the origin (0, 0) on a 2D plane and walk on the path specified by path.

    \n\n

    Return true if the path crosses itself at any point, that is, if at any time you are on a location you have previously visited. Return false otherwise.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: path = "NES"\nOutput: false \nExplanation: Notice that the path doesn't cross any point more than once.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: path = "NESWW"\nOutput: true\nExplanation: Notice that the path visits the origin twice.
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= path.length <= 104
    • \n\t
    • path[i] is either 'N', 'S', 'E', or 'W'.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 path\uff0c\u5176\u4e2d path[i] \u7684\u503c\u53ef\u4ee5\u662f 'N'\u3001'S'\u3001'E' \u6216\u8005 'W'\uff0c\u5206\u522b\u8868\u793a\u5411\u5317\u3001\u5411\u5357\u3001\u5411\u4e1c\u3001\u5411\u897f\u79fb\u52a8\u4e00\u4e2a\u5355\u4f4d\u3002

    \n\n

    \u673a\u5668\u4eba\u4ece\u4e8c\u7ef4\u5e73\u9762\u4e0a\u7684\u539f\u70b9 (0, 0) \u5904\u5f00\u59cb\u51fa\u53d1\uff0c\u6309 path \u6240\u6307\u793a\u7684\u8def\u5f84\u884c\u8d70\u3002

    \n\n

    \u5982\u679c\u8def\u5f84\u5728\u4efb\u4f55\u4f4d\u7f6e\u4e0a\u51fa\u73b0\u76f8\u4ea4\u7684\u60c5\u51b5\uff0c\u4e5f\u5c31\u662f\u8d70\u5230\u4e4b\u524d\u5df2\u7ecf\u8d70\u8fc7\u7684\u4f4d\u7f6e\uff0c\u8bf7\u8fd4\u56de True \uff1b\u5426\u5219\uff0c\u8fd4\u56de False \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1apath = "NES"\n\u8f93\u51fa\uff1afalse \n\u89e3\u91ca\uff1a\u8be5\u8def\u5f84\u6ca1\u6709\u5728\u4efb\u4f55\u4f4d\u7f6e\u76f8\u4ea4\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1apath = "NESWW"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u8be5\u8def\u5f84\u7ecf\u8fc7\u539f\u70b9\u4e24\u6b21\u3002
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= path.length <= 10^4
    • \n\t
    • path \u4ec5\u7531 {'N', 'S', 'E', 'W} \u4e2d\u7684\u5b57\u7b26\u7ec4\u6210
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isPathCrossing(string path) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isPathCrossing(String path) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isPathCrossing(self, path):\n \"\"\"\n :type path: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isPathCrossing(self, path: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isPathCrossing(char * path){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsPathCrossing(string path) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} path\n * @return {boolean}\n */\nvar isPathCrossing = function(path) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} path\n# @return {Boolean}\ndef is_path_crossing(path)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isPathCrossing(_ path: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isPathCrossing(path string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isPathCrossing(path: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isPathCrossing(path: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_path_crossing(path: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $path\n * @return Boolean\n */\n function isPathCrossing($path) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isPathCrossing(path: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-path-crossing path)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1496](https://leetcode-cn.com/problems/path-crossing)", "[\u5224\u65ad\u8def\u5f84\u662f\u5426\u76f8\u4ea4](/solution/1400-1499/1496.Path%20Crossing/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1496](https://leetcode.com/problems/path-crossing)", "[Path Crossing](/solution/1400-1499/1496.Path%20Crossing/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1618", "frontend_question_id": "1474", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/delete-n-nodes-after-m-nodes-of-a-linked-list", "url_en": "https://leetcode.com/problems/delete-n-nodes-after-m-nodes-of-a-linked-list", "relative_path_cn": "/solution/1400-1499/1474.Delete%20N%20Nodes%20After%20M%20Nodes%20of%20a%20Linked%20List/README.md", "relative_path_en": "/solution/1400-1499/1474.Delete%20N%20Nodes%20After%20M%20Nodes%20of%20a%20Linked%20List/README_EN.md", "title_cn": "\u5220\u9664\u94fe\u8868 M \u4e2a\u8282\u70b9\u4e4b\u540e\u7684 N \u4e2a\u8282\u70b9", "title_en": "Delete N Nodes After M Nodes of a Linked List", "question_title_slug": "delete-n-nodes-after-m-nodes-of-a-linked-list", "content_en": "

    Given the head of a linked list and two integers m and n. Traverse the linked list and remove some nodes in the following way:

    \r\n\r\n
      \r\n\t
    • Start with the head as the current node.
    • \r\n\t
    • Keep the first m nodes starting with the current node.
    • \r\n\t
    • Remove the next n nodes
    • \r\n\t
    • Keep repeating steps 2 and 3 until you reach the end of the list.
    • \r\n
    \r\n\r\n

    Return the head of the modified list after removing the mentioned nodes.

    \r\n\r\n

    Follow up question: How can you solve this problem by modifying the list in-place?

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n

    \"\"

    \r\n\r\n
    \r\nInput: head = [1,2,3,4,5,6,7,8,9,10,11,12,13], m = 2, n = 3\r\nOutput: [1,2,6,7,11,12]\r\nExplanation: Keep the first (m = 2) nodes starting from the head of the linked List  (1 ->2) show in black nodes.\r\nDelete the next (n = 3) nodes (3 -> 4 -> 5) show in read nodes.\r\nContinue with the same procedure until reaching the tail of the Linked List.\r\nHead of linked list after removing nodes is returned.
    \r\n\r\n

    Example 2:

    \r\n\r\n

    \"\"

    \r\n\r\n
    \r\nInput: head = [1,2,3,4,5,6,7,8,9,10,11], m = 1, n = 3\r\nOutput: [1,5,9]\r\nExplanation: Head of linked list after removing nodes is returned.
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: head = [1,2,3,4,5,6,7,8,9,10,11], m = 3, n = 1\r\nOutput: [1,2,3,5,6,7,9,10,11]\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: head = [9,3,7,7,9,10,8,2], m = 1, n = 2\r\nOutput: [9,7,8]\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • The given linked list will contain between 1 and 10^4 nodes.
    • \r\n\t
    • The value of each node in the linked list will be in the range [1, 10^6].
    • \r\n\t
    • 1 <= m,n <= 1000
    • \r\n
    ", "content_cn": "

    \u7ed9\u5b9a\u94fe\u8868\u00a0head\u00a0\u548c\u4e24\u4e2a\u6574\u6570\u00a0m\u00a0\u548c\u00a0n. \u904d\u5386\u8be5\u94fe\u8868\u5e76\u6309\u7167\u5982\u4e0b\u65b9\u5f0f\u5220\u9664\u8282\u70b9:

    \n\n
      \n\t
    • \u5f00\u59cb\u65f6\u4ee5\u5934\u8282\u70b9\u4f5c\u4e3a\u5f53\u524d\u8282\u70b9.
    • \n\t
    • \u4fdd\u7559\u4ee5\u5f53\u524d\u8282\u70b9\u5f00\u59cb\u7684\u524d\u00a0m\u00a0\u4e2a\u8282\u70b9.
    • \n\t
    • \u5220\u9664\u63a5\u4e0b\u6765\u7684\u00a0n\u00a0\u4e2a\u8282\u70b9.
    • \n\t
    • \u91cd\u590d\u6b65\u9aa4 2 \u548c 3,\u00a0\u76f4\u5230\u5230\u8fbe\u94fe\u8868\u7ed3\u5c3e.
    • \n
    \n\n

    \u5728\u5220\u9664\u4e86\u6307\u5b9a\u7ed3\u70b9\u4e4b\u540e,\u00a0\u8fd4\u56de\u4fee\u6539\u8fc7\u540e\u7684\u94fe\u8868\u7684\u5934\u8282\u70b9.

    \n\n

    \u8fdb\u9636\u95ee\u9898: \u4f60\u80fd\u901a\u8fc7\u5c31\u5730\u4fee\u6539\u94fe\u8868\u7684\u65b9\u5f0f\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u5417?

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1:

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165: head = [1,2,3,4,5,6,7,8,9,10,11,12,13], m = 2, n = 3\n\u8f93\u51fa: [1,2,6,7,11,12]\n\u89e3\u6790: \u4fdd\u7559\u524d(m = 2)\u4e2a\u7ed3\u70b9,  \u4e5f\u5c31\u662f\u4ee5\u9ed1\u8272\u8282\u70b9\u8868\u793a\u7684\u4ece\u94fe\u8868\u5934\u7ed3\u70b9\u5f00\u59cb\u7684\u7ed3\u70b9(1 ->2).\n\u5220\u9664\u63a5\u4e0b\u6765\u7684(n = 3)\u4e2a\u7ed3\u70b9(3 -> 4 -> 5), \u5728\u56fe\u4e2d\u4ee5\u7ea2\u8272\u7ed3\u70b9\u8868\u793a.\n\u7ee7\u7eed\u76f8\u540c\u7684\u64cd\u4f5c, \u76f4\u5230\u94fe\u8868\u7684\u672b\u5c3e.\n\u8fd4\u56de\u5220\u9664\u7ed3\u70b9\u4e4b\u540e\u7684\u94fe\u8868\u7684\u5934\u7ed3\u70b9.
    \n\n

    \u793a\u4f8b 2:

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165: head = [1,2,3,4,5,6,7,8,9,10,11], m = 1, n = 3\n\u8f93\u51fa: [1,5,9]\n\u89e3\u6790: \u8fd4\u56de\u5220\u9664\u7ed3\u70b9\u4e4b\u540e\u7684\u94fe\u8868\u7684\u5934\u7ed3\u70b9.
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \n\u8f93\u5165: head = [1,2,3,4,5,6,7,8,9,10,11], m = 3, n = 1\n\u8f93\u51fa: [1,2,3,5,6,7,9,10,11]\n
    \n\n

    \u793a\u4f8b\u00a04:

    \n\n
    \n\u8f93\u5165: head = [9,3,7,7,9,10,8,2], m = 1, n = 2\n\u8f93\u51fa: [9,7,8]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a:

    \n\n
      \n\t
    • \u00a01 <=\u00a0\u94fe\u8868\u7ed3\u70b9\u6570 <= 10^4
    • \n\t
    • [1 <= \u94fe\u8868\u7684\u6bcf\u4e00\u4e2a\u7ed3\u70b9\u503c <=10^6]
    • \n\t
    • 1 <= m,n <=\u00a01000
    • \n
    \n", "tags_en": ["Linked List"], "tags_cn": ["\u94fe\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n ListNode* deleteNodes(ListNode* head, int m, int n) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public ListNode deleteNodes(ListNode head, int m, int n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def deleteNodes(self, head, m, n):\n \"\"\"\n :type head: ListNode\n :type m: int\n :type n: int\n :rtype: ListNode\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def deleteNodes(self, head: ListNode, m: int, n: int) -> ListNode:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nstruct ListNode* deleteNodes(struct ListNode* head, int m, int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public ListNode DeleteNodes(ListNode head, int m, int n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} head\n * @param {number} m\n * @param {number} n\n * @return {ListNode}\n */\nvar deleteNodes = function(head, m, n) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode} head\n# @param {Integer} m\n# @param {Integer} n\n# @return {ListNode}\ndef delete_nodes(head, m, n)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func deleteNodes(_ head: ListNode?, _ m: Int, _ n: Int) -> ListNode? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc deleteNodes(head *ListNode, m int, n int) *ListNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def deleteNodes(head: ListNode, m: Int, n: Int): ListNode = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun deleteNodes(head: ListNode?, m: Int, n: Int): ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn delete_nodes(head: Option>, m: i32, n: i32) -> Option> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @param Integer $m\n * @param Integer $n\n * @return ListNode\n */\n function deleteNodes($head, $m, $n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction deleteNodes(head: ListNode | null, m: number, n: number): ListNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (delete-nodes head m n)\n (-> (or/c list-node? #f) exact-integer? exact-integer? (or/c list-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1474](https://leetcode-cn.com/problems/delete-n-nodes-after-m-nodes-of-a-linked-list)", "[\u5220\u9664\u94fe\u8868 M \u4e2a\u8282\u70b9\u4e4b\u540e\u7684 N \u4e2a\u8282\u70b9](/solution/1400-1499/1474.Delete%20N%20Nodes%20After%20M%20Nodes%20of%20a%20Linked%20List/README.md)", "`\u94fe\u8868`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1474](https://leetcode.com/problems/delete-n-nodes-after-m-nodes-of-a-linked-list)", "[Delete N Nodes After M Nodes of a Linked List](/solution/1400-1499/1474.Delete%20N%20Nodes%20After%20M%20Nodes%20of%20a%20Linked%20List/README_EN.md)", "`Linked List`", "Easy", "\ud83d\udd12"]}, {"question_id": "1617", "frontend_question_id": "1510", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/stone-game-iv", "url_en": "https://leetcode.com/problems/stone-game-iv", "relative_path_cn": "/solution/1500-1599/1510.Stone%20Game%20IV/README.md", "relative_path_en": "/solution/1500-1599/1510.Stone%20Game%20IV/README_EN.md", "title_cn": "\u77f3\u5b50\u6e38\u620f IV", "title_en": "Stone Game IV", "question_title_slug": "stone-game-iv", "content_en": "

    Alice and Bob take turns playing a game, with Alice starting first.

    \n\n

    Initially, there are n stones in a pile.  On each player's turn, that player makes a move consisting of removing any non-zero square number of stones in the pile.

    \n\n

    Also, if a player cannot make a move, he/she loses the game.

    \n\n

    Given a positive integer n. Return True if and only if Alice wins the game otherwise return False, assuming both players play optimally.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 1\nOutput: true\nExplanation: Alice can remove 1 stone winning the game because Bob doesn't have any moves.
    \n\n

    Example 2:

    \n\n
    \nInput: n = 2\nOutput: false\nExplanation: Alice can only remove 1 stone, after that Bob removes the last one winning the game (2 -> 1 -> 0).
    \n\n

    Example 3:

    \n\n
    \nInput: n = 4\nOutput: true\nExplanation: n is already a perfect square, Alice can win with one move, removing 4 stones (4 -> 0).\n
    \n\n

    Example 4:

    \n\n
    \nInput: n = 7\nOutput: false\nExplanation: Alice can't win the game if Bob plays optimally.\nIf Alice starts removing 4 stones, Bob will remove 1 stone then Alice should remove only 1 stone and finally Bob removes the last one (7 -> 3 -> 2 -> 1 -> 0). \nIf Alice starts removing 1 stone, Bob will remove 4 stones then Alice only can remove 1 stone and finally Bob removes the last one (7 -> 6 -> 2 -> 1 -> 0).
    \n\n

    Example 5:

    \n\n
    \nInput: n = 17\nOutput: false\nExplanation: Alice can't win the game if Bob plays optimally.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 10^5
    • \n
    \n", "content_cn": "

    Alice \u548c Bob \u4e24\u4e2a\u4eba\u8f6e\u6d41\u73a9\u4e00\u4e2a\u6e38\u620f\uff0cAlice \u5148\u624b\u3002

    \n\n

    \u4e00\u5f00\u59cb\uff0c\u6709 n \u4e2a\u77f3\u5b50\u5806\u5728\u4e00\u8d77\u3002\u6bcf\u4e2a\u4eba\u8f6e\u6d41\u64cd\u4f5c\uff0c\u6b63\u5728\u64cd\u4f5c\u7684\u73a9\u5bb6\u53ef\u4ee5\u4ece\u77f3\u5b50\u5806\u91cc\u62ff\u8d70 \u4efb\u610f \u975e\u96f6 \u5e73\u65b9\u6570 \u4e2a\u77f3\u5b50\u3002

    \n\n

    \u5982\u679c\u77f3\u5b50\u5806\u91cc\u6ca1\u6709\u77f3\u5b50\u4e86\uff0c\u5219\u65e0\u6cd5\u64cd\u4f5c\u7684\u73a9\u5bb6\u8f93\u6389\u6e38\u620f\u3002

    \n\n

    \u7ed9\u4f60\u6b63\u6574\u6570 n \uff0c\u4e14\u5df2\u77e5\u4e24\u4e2a\u4eba\u90fd\u91c7\u53d6\u6700\u4f18\u7b56\u7565\u3002\u5982\u679c Alice \u4f1a\u8d62\u5f97\u6bd4\u8d5b\uff0c\u90a3\u4e48\u8fd4\u56de True \uff0c\u5426\u5219\u8fd4\u56de False \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1aAlice \u62ff\u8d70 1 \u4e2a\u77f3\u5b50\u5e76\u8d62\u5f97\u80dc\u5229\uff0c\u56e0\u4e3a Bob \u65e0\u6cd5\u8fdb\u884c\u4efb\u4f55\u64cd\u4f5c\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 2\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1aAlice \u53ea\u80fd\u62ff\u8d70 1 \u4e2a\u77f3\u5b50\uff0c\u7136\u540e Bob \u62ff\u8d70\u6700\u540e\u4e00\u4e2a\u77f3\u5b50\u5e76\u8d62\u5f97\u80dc\u5229\uff082 -> 1 -> 0\uff09\u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 4\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1an \u5df2\u7ecf\u662f\u4e00\u4e2a\u5e73\u65b9\u6570\uff0cAlice \u53ef\u4ee5\u4e00\u6b21\u5168\u62ff\u6389 4 \u4e2a\u77f3\u5b50\u5e76\u8d62\u5f97\u80dc\u5229\uff084 -> 0\uff09\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 7\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u5f53 Bob \u91c7\u53d6\u6700\u4f18\u7b56\u7565\u65f6\uff0cAlice \u65e0\u6cd5\u8d62\u5f97\u6bd4\u8d5b\u3002\n\u5982\u679c Alice \u4e00\u5f00\u59cb\u62ff\u8d70 4 \u4e2a\u77f3\u5b50\uff0c Bob \u4f1a\u62ff\u8d70 1 \u4e2a\u77f3\u5b50\uff0c\u7136\u540e Alice \u53ea\u80fd\u62ff\u8d70 1 \u4e2a\u77f3\u5b50\uff0cBob \u62ff\u8d70\u6700\u540e\u4e00\u4e2a\u77f3\u5b50\u5e76\u8d62\u5f97\u80dc\u5229\uff087 -> 3 -> 2 -> 1 -> 0\uff09\u3002\n\u5982\u679c Alice \u4e00\u5f00\u59cb\u62ff\u8d70 1 \u4e2a\u77f3\u5b50\uff0c Bob \u4f1a\u62ff\u8d70 4 \u4e2a\u77f3\u5b50\uff0c\u7136\u540e Alice \u53ea\u80fd\u62ff\u8d70 1 \u4e2a\u77f3\u5b50\uff0cBob \u62ff\u8d70\u6700\u540e\u4e00\u4e2a\u77f3\u5b50\u5e76\u8d62\u5f97\u80dc\u5229\uff087 -> 6 -> 2 -> 1 -> 0\uff09\u3002
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 17\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u5982\u679c Bob \u91c7\u53d6\u6700\u4f18\u7b56\u7565\uff0cAlice \u65e0\u6cd5\u8d62\u5f97\u80dc\u5229\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 10^5
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool winnerSquareGame(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean winnerSquareGame(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def winnerSquareGame(self, n):\n \"\"\"\n :type n: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def winnerSquareGame(self, n: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool winnerSquareGame(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool WinnerSquareGame(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {boolean}\n */\nvar winnerSquareGame = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Boolean}\ndef winner_square_game(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func winnerSquareGame(_ n: Int) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func winnerSquareGame(n int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def winnerSquareGame(n: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun winnerSquareGame(n: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn winner_square_game(n: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Boolean\n */\n function winnerSquareGame($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function winnerSquareGame(n: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (winner-square-game n)\n (-> exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1510](https://leetcode-cn.com/problems/stone-game-iv)", "[\u77f3\u5b50\u6e38\u620f IV](/solution/1500-1599/1510.Stone%20Game%20IV/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1510](https://leetcode.com/problems/stone-game-iv)", "[Stone Game IV](/solution/1500-1599/1510.Stone%20Game%20IV/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1616", "frontend_question_id": "1509", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-difference-between-largest-and-smallest-value-in-three-moves", "url_en": "https://leetcode.com/problems/minimum-difference-between-largest-and-smallest-value-in-three-moves", "relative_path_cn": "/solution/1500-1599/1509.Minimum%20Difference%20Between%20Largest%20and%20Smallest%20Value%20in%20Three%20Moves/README.md", "relative_path_en": "/solution/1500-1599/1509.Minimum%20Difference%20Between%20Largest%20and%20Smallest%20Value%20in%20Three%20Moves/README_EN.md", "title_cn": "\u4e09\u6b21\u64cd\u4f5c\u540e\u6700\u5927\u503c\u4e0e\u6700\u5c0f\u503c\u7684\u6700\u5c0f\u5dee", "title_en": "Minimum Difference Between Largest and Smallest Value in Three Moves", "question_title_slug": "minimum-difference-between-largest-and-smallest-value-in-three-moves", "content_en": "

    Given an array nums, you are allowed to choose one element of nums and change it by any value in one move.

    \r\n\r\n

    Return the minimum difference between the largest and smallest value of nums after perfoming at most 3 moves.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: nums = [5,3,2,4]\r\nOutput: 0\r\nExplanation: Change the array [5,3,2,4] to [2,2,2,2].\r\nThe difference between the maximum and minimum is 2-2 = 0.
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: nums = [1,5,0,10,14]\r\nOutput: 1\r\nExplanation: Change the array [1,5,0,10,14] to [1,1,0,1,1]. \r\nThe difference between the maximum and minimum is 1-0 = 1.\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: nums = [6,6,0,1,1,4,6]\r\nOutput: 2\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: nums = [1,5,6,14,15]\r\nOutput: 1\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= nums.length <= 10^5
    • \r\n\t
    • -10^9 <= nums[i] <= 10^9
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 nums \uff0c\u6bcf\u6b21\u64cd\u4f5c\u4f60\u53ef\u4ee5\u9009\u62e9 nums \u4e2d\u7684\u4efb\u610f\u4e00\u4e2a\u5143\u7d20\u5e76\u5c06\u5b83\u6539\u6210\u4efb\u610f\u503c\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u4e09\u6b21\u64cd\u4f5c\u540e\uff0c nums \u4e2d\u6700\u5927\u503c\u4e0e\u6700\u5c0f\u503c\u7684\u5dee\u7684\u6700\u5c0f\u503c\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [5,3,2,4]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u5c06\u6570\u7ec4 [5,3,2,4] \u53d8\u6210 [2,2,2,2].\n\u6700\u5927\u503c\u4e0e\u6700\u5c0f\u503c\u7684\u5dee\u4e3a 2-2 = 0 \u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,5,0,10,14]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u5c06\u6570\u7ec4 [1,5,0,10,14] \u53d8\u6210 [1,1,0,1,1] \u3002\n\u6700\u5927\u503c\u4e0e\u6700\u5c0f\u503c\u7684\u5dee\u4e3a 1-0 = 1 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [6,6,0,1,1,4,6]\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,5,6,14,15]\n\u8f93\u51fa\uff1a1\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 10^5
    • \n\t
    • -10^9 <= nums[i] <= 10^9
    • \n
    \n", "tags_en": ["Sort", "Array"], "tags_cn": ["\u6392\u5e8f", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minDifference(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minDifference(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minDifference(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minDifference(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minDifference(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinDifference(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar minDifference = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef min_difference(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minDifference(_ nums: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minDifference(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minDifference(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minDifference(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_difference(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function minDifference($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minDifference(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-difference nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1509](https://leetcode-cn.com/problems/minimum-difference-between-largest-and-smallest-value-in-three-moves)", "[\u4e09\u6b21\u64cd\u4f5c\u540e\u6700\u5927\u503c\u4e0e\u6700\u5c0f\u503c\u7684\u6700\u5c0f\u5dee](/solution/1500-1599/1509.Minimum%20Difference%20Between%20Largest%20and%20Smallest%20Value%20in%20Three%20Moves/README.md)", "`\u6392\u5e8f`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1509](https://leetcode.com/problems/minimum-difference-between-largest-and-smallest-value-in-three-moves)", "[Minimum Difference Between Largest and Smallest Value in Three Moves](/solution/1500-1599/1509.Minimum%20Difference%20Between%20Largest%20and%20Smallest%20Value%20in%20Three%20Moves/README_EN.md)", "`Sort`,`Array`", "Medium", ""]}, {"question_id": "1615", "frontend_question_id": "1508", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/range-sum-of-sorted-subarray-sums", "url_en": "https://leetcode.com/problems/range-sum-of-sorted-subarray-sums", "relative_path_cn": "/solution/1500-1599/1508.Range%20Sum%20of%20Sorted%20Subarray%20Sums/README.md", "relative_path_en": "/solution/1500-1599/1508.Range%20Sum%20of%20Sorted%20Subarray%20Sums/README_EN.md", "title_cn": "\u5b50\u6570\u7ec4\u548c\u6392\u5e8f\u540e\u7684\u533a\u95f4\u548c", "title_en": "Range Sum of Sorted Subarray Sums", "question_title_slug": "range-sum-of-sorted-subarray-sums", "content_en": "

    You are given the array nums consisting of n positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers.

    \n\n

    Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the new array. Since the answer can be a huge number return it modulo 109 + 7.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,3,4], n = 4, left = 1, right = 5\nOutput: 13 \nExplanation: All subarray sums are 1, 3, 6, 10, 2, 5, 9, 3, 7, 4. After sorting them in non-decreasing order we have the new array [1, 2, 3, 3, 4, 5, 6, 7, 9, 10]. The sum of the numbers from index le = 1 to ri = 5 is 1 + 2 + 3 + 3 + 4 = 13. \n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,2,3,4], n = 4, left = 3, right = 4\nOutput: 6\nExplanation: The given array is the same as example 1. We have the new array [1, 2, 3, 3, 4, 5, 6, 7, 9, 10]. The sum of the numbers from index le = 3 to ri = 4 is 3 + 3 = 6.\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [1,2,3,4], n = 4, left = 1, right = 10\nOutput: 50\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= nums.length <= 1000
    • \n\t
    • 1 <= nums[i] <= 100
    • \n\t
    • 1 <= left <= right <= n * (n + 1) / 2
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 nums \uff0c\u5b83\u5305\u542b n \u4e2a\u6b63\u6574\u6570\u3002\u4f60\u9700\u8981\u8ba1\u7b97\u6240\u6709\u975e\u7a7a\u8fde\u7eed\u5b50\u6570\u7ec4\u7684\u548c\uff0c\u5e76\u5c06\u5b83\u4eec\u6309\u5347\u5e8f\u6392\u5e8f\uff0c\u5f97\u5230\u4e00\u4e2a\u65b0\u7684\u5305\u542b n * (n + 1) / 2 \u4e2a\u6570\u5b57\u7684\u6570\u7ec4\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u5728\u65b0\u6570\u7ec4\u4e2d\u4e0b\u6807\u4e3a left \u5230 right \uff08\u4e0b\u6807\u4ece 1 \u5f00\u59cb\uff09\u7684\u6240\u6709\u6570\u5b57\u548c\uff08\u5305\u62ec\u5de6\u53f3\u7aef\u70b9\uff09\u3002\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u5f88\u5927\uff0c\u8bf7\u4f60\u5c06\u5b83\u5bf9 10^9 + 7 \u53d6\u6a21\u540e\u8fd4\u56de\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,3,4], n = 4, left = 1, right = 5\n\u8f93\u51fa\uff1a13 \n\u89e3\u91ca\uff1a\u6240\u6709\u7684\u5b50\u6570\u7ec4\u548c\u4e3a 1, 3, 6, 10, 2, 5, 9, 3, 7, 4 \u3002\u5c06\u5b83\u4eec\u5347\u5e8f\u6392\u5e8f\u540e\uff0c\u6211\u4eec\u5f97\u5230\u65b0\u7684\u6570\u7ec4 [1, 2, 3, 3, 4, 5, 6, 7, 9, 10] \u3002\u4e0b\u6807\u4ece le = 1 \u5230 ri = 5 \u7684\u548c\u4e3a 1 + 2 + 3 + 3 + 4 = 13 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,3,4], n = 4, left = 3, right = 4\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u7ed9\u5b9a\u6570\u7ec4\u4e0e\u793a\u4f8b 1 \u4e00\u6837\uff0c\u6240\u4ee5\u65b0\u6570\u7ec4\u4e3a [1, 2, 3, 3, 4, 5, 6, 7, 9, 10] \u3002\u4e0b\u6807\u4ece le = 3 \u5230 ri = 4 \u7684\u548c\u4e3a 3 + 3 = 6 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,3,4], n = 4, left = 1, right = 10\n\u8f93\u51fa\uff1a50\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 10^3
    • \n\t
    • nums.length == n
    • \n\t
    • 1 <= nums[i] <= 100
    • \n\t
    • 1 <= left <= right <= n * (n + 1) / 2
    • \n
    \n", "tags_en": ["Sort", "Array"], "tags_cn": ["\u6392\u5e8f", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int rangeSum(vector& nums, int n, int left, int right) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int rangeSum(int[] nums, int n, int left, int right) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def rangeSum(self, nums, n, left, right):\n \"\"\"\n :type nums: List[int]\n :type n: int\n :type left: int\n :type right: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint rangeSum(int* nums, int numsSize, int n, int left, int right){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int RangeSum(int[] nums, int n, int left, int right) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} n\n * @param {number} left\n * @param {number} right\n * @return {number}\n */\nvar rangeSum = function(nums, n, left, right) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} n\n# @param {Integer} left\n# @param {Integer} right\n# @return {Integer}\ndef range_sum(nums, n, left, right)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func rangeSum(_ nums: [Int], _ n: Int, _ left: Int, _ right: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func rangeSum(nums []int, n int, left int, right int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def rangeSum(nums: Array[Int], n: Int, left: Int, right: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun rangeSum(nums: IntArray, n: Int, left: Int, right: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn range_sum(nums: Vec, n: i32, left: i32, right: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $n\n * @param Integer $left\n * @param Integer $right\n * @return Integer\n */\n function rangeSum($nums, $n, $left, $right) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function rangeSum(nums: number[], n: number, left: number, right: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (range-sum nums n left right)\n (-> (listof exact-integer?) exact-integer? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1508](https://leetcode-cn.com/problems/range-sum-of-sorted-subarray-sums)", "[\u5b50\u6570\u7ec4\u548c\u6392\u5e8f\u540e\u7684\u533a\u95f4\u548c](/solution/1500-1599/1508.Range%20Sum%20of%20Sorted%20Subarray%20Sums/README.md)", "`\u6392\u5e8f`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1508](https://leetcode.com/problems/range-sum-of-sorted-subarray-sums)", "[Range Sum of Sorted Subarray Sums](/solution/1500-1599/1508.Range%20Sum%20of%20Sorted%20Subarray%20Sums/README_EN.md)", "`Sort`,`Array`", "Medium", ""]}, {"question_id": "1613", "frontend_question_id": "1489", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree", "url_en": "https://leetcode.com/problems/find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree", "relative_path_cn": "/solution/1400-1499/1489.Find%20Critical%20and%20Pseudo-Critical%20Edges%20in%20Minimum%20Spanning%20Tree/README.md", "relative_path_en": "/solution/1400-1499/1489.Find%20Critical%20and%20Pseudo-Critical%20Edges%20in%20Minimum%20Spanning%20Tree/README_EN.md", "title_cn": "\u627e\u5230\u6700\u5c0f\u751f\u6210\u6811\u91cc\u7684\u5173\u952e\u8fb9\u548c\u4f2a\u5173\u952e\u8fb9", "title_en": "Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree", "question_title_slug": "find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree", "content_en": "

    Given a weighted undirected connected graph with n vertices numbered from 0 to n - 1, and an array edges where edges[i] = [ai, bi, weighti] represents a bidirectional and weighted edge between nodes ai and bi. A minimum spanning tree (MST) is a subset of the graph's edges that connects all vertices without cycles and with the minimum possible total edge weight.

    \n\n

    Find all the critical and pseudo-critical edges in the given graph's minimum spanning tree (MST). An MST edge whose deletion from the graph would cause the MST weight to increase is called a critical edge. On the other hand, a pseudo-critical edge is that which can appear in some MSTs but not all.

    \n\n

    Note that you can return the indices of the edges in any order.

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: n = 5, edges = [[0,1,1],[1,2,1],[2,3,2],[0,3,2],[0,4,3],[3,4,3],[1,4,6]]\nOutput: [[0,1],[2,3,4,5]]\nExplanation: The figure above describes the graph.\nThe following figure shows all the possible MSTs:\n\"\"\nNotice that the two edges 0 and 1 appear in all MSTs, therefore they are critical edges, so we return them in the first list of the output.\nThe edges 2, 3, 4, and 5 are only part of some MSTs, therefore they are considered pseudo-critical edges. We add them to the second list of the output.\n
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: n = 4, edges = [[0,1,1],[1,2,1],[2,3,1],[0,3,1]]\nOutput: [[],[0,1,2,3]]\nExplanation: We can observe that since all 4 edges have equal weight, choosing any 3 edges from the given 4 will yield an MST. Therefore all 4 edges are pseudo-critical.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= n <= 100
    • \n\t
    • 1 <= edges.length <= min(200, n * (n - 1) / 2)
    • \n\t
    • edges[i].length == 3
    • \n\t
    • 0 <= ai < bi < n
    • \n\t
    • 1 <= weighti <= 1000
    • \n\t
    • All pairs (ai, bi) are distinct.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a n \u4e2a\u70b9\u7684\u5e26\u6743\u65e0\u5411\u8fde\u901a\u56fe\uff0c\u8282\u70b9\u7f16\u53f7\u4e3a 0 \u5230 n-1 \uff0c\u540c\u65f6\u8fd8\u6709\u4e00\u4e2a\u6570\u7ec4 edges \uff0c\u5176\u4e2d edges[i] = [fromi, toi, weighti] \u8868\u793a\u5728 fromi \u548c toi \u8282\u70b9\u4e4b\u95f4\u6709\u4e00\u6761\u5e26\u6743\u65e0\u5411\u8fb9\u3002\u6700\u5c0f\u751f\u6210\u6811 (MST) \u662f\u7ed9\u5b9a\u56fe\u4e2d\u8fb9\u7684\u4e00\u4e2a\u5b50\u96c6\uff0c\u5b83\u8fde\u63a5\u4e86\u6240\u6709\u8282\u70b9\u4e14\u6ca1\u6709\u73af\uff0c\u800c\u4e14\u8fd9\u4e9b\u8fb9\u7684\u6743\u503c\u548c\u6700\u5c0f\u3002

    \n\n

    \u8bf7\u4f60\u627e\u5230\u7ed9\u5b9a\u56fe\u4e2d\u6700\u5c0f\u751f\u6210\u6811\u7684\u6240\u6709\u5173\u952e\u8fb9\u548c\u4f2a\u5173\u952e\u8fb9\u3002\u5982\u679c\u4ece\u56fe\u4e2d\u5220\u53bb\u67d0\u6761\u8fb9\uff0c\u4f1a\u5bfc\u81f4\u6700\u5c0f\u751f\u6210\u6811\u7684\u6743\u503c\u548c\u589e\u52a0\uff0c\u90a3\u4e48\u6211\u4eec\u5c31\u8bf4\u5b83\u662f\u4e00\u6761\u5173\u952e\u8fb9\u3002\u4f2a\u5173\u952e\u8fb9\u5219\u662f\u53ef\u80fd\u4f1a\u51fa\u73b0\u5728\u67d0\u4e9b\u6700\u5c0f\u751f\u6210\u6811\u4e2d\u4f46\u4e0d\u4f1a\u51fa\u73b0\u5728\u6240\u6709\u6700\u5c0f\u751f\u6210\u6811\u4e2d\u7684\u8fb9\u3002

    \n\n

    \u8bf7\u6ce8\u610f\uff0c\u4f60\u53ef\u4ee5\u5206\u522b\u4ee5\u4efb\u610f\u987a\u5e8f\u8fd4\u56de\u5173\u952e\u8fb9\u7684\u4e0b\u6807\u548c\u4f2a\u5173\u952e\u8fb9\u7684\u4e0b\u6807\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 5, edges = [[0,1,1],[1,2,1],[2,3,2],[0,3,2],[0,4,3],[3,4,3],[1,4,6]]\n\u8f93\u51fa\uff1a[[0,1],[2,3,4,5]]\n\u89e3\u91ca\uff1a\u4e0a\u56fe\u63cf\u8ff0\u4e86\u7ed9\u5b9a\u56fe\u3002\n\u4e0b\u56fe\u662f\u6240\u6709\u7684\u6700\u5c0f\u751f\u6210\u6811\u3002\n\"\"\n\u6ce8\u610f\u5230\u7b2c 0 \u6761\u8fb9\u548c\u7b2c 1 \u6761\u8fb9\u51fa\u73b0\u5728\u4e86\u6240\u6709\u6700\u5c0f\u751f\u6210\u6811\u4e2d\uff0c\u6240\u4ee5\u5b83\u4eec\u662f\u5173\u952e\u8fb9\uff0c\u6211\u4eec\u5c06\u8fd9\u4e24\u4e2a\u4e0b\u6807\u4f5c\u4e3a\u8f93\u51fa\u7684\u7b2c\u4e00\u4e2a\u5217\u8868\u3002\n\u8fb9 2\uff0c3\uff0c4 \u548c 5 \u662f\u6240\u6709 MST \u7684\u5269\u4f59\u8fb9\uff0c\u6240\u4ee5\u5b83\u4eec\u662f\u4f2a\u5173\u952e\u8fb9\u3002\u6211\u4eec\u5c06\u5b83\u4eec\u4f5c\u4e3a\u8f93\u51fa\u7684\u7b2c\u4e8c\u4e2a\u5217\u8868\u3002\n
    \n\n

    \u793a\u4f8b 2 \uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 4, edges = [[0,1,1],[1,2,1],[2,3,1],[0,3,1]]\n\u8f93\u51fa\uff1a[[],[0,1,2,3]]\n\u89e3\u91ca\uff1a\u53ef\u4ee5\u89c2\u5bdf\u5230 4 \u6761\u8fb9\u90fd\u6709\u76f8\u540c\u7684\u6743\u503c\uff0c\u4efb\u9009\u5b83\u4eec\u4e2d\u7684 3 \u6761\u53ef\u4ee5\u5f62\u6210\u4e00\u68f5 MST \u3002\u6240\u4ee5 4 \u6761\u8fb9\u90fd\u662f\u4f2a\u5173\u952e\u8fb9\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= n <= 100
    • \n\t
    • 1 <= edges.length <= min(200, n * (n - 1) / 2)
    • \n\t
    • edges[i].length == 3
    • \n\t
    • 0 <= fromi < toi < n
    • \n\t
    • 1 <= weighti <= 1000
    • \n\t
    • \u6240\u6709 (fromi, toi) \u6570\u5bf9\u90fd\u662f\u4e92\u4e0d\u76f8\u540c\u7684\u3002
    • \n
    \n", "tags_en": ["Depth-first Search", "Union Find"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e76\u67e5\u96c6"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> findCriticalAndPseudoCriticalEdges(int n, vector>& edges) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> findCriticalAndPseudoCriticalEdges(int n, int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findCriticalAndPseudoCriticalEdges(self, n, edges):\n \"\"\"\n :type n: int\n :type edges: List[List[int]]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findCriticalAndPseudoCriticalEdges(self, n: int, edges: List[List[int]]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** findCriticalAndPseudoCriticalEdges(int n, int** edges, int edgesSize, int* edgesColSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> FindCriticalAndPseudoCriticalEdges(int n, int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} edges\n * @return {number[][]}\n */\nvar findCriticalAndPseudoCriticalEdges = function(n, edges) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} edges\n# @return {Integer[][]}\ndef find_critical_and_pseudo_critical_edges(n, edges)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findCriticalAndPseudoCriticalEdges(_ n: Int, _ edges: [[Int]]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findCriticalAndPseudoCriticalEdges(n int, edges [][]int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findCriticalAndPseudoCriticalEdges(n: Int, edges: Array[Array[Int]]): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findCriticalAndPseudoCriticalEdges(n: Int, edges: Array): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_critical_and_pseudo_critical_edges(n: i32, edges: Vec>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $edges\n * @return Integer[][]\n */\n function findCriticalAndPseudoCriticalEdges($n, $edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findCriticalAndPseudoCriticalEdges(n: number, edges: number[][]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-critical-and-pseudo-critical-edges n edges)\n (-> exact-integer? (listof (listof exact-integer?)) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1489](https://leetcode-cn.com/problems/find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree)", "[\u627e\u5230\u6700\u5c0f\u751f\u6210\u6811\u91cc\u7684\u5173\u952e\u8fb9\u548c\u4f2a\u5173\u952e\u8fb9](/solution/1400-1499/1489.Find%20Critical%20and%20Pseudo-Critical%20Edges%20in%20Minimum%20Spanning%20Tree/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e76\u67e5\u96c6`", "\u56f0\u96be", ""], "md_table_row_en": ["[1489](https://leetcode.com/problems/find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree)", "[Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree](/solution/1400-1499/1489.Find%20Critical%20and%20Pseudo-Critical%20Edges%20in%20Minimum%20Spanning%20Tree/README_EN.md)", "`Depth-first Search`,`Union Find`", "Hard", ""]}, {"question_id": "1612", "frontend_question_id": "1488", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/avoid-flood-in-the-city", "url_en": "https://leetcode.com/problems/avoid-flood-in-the-city", "relative_path_cn": "/solution/1400-1499/1488.Avoid%20Flood%20in%20The%20City/README.md", "relative_path_en": "/solution/1400-1499/1488.Avoid%20Flood%20in%20The%20City/README_EN.md", "title_cn": "\u907f\u514d\u6d2a\u6c34\u6cdb\u6ee5", "title_en": "Avoid Flood in The City", "question_title_slug": "avoid-flood-in-the-city", "content_en": "

    Your country has an infinite number of lakes. Initially, all the lakes are empty, but when it rains over the nth lake, the nth lake becomes full of water. If it rains over a lake which is full of water, there will be a flood. Your goal is to avoid the flood in any lake.

    \n\n

    Given an integer array rains where:

    \n\n
      \n\t
    • rains[i] > 0 means there will be rains over the rains[i] lake.
    • \n\t
    • rains[i] == 0 means there are no rains this day and you can choose one lake this day and dry it.
    • \n
    \n\n

    Return an array ans where:

    \n\n
      \n\t
    • ans.length == rains.length
    • \n\t
    • ans[i] == -1 if rains[i] > 0.
    • \n\t
    • ans[i] is the lake you choose to dry in the ith day if rains[i] == 0.
    • \n
    \n\n

    If there are multiple valid answers return any of them. If it is impossible to avoid flood return an empty array.

    \n\n

    Notice that if you chose to dry a full lake, it becomes empty, but if you chose to dry an empty lake, nothing changes. (see example 4)

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: rains = [1,2,3,4]\nOutput: [-1,-1,-1,-1]\nExplanation: After the first day full lakes are [1]\nAfter the second day full lakes are [1,2]\nAfter the third day full lakes are [1,2,3]\nAfter the fourth day full lakes are [1,2,3,4]\nThere's no day to dry any lake and there is no flood in any lake.\n
    \n\n

    Example 2:

    \n\n
    \nInput: rains = [1,2,0,0,2,1]\nOutput: [-1,-1,2,1,-1,-1]\nExplanation: After the first day full lakes are [1]\nAfter the second day full lakes are [1,2]\nAfter the third day, we dry lake 2. Full lakes are [1]\nAfter the fourth day, we dry lake 1. There is no full lakes.\nAfter the fifth day, full lakes are [2].\nAfter the sixth day, full lakes are [1,2].\nIt is easy that this scenario is flood-free. [-1,-1,1,2,-1,-1] is another acceptable scenario.\n
    \n\n

    Example 3:

    \n\n
    \nInput: rains = [1,2,0,1,2]\nOutput: []\nExplanation: After the second day, full lakes are  [1,2]. We have to dry one lake in the third day.\nAfter that, it will rain over lakes [1,2]. It's easy to prove that no matter which lake you choose to dry in the 3rd day, the other one will flood.\n
    \n\n

    Example 4:

    \n\n
    \nInput: rains = [69,0,0,0,69]\nOutput: [-1,69,1,1,-1]\nExplanation: Any solution on one of the forms [-1,69,x,y,-1], [-1,x,69,y,-1] or [-1,x,y,69,-1] is acceptable where 1 <= x,y <= 10^9\n
    \n\n

    Example 5:

    \n\n
    \nInput: rains = [10,20,20]\nOutput: []\nExplanation: It will rain over lake 20 two consecutive days. There is no chance to dry any lake.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= rains.length <= 105
    • \n\t
    • 0 <= rains[i] <= 109
    • \n
    \n", "content_cn": "

    \u4f60\u7684\u56fd\u5bb6\u6709\u65e0\u6570\u4e2a\u6e56\u6cca\uff0c\u6240\u6709\u6e56\u6cca\u4e00\u5f00\u59cb\u90fd\u662f\u7a7a\u7684\u3002\u5f53\u7b2c n \u4e2a\u6e56\u6cca\u4e0b\u96e8\u7684\u65f6\u5019\uff0c\u5982\u679c\u7b2c n \u4e2a\u6e56\u6cca\u662f\u7a7a\u7684\uff0c\u90a3\u4e48\u5b83\u5c31\u4f1a\u88c5\u6ee1\u6c34\uff0c\u5426\u5219\u8fd9\u4e2a\u6e56\u6cca\u4f1a\u53d1\u751f\u6d2a\u6c34\u3002\u4f60\u7684\u76ee\u6807\u662f\u907f\u514d\u4efb\u610f\u4e00\u4e2a\u6e56\u6cca\u53d1\u751f\u6d2a\u6c34\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 rains \uff0c\u5176\u4e2d\uff1a

    \n\n
      \n\t
    • rains[i] > 0 \u8868\u793a\u7b2c i \u5929\u65f6\uff0c\u7b2c rains[i] \u4e2a\u6e56\u6cca\u4f1a\u4e0b\u96e8\u3002
    • \n\t
    • rains[i] == 0 \u8868\u793a\u7b2c i \u5929\u6ca1\u6709\u6e56\u6cca\u4f1a\u4e0b\u96e8\uff0c\u4f60\u53ef\u4ee5\u9009\u62e9 \u4e00\u4e2a \u6e56\u6cca\u5e76 \u62bd\u5e72 \u8fd9\u4e2a\u6e56\u6cca\u7684\u6c34\u3002
    • \n
    \n\n

    \u8bf7\u8fd4\u56de\u4e00\u4e2a\u6570\u7ec4 ans \uff0c\u6ee1\u8db3\uff1a

    \n\n
      \n\t
    • ans.length == rains.length
    • \n\t
    • \u5982\u679c rains[i] > 0 \uff0c\u90a3\u4e48ans[i] == -1 \u3002
    • \n\t
    • \u5982\u679c rains[i] == 0 \uff0cans[i] \u662f\u4f60\u7b2c i \u5929\u9009\u62e9\u62bd\u5e72\u7684\u6e56\u6cca\u3002
    • \n
    \n\n

    \u5982\u679c\u6709\u591a\u79cd\u53ef\u884c\u89e3\uff0c\u8bf7\u8fd4\u56de\u5b83\u4eec\u4e2d\u7684 \u4efb\u610f\u4e00\u4e2a \u3002\u5982\u679c\u6ca1\u529e\u6cd5\u963b\u6b62\u6d2a\u6c34\uff0c\u8bf7\u8fd4\u56de\u4e00\u4e2a \u7a7a\u7684\u6570\u7ec4 \u3002

    \n\n

    \u8bf7\u6ce8\u610f\uff0c\u5982\u679c\u4f60\u9009\u62e9\u62bd\u5e72\u4e00\u4e2a\u88c5\u6ee1\u6c34\u7684\u6e56\u6cca\uff0c\u5b83\u4f1a\u53d8\u6210\u4e00\u4e2a\u7a7a\u7684\u6e56\u6cca\u3002\u4f46\u5982\u679c\u4f60\u9009\u62e9\u62bd\u5e72\u4e00\u4e2a\u7a7a\u7684\u6e56\u6cca\uff0c\u90a3\u4e48\u5c06\u65e0\u4e8b\u53d1\u751f\uff08\u8be6\u60c5\u8bf7\u770b\u793a\u4f8b 4\uff09\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1arains = [1,2,3,4]\n\u8f93\u51fa\uff1a[-1,-1,-1,-1]\n\u89e3\u91ca\uff1a\u7b2c\u4e00\u5929\u540e\uff0c\u88c5\u6ee1\u6c34\u7684\u6e56\u6cca\u5305\u62ec [1]\n\u7b2c\u4e8c\u5929\u540e\uff0c\u88c5\u6ee1\u6c34\u7684\u6e56\u6cca\u5305\u62ec [1,2]\n\u7b2c\u4e09\u5929\u540e\uff0c\u88c5\u6ee1\u6c34\u7684\u6e56\u6cca\u5305\u62ec [1,2,3]\n\u7b2c\u56db\u5929\u540e\uff0c\u88c5\u6ee1\u6c34\u7684\u6e56\u6cca\u5305\u62ec [1,2,3,4]\n\u6ca1\u6709\u54ea\u4e00\u5929\u4f60\u53ef\u4ee5\u62bd\u5e72\u4efb\u4f55\u6e56\u6cca\u7684\u6c34\uff0c\u4e5f\u6ca1\u6709\u6e56\u6cca\u4f1a\u53d1\u751f\u6d2a\u6c34\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1arains = [1,2,0,0,2,1]\n\u8f93\u51fa\uff1a[-1,-1,2,1,-1,-1]\n\u89e3\u91ca\uff1a\u7b2c\u4e00\u5929\u540e\uff0c\u88c5\u6ee1\u6c34\u7684\u6e56\u6cca\u5305\u62ec [1]\n\u7b2c\u4e8c\u5929\u540e\uff0c\u88c5\u6ee1\u6c34\u7684\u6e56\u6cca\u5305\u62ec [1,2]\n\u7b2c\u4e09\u5929\u540e\uff0c\u6211\u4eec\u62bd\u5e72\u6e56\u6cca 2 \u3002\u6240\u4ee5\u5269\u4e0b\u88c5\u6ee1\u6c34\u7684\u6e56\u6cca\u5305\u62ec [1]\n\u7b2c\u56db\u5929\u540e\uff0c\u6211\u4eec\u62bd\u5e72\u6e56\u6cca 1 \u3002\u6240\u4ee5\u6682\u65f6\u6ca1\u6709\u88c5\u6ee1\u6c34\u7684\u6e56\u6cca\u4e86\u3002\n\u7b2c\u4e94\u5929\u540e\uff0c\u88c5\u6ee1\u6c34\u7684\u6e56\u6cca\u5305\u62ec [2]\u3002\n\u7b2c\u516d\u5929\u540e\uff0c\u88c5\u6ee1\u6c34\u7684\u6e56\u6cca\u5305\u62ec [1,2]\u3002\n\u53ef\u4ee5\u770b\u51fa\uff0c\u8fd9\u4e2a\u65b9\u6848\u4e0b\u4e0d\u4f1a\u6709\u6d2a\u6c34\u53d1\u751f\u3002\u540c\u65f6\uff0c [-1,-1,1,2,-1,-1] \u4e5f\u662f\u53e6\u4e00\u4e2a\u53ef\u884c\u7684\u6ca1\u6709\u6d2a\u6c34\u7684\u65b9\u6848\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1arains = [1,2,0,1,2]\n\u8f93\u51fa\uff1a[]\n\u89e3\u91ca\uff1a\u7b2c\u4e8c\u5929\u540e\uff0c\u88c5\u6ee1\u6c34\u7684\u6e56\u6cca\u5305\u62ec [1,2]\u3002\u6211\u4eec\u53ef\u4ee5\u5728\u7b2c\u4e09\u5929\u62bd\u5e72\u4e00\u4e2a\u6e56\u6cca\u7684\u6c34\u3002\n\u4f46\u7b2c\u4e09\u5929\u540e\uff0c\u6e56\u6cca 1 \u548c 2 \u90fd\u4f1a\u518d\u6b21\u4e0b\u96e8\uff0c\u6240\u4ee5\u4e0d\u7ba1\u6211\u4eec\u7b2c\u4e09\u5929\u62bd\u5e72\u54ea\u4e2a\u6e56\u6cca\u7684\u6c34\uff0c\u53e6\u4e00\u4e2a\u6e56\u6cca\u90fd\u4f1a\u53d1\u751f\u6d2a\u6c34\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1arains = [69,0,0,0,69]\n\u8f93\u51fa\uff1a[-1,69,1,1,-1]\n\u89e3\u91ca\uff1a\u4efb\u4f55\u5f62\u5982 [-1,69,x,y,-1], [-1,x,69,y,-1] \u6216\u8005 [-1,x,y,69,-1] \u90fd\u662f\u53ef\u884c\u7684\u89e3\uff0c\u5176\u4e2d 1 <= x,y <= 10^9\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1arains = [10,20,20]\n\u8f93\u51fa\uff1a[]\n\u89e3\u91ca\uff1a\u7531\u4e8e\u6e56\u6cca 20 \u4f1a\u8fde\u7eed\u4e0b 2 \u5929\u7684\u96e8\uff0c\u6240\u4ee5\u6ca1\u6709\u6ca1\u6709\u529e\u6cd5\u963b\u6b62\u6d2a\u6c34\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= rains.length <= 10^5
    • \n\t
    • 0 <= rains[i] <= 10^9
    • \n
    \n", "tags_en": ["Array", "Hash Table"], "tags_cn": ["\u6570\u7ec4", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector avoidFlood(vector& rains) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] avoidFlood(int[] rains) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def avoidFlood(self, rains):\n \"\"\"\n :type rains: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def avoidFlood(self, rains: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* avoidFlood(int* rains, int rainsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] AvoidFlood(int[] rains) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} rains\n * @return {number[]}\n */\nvar avoidFlood = function(rains) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} rains\n# @return {Integer[]}\ndef avoid_flood(rains)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func avoidFlood(_ rains: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func avoidFlood(rains []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def avoidFlood(rains: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun avoidFlood(rains: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn avoid_flood(rains: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $rains\n * @return Integer[]\n */\n function avoidFlood($rains) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function avoidFlood(rains: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (avoid-flood rains)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1488](https://leetcode-cn.com/problems/avoid-flood-in-the-city)", "[\u907f\u514d\u6d2a\u6c34\u6cdb\u6ee5](/solution/1400-1499/1488.Avoid%20Flood%20in%20The%20City/README.md)", "`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1488](https://leetcode.com/problems/avoid-flood-in-the-city)", "[Avoid Flood in The City](/solution/1400-1499/1488.Avoid%20Flood%20in%20The%20City/README_EN.md)", "`Array`,`Hash Table`", "Medium", ""]}, {"question_id": "1611", "frontend_question_id": "1487", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/making-file-names-unique", "url_en": "https://leetcode.com/problems/making-file-names-unique", "relative_path_cn": "/solution/1400-1499/1487.Making%20File%20Names%20Unique/README.md", "relative_path_en": "/solution/1400-1499/1487.Making%20File%20Names%20Unique/README_EN.md", "title_cn": "\u4fdd\u8bc1\u6587\u4ef6\u540d\u552f\u4e00", "title_en": "Making File Names Unique", "question_title_slug": "making-file-names-unique", "content_en": "

    Given an array of strings names of size n. You will create n folders in your file system such that, at the ith minute, you will create a folder with the name names[i].

    \r\n\r\n

    Since two files cannot have the same name, if you enter a folder name which is previously used, the system will have a suffix addition to its name in the form of (k), where, k is the smallest positive integer such that the obtained name remains unique.

    \r\n\r\n

    Return an array of strings of length n where ans[i] is the actual name the system will assign to the ith folder when you create it.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: names = ["pes","fifa","gta","pes(2019)"]\r\nOutput: ["pes","fifa","gta","pes(2019)"]\r\nExplanation: Let's see how the file system creates folder names:\r\n"pes" --> not assigned before, remains "pes"\r\n"fifa" --> not assigned before, remains "fifa"\r\n"gta" --> not assigned before, remains "gta"\r\n"pes(2019)" --> not assigned before, remains "pes(2019)"\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: names = ["gta","gta(1)","gta","avalon"]\r\nOutput: ["gta","gta(1)","gta(2)","avalon"]\r\nExplanation: Let's see how the file system creates folder names:\r\n"gta" --> not assigned before, remains "gta"\r\n"gta(1)" --> not assigned before, remains "gta(1)"\r\n"gta" --> the name is reserved, system adds (k), since "gta(1)" is also reserved, systems put k = 2. it becomes "gta(2)"\r\n"avalon" --> not assigned before, remains "avalon"\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: names = ["onepiece","onepiece(1)","onepiece(2)","onepiece(3)","onepiece"]\r\nOutput: ["onepiece","onepiece(1)","onepiece(2)","onepiece(3)","onepiece(4)"]\r\nExplanation: When the last folder is created, the smallest positive valid k is 4, and it becomes "onepiece(4)".\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: names = ["wano","wano","wano","wano"]\r\nOutput: ["wano","wano(1)","wano(2)","wano(3)"]\r\nExplanation: Just increase the value of k each time you create folder "wano".\r\n
    \r\n\r\n

    Example 5:

    \r\n\r\n
    \r\nInput: names = ["kaido","kaido(1)","kaido","kaido(1)"]\r\nOutput: ["kaido","kaido(1)","kaido(2)","kaido(1)(1)"]\r\nExplanation: Please note that system adds the suffix (k) to current name even it contained the same suffix before.\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= names.length <= 5 * 10^4
    • \r\n\t
    • 1 <= names[i].length <= 20
    • \r\n\t
    • names[i] consists of lower case English letters, digits and/or round brackets.
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u5b57\u7b26\u4e32\u6570\u7ec4 names \u3002\u4f60\u5c06\u4f1a\u5728\u6587\u4ef6\u7cfb\u7edf\u4e2d\u521b\u5efa n \u4e2a\u6587\u4ef6\u5939\uff1a\u5728\u7b2c i \u5206\u949f\uff0c\u65b0\u5efa\u540d\u4e3a names[i] \u7684\u6587\u4ef6\u5939\u3002

    \n\n

    \u7531\u4e8e\u4e24\u4e2a\u6587\u4ef6 \u4e0d\u80fd \u5171\u4eab\u76f8\u540c\u7684\u6587\u4ef6\u540d\uff0c\u56e0\u6b64\u5982\u679c\u65b0\u5efa\u6587\u4ef6\u5939\u4f7f\u7528\u7684\u6587\u4ef6\u540d\u5df2\u7ecf\u88ab\u5360\u7528\uff0c\u7cfb\u7edf\u4f1a\u4ee5 (k) \u7684\u5f62\u5f0f\u4e3a\u65b0\u6587\u4ef6\u5939\u7684\u6587\u4ef6\u540d\u6dfb\u52a0\u540e\u7f00\uff0c\u5176\u4e2d k \u662f\u80fd\u4fdd\u8bc1\u6587\u4ef6\u540d\u552f\u4e00\u7684 \u6700\u5c0f\u6b63\u6574\u6570 \u3002

    \n\n

    \u8fd4\u56de\u957f\u5ea6\u4e3a n \u7684\u5b57\u7b26\u4e32\u6570\u7ec4\uff0c\u5176\u4e2d ans[i] \u662f\u521b\u5efa\u7b2c i \u4e2a\u6587\u4ef6\u5939\u65f6\u7cfb\u7edf\u5206\u914d\u7ed9\u8be5\u6587\u4ef6\u5939\u7684\u5b9e\u9645\u540d\u79f0\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anames = ["pes","fifa","gta","pes(2019)"]\n\u8f93\u51fa\uff1a["pes","fifa","gta","pes(2019)"]\n\u89e3\u91ca\uff1a\u6587\u4ef6\u7cfb\u7edf\u5c06\u4f1a\u8fd9\u6837\u521b\u5efa\u6587\u4ef6\u540d\uff1a\n"pes" --> \u4e4b\u524d\u672a\u5206\u914d\uff0c\u4ecd\u4e3a "pes"\n"fifa" --> \u4e4b\u524d\u672a\u5206\u914d\uff0c\u4ecd\u4e3a "fifa"\n"gta" --> \u4e4b\u524d\u672a\u5206\u914d\uff0c\u4ecd\u4e3a "gta"\n"pes(2019)" --> \u4e4b\u524d\u672a\u5206\u914d\uff0c\u4ecd\u4e3a "pes(2019)"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anames = ["gta","gta(1)","gta","avalon"]\n\u8f93\u51fa\uff1a["gta","gta(1)","gta(2)","avalon"]\n\u89e3\u91ca\uff1a\u6587\u4ef6\u7cfb\u7edf\u5c06\u4f1a\u8fd9\u6837\u521b\u5efa\u6587\u4ef6\u540d\uff1a\n"gta" --> \u4e4b\u524d\u672a\u5206\u914d\uff0c\u4ecd\u4e3a "gta"\n"gta(1)" --> \u4e4b\u524d\u672a\u5206\u914d\uff0c\u4ecd\u4e3a "gta(1)"\n"gta" --> \u6587\u4ef6\u540d\u88ab\u5360\u7528\uff0c\u7cfb\u7edf\u4e3a\u8be5\u540d\u79f0\u6dfb\u52a0\u540e\u7f00 (k)\uff0c\u7531\u4e8e "gta(1)" \u4e5f\u88ab\u5360\u7528\uff0c\u6240\u4ee5 k = 2 \u3002\u5b9e\u9645\u521b\u5efa\u7684\u6587\u4ef6\u540d\u4e3a "gta(2)" \u3002\n"avalon" --> \u4e4b\u524d\u672a\u5206\u914d\uff0c\u4ecd\u4e3a "avalon"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1anames = ["onepiece","onepiece(1)","onepiece(2)","onepiece(3)","onepiece"]\n\u8f93\u51fa\uff1a["onepiece","onepiece(1)","onepiece(2)","onepiece(3)","onepiece(4)"]\n\u89e3\u91ca\uff1a\u5f53\u521b\u5efa\u6700\u540e\u4e00\u4e2a\u6587\u4ef6\u5939\u65f6\uff0c\u6700\u5c0f\u7684\u6b63\u6709\u6548 k \u4e3a 4 \uff0c\u6587\u4ef6\u540d\u53d8\u4e3a "onepiece(4)"\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1anames = ["wano","wano","wano","wano"]\n\u8f93\u51fa\uff1a["wano","wano(1)","wano(2)","wano(3)"]\n\u89e3\u91ca\uff1a\u6bcf\u6b21\u521b\u5efa\u6587\u4ef6\u5939 "wano" \u65f6\uff0c\u53ea\u9700\u589e\u52a0\u540e\u7f00\u4e2d k \u7684\u503c\u5373\u53ef\u3002
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1anames = ["kaido","kaido(1)","kaido","kaido(1)"]\n\u8f93\u51fa\uff1a["kaido","kaido(1)","kaido(2)","kaido(1)(1)"]\n\u89e3\u91ca\uff1a\u6ce8\u610f\uff0c\u5982\u679c\u542b\u540e\u7f00\u6587\u4ef6\u540d\u88ab\u5360\u7528\uff0c\u90a3\u4e48\u7cfb\u7edf\u4e5f\u4f1a\u6309\u89c4\u5219\u5728\u540d\u79f0\u540e\u6dfb\u52a0\u65b0\u7684\u540e\u7f00 (k) \u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= names.length <= 5 * 10^4
    • \n\t
    • 1 <= names[i].length <= 20
    • \n\t
    • names[i] \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3001\u6570\u5b57\u548c/\u6216\u5706\u62ec\u53f7\u7ec4\u6210\u3002
    • \n
    \n", "tags_en": ["Hash Table", "String"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector getFolderNames(vector& names) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String[] getFolderNames(String[] names) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getFolderNames(self, names):\n \"\"\"\n :type names: List[str]\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getFolderNames(self, names: List[str]) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** getFolderNames(char ** names, int namesSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string[] GetFolderNames(string[] names) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} names\n * @return {string[]}\n */\nvar getFolderNames = function(names) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} names\n# @return {String[]}\ndef get_folder_names(names)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getFolderNames(_ names: [String]) -> [String] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getFolderNames(names []string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getFolderNames(names: Array[String]): Array[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getFolderNames(names: Array): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_folder_names(names: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $names\n * @return String[]\n */\n function getFolderNames($names) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getFolderNames(names: string[]): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-folder-names names)\n (-> (listof string?) (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1487](https://leetcode-cn.com/problems/making-file-names-unique)", "[\u4fdd\u8bc1\u6587\u4ef6\u540d\u552f\u4e00](/solution/1400-1499/1487.Making%20File%20Names%20Unique/README.md)", "`\u54c8\u5e0c\u8868`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1487](https://leetcode.com/problems/making-file-names-unique)", "[Making File Names Unique](/solution/1400-1499/1487.Making%20File%20Names%20Unique/README_EN.md)", "`Hash Table`,`String`", "Medium", ""]}, {"question_id": "1610", "frontend_question_id": "1486", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/xor-operation-in-an-array", "url_en": "https://leetcode.com/problems/xor-operation-in-an-array", "relative_path_cn": "/solution/1400-1499/1486.XOR%20Operation%20in%20an%20Array/README.md", "relative_path_en": "/solution/1400-1499/1486.XOR%20Operation%20in%20an%20Array/README_EN.md", "title_cn": "\u6570\u7ec4\u5f02\u6216\u64cd\u4f5c", "title_en": "XOR Operation in an Array", "question_title_slug": "xor-operation-in-an-array", "content_en": "

    Given an integer n and an integer start.

    \r\n\r\n

    Define an array nums where nums[i] = start + 2*i (0-indexed) and n == nums.length.

    \r\n\r\n

    Return the bitwise XOR of all elements of nums.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: n = 5, start = 0\r\nOutput: 8\r\nExplanation: Array nums is equal to [0, 2, 4, 6, 8] where (0 ^ 2 ^ 4 ^ 6 ^ 8) = 8.\r\nWhere "^" corresponds to bitwise XOR operator.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: n = 4, start = 3\r\nOutput: 8\r\nExplanation: Array nums is equal to [3, 5, 7, 9] where (3 ^ 5 ^ 7 ^ 9) = 8.
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: n = 1, start = 7\r\nOutput: 7\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: n = 10, start = 5\r\nOutput: 2\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= n <= 1000
    • \r\n\t
    • 0 <= start <= 1000
    • \r\n\t
    • n == nums.length
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u6574\u6570\uff0cn \u548c start \u3002

    \n\n

    \u6570\u7ec4 nums \u5b9a\u4e49\u4e3a\uff1anums[i] = start + 2*i\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\u4e14 n == nums.length \u3002

    \n\n

    \u8bf7\u8fd4\u56de nums \u4e2d\u6240\u6709\u5143\u7d20\u6309\u4f4d\u5f02\u6216\uff08XOR\uff09\u540e\u5f97\u5230\u7684\u7ed3\u679c\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1an = 5, start = 0\n\u8f93\u51fa\uff1a8\n\u89e3\u91ca\uff1a\u6570\u7ec4 nums \u4e3a [0, 2, 4, 6, 8]\uff0c\u5176\u4e2d (0 ^ 2 ^ 4 ^ 6 ^ 8) = 8 \u3002\n     "^" \u4e3a\u6309\u4f4d\u5f02\u6216 XOR \u8fd0\u7b97\u7b26\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1an = 4, start = 3\n\u8f93\u51fa\uff1a8\n\u89e3\u91ca\uff1a\u6570\u7ec4 nums \u4e3a [3, 5, 7, 9]\uff0c\u5176\u4e2d (3 ^ 5 ^ 7 ^ 9) = 8.
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1an = 1, start = 7\n\u8f93\u51fa\uff1a7\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1an = 10, start = 5\n\u8f93\u51fa\uff1a2\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 1000
    • \n\t
    • 0 <= start <= 1000
    • \n\t
    • n == nums.length
    • \n
    \n", "tags_en": ["Bit Manipulation", "Array"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int xorOperation(int n, int start) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int xorOperation(int n, int start) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def xorOperation(self, n, start):\n \"\"\"\n :type n: int\n :type start: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def xorOperation(self, n: int, start: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint xorOperation(int n, int start){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int XorOperation(int n, int start) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} start\n * @return {number}\n */\nvar xorOperation = function(n, start) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} start\n# @return {Integer}\ndef xor_operation(n, start)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func xorOperation(_ n: Int, _ start: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func xorOperation(n int, start int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def xorOperation(n: Int, start: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun xorOperation(n: Int, start: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn xor_operation(n: i32, start: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $start\n * @return Integer\n */\n function xorOperation($n, $start) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function xorOperation(n: number, start: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (xor-operation n start)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1486](https://leetcode-cn.com/problems/xor-operation-in-an-array)", "[\u6570\u7ec4\u5f02\u6216\u64cd\u4f5c](/solution/1400-1499/1486.XOR%20Operation%20in%20an%20Array/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1486](https://leetcode.com/problems/xor-operation-in-an-array)", "[XOR Operation in an Array](/solution/1400-1499/1486.XOR%20Operation%20in%20an%20Array/README_EN.md)", "`Bit Manipulation`,`Array`", "Easy", ""]}, {"question_id": "1609", "frontend_question_id": "1469", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/find-all-the-lonely-nodes", "url_en": "https://leetcode.com/problems/find-all-the-lonely-nodes", "relative_path_cn": "/solution/1400-1499/1469.Find%20All%20The%20Lonely%20Nodes/README.md", "relative_path_en": "/solution/1400-1499/1469.Find%20All%20The%20Lonely%20Nodes/README_EN.md", "title_cn": "\u5bfb\u627e\u6240\u6709\u7684\u72ec\u751f\u8282\u70b9", "title_en": "Find All The Lonely Nodes", "question_title_slug": "find-all-the-lonely-nodes", "content_en": "

    In a binary tree, a lonely node is a node that is the only child of its parent node. The root of the tree is not lonely because it does not have a parent node.

    \n\n

    Given the root of a binary tree, return an array containing the values of all lonely nodes in the tree. Return the list in any order.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,2,3,null,4]\nOutput: [4]\nExplanation: Light blue node is the only lonely node.\nNode 1 is the root and is not lonely.\nNodes 2 and 3 have the same parent and are not lonely.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [7,1,4,6,null,5,3,null,null,null,null,null,2]\nOutput: [6,2]\nExplanation: Light blue nodes are lonely nodes.\nPlease remember that order doesn't matter, [2,6] is also an acceptable answer.\n
    \n\n

    Example 3:

    \n\"\" \n\n
    \n\nInput: root = [11,99,88,77,null,null,66,55,null,null,44,33,null,null,22]\nOutput: [77,55,33,66,44,22]\nExplanation: Nodes 99 and 88 share the same parent. Node 11 is the root.\nAll other nodes are lonely.\n
    \n\n

    Example 4:

    \n\n
    \nInput: root = [197]\nOutput: []\n
    \n\n

    Example 5:

    \n\n
    \nInput: root = [31,null,78,null,28]\nOutput: [78,28]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 1000].
    • \n\t
    • Each node's value is between [1, 10^6].
    • \n
    \n", "content_cn": "

    \u4e8c\u53c9\u6811\u4e2d\uff0c\u5982\u679c\u4e00\u4e2a\u8282\u70b9\u662f\u5176\u7236\u8282\u70b9\u7684\u552f\u4e00\u5b50\u8282\u70b9\uff0c\u5219\u79f0\u8fd9\u6837\u7684\u8282\u70b9\u4e3a “\u72ec\u751f\u8282\u70b9” \u3002\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9\u4e0d\u4f1a\u662f\u72ec\u751f\u8282\u70b9\uff0c\u56e0\u4e3a\u5b83\u6ca1\u6709\u7236\u8282\u70b9\u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u68f5\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9 root \uff0c\u8fd4\u56de\u6811\u4e2d \u6240\u6709\u7684\u72ec\u751f\u8282\u70b9\u7684\u503c\u6240\u6784\u6210\u7684\u6570\u7ec4 \u3002\u6570\u7ec4\u7684\u987a\u5e8f \u4e0d\u9650 \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aroot = [1,2,3,null,4]\n\u8f93\u51fa\uff1a[4]\n\u89e3\u91ca\uff1a\u6d45\u84dd\u8272\u7684\u8282\u70b9\u662f\u552f\u4e00\u7684\u72ec\u751f\u8282\u70b9\u3002\n\u8282\u70b9 1 \u662f\u6839\u8282\u70b9\uff0c\u4e0d\u662f\u72ec\u751f\u7684\u3002\n\u8282\u70b9 2 \u548c 3 \u6709\u5171\u540c\u7684\u7236\u8282\u70b9\uff0c\u6240\u4ee5\u5b83\u4eec\u90fd\u4e0d\u662f\u72ec\u751f\u7684\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aroot = [7,1,4,6,null,5,3,null,null,null,null,null,2]\n\u8f93\u51fa\uff1a[6,2]\n\u8f93\u51fa\uff1a\u6d45\u84dd\u8272\u7684\u8282\u70b9\u662f\u72ec\u751f\u8282\u70b9\u3002\n\u8bf7\u8c28\u8bb0\uff0c\u987a\u5e8f\u662f\u4e0d\u9650\u7684\u3002 [2,6] \u4e5f\u662f\u4e00\u79cd\u53ef\u63a5\u53d7\u7684\u7b54\u6848\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aroot = [11,99,88,77,null,null,66,55,null,null,44,33,null,null,22]\n\u8f93\u51fa\uff1a[77,55,33,66,44,22]\n\u89e3\u91ca\uff1a\u8282\u70b9 99 \u548c 88 \u6709\u5171\u540c\u7684\u7236\u8282\u70b9\uff0c\u8282\u70b9 11 \u662f\u6839\u8282\u70b9\u3002\n\u5176\u4ed6\u6240\u6709\u8282\u70b9\u90fd\u662f\u72ec\u751f\u8282\u70b9\u3002
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [197]\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [31,null,78,null,28]\n\u8f93\u51fa\uff1a[78,28]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    •  tree \u4e2d\u8282\u70b9\u4e2a\u6570\u7684\u53d6\u503c\u8303\u56f4\u662f [1, 1000]\u3002
    • \n\t
    • \u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u7684\u53d6\u503c\u8303\u56f4\u662f [1, 10^6]\u3002
    • \n
    \n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector getLonelyNodes(TreeNode* root) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public List getLonelyNodes(TreeNode root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def getLonelyNodes(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: List[int]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def getLonelyNodes(self, root: TreeNode) -> List[int]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* getLonelyNodes(struct TreeNode* root, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public IList GetLonelyNodes(TreeNode root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number[]}\n */\nvar getLonelyNodes = function(root) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer[]}\ndef get_lonely_nodes(root)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func getLonelyNodes(_ root: TreeNode?) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc getLonelyNodes(root *TreeNode) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def getLonelyNodes(root: TreeNode): List[Int] = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun getLonelyNodes(root: TreeNode?): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn get_lonely_nodes(root: Option>>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer[]\n */\n function getLonelyNodes($root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction getLonelyNodes(root: TreeNode | null): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (get-lonely-nodes root)\n (-> (or/c tree-node? #f) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1469](https://leetcode-cn.com/problems/find-all-the-lonely-nodes)", "[\u5bfb\u627e\u6240\u6709\u7684\u72ec\u751f\u8282\u70b9](/solution/1400-1499/1469.Find%20All%20The%20Lonely%20Nodes/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1469](https://leetcode.com/problems/find-all-the-lonely-nodes)", "[Find All The Lonely Nodes](/solution/1400-1499/1469.Find%20All%20The%20Lonely%20Nodes/README_EN.md)", "`Tree`,`Depth-first Search`", "Easy", "\ud83d\udd12"]}, {"question_id": "1608", "frontend_question_id": "1468", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/calculate-salaries", "url_en": "https://leetcode.com/problems/calculate-salaries", "relative_path_cn": "/solution/1400-1499/1468.Calculate%20Salaries/README.md", "relative_path_en": "/solution/1400-1499/1468.Calculate%20Salaries/README_EN.md", "title_cn": "\u8ba1\u7b97\u7a0e\u540e\u5de5\u8d44", "title_en": "Calculate Salaries", "question_title_slug": "calculate-salaries", "content_en": "

    Table Salaries:

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| company_id    | int     |\n| employee_id   | int     |\n| employee_name | varchar |\n| salary        | int     |\n+---------------+---------+\n(company_id, employee_id) is the primary key for this table.\nThis table contains the company id, the id, the name and the salary for an employee.\n
    \n\n

     

    \n\n

    Write an SQL query to find the salaries of the employees after applying taxes.

    \n\n

    The tax rate is calculated for each company based on the following criteria:

    \n\n
      \n\t
    • 0% If the max salary of any employee in the company is less than 1000$.
    • \n\t
    • 24% If the max salary of any employee in the company is in the range [1000, 10000] inclusive.
    • \n\t
    • 49% If the max salary of any employee in the company is greater than 10000$.
    • \n
    \n\n

    Return the result table in any order. Round the salary to the nearest integer.

    \n\n

    The query result format is in the following example:

    \n\n
    \nSalaries table:\n+------------+-------------+---------------+--------+\n| company_id | employee_id | employee_name | salary |\n+------------+-------------+---------------+--------+\n| 1          | 1           | Tony          | 2000   |\n| 1          | 2           | Pronub        | 21300  |\n| 1          | 3           | Tyrrox        | 10800  |\n| 2          | 1           | Pam           | 300    |\n| 2          | 7           | Bassem        | 450    |\n| 2          | 9           | Hermione      | 700    |\n| 3          | 7           | Bocaben       | 100    |\n| 3          | 2           | Ognjen        | 2200   |\n| 3          | 13          | Nyancat       | 3300   |\n| 3          | 15          | Morninngcat   | 7777   |\n+------------+-------------+---------------+--------+\n\nResult table:\n+------------+-------------+---------------+--------+\n| company_id | employee_id | employee_name | salary |\n+------------+-------------+---------------+--------+\n| 1          | 1           | Tony          | 1020   |\n| 1          | 2           | Pronub        | 10863  |\n| 1          | 3           | Tyrrox        | 5508   |\n| 2          | 1           | Pam           | 300    |\n| 2          | 7           | Bassem        | 450    |\n| 2          | 9           | Hermione      | 700    |\n| 3          | 7           | Bocaben       | 76     |\n| 3          | 2           | Ognjen        | 1672   |\n| 3          | 13          | Nyancat       | 2508   |\n| 3          | 15          | Morninngcat   | 5911   |\n+------------+-------------+---------------+--------+\nFor company 1, Max salary is 21300. Employees in company 1 have taxes = 49%\nFor company 2, Max salary is 700. Employees in company 2 have taxes = 0%\nFor company 3, Max salary is 7777. Employees in company 3 have taxes = 24%\nThe salary after taxes = salary - (taxes percentage / 100) * salary\nFor example, Salary for Morninngcat (3, 15) after taxes = 7777 - 7777 * (24 / 100) = 7777 - 1866.48 = 5910.52, which is rounded to 5911.\n
    \n", "content_cn": "

    Salaries \u8868\uff1a

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| company_id    | int     |\n| employee_id   | int     |\n| employee_name | varchar |\n| salary        | int     |\n+---------------+---------+\n(company_id, employee_id) \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\n\u8fd9\u4e2a\u8868\u5305\u62ec\u5458\u5de5\u7684company id, id, name \u548c salary \n
    \n\n

    \u00a0

    \n\n

    \u5199\u4e00\u6761\u67e5\u8be2 SQL \u6765\u67e5\u627e\u6bcf\u4e2a\u5458\u5de5\u7684\u7a0e\u540e\u5de5\u8d44

    \n\n

    \u6bcf\u4e2a\u516c\u53f8\u7684\u7a0e\u7387\u8ba1\u7b97\u4f9d\u7167\u4ee5\u4e0b\u89c4\u5219

    \n\n
      \n\t
    • \u5982\u679c\u8fd9\u4e2a\u516c\u53f8\u5458\u5de5\u6700\u9ad8\u5de5\u8d44\u4e0d\u5230 1000 \uff0c\u7a0e\u7387\u4e3a 0%
    • \n\t
    • \u5982\u679c\u8fd9\u4e2a\u516c\u53f8\u5458\u5de5\u6700\u9ad8\u5de5\u8d44\u5728 1000 \u5230 10000 \u4e4b\u95f4\uff0c\u7a0e\u7387\u4e3a 24%
    • \n\t
    • \u5982\u679c\u8fd9\u4e2a\u516c\u53f8\u5458\u5de5\u6700\u9ad8\u5de5\u8d44\u5927\u4e8e 10000 \uff0c\u7a0e\u7387\u4e3a 49%
    • \n
    \n\n

    \u6309\u4efb\u610f\u987a\u5e8f\u8fd4\u56de\u7ed3\u679c\uff0c\u7a0e\u540e\u5de5\u8d44\u7ed3\u679c\u53d6\u6574

    \n\n

    \u00a0

    \n\n

    \u7ed3\u679c\u8868\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a\uff1a

    \n\n
    \nSalaries \u8868\uff1a\n+------------+-------------+---------------+--------+\n| company_id | employee_id | employee_name | salary |\n+------------+-------------+---------------+--------+\n| 1          | 1           | Tony          | 2000   |\n| 1          | 2           | Pronub        | 21300  |\n| 1          | 3           | Tyrrox        | 10800  |\n| 2          | 1           | Pam           | 300    |\n| 2          | 7           | Bassem        | 450    |\n| 2          | 9           | Hermione      | 700    |\n| 3          | 7           | Bocaben       | 100    |\n| 3          | 2           | Ognjen        | 2200   |\n| 3          | 13          | Nyancat       | 3300   |\n| 3          | 15          | Morninngcat   | 7777   |\n+------------+-------------+---------------+--------+\n\nResult \u8868\uff1a\n+------------+-------------+---------------+--------+\n| company_id | employee_id | employee_name | salary |\n+------------+-------------+---------------+--------+\n| 1          | 1           | Tony          | 1020   |\n| 1          | 2           | Pronub        | 10863  |\n| 1          | 3           | Tyrrox        | 5508   |\n| 2          | 1           | Pam           | 300    |\n| 2          | 7           | Bassem        | 450    |\n| 2          | 9           | Hermione      | 700    |\n| 3          | 7           | Bocaben       | 76     |\n| 3          | 2           | Ognjen        | 1672   |\n| 3          | 13          | Nyancat       | 2508   |\n| 3          | 15          | Morninngcat   | 5911   |\n+------------+-------------+---------------+--------+\n\u5bf9\u4e8e\u516c\u53f8 1 \uff0c\u6700\u9ad8\u5de5\u8d44\u662f 21300 \uff0c\u5176\u6bcf\u4e2a\u5458\u5de5\u7684\u7a0e\u7387\u4e3a 49%\n\u5bf9\u4e8e\u516c\u53f8 2 \uff0c\u6700\u9ad8\u5de5\u8d44\u662f 700 \uff0c\u5176\u6bcf\u4e2a\u5458\u5de5\u7a0e\u7387\u4e3a 0%\n\u5bf9\u4e8e\u516c\u53f8 3 \uff0c\u6700\u9ad8\u5de5\u8d44\u662f 7777 \uff0c\u5176\u6bcf\u4e2a\u5458\u5de5\u7a0e\u7387\u662f 24%\n\u7a0e\u540e\u5de5\u8d44\u8ba1\u7b97 = \u5de5\u8d44 - ( \u7a0e\u7387 / 100\uff09*\u5de5\u8d44\n\u5bf9\u4e8e\u4e0a\u8ff0\u6848\u4f8b\uff0cMorninngcat \u7684\u7a0e\u540e\u5de5\u8d44 = 7777 - 7777 * ( 24 / 100) = 7777 - 1866.48 = 5910.52 \uff0c\u53d6\u6574\u4e3a 5911\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1468](https://leetcode-cn.com/problems/calculate-salaries)", "[\u8ba1\u7b97\u7a0e\u540e\u5de5\u8d44](/solution/1400-1499/1468.Calculate%20Salaries/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1468](https://leetcode.com/problems/calculate-salaries)", "[Calculate Salaries](/solution/1400-1499/1468.Calculate%20Salaries/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1607", "frontend_question_id": "1459", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/rectangles-area", "url_en": "https://leetcode.com/problems/rectangles-area", "relative_path_cn": "/solution/1400-1499/1459.Rectangles%20Area/README.md", "relative_path_en": "/solution/1400-1499/1459.Rectangles%20Area/README_EN.md", "title_cn": "\u77e9\u5f62\u9762\u79ef", "title_en": "Rectangles Area", "question_title_slug": "rectangles-area", "content_en": "

    Table: Points

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| x_value       | int     |\n| y_value       | int     |\n+---------------+---------+\nid is the primary key for this table.\nEach point is represented as a 2D coordinate (x_value, y_value).
    \n\n

     

    \n\n

    Write an SQL query to report all possible axis-aligned rectangles with non-zero area that can be formed by any two points in the Points table.

    \n\n

    Each row in the result should contain three columns (p1, p2, area) where:

    \n\n
      \n\t
    • p1 and p2 are the id's of the two points that determine the opposite corners of a rectangle.
    • \n\t
    • area is the area of the rectangle and must be non-zero.
    • \n
    \n\n

    Report the query in descending order by area first, then in ascending order by p1's id if there is a tie, then in ascending order by p2's id if there is another tie.

    \n\n

    The query result format is in the following table:

    \n\n

     

    \n\n
    \nPoints table:\n+----------+-------------+-------------+\n| id       | x_value     | y_value     |\n+----------+-------------+-------------+\n| 1        | 2           | 7           |\n| 2        | 4           | 8           |\n| 3        | 2           | 10          |\n+----------+-------------+-------------+\n\nResult table:\n+----------+-------------+-------------+\n| p1       | p2          | area        |\n+----------+-------------+-------------+\n| 2        | 3           | 4           |\n| 1        | 2           | 2           |\n+----------+-------------+-------------+\n\n\"\"\nThe rectangle formed by p1 = 2 and p2 = 3 has an area equal to |4-2| * |8-10| = 4.\nThe rectangle formed by p1 = 1 and p2 = 2 has an area equal to |2-4| * |7-8| = 2.\nNote that the rectangle formed by p1 = 1 and p2 = 3 is invalid because the area is 0.\n
    \n", "content_cn": "

    \u8868: Points

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| x_value       | int     |\n| y_value       | int     |\n+---------------+---------+\nid \u662f\u8be5\u8868\u4e3b\u952e\n\u6bcf\u4e2a\u70b9\u90fd\u7528\u4e8c\u7ef4\u5750\u6807 (x_value, y_value) \u8868\u793a
    \n\n

    \u00a0

    \n\n

    \u5199\u4e00\u4e2a SQL \u8bed\u53e5\uff0c\u62a5\u544a\u7531\u8868\u4e2d\u4efb\u610f\u4e24\u70b9\u53ef\u4ee5\u5f62\u6210\u7684\u6240\u6709 \u8fb9\u4e0e\u5750\u6807\u8f74\u5e73\u884c \u4e14 \u9762\u79ef\u4e0d\u4e3a\u96f6 \u7684\u77e9\u5f62\u3002

    \n\n

    \u7ed3\u679c\u8868\u4e2d\u7684\u6bcf\u4e00\u884c\u5305\u542b\u4e09\u5217 (p1, p2, area)\u00a0\u5982\u4e0b:

    \n\n
      \n\t
    • p1\u00a0\u548c\u00a0p2\u00a0\u662f\u77e9\u5f62\u4e24\u4e2a\u5bf9\u89d2\u7684 id
    • \n\t
    • \u77e9\u5f62\u7684\u9762\u79ef\u7531\u5217\u00a0area\u00a0\u8868\u793a
    • \n
    \n\n

    \u8bf7\u6309\u7167\u9762\u79ef\u00a0area \u5927\u5c0f\u964d\u5e8f\u6392\u5217\uff1b\u5982\u679c\u9762\u79ef\u76f8\u540c\u7684\u8bdd, \u5219\u6309\u7167\u00a0p1\u00a0\u5347\u5e8f\u6392\u5e8f\uff1b\u82e5\u4ecd\u76f8\u540c\uff0c\u5219\u6309 p2 \u5347\u5e8f\u6392\u5217\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u5982\u4e0b\u4f8b\u6240\u793a\uff1a

    \n\n
    \nPoints \u8868:\n+----------+-------------+-------------+\n| id       | x_value     | y_value     |\n+----------+-------------+-------------+\n| 1        | 2           | 7           |\n| 2        | 4           | 8           |\n| 3        | 2           | 10          |\n+----------+-------------+-------------+\n\nResult \u8868:\n+----------+-------------+-------------+\n| p1       | p2          | area        |\n+----------+-------------+-------------+\n| 2        | 3           | 4           |\n| 1        | 2           | 2           |\n+----------+-------------+-------------+\n\n\"\"\n\np1 = 2 \u4e14 p2 = 3 \u65f6, \u9762\u79ef\u7b49\u4e8e |4-2| * |8-10| = 4\np1 = 1 \u4e14 p2 = 2 \u65f6, \u9762\u79ef\u7b49\u4e8e ||2-4| * |7-8| = 2 \np1 = 1 \u4e14 p2 = 3 \u65f6, \u662f\u4e0d\u53ef\u80fd\u4e3a\u77e9\u5f62\u7684, \u9762\u79ef\u7b49\u4e8e 0\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1459](https://leetcode-cn.com/problems/rectangles-area)", "[\u77e9\u5f62\u9762\u79ef](/solution/1400-1499/1459.Rectangles%20Area/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1459](https://leetcode.com/problems/rectangles-area)", "[Rectangles Area](/solution/1400-1499/1459.Rectangles%20Area/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1605", "frontend_question_id": "1482", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-number-of-days-to-make-m-bouquets", "url_en": "https://leetcode.com/problems/minimum-number-of-days-to-make-m-bouquets", "relative_path_cn": "/solution/1400-1499/1482.Minimum%20Number%20of%20Days%20to%20Make%20m%20Bouquets/README.md", "relative_path_en": "/solution/1400-1499/1482.Minimum%20Number%20of%20Days%20to%20Make%20m%20Bouquets/README_EN.md", "title_cn": "\u5236\u4f5c m \u675f\u82b1\u6240\u9700\u7684\u6700\u5c11\u5929\u6570", "title_en": "Minimum Number of Days to Make m Bouquets", "question_title_slug": "minimum-number-of-days-to-make-m-bouquets", "content_en": "

    Given an integer array bloomDay, an integer m and an integer k.

    \r\n\r\n

    We need to make m bouquets. To make a bouquet, you need to use k adjacent flowers from the garden.

    \r\n\r\n

    The garden consists of n flowers, the ith flower will bloom in the bloomDay[i] and then can be used in exactly one bouquet.

    \r\n\r\n

    Return the minimum number of days you need to wait to be able to make m bouquets from the garden. If it is impossible to make m bouquets return -1.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: bloomDay = [1,10,3,10,2], m = 3, k = 1\r\nOutput: 3\r\nExplanation: Let's see what happened in the first three days. x means flower bloomed and _ means flower didn't bloom in the garden.\r\nWe need 3 bouquets each should contain 1 flower.\r\nAfter day 1: [x, _, _, _, _]   // we can only make one bouquet.\r\nAfter day 2: [x, _, _, _, x]   // we can only make two bouquets.\r\nAfter day 3: [x, _, x, _, x]   // we can make 3 bouquets. The answer is 3.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: bloomDay = [1,10,3,10,2], m = 3, k = 2\r\nOutput: -1\r\nExplanation: We need 3 bouquets each has 2 flowers, that means we need 6 flowers. We only have 5 flowers so it is impossible to get the needed bouquets and we return -1.\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: bloomDay = [7,7,7,7,12,7,7], m = 2, k = 3\r\nOutput: 12\r\nExplanation: We need 2 bouquets each should have 3 flowers.\r\nHere's the garden after the 7 and 12 days:\r\nAfter day 7: [x, x, x, x, _, x, x]\r\nWe can make one bouquet of the first three flowers that bloomed. We cannot make another bouquet from the last three flowers that bloomed because they are not adjacent.\r\nAfter day 12: [x, x, x, x, x, x, x]\r\nIt is obvious that we can make two bouquets in different ways.\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: bloomDay = [1000000000,1000000000], m = 1, k = 1\r\nOutput: 1000000000\r\nExplanation: You need to wait 1000000000 days to have a flower ready for a bouquet.\r\n
    \r\n\r\n

    Example 5:

    \r\n\r\n
    \r\nInput: bloomDay = [1,10,2,9,3,8,4,7,5,6], m = 4, k = 2\r\nOutput: 9\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • bloomDay.length == n
    • \r\n\t
    • 1 <= n <= 10^5
    • \r\n\t
    • 1 <= bloomDay[i] <= 10^9
    • \r\n\t
    • 1 <= m <= 10^6
    • \r\n\t
    • 1 <= k <= n
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 bloomDay\uff0c\u4ee5\u53ca\u4e24\u4e2a\u6574\u6570 m \u548c k \u3002

    \n\n

    \u73b0\u9700\u8981\u5236\u4f5c m \u675f\u82b1\u3002\u5236\u4f5c\u82b1\u675f\u65f6\uff0c\u9700\u8981\u4f7f\u7528\u82b1\u56ed\u4e2d \u76f8\u90bb\u7684 k \u6735\u82b1 \u3002

    \n\n

    \u82b1\u56ed\u4e2d\u6709 n \u6735\u82b1\uff0c\u7b2c i \u6735\u82b1\u4f1a\u5728 bloomDay[i] \u65f6\u76db\u5f00\uff0c\u6070\u597d \u53ef\u4ee5\u7528\u4e8e \u4e00\u675f \u82b1\u4e2d\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u4ece\u82b1\u56ed\u4e2d\u6458 m \u675f\u82b1\u9700\u8981\u7b49\u5f85\u7684\u6700\u5c11\u7684\u5929\u6570\u3002\u5982\u679c\u4e0d\u80fd\u6458\u5230 m \u675f\u82b1\u5219\u8fd4\u56de -1 \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1abloomDay = [1,10,3,10,2], m = 3, k = 1\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u8ba9\u6211\u4eec\u4e00\u8d77\u89c2\u5bdf\u8fd9\u4e09\u5929\u7684\u82b1\u5f00\u8fc7\u7a0b\uff0cx \u8868\u793a\u82b1\u5f00\uff0c\u800c _ \u8868\u793a\u82b1\u8fd8\u672a\u5f00\u3002\n\u73b0\u5728\u9700\u8981\u5236\u4f5c 3 \u675f\u82b1\uff0c\u6bcf\u675f\u53ea\u9700\u8981 1 \u6735\u3002\n1 \u5929\u540e\uff1a[x, _, _, _, _]   // \u53ea\u80fd\u5236\u4f5c 1 \u675f\u82b1\n2 \u5929\u540e\uff1a[x, _, _, _, x]   // \u53ea\u80fd\u5236\u4f5c 2 \u675f\u82b1\n3 \u5929\u540e\uff1a[x, _, x, _, x]   // \u53ef\u4ee5\u5236\u4f5c 3 \u675f\u82b1\uff0c\u7b54\u6848\u4e3a 3\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1abloomDay = [1,10,3,10,2], m = 3, k = 2\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u8981\u5236\u4f5c 3 \u675f\u82b1\uff0c\u6bcf\u675f\u9700\u8981 2 \u6735\u82b1\uff0c\u4e5f\u5c31\u662f\u4e00\u5171\u9700\u8981 6 \u6735\u82b1\u3002\u800c\u82b1\u56ed\u4e2d\u53ea\u6709 5 \u6735\u82b1\uff0c\u65e0\u6cd5\u6ee1\u8db3\u5236\u4f5c\u8981\u6c42\uff0c\u8fd4\u56de -1 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1abloomDay = [7,7,7,7,12,7,7], m = 2, k = 3\n\u8f93\u51fa\uff1a12\n\u89e3\u91ca\uff1a\u8981\u5236\u4f5c 2 \u675f\u82b1\uff0c\u6bcf\u675f\u9700\u8981 3 \u6735\u3002\n\u82b1\u56ed\u5728 7 \u5929\u540e\u548c 12 \u5929\u540e\u7684\u60c5\u51b5\u5982\u4e0b\uff1a\n7 \u5929\u540e\uff1a[x, x, x, x, _, x, x]\n\u53ef\u4ee5\u7528\u524d 3 \u6735\u76db\u5f00\u7684\u82b1\u5236\u4f5c\u7b2c\u4e00\u675f\u82b1\u3002\u4f46\u4e0d\u80fd\u4f7f\u7528\u540e 3 \u6735\u76db\u5f00\u7684\u82b1\uff0c\u56e0\u4e3a\u5b83\u4eec\u4e0d\u76f8\u90bb\u3002\n12 \u5929\u540e\uff1a[x, x, x, x, x, x, x]\n\u663e\u7136\uff0c\u6211\u4eec\u53ef\u4ee5\u7528\u4e0d\u540c\u7684\u65b9\u5f0f\u5236\u4f5c\u4e24\u675f\u82b1\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1abloomDay = [1000000000,1000000000], m = 1, k = 1\n\u8f93\u51fa\uff1a1000000000\n\u89e3\u91ca\uff1a\u9700\u8981\u7b49 1000000000 \u5929\u624d\u80fd\u91c7\u5230\u82b1\u6765\u5236\u4f5c\u82b1\u675f\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1abloomDay = [1,10,2,9,3,8,4,7,5,6], m = 4, k = 2\n\u8f93\u51fa\uff1a9\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • bloomDay.length == n
    • \n\t
    • 1 <= n <= 10^5
    • \n\t
    • 1 <= bloomDay[i] <= 10^9
    • \n\t
    • 1 <= m <= 10^6
    • \n\t
    • 1 <= k <= n
    • \n
    \n", "tags_en": ["Array", "Binary Search"], "tags_cn": ["\u6570\u7ec4", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minDays(vector& bloomDay, int m, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minDays(int[] bloomDay, int m, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minDays(self, bloomDay, m, k):\n \"\"\"\n :type bloomDay: List[int]\n :type m: int\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minDays(self, bloomDay: List[int], m: int, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minDays(int* bloomDay, int bloomDaySize, int m, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinDays(int[] bloomDay, int m, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} bloomDay\n * @param {number} m\n * @param {number} k\n * @return {number}\n */\nvar minDays = function(bloomDay, m, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} bloom_day\n# @param {Integer} m\n# @param {Integer} k\n# @return {Integer}\ndef min_days(bloom_day, m, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minDays(_ bloomDay: [Int], _ m: Int, _ k: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minDays(bloomDay []int, m int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minDays(bloomDay: Array[Int], m: Int, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minDays(bloomDay: IntArray, m: Int, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_days(bloom_day: Vec, m: i32, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $bloomDay\n * @param Integer $m\n * @param Integer $k\n * @return Integer\n */\n function minDays($bloomDay, $m, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minDays(bloomDay: number[], m: number, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-days bloomDay m k)\n (-> (listof exact-integer?) exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1482](https://leetcode-cn.com/problems/minimum-number-of-days-to-make-m-bouquets)", "[\u5236\u4f5c m \u675f\u82b1\u6240\u9700\u7684\u6700\u5c11\u5929\u6570](/solution/1400-1499/1482.Minimum%20Number%20of%20Days%20to%20Make%20m%20Bouquets/README.md)", "`\u6570\u7ec4`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1482](https://leetcode.com/problems/minimum-number-of-days-to-make-m-bouquets)", "[Minimum Number of Days to Make m Bouquets](/solution/1400-1499/1482.Minimum%20Number%20of%20Days%20to%20Make%20m%20Bouquets/README_EN.md)", "`Array`,`Binary Search`", "Medium", ""]}, {"question_id": "1604", "frontend_question_id": "1481", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/least-number-of-unique-integers-after-k-removals", "url_en": "https://leetcode.com/problems/least-number-of-unique-integers-after-k-removals", "relative_path_cn": "/solution/1400-1499/1481.Least%20Number%20of%20Unique%20Integers%20after%20K%20Removals/README.md", "relative_path_en": "/solution/1400-1499/1481.Least%20Number%20of%20Unique%20Integers%20after%20K%20Removals/README_EN.md", "title_cn": "\u4e0d\u540c\u6574\u6570\u7684\u6700\u5c11\u6570\u76ee", "title_en": "Least Number of Unique Integers after K Removals", "question_title_slug": "least-number-of-unique-integers-after-k-removals", "content_en": "

    Given an array of integers arr and an integer k. Find the least number of unique integers after removing exactly k elements.

    \r\n\r\n
      \r\n
    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: arr = [5,5,4], k = 1\r\nOutput: 1\r\nExplanation: Remove the single 4, only 5 is left.\r\n
    \r\nExample 2:\r\n\r\n
    \r\nInput: arr = [4,3,1,1,3,3,2], k = 3\r\nOutput: 2\r\nExplanation: Remove 4, 2 and either one of the two 1s or three 3s. 1 and 3 will be left.
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= arr.length <= 10^5
    • \r\n\t
    • 1 <= arr[i] <= 10^9
    • \r\n\t
    • 0 <= k <= arr.length
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr \u548c\u4e00\u4e2a\u6574\u6570 k \u3002\u73b0\u9700\u8981\u4ece\u6570\u7ec4\u4e2d\u6070\u597d\u79fb\u9664 k \u4e2a\u5143\u7d20\uff0c\u8bf7\u627e\u51fa\u79fb\u9664\u540e\u6570\u7ec4\u4e2d\u4e0d\u540c\u6574\u6570\u7684\u6700\u5c11\u6570\u76ee\u3002

    \n\n
      \n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [5,5,4], k = 1\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u79fb\u9664 1 \u4e2a 4 \uff0c\u6570\u7ec4\u4e2d\u53ea\u5269\u4e0b 5 \u4e00\u79cd\u6574\u6570\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [4,3,1,1,3,3,2], k = 3\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5148\u79fb\u9664 4\u30012 \uff0c\u7136\u540e\u518d\u79fb\u9664\u4e24\u4e2a 1 \u4e2d\u7684\u4efb\u610f 1 \u4e2a\u6216\u8005\u4e09\u4e2a 3 \u4e2d\u7684\u4efb\u610f 1 \u4e2a\uff0c\u6700\u540e\u5269\u4e0b 1 \u548c 3 \u4e24\u79cd\u6574\u6570\u3002
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= arr.length <= 10^5
    • \n\t
    • 1 <= arr[i] <= 10^9
    • \n\t
    • 0 <= k <= arr.length
    • \n
    \n", "tags_en": ["Sort", "Array"], "tags_cn": ["\u6392\u5e8f", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findLeastNumOfUniqueInts(vector& arr, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findLeastNumOfUniqueInts(int[] arr, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findLeastNumOfUniqueInts(self, arr, k):\n \"\"\"\n :type arr: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findLeastNumOfUniqueInts(self, arr: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findLeastNumOfUniqueInts(int* arr, int arrSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindLeastNumOfUniqueInts(int[] arr, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @param {number} k\n * @return {number}\n */\nvar findLeastNumOfUniqueInts = function(arr, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @param {Integer} k\n# @return {Integer}\ndef find_least_num_of_unique_ints(arr, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findLeastNumOfUniqueInts(_ arr: [Int], _ k: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findLeastNumOfUniqueInts(arr []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findLeastNumOfUniqueInts(arr: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findLeastNumOfUniqueInts(arr: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_least_num_of_unique_ints(arr: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @param Integer $k\n * @return Integer\n */\n function findLeastNumOfUniqueInts($arr, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findLeastNumOfUniqueInts(arr: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-least-num-of-unique-ints arr k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1481](https://leetcode-cn.com/problems/least-number-of-unique-integers-after-k-removals)", "[\u4e0d\u540c\u6574\u6570\u7684\u6700\u5c11\u6570\u76ee](/solution/1400-1499/1481.Least%20Number%20of%20Unique%20Integers%20after%20K%20Removals/README.md)", "`\u6392\u5e8f`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1481](https://leetcode.com/problems/least-number-of-unique-integers-after-k-removals)", "[Least Number of Unique Integers after K Removals](/solution/1400-1499/1481.Least%20Number%20of%20Unique%20Integers%20after%20K%20Removals/README_EN.md)", "`Sort`,`Array`", "Medium", ""]}, {"question_id": "1603", "frontend_question_id": "1480", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/running-sum-of-1d-array", "url_en": "https://leetcode.com/problems/running-sum-of-1d-array", "relative_path_cn": "/solution/1400-1499/1480.Running%20Sum%20of%201d%20Array/README.md", "relative_path_en": "/solution/1400-1499/1480.Running%20Sum%20of%201d%20Array/README_EN.md", "title_cn": "\u4e00\u7ef4\u6570\u7ec4\u7684\u52a8\u6001\u548c", "title_en": "Running Sum of 1d Array", "question_title_slug": "running-sum-of-1d-array", "content_en": "

    Given an array nums. We define a running sum of an array as runningSum[i] = sum(nums[0]…nums[i]).

    \r\n\r\n

    Return the running sum of nums.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: nums = [1,2,3,4]\r\nOutput: [1,3,6,10]\r\nExplanation: Running sum is obtained as follows: [1, 1+2, 1+2+3, 1+2+3+4].
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: nums = [1,1,1,1,1]\r\nOutput: [1,2,3,4,5]\r\nExplanation: Running sum is obtained as follows: [1, 1+1, 1+1+1, 1+1+1+1, 1+1+1+1+1].
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: nums = [3,1,2,10,1]\r\nOutput: [3,4,6,16,17]\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= nums.length <= 1000
    • \r\n\t
    • -10^6 <= nums[i] <= 10^6
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 nums \u3002\u6570\u7ec4\u300c\u52a8\u6001\u548c\u300d\u7684\u8ba1\u7b97\u516c\u5f0f\u4e3a\uff1arunningSum[i] = sum(nums[0]…nums[i]) \u3002

    \n\n

    \u8bf7\u8fd4\u56de nums \u7684\u52a8\u6001\u548c\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,2,3,4]\n\u8f93\u51fa\uff1a[1,3,6,10]\n\u89e3\u91ca\uff1a\u52a8\u6001\u548c\u8ba1\u7b97\u8fc7\u7a0b\u4e3a [1, 1+2, 1+2+3, 1+2+3+4] \u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,1,1,1,1]\n\u8f93\u51fa\uff1a[1,2,3,4,5]\n\u89e3\u91ca\uff1a\u52a8\u6001\u548c\u8ba1\u7b97\u8fc7\u7a0b\u4e3a [1, 1+1, 1+1+1, 1+1+1+1, 1+1+1+1+1] \u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [3,1,2,10,1]\n\u8f93\u51fa\uff1a[3,4,6,16,17]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 1000
    • \n\t
    • -10^6 <= nums[i] <= 10^6
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector runningSum(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] runningSum(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def runningSum(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def runningSum(self, nums: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* runningSum(int* nums, int numsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] RunningSum(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar runningSum = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer[]}\ndef running_sum(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func runningSum(_ nums: [Int]) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func runningSum(nums []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def runningSum(nums: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun runningSum(nums: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn running_sum(nums: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer[]\n */\n function runningSum($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function runningSum(nums: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (running-sum nums)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1480](https://leetcode-cn.com/problems/running-sum-of-1d-array)", "[\u4e00\u7ef4\u6570\u7ec4\u7684\u52a8\u6001\u548c](/solution/1400-1499/1480.Running%20Sum%20of%201d%20Array/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1480](https://leetcode.com/problems/running-sum-of-1d-array)", "[Running Sum of 1d Array](/solution/1400-1499/1480.Running%20Sum%20of%201d%20Array/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1587", "frontend_question_id": "1494", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/parallel-courses-ii", "url_en": "https://leetcode.com/problems/parallel-courses-ii", "relative_path_cn": "/solution/1400-1499/1494.Parallel%20Courses%20II/README.md", "relative_path_en": "/solution/1400-1499/1494.Parallel%20Courses%20II/README_EN.md", "title_cn": "\u5e76\u884c\u8bfe\u7a0b II", "title_en": "Parallel Courses II", "question_title_slug": "parallel-courses-ii", "content_en": "

    You are given an integer n, which indicates that there are n courses labeled from 1 to n. You are also given an array relations where relations[i] = [prevCoursei, nextCoursei], representing a prerequisite relationship between course prevCoursei and course nextCoursei: course prevCoursei has to be taken before course nextCoursei. Also, you are given the integer k.

    \n\n

    In one semester, you can take at most k courses as long as you have taken all the prerequisites in the previous semester for the courses you are taking.

    \n\n

    Return the minimum number of semesters needed to take all courses. The testcases will be generated such that it is possible to take every course.

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: n = 4, dependencies = [[2,1],[3,1],[1,4]], k = 2\nOutput: 3 \nExplanation: The figure above represents the given graph.\nIn the first semester, you can take courses 2 and 3.\nIn the second semester, you can take course 1.\nIn the third semester, you can take course 4.\n
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: n = 5, dependencies = [[2,1],[3,1],[4,1],[1,5]], k = 2\nOutput: 4 \nExplanation: The figure above represents the given graph.\nIn the first semester, you can take courses 2 and 3 only since you cannot take more than two per semester.\nIn the second semester, you can take course 4.\nIn the third semester, you can take course 1.\nIn the fourth semester, you can take course 5.\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 11, dependencies = [], k = 2\nOutput: 6\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 15
    • \n\t
    • 1 <= k <= n
    • \n\t
    • 0 <= relations.length <= n * (n-1) / 2
    • \n\t
    • relations[i].length == 2
    • \n\t
    • 1 <= prevCoursei, nextCoursei <= n
    • \n\t
    • prevCoursei != nextCoursei
    • \n\t
    • All the pairs [prevCoursei, nextCoursei] are unique.
    • \n\t
    • The given graph is a directed acyclic graph.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n \u8868\u793a\u67d0\u6240\u5927\u5b66\u91cc\u8bfe\u7a0b\u7684\u6570\u76ee\uff0c\u7f16\u53f7\u4e3a 1 \u5230 n \uff0c\u6570\u7ec4 dependencies \u4e2d\uff0c dependencies[i] = [xi, yi]  \u8868\u793a\u4e00\u4e2a\u5148\u4fee\u8bfe\u7684\u5173\u7cfb\uff0c\u4e5f\u5c31\u662f\u8bfe\u7a0b xi \u5fc5\u987b\u5728\u8bfe\u7a0b yi \u4e4b\u524d\u4e0a\u3002\u540c\u65f6\u4f60\u8fd8\u6709\u4e00\u4e2a\u6574\u6570 k \u3002

    \n\n

    \u5728\u4e00\u4e2a\u5b66\u671f\u4e2d\uff0c\u4f60 \u6700\u591a \u53ef\u4ee5\u540c\u65f6\u4e0a k \u95e8\u8bfe\uff0c\u524d\u63d0\u662f\u8fd9\u4e9b\u8bfe\u7684\u5148\u4fee\u8bfe\u5728\u4e4b\u524d\u7684\u5b66\u671f\u91cc\u5df2\u7ecf\u4e0a\u8fc7\u4e86\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u4e0a\u5b8c\u6240\u6709\u8bfe\u6700\u5c11\u9700\u8981\u591a\u5c11\u4e2a\u5b66\u671f\u3002\u9898\u76ee\u4fdd\u8bc1\u4e00\u5b9a\u5b58\u5728\u4e00\u79cd\u4e0a\u5b8c\u6240\u6709\u8bfe\u7684\u65b9\u5f0f\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 4, dependencies = [[2,1],[3,1],[1,4]], k = 2\n\u8f93\u51fa\uff1a3 \n\u89e3\u91ca\uff1a\u4e0a\u56fe\u5c55\u793a\u4e86\u9898\u76ee\u8f93\u5165\u7684\u56fe\u3002\u5728\u7b2c\u4e00\u4e2a\u5b66\u671f\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4e0a\u8bfe\u7a0b 2 \u548c\u8bfe\u7a0b 3 \u3002\u7136\u540e\u7b2c\u4e8c\u4e2a\u5b66\u671f\u4e0a\u8bfe\u7a0b 1 \uff0c\u7b2c\u4e09\u4e2a\u5b66\u671f\u4e0a\u8bfe\u7a0b 4 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 5, dependencies = [[2,1],[3,1],[4,1],[1,5]], k = 2\n\u8f93\u51fa\uff1a4 \n\u89e3\u91ca\uff1a\u4e0a\u56fe\u5c55\u793a\u4e86\u9898\u76ee\u8f93\u5165\u7684\u56fe\u3002\u4e00\u4e2a\u6700\u4f18\u65b9\u6848\u662f\uff1a\u7b2c\u4e00\u5b66\u671f\u4e0a\u8bfe\u7a0b 2 \u548c 3\uff0c\u7b2c\u4e8c\u5b66\u671f\u4e0a\u8bfe\u7a0b 4 \uff0c\u7b2c\u4e09\u5b66\u671f\u4e0a\u8bfe\u7a0b 1 \uff0c\u7b2c\u56db\u5b66\u671f\u4e0a\u8bfe\u7a0b 5 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1an = 11, dependencies = [], k = 2\n\u8f93\u51fa\uff1a6\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 15
    • \n\t
    • 1 <= k <= n
    • \n\t
    • 0 <= dependencies.length <= n * (n-1) / 2
    • \n\t
    • dependencies[i].length == 2
    • \n\t
    • 1 <= xi, yi <= n
    • \n\t
    • xi != yi
    • \n\t
    • \u6240\u6709\u5148\u4fee\u5173\u7cfb\u90fd\u662f\u4e0d\u540c\u7684\uff0c\u4e5f\u5c31\u662f\u8bf4 dependencies[i] != dependencies[j] \u3002
    • \n\t
    • \u9898\u76ee\u8f93\u5165\u7684\u56fe\u662f\u4e2a\u6709\u5411\u65e0\u73af\u56fe\u3002
    • \n
    \n", "tags_en": ["Graph"], "tags_cn": ["\u56fe"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minNumberOfSemesters(int n, vector>& relations, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minNumberOfSemesters(int n, int[][] relations, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minNumberOfSemesters(self, n, relations, k):\n \"\"\"\n :type n: int\n :type relations: List[List[int]]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minNumberOfSemesters(self, n: int, relations: List[List[int]], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minNumberOfSemesters(int n, int** relations, int relationsSize, int* relationsColSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinNumberOfSemesters(int n, int[][] relations, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} relations\n * @param {number} k\n * @return {number}\n */\nvar minNumberOfSemesters = function(n, relations, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} relations\n# @param {Integer} k\n# @return {Integer}\ndef min_number_of_semesters(n, relations, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minNumberOfSemesters(_ n: Int, _ relations: [[Int]], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minNumberOfSemesters(n int, relations [][]int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minNumberOfSemesters(n: Int, relations: Array[Array[Int]], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minNumberOfSemesters(n: Int, relations: Array, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_number_of_semesters(n: i32, relations: Vec>, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $relations\n * @param Integer $k\n * @return Integer\n */\n function minNumberOfSemesters($n, $relations, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minNumberOfSemesters(n: number, relations: number[][], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-number-of-semesters n relations k)\n (-> exact-integer? (listof (listof exact-integer?)) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1494](https://leetcode-cn.com/problems/parallel-courses-ii)", "[\u5e76\u884c\u8bfe\u7a0b II](/solution/1400-1499/1494.Parallel%20Courses%20II/README.md)", "`\u56fe`", "\u56f0\u96be", ""], "md_table_row_en": ["[1494](https://leetcode.com/problems/parallel-courses-ii)", "[Parallel Courses II](/solution/1400-1499/1494.Parallel%20Courses%20II/README_EN.md)", "`Graph`", "Hard", ""]}, {"question_id": "1586", "frontend_question_id": "1493", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-subarray-of-1s-after-deleting-one-element", "url_en": "https://leetcode.com/problems/longest-subarray-of-1s-after-deleting-one-element", "relative_path_cn": "/solution/1400-1499/1493.Longest%20Subarray%20of%201%27s%20After%20Deleting%20One%20Element/README.md", "relative_path_en": "/solution/1400-1499/1493.Longest%20Subarray%20of%201%27s%20After%20Deleting%20One%20Element/README_EN.md", "title_cn": "\u5220\u6389\u4e00\u4e2a\u5143\u7d20\u4ee5\u540e\u5168\u4e3a 1 \u7684\u6700\u957f\u5b50\u6570\u7ec4", "title_en": "Longest Subarray of 1's After Deleting One Element", "question_title_slug": "longest-subarray-of-1s-after-deleting-one-element", "content_en": "

    Given a binary array nums, you should delete one element from it.

    \n\n

    Return the size of the longest non-empty subarray containing only 1's in the resulting array.

    \n\n

    Return 0 if there is no such subarray.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,1,0,1]\nOutput: 3\nExplanation: After deleting the number in position 2, [1,1,1] contains 3 numbers with value of 1's.
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [0,1,1,1,0,1,1,0,1]\nOutput: 5\nExplanation: After deleting the number in position 4, [0,1,1,1,1,1,0,1] longest subarray with value of 1's is [1,1,1,1,1].
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [1,1,1]\nOutput: 2\nExplanation: You must delete one element.
    \n\n

    Example 4:

    \n\n
    \nInput: nums = [1,1,0,0,1,1,1,0,1]\nOutput: 4\n
    \n\n

    Example 5:

    \n\n
    \nInput: nums = [0,0,0]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 10^5
    • \n\t
    • nums[i] is either 0 or 1.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u4e8c\u8fdb\u5236\u6570\u7ec4 nums \uff0c\u4f60\u9700\u8981\u4ece\u4e2d\u5220\u6389\u4e00\u4e2a\u5143\u7d20\u3002

    \n\n

    \u8bf7\u4f60\u5728\u5220\u6389\u5143\u7d20\u7684\u7ed3\u679c\u6570\u7ec4\u4e2d\uff0c\u8fd4\u56de\u6700\u957f\u7684\u4e14\u53ea\u5305\u542b 1 \u7684\u975e\u7a7a\u5b50\u6570\u7ec4\u7684\u957f\u5ea6\u3002

    \n\n

    \u5982\u679c\u4e0d\u5b58\u5728\u8fd9\u6837\u7684\u5b50\u6570\u7ec4\uff0c\u8bf7\u8fd4\u56de 0 \u3002

    \n\n

     

    \n\n

    \u63d0\u793a 1\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,1,0,1]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u5220\u6389\u4f4d\u7f6e 2 \u7684\u6570\u540e\uff0c[1,1,1] \u5305\u542b 3 \u4e2a 1 \u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [0,1,1,1,0,1,1,0,1]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u5220\u6389\u4f4d\u7f6e 4 \u7684\u6570\u5b57\u540e\uff0c[0,1,1,1,1,1,0,1] \u7684\u6700\u957f\u5168 1 \u5b50\u6570\u7ec4\u4e3a [1,1,1,1,1] \u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,1,1]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u4f60\u5fc5\u987b\u8981\u5220\u9664\u4e00\u4e2a\u5143\u7d20\u3002
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,1,0,0,1,1,1,0,1]\n\u8f93\u51fa\uff1a4\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [0,0,0]\n\u8f93\u51fa\uff1a0\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 10^5
    • \n\t
    • nums[i] \u8981\u4e48\u662f 0 \u8981\u4e48\u662f 1 \u3002
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int longestSubarray(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int longestSubarray(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestSubarray(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestSubarray(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint longestSubarray(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LongestSubarray(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar longestSubarray = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef longest_subarray(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestSubarray(_ nums: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestSubarray(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestSubarray(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestSubarray(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_subarray(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function longestSubarray($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestSubarray(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-subarray nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1493](https://leetcode-cn.com/problems/longest-subarray-of-1s-after-deleting-one-element)", "[\u5220\u6389\u4e00\u4e2a\u5143\u7d20\u4ee5\u540e\u5168\u4e3a 1 \u7684\u6700\u957f\u5b50\u6570\u7ec4](/solution/1400-1499/1493.Longest%20Subarray%20of%201%27s%20After%20Deleting%20One%20Element/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1493](https://leetcode.com/problems/longest-subarray-of-1s-after-deleting-one-element)", "[Longest Subarray of 1's After Deleting One Element](/solution/1400-1499/1493.Longest%20Subarray%20of%201%27s%20After%20Deleting%20One%20Element/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "1585", "frontend_question_id": "1492", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/the-kth-factor-of-n", "url_en": "https://leetcode.com/problems/the-kth-factor-of-n", "relative_path_cn": "/solution/1400-1499/1492.The%20kth%20Factor%20of%20n/README.md", "relative_path_en": "/solution/1400-1499/1492.The%20kth%20Factor%20of%20n/README_EN.md", "title_cn": "n \u7684\u7b2c k \u4e2a\u56e0\u5b50", "title_en": "The kth Factor of n", "question_title_slug": "the-kth-factor-of-n", "content_en": "

    Given two positive integers n and k.

    \r\n\r\n

    A factor of an integer n is defined as an integer i where n % i == 0.

    \r\n\r\n

    Consider a list of all factors of n sorted in ascending order, return the kth factor in this list or return -1 if n has less than k factors.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: n = 12, k = 3\r\nOutput: 3\r\nExplanation: Factors list is [1, 2, 3, 4, 6, 12], the 3rd factor is 3.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: n = 7, k = 2\r\nOutput: 7\r\nExplanation: Factors list is [1, 7], the 2nd factor is 7.\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: n = 4, k = 4\r\nOutput: -1\r\nExplanation: Factors list is [1, 2, 4], there is only 3 factors. We should return -1.\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: n = 1, k = 1\r\nOutput: 1\r\nExplanation: Factors list is [1], the 1st factor is 1.\r\n
    \r\n\r\n

    Example 5:

    \r\n\r\n
    \r\nInput: n = 1000, k = 3\r\nOutput: 4\r\nExplanation: Factors list is [1, 2, 4, 5, 8, 10, 20, 25, 40, 50, 100, 125, 200, 250, 500, 1000].\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= k <= n <= 1000
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u6b63\u6574\u6570 n \u548c k \u3002

    \n\n

    \u5982\u679c\u6b63\u6574\u6570 i \u6ee1\u8db3 n % i == 0 \uff0c\u90a3\u4e48\u6211\u4eec\u5c31\u8bf4\u6b63\u6574\u6570 i \u662f\u6574\u6570 n \u7684\u56e0\u5b50\u3002

    \n\n

    \u8003\u8651\u6574\u6570 n \u7684\u6240\u6709\u56e0\u5b50\uff0c\u5c06\u5b83\u4eec \u5347\u5e8f\u6392\u5217 \u3002\u8bf7\u4f60\u8fd4\u56de\u7b2c k \u4e2a\u56e0\u5b50\u3002\u5982\u679c n \u7684\u56e0\u5b50\u6570\u5c11\u4e8e k \uff0c\u8bf7\u4f60\u8fd4\u56de -1 \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1an = 12, k = 3\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u56e0\u5b50\u5217\u8868\u5305\u62ec [1, 2, 3, 4, 6, 12]\uff0c\u7b2c 3 \u4e2a\u56e0\u5b50\u662f 3 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1an = 7, k = 2\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\u56e0\u5b50\u5217\u8868\u5305\u62ec [1, 7] \uff0c\u7b2c 2 \u4e2a\u56e0\u5b50\u662f 7 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1an = 4, k = 4\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u56e0\u5b50\u5217\u8868\u5305\u62ec [1, 2, 4] \uff0c\u53ea\u6709 3 \u4e2a\u56e0\u5b50\uff0c\u6240\u4ee5\u6211\u4eec\u5e94\u8be5\u8fd4\u56de -1 \u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1an = 1, k = 1\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u56e0\u5b50\u5217\u8868\u5305\u62ec [1] \uff0c\u7b2c 1 \u4e2a\u56e0\u5b50\u4e3a 1 \u3002\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1an = 1000, k = 3\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u56e0\u5b50\u5217\u8868\u5305\u62ec [1, 2, 4, 5, 8, 10, 20, 25, 40, 50, 100, 125, 200, 250, 500, 1000] \u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= k <= n <= 1000
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int kthFactor(int n, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int kthFactor(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def kthFactor(self, n, k):\n \"\"\"\n :type n: int\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def kthFactor(self, n: int, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint kthFactor(int n, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int KthFactor(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} k\n * @return {number}\n */\nvar kthFactor = function(n, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} k\n# @return {Integer}\ndef kth_factor(n, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func kthFactor(_ n: Int, _ k: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func kthFactor(n int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def kthFactor(n: Int, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun kthFactor(n: Int, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn kth_factor(n: i32, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $k\n * @return Integer\n */\n function kthFactor($n, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function kthFactor(n: number, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (kth-factor n k)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1492](https://leetcode-cn.com/problems/the-kth-factor-of-n)", "[n \u7684\u7b2c k \u4e2a\u56e0\u5b50](/solution/1400-1499/1492.The%20kth%20Factor%20of%20n/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1492](https://leetcode.com/problems/the-kth-factor-of-n)", "[The kth Factor of n](/solution/1400-1499/1492.The%20kth%20Factor%20of%20n/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "1584", "frontend_question_id": "1491", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/average-salary-excluding-the-minimum-and-maximum-salary", "url_en": "https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary", "relative_path_cn": "/solution/1400-1499/1491.Average%20Salary%20Excluding%20the%20Minimum%20and%20Maximum%20Salary/README.md", "relative_path_en": "/solution/1400-1499/1491.Average%20Salary%20Excluding%20the%20Minimum%20and%20Maximum%20Salary/README_EN.md", "title_cn": "\u53bb\u6389\u6700\u4f4e\u5de5\u8d44\u548c\u6700\u9ad8\u5de5\u8d44\u540e\u7684\u5de5\u8d44\u5e73\u5747\u503c", "title_en": "Average Salary Excluding the Minimum and Maximum Salary", "question_title_slug": "average-salary-excluding-the-minimum-and-maximum-salary", "content_en": "

    Given an array of unique integers salary where salary[i] is the salary of the employee i.

    \r\n\r\n

    Return the average salary of employees excluding the minimum and maximum salary.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: salary = [4000,3000,1000,2000]\r\nOutput: 2500.00000\r\nExplanation: Minimum salary and maximum salary are 1000 and 4000 respectively.\r\nAverage salary excluding minimum and maximum salary is (2000+3000)/2= 2500\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: salary = [1000,2000,3000]\r\nOutput: 2000.00000\r\nExplanation: Minimum salary and maximum salary are 1000 and 3000 respectively.\r\nAverage salary excluding minimum and maximum salary is (2000)/1= 2000\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: salary = [6000,5000,4000,3000,2000,1000]\r\nOutput: 3500.00000\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: salary = [8000,9000,2000,3000,6000,1000]\r\nOutput: 4750.00000\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 3 <= salary.length <= 100
    • \r\n\t
    • 10^3 <= salary[i] <= 10^6
    • \r\n\t
    • salary[i] is unique.
    • \r\n\t
    • Answers within 10^-5 of the actual value will be accepted as correct.
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 salary \uff0c\u6570\u7ec4\u91cc\u6bcf\u4e2a\u6570\u90fd\u662f \u552f\u4e00 \u7684\uff0c\u5176\u4e2d salary[i] \u662f\u7b2c i \u4e2a\u5458\u5de5\u7684\u5de5\u8d44\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u53bb\u6389\u6700\u4f4e\u5de5\u8d44\u548c\u6700\u9ad8\u5de5\u8d44\u4ee5\u540e\uff0c\u5269\u4e0b\u5458\u5de5\u5de5\u8d44\u7684\u5e73\u5747\u503c\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1asalary = [4000,3000,1000,2000]\n\u8f93\u51fa\uff1a2500.00000\n\u89e3\u91ca\uff1a\u6700\u4f4e\u5de5\u8d44\u548c\u6700\u9ad8\u5de5\u8d44\u5206\u522b\u662f 1000 \u548c 4000 \u3002\n\u53bb\u6389\u6700\u4f4e\u5de5\u8d44\u548c\u6700\u9ad8\u5de5\u8d44\u4ee5\u540e\u7684\u5e73\u5747\u5de5\u8d44\u662f (2000+3000)/2= 2500\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1asalary = [1000,2000,3000]\n\u8f93\u51fa\uff1a2000.00000\n\u89e3\u91ca\uff1a\u6700\u4f4e\u5de5\u8d44\u548c\u6700\u9ad8\u5de5\u8d44\u5206\u522b\u662f 1000 \u548c 3000 \u3002\n\u53bb\u6389\u6700\u4f4e\u5de5\u8d44\u548c\u6700\u9ad8\u5de5\u8d44\u4ee5\u540e\u7684\u5e73\u5747\u5de5\u8d44\u662f (2000)/1= 2000\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1asalary = [6000,5000,4000,3000,2000,1000]\n\u8f93\u51fa\uff1a3500.00000\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1asalary = [8000,9000,2000,3000,6000,1000]\n\u8f93\u51fa\uff1a4750.00000\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 3 <= salary.length <= 100
    • \n\t
    • 10^3 <= salary[i] <= 10^6
    • \n\t
    • salary[i] \u662f\u552f\u4e00\u7684\u3002
    • \n\t
    • \u4e0e\u771f\u5b9e\u503c\u8bef\u5dee\u5728 10^-5 \u4ee5\u5185\u7684\u7ed3\u679c\u90fd\u5c06\u89c6\u4e3a\u6b63\u786e\u7b54\u6848\u3002
    • \n
    \n", "tags_en": ["Sort", "Array"], "tags_cn": ["\u6392\u5e8f", "\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n double average(vector& salary) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double average(int[] salary) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def average(self, salary):\n \"\"\"\n :type salary: List[int]\n :rtype: float\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def average(self, salary: List[int]) -> float:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\ndouble average(int* salary, int salarySize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double Average(int[] salary) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} salary\n * @return {number}\n */\nvar average = function(salary) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} salary\n# @return {Float}\ndef average(salary)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func average(_ salary: [Int]) -> Double {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func average(salary []int) float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def average(salary: Array[Int]): Double = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun average(salary: IntArray): Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn average(salary: Vec) -> f64 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $salary\n * @return Float\n */\n function average($salary) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function average(salary: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (average salary)\n (-> (listof exact-integer?) flonum?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1491](https://leetcode-cn.com/problems/average-salary-excluding-the-minimum-and-maximum-salary)", "[\u53bb\u6389\u6700\u4f4e\u5de5\u8d44\u548c\u6700\u9ad8\u5de5\u8d44\u540e\u7684\u5de5\u8d44\u5e73\u5747\u503c](/solution/1400-1499/1491.Average%20Salary%20Excluding%20the%20Minimum%20and%20Maximum%20Salary/README.md)", "`\u6392\u5e8f`,`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1491](https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary)", "[Average Salary Excluding the Minimum and Maximum Salary](/solution/1400-1499/1491.Average%20Salary%20Excluding%20the%20Minimum%20and%20Maximum%20Salary/README_EN.md)", "`Sort`,`Array`", "Easy", ""]}, {"question_id": "1583", "frontend_question_id": "1473", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/paint-house-iii", "url_en": "https://leetcode.com/problems/paint-house-iii", "relative_path_cn": "/solution/1400-1499/1473.Paint%20House%20III/README.md", "relative_path_en": "/solution/1400-1499/1473.Paint%20House%20III/README_EN.md", "title_cn": "\u7c89\u5237\u623f\u5b50 III", "title_en": "Paint House III", "question_title_slug": "paint-house-iii", "content_en": "

    There is a row of m houses in a small city, each house must be painted with one of the n colors (labeled from 1 to n), some houses that have been painted last summer should not be painted again.

    \n\n

    A neighborhood is a maximal group of continuous houses that are painted with the same color.

    \n\n
      \n\t
    • For example: houses = [1,2,2,3,3,2,1,1] contains 5 neighborhoods [{1}, {2,2}, {3,3}, {2}, {1,1}].
    • \n
    \n\n

    Given an array houses, an m x n matrix cost and an integer target where:

    \n\n
      \n\t
    • houses[i]: is the color of the house i, and 0 if the house is not painted yet.
    • \n\t
    • cost[i][j]: is the cost of paint the house i with the color j + 1.
    • \n
    \n\n

    Return the minimum cost of painting all the remaining houses in such a way that there are exactly target neighborhoods. If it is not possible, return -1.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: houses = [0,0,0,0,0], cost = [[1,10],[10,1],[10,1],[1,10],[5,1]], m = 5, n = 2, target = 3\nOutput: 9\nExplanation: Paint houses of this way [1,2,2,1,1]\nThis array contains target = 3 neighborhoods, [{1}, {2,2}, {1,1}].\nCost of paint all houses (1 + 1 + 1 + 1 + 5) = 9.\n
    \n\n

    Example 2:

    \n\n
    \nInput: houses = [0,2,1,2,0], cost = [[1,10],[10,1],[10,1],[1,10],[5,1]], m = 5, n = 2, target = 3\nOutput: 11\nExplanation: Some houses are already painted, Paint the houses of this way [2,2,1,2,2]\nThis array contains target = 3 neighborhoods, [{2,2}, {1}, {2,2}]. \nCost of paint the first and last house (10 + 1) = 11.\n
    \n\n

    Example 3:

    \n\n
    \nInput: houses = [0,0,0,0,0], cost = [[1,10],[10,1],[1,10],[10,1],[1,10]], m = 5, n = 2, target = 5\nOutput: 5\n
    \n\n

    Example 4:

    \n\n
    \nInput: houses = [3,1,2,3], cost = [[1,1,1],[1,1,1],[1,1,1],[1,1,1]], m = 4, n = 3, target = 3\nOutput: -1\nExplanation: Houses are already painted with a total of 4 neighborhoods [{3},{1},{2},{3}] different of target = 3.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == houses.length == cost.length
    • \n\t
    • n == cost[i].length
    • \n\t
    • 1 <= m <= 100
    • \n\t
    • 1 <= n <= 20
    • \n\t
    • 1 <= target <= m
    • \n\t
    • 0 <= houses[i] <= n
    • \n\t
    • 1 <= cost[i][j] <= 10^4
    • \n
    \n", "content_cn": "

    \u5728\u4e00\u4e2a\u5c0f\u57ce\u5e02\u91cc\uff0c\u6709\u00a0m\u00a0\u4e2a\u623f\u5b50\u6392\u6210\u4e00\u6392\uff0c\u4f60\u9700\u8981\u7ed9\u6bcf\u4e2a\u623f\u5b50\u6d82\u4e0a n\u00a0\u79cd\u989c\u8272\u4e4b\u4e00\uff08\u989c\u8272\u7f16\u53f7\u4e3a 1 \u5230 n\u00a0\uff09\u3002\u6709\u7684\u623f\u5b50\u53bb\u5e74\u590f\u5929\u5df2\u7ecf\u6d82\u8fc7\u989c\u8272\u4e86\uff0c\u6240\u4ee5\u8fd9\u4e9b\u623f\u5b50\u4e0d\u53ef\u4ee5\u88ab\u91cd\u65b0\u6d82\u8272\u3002

    \n\n

    \u6211\u4eec\u5c06\u8fde\u7eed\u76f8\u540c\u989c\u8272\u5c3d\u53ef\u80fd\u591a\u7684\u623f\u5b50\u79f0\u4e3a\u4e00\u4e2a\u8857\u533a\u3002\uff08\u6bd4\u65b9\u8bf4 houses = [1,2,2,3,3,2,1,1] \uff0c\u5b83\u5305\u542b 5 \u4e2a\u8857\u533a\u00a0 [{1}, {2,2}, {3,3}, {2}, {1,1}] \u3002\uff09

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4\u00a0houses\u00a0\uff0c\u4e00\u4e2a\u00a0m * n\u00a0\u7684\u77e9\u9635\u00a0cost\u00a0\u548c\u4e00\u4e2a\u6574\u6570\u00a0target\u00a0\uff0c\u5176\u4e2d\uff1a

    \n\n
      \n\t
    • houses[i]\uff1a\u662f\u7b2c\u00a0i\u00a0\u4e2a\u623f\u5b50\u7684\u989c\u8272\uff0c0\u00a0\u8868\u793a\u8fd9\u4e2a\u623f\u5b50\u8fd8\u6ca1\u6709\u88ab\u6d82\u8272\u3002
    • \n\t
    • cost[i][j]\uff1a\u662f\u5c06\u7b2c\u00a0i\u00a0\u4e2a\u623f\u5b50\u6d82\u6210\u989c\u8272\u00a0j+1\u00a0\u7684\u82b1\u8d39\u3002
    • \n
    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u623f\u5b50\u6d82\u8272\u65b9\u6848\u7684\u6700\u5c0f\u603b\u82b1\u8d39\uff0c\u4f7f\u5f97\u6bcf\u4e2a\u623f\u5b50\u90fd\u88ab\u6d82\u8272\u540e\uff0c\u6070\u597d\u7ec4\u6210\u00a0target\u00a0\u4e2a\u8857\u533a\u3002\u5982\u679c\u6ca1\u6709\u53ef\u7528\u7684\u6d82\u8272\u65b9\u6848\uff0c\u8bf7\u8fd4\u56de\u00a0-1\u00a0\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahouses = [0,0,0,0,0], cost = [[1,10],[10,1],[10,1],[1,10],[5,1]], m = 5, n = 2, target = 3\n\u8f93\u51fa\uff1a9\n\u89e3\u91ca\uff1a\u623f\u5b50\u6d82\u8272\u65b9\u6848\u4e3a [1,2,2,1,1]\n\u6b64\u65b9\u6848\u5305\u542b target = 3 \u4e2a\u8857\u533a\uff0c\u5206\u522b\u662f [{1}, {2,2}, {1,1}]\u3002\n\u6d82\u8272\u7684\u603b\u82b1\u8d39\u4e3a (1 + 1 + 1 + 1 + 5) = 9\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahouses = [0,2,1,2,0], cost = [[1,10],[10,1],[10,1],[1,10],[5,1]], m = 5, n = 2, target = 3\n\u8f93\u51fa\uff1a11\n\u89e3\u91ca\uff1a\u6709\u7684\u623f\u5b50\u5df2\u7ecf\u88ab\u6d82\u8272\u4e86\uff0c\u5728\u6b64\u57fa\u7840\u4e0a\u6d82\u8272\u65b9\u6848\u4e3a [2,2,1,2,2]\n\u6b64\u65b9\u6848\u5305\u542b target = 3 \u4e2a\u8857\u533a\uff0c\u5206\u522b\u662f [{2,2}, {1}, {2,2}]\u3002\n\u7ed9\u7b2c\u4e00\u4e2a\u548c\u6700\u540e\u4e00\u4e2a\u623f\u5b50\u6d82\u8272\u7684\u82b1\u8d39\u4e3a (10 + 1) = 11\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahouses = [0,0,0,0,0], cost = [[1,10],[10,1],[1,10],[10,1],[1,10]], m = 5, n = 2, target = 5\n\u8f93\u51fa\uff1a5\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahouses = [3,1,2,3], cost = [[1,1,1],[1,1,1],[1,1,1],[1,1,1]], m = 4, n = 3, target = 3\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u623f\u5b50\u5df2\u7ecf\u88ab\u6d82\u8272\u5e76\u7ec4\u6210\u4e86 4 \u4e2a\u8857\u533a\uff0c\u5206\u522b\u662f [{3},{1},{2},{3}] \uff0c\u65e0\u6cd5\u5f62\u6210 target = 3 \u4e2a\u8857\u533a\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == houses.length == cost.length
    • \n\t
    • n == cost[i].length
    • \n\t
    • 1 <= m <= 100
    • \n\t
    • 1 <= n <= 20
    • \n\t
    • 1 <= target\u00a0<= m
    • \n\t
    • 0 <= houses[i]\u00a0<= n
    • \n\t
    • 1 <= cost[i][j] <= 10^4
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minCost(vector& houses, vector>& cost, int m, int n, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minCost(int[] houses, int[][] cost, int m, int n, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minCost(self, houses, cost, m, n, target):\n \"\"\"\n :type houses: List[int]\n :type cost: List[List[int]]\n :type m: int\n :type n: int\n :type target: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minCost(self, houses: List[int], cost: List[List[int]], m: int, n: int, target: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minCost(int* houses, int housesSize, int** cost, int costSize, int* costColSize, int m, int n, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinCost(int[] houses, int[][] cost, int m, int n, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} houses\n * @param {number[][]} cost\n * @param {number} m\n * @param {number} n\n * @param {number} target\n * @return {number}\n */\nvar minCost = function(houses, cost, m, n, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} houses\n# @param {Integer[][]} cost\n# @param {Integer} m\n# @param {Integer} n\n# @param {Integer} target\n# @return {Integer}\ndef min_cost(houses, cost, m, n, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minCost(_ houses: [Int], _ cost: [[Int]], _ m: Int, _ n: Int, _ target: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minCost(houses []int, cost [][]int, m int, n int, target int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minCost(houses: Array[Int], cost: Array[Array[Int]], m: Int, n: Int, target: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minCost(houses: IntArray, cost: Array, m: Int, n: Int, target: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_cost(houses: Vec, cost: Vec>, m: i32, n: i32, target: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $houses\n * @param Integer[][] $cost\n * @param Integer $m\n * @param Integer $n\n * @param Integer $target\n * @return Integer\n */\n function minCost($houses, $cost, $m, $n, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minCost(houses: number[], cost: number[][], m: number, n: number, target: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-cost houses cost m n target)\n (-> (listof exact-integer?) (listof (listof exact-integer?)) exact-integer? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1473](https://leetcode-cn.com/problems/paint-house-iii)", "[\u7c89\u5237\u623f\u5b50 III](/solution/1400-1499/1473.Paint%20House%20III/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1473](https://leetcode.com/problems/paint-house-iii)", "[Paint House III](/solution/1400-1499/1473.Paint%20House%20III/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1582", "frontend_question_id": "1472", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/design-browser-history", "url_en": "https://leetcode.com/problems/design-browser-history", "relative_path_cn": "/solution/1400-1499/1472.Design%20Browser%20History/README.md", "relative_path_en": "/solution/1400-1499/1472.Design%20Browser%20History/README_EN.md", "title_cn": "\u8bbe\u8ba1\u6d4f\u89c8\u5668\u5386\u53f2\u8bb0\u5f55", "title_en": "Design Browser History", "question_title_slug": "design-browser-history", "content_en": "

    You have a browser of one tab where you start on the homepage and you can visit another url, get back in the history number of steps or move forward in the history number of steps.

    \n\n

    Implement the BrowserHistory class:

    \n\n
      \n\t
    • BrowserHistory(string homepage) Initializes the object with the homepage of the browser.
    • \n\t
    • void visit(string url) Visits url from the current page. It clears up all the forward history.
    • \n\t
    • string back(int steps) Move steps back in history. If you can only return x steps in the history and steps > x, you will return only x steps. Return the current url after moving back in history at most steps.
    • \n\t
    • string forward(int steps) Move steps forward in history. If you can only forward x steps in the history and steps > x, you will forward only x steps. Return the current url after forwarding in history at most steps.
    • \n
    \n\n

     

    \n

    Example:

    \n\n
    \nInput:\n["BrowserHistory","visit","visit","visit","back","back","forward","visit","forward","back","back"]\n[["leetcode.com"],["google.com"],["facebook.com"],["youtube.com"],[1],[1],[1],["linkedin.com"],[2],[2],[7]]\nOutput:\n[null,null,null,null,"facebook.com","google.com","facebook.com",null,"linkedin.com","google.com","leetcode.com"]\n\nExplanation:\nBrowserHistory browserHistory = new BrowserHistory("leetcode.com");\nbrowserHistory.visit("google.com");       // You are in "leetcode.com". Visit "google.com"\nbrowserHistory.visit("facebook.com");     // You are in "google.com". Visit "facebook.com"\nbrowserHistory.visit("youtube.com");      // You are in "facebook.com". Visit "youtube.com"\nbrowserHistory.back(1);                   // You are in "youtube.com", move back to "facebook.com" return "facebook.com"\nbrowserHistory.back(1);                   // You are in "facebook.com", move back to "google.com" return "google.com"\nbrowserHistory.forward(1);                // You are in "google.com", move forward to "facebook.com" return "facebook.com"\nbrowserHistory.visit("linkedin.com");     // You are in "facebook.com". Visit "linkedin.com"\nbrowserHistory.forward(2);                // You are in "linkedin.com", you cannot move forward any steps.\nbrowserHistory.back(2);                   // You are in "linkedin.com", move back two steps to "facebook.com" then to "google.com". return "google.com"\nbrowserHistory.back(7);                   // You are in "google.com", you can move back only one step to "leetcode.com". return "leetcode.com"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= homepage.length <= 20
    • \n\t
    • 1 <= url.length <= 20
    • \n\t
    • 1 <= steps <= 100
    • \n\t
    • homepage and url consist of  '.' or lower case English letters.
    • \n\t
    • At most 5000 calls will be made to visit, back, and forward.
    • \n
    \n", "content_cn": "

    \u4f60\u6709\u4e00\u4e2a\u53ea\u652f\u6301\u5355\u4e2a\u6807\u7b7e\u9875\u7684 \u6d4f\u89c8\u5668 \uff0c\u6700\u5f00\u59cb\u4f60\u6d4f\u89c8\u7684\u7f51\u9875\u662f homepage \uff0c\u4f60\u53ef\u4ee5\u8bbf\u95ee\u5176\u4ed6\u7684\u7f51\u7ad9 url \uff0c\u4e5f\u53ef\u4ee5\u5728\u6d4f\u89c8\u5386\u53f2\u4e2d\u540e\u9000 steps \u6b65\u6216\u524d\u8fdb steps \u6b65\u3002

    \n\n

    \u8bf7\u4f60\u5b9e\u73b0 BrowserHistory \u7c7b\uff1a

    \n\n
      \n\t
    • BrowserHistory(string homepage) \uff0c\u7528 homepage \u521d\u59cb\u5316\u6d4f\u89c8\u5668\u7c7b\u3002
    • \n\t
    • void visit(string url) \u4ece\u5f53\u524d\u9875\u8df3\u8f6c\u8bbf\u95ee url \u5bf9\u5e94\u7684\u9875\u9762  \u3002\u6267\u884c\u6b64\u64cd\u4f5c\u4f1a\u628a\u6d4f\u89c8\u5386\u53f2\u524d\u8fdb\u7684\u8bb0\u5f55\u5168\u90e8\u5220\u9664\u3002
    • \n\t
    • string back(int steps) \u5728\u6d4f\u89c8\u5386\u53f2\u4e2d\u540e\u9000 steps \u6b65\u3002\u5982\u679c\u4f60\u53ea\u80fd\u5728\u6d4f\u89c8\u5386\u53f2\u4e2d\u540e\u9000\u81f3\u591a x \u6b65\u4e14 steps > x \uff0c\u90a3\u4e48\u4f60\u53ea\u540e\u9000 x \u6b65\u3002\u8bf7\u8fd4\u56de\u540e\u9000 \u81f3\u591a steps \u6b65\u4ee5\u540e\u7684 url \u3002
    • \n\t
    • string forward(int steps) \u5728\u6d4f\u89c8\u5386\u53f2\u4e2d\u524d\u8fdb steps \u6b65\u3002\u5982\u679c\u4f60\u53ea\u80fd\u5728\u6d4f\u89c8\u5386\u53f2\u4e2d\u524d\u8fdb\u81f3\u591a x \u6b65\u4e14 steps > x \uff0c\u90a3\u4e48\u4f60\u53ea\u524d\u8fdb x \u6b65\u3002\u8bf7\u8fd4\u56de\u524d\u8fdb \u81f3\u591a steps\u6b65\u4ee5\u540e\u7684 url \u3002
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1a\n["BrowserHistory","visit","visit","visit","back","back","forward","visit","forward","back","back"]\n[["leetcode.com"],["google.com"],["facebook.com"],["youtube.com"],[1],[1],[1],["linkedin.com"],[2],[2],[7]]\n\u8f93\u51fa\uff1a\n[null,null,null,null,"facebook.com","google.com","facebook.com",null,"linkedin.com","google.com","leetcode.com"]\n\n\u89e3\u91ca\uff1a\nBrowserHistory browserHistory = new BrowserHistory("leetcode.com");\nbrowserHistory.visit("google.com");       // \u4f60\u539f\u672c\u5728\u6d4f\u89c8 "leetcode.com" \u3002\u8bbf\u95ee "google.com"\nbrowserHistory.visit("facebook.com");     // \u4f60\u539f\u672c\u5728\u6d4f\u89c8 "google.com" \u3002\u8bbf\u95ee "facebook.com"\nbrowserHistory.visit("youtube.com");      // \u4f60\u539f\u672c\u5728\u6d4f\u89c8 "facebook.com" \u3002\u8bbf\u95ee "youtube.com"\nbrowserHistory.back(1);                   // \u4f60\u539f\u672c\u5728\u6d4f\u89c8 "youtube.com" \uff0c\u540e\u9000\u5230 "facebook.com" \u5e76\u8fd4\u56de "facebook.com"\nbrowserHistory.back(1);                   // \u4f60\u539f\u672c\u5728\u6d4f\u89c8 "facebook.com" \uff0c\u540e\u9000\u5230 "google.com" \u5e76\u8fd4\u56de "google.com"\nbrowserHistory.forward(1);                // \u4f60\u539f\u672c\u5728\u6d4f\u89c8 "google.com" \uff0c\u524d\u8fdb\u5230 "facebook.com" \u5e76\u8fd4\u56de "facebook.com"\nbrowserHistory.visit("linkedin.com");     // \u4f60\u539f\u672c\u5728\u6d4f\u89c8 "facebook.com" \u3002 \u8bbf\u95ee "linkedin.com"\nbrowserHistory.forward(2);                // \u4f60\u539f\u672c\u5728\u6d4f\u89c8 "linkedin.com" \uff0c\u4f60\u65e0\u6cd5\u524d\u8fdb\u4efb\u4f55\u6b65\u6570\u3002\nbrowserHistory.back(2);                   // \u4f60\u539f\u672c\u5728\u6d4f\u89c8 "linkedin.com" \uff0c\u540e\u9000\u4e24\u6b65\u4f9d\u6b21\u5148\u5230 "facebook.com" \uff0c\u7136\u540e\u5230 "google.com" \uff0c\u5e76\u8fd4\u56de "google.com"\nbrowserHistory.back(7);                   // \u4f60\u539f\u672c\u5728\u6d4f\u89c8 "google.com"\uff0c \u4f60\u53ea\u80fd\u540e\u9000\u4e00\u6b65\u5230 "leetcode.com" \uff0c\u5e76\u8fd4\u56de "leetcode.com"\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= homepage.length <= 20
    • \n\t
    • 1 <= url.length <= 20
    • \n\t
    • 1 <= steps <= 100
    • \n\t
    • homepage \u548c url \u90fd\u53ea\u5305\u542b '.' \u6216\u8005\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    • \n\t
    • \u6700\u591a\u8c03\u7528 5000 \u6b21 visit\uff0c back \u548c forward \u51fd\u6570\u3002
    • \n
    \n", "tags_en": ["Design"], "tags_cn": ["\u8bbe\u8ba1"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class BrowserHistory {\npublic:\n BrowserHistory(string homepage) {\n\n }\n \n void visit(string url) {\n\n }\n \n string back(int steps) {\n\n }\n \n string forward(int steps) {\n\n }\n};\n\n/**\n * Your BrowserHistory object will be instantiated and called as such:\n * BrowserHistory* obj = new BrowserHistory(homepage);\n * obj->visit(url);\n * string param_2 = obj->back(steps);\n * string param_3 = obj->forward(steps);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class BrowserHistory {\n\n public BrowserHistory(String homepage) {\n\n }\n \n public void visit(String url) {\n\n }\n \n public String back(int steps) {\n\n }\n \n public String forward(int steps) {\n\n }\n}\n\n/**\n * Your BrowserHistory object will be instantiated and called as such:\n * BrowserHistory obj = new BrowserHistory(homepage);\n * obj.visit(url);\n * String param_2 = obj.back(steps);\n * String param_3 = obj.forward(steps);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class BrowserHistory(object):\n\n def __init__(self, homepage):\n \"\"\"\n :type homepage: str\n \"\"\"\n\n\n def visit(self, url):\n \"\"\"\n :type url: str\n :rtype: None\n \"\"\"\n\n\n def back(self, steps):\n \"\"\"\n :type steps: int\n :rtype: str\n \"\"\"\n\n\n def forward(self, steps):\n \"\"\"\n :type steps: int\n :rtype: str\n \"\"\"\n\n\n\n# Your BrowserHistory object will be instantiated and called as such:\n# obj = BrowserHistory(homepage)\n# obj.visit(url)\n# param_2 = obj.back(steps)\n# param_3 = obj.forward(steps)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class BrowserHistory:\n\n def __init__(self, homepage: str):\n\n\n def visit(self, url: str) -> None:\n\n\n def back(self, steps: int) -> str:\n\n\n def forward(self, steps: int) -> str:\n\n\n\n# Your BrowserHistory object will be instantiated and called as such:\n# obj = BrowserHistory(homepage)\n# obj.visit(url)\n# param_2 = obj.back(steps)\n# param_3 = obj.forward(steps)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} BrowserHistory;\n\n\nBrowserHistory* browserHistoryCreate(char * homepage) {\n \n}\n\nvoid browserHistoryVisit(BrowserHistory* obj, char * url) {\n \n}\n\nchar * browserHistoryBack(BrowserHistory* obj, int steps) {\n \n}\n\nchar * browserHistoryForward(BrowserHistory* obj, int steps) {\n \n}\n\nvoid browserHistoryFree(BrowserHistory* obj) {\n \n}\n\n/**\n * Your BrowserHistory struct will be instantiated and called as such:\n * BrowserHistory* obj = browserHistoryCreate(homepage);\n * browserHistoryVisit(obj, url);\n \n * char * param_2 = browserHistoryBack(obj, steps);\n \n * char * param_3 = browserHistoryForward(obj, steps);\n \n * browserHistoryFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class BrowserHistory {\n\n public BrowserHistory(string homepage) {\n\n }\n \n public void Visit(string url) {\n\n }\n \n public string Back(int steps) {\n\n }\n \n public string Forward(int steps) {\n\n }\n}\n\n/**\n * Your BrowserHistory object will be instantiated and called as such:\n * BrowserHistory obj = new BrowserHistory(homepage);\n * obj.Visit(url);\n * string param_2 = obj.Back(steps);\n * string param_3 = obj.Forward(steps);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} homepage\n */\nvar BrowserHistory = function(homepage) {\n\n};\n\n/** \n * @param {string} url\n * @return {void}\n */\nBrowserHistory.prototype.visit = function(url) {\n\n};\n\n/** \n * @param {number} steps\n * @return {string}\n */\nBrowserHistory.prototype.back = function(steps) {\n\n};\n\n/** \n * @param {number} steps\n * @return {string}\n */\nBrowserHistory.prototype.forward = function(steps) {\n\n};\n\n/**\n * Your BrowserHistory object will be instantiated and called as such:\n * var obj = new BrowserHistory(homepage)\n * obj.visit(url)\n * var param_2 = obj.back(steps)\n * var param_3 = obj.forward(steps)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class BrowserHistory\n\n=begin\n :type homepage: String\n=end\n def initialize(homepage)\n\n end\n\n\n=begin\n :type url: String\n :rtype: Void\n=end\n def visit(url)\n\n end\n\n\n=begin\n :type steps: Integer\n :rtype: String\n=end\n def back(steps)\n\n end\n\n\n=begin\n :type steps: Integer\n :rtype: String\n=end\n def forward(steps)\n\n end\n\n\nend\n\n# Your BrowserHistory object will be instantiated and called as such:\n# obj = BrowserHistory.new(homepage)\n# obj.visit(url)\n# param_2 = obj.back(steps)\n# param_3 = obj.forward(steps)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass BrowserHistory {\n\n init(_ homepage: String) {\n \n }\n \n func visit(_ url: String) {\n \n }\n \n func back(_ steps: Int) -> String {\n \n }\n \n func forward(_ steps: Int) -> String {\n \n }\n}\n\n/**\n * Your BrowserHistory object will be instantiated and called as such:\n * let obj = BrowserHistory(homepage)\n * obj.visit(url)\n * let ret_2: String = obj.back(steps)\n * let ret_3: String = obj.forward(steps)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type BrowserHistory struct {\n\n}\n\n\nfunc Constructor(homepage string) BrowserHistory {\n\n}\n\n\nfunc (this *BrowserHistory) Visit(url string) {\n\n}\n\n\nfunc (this *BrowserHistory) Back(steps int) string {\n\n}\n\n\nfunc (this *BrowserHistory) Forward(steps int) string {\n\n}\n\n\n/**\n * Your BrowserHistory object will be instantiated and called as such:\n * obj := Constructor(homepage);\n * obj.Visit(url);\n * param_2 := obj.Back(steps);\n * param_3 := obj.Forward(steps);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class BrowserHistory(_homepage: String) {\n\n def visit(url: String) {\n\n }\n\n def back(steps: Int): String = {\n\n }\n\n def forward(steps: Int): String = {\n\n }\n\n}\n\n/**\n * Your BrowserHistory object will be instantiated and called as such:\n * var obj = new BrowserHistory(homepage)\n * obj.visit(url)\n * var param_2 = obj.back(steps)\n * var param_3 = obj.forward(steps)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class BrowserHistory(homepage: String) {\n\n fun visit(url: String) {\n\n }\n\n fun back(steps: Int): String {\n\n }\n\n fun forward(steps: Int): String {\n\n }\n\n}\n\n/**\n * Your BrowserHistory object will be instantiated and called as such:\n * var obj = BrowserHistory(homepage)\n * obj.visit(url)\n * var param_2 = obj.back(steps)\n * var param_3 = obj.forward(steps)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct BrowserHistory {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl BrowserHistory {\n\n fn new(homepage: String) -> Self {\n\n }\n \n fn visit(&self, url: String) {\n\n }\n \n fn back(&self, steps: i32) -> String {\n\n }\n \n fn forward(&self, steps: i32) -> String {\n\n }\n}\n\n/**\n * Your BrowserHistory object will be instantiated and called as such:\n * let obj = BrowserHistory::new(homepage);\n * obj.visit(url);\n * let ret_2: String = obj.back(steps);\n * let ret_3: String = obj.forward(steps);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class BrowserHistory {\n /**\n * @param String $homepage\n */\n function __construct($homepage) {\n \n }\n \n /**\n * @param String $url\n * @return NULL\n */\n function visit($url) {\n \n }\n \n /**\n * @param Integer $steps\n * @return String\n */\n function back($steps) {\n \n }\n \n /**\n * @param Integer $steps\n * @return String\n */\n function forward($steps) {\n \n }\n}\n\n/**\n * Your BrowserHistory object will be instantiated and called as such:\n * $obj = BrowserHistory($homepage);\n * $obj->visit($url);\n * $ret_2 = $obj->back($steps);\n * $ret_3 = $obj->forward($steps);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class BrowserHistory {\n constructor(homepage: string) {\n\n }\n\n visit(url: string): void {\n\n }\n\n back(steps: number): string {\n\n }\n\n forward(steps: number): string {\n\n }\n}\n\n/**\n * Your BrowserHistory object will be instantiated and called as such:\n * var obj = new BrowserHistory(homepage)\n * obj.visit(url)\n * var param_2 = obj.back(steps)\n * var param_3 = obj.forward(steps)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define browser-history%\n (class object%\n (super-new)\n\n ; homepage : string?\n (init-field\n homepage)\n \n ; visit : string? -> void?\n (define/public (visit url)\n\n )\n ; back : exact-integer? -> string?\n (define/public (back steps)\n\n )\n ; forward : exact-integer? -> string?\n (define/public (forward steps)\n\n )))\n\n;; Your browser-history% object will be instantiated and called as such:\n;; (define obj (new browser-history% [homepage homepage]))\n;; (send obj visit url)\n;; (define param_2 (send obj back steps))\n;; (define param_3 (send obj forward steps))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1472](https://leetcode-cn.com/problems/design-browser-history)", "[\u8bbe\u8ba1\u6d4f\u89c8\u5668\u5386\u53f2\u8bb0\u5f55](/solution/1400-1499/1472.Design%20Browser%20History/README.md)", "`\u8bbe\u8ba1`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1472](https://leetcode.com/problems/design-browser-history)", "[Design Browser History](/solution/1400-1499/1472.Design%20Browser%20History/README_EN.md)", "`Design`", "Medium", ""]}, {"question_id": "1581", "frontend_question_id": "1471", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/the-k-strongest-values-in-an-array", "url_en": "https://leetcode.com/problems/the-k-strongest-values-in-an-array", "relative_path_cn": "/solution/1400-1499/1471.The%20k%20Strongest%20Values%20in%20an%20Array/README.md", "relative_path_en": "/solution/1400-1499/1471.The%20k%20Strongest%20Values%20in%20an%20Array/README_EN.md", "title_cn": "\u6570\u7ec4\u4e2d\u7684 k \u4e2a\u6700\u5f3a\u503c", "title_en": "The k Strongest Values in an Array", "question_title_slug": "the-k-strongest-values-in-an-array", "content_en": "

    Given an array of integers arr and an integer k.

    \r\n\r\n

    A value arr[i] is said to be stronger than a value arr[j] if |arr[i] - m| > |arr[j] - m| where m is the median of the array.
    \r\nIf |arr[i] - m| == |arr[j] - m|, then arr[i] is said to be stronger than arr[j] if arr[i] > arr[j].

    \r\n\r\n

    Return a list of the strongest k values in the array. return the answer in any arbitrary order.

    \r\n\r\n

    Median is the middle value in an ordered integer list. More formally, if the length of the list is n, the median is the element in position ((n - 1) / 2) in the sorted list (0-indexed).

    \r\n\r\n
      \r\n\t
    • For arr = [6, -3, 7, 2, 11]n = 5 and the median is obtained by sorting the array arr = [-3, 2, 6, 7, 11] and the median is arr[m] where m = ((5 - 1) / 2) = 2. The median is 6.
    • \r\n\t
    • For arr = [-7, 22, 17, 3]n = 4 and the median is obtained by sorting the array arr = [-7, 3, 17, 22] and the median is arr[m] where m = ((4 - 1) / 2) = 1. The median is 3.
    • \r\n
    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: arr = [1,2,3,4,5], k = 2\r\nOutput: [5,1]\r\nExplanation: Median is 3, the elements of the array sorted by the strongest are [5,1,4,2,3]. The strongest 2 elements are [5, 1]. [1, 5] is also accepted answer.\r\nPlease note that although |5 - 3| == |1 - 3| but 5 is stronger than 1 because 5 > 1.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: arr = [1,1,3,5,5], k = 2\r\nOutput: [5,5]\r\nExplanation: Median is 3, the elements of the array sorted by the strongest are [5,5,1,1,3]. The strongest 2 elements are [5, 5].\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: arr = [6,7,11,7,6,8], k = 5\r\nOutput: [11,8,6,6,7]\r\nExplanation: Median is 7, the elements of the array sorted by the strongest are [11,8,6,6,7,7].\r\nAny permutation of [11,8,6,6,7] is accepted.\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: arr = [6,-3,7,2,11], k = 3\r\nOutput: [-3,11,2]\r\n
    \r\n\r\n

    Example 5:

    \r\n\r\n
    \r\nInput: arr = [-7,22,17,3], k = 2\r\nOutput: [22,17]\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= arr.length <= 10^5
    • \r\n\t
    • -10^5 <= arr[i] <= 10^5
    • \r\n\t
    • 1 <= k <= arr.length
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr \u548c\u4e00\u4e2a\u6574\u6570 k \u3002

    \n\n

    \u8bbe m \u4e3a\u6570\u7ec4\u7684\u4e2d\u4f4d\u6570\uff0c\u53ea\u8981\u6ee1\u8db3\u4e0b\u8ff0\u4e24\u4e2a\u524d\u63d0\u4e4b\u4e00\uff0c\u5c31\u53ef\u4ee5\u5224\u5b9a arr[i] \u7684\u503c\u6bd4 arr[j] \u7684\u503c\u66f4\u5f3a\uff1a

    \n\n
      \n\t
    •  |arr[i] - m| > |arr[j] - m|
    • \n\t
    •  |arr[i] - m| == |arr[j] - m|\uff0c\u4e14 arr[i] > arr[j]
    • \n
    \n\n

    \u8bf7\u8fd4\u56de\u7531\u6570\u7ec4\u4e2d\u6700\u5f3a\u7684 k \u4e2a\u503c\u7ec4\u6210\u7684\u5217\u8868\u3002\u7b54\u6848\u53ef\u4ee5\u4ee5 \u4efb\u610f\u987a\u5e8f \u8fd4\u56de\u3002

    \n\n

    \u4e2d\u4f4d\u6570 \u662f\u4e00\u4e2a\u6709\u5e8f\u6574\u6570\u5217\u8868\u4e2d\u5904\u4e8e\u4e2d\u95f4\u4f4d\u7f6e\u7684\u503c\u3002\u5f62\u5f0f\u4e0a\uff0c\u5982\u679c\u5217\u8868\u7684\u957f\u5ea6\u4e3a n \uff0c\u90a3\u4e48\u4e2d\u4f4d\u6570\u5c31\u662f\u8be5\u6709\u5e8f\u5217\u8868\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\u4e2d\u4f4d\u4e8e ((n - 1) / 2) \u7684\u5143\u7d20\u3002

    \n\n
      \n\t
    • \u4f8b\u5982 arr = [6, -3, 7, 2, 11]\uff0cn = 5\uff1a\u6570\u7ec4\u6392\u5e8f\u540e\u5f97\u5230 arr = [-3, 2, 6, 7, 11] \uff0c\u6570\u7ec4\u7684\u4e2d\u95f4\u4f4d\u7f6e\u4e3a m = ((5 - 1) / 2) = 2 \uff0c\u4e2d\u4f4d\u6570 arr[m] \u7684\u503c\u4e3a 6 \u3002
    • \n\t
    • \u4f8b\u5982 arr = [-7, 22, 17, 3]\uff0cn = 4\uff1a\u6570\u7ec4\u6392\u5e8f\u540e\u5f97\u5230 arr = [-7, 3, 17, 22] \uff0c\u6570\u7ec4\u7684\u4e2d\u95f4\u4f4d\u7f6e\u4e3a m = ((4 - 1) / 2) = 1 \uff0c\u4e2d\u4f4d\u6570 arr[m] \u7684\u503c\u4e3a 3 \u3002
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [1,2,3,4,5], k = 2\n\u8f93\u51fa\uff1a[5,1]\n\u89e3\u91ca\uff1a\u4e2d\u4f4d\u6570\u4e3a 3\uff0c\u6309\u4ece\u5f3a\u5230\u5f31\u987a\u5e8f\u6392\u5e8f\u540e\uff0c\u6570\u7ec4\u53d8\u4e3a [5,1,4,2,3]\u3002\u6700\u5f3a\u7684\u4e24\u4e2a\u5143\u7d20\u662f [5, 1]\u3002[1, 5] \u4e5f\u662f\u6b63\u786e\u7b54\u6848\u3002\n\u6ce8\u610f\uff0c\u5c3d\u7ba1 |5 - 3| == |1 - 3| \uff0c\u4f46\u662f 5 \u6bd4 1 \u66f4\u5f3a\uff0c\u56e0\u4e3a 5 > 1 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [1,1,3,5,5], k = 2\n\u8f93\u51fa\uff1a[5,5]\n\u89e3\u91ca\uff1a\u4e2d\u4f4d\u6570\u4e3a 3, \u6309\u4ece\u5f3a\u5230\u5f31\u987a\u5e8f\u6392\u5e8f\u540e\uff0c\u6570\u7ec4\u53d8\u4e3a [5,5,1,1,3]\u3002\u6700\u5f3a\u7684\u4e24\u4e2a\u5143\u7d20\u662f [5, 5]\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [6,7,11,7,6,8], k = 5\n\u8f93\u51fa\uff1a[11,8,6,6,7]\n\u89e3\u91ca\uff1a\u4e2d\u4f4d\u6570\u4e3a 7, \u6309\u4ece\u5f3a\u5230\u5f31\u987a\u5e8f\u6392\u5e8f\u540e\uff0c\u6570\u7ec4\u53d8\u4e3a [11,8,6,6,7,7]\u3002\n[11,8,6,6,7] \u7684\u4efb\u4f55\u6392\u5217\u90fd\u662f\u6b63\u786e\u7b54\u6848\u3002
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [6,-3,7,2,11], k = 3\n\u8f93\u51fa\uff1a[-3,11,2]\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [-7,22,17,3], k = 2\n\u8f93\u51fa\uff1a[22,17]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= arr.length <= 10^5
    • \n\t
    • -10^5 <= arr[i] <= 10^5
    • \n\t
    • 1 <= k <= arr.length
    • \n
    \n", "tags_en": ["Sort", "Array"], "tags_cn": ["\u6392\u5e8f", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector getStrongest(vector& arr, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] getStrongest(int[] arr, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getStrongest(self, arr, k):\n \"\"\"\n :type arr: List[int]\n :type k: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getStrongest(self, arr: List[int], k: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* getStrongest(int* arr, int arrSize, int k, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] GetStrongest(int[] arr, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @param {number} k\n * @return {number[]}\n */\nvar getStrongest = function(arr, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @param {Integer} k\n# @return {Integer[]}\ndef get_strongest(arr, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getStrongest(_ arr: [Int], _ k: Int) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getStrongest(arr []int, k int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getStrongest(arr: Array[Int], k: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getStrongest(arr: IntArray, k: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_strongest(arr: Vec, k: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @param Integer $k\n * @return Integer[]\n */\n function getStrongest($arr, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getStrongest(arr: number[], k: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-strongest arr k)\n (-> (listof exact-integer?) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1471](https://leetcode-cn.com/problems/the-k-strongest-values-in-an-array)", "[\u6570\u7ec4\u4e2d\u7684 k \u4e2a\u6700\u5f3a\u503c](/solution/1400-1499/1471.The%20k%20Strongest%20Values%20in%20an%20Array/README.md)", "`\u6392\u5e8f`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1471](https://leetcode.com/problems/the-k-strongest-values-in-an-array)", "[The k Strongest Values in an Array](/solution/1400-1499/1471.The%20k%20Strongest%20Values%20in%20an%20Array/README_EN.md)", "`Sort`,`Array`", "Medium", ""]}, {"question_id": "1580", "frontend_question_id": "1470", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/shuffle-the-array", "url_en": "https://leetcode.com/problems/shuffle-the-array", "relative_path_cn": "/solution/1400-1499/1470.Shuffle%20the%20Array/README.md", "relative_path_en": "/solution/1400-1499/1470.Shuffle%20the%20Array/README_EN.md", "title_cn": "\u91cd\u65b0\u6392\u5217\u6570\u7ec4", "title_en": "Shuffle the Array", "question_title_slug": "shuffle-the-array", "content_en": "

    Given the array nums consisting of 2n elements in the form [x1,x2,...,xn,y1,y2,...,yn].

    \r\n\r\n

    Return the array in the form [x1,y1,x2,y2,...,xn,yn].

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: nums = [2,5,1,3,4,7], n = 3\r\nOutput: [2,3,5,4,1,7] \r\nExplanation: Since x1=2, x2=5, x3=1, y1=3, y2=4, y3=7 then the answer is [2,3,5,4,1,7].\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: nums = [1,2,3,4,4,3,2,1], n = 4\r\nOutput: [1,4,2,3,3,2,4,1]\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: nums = [1,1,2,2], n = 2\r\nOutput: [1,2,1,2]\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= n <= 500
    • \r\n\t
    • nums.length == 2n
    • \r\n\t
    • 1 <= nums[i] <= 10^3
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 nums \uff0c\u6570\u7ec4\u4e2d\u6709 2n \u4e2a\u5143\u7d20\uff0c\u6309 [x1,x2,...,xn,y1,y2,...,yn] \u7684\u683c\u5f0f\u6392\u5217\u3002

    \n\n

    \u8bf7\u4f60\u5c06\u6570\u7ec4\u6309 [x1,y1,x2,y2,...,xn,yn] \u683c\u5f0f\u91cd\u65b0\u6392\u5217\uff0c\u8fd4\u56de\u91cd\u6392\u540e\u7684\u6570\u7ec4\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [2,5,1,3,4,7], n = 3\n\u8f93\u51fa\uff1a[2,3,5,4,1,7] \n\u89e3\u91ca\uff1a\u7531\u4e8e x1=2, x2=5, x3=1, y1=3, y2=4, y3=7 \uff0c\u6240\u4ee5\u7b54\u6848\u4e3a [2,3,5,4,1,7]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,2,3,4,4,3,2,1], n = 4\n\u8f93\u51fa\uff1a[1,4,2,3,3,2,4,1]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,1,2,2], n = 2\n\u8f93\u51fa\uff1a[1,2,1,2]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 500
    • \n\t
    • nums.length == 2n
    • \n\t
    • 1 <= nums[i] <= 10^3
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector shuffle(vector& nums, int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] shuffle(int[] nums, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def shuffle(self, nums, n):\n \"\"\"\n :type nums: List[int]\n :type n: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def shuffle(self, nums: List[int], n: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* shuffle(int* nums, int numsSize, int n, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] Shuffle(int[] nums, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} n\n * @return {number[]}\n */\nvar shuffle = function(nums, n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} n\n# @return {Integer[]}\ndef shuffle(nums, n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func shuffle(_ nums: [Int], _ n: Int) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func shuffle(nums []int, n int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def shuffle(nums: Array[Int], n: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun shuffle(nums: IntArray, n: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn shuffle(nums: Vec, n: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $n\n * @return Integer[]\n */\n function shuffle($nums, $n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function shuffle(nums: number[], n: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (shuffle nums n)\n (-> (listof exact-integer?) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1470](https://leetcode-cn.com/problems/shuffle-the-array)", "[\u91cd\u65b0\u6392\u5217\u6570\u7ec4](/solution/1400-1499/1470.Shuffle%20the%20Array/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1470](https://leetcode.com/problems/shuffle-the-array)", "[Shuffle the Array](/solution/1400-1499/1470.Shuffle%20the%20Array/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1579", "frontend_question_id": "1454", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/active-users", "url_en": "https://leetcode.com/problems/active-users", "relative_path_cn": "/solution/1400-1499/1454.Active%20Users/README.md", "relative_path_en": "/solution/1400-1499/1454.Active%20Users/README_EN.md", "title_cn": "\u6d3b\u8dc3\u7528\u6237", "title_en": "Active Users", "question_title_slug": "active-users", "content_en": "

    Table Accounts:

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| name          | varchar |\n+---------------+---------+\nthe id is the primary key for this table.\nThis table contains the account id and the user name of each account.\n
    \n\n

     

    \n\n

    Table Logins:

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| login_date    | date    |\n+---------------+---------+\nThere is no primary key for this table, it may contain duplicates.\nThis table contains the account id of the user who logged in and the login date. A user may log in multiple times in the day.\n
    \n\n

     

    \n\n

    Write an SQL query to find the id and the name of active users.

    \n\n

    Active users are those who logged in to their accounts for 5 or more consecutive days.

    \n\n

    Return the result table ordered by the id.

    \n\n

    The query result format is in the following example:

    \n\n
    \nAccounts table:\n+----+----------+\n| id | name     |\n+----+----------+\n| 1  | Winston  |\n| 7  | Jonathan |\n+----+----------+\n\nLogins table:\n+----+------------+\n| id | login_date |\n+----+------------+\n| 7  | 2020-05-30 |\n| 1  | 2020-05-30 |\n| 7  | 2020-05-31 |\n| 7  | 2020-06-01 |\n| 7  | 2020-06-02 |\n| 7  | 2020-06-02 |\n| 7  | 2020-06-03 |\n| 1  | 2020-06-07 |\n| 7  | 2020-06-10 |\n+----+------------+\n\nResult table:\n+----+----------+\n| id | name     |\n+----+----------+\n| 7  | Jonathan |\n+----+----------+\nUser Winston with id = 1 logged in 2 times only in 2 different days, so, Winston is not an active user.\nUser Jonathan with id = 7 logged in 7 times in 6 different days, five of them were consecutive days, so, Jonathan is an active user.\n
    \n\n

    Follow up question:
    \nCan you write a general solution if the active users are those who logged in to their accounts for n or more consecutive days?

    \n", "content_cn": "

    \u8868 Accounts:

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| name          | varchar |\n+---------------+---------+\nid \u662f\u8be5\u8868\u4e3b\u952e.\n\u8be5\u8868\u5305\u542b\u8d26\u6237 id \u548c\u8d26\u6237\u7684\u7528\u6237\u540d.\n
    \n\n

    \u00a0

    \n\n

    \u8868 Logins:

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| login_date    | date    |\n+---------------+---------+\n\u8be5\u8868\u65e0\u4e3b\u952e, \u53ef\u80fd\u5305\u542b\u91cd\u590d\u9879.\n\u8be5\u8868\u5305\u542b\u767b\u5f55\u7528\u6237\u7684\u8d26\u6237 id \u548c\u767b\u5f55\u65e5\u671f. \u7528\u6237\u4e5f\u8bb8\u4e00\u5929\u5185\u767b\u5f55\u591a\u6b21.\n
    \n\n

    \u00a0

    \n\n

    \u5199\u4e00\u4e2a SQL \u67e5\u8be2,\u00a0 \u627e\u5230\u6d3b\u8dc3\u7528\u6237\u7684 id \u548c name.

    \n\n

    \u6d3b\u8dc3\u7528\u6237\u662f\u6307\u90a3\u4e9b\u81f3\u5c11\u8fde\u7eed\u00a05 \u5929\u767b\u5f55\u8d26\u6237\u7684\u7528\u6237.

    \n\n

    \u8fd4\u56de\u7684\u7ed3\u679c\u8868\u6309\u7167 id \u6392\u5e8f.

    \n\n

    \u7ed3\u679c\u8868\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a:

    \n\n
    \nAccounts \u8868:\n+----+----------+\n| id | name     |\n+----+----------+\n| 1  | Winston  |\n| 7  | Jonathan |\n+----+----------+\n\nLogins \u8868:\n+----+------------+\n| id | login_date |\n+----+------------+\n| 7  | 2020-05-30 |\n| 1  | 2020-05-30 |\n| 7  | 2020-05-31 |\n| 7  | 2020-06-01 |\n| 7  | 2020-06-02 |\n| 7  | 2020-06-02 |\n| 7  | 2020-06-03 |\n| 1  | 2020-06-07 |\n| 7  | 2020-06-10 |\n+----+------------+\n\nResult \u8868:\n+----+----------+\n| id | name     |\n+----+----------+\n| 7  | Jonathan |\n+----+----------+\nid = 1 \u7684\u7528\u6237 Winston \u4ec5\u4ec5\u5728\u4e0d\u540c\u7684 2 \u5929\u5185\u767b\u5f55\u4e86 2 \u6b21, \u6240\u4ee5, Winston \u4e0d\u662f\u6d3b\u8dc3\u7528\u6237.\nid = 7 \u7684\u7528\u6237 Jonathon \u5728\u4e0d\u540c\u7684 6 \u5929\u5185\u767b\u5f55\u4e86 7 \u6b21, , 6 \u5929\u4e2d\u6709 5 \u5929\u662f\u8fde\u7eed\u7684, \u6240\u4ee5, Jonathan \u662f\u6d3b\u8dc3\u7528\u6237.\n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\u95ee\u9898:
    \n\u5982\u679c\u6d3b\u8dc3\u7528\u6237\u662f\u90a3\u4e9b\u81f3\u5c11\u8fde\u7eed\u00a0n\u00a0\u5929\u767b\u5f55\u8d26\u6237\u7684\u7528\u6237,\u00a0\u4f60\u80fd\u5426\u5199\u51fa\u901a\u7528\u7684\u89e3\u51b3\u65b9\u6848?

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1454](https://leetcode-cn.com/problems/active-users)", "[\u6d3b\u8dc3\u7528\u6237](/solution/1400-1499/1454.Active%20Users/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1454](https://leetcode.com/problems/active-users)", "[Active Users](/solution/1400-1499/1454.Active%20Users/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1578", "frontend_question_id": "1445", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/apples-oranges", "url_en": "https://leetcode.com/problems/apples-oranges", "relative_path_cn": "/solution/1400-1499/1445.Apples%20%26%20Oranges/README.md", "relative_path_en": "/solution/1400-1499/1445.Apples%20%26%20Oranges/README_EN.md", "title_cn": "\u82f9\u679c\u548c\u6854\u5b50", "title_en": "Apples & Oranges", "question_title_slug": "apples-oranges", "content_en": "

    Table: Sales

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| sale_date     | date    |\n| fruit         | enum    | \n| sold_num      | int     | \n+---------------+---------+\n(sale_date,fruit) is the primary key for this table.\nThis table contains the sales of "apples" and "oranges" sold each day.\n
    \n\n

     

    \n\n

    Write an SQL query to report the difference between number of apples and oranges sold each day.

    \n\n

    Return the result table ordered by sale_date in format ('YYYY-MM-DD').

    \n\n

    The query result format is in the following example:

    \n\n

     

    \n\n
    \nSales table:\n+------------+------------+-------------+\n| sale_date  | fruit      | sold_num    |\n+------------+------------+-------------+\n| 2020-05-01 | apples     | 10          |\n| 2020-05-01 | oranges    | 8           |\n| 2020-05-02 | apples     | 15          |\n| 2020-05-02 | oranges    | 15          |\n| 2020-05-03 | apples     | 20          |\n| 2020-05-03 | oranges    | 0           |\n| 2020-05-04 | apples     | 15          |\n| 2020-05-04 | oranges    | 16          |\n+------------+------------+-------------+\n\nResult table:\n+------------+--------------+\n| sale_date  | diff         |\n+------------+--------------+\n| 2020-05-01 | 2            |\n| 2020-05-02 | 0            |\n| 2020-05-03 | 20           |\n| 2020-05-04 | -1           |\n+------------+--------------+\n\nDay 2020-05-01, 10 apples and 8 oranges were sold (Difference  10 - 8 = 2).\nDay 2020-05-02, 15 apples and 15 oranges were sold (Difference 15 - 15 = 0).\nDay 2020-05-03, 20 apples and 0 oranges were sold (Difference 20 - 0 = 20).\nDay 2020-05-04, 15 apples and 16 oranges were sold (Difference 15 - 16 = -1).\n
    \n", "content_cn": "

    \u8868: Sales

    \n\n
    +---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| sale_date     | date    |\n| fruit         | enum    | \n| sold_num      | int     | \n+---------------+---------+\n(sale_date,fruit) \u662f\u8be5\u8868\u4e3b\u952e.\n\u8be5\u8868\u5305\u542b\u4e86\u6bcf\u4e00\u5929\u4e2d"\u82f9\u679c" \u548c "\u6854\u5b50"\u7684\u9500\u552e\u60c5\u51b5.\n
    \n\n

     

    \n\n

    \u5199\u4e00\u4e2a SQL \u67e5\u8be2, \u62a5\u544a\u6bcf\u4e00\u5929 \u82f9\u679c \u548c \u6854\u5b50 \u9500\u552e\u7684\u6570\u76ee\u7684\u5dee\u5f02.

    \n\n

    \u8fd4\u56de\u7684\u7ed3\u679c\u8868, \u6309\u7167\u683c\u5f0f\u4e3a ('YYYY-MM-DD') \u7684 sale_date \u6392\u5e8f.

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u8868\u5982\u4e0b\u4f8b\u6240\u793a:

    \n\n

     

    \n\n
    Sales \u8868:\n+------------+------------+-------------+\n| sale_date  | fruit      | sold_num    |\n+------------+------------+-------------+\n| 2020-05-01 | apples     | 10          |\n| 2020-05-01 | oranges    | 8           |\n| 2020-05-02 | apples     | 15          |\n| 2020-05-02 | oranges    | 15          |\n| 2020-05-03 | apples     | 20          |\n| 2020-05-03 | oranges    | 0           |\n| 2020-05-04 | apples     | 15          |\n| 2020-05-04 | oranges    | 16          |\n+------------+------------+-------------+\n\nResult \u8868:\n+------------+--------------+\n| sale_date  | diff         |\n+------------+--------------+\n| 2020-05-01 | 2            |\n| 2020-05-02 | 0            |\n| 2020-05-03 | 20           |\n| 2020-05-04 | -1           |\n+------------+--------------+\n\n\u5728 2020-05-01, \u5356\u4e86 10 \u4e2a\u82f9\u679c \u548c 8 \u4e2a\u6854\u5b50 (\u5dee\u5f02\u4e3a 10 - 8 = 2).\n\u5728 2020-05-02, \u5356\u4e86 15 \u4e2a\u82f9\u679c \u548c 15 \u4e2a\u6854\u5b50 (\u5dee\u5f02\u4e3a 15 - 15 = 0).\n\u5728 2020-05-03, \u5356\u4e86 20 \u4e2a\u82f9\u679c \u548c 0 \u4e2a\u6854\u5b50 (\u5dee\u5f02\u4e3a 20 - 0 = 20).\n\u5728 2020-05-04, \u5356\u4e86 15 \u4e2a\u82f9\u679c \u548c 16 \u4e2a\u6854\u5b50 (\u5dee\u5f02\u4e3a 15 - 16 = -1).\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1445](https://leetcode-cn.com/problems/apples-oranges)", "[\u82f9\u679c\u548c\u6854\u5b50](/solution/1400-1499/1445.Apples%20%26%20Oranges/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1445](https://leetcode.com/problems/apples-oranges)", "[Apples & Oranges](/solution/1400-1499/1445.Apples%20%26%20Oranges/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1577", "frontend_question_id": "1467", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/probability-of-a-two-boxes-having-the-same-number-of-distinct-balls", "url_en": "https://leetcode.com/problems/probability-of-a-two-boxes-having-the-same-number-of-distinct-balls", "relative_path_cn": "/solution/1400-1499/1467.Probability%20of%20a%20Two%20Boxes%20Having%20The%20Same%20Number%20of%20Distinct%20Balls/README.md", "relative_path_en": "/solution/1400-1499/1467.Probability%20of%20a%20Two%20Boxes%20Having%20The%20Same%20Number%20of%20Distinct%20Balls/README_EN.md", "title_cn": "\u4e24\u4e2a\u76d2\u5b50\u4e2d\u7403\u7684\u989c\u8272\u6570\u76f8\u540c\u7684\u6982\u7387", "title_en": "Probability of a Two Boxes Having The Same Number of Distinct Balls", "question_title_slug": "probability-of-a-two-boxes-having-the-same-number-of-distinct-balls", "content_en": "

    Given 2n balls of k distinct colors. You will be given an integer array balls of size k where balls[i] is the number of balls of color i

    \n\n

    All the balls will be shuffled uniformly at random, then we will distribute the first n balls to the first box and the remaining n balls to the other box (Please read the explanation of the second example carefully).

    \n\n

    Please note that the two boxes are considered different. For example, if we have two balls of colors a and b, and two boxes [] and (), then the distribution [a] (b) is considered different than the distribution [b] (a) (Please read the explanation of the first example carefully).

    \n\n

    We want to calculate the probability that the two boxes have the same number of distinct balls.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: balls = [1,1]\nOutput: 1.00000\nExplanation: Only 2 ways to divide the balls equally:\n- A ball of color 1 to box 1 and a ball of color 2 to box 2\n- A ball of color 2 to box 1 and a ball of color 1 to box 2\nIn both ways, the number of distinct colors in each box is equal. The probability is 2/2 = 1\n
    \n\n

    Example 2:

    \n\n
    \nInput: balls = [2,1,1]\nOutput: 0.66667\nExplanation: We have the set of balls [1, 1, 2, 3]\nThis set of balls will be shuffled randomly and we may have one of the 12 distinct shuffles with equale probability (i.e. 1/12):\n[1,1 / 2,3], [1,1 / 3,2], [1,2 / 1,3], [1,2 / 3,1], [1,3 / 1,2], [1,3 / 2,1], [2,1 / 1,3], [2,1 / 3,1], [2,3 / 1,1], [3,1 / 1,2], [3,1 / 2,1], [3,2 / 1,1]\nAfter that we add the first two balls to the first box and the second two balls to the second box.\nWe can see that 8 of these 12 possible random distributions have the same number of distinct colors of balls in each box.\nProbability is 8/12 = 0.66667\n
    \n\n

    Example 3:

    \n\n
    \nInput: balls = [1,2,1,2]\nOutput: 0.60000\nExplanation: The set of balls is [1, 2, 2, 3, 4, 4]. It is hard to display all the 180 possible random shuffles of this set but it is easy to check that 108 of them will have the same number of distinct colors in each box.\nProbability = 108 / 180 = 0.6\n
    \n\n

    Example 4:

    \n\n
    \nInput: balls = [3,2,1]\nOutput: 0.30000\nExplanation: The set of balls is [1, 1, 1, 2, 2, 3]. It is hard to display all the 60 possible random shuffles of this set but it is easy to check that 18 of them will have the same number of distinct colors in each box.\nProbability = 18 / 60 = 0.3\n
    \n\n

    Example 5:

    \n\n
    \nInput: balls = [6,6,6,6,6,6]\nOutput: 0.90327\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= balls.length <= 8
    • \n\t
    • 1 <= balls[i] <= 6
    • \n\t
    • sum(balls) is even.
    • \n\t
    • Answers within 10^-5 of the actual value will be accepted as correct.
    • \n
    \n", "content_cn": "

    \u684c\u9762\u4e0a\u6709 2n \u4e2a\u989c\u8272\u4e0d\u5b8c\u5168\u76f8\u540c\u7684\u7403\uff0c\u7403\u4e0a\u7684\u989c\u8272\u5171\u6709 k \u79cd\u3002\u7ed9\u4f60\u4e00\u4e2a\u5927\u5c0f\u4e3a k \u7684\u6574\u6570\u6570\u7ec4 balls \uff0c\u5176\u4e2d balls[i] \u662f\u989c\u8272\u4e3a i \u7684\u7403\u7684\u6570\u91cf\u3002

    \n\n

    \u6240\u6709\u7684\u7403\u90fd\u5df2\u7ecf \u968f\u673a\u6253\u4e71\u987a\u5e8f \uff0c\u524d n \u4e2a\u7403\u653e\u5165\u7b2c\u4e00\u4e2a\u76d2\u5b50\uff0c\u540e n \u4e2a\u7403\u653e\u5165\u53e6\u4e00\u4e2a\u76d2\u5b50\uff08\u8bf7\u8ba4\u771f\u9605\u8bfb\u793a\u4f8b 2 \u7684\u89e3\u91ca\u90e8\u5206\uff09\u3002

    \n\n

    \u6ce8\u610f\uff1a\u8fd9\u4e24\u4e2a\u76d2\u5b50\u662f\u4e0d\u540c\u7684\u3002\u4f8b\u5982\uff0c\u4e24\u4e2a\u7403\u989c\u8272\u5206\u522b\u4e3a a \u548c b\uff0c\u76d2\u5b50\u5206\u522b\u4e3a [] \u548c ()\uff0c\u90a3\u4e48 [a] (b) \u548c [b] (a) \u8fd9\u4e24\u79cd\u5206\u914d\u65b9\u5f0f\u662f\u4e0d\u540c\u7684\uff08\u8bf7\u8ba4\u771f\u9605\u8bfb\u793a\u4f8b 1 \u7684\u89e3\u91ca\u90e8\u5206\uff09\u3002

    \n\n

    \u8bf7\u8ba1\u7b97\u300c\u4e24\u4e2a\u76d2\u5b50\u4e2d\u7403\u7684\u989c\u8272\u6570\u76f8\u540c\u300d\u7684\u60c5\u51b5\u7684\u6982\u7387\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aballs = [1,1]\n\u8f93\u51fa\uff1a1.00000\n\u89e3\u91ca\uff1a\u7403\u5e73\u5747\u5206\u914d\u7684\u65b9\u5f0f\u53ea\u6709\u4e24\u79cd\uff1a\n- \u989c\u8272\u4e3a 1 \u7684\u7403\u653e\u5165\u7b2c\u4e00\u4e2a\u76d2\u5b50\uff0c\u989c\u8272\u4e3a 2 \u7684\u7403\u653e\u5165\u7b2c\u4e8c\u4e2a\u76d2\u5b50\n- \u989c\u8272\u4e3a 2 \u7684\u7403\u653e\u5165\u7b2c\u4e00\u4e2a\u76d2\u5b50\uff0c\u989c\u8272\u4e3a 1 \u7684\u7403\u653e\u5165\u7b2c\u4e8c\u4e2a\u76d2\u5b50\n\u8fd9\u4e24\u79cd\u5206\u914d\uff0c\u4e24\u4e2a\u76d2\u5b50\u4e2d\u7403\u7684\u989c\u8272\u6570\u90fd\u76f8\u540c\u3002\u6240\u4ee5\u6982\u7387\u4e3a 2/2 = 1 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aballs = [2,1,1]\n\u8f93\u51fa\uff1a0.66667\n\u89e3\u91ca\uff1a\u7403\u7684\u5217\u8868\u4e3a [1, 1, 2, 3]\n\u968f\u673a\u6253\u4e71\uff0c\u5f97\u5230 12 \u79cd\u7b49\u6982\u7387\u7684\u4e0d\u540c\u6253\u4e71\u65b9\u6848\uff0c\u6bcf\u79cd\u65b9\u6848\u6982\u7387\u4e3a 1/12 \uff1a\n[1,1 / 2,3], [1,1 / 3,2], [1,2 / 1,3], [1,2 / 3,1], [1,3 / 1,2], [1,3 / 2,1], [2,1 / 1,3], [2,1 / 3,1], [2,3 / 1,1], [3,1 / 1,2], [3,1 / 2,1], [3,2 / 1,1]\n\u7136\u540e\uff0c\u6211\u4eec\u5c06\u524d\u4e24\u4e2a\u7403\u653e\u5165\u7b2c\u4e00\u4e2a\u76d2\u5b50\uff0c\u540e\u4e24\u4e2a\u7403\u653e\u5165\u7b2c\u4e8c\u4e2a\u76d2\u5b50\u3002\n\u8fd9 12 \u79cd\u53ef\u80fd\u7684\u968f\u673a\u6253\u4e71\u65b9\u5f0f\u4e2d\u7684 8 \u79cd\u6ee1\u8db3\u300c\u4e24\u4e2a\u76d2\u5b50\u4e2d\u7403\u7684\u989c\u8272\u6570\u76f8\u540c\u300d\u3002\n\u6982\u7387 = 8/12 = 0.66667\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aballs = [1,2,1,2]\n\u8f93\u51fa\uff1a0.60000\n\u89e3\u91ca\uff1a\u7403\u7684\u5217\u8868\u4e3a [1, 2, 2, 3, 4, 4]\u3002\u8981\u60f3\u663e\u793a\u6240\u6709 180 \u79cd\u968f\u673a\u6253\u4e71\u65b9\u6848\u662f\u5f88\u96be\u7684\uff0c\u4f46\u53ea\u68c0\u67e5\u300c\u4e24\u4e2a\u76d2\u5b50\u4e2d\u7403\u7684\u989c\u8272\u6570\u76f8\u540c\u300d\u7684 108 \u79cd\u60c5\u51b5\u662f\u6bd4\u8f83\u5bb9\u6613\u7684\u3002\n\u6982\u7387 = 108 / 180 = 0.6 \u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1aballs = [3,2,1]\n\u8f93\u51fa\uff1a0.30000\n\u89e3\u91ca\uff1a\u7403\u7684\u5217\u8868\u4e3a [1, 1, 1, 2, 2, 3]\u3002\u8981\u60f3\u663e\u793a\u6240\u6709 60 \u79cd\u968f\u673a\u6253\u4e71\u65b9\u6848\u662f\u5f88\u96be\u7684\uff0c\u4f46\u53ea\u68c0\u67e5\u300c\u4e24\u4e2a\u76d2\u5b50\u4e2d\u7403\u7684\u989c\u8272\u6570\u76f8\u540c\u300d\u7684 18 \u79cd\u60c5\u51b5\u662f\u6bd4\u8f83\u5bb9\u6613\u7684\u3002\n\u6982\u7387 = 18 / 60 = 0.3 \u3002\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1aballs = [6,6,6,6,6,6]\n\u8f93\u51fa\uff1a0.90327\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= balls.length <= 8
    • \n\t
    • 1 <= balls[i] <= 6
    • \n\t
    • sum(balls) \u662f\u5076\u6570
    • \n\t
    • \u7b54\u6848\u4e0e\u771f\u5b9e\u503c\u8bef\u5dee\u5728 10^-5 \u4ee5\u5185\uff0c\u5219\u88ab\u89c6\u4e3a\u6b63\u786e\u7b54\u6848
    • \n
    \n", "tags_en": ["Math", "Backtracking"], "tags_cn": ["\u6570\u5b66", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n double getProbability(vector& balls) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double getProbability(int[] balls) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getProbability(self, balls):\n \"\"\"\n :type balls: List[int]\n :rtype: float\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getProbability(self, balls: List[int]) -> float:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\ndouble getProbability(int* balls, int ballsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double GetProbability(int[] balls) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} balls\n * @return {number}\n */\nvar getProbability = function(balls) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} balls\n# @return {Float}\ndef get_probability(balls)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getProbability(_ balls: [Int]) -> Double {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getProbability(balls []int) float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getProbability(balls: Array[Int]): Double = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getProbability(balls: IntArray): Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_probability(balls: Vec) -> f64 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $balls\n * @return Float\n */\n function getProbability($balls) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getProbability(balls: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-probability balls)\n (-> (listof exact-integer?) flonum?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1467](https://leetcode-cn.com/problems/probability-of-a-two-boxes-having-the-same-number-of-distinct-balls)", "[\u4e24\u4e2a\u76d2\u5b50\u4e2d\u7403\u7684\u989c\u8272\u6570\u76f8\u540c\u7684\u6982\u7387](/solution/1400-1499/1467.Probability%20of%20a%20Two%20Boxes%20Having%20The%20Same%20Number%20of%20Distinct%20Balls/README.md)", "`\u6570\u5b66`,`\u56de\u6eaf\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[1467](https://leetcode.com/problems/probability-of-a-two-boxes-having-the-same-number-of-distinct-balls)", "[Probability of a Two Boxes Having The Same Number of Distinct Balls](/solution/1400-1499/1467.Probability%20of%20a%20Two%20Boxes%20Having%20The%20Same%20Number%20of%20Distinct%20Balls/README_EN.md)", "`Math`,`Backtracking`", "Hard", ""]}, {"question_id": "1576", "frontend_question_id": "1466", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reorder-routes-to-make-all-paths-lead-to-the-city-zero", "url_en": "https://leetcode.com/problems/reorder-routes-to-make-all-paths-lead-to-the-city-zero", "relative_path_cn": "/solution/1400-1499/1466.Reorder%20Routes%20to%20Make%20All%20Paths%20Lead%20to%20the%20City%20Zero/README.md", "relative_path_en": "/solution/1400-1499/1466.Reorder%20Routes%20to%20Make%20All%20Paths%20Lead%20to%20the%20City%20Zero/README_EN.md", "title_cn": "\u91cd\u65b0\u89c4\u5212\u8def\u7ebf", "title_en": "Reorder Routes to Make All Paths Lead to the City Zero", "question_title_slug": "reorder-routes-to-make-all-paths-lead-to-the-city-zero", "content_en": "

    There are n cities numbered from 0 to n - 1 and n - 1 roads such that there is only one way to travel between two different cities (this network form a tree). Last year, The ministry of transport decided to orient the roads in one direction because they are too narrow.

    \n\n

    Roads are represented by connections where connections[i] = [ai, bi] represents a road from city ai to city bi.

    \n\n

    This year, there will be a big event in the capital (city 0), and many people want to travel to this city.

    \n\n

    Your task consists of reorienting some roads such that each city can visit the city 0. Return the minimum number of edges changed.

    \n\n

    It's guaranteed that each city can reach city 0 after reorder.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: n = 6, connections = [[0,1],[1,3],[2,3],[4,0],[4,5]]\nOutput: 3\nExplanation: Change the direction of edges show in red such that each node can reach the node 0 (capital).\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: n = 5, connections = [[1,0],[1,2],[3,2],[3,4]]\nOutput: 2\nExplanation: Change the direction of edges show in red such that each node can reach the node 0 (capital).\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 3, connections = [[1,0],[2,0]]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= n <= 5 * 104
    • \n\t
    • connections.length == n - 1
    • \n\t
    • connections[i].length == 2
    • \n\t
    • 0 <= ai, bi <= n - 1
    • \n\t
    • ai != bi
    • \n
    \n", "content_cn": "

    n \u5ea7\u57ce\u5e02\uff0c\u4ece 0 \u5230 n-1 \u7f16\u53f7\uff0c\u5176\u95f4\u5171\u6709 n-1 \u6761\u8def\u7ebf\u3002\u56e0\u6b64\uff0c\u8981\u60f3\u5728\u4e24\u5ea7\u4e0d\u540c\u57ce\u5e02\u4e4b\u95f4\u65c5\u884c\u53ea\u6709\u552f\u4e00\u4e00\u6761\u8def\u7ebf\u53ef\u4f9b\u9009\u62e9\uff08\u8def\u7ebf\u7f51\u5f62\u6210\u4e00\u9897\u6811\uff09\u3002\u53bb\u5e74\uff0c\u4ea4\u901a\u8fd0\u8f93\u90e8\u51b3\u5b9a\u91cd\u65b0\u89c4\u5212\u8def\u7ebf\uff0c\u4ee5\u6539\u53d8\u4ea4\u901a\u62e5\u5835\u7684\u72b6\u51b5\u3002

    \n\n

    \u8def\u7ebf\u7528 connections \u8868\u793a\uff0c\u5176\u4e2d connections[i] = [a, b] \u8868\u793a\u4ece\u57ce\u5e02 a \u5230 b \u7684\u4e00\u6761\u6709\u5411\u8def\u7ebf\u3002

    \n\n

    \u4eca\u5e74\uff0c\u57ce\u5e02 0 \u5c06\u4f1a\u4e3e\u529e\u4e00\u573a\u5927\u578b\u6bd4\u8d5b\uff0c\u5f88\u591a\u6e38\u5ba2\u90fd\u60f3\u524d\u5f80\u57ce\u5e02 0 \u3002

    \n\n

    \u8bf7\u4f60\u5e2e\u52a9\u91cd\u65b0\u89c4\u5212\u8def\u7ebf\u65b9\u5411\uff0c\u4f7f\u6bcf\u4e2a\u57ce\u5e02\u90fd\u53ef\u4ee5\u8bbf\u95ee\u57ce\u5e02 0 \u3002\u8fd4\u56de\u9700\u8981\u53d8\u66f4\u65b9\u5411\u7684\u6700\u5c0f\u8def\u7ebf\u6570\u3002

    \n\n

    \u9898\u76ee\u6570\u636e \u4fdd\u8bc1 \u6bcf\u4e2a\u57ce\u5e02\u5728\u91cd\u65b0\u89c4\u5212\u8def\u7ebf\u65b9\u5411\u540e\u90fd\u80fd\u5230\u8fbe\u57ce\u5e02 0 \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 6, connections = [[0,1],[1,3],[2,3],[4,0],[4,5]]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u66f4\u6539\u4ee5\u7ea2\u8272\u663e\u793a\u7684\u8def\u7ebf\u7684\u65b9\u5411\uff0c\u4f7f\u6bcf\u4e2a\u57ce\u5e02\u90fd\u53ef\u4ee5\u5230\u8fbe\u57ce\u5e02 0 \u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 5, connections = [[1,0],[1,2],[3,2],[3,4]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u66f4\u6539\u4ee5\u7ea2\u8272\u663e\u793a\u7684\u8def\u7ebf\u7684\u65b9\u5411\uff0c\u4f7f\u6bcf\u4e2a\u57ce\u5e02\u90fd\u53ef\u4ee5\u5230\u8fbe\u57ce\u5e02 0 \u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1an = 3, connections = [[1,0],[2,0]]\n\u8f93\u51fa\uff1a0\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= n <= 5 * 10^4
    • \n\t
    • connections.length == n-1
    • \n\t
    • connections[i].length == 2
    • \n\t
    • 0 <= connections[i][0], connections[i][1] <= n-1
    • \n\t
    • connections[i][0] != connections[i][1]
    • \n
    \n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minReorder(int n, vector>& connections) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minReorder(int n, int[][] connections) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minReorder(self, n, connections):\n \"\"\"\n :type n: int\n :type connections: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minReorder(self, n: int, connections: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minReorder(int n, int** connections, int connectionsSize, int* connectionsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinReorder(int n, int[][] connections) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} connections\n * @return {number}\n */\nvar minReorder = function(n, connections) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} connections\n# @return {Integer}\ndef min_reorder(n, connections)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minReorder(_ n: Int, _ connections: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minReorder(n int, connections [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minReorder(n: Int, connections: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minReorder(n: Int, connections: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_reorder(n: i32, connections: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $connections\n * @return Integer\n */\n function minReorder($n, $connections) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minReorder(n: number, connections: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-reorder n connections)\n (-> exact-integer? (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1466](https://leetcode-cn.com/problems/reorder-routes-to-make-all-paths-lead-to-the-city-zero)", "[\u91cd\u65b0\u89c4\u5212\u8def\u7ebf](/solution/1400-1499/1466.Reorder%20Routes%20to%20Make%20All%20Paths%20Lead%20to%20the%20City%20Zero/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1466](https://leetcode.com/problems/reorder-routes-to-make-all-paths-lead-to-the-city-zero)", "[Reorder Routes to Make All Paths Lead to the City Zero](/solution/1400-1499/1466.Reorder%20Routes%20to%20Make%20All%20Paths%20Lead%20to%20the%20City%20Zero/README_EN.md)", "`Tree`,`Depth-first Search`", "Medium", ""]}, {"question_id": "1575", "frontend_question_id": "1465", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts", "url_en": "https://leetcode.com/problems/maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts", "relative_path_cn": "/solution/1400-1499/1465.Maximum%20Area%20of%20a%20Piece%20of%20Cake%20After%20Horizontal%20and%20Vertical%20Cuts/README.md", "relative_path_en": "/solution/1400-1499/1465.Maximum%20Area%20of%20a%20Piece%20of%20Cake%20After%20Horizontal%20and%20Vertical%20Cuts/README_EN.md", "title_cn": "\u5207\u5272\u540e\u9762\u79ef\u6700\u5927\u7684\u86cb\u7cd5", "title_en": "Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts", "question_title_slug": "maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts", "content_en": "

    You are given a rectangular cake of size h x w and two arrays of integers horizontalCuts and verticalCuts where:

    \n\n
      \n\t
    • horizontalCuts[i] is the distance from the top of the rectangular cake to the ith horizontal cut and similarly, and
    • \n\t
    • verticalCuts[j] is the distance from the left of the rectangular cake to the jth vertical cut.
    • \n
    \n\n

    Return the maximum area of a piece of cake after you cut at each horizontal and vertical position provided in the arrays horizontalCuts and verticalCuts. Since the answer can be a large number, return this modulo 109 + 7.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: h = 5, w = 4, horizontalCuts = [1,2,4], verticalCuts = [1,3]\nOutput: 4 \nExplanation: The figure above represents the given rectangular cake. Red lines are the horizontal and vertical cuts. After you cut the cake, the green piece of cake has the maximum area.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: h = 5, w = 4, horizontalCuts = [3,1], verticalCuts = [1]\nOutput: 6\nExplanation: The figure above represents the given rectangular cake. Red lines are the horizontal and vertical cuts. After you cut the cake, the green and yellow pieces of cake have the maximum area.\n
    \n\n

    Example 3:

    \n\n
    \nInput: h = 5, w = 4, horizontalCuts = [3], verticalCuts = [3]\nOutput: 9\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= h, w <= 109
    • \n\t
    • 1 <= horizontalCuts.length <= min(h - 1, 105)
    • \n\t
    • 1 <= verticalCuts.length <= min(w - 1, 105)
    • \n\t
    • 1 <= horizontalCuts[i] < h
    • \n\t
    • 1 <= verticalCuts[i] < w
    • \n\t
    • All the elements in horizontalCuts are distinct.
    • \n\t
    • All the elements in verticalCuts are distinct.
    • \n
    \n", "content_cn": "

    \u77e9\u5f62\u86cb\u7cd5\u7684\u9ad8\u5ea6\u4e3a h \u4e14\u5bbd\u5ea6\u4e3a w\uff0c\u7ed9\u4f60\u4e24\u4e2a\u6574\u6570\u6570\u7ec4 horizontalCuts \u548c verticalCuts\uff0c\u5176\u4e2d horizontalCuts[i] \u662f\u4ece\u77e9\u5f62\u86cb\u7cd5\u9876\u90e8\u5230\u7b2c  i \u4e2a\u6c34\u5e73\u5207\u53e3\u7684\u8ddd\u79bb\uff0c\u7c7b\u4f3c\u5730\uff0c verticalCuts[j] \u662f\u4ece\u77e9\u5f62\u86cb\u7cd5\u7684\u5de6\u4fa7\u5230\u7b2c j \u4e2a\u7ad6\u76f4\u5207\u53e3\u7684\u8ddd\u79bb\u3002

    \n\n

    \u8bf7\u4f60\u6309\u6570\u7ec4 horizontalCuts \u548c verticalCuts \u4e2d\u63d0\u4f9b\u7684\u6c34\u5e73\u548c\u7ad6\u76f4\u4f4d\u7f6e\u5207\u5272\u540e\uff0c\u8bf7\u4f60\u627e\u51fa \u9762\u79ef\u6700\u5927 \u7684\u90a3\u4efd\u86cb\u7cd5\uff0c\u5e76\u8fd4\u56de\u5176 \u9762\u79ef \u3002\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u662f\u4e00\u4e2a\u5f88\u5927\u7684\u6570\u5b57\uff0c\u56e0\u6b64\u9700\u8981\u5c06\u7ed3\u679c\u5bf9 10^9 + 7 \u53d6\u4f59\u540e\u8fd4\u56de\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1ah = 5, w = 4, horizontalCuts = [1,2,4], verticalCuts = [1,3]\n\u8f93\u51fa\uff1a4 \n\u89e3\u91ca\uff1a\u4e0a\u56fe\u6240\u793a\u7684\u77e9\u9635\u86cb\u7cd5\u4e2d\uff0c\u7ea2\u8272\u7ebf\u8868\u793a\u6c34\u5e73\u548c\u7ad6\u76f4\u65b9\u5411\u4e0a\u7684\u5207\u53e3\u3002\u5207\u5272\u86cb\u7cd5\u540e\uff0c\u7eff\u8272\u7684\u90a3\u4efd\u86cb\u7cd5\u9762\u79ef\u6700\u5927\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1ah = 5, w = 4, horizontalCuts = [3,1], verticalCuts = [1]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u4e0a\u56fe\u6240\u793a\u7684\u77e9\u9635\u86cb\u7cd5\u4e2d\uff0c\u7ea2\u8272\u7ebf\u8868\u793a\u6c34\u5e73\u548c\u7ad6\u76f4\u65b9\u5411\u4e0a\u7684\u5207\u53e3\u3002\u5207\u5272\u86cb\u7cd5\u540e\uff0c\u7eff\u8272\u548c\u9ec4\u8272\u7684\u4e24\u4efd\u86cb\u7cd5\u9762\u79ef\u6700\u5927\u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1ah = 5, w = 4, horizontalCuts = [3], verticalCuts = [3]\n\u8f93\u51fa\uff1a9\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= h, w <= 10^9
    • \n\t
    • 1 <= horizontalCuts.length < min(h, 10^5)
    • \n\t
    • 1 <= verticalCuts.length < min(w, 10^5)
    • \n\t
    • 1 <= horizontalCuts[i] < h
    • \n\t
    • 1 <= verticalCuts[i] < w
    • \n\t
    • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1 horizontalCuts \u4e2d\u7684\u6240\u6709\u5143\u7d20\u5404\u4e0d\u76f8\u540c
    • \n\t
    • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1 verticalCuts \u4e2d\u7684\u6240\u6709\u5143\u7d20\u5404\u4e0d\u76f8\u540c
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxArea(int h, int w, vector& horizontalCuts, vector& verticalCuts) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxArea(int h, int w, int[] horizontalCuts, int[] verticalCuts) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxArea(self, h, w, horizontalCuts, verticalCuts):\n \"\"\"\n :type h: int\n :type w: int\n :type horizontalCuts: List[int]\n :type verticalCuts: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxArea(self, h: int, w: int, horizontalCuts: List[int], verticalCuts: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxArea(int h, int w, int* horizontalCuts, int horizontalCutsSize, int* verticalCuts, int verticalCutsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxArea(int h, int w, int[] horizontalCuts, int[] verticalCuts) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} h\n * @param {number} w\n * @param {number[]} horizontalCuts\n * @param {number[]} verticalCuts\n * @return {number}\n */\nvar maxArea = function(h, w, horizontalCuts, verticalCuts) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} h\n# @param {Integer} w\n# @param {Integer[]} horizontal_cuts\n# @param {Integer[]} vertical_cuts\n# @return {Integer}\ndef max_area(h, w, horizontal_cuts, vertical_cuts)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxArea(_ h: Int, _ w: Int, _ horizontalCuts: [Int], _ verticalCuts: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxArea(h int, w int, horizontalCuts []int, verticalCuts []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxArea(h: Int, w: Int, horizontalCuts: Array[Int], verticalCuts: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxArea(h: Int, w: Int, horizontalCuts: IntArray, verticalCuts: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_area(h: i32, w: i32, horizontal_cuts: Vec, vertical_cuts: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $h\n * @param Integer $w\n * @param Integer[] $horizontalCuts\n * @param Integer[] $verticalCuts\n * @return Integer\n */\n function maxArea($h, $w, $horizontalCuts, $verticalCuts) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxArea(h: number, w: number, horizontalCuts: number[], verticalCuts: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-area h w horizontalCuts verticalCuts)\n (-> exact-integer? exact-integer? (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1465](https://leetcode-cn.com/problems/maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts)", "[\u5207\u5272\u540e\u9762\u79ef\u6700\u5927\u7684\u86cb\u7cd5](/solution/1400-1499/1465.Maximum%20Area%20of%20a%20Piece%20of%20Cake%20After%20Horizontal%20and%20Vertical%20Cuts/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1465](https://leetcode.com/problems/maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts)", "[Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts](/solution/1400-1499/1465.Maximum%20Area%20of%20a%20Piece%20of%20Cake%20After%20Horizontal%20and%20Vertical%20Cuts/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "1574", "frontend_question_id": "1464", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-product-of-two-elements-in-an-array", "url_en": "https://leetcode.com/problems/maximum-product-of-two-elements-in-an-array", "relative_path_cn": "/solution/1400-1499/1464.Maximum%20Product%20of%20Two%20Elements%20in%20an%20Array/README.md", "relative_path_en": "/solution/1400-1499/1464.Maximum%20Product%20of%20Two%20Elements%20in%20an%20Array/README_EN.md", "title_cn": "\u6570\u7ec4\u4e2d\u4e24\u5143\u7d20\u7684\u6700\u5927\u4e58\u79ef", "title_en": "Maximum Product of Two Elements in an Array", "question_title_slug": "maximum-product-of-two-elements-in-an-array", "content_en": "Given the array of integers nums, you will choose two different indices i and j of that array. Return the maximum value of (nums[i]-1)*(nums[j]-1).\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [3,4,5,2]\nOutput: 12 \nExplanation: If you choose the indices i=1 and j=2 (indexed from 0), you will get the maximum value, that is, (nums[1]-1)*(nums[2]-1) = (4-1)*(5-1) = 3*4 = 12. \n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,5,4,5]\nOutput: 16\nExplanation: Choosing the indices i=1 and j=3 (indexed from 0), you will get the maximum value of (5-1)*(5-1) = 16.\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [3,7]\nOutput: 12\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= nums.length <= 500
    • \n\t
    • 1 <= nums[i] <= 10^3
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums\uff0c\u8bf7\u4f60\u9009\u62e9\u6570\u7ec4\u7684\u4e24\u4e2a\u4e0d\u540c\u4e0b\u6807 i \u548c j\uff0c\u4f7f (nums[i]-1)*(nums[j]-1) \u53d6\u5f97\u6700\u5927\u503c\u3002

    \n\n

    \u8bf7\u4f60\u8ba1\u7b97\u5e76\u8fd4\u56de\u8be5\u5f0f\u7684\u6700\u5927\u503c\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [3,4,5,2]\n\u8f93\u51fa\uff1a12 \n\u89e3\u91ca\uff1a\u5982\u679c\u9009\u62e9\u4e0b\u6807 i=1 \u548c j=2\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\uff0c\u5219\u53ef\u4ee5\u83b7\u5f97\u6700\u5927\u503c\uff0c(nums[1]-1)*(nums[2]-1) = (4-1)*(5-1) = 3*4 = 12 \u3002 \n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,5,4,5]\n\u8f93\u51fa\uff1a16\n\u89e3\u91ca\uff1a\u9009\u62e9\u4e0b\u6807 i=1 \u548c j=3\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\uff0c\u5219\u53ef\u4ee5\u83b7\u5f97\u6700\u5927\u503c (5-1)*(5-1) = 16 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [3,7]\n\u8f93\u51fa\uff1a12\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= nums.length <= 500
    • \n\t
    • 1 <= nums[i] <= 10^3
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxProduct(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxProduct(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxProduct(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxProduct(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxProduct(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxProduct(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar maxProduct = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef max_product(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxProduct(_ nums: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxProduct(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxProduct(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxProduct(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_product(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function maxProduct($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxProduct(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-product nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1464](https://leetcode-cn.com/problems/maximum-product-of-two-elements-in-an-array)", "[\u6570\u7ec4\u4e2d\u4e24\u5143\u7d20\u7684\u6700\u5927\u4e58\u79ef](/solution/1400-1499/1464.Maximum%20Product%20of%20Two%20Elements%20in%20an%20Array/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1464](https://leetcode.com/problems/maximum-product-of-two-elements-in-an-array)", "[Maximum Product of Two Elements in an Array](/solution/1400-1499/1464.Maximum%20Product%20of%20Two%20Elements%20in%20an%20Array/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1573", "frontend_question_id": "1477", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-two-non-overlapping-sub-arrays-each-with-target-sum", "url_en": "https://leetcode.com/problems/find-two-non-overlapping-sub-arrays-each-with-target-sum", "relative_path_cn": "/solution/1400-1499/1477.Find%20Two%20Non-overlapping%20Sub-arrays%20Each%20With%20Target%20Sum/README.md", "relative_path_en": "/solution/1400-1499/1477.Find%20Two%20Non-overlapping%20Sub-arrays%20Each%20With%20Target%20Sum/README_EN.md", "title_cn": "\u627e\u4e24\u4e2a\u548c\u4e3a\u76ee\u6807\u503c\u4e14\u4e0d\u91cd\u53e0\u7684\u5b50\u6570\u7ec4", "title_en": "Find Two Non-overlapping Sub-arrays Each With Target Sum", "question_title_slug": "find-two-non-overlapping-sub-arrays-each-with-target-sum", "content_en": "

    Given an array of integers arr and an integer target.

    \n\n

    You have to find two non-overlapping sub-arrays of arr each with a sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.

    \n\n

    Return the minimum sum of the lengths of the two required sub-arrays, or return -1 if you cannot find such two sub-arrays.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr = [3,2,2,4,3], target = 3\nOutput: 2\nExplanation: Only two sub-arrays have sum = 3 ([3] and [3]). The sum of their lengths is 2.\n
    \n\n

    Example 2:

    \n\n
    \nInput: arr = [7,3,4,7], target = 7\nOutput: 2\nExplanation: Although we have three non-overlapping sub-arrays of sum = 7 ([7], [3,4] and [7]), but we will choose the first and third sub-arrays as the sum of their lengths is 2.\n
    \n\n

    Example 3:

    \n\n
    \nInput: arr = [4,3,2,6,2,3,4], target = 6\nOutput: -1\nExplanation: We have only one sub-array of sum = 6.\n
    \n\n

    Example 4:

    \n\n
    \nInput: arr = [5,5,4,4,5], target = 3\nOutput: -1\nExplanation: We cannot find a sub-array of sum = 3.\n
    \n\n

    Example 5:

    \n\n
    \nInput: arr = [3,1,1,1,5,1,2,1], target = 3\nOutput: 3\nExplanation: Note that sub-arrays [1,2] and [2,1] cannot be an answer because they overlap.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= arr.length <= 105
    • \n\t
    • 1 <= arr[i] <= 1000
    • \n\t
    • 1 <= target <= 108
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr \u548c\u4e00\u4e2a\u6574\u6570\u503c target \u3002

    \n\n

    \u8bf7\u4f60\u5728 arr \u4e2d\u627e \u4e24\u4e2a\u4e92\u4e0d\u91cd\u53e0\u7684\u5b50\u6570\u7ec4 \u4e14\u5b83\u4eec\u7684\u548c\u90fd\u7b49\u4e8e target \u3002\u53ef\u80fd\u4f1a\u6709\u591a\u79cd\u65b9\u6848\uff0c\u8bf7\u4f60\u8fd4\u56de\u6ee1\u8db3\u8981\u6c42\u7684\u4e24\u4e2a\u5b50\u6570\u7ec4\u957f\u5ea6\u548c\u7684 \u6700\u5c0f\u503c \u3002

    \n\n

    \u8bf7\u8fd4\u56de\u6ee1\u8db3\u8981\u6c42\u7684\u6700\u5c0f\u957f\u5ea6\u548c\uff0c\u5982\u679c\u65e0\u6cd5\u627e\u5230\u8fd9\u6837\u7684\u4e24\u4e2a\u5b50\u6570\u7ec4\uff0c\u8bf7\u8fd4\u56de -1 \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [3,2,2,4,3], target = 3\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u53ea\u6709\u4e24\u4e2a\u5b50\u6570\u7ec4\u548c\u4e3a 3 \uff08[3] \u548c [3]\uff09\u3002\u5b83\u4eec\u7684\u957f\u5ea6\u548c\u4e3a 2 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [7,3,4,7], target = 7\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5c3d\u7ba1\u6211\u4eec\u6709 3 \u4e2a\u4e92\u4e0d\u91cd\u53e0\u7684\u5b50\u6570\u7ec4\u548c\u4e3a 7 \uff08[7], [3,4] \u548c [7]\uff09\uff0c\u4f46\u6211\u4eec\u4f1a\u9009\u62e9\u7b2c\u4e00\u4e2a\u548c\u7b2c\u4e09\u4e2a\u5b50\u6570\u7ec4\uff0c\u56e0\u4e3a\u5b83\u4eec\u7684\u957f\u5ea6\u548c 2 \u662f\u6700\u5c0f\u503c\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [4,3,2,6,2,3,4], target = 6\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u6211\u4eec\u53ea\u6709\u4e00\u4e2a\u548c\u4e3a 6 \u7684\u5b50\u6570\u7ec4\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [5,5,4,4,5], target = 3\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u6211\u4eec\u65e0\u6cd5\u627e\u5230\u548c\u4e3a 3 \u7684\u5b50\u6570\u7ec4\u3002\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [3,1,1,1,5,1,2,1], target = 3\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6ce8\u610f\u5b50\u6570\u7ec4 [1,2] \u548c [2,1] \u4e0d\u80fd\u6210\u4e3a\u4e00\u4e2a\u65b9\u6848\u56e0\u4e3a\u5b83\u4eec\u91cd\u53e0\u4e86\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= arr.length <= 10^5
    • \n\t
    • 1 <= arr[i] <= 1000
    • \n\t
    • 1 <= target <= 10^8
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minSumOfLengths(vector& arr, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minSumOfLengths(int[] arr, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minSumOfLengths(self, arr, target):\n \"\"\"\n :type arr: List[int]\n :type target: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minSumOfLengths(self, arr: List[int], target: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minSumOfLengths(int* arr, int arrSize, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinSumOfLengths(int[] arr, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @param {number} target\n * @return {number}\n */\nvar minSumOfLengths = function(arr, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @param {Integer} target\n# @return {Integer}\ndef min_sum_of_lengths(arr, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minSumOfLengths(_ arr: [Int], _ target: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minSumOfLengths(arr []int, target int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minSumOfLengths(arr: Array[Int], target: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minSumOfLengths(arr: IntArray, target: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_sum_of_lengths(arr: Vec, target: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @param Integer $target\n * @return Integer\n */\n function minSumOfLengths($arr, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minSumOfLengths(arr: number[], target: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-sum-of-lengths arr target)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1477](https://leetcode-cn.com/problems/find-two-non-overlapping-sub-arrays-each-with-target-sum)", "[\u627e\u4e24\u4e2a\u548c\u4e3a\u76ee\u6807\u503c\u4e14\u4e0d\u91cd\u53e0\u7684\u5b50\u6570\u7ec4](/solution/1400-1499/1477.Find%20Two%20Non-overlapping%20Sub-arrays%20Each%20With%20Target%20Sum/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1477](https://leetcode.com/problems/find-two-non-overlapping-sub-arrays-each-with-target-sum)", "[Find Two Non-overlapping Sub-arrays Each With Target Sum](/solution/1400-1499/1477.Find%20Two%20Non-overlapping%20Sub-arrays%20Each%20With%20Target%20Sum/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "1572", "frontend_question_id": "1476", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/subrectangle-queries", "url_en": "https://leetcode.com/problems/subrectangle-queries", "relative_path_cn": "/solution/1400-1499/1476.Subrectangle%20Queries/README.md", "relative_path_en": "/solution/1400-1499/1476.Subrectangle%20Queries/README_EN.md", "title_cn": "\u5b50\u77e9\u5f62\u67e5\u8be2", "title_en": "Subrectangle Queries", "question_title_slug": "subrectangle-queries", "content_en": "

    Implement the class SubrectangleQueries which receives a rows x cols rectangle as a matrix of integers in the constructor and supports two methods:

    \n\n

    1. updateSubrectangle(int row1, int col1, int row2, int col2, int newValue)

    \n\n
      \n\t
    • Updates all values with newValue in the subrectangle whose upper left coordinate is (row1,col1) and bottom right coordinate is (row2,col2).
    • \n
    \n\n

    2. getValue(int row, int col)

    \n\n
      \n\t
    • Returns the current value of the coordinate (row,col) from the rectangle.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["SubrectangleQueries","getValue","updateSubrectangle","getValue","getValue","updateSubrectangle","getValue","getValue"]\n[[[[1,2,1],[4,3,4],[3,2,1],[1,1,1]]],[0,2],[0,0,3,2,5],[0,2],[3,1],[3,0,3,2,10],[3,1],[0,2]]\nOutput\n[null,1,null,5,5,null,10,5]\nExplanation\nSubrectangleQueries subrectangleQueries = new SubrectangleQueries([[1,2,1],[4,3,4],[3,2,1],[1,1,1]]);  \n// The initial rectangle (4x3) looks like:\n// 1 2 1\n// 4 3 4\n// 3 2 1\n// 1 1 1\nsubrectangleQueries.getValue(0, 2); // return 1\nsubrectangleQueries.updateSubrectangle(0, 0, 3, 2, 5);\n// After this update the rectangle looks like:\n// 5 5 5\n// 5 5 5\n// 5 5 5\n// 5 5 5 \nsubrectangleQueries.getValue(0, 2); // return 5\nsubrectangleQueries.getValue(3, 1); // return 5\nsubrectangleQueries.updateSubrectangle(3, 0, 3, 2, 10);\n// After this update the rectangle looks like:\n// 5   5   5\n// 5   5   5\n// 5   5   5\n// 10  10  10 \nsubrectangleQueries.getValue(3, 1); // return 10\nsubrectangleQueries.getValue(0, 2); // return 5\n
    \n\n

    Example 2:

    \n\n
    \nInput\n["SubrectangleQueries","getValue","updateSubrectangle","getValue","getValue","updateSubrectangle","getValue"]\n[[[[1,1,1],[2,2,2],[3,3,3]]],[0,0],[0,0,2,2,100],[0,0],[2,2],[1,1,2,2,20],[2,2]]\nOutput\n[null,1,null,100,100,null,20]\nExplanation\nSubrectangleQueries subrectangleQueries = new SubrectangleQueries([[1,1,1],[2,2,2],[3,3,3]]);\nsubrectangleQueries.getValue(0, 0); // return 1\nsubrectangleQueries.updateSubrectangle(0, 0, 2, 2, 100);\nsubrectangleQueries.getValue(0, 0); // return 100\nsubrectangleQueries.getValue(2, 2); // return 100\nsubrectangleQueries.updateSubrectangle(1, 1, 2, 2, 20);\nsubrectangleQueries.getValue(2, 2); // return 20\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • There will be at most 500 operations considering both methods: updateSubrectangle and getValue.
    • \n\t
    • 1 <= rows, cols <= 100
    • \n\t
    • rows == rectangle.length
    • \n\t
    • cols == rectangle[i].length
    • \n\t
    • 0 <= row1 <= row2 < rows
    • \n\t
    • 0 <= col1 <= col2 < cols
    • \n\t
    • 1 <= newValue, rectangle[i][j] <= 10^9
    • \n\t
    • 0 <= row < rows
    • \n\t
    • 0 <= col < cols
    • \n
    \n", "content_cn": "

    \u8bf7\u4f60\u5b9e\u73b0\u4e00\u4e2a\u7c7b SubrectangleQueries \uff0c\u5b83\u7684\u6784\u9020\u51fd\u6570\u7684\u53c2\u6570\u662f\u4e00\u4e2a rows x cols \u7684\u77e9\u5f62\uff08\u8fd9\u91cc\u7528\u6574\u6570\u77e9\u9635\u8868\u793a\uff09\uff0c\u5e76\u652f\u6301\u4ee5\u4e0b\u4e24\u79cd\u64cd\u4f5c\uff1a

    \n\n

    1. updateSubrectangle(int row1, int col1, int row2, int col2, int newValue)

    \n\n
      \n\t
    • \u7528 newValue \u66f4\u65b0\u4ee5 (row1,col1) \u4e3a\u5de6\u4e0a\u89d2\u4e14\u4ee5 (row2,col2) \u4e3a\u53f3\u4e0b\u89d2\u7684\u5b50\u77e9\u5f62\u3002
    • \n
    \n\n

    2. getValue(int row, int col)

    \n\n
      \n\t
    • \u8fd4\u56de\u77e9\u5f62\u4e2d\u5750\u6807 (row,col) \u7684\u5f53\u524d\u503c\u3002
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a\n["SubrectangleQueries","getValue","updateSubrectangle","getValue","getValue","updateSubrectangle","getValue","getValue"]\n[[[[1,2,1],[4,3,4],[3,2,1],[1,1,1]]],[0,2],[0,0,3,2,5],[0,2],[3,1],[3,0,3,2,10],[3,1],[0,2]]\n\u8f93\u51fa\uff1a\n[null,1,null,5,5,null,10,5]\n\u89e3\u91ca\uff1a\nSubrectangleQueries subrectangleQueries = new SubrectangleQueries([[1,2,1],[4,3,4],[3,2,1],[1,1,1]]);  \n// \u521d\u59cb\u7684 (4x3) \u77e9\u5f62\u5982\u4e0b\uff1a\n// 1 2 1\n// 4 3 4\n// 3 2 1\n// 1 1 1\nsubrectangleQueries.getValue(0, 2); // \u8fd4\u56de 1\nsubrectangleQueries.updateSubrectangle(0, 0, 3, 2, 5);\n// \u6b64\u6b21\u66f4\u65b0\u540e\u77e9\u5f62\u53d8\u4e3a\uff1a\n// 5 5 5\n// 5 5 5\n// 5 5 5\n// 5 5 5 \nsubrectangleQueries.getValue(0, 2); // \u8fd4\u56de 5\nsubrectangleQueries.getValue(3, 1); // \u8fd4\u56de 5\nsubrectangleQueries.updateSubrectangle(3, 0, 3, 2, 10);\n// \u6b64\u6b21\u66f4\u65b0\u540e\u77e9\u5f62\u53d8\u4e3a\uff1a\n// 5   5   5\n// 5   5   5\n// 5   5   5\n// 10  10  10 \nsubrectangleQueries.getValue(3, 1); // \u8fd4\u56de 10\nsubrectangleQueries.getValue(0, 2); // \u8fd4\u56de 5\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a\n["SubrectangleQueries","getValue","updateSubrectangle","getValue","getValue","updateSubrectangle","getValue"]\n[[[[1,1,1],[2,2,2],[3,3,3]]],[0,0],[0,0,2,2,100],[0,0],[2,2],[1,1,2,2,20],[2,2]]\n\u8f93\u51fa\uff1a\n[null,1,null,100,100,null,20]\n\u89e3\u91ca\uff1a\nSubrectangleQueries subrectangleQueries = new SubrectangleQueries([[1,1,1],[2,2,2],[3,3,3]]);\nsubrectangleQueries.getValue(0, 0); // \u8fd4\u56de 1\nsubrectangleQueries.updateSubrectangle(0, 0, 2, 2, 100);\nsubrectangleQueries.getValue(0, 0); // \u8fd4\u56de 100\nsubrectangleQueries.getValue(2, 2); // \u8fd4\u56de 100\nsubrectangleQueries.updateSubrectangle(1, 1, 2, 2, 20);\nsubrectangleQueries.getValue(2, 2); // \u8fd4\u56de 20\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6700\u591a\u6709 500 \u6b21updateSubrectangle \u548c getValue \u64cd\u4f5c\u3002
    • \n\t
    • 1 <= rows, cols <= 100
    • \n\t
    • rows == rectangle.length
    • \n\t
    • cols == rectangle[i].length
    • \n\t
    • 0 <= row1 <= row2 < rows
    • \n\t
    • 0 <= col1 <= col2 < cols
    • \n\t
    • 1 <= newValue, rectangle[i][j] <= 10^9
    • \n\t
    • 0 <= row < rows
    • \n\t
    • 0 <= col < cols
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class SubrectangleQueries {\npublic:\n SubrectangleQueries(vector>& rectangle) {\n\n }\n \n void updateSubrectangle(int row1, int col1, int row2, int col2, int newValue) {\n\n }\n \n int getValue(int row, int col) {\n\n }\n};\n\n/**\n * Your SubrectangleQueries object will be instantiated and called as such:\n * SubrectangleQueries* obj = new SubrectangleQueries(rectangle);\n * obj->updateSubrectangle(row1,col1,row2,col2,newValue);\n * int param_2 = obj->getValue(row,col);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class SubrectangleQueries {\n\n public SubrectangleQueries(int[][] rectangle) {\n\n }\n \n public void updateSubrectangle(int row1, int col1, int row2, int col2, int newValue) {\n\n }\n \n public int getValue(int row, int col) {\n\n }\n}\n\n/**\n * Your SubrectangleQueries object will be instantiated and called as such:\n * SubrectangleQueries obj = new SubrectangleQueries(rectangle);\n * obj.updateSubrectangle(row1,col1,row2,col2,newValue);\n * int param_2 = obj.getValue(row,col);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class SubrectangleQueries(object):\n\n def __init__(self, rectangle):\n \"\"\"\n :type rectangle: List[List[int]]\n \"\"\"\n\n\n def updateSubrectangle(self, row1, col1, row2, col2, newValue):\n \"\"\"\n :type row1: int\n :type col1: int\n :type row2: int\n :type col2: int\n :type newValue: int\n :rtype: None\n \"\"\"\n\n\n def getValue(self, row, col):\n \"\"\"\n :type row: int\n :type col: int\n :rtype: int\n \"\"\"\n\n\n\n# Your SubrectangleQueries object will be instantiated and called as such:\n# obj = SubrectangleQueries(rectangle)\n# obj.updateSubrectangle(row1,col1,row2,col2,newValue)\n# param_2 = obj.getValue(row,col)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class SubrectangleQueries:\n\n def __init__(self, rectangle: List[List[int]]):\n\n\n def updateSubrectangle(self, row1: int, col1: int, row2: int, col2: int, newValue: int) -> None:\n\n\n def getValue(self, row: int, col: int) -> int:\n\n\n\n# Your SubrectangleQueries object will be instantiated and called as such:\n# obj = SubrectangleQueries(rectangle)\n# obj.updateSubrectangle(row1,col1,row2,col2,newValue)\n# param_2 = obj.getValue(row,col)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} SubrectangleQueries;\n\n\nSubrectangleQueries* subrectangleQueriesCreate(int** rectangle, int rectangleSize, int* rectangleColSize) {\n\n}\n\nvoid subrectangleQueriesUpdateSubrectangle(SubrectangleQueries* obj, int row1, int col1, int row2, int col2, int newValue) {\n\n}\n\nint subrectangleQueriesGetValue(SubrectangleQueries* obj, int row, int col) {\n\n}\n\nvoid subrectangleQueriesFree(SubrectangleQueries* obj) {\n\n}\n\n/**\n * Your SubrectangleQueries struct will be instantiated and called as such:\n * SubrectangleQueries* obj = subrectangleQueriesCreate(rectangle, rectangleSize, rectangleColSize);\n * subrectangleQueriesUpdateSubrectangle(obj, row1, col1, row2, col2, newValue);\n \n * int param_2 = subrectangleQueriesGetValue(obj, row, col);\n \n * subrectangleQueriesFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class SubrectangleQueries {\n\n public SubrectangleQueries(int[][] rectangle) {\n\n }\n \n public void UpdateSubrectangle(int row1, int col1, int row2, int col2, int newValue) {\n\n }\n \n public int GetValue(int row, int col) {\n\n }\n}\n\n/**\n * Your SubrectangleQueries object will be instantiated and called as such:\n * SubrectangleQueries obj = new SubrectangleQueries(rectangle);\n * obj.UpdateSubrectangle(row1,col1,row2,col2,newValue);\n * int param_2 = obj.GetValue(row,col);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} rectangle\n */\nvar SubrectangleQueries = function(rectangle) {\n\n};\n\n/** \n * @param {number} row1 \n * @param {number} col1 \n * @param {number} row2 \n * @param {number} col2 \n * @param {number} newValue\n * @return {void}\n */\nSubrectangleQueries.prototype.updateSubrectangle = function(row1, col1, row2, col2, newValue) {\n\n};\n\n/** \n * @param {number} row \n * @param {number} col\n * @return {number}\n */\nSubrectangleQueries.prototype.getValue = function(row, col) {\n\n};\n\n/**\n * Your SubrectangleQueries object will be instantiated and called as such:\n * var obj = new SubrectangleQueries(rectangle)\n * obj.updateSubrectangle(row1,col1,row2,col2,newValue)\n * var param_2 = obj.getValue(row,col)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class SubrectangleQueries\n\n=begin\n :type rectangle: Integer[][]\n=end\n def initialize(rectangle)\n\n end\n\n\n=begin\n :type row1: Integer\n :type col1: Integer\n :type row2: Integer\n :type col2: Integer\n :type new_value: Integer\n :rtype: Void\n=end\n def update_subrectangle(row1, col1, row2, col2, new_value)\n\n end\n\n\n=begin\n :type row: Integer\n :type col: Integer\n :rtype: Integer\n=end\n def get_value(row, col)\n\n end\n\n\nend\n\n# Your SubrectangleQueries object will be instantiated and called as such:\n# obj = SubrectangleQueries.new(rectangle)\n# obj.update_subrectangle(row1, col1, row2, col2, new_value)\n# param_2 = obj.get_value(row, col)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass SubrectangleQueries {\n\n init(_ rectangle: [[Int]]) {\n\n }\n \n func updateSubrectangle(_ row1: Int, _ col1: Int, _ row2: Int, _ col2: Int, _ newValue: Int) {\n\n }\n \n func getValue(_ row: Int, _ col: Int) -> Int {\n\n }\n}\n\n/**\n * Your SubrectangleQueries object will be instantiated and called as such:\n * let obj = SubrectangleQueries(rectangle)\n * obj.updateSubrectangle(row1, col1, row2, col2, newValue)\n * let ret_2: Int = obj.getValue(row, col)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type SubrectangleQueries struct {\n\n}\n\n\nfunc Constructor(rectangle [][]int) SubrectangleQueries {\n\n}\n\n\nfunc (this *SubrectangleQueries) UpdateSubrectangle(row1 int, col1 int, row2 int, col2 int, newValue int) {\n\n}\n\n\nfunc (this *SubrectangleQueries) GetValue(row int, col int) int {\n\n}\n\n\n/**\n * Your SubrectangleQueries object will be instantiated and called as such:\n * obj := Constructor(rectangle);\n * obj.UpdateSubrectangle(row1,col1,row2,col2,newValue);\n * param_2 := obj.GetValue(row,col);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class SubrectangleQueries(_rectangle: Array[Array[Int]]) {\n\n def updateSubrectangle(row1: Int, col1: Int, row2: Int, col2: Int, newValue: Int) {\n\n }\n\n def getValue(row: Int, col: Int): Int = {\n\n }\n\n}\n\n/**\n * Your SubrectangleQueries object will be instantiated and called as such:\n * var obj = new SubrectangleQueries(rectangle)\n * obj.updateSubrectangle(row1,col1,row2,col2,newValue)\n * var param_2 = obj.getValue(row,col)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class SubrectangleQueries(rectangle: Array) {\n\n fun updateSubrectangle(row1: Int, col1: Int, row2: Int, col2: Int, newValue: Int) {\n\n }\n\n fun getValue(row: Int, col: Int): Int {\n\n }\n\n}\n\n/**\n * Your SubrectangleQueries object will be instantiated and called as such:\n * var obj = SubrectangleQueries(rectangle)\n * obj.updateSubrectangle(row1,col1,row2,col2,newValue)\n * var param_2 = obj.getValue(row,col)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct SubrectangleQueries {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl SubrectangleQueries {\n\n fn new(rectangle: Vec>) -> Self {\n\n }\n \n fn update_subrectangle(&self, row1: i32, col1: i32, row2: i32, col2: i32, new_value: i32) {\n\n }\n \n fn get_value(&self, row: i32, col: i32) -> i32 {\n\n }\n}\n\n/**\n * Your SubrectangleQueries object will be instantiated and called as such:\n * let obj = SubrectangleQueries::new(rectangle);\n * obj.update_subrectangle(row1, col1, row2, col2, newValue);\n * let ret_2: i32 = obj.get_value(row, col);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class SubrectangleQueries {\n /**\n * @param Integer[][] $rectangle\n */\n function __construct($rectangle) {\n\n }\n\n /**\n * @param Integer $row1\n * @param Integer $col1\n * @param Integer $row2\n * @param Integer $col2\n * @param Integer $newValue\n * @return NULL\n */\n function updateSubrectangle($row1, $col1, $row2, $col2, $newValue) {\n\n }\n\n /**\n * @param Integer $row\n * @param Integer $col\n * @return Integer\n */\n function getValue($row, $col) {\n\n }\n}\n\n/**\n * Your SubrectangleQueries object will be instantiated and called as such:\n * $obj = SubrectangleQueries($rectangle);\n * $obj->updateSubrectangle($row1, $col1, $row2, $col2, $newValue);\n * $ret_2 = $obj->getValue($row, $col);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class SubrectangleQueries {\n constructor(rectangle: number[][]) {\n\n }\n\n updateSubrectangle(row1: number, col1: number, row2: number, col2: number, newValue: number): void {\n\n }\n\n getValue(row: number, col: number): number {\n\n }\n}\n\n/**\n * Your SubrectangleQueries object will be instantiated and called as such:\n * var obj = new SubrectangleQueries(rectangle)\n * obj.updateSubrectangle(row1,col1,row2,col2,newValue)\n * var param_2 = obj.getValue(row,col)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define subrectangle-queries%\n (class object%\n (super-new)\n\n ; rectangle : (listof (listof exact-integer?))\n (init-field\n rectangle)\n \n ; update-subrectangle : exact-integer? exact-integer? exact-integer? exact-integer? exact-integer? -> void?\n (define/public (update-subrectangle row1 col1 row2 col2 newValue)\n\n )\n ; get-value : exact-integer? exact-integer? -> exact-integer?\n (define/public (get-value row col)\n\n )))\n\n;; Your subrectangle-queries% object will be instantiated and called as such:\n;; (define obj (new subrectangle-queries% [rectangle rectangle]))\n;; (send obj update-subrectangle row1 col1 row2 col2 new-value)\n;; (define param_2 (send obj get-value row col))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1476](https://leetcode-cn.com/problems/subrectangle-queries)", "[\u5b50\u77e9\u5f62\u67e5\u8be2](/solution/1400-1499/1476.Subrectangle%20Queries/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1476](https://leetcode.com/problems/subrectangle-queries)", "[Subrectangle Queries](/solution/1400-1499/1476.Subrectangle%20Queries/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "1571", "frontend_question_id": "1478", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/allocate-mailboxes", "url_en": "https://leetcode.com/problems/allocate-mailboxes", "relative_path_cn": "/solution/1400-1499/1478.Allocate%20Mailboxes/README.md", "relative_path_en": "/solution/1400-1499/1478.Allocate%20Mailboxes/README_EN.md", "title_cn": "\u5b89\u6392\u90ae\u7b52", "title_en": "Allocate Mailboxes", "question_title_slug": "allocate-mailboxes", "content_en": "

    Given the array houses and an integer k. where houses[i] is the location of the ith house along a street, your task is to allocate k mailboxes in the street.

    \r\n\r\n

    Return the minimum total distance between each house and its nearest mailbox.

    \r\n\r\n

    The answer is guaranteed to fit in a 32-bit signed integer.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n

    \"\"

    \r\n\r\n
    \r\nInput: houses = [1,4,8,10,20], k = 3\r\nOutput: 5\r\nExplanation: Allocate mailboxes in position 3, 9 and 20.\r\nMinimum total distance from each houses to nearest mailboxes is |3-1| + |4-3| + |9-8| + |10-9| + |20-20| = 5 \r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n

    \"\"

    \r\n\r\n
    \r\nInput: houses = [2,3,5,12,18], k = 2\r\nOutput: 9\r\nExplanation: Allocate mailboxes in position 3 and 14.\r\nMinimum total distance from each houses to nearest mailboxes is |2-3| + |3-3| + |5-3| + |12-14| + |18-14| = 9.\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: houses = [7,4,6,1], k = 1\r\nOutput: 8\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: houses = [3,6,14,10], k = 4\r\nOutput: 0\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • n == houses.length
    • \r\n\t
    • 1 <= n <= 100
    • \r\n\t
    • 1 <= houses[i] <= 10^4
    • \r\n\t
    • 1 <= k <= n
    • \r\n\t
    • Array houses contain unique integers.
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u623f\u5c4b\u6570\u7ec4houses \u548c\u4e00\u4e2a\u6574\u6570 k \uff0c\u5176\u4e2d houses[i] \u662f\u7b2c i \u680b\u623f\u5b50\u5728\u4e00\u6761\u8857\u4e0a\u7684\u4f4d\u7f6e\uff0c\u73b0\u9700\u8981\u5728\u8fd9\u6761\u8857\u4e0a\u5b89\u6392 k \u4e2a\u90ae\u7b52\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u6bcf\u680b\u623f\u5b50\u4e0e\u79bb\u5b83\u6700\u8fd1\u7684\u90ae\u7b52\u4e4b\u95f4\u7684\u8ddd\u79bb\u7684 \u6700\u5c0f \u603b\u548c\u3002

    \n\n

    \u7b54\u6848\u4fdd\u8bc1\u5728 32 \u4f4d\u6709\u7b26\u53f7\u6574\u6570\u8303\u56f4\u4ee5\u5185\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1ahouses = [1,4,8,10,20], k = 3\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u5c06\u90ae\u7b52\u5206\u522b\u5b89\u653e\u5728\u4f4d\u7f6e 3\uff0c 9 \u548c 20 \u5904\u3002\n\u6bcf\u4e2a\u623f\u5b50\u5230\u6700\u8fd1\u90ae\u7b52\u7684\u8ddd\u79bb\u548c\u4e3a |3-1| + |4-3| + |9-8| + |10-9| + |20-20| = 5 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1ahouses = [2,3,5,12,18], k = 2\n\u8f93\u51fa\uff1a9\n\u89e3\u91ca\uff1a\u5c06\u90ae\u7b52\u5206\u522b\u5b89\u653e\u5728\u4f4d\u7f6e 3 \u548c 14 \u5904\u3002\n\u6bcf\u4e2a\u623f\u5b50\u5230\u6700\u8fd1\u90ae\u7b52\u8ddd\u79bb\u548c\u4e3a |2-3| + |3-3| + |5-3| + |12-14| + |18-14| = 9 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1ahouses = [7,4,6,1], k = 1\n\u8f93\u51fa\uff1a8\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1ahouses = [3,6,14,10], k = 4\n\u8f93\u51fa\uff1a0\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == houses.length
    • \n\t
    • 1 <= n <= 100
    • \n\t
    • 1 <= houses[i] <= 10^4
    • \n\t
    • 1 <= k <= n
    • \n\t
    • \u6570\u7ec4 houses \u4e2d\u7684\u6574\u6570\u4e92\u4e0d\u76f8\u540c\u3002
    • \n
    \n", "tags_en": ["Math", "Dynamic Programming"], "tags_cn": ["\u6570\u5b66", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minDistance(vector& houses, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minDistance(int[] houses, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minDistance(self, houses, k):\n \"\"\"\n :type houses: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minDistance(self, houses: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minDistance(int* houses, int housesSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinDistance(int[] houses, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} houses\n * @param {number} k\n * @return {number}\n */\nvar minDistance = function(houses, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} houses\n# @param {Integer} k\n# @return {Integer}\ndef min_distance(houses, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minDistance(_ houses: [Int], _ k: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minDistance(houses []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minDistance(houses: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minDistance(houses: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_distance(houses: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $houses\n * @param Integer $k\n * @return Integer\n */\n function minDistance($houses, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minDistance(houses: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-distance houses k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1478](https://leetcode-cn.com/problems/allocate-mailboxes)", "[\u5b89\u6392\u90ae\u7b52](/solution/1400-1499/1478.Allocate%20Mailboxes/README.md)", "`\u6570\u5b66`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1478](https://leetcode.com/problems/allocate-mailboxes)", "[Allocate Mailboxes](/solution/1400-1499/1478.Allocate%20Mailboxes/README_EN.md)", "`Math`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "1570", "frontend_question_id": "1475", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/final-prices-with-a-special-discount-in-a-shop", "url_en": "https://leetcode.com/problems/final-prices-with-a-special-discount-in-a-shop", "relative_path_cn": "/solution/1400-1499/1475.Final%20Prices%20With%20a%20Special%20Discount%20in%20a%20Shop/README.md", "relative_path_en": "/solution/1400-1499/1475.Final%20Prices%20With%20a%20Special%20Discount%20in%20a%20Shop/README_EN.md", "title_cn": "\u5546\u54c1\u6298\u6263\u540e\u7684\u6700\u7ec8\u4ef7\u683c", "title_en": "Final Prices With a Special Discount in a Shop", "question_title_slug": "final-prices-with-a-special-discount-in-a-shop", "content_en": "

    Given the array prices where prices[i] is the price of the ith item in a shop. There is a special discount for items in the shop, if you buy the ith item, then you will receive a discount equivalent to prices[j] where j is the minimum index such that j > i and prices[j] <= prices[i], otherwise, you will not receive any discount at all.

    \n\n

    Return an array where the ith element is the final price you will pay for the ith item of the shop considering the special discount.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: prices = [8,4,6,2,3]\nOutput: [4,2,4,2,3]\nExplanation: \nFor item 0 with price[0]=8 you will receive a discount equivalent to prices[1]=4, therefore, the final price you will pay is 8 - 4 = 4. \nFor item 1 with price[1]=4 you will receive a discount equivalent to prices[3]=2, therefore, the final price you will pay is 4 - 2 = 2. \nFor item 2 with price[2]=6 you will receive a discount equivalent to prices[3]=2, therefore, the final price you will pay is 6 - 2 = 4. \nFor items 3 and 4 you will not receive any discount at all.\n
    \n\n

    Example 2:

    \n\n
    \nInput: prices = [1,2,3,4,5]\nOutput: [1,2,3,4,5]\nExplanation: In this case, for all items, you will not receive any discount at all.\n
    \n\n

    Example 3:

    \n\n
    \nInput: prices = [10,1,1,6]\nOutput: [9,0,1,6]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= prices.length <= 500
    • \n\t
    • 1 <= prices[i] <= 10^3
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 prices \uff0c\u5176\u4e2d prices[i] \u662f\u5546\u5e97\u91cc\u7b2c i \u4ef6\u5546\u54c1\u7684\u4ef7\u683c\u3002

    \n\n

    \u5546\u5e97\u91cc\u6b63\u5728\u8fdb\u884c\u4fc3\u9500\u6d3b\u52a8\uff0c\u5982\u679c\u4f60\u8981\u4e70\u7b2c i \u4ef6\u5546\u54c1\uff0c\u90a3\u4e48\u4f60\u53ef\u4ee5\u5f97\u5230\u4e0e prices[j] \u76f8\u7b49\u7684\u6298\u6263\uff0c\u5176\u4e2d j \u662f\u6ee1\u8db3 j > i \u4e14 prices[j] <= prices[i] \u7684 \u6700\u5c0f\u4e0b\u6807 \uff0c\u5982\u679c\u6ca1\u6709\u6ee1\u8db3\u6761\u4ef6\u7684 j \uff0c\u4f60\u5c06\u6ca1\u6709\u4efb\u4f55\u6298\u6263\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u4e00\u4e2a\u6570\u7ec4\uff0c\u6570\u7ec4\u4e2d\u7b2c i \u4e2a\u5143\u7d20\u662f\u6298\u6263\u540e\u4f60\u8d2d\u4e70\u5546\u54c1 i \u6700\u7ec8\u9700\u8981\u652f\u4ed8\u7684\u4ef7\u683c\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aprices = [8,4,6,2,3]\n\u8f93\u51fa\uff1a[4,2,4,2,3]\n\u89e3\u91ca\uff1a\n\u5546\u54c1 0 \u7684\u4ef7\u683c\u4e3a price[0]=8 \uff0c\u4f60\u5c06\u5f97\u5230 prices[1]=4 \u7684\u6298\u6263\uff0c\u6240\u4ee5\u6700\u7ec8\u4ef7\u683c\u4e3a 8 - 4 = 4 \u3002\n\u5546\u54c1 1 \u7684\u4ef7\u683c\u4e3a price[1]=4 \uff0c\u4f60\u5c06\u5f97\u5230 prices[3]=2 \u7684\u6298\u6263\uff0c\u6240\u4ee5\u6700\u7ec8\u4ef7\u683c\u4e3a 4 - 2 = 2 \u3002\n\u5546\u54c1 2 \u7684\u4ef7\u683c\u4e3a price[2]=6 \uff0c\u4f60\u5c06\u5f97\u5230 prices[3]=2 \u7684\u6298\u6263\uff0c\u6240\u4ee5\u6700\u7ec8\u4ef7\u683c\u4e3a 6 - 2 = 4 \u3002\n\u5546\u54c1 3 \u548c 4 \u90fd\u6ca1\u6709\u6298\u6263\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aprices = [1,2,3,4,5]\n\u8f93\u51fa\uff1a[1,2,3,4,5]\n\u89e3\u91ca\uff1a\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6240\u6709\u5546\u54c1\u90fd\u6ca1\u6709\u6298\u6263\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aprices = [10,1,1,6]\n\u8f93\u51fa\uff1a[9,0,1,6]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= prices.length <= 500
    • \n\t
    • 1 <= prices[i] <= 10^3
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector finalPrices(vector& prices) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] finalPrices(int[] prices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def finalPrices(self, prices):\n \"\"\"\n :type prices: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def finalPrices(self, prices: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* finalPrices(int* prices, int pricesSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] FinalPrices(int[] prices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} prices\n * @return {number[]}\n */\nvar finalPrices = function(prices) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} prices\n# @return {Integer[]}\ndef final_prices(prices)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func finalPrices(_ prices: [Int]) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func finalPrices(prices []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def finalPrices(prices: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun finalPrices(prices: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn final_prices(prices: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $prices\n * @return Integer[]\n */\n function finalPrices($prices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function finalPrices(prices: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (final-prices prices)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1475](https://leetcode-cn.com/problems/final-prices-with-a-special-discount-in-a-shop)", "[\u5546\u54c1\u6298\u6263\u540e\u7684\u6700\u7ec8\u4ef7\u683c](/solution/1400-1499/1475.Final%20Prices%20With%20a%20Special%20Discount%20in%20a%20Shop/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1475](https://leetcode.com/problems/final-prices-with-a-special-discount-in-a-shop)", "[Final Prices With a Special Discount in a Shop](/solution/1400-1499/1475.Final%20Prices%20With%20a%20Special%20Discount%20in%20a%20Shop/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1569", "frontend_question_id": "1458", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/max-dot-product-of-two-subsequences", "url_en": "https://leetcode.com/problems/max-dot-product-of-two-subsequences", "relative_path_cn": "/solution/1400-1499/1458.Max%20Dot%20Product%20of%20Two%20Subsequences/README.md", "relative_path_en": "/solution/1400-1499/1458.Max%20Dot%20Product%20of%20Two%20Subsequences/README_EN.md", "title_cn": "\u4e24\u4e2a\u5b50\u5e8f\u5217\u7684\u6700\u5927\u70b9\u79ef", "title_en": "Max Dot Product of Two Subsequences", "question_title_slug": "max-dot-product-of-two-subsequences", "content_en": "

    Given two arrays nums1 and nums2.

    \n\n

    Return the maximum dot product between non-empty subsequences of nums1 and nums2 with the same length.

    \n\n

    A subsequence of a array is a new array which is formed from the original array by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (ie, [2,3,5] is a subsequence of [1,2,3,4,5] while [1,5,3] is not).

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums1 = [2,1,-2,5], nums2 = [3,0,-6]\nOutput: 18\nExplanation: Take subsequence [2,-2] from nums1 and subsequence [3,-6] from nums2.\nTheir dot product is (2*3 + (-2)*(-6)) = 18.
    \n\n

    Example 2:

    \n\n
    \nInput: nums1 = [3,-2], nums2 = [2,-6,7]\nOutput: 21\nExplanation: Take subsequence [3] from nums1 and subsequence [7] from nums2.\nTheir dot product is (3*7) = 21.
    \n\n

    Example 3:

    \n\n
    \nInput: nums1 = [-1,-1], nums2 = [1,1]\nOutput: -1\nExplanation: Take subsequence [-1] from nums1 and subsequence [1] from nums2.\nTheir dot product is -1.
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums1.length, nums2.length <= 500
    • \n\t
    • -1000 <= nums1[i], nums2[i] <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u6570\u7ec4 nums1 \u548c nums2 \u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de nums1 \u548c nums2 \u4e2d\u4e24\u4e2a\u957f\u5ea6\u76f8\u540c\u7684 \u975e\u7a7a \u5b50\u5e8f\u5217\u7684\u6700\u5927\u70b9\u79ef\u3002

    \n\n

    \u6570\u7ec4\u7684\u975e\u7a7a\u5b50\u5e8f\u5217\u662f\u901a\u8fc7\u5220\u9664\u539f\u6570\u7ec4\u4e2d\u67d0\u4e9b\u5143\u7d20\uff08\u53ef\u80fd\u4e00\u4e2a\u4e5f\u4e0d\u5220\u9664\uff09\u540e\u5269\u4f59\u6570\u5b57\u7ec4\u6210\u7684\u5e8f\u5217\uff0c\u4f46\u4e0d\u80fd\u6539\u53d8\u6570\u5b57\u95f4\u76f8\u5bf9\u987a\u5e8f\u3002\u6bd4\u65b9\u8bf4\uff0c[2,3,5] \u662f [1,2,3,4,5] \u7684\u4e00\u4e2a\u5b50\u5e8f\u5217\u800c [1,5,3] \u4e0d\u662f\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums1 = [2,1,-2,5], nums2 = [3,0,-6]\n\u8f93\u51fa\uff1a18\n\u89e3\u91ca\uff1a\u4ece nums1 \u4e2d\u5f97\u5230\u5b50\u5e8f\u5217 [2,-2] \uff0c\u4ece nums2 \u4e2d\u5f97\u5230\u5b50\u5e8f\u5217 [3,-6] \u3002\n\u5b83\u4eec\u7684\u70b9\u79ef\u4e3a (2*3 + (-2)*(-6)) = 18 \u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums1 = [3,-2], nums2 = [2,-6,7]\n\u8f93\u51fa\uff1a21\n\u89e3\u91ca\uff1a\u4ece nums1 \u4e2d\u5f97\u5230\u5b50\u5e8f\u5217 [3] \uff0c\u4ece nums2 \u4e2d\u5f97\u5230\u5b50\u5e8f\u5217 [7] \u3002\n\u5b83\u4eec\u7684\u70b9\u79ef\u4e3a (3*7) = 21 \u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums1 = [-1,-1], nums2 = [1,1]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u4ece nums1 \u4e2d\u5f97\u5230\u5b50\u5e8f\u5217 [-1] \uff0c\u4ece nums2 \u4e2d\u5f97\u5230\u5b50\u5e8f\u5217 [1] \u3002\n\u5b83\u4eec\u7684\u70b9\u79ef\u4e3a -1 \u3002
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums1.length, nums2.length <= 500
    • \n\t
    • -1000 <= nums1[i], nums2[i] <= 100
    • \n
    \n\n

     

    \n\n

    \u70b9\u79ef\uff1a

    \n\n
    \n\u5b9a\u4e49 a = [a1a2,…, an] \u548c b = [b1b2,…, bn] \u7684\u70b9\u79ef\u4e3a\uff1a\n\n\"\\mathbf{a}\\cdot\n\n\u8fd9\u91cc\u7684 Σ \u6307\u793a\u603b\u548c\u7b26\u53f7\u3002\n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxDotProduct(vector& nums1, vector& nums2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxDotProduct(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxDotProduct(self, nums1, nums2):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxDotProduct(self, nums1: List[int], nums2: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxDotProduct(int* nums1, int nums1Size, int* nums2, int nums2Size){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxDotProduct(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums1\n * @param {number[]} nums2\n * @return {number}\n */\nvar maxDotProduct = function(nums1, nums2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums1\n# @param {Integer[]} nums2\n# @return {Integer}\ndef max_dot_product(nums1, nums2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxDotProduct(_ nums1: [Int], _ nums2: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxDotProduct(nums1 []int, nums2 []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxDotProduct(nums1: Array[Int], nums2: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxDotProduct(nums1: IntArray, nums2: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_dot_product(nums1: Vec, nums2: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums1\n * @param Integer[] $nums2\n * @return Integer\n */\n function maxDotProduct($nums1, $nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxDotProduct(nums1: number[], nums2: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-dot-product nums1 nums2)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1458](https://leetcode-cn.com/problems/max-dot-product-of-two-subsequences)", "[\u4e24\u4e2a\u5b50\u5e8f\u5217\u7684\u6700\u5927\u70b9\u79ef](/solution/1400-1499/1458.Max%20Dot%20Product%20of%20Two%20Subsequences/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1458](https://leetcode.com/problems/max-dot-product-of-two-subsequences)", "[Max Dot Product of Two Subsequences](/solution/1400-1499/1458.Max%20Dot%20Product%20of%20Two%20Subsequences/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1568", "frontend_question_id": "1457", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/pseudo-palindromic-paths-in-a-binary-tree", "url_en": "https://leetcode.com/problems/pseudo-palindromic-paths-in-a-binary-tree", "relative_path_cn": "/solution/1400-1499/1457.Pseudo-Palindromic%20Paths%20in%20a%20Binary%20Tree/README.md", "relative_path_en": "/solution/1400-1499/1457.Pseudo-Palindromic%20Paths%20in%20a%20Binary%20Tree/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u4e2d\u7684\u4f2a\u56de\u6587\u8def\u5f84", "title_en": "Pseudo-Palindromic Paths in a Binary Tree", "question_title_slug": "pseudo-palindromic-paths-in-a-binary-tree", "content_en": "

    Given a binary tree where node values are digits from 1 to 9. A path in the binary tree is said to be pseudo-palindromic if at least one permutation of the node values in the path is a palindrome.

    \n\n

    Return the number of pseudo-palindromic paths going from the root node to leaf nodes.

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: root = [2,3,1,3,1,null,1]\nOutput: 2 \nExplanation: The figure above represents the given binary tree. There are three paths going from the root node to leaf nodes: the red path [2,3,3], the green path [2,1,1], and the path [2,3,1]. Among these paths only red path and green path are pseudo-palindromic paths since the red path [2,3,3] can be rearranged in [3,2,3] (palindrome) and the green path [2,1,1] can be rearranged in [1,2,1] (palindrome).\n
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: root = [2,1,1,1,3,null,null,null,null,null,1]\nOutput: 1 \nExplanation: The figure above represents the given binary tree. There are three paths going from the root node to leaf nodes: the green path [2,1,1], the path [2,1,3,1], and the path [2,1]. Among these paths only the green path is pseudo-palindromic since [2,1,1] can be rearranged in [1,2,1] (palindrome).\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = [9]\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 105].
    • \n\t
    • 1 <= Node.val <= 9
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u68f5\u4e8c\u53c9\u6811\uff0c\u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u4e3a 1 \u5230 9 \u3002\u6211\u4eec\u79f0\u4e8c\u53c9\u6811\u4e2d\u7684\u4e00\u6761\u8def\u5f84\u662f \u300c\u4f2a\u56de\u6587\u300d\u7684\uff0c\u5f53\u5b83\u6ee1\u8db3\uff1a\u8def\u5f84\u7ecf\u8fc7\u7684\u6240\u6709\u8282\u70b9\u503c\u7684\u6392\u5217\u4e2d\uff0c\u5b58\u5728\u4e00\u4e2a\u56de\u6587\u5e8f\u5217\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u4ece\u6839\u5230\u53f6\u5b50\u8282\u70b9\u7684\u6240\u6709\u8def\u5f84\u4e2d \u4f2a\u56de\u6587 \u8def\u5f84\u7684\u6570\u76ee\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1aroot = [2,3,1,3,1,null,1]\n\u8f93\u51fa\uff1a2 \n\u89e3\u91ca\uff1a\u4e0a\u56fe\u4e3a\u7ed9\u5b9a\u7684\u4e8c\u53c9\u6811\u3002\u603b\u5171\u6709 3 \u6761\u4ece\u6839\u5230\u53f6\u5b50\u7684\u8def\u5f84\uff1a\u7ea2\u8272\u8def\u5f84 [2,3,3] \uff0c\u7eff\u8272\u8def\u5f84 [2,1,1] \u548c\u8def\u5f84 [2,3,1] \u3002\n     \u5728\u8fd9\u4e9b\u8def\u5f84\u4e2d\uff0c\u53ea\u6709\u7ea2\u8272\u548c\u7eff\u8272\u7684\u8def\u5f84\u662f\u4f2a\u56de\u6587\u8def\u5f84\uff0c\u56e0\u4e3a\u7ea2\u8272\u8def\u5f84 [2,3,3] \u5b58\u5728\u56de\u6587\u6392\u5217 [3,2,3] \uff0c\u7eff\u8272\u8def\u5f84 [2,1,1] \u5b58\u5728\u56de\u6587\u6392\u5217 [1,2,1] \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1aroot = [2,1,1,1,3,null,null,null,null,null,1]\n\u8f93\u51fa\uff1a1 \n\u89e3\u91ca\uff1a\u4e0a\u56fe\u4e3a\u7ed9\u5b9a\u4e8c\u53c9\u6811\u3002\u603b\u5171\u6709 3 \u6761\u4ece\u6839\u5230\u53f6\u5b50\u7684\u8def\u5f84\uff1a\u7eff\u8272\u8def\u5f84 [2,1,1] \uff0c\u8def\u5f84 [2,1,3,1] \u548c\u8def\u5f84 [2,1] \u3002\n     \u8fd9\u4e9b\u8def\u5f84\u4e2d\u53ea\u6709\u7eff\u8272\u8def\u5f84\u662f\u4f2a\u56de\u6587\u8def\u5f84\uff0c\u56e0\u4e3a [2,1,1] \u5b58\u5728\u56de\u6587\u6392\u5217 [1,2,1] \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aroot = [9]\n\u8f93\u51fa\uff1a1\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u7ed9\u5b9a\u4e8c\u53c9\u6811\u7684\u8282\u70b9\u6570\u76ee\u5728 1 \u5230 10^5 \u4e4b\u95f4\u3002
    • \n\t
    • \u8282\u70b9\u503c\u5728 1 \u5230 9 \u4e4b\u95f4\u3002
    • \n
    \n", "tags_en": ["Bit Manipulation", "Tree", "Depth-first Search"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int pseudoPalindromicPaths (TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int pseudoPalindromicPaths (TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def pseudoPalindromicPaths (self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def pseudoPalindromicPaths (self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint pseudoPalindromicPaths (struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int PseudoPalindromicPaths (TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar pseudoPalindromicPaths = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef pseudo_palindromic_paths (root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func pseudoPalindromicPaths (_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc pseudoPalindromicPaths (root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def pseudoPalindromicPaths (root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun pseudoPalindromicPaths (root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn pseudo_palindromic_paths (root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function pseudoPalindromicPaths ($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction pseudoPalindromicPaths (root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (pseudo-palindromic-paths root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1457](https://leetcode-cn.com/problems/pseudo-palindromic-paths-in-a-binary-tree)", "[\u4e8c\u53c9\u6811\u4e2d\u7684\u4f2a\u56de\u6587\u8def\u5f84](/solution/1400-1499/1457.Pseudo-Palindromic%20Paths%20in%20a%20Binary%20Tree/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1457](https://leetcode.com/problems/pseudo-palindromic-paths-in-a-binary-tree)", "[Pseudo-Palindromic Paths in a Binary Tree](/solution/1400-1499/1457.Pseudo-Palindromic%20Paths%20in%20a%20Binary%20Tree/README_EN.md)", "`Bit Manipulation`,`Tree`,`Depth-first Search`", "Medium", ""]}, {"question_id": "1567", "frontend_question_id": "1456", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-number-of-vowels-in-a-substring-of-given-length", "url_en": "https://leetcode.com/problems/maximum-number-of-vowels-in-a-substring-of-given-length", "relative_path_cn": "/solution/1400-1499/1456.Maximum%20Number%20of%20Vowels%20in%20a%20Substring%20of%20Given%20Length/README.md", "relative_path_en": "/solution/1400-1499/1456.Maximum%20Number%20of%20Vowels%20in%20a%20Substring%20of%20Given%20Length/README_EN.md", "title_cn": "\u5b9a\u957f\u5b50\u4e32\u4e2d\u5143\u97f3\u7684\u6700\u5927\u6570\u76ee", "title_en": "Maximum Number of Vowels in a Substring of Given Length", "question_title_slug": "maximum-number-of-vowels-in-a-substring-of-given-length", "content_en": "

    Given a string s and an integer k.

    \r\n\r\n

    Return the maximum number of vowel letters in any substring of s with length k.

    \r\n\r\n

    Vowel letters in English are (a, e, i, o, u).

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: s = "abciiidef", k = 3\r\nOutput: 3\r\nExplanation: The substring "iii" contains 3 vowel letters.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: s = "aeiou", k = 2\r\nOutput: 2\r\nExplanation: Any substring of length 2 contains 2 vowels.\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: s = "leetcode", k = 3\r\nOutput: 2\r\nExplanation: "lee", "eet" and "ode" contain 2 vowels.\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: s = "rhythms", k = 4\r\nOutput: 0\r\nExplanation: We can see that s doesn't have any vowel letters.\r\n
    \r\n\r\n

    Example 5:

    \r\n\r\n
    \r\nInput: s = "tryhard", k = 4\r\nOutput: 1\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= s.length <= 10^5
    • \r\n\t
    • s consists of lowercase English letters.
    • \r\n\t
    • 1 <= k <= s.length
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u5b57\u7b26\u4e32 s \u548c\u6574\u6570 k \u3002

    \n\n

    \u8bf7\u8fd4\u56de\u5b57\u7b26\u4e32 s \u4e2d\u957f\u5ea6\u4e3a k \u7684\u5355\u4e2a\u5b50\u5b57\u7b26\u4e32\u4e2d\u53ef\u80fd\u5305\u542b\u7684\u6700\u5927\u5143\u97f3\u5b57\u6bcd\u6570\u3002

    \n\n

    \u82f1\u6587\u4e2d\u7684 \u5143\u97f3\u5b57\u6bcd \u4e3a\uff08a, e, i, o, u\uff09\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1as = "abciiidef", k = 3\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u5b50\u5b57\u7b26\u4e32 "iii" \u5305\u542b 3 \u4e2a\u5143\u97f3\u5b57\u6bcd\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1as = "aeiou", k = 2\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u4efb\u610f\u957f\u5ea6\u4e3a 2 \u7684\u5b50\u5b57\u7b26\u4e32\u90fd\u5305\u542b 2 \u4e2a\u5143\u97f3\u5b57\u6bcd\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1as = "leetcode", k = 3\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a"lee"\u3001"eet" \u548c "ode" \u90fd\u5305\u542b 2 \u4e2a\u5143\u97f3\u5b57\u6bcd\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1as = "rhythms", k = 4\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u5b57\u7b26\u4e32 s \u4e2d\u4e0d\u542b\u4efb\u4f55\u5143\u97f3\u5b57\u6bcd\u3002\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1as = "tryhard", k = 4\n\u8f93\u51fa\uff1a1\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 10^5
    • \n\t
    • s \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n\t
    • 1 <= k <= s.length
    • \n
    \n", "tags_en": ["String", "Sliding Window"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxVowels(string s, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxVowels(String s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxVowels(self, s, k):\n \"\"\"\n :type s: str\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxVowels(self, s: str, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxVowels(char * s, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxVowels(string s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number} k\n * @return {number}\n */\nvar maxVowels = function(s, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer} k\n# @return {Integer}\ndef max_vowels(s, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxVowels(_ s: String, _ k: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxVowels(s string, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxVowels(s: String, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxVowels(s: String, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_vowels(s: String, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer $k\n * @return Integer\n */\n function maxVowels($s, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxVowels(s: string, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-vowels s k)\n (-> string? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1456](https://leetcode-cn.com/problems/maximum-number-of-vowels-in-a-substring-of-given-length)", "[\u5b9a\u957f\u5b50\u4e32\u4e2d\u5143\u97f3\u7684\u6700\u5927\u6570\u76ee](/solution/1400-1499/1456.Maximum%20Number%20of%20Vowels%20in%20a%20Substring%20of%20Given%20Length/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1456](https://leetcode.com/problems/maximum-number-of-vowels-in-a-substring-of-given-length)", "[Maximum Number of Vowels in a Substring of Given Length](/solution/1400-1499/1456.Maximum%20Number%20of%20Vowels%20in%20a%20Substring%20of%20Given%20Length/README_EN.md)", "`String`,`Sliding Window`", "Medium", ""]}, {"question_id": "1566", "frontend_question_id": "1455", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence", "url_en": "https://leetcode.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence", "relative_path_cn": "/solution/1400-1499/1455.Check%20If%20a%20Word%20Occurs%20As%20a%20Prefix%20of%20Any%20Word%20in%20a%20Sentence/README.md", "relative_path_en": "/solution/1400-1499/1455.Check%20If%20a%20Word%20Occurs%20As%20a%20Prefix%20of%20Any%20Word%20in%20a%20Sentence/README_EN.md", "title_cn": "\u68c0\u67e5\u5355\u8bcd\u662f\u5426\u4e3a\u53e5\u4e2d\u5176\u4ed6\u5355\u8bcd\u7684\u524d\u7f00", "title_en": "Check If a Word Occurs As a Prefix of Any Word in a Sentence", "question_title_slug": "check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence", "content_en": "

    Given a sentence that consists of some words separated by a single space, and a searchWord.

    \n\n

    You have to check if searchWord is a prefix of any word in sentence.

    \n\n

    Return the index of the word in sentence where searchWord is a prefix of this word (1-indexed).

    \n\n

    If searchWord is a prefix of more than one word, return the index of the first word (minimum index). If there is no such word return -1.

    \n\n

    A prefix of a string S is any leading contiguous substring of S.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: sentence = "i love eating burger", searchWord = "burg"\nOutput: 4\nExplanation: "burg" is prefix of "burger" which is the 4th word in the sentence.\n
    \n\n

    Example 2:

    \n\n
    \nInput: sentence = "this problem is an easy problem", searchWord = "pro"\nOutput: 2\nExplanation: "pro" is prefix of "problem" which is the 2nd and the 6th word in the sentence, but we return 2 as it's the minimal index.\n
    \n\n

    Example 3:

    \n\n
    \nInput: sentence = "i am tired", searchWord = "you"\nOutput: -1\nExplanation: "you" is not a prefix of any word in the sentence.\n
    \n\n

    Example 4:

    \n\n
    \nInput: sentence = "i use triple pillow", searchWord = "pill"\nOutput: 4\n
    \n\n

    Example 5:

    \n\n
    \nInput: sentence = "hello from the other side", searchWord = "they"\nOutput: -1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= sentence.length <= 100
    • \n\t
    • 1 <= searchWord.length <= 10
    • \n\t
    • sentence consists of lowercase English letters and spaces.
    • \n\t
    • searchWord consists of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 sentence \u4f5c\u4e3a\u53e5\u5b50\u5e76\u6307\u5b9a\u68c0\u7d22\u8bcd\u4e3a searchWord \uff0c\u5176\u4e2d\u53e5\u5b50\u7531\u82e5\u5e72\u7528 \u5355\u4e2a\u7a7a\u683c \u5206\u9694\u7684\u5355\u8bcd\u7ec4\u6210\u3002

    \n\n

    \u8bf7\u4f60\u68c0\u67e5\u68c0\u7d22\u8bcd searchWord \u662f\u5426\u4e3a\u53e5\u5b50 sentence \u4e2d\u4efb\u610f\u5355\u8bcd\u7684\u524d\u7f00\u3002

    \n\n
      \n\t
    • \u5982\u679c\u00a0searchWord \u662f\u67d0\u4e00\u4e2a\u5355\u8bcd\u7684\u524d\u7f00\uff0c\u5219\u8fd4\u56de\u53e5\u5b50\u00a0sentence \u4e2d\u8be5\u5355\u8bcd\u6240\u5bf9\u5e94\u7684\u4e0b\u6807\uff08\u4e0b\u6807\u4ece 1 \u5f00\u59cb\uff09\u3002
    • \n\t
    • \u5982\u679c searchWord \u662f\u591a\u4e2a\u5355\u8bcd\u7684\u524d\u7f00\uff0c\u5219\u8fd4\u56de\u5339\u914d\u7684\u7b2c\u4e00\u4e2a\u5355\u8bcd\u7684\u4e0b\u6807\uff08\u6700\u5c0f\u4e0b\u6807\uff09\u3002
    • \n\t
    • \u5982\u679c searchWord \u4e0d\u662f\u4efb\u4f55\u5355\u8bcd\u7684\u524d\u7f00\uff0c\u5219\u8fd4\u56de -1 \u3002
    • \n
    \n\n

    \u5b57\u7b26\u4e32 S \u7684 \u524d\u7f00 \u662f S \u7684\u4efb\u4f55\u524d\u5bfc\u8fde\u7eed\u5b50\u5b57\u7b26\u4e32\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1asentence = \"i love eating burger\", searchWord = \"burg\"\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\"burg\" \u662f \"burger\" \u7684\u524d\u7f00\uff0c\u800c \"burger\" \u662f\u53e5\u5b50\u4e2d\u7b2c 4 \u4e2a\u5355\u8bcd\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1asentence = \"this problem is an easy problem\", searchWord = \"pro\"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\"pro\" \u662f \"problem\" \u7684\u524d\u7f00\uff0c\u800c \"problem\" \u662f\u53e5\u5b50\u4e2d\u7b2c 2 \u4e2a\u4e5f\u662f\u7b2c 6 \u4e2a\u5355\u8bcd\uff0c\u4f46\u662f\u5e94\u8be5\u8fd4\u56de\u6700\u5c0f\u4e0b\u6807 2 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1asentence = \"i am tired\", searchWord = \"you\"\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\"you\" \u4e0d\u662f\u53e5\u5b50\u4e2d\u4efb\u4f55\u5355\u8bcd\u7684\u524d\u7f00\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1asentence = \"i use triple pillow\", searchWord = \"pill\"\n\u8f93\u51fa\uff1a4\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1asentence = \"hello from the other side\", searchWord = \"they\"\n\u8f93\u51fa\uff1a-1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= sentence.length <= 100
    • \n\t
    • 1 <= searchWord.length <= 10
    • \n\t
    • sentence \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u548c\u7a7a\u683c\u7ec4\u6210\u3002
    • \n\t
    • searchWord \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\u3002
    • \n\t
    • \u524d\u7f00\u5c31\u662f\u7d27\u5bc6\u9644\u7740\u4e8e\u8bcd\u6839\u7684\u8bed\u7d20\uff0c\u4e2d\u95f4\u4e0d\u80fd\u63d2\u5165\u5176\u5b83\u6210\u5206\uff0c\u5e76\u4e14\u5b83\u7684\u4f4d\u7f6e\u662f\u56fa\u5b9a\u7684\u2014\u2014-\u4f4d\u4e8e\u8bcd\u6839\u4e4b\u524d\u3002\uff08\u5f15\u7528\u81ea \u524d\u7f00_\u767e\u5ea6\u767e\u79d1 \uff09
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int isPrefixOfWord(string sentence, string searchWord) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int isPrefixOfWord(String sentence, String searchWord) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isPrefixOfWord(self, sentence, searchWord):\n \"\"\"\n :type sentence: str\n :type searchWord: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isPrefixOfWord(self, sentence: str, searchWord: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint isPrefixOfWord(char * sentence, char * searchWord){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int IsPrefixOfWord(string sentence, string searchWord) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} sentence\n * @param {string} searchWord\n * @return {number}\n */\nvar isPrefixOfWord = function(sentence, searchWord) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} sentence\n# @param {String} search_word\n# @return {Integer}\ndef is_prefix_of_word(sentence, search_word)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isPrefixOfWord(_ sentence: String, _ searchWord: String) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isPrefixOfWord(sentence string, searchWord string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isPrefixOfWord(sentence: String, searchWord: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isPrefixOfWord(sentence: String, searchWord: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_prefix_of_word(sentence: String, search_word: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $sentence\n * @param String $searchWord\n * @return Integer\n */\n function isPrefixOfWord($sentence, $searchWord) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isPrefixOfWord(sentence: string, searchWord: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-prefix-of-word sentence searchWord)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1455](https://leetcode-cn.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence)", "[\u68c0\u67e5\u5355\u8bcd\u662f\u5426\u4e3a\u53e5\u4e2d\u5176\u4ed6\u5355\u8bcd\u7684\u524d\u7f00](/solution/1400-1499/1455.Check%20If%20a%20Word%20Occurs%20As%20a%20Prefix%20of%20Any%20Word%20in%20a%20Sentence/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1455](https://leetcode.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence)", "[Check If a Word Occurs As a Prefix of Any Word in a Sentence](/solution/1400-1499/1455.Check%20If%20a%20Word%20Occurs%20As%20a%20Prefix%20of%20Any%20Word%20in%20a%20Sentence/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1565", "frontend_question_id": "1440", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/evaluate-boolean-expression", "url_en": "https://leetcode.com/problems/evaluate-boolean-expression", "relative_path_cn": "/solution/1400-1499/1440.Evaluate%20Boolean%20Expression/README.md", "relative_path_en": "/solution/1400-1499/1440.Evaluate%20Boolean%20Expression/README_EN.md", "title_cn": "\u8ba1\u7b97\u5e03\u5c14\u8868\u8fbe\u5f0f\u7684\u503c", "title_en": "Evaluate Boolean Expression", "question_title_slug": "evaluate-boolean-expression", "content_en": "

    Table Variables:

    \r\n\r\n
    \r\n+---------------+---------+\r\n| Column Name   | Type    |\r\n+---------------+---------+\r\n| name          | varchar |\r\n| value         | int     |\r\n+---------------+---------+\r\nname is the primary key for this table.\r\nThis table contains the stored variables and their values.\r\n
    \r\n\r\n

     

    \r\n\r\n

    Table Expressions:

    \r\n\r\n
    \r\n+---------------+---------+\r\n| Column Name   | Type    |\r\n+---------------+---------+\r\n| left_operand  | varchar |\r\n| operator      | enum    |\r\n| right_operand | varchar |\r\n+---------------+---------+\r\n(left_operand, operator, right_operand) is the primary key for this table.\r\nThis table contains a boolean expression that should be evaluated.\r\noperator is an enum that takes one of the values ('<', '>', '=')\r\nThe values of left_operand and right_operand are guaranteed to be in the Variables table.\r\n
    \r\n\r\n

     

    \r\n\r\n

    Write an SQL query to evaluate the boolean expressions in Expressions table.

    \r\n\r\n

    Return the result table in any order.

    \r\n\r\n

    The query result format is in the following example.

    \r\n\r\n
    \r\nVariables table:\r\n+------+-------+\r\n| name | value |\r\n+------+-------+\r\n| x    | 66    |\r\n| y    | 77    |\r\n+------+-------+\r\n\r\nExpressions table:\r\n+--------------+----------+---------------+\r\n| left_operand | operator | right_operand |\r\n+--------------+----------+---------------+\r\n| x            | >        | y             |\r\n| x            | <        | y             |\r\n| x            | =        | y             |\r\n| y            | >        | x             |\r\n| y            | <        | x             |\r\n| x            | =        | x             |\r\n+--------------+----------+---------------+\r\n\r\nResult table:\r\n+--------------+----------+---------------+-------+\r\n| left_operand | operator | right_operand | value |\r\n+--------------+----------+---------------+-------+\r\n| x            | >        | y             | false |\r\n| x            | <        | y             | true  |\r\n| x            | =        | y             | false |\r\n| y            | >        | x             | true  |\r\n| y            | <        | x             | false |\r\n| x            | =        | x             | true  |\r\n+--------------+----------+---------------+-------+\r\nAs shown, you need find the value of each boolean exprssion in the table using the variables table.\r\n
    ", "content_cn": "

    \u8868 Variables:

    \n\n
    +---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| name          | varchar |\n| value         | int     |\n+---------------+---------+\nname \u662f\u8be5\u8868\u4e3b\u952e.\n\u8be5\u8868\u5305\u542b\u4e86\u5b58\u50a8\u7684\u53d8\u91cf\u53ca\u5176\u5bf9\u5e94\u7684\u503c.\n
    \n\n

     

    \n\n

    \u8868 Expressions:

    \n\n
    +---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| left_operand  | varchar |\n| operator      | enum    |\n| right_operand | varchar |\n+---------------+---------+\n(left_operand, operator, right_operand) \u662f\u8be5\u8868\u4e3b\u952e.\n\u8be5\u8868\u5305\u542b\u4e86\u9700\u8981\u8ba1\u7b97\u7684\u5e03\u5c14\u8868\u8fbe\u5f0f.\noperator \u662f\u679a\u4e3e\u7c7b\u578b, \u53d6\u503c\u4e8e('<', '>', '=')\nleft_operand \u548c right_operand \u7684\u503c\u4fdd\u8bc1\u5b58\u5728\u4e8e Variables \u8868\u5355\u4e2d.\n
    \n\n

     

    \n\n

    \u5199\u4e00\u4e2a SQL \u67e5\u8be2,  \u4ee5\u8ba1\u7b97\u8868 Expressions \u4e2d\u7684\u5e03\u5c14\u8868\u8fbe\u5f0f.

    \n\n

    \u8fd4\u56de\u7684\u7ed3\u679c\u8868\u6ca1\u6709\u987a\u5e8f\u8981\u6c42.

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a.

    \n\n
    Variables \u8868:\n+------+-------+\n| name | value |\n+------+-------+\n| x    | 66    |\n| y    | 77    |\n+------+-------+\n\nExpressions \u8868:\n+--------------+----------+---------------+\n| left_operand | operator | right_operand |\n+--------------+----------+---------------+\n| x            | >        | y             |\n| x            | <        | y             |\n| x            | =        | y             |\n| y            | >        | x             |\n| y            | <        | x             |\n| x            | =        | x             |\n+--------------+----------+---------------+\n\nResult \u8868:\n+--------------+----------+---------------+-------+\n| left_operand | operator | right_operand | value |\n+--------------+----------+---------------+-------+\n| x            | >        | y             | false |\n| x            | <        | y             | true  |\n| x            | =        | y             | false |\n| y            | >        | x             | true  |\n| y            | <        | x             | false |\n| x            | =        | x             | true  |\n+--------------+----------+---------------+-------+\n\u5982\u4e0a\u6240\u793a, \u4f60\u9700\u8981\u901a\u8fc7\u4f7f\u7528 Variables \u8868\u6765\u627e\u5230 Expressions \u8868\u4e2d\u7684\u6bcf\u4e00\u4e2a\u5e03\u5c14\u8868\u8fbe\u5f0f\u7684\u503c.\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1440](https://leetcode-cn.com/problems/evaluate-boolean-expression)", "[\u8ba1\u7b97\u5e03\u5c14\u8868\u8fbe\u5f0f\u7684\u503c](/solution/1400-1499/1440.Evaluate%20Boolean%20Expression/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1440](https://leetcode.com/problems/evaluate-boolean-expression)", "[Evaluate Boolean Expression](/solution/1400-1499/1440.Evaluate%20Boolean%20Expression/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1564", "frontend_question_id": "1435", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/create-a-session-bar-chart", "url_en": "https://leetcode.com/problems/create-a-session-bar-chart", "relative_path_cn": "/solution/1400-1499/1435.Create%20a%20Session%20Bar%20Chart/README.md", "relative_path_en": "/solution/1400-1499/1435.Create%20a%20Session%20Bar%20Chart/README_EN.md", "title_cn": "\u5236\u4f5c\u4f1a\u8bdd\u67f1\u72b6\u56fe", "title_en": "Create a Session Bar Chart", "question_title_slug": "create-a-session-bar-chart", "content_en": "

    Table: Sessions

    \n\n
    \n+---------------------+---------+\n| Column Name         | Type    |\n+---------------------+---------+\n| session_id          | int     |\n| duration            | int     |\n+---------------------+---------+\nsession_id is the primary key for this table.\nduration is the time in seconds that a user has visited the application.\n
    \n\n

     

    \n\n

    You want to know how long a user visits your application. You decided to create bins of "[0-5>", "[5-10>", "[10-15>" and "15 minutes or more" and count the number of sessions on it.

    \n\n

    Write an SQL query to report the (bin, total) in any order.

    \n\n

    The query result format is in the following example.

    \n\n
    \nSessions table:\n+-------------+---------------+\n| session_id  | duration      |\n+-------------+---------------+\n| 1           | 30            |\n| 2           | 199           |\n| 3           | 299           |\n| 4           | 580           |\n| 5           | 1000          |\n+-------------+---------------+\n\nResult table:\n+--------------+--------------+\n| bin          | total        |\n+--------------+--------------+\n| [0-5>        | 3            |\n| [5-10>       | 1            |\n| [10-15>      | 0            |\n| 15 or more   | 1            |\n+--------------+--------------+\n\nFor session_id 1, 2 and 3 have a duration greater or equal than 0 minutes and less than 5 minutes.\nFor session_id 4 has a duration greater or equal than 5 minutes and less than 10 minutes.\nThere are no session with a duration greater or equial than 10 minutes and less than 15 minutes.\nFor session_id 5 has a duration greater or equal than 15 minutes.\n
    \n", "content_cn": "

    \u8868\uff1aSessions

    \n\n
    +---------------------+---------+\n| Column Name         | Type    |\n+---------------------+---------+\n| session_id          | int     |\n| duration            | int     |\n+---------------------+---------+\nsession_id \u662f\u8be5\u8868\u4e3b\u952e\nduration \u662f\u7528\u6237\u8bbf\u95ee\u5e94\u7528\u7684\u65f6\u95f4, \u4ee5\u79d2\u4e3a\u5355\u4f4d\n
    \n\n

     

    \n\n

    \u4f60\u60f3\u77e5\u9053\u7528\u6237\u5728\u4f60\u7684 app \u4e0a\u7684\u8bbf\u95ee\u65f6\u957f\u60c5\u51b5\u3002\u56e0\u6b64\u51b3\u5b9a\u7edf\u8ba1\u8bbf\u95ee\u65f6\u957f\u533a\u95f4\u5206\u522b\u4e3a "[0-5>", "[5-10>", "[10-15>" \u548c "15 or more" \uff08\u5355\u4f4d\uff1a\u5206\u949f\uff09\u7684\u4f1a\u8bdd\u6570\u91cf\uff0c\u5e76\u4ee5\u6b64\u7ed8\u5236\u67f1\u72b6\u56fe\u3002

    \n\n

    \u5199\u4e00\u4e2aSQL\u67e5\u8be2\u6765\u62a5\u544a\uff08\u8bbf\u95ee\u65f6\u957f\u533a\u95f4\uff0c\u4f1a\u8bdd\u603b\u6570\uff09\u3002\u7ed3\u679c\u53ef\u7528\u4efb\u4f55\u987a\u5e8f\u5448\u73b0\u3002

    \n\n

     

    \n\n

    \u4e0b\u65b9\u4e3a\u67e5\u8be2\u7684\u8f93\u51fa\u683c\u5f0f\uff1a

    \n\n
    Sessions \u8868\uff1a\n+-------------+---------------+\n| session_id  | duration      |\n+-------------+---------------+\n| 1           | 30            |\n| 2           | 199           |\n| 3           | 299           |\n| 4           | 580           |\n| 5           | 1000          |\n+-------------+---------------+\n\nResult \u8868\uff1a\n+--------------+--------------+\n| bin          | total        |\n+--------------+--------------+\n| [0-5>        | 3            |\n| [5-10>       | 1            |\n| [10-15>      | 0            |\n| 15 or more   | 1            |\n+--------------+--------------+\n\n\u5bf9\u4e8e session_id 1\uff0c2 \u548c 3 \uff0c\u5b83\u4eec\u7684\u8bbf\u95ee\u65f6\u95f4\u5927\u4e8e\u7b49\u4e8e 0 \u5206\u949f\u4e14\u5c0f\u4e8e 5 \u5206\u949f\u3002\n\u5bf9\u4e8e session_id 4\uff0c\u5b83\u7684\u8bbf\u95ee\u65f6\u95f4\u5927\u4e8e\u7b49\u4e8e 5 \u5206\u949f\u4e14\u5c0f\u4e8e 10 \u5206\u949f\u3002\n\u6ca1\u6709\u4f1a\u8bdd\u7684\u8bbf\u95ee\u65f6\u95f4\u5927\u4e8e\u7b49\u4e8e 10 \u5206\u949f\u4e14\u5c0f\u4e8e 15 \u5206\u949f\u3002\n\u5bf9\u4e8e session_id 5, \u5b83\u7684\u8bbf\u95ee\u65f6\u95f4\u5927\u4e8e\u7b49\u4e8e 15 \u5206\u949f\u3002\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1435](https://leetcode-cn.com/problems/create-a-session-bar-chart)", "[\u5236\u4f5c\u4f1a\u8bdd\u67f1\u72b6\u56fe](/solution/1400-1499/1435.Create%20a%20Session%20Bar%20Chart/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1435](https://leetcode.com/problems/create-a-session-bar-chart)", "[Create a Session Bar Chart](/solution/1400-1499/1435.Create%20a%20Session%20Bar%20Chart/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1563", "frontend_question_id": "1453", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-number-of-darts-inside-of-a-circular-dartboard", "url_en": "https://leetcode.com/problems/maximum-number-of-darts-inside-of-a-circular-dartboard", "relative_path_cn": "/solution/1400-1499/1453.Maximum%20Number%20of%20Darts%20Inside%20of%20a%20Circular%20Dartboard/README.md", "relative_path_en": "/solution/1400-1499/1453.Maximum%20Number%20of%20Darts%20Inside%20of%20a%20Circular%20Dartboard/README_EN.md", "title_cn": "\u5706\u5f62\u9776\u5185\u7684\u6700\u5927\u98de\u9556\u6570\u91cf", "title_en": "Maximum Number of Darts Inside of a Circular Dartboard", "question_title_slug": "maximum-number-of-darts-inside-of-a-circular-dartboard", "content_en": "

    You have a very large square wall and a circular dartboard placed on the wall. You have been challenged to throw darts into the board blindfolded. Darts thrown at the wall are represented as an array of points on a 2D plane. 

    \r\n\r\n

    Return the maximum number of points that are within or lie on any circular dartboard of radius r.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n

    \"\"

    \r\n\r\n
    \r\nInput: points = [[-2,0],[2,0],[0,2],[0,-2]], r = 2\r\nOutput: 4\r\nExplanation: Circle dartboard with center in (0,0) and radius = 2 contain all points.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n

    \"\"

    \r\n\r\n
    \r\nInput: points = [[-3,0],[3,0],[2,6],[5,4],[0,9],[7,8]], r = 5\r\nOutput: 5\r\nExplanation: Circle dartboard with center in (0,4) and radius = 5 contain all points except the point (7,8).\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: points = [[-2,0],[2,0],[0,2],[0,-2]], r = 1\r\nOutput: 1\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: points = [[1,2],[3,5],[1,-1],[2,3],[4,1],[1,3]], r = 2\r\nOutput: 4\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= points.length <= 100
    • \r\n\t
    • points[i].length == 2
    • \r\n\t
    • -10^4 <= points[i][0], points[i][1] <= 10^4
    • \r\n\t
    • 1 <= r <= 5000
    • \r\n
    ", "content_cn": "

    \u5899\u58c1\u4e0a\u6302\u7740\u4e00\u4e2a\u5706\u5f62\u7684\u98de\u9556\u9776\u3002\u73b0\u5728\u8bf7\u4f60\u8499\u7740\u773c\u775b\u5411\u9776\u4e0a\u6295\u63b7\u98de\u9556\u3002

    \n\n

    \u6295\u63b7\u5230\u5899\u4e0a\u7684\u98de\u9556\u7528\u4e8c\u7ef4\u5e73\u9762\u4e0a\u7684\u70b9\u5750\u6807\u6570\u7ec4\u8868\u793a\u3002\u98de\u9556\u9776\u7684\u534a\u5f84\u4e3a r \u3002

    \n\n

    \u8bf7\u8fd4\u56de\u80fd\u591f\u843d\u5728 \u4efb\u610f \u534a\u5f84\u4e3a r \u7684\u5706\u5f62\u9776\u5185\u6216\u9776\u4e0a\u7684\u6700\u5927\u98de\u9556\u6570\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1apoints = [[-2,0],[2,0],[0,2],[0,-2]], r = 2\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u5982\u679c\u5706\u5f62\u7684\u98de\u9556\u9776\u7684\u5706\u5fc3\u4e3a (0,0) \uff0c\u534a\u5f84\u4e3a 2 \uff0c\u6240\u6709\u7684\u98de\u9556\u90fd\u843d\u5728\u9776\u4e0a\uff0c\u6b64\u65f6\u843d\u5728\u9776\u4e0a\u7684\u98de\u9556\u6570\u6700\u5927\uff0c\u503c\u4e3a 4 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1apoints = [[-3,0],[3,0],[2,6],[5,4],[0,9],[7,8]], r = 5\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u5982\u679c\u5706\u5f62\u7684\u98de\u9556\u9776\u7684\u5706\u5fc3\u4e3a (0,4) \uff0c\u534a\u5f84\u4e3a 5 \uff0c\u5219\u9664\u4e86 (7,8) \u4e4b\u5916\u7684\u98de\u9556\u90fd\u843d\u5728\u9776\u4e0a\uff0c\u6b64\u65f6\u843d\u5728\u9776\u4e0a\u7684\u98de\u9556\u6570\u6700\u5927\uff0c\u503c\u4e3a 5 \u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1apoints = [[-2,0],[2,0],[0,2],[0,-2]], r = 1\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1apoints = [[1,2],[3,5],[1,-1],[2,3],[4,1],[1,3]], r = 2\n\u8f93\u51fa\uff1a4\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= points.length <= 100
    • \n\t
    • points[i].length == 2
    • \n\t
    • -10^4 <= points[i][0], points[i][1] <= 10^4
    • \n\t
    • 1 <= r <= 5000
    • \n
    \n", "tags_en": ["Geometry"], "tags_cn": ["\u51e0\u4f55"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numPoints(vector>& points, int r) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numPoints(int[][] points, int r) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numPoints(self, points, r):\n \"\"\"\n :type points: List[List[int]]\n :type r: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numPoints(self, points: List[List[int]], r: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numPoints(int** points, int pointsSize, int* pointsColSize, int r){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumPoints(int[][] points, int r) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} points\n * @param {number} r\n * @return {number}\n */\nvar numPoints = function(points, r) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} points\n# @param {Integer} r\n# @return {Integer}\ndef num_points(points, r)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numPoints(_ points: [[Int]], _ r: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numPoints(points [][]int, r int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numPoints(points: Array[Array[Int]], r: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numPoints(points: Array, r: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_points(points: Vec>, r: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $points\n * @param Integer $r\n * @return Integer\n */\n function numPoints($points, $r) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numPoints(points: number[][], r: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-points points r)\n (-> (listof (listof exact-integer?)) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1453](https://leetcode-cn.com/problems/maximum-number-of-darts-inside-of-a-circular-dartboard)", "[\u5706\u5f62\u9776\u5185\u7684\u6700\u5927\u98de\u9556\u6570\u91cf](/solution/1400-1499/1453.Maximum%20Number%20of%20Darts%20Inside%20of%20a%20Circular%20Dartboard/README.md)", "`\u51e0\u4f55`", "\u56f0\u96be", ""], "md_table_row_en": ["[1453](https://leetcode.com/problems/maximum-number-of-darts-inside-of-a-circular-dartboard)", "[Maximum Number of Darts Inside of a Circular Dartboard](/solution/1400-1499/1453.Maximum%20Number%20of%20Darts%20Inside%20of%20a%20Circular%20Dartboard/README_EN.md)", "`Geometry`", "Hard", ""]}, {"question_id": "1562", "frontend_question_id": "1452", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/people-whose-list-of-favorite-companies-is-not-a-subset-of-another-list", "url_en": "https://leetcode.com/problems/people-whose-list-of-favorite-companies-is-not-a-subset-of-another-list", "relative_path_cn": "/solution/1400-1499/1452.People%20Whose%20List%20of%20Favorite%20Companies%20Is%20Not%20a%20Subset%20of%20Another%20List/README.md", "relative_path_en": "/solution/1400-1499/1452.People%20Whose%20List%20of%20Favorite%20Companies%20Is%20Not%20a%20Subset%20of%20Another%20List/README_EN.md", "title_cn": "\u6536\u85cf\u6e05\u5355", "title_en": "People Whose List of Favorite Companies Is Not a Subset of Another List", "question_title_slug": "people-whose-list-of-favorite-companies-is-not-a-subset-of-another-list", "content_en": "

    Given the array favoriteCompanies where favoriteCompanies[i] is the list of favorites companies for the ith person (indexed from 0).

    \n\n

    Return the indices of people whose list of favorite companies is not a subset of any other list of favorites companies. You must return the indices in increasing order.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: favoriteCompanies = [["leetcode","google","facebook"],["google","microsoft"],["google","facebook"],["google"],["amazon"]]\nOutput: [0,1,4] \nExplanation: \nPerson with index=2 has favoriteCompanies[2]=["google","facebook"] which is a subset of favoriteCompanies[0]=["leetcode","google","facebook"] corresponding to the person with index 0. \nPerson with index=3 has favoriteCompanies[3]=["google"] which is a subset of favoriteCompanies[0]=["leetcode","google","facebook"] and favoriteCompanies[1]=["google","microsoft"]. \nOther lists of favorite companies are not a subset of another list, therefore, the answer is [0,1,4].\n
    \n\n

    Example 2:

    \n\n
    \nInput: favoriteCompanies = [["leetcode","google","facebook"],["leetcode","amazon"],["facebook","google"]]\nOutput: [0,1] \nExplanation: In this case favoriteCompanies[2]=["facebook","google"] is a subset of favoriteCompanies[0]=["leetcode","google","facebook"], therefore, the answer is [0,1].\n
    \n\n

    Example 3:

    \n\n
    \nInput: favoriteCompanies = [["leetcode"],["google"],["facebook"],["amazon"]]\nOutput: [0,1,2,3]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= favoriteCompanies.length <= 100
    • \n\t
    • 1 <= favoriteCompanies[i].length <= 500
    • \n\t
    • 1 <= favoriteCompanies[i][j].length <= 20
    • \n\t
    • All strings in favoriteCompanies[i] are distinct.
    • \n\t
    • All lists of favorite companies are distinct, that is, If we sort alphabetically each list then favoriteCompanies[i] != favoriteCompanies[j].
    • \n\t
    • All strings consist of lowercase English letters only.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 favoriteCompanies \uff0c\u5176\u4e2d favoriteCompanies[i] \u662f\u7b2c i \u540d\u7528\u6237\u6536\u85cf\u7684\u516c\u53f8\u6e05\u5355\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\u3002

    \n\n

    \u8bf7\u627e\u51fa\u4e0d\u662f\u5176\u4ed6\u4efb\u4f55\u4eba\u6536\u85cf\u7684\u516c\u53f8\u6e05\u5355\u7684\u5b50\u96c6\u7684\u6536\u85cf\u6e05\u5355\uff0c\u5e76\u8fd4\u56de\u8be5\u6e05\u5355\u4e0b\u6807\u3002\u4e0b\u6807\u9700\u8981\u6309\u5347\u5e8f\u6392\u5217\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1afavoriteCompanies = [["leetcode","google","facebook"],["google","microsoft"],["google","facebook"],["google"],["amazon"]]\n\u8f93\u51fa\uff1a[0,1,4] \n\u89e3\u91ca\uff1a\nfavoriteCompanies[2]=["google","facebook"] \u662f favoriteCompanies[0]=["leetcode","google","facebook"] \u7684\u5b50\u96c6\u3002\nfavoriteCompanies[3]=["google"] \u662f favoriteCompanies[0]=["leetcode","google","facebook"] \u548c favoriteCompanies[1]=["google","microsoft"] \u7684\u5b50\u96c6\u3002\n\u5176\u4f59\u7684\u6536\u85cf\u6e05\u5355\u5747\u4e0d\u662f\u5176\u4ed6\u4efb\u4f55\u4eba\u6536\u85cf\u7684\u516c\u53f8\u6e05\u5355\u7684\u5b50\u96c6\uff0c\u56e0\u6b64\uff0c\u7b54\u6848\u4e3a [0,1,4] \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1afavoriteCompanies = [["leetcode","google","facebook"],["leetcode","amazon"],["facebook","google"]]\n\u8f93\u51fa\uff1a[0,1] \n\u89e3\u91ca\uff1afavoriteCompanies[2]=["facebook","google"] \u662f favoriteCompanies[0]=["leetcode","google","facebook"] \u7684\u5b50\u96c6\uff0c\u56e0\u6b64\uff0c\u7b54\u6848\u4e3a [0,1] \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1afavoriteCompanies = [["leetcode"],["google"],["facebook"],["amazon"]]\n\u8f93\u51fa\uff1a[0,1,2,3]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= favoriteCompanies.length <= 100
    • \n\t
    • 1 <= favoriteCompanies[i].length <= 500
    • \n\t
    • 1 <= favoriteCompanies[i][j].length <= 20
    • \n\t
    • favoriteCompanies[i] \u4e2d\u7684\u6240\u6709\u5b57\u7b26\u4e32 \u5404\u4e0d\u76f8\u540c \u3002
    • \n\t
    • \u7528\u6237\u6536\u85cf\u7684\u516c\u53f8\u6e05\u5355\u4e5f \u5404\u4e0d\u76f8\u540c \uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u5373\u4fbf\u6211\u4eec\u6309\u5b57\u6bcd\u987a\u5e8f\u6392\u5e8f\u6bcf\u4e2a\u6e05\u5355\uff0c favoriteCompanies[i] != favoriteCompanies[j] \u4ecd\u7136\u6210\u7acb\u3002
    • \n\t
    • \u6240\u6709\u5b57\u7b26\u4e32\u4ec5\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    • \n
    \n", "tags_en": ["Sort", "String"], "tags_cn": ["\u6392\u5e8f", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector peopleIndexes(vector>& favoriteCompanies) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List peopleIndexes(List> favoriteCompanies) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def peopleIndexes(self, favoriteCompanies):\n \"\"\"\n :type favoriteCompanies: List[List[str]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def peopleIndexes(self, favoriteCompanies: List[List[str]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* peopleIndexes(char *** favoriteCompanies, int favoriteCompaniesSize, int* favoriteCompaniesColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList PeopleIndexes(IList> favoriteCompanies) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[][]} favoriteCompanies\n * @return {number[]}\n */\nvar peopleIndexes = function(favoriteCompanies) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[][]} favorite_companies\n# @return {Integer[]}\ndef people_indexes(favorite_companies)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func peopleIndexes(_ favoriteCompanies: [[String]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func peopleIndexes(favoriteCompanies [][]string) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def peopleIndexes(favoriteCompanies: List[List[String]]): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun peopleIndexes(favoriteCompanies: List>): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn people_indexes(favorite_companies: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $favoriteCompanies\n * @return Integer[]\n */\n function peopleIndexes($favoriteCompanies) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function peopleIndexes(favoriteCompanies: string[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (people-indexes favoriteCompanies)\n (-> (listof (listof string?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1452](https://leetcode-cn.com/problems/people-whose-list-of-favorite-companies-is-not-a-subset-of-another-list)", "[\u6536\u85cf\u6e05\u5355](/solution/1400-1499/1452.People%20Whose%20List%20of%20Favorite%20Companies%20Is%20Not%20a%20Subset%20of%20Another%20List/README.md)", "`\u6392\u5e8f`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1452](https://leetcode.com/problems/people-whose-list-of-favorite-companies-is-not-a-subset-of-another-list)", "[People Whose List of Favorite Companies Is Not a Subset of Another List](/solution/1400-1499/1452.People%20Whose%20List%20of%20Favorite%20Companies%20Is%20Not%20a%20Subset%20of%20Another%20List/README_EN.md)", "`Sort`,`String`", "Medium", ""]}, {"question_id": "1561", "frontend_question_id": "1451", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/rearrange-words-in-a-sentence", "url_en": "https://leetcode.com/problems/rearrange-words-in-a-sentence", "relative_path_cn": "/solution/1400-1499/1451.Rearrange%20Words%20in%20a%20Sentence/README.md", "relative_path_en": "/solution/1400-1499/1451.Rearrange%20Words%20in%20a%20Sentence/README_EN.md", "title_cn": "\u91cd\u65b0\u6392\u5217\u53e5\u5b50\u4e2d\u7684\u5355\u8bcd", "title_en": "Rearrange Words in a Sentence", "question_title_slug": "rearrange-words-in-a-sentence", "content_en": "

    Given a sentence text (A sentence is a string of space-separated words) in the following format:

    \n\n
      \n\t
    • First letter is in upper case.
    • \n\t
    • Each word in text are separated by a single space.
    • \n
    \n\n

    Your task is to rearrange the words in text such that all words are rearranged in an increasing order of their lengths. If two words have the same length, arrange them in their original order.

    \n\n

    Return the new text following the format shown above.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: text = "Leetcode is cool"\nOutput: "Is cool leetcode"\nExplanation: There are 3 words, "Leetcode" of length 8, "is" of length 2 and "cool" of length 4.\nOutput is ordered by length and the new first word starts with capital letter.\n
    \n\n

    Example 2:

    \n\n
    \nInput: text = "Keep calm and code on"\nOutput: "On and keep calm code"\nExplanation: Output is ordered as follows:\n"On" 2 letters.\n"and" 3 letters.\n"keep" 4 letters in case of tie order by position in original text.\n"calm" 4 letters.\n"code" 4 letters.\n
    \n\n

    Example 3:

    \n\n
    \nInput: text = "To be or not to be"\nOutput: "To be or to be not"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • text begins with a capital letter and then contains lowercase letters and single space between words.
    • \n\t
    • 1 <= text.length <= 10^5
    • \n
    \n", "content_cn": "

    \u300c\u53e5\u5b50\u300d\u662f\u4e00\u4e2a\u7528\u7a7a\u683c\u5206\u9694\u5355\u8bcd\u7684\u5b57\u7b26\u4e32\u3002\u7ed9\u4f60\u4e00\u4e2a\u6ee1\u8db3\u4e0b\u8ff0\u683c\u5f0f\u7684\u53e5\u5b50 text :

    \n\n
      \n\t
    • \u53e5\u5b50\u7684\u9996\u5b57\u6bcd\u5927\u5199
    • \n\t
    • text \u4e2d\u7684\u6bcf\u4e2a\u5355\u8bcd\u90fd\u7528\u5355\u4e2a\u7a7a\u683c\u5206\u9694\u3002
    • \n
    \n\n

    \u8bf7\u4f60\u91cd\u65b0\u6392\u5217 text \u4e2d\u7684\u5355\u8bcd\uff0c\u4f7f\u6240\u6709\u5355\u8bcd\u6309\u5176\u957f\u5ea6\u7684\u5347\u5e8f\u6392\u5217\u3002\u5982\u679c\u4e24\u4e2a\u5355\u8bcd\u7684\u957f\u5ea6\u76f8\u540c\uff0c\u5219\u4fdd\u7559\u5176\u5728\u539f\u53e5\u5b50\u4e2d\u7684\u76f8\u5bf9\u987a\u5e8f\u3002

    \n\n

    \u8bf7\u540c\u6837\u6309\u4e0a\u8ff0\u683c\u5f0f\u8fd4\u56de\u65b0\u7684\u53e5\u5b50\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1atext = "Leetcode is cool"\n\u8f93\u51fa\uff1a"Is cool leetcode"\n\u89e3\u91ca\uff1a\u53e5\u5b50\u4e2d\u5171\u6709 3 \u4e2a\u5355\u8bcd\uff0c\u957f\u5ea6\u4e3a 8 \u7684 "Leetcode" \uff0c\u957f\u5ea6\u4e3a 2 \u7684 "is" \u4ee5\u53ca\u957f\u5ea6\u4e3a 4 \u7684 "cool" \u3002\n\u8f93\u51fa\u9700\u8981\u6309\u5355\u8bcd\u7684\u957f\u5ea6\u5347\u5e8f\u6392\u5217\uff0c\u65b0\u53e5\u5b50\u4e2d\u7684\u7b2c\u4e00\u4e2a\u5355\u8bcd\u9996\u5b57\u6bcd\u9700\u8981\u5927\u5199\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1atext = "Keep calm and code on"\n\u8f93\u51fa\uff1a"On and keep calm code"\n\u89e3\u91ca\uff1a\u8f93\u51fa\u7684\u6392\u5e8f\u60c5\u51b5\u5982\u4e0b\uff1a\n"On" 2 \u4e2a\u5b57\u6bcd\u3002\n"and" 3 \u4e2a\u5b57\u6bcd\u3002\n"keep" 4 \u4e2a\u5b57\u6bcd\uff0c\u56e0\u4e3a\u5b58\u5728\u957f\u5ea6\u76f8\u540c\u7684\u5176\u4ed6\u5355\u8bcd\uff0c\u6240\u4ee5\u5b83\u4eec\u4e4b\u95f4\u9700\u8981\u4fdd\u7559\u5728\u539f\u53e5\u5b50\u4e2d\u7684\u76f8\u5bf9\u987a\u5e8f\u3002\n"calm" 4 \u4e2a\u5b57\u6bcd\u3002\n"code" 4 \u4e2a\u5b57\u6bcd\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1atext = "To be or not to be"\n\u8f93\u51fa\uff1a"To be or to be not"\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • text \u4ee5\u5927\u5199\u5b57\u6bcd\u5f00\u5934\uff0c\u7136\u540e\u5305\u542b\u82e5\u5e72\u5c0f\u5199\u5b57\u6bcd\u4ee5\u53ca\u5355\u8bcd\u95f4\u7684\u5355\u4e2a\u7a7a\u683c\u3002
    • \n\t
    • 1 <= text.length <= 10^5
    • \n
    \n", "tags_en": ["Sort", "String"], "tags_cn": ["\u6392\u5e8f", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string arrangeWords(string text) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String arrangeWords(String text) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def arrangeWords(self, text):\n \"\"\"\n :type text: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def arrangeWords(self, text: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * arrangeWords(char * text){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ArrangeWords(string text) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} text\n * @return {string}\n */\nvar arrangeWords = function(text) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} text\n# @return {String}\ndef arrange_words(text)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func arrangeWords(_ text: String) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func arrangeWords(text string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def arrangeWords(text: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun arrangeWords(text: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn arrange_words(text: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $text\n * @return String\n */\n function arrangeWords($text) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function arrangeWords(text: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (arrange-words text)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1451](https://leetcode-cn.com/problems/rearrange-words-in-a-sentence)", "[\u91cd\u65b0\u6392\u5217\u53e5\u5b50\u4e2d\u7684\u5355\u8bcd](/solution/1400-1499/1451.Rearrange%20Words%20in%20a%20Sentence/README.md)", "`\u6392\u5e8f`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1451](https://leetcode.com/problems/rearrange-words-in-a-sentence)", "[Rearrange Words in a Sentence](/solution/1400-1499/1451.Rearrange%20Words%20in%20a%20Sentence/README_EN.md)", "`Sort`,`String`", "Medium", ""]}, {"question_id": "1560", "frontend_question_id": "1450", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-students-doing-homework-at-a-given-time", "url_en": "https://leetcode.com/problems/number-of-students-doing-homework-at-a-given-time", "relative_path_cn": "/solution/1400-1499/1450.Number%20of%20Students%20Doing%20Homework%20at%20a%20Given%20Time/README.md", "relative_path_en": "/solution/1400-1499/1450.Number%20of%20Students%20Doing%20Homework%20at%20a%20Given%20Time/README_EN.md", "title_cn": "\u5728\u65e2\u5b9a\u65f6\u95f4\u505a\u4f5c\u4e1a\u7684\u5b66\u751f\u4eba\u6570", "title_en": "Number of Students Doing Homework at a Given Time", "question_title_slug": "number-of-students-doing-homework-at-a-given-time", "content_en": "

    Given two integer arrays startTime and endTime and given an integer queryTime.

    \n\n

    The ith student started doing their homework at the time startTime[i] and finished it at time endTime[i].

    \n\n

    Return the number of students doing their homework at time queryTime. More formally, return the number of students where queryTime lays in the interval [startTime[i], endTime[i]] inclusive.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: startTime = [1,2,3], endTime = [3,2,7], queryTime = 4\nOutput: 1\nExplanation: We have 3 students where:\nThe first student started doing homework at time 1 and finished at time 3 and wasn't doing anything at time 4.\nThe second student started doing homework at time 2 and finished at time 2 and also wasn't doing anything at time 4.\nThe third student started doing homework at time 3 and finished at time 7 and was the only student doing homework at time 4.\n
    \n\n

    Example 2:

    \n\n
    \nInput: startTime = [4], endTime = [4], queryTime = 4\nOutput: 1\nExplanation: The only student was doing their homework at the queryTime.\n
    \n\n

    Example 3:

    \n\n
    \nInput: startTime = [4], endTime = [4], queryTime = 5\nOutput: 0\n
    \n\n

    Example 4:

    \n\n
    \nInput: startTime = [1,1,1,1], endTime = [1,3,2,4], queryTime = 7\nOutput: 0\n
    \n\n

    Example 5:

    \n\n
    \nInput: startTime = [9,8,7,6,5,4,3,2,1], endTime = [10,10,10,10,10,10,10,10,10], queryTime = 5\nOutput: 5\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • startTime.length == endTime.length
    • \n\t
    • 1 <= startTime.length <= 100
    • \n\t
    • 1 <= startTime[i] <= endTime[i] <= 1000
    • \n\t
    • 1 <= queryTime <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u6574\u6570\u6570\u7ec4 startTime\uff08\u5f00\u59cb\u65f6\u95f4\uff09\u548c endTime\uff08\u7ed3\u675f\u65f6\u95f4\uff09\uff0c\u5e76\u6307\u5b9a\u4e00\u4e2a\u6574\u6570 queryTime \u4f5c\u4e3a\u67e5\u8be2\u65f6\u95f4\u3002

    \n\n

    \u5df2\u77e5\uff0c\u7b2c i \u540d\u5b66\u751f\u5728 startTime[i] \u65f6\u5f00\u59cb\u5199\u4f5c\u4e1a\u5e76\u4e8e endTime[i] \u65f6\u5b8c\u6210\u4f5c\u4e1a\u3002

    \n\n

    \u8bf7\u8fd4\u56de\u5728\u67e5\u8be2\u65f6\u95f4 queryTime \u65f6\u6b63\u5728\u505a\u4f5c\u4e1a\u7684\u5b66\u751f\u4eba\u6570\u3002\u5f62\u5f0f\u4e0a\uff0c\u8fd4\u56de\u80fd\u591f\u4f7f queryTime \u5904\u4e8e\u533a\u95f4 [startTime[i], endTime[i]]\uff08\u542b\uff09\u7684\u5b66\u751f\u4eba\u6570\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1astartTime = [1,2,3], endTime = [3,2,7], queryTime = 4\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u4e00\u5171\u6709 3 \u540d\u5b66\u751f\u3002\n\u7b2c\u4e00\u540d\u5b66\u751f\u5728\u65f6\u95f4 1 \u5f00\u59cb\u5199\u4f5c\u4e1a\uff0c\u5e76\u4e8e\u65f6\u95f4 3 \u5b8c\u6210\u4f5c\u4e1a\uff0c\u5728\u65f6\u95f4 4 \u6ca1\u6709\u5904\u4e8e\u505a\u4f5c\u4e1a\u7684\u72b6\u6001\u3002\n\u7b2c\u4e8c\u540d\u5b66\u751f\u5728\u65f6\u95f4 2 \u5f00\u59cb\u5199\u4f5c\u4e1a\uff0c\u5e76\u4e8e\u65f6\u95f4 2 \u5b8c\u6210\u4f5c\u4e1a\uff0c\u5728\u65f6\u95f4 4 \u6ca1\u6709\u5904\u4e8e\u505a\u4f5c\u4e1a\u7684\u72b6\u6001\u3002\n\u7b2c\u4e09\u540d\u5b66\u751f\u5728\u65f6\u95f4 3 \u5f00\u59cb\u5199\u4f5c\u4e1a\uff0c\u9884\u8ba1\u4e8e\u65f6\u95f4 7 \u5b8c\u6210\u4f5c\u4e1a\uff0c\u8fd9\u662f\u662f\u552f\u4e00\u4e00\u540d\u5728\u65f6\u95f4 4 \u65f6\u6b63\u5728\u505a\u4f5c\u4e1a\u7684\u5b66\u751f\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1astartTime = [4], endTime = [4], queryTime = 4\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u5728\u67e5\u8be2\u65f6\u95f4\u53ea\u6709\u4e00\u540d\u5b66\u751f\u5728\u505a\u4f5c\u4e1a\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1astartTime = [4], endTime = [4], queryTime = 5\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1astartTime = [1,1,1,1], endTime = [1,3,2,4], queryTime = 7\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1astartTime = [9,8,7,6,5,4,3,2,1], endTime = [10,10,10,10,10,10,10,10,10], queryTime = 5\n\u8f93\u51fa\uff1a5\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • startTime.length == endTime.length
    • \n\t
    • 1 <= startTime.length <= 100
    • \n\t
    • 1 <= startTime[i] <= endTime[i] <= 1000
    • \n\t
    • 1 <= queryTime <= 1000
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int busyStudent(vector& startTime, vector& endTime, int queryTime) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int busyStudent(int[] startTime, int[] endTime, int queryTime) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def busyStudent(self, startTime, endTime, queryTime):\n \"\"\"\n :type startTime: List[int]\n :type endTime: List[int]\n :type queryTime: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint busyStudent(int* startTime, int startTimeSize, int* endTime, int endTimeSize, int queryTime){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int BusyStudent(int[] startTime, int[] endTime, int queryTime) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} startTime\n * @param {number[]} endTime\n * @param {number} queryTime\n * @return {number}\n */\nvar busyStudent = function(startTime, endTime, queryTime) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} start_time\n# @param {Integer[]} end_time\n# @param {Integer} query_time\n# @return {Integer}\ndef busy_student(start_time, end_time, query_time)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func busyStudent(_ startTime: [Int], _ endTime: [Int], _ queryTime: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func busyStudent(startTime []int, endTime []int, queryTime int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def busyStudent(startTime: Array[Int], endTime: Array[Int], queryTime: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun busyStudent(startTime: IntArray, endTime: IntArray, queryTime: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn busy_student(start_time: Vec, end_time: Vec, query_time: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $startTime\n * @param Integer[] $endTime\n * @param Integer $queryTime\n * @return Integer\n */\n function busyStudent($startTime, $endTime, $queryTime) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function busyStudent(startTime: number[], endTime: number[], queryTime: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (busy-student startTime endTime queryTime)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1450](https://leetcode-cn.com/problems/number-of-students-doing-homework-at-a-given-time)", "[\u5728\u65e2\u5b9a\u65f6\u95f4\u505a\u4f5c\u4e1a\u7684\u5b66\u751f\u4eba\u6570](/solution/1400-1499/1450.Number%20of%20Students%20Doing%20Homework%20at%20a%20Given%20Time/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1450](https://leetcode.com/problems/number-of-students-doing-homework-at-a-given-time)", "[Number of Students Doing Homework at a Given Time](/solution/1400-1499/1450.Number%20of%20Students%20Doing%20Homework%20at%20a%20Given%20Time/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1559", "frontend_question_id": "1463", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/cherry-pickup-ii", "url_en": "https://leetcode.com/problems/cherry-pickup-ii", "relative_path_cn": "/solution/1400-1499/1463.Cherry%20Pickup%20II/README.md", "relative_path_en": "/solution/1400-1499/1463.Cherry%20Pickup%20II/README_EN.md", "title_cn": "\u6458\u6a31\u6843 II", "title_en": "Cherry Pickup II", "question_title_slug": "cherry-pickup-ii", "content_en": "

    Given a rows x cols matrix grid representing a field of cherries. Each cell in grid represents the number of cherries that you can collect.

    \n\n

    You have two robots that can collect cherries for you, Robot #1 is located at the top-left corner (0,0) , and Robot #2 is located at the top-right corner (0, cols-1) of the grid.

    \n\n

    Return the maximum number of cherries collection using both robots  by following the rules below:

    \n\n
      \n\t
    • From a cell (i,j), robots can move to cell (i+1, j-1) , (i+1, j) or (i+1, j+1).
    • \n\t
    • When any robot is passing through a cell, It picks it up all cherries, and the cell becomes an empty cell (0).
    • \n\t
    • When both robots stay on the same cell, only one of them takes the cherries.
    • \n\t
    • Both robots cannot move outside of the grid at any moment.
    • \n\t
    • Both robots should reach the bottom row in the grid.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: grid = [[3,1,1],[2,5,1],[1,5,5],[2,1,1]]\nOutput: 24\nExplanation: Path of robot #1 and #2 are described in color green and blue respectively.\nCherries taken by Robot #1, (3 + 2 + 5 + 2) = 12.\nCherries taken by Robot #2, (1 + 5 + 5 + 1) = 12.\nTotal of cherries: 12 + 12 = 24.\n
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: grid = [[1,0,0,0,0,0,1],[2,0,0,0,0,3,0],[2,0,9,0,0,0,0],[0,3,0,5,4,0,0],[1,0,2,3,0,0,6]]\nOutput: 28\nExplanation: Path of robot #1 and #2 are described in color green and blue respectively.\nCherries taken by Robot #1, (1 + 9 + 5 + 2) = 17.\nCherries taken by Robot #2, (1 + 3 + 4 + 3) = 11.\nTotal of cherries: 17 + 11 = 28.\n
    \n\n

    Example 3:

    \n\n
    \nInput: grid = [[1,0,0,3],[0,0,0,3],[0,0,3,3],[9,0,3,3]]\nOutput: 22\n
    \n\n

    Example 4:

    \n\n
    \nInput: grid = [[1,1],[1,1]]\nOutput: 4\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • rows == grid.length
    • \n\t
    • cols == grid[i].length
    • \n\t
    • 2 <= rows, cols <= 70
    • \n\t
    • 0 <= grid[i][j] <= 100 
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a rows x cols \u7684\u77e9\u9635 grid \u6765\u8868\u793a\u4e00\u5757\u6a31\u6843\u5730\u3002 grid \u4e2d\u6bcf\u4e2a\u683c\u5b50\u7684\u6570\u5b57\u8868\u793a\u4f60\u80fd\u83b7\u5f97\u7684\u6a31\u6843\u6570\u76ee\u3002

    \n\n

    \u4f60\u6709\u4e24\u4e2a\u673a\u5668\u4eba\u5e2e\u4f60\u6536\u96c6\u6a31\u6843\uff0c\u673a\u5668\u4eba 1 \u4ece\u5de6\u4e0a\u89d2\u683c\u5b50 (0,0) \u51fa\u53d1\uff0c\u673a\u5668\u4eba 2 \u4ece\u53f3\u4e0a\u89d2\u683c\u5b50 (0, cols-1) \u51fa\u53d1\u3002

    \n\n

    \u8bf7\u4f60\u6309\u7167\u5982\u4e0b\u89c4\u5219\uff0c\u8fd4\u56de\u4e24\u4e2a\u673a\u5668\u4eba\u80fd\u6536\u96c6\u7684\u6700\u591a\u6a31\u6843\u6570\u76ee\uff1a

    \n\n
      \n\t
    • \u4ece\u683c\u5b50 (i,j) \u51fa\u53d1\uff0c\u673a\u5668\u4eba\u53ef\u4ee5\u79fb\u52a8\u5230\u683c\u5b50 (i+1, j-1)\uff0c(i+1, j) \u6216\u8005 (i+1, j+1) \u3002
    • \n\t
    • \u5f53\u4e00\u4e2a\u673a\u5668\u4eba\u7ecf\u8fc7\u67d0\u4e2a\u683c\u5b50\u65f6\uff0c\u5b83\u4f1a\u628a\u8be5\u683c\u5b50\u5185\u6240\u6709\u7684\u6a31\u6843\u90fd\u6458\u8d70\uff0c\u7136\u540e\u8fd9\u4e2a\u4f4d\u7f6e\u4f1a\u53d8\u6210\u7a7a\u683c\u5b50\uff0c\u5373\u6ca1\u6709\u6a31\u6843\u7684\u683c\u5b50\u3002
    • \n\t
    • \u5f53\u4e24\u4e2a\u673a\u5668\u4eba\u540c\u65f6\u5230\u8fbe\u540c\u4e00\u4e2a\u683c\u5b50\u65f6\uff0c\u5b83\u4eec\u4e2d\u53ea\u6709\u4e00\u4e2a\u53ef\u4ee5\u6458\u5230\u6a31\u6843\u3002
    • \n\t
    • \u4e24\u4e2a\u673a\u5668\u4eba\u5728\u4efb\u610f\u65f6\u523b\u90fd\u4e0d\u80fd\u79fb\u52a8\u5230 grid \u5916\u9762\u3002
    • \n\t
    • \u4e24\u4e2a\u673a\u5668\u4eba\u6700\u540e\u90fd\u8981\u5230\u8fbe grid \u6700\u5e95\u4e0b\u4e00\u884c\u3002
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1agrid = [[3,1,1],[2,5,1],[1,5,5],[2,1,1]]\n\u8f93\u51fa\uff1a24\n\u89e3\u91ca\uff1a\u673a\u5668\u4eba 1 \u548c\u673a\u5668\u4eba 2 \u7684\u8def\u5f84\u5728\u4e0a\u56fe\u4e2d\u5206\u522b\u7528\u7eff\u8272\u548c\u84dd\u8272\u8868\u793a\u3002\n\u673a\u5668\u4eba 1 \u6458\u7684\u6a31\u6843\u6570\u76ee\u4e3a (3 + 2 + 5 + 2) = 12 \u3002\n\u673a\u5668\u4eba 2 \u6458\u7684\u6a31\u6843\u6570\u76ee\u4e3a (1 + 5 + 5 + 1) = 12 \u3002\n\u6a31\u6843\u603b\u6570\u4e3a\uff1a 12 + 12 = 24 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1agrid = [[1,0,0,0,0,0,1],[2,0,0,0,0,3,0],[2,0,9,0,0,0,0],[0,3,0,5,4,0,0],[1,0,2,3,0,0,6]]\n\u8f93\u51fa\uff1a28\n\u89e3\u91ca\uff1a\u673a\u5668\u4eba 1 \u548c\u673a\u5668\u4eba 2 \u7684\u8def\u5f84\u5728\u4e0a\u56fe\u4e2d\u5206\u522b\u7528\u7eff\u8272\u548c\u84dd\u8272\u8868\u793a\u3002\n\u673a\u5668\u4eba 1 \u6458\u7684\u6a31\u6843\u6570\u76ee\u4e3a (1 + 9 + 5 + 2) = 17 \u3002\n\u673a\u5668\u4eba 2 \u6458\u7684\u6a31\u6843\u6570\u76ee\u4e3a (1 + 3 + 4 + 3) = 11 \u3002\n\u6a31\u6843\u603b\u6570\u4e3a\uff1a 17 + 11 = 28 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1agrid = [[1,0,0,3],[0,0,0,3],[0,0,3,3],[9,0,3,3]]\n\u8f93\u51fa\uff1a22\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1agrid = [[1,1],[1,1]]\n\u8f93\u51fa\uff1a4\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • rows == grid.length
    • \n\t
    • cols == grid[i].length
    • \n\t
    • 2 <= rows, cols <= 70
    • \n\t
    • 0 <= grid[i][j] <= 100 
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int cherryPickup(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int cherryPickup(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def cherryPickup(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def cherryPickup(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint cherryPickup(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CherryPickup(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar cherryPickup = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef cherry_pickup(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func cherryPickup(_ grid: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func cherryPickup(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def cherryPickup(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun cherryPickup(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn cherry_pickup(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function cherryPickup($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function cherryPickup(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (cherry-pickup grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1463](https://leetcode-cn.com/problems/cherry-pickup-ii)", "[\u6458\u6a31\u6843 II](/solution/1400-1499/1463.Cherry%20Pickup%20II/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1463](https://leetcode.com/problems/cherry-pickup-ii)", "[Cherry Pickup II](/solution/1400-1499/1463.Cherry%20Pickup%20II/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1558", "frontend_question_id": "1462", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/course-schedule-iv", "url_en": "https://leetcode.com/problems/course-schedule-iv", "relative_path_cn": "/solution/1400-1499/1462.Course%20Schedule%20IV/README.md", "relative_path_en": "/solution/1400-1499/1462.Course%20Schedule%20IV/README_EN.md", "title_cn": "\u8bfe\u7a0b\u8868 IV", "title_en": "Course Schedule IV", "question_title_slug": "course-schedule-iv", "content_en": "

    There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i] = [ai, bi] indicates that you must take course bi first if you want to take course ai.

    \n\n
      \n\t
    • For example, the pair [0, 1], indicates that to take course 0 you have to first take course 1.
    • \n
    \n\n

    You are also given an array queries where queries[j] = [uj, vj]. For the jth query, you should answer whether the course uj is a prerequisite of the course vj or not. Note that if course a is a prerequisite of course b and course b is a prerequisite of course c, then, course a is a prerequisite of course c.

    \n\n

    Return a boolean array answer, where answer[j] is the answer of the jth query.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: numCourses = 2, prerequisites = [[1,0]], queries = [[0,1],[1,0]]\nOutput: [false,true]\nExplanation: course 0 is not a prerequisite of course 1 but the opposite is true.\n
    \n\n

    Example 2:

    \n\n
    \nInput: numCourses = 2, prerequisites = [], queries = [[1,0],[0,1]]\nOutput: [false,false]\nExplanation: There are no prerequisites and each course is independent.\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: numCourses = 3, prerequisites = [[1,2],[1,0],[2,0]], queries = [[1,0],[1,2]]\nOutput: [true,true]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= numCourses <= 100
    • \n\t
    • 0 <= prerequisite.length <= (numCourses * (numCourses - 1) / 2)
    • \n\t
    • 0 <= ai, bi < n
    • \n\t
    • ai != bi
    • \n\t
    • All the pairs [ai, bi] are unique.
    • \n\t
    • The prerequisites graph has no cycles.
    • \n\t
    • 1 <= queries.length <= 104
    • \n\t
    • 0 <= ui, vi < n
    • \n\t
    • ui != vi
    • \n
    \n", "content_cn": "

    \u4f60\u603b\u5171\u9700\u8981\u4e0a n \u95e8\u8bfe\uff0c\u8bfe\u7a0b\u7f16\u53f7\u4f9d\u6b21\u4e3a 0 \u5230 n-1 \u3002

    \n\n

    \u6709\u7684\u8bfe\u4f1a\u6709\u76f4\u63a5\u7684\u5148\u4fee\u8bfe\u7a0b\uff0c\u6bd4\u5982\u5982\u679c\u60f3\u4e0a\u8bfe\u7a0b 0 \uff0c\u4f60\u5fc5\u987b\u5148\u4e0a\u8bfe\u7a0b 1 \uff0c\u90a3\u4e48\u4f1a\u4ee5 [1,0] \u6570\u5bf9\u7684\u5f62\u5f0f\u7ed9\u51fa\u5148\u4fee\u8bfe\u7a0b\u6570\u5bf9\u3002

    \n\n

    \u7ed9\u4f60\u8bfe\u7a0b\u603b\u6570 n \u548c\u4e00\u4e2a\u76f4\u63a5\u5148\u4fee\u8bfe\u7a0b\u6570\u5bf9\u5217\u8868 prerequisite \u548c\u4e00\u4e2a\u67e5\u8be2\u5bf9\u5217\u8868 queries \u3002

    \n\n

    \u5bf9\u4e8e\u6bcf\u4e2a\u67e5\u8be2\u5bf9 queries[i] \uff0c\u8bf7\u5224\u65ad queries[i][0] \u662f\u5426\u662f queries[i][1] \u7684\u5148\u4fee\u8bfe\u7a0b\u3002

    \n\n

    \u8bf7\u8fd4\u56de\u4e00\u4e2a\u5e03\u5c14\u503c\u5217\u8868\uff0c\u5217\u8868\u4e2d\u6bcf\u4e2a\u5143\u7d20\u4f9d\u6b21\u5206\u522b\u5bf9\u5e94 queries \u6bcf\u4e2a\u67e5\u8be2\u5bf9\u7684\u5224\u65ad\u7ed3\u679c\u3002

    \n\n

    \u6ce8\u610f\uff1a\u5982\u679c\u8bfe\u7a0b a \u662f\u8bfe\u7a0b b \u7684\u5148\u4fee\u8bfe\u7a0b\u4e14\u8bfe\u7a0b b \u662f\u8bfe\u7a0b c \u7684\u5148\u4fee\u8bfe\u7a0b\uff0c\u90a3\u4e48\u8bfe\u7a0b a \u4e5f\u662f\u8bfe\u7a0b c \u7684\u5148\u4fee\u8bfe\u7a0b\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 2, prerequisites = [[1,0]], queries = [[0,1],[1,0]]\n\u8f93\u51fa\uff1a[false,true]\n\u89e3\u91ca\uff1a\u8bfe\u7a0b 0 \u4e0d\u662f\u8bfe\u7a0b 1 \u7684\u5148\u4fee\u8bfe\u7a0b\uff0c\u4f46\u8bfe\u7a0b 1 \u662f\u8bfe\u7a0b 0 \u7684\u5148\u4fee\u8bfe\u7a0b\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1an = 2, prerequisites = [], queries = [[1,0],[0,1]]\n\u8f93\u51fa\uff1a[false,false]\n\u89e3\u91ca\uff1a\u6ca1\u6709\u5148\u4fee\u8bfe\u7a0b\u5bf9\uff0c\u6240\u4ee5\u6bcf\u95e8\u8bfe\u7a0b\u4e4b\u95f4\u662f\u72ec\u7acb\u7684\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 3, prerequisites = [[1,2],[1,0],[2,0]], queries = [[1,0],[1,2]]\n\u8f93\u51fa\uff1a[true,true]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1an = 3, prerequisites = [[1,0],[2,0]], queries = [[0,1],[2,0]]\n\u8f93\u51fa\uff1a[false,true]\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1an = 5, prerequisites = [[0,1],[1,2],[2,3],[3,4]], queries = [[0,4],[4,0],[1,3],[3,0]]\n\u8f93\u51fa\uff1a[true,false,true,false]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= n <= 100
    • \n\t
    • 0 <= prerequisite.length <= (n * (n - 1) / 2)
    • \n\t
    • 0 <= prerequisite[i][0], prerequisite[i][1] < n
    • \n\t
    • prerequisite[i][0] != prerequisite[i][1]
    • \n\t
    • \u5148\u4fee\u8bfe\u7a0b\u56fe\u4e2d\u6ca1\u6709\u73af\u3002
    • \n\t
    • \u5148\u4fee\u8bfe\u7a0b\u56fe\u4e2d\u6ca1\u6709\u91cd\u590d\u7684\u8fb9\u3002
    • \n\t
    • 1 <= queries.length <= 10^4
    • \n\t
    • queries[i][0] != queries[i][1]
    • \n
    \n", "tags_en": ["Graph"], "tags_cn": ["\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector checkIfPrerequisite(int numCourses, vector>& prerequisites, vector>& queries) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List checkIfPrerequisite(int numCourses, int[][] prerequisites, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def checkIfPrerequisite(self, numCourses, prerequisites, queries):\n \"\"\"\n :type numCourses: int\n :type prerequisites: List[List[int]]\n :type queries: List[List[int]]\n :rtype: List[bool]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def checkIfPrerequisite(self, numCourses: int, prerequisites: List[List[int]], queries: List[List[int]]) -> List[bool]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nbool* checkIfPrerequisite(int numCourses, int** prerequisites, int prerequisitesSize, int* prerequisitesColSize, int** queries, int queriesSize, int* queriesColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList CheckIfPrerequisite(int numCourses, int[][] prerequisites, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} numCourses\n * @param {number[][]} prerequisites\n * @param {number[][]} queries\n * @return {boolean[]}\n */\nvar checkIfPrerequisite = function(numCourses, prerequisites, queries) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} num_courses\n# @param {Integer[][]} prerequisites\n# @param {Integer[][]} queries\n# @return {Boolean[]}\ndef check_if_prerequisite(num_courses, prerequisites, queries)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func checkIfPrerequisite(_ numCourses: Int, _ prerequisites: [[Int]], _ queries: [[Int]]) -> [Bool] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func checkIfPrerequisite(numCourses int, prerequisites [][]int, queries [][]int) []bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def checkIfPrerequisite(numCourses: Int, prerequisites: Array[Array[Int]], queries: Array[Array[Int]]): List[Boolean] = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun checkIfPrerequisite(numCourses: Int, prerequisites: Array, queries: Array): List {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn check_if_prerequisite(num_courses: i32, prerequisites: Vec>, queries: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $numCourses\n * @param Integer[][] $prerequisites\n * @param Integer[][] $queries\n * @return Boolean[]\n */\n function checkIfPrerequisite($numCourses, $prerequisites, $queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function checkIfPrerequisite(numCourses: number, prerequisites: number[][], queries: number[][]): boolean[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (check-if-prerequisite numCourses prerequisites queries)\n (-> exact-integer? (listof (listof exact-integer?)) (listof (listof exact-integer?)) (listof boolean?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1462](https://leetcode-cn.com/problems/course-schedule-iv)", "[\u8bfe\u7a0b\u8868 IV](/solution/1400-1499/1462.Course%20Schedule%20IV/README.md)", "`\u56fe`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1462](https://leetcode.com/problems/course-schedule-iv)", "[Course Schedule IV](/solution/1400-1499/1462.Course%20Schedule%20IV/README_EN.md)", "`Graph`", "Medium", ""]}, {"question_id": "1557", "frontend_question_id": "1461", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/check-if-a-string-contains-all-binary-codes-of-size-k", "url_en": "https://leetcode.com/problems/check-if-a-string-contains-all-binary-codes-of-size-k", "relative_path_cn": "/solution/1400-1499/1461.Check%20If%20a%20String%20Contains%20All%20Binary%20Codes%20of%20Size%20K/README.md", "relative_path_en": "/solution/1400-1499/1461.Check%20If%20a%20String%20Contains%20All%20Binary%20Codes%20of%20Size%20K/README_EN.md", "title_cn": "\u68c0\u67e5\u4e00\u4e2a\u5b57\u7b26\u4e32\u662f\u5426\u5305\u542b\u6240\u6709\u957f\u5ea6\u4e3a K \u7684\u4e8c\u8fdb\u5236\u5b50\u4e32", "title_en": "Check If a String Contains All Binary Codes of Size K", "question_title_slug": "check-if-a-string-contains-all-binary-codes-of-size-k", "content_en": "

    Given a binary string s and an integer k.

    \n\n

    Return true if every binary code of length k is a substring of s. Otherwise, return false.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "00110110", k = 2\nOutput: true\nExplanation: The binary codes of length 2 are "00", "01", "10" and "11". They can be all found as substrings at indicies 0, 1, 3 and 2 respectively.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "00110", k = 2\nOutput: true\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "0110", k = 1\nOutput: true\nExplanation: The binary codes of length 1 are "0" and "1", it is clear that both exist as a substring. \n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "0110", k = 2\nOutput: false\nExplanation: The binary code "00" is of length 2 and doesn't exist in the array.\n
    \n\n

    Example 5:

    \n\n
    \nInput: s = "0000000001011100", k = 4\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 5 * 105
    • \n\t
    • s[i] is either '0' or '1'.
    • \n\t
    • 1 <= k <= 20
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32\u00a0s\u00a0\u548c\u4e00\u4e2a\u6574\u6570\u00a0k\u00a0\u3002

    \n\n

    \u5982\u679c\u6240\u6709\u957f\u5ea6\u4e3a k\u00a0\u7684\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32\u90fd\u662f s\u00a0\u7684\u5b50\u4e32\uff0c\u8bf7\u8fd4\u56de true \uff0c\u5426\u5219\u8bf7\u8fd4\u56de false \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"00110110\", k = 2\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u957f\u5ea6\u4e3a 2 \u7684\u4e8c\u8fdb\u5236\u4e32\u5305\u62ec \"00\"\uff0c\"01\"\uff0c\"10\" \u548c \"11\"\u3002\u5b83\u4eec\u5206\u522b\u662f s \u4e2d\u4e0b\u6807\u4e3a 0\uff0c1\uff0c3\uff0c2 \u5f00\u59cb\u7684\u957f\u5ea6\u4e3a 2 \u7684\u5b50\u4e32\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"00110\", k = 2\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"0110\", k = 1\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u957f\u5ea6\u4e3a 1 \u7684\u4e8c\u8fdb\u5236\u4e32\u5305\u62ec \"0\" \u548c \"1\"\uff0c\u663e\u7136\u5b83\u4eec\u90fd\u662f s \u7684\u5b50\u4e32\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"0110\", k = 2\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u957f\u5ea6\u4e3a 2 \u7684\u4e8c\u8fdb\u5236\u4e32 \"00\" \u6ca1\u6709\u51fa\u73b0\u5728 s \u4e2d\u3002\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"0000000001011100\", k = 4\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 5 * 105
    • \n\t
    • s[i] \u4e0d\u662f'0' \u5c31\u662f '1'
    • \n\t
    • 1 <= k <= 20
    • \n
    \n", "tags_en": ["Bit Manipulation", "String"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool hasAllCodes(string s, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean hasAllCodes(String s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def hasAllCodes(self, s, k):\n \"\"\"\n :type s: str\n :type k: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def hasAllCodes(self, s: str, k: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool hasAllCodes(char * s, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool HasAllCodes(string s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number} k\n * @return {boolean}\n */\nvar hasAllCodes = function(s, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer} k\n# @return {Boolean}\ndef has_all_codes(s, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func hasAllCodes(_ s: String, _ k: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func hasAllCodes(s string, k int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def hasAllCodes(s: String, k: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun hasAllCodes(s: String, k: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn has_all_codes(s: String, k: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer $k\n * @return Boolean\n */\n function hasAllCodes($s, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function hasAllCodes(s: string, k: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (has-all-codes s k)\n (-> string? exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1461](https://leetcode-cn.com/problems/check-if-a-string-contains-all-binary-codes-of-size-k)", "[\u68c0\u67e5\u4e00\u4e2a\u5b57\u7b26\u4e32\u662f\u5426\u5305\u542b\u6240\u6709\u957f\u5ea6\u4e3a K \u7684\u4e8c\u8fdb\u5236\u5b50\u4e32](/solution/1400-1499/1461.Check%20If%20a%20String%20Contains%20All%20Binary%20Codes%20of%20Size%20K/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1461](https://leetcode.com/problems/check-if-a-string-contains-all-binary-codes-of-size-k)", "[Check If a String Contains All Binary Codes of Size K](/solution/1400-1499/1461.Check%20If%20a%20String%20Contains%20All%20Binary%20Codes%20of%20Size%20K/README_EN.md)", "`Bit Manipulation`,`String`", "Medium", ""]}, {"question_id": "1556", "frontend_question_id": "1460", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/make-two-arrays-equal-by-reversing-sub-arrays", "url_en": "https://leetcode.com/problems/make-two-arrays-equal-by-reversing-sub-arrays", "relative_path_cn": "/solution/1400-1499/1460.Make%20Two%20Arrays%20Equal%20by%20Reversing%20Sub-arrays/README.md", "relative_path_en": "/solution/1400-1499/1460.Make%20Two%20Arrays%20Equal%20by%20Reversing%20Sub-arrays/README_EN.md", "title_cn": "\u901a\u8fc7\u7ffb\u8f6c\u5b50\u6570\u7ec4\u4f7f\u4e24\u4e2a\u6570\u7ec4\u76f8\u7b49", "title_en": "Make Two Arrays Equal by Reversing Sub-arrays", "question_title_slug": "make-two-arrays-equal-by-reversing-sub-arrays", "content_en": "

    Given two integer arrays of equal length target and arr.

    \n\n

    In one step, you can select any non-empty sub-array of arr and reverse it. You are allowed to make any number of steps.

    \n\n

    Return True if you can make arr equal to target, or False otherwise.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: target = [1,2,3,4], arr = [2,4,1,3]\nOutput: true\nExplanation: You can follow the next steps to convert arr to target:\n1- Reverse sub-array [2,4,1], arr becomes [1,4,2,3]\n2- Reverse sub-array [4,2], arr becomes [1,2,4,3]\n3- Reverse sub-array [4,3], arr becomes [1,2,3,4]\nThere are multiple ways to convert arr to target, this is not the only way to do so.\n
    \n\n

    Example 2:

    \n\n
    \nInput: target = [7], arr = [7]\nOutput: true\nExplanation: arr is equal to target without any reverses.\n
    \n\n

    Example 3:

    \n\n
    \nInput: target = [1,12], arr = [12,1]\nOutput: true\n
    \n\n

    Example 4:

    \n\n
    \nInput: target = [3,7,9], arr = [3,7,11]\nOutput: false\nExplanation: arr doesn't have value 9 and it can never be converted to target.\n
    \n\n

    Example 5:

    \n\n
    \nInput: target = [1,1,1,1,1], arr = [1,1,1,1,1]\nOutput: true\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • target.length == arr.length
    • \n\t
    • 1 <= target.length <= 1000
    • \n\t
    • 1 <= target[i] <= 1000
    • \n\t
    • 1 <= arr[i] <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u957f\u5ea6\u76f8\u540c\u7684\u6574\u6570\u6570\u7ec4 target \u548c arr \u3002

    \n\n

    \u6bcf\u4e00\u6b65\u4e2d\uff0c\u4f60\u53ef\u4ee5\u9009\u62e9 arr \u7684\u4efb\u610f \u975e\u7a7a\u5b50\u6570\u7ec4 \u5e76\u5c06\u5b83\u7ffb\u8f6c\u3002\u4f60\u53ef\u4ee5\u6267\u884c\u6b64\u8fc7\u7a0b\u4efb\u610f\u6b21\u3002

    \n\n

    \u5982\u679c\u4f60\u80fd\u8ba9 arr \u53d8\u5f97\u4e0e target \u76f8\u540c\uff0c\u8fd4\u56de True\uff1b\u5426\u5219\uff0c\u8fd4\u56de False \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1atarget = [1,2,3,4], arr = [2,4,1,3]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u6309\u7167\u5982\u4e0b\u6b65\u9aa4\u4f7f arr \u53d8\u6210 target\uff1a\n1- \u7ffb\u8f6c\u5b50\u6570\u7ec4 [2,4,1] \uff0carr \u53d8\u6210 [1,4,2,3]\n2- \u7ffb\u8f6c\u5b50\u6570\u7ec4 [4,2] \uff0carr \u53d8\u6210 [1,2,4,3]\n3- \u7ffb\u8f6c\u5b50\u6570\u7ec4 [4,3] \uff0carr \u53d8\u6210 [1,2,3,4]\n\u4e0a\u8ff0\u65b9\u6cd5\u5e76\u4e0d\u662f\u552f\u4e00\u7684\uff0c\u8fd8\u5b58\u5728\u591a\u79cd\u5c06 arr \u53d8\u6210 target \u7684\u65b9\u6cd5\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1atarget = [7], arr = [7]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1aarr \u4e0d\u9700\u8981\u505a\u4efb\u4f55\u7ffb\u8f6c\u5df2\u7ecf\u4e0e target \u76f8\u7b49\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1atarget = [1,12], arr = [12,1]\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1atarget = [3,7,9], arr = [3,7,11]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1aarr \u6ca1\u6709\u6570\u5b57 9 \uff0c\u6240\u4ee5\u65e0\u8bba\u5982\u4f55\u4e5f\u65e0\u6cd5\u53d8\u6210 target \u3002\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1atarget = [1,1,1,1,1], arr = [1,1,1,1,1]\n\u8f93\u51fa\uff1atrue\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • target.length == arr.length
    • \n\t
    • 1 <= target.length <= 1000
    • \n\t
    • 1 <= target[i] <= 1000
    • \n\t
    • 1 <= arr[i] <= 1000
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canBeEqual(vector& target, vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canBeEqual(int[] target, int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canBeEqual(self, target, arr):\n \"\"\"\n :type target: List[int]\n :type arr: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canBeEqual(self, target: List[int], arr: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canBeEqual(int* target, int targetSize, int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanBeEqual(int[] target, int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} target\n * @param {number[]} arr\n * @return {boolean}\n */\nvar canBeEqual = function(target, arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} target\n# @param {Integer[]} arr\n# @return {Boolean}\ndef can_be_equal(target, arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canBeEqual(_ target: [Int], _ arr: [Int]) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canBeEqual(target []int, arr []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canBeEqual(target: Array[Int], arr: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canBeEqual(target: IntArray, arr: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_be_equal(target: Vec, arr: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $target\n * @param Integer[] $arr\n * @return Boolean\n */\n function canBeEqual($target, $arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canBeEqual(target: number[], arr: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-be-equal target arr)\n (-> (listof exact-integer?) (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1460](https://leetcode-cn.com/problems/make-two-arrays-equal-by-reversing-sub-arrays)", "[\u901a\u8fc7\u7ffb\u8f6c\u5b50\u6570\u7ec4\u4f7f\u4e24\u4e2a\u6570\u7ec4\u76f8\u7b49](/solution/1400-1499/1460.Make%20Two%20Arrays%20Equal%20by%20Reversing%20Sub-arrays/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1460](https://leetcode.com/problems/make-two-arrays-equal-by-reversing-sub-arrays)", "[Make Two Arrays Equal by Reversing Sub-arrays](/solution/1400-1499/1460.Make%20Two%20Arrays%20Equal%20by%20Reversing%20Sub-arrays/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1555", "frontend_question_id": "1444", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-ways-of-cutting-a-pizza", "url_en": "https://leetcode.com/problems/number-of-ways-of-cutting-a-pizza", "relative_path_cn": "/solution/1400-1499/1444.Number%20of%20Ways%20of%20Cutting%20a%20Pizza/README.md", "relative_path_en": "/solution/1400-1499/1444.Number%20of%20Ways%20of%20Cutting%20a%20Pizza/README_EN.md", "title_cn": "\u5207\u62ab\u8428\u7684\u65b9\u6848\u6570", "title_en": "Number of Ways of Cutting a Pizza", "question_title_slug": "number-of-ways-of-cutting-a-pizza", "content_en": "

    Given a rectangular pizza represented as a rows x cols matrix containing the following characters: 'A' (an apple) and '.' (empty cell) and given the integer k. You have to cut the pizza into k pieces using k-1 cuts. 

    \r\n\r\n

    For each cut you choose the direction: vertical or horizontal, then you choose a cut position at the cell boundary and cut the pizza into two pieces. If you cut the pizza vertically, give the left part of the pizza to a person. If you cut the pizza horizontally, give the upper part of the pizza to a person. Give the last piece of pizza to the last person.

    \r\n\r\n

    Return the number of ways of cutting the pizza such that each piece contains at least one apple. Since the answer can be a huge number, return this modulo 10^9 + 7.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n

    \"\"

    \r\n\r\n
    \r\nInput: pizza = ["A..","AAA","..."], k = 3\r\nOutput: 3 \r\nExplanation: The figure above shows the three ways to cut the pizza. Note that pieces must contain at least one apple.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: pizza = ["A..","AA.","..."], k = 3\r\nOutput: 1\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: pizza = ["A..","A..","..."], k = 1\r\nOutput: 1\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= rows, cols <= 50
    • \r\n\t
    • rows == pizza.length
    • \r\n\t
    • cols == pizza[i].length
    • \r\n\t
    • 1 <= k <= 10
    • \r\n\t
    • pizza consists of characters 'A' and '.' only.
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a rows x cols \u5927\u5c0f\u7684\u77e9\u5f62\u62ab\u8428\u548c\u4e00\u4e2a\u6574\u6570 k \uff0c\u77e9\u5f62\u5305\u542b\u4e24\u79cd\u5b57\u7b26\uff1a 'A' \uff08\u8868\u793a\u82f9\u679c\uff09\u548c '.' \uff08\u8868\u793a\u7a7a\u767d\u683c\u5b50\uff09\u3002\u4f60\u9700\u8981\u5207\u62ab\u8428 k-1 \u6b21\uff0c\u5f97\u5230 k \u5757\u62ab\u8428\u5e76\u9001\u7ed9\u522b\u4eba\u3002

    \n\n

    \u5207\u62ab\u8428\u7684\u6bcf\u4e00\u5200\uff0c\u5148\u8981\u9009\u62e9\u662f\u5411\u5782\u76f4\u8fd8\u662f\u6c34\u5e73\u65b9\u5411\u5207\uff0c\u518d\u5728\u77e9\u5f62\u7684\u8fb9\u754c\u4e0a\u9009\u4e00\u4e2a\u5207\u7684\u4f4d\u7f6e\uff0c\u5c06\u62ab\u8428\u4e00\u5206\u4e3a\u4e8c\u3002\u5982\u679c\u5782\u76f4\u5730\u5207\u62ab\u8428\uff0c\u90a3\u4e48\u9700\u8981\u628a\u5de6\u8fb9\u7684\u90e8\u5206\u9001\u7ed9\u4e00\u4e2a\u4eba\uff0c\u5982\u679c\u6c34\u5e73\u5730\u5207\uff0c\u90a3\u4e48\u9700\u8981\u628a\u4e0a\u9762\u7684\u90e8\u5206\u9001\u7ed9\u4e00\u4e2a\u4eba\u3002\u5728\u5207\u5b8c\u6700\u540e\u4e00\u5200\u540e\uff0c\u9700\u8981\u628a\u5269\u4e0b\u6765\u7684\u4e00\u5757\u9001\u7ed9\u6700\u540e\u4e00\u4e2a\u4eba\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u786e\u4fdd\u6bcf\u4e00\u5757\u62ab\u8428\u5305\u542b \u81f3\u5c11 \u4e00\u4e2a\u82f9\u679c\u7684\u5207\u62ab\u8428\u65b9\u6848\u6570\u3002\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u662f\u4e2a\u5f88\u5927\u7684\u6570\u5b57\uff0c\u8bf7\u4f60\u8fd4\u56de\u5b83\u5bf9 10^9 + 7 \u53d6\u4f59\u7684\u7ed3\u679c\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1apizza = ["A..","AAA","..."], k = 3\n\u8f93\u51fa\uff1a3 \n\u89e3\u91ca\uff1a\u4e0a\u56fe\u5c55\u793a\u4e86\u4e09\u79cd\u5207\u62ab\u8428\u7684\u65b9\u6848\u3002\u6ce8\u610f\u6bcf\u4e00\u5757\u62ab\u8428\u90fd\u81f3\u5c11\u5305\u542b\u4e00\u4e2a\u82f9\u679c\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1apizza = ["A..","AA.","..."], k = 3\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1apizza = ["A..","A..","..."], k = 1\n\u8f93\u51fa\uff1a1\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= rows, cols <= 50
    • \n\t
    • rows == pizza.length
    • \n\t
    • cols == pizza[i].length
    • \n\t
    • 1 <= k <= 10
    • \n\t
    • pizza \u53ea\u5305\u542b\u5b57\u7b26 'A' \u548c '.' \u3002
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int ways(vector& pizza, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int ways(String[] pizza, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def ways(self, pizza, k):\n \"\"\"\n :type pizza: List[str]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def ways(self, pizza: List[str], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint ways(char ** pizza, int pizzaSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int Ways(string[] pizza, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} pizza\n * @param {number} k\n * @return {number}\n */\nvar ways = function(pizza, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} pizza\n# @param {Integer} k\n# @return {Integer}\ndef ways(pizza, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func ways(_ pizza: [String], _ k: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func ways(pizza []string, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def ways(pizza: Array[String], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun ways(pizza: Array, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn ways(pizza: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $pizza\n * @param Integer $k\n * @return Integer\n */\n function ways($pizza, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function ways(pizza: string[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (ways pizza k)\n (-> (listof string?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1444](https://leetcode-cn.com/problems/number-of-ways-of-cutting-a-pizza)", "[\u5207\u62ab\u8428\u7684\u65b9\u6848\u6570](/solution/1400-1499/1444.Number%20of%20Ways%20of%20Cutting%20a%20Pizza/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1444](https://leetcode.com/problems/number-of-ways-of-cutting-a-pizza)", "[Number of Ways of Cutting a Pizza](/solution/1400-1499/1444.Number%20of%20Ways%20of%20Cutting%20a%20Pizza/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1554", "frontend_question_id": "1443", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-time-to-collect-all-apples-in-a-tree", "url_en": "https://leetcode.com/problems/minimum-time-to-collect-all-apples-in-a-tree", "relative_path_cn": "/solution/1400-1499/1443.Minimum%20Time%20to%20Collect%20All%20Apples%20in%20a%20Tree/README.md", "relative_path_en": "/solution/1400-1499/1443.Minimum%20Time%20to%20Collect%20All%20Apples%20in%20a%20Tree/README_EN.md", "title_cn": "\u6536\u96c6\u6811\u4e0a\u6240\u6709\u82f9\u679c\u7684\u6700\u5c11\u65f6\u95f4", "title_en": "Minimum Time to Collect All Apples in a Tree", "question_title_slug": "minimum-time-to-collect-all-apples-in-a-tree", "content_en": "

    Given an undirected tree consisting of n vertices numbered from 0 to n-1, which has some apples in their vertices. You spend 1 second to walk over one edge of the tree. Return the minimum time in seconds you have to spend to collect all apples in the tree, starting at vertex 0 and coming back to this vertex.

    \n\n

    The edges of the undirected tree are given in the array edges, where edges[i] = [ai, bi] means that exists an edge connecting the vertices ai and bi. Additionally, there is a boolean array hasApple, where hasApple[i] = true means that vertex i has an apple; otherwise, it does not have any apple.

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: n = 7, edges = [[0,1],[0,2],[1,4],[1,5],[2,3],[2,6]], hasApple = [false,false,true,false,true,true,false]\nOutput: 8 \nExplanation: The figure above represents the given tree where red vertices have an apple. One optimal path to collect all apples is shown by the green arrows.  \n
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: n = 7, edges = [[0,1],[0,2],[1,4],[1,5],[2,3],[2,6]], hasApple = [false,false,true,false,false,true,false]\nOutput: 6\nExplanation: The figure above represents the given tree where red vertices have an apple. One optimal path to collect all apples is shown by the green arrows.  \n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 7, edges = [[0,1],[0,2],[1,4],[1,5],[2,3],[2,6]], hasApple = [false,false,false,false,false,false,false]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 10^5
    • \n\t
    • edges.length == n - 1
    • \n\t
    • edges[i].length == 2
    • \n\t
    • 0 <= ai < bi <= n - 1
    • \n\t
    • fromi < toi
    • \n\t
    • hasApple.length == n
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u68f5\u6709 n \u4e2a\u8282\u70b9\u7684\u65e0\u5411\u6811\uff0c\u8282\u70b9\u7f16\u53f7\u4e3a 0 \u5230 n-1 \uff0c\u5b83\u4eec\u4e2d\u6709\u4e00\u4e9b\u8282\u70b9\u6709\u82f9\u679c\u3002\u901a\u8fc7\u6811\u4e0a\u7684\u4e00\u6761\u8fb9\uff0c\u9700\u8981\u82b1\u8d39 1 \u79d2\u949f\u3002\u4f60\u4ece \u8282\u70b9 0 \u51fa\u53d1\uff0c\u8bf7\u4f60\u8fd4\u56de\u6700\u5c11\u9700\u8981\u591a\u5c11\u79d2\uff0c\u53ef\u4ee5\u6536\u96c6\u5230\u6240\u6709\u82f9\u679c\uff0c\u5e76\u56de\u5230\u8282\u70b9 0 \u3002

    \n\n

    \u65e0\u5411\u6811\u7684\u8fb9\u7531 edges \u7ed9\u51fa\uff0c\u5176\u4e2d edges[i] = [fromi, toi] \uff0c\u8868\u793a\u6709\u4e00\u6761\u8fb9\u8fde\u63a5 from \u548c toi \u3002\u9664\u6b64\u4ee5\u5916\uff0c\u8fd8\u6709\u4e00\u4e2a\u5e03\u5c14\u6570\u7ec4 hasApple \uff0c\u5176\u4e2d hasApple[i] = true \u4ee3\u8868\u8282\u70b9 i \u6709\u4e00\u4e2a\u82f9\u679c\uff0c\u5426\u5219\uff0c\u8282\u70b9 i \u6ca1\u6709\u82f9\u679c\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 7, edges = [[0,1],[0,2],[1,4],[1,5],[2,3],[2,6]], hasApple = [false,false,true,false,true,true,false]\n\u8f93\u51fa\uff1a8 \n\u89e3\u91ca\uff1a\u4e0a\u56fe\u5c55\u793a\u4e86\u7ed9\u5b9a\u7684\u6811\uff0c\u5176\u4e2d\u7ea2\u8272\u8282\u70b9\u8868\u793a\u6709\u82f9\u679c\u3002\u4e00\u4e2a\u80fd\u6536\u96c6\u5230\u6240\u6709\u82f9\u679c\u7684\u6700\u4f18\u65b9\u6848\u7531\u7eff\u8272\u7bad\u5934\u8868\u793a\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 7, edges = [[0,1],[0,2],[1,4],[1,5],[2,3],[2,6]], hasApple = [false,false,true,false,false,true,false]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u4e0a\u56fe\u5c55\u793a\u4e86\u7ed9\u5b9a\u7684\u6811\uff0c\u5176\u4e2d\u7ea2\u8272\u8282\u70b9\u8868\u793a\u6709\u82f9\u679c\u3002\u4e00\u4e2a\u80fd\u6536\u96c6\u5230\u6240\u6709\u82f9\u679c\u7684\u6700\u4f18\u65b9\u6848\u7531\u7eff\u8272\u7bad\u5934\u8868\u793a\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1an = 7, edges = [[0,1],[0,2],[1,4],[1,5],[2,3],[2,6]], hasApple = [false,false,false,false,false,false,false]\n\u8f93\u51fa\uff1a0\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 10^5
    • \n\t
    • edges.length == n-1
    • \n\t
    • edges[i].length == 2
    • \n\t
    • 0 <= fromi, toi <= n-1
    • \n\t
    • fromi < toi
    • \n\t
    • hasApple.length == n
    • \n
    \n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minTime(int n, vector>& edges, vector& hasApple) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minTime(int n, int[][] edges, List hasApple) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minTime(self, n, edges, hasApple):\n \"\"\"\n :type n: int\n :type edges: List[List[int]]\n :type hasApple: List[bool]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minTime(self, n: int, edges: List[List[int]], hasApple: List[bool]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minTime(int n, int** edges, int edgesSize, int* edgesColSize, bool* hasApple, int hasAppleSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinTime(int n, int[][] edges, IList hasApple) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} edges\n * @param {boolean[]} hasApple\n * @return {number}\n */\nvar minTime = function(n, edges, hasApple) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} edges\n# @param {Boolean[]} has_apple\n# @return {Integer}\ndef min_time(n, edges, has_apple)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minTime(_ n: Int, _ edges: [[Int]], _ hasApple: [Bool]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minTime(n int, edges [][]int, hasApple []bool) int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minTime(n: Int, edges: Array[Array[Int]], hasApple: List[Boolean]): Int = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minTime(n: Int, edges: Array, hasApple: List): Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_time(n: i32, edges: Vec>, has_apple: Vec) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $edges\n * @param Boolean[] $hasApple\n * @return Integer\n */\n function minTime($n, $edges, $hasApple) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minTime(n: number, edges: number[][], hasApple: boolean[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-time n edges hasApple)\n (-> exact-integer? (listof (listof exact-integer?)) (listof boolean?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1443](https://leetcode-cn.com/problems/minimum-time-to-collect-all-apples-in-a-tree)", "[\u6536\u96c6\u6811\u4e0a\u6240\u6709\u82f9\u679c\u7684\u6700\u5c11\u65f6\u95f4](/solution/1400-1499/1443.Minimum%20Time%20to%20Collect%20All%20Apples%20in%20a%20Tree/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1443](https://leetcode.com/problems/minimum-time-to-collect-all-apples-in-a-tree)", "[Minimum Time to Collect All Apples in a Tree](/solution/1400-1499/1443.Minimum%20Time%20to%20Collect%20All%20Apples%20in%20a%20Tree/README_EN.md)", "`Tree`,`Depth-first Search`", "Medium", ""]}, {"question_id": "1553", "frontend_question_id": "1442", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-triplets-that-can-form-two-arrays-of-equal-xor", "url_en": "https://leetcode.com/problems/count-triplets-that-can-form-two-arrays-of-equal-xor", "relative_path_cn": "/solution/1400-1499/1442.Count%20Triplets%20That%20Can%20Form%20Two%20Arrays%20of%20Equal%20XOR/README.md", "relative_path_en": "/solution/1400-1499/1442.Count%20Triplets%20That%20Can%20Form%20Two%20Arrays%20of%20Equal%20XOR/README_EN.md", "title_cn": "\u5f62\u6210\u4e24\u4e2a\u5f02\u6216\u76f8\u7b49\u6570\u7ec4\u7684\u4e09\u5143\u7ec4\u6570\u76ee", "title_en": "Count Triplets That Can Form Two Arrays of Equal XOR", "question_title_slug": "count-triplets-that-can-form-two-arrays-of-equal-xor", "content_en": "

    Given an array of integers arr.

    \r\n\r\n

    We want to select three indices i, j and k where (0 <= i < j <= k < arr.length).

    \r\n\r\n

    Let's define a and b as follows:

    \r\n\r\n
      \r\n\t
    • a = arr[i] ^ arr[i + 1] ^ ... ^ arr[j - 1]
    • \r\n\t
    • b = arr[j] ^ arr[j + 1] ^ ... ^ arr[k]
    • \r\n
    \r\n\r\n

    Note that ^ denotes the bitwise-xor operation.

    \r\n\r\n

    Return the number of triplets (i, j and k) Where a == b.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: arr = [2,3,1,6,7]\r\nOutput: 4\r\nExplanation: The triplets are (0,1,2), (0,2,2), (2,3,4) and (2,4,4)\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: arr = [1,1,1,1,1]\r\nOutput: 10\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: arr = [2,3]\r\nOutput: 0\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: arr = [1,3,5,7,9]\r\nOutput: 3\r\n
    \r\n\r\n

    Example 5:

    \r\n\r\n
    \r\nInput: arr = [7,11,12,9,5,2,7,17,22]\r\nOutput: 8\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= arr.length <= 300
    • \r\n\t
    • 1 <= arr[i] <= 10^8
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr \u3002

    \n\n

    \u73b0\u9700\u8981\u4ece\u6570\u7ec4\u4e2d\u53d6\u4e09\u4e2a\u4e0b\u6807 i\u3001j \u548c k \uff0c\u5176\u4e2d (0 <= i < j <= k < arr.length) \u3002

    \n\n

    a \u548c b \u5b9a\u4e49\u5982\u4e0b\uff1a

    \n\n
      \n\t
    • a = arr[i] ^ arr[i + 1] ^ ... ^ arr[j - 1]
    • \n\t
    • b = arr[j] ^ arr[j + 1] ^ ... ^ arr[k]
    • \n
    \n\n

    \u6ce8\u610f\uff1a^ \u8868\u793a \u6309\u4f4d\u5f02\u6216 \u64cd\u4f5c\u3002

    \n\n

    \u8bf7\u8fd4\u56de\u80fd\u591f\u4ee4 a == b \u6210\u7acb\u7684\u4e09\u5143\u7ec4 (i, j , k) \u7684\u6570\u76ee\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [2,3,1,6,7]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u6ee1\u8db3\u9898\u610f\u7684\u4e09\u5143\u7ec4\u5206\u522b\u662f (0,1,2), (0,2,2), (2,3,4) \u4ee5\u53ca (2,4,4)\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [1,1,1,1,1]\n\u8f93\u51fa\uff1a10\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [2,3]\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [1,3,5,7,9]\n\u8f93\u51fa\uff1a3\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [7,11,12,9,5,2,7,17,22]\n\u8f93\u51fa\uff1a8\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= arr.length <= 300
    • \n\t
    • 1 <= arr[i] <= 10^8
    • \n
    \n", "tags_en": ["Bit Manipulation", "Array", "Math"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u6570\u7ec4", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countTriplets(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countTriplets(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countTriplets(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countTriplets(self, arr: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countTriplets(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountTriplets(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar countTriplets = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef count_triplets(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countTriplets(_ arr: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countTriplets(arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countTriplets(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countTriplets(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_triplets(arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function countTriplets($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countTriplets(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-triplets arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1442](https://leetcode-cn.com/problems/count-triplets-that-can-form-two-arrays-of-equal-xor)", "[\u5f62\u6210\u4e24\u4e2a\u5f02\u6216\u76f8\u7b49\u6570\u7ec4\u7684\u4e09\u5143\u7ec4\u6570\u76ee](/solution/1400-1499/1442.Count%20Triplets%20That%20Can%20Form%20Two%20Arrays%20of%20Equal%20XOR/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u6570\u7ec4`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1442](https://leetcode.com/problems/count-triplets-that-can-form-two-arrays-of-equal-xor)", "[Count Triplets That Can Form Two Arrays of Equal XOR](/solution/1400-1499/1442.Count%20Triplets%20That%20Can%20Form%20Two%20Arrays%20of%20Equal%20XOR/README_EN.md)", "`Bit Manipulation`,`Array`,`Math`", "Medium", ""]}, {"question_id": "1552", "frontend_question_id": "1441", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/build-an-array-with-stack-operations", "url_en": "https://leetcode.com/problems/build-an-array-with-stack-operations", "relative_path_cn": "/solution/1400-1499/1441.Build%20an%20Array%20With%20Stack%20Operations/README.md", "relative_path_en": "/solution/1400-1499/1441.Build%20an%20Array%20With%20Stack%20Operations/README_EN.md", "title_cn": "\u7528\u6808\u64cd\u4f5c\u6784\u5efa\u6570\u7ec4", "title_en": "Build an Array With Stack Operations", "question_title_slug": "build-an-array-with-stack-operations", "content_en": "

    Given an array target and an integer n. In each iteration, you will read a number from  list = {1,2,3..., n}.

    \n\n

    Build the target array using the following operations:

    \n\n
      \n\t
    • Push: Read a new element from the beginning list, and push it in the array.
    • \n\t
    • Pop: delete the last element of the array.
    • \n\t
    • If the target array is already built, stop reading more elements.
    • \n
    \n\n

    Return the operations to build the target array. You are guaranteed that the answer is unique.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: target = [1,3], n = 3\nOutput: ["Push","Push","Pop","Push"]\nExplanation: \nRead number 1 and automatically push in the array -> [1]\nRead number 2 and automatically push in the array then Pop it -> [1]\nRead number 3 and automatically push in the array -> [1,3]\n
    \n\n

    Example 2:

    \n\n
    \nInput: target = [1,2,3], n = 3\nOutput: ["Push","Push","Push"]\n
    \n\n

    Example 3:

    \n\n
    \nInput: target = [1,2], n = 4\nOutput: ["Push","Push"]\nExplanation: You only need to read the first 2 numbers and stop.\n
    \n\n

    Example 4:

    \n\n
    \nInput: target = [2,3,4], n = 4\nOutput: ["Push","Pop","Push","Push","Push"]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= target.length <= 100
    • \n\t
    • 1 <= target[i] <= n
    • \n\t
    • 1 <= n <= 100
    • \n\t
    • target is strictly increasing.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u76ee\u6807\u6570\u7ec4 target \u548c\u4e00\u4e2a\u6574\u6570 n\u3002\u6bcf\u6b21\u8fed\u4ee3\uff0c\u9700\u8981\u4ece\u00a0 list = {1,2,3..., n} \u4e2d\u4f9d\u5e8f\u8bfb\u53d6\u4e00\u4e2a\u6570\u5b57\u3002

    \n\n

    \u8bf7\u4f7f\u7528\u4e0b\u8ff0\u64cd\u4f5c\u6765\u6784\u5efa\u76ee\u6807\u6570\u7ec4 target \uff1a

    \n\n
      \n\t
    • Push\uff1a\u4ece list \u4e2d\u8bfb\u53d6\u4e00\u4e2a\u65b0\u5143\u7d20\uff0c \u5e76\u5c06\u5176\u63a8\u5165\u6570\u7ec4\u4e2d\u3002
    • \n\t
    • Pop\uff1a\u5220\u9664\u6570\u7ec4\u4e2d\u7684\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u3002
    • \n\t
    • \u5982\u679c\u76ee\u6807\u6570\u7ec4\u6784\u5efa\u5b8c\u6210\uff0c\u5c31\u505c\u6b62\u8bfb\u53d6\u66f4\u591a\u5143\u7d20\u3002
    • \n
    \n\n

    \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u76ee\u6807\u6570\u7ec4\u4e25\u683c\u9012\u589e\uff0c\u5e76\u4e14\u53ea\u5305\u542b 1 \u5230 n \u4e4b\u95f4\u7684\u6570\u5b57\u3002

    \n\n

    \u8bf7\u8fd4\u56de\u6784\u5efa\u76ee\u6807\u6570\u7ec4\u6240\u7528\u7684\u64cd\u4f5c\u5e8f\u5217\u3002

    \n\n

    \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u7b54\u6848\u662f\u552f\u4e00\u7684\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1atarget = [1,3], n = 3\n\u8f93\u51fa\uff1a[\"Push\",\"Push\",\"Pop\",\"Push\"]\n\u89e3\u91ca\uff1a \n\u8bfb\u53d6 1 \u5e76\u81ea\u52a8\u63a8\u5165\u6570\u7ec4 -> [1]\n\u8bfb\u53d6 2 \u5e76\u81ea\u52a8\u63a8\u5165\u6570\u7ec4\uff0c\u7136\u540e\u5220\u9664\u5b83 -> [1]\n\u8bfb\u53d6 3 \u5e76\u81ea\u52a8\u63a8\u5165\u6570\u7ec4 -> [1,3]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1atarget = [1,2,3], n = 3\n\u8f93\u51fa\uff1a[\"Push\",\"Push\",\"Push\"]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1atarget = [1,2], n = 4\n\u8f93\u51fa\uff1a[\"Push\",\"Push\"]\n\u89e3\u91ca\uff1a\u53ea\u9700\u8981\u8bfb\u53d6\u524d 2 \u4e2a\u6570\u5b57\u5c31\u53ef\u4ee5\u505c\u6b62\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1atarget = [2,3,4], n = 4\n\u8f93\u51fa\uff1a[\"Push\",\"Pop\",\"Push\",\"Push\",\"Push\"]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= target.length <= 100
    • \n\t
    • 1 <= target[i]\u00a0<= 100
    • \n\t
    • 1 <= n <= 100
    • \n\t
    • target \u662f\u4e25\u683c\u9012\u589e\u7684
    • \n
    \n", "tags_en": ["Stack"], "tags_cn": ["\u6808"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector buildArray(vector& target, int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List buildArray(int[] target, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def buildArray(self, target, n):\n \"\"\"\n :type target: List[int]\n :type n: int\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def buildArray(self, target: List[int], n: int) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** buildArray(int* target, int targetSize, int n, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList BuildArray(int[] target, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} target\n * @param {number} n\n * @return {string[]}\n */\nvar buildArray = function(target, n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} target\n# @param {Integer} n\n# @return {String[]}\ndef build_array(target, n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func buildArray(_ target: [Int], _ n: Int) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func buildArray(target []int, n int) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def buildArray(target: Array[Int], n: Int): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun buildArray(target: IntArray, n: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn build_array(target: Vec, n: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $target\n * @param Integer $n\n * @return String[]\n */\n function buildArray($target, $n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function buildArray(target: number[], n: number): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (build-array target n)\n (-> (listof exact-integer?) exact-integer? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1441](https://leetcode-cn.com/problems/build-an-array-with-stack-operations)", "[\u7528\u6808\u64cd\u4f5c\u6784\u5efa\u6570\u7ec4](/solution/1400-1499/1441.Build%20an%20Array%20With%20Stack%20Operations/README.md)", "`\u6808`", "\u7b80\u5355", ""], "md_table_row_en": ["[1441](https://leetcode.com/problems/build-an-array-with-stack-operations)", "[Build an Array With Stack Operations](/solution/1400-1499/1441.Build%20an%20Array%20With%20Stack%20Operations/README_EN.md)", "`Stack`", "Easy", ""]}, {"question_id": "1551", "frontend_question_id": "1421", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/npv-queries", "url_en": "https://leetcode.com/problems/npv-queries", "relative_path_cn": "/solution/1400-1499/1421.NPV%20Queries/README.md", "relative_path_en": "/solution/1400-1499/1421.NPV%20Queries/README_EN.md", "title_cn": "\u51c0\u73b0\u503c\u67e5\u8be2", "title_en": "NPV Queries", "question_title_slug": "npv-queries", "content_en": "

    Table: NPV

    \r\n\r\n
    \r\n+---------------+---------+\r\n| Column Name   | Type    |\r\n+---------------+---------+\r\n| id            | int     |\r\n| year          | int     |\r\n| npv           | int     |\r\n+---------------+---------+\r\n(id, year) is the primary key of this table.\r\nThe table has information about the id and the year of each inventory and the corresponding net present value.\r\n
    \r\n\r\n

     

    \r\n\r\n

    Table: Queries

    \r\n\r\n
    \r\n+---------------+---------+\r\n| Column Name   | Type    |\r\n+---------------+---------+\r\n| id            | int     |\r\n| year          | int     |\r\n+---------------+---------+\r\n(id, year) is the primary key of this table.\r\nThe table has information about the id and the year of each inventory query.\r\n
    \r\n\r\n

     

    \r\n\r\n

    Write an SQL query to find the npv of all each query of queries table.

    \r\n\r\n

    Return the result table in any order.

    \r\n\r\n

    The query result format is in the following example:

    \r\n\r\n
    \r\nNPV table:\r\n+------+--------+--------+\r\n| id   | year   | npv    |\r\n+------+--------+--------+\r\n| 1    | 2018   | 100    |\r\n| 7    | 2020   | 30     |\r\n| 13   | 2019   | 40     |\r\n| 1    | 2019   | 113    |\r\n| 2    | 2008   | 121    |\r\n| 3    | 2009   | 12     |\r\n| 11   | 2020   | 99     |\r\n| 7    | 2019   | 0      |\r\n+------+--------+--------+\r\n\r\nQueries table:\r\n+------+--------+\r\n| id   | year   |\r\n+------+--------+\r\n| 1    | 2019   |\r\n| 2    | 2008   |\r\n| 3    | 2009   |\r\n| 7    | 2018   |\r\n| 7    | 2019   |\r\n| 7    | 2020   |\r\n| 13   | 2019   |\r\n+------+--------+\r\n\r\nResult table:\r\n+------+--------+--------+\r\n| id   | year   | npv    |\r\n+------+--------+--------+\r\n| 1    | 2019   | 113    |\r\n| 2    | 2008   | 121    |\r\n| 3    | 2009   | 12     |\r\n| 7    | 2018   | 0      |\r\n| 7    | 2019   | 0      |\r\n| 7    | 2020   | 30     |\r\n| 13   | 2019   | 40     |\r\n+------+--------+--------+\r\n\r\nThe npv value of (7, 2018) is not present in the NPV table, we consider it 0.\r\nThe npv values of all other queries can be found in the NPV table.\r\n
    ", "content_cn": "

    \u8868: NPV

    \n\n
    +---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| year          | int     |\n| npv           | int     |\n+---------------+---------+\n(id, year) \u662f\u8be5\u8868\u4e3b\u952e.\n\u8be5\u8868\u6709\u6bcf\u4e00\u7b14\u5b58\u8d27\u7684\u5e74\u4efd, id \u548c\u5bf9\u5e94\u51c0\u73b0\u503c\u7684\u4fe1\u606f.\n
    \n\n

     

    \n\n

    \u8868: Queries

    \n\n
    +---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| year          | int     |\n+---------------+---------+\n(id, year) \u662f\u8be5\u8868\u4e3b\u952e.\n\u8be5\u8868\u6709\u6bcf\u4e00\u6b21\u67e5\u8be2\u6240\u5bf9\u5e94\u5b58\u8d27\u7684 id \u548c\u5e74\u4efd\u7684\u4fe1\u606f.\n
    \n\n

     

    \n\n

    \u5199\u4e00\u4e2a SQL, \u627e\u5230 Queries \u8868\u4e2d\u6bcf\u4e00\u6b21\u67e5\u8be2\u7684\u51c0\u73b0\u503c.

    \n\n

    \u7ed3\u679c\u8868\u6ca1\u6709\u987a\u5e8f\u8981\u6c42.

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u7684\u683c\u5f0f\u5982\u4e0b\u6240\u793a:

    \n\n
    NPV \u8868:\n+------+--------+--------+\n| id   | year   | npv    |\n+------+--------+--------+\n| 1    | 2018   | 100    |\n| 7    | 2020   | 30     |\n| 13   | 2019   | 40     |\n| 1    | 2019   | 113    |\n| 2    | 2008   | 121    |\n| 3    | 2009   | 12     |\n| 11   | 2020   | 99     |\n| 7    | 2019   | 0      |\n+------+--------+--------+\n\nQueries \u8868:\n+------+--------+\n| id   | year   |\n+------+--------+\n| 1    | 2019   |\n| 2    | 2008   |\n| 3    | 2009   |\n| 7    | 2018   |\n| 7    | 2019   |\n| 7    | 2020   |\n| 13   | 2019   |\n+------+--------+\n\n\u7ed3\u679c\u8868:\n+------+--------+--------+\n| id   | year   | npv    |\n+------+--------+--------+\n| 1    | 2019   | 113    |\n| 2    | 2008   | 121    |\n| 3    | 2009   | 12     |\n| 7    | 2018   | 0      |\n| 7    | 2019   | 0      |\n| 7    | 2020   | 30     |\n| 13   | 2019   | 40     |\n+------+--------+--------+\n\n(7, 2018)\u7684\u51c0\u73b0\u503c\u4e0d\u5728 NPV \u8868\u4e2d, \u6211\u4eec\u628a\u5b83\u770b\u4f5c\u662f 0.\n\u6240\u6709\u5176\u5b83\u67e5\u8be2\u7684\u51c0\u73b0\u503c\u90fd\u80fd\u5728 NPV \u8868\u4e2d\u627e\u5230.\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1421](https://leetcode-cn.com/problems/npv-queries)", "[\u51c0\u73b0\u503c\u67e5\u8be2](/solution/1400-1499/1421.NPV%20Queries/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1421](https://leetcode.com/problems/npv-queries)", "[NPV Queries](/solution/1400-1499/1421.NPV%20Queries/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1550", "frontend_question_id": "1439", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-the-kth-smallest-sum-of-a-matrix-with-sorted-rows", "url_en": "https://leetcode.com/problems/find-the-kth-smallest-sum-of-a-matrix-with-sorted-rows", "relative_path_cn": "/solution/1400-1499/1439.Find%20the%20Kth%20Smallest%20Sum%20of%20a%20Matrix%20With%20Sorted%20Rows/README.md", "relative_path_en": "/solution/1400-1499/1439.Find%20the%20Kth%20Smallest%20Sum%20of%20a%20Matrix%20With%20Sorted%20Rows/README_EN.md", "title_cn": "\u6709\u5e8f\u77e9\u9635\u4e2d\u7684\u7b2c k \u4e2a\u6700\u5c0f\u6570\u7ec4\u548c", "title_en": "Find the Kth Smallest Sum of a Matrix With Sorted Rows", "question_title_slug": "find-the-kth-smallest-sum-of-a-matrix-with-sorted-rows", "content_en": "

    You are given an m * n matrix, mat, and an integer k, which has its rows sorted in non-decreasing order.

    \n\n

    You are allowed to choose exactly 1 element from each row to form an array. Return the Kth smallest array sum among all possible arrays.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: mat = [[1,3,11],[2,4,6]], k = 5\nOutput: 7\nExplanation: Choosing one element from each row, the first k smallest sum are:\n[1,2], [1,4], [3,2], [3,4], [1,6]. Where the 5th sum is 7.  
    \n\n

    Example 2:

    \n\n
    \nInput: mat = [[1,3,11],[2,4,6]], k = 9\nOutput: 17\n
    \n\n

    Example 3:

    \n\n
    \nInput: mat = [[1,10,10],[1,4,5],[2,3,6]], k = 7\nOutput: 9\nExplanation: Choosing one element from each row, the first k smallest sum are:\n[1,1,2], [1,1,3], [1,4,2], [1,4,3], [1,1,6], [1,5,2], [1,5,3]. Where the 7th sum is 9.  \n
    \n\n

    Example 4:

    \n\n
    \nInput: mat = [[1,1,10],[2,2,9]], k = 7\nOutput: 12\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == mat.length
    • \n\t
    • n == mat.length[i]
    • \n\t
    • 1 <= m, n <= 40
    • \n\t
    • 1 <= k <= min(200, n ^ m)
    • \n\t
    • 1 <= mat[i][j] <= 5000
    • \n\t
    • mat[i] is a non decreasing array.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a m * n \u7684\u77e9\u9635 mat\uff0c\u4ee5\u53ca\u4e00\u4e2a\u6574\u6570 k \uff0c\u77e9\u9635\u4e2d\u7684\u6bcf\u4e00\u884c\u90fd\u4ee5\u975e\u9012\u51cf\u7684\u987a\u5e8f\u6392\u5217\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u4ece\u6bcf\u4e00\u884c\u4e2d\u9009\u51fa 1 \u4e2a\u5143\u7d20\u5f62\u6210\u4e00\u4e2a\u6570\u7ec4\u3002\u8fd4\u56de\u6240\u6709\u53ef\u80fd\u6570\u7ec4\u4e2d\u7684\u7b2c k \u4e2a \u6700\u5c0f \u6570\u7ec4\u548c\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1amat = [[1,3,11],[2,4,6]], k = 5\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\u4ece\u6bcf\u4e00\u884c\u4e2d\u9009\u51fa\u4e00\u4e2a\u5143\u7d20\uff0c\u524d k \u4e2a\u548c\u6700\u5c0f\u7684\u6570\u7ec4\u5206\u522b\u662f\uff1a\n[1,2], [1,4], [3,2], [3,4], [1,6]\u3002\u5176\u4e2d\u7b2c 5 \u4e2a\u7684\u548c\u662f 7 \u3002  
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1amat = [[1,3,11],[2,4,6]], k = 9\n\u8f93\u51fa\uff1a17\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1amat = [[1,10,10],[1,4,5],[2,3,6]], k = 7\n\u8f93\u51fa\uff1a9\n\u89e3\u91ca\uff1a\u4ece\u6bcf\u4e00\u884c\u4e2d\u9009\u51fa\u4e00\u4e2a\u5143\u7d20\uff0c\u524d k \u4e2a\u548c\u6700\u5c0f\u7684\u6570\u7ec4\u5206\u522b\u662f\uff1a\n[1,1,2], [1,1,3], [1,4,2], [1,4,3], [1,1,6], [1,5,2], [1,5,3]\u3002\u5176\u4e2d\u7b2c 7 \u4e2a\u7684\u548c\u662f 9 \u3002 \n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1amat = [[1,1,10],[2,2,9]], k = 7\n\u8f93\u51fa\uff1a12\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == mat.length
    • \n\t
    • n == mat.length[i]
    • \n\t
    • 1 <= m, n <= 40
    • \n\t
    • 1 <= k <= min(200, n ^ m)
    • \n\t
    • 1 <= mat[i][j] <= 5000
    • \n\t
    • mat[i] \u662f\u4e00\u4e2a\u975e\u9012\u51cf\u6570\u7ec4
    • \n
    \n", "tags_en": ["Heap"], "tags_cn": ["\u5806"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int kthSmallest(vector>& mat, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int kthSmallest(int[][] mat, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def kthSmallest(self, mat, k):\n \"\"\"\n :type mat: List[List[int]]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def kthSmallest(self, mat: List[List[int]], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint kthSmallest(int** mat, int matSize, int* matColSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int KthSmallest(int[][] mat, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} mat\n * @param {number} k\n * @return {number}\n */\nvar kthSmallest = function(mat, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} mat\n# @param {Integer} k\n# @return {Integer}\ndef kth_smallest(mat, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func kthSmallest(_ mat: [[Int]], _ k: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func kthSmallest(mat [][]int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def kthSmallest(mat: Array[Array[Int]], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun kthSmallest(mat: Array, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn kth_smallest(mat: Vec>, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $mat\n * @param Integer $k\n * @return Integer\n */\n function kthSmallest($mat, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function kthSmallest(mat: number[][], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (kth-smallest mat k)\n (-> (listof (listof exact-integer?)) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1439](https://leetcode-cn.com/problems/find-the-kth-smallest-sum-of-a-matrix-with-sorted-rows)", "[\u6709\u5e8f\u77e9\u9635\u4e2d\u7684\u7b2c k \u4e2a\u6700\u5c0f\u6570\u7ec4\u548c](/solution/1400-1499/1439.Find%20the%20Kth%20Smallest%20Sum%20of%20a%20Matrix%20With%20Sorted%20Rows/README.md)", "`\u5806`", "\u56f0\u96be", ""], "md_table_row_en": ["[1439](https://leetcode.com/problems/find-the-kth-smallest-sum-of-a-matrix-with-sorted-rows)", "[Find the Kth Smallest Sum of a Matrix With Sorted Rows](/solution/1400-1499/1439.Find%20the%20Kth%20Smallest%20Sum%20of%20a%20Matrix%20With%20Sorted%20Rows/README_EN.md)", "`Heap`", "Hard", ""]}, {"question_id": "1549", "frontend_question_id": "1438", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit", "url_en": "https://leetcode.com/problems/longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit", "relative_path_cn": "/solution/1400-1499/1438.Longest%20Continuous%20Subarray%20With%20Absolute%20Diff%20Less%20Than%20or%20Equal%20to%20Limit/README.md", "relative_path_en": "/solution/1400-1499/1438.Longest%20Continuous%20Subarray%20With%20Absolute%20Diff%20Less%20Than%20or%20Equal%20to%20Limit/README_EN.md", "title_cn": "\u7edd\u5bf9\u5dee\u4e0d\u8d85\u8fc7\u9650\u5236\u7684\u6700\u957f\u8fde\u7eed\u5b50\u6570\u7ec4", "title_en": "Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit", "question_title_slug": "longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit", "content_en": "

    Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [8,2,4,7], limit = 4\nOutput: 2 \nExplanation: All subarrays are: \n[8] with maximum absolute diff |8-8| = 0 <= 4.\n[8,2] with maximum absolute diff |8-2| = 6 > 4. \n[8,2,4] with maximum absolute diff |8-2| = 6 > 4.\n[8,2,4,7] with maximum absolute diff |8-2| = 6 > 4.\n[2] with maximum absolute diff |2-2| = 0 <= 4.\n[2,4] with maximum absolute diff |2-4| = 2 <= 4.\n[2,4,7] with maximum absolute diff |2-7| = 5 > 4.\n[4] with maximum absolute diff |4-4| = 0 <= 4.\n[4,7] with maximum absolute diff |4-7| = 3 <= 4.\n[7] with maximum absolute diff |7-7| = 0 <= 4. \nTherefore, the size of the longest subarray is 2.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [10,1,2,4,7,2], limit = 5\nOutput: 4 \nExplanation: The subarray [2,4,7,2] is the longest since the maximum absolute diff is |2-7| = 5 <= 5.\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [4,2,2,2,4,4,2,2], limit = 0\nOutput: 3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • 1 <= nums[i] <= 109
    • \n\t
    • 0 <= limit <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \uff0c\u548c\u4e00\u4e2a\u8868\u793a\u9650\u5236\u7684\u6574\u6570 limit\uff0c\u8bf7\u4f60\u8fd4\u56de\u6700\u957f\u8fde\u7eed\u5b50\u6570\u7ec4\u7684\u957f\u5ea6\uff0c\u8be5\u5b50\u6570\u7ec4\u4e2d\u7684\u4efb\u610f\u4e24\u4e2a\u5143\u7d20\u4e4b\u95f4\u7684\u7edd\u5bf9\u5dee\u5fc5\u987b\u5c0f\u4e8e\u6216\u8005\u7b49\u4e8e limit \u3002

    \n\n

    \u5982\u679c\u4e0d\u5b58\u5728\u6ee1\u8db3\u6761\u4ef6\u7684\u5b50\u6570\u7ec4\uff0c\u5219\u8fd4\u56de 0 \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [8,2,4,7], limit = 4\n\u8f93\u51fa\uff1a2 \n\u89e3\u91ca\uff1a\u6240\u6709\u5b50\u6570\u7ec4\u5982\u4e0b\uff1a\n[8] \u6700\u5927\u7edd\u5bf9\u5dee |8-8| = 0 <= 4.\n[8,2] \u6700\u5927\u7edd\u5bf9\u5dee |8-2| = 6 > 4. \n[8,2,4] \u6700\u5927\u7edd\u5bf9\u5dee |8-2| = 6 > 4.\n[8,2,4,7] \u6700\u5927\u7edd\u5bf9\u5dee |8-2| = 6 > 4.\n[2] \u6700\u5927\u7edd\u5bf9\u5dee |2-2| = 0 <= 4.\n[2,4] \u6700\u5927\u7edd\u5bf9\u5dee |2-4| = 2 <= 4.\n[2,4,7] \u6700\u5927\u7edd\u5bf9\u5dee |2-7| = 5 > 4.\n[4] \u6700\u5927\u7edd\u5bf9\u5dee |4-4| = 0 <= 4.\n[4,7] \u6700\u5927\u7edd\u5bf9\u5dee |4-7| = 3 <= 4.\n[7] \u6700\u5927\u7edd\u5bf9\u5dee |7-7| = 0 <= 4. \n\u56e0\u6b64\uff0c\u6ee1\u8db3\u9898\u610f\u7684\u6700\u957f\u5b50\u6570\u7ec4\u7684\u957f\u5ea6\u4e3a 2 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [10,1,2,4,7,2], limit = 5\n\u8f93\u51fa\uff1a4 \n\u89e3\u91ca\uff1a\u6ee1\u8db3\u9898\u610f\u7684\u6700\u957f\u5b50\u6570\u7ec4\u662f [2,4,7,2]\uff0c\u5176\u6700\u5927\u7edd\u5bf9\u5dee |2-7| = 5 <= 5 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [4,2,2,2,4,4,2,2], limit = 0\n\u8f93\u51fa\uff1a3\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 10^5
    • \n\t
    • 1 <= nums[i] <= 10^9
    • \n\t
    • 0 <= limit <= 10^9
    • \n
    \n", "tags_en": ["Array", "Sliding Window"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int longestSubarray(vector& nums, int limit) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int longestSubarray(int[] nums, int limit) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestSubarray(self, nums, limit):\n \"\"\"\n :type nums: List[int]\n :type limit: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestSubarray(self, nums: List[int], limit: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint longestSubarray(int* nums, int numsSize, int limit){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LongestSubarray(int[] nums, int limit) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} limit\n * @return {number}\n */\nvar longestSubarray = function(nums, limit) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} limit\n# @return {Integer}\ndef longest_subarray(nums, limit)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestSubarray(_ nums: [Int], _ limit: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestSubarray(nums []int, limit int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestSubarray(nums: Array[Int], limit: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestSubarray(nums: IntArray, limit: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_subarray(nums: Vec, limit: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $limit\n * @return Integer\n */\n function longestSubarray($nums, $limit) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestSubarray(nums: number[], limit: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-subarray nums limit)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1438](https://leetcode-cn.com/problems/longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit)", "[\u7edd\u5bf9\u5dee\u4e0d\u8d85\u8fc7\u9650\u5236\u7684\u6700\u957f\u8fde\u7eed\u5b50\u6570\u7ec4](/solution/1400-1499/1438.Longest%20Continuous%20Subarray%20With%20Absolute%20Diff%20Less%20Than%20or%20Equal%20to%20Limit/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1438](https://leetcode.com/problems/longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit)", "[Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit](/solution/1400-1499/1438.Longest%20Continuous%20Subarray%20With%20Absolute%20Diff%20Less%20Than%20or%20Equal%20to%20Limit/README_EN.md)", "`Array`,`Sliding Window`", "Medium", ""]}, {"question_id": "1548", "frontend_question_id": "1437", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/check-if-all-1s-are-at-least-length-k-places-away", "url_en": "https://leetcode.com/problems/check-if-all-1s-are-at-least-length-k-places-away", "relative_path_cn": "/solution/1400-1499/1437.Check%20If%20All%201%27s%20Are%20at%20Least%20Length%20K%20Places%20Away/README.md", "relative_path_en": "/solution/1400-1499/1437.Check%20If%20All%201%27s%20Are%20at%20Least%20Length%20K%20Places%20Away/README_EN.md", "title_cn": "\u662f\u5426\u6240\u6709 1 \u90fd\u81f3\u5c11\u76f8\u9694 k \u4e2a\u5143\u7d20", "title_en": "Check If All 1's Are at Least Length K Places Away", "question_title_slug": "check-if-all-1s-are-at-least-length-k-places-away", "content_en": "

    Given an array nums of 0s and 1s and an integer k, return True if all 1's are at least k places away from each other, otherwise return False.

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: nums = [1,0,0,0,1,0,0,1], k = 2\nOutput: true\nExplanation: Each of the 1s are at least 2 places away from each other.\n
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: nums = [1,0,0,1,0,1], k = 2\nOutput: false\nExplanation: The second 1 and third 1 are only one apart from each other.
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [1,1,1,1,1], k = 0\nOutput: true\n
    \n\n

    Example 4:

    \n\n
    \nInput: nums = [0,1,0,1], k = 1\nOutput: true\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • 0 <= k <= nums.length
    • \n\t
    • nums[i] is 0 or 1
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u7531\u82e5\u5e72 0 \u548c 1 \u7ec4\u6210\u7684\u6570\u7ec4 nums \u4ee5\u53ca\u6574\u6570 k\u3002\u5982\u679c\u6240\u6709 1 \u90fd\u81f3\u5c11\u76f8\u9694 k \u4e2a\u5143\u7d20\uff0c\u5219\u8fd4\u56de True \uff1b\u5426\u5219\uff0c\u8fd4\u56de False \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1anums = [1,0,0,0,1,0,0,1], k = 2\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u6bcf\u4e2a 1 \u90fd\u81f3\u5c11\u76f8\u9694 2 \u4e2a\u5143\u7d20\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1anums = [1,0,0,1,0,1], k = 2\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u7b2c\u4e8c\u4e2a 1 \u548c\u7b2c\u4e09\u4e2a 1 \u4e4b\u95f4\u53ea\u9694\u4e86 1 \u4e2a\u5143\u7d20\u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,1,1,1,1], k = 0\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [0,1,0,1], k = 1\n\u8f93\u51fa\uff1atrue\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 10^5
    • \n\t
    • 0 <= k <= nums.length
    • \n\t
    • nums[i] \u7684\u503c\u4e3a 0 \u6216 1
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool kLengthApart(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean kLengthApart(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def kLengthApart(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def kLengthApart(self, nums: List[int], k: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool kLengthApart(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool KLengthApart(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {boolean}\n */\nvar kLengthApart = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Boolean}\ndef k_length_apart(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func kLengthApart(_ nums: [Int], _ k: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func kLengthApart(nums []int, k int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def kLengthApart(nums: Array[Int], k: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun kLengthApart(nums: IntArray, k: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn k_length_apart(nums: Vec, k: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Boolean\n */\n function kLengthApart($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function kLengthApart(nums: number[], k: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (k-length-apart nums k)\n (-> (listof exact-integer?) exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1437](https://leetcode-cn.com/problems/check-if-all-1s-are-at-least-length-k-places-away)", "[\u662f\u5426\u6240\u6709 1 \u90fd\u81f3\u5c11\u76f8\u9694 k \u4e2a\u5143\u7d20](/solution/1400-1499/1437.Check%20If%20All%201%27s%20Are%20at%20Least%20Length%20K%20Places%20Away/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1437](https://leetcode.com/problems/check-if-all-1s-are-at-least-length-k-places-away)", "[Check If All 1's Are at Least Length K Places Away](/solution/1400-1499/1437.Check%20If%20All%201%27s%20Are%20at%20Least%20Length%20K%20Places%20Away/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1547", "frontend_question_id": "1436", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/destination-city", "url_en": "https://leetcode.com/problems/destination-city", "relative_path_cn": "/solution/1400-1499/1436.Destination%20City/README.md", "relative_path_en": "/solution/1400-1499/1436.Destination%20City/README_EN.md", "title_cn": "\u65c5\u884c\u7ec8\u70b9\u7ad9", "title_en": "Destination City", "question_title_slug": "destination-city", "content_en": "

    You are given the array paths, where paths[i] = [cityAi, cityBi] means there exists a direct path going from cityAi to cityBi. Return the destination city, that is, the city without any path outgoing to another city.

    \n\n

    It is guaranteed that the graph of paths forms a line without any loop, therefore, there will be exactly one destination city.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: paths = [["London","New York"],["New York","Lima"],["Lima","Sao Paulo"]]\nOutput: "Sao Paulo" \nExplanation: Starting at "London" city you will reach "Sao Paulo" city which is the destination city. Your trip consist of: "London" -> "New York" -> "Lima" -> "Sao Paulo".\n
    \n\n

    Example 2:

    \n\n
    \nInput: paths = [["B","C"],["D","B"],["C","A"]]\nOutput: "A"\nExplanation: All possible trips are: \n"D" -> "B" -> "C" -> "A". \n"B" -> "C" -> "A". \n"C" -> "A". \n"A". \nClearly the destination city is "A".\n
    \n\n

    Example 3:

    \n\n
    \nInput: paths = [["A","Z"]]\nOutput: "Z"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= paths.length <= 100
    • \n\t
    • paths[i].length == 2
    • \n\t
    • 1 <= cityAi.length, cityBi.length <= 10
    • \n\t
    • cityAi != cityBi
    • \n\t
    • All strings consist of lowercase and uppercase English letters and the space character.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4efd\u65c5\u6e38\u7ebf\u8def\u56fe\uff0c\u8be5\u7ebf\u8def\u56fe\u4e2d\u7684\u65c5\u884c\u7ebf\u8def\u7528\u6570\u7ec4 paths \u8868\u793a\uff0c\u5176\u4e2d paths[i] = [cityAi, cityBi] \u8868\u793a\u8be5\u7ebf\u8def\u5c06\u4f1a\u4ece cityAi \u76f4\u63a5\u524d\u5f80 cityBi \u3002\u8bf7\u4f60\u627e\u51fa\u8fd9\u6b21\u65c5\u884c\u7684\u7ec8\u70b9\u7ad9\uff0c\u5373\u6ca1\u6709\u4efb\u4f55\u53ef\u4ee5\u901a\u5f80\u5176\u4ed6\u57ce\u5e02\u7684\u7ebf\u8def\u7684\u57ce\u5e02\u3002

    \n\n

    \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u7ebf\u8def\u56fe\u4f1a\u5f62\u6210\u4e00\u6761\u4e0d\u5b58\u5728\u5faa\u73af\u7684\u7ebf\u8def\uff0c\u56e0\u6b64\u53ea\u4f1a\u6709\u4e00\u4e2a\u65c5\u884c\u7ec8\u70b9\u7ad9\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1apaths = [["London","New York"],["New York","Lima"],["Lima","Sao Paulo"]]\n\u8f93\u51fa\uff1a"Sao Paulo" \n\u89e3\u91ca\uff1a\u4ece "London" \u51fa\u53d1\uff0c\u6700\u540e\u62b5\u8fbe\u7ec8\u70b9\u7ad9 "Sao Paulo" \u3002\u672c\u6b21\u65c5\u884c\u7684\u8def\u7ebf\u662f "London" -> "New York" -> "Lima" -> "Sao Paulo" \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1apaths = [["B","C"],["D","B"],["C","A"]]\n\u8f93\u51fa\uff1a"A"\n\u89e3\u91ca\uff1a\u6240\u6709\u53ef\u80fd\u7684\u7ebf\u8def\u662f\uff1a\n"D" -> "B" -> "C" -> "A". \n"B" -> "C" -> "A". \n"C" -> "A". \n"A". \n\u663e\u7136\uff0c\u65c5\u884c\u7ec8\u70b9\u7ad9\u662f "A" \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1apaths = [["A","Z"]]\n\u8f93\u51fa\uff1a"Z"\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= paths.length <= 100
    • \n\t
    • paths[i].length == 2
    • \n\t
    • 1 <= cityAi.length, cityBi.length <= 10
    • \n\t
    • cityA!= cityBi
    • \n\t
    • \u6240\u6709\u5b57\u7b26\u4e32\u5747\u7531\u5927\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u548c\u7a7a\u683c\u5b57\u7b26\u7ec4\u6210\u3002
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string destCity(vector>& paths) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String destCity(List> paths) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def destCity(self, paths):\n \"\"\"\n :type paths: List[List[str]]\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def destCity(self, paths: List[List[str]]) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * destCity(char *** paths, int pathsSize, int* pathsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string DestCity(IList> paths) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[][]} paths\n * @return {string}\n */\nvar destCity = function(paths) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[][]} paths\n# @return {String}\ndef dest_city(paths)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func destCity(_ paths: [[String]]) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func destCity(paths [][]string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def destCity(paths: List[List[String]]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun destCity(paths: List>): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn dest_city(paths: Vec>) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $paths\n * @return String\n */\n function destCity($paths) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function destCity(paths: string[][]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (dest-city paths)\n (-> (listof (listof string?)) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1436](https://leetcode-cn.com/problems/destination-city)", "[\u65c5\u884c\u7ec8\u70b9\u7ad9](/solution/1400-1499/1436.Destination%20City/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1436](https://leetcode.com/problems/destination-city)", "[Destination City](/solution/1400-1499/1436.Destination%20City/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1546", "frontend_question_id": "1412", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/find-the-quiet-students-in-all-exams", "url_en": "https://leetcode.com/problems/find-the-quiet-students-in-all-exams", "relative_path_cn": "/solution/1400-1499/1412.Find%20the%20Quiet%20Students%20in%20All%20Exams/README.md", "relative_path_en": "/solution/1400-1499/1412.Find%20the%20Quiet%20Students%20in%20All%20Exams/README_EN.md", "title_cn": "\u67e5\u627e\u6210\u7ee9\u5904\u4e8e\u4e2d\u6e38\u7684\u5b66\u751f", "title_en": "Find the Quiet Students in All Exams", "question_title_slug": "find-the-quiet-students-in-all-exams", "content_en": "

    Table: Student

    \n\n
    \n+---------------------+---------+\n| Column Name         | Type    |\n+---------------------+---------+\n| student_id          | int     |\n| student_name        | varchar |\n+---------------------+---------+\nstudent_id is the primary key for this table.\nstudent_name is the name of the student.
    \n\n

     

    \n\n

    Table: Exam

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| exam_id       | int     |\n| student_id    | int     |\n| score         | int     |\n+---------------+---------+\n(exam_id, student_id) is the primary key for this table.\nStudent with student_id got score points in exam with id exam_id.\n
    \n\n

     

    \n\n

    A "quite" student is the one who took at least one exam and didn't score neither the high score nor the low score.

    \n\n

    Write an SQL query to report the students (student_id, student_name) being "quiet" in ALL exams.

    \n\n

    Don't return the student who has never taken any exam. Return the result table ordered by student_id.

    \n\n

    The query result format is in the following example.

    \n\n

     

    \n\n
    \nStudent table:\n+-------------+---------------+\n| student_id  | student_name  |\n+-------------+---------------+\n| 1           | Daniel        |\n| 2           | Jade          |\n| 3           | Stella        |\n| 4           | Jonathan      |\n| 5           | Will          |\n+-------------+---------------+\n\nExam table:\n+------------+--------------+-----------+\n| exam_id    | student_id   | score     |\n+------------+--------------+-----------+\n| 10         |     1        |    70     |\n| 10         |     2        |    80     |\n| 10         |     3        |    90     |\n| 20         |     1        |    80     |\n| 30         |     1        |    70     |\n| 30         |     3        |    80     |\n| 30         |     4        |    90     |\n| 40         |     1        |    60     |\n| 40         |     2        |    70     |\n| 40         |     4        |    80     |\n+------------+--------------+-----------+\n\nResult table:\n+-------------+---------------+\n| student_id  | student_name  |\n+-------------+---------------+\n| 2           | Jade          |\n+-------------+---------------+\n\nFor exam 1: Student 1 and 3 hold the lowest and high score respectively.\nFor exam 2: Student 1 hold both highest and lowest score.\nFor exam 3 and 4: Studnet 1 and 4 hold the lowest and high score respectively.\nStudent 2 and 5 have never got the highest or lowest in any of the exam.\nSince student 5 is not taking any exam, he is excluded from the result.\nSo, we only return the information of Student 2.
    \n", "content_cn": "

    \u8868: Student

    \n\n
    \n+---------------------+---------+\n| Column Name         | Type    |\n+---------------------+---------+\n| student_id          | int     |\n| student_name        | varchar |\n+---------------------+---------+\nstudent_id \u662f\u8be5\u8868\u4e3b\u952e.\nstudent_name \u5b66\u751f\u540d\u5b57.
    \n\n

    \u00a0

    \n\n

    \u8868: Exam

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| exam_id       | int     |\n| student_id    | int     |\n| score         | int     |\n+---------------+---------+\n(exam_id, student_id) \u662f\u8be5\u8868\u4e3b\u952e.\n\u5b66\u751f student_id \u5728\u6d4b\u9a8c exam_id \u4e2d\u5f97\u5206\u4e3a score.\n
    \n\n

    \u00a0

    \n\n

    \u6210\u7ee9\u5904\u4e8e\u4e2d\u6e38\u7684\u5b66\u751f\u662f\u6307\u81f3\u5c11\u53c2\u52a0\u4e86\u4e00\u6b21\u6d4b\u9a8c,\u00a0\u4e14\u5f97\u5206\u65e2\u4e0d\u662f\u6700\u9ad8\u5206\u4e5f\u4e0d\u662f\u6700\u4f4e\u5206\u7684\u5b66\u751f\u3002

    \n\n

    \u5199\u4e00\u4e2a SQL \u8bed\u53e5\uff0c\u627e\u51fa\u5728 \u6240\u6709 \u6d4b\u9a8c\u4e2d\u90fd\u5904\u4e8e\u4e2d\u6e38\u7684\u5b66\u751f (student_id, student_name)\u3002

    \n\n

    \u4e0d\u8981\u8fd4\u56de\u4ece\u6765\u6ca1\u6709\u53c2\u52a0\u8fc7\u6d4b\u9a8c\u7684\u5b66\u751f\u3002\u8fd4\u56de\u7ed3\u679c\u8868\u6309\u7167\u00a0student_id\u00a0\u6392\u5e8f\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u3002

    \n\n

    \u00a0

    \n\n
    \nStudent \u8868\uff1a\n+-------------+---------------+\n| student_id  | student_name  |\n+-------------+---------------+\n| 1           | Daniel        |\n| 2           | Jade          |\n| 3           | Stella        |\n| 4           | Jonathan      |\n| 5           | Will          |\n+-------------+---------------+\n\nExam \u8868\uff1a\n+------------+--------------+-----------+\n| exam_id    | student_id   | score     |\n+------------+--------------+-----------+\n| 10         |     1        |    70     |\n| 10         |     2        |    80     |\n| 10         |     3        |    90     |\n| 20         |     1        |    80     |\n| 30         |     1        |    70     |\n| 30         |     3        |    80     |\n| 30         |     4        |    90     |\n| 40         |     1        |    60     |\n| 40         |     2        |    70     |\n| 40         |     4        |    80     |\n+------------+--------------+-----------+\n\nResult \u8868\uff1a\n+-------------+---------------+\n| student_id  | student_name  |\n+-------------+---------------+\n| 2           | Jade          |\n+-------------+---------------+\n\n\u5bf9\u4e8e\u6d4b\u9a8c 1: \u5b66\u751f 1 \u548c 3 \u5206\u522b\u83b7\u5f97\u4e86\u6700\u4f4e\u5206\u548c\u6700\u9ad8\u5206\u3002\n\u5bf9\u4e8e\u6d4b\u9a8c 2: \u5b66\u751f 1 \u65e2\u83b7\u5f97\u4e86\u6700\u9ad8\u5206, \u4e5f\u83b7\u5f97\u4e86\u6700\u4f4e\u5206\u3002\n\u5bf9\u4e8e\u6d4b\u9a8c 3 \u548c 4: \u5b66\u751f 1 \u548c 4 \u5206\u522b\u83b7\u5f97\u4e86\u6700\u4f4e\u5206\u548c\u6700\u9ad8\u5206\u3002\n\u5b66\u751f 2 \u548c 5 \u6ca1\u6709\u5728\u4efb\u4e00\u573a\u6d4b\u9a8c\u4e2d\u83b7\u5f97\u4e86\u6700\u9ad8\u5206\u6216\u8005\u6700\u4f4e\u5206\u3002\n\u56e0\u4e3a\u5b66\u751f 5 \u4ece\u6765\u6ca1\u6709\u53c2\u52a0\u8fc7\u4efb\u4f55\u6d4b\u9a8c, \u6240\u4ee5\u4ed6\u88ab\u6392\u9664\u4e8e\u7ed3\u679c\u8868\u3002\n\u7531\u6b64, \u6211\u4eec\u4ec5\u4ec5\u8fd4\u56de\u5b66\u751f 2 \u7684\u4fe1\u606f\u3002
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1412](https://leetcode-cn.com/problems/find-the-quiet-students-in-all-exams)", "[\u67e5\u627e\u6210\u7ee9\u5904\u4e8e\u4e2d\u6e38\u7684\u5b66\u751f](/solution/1400-1499/1412.Find%20the%20Quiet%20Students%20in%20All%20Exams/README.md)", "", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1412](https://leetcode.com/problems/find-the-quiet-students-in-all-exams)", "[Find the Quiet Students in All Exams](/solution/1400-1499/1412.Find%20the%20Quiet%20Students%20in%20All%20Exams/README_EN.md)", "", "Hard", "\ud83d\udd12"]}, {"question_id": "1545", "frontend_question_id": "1449", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/form-largest-integer-with-digits-that-add-up-to-target", "url_en": "https://leetcode.com/problems/form-largest-integer-with-digits-that-add-up-to-target", "relative_path_cn": "/solution/1400-1499/1449.Form%20Largest%20Integer%20With%20Digits%20That%20Add%20up%20to%20Target/README.md", "relative_path_en": "/solution/1400-1499/1449.Form%20Largest%20Integer%20With%20Digits%20That%20Add%20up%20to%20Target/README_EN.md", "title_cn": "\u6570\u4f4d\u6210\u672c\u548c\u4e3a\u76ee\u6807\u503c\u7684\u6700\u5927\u6570\u5b57", "title_en": "Form Largest Integer With Digits That Add up to Target", "question_title_slug": "form-largest-integer-with-digits-that-add-up-to-target", "content_en": "

    Given an array of integers cost and an integer target. Return the maximum integer you can paint under the following rules:

    \n\n
      \n\t
    • The cost of painting a digit (i+1) is given by cost[i] (0 indexed).
    • \n\t
    • The total cost used must be equal to target.
    • \n\t
    • Integer does not have digits 0.
    • \n
    \n\n

    Since the answer may be too large, return it as string.

    \n\n

    If there is no way to paint any integer given the condition, return "0".

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: cost = [4,3,2,5,6,7,2,5,5], target = 9\nOutput: "7772"\nExplanation:  The cost to paint the digit '7' is 2, and the digit '2' is 3. Then cost("7772") = 2*3+ 3*1 = 9. You could also paint "977", but "7772" is the largest number.\nDigit    cost\n  1  ->   4\n  2  ->   3\n  3  ->   2\n  4  ->   5\n  5  ->   6\n  6  ->   7\n  7  ->   2\n  8  ->   5\n  9  ->   5\n
    \n\n

    Example 2:

    \n\n
    \nInput: cost = [7,6,5,5,5,6,8,7,8], target = 12\nOutput: "85"\nExplanation: The cost to paint the digit '8' is 7, and the digit '5' is 5. Then cost("85") = 7 + 5 = 12.\n
    \n\n

    Example 3:

    \n\n
    \nInput: cost = [2,4,6,2,4,6,4,4,4], target = 5\nOutput: "0"\nExplanation: It's not possible to paint any integer with total cost equal to target.\n
    \n\n

    Example 4:

    \n\n
    \nInput: cost = [6,10,15,40,40,40,40,40,40], target = 47\nOutput: "32211"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • cost.length == 9
    • \n\t
    • 1 <= cost[i] <= 5000
    • \n\t
    • 1 <= target <= 5000
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0cost\u00a0\u548c\u4e00\u4e2a\u6574\u6570\u00a0target\u00a0\u3002\u8bf7\u4f60\u8fd4\u56de\u6ee1\u8db3\u5982\u4e0b\u89c4\u5219\u53ef\u4ee5\u5f97\u5230\u7684\u00a0\u6700\u5927\u00a0\u6574\u6570\uff1a

    \n\n
      \n\t
    • \u7ed9\u5f53\u524d\u7ed3\u679c\u6dfb\u52a0\u4e00\u4e2a\u6570\u4f4d\uff08i + 1\uff09\u7684\u6210\u672c\u4e3a\u00a0cost[i]\u00a0\uff08cost\u00a0\u6570\u7ec4\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\u3002
    • \n\t
    • \u603b\u6210\u672c\u5fc5\u987b\u6070\u597d\u7b49\u4e8e\u00a0target\u00a0\u3002
    • \n\t
    • \u6dfb\u52a0\u7684\u6570\u4f4d\u4e2d\u6ca1\u6709\u6570\u5b57 0 \u3002
    • \n
    \n\n

    \u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u4f1a\u5f88\u5927\uff0c\u8bf7\u4f60\u4ee5\u5b57\u7b26\u4e32\u5f62\u5f0f\u8fd4\u56de\u3002

    \n\n

    \u5982\u679c\u6309\u7167\u4e0a\u8ff0\u8981\u6c42\u65e0\u6cd5\u5f97\u5230\u4efb\u4f55\u6574\u6570\uff0c\u8bf7\u4f60\u8fd4\u56de \"0\" \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1acost = [4,3,2,5,6,7,2,5,5], target = 9\n\u8f93\u51fa\uff1a\"7772\"\n\u89e3\u91ca\uff1a\u6dfb\u52a0\u6570\u4f4d '7' \u7684\u6210\u672c\u4e3a 2 \uff0c\u6dfb\u52a0\u6570\u4f4d '2' \u7684\u6210\u672c\u4e3a 3 \u3002\u6240\u4ee5 \"7772\" \u7684\u4ee3\u4ef7\u4e3a 2*3+ 3*1 = 9 \u3002 \"977\" \u4e5f\u662f\u6ee1\u8db3\u8981\u6c42\u7684\u6570\u5b57\uff0c\u4f46 \"7772\" \u662f\u8f83\u5927\u7684\u6570\u5b57\u3002\n \u6570\u5b57     \u6210\u672c\n  1  ->   4\n  2  ->   3\n  3  ->   2\n  4  ->   5\n  5  ->   6\n  6  ->   7\n  7  ->   2\n  8  ->   5\n  9  ->   5\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1acost = [7,6,5,5,5,6,8,7,8], target = 12\n\u8f93\u51fa\uff1a\"85\"\n\u89e3\u91ca\uff1a\u6dfb\u52a0\u6570\u4f4d '8' \u7684\u6210\u672c\u662f 7 \uff0c\u6dfb\u52a0\u6570\u4f4d '5' \u7684\u6210\u672c\u662f 5 \u3002\"85\" \u7684\u6210\u672c\u4e3a 7 + 5 = 12 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1acost = [2,4,6,2,4,6,4,4,4], target = 5\n\u8f93\u51fa\uff1a\"0\"\n\u89e3\u91ca\uff1a\u603b\u6210\u672c\u662f target \u7684\u6761\u4ef6\u4e0b\uff0c\u65e0\u6cd5\u751f\u6210\u4efb\u4f55\u6574\u6570\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1acost = [6,10,15,40,40,40,40,40,40], target = 47\n\u8f93\u51fa\uff1a\"32211\"\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • cost.length == 9
    • \n\t
    • 1 <= cost[i] <= 5000
    • \n\t
    • 1 <= target <= 5000
    • \n
    \n", "tags_en": ["String", "Dynamic Programming"], "tags_cn": ["\u5b57\u7b26\u4e32", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string largestNumber(vector& cost, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String largestNumber(int[] cost, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def largestNumber(self, cost, target):\n \"\"\"\n :type cost: List[int]\n :type target: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def largestNumber(self, cost: List[int], target: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * largestNumber(int* cost, int costSize, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string LargestNumber(int[] cost, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} cost\n * @param {number} target\n * @return {string}\n */\nvar largestNumber = function(cost, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} cost\n# @param {Integer} target\n# @return {String}\ndef largest_number(cost, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func largestNumber(_ cost: [Int], _ target: Int) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func largestNumber(cost []int, target int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def largestNumber(cost: Array[Int], target: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun largestNumber(cost: IntArray, target: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn largest_number(cost: Vec, target: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $cost\n * @param Integer $target\n * @return String\n */\n function largestNumber($cost, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function largestNumber(cost: number[], target: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (largest-number cost target)\n (-> (listof exact-integer?) exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1449](https://leetcode-cn.com/problems/form-largest-integer-with-digits-that-add-up-to-target)", "[\u6570\u4f4d\u6210\u672c\u548c\u4e3a\u76ee\u6807\u503c\u7684\u6700\u5927\u6570\u5b57](/solution/1400-1499/1449.Form%20Largest%20Integer%20With%20Digits%20That%20Add%20up%20to%20Target/README.md)", "`\u5b57\u7b26\u4e32`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1449](https://leetcode.com/problems/form-largest-integer-with-digits-that-add-up-to-target)", "[Form Largest Integer With Digits That Add up to Target](/solution/1400-1499/1449.Form%20Largest%20Integer%20With%20Digits%20That%20Add%20up%20to%20Target/README_EN.md)", "`String`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "1544", "frontend_question_id": "1448", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-good-nodes-in-binary-tree", "url_en": "https://leetcode.com/problems/count-good-nodes-in-binary-tree", "relative_path_cn": "/solution/1400-1499/1448.Count%20Good%20Nodes%20in%20Binary%20Tree/README.md", "relative_path_en": "/solution/1400-1499/1448.Count%20Good%20Nodes%20in%20Binary%20Tree/README_EN.md", "title_cn": "\u7edf\u8ba1\u4e8c\u53c9\u6811\u4e2d\u597d\u8282\u70b9\u7684\u6570\u76ee", "title_en": "Count Good Nodes in Binary Tree", "question_title_slug": "count-good-nodes-in-binary-tree", "content_en": "

    Given a binary tree root, a node X in the tree is named good if in the path from root to X there are no nodes with a value greater than X.

    \r\n\r\n

    Return the number of good nodes in the binary tree.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n

    \"\"

    \r\n\r\n
    \r\nInput: root = [3,1,4,3,null,1,5]\r\nOutput: 4\r\nExplanation: Nodes in blue are good.\r\nRoot Node (3) is always a good node.\r\nNode 4 -> (3,4) is the maximum value in the path starting from the root.\r\nNode 5 -> (3,4,5) is the maximum value in the path\r\nNode 3 -> (3,1,3) is the maximum value in the path.
    \r\n\r\n

    Example 2:

    \r\n\r\n

    \"\"

    \r\n\r\n
    \r\nInput: root = [3,3,null,4,2]\r\nOutput: 3\r\nExplanation: Node 2 -> (3, 3, 2) is not good, because "3" is higher than it.
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: root = [1]\r\nOutput: 1\r\nExplanation: Root is considered as good.
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • The number of nodes in the binary tree is in the range [1, 10^5].
    • \r\n\t
    • Each node's value is between [-10^4, 10^4].
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u68f5\u6839\u4e3a root \u7684\u4e8c\u53c9\u6811\uff0c\u8bf7\u4f60\u8fd4\u56de\u4e8c\u53c9\u6811\u4e2d\u597d\u8282\u70b9\u7684\u6570\u76ee\u3002

    \n\n

    \u300c\u597d\u8282\u70b9\u300dX \u5b9a\u4e49\u4e3a\uff1a\u4ece\u6839\u5230\u8be5\u8282\u70b9 X \u6240\u7ecf\u8fc7\u7684\u8282\u70b9\u4e2d\uff0c\u6ca1\u6709\u4efb\u4f55\u8282\u70b9\u7684\u503c\u5927\u4e8e X \u7684\u503c\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1aroot = [3,1,4,3,null,1,5]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u56fe\u4e2d\u84dd\u8272\u8282\u70b9\u4e3a\u597d\u8282\u70b9\u3002\n\u6839\u8282\u70b9 (3) \u6c38\u8fdc\u662f\u4e2a\u597d\u8282\u70b9\u3002\n\u8282\u70b9 4 -> (3,4) \u662f\u8def\u5f84\u4e2d\u7684\u6700\u5927\u503c\u3002\n\u8282\u70b9 5 -> (3,4,5) \u662f\u8def\u5f84\u4e2d\u7684\u6700\u5927\u503c\u3002\n\u8282\u70b9 3 -> (3,1,3) \u662f\u8def\u5f84\u4e2d\u7684\u6700\u5927\u503c\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1aroot = [3,3,null,4,2]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u8282\u70b9 2 -> (3, 3, 2) \u4e0d\u662f\u597d\u8282\u70b9\uff0c\u56e0\u4e3a "3" \u6bd4\u5b83\u5927\u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aroot = [1]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u6839\u8282\u70b9\u662f\u597d\u8282\u70b9\u3002
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u4e8c\u53c9\u6811\u4e2d\u8282\u70b9\u6570\u76ee\u8303\u56f4\u662f [1, 10^5] \u3002
    • \n\t
    • \u6bcf\u4e2a\u8282\u70b9\u6743\u503c\u7684\u8303\u56f4\u662f [-10^4, 10^4] \u3002
    • \n
    \n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int goodNodes(TreeNode* root) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int goodNodes(TreeNode root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def goodNodes(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def goodNodes(self, root: TreeNode) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint goodNodes(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int GoodNodes(TreeNode root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar goodNodes = function(root) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef good_nodes(root)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func goodNodes(_ root: TreeNode?) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc goodNodes(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def goodNodes(root: TreeNode): Int = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun goodNodes(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn good_nodes(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function goodNodes($root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction goodNodes(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (good-nodes root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1448](https://leetcode-cn.com/problems/count-good-nodes-in-binary-tree)", "[\u7edf\u8ba1\u4e8c\u53c9\u6811\u4e2d\u597d\u8282\u70b9\u7684\u6570\u76ee](/solution/1400-1499/1448.Count%20Good%20Nodes%20in%20Binary%20Tree/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1448](https://leetcode.com/problems/count-good-nodes-in-binary-tree)", "[Count Good Nodes in Binary Tree](/solution/1400-1499/1448.Count%20Good%20Nodes%20in%20Binary%20Tree/README_EN.md)", "`Tree`,`Depth-first Search`", "Medium", ""]}, {"question_id": "1543", "frontend_question_id": "1447", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/simplified-fractions", "url_en": "https://leetcode.com/problems/simplified-fractions", "relative_path_cn": "/solution/1400-1499/1447.Simplified%20Fractions/README.md", "relative_path_en": "/solution/1400-1499/1447.Simplified%20Fractions/README_EN.md", "title_cn": "\u6700\u7b80\u5206\u6570", "title_en": "Simplified Fractions", "question_title_slug": "simplified-fractions", "content_en": "

    Given an integer n, return a list of all simplified fractions between 0 and 1 (exclusive) such that the denominator is less-than-or-equal-to n. The fractions can be in any order.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: n = 2\r\nOutput: ["1/2"]\r\nExplanation: "1/2" is the only unique fraction with a denominator less-than-or-equal-to 2.
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: n = 3\r\nOutput: ["1/2","1/3","2/3"]\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: n = 4\r\nOutput: ["1/2","1/3","1/4","2/3","3/4"]\r\nExplanation: "2/4" is not a simplified fraction because it can be simplified to "1/2".
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: n = 1\r\nOutput: []\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= n <= 100
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n \uff0c\u8bf7\u4f60\u8fd4\u56de\u6240\u6709 0 \u5230 1 \u4e4b\u95f4\uff08\u4e0d\u5305\u62ec 0 \u548c 1\uff09\u6ee1\u8db3\u5206\u6bcd\u5c0f\u4e8e\u7b49\u4e8e  n \u7684 \u6700\u7b80 \u5206\u6570 \u3002\u5206\u6570\u53ef\u4ee5\u4ee5 \u4efb\u610f \u987a\u5e8f\u8fd4\u56de\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1an = 2\n\u8f93\u51fa\uff1a["1/2"]\n\u89e3\u91ca\uff1a"1/2" \u662f\u552f\u4e00\u4e00\u4e2a\u5206\u6bcd\u5c0f\u4e8e\u7b49\u4e8e 2 \u7684\u6700\u7b80\u5206\u6570\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1an = 3\n\u8f93\u51fa\uff1a["1/2","1/3","2/3"]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1an = 4\n\u8f93\u51fa\uff1a["1/2","1/3","1/4","2/3","3/4"]\n\u89e3\u91ca\uff1a"2/4" \u4e0d\u662f\u6700\u7b80\u5206\u6570\uff0c\u56e0\u4e3a\u5b83\u53ef\u4ee5\u5316\u7b80\u4e3a "1/2" \u3002
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1a[]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 100
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector simplifiedFractions(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List simplifiedFractions(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def simplifiedFractions(self, n):\n \"\"\"\n :type n: int\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def simplifiedFractions(self, n: int) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** simplifiedFractions(int n, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList SimplifiedFractions(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {string[]}\n */\nvar simplifiedFractions = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {String[]}\ndef simplified_fractions(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func simplifiedFractions(_ n: Int) -> [String] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func simplifiedFractions(n int) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def simplifiedFractions(n: Int): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun simplifiedFractions(n: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn simplified_fractions(n: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return String[]\n */\n function simplifiedFractions($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function simplifiedFractions(n: number): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (simplified-fractions n)\n (-> exact-integer? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1447](https://leetcode-cn.com/problems/simplified-fractions)", "[\u6700\u7b80\u5206\u6570](/solution/1400-1499/1447.Simplified%20Fractions/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1447](https://leetcode.com/problems/simplified-fractions)", "[Simplified Fractions](/solution/1400-1499/1447.Simplified%20Fractions/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "1542", "frontend_question_id": "1446", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/consecutive-characters", "url_en": "https://leetcode.com/problems/consecutive-characters", "relative_path_cn": "/solution/1400-1499/1446.Consecutive%20Characters/README.md", "relative_path_en": "/solution/1400-1499/1446.Consecutive%20Characters/README_EN.md", "title_cn": "\u8fde\u7eed\u5b57\u7b26", "title_en": "Consecutive Characters", "question_title_slug": "consecutive-characters", "content_en": "

    Given a string s, the power of the string is the maximum length of a non-empty substring that contains only one unique character.

    \r\n\r\n

    Return the power of the string.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: s = "leetcode"\r\nOutput: 2\r\nExplanation: The substring "ee" is of length 2 with the character 'e' only.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: s = "abbcccddddeeeeedcba"\r\nOutput: 5\r\nExplanation: The substring "eeeee" is of length 5 with the character 'e' only.\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: s = "triplepillooooow"\r\nOutput: 5\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: s = "hooraaaaaaaaaaay"\r\nOutput: 11\r\n
    \r\n\r\n

    Example 5:

    \r\n\r\n
    \r\nInput: s = "tourist"\r\nOutput: 1\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= s.length <= 500
    • \r\n\t
    • s contains only lowercase English letters.
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \uff0c\u5b57\u7b26\u4e32\u7684\u300c\u80fd\u91cf\u300d\u5b9a\u4e49\u4e3a\uff1a\u53ea\u5305\u542b\u4e00\u79cd\u5b57\u7b26\u7684\u6700\u957f\u975e\u7a7a\u5b50\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u5b57\u7b26\u4e32\u7684\u80fd\u91cf\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1as = "leetcode"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5b50\u5b57\u7b26\u4e32 "ee" \u957f\u5ea6\u4e3a 2 \uff0c\u53ea\u5305\u542b\u5b57\u7b26 'e' \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1as = "abbcccddddeeeeedcba"\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u5b50\u5b57\u7b26\u4e32 "eeeee" \u957f\u5ea6\u4e3a 5 \uff0c\u53ea\u5305\u542b\u5b57\u7b26 'e' \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1as = "triplepillooooow"\n\u8f93\u51fa\uff1a5\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1as = "hooraaaaaaaaaaay"\n\u8f93\u51fa\uff1a11\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1as = "tourist"\n\u8f93\u51fa\uff1a1\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 500
    • \n\t
    • s \u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxPower(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxPower(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxPower(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxPower(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxPower(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxPower(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar maxPower = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef max_power(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxPower(_ s: String) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxPower(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxPower(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxPower(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_power(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function maxPower($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxPower(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-power s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1446](https://leetcode-cn.com/problems/consecutive-characters)", "[\u8fde\u7eed\u5b57\u7b26](/solution/1400-1499/1446.Consecutive%20Characters/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1446](https://leetcode.com/problems/consecutive-characters)", "[Consecutive Characters](/solution/1400-1499/1446.Consecutive%20Characters/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1541", "frontend_question_id": "1407", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/top-travellers", "url_en": "https://leetcode.com/problems/top-travellers", "relative_path_cn": "/solution/1400-1499/1407.Top%20Travellers/README.md", "relative_path_en": "/solution/1400-1499/1407.Top%20Travellers/README_EN.md", "title_cn": "\u6392\u540d\u9760\u524d\u7684\u65c5\u884c\u8005", "title_en": "Top Travellers", "question_title_slug": "top-travellers", "content_en": "

    Table: Users

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| name          | varchar |\n+---------------+---------+\nid is the primary key for this table.\nname is the name of the user.\n
    \n\n

     

    \n\n

    Table: Rides

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| user_id       | int     |\n| distance      | int     |\n+---------------+---------+\nid is the primary key for this table.\nuser_id is the id of the user who travelled the distance "distance".\n
    \n\n

     

    \n\n

    Write an SQL query to report the distance travelled by each user.

    \n\n

    Return the result table ordered by travelled_distance in descending order, if two or more users travelled the same distance, order them by their name in ascending order.

    \n\n

    The query result format is in the following example.

    \n\n

     

    \n\n
    \nUsers table:\n+------+-----------+\n| id   | name      |\n+------+-----------+\n| 1    | Alice     |\n| 2    | Bob       |\n| 3    | Alex      |\n| 4    | Donald    |\n| 7    | Lee       |\n| 13   | Jonathan  |\n| 19   | Elvis     |\n+------+-----------+\n\nRides table:\n+------+----------+----------+\n| id   | user_id  | distance |\n+------+----------+----------+\n| 1    | 1        | 120      |\n| 2    | 2        | 317      |\n| 3    | 3        | 222      |\n| 4    | 7        | 100      |\n| 5    | 13       | 312      |\n| 6    | 19       | 50       |\n| 7    | 7        | 120      |\n| 8    | 19       | 400      |\n| 9    | 7        | 230      |\n+------+----------+----------+\n\nResult table:\n+----------+--------------------+\n| name     | travelled_distance |\n+----------+--------------------+\n| Elvis    | 450                |\n| Lee      | 450                |\n| Bob      | 317                |\n| Jonathan | 312                |\n| Alex     | 222                |\n| Alice    | 120                |\n| Donald   | 0                  |\n+----------+--------------------+\nElvis and Lee travelled 450 miles, Elvis is the top traveller as his name is alphabetically smaller than Lee.\nBob, Jonathan, Alex and Alice have only one ride and we just order them by the total distances of the ride.\nDonald didn't have any rides, the distance travelled by him is 0.\n
    \n", "content_cn": "

    \u8868\uff1aUsers

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| name          | varchar |\n+---------------+---------+\nid \u662f\u8be5\u8868\u5355\u4e3b\u952e\u3002\nname \u662f\u7528\u6237\u540d\u5b57\u3002
    \n\n

    \u00a0

    \n\n

    \u8868\uff1aRides

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| user_id       | int     |\n| distance      | int     |\n+---------------+---------+\nid \u662f\u8be5\u8868\u5355\u4e3b\u952e\u3002\nuser_id \u662f\u672c\u6b21\u884c\u7a0b\u7684\u7528\u6237\u7684 id, \u800c\u8be5\u7528\u6237\u6b64\u6b21\u884c\u7a0b\u8ddd\u79bb\u4e3a distance \u3002\n
    \n\n

    \u00a0

    \n\n

    \u5199\u4e00\u6bb5 SQL ,\u00a0\u62a5\u544a\u6bcf\u4e2a\u7528\u6237\u7684\u65c5\u884c\u8ddd\u79bb\u3002

    \n\n

    \u8fd4\u56de\u7684\u7ed3\u679c\u8868\u5355\uff0c\u4ee5\u00a0travelled_distance\u00a0\u964d\u5e8f\u6392\u5217 \uff0c\u5982\u679c\u6709\u4e24\u4e2a\u6216\u8005\u66f4\u591a\u7684\u7528\u6237\u65c5\u884c\u4e86\u76f8\u540c\u7684\u8ddd\u79bb,\u00a0\u90a3\u4e48\u518d\u4ee5\u00a0name\u00a0\u5347\u5e8f\u6392\u5217 \u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a\u3002

    \n\n
    \nUsers \u8868\uff1a\n+------+-----------+\n| id   | name      |\n+------+-----------+\n| 1    | Alice     |\n| 2    | Bob       |\n| 3    | Alex      |\n| 4    | Donald    |\n| 7    | Lee       |\n| 13   | Jonathan  |\n| 19   | Elvis     |\n+------+-----------+\n\nRides \u8868\uff1a\n+------+----------+----------+\n| id   | user_id  | distance |\n+------+----------+----------+\n| 1    | 1        | 120      |\n| 2    | 2        | 317      |\n| 3    | 3        | 222      |\n| 4    | 7        | 100      |\n| 5    | 13       | 312      |\n| 6    | 19       | 50       |\n| 7    | 7        | 120      |\n| 8    | 19       | 400      |\n| 9    | 7        | 230      |\n+------+----------+----------+\n\nResult \u8868\uff1a\n+----------+--------------------+\n| name     | travelled_distance |\n+----------+--------------------+\n| Elvis    | 450                |\n| Lee      | 450                |\n| Bob      | 317                |\n| Jonathan | 312                |\n| Alex     | 222                |\n| Alice    | 120                |\n| Donald   | 0                  |\n+----------+--------------------+\nElvis \u548c Lee \u65c5\u884c\u4e86 450 \u82f1\u91cc\uff0cElvis \u662f\u6392\u540d\u9760\u524d\u7684\u65c5\u884c\u8005\uff0c\u56e0\u4e3a\u4ed6\u7684\u540d\u5b57\u5728\u5b57\u6bcd\u8868\u4e0a\u7684\u6392\u5e8f\u6bd4 Lee \u66f4\u5c0f\u3002\nBob, Jonathan, Alex \u548c Alice \u53ea\u6709\u4e00\u6b21\u884c\u7a0b\uff0c\u6211\u4eec\u53ea\u6309\u6b64\u6b21\u884c\u7a0b\u7684\u5168\u90e8\u8ddd\u79bb\u5bf9\u4ed6\u4eec\u6392\u5e8f\u3002\nDonald \u6ca1\u6709\u4efb\u4f55\u884c\u7a0b, \u4ed6\u7684\u65c5\u884c\u8ddd\u79bb\u4e3a 0\u3002\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1407](https://leetcode-cn.com/problems/top-travellers)", "[\u6392\u540d\u9760\u524d\u7684\u65c5\u884c\u8005](/solution/1400-1499/1407.Top%20Travellers/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1407](https://leetcode.com/problems/top-travellers)", "[Top Travellers](/solution/1400-1499/1407.Top%20Travellers/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1539", "frontend_question_id": "1424", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/diagonal-traverse-ii", "url_en": "https://leetcode.com/problems/diagonal-traverse-ii", "relative_path_cn": "/solution/1400-1499/1424.Diagonal%20Traverse%20II/README.md", "relative_path_en": "/solution/1400-1499/1424.Diagonal%20Traverse%20II/README_EN.md", "title_cn": "\u5bf9\u89d2\u7ebf\u904d\u5386 II", "title_en": "Diagonal Traverse II", "question_title_slug": "diagonal-traverse-ii", "content_en": "Given a list of lists of integers, nums, return all elements of nums in diagonal order as shown in the below images.\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: nums = [[1,2,3],[4,5,6],[7,8,9]]\nOutput: [1,4,2,7,5,3,8,6,9]\n
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: nums = [[1,2,3,4,5],[6,7],[8],[9,10,11],[12,13,14,15,16]]\nOutput: [1,6,2,8,7,3,9,4,12,10,5,13,11,14,15,16]\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [[1,2,3],[4],[5,6,7],[8],[9,10,11]]\nOutput: [1,4,2,5,3,8,6,9,7,10,11]\n
    \n\n

    Example 4:

    \n\n
    \nInput: nums = [[1,2,3,4,5,6]]\nOutput: [1,2,3,4,5,6]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 10^5
    • \n\t
    • 1 <= nums[i].length <= 10^5
    • \n\t
    • 1 <= nums[i][j] <= 10^9
    • \n\t
    • There at most 10^5 elements in nums.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5217\u8868 nums \uff0c\u91cc\u9762\u6bcf\u4e00\u4e2a\u5143\u7d20\u90fd\u662f\u4e00\u4e2a\u6574\u6570\u5217\u8868\u3002\u8bf7\u4f60\u4f9d\u7167\u4e0b\u9762\u5404\u56fe\u7684\u89c4\u5219\uff0c\u6309\u987a\u5e8f\u8fd4\u56de nums \u4e2d\u5bf9\u89d2\u7ebf\u4e0a\u7684\u6574\u6570\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1anums = [[1,2,3],[4,5,6],[7,8,9]]\n\u8f93\u51fa\uff1a[1,4,2,7,5,3,8,6,9]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1anums = [[1,2,3,4,5],[6,7],[8],[9,10,11],[12,13,14,15,16]]\n\u8f93\u51fa\uff1a[1,6,2,8,7,3,9,4,12,10,5,13,11,14,15,16]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [[1,2,3],[4],[5,6,7],[8],[9,10,11]]\n\u8f93\u51fa\uff1a[1,4,2,5,3,8,6,9,7,10,11]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [[1,2,3,4,5,6]]\n\u8f93\u51fa\uff1a[1,2,3,4,5,6]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 10^5
    • \n\t
    • 1 <= nums[i].length <= 10^5
    • \n\t
    • 1 <= nums[i][j] <= 10^9
    • \n\t
    • nums \u4e2d\u6700\u591a\u6709 10^5 \u4e2a\u6570\u5b57\u3002
    • \n
    \n", "tags_en": ["Sort", "Array"], "tags_cn": ["\u6392\u5e8f", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findDiagonalOrder(vector>& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] findDiagonalOrder(List> nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findDiagonalOrder(self, nums):\n \"\"\"\n :type nums: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findDiagonalOrder(self, nums: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* findDiagonalOrder(int** nums, int numsSize, int* numsColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] FindDiagonalOrder(IList> nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} nums\n * @return {number[]}\n */\nvar findDiagonalOrder = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} nums\n# @return {Integer[]}\ndef find_diagonal_order(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findDiagonalOrder(_ nums: [[Int]]) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findDiagonalOrder(nums [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findDiagonalOrder(nums: List[List[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findDiagonalOrder(nums: List>): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_diagonal_order(nums: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $nums\n * @return Integer[]\n */\n function findDiagonalOrder($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findDiagonalOrder(nums: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-diagonal-order nums)\n (-> (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1424](https://leetcode-cn.com/problems/diagonal-traverse-ii)", "[\u5bf9\u89d2\u7ebf\u904d\u5386 II](/solution/1400-1499/1424.Diagonal%20Traverse%20II/README.md)", "`\u6392\u5e8f`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1424](https://leetcode.com/problems/diagonal-traverse-ii)", "[Diagonal Traverse II](/solution/1400-1499/1424.Diagonal%20Traverse%20II/README_EN.md)", "`Sort`,`Array`", "Medium", ""]}, {"question_id": "1538", "frontend_question_id": "1423", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-points-you-can-obtain-from-cards", "url_en": "https://leetcode.com/problems/maximum-points-you-can-obtain-from-cards", "relative_path_cn": "/solution/1400-1499/1423.Maximum%20Points%20You%20Can%20Obtain%20from%20Cards/README.md", "relative_path_en": "/solution/1400-1499/1423.Maximum%20Points%20You%20Can%20Obtain%20from%20Cards/README_EN.md", "title_cn": "\u53ef\u83b7\u5f97\u7684\u6700\u5927\u70b9\u6570", "title_en": "Maximum Points You Can Obtain from Cards", "question_title_slug": "maximum-points-you-can-obtain-from-cards", "content_en": "

    There are several cards arranged in a row, and each card has an associated number of points. The points are given in the integer array cardPoints.

    \n\n

    In one step, you can take one card from the beginning or from the end of the row. You have to take exactly k cards.

    \n\n

    Your score is the sum of the points of the cards you have taken.

    \n\n

    Given the integer array cardPoints and the integer k, return the maximum score you can obtain.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: cardPoints = [1,2,3,4,5,6,1], k = 3\nOutput: 12\nExplanation: After the first step, your score will always be 1. However, choosing the rightmost card first will maximize your total score. The optimal strategy is to take the three cards on the right, giving a final score of 1 + 6 + 5 = 12.\n
    \n\n

    Example 2:

    \n\n
    \nInput: cardPoints = [2,2,2], k = 2\nOutput: 4\nExplanation: Regardless of which two cards you take, your score will always be 4.\n
    \n\n

    Example 3:

    \n\n
    \nInput: cardPoints = [9,7,7,9,7,7,9], k = 7\nOutput: 55\nExplanation: You have to take all the cards. Your score is the sum of points of all cards.\n
    \n\n

    Example 4:

    \n\n
    \nInput: cardPoints = [1,1000,1], k = 1\nOutput: 1\nExplanation: You cannot take the card in the middle. Your best score is 1. \n
    \n\n

    Example 5:

    \n\n
    \nInput: cardPoints = [1,79,80,1,1,1,200,1], k = 3\nOutput: 202\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= cardPoints.length <= 105
    • \n\t
    • 1 <= cardPoints[i] <= 104
    • \n\t
    • 1 <= k <= cardPoints.length
    • \n
    \n", "content_cn": "

    \u51e0\u5f20\u5361\u724c \u6392\u6210\u4e00\u884c\uff0c\u6bcf\u5f20\u5361\u724c\u90fd\u6709\u4e00\u4e2a\u5bf9\u5e94\u7684\u70b9\u6570\u3002\u70b9\u6570\u7531\u6574\u6570\u6570\u7ec4 cardPoints \u7ed9\u51fa\u3002

    \n\n

    \u6bcf\u6b21\u884c\u52a8\uff0c\u4f60\u53ef\u4ee5\u4ece\u884c\u7684\u5f00\u5934\u6216\u8005\u672b\u5c3e\u62ff\u4e00\u5f20\u5361\u724c\uff0c\u6700\u7ec8\u4f60\u5fc5\u987b\u6b63\u597d\u62ff k \u5f20\u5361\u724c\u3002

    \n\n

    \u4f60\u7684\u70b9\u6570\u5c31\u662f\u4f60\u62ff\u5230\u624b\u4e2d\u7684\u6240\u6709\u5361\u724c\u7684\u70b9\u6570\u4e4b\u548c\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 cardPoints \u548c\u6574\u6570 k\uff0c\u8bf7\u4f60\u8fd4\u56de\u53ef\u4ee5\u83b7\u5f97\u7684\u6700\u5927\u70b9\u6570\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1acardPoints = [1,2,3,4,5,6,1], k = 3\n\u8f93\u51fa\uff1a12\n\u89e3\u91ca\uff1a\u7b2c\u4e00\u6b21\u884c\u52a8\uff0c\u4e0d\u7ba1\u62ff\u54ea\u5f20\u724c\uff0c\u4f60\u7684\u70b9\u6570\u603b\u662f 1 \u3002\u4f46\u662f\uff0c\u5148\u62ff\u6700\u53f3\u8fb9\u7684\u5361\u724c\u5c06\u4f1a\u6700\u5927\u5316\u4f60\u7684\u53ef\u83b7\u5f97\u70b9\u6570\u3002\u6700\u4f18\u7b56\u7565\u662f\u62ff\u53f3\u8fb9\u7684\u4e09\u5f20\u724c\uff0c\u6700\u7ec8\u70b9\u6570\u4e3a 1 + 6 + 5 = 12 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1acardPoints = [2,2,2], k = 2\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u65e0\u8bba\u4f60\u62ff\u8d77\u54ea\u4e24\u5f20\u5361\u724c\uff0c\u53ef\u83b7\u5f97\u7684\u70b9\u6570\u603b\u662f 4 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1acardPoints = [9,7,7,9,7,7,9], k = 7\n\u8f93\u51fa\uff1a55\n\u89e3\u91ca\uff1a\u4f60\u5fc5\u987b\u62ff\u8d77\u6240\u6709\u5361\u724c\uff0c\u53ef\u4ee5\u83b7\u5f97\u7684\u70b9\u6570\u4e3a\u6240\u6709\u5361\u724c\u7684\u70b9\u6570\u4e4b\u548c\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1acardPoints = [1,1000,1], k = 1\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u4f60\u65e0\u6cd5\u62ff\u5230\u4e2d\u95f4\u90a3\u5f20\u5361\u724c\uff0c\u6240\u4ee5\u53ef\u4ee5\u83b7\u5f97\u7684\u6700\u5927\u70b9\u6570\u4e3a 1 \u3002 \n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1acardPoints = [1,79,80,1,1,1,200,1], k = 3\n\u8f93\u51fa\uff1a202\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= cardPoints.length <= 10^5
    • \n\t
    • 1 <= cardPoints[i] <= 10^4
    • \n\t
    • 1 <= k <= cardPoints.length
    • \n
    \n", "tags_en": ["Array", "Dynamic Programming", "Sliding Window"], "tags_cn": ["\u6570\u7ec4", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxScore(vector& cardPoints, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxScore(int[] cardPoints, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxScore(self, cardPoints, k):\n \"\"\"\n :type cardPoints: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxScore(self, cardPoints: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxScore(int* cardPoints, int cardPointsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxScore(int[] cardPoints, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} cardPoints\n * @param {number} k\n * @return {number}\n */\nvar maxScore = function(cardPoints, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} card_points\n# @param {Integer} k\n# @return {Integer}\ndef max_score(card_points, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxScore(_ cardPoints: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxScore(cardPoints []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxScore(cardPoints: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxScore(cardPoints: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_score(card_points: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $cardPoints\n * @param Integer $k\n * @return Integer\n */\n function maxScore($cardPoints, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxScore(cardPoints: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-score cardPoints k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1423](https://leetcode-cn.com/problems/maximum-points-you-can-obtain-from-cards)", "[\u53ef\u83b7\u5f97\u7684\u6700\u5927\u70b9\u6570](/solution/1400-1499/1423.Maximum%20Points%20You%20Can%20Obtain%20from%20Cards/README.md)", "`\u6570\u7ec4`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1423](https://leetcode.com/problems/maximum-points-you-can-obtain-from-cards)", "[Maximum Points You Can Obtain from Cards](/solution/1400-1499/1423.Maximum%20Points%20You%20Can%20Obtain%20from%20Cards/README_EN.md)", "`Array`,`Dynamic Programming`,`Sliding Window`", "Medium", ""]}, {"question_id": "1537", "frontend_question_id": "1422", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-score-after-splitting-a-string", "url_en": "https://leetcode.com/problems/maximum-score-after-splitting-a-string", "relative_path_cn": "/solution/1400-1499/1422.Maximum%20Score%20After%20Splitting%20a%20String/README.md", "relative_path_en": "/solution/1400-1499/1422.Maximum%20Score%20After%20Splitting%20a%20String/README_EN.md", "title_cn": "\u5206\u5272\u5b57\u7b26\u4e32\u7684\u6700\u5927\u5f97\u5206", "title_en": "Maximum Score After Splitting a String", "question_title_slug": "maximum-score-after-splitting-a-string", "content_en": "

    Given a string s of zeros and ones, return the maximum score after splitting the string into two non-empty substrings (i.e. left substring and right substring).

    \n\n

    The score after splitting a string is the number of zeros in the left substring plus the number of ones in the right substring.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "011101"\nOutput: 5 \nExplanation: \nAll possible ways of splitting s into two non-empty substrings are:\nleft = "0" and right = "11101", score = 1 + 4 = 5 \nleft = "01" and right = "1101", score = 1 + 3 = 4 \nleft = "011" and right = "101", score = 1 + 2 = 3 \nleft = "0111" and right = "01", score = 1 + 1 = 2 \nleft = "01110" and right = "1", score = 2 + 1 = 3\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "00111"\nOutput: 5\nExplanation: When left = "00" and right = "111", we get the maximum score = 2 + 3 = 5\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "1111"\nOutput: 3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= s.length <= 500
    • \n\t
    • The string s consists of characters '0' and '1' only.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u7531\u82e5\u5e72 0 \u548c 1 \u7ec4\u6210\u7684\u5b57\u7b26\u4e32 s \uff0c\u8bf7\u4f60\u8ba1\u7b97\u5e76\u8fd4\u56de\u5c06\u8be5\u5b57\u7b26\u4e32\u5206\u5272\u6210\u4e24\u4e2a \u975e\u7a7a \u5b50\u5b57\u7b26\u4e32\uff08\u5373 \u5de6 \u5b50\u5b57\u7b26\u4e32\u548c \u53f3 \u5b50\u5b57\u7b26\u4e32\uff09\u6240\u80fd\u83b7\u5f97\u7684\u6700\u5927\u5f97\u5206\u3002

    \n\n

    \u300c\u5206\u5272\u5b57\u7b26\u4e32\u7684\u5f97\u5206\u300d\u4e3a \u5de6 \u5b50\u5b57\u7b26\u4e32\u4e2d 0 \u7684\u6570\u91cf\u52a0\u4e0a \u53f3 \u5b50\u5b57\u7b26\u4e32\u4e2d 1 \u7684\u6570\u91cf\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1as = "011101"\n\u8f93\u51fa\uff1a5 \n\u89e3\u91ca\uff1a\n\u5c06\u5b57\u7b26\u4e32 s \u5212\u5206\u4e3a\u4e24\u4e2a\u975e\u7a7a\u5b50\u5b57\u7b26\u4e32\u7684\u53ef\u884c\u65b9\u6848\u6709\uff1a\n\u5de6\u5b50\u5b57\u7b26\u4e32 = "0" \u4e14 \u53f3\u5b50\u5b57\u7b26\u4e32 = "11101"\uff0c\u5f97\u5206 = 1 + 4 = 5 \n\u5de6\u5b50\u5b57\u7b26\u4e32 = "01" \u4e14 \u53f3\u5b50\u5b57\u7b26\u4e32 = "1101"\uff0c\u5f97\u5206 = 1 + 3 = 4 \n\u5de6\u5b50\u5b57\u7b26\u4e32 = "011" \u4e14 \u53f3\u5b50\u5b57\u7b26\u4e32 = "101"\uff0c\u5f97\u5206 = 1 + 2 = 3 \n\u5de6\u5b50\u5b57\u7b26\u4e32 = "0111" \u4e14 \u53f3\u5b50\u5b57\u7b26\u4e32 = "01"\uff0c\u5f97\u5206 = 1 + 1 = 2 \n\u5de6\u5b50\u5b57\u7b26\u4e32 = "01110" \u4e14 \u53f3\u5b50\u5b57\u7b26\u4e32 = "1"\uff0c\u5f97\u5206 = 2 + 1 = 3\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1as = "00111"\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u5f53 \u5de6\u5b50\u5b57\u7b26\u4e32 = "00" \u4e14 \u53f3\u5b50\u5b57\u7b26\u4e32 = "111" \u65f6\uff0c\u6211\u4eec\u5f97\u5230\u6700\u5927\u5f97\u5206 = 2 + 3 = 5\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1as = "1111"\n\u8f93\u51fa\uff1a3\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= s.length <= 500
    • \n\t
    • \u5b57\u7b26\u4e32 s \u4ec5\u7531\u5b57\u7b26 '0' \u548c '1' \u7ec4\u6210\u3002
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxScore(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxScore(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxScore(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxScore(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxScore(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxScore(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar maxScore = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef max_score(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxScore(_ s: String) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxScore(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxScore(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxScore(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_score(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function maxScore($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxScore(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-score s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1422](https://leetcode-cn.com/problems/maximum-score-after-splitting-a-string)", "[\u5206\u5272\u5b57\u7b26\u4e32\u7684\u6700\u5927\u5f97\u5206](/solution/1400-1499/1422.Maximum%20Score%20After%20Splitting%20a%20String/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1422](https://leetcode.com/problems/maximum-score-after-splitting-a-string)", "[Maximum Score After Splitting a String](/solution/1400-1499/1422.Maximum%20Score%20After%20Splitting%20a%20String/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1536", "frontend_question_id": "1398", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/customers-who-bought-products-a-and-b-but-not-c", "url_en": "https://leetcode.com/problems/customers-who-bought-products-a-and-b-but-not-c", "relative_path_cn": "/solution/1300-1399/1398.Customers%20Who%20Bought%20Products%20A%20and%20B%20but%20Not%20C/README.md", "relative_path_en": "/solution/1300-1399/1398.Customers%20Who%20Bought%20Products%20A%20and%20B%20but%20Not%20C/README_EN.md", "title_cn": "\u8d2d\u4e70\u4e86\u4ea7\u54c1 A \u548c\u4ea7\u54c1 B \u5374\u6ca1\u6709\u8d2d\u4e70\u4ea7\u54c1 C \u7684\u987e\u5ba2", "title_en": "Customers Who Bought Products A and B but Not C", "question_title_slug": "customers-who-bought-products-a-and-b-but-not-c", "content_en": "

    Table: Customers

    \n\n
    \n+---------------------+---------+\n| Column Name         | Type    |\n+---------------------+---------+\n| customer_id         | int     |\n| customer_name       | varchar |\n+---------------------+---------+\ncustomer_id is the primary key for this table.\ncustomer_name is the name of the customer.
    \n\n

     

    \n\n

    Table: Orders

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| order_id      | int     |\n| customer_id   | int     |\n| product_name  | varchar |\n+---------------+---------+\norder_id is the primary key for this table.\ncustomer_id is the id of the customer who bought the product "product_name".\n
    \n\n

     

    \n\n

    Write an SQL query to report the customer_id and customer_name of customers who bought products "A", "B" but did not buy the product "C" since we want to recommend them buy this product.

    \n\n

    Return the result table ordered by customer_id.

    \n\n

    The query result format is in the following example.

    \n\n

     

    \n\n
    \nCustomers table:\n+-------------+---------------+\n| customer_id | customer_name |\n+-------------+---------------+\n| 1           | Daniel        |\n| 2           | Diana         |\n| 3           | Elizabeth     |\n| 4           | Jhon          |\n+-------------+---------------+\n\nOrders table:\n+------------+--------------+---------------+\n| order_id   | customer_id  | product_name  |\n+------------+--------------+---------------+\n| 10         |     1        |     A         |\n| 20         |     1        |     B         |\n| 30         |     1        |     D         |\n| 40         |     1        |     C         |\n| 50         |     2        |     A         |\n| 60         |     3        |     A         |\n| 70         |     3        |     B         |\n| 80         |     3        |     D         |\n| 90         |     4        |     C         |\n+------------+--------------+---------------+\n\nResult table:\n+-------------+---------------+\n| customer_id | customer_name |\n+-------------+---------------+\n| 3           | Elizabeth     |\n+-------------+---------------+\nOnly the customer_id with id 3 bought the product A and B but not the product C.
    \n", "content_cn": "

     Customers \u8868\uff1a

    \n\n
    \n+---------------------+---------+\n| Column Name         | Type    |\n+---------------------+---------+\n| customer_id         | int     |\n| customer_name       | varchar |\n+---------------------+---------+\ncustomer_id \u662f\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\u3002\ncustomer_name \u662f\u987e\u5ba2\u7684\u540d\u79f0\u3002
    \n\n

     

    \n\n

    Orders \u8868\uff1a

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| order_id      | int     |\n| customer_id   | int     |\n| product_name  | varchar |\n+---------------+---------+\norder_id \u662f\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\u3002\ncustomer_id \u662f\u8d2d\u4e70\u4e86\u540d\u4e3a "product_name" \u4ea7\u54c1\u987e\u5ba2\u7684id\u3002\n
    \n\n

     

    \n\n

    \u8bf7\u4f60\u8bbe\u8ba1 SQL \u67e5\u8be2\u6765\u62a5\u544a\u8d2d\u4e70\u4e86\u4ea7\u54c1 A \u548c\u4ea7\u54c1 B \u5374\u6ca1\u6709\u8d2d\u4e70\u4ea7\u54c1 C \u7684\u987e\u5ba2\u7684 ID \u548c\u59d3\u540d\uff08 customer_id \u548c customer_name \uff09\uff0c\u6211\u4eec\u5c06\u57fa\u4e8e\u6b64\u7ed3\u679c\u4e3a\u4ed6\u4eec\u63a8\u8350\u4ea7\u54c1 C \u3002
    \n\u60a8\u8fd4\u56de\u7684\u67e5\u8be2\u7ed3\u679c\u9700\u8981\u6309\u7167 customer_id \u6392\u5e8f\u3002

    \n\n

     

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u5982\u4e0b\u4f8b\u6240\u793a\u3002

    \n\n
    \nCustomers table:\n+-------------+---------------+\n| customer_id | customer_name |\n+-------------+---------------+\n| 1           | Daniel        |\n| 2           | Diana         |\n| 3           | Elizabeth     |\n| 4           | Jhon          |\n+-------------+---------------+\n\nOrders table:\n+------------+--------------+---------------+\n| order_id   | customer_id  | product_name  |\n+------------+--------------+---------------+\n| 10         |     1        |     A         |\n| 20         |     1        |     B         |\n| 30         |     1        |     D         |\n| 40         |     1        |     C         |\n| 50         |     2        |     A         |\n| 60         |     3        |     A         |\n| 70         |     3        |     B         |\n| 80         |     3        |     D         |\n| 90         |     4        |     C         |\n+------------+--------------+---------------+\n\nResult table:\n+-------------+---------------+\n| customer_id | customer_name |\n+-------------+---------------+\n| 3           | Elizabeth     |\n+-------------+---------------+\n\u53ea\u6709 customer_id \u4e3a 3 \u7684\u987e\u5ba2\u8d2d\u4e70\u4e86\u4ea7\u54c1 A \u548c\u4ea7\u54c1 B \uff0c\u5374\u6ca1\u6709\u8d2d\u4e70\u4ea7\u54c1 C \u3002
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1398](https://leetcode-cn.com/problems/customers-who-bought-products-a-and-b-but-not-c)", "[\u8d2d\u4e70\u4e86\u4ea7\u54c1 A \u548c\u4ea7\u54c1 B \u5374\u6ca1\u6709\u8d2d\u4e70\u4ea7\u54c1 C \u7684\u987e\u5ba2](/solution/1300-1399/1398.Customers%20Who%20Bought%20Products%20A%20and%20B%20but%20Not%20C/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1398](https://leetcode.com/problems/customers-who-bought-products-a-and-b-but-not-c)", "[Customers Who Bought Products A and B but Not C](/solution/1300-1399/1398.Customers%20Who%20Bought%20Products%20A%20and%20B%20but%20Not%20C/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1535", "frontend_question_id": "1420", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/build-array-where-you-can-find-the-maximum-exactly-k-comparisons", "url_en": "https://leetcode.com/problems/build-array-where-you-can-find-the-maximum-exactly-k-comparisons", "relative_path_cn": "/solution/1400-1499/1420.Build%20Array%20Where%20You%20Can%20Find%20The%20Maximum%20Exactly%20K%20Comparisons/README.md", "relative_path_en": "/solution/1400-1499/1420.Build%20Array%20Where%20You%20Can%20Find%20The%20Maximum%20Exactly%20K%20Comparisons/README_EN.md", "title_cn": "\u751f\u6210\u6570\u7ec4", "title_en": "Build Array Where You Can Find The Maximum Exactly K Comparisons", "question_title_slug": "build-array-where-you-can-find-the-maximum-exactly-k-comparisons", "content_en": "

    Given three integers n, m and k. Consider the following algorithm to find the maximum element of an array of positive integers:

    \r\n\"\"\r\n

    You should build the array arr which has the following properties:

    \r\n\r\n
      \r\n\t
    • arr has exactly n integers.
    • \r\n\t
    • 1 <= arr[i] <= m where (0 <= i < n).
    • \r\n\t
    • After applying the mentioned algorithm to arr, the value search_cost is equal to k.
    • \r\n
    \r\n\r\n

    Return the number of ways to build the array arr under the mentioned conditions. As the answer may grow large, the answer must be computed modulo 10^9 + 7.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: n = 2, m = 3, k = 1\r\nOutput: 6\r\nExplanation: The possible arrays are [1, 1], [2, 1], [2, 2], [3, 1], [3, 2] [3, 3]\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: n = 5, m = 2, k = 3\r\nOutput: 0\r\nExplanation: There are no possible arrays that satisify the mentioned conditions.\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: n = 9, m = 1, k = 1\r\nOutput: 1\r\nExplanation: The only possible array is [1, 1, 1, 1, 1, 1, 1, 1, 1]\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: n = 50, m = 100, k = 25\r\nOutput: 34549172\r\nExplanation: Don't forget to compute the answer modulo 1000000007\r\n
    \r\n\r\n

    Example 5:

    \r\n\r\n
    \r\nInput: n = 37, m = 17, k = 7\r\nOutput: 418930126\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= n <= 50
    • \r\n\t
    • 1 <= m <= 100
    • \r\n\t
    • 0 <= k <= n
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e09\u4e2a\u6574\u6570 n\u3001m \u548c k \u3002\u4e0b\u56fe\u63cf\u8ff0\u7684\u7b97\u6cd5\u7528\u4e8e\u627e\u51fa\u6b63\u6574\u6570\u6570\u7ec4\u4e2d\u6700\u5927\u7684\u5143\u7d20\u3002

    \n\n

    \"\"

    \n\n

    \u8bf7\u4f60\u751f\u6210\u4e00\u4e2a\u5177\u6709\u4e0b\u8ff0\u5c5e\u6027\u7684\u6570\u7ec4 arr \uff1a

    \n\n
      \n\t
    • arr \u4e2d\u6709 n \u4e2a\u6574\u6570\u3002
    • \n\t
    • 1 <= arr[i] <= m \u5176\u4e2d (0 <= i < n) \u3002
    • \n\t
    • \u5c06\u4e0a\u9762\u63d0\u5230\u7684\u7b97\u6cd5\u5e94\u7528\u4e8e arr \uff0csearch_cost \u7684\u503c\u7b49\u4e8e k \u3002
    • \n
    \n\n

    \u8fd4\u56de\u4e0a\u8ff0\u6761\u4ef6\u4e0b\u751f\u6210\u6570\u7ec4 arr \u7684 \u65b9\u6cd5\u6570 \uff0c\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u4f1a\u5f88\u5927\uff0c\u6240\u4ee5 \u5fc5\u987b \u5bf9 10^9 + 7 \u53d6\u4f59\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1an = 2, m = 3, k = 1\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u53ef\u80fd\u7684\u6570\u7ec4\u5206\u522b\u4e3a [1, 1], [2, 1], [2, 2], [3, 1], [3, 2] [3, 3]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1an = 5, m = 2, k = 3\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6ca1\u6709\u6570\u7ec4\u53ef\u4ee5\u6ee1\u8db3\u4e0a\u8ff0\u6761\u4ef6\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1an = 9, m = 1, k = 1\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u53ef\u80fd\u7684\u6570\u7ec4\u53ea\u6709 [1, 1, 1, 1, 1, 1, 1, 1, 1]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1an = 50, m = 100, k = 25\n\u8f93\u51fa\uff1a34549172\n\u89e3\u91ca\uff1a\u4e0d\u8981\u5fd8\u4e86\u5bf9 1000000007 \u53d6\u4f59\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1an = 37, m = 17, k = 7\n\u8f93\u51fa\uff1a418930126\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 50
    • \n\t
    • 1 <= m <= 100
    • \n\t
    • 0 <= k <= n
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numOfArrays(int n, int m, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numOfArrays(int n, int m, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numOfArrays(self, n, m, k):\n \"\"\"\n :type n: int\n :type m: int\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numOfArrays(self, n: int, m: int, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numOfArrays(int n, int m, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumOfArrays(int n, int m, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} m\n * @param {number} k\n * @return {number}\n */\nvar numOfArrays = function(n, m, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} m\n# @param {Integer} k\n# @return {Integer}\ndef num_of_arrays(n, m, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numOfArrays(_ n: Int, _ m: Int, _ k: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numOfArrays(n int, m int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numOfArrays(n: Int, m: Int, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numOfArrays(n: Int, m: Int, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_of_arrays(n: i32, m: i32, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $m\n * @param Integer $k\n * @return Integer\n */\n function numOfArrays($n, $m, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numOfArrays(n: number, m: number, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-of-arrays n m k)\n (-> exact-integer? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1420](https://leetcode-cn.com/problems/build-array-where-you-can-find-the-maximum-exactly-k-comparisons)", "[\u751f\u6210\u6570\u7ec4](/solution/1400-1499/1420.Build%20Array%20Where%20You%20Can%20Find%20The%20Maximum%20Exactly%20K%20Comparisons/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1420](https://leetcode.com/problems/build-array-where-you-can-find-the-maximum-exactly-k-comparisons)", "[Build Array Where You Can Find The Maximum Exactly K Comparisons](/solution/1400-1499/1420.Build%20Array%20Where%20You%20Can%20Find%20The%20Maximum%20Exactly%20K%20Comparisons/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1534", "frontend_question_id": "1419", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-number-of-frogs-croaking", "url_en": "https://leetcode.com/problems/minimum-number-of-frogs-croaking", "relative_path_cn": "/solution/1400-1499/1419.Minimum%20Number%20of%20Frogs%20Croaking/README.md", "relative_path_en": "/solution/1400-1499/1419.Minimum%20Number%20of%20Frogs%20Croaking/README_EN.md", "title_cn": "\u6570\u9752\u86d9", "title_en": "Minimum Number of Frogs Croaking", "question_title_slug": "minimum-number-of-frogs-croaking", "content_en": "

    Given the string croakOfFrogs, which represents a combination of the string "croak" from different frogs, that is, multiple frogs can croak at the same time, so multiple “croak” are mixed. Return the minimum number of different frogs to finish all the croak in the given string.

    \n\n

    A valid "croak" means a frog is printing 5 letters ‘c’, ’r’, ’o’, ’a’, ’k’ sequentially. The frogs have to print all five letters to finish a croak. If the given string is not a combination of valid "croak" return -1.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: croakOfFrogs = "croakcroak"\nOutput: 1 \nExplanation: One frog yelling "croak" twice.\n
    \n\n

    Example 2:

    \n\n
    \nInput: croakOfFrogs = "crcoakroak"\nOutput: 2 \nExplanation: The minimum number of frogs is two. \nThe first frog could yell "crcoakroak".\nThe second frog could yell later "crcoakroak".\n
    \n\n

    Example 3:

    \n\n
    \nInput: croakOfFrogs = "croakcrook"\nOutput: -1\nExplanation: The given string is an invalid combination of "croak" from different frogs.\n
    \n\n

    Example 4:

    \n\n
    \nInput: croakOfFrogs = "croakcroa"\nOutput: -1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= croakOfFrogs.length <= 10^5
    • \n\t
    • All characters in the string are: 'c', 'r', 'o', 'a' or 'k'.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 croakOfFrogs\uff0c\u5b83\u8868\u793a\u4e0d\u540c\u9752\u86d9\u53d1\u51fa\u7684\u86d9\u9e23\u58f0\uff08\u5b57\u7b26\u4e32 "croak" \uff09\u7684\u7ec4\u5408\u3002\u7531\u4e8e\u540c\u4e00\u65f6\u95f4\u53ef\u4ee5\u6709\u591a\u53ea\u9752\u86d9\u5471\u5471\u4f5c\u54cd\uff0c\u6240\u4ee5 croakOfFrogs \u4e2d\u4f1a\u6df7\u5408\u591a\u4e2a “croak” \u3002\u8bf7\u4f60\u8fd4\u56de\u6a21\u62df\u5b57\u7b26\u4e32\u4e2d\u6240\u6709\u86d9\u9e23\u6240\u9700\u4e0d\u540c\u9752\u86d9\u7684\u6700\u5c11\u6570\u76ee\u3002

    \n\n

    \u6ce8\u610f\uff1a\u8981\u60f3\u53d1\u51fa\u86d9\u9e23 "croak"\uff0c\u9752\u86d9\u5fc5\u987b \u4f9d\u5e8f \u8f93\u51fa ‘c’, ’r’, ’o’, ’a’, ’k’ \u8fd9 5 \u4e2a\u5b57\u6bcd\u3002\u5982\u679c\u6ca1\u6709\u8f93\u51fa\u5168\u90e8\u4e94\u4e2a\u5b57\u6bcd\uff0c\u90a3\u4e48\u5b83\u5c31\u4e0d\u4f1a\u53d1\u51fa\u58f0\u97f3\u3002

    \n\n

    \u5982\u679c\u5b57\u7b26\u4e32 croakOfFrogs \u4e0d\u662f\u7531\u82e5\u5e72\u6709\u6548\u7684 "croak" \u5b57\u7b26\u6df7\u5408\u800c\u6210\uff0c\u8bf7\u8fd4\u56de -1 \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1acroakOfFrogs = "croakcroak"\n\u8f93\u51fa\uff1a1 \n\u89e3\u91ca\uff1a\u4e00\u53ea\u9752\u86d9 “\u5471\u5471” \u4e24\u6b21\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1acroakOfFrogs = "crcoakroak"\n\u8f93\u51fa\uff1a2 \n\u89e3\u91ca\uff1a\u6700\u5c11\u9700\u8981\u4e24\u53ea\u9752\u86d9\uff0c“\u5471\u5471” \u58f0\u7528\u9ed1\u4f53\u6807\u6ce8\n\u7b2c\u4e00\u53ea\u9752\u86d9 "crcoakroak"\n\u7b2c\u4e8c\u53ea\u9752\u86d9 "crcoakroak"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1acroakOfFrogs = "croakcrook"\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u7ed9\u51fa\u7684\u5b57\u7b26\u4e32\u4e0d\u662f "croak" \u7684\u6709\u6548\u7ec4\u5408\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1acroakOfFrogs = "croakcroa"\n\u8f93\u51fa\uff1a-1\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= croakOfFrogs.length <= 10^5
    • \n\t
    • \u5b57\u7b26\u4e32\u4e2d\u7684\u5b57\u7b26\u53ea\u6709 'c', 'r', 'o', 'a' \u6216\u8005 'k'
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minNumberOfFrogs(string croakOfFrogs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minNumberOfFrogs(String croakOfFrogs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minNumberOfFrogs(self, croakOfFrogs):\n \"\"\"\n :type croakOfFrogs: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minNumberOfFrogs(self, croakOfFrogs: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minNumberOfFrogs(char * croakOfFrogs){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinNumberOfFrogs(string croakOfFrogs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} croakOfFrogs\n * @return {number}\n */\nvar minNumberOfFrogs = function(croakOfFrogs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} croak_of_frogs\n# @return {Integer}\ndef min_number_of_frogs(croak_of_frogs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minNumberOfFrogs(_ croakOfFrogs: String) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minNumberOfFrogs(croakOfFrogs string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minNumberOfFrogs(croakOfFrogs: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minNumberOfFrogs(croakOfFrogs: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_number_of_frogs(croak_of_frogs: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $croakOfFrogs\n * @return Integer\n */\n function minNumberOfFrogs($croakOfFrogs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minNumberOfFrogs(croakOfFrogs: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-number-of-frogs croakOfFrogs)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1419](https://leetcode-cn.com/problems/minimum-number-of-frogs-croaking)", "[\u6570\u9752\u86d9](/solution/1400-1499/1419.Minimum%20Number%20of%20Frogs%20Croaking/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1419](https://leetcode.com/problems/minimum-number-of-frogs-croaking)", "[Minimum Number of Frogs Croaking](/solution/1400-1499/1419.Minimum%20Number%20of%20Frogs%20Croaking/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "1533", "frontend_question_id": "1418", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/display-table-of-food-orders-in-a-restaurant", "url_en": "https://leetcode.com/problems/display-table-of-food-orders-in-a-restaurant", "relative_path_cn": "/solution/1400-1499/1418.Display%20Table%20of%20Food%20Orders%20in%20a%20Restaurant/README.md", "relative_path_en": "/solution/1400-1499/1418.Display%20Table%20of%20Food%20Orders%20in%20a%20Restaurant/README_EN.md", "title_cn": "\u70b9\u83dc\u5c55\u793a\u8868", "title_en": "Display Table of Food Orders in a Restaurant", "question_title_slug": "display-table-of-food-orders-in-a-restaurant", "content_en": "

    Given the array orders, which represents the orders that customers have done in a restaurant. More specifically orders[i]=[customerNamei,tableNumberi,foodItemi] where customerNamei is the name of the customer, tableNumberi is the table customer sit at, and foodItemi is the item customer orders.

    \r\n\r\n

    Return the restaurant's “display table. The “display table” is a table whose row entries denote how many of each food item each table ordered. The first column is the table number and the remaining columns correspond to each food item in alphabetical order. The first row should be a header whose first column is “Table”, followed by the names of the food items. Note that the customer names are not part of the table. Additionally, the rows should be sorted in numerically increasing order.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: orders = [["David","3","Ceviche"],["Corina","10","Beef Burrito"],["David","3","Fried Chicken"],["Carla","5","Water"],["Carla","5","Ceviche"],["Rous","3","Ceviche"]]\r\nOutput: [["Table","Beef Burrito","Ceviche","Fried Chicken","Water"],["3","0","2","1","0"],["5","0","1","0","1"],["10","1","0","0","0"]] \r\nExplanation:\r\nThe displaying table looks like:\r\nTable,Beef Burrito,Ceviche,Fried Chicken,Water\r\n3    ,0           ,2      ,1            ,0\r\n5    ,0           ,1      ,0            ,1\r\n10   ,1           ,0      ,0            ,0\r\nFor the table 3: David orders "Ceviche" and "Fried Chicken", and Rous orders "Ceviche".\r\nFor the table 5: Carla orders "Water" and "Ceviche".\r\nFor the table 10: Corina orders "Beef Burrito". \r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: orders = [["James","12","Fried Chicken"],["Ratesh","12","Fried Chicken"],["Amadeus","12","Fried Chicken"],["Adam","1","Canadian Waffles"],["Brianna","1","Canadian Waffles"]]\r\nOutput: [["Table","Canadian Waffles","Fried Chicken"],["1","2","0"],["12","0","3"]] \r\nExplanation: \r\nFor the table 1: Adam and Brianna order "Canadian Waffles".\r\nFor the table 12: James, Ratesh and Amadeus order "Fried Chicken".\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: orders = [["Laura","2","Bean Burrito"],["Jhon","2","Beef Burrito"],["Melissa","2","Soda"]]\r\nOutput: [["Table","Bean Burrito","Beef Burrito","Soda"],["2","1","1","1"]]\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= orders.length <= 5 * 10^4
    • \r\n\t
    • orders[i].length == 3
    • \r\n\t
    • 1 <= customerNamei.length, foodItemi.length <= 20
    • \r\n\t
    • customerNamei and foodItemi consist of lowercase and uppercase English letters and the space character.
    • \r\n\t
    • tableNumberi is a valid integer between 1 and 500.
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 orders\uff0c\u8868\u793a\u5ba2\u6237\u5728\u9910\u5385\u4e2d\u5b8c\u6210\u7684\u8ba2\u5355\uff0c\u786e\u5207\u5730\u8bf4\uff0c orders[i]=[customerNamei,tableNumberi,foodItemi] \uff0c\u5176\u4e2d customerNamei \u662f\u5ba2\u6237\u7684\u59d3\u540d\uff0ctableNumberi \u662f\u5ba2\u6237\u6240\u5728\u9910\u684c\u7684\u684c\u53f7\uff0c\u800c foodItemi \u662f\u5ba2\u6237\u70b9\u7684\u9910\u54c1\u540d\u79f0\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u8be5\u9910\u5385\u7684 \u70b9\u83dc\u5c55\u793a\u8868 \u3002\u5728\u8fd9\u5f20\u8868\u4e2d\uff0c\u8868\u4e2d\u7b2c\u4e00\u884c\u4e3a\u6807\u9898\uff0c\u5176\u7b2c\u4e00\u5217\u4e3a\u9910\u684c\u684c\u53f7 “Table” \uff0c\u540e\u9762\u6bcf\u4e00\u5217\u90fd\u662f\u6309\u5b57\u6bcd\u987a\u5e8f\u6392\u5217\u7684\u9910\u54c1\u540d\u79f0\u3002\u63a5\u4e0b\u6765\u6bcf\u4e00\u884c\u4e2d\u7684\u9879\u5219\u8868\u793a\u6bcf\u5f20\u9910\u684c\u8ba2\u8d2d\u7684\u76f8\u5e94\u9910\u54c1\u6570\u91cf\uff0c\u7b2c\u4e00\u5217\u5e94\u5f53\u586b\u5bf9\u5e94\u7684\u684c\u53f7\uff0c\u540e\u9762\u4f9d\u6b21\u586b\u5199\u4e0b\u5355\u7684\u9910\u54c1\u6570\u91cf\u3002

    \n\n

    \u6ce8\u610f\uff1a\u5ba2\u6237\u59d3\u540d\u4e0d\u662f\u70b9\u83dc\u5c55\u793a\u8868\u7684\u4e00\u90e8\u5206\u3002\u6b64\u5916\uff0c\u8868\u4e2d\u7684\u6570\u636e\u884c\u5e94\u8be5\u6309\u9910\u684c\u684c\u53f7\u5347\u5e8f\u6392\u5217\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aorders = [["David","3","Ceviche"],["Corina","10","Beef Burrito"],["David","3","Fried Chicken"],["Carla","5","Water"],["Carla","5","Ceviche"],["Rous","3","Ceviche"]]\n\u8f93\u51fa\uff1a[["Table","Beef Burrito","Ceviche","Fried Chicken","Water"],["3","0","2","1","0"],["5","0","1","0","1"],["10","1","0","0","0"]] \n\u89e3\u91ca\uff1a\n\u70b9\u83dc\u5c55\u793a\u8868\u5982\u4e0b\u6240\u793a\uff1a\nTable,Beef Burrito,Ceviche,Fried Chicken,Water\n3    ,0           ,2      ,1            ,0\n5    ,0           ,1      ,0            ,1\n10   ,1           ,0      ,0            ,0\n\u5bf9\u4e8e\u9910\u684c 3\uff1aDavid \u70b9\u4e86 "Ceviche" \u548c "Fried Chicken"\uff0c\u800c Rous \u70b9\u4e86 "Ceviche"\n\u800c\u9910\u684c 5\uff1aCarla \u70b9\u4e86 "Water" \u548c "Ceviche"\n\u9910\u684c 10\uff1aCorina \u70b9\u4e86 "Beef Burrito" \n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aorders = [["James","12","Fried Chicken"],["Ratesh","12","Fried Chicken"],["Amadeus","12","Fried Chicken"],["Adam","1","Canadian Waffles"],["Brianna","1","Canadian Waffles"]]\n\u8f93\u51fa\uff1a[["Table","Canadian Waffles","Fried Chicken"],["1","2","0"],["12","0","3"]] \n\u89e3\u91ca\uff1a\n\u5bf9\u4e8e\u9910\u684c 1\uff1aAdam \u548c Brianna \u90fd\u70b9\u4e86 "Canadian Waffles"\n\u800c\u9910\u684c 12\uff1aJames, Ratesh \u548c Amadeus \u90fd\u70b9\u4e86 "Fried Chicken"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aorders = [["Laura","2","Bean Burrito"],["Jhon","2","Beef Burrito"],["Melissa","2","Soda"]]\n\u8f93\u51fa\uff1a[["Table","Bean Burrito","Beef Burrito","Soda"],["2","1","1","1"]]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= orders.length <= 5 * 10^4
    • \n\t
    • orders[i].length == 3
    • \n\t
    • 1 <= customerNamei.length, foodItemi.length <= 20
    • \n\t
    • customerNamei \u548c foodItemi \u7531\u5927\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u53ca\u7a7a\u683c\u5b57\u7b26 ' ' \u7ec4\u6210\u3002
    • \n\t
    • tableNumberi \u662f 1 \u5230 500 \u8303\u56f4\u5185\u7684\u6574\u6570\u3002
    • \n
    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> displayTable(vector>& orders) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> displayTable(List> orders) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def displayTable(self, orders):\n \"\"\"\n :type orders: List[List[str]]\n :rtype: List[List[str]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def displayTable(self, orders: List[List[str]]) -> List[List[str]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nchar *** displayTable(char *** orders, int ordersSize, int* ordersColSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> DisplayTable(IList> orders) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[][]} orders\n * @return {string[][]}\n */\nvar displayTable = function(orders) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[][]} orders\n# @return {String[][]}\ndef display_table(orders)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func displayTable(_ orders: [[String]]) -> [[String]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func displayTable(orders [][]string) [][]string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def displayTable(orders: List[List[String]]): List[List[String]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun displayTable(orders: List>): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn display_table(orders: Vec>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $orders\n * @return String[][]\n */\n function displayTable($orders) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function displayTable(orders: string[][]): string[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (display-table orders)\n (-> (listof (listof string?)) (listof (listof string?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1418](https://leetcode-cn.com/problems/display-table-of-food-orders-in-a-restaurant)", "[\u70b9\u83dc\u5c55\u793a\u8868](/solution/1400-1499/1418.Display%20Table%20of%20Food%20Orders%20in%20a%20Restaurant/README.md)", "`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1418](https://leetcode.com/problems/display-table-of-food-orders-in-a-restaurant)", "[Display Table of Food Orders in a Restaurant](/solution/1400-1499/1418.Display%20Table%20of%20Food%20Orders%20in%20a%20Restaurant/README_EN.md)", "`Hash Table`", "Medium", ""]}, {"question_id": "1532", "frontend_question_id": "1417", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reformat-the-string", "url_en": "https://leetcode.com/problems/reformat-the-string", "relative_path_cn": "/solution/1400-1499/1417.Reformat%20The%20String/README.md", "relative_path_en": "/solution/1400-1499/1417.Reformat%20The%20String/README_EN.md", "title_cn": "\u91cd\u65b0\u683c\u5f0f\u5316\u5b57\u7b26\u4e32", "title_en": "Reformat The String", "question_title_slug": "reformat-the-string", "content_en": "

    Given alphanumeric string s. (Alphanumeric string is a string consisting of lowercase English letters and digits).

    \n\n

    You have to find a permutation of the string where no letter is followed by another letter and no digit is followed by another digit. That is, no two adjacent characters have the same type.

    \n\n

    Return the reformatted string or return an empty string if it is impossible to reformat the string.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "a0b1c2"\nOutput: "0a1b2c"\nExplanation: No two adjacent characters have the same type in "0a1b2c". "a0b1c2", "0a1b2c", "0c2a1b" are also valid permutations.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "leetcode"\nOutput: ""\nExplanation: "leetcode" has only characters so we cannot separate them by digits.\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "1229857369"\nOutput: ""\nExplanation: "1229857369" has only digits so we cannot separate them by characters.\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "covid2019"\nOutput: "c2o0v1i9d"\n
    \n\n

    Example 5:

    \n\n
    \nInput: s = "ab123"\nOutput: "1a2b3"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 500
    • \n\t
    • s consists of only lowercase English letters and/or digits.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6df7\u5408\u4e86\u6570\u5b57\u548c\u5b57\u6bcd\u7684\u5b57\u7b26\u4e32 s\uff0c\u5176\u4e2d\u7684\u5b57\u6bcd\u5747\u4e3a\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002

    \n\n

    \u8bf7\u4f60\u5c06\u8be5\u5b57\u7b26\u4e32\u91cd\u65b0\u683c\u5f0f\u5316\uff0c\u4f7f\u5f97\u4efb\u610f\u4e24\u4e2a\u76f8\u90bb\u5b57\u7b26\u7684\u7c7b\u578b\u90fd\u4e0d\u540c\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u5b57\u6bcd\u540e\u9762\u5e94\u8be5\u8ddf\u7740\u6570\u5b57\uff0c\u800c\u6570\u5b57\u540e\u9762\u5e94\u8be5\u8ddf\u7740\u5b57\u6bcd\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de \u91cd\u65b0\u683c\u5f0f\u5316\u540e \u7684\u5b57\u7b26\u4e32\uff1b\u5982\u679c\u65e0\u6cd5\u6309\u8981\u6c42\u91cd\u65b0\u683c\u5f0f\u5316\uff0c\u5219\u8fd4\u56de\u4e00\u4e2a \u7a7a\u5b57\u7b26\u4e32 \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1as = "a0b1c2"\n\u8f93\u51fa\uff1a"0a1b2c"\n\u89e3\u91ca\uff1a"0a1b2c" \u4e2d\u4efb\u610f\u4e24\u4e2a\u76f8\u90bb\u5b57\u7b26\u7684\u7c7b\u578b\u90fd\u4e0d\u540c\u3002 "a0b1c2", "0a1b2c", "0c2a1b" \u4e5f\u662f\u6ee1\u8db3\u9898\u76ee\u8981\u6c42\u7684\u7b54\u6848\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1as = "leetcode"\n\u8f93\u51fa\uff1a""\n\u89e3\u91ca\uff1a"leetcode" \u4e2d\u53ea\u6709\u5b57\u6bcd\uff0c\u6240\u4ee5\u65e0\u6cd5\u6ee1\u8db3\u91cd\u65b0\u683c\u5f0f\u5316\u7684\u6761\u4ef6\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1as = "1229857369"\n\u8f93\u51fa\uff1a""\n\u89e3\u91ca\uff1a"1229857369" \u4e2d\u53ea\u6709\u6570\u5b57\uff0c\u6240\u4ee5\u65e0\u6cd5\u6ee1\u8db3\u91cd\u65b0\u683c\u5f0f\u5316\u7684\u6761\u4ef6\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1as = "covid2019"\n\u8f93\u51fa\uff1a"c2o0v1i9d"\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1as = "ab123"\n\u8f93\u51fa\uff1a"1a2b3"\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 500
    • \n\t
    • s \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u548c/\u6216\u6570\u5b57\u7ec4\u6210\u3002
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string reformat(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String reformat(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def reformat(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def reformat(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * reformat(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string Reformat(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar reformat = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef reformat(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func reformat(_ s: String) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func reformat(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def reformat(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun reformat(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn reformat(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function reformat($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function reformat(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (reformat s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1417](https://leetcode-cn.com/problems/reformat-the-string)", "[\u91cd\u65b0\u683c\u5f0f\u5316\u5b57\u7b26\u4e32](/solution/1400-1499/1417.Reformat%20The%20String/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1417](https://leetcode.com/problems/reformat-the-string)", "[Reformat The String](/solution/1400-1499/1417.Reformat%20The%20String/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1531", "frontend_question_id": "1434", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-ways-to-wear-different-hats-to-each-other", "url_en": "https://leetcode.com/problems/number-of-ways-to-wear-different-hats-to-each-other", "relative_path_cn": "/solution/1400-1499/1434.Number%20of%20Ways%20to%20Wear%20Different%20Hats%20to%20Each%20Other/README.md", "relative_path_en": "/solution/1400-1499/1434.Number%20of%20Ways%20to%20Wear%20Different%20Hats%20to%20Each%20Other/README_EN.md", "title_cn": "\u6bcf\u4e2a\u4eba\u6234\u4e0d\u540c\u5e3d\u5b50\u7684\u65b9\u6848\u6570", "title_en": "Number of Ways to Wear Different Hats to Each Other", "question_title_slug": "number-of-ways-to-wear-different-hats-to-each-other", "content_en": "

    There are n people and 40 types of hats labeled from 1 to 40.

    \r\n\r\n

    Given a list of list of integers hats, where hats[i] is a list of all hats preferred by the i-th person.

    \r\n\r\n

    Return the number of ways that the n people wear different hats to each other.

    \r\n\r\n

    Since the answer may be too large, return it modulo 10^9 + 7.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: hats = [[3,4],[4,5],[5]]\r\nOutput: 1\r\nExplanation: There is only one way to choose hats given the conditions. \r\nFirst person choose hat 3, Second person choose hat 4 and last one hat 5.
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: hats = [[3,5,1],[3,5]]\r\nOutput: 4\r\nExplanation: There are 4 ways to choose hats\r\n(3,5), (5,3), (1,3) and (1,5)\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: hats = [[1,2,3,4],[1,2,3,4],[1,2,3,4],[1,2,3,4]]\r\nOutput: 24\r\nExplanation: Each person can choose hats labeled from 1 to 4.\r\nNumber of Permutations of (1,2,3,4) = 24.\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: hats = [[1,2,3],[2,3,5,6],[1,3,7,9],[1,8,9],[2,5,7]]\r\nOutput: 111\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • n == hats.length
    • \r\n\t
    • 1 <= n <= 10
    • \r\n\t
    • 1 <= hats[i].length <= 40
    • \r\n\t
    • 1 <= hats[i][j] <= 40
    • \r\n\t
    • hats[i] contains a list of unique integers.
    • \r\n
    ", "content_cn": "

    \u603b\u5171\u6709 n \u4e2a\u4eba\u548c 40 \u79cd\u4e0d\u540c\u7684\u5e3d\u5b50\uff0c\u5e3d\u5b50\u7f16\u53f7\u4ece 1 \u5230 40 \u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u5217\u8868\u7684\u5217\u8868 hats \uff0c\u5176\u4e2d hats[i] \u662f\u7b2c i \u4e2a\u4eba\u6240\u6709\u559c\u6b22\u5e3d\u5b50\u7684\u5217\u8868\u3002

    \n\n

    \u8bf7\u4f60\u7ed9\u6bcf\u4e2a\u4eba\u5b89\u6392\u4e00\u9876\u4ed6\u559c\u6b22\u7684\u5e3d\u5b50\uff0c\u786e\u4fdd\u6bcf\u4e2a\u4eba\u6234\u7684\u5e3d\u5b50\u8ddf\u522b\u4eba\u90fd\u4e0d\u4e00\u6837\uff0c\u5e76\u8fd4\u56de\u65b9\u6848\u6570\u3002

    \n\n

    \u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u5f88\u5927\uff0c\u8bf7\u8fd4\u56de\u5b83\u5bf9 10^9 + 7 \u53d6\u4f59\u540e\u7684\u7ed3\u679c\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahats = [[3,4],[4,5],[5]]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u7ed9\u5b9a\u6761\u4ef6\u4e0b\u53ea\u6709\u4e00\u79cd\u65b9\u6cd5\u9009\u62e9\u5e3d\u5b50\u3002\n\u7b2c\u4e00\u4e2a\u4eba\u9009\u62e9\u5e3d\u5b50 3\uff0c\u7b2c\u4e8c\u4e2a\u4eba\u9009\u62e9\u5e3d\u5b50 4\uff0c\u6700\u540e\u4e00\u4e2a\u4eba\u9009\u62e9\u5e3d\u5b50 5\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahats = [[3,5,1],[3,5]]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u603b\u5171\u6709 4 \u79cd\u5b89\u6392\u5e3d\u5b50\u7684\u65b9\u6cd5\uff1a\n(3,5)\uff0c(5,3)\uff0c(1,3) \u548c (1,5)\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahats = [[1,2,3,4],[1,2,3,4],[1,2,3,4],[1,2,3,4]]\n\u8f93\u51fa\uff1a24\n\u89e3\u91ca\uff1a\u6bcf\u4e2a\u4eba\u90fd\u53ef\u4ee5\u4ece\u7f16\u53f7\u4e3a 1 \u5230 4 \u7684\u5e3d\u5b50\u4e2d\u9009\u3002\n(1,2,3,4) 4 \u4e2a\u5e3d\u5b50\u7684\u6392\u5217\u65b9\u6848\u6570\u4e3a 24 \u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahats = [[1,2,3],[2,3,5,6],[1,3,7,9],[1,8,9],[2,5,7]]\n\u8f93\u51fa\uff1a111\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == hats.length
    • \n\t
    • 1 <= n <= 10
    • \n\t
    • 1 <= hats[i].length <= 40
    • \n\t
    • 1 <= hats[i][j] <= 40
    • \n\t
    • hats[i] \u5305\u542b\u4e00\u4e2a\u6570\u5b57\u4e92\u4e0d\u76f8\u540c\u7684\u6574\u6570\u5217\u8868\u3002
    • \n
    \n", "tags_en": ["Bit Manipulation", "Dynamic Programming"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numberWays(vector>& hats) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numberWays(List> hats) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numberWays(self, hats):\n \"\"\"\n :type hats: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numberWays(self, hats: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numberWays(int** hats, int hatsSize, int* hatsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumberWays(IList> hats) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} hats\n * @return {number}\n */\nvar numberWays = function(hats) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} hats\n# @return {Integer}\ndef number_ways(hats)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numberWays(_ hats: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numberWays(hats [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numberWays(hats: List[List[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numberWays(hats: List>): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn number_ways(hats: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $hats\n * @return Integer\n */\n function numberWays($hats) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numberWays(hats: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (number-ways hats)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1434](https://leetcode-cn.com/problems/number-of-ways-to-wear-different-hats-to-each-other)", "[\u6bcf\u4e2a\u4eba\u6234\u4e0d\u540c\u5e3d\u5b50\u7684\u65b9\u6848\u6570](/solution/1400-1499/1434.Number%20of%20Ways%20to%20Wear%20Different%20Hats%20to%20Each%20Other/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1434](https://leetcode.com/problems/number-of-ways-to-wear-different-hats-to-each-other)", "[Number of Ways to Wear Different Hats to Each Other](/solution/1400-1499/1434.Number%20of%20Ways%20to%20Wear%20Different%20Hats%20to%20Each%20Other/README_EN.md)", "`Bit Manipulation`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "1530", "frontend_question_id": "1433", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/check-if-a-string-can-break-another-string", "url_en": "https://leetcode.com/problems/check-if-a-string-can-break-another-string", "relative_path_cn": "/solution/1400-1499/1433.Check%20If%20a%20String%20Can%20Break%20Another%20String/README.md", "relative_path_en": "/solution/1400-1499/1433.Check%20If%20a%20String%20Can%20Break%20Another%20String/README_EN.md", "title_cn": "\u68c0\u67e5\u4e00\u4e2a\u5b57\u7b26\u4e32\u662f\u5426\u53ef\u4ee5\u6253\u7834\u53e6\u4e00\u4e2a\u5b57\u7b26\u4e32", "title_en": "Check If a String Can Break Another String", "question_title_slug": "check-if-a-string-can-break-another-string", "content_en": "

    Given two strings: s1 and s2 with the same size, check if some permutation of string s1 can break some permutation of string s2 or vice-versa. In other words s2 can break s1 or vice-versa.

    \n\n

    A string x can break string y (both of size n) if x[i] >= y[i] (in alphabetical order) for all i between 0 and n-1.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s1 = "abc", s2 = "xya"\nOutput: true\nExplanation: "ayx" is a permutation of s2="xya" which can break to string "abc" which is a permutation of s1="abc".\n
    \n\n

    Example 2:

    \n\n
    \nInput: s1 = "abe", s2 = "acd"\nOutput: false \nExplanation: All permutations for s1="abe" are: "abe", "aeb", "bae", "bea", "eab" and "eba" and all permutation for s2="acd" are: "acd", "adc", "cad", "cda", "dac" and "dca". However, there is not any permutation from s1 which can break some permutation from s2 and vice-versa.\n
    \n\n

    Example 3:

    \n\n
    \nInput: s1 = "leetcodee", s2 = "interview"\nOutput: true\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • s1.length == n
    • \n\t
    • s2.length == n
    • \n\t
    • 1 <= n <= 10^5
    • \n\t
    • All strings consist of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u5b57\u7b26\u4e32 s1 \u548c s2 \uff0c\u5b83\u4eec\u957f\u5ea6\u76f8\u7b49\uff0c\u8bf7\u4f60\u68c0\u67e5\u662f\u5426\u5b58\u5728\u4e00\u4e2a s1  \u7684\u6392\u5217\u53ef\u4ee5\u6253\u7834 s2 \u7684\u4e00\u4e2a\u6392\u5217\uff0c\u6216\u8005\u662f\u5426\u5b58\u5728\u4e00\u4e2a s2 \u7684\u6392\u5217\u53ef\u4ee5\u6253\u7834 s1 \u7684\u4e00\u4e2a\u6392\u5217\u3002

    \n\n

    \u5b57\u7b26\u4e32 x \u53ef\u4ee5\u6253\u7834\u5b57\u7b26\u4e32 y \uff08\u4e24\u8005\u957f\u5ea6\u90fd\u4e3a n \uff09\u9700\u6ee1\u8db3\u5bf9\u4e8e\u6240\u6709 i\uff08\u5728 0 \u5230 n - 1 \u4e4b\u95f4\uff09\u90fd\u6709 x[i] >= y[i]\uff08\u5b57\u5178\u5e8f\u610f\u4e49\u4e0b\u7684\u987a\u5e8f\uff09\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1as1 = "abc", s2 = "xya"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a"ayx" \u662f s2="xya" \u7684\u4e00\u4e2a\u6392\u5217\uff0c"abc" \u662f\u5b57\u7b26\u4e32 s1="abc" \u7684\u4e00\u4e2a\u6392\u5217\uff0c\u4e14 "ayx" \u53ef\u4ee5\u6253\u7834 "abc" \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1as1 = "abe", s2 = "acd"\n\u8f93\u51fa\uff1afalse \n\u89e3\u91ca\uff1as1="abe" \u7684\u6240\u6709\u6392\u5217\u5305\u62ec\uff1a"abe"\uff0c"aeb"\uff0c"bae"\uff0c"bea"\uff0c"eab" \u548c "eba" \uff0cs2="acd" \u7684\u6240\u6709\u6392\u5217\u5305\u62ec\uff1a"acd"\uff0c"adc"\uff0c"cad"\uff0c"cda"\uff0c"dac" \u548c "dca"\u3002\u7136\u800c\u6ca1\u6709\u4efb\u4f55 s1 \u7684\u6392\u5217\u53ef\u4ee5\u6253\u7834 s2 \u7684\u6392\u5217\u3002\u4e5f\u6ca1\u6709 s2 \u7684\u6392\u5217\u80fd\u6253\u7834 s1 \u7684\u6392\u5217\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1as1 = "leetcodee", s2 = "interview"\n\u8f93\u51fa\uff1atrue\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • s1.length == n
    • \n\t
    • s2.length == n
    • \n\t
    • 1 <= n <= 10^5
    • \n\t
    • \u6240\u6709\u5b57\u7b26\u4e32\u90fd\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    • \n
    \n", "tags_en": ["Greedy", "String"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool checkIfCanBreak(string s1, string s2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean checkIfCanBreak(String s1, String s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def checkIfCanBreak(self, s1, s2):\n \"\"\"\n :type s1: str\n :type s2: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def checkIfCanBreak(self, s1: str, s2: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool checkIfCanBreak(char * s1, char * s2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CheckIfCanBreak(string s1, string s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s1\n * @param {string} s2\n * @return {boolean}\n */\nvar checkIfCanBreak = function(s1, s2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s1\n# @param {String} s2\n# @return {Boolean}\ndef check_if_can_break(s1, s2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func checkIfCanBreak(_ s1: String, _ s2: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func checkIfCanBreak(s1 string, s2 string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def checkIfCanBreak(s1: String, s2: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun checkIfCanBreak(s1: String, s2: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn check_if_can_break(s1: String, s2: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s1\n * @param String $s2\n * @return Boolean\n */\n function checkIfCanBreak($s1, $s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function checkIfCanBreak(s1: string, s2: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (check-if-can-break s1 s2)\n (-> string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1433](https://leetcode-cn.com/problems/check-if-a-string-can-break-another-string)", "[\u68c0\u67e5\u4e00\u4e2a\u5b57\u7b26\u4e32\u662f\u5426\u53ef\u4ee5\u6253\u7834\u53e6\u4e00\u4e2a\u5b57\u7b26\u4e32](/solution/1400-1499/1433.Check%20If%20a%20String%20Can%20Break%20Another%20String/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1433](https://leetcode.com/problems/check-if-a-string-can-break-another-string)", "[Check If a String Can Break Another String](/solution/1400-1499/1433.Check%20If%20a%20String%20Can%20Break%20Another%20String/README_EN.md)", "`Greedy`,`String`", "Medium", ""]}, {"question_id": "1529", "frontend_question_id": "1432", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/max-difference-you-can-get-from-changing-an-integer", "url_en": "https://leetcode.com/problems/max-difference-you-can-get-from-changing-an-integer", "relative_path_cn": "/solution/1400-1499/1432.Max%20Difference%20You%20Can%20Get%20From%20Changing%20an%20Integer/README.md", "relative_path_en": "/solution/1400-1499/1432.Max%20Difference%20You%20Can%20Get%20From%20Changing%20an%20Integer/README_EN.md", "title_cn": "\u6539\u53d8\u4e00\u4e2a\u6574\u6570\u80fd\u5f97\u5230\u7684\u6700\u5927\u5dee\u503c", "title_en": "Max Difference You Can Get From Changing an Integer", "question_title_slug": "max-difference-you-can-get-from-changing-an-integer", "content_en": "

    You are given an integer num. You will apply the following steps exactly two times:

    \n\n
      \n\t
    • Pick a digit x (0 <= x <= 9).
    • \n\t
    • Pick another digit y (0 <= y <= 9). The digit y can be equal to x.
    • \n\t
    • Replace all the occurrences of x in the decimal representation of num by y.
    • \n\t
    • The new integer cannot have any leading zeros, also the new integer cannot be 0.
    • \n
    \n\n

    Let a and b be the results of applying the operations to num the first and second times, respectively.

    \n\n

    Return the max difference between a and b.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: num = 555\nOutput: 888\nExplanation: The first time pick x = 5 and y = 9 and store the new integer in a.\nThe second time pick x = 5 and y = 1 and store the new integer in b.\nWe have now a = 999 and b = 111 and max difference = 888\n
    \n\n

    Example 2:

    \n\n
    \nInput: num = 9\nOutput: 8\nExplanation: The first time pick x = 9 and y = 9 and store the new integer in a.\nThe second time pick x = 9 and y = 1 and store the new integer in b.\nWe have now a = 9 and b = 1 and max difference = 8\n
    \n\n

    Example 3:

    \n\n
    \nInput: num = 123456\nOutput: 820000\n
    \n\n

    Example 4:

    \n\n
    \nInput: num = 10000\nOutput: 80000\n
    \n\n

    Example 5:

    \n\n
    \nInput: num = 9288\nOutput: 8700\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= num <= 10^8
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 num \u3002\u4f60\u53ef\u4ee5\u5bf9\u5b83\u8fdb\u884c\u5982\u4e0b\u6b65\u9aa4\u6070\u597d \u4e24\u6b21 \uff1a

    \n\n
      \n\t
    • \u9009\u62e9\u4e00\u4e2a\u6570\u5b57 x (0 <= x <= 9).
    • \n\t
    • \u9009\u62e9\u53e6\u4e00\u4e2a\u6570\u5b57 y (0 <= y <= 9) \u3002\u6570\u5b57 y \u53ef\u4ee5\u7b49\u4e8e x \u3002
    • \n\t
    • \u5c06 num \u4e2d\u6240\u6709\u51fa\u73b0 x \u7684\u6570\u4f4d\u90fd\u7528 y \u66ff\u6362\u3002
    • \n\t
    • \u5f97\u5230\u7684\u65b0\u7684\u6574\u6570 \u4e0d\u80fd \u6709\u524d\u5bfc 0 \uff0c\u5f97\u5230\u7684\u65b0\u6574\u6570\u4e5f \u4e0d\u80fd \u662f 0 \u3002
    • \n
    \n\n

    \u4ee4\u4e24\u6b21\u5bf9 num \u7684\u64cd\u4f5c\u5f97\u5230\u7684\u7ed3\u679c\u5206\u522b\u4e3a a \u548c b \u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de a \u548c b \u7684 \u6700\u5927\u5dee\u503c \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anum = 555\n\u8f93\u51fa\uff1a888\n\u89e3\u91ca\uff1a\u7b2c\u4e00\u6b21\u9009\u62e9 x = 5 \u4e14 y = 9 \uff0c\u5e76\u628a\u5f97\u5230\u7684\u65b0\u6570\u5b57\u4fdd\u5b58\u5728 a \u4e2d\u3002\n\u7b2c\u4e8c\u6b21\u9009\u62e9 x = 5 \u4e14 y = 1 \uff0c\u5e76\u628a\u5f97\u5230\u7684\u65b0\u6570\u5b57\u4fdd\u5b58\u5728 b \u4e2d\u3002\n\u73b0\u5728\uff0c\u6211\u4eec\u6709 a = 999 \u548c b = 111 \uff0c\u6700\u5927\u5dee\u503c\u4e3a 888\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anum = 9\n\u8f93\u51fa\uff1a8\n\u89e3\u91ca\uff1a\u7b2c\u4e00\u6b21\u9009\u62e9 x = 9 \u4e14 y = 9 \uff0c\u5e76\u628a\u5f97\u5230\u7684\u65b0\u6570\u5b57\u4fdd\u5b58\u5728 a \u4e2d\u3002\n\u7b2c\u4e8c\u6b21\u9009\u62e9 x = 9 \u4e14 y = 1 \uff0c\u5e76\u628a\u5f97\u5230\u7684\u65b0\u6570\u5b57\u4fdd\u5b58\u5728 b \u4e2d\u3002\n\u73b0\u5728\uff0c\u6211\u4eec\u6709 a = 9 \u548c b = 1 \uff0c\u6700\u5927\u5dee\u503c\u4e3a 8\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1anum = 123456\n\u8f93\u51fa\uff1a820000\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1anum = 10000\n\u8f93\u51fa\uff1a80000\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1anum = 9288\n\u8f93\u51fa\uff1a8700\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= num <= 10^8
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxDiff(int num) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxDiff(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxDiff(self, num):\n \"\"\"\n :type num: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxDiff(self, num: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxDiff(int num){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxDiff(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} num\n * @return {number}\n */\nvar maxDiff = function(num) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} num\n# @return {Integer}\ndef max_diff(num)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxDiff(_ num: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxDiff(num int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxDiff(num: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxDiff(num: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_diff(num: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $num\n * @return Integer\n */\n function maxDiff($num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxDiff(num: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-diff num)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1432](https://leetcode-cn.com/problems/max-difference-you-can-get-from-changing-an-integer)", "[\u6539\u53d8\u4e00\u4e2a\u6574\u6570\u80fd\u5f97\u5230\u7684\u6700\u5927\u5dee\u503c](/solution/1400-1499/1432.Max%20Difference%20You%20Can%20Get%20From%20Changing%20an%20Integer/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1432](https://leetcode.com/problems/max-difference-you-can-get-from-changing-an-integer)", "[Max Difference You Can Get From Changing an Integer](/solution/1400-1499/1432.Max%20Difference%20You%20Can%20Get%20From%20Changing%20an%20Integer/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "1528", "frontend_question_id": "1431", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/kids-with-the-greatest-number-of-candies", "url_en": "https://leetcode.com/problems/kids-with-the-greatest-number-of-candies", "relative_path_cn": "/solution/1400-1499/1431.Kids%20With%20the%20Greatest%20Number%20of%20Candies/README.md", "relative_path_en": "/solution/1400-1499/1431.Kids%20With%20the%20Greatest%20Number%20of%20Candies/README_EN.md", "title_cn": "\u62e5\u6709\u6700\u591a\u7cd6\u679c\u7684\u5b69\u5b50", "title_en": "Kids With the Greatest Number of Candies", "question_title_slug": "kids-with-the-greatest-number-of-candies", "content_en": "

    Given the array candies and the integer extraCandies, where candies[i] represents the number of candies that the ith kid has.

    \n\n

    For each kid check if there is a way to distribute extraCandies among the kids such that he or she can have the greatest number of candies among them. Notice that multiple kids can have the greatest number of candies.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: candies = [2,3,5,1,3], extraCandies = 3\nOutput: [true,true,true,false,true] \nExplanation: \nKid 1 has 2 candies and if he or she receives all extra candies (3) will have 5 candies --- the greatest number of candies among the kids. \nKid 2 has 3 candies and if he or she receives at least 2 extra candies will have the greatest number of candies among the kids. \nKid 3 has 5 candies and this is already the greatest number of candies among the kids. \nKid 4 has 1 candy and even if he or she receives all extra candies will only have 4 candies. \nKid 5 has 3 candies and if he or she receives at least 2 extra candies will have the greatest number of candies among the kids. \n
    \n\n

    Example 2:

    \n\n
    \nInput: candies = [4,2,1,1,2], extraCandies = 1\nOutput: [true,false,false,false,false] \nExplanation: There is only 1 extra candy, therefore only kid 1 will have the greatest number of candies among the kids regardless of who takes the extra candy.\n
    \n\n

    Example 3:

    \n\n
    \nInput: candies = [12,1,12], extraCandies = 10\nOutput: [true,false,true]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= candies.length <= 100
    • \n\t
    • 1 <= candies[i] <= 100
    • \n\t
    • 1 <= extraCandies <= 50
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 candies \u548c\u4e00\u4e2a\u6574\u6570 extraCandies \uff0c\u5176\u4e2d candies[i] \u4ee3\u8868\u7b2c i \u4e2a\u5b69\u5b50\u62e5\u6709\u7684\u7cd6\u679c\u6570\u76ee\u3002

    \n\n

    \u5bf9\u6bcf\u4e00\u4e2a\u5b69\u5b50\uff0c\u68c0\u67e5\u662f\u5426\u5b58\u5728\u4e00\u79cd\u65b9\u6848\uff0c\u5c06\u989d\u5916\u7684 extraCandies \u4e2a\u7cd6\u679c\u5206\u914d\u7ed9\u5b69\u5b50\u4eec\u4e4b\u540e\uff0c\u6b64\u5b69\u5b50\u6709 \u6700\u591a \u7684\u7cd6\u679c\u3002\u6ce8\u610f\uff0c\u5141\u8bb8\u6709\u591a\u4e2a\u5b69\u5b50\u540c\u65f6\u62e5\u6709 \u6700\u591a \u7684\u7cd6\u679c\u6570\u76ee\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1acandies = [2,3,5,1,3], extraCandies = 3\n\u8f93\u51fa\uff1a[true,true,true,false,true] \n\u89e3\u91ca\uff1a\n\u5b69\u5b50 1 \u6709 2 \u4e2a\u7cd6\u679c\uff0c\u5982\u679c\u4ed6\u5f97\u5230\u6240\u6709\u989d\u5916\u7684\u7cd6\u679c\uff083\u4e2a\uff09\uff0c\u90a3\u4e48\u4ed6\u603b\u5171\u6709 5 \u4e2a\u7cd6\u679c\uff0c\u4ed6\u5c06\u6210\u4e3a\u62e5\u6709\u6700\u591a\u7cd6\u679c\u7684\u5b69\u5b50\u3002\n\u5b69\u5b50 2 \u6709 3 \u4e2a\u7cd6\u679c\uff0c\u5982\u679c\u4ed6\u5f97\u5230\u81f3\u5c11 2 \u4e2a\u989d\u5916\u7cd6\u679c\uff0c\u90a3\u4e48\u4ed6\u5c06\u6210\u4e3a\u62e5\u6709\u6700\u591a\u7cd6\u679c\u7684\u5b69\u5b50\u3002\n\u5b69\u5b50 3 \u6709 5 \u4e2a\u7cd6\u679c\uff0c\u4ed6\u5df2\u7ecf\u662f\u62e5\u6709\u6700\u591a\u7cd6\u679c\u7684\u5b69\u5b50\u3002\n\u5b69\u5b50 4 \u6709 1 \u4e2a\u7cd6\u679c\uff0c\u5373\u4f7f\u4ed6\u5f97\u5230\u6240\u6709\u989d\u5916\u7684\u7cd6\u679c\uff0c\u4ed6\u4e5f\u53ea\u6709 4 \u4e2a\u7cd6\u679c\uff0c\u65e0\u6cd5\u6210\u4e3a\u62e5\u6709\u7cd6\u679c\u6700\u591a\u7684\u5b69\u5b50\u3002\n\u5b69\u5b50 5 \u6709 3 \u4e2a\u7cd6\u679c\uff0c\u5982\u679c\u4ed6\u5f97\u5230\u81f3\u5c11 2 \u4e2a\u989d\u5916\u7cd6\u679c\uff0c\u90a3\u4e48\u4ed6\u5c06\u6210\u4e3a\u62e5\u6709\u6700\u591a\u7cd6\u679c\u7684\u5b69\u5b50\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1acandies = [4,2,1,1,2], extraCandies = 1\n\u8f93\u51fa\uff1a[true,false,false,false,false] \n\u89e3\u91ca\uff1a\u53ea\u6709 1 \u4e2a\u989d\u5916\u7cd6\u679c\uff0c\u6240\u4ee5\u4e0d\u7ba1\u989d\u5916\u7cd6\u679c\u7ed9\u8c01\uff0c\u53ea\u6709\u5b69\u5b50 1 \u53ef\u4ee5\u6210\u4e3a\u62e5\u6709\u7cd6\u679c\u6700\u591a\u7684\u5b69\u5b50\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1acandies = [12,1,12], extraCandies = 10\n\u8f93\u51fa\uff1a[true,false,true]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= candies.length <= 100
    • \n\t
    • 1 <= candies[i] <= 100
    • \n\t
    • 1 <= extraCandies <= 50
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector kidsWithCandies(vector& candies, int extraCandies) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List kidsWithCandies(int[] candies, int extraCandies) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def kidsWithCandies(self, candies, extraCandies):\n \"\"\"\n :type candies: List[int]\n :type extraCandies: int\n :rtype: List[bool]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def kidsWithCandies(self, candies: List[int], extraCandies: int) -> List[bool]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nbool* kidsWithCandies(int* candies, int candiesSize, int extraCandies, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList KidsWithCandies(int[] candies, int extraCandies) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} candies\n * @param {number} extraCandies\n * @return {boolean[]}\n */\nvar kidsWithCandies = function(candies, extraCandies) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} candies\n# @param {Integer} extra_candies\n# @return {Boolean[]}\ndef kids_with_candies(candies, extra_candies)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func kidsWithCandies(_ candies: [Int], _ extraCandies: Int) -> [Bool] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func kidsWithCandies(candies []int, extraCandies int) []bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def kidsWithCandies(candies: Array[Int], extraCandies: Int): List[Boolean] = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun kidsWithCandies(candies: IntArray, extraCandies: Int): List {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn kids_with_candies(candies: Vec, extra_candies: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $candies\n * @param Integer $extraCandies\n * @return Boolean[]\n */\n function kidsWithCandies($candies, $extraCandies) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function kidsWithCandies(candies: number[], extraCandies: number): boolean[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (kids-with-candies candies extraCandies)\n (-> (listof exact-integer?) exact-integer? (listof boolean?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1431](https://leetcode-cn.com/problems/kids-with-the-greatest-number-of-candies)", "[\u62e5\u6709\u6700\u591a\u7cd6\u679c\u7684\u5b69\u5b50](/solution/1400-1499/1431.Kids%20With%20the%20Greatest%20Number%20of%20Candies/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1431](https://leetcode.com/problems/kids-with-the-greatest-number-of-candies)", "[Kids With the Greatest Number of Candies](/solution/1400-1499/1431.Kids%20With%20the%20Greatest%20Number%20of%20Candies/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1527", "frontend_question_id": "1411", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-ways-to-paint-n-3-grid", "url_en": "https://leetcode.com/problems/number-of-ways-to-paint-n-3-grid", "relative_path_cn": "/solution/1400-1499/1411.Number%20of%20Ways%20to%20Paint%20N%20%C3%97%203%20Grid/README.md", "relative_path_en": "/solution/1400-1499/1411.Number%20of%20Ways%20to%20Paint%20N%20%C3%97%203%20Grid/README_EN.md", "title_cn": "\u7ed9 N x 3 \u7f51\u683c\u56fe\u6d82\u8272\u7684\u65b9\u6848\u6570", "title_en": "Number of Ways to Paint N \u00d7 3 Grid", "question_title_slug": "number-of-ways-to-paint-n-3-grid", "content_en": "

    You have a grid of size n x 3 and you want to paint each cell of the grid with exactly one of the three colors: Red, Yellow, or Green while making sure that no two adjacent cells have the same color (i.e., no two cells that share vertical or horizontal sides have the same color).

    \n\n

    Given n the number of rows of the grid, return the number of ways you can paint this grid. As the answer may grow large, the answer must be computed modulo 109 + 7.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: n = 1\nOutput: 12\nExplanation: There are 12 possible way to paint the grid as shown.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 2\nOutput: 54\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 3\nOutput: 246\n
    \n\n

    Example 4:

    \n\n
    \nInput: n = 7\nOutput: 106494\n
    \n\n

    Example 5:

    \n\n
    \nInput: n = 5000\nOutput: 30228214\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == grid.length
    • \n\t
    • grid[i].length == 3
    • \n\t
    • 1 <= n <= 5000
    • \n
    \n", "content_cn": "

    \u4f60\u6709\u4e00\u4e2a n x 3 \u7684\u7f51\u683c\u56fe grid \uff0c\u4f60\u9700\u8981\u7528 \u7ea2\uff0c\u9ec4\uff0c\u7eff \u4e09\u79cd\u989c\u8272\u4e4b\u4e00\u7ed9\u6bcf\u4e00\u4e2a\u683c\u5b50\u4e0a\u8272\uff0c\u4e14\u786e\u4fdd\u76f8\u90bb\u683c\u5b50\u989c\u8272\u4e0d\u540c\uff08\u4e5f\u5c31\u662f\u6709\u76f8\u540c\u6c34\u5e73\u8fb9\u6216\u8005\u5782\u76f4\u8fb9\u7684\u683c\u5b50\u989c\u8272\u4e0d\u540c\uff09\u3002

    \n\n

    \u7ed9\u4f60\u7f51\u683c\u56fe\u7684\u884c\u6570 n \u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u7ed9 grid \u6d82\u8272\u7684\u65b9\u6848\u6570\u3002\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u4f1a\u975e\u5e38\u5927\uff0c\u8bf7\u4f60\u8fd4\u56de\u7b54\u6848\u5bf9 10^9 + 7 \u53d6\u4f59\u7684\u7ed3\u679c\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1a12\n\u89e3\u91ca\uff1a\u603b\u5171\u6709 12 \u79cd\u53ef\u884c\u7684\u65b9\u6cd5\uff1a\n\"\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1an = 2\n\u8f93\u51fa\uff1a54\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1an = 3\n\u8f93\u51fa\uff1a246\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1an = 7\n\u8f93\u51fa\uff1a106494\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1an = 5000\n\u8f93\u51fa\uff1a30228214\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == grid.length
    • \n\t
    • grid[i].length == 3
    • \n\t
    • 1 <= n <= 5000
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numOfWays(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numOfWays(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numOfWays(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numOfWays(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numOfWays(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumOfWays(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar numOfWays = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef num_of_ways(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numOfWays(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numOfWays(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numOfWays(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numOfWays(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_of_ways(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function numOfWays($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numOfWays(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-of-ways n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1411](https://leetcode-cn.com/problems/number-of-ways-to-paint-n-3-grid)", "[\u7ed9 N x 3 \u7f51\u683c\u56fe\u6d82\u8272\u7684\u65b9\u6848\u6570](/solution/1400-1499/1411.Number%20of%20Ways%20to%20Paint%20N%20%C3%97%203%20Grid/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1411](https://leetcode.com/problems/number-of-ways-to-paint-n-3-grid)", "[Number of Ways to Paint N \u00d7 3 Grid](/solution/1400-1499/1411.Number%20of%20Ways%20to%20Paint%20N%20%C3%97%203%20Grid/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1526", "frontend_question_id": "1410", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/html-entity-parser", "url_en": "https://leetcode.com/problems/html-entity-parser", "relative_path_cn": "/solution/1400-1499/1410.HTML%20Entity%20Parser/README.md", "relative_path_en": "/solution/1400-1499/1410.HTML%20Entity%20Parser/README_EN.md", "title_cn": "HTML \u5b9e\u4f53\u89e3\u6790\u5668", "title_en": "HTML Entity Parser", "question_title_slug": "html-entity-parser", "content_en": "

    HTML entity parser is the parser that takes HTML code as input and replace all the entities of the special characters by the characters itself.

    \n\n

    The special characters and their entities for HTML are:

    \n\n
      \n\t
    • Quotation Mark: the entity is &quot; and symbol character is ".
    • \n\t
    • Single Quote Mark: the entity is &apos; and symbol character is '.
    • \n\t
    • Ampersand: the entity is &amp; and symbol character is &.
    • \n\t
    • Greater Than Sign: the entity is &gt; and symbol character is >.
    • \n\t
    • Less Than Sign: the entity is &lt; and symbol character is <.
    • \n\t
    • Slash: the entity is &frasl; and symbol character is /.
    • \n
    \n\n

    Given the input text string to the HTML parser, you have to implement the entity parser.

    \n\n

    Return the text after replacing the entities by the special characters.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: text = "&amp; is an HTML entity but &ambassador; is not."\nOutput: "& is an HTML entity but &ambassador; is not."\nExplanation: The parser will replace the &amp; entity by &\n
    \n\n

    Example 2:

    \n\n
    \nInput: text = "and I quote: &quot;...&quot;"\nOutput: "and I quote: \\"...\\""\n
    \n\n

    Example 3:

    \n\n
    \nInput: text = "Stay home! Practice on Leetcode :)"\nOutput: "Stay home! Practice on Leetcode :)"\n
    \n\n

    Example 4:

    \n\n
    \nInput: text = "x &gt; y &amp;&amp; x &lt; y is always false"\nOutput: "x > y && x < y is always false"\n
    \n\n

    Example 5:

    \n\n
    \nInput: text = "leetcode.com&frasl;problemset&frasl;all"\nOutput: "leetcode.com/problemset/all"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= text.length <= 10^5
    • \n\t
    • The string may contain any possible characters out of all the 256 ASCII characters.
    • \n
    \n", "content_cn": "

    \u300cHTML \u5b9e\u4f53\u89e3\u6790\u5668\u300d \u662f\u4e00\u79cd\u7279\u6b8a\u7684\u89e3\u6790\u5668\uff0c\u5b83\u5c06 HTML \u4ee3\u7801\u4f5c\u4e3a\u8f93\u5165\uff0c\u5e76\u7528\u5b57\u7b26\u672c\u8eab\u66ff\u6362\u6389\u6240\u6709\u8fd9\u4e9b\u7279\u6b8a\u7684\u5b57\u7b26\u5b9e\u4f53\u3002

    \n\n

    HTML \u91cc\u8fd9\u4e9b\u7279\u6b8a\u5b57\u7b26\u548c\u5b83\u4eec\u5bf9\u5e94\u7684\u5b57\u7b26\u5b9e\u4f53\u5305\u62ec\uff1a

    \n\n
      \n\t
    • \u53cc\u5f15\u53f7\uff1a\u5b57\u7b26\u5b9e\u4f53\u4e3a &quot; \uff0c\u5bf9\u5e94\u7684\u5b57\u7b26\u662f " \u3002
    • \n\t
    • \u5355\u5f15\u53f7\uff1a\u5b57\u7b26\u5b9e\u4f53\u4e3a &apos; \uff0c\u5bf9\u5e94\u7684\u5b57\u7b26\u662f ' \u3002
    • \n\t
    • \u4e0e\u7b26\u53f7\uff1a\u5b57\u7b26\u5b9e\u4f53\u4e3a &amp; \uff0c\u5bf9\u5e94\u5bf9\u7684\u5b57\u7b26\u662f & \u3002
    • \n\t
    • \u5927\u4e8e\u53f7\uff1a\u5b57\u7b26\u5b9e\u4f53\u4e3a &gt; \uff0c\u5bf9\u5e94\u7684\u5b57\u7b26\u662f > \u3002
    • \n\t
    • \u5c0f\u4e8e\u53f7\uff1a\u5b57\u7b26\u5b9e\u4f53\u4e3a &lt; \uff0c\u5bf9\u5e94\u7684\u5b57\u7b26\u662f < \u3002
    • \n\t
    • \u659c\u7ebf\u53f7\uff1a\u5b57\u7b26\u5b9e\u4f53\u4e3a &frasl; \uff0c\u5bf9\u5e94\u7684\u5b57\u7b26\u662f / \u3002
    • \n
    \n\n

    \u7ed9\u4f60\u8f93\u5165\u5b57\u7b26\u4e32 text \uff0c\u8bf7\u4f60\u5b9e\u73b0\u4e00\u4e2a HTML \u5b9e\u4f53\u89e3\u6790\u5668\uff0c\u8fd4\u56de\u89e3\u6790\u5668\u89e3\u6790\u540e\u7684\u7ed3\u679c\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1atext = "&amp; is an HTML entity but &ambassador; is not."\n\u8f93\u51fa\uff1a"& is an HTML entity but &ambassador; is not."\n\u89e3\u91ca\uff1a\u89e3\u6790\u5668\u628a\u5b57\u7b26\u5b9e\u4f53 &amp; \u7528 & \u66ff\u6362\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1atext = "and I quote: &quot;...&quot;"\n\u8f93\u51fa\uff1a"and I quote: \\"...\\""\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1atext = "Stay home! Practice on Leetcode :)"\n\u8f93\u51fa\uff1a"Stay home! Practice on Leetcode :)"\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1atext = "x &gt; y &amp;&amp; x &lt; y is always false"\n\u8f93\u51fa\uff1a"x > y && x < y is always false"\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1atext = "leetcode.com&frasl;problemset&frasl;all"\n\u8f93\u51fa\uff1a"leetcode.com/problemset/all"\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= text.length <= 10^5
    • \n\t
    • \u5b57\u7b26\u4e32\u53ef\u80fd\u5305\u542b 256 \u4e2aASCII \u5b57\u7b26\u4e2d\u7684\u4efb\u610f\u5b57\u7b26\u3002
    • \n
    \n", "tags_en": ["Stack", "String"], "tags_cn": ["\u6808", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string entityParser(string text) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String entityParser(String text) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def entityParser(self, text):\n \"\"\"\n :type text: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def entityParser(self, text: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * entityParser(char * text){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string EntityParser(string text) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} text\n * @return {string}\n */\nvar entityParser = function(text) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} text\n# @return {String}\ndef entity_parser(text)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func entityParser(_ text: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func entityParser(text string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def entityParser(text: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun entityParser(text: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn entity_parser(text: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $text\n * @return String\n */\n function entityParser($text) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function entityParser(text: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (entity-parser text)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1410](https://leetcode-cn.com/problems/html-entity-parser)", "[HTML \u5b9e\u4f53\u89e3\u6790\u5668](/solution/1400-1499/1410.HTML%20Entity%20Parser/README.md)", "`\u6808`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1410](https://leetcode.com/problems/html-entity-parser)", "[HTML Entity Parser](/solution/1400-1499/1410.HTML%20Entity%20Parser/README_EN.md)", "`Stack`,`String`", "Medium", ""]}, {"question_id": "1525", "frontend_question_id": "1409", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/queries-on-a-permutation-with-key", "url_en": "https://leetcode.com/problems/queries-on-a-permutation-with-key", "relative_path_cn": "/solution/1400-1499/1409.Queries%20on%20a%20Permutation%20With%20Key/README.md", "relative_path_en": "/solution/1400-1499/1409.Queries%20on%20a%20Permutation%20With%20Key/README_EN.md", "title_cn": "\u67e5\u8be2\u5e26\u952e\u7684\u6392\u5217", "title_en": "Queries on a Permutation With Key", "question_title_slug": "queries-on-a-permutation-with-key", "content_en": "

    Given the array queries of positive integers between 1 and m, you have to process all queries[i] (from i=0 to i=queries.length-1) according to the following rules:

    \r\n\r\n
      \r\n\t
    • In the beginning, you have the permutation P=[1,2,3,...,m].
    • \r\n\t
    • For the current i, find the position of queries[i] in the permutation P (indexing from 0) and then move this at the beginning of the permutation P. Notice that the position of queries[i] in P is the result for queries[i].
    • \r\n
    \r\n\r\n

    Return an array containing the result for the given queries.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: queries = [3,1,2,1], m = 5\r\nOutput: [2,1,2,1] \r\nExplanation: The queries are processed as follow: \r\nFor i=0: queries[i]=3, P=[1,2,3,4,5], position of 3 in P is 2, then we move 3 to the beginning of P resulting in P=[3,1,2,4,5]. \r\nFor i=1: queries[i]=1, P=[3,1,2,4,5], position of 1 in P is 1, then we move 1 to the beginning of P resulting in P=[1,3,2,4,5]. \r\nFor i=2: queries[i]=2, P=[1,3,2,4,5], position of 2 in P is 2, then we move 2 to the beginning of P resulting in P=[2,1,3,4,5]. \r\nFor i=3: queries[i]=1, P=[2,1,3,4,5], position of 1 in P is 1, then we move 1 to the beginning of P resulting in P=[1,2,3,4,5]. \r\nTherefore, the array containing the result is [2,1,2,1].  \r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: queries = [4,1,2,2], m = 4\r\nOutput: [3,1,2,0]\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: queries = [7,5,5,8,3], m = 8\r\nOutput: [6,5,0,7,5]\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= m <= 10^3
    • \r\n\t
    • 1 <= queries.length <= m
    • \r\n\t
    • 1 <= queries[i] <= m
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5f85\u67e5\u6570\u7ec4 queries \uff0c\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u4e3a 1 \u5230 m \u4e4b\u95f4\u7684\u6b63\u6574\u6570\u3002 \u8bf7\u4f60\u6839\u636e\u4ee5\u4e0b\u89c4\u5219\u5904\u7406\u6240\u6709\u5f85\u67e5\u9879 queries[i]\uff08\u4ece i=0 \u5230 i=queries.length-1\uff09\uff1a

    \n\n
      \n\t
    • \u4e00\u5f00\u59cb\uff0c\u6392\u5217 P=[1,2,3,...,m]\u3002
    • \n\t
    • \u5bf9\u4e8e\u5f53\u524d\u7684 i \uff0c\u8bf7\u4f60\u627e\u51fa\u5f85\u67e5\u9879 queries[i] \u5728\u6392\u5217 P \u4e2d\u7684\u4f4d\u7f6e\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\uff0c\u7136\u540e\u5c06\u5176\u4ece\u539f\u4f4d\u7f6e\u79fb\u52a8\u5230\u6392\u5217 P \u7684\u8d77\u59cb\u4f4d\u7f6e\uff08\u5373\u4e0b\u6807\u4e3a 0 \u5904\uff09\u3002\u6ce8\u610f\uff0c queries[i] \u5728 P \u4e2d\u7684\u4f4d\u7f6e\u5c31\u662f queries[i] \u7684\u67e5\u8be2\u7ed3\u679c\u3002
    • \n
    \n\n

    \u8bf7\u4f60\u4ee5\u6570\u7ec4\u5f62\u5f0f\u8fd4\u56de\u5f85\u67e5\u6570\u7ec4  queries \u7684\u67e5\u8be2\u7ed3\u679c\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aqueries = [3,1,2,1], m = 5\n\u8f93\u51fa\uff1a[2,1,2,1] \n\u89e3\u91ca\uff1a\u5f85\u67e5\u6570\u7ec4 queries \u5904\u7406\u5982\u4e0b\uff1a\n\u5bf9\u4e8e i=0: queries[i]=3, P=[1,2,3,4,5], 3 \u5728 P \u4e2d\u7684\u4f4d\u7f6e\u662f 2\uff0c\u63a5\u7740\u6211\u4eec\u628a 3 \u79fb\u52a8\u5230 P \u7684\u8d77\u59cb\u4f4d\u7f6e\uff0c\u5f97\u5230 P=[3,1,2,4,5] \u3002\n\u5bf9\u4e8e i=1: queries[i]=1, P=[3,1,2,4,5], 1 \u5728 P \u4e2d\u7684\u4f4d\u7f6e\u662f 1\uff0c\u63a5\u7740\u6211\u4eec\u628a 1 \u79fb\u52a8\u5230 P \u7684\u8d77\u59cb\u4f4d\u7f6e\uff0c\u5f97\u5230 P=[1,3,2,4,5] \u3002 \n\u5bf9\u4e8e i=2: queries[i]=2, P=[1,3,2,4,5], 2 \u5728 P \u4e2d\u7684\u4f4d\u7f6e\u662f 2\uff0c\u63a5\u7740\u6211\u4eec\u628a 2 \u79fb\u52a8\u5230 P \u7684\u8d77\u59cb\u4f4d\u7f6e\uff0c\u5f97\u5230 P=[2,1,3,4,5] \u3002\n\u5bf9\u4e8e i=3: queries[i]=1, P=[2,1,3,4,5], 1 \u5728 P \u4e2d\u7684\u4f4d\u7f6e\u662f 1\uff0c\u63a5\u7740\u6211\u4eec\u628a 1 \u79fb\u52a8\u5230 P \u7684\u8d77\u59cb\u4f4d\u7f6e\uff0c\u5f97\u5230 P=[1,2,3,4,5] \u3002 \n\u56e0\u6b64\uff0c\u8fd4\u56de\u7684\u7ed3\u679c\u6570\u7ec4\u4e3a [2,1,2,1] \u3002  \n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aqueries = [4,1,2,2], m = 4\n\u8f93\u51fa\uff1a[3,1,2,0]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aqueries = [7,5,5,8,3], m = 8\n\u8f93\u51fa\uff1a[6,5,0,7,5]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= m <= 10^3
    • \n\t
    • 1 <= queries.length <= m
    • \n\t
    • 1 <= queries[i] <= m
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector processQueries(vector& queries, int m) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] processQueries(int[] queries, int m) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def processQueries(self, queries, m):\n \"\"\"\n :type queries: List[int]\n :type m: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def processQueries(self, queries: List[int], m: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* processQueries(int* queries, int queriesSize, int m, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] ProcessQueries(int[] queries, int m) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} queries\n * @param {number} m\n * @return {number[]}\n */\nvar processQueries = function(queries, m) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} queries\n# @param {Integer} m\n# @return {Integer[]}\ndef process_queries(queries, m)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func processQueries(_ queries: [Int], _ m: Int) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func processQueries(queries []int, m int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def processQueries(queries: Array[Int], m: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun processQueries(queries: IntArray, m: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn process_queries(queries: Vec, m: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $queries\n * @param Integer $m\n * @return Integer[]\n */\n function processQueries($queries, $m) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function processQueries(queries: number[], m: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (process-queries queries m)\n (-> (listof exact-integer?) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1409](https://leetcode-cn.com/problems/queries-on-a-permutation-with-key)", "[\u67e5\u8be2\u5e26\u952e\u7684\u6392\u5217](/solution/1400-1499/1409.Queries%20on%20a%20Permutation%20With%20Key/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1409](https://leetcode.com/problems/queries-on-a-permutation-with-key)", "[Queries on a Permutation With Key](/solution/1400-1499/1409.Queries%20on%20a%20Permutation%20With%20Key/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "1524", "frontend_question_id": "1408", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/string-matching-in-an-array", "url_en": "https://leetcode.com/problems/string-matching-in-an-array", "relative_path_cn": "/solution/1400-1499/1408.String%20Matching%20in%20an%20Array/README.md", "relative_path_en": "/solution/1400-1499/1408.String%20Matching%20in%20an%20Array/README_EN.md", "title_cn": "\u6570\u7ec4\u4e2d\u7684\u5b57\u7b26\u4e32\u5339\u914d", "title_en": "String Matching in an Array", "question_title_slug": "string-matching-in-an-array", "content_en": "

    Given an array of string words. Return all strings in words which is substring of another word in any order. 

    \r\n\r\n

    String words[i] is substring of words[j], if can be obtained removing some characters to left and/or right side of words[j].

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: words = ["mass","as","hero","superhero"]\r\nOutput: ["as","hero"]\r\nExplanation: "as" is substring of "mass" and "hero" is substring of "superhero".\r\n["hero","as"] is also a valid answer.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: words = ["leetcode","et","code"]\r\nOutput: ["et","code"]\r\nExplanation: "et", "code" are substring of "leetcode".\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: words = ["blue","green","bu"]\r\nOutput: []\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= words.length <= 100
    • \r\n\t
    • 1 <= words[i].length <= 30
    • \r\n\t
    • words[i] contains only lowercase English letters.
    • \r\n\t
    • It's guaranteed that words[i] will be unique.
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4 words \uff0c\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u5b57\u7b26\u4e32\u90fd\u53ef\u4ee5\u770b\u4f5c\u662f\u4e00\u4e2a\u5355\u8bcd\u3002\u8bf7\u4f60\u6309 \u4efb\u610f \u987a\u5e8f\u8fd4\u56de words \u4e2d\u662f\u5176\u4ed6\u5355\u8bcd\u7684\u5b50\u5b57\u7b26\u4e32\u7684\u6240\u6709\u5355\u8bcd\u3002

    \n\n

    \u5982\u679c\u4f60\u53ef\u4ee5\u5220\u9664 words[j] \u6700\u5de6\u4fa7\u548c/\u6216\u6700\u53f3\u4fa7\u7684\u82e5\u5e72\u5b57\u7b26\u5f97\u5230 word[i] \uff0c\u90a3\u4e48\u5b57\u7b26\u4e32 words[i] \u5c31\u662f words[j] \u7684\u4e00\u4e2a\u5b50\u5b57\u7b26\u4e32\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1awords = ["mass","as","hero","superhero"]\n\u8f93\u51fa\uff1a["as","hero"]\n\u89e3\u91ca\uff1a"as" \u662f "mass" \u7684\u5b50\u5b57\u7b26\u4e32\uff0c"hero" \u662f "superhero" \u7684\u5b50\u5b57\u7b26\u4e32\u3002\n["hero","as"] \u4e5f\u662f\u6709\u6548\u7684\u7b54\u6848\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1awords = ["leetcode","et","code"]\n\u8f93\u51fa\uff1a["et","code"]\n\u89e3\u91ca\uff1a"et" \u548c "code" \u90fd\u662f "leetcode" \u7684\u5b50\u5b57\u7b26\u4e32\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1awords = ["blue","green","bu"]\n\u8f93\u51fa\uff1a[]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= words.length <= 100
    • \n\t
    • 1 <= words[i].length <= 30
    • \n\t
    • words[i] \u4ec5\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    • \n\t
    • \u9898\u76ee\u6570\u636e \u4fdd\u8bc1 \u6bcf\u4e2a words[i] \u90fd\u662f\u72ec\u4e00\u65e0\u4e8c\u7684\u3002
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector stringMatching(vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List stringMatching(String[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def stringMatching(self, words):\n \"\"\"\n :type words: List[str]\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def stringMatching(self, words: List[str]) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** stringMatching(char ** words, int wordsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList StringMatching(string[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @return {string[]}\n */\nvar stringMatching = function(words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @return {String[]}\ndef string_matching(words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func stringMatching(_ words: [String]) -> [String] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func stringMatching(words []string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def stringMatching(words: Array[String]): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun stringMatching(words: Array): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn string_matching(words: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @return String[]\n */\n function stringMatching($words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function stringMatching(words: string[]): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (string-matching words)\n (-> (listof string?) (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1408](https://leetcode-cn.com/problems/string-matching-in-an-array)", "[\u6570\u7ec4\u4e2d\u7684\u5b57\u7b26\u4e32\u5339\u914d](/solution/1400-1499/1408.String%20Matching%20in%20an%20Array/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1408](https://leetcode.com/problems/string-matching-in-an-array)", "[String Matching in an Array](/solution/1400-1499/1408.String%20Matching%20in%20an%20Array/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1523", "frontend_question_id": "1393", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/capital-gainloss", "url_en": "https://leetcode.com/problems/capital-gainloss", "relative_path_cn": "/solution/1300-1399/1393.Capital%20GainLoss/README.md", "relative_path_en": "/solution/1300-1399/1393.Capital%20GainLoss/README_EN.md", "title_cn": "\u80a1\u7968\u7684\u8d44\u672c\u635f\u76ca", "title_en": "Capital GainLoss", "question_title_slug": "capital-gainloss", "content_en": "

    Table: Stocks

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| stock_name    | varchar |\n| operation     | enum    |\n| operation_day | int     |\n| price         | int     |\n+---------------+---------+\n(stock_name, operation_day) is the primary key for this table.\nThe operation column is an ENUM of type ('Sell', 'Buy')\nEach row of this table indicates that the stock which has stock_name had an operation on the day operation_day with the price.\nIt is guaranteed that each 'Sell' operation for a stock has a corresponding 'Buy' operation in a previous day.\n
    \n\n

     

    \n\n

    Write an SQL query to report the Capital gain/loss for each stock.

    \n\n

    The capital gain/loss of a stock is total gain or loss after buying and selling the stock one or many times.

    \n\n

    Return the result table in any order.

    \n\n

    The query result format is in the following example:

    \n\n

     

    \n\n
    \nStocks table:\n+---------------+-----------+---------------+--------+\n| stock_name    | operation | operation_day | price  |\n+---------------+-----------+---------------+--------+\n| Leetcode      | Buy       | 1             | 1000   |\n| Corona Masks  | Buy       | 2             | 10     |\n| Leetcode      | Sell      | 5             | 9000   |\n| Handbags      | Buy       | 17            | 30000  |\n| Corona Masks  | Sell      | 3             | 1010   |\n| Corona Masks  | Buy       | 4             | 1000   |\n| Corona Masks  | Sell      | 5             | 500    |\n| Corona Masks  | Buy       | 6             | 1000   |\n| Handbags      | Sell      | 29            | 7000   |\n| Corona Masks  | Sell      | 10            | 10000  |\n+---------------+-----------+---------------+--------+\n\nResult table:\n+---------------+-------------------+\n| stock_name    | capital_gain_loss |\n+---------------+-------------------+\n| Corona Masks  | 9500              |\n| Leetcode      | 8000              |\n| Handbags      | -23000            |\n+---------------+-------------------+\nLeetcode stock was bought at day 1 for 1000$ and was sold at day 5 for 9000$. Capital gain = 9000 - 1000 = 8000$.\nHandbags stock was bought at day 17 for 30000$ and was sold at day 29 for 7000$. Capital loss = 7000 - 30000 = -23000$.\nCorona Masks stock was bought at day 1 for 10$ and was sold at day 3 for 1010$. It was bought again at day 4 for 1000$ and was sold at day 5 for 500$. At last, it was bought at day 6 for 1000$ and was sold at day 10 for 10000$. Capital gain/loss is the sum of capital gains/losses for each ('Buy' --> 'Sell') operation = (1010 - 10) + (500 - 1000) + (10000 - 1000) = 1000 - 500 + 9000 = 9500$.\n\n
    \n", "content_cn": "

    Stocks \u8868\uff1a

    \n\n
    +---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| stock_name    | varchar |\n| operation     | enum    |\n| operation_day | int     |\n| price         | int     |\n+---------------+---------+\n(stock_name, day) \u662f\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\noperation \u5217\u4f7f\u7528\u7684\u662f\u4e00\u79cd\u679a\u4e3e\u7c7b\u578b\uff0c\u5305\u62ec\uff1a('Sell','Buy')\n\u6b64\u8868\u7684\u6bcf\u4e00\u884c\u4ee3\u8868\u4e86\u540d\u4e3a stock_name \u7684\u67d0\u652f\u80a1\u7968\u5728 operation_day \u8fd9\u4e00\u5929\u7684\u64cd\u4f5c\u4ef7\u683c\u3002\n\u4fdd\u8bc1\u80a1\u7968\u7684\u6bcf\u6b21'Sell'\u64cd\u4f5c\u524d\uff0c\u90fd\u6709\u76f8\u5e94\u7684'Buy'\u64cd\u4f5c\u3002\n
    \n\n

     

    \n\n

    \u7f16\u5199\u4e00\u4e2aSQL\u67e5\u8be2\u6765\u62a5\u544a\u6bcf\u652f\u80a1\u7968\u7684\u8d44\u672c\u635f\u76ca\u3002

    \n\n

    \u80a1\u7968\u7684\u8d44\u672c\u635f\u76ca\u662f\u4e00\u6b21\u6216\u591a\u6b21\u4e70\u5356\u80a1\u7968\u540e\u7684\u5168\u90e8\u6536\u76ca\u6216\u635f\u5931\u3002

    \n\n

    \u4ee5\u4efb\u610f\u987a\u5e8f\u8fd4\u56de\u7ed3\u679c\u5373\u53ef\u3002

    \n\n

    SQL\u67e5\u8be2\u7ed3\u679c\u7684\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a\uff1a

    \n\n
    Stocks \u8868:\n+---------------+-----------+---------------+--------+\n| stock_name    | operation | operation_day | price  |\n+---------------+-----------+---------------+--------+\n| Leetcode      | Buy       | 1             | 1000   |\n| Corona Masks  | Buy       | 2             | 10     |\n| Leetcode      | Sell      | 5             | 9000   |\n| Handbags      | Buy       | 17            | 30000  |\n| Corona Masks  | Sell      | 3             | 1010   |\n| Corona Masks  | Buy       | 4             | 1000   |\n| Corona Masks  | Sell      | 5             | 500    |\n| Corona Masks  | Buy       | 6             | 1000   |\n| Handbags      | Sell      | 29            | 7000   |\n| Corona Masks  | Sell      | 10            | 10000  |\n+---------------+-----------+---------------+--------+\n\nResult \u8868:\n+---------------+-------------------+\n| stock_name    | capital_gain_loss |\n+---------------+-------------------+\n| Corona Masks  | 9500              |\n| Leetcode      | 8000              |\n| Handbags      | -23000            |\n+---------------+-------------------+\nLeetcode \u80a1\u7968\u5728\u7b2c\u4e00\u5929\u4ee51000\u7f8e\u5143\u7684\u4ef7\u683c\u4e70\u5165\uff0c\u5728\u7b2c\u4e94\u5929\u4ee59000\u7f8e\u5143\u7684\u4ef7\u683c\u5356\u51fa\u3002\u8d44\u672c\u6536\u76ca=9000-1000=8000\u7f8e\u5143\u3002\nHandbags \u80a1\u7968\u5728\u7b2c17\u5929\u4ee530000\u7f8e\u5143\u7684\u4ef7\u683c\u4e70\u5165\uff0c\u5728\u7b2c29\u5929\u4ee57000\u7f8e\u5143\u7684\u4ef7\u683c\u5356\u51fa\u3002\u8d44\u672c\u635f\u5931=7000-30000=-23000\u7f8e\u5143\u3002\nCorona Masks \u80a1\u7968\u5728\u7b2c1\u5929\u4ee510\u7f8e\u5143\u7684\u4ef7\u683c\u4e70\u5165\uff0c\u5728\u7b2c3\u5929\u4ee51010\u7f8e\u5143\u7684\u4ef7\u683c\u5356\u51fa\u3002\u5728\u7b2c4\u5929\u4ee51000\u7f8e\u5143\u7684\u4ef7\u683c\u518d\u6b21\u8d2d\u4e70\uff0c\u5728\u7b2c5\u5929\u4ee5500\u7f8e\u5143\u7684\u4ef7\u683c\u51fa\u552e\u3002\u6700\u540e\uff0c\u5b83\u5728\u7b2c6\u5929\u4ee51000\u7f8e\u5143\u7684\u4ef7\u683c\u88ab\u4e70\u8d70\uff0c\u5728\u7b2c10\u5929\u4ee510000\u7f8e\u5143\u7684\u4ef7\u683c\u88ab\u5356\u6389\u3002\u8d44\u672c\u635f\u76ca\u662f\u6bcf\u6b21\uff08’Buy'->'Sell'\uff09\u64cd\u4f5c\u8d44\u672c\u6536\u76ca\u6216\u635f\u5931\u7684\u548c=\uff081010-10\uff09+\uff08500-1000\uff09+\uff0810000-1000\uff09=1000-500+9000=9500\u7f8e\u5143\u3002\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1393](https://leetcode-cn.com/problems/capital-gainloss)", "[\u80a1\u7968\u7684\u8d44\u672c\u635f\u76ca](/solution/1300-1399/1393.Capital%20GainLoss/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1393](https://leetcode.com/problems/capital-gainloss)", "[Capital GainLoss](/solution/1300-1399/1393.Capital%20GainLoss/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1522", "frontend_question_id": "1406", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/stone-game-iii", "url_en": "https://leetcode.com/problems/stone-game-iii", "relative_path_cn": "/solution/1400-1499/1406.Stone%20Game%20III/README.md", "relative_path_en": "/solution/1400-1499/1406.Stone%20Game%20III/README_EN.md", "title_cn": "\u77f3\u5b50\u6e38\u620f III", "title_en": "Stone Game III", "question_title_slug": "stone-game-iii", "content_en": "

    Alice and Bob continue their games with piles of stones. There are several stones arranged in a row, and each stone has an associated value which is an integer given in the array stoneValue.

    \r\n\r\n

    Alice and Bob take turns, with Alice starting first. On each player's turn, that player can take 1, 2 or 3 stones from the first remaining stones in the row.

    \r\n\r\n

    The score of each player is the sum of values of the stones taken. The score of each player is 0 initially.

    \r\n\r\n

    The objective of the game is to end with the highest score, and the winner is the player with the highest score and there could be a tie. The game continues until all the stones have been taken.

    \r\n\r\n

    Assume Alice and Bob play optimally.

    \r\n\r\n

    Return "Alice" if Alice will win, "Bob" if Bob will win or "Tie" if they end the game with the same score.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: values = [1,2,3,7]\r\nOutput: "Bob"\r\nExplanation: Alice will always lose. Her best move will be to take three piles and the score become 6. Now the score of Bob is 7 and Bob wins.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: values = [1,2,3,-9]\r\nOutput: "Alice"\r\nExplanation: Alice must choose all the three piles at the first move to win and leave Bob with negative score.\r\nIf Alice chooses one pile her score will be 1 and the next move Bob's score becomes 5. The next move Alice will take the pile with value = -9 and lose.\r\nIf Alice chooses two piles her score will be 3 and the next move Bob's score becomes 3. The next move Alice will take the pile with value = -9 and also lose.\r\nRemember that both play optimally so here Alice will choose the scenario that makes her win.\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: values = [1,2,3,6]\r\nOutput: "Tie"\r\nExplanation: Alice cannot win this game. She can end the game in a draw if she decided to choose all the first three piles, otherwise she will lose.\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: values = [1,2,3,-1,-2,-3,7]\r\nOutput: "Alice"\r\n
    \r\n\r\n

    Example 5:

    \r\n\r\n
    \r\nInput: values = [-1,-2,-3]\r\nOutput: "Tie"\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= values.length <= 50000
    • \r\n\t
    • -1000 <= values[i] <= 1000
    • \r\n
    ", "content_cn": "

    Alice \u548c Bob \u7528\u51e0\u5806\u77f3\u5b50\u5728\u505a\u6e38\u620f\u3002\u51e0\u5806\u77f3\u5b50\u6392\u6210\u4e00\u884c\uff0c\u6bcf\u5806\u77f3\u5b50\u90fd\u5bf9\u5e94\u4e00\u4e2a\u5f97\u5206\uff0c\u7531\u6570\u7ec4 stoneValue \u7ed9\u51fa\u3002

    \n\n

    Alice \u548c Bob \u8f6e\u6d41\u53d6\u77f3\u5b50\uff0cAlice \u603b\u662f\u5148\u5f00\u59cb\u3002\u5728\u6bcf\u4e2a\u73a9\u5bb6\u7684\u56de\u5408\u4e2d\uff0c\u8be5\u73a9\u5bb6\u53ef\u4ee5\u62ff\u8d70\u5269\u4e0b\u77f3\u5b50\u4e2d\u7684\u7684\u524d 1\u30012 \u6216 3 \u5806\u77f3\u5b50 \u3002\u6bd4\u8d5b\u4e00\u76f4\u6301\u7eed\u5230\u6240\u6709\u77f3\u5934\u90fd\u88ab\u62ff\u8d70\u3002

    \n\n

    \u6bcf\u4e2a\u73a9\u5bb6\u7684\u6700\u7ec8\u5f97\u5206\u4e3a\u4ed6\u6240\u62ff\u5230\u7684\u6bcf\u5806\u77f3\u5b50\u7684\u5bf9\u5e94\u5f97\u5206\u4e4b\u548c\u3002\u6bcf\u4e2a\u73a9\u5bb6\u7684\u521d\u59cb\u5206\u6570\u90fd\u662f 0 \u3002\u6bd4\u8d5b\u7684\u76ee\u6807\u662f\u51b3\u51fa\u6700\u9ad8\u5206\uff0c\u5f97\u5206\u6700\u9ad8\u7684\u9009\u624b\u5c06\u4f1a\u8d62\u5f97\u6bd4\u8d5b\uff0c\u6bd4\u8d5b\u4e5f\u53ef\u80fd\u4f1a\u51fa\u73b0\u5e73\u5c40\u3002

    \n\n

    \u5047\u8bbe Alice \u548c Bob \u90fd\u91c7\u53d6 \u6700\u4f18\u7b56\u7565 \u3002\u5982\u679c Alice \u8d62\u4e86\u5c31\u8fd4\u56de "Alice" \uff0cBob \u8d62\u4e86\u5c31\u8fd4\u56de "Bob"\uff0c\u5e73\u5c40\uff08\u5206\u6570\u76f8\u540c\uff09\u8fd4\u56de "Tie" \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1avalues = [1,2,3,7]\n\u8f93\u51fa\uff1a"Bob"\n\u89e3\u91ca\uff1aAlice \u603b\u662f\u4f1a\u8f93\uff0c\u5979\u7684\u6700\u4f73\u9009\u62e9\u662f\u62ff\u8d70\u524d\u4e09\u5806\uff0c\u5f97\u5206\u53d8\u6210 6 \u3002\u4f46\u662f Bob \u7684\u5f97\u5206\u4e3a 7\uff0cBob \u83b7\u80dc\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1avalues = [1,2,3,-9]\n\u8f93\u51fa\uff1a"Alice"\n\u89e3\u91ca\uff1aAlice \u8981\u60f3\u83b7\u80dc\u5c31\u5fc5\u987b\u5728\u7b2c\u4e00\u4e2a\u56de\u5408\u62ff\u8d70\u524d\u4e09\u5806\u77f3\u5b50\uff0c\u7ed9 Bob \u7559\u4e0b\u8d1f\u5206\u3002\n\u5982\u679c Alice \u53ea\u62ff\u8d70\u7b2c\u4e00\u5806\uff0c\u90a3\u4e48\u5979\u7684\u5f97\u5206\u4e3a 1\uff0c\u63a5\u4e0b\u6765 Bob \u62ff\u8d70\u7b2c\u4e8c\u3001\u4e09\u5806\uff0c\u5f97\u5206\u4e3a 5 \u3002\u4e4b\u540e Alice \u53ea\u80fd\u62ff\u5230\u5206\u6570 -9 \u7684\u77f3\u5b50\u5806\uff0c\u8f93\u6389\u6bd4\u8d5b\u3002\n\u5982\u679c Alice \u62ff\u8d70\u524d\u4e24\u5806\uff0c\u90a3\u4e48\u5979\u7684\u5f97\u5206\u4e3a 3\uff0c\u63a5\u4e0b\u6765 Bob \u62ff\u8d70\u7b2c\u4e09\u5806\uff0c\u5f97\u5206\u4e3a 3 \u3002\u4e4b\u540e Alice \u53ea\u80fd\u62ff\u5230\u5206\u6570 -9 \u7684\u77f3\u5b50\u5806\uff0c\u540c\u6837\u4f1a\u8f93\u6389\u6bd4\u8d5b\u3002\n\u6ce8\u610f\uff0c\u4ed6\u4eec\u90fd\u5e94\u8be5\u91c7\u53d6 \u6700\u4f18\u7b56\u7565 \uff0c\u6240\u4ee5\u5728\u8fd9\u91cc Alice \u5c06\u9009\u62e9\u80fd\u591f\u4f7f\u5979\u83b7\u80dc\u7684\u65b9\u6848\u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1avalues = [1,2,3,6]\n\u8f93\u51fa\uff1a"Tie"\n\u89e3\u91ca\uff1aAlice \u65e0\u6cd5\u8d62\u5f97\u6bd4\u8d5b\u3002\u5982\u679c\u5979\u51b3\u5b9a\u9009\u62e9\u524d\u4e09\u5806\uff0c\u5979\u53ef\u4ee5\u4ee5\u5e73\u5c40\u7ed3\u675f\u6bd4\u8d5b\uff0c\u5426\u5219\u5979\u5c31\u4f1a\u8f93\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1avalues = [1,2,3,-1,-2,-3,7]\n\u8f93\u51fa\uff1a"Alice"\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1avalues = [-1,-2,-3]\n\u8f93\u51fa\uff1a"Tie"\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= values.length <= 50000
    • \n\t
    • -1000 <= values[i] <= 1000
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string stoneGameIII(vector& stoneValue) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String stoneGameIII(int[] stoneValue) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def stoneGameIII(self, stoneValue):\n \"\"\"\n :type stoneValue: List[int]\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def stoneGameIII(self, stoneValue: List[int]) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * stoneGameIII(int* stoneValue, int stoneValueSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string StoneGameIII(int[] stoneValue) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} stoneValue\n * @return {string}\n */\nvar stoneGameIII = function(stoneValue) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} stone_value\n# @return {String}\ndef stone_game_iii(stone_value)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func stoneGameIII(_ stoneValue: [Int]) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func stoneGameIII(stoneValue []int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def stoneGameIII(stoneValue: Array[Int]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun stoneGameIII(stoneValue: IntArray): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn stone_game_iii(stone_value: Vec) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $stoneValue\n * @return String\n */\n function stoneGameIII($stoneValue) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function stoneGameIII(stoneValue: number[]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (stone-game-iii stoneValue)\n (-> (listof exact-integer?) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1406](https://leetcode-cn.com/problems/stone-game-iii)", "[\u77f3\u5b50\u6e38\u620f III](/solution/1400-1499/1406.Stone%20Game%20III/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1406](https://leetcode.com/problems/stone-game-iii)", "[Stone Game III](/solution/1400-1499/1406.Stone%20Game%20III/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1520", "frontend_question_id": "1404", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-steps-to-reduce-a-number-in-binary-representation-to-one", "url_en": "https://leetcode.com/problems/number-of-steps-to-reduce-a-number-in-binary-representation-to-one", "relative_path_cn": "/solution/1400-1499/1404.Number%20of%20Steps%20to%20Reduce%20a%20Number%20in%20Binary%20Representation%20to%20One/README.md", "relative_path_en": "/solution/1400-1499/1404.Number%20of%20Steps%20to%20Reduce%20a%20Number%20in%20Binary%20Representation%20to%20One/README_EN.md", "title_cn": "\u5c06\u4e8c\u8fdb\u5236\u8868\u793a\u51cf\u5230 1 \u7684\u6b65\u9aa4\u6570", "title_en": "Number of Steps to Reduce a Number in Binary Representation to One", "question_title_slug": "number-of-steps-to-reduce-a-number-in-binary-representation-to-one", "content_en": "

    Given a number s in their binary representation. Return the number of steps to reduce it to 1 under the following rules:

    \n\n
      \n\t
    • \n\t

      If the current number is even, you have to divide it by 2.

      \n\t
    • \n\t
    • \n\t

      If the current number is odd, you have to add 1 to it.

      \n\t
    • \n
    \n\n

    It's guaranteed that you can always reach to one for all testcases.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "1101"\nOutput: 6\nExplanation: "1101" corressponds to number 13 in their decimal representation.\nStep 1) 13 is odd, add 1 and obtain 14. \nStep 2) 14 is even, divide by 2 and obtain 7.\nStep 3) 7 is odd, add 1 and obtain 8.\nStep 4) 8 is even, divide by 2 and obtain 4.  \nStep 5) 4 is even, divide by 2 and obtain 2. \nStep 6) 2 is even, divide by 2 and obtain 1.  \n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "10"\nOutput: 1\nExplanation: "10" corressponds to number 2 in their decimal representation.\nStep 1) 2 is even, divide by 2 and obtain 1.  \n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "1"\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 500
    • \n\t
    • s consists of characters '0' or '1'
    • \n\t
    • s[0] == '1'
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u4ee5\u4e8c\u8fdb\u5236\u5f62\u5f0f\u8868\u793a\u7684\u6570\u5b57 s \u3002\u8bf7\u4f60\u8fd4\u56de\u6309\u4e0b\u8ff0\u89c4\u5219\u5c06\u5176\u51cf\u5c11\u5230 1 \u6240\u9700\u8981\u7684\u6b65\u9aa4\u6570\uff1a

    \n\n
      \n\t
    • \n\t

      \u5982\u679c\u5f53\u524d\u6570\u5b57\u4e3a\u5076\u6570\uff0c\u5219\u5c06\u5176\u9664\u4ee5 2 \u3002

      \n\t
    • \n\t
    • \n\t

      \u5982\u679c\u5f53\u524d\u6570\u5b57\u4e3a\u5947\u6570\uff0c\u5219\u5c06\u5176\u52a0\u4e0a 1 \u3002

      \n\t
    • \n
    \n\n

    \u9898\u76ee\u4fdd\u8bc1\u4f60\u603b\u662f\u53ef\u4ee5\u6309\u4e0a\u8ff0\u89c4\u5219\u5c06\u6d4b\u8bd5\u7528\u4f8b\u53d8\u4e3a 1 \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1as = "1101"\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a"1101" \u8868\u793a\u5341\u8fdb\u5236\u6570 13 \u3002\nStep 1) 13 \u662f\u5947\u6570\uff0c\u52a0 1 \u5f97\u5230 14 \nStep 2) 14 \u662f\u5076\u6570\uff0c\u9664 2 \u5f97\u5230 7\nStep 3) 7  \u662f\u5947\u6570\uff0c\u52a0 1 \u5f97\u5230 8\nStep 4) 8  \u662f\u5076\u6570\uff0c\u9664 2 \u5f97\u5230 4  \nStep 5) 4  \u662f\u5076\u6570\uff0c\u9664 2 \u5f97\u5230 2 \nStep 6) 2  \u662f\u5076\u6570\uff0c\u9664 2 \u5f97\u5230 1  \n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1as = "10"\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a"10" \u8868\u793a\u5341\u8fdb\u5236\u6570 2 \u3002\nStep 1) 2 \u662f\u5076\u6570\uff0c\u9664 2 \u5f97\u5230 1 \n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1as = "1"\n\u8f93\u51fa\uff1a0\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 500
    • \n\t
    • s \u7531\u5b57\u7b26 '0' \u6216 '1' \u7ec4\u6210\u3002
    • \n\t
    • s[0] == '1'
    • \n
    \n", "tags_en": ["Bit Manipulation", "String"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numSteps(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numSteps(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numSteps(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numSteps(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numSteps(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumSteps(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar numSteps = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef num_steps(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numSteps(_ s: String) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numSteps(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numSteps(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numSteps(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_steps(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function numSteps($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numSteps(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-steps s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1404](https://leetcode-cn.com/problems/number-of-steps-to-reduce-a-number-in-binary-representation-to-one)", "[\u5c06\u4e8c\u8fdb\u5236\u8868\u793a\u51cf\u5230 1 \u7684\u6b65\u9aa4\u6570](/solution/1400-1499/1404.Number%20of%20Steps%20to%20Reduce%20a%20Number%20in%20Binary%20Representation%20to%20One/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1404](https://leetcode.com/problems/number-of-steps-to-reduce-a-number-in-binary-representation-to-one)", "[Number of Steps to Reduce a Number in Binary Representation to One](/solution/1400-1499/1404.Number%20of%20Steps%20to%20Reduce%20a%20Number%20in%20Binary%20Representation%20to%20One/README_EN.md)", "`Bit Manipulation`,`String`", "Medium", ""]}, {"question_id": "1519", "frontend_question_id": "1403", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-subsequence-in-non-increasing-order", "url_en": "https://leetcode.com/problems/minimum-subsequence-in-non-increasing-order", "relative_path_cn": "/solution/1400-1499/1403.Minimum%20Subsequence%20in%20Non-Increasing%20Order/README.md", "relative_path_en": "/solution/1400-1499/1403.Minimum%20Subsequence%20in%20Non-Increasing%20Order/README_EN.md", "title_cn": "\u975e\u9012\u589e\u987a\u5e8f\u7684\u6700\u5c0f\u5b50\u5e8f\u5217", "title_en": "Minimum Subsequence in Non-Increasing Order", "question_title_slug": "minimum-subsequence-in-non-increasing-order", "content_en": "

    Given the array nums, obtain a subsequence of the array whose sum of elements is strictly greater than the sum of the non included elements in such subsequence. 

    \r\n\r\n

    If there are multiple solutions, return the subsequence with minimum size and if there still exist multiple solutions, return the subsequence with the maximum total sum of all its elements. A subsequence of an array can be obtained by erasing some (possibly zero) elements from the array. 

    \r\n\r\n

    Note that the solution with the given constraints is guaranteed to be unique. Also return the answer sorted in non-increasing order.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: nums = [4,3,10,9,8]\r\nOutput: [10,9] \r\nExplanation: The subsequences [10,9] and [10,8] are minimal such that the sum of their elements is strictly greater than the sum of elements not included, however, the subsequence [10,9] has the maximum total sum of its elements. \r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: nums = [4,4,7,6,7]\r\nOutput: [7,7,6] \r\nExplanation: The subsequence [7,7] has the sum of its elements equal to 14 which is not strictly greater than the sum of elements not included (14 = 4 + 4 + 6). Therefore, the subsequence [7,6,7] is the minimal satisfying the conditions. Note the subsequence has to returned in non-decreasing order.  \r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: nums = [6]\r\nOutput: [6]\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= nums.length <= 500
    • \r\n\t
    • 1 <= nums[i] <= 100
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 nums\uff0c\u8bf7\u4f60\u4ece\u4e2d\u62bd\u53d6\u4e00\u4e2a\u5b50\u5e8f\u5217\uff0c\u6ee1\u8db3\u8be5\u5b50\u5e8f\u5217\u7684\u5143\u7d20\u4e4b\u548c \u4e25\u683c \u5927\u4e8e\u672a\u5305\u542b\u5728\u8be5\u5b50\u5e8f\u5217\u4e2d\u7684\u5404\u5143\u7d20\u4e4b\u548c\u3002

    \n\n

    \u5982\u679c\u5b58\u5728\u591a\u4e2a\u89e3\u51b3\u65b9\u6848\uff0c\u53ea\u9700\u8fd4\u56de \u957f\u5ea6\u6700\u5c0f \u7684\u5b50\u5e8f\u5217\u3002\u5982\u679c\u4ecd\u7136\u6709\u591a\u4e2a\u89e3\u51b3\u65b9\u6848\uff0c\u5219\u8fd4\u56de \u5143\u7d20\u4e4b\u548c\u6700\u5927 \u7684\u5b50\u5e8f\u5217\u3002

    \n\n

    \u4e0e\u5b50\u6570\u7ec4\u4e0d\u540c\u7684\u5730\u65b9\u5728\u4e8e\uff0c\u300c\u6570\u7ec4\u7684\u5b50\u5e8f\u5217\u300d\u4e0d\u5f3a\u8c03\u5143\u7d20\u5728\u539f\u6570\u7ec4\u4e2d\u7684\u8fde\u7eed\u6027\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u5b83\u53ef\u4ee5\u901a\u8fc7\u4ece\u6570\u7ec4\u4e2d\u5206\u79bb\u4e00\u4e9b\uff08\u4e5f\u53ef\u80fd\u4e0d\u5206\u79bb\uff09\u5143\u7d20\u5f97\u5230\u3002

    \n\n

    \u6ce8\u610f\uff0c\u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u6ee1\u8db3\u6240\u6709\u7ea6\u675f\u6761\u4ef6\u7684\u89e3\u51b3\u65b9\u6848\u662f \u552f\u4e00 \u7684\u3002\u540c\u65f6\uff0c\u8fd4\u56de\u7684\u7b54\u6848\u5e94\u5f53\u6309 \u975e\u9012\u589e\u987a\u5e8f \u6392\u5217\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [4,3,10,9,8]\n\u8f93\u51fa\uff1a[10,9] \n\u89e3\u91ca\uff1a\u5b50\u5e8f\u5217 [10,9] \u548c [10,8] \u662f\u6700\u5c0f\u7684\u3001\u6ee1\u8db3\u5143\u7d20\u4e4b\u548c\u5927\u4e8e\u5176\u4ed6\u5404\u5143\u7d20\u4e4b\u548c\u7684\u5b50\u5e8f\u5217\u3002\u4f46\u662f [10,9] \u7684\u5143\u7d20\u4e4b\u548c\u6700\u5927\u3002 \n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [4,4,7,6,7]\n\u8f93\u51fa\uff1a[7,7,6] \n\u89e3\u91ca\uff1a\u5b50\u5e8f\u5217 [7,7] \u7684\u548c\u4e3a 14 \uff0c\u4e0d\u4e25\u683c\u5927\u4e8e\u5269\u4e0b\u7684\u5176\u4ed6\u5143\u7d20\u4e4b\u548c\uff0814 = 4 + 4 + 6\uff09\u3002\u56e0\u6b64\uff0c[7,6,7] \u662f\u6ee1\u8db3\u9898\u610f\u7684\u6700\u5c0f\u5b50\u5e8f\u5217\u3002\u6ce8\u610f\uff0c\u5143\u7d20\u6309\u975e\u9012\u589e\u987a\u5e8f\u8fd4\u56de\u3002  \n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [6]\n\u8f93\u51fa\uff1a[6]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 500
    • \n\t
    • 1 <= nums[i] <= 100
    • \n
    \n", "tags_en": ["Greedy", "Sort"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6392\u5e8f"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector minSubsequence(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List minSubsequence(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minSubsequence(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minSubsequence(self, nums: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* minSubsequence(int* nums, int numsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList MinSubsequence(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar minSubsequence = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer[]}\ndef min_subsequence(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minSubsequence(_ nums: [Int]) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minSubsequence(nums []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minSubsequence(nums: Array[Int]): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minSubsequence(nums: IntArray): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_subsequence(nums: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer[]\n */\n function minSubsequence($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minSubsequence(nums: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-subsequence nums)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1403](https://leetcode-cn.com/problems/minimum-subsequence-in-non-increasing-order)", "[\u975e\u9012\u589e\u987a\u5e8f\u7684\u6700\u5c0f\u5b50\u5e8f\u5217](/solution/1400-1499/1403.Minimum%20Subsequence%20in%20Non-Increasing%20Order/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6392\u5e8f`", "\u7b80\u5355", ""], "md_table_row_en": ["[1403](https://leetcode.com/problems/minimum-subsequence-in-non-increasing-order)", "[Minimum Subsequence in Non-Increasing Order](/solution/1400-1499/1403.Minimum%20Subsequence%20in%20Non-Increasing%20Order/README_EN.md)", "`Greedy`,`Sort`", "Easy", ""]}, {"question_id": "1518", "frontend_question_id": "1384", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/total-sales-amount-by-year", "url_en": "https://leetcode.com/problems/total-sales-amount-by-year", "relative_path_cn": "/solution/1300-1399/1384.Total%20Sales%20Amount%20by%20Year/README.md", "relative_path_en": "/solution/1300-1399/1384.Total%20Sales%20Amount%20by%20Year/README_EN.md", "title_cn": "\u6309\u5e74\u5ea6\u5217\u51fa\u9500\u552e\u603b\u989d", "title_en": "Total Sales Amount by Year", "question_title_slug": "total-sales-amount-by-year", "content_en": "

    Table: Product

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| product_id    | int     |\n| product_name  | varchar |\n+---------------+---------+\nproduct_id is the primary key for this table.\nproduct_name is the name of the product.\n
    \n\n

     

    \n\n

    Table: Sales

    \n\n
    \n+---------------------+---------+\n| Column Name         | Type    |\n+---------------------+---------+\n| product_id          | int     |\n| period_start        | date    |\n| period_end          | date    |\n| average_daily_sales | int     |\n+---------------------+---------+\nproduct_id is the primary key for this table. \nperiod_start and period_end indicates the start and end date for sales period, both dates are inclusive.\nThe average_daily_sales column holds the average daily sales amount of the items for the period.\n\n
    \n\n

    Write an SQL query to report the Total sales amount of each item for each year, with corresponding product name, product_id, product_name and report_year.

    \n\n

    Dates of the sales years are between 2018 to 2020. Return the result table ordered by product_id and report_year.

    \n\n

    The query result format is in the following example:

    \n\n
    \nProduct table:\n+------------+--------------+\n| product_id | product_name |\n+------------+--------------+\n| 1          | LC Phone     |\n| 2          | LC T-Shirt   |\n| 3          | LC Keychain  |\n+------------+--------------+\n\nSales table:\n+------------+--------------+-------------+---------------------+\n| product_id | period_start | period_end  | average_daily_sales |\n+------------+--------------+-------------+---------------------+\n| 1          | 2019-01-25   | 2019-02-28  | 100                 |\n| 2          | 2018-12-01   | 2020-01-01  | 10                  |\n| 3          | 2019-12-01   | 2020-01-31  | 1                   |\n+------------+--------------+-------------+---------------------+\n\nResult table:\n+------------+--------------+-------------+--------------+\n| product_id | product_name | report_year | total_amount |\n+------------+--------------+-------------+--------------+\n| 1          | LC Phone     |    2019     | 3500         |\n| 2          | LC T-Shirt   |    2018     | 310          |\n| 2          | LC T-Shirt   |    2019     | 3650         |\n| 2          | LC T-Shirt   |    2020     | 10           |\n| 3          | LC Keychain  |    2019     | 31           |\n| 3          | LC Keychain  |    2020     | 31           |\n+------------+--------------+-------------+--------------+\nLC Phone was sold for the period of 2019-01-25 to 2019-02-28, and there are 35 days for this period. Total amount 35*100 = 3500. \nLC T-shirt was sold for the period of 2018-12-01 to 2020-01-01, and there are 31, 365, 1 days for years 2018, 2019 and 2020 respectively.\nLC Keychain was sold for the period of 2019-12-01 to 2020-01-31, and there are 31, 31 days for years 2019 and 2020 respectively.\n
    \n", "content_cn": "

    \u00a0Product\u00a0\u8868\uff1a

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| product_id    | int     |\n| product_name  | varchar |\n+---------------+---------+\nproduct_id \u662f\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\u3002\nproduct_name \u662f\u4ea7\u54c1\u7684\u540d\u79f0\u3002\n
    \n\n

    \u00a0

    \n\n

    Sales\u00a0\u8868\uff1a

    \n\n
    \n+---------------------+---------+\n| Column Name         | Type    |\n+---------------------+---------+\n| product_id          | int     |\n| period_start        | date    |\n| period_end          | date    |\n| average_daily_sales | int     |\n+---------------------+---------+\nproduct_id \u662f\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\u3002\nperiod_start\u00a0\u548c period_end\u00a0\u662f\u8be5\u4ea7\u54c1\u9500\u552e\u671f\u7684\u8d77\u59cb\u65e5\u671f\u548c\u7ed3\u675f\u65e5\u671f\uff0c\u4e14\u8fd9\u4e24\u4e2a\u65e5\u671f\u5305\u542b\u5728\u9500\u552e\u671f\u5185\u3002\naverage_daily_sales \u5217\u5b58\u50a8\u9500\u552e\u671f\u5185\u8be5\u4ea7\u54c1\u7684\u65e5\u5e73\u5747\u9500\u552e\u989d\u3002\n
    \n\n

    \u00a0

    \n\n

    \u7f16\u5199\u4e00\u6bb5 SQL \u67e5\u8be2\u6bcf\u4e2a\u4ea7\u54c1\u6bcf\u5e74\u7684\u603b\u9500\u552e\u989d\uff0c\u5e76\u5305\u542b product_id, product_name \u4ee5\u53ca report_year \u7b49\u4fe1\u606f\u3002

    \n\n

    \u9500\u552e\u5e74\u4efd\u7684\u65e5\u671f\u4ecb\u4e8e 2018 \u5e74\u5230 2020 \u5e74\u4e4b\u95f4\u3002\u4f60\u8fd4\u56de\u7684\u7ed3\u679c\u9700\u8981\u6309\u00a0product_id \u548c report_year \u6392\u5e8f\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a\uff1a

    \n\n
    \nProduct table:\n+------------+--------------+\n| product_id | product_name |\n+------------+--------------+\n| 1          | LC Phone     |\n| 2          | LC T-Shirt   |\n| 3          | LC Keychain  |\n+------------+--------------+\n\nSales table:\n+------------+--------------+-------------+---------------------+\n| product_id | period_start | period_end  | average_daily_sales |\n+------------+--------------+-------------+---------------------+\n| 1          | 2019-01-25   | 2019-02-28  | 100                 |\n| 2          | 2018-12-01   | 2020-01-01  | 10                  |\n| 3          | 2019-12-01   | 2020-01-31  | 1                   |\n+------------+--------------+-------------+---------------------+\n\nResult table:\n+------------+--------------+-------------+--------------+\n| product_id | product_name | report_year | total_amount |\n+------------+--------------+-------------+--------------+\n| 1          | LC Phone     |    2019     | 3500         |\n| 2          | LC T-Shirt   |    2018     | 310          |\n| 2          | LC T-Shirt   |    2019     | 3650         |\n| 2          | LC T-Shirt   |    2020     | 10           |\n| 3          | LC Keychain  |    2019     | 31           |\n| 3          | LC Keychain  |    2020     | 31           |\n+------------+--------------+-------------+--------------+\nLC Phone \u5728 2019-01-25 \u81f3 2019-02-28 \u671f\u95f4\u9500\u552e\uff0c\u8be5\u4ea7\u54c1\u9500\u552e\u65f6\u95f4\u603b\u8ba135\u5929\u3002\u9500\u552e\u603b\u989d 35*100 = 3500\u3002\nLC T-shirt \u5728 2018-12-01\u00a0\u81f3 2020-01-01 \u671f\u95f4\u9500\u552e\uff0c\u8be5\u4ea7\u54c1\u57282018\u5e74\u30012019\u5e74\u30012020\u5e74\u7684\u9500\u552e\u65f6\u95f4\u5206\u522b\u662f31\u5929\u3001365\u5929\u30011\u5929\uff0c2018\u5e74\u30012019\u5e74\u30012020\u5e74\u7684\u9500\u552e\u603b\u989d\u5206\u522b\u662f31*10=310\u3001365*10=3650\u30011*10=10\u3002\nLC Keychain \u5728 2019-12-01\u00a0\u81f3 2020-01-31 \u671f\u95f4\u9500\u552e\uff0c\u8be5\u4ea7\u54c1\u57282019\u5e74\u30012020\u5e74\u7684\u9500\u552e\u65f6\u95f4\u5206\u522b\u662f\uff1a31\u5929\u300131\u5929\uff0c2019\u5e74\u30012020\u5e74\u7684\u9500\u552e\u603b\u989d\u5206\u522b\u662f31*1=31\u300131*1=31\u3002\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1384](https://leetcode-cn.com/problems/total-sales-amount-by-year)", "[\u6309\u5e74\u5ea6\u5217\u51fa\u9500\u552e\u603b\u989d](/solution/1300-1399/1384.Total%20Sales%20Amount%20by%20Year/README.md)", "", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1384](https://leetcode.com/problems/total-sales-amount-by-year)", "[Total Sales Amount by Year](/solution/1300-1399/1384.Total%20Sales%20Amount%20by%20Year/README_EN.md)", "", "Hard", "\ud83d\udd12"]}, {"question_id": "1517", "frontend_question_id": "1416", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/restore-the-array", "url_en": "https://leetcode.com/problems/restore-the-array", "relative_path_cn": "/solution/1400-1499/1416.Restore%20The%20Array/README.md", "relative_path_en": "/solution/1400-1499/1416.Restore%20The%20Array/README_EN.md", "title_cn": "\u6062\u590d\u6570\u7ec4", "title_en": "Restore The Array", "question_title_slug": "restore-the-array", "content_en": "

    A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits and all we know is that all integers in the array were in the range [1, k] and there are no leading zeros in the array.

    \r\n\r\n

    Given the string s and the integer k. There can be multiple ways to restore the array.

    \r\n\r\n

    Return the number of possible array that can be printed as a string s using the mentioned program.

    \r\n\r\n

    The number of ways could be very large so return it modulo 10^9 + 7

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: s = "1000", k = 10000\r\nOutput: 1\r\nExplanation: The only possible array is [1000]\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: s = "1000", k = 10\r\nOutput: 0\r\nExplanation: There cannot be an array that was printed this way and has all integer >= 1 and <= 10.\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: s = "1317", k = 2000\r\nOutput: 8\r\nExplanation: Possible arrays are [1317],[131,7],[13,17],[1,317],[13,1,7],[1,31,7],[1,3,17],[1,3,1,7]\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: s = "2020", k = 30\r\nOutput: 1\r\nExplanation: The only possible array is [20,20]. [2020] is invalid because 2020 > 30. [2,020] is ivalid because 020 contains leading zeros.\r\n
    \r\n\r\n

    Example 5:

    \r\n\r\n
    \r\nInput: s = "1234567890", k = 90\r\nOutput: 34\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= s.length <= 10^5.
    • \r\n\t
    • s consists of only digits and doesn't contain leading zeros.
    • \r\n\t
    • 1 <= k <= 10^9.
    • \r\n
    ", "content_cn": "

    \u67d0\u4e2a\u7a0b\u5e8f\u672c\u6765\u5e94\u8be5\u8f93\u51fa\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u3002\u4f46\u662f\u8fd9\u4e2a\u7a0b\u5e8f\u5fd8\u8bb0\u8f93\u51fa\u7a7a\u683c\u4e86\u4ee5\u81f4\u8f93\u51fa\u4e86\u4e00\u4e2a\u6570\u5b57\u5b57\u7b26\u4e32\uff0c\u6211\u4eec\u6240\u77e5\u9053\u7684\u4fe1\u606f\u53ea\u6709\uff1a\u6570\u7ec4\u4e2d\u6240\u6709\u6574\u6570\u90fd\u5728 [1, k] \u4e4b\u95f4\uff0c\u4e14\u6570\u7ec4\u4e2d\u7684\u6570\u5b57\u90fd\u6ca1\u6709\u524d\u5bfc 0 \u3002

    \n\n

    \u7ed9\u4f60\u5b57\u7b26\u4e32 s \u548c\u6574\u6570 k \u3002\u53ef\u80fd\u4f1a\u6709\u591a\u79cd\u4e0d\u540c\u7684\u6570\u7ec4\u6062\u590d\u7ed3\u679c\u3002

    \n\n

    \u6309\u7167\u4e0a\u8ff0\u7a0b\u5e8f\uff0c\u8bf7\u4f60\u8fd4\u56de\u6240\u6709\u53ef\u80fd\u8f93\u51fa\u5b57\u7b26\u4e32 s \u7684\u6570\u7ec4\u65b9\u6848\u6570\u3002

    \n\n

    \u7531\u4e8e\u6570\u7ec4\u65b9\u6848\u6570\u53ef\u80fd\u4f1a\u5f88\u5927\uff0c\u8bf7\u4f60\u8fd4\u56de\u5b83\u5bf9 10^9 + 7 \u53d6\u4f59 \u540e\u7684\u7ed3\u679c\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1as = "1000", k = 10000\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u552f\u4e00\u4e00\u79cd\u53ef\u80fd\u7684\u6570\u7ec4\u65b9\u6848\u662f [1000]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1as = "1000", k = 10\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u4e0d\u5b58\u5728\u4efb\u4f55\u6570\u7ec4\u65b9\u6848\u6ee1\u8db3\u6240\u6709\u6574\u6570\u90fd >= 1 \u4e14 <= 10 \u540c\u65f6\u8f93\u51fa\u7ed3\u679c\u4e3a s \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1as = "1317", k = 2000\n\u8f93\u51fa\uff1a8\n\u89e3\u91ca\uff1a\u53ef\u884c\u7684\u6570\u7ec4\u65b9\u6848\u4e3a [1317]\uff0c[131,7]\uff0c[13,17]\uff0c[1,317]\uff0c[13,1,7]\uff0c[1,31,7]\uff0c[1,3,17]\uff0c[1,3,1,7]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1as = "2020", k = 30\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u552f\u4e00\u53ef\u80fd\u7684\u6570\u7ec4\u65b9\u6848\u662f [20,20] \u3002 [2020] \u4e0d\u662f\u53ef\u884c\u7684\u6570\u7ec4\u65b9\u6848\uff0c\u539f\u56e0\u662f 2020 > 30 \u3002 [2,020] \u4e5f\u4e0d\u662f\u53ef\u884c\u7684\u6570\u7ec4\u65b9\u6848\uff0c\u56e0\u4e3a 020 \u542b\u6709\u524d\u5bfc 0 \u3002\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1as = "1234567890", k = 90\n\u8f93\u51fa\uff1a34\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 10^5.
    • \n\t
    • s \u53ea\u5305\u542b\u6570\u5b57\u4e14\u4e0d\u5305\u542b\u524d\u5bfc 0 \u3002
    • \n\t
    • 1 <= k <= 10^9.
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numberOfArrays(string s, int k) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numberOfArrays(String s, int k) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numberOfArrays(self, s, k):\n \"\"\"\n :type s: str\n :type k: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numberOfArrays(self, s: str, k: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numberOfArrays(char * s, int k){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumberOfArrays(string s, int k) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number} k\n * @return {number}\n */\nvar numberOfArrays = function(s, k) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer} k\n# @return {Integer}\ndef number_of_arrays(s, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numberOfArrays(_ s: String, _ k: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numberOfArrays(s string, k int) int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numberOfArrays(s: String, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numberOfArrays(s: String, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn number_of_arrays(s: String, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer $k\n * @return Integer\n */\n function numberOfArrays($s, $k) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numberOfArrays(s: string, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (number-of-arrays s k)\n (-> string? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1416](https://leetcode-cn.com/problems/restore-the-array)", "[\u6062\u590d\u6570\u7ec4](/solution/1400-1499/1416.Restore%20The%20Array/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1416](https://leetcode.com/problems/restore-the-array)", "[Restore The Array](/solution/1400-1499/1416.Restore%20The%20Array/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1516", "frontend_question_id": "1415", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/the-k-th-lexicographical-string-of-all-happy-strings-of-length-n", "url_en": "https://leetcode.com/problems/the-k-th-lexicographical-string-of-all-happy-strings-of-length-n", "relative_path_cn": "/solution/1400-1499/1415.The%20k-th%20Lexicographical%20String%20of%20All%20Happy%20Strings%20of%20Length%20n/README.md", "relative_path_en": "/solution/1400-1499/1415.The%20k-th%20Lexicographical%20String%20of%20All%20Happy%20Strings%20of%20Length%20n/README_EN.md", "title_cn": "\u957f\u5ea6\u4e3a n \u7684\u5f00\u5fc3\u5b57\u7b26\u4e32\u4e2d\u5b57\u5178\u5e8f\u7b2c k \u5c0f\u7684\u5b57\u7b26\u4e32", "title_en": "The k-th Lexicographical String of All Happy Strings of Length n", "question_title_slug": "the-k-th-lexicographical-string-of-all-happy-strings-of-length-n", "content_en": "

    A happy string is a string that:

    \r\n\r\n
      \r\n\t
    • consists only of letters of the set ['a', 'b', 'c'].
    • \r\n\t
    • s[i] != s[i + 1] for all values of i from 1 to s.length - 1 (string is 1-indexed).
    • \r\n
    \r\n\r\n

    For example, strings "abc", "ac", "b" and "abcbabcbcb" are all happy strings and strings "aa", "baa" and "ababbc" are not happy strings.

    \r\n\r\n

    Given two integers n and k, consider a list of all happy strings of length n sorted in lexicographical order.

    \r\n\r\n

    Return the kth string of this list or return an empty string if there are less than k happy strings of length n.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: n = 1, k = 3\r\nOutput: "c"\r\nExplanation: The list ["a", "b", "c"] contains all happy strings of length 1. The third string is "c".\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: n = 1, k = 4\r\nOutput: ""\r\nExplanation: There are only 3 happy strings of length 1.\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: n = 3, k = 9\r\nOutput: "cab"\r\nExplanation: There are 12 different happy string of length 3 ["aba", "abc", "aca", "acb", "bab", "bac", "bca", "bcb", "cab", "cac", "cba", "cbc"]. You will find the 9th string = "cab"\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: n = 2, k = 7\r\nOutput: ""\r\n
    \r\n\r\n

    Example 5:

    \r\n\r\n
    \r\nInput: n = 10, k = 100\r\nOutput: "abacbabacb"\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= n <= 10
    • \r\n\t
    • 1 <= k <= 100
    • \r\n
    \r\n\r\n
     
    ", "content_cn": "

    \u4e00\u4e2a \u300c\u5f00\u5fc3\u5b57\u7b26\u4e32\u300d\u5b9a\u4e49\u4e3a\uff1a

    \n\n
      \n\t
    • \u4ec5\u5305\u542b\u5c0f\u5199\u5b57\u6bcd ['a', 'b', 'c'].
    • \n\t
    • \u5bf9\u6240\u6709\u5728 1 \u5230 s.length - 1 \u4e4b\u95f4\u7684 i \uff0c\u6ee1\u8db3 s[i] != s[i + 1] \uff08\u5b57\u7b26\u4e32\u7684\u4e0b\u6807\u4ece 1 \u5f00\u59cb\uff09\u3002
    • \n
    \n\n

    \u6bd4\u65b9\u8bf4\uff0c\u5b57\u7b26\u4e32 "abc"\uff0c"ac"\uff0c"b" \u548c "abcbabcbcb" \u90fd\u662f\u5f00\u5fc3\u5b57\u7b26\u4e32\uff0c\u4f46\u662f "aa"\uff0c"baa" \u548c "ababbc" \u90fd\u4e0d\u662f\u5f00\u5fc3\u5b57\u7b26\u4e32\u3002

    \n\n

    \u7ed9\u4f60\u4e24\u4e2a\u6574\u6570 n \u548c k \uff0c\u4f60\u9700\u8981\u5c06\u957f\u5ea6\u4e3a n \u7684\u6240\u6709\u5f00\u5fc3\u5b57\u7b26\u4e32\u6309\u5b57\u5178\u5e8f\u6392\u5e8f\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u6392\u5e8f\u540e\u7684\u7b2c k \u4e2a\u5f00\u5fc3\u5b57\u7b26\u4e32\uff0c\u5982\u679c\u957f\u5ea6\u4e3a n \u7684\u5f00\u5fc3\u5b57\u7b26\u4e32\u5c11\u4e8e k \u4e2a\uff0c\u90a3\u4e48\u8bf7\u4f60\u8fd4\u56de \u7a7a\u5b57\u7b26\u4e32 \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1an = 1, k = 3\n\u8f93\u51fa\uff1a"c"\n\u89e3\u91ca\uff1a\u5217\u8868 ["a", "b", "c"] \u5305\u542b\u4e86\u6240\u6709\u957f\u5ea6\u4e3a 1 \u7684\u5f00\u5fc3\u5b57\u7b26\u4e32\u3002\u6309\u7167\u5b57\u5178\u5e8f\u6392\u5e8f\u540e\u7b2c\u4e09\u4e2a\u5b57\u7b26\u4e32\u4e3a "c" \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1an = 1, k = 4\n\u8f93\u51fa\uff1a""\n\u89e3\u91ca\uff1a\u957f\u5ea6\u4e3a 1 \u7684\u5f00\u5fc3\u5b57\u7b26\u4e32\u53ea\u6709 3 \u4e2a\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1an = 3, k = 9\n\u8f93\u51fa\uff1a"cab"\n\u89e3\u91ca\uff1a\u957f\u5ea6\u4e3a 3 \u7684\u5f00\u5fc3\u5b57\u7b26\u4e32\u603b\u5171\u6709 12 \u4e2a ["aba", "abc", "aca", "acb", "bab", "bac", "bca", "bcb", "cab", "cac", "cba", "cbc"] \u3002\u7b2c 9 \u4e2a\u5b57\u7b26\u4e32\u4e3a "cab"\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1an = 2, k = 7\n\u8f93\u51fa\uff1a""\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1an = 10, k = 100\n\u8f93\u51fa\uff1a"abacbabacb"\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 10
    • \n\t
    • 1 <= k <= 100
    • \n
    \n\n

     

    \n", "tags_en": ["Backtracking"], "tags_cn": ["\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string getHappyString(int n, int k) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String getHappyString(int n, int k) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getHappyString(self, n, k):\n \"\"\"\n :type n: int\n :type k: int\n :rtype: str\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getHappyString(self, n: int, k: int) -> str:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * getHappyString(int n, int k){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string GetHappyString(int n, int k) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} k\n * @return {string}\n */\nvar getHappyString = function(n, k) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} k\n# @return {String}\ndef get_happy_string(n, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getHappyString(_ n: Int, _ k: Int) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getHappyString(n int, k int) string {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getHappyString(n: Int, k: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getHappyString(n: Int, k: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_happy_string(n: i32, k: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $k\n * @return String\n */\n function getHappyString($n, $k) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getHappyString(n: number, k: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-happy-string n k)\n (-> exact-integer? exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1415](https://leetcode-cn.com/problems/the-k-th-lexicographical-string-of-all-happy-strings-of-length-n)", "[\u957f\u5ea6\u4e3a n \u7684\u5f00\u5fc3\u5b57\u7b26\u4e32\u4e2d\u5b57\u5178\u5e8f\u7b2c k \u5c0f\u7684\u5b57\u7b26\u4e32](/solution/1400-1499/1415.The%20k-th%20Lexicographical%20String%20of%20All%20Happy%20Strings%20of%20Length%20n/README.md)", "`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1415](https://leetcode.com/problems/the-k-th-lexicographical-string-of-all-happy-strings-of-length-n)", "[The k-th Lexicographical String of All Happy Strings of Length n](/solution/1400-1499/1415.The%20k-th%20Lexicographical%20String%20of%20All%20Happy%20Strings%20of%20Length%20n/README_EN.md)", "`Backtracking`", "Medium", ""]}, {"question_id": "1515", "frontend_question_id": "1414", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-the-minimum-number-of-fibonacci-numbers-whose-sum-is-k", "url_en": "https://leetcode.com/problems/find-the-minimum-number-of-fibonacci-numbers-whose-sum-is-k", "relative_path_cn": "/solution/1400-1499/1414.Find%20the%20Minimum%20Number%20of%20Fibonacci%20Numbers%20Whose%20Sum%20Is%20K/README.md", "relative_path_en": "/solution/1400-1499/1414.Find%20the%20Minimum%20Number%20of%20Fibonacci%20Numbers%20Whose%20Sum%20Is%20K/README_EN.md", "title_cn": "\u548c\u4e3a K \u7684\u6700\u5c11\u6590\u6ce2\u90a3\u5951\u6570\u5b57\u6570\u76ee", "title_en": "Find the Minimum Number of Fibonacci Numbers Whose Sum Is K", "question_title_slug": "find-the-minimum-number-of-fibonacci-numbers-whose-sum-is-k", "content_en": "

    Given an integer k, return the minimum number of Fibonacci numbers whose sum is equal to k. The same Fibonacci number can be used multiple times.

    \n\n

    The Fibonacci numbers are defined as:

    \n\n
      \n\t
    • F1 = 1
    • \n\t
    • F2 = 1
    • \n\t
    • Fn = Fn-1 + Fn-2 for n > 2.
    • \n
    \nIt is guaranteed that for the given constraints we can always find such Fibonacci numbers that sum up to k.\n

     

    \n

    Example 1:

    \n\n
    \nInput: k = 7\nOutput: 2 \nExplanation: The Fibonacci numbers are: 1, 1, 2, 3, 5, 8, 13, ... \nFor k = 7 we can use 2 + 5 = 7.
    \n\n

    Example 2:

    \n\n
    \nInput: k = 10\nOutput: 2 \nExplanation: For k = 10 we can use 2 + 8 = 10.\n
    \n\n

    Example 3:

    \n\n
    \nInput: k = 19\nOutput: 3 \nExplanation: For k = 19 we can use 1 + 5 + 13 = 19.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= k <= 10^9
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u6570\u5b57 k \uff0c\u8bf7\u4f60\u8fd4\u56de\u548c\u4e3a k \u7684\u6590\u6ce2\u90a3\u5951\u6570\u5b57\u7684\u6700\u5c11\u6570\u76ee\uff0c\u5176\u4e2d\uff0c\u6bcf\u4e2a\u6590\u6ce2\u90a3\u5951\u6570\u5b57\u90fd\u53ef\u4ee5\u88ab\u4f7f\u7528\u591a\u6b21\u3002

    \n\n

    \u6590\u6ce2\u90a3\u5951\u6570\u5b57\u5b9a\u4e49\u4e3a\uff1a

    \n\n
      \n\t
    • F1 = 1
    • \n\t
    • F2 = 1
    • \n\t
    • Fn = Fn-1 + Fn-2 \uff0c \u5176\u4e2d n > 2 \u3002
    • \n
    \n\n

    \u6570\u636e\u4fdd\u8bc1\u5bf9\u4e8e\u7ed9\u5b9a\u7684 k \uff0c\u4e00\u5b9a\u80fd\u627e\u5230\u53ef\u884c\u89e3\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1ak = 7\n\u8f93\u51fa\uff1a2 \n\u89e3\u91ca\uff1a\u6590\u6ce2\u90a3\u5951\u6570\u5b57\u4e3a\uff1a1\uff0c1\uff0c2\uff0c3\uff0c5\uff0c8\uff0c13\uff0c……\n\u5bf9\u4e8e k = 7 \uff0c\u6211\u4eec\u53ef\u4ee5\u5f97\u5230 2 + 5 = 7 \u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1ak = 10\n\u8f93\u51fa\uff1a2 \n\u89e3\u91ca\uff1a\u5bf9\u4e8e k = 10 \uff0c\u6211\u4eec\u53ef\u4ee5\u5f97\u5230 2 + 8 = 10 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1ak = 19\n\u8f93\u51fa\uff1a3 \n\u89e3\u91ca\uff1a\u5bf9\u4e8e k = 19 \uff0c\u6211\u4eec\u53ef\u4ee5\u5f97\u5230 1 + 5 + 13 = 19 \u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= k <= 10^9
    • \n
    \n", "tags_en": ["Greedy", "Array"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findMinFibonacciNumbers(int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findMinFibonacciNumbers(int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findMinFibonacciNumbers(self, k):\n \"\"\"\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findMinFibonacciNumbers(self, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findMinFibonacciNumbers(int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindMinFibonacciNumbers(int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} k\n * @return {number}\n */\nvar findMinFibonacciNumbers = function(k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} k\n# @return {Integer}\ndef find_min_fibonacci_numbers(k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findMinFibonacciNumbers(_ k: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findMinFibonacciNumbers(k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findMinFibonacciNumbers(k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findMinFibonacciNumbers(k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_min_fibonacci_numbers(k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $k\n * @return Integer\n */\n function findMinFibonacciNumbers($k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findMinFibonacciNumbers(k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-min-fibonacci-numbers k)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1414](https://leetcode-cn.com/problems/find-the-minimum-number-of-fibonacci-numbers-whose-sum-is-k)", "[\u548c\u4e3a K \u7684\u6700\u5c11\u6590\u6ce2\u90a3\u5951\u6570\u5b57\u6570\u76ee](/solution/1400-1499/1414.Find%20the%20Minimum%20Number%20of%20Fibonacci%20Numbers%20Whose%20Sum%20Is%20K/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1414](https://leetcode.com/problems/find-the-minimum-number-of-fibonacci-numbers-whose-sum-is-k)", "[Find the Minimum Number of Fibonacci Numbers Whose Sum Is K](/solution/1400-1499/1414.Find%20the%20Minimum%20Number%20of%20Fibonacci%20Numbers%20Whose%20Sum%20Is%20K/README_EN.md)", "`Greedy`,`Array`", "Medium", ""]}, {"question_id": "1514", "frontend_question_id": "1413", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-value-to-get-positive-step-by-step-sum", "url_en": "https://leetcode.com/problems/minimum-value-to-get-positive-step-by-step-sum", "relative_path_cn": "/solution/1400-1499/1413.Minimum%20Value%20to%20Get%20Positive%20Step%20by%20Step%20Sum/README.md", "relative_path_en": "/solution/1400-1499/1413.Minimum%20Value%20to%20Get%20Positive%20Step%20by%20Step%20Sum/README_EN.md", "title_cn": "\u9010\u6b65\u6c42\u548c\u5f97\u5230\u6b63\u6570\u7684\u6700\u5c0f\u503c", "title_en": "Minimum Value to Get Positive Step by Step Sum", "question_title_slug": "minimum-value-to-get-positive-step-by-step-sum", "content_en": "

    Given an array of integers nums, you start with an initial positive value startValue.

    \r\n\r\n

    In each iteration, you calculate the step by step sum of startValue plus elements in nums (from left to right).

    \r\n\r\n

    Return the minimum positive value of startValue such that the step by step sum is never less than 1.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: nums = [-3,2,-3,4,2]\r\nOutput: 5\r\nExplanation: If you choose startValue = 4, in the third iteration your step by step sum is less than 1.\r\n                step by step sum\r\n                startValue = 4 | startValue = 5 | nums\r\n                  (4 -3 ) = 1  | (5 -3 ) = 2    |  -3\r\n                  (1 +2 ) = 3  | (2 +2 ) = 4    |   2\r\n                  (3 -3 ) = 0  | (4 -3 ) = 1    |  -3\r\n                  (0 +4 ) = 4  | (1 +4 ) = 5    |   4\r\n                  (4 +2 ) = 6  | (5 +2 ) = 7    |   2\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: nums = [1,2]\r\nOutput: 1\r\nExplanation: Minimum start value should be positive. \r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: nums = [1,-2,-3]\r\nOutput: 5\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= nums.length <= 100
    • \r\n\t
    • -100 <= nums[i] <= 100
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \u3002\u4f60\u53ef\u4ee5\u9009\u5b9a\u4efb\u610f\u7684 \u6b63\u6570 startValue \u4f5c\u4e3a\u521d\u59cb\u503c\u3002

    \n\n

    \u4f60\u9700\u8981\u4ece\u5de6\u5230\u53f3\u904d\u5386 nums \u6570\u7ec4\uff0c\u5e76\u5c06 startValue \u4f9d\u6b21\u7d2f\u52a0\u4e0a nums \u6570\u7ec4\u4e2d\u7684\u503c\u3002

    \n\n

    \u8bf7\u4f60\u5728\u786e\u4fdd\u7d2f\u52a0\u548c\u59cb\u7ec8\u5927\u4e8e\u7b49\u4e8e 1 \u7684\u524d\u63d0\u4e0b\uff0c\u9009\u51fa\u4e00\u4e2a\u6700\u5c0f\u7684 \u6b63\u6570 \u4f5c\u4e3a startValue \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [-3,2,-3,4,2]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u5982\u679c\u4f60\u9009\u62e9 startValue = 4\uff0c\u5728\u7b2c\u4e09\u6b21\u7d2f\u52a0\u65f6\uff0c\u548c\u5c0f\u4e8e 1 \u3002\n                \u7d2f\u52a0\u6c42\u548c\n                startValue = 4 | startValue = 5 | nums\n                  (4 -3 ) = 1  | (5 -3 ) = 2    |  -3\n                  (1 +2 ) = 3  | (2 +2 ) = 4    |   2\n                  (3 -3 ) = 0  | (4 -3 ) = 1    |  -3\n                  (0 +4 ) = 4  | (1 +4 ) = 5    |   4\n                  (4 +2 ) = 6  | (5 +2 ) = 7    |   2\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u6700\u5c0f\u7684 startValue \u9700\u8981\u662f\u6b63\u6570\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,-2,-3]\n\u8f93\u51fa\uff1a5\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 100
    • \n\t
    • -100 <= nums[i] <= 100
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minStartValue(vector& nums) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minStartValue(int[] nums) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minStartValue(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minStartValue(self, nums: List[int]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minStartValue(int* nums, int numsSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinStartValue(int[] nums) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar minStartValue = function(nums) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef min_start_value(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minStartValue(_ nums: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minStartValue(nums []int) int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minStartValue(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minStartValue(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_start_value(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function minStartValue($nums) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minStartValue(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-start-value nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1413](https://leetcode-cn.com/problems/minimum-value-to-get-positive-step-by-step-sum)", "[\u9010\u6b65\u6c42\u548c\u5f97\u5230\u6b63\u6570\u7684\u6700\u5c0f\u503c](/solution/1400-1499/1413.Minimum%20Value%20to%20Get%20Positive%20Step%20by%20Step%20Sum/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1413](https://leetcode.com/problems/minimum-value-to-get-positive-step-by-step-sum)", "[Minimum Value to Get Positive Step by Step Sum](/solution/1400-1499/1413.Minimum%20Value%20to%20Get%20Positive%20Step%20by%20Step%20Sum/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1513", "frontend_question_id": "1397", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-all-good-strings", "url_en": "https://leetcode.com/problems/find-all-good-strings", "relative_path_cn": "/solution/1300-1399/1397.Find%20All%20Good%20Strings/README.md", "relative_path_en": "/solution/1300-1399/1397.Find%20All%20Good%20Strings/README_EN.md", "title_cn": "\u627e\u5230\u6240\u6709\u597d\u5b57\u7b26\u4e32", "title_en": "Find All Good Strings", "question_title_slug": "find-all-good-strings", "content_en": "

    Given the strings s1 and s2 of size n and the string evil, return the number of good strings.

    \n\n

    A good string has size n, it is alphabetically greater than or equal to s1, it is alphabetically smaller than or equal to s2, and it does not contain the string evil as a substring. Since the answer can be a huge number, return this modulo 109 + 7.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 2, s1 = "aa", s2 = "da", evil = "b"\nOutput: 51 \nExplanation: There are 25 good strings starting with 'a': "aa","ac","ad",...,"az". Then there are 25 good strings starting with 'c': "ca","cc","cd",...,"cz" and finally there is one good string starting with 'd': "da". \n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 8, s1 = "leetcode", s2 = "leetgoes", evil = "leet"\nOutput: 0 \nExplanation: All strings greater than or equal to s1 and smaller than or equal to s2 start with the prefix "leet", therefore, there is not any good string.\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 2, s1 = "gx", s2 = "gz", evil = "x"\nOutput: 2\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • s1.length == n
    • \n\t
    • s2.length == n
    • \n\t
    • s1 <= s2
    • \n\t
    • 1 <= n <= 500
    • \n\t
    • 1 <= evil.length <= 50
    • \n\t
    • All strings consist of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u957f\u5ea6\u4e3a n \u7684\u5b57\u7b26\u4e32 s1 \u548c s2 \uff0c\u4ee5\u53ca\u4e00\u4e2a\u5b57\u7b26\u4e32 evil \u3002\u8bf7\u4f60\u8fd4\u56de \u597d\u5b57\u7b26\u4e32 \u7684\u6570\u76ee\u3002

    \n\n

    \u597d\u5b57\u7b26\u4e32 \u7684\u5b9a\u4e49\u4e3a\uff1a\u5b83\u7684\u957f\u5ea6\u4e3a n \uff0c\u5b57\u5178\u5e8f\u5927\u4e8e\u7b49\u4e8e s1 \uff0c\u5b57\u5178\u5e8f\u5c0f\u4e8e\u7b49\u4e8e s2 \uff0c\u4e14\u4e0d\u5305\u542b evil \u4e3a\u5b50\u5b57\u7b26\u4e32\u3002

    \n\n

    \u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u5f88\u5927\uff0c\u8bf7\u4f60\u8fd4\u56de\u7b54\u6848\u5bf9 10^9 + 7 \u53d6\u4f59\u7684\u7ed3\u679c\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1an = 2, s1 = "aa", s2 = "da", evil = "b"\n\u8f93\u51fa\uff1a51 \n\u89e3\u91ca\uff1a\u603b\u5171\u6709 25 \u4e2a\u4ee5 'a' \u5f00\u5934\u7684\u597d\u5b57\u7b26\u4e32\uff1a"aa"\uff0c"ac"\uff0c"ad"\uff0c...\uff0c"az"\u3002\u8fd8\u6709 25 \u4e2a\u4ee5 'c' \u5f00\u5934\u7684\u597d\u5b57\u7b26\u4e32\uff1a"ca"\uff0c"cc"\uff0c"cd"\uff0c...\uff0c"cz"\u3002\u6700\u540e\uff0c\u8fd8\u6709\u4e00\u4e2a\u4ee5 'd' \u5f00\u5934\u7684\u597d\u5b57\u7b26\u4e32\uff1a"da"\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1an = 8, s1 = "leetcode", s2 = "leetgoes", evil = "leet"\n\u8f93\u51fa\uff1a0 \n\u89e3\u91ca\uff1a\u6240\u6709\u5b57\u5178\u5e8f\u5927\u4e8e\u7b49\u4e8e s1 \u4e14\u5c0f\u4e8e\u7b49\u4e8e s2 \u7684\u5b57\u7b26\u4e32\u90fd\u4ee5 evil \u5b57\u7b26\u4e32 "leet" \u5f00\u5934\u3002\u6240\u4ee5\u6ca1\u6709\u597d\u5b57\u7b26\u4e32\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1an = 2, s1 = "gx", s2 = "gz", evil = "x"\n\u8f93\u51fa\uff1a2\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • s1.length == n
    • \n\t
    • s2.length == n
    • \n\t
    • s1 <= s2
    • \n\t
    • 1 <= n <= 500
    • \n\t
    • 1 <= evil.length <= 50
    • \n\t
    • \u6240\u6709\u5b57\u7b26\u4e32\u90fd\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findGoodStrings(int n, string s1, string s2, string evil) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findGoodStrings(int n, String s1, String s2, String evil) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findGoodStrings(self, n, s1, s2, evil):\n \"\"\"\n :type n: int\n :type s1: str\n :type s2: str\n :type evil: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findGoodStrings(self, n: int, s1: str, s2: str, evil: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findGoodStrings(int n, char * s1, char * s2, char * evil){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindGoodStrings(int n, string s1, string s2, string evil) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {string} s1\n * @param {string} s2\n * @param {string} evil\n * @return {number}\n */\nvar findGoodStrings = function(n, s1, s2, evil) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {String} s1\n# @param {String} s2\n# @param {String} evil\n# @return {Integer}\ndef find_good_strings(n, s1, s2, evil)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findGoodStrings(_ n: Int, _ s1: String, _ s2: String, _ evil: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findGoodStrings(n int, s1 string, s2 string, evil string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findGoodStrings(n: Int, s1: String, s2: String, evil: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findGoodStrings(n: Int, s1: String, s2: String, evil: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_good_strings(n: i32, s1: String, s2: String, evil: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param String $s1\n * @param String $s2\n * @param String $evil\n * @return Integer\n */\n function findGoodStrings($n, $s1, $s2, $evil) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findGoodStrings(n: number, s1: string, s2: string, evil: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-good-strings n s1 s2 evil)\n (-> exact-integer? string? string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1397](https://leetcode-cn.com/problems/find-all-good-strings)", "[\u627e\u5230\u6240\u6709\u597d\u5b57\u7b26\u4e32](/solution/1300-1399/1397.Find%20All%20Good%20Strings/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1397](https://leetcode.com/problems/find-all-good-strings)", "[Find All Good Strings](/solution/1300-1399/1397.Find%20All%20Good%20Strings/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1512", "frontend_question_id": "1396", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/design-underground-system", "url_en": "https://leetcode.com/problems/design-underground-system", "relative_path_cn": "/solution/1300-1399/1396.Design%20Underground%20System/README.md", "relative_path_en": "/solution/1300-1399/1396.Design%20Underground%20System/README_EN.md", "title_cn": "\u8bbe\u8ba1\u5730\u94c1\u7cfb\u7edf", "title_en": "Design Underground System", "question_title_slug": "design-underground-system", "content_en": "

    An underground railway system is keeping track of customer travel times between different stations. They are using this data to calculate the average time it takes to travel from one station to another.

    \n\n

    Implement the UndergroundSystem class:

    \n\n
      \n\t
    • void checkIn(int id, string stationName, int t)\n\n\t
        \n\t\t
      • A customer with a card ID equal to id, checks in at the station stationName at time t.
      • \n\t\t
      • A customer can only be checked into one place at a time.
      • \n\t
      \n\t
    • \n\t
    • void checkOut(int id, string stationName, int t)\n\t
        \n\t\t
      • A customer with a card ID equal to id, checks out from the station stationName at time t.
      • \n\t
      \n\t
    • \n\t
    • double getAverageTime(string startStation, string endStation)\n\t
        \n\t\t
      • Returns the average time it takes to travel from startStation to endStation.
      • \n\t\t
      • The average time is computed from all the previous traveling times from startStation to endStation that happened directly, meaning a check in at startStation followed by a check out from endStation.
      • \n\t\t
      • The time it takes to travel from startStation to endStation may be different from the time it takes to travel from endStation to startStation.
      • \n\t\t
      • There will be at least one customer that has traveled from startStation to endStation before getAverageTime is called.
      • \n\t
      \n\t
    • \n
    \n\n

    You may assume all calls to the checkIn and checkOut methods are consistent. If a customer checks in at time t1 then checks out at time t2, then t1 < t2. All events happen in chronological order.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["UndergroundSystem","checkIn","checkIn","checkIn","checkOut","checkOut","checkOut","getAverageTime","getAverageTime","checkIn","getAverageTime","checkOut","getAverageTime"]\n[[],[45,"Leyton",3],[32,"Paradise",8],[27,"Leyton",10],[45,"Waterloo",15],[27,"Waterloo",20],[32,"Cambridge",22],["Paradise","Cambridge"],["Leyton","Waterloo"],[10,"Leyton",24],["Leyton","Waterloo"],[10,"Waterloo",38],["Leyton","Waterloo"]]\n\nOutput\n[null,null,null,null,null,null,null,14.00000,11.00000,null,11.00000,null,12.00000]\n\nExplanation\nUndergroundSystem undergroundSystem = new UndergroundSystem();\nundergroundSystem.checkIn(45, "Leyton", 3);\nundergroundSystem.checkIn(32, "Paradise", 8);\nundergroundSystem.checkIn(27, "Leyton", 10);\nundergroundSystem.checkOut(45, "Waterloo", 15);  // Customer 45 "Leyton" -> "Waterloo" in 15-3 = 12\nundergroundSystem.checkOut(27, "Waterloo", 20);  // Customer 27 "Leyton" -> "Waterloo" in 20-10 = 10\nundergroundSystem.checkOut(32, "Cambridge", 22); // Customer 32 "Paradise" -> "Cambridge" in 22-8 = 14\nundergroundSystem.getAverageTime("Paradise", "Cambridge"); // return 14.00000. One trip "Paradise" -> "Cambridge", (14) / 1 = 14\nundergroundSystem.getAverageTime("Leyton", "Waterloo");    // return 11.00000. Two trips "Leyton" -> "Waterloo", (10 + 12) / 2 = 11\nundergroundSystem.checkIn(10, "Leyton", 24);\nundergroundSystem.getAverageTime("Leyton", "Waterloo");    // return 11.00000\nundergroundSystem.checkOut(10, "Waterloo", 38);  // Customer 10 "Leyton" -> "Waterloo" in 38-24 = 14\nundergroundSystem.getAverageTime("Leyton", "Waterloo");    // return 12.00000. Three trips "Leyton" -> "Waterloo", (10 + 12 + 14) / 3 = 12\n
    \n\n

    Example 2:

    \n\n
    \nInput\n["UndergroundSystem","checkIn","checkOut","getAverageTime","checkIn","checkOut","getAverageTime","checkIn","checkOut","getAverageTime"]\n[[],[10,"Leyton",3],[10,"Paradise",8],["Leyton","Paradise"],[5,"Leyton",10],[5,"Paradise",16],["Leyton","Paradise"],[2,"Leyton",21],[2,"Paradise",30],["Leyton","Paradise"]]\n\nOutput\n[null,null,null,5.00000,null,null,5.50000,null,null,6.66667]\n\nExplanation\nUndergroundSystem undergroundSystem = new UndergroundSystem();\nundergroundSystem.checkIn(10, "Leyton", 3);\nundergroundSystem.checkOut(10, "Paradise", 8); // Customer 10 "Leyton" -> "Paradise" in 8-3 = 5\nundergroundSystem.getAverageTime("Leyton", "Paradise"); // return 5.00000, (5) / 1 = 5\nundergroundSystem.checkIn(5, "Leyton", 10);\nundergroundSystem.checkOut(5, "Paradise", 16); // Customer 5 "Leyton" -> "Paradise" in 16-10 = 6\nundergroundSystem.getAverageTime("Leyton", "Paradise"); // return 5.50000, (5 + 6) / 2 = 5.5\nundergroundSystem.checkIn(2, "Leyton", 21);\nundergroundSystem.checkOut(2, "Paradise", 30); // Customer 2 "Leyton" -> "Paradise" in 30-21 = 9\nundergroundSystem.getAverageTime("Leyton", "Paradise"); // return 6.66667, (5 + 6 + 9) / 3 = 6.66667\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= id, t <= 106
    • \n\t
    • 1 <= stationName.length, startStation.length, endStation.length <= 10
    • \n\t
    • All strings consist of uppercase and lowercase English letters and digits.
    • \n\t
    • There will be at most 2 * 104 calls in total to checkIn, checkOut, and getAverageTime.
    • \n\t
    • Answers within 10-5 of the actual value will be accepted.
    • \n
    \n", "content_cn": "

    \u8bf7\u4f60\u5b9e\u73b0\u4e00\u4e2a\u7c7b UndergroundSystem \uff0c\u5b83\u652f\u6301\u4ee5\u4e0b 3 \u79cd\u65b9\u6cd5\uff1a

    \n\n

    1. checkIn(int id, string stationName, int t)

    \n\n
      \n\t
    • \u7f16\u53f7\u4e3a id \u7684\u4e58\u5ba2\u5728 t \u65f6\u523b\u8fdb\u5165\u5730\u94c1\u7ad9 stationName \u3002
    • \n\t
    • \u4e00\u4e2a\u4e58\u5ba2\u5728\u540c\u4e00\u65f6\u95f4\u53ea\u80fd\u5728\u4e00\u4e2a\u5730\u94c1\u7ad9\u8fdb\u5165\u6216\u8005\u79bb\u5f00\u3002
    • \n
    \n\n

    2. checkOut(int id, string stationName, int t)

    \n\n
      \n\t
    • \u7f16\u53f7\u4e3a id \u7684\u4e58\u5ba2\u5728 t \u65f6\u523b\u79bb\u5f00\u5730\u94c1\u7ad9 stationName \u3002
    • \n
    \n\n

    3. getAverageTime(string startStation, string endStation) 

    \n\n
      \n\t
    • \u8fd4\u56de\u4ece\u5730\u94c1\u7ad9 startStation \u5230\u5730\u94c1\u7ad9 endStation \u7684\u5e73\u5747\u82b1\u8d39\u65f6\u95f4\u3002
    • \n\t
    • \u5e73\u5747\u65f6\u95f4\u8ba1\u7b97\u7684\u884c\u7a0b\u5305\u62ec\u5f53\u524d\u4e3a\u6b62\u6240\u6709\u4ece startStation \u76f4\u63a5\u5230\u8fbe endStation \u7684\u884c\u7a0b\u3002
    • \n\t
    • \u8c03\u7528 getAverageTime \u65f6\uff0c\u8be2\u95ee\u7684\u8def\u7ebf\u81f3\u5c11\u5305\u542b\u4e00\u8d9f\u884c\u7a0b\u3002
    • \n
    \n\n

    \u4f60\u53ef\u4ee5\u5047\u8bbe\u6240\u6709\u5bf9 checkIn \u548c checkOut \u7684\u8c03\u7528\u90fd\u662f\u7b26\u5408\u903b\u8f91\u7684\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u5982\u679c\u4e00\u4e2a\u987e\u5ba2\u5728 t1 \u65f6\u523b\u5230\u8fbe\u67d0\u4e2a\u5730\u94c1\u7ad9\uff0c\u90a3\u4e48\u4ed6\u79bb\u5f00\u7684\u65f6\u95f4 t2 \u4e00\u5b9a\u6ee1\u8db3 t2 > t1 \u3002\u6240\u6709\u7684\u4e8b\u4ef6\u90fd\u6309\u65f6\u95f4\u987a\u5e8f\u7ed9\u51fa\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1a\n["UndergroundSystem","checkIn","checkIn","checkIn","checkOut","checkOut","checkOut","getAverageTime","getAverageTime","checkIn","getAverageTime","checkOut","getAverageTime"]\n[[],[45,"Leyton",3],[32,"Paradise",8],[27,"Leyton",10],[45,"Waterloo",15],[27,"Waterloo",20],[32,"Cambridge",22],["Paradise","Cambridge"],["Leyton","Waterloo"],[10,"Leyton",24],["Leyton","Waterloo"],[10,"Waterloo",38],["Leyton","Waterloo"]]\n\n\u8f93\u51fa\uff1a\n[null,null,null,null,null,null,null,14.0,11.0,null,11.0,null,12.0]\n\n\u89e3\u91ca\uff1a\nUndergroundSystem undergroundSystem = new UndergroundSystem();\nundergroundSystem.checkIn(45, "Leyton", 3);\nundergroundSystem.checkIn(32, "Paradise", 8);\nundergroundSystem.checkIn(27, "Leyton", 10);\nundergroundSystem.checkOut(45, "Waterloo", 15);\nundergroundSystem.checkOut(27, "Waterloo", 20);\nundergroundSystem.checkOut(32, "Cambridge", 22);\nundergroundSystem.getAverageTime("Paradise", "Cambridge");       // \u8fd4\u56de 14.0\u3002\u4ece "Paradise"\uff08\u65f6\u523b 8\uff09\u5230 "Cambridge"(\u65f6\u523b 22)\u7684\u884c\u7a0b\u53ea\u6709\u4e00\u8d9f\nundergroundSystem.getAverageTime("Leyton", "Waterloo");          // \u8fd4\u56de 11.0\u3002\u603b\u5171\u6709 2 \u8eba\u4ece "Leyton" \u5230 "Waterloo" \u7684\u884c\u7a0b\uff0c\u7f16\u53f7\u4e3a id=45 \u7684\u4e58\u5ba2\u51fa\u53d1\u4e8e time=3 \u5230\u8fbe\u4e8e time=15\uff0c\u7f16\u53f7\u4e3a id=27 \u7684\u4e58\u5ba2\u4e8e time=10 \u51fa\u53d1\u4e8e time=20 \u5230\u8fbe\u3002\u6240\u4ee5\u5e73\u5747\u65f6\u95f4\u4e3a ( (15-3) + (20-10) ) / 2 = 11.0\nundergroundSystem.checkIn(10, "Leyton", 24);\nundergroundSystem.getAverageTime("Leyton", "Waterloo");          // \u8fd4\u56de 11.0\nundergroundSystem.checkOut(10, "Waterloo", 38);\nundergroundSystem.getAverageTime("Leyton", "Waterloo");          // \u8fd4\u56de 12.0
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u603b\u5171\u6700\u591a\u6709 20000 \u6b21\u64cd\u4f5c\u3002
    • \n\t
    • 1 <= id, t <= 10^6
    • \n\t
    • \u6240\u6709\u7684\u5b57\u7b26\u4e32\u5305\u542b\u5927\u5199\u5b57\u6bcd\uff0c\u5c0f\u5199\u5b57\u6bcd\u548c\u6570\u5b57\u3002
    • \n\t
    • 1 <= stationName.length <= 10
    • \n\t
    • \u4e0e\u6807\u51c6\u7b54\u6848\u8bef\u5dee\u5728 10^-5 \u4ee5\u5185\u7684\u7ed3\u679c\u90fd\u89c6\u4e3a\u6b63\u786e\u7ed3\u679c\u3002
    • \n
    \n", "tags_en": ["Design"], "tags_cn": ["\u8bbe\u8ba1"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class UndergroundSystem {\npublic:\n UndergroundSystem() {\n\n }\n \n void checkIn(int id, string stationName, int t) {\n\n }\n \n void checkOut(int id, string stationName, int t) {\n\n }\n \n double getAverageTime(string startStation, string endStation) {\n\n }\n};\n\n/**\n * Your UndergroundSystem object will be instantiated and called as such:\n * UndergroundSystem* obj = new UndergroundSystem();\n * obj->checkIn(id,stationName,t);\n * obj->checkOut(id,stationName,t);\n * double param_3 = obj->getAverageTime(startStation,endStation);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class UndergroundSystem {\n\n public UndergroundSystem() {\n\n }\n \n public void checkIn(int id, String stationName, int t) {\n\n }\n \n public void checkOut(int id, String stationName, int t) {\n\n }\n \n public double getAverageTime(String startStation, String endStation) {\n\n }\n}\n\n/**\n * Your UndergroundSystem object will be instantiated and called as such:\n * UndergroundSystem obj = new UndergroundSystem();\n * obj.checkIn(id,stationName,t);\n * obj.checkOut(id,stationName,t);\n * double param_3 = obj.getAverageTime(startStation,endStation);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class UndergroundSystem(object):\n\n def __init__(self):\n\n\n def checkIn(self, id, stationName, t):\n \"\"\"\n :type id: int\n :type stationName: str\n :type t: int\n :rtype: None\n \"\"\"\n\n\n def checkOut(self, id, stationName, t):\n \"\"\"\n :type id: int\n :type stationName: str\n :type t: int\n :rtype: None\n \"\"\"\n\n\n def getAverageTime(self, startStation, endStation):\n \"\"\"\n :type startStation: str\n :type endStation: str\n :rtype: float\n \"\"\"\n\n\n\n# Your UndergroundSystem object will be instantiated and called as such:\n# obj = UndergroundSystem()\n# obj.checkIn(id,stationName,t)\n# obj.checkOut(id,stationName,t)\n# param_3 = obj.getAverageTime(startStation,endStation)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class UndergroundSystem:\n\n def __init__(self):\n\n\n def checkIn(self, id: int, stationName: str, t: int) -> None:\n\n\n def checkOut(self, id: int, stationName: str, t: int) -> None:\n\n\n def getAverageTime(self, startStation: str, endStation: str) -> float:\n\n\n\n# Your UndergroundSystem object will be instantiated and called as such:\n# obj = UndergroundSystem()\n# obj.checkIn(id,stationName,t)\n# obj.checkOut(id,stationName,t)\n# param_3 = obj.getAverageTime(startStation,endStation)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} UndergroundSystem;\n\n\nUndergroundSystem* undergroundSystemCreate() {\n \n}\n\nvoid undergroundSystemCheckIn(UndergroundSystem* obj, int id, char * stationName, int t) {\n \n}\n\nvoid undergroundSystemCheckOut(UndergroundSystem* obj, int id, char * stationName, int t) {\n \n}\n\ndouble undergroundSystemGetAverageTime(UndergroundSystem* obj, char * startStation, char * endStation) {\n \n}\n\nvoid undergroundSystemFree(UndergroundSystem* obj) {\n \n}\n\n/**\n * Your UndergroundSystem struct will be instantiated and called as such:\n * UndergroundSystem* obj = undergroundSystemCreate();\n * undergroundSystemCheckIn(obj, id, stationName, t);\n \n * undergroundSystemCheckOut(obj, id, stationName, t);\n \n * double param_3 = undergroundSystemGetAverageTime(obj, startStation, endStation);\n \n * undergroundSystemFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class UndergroundSystem {\n\n public UndergroundSystem() {\n\n }\n \n public void CheckIn(int id, string stationName, int t) {\n\n }\n \n public void CheckOut(int id, string stationName, int t) {\n\n }\n \n public double GetAverageTime(string startStation, string endStation) {\n\n }\n}\n\n/**\n * Your UndergroundSystem object will be instantiated and called as such:\n * UndergroundSystem obj = new UndergroundSystem();\n * obj.CheckIn(id,stationName,t);\n * obj.CheckOut(id,stationName,t);\n * double param_3 = obj.GetAverageTime(startStation,endStation);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "\nvar UndergroundSystem = function() {\n\n};\n\n/** \n * @param {number} id \n * @param {string} stationName \n * @param {number} t\n * @return {void}\n */\nUndergroundSystem.prototype.checkIn = function(id, stationName, t) {\n\n};\n\n/** \n * @param {number} id \n * @param {string} stationName \n * @param {number} t\n * @return {void}\n */\nUndergroundSystem.prototype.checkOut = function(id, stationName, t) {\n\n};\n\n/** \n * @param {string} startStation \n * @param {string} endStation\n * @return {number}\n */\nUndergroundSystem.prototype.getAverageTime = function(startStation, endStation) {\n\n};\n\n/**\n * Your UndergroundSystem object will be instantiated and called as such:\n * var obj = new UndergroundSystem()\n * obj.checkIn(id,stationName,t)\n * obj.checkOut(id,stationName,t)\n * var param_3 = obj.getAverageTime(startStation,endStation)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class UndergroundSystem\n def initialize()\n\n end\n\n\n=begin\n :type id: Integer\n :type station_name: String\n :type t: Integer\n :rtype: Void\n=end\n def check_in(id, station_name, t)\n\n end\n\n\n=begin\n :type id: Integer\n :type station_name: String\n :type t: Integer\n :rtype: Void\n=end\n def check_out(id, station_name, t)\n\n end\n\n\n=begin\n :type start_station: String\n :type end_station: String\n :rtype: Float\n=end\n def get_average_time(start_station, end_station)\n\n end\n\n\nend\n\n# Your UndergroundSystem object will be instantiated and called as such:\n# obj = UndergroundSystem.new()\n# obj.check_in(id, station_name, t)\n# obj.check_out(id, station_name, t)\n# param_3 = obj.get_average_time(start_station, end_station)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass UndergroundSystem {\n\n init() {\n\n }\n \n func checkIn(_ id: Int, _ stationName: String, _ t: Int) {\n\n }\n \n func checkOut(_ id: Int, _ stationName: String, _ t: Int) {\n\n }\n \n func getAverageTime(_ startStation: String, _ endStation: String) -> Double {\n\n }\n}\n\n/**\n * Your UndergroundSystem object will be instantiated and called as such:\n * let obj = UndergroundSystem()\n * obj.checkIn(id, stationName, t)\n * obj.checkOut(id, stationName, t)\n * let ret_3: Double = obj.getAverageTime(startStation, endStation)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type UndergroundSystem struct {\n\n}\n\n\nfunc Constructor() UndergroundSystem {\n\n}\n\n\nfunc (this *UndergroundSystem) CheckIn(id int, stationName string, t int) {\n\n}\n\n\nfunc (this *UndergroundSystem) CheckOut(id int, stationName string, t int) {\n\n}\n\n\nfunc (this *UndergroundSystem) GetAverageTime(startStation string, endStation string) float64 {\n\n}\n\n\n/**\n * Your UndergroundSystem object will be instantiated and called as such:\n * obj := Constructor();\n * obj.CheckIn(id,stationName,t);\n * obj.CheckOut(id,stationName,t);\n * param_3 := obj.GetAverageTime(startStation,endStation);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class UndergroundSystem() {\n\n def checkIn(id: Int, stationName: String, t: Int) {\n\n }\n\n def checkOut(id: Int, stationName: String, t: Int) {\n\n }\n\n def getAverageTime(startStation: String, endStation: String): Double = {\n\n }\n\n}\n\n/**\n * Your UndergroundSystem object will be instantiated and called as such:\n * var obj = new UndergroundSystem()\n * obj.checkIn(id,stationName,t)\n * obj.checkOut(id,stationName,t)\n * var param_3 = obj.getAverageTime(startStation,endStation)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class UndergroundSystem() {\n\n fun checkIn(id: Int, stationName: String, t: Int) {\n\n }\n\n fun checkOut(id: Int, stationName: String, t: Int) {\n\n }\n\n fun getAverageTime(startStation: String, endStation: String): Double {\n\n }\n\n}\n\n/**\n * Your UndergroundSystem object will be instantiated and called as such:\n * var obj = UndergroundSystem()\n * obj.checkIn(id,stationName,t)\n * obj.checkOut(id,stationName,t)\n * var param_3 = obj.getAverageTime(startStation,endStation)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct UndergroundSystem {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl UndergroundSystem {\n\n fn new() -> Self {\n\n }\n \n fn check_in(&self, id: i32, station_name: String, t: i32) {\n\n }\n \n fn check_out(&self, id: i32, station_name: String, t: i32) {\n\n }\n \n fn get_average_time(&self, start_station: String, end_station: String) -> f64 {\n\n }\n}\n\n/**\n * Your UndergroundSystem object will be instantiated and called as such:\n * let obj = UndergroundSystem::new();\n * obj.check_in(id, stationName, t);\n * obj.check_out(id, stationName, t);\n * let ret_3: f64 = obj.get_average_time(startStation, endStation);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class UndergroundSystem {\n /**\n */\n function __construct() {\n\n }\n\n /**\n * @param Integer $id\n * @param String $stationName\n * @param Integer $t\n * @return NULL\n */\n function checkIn($id, $stationName, $t) {\n\n }\n\n /**\n * @param Integer $id\n * @param String $stationName\n * @param Integer $t\n * @return NULL\n */\n function checkOut($id, $stationName, $t) {\n\n }\n\n /**\n * @param String $startStation\n * @param String $endStation\n * @return Float\n */\n function getAverageTime($startStation, $endStation) {\n\n }\n}\n\n/**\n * Your UndergroundSystem object will be instantiated and called as such:\n * $obj = UndergroundSystem();\n * $obj->checkIn($id, $stationName, $t);\n * $obj->checkOut($id, $stationName, $t);\n * $ret_3 = $obj->getAverageTime($startStation, $endStation);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class UndergroundSystem {\n constructor() {\n\n }\n\n checkIn(id: number, stationName: string, t: number): void {\n\n }\n\n checkOut(id: number, stationName: string, t: number): void {\n\n }\n\n getAverageTime(startStation: string, endStation: string): number {\n\n }\n}\n\n/**\n * Your UndergroundSystem object will be instantiated and called as such:\n * var obj = new UndergroundSystem()\n * obj.checkIn(id,stationName,t)\n * obj.checkOut(id,stationName,t)\n * var param_3 = obj.getAverageTime(startStation,endStation)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define underground-system%\n (class object%\n (super-new)\n (init-field)\n \n ; check-in : exact-integer? string? exact-integer? -> void?\n (define/public (check-in id stationName t)\n\n )\n ; check-out : exact-integer? string? exact-integer? -> void?\n (define/public (check-out id stationName t)\n\n )\n ; get-average-time : string? string? -> flonum?\n (define/public (get-average-time startStation endStation)\n\n )))\n\n;; Your underground-system% object will be instantiated and called as such:\n;; (define obj (new underground-system%))\n;; (send obj check-in id station-name t)\n;; (send obj check-out id station-name t)\n;; (define param_3 (send obj get-average-time start-station end-station))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1396](https://leetcode-cn.com/problems/design-underground-system)", "[\u8bbe\u8ba1\u5730\u94c1\u7cfb\u7edf](/solution/1300-1399/1396.Design%20Underground%20System/README.md)", "`\u8bbe\u8ba1`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1396](https://leetcode.com/problems/design-underground-system)", "[Design Underground System](/solution/1300-1399/1396.Design%20Underground%20System/README_EN.md)", "`Design`", "Medium", ""]}, {"question_id": "1511", "frontend_question_id": "1395", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-number-of-teams", "url_en": "https://leetcode.com/problems/count-number-of-teams", "relative_path_cn": "/solution/1300-1399/1395.Count%20Number%20of%20Teams/README.md", "relative_path_en": "/solution/1300-1399/1395.Count%20Number%20of%20Teams/README_EN.md", "title_cn": "\u7edf\u8ba1\u4f5c\u6218\u5355\u4f4d\u6570", "title_en": "Count Number of Teams", "question_title_slug": "count-number-of-teams", "content_en": "

    There are n soldiers standing in a line. Each soldier is assigned a unique rating value.

    \n\n

    You have to form a team of 3 soldiers amongst them under the following rules:

    \n\n
      \n\t
    • Choose 3 soldiers with index (i, j, k) with rating (rating[i], rating[j], rating[k]).
    • \n\t
    • A team is valid if: (rating[i] < rating[j] < rating[k]) or (rating[i] > rating[j] > rating[k]) where (0 <= i < j < k < n).
    • \n
    \n\n

    Return the number of teams you can form given the conditions. (soldiers can be part of multiple teams).

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: rating = [2,5,3,4,1]\nOutput: 3\nExplanation: We can form three teams given the conditions. (2,3,4), (5,4,1), (5,3,1). \n
    \n\n

    Example 2:

    \n\n
    \nInput: rating = [2,1,3]\nOutput: 0\nExplanation: We can't form any team given the conditions.\n
    \n\n

    Example 3:

    \n\n
    \nInput: rating = [1,2,3,4]\nOutput: 4\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == rating.length
    • \n\t
    • 3 <= n <= 1000
    • \n\t
    • 1 <= rating[i] <= 105
    • \n\t
    • All the integers in rating are unique.
    • \n
    \n", "content_cn": "

    \u00a0n \u540d\u58eb\u5175\u7ad9\u6210\u4e00\u6392\u3002\u6bcf\u4e2a\u58eb\u5175\u90fd\u6709\u4e00\u4e2a \u72ec\u4e00\u65e0\u4e8c \u7684\u8bc4\u5206 rating \u3002

    \n\n

    \u6bcf 3 \u4e2a\u58eb\u5175\u53ef\u4ee5\u7ec4\u6210\u4e00\u4e2a\u4f5c\u6218\u5355\u4f4d\uff0c\u5206\u7ec4\u89c4\u5219\u5982\u4e0b\uff1a

    \n\n
      \n\t
    • \u4ece\u961f\u4f0d\u4e2d\u9009\u51fa\u4e0b\u6807\u5206\u522b\u4e3a i\u3001j\u3001k \u7684 3 \u540d\u58eb\u5175\uff0c\u4ed6\u4eec\u7684\u8bc4\u5206\u5206\u522b\u4e3a rating[i]\u3001rating[j]\u3001rating[k]
    • \n\t
    • \u4f5c\u6218\u5355\u4f4d\u9700\u6ee1\u8db3\uff1a rating[i] < rating[j] < rating[k] \u6216\u8005 rating[i] > rating[j] > rating[k] \uff0c\u5176\u4e2d\u00a0 0\u00a0<= i <\u00a0j <\u00a0k <\u00a0n
    • \n
    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u6309\u4e0a\u8ff0\u6761\u4ef6\u53ef\u4ee5\u7ec4\u5efa\u7684\u4f5c\u6218\u5355\u4f4d\u6570\u91cf\u3002\u6bcf\u4e2a\u58eb\u5175\u90fd\u53ef\u4ee5\u662f\u591a\u4e2a\u4f5c\u6218\u5355\u4f4d\u7684\u4e00\u90e8\u5206\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1arating = [2,5,3,4,1]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6211\u4eec\u53ef\u4ee5\u7ec4\u5efa\u4e09\u4e2a\u4f5c\u6218\u5355\u4f4d (2,3,4)\u3001(5,4,1)\u3001(5,3,1) \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1arating = [2,1,3]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6839\u636e\u9898\u76ee\u6761\u4ef6\uff0c\u6211\u4eec\u65e0\u6cd5\u7ec4\u5efa\u4f5c\u6218\u5355\u4f4d\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1arating = [1,2,3,4]\n\u8f93\u51fa\uff1a4\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == rating.length
    • \n\t
    • 3 <= n <= 1000
    • \n\t
    • 1 <= rating[i] <= 10^5
    • \n\t
    • rating\u00a0\u4e2d\u7684\u5143\u7d20\u90fd\u662f\u552f\u4e00\u7684
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numTeams(vector& rating) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numTeams(int[] rating) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numTeams(self, rating):\n \"\"\"\n :type rating: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numTeams(self, rating: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numTeams(int* rating, int ratingSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumTeams(int[] rating) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} rating\n * @return {number}\n */\nvar numTeams = function(rating) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} rating\n# @return {Integer}\ndef num_teams(rating)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numTeams(_ rating: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numTeams(rating []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numTeams(rating: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numTeams(rating: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_teams(rating: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $rating\n * @return Integer\n */\n function numTeams($rating) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numTeams(rating: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-teams rating)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1395](https://leetcode-cn.com/problems/count-number-of-teams)", "[\u7edf\u8ba1\u4f5c\u6218\u5355\u4f4d\u6570](/solution/1300-1399/1395.Count%20Number%20of%20Teams/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1395](https://leetcode.com/problems/count-number-of-teams)", "[Count Number of Teams](/solution/1300-1399/1395.Count%20Number%20of%20Teams/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "1510", "frontend_question_id": "1394", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-lucky-integer-in-an-array", "url_en": "https://leetcode.com/problems/find-lucky-integer-in-an-array", "relative_path_cn": "/solution/1300-1399/1394.Find%20Lucky%20Integer%20in%20an%20Array/README.md", "relative_path_en": "/solution/1300-1399/1394.Find%20Lucky%20Integer%20in%20an%20Array/README_EN.md", "title_cn": "\u627e\u51fa\u6570\u7ec4\u4e2d\u7684\u5e78\u8fd0\u6570", "title_en": "Find Lucky Integer in an Array", "question_title_slug": "find-lucky-integer-in-an-array", "content_en": "

    Given an array of integers arr, a lucky integer is an integer which has a frequency in the array equal to its value.

    \r\n\r\n

    Return a lucky integer in the array. If there are multiple lucky integers return the largest of them. If there is no lucky integer return -1.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: arr = [2,2,3,4]\r\nOutput: 2\r\nExplanation: The only lucky number in the array is 2 because frequency[2] == 2.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: arr = [1,2,2,3,3,3]\r\nOutput: 3\r\nExplanation: 1, 2 and 3 are all lucky numbers, return the largest of them.\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: arr = [2,2,2,3,3]\r\nOutput: -1\r\nExplanation: There are no lucky numbers in the array.\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: arr = [5]\r\nOutput: -1\r\n
    \r\n\r\n

    Example 5:

    \r\n\r\n
    \r\nInput: arr = [7,7,7,7,7,7,7]\r\nOutput: 7\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= arr.length <= 500
    • \r\n\t
    • 1 <= arr[i] <= 500
    • \r\n
    ", "content_cn": "

    \u5728\u6574\u6570\u6570\u7ec4\u4e2d\uff0c\u5982\u679c\u4e00\u4e2a\u6574\u6570\u7684\u51fa\u73b0\u9891\u6b21\u548c\u5b83\u7684\u6570\u503c\u5927\u5c0f\u76f8\u7b49\uff0c\u6211\u4eec\u5c31\u79f0\u8fd9\u4e2a\u6574\u6570\u4e3a\u300c\u5e78\u8fd0\u6570\u300d\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr\uff0c\u8bf7\u4f60\u4ece\u4e2d\u627e\u51fa\u5e76\u8fd4\u56de\u4e00\u4e2a\u5e78\u8fd0\u6570\u3002

    \n\n
      \n\t
    • \u5982\u679c\u6570\u7ec4\u4e2d\u5b58\u5728\u591a\u4e2a\u5e78\u8fd0\u6570\uff0c\u53ea\u9700\u8fd4\u56de \u6700\u5927 \u7684\u90a3\u4e2a\u3002
    • \n\t
    • \u5982\u679c\u6570\u7ec4\u4e2d\u4e0d\u542b\u5e78\u8fd0\u6570\uff0c\u5219\u8fd4\u56de -1 \u3002
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [2,2,3,4]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6570\u7ec4\u4e2d\u552f\u4e00\u7684\u5e78\u8fd0\u6570\u662f 2 \uff0c\u56e0\u4e3a\u6570\u503c 2 \u7684\u51fa\u73b0\u9891\u6b21\u4e5f\u662f 2 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [1,2,2,3,3,3]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a1\u30012 \u4ee5\u53ca 3 \u90fd\u662f\u5e78\u8fd0\u6570\uff0c\u53ea\u9700\u8981\u8fd4\u56de\u5176\u4e2d\u6700\u5927\u7684 3 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [2,2,2,3,3]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u6570\u7ec4\u4e2d\u4e0d\u5b58\u5728\u5e78\u8fd0\u6570\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [5]\n\u8f93\u51fa\uff1a-1\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [7,7,7,7,7,7,7]\n\u8f93\u51fa\uff1a7\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= arr.length <= 500
    • \n\t
    • 1 <= arr[i] <= 500
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findLucky(vector& arr) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findLucky(int[] arr) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findLucky(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findLucky(self, arr: List[int]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findLucky(int* arr, int arrSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindLucky(int[] arr) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar findLucky = function(arr) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef find_lucky(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findLucky(_ arr: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findLucky(arr []int) int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findLucky(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findLucky(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_lucky(arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function findLucky($arr) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findLucky(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-lucky arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1394](https://leetcode-cn.com/problems/find-lucky-integer-in-an-array)", "[\u627e\u51fa\u6570\u7ec4\u4e2d\u7684\u5e78\u8fd0\u6570](/solution/1300-1399/1394.Find%20Lucky%20Integer%20in%20an%20Array/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1394](https://leetcode.com/problems/find-lucky-integer-in-an-array)", "[Find Lucky Integer in an Array](/solution/1300-1399/1394.Find%20Lucky%20Integer%20in%20an%20Array/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1509", "frontend_question_id": "1378", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/replace-employee-id-with-the-unique-identifier", "url_en": "https://leetcode.com/problems/replace-employee-id-with-the-unique-identifier", "relative_path_cn": "/solution/1300-1399/1378.Replace%20Employee%20ID%20With%20The%20Unique%20Identifier/README.md", "relative_path_en": "/solution/1300-1399/1378.Replace%20Employee%20ID%20With%20The%20Unique%20Identifier/README_EN.md", "title_cn": "\u4f7f\u7528\u552f\u4e00\u6807\u8bc6\u7801\u66ff\u6362\u5458\u5de5ID", "title_en": "Replace Employee ID With The Unique Identifier", "question_title_slug": "replace-employee-id-with-the-unique-identifier", "content_en": "

    Table: Employees

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| name          | varchar |\n+---------------+---------+\nid is the primary key for this table.\nEach row of this table contains the id and the name of an employee in a company.\n
    \n\n

     

    \n\n

    Table: EmployeeUNI

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| unique_id     | int     |\n+---------------+---------+\n(id, unique_id) is the primary key for this table.\nEach row of this table contains the id and the corresponding unique id of an employee in the company.\n
    \n\n

     

    \n\n

    Write an SQL query to show the unique ID of each user, If a user doesn't have a unique ID replace just show null.

    \n\n

    Return the result table in any order.

    \n\n

    The query result format is in the following example:

    \n\n
    \nEmployees table:\n+----+----------+\n| id | name     |\n+----+----------+\n| 1  | Alice    |\n| 7  | Bob      |\n| 11 | Meir     |\n| 90 | Winston  |\n| 3  | Jonathan |\n+----+----------+\n\nEmployeeUNI table:\n+----+-----------+\n| id | unique_id |\n+----+-----------+\n| 3  | 1         |\n| 11 | 2         |\n| 90 | 3         |\n+----+-----------+\n\nResult table:\n+-----------+----------+\n| unique_id | name     |\n+-----------+----------+\n| null      | Alice    |\n| null      | Bob      |\n| 2         | Meir     |\n| 3         | Winston  |\n| 1         | Jonathan |\n+-----------+----------+\n\nAlice and Bob don't have a unique ID, We will show null instead.\nThe unique ID of Meir is 2.\nThe unique ID of Winston is 3.\nThe unique ID of Jonathan is 1.\n
    \n", "content_cn": "

    Employees \u8868\uff1a

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| name          | varchar |\n+---------------+---------+\nid \u662f\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\u3002\n\u8fd9\u5f20\u8868\u7684\u6bcf\u4e00\u884c\u5206\u522b\u4ee3\u8868\u4e86\u67d0\u516c\u53f8\u5176\u4e2d\u4e00\u4f4d\u5458\u5de5\u7684\u540d\u5b57\u548c ID \u3002\n
    \n\n

     

    \n\n

    EmployeeUNI \u8868\uff1a

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| unique_id     | int     |\n+---------------+---------+\n(id, unique_id) \u662f\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\u3002\n\u8fd9\u5f20\u8868\u7684\u6bcf\u4e00\u884c\u5305\u542b\u4e86\u8be5\u516c\u53f8\u67d0\u4f4d\u5458\u5de5\u7684 ID \u548c\u4ed6\u7684\u552f\u4e00\u6807\u8bc6\u7801\uff08unique ID\uff09\u3002\n
    \n\n

     

    \n\n

    \u5199\u4e00\u6bb5SQL\u67e5\u8be2\u6765\u5c55\u793a\u6bcf\u4f4d\u7528\u6237\u7684 \u552f\u4e00\u6807\u8bc6\u7801\uff08unique ID \uff09\uff1b\u5982\u679c\u67d0\u4f4d\u5458\u5de5\u6ca1\u6709\u552f\u4e00\u6807\u8bc6\u7801\uff0c\u4f7f\u7528 null \u586b\u5145\u5373\u53ef\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u4ee5 \u4efb\u610f \u987a\u5e8f\u8fd4\u56de\u7ed3\u679c\u8868\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u7684\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a\uff1a

    \n\n
    \nEmployees table:\n+----+----------+\n| id | name     |\n+----+----------+\n| 1  | Alice    |\n| 7  | Bob      |\n| 11 | Meir     |\n| 90 | Winston  |\n| 3  | Jonathan |\n+----+----------+\n\nEmployeeUNI table:\n+----+-----------+\n| id | unique_id |\n+----+-----------+\n| 3  | 1         |\n| 11 | 2         |\n| 90 | 3         |\n+----+-----------+\n\nEmployeeUNI table:\n+-----------+----------+\n| unique_id | name     |\n+-----------+----------+\n| null      | Alice    |\n| null      | Bob      |\n| 2         | Meir     |\n| 3         | Winston  |\n| 1         | Jonathan |\n+-----------+----------+\n\nAlice and Bob \u6ca1\u6709\u552f\u4e00\u6807\u8bc6\u7801, \u56e0\u6b64\u6211\u4eec\u4f7f\u7528 null \u66ff\u4ee3\u3002\nMeir \u7684\u552f\u4e00\u6807\u8bc6\u7801\u662f 2 \u3002\nWinston \u7684\u552f\u4e00\u6807\u8bc6\u7801\u662f 3 \u3002\nJonathan \u552f\u4e00\u6807\u8bc6\u7801\u662f 1 \u3002\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1378](https://leetcode-cn.com/problems/replace-employee-id-with-the-unique-identifier)", "[\u4f7f\u7528\u552f\u4e00\u6807\u8bc6\u7801\u66ff\u6362\u5458\u5de5ID](/solution/1300-1399/1378.Replace%20Employee%20ID%20With%20The%20Unique%20Identifier/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1378](https://leetcode.com/problems/replace-employee-id-with-the-unique-identifier)", "[Replace Employee ID With The Unique Identifier](/solution/1300-1399/1378.Replace%20Employee%20ID%20With%20The%20Unique%20Identifier/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1508", "frontend_question_id": "1392", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-happy-prefix", "url_en": "https://leetcode.com/problems/longest-happy-prefix", "relative_path_cn": "/solution/1300-1399/1392.Longest%20Happy%20Prefix/README.md", "relative_path_en": "/solution/1300-1399/1392.Longest%20Happy%20Prefix/README_EN.md", "title_cn": "\u6700\u957f\u5feb\u4e50\u524d\u7f00", "title_en": "Longest Happy Prefix", "question_title_slug": "longest-happy-prefix", "content_en": "

    A string is called a happy prefix if is a non-empty prefix which is also a suffix (excluding itself).

    \n\n

    Given a string s, return the longest happy prefix of s. Return an empty string "" if no such prefix exists.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "level"\nOutput: "l"\nExplanation: s contains 4 prefix excluding itself ("l", "le", "lev", "leve"), and suffix ("l", "el", "vel", "evel"). The largest prefix which is also suffix is given by "l".\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "ababab"\nOutput: "abab"\nExplanation: "abab" is the largest prefix which is also suffix. They can overlap in the original string.\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "leetcodeleet"\nOutput: "leet"\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "a"\nOutput: ""\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 105
    • \n\t
    • s contains only lowercase English letters.
    • \n
    \n", "content_cn": "

    \u300c\u5feb\u4e50\u524d\u7f00\u300d\u662f\u5728\u539f\u5b57\u7b26\u4e32\u4e2d\u65e2\u662f \u975e\u7a7a \u524d\u7f00\u4e5f\u662f\u540e\u7f00\uff08\u4e0d\u5305\u62ec\u539f\u5b57\u7b26\u4e32\u81ea\u8eab\uff09\u7684\u5b57\u7b26\u4e32\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s\uff0c\u8bf7\u4f60\u8fd4\u56de\u5b83\u7684 \u6700\u957f\u5feb\u4e50\u524d\u7f00\u3002

    \n\n

    \u5982\u679c\u4e0d\u5b58\u5728\u6ee1\u8db3\u9898\u610f\u7684\u524d\u7f00\uff0c\u5219\u8fd4\u56de\u4e00\u4e2a\u7a7a\u5b57\u7b26\u4e32\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1as = "level"\n\u8f93\u51fa\uff1a"l"\n\u89e3\u91ca\uff1a\u4e0d\u5305\u62ec s \u81ea\u5df1\uff0c\u4e00\u5171\u6709 4 \u4e2a\u524d\u7f00\uff08"l", "le", "lev", "leve"\uff09\u548c 4 \u4e2a\u540e\u7f00\uff08"l", "el", "vel", "evel"\uff09\u3002\u6700\u957f\u7684\u65e2\u662f\u524d\u7f00\u4e5f\u662f\u540e\u7f00\u7684\u5b57\u7b26\u4e32\u662f "l" \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1as = "ababab"\n\u8f93\u51fa\uff1a"abab"\n\u89e3\u91ca\uff1a"abab" \u662f\u6700\u957f\u7684\u65e2\u662f\u524d\u7f00\u4e5f\u662f\u540e\u7f00\u7684\u5b57\u7b26\u4e32\u3002\u9898\u76ee\u5141\u8bb8\u524d\u540e\u7f00\u5728\u539f\u5b57\u7b26\u4e32\u4e2d\u91cd\u53e0\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1as = "leetcodeleet"\n\u8f93\u51fa\uff1a"leet"\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1as = "a"\n\u8f93\u51fa\uff1a""\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 10^5
    • \n\t
    • s \u53ea\u542b\u6709\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string longestPrefix(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String longestPrefix(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestPrefix(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestPrefix(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * longestPrefix(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string LongestPrefix(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar longestPrefix = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef longest_prefix(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestPrefix(_ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestPrefix(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestPrefix(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestPrefix(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_prefix(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function longestPrefix($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestPrefix(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-prefix s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1392](https://leetcode-cn.com/problems/longest-happy-prefix)", "[\u6700\u957f\u5feb\u4e50\u524d\u7f00](/solution/1300-1399/1392.Longest%20Happy%20Prefix/README.md)", "`\u5b57\u7b26\u4e32`", "\u56f0\u96be", ""], "md_table_row_en": ["[1392](https://leetcode.com/problems/longest-happy-prefix)", "[Longest Happy Prefix](/solution/1300-1399/1392.Longest%20Happy%20Prefix/README_EN.md)", "`String`", "Hard", ""]}, {"question_id": "1507", "frontend_question_id": "1391", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/check-if-there-is-a-valid-path-in-a-grid", "url_en": "https://leetcode.com/problems/check-if-there-is-a-valid-path-in-a-grid", "relative_path_cn": "/solution/1300-1399/1391.Check%20if%20There%20is%20a%20Valid%20Path%20in%20a%20Grid/README.md", "relative_path_en": "/solution/1300-1399/1391.Check%20if%20There%20is%20a%20Valid%20Path%20in%20a%20Grid/README_EN.md", "title_cn": "\u68c0\u67e5\u7f51\u683c\u4e2d\u662f\u5426\u5b58\u5728\u6709\u6548\u8def\u5f84", "title_en": "Check if There is a Valid Path in a Grid", "question_title_slug": "check-if-there-is-a-valid-path-in-a-grid", "content_en": "Given a m x n grid. Each cell of the grid represents a street. The street of grid[i][j] can be:\n
      \n\t
    • 1 which means a street connecting the left cell and the right cell.
    • \n\t
    • 2 which means a street connecting the upper cell and the lower cell.
    • \n\t
    • 3 which means a street connecting the left cell and the lower cell.
    • \n\t
    • 4 which means a street connecting the right cell and the lower cell.
    • \n\t
    • 5 which means a street connecting the left cell and the upper cell.
    • \n\t
    • 6 which means a street connecting the right cell and the upper cell.
    • \n
    \n\n

    \"\"

    \n\n

    You will initially start at the street of the upper-left cell (0,0). A valid path in the grid is a path which starts from the upper left cell (0,0) and ends at the bottom-right cell (m - 1, n - 1). The path should only follow the streets.

    \n\n

    Notice that you are not allowed to change any street.

    \n\n

    Return true if there is a valid path in the grid or false otherwise.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: grid = [[2,4,3],[6,5,2]]\nOutput: true\nExplanation: As shown you can start at cell (0, 0) and visit all the cells of the grid to reach (m - 1, n - 1).\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: grid = [[1,2,1],[1,2,1]]\nOutput: false\nExplanation: As shown you the street at cell (0, 0) is not connected with any street of any other cell and you will get stuck at cell (0, 0)\n
    \n\n

    Example 3:

    \n\n
    \nInput: grid = [[1,1,2]]\nOutput: false\nExplanation: You will get stuck at cell (0, 1) and you cannot reach cell (0, 2).\n
    \n\n

    Example 4:

    \n\n
    \nInput: grid = [[1,1,1,1,1,1,3]]\nOutput: true\n
    \n\n

    Example 5:

    \n\n
    \nInput: grid = [[2],[2],[2],[2],[2],[2],[6]]\nOutput: true\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= m, n <= 300
    • \n\t
    • 1 <= grid[i][j] <= 6
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a m x n \u7684\u7f51\u683c grid\u3002\u7f51\u683c\u91cc\u7684\u6bcf\u4e2a\u5355\u5143\u90fd\u4ee3\u8868\u4e00\u6761\u8857\u9053\u3002grid[i][j] \u7684\u8857\u9053\u53ef\u4ee5\u662f\uff1a

    \n\n
      \n\t
    • 1 \u8868\u793a\u8fde\u63a5\u5de6\u5355\u5143\u683c\u548c\u53f3\u5355\u5143\u683c\u7684\u8857\u9053\u3002
    • \n\t
    • 2 \u8868\u793a\u8fde\u63a5\u4e0a\u5355\u5143\u683c\u548c\u4e0b\u5355\u5143\u683c\u7684\u8857\u9053\u3002
    • \n\t
    • 3 \u8868\u793a\u8fde\u63a5\u5de6\u5355\u5143\u683c\u548c\u4e0b\u5355\u5143\u683c\u7684\u8857\u9053\u3002
    • \n\t
    • 4 \u8868\u793a\u8fde\u63a5\u53f3\u5355\u5143\u683c\u548c\u4e0b\u5355\u5143\u683c\u7684\u8857\u9053\u3002
    • \n\t
    • 5 \u8868\u793a\u8fde\u63a5\u5de6\u5355\u5143\u683c\u548c\u4e0a\u5355\u5143\u683c\u7684\u8857\u9053\u3002
    • \n\t
    • 6 \u8868\u793a\u8fde\u63a5\u53f3\u5355\u5143\u683c\u548c\u4e0a\u5355\u5143\u683c\u7684\u8857\u9053\u3002
    • \n
    \n\n

    \"\"

    \n\n

    \u4f60\u6700\u5f00\u59cb\u4ece\u5de6\u4e0a\u89d2\u7684\u5355\u5143\u683c (0,0) \u5f00\u59cb\u51fa\u53d1\uff0c\u7f51\u683c\u4e2d\u7684\u300c\u6709\u6548\u8def\u5f84\u300d\u662f\u6307\u4ece\u5de6\u4e0a\u65b9\u7684\u5355\u5143\u683c (0,0) \u5f00\u59cb\u3001\u4e00\u76f4\u5230\u53f3\u4e0b\u65b9\u7684 (m-1,n-1) \u7ed3\u675f\u7684\u8def\u5f84\u3002\u8be5\u8def\u5f84\u5fc5\u987b\u53ea\u6cbf\u7740\u8857\u9053\u8d70\u3002

    \n\n

    \u6ce8\u610f\uff1a\u4f60 \u4e0d\u80fd \u53d8\u66f4\u8857\u9053\u3002

    \n\n

    \u5982\u679c\u7f51\u683c\u4e2d\u5b58\u5728\u6709\u6548\u7684\u8def\u5f84\uff0c\u5219\u8fd4\u56de true\uff0c\u5426\u5219\u8fd4\u56de false \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1agrid = [[2,4,3],[6,5,2]]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u5982\u56fe\u6240\u793a\uff0c\u4f60\u53ef\u4ee5\u4ece (0, 0) \u5f00\u59cb\uff0c\u8bbf\u95ee\u7f51\u683c\u4e2d\u7684\u6240\u6709\u5355\u5143\u683c\u5e76\u5230\u8fbe (m - 1, n - 1) \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1agrid = [[1,2,1],[1,2,1]]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u5982\u56fe\u6240\u793a\uff0c\u5355\u5143\u683c (0, 0) \u4e0a\u7684\u8857\u9053\u6ca1\u6709\u4e0e\u4efb\u4f55\u5176\u4ed6\u5355\u5143\u683c\u4e0a\u7684\u8857\u9053\u76f8\u8fde\uff0c\u4f60\u53ea\u4f1a\u505c\u5728 (0, 0) \u5904\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1agrid = [[1,1,2]]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u4f60\u4f1a\u505c\u5728 (0, 1)\uff0c\u800c\u4e14\u65e0\u6cd5\u5230\u8fbe (0, 2) \u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1agrid = [[1,1,1,1,1,1,3]]\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1agrid = [[2],[2],[2],[2],[2],[2],[6]]\n\u8f93\u51fa\uff1atrue\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= m, n <= 300
    • \n\t
    • 1 <= grid[i][j] <= 6
    • \n
    \n", "tags_en": ["Depth-first Search", "Breadth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool hasValidPath(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean hasValidPath(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def hasValidPath(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def hasValidPath(self, grid: List[List[int]]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool hasValidPath(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool HasValidPath(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {boolean}\n */\nvar hasValidPath = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Boolean}\ndef has_valid_path(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func hasValidPath(_ grid: [[Int]]) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func hasValidPath(grid [][]int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def hasValidPath(grid: Array[Array[Int]]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun hasValidPath(grid: Array): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn has_valid_path(grid: Vec>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Boolean\n */\n function hasValidPath($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function hasValidPath(grid: number[][]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (has-valid-path grid)\n (-> (listof (listof exact-integer?)) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1391](https://leetcode-cn.com/problems/check-if-there-is-a-valid-path-in-a-grid)", "[\u68c0\u67e5\u7f51\u683c\u4e2d\u662f\u5426\u5b58\u5728\u6709\u6548\u8def\u5f84](/solution/1300-1399/1391.Check%20if%20There%20is%20a%20Valid%20Path%20in%20a%20Grid/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1391](https://leetcode.com/problems/check-if-there-is-a-valid-path-in-a-grid)", "[Check if There is a Valid Path in a Grid](/solution/1300-1399/1391.Check%20if%20There%20is%20a%20Valid%20Path%20in%20a%20Grid/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`", "Medium", ""]}, {"question_id": "1505", "frontend_question_id": "1389", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/create-target-array-in-the-given-order", "url_en": "https://leetcode.com/problems/create-target-array-in-the-given-order", "relative_path_cn": "/solution/1300-1399/1389.Create%20Target%20Array%20in%20the%20Given%20Order/README.md", "relative_path_en": "/solution/1300-1399/1389.Create%20Target%20Array%20in%20the%20Given%20Order/README_EN.md", "title_cn": "\u6309\u65e2\u5b9a\u987a\u5e8f\u521b\u5efa\u76ee\u6807\u6570\u7ec4", "title_en": "Create Target Array in the Given Order", "question_title_slug": "create-target-array-in-the-given-order", "content_en": "

    Given two arrays of integers nums and index. Your task is to create target array under the following rules:

    \n\n
      \n\t
    • Initially target array is empty.
    • \n\t
    • From left to right read nums[i] and index[i], insert at index index[i] the value nums[i] in target array.
    • \n\t
    • Repeat the previous step until there are no elements to read in nums and index.
    • \n
    \n\n

    Return the target array.

    \n\n

    It is guaranteed that the insertion operations will be valid.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [0,1,2,3,4], index = [0,1,2,2,1]\nOutput: [0,4,1,3,2]\nExplanation:\nnums       index     target\n0            0        [0]\n1            1        [0,1]\n2            2        [0,1,2]\n3            2        [0,1,3,2]\n4            1        [0,4,1,3,2]\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,2,3,4,0], index = [0,1,2,3,0]\nOutput: [0,1,2,3,4]\nExplanation:\nnums       index     target\n1            0        [1]\n2            1        [1,2]\n3            2        [1,2,3]\n4            3        [1,2,3,4]\n0            0        [0,1,2,3,4]\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [1], index = [0]\nOutput: [1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length, index.length <= 100
    • \n\t
    • nums.length == index.length
    • \n\t
    • 0 <= nums[i] <= 100
    • \n\t
    • 0 <= index[i] <= i
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u6574\u6570\u6570\u7ec4 nums \u548c index\u3002\u4f60\u9700\u8981\u6309\u7167\u4ee5\u4e0b\u89c4\u5219\u521b\u5efa\u76ee\u6807\u6570\u7ec4\uff1a

    \n\n
      \n\t
    • \u76ee\u6807\u6570\u7ec4 target \u6700\u521d\u4e3a\u7a7a\u3002
    • \n\t
    • \u6309\u4ece\u5de6\u5230\u53f3\u7684\u987a\u5e8f\u4f9d\u6b21\u8bfb\u53d6 nums[i] \u548c index[i]\uff0c\u5728 target \u6570\u7ec4\u4e2d\u7684\u4e0b\u6807 index[i] \u5904\u63d2\u5165\u503c nums[i] \u3002
    • \n\t
    • \u91cd\u590d\u4e0a\u4e00\u6b65\uff0c\u76f4\u5230\u5728 nums \u548c index \u4e2d\u90fd\u6ca1\u6709\u8981\u8bfb\u53d6\u7684\u5143\u7d20\u3002
    • \n
    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u76ee\u6807\u6570\u7ec4\u3002

    \n\n

    \u9898\u76ee\u4fdd\u8bc1\u6570\u5b57\u63d2\u5165\u4f4d\u7f6e\u603b\u662f\u5b58\u5728\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [0,1,2,3,4], index = [0,1,2,2,1]\n\u8f93\u51fa\uff1a[0,4,1,3,2]\n\u89e3\u91ca\uff1a\nnums       index     target\n0            0        [0]\n1            1        [0,1]\n2            2        [0,1,2]\n3            2        [0,1,3,2]\n4            1        [0,4,1,3,2]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,2,3,4,0], index = [0,1,2,3,0]\n\u8f93\u51fa\uff1a[0,1,2,3,4]\n\u89e3\u91ca\uff1a\nnums       index     target\n1            0        [1]\n2            1        [1,2]\n3            2        [1,2,3]\n4            3        [1,2,3,4]\n0            0        [0,1,2,3,4]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1], index = [0]\n\u8f93\u51fa\uff1a[1]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length, index.length <= 100
    • \n\t
    • nums.length == index.length
    • \n\t
    • 0 <= nums[i] <= 100
    • \n\t
    • 0 <= index[i] <= i
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector createTargetArray(vector& nums, vector& index) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] createTargetArray(int[] nums, int[] index) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def createTargetArray(self, nums, index):\n \"\"\"\n :type nums: List[int]\n :type index: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* createTargetArray(int* nums, int numsSize, int* index, int indexSize, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] CreateTargetArray(int[] nums, int[] index) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number[]} index\n * @return {number[]}\n */\nvar createTargetArray = function(nums, index) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer[]} index\n# @return {Integer[]}\ndef create_target_array(nums, index)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func createTargetArray(_ nums: [Int], _ index: [Int]) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func createTargetArray(nums []int, index []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def createTargetArray(nums: Array[Int], index: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun createTargetArray(nums: IntArray, index: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn create_target_array(nums: Vec, index: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer[] $index\n * @return Integer[]\n */\n function createTargetArray($nums, $index) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function createTargetArray(nums: number[], index: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (create-target-array nums index)\n (-> (listof exact-integer?) (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1389](https://leetcode-cn.com/problems/create-target-array-in-the-given-order)", "[\u6309\u65e2\u5b9a\u987a\u5e8f\u521b\u5efa\u76ee\u6807\u6570\u7ec4](/solution/1300-1399/1389.Create%20Target%20Array%20in%20the%20Given%20Order/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1389](https://leetcode.com/problems/create-target-array-in-the-given-order)", "[Create Target Array in the Given Order](/solution/1300-1399/1389.Create%20Target%20Array%20in%20the%20Given%20Order/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1504", "frontend_question_id": "1369", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/get-the-second-most-recent-activity", "url_en": "https://leetcode.com/problems/get-the-second-most-recent-activity", "relative_path_cn": "/solution/1300-1399/1369.Get%20the%20Second%20Most%20Recent%20Activity/README.md", "relative_path_en": "/solution/1300-1399/1369.Get%20the%20Second%20Most%20Recent%20Activity/README_EN.md", "title_cn": "\u83b7\u53d6\u6700\u8fd1\u7b2c\u4e8c\u6b21\u7684\u6d3b\u52a8", "title_en": "Get the Second Most Recent Activity", "question_title_slug": "get-the-second-most-recent-activity", "content_en": "

    Table: UserActivity

    \r\n\r\n
    \r\n+---------------+---------+\r\n| Column Name   | Type    |\r\n+---------------+---------+\r\n| username      | varchar |\r\n| activity      | varchar |\r\n| startDate     | Date    |\r\n| endDate       | Date    |\r\n+---------------+---------+\r\nThis table does not contain primary key.\r\nThis table contain information about the activity performed of each user in a period of time.\r\nA person with username performed a activity from startDate to endDate.\r\n\r\n
    \r\n\r\n

    Write an SQL query to show the second most recent activity of each user.

    \r\n\r\n

    If the user only has one activity, return that one. 

    \r\n\r\n

    A user can't perform more than one activity at the same time. Return the result table in any order.

    \r\n\r\n

    The query result format is in the following example:

    \r\n\r\n
    \r\nUserActivity table:\r\n+------------+--------------+-------------+-------------+\r\n| username   | activity     | startDate   | endDate     |\r\n+------------+--------------+-------------+-------------+\r\n| Alice      | Travel       | 2020-02-12  | 2020-02-20  |\r\n| Alice      | Dancing      | 2020-02-21  | 2020-02-23  |\r\n| Alice      | Travel       | 2020-02-24  | 2020-02-28  |\r\n| Bob        | Travel       | 2020-02-11  | 2020-02-18  |\r\n+------------+--------------+-------------+-------------+\r\n\r\nResult table:\r\n+------------+--------------+-------------+-------------+\r\n| username   | activity     | startDate   | endDate     |\r\n+------------+--------------+-------------+-------------+\r\n| Alice      | Dancing      | 2020-02-21  | 2020-02-23  |\r\n| Bob        | Travel       | 2020-02-11  | 2020-02-18  |\r\n+------------+--------------+-------------+-------------+\r\n\r\nThe most recent activity of Alice is Travel from 2020-02-24 to 2020-02-28, before that she was dancing from 2020-02-21 to 2020-02-23.\r\nBob only has one record, we just take that one.\r\n
    ", "content_cn": "

    \u8868: UserActivity

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| username      | varchar |\n| activity      | varchar |\n| startDate     | Date    |\n| endDate       | Date    |\n+---------------+---------+\n\u8be5\u8868\u4e0d\u5305\u542b\u4e3b\u952e\n\u8be5\u8868\u5305\u542b\u6bcf\u4e2a\u7528\u6237\u5728\u4e00\u6bb5\u65f6\u95f4\u5185\u8fdb\u884c\u7684\u6d3b\u52a8\u7684\u4fe1\u606f\n\u540d\u4e3a username \u7684\u7528\u6237\u5728 startDate \u5230 endDate \u65e5\u5185\u6709\u4e00\u6b21\u6d3b\u52a8\n
    \n\n

    \u00a0

    \n\n

    \u5199\u4e00\u6761SQL\u67e5\u8be2\u5c55\u793a\u6bcf\u4e00\u4f4d\u7528\u6237 \u6700\u8fd1\u7b2c\u4e8c\u6b21 \u7684\u6d3b\u52a8

    \n\n

    \u5982\u679c\u7528\u6237\u4ec5\u6709\u4e00\u6b21\u6d3b\u52a8\uff0c\u8fd4\u56de\u8be5\u6d3b\u52a8

    \n\n

    \u4e00\u4e2a\u7528\u6237\u4e0d\u80fd\u540c\u65f6\u8fdb\u884c\u8d85\u8fc7\u4e00\u9879\u6d3b\u52a8\uff0c\u4ee5 \u4efb\u610f \u987a\u5e8f\u8fd4\u56de\u7ed3\u679c

    \n\n

    \u4e0b\u9762\u662f\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u7684\u4f8b\u5b50\uff1a

    \n\n
    \nUserActivity \u8868:\n+------------+--------------+-------------+-------------+\n| username   | activity     | startDate   | endDate     |\n+------------+--------------+-------------+-------------+\n| Alice      | Travel       | 2020-02-12  | 2020-02-20  |\n| Alice      | Dancing      | 2020-02-21  | 2020-02-23  |\n| Alice      | Travel       | 2020-02-24  | 2020-02-28  |\n| Bob        | Travel       | 2020-02-11  | 2020-02-18  |\n+------------+--------------+-------------+-------------+\n\nResult \u8868:\n+------------+--------------+-------------+-------------+\n| username   | activity     | startDate   | endDate     |\n+------------+--------------+-------------+-------------+\n| Alice      | Dancing      | 2020-02-21  | 2020-02-23  |\n| Bob        | Travel       | 2020-02-11  | 2020-02-18  |\n+------------+--------------+-------------+-------------+\n\nAlice \u6700\u8fd1\u4e00\u6b21\u7684\u6d3b\u52a8\u662f\u4ece 2020-02-24 \u5230 2020-02-28 \u7684\u65c5\u884c, \u5728\u6b64\u4e4b\u524d\u7684 2020-02-21 \u5230 2020-02-23 \u5979\u8fdb\u884c\u4e86\u821e\u8e48\nBob \u53ea\u6709\u4e00\u6761\u8bb0\u5f55\uff0c\u6211\u4eec\u5c31\u53d6\u8fd9\u6761\u8bb0\u5f55\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1369](https://leetcode-cn.com/problems/get-the-second-most-recent-activity)", "[\u83b7\u53d6\u6700\u8fd1\u7b2c\u4e8c\u6b21\u7684\u6d3b\u52a8](/solution/1300-1399/1369.Get%20the%20Second%20Most%20Recent%20Activity/README.md)", "", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1369](https://leetcode.com/problems/get-the-second-most-recent-activity)", "[Get the Second Most Recent Activity](/solution/1300-1399/1369.Get%20the%20Second%20Most%20Recent%20Activity/README_EN.md)", "", "Hard", "\ud83d\udd12"]}, {"question_id": "1503", "frontend_question_id": "1402", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reducing-dishes", "url_en": "https://leetcode.com/problems/reducing-dishes", "relative_path_cn": "/solution/1400-1499/1402.Reducing%20Dishes/README.md", "relative_path_en": "/solution/1400-1499/1402.Reducing%20Dishes/README_EN.md", "title_cn": "\u505a\u83dc\u987a\u5e8f", "title_en": "Reducing Dishes", "question_title_slug": "reducing-dishes", "content_en": "

    A chef has collected data on the satisfaction level of his n dishes. Chef can cook any dish in 1 unit of time.

    \r\n\r\n

    Like-time coefficient of a dish is defined as the time taken to cook that dish including previous dishes multiplied by its satisfaction level  i.e.  time[i]*satisfaction[i]

    \r\n\r\n

    Return the maximum sum of Like-time coefficient that the chef can obtain after dishes preparation.

    \r\n\r\n

    Dishes can be prepared in any order and the chef can discard some dishes to get this maximum value.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: satisfaction = [-1,-8,0,5,-9]\r\nOutput: 14\r\nExplanation: After Removing the second and last dish, the maximum total Like-time coefficient will be equal to (-1*1 + 0*2 + 5*3 = 14). Each dish is prepared in one unit of time.
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: satisfaction = [4,3,2]\r\nOutput: 20\r\nExplanation: Dishes can be prepared in any order, (2*1 + 3*2 + 4*3 = 20)\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: satisfaction = [-1,-4,-5]\r\nOutput: 0\r\nExplanation: People don't like the dishes. No dish is prepared.\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: satisfaction = [-2,5,-1,0,3,-3]\r\nOutput: 35\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • n == satisfaction.length
    • \r\n\t
    • 1 <= n <= 500
    • \r\n\t
    • -10^3 <= satisfaction[i] <= 10^3
    • \r\n
    ", "content_cn": "

    \u4e00\u4e2a\u53a8\u5e08\u6536\u96c6\u4e86\u4ed6 n \u9053\u83dc\u7684\u6ee1\u610f\u7a0b\u5ea6 satisfaction \uff0c\u8fd9\u4e2a\u53a8\u5e08\u505a\u51fa\u6bcf\u9053\u83dc\u7684\u65f6\u95f4\u90fd\u662f 1 \u5355\u4f4d\u65f6\u95f4\u3002

    \n\n

    \u4e00\u9053\u83dc\u7684 \u300c\u559c\u7231\u65f6\u95f4\u300d\u7cfb\u6570\u5b9a\u4e49\u4e3a\u70f9\u996a\u8fd9\u9053\u83dc\u4ee5\u53ca\u4e4b\u524d\u6bcf\u9053\u83dc\u6240\u82b1\u8d39\u7684\u65f6\u95f4\u4e58\u4ee5\u8fd9\u9053\u83dc\u7684\u6ee1\u610f\u7a0b\u5ea6\uff0c\u4e5f\u5c31\u662f time[i]*satisfaction[i] \u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u505a\u5b8c\u6240\u6709\u83dc \u300c\u559c\u7231\u65f6\u95f4\u300d\u603b\u548c\u7684\u6700\u5927\u503c\u4e3a\u591a\u5c11\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u6309 \u4efb\u610f \u987a\u5e8f\u5b89\u6392\u505a\u83dc\u7684\u987a\u5e8f\uff0c\u4f60\u4e5f\u53ef\u4ee5\u9009\u62e9\u653e\u5f03\u505a\u67d0\u4e9b\u83dc\u6765\u83b7\u5f97\u66f4\u5927\u7684\u603b\u548c\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1asatisfaction = [-1,-8,0,5,-9]\n\u8f93\u51fa\uff1a14\n\u89e3\u91ca\uff1a\u53bb\u6389\u7b2c\u4e8c\u9053\u548c\u6700\u540e\u4e00\u9053\u83dc\uff0c\u6700\u5927\u7684\u559c\u7231\u65f6\u95f4\u7cfb\u6570\u548c\u4e3a (-1*1 + 0*2 + 5*3 = 14) \u3002\u6bcf\u9053\u83dc\u90fd\u9700\u8981\u82b1\u8d39 1 \u5355\u4f4d\u65f6\u95f4\u5b8c\u6210\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1asatisfaction = [4,3,2]\n\u8f93\u51fa\uff1a20\n\u89e3\u91ca\uff1a\u6309\u7167\u539f\u6765\u987a\u5e8f\u76f8\u53cd\u7684\u65f6\u95f4\u505a\u83dc (2*1 + 3*2 + 4*3 = 20)\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1asatisfaction = [-1,-4,-5]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u5927\u5bb6\u90fd\u4e0d\u559c\u6b22\u8fd9\u4e9b\u83dc\uff0c\u6240\u4ee5\u4e0d\u505a\u4efb\u4f55\u83dc\u53ef\u4ee5\u83b7\u5f97\u6700\u5927\u7684\u559c\u7231\u65f6\u95f4\u7cfb\u6570\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1asatisfaction = [-2,5,-1,0,3,-3]\n\u8f93\u51fa\uff1a35\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == satisfaction.length
    • \n\t
    • 1 <= n <= 500
    • \n\t
    • -10^3 <= satisfaction[i] <= 10^3
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxSatisfaction(vector& satisfaction) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxSatisfaction(int[] satisfaction) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxSatisfaction(self, satisfaction):\n \"\"\"\n :type satisfaction: List[int]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxSatisfaction(self, satisfaction: List[int]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxSatisfaction(int* satisfaction, int satisfactionSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxSatisfaction(int[] satisfaction) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} satisfaction\n * @return {number}\n */\nvar maxSatisfaction = function(satisfaction) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} satisfaction\n# @return {Integer}\ndef max_satisfaction(satisfaction)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxSatisfaction(_ satisfaction: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxSatisfaction(satisfaction []int) int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxSatisfaction(satisfaction: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxSatisfaction(satisfaction: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_satisfaction(satisfaction: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $satisfaction\n * @return Integer\n */\n function maxSatisfaction($satisfaction) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxSatisfaction(satisfaction: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-satisfaction satisfaction)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1402](https://leetcode-cn.com/problems/reducing-dishes)", "[\u505a\u83dc\u987a\u5e8f](/solution/1400-1499/1402.Reducing%20Dishes/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1402](https://leetcode.com/problems/reducing-dishes)", "[Reducing Dishes](/solution/1400-1499/1402.Reducing%20Dishes/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1502", "frontend_question_id": "1400", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/construct-k-palindrome-strings", "url_en": "https://leetcode.com/problems/construct-k-palindrome-strings", "relative_path_cn": "/solution/1400-1499/1400.Construct%20K%20Palindrome%20Strings/README.md", "relative_path_en": "/solution/1400-1499/1400.Construct%20K%20Palindrome%20Strings/README_EN.md", "title_cn": "\u6784\u9020 K \u4e2a\u56de\u6587\u5b57\u7b26\u4e32", "title_en": "Construct K Palindrome Strings", "question_title_slug": "construct-k-palindrome-strings", "content_en": "

    Given a string s and an integer k. You should construct k non-empty palindrome strings using all the characters in s.

    \r\n\r\n

    Return True if you can use all the characters in s to construct k palindrome strings or False otherwise.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: s = "annabelle", k = 2\r\nOutput: true\r\nExplanation: You can construct two palindromes using all characters in s.\r\nSome possible constructions "anna" + "elble", "anbna" + "elle", "anellena" + "b"\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: s = "leetcode", k = 3\r\nOutput: false\r\nExplanation: It is impossible to construct 3 palindromes using all the characters of s.\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: s = "true", k = 4\r\nOutput: true\r\nExplanation: The only possible solution is to put each character in a separate string.\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: s = "yzyzyzyzyzyzyzy", k = 2\r\nOutput: true\r\nExplanation: Simply you can put all z's in one string and all y's in the other string. Both strings will be palindrome.\r\n
    \r\n\r\n

    Example 5:

    \r\n\r\n
    \r\nInput: s = "cr", k = 7\r\nOutput: false\r\nExplanation: We don't have enough characters in s to construct 7 palindromes.\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= s.length <= 10^5
    • \r\n\t
    • All characters in s are lower-case English letters.
    • \r\n\t
    • 1 <= k <= 10^5
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \u548c\u4e00\u4e2a\u6574\u6570 k \u3002\u8bf7\u4f60\u7528 s \u5b57\u7b26\u4e32\u4e2d \u6240\u6709\u5b57\u7b26 \u6784\u9020 k \u4e2a\u975e\u7a7a \u56de\u6587\u4e32 \u3002

    \n\n

    \u5982\u679c\u4f60\u53ef\u4ee5\u7528 s \u4e2d\u6240\u6709\u5b57\u7b26\u6784\u9020 k \u4e2a\u56de\u6587\u5b57\u7b26\u4e32\uff0c\u90a3\u4e48\u8bf7\u4f60\u8fd4\u56de True \uff0c\u5426\u5219\u8fd4\u56de False \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = "annabelle", k = 2\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u53ef\u4ee5\u7528 s \u4e2d\u6240\u6709\u5b57\u7b26\u6784\u9020 2 \u4e2a\u56de\u6587\u5b57\u7b26\u4e32\u3002\n\u4e00\u4e9b\u53ef\u884c\u7684\u6784\u9020\u65b9\u6848\u5305\u62ec\uff1a"anna" + "elble"\uff0c"anbna" + "elle"\uff0c"anellena" + "b"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = "leetcode", k = 3\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u65e0\u6cd5\u7528 s \u4e2d\u6240\u6709\u5b57\u7b26\u6784\u9020 3 \u4e2a\u56de\u6587\u4e32\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = "true", k = 4\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u552f\u4e00\u53ef\u884c\u7684\u65b9\u6848\u662f\u8ba9 s \u4e2d\u6bcf\u4e2a\u5b57\u7b26\u5355\u72ec\u6784\u6210\u4e00\u4e2a\u5b57\u7b26\u4e32\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = "yzyzyzyzyzyzyzy", k = 2\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u4f60\u53ea\u9700\u8981\u5c06\u6240\u6709\u7684 z \u653e\u5728\u4e00\u4e2a\u5b57\u7b26\u4e32\u4e2d\uff0c\u6240\u6709\u7684 y \u653e\u5728\u53e6\u4e00\u4e2a\u5b57\u7b26\u4e32\u4e2d\u3002\u90a3\u4e48\u4e24\u4e2a\u5b57\u7b26\u4e32\u90fd\u662f\u56de\u6587\u4e32\u3002\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = "cr", k = 7\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u6211\u4eec\u6ca1\u6709\u8db3\u591f\u7684\u5b57\u7b26\u53bb\u6784\u9020 7 \u4e2a\u56de\u6587\u4e32\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 10^5
    • \n\t
    • s \u4e2d\u6240\u6709\u5b57\u7b26\u90fd\u662f\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    • \n\t
    • 1 <= k <= 10^5
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canConstruct(string s, int k) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canConstruct(String s, int k) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canConstruct(self, s, k):\n \"\"\"\n :type s: str\n :type k: int\n :rtype: bool\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canConstruct(self, s: str, k: int) -> bool:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canConstruct(char * s, int k){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanConstruct(string s, int k) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number} k\n * @return {boolean}\n */\nvar canConstruct = function(s, k) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer} k\n# @return {Boolean}\ndef can_construct(s, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canConstruct(_ s: String, _ k: Int) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canConstruct(s string, k int) bool {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canConstruct(s: String, k: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canConstruct(s: String, k: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_construct(s: String, k: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer $k\n * @return Boolean\n */\n function canConstruct($s, $k) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canConstruct(s: string, k: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-construct s k)\n (-> string? exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1400](https://leetcode-cn.com/problems/construct-k-palindrome-strings)", "[\u6784\u9020 K \u4e2a\u56de\u6587\u5b57\u7b26\u4e32](/solution/1400-1499/1400.Construct%20K%20Palindrome%20Strings/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1400](https://leetcode.com/problems/construct-k-palindrome-strings)", "[Construct K Palindrome Strings](/solution/1400-1499/1400.Construct%20K%20Palindrome%20Strings/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1501", "frontend_question_id": "1401", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/circle-and-rectangle-overlapping", "url_en": "https://leetcode.com/problems/circle-and-rectangle-overlapping", "relative_path_cn": "/solution/1400-1499/1401.Circle%20and%20Rectangle%20Overlapping/README.md", "relative_path_en": "/solution/1400-1499/1401.Circle%20and%20Rectangle%20Overlapping/README_EN.md", "title_cn": "\u5706\u548c\u77e9\u5f62\u662f\u5426\u6709\u91cd\u53e0", "title_en": "Circle and Rectangle Overlapping", "question_title_slug": "circle-and-rectangle-overlapping", "content_en": "

    Given a circle represented as (radius, x_center, y_center) and an axis-aligned rectangle represented as (x1, y1, x2, y2), where (x1, y1) are the coordinates of the bottom-left corner, and (x2, y2) are the coordinates of the top-right corner of the rectangle.

    \n\n

    Return True if the circle and rectangle are overlapped otherwise return False.

    \n\n

    In other words, check if there are any point (xi, yi) such that belongs to the circle and the rectangle at the same time.

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: radius = 1, x_center = 0, y_center = 0, x1 = 1, y1 = -1, x2 = 3, y2 = 1\nOutput: true\nExplanation: Circle and rectangle share the point (1,0) \n
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: radius = 1, x_center = 0, y_center = 0, x1 = -1, y1 = 0, x2 = 0, y2 = 1\nOutput: true\n
    \n\n

    Example 3:

    \n\n

    \"\"

    \n\n
    \nInput: radius = 1, x_center = 1, y_center = 1, x1 = -3, y1 = -3, x2 = 3, y2 = 3\nOutput: true\n
    \n\n

    Example 4:

    \n\n
    \nInput: radius = 1, x_center = 1, y_center = 1, x1 = 1, y1 = -3, x2 = 2, y2 = -1\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= radius <= 2000
    • \n\t
    • -10^4 <= x_center, y_center, x1, y1, x2, y2 <= 10^4
    • \n\t
    • x1 < x2
    • \n\t
    • y1 < y2
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u4ee5 (radius, x_center, y_center) \u8868\u793a\u7684\u5706\u548c\u4e00\u4e2a\u4e0e\u5750\u6807\u8f74\u5e73\u884c\u7684\u77e9\u5f62 (x1, y1, x2, y2)\uff0c\u5176\u4e2d (x1, y1) \u662f\u77e9\u5f62\u5de6\u4e0b\u89d2\u7684\u5750\u6807\uff0c(x2, y2) \u662f\u53f3\u4e0a\u89d2\u7684\u5750\u6807\u3002

    \n\n

    \u5982\u679c\u5706\u548c\u77e9\u5f62\u6709\u91cd\u53e0\u7684\u90e8\u5206\uff0c\u8bf7\u4f60\u8fd4\u56de True \uff0c\u5426\u5219\u8fd4\u56de False \u3002

    \n\n

    \u6362\u53e5\u8bdd\u8bf4\uff0c\u8bf7\u4f60\u68c0\u6d4b\u662f\u5426 \u5b58\u5728 \u70b9 (xi, yi) \uff0c\u5b83\u65e2\u5728\u5706\u4e0a\u4e5f\u5728\u77e9\u5f62\u4e0a\uff08\u4e24\u8005\u90fd\u5305\u62ec\u70b9\u843d\u5728\u8fb9\u754c\u4e0a\u7684\u60c5\u51b5\uff09\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1aradius = 1, x_center = 0, y_center = 0, x1 = 1, y1 = -1, x2 = 3, y2 = 1\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u5706\u548c\u77e9\u5f62\u6709\u516c\u5171\u70b9 (1,0) \n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1aradius = 1, x_center = 0, y_center = 0, x1 = -1, y1 = 0, x2 = 0, y2 = 1\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1aradius = 1, x_center = 1, y_center = 1, x1 = -3, y1 = -3, x2 = 3, y2 = 3\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1aradius = 1, x_center = 1, y_center = 1, x1 = 1, y1 = -3, x2 = 2, y2 = -1\n\u8f93\u51fa\uff1afalse\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= radius <= 2000
    • \n\t
    • -10^4 <= x_center, y_center, x1, y1, x2, y2 <= 10^4
    • \n\t
    • x1 < x2
    • \n\t
    • y1 < y2
    • \n
    \n", "tags_en": ["Geometry"], "tags_cn": ["\u51e0\u4f55"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool checkOverlap(int radius, int x_center, int y_center, int x1, int y1, int x2, int y2) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean checkOverlap(int radius, int x_center, int y_center, int x1, int y1, int x2, int y2) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def checkOverlap(self, radius, x_center, y_center, x1, y1, x2, y2):\n \"\"\"\n :type radius: int\n :type x_center: int\n :type y_center: int\n :type x1: int\n :type y1: int\n :type x2: int\n :type y2: int\n :rtype: bool\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def checkOverlap(self, radius: int, x_center: int, y_center: int, x1: int, y1: int, x2: int, y2: int) -> bool:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool checkOverlap(int radius, int x_center, int y_center, int x1, int y1, int x2, int y2){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CheckOverlap(int radius, int x_center, int y_center, int x1, int y1, int x2, int y2) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} radius\n * @param {number} x_center\n * @param {number} y_center\n * @param {number} x1\n * @param {number} y1\n * @param {number} x2\n * @param {number} y2\n * @return {boolean}\n */\nvar checkOverlap = function(radius, x_center, y_center, x1, y1, x2, y2) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} radius\n# @param {Integer} x_center\n# @param {Integer} y_center\n# @param {Integer} x1\n# @param {Integer} y1\n# @param {Integer} x2\n# @param {Integer} y2\n# @return {Boolean}\ndef check_overlap(radius, x_center, y_center, x1, y1, x2, y2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func checkOverlap(_ radius: Int, _ x_center: Int, _ y_center: Int, _ x1: Int, _ y1: Int, _ x2: Int, _ y2: Int) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func checkOverlap(radius int, x_center int, y_center int, x1 int, y1 int, x2 int, y2 int) bool {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def checkOverlap(radius: Int, x_center: Int, y_center: Int, x1: Int, y1: Int, x2: Int, y2: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun checkOverlap(radius: Int, x_center: Int, y_center: Int, x1: Int, y1: Int, x2: Int, y2: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn check_overlap(radius: i32, x_center: i32, y_center: i32, x1: i32, y1: i32, x2: i32, y2: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $radius\n * @param Integer $x_center\n * @param Integer $y_center\n * @param Integer $x1\n * @param Integer $y1\n * @param Integer $x2\n * @param Integer $y2\n * @return Boolean\n */\n function checkOverlap($radius, $x_center, $y_center, $x1, $y1, $x2, $y2) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function checkOverlap(radius: number, x_center: number, y_center: number, x1: number, y1: number, x2: number, y2: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (check-overlap radius x_center y_center x1 y1 x2 y2)\n (-> exact-integer? exact-integer? exact-integer? exact-integer? exact-integer? exact-integer? exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1401](https://leetcode-cn.com/problems/circle-and-rectangle-overlapping)", "[\u5706\u548c\u77e9\u5f62\u662f\u5426\u6709\u91cd\u53e0](/solution/1400-1499/1401.Circle%20and%20Rectangle%20Overlapping/README.md)", "`\u51e0\u4f55`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1401](https://leetcode.com/problems/circle-and-rectangle-overlapping)", "[Circle and Rectangle Overlapping](/solution/1400-1499/1401.Circle%20and%20Rectangle%20Overlapping/README_EN.md)", "`Geometry`", "Medium", ""]}, {"question_id": "1500", "frontend_question_id": "1399", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-largest-group", "url_en": "https://leetcode.com/problems/count-largest-group", "relative_path_cn": "/solution/1300-1399/1399.Count%20Largest%20Group/README.md", "relative_path_en": "/solution/1300-1399/1399.Count%20Largest%20Group/README_EN.md", "title_cn": "\u7edf\u8ba1\u6700\u5927\u7ec4\u7684\u6570\u76ee", "title_en": "Count Largest Group", "question_title_slug": "count-largest-group", "content_en": "

    Given an integer n. Each number from 1 to n is grouped according to the sum of its digits. 

    \n\n

    Return how many groups have the largest size.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 13\nOutput: 4\nExplanation: There are 9 groups in total, they are grouped according sum of its digits of numbers from 1 to 13:\n[1,10], [2,11], [3,12], [4,13], [5], [6], [7], [8], [9]. There are 4 groups with largest size.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 2\nOutput: 2\nExplanation: There are 2 groups [1], [2] of size 1.\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 15\nOutput: 6\n
    \n\n

    Example 4:

    \n\n
    \nInput: n = 24\nOutput: 5\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 10^4
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n \u3002\u8bf7\u4f60\u5148\u6c42\u51fa\u4ece 1 \u5230 n \u7684\u6bcf\u4e2a\u6574\u6570 10 \u8fdb\u5236\u8868\u793a\u4e0b\u7684\u6570\u4f4d\u548c\uff08\u6bcf\u4e00\u4f4d\u4e0a\u7684\u6570\u5b57\u76f8\u52a0\uff09\uff0c\u7136\u540e\u628a\u6570\u4f4d\u548c\u76f8\u7b49\u7684\u6570\u5b57\u653e\u5230\u540c\u4e00\u4e2a\u7ec4\u4e2d\u3002

    \n\n

    \u8bf7\u4f60\u7edf\u8ba1\u6bcf\u4e2a\u7ec4\u4e2d\u7684\u6570\u5b57\u6570\u76ee\uff0c\u5e76\u8fd4\u56de\u6570\u5b57\u6570\u76ee\u5e76\u5217\u6700\u591a\u7684\u7ec4\u6709\u591a\u5c11\u4e2a\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1an = 13\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u603b\u5171\u6709 9 \u4e2a\u7ec4\uff0c\u5c06 1 \u5230 13 \u6309\u6570\u4f4d\u6c42\u548c\u540e\u8fd9\u4e9b\u7ec4\u5206\u522b\u662f\uff1a\n[1,10]\uff0c[2,11]\uff0c[3,12]\uff0c[4,13]\uff0c[5]\uff0c[6]\uff0c[7]\uff0c[8]\uff0c[9]\u3002\u603b\u5171\u6709 4 \u4e2a\u7ec4\u62e5\u6709\u7684\u6570\u5b57\u5e76\u5217\u6700\u591a\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1an = 2\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u603b\u5171\u6709 2 \u4e2a\u5927\u5c0f\u4e3a 1 \u7684\u7ec4 [1]\uff0c[2]\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1an = 15\n\u8f93\u51fa\uff1a6\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1an = 24\n\u8f93\u51fa\uff1a5\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 10^4
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countLargestGroup(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countLargestGroup(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countLargestGroup(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countLargestGroup(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countLargestGroup(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountLargestGroup(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar countLargestGroup = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef count_largest_group(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countLargestGroup(_ n: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countLargestGroup(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countLargestGroup(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countLargestGroup(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_largest_group(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function countLargestGroup($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countLargestGroup(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-largest-group n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1399](https://leetcode-cn.com/problems/count-largest-group)", "[\u7edf\u8ba1\u6700\u5927\u7ec4\u7684\u6570\u76ee](/solution/1300-1399/1399.Count%20Largest%20Group/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1399](https://leetcode.com/problems/count-largest-group)", "[Count Largest Group](/solution/1300-1399/1399.Count%20Largest%20Group/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1499", "frontend_question_id": "1383", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-performance-of-a-team", "url_en": "https://leetcode.com/problems/maximum-performance-of-a-team", "relative_path_cn": "/solution/1300-1399/1383.Maximum%20Performance%20of%20a%20Team/README.md", "relative_path_en": "/solution/1300-1399/1383.Maximum%20Performance%20of%20a%20Team/README_EN.md", "title_cn": "\u6700\u5927\u7684\u56e2\u961f\u8868\u73b0\u503c", "title_en": "Maximum Performance of a Team", "question_title_slug": "maximum-performance-of-a-team", "content_en": "

    You are given two integers n and k and two integer arrays speed and efficiency both of length n. There are n engineers numbered from 1 to n. speed[i] and efficiency[i] represent the speed and efficiency of the ith engineer respectively.

    \n\n

    Choose at most k different engineers out of the n engineers to form a team with the maximum performance.

    \n\n

    The performance of a team is the sum of their engineers' speeds multiplied by the minimum efficiency among their engineers.

    \n\n

    Return the maximum performance of this team. Since the answer can be a huge number, return it modulo 109 + 7.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 6, speed = [2,10,3,1,5,8], efficiency = [5,4,3,9,7,2], k = 2\nOutput: 60\nExplanation: \nWe have the maximum performance of the team by selecting engineer 2 (with speed=10 and efficiency=4) and engineer 5 (with speed=5 and efficiency=7). That is, performance = (10 + 5) * min(4, 7) = 60.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 6, speed = [2,10,3,1,5,8], efficiency = [5,4,3,9,7,2], k = 3\nOutput: 68\nExplanation:\nThis is the same example as the first but k = 3. We can select engineer 1, engineer 2 and engineer 5 to get the maximum performance of the team. That is, performance = (2 + 10 + 5) * min(5, 4, 7) = 68.\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 6, speed = [2,10,3,1,5,8], efficiency = [5,4,3,9,7,2], k = 4\nOutput: 72\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= <= k <= n <= 105
    • \n\t
    • speed.length == n
    • \n\t
    • efficiency.length == n
    • \n\t
    • 1 <= speed[i] <= 105
    • \n\t
    • 1 <= efficiency[i] <= 108
    • \n
    \n", "content_cn": "

    \u516c\u53f8\u6709\u7f16\u53f7\u4e3a 1 \u5230 n \u7684 n \u4e2a\u5de5\u7a0b\u5e08\uff0c\u7ed9\u4f60\u4e24\u4e2a\u6570\u7ec4 speed \u548c efficiency \uff0c\u5176\u4e2d speed[i] \u548c efficiency[i] \u5206\u522b\u4ee3\u8868\u7b2c i \u4f4d\u5de5\u7a0b\u5e08\u7684\u901f\u5ea6\u548c\u6548\u7387\u3002\u8bf7\u4f60\u8fd4\u56de\u7531\u6700\u591a k \u4e2a\u5de5\u7a0b\u5e08\u7ec4\u6210\u7684 \u200b\u200b\u200b\u200b\u200b\u200b\u6700\u5927\u56e2\u961f\u8868\u73b0\u503c \uff0c\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u5f88\u5927\uff0c\u8bf7\u4f60\u8fd4\u56de\u7ed3\u679c\u5bf9 10^9 + 7 \u53d6\u4f59\u540e\u7684\u7ed3\u679c\u3002

    \n\n

    \u56e2\u961f\u8868\u73b0\u503c \u7684\u5b9a\u4e49\u4e3a\uff1a\u4e00\u4e2a\u56e2\u961f\u4e2d\u300c\u6240\u6709\u5de5\u7a0b\u5e08\u901f\u5ea6\u7684\u548c\u300d\u4e58\u4ee5\u4ed6\u4eec\u300c\u6548\u7387\u503c\u4e2d\u7684\u6700\u5c0f\u503c\u300d\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1an = 6, speed = [2,10,3,1,5,8], efficiency = [5,4,3,9,7,2], k = 2\n\u8f93\u51fa\uff1a60\n\u89e3\u91ca\uff1a\n\u6211\u4eec\u9009\u62e9\u5de5\u7a0b\u5e08 2\uff08speed=10 \u4e14 efficiency=4\uff09\u548c\u5de5\u7a0b\u5e08 5\uff08speed=5 \u4e14 efficiency=7\uff09\u3002\u4ed6\u4eec\u7684\u56e2\u961f\u8868\u73b0\u503c\u4e3a performance = (10 + 5) * min(4, 7) = 60 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1an = 6, speed = [2,10,3,1,5,8], efficiency = [5,4,3,9,7,2], k = 3\n\u8f93\u51fa\uff1a68\n\u89e3\u91ca\uff1a\n\u6b64\u793a\u4f8b\u4e0e\u7b2c\u4e00\u4e2a\u793a\u4f8b\u76f8\u540c\uff0c\u9664\u4e86 k = 3 \u3002\u6211\u4eec\u53ef\u4ee5\u9009\u62e9\u5de5\u7a0b\u5e08 1 \uff0c\u5de5\u7a0b\u5e08 2 \u548c\u5de5\u7a0b\u5e08 5 \u5f97\u5230\u6700\u5927\u7684\u56e2\u961f\u8868\u73b0\u503c\u3002\u8868\u73b0\u503c\u4e3a performance = (2 + 10 + 5) * min(5, 4, 7) = 68 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1an = 6, speed = [2,10,3,1,5,8], efficiency = [5,4,3,9,7,2], k = 4\n\u8f93\u51fa\uff1a72\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 10^5
    • \n\t
    • speed.length == n
    • \n\t
    • efficiency.length == n
    • \n\t
    • 1 <= speed[i] <= 10^5
    • \n\t
    • 1 <= efficiency[i] <= 10^8
    • \n\t
    • 1 <= k <= n
    • \n
    \n", "tags_en": ["Greedy", "Sort"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6392\u5e8f"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxPerformance(int n, vector& speed, vector& efficiency, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxPerformance(int n, int[] speed, int[] efficiency, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxPerformance(self, n, speed, efficiency, k):\n \"\"\"\n :type n: int\n :type speed: List[int]\n :type efficiency: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxPerformance(self, n: int, speed: List[int], efficiency: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxPerformance(int n, int* speed, int speedSize, int* efficiency, int efficiencySize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxPerformance(int n, int[] speed, int[] efficiency, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[]} speed\n * @param {number[]} efficiency\n * @param {number} k\n * @return {number}\n */\nvar maxPerformance = function(n, speed, efficiency, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[]} speed\n# @param {Integer[]} efficiency\n# @param {Integer} k\n# @return {Integer}\ndef max_performance(n, speed, efficiency, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxPerformance(_ n: Int, _ speed: [Int], _ efficiency: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxPerformance(n int, speed []int, efficiency []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxPerformance(n: Int, speed: Array[Int], efficiency: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxPerformance(n: Int, speed: IntArray, efficiency: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_performance(n: i32, speed: Vec, efficiency: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[] $speed\n * @param Integer[] $efficiency\n * @param Integer $k\n * @return Integer\n */\n function maxPerformance($n, $speed, $efficiency, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxPerformance(n: number, speed: number[], efficiency: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-performance n speed efficiency k)\n (-> exact-integer? (listof exact-integer?) (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1383](https://leetcode-cn.com/problems/maximum-performance-of-a-team)", "[\u6700\u5927\u7684\u56e2\u961f\u8868\u73b0\u503c](/solution/1300-1399/1383.Maximum%20Performance%20of%20a%20Team/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6392\u5e8f`", "\u56f0\u96be", ""], "md_table_row_en": ["[1383](https://leetcode.com/problems/maximum-performance-of-a-team)", "[Maximum Performance of a Team](/solution/1300-1399/1383.Maximum%20Performance%20of%20a%20Team/README_EN.md)", "`Greedy`,`Sort`", "Hard", ""]}, {"question_id": "1498", "frontend_question_id": "1379", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree", "url_en": "https://leetcode.com/problems/find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree", "relative_path_cn": "/solution/1300-1399/1379.Find%20a%20Corresponding%20Node%20of%20a%20Binary%20Tree%20in%20a%20Clone%20of%20That%20Tree/README.md", "relative_path_en": "/solution/1300-1399/1379.Find%20a%20Corresponding%20Node%20of%20a%20Binary%20Tree%20in%20a%20Clone%20of%20That%20Tree/README_EN.md", "title_cn": "\u627e\u51fa\u514b\u9686\u4e8c\u53c9\u6811\u4e2d\u7684\u76f8\u540c\u8282\u70b9", "title_en": "Find a Corresponding Node of a Binary Tree in a Clone of That Tree", "question_title_slug": "find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree", "content_en": "

    Given two binary trees original and cloned and given a reference to a node target in the original tree.

    \r\n\r\n

    The cloned tree is a copy of the original tree.

    \r\n\r\n

    Return a reference to the same node in the cloned tree.

    \r\n\r\n

    Note that you are not allowed to change any of the two trees or the target node and the answer must be a reference to a node in the cloned tree.

    \r\n\r\n

    Follow up: Solve the problem if repeated values on the tree are allowed.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\"\"\r\n
    \r\nInput: tree = [7,4,3,null,null,6,19], target = 3\r\nOutput: 3\r\nExplanation: In all examples the original and cloned trees are shown. The target node is a green node from the original tree. The answer is the yellow node from the cloned tree.\r\n
    \r\n\r\n

    Example 2:

    \r\n\"\"\r\n
    \r\nInput: tree = [7], target =  7\r\nOutput: 7\r\n
    \r\n\r\n

    Example 3:

    \r\n\"\"\r\n
    \r\nInput: tree = [8,null,6,null,5,null,4,null,3,null,2,null,1], target = 4\r\nOutput: 4\r\n
    \r\n\r\n

    Example 4:

    \r\n\"\"\r\n
    \r\nInput: tree = [1,2,3,4,5,6,7,8,9,10], target = 5\r\nOutput: 5\r\n
    \r\n\r\n

    Example 5:

    \r\n\"\"\r\n
    \r\nInput: tree = [1,2,null,3], target = 2\r\nOutput: 2\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • The number of nodes in the tree is in the range [1, 10^4].
    • \r\n\t
    • The values of the nodes of the tree are unique.
    • \r\n\t
    • target node is a node from the original tree and is not null.
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e24\u68f5\u4e8c\u53c9\u6811\uff0c\u539f\u59cb\u6811 original \u548c\u514b\u9686\u6811 cloned\uff0c\u4ee5\u53ca\u4e00\u4e2a\u4f4d\u4e8e\u539f\u59cb\u6811 original \u4e2d\u7684\u76ee\u6807\u8282\u70b9 target\u3002

    \n\n

    \u5176\u4e2d\uff0c\u514b\u9686\u6811 cloned \u662f\u539f\u59cb\u6811 original \u7684\u4e00\u4e2a \u526f\u672c \u3002

    \n\n

    \u8bf7\u627e\u51fa\u5728\u6811 cloned \u4e2d\uff0c\u4e0e target \u76f8\u540c \u7684\u8282\u70b9\uff0c\u5e76\u8fd4\u56de\u5bf9\u8be5\u8282\u70b9\u7684\u5f15\u7528\uff08\u5728 C/C++ \u7b49\u6709\u6307\u9488\u7684\u8bed\u8a00\u4e2d\u8fd4\u56de \u8282\u70b9\u6307\u9488\uff0c\u5176\u4ed6\u8bed\u8a00\u8fd4\u56de\u8282\u70b9\u672c\u8eab\uff09\u3002

    \n\n

     

    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    1. \u4f60 \u4e0d\u80fd \u5bf9\u4e24\u68f5\u4e8c\u53c9\u6811\uff0c\u4ee5\u53ca target \u8282\u70b9\u8fdb\u884c\u66f4\u6539\u3002
    2. \n\t
    3. \u53ea\u80fd \u8fd4\u56de\u5bf9\u514b\u9686\u6811 cloned \u4e2d\u5df2\u6709\u7684\u8282\u70b9\u7684\u5f15\u7528\u3002
    4. \n
    \n\n
      \n
    \n\n

    \u8fdb\u9636\uff1a\u5982\u679c\u6811\u4e2d\u5141\u8bb8\u51fa\u73b0\u503c\u76f8\u540c\u7684\u8282\u70b9\uff0c\u4f60\u5c06\u5982\u4f55\u89e3\u7b54\uff1f

    \n\n

     

    \n\n
      \n
    \n\n

    \u793a\u4f8b 1:

    \n\n

    \"\"

    \n\n
    \u8f93\u5165: tree = [7,4,3,null,null,6,19], target = 3\n\u8f93\u51fa: 3\n\u89e3\u91ca: \u4e0a\u56fe\u753b\u51fa\u4e86\u6811 original \u548c cloned\u3002target \u8282\u70b9\u5728\u6811 original \u4e2d\uff0c\u7528\u7eff\u8272\u6807\u8bb0\u3002\u7b54\u6848\u662f\u6811 cloned \u4e2d\u7684\u9ec4\u989c\u8272\u7684\u8282\u70b9\uff08\u5176\u4ed6\u793a\u4f8b\u7c7b\u4f3c\uff09\u3002
    \n\n

    \u793a\u4f8b 2:

    \n\n

    \"\"

    \n\n
    \u8f93\u5165: tree = [7], target =  7\n\u8f93\u51fa: 7\n
    \n\n

    \u793a\u4f8b 3:

    \n\n

    \"\"

    \n\n
    \u8f93\u5165: tree = [8,null,6,null,5,null,4,null,3,null,2,null,1], target = 4\n\u8f93\u51fa: 4\n
    \n\n

    \u793a\u4f8b 4:

    \n\n

    \"\"

    \n\n
    \u8f93\u5165: tree = [1,2,3,4,5,6,7,8,9,10], target = 5\n\u8f93\u51fa: 5\n
    \n\n

    \u793a\u4f8b 5:

    \n\n

    \"\"

    \n\n
    \u8f93\u5165: tree = [1,2,null,3], target = 2\n\u8f93\u51fa: 2
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u7684\u6570\u91cf\u8303\u56f4\u4e3a [1, 10^4] \u3002
    • \n\t
    • \u540c\u4e00\u68f5\u6811\u4e2d\uff0c\u6ca1\u6709\u503c\u76f8\u540c\u7684\u8282\u70b9\u3002
    • \n\t
    • target \u8282\u70b9\u662f\u6811 original \u4e2d\u7684\u4e00\u4e2a\u8282\u70b9\uff0c\u5e76\u4e14\u4e0d\u4f1a\u662f null \u3002
    • \n
    \n", "tags_en": ["Tree", "Depth-first Search", "Breadth-first Search", "Recursion"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u9012\u5f52"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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\nclass Solution {\npublic:\n TreeNode* getTargetCopy(TreeNode* original, TreeNode* cloned, TreeNode* target) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode(int x) { val = x; }\n * }\n */\n\nclass Solution {\n public final TreeNode getTargetCopy(final TreeNode original, final TreeNode cloned, final TreeNode target) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution(object):\n def getTargetCopy(self, original, cloned, target):\n \"\"\"\n :type original: TreeNode\n :type cloned: TreeNode\n :type target: TreeNode\n :rtype: TreeNode\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution:\n def getTargetCopy(self, original: TreeNode, cloned: TreeNode, target: TreeNode) -> TreeNode:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int x) { val = x; }\n * }\n */\n\npublic class Solution {\n public TreeNode GetTargetCopy(TreeNode original, TreeNode cloned, TreeNode target) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val) {\n * this.val = val;\n * this.left = this.right = null;\n * }\n */\n/**\n * @param {TreeNode} original\n * @param {TreeNode} cloned\n * @param {TreeNode} target\n * @return {TreeNode}\n */\n\nvar getTargetCopy = function(original, cloned, target) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction getTargetCopy(original: TreeNode | null, cloned: TreeNode | null, target: TreeNode | null): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1379](https://leetcode-cn.com/problems/find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree)", "[\u627e\u51fa\u514b\u9686\u4e8c\u53c9\u6811\u4e2d\u7684\u76f8\u540c\u8282\u70b9](/solution/1300-1399/1379.Find%20a%20Corresponding%20Node%20of%20a%20Binary%20Tree%20in%20a%20Clone%20of%20That%20Tree/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u9012\u5f52`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1379](https://leetcode.com/problems/find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree)", "[Find a Corresponding Node of a Binary Tree in a Clone of That Tree](/solution/1300-1399/1379.Find%20a%20Corresponding%20Node%20of%20a%20Binary%20Tree%20in%20a%20Clone%20of%20That%20Tree/README_EN.md)", "`Tree`,`Depth-first Search`,`Breadth-first Search`,`Recursion`", "Medium", ""]}, {"question_id": "1497", "frontend_question_id": "1381", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/design-a-stack-with-increment-operation", "url_en": "https://leetcode.com/problems/design-a-stack-with-increment-operation", "relative_path_cn": "/solution/1300-1399/1381.Design%20a%20Stack%20With%20Increment%20Operation/README.md", "relative_path_en": "/solution/1300-1399/1381.Design%20a%20Stack%20With%20Increment%20Operation/README_EN.md", "title_cn": "\u8bbe\u8ba1\u4e00\u4e2a\u652f\u6301\u589e\u91cf\u64cd\u4f5c\u7684\u6808", "title_en": "Design a Stack With Increment Operation", "question_title_slug": "design-a-stack-with-increment-operation", "content_en": "

    Design a stack which supports the following operations.

    \n\n

    Implement the CustomStack class:

    \n\n
      \n\t
    • CustomStack(int maxSize) Initializes the object with maxSize which is the maximum number of elements in the stack or do nothing if the stack reached the maxSize.
    • \n\t
    • void push(int x) Adds x to the top of the stack if the stack hasn't reached the maxSize.
    • \n\t
    • int pop() Pops and returns the top of stack or -1 if the stack is empty.
    • \n\t
    • void inc(int k, int val) Increments the bottom k elements of the stack by val. If there are less than k elements in the stack, just increment all the elements in the stack.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["CustomStack","push","push","pop","push","push","push","increment","increment","pop","pop","pop","pop"]\n[[3],[1],[2],[],[2],[3],[4],[5,100],[2,100],[],[],[],[]]\nOutput\n[null,null,null,2,null,null,null,null,null,103,202,201,-1]\nExplanation\nCustomStack customStack = new CustomStack(3); // Stack is Empty []\ncustomStack.push(1);                          // stack becomes [1]\ncustomStack.push(2);                          // stack becomes [1, 2]\ncustomStack.pop();                            // return 2 --> Return top of the stack 2, stack becomes [1]\ncustomStack.push(2);                          // stack becomes [1, 2]\ncustomStack.push(3);                          // stack becomes [1, 2, 3]\ncustomStack.push(4);                          // stack still [1, 2, 3], Don't add another elements as size is 4\ncustomStack.increment(5, 100);                // stack becomes [101, 102, 103]\ncustomStack.increment(2, 100);                // stack becomes [201, 202, 103]\ncustomStack.pop();                            // return 103 --> Return top of the stack 103, stack becomes [201, 202]\ncustomStack.pop();                            // return 202 --> Return top of the stack 102, stack becomes [201]\ncustomStack.pop();                            // return 201 --> Return top of the stack 101, stack becomes []\ncustomStack.pop();                            // return -1 --> Stack is empty return -1.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= maxSize <= 1000
    • \n\t
    • 1 <= x <= 1000
    • \n\t
    • 1 <= k <= 1000
    • \n\t
    • 0 <= val <= 100
    • \n\t
    • At most 1000 calls will be made to each method of increment, push and pop each separately.
    • \n
    \n", "content_cn": "

    \u8bf7\u4f60\u8bbe\u8ba1\u4e00\u4e2a\u652f\u6301\u4e0b\u8ff0\u64cd\u4f5c\u7684\u6808\u3002

    \n\n

    \u5b9e\u73b0\u81ea\u5b9a\u4e49\u6808\u7c7b CustomStack \uff1a

    \n\n
      \n\t
    • CustomStack(int maxSize)\uff1a\u7528 maxSize \u521d\u59cb\u5316\u5bf9\u8c61\uff0cmaxSize \u662f\u6808\u4e2d\u6700\u591a\u80fd\u5bb9\u7eb3\u7684\u5143\u7d20\u6570\u91cf\uff0c\u6808\u5728\u589e\u957f\u5230 maxSize \u4e4b\u540e\u5219\u4e0d\u652f\u6301 push \u64cd\u4f5c\u3002
    • \n\t
    • void push(int x)\uff1a\u5982\u679c\u6808\u8fd8\u672a\u589e\u957f\u5230 maxSize \uff0c\u5c31\u5c06 x \u6dfb\u52a0\u5230\u6808\u9876\u3002
    • \n\t
    • int pop()\uff1a\u5f39\u51fa\u6808\u9876\u5143\u7d20\uff0c\u5e76\u8fd4\u56de\u6808\u9876\u7684\u503c\uff0c\u6216\u6808\u4e3a\u7a7a\u65f6\u8fd4\u56de -1 \u3002
    • \n\t
    • void inc(int k, int val)\uff1a\u6808\u5e95\u7684 k \u4e2a\u5143\u7d20\u7684\u503c\u90fd\u589e\u52a0 val \u3002\u5982\u679c\u6808\u4e2d\u5143\u7d20\u603b\u6570\u5c0f\u4e8e k \uff0c\u5219\u6808\u4e2d\u7684\u6240\u6709\u5143\u7d20\u90fd\u589e\u52a0 val \u3002
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1a\n["CustomStack","push","push","pop","push","push","push","increment","increment","pop","pop","pop","pop"]\n[[3],[1],[2],[],[2],[3],[4],[5,100],[2,100],[],[],[],[]]\n\u8f93\u51fa\uff1a\n[null,null,null,2,null,null,null,null,null,103,202,201,-1]\n\u89e3\u91ca\uff1a\nCustomStack customStack = new CustomStack(3); // \u6808\u662f\u7a7a\u7684 []\ncustomStack.push(1);                          // \u6808\u53d8\u4e3a [1]\ncustomStack.push(2);                          // \u6808\u53d8\u4e3a [1, 2]\ncustomStack.pop();                            // \u8fd4\u56de 2 --> \u8fd4\u56de\u6808\u9876\u503c 2\uff0c\u6808\u53d8\u4e3a [1]\ncustomStack.push(2);                          // \u6808\u53d8\u4e3a [1, 2]\ncustomStack.push(3);                          // \u6808\u53d8\u4e3a [1, 2, 3]\ncustomStack.push(4);                          // \u6808\u4ecd\u7136\u662f [1, 2, 3]\uff0c\u4e0d\u80fd\u6dfb\u52a0\u5176\u4ed6\u5143\u7d20\u4f7f\u6808\u5927\u5c0f\u53d8\u4e3a 4\ncustomStack.increment(5, 100);                // \u6808\u53d8\u4e3a [101, 102, 103]\ncustomStack.increment(2, 100);                // \u6808\u53d8\u4e3a [201, 202, 103]\ncustomStack.pop();                            // \u8fd4\u56de 103 --> \u8fd4\u56de\u6808\u9876\u503c 103\uff0c\u6808\u53d8\u4e3a [201, 202]\ncustomStack.pop();                            // \u8fd4\u56de 202 --> \u8fd4\u56de\u6808\u9876\u503c 202\uff0c\u6808\u53d8\u4e3a [201]\ncustomStack.pop();                            // \u8fd4\u56de 201 --> \u8fd4\u56de\u6808\u9876\u503c 201\uff0c\u6808\u53d8\u4e3a []\ncustomStack.pop();                            // \u8fd4\u56de -1 --> \u6808\u4e3a\u7a7a\uff0c\u8fd4\u56de -1\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= maxSize <= 1000
    • \n\t
    • 1 <= x <= 1000
    • \n\t
    • 1 <= k <= 1000
    • \n\t
    • 0 <= val <= 100
    • \n\t
    • \u6bcf\u79cd\u65b9\u6cd5 increment\uff0cpush \u4ee5\u53ca pop \u5206\u522b\u6700\u591a\u8c03\u7528 1000 \u6b21
    • \n
    \n", "tags_en": ["Stack", "Design"], "tags_cn": ["\u6808", "\u8bbe\u8ba1"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class CustomStack {\npublic:\n CustomStack(int maxSize) {\n\n }\n \n void push(int x) {\n\n }\n \n int pop() {\n\n }\n \n void increment(int k, int val) {\n\n }\n};\n\n/**\n * Your CustomStack object will be instantiated and called as such:\n * CustomStack* obj = new CustomStack(maxSize);\n * obj->push(x);\n * int param_2 = obj->pop();\n * obj->increment(k,val);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class CustomStack {\n\n public CustomStack(int maxSize) {\n\n }\n \n public void push(int x) {\n\n }\n \n public int pop() {\n\n }\n \n public void increment(int k, int val) {\n\n }\n}\n\n/**\n * Your CustomStack object will be instantiated and called as such:\n * CustomStack obj = new CustomStack(maxSize);\n * obj.push(x);\n * int param_2 = obj.pop();\n * obj.increment(k,val);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class CustomStack(object):\n\n def __init__(self, maxSize):\n \"\"\"\n :type maxSize: int\n \"\"\"\n\n\n def push(self, x):\n \"\"\"\n :type x: int\n :rtype: None\n \"\"\"\n\n\n def pop(self):\n \"\"\"\n :rtype: int\n \"\"\"\n\n\n def increment(self, k, val):\n \"\"\"\n :type k: int\n :type val: int\n :rtype: None\n \"\"\"\n\n\n\n# Your CustomStack object will be instantiated and called as such:\n# obj = CustomStack(maxSize)\n# obj.push(x)\n# param_2 = obj.pop()\n# obj.increment(k,val)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class CustomStack:\n\n def __init__(self, maxSize: int):\n\n\n def push(self, x: int) -> None:\n\n\n def pop(self) -> int:\n\n\n def increment(self, k: int, val: int) -> None:\n\n\n\n# Your CustomStack object will be instantiated and called as such:\n# obj = CustomStack(maxSize)\n# obj.push(x)\n# param_2 = obj.pop()\n# obj.increment(k,val)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} CustomStack;\n\n\nCustomStack* customStackCreate(int maxSize) {\n\n}\n\nvoid customStackPush(CustomStack* obj, int x) {\n\n}\n\nint customStackPop(CustomStack* obj) {\n\n}\n\nvoid customStackIncrement(CustomStack* obj, int k, int val) {\n\n}\n\nvoid customStackFree(CustomStack* obj) {\n\n}\n\n/**\n * Your CustomStack struct will be instantiated and called as such:\n * CustomStack* obj = customStackCreate(maxSize);\n * customStackPush(obj, x);\n \n * int param_2 = customStackPop(obj);\n \n * customStackIncrement(obj, k, val);\n \n * customStackFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class CustomStack {\n\n public CustomStack(int maxSize) {\n\n }\n \n public void Push(int x) {\n\n }\n \n public int Pop() {\n\n }\n \n public void Increment(int k, int val) {\n\n }\n}\n\n/**\n * Your CustomStack object will be instantiated and called as such:\n * CustomStack obj = new CustomStack(maxSize);\n * obj.Push(x);\n * int param_2 = obj.Pop();\n * obj.Increment(k,val);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} maxSize\n */\nvar CustomStack = function(maxSize) {\n\n};\n\n/** \n * @param {number} x\n * @return {void}\n */\nCustomStack.prototype.push = function(x) {\n\n};\n\n/**\n * @return {number}\n */\nCustomStack.prototype.pop = function() {\n\n};\n\n/** \n * @param {number} k \n * @param {number} val\n * @return {void}\n */\nCustomStack.prototype.increment = function(k, val) {\n\n};\n\n/**\n * Your CustomStack object will be instantiated and called as such:\n * var obj = new CustomStack(maxSize)\n * obj.push(x)\n * var param_2 = obj.pop()\n * obj.increment(k,val)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class CustomStack\n\n=begin\n :type max_size: Integer\n=end\n def initialize(max_size)\n\n end\n\n\n=begin\n :type x: Integer\n :rtype: Void\n=end\n def push(x)\n\n end\n\n\n=begin\n :rtype: Integer\n=end\n def pop()\n\n end\n\n\n=begin\n :type k: Integer\n :type val: Integer\n :rtype: Void\n=end\n def increment(k, val)\n\n end\n\n\nend\n\n# Your CustomStack object will be instantiated and called as such:\n# obj = CustomStack.new(max_size)\n# obj.push(x)\n# param_2 = obj.pop()\n# obj.increment(k, val)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass CustomStack {\n\n init(_ maxSize: Int) {\n\n }\n \n func push(_ x: Int) {\n\n }\n \n func pop() -> Int {\n\n }\n \n func increment(_ k: Int, _ val: Int) {\n\n }\n}\n\n/**\n * Your CustomStack object will be instantiated and called as such:\n * let obj = CustomStack(maxSize)\n * obj.push(x)\n * let ret_2: Int = obj.pop()\n * obj.increment(k, val)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type CustomStack struct {\n\n}\n\n\nfunc Constructor(maxSize int) CustomStack {\n\n}\n\n\nfunc (this *CustomStack) Push(x int) {\n\n}\n\n\nfunc (this *CustomStack) Pop() int {\n\n}\n\n\nfunc (this *CustomStack) Increment(k int, val int) {\n\n}\n\n\n/**\n * Your CustomStack object will be instantiated and called as such:\n * obj := Constructor(maxSize);\n * obj.Push(x);\n * param_2 := obj.Pop();\n * obj.Increment(k,val);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class CustomStack(_maxSize: Int) {\n\n def push(x: Int) {\n\n }\n\n def pop(): Int = {\n\n }\n\n def increment(k: Int, `val`: Int) {\n\n }\n\n}\n\n/**\n * Your CustomStack object will be instantiated and called as such:\n * var obj = new CustomStack(maxSize)\n * obj.push(x)\n * var param_2 = obj.pop()\n * obj.increment(k,`val`)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class CustomStack(maxSize: Int) {\n\n fun push(x: Int) {\n\n }\n\n fun pop(): Int {\n\n }\n\n fun increment(k: Int, `val`: Int) {\n\n }\n\n}\n\n/**\n * Your CustomStack object will be instantiated and called as such:\n * var obj = CustomStack(maxSize)\n * obj.push(x)\n * var param_2 = obj.pop()\n * obj.increment(k,`val`)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct CustomStack {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl CustomStack {\n\n fn new(maxSize: i32) -> Self {\n\n }\n \n fn push(&self, x: i32) {\n\n }\n \n fn pop(&self) -> i32 {\n\n }\n \n fn increment(&self, k: i32, val: i32) {\n\n }\n}\n\n/**\n * Your CustomStack object will be instantiated and called as such:\n * let obj = CustomStack::new(maxSize);\n * obj.push(x);\n * let ret_2: i32 = obj.pop();\n * obj.increment(k, val);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class CustomStack {\n /**\n * @param Integer $maxSize\n */\n function __construct($maxSize) {\n\n }\n\n /**\n * @param Integer $x\n * @return NULL\n */\n function push($x) {\n\n }\n\n /**\n * @return Integer\n */\n function pop() {\n\n }\n\n /**\n * @param Integer $k\n * @param Integer $val\n * @return NULL\n */\n function increment($k, $val) {\n\n }\n}\n\n/**\n * Your CustomStack object will be instantiated and called as such:\n * $obj = CustomStack($maxSize);\n * $obj->push($x);\n * $ret_2 = $obj->pop();\n * $obj->increment($k, $val);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class CustomStack {\n constructor(maxSize: number) {\n\n }\n\n push(x: number): void {\n\n }\n\n pop(): number {\n\n }\n\n increment(k: number, val: number): void {\n\n }\n}\n\n/**\n * Your CustomStack object will be instantiated and called as such:\n * var obj = new CustomStack(maxSize)\n * obj.push(x)\n * var param_2 = obj.pop()\n * obj.increment(k,val)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define custom-stack%\n (class object%\n (super-new)\n\n ; max-size : exact-integer?\n (init-field\n max-size)\n \n ; push : exact-integer? -> void?\n (define/public (push x)\n\n )\n ; pop : -> exact-integer?\n (define/public (pop)\n\n )\n ; increment : exact-integer? exact-integer? -> void?\n (define/public (increment k val)\n\n )))\n\n;; Your custom-stack% object will be instantiated and called as such:\n;; (define obj (new custom-stack% [maxSize maxSize]))\n;; (send obj push x)\n;; (define param_2 (send obj pop))\n;; (send obj increment k val)", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1381](https://leetcode-cn.com/problems/design-a-stack-with-increment-operation)", "[\u8bbe\u8ba1\u4e00\u4e2a\u652f\u6301\u589e\u91cf\u64cd\u4f5c\u7684\u6808](/solution/1300-1399/1381.Design%20a%20Stack%20With%20Increment%20Operation/README.md)", "`\u6808`,`\u8bbe\u8ba1`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1381](https://leetcode.com/problems/design-a-stack-with-increment-operation)", "[Design a Stack With Increment Operation](/solution/1300-1399/1381.Design%20a%20Stack%20With%20Increment%20Operation/README_EN.md)", "`Stack`,`Design`", "Medium", ""]}, {"question_id": "1496", "frontend_question_id": "1380", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/lucky-numbers-in-a-matrix", "url_en": "https://leetcode.com/problems/lucky-numbers-in-a-matrix", "relative_path_cn": "/solution/1300-1399/1380.Lucky%20Numbers%20in%20a%20Matrix/README.md", "relative_path_en": "/solution/1300-1399/1380.Lucky%20Numbers%20in%20a%20Matrix/README_EN.md", "title_cn": "\u77e9\u9635\u4e2d\u7684\u5e78\u8fd0\u6570", "title_en": "Lucky Numbers in a Matrix", "question_title_slug": "lucky-numbers-in-a-matrix", "content_en": "

    Given a m * n matrix of distinct numbers, return all lucky numbers in the matrix in any order.

    \n\n

    A lucky number is an element of the matrix such that it is the minimum element in its row and maximum in its column.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: matrix = [[3,7,8],[9,11,13],[15,16,17]]\nOutput: [15]\nExplanation: 15 is the only lucky number since it is the minimum in its row and the maximum in its column\n
    \n\n

    Example 2:

    \n\n
    \nInput: matrix = [[1,10,4,2],[9,3,8,7],[15,16,17,12]]\nOutput: [12]\nExplanation: 12 is the only lucky number since it is the minimum in its row and the maximum in its column.\n
    \n\n

    Example 3:

    \n\n
    \nInput: matrix = [[7,8],[1,2]]\nOutput: [7]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == mat.length
    • \n\t
    • n == mat[i].length
    • \n\t
    • 1 <= n, m <= 50
    • \n\t
    • 1 <= matrix[i][j] <= 10^5.
    • \n\t
    • All elements in the matrix are distinct.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a m * n \u7684\u77e9\u9635\uff0c\u77e9\u9635\u4e2d\u7684\u6570\u5b57 \u5404\u4e0d\u76f8\u540c \u3002\u8bf7\u4f60\u6309 \u4efb\u610f \u987a\u5e8f\u8fd4\u56de\u77e9\u9635\u4e2d\u7684\u6240\u6709\u5e78\u8fd0\u6570\u3002

    \n\n

    \u5e78\u8fd0\u6570\u662f\u6307\u77e9\u9635\u4e2d\u6ee1\u8db3\u540c\u65f6\u4e0b\u5217\u4e24\u4e2a\u6761\u4ef6\u7684\u5143\u7d20\uff1a

    \n\n
      \n\t
    • \u5728\u540c\u4e00\u884c\u7684\u6240\u6709\u5143\u7d20\u4e2d\u6700\u5c0f
    • \n\t
    • \u5728\u540c\u4e00\u5217\u7684\u6240\u6709\u5143\u7d20\u4e2d\u6700\u5927
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1amatrix = [[3,7,8],[9,11,13],[15,16,17]]\n\u8f93\u51fa\uff1a[15]\n\u89e3\u91ca\uff1a15 \u662f\u552f\u4e00\u7684\u5e78\u8fd0\u6570\uff0c\u56e0\u4e3a\u5b83\u662f\u5176\u6240\u5728\u884c\u4e2d\u7684\u6700\u5c0f\u503c\uff0c\u4e5f\u662f\u6240\u5728\u5217\u4e2d\u7684\u6700\u5927\u503c\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1amatrix = [[1,10,4,2],[9,3,8,7],[15,16,17,12]]\n\u8f93\u51fa\uff1a[12]\n\u89e3\u91ca\uff1a12 \u662f\u552f\u4e00\u7684\u5e78\u8fd0\u6570\uff0c\u56e0\u4e3a\u5b83\u662f\u5176\u6240\u5728\u884c\u4e2d\u7684\u6700\u5c0f\u503c\uff0c\u4e5f\u662f\u6240\u5728\u5217\u4e2d\u7684\u6700\u5927\u503c\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1amatrix = [[7,8],[1,2]]\n\u8f93\u51fa\uff1a[7]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == mat.length
    • \n\t
    • n == mat[i].length
    • \n\t
    • 1 <= n, m <= 50
    • \n\t
    • 1 <= matrix[i][j] <= 10^5
    • \n\t
    • \u77e9\u9635\u4e2d\u7684\u6240\u6709\u5143\u7d20\u90fd\u662f\u4e0d\u540c\u7684
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector luckyNumbers (vector>& matrix) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List luckyNumbers (int[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def luckyNumbers (self, matrix):\n \"\"\"\n :type matrix: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def luckyNumbers (self, matrix: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* luckyNumbers (int** matrix, int matrixSize, int* matrixColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList LuckyNumbers (int[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} matrix\n * @return {number[]}\n */\nvar luckyNumbers = function(matrix) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} matrix\n# @return {Integer[]}\ndef lucky_numbers (matrix)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func luckyNumbers (_ matrix: [[Int]]) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func luckyNumbers (matrix [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def luckyNumbers (matrix: Array[Array[Int]]): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun luckyNumbers (matrix: Array): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn lucky_numbers (matrix: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $matrix\n * @return Integer[]\n */\n function luckyNumbers ($matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function luckyNumbers (matrix: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (lucky-numbers matrix)\n (-> (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1380](https://leetcode-cn.com/problems/lucky-numbers-in-a-matrix)", "[\u77e9\u9635\u4e2d\u7684\u5e78\u8fd0\u6570](/solution/1300-1399/1380.Lucky%20Numbers%20in%20a%20Matrix/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1380](https://leetcode.com/problems/lucky-numbers-in-a-matrix)", "[Lucky Numbers in a Matrix](/solution/1300-1399/1380.Lucky%20Numbers%20in%20a%20Matrix/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1495", "frontend_question_id": "1364", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/number-of-trusted-contacts-of-a-customer", "url_en": "https://leetcode.com/problems/number-of-trusted-contacts-of-a-customer", "relative_path_cn": "/solution/1300-1399/1364.Number%20of%20Trusted%20Contacts%20of%20a%20Customer/README.md", "relative_path_en": "/solution/1300-1399/1364.Number%20of%20Trusted%20Contacts%20of%20a%20Customer/README_EN.md", "title_cn": "\u987e\u5ba2\u7684\u53ef\u4fe1\u8054\u7cfb\u4eba\u6570\u91cf", "title_en": "Number of Trusted Contacts of a Customer", "question_title_slug": "number-of-trusted-contacts-of-a-customer", "content_en": "

    Table: Customers

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| customer_id   | int     |\n| customer_name | varchar |\n| email         | varchar |\n+---------------+---------+\ncustomer_id is the primary key for this table.\nEach row of this table contains the name and the email of a customer of an online shop.\n
    \n\n

     

    \n\n

    Table: Contacts

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| user_id       | id      |\n| contact_name  | varchar |\n| contact_email | varchar |\n+---------------+---------+\n(user_id, contact_email) is the primary key for this table.\nEach row of this table contains the name and email of one contact of customer with user_id.\nThis table contains information about people each customer trust. The contact may or may not exist in the Customers table.\n\n
    \n\n

     

    \n\n

    Table: Invoices

    \n\n
    \n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| invoice_id   | int     |\n| price        | int     |\n| user_id      | int     |\n+--------------+---------+\ninvoice_id is the primary key for this table.\nEach row of this table indicates that user_id has an invoice with invoice_id and a price.\n
    \n\n

     

    \n\n

    Write an SQL query to find the following for each invoice_id:

    \n\n
      \n\t
    • customer_name: The name of the customer the invoice is related to.
    • \n\t
    • price: The price of the invoice.
    • \n\t
    • contacts_cnt: The number of contacts related to the customer.
    • \n\t
    • trusted_contacts_cnt: The number of contacts related to the customer and at the same time they are customers to the shop. (i.e His/Her email exists in the Customers table.)
    • \n
    \n\n

    Order the result table by invoice_id.

    \n\n

    The query result format is in the following example:

    \n\n
    \nCustomers table:\n+-------------+---------------+--------------------+\n| customer_id | customer_name | email              |\n+-------------+---------------+--------------------+\n| 1           | Alice         | alice@leetcode.com |\n| 2           | Bob           | bob@leetcode.com   |\n| 13          | John          | john@leetcode.com  |\n| 6           | Alex          | alex@leetcode.com  |\n+-------------+---------------+--------------------+\nContacts table:\n+-------------+--------------+--------------------+\n| user_id     | contact_name | contact_email      |\n+-------------+--------------+--------------------+\n| 1           | Bob          | bob@leetcode.com   |\n| 1           | John         | john@leetcode.com  |\n| 1           | Jal          | jal@leetcode.com   |\n| 2           | Omar         | omar@leetcode.com  |\n| 2           | Meir         | meir@leetcode.com  |\n| 6           | Alice        | alice@leetcode.com |\n+-------------+--------------+--------------------+\nInvoices table:\n+------------+-------+---------+\n| invoice_id | price | user_id |\n+------------+-------+---------+\n| 77         | 100   | 1       |\n| 88         | 200   | 1       |\n| 99         | 300   | 2       |\n| 66         | 400   | 2       |\n| 55         | 500   | 13      |\n| 44         | 60    | 6       |\n+------------+-------+---------+\nResult table:\n+------------+---------------+-------+--------------+----------------------+\n| invoice_id | customer_name | price | contacts_cnt | trusted_contacts_cnt |\n+------------+---------------+-------+--------------+----------------------+\n| 44         | Alex          | 60    | 1            | 1                    |\n| 55         | John          | 500   | 0            | 0                    |\n| 66         | Bob           | 400   | 2            | 0                    |\n| 77         | Alice         | 100   | 3            | 2                    |\n| 88         | Alice         | 200   | 3            | 2                    |\n| 99         | Bob           | 300   | 2            | 0                    |\n+------------+---------------+-------+--------------+----------------------+\nAlice has three contacts, two of them are trusted contacts (Bob and John).\nBob has two contacts, none of them is a trusted contact.\nAlex has one contact and it is a trusted contact (Alice).\nJohn doesn't have any contacts.\n
    \n", "content_cn": "

    \u987e\u5ba2\u8868\uff1aCustomers

    \n\n
    +---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| customer_id   | int     |\n| customer_name | varchar |\n| email         | varchar |\n+---------------+---------+\ncustomer_id \u662f\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\u3002\n\u6b64\u8868\u7684\u6bcf\u4e00\u884c\u5305\u542b\u4e86\u67d0\u5728\u7ebf\u5546\u5e97\u987e\u5ba2\u7684\u59d3\u540d\u548c\u7535\u5b50\u90ae\u4ef6\u3002\n
    \n\n

     

    \n\n

    \u8054\u7cfb\u65b9\u5f0f\u8868\uff1aContacts

    \n\n
    +---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| user_id       | id      |\n| contact_name  | varchar |\n| contact_email | varchar |\n+---------------+---------+\n(user_id, contact_email) \u662f\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\u3002\n\u6b64\u8868\u7684\u6bcf\u4e00\u884c\u8868\u793a\u7f16\u53f7\u4e3a user_id \u7684\u987e\u5ba2\u7684\u67d0\u4f4d\u8054\u7cfb\u4eba\u7684\u59d3\u540d\u548c\u7535\u5b50\u90ae\u4ef6\u3002\n\u6b64\u8868\u5305\u542b\u6bcf\u4f4d\u987e\u5ba2\u7684\u8054\u7cfb\u4eba\u4fe1\u606f\uff0c\u4f46\u987e\u5ba2\u7684\u8054\u7cfb\u4eba\u4e0d\u4e00\u5b9a\u5b58\u5728\u4e8e\u987e\u5ba2\u8868\u4e2d\u3002\n
    \n\n

     

    \n\n

    \u53d1\u7968\u8868\uff1aInvoices

    \n\n
    +--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| invoice_id   | int     |\n| price        | int     |\n| user_id      | int     |\n+--------------+---------+\ninvoice_id \u662f\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\u3002\n\u6b64\u8868\u7684\u6bcf\u4e00\u884c\u5206\u522b\u8868\u793a\u7f16\u53f7\u4e3a user_id \u7684\u987e\u5ba2\u62e5\u6709\u6709\u4e00\u5f20\u7f16\u53f7\u4e3a invoice_id\u3001\u4ef7\u683c\u4e3a price \u7684\u53d1\u7968\u3002\n
    \n\n

     

    \n\n

    \u4e3a\u6bcf\u5f20\u53d1\u7968 invoice_id \u7f16\u5199\u4e00\u4e2aSQL\u67e5\u8be2\u4ee5\u67e5\u627e\u4ee5\u4e0b\u5185\u5bb9\uff1a

    \n\n
      \n\t
    • customer_name\uff1a\u4e0e\u53d1\u7968\u76f8\u5173\u7684\u987e\u5ba2\u540d\u79f0\u3002
    • \n\t
    • price\uff1a\u53d1\u7968\u7684\u4ef7\u683c\u3002
    • \n\t
    • contacts_cnt\uff1a\u8be5\u987e\u5ba2\u7684\u8054\u7cfb\u4eba\u6570\u91cf\u3002
    • \n\t
    • trusted_contacts_cnt\uff1a\u53ef\u4fe1\u8054\u7cfb\u4eba\u7684\u6570\u91cf\uff1a\u65e2\u662f\u8be5\u987e\u5ba2\u7684\u8054\u7cfb\u4eba\u53c8\u662f\u5546\u5e97\u987e\u5ba2\u7684\u8054\u7cfb\u4eba\u6570\u91cf\uff08\u5373\uff1a\u53ef\u4fe1\u8054\u7cfb\u4eba\u7684\u7535\u5b50\u90ae\u4ef6\u5b58\u5728\u4e8e\u5ba2\u6237\u8868\u4e2d\uff09\u3002
    • \n
    \n\n

    \u5c06\u67e5\u8be2\u7684\u7ed3\u679c\u6309\u7167 invoice_id \u6392\u5e8f\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u7684\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a\uff1a

    \n\n
    Customers table:\n+-------------+---------------+--------------------+\n| customer_id | customer_name | email              |\n+-------------+---------------+--------------------+\n| 1           | Alice         | alice@leetcode.com |\n| 2           | Bob           | bob@leetcode.com   |\n| 13          | John          | john@leetcode.com  |\n| 6           | Alex          | alex@leetcode.com  |\n+-------------+---------------+--------------------+\nContacts table:\n+-------------+--------------+--------------------+\n| user_id     | contact_name | contact_email      |\n+-------------+--------------+--------------------+\n| 1           | Bob          | bob@leetcode.com   |\n| 1           | John         | john@leetcode.com  |\n| 1           | Jal          | jal@leetcode.com   |\n| 2           | Omar         | omar@leetcode.com  |\n| 2           | Meir         | meir@leetcode.com  |\n| 6           | Alice        | alice@leetcode.com |\n+-------------+--------------+--------------------+\nInvoices table:\n+------------+-------+---------+\n| invoice_id | price | user_id |\n+------------+-------+---------+\n| 77         | 100   | 1       |\n| 88         | 200   | 1       |\n| 99         | 300   | 2       |\n| 66         | 400   | 2       |\n| 55         | 500   | 13      |\n| 44         | 60    | 6       |\n+------------+-------+---------+\nResult table:\n+------------+---------------+-------+--------------+----------------------+\n| invoice_id | customer_name | price | contacts_cnt | trusted_contacts_cnt |\n+------------+---------------+-------+--------------+----------------------+\n| 44         | Alex          | 60    | 1            | 1                    |\n| 55         | John          | 500   | 0            | 0                    |\n| 66         | Bob           | 400   | 2            | 0                    |\n| 77         | Alice         | 100   | 3            | 2                    |\n| 88         | Alice         | 200   | 3            | 2                    |\n| 99         | Bob           | 300   | 2            | 0                    |\n+------------+---------------+-------+--------------+----------------------+\nAlice \u6709\u4e09\u4f4d\u8054\u7cfb\u4eba\uff0c\u5176\u4e2d\u4e24\u4f4d(Bob \u548c John)\u662f\u53ef\u4fe1\u8054\u7cfb\u4eba\u3002\nBob \u6709\u4e24\u4f4d\u8054\u7cfb\u4eba, \u4ed6\u4eec\u4e2d\u7684\u4efb\u4f55\u4e00\u4f4d\u90fd\u4e0d\u662f\u53ef\u4fe1\u8054\u7cfb\u4eba\u3002\nAlex \u53ea\u6709\u4e00\u4f4d\u8054\u7cfb\u4eba(Alice)\uff0c\u5e76\u662f\u4e00\u4f4d\u53ef\u4fe1\u8054\u7cfb\u4eba\u3002\nJohn \u6ca1\u6709\u4efb\u4f55\u8054\u7cfb\u4eba\u3002\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1364](https://leetcode-cn.com/problems/number-of-trusted-contacts-of-a-customer)", "[\u987e\u5ba2\u7684\u53ef\u4fe1\u8054\u7cfb\u4eba\u6570\u91cf](/solution/1300-1399/1364.Number%20of%20Trusted%20Contacts%20of%20a%20Customer/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1364](https://leetcode.com/problems/number-of-trusted-contacts-of-a-customer)", "[Number of Trusted Contacts of a Customer](/solution/1300-1399/1364.Number%20of%20Trusted%20Contacts%20of%20a%20Customer/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1494", "frontend_question_id": "1355", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/activity-participants", "url_en": "https://leetcode.com/problems/activity-participants", "relative_path_cn": "/solution/1300-1399/1355.Activity%20Participants/README.md", "relative_path_en": "/solution/1300-1399/1355.Activity%20Participants/README_EN.md", "title_cn": "\u6d3b\u52a8\u53c2\u4e0e\u8005", "title_en": "Activity Participants", "question_title_slug": "activity-participants", "content_en": "

    Table: Friends

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| name          | varchar |\n| activity      | varchar |\n+---------------+---------+\nid is the id of the friend and primary key for this table.\nname is the name of the friend.\nactivity is the name of the activity which the friend takes part in.\n
    \n\n

    Table: Activities

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| name          | varchar |\n+---------------+---------+\nid is the primary key for this table.\nname is the name of the activity.\n
    \n\n

     

    \n\n

    Write an SQL query to find the names of all the activities with neither maximum, nor minimum number of participants.

    \n\n

    Return the result table in any order. Each activity in table Activities is performed by any person in the table Friends.

    \n\n

    The query result format is in the following example:

    \n\n
    \nFriends table:\n+------+--------------+---------------+\n| id   | name         | activity      |\n+------+--------------+---------------+\n| 1    | Jonathan D.  | Eating        |\n| 2    | Jade W.      | Singing       |\n| 3    | Victor J.    | Singing       |\n| 4    | Elvis Q.     | Eating        |\n| 5    | Daniel A.    | Eating        |\n| 6    | Bob B.       | Horse Riding  |\n+------+--------------+---------------+\n\nActivities table:\n+------+--------------+\n| id   | name         |\n+------+--------------+\n| 1    | Eating       |\n| 2    | Singing      |\n| 3    | Horse Riding |\n+------+--------------+\n\nResult table:\n+--------------+\n| activity     |\n+--------------+\n| Singing      |\n+--------------+\n\nEating activity is performed by 3 friends, maximum number of participants, (Jonathan D. , Elvis Q. and Daniel A.)\nHorse Riding activity is performed by 1 friend, minimum number of participants, (Bob B.)\nSinging is performed by 2 friends (Victor J. and Jade W.)\n
    \n", "content_cn": "

    \u8868: Friends

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| name          | varchar |\n| activity      | varchar |\n+---------------+---------+\nid \u662f\u670b\u53cb\u7684 id \u548c\u8be5\u8868\u7684\u4e3b\u952e\nname \u662f\u670b\u53cb\u7684\u540d\u5b57\nactivity \u662f\u670b\u53cb\u53c2\u52a0\u7684\u6d3b\u52a8\u7684\u540d\u5b57\n
    \n\n

    \u8868: Activities

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| name          | varchar |\n+---------------+---------+\nid \u662f\u8be5\u8868\u7684\u4e3b\u952e\nname \u662f\u6d3b\u52a8\u7684\u540d\u5b57\n
    \n\n

    \u00a0

    \n\n

    \u5199\u4e00\u6761 SQL \u67e5\u8be2\u90a3\u4e9b\u65e2\u6ca1\u6709\u6700\u591a\uff0c\u4e5f\u6ca1\u6709\u6700\u5c11\u53c2\u4e0e\u8005\u7684\u6d3b\u52a8\u7684\u540d\u5b57

    \n\n

    \u53ef\u4ee5\u4ee5\u4efb\u4f55\u987a\u5e8f\u8fd4\u56de\u7ed3\u679c\uff0cActivities \u8868\u7684\u6bcf\u9879\u6d3b\u52a8\u7684\u53c2\u4e0e\u8005\u90fd\u6765\u81ea Friends \u8868

    \n\n

    \u6ce8\u610f\uff1a\u540d\u79f0\u76f8\u540c id \u4e0d\u540c\u7684\u53c2\u4e0e\u8005\u7b97\u4f5c\u4e24\u4e2a\u4eba

    \n\n

    \u4e0b\u9762\u662f\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u7684\u4f8b\u5b50\uff1a

    \n\n
    \nFriends \u8868:\n+------+--------------+---------------+\n| id   | name         | activity      |\n+------+--------------+---------------+\n| 1    | Jonathan D.  | Eating        |\n| 2    | Jade W.      | Singing       |\n| 3    | Victor J.    | Singing       |\n| 4    | Elvis Q.     | Eating        |\n| 5    | Daniel A.    | Eating        |\n| 6    | Bob B.       | Horse Riding  |\n+------+--------------+---------------+\n\nActivities \u8868:\n+------+--------------+\n| id   | name         |\n+------+--------------+\n| 1    | Eating       |\n| 2    | Singing      |\n| 3    | Horse Riding |\n+------+--------------+\n\nResult \u8868:\n+--------------+\n| activity     |\n+--------------+\n| Singing      |\n+--------------+\n\nEating \u6d3b\u52a8\u6709\u4e09\u4e2a\u4eba\u53c2\u52a0, \u662f\u6700\u591a\u4eba\u53c2\u52a0\u7684\u6d3b\u52a8 (Jonathan D. , Elvis Q. and Daniel A.)\nHorse Riding \u6d3b\u52a8\u6709\u4e00\u4e2a\u4eba\u53c2\u52a0, \u662f\u6700\u5c11\u4eba\u53c2\u52a0\u7684\u6d3b\u52a8 (Bob B.)\nSinging \u6d3b\u52a8\u6709\u4e24\u4e2a\u4eba\u53c2\u52a0 (Victor J. and Jade W.)\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1355](https://leetcode-cn.com/problems/activity-participants)", "[\u6d3b\u52a8\u53c2\u4e0e\u8005](/solution/1300-1399/1355.Activity%20Participants/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1355](https://leetcode.com/problems/activity-participants)", "[Activity Participants](/solution/1300-1399/1355.Activity%20Participants/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1493", "frontend_question_id": "1377", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/frog-position-after-t-seconds", "url_en": "https://leetcode.com/problems/frog-position-after-t-seconds", "relative_path_cn": "/solution/1300-1399/1377.Frog%20Position%20After%20T%20Seconds/README.md", "relative_path_en": "/solution/1300-1399/1377.Frog%20Position%20After%20T%20Seconds/README_EN.md", "title_cn": "T \u79d2\u540e\u9752\u86d9\u7684\u4f4d\u7f6e", "title_en": "Frog Position After T Seconds", "question_title_slug": "frog-position-after-t-seconds", "content_en": "

    Given an undirected tree consisting of n vertices numbered from 1 to n. A frog starts jumping from vertex 1. In one second, the frog jumps from its current vertex to another unvisited vertex if they are directly connected. The frog can not jump back to a visited vertex. In case the frog can jump to several vertices, it jumps randomly to one of them with the same probability. Otherwise, when the frog can not jump to any unvisited vertex, it jumps forever on the same vertex.

    \n\n

    The edges of the undirected tree are given in the array edges, where edges[i] = [ai, bi] means that exists an edge connecting the vertices ai and bi.

    \n\n

    Return the probability that after t seconds the frog is on the vertex target.

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: n = 7, edges = [[1,2],[1,3],[1,7],[2,4],[2,6],[3,5]], t = 2, target = 4\nOutput: 0.16666666666666666 \nExplanation: The figure above shows the given graph. The frog starts at vertex 1, jumping with 1/3 probability to the vertex 2 after second 1 and then jumping with 1/2 probability to vertex 4 after second 2. Thus the probability for the frog is on the vertex 4 after 2 seconds is 1/3 * 1/2 = 1/6 = 0.16666666666666666. \n
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: n = 7, edges = [[1,2],[1,3],[1,7],[2,4],[2,6],[3,5]], t = 1, target = 7\nOutput: 0.3333333333333333\nExplanation: The figure above shows the given graph. The frog starts at vertex 1, jumping with 1/3 = 0.3333333333333333 probability to the vertex 7 after second 1. \n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 7, edges = [[1,2],[1,3],[1,7],[2,4],[2,6],[3,5]], t = 20, target = 6\nOutput: 0.16666666666666666\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 100
    • \n\t
    • edges.length == n - 1
    • \n\t
    • edges[i].length == 2
    • \n\t
    • 1 <= ai, bi <= n
    • \n\t
    • 1 <= t <= 50
    • \n\t
    • 1 <= target <= n
    • \n\t
    • Answers within 10-5 of the actual value will be accepted as correct.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u68f5\u7531 n \u4e2a\u9876\u70b9\u7ec4\u6210\u7684\u65e0\u5411\u6811\uff0c\u9876\u70b9\u7f16\u53f7\u4ece 1 \u5230 n\u3002\u9752\u86d9\u4ece \u9876\u70b9 1 \u5f00\u59cb\u8d77\u8df3\u3002\u89c4\u5219\u5982\u4e0b\uff1a

    \n\n
      \n\t
    • \u5728\u4e00\u79d2\u5185\uff0c\u9752\u86d9\u4ece\u5b83\u6240\u5728\u7684\u5f53\u524d\u9876\u70b9\u8df3\u5230\u53e6\u4e00\u4e2a \u672a\u8bbf\u95ee \u8fc7\u7684\u9876\u70b9\uff08\u5982\u679c\u5b83\u4eec\u76f4\u63a5\u76f8\u8fde\uff09\u3002
    • \n\t
    • \u9752\u86d9\u65e0\u6cd5\u8df3\u56de\u5df2\u7ecf\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\u3002
    • \n\t
    • \u5982\u679c\u9752\u86d9\u53ef\u4ee5\u8df3\u5230\u591a\u4e2a\u4e0d\u540c\u9876\u70b9\uff0c\u90a3\u4e48\u5b83\u8df3\u5230\u5176\u4e2d\u4efb\u610f\u4e00\u4e2a\u9876\u70b9\u4e0a\u7684\u673a\u7387\u90fd\u76f8\u540c\u3002
    • \n\t
    • \u5982\u679c\u9752\u86d9\u4e0d\u80fd\u8df3\u5230\u4efb\u4f55\u672a\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\u4e0a\uff0c\u90a3\u4e48\u5b83\u6bcf\u6b21\u8df3\u8dc3\u90fd\u4f1a\u505c\u7559\u5728\u539f\u5730\u3002
    • \n
    \n\n

    \u65e0\u5411\u6811\u7684\u8fb9\u7528\u6570\u7ec4 edges \u63cf\u8ff0\uff0c\u5176\u4e2d edges[i] = [fromi, toi] \u610f\u5473\u7740\u5b58\u5728\u4e00\u6761\u76f4\u63a5\u8fde\u901a fromi \u548c toi \u4e24\u4e2a\u9876\u70b9\u7684\u8fb9\u3002

    \n\n

    \u8fd4\u56de\u9752\u86d9\u5728 t \u79d2\u540e\u4f4d\u4e8e\u76ee\u6807\u9876\u70b9 target \u4e0a\u7684\u6982\u7387\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 7, edges = [[1,2],[1,3],[1,7],[2,4],[2,6],[3,5]], t = 2, target = 4\n\u8f93\u51fa\uff1a0.16666666666666666 \n\u89e3\u91ca\uff1a\u4e0a\u56fe\u663e\u793a\u4e86\u9752\u86d9\u7684\u8df3\u8dc3\u8def\u5f84\u3002\u9752\u86d9\u4ece\u9876\u70b9 1 \u8d77\u8df3\uff0c\u7b2c 1 \u79d2 \u6709 1/3 \u7684\u6982\u7387\u8df3\u5230\u9876\u70b9 2 \uff0c\u7136\u540e\u7b2c 2 \u79d2 \u6709 1/2 \u7684\u6982\u7387\u8df3\u5230\u9876\u70b9 4\uff0c\u56e0\u6b64\u9752\u86d9\u5728 2 \u79d2\u540e\u4f4d\u4e8e\u9876\u70b9 4 \u7684\u6982\u7387\u662f 1/3 * 1/2 = 1/6 = 0.16666666666666666 \u3002 \n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 7, edges = [[1,2],[1,3],[1,7],[2,4],[2,6],[3,5]], t = 1, target = 7\n\u8f93\u51fa\uff1a0.3333333333333333\n\u89e3\u91ca\uff1a\u4e0a\u56fe\u663e\u793a\u4e86\u9752\u86d9\u7684\u8df3\u8dc3\u8def\u5f84\u3002\u9752\u86d9\u4ece\u9876\u70b9 1 \u8d77\u8df3\uff0c\u6709 1/3 = 0.3333333333333333 \u7684\u6982\u7387\u80fd\u591f 1 \u79d2 \u540e\u8df3\u5230\u9876\u70b9 7 \u3002 \n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1an = 7, edges = [[1,2],[1,3],[1,7],[2,4],[2,6],[3,5]], t = 20, target = 6\n\u8f93\u51fa\uff1a0.16666666666666666\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 100
    • \n\t
    • edges.length == n-1
    • \n\t
    • edges[i].length == 2
    • \n\t
    • 1 <= edges[i][0], edges[i][1] <= n
    • \n\t
    • 1 <= t <= 50
    • \n\t
    • 1 <= target <= n
    • \n\t
    • \u4e0e\u51c6\u786e\u503c\u8bef\u5dee\u5728 10^-5 \u4e4b\u5185\u7684\u7ed3\u679c\u5c06\u88ab\u5224\u5b9a\u4e3a\u6b63\u786e\u3002
    • \n
    \n", "tags_en": ["Depth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n double frogPosition(int n, vector>& edges, int t, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double frogPosition(int n, int[][] edges, int t, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def frogPosition(self, n, edges, t, target):\n \"\"\"\n :type n: int\n :type edges: List[List[int]]\n :type t: int\n :type target: int\n :rtype: float\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def frogPosition(self, n: int, edges: List[List[int]], t: int, target: int) -> float:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\ndouble frogPosition(int n, int** edges, int edgesSize, int* edgesColSize, int t, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double FrogPosition(int n, int[][] edges, int t, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} edges\n * @param {number} t\n * @param {number} target\n * @return {number}\n */\nvar frogPosition = function(n, edges, t, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} edges\n# @param {Integer} t\n# @param {Integer} target\n# @return {Float}\ndef frog_position(n, edges, t, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func frogPosition(_ n: Int, _ edges: [[Int]], _ t: Int, _ target: Int) -> Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func frogPosition(n int, edges [][]int, t int, target int) float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def frogPosition(n: Int, edges: Array[Array[Int]], t: Int, target: Int): Double = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun frogPosition(n: Int, edges: Array, t: Int, target: Int): Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn frog_position(n: i32, edges: Vec>, t: i32, target: i32) -> f64 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $edges\n * @param Integer $t\n * @param Integer $target\n * @return Float\n */\n function frogPosition($n, $edges, $t, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function frogPosition(n: number, edges: number[][], t: number, target: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (frog-position n edges t target)\n (-> exact-integer? (listof (listof exact-integer?)) exact-integer? exact-integer? flonum?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1377](https://leetcode-cn.com/problems/frog-position-after-t-seconds)", "[T \u79d2\u540e\u9752\u86d9\u7684\u4f4d\u7f6e](/solution/1300-1399/1377.Frog%20Position%20After%20T%20Seconds/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[1377](https://leetcode.com/problems/frog-position-after-t-seconds)", "[Frog Position After T Seconds](/solution/1300-1399/1377.Frog%20Position%20After%20T%20Seconds/README_EN.md)", "`Depth-first Search`", "Hard", ""]}, {"question_id": "1492", "frontend_question_id": "1376", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/time-needed-to-inform-all-employees", "url_en": "https://leetcode.com/problems/time-needed-to-inform-all-employees", "relative_path_cn": "/solution/1300-1399/1376.Time%20Needed%20to%20Inform%20All%20Employees/README.md", "relative_path_en": "/solution/1300-1399/1376.Time%20Needed%20to%20Inform%20All%20Employees/README_EN.md", "title_cn": "\u901a\u77e5\u6240\u6709\u5458\u5de5\u6240\u9700\u7684\u65f6\u95f4", "title_en": "Time Needed to Inform All Employees", "question_title_slug": "time-needed-to-inform-all-employees", "content_en": "

    A company has n employees with a unique ID for each employee from 0 to n - 1. The head of the company is the one with headID.

    \n\n

    Each employee has one direct manager given in the manager array where manager[i] is the direct manager of the i-th employee, manager[headID] = -1. Also, it is guaranteed that the subordination relationships have a tree structure.

    \n\n

    The head of the company wants to inform all the company employees of an urgent piece of news. He will inform his direct subordinates, and they will inform their subordinates, and so on until all employees know about the urgent news.

    \n\n

    The i-th employee needs informTime[i] minutes to inform all of his direct subordinates (i.e., After informTime[i] minutes, all his direct subordinates can start spreading the news).

    \n\n

    Return the number of minutes needed to inform all the employees about the urgent news.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 1, headID = 0, manager = [-1], informTime = [0]\nOutput: 0\nExplanation: The head of the company is the only employee in the company.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: n = 6, headID = 2, manager = [2,2,-1,2,2,2], informTime = [0,0,1,0,0,0]\nOutput: 1\nExplanation: The head of the company with id = 2 is the direct manager of all the employees in the company and needs 1 minute to inform them all.\nThe tree structure of the employees in the company is shown.\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: n = 7, headID = 6, manager = [1,2,3,4,5,6,-1], informTime = [0,6,5,4,3,2,1]\nOutput: 21\nExplanation: The head has id = 6. He will inform employee with id = 5 in 1 minute.\nThe employee with id = 5 will inform the employee with id = 4 in 2 minutes.\nThe employee with id = 4 will inform the employee with id = 3 in 3 minutes.\nThe employee with id = 3 will inform the employee with id = 2 in 4 minutes.\nThe employee with id = 2 will inform the employee with id = 1 in 5 minutes.\nThe employee with id = 1 will inform the employee with id = 0 in 6 minutes.\nNeeded time = 1 + 2 + 3 + 4 + 5 + 6 = 21.\n
    \n\n

    Example 4:

    \n\n
    \nInput: n = 15, headID = 0, manager = [-1,0,0,1,1,2,2,3,3,4,4,5,5,6,6], informTime = [1,1,1,1,1,1,1,0,0,0,0,0,0,0,0]\nOutput: 3\nExplanation: The first minute the head will inform employees 1 and 2.\nThe second minute they will inform employees 3, 4, 5 and 6.\nThe third minute they will inform the rest of employees.\n
    \n\n

    Example 5:

    \n\n
    \nInput: n = 4, headID = 2, manager = [3,3,-1,2], informTime = [0,0,162,914]\nOutput: 1076\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 105
    • \n\t
    • 0 <= headID < n
    • \n\t
    • manager.length == n
    • \n\t
    • 0 <= manager[i] < n
    • \n\t
    • manager[headID] == -1
    • \n\t
    • informTime.length == n
    • \n\t
    • 0 <= informTime[i] <= 1000
    • \n\t
    • informTime[i] == 0 if employee i has no subordinates.
    • \n\t
    • It is guaranteed that all the employees can be informed.
    • \n
    \n", "content_cn": "

    \u516c\u53f8\u91cc\u6709 n \u540d\u5458\u5de5\uff0c\u6bcf\u4e2a\u5458\u5de5\u7684 ID \u90fd\u662f\u72ec\u4e00\u65e0\u4e8c\u7684\uff0c\u7f16\u53f7\u4ece 0 \u5230 n - 1\u3002\u516c\u53f8\u7684\u603b\u8d1f\u8d23\u4eba\u901a\u8fc7 headID \u8fdb\u884c\u6807\u8bc6\u3002

    \n\n

    \u5728 manager \u6570\u7ec4\u4e2d\uff0c\u6bcf\u4e2a\u5458\u5de5\u90fd\u6709\u4e00\u4e2a\u76f4\u5c5e\u8d1f\u8d23\u4eba\uff0c\u5176\u4e2d manager[i] \u662f\u7b2c i \u540d\u5458\u5de5\u7684\u76f4\u5c5e\u8d1f\u8d23\u4eba\u3002\u5bf9\u4e8e\u603b\u8d1f\u8d23\u4eba\uff0cmanager[headID] = -1\u3002\u9898\u76ee\u4fdd\u8bc1\u4ece\u5c5e\u5173\u7cfb\u53ef\u4ee5\u7528\u6811\u7ed3\u6784\u663e\u793a\u3002

    \n\n

    \u516c\u53f8\u603b\u8d1f\u8d23\u4eba\u60f3\u8981\u5411\u516c\u53f8\u6240\u6709\u5458\u5de5\u901a\u544a\u4e00\u6761\u7d27\u6025\u6d88\u606f\u3002\u4ed6\u5c06\u4f1a\u9996\u5148\u901a\u77e5\u4ed6\u7684\u76f4\u5c5e\u4e0b\u5c5e\u4eec\uff0c\u7136\u540e\u7531\u8fd9\u4e9b\u4e0b\u5c5e\u901a\u77e5\u4ed6\u4eec\u7684\u4e0b\u5c5e\uff0c\u76f4\u5230\u6240\u6709\u7684\u5458\u5de5\u90fd\u5f97\u77e5\u8fd9\u6761\u7d27\u6025\u6d88\u606f\u3002

    \n\n

    \u7b2c i \u540d\u5458\u5de5\u9700\u8981 informTime[i] \u5206\u949f\u6765\u901a\u77e5\u5b83\u7684\u6240\u6709\u76f4\u5c5e\u4e0b\u5c5e\uff08\u4e5f\u5c31\u662f\u8bf4\u5728 informTime[i] \u5206\u949f\u540e\uff0c\u4ed6\u7684\u6240\u6709\u76f4\u5c5e\u4e0b\u5c5e\u90fd\u53ef\u4ee5\u5f00\u59cb\u4f20\u64ad\u8fd9\u4e00\u6d88\u606f\uff09\u3002

    \n\n

    \u8fd4\u56de\u901a\u77e5\u6240\u6709\u5458\u5de5\u8fd9\u4e00\u7d27\u6025\u6d88\u606f\u6240\u9700\u8981\u7684 \u5206\u949f\u6570 \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1an = 1, headID = 0, manager = [-1], informTime = [0]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u516c\u53f8\u603b\u8d1f\u8d23\u4eba\u662f\u8be5\u516c\u53f8\u7684\u552f\u4e00\u4e00\u540d\u5458\u5de5\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 6, headID = 2, manager = [2,2,-1,2,2,2], informTime = [0,0,1,0,0,0]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1aid = 2 \u7684\u5458\u5de5\u662f\u516c\u53f8\u7684\u603b\u8d1f\u8d23\u4eba\uff0c\u4e5f\u662f\u5176\u4ed6\u6240\u6709\u5458\u5de5\u7684\u76f4\u5c5e\u8d1f\u8d23\u4eba\uff0c\u4ed6\u9700\u8981 1 \u5206\u949f\u6765\u901a\u77e5\u6240\u6709\u5458\u5de5\u3002\n\u4e0a\u56fe\u663e\u793a\u4e86\u516c\u53f8\u5458\u5de5\u7684\u6811\u7ed3\u6784\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 7, headID = 6, manager = [1,2,3,4,5,6,-1], informTime = [0,6,5,4,3,2,1]\n\u8f93\u51fa\uff1a21\n\u89e3\u91ca\uff1a\u603b\u8d1f\u8d23\u4eba id = 6\u3002\u4ed6\u5c06\u5728 1 \u5206\u949f\u5185\u901a\u77e5 id = 5 \u7684\u5458\u5de5\u3002\nid = 5 \u7684\u5458\u5de5\u5c06\u5728 2 \u5206\u949f\u5185\u901a\u77e5 id = 4 \u7684\u5458\u5de5\u3002\nid = 4 \u7684\u5458\u5de5\u5c06\u5728 3 \u5206\u949f\u5185\u901a\u77e5 id = 3 \u7684\u5458\u5de5\u3002\nid = 3 \u7684\u5458\u5de5\u5c06\u5728 4 \u5206\u949f\u5185\u901a\u77e5 id = 2 \u7684\u5458\u5de5\u3002\nid = 2 \u7684\u5458\u5de5\u5c06\u5728 5 \u5206\u949f\u5185\u901a\u77e5 id = 1 \u7684\u5458\u5de5\u3002\nid = 1 \u7684\u5458\u5de5\u5c06\u5728 6 \u5206\u949f\u5185\u901a\u77e5 id = 0 \u7684\u5458\u5de5\u3002\n\u6240\u9700\u65f6\u95f4 = 1 + 2 + 3 + 4 + 5 + 6 = 21 \u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1an = 15, headID = 0, manager = [-1,0,0,1,1,2,2,3,3,4,4,5,5,6,6], informTime = [1,1,1,1,1,1,1,0,0,0,0,0,0,0,0]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u7b2c\u4e00\u5206\u949f\u603b\u8d1f\u8d23\u4eba\u901a\u77e5\u5458\u5de5 1 \u548c 2 \u3002\n\u7b2c\u4e8c\u5206\u949f\u4ed6\u4eec\u5c06\u4f1a\u901a\u77e5\u5458\u5de5 3, 4, 5 \u548c 6 \u3002\n\u7b2c\u4e09\u5206\u949f\u4ed6\u4eec\u5c06\u4f1a\u901a\u77e5\u5269\u4e0b\u7684\u5458\u5de5\u3002\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1an = 4, headID = 2, manager = [3,3,-1,2], informTime = [0,0,162,914]\n\u8f93\u51fa\uff1a1076\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 10^5
    • \n\t
    • 0 <= headID < n
    • \n\t
    • manager.length == n
    • \n\t
    • 0 <= manager[i] < n
    • \n\t
    • manager[headID] == -1
    • \n\t
    • informTime.length == n
    • \n\t
    • 0 <= informTime[i] <= 1000
    • \n\t
    • \u5982\u679c\u5458\u5de5 i \u6ca1\u6709\u4e0b\u5c5e\uff0cinformTime[i] == 0 \u3002
    • \n\t
    • \u9898\u76ee \u4fdd\u8bc1 \u6240\u6709\u5458\u5de5\u90fd\u53ef\u4ee5\u6536\u5230\u901a\u77e5\u3002
    • \n
    \n", "tags_en": ["Depth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numOfMinutes(int n, int headID, vector& manager, vector& informTime) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numOfMinutes(int n, int headID, int[] manager, int[] informTime) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numOfMinutes(self, n, headID, manager, informTime):\n \"\"\"\n :type n: int\n :type headID: int\n :type manager: List[int]\n :type informTime: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numOfMinutes(self, n: int, headID: int, manager: List[int], informTime: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numOfMinutes(int n, int headID, int* manager, int managerSize, int* informTime, int informTimeSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumOfMinutes(int n, int headID, int[] manager, int[] informTime) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} headID\n * @param {number[]} manager\n * @param {number[]} informTime\n * @return {number}\n */\nvar numOfMinutes = function(n, headID, manager, informTime) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} head_id\n# @param {Integer[]} manager\n# @param {Integer[]} inform_time\n# @return {Integer}\ndef num_of_minutes(n, head_id, manager, inform_time)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numOfMinutes(_ n: Int, _ headID: Int, _ manager: [Int], _ informTime: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numOfMinutes(n int, headID int, manager []int, informTime []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numOfMinutes(n: Int, headID: Int, manager: Array[Int], informTime: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numOfMinutes(n: Int, headID: Int, manager: IntArray, informTime: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_of_minutes(n: i32, head_id: i32, manager: Vec, inform_time: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $headID\n * @param Integer[] $manager\n * @param Integer[] $informTime\n * @return Integer\n */\n function numOfMinutes($n, $headID, $manager, $informTime) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numOfMinutes(n: number, headID: number, manager: number[], informTime: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-of-minutes n headID manager informTime)\n (-> exact-integer? exact-integer? (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1376](https://leetcode-cn.com/problems/time-needed-to-inform-all-employees)", "[\u901a\u77e5\u6240\u6709\u5458\u5de5\u6240\u9700\u7684\u65f6\u95f4](/solution/1300-1399/1376.Time%20Needed%20to%20Inform%20All%20Employees/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1376](https://leetcode.com/problems/time-needed-to-inform-all-employees)", "[Time Needed to Inform All Employees](/solution/1300-1399/1376.Time%20Needed%20to%20Inform%20All%20Employees/README_EN.md)", "`Depth-first Search`", "Medium", ""]}, {"question_id": "1491", "frontend_question_id": "1375", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/bulb-switcher-iii", "url_en": "https://leetcode.com/problems/bulb-switcher-iii", "relative_path_cn": "/solution/1300-1399/1375.Bulb%20Switcher%20III/README.md", "relative_path_en": "/solution/1300-1399/1375.Bulb%20Switcher%20III/README_EN.md", "title_cn": "\u706f\u6ce1\u5f00\u5173 III", "title_en": "Bulb Switcher III", "question_title_slug": "bulb-switcher-iii", "content_en": "

    There is a room with n bulbs, numbered from 1 to n, arranged in a row from left to right. Initially, all the bulbs are turned off.

    \n\n

    At moment k (for k from 0 to n - 1), we turn on the light[k] bulb. A bulb change color to blue only if it is on and all the previous bulbs (to the left) are turned on too.

    \n\n

    Return the number of moments in which all turned on bulbs are blue.

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: light = [2,1,3,5,4]\nOutput: 3\nExplanation: All bulbs turned on, are blue at the moment 1, 2 and 4.\n
    \n\n

    Example 2:

    \n\n
    \nInput: light = [3,2,4,1,5]\nOutput: 2\nExplanation: All bulbs turned on, are blue at the moment 3, and 4 (index-0).\n
    \n\n

    Example 3:

    \n\n
    \nInput: light = [4,1,2,3]\nOutput: 1\nExplanation: All bulbs turned on, are blue at the moment 3 (index-0).\nBulb 4th changes to blue at the moment 3.\n
    \n\n

    Example 4:

    \n\n
    \nInput: light = [2,1,4,3,6,5]\nOutput: 3\n
    \n\n

    Example 5:

    \n\n
    \nInput: light = [1,2,3,4,5,6]\nOutput: 6\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == light.length
    • \n\t
    • 1 <= n <= 5 * 10^4
    • \n\t
    • light is a permutation of  [1, 2, ..., n]
    • \n
    \n", "content_cn": "

    \u623f\u95f4\u4e2d\u6709 n \u679a\u706f\u6ce1\uff0c\u7f16\u53f7\u4ece 1 \u5230 n\uff0c\u81ea\u5de6\u5411\u53f3\u6392\u6210\u4e00\u6392\u3002\u6700\u521d\uff0c\u6240\u6709\u7684\u706f\u90fd\u662f\u5173\u7740\u7684\u3002

    \n\n

    \u5728 k  \u65f6\u523b\uff08 k \u7684\u53d6\u503c\u8303\u56f4\u662f 0 \u5230 n - 1\uff09\uff0c\u6211\u4eec\u6253\u5f00 light[k] \u8fd9\u4e2a\u706f\u3002

    \n\n

    \u706f\u7684\u989c\u8272\u8981\u60f3 \u53d8\u6210\u84dd\u8272 \u5c31\u5fc5\u987b\u540c\u65f6\u6ee1\u8db3\u4e0b\u9762\u4e24\u4e2a\u6761\u4ef6\uff1a

    \n\n
      \n\t
    • \u706f\u5904\u4e8e\u6253\u5f00\u72b6\u6001\u3002
    • \n\t
    • \u6392\u5728\u5b83\u4e4b\u524d\uff08\u5de6\u4fa7\uff09\u7684\u6240\u6709\u706f\u4e5f\u90fd\u5904\u4e8e\u6253\u5f00\u72b6\u6001\u3002
    • \n
    \n\n

    \u8bf7\u8fd4\u56de\u80fd\u591f\u8ba9 \u6240\u6709\u5f00\u7740\u7684 \u706f\u90fd \u53d8\u6210\u84dd\u8272 \u7684\u65f6\u523b \u6570\u76ee \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1alight = [2,1,3,5,4]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6240\u6709\u5f00\u7740\u7684\u706f\u90fd\u53d8\u84dd\u7684\u65f6\u523b\u5206\u522b\u662f 1\uff0c2 \u548c 4 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1alight = [3,2,4,1,5]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6240\u6709\u5f00\u7740\u7684\u706f\u90fd\u53d8\u84dd\u7684\u65f6\u523b\u5206\u522b\u662f 3 \u548c 4\uff08index-0\uff09\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1alight = [4,1,2,3]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u6240\u6709\u5f00\u7740\u7684\u706f\u90fd\u53d8\u84dd\u7684\u65f6\u523b\u662f 3\uff08index-0\uff09\u3002\n\u7b2c 4 \u4e2a\u706f\u5728\u65f6\u523b 3 \u53d8\u84dd\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1alight = [2,1,4,3,6,5]\n\u8f93\u51fa\uff1a3\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1alight = [1,2,3,4,5,6]\n\u8f93\u51fa\uff1a6\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == light.length
    • \n\t
    • 1 <= n <= 5 * 10^4
    • \n\t
    • light \u662f [1, 2, ..., n] \u7684\u4e00\u4e2a\u6392\u5217\u3002
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numTimesAllBlue(vector& light) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numTimesAllBlue(int[] light) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numTimesAllBlue(self, light):\n \"\"\"\n :type light: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numTimesAllBlue(self, light: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numTimesAllBlue(int* light, int lightSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumTimesAllBlue(int[] light) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} light\n * @return {number}\n */\nvar numTimesAllBlue = function(light) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} light\n# @return {Integer}\ndef num_times_all_blue(light)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numTimesAllBlue(_ light: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numTimesAllBlue(light []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numTimesAllBlue(light: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numTimesAllBlue(light: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_times_all_blue(light: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $light\n * @return Integer\n */\n function numTimesAllBlue($light) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numTimesAllBlue(light: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-times-all-blue light)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1375](https://leetcode-cn.com/problems/bulb-switcher-iii)", "[\u706f\u6ce1\u5f00\u5173 III](/solution/1300-1399/1375.Bulb%20Switcher%20III/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1375](https://leetcode.com/problems/bulb-switcher-iii)", "[Bulb Switcher III](/solution/1300-1399/1375.Bulb%20Switcher%20III/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "1490", "frontend_question_id": "1374", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/generate-a-string-with-characters-that-have-odd-counts", "url_en": "https://leetcode.com/problems/generate-a-string-with-characters-that-have-odd-counts", "relative_path_cn": "/solution/1300-1399/1374.Generate%20a%20String%20With%20Characters%20That%20Have%20Odd%20Counts/README.md", "relative_path_en": "/solution/1300-1399/1374.Generate%20a%20String%20With%20Characters%20That%20Have%20Odd%20Counts/README_EN.md", "title_cn": "\u751f\u6210\u6bcf\u79cd\u5b57\u7b26\u90fd\u662f\u5947\u6570\u4e2a\u7684\u5b57\u7b26\u4e32", "title_en": "Generate a String With Characters That Have Odd Counts", "question_title_slug": "generate-a-string-with-characters-that-have-odd-counts", "content_en": "

    Given an integer n, return a string with n characters such that each character in such string occurs an odd number of times.

    \n\n

    The returned string must contain only lowercase English letters. If there are multiples valid strings, return any of them.  

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 4\nOutput: "pppz"\nExplanation: "pppz" is a valid string since the character 'p' occurs three times and the character 'z' occurs once. Note that there are many other valid strings such as "ohhh" and "love".\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 2\nOutput: "xy"\nExplanation: "xy" is a valid string since the characters 'x' and 'y' occur once. Note that there are many other valid strings such as "ag" and "ur".\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 7\nOutput: "holasss"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 500
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n\uff0c\u8bf7\u4f60\u8fd4\u56de\u4e00\u4e2a\u542b n \u4e2a\u5b57\u7b26\u7684\u5b57\u7b26\u4e32\uff0c\u5176\u4e2d\u6bcf\u79cd\u5b57\u7b26\u5728\u8be5\u5b57\u7b26\u4e32\u4e2d\u90fd\u6070\u597d\u51fa\u73b0 \u5947\u6570\u6b21 \u3002

    \n\n

    \u8fd4\u56de\u7684\u5b57\u7b26\u4e32\u5fc5\u987b\u53ea\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002\u5982\u679c\u5b58\u5728\u591a\u4e2a\u6ee1\u8db3\u9898\u76ee\u8981\u6c42\u7684\u5b57\u7b26\u4e32\uff0c\u5219\u8fd4\u56de\u5176\u4e2d\u4efb\u610f\u4e00\u4e2a\u5373\u53ef\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1an = 4\n\u8f93\u51fa\uff1a"pppz"\n\u89e3\u91ca\uff1a"pppz" \u662f\u4e00\u4e2a\u6ee1\u8db3\u9898\u76ee\u8981\u6c42\u7684\u5b57\u7b26\u4e32\uff0c\u56e0\u4e3a 'p' \u51fa\u73b0 3 \u6b21\uff0c\u4e14 'z' \u51fa\u73b0 1 \u6b21\u3002\u5f53\u7136\uff0c\u8fd8\u6709\u5f88\u591a\u5176\u4ed6\u5b57\u7b26\u4e32\u4e5f\u6ee1\u8db3\u9898\u76ee\u8981\u6c42\uff0c\u6bd4\u5982\uff1a"ohhh" \u548c "love"\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1an = 2\n\u8f93\u51fa\uff1a"xy"\n\u89e3\u91ca\uff1a"xy" \u662f\u4e00\u4e2a\u6ee1\u8db3\u9898\u76ee\u8981\u6c42\u7684\u5b57\u7b26\u4e32\uff0c\u56e0\u4e3a 'x' \u548c 'y' \u5404\u51fa\u73b0 1 \u6b21\u3002\u5f53\u7136\uff0c\u8fd8\u6709\u5f88\u591a\u5176\u4ed6\u5b57\u7b26\u4e32\u4e5f\u6ee1\u8db3\u9898\u76ee\u8981\u6c42\uff0c\u6bd4\u5982\uff1a"ag" \u548c "ur"\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1an = 7\n\u8f93\u51fa\uff1a"holasss"\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 500
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string generateTheString(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String generateTheString(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def generateTheString(self, n):\n \"\"\"\n :type n: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def generateTheString(self, n: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * generateTheString(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string GenerateTheString(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {string}\n */\nvar generateTheString = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {String}\ndef generate_the_string(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func generateTheString(_ n: Int) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func generateTheString(n int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def generateTheString(n: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun generateTheString(n: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn generate_the_string(n: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return String\n */\n function generateTheString($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function generateTheString(n: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (generate-the-string n)\n (-> exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1374](https://leetcode-cn.com/problems/generate-a-string-with-characters-that-have-odd-counts)", "[\u751f\u6210\u6bcf\u79cd\u5b57\u7b26\u90fd\u662f\u5947\u6570\u4e2a\u7684\u5b57\u7b26\u4e32](/solution/1300-1399/1374.Generate%20a%20String%20With%20Characters%20That%20Have%20Odd%20Counts/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1374](https://leetcode.com/problems/generate-a-string-with-characters-that-have-odd-counts)", "[Generate a String With Characters That Have Odd Counts](/solution/1300-1399/1374.Generate%20a%20String%20With%20Characters%20That%20Have%20Odd%20Counts/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1489", "frontend_question_id": "1388", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/pizza-with-3n-slices", "url_en": "https://leetcode.com/problems/pizza-with-3n-slices", "relative_path_cn": "/solution/1300-1399/1388.Pizza%20With%203n%20Slices/README.md", "relative_path_en": "/solution/1300-1399/1388.Pizza%20With%203n%20Slices/README_EN.md", "title_cn": "3n \u5757\u62ab\u8428", "title_en": "Pizza With 3n Slices", "question_title_slug": "pizza-with-3n-slices", "content_en": "

    There is a pizza with 3n slices of varying size, you and your friends will take slices of pizza as follows:

    \n\n
      \n\t
    • You will pick any pizza slice.
    • \n\t
    • Your friend Alice will pick next slice in anti clockwise direction of your pick. 
    • \n\t
    • Your friend Bob will pick next slice in clockwise direction of your pick.
    • \n\t
    • Repeat until there are no more slices of pizzas.
    • \n
    \n\n

    Sizes of Pizza slices is represented by circular array slices in clockwise direction.

    \n\n

    Return the maximum possible sum of slice sizes which you can have.

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: slices = [1,2,3,4,5,6]\nOutput: 10\nExplanation: Pick pizza slice of size 4, Alice and Bob will pick slices with size 3 and 5 respectively. Then Pick slices with size 6, finally Alice and Bob will pick slice of size 2 and 1 respectively. Total = 4 + 6.\n
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: slices = [8,9,8,6,1,1]\nOutput: 16\nOutput: Pick pizza slice of size 8 in each turn. If you pick slice with size 9 your partners will pick slices of size 8.\n
    \n\n

    Example 3:

    \n\n
    \nInput: slices = [4,1,2,5,8,3,1,9,7]\nOutput: 21\n
    \n\n

    Example 4:

    \n\n
    \nInput: slices = [3,1,2]\nOutput: 3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= slices.length <= 500
    • \n\t
    • slices.length % 3 == 0
    • \n\t
    • 1 <= slices[i] <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u62ab\u8428\uff0c\u5b83\u7531 3n \u5757\u4e0d\u540c\u5927\u5c0f\u7684\u90e8\u5206\u7ec4\u6210\uff0c\u73b0\u5728\u4f60\u548c\u4f60\u7684\u670b\u53cb\u4eec\u9700\u8981\u6309\u7167\u5982\u4e0b\u89c4\u5219\u6765\u5206\u62ab\u8428\uff1a

    \n\n
      \n\t
    • \u4f60\u6311\u9009 \u4efb\u610f \u4e00\u5757\u62ab\u8428\u3002
    • \n\t
    • Alice \u5c06\u4f1a\u6311\u9009\u4f60\u6240\u9009\u62e9\u7684\u62ab\u8428\u9006\u65f6\u9488\u65b9\u5411\u7684\u4e0b\u4e00\u5757\u62ab\u8428\u3002
    • \n\t
    • Bob \u5c06\u4f1a\u6311\u9009\u4f60\u6240\u9009\u62e9\u7684\u62ab\u8428\u987a\u65f6\u9488\u65b9\u5411\u7684\u4e0b\u4e00\u5757\u62ab\u8428\u3002
    • \n\t
    • \u91cd\u590d\u4e0a\u8ff0\u8fc7\u7a0b\u76f4\u5230\u6ca1\u6709\u62ab\u8428\u5269\u4e0b\u3002
    • \n
    \n\n

    \u6bcf\u4e00\u5757\u62ab\u8428\u7684\u5927\u5c0f\u6309\u987a\u65f6\u9488\u65b9\u5411\u7531\u5faa\u73af\u6570\u7ec4 slices \u8868\u793a\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u4f60\u53ef\u4ee5\u83b7\u5f97\u7684\u62ab\u8428\u5927\u5c0f\u603b\u548c\u7684\u6700\u5927\u503c\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1aslices = [1,2,3,4,5,6]\n\u8f93\u51fa\uff1a10\n\u89e3\u91ca\uff1a\u9009\u62e9\u5927\u5c0f\u4e3a 4 \u7684\u62ab\u8428\uff0cAlice \u548c Bob \u5206\u522b\u6311\u9009\u5927\u5c0f\u4e3a 3 \u548c 5 \u7684\u62ab\u8428\u3002\u7136\u540e\u4f60\u9009\u62e9\u5927\u5c0f\u4e3a 6 \u7684\u62ab\u8428\uff0cAlice \u548c Bob \u5206\u522b\u6311\u9009\u5927\u5c0f\u4e3a 2 \u548c 1 \u7684\u62ab\u8428\u3002\u4f60\u83b7\u5f97\u7684\u62ab\u8428\u603b\u5927\u5c0f\u4e3a 4 + 6 = 10 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1aslices = [8,9,8,6,1,1]\n\u8f93\u51fa\uff1a16\n\u89e3\u91ca\uff1a\u4e24\u8f6e\u90fd\u9009\u5927\u5c0f\u4e3a 8 \u7684\u62ab\u8428\u3002\u5982\u679c\u4f60\u9009\u62e9\u5927\u5c0f\u4e3a 9 \u7684\u62ab\u8428\uff0c\u4f60\u7684\u670b\u53cb\u4eec\u5c31\u4f1a\u9009\u62e9\u5927\u5c0f\u4e3a 8 \u7684\u62ab\u8428\uff0c\u8fd9\u79cd\u60c5\u51b5\u4e0b\u4f60\u7684\u603b\u548c\u4e0d\u662f\u6700\u5927\u7684\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aslices = [4,1,2,5,8,3,1,9,7]\n\u8f93\u51fa\uff1a21\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1aslices = [3,1,2]\n\u8f93\u51fa\uff1a3\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= slices.length <= 500
    • \n\t
    • slices.length % 3 == 0
    • \n\t
    • 1 <= slices[i] <= 1000
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxSizeSlices(vector& slices) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxSizeSlices(int[] slices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxSizeSlices(self, slices):\n \"\"\"\n :type slices: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxSizeSlices(self, slices: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxSizeSlices(int* slices, int slicesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxSizeSlices(int[] slices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} slices\n * @return {number}\n */\nvar maxSizeSlices = function(slices) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} slices\n# @return {Integer}\ndef max_size_slices(slices)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxSizeSlices(_ slices: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxSizeSlices(slices []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxSizeSlices(slices: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxSizeSlices(slices: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_size_slices(slices: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $slices\n * @return Integer\n */\n function maxSizeSlices($slices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxSizeSlices(slices: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-size-slices slices)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1388](https://leetcode-cn.com/problems/pizza-with-3n-slices)", "[3n \u5757\u62ab\u8428](/solution/1300-1399/1388.Pizza%20With%203n%20Slices/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1388](https://leetcode.com/problems/pizza-with-3n-slices)", "[Pizza With 3n Slices](/solution/1300-1399/1388.Pizza%20With%203n%20Slices/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1488", "frontend_question_id": "1387", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sort-integers-by-the-power-value", "url_en": "https://leetcode.com/problems/sort-integers-by-the-power-value", "relative_path_cn": "/solution/1300-1399/1387.Sort%20Integers%20by%20The%20Power%20Value/README.md", "relative_path_en": "/solution/1300-1399/1387.Sort%20Integers%20by%20The%20Power%20Value/README_EN.md", "title_cn": "\u5c06\u6574\u6570\u6309\u6743\u91cd\u6392\u5e8f", "title_en": "Sort Integers by The Power Value", "question_title_slug": "sort-integers-by-the-power-value", "content_en": "

    The power of an integer x is defined as the number of steps needed to transform x into 1 using the following steps:

    \r\n\r\n
      \r\n\t
    • if x is even then x = x / 2
    • \r\n\t
    • if x is odd then x = 3 * x + 1
    • \r\n
    \r\n\r\n

    For example, the power of x = 3 is 7 because 3 needs 7 steps to become 1 (3 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1).

    \r\n\r\n

    Given three integers lo, hi and k. The task is to sort all integers in the interval [lo, hi] by the power value in ascending order, if two or more integers have the same power value sort them by ascending order.

    \r\n\r\n

    Return the k-th integer in the range [lo, hi] sorted by the power value.

    \r\n\r\n

    Notice that for any integer x (lo <= x <= hi) it is guaranteed that x will transform into 1 using these steps and that the power of x is will fit in 32 bit signed integer.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: lo = 12, hi = 15, k = 2\r\nOutput: 13\r\nExplanation: The power of 12 is 9 (12 --> 6 --> 3 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1)\r\nThe power of 13 is 9\r\nThe power of 14 is 17\r\nThe power of 15 is 17\r\nThe interval sorted by the power value [12,13,14,15]. For k = 2 answer is the second element which is 13.\r\nNotice that 12 and 13 have the same power value and we sorted them in ascending order. Same for 14 and 15.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: lo = 1, hi = 1, k = 1\r\nOutput: 1\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: lo = 7, hi = 11, k = 4\r\nOutput: 7\r\nExplanation: The power array corresponding to the interval [7, 8, 9, 10, 11] is [16, 3, 19, 6, 14].\r\nThe interval sorted by power is [8, 10, 11, 7, 9].\r\nThe fourth number in the sorted array is 7.\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: lo = 10, hi = 20, k = 5\r\nOutput: 13\r\n
    \r\n\r\n

    Example 5:

    \r\n\r\n
    \r\nInput: lo = 1, hi = 1000, k = 777\r\nOutput: 570\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= lo <= hi <= 1000
    • \r\n\t
    • 1 <= k <= hi - lo + 1
    • \r\n
    ", "content_cn": "

    \u6211\u4eec\u5c06\u6574\u6570 x \u7684 \u6743\u91cd \u5b9a\u4e49\u4e3a\u6309\u7167\u4e0b\u8ff0\u89c4\u5219\u5c06 x \u53d8\u6210 1 \u6240\u9700\u8981\u7684\u6b65\u6570\uff1a

    \n\n
      \n\t
    • \u5982\u679c x \u662f\u5076\u6570\uff0c\u90a3\u4e48 x = x / 2
    • \n\t
    • \u5982\u679c x \u662f\u5947\u6570\uff0c\u90a3\u4e48 x = 3 * x + 1
    • \n
    \n\n

    \u6bd4\u65b9\u8bf4\uff0cx=3 \u7684\u6743\u91cd\u4e3a 7 \u3002\u56e0\u4e3a 3 \u9700\u8981 7 \u6b65\u53d8\u6210 1 \uff083 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1\uff09\u3002

    \n\n

    \u7ed9\u4f60\u4e09\u4e2a\u6574\u6570 lo\uff0c hi \u548c k \u3002\u4f60\u7684\u4efb\u52a1\u662f\u5c06\u533a\u95f4 [lo, hi] \u4e4b\u95f4\u7684\u6574\u6570\u6309\u7167\u5b83\u4eec\u7684\u6743\u91cd \u5347\u5e8f\u6392\u5e8f \uff0c\u5982\u679c\u5927\u4e8e\u7b49\u4e8e 2 \u4e2a\u6574\u6570\u6709 \u76f8\u540c \u7684\u6743\u91cd\uff0c\u90a3\u4e48\u6309\u7167\u6570\u5b57\u81ea\u8eab\u7684\u6570\u503c \u5347\u5e8f\u6392\u5e8f \u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u533a\u95f4 [lo, hi] \u4e4b\u95f4\u7684\u6574\u6570\u6309\u6743\u91cd\u6392\u5e8f\u540e\u7684\u7b2c k \u4e2a\u6570\u3002

    \n\n

    \u6ce8\u610f\uff0c\u9898\u76ee\u4fdd\u8bc1\u5bf9\u4e8e\u4efb\u610f\u6574\u6570 x \uff08lo <= x <= hi\uff09 \uff0c\u5b83\u53d8\u6210 1 \u6240\u9700\u8981\u7684\u6b65\u6570\u662f\u4e00\u4e2a 32 \u4f4d\u6709\u7b26\u53f7\u6574\u6570\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1alo = 12, hi = 15, k = 2\n\u8f93\u51fa\uff1a13\n\u89e3\u91ca\uff1a12 \u7684\u6743\u91cd\u4e3a 9\uff0812 --> 6 --> 3 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1\uff09\n13 \u7684\u6743\u91cd\u4e3a 9\n14 \u7684\u6743\u91cd\u4e3a 17\n15 \u7684\u6743\u91cd\u4e3a 17\n\u533a\u95f4\u5185\u7684\u6570\u6309\u6743\u91cd\u6392\u5e8f\u4ee5\u540e\u7684\u7ed3\u679c\u4e3a [12,13,14,15] \u3002\u5bf9\u4e8e k = 2 \uff0c\u7b54\u6848\u662f\u7b2c\u4e8c\u4e2a\u6574\u6570\u4e5f\u5c31\u662f 13 \u3002\n\u6ce8\u610f\uff0c12 \u548c 13 \u6709\u76f8\u540c\u7684\u6743\u91cd\uff0c\u6240\u4ee5\u6211\u4eec\u6309\u7167\u5b83\u4eec\u672c\u8eab\u5347\u5e8f\u6392\u5e8f\u300214 \u548c 15 \u540c\u7406\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1alo = 1, hi = 1, k = 1\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1alo = 7, hi = 11, k = 4\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\u533a\u95f4\u5185\u6574\u6570 [7, 8, 9, 10, 11] \u5bf9\u5e94\u7684\u6743\u91cd\u4e3a [16, 3, 19, 6, 14] \u3002\n\u6309\u6743\u91cd\u6392\u5e8f\u540e\u5f97\u5230\u7684\u7ed3\u679c\u4e3a [8, 10, 11, 7, 9] \u3002\n\u6392\u5e8f\u540e\u6570\u7ec4\u4e2d\u7b2c 4 \u4e2a\u6570\u5b57\u4e3a 7 \u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1alo = 10, hi = 20, k = 5\n\u8f93\u51fa\uff1a13\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1alo = 1, hi = 1000, k = 777\n\u8f93\u51fa\uff1a570\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= lo <= hi <= 1000
    • \n\t
    • 1 <= k <= hi - lo + 1
    • \n
    \n", "tags_en": ["Sort", "Graph"], "tags_cn": ["\u6392\u5e8f", "\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int getKth(int lo, int hi, int k) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int getKth(int lo, int hi, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getKth(self, lo, hi, k):\n \"\"\"\n :type lo: int\n :type hi: int\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getKth(self, lo: int, hi: int, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint getKth(int lo, int hi, int k){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int GetKth(int lo, int hi, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} lo\n * @param {number} hi\n * @param {number} k\n * @return {number}\n */\nvar getKth = function(lo, hi, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} lo\n# @param {Integer} hi\n# @param {Integer} k\n# @return {Integer}\ndef get_kth(lo, hi, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getKth(_ lo: Int, _ hi: Int, _ k: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getKth(lo int, hi int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getKth(lo: Int, hi: Int, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getKth(lo: Int, hi: Int, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_kth(lo: i32, hi: i32, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $lo\n * @param Integer $hi\n * @param Integer $k\n * @return Integer\n */\n function getKth($lo, $hi, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getKth(lo: number, hi: number, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-kth lo hi k)\n (-> exact-integer? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1387](https://leetcode-cn.com/problems/sort-integers-by-the-power-value)", "[\u5c06\u6574\u6570\u6309\u6743\u91cd\u6392\u5e8f](/solution/1300-1399/1387.Sort%20Integers%20by%20The%20Power%20Value/README.md)", "`\u6392\u5e8f`,`\u56fe`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1387](https://leetcode.com/problems/sort-integers-by-the-power-value)", "[Sort Integers by The Power Value](/solution/1300-1399/1387.Sort%20Integers%20by%20The%20Power%20Value/README_EN.md)", "`Sort`,`Graph`", "Medium", ""]}, {"question_id": "1487", "frontend_question_id": "1386", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/cinema-seat-allocation", "url_en": "https://leetcode.com/problems/cinema-seat-allocation", "relative_path_cn": "/solution/1300-1399/1386.Cinema%20Seat%20Allocation/README.md", "relative_path_en": "/solution/1300-1399/1386.Cinema%20Seat%20Allocation/README_EN.md", "title_cn": "\u5b89\u6392\u7535\u5f71\u9662\u5ea7\u4f4d", "title_en": "Cinema Seat Allocation", "question_title_slug": "cinema-seat-allocation", "content_en": "

    \"\"

    \n\n

    A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.

    \n\n

    Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already reserved.

    \n\n

    Return the maximum number of four-person groups you can assign on the cinema seats. A four-person group occupies four adjacent seats in one single row. Seats across an aisle (such as [3,3] and [3,4]) are not considered to be adjacent, but there is an exceptional case on which an aisle split a four-person group, in that case, the aisle split a four-person group in the middle, which means to have two people on each side.

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: n = 3, reservedSeats = [[1,2],[1,3],[1,8],[2,6],[3,1],[3,10]]\nOutput: 4\nExplanation: The figure above shows the optimal allocation for four groups, where seats mark with blue are already reserved and contiguous seats mark with orange are for one group.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 2, reservedSeats = [[2,1],[1,8],[2,6]]\nOutput: 2\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 4, reservedSeats = [[4,3],[1,4],[4,6],[1,7]]\nOutput: 4\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 10^9
    • \n\t
    • 1 <= reservedSeats.length <= min(10*n, 10^4)
    • \n\t
    • reservedSeats[i].length == 2
    • \n\t
    • 1 <= reservedSeats[i][0] <= n
    • \n\t
    • 1 <= reservedSeats[i][1] <= 10
    • \n\t
    • All reservedSeats[i] are distinct.
    • \n
    \n", "content_cn": "

    \"\"

    \n\n

    \u5982\u4e0a\u56fe\u6240\u793a\uff0c\u7535\u5f71\u9662\u7684\u89c2\u5f71\u5385\u4e2d\u6709 n \u884c\u5ea7\u4f4d\uff0c\u884c\u7f16\u53f7\u4ece 1 \u5230 n \uff0c\u4e14\u6bcf\u4e00\u884c\u5185\u603b\u5171\u6709 10 \u4e2a\u5ea7\u4f4d\uff0c\u5217\u7f16\u53f7\u4ece 1 \u5230 10 \u3002

    \n\n

    \u7ed9\u4f60\u6570\u7ec4 reservedSeats \uff0c\u5305\u542b\u6240\u6709\u5df2\u7ecf\u88ab\u9884\u7ea6\u4e86\u7684\u5ea7\u4f4d\u3002\u6bd4\u5982\u8bf4\uff0cresearvedSeats[i]=[3,8] \uff0c\u5b83\u8868\u793a\u7b2c 3 \u884c\u7b2c 8 \u4e2a\u5ea7\u4f4d\u88ab\u9884\u7ea6\u4e86\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de \u6700\u591a\u80fd\u5b89\u6392\u591a\u5c11\u4e2a 4 \u4eba\u5bb6\u5ead \u30024 \u4eba\u5bb6\u5ead\u8981\u5360\u636e \u540c\u4e00\u884c\u5185\u8fde\u7eed \u7684 4 \u4e2a\u5ea7\u4f4d\u3002\u9694\u7740\u8fc7\u9053\u7684\u5ea7\u4f4d\uff08\u6bd4\u65b9\u8bf4 [3,3] \u548c [3,4]\uff09\u4e0d\u662f\u8fde\u7eed\u7684\u5ea7\u4f4d\uff0c\u4f46\u662f\u5982\u679c\u4f60\u53ef\u4ee5\u5c06 4 \u4eba\u5bb6\u5ead\u62c6\u6210\u8fc7\u9053\u4e24\u8fb9\u5404\u5750 2 \u4eba\uff0c\u8fd9\u6837\u5b50\u662f\u5141\u8bb8\u7684\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 3, reservedSeats = [[1,2],[1,3],[1,8],[2,6],[3,1],[3,10]]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u4e0a\u56fe\u6240\u793a\u662f\u6700\u4f18\u7684\u5b89\u6392\u65b9\u6848\uff0c\u603b\u5171\u53ef\u4ee5\u5b89\u6392 4 \u4e2a\u5bb6\u5ead\u3002\u84dd\u8272\u7684\u53c9\u8868\u793a\u88ab\u9884\u7ea6\u7684\u5ea7\u4f4d\uff0c\u6a59\u8272\u7684\u8fde\u7eed\u5ea7\u4f4d\u8868\u793a\u4e00\u4e2a 4 \u4eba\u5bb6\u5ead\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1an = 2, reservedSeats = [[2,1],[1,8],[2,6]]\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1an = 4, reservedSeats = [[4,3],[1,4],[4,6],[1,7]]\n\u8f93\u51fa\uff1a4\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 10^9
    • \n\t
    • 1 <= reservedSeats.length <= min(10*n, 10^4)
    • \n\t
    • reservedSeats[i].length == 2
    • \n\t
    • 1 <= reservedSeats[i][0] <= n
    • \n\t
    • 1 <= reservedSeats[i][1] <= 10
    • \n\t
    • \u6240\u6709 reservedSeats[i] \u90fd\u662f\u4e92\u4e0d\u76f8\u540c\u7684\u3002
    • \n
    \n", "tags_en": ["Greedy", "Array"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxNumberOfFamilies(int n, vector>& reservedSeats) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxNumberOfFamilies(int n, int[][] reservedSeats) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxNumberOfFamilies(self, n, reservedSeats):\n \"\"\"\n :type n: int\n :type reservedSeats: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxNumberOfFamilies(int n, int** reservedSeats, int reservedSeatsSize, int* reservedSeatsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxNumberOfFamilies(int n, int[][] reservedSeats) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} reservedSeats\n * @return {number}\n */\nvar maxNumberOfFamilies = function(n, reservedSeats) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} reserved_seats\n# @return {Integer}\ndef max_number_of_families(n, reserved_seats)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxNumberOfFamilies(_ n: Int, _ reservedSeats: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxNumberOfFamilies(n int, reservedSeats [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxNumberOfFamilies(n: Int, reservedSeats: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxNumberOfFamilies(n: Int, reservedSeats: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_number_of_families(n: i32, reserved_seats: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $reservedSeats\n * @return Integer\n */\n function maxNumberOfFamilies($n, $reservedSeats) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxNumberOfFamilies(n: number, reservedSeats: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-number-of-families n reservedSeats)\n (-> exact-integer? (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1386](https://leetcode-cn.com/problems/cinema-seat-allocation)", "[\u5b89\u6392\u7535\u5f71\u9662\u5ea7\u4f4d](/solution/1300-1399/1386.Cinema%20Seat%20Allocation/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1386](https://leetcode.com/problems/cinema-seat-allocation)", "[Cinema Seat Allocation](/solution/1300-1399/1386.Cinema%20Seat%20Allocation/README_EN.md)", "`Greedy`,`Array`", "Medium", ""]}, {"question_id": "1486", "frontend_question_id": "1385", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-the-distance-value-between-two-arrays", "url_en": "https://leetcode.com/problems/find-the-distance-value-between-two-arrays", "relative_path_cn": "/solution/1300-1399/1385.Find%20the%20Distance%20Value%20Between%20Two%20Arrays/README.md", "relative_path_en": "/solution/1300-1399/1385.Find%20the%20Distance%20Value%20Between%20Two%20Arrays/README_EN.md", "title_cn": "\u4e24\u4e2a\u6570\u7ec4\u95f4\u7684\u8ddd\u79bb\u503c", "title_en": "Find the Distance Value Between Two Arrays", "question_title_slug": "find-the-distance-value-between-two-arrays", "content_en": "

    Given two integer arrays arr1 and arr2, and the integer d, return the distance value between the two arrays.

    \n\n

    The distance value is defined as the number of elements arr1[i] such that there is not any element arr2[j] where |arr1[i]-arr2[j]| <= d.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr1 = [4,5,8], arr2 = [10,9,1,8], d = 2\nOutput: 2\nExplanation: \nFor arr1[0]=4 we have: \n|4-10|=6 > d=2 \n|4-9|=5 > d=2 \n|4-1|=3 > d=2 \n|4-8|=4 > d=2 \nFor arr1[1]=5 we have: \n|5-10|=5 > d=2 \n|5-9|=4 > d=2 \n|5-1|=4 > d=2 \n|5-8|=3 > d=2\nFor arr1[2]=8 we have:\n|8-10|=2 <= d=2\n|8-9|=1 <= d=2\n|8-1|=7 > d=2\n|8-8|=0 <= d=2\n
    \n\n

    Example 2:

    \n\n
    \nInput: arr1 = [1,4,2,3], arr2 = [-4,-3,6,10,20,30], d = 3\nOutput: 2\n
    \n\n

    Example 3:

    \n\n
    \nInput: arr1 = [2,1,100,3], arr2 = [-5,-2,10,-3,7], d = 6\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= arr1.length, arr2.length <= 500
    • \n\t
    • -10^3 <= arr1[i], arr2[j] <= 10^3
    • \n\t
    • 0 <= d <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u6574\u6570\u6570\u7ec4 arr1 \uff0c arr2 \u548c\u4e00\u4e2a\u6574\u6570 d \uff0c\u8bf7\u4f60\u8fd4\u56de\u4e24\u4e2a\u6570\u7ec4\u4e4b\u95f4\u7684 \u8ddd\u79bb\u503c \u3002

    \n\n

    \u300c\u8ddd\u79bb\u503c\u300d \u5b9a\u4e49\u4e3a\u7b26\u5408\u6b64\u8ddd\u79bb\u8981\u6c42\u7684\u5143\u7d20\u6570\u76ee\uff1a\u5bf9\u4e8e\u5143\u7d20 arr1[i] \uff0c\u4e0d\u5b58\u5728\u4efb\u4f55\u5143\u7d20 arr2[j] \u6ee1\u8db3 |arr1[i]-arr2[j]| <= d \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aarr1 = [4,5,8], arr2 = [10,9,1,8], d = 2\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n\u5bf9\u4e8e arr1[0]=4 \u6211\u4eec\u6709\uff1a\n|4-10|=6 > d=2 \n|4-9|=5 > d=2 \n|4-1|=3 > d=2 \n|4-8|=4 > d=2 \n\u6240\u4ee5 arr1[0]=4 \u7b26\u5408\u8ddd\u79bb\u8981\u6c42\n\n\u5bf9\u4e8e arr1[1]=5 \u6211\u4eec\u6709\uff1a\n|5-10|=5 > d=2 \n|5-9|=4 > d=2 \n|5-1|=4 > d=2 \n|5-8|=3 > d=2\n\u6240\u4ee5 arr1[1]=5 \u4e5f\u7b26\u5408\u8ddd\u79bb\u8981\u6c42\n\n\u5bf9\u4e8e arr1[2]=8 \u6211\u4eec\u6709\uff1a\n|8-10|=2 <= d=2\n|8-9|=1 <= d=2\n|8-1|=7 > d=2\n|8-8|=0 <= d=2\n\u5b58\u5728\u8ddd\u79bb\u5c0f\u4e8e\u7b49\u4e8e 2 \u7684\u60c5\u51b5\uff0c\u4e0d\u7b26\u5408\u8ddd\u79bb\u8981\u6c42 \n\n\u6545\u800c\u53ea\u6709 arr1[0]=4 \u548c arr1[1]=5 \u4e24\u4e2a\u7b26\u5408\u8ddd\u79bb\u8981\u6c42\uff0c\u8ddd\u79bb\u503c\u4e3a 2
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aarr1 = [1,4,2,3], arr2 = [-4,-3,6,10,20,30], d = 3\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aarr1 = [2,1,100,3], arr2 = [-5,-2,10,-3,7], d = 6\n\u8f93\u51fa\uff1a1\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= arr1.length, arr2.length <= 500
    • \n\t
    • -10^3 <= arr1[i], arr2[j] <= 10^3
    • \n\t
    • 0 <= d <= 100
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findTheDistanceValue(vector& arr1, vector& arr2, int d) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findTheDistanceValue(int[] arr1, int[] arr2, int d) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findTheDistanceValue(self, arr1, arr2, d):\n \"\"\"\n :type arr1: List[int]\n :type arr2: List[int]\n :type d: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findTheDistanceValue(self, arr1: List[int], arr2: List[int], d: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findTheDistanceValue(int* arr1, int arr1Size, int* arr2, int arr2Size, int d){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindTheDistanceValue(int[] arr1, int[] arr2, int d) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr1\n * @param {number[]} arr2\n * @param {number} d\n * @return {number}\n */\nvar findTheDistanceValue = function(arr1, arr2, d) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr1\n# @param {Integer[]} arr2\n# @param {Integer} d\n# @return {Integer}\ndef find_the_distance_value(arr1, arr2, d)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findTheDistanceValue(_ arr1: [Int], _ arr2: [Int], _ d: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findTheDistanceValue(arr1 []int, arr2 []int, d int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findTheDistanceValue(arr1: Array[Int], arr2: Array[Int], d: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findTheDistanceValue(arr1: IntArray, arr2: IntArray, d: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_the_distance_value(arr1: Vec, arr2: Vec, d: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr1\n * @param Integer[] $arr2\n * @param Integer $d\n * @return Integer\n */\n function findTheDistanceValue($arr1, $arr2, $d) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findTheDistanceValue(arr1: number[], arr2: number[], d: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-the-distance-value arr1 arr2 d)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1385](https://leetcode-cn.com/problems/find-the-distance-value-between-two-arrays)", "[\u4e24\u4e2a\u6570\u7ec4\u95f4\u7684\u8ddd\u79bb\u503c](/solution/1300-1399/1385.Find%20the%20Distance%20Value%20Between%20Two%20Arrays/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1385](https://leetcode.com/problems/find-the-distance-value-between-two-arrays)", "[Find the Distance Value Between Two Arrays](/solution/1300-1399/1385.Find%20the%20Distance%20Value%20Between%20Two%20Arrays/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1485", "frontend_question_id": "1368", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-cost-to-make-at-least-one-valid-path-in-a-grid", "url_en": "https://leetcode.com/problems/minimum-cost-to-make-at-least-one-valid-path-in-a-grid", "relative_path_cn": "/solution/1300-1399/1368.Minimum%20Cost%20to%20Make%20at%20Least%20One%20Valid%20Path%20in%20a%20Grid/README.md", "relative_path_en": "/solution/1300-1399/1368.Minimum%20Cost%20to%20Make%20at%20Least%20One%20Valid%20Path%20in%20a%20Grid/README_EN.md", "title_cn": "\u4f7f\u7f51\u683c\u56fe\u81f3\u5c11\u6709\u4e00\u6761\u6709\u6548\u8def\u5f84\u7684\u6700\u5c0f\u4ee3\u4ef7", "title_en": "Minimum Cost to Make at Least One Valid Path in a Grid", "question_title_slug": "minimum-cost-to-make-at-least-one-valid-path-in-a-grid", "content_en": "Given a m x n grid. Each cell of the grid has a sign pointing to the next cell you should visit if you are currently in this cell. The sign of grid[i][j] can be:\n
      \n\t
    • 1 which means go to the cell to the right. (i.e go from grid[i][j] to grid[i][j + 1])
    • \n\t
    • 2 which means go to the cell to the left. (i.e go from grid[i][j] to grid[i][j - 1])
    • \n\t
    • 3 which means go to the lower cell. (i.e go from grid[i][j] to grid[i + 1][j])
    • \n\t
    • 4 which means go to the upper cell. (i.e go from grid[i][j] to grid[i - 1][j])
    • \n
    \n\n

    Notice that there could be some invalid signs on the cells of the grid which points outside the grid.

    \n\n

    You will initially start at the upper left cell (0,0). A valid path in the grid is a path which starts from the upper left cell (0,0) and ends at the bottom-right cell (m - 1, n - 1) following the signs on the grid. The valid path doesn't have to be the shortest.

    \n\n

    You can modify the sign on a cell with cost = 1. You can modify the sign on a cell one time only.

    \n\n

    Return the minimum cost to make the grid have at least one valid path.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: grid = [[1,1,1,1],[2,2,2,2],[1,1,1,1],[2,2,2,2]]\nOutput: 3\nExplanation: You will start at point (0, 0).\nThe path to (3, 3) is as follows. (0, 0) --> (0, 1) --> (0, 2) --> (0, 3) change the arrow to down with cost = 1 --> (1, 3) --> (1, 2) --> (1, 1) --> (1, 0) change the arrow to down with cost = 1 --> (2, 0) --> (2, 1) --> (2, 2) --> (2, 3) change the arrow to down with cost = 1 --> (3, 3)\nThe total cost = 3.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: grid = [[1,1,3],[3,2,2],[1,1,4]]\nOutput: 0\nExplanation: You can follow the path from (0, 0) to (2, 2).\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: grid = [[1,2],[4,3]]\nOutput: 1\n
    \n\n

    Example 4:

    \n\n
    \nInput: grid = [[2,2,2],[2,2,2]]\nOutput: 3\n
    \n\n

    Example 5:

    \n\n
    \nInput: grid = [[4]]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= m, n <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a m x n \u7684\u7f51\u683c\u56fe grid \u3002 grid \u4e2d\u6bcf\u4e2a\u683c\u5b50\u90fd\u6709\u4e00\u4e2a\u6570\u5b57\uff0c\u5bf9\u5e94\u7740\u4ece\u8be5\u683c\u5b50\u51fa\u53d1\u4e0b\u4e00\u6b65\u8d70\u7684\u65b9\u5411\u3002 grid[i][j] \u4e2d\u7684\u6570\u5b57\u53ef\u80fd\u4e3a\u4ee5\u4e0b\u51e0\u79cd\u60c5\u51b5\uff1a

    \n\n
      \n\t
    • 1 \uff0c\u4e0b\u4e00\u6b65\u5f80\u53f3\u8d70\uff0c\u4e5f\u5c31\u662f\u4f60\u4f1a\u4ece grid[i][j] \u8d70\u5230 grid[i][j + 1]
    • \n\t
    • 2 \uff0c\u4e0b\u4e00\u6b65\u5f80\u5de6\u8d70\uff0c\u4e5f\u5c31\u662f\u4f60\u4f1a\u4ece grid[i][j] \u8d70\u5230 grid[i][j - 1]
    • \n\t
    • 3 \uff0c\u4e0b\u4e00\u6b65\u5f80\u4e0b\u8d70\uff0c\u4e5f\u5c31\u662f\u4f60\u4f1a\u4ece grid[i][j] \u8d70\u5230 grid[i + 1][j]
    • \n\t
    • 4 \uff0c\u4e0b\u4e00\u6b65\u5f80\u4e0a\u8d70\uff0c\u4e5f\u5c31\u662f\u4f60\u4f1a\u4ece grid[i][j] \u8d70\u5230 grid[i - 1][j]
    • \n
    \n\n

    \u6ce8\u610f\u7f51\u683c\u56fe\u4e2d\u53ef\u80fd\u4f1a\u6709 \u65e0\u6548\u6570\u5b57 \uff0c\u56e0\u4e3a\u5b83\u4eec\u53ef\u80fd\u6307\u5411 grid \u4ee5\u5916\u7684\u533a\u57df\u3002

    \n\n

    \u4e00\u5f00\u59cb\uff0c\u4f60\u4f1a\u4ece\u6700\u5de6\u4e0a\u89d2\u7684\u683c\u5b50 (0,0) \u51fa\u53d1\u3002\u6211\u4eec\u5b9a\u4e49\u4e00\u6761 \u6709\u6548\u8def\u5f84 \u4e3a\u4ece\u683c\u5b50 (0,0) \u51fa\u53d1\uff0c\u6bcf\u4e00\u6b65\u90fd\u987a\u7740\u6570\u5b57\u5bf9\u5e94\u65b9\u5411\u8d70\uff0c\u6700\u7ec8\u5728\u6700\u53f3\u4e0b\u89d2\u7684\u683c\u5b50 (m - 1, n - 1) \u7ed3\u675f\u7684\u8def\u5f84\u3002\u6709\u6548\u8def\u5f84 \u4e0d\u9700\u8981\u662f\u6700\u77ed\u8def\u5f84 \u3002

    \n\n

    \u4f60\u53ef\u4ee5\u82b1\u8d39 cost = 1 \u7684\u4ee3\u4ef7\u4fee\u6539\u4e00\u4e2a\u683c\u5b50\u4e2d\u7684\u6570\u5b57\uff0c\u4f46\u6bcf\u4e2a\u683c\u5b50\u4e2d\u7684\u6570\u5b57 \u53ea\u80fd\u4fee\u6539\u4e00\u6b21 \u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u8ba9\u7f51\u683c\u56fe\u81f3\u5c11\u6709\u4e00\u6761\u6709\u6548\u8def\u5f84\u7684\u6700\u5c0f\u4ee3\u4ef7\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1agrid = [[1,1,1,1],[2,2,2,2],[1,1,1,1],[2,2,2,2]]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u4f60\u5c06\u4ece\u70b9 (0, 0) \u51fa\u53d1\u3002\n\u5230\u8fbe (3, 3) \u7684\u8def\u5f84\u4e3a\uff1a (0, 0) --> (0, 1) --> (0, 2) --> (0, 3) \u82b1\u8d39\u4ee3\u4ef7 cost = 1 \u4f7f\u65b9\u5411\u5411\u4e0b --> (1, 3) --> (1, 2) --> (1, 1) --> (1, 0) \u82b1\u8d39\u4ee3\u4ef7 cost = 1 \u4f7f\u65b9\u5411\u5411\u4e0b --> (2, 0) --> (2, 1) --> (2, 2) --> (2, 3) \u82b1\u8d39\u4ee3\u4ef7 cost = 1 \u4f7f\u65b9\u5411\u5411\u4e0b --> (3, 3)\n\u603b\u82b1\u8d39\u4e3a cost = 3.\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1agrid = [[1,1,3],[3,2,2],[1,1,4]]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u4e0d\u4fee\u6539\u4efb\u4f55\u6570\u5b57\u4f60\u5c31\u53ef\u4ee5\u4ece (0, 0) \u5230\u8fbe (2, 2) \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1agrid = [[1,2],[4,3]]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1agrid = [[2,2,2],[2,2,2]]\n\u8f93\u51fa\uff1a3\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1agrid = [[4]]\n\u8f93\u51fa\uff1a0\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= m, n <= 100
    • \n
    \n", "tags_en": ["Breadth-first Search"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minCost(vector>& grid) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minCost(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minCost(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minCost(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minCost(int** grid, int gridSize, int* gridColSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinCost(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar minCost = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef min_cost(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minCost(_ grid: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minCost(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minCost(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minCost(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_cost(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function minCost($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minCost(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-cost grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1368](https://leetcode-cn.com/problems/minimum-cost-to-make-at-least-one-valid-path-in-a-grid)", "[\u4f7f\u7f51\u683c\u56fe\u81f3\u5c11\u6709\u4e00\u6761\u6709\u6548\u8def\u5f84\u7684\u6700\u5c0f\u4ee3\u4ef7](/solution/1300-1399/1368.Minimum%20Cost%20to%20Make%20at%20Least%20One%20Valid%20Path%20in%20a%20Grid/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[1368](https://leetcode.com/problems/minimum-cost-to-make-at-least-one-valid-path-in-a-grid)", "[Minimum Cost to Make at Least One Valid Path in a Grid](/solution/1300-1399/1368.Minimum%20Cost%20to%20Make%20at%20Least%20One%20Valid%20Path%20in%20a%20Grid/README_EN.md)", "`Breadth-first Search`", "Hard", ""]}, {"question_id": "1484", "frontend_question_id": "1367", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/linked-list-in-binary-tree", "url_en": "https://leetcode.com/problems/linked-list-in-binary-tree", "relative_path_cn": "/solution/1300-1399/1367.Linked%20List%20in%20Binary%20Tree/README.md", "relative_path_en": "/solution/1300-1399/1367.Linked%20List%20in%20Binary%20Tree/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u4e2d\u7684\u5217\u8868", "title_en": "Linked List in Binary Tree", "question_title_slug": "linked-list-in-binary-tree", "content_en": "

    Given a binary tree root and a linked list with head as the first node. 

    \n\n

    Return True if all the elements in the linked list starting from the head correspond to some downward path connected in the binary tree otherwise return False.

    \n\n

    In this context downward path means a path that starts at some node and goes downwards.

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: head = [4,2,8], root = [1,4,4,null,2,2,null,1,null,6,8,null,null,null,null,1,3]\nOutput: true\nExplanation: Nodes in blue form a subpath in the binary Tree.  \n
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: head = [1,4,2,6], root = [1,4,4,null,2,2,null,1,null,6,8,null,null,null,null,1,3]\nOutput: true\n
    \n\n

    Example 3:

    \n\n
    \nInput: head = [1,4,2,6,8], root = [1,4,4,null,2,2,null,1,null,6,8,null,null,null,null,1,3]\nOutput: false\nExplanation: There is no path in the binary tree that contains all the elements of the linked list from head.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree will be in the range [1, 2500].
    • \n\t
    • The number of nodes in the list will be in the range [1, 100].
    • \n\t
    • 1 <= Node.val <= 100 for each node in the linked list and binary tree.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u68f5\u4ee5 root \u4e3a\u6839\u7684\u4e8c\u53c9\u6811\u548c\u4e00\u4e2a head \u4e3a\u7b2c\u4e00\u4e2a\u8282\u70b9\u7684\u94fe\u8868\u3002

    \n\n

    \u5982\u679c\u5728\u4e8c\u53c9\u6811\u4e2d\uff0c\u5b58\u5728\u4e00\u6761\u4e00\u76f4\u5411\u4e0b\u7684\u8def\u5f84\uff0c\u4e14\u6bcf\u4e2a\u70b9\u7684\u6570\u503c\u6070\u597d\u4e00\u4e00\u5bf9\u5e94\u4ee5 head \u4e3a\u9996\u7684\u94fe\u8868\u4e2d\u6bcf\u4e2a\u8282\u70b9\u7684\u503c\uff0c\u90a3\u4e48\u8bf7\u4f60\u8fd4\u56de True \uff0c\u5426\u5219\u8fd4\u56de False \u3002

    \n\n

    \u4e00\u76f4\u5411\u4e0b\u7684\u8def\u5f84\u7684\u610f\u601d\u662f\uff1a\u4ece\u6811\u4e2d\u67d0\u4e2a\u8282\u70b9\u5f00\u59cb\uff0c\u4e00\u76f4\u8fde\u7eed\u5411\u4e0b\u7684\u8def\u5f84\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1ahead = [4,2,8], root = [1,4,4,null,2,2,null,1,null,6,8,null,null,null,null,1,3]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u6811\u4e2d\u84dd\u8272\u7684\u8282\u70b9\u6784\u6210\u4e86\u4e0e\u94fe\u8868\u5bf9\u5e94\u7684\u5b50\u8def\u5f84\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1ahead = [1,4,2,6], root = [1,4,4,null,2,2,null,1,null,6,8,null,null,null,null,1,3]\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1ahead = [1,4,2,6,8], root = [1,4,4,null,2,2,null,1,null,6,8,null,null,null,null,1,3]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u4e8c\u53c9\u6811\u4e2d\u4e0d\u5b58\u5728\u4e00\u4e00\u5bf9\u5e94\u94fe\u8868\u7684\u8def\u5f84\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u4e8c\u53c9\u6811\u548c\u94fe\u8868\u4e2d\u7684\u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u90fd\u6ee1\u8db3 1 <= node.val <= 100 \u3002
    • \n\t
    • \u94fe\u8868\u5305\u542b\u7684\u8282\u70b9\u6570\u76ee\u5728 1 \u5230 100 \u4e4b\u95f4\u3002
    • \n\t
    • \u4e8c\u53c9\u6811\u5305\u542b\u7684\u8282\u70b9\u6570\u76ee\u5728 1 \u5230 2500 \u4e4b\u95f4\u3002
    • \n
    \n", "tags_en": ["Tree", "Linked List", "Dynamic Programming"], "tags_cn": ["\u6811", "\u94fe\u8868", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n bool isSubPath(ListNode* head, TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public boolean isSubPath(ListNode head, TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\n# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def isSubPath(self, head, root):\n \"\"\"\n :type head: ListNode\n :type root: TreeNode\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\n# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def isSubPath(self, head: ListNode, root: TreeNode) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nbool isSubPath(struct ListNode* head, struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public bool IsSubPath(ListNode head, TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {ListNode} head\n * @param {TreeNode} root\n * @return {boolean}\n */\nvar isSubPath = function(head, root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {ListNode} head\n# @param {TreeNode} root\n# @return {Boolean}\ndef is_sub_path(head, root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func isSubPath(_ head: ListNode?, _ root: TreeNode?) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\n/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc isSubPath(head *ListNode, root *TreeNode) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\n/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def isSubPath(head: ListNode, root: TreeNode): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\n/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun isSubPath(head: ListNode?, root: TreeNode?): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\n// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn is_sub_path(head: Option>, root: Option>>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\n/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @param TreeNode $root\n * @return Boolean\n */\n function isSubPath($head, $root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\n/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction isSubPath(head: ListNode | null, root: TreeNode | null): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (is-sub-path head root)\n (-> (or/c list-node? #f) (or/c tree-node? #f) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1367](https://leetcode-cn.com/problems/linked-list-in-binary-tree)", "[\u4e8c\u53c9\u6811\u4e2d\u7684\u5217\u8868](/solution/1300-1399/1367.Linked%20List%20in%20Binary%20Tree/README.md)", "`\u6811`,`\u94fe\u8868`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1367](https://leetcode.com/problems/linked-list-in-binary-tree)", "[Linked List in Binary Tree](/solution/1300-1399/1367.Linked%20List%20in%20Binary%20Tree/README_EN.md)", "`Tree`,`Linked List`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "1483", "frontend_question_id": "1366", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/rank-teams-by-votes", "url_en": "https://leetcode.com/problems/rank-teams-by-votes", "relative_path_cn": "/solution/1300-1399/1366.Rank%20Teams%20by%20Votes/README.md", "relative_path_en": "/solution/1300-1399/1366.Rank%20Teams%20by%20Votes/README_EN.md", "title_cn": "\u901a\u8fc7\u6295\u7968\u5bf9\u56e2\u961f\u6392\u540d", "title_en": "Rank Teams by Votes", "question_title_slug": "rank-teams-by-votes", "content_en": "

    In a special ranking system, each voter gives a rank from highest to lowest to all teams participated in the competition.

    \n\n

    The ordering of teams is decided by who received the most position-one votes. If two or more teams tie in the first position, we consider the second position to resolve the conflict, if they tie again, we continue this process until the ties are resolved. If two or more teams are still tied after considering all positions, we rank them alphabetically based on their team letter.

    \n\n

    Given an array of strings votes which is the votes of all voters in the ranking systems. Sort all teams according to the ranking system described above.

    \n\n

    Return a string of all teams sorted by the ranking system.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: votes = ["ABC","ACB","ABC","ACB","ACB"]\nOutput: "ACB"\nExplanation: Team A was ranked first place by 5 voters. No other team was voted as first place so team A is the first team.\nTeam B was ranked second by 2 voters and was ranked third by 3 voters.\nTeam C was ranked second by 3 voters and was ranked third by 2 voters.\nAs most of the voters ranked C second, team C is the second team and team B is the third.\n
    \n\n

    Example 2:

    \n\n
    \nInput: votes = ["WXYZ","XYZW"]\nOutput: "XWYZ"\nExplanation: X is the winner due to tie-breaking rule. X has same votes as W for the first position but X has one vote as second position while W doesn't have any votes as second position. \n
    \n\n

    Example 3:

    \n\n
    \nInput: votes = ["ZMNAGUEDSJYLBOPHRQICWFXTVK"]\nOutput: "ZMNAGUEDSJYLBOPHRQICWFXTVK"\nExplanation: Only one voter so his votes are used for the ranking.\n
    \n\n

    Example 4:

    \n\n
    \nInput: votes = ["BCA","CAB","CBA","ABC","ACB","BAC"]\nOutput: "ABC"\nExplanation: \nTeam A was ranked first by 2 voters, second by 2 voters and third by 2 voters.\nTeam B was ranked first by 2 voters, second by 2 voters and third by 2 voters.\nTeam C was ranked first by 2 voters, second by 2 voters and third by 2 voters.\nThere is a tie and we rank teams ascending by their IDs.\n
    \n\n

    Example 5:

    \n\n
    \nInput: votes = ["M","M","M","M"]\nOutput: "M"\nExplanation: Only team M in the competition so it has the first rank.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= votes.length <= 1000
    • \n\t
    • 1 <= votes[i].length <= 26
    • \n\t
    • votes[i].length == votes[j].length for 0 <= i, j < votes.length.
    • \n\t
    • votes[i][j] is an English upper-case letter.
    • \n\t
    • All characters of votes[i] are unique.
    • \n\t
    • All the characters that occur in votes[0] also occur in votes[j] where 1 <= j < votes.length.
    • \n
    \n", "content_cn": "

    \u73b0\u5728\u6709\u4e00\u4e2a\u7279\u6b8a\u7684\u6392\u540d\u7cfb\u7edf\uff0c\u4f9d\u636e\u53c2\u8d5b\u56e2\u961f\u5728\u6295\u7968\u4eba\u5fc3\u4e2d\u7684\u6b21\u5e8f\u8fdb\u884c\u6392\u540d\uff0c\u6bcf\u4e2a\u6295\u7968\u8005\u90fd\u9700\u8981\u6309\u4ece\u9ad8\u5230\u4f4e\u7684\u987a\u5e8f\u5bf9\u53c2\u4e0e\u6392\u540d\u7684\u6240\u6709\u56e2\u961f\u8fdb\u884c\u6392\u4f4d\u3002

    \n\n

    \u6392\u540d\u89c4\u5219\u5982\u4e0b\uff1a

    \n\n
      \n\t
    • \u53c2\u8d5b\u56e2\u961f\u7684\u6392\u540d\u6b21\u5e8f\u4f9d\u7167\u5176\u6240\u83b7\u300c\u6392\u4f4d\u7b2c\u4e00\u300d\u7684\u7968\u7684\u591a\u5c11\u51b3\u5b9a\u3002\u5982\u679c\u5b58\u5728\u591a\u4e2a\u56e2\u961f\u5e76\u5217\u7684\u60c5\u51b5\uff0c\u5c06\u7ee7\u7eed\u8003\u8651\u5176\u300c\u6392\u4f4d\u7b2c\u4e8c\u300d\u7684\u7968\u7684\u6570\u91cf\u3002\u4ee5\u6b64\u7c7b\u63a8\uff0c\u76f4\u5230\u4e0d\u518d\u5b58\u5728\u5e76\u5217\u7684\u60c5\u51b5\u3002
    • \n\t
    • \u5982\u679c\u5728\u8003\u8651\u5b8c\u6240\u6709\u6295\u7968\u60c5\u51b5\u540e\u4ecd\u7136\u51fa\u73b0\u5e76\u5217\u73b0\u8c61\uff0c\u5219\u6839\u636e\u56e2\u961f\u5b57\u6bcd\u7684\u5b57\u6bcd\u987a\u5e8f\u8fdb\u884c\u6392\u540d\u3002
    • \n
    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4 votes \u4ee3\u8868\u5168\u4f53\u6295\u7968\u8005\u7ed9\u51fa\u7684\u6392\u4f4d\u60c5\u51b5\uff0c\u8bf7\u4f60\u6839\u636e\u4e0a\u8ff0\u6392\u540d\u89c4\u5219\u5bf9\u6240\u6709\u53c2\u8d5b\u56e2\u961f\u8fdb\u884c\u6392\u540d\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u80fd\u8868\u793a\u6309\u6392\u540d\u7cfb\u7edf \u6392\u5e8f\u540e \u7684\u6240\u6709\u56e2\u961f\u6392\u540d\u7684\u5b57\u7b26\u4e32\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1avotes = ["ABC","ACB","ABC","ACB","ACB"]\n\u8f93\u51fa\uff1a"ACB"\n\u89e3\u91ca\uff1aA \u961f\u83b7\u5f97\u4e94\u7968\u300c\u6392\u4f4d\u7b2c\u4e00\u300d\uff0c\u6ca1\u6709\u5176\u4ed6\u961f\u83b7\u5f97\u300c\u6392\u4f4d\u7b2c\u4e00\u300d\uff0c\u6240\u4ee5 A \u961f\u6392\u540d\u7b2c\u4e00\u3002\nB \u961f\u83b7\u5f97\u4e24\u7968\u300c\u6392\u4f4d\u7b2c\u4e8c\u300d\uff0c\u4e09\u7968\u300c\u6392\u4f4d\u7b2c\u4e09\u300d\u3002\nC \u961f\u83b7\u5f97\u4e09\u7968\u300c\u6392\u4f4d\u7b2c\u4e8c\u300d\uff0c\u4e24\u7968\u300c\u6392\u4f4d\u7b2c\u4e09\u300d\u3002\n\u7531\u4e8e C \u961f\u300c\u6392\u4f4d\u7b2c\u4e8c\u300d\u7684\u7968\u6570\u8f83\u591a\uff0c\u6240\u4ee5 C \u961f\u6392\u7b2c\u4e8c\uff0cB \u961f\u6392\u7b2c\u4e09\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1avotes = ["WXYZ","XYZW"]\n\u8f93\u51fa\uff1a"XWYZ"\n\u89e3\u91ca\uff1aX \u961f\u5728\u5e76\u5217\u50f5\u5c40\u6253\u7834\u540e\u6210\u4e3a\u6392\u540d\u7b2c\u4e00\u7684\u56e2\u961f\u3002X \u961f\u548c W \u961f\u7684\u300c\u6392\u4f4d\u7b2c\u4e00\u300d\u7968\u6570\u4e00\u6837\uff0c\u4f46\u662f X \u961f\u6709\u4e00\u7968\u300c\u6392\u4f4d\u7b2c\u4e8c\u300d\uff0c\u800c W \u6ca1\u6709\u83b7\u5f97\u300c\u6392\u4f4d\u7b2c\u4e8c\u300d\u3002 \n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1avotes = ["ZMNAGUEDSJYLBOPHRQICWFXTVK"]\n\u8f93\u51fa\uff1a"ZMNAGUEDSJYLBOPHRQICWFXTVK"\n\u89e3\u91ca\uff1a\u53ea\u6709\u4e00\u4e2a\u6295\u7968\u8005\uff0c\u6240\u4ee5\u6392\u540d\u5b8c\u5168\u6309\u7167\u4ed6\u7684\u610f\u613f\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1avotes = ["BCA","CAB","CBA","ABC","ACB","BAC"]\n\u8f93\u51fa\uff1a"ABC"\n\u89e3\u91ca\uff1a \nA \u961f\u83b7\u5f97\u4e24\u7968\u300c\u6392\u4f4d\u7b2c\u4e00\u300d\uff0c\u4e24\u7968\u300c\u6392\u4f4d\u7b2c\u4e8c\u300d\uff0c\u4e24\u7968\u300c\u6392\u4f4d\u7b2c\u4e09\u300d\u3002\nB \u961f\u83b7\u5f97\u4e24\u7968\u300c\u6392\u4f4d\u7b2c\u4e00\u300d\uff0c\u4e24\u7968\u300c\u6392\u4f4d\u7b2c\u4e8c\u300d\uff0c\u4e24\u7968\u300c\u6392\u4f4d\u7b2c\u4e09\u300d\u3002\nC \u961f\u83b7\u5f97\u4e24\u7968\u300c\u6392\u4f4d\u7b2c\u4e00\u300d\uff0c\u4e24\u7968\u300c\u6392\u4f4d\u7b2c\u4e8c\u300d\uff0c\u4e24\u7968\u300c\u6392\u4f4d\u7b2c\u4e09\u300d\u3002\n\u5b8c\u5168\u5e76\u5217\uff0c\u6240\u4ee5\u6211\u4eec\u9700\u8981\u6309\u7167\u5b57\u6bcd\u5347\u5e8f\u6392\u540d\u3002\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1avotes = ["M","M","M","M"]\n\u8f93\u51fa\uff1a"M"\n\u89e3\u91ca\uff1a\u53ea\u6709 M \u961f\u53c2\u8d5b\uff0c\u6240\u4ee5\u5b83\u6392\u540d\u7b2c\u4e00\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= votes.length <= 1000
    • \n\t
    • 1 <= votes[i].length <= 26
    • \n\t
    • votes[i].length == votes[j].length for 0 <= i, j < votes.length
    • \n\t
    • votes[i][j] \u662f\u82f1\u6587 \u5927\u5199 \u5b57\u6bcd
    • \n\t
    • votes[i] \u4e2d\u7684\u6240\u6709\u5b57\u6bcd\u90fd\u662f\u552f\u4e00\u7684
    • \n\t
    • votes[0] \u4e2d\u51fa\u73b0\u7684\u6240\u6709\u5b57\u6bcd \u540c\u6837\u4e5f \u51fa\u73b0\u5728 votes[j] \u4e2d\uff0c\u5176\u4e2d 1 <= j < votes.length
    • \n
    \n", "tags_en": ["Sort", "Array"], "tags_cn": ["\u6392\u5e8f", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string rankTeams(vector& votes) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String rankTeams(String[] votes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def rankTeams(self, votes):\n \"\"\"\n :type votes: List[str]\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def rankTeams(self, votes: List[str]) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * rankTeams(char ** votes, int votesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string RankTeams(string[] votes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} votes\n * @return {string}\n */\nvar rankTeams = function(votes) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} votes\n# @return {String}\ndef rank_teams(votes)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func rankTeams(_ votes: [String]) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func rankTeams(votes []string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def rankTeams(votes: Array[String]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun rankTeams(votes: Array): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn rank_teams(votes: Vec) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $votes\n * @return String\n */\n function rankTeams($votes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function rankTeams(votes: string[]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (rank-teams votes)\n (-> (listof string?) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1366](https://leetcode-cn.com/problems/rank-teams-by-votes)", "[\u901a\u8fc7\u6295\u7968\u5bf9\u56e2\u961f\u6392\u540d](/solution/1300-1399/1366.Rank%20Teams%20by%20Votes/README.md)", "`\u6392\u5e8f`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1366](https://leetcode.com/problems/rank-teams-by-votes)", "[Rank Teams by Votes](/solution/1300-1399/1366.Rank%20Teams%20by%20Votes/README_EN.md)", "`Sort`,`Array`", "Medium", ""]}, {"question_id": "1482", "frontend_question_id": "1365", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/how-many-numbers-are-smaller-than-the-current-number", "url_en": "https://leetcode.com/problems/how-many-numbers-are-smaller-than-the-current-number", "relative_path_cn": "/solution/1300-1399/1365.How%20Many%20Numbers%20Are%20Smaller%20Than%20the%20Current%20Number/README.md", "relative_path_en": "/solution/1300-1399/1365.How%20Many%20Numbers%20Are%20Smaller%20Than%20the%20Current%20Number/README_EN.md", "title_cn": "\u6709\u591a\u5c11\u5c0f\u4e8e\u5f53\u524d\u6570\u5b57\u7684\u6570\u5b57", "title_en": "How Many Numbers Are Smaller Than the Current Number", "question_title_slug": "how-many-numbers-are-smaller-than-the-current-number", "content_en": "

    Given the array nums, for each nums[i] find out how many numbers in the array are smaller than it. That is, for each nums[i] you have to count the number of valid j's such that j != i and nums[j] < nums[i].

    \n\n

    Return the answer in an array.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [8,1,2,2,3]\nOutput: [4,0,1,1,3]\nExplanation: \nFor nums[0]=8 there exist four smaller numbers than it (1, 2, 2 and 3). \nFor nums[1]=1 does not exist any smaller number than it.\nFor nums[2]=2 there exist one smaller number than it (1). \nFor nums[3]=2 there exist one smaller number than it (1). \nFor nums[4]=3 there exist three smaller numbers than it (1, 2 and 2).\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [6,5,4,8]\nOutput: [2,1,0,3]\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [7,7,7,7]\nOutput: [0,0,0,0]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= nums.length <= 500
    • \n\t
    • 0 <= nums[i] <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 nums\uff0c\u5bf9\u4e8e\u5176\u4e2d\u6bcf\u4e2a\u5143\u7d20 nums[i]\uff0c\u8bf7\u4f60\u7edf\u8ba1\u6570\u7ec4\u4e2d\u6bd4\u5b83\u5c0f\u7684\u6240\u6709\u6570\u5b57\u7684\u6570\u76ee\u3002

    \n\n

    \u6362\u800c\u8a00\u4e4b\uff0c\u5bf9\u4e8e\u6bcf\u4e2a nums[i] \u4f60\u5fc5\u987b\u8ba1\u7b97\u51fa\u6709\u6548\u7684 j \u7684\u6570\u91cf\uff0c\u5176\u4e2d j \u6ee1\u8db3 j != i \u4e14 nums[j] < nums[i] \u3002

    \n\n

    \u4ee5\u6570\u7ec4\u5f62\u5f0f\u8fd4\u56de\u7b54\u6848\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [8,1,2,2,3]\n\u8f93\u51fa\uff1a[4,0,1,1,3]\n\u89e3\u91ca\uff1a \n\u5bf9\u4e8e nums[0]=8 \u5b58\u5728\u56db\u4e2a\u6bd4\u5b83\u5c0f\u7684\u6570\u5b57\uff1a\uff081\uff0c2\uff0c2 \u548c 3\uff09\u3002 \n\u5bf9\u4e8e nums[1]=1 \u4e0d\u5b58\u5728\u6bd4\u5b83\u5c0f\u7684\u6570\u5b57\u3002\n\u5bf9\u4e8e nums[2]=2 \u5b58\u5728\u4e00\u4e2a\u6bd4\u5b83\u5c0f\u7684\u6570\u5b57\uff1a\uff081\uff09\u3002 \n\u5bf9\u4e8e nums[3]=2 \u5b58\u5728\u4e00\u4e2a\u6bd4\u5b83\u5c0f\u7684\u6570\u5b57\uff1a\uff081\uff09\u3002 \n\u5bf9\u4e8e nums[4]=3 \u5b58\u5728\u4e09\u4e2a\u6bd4\u5b83\u5c0f\u7684\u6570\u5b57\uff1a\uff081\uff0c2 \u548c 2\uff09\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [6,5,4,8]\n\u8f93\u51fa\uff1a[2,1,0,3]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [7,7,7,7]\n\u8f93\u51fa\uff1a[0,0,0,0]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= nums.length <= 500
    • \n\t
    • 0 <= nums[i] <= 100
    • \n
    \n", "tags_en": ["Array", "Hash Table"], "tags_cn": ["\u6570\u7ec4", "\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector smallerNumbersThanCurrent(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] smallerNumbersThanCurrent(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def smallerNumbersThanCurrent(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def smallerNumbersThanCurrent(self, nums: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* smallerNumbersThanCurrent(int* nums, int numsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] SmallerNumbersThanCurrent(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar smallerNumbersThanCurrent = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer[]}\ndef smaller_numbers_than_current(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func smallerNumbersThanCurrent(_ nums: [Int]) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func smallerNumbersThanCurrent(nums []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def smallerNumbersThanCurrent(nums: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun smallerNumbersThanCurrent(nums: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn smaller_numbers_than_current(nums: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer[]\n */\n function smallerNumbersThanCurrent($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function smallerNumbersThanCurrent(nums: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (smaller-numbers-than-current nums)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1365](https://leetcode-cn.com/problems/how-many-numbers-are-smaller-than-the-current-number)", "[\u6709\u591a\u5c11\u5c0f\u4e8e\u5f53\u524d\u6570\u5b57\u7684\u6570\u5b57](/solution/1300-1399/1365.How%20Many%20Numbers%20Are%20Smaller%20Than%20the%20Current%20Number/README.md)", "`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[1365](https://leetcode.com/problems/how-many-numbers-are-smaller-than-the-current-number)", "[How Many Numbers Are Smaller Than the Current Number](/solution/1300-1399/1365.How%20Many%20Numbers%20Are%20Smaller%20Than%20the%20Current%20Number/README_EN.md)", "`Array`,`Hash Table`", "Easy", ""]}, {"question_id": "1481", "frontend_question_id": "1350", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/students-with-invalid-departments", "url_en": "https://leetcode.com/problems/students-with-invalid-departments", "relative_path_cn": "/solution/1300-1399/1350.Students%20With%20Invalid%20Departments/README.md", "relative_path_en": "/solution/1300-1399/1350.Students%20With%20Invalid%20Departments/README_EN.md", "title_cn": "\u9662\u7cfb\u65e0\u6548\u7684\u5b66\u751f", "title_en": "Students With Invalid Departments", "question_title_slug": "students-with-invalid-departments", "content_en": "

    Table: Departments

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| name          | varchar |\n+---------------+---------+\nid is the primary key of this table.\nThe table has information about the id of each department of a university.\n
    \n\n

     

    \n\n

    Table: Students

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| name          | varchar |\n| department_id | int     |\n+---------------+---------+\nid is the primary key of this table.\nThe table has information about the id of each student at a university and the id of the department he/she studies at.\n
    \n\n

     

    \n\n

    Write an SQL query to find the id and the name of all students who are enrolled in departments that no longer exists.

    \n\n

    Return the result table in any order.

    \n\n

    The query result format is in the following example:

    \n\n
    \nDepartments table:\n+------+--------------------------+\n| id   | name                     |\n+------+--------------------------+\n| 1    | Electrical Engineering   |\n| 7    | Computer Engineering     |\n| 13   | Bussiness Administration |\n+------+--------------------------+\n\nStudents table:\n+------+----------+---------------+\n| id   | name     | department_id |\n+------+----------+---------------+\n| 23   | Alice    | 1             |\n| 1    | Bob      | 7             |\n| 5    | Jennifer | 13            |\n| 2    | John     | 14            |\n| 4    | Jasmine  | 77            |\n| 3    | Steve    | 74            |\n| 6    | Luis     | 1             |\n| 8    | Jonathan | 7             |\n| 7    | Daiana   | 33            |\n| 11   | Madelynn | 1             |\n+------+----------+---------------+\n\nResult table:\n+------+----------+\n| id   | name     |\n+------+----------+\n| 2    | John     |\n| 7    | Daiana   |\n| 4    | Jasmine  |\n| 3    | Steve    |\n+------+----------+\n\nJohn, Daiana, Steve and Jasmine are enrolled in departments 14, 33, 74 and 77 respectively. department 14, 33, 74 and 77 doesn't exist in the Departments table.\n
    \n", "content_cn": "

    \u9662\u7cfb\u8868: Departments

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| name          | varchar |\n+---------------+---------+\nid \u662f\u8be5\u8868\u7684\u4e3b\u952e\n\u8be5\u8868\u5305\u542b\u4e00\u6240\u5927\u5b66\u6bcf\u4e2a\u9662\u7cfb\u7684 id \u4fe1\u606f\n
    \n\n

     

    \n\n

    \u5b66\u751f\u8868: Students

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| name          | varchar |\n| department_id | int     |\n+---------------+---------+\nid \u662f\u8be5\u8868\u7684\u4e3b\u952e\n\u8be5\u8868\u5305\u542b\u4e00\u6240\u5927\u5b66\u6bcf\u4e2a\u5b66\u751f\u7684 id \u548c\u4ed6/\u5979\u5c31\u8bfb\u7684\u9662\u7cfb\u4fe1\u606f\n
    \n\n

     

    \n\n

    \u5199\u4e00\u6761 SQL \u8bed\u53e5\u4ee5\u67e5\u8be2\u90a3\u4e9b\u6240\u5728\u9662\u7cfb\u4e0d\u5b58\u5728\u7684\u5b66\u751f\u7684 id \u548c\u59d3\u540d

    \n\n

    \u53ef\u4ee5\u4ee5\u4efb\u4f55\u987a\u5e8f\u8fd4\u56de\u7ed3\u679c

    \n\n

    \u4e0b\u9762\u662f\u8fd4\u56de\u7ed3\u679c\u683c\u5f0f\u7684\u4f8b\u5b50

    \n\n
    \nDepartments \u8868:\n+------+--------------------------+\n| id   | name                     |\n+------+--------------------------+\n| 1    | Electrical Engineering   |\n| 7    | Computer Engineering     |\n| 13   | Bussiness Administration |\n+------+--------------------------+\n\nStudents \u8868:\n+------+----------+---------------+\n| id   | name     | department_id |\n+------+----------+---------------+\n| 23   | Alice    | 1             |\n| 1    | Bob      | 7             |\n| 5    | Jennifer | 13            |\n| 2    | John     | 14            |\n| 4    | Jasmine  | 77            |\n| 3    | Steve    | 74            |\n| 6    | Luis     | 1             |\n| 8    | Jonathan | 7             |\n| 7    | Daiana   | 33            |\n| 11   | Madelynn | 1             |\n+------+----------+---------------+\n\n\u7ed3\u679c\u8868:\n+------+----------+\n| id   | name     |\n+------+----------+\n| 2    | John     |\n| 7    | Daiana   |\n| 4    | Jasmine  |\n| 3    | Steve    |\n+------+----------+\n\nJohn, Daiana, Steve \u548c Jasmine \u6240\u5728\u7684\u9662\u7cfb\u5206\u522b\u662f 14, 33, 74 \u548c 77\uff0c \u5176\u4e2d 14, 33, 74 \u548c 77 \u5e76\u4e0d\u5b58\u5728\u4e8e\u9662\u7cfb\u8868\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1350](https://leetcode-cn.com/problems/students-with-invalid-departments)", "[\u9662\u7cfb\u65e0\u6548\u7684\u5b66\u751f](/solution/1300-1399/1350.Students%20With%20Invalid%20Departments/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1350](https://leetcode.com/problems/students-with-invalid-departments)", "[Students With Invalid Departments](/solution/1300-1399/1350.Students%20With%20Invalid%20Departments/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1480", "frontend_question_id": "1341", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/movie-rating", "url_en": "https://leetcode.com/problems/movie-rating", "relative_path_cn": "/solution/1300-1399/1341.Movie%20Rating/README.md", "relative_path_en": "/solution/1300-1399/1341.Movie%20Rating/README_EN.md", "title_cn": "\u7535\u5f71\u8bc4\u5206", "title_en": "Movie Rating", "question_title_slug": "movie-rating", "content_en": "

    Table: Movies

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| movie_id      | int     |\n| title         | varchar |\n+---------------+---------+\nmovie_id is the primary key for this table.\ntitle is the name of the movie.\n
    \n\n

    Table: Users

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| user_id       | int     |\n| name          | varchar |\n+---------------+---------+\nuser_id is the primary key for this table.\n
    \n\n

    Table: Movie_Rating

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| movie_id      | int     |\n| user_id       | int     |\n| rating        | int     |\n| created_at    | date    |\n+---------------+---------+\n(movie_id, user_id) is the primary key for this table.\nThis table contains the rating of a movie by a user in their review.\ncreated_at is the user's review date. \n
    \n\n

     

    \n\n

    Write the following SQL query:

    \n\n
      \n\t
    • Find the name of the user who has rated the greatest number of movies.\n\t

      In case of a tie, return lexicographically smaller user name.

      \n\t
    • \n\t
    • Find the movie name with the highest average rating in February 2020.\n\t

      In case of a tie, return lexicographically smaller movie name.

      \n\t
    • \n
    \n\n

    The query is returned in 2 rows, the query result format is in the following example:

    \n\n
    \nMovies table:\n+-------------+--------------+\n| movie_id    |  title       |\n+-------------+--------------+\n| 1           | Avengers     |\n| 2           | Frozen 2     |\n| 3           | Joker        |\n+-------------+--------------+\n\nUsers table:\n+-------------+--------------+\n| user_id     |  name        |\n+-------------+--------------+\n| 1           | Daniel       |\n| 2           | Monica       |\n| 3           | Maria        |\n| 4           | James        |\n+-------------+--------------+\n\nMovie_Rating table:\n+-------------+--------------+--------------+-------------+\n| movie_id    | user_id      | rating       | created_at  |\n+-------------+--------------+--------------+-------------+\n| 1           | 1            | 3            | 2020-01-12  |\n| 1           | 2            | 4            | 2020-02-11  |\n| 1           | 3            | 2            | 2020-02-12  |\n| 1           | 4            | 1            | 2020-01-01  |\n| 2           | 1            | 5            | 2020-02-17  | \n| 2           | 2            | 2            | 2020-02-01  | \n| 2           | 3            | 2            | 2020-03-01  |\n| 3           | 1            | 3            | 2020-02-22  | \n| 3           | 2            | 4            | 2020-02-25  | \n+-------------+--------------+--------------+-------------+\n\nResult table:\n+--------------+\n| results      |\n+--------------+\n| Daniel       |\n| Frozen 2     |\n+--------------+\n\nDaniel and Monica have rated 3 movies ("Avengers", "Frozen 2" and "Joker") but Daniel is smaller lexicographically.\nFrozen 2 and Joker have a rating average of 3.5 in February but Frozen 2 is smaller lexicographically.\n
    \n", "content_cn": "

    \u8868\uff1aMovies

    \n\n
    +---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| movie_id      | int     |\n| title         | varchar |\n+---------------+---------+\nmovie_id \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\u3002\ntitle \u662f\u7535\u5f71\u7684\u540d\u5b57\u3002\n
    \n\n

    \u8868\uff1aUsers

    \n\n
    +---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| user_id       | int     |\n| name          | varchar |\n+---------------+---------+\nuser_id \u662f\u8868\u7684\u4e3b\u952e\u3002\n
    \n\n

    \u8868\uff1aMovie_Rating

    \n\n
    +---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| movie_id      | int     |\n| user_id       | int     |\n| rating        | int     |\n| created_at    | date    |\n+---------------+---------+\n(movie_id, user_id) \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\u3002\n\u8fd9\u4e2a\u8868\u5305\u542b\u7528\u6237\u5728\u5176\u8bc4\u8bba\u4e2d\u5bf9\u7535\u5f71\u7684\u8bc4\u5206 rating \u3002\ncreated_at \u662f\u7528\u6237\u7684\u70b9\u8bc4\u65e5\u671f\u3002 \n
    \n\n

     

    \n\n

    \u8bf7\u4f60\u7f16\u5199\u4e00\u7ec4 SQL \u67e5\u8be2\uff1a

    \n\n
      \n\t
    • \u67e5\u627e\u8bc4\u8bba\u7535\u5f71\u6570\u91cf\u6700\u591a\u7684\u7528\u6237\u540d\u3002\n\t

      \u5982\u679c\u51fa\u73b0\u5e73\u5c40\uff0c\u8fd4\u56de\u5b57\u5178\u5e8f\u8f83\u5c0f\u7684\u7528\u6237\u540d\u3002

      \n\t
    • \n\t
    • \u67e5\u627e\u5728 2020 \u5e74 2 \u6708 \u5e73\u5747\u8bc4\u5206\u6700\u9ad8 \u7684\u7535\u5f71\u540d\u79f0\u3002\n\t

      \u5982\u679c\u51fa\u73b0\u5e73\u5c40\uff0c\u8fd4\u56de\u5b57\u5178\u5e8f\u8f83\u5c0f\u7684\u7535\u5f71\u540d\u79f0\u3002

      \n\t
    • \n
    \n\n

    \u67e5\u8be2\u5206\u4e24\u884c\u8fd4\u56de\uff0c\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a\uff1a

    \n\n
    Movies \u8868\uff1a\n+-------------+--------------+\n| movie_id    |  title       |\n+-------------+--------------+\n| 1           | Avengers     |\n| 2           | Frozen 2     |\n| 3           | Joker        |\n+-------------+--------------+\n\nUsers \u8868\uff1a\n+-------------+--------------+\n| user_id     |  name        |\n+-------------+--------------+\n| 1           | Daniel       |\n| 2           | Monica       |\n| 3           | Maria        |\n| 4           | James        |\n+-------------+--------------+\n\nMovie_Rating \u8868\uff1a\n+-------------+--------------+--------------+-------------+\n| movie_id    | user_id      | rating       | created_at  |\n+-------------+--------------+--------------+-------------+\n| 1           | 1            | 3            | 2020-01-12  |\n| 1           | 2            | 4            | 2020-02-11  |\n| 1           | 3            | 2            | 2020-02-12  |\n| 1           | 4            | 1            | 2020-01-01  |\n| 2           | 1            | 5            | 2020-02-17  | \n| 2           | 2            | 2            | 2020-02-01  | \n| 2           | 3            | 2            | 2020-03-01  |\n| 3           | 1            | 3            | 2020-02-22  | \n| 3           | 2            | 4            | 2020-02-25  | \n+-------------+--------------+--------------+-------------+\n\nResult \u8868\uff1a\n+--------------+\n| results      |\n+--------------+\n| Daniel       |\n| Frozen 2     |\n+--------------+\n\nDaniel \u548c Monica \u90fd\u70b9\u8bc4\u4e86 3 \u90e8\u7535\u5f71\uff08"Avengers", "Frozen 2" \u548c "Joker"\uff09 \u4f46\u662f Daniel \u5b57\u5178\u5e8f\u6bd4\u8f83\u5c0f\u3002\nFrozen 2 \u548c Joker \u5728 2 \u6708\u7684\u8bc4\u5206\u90fd\u662f 3.5\uff0c\u4f46\u662f Frozen 2 \u7684\u5b57\u5178\u5e8f\u6bd4\u8f83\u5c0f\u3002\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1341](https://leetcode-cn.com/problems/movie-rating)", "[\u7535\u5f71\u8bc4\u5206](/solution/1300-1399/1341.Movie%20Rating/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1341](https://leetcode.com/problems/movie-rating)", "[Movie Rating](/solution/1300-1399/1341.Movie%20Rating/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1479", "frontend_question_id": "1354", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/construct-target-array-with-multiple-sums", "url_en": "https://leetcode.com/problems/construct-target-array-with-multiple-sums", "relative_path_cn": "/solution/1300-1399/1354.Construct%20Target%20Array%20With%20Multiple%20Sums/README.md", "relative_path_en": "/solution/1300-1399/1354.Construct%20Target%20Array%20With%20Multiple%20Sums/README_EN.md", "title_cn": "\u591a\u6b21\u6c42\u548c\u6784\u9020\u76ee\u6807\u6570\u7ec4", "title_en": "Construct Target Array With Multiple Sums", "question_title_slug": "construct-target-array-with-multiple-sums", "content_en": "

    You are given an array target of n integers. From a starting array arr consisting of n 1's, you may perform the following procedure :

    \n\n
      \n\t
    • let x be the sum of all elements currently in your array.
    • \n\t
    • choose index i, such that 0 <= i < n and set the value of arr at index i to x.
    • \n\t
    • You may repeat this procedure as many times as needed.
    • \n
    \n\n

    Return true if it is possible to construct the target array from arr, otherwise, return false.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: target = [9,3,5]\nOutput: true\nExplanation: Start with arr = [1, 1, 1] \n[1, 1, 1], sum = 3 choose index 1\n[1, 3, 1], sum = 5 choose index 2\n[1, 3, 5], sum = 9 choose index 0\n[9, 3, 5] Done\n
    \n\n

    Example 2:

    \n\n
    \nInput: target = [1,1,1,2]\nOutput: false\nExplanation: Impossible to create target array from [1,1,1,1].\n
    \n\n

    Example 3:

    \n\n
    \nInput: target = [8,5]\nOutput: true\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == target.length
    • \n\t
    • 1 <= n <= 5 * 104
    • \n\t
    • 1 <= target[i] <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 target \u3002\u4e00\u5f00\u59cb\uff0c\u4f60\u6709\u4e00\u4e2a\u6570\u7ec4 A \uff0c\u5b83\u7684\u6240\u6709\u5143\u7d20\u5747\u4e3a 1 \uff0c\u4f60\u53ef\u4ee5\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\uff1a

    \n\n
      \n\t
    • \u4ee4 x \u4e3a\u4f60\u6570\u7ec4\u91cc\u6240\u6709\u5143\u7d20\u7684\u548c
    • \n\t
    • \u9009\u62e9\u6ee1\u8db3 0 <= i < target.size \u7684\u4efb\u610f\u4e0b\u6807 i \uff0c\u5e76\u8ba9 A \u6570\u7ec4\u91cc\u4e0b\u6807\u4e3a i \u5904\u7684\u503c\u4e3a x \u3002
    • \n\t
    • \u4f60\u53ef\u4ee5\u91cd\u590d\u8be5\u8fc7\u7a0b\u4efb\u610f\u6b21
    • \n
    \n\n

    \u5982\u679c\u80fd\u4ece A \u5f00\u59cb\u6784\u9020\u51fa\u76ee\u6807\u6570\u7ec4 target \uff0c\u8bf7\u4f60\u8fd4\u56de True \uff0c\u5426\u5219\u8fd4\u56de False \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1atarget = [9,3,5]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u4ece [1, 1, 1] \u5f00\u59cb\n[1, 1, 1], \u548c\u4e3a 3 \uff0c\u9009\u62e9\u4e0b\u6807 1\n[1, 3, 1], \u548c\u4e3a 5\uff0c \u9009\u62e9\u4e0b\u6807 2\n[1, 3, 5], \u548c\u4e3a 9\uff0c \u9009\u62e9\u4e0b\u6807 0\n[9, 3, 5] \u5b8c\u6210\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1atarget = [1,1,1,2]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u4e0d\u53ef\u80fd\u4ece [1,1,1,1] \u51fa\u53d1\u6784\u9020\u76ee\u6807\u6570\u7ec4\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1atarget = [8,5]\n\u8f93\u51fa\uff1atrue\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • N == target.length
    • \n\t
    • 1 <= target.length <= 5 * 10^4
    • \n\t
    • 1 <= target[i] <= 10^9
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isPossible(vector& target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isPossible(int[] target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isPossible(self, target):\n \"\"\"\n :type target: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isPossible(self, target: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isPossible(int* target, int targetSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsPossible(int[] target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} target\n * @return {boolean}\n */\nvar isPossible = function(target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} target\n# @return {Boolean}\ndef is_possible(target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isPossible(_ target: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isPossible(target []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isPossible(target: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isPossible(target: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_possible(target: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $target\n * @return Boolean\n */\n function isPossible($target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isPossible(target: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-possible target)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1354](https://leetcode-cn.com/problems/construct-target-array-with-multiple-sums)", "[\u591a\u6b21\u6c42\u548c\u6784\u9020\u76ee\u6807\u6570\u7ec4](/solution/1300-1399/1354.Construct%20Target%20Array%20With%20Multiple%20Sums/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[1354](https://leetcode.com/problems/construct-target-array-with-multiple-sums)", "[Construct Target Array With Multiple Sums](/solution/1300-1399/1354.Construct%20Target%20Array%20With%20Multiple%20Sums/README_EN.md)", "`Greedy`", "Hard", ""]}, {"question_id": "1478", "frontend_question_id": "1353", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-number-of-events-that-can-be-attended", "url_en": "https://leetcode.com/problems/maximum-number-of-events-that-can-be-attended", "relative_path_cn": "/solution/1300-1399/1353.Maximum%20Number%20of%20Events%20That%20Can%20Be%20Attended/README.md", "relative_path_en": "/solution/1300-1399/1353.Maximum%20Number%20of%20Events%20That%20Can%20Be%20Attended/README_EN.md", "title_cn": "\u6700\u591a\u53ef\u4ee5\u53c2\u52a0\u7684\u4f1a\u8bae\u6570\u76ee", "title_en": "Maximum Number of Events That Can Be Attended", "question_title_slug": "maximum-number-of-events-that-can-be-attended", "content_en": "

    Given an array of events where events[i] = [startDayi, endDayi]. Every event i starts at startDayi and ends at endDayi.

    \n\n

    You can attend an event i at any day d where startTimei <= d <= endTimei. Notice that you can only attend one event at any time d.

    \n\n

    Return the maximum number of events you can attend.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: events = [[1,2],[2,3],[3,4]]\nOutput: 3\nExplanation: You can attend all the three events.\nOne way to attend them all is as shown.\nAttend the first event on day 1.\nAttend the second event on day 2.\nAttend the third event on day 3.\n
    \n\n

    Example 2:

    \n\n
    \nInput: events= [[1,2],[2,3],[3,4],[1,2]]\nOutput: 4\n
    \n\n

    Example 3:

    \n\n
    \nInput: events = [[1,4],[4,4],[2,2],[3,4],[1,1]]\nOutput: 4\n
    \n\n

    Example 4:

    \n\n
    \nInput: events = [[1,100000]]\nOutput: 1\n
    \n\n

    Example 5:

    \n\n
    \nInput: events = [[1,1],[1,2],[1,3],[1,4],[1,5],[1,6],[1,7]]\nOutput: 7\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= events.length <= 105
    • \n\t
    • events[i].length == 2
    • \n\t
    • 1 <= startDayi <= endDayi <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 events\uff0c\u5176\u4e2d events[i] = [startDayi, endDayi] \uff0c\u8868\u793a\u4f1a\u8bae i \u5f00\u59cb\u4e8e startDayi \uff0c\u7ed3\u675f\u4e8e endDayi \u3002

    \n\n

    \u4f60\u53ef\u4ee5\u5728\u6ee1\u8db3 startDayi <= d <= endDayi \u4e2d\u7684\u4efb\u610f\u4e00\u5929 d \u53c2\u52a0\u4f1a\u8bae i \u3002\u6ce8\u610f\uff0c\u4e00\u5929\u53ea\u80fd\u53c2\u52a0\u4e00\u4e2a\u4f1a\u8bae\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u4f60\u53ef\u4ee5\u53c2\u52a0\u7684 \u6700\u5927 \u4f1a\u8bae\u6570\u76ee\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1aevents = [[1,2],[2,3],[3,4]]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u53c2\u52a0\u6240\u6709\u7684\u4e09\u4e2a\u4f1a\u8bae\u3002\n\u5b89\u6392\u4f1a\u8bae\u7684\u4e00\u79cd\u65b9\u6848\u5982\u4e0a\u56fe\u3002\n\u7b2c 1 \u5929\u53c2\u52a0\u7b2c\u4e00\u4e2a\u4f1a\u8bae\u3002\n\u7b2c 2 \u5929\u53c2\u52a0\u7b2c\u4e8c\u4e2a\u4f1a\u8bae\u3002\n\u7b2c 3 \u5929\u53c2\u52a0\u7b2c\u4e09\u4e2a\u4f1a\u8bae\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aevents= [[1,2],[2,3],[3,4],[1,2]]\n\u8f93\u51fa\uff1a4\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aevents = [[1,4],[4,4],[2,2],[3,4],[1,1]]\n\u8f93\u51fa\uff1a4\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1aevents = [[1,100000]]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1aevents = [[1,1],[1,2],[1,3],[1,4],[1,5],[1,6],[1,7]]\n\u8f93\u51fa\uff1a7\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= events.length <= 10^5
    • \n\t
    • events[i].length == 2
    • \n\t
    • 1 <= events[i][0] <= events[i][1] <= 10^5
    • \n
    \n", "tags_en": ["Greedy", "Sort", "Segment Tree"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6392\u5e8f", "\u7ebf\u6bb5\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxEvents(vector>& events) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxEvents(int[][] events) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxEvents(self, events):\n \"\"\"\n :type events: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxEvents(self, events: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxEvents(int** events, int eventsSize, int* eventsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxEvents(int[][] events) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} events\n * @return {number}\n */\nvar maxEvents = function(events) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} events\n# @return {Integer}\ndef max_events(events)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxEvents(_ events: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxEvents(events [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxEvents(events: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxEvents(events: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_events(events: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $events\n * @return Integer\n */\n function maxEvents($events) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxEvents(events: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-events events)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1353](https://leetcode-cn.com/problems/maximum-number-of-events-that-can-be-attended)", "[\u6700\u591a\u53ef\u4ee5\u53c2\u52a0\u7684\u4f1a\u8bae\u6570\u76ee](/solution/1300-1399/1353.Maximum%20Number%20of%20Events%20That%20Can%20Be%20Attended/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6392\u5e8f`,`\u7ebf\u6bb5\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1353](https://leetcode.com/problems/maximum-number-of-events-that-can-be-attended)", "[Maximum Number of Events That Can Be Attended](/solution/1300-1399/1353.Maximum%20Number%20of%20Events%20That%20Can%20Be%20Attended/README_EN.md)", "`Greedy`,`Sort`,`Segment Tree`", "Medium", ""]}, {"question_id": "1477", "frontend_question_id": "1352", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/product-of-the-last-k-numbers", "url_en": "https://leetcode.com/problems/product-of-the-last-k-numbers", "relative_path_cn": "/solution/1300-1399/1352.Product%20of%20the%20Last%20K%20Numbers/README.md", "relative_path_en": "/solution/1300-1399/1352.Product%20of%20the%20Last%20K%20Numbers/README_EN.md", "title_cn": "\u6700\u540e K \u4e2a\u6570\u7684\u4e58\u79ef", "title_en": "Product of the Last K Numbers", "question_title_slug": "product-of-the-last-k-numbers", "content_en": "

    Implement the class ProductOfNumbers that supports two methods:

    \n\n

    1. add(int num)

    \n\n
      \n\t
    • Adds the number num to the back of the current list of numbers.
    • \n
    \n\n

    2. getProduct(int k)

    \n\n
      \n\t
    • Returns the product of the last k numbers in the current list.
    • \n\t
    • You can assume that always the current list has at least k numbers.
    • \n
    \n\n

    At any time, the product of any contiguous sequence of numbers will fit into a single 32-bit integer without overflowing.

    \n\n

     

    \n

    Example:

    \n\n
    \nInput\n["ProductOfNumbers","add","add","add","add","add","getProduct","getProduct","getProduct","add","getProduct"]\n[[],[3],[0],[2],[5],[4],[2],[3],[4],[8],[2]]\n\nOutput\n[null,null,null,null,null,null,20,40,0,null,32]\n\nExplanation\nProductOfNumbers productOfNumbers = new ProductOfNumbers();\nproductOfNumbers.add(3);        // [3]\nproductOfNumbers.add(0);        // [3,0]\nproductOfNumbers.add(2);        // [3,0,2]\nproductOfNumbers.add(5);        // [3,0,2,5]\nproductOfNumbers.add(4);        // [3,0,2,5,4]\nproductOfNumbers.getProduct(2); // return 20. The product of the last 2 numbers is 5 * 4 = 20\nproductOfNumbers.getProduct(3); // return 40. The product of the last 3 numbers is 2 * 5 * 4 = 40\nproductOfNumbers.getProduct(4); // return 0. The product of the last 4 numbers is 0 * 2 * 5 * 4 = 0\nproductOfNumbers.add(8);        // [3,0,2,5,4,8]\nproductOfNumbers.getProduct(2); // return 32. The product of the last 2 numbers is 4 * 8 = 32 \n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • There will be at most 40000 operations considering both add and getProduct.
    • \n\t
    • 0 <= num <= 100
    • \n\t
    • 1 <= k <= 40000
    • \n
    \n", "content_cn": "

    \u8bf7\u4f60\u5b9e\u73b0\u4e00\u4e2a\u300c\u6570\u5b57\u4e58\u79ef\u7c7b\u300dProductOfNumbers\uff0c\u8981\u6c42\u652f\u6301\u4e0b\u8ff0\u4e24\u79cd\u65b9\u6cd5\uff1a

    \n\n

    1. add(int num)

    \n\n
      \n\t
    • \u5c06\u6570\u5b57 num \u6dfb\u52a0\u5230\u5f53\u524d\u6570\u5b57\u5217\u8868\u7684\u6700\u540e\u9762\u3002
    • \n
    \n\n

    2. getProduct(int k)

    \n\n
      \n\t
    • \u8fd4\u56de\u5f53\u524d\u6570\u5b57\u5217\u8868\u4e2d\uff0c\u6700\u540e k \u4e2a\u6570\u5b57\u7684\u4e58\u79ef\u3002
    • \n\t
    • \u4f60\u53ef\u4ee5\u5047\u8bbe\u5f53\u524d\u5217\u8868\u4e2d\u59cb\u7ec8 \u81f3\u5c11 \u5305\u542b k \u4e2a\u6570\u5b57\u3002
    • \n
    \n\n

    \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\uff1a\u4efb\u4f55\u65f6\u5019\uff0c\u4efb\u4e00\u8fde\u7eed\u6570\u5b57\u5e8f\u5217\u7684\u4e58\u79ef\u90fd\u5728 32-bit \u6574\u6570\u8303\u56f4\u5185\uff0c\u4e0d\u4f1a\u6ea2\u51fa\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1a\n["ProductOfNumbers","add","add","add","add","add","getProduct","getProduct","getProduct","add","getProduct"]\n[[],[3],[0],[2],[5],[4],[2],[3],[4],[8],[2]]\n\n\u8f93\u51fa\uff1a\n[null,null,null,null,null,null,20,40,0,null,32]\n\n\u89e3\u91ca\uff1a\nProductOfNumbers productOfNumbers = new ProductOfNumbers();\nproductOfNumbers.add(3);        // [3]\nproductOfNumbers.add(0);        // [3,0]\nproductOfNumbers.add(2);        // [3,0,2]\nproductOfNumbers.add(5);        // [3,0,2,5]\nproductOfNumbers.add(4);        // [3,0,2,5,4]\nproductOfNumbers.getProduct(2); // \u8fd4\u56de 20 \u3002\u6700\u540e 2 \u4e2a\u6570\u5b57\u7684\u4e58\u79ef\u662f 5 * 4 = 20\nproductOfNumbers.getProduct(3); // \u8fd4\u56de 40 \u3002\u6700\u540e 3 \u4e2a\u6570\u5b57\u7684\u4e58\u79ef\u662f 2 * 5 * 4 = 40\nproductOfNumbers.getProduct(4); // \u8fd4\u56de  0 \u3002\u6700\u540e 4 \u4e2a\u6570\u5b57\u7684\u4e58\u79ef\u662f 0 * 2 * 5 * 4 = 0\nproductOfNumbers.add(8);        // [3,0,2,5,4,8]\nproductOfNumbers.getProduct(2); // \u8fd4\u56de 32 \u3002\u6700\u540e 2 \u4e2a\u6570\u5b57\u7684\u4e58\u79ef\u662f 4 * 8 = 32 \n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • add \u548c getProduct \u4e24\u79cd\u64cd\u4f5c\u52a0\u8d77\u6765\u603b\u5171\u4e0d\u4f1a\u8d85\u8fc7 40000 \u6b21\u3002
    • \n\t
    • 0 <= num <= 100
    • \n\t
    • 1 <= k <= 40000
    • \n
    \n", "tags_en": ["Design", "Array"], "tags_cn": ["\u8bbe\u8ba1", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class ProductOfNumbers {\npublic:\n ProductOfNumbers() {\n\n }\n \n void add(int num) {\n\n }\n \n int getProduct(int k) {\n\n }\n};\n\n/**\n * Your ProductOfNumbers object will be instantiated and called as such:\n * ProductOfNumbers* obj = new ProductOfNumbers();\n * obj->add(num);\n * int param_2 = obj->getProduct(k);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class ProductOfNumbers {\n\n public ProductOfNumbers() {\n\n }\n \n public void add(int num) {\n\n }\n \n public int getProduct(int k) {\n\n }\n}\n\n/**\n * Your ProductOfNumbers object will be instantiated and called as such:\n * ProductOfNumbers obj = new ProductOfNumbers();\n * obj.add(num);\n * int param_2 = obj.getProduct(k);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class ProductOfNumbers(object):\n\n def __init__(self):\n\n\n def add(self, num):\n \"\"\"\n :type num: int\n :rtype: None\n \"\"\"\n\n\n def getProduct(self, k):\n \"\"\"\n :type k: int\n :rtype: int\n \"\"\"\n\n\n\n# Your ProductOfNumbers object will be instantiated and called as such:\n# obj = ProductOfNumbers()\n# obj.add(num)\n# param_2 = obj.getProduct(k)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class ProductOfNumbers:\n\n def __init__(self):\n\n\n def add(self, num: int) -> None:\n\n\n def getProduct(self, k: int) -> int:\n\n\n\n# Your ProductOfNumbers object will be instantiated and called as such:\n# obj = ProductOfNumbers()\n# obj.add(num)\n# param_2 = obj.getProduct(k)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} ProductOfNumbers;\n\n\nProductOfNumbers* productOfNumbersCreate() {\n\n}\n\nvoid productOfNumbersAdd(ProductOfNumbers* obj, int num) {\n\n}\n\nint productOfNumbersGetProduct(ProductOfNumbers* obj, int k) {\n\n}\n\nvoid productOfNumbersFree(ProductOfNumbers* obj) {\n\n}\n\n/**\n * Your ProductOfNumbers struct will be instantiated and called as such:\n * ProductOfNumbers* obj = productOfNumbersCreate();\n * productOfNumbersAdd(obj, num);\n \n * int param_2 = productOfNumbersGetProduct(obj, k);\n \n * productOfNumbersFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class ProductOfNumbers {\n\n public ProductOfNumbers() {\n\n }\n \n public void Add(int num) {\n\n }\n \n public int GetProduct(int k) {\n\n }\n}\n\n/**\n * Your ProductOfNumbers object will be instantiated and called as such:\n * ProductOfNumbers obj = new ProductOfNumbers();\n * obj.Add(num);\n * int param_2 = obj.GetProduct(k);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "\nvar ProductOfNumbers = function() {\n\n};\n\n/** \n * @param {number} num\n * @return {void}\n */\nProductOfNumbers.prototype.add = function(num) {\n\n};\n\n/** \n * @param {number} k\n * @return {number}\n */\nProductOfNumbers.prototype.getProduct = function(k) {\n\n};\n\n/**\n * Your ProductOfNumbers object will be instantiated and called as such:\n * var obj = new ProductOfNumbers()\n * obj.add(num)\n * var param_2 = obj.getProduct(k)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class ProductOfNumbers\n def initialize()\n\n end\n\n\n=begin\n :type num: Integer\n :rtype: Void\n=end\n def add(num)\n\n end\n\n\n=begin\n :type k: Integer\n :rtype: Integer\n=end\n def get_product(k)\n\n end\n\n\nend\n\n# Your ProductOfNumbers object will be instantiated and called as such:\n# obj = ProductOfNumbers.new()\n# obj.add(num)\n# param_2 = obj.get_product(k)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass ProductOfNumbers {\n\n init() {\n \n }\n \n func add(_ num: Int) {\n \n }\n \n func getProduct(_ k: Int) -> Int {\n \n }\n}\n\n/**\n * Your ProductOfNumbers object will be instantiated and called as such:\n * let obj = ProductOfNumbers()\n * obj.add(num)\n * let ret_2: Int = obj.getProduct(k)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type ProductOfNumbers struct {\n\n}\n\n\nfunc Constructor() ProductOfNumbers {\n\n}\n\n\nfunc (this *ProductOfNumbers) Add(num int) {\n\n}\n\n\nfunc (this *ProductOfNumbers) GetProduct(k int) int {\n\n}\n\n\n/**\n * Your ProductOfNumbers object will be instantiated and called as such:\n * obj := Constructor();\n * obj.Add(num);\n * param_2 := obj.GetProduct(k);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class ProductOfNumbers() {\n\n def add(num: Int) {\n\n }\n\n def getProduct(k: Int): Int = {\n\n }\n\n}\n\n/**\n * Your ProductOfNumbers object will be instantiated and called as such:\n * var obj = new ProductOfNumbers()\n * obj.add(num)\n * var param_2 = obj.getProduct(k)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class ProductOfNumbers() {\n\n fun add(num: Int) {\n\n }\n\n fun getProduct(k: Int): Int {\n\n }\n\n}\n\n/**\n * Your ProductOfNumbers object will be instantiated and called as such:\n * var obj = ProductOfNumbers()\n * obj.add(num)\n * var param_2 = obj.getProduct(k)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct ProductOfNumbers {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl ProductOfNumbers {\n\n fn new() -> Self {\n\n }\n \n fn add(&self, num: i32) {\n\n }\n \n fn get_product(&self, k: i32) -> i32 {\n\n }\n}\n\n/**\n * Your ProductOfNumbers object will be instantiated and called as such:\n * let obj = ProductOfNumbers::new();\n * obj.add(num);\n * let ret_2: i32 = obj.get_product(k);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class ProductOfNumbers {\n /**\n */\n function __construct() {\n\n }\n\n /**\n * @param Integer $num\n * @return NULL\n */\n function add($num) {\n\n }\n\n /**\n * @param Integer $k\n * @return Integer\n */\n function getProduct($k) {\n\n }\n}\n\n/**\n * Your ProductOfNumbers object will be instantiated and called as such:\n * $obj = ProductOfNumbers();\n * $obj->add($num);\n * $ret_2 = $obj->getProduct($k);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class ProductOfNumbers {\n constructor() {\n\n }\n\n add(num: number): void {\n\n }\n\n getProduct(k: number): number {\n\n }\n}\n\n/**\n * Your ProductOfNumbers object will be instantiated and called as such:\n * var obj = new ProductOfNumbers()\n * obj.add(num)\n * var param_2 = obj.getProduct(k)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define product-of-numbers%\n (class object%\n (super-new)\n (init-field)\n \n ; add : exact-integer? -> void?\n (define/public (add num)\n\n )\n ; get-product : exact-integer? -> exact-integer?\n (define/public (get-product k)\n\n )))\n\n;; Your product-of-numbers% object will be instantiated and called as such:\n;; (define obj (new product-of-numbers%))\n;; (send obj add num)\n;; (define param_2 (send obj get-product k))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1352](https://leetcode-cn.com/problems/product-of-the-last-k-numbers)", "[\u6700\u540e K \u4e2a\u6570\u7684\u4e58\u79ef](/solution/1300-1399/1352.Product%20of%20the%20Last%20K%20Numbers/README.md)", "`\u8bbe\u8ba1`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1352](https://leetcode.com/problems/product-of-the-last-k-numbers)", "[Product of the Last K Numbers](/solution/1300-1399/1352.Product%20of%20the%20Last%20K%20Numbers/README_EN.md)", "`Design`,`Array`", "Medium", ""]}, {"question_id": "1476", "frontend_question_id": "1351", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-negative-numbers-in-a-sorted-matrix", "url_en": "https://leetcode.com/problems/count-negative-numbers-in-a-sorted-matrix", "relative_path_cn": "/solution/1300-1399/1351.Count%20Negative%20Numbers%20in%20a%20Sorted%20Matrix/README.md", "relative_path_en": "/solution/1300-1399/1351.Count%20Negative%20Numbers%20in%20a%20Sorted%20Matrix/README_EN.md", "title_cn": "\u7edf\u8ba1\u6709\u5e8f\u77e9\u9635\u4e2d\u7684\u8d1f\u6570", "title_en": "Count Negative Numbers in a Sorted Matrix", "question_title_slug": "count-negative-numbers-in-a-sorted-matrix", "content_en": "

    Given a m x n matrix grid which is sorted in non-increasing order both row-wise and column-wise, return the number of negative numbers in grid.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: grid = [[4,3,2,-1],[3,2,1,-1],[1,1,-1,-2],[-1,-1,-2,-3]]\nOutput: 8\nExplanation: There are 8 negatives number in the matrix.\n
    \n\n

    Example 2:

    \n\n
    \nInput: grid = [[3,2],[1,0]]\nOutput: 0\n
    \n\n

    Example 3:

    \n\n
    \nInput: grid = [[1,-1],[-1,-1]]\nOutput: 3\n
    \n\n

    Example 4:

    \n\n
    \nInput: grid = [[-1]]\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= m, n <= 100
    • \n\t
    • -100 <= grid[i][j] <= 100
    • \n
    \n\n

     

    \nFollow up: Could you find an O(n + m) solution?", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u00a0m\u00a0* n\u00a0\u7684\u77e9\u9635\u00a0grid\uff0c\u77e9\u9635\u4e2d\u7684\u5143\u7d20\u65e0\u8bba\u662f\u6309\u884c\u8fd8\u662f\u6309\u5217\uff0c\u90fd\u4ee5\u975e\u9012\u589e\u987a\u5e8f\u6392\u5217\u3002\u00a0

    \n\n

    \u8bf7\u4f60\u7edf\u8ba1\u5e76\u8fd4\u56de\u00a0grid\u00a0\u4e2d \u8d1f\u6570 \u7684\u6570\u76ee\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1agrid = [[4,3,2,-1],[3,2,1,-1],[1,1,-1,-2],[-1,-1,-2,-3]]\n\u8f93\u51fa\uff1a8\n\u89e3\u91ca\uff1a\u77e9\u9635\u4e2d\u5171\u6709 8 \u4e2a\u8d1f\u6570\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1agrid = [[3,2],[1,0]]\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1agrid = [[1,-1],[-1,-1]]\n\u8f93\u51fa\uff1a3\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1agrid = [[-1]]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= m, n <= 100
    • \n\t
    • -100 <= grid[i][j] <= 100
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u53ef\u4ee5\u8bbe\u8ba1\u4e00\u4e2a\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n + m) \u7684\u89e3\u51b3\u65b9\u6848\u5417\uff1f

    \n\n

    \u00a0

    \n", "tags_en": ["Array", "Binary Search"], "tags_cn": ["\u6570\u7ec4", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countNegatives(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countNegatives(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countNegatives(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countNegatives(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countNegatives(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountNegatives(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar countNegatives = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef count_negatives(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countNegatives(_ grid: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countNegatives(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countNegatives(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countNegatives(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_negatives(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function countNegatives($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countNegatives(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-negatives grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1351](https://leetcode-cn.com/problems/count-negative-numbers-in-a-sorted-matrix)", "[\u7edf\u8ba1\u6709\u5e8f\u77e9\u9635\u4e2d\u7684\u8d1f\u6570](/solution/1300-1399/1351.Count%20Negative%20Numbers%20in%20a%20Sorted%20Matrix/README.md)", "`\u6570\u7ec4`,`\u4e8c\u5206\u67e5\u627e`", "\u7b80\u5355", ""], "md_table_row_en": ["[1351](https://leetcode.com/problems/count-negative-numbers-in-a-sorted-matrix)", "[Count Negative Numbers in a Sorted Matrix](/solution/1300-1399/1351.Count%20Negative%20Numbers%20in%20a%20Sorted%20Matrix/README_EN.md)", "`Array`,`Binary Search`", "Easy", ""]}, {"question_id": "1475", "frontend_question_id": "1373", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-sum-bst-in-binary-tree", "url_en": "https://leetcode.com/problems/maximum-sum-bst-in-binary-tree", "relative_path_cn": "/solution/1300-1399/1373.Maximum%20Sum%20BST%20in%20Binary%20Tree/README.md", "relative_path_en": "/solution/1300-1399/1373.Maximum%20Sum%20BST%20in%20Binary%20Tree/README_EN.md", "title_cn": "\u4e8c\u53c9\u641c\u7d22\u5b50\u6811\u7684\u6700\u5927\u952e\u503c\u548c", "title_en": "Maximum Sum BST in Binary Tree", "question_title_slug": "maximum-sum-bst-in-binary-tree", "content_en": "

    Given a binary tree root, the task is to return the maximum sum of all keys of any sub-tree which is also a Binary Search Tree (BST).

    \n\n

    Assume a BST is defined as follows:

    \n\n
      \n\t
    • The left subtree of a node contains only nodes with keys less than the node's key.
    • \n\t
    • The right subtree of a node contains only nodes with keys greater than the node's key.
    • \n\t
    • Both the left and right subtrees must also be binary search trees.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: root = [1,4,3,2,4,2,5,null,null,null,null,null,null,4,6]\nOutput: 20\nExplanation: Maximum sum in a valid Binary search tree is obtained in root node with key equal to 3.\n
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: root = [4,3,null,1,2]\nOutput: 2\nExplanation: Maximum sum in a valid Binary search tree is obtained in a single root node with key equal to 2.\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = [-4,-2,-5]\nOutput: 0\nExplanation: All values are negatives. Return an empty BST.\n
    \n\n

    Example 4:

    \n\n
    \nInput: root = [2,1,3]\nOutput: 6\n
    \n\n

    Example 5:

    \n\n
    \nInput: root = [5,4,8,3,null,6,3]\nOutput: 7\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The given binary tree will have between 1 and 40000 nodes.
    • \n\t
    • Each node's value is between [-4 * 10^4 , 4 * 10^4].
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u68f5\u4ee5\u00a0root\u00a0\u4e3a\u6839\u7684\u00a0\u4e8c\u53c9\u6811\u00a0\uff0c\u8bf7\u4f60\u8fd4\u56de \u4efb\u610f\u00a0\u4e8c\u53c9\u641c\u7d22\u5b50\u6811\u7684\u6700\u5927\u952e\u503c\u548c\u3002

    \n\n

    \u4e8c\u53c9\u641c\u7d22\u6811\u7684\u5b9a\u4e49\u5982\u4e0b\uff1a

    \n\n
      \n\t
    • \u4efb\u610f\u8282\u70b9\u7684\u5de6\u5b50\u6811\u4e2d\u7684\u952e\u503c\u90fd\u00a0\u5c0f\u4e8e\u00a0\u6b64\u8282\u70b9\u7684\u952e\u503c\u3002
    • \n\t
    • \u4efb\u610f\u8282\u70b9\u7684\u53f3\u5b50\u6811\u4e2d\u7684\u952e\u503c\u90fd \u5927\u4e8e\u00a0\u6b64\u8282\u70b9\u7684\u952e\u503c\u3002
    • \n\t
    • \u4efb\u610f\u8282\u70b9\u7684\u5de6\u5b50\u6811\u548c\u53f3\u5b50\u6811\u90fd\u662f\u4e8c\u53c9\u641c\u7d22\u6811\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aroot = [1,4,3,2,4,2,5,null,null,null,null,null,null,4,6]\n\u8f93\u51fa\uff1a20\n\u89e3\u91ca\uff1a\u952e\u503c\u4e3a 3 \u7684\u5b50\u6811\u662f\u548c\u6700\u5927\u7684\u4e8c\u53c9\u641c\u7d22\u6811\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aroot = [4,3,null,1,2]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u952e\u503c\u4e3a 2 \u7684\u5355\u8282\u70b9\u5b50\u6811\u662f\u548c\u6700\u5927\u7684\u4e8c\u53c9\u641c\u7d22\u6811\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [-4,-2,-5]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6240\u6709\u8282\u70b9\u952e\u503c\u90fd\u4e3a\u8d1f\u6570\uff0c\u548c\u6700\u5927\u7684\u4e8c\u53c9\u641c\u7d22\u6811\u4e3a\u7a7a\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [2,1,3]\n\u8f93\u51fa\uff1a6\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [5,4,8,3,null,6,3]\n\u8f93\u51fa\uff1a7\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6bcf\u68f5\u6811\u6709 1 \u5230 40000\u00a0\u4e2a\u8282\u70b9\u3002
    • \n\t
    • \u6bcf\u4e2a\u8282\u70b9\u7684\u952e\u503c\u5728\u00a0[-4 * 10^4\u00a0, 4 * 10^4] \u4e4b\u95f4\u3002
    • \n
    \n", "tags_en": ["Binary Search Tree", "Dynamic Programming"], "tags_cn": ["\u4e8c\u53c9\u641c\u7d22\u6811", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int maxSumBST(TreeNode* root) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int maxSumBST(TreeNode root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def maxSumBST(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def maxSumBST(self, root: TreeNode) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint maxSumBST(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int MaxSumBST(TreeNode root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar maxSumBST = function(root) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef max_sum_bst(root)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func maxSumBST(_ root: TreeNode?) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc maxSumBST(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def maxSumBST(root: TreeNode): Int = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun maxSumBST(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn max_sum_bst(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function maxSumBST($root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction maxSumBST(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (max-sum-bst root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1373](https://leetcode-cn.com/problems/maximum-sum-bst-in-binary-tree)", "[\u4e8c\u53c9\u641c\u7d22\u5b50\u6811\u7684\u6700\u5927\u952e\u503c\u548c](/solution/1300-1399/1373.Maximum%20Sum%20BST%20in%20Binary%20Tree/README.md)", "`\u4e8c\u53c9\u641c\u7d22\u6811`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1373](https://leetcode.com/problems/maximum-sum-bst-in-binary-tree)", "[Maximum Sum BST in Binary Tree](/solution/1300-1399/1373.Maximum%20Sum%20BST%20in%20Binary%20Tree/README_EN.md)", "`Binary Search Tree`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "1474", "frontend_question_id": "1372", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-zigzag-path-in-a-binary-tree", "url_en": "https://leetcode.com/problems/longest-zigzag-path-in-a-binary-tree", "relative_path_cn": "/solution/1300-1399/1372.Longest%20ZigZag%20Path%20in%20a%20Binary%20Tree/README.md", "relative_path_en": "/solution/1300-1399/1372.Longest%20ZigZag%20Path%20in%20a%20Binary%20Tree/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u4e2d\u7684\u6700\u957f\u4ea4\u9519\u8def\u5f84", "title_en": "Longest ZigZag Path in a Binary Tree", "question_title_slug": "longest-zigzag-path-in-a-binary-tree", "content_en": "

    You are given the root of a binary tree.

    \n\n

    A ZigZag path for a binary tree is defined as follow:

    \n\n
      \n\t
    • Choose any node in the binary tree and a direction (right or left).
    • \n\t
    • If the current direction is right, move to the right child of the current node; otherwise, move to the left child.
    • \n\t
    • Change the direction from right to left or from left to right.
    • \n\t
    • Repeat the second and third steps until you can't move in the tree.
    • \n
    \n\n

    Zigzag length is defined as the number of nodes visited - 1. (A single node has a length of 0).

    \n\n

    Return the longest ZigZag path contained in that tree.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,null,1,1,1,null,null,1,1,null,1,null,null,null,1,null,1]\nOutput: 3\nExplanation: Longest ZigZag path in blue nodes (right -> left -> right).\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [1,1,1,null,1,null,null,1,1,null,1]\nOutput: 4\nExplanation: Longest ZigZag path in blue nodes (left -> right -> left -> right).\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = [1]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 5 * 104].
    • \n\t
    • 1 <= Node.val <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u68f5\u4ee5 root \u4e3a\u6839\u7684\u4e8c\u53c9\u6811\uff0c\u4e8c\u53c9\u6811\u4e2d\u7684\u4ea4\u9519\u8def\u5f84\u5b9a\u4e49\u5982\u4e0b\uff1a

    \n\n
      \n\t
    • \u9009\u62e9\u4e8c\u53c9\u6811\u4e2d \u4efb\u610f \u8282\u70b9\u548c\u4e00\u4e2a\u65b9\u5411\uff08\u5de6\u6216\u8005\u53f3\uff09\u3002
    • \n\t
    • \u5982\u679c\u524d\u8fdb\u65b9\u5411\u4e3a\u53f3\uff0c\u90a3\u4e48\u79fb\u52a8\u5230\u5f53\u524d\u8282\u70b9\u7684\u7684\u53f3\u5b50\u8282\u70b9\uff0c\u5426\u5219\u79fb\u52a8\u5230\u5b83\u7684\u5de6\u5b50\u8282\u70b9\u3002
    • \n\t
    • \u6539\u53d8\u524d\u8fdb\u65b9\u5411\uff1a\u5de6\u53d8\u53f3\u6216\u8005\u53f3\u53d8\u5de6\u3002
    • \n\t
    • \u91cd\u590d\u7b2c\u4e8c\u6b65\u548c\u7b2c\u4e09\u6b65\uff0c\u76f4\u5230\u4f60\u5728\u6811\u4e2d\u65e0\u6cd5\u7ee7\u7eed\u79fb\u52a8\u3002
    • \n
    \n\n

    \u4ea4\u9519\u8def\u5f84\u7684\u957f\u5ea6\u5b9a\u4e49\u4e3a\uff1a\u8bbf\u95ee\u8fc7\u7684\u8282\u70b9\u6570\u76ee - 1\uff08\u5355\u4e2a\u8282\u70b9\u7684\u8def\u5f84\u957f\u5ea6\u4e3a 0 \uff09\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u7ed9\u5b9a\u6811\u4e2d\u6700\u957f \u4ea4\u9519\u8def\u5f84 \u7684\u957f\u5ea6\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1aroot = [1,null,1,1,1,null,null,1,1,null,1,null,null,null,1,null,1]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u84dd\u8272\u8282\u70b9\u4e3a\u6811\u4e2d\u6700\u957f\u4ea4\u9519\u8def\u5f84\uff08\u53f3 -> \u5de6 -> \u53f3\uff09\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1aroot = [1,1,1,null,1,null,null,1,1,null,1]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u84dd\u8272\u8282\u70b9\u4e3a\u6811\u4e2d\u6700\u957f\u4ea4\u9519\u8def\u5f84\uff08\u5de6 -> \u53f3 -> \u5de6 -> \u53f3\uff09\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aroot = [1]\n\u8f93\u51fa\uff1a0\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6bcf\u68f5\u6811\u6700\u591a\u6709 50000 \u4e2a\u8282\u70b9\u3002
    • \n\t
    • \u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u5728 [1, 100] \u4e4b\u95f4\u3002
    • \n
    \n", "tags_en": ["Tree", "Dynamic Programming"], "tags_cn": ["\u6811", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int longestZigZag(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int longestZigZag(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def longestZigZag(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def longestZigZag(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint longestZigZag(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int LongestZigZag(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar longestZigZag = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef longest_zig_zag(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func longestZigZag(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc longestZigZag(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def longestZigZag(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun longestZigZag(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn longest_zig_zag(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function longestZigZag($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction longestZigZag(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (longest-zig-zag root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1372](https://leetcode-cn.com/problems/longest-zigzag-path-in-a-binary-tree)", "[\u4e8c\u53c9\u6811\u4e2d\u7684\u6700\u957f\u4ea4\u9519\u8def\u5f84](/solution/1300-1399/1372.Longest%20ZigZag%20Path%20in%20a%20Binary%20Tree/README.md)", "`\u6811`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1372](https://leetcode.com/problems/longest-zigzag-path-in-a-binary-tree)", "[Longest ZigZag Path in a Binary Tree](/solution/1300-1399/1372.Longest%20ZigZag%20Path%20in%20a%20Binary%20Tree/README_EN.md)", "`Tree`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "1473", "frontend_question_id": "1371", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-the-longest-substring-containing-vowels-in-even-counts", "url_en": "https://leetcode.com/problems/find-the-longest-substring-containing-vowels-in-even-counts", "relative_path_cn": "/solution/1300-1399/1371.Find%20the%20Longest%20Substring%20Containing%20Vowels%20in%20Even%20Counts/README.md", "relative_path_en": "/solution/1300-1399/1371.Find%20the%20Longest%20Substring%20Containing%20Vowels%20in%20Even%20Counts/README_EN.md", "title_cn": "\u6bcf\u4e2a\u5143\u97f3\u5305\u542b\u5076\u6570\u6b21\u7684\u6700\u957f\u5b50\u5b57\u7b26\u4e32", "title_en": "Find the Longest Substring Containing Vowels in Even Counts", "question_title_slug": "find-the-longest-substring-containing-vowels-in-even-counts", "content_en": "

    Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "eleetminicoworoep"\nOutput: 13\nExplanation: The longest substring is "leetminicowor" which contains two each of the vowels: e, i and o and zero of the vowels: a and u.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "leetcodeisgreat"\nOutput: 5\nExplanation: The longest substring is "leetc" which contains two e's.\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "bcbcbc"\nOutput: 6\nExplanation: In this case, the given string "bcbcbc" is the longest because all vowels: a, e, i, o and u appear zero times.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 5 x 10^5
    • \n\t
    • s contains only lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \uff0c\u8bf7\u4f60\u8fd4\u56de\u6ee1\u8db3\u4ee5\u4e0b\u6761\u4ef6\u7684\u6700\u957f\u5b50\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\uff1a\u6bcf\u4e2a\u5143\u97f3\u5b57\u6bcd\uff0c\u5373 'a'\uff0c'e'\uff0c'i'\uff0c'o'\uff0c'u' \uff0c\u5728\u5b50\u5b57\u7b26\u4e32\u4e2d\u90fd\u6070\u597d\u51fa\u73b0\u4e86\u5076\u6570\u6b21\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = "eleetminicoworoep"\n\u8f93\u51fa\uff1a13\n\u89e3\u91ca\uff1a\u6700\u957f\u5b50\u5b57\u7b26\u4e32\u662f "leetminicowor" \uff0c\u5b83\u5305\u542b e\uff0ci\uff0co \u5404 2 \u4e2a\uff0c\u4ee5\u53ca 0 \u4e2a a\uff0cu \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = "leetcodeisgreat"\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u6700\u957f\u5b50\u5b57\u7b26\u4e32\u662f "leetc" \uff0c\u5176\u4e2d\u5305\u542b 2 \u4e2a e \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = "bcbcbc"\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u5b57\u7b26\u4e32 "bcbcbc" \u672c\u8eab\u5c31\u662f\u6700\u957f\u7684\uff0c\u56e0\u4e3a\u6240\u6709\u7684\u5143\u97f3 a\uff0ce\uff0ci\uff0co\uff0cu \u90fd\u51fa\u73b0\u4e86 0 \u6b21\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 5 x 10^5
    • \n\t
    • s \u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findTheLongestSubstring(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findTheLongestSubstring(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findTheLongestSubstring(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findTheLongestSubstring(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findTheLongestSubstring(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindTheLongestSubstring(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar findTheLongestSubstring = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef find_the_longest_substring(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findTheLongestSubstring(_ s: String) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findTheLongestSubstring(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findTheLongestSubstring(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findTheLongestSubstring(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_the_longest_substring(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function findTheLongestSubstring($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findTheLongestSubstring(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-the-longest-substring s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1371](https://leetcode-cn.com/problems/find-the-longest-substring-containing-vowels-in-even-counts)", "[\u6bcf\u4e2a\u5143\u97f3\u5305\u542b\u5076\u6570\u6b21\u7684\u6700\u957f\u5b50\u5b57\u7b26\u4e32](/solution/1300-1399/1371.Find%20the%20Longest%20Substring%20Containing%20Vowels%20in%20Even%20Counts/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1371](https://leetcode.com/problems/find-the-longest-substring-containing-vowels-in-even-counts)", "[Find the Longest Substring Containing Vowels in Even Counts](/solution/1300-1399/1371.Find%20the%20Longest%20Substring%20Containing%20Vowels%20in%20Even%20Counts/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "1472", "frontend_question_id": "1370", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/increasing-decreasing-string", "url_en": "https://leetcode.com/problems/increasing-decreasing-string", "relative_path_cn": "/solution/1300-1399/1370.Increasing%20Decreasing%20String/README.md", "relative_path_en": "/solution/1300-1399/1370.Increasing%20Decreasing%20String/README_EN.md", "title_cn": "\u4e0a\u5347\u4e0b\u964d\u5b57\u7b26\u4e32", "title_en": "Increasing Decreasing String", "question_title_slug": "increasing-decreasing-string", "content_en": "

    Given a string s. You should re-order the string using the following algorithm:

    \n\n
      \n\t
    1. Pick the smallest character from s and append it to the result.
    2. \n\t
    3. Pick the smallest character from s which is greater than the last appended character to the result and append it.
    4. \n\t
    5. Repeat step 2 until you cannot pick more characters.
    6. \n\t
    7. Pick the largest character from s and append it to the result.
    8. \n\t
    9. Pick the largest character from s which is smaller than the last appended character to the result and append it.
    10. \n\t
    11. Repeat step 5 until you cannot pick more characters.
    12. \n\t
    13. Repeat the steps from 1 to 6 until you pick all characters from s.
    14. \n
    \n\n

    In each step, If the smallest or the largest character appears more than once you can choose any occurrence and append it to the result.

    \n\n

    Return the result string after sorting s with this algorithm.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "aaaabbbbcccc"\nOutput: "abccbaabccba"\nExplanation: After steps 1, 2 and 3 of the first iteration, result = "abc"\nAfter steps 4, 5 and 6 of the first iteration, result = "abccba"\nFirst iteration is done. Now s = "aabbcc" and we go back to step 1\nAfter steps 1, 2 and 3 of the second iteration, result = "abccbaabc"\nAfter steps 4, 5 and 6 of the second iteration, result = "abccbaabccba"\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "rat"\nOutput: "art"\nExplanation: The word "rat" becomes "art" after re-ordering it with the mentioned algorithm.\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "leetcode"\nOutput: "cdelotee"\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "ggggggg"\nOutput: "ggggggg"\n
    \n\n

    Example 5:

    \n\n
    \nInput: s = "spo"\nOutput: "ops"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 500
    • \n\t
    • s contains only lower-case English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \uff0c\u8bf7\u4f60\u6839\u636e\u4e0b\u9762\u7684\u7b97\u6cd5\u91cd\u65b0\u6784\u9020\u5b57\u7b26\u4e32\uff1a

    \n\n
      \n\t
    1. \u4ece s \u4e2d\u9009\u51fa \u6700\u5c0f \u7684\u5b57\u7b26\uff0c\u5c06\u5b83 \u63a5\u5728 \u7ed3\u679c\u5b57\u7b26\u4e32\u7684\u540e\u9762\u3002
    2. \n\t
    3. \u4ece s \u5269\u4f59\u5b57\u7b26\u4e2d\u9009\u51fa \u6700\u5c0f \u7684\u5b57\u7b26\uff0c\u4e14\u8be5\u5b57\u7b26\u6bd4\u4e0a\u4e00\u4e2a\u6dfb\u52a0\u7684\u5b57\u7b26\u5927\uff0c\u5c06\u5b83 \u63a5\u5728 \u7ed3\u679c\u5b57\u7b26\u4e32\u540e\u9762\u3002
    4. \n\t
    5. \u91cd\u590d\u6b65\u9aa4 2 \uff0c\u76f4\u5230\u4f60\u6ca1\u6cd5\u4ece s \u4e2d\u9009\u62e9\u5b57\u7b26\u3002
    6. \n\t
    7. \u4ece s \u4e2d\u9009\u51fa \u6700\u5927 \u7684\u5b57\u7b26\uff0c\u5c06\u5b83 \u63a5\u5728 \u7ed3\u679c\u5b57\u7b26\u4e32\u7684\u540e\u9762\u3002
    8. \n\t
    9. \u4ece s \u5269\u4f59\u5b57\u7b26\u4e2d\u9009\u51fa \u6700\u5927 \u7684\u5b57\u7b26\uff0c\u4e14\u8be5\u5b57\u7b26\u6bd4\u4e0a\u4e00\u4e2a\u6dfb\u52a0\u7684\u5b57\u7b26\u5c0f\uff0c\u5c06\u5b83 \u63a5\u5728 \u7ed3\u679c\u5b57\u7b26\u4e32\u540e\u9762\u3002
    10. \n\t
    11. \u91cd\u590d\u6b65\u9aa4 5 \uff0c\u76f4\u5230\u4f60\u6ca1\u6cd5\u4ece s \u4e2d\u9009\u62e9\u5b57\u7b26\u3002
    12. \n\t
    13. \u91cd\u590d\u6b65\u9aa4 1 \u5230 6 \uff0c\u76f4\u5230 s \u4e2d\u6240\u6709\u5b57\u7b26\u90fd\u5df2\u7ecf\u88ab\u9009\u8fc7\u3002
    14. \n
    \n\n

    \u5728\u4efb\u4f55\u4e00\u6b65\u4e2d\uff0c\u5982\u679c\u6700\u5c0f\u6216\u8005\u6700\u5927\u5b57\u7b26\u4e0d\u6b62\u4e00\u4e2a \uff0c\u4f60\u53ef\u4ee5\u9009\u62e9\u5176\u4e2d\u4efb\u610f\u4e00\u4e2a\uff0c\u5e76\u5c06\u5176\u6dfb\u52a0\u5230\u7ed3\u679c\u5b57\u7b26\u4e32\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u5c06 s \u4e2d\u5b57\u7b26\u91cd\u65b0\u6392\u5e8f\u540e\u7684 \u7ed3\u679c\u5b57\u7b26\u4e32 \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1as = "aaaabbbbcccc"\n\u8f93\u51fa\uff1a"abccbaabccba"\n\u89e3\u91ca\uff1a\u7b2c\u4e00\u8f6e\u7684\u6b65\u9aa4 1\uff0c2\uff0c3 \u540e\uff0c\u7ed3\u679c\u5b57\u7b26\u4e32\u4e3a result = "abc"\n\u7b2c\u4e00\u8f6e\u7684\u6b65\u9aa4 4\uff0c5\uff0c6 \u540e\uff0c\u7ed3\u679c\u5b57\u7b26\u4e32\u4e3a result = "abccba"\n\u7b2c\u4e00\u8f6e\u7ed3\u675f\uff0c\u73b0\u5728 s = "aabbcc" \uff0c\u6211\u4eec\u518d\u6b21\u56de\u5230\u6b65\u9aa4 1\n\u7b2c\u4e8c\u8f6e\u7684\u6b65\u9aa4 1\uff0c2\uff0c3 \u540e\uff0c\u7ed3\u679c\u5b57\u7b26\u4e32\u4e3a result = "abccbaabc"\n\u7b2c\u4e8c\u8f6e\u7684\u6b65\u9aa4 4\uff0c5\uff0c6 \u540e\uff0c\u7ed3\u679c\u5b57\u7b26\u4e32\u4e3a result = "abccbaabccba"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1as = "rat"\n\u8f93\u51fa\uff1a"art"\n\u89e3\u91ca\uff1a\u5355\u8bcd "rat" \u5728\u4e0a\u8ff0\u7b97\u6cd5\u91cd\u6392\u5e8f\u4ee5\u540e\u53d8\u6210 "art"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1as = "leetcode"\n\u8f93\u51fa\uff1a"cdelotee"\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1as = "ggggggg"\n\u8f93\u51fa\uff1a"ggggggg"\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1as = "spo"\n\u8f93\u51fa\uff1a"ops"\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 500
    • \n\t
    • s \u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    • \n
    \n", "tags_en": ["Sort", "String"], "tags_cn": ["\u6392\u5e8f", "\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string sortString(string s) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String sortString(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def sortString(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def sortString(self, s: str) -> str:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * sortString(char * s){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string SortString(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar sortString = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef sort_string(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func sortString(_ s: String) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func sortString(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def sortString(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun sortString(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sort_string(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function sortString($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function sortString(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (sort-string s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1370](https://leetcode-cn.com/problems/increasing-decreasing-string)", "[\u4e0a\u5347\u4e0b\u964d\u5b57\u7b26\u4e32](/solution/1300-1399/1370.Increasing%20Decreasing%20String/README.md)", "`\u6392\u5e8f`,`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1370](https://leetcode.com/problems/increasing-decreasing-string)", "[Increasing Decreasing String](/solution/1300-1399/1370.Increasing%20Decreasing%20String/README_EN.md)", "`Sort`,`String`", "Easy", ""]}, {"question_id": "1471", "frontend_question_id": "1349", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-students-taking-exam", "url_en": "https://leetcode.com/problems/maximum-students-taking-exam", "relative_path_cn": "/solution/1300-1399/1349.Maximum%20Students%20Taking%20Exam/README.md", "relative_path_en": "/solution/1300-1399/1349.Maximum%20Students%20Taking%20Exam/README_EN.md", "title_cn": "\u53c2\u52a0\u8003\u8bd5\u7684\u6700\u5927\u5b66\u751f\u6570", "title_en": "Maximum Students Taking Exam", "question_title_slug": "maximum-students-taking-exam", "content_en": "

    Given a m * n matrix seats  that represent seats distributions in a classroom. If a seat is broken, it is denoted by '#' character otherwise it is denoted by a '.' character.

    \n\n

    Students can see the answers of those sitting next to the left, right, upper left and upper right, but he cannot see the answers of the student sitting directly in front or behind him. Return the maximum number of students that can take the exam together without any cheating being possible..

    \n\n

    Students must be placed in seats in good condition.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: seats = [["#",".","#","#",".","#"],\n                [".","#","#","#","#","."],\n                ["#",".","#","#",".","#"]]\nOutput: 4\nExplanation: Teacher can place 4 students in available seats so they don't cheat on the exam. \n
    \n\n

    Example 2:

    \n\n
    \nInput: seats = [[".","#"],\n                ["#","#"],\n                ["#","."],\n                ["#","#"],\n                [".","#"]]\nOutput: 3\nExplanation: Place all students in available seats. \n\n
    \n\n

    Example 3:

    \n\n
    \nInput: seats = [["#",".",".",".","#"],\n                [".","#",".","#","."],\n                [".",".","#",".","."],\n                [".","#",".","#","."],\n                ["#",".",".",".","#"]]\nOutput: 10\nExplanation: Place students in available seats in column 1, 3 and 5.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • seats contains only characters '.' and'#'.
    • \n\t
    • m == seats.length
    • \n\t
    • n == seats[i].length
    • \n\t
    • 1 <= m <= 8
    • \n\t
    • 1 <= n <= 8
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a m * n \u7684\u77e9\u9635 seats \u8868\u793a\u6559\u5ba4\u4e2d\u7684\u5ea7\u4f4d\u5206\u5e03\u3002\u5982\u679c\u5ea7\u4f4d\u662f\u574f\u7684\uff08\u4e0d\u53ef\u7528\uff09\uff0c\u5c31\u7528 '#' \u8868\u793a\uff1b\u5426\u5219\uff0c\u7528 '.' \u8868\u793a\u3002

    \n\n

    \u5b66\u751f\u53ef\u4ee5\u770b\u5230\u5de6\u4fa7\u3001\u53f3\u4fa7\u3001\u5de6\u4e0a\u3001\u53f3\u4e0a\u8fd9\u56db\u4e2a\u65b9\u5411\u4e0a\u7d27\u90bb\u4ed6\u7684\u5b66\u751f\u7684\u7b54\u5377\uff0c\u4f46\u662f\u770b\u4e0d\u5230\u76f4\u63a5\u5750\u5728\u4ed6\u524d\u9762\u6216\u8005\u540e\u9762\u7684\u5b66\u751f\u7684\u7b54\u5377\u3002\u8bf7\u4f60\u8ba1\u7b97\u5e76\u8fd4\u56de\u8be5\u8003\u573a\u53ef\u4ee5\u5bb9\u7eb3\u7684\u4e00\u8d77\u53c2\u52a0\u8003\u8bd5\u4e14\u65e0\u6cd5\u4f5c\u5f0a\u7684\u6700\u5927\u5b66\u751f\u4eba\u6570\u3002

    \n\n

    \u5b66\u751f\u5fc5\u987b\u5750\u5728\u72b6\u51b5\u826f\u597d\u7684\u5ea7\u4f4d\u4e0a\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \n\n
    \u8f93\u5165\uff1aseats = [["#",".","#","#",".","#"],\n              [".","#","#","#","#","."],\n              ["#",".","#","#",".","#"]]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u6559\u5e08\u53ef\u4ee5\u8ba9 4 \u4e2a\u5b66\u751f\u5750\u5728\u53ef\u7528\u7684\u5ea7\u4f4d\u4e0a\uff0c\u8fd9\u6837\u4ed6\u4eec\u5c31\u65e0\u6cd5\u5728\u8003\u8bd5\u4e2d\u4f5c\u5f0a\u3002 \n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aseats = [[".","#"],\n              ["#","#"],\n              ["#","."],\n              ["#","#"],\n              [".","#"]]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u8ba9\u6240\u6709\u5b66\u751f\u5750\u5728\u53ef\u7528\u7684\u5ea7\u4f4d\u4e0a\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aseats = [["#",".",".",".","#"],\n              [".","#",".","#","."],\n              [".",".","#",".","."],\n              [".","#",".","#","."],\n              ["#",".",".",".","#"]]\n\u8f93\u51fa\uff1a10\n\u89e3\u91ca\uff1a\u8ba9\u5b66\u751f\u5750\u5728\u7b2c 1\u30013 \u548c 5 \u5217\u7684\u53ef\u7528\u5ea7\u4f4d\u4e0a\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • seats \u53ea\u5305\u542b\u5b57\u7b26 '.' \u548c'#'
    • \n\t
    • m == seats.length
    • \n\t
    • n == seats[i].length
    • \n\t
    • 1 <= m <= 8
    • \n\t
    • 1 <= n <= 8
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxStudents(vector>& seats) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxStudents(char[][] seats) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxStudents(self, seats):\n \"\"\"\n :type seats: List[List[str]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxStudents(self, seats: List[List[str]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxStudents(char** seats, int seatsSize, int* seatsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxStudents(char[][] seats) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {character[][]} seats\n * @return {number}\n */\nvar maxStudents = function(seats) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Character[][]} seats\n# @return {Integer}\ndef max_students(seats)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxStudents(_ seats: [[Character]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxStudents(seats [][]byte) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxStudents(seats: Array[Array[Char]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxStudents(seats: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_students(seats: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $seats\n * @return Integer\n */\n function maxStudents($seats) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxStudents(seats: string[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-students seats)\n (-> (listof (listof char?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1349](https://leetcode-cn.com/problems/maximum-students-taking-exam)", "[\u53c2\u52a0\u8003\u8bd5\u7684\u6700\u5927\u5b66\u751f\u6570](/solution/1300-1399/1349.Maximum%20Students%20Taking%20Exam/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1349](https://leetcode.com/problems/maximum-students-taking-exam)", "[Maximum Students Taking Exam](/solution/1300-1399/1349.Maximum%20Students%20Taking%20Exam/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1470", "frontend_question_id": "1348", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/tweet-counts-per-frequency", "url_en": "https://leetcode.com/problems/tweet-counts-per-frequency", "relative_path_cn": "/solution/1300-1399/1348.Tweet%20Counts%20Per%20Frequency/README.md", "relative_path_en": "/solution/1300-1399/1348.Tweet%20Counts%20Per%20Frequency/README_EN.md", "title_cn": "\u63a8\u6587\u8ba1\u6570", "title_en": "Tweet Counts Per Frequency", "question_title_slug": "tweet-counts-per-frequency", "content_en": "

    A social media company is trying to monitor activity on their site by analyzing the number of tweets that occur in select periods of time. These periods can be partitioned into smaller time chunks based on a certain frequency (every minute, hour, or day).

    \n\n

    For example, the period [10, 10000] (in seconds) would be partitioned into the following time chunks with these frequencies:

    \n\n
      \n\t
    • Every minute (60-second chunks): [10,69], [70,129], [130,189], ..., [9970,10000]
    • \n\t
    • Every hour (3600-second chunks): [10,3609], [3610,7209], [7210,10000]
    • \n\t
    • Every day (86400-second chunks): [10,10000]
    • \n
    \n\n

    Notice that the last chunk may be shorter than the specified frequency's chunk size and will always end with the end time of the period (10000 in the above example).

    \n\n

    Design and implement an API to help the company with their analysis.

    \n\n

    Implement the TweetCounts class:

    \n\n
      \n\t
    • TweetCounts() Initializes the TweetCounts object.
    • \n\t
    • void recordTweet(String tweetName, int time) Stores the tweetName at the recorded time (in seconds).
    • \n\t
    • List<Integer> getTweetCountsPerFrequency(String freq, String tweetName, int startTime, int endTime) Returns a list of integers representing the number of tweets with tweetName in each time chunk for the given period of time [startTime, endTime] (in seconds) and frequency freq.\n\t
        \n\t\t
      • freq is one of "minute", "hour", or "day" representing a frequency of every minute, hour, or day respectively.
      • \n\t
      \n\t
    • \n
    \n\n

     

    \n

    Example:

    \n\n
    \nInput\n["TweetCounts","recordTweet","recordTweet","recordTweet","getTweetCountsPerFrequency","getTweetCountsPerFrequency","recordTweet","getTweetCountsPerFrequency"]\n[[],["tweet3",0],["tweet3",60],["tweet3",10],["minute","tweet3",0,59],["minute","tweet3",0,60],["tweet3",120],["hour","tweet3",0,210]]\n\nOutput\n[null,null,null,null,[2],[2,1],null,[4]]\n\nExplanation\nTweetCounts tweetCounts = new TweetCounts();\ntweetCounts.recordTweet("tweet3", 0);                              // New tweet "tweet3" at time 0\ntweetCounts.recordTweet("tweet3", 60);                             // New tweet "tweet3" at time 60\ntweetCounts.recordTweet("tweet3", 10);                             // New tweet "tweet3" at time 10\ntweetCounts.getTweetCountsPerFrequency("minute", "tweet3", 0, 59); // return [2]; chunk [0,59] had 2 tweets\ntweetCounts.getTweetCountsPerFrequency("minute", "tweet3", 0, 60); // return [2,1]; chunk [0,59] had 2 tweets, chunk [60,60] had 1 tweet\ntweetCounts.recordTweet("tweet3", 120);                            // New tweet "tweet3" at time 120\ntweetCounts.getTweetCountsPerFrequency("hour", "tweet3", 0, 210);  // return [4]; chunk [0,210] had 4 tweets\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= time, startTime, endTime <= 109
    • \n\t
    • 0 <= endTime - startTime <= 104
    • \n\t
    • There will be at most 104 calls in total to recordTweet and getTweetCountsPerFrequency.
    • \n
    \n", "content_cn": "

    \u8bf7\u4f60\u5b9e\u73b0\u4e00\u4e2a\u80fd\u591f\u652f\u6301\u4ee5\u4e0b\u4e24\u79cd\u65b9\u6cd5\u7684\u63a8\u6587\u8ba1\u6570\u7c7b TweetCounts\uff1a

    \n\n

    1. recordTweet(string tweetName, int time)

    \n\n
      \n\t
    • \u8bb0\u5f55\u63a8\u6587\u53d1\u5e03\u60c5\u51b5\uff1a\u7528\u6237 tweetName \u5728 time\uff08\u4ee5 \u79d2 \u4e3a\u5355\u4f4d\uff09\u65f6\u523b\u53d1\u5e03\u4e86\u4e00\u6761\u63a8\u6587\u3002
    • \n
    \n\n

    2. getTweetCountsPerFrequency(string freq, string tweetName, int startTime, int endTime)

    \n\n
      \n\t
    • \u8fd4\u56de\u4ece\u5f00\u59cb\u65f6\u95f4 startTime\uff08\u4ee5 \u79d2 \u4e3a\u5355\u4f4d\uff09\u5230\u7ed3\u675f\u65f6\u95f4 endTime\uff08\u4ee5 \u79d2 \u4e3a\u5355\u4f4d\uff09\u5185\uff0c\u6bcf \u5206 minute\uff0c\u65f6 hour \u6216\u8005 \u65e5 day \uff08\u53d6\u51b3\u4e8e freq\uff09\u5185\u6307\u5b9a\u7528\u6237 tweetName \u53d1\u5e03\u7684\u63a8\u6587\u603b\u6570\u3002
    • \n\t
    • freq \u7684\u503c\u59cb\u7ec8\u4e3a \u5206 minute\uff0c\u65f6 hour \u6216\u8005 \u65e5 day \u4e4b\u4e00\uff0c\u8868\u793a\u83b7\u53d6\u6307\u5b9a\u7528\u6237 tweetName \u53d1\u5e03\u63a8\u6587\u6b21\u6570\u7684\u65f6\u95f4\u95f4\u9694\u3002
    • \n\t
    • \u7b2c\u4e00\u4e2a\u65f6\u95f4\u95f4\u9694\u59cb\u7ec8\u4ece startTime \u5f00\u59cb\uff0c\u56e0\u6b64\u65f6\u95f4\u95f4\u9694\u4e3a [startTime, startTime + delta*1>,  [startTime + delta*1, startTime + delta*2>, [startTime + delta*2, startTime + delta*3>, ... , [startTime + delta*i, min(startTime + delta*(i+1), endTime + 1)>\uff0c\u5176\u4e2d i \u548c delta\uff08\u53d6\u51b3\u4e8e freq\uff09\u90fd\u662f\u975e\u8d1f\u6574\u6570\u3002
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1a\n["TweetCounts","recordTweet","recordTweet","recordTweet","getTweetCountsPerFrequency","getTweetCountsPerFrequency","recordTweet","getTweetCountsPerFrequency"]\n[[],["tweet3",0],["tweet3",60],["tweet3",10],["minute","tweet3",0,59],["minute","tweet3",0,60],["tweet3",120],["hour","tweet3",0,210]]\n\n\u8f93\u51fa\uff1a\n[null,null,null,null,[2],[2,1],null,[4]]\n\n\u89e3\u91ca\uff1a\nTweetCounts tweetCounts = new TweetCounts();\ntweetCounts.recordTweet("tweet3", 0);\ntweetCounts.recordTweet("tweet3", 60);\ntweetCounts.recordTweet("tweet3", 10);                             // "tweet3" \u53d1\u5e03\u63a8\u6587\u7684\u65f6\u95f4\u5206\u522b\u662f 0, 10 \u548c 60 \u3002\ntweetCounts.getTweetCountsPerFrequency("minute", "tweet3", 0, 59); // \u8fd4\u56de [2]\u3002\u7edf\u8ba1\u9891\u7387\u662f\u6bcf\u5206\u949f\uff0860 \u79d2\uff09\uff0c\u56e0\u6b64\u53ea\u6709\u4e00\u4e2a\u6709\u6548\u65f6\u95f4\u95f4\u9694 [0,60> - > 2 \u6761\u63a8\u6587\u3002\ntweetCounts.getTweetCountsPerFrequency("minute", "tweet3", 0, 60); // \u8fd4\u56de [2,1]\u3002\u7edf\u8ba1\u9891\u7387\u662f\u6bcf\u5206\u949f\uff0860 \u79d2\uff09\uff0c\u56e0\u6b64\u6709\u4e24\u4e2a\u6709\u6548\u65f6\u95f4\u95f4\u9694 1) [0,60> - > 2 \u6761\u63a8\u6587\uff0c\u548c 2) [60,61> - > 1 \u6761\u63a8\u6587\u3002 \ntweetCounts.recordTweet("tweet3", 120);                            // "tweet3" \u53d1\u5e03\u63a8\u6587\u7684\u65f6\u95f4\u5206\u522b\u662f 0, 10, 60 \u548c 120 \u3002\ntweetCounts.getTweetCountsPerFrequency("hour", "tweet3", 0, 210);  // \u8fd4\u56de [4]\u3002\u7edf\u8ba1\u9891\u7387\u662f\u6bcf\u5c0f\u65f6\uff083600 \u79d2\uff09\uff0c\u56e0\u6b64\u53ea\u6709\u4e00\u4e2a\u6709\u6548\u65f6\u95f4\u95f4\u9694 [0,211> - > 4 \u6761\u63a8\u6587\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u540c\u65f6\u8003\u8651 recordTweet \u548c getTweetCountsPerFrequency\uff0c\u6700\u591a\u6709 10000 \u6b21\u64cd\u4f5c\u3002
    • \n\t
    • 0 <= time, startTime, endTime <= 10^9
    • \n\t
    • 0 <= endTime - startTime <= 10^4
    • \n
    \n", "tags_en": ["Design"], "tags_cn": ["\u8bbe\u8ba1"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class TweetCounts {\npublic:\n TweetCounts() {\n\n }\n \n void recordTweet(string tweetName, int time) {\n\n }\n \n vector getTweetCountsPerFrequency(string freq, string tweetName, int startTime, int endTime) {\n\n }\n};\n\n/**\n * Your TweetCounts object will be instantiated and called as such:\n * TweetCounts* obj = new TweetCounts();\n * obj->recordTweet(tweetName,time);\n * vector param_2 = obj->getTweetCountsPerFrequency(freq,tweetName,startTime,endTime);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class TweetCounts {\n\n public TweetCounts() {\n\n }\n \n public void recordTweet(String tweetName, int time) {\n\n }\n \n public List getTweetCountsPerFrequency(String freq, String tweetName, int startTime, int endTime) {\n\n }\n}\n\n/**\n * Your TweetCounts object will be instantiated and called as such:\n * TweetCounts obj = new TweetCounts();\n * obj.recordTweet(tweetName,time);\n * List param_2 = obj.getTweetCountsPerFrequency(freq,tweetName,startTime,endTime);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class TweetCounts(object):\n\n def __init__(self):\n\n\n def recordTweet(self, tweetName, time):\n \"\"\"\n :type tweetName: str\n :type time: int\n :rtype: None\n \"\"\"\n\n\n def getTweetCountsPerFrequency(self, freq, tweetName, startTime, endTime):\n \"\"\"\n :type freq: str\n :type tweetName: str\n :type startTime: int\n :type endTime: int\n :rtype: List[int]\n \"\"\"\n\n\n\n# Your TweetCounts object will be instantiated and called as such:\n# obj = TweetCounts()\n# obj.recordTweet(tweetName,time)\n# param_2 = obj.getTweetCountsPerFrequency(freq,tweetName,startTime,endTime)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class TweetCounts:\n\n def __init__(self):\n\n\n def recordTweet(self, tweetName: str, time: int) -> None:\n\n\n def getTweetCountsPerFrequency(self, freq: str, tweetName: str, startTime: int, endTime: int) -> List[int]:\n\n\n\n# Your TweetCounts object will be instantiated and called as such:\n# obj = TweetCounts()\n# obj.recordTweet(tweetName,time)\n# param_2 = obj.getTweetCountsPerFrequency(freq,tweetName,startTime,endTime)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} TweetCounts;\n\n\nTweetCounts* tweetCountsCreate() {\n \n}\n\nvoid tweetCountsRecordTweet(TweetCounts* obj, char * tweetName, int time) {\n \n}\n\nint* tweetCountsGetTweetCountsPerFrequency(TweetCounts* obj, char * freq, char * tweetName, int startTime, int endTime, int* retSize) {\n \n}\n\nvoid tweetCountsFree(TweetCounts* obj) {\n \n}\n\n/**\n * Your TweetCounts struct will be instantiated and called as such:\n * TweetCounts* obj = tweetCountsCreate();\n * tweetCountsRecordTweet(obj, tweetName, time);\n \n * int* param_2 = tweetCountsGetTweetCountsPerFrequency(obj, freq, tweetName, startTime, endTime, retSize);\n \n * tweetCountsFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class TweetCounts {\n\n public TweetCounts() {\n\n }\n \n public void RecordTweet(string tweetName, int time) {\n\n }\n \n public IList GetTweetCountsPerFrequency(string freq, string tweetName, int startTime, int endTime) {\n\n }\n}\n\n/**\n * Your TweetCounts object will be instantiated and called as such:\n * TweetCounts obj = new TweetCounts();\n * obj.RecordTweet(tweetName,time);\n * IList param_2 = obj.GetTweetCountsPerFrequency(freq,tweetName,startTime,endTime);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "\nvar TweetCounts = function() {\n\n};\n\n/** \n * @param {string} tweetName \n * @param {number} time\n * @return {void}\n */\nTweetCounts.prototype.recordTweet = function(tweetName, time) {\n\n};\n\n/** \n * @param {string} freq \n * @param {string} tweetName \n * @param {number} startTime \n * @param {number} endTime\n * @return {number[]}\n */\nTweetCounts.prototype.getTweetCountsPerFrequency = function(freq, tweetName, startTime, endTime) {\n\n};\n\n/**\n * Your TweetCounts object will be instantiated and called as such:\n * var obj = new TweetCounts()\n * obj.recordTweet(tweetName,time)\n * var param_2 = obj.getTweetCountsPerFrequency(freq,tweetName,startTime,endTime)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class TweetCounts\n def initialize()\n\n end\n\n\n=begin\n :type tweet_name: String\n :type time: Integer\n :rtype: Void\n=end\n def record_tweet(tweet_name, time)\n\n end\n\n\n=begin\n :type freq: String\n :type tweet_name: String\n :type start_time: Integer\n :type end_time: Integer\n :rtype: Integer[]\n=end\n def get_tweet_counts_per_frequency(freq, tweet_name, start_time, end_time)\n\n end\n\n\nend\n\n# Your TweetCounts object will be instantiated and called as such:\n# obj = TweetCounts.new()\n# obj.record_tweet(tweet_name, time)\n# param_2 = obj.get_tweet_counts_per_frequency(freq, tweet_name, start_time, end_time)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass TweetCounts {\n\n init() {\n\n }\n \n func recordTweet(_ tweetName: String, _ time: Int) {\n\n }\n \n func getTweetCountsPerFrequency(_ freq: String, _ tweetName: String, _ startTime: Int, _ endTime: Int) -> [Int] {\n\n }\n}\n\n/**\n * Your TweetCounts object will be instantiated and called as such:\n * let obj = TweetCounts()\n * obj.recordTweet(tweetName, time)\n * let ret_2: [Int] = obj.getTweetCountsPerFrequency(freq, tweetName, startTime, endTime)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type TweetCounts struct {\n\n}\n\n\nfunc Constructor() TweetCounts {\n\n}\n\n\nfunc (this *TweetCounts) RecordTweet(tweetName string, time int) {\n\n}\n\n\nfunc (this *TweetCounts) GetTweetCountsPerFrequency(freq string, tweetName string, startTime int, endTime int) []int {\n\n}\n\n\n/**\n * Your TweetCounts object will be instantiated and called as such:\n * obj := Constructor();\n * obj.RecordTweet(tweetName,time);\n * param_2 := obj.GetTweetCountsPerFrequency(freq,tweetName,startTime,endTime);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class TweetCounts() {\n\n def recordTweet(tweetName: String, time: Int) {\n\n }\n\n def getTweetCountsPerFrequency(freq: String, tweetName: String, startTime: Int, endTime: Int): List[Int] = {\n\n }\n\n}\n\n/**\n * Your TweetCounts object will be instantiated and called as such:\n * var obj = new TweetCounts()\n * obj.recordTweet(tweetName,time)\n * var param_2 = obj.getTweetCountsPerFrequency(freq,tweetName,startTime,endTime)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class TweetCounts() {\n\n fun recordTweet(tweetName: String, time: Int) {\n\n }\n\n fun getTweetCountsPerFrequency(freq: String, tweetName: String, startTime: Int, endTime: Int): List {\n\n }\n\n}\n\n/**\n * Your TweetCounts object will be instantiated and called as such:\n * var obj = TweetCounts()\n * obj.recordTweet(tweetName,time)\n * var param_2 = obj.getTweetCountsPerFrequency(freq,tweetName,startTime,endTime)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct TweetCounts {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl TweetCounts {\n\n fn new() -> Self {\n\n }\n \n fn record_tweet(&self, tweet_name: String, time: i32) {\n\n }\n \n fn get_tweet_counts_per_frequency(&self, freq: String, tweet_name: String, start_time: i32, end_time: i32) -> Vec {\n\n }\n}\n\n/**\n * Your TweetCounts object will be instantiated and called as such:\n * let obj = TweetCounts::new();\n * obj.record_tweet(tweetName, time);\n * let ret_2: Vec = obj.get_tweet_counts_per_frequency(freq, tweetName, startTime, endTime);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class TweetCounts {\n /**\n */\n function __construct() {\n\n }\n\n /**\n * @param String $tweetName\n * @param Integer $time\n * @return NULL\n */\n function recordTweet($tweetName, $time) {\n\n }\n\n /**\n * @param String $freq\n * @param String $tweetName\n * @param Integer $startTime\n * @param Integer $endTime\n * @return Integer[]\n */\n function getTweetCountsPerFrequency($freq, $tweetName, $startTime, $endTime) {\n\n }\n}\n\n/**\n * Your TweetCounts object will be instantiated and called as such:\n * $obj = TweetCounts();\n * $obj->recordTweet($tweetName, $time);\n * $ret_2 = $obj->getTweetCountsPerFrequency($freq, $tweetName, $startTime, $endTime);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class TweetCounts {\n constructor() {\n\n }\n\n recordTweet(tweetName: string, time: number): void {\n\n }\n\n getTweetCountsPerFrequency(freq: string, tweetName: string, startTime: number, endTime: number): number[] {\n\n }\n}\n\n/**\n * Your TweetCounts object will be instantiated and called as such:\n * var obj = new TweetCounts()\n * obj.recordTweet(tweetName,time)\n * var param_2 = obj.getTweetCountsPerFrequency(freq,tweetName,startTime,endTime)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define tweet-counts%\n (class object%\n (super-new)\n (init-field)\n \n ; record-tweet : string? exact-integer? -> void?\n (define/public (record-tweet tweetName time)\n\n )\n ; get-tweet-counts-per-frequency : string? string? exact-integer? exact-integer? -> (listof exact-integer?)\n (define/public (get-tweet-counts-per-frequency freq tweetName startTime endTime)\n\n )))\n\n;; Your tweet-counts% object will be instantiated and called as such:\n;; (define obj (new tweet-counts%))\n;; (send obj record-tweet tweet-name time)\n;; (define param_2 (send obj get-tweet-counts-per-frequency freq tweet-name start-time end-time))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1348](https://leetcode-cn.com/problems/tweet-counts-per-frequency)", "[\u63a8\u6587\u8ba1\u6570](/solution/1300-1399/1348.Tweet%20Counts%20Per%20Frequency/README.md)", "`\u8bbe\u8ba1`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1348](https://leetcode.com/problems/tweet-counts-per-frequency)", "[Tweet Counts Per Frequency](/solution/1300-1399/1348.Tweet%20Counts%20Per%20Frequency/README_EN.md)", "`Design`", "Medium", ""]}, {"question_id": "1469", "frontend_question_id": "1347", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-number-of-steps-to-make-two-strings-anagram", "url_en": "https://leetcode.com/problems/minimum-number-of-steps-to-make-two-strings-anagram", "relative_path_cn": "/solution/1300-1399/1347.Minimum%20Number%20of%20Steps%20to%20Make%20Two%20Strings%20Anagram/README.md", "relative_path_en": "/solution/1300-1399/1347.Minimum%20Number%20of%20Steps%20to%20Make%20Two%20Strings%20Anagram/README_EN.md", "title_cn": "\u5236\u9020\u5b57\u6bcd\u5f02\u4f4d\u8bcd\u7684\u6700\u5c0f\u6b65\u9aa4\u6570", "title_en": "Minimum Number of Steps to Make Two Strings Anagram", "question_title_slug": "minimum-number-of-steps-to-make-two-strings-anagram", "content_en": "

    Given two equal-size strings s and t. In one step you can choose any character of t and replace it with another character.

    \n\n

    Return the minimum number of steps to make t an anagram of s.

    \n\n

    An Anagram of a string is a string that contains the same characters with a different (or the same) ordering.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "bab", t = "aba"\nOutput: 1\nExplanation: Replace the first 'a' in t with b, t = "bba" which is anagram of s.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "leetcode", t = "practice"\nOutput: 5\nExplanation: Replace 'p', 'r', 'a', 'i' and 'c' from t with proper characters to make t anagram of s.\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "anagram", t = "mangaar"\nOutput: 0\nExplanation: "anagram" and "mangaar" are anagrams. \n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "xxyyzz", t = "xxyyzz"\nOutput: 0\n
    \n\n

    Example 5:

    \n\n
    \nInput: s = "friend", t = "family"\nOutput: 4\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 50000
    • \n\t
    • s.length == t.length
    • \n\t
    • s and t contain lower-case English letters only.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u957f\u5ea6\u76f8\u7b49\u7684\u5b57\u7b26\u4e32 s \u548c t\u3002\u6bcf\u4e00\u4e2a\u6b65\u9aa4\u4e2d\uff0c\u4f60\u53ef\u4ee5\u9009\u62e9\u5c06 t \u4e2d\u7684 \u4efb\u4e00\u5b57\u7b26 \u66ff\u6362\u4e3a \u53e6\u4e00\u4e2a\u5b57\u7b26\u3002

    \n\n

    \u8fd4\u56de\u4f7f t \u6210\u4e3a s \u7684\u5b57\u6bcd\u5f02\u4f4d\u8bcd\u7684\u6700\u5c0f\u6b65\u9aa4\u6570\u3002

    \n\n

    \u5b57\u6bcd\u5f02\u4f4d\u8bcd \u6307\u5b57\u6bcd\u76f8\u540c\uff0c\u4f46\u6392\u5217\u4e0d\u540c\uff08\u4e5f\u53ef\u80fd\u76f8\u540c\uff09\u7684\u5b57\u7b26\u4e32\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u51fa\uff1as = "bab", t = "aba"\n\u8f93\u51fa\uff1a1\n\u63d0\u793a\uff1a\u7528 'b' \u66ff\u6362 t \u4e2d\u7684\u7b2c\u4e00\u4e2a 'a'\uff0ct = "bba" \u662f s \u7684\u4e00\u4e2a\u5b57\u6bcd\u5f02\u4f4d\u8bcd\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u51fa\uff1as = "leetcode", t = "practice"\n\u8f93\u51fa\uff1a5\n\u63d0\u793a\uff1a\u7528\u5408\u9002\u7684\u5b57\u7b26\u66ff\u6362 t \u4e2d\u7684 'p', 'r', 'a', 'i' \u548c 'c'\uff0c\u4f7f t \u53d8\u6210 s \u7684\u5b57\u6bcd\u5f02\u4f4d\u8bcd\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u51fa\uff1as = "anagram", t = "mangaar"\n\u8f93\u51fa\uff1a0\n\u63d0\u793a\uff1a"anagram" \u548c "mangaar" \u672c\u8eab\u5c31\u662f\u4e00\u7ec4\u5b57\u6bcd\u5f02\u4f4d\u8bcd\u3002 \n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u51fa\uff1as = "xxyyzz", t = "xxyyzz"\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u51fa\uff1as = "friend", t = "family"\n\u8f93\u51fa\uff1a4\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 50000
    • \n\t
    • s.length == t.length
    • \n\t
    • s \u548c t \u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minSteps(string s, string t) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minSteps(String s, String t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minSteps(self, s, t):\n \"\"\"\n :type s: str\n :type t: str\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minSteps(self, s: str, t: str) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minSteps(char * s, char * t){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinSteps(string s, string t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string} t\n * @return {number}\n */\nvar minSteps = function(s, t) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String} t\n# @return {Integer}\ndef min_steps(s, t)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minSteps(_ s: String, _ t: String) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minSteps(s string, t string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minSteps(s: String, t: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minSteps(s: String, t: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_steps(s: String, t: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String $t\n * @return Integer\n */\n function minSteps($s, $t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minSteps(s: string, t: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-steps s t)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1347](https://leetcode-cn.com/problems/minimum-number-of-steps-to-make-two-strings-anagram)", "[\u5236\u9020\u5b57\u6bcd\u5f02\u4f4d\u8bcd\u7684\u6700\u5c0f\u6b65\u9aa4\u6570](/solution/1300-1399/1347.Minimum%20Number%20of%20Steps%20to%20Make%20Two%20Strings%20Anagram/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1347](https://leetcode.com/problems/minimum-number-of-steps-to-make-two-strings-anagram)", "[Minimum Number of Steps to Make Two Strings Anagram](/solution/1300-1399/1347.Minimum%20Number%20of%20Steps%20to%20Make%20Two%20Strings%20Anagram/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "1468", "frontend_question_id": "1346", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/check-if-n-and-its-double-exist", "url_en": "https://leetcode.com/problems/check-if-n-and-its-double-exist", "relative_path_cn": "/solution/1300-1399/1346.Check%20If%20N%20and%20Its%20Double%20Exist/README.md", "relative_path_en": "/solution/1300-1399/1346.Check%20If%20N%20and%20Its%20Double%20Exist/README_EN.md", "title_cn": "\u68c0\u67e5\u6574\u6570\u53ca\u5176\u4e24\u500d\u6570\u662f\u5426\u5b58\u5728", "title_en": "Check If N and Its Double Exist", "question_title_slug": "check-if-n-and-its-double-exist", "content_en": "

    Given an array arr of integers, check if there exists two integers N and M such that N is the double of M ( i.e. N = 2 * M).

    \n\n

    More formally check if there exists two indices i and j such that :

    \n\n
      \n\t
    • i != j
    • \n\t
    • 0 <= i, j < arr.length
    • \n\t
    • arr[i] == 2 * arr[j]
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr = [10,2,5,3]\nOutput: true\nExplanation: N = 10 is the double of M = 5,that is, 10 = 2 * 5.\n
    \n\n

    Example 2:

    \n\n
    \nInput: arr = [7,1,14,11]\nOutput: true\nExplanation: N = 14 is the double of M = 7,that is, 14 = 2 * 7.\n
    \n\n

    Example 3:

    \n\n
    \nInput: arr = [3,1,7,11]\nOutput: false\nExplanation: In this case does not exist N and M, such that N = 2 * M.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= arr.length <= 500
    • \n\t
    • -10^3 <= arr[i] <= 10^3
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr\uff0c\u8bf7\u4f60\u68c0\u67e5\u662f\u5426\u5b58\u5728\u4e24\u4e2a\u6574\u6570 N \u548c M\uff0c\u6ee1\u8db3 N \u662f M \u7684\u4e24\u500d\uff08\u5373\uff0cN = 2 * M\uff09\u3002

    \n\n

    \u66f4\u6b63\u5f0f\u5730\uff0c\u68c0\u67e5\u662f\u5426\u5b58\u5728\u4e24\u4e2a\u4e0b\u6807 i \u548c j \u6ee1\u8db3\uff1a

    \n\n
      \n\t
    • i != j
    • \n\t
    • 0 <= i, j < arr.length
    • \n\t
    • arr[i] == 2 * arr[j]
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [10,2,5,3]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1aN = 10 \u662f M = 5 \u7684\u4e24\u500d\uff0c\u5373 10 = 2 * 5 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [7,1,14,11]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1aN = 14 \u662f M = 7 \u7684\u4e24\u500d\uff0c\u5373 14 = 2 * 7 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [3,1,7,11]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u5728\u8be5\u60c5\u51b5\u4e0b\u4e0d\u5b58\u5728 N \u548c M \u6ee1\u8db3 N = 2 * M \u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= arr.length <= 500
    • \n\t
    • -10^3 <= arr[i] <= 10^3
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool checkIfExist(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean checkIfExist(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def checkIfExist(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def checkIfExist(self, arr: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool checkIfExist(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CheckIfExist(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {boolean}\n */\nvar checkIfExist = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Boolean}\ndef check_if_exist(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func checkIfExist(_ arr: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func checkIfExist(arr []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def checkIfExist(arr: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun checkIfExist(arr: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn check_if_exist(arr: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Boolean\n */\n function checkIfExist($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function checkIfExist(arr: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (check-if-exist arr)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1346](https://leetcode-cn.com/problems/check-if-n-and-its-double-exist)", "[\u68c0\u67e5\u6574\u6570\u53ca\u5176\u4e24\u500d\u6570\u662f\u5426\u5b58\u5728](/solution/1300-1399/1346.Check%20If%20N%20and%20Its%20Double%20Exist/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1346](https://leetcode.com/problems/check-if-n-and-its-double-exist)", "[Check If N and Its Double Exist](/solution/1300-1399/1346.Check%20If%20N%20and%20Its%20Double%20Exist/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1467", "frontend_question_id": "1336", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/number-of-transactions-per-visit", "url_en": "https://leetcode.com/problems/number-of-transactions-per-visit", "relative_path_cn": "/solution/1300-1399/1336.Number%20of%20Transactions%20per%20Visit/README.md", "relative_path_en": "/solution/1300-1399/1336.Number%20of%20Transactions%20per%20Visit/README_EN.md", "title_cn": "\u6bcf\u6b21\u8bbf\u95ee\u7684\u4ea4\u6613\u6b21\u6570", "title_en": "Number of Transactions per Visit", "question_title_slug": "number-of-transactions-per-visit", "content_en": "

    Table: Visits

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| user_id       | int     |\n| visit_date    | date    |\n+---------------+---------+\n(user_id, visit_date) is the primary key for this table.\nEach row of this table indicates that user_id has visited the bank in visit_date.\n
    \n\n

     

    \n\n

    Table: Transactions

    \n\n
    \n+------------------+---------+\n| Column Name      | Type    |\n+------------------+---------+\n| user_id          | int     |\n| transaction_date | date    |\n| amount           | int     |\n+------------------+---------+\nThere is no primary key for this table, it may contain duplicates.\nEach row of this table indicates that user_id has done a transaction of amount in transaction_date.\nIt is guaranteed that the user has visited the bank in the transaction_date.(i.e The Visits table contains (user_id, transaction_date) in one row)\n
    \n\n

     

    \n\n

    A bank wants to draw a chart of the number of transactions bank visitors did in one visit to the bank and the corresponding number of visitors who have done this number of transaction in one visit.

    \n\n

    Write an SQL query to find how many users visited the bank and didn't do any transactions, how many visited the bank and did one transaction and so on.

    \n\n

    The result table will contain two columns:

    \n\n
      \n\t
    • transactions_count which is the number of transactions done in one visit.
    • \n\t
    • visits_count which is the corresponding number of users who did transactions_count in one visit to the bank.
    • \n
    \n\n

    transactions_count should take all values from 0 to max(transactions_count) done by one or more users.

    \n\n

    Order the result table by transactions_count.

    \n\n

    The query result format is in the following example:

    \n\n
    \nVisits table:\n+---------+------------+\n| user_id | visit_date |\n+---------+------------+\n| 1       | 2020-01-01 |\n| 2       | 2020-01-02 |\n| 12      | 2020-01-01 |\n| 19      | 2020-01-03 |\n| 1       | 2020-01-02 |\n| 2       | 2020-01-03 |\n| 1       | 2020-01-04 |\n| 7       | 2020-01-11 |\n| 9       | 2020-01-25 |\n| 8       | 2020-01-28 |\n+---------+------------+\nTransactions table:\n+---------+------------------+--------+\n| user_id | transaction_date | amount |\n+---------+------------------+--------+\n| 1       | 2020-01-02       | 120    |\n| 2       | 2020-01-03       | 22     |\n| 7       | 2020-01-11       | 232    |\n| 1       | 2020-01-04       | 7      |\n| 9       | 2020-01-25       | 33     |\n| 9       | 2020-01-25       | 66     |\n| 8       | 2020-01-28       | 1      |\n| 9       | 2020-01-25       | 99     |\n+---------+------------------+--------+\nResult table:\n+--------------------+--------------+\n| transactions_count | visits_count |\n+--------------------+--------------+\n| 0                  | 4            |\n| 1                  | 5            |\n| 2                  | 0            |\n| 3                  | 1            |\n+--------------------+--------------+\n* For transactions_count = 0, The visits (1, "2020-01-01"), (2, "2020-01-02"), (12, "2020-01-01") and (19, "2020-01-03") did no transactions so visits_count = 4.\n* For transactions_count = 1, The visits (2, "2020-01-03"), (7, "2020-01-11"), (8, "2020-01-28"), (1, "2020-01-02") and (1, "2020-01-04") did one transaction so visits_count = 5.\n* For transactions_count = 2, No customers visited the bank and did two transactions so visits_count = 0.\n* For transactions_count = 3, The visit (9, "2020-01-25") did three transactions so visits_count = 1.\n* For transactions_count >= 4, No customers visited the bank and did more than three transactions so we will stop at transactions_count = 3\n\nThe chart drawn for this example is as follows:\n\"\"\n
    \n", "content_cn": "

    \u8868: Visits

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| user_id       | int     |\n| visit_date    | date    |\n+---------------+---------+\n(user_id, visit_date) \u662f\u8be5\u8868\u7684\u4e3b\u952e\n\u8be5\u8868\u7684\u6bcf\u884c\u8868\u793a user_id \u5728 visit_date \u8bbf\u95ee\u4e86\u94f6\u884c\n
    \n\n

     

    \n\n

    \u8868: Transactions

    \n\n
    \n+------------------+---------+\n| Column Name      | Type    |\n+------------------+---------+\n| user_id          | int     |\n| transaction_date | date    |\n| amount           | int     |\n+------------------+---------+\n\u8be5\u8868\u6ca1\u6709\u4e3b\u952e\uff0c\u6240\u4ee5\u53ef\u80fd\u6709\u91cd\u590d\u884c\n\u8be5\u8868\u7684\u6bcf\u4e00\u884c\u8868\u793a user_id \u5728 transaction_date \u5b8c\u6210\u4e86\u4e00\u7b14 amount \u6570\u989d\u7684\u4ea4\u6613\n\u53ef\u4ee5\u4fdd\u8bc1\u7528\u6237 (user) \u5728 transaction_date \u8bbf\u95ee\u4e86\u94f6\u884c (\u4e5f\u5c31\u662f\u8bf4 Visits \u8868\u5305\u542b (user_id, transaction_date) \u884c)\n
    \n\n

     

    \n\n

    \u94f6\u884c\u60f3\u8981\u5f97\u5230\u94f6\u884c\u5ba2\u6237\u5728\u4e00\u6b21\u8bbf\u95ee\u65f6\u7684\u4ea4\u6613\u6b21\u6570\u548c\u76f8\u5e94\u7684\u5728\u4e00\u6b21\u8bbf\u95ee\u65f6\u8be5\u4ea4\u6613\u6b21\u6570\u7684\u5ba2\u6237\u6570\u91cf\u7684\u56fe\u8868

    \n\n

    \u5199\u4e00\u6761 SQL \u67e5\u8be2\u591a\u5c11\u5ba2\u6237\u8bbf\u95ee\u4e86\u94f6\u884c\u4f46\u6ca1\u6709\u8fdb\u884c\u4efb\u4f55\u4ea4\u6613\uff0c\u591a\u5c11\u5ba2\u6237\u8bbf\u95ee\u4e86\u94f6\u884c\u8fdb\u884c\u4e86\u4e00\u6b21\u4ea4\u6613\u7b49\u7b49

    \n\n

    \u7ed3\u679c\u5305\u542b\u4e24\u5217\uff1a

    \n\n
      \n\t
    • transactions_count\uff1a \u5ba2\u6237\u5728\u4e00\u6b21\u8bbf\u95ee\u4e2d\u7684\u4ea4\u6613\u6b21\u6570
    • \n\t
    • visits_count\uff1a \u5728 transactions_count \u4ea4\u6613\u6b21\u6570\u4e0b\u76f8\u5e94\u7684\u4e00\u6b21\u8bbf\u95ee\u65f6\u7684\u5ba2\u6237\u6570\u91cf
    • \n
    \n\n

    transactions_count \u7684\u503c\u4ece 0 \u5230\u6240\u6709\u7528\u6237\u4e00\u6b21\u8bbf\u95ee\u4e2d\u7684 max(transactions_count) 

    \n\n

    \u6309 transactions_count \u6392\u5e8f

    \n\n

    \u4e0b\u9762\u662f\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u7684\u4f8b\u5b50\uff1a

    \n\n
    \nVisits \u8868:\n+---------+------------+\n| user_id | visit_date |\n+---------+------------+\n| 1       | 2020-01-01 |\n| 2       | 2020-01-02 |\n| 12      | 2020-01-01 |\n| 19      | 2020-01-03 |\n| 1       | 2020-01-02 |\n| 2       | 2020-01-03 |\n| 1       | 2020-01-04 |\n| 7       | 2020-01-11 |\n| 9       | 2020-01-25 |\n| 8       | 2020-01-28 |\n+---------+------------+\nTransactions \u8868:\n+---------+------------------+--------+\n| user_id | transaction_date | amount |\n+---------+------------------+--------+\n| 1       | 2020-01-02       | 120    |\n| 2       | 2020-01-03       | 22     |\n| 7       | 2020-01-11       | 232    |\n| 1       | 2020-01-04       | 7      |\n| 9       | 2020-01-25       | 33     |\n| 9       | 2020-01-25       | 66     |\n| 8       | 2020-01-28       | 1      |\n| 9       | 2020-01-25       | 99     |\n+---------+------------------+--------+\n\u7ed3\u679c\u8868:\n+--------------------+--------------+\n| transactions_count | visits_count |\n+--------------------+--------------+\n| 0                  | 4            |\n| 1                  | 5            |\n| 2                  | 0            |\n| 3                  | 1            |\n+--------------------+--------------+\n* \u5bf9\u4e8e transactions_count = 0, visits \u4e2d (1, "2020-01-01"), (2, "2020-01-02"), (12, "2020-01-01") \u548c (19, "2020-01-03") \u6ca1\u6709\u8fdb\u884c\u4ea4\u6613\uff0c\u6240\u4ee5 visits_count = 4 \u3002\n* \u5bf9\u4e8e transactions_count = 1, visits \u4e2d (2, "2020-01-03"), (7, "2020-01-11"), (8, "2020-01-28"), (1, "2020-01-02") \u548c (1, "2020-01-04") \u8fdb\u884c\u4e86\u4e00\u6b21\u4ea4\u6613\uff0c\u6240\u4ee5 visits_count = 5 \u3002\n* \u5bf9\u4e8e transactions_count = 2, \u6ca1\u6709\u5ba2\u6237\u8bbf\u95ee\u94f6\u884c\u8fdb\u884c\u4e86\u4e24\u6b21\u4ea4\u6613\uff0c\u6240\u4ee5 visits_count = 0 \u3002\n* \u5bf9\u4e8e transactions_count = 3, visits \u4e2d (9, "2020-01-25") \u8fdb\u884c\u4e86\u4e09\u6b21\u4ea4\u6613\uff0c\u6240\u4ee5 visits_count = 1 \u3002\n* \u5bf9\u4e8e transactions_count >= 4, \u6ca1\u6709\u5ba2\u6237\u8bbf\u95ee\u94f6\u884c\u8fdb\u884c\u4e86\u8d85\u8fc73\u6b21\u4ea4\u6613\uff0c\u6240\u4ee5\u6211\u4eec\u505c\u6b62\u5728 transactions_count = 3 \u3002\n\n\u5982\u4e0b\u662f\u8fd9\u4e2a\u4f8b\u5b50\u7684\u56fe\u8868\uff1a\n\"\"\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1336](https://leetcode-cn.com/problems/number-of-transactions-per-visit)", "[\u6bcf\u6b21\u8bbf\u95ee\u7684\u4ea4\u6613\u6b21\u6570](/solution/1300-1399/1336.Number%20of%20Transactions%20per%20Visit/README.md)", "", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1336](https://leetcode.com/problems/number-of-transactions-per-visit)", "[Number of Transactions per Visit](/solution/1300-1399/1336.Number%20of%20Transactions%20per%20Visit/README_EN.md)", "", "Hard", "\ud83d\udd12"]}, {"question_id": "1466", "frontend_question_id": "1340", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/jump-game-v", "url_en": "https://leetcode.com/problems/jump-game-v", "relative_path_cn": "/solution/1300-1399/1340.Jump%20Game%20V/README.md", "relative_path_en": "/solution/1300-1399/1340.Jump%20Game%20V/README_EN.md", "title_cn": "\u8df3\u8dc3\u6e38\u620f V", "title_en": "Jump Game V", "question_title_slug": "jump-game-v", "content_en": "

    Given an array of integers arr and an integer d. In one step you can jump from index i to index:

    \r\n\r\n
      \r\n\t
    • i + x where: i + x < arr.length and 0 < x <= d.
    • \r\n\t
    • i - x where: i - x >= 0 and 0 < x <= d.
    • \r\n
    \r\n\r\n

    In addition, you can only jump from index i to index j if arr[i] > arr[j] and arr[i] > arr[k] for all indices k between i and j (More formally min(i, j) < k < max(i, j)).

    \r\n\r\n

    You can choose any index of the array and start jumping. Return the maximum number of indices you can visit.

    \r\n\r\n

    Notice that you can not jump outside of the array at any time.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\"\"\r\n
    \r\nInput: arr = [6,4,14,6,8,13,9,7,10,6,12], d = 2\r\nOutput: 4\r\nExplanation: You can start at index 10. You can jump 10 --> 8 --> 6 --> 7 as shown.\r\nNote that if you start at index 6 you can only jump to index 7. You cannot jump to index 5 because 13 > 9. You cannot jump to index 4 because index 5 is between index 4 and 6 and 13 > 9.\r\nSimilarly You cannot jump from index 3 to index 2 or index 1.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: arr = [3,3,3,3,3], d = 3\r\nOutput: 1\r\nExplanation: You can start at any index. You always cannot jump to any index.\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: arr = [7,6,5,4,3,2,1], d = 1\r\nOutput: 7\r\nExplanation: Start at index 0. You can visit all the indicies. \r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: arr = [7,1,7,1,7,1], d = 2\r\nOutput: 2\r\n
    \r\n\r\n

    Example 5:

    \r\n\r\n
    \r\nInput: arr = [66], d = 1\r\nOutput: 1\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= arr.length <= 1000
    • \r\n\t
    • 1 <= arr[i] <= 10^5
    • \r\n\t
    • 1 <= d <= arr.length
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr \u548c\u4e00\u4e2a\u6574\u6570 d \u3002\u6bcf\u4e00\u6b65\u4f60\u53ef\u4ee5\u4ece\u4e0b\u6807 i \u8df3\u5230\uff1a

    \n\n
      \n\t
    • i + x \uff0c\u5176\u4e2d i + x < arr.length \u4e14 0 < x <= d \u3002
    • \n\t
    • i - x \uff0c\u5176\u4e2d i - x >= 0 \u4e14 0 < x <= d \u3002
    • \n
    \n\n

    \u9664\u6b64\u4ee5\u5916\uff0c\u4f60\u4ece\u4e0b\u6807 i \u8df3\u5230\u4e0b\u6807 j \u9700\u8981\u6ee1\u8db3\uff1aarr[i] > arr[j] \u4e14 arr[i] > arr[k] \uff0c\u5176\u4e2d\u4e0b\u6807 k \u662f\u6240\u6709 i \u5230 j \u4e4b\u95f4\u7684\u6570\u5b57\uff08\u66f4\u6b63\u5f0f\u7684\uff0cmin(i, j) < k < max(i, j)\uff09\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u9009\u62e9\u6570\u7ec4\u7684\u4efb\u610f\u4e0b\u6807\u5f00\u59cb\u8df3\u8dc3\u3002\u8bf7\u4f60\u8fd4\u56de\u4f60 \u6700\u591a \u53ef\u4ee5\u8bbf\u95ee\u591a\u5c11\u4e2a\u4e0b\u6807\u3002

    \n\n

    \u8bf7\u6ce8\u610f\uff0c\u4efb\u4f55\u65f6\u523b\u4f60\u90fd\u4e0d\u80fd\u8df3\u5230\u6570\u7ec4\u7684\u5916\u9762\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1aarr = [6,4,14,6,8,13,9,7,10,6,12], d = 2\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u4ece\u4e0b\u6807 10 \u51fa\u53d1\uff0c\u7136\u540e\u5982\u4e0a\u56fe\u4f9d\u6b21\u7ecf\u8fc7 10 --> 8 --> 6 --> 7 \u3002\n\u6ce8\u610f\uff0c\u5982\u679c\u4f60\u4ece\u4e0b\u6807 6 \u5f00\u59cb\uff0c\u4f60\u53ea\u80fd\u8df3\u5230\u4e0b\u6807 7 \u5904\u3002\u4f60\u4e0d\u80fd\u8df3\u5230\u4e0b\u6807 5 \u5904\u56e0\u4e3a 13 > 9 \u3002\u4f60\u4e5f\u4e0d\u80fd\u8df3\u5230\u4e0b\u6807 4 \u5904\uff0c\u56e0\u4e3a\u4e0b\u6807 5 \u5728\u4e0b\u6807 4 \u548c 6 \u4e4b\u95f4\u4e14 13 > 9 \u3002\n\u7c7b\u4f3c\u7684\uff0c\u4f60\u4e0d\u80fd\u4ece\u4e0b\u6807 3 \u5904\u8df3\u5230\u4e0b\u6807 2 \u6216\u8005\u4e0b\u6807 1 \u5904\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [3,3,3,3,3], d = 3\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u4ece\u4efb\u610f\u4e0b\u6807\u5904\u5f00\u59cb\u4e14\u4f60\u6c38\u8fdc\u65e0\u6cd5\u8df3\u5230\u4efb\u4f55\u5176\u4ed6\u5750\u6807\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [7,6,5,4,3,2,1], d = 1\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\u4ece\u4e0b\u6807 0 \u5904\u5f00\u59cb\uff0c\u4f60\u53ef\u4ee5\u6309\u7167\u6570\u503c\u4ece\u5927\u5230\u5c0f\uff0c\u8bbf\u95ee\u6240\u6709\u7684\u4e0b\u6807\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [7,1,7,1,7,1], d = 2\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [66], d = 1\n\u8f93\u51fa\uff1a1\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= arr.length <= 1000
    • \n\t
    • 1 <= arr[i] <= 10^5
    • \n\t
    • 1 <= d <= arr.length
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxJumps(vector& arr, int d) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxJumps(int[] arr, int d) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxJumps(self, arr, d):\n \"\"\"\n :type arr: List[int]\n :type d: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxJumps(self, arr: List[int], d: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxJumps(int* arr, int arrSize, int d){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxJumps(int[] arr, int d) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @param {number} d\n * @return {number}\n */\nvar maxJumps = function(arr, d) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @param {Integer} d\n# @return {Integer}\ndef max_jumps(arr, d)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxJumps(_ arr: [Int], _ d: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxJumps(arr []int, d int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxJumps(arr: Array[Int], d: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxJumps(arr: IntArray, d: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_jumps(arr: Vec, d: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @param Integer $d\n * @return Integer\n */\n function maxJumps($arr, $d) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxJumps(arr: number[], d: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-jumps arr d)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1340](https://leetcode-cn.com/problems/jump-game-v)", "[\u8df3\u8dc3\u6e38\u620f V](/solution/1300-1399/1340.Jump%20Game%20V/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1340](https://leetcode.com/problems/jump-game-v)", "[Jump Game V](/solution/1300-1399/1340.Jump%20Game%20V/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1465", "frontend_question_id": "1339", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-product-of-splitted-binary-tree", "url_en": "https://leetcode.com/problems/maximum-product-of-splitted-binary-tree", "relative_path_cn": "/solution/1300-1399/1339.Maximum%20Product%20of%20Splitted%20Binary%20Tree/README.md", "relative_path_en": "/solution/1300-1399/1339.Maximum%20Product%20of%20Splitted%20Binary%20Tree/README_EN.md", "title_cn": "\u5206\u88c2\u4e8c\u53c9\u6811\u7684\u6700\u5927\u4e58\u79ef", "title_en": "Maximum Product of Splitted Binary Tree", "question_title_slug": "maximum-product-of-splitted-binary-tree", "content_en": "

    Given a binary tree root. Split the binary tree into two subtrees by removing 1 edge such that the product of the sums of the subtrees are maximized.

    \r\n\r\n

    Since the answer may be too large, return it modulo 10^9 + 7.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n

    \"\"

    \r\n\r\n
    \r\nInput: root = [1,2,3,4,5,6]\r\nOutput: 110\r\nExplanation: Remove the red edge and get 2 binary trees with sum 11 and 10. Their product is 110 (11*10)\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n

    \"\"

    \r\n\r\n
    \r\nInput: root = [1,null,2,3,4,null,null,5,6]\r\nOutput: 90\r\nExplanation:  Remove the red edge and get 2 binary trees with sum 15 and 6.Their product is 90 (15*6)\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: root = [2,3,9,10,7,8,6,5,4,11,1]\r\nOutput: 1025\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: root = [1,1]\r\nOutput: 1\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • Each tree has at most 50000 nodes and at least 2 nodes.
    • \r\n\t
    • Each node's value is between [1, 10000].
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u68f5\u4e8c\u53c9\u6811\uff0c\u5b83\u7684\u6839\u4e3a root \u3002\u8bf7\u4f60\u5220\u9664 1 \u6761\u8fb9\uff0c\u4f7f\u4e8c\u53c9\u6811\u5206\u88c2\u6210\u4e24\u68f5\u5b50\u6811\uff0c\u4e14\u5b83\u4eec\u5b50\u6811\u548c\u7684\u4e58\u79ef\u5c3d\u53ef\u80fd\u5927\u3002

    \n\n

    \u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u4f1a\u5f88\u5927\uff0c\u8bf7\u4f60\u5c06\u7ed3\u679c\u5bf9 10^9 + 7 \u53d6\u6a21\u540e\u518d\u8fd4\u56de\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1aroot = [1,2,3,4,5,6]\n\u8f93\u51fa\uff1a110\n\u89e3\u91ca\uff1a\u5220\u9664\u7ea2\u8272\u7684\u8fb9\uff0c\u5f97\u5230 2 \u68f5\u5b50\u6811\uff0c\u548c\u5206\u522b\u4e3a 11 \u548c 10 \u3002\u5b83\u4eec\u7684\u4e58\u79ef\u662f 110 \uff0811*10\uff09\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1aroot = [1,null,2,3,4,null,null,5,6]\n\u8f93\u51fa\uff1a90\n\u89e3\u91ca\uff1a\u79fb\u9664\u7ea2\u8272\u7684\u8fb9\uff0c\u5f97\u5230 2 \u68f5\u5b50\u6811\uff0c\u548c\u5206\u522b\u662f 15 \u548c 6 \u3002\u5b83\u4eec\u7684\u4e58\u79ef\u4e3a 90 \uff0815*6\uff09\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aroot = [2,3,9,10,7,8,6,5,4,11,1]\n\u8f93\u51fa\uff1a1025\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1aroot = [1,1]\n\u8f93\u51fa\uff1a1\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6bcf\u68f5\u6811\u6700\u591a\u6709 50000 \u4e2a\u8282\u70b9\uff0c\u4e14\u81f3\u5c11\u6709 2 \u4e2a\u8282\u70b9\u3002
    • \n\t
    • \u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u5728 [1, 10000] \u4e4b\u95f4\u3002
    • \n
    \n", "tags_en": ["Tree", "Dynamic Programming"], "tags_cn": ["\u6811", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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 */\nclass Solution {\npublic:\n int maxProduct(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode(int x) { val = x; }\n * }\n */\nclass Solution {\n public int maxProduct(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution(object):\n def maxProduct(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution:\n def maxProduct(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint maxProduct(struct TreeNode* root){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int x) { val = x; }\n * }\n */\npublic class Solution {\n public int MaxProduct(TreeNode root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val) {\n * this.val = val;\n * this.left = this.right = null;\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar maxProduct = function(root) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val)\n# @val = val\n# @left, @right = nil, nil\n# end\n# end\n\n# @param {TreeNode} root\n# @return {Integer}\ndef max_product(root)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.left = nil\n * self.right = nil\n * }\n * }\n */\nclass Solution {\n func maxProduct(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc maxProduct(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(var _value: Int) {\n * var value: Int = _value\n * var left: TreeNode = null\n * var right: TreeNode = null\n * }\n */\nobject Solution {\n def maxProduct(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun maxProduct(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n// \n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn max_product(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($value) { $this->val = $value; }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function maxProduct($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction maxProduct(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (max-product root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1339](https://leetcode-cn.com/problems/maximum-product-of-splitted-binary-tree)", "[\u5206\u88c2\u4e8c\u53c9\u6811\u7684\u6700\u5927\u4e58\u79ef](/solution/1300-1399/1339.Maximum%20Product%20of%20Splitted%20Binary%20Tree/README.md)", "`\u6811`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1339](https://leetcode.com/problems/maximum-product-of-splitted-binary-tree)", "[Maximum Product of Splitted Binary Tree](/solution/1300-1399/1339.Maximum%20Product%20of%20Splitted%20Binary%20Tree/README_EN.md)", "`Tree`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "1464", "frontend_question_id": "1338", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reduce-array-size-to-the-half", "url_en": "https://leetcode.com/problems/reduce-array-size-to-the-half", "relative_path_cn": "/solution/1300-1399/1338.Reduce%20Array%20Size%20to%20The%20Half/README.md", "relative_path_en": "/solution/1300-1399/1338.Reduce%20Array%20Size%20to%20The%20Half/README_EN.md", "title_cn": "\u6570\u7ec4\u5927\u5c0f\u51cf\u534a", "title_en": "Reduce Array Size to The Half", "question_title_slug": "reduce-array-size-to-the-half", "content_en": "

    Given an array arr.  You can choose a set of integers and remove all the occurrences of these integers in the array.

    \r\n\r\n

    Return the minimum size of the set so that at least half of the integers of the array are removed.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: arr = [3,3,3,3,5,5,5,2,2,7]\r\nOutput: 2\r\nExplanation: Choosing {3,7} will make the new array [5,5,5,2,2] which has size 5 (i.e equal to half of the size of the old array).\r\nPossible sets of size 2 are {3,5},{3,2},{5,2}.\r\nChoosing set {2,7} is not possible as it will make the new array [3,3,3,3,5,5,5] which has size greater than half of the size of the old array.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: arr = [7,7,7,7,7,7]\r\nOutput: 1\r\nExplanation: The only possible set you can choose is {7}. This will make the new array empty.\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: arr = [1,9]\r\nOutput: 1\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: arr = [1000,1000,3,7]\r\nOutput: 1\r\n
    \r\n\r\n

    Example 5:

    \r\n\r\n
    \r\nInput: arr = [1,2,3,4,5,6,7,8,9,10]\r\nOutput: 5\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= arr.length <= 10^5
    • \r\n\t
    • arr.length is even.
    • \r\n\t
    • 1 <= arr[i] <= 10^5
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr\u3002\u4f60\u53ef\u4ee5\u4ece\u4e2d\u9009\u51fa\u4e00\u4e2a\u6574\u6570\u96c6\u5408\uff0c\u5e76\u5220\u9664\u8fd9\u4e9b\u6574\u6570\u5728\u6570\u7ec4\u4e2d\u7684\u6bcf\u6b21\u51fa\u73b0\u3002

    \n\n

    \u8fd4\u56de \u81f3\u5c11 \u80fd\u5220\u9664\u6570\u7ec4\u4e2d\u7684\u4e00\u534a\u6574\u6570\u7684\u6574\u6570\u96c6\u5408\u7684\u6700\u5c0f\u5927\u5c0f\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [3,3,3,3,5,5,5,2,2,7]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u9009\u62e9 {3,7} \u4f7f\u5f97\u7ed3\u679c\u6570\u7ec4\u4e3a [5,5,5,2,2]\u3001\u957f\u5ea6\u4e3a 5\uff08\u539f\u6570\u7ec4\u957f\u5ea6\u7684\u4e00\u534a\uff09\u3002\n\u5927\u5c0f\u4e3a 2 \u7684\u53ef\u884c\u96c6\u5408\u6709 {3,5},{3,2},{5,2}\u3002\n\u9009\u62e9 {2,7} \u662f\u4e0d\u53ef\u884c\u7684\uff0c\u5b83\u7684\u7ed3\u679c\u6570\u7ec4\u4e3a [3,3,3,3,5,5,5]\uff0c\u65b0\u6570\u7ec4\u957f\u5ea6\u5927\u4e8e\u539f\u6570\u7ec4\u7684\u4e8c\u5206\u4e4b\u4e00\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [7,7,7,7,7,7]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u6211\u4eec\u53ea\u80fd\u9009\u62e9\u96c6\u5408 {7}\uff0c\u7ed3\u679c\u6570\u7ec4\u4e3a\u7a7a\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [1,9]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [1000,1000,3,7]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [1,2,3,4,5,6,7,8,9,10]\n\u8f93\u51fa\uff1a5\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= arr.length <= 10^5
    • \n\t
    • arr.length \u4e3a\u5076\u6570
    • \n\t
    • 1 <= arr[i] <= 10^5
    • \n
    \n", "tags_en": ["Greedy", "Array"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minSetSize(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minSetSize(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minSetSize(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minSetSize(self, arr: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minSetSize(int* arr, int arrSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinSetSize(int[] arr) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar minSetSize = function(arr) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef min_set_size(arr)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minSetSize(_ arr: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minSetSize(arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minSetSize(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minSetSize(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_set_size(arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function minSetSize($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minSetSize(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-set-size arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1338](https://leetcode-cn.com/problems/reduce-array-size-to-the-half)", "[\u6570\u7ec4\u5927\u5c0f\u51cf\u534a](/solution/1300-1399/1338.Reduce%20Array%20Size%20to%20The%20Half/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1338](https://leetcode.com/problems/reduce-array-size-to-the-half)", "[Reduce Array Size to The Half](/solution/1300-1399/1338.Reduce%20Array%20Size%20to%20The%20Half/README_EN.md)", "`Greedy`,`Array`", "Medium", ""]}, {"question_id": "1463", "frontend_question_id": "1337", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/the-k-weakest-rows-in-a-matrix", "url_en": "https://leetcode.com/problems/the-k-weakest-rows-in-a-matrix", "relative_path_cn": "/solution/1300-1399/1337.The%20K%20Weakest%20Rows%20in%20a%20Matrix/README.md", "relative_path_en": "/solution/1300-1399/1337.The%20K%20Weakest%20Rows%20in%20a%20Matrix/README_EN.md", "title_cn": "\u77e9\u9635\u4e2d\u6218\u6597\u529b\u6700\u5f31\u7684 K \u884c", "title_en": "The K Weakest Rows in a Matrix", "question_title_slug": "the-k-weakest-rows-in-a-matrix", "content_en": "

    You are given an m x n binary matrix mat of 1's (representing soldiers) and 0's (representing civilians). The soldiers are positioned in front of the civilians. That is, all the 1's will appear to the left of all the 0's in each row.

    \n\n

    A row i is weaker than a row j if one of the following is true:

    \n\n
      \n\t
    • The number of soldiers in row i is less than the number of soldiers in row j.
    • \n\t
    • Both rows have the same number of soldiers and i < j.
    • \n
    \n\n

    Return the indices of the k weakest rows in the matrix ordered from weakest to strongest.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: mat = \n[[1,1,0,0,0],\n [1,1,1,1,0],\n [1,0,0,0,0],\n [1,1,0,0,0],\n [1,1,1,1,1]], \nk = 3\nOutput: [2,0,3]\nExplanation: \nThe number of soldiers in each row is: \n- Row 0: 2 \n- Row 1: 4 \n- Row 2: 1 \n- Row 3: 2 \n- Row 4: 5 \nThe rows ordered from weakest to strongest are [2,0,3,1,4].\n
    \n\n

    Example 2:

    \n\n
    \nInput: mat = \n[[1,0,0,0],\n [1,1,1,1],\n [1,0,0,0],\n [1,0,0,0]], \nk = 2\nOutput: [0,2]\nExplanation: \nThe number of soldiers in each row is: \n- Row 0: 1 \n- Row 1: 4 \n- Row 2: 1 \n- Row 3: 1 \nThe rows ordered from weakest to strongest are [0,2,3,1].\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == mat.length
    • \n\t
    • n == mat[i].length
    • \n\t
    • 2 <= n, m <= 100
    • \n\t
    • 1 <= k <= m
    • \n\t
    • matrix[i][j] is either 0 or 1.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5927\u5c0f\u4e3a\u00a0m\u00a0* n\u00a0\u7684\u77e9\u9635\u00a0mat\uff0c\u77e9\u9635\u7531\u82e5\u5e72\u519b\u4eba\u548c\u5e73\u6c11\u7ec4\u6210\uff0c\u5206\u522b\u7528 1 \u548c 0 \u8868\u793a\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u77e9\u9635\u4e2d\u6218\u6597\u529b\u6700\u5f31\u7684\u00a0k\u00a0\u884c\u7684\u7d22\u5f15\uff0c\u6309\u4ece\u6700\u5f31\u5230\u6700\u5f3a\u6392\u5e8f\u3002

    \n\n

    \u5982\u679c\u7b2c\u00a0i\u00a0\u884c\u7684\u519b\u4eba\u6570\u91cf\u5c11\u4e8e\u7b2c\u00a0j\u00a0\u884c\uff0c\u6216\u8005\u4e24\u884c\u519b\u4eba\u6570\u91cf\u76f8\u540c\u4f46 i \u5c0f\u4e8e j\uff0c\u90a3\u4e48\u6211\u4eec\u8ba4\u4e3a\u7b2c i \u884c\u7684\u6218\u6597\u529b\u6bd4\u7b2c j \u884c\u5f31\u3002

    \n\n

    \u519b\u4eba \u603b\u662f \u6392\u5728\u4e00\u884c\u4e2d\u7684\u9760\u524d\u4f4d\u7f6e\uff0c\u4e5f\u5c31\u662f\u8bf4 1 \u603b\u662f\u51fa\u73b0\u5728 0 \u4e4b\u524d\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1amat = \n[[1,1,0,0,0],\n [1,1,1,1,0],\n [1,0,0,0,0],\n [1,1,0,0,0],\n [1,1,1,1,1]], \nk = 3\n\u8f93\u51fa\uff1a[2,0,3]\n\u89e3\u91ca\uff1a\n\u6bcf\u884c\u4e2d\u7684\u519b\u4eba\u6570\u76ee\uff1a\n\u884c 0 -> 2 \n\u884c 1 -> 4 \n\u884c 2 -> 1 \n\u884c 3 -> 2 \n\u884c 4 -> 5 \n\u4ece\u6700\u5f31\u5230\u6700\u5f3a\u5bf9\u8fd9\u4e9b\u884c\u6392\u5e8f\u540e\u5f97\u5230 [2,0,3,1,4]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1amat = \n[[1,0,0,0],\n\u00a0[1,1,1,1],\n\u00a0[1,0,0,0],\n\u00a0[1,0,0,0]], \nk = 2\n\u8f93\u51fa\uff1a[0,2]\n\u89e3\u91ca\uff1a \n\u6bcf\u884c\u4e2d\u7684\u519b\u4eba\u6570\u76ee\uff1a\n\u884c 0 -> 1 \n\u884c 1 -> 4 \n\u884c 2 -> 1 \n\u884c 3 -> 1 \n\u4ece\u6700\u5f31\u5230\u6700\u5f3a\u5bf9\u8fd9\u4e9b\u884c\u6392\u5e8f\u540e\u5f97\u5230 [0,2,3,1]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == mat.length
    • \n\t
    • n == mat[i].length
    • \n\t
    • 2 <= n, m <= 100
    • \n\t
    • 1 <= k <= m
    • \n\t
    • matrix[i][j] \u4e0d\u662f 0 \u5c31\u662f 1
    • \n
    \n", "tags_en": ["Array", "Binary Search"], "tags_cn": ["\u6570\u7ec4", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector kWeakestRows(vector>& mat, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] kWeakestRows(int[][] mat, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def kWeakestRows(self, mat, k):\n \"\"\"\n :type mat: List[List[int]]\n :type k: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def kWeakestRows(self, mat: List[List[int]], k: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* kWeakestRows(int** mat, int matSize, int* matColSize, int k, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] KWeakestRows(int[][] mat, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} mat\n * @param {number} k\n * @return {number[]}\n */\nvar kWeakestRows = function(mat, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} mat\n# @param {Integer} k\n# @return {Integer[]}\ndef k_weakest_rows(mat, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func kWeakestRows(_ mat: [[Int]], _ k: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func kWeakestRows(mat [][]int, k int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def kWeakestRows(mat: Array[Array[Int]], k: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun kWeakestRows(mat: Array, k: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn k_weakest_rows(mat: Vec>, k: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $mat\n * @param Integer $k\n * @return Integer[]\n */\n function kWeakestRows($mat, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function kWeakestRows(mat: number[][], k: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (k-weakest-rows mat k)\n (-> (listof (listof exact-integer?)) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1337](https://leetcode-cn.com/problems/the-k-weakest-rows-in-a-matrix)", "[\u77e9\u9635\u4e2d\u6218\u6597\u529b\u6700\u5f31\u7684 K \u884c](/solution/1300-1399/1337.The%20K%20Weakest%20Rows%20in%20a%20Matrix/README.md)", "`\u6570\u7ec4`,`\u4e8c\u5206\u67e5\u627e`", "\u7b80\u5355", ""], "md_table_row_en": ["[1337](https://leetcode.com/problems/the-k-weakest-rows-in-a-matrix)", "[The K Weakest Rows in a Matrix](/solution/1300-1399/1337.The%20K%20Weakest%20Rows%20in%20a%20Matrix/README_EN.md)", "`Array`,`Binary Search`", "Easy", ""]}, {"question_id": "1462", "frontend_question_id": "1327", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/list-the-products-ordered-in-a-period", "url_en": "https://leetcode.com/problems/list-the-products-ordered-in-a-period", "relative_path_cn": "/solution/1300-1399/1327.List%20the%20Products%20Ordered%20in%20a%20Period/README.md", "relative_path_en": "/solution/1300-1399/1327.List%20the%20Products%20Ordered%20in%20a%20Period/README_EN.md", "title_cn": "\u5217\u51fa\u6307\u5b9a\u65f6\u95f4\u6bb5\u5185\u6240\u6709\u7684\u4e0b\u5355\u4ea7\u54c1", "title_en": "List the Products Ordered in a Period", "question_title_slug": "list-the-products-ordered-in-a-period", "content_en": "

    Table: Products

    \n\n
    \n+------------------+---------+\n| Column Name      | Type    |\n+------------------+---------+\n| product_id       | int     |\n| product_name     | varchar |\n| product_category | varchar |\n+------------------+---------+\nproduct_id is the primary key for this table.\nThis table contains data about the company's products.\n
    \n\n

    Table: Orders

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| product_id    | int     |\n| order_date    | date    |\n| unit          | int     |\n+---------------+---------+\nThere is no primary key for this table. It may have duplicate rows.\nproduct_id is a foreign key to Products table.\nunit is the number of products ordered in order_date.\n
    \n\n

     

    \n\n

    Write an SQL query to get the names of products with greater than or equal to 100 units ordered in February 2020 and their amount.

    \n\n

    Return result table in any order.

    \n\n

    The query result format is in the following example:

    \n\n

     

    \n\n
    \nProducts table:\n+-------------+-----------------------+------------------+\n| product_id  | product_name          | product_category |\n+-------------+-----------------------+------------------+\n| 1           | Leetcode Solutions    | Book             |\n| 2           | Jewels of Stringology | Book             |\n| 3           | HP                    | Laptop           |\n| 4           | Lenovo                | Laptop           |\n| 5           | Leetcode Kit          | T-shirt          |\n+-------------+-----------------------+------------------+\n\nOrders table:\n+--------------+--------------+----------+\n| product_id   | order_date   | unit     |\n+--------------+--------------+----------+\n| 1            | 2020-02-05   | 60       |\n| 1            | 2020-02-10   | 70       |\n| 2            | 2020-01-18   | 30       |\n| 2            | 2020-02-11   | 80       |\n| 3            | 2020-02-17   | 2        |\n| 3            | 2020-02-24   | 3        |\n| 4            | 2020-03-01   | 20       |\n| 4            | 2020-03-04   | 30       |\n| 4            | 2020-03-04   | 60       |\n| 5            | 2020-02-25   | 50       |\n| 5            | 2020-02-27   | 50       |\n| 5            | 2020-03-01   | 50       |\n+--------------+--------------+----------+\n\nResult table:\n+--------------------+---------+\n| product_name       | unit    |\n+--------------------+---------+\n| Leetcode Solutions | 130     |\n| Leetcode Kit       | 100     |\n+--------------------+---------+\n\nProducts with product_id = 1 is ordered in February a total of (60 + 70) = 130.\nProducts with product_id = 2 is ordered in February a total of 80.\nProducts with product_id = 3 is ordered in February a total of (2 + 3) = 5.\nProducts with product_id = 4 was not ordered in February 2020.\nProducts with product_id = 5 is ordered in February a total of (50 + 50) = 100.\n
    \n", "content_cn": "

    \u8868: Products

    \n\n
    +------------------+---------+\n| Column Name      | Type    |\n+------------------+---------+\n| product_id       | int     |\n| product_name     | varchar |\n| product_category | varchar |\n+------------------+---------+\nproduct_id \u662f\u8be5\u8868\u4e3b\u952e\u3002\n\u8be5\u8868\u5305\u542b\u8be5\u516c\u53f8\u4ea7\u54c1\u7684\u6570\u636e\u3002\n
    \n\n

    \u8868: Orders

    \n\n
    +---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| product_id    | int     |\n| order_date    | date    |\n| unit          | int     |\n+---------------+---------+\n\u8be5\u8868\u65e0\u4e3b\u952e\uff0c\u53ef\u80fd\u5305\u542b\u91cd\u590d\u884c\u3002\nproduct_id \u662f\u8868\u5355 Products \u7684\u5916\u952e\u3002\nunit \u662f\u5728\u65e5\u671f order_date \u5185\u4e0b\u5355\u4ea7\u54c1\u7684\u6570\u76ee\u3002\n
    \n\n

     

    \n\n

    \u5199\u4e00\u4e2a SQL \u8bed\u53e5\uff0c\u8981\u6c42\u83b7\u53d6\u5728 2020 \u5e74 2 \u6708\u4efd\u4e0b\u5355\u7684\u6570\u91cf\u4e0d\u5c11\u4e8e 100 \u7684\u4ea7\u54c1\u7684\u540d\u5b57\u548c\u6570\u76ee\u3002

    \n\n

    \u8fd4\u56de\u7ed3\u679c\u8868\u5355\u7684\u987a\u5e8f\u65e0\u8981\u6c42\u3002

    \n\n

     

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u7684\u683c\u5f0f\u5982\u4e0b\uff1a

    \n\n
    Products \u8868:\n+-------------+-----------------------+------------------+\n| product_id  | product_name          | product_category |\n+-------------+-----------------------+------------------+\n| 1           | Leetcode Solutions    | Book             |\n| 2           | Jewels of Stringology | Book             |\n| 3           | HP                    | Laptop           |\n| 4           | Lenovo                | Laptop           |\n| 5           | Leetcode Kit          | T-shirt          |\n+-------------+-----------------------+------------------+\n\nOrders \u8868:\n+--------------+--------------+----------+\n| product_id   | order_date   | unit     |\n+--------------+--------------+----------+\n| 1            | 2020-02-05   | 60       |\n| 1            | 2020-02-10   | 70       |\n| 2            | 2020-01-18   | 30       |\n| 2            | 2020-02-11   | 80       |\n| 3            | 2020-02-17   | 2        |\n| 3            | 2020-02-24   | 3        |\n| 4            | 2020-03-01   | 20       |\n| 4            | 2020-03-04   | 30       |\n| 4            | 2020-03-04   | 60       |\n| 5            | 2020-02-25   | 50       |\n| 5            | 2020-02-27   | 50       |\n| 5            | 2020-03-01   | 50       |\n+--------------+--------------+----------+\n\nResult \u8868:\n+--------------------+---------+\n| product_name       | unit    |\n+--------------------+---------+\n| Leetcode Solutions | 130     |\n| Leetcode Kit       | 100     |\n+--------------------+---------+\n\n2020 \u5e74 2 \u6708\u4efd\u4e0b\u5355 product_id = 1 \u7684\u4ea7\u54c1\u7684\u6570\u76ee\u603b\u548c\u4e3a (60 + 70) = 130 \u3002\n2020 \u5e74 2 \u6708\u4efd\u4e0b\u5355 product_id = 2 \u7684\u4ea7\u54c1\u7684\u6570\u76ee\u603b\u548c\u4e3a 80 \u3002\n2020 \u5e74 2 \u6708\u4efd\u4e0b\u5355 product_id = 3 \u7684\u4ea7\u54c1\u7684\u6570\u76ee\u603b\u548c\u4e3a (2 + 3) = 5 \u3002\n2020 \u5e74 2 \u6708\u4efd product_id = 4 \u7684\u4ea7\u54c1\u5e76\u6ca1\u6709\u4e0b\u5355\u3002\n2020 \u5e74 2 \u6708\u4efd\u4e0b\u5355 product_id = 5 \u7684\u4ea7\u54c1\u7684\u6570\u76ee\u603b\u548c\u4e3a (50 + 50) = 100 \u3002\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1327](https://leetcode-cn.com/problems/list-the-products-ordered-in-a-period)", "[\u5217\u51fa\u6307\u5b9a\u65f6\u95f4\u6bb5\u5185\u6240\u6709\u7684\u4e0b\u5355\u4ea7\u54c1](/solution/1300-1399/1327.List%20the%20Products%20Ordered%20in%20a%20Period/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1327](https://leetcode.com/problems/list-the-products-ordered-in-a-period)", "[List the Products Ordered in a Period](/solution/1300-1399/1327.List%20the%20Products%20Ordered%20in%20a%20Period/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1461", "frontend_question_id": "1359", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-all-valid-pickup-and-delivery-options", "url_en": "https://leetcode.com/problems/count-all-valid-pickup-and-delivery-options", "relative_path_cn": "/solution/1300-1399/1359.Count%20All%20Valid%20Pickup%20and%20Delivery%20Options/README.md", "relative_path_en": "/solution/1300-1399/1359.Count%20All%20Valid%20Pickup%20and%20Delivery%20Options/README_EN.md", "title_cn": "\u6709\u6548\u7684\u5feb\u9012\u5e8f\u5217\u6570\u76ee", "title_en": "Count All Valid Pickup and Delivery Options", "question_title_slug": "count-all-valid-pickup-and-delivery-options", "content_en": "

    Given n orders, each order consist in pickup and delivery services. 

    \n\n

    Count all valid pickup/delivery possible sequences such that delivery(i) is always after of pickup(i). 

    \n\n

    Since the answer may be too large, return it modulo 10^9 + 7.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 1\nOutput: 1\nExplanation: Unique order (P1, D1), Delivery 1 always is after of Pickup 1.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 2\nOutput: 6\nExplanation: All possible orders: \n(P1,P2,D1,D2), (P1,P2,D2,D1), (P1,D1,P2,D2), (P2,P1,D1,D2), (P2,P1,D2,D1) and (P2,D2,P1,D1).\nThis is an invalid order (P1,D2,P2,D1) because Pickup 2 is after of Delivery 2.\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 3\nOutput: 90\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 500
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60 n \u7b14\u8ba2\u5355\uff0c\u6bcf\u7b14\u8ba2\u5355\u90fd\u9700\u8981\u5feb\u9012\u670d\u52a1\u3002

    \n\n

    \u8bf7\u4f60\u7edf\u8ba1\u6240\u6709\u6709\u6548\u7684 \u6536\u4ef6/\u914d\u9001 \u5e8f\u5217\u7684\u6570\u76ee\uff0c\u786e\u4fdd\u7b2c i \u4e2a\u7269\u54c1\u7684\u914d\u9001\u670d\u52a1 delivery(i) \u603b\u662f\u5728\u5176\u6536\u4ef6\u670d\u52a1 pickup(i) \u4e4b\u540e\u3002

    \n\n

    \u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u5f88\u5927\uff0c\u8bf7\u8fd4\u56de\u7b54\u6848\u5bf9 10^9 + 7 \u53d6\u4f59\u7684\u7ed3\u679c\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u53ea\u6709\u4e00\u79cd\u5e8f\u5217 (P1, D1)\uff0c\u7269\u54c1 1 \u7684\u914d\u9001\u670d\u52a1\uff08D1\uff09\u5728\u7269\u54c1 1 \u7684\u6536\u4ef6\u670d\u52a1\uff08P1\uff09\u540e\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1an = 2\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u6240\u6709\u53ef\u80fd\u7684\u5e8f\u5217\u5305\u62ec\uff1a\n(P1,P2,D1,D2)\uff0c(P1,P2,D2,D1)\uff0c(P1,D1,P2,D2)\uff0c(P2,P1,D1,D2)\uff0c(P2,P1,D2,D1) \u548c (P2,D2,P1,D1)\u3002\n(P1,D2,P2,D1) \u662f\u4e00\u4e2a\u65e0\u6548\u7684\u5e8f\u5217\uff0c\u56e0\u4e3a\u7269\u54c1 2 \u7684\u6536\u4ef6\u670d\u52a1\uff08P2\uff09\u4e0d\u5e94\u5728\u7269\u54c1 2 \u7684\u914d\u9001\u670d\u52a1\uff08D2\uff09\u4e4b\u540e\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1an = 3\n\u8f93\u51fa\uff1a90\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 500
    • \n
    \n", "tags_en": ["Math", "Dynamic Programming"], "tags_cn": ["\u6570\u5b66", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countOrders(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countOrders(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countOrders(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countOrders(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countOrders(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountOrders(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar countOrders = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef count_orders(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countOrders(_ n: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countOrders(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countOrders(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countOrders(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_orders(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function countOrders($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countOrders(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-orders n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1359](https://leetcode-cn.com/problems/count-all-valid-pickup-and-delivery-options)", "[\u6709\u6548\u7684\u5feb\u9012\u5e8f\u5217\u6570\u76ee](/solution/1300-1399/1359.Count%20All%20Valid%20Pickup%20and%20Delivery%20Options/README.md)", "`\u6570\u5b66`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1359](https://leetcode.com/problems/count-all-valid-pickup-and-delivery-options)", "[Count All Valid Pickup and Delivery Options](/solution/1300-1399/1359.Count%20All%20Valid%20Pickup%20and%20Delivery%20Options/README_EN.md)", "`Math`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "1460", "frontend_question_id": "1358", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-substrings-containing-all-three-characters", "url_en": "https://leetcode.com/problems/number-of-substrings-containing-all-three-characters", "relative_path_cn": "/solution/1300-1399/1358.Number%20of%20Substrings%20Containing%20All%20Three%20Characters/README.md", "relative_path_en": "/solution/1300-1399/1358.Number%20of%20Substrings%20Containing%20All%20Three%20Characters/README_EN.md", "title_cn": "\u5305\u542b\u6240\u6709\u4e09\u79cd\u5b57\u7b26\u7684\u5b50\u5b57\u7b26\u4e32\u6570\u76ee", "title_en": "Number of Substrings Containing All Three Characters", "question_title_slug": "number-of-substrings-containing-all-three-characters", "content_en": "

    Given a string s consisting only of characters a, b and c.

    \n\n

    Return the number of substrings containing at least one occurrence of all these characters a, b and c.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "abcabc"\nOutput: 10\nExplanation: The substrings containing at least one occurrence of the characters ab and c are "abc", "abca", "abcab", "abcabc", "bca", "bcab", "bcabc", "cab", "cabc" and "abc" (again). \n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "aaacb"\nOutput: 3\nExplanation: The substrings containing at least one occurrence of the characters ab and c are "aaacb", "aacb" and "acb". \n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "abc"\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 3 <= s.length <= 5 x 10^4
    • \n\t
    • s only consists of a, b or characters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \uff0c\u5b83\u53ea\u5305\u542b\u4e09\u79cd\u5b57\u7b26 a, b \u548c c \u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de a\uff0cb \u548c c \u90fd \u81f3\u5c11 \u51fa\u73b0\u8fc7\u4e00\u6b21\u7684\u5b50\u5b57\u7b26\u4e32\u6570\u76ee\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1as = "abcabc"\n\u8f93\u51fa\uff1a10\n\u89e3\u91ca\uff1a\u5305\u542b a\uff0cb \u548c c \u5404\u81f3\u5c11\u4e00\u6b21\u7684\u5b50\u5b57\u7b26\u4e32\u4e3a "abc", "abca", "abcab", "abcabc", "bca", "bcab", "bcabc", "cab", "cabc" \u548c "abc" (\u76f8\u540c\u5b57\u7b26\u4e32\u7b97\u591a\u6b21)\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1as = "aaacb"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u5305\u542b a\uff0cb \u548c c \u5404\u81f3\u5c11\u4e00\u6b21\u7684\u5b50\u5b57\u7b26\u4e32\u4e3a "aaacb", "aacb" \u548c "acb" \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1as = "abc"\n\u8f93\u51fa\uff1a1\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 3 <= s.length <= 5 x 10^4
    • \n\t
    • s \u53ea\u5305\u542b\u5b57\u7b26 a\uff0cb \u548c c \u3002
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numberOfSubstrings(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numberOfSubstrings(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numberOfSubstrings(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numberOfSubstrings(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numberOfSubstrings(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumberOfSubstrings(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar numberOfSubstrings = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef number_of_substrings(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numberOfSubstrings(_ s: String) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numberOfSubstrings(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numberOfSubstrings(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numberOfSubstrings(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn number_of_substrings(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function numberOfSubstrings($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numberOfSubstrings(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (number-of-substrings s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1358](https://leetcode-cn.com/problems/number-of-substrings-containing-all-three-characters)", "[\u5305\u542b\u6240\u6709\u4e09\u79cd\u5b57\u7b26\u7684\u5b50\u5b57\u7b26\u4e32\u6570\u76ee](/solution/1300-1399/1358.Number%20of%20Substrings%20Containing%20All%20Three%20Characters/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1358](https://leetcode.com/problems/number-of-substrings-containing-all-three-characters)", "[Number of Substrings Containing All Three Characters](/solution/1300-1399/1358.Number%20of%20Substrings%20Containing%20All%20Three%20Characters/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "1459", "frontend_question_id": "1357", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/apply-discount-every-n-orders", "url_en": "https://leetcode.com/problems/apply-discount-every-n-orders", "relative_path_cn": "/solution/1300-1399/1357.Apply%20Discount%20Every%20n%20Orders/README.md", "relative_path_en": "/solution/1300-1399/1357.Apply%20Discount%20Every%20n%20Orders/README_EN.md", "title_cn": "\u6bcf\u9694 n \u4e2a\u987e\u5ba2\u6253\u6298", "title_en": "Apply Discount Every n Orders", "question_title_slug": "apply-discount-every-n-orders", "content_en": "

    There is a sale in a supermarket, there will be a discount every n customer.
    \nThere are some products in the supermarket where the id of the i-th product is products[i] and the price per unit of this product is prices[i].
    \nThe system will count the number of customers and when the n-th customer arrive he/she will have a discount on the bill. (i.e if the cost is x the new cost is x - (discount * x) / 100). Then the system will start counting customers again.
    \nThe customer orders a certain amount of each product where product[i] is the id of the i-th product the customer ordered and amount[i] is the number of units the customer ordered of that product.

    \n\n

    Implement the Cashier class:

    \n\n
      \n\t
    • Cashier(int n, int discount, int[] products, int[] prices) Initializes the object with n, the discount, the products and their prices.
    • \n\t
    • double getBill(int[] product, int[] amount) returns the value of the bill and apply the discount if needed. Answers within 10^-5 of the actual value will be accepted as correct.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["Cashier","getBill","getBill","getBill","getBill","getBill","getBill","getBill"]\n[[3,50,[1,2,3,4,5,6,7],[100,200,300,400,300,200,100]],[[1,2],[1,2]],[[3,7],[10,10]],[[1,2,3,4,5,6,7],[1,1,1,1,1,1,1]],[[4],[10]],[[7,3],[10,10]],[[7,5,3,1,6,4,2],[10,10,10,9,9,9,7]],[[2,3,5],[5,3,2]]]\nOutput\n[null,500.0,4000.0,800.0,4000.0,4000.0,7350.0,2500.0]\nExplanation\nCashier cashier = new Cashier(3,50,[1,2,3,4,5,6,7],[100,200,300,400,300,200,100]);\ncashier.getBill([1,2],[1,2]);                        // return 500.0, bill = 1 * 100 + 2 * 200 = 500.\ncashier.getBill([3,7],[10,10]);                      // return 4000.0\ncashier.getBill([1,2,3,4,5,6,7],[1,1,1,1,1,1,1]);    // return 800.0, The bill was 1600.0 but as this is the third customer, he has a discount of 50% which means his bill is only 1600 - 1600 * (50 / 100) = 800.\ncashier.getBill([4],[10]);                           // return 4000.0\ncashier.getBill([7,3],[10,10]);                      // return 4000.0\ncashier.getBill([7,5,3,1,6,4,2],[10,10,10,9,9,9,7]); // return 7350.0, Bill was 14700.0 but as the system counted three more customers, he will have a 50% discount and the bill becomes 7350.0\ncashier.getBill([2,3,5],[5,3,2]);                    // return 2500.0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 10^4
    • \n\t
    • 0 <= discount <= 100
    • \n\t
    • 1 <= products.length <= 200
    • \n\t
    • 1 <= products[i] <= 200
    • \n\t
    • There are not repeated elements in the array products.
    • \n\t
    • prices.length == products.length
    • \n\t
    • 1 <= prices[i] <= 1000
    • \n\t
    • 1 <= product.length <= products.length
    • \n\t
    • product[i] exists in products.
    • \n\t
    • amount.length == product.length
    • \n\t
    • 1 <= amount[i] <= 1000
    • \n\t
    • At most 1000 calls will be made to getBill.
    • \n\t
    • Answers within 10^-5 of the actual value will be accepted as correct.
    • \n
    \n", "content_cn": "

    \u8d85\u5e02\u91cc\u6b63\u5728\u4e3e\u884c\u6253\u6298\u6d3b\u52a8\uff0c\u6bcf\u9694 n \u4e2a\u987e\u5ba2\u4f1a\u5f97\u5230 discount \u7684\u6298\u6263\u3002

    \n\n

    \u8d85\u5e02\u91cc\u6709\u4e00\u4e9b\u5546\u54c1\uff0c\u7b2c i \u79cd\u5546\u54c1\u4e3a products[i] \u4e14\u6bcf\u4ef6\u5355\u54c1\u7684\u4ef7\u683c\u4e3a prices[i] \u3002

    \n\n

    \u7ed3\u8d26\u7cfb\u7edf\u4f1a\u7edf\u8ba1\u987e\u5ba2\u7684\u6570\u76ee\uff0c\u6bcf\u9694 n \u4e2a\u987e\u5ba2\u7ed3\u8d26\u65f6\uff0c\u8be5\u987e\u5ba2\u7684\u8d26\u5355\u90fd\u4f1a\u6253\u6298\uff0c\u6298\u6263\u4e3a discount \uff08\u4e5f\u5c31\u662f\u5982\u679c\u539f\u672c\u8d26\u5355\u4e3a x \uff0c\u90a3\u4e48\u5b9e\u9645\u91d1\u989d\u4f1a\u53d8\u6210 x - (discount * x) / 100 \uff09\uff0c\u7136\u540e\u7cfb\u7edf\u4f1a\u91cd\u65b0\u5f00\u59cb\u8ba1\u6570\u3002

    \n\n

    \u987e\u5ba2\u4f1a\u8d2d\u4e70\u4e00\u4e9b\u5546\u54c1\uff0c product[i] \u662f\u987e\u5ba2\u8d2d\u4e70\u7684\u7b2c i \u79cd\u5546\u54c1\uff0c amount[i] \u662f\u5bf9\u5e94\u7684\u8d2d\u4e70\u8be5\u79cd\u5546\u54c1\u7684\u6570\u76ee\u3002

    \n\n

    \u8bf7\u4f60\u5b9e\u73b0 Cashier \u7c7b\uff1a

    \n\n
      \n\t
    • Cashier(int n, int discount, int[] products, int[] prices) \u521d\u59cb\u5316\u5b9e\u4f8b\u5bf9\u8c61\uff0c\u53c2\u6570\u5206\u522b\u4e3a\u6253\u6298\u9891\u7387 n \uff0c\u6298\u6263\u5927\u5c0f discount \uff0c\u8d85\u5e02\u91cc\u7684\u5546\u54c1\u5217\u8868 products \u548c\u5b83\u4eec\u7684\u4ef7\u683c prices \u3002
    • \n\t
    • double getBill(int[] product, int[] amount) \u8fd4\u56de\u8d26\u5355\u7684\u5b9e\u9645\u91d1\u989d\uff08\u5982\u679c\u6709\u6253\u6298\uff0c\u8bf7\u8fd4\u56de\u6253\u6298\u540e\u7684\u7ed3\u679c\uff09\u3002\u8fd4\u56de\u7ed3\u679c\u4e0e\u6807\u51c6\u7b54\u6848\u8bef\u5dee\u5728 10^-5 \u4ee5\u5185\u90fd\u89c6\u4e3a\u6b63\u786e\u7ed3\u679c\u3002
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\n["Cashier","getBill","getBill","getBill","getBill","getBill","getBill","getBill"]\n[[3,50,[1,2,3,4,5,6,7],[100,200,300,400,300,200,100]],[[1,2],[1,2]],[[3,7],[10,10]],[[1,2,3,4,5,6,7],[1,1,1,1,1,1,1]],[[4],[10]],[[7,3],[10,10]],[[7,5,3,1,6,4,2],[10,10,10,9,9,9,7]],[[2,3,5],[5,3,2]]]\n\u8f93\u51fa\n[null,500.0,4000.0,800.0,4000.0,4000.0,7350.0,2500.0]\n\u89e3\u91ca\nCashier cashier = new Cashier(3,50,[1,2,3,4,5,6,7],[100,200,300,400,300,200,100]);\ncashier.getBill([1,2],[1,2]);                        // \u8fd4\u56de 500.0, \u8d26\u5355\u91d1\u989d\u4e3a = 1 * 100 + 2 * 200 = 500.\ncashier.getBill([3,7],[10,10]);                      // \u8fd4\u56de 4000.0\ncashier.getBill([1,2,3,4,5,6,7],[1,1,1,1,1,1,1]);    // \u8fd4\u56de 800.0 \uff0c\u8d26\u5355\u539f\u672c\u4e3a 1600.0 \uff0c\u4f46\u7531\u4e8e\u8be5\u987e\u5ba2\u662f\u7b2c\u4e09\u4f4d\u987e\u5ba2\uff0c\u4ed6\u5c06\u5f97\u5230 50% \u7684\u6298\u6263\uff0c\u6240\u4ee5\u5b9e\u9645\u91d1\u989d\u4e3a 1600 - 1600 * (50 / 100) = 800 \u3002\ncashier.getBill([4],[10]);                           // \u8fd4\u56de 4000.0\ncashier.getBill([7,3],[10,10]);                      // \u8fd4\u56de 4000.0\ncashier.getBill([7,5,3,1,6,4,2],[10,10,10,9,9,9,7]); // \u8fd4\u56de 7350.0 \uff0c\u8d26\u5355\u539f\u672c\u4e3a 14700.0 \uff0c\u4f46\u7531\u4e8e\u7cfb\u7edf\u8ba1\u6570\u518d\u6b21\u8fbe\u5230\u4e09\uff0c\u8be5\u987e\u5ba2\u5c06\u5f97\u5230 50% \u7684\u6298\u6263\uff0c\u5b9e\u9645\u91d1\u989d\u4e3a 7350.0 \u3002\ncashier.getBill([2,3,5],[5,3,2]);                    // \u8fd4\u56de 2500.0\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 10^4
    • \n\t
    • 0 <= discount <= 100
    • \n\t
    • 1 <= products.length <= 200
    • \n\t
    • 1 <= products[i] <= 200
    • \n\t
    • products \u5217\u8868\u4e2d \u4e0d\u4f1a \u6709\u91cd\u590d\u7684\u5143\u7d20\u3002
    • \n\t
    • prices.length == products.length
    • \n\t
    • 1 <= prices[i] <= 1000
    • \n\t
    • 1 <= product.length <= products.length
    • \n\t
    • product[i] \u5728 products \u51fa\u73b0\u8fc7\u3002
    • \n\t
    • amount.length == product.length
    • \n\t
    • 1 <= amount[i] <= 1000
    • \n\t
    • \u6700\u591a\u6709 1000 \u6b21\u5bf9 getBill \u51fd\u6570\u7684\u8c03\u7528\u3002
    • \n\t
    • \u8fd4\u56de\u7ed3\u679c\u4e0e\u6807\u51c6\u7b54\u6848\u8bef\u5dee\u5728 10^-5 \u4ee5\u5185\u90fd\u89c6\u4e3a\u6b63\u786e\u7ed3\u679c\u3002
    • \n
    \n", "tags_en": ["Design"], "tags_cn": ["\u8bbe\u8ba1"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Cashier {\npublic:\n Cashier(int n, int discount, vector& products, vector& prices) {\n\n }\n \n double getBill(vector product, vector amount) {\n\n }\n};\n\n/**\n * Your Cashier object will be instantiated and called as such:\n * Cashier* obj = new Cashier(n, discount, products, prices);\n * double param_1 = obj->getBill(product,amount);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Cashier {\n\n public Cashier(int n, int discount, int[] products, int[] prices) {\n\n }\n \n public double getBill(int[] product, int[] amount) {\n\n }\n}\n\n/**\n * Your Cashier object will be instantiated and called as such:\n * Cashier obj = new Cashier(n, discount, products, prices);\n * double param_1 = obj.getBill(product,amount);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Cashier(object):\n\n def __init__(self, n, discount, products, prices):\n \"\"\"\n :type n: int\n :type discount: int\n :type products: List[int]\n :type prices: List[int]\n \"\"\"\n\n\n def getBill(self, product, amount):\n \"\"\"\n :type product: List[int]\n :type amount: List[int]\n :rtype: float\n \"\"\"\n\n\n\n# Your Cashier object will be instantiated and called as such:\n# obj = Cashier(n, discount, products, prices)\n# param_1 = obj.getBill(product,amount)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Cashier:\n\n def __init__(self, n: int, discount: int, products: List[int], prices: List[int]):\n\n\n def getBill(self, product: List[int], amount: List[int]) -> float:\n\n\n\n# Your Cashier object will be instantiated and called as such:\n# obj = Cashier(n, discount, products, prices)\n# param_1 = obj.getBill(product,amount)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} Cashier;\n\n\nCashier* cashierCreate(int n, int discount, int* products, int productsSize, int* prices, int pricesSize) {\n\n}\n\ndouble cashierGetBill(Cashier* obj, int* product, int productSize, int* amount, int amountSize) {\n\n}\n\nvoid cashierFree(Cashier* obj) {\n\n}\n\n/**\n * Your Cashier struct will be instantiated and called as such:\n * Cashier* obj = cashierCreate(n, discount, products, productsSize, prices, pricesSize);\n * double param_1 = cashierGetBill(obj, product, productSize, amount, amountSize);\n \n * cashierFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Cashier {\n\n public Cashier(int n, int discount, int[] products, int[] prices) {\n\n }\n \n public double GetBill(int[] product, int[] amount) {\n\n }\n}\n\n/**\n * Your Cashier object will be instantiated and called as such:\n * Cashier obj = new Cashier(n, discount, products, prices);\n * double param_1 = obj.GetBill(product,amount);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} discount\n * @param {number[]} products\n * @param {number[]} prices\n */\nvar Cashier = function(n, discount, products, prices) {\n\n};\n\n/** \n * @param {number[]} product \n * @param {number[]} amount\n * @return {number}\n */\nCashier.prototype.getBill = function(product, amount) {\n\n};\n\n/**\n * Your Cashier object will be instantiated and called as such:\n * var obj = new Cashier(n, discount, products, prices)\n * var param_1 = obj.getBill(product,amount)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class Cashier\n\n=begin\n :type n: Integer\n :type discount: Integer\n :type products: Integer[]\n :type prices: Integer[]\n=end\n def initialize(n, discount, products, prices)\n\n end\n\n\n=begin\n :type product: Integer[]\n :type amount: Integer[]\n :rtype: Float\n=end\n def get_bill(product, amount)\n\n end\n\n\nend\n\n# Your Cashier object will be instantiated and called as such:\n# obj = Cashier.new(n, discount, products, prices)\n# param_1 = obj.get_bill(product, amount)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass Cashier {\n\n init(_ n: Int, _ discount: Int, _ products: [Int], _ prices: [Int]) {\n\n }\n \n func getBill(_ product: [Int], _ amount: [Int]) -> Double {\n\n }\n}\n\n/**\n * Your Cashier object will be instantiated and called as such:\n * let obj = Cashier(n, discount, products, prices)\n * let ret_1: Double = obj.getBill(product, amount)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type Cashier struct {\n\n}\n\n\nfunc Constructor(n int, discount int, products []int, prices []int) Cashier {\n\n}\n\n\nfunc (this *Cashier) GetBill(product []int, amount []int) float64 {\n\n}\n\n\n/**\n * Your Cashier object will be instantiated and called as such:\n * obj := Constructor(n, discount, products, prices);\n * param_1 := obj.GetBill(product,amount);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class Cashier(_n: Int, _discount: Int, _products: Array[Int], _prices: Array[Int]) {\n\n def getBill(product: Array[Int], amount: Array[Int]): Double = {\n\n }\n\n}\n\n/**\n * Your Cashier object will be instantiated and called as such:\n * var obj = new Cashier(n, discount, products, prices)\n * var param_1 = obj.getBill(product,amount)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Cashier(n: Int, discount: Int, products: IntArray, prices: IntArray) {\n\n fun getBill(product: IntArray, amount: IntArray): Double {\n\n }\n\n}\n\n/**\n * Your Cashier object will be instantiated and called as such:\n * var obj = Cashier(n, discount, products, prices)\n * var param_1 = obj.getBill(product,amount)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct Cashier {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl Cashier {\n\n fn new(n: i32, discount: i32, products: Vec, prices: Vec) -> Self {\n\n }\n \n fn get_bill(&self, product: Vec, amount: Vec) -> f64 {\n\n }\n}\n\n/**\n * Your Cashier object will be instantiated and called as such:\n * let obj = Cashier::new(n, discount, products, prices);\n * let ret_1: f64 = obj.get_bill(product, amount);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Cashier {\n /**\n * @param Integer $n\n * @param Integer $discount\n * @param Integer[] $products\n * @param Integer[] $prices\n */\n function __construct($n, $discount, $products, $prices) {\n\n }\n\n /**\n * @param Integer[] $product\n * @param Integer[] $amount\n * @return Float\n */\n function getBill($product, $amount) {\n\n }\n}\n\n/**\n * Your Cashier object will be instantiated and called as such:\n * $obj = Cashier($n, $discount, $products, $prices);\n * $ret_1 = $obj->getBill($product, $amount);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class Cashier {\n constructor(n: number, discount: number, products: number[], prices: number[]) {\n\n }\n\n getBill(product: number[], amount: number[]): number {\n\n }\n}\n\n/**\n * Your Cashier object will be instantiated and called as such:\n * var obj = new Cashier(n, discount, products, prices)\n * var param_1 = obj.getBill(product,amount)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define cashier%\n (class object%\n (super-new)\n\n ; n : exact-integer?\n\n ; discount : exact-integer?\n\n ; products : (listof exact-integer?)\n\n ; prices : (listof exact-integer?)\n (init-field\n n\n discount\n products\n prices)\n \n ; get-bill : (listof exact-integer?) (listof exact-integer?) -> flonum?\n (define/public (get-bill product amount)\n\n )))\n\n;; Your cashier% object will be instantiated and called as such:\n;; (define obj (new cashier% [n n] [discount discount] [products products] [prices prices]))\n;; (define param_1 (send obj get-bill product amount))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1357](https://leetcode-cn.com/problems/apply-discount-every-n-orders)", "[\u6bcf\u9694 n \u4e2a\u987e\u5ba2\u6253\u6298](/solution/1300-1399/1357.Apply%20Discount%20Every%20n%20Orders/README.md)", "`\u8bbe\u8ba1`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1357](https://leetcode.com/problems/apply-discount-every-n-orders)", "[Apply Discount Every n Orders](/solution/1300-1399/1357.Apply%20Discount%20Every%20n%20Orders/README_EN.md)", "`Design`", "Medium", ""]}, {"question_id": "1458", "frontend_question_id": "1356", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sort-integers-by-the-number-of-1-bits", "url_en": "https://leetcode.com/problems/sort-integers-by-the-number-of-1-bits", "relative_path_cn": "/solution/1300-1399/1356.Sort%20Integers%20by%20The%20Number%20of%201%20Bits/README.md", "relative_path_en": "/solution/1300-1399/1356.Sort%20Integers%20by%20The%20Number%20of%201%20Bits/README_EN.md", "title_cn": "\u6839\u636e\u6570\u5b57\u4e8c\u8fdb\u5236\u4e0b 1 \u7684\u6570\u76ee\u6392\u5e8f", "title_en": "Sort Integers by The Number of 1 Bits", "question_title_slug": "sort-integers-by-the-number-of-1-bits", "content_en": "

    Given an integer array arr. You have to sort the integers in the array in ascending order by the number of 1's in their binary representation and in case of two or more integers have the same number of 1's you have to sort them in ascending order.

    \n\n

    Return the sorted array.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr = [0,1,2,3,4,5,6,7,8]\nOutput: [0,1,2,4,8,3,5,6,7]\nExplantion: [0] is the only integer with 0 bits.\n[1,2,4,8] all have 1 bit.\n[3,5,6] have 2 bits.\n[7] has 3 bits.\nThe sorted array by bits is [0,1,2,4,8,3,5,6,7]\n
    \n\n

    Example 2:

    \n\n
    \nInput: arr = [1024,512,256,128,64,32,16,8,4,2,1]\nOutput: [1,2,4,8,16,32,64,128,256,512,1024]\nExplantion: All integers have 1 bit in the binary representation, you should just sort them in ascending order.\n
    \n\n

    Example 3:

    \n\n
    \nInput: arr = [10000,10000]\nOutput: [10000,10000]\n
    \n\n

    Example 4:

    \n\n
    \nInput: arr = [2,3,5,7,11,13,17,19]\nOutput: [2,3,5,17,7,11,13,19]\n
    \n\n

    Example 5:

    \n\n
    \nInput: arr = [10,100,1000,10000]\nOutput: [10,100,10000,1000]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= arr.length <= 500
    • \n\t
    • 0 <= arr[i] <= 10^4
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr \u3002\u8bf7\u4f60\u5c06\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u6309\u7167\u5176\u4e8c\u8fdb\u5236\u8868\u793a\u4e2d\u6570\u5b57 1 \u7684\u6570\u76ee\u5347\u5e8f\u6392\u5e8f\u3002

    \n\n

    \u5982\u679c\u5b58\u5728\u591a\u4e2a\u6570\u5b57\u4e8c\u8fdb\u5236\u4e2d 1 \u7684\u6570\u76ee\u76f8\u540c\uff0c\u5219\u5fc5\u987b\u5c06\u5b83\u4eec\u6309\u7167\u6570\u503c\u5927\u5c0f\u5347\u5e8f\u6392\u5217\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u6392\u5e8f\u540e\u7684\u6570\u7ec4\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [0,1,2,3,4,5,6,7,8]\n\u8f93\u51fa\uff1a[0,1,2,4,8,3,5,6,7]\n\u89e3\u91ca\uff1a[0] \u662f\u552f\u4e00\u4e00\u4e2a\u6709 0 \u4e2a 1 \u7684\u6570\u3002\n[1,2,4,8] \u90fd\u6709 1 \u4e2a 1 \u3002\n[3,5,6] \u6709 2 \u4e2a 1 \u3002\n[7] \u6709 3 \u4e2a 1 \u3002\n\u6309\u7167 1 \u7684\u4e2a\u6570\u6392\u5e8f\u5f97\u5230\u7684\u7ed3\u679c\u6570\u7ec4\u4e3a [0,1,2,4,8,3,5,6,7]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [1024,512,256,128,64,32,16,8,4,2,1]\n\u8f93\u51fa\uff1a[1,2,4,8,16,32,64,128,256,512,1024]\n\u89e3\u91ca\uff1a\u6570\u7ec4\u4e2d\u6240\u6709\u6574\u6570\u4e8c\u8fdb\u5236\u4e0b\u90fd\u53ea\u6709 1 \u4e2a 1 \uff0c\u6240\u4ee5\u4f60\u9700\u8981\u6309\u7167\u6570\u503c\u5927\u5c0f\u5c06\u5b83\u4eec\u6392\u5e8f\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [10000,10000]\n\u8f93\u51fa\uff1a[10000,10000]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [2,3,5,7,11,13,17,19]\n\u8f93\u51fa\uff1a[2,3,5,17,7,11,13,19]\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [10,100,1000,10000]\n\u8f93\u51fa\uff1a[10,100,10000,1000]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= arr.length <= 500
    • \n\t
    • 0 <= arr[i] <= 10^4
    • \n
    \n", "tags_en": ["Sort", "Bit Manipulation"], "tags_cn": ["\u6392\u5e8f", "\u4f4d\u8fd0\u7b97"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector sortByBits(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] sortByBits(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def sortByBits(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def sortByBits(self, arr: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* sortByBits(int* arr, int arrSize, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] SortByBits(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number[]}\n */\nvar sortByBits = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer[]}\ndef sort_by_bits(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func sortByBits(_ arr: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func sortByBits(arr []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def sortByBits(arr: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun sortByBits(arr: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sort_by_bits(arr: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer[]\n */\n function sortByBits($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function sortByBits(arr: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (sort-by-bits arr)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1356](https://leetcode-cn.com/problems/sort-integers-by-the-number-of-1-bits)", "[\u6839\u636e\u6570\u5b57\u4e8c\u8fdb\u5236\u4e0b 1 \u7684\u6570\u76ee\u6392\u5e8f](/solution/1300-1399/1356.Sort%20Integers%20by%20The%20Number%20of%201%20Bits/README.md)", "`\u6392\u5e8f`,`\u4f4d\u8fd0\u7b97`", "\u7b80\u5355", ""], "md_table_row_en": ["[1356](https://leetcode.com/problems/sort-integers-by-the-number-of-1-bits)", "[Sort Integers by The Number of 1 Bits](/solution/1300-1399/1356.Sort%20Integers%20by%20The%20Number%20of%201%20Bits/README_EN.md)", "`Sort`,`Bit Manipulation`", "Easy", ""]}, {"question_id": "1457", "frontend_question_id": "1335", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-difficulty-of-a-job-schedule", "url_en": "https://leetcode.com/problems/minimum-difficulty-of-a-job-schedule", "relative_path_cn": "/solution/1300-1399/1335.Minimum%20Difficulty%20of%20a%20Job%20Schedule/README.md", "relative_path_en": "/solution/1300-1399/1335.Minimum%20Difficulty%20of%20a%20Job%20Schedule/README_EN.md", "title_cn": "\u5de5\u4f5c\u8ba1\u5212\u7684\u6700\u4f4e\u96be\u5ea6", "title_en": "Minimum Difficulty of a Job Schedule", "question_title_slug": "minimum-difficulty-of-a-job-schedule", "content_en": "

    You want to schedule a list of jobs in d days. Jobs are dependent (i.e To work on the i-th job, you have to finish all the jobs j where 0 <= j < i).

    \r\n\r\n

    You have to finish at least one task every day. The difficulty of a job schedule is the sum of difficulties of each day of the d days. The difficulty of a day is the maximum difficulty of a job done in that day.

    \r\n\r\n

    Given an array of integers jobDifficulty and an integer d. The difficulty of the i-th job is jobDifficulty[i].

    \r\n\r\n

    Return the minimum difficulty of a job schedule. If you cannot find a schedule for the jobs return -1.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\"\"\r\n
    \r\nInput: jobDifficulty = [6,5,4,3,2,1], d = 2\r\nOutput: 7\r\nExplanation: First day you can finish the first 5 jobs, total difficulty = 6.\r\nSecond day you can finish the last job, total difficulty = 1.\r\nThe difficulty of the schedule = 6 + 1 = 7 \r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: jobDifficulty = [9,9,9], d = 4\r\nOutput: -1\r\nExplanation: If you finish a job per day you will still have a free day. you cannot find a schedule for the given jobs.\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: jobDifficulty = [1,1,1], d = 3\r\nOutput: 3\r\nExplanation: The schedule is one job per day. total difficulty will be 3.\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: jobDifficulty = [7,1,7,1,7,1], d = 3\r\nOutput: 15\r\n
    \r\n\r\n

    Example 5:

    \r\n\r\n
    \r\nInput: jobDifficulty = [11,111,22,222,33,333,44,444], d = 6\r\nOutput: 843\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= jobDifficulty.length <= 300
    • \r\n\t
    • 0 <= jobDifficulty[i] <= 1000
    • \r\n\t
    • 1 <= d <= 10
    • \r\n
    ", "content_cn": "

    \u4f60\u9700\u8981\u5236\u5b9a\u4e00\u4efd d \u5929\u7684\u5de5\u4f5c\u8ba1\u5212\u8868\u3002\u5de5\u4f5c\u4e4b\u95f4\u5b58\u5728\u4f9d\u8d56\uff0c\u8981\u60f3\u6267\u884c\u7b2c i \u9879\u5de5\u4f5c\uff0c\u4f60\u5fc5\u987b\u5b8c\u6210\u5168\u90e8 j \u9879\u5de5\u4f5c\uff08 0 <= j < i\uff09\u3002

    \n\n

    \u4f60\u6bcf\u5929 \u81f3\u5c11 \u9700\u8981\u5b8c\u6210\u4e00\u9879\u4efb\u52a1\u3002\u5de5\u4f5c\u8ba1\u5212\u7684\u603b\u96be\u5ea6\u662f\u8fd9 d \u5929\u6bcf\u4e00\u5929\u7684\u96be\u5ea6\u4e4b\u548c\uff0c\u800c\u4e00\u5929\u7684\u5de5\u4f5c\u96be\u5ea6\u662f\u5f53\u5929\u5e94\u8be5\u5b8c\u6210\u5de5\u4f5c\u7684\u6700\u5927\u96be\u5ea6\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 jobDifficulty \u548c\u4e00\u4e2a\u6574\u6570 d\uff0c\u5206\u522b\u4ee3\u8868\u5de5\u4f5c\u96be\u5ea6\u548c\u9700\u8981\u8ba1\u5212\u7684\u5929\u6570\u3002\u7b2c i \u9879\u5de5\u4f5c\u7684\u96be\u5ea6\u662f jobDifficulty[i]\u3002

    \n\n

    \u8fd4\u56de\u6574\u4e2a\u5de5\u4f5c\u8ba1\u5212\u7684 \u6700\u5c0f\u96be\u5ea6 \u3002\u5982\u679c\u65e0\u6cd5\u5236\u5b9a\u5de5\u4f5c\u8ba1\u5212\uff0c\u5219\u8fd4\u56de -1 \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1ajobDifficulty = [6,5,4,3,2,1], d = 2\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\u7b2c\u4e00\u5929\uff0c\u60a8\u53ef\u4ee5\u5b8c\u6210\u524d 5 \u9879\u5de5\u4f5c\uff0c\u603b\u96be\u5ea6 = 6.\n\u7b2c\u4e8c\u5929\uff0c\u60a8\u53ef\u4ee5\u5b8c\u6210\u6700\u540e\u4e00\u9879\u5de5\u4f5c\uff0c\u603b\u96be\u5ea6 = 1.\n\u8ba1\u5212\u8868\u7684\u96be\u5ea6 = 6 + 1 = 7 \n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1ajobDifficulty = [9,9,9], d = 4\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u5c31\u7b97\u4f60\u6bcf\u5929\u5b8c\u6210\u4e00\u9879\u5de5\u4f5c\uff0c\u4ecd\u7136\u6709\u4e00\u5929\u662f\u7a7a\u95f2\u7684\uff0c\u4f60\u65e0\u6cd5\u5236\u5b9a\u4e00\u4efd\u80fd\u591f\u6ee1\u8db3\u65e2\u5b9a\u5de5\u4f5c\u65f6\u95f4\u7684\u8ba1\u5212\u8868\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1ajobDifficulty = [1,1,1], d = 3\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u5de5\u4f5c\u8ba1\u5212\u4e3a\u6bcf\u5929\u4e00\u9879\u5de5\u4f5c\uff0c\u603b\u96be\u5ea6\u4e3a 3 \u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1ajobDifficulty = [7,1,7,1,7,1], d = 3\n\u8f93\u51fa\uff1a15\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1ajobDifficulty = [11,111,22,222,33,333,44,444], d = 6\n\u8f93\u51fa\uff1a843\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= jobDifficulty.length <= 300
    • \n\t
    • 0 <= jobDifficulty[i] <= 1000
    • \n\t
    • 1 <= d <= 10
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minDifficulty(vector& jobDifficulty, int d) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minDifficulty(int[] jobDifficulty, int d) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minDifficulty(self, jobDifficulty, d):\n \"\"\"\n :type jobDifficulty: List[int]\n :type d: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minDifficulty(self, jobDifficulty: List[int], d: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minDifficulty(int* jobDifficulty, int jobDifficultySize, int d){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinDifficulty(int[] jobDifficulty, int d) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} jobDifficulty\n * @param {number} d\n * @return {number}\n */\nvar minDifficulty = function(jobDifficulty, d) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} job_difficulty\n# @param {Integer} d\n# @return {Integer}\ndef min_difficulty(job_difficulty, d)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minDifficulty(_ jobDifficulty: [Int], _ d: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minDifficulty(jobDifficulty []int, d int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minDifficulty(jobDifficulty: Array[Int], d: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minDifficulty(jobDifficulty: IntArray, d: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_difficulty(job_difficulty: Vec, d: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $jobDifficulty\n * @param Integer $d\n * @return Integer\n */\n function minDifficulty($jobDifficulty, $d) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minDifficulty(jobDifficulty: number[], d: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-difficulty jobDifficulty d)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1335](https://leetcode-cn.com/problems/minimum-difficulty-of-a-job-schedule)", "[\u5de5\u4f5c\u8ba1\u5212\u7684\u6700\u4f4e\u96be\u5ea6](/solution/1300-1399/1335.Minimum%20Difficulty%20of%20a%20Job%20Schedule/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1335](https://leetcode.com/problems/minimum-difficulty-of-a-job-schedule)", "[Minimum Difficulty of a Job Schedule](/solution/1300-1399/1335.Minimum%20Difficulty%20of%20a%20Job%20Schedule/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1456", "frontend_question_id": "1334", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance", "url_en": "https://leetcode.com/problems/find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance", "relative_path_cn": "/solution/1300-1399/1334.Find%20the%20City%20With%20the%20Smallest%20Number%20of%20Neighbors%20at%20a%20Threshold%20Distance/README.md", "relative_path_en": "/solution/1300-1399/1334.Find%20the%20City%20With%20the%20Smallest%20Number%20of%20Neighbors%20at%20a%20Threshold%20Distance/README_EN.md", "title_cn": "\u9608\u503c\u8ddd\u79bb\u5185\u90bb\u5c45\u6700\u5c11\u7684\u57ce\u5e02", "title_en": "Find the City With the Smallest Number of Neighbors at a Threshold Distance", "question_title_slug": "find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance", "content_en": "

    There are n cities numbered from 0 to n-1. Given the array edges where edges[i] = [fromi, toi, weighti] represents a bidirectional and weighted edge between cities fromi and toi, and given the integer distanceThreshold.

    \n\n

    Return the city with the smallest number of cities that are reachable through some path and whose distance is at most distanceThreshold, If there are multiple such cities, return the city with the greatest number.

    \n\n

    Notice that the distance of a path connecting cities i and j is equal to the sum of the edges' weights along that path.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: n = 4, edges = [[0,1,3],[1,2,1],[1,3,4],[2,3,1]], distanceThreshold = 4\nOutput: 3\nExplanation: The figure above describes the graph. \nThe neighboring cities at a distanceThreshold = 4 for each city are:\nCity 0 -> [City 1, City 2] \nCity 1 -> [City 0, City 2, City 3] \nCity 2 -> [City 0, City 1, City 3] \nCity 3 -> [City 1, City 2] \nCities 0 and 3 have 2 neighboring cities at a distanceThreshold = 4, but we have to return city 3 since it has the greatest number.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: n = 5, edges = [[0,1,2],[0,4,8],[1,2,3],[1,4,2],[2,3,1],[3,4,1]], distanceThreshold = 2\nOutput: 0\nExplanation: The figure above describes the graph. \nThe neighboring cities at a distanceThreshold = 2 for each city are:\nCity 0 -> [City 1] \nCity 1 -> [City 0, City 4] \nCity 2 -> [City 3, City 4] \nCity 3 -> [City 2, City 4]\nCity 4 -> [City 1, City 2, City 3] \nThe city 0 has 1 neighboring city at a distanceThreshold = 2.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= n <= 100
    • \n\t
    • 1 <= edges.length <= n * (n - 1) / 2
    • \n\t
    • edges[i].length == 3
    • \n\t
    • 0 <= fromi < toi < n
    • \n\t
    • 1 <= weighti, distanceThreshold <= 10^4
    • \n\t
    • All pairs (fromi, toi) are distinct.
    • \n
    \n", "content_cn": "

    \u6709 n\u00a0\u4e2a\u57ce\u5e02\uff0c\u6309\u4ece 0 \u5230 n-1\u00a0\u7f16\u53f7\u3002\u7ed9\u4f60\u4e00\u4e2a\u8fb9\u6570\u7ec4\u00a0edges\uff0c\u5176\u4e2d edges[i] = [fromi, toi, weighti]\u00a0\u4ee3\u8868\u00a0fromi\u00a0\u548c\u00a0toi\u00a0\u4e24\u4e2a\u57ce\u5e02\u4e4b\u95f4\u7684\u53cc\u5411\u52a0\u6743\u8fb9\uff0c\u8ddd\u79bb\u9608\u503c\u662f\u4e00\u4e2a\u6574\u6570\u00a0distanceThreshold\u3002

    \n\n

    \u8fd4\u56de\u80fd\u901a\u8fc7\u67d0\u4e9b\u8def\u5f84\u5230\u8fbe\u5176\u4ed6\u57ce\u5e02\u6570\u76ee\u6700\u5c11\u3001\u4e14\u8def\u5f84\u8ddd\u79bb \u6700\u5927 \u4e3a\u00a0distanceThreshold\u00a0\u7684\u57ce\u5e02\u3002\u5982\u679c\u6709\u591a\u4e2a\u8fd9\u6837\u7684\u57ce\u5e02\uff0c\u5219\u8fd4\u56de\u7f16\u53f7\u6700\u5927\u7684\u57ce\u5e02\u3002

    \n\n

    \u6ce8\u610f\uff0c\u8fde\u63a5\u57ce\u5e02 i \u548c j \u7684\u8def\u5f84\u7684\u8ddd\u79bb\u7b49\u4e8e\u6cbf\u8be5\u8def\u5f84\u7684\u6240\u6709\u8fb9\u7684\u6743\u91cd\u4e4b\u548c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1an = 4, edges = [[0,1,3],[1,2,1],[1,3,4],[2,3,1]], distanceThreshold = 4\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u57ce\u5e02\u5206\u5e03\u56fe\u5982\u4e0a\u3002\n\u6bcf\u4e2a\u57ce\u5e02\u9608\u503c\u8ddd\u79bb distanceThreshold = 4 \u5185\u7684\u90bb\u5c45\u57ce\u5e02\u5206\u522b\u662f\uff1a\n\u57ce\u5e02 0 -> [\u57ce\u5e02 1, \u57ce\u5e02 2]\u00a0\n\u57ce\u5e02 1 -> [\u57ce\u5e02 0, \u57ce\u5e02 2, \u57ce\u5e02 3]\u00a0\n\u57ce\u5e02 2 -> [\u57ce\u5e02 0, \u57ce\u5e02 1, \u57ce\u5e02 3]\u00a0\n\u57ce\u5e02 3 -> [\u57ce\u5e02 1, \u57ce\u5e02 2]\u00a0\n\u57ce\u5e02 0 \u548c 3 \u5728\u9608\u503c\u8ddd\u79bb 4 \u4ee5\u5185\u90fd\u6709 2 \u4e2a\u90bb\u5c45\u57ce\u5e02\uff0c\u4f46\u662f\u6211\u4eec\u5fc5\u987b\u8fd4\u56de\u57ce\u5e02 3\uff0c\u56e0\u4e3a\u5b83\u7684\u7f16\u53f7\u6700\u5927\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1an = 5, edges = [[0,1,2],[0,4,8],[1,2,3],[1,4,2],[2,3,1],[3,4,1]], distanceThreshold = 2\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u57ce\u5e02\u5206\u5e03\u56fe\u5982\u4e0a\u3002\u00a0\n\u6bcf\u4e2a\u57ce\u5e02\u9608\u503c\u8ddd\u79bb distanceThreshold = 2 \u5185\u7684\u90bb\u5c45\u57ce\u5e02\u5206\u522b\u662f\uff1a\n\u57ce\u5e02 0 -> [\u57ce\u5e02 1]\u00a0\n\u57ce\u5e02 1 -> [\u57ce\u5e02 0, \u57ce\u5e02 4]\u00a0\n\u57ce\u5e02 2 -> [\u57ce\u5e02 3, \u57ce\u5e02 4]\u00a0\n\u57ce\u5e02 3 -> [\u57ce\u5e02 2, \u57ce\u5e02 4]\n\u57ce\u5e02 4 -> [\u57ce\u5e02 1, \u57ce\u5e02 2, \u57ce\u5e02 3]\u00a0\n\u57ce\u5e02 0 \u5728\u9608\u503c\u8ddd\u79bb 2 \u4ee5\u5185\u53ea\u6709 1 \u4e2a\u90bb\u5c45\u57ce\u5e02\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= n <= 100
    • \n\t
    • 1 <= edges.length <= n * (n - 1) / 2
    • \n\t
    • edges[i].length == 3
    • \n\t
    • 0 <= fromi < toi < n
    • \n\t
    • 1 <= weighti,\u00a0distanceThreshold <= 10^4
    • \n\t
    • \u6240\u6709 (fromi, toi)\u00a0\u90fd\u662f\u4e0d\u540c\u7684\u3002
    • \n
    \n", "tags_en": ["Graph"], "tags_cn": ["\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findTheCity(int n, vector>& edges, int distanceThreshold) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findTheCity(int n, int[][] edges, int distanceThreshold) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findTheCity(self, n, edges, distanceThreshold):\n \"\"\"\n :type n: int\n :type edges: List[List[int]]\n :type distanceThreshold: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findTheCity(self, n: int, edges: List[List[int]], distanceThreshold: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findTheCity(int n, int** edges, int edgesSize, int* edgesColSize, int distanceThreshold){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindTheCity(int n, int[][] edges, int distanceThreshold) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} edges\n * @param {number} distanceThreshold\n * @return {number}\n */\nvar findTheCity = function(n, edges, distanceThreshold) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} edges\n# @param {Integer} distance_threshold\n# @return {Integer}\ndef find_the_city(n, edges, distance_threshold)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findTheCity(_ n: Int, _ edges: [[Int]], _ distanceThreshold: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findTheCity(n int, edges [][]int, distanceThreshold int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findTheCity(n: Int, edges: Array[Array[Int]], distanceThreshold: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findTheCity(n: Int, edges: Array, distanceThreshold: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_the_city(n: i32, edges: Vec>, distance_threshold: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $edges\n * @param Integer $distanceThreshold\n * @return Integer\n */\n function findTheCity($n, $edges, $distanceThreshold) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findTheCity(n: number, edges: number[][], distanceThreshold: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-the-city n edges distanceThreshold)\n (-> exact-integer? (listof (listof exact-integer?)) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1334](https://leetcode-cn.com/problems/find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance)", "[\u9608\u503c\u8ddd\u79bb\u5185\u90bb\u5c45\u6700\u5c11\u7684\u57ce\u5e02](/solution/1300-1399/1334.Find%20the%20City%20With%20the%20Smallest%20Number%20of%20Neighbors%20at%20a%20Threshold%20Distance/README.md)", "`\u56fe`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1334](https://leetcode.com/problems/find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance)", "[Find the City With the Smallest Number of Neighbors at a Threshold Distance](/solution/1300-1399/1334.Find%20the%20City%20With%20the%20Smallest%20Number%20of%20Neighbors%20at%20a%20Threshold%20Distance/README_EN.md)", "`Graph`", "Medium", ""]}, {"question_id": "1455", "frontend_question_id": "1333", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/filter-restaurants-by-vegan-friendly-price-and-distance", "url_en": "https://leetcode.com/problems/filter-restaurants-by-vegan-friendly-price-and-distance", "relative_path_cn": "/solution/1300-1399/1333.Filter%20Restaurants%20by%20Vegan-Friendly%2C%20Price%20and%20Distance/README.md", "relative_path_en": "/solution/1300-1399/1333.Filter%20Restaurants%20by%20Vegan-Friendly%2C%20Price%20and%20Distance/README_EN.md", "title_cn": "\u9910\u5385\u8fc7\u6ee4\u5668", "title_en": "Filter Restaurants by Vegan-Friendly, Price and Distance", "question_title_slug": "filter-restaurants-by-vegan-friendly-price-and-distance", "content_en": "

    Given the array restaurants where  restaurants[i] = [idi, ratingi, veganFriendlyi, pricei, distancei]. You have to filter the restaurants using three filters.

    \n\n

    The veganFriendly filter will be either true (meaning you should only include restaurants with veganFriendlyi set to true) or false (meaning you can include any restaurant). In addition, you have the filters maxPrice and maxDistance which are the maximum value for price and distance of restaurants you should consider respectively.

    \n\n

    Return the array of restaurant IDs after filtering, ordered by rating from highest to lowest. For restaurants with the same rating, order them by id from highest to lowest. For simplicity veganFriendlyi and veganFriendly take value 1 when it is true, and 0 when it is false.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: restaurants = [[1,4,1,40,10],[2,8,0,50,5],[3,8,1,30,4],[4,10,0,10,3],[5,1,1,15,1]], veganFriendly = 1, maxPrice = 50, maxDistance = 10\nOutput: [3,1,5] \nExplanation: \nThe restaurants are:\nRestaurant 1 [id=1, rating=4, veganFriendly=1, price=40, distance=10]\nRestaurant 2 [id=2, rating=8, veganFriendly=0, price=50, distance=5]\nRestaurant 3 [id=3, rating=8, veganFriendly=1, price=30, distance=4]\nRestaurant 4 [id=4, rating=10, veganFriendly=0, price=10, distance=3]\nRestaurant 5 [id=5, rating=1, veganFriendly=1, price=15, distance=1] \nAfter filter restaurants with veganFriendly = 1, maxPrice = 50 and maxDistance = 10 we have restaurant 3, restaurant 1 and restaurant 5 (ordered by rating from highest to lowest). \n
    \n\n

    Example 2:

    \n\n
    \nInput: restaurants = [[1,4,1,40,10],[2,8,0,50,5],[3,8,1,30,4],[4,10,0,10,3],[5,1,1,15,1]], veganFriendly = 0, maxPrice = 50, maxDistance = 10\nOutput: [4,3,2,1,5]\nExplanation: The restaurants are the same as in example 1, but in this case the filter veganFriendly = 0, therefore all restaurants are considered.\n
    \n\n

    Example 3:

    \n\n
    \nInput: restaurants = [[1,4,1,40,10],[2,8,0,50,5],[3,8,1,30,4],[4,10,0,10,3],[5,1,1,15,1]], veganFriendly = 0, maxPrice = 30, maxDistance = 3\nOutput: [4,5]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= restaurants.length <= 10^4
    • \n\t
    • restaurants[i].length == 5
    • \n\t
    • 1 <= idi, ratingi, pricei, distancei <= 10^5
    • \n\t
    • 1 <= maxPrice, maxDistance <= 10^5
    • \n\t
    • veganFriendlyi and veganFriendly are 0 or 1.
    • \n\t
    • All idi are distinct.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u9910\u9986\u4fe1\u606f\u6570\u7ec4 restaurants\uff0c\u5176\u4e2d  restaurants[i] = [idi, ratingi, veganFriendlyi, pricei, distancei]\u3002\u4f60\u5fc5\u987b\u4f7f\u7528\u4ee5\u4e0b\u4e09\u4e2a\u8fc7\u6ee4\u5668\u6765\u8fc7\u6ee4\u8fd9\u4e9b\u9910\u9986\u4fe1\u606f\u3002

    \n\n

    \u5176\u4e2d\u7d20\u98df\u8005\u53cb\u597d\u8fc7\u6ee4\u5668 veganFriendly \u7684\u503c\u53ef\u4ee5\u4e3a true \u6216\u8005 false\uff0c\u5982\u679c\u4e3a true \u5c31\u610f\u5473\u7740\u4f60\u5e94\u8be5\u53ea\u5305\u62ec veganFriendlyi \u4e3a true \u7684\u9910\u9986\uff0c\u4e3a false \u5219\u610f\u5473\u7740\u53ef\u4ee5\u5305\u62ec\u4efb\u4f55\u9910\u9986\u3002\u6b64\u5916\uff0c\u6211\u4eec\u8fd8\u6709\u6700\u5927\u4ef7\u683c maxPrice \u548c\u6700\u5927\u8ddd\u79bb maxDistance \u4e24\u4e2a\u8fc7\u6ee4\u5668\uff0c\u5b83\u4eec\u5206\u522b\u8003\u8651\u9910\u5385\u7684\u4ef7\u683c\u56e0\u7d20\u548c\u8ddd\u79bb\u56e0\u7d20\u7684\u6700\u5927\u503c\u3002

    \n\n

    \u8fc7\u6ee4\u540e\u8fd4\u56de\u9910\u9986\u7684 id\uff0c\u6309\u7167 rating \u4ece\u9ad8\u5230\u4f4e\u6392\u5e8f\u3002\u5982\u679c rating \u76f8\u540c\uff0c\u90a3\u4e48\u6309 id \u4ece\u9ad8\u5230\u4f4e\u6392\u5e8f\u3002\u7b80\u5355\u8d77\u89c1\uff0c veganFriendlyi \u548c veganFriendly \u4e3a true \u65f6\u53d6\u503c\u4e3a 1\uff0c\u4e3a false \u65f6\uff0c\u53d6\u503c\u4e3a 0 \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1arestaurants = [[1,4,1,40,10],[2,8,0,50,5],[3,8,1,30,4],[4,10,0,10,3],[5,1,1,15,1]], veganFriendly = 1, maxPrice = 50, maxDistance = 10\n\u8f93\u51fa\uff1a[3,1,5] \n\u89e3\u91ca\uff1a \n\u8fd9\u4e9b\u9910\u9986\u4e3a\uff1a\n\u9910\u9986 1 [id=1, rating=4, veganFriendly=1, price=40, distance=10]\n\u9910\u9986 2 [id=2, rating=8, veganFriendly=0, price=50, distance=5]\n\u9910\u9986 3 [id=3, rating=8, veganFriendly=1, price=30, distance=4]\n\u9910\u9986 4 [id=4, rating=10, veganFriendly=0, price=10, distance=3]\n\u9910\u9986 5 [id=5, rating=1, veganFriendly=1, price=15, distance=1] \n\u5728\u6309\u7167 veganFriendly = 1, maxPrice = 50 \u548c maxDistance = 10 \u8fdb\u884c\u8fc7\u6ee4\u540e\uff0c\u6211\u4eec\u5f97\u5230\u4e86\u9910\u9986 3, \u9910\u9986 1 \u548c \u9910\u9986 5\uff08\u6309\u8bc4\u5206\u4ece\u9ad8\u5230\u4f4e\u6392\u5e8f\uff09\u3002 \n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1arestaurants = [[1,4,1,40,10],[2,8,0,50,5],[3,8,1,30,4],[4,10,0,10,3],[5,1,1,15,1]], veganFriendly = 0, maxPrice = 50, maxDistance = 10\n\u8f93\u51fa\uff1a[4,3,2,1,5]\n\u89e3\u91ca\uff1a\u9910\u9986\u4e0e\u793a\u4f8b 1 \u76f8\u540c\uff0c\u4f46\u5728 veganFriendly = 0 \u7684\u8fc7\u6ee4\u6761\u4ef6\u4e0b\uff0c\u5e94\u8be5\u8003\u8651\u6240\u6709\u9910\u9986\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1arestaurants = [[1,4,1,40,10],[2,8,0,50,5],[3,8,1,30,4],[4,10,0,10,3],[5,1,1,15,1]], veganFriendly = 0, maxPrice = 30, maxDistance = 3\n\u8f93\u51fa\uff1a[4,5]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= restaurants.length <= 10^4
    • \n\t
    • restaurants[i].length == 5
    • \n\t
    • 1 <= idi, ratingi, pricei, distancei <= 10^5
    • \n\t
    • 1 <= maxPrice, maxDistance <= 10^5
    • \n\t
    • veganFriendlyi \u548c veganFriendly \u7684\u503c\u4e3a 0 \u6216 1 \u3002
    • \n\t
    • \u6240\u6709 idi \u5404\u4e0d\u76f8\u540c\u3002
    • \n
    \n", "tags_en": ["Sort", "Array"], "tags_cn": ["\u6392\u5e8f", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector filterRestaurants(vector>& restaurants, int veganFriendly, int maxPrice, int maxDistance) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List filterRestaurants(int[][] restaurants, int veganFriendly, int maxPrice, int maxDistance) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def filterRestaurants(self, restaurants, veganFriendly, maxPrice, maxDistance):\n \"\"\"\n :type restaurants: List[List[int]]\n :type veganFriendly: int\n :type maxPrice: int\n :type maxDistance: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def filterRestaurants(self, restaurants: List[List[int]], veganFriendly: int, maxPrice: int, maxDistance: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* filterRestaurants(int** restaurants, int restaurantsSize, int* restaurantsColSize, int veganFriendly, int maxPrice, int maxDistance, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList FilterRestaurants(int[][] restaurants, int veganFriendly, int maxPrice, int maxDistance) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} restaurants\n * @param {number} veganFriendly\n * @param {number} maxPrice\n * @param {number} maxDistance\n * @return {number[]}\n */\nvar filterRestaurants = function(restaurants, veganFriendly, maxPrice, maxDistance) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} restaurants\n# @param {Integer} vegan_friendly\n# @param {Integer} max_price\n# @param {Integer} max_distance\n# @return {Integer[]}\ndef filter_restaurants(restaurants, vegan_friendly, max_price, max_distance)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func filterRestaurants(_ restaurants: [[Int]], _ veganFriendly: Int, _ maxPrice: Int, _ maxDistance: Int) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func filterRestaurants(restaurants [][]int, veganFriendly int, maxPrice int, maxDistance int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def filterRestaurants(restaurants: Array[Array[Int]], veganFriendly: Int, maxPrice: Int, maxDistance: Int): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun filterRestaurants(restaurants: Array, veganFriendly: Int, maxPrice: Int, maxDistance: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn filter_restaurants(restaurants: Vec>, vegan_friendly: i32, max_price: i32, max_distance: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $restaurants\n * @param Integer $veganFriendly\n * @param Integer $maxPrice\n * @param Integer $maxDistance\n * @return Integer[]\n */\n function filterRestaurants($restaurants, $veganFriendly, $maxPrice, $maxDistance) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function filterRestaurants(restaurants: number[][], veganFriendly: number, maxPrice: number, maxDistance: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (filter-restaurants restaurants veganFriendly maxPrice maxDistance)\n (-> (listof (listof exact-integer?)) exact-integer? exact-integer? exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1333](https://leetcode-cn.com/problems/filter-restaurants-by-vegan-friendly-price-and-distance)", "[\u9910\u5385\u8fc7\u6ee4\u5668](/solution/1300-1399/1333.Filter%20Restaurants%20by%20Vegan-Friendly%2C%20Price%20and%20Distance/README.md)", "`\u6392\u5e8f`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1333](https://leetcode.com/problems/filter-restaurants-by-vegan-friendly-price-and-distance)", "[Filter Restaurants by Vegan-Friendly, Price and Distance](/solution/1300-1399/1333.Filter%20Restaurants%20by%20Vegan-Friendly%2C%20Price%20and%20Distance/README_EN.md)", "`Sort`,`Array`", "Medium", ""]}, {"question_id": "1454", "frontend_question_id": "1332", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/remove-palindromic-subsequences", "url_en": "https://leetcode.com/problems/remove-palindromic-subsequences", "relative_path_cn": "/solution/1300-1399/1332.Remove%20Palindromic%20Subsequences/README.md", "relative_path_en": "/solution/1300-1399/1332.Remove%20Palindromic%20Subsequences/README_EN.md", "title_cn": "\u5220\u9664\u56de\u6587\u5b50\u5e8f\u5217", "title_en": "Remove Palindromic Subsequences", "question_title_slug": "remove-palindromic-subsequences", "content_en": "

    You are given a string s consisting only of letters 'a' and 'b'. In a single step you can remove one palindromic subsequence from s.

    \n\n

    Return the minimum number of steps to make the given string empty.

    \n\n

    A string is a subsequence of a given string if it is generated by deleting some characters of a given string without changing its order. Note that a subsequence does not necessarily need to be contiguous.

    \n\n

    A string is called palindrome if is one that reads the same backward as well as forward.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "ababa"\nOutput: 1\nExplanation: s is already a palindrome, so its entirety can be removed in a single step.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "abb"\nOutput: 2\nExplanation: "abb" -> "bb" -> "". \nRemove palindromic subsequence "a" then "bb".\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "baabb"\nOutput: 2\nExplanation: "baabb" -> "b" -> "". \nRemove palindromic subsequence "baab" then "b".\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 1000
    • \n\t
    • s[i] is either 'a' or 'b'.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s\uff0c\u5b83\u4ec5\u7531\u5b57\u6bcd 'a' \u548c 'b' \u7ec4\u6210\u3002\u6bcf\u4e00\u6b21\u5220\u9664\u64cd\u4f5c\u90fd\u53ef\u4ee5\u4ece s \u4e2d\u5220\u9664\u4e00\u4e2a\u56de\u6587 \u5b50\u5e8f\u5217\u3002

    \n\n

    \u8fd4\u56de\u5220\u9664\u7ed9\u5b9a\u5b57\u7b26\u4e32\u4e2d\u6240\u6709\u5b57\u7b26\uff08\u5b57\u7b26\u4e32\u4e3a\u7a7a\uff09\u7684\u6700\u5c0f\u5220\u9664\u6b21\u6570\u3002

    \n\n

    \u300c\u5b50\u5e8f\u5217\u300d\u5b9a\u4e49\uff1a\u5982\u679c\u4e00\u4e2a\u5b57\u7b26\u4e32\u53ef\u4ee5\u901a\u8fc7\u5220\u9664\u539f\u5b57\u7b26\u4e32\u67d0\u4e9b\u5b57\u7b26\u800c\u4e0d\u6539\u53d8\u539f\u5b57\u7b26\u987a\u5e8f\u5f97\u5230\uff0c\u90a3\u4e48\u8fd9\u4e2a\u5b57\u7b26\u4e32\u5c31\u662f\u539f\u5b57\u7b26\u4e32\u7684\u4e00\u4e2a\u5b50\u5e8f\u5217\u3002

    \n\n

    \u300c\u56de\u6587\u300d\u5b9a\u4e49\uff1a\u5982\u679c\u4e00\u4e2a\u5b57\u7b26\u4e32\u5411\u540e\u548c\u5411\u524d\u8bfb\u662f\u4e00\u81f4\u7684\uff0c\u90a3\u4e48\u8fd9\u4e2a\u5b57\u7b26\u4e32\u5c31\u662f\u4e00\u4e2a\u56de\u6587\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1as = "ababa"\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u5b57\u7b26\u4e32\u672c\u8eab\u5c31\u662f\u56de\u6587\u5e8f\u5217\uff0c\u53ea\u9700\u8981\u5220\u9664\u4e00\u6b21\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1as = "abb"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a"abb" -> "bb" -> "". \n\u5148\u5220\u9664\u56de\u6587\u5b50\u5e8f\u5217 "a"\uff0c\u7136\u540e\u518d\u5220\u9664 "bb"\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1as = "baabb"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a"baabb" -> "b" -> "". \n\u5148\u5220\u9664\u56de\u6587\u5b50\u5e8f\u5217 "baab"\uff0c\u7136\u540e\u518d\u5220\u9664 "b"\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1as = ""\n\u8f93\u51fa\uff1a0\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= s.length <= 1000
    • \n\t
    • s \u4ec5\u5305\u542b\u5b57\u6bcd 'a'  \u548c 'b'
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int removePalindromeSub(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int removePalindromeSub(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def removePalindromeSub(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def removePalindromeSub(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint removePalindromeSub(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int RemovePalindromeSub(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar removePalindromeSub = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef remove_palindrome_sub(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func removePalindromeSub(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func removePalindromeSub(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def removePalindromeSub(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun removePalindromeSub(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn remove_palindrome_sub(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function removePalindromeSub($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function removePalindromeSub(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (remove-palindrome-sub s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1332](https://leetcode-cn.com/problems/remove-palindromic-subsequences)", "[\u5220\u9664\u56de\u6587\u5b50\u5e8f\u5217](/solution/1300-1399/1332.Remove%20Palindromic%20Subsequences/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1332](https://leetcode.com/problems/remove-palindromic-subsequences)", "[Remove Palindromic Subsequences](/solution/1300-1399/1332.Remove%20Palindromic%20Subsequences/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1453", "frontend_question_id": "1322", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/ads-performance", "url_en": "https://leetcode.com/problems/ads-performance", "relative_path_cn": "/solution/1300-1399/1322.Ads%20Performance/README.md", "relative_path_en": "/solution/1300-1399/1322.Ads%20Performance/README_EN.md", "title_cn": "\u5e7f\u544a\u6548\u679c", "title_en": "Ads Performance", "question_title_slug": "ads-performance", "content_en": "

    Table: Ads

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| ad_id         | int     |\n| user_id       | int     |\n| action        | enum    |\n+---------------+---------+\n(ad_id, user_id) is the primary key for this table.\nEach row of this table contains the ID of an Ad, the ID of a user and the action taken by this user regarding this Ad.\nThe action column is an ENUM type of ('Clicked', 'Viewed', 'Ignored').\n
    \n\n

     

    \n\n

    A company is running Ads and wants to calculate the performance of each Ad.

    \n\n

    Performance of the Ad is measured using Click-Through Rate (CTR) where:

    \n\n

    \"\"

    \n\n

    Write an SQL query to find the ctr of each Ad.

    \n\n

    Round ctr to 2 decimal points. Order the result table by ctr in descending order and by ad_id in ascending order in case of a tie.

    \n\n

    The query result format is in the following example:

    \n\n
    \nAds table:\n+-------+---------+---------+\n| ad_id | user_id | action  |\n+-------+---------+---------+\n| 1     | 1       | Clicked |\n| 2     | 2       | Clicked |\n| 3     | 3       | Viewed  |\n| 5     | 5       | Ignored |\n| 1     | 7       | Ignored |\n| 2     | 7       | Viewed  |\n| 3     | 5       | Clicked |\n| 1     | 4       | Viewed  |\n| 2     | 11      | Viewed  |\n| 1     | 2       | Clicked |\n+-------+---------+---------+\nResult table:\n+-------+-------+\n| ad_id | ctr   |\n+-------+-------+\n| 1     | 66.67 |\n| 3     | 50.00 |\n| 2     | 33.33 |\n| 5     | 0.00  |\n+-------+-------+\nfor ad_id = 1, ctr = (2/(2+1)) * 100 = 66.67\nfor ad_id = 2, ctr = (1/(1+2)) * 100 = 33.33\nfor ad_id = 3, ctr = (1/(1+1)) * 100 = 50.00\nfor ad_id = 5, ctr = 0.00, Note that ad_id = 5 has no clicks or views.\nNote that we don't care about Ignored Ads.\nResult table is ordered by the ctr. in case of a tie we order them by ad_id\n
    \n", "content_cn": "

    \u8868: Ads

    \n\n
    +---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| ad_id         | int     |\n| user_id       | int     |\n| action        | enum    |\n+---------------+---------+\n(ad_id, user_id) \u662f\u8be5\u8868\u7684\u4e3b\u952e\n\u8be5\u8868\u7684\u6bcf\u4e00\u884c\u5305\u542b\u4e00\u6761\u5e7f\u544a\u7684 ID(ad_id)\uff0c\u7528\u6237\u7684 ID(user_id) \u548c\u7528\u6237\u5bf9\u5e7f\u544a\u91c7\u53d6\u7684\u884c\u4e3a (action)\naction \u5217\u662f\u4e00\u4e2a\u679a\u4e3e\u7c7b\u578b ('Clicked', 'Viewed', 'Ignored') \u3002\n
    \n\n

     

    \n\n

    \u4e00\u5bb6\u516c\u53f8\u6b63\u5728\u8fd0\u8425\u8fd9\u4e9b\u5e7f\u544a\u5e76\u60f3\u8ba1\u7b97\u6bcf\u6761\u5e7f\u544a\u7684\u6548\u679c\u3002

    \n\n

    \u5e7f\u544a\u6548\u679c\u7528\u70b9\u51fb\u901a\u8fc7\u7387\uff08Click-Through Rate\uff1aCTR\uff09\u6765\u8861\u91cf\uff0c\u516c\u5f0f\u5982\u4e0b:

    \n\n

    \"\"

    \n\n

    \u5199\u4e00\u6761SQL\u8bed\u53e5\u6765\u67e5\u8be2\u6bcf\u4e00\u6761\u5e7f\u544a\u7684 ctr \uff0c

    \n\n

     ctr \u8981\u4fdd\u7559\u4e24\u4f4d\u5c0f\u6570\u3002\u7ed3\u679c\u9700\u8981\u6309 ctr \u964d\u5e8f\u3001\u6309 ad_id \u5347\u5e8f \u8fdb\u884c\u6392\u5e8f\u3002

    \n\n

     

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u793a\u4f8b\u5982\u4e0b\uff1a

    \n\n
    Ads \u8868:\n+-------+---------+---------+\n| ad_id | user_id | action  |\n+-------+---------+---------+\n| 1     | 1       | Clicked |\n| 2     | 2       | Clicked |\n| 3     | 3       | Viewed  |\n| 5     | 5       | Ignored |\n| 1     | 7       | Ignored |\n| 2     | 7       | Viewed  |\n| 3     | 5       | Clicked |\n| 1     | 4       | Viewed  |\n| 2     | 11      | Viewed  |\n| 1     | 2       | Clicked |\n+-------+---------+---------+\n\u7ed3\u679c\u8868:\n+-------+-------+\n| ad_id | ctr   |\n+-------+-------+\n| 1     | 66.67 |\n| 3     | 50.00 |\n| 2     | 33.33 |\n| 5     | 0.00  |\n+-------+-------+\n\u5bf9\u4e8e ad_id = 1, ctr = (2/(2+1)) * 100 = 66.67\n\u5bf9\u4e8e ad_id = 2, ctr = (1/(1+2)) * 100 = 33.33\n\u5bf9\u4e8e ad_id = 3, ctr = (1/(1+1)) * 100 = 50.00\n\u5bf9\u4e8e ad_id = 5, ctr = 0.00, \u6ce8\u610f ad_id = 5 \u6ca1\u6709\u88ab\u70b9\u51fb (Clicked) \u6216\u67e5\u770b (Viewed) \u8fc7\n\u6ce8\u610f\u6211\u4eec\u4e0d\u5173\u5fc3 action \u4e3a Ingnored \u7684\u5e7f\u544a\n\u7ed3\u679c\u6309 ctr\uff08\u964d\u5e8f\uff09\uff0cad_id\uff08\u5347\u5e8f\uff09\u6392\u5e8f\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1322](https://leetcode-cn.com/problems/ads-performance)", "[\u5e7f\u544a\u6548\u679c](/solution/1300-1399/1322.Ads%20Performance/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1322](https://leetcode.com/problems/ads-performance)", "[Ads Performance](/solution/1300-1399/1322.Ads%20Performance/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1452", "frontend_question_id": "1321", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/restaurant-growth", "url_en": "https://leetcode.com/problems/restaurant-growth", "relative_path_cn": "/solution/1300-1399/1321.Restaurant%20Growth/README.md", "relative_path_en": "/solution/1300-1399/1321.Restaurant%20Growth/README_EN.md", "title_cn": "\u9910\u9986\u8425\u4e1a\u989d\u53d8\u5316\u589e\u957f", "title_en": "Restaurant Growth", "question_title_slug": "restaurant-growth", "content_en": "

    Table: Customer

    \r\n\r\n
    \r\n+---------------+---------+\r\n| Column Name   | Type    |\r\n+---------------+---------+\r\n| customer_id   | int     |\r\n| name          | varchar |\r\n| visited_on    | date    |\r\n| amount        | int     |\r\n+---------------+---------+\r\n(customer_id, visited_on) is the primary key for this table.\r\nThis table contains data about customer transactions in a restaurant.\r\nvisited_on is the date on which the customer with ID (customer_id) have visited the restaurant.\r\namount is the total paid by a customer.\r\n
    \r\n\r\n

     

    \r\n\r\n

    You are the restaurant owner and you want to analyze a possible expansion (there will be at least one customer every day).

    \r\n\r\n

    Write an SQL query to compute moving average of how much customer paid in a 7 days window (current day + 6 days before) .

    \r\n\r\n

    The query result format is in the following example:

    \r\n\r\n

    Return result table ordered by visited_on.

    \r\n\r\n

    average_amount should be rounded to 2 decimal places, all dates are in the format ('YYYY-MM-DD').

    \r\n\r\n

     

    \r\n\r\n
    \r\nCustomer table:\r\n+-------------+--------------+--------------+-------------+\r\n| customer_id | name         | visited_on   | amount      |\r\n+-------------+--------------+--------------+-------------+\r\n| 1           | Jhon         | 2019-01-01   | 100         |\r\n| 2           | Daniel       | 2019-01-02   | 110         |\r\n| 3           | Jade         | 2019-01-03   | 120         |\r\n| 4           | Khaled       | 2019-01-04   | 130         |\r\n| 5           | Winston      | 2019-01-05   | 110         | \r\n| 6           | Elvis        | 2019-01-06   | 140         | \r\n| 7           | Anna         | 2019-01-07   | 150         |\r\n| 8           | Maria        | 2019-01-08   | 80          |\r\n| 9           | Jaze         | 2019-01-09   | 110         | \r\n| 1           | Jhon         | 2019-01-10   | 130         | \r\n| 3           | Jade         | 2019-01-10   | 150         | \r\n+-------------+--------------+--------------+-------------+\r\n\r\nResult table:\r\n+--------------+--------------+----------------+\r\n| visited_on   | amount       | average_amount |\r\n+--------------+--------------+----------------+\r\n| 2019-01-07   | 860          | 122.86         |\r\n| 2019-01-08   | 840          | 120            |\r\n| 2019-01-09   | 840          | 120            |\r\n| 2019-01-10   | 1000         | 142.86         |\r\n+--------------+--------------+----------------+\r\n\r\n1st moving average from 2019-01-01 to 2019-01-07 has an average_amount of (100 + 110 + 120 + 130 + 110 + 140 + 150)/7 = 122.86\r\n2nd moving average from 2019-01-02 to 2019-01-08 has an average_amount of (110 + 120 + 130 + 110 + 140 + 150 + 80)/7 = 120\r\n3rd moving average from 2019-01-03 to 2019-01-09 has an average_amount of (120 + 130 + 110 + 140 + 150 + 80 + 110)/7 = 120\r\n4th moving average from 2019-01-04 to 2019-01-10 has an average_amount of (130 + 110 + 140 + 150 + 80 + 110 + 130 + 150)/7 = 142.86\r\n
    ", "content_cn": "

    \u8868: Customer

    \n\n
    +---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| customer_id   | int     |\n| name          | varchar |\n| visited_on    | date    |\n| amount        | int     |\n+---------------+---------+\n(customer_id, visited_on) \u662f\u8be5\u8868\u7684\u4e3b\u952e\n\u8be5\u8868\u5305\u542b\u4e00\u5bb6\u9910\u9986\u7684\u987e\u5ba2\u4ea4\u6613\u6570\u636e\nvisited_on \u8868\u793a (customer_id) \u7684\u987e\u5ba2\u5728 visited_on \u90a3\u5929\u8bbf\u95ee\u4e86\u9910\u9986\namount \u662f\u4e00\u4e2a\u987e\u5ba2\u67d0\u4e00\u5929\u7684\u6d88\u8d39\u603b\u989d\n
    \n\n

     

    \n\n

    \u4f60\u662f\u9910\u9986\u7684\u8001\u677f\uff0c\u73b0\u5728\u4f60\u60f3\u5206\u6790\u4e00\u4e0b\u53ef\u80fd\u7684\u8425\u4e1a\u989d\u53d8\u5316\u589e\u957f\uff08\u6bcf\u5929\u81f3\u5c11\u6709\u4e00\u4f4d\u987e\u5ba2\uff09

    \n\n

    \u5199\u4e00\u6761 SQL \u67e5\u8be2\u8ba1\u7b97\u4ee5 7 \u5929\uff08\u67d0\u65e5\u671f + \u8be5\u65e5\u671f\u524d\u7684 6 \u5929\uff09\u4e3a\u4e00\u4e2a\u65f6\u95f4\u6bb5\u7684\u987e\u5ba2\u6d88\u8d39\u5e73\u5747\u503c

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u7684\u4f8b\u5b50\u5982\u4e0b\uff1a

    \n\n
      \n\t
    • \u67e5\u8be2\u7ed3\u679c\u6309 visited_on \u6392\u5e8f
    • \n\t
    • average_amount \u8981 \u4fdd\u7559\u4e24\u4f4d\u5c0f\u6570\uff0c\u65e5\u671f\u6570\u636e\u7684\u683c\u5f0f\u4e3a ('YYYY-MM-DD')
    • \n
    \n\n

     

    \n\n
    Customer \u8868:\n+-------------+--------------+--------------+-------------+\n| customer_id | name         | visited_on   | amount      |\n+-------------+--------------+--------------+-------------+\n| 1           | Jhon         | 2019-01-01   | 100         |\n| 2           | Daniel       | 2019-01-02   | 110         |\n| 3           | Jade         | 2019-01-03   | 120         |\n| 4           | Khaled       | 2019-01-04   | 130         |\n| 5           | Winston      | 2019-01-05   | 110         | \n| 6           | Elvis        | 2019-01-06   | 140         | \n| 7           | Anna         | 2019-01-07   | 150         |\n| 8           | Maria        | 2019-01-08   | 80          |\n| 9           | Jaze         | 2019-01-09   | 110         | \n| 1           | Jhon         | 2019-01-10   | 130         | \n| 3           | Jade         | 2019-01-10   | 150         | \n+-------------+--------------+--------------+-------------+\n\n\u7ed3\u679c\u8868:\n+--------------+--------------+----------------+\n| visited_on   | amount       | average_amount |\n+--------------+--------------+----------------+\n| 2019-01-07   | 860          | 122.86         |\n| 2019-01-08   | 840          | 120            |\n| 2019-01-09   | 840          | 120            |\n| 2019-01-10   | 1000         | 142.86         |\n+--------------+--------------+----------------+\n\n\u7b2c\u4e00\u4e2a\u4e03\u5929\u6d88\u8d39\u5e73\u5747\u503c\u4ece 2019-01-01 \u5230 2019-01-07 \u662f (100 + 110 + 120 + 130 + 110 + 140 + 150)/7 = 122.86\n\u7b2c\u4e8c\u4e2a\u4e03\u5929\u6d88\u8d39\u5e73\u5747\u503c\u4ece 2019-01-02 \u5230 2019-01-08 \u662f (110 + 120 + 130 + 110 + 140 + 150 + 80)/7 = 120\n\u7b2c\u4e09\u4e2a\u4e03\u5929\u6d88\u8d39\u5e73\u5747\u503c\u4ece 2019-01-03 \u5230 2019-01-09 \u662f (120 + 130 + 110 + 140 + 150 + 80 + 110)/7 = 120\n\u7b2c\u56db\u4e2a\u4e03\u5929\u6d88\u8d39\u5e73\u5747\u503c\u4ece 2019-01-04 \u5230 2019-01-10 \u662f (130 + 110 + 140 + 150 + 80 + 110 + 130 + 150)/7 = 142.86
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1321](https://leetcode-cn.com/problems/restaurant-growth)", "[\u9910\u9986\u8425\u4e1a\u989d\u53d8\u5316\u589e\u957f](/solution/1300-1399/1321.Restaurant%20Growth/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1321](https://leetcode.com/problems/restaurant-growth)", "[Restaurant Growth](/solution/1300-1399/1321.Restaurant%20Growth/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1451", "frontend_question_id": "1326", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-number-of-taps-to-open-to-water-a-garden", "url_en": "https://leetcode.com/problems/minimum-number-of-taps-to-open-to-water-a-garden", "relative_path_cn": "/solution/1300-1399/1326.Minimum%20Number%20of%20Taps%20to%20Open%20to%20Water%20a%20Garden/README.md", "relative_path_en": "/solution/1300-1399/1326.Minimum%20Number%20of%20Taps%20to%20Open%20to%20Water%20a%20Garden/README_EN.md", "title_cn": "\u704c\u6e89\u82b1\u56ed\u7684\u6700\u5c11\u6c34\u9f99\u5934\u6570\u76ee", "title_en": "Minimum Number of Taps to Open to Water a Garden", "question_title_slug": "minimum-number-of-taps-to-open-to-water-a-garden", "content_en": "

    There is a one-dimensional garden on the x-axis. The garden starts at the point 0 and ends at the point n. (i.e The length of the garden is n).

    \n\n

    There are n + 1 taps located at points [0, 1, ..., n] in the garden.

    \n\n

    Given an integer n and an integer array ranges of length n + 1 where ranges[i] (0-indexed) means the i-th tap can water the area [i - ranges[i], i + ranges[i]] if it was open.

    \n\n

    Return the minimum number of taps that should be open to water the whole garden, If the garden cannot be watered return -1.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: n = 5, ranges = [3,4,1,1,0,0]\nOutput: 1\nExplanation: The tap at point 0 can cover the interval [-3,3]\nThe tap at point 1 can cover the interval [-3,5]\nThe tap at point 2 can cover the interval [1,3]\nThe tap at point 3 can cover the interval [2,4]\nThe tap at point 4 can cover the interval [4,4]\nThe tap at point 5 can cover the interval [5,5]\nOpening Only the second tap will water the whole garden [0,5]\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 3, ranges = [0,0,0,0]\nOutput: -1\nExplanation: Even if you activate all the four taps you cannot water the whole garden.\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 7, ranges = [1,2,1,0,2,1,0,1]\nOutput: 3\n
    \n\n

    Example 4:

    \n\n
    \nInput: n = 8, ranges = [4,0,0,0,0,0,0,0,4]\nOutput: 2\n
    \n\n

    Example 5:

    \n\n
    \nInput: n = 8, ranges = [4,0,0,0,4,0,0,0,4]\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 10^4
    • \n\t
    • ranges.length == n + 1
    • \n\t
    • 0 <= ranges[i] <= 100
    • \n
    \n", "content_cn": "

    \u5728 x \u8f74\u4e0a\u6709\u4e00\u4e2a\u4e00\u7ef4\u7684\u82b1\u56ed\u3002\u82b1\u56ed\u957f\u5ea6\u4e3a n\uff0c\u4ece\u70b9 0 \u5f00\u59cb\uff0c\u5230\u70b9 n \u7ed3\u675f\u3002

    \n\n

    \u82b1\u56ed\u91cc\u603b\u5171\u6709 n + 1 \u4e2a\u6c34\u9f99\u5934\uff0c\u5206\u522b\u4f4d\u4e8e [0, 1, ..., n] \u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n \u548c\u4e00\u4e2a\u957f\u5ea6\u4e3a n + 1 \u7684\u6574\u6570\u6570\u7ec4 ranges \uff0c\u5176\u4e2d ranges[i] \uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\u8868\u793a\uff1a\u5982\u679c\u6253\u5f00\u70b9 i \u5904\u7684\u6c34\u9f99\u5934\uff0c\u53ef\u4ee5\u704c\u6e89\u7684\u533a\u57df\u4e3a [i -  ranges[i], i + ranges[i]] \u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u53ef\u4ee5\u704c\u6e89\u6574\u4e2a\u82b1\u56ed\u7684 \u6700\u5c11\u6c34\u9f99\u5934\u6570\u76ee \u3002\u5982\u679c\u82b1\u56ed\u59cb\u7ec8\u5b58\u5728\u65e0\u6cd5\u704c\u6e89\u5230\u7684\u5730\u65b9\uff0c\u8bf7\u4f60\u8fd4\u56de -1 \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 5, ranges = [3,4,1,1,0,0]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\n\u70b9 0 \u5904\u7684\u6c34\u9f99\u5934\u53ef\u4ee5\u704c\u6e89\u533a\u95f4 [-3,3]\n\u70b9 1 \u5904\u7684\u6c34\u9f99\u5934\u53ef\u4ee5\u704c\u6e89\u533a\u95f4 [-3,5]\n\u70b9 2 \u5904\u7684\u6c34\u9f99\u5934\u53ef\u4ee5\u704c\u6e89\u533a\u95f4 [1,3]\n\u70b9 3 \u5904\u7684\u6c34\u9f99\u5934\u53ef\u4ee5\u704c\u6e89\u533a\u95f4 [2,4]\n\u70b9 4 \u5904\u7684\u6c34\u9f99\u5934\u53ef\u4ee5\u704c\u6e89\u533a\u95f4 [4,4]\n\u70b9 5 \u5904\u7684\u6c34\u9f99\u5934\u53ef\u4ee5\u704c\u6e89\u533a\u95f4 [5,5]\n\u53ea\u9700\u8981\u6253\u5f00\u70b9 1 \u5904\u7684\u6c34\u9f99\u5934\u5373\u53ef\u704c\u6e89\u6574\u4e2a\u82b1\u56ed [0,5] \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1an = 3, ranges = [0,0,0,0]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u5373\u4f7f\u6253\u5f00\u6240\u6709\u6c34\u9f99\u5934\uff0c\u4f60\u4e5f\u65e0\u6cd5\u704c\u6e89\u6574\u4e2a\u82b1\u56ed\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1an = 7, ranges = [1,2,1,0,2,1,0,1]\n\u8f93\u51fa\uff1a3\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1an = 8, ranges = [4,0,0,0,0,0,0,0,4]\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1an = 8, ranges = [4,0,0,0,4,0,0,0,4]\n\u8f93\u51fa\uff1a1\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 10^4
    • \n\t
    • ranges.length == n + 1
    • \n\t
    • 0 <= ranges[i] <= 100
    • \n
    \n", "tags_en": ["Greedy", "Dynamic Programming"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minTaps(int n, vector& ranges) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minTaps(int n, int[] ranges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minTaps(self, n, ranges):\n \"\"\"\n :type n: int\n :type ranges: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minTaps(self, n: int, ranges: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minTaps(int n, int* ranges, int rangesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinTaps(int n, int[] ranges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[]} ranges\n * @return {number}\n */\nvar minTaps = function(n, ranges) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[]} ranges\n# @return {Integer}\ndef min_taps(n, ranges)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minTaps(_ n: Int, _ ranges: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minTaps(n int, ranges []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minTaps(n: Int, ranges: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minTaps(n: Int, ranges: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_taps(n: i32, ranges: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[] $ranges\n * @return Integer\n */\n function minTaps($n, $ranges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minTaps(n: number, ranges: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-taps n ranges)\n (-> exact-integer? (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1326](https://leetcode-cn.com/problems/minimum-number-of-taps-to-open-to-water-a-garden)", "[\u704c\u6e89\u82b1\u56ed\u7684\u6700\u5c11\u6c34\u9f99\u5934\u6570\u76ee](/solution/1300-1399/1326.Minimum%20Number%20of%20Taps%20to%20Open%20to%20Water%20a%20Garden/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1326](https://leetcode.com/problems/minimum-number-of-taps-to-open-to-water-a-garden)", "[Minimum Number of Taps to Open to Water a Garden](/solution/1300-1399/1326.Minimum%20Number%20of%20Taps%20to%20Open%20to%20Water%20a%20Garden/README_EN.md)", "`Greedy`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "1450", "frontend_question_id": "1325", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/delete-leaves-with-a-given-value", "url_en": "https://leetcode.com/problems/delete-leaves-with-a-given-value", "relative_path_cn": "/solution/1300-1399/1325.Delete%20Leaves%20With%20a%20Given%20Value/README.md", "relative_path_en": "/solution/1300-1399/1325.Delete%20Leaves%20With%20a%20Given%20Value/README_EN.md", "title_cn": "\u5220\u9664\u7ed9\u5b9a\u503c\u7684\u53f6\u5b50\u8282\u70b9", "title_en": "Delete Leaves With a Given Value", "question_title_slug": "delete-leaves-with-a-given-value", "content_en": "

    Given a binary tree root and an integer target, delete all the leaf nodes with value target.

    \n\n

    Note that once you delete a leaf node with value targetif it's parent node becomes a leaf node and has the value target, it should also be deleted (you need to continue doing that until you can't).

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: root = [1,2,3,2,null,2,4], target = 2\nOutput: [1,null,3,null,4]\nExplanation: Leaf nodes in green with value (target = 2) are removed (Picture in left). \nAfter removing, new nodes become leaf nodes with value (target = 2) (Picture in center).\n
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: root = [1,3,3,3,2], target = 3\nOutput: [1,3,null,null,2]\n
    \n\n

    Example 3:

    \n\n

    \"\"

    \n\n
    \nInput: root = [1,2,null,2,null,2], target = 2\nOutput: [1]\nExplanation: Leaf nodes in green with value (target = 2) are removed at each step.\n
    \n\n

    Example 4:

    \n\n
    \nInput: root = [1,1,1], target = 1\nOutput: []\n
    \n\n

    Example 5:

    \n\n
    \nInput: root = [1,2,3], target = 1\nOutput: [1,2,3]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= target <= 1000
    • \n\t
    • The given binary tree will have between 1 and 3000 nodes.
    • \n\t
    • Each node's value is between [1, 1000].
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u68f5\u4ee5 root \u4e3a\u6839\u7684\u4e8c\u53c9\u6811\u548c\u4e00\u4e2a\u6574\u6570 target \uff0c\u8bf7\u4f60\u5220\u9664\u6240\u6709\u503c\u4e3a target \u7684 \u53f6\u5b50\u8282\u70b9 \u3002

    \n\n

    \u6ce8\u610f\uff0c\u4e00\u65e6\u5220\u9664\u503c\u4e3a target \u7684\u53f6\u5b50\u8282\u70b9\uff0c\u5b83\u7684\u7236\u8282\u70b9\u5c31\u53ef\u80fd\u53d8\u6210\u53f6\u5b50\u8282\u70b9\uff1b\u5982\u679c\u65b0\u53f6\u5b50\u8282\u70b9\u7684\u503c\u6070\u597d\u4e5f\u662f target \uff0c\u90a3\u4e48\u8fd9\u4e2a\u8282\u70b9\u4e5f\u5e94\u8be5\u88ab\u5220\u9664\u3002

    \n\n

    \u4e5f\u5c31\u662f\u8bf4\uff0c\u4f60\u9700\u8981\u91cd\u590d\u6b64\u8fc7\u7a0b\u76f4\u5230\u4e0d\u80fd\u7ee7\u7eed\u5220\u9664\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1aroot = [1,2,3,2,null,2,4], target = 2\n\u8f93\u51fa\uff1a[1,null,3,null,4]\n\u89e3\u91ca\uff1a\n\u4e0a\u9762\u5de6\u8fb9\u7684\u56fe\u4e2d\uff0c\u7eff\u8272\u8282\u70b9\u4e3a\u53f6\u5b50\u8282\u70b9\uff0c\u4e14\u5b83\u4eec\u7684\u503c\u4e0e target \u76f8\u540c\uff08\u540c\u4e3a 2 \uff09\uff0c\u5b83\u4eec\u4f1a\u88ab\u5220\u9664\uff0c\u5f97\u5230\u4e2d\u95f4\u7684\u56fe\u3002\n\u6709\u4e00\u4e2a\u65b0\u7684\u8282\u70b9\u53d8\u6210\u4e86\u53f6\u5b50\u8282\u70b9\u4e14\u5b83\u7684\u503c\u4e0e target \u76f8\u540c\uff0c\u6240\u4ee5\u5c06\u518d\u6b21\u8fdb\u884c\u5220\u9664\uff0c\u4ece\u800c\u5f97\u5230\u6700\u53f3\u8fb9\u7684\u56fe\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1aroot = [1,3,3,3,2], target = 3\n\u8f93\u51fa\uff1a[1,3,null,null,2]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1aroot = [1,2,null,2,null,2], target = 2\n\u8f93\u51fa\uff1a[1]\n\u89e3\u91ca\uff1a\u6bcf\u4e00\u6b65\u90fd\u5220\u9664\u4e00\u4e2a\u7eff\u8272\u7684\u53f6\u5b50\u8282\u70b9\uff08\u503c\u4e3a 2\uff09\u3002
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1aroot = [1,1,1], target = 1\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1aroot = [1,2,3], target = 1\n\u8f93\u51fa\uff1a[1,2,3]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= target <= 1000
    • \n\t
    • \u6bcf\u4e00\u68f5\u6811\u6700\u591a\u6709 3000 \u4e2a\u8282\u70b9\u3002
    • \n\t
    • \u6bcf\u4e00\u4e2a\u8282\u70b9\u503c\u7684\u8303\u56f4\u662f [1, 1000] \u3002
    • \n
    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* removeLeafNodes(TreeNode* root, int target) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode removeLeafNodes(TreeNode root, int target) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def removeLeafNodes(self, root, target):\n \"\"\"\n :type root: TreeNode\n :type target: int\n :rtype: TreeNode\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def removeLeafNodes(self, root: TreeNode, target: int) -> TreeNode:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* removeLeafNodes(struct TreeNode* root, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode RemoveLeafNodes(TreeNode root, int target) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number} target\n * @return {TreeNode}\n */\nvar removeLeafNodes = function(root, target) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @param {Integer} target\n# @return {TreeNode}\ndef remove_leaf_nodes(root, target)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func removeLeafNodes(_ root: TreeNode?, _ target: Int) -> TreeNode? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc removeLeafNodes(root *TreeNode, target int) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def removeLeafNodes(root: TreeNode, target: Int): TreeNode = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun removeLeafNodes(root: TreeNode?, target: Int): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn remove_leaf_nodes(root: Option>>, target: i32) -> Option>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param Integer $target\n * @return TreeNode\n */\n function removeLeafNodes($root, $target) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction removeLeafNodes(root: TreeNode | null, target: number): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (remove-leaf-nodes root target)\n (-> (or/c tree-node? #f) exact-integer? (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1325](https://leetcode-cn.com/problems/delete-leaves-with-a-given-value)", "[\u5220\u9664\u7ed9\u5b9a\u503c\u7684\u53f6\u5b50\u8282\u70b9](/solution/1300-1399/1325.Delete%20Leaves%20With%20a%20Given%20Value/README.md)", "`\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1325](https://leetcode.com/problems/delete-leaves-with-a-given-value)", "[Delete Leaves With a Given Value](/solution/1300-1399/1325.Delete%20Leaves%20With%20a%20Given%20Value/README_EN.md)", "`Tree`", "Medium", ""]}, {"question_id": "1449", "frontend_question_id": "1324", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/print-words-vertically", "url_en": "https://leetcode.com/problems/print-words-vertically", "relative_path_cn": "/solution/1300-1399/1324.Print%20Words%20Vertically/README.md", "relative_path_en": "/solution/1300-1399/1324.Print%20Words%20Vertically/README_EN.md", "title_cn": "\u7ad6\u76f4\u6253\u5370\u5355\u8bcd", "title_en": "Print Words Vertically", "question_title_slug": "print-words-vertically", "content_en": "

    Given a string s. Return all the words vertically in the same order in which they appear in s.
    \r\nWords are returned as a list of strings, complete with spaces when is necessary. (Trailing spaces are not allowed).
    \r\nEach word would be put on only one column and that in one column there will be only one word.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: s = "HOW ARE YOU"\r\nOutput: ["HAY","ORO","WEU"]\r\nExplanation: Each word is printed vertically. \r\n "HAY"\r\n "ORO"\r\n "WEU"\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: s = "TO BE OR NOT TO BE"\r\nOutput: ["TBONTB","OEROOE","   T"]\r\nExplanation: Trailing spaces is not allowed. \r\n"TBONTB"\r\n"OEROOE"\r\n"   T"\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: s = "CONTEST IS COMING"\r\nOutput: ["CIC","OSO","N M","T I","E N","S G","T"]\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= s.length <= 200
    • \r\n\t
    • s contains only upper case English letters.
    • \r\n\t
    • It's guaranteed that there is only one space between 2 words.
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s\u3002\u8bf7\u4f60\u6309\u7167\u5355\u8bcd\u5728 s \u4e2d\u7684\u51fa\u73b0\u987a\u5e8f\u5c06\u5b83\u4eec\u5168\u90e8\u7ad6\u76f4\u8fd4\u56de\u3002
    \n\u5355\u8bcd\u5e94\u8be5\u4ee5\u5b57\u7b26\u4e32\u5217\u8868\u7684\u5f62\u5f0f\u8fd4\u56de\uff0c\u5fc5\u8981\u65f6\u7528\u7a7a\u683c\u8865\u4f4d\uff0c\u4f46\u8f93\u51fa\u5c3e\u90e8\u7684\u7a7a\u683c\u9700\u8981\u5220\u9664\uff08\u4e0d\u5141\u8bb8\u5c3e\u968f\u7a7a\u683c\uff09\u3002
    \n\u6bcf\u4e2a\u5355\u8bcd\u53ea\u80fd\u653e\u5728\u4e00\u5217\u4e0a\uff0c\u6bcf\u4e00\u5217\u4e2d\u4e5f\u53ea\u80fd\u6709\u4e00\u4e2a\u5355\u8bcd\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1as = "HOW ARE YOU"\n\u8f93\u51fa\uff1a["HAY","ORO","WEU"]\n\u89e3\u91ca\uff1a\u6bcf\u4e2a\u5355\u8bcd\u90fd\u5e94\u8be5\u7ad6\u76f4\u6253\u5370\u3002 \n "HAY"\n "ORO"\n "WEU"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1as = "TO BE OR NOT TO BE"\n\u8f93\u51fa\uff1a["TBONTB","OEROOE","   T"]\n\u89e3\u91ca\uff1a\u9898\u76ee\u5141\u8bb8\u4f7f\u7528\u7a7a\u683c\u8865\u4f4d\uff0c\u4f46\u4e0d\u5141\u8bb8\u8f93\u51fa\u672b\u5c3e\u51fa\u73b0\u7a7a\u683c\u3002\n"TBONTB"\n"OEROOE"\n"   T"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1as = "CONTEST IS COMING"\n\u8f93\u51fa\uff1a["CIC","OSO","N M","T I","E N","S G","T"]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 200
    • \n\t
    • s \u4ec5\u542b\u5927\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    • \n\t
    • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u4e24\u4e2a\u5355\u8bcd\u4e4b\u95f4\u53ea\u6709\u4e00\u4e2a\u7a7a\u683c\u3002
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector printVertically(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List printVertically(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def printVertically(self, s):\n \"\"\"\n :type s: str\n :rtype: List[str]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def printVertically(self, s: str) -> List[str]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** printVertically(char * s, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList PrintVertically(string s) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string[]}\n */\nvar printVertically = function(s) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String[]}\ndef print_vertically(s)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func printVertically(_ s: String) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func printVertically(s string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def printVertically(s: String): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun printVertically(s: String): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn print_vertically(s: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String[]\n */\n function printVertically($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function printVertically(s: string): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (print-vertically s)\n (-> string? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1324](https://leetcode-cn.com/problems/print-words-vertically)", "[\u7ad6\u76f4\u6253\u5370\u5355\u8bcd](/solution/1300-1399/1324.Print%20Words%20Vertically/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1324](https://leetcode.com/problems/print-words-vertically)", "[Print Words Vertically](/solution/1300-1399/1324.Print%20Words%20Vertically/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "1448", "frontend_question_id": "1323", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-69-number", "url_en": "https://leetcode.com/problems/maximum-69-number", "relative_path_cn": "/solution/1300-1399/1323.Maximum%2069%20Number/README.md", "relative_path_en": "/solution/1300-1399/1323.Maximum%2069%20Number/README_EN.md", "title_cn": "6 \u548c 9 \u7ec4\u6210\u7684\u6700\u5927\u6570\u5b57", "title_en": "Maximum 69 Number", "question_title_slug": "maximum-69-number", "content_en": "

    Given a positive integer num consisting only of digits 6 and 9.

    \r\n\r\n

    Return the maximum number you can get by changing at most one digit (6 becomes 9, and 9 becomes 6).

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: num = 9669\r\nOutput: 9969\r\nExplanation: \r\nChanging the first digit results in 6669.\r\nChanging the second digit results in 9969.\r\nChanging the third digit results in 9699.\r\nChanging the fourth digit results in 9666. \r\nThe maximum number is 9969.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: num = 9996\r\nOutput: 9999\r\nExplanation: Changing the last digit 6 to 9 results in the maximum number.
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: num = 9999\r\nOutput: 9999\r\nExplanation: It is better not to apply any change.
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= num <= 10^4
    • \r\n\t
    • num's digits are 6 or 9.
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u4ec5\u7531\u6570\u5b57 6 \u548c 9 \u7ec4\u6210\u7684\u6b63\u6574\u6570 num\u3002

    \n\n

    \u4f60\u6700\u591a\u53ea\u80fd\u7ffb\u8f6c\u4e00\u4f4d\u6570\u5b57\uff0c\u5c06 6 \u53d8\u6210 9\uff0c\u6216\u8005\u628a 9 \u53d8\u6210 6 \u3002

    \n\n

    \u8bf7\u8fd4\u56de\u4f60\u53ef\u4ee5\u5f97\u5230\u7684\u6700\u5927\u6570\u5b57\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anum = 9669\n\u8f93\u51fa\uff1a9969\n\u89e3\u91ca\uff1a\n\u6539\u53d8\u7b2c\u4e00\u4f4d\u6570\u5b57\u53ef\u4ee5\u5f97\u5230 6669 \u3002\n\u6539\u53d8\u7b2c\u4e8c\u4f4d\u6570\u5b57\u53ef\u4ee5\u5f97\u5230 9969 \u3002\n\u6539\u53d8\u7b2c\u4e09\u4f4d\u6570\u5b57\u53ef\u4ee5\u5f97\u5230 9699 \u3002\n\u6539\u53d8\u7b2c\u56db\u4f4d\u6570\u5b57\u53ef\u4ee5\u5f97\u5230 9666 \u3002\n\u5176\u4e2d\u6700\u5927\u7684\u6570\u5b57\u662f 9969 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anum = 9996\n\u8f93\u51fa\uff1a9999\n\u89e3\u91ca\uff1a\u5c06\u6700\u540e\u4e00\u4f4d\u4ece 6 \u53d8\u5230 9\uff0c\u5176\u7ed3\u679c 9999 \u662f\u6700\u5927\u7684\u6570\u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1anum = 9999\n\u8f93\u51fa\uff1a9999\n\u89e3\u91ca\uff1a\u65e0\u9700\u6539\u53d8\u5c31\u5df2\u7ecf\u662f\u6700\u5927\u7684\u6570\u5b57\u4e86\u3002
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= num <= 10^4
    • \n\t
    • num \u6bcf\u4e00\u4f4d\u4e0a\u7684\u6570\u5b57\u90fd\u662f 6 \u6216\u8005 9 \u3002
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maximum69Number (int num) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maximum69Number (int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximum69Number (self, num):\n \"\"\"\n :type num: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximum69Number (self, num: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maximum69Number (int num){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int Maximum69Number (int num) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} num\n * @return {number}\n */\nvar maximum69Number = function(num) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} num\n# @return {Integer}\ndef maximum69_number (num)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximum69Number (_ num: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximum69Number (num int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximum69Number (num: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximum69Number (num: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximum69_number (num: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $num\n * @return Integer\n */\n function maximum69Number ($num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximum69Number (num: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximum69-number num)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1323](https://leetcode-cn.com/problems/maximum-69-number)", "[6 \u548c 9 \u7ec4\u6210\u7684\u6700\u5927\u6570\u5b57](/solution/1300-1399/1323.Maximum%2069%20Number/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[1323](https://leetcode.com/problems/maximum-69-number)", "[Maximum 69 Number](/solution/1300-1399/1323.Maximum%2069%20Number/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "1447", "frontend_question_id": "1345", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/jump-game-iv", "url_en": "https://leetcode.com/problems/jump-game-iv", "relative_path_cn": "/solution/1300-1399/1345.Jump%20Game%20IV/README.md", "relative_path_en": "/solution/1300-1399/1345.Jump%20Game%20IV/README_EN.md", "title_cn": "\u8df3\u8dc3\u6e38\u620f IV", "title_en": "Jump Game IV", "question_title_slug": "jump-game-iv", "content_en": "

    Given an array of integers arr, you are initially positioned at the first index of the array.

    \n\n

    In one step you can jump from index i to index:

    \n\n
      \n\t
    • i + 1 where: i + 1 < arr.length.
    • \n\t
    • i - 1 where: i - 1 >= 0.
    • \n\t
    • j where: arr[i] == arr[j] and i != j.
    • \n
    \n\n

    Return the minimum number of steps to reach the last index of the array.

    \n\n

    Notice that you can not jump outside of the array at any time.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr = [100,-23,-23,404,100,23,23,23,3,404]\nOutput: 3\nExplanation: You need three jumps from index 0 --> 4 --> 3 --> 9. Note that index 9 is the last index of the array.\n
    \n\n

    Example 2:

    \n\n
    \nInput: arr = [7]\nOutput: 0\nExplanation: Start index is the last index. You don't need to jump.\n
    \n\n

    Example 3:

    \n\n
    \nInput: arr = [7,6,9,6,9,6,9,7]\nOutput: 1\nExplanation: You can jump directly from index 0 to index 7 which is last index of the array.\n
    \n\n

    Example 4:

    \n\n
    \nInput: arr = [6,1,9]\nOutput: 2\n
    \n\n

    Example 5:

    \n\n
    \nInput: arr = [11,22,7,7,7,7,7,7,7,22,13]\nOutput: 3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= arr.length <= 5 * 104
    • \n\t
    • -108 <= arr[i] <= 108
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr \uff0c\u4f60\u4e00\u5f00\u59cb\u5728\u6570\u7ec4\u7684\u7b2c\u4e00\u4e2a\u5143\u7d20\u5904\uff08\u4e0b\u6807\u4e3a 0\uff09\u3002

    \n\n

    \u6bcf\u4e00\u6b65\uff0c\u4f60\u53ef\u4ee5\u4ece\u4e0b\u6807 i \u8df3\u5230\u4e0b\u6807\uff1a

    \n\n
      \n\t
    • i + 1 \u6ee1\u8db3\uff1ai + 1 < arr.length
    • \n\t
    • i - 1 \u6ee1\u8db3\uff1ai - 1 >= 0
    • \n\t
    • j \u6ee1\u8db3\uff1aarr[i] == arr[j] \u4e14 i != j
    • \n
    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u5230\u8fbe\u6570\u7ec4\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u7684\u4e0b\u6807\u5904\u6240\u9700\u7684 \u6700\u5c11\u64cd\u4f5c\u6b21\u6570 \u3002

    \n\n

    \u6ce8\u610f\uff1a\u4efb\u4f55\u65f6\u5019\u4f60\u90fd\u4e0d\u80fd\u8df3\u5230\u6570\u7ec4\u5916\u9762\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [100,-23,-23,404,100,23,23,23,3,404]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u90a3\u4f60\u9700\u8981\u8df3\u8dc3 3 \u6b21\uff0c\u4e0b\u6807\u4f9d\u6b21\u4e3a 0 --> 4 --> 3 --> 9 \u3002\u4e0b\u6807 9 \u4e3a\u6570\u7ec4\u7684\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u7684\u4e0b\u6807\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [7]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u4e00\u5f00\u59cb\u5c31\u5728\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u5904\uff0c\u6240\u4ee5\u4f60\u4e0d\u9700\u8981\u8df3\u8dc3\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [7,6,9,6,9,6,9,7]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u76f4\u63a5\u4ece\u4e0b\u6807 0 \u5904\u8df3\u5230\u4e0b\u6807 7 \u5904\uff0c\u4e5f\u5c31\u662f\u6570\u7ec4\u7684\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u5904\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [6,1,9]\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [11,22,7,7,7,7,7,7,7,22,13]\n\u8f93\u51fa\uff1a3\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= arr.length <= 5 * 10^4
    • \n\t
    • -10^8 <= arr[i] <= 10^8
    • \n
    \n", "tags_en": ["Breadth-first Search"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minJumps(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minJumps(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minJumps(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minJumps(self, arr: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minJumps(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinJumps(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar minJumps = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef min_jumps(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minJumps(_ arr: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minJumps(arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minJumps(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minJumps(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_jumps(arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function minJumps($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minJumps(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-jumps arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1345](https://leetcode-cn.com/problems/jump-game-iv)", "[\u8df3\u8dc3\u6e38\u620f IV](/solution/1300-1399/1345.Jump%20Game%20IV/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[1345](https://leetcode.com/problems/jump-game-iv)", "[Jump Game IV](/solution/1300-1399/1345.Jump%20Game%20IV/README_EN.md)", "`Breadth-first Search`", "Hard", ""]}, {"question_id": "1446", "frontend_question_id": "1344", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/angle-between-hands-of-a-clock", "url_en": "https://leetcode.com/problems/angle-between-hands-of-a-clock", "relative_path_cn": "/solution/1300-1399/1344.Angle%20Between%20Hands%20of%20a%20Clock/README.md", "relative_path_en": "/solution/1300-1399/1344.Angle%20Between%20Hands%20of%20a%20Clock/README_EN.md", "title_cn": "\u65f6\u949f\u6307\u9488\u7684\u5939\u89d2", "title_en": "Angle Between Hands of a Clock", "question_title_slug": "angle-between-hands-of-a-clock", "content_en": "

    Given two numbers, hour and minutes. Return the smaller angle (in degrees) formed between the hour and the minute hand.

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: hour = 12, minutes = 30\nOutput: 165\n
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: hour = 3, minutes = 30\nOutput: 75\n
    \n\n

    Example 3:

    \n\n

    \"\"

    \n\n
    \nInput: hour = 3, minutes = 15\nOutput: 7.5\n
    \n\n

    Example 4:

    \n\n
    \nInput: hour = 4, minutes = 50\nOutput: 155\n
    \n\n

    Example 5:

    \n\n
    \nInput: hour = 12, minutes = 0\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= hour <= 12
    • \n\t
    • 0 <= minutes <= 59
    • \n\t
    • Answers within 10^-5 of the actual value will be accepted as correct.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u6570 hour \u548c minutes \u3002\u8bf7\u4f60\u8fd4\u56de\u5728\u65f6\u949f\u4e0a\uff0c\u7531\u7ed9\u5b9a\u65f6\u95f4\u7684\u65f6\u9488\u548c\u5206\u9488\u7ec4\u6210\u7684\u8f83\u5c0f\u89d2\u7684\u89d2\u5ea6\uff0860 \u5355\u4f4d\u5236\uff09\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1ahour = 12, minutes = 30\n\u8f93\u51fa\uff1a165\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1ahour = 3, minutes = 30\n\u8f93\u51fa\uff1b75\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1ahour = 3, minutes = 15\n\u8f93\u51fa\uff1a7.5\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1ahour = 4, minutes = 50\n\u8f93\u51fa\uff1a155\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1ahour = 12, minutes = 0\n\u8f93\u51fa\uff1a0\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= hour <= 12
    • \n\t
    • 0 <= minutes <= 59
    • \n\t
    • \u4e0e\u6807\u51c6\u7b54\u6848\u8bef\u5dee\u5728 10^-5 \u4ee5\u5185\u7684\u7ed3\u679c\u90fd\u88ab\u89c6\u4e3a\u6b63\u786e\u7ed3\u679c\u3002
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n double angleClock(int hour, int minutes) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double angleClock(int hour, int minutes) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def angleClock(self, hour, minutes):\n \"\"\"\n :type hour: int\n :type minutes: int\n :rtype: float\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def angleClock(self, hour: int, minutes: int) -> float:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\ndouble angleClock(int hour, int minutes){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double AngleClock(int hour, int minutes) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} hour\n * @param {number} minutes\n * @return {number}\n */\nvar angleClock = function(hour, minutes) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} hour\n# @param {Integer} minutes\n# @return {Float}\ndef angle_clock(hour, minutes)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func angleClock(_ hour: Int, _ minutes: Int) -> Double {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func angleClock(hour int, minutes int) float64 {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def angleClock(hour: Int, minutes: Int): Double = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun angleClock(hour: Int, minutes: Int): Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn angle_clock(hour: i32, minutes: i32) -> f64 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $hour\n * @param Integer $minutes\n * @return Float\n */\n function angleClock($hour, $minutes) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function angleClock(hour: number, minutes: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (angle-clock hour minutes)\n (-> exact-integer? exact-integer? flonum?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1344](https://leetcode-cn.com/problems/angle-between-hands-of-a-clock)", "[\u65f6\u949f\u6307\u9488\u7684\u5939\u89d2](/solution/1300-1399/1344.Angle%20Between%20Hands%20of%20a%20Clock/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1344](https://leetcode.com/problems/angle-between-hands-of-a-clock)", "[Angle Between Hands of a Clock](/solution/1300-1399/1344.Angle%20Between%20Hands%20of%20a%20Clock/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "1445", "frontend_question_id": "1343", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-sub-arrays-of-size-k-and-average-greater-than-or-equal-to-threshold", "url_en": "https://leetcode.com/problems/number-of-sub-arrays-of-size-k-and-average-greater-than-or-equal-to-threshold", "relative_path_cn": "/solution/1300-1399/1343.Number%20of%20Sub-arrays%20of%20Size%20K%20and%20Average%20Greater%20than%20or%20Equal%20to%20Threshold/README.md", "relative_path_en": "/solution/1300-1399/1343.Number%20of%20Sub-arrays%20of%20Size%20K%20and%20Average%20Greater%20than%20or%20Equal%20to%20Threshold/README_EN.md", "title_cn": "\u5927\u5c0f\u4e3a K \u4e14\u5e73\u5747\u503c\u5927\u4e8e\u7b49\u4e8e\u9608\u503c\u7684\u5b50\u6570\u7ec4\u6570\u76ee", "title_en": "Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold", "question_title_slug": "number-of-sub-arrays-of-size-k-and-average-greater-than-or-equal-to-threshold", "content_en": "

    Given an array of integers arr and two integers k and threshold.

    \n\n

    Return the number of sub-arrays of size k and average greater than or equal to threshold.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4\nOutput: 3\nExplanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively. All other sub-arrays of size 3 have averages less than 4 (the threshold).\n
    \n\n

    Example 2:

    \n\n
    \nInput: arr = [1,1,1,1,1], k = 1, threshold = 0\nOutput: 5\n
    \n\n

    Example 3:

    \n\n
    \nInput: arr = [11,13,17,23,29,31,7,5,2,3], k = 3, threshold = 5\nOutput: 6\nExplanation: The first 6 sub-arrays of size 3 have averages greater than 5. Note that averages are not integers.\n
    \n\n

    Example 4:

    \n\n
    \nInput: arr = [7,7,7,7,7,7,7], k = 7, threshold = 7\nOutput: 1\n
    \n\n

    Example 5:

    \n\n
    \nInput: arr = [4,4,4,4], k = 4, threshold = 1\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= arr.length <= 10^5
    • \n\t
    • 1 <= arr[i] <= 10^4
    • \n\t
    • 1 <= k <= arr.length
    • \n\t
    • 0 <= threshold <= 10^4
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr \u548c\u4e24\u4e2a\u6574\u6570 k \u548c threshold \u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u957f\u5ea6\u4e3a k \u4e14\u5e73\u5747\u503c\u5927\u4e8e\u7b49\u4e8e threshold \u7684\u5b50\u6570\u7ec4\u6570\u76ee\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u5b50\u6570\u7ec4 [2,5,5],[5,5,5] \u548c [5,5,8] \u7684\u5e73\u5747\u503c\u5206\u522b\u4e3a 4\uff0c5 \u548c 6 \u3002\u5176\u4ed6\u957f\u5ea6\u4e3a 3 \u7684\u5b50\u6570\u7ec4\u7684\u5e73\u5747\u503c\u90fd\u5c0f\u4e8e 4 \uff08threshold \u7684\u503c)\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [1,1,1,1,1], k = 1, threshold = 0\n\u8f93\u51fa\uff1a5\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [11,13,17,23,29,31,7,5,2,3], k = 3, threshold = 5\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u524d 6 \u4e2a\u957f\u5ea6\u4e3a 3 \u7684\u5b50\u6570\u7ec4\u5e73\u5747\u503c\u90fd\u5927\u4e8e 5 \u3002\u6ce8\u610f\u5e73\u5747\u503c\u4e0d\u662f\u6574\u6570\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [7,7,7,7,7,7,7], k = 7, threshold = 7\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [4,4,4,4], k = 4, threshold = 1\n\u8f93\u51fa\uff1a1\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= arr.length <= 10^5
    • \n\t
    • 1 <= arr[i] <= 10^4
    • \n\t
    • 1 <= k <= arr.length
    • \n\t
    • 0 <= threshold <= 10^4
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numOfSubarrays(vector& arr, int k, int threshold) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numOfSubarrays(int[] arr, int k, int threshold) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numOfSubarrays(self, arr, k, threshold):\n \"\"\"\n :type arr: List[int]\n :type k: int\n :type threshold: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numOfSubarrays(self, arr: List[int], k: int, threshold: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numOfSubarrays(int* arr, int arrSize, int k, int threshold){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumOfSubarrays(int[] arr, int k, int threshold) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @param {number} k\n * @param {number} threshold\n * @return {number}\n */\nvar numOfSubarrays = function(arr, k, threshold) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @param {Integer} k\n# @param {Integer} threshold\n# @return {Integer}\ndef num_of_subarrays(arr, k, threshold)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numOfSubarrays(_ arr: [Int], _ k: Int, _ threshold: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numOfSubarrays(arr []int, k int, threshold int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numOfSubarrays(arr: Array[Int], k: Int, threshold: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numOfSubarrays(arr: IntArray, k: Int, threshold: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_of_subarrays(arr: Vec, k: i32, threshold: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @param Integer $k\n * @param Integer $threshold\n * @return Integer\n */\n function numOfSubarrays($arr, $k, $threshold) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numOfSubarrays(arr: number[], k: number, threshold: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-of-subarrays arr k threshold)\n (-> (listof exact-integer?) exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1343](https://leetcode-cn.com/problems/number-of-sub-arrays-of-size-k-and-average-greater-than-or-equal-to-threshold)", "[\u5927\u5c0f\u4e3a K \u4e14\u5e73\u5747\u503c\u5927\u4e8e\u7b49\u4e8e\u9608\u503c\u7684\u5b50\u6570\u7ec4\u6570\u76ee](/solution/1300-1399/1343.Number%20of%20Sub-arrays%20of%20Size%20K%20and%20Average%20Greater%20than%20or%20Equal%20to%20Threshold/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1343](https://leetcode.com/problems/number-of-sub-arrays-of-size-k-and-average-greater-than-or-equal-to-threshold)", "[Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold](/solution/1300-1399/1343.Number%20of%20Sub-arrays%20of%20Size%20K%20and%20Average%20Greater%20than%20or%20Equal%20to%20Threshold/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "1444", "frontend_question_id": "1342", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-steps-to-reduce-a-number-to-zero", "url_en": "https://leetcode.com/problems/number-of-steps-to-reduce-a-number-to-zero", "relative_path_cn": "/solution/1300-1399/1342.Number%20of%20Steps%20to%20Reduce%20a%20Number%20to%20Zero/README.md", "relative_path_en": "/solution/1300-1399/1342.Number%20of%20Steps%20to%20Reduce%20a%20Number%20to%20Zero/README_EN.md", "title_cn": "\u5c06\u6570\u5b57\u53d8\u6210 0 \u7684\u64cd\u4f5c\u6b21\u6570", "title_en": "Number of Steps to Reduce a Number to Zero", "question_title_slug": "number-of-steps-to-reduce-a-number-to-zero", "content_en": "

    Given a non-negative integer num, return the number of steps to reduce it to zero. If the current number is even, you have to divide it by 2, otherwise, you have to subtract 1 from it.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: num = 14\nOutput: 6\nExplanation: \nStep 1) 14 is even; divide by 2 and obtain 7. \nStep 2) 7 is odd; subtract 1 and obtain 6.\nStep 3) 6 is even; divide by 2 and obtain 3. \nStep 4) 3 is odd; subtract 1 and obtain 2. \nStep 5) 2 is even; divide by 2 and obtain 1. \nStep 6) 1 is odd; subtract 1 and obtain 0.\n
    \n\n

    Example 2:

    \n\n
    \nInput: num = 8\nOutput: 4\nExplanation: \nStep 1) 8 is even; divide by 2 and obtain 4. \nStep 2) 4 is even; divide by 2 and obtain 2. \nStep 3) 2 is even; divide by 2 and obtain 1. \nStep 4) 1 is odd; subtract 1 and obtain 0.\n
    \n\n

    Example 3:

    \n\n
    \nInput: num = 123\nOutput: 12\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= num <= 10^6
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u975e\u8d1f\u6574\u6570 num \uff0c\u8bf7\u4f60\u8fd4\u56de\u5c06\u5b83\u53d8\u6210 0 \u6240\u9700\u8981\u7684\u6b65\u6570\u3002 \u5982\u679c\u5f53\u524d\u6570\u5b57\u662f\u5076\u6570\uff0c\u4f60\u9700\u8981\u628a\u5b83\u9664\u4ee5 2 \uff1b\u5426\u5219\uff0c\u51cf\u53bb 1 \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anum = 14\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\n\u6b65\u9aa4 1) 14 \u662f\u5076\u6570\uff0c\u9664\u4ee5 2 \u5f97\u5230 7 \u3002\n\u6b65\u9aa4 2\uff09 7 \u662f\u5947\u6570\uff0c\u51cf 1 \u5f97\u5230 6 \u3002\n\u6b65\u9aa4 3\uff09 6 \u662f\u5076\u6570\uff0c\u9664\u4ee5 2 \u5f97\u5230 3 \u3002\n\u6b65\u9aa4 4\uff09 3 \u662f\u5947\u6570\uff0c\u51cf 1 \u5f97\u5230 2 \u3002\n\u6b65\u9aa4 5\uff09 2 \u662f\u5076\u6570\uff0c\u9664\u4ee5 2 \u5f97\u5230 1 \u3002\n\u6b65\u9aa4 6\uff09 1 \u662f\u5947\u6570\uff0c\u51cf 1 \u5f97\u5230 0 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anum = 8\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\n\u6b65\u9aa4 1\uff09 8 \u662f\u5076\u6570\uff0c\u9664\u4ee5 2 \u5f97\u5230 4 \u3002\n\u6b65\u9aa4 2\uff09 4 \u662f\u5076\u6570\uff0c\u9664\u4ee5 2 \u5f97\u5230 2 \u3002\n\u6b65\u9aa4 3\uff09 2 \u662f\u5076\u6570\uff0c\u9664\u4ee5 2 \u5f97\u5230 1 \u3002\n\u6b65\u9aa4 4\uff09 1 \u662f\u5947\u6570\uff0c\u51cf 1 \u5f97\u5230 0 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1anum = 123\n\u8f93\u51fa\uff1a12\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= num <= 10^6
    • \n
    \n", "tags_en": ["Bit Manipulation"], "tags_cn": ["\u4f4d\u8fd0\u7b97"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numberOfSteps(int num) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numberOfSteps(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numberOfSteps(self, num):\n \"\"\"\n :type num: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numberOfSteps(self, num: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numberOfSteps(int num){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumberOfSteps(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} num\n * @return {number}\n */\nvar numberOfSteps = function(num) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} num\n# @return {Integer}\ndef number_of_steps(num)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numberOfSteps(_ num: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numberOfSteps(num int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numberOfSteps(num: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numberOfSteps(num: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn number_of_steps(num: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $num\n * @return Integer\n */\n function numberOfSteps($num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numberOfSteps(num: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (number-of-steps num)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1342](https://leetcode-cn.com/problems/number-of-steps-to-reduce-a-number-to-zero)", "[\u5c06\u6570\u5b57\u53d8\u6210 0 \u7684\u64cd\u4f5c\u6b21\u6570](/solution/1300-1399/1342.Number%20of%20Steps%20to%20Reduce%20a%20Number%20to%20Zero/README.md)", "`\u4f4d\u8fd0\u7b97`", "\u7b80\u5355", ""], "md_table_row_en": ["[1342](https://leetcode.com/problems/number-of-steps-to-reduce-a-number-to-zero)", "[Number of Steps to Reduce a Number to Zero](/solution/1300-1399/1342.Number%20of%20Steps%20to%20Reduce%20a%20Number%20to%20Zero/README_EN.md)", "`Bit Manipulation`", "Easy", ""]}, {"question_id": "1443", "frontend_question_id": "1320", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-distance-to-type-a-word-using-two-fingers", "url_en": "https://leetcode.com/problems/minimum-distance-to-type-a-word-using-two-fingers", "relative_path_cn": "/solution/1300-1399/1320.Minimum%20Distance%20to%20Type%20a%20Word%20Using%20Two%20Fingers/README.md", "relative_path_en": "/solution/1300-1399/1320.Minimum%20Distance%20to%20Type%20a%20Word%20Using%20Two%20Fingers/README_EN.md", "title_cn": "\u4e8c\u6307\u8f93\u5165\u7684\u7684\u6700\u5c0f\u8ddd\u79bb", "title_en": "Minimum Distance to Type a Word Using Two Fingers", "question_title_slug": "minimum-distance-to-type-a-word-using-two-fingers", "content_en": "

    \"\"

    \r\n\r\n

    You have a keyboard layout as shown above in the XY plane, where each English uppercase letter is located at some coordinate, for example, the letter A is located at coordinate (0,0), the letter B is located at coordinate (0,1), the letter P is located at coordinate (2,3) and the letter Z is located at coordinate (4,1).

    \r\n\r\n

    Given the string word, return the minimum total distance to type such string using only two fingers. The distance between coordinates (x1,y1) and (x2,y2) is |x1 - x2| + |y1 - y2|

    \r\n\r\n

    Note that the initial positions of your two fingers are considered free so don't count towards your total distance, also your two fingers do not have to start at the first letter or the first two letters.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: word = "CAKE"\r\nOutput: 3\r\nExplanation: \r\nUsing two fingers, one optimal way to type "CAKE" is: \r\nFinger 1 on letter 'C' -> cost = 0 \r\nFinger 1 on letter 'A' -> cost = Distance from letter 'C' to letter 'A' = 2 \r\nFinger 2 on letter 'K' -> cost = 0 \r\nFinger 2 on letter 'E' -> cost = Distance from letter 'K' to letter 'E' = 1 \r\nTotal distance = 3\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: word = "HAPPY"\r\nOutput: 6\r\nExplanation: \r\nUsing two fingers, one optimal way to type "HAPPY" is:\r\nFinger 1 on letter 'H' -> cost = 0\r\nFinger 1 on letter 'A' -> cost = Distance from letter 'H' to letter 'A' = 2\r\nFinger 2 on letter 'P' -> cost = 0\r\nFinger 2 on letter 'P' -> cost = Distance from letter 'P' to letter 'P' = 0\r\nFinger 1 on letter 'Y' -> cost = Distance from letter 'A' to letter 'Y' = 4\r\nTotal distance = 6\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: word = "NEW"\r\nOutput: 3\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: word = "YEAR"\r\nOutput: 7\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 2 <= word.length <= 300
    • \r\n\t
    • Each word[i] is an English uppercase letter.
    • \r\n
    ", "content_cn": "

    \"\"

    \n\n

    \u4e8c\u6307\u8f93\u5165\u6cd5\u5b9a\u5236\u952e\u76d8\u5728 XY \u5e73\u9762\u4e0a\u7684\u5e03\u5c40\u5982\u4e0a\u56fe\u6240\u793a\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5927\u5199\u82f1\u6587\u5b57\u6bcd\u90fd\u4f4d\u4e8e\u67d0\u4e2a\u5750\u6807\u5904\uff0c\u4f8b\u5982\u5b57\u6bcd A \u4f4d\u4e8e\u5750\u6807 (0,0)\uff0c\u5b57\u6bcd B \u4f4d\u4e8e\u5750\u6807 (0,1)\uff0c\u5b57\u6bcd P \u4f4d\u4e8e\u5750\u6807 (2,3) \u4e14\u5b57\u6bcd Z \u4f4d\u4e8e\u5750\u6807 (4,1)\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u5f85\u8f93\u5165\u5b57\u7b26\u4e32 word\uff0c\u8bf7\u4f60\u8ba1\u7b97\u5e76\u8fd4\u56de\u5728\u4ec5\u4f7f\u7528\u4e24\u6839\u624b\u6307\u7684\u60c5\u51b5\u4e0b\uff0c\u952e\u5165\u8be5\u5b57\u7b26\u4e32\u9700\u8981\u7684\u6700\u5c0f\u79fb\u52a8\u603b\u8ddd\u79bb\u3002\u5750\u6807 (x1,y1) \u548c (x2,y2) \u4e4b\u95f4\u7684\u8ddd\u79bb\u662f |x1 - x2| + |y1 - y2|\u3002 

    \n\n

    \u6ce8\u610f\uff0c\u4e24\u6839\u624b\u6307\u7684\u8d77\u59cb\u4f4d\u7f6e\u662f\u96f6\u4ee3\u4ef7\u7684\uff0c\u4e0d\u8ba1\u5165\u79fb\u52a8\u603b\u8ddd\u79bb\u3002\u4f60\u7684\u4e24\u6839\u624b\u6307\u7684\u8d77\u59cb\u4f4d\u7f6e\u4e5f\u4e0d\u5fc5\u4ece\u9996\u5b57\u6bcd\u6216\u8005\u524d\u4e24\u4e2a\u5b57\u6bcd\u5f00\u59cb\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aword = "CAKE"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a \n\u4f7f\u7528\u4e24\u6839\u624b\u6307\u8f93\u5165 "CAKE" \u7684\u6700\u4f73\u65b9\u6848\u4e4b\u4e00\u662f\uff1a \n\u624b\u6307 1 \u5728\u5b57\u6bcd 'C' \u4e0a -> \u79fb\u52a8\u8ddd\u79bb = 0 \n\u624b\u6307 1 \u5728\u5b57\u6bcd 'A' \u4e0a -> \u79fb\u52a8\u8ddd\u79bb = \u4ece\u5b57\u6bcd 'C' \u5230\u5b57\u6bcd 'A' \u7684\u8ddd\u79bb = 2 \n\u624b\u6307 2 \u5728\u5b57\u6bcd 'K' \u4e0a -> \u79fb\u52a8\u8ddd\u79bb = 0 \n\u624b\u6307 2 \u5728\u5b57\u6bcd 'E' \u4e0a -> \u79fb\u52a8\u8ddd\u79bb = \u4ece\u5b57\u6bcd 'K' \u5230\u5b57\u6bcd 'E' \u7684\u8ddd\u79bb  = 1 \n\u603b\u8ddd\u79bb = 3\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aword = "HAPPY"\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a \n\u4f7f\u7528\u4e24\u6839\u624b\u6307\u8f93\u5165 "HAPPY" \u7684\u6700\u4f73\u65b9\u6848\u4e4b\u4e00\u662f\uff1a\n\u624b\u6307 1 \u5728\u5b57\u6bcd 'H' \u4e0a -> \u79fb\u52a8\u8ddd\u79bb = 0\n\u624b\u6307 1 \u5728\u5b57\u6bcd 'A' \u4e0a -> \u79fb\u52a8\u8ddd\u79bb = \u4ece\u5b57\u6bcd 'H' \u5230\u5b57\u6bcd 'A' \u7684\u8ddd\u79bb = 2\n\u624b\u6307 2 \u5728\u5b57\u6bcd 'P' \u4e0a -> \u79fb\u52a8\u8ddd\u79bb = 0\n\u624b\u6307 2 \u5728\u5b57\u6bcd 'P' \u4e0a -> \u79fb\u52a8\u8ddd\u79bb = \u4ece\u5b57\u6bcd 'P' \u5230\u5b57\u6bcd 'P' \u7684\u8ddd\u79bb = 0\n\u624b\u6307 1 \u5728\u5b57\u6bcd 'Y' \u4e0a -> \u79fb\u52a8\u8ddd\u79bb = \u4ece\u5b57\u6bcd 'A' \u5230\u5b57\u6bcd 'Y' \u7684\u8ddd\u79bb = 4\n\u603b\u8ddd\u79bb = 6\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aword = "NEW"\n\u8f93\u51fa\uff1a3\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1aword = "YEAR"\n\u8f93\u51fa\uff1a7\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= word.length <= 300
    • \n\t
    • \u6bcf\u4e2a word[i] \u90fd\u662f\u4e00\u4e2a\u5927\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minimumDistance(string word) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minimumDistance(String word) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimumDistance(self, word):\n \"\"\"\n :type word: str\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimumDistance(self, word: str) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minimumDistance(char * word){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinimumDistance(string word) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} word\n * @return {number}\n */\nvar minimumDistance = function(word) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} word\n# @return {Integer}\ndef minimum_distance(word)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimumDistance(_ word: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimumDistance(word string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimumDistance(word: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimumDistance(word: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimum_distance(word: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $word\n * @return Integer\n */\n function minimumDistance($word) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimumDistance(word: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimum-distance word)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1320](https://leetcode-cn.com/problems/minimum-distance-to-type-a-word-using-two-fingers)", "[\u4e8c\u6307\u8f93\u5165\u7684\u7684\u6700\u5c0f\u8ddd\u79bb](/solution/1300-1399/1320.Minimum%20Distance%20to%20Type%20a%20Word%20Using%20Two%20Fingers/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1320](https://leetcode.com/problems/minimum-distance-to-type-a-word-using-two-fingers)", "[Minimum Distance to Type a Word Using Two Fingers](/solution/1300-1399/1320.Minimum%20Distance%20to%20Type%20a%20Word%20Using%20Two%20Fingers/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1442", "frontend_question_id": "1319", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-operations-to-make-network-connected", "url_en": "https://leetcode.com/problems/number-of-operations-to-make-network-connected", "relative_path_cn": "/solution/1300-1399/1319.Number%20of%20Operations%20to%20Make%20Network%20Connected/README.md", "relative_path_en": "/solution/1300-1399/1319.Number%20of%20Operations%20to%20Make%20Network%20Connected/README_EN.md", "title_cn": "\u8fde\u901a\u7f51\u7edc\u7684\u64cd\u4f5c\u6b21\u6570", "title_en": "Number of Operations to Make Network Connected", "question_title_slug": "number-of-operations-to-make-network-connected", "content_en": "

    There are n computers numbered from 0 to n-1 connected by ethernet cables connections forming a network where connections[i] = [a, b] represents a connection between computers a and b. Any computer can reach any other computer directly or indirectly through the network.

    \n\n

    Given an initial computer network connections. You can extract certain cables between two directly connected computers, and place them between any pair of disconnected computers to make them directly connected. Return the minimum number of times you need to do this in order to make all the computers connected. If it's not possible, return -1. 

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: n = 4, connections = [[0,1],[0,2],[1,2]]\nOutput: 1\nExplanation: Remove cable between computer 1 and 2 and place between computers 1 and 3.\n
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: n = 6, connections = [[0,1],[0,2],[0,3],[1,2],[1,3]]\nOutput: 2\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 6, connections = [[0,1],[0,2],[0,3],[1,2]]\nOutput: -1\nExplanation: There are not enough cables.\n
    \n\n

    Example 4:

    \n\n
    \nInput: n = 5, connections = [[0,1],[0,2],[3,4],[2,3]]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 10^5
    • \n\t
    • 1 <= connections.length <= min(n*(n-1)/2, 10^5)
    • \n\t
    • connections[i].length == 2
    • \n\t
    • 0 <= connections[i][0], connections[i][1] < n
    • \n\t
    • connections[i][0] != connections[i][1]
    • \n\t
    • There are no repeated connections.
    • \n\t
    • No two computers are connected by more than one cable.
    • \n
    \n", "content_cn": "

    \u7528\u4ee5\u592a\u7f51\u7ebf\u7f06\u5c06 n \u53f0\u8ba1\u7b97\u673a\u8fde\u63a5\u6210\u4e00\u4e2a\u7f51\u7edc\uff0c\u8ba1\u7b97\u673a\u7684\u7f16\u53f7\u4ece 0 \u5230 n-1\u3002\u7ebf\u7f06\u7528 connections \u8868\u793a\uff0c\u5176\u4e2d connections[i] = [a, b] \u8fde\u63a5\u4e86\u8ba1\u7b97\u673a a \u548c b\u3002

    \n\n

    \u7f51\u7edc\u4e2d\u7684\u4efb\u4f55\u4e00\u53f0\u8ba1\u7b97\u673a\u90fd\u53ef\u4ee5\u901a\u8fc7\u7f51\u7edc\u76f4\u63a5\u6216\u8005\u95f4\u63a5\u8bbf\u95ee\u540c\u4e00\u4e2a\u7f51\u7edc\u4e2d\u5176\u4ed6\u4efb\u610f\u4e00\u53f0\u8ba1\u7b97\u673a\u3002

    \n\n

    \u7ed9\u4f60\u8fd9\u4e2a\u8ba1\u7b97\u673a\u7f51\u7edc\u7684\u521d\u59cb\u5e03\u7ebf connections\uff0c\u4f60\u53ef\u4ee5\u62d4\u5f00\u4efb\u610f\u4e24\u53f0\u76f4\u8fde\u8ba1\u7b97\u673a\u4e4b\u95f4\u7684\u7ebf\u7f06\uff0c\u5e76\u7528\u5b83\u8fde\u63a5\u4e00\u5bf9\u672a\u76f4\u8fde\u7684\u8ba1\u7b97\u673a\u3002\u8bf7\u4f60\u8ba1\u7b97\u5e76\u8fd4\u56de\u4f7f\u6240\u6709\u8ba1\u7b97\u673a\u90fd\u8fde\u901a\u6240\u9700\u7684\u6700\u5c11\u64cd\u4f5c\u6b21\u6570\u3002\u5982\u679c\u4e0d\u53ef\u80fd\uff0c\u5219\u8fd4\u56de -1 \u3002 

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 4, connections = [[0,1],[0,2],[1,2]]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u62d4\u4e0b\u8ba1\u7b97\u673a 1 \u548c 2 \u4e4b\u95f4\u7684\u7ebf\u7f06\uff0c\u5e76\u5c06\u5b83\u63d2\u5230\u8ba1\u7b97\u673a 1 \u548c 3 \u4e0a\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 6, connections = [[0,1],[0,2],[0,3],[1,2],[1,3]]\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1an = 6, connections = [[0,1],[0,2],[0,3],[1,2]]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u7ebf\u7f06\u6570\u91cf\u4e0d\u8db3\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1an = 5, connections = [[0,1],[0,2],[3,4],[2,3]]\n\u8f93\u51fa\uff1a0\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 10^5
    • \n\t
    • 1 <= connections.length <= min(n*(n-1)/2, 10^5)
    • \n\t
    • connections[i].length == 2
    • \n\t
    • 0 <= connections[i][0], connections[i][1] < n
    • \n\t
    • connections[i][0] != connections[i][1]
    • \n\t
    • \u6ca1\u6709\u91cd\u590d\u7684\u8fde\u63a5\u3002
    • \n\t
    • \u4e24\u53f0\u8ba1\u7b97\u673a\u4e0d\u4f1a\u901a\u8fc7\u591a\u6761\u7ebf\u7f06\u8fde\u63a5\u3002
    • \n
    \n", "tags_en": ["Depth-first Search", "Breadth-first Search", "Union Find"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e76\u67e5\u96c6"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int makeConnected(int n, vector>& connections) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int makeConnected(int n, int[][] connections) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def makeConnected(self, n, connections):\n \"\"\"\n :type n: int\n :type connections: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def makeConnected(self, n: int, connections: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint makeConnected(int n, int** connections, int connectionsSize, int* connectionsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MakeConnected(int n, int[][] connections) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} connections\n * @return {number}\n */\nvar makeConnected = function(n, connections) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} connections\n# @return {Integer}\ndef make_connected(n, connections)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func makeConnected(_ n: Int, _ connections: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func makeConnected(n int, connections [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def makeConnected(n: Int, connections: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun makeConnected(n: Int, connections: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn make_connected(n: i32, connections: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $connections\n * @return Integer\n */\n function makeConnected($n, $connections) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function makeConnected(n: number, connections: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (make-connected n connections)\n (-> exact-integer? (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1319](https://leetcode-cn.com/problems/number-of-operations-to-make-network-connected)", "[\u8fde\u901a\u7f51\u7edc\u7684\u64cd\u4f5c\u6b21\u6570](/solution/1300-1399/1319.Number%20of%20Operations%20to%20Make%20Network%20Connected/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e76\u67e5\u96c6`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1319](https://leetcode.com/problems/number-of-operations-to-make-network-connected)", "[Number of Operations to Make Network Connected](/solution/1300-1399/1319.Number%20of%20Operations%20to%20Make%20Network%20Connected/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`,`Union Find`", "Medium", ""]}, {"question_id": "1441", "frontend_question_id": "1318", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-flips-to-make-a-or-b-equal-to-c", "url_en": "https://leetcode.com/problems/minimum-flips-to-make-a-or-b-equal-to-c", "relative_path_cn": "/solution/1300-1399/1318.Minimum%20Flips%20to%20Make%20a%20OR%20b%20Equal%20to%20c/README.md", "relative_path_en": "/solution/1300-1399/1318.Minimum%20Flips%20to%20Make%20a%20OR%20b%20Equal%20to%20c/README_EN.md", "title_cn": "\u6216\u8fd0\u7b97\u7684\u6700\u5c0f\u7ffb\u8f6c\u6b21\u6570", "title_en": "Minimum Flips to Make a OR b Equal to c", "question_title_slug": "minimum-flips-to-make-a-or-b-equal-to-c", "content_en": "

    Given 3 positives numbers a, b and c. Return the minimum flips required in some bits of a and b to make ( a OR b == c ). (bitwise OR operation).
    \r\nFlip operation consists of change any single bit 1 to 0 or change the bit 0 to 1 in their binary representation.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n

    \"\"

    \r\n\r\n
    \r\nInput: a = 2, b = 6, c = 5\r\nOutput: 3\r\nExplanation: After flips a = 1 , b = 4 , c = 5 such that (a OR b == c)
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: a = 4, b = 2, c = 7\r\nOutput: 1\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: a = 1, b = 2, c = 3\r\nOutput: 0\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= a <= 10^9
    • \r\n\t
    • 1 <= b <= 10^9
    • \r\n\t
    • 1 <= c <= 10^9
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e09\u4e2a\u6b63\u6574\u6570 a\u3001b \u548c c\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u5bf9 a \u548c b \u7684\u4e8c\u8fdb\u5236\u8868\u793a\u8fdb\u884c\u4f4d\u7ffb\u8f6c\u64cd\u4f5c\uff0c\u8fd4\u56de\u80fd\u591f\u4f7f\u6309\u4f4d\u6216\u8fd0\u7b97   a OR b == c  \u6210\u7acb\u7684\u6700\u5c0f\u7ffb\u8f6c\u6b21\u6570\u3002

    \n\n

    \u300c\u4f4d\u7ffb\u8f6c\u64cd\u4f5c\u300d\u662f\u6307\u5c06\u4e00\u4e2a\u6570\u7684\u4e8c\u8fdb\u5236\u8868\u793a\u4efb\u4f55\u5355\u4e2a\u4f4d\u4e0a\u7684 1 \u53d8\u6210 0 \u6216\u8005 0 \u53d8\u6210 1 \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1aa = 2, b = 6, c = 5\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u7ffb\u8f6c\u540e a = 1 , b = 4 , c = 5 \u4f7f\u5f97 a OR b == c
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aa = 4, b = 2, c = 7\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aa = 1, b = 2, c = 3\n\u8f93\u51fa\uff1a0\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= a <= 10^9
    • \n\t
    • 1 <= b <= 10^9
    • \n\t
    • 1 <= c <= 10^9
    • \n
    \n", "tags_en": ["Bit Manipulation"], "tags_cn": ["\u4f4d\u8fd0\u7b97"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minFlips(int a, int b, int c) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minFlips(int a, int b, int c) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minFlips(self, a, b, c):\n \"\"\"\n :type a: int\n :type b: int\n :type c: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minFlips(self, a: int, b: int, c: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minFlips(int a, int b, int c){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinFlips(int a, int b, int c) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} a\n * @param {number} b\n * @param {number} c\n * @return {number}\n */\nvar minFlips = function(a, b, c) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} a\n# @param {Integer} b\n# @param {Integer} c\n# @return {Integer}\ndef min_flips(a, b, c)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minFlips(_ a: Int, _ b: Int, _ c: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minFlips(a int, b int, c int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minFlips(a: Int, b: Int, c: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minFlips(a: Int, b: Int, c: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_flips(a: i32, b: i32, c: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $a\n * @param Integer $b\n * @param Integer $c\n * @return Integer\n */\n function minFlips($a, $b, $c) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minFlips(a: number, b: number, c: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-flips a b c)\n (-> exact-integer? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1318](https://leetcode-cn.com/problems/minimum-flips-to-make-a-or-b-equal-to-c)", "[\u6216\u8fd0\u7b97\u7684\u6700\u5c0f\u7ffb\u8f6c\u6b21\u6570](/solution/1300-1399/1318.Minimum%20Flips%20to%20Make%20a%20OR%20b%20Equal%20to%20c/README.md)", "`\u4f4d\u8fd0\u7b97`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1318](https://leetcode.com/problems/minimum-flips-to-make-a-or-b-equal-to-c)", "[Minimum Flips to Make a OR b Equal to c](/solution/1300-1399/1318.Minimum%20Flips%20to%20Make%20a%20OR%20b%20Equal%20to%20c/README_EN.md)", "`Bit Manipulation`", "Medium", ""]}, {"question_id": "1440", "frontend_question_id": "1317", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers", "url_en": "https://leetcode.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers", "relative_path_cn": "/solution/1300-1399/1317.Convert%20Integer%20to%20the%20Sum%20of%20Two%20No-Zero%20Integers/README.md", "relative_path_en": "/solution/1300-1399/1317.Convert%20Integer%20to%20the%20Sum%20of%20Two%20No-Zero%20Integers/README_EN.md", "title_cn": "\u5c06\u6574\u6570\u8f6c\u6362\u4e3a\u4e24\u4e2a\u65e0\u96f6\u6574\u6570\u7684\u548c", "title_en": "Convert Integer to the Sum of Two No-Zero Integers", "question_title_slug": "convert-integer-to-the-sum-of-two-no-zero-integers", "content_en": "

    Given an integer n. No-Zero integer is a positive integer which doesn't contain any 0 in its decimal representation.

    \r\n\r\n

    Return a list of two integers [A, B] where:

    \r\n\r\n
      \r\n\t
    • A and B are No-Zero integers.
    • \r\n\t
    • A + B = n
    • \r\n
    \r\n\r\n

    It's guarateed that there is at least one valid solution. If there are many valid solutions you can return any of them.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: n = 2\r\nOutput: [1,1]\r\nExplanation: A = 1, B = 1. A + B = n and both A and B don't contain any 0 in their decimal representation.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: n = 11\r\nOutput: [2,9]\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: n = 10000\r\nOutput: [1,9999]\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: n = 69\r\nOutput: [1,68]\r\n
    \r\n\r\n

    Example 5:

    \r\n\r\n
    \r\nInput: n = 1010\r\nOutput: [11,999]\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 2 <= n <= 10^4
    • \r\n
    ", "content_cn": "

    \u300c\u65e0\u96f6\u6574\u6570\u300d\u662f\u5341\u8fdb\u5236\u8868\u793a\u4e2d \u4e0d\u542b\u4efb\u4f55 0 \u7684\u6b63\u6574\u6570\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n\uff0c\u8bf7\u4f60\u8fd4\u56de\u4e00\u4e2a \u7531\u4e24\u4e2a\u6574\u6570\u7ec4\u6210\u7684\u5217\u8868 [A, B]\uff0c\u6ee1\u8db3\uff1a

    \n\n
      \n\t
    • A \u548c B \u90fd\u662f\u65e0\u96f6\u6574\u6570
    • \n\t
    • A + B = n
    • \n
    \n\n

    \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u81f3\u5c11\u6709\u4e00\u4e2a\u6709\u6548\u7684\u89e3\u51b3\u65b9\u6848\u3002

    \n\n

    \u5982\u679c\u5b58\u5728\u591a\u4e2a\u6709\u6548\u89e3\u51b3\u65b9\u6848\uff0c\u4f60\u53ef\u4ee5\u8fd4\u56de\u5176\u4e2d\u4efb\u610f\u4e00\u4e2a\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1an = 2\n\u8f93\u51fa\uff1a[1,1]\n\u89e3\u91ca\uff1aA = 1, B = 1. A + B = n \u5e76\u4e14 A \u548c B \u7684\u5341\u8fdb\u5236\u8868\u793a\u5f62\u5f0f\u90fd\u4e0d\u5305\u542b\u4efb\u4f55 0 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1an = 11\n\u8f93\u51fa\uff1a[2,9]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1an = 10000\n\u8f93\u51fa\uff1a[1,9999]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1an = 69\n\u8f93\u51fa\uff1a[1,68]\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1an = 1010\n\u8f93\u51fa\uff1a[11,999]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= n <= 10^4
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector getNoZeroIntegers(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] getNoZeroIntegers(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getNoZeroIntegers(self, n):\n \"\"\"\n :type n: int\n :rtype: List[int]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getNoZeroIntegers(self, n: int) -> List[int]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* getNoZeroIntegers(int n, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] GetNoZeroIntegers(int n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number[]}\n */\nvar getNoZeroIntegers = function(n) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer[]}\ndef get_no_zero_integers(n)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getNoZeroIntegers(_ n: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getNoZeroIntegers(n int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getNoZeroIntegers(n: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getNoZeroIntegers(n: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_no_zero_integers(n: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer[]\n */\n function getNoZeroIntegers($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getNoZeroIntegers(n: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-no-zero-integers n)\n (-> exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1317](https://leetcode-cn.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers)", "[\u5c06\u6574\u6570\u8f6c\u6362\u4e3a\u4e24\u4e2a\u65e0\u96f6\u6574\u6570\u7684\u548c](/solution/1300-1399/1317.Convert%20Integer%20to%20the%20Sum%20of%20Two%20No-Zero%20Integers/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[1317](https://leetcode.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers)", "[Convert Integer to the Sum of Two No-Zero Integers](/solution/1300-1399/1317.Convert%20Integer%20to%20the%20Sum%20of%20Two%20No-Zero%20Integers/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "1439", "frontend_question_id": "1308", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/running-total-for-different-genders", "url_en": "https://leetcode.com/problems/running-total-for-different-genders", "relative_path_cn": "/solution/1300-1399/1308.Running%20Total%20for%20Different%20Genders/README.md", "relative_path_en": "/solution/1300-1399/1308.Running%20Total%20for%20Different%20Genders/README_EN.md", "title_cn": "\u4e0d\u540c\u6027\u522b\u6bcf\u65e5\u5206\u6570\u603b\u8ba1", "title_en": "Running Total for Different Genders", "question_title_slug": "running-total-for-different-genders", "content_en": "

    Table: Scores

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| player_name   | varchar |\n| gender        | varchar |\n| day           | date    |\n| score_points  | int     |\n+---------------+---------+\n(gender, day) is the primary key for this table.\nA competition is held between females team and males team.\nEach row of this table indicates that a player_name and with gender has scored score_point in someday.\nGender is 'F' if the player is in females team and 'M' if the player is in males team.\n
    \n\n

     

    \n\n

    Write an SQL query to find the total score for each gender at each day.

    \n\n

    Order the result table by gender and day

    \n\n

    The query result format is in the following example:

    \n\n
    \nScores table:\n+-------------+--------+------------+--------------+\n| player_name | gender | day        | score_points |\n+-------------+--------+------------+--------------+\n| Aron        | F      | 2020-01-01 | 17           |\n| Alice       | F      | 2020-01-07 | 23           |\n| Bajrang     | M      | 2020-01-07 | 7            |\n| Khali       | M      | 2019-12-25 | 11           |\n| Slaman      | M      | 2019-12-30 | 13           |\n| Joe         | M      | 2019-12-31 | 3            |\n| Jose        | M      | 2019-12-18 | 2            |\n| Priya       | F      | 2019-12-31 | 23           |\n| Priyanka    | F      | 2019-12-30 | 17           |\n+-------------+--------+------------+--------------+\nResult table:\n+--------+------------+-------+\n| gender | day        | total |\n+--------+------------+-------+\n| F      | 2019-12-30 | 17    |\n| F      | 2019-12-31 | 40    |\n| F      | 2020-01-01 | 57    |\n| F      | 2020-01-07 | 80    |\n| M      | 2019-12-18 | 2     |\n| M      | 2019-12-25 | 13    |\n| M      | 2019-12-30 | 26    |\n| M      | 2019-12-31 | 29    |\n| M      | 2020-01-07 | 36    |\n+--------+------------+-------+\nFor females team:\nFirst day is 2019-12-30, Priyanka scored 17 points and the total score for the team is 17.\nSecond day is 2019-12-31, Priya scored 23 points and the total score for the team is 40.\nThird day is 2020-01-01, Aron scored 17 points and the total score for the team is 57.\nFourth day is 2020-01-07, Alice scored 23 points and the total score for the team is 80.\nFor males team:\nFirst day is 2019-12-18, Jose scored 2 points and the total score for the team is 2.\nSecond day is 2019-12-25, Khali scored 11 points and the total score for the team is 13.\nThird day is 2019-12-30, Slaman scored 13 points and the total score for the team is 26.\nFourth day is 2019-12-31, Joe scored 3 points and the total score for the team is 29.\nFifth day is 2020-01-07, Bajrang scored 7 points and the total score for the team is 36.\n
    \n", "content_cn": "

    \u8868: Scores

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| player_name   | varchar |\n| gender        | varchar |\n| day           | date    |\n| score_points  | int     |\n+---------------+---------+\n(gender, day)\u662f\u8be5\u8868\u7684\u4e3b\u952e\n\u4e00\u573a\u6bd4\u8d5b\u662f\u5728\u5973\u961f\u548c\u7537\u961f\u4e4b\u95f4\u4e3e\u884c\u7684\n\u8be5\u8868\u7684\u6bcf\u4e00\u884c\u8868\u793a\u4e00\u4e2a\u540d\u53eb (player_name) \u6027\u522b\u4e3a (gender) \u7684\u53c2\u8d5b\u8005\u5728\u67d0\u4e00\u5929\u83b7\u5f97\u4e86 (score_points) \u7684\u5206\u6570\n\u5982\u679c\u53c2\u8d5b\u8005\u662f\u5973\u6027\uff0c\u90a3\u4e48 gender \u5217\u4e3a 'F'\uff0c\u5982\u679c\u53c2\u8d5b\u8005\u662f\u7537\u6027\uff0c\u90a3\u4e48 gender \u5217\u4e3a 'M'\n
    \n\n

     

    \n\n

    \u5199\u4e00\u6761SQL\u8bed\u53e5\u67e5\u8be2\u6bcf\u79cd\u6027\u522b\u5728\u6bcf\u4e00\u5929\u7684\u603b\u5206\uff0c\u5e76\u6309\u6027\u522b\u548c\u65e5\u671f\u5bf9\u67e5\u8be2\u7ed3\u679c\u6392\u5e8f

    \n\n

    \u4e0b\u9762\u662f\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u7684\u4f8b\u5b50\uff1a

    \n\n
    \nScores\u8868:\n+-------------+--------+------------+--------------+\n| player_name | gender | day        | score_points |\n+-------------+--------+------------+--------------+\n| Aron        | F      | 2020-01-01 | 17           |\n| Alice       | F      | 2020-01-07 | 23           |\n| Bajrang     | M      | 2020-01-07 | 7            |\n| Khali       | M      | 2019-12-25 | 11           |\n| Slaman      | M      | 2019-12-30 | 13           |\n| Joe         | M      | 2019-12-31 | 3            |\n| Jose        | M      | 2019-12-18 | 2            |\n| Priya       | F      | 2019-12-31 | 23           |\n| Priyanka    | F      | 2019-12-30 | 17           |\n+-------------+--------+------------+--------------+\n\u7ed3\u679c\u8868:\n+--------+------------+-------+\n| gender | day        | total |\n+--------+------------+-------+\n| F      | 2019-12-30 | 17    |\n| F      | 2019-12-31 | 40    |\n| F      | 2020-01-01 | 57    |\n| F      | 2020-01-07 | 80    |\n| M      | 2019-12-18 | 2     |\n| M      | 2019-12-25 | 13    |\n| M      | 2019-12-30 | 26    |\n| M      | 2019-12-31 | 29    |\n| M      | 2020-01-07 | 36    |\n+--------+------------+-------+\n\u5973\u6027\u961f\u4f0d:\n\u7b2c\u4e00\u5929\u662f 2019-12-30\uff0cPriyanka \u83b7\u5f97 17 \u5206\uff0c\u961f\u4f0d\u7684\u603b\u5206\u662f 17 \u5206\n\u7b2c\u4e8c\u5929\u662f 2019-12-31, Priya \u83b7\u5f97 23 \u5206\uff0c\u961f\u4f0d\u7684\u603b\u5206\u662f 40 \u5206\n\u7b2c\u4e09\u5929\u662f 2020-01-01, Aron \u83b7\u5f97 17 \u5206\uff0c\u961f\u4f0d\u7684\u603b\u5206\u662f 57 \u5206\n\u7b2c\u56db\u5929\u662f 2020-01-07, Alice \u83b7\u5f97 23 \u5206\uff0c\u961f\u4f0d\u7684\u603b\u5206\u662f 80 \u5206\n\u7537\u6027\u961f\u4f0d\uff1a\n\u7b2c\u4e00\u5929\u662f 2019-12-18, Jose \u83b7\u5f97 2 \u5206\uff0c\u961f\u4f0d\u7684\u603b\u5206\u662f 2 \u5206\n\u7b2c\u4e8c\u5929\u662f 2019-12-25, Khali \u83b7\u5f97 11 \u5206\uff0c\u961f\u4f0d\u7684\u603b\u5206\u662f 13 \u5206\n\u7b2c\u4e09\u5929\u662f 2019-12-30, Slaman \u83b7\u5f97 13 \u5206\uff0c\u961f\u4f0d\u7684\u603b\u5206\u662f 26 \u5206\n\u7b2c\u56db\u5929\u662f 2019-12-31, Joe \u83b7\u5f97 3 \u5206\uff0c\u961f\u4f0d\u7684\u603b\u5206\u662f 29 \u5206\n\u7b2c\u4e94\u5929\u662f 2020-01-07, Bajrang \u83b7\u5f97 7 \u5206\uff0c\u961f\u4f0d\u7684\u603b\u5206\u662f 36 \u5206\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1308](https://leetcode-cn.com/problems/running-total-for-different-genders)", "[\u4e0d\u540c\u6027\u522b\u6bcf\u65e5\u5206\u6570\u603b\u8ba1](/solution/1300-1399/1308.Running%20Total%20for%20Different%20Genders/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1308](https://leetcode.com/problems/running-total-for-different-genders)", "[Running Total for Different Genders](/solution/1300-1399/1308.Running%20Total%20for%20Different%20Genders/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1438", "frontend_question_id": "1303", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/find-the-team-size", "url_en": "https://leetcode.com/problems/find-the-team-size", "relative_path_cn": "/solution/1300-1399/1303.Find%20the%20Team%20Size/README.md", "relative_path_en": "/solution/1300-1399/1303.Find%20the%20Team%20Size/README_EN.md", "title_cn": "\u6c42\u56e2\u961f\u4eba\u6570", "title_en": "Find the Team Size", "question_title_slug": "find-the-team-size", "content_en": "

    Table: Employee

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| employee_id   | int     |\n| team_id       | int     |\n+---------------+---------+\nemployee_id is the primary key for this table.\nEach row of this table contains the ID of each employee and their respective team.\n
    \n\n

    Write an SQL query to find the team size of each of the employees.

    \n\n

    Return result table in any order.

    \n\n

    The query result format is in the following example:

    \n\n
    \nEmployee Table:\n+-------------+------------+\n| employee_id | team_id    |\n+-------------+------------+\n|     1       |     8      |\n|     2       |     8      |\n|     3       |     8      |\n|     4       |     7      |\n|     5       |     9      |\n|     6       |     9      |\n+-------------+------------+\nResult table:\n+-------------+------------+\n| employee_id | team_size  |\n+-------------+------------+\n|     1       |     3      |\n|     2       |     3      |\n|     3       |     3      |\n|     4       |     1      |\n|     5       |     2      |\n|     6       |     2      |\n+-------------+------------+\nEmployees with Id 1,2,3 are part of a team with team_id = 8.\nEmployees with Id 4 is part of a team with team_id = 7.\nEmployees with Id 5,6 are part of a team with team_id = 9.\n\n
    \n", "content_cn": "

    \u5458\u5de5\u8868\uff1aEmployee

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| employee_id   | int     |\n| team_id       | int     |\n+---------------+---------+\nemployee_id \u5b57\u6bb5\u662f\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\uff0c\u8868\u4e2d\u7684\u6bcf\u4e00\u884c\u90fd\u5305\u542b\u6bcf\u4e2a\u5458\u5de5\u7684 ID \u548c\u4ed6\u4eec\u6240\u5c5e\u7684\u56e2\u961f\u3002\n
    \n\n

    \u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\uff0c\u4ee5\u6c42\u5f97\u6bcf\u4e2a\u5458\u5de5\u6240\u5728\u56e2\u961f\u7684\u603b\u4eba\u6570\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u4e2d\u7684\u987a\u5e8f\u65e0\u7279\u5b9a\u8981\u6c42\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u793a\u4f8b\u5982\u4e0b\uff1a

    \n\n
    \nEmployee Table:\n+-------------+------------+\n| employee_id | team_id    |\n+-------------+------------+\n|     1       |     8      |\n|     2       |     8      |\n|     3       |     8      |\n|     4       |     7      |\n|     5       |     9      |\n|     6       |     9      |\n+-------------+------------+\nResult table:\n+-------------+------------+\n| employee_id | team_size  |\n+-------------+------------+\n|     1       |     3      |\n|     2       |     3      |\n|     3       |     3      |\n|     4       |     1      |\n|     5       |     2      |\n|     6       |     2      |\n+-------------+------------+\nID \u4e3a 1\u30012\u30013 \u7684\u5458\u5de5\u662f team_id \u4e3a 8 \u7684\u56e2\u961f\u7684\u6210\u5458\uff0c\nID \u4e3a 4 \u7684\u5458\u5de5\u662f team_id \u4e3a 7 \u7684\u56e2\u961f\u7684\u6210\u5458\uff0c\nID \u4e3a 5\u30016 \u7684\u5458\u5de5\u662f team_id \u4e3a 9 \u7684\u56e2\u961f\u7684\u6210\u5458\u3002\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1303](https://leetcode-cn.com/problems/find-the-team-size)", "[\u6c42\u56e2\u961f\u4eba\u6570](/solution/1300-1399/1303.Find%20the%20Team%20Size/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1303](https://leetcode.com/problems/find-the-team-size)", "[Find the Team Size](/solution/1300-1399/1303.Find%20the%20Team%20Size/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1437", "frontend_question_id": "1312", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-insertion-steps-to-make-a-string-palindrome", "url_en": "https://leetcode.com/problems/minimum-insertion-steps-to-make-a-string-palindrome", "relative_path_cn": "/solution/1300-1399/1312.Minimum%20Insertion%20Steps%20to%20Make%20a%20String%20Palindrome/README.md", "relative_path_en": "/solution/1300-1399/1312.Minimum%20Insertion%20Steps%20to%20Make%20a%20String%20Palindrome/README_EN.md", "title_cn": "\u8ba9\u5b57\u7b26\u4e32\u6210\u4e3a\u56de\u6587\u4e32\u7684\u6700\u5c11\u63d2\u5165\u6b21\u6570", "title_en": "Minimum Insertion Steps to Make a String Palindrome", "question_title_slug": "minimum-insertion-steps-to-make-a-string-palindrome", "content_en": "

    Given a string s. In one step you can insert any character at any index of the string.

    \n\n

    Return the minimum number of steps to make s palindrome.

    \n\n

    Palindrome String is one that reads the same backward as well as forward.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "zzazz"\nOutput: 0\nExplanation: The string "zzazz" is already palindrome we don't need any insertions.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "mbadm"\nOutput: 2\nExplanation: String can be "mbdadbm" or "mdbabdm".\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "leetcode"\nOutput: 5\nExplanation: Inserting 5 characters the string becomes "leetcodocteel".\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "g"\nOutput: 0\n
    \n\n

    Example 5:

    \n\n
    \nInput: s = "no"\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 500
    • \n\t
    • All characters of s are lower case English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \uff0c\u6bcf\u4e00\u6b21\u64cd\u4f5c\u4f60\u90fd\u53ef\u4ee5\u5728\u5b57\u7b26\u4e32\u7684\u4efb\u610f\u4f4d\u7f6e\u63d2\u5165\u4efb\u610f\u5b57\u7b26\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u8ba9 s \u6210\u4e3a\u56de\u6587\u4e32\u7684 \u6700\u5c11\u64cd\u4f5c\u6b21\u6570 \u3002

    \n\n

    \u300c\u56de\u6587\u4e32\u300d\u662f\u6b63\u8bfb\u548c\u53cd\u8bfb\u90fd\u76f8\u540c\u7684\u5b57\u7b26\u4e32\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = "zzazz"\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u5b57\u7b26\u4e32 "zzazz" \u5df2\u7ecf\u662f\u56de\u6587\u4e32\u4e86\uff0c\u6240\u4ee5\u4e0d\u9700\u8981\u505a\u4efb\u4f55\u63d2\u5165\u64cd\u4f5c\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = "mbadm"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5b57\u7b26\u4e32\u53ef\u53d8\u4e3a "mbdadbm" \u6216\u8005 "mdbabdm" \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = "leetcode"\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u63d2\u5165 5 \u4e2a\u5b57\u7b26\u540e\u5b57\u7b26\u4e32\u53d8\u4e3a "leetcodocteel" \u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = "g"\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = "no"\n\u8f93\u51fa\uff1a1\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 500
    • \n\t
    • s \u4e2d\u6240\u6709\u5b57\u7b26\u90fd\u662f\u5c0f\u5199\u5b57\u6bcd\u3002
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minInsertions(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minInsertions(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minInsertions(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minInsertions(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minInsertions(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinInsertions(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar minInsertions = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef min_insertions(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minInsertions(_ s: String) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minInsertions(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minInsertions(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minInsertions(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_insertions(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function minInsertions($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minInsertions(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-insertions s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1312](https://leetcode-cn.com/problems/minimum-insertion-steps-to-make-a-string-palindrome)", "[\u8ba9\u5b57\u7b26\u4e32\u6210\u4e3a\u56de\u6587\u4e32\u7684\u6700\u5c11\u63d2\u5165\u6b21\u6570](/solution/1300-1399/1312.Minimum%20Insertion%20Steps%20to%20Make%20a%20String%20Palindrome/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1312](https://leetcode.com/problems/minimum-insertion-steps-to-make-a-string-palindrome)", "[Minimum Insertion Steps to Make a String Palindrome](/solution/1300-1399/1312.Minimum%20Insertion%20Steps%20to%20Make%20a%20String%20Palindrome/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1436", "frontend_question_id": "1311", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/get-watched-videos-by-your-friends", "url_en": "https://leetcode.com/problems/get-watched-videos-by-your-friends", "relative_path_cn": "/solution/1300-1399/1311.Get%20Watched%20Videos%20by%20Your%20Friends/README.md", "relative_path_en": "/solution/1300-1399/1311.Get%20Watched%20Videos%20by%20Your%20Friends/README_EN.md", "title_cn": "\u83b7\u53d6\u4f60\u597d\u53cb\u5df2\u89c2\u770b\u7684\u89c6\u9891", "title_en": "Get Watched Videos by Your Friends", "question_title_slug": "get-watched-videos-by-your-friends", "content_en": "

    There are n people, each person has a unique id between 0 and n-1. Given the arrays watchedVideos and friends, where watchedVideos[i] and friends[i] contain the list of watched videos and the list of friends respectively for the person with id = i.

    \n\n

    Level 1 of videos are all watched videos by your friends, level 2 of videos are all watched videos by the friends of your friends and so on. In general, the level k of videos are all watched videos by people with the shortest path exactly equal to k with you. Given your id and the level of videos, return the list of videos ordered by their frequencies (increasing). For videos with the same frequency order them alphabetically from least to greatest. 

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: watchedVideos = [["A","B"],["C"],["B","C"],["D"]], friends = [[1,2],[0,3],[0,3],[1,2]], id = 0, level = 1\nOutput: ["B","C"] \nExplanation: \nYou have id = 0 (green color in the figure) and your friends are (yellow color in the figure):\nPerson with id = 1 -> watchedVideos = ["C"] \nPerson with id = 2 -> watchedVideos = ["B","C"] \nThe frequencies of watchedVideos by your friends are: \nB -> 1 \nC -> 2\n
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: watchedVideos = [["A","B"],["C"],["B","C"],["D"]], friends = [[1,2],[0,3],[0,3],[1,2]], id = 0, level = 2\nOutput: ["D"]\nExplanation: \nYou have id = 0 (green color in the figure) and the only friend of your friends is the person with id = 3 (yellow color in the figure).\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == watchedVideos.length == friends.length
    • \n\t
    • 2 <= n <= 100
    • \n\t
    • 1 <= watchedVideos[i].length <= 100
    • \n\t
    • 1 <= watchedVideos[i][j].length <= 8
    • \n\t
    • 0 <= friends[i].length < n
    • \n\t
    • 0 <= friends[i][j] < n
    • \n\t
    • 0 <= id < n
    • \n\t
    • 1 <= level < n
    • \n\t
    • if friends[i] contains j, then friends[j] contains i
    • \n
    \n", "content_cn": "

    \u6709 n \u4e2a\u4eba\uff0c\u6bcf\u4e2a\u4eba\u90fd\u6709\u4e00\u4e2a  0 \u5230 n-1 \u7684\u552f\u4e00 id \u3002

    \n\n

    \u7ed9\u4f60\u6570\u7ec4 watchedVideos  \u548c friends \uff0c\u5176\u4e2d watchedVideos[i]  \u548c friends[i] \u5206\u522b\u8868\u793a id = i \u7684\u4eba\u89c2\u770b\u8fc7\u7684\u89c6\u9891\u5217\u8868\u548c\u4ed6\u7684\u597d\u53cb\u5217\u8868\u3002

    \n\n

    Level 1 \u7684\u89c6\u9891\u5305\u542b\u6240\u6709\u4f60\u597d\u53cb\u89c2\u770b\u8fc7\u7684\u89c6\u9891\uff0clevel 2 \u7684\u89c6\u9891\u5305\u542b\u6240\u6709\u4f60\u597d\u53cb\u7684\u597d\u53cb\u89c2\u770b\u8fc7\u7684\u89c6\u9891\uff0c\u4ee5\u6b64\u7c7b\u63a8\u3002\u4e00\u822c\u7684\uff0cLevel \u4e3a k \u7684\u89c6\u9891\u5305\u542b\u6240\u6709\u4ece\u4f60\u51fa\u53d1\uff0c\u6700\u77ed\u8ddd\u79bb\u4e3a k \u7684\u597d\u53cb\u89c2\u770b\u8fc7\u7684\u89c6\u9891\u3002

    \n\n

    \u7ed9\u5b9a\u4f60\u7684 id  \u548c\u4e00\u4e2a level \u503c\uff0c\u8bf7\u4f60\u627e\u51fa\u6240\u6709\u6307\u5b9a level \u7684\u89c6\u9891\uff0c\u5e76\u5c06\u5b83\u4eec\u6309\u89c2\u770b\u9891\u7387\u5347\u5e8f\u8fd4\u56de\u3002\u5982\u679c\u6709\u9891\u7387\u76f8\u540c\u7684\u89c6\u9891\uff0c\u8bf7\u5c06\u5b83\u4eec\u6309\u5b57\u6bcd\u987a\u5e8f\u4ece\u5c0f\u5230\u5927\u6392\u5217\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1awatchedVideos = [["A","B"],["C"],["B","C"],["D"]], friends = [[1,2],[0,3],[0,3],[1,2]], id = 0, level = 1\n\u8f93\u51fa\uff1a["B","C"] \n\u89e3\u91ca\uff1a\n\u4f60\u7684 id \u4e3a 0\uff08\u7eff\u8272\uff09\uff0c\u4f60\u7684\u670b\u53cb\u5305\u62ec\uff08\u9ec4\u8272\uff09\uff1a\nid \u4e3a 1 -> watchedVideos = ["C"] \nid \u4e3a 2 -> watchedVideos = ["B","C"] \n\u4f60\u670b\u53cb\u89c2\u770b\u8fc7\u89c6\u9891\u7684\u9891\u7387\u4e3a\uff1a\nB -> 1 \nC -> 2\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1awatchedVideos = [["A","B"],["C"],["B","C"],["D"]], friends = [[1,2],[0,3],[0,3],[1,2]], id = 0, level = 2\n\u8f93\u51fa\uff1a["D"]\n\u89e3\u91ca\uff1a\n\u4f60\u7684 id \u4e3a 0\uff08\u7eff\u8272\uff09\uff0c\u4f60\u670b\u53cb\u7684\u670b\u53cb\u53ea\u6709\u4e00\u4e2a\u4eba\uff0c\u4ed6\u7684 id \u4e3a 3\uff08\u9ec4\u8272\uff09\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == watchedVideos.length == friends.length
    • \n\t
    • 2 <= n <= 100
    • \n\t
    • 1 <= watchedVideos[i].length <= 100
    • \n\t
    • 1 <= watchedVideos[i][j].length <= 8
    • \n\t
    • 0 <= friends[i].length < n
    • \n\t
    • 0 <= friends[i][j] < n
    • \n\t
    • 0 <= id < n
    • \n\t
    • 1 <= level < n
    • \n\t
    • \u5982\u679c friends[i] \u5305\u542b j \uff0c\u90a3\u4e48 friends[j] \u5305\u542b i
    • \n
    \n", "tags_en": ["Breadth-first Search", "Hash Table", "String"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u54c8\u5e0c\u8868", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector watchedVideosByFriends(vector>& watchedVideos, vector>& friends, int id, int level) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List watchedVideosByFriends(List> watchedVideos, int[][] friends, int id, int level) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def watchedVideosByFriends(self, watchedVideos, friends, id, level):\n \"\"\"\n :type watchedVideos: List[List[str]]\n :type friends: List[List[int]]\n :type id: int\n :type level: int\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def watchedVideosByFriends(self, watchedVideos: List[List[str]], friends: List[List[int]], id: int, level: int) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** watchedVideosByFriends(char *** watchedVideos, int watchedVideosSize, int* watchedVideosColSize, int** friends, int friendsSize, int* friendsColSize, int id, int level, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList WatchedVideosByFriends(IList> watchedVideos, int[][] friends, int id, int level) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[][]} watchedVideos\n * @param {number[][]} friends\n * @param {number} id\n * @param {number} level\n * @return {string[]}\n */\nvar watchedVideosByFriends = function(watchedVideos, friends, id, level) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[][]} watched_videos\n# @param {Integer[][]} friends\n# @param {Integer} id\n# @param {Integer} level\n# @return {String[]}\ndef watched_videos_by_friends(watched_videos, friends, id, level)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func watchedVideosByFriends(_ watchedVideos: [[String]], _ friends: [[Int]], _ id: Int, _ level: Int) -> [String] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func watchedVideosByFriends(watchedVideos [][]string, friends [][]int, id int, level int) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def watchedVideosByFriends(watchedVideos: List[List[String]], friends: Array[Array[Int]], id: Int, level: Int): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun watchedVideosByFriends(watchedVideos: List>, friends: Array, id: Int, level: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn watched_videos_by_friends(watched_videos: Vec>, friends: Vec>, id: i32, level: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $watchedVideos\n * @param Integer[][] $friends\n * @param Integer $id\n * @param Integer $level\n * @return String[]\n */\n function watchedVideosByFriends($watchedVideos, $friends, $id, $level) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function watchedVideosByFriends(watchedVideos: string[][], friends: number[][], id: number, level: number): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (watched-videos-by-friends watchedVideos friends id level)\n (-> (listof (listof string?)) (listof (listof exact-integer?)) exact-integer? exact-integer? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1311](https://leetcode-cn.com/problems/get-watched-videos-by-your-friends)", "[\u83b7\u53d6\u4f60\u597d\u53cb\u5df2\u89c2\u770b\u7684\u89c6\u9891](/solution/1300-1399/1311.Get%20Watched%20Videos%20by%20Your%20Friends/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u54c8\u5e0c\u8868`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1311](https://leetcode.com/problems/get-watched-videos-by-your-friends)", "[Get Watched Videos by Your Friends](/solution/1300-1399/1311.Get%20Watched%20Videos%20by%20Your%20Friends/README_EN.md)", "`Breadth-first Search`,`Hash Table`,`String`", "Medium", ""]}, {"question_id": "1435", "frontend_question_id": "1310", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/xor-queries-of-a-subarray", "url_en": "https://leetcode.com/problems/xor-queries-of-a-subarray", "relative_path_cn": "/solution/1300-1399/1310.XOR%20Queries%20of%20a%20Subarray/README.md", "relative_path_en": "/solution/1300-1399/1310.XOR%20Queries%20of%20a%20Subarray/README_EN.md", "title_cn": "\u5b50\u6570\u7ec4\u5f02\u6216\u67e5\u8be2", "title_en": "XOR Queries of a Subarray", "question_title_slug": "xor-queries-of-a-subarray", "content_en": "Given the array arr of positive integers and the array queries where queries[i] = [Li, Ri], for each query i compute the XOR of elements from Li to Ri (that is, arr[Li] xor arr[Li+1] xor ... xor arr[Ri] ). Return an array containing the result for the given queries.\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: arr = [1,3,4,8], queries = [[0,1],[1,2],[0,3],[3,3]]\r\nOutput: [2,7,14,8] \r\nExplanation: \r\nThe binary representation of the elements in the array are:\r\n1 = 0001 \r\n3 = 0011 \r\n4 = 0100 \r\n8 = 1000 \r\nThe XOR values for queries are:\r\n[0,1] = 1 xor 3 = 2 \r\n[1,2] = 3 xor 4 = 7 \r\n[0,3] = 1 xor 3 xor 4 xor 8 = 14 \r\n[3,3] = 8\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: arr = [4,8,2,10], queries = [[2,3],[1,3],[0,0],[0,3]]\r\nOutput: [8,0,4,4]\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= arr.length <= 3 * 10^4
    • \r\n\t
    • 1 <= arr[i] <= 10^9
    • \r\n\t
    • 1 <= queries.length <= 3 * 10^4
    • \r\n\t
    • queries[i].length == 2
    • \r\n\t
    • 0 <= queries[i][0] <= queries[i][1] < arr.length
    • \r\n
    ", "content_cn": "

    \u6709\u4e00\u4e2a\u6b63\u6574\u6570\u6570\u7ec4\u00a0arr\uff0c\u73b0\u7ed9\u4f60\u4e00\u4e2a\u5bf9\u5e94\u7684\u67e5\u8be2\u6570\u7ec4\u00a0queries\uff0c\u5176\u4e2d\u00a0queries[i] = [Li,\u00a0Ri]\u3002

    \n\n

    \u5bf9\u4e8e\u6bcf\u4e2a\u67e5\u8be2\u00a0i\uff0c\u8bf7\u4f60\u8ba1\u7b97\u4ece\u00a0Li\u00a0\u5230\u00a0Ri\u00a0\u7684\u00a0XOR\u00a0\u503c\uff08\u5373\u00a0arr[Li] xor arr[Li+1] xor ... xor arr[Ri]\uff09\u4f5c\u4e3a\u672c\u6b21\u67e5\u8be2\u7684\u7ed3\u679c\u3002

    \n\n

    \u5e76\u8fd4\u56de\u4e00\u4e2a\u5305\u542b\u7ed9\u5b9a\u67e5\u8be2\u00a0queries\u00a0\u6240\u6709\u7ed3\u679c\u7684\u6570\u7ec4\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [1,3,4,8], queries = [[0,1],[1,2],[0,3],[3,3]]\n\u8f93\u51fa\uff1a[2,7,14,8] \n\u89e3\u91ca\uff1a\n\u6570\u7ec4\u4e2d\u5143\u7d20\u7684\u4e8c\u8fdb\u5236\u8868\u793a\u5f62\u5f0f\u662f\uff1a\n1 = 0001 \n3 = 0011 \n4 = 0100 \n8 = 1000 \n\u67e5\u8be2\u7684 XOR \u503c\u4e3a\uff1a\n[0,1] = 1 xor 3 = 2 \n[1,2] = 3 xor 4 = 7 \n[0,3] = 1 xor 3 xor 4 xor 8 = 14 \n[3,3] = 8\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [4,8,2,10], queries = [[2,3],[1,3],[0,0],[0,3]]\n\u8f93\u51fa\uff1a[8,0,4,4]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= arr.length <= 3 *\u00a010^4
    • \n\t
    • 1 <= arr[i] <= 10^9
    • \n\t
    • 1 <= queries.length <= 3 * 10^4
    • \n\t
    • queries[i].length == 2
    • \n\t
    • 0 <= queries[i][0] <= queries[i][1] < arr.length
    • \n
    \n", "tags_en": ["Bit Manipulation"], "tags_cn": ["\u4f4d\u8fd0\u7b97"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector xorQueries(vector& arr, vector>& queries) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] xorQueries(int[] arr, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def xorQueries(self, arr, queries):\n \"\"\"\n :type arr: List[int]\n :type queries: List[List[int]]\n :rtype: List[int]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* xorQueries(int* arr, int arrSize, int** queries, int queriesSize, int* queriesColSize, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] XorQueries(int[] arr, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @param {number[][]} queries\n * @return {number[]}\n */\nvar xorQueries = function(arr, queries) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @param {Integer[][]} queries\n# @return {Integer[]}\ndef xor_queries(arr, queries)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func xorQueries(_ arr: [Int], _ queries: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func xorQueries(arr []int, queries [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def xorQueries(arr: Array[Int], queries: Array[Array[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun xorQueries(arr: IntArray, queries: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn xor_queries(arr: Vec, queries: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @param Integer[][] $queries\n * @return Integer[]\n */\n function xorQueries($arr, $queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function xorQueries(arr: number[], queries: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (xor-queries arr queries)\n (-> (listof exact-integer?) (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1310](https://leetcode-cn.com/problems/xor-queries-of-a-subarray)", "[\u5b50\u6570\u7ec4\u5f02\u6216\u67e5\u8be2](/solution/1300-1399/1310.XOR%20Queries%20of%20a%20Subarray/README.md)", "`\u4f4d\u8fd0\u7b97`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1310](https://leetcode.com/problems/xor-queries-of-a-subarray)", "[XOR Queries of a Subarray](/solution/1300-1399/1310.XOR%20Queries%20of%20a%20Subarray/README_EN.md)", "`Bit Manipulation`", "Medium", ""]}, {"question_id": "1434", "frontend_question_id": "1309", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/decrypt-string-from-alphabet-to-integer-mapping", "url_en": "https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping", "relative_path_cn": "/solution/1300-1399/1309.Decrypt%20String%20from%20Alphabet%20to%20Integer%20Mapping/README.md", "relative_path_en": "/solution/1300-1399/1309.Decrypt%20String%20from%20Alphabet%20to%20Integer%20Mapping/README_EN.md", "title_cn": "\u89e3\u7801\u5b57\u6bcd\u5230\u6574\u6570\u6620\u5c04", "title_en": "Decrypt String from Alphabet to Integer Mapping", "question_title_slug": "decrypt-string-from-alphabet-to-integer-mapping", "content_en": "

    Given a string s formed by digits ('0' - '9') and '#' . We want to map s to English lowercase characters as follows:

    \n\n
      \n\t
    • Characters ('a' to 'i') are represented by ('1' to '9') respectively.
    • \n\t
    • Characters ('j' to 'z') are represented by ('10#' to '26#') respectively. 
    • \n
    \n\n

    Return the string formed after mapping.

    \n\n

    It's guaranteed that a unique mapping will always exist.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "10#11#12"\nOutput: "jkab"\nExplanation: "j" -> "10#" , "k" -> "11#" , "a" -> "1" , "b" -> "2".\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "1326#"\nOutput: "acz"\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "25#"\nOutput: "y"\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "12345678910#11#12#13#14#15#16#17#18#19#20#21#22#23#24#25#26#"\nOutput: "abcdefghijklmnopqrstuvwxyz"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 1000
    • \n\t
    • s[i] only contains digits letters ('0'-'9') and '#' letter.
    • \n\t
    • s will be valid string such that mapping is always possible.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s\uff0c\u5b83\u7531\u6570\u5b57\uff08'0' - '9'\uff09\u548c '#' \u7ec4\u6210\u3002\u6211\u4eec\u5e0c\u671b\u6309\u4e0b\u8ff0\u89c4\u5219\u5c06 s \u6620\u5c04\u4e3a\u4e00\u4e9b\u5c0f\u5199\u82f1\u6587\u5b57\u7b26\uff1a

    \n\n
      \n\t
    • \u5b57\u7b26\uff08'a' - 'i'\uff09\u5206\u522b\u7528\uff08'1''9'\uff09\u8868\u793a\u3002
    • \n\t
    • \u5b57\u7b26\uff08'j' - 'z'\uff09\u5206\u522b\u7528\uff08'10#' - '26#'\uff09\u8868\u793a\u3002 
    • \n
    \n\n

    \u8fd4\u56de\u6620\u5c04\u4e4b\u540e\u5f62\u6210\u7684\u65b0\u5b57\u7b26\u4e32\u3002

    \n\n

    \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u6620\u5c04\u59cb\u7ec8\u552f\u4e00\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1as = "10#11#12"\n\u8f93\u51fa\uff1a"jkab"\n\u89e3\u91ca\uff1a"j" -> "10#" , "k" -> "11#" , "a" -> "1" , "b" -> "2".\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1as = "1326#"\n\u8f93\u51fa\uff1a"acz"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1as = "25#"\n\u8f93\u51fa\uff1a"y"\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1as = "12345678910#11#12#13#14#15#16#17#18#19#20#21#22#23#24#25#26#"\n\u8f93\u51fa\uff1a"abcdefghijklmnopqrstuvwxyz"\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 1000
    • \n\t
    • s[i] \u53ea\u5305\u542b\u6570\u5b57\uff08'0'-'9'\uff09\u548c '#' \u5b57\u7b26\u3002
    • \n\t
    • s \u662f\u6620\u5c04\u59cb\u7ec8\u5b58\u5728\u7684\u6709\u6548\u5b57\u7b26\u4e32\u3002
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string freqAlphabets(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String freqAlphabets(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def freqAlphabets(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def freqAlphabets(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * freqAlphabets(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string FreqAlphabets(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar freqAlphabets = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef freq_alphabets(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func freqAlphabets(_ s: String) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func freqAlphabets(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def freqAlphabets(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun freqAlphabets(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn freq_alphabets(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function freqAlphabets($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function freqAlphabets(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (freq-alphabets s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1309](https://leetcode-cn.com/problems/decrypt-string-from-alphabet-to-integer-mapping)", "[\u89e3\u7801\u5b57\u6bcd\u5230\u6574\u6570\u6620\u5c04](/solution/1300-1399/1309.Decrypt%20String%20from%20Alphabet%20to%20Integer%20Mapping/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1309](https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping)", "[Decrypt String from Alphabet to Integer Mapping](/solution/1300-1399/1309.Decrypt%20String%20from%20Alphabet%20to%20Integer%20Mapping/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1432", "frontend_question_id": "1430", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/check-if-a-string-is-a-valid-sequence-from-root-to-leaves-path-in-a-binary-tree", "url_en": "https://leetcode.com/problems/check-if-a-string-is-a-valid-sequence-from-root-to-leaves-path-in-a-binary-tree", "relative_path_cn": "/solution/1400-1499/1430.Check%20If%20a%20String%20Is%20a%20Valid%20Sequence%20from%20Root%20to%20Leaves%20Path%20in%20a%20Binary%20Tree/README.md", "relative_path_en": "/solution/1400-1499/1430.Check%20If%20a%20String%20Is%20a%20Valid%20Sequence%20from%20Root%20to%20Leaves%20Path%20in%20a%20Binary%20Tree/README_EN.md", "title_cn": "\u5224\u65ad\u7ed9\u5b9a\u7684\u5e8f\u5217\u662f\u5426\u662f\u4e8c\u53c9\u6811\u4ece\u6839\u5230\u53f6\u7684\u8def\u5f84", "title_en": "Check If a String Is a Valid Sequence from Root to Leaves Path in a Binary Tree", "question_title_slug": "check-if-a-string-is-a-valid-sequence-from-root-to-leaves-path-in-a-binary-tree", "content_en": "

    Given a binary tree where each path going from the root to any leaf form a valid sequence, check if a given string is a valid sequence in such binary tree. 

    \n\n

    We get the given string from the concatenation of an array of integers arr and the concatenation of all values of the nodes along a path results in a sequence in the given binary tree.

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: root = [0,1,0,0,1,0,null,null,1,0,0], arr = [0,1,0,1]\nOutput: true\nExplanation: \nThe path 0 -> 1 -> 0 -> 1 is a valid sequence (green color in the figure). \nOther valid sequences are: \n0 -> 1 -> 1 -> 0 \n0 -> 0 -> 0\n
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: root = [0,1,0,0,1,0,null,null,1,0,0], arr = [0,0,1]\nOutput: false \nExplanation: The path 0 -> 0 -> 1 does not exist, therefore it is not even a sequence.\n
    \n\n

    Example 3:

    \n\n

    \"\"

    \n\n
    \nInput: root = [0,1,0,0,1,0,null,null,1,0,0], arr = [0,1,1]\nOutput: false\nExplanation: The path 0 -> 1 -> 1 is a sequence, but it is not a valid sequence.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= arr.length <= 5000
    • \n\t
    • 0 <= arr[i] <= 9
    • \n\t
    • Each node's value is between [0 - 9].
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811\uff0c\u6211\u4eec\u79f0\u4ece\u6839\u8282\u70b9\u5230\u4efb\u610f\u53f6\u8282\u70b9\u7684\u4efb\u610f\u8def\u5f84\u4e2d\u7684\u8282\u70b9\u503c\u6240\u6784\u6210\u7684\u5e8f\u5217\u4e3a\u8be5\u4e8c\u53c9\u6811\u7684\u4e00\u4e2a “\u6709\u6548\u5e8f\u5217” \u3002\u68c0\u67e5\u4e00\u4e2a\u7ed9\u5b9a\u7684\u5e8f\u5217\u662f\u5426\u662f\u7ed9\u5b9a\u4e8c\u53c9\u6811\u7684\u4e00\u4e2a “\u6709\u6548\u5e8f\u5217” \u3002

    \n\n

    \u6211\u4eec\u4ee5\u6574\u6570\u6570\u7ec4 arr \u7684\u5f62\u5f0f\u7ed9\u51fa\u8fd9\u4e2a\u5e8f\u5217\u3002\u4ece\u6839\u8282\u70b9\u5230\u4efb\u610f\u53f6\u8282\u70b9\u7684\u4efb\u610f\u8def\u5f84\u4e2d\u7684\u8282\u70b9\u503c\u6240\u6784\u6210\u7684\u5e8f\u5217\u90fd\u662f\u8fd9\u4e2a\u4e8c\u53c9\u6811\u7684 “\u6709\u6548\u5e8f\u5217” \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aroot = [0,1,0,0,1,0,null,null,1,0,0], arr = [0,1,0,1]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\n\u8def\u5f84 0 -> 1 -> 0 -> 1 \u662f\u4e00\u4e2a“\u6709\u6548\u5e8f\u5217”\uff08\u56fe\u4e2d\u7684\u7eff\u8272\u8282\u70b9\uff09\u3002\n\u5176\u4ed6\u7684“\u6709\u6548\u5e8f\u5217”\u662f\uff1a\n0 -> 1 -> 1 -> 0 \n0 -> 0 -> 0\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aroot = [0,1,0,0,1,0,null,null,1,0,0], arr = [0,0,1]\n\u8f93\u51fa\uff1afalse \n\u89e3\u91ca\uff1a\u8def\u5f84 0 -> 0 -> 1 \u4e0d\u5b58\u5728\uff0c\u6240\u4ee5\u8fd9\u4e0d\u662f\u4e00\u4e2a“\u5e8f\u5217”\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aroot = [0,1,0,0,1,0,null,null,1,0,0], arr = [0,1,1]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u8def\u5f84 0 -> 1 -> 1 \u662f\u4e00\u4e2a\u5e8f\u5217\uff0c\u4f46\u4e0d\u662f\u4e00\u4e2a“\u6709\u6548\u5e8f\u5217”\uff08\u8bd1\u8005\u6ce8\uff1a\u56e0\u4e3a\u5e8f\u5217\u7684\u7ec8\u70b9\u4e0d\u662f\u53f6\u8282\u70b9\uff09\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= arr.length <= 5000
    • \n\t
    • 0 <= arr[i] <= 9
    • \n\t
    • \u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u7684\u53d6\u503c\u8303\u56f4\u662f [0 - 9]
    • \n
    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n bool isValidSequence(TreeNode* root, vector& arr) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public boolean isValidSequence(TreeNode root, int[] arr) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def isValidSequence(self, root, arr):\n \"\"\"\n :type root: TreeNode\n :type arr: List[int]\n :rtype: bool\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def isValidSequence(self, root: TreeNode, arr: List[int]) -> bool:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nbool isValidSequence(struct TreeNode* root, int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public bool IsValidSequence(TreeNode root, int[] arr) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number[]} arr\n * @return {boolean}\n */\nvar isValidSequence = function(root, arr) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @param {Integer[]} arr\n# @return {Boolean}\ndef is_valid_sequence(root, arr)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func isValidSequence(_ root: TreeNode?, _ arr: [Int]) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc isValidSequence(root *TreeNode, arr []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def isValidSequence(root: TreeNode, arr: Array[Int]): Boolean = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun isValidSequence(root: TreeNode?, arr: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn is_valid_sequence(root: Option>>, arr: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param Integer[] $arr\n * @return Boolean\n */\n function isValidSequence($root, $arr) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction isValidSequence(root: TreeNode | null, arr: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (is-valid-sequence root arr)\n (-> (or/c tree-node? #f) (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1430](https://leetcode-cn.com/problems/check-if-a-string-is-a-valid-sequence-from-root-to-leaves-path-in-a-binary-tree)", "[\u5224\u65ad\u7ed9\u5b9a\u7684\u5e8f\u5217\u662f\u5426\u662f\u4e8c\u53c9\u6811\u4ece\u6839\u5230\u53f6\u7684\u8def\u5f84](/solution/1400-1499/1430.Check%20If%20a%20String%20Is%20a%20Valid%20Sequence%20from%20Root%20to%20Leaves%20Path%20in%20a%20Binary%20Tree/README.md)", "`\u6811`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1430](https://leetcode.com/problems/check-if-a-string-is-a-valid-sequence-from-root-to-leaves-path-in-a-binary-tree)", "[Check If a String Is a Valid Sequence from Root to Leaves Path in a Binary Tree](/solution/1400-1499/1430.Check%20If%20a%20String%20Is%20a%20Valid%20Sequence%20from%20Root%20to%20Leaves%20Path%20in%20a%20Binary%20Tree/README_EN.md)", "`Tree`", "Medium", "\ud83d\udd12"]}, {"question_id": "1429", "frontend_question_id": "1307", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/verbal-arithmetic-puzzle", "url_en": "https://leetcode.com/problems/verbal-arithmetic-puzzle", "relative_path_cn": "/solution/1300-1399/1307.Verbal%20Arithmetic%20Puzzle/README.md", "relative_path_en": "/solution/1300-1399/1307.Verbal%20Arithmetic%20Puzzle/README_EN.md", "title_cn": "\u53e3\u7b97\u96be\u9898", "title_en": "Verbal Arithmetic Puzzle", "question_title_slug": "verbal-arithmetic-puzzle", "content_en": "

    Given an equation, represented by words on left side and the result on right side.

    \n\n

    You need to check if the equation is solvable under the following rules:

    \n\n
      \n\t
    • Each character is decoded as one digit (0 - 9).
    • \n\t
    • Every pair of different characters they must map to different digits.
    • \n\t
    • Each words[i] and result are decoded as one number without leading zeros.
    • \n\t
    • Sum of numbers on left side (words) will equal to the number on right side (result). 
    • \n
    \n\n

    Return True if the equation is solvable otherwise return False.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: words = ["SEND","MORE"], result = "MONEY"\nOutput: true\nExplanation: Map 'S'-> 9, 'E'->5, 'N'->6, 'D'->7, 'M'->1, 'O'->0, 'R'->8, 'Y'->'2'\nSuch that: "SEND" + "MORE" = "MONEY" ,  9567 + 1085 = 10652
    \n\n

    Example 2:

    \n\n
    \nInput: words = ["SIX","SEVEN","SEVEN"], result = "TWENTY"\nOutput: true\nExplanation: Map 'S'-> 6, 'I'->5, 'X'->0, 'E'->8, 'V'->7, 'N'->2, 'T'->1, 'W'->'3', 'Y'->4\nSuch that: "SIX" + "SEVEN" + "SEVEN" = "TWENTY" ,  650 + 68782 + 68782 = 138214
    \n\n

    Example 3:

    \n\n
    \nInput: words = ["THIS","IS","TOO"], result = "FUNNY"\nOutput: true\n
    \n\n

    Example 4:

    \n\n
    \nInput: words = ["LEET","CODE"], result = "POINT"\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= words.length <= 5
    • \n\t
    • 1 <= words[i].length, result.length <= 7
    • \n\t
    • words[i], result contain only uppercase English letters.
    • \n\t
    • The number of different characters used in the expression is at most 10.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u65b9\u7a0b\uff0c\u5de6\u8fb9\u7528 words \u8868\u793a\uff0c\u53f3\u8fb9\u7528 result \u8868\u793a\u3002

    \n\n

    \u4f60\u9700\u8981\u6839\u636e\u4ee5\u4e0b\u89c4\u5219\u68c0\u67e5\u65b9\u7a0b\u662f\u5426\u53ef\u89e3\uff1a

    \n\n
      \n\t
    • \u6bcf\u4e2a\u5b57\u7b26\u90fd\u4f1a\u88ab\u89e3\u7801\u6210\u4e00\u4f4d\u6570\u5b57\uff080 - 9\uff09\u3002
    • \n\t
    • \u6bcf\u5bf9\u4e0d\u540c\u7684\u5b57\u7b26\u5fc5\u987b\u6620\u5c04\u5230\u4e0d\u540c\u7684\u6570\u5b57\u3002
    • \n\t
    • \u6bcf\u4e2a words[i] \u548c result \u90fd\u4f1a\u88ab\u89e3\u7801\u6210\u4e00\u4e2a\u6ca1\u6709\u524d\u5bfc\u96f6\u7684\u6570\u5b57\u3002
    • \n\t
    • \u5de6\u4fa7\u6570\u5b57\u4e4b\u548c\uff08words\uff09\u7b49\u4e8e\u53f3\u4fa7\u6570\u5b57\uff08result\uff09\u3002 
    • \n
    \n\n

    \u5982\u679c\u65b9\u7a0b\u53ef\u89e3\uff0c\u8fd4\u56de True\uff0c\u5426\u5219\u8fd4\u56de False\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1awords = ["SEND","MORE"], result = "MONEY"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u6620\u5c04 'S'-> 9, 'E'->5, 'N'->6, 'D'->7, 'M'->1, 'O'->0, 'R'->8, 'Y'->'2'\n\u6240\u4ee5 "SEND" + "MORE" = "MONEY" ,  9567 + 1085 = 10652
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1awords = ["SIX","SEVEN","SEVEN"], result = "TWENTY"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u6620\u5c04 'S'-> 6, 'I'->5, 'X'->0, 'E'->8, 'V'->7, 'N'->2, 'T'->1, 'W'->'3', 'Y'->4\n\u6240\u4ee5 "SIX" + "SEVEN" + "SEVEN" = "TWENTY" ,  650 + 68782 + 68782 = 138214
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1awords = ["THIS","IS","TOO"], result = "FUNNY"\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1awords = ["LEET","CODE"], result = "POINT"\n\u8f93\u51fa\uff1afalse\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= words.length <= 5
    • \n\t
    • 1 <= words[i].length, results.length <= 7
    • \n\t
    • words[i], result \u53ea\u542b\u6709\u5927\u5199\u82f1\u6587\u5b57\u6bcd
    • \n\t
    • \u8868\u8fbe\u5f0f\u4e2d\u4f7f\u7528\u7684\u4e0d\u540c\u5b57\u7b26\u6570\u6700\u5927\u4e3a 10
    • \n
    \n", "tags_en": ["Math", "Backtracking"], "tags_cn": ["\u6570\u5b66", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isSolvable(vector& words, string result) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isSolvable(String[] words, String result) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isSolvable(self, words, result):\n \"\"\"\n :type words: List[str]\n :type result: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isSolvable(self, words: List[str], result: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isSolvable(char ** words, int wordsSize, char * result){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsSolvable(string[] words, string result) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @param {string} result\n * @return {boolean}\n */\nvar isSolvable = function(words, result) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @param {String} result\n# @return {Boolean}\ndef is_solvable(words, result)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isSolvable(_ words: [String], _ result: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isSolvable(words []string, result string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isSolvable(words: Array[String], result: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isSolvable(words: Array, result: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_solvable(words: Vec, result: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @param String $result\n * @return Boolean\n */\n function isSolvable($words, $result) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isSolvable(words: string[], result: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-solvable words result)\n (-> (listof string?) string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1307](https://leetcode-cn.com/problems/verbal-arithmetic-puzzle)", "[\u53e3\u7b97\u96be\u9898](/solution/1300-1399/1307.Verbal%20Arithmetic%20Puzzle/README.md)", "`\u6570\u5b66`,`\u56de\u6eaf\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[1307](https://leetcode.com/problems/verbal-arithmetic-puzzle)", "[Verbal Arithmetic Puzzle](/solution/1300-1399/1307.Verbal%20Arithmetic%20Puzzle/README_EN.md)", "`Math`,`Backtracking`", "Hard", ""]}, {"question_id": "1428", "frontend_question_id": "1306", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/jump-game-iii", "url_en": "https://leetcode.com/problems/jump-game-iii", "relative_path_cn": "/solution/1300-1399/1306.Jump%20Game%20III/README.md", "relative_path_en": "/solution/1300-1399/1306.Jump%20Game%20III/README_EN.md", "title_cn": "\u8df3\u8dc3\u6e38\u620f III", "title_en": "Jump Game III", "question_title_slug": "jump-game-iii", "content_en": "

    Given an array of non-negative integers arr, you are initially positioned at start index of the array. When you are at index i, you can jump to i + arr[i] or i - arr[i], check if you can reach to any index with value 0.

    \n\n

    Notice that you can not jump outside of the array at any time.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr = [4,2,3,0,3,1,2], start = 5\nOutput: true\nExplanation: \nAll possible ways to reach at index 3 with value 0 are: \nindex 5 -> index 4 -> index 1 -> index 3 \nindex 5 -> index 6 -> index 4 -> index 1 -> index 3 \n
    \n\n

    Example 2:

    \n\n
    \nInput: arr = [4,2,3,0,3,1,2], start = 0\nOutput: true \nExplanation: \nOne possible way to reach at index 3 with value 0 is: \nindex 0 -> index 4 -> index 1 -> index 3\n
    \n\n

    Example 3:

    \n\n
    \nInput: arr = [3,0,2,1,2], start = 2\nOutput: false\nExplanation: There is no way to reach at index 1 with value 0.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= arr.length <= 5 * 104
    • \n\t
    • 0 <= arr[i] < arr.length
    • \n\t
    • 0 <= start < arr.length
    • \n
    \n", "content_cn": "

    \u8fd9\u91cc\u6709\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\u6570\u7ec4 arr\uff0c\u4f60\u6700\u5f00\u59cb\u4f4d\u4e8e\u8be5\u6570\u7ec4\u7684\u8d77\u59cb\u4e0b\u6807 start \u5904\u3002\u5f53\u4f60\u4f4d\u4e8e\u4e0b\u6807 i \u5904\u65f6\uff0c\u4f60\u53ef\u4ee5\u8df3\u5230 i + arr[i] \u6216\u8005 i - arr[i]\u3002

    \n\n

    \u8bf7\u4f60\u5224\u65ad\u81ea\u5df1\u662f\u5426\u80fd\u591f\u8df3\u5230\u5bf9\u5e94\u5143\u7d20\u503c\u4e3a 0 \u7684 \u4efb\u4e00 \u4e0b\u6807\u5904\u3002

    \n\n

    \u6ce8\u610f\uff0c\u4e0d\u7ba1\u662f\u4ec0\u4e48\u60c5\u51b5\u4e0b\uff0c\u4f60\u90fd\u65e0\u6cd5\u8df3\u5230\u6570\u7ec4\u4e4b\u5916\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [4,2,3,0,3,1,2], start = 5\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\n\u5230\u8fbe\u503c\u4e3a 0 \u7684\u4e0b\u6807 3 \u6709\u4ee5\u4e0b\u53ef\u80fd\u65b9\u6848\uff1a \n\u4e0b\u6807 5 -> \u4e0b\u6807 4 -> \u4e0b\u6807 1 -> \u4e0b\u6807 3 \n\u4e0b\u6807 5 -> \u4e0b\u6807 6 -> \u4e0b\u6807 4 -> \u4e0b\u6807 1 -> \u4e0b\u6807 3 \n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [4,2,3,0,3,1,2], start = 0\n\u8f93\u51fa\uff1atrue \n\u89e3\u91ca\uff1a\n\u5230\u8fbe\u503c\u4e3a 0 \u7684\u4e0b\u6807 3 \u6709\u4ee5\u4e0b\u53ef\u80fd\u65b9\u6848\uff1a \n\u4e0b\u6807 0 -> \u4e0b\u6807 4 -> \u4e0b\u6807 1 -> \u4e0b\u6807 3\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [3,0,2,1,2], start = 2\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u65e0\u6cd5\u5230\u8fbe\u503c\u4e3a 0 \u7684\u4e0b\u6807 1 \u5904\u3002 \n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= arr.length <= 5 * 10^4
    • \n\t
    • 0 <= arr[i] < arr.length
    • \n\t
    • 0 <= start < arr.length
    • \n
    \n", "tags_en": ["Depth-first Search", "Breadth-first Search", "Recursion"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u9012\u5f52"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canReach(vector& arr, int start) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canReach(int[] arr, int start) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canReach(self, arr, start):\n \"\"\"\n :type arr: List[int]\n :type start: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canReach(self, arr: List[int], start: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canReach(int* arr, int arrSize, int start){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanReach(int[] arr, int start) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @param {number} start\n * @return {boolean}\n */\nvar canReach = function(arr, start) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @param {Integer} start\n# @return {Boolean}\ndef can_reach(arr, start)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canReach(_ arr: [Int], _ start: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canReach(arr []int, start int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canReach(arr: Array[Int], start: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canReach(arr: IntArray, start: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_reach(arr: Vec, start: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @param Integer $start\n * @return Boolean\n */\n function canReach($arr, $start) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canReach(arr: number[], start: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-reach arr start)\n (-> (listof exact-integer?) exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1306](https://leetcode-cn.com/problems/jump-game-iii)", "[\u8df3\u8dc3\u6e38\u620f III](/solution/1300-1399/1306.Jump%20Game%20III/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u9012\u5f52`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1306](https://leetcode.com/problems/jump-game-iii)", "[Jump Game III](/solution/1300-1399/1306.Jump%20Game%20III/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`,`Recursion`", "Medium", ""]}, {"question_id": "1427", "frontend_question_id": "1305", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/all-elements-in-two-binary-search-trees", "url_en": "https://leetcode.com/problems/all-elements-in-two-binary-search-trees", "relative_path_cn": "/solution/1300-1399/1305.All%20Elements%20in%20Two%20Binary%20Search%20Trees/README.md", "relative_path_en": "/solution/1300-1399/1305.All%20Elements%20in%20Two%20Binary%20Search%20Trees/README_EN.md", "title_cn": "\u4e24\u68f5\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u7684\u6240\u6709\u5143\u7d20", "title_en": "All Elements in Two Binary Search Trees", "question_title_slug": "all-elements-in-two-binary-search-trees", "content_en": "

    Given two binary search trees root1 and root2.

    \n\n

    Return a list containing all the integers from both trees sorted in ascending order.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root1 = [2,1,4], root2 = [1,0,3]\nOutput: [0,1,1,2,3,4]\n
    \n\n

    Example 2:

    \n\n
    \nInput: root1 = [0,-10,10], root2 = [5,1,7,0,2]\nOutput: [-10,0,0,1,2,5,7,10]\n
    \n\n

    Example 3:

    \n\n
    \nInput: root1 = [], root2 = [5,1,7,0,2]\nOutput: [0,1,2,5,7]\n
    \n\n

    Example 4:

    \n\n
    \nInput: root1 = [0,-10,10], root2 = []\nOutput: [-10,0,10]\n
    \n\n

    Example 5:

    \n\"\"\n
    \nInput: root1 = [1,null,8], root2 = [8,1]\nOutput: [1,1,8,8]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • Each tree has at most 5000 nodes.
    • \n\t
    • Each node's value is between [-10^5, 10^5].
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60 root1 \u548c root2 \u8fd9\u4e24\u68f5\u4e8c\u53c9\u641c\u7d22\u6811\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u4e00\u4e2a\u5217\u8868\uff0c\u5176\u4e2d\u5305\u542b \u4e24\u68f5\u6811 \u4e2d\u7684\u6240\u6709\u6574\u6570\u5e76\u6309 \u5347\u5e8f \u6392\u5e8f\u3002.

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1aroot1 = [2,1,4], root2 = [1,0,3]\n\u8f93\u51fa\uff1a[0,1,1,2,3,4]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aroot1 = [0,-10,10], root2 = [5,1,7,0,2]\n\u8f93\u51fa\uff1a[-10,0,0,1,2,5,7,10]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aroot1 = [], root2 = [5,1,7,0,2]\n\u8f93\u51fa\uff1a[0,1,2,5,7]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1aroot1 = [0,-10,10], root2 = []\n\u8f93\u51fa\uff1a[-10,0,10]\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1aroot1 = [1,null,8], root2 = [8,1]\n\u8f93\u51fa\uff1a[1,1,8,8]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6bcf\u68f5\u6811\u6700\u591a\u6709 5000 \u4e2a\u8282\u70b9\u3002
    • \n\t
    • \u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u5728 [-10^5, 10^5] \u4e4b\u95f4\u3002
    • \n
    \n", "tags_en": ["Sort", "Tree"], "tags_cn": ["\u6392\u5e8f", "\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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 */\nclass Solution {\npublic:\n vector getAllElements(TreeNode* root1, TreeNode* root2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode(int x) { val = x; }\n * }\n */\nclass Solution {\n public List getAllElements(TreeNode root1, TreeNode root2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution(object):\n def getAllElements(self, root1, root2):\n \"\"\"\n :type root1: TreeNode\n :type root2: TreeNode\n :rtype: List[int]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution:\n def getAllElements(self, root1: TreeNode, root2: TreeNode) -> List[int]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* getAllElements(struct TreeNode* root1, struct TreeNode* root2, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int x) { val = x; }\n * }\n */\npublic class Solution {\n public IList GetAllElements(TreeNode root1, TreeNode root2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val) {\n * this.val = val;\n * this.left = this.right = null;\n * }\n */\n/**\n * @param {TreeNode} root1\n * @param {TreeNode} root2\n * @return {number[]}\n */\nvar getAllElements = function(root1, root2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val)\n# @val = val\n# @left, @right = nil, nil\n# end\n# end\n\n# @param {TreeNode} root1\n# @param {TreeNode} root2\n# @return {Integer[]}\ndef get_all_elements(root1, root2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.left = nil\n * self.right = nil\n * }\n * }\n */\nclass Solution {\n func getAllElements(_ root1: TreeNode?, _ root2: TreeNode?) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc getAllElements(root1 *TreeNode, root2 *TreeNode) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(var _value: Int) {\n * var value: Int = _value\n * var left: TreeNode = null\n * var right: TreeNode = null\n * }\n */\nobject Solution {\n def getAllElements(root1: TreeNode, root2: TreeNode): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun getAllElements(root1: TreeNode?, root2: TreeNode?): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n// \n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn get_all_elements(root1: Option>>, root2: Option>>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($value) { $this->val = $value; }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root1\n * @param TreeNode $root2\n * @return Integer[]\n */\n function getAllElements($root1, $root2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction getAllElements(root1: TreeNode | null, root2: TreeNode | null): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (get-all-elements root1 root2)\n (-> (or/c tree-node? #f) (or/c tree-node? #f) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1305](https://leetcode-cn.com/problems/all-elements-in-two-binary-search-trees)", "[\u4e24\u68f5\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u7684\u6240\u6709\u5143\u7d20](/solution/1300-1399/1305.All%20Elements%20in%20Two%20Binary%20Search%20Trees/README.md)", "`\u6392\u5e8f`,`\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1305](https://leetcode.com/problems/all-elements-in-two-binary-search-trees)", "[All Elements in Two Binary Search Trees](/solution/1300-1399/1305.All%20Elements%20in%20Two%20Binary%20Search%20Trees/README_EN.md)", "`Sort`,`Tree`", "Medium", ""]}, {"question_id": "1426", "frontend_question_id": "1304", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-n-unique-integers-sum-up-to-zero", "url_en": "https://leetcode.com/problems/find-n-unique-integers-sum-up-to-zero", "relative_path_cn": "/solution/1300-1399/1304.Find%20N%20Unique%20Integers%20Sum%20up%20to%20Zero/README.md", "relative_path_en": "/solution/1300-1399/1304.Find%20N%20Unique%20Integers%20Sum%20up%20to%20Zero/README_EN.md", "title_cn": "\u548c\u4e3a\u96f6\u7684N\u4e2a\u552f\u4e00\u6574\u6570", "title_en": "Find N Unique Integers Sum up to Zero", "question_title_slug": "find-n-unique-integers-sum-up-to-zero", "content_en": "

    Given an integer n, return any array containing n unique integers such that they add up to 0.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 5\nOutput: [-7,-1,1,3,4]\nExplanation: These arrays also are accepted [-5,-1,1,2,3] , [-3,-1,2,-2,4].\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 3\nOutput: [-1,0,1]\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 1\nOutput: [0]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n\uff0c\u8bf7\u4f60\u8fd4\u56de \u4efb\u610f \u4e00\u4e2a\u7531 n \u4e2a \u5404\u4e0d\u76f8\u540c \u7684\u6574\u6570\u7ec4\u6210\u7684\u6570\u7ec4\uff0c\u5e76\u4e14\u8fd9 n \u4e2a\u6570\u76f8\u52a0\u548c\u4e3a 0 \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1an = 5\n\u8f93\u51fa\uff1a[-7,-1,1,3,4]\n\u89e3\u91ca\uff1a\u8fd9\u4e9b\u6570\u7ec4\u4e5f\u662f\u6b63\u786e\u7684 [-5,-1,1,2,3]\uff0c[-3,-1,2,-2,4]\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1an = 3\n\u8f93\u51fa\uff1a[-1,0,1]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1a[0]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 1000
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector sumZero(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] sumZero(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def sumZero(self, n):\n \"\"\"\n :type n: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def sumZero(self, n: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* sumZero(int n, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] SumZero(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number[]}\n */\nvar sumZero = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer[]}\ndef sum_zero(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func sumZero(_ n: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func sumZero(n int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def sumZero(n: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun sumZero(n: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sum_zero(n: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer[]\n */\n function sumZero($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function sumZero(n: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (sum-zero n)\n (-> exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1304](https://leetcode-cn.com/problems/find-n-unique-integers-sum-up-to-zero)", "[\u548c\u4e3a\u96f6\u7684N\u4e2a\u552f\u4e00\u6574\u6570](/solution/1300-1399/1304.Find%20N%20Unique%20Integers%20Sum%20up%20to%20Zero/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1304](https://leetcode.com/problems/find-n-unique-integers-sum-up-to-zero)", "[Find N Unique Integers Sum up to Zero](/solution/1300-1399/1304.Find%20N%20Unique%20Integers%20Sum%20up%20to%20Zero/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1425", "frontend_question_id": "1294", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/weather-type-in-each-country", "url_en": "https://leetcode.com/problems/weather-type-in-each-country", "relative_path_cn": "/solution/1200-1299/1294.Weather%20Type%20in%20Each%20Country/README.md", "relative_path_en": "/solution/1200-1299/1294.Weather%20Type%20in%20Each%20Country/README_EN.md", "title_cn": "\u4e0d\u540c\u56fd\u5bb6\u7684\u5929\u6c14\u7c7b\u578b", "title_en": "Weather Type in Each Country", "question_title_slug": "weather-type-in-each-country", "content_en": "

    Table: Countries

    \r\n\r\n
    \r\n+---------------+---------+\r\n| Column Name   | Type    |\r\n+---------------+---------+\r\n| country_id    | int     |\r\n| country_name  | varchar |\r\n+---------------+---------+\r\ncountry_id is the primary key for this table.\r\nEach row of this table contains the ID and the name of one country.\r\n
    \r\n\r\n

     

    \r\n\r\n

    Table: Weather

    \r\n\r\n
    \r\n+---------------+---------+\r\n| Column Name   | Type    |\r\n+---------------+---------+\r\n| country_id    | int     |\r\n| weather_state | varchar |\r\n| day           | date    |\r\n+---------------+---------+\r\n(country_id, day) is the primary key for this table.\r\nEach row of this table indicates the weather state in a country for one day.\r\n
    \r\n\r\n

     

    \r\n\r\n

    Write an SQL query to find the type of weather in each country for November 2019.

    \r\n\r\n

    The type of weather is Cold if the average weather_state is less than or equal 15, Hot if the average weather_state is greater than or equal 25 and Warm otherwise.

    \r\n\r\n

    Return result table in any order.

    \r\n\r\n

    The query result format is in the following example:

    \r\n\r\n
    \r\nCountries table:\r\n+------------+--------------+\r\n| country_id | country_name |\r\n+------------+--------------+\r\n| 2          | USA          |\r\n| 3          | Australia    |\r\n| 7          | Peru         |\r\n| 5          | China        |\r\n| 8          | Morocco      |\r\n| 9          | Spain        |\r\n+------------+--------------+\r\nWeather table:\r\n+------------+---------------+------------+\r\n| country_id | weather_state | day        |\r\n+------------+---------------+------------+\r\n| 2          | 15            | 2019-11-01 |\r\n| 2          | 12            | 2019-10-28 |\r\n| 2          | 12            | 2019-10-27 |\r\n| 3          | -2            | 2019-11-10 |\r\n| 3          | 0             | 2019-11-11 |\r\n| 3          | 3             | 2019-11-12 |\r\n| 5          | 16            | 2019-11-07 |\r\n| 5          | 18            | 2019-11-09 |\r\n| 5          | 21            | 2019-11-23 |\r\n| 7          | 25            | 2019-11-28 |\r\n| 7          | 22            | 2019-12-01 |\r\n| 7          | 20            | 2019-12-02 |\r\n| 8          | 25            | 2019-11-05 |\r\n| 8          | 27            | 2019-11-15 |\r\n| 8          | 31            | 2019-11-25 |\r\n| 9          | 7             | 2019-10-23 |\r\n| 9          | 3             | 2019-12-23 |\r\n+------------+---------------+------------+\r\nResult table:\r\n+--------------+--------------+\r\n| country_name | weather_type |\r\n+--------------+--------------+\r\n| USA          | Cold         |\r\n| Austraila    | Cold         |\r\n| Peru         | Hot          |\r\n| China        | Warm         |\r\n| Morocco      | Hot          |\r\n+--------------+--------------+\r\nAverage weather_state in USA in November is (15) / 1 = 15 so weather type is Cold.\r\nAverage weather_state in Austraila in November is (-2 + 0 + 3) / 3 = 0.333 so weather type is Cold.\r\nAverage weather_state in Peru in November is (25) / 1 = 25 so weather type is Hot.\r\nAverage weather_state in China in November is (16 + 18 + 21) / 3 = 18.333 so weather type is Warm.\r\nAverage weather_state in Morocco in November is (25 + 27 + 31) / 3 = 27.667 so weather type is Hot.\r\nWe know nothing about average weather_state in Spain in November so we don't include it in the result table. \r\n
    ", "content_cn": "

    \u56fd\u5bb6\u8868\uff1aCountries

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| country_id    | int     |\n| country_name  | varchar |\n+---------------+---------+\ncountry_id \u662f\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\u3002\n\u8be5\u8868\u7684\u6bcf\u884c\u6709 country_id \u548c country_name \u4e24\u5217\u3002\n
    \n\n

     

    \n\n

    \u5929\u6c14\u8868\uff1aWeather

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| country_id    | int     |\n| weather_state | varchar |\n| day           | date    |\n+---------------+---------+\n(country_id, day) \u662f\u8be5\u8868\u7684\u590d\u5408\u4e3b\u952e\u3002\n\u8be5\u8868\u7684\u6bcf\u4e00\u884c\u8bb0\u5f55\u4e86\u67d0\u4e2a\u56fd\u5bb6\u67d0\u4e00\u5929\u7684\u5929\u6c14\u60c5\u51b5\u3002\n
    \n\n

     

    \n\n

    \u5199\u4e00\u6bb5 SQL \u6765\u627e\u5230\u8868\u4e2d\u6bcf\u4e2a\u56fd\u5bb6\u5728 2019 \u5e74 11 \u6708\u7684\u5929\u6c14\u7c7b\u578b\u3002

    \n\n

    \u5929\u6c14\u7c7b\u578b\u7684\u5b9a\u4e49\u5982\u4e0b\uff1a\u5f53 weather_state \u7684\u5e73\u5747\u503c\u5c0f\u4e8e\u6216\u7b49\u4e8e15\u8fd4\u56de Cold\uff0c\u5f53 weather_state \u7684\u5e73\u5747\u503c\u5927\u4e8e\u6216\u7b49\u4e8e 25 \u8fd4\u56de Hot\uff0c\u5426\u5219\u8fd4\u56de Warm\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u4ee5\u4efb\u610f\u987a\u5e8f\u8fd4\u56de\u4f60\u7684\u67e5\u8be2\u7ed3\u679c\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u6240\u793a\uff1a

    \n\n
    \nCountries table:\n+------------+--------------+\n| country_id | country_name |\n+------------+--------------+\n| 2          | USA          |\n| 3          | Australia    |\n| 7          | Peru         |\n| 5          | China        |\n| 8          | Morocco      |\n| 9          | Spain        |\n+------------+--------------+\nWeather table:\n+------------+---------------+------------+\n| country_id | weather_state | day        |\n+------------+---------------+------------+\n| 2          | 15            | 2019-11-01 |\n| 2          | 12            | 2019-10-28 |\n| 2          | 12            | 2019-10-27 |\n| 3          | -2            | 2019-11-10 |\n| 3          | 0             | 2019-11-11 |\n| 3          | 3             | 2019-11-12 |\n| 5          | 16            | 2019-11-07 |\n| 5          | 18            | 2019-11-09 |\n| 5          | 21            | 2019-11-23 |\n| 7          | 25            | 2019-11-28 |\n| 7          | 22            | 2019-12-01 |\n| 7          | 20            | 2019-12-02 |\n| 8          | 25            | 2019-11-05 |\n| 8          | 27            | 2019-11-15 |\n| 8          | 31            | 2019-11-25 |\n| 9          | 7             | 2019-10-23 |\n| 9          | 3             | 2019-12-23 |\n+------------+---------------+------------+\nResult table:\n+--------------+--------------+\n| country_name | weather_type |\n+--------------+--------------+\n| USA          | Cold         |\n| Austraila    | Cold         |\n| Peru         | Hot          |\n| China        | Warm         |\n| Morocco      | Hot          |\n+--------------+--------------+\nUSA 11 \u6708\u7684\u5e73\u5747 weather_state \u4e3a (15) / 1 = 15 \u6240\u4ee5\u5929\u6c14\u7c7b\u578b\u4e3a Cold\u3002\nAustralia 11 \u6708\u7684\u5e73\u5747 weather_state \u4e3a (-2 + 0 + 3) / 3 = 0.333 \u6240\u4ee5\u5929\u6c14\u7c7b\u578b\u4e3a Cold\u3002\nPeru 11 \u6708\u7684\u5e73\u5747 weather_state \u4e3a (25) / 1 = 25 \u6240\u4ee5\u5929\u6c14\u7c7b\u578b\u4e3a Hot\u3002\nChina 11 \u6708\u7684\u5e73\u5747 weather_state \u4e3a (16 + 18 + 21) / 3 = 18.333 \u6240\u4ee5\u5929\u6c14\u7c7b\u578b\u4e3a Warm\u3002\nMorocco 11 \u6708\u7684\u5e73\u5747 weather_state \u4e3a (25 + 27 + 31) / 3 = 27.667 \u6240\u4ee5\u5929\u6c14\u7c7b\u578b\u4e3a Hot\u3002\n\u6211\u4eec\u5e76\u4e0d\u77e5\u9053 Spain \u5728 11 \u6708\u7684 weather_state \u60c5\u51b5\u6240\u4ee5\u65e0\u9700\u5c06\u4ed6\u5305\u542b\u5728\u7ed3\u679c\u4e2d\u3002\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1294](https://leetcode-cn.com/problems/weather-type-in-each-country)", "[\u4e0d\u540c\u56fd\u5bb6\u7684\u5929\u6c14\u7c7b\u578b](/solution/1200-1299/1294.Weather%20Type%20in%20Each%20Country/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1294](https://leetcode.com/problems/weather-type-in-each-country)", "[Weather Type in Each Country](/solution/1200-1299/1294.Weather%20Type%20in%20Each%20Country/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1424", "frontend_question_id": "1298", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-candies-you-can-get-from-boxes", "url_en": "https://leetcode.com/problems/maximum-candies-you-can-get-from-boxes", "relative_path_cn": "/solution/1200-1299/1298.Maximum%20Candies%20You%20Can%20Get%20from%20Boxes/README.md", "relative_path_en": "/solution/1200-1299/1298.Maximum%20Candies%20You%20Can%20Get%20from%20Boxes/README_EN.md", "title_cn": "\u4f60\u80fd\u4ece\u76d2\u5b50\u91cc\u83b7\u5f97\u7684\u6700\u5927\u7cd6\u679c\u6570", "title_en": "Maximum Candies You Can Get from Boxes", "question_title_slug": "maximum-candies-you-can-get-from-boxes", "content_en": "

    Given n boxes, each box is given in the format [status, candies, keys, containedBoxes] where:

    \r\n\r\n
      \r\n\t
    • status[i]: an integer which is 1 if box[i] is open and 0 if box[i] is closed.
    • \r\n\t
    • candies[i]: an integer representing the number of candies in box[i].
    • \r\n\t
    • keys[i]: an array contains the indices of the boxes you can open with the key in box[i].
    • \r\n\t
    • containedBoxes[i]: an array contains the indices of the boxes found in box[i].
    • \r\n
    \r\n\r\n

    You will start with some boxes given in initialBoxes array. You can take all the candies in any open box and you can use the keys in it to open new boxes and you also can use the boxes you find in it.

    \r\n\r\n

    Return the maximum number of candies you can get following the rules above.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: status = [1,0,1,0], candies = [7,5,4,100], keys = [[],[],[1],[]], containedBoxes = [[1,2],[3],[],[]], initialBoxes = [0]\r\nOutput: 16\r\nExplanation: You will be initially given box 0. You will find 7 candies in it and boxes 1 and 2. Box 1 is closed and you don't have a key for it so you will open box 2. You will find 4 candies and a key to box 1 in box 2.\r\nIn box 1, you will find 5 candies and box 3 but you will not find a key to box 3 so box 3 will remain closed.\r\nTotal number of candies collected = 7 + 4 + 5 = 16 candy.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: status = [1,0,0,0,0,0], candies = [1,1,1,1,1,1], keys = [[1,2,3,4,5],[],[],[],[],[]], containedBoxes = [[1,2,3,4,5],[],[],[],[],[]], initialBoxes = [0]\r\nOutput: 6\r\nExplanation: You have initially box 0. Opening it you can find boxes 1,2,3,4 and 5 and their keys. The total number of candies will be 6.\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: status = [1,1,1], candies = [100,1,100], keys = [[],[0,2],[]], containedBoxes = [[],[],[]], initialBoxes = [1]\r\nOutput: 1\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: status = [1], candies = [100], keys = [[]], containedBoxes = [[]], initialBoxes = []\r\nOutput: 0\r\n
    \r\n\r\n

    Example 5:

    \r\n\r\n
    \r\nInput: status = [1,1,1], candies = [2,3,2], keys = [[],[],[]], containedBoxes = [[],[],[]], initialBoxes = [2,1,0]\r\nOutput: 7\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= status.length <= 1000
    • \r\n\t
    • status.length == candies.length == keys.length == containedBoxes.length == n
    • \r\n\t
    • status[i] is 0 or 1.
    • \r\n\t
    • 1 <= candies[i] <= 1000
    • \r\n\t
    • 0 <= keys[i].length <= status.length
    • \r\n\t
    • 0 <= keys[i][j] < status.length
    • \r\n\t
    • All values in keys[i] are unique.
    • \r\n\t
    • 0 <= containedBoxes[i].length <= status.length
    • \r\n\t
    • 0 <= containedBoxes[i][j] < status.length
    • \r\n\t
    • All values in containedBoxes[i] are unique.
    • \r\n\t
    • Each box is contained in one box at most.
    • \r\n\t
    • 0 <= initialBoxes.length <= status.length
    • \r\n\t
    • 0 <= initialBoxes[i] < status.length
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60 n \u4e2a\u76d2\u5b50\uff0c\u6bcf\u4e2a\u76d2\u5b50\u7684\u683c\u5f0f\u4e3a [status, candies, keys, containedBoxes] \uff0c\u5176\u4e2d\uff1a

    \n\n
      \n\t
    • \u72b6\u6001\u5b57 status[i]\uff1a\u6574\u6570\uff0c\u5982\u679c box[i] \u662f\u5f00\u7684\uff0c\u90a3\u4e48\u662f \uff0c\u5426\u5219\u662f \u3002
    • \n\t
    • \u7cd6\u679c\u6570 candies[i]: \u6574\u6570\uff0c\u8868\u793a box[i] \u4e2d\u7cd6\u679c\u7684\u6570\u76ee\u3002
    • \n\t
    • \u94a5\u5319 keys[i]\uff1a\u6570\u7ec4\uff0c\u8868\u793a\u4f60\u6253\u5f00 box[i] \u540e\uff0c\u53ef\u4ee5\u5f97\u5230\u4e00\u4e9b\u76d2\u5b50\u7684\u94a5\u5319\uff0c\u6bcf\u4e2a\u5143\u7d20\u5206\u522b\u4e3a\u8be5\u94a5\u5319\u5bf9\u5e94\u76d2\u5b50\u7684\u4e0b\u6807\u3002
    • \n\t
    • \u5185\u542b\u7684\u76d2\u5b50 containedBoxes[i]\uff1a\u6574\u6570\uff0c\u8868\u793a\u653e\u5728 box[i] \u91cc\u7684\u76d2\u5b50\u6240\u5bf9\u5e94\u7684\u4e0b\u6807\u3002
    • \n
    \n\n

    \u7ed9\u4f60\u4e00\u4e2a initialBoxes \u6570\u7ec4\uff0c\u8868\u793a\u4f60\u73b0\u5728\u5f97\u5230\u7684\u76d2\u5b50\uff0c\u4f60\u53ef\u4ee5\u83b7\u5f97\u91cc\u9762\u7684\u7cd6\u679c\uff0c\u4e5f\u53ef\u4ee5\u7528\u76d2\u5b50\u91cc\u7684\u94a5\u5319\u6253\u5f00\u65b0\u7684\u76d2\u5b50\uff0c\u8fd8\u53ef\u4ee5\u7ee7\u7eed\u63a2\u7d22\u4ece\u8fd9\u4e2a\u76d2\u5b50\u91cc\u627e\u5230\u7684\u5176\u4ed6\u76d2\u5b50\u3002

    \n\n

    \u8bf7\u4f60\u6309\u7167\u4e0a\u8ff0\u89c4\u5219\uff0c\u8fd4\u56de\u53ef\u4ee5\u83b7\u5f97\u7cd6\u679c\u7684 \u6700\u5927\u6570\u76ee \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1astatus = [1,0,1,0], candies = [7,5,4,100], keys = [[],[],[1],[]], containedBoxes = [[1,2],[3],[],[]], initialBoxes = [0]\n\u8f93\u51fa\uff1a16\n\u89e3\u91ca\uff1a\n\u4e00\u5f00\u59cb\u4f60\u6709\u76d2\u5b50 0 \u3002\u4f60\u5c06\u83b7\u5f97\u5b83\u91cc\u9762\u7684 7 \u4e2a\u7cd6\u679c\u548c\u76d2\u5b50 1 \u548c 2\u3002\n\u76d2\u5b50 1 \u76ee\u524d\u72b6\u6001\u662f\u5173\u95ed\u7684\uff0c\u800c\u4e14\u4f60\u8fd8\u6ca1\u6709\u5bf9\u5e94\u5b83\u7684\u94a5\u5319\u3002\u6240\u4ee5\u4f60\u5c06\u4f1a\u6253\u5f00\u76d2\u5b50 2 \uff0c\u5e76\u5f97\u5230\u91cc\u9762\u7684 4 \u4e2a\u7cd6\u679c\u548c\u76d2\u5b50 1 \u7684\u94a5\u5319\u3002\n\u5728\u76d2\u5b50 1 \u4e2d\uff0c\u4f60\u4f1a\u83b7\u5f97 5 \u4e2a\u7cd6\u679c\u548c\u76d2\u5b50 3 \uff0c\u4f46\u662f\u4f60\u6ca1\u6cd5\u83b7\u5f97\u76d2\u5b50 3 \u7684\u94a5\u5319\u6240\u4ee5\u76d2\u5b50 3 \u4f1a\u4fdd\u6301\u5173\u95ed\u72b6\u6001\u3002\n\u4f60\u603b\u5171\u53ef\u4ee5\u83b7\u5f97\u7684\u7cd6\u679c\u6570\u76ee = 7 + 4 + 5 = 16 \u4e2a\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1astatus = [1,0,0,0,0,0], candies = [1,1,1,1,1,1], keys = [[1,2,3,4,5],[],[],[],[],[]], containedBoxes = [[1,2,3,4,5],[],[],[],[],[]], initialBoxes = [0]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\n\u4f60\u4e00\u5f00\u59cb\u62e5\u6709\u76d2\u5b50 0 \u3002\u6253\u5f00\u5b83\u4f60\u53ef\u4ee5\u627e\u5230\u76d2\u5b50 1,2,3,4,5 \u548c\u5b83\u4eec\u5bf9\u5e94\u7684\u94a5\u5319\u3002\n\u6253\u5f00\u8fd9\u4e9b\u76d2\u5b50\uff0c\u4f60\u5c06\u83b7\u5f97\u6240\u6709\u76d2\u5b50\u7684\u7cd6\u679c\uff0c\u6240\u4ee5\u603b\u7cd6\u679c\u6570\u4e3a 6 \u4e2a\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1astatus = [1,1,1], candies = [100,1,100], keys = [[],[0,2],[]], containedBoxes = [[],[],[]], initialBoxes = [1]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1astatus = [1], candies = [100], keys = [[]], containedBoxes = [[]], initialBoxes = []\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1astatus = [1,1,1], candies = [2,3,2], keys = [[],[],[]], containedBoxes = [[],[],[]], initialBoxes = [2,1,0]\n\u8f93\u51fa\uff1a7\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= status.length <= 1000
    • \n\t
    • status.length == candies.length == keys.length == containedBoxes.length == n
    • \n\t
    • status[i] \u8981\u4e48\u662f 0 \u8981\u4e48\u662f 1 \u3002
    • \n\t
    • 1 <= candies[i] <= 1000
    • \n\t
    • 0 <= keys[i].length <= status.length
    • \n\t
    • 0 <= keys[i][j] < status.length
    • \n\t
    • keys[i] \u4e2d\u7684\u503c\u90fd\u662f\u4e92\u4e0d\u76f8\u540c\u7684\u3002
    • \n\t
    • 0 <= containedBoxes[i].length <= status.length
    • \n\t
    • 0 <= containedBoxes[i][j] < status.length
    • \n\t
    • containedBoxes[i] \u4e2d\u7684\u503c\u90fd\u662f\u4e92\u4e0d\u76f8\u540c\u7684\u3002
    • \n\t
    • \u6bcf\u4e2a\u76d2\u5b50\u6700\u591a\u88ab\u4e00\u4e2a\u76d2\u5b50\u5305\u542b\u3002
    • \n\t
    • 0 <= initialBoxes.length <= status.length
    • \n\t
    • 0 <= initialBoxes[i] < status.length
    • \n
    \n", "tags_en": ["Breadth-first Search"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxCandies(vector& status, vector& candies, vector>& keys, vector>& containedBoxes, vector& initialBoxes) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxCandies(int[] status, int[] candies, int[][] keys, int[][] containedBoxes, int[] initialBoxes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxCandies(self, status, candies, keys, containedBoxes, initialBoxes):\n \"\"\"\n :type status: List[int]\n :type candies: List[int]\n :type keys: List[List[int]]\n :type containedBoxes: List[List[int]]\n :type initialBoxes: List[int]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxCandies(self, status: List[int], candies: List[int], keys: List[List[int]], containedBoxes: List[List[int]], initialBoxes: List[int]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxCandies(int* status, int statusSize, int* candies, int candiesSize, int** keys, int keysSize, int* keysColSize, int** containedBoxes, int containedBoxesSize, int* containedBoxesColSize, int* initialBoxes, int initialBoxesSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxCandies(int[] status, int[] candies, int[][] keys, int[][] containedBoxes, int[] initialBoxes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} status\n * @param {number[]} candies\n * @param {number[][]} keys\n * @param {number[][]} containedBoxes\n * @param {number[]} initialBoxes\n * @return {number}\n */\nvar maxCandies = function(status, candies, keys, containedBoxes, initialBoxes) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} status\n# @param {Integer[]} candies\n# @param {Integer[][]} keys\n# @param {Integer[][]} contained_boxes\n# @param {Integer[]} initial_boxes\n# @return {Integer}\ndef max_candies(status, candies, keys, contained_boxes, initial_boxes)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxCandies(_ status: [Int], _ candies: [Int], _ keys: [[Int]], _ containedBoxes: [[Int]], _ initialBoxes: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxCandies(status []int, candies []int, keys [][]int, containedBoxes [][]int, initialBoxes []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxCandies(status: Array[Int], candies: Array[Int], keys: Array[Array[Int]], containedBoxes: Array[Array[Int]], initialBoxes: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxCandies(status: IntArray, candies: IntArray, keys: Array, containedBoxes: Array, initialBoxes: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_candies(status: Vec, candies: Vec, keys: Vec>, contained_boxes: Vec>, initial_boxes: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $status\n * @param Integer[] $candies\n * @param Integer[][] $keys\n * @param Integer[][] $containedBoxes\n * @param Integer[] $initialBoxes\n * @return Integer\n */\n function maxCandies($status, $candies, $keys, $containedBoxes, $initialBoxes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxCandies(status: number[], candies: number[], keys: number[][], containedBoxes: number[][], initialBoxes: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-candies status candies keys containedBoxes initialBoxes)\n (-> (listof exact-integer?) (listof exact-integer?) (listof (listof exact-integer?)) (listof (listof exact-integer?)) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1298](https://leetcode-cn.com/problems/maximum-candies-you-can-get-from-boxes)", "[\u4f60\u80fd\u4ece\u76d2\u5b50\u91cc\u83b7\u5f97\u7684\u6700\u5927\u7cd6\u679c\u6570](/solution/1200-1299/1298.Maximum%20Candies%20You%20Can%20Get%20from%20Boxes/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[1298](https://leetcode.com/problems/maximum-candies-you-can-get-from-boxes)", "[Maximum Candies You Can Get from Boxes](/solution/1200-1299/1298.Maximum%20Candies%20You%20Can%20Get%20from%20Boxes/README_EN.md)", "`Breadth-first Search`", "Hard", ""]}, {"question_id": "1423", "frontend_question_id": "1297", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-number-of-occurrences-of-a-substring", "url_en": "https://leetcode.com/problems/maximum-number-of-occurrences-of-a-substring", "relative_path_cn": "/solution/1200-1299/1297.Maximum%20Number%20of%20Occurrences%20of%20a%20Substring/README.md", "relative_path_en": "/solution/1200-1299/1297.Maximum%20Number%20of%20Occurrences%20of%20a%20Substring/README_EN.md", "title_cn": "\u5b50\u4e32\u7684\u6700\u5927\u51fa\u73b0\u6b21\u6570", "title_en": "Maximum Number of Occurrences of a Substring", "question_title_slug": "maximum-number-of-occurrences-of-a-substring", "content_en": "

    Given a string s, return the maximum number of ocurrences of any substring under the following rules:

    \r\n\r\n
      \r\n\t
    • The number of unique characters in the substring must be less than or equal to maxLetters.
    • \r\n\t
    • The substring size must be between minSize and maxSize inclusive.
    • \r\n
    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4\r\nOutput: 2\r\nExplanation: Substring "aab" has 2 ocurrences in the original string.\r\nIt satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize).\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3\r\nOutput: 2\r\nExplanation: Substring "aaa" occur 2 times in the string. It can overlap.\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3\r\nOutput: 3\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3\r\nOutput: 0\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= s.length <= 10^5
    • \r\n\t
    • 1 <= maxLetters <= 26
    • \r\n\t
    • 1 <= minSize <= maxSize <= min(26, s.length)
    • \r\n\t
    • s only contains lowercase English letters.
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \uff0c\u8bf7\u4f60\u8fd4\u56de\u6ee1\u8db3\u4ee5\u4e0b\u6761\u4ef6\u4e14\u51fa\u73b0\u6b21\u6570\u6700\u5927\u7684 \u4efb\u610f \u5b50\u4e32\u7684\u51fa\u73b0\u6b21\u6570\uff1a

    \n\n
      \n\t
    • \u5b50\u4e32\u4e2d\u4e0d\u540c\u5b57\u6bcd\u7684\u6570\u76ee\u5fc5\u987b\u5c0f\u4e8e\u7b49\u4e8e maxLetters \u3002
    • \n\t
    • \u5b50\u4e32\u7684\u957f\u5ea6\u5fc5\u987b\u5927\u4e8e\u7b49\u4e8e minSize \u4e14\u5c0f\u4e8e\u7b49\u4e8e maxSize \u3002
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1as = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5b50\u4e32 "aab" \u5728\u539f\u5b57\u7b26\u4e32\u4e2d\u51fa\u73b0\u4e86 2 \u6b21\u3002\n\u5b83\u6ee1\u8db3\u6240\u6709\u7684\u8981\u6c42\uff1a2 \u4e2a\u4e0d\u540c\u7684\u5b57\u6bcd\uff0c\u957f\u5ea6\u4e3a 3 \uff08\u5728 minSize \u548c maxSize \u8303\u56f4\u5185\uff09\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1as = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5b50\u4e32 "aaa" \u5728\u539f\u5b57\u7b26\u4e32\u4e2d\u51fa\u73b0\u4e86 2 \u6b21\uff0c\u4e14\u5b83\u4eec\u6709\u91cd\u53e0\u90e8\u5206\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1as = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3\n\u8f93\u51fa\uff1a3\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1as = "abcde", maxLetters = 2, minSize = 3, maxSize = 3\n\u8f93\u51fa\uff1a0\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 10^5
    • \n\t
    • 1 <= maxLetters <= 26
    • \n\t
    • 1 <= minSize <= maxSize <= min(26, s.length)
    • \n\t
    • s \u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    • \n
    \n", "tags_en": ["Bit Manipulation", "String"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxFreq(string s, int maxLetters, int minSize, int maxSize) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxFreq(String s, int maxLetters, int minSize, int maxSize) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxFreq(self, s, maxLetters, minSize, maxSize):\n \"\"\"\n :type s: str\n :type maxLetters: int\n :type minSize: int\n :type maxSize: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxFreq(char * s, int maxLetters, int minSize, int maxSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxFreq(string s, int maxLetters, int minSize, int maxSize) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number} maxLetters\n * @param {number} minSize\n * @param {number} maxSize\n * @return {number}\n */\nvar maxFreq = function(s, maxLetters, minSize, maxSize) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer} max_letters\n# @param {Integer} min_size\n# @param {Integer} max_size\n# @return {Integer}\ndef max_freq(s, max_letters, min_size, max_size)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxFreq(_ s: String, _ maxLetters: Int, _ minSize: Int, _ maxSize: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxFreq(s string, maxLetters int, minSize int, maxSize int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxFreq(s: String, maxLetters: Int, minSize: Int, maxSize: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxFreq(s: String, maxLetters: Int, minSize: Int, maxSize: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_freq(s: String, max_letters: i32, min_size: i32, max_size: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer $maxLetters\n * @param Integer $minSize\n * @param Integer $maxSize\n * @return Integer\n */\n function maxFreq($s, $maxLetters, $minSize, $maxSize) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxFreq(s: string, maxLetters: number, minSize: number, maxSize: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-freq s maxLetters minSize maxSize)\n (-> string? exact-integer? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1297](https://leetcode-cn.com/problems/maximum-number-of-occurrences-of-a-substring)", "[\u5b50\u4e32\u7684\u6700\u5927\u51fa\u73b0\u6b21\u6570](/solution/1200-1299/1297.Maximum%20Number%20of%20Occurrences%20of%20a%20Substring/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1297](https://leetcode.com/problems/maximum-number-of-occurrences-of-a-substring)", "[Maximum Number of Occurrences of a Substring](/solution/1200-1299/1297.Maximum%20Number%20of%20Occurrences%20of%20a%20Substring/README_EN.md)", "`Bit Manipulation`,`String`", "Medium", ""]}, {"question_id": "1422", "frontend_question_id": "1296", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/divide-array-in-sets-of-k-consecutive-numbers", "url_en": "https://leetcode.com/problems/divide-array-in-sets-of-k-consecutive-numbers", "relative_path_cn": "/solution/1200-1299/1296.Divide%20Array%20in%20Sets%20of%20K%20Consecutive%20Numbers/README.md", "relative_path_en": "/solution/1200-1299/1296.Divide%20Array%20in%20Sets%20of%20K%20Consecutive%20Numbers/README_EN.md", "title_cn": "\u5212\u5206\u6570\u7ec4\u4e3a\u8fde\u7eed\u6570\u5b57\u7684\u96c6\u5408", "title_en": "Divide Array in Sets of K Consecutive Numbers", "question_title_slug": "divide-array-in-sets-of-k-consecutive-numbers", "content_en": "

    Given an array of integers nums and a positive integer k, find whether it's possible to divide this array into sets of k consecutive numbers
    \nReturn True if it is possible. Otherwise, return False.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,3,3,4,4,5,6], k = 4\nOutput: true\nExplanation: Array can be divided into [1,2,3,4] and [3,4,5,6].\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [3,2,1,2,3,4,3,4,5,9,10,11], k = 3\nOutput: true\nExplanation: Array can be divided into [1,2,3] , [2,3,4] , [3,4,5] and [9,10,11].\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [3,3,2,2,1,1], k = 3\nOutput: true\n
    \n\n

    Example 4:

    \n\n
    \nInput: nums = [1,2,3,4], k = 3\nOutput: false\nExplanation: Each array should be divided in subarrays of size 3.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= k <= nums.length <= 105
    • \n\t
    • 1 <= nums[i] <= 109
    • \n
    \n\n

     

    \nNote: This question is the same as 846: https://leetcode.com/problems/hand-of-straights/", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0nums\u00a0\u548c\u4e00\u4e2a\u6b63\u6574\u6570\u00a0k\uff0c\u8bf7\u4f60\u5224\u65ad\u662f\u5426\u53ef\u4ee5\u628a\u8fd9\u4e2a\u6570\u7ec4\u5212\u5206\u6210\u4e00\u4e9b\u7531\u00a0k\u00a0\u4e2a\u8fde\u7eed\u6570\u5b57\u7ec4\u6210\u7684\u96c6\u5408\u3002
    \n\u5982\u679c\u53ef\u4ee5\uff0c\u8bf7\u8fd4\u56de\u00a0True\uff1b\u5426\u5219\uff0c\u8fd4\u56de\u00a0False\u3002

    \n\n

    \u00a0

    \n\n

    \u6ce8\u610f\uff1a\u6b64\u9898\u76ee\u4e0e 846 \u91cd\u590d\uff1ahttps://leetcode-cn.com/problems/hand-of-straights/

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,3,3,4,4,5,6], k = 4\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u6570\u7ec4\u53ef\u4ee5\u5206\u6210 [1,2,3,4] \u548c [3,4,5,6]\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [3,2,1,2,3,4,3,4,5,9,10,11], k = 3\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u6570\u7ec4\u53ef\u4ee5\u5206\u6210 [1,2,3] , [2,3,4] , [3,4,5] \u548c [9,10,11]\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [3,3,2,2,1,1], k = 3\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,3,4], k = 3\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u6570\u7ec4\u4e0d\u80fd\u5206\u6210\u51e0\u4e2a\u5927\u5c0f\u4e3a 3 \u7684\u5b50\u6570\u7ec4\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 10^5
    • \n\t
    • 1 <= nums[i] <= 10^9
    • \n\t
    • 1 <= k <= nums.length
    • \n
    \n", "tags_en": ["Greedy", "Array"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isPossibleDivide(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isPossibleDivide(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isPossibleDivide(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isPossibleDivide(self, nums: List[int], k: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isPossibleDivide(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsPossibleDivide(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {boolean}\n */\nvar isPossibleDivide = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Boolean}\ndef is_possible_divide(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isPossibleDivide(_ nums: [Int], _ k: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isPossibleDivide(nums []int, k int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isPossibleDivide(nums: Array[Int], k: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isPossibleDivide(nums: IntArray, k: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_possible_divide(nums: Vec, k: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Boolean\n */\n function isPossibleDivide($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isPossibleDivide(nums: number[], k: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-possible-divide nums k)\n (-> (listof exact-integer?) exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1296](https://leetcode-cn.com/problems/divide-array-in-sets-of-k-consecutive-numbers)", "[\u5212\u5206\u6570\u7ec4\u4e3a\u8fde\u7eed\u6570\u5b57\u7684\u96c6\u5408](/solution/1200-1299/1296.Divide%20Array%20in%20Sets%20of%20K%20Consecutive%20Numbers/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1296](https://leetcode.com/problems/divide-array-in-sets-of-k-consecutive-numbers)", "[Divide Array in Sets of K Consecutive Numbers](/solution/1200-1299/1296.Divide%20Array%20in%20Sets%20of%20K%20Consecutive%20Numbers/README_EN.md)", "`Greedy`,`Array`", "Medium", ""]}, {"question_id": "1421", "frontend_question_id": "1295", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-numbers-with-even-number-of-digits", "url_en": "https://leetcode.com/problems/find-numbers-with-even-number-of-digits", "relative_path_cn": "/solution/1200-1299/1295.Find%20Numbers%20with%20Even%20Number%20of%20Digits/README.md", "relative_path_en": "/solution/1200-1299/1295.Find%20Numbers%20with%20Even%20Number%20of%20Digits/README_EN.md", "title_cn": "\u7edf\u8ba1\u4f4d\u6570\u4e3a\u5076\u6570\u7684\u6570\u5b57", "title_en": "Find Numbers with Even Number of Digits", "question_title_slug": "find-numbers-with-even-number-of-digits", "content_en": "Given an array nums of integers, return how many of them contain an even number of digits.\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [12,345,2,6,7896]\nOutput: 2\nExplanation: \n12 contains 2 digits (even number of digits). \n345 contains 3 digits (odd number of digits). \n2 contains 1 digit (odd number of digits). \n6 contains 1 digit (odd number of digits). \n7896 contains 4 digits (even number of digits). \nTherefore only 12 and 7896 contain an even number of digits.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [555,901,482,1771]\nOutput: 1 \nExplanation: \nOnly 1771 contains an even number of digits.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 500
    • \n\t
    • 1 <= nums[i] <= 10^5
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums\uff0c\u8bf7\u4f60\u8fd4\u56de\u5176\u4e2d\u4f4d\u6570\u4e3a \u5076\u6570 \u7684\u6570\u5b57\u7684\u4e2a\u6570\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [12,345,2,6,7896]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n12 \u662f 2 \u4f4d\u6570\u5b57\uff08\u4f4d\u6570\u4e3a\u5076\u6570\uff09 \n345 \u662f 3 \u4f4d\u6570\u5b57\uff08\u4f4d\u6570\u4e3a\u5947\u6570\uff09  \n2 \u662f 1 \u4f4d\u6570\u5b57\uff08\u4f4d\u6570\u4e3a\u5947\u6570\uff09 \n6 \u662f 1 \u4f4d\u6570\u5b57 \u4f4d\u6570\u4e3a\u5947\u6570\uff09 \n7896 \u662f 4 \u4f4d\u6570\u5b57\uff08\u4f4d\u6570\u4e3a\u5076\u6570\uff09  \n\u56e0\u6b64\u53ea\u6709 12 \u548c 7896 \u662f\u4f4d\u6570\u4e3a\u5076\u6570\u7684\u6570\u5b57\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [555,901,482,1771]\n\u8f93\u51fa\uff1a1 \n\u89e3\u91ca\uff1a \n\u53ea\u6709 1771 \u662f\u4f4d\u6570\u4e3a\u5076\u6570\u7684\u6570\u5b57\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 500
    • \n\t
    • 1 <= nums[i] <= 10^5
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findNumbers(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findNumbers(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findNumbers(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findNumbers(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findNumbers(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindNumbers(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar findNumbers = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef find_numbers(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findNumbers(_ nums: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findNumbers(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findNumbers(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findNumbers(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_numbers(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function findNumbers($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findNumbers(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-numbers nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1295](https://leetcode-cn.com/problems/find-numbers-with-even-number-of-digits)", "[\u7edf\u8ba1\u4f4d\u6570\u4e3a\u5076\u6570\u7684\u6570\u5b57](/solution/1200-1299/1295.Find%20Numbers%20with%20Even%20Number%20of%20Digits/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1295](https://leetcode.com/problems/find-numbers-with-even-number-of-digits)", "[Find Numbers with Even Number of Digits](/solution/1200-1299/1295.Find%20Numbers%20with%20Even%20Number%20of%20Digits/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1420", "frontend_question_id": "1285", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/find-the-start-and-end-number-of-continuous-ranges", "url_en": "https://leetcode.com/problems/find-the-start-and-end-number-of-continuous-ranges", "relative_path_cn": "/solution/1200-1299/1285.Find%20the%20Start%20and%20End%20Number%20of%20Continuous%20Ranges/README.md", "relative_path_en": "/solution/1200-1299/1285.Find%20the%20Start%20and%20End%20Number%20of%20Continuous%20Ranges/README_EN.md", "title_cn": "\u627e\u5230\u8fde\u7eed\u533a\u95f4\u7684\u5f00\u59cb\u548c\u7ed3\u675f\u6570\u5b57", "title_en": "Find the Start and End Number of Continuous Ranges", "question_title_slug": "find-the-start-and-end-number-of-continuous-ranges", "content_en": "

    Table: Logs

    \r\n\r\n
    \r\n+---------------+---------+\r\n| Column Name   | Type    |\r\n+---------------+---------+\r\n| log_id        | int     |\r\n+---------------+---------+\r\nid is the primary key for this table.\r\nEach row of this table contains the ID in a log Table.\r\n\r\n
    \r\n\r\n

    Since some IDs have been removed from Logs. Write an SQL query to find the start and end number of continuous ranges in table Logs.

    \r\n\r\n

    Order the result table by start_id.

    \r\n\r\n

    The query result format is in the following example:

    \r\n\r\n
    \r\nLogs table:\r\n+------------+\r\n| log_id     |\r\n+------------+\r\n| 1          |\r\n| 2          |\r\n| 3          |\r\n| 7          |\r\n| 8          |\r\n| 10         |\r\n+------------+\r\n\r\nResult table:\r\n+------------+--------------+\r\n| start_id   | end_id       |\r\n+------------+--------------+\r\n| 1          | 3            |\r\n| 7          | 8            |\r\n| 10         | 10           |\r\n+------------+--------------+\r\nThe result table should contain all ranges in table Logs.\r\nFrom 1 to 3 is contained in the table.\r\nFrom 4 to 6 is missing in the table\r\nFrom 7 to 8 is contained in the table.\r\nNumber 9 is missing in the table.\r\nNumber 10 is contained in the table.\r\n
    ", "content_cn": "

    \u8868\uff1aLogs

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| log_id        | int     |\n+---------------+---------+\nid \u662f\u4e0a\u8868\u7684\u4e3b\u952e\u3002\n\u4e0a\u8868\u7684\u6bcf\u4e00\u884c\u5305\u542b\u65e5\u5fd7\u8868\u4e2d\u7684\u4e00\u4e2a ID\u3002\n
    \n\n

     

    \n\n

    \u540e\u6765\u4e00\u4e9b ID \u4ece Logs \u8868\u4e2d\u5220\u9664\u3002\u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\u5f97\u5230 Logs \u8868\u4e2d\u7684\u8fde\u7eed\u533a\u95f4\u7684\u5f00\u59cb\u6570\u5b57\u548c\u7ed3\u675f\u6570\u5b57\u3002

    \n\n

    \u5c06\u67e5\u8be2\u8868\u6309\u7167 start_id \u6392\u5e8f\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u9762\u7684\u4f8b\u5b50\uff1a

    \n\n
    \nLogs \u8868\uff1a\n+------------+\n| log_id     |\n+------------+\n| 1          |\n| 2          |\n| 3          |\n| 7          |\n| 8          |\n| 10         |\n+------------+\n\n\u7ed3\u679c\u8868\uff1a\n+------------+--------------+\n| start_id   | end_id       |\n+------------+--------------+\n| 1          | 3            |\n| 7          | 8            |\n| 10         | 10           |\n+------------+--------------+\n\u7ed3\u679c\u8868\u5e94\u5305\u542b Logs \u8868\u4e2d\u7684\u6240\u6709\u533a\u95f4\u3002\n\u4ece 1 \u5230 3 \u5728\u8868\u4e2d\u3002\n\u4ece 4 \u5230 6 \u4e0d\u5728\u8868\u4e2d\u3002\n\u4ece 7 \u5230 8 \u5728\u8868\u4e2d\u3002\n9 \u4e0d\u5728\u8868\u4e2d\u3002\n10 \u5728\u8868\u4e2d\u3002\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1285](https://leetcode-cn.com/problems/find-the-start-and-end-number-of-continuous-ranges)", "[\u627e\u5230\u8fde\u7eed\u533a\u95f4\u7684\u5f00\u59cb\u548c\u7ed3\u675f\u6570\u5b57](/solution/1200-1299/1285.Find%20the%20Start%20and%20End%20Number%20of%20Continuous%20Ranges/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1285](https://leetcode.com/problems/find-the-start-and-end-number-of-continuous-ranges)", "[Find the Start and End Number of Continuous Ranges](/solution/1200-1299/1285.Find%20the%20Start%20and%20End%20Number%20of%20Continuous%20Ranges/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1415", "frontend_question_id": "1280", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/students-and-examinations", "url_en": "https://leetcode.com/problems/students-and-examinations", "relative_path_cn": "/solution/1200-1299/1280.Students%20and%20Examinations/README.md", "relative_path_en": "/solution/1200-1299/1280.Students%20and%20Examinations/README_EN.md", "title_cn": "\u5b66\u751f\u4eec\u53c2\u52a0\u5404\u79d1\u6d4b\u8bd5\u7684\u6b21\u6570", "title_en": "Students and Examinations", "question_title_slug": "students-and-examinations", "content_en": "

    Table: Students

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| student_id    | int     |\n| student_name  | varchar |\n+---------------+---------+\nstudent_id is the primary key for this table.\nEach row of this table contains the ID and the name of one student in the school.\n
    \n\n

     

    \n\n

    Table: Subjects

    \n\n
    \n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| subject_name | varchar |\n+--------------+---------+\nsubject_name is the primary key for this table.\nEach row of this table contains the name of one subject in the school.\n
    \n\n

     

    \n\n

    Table: Examinations

    \n\n
    \n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| student_id   | int     |\n| subject_name | varchar |\n+--------------+---------+\nThere is no primary key for this table. It may contain duplicates.\nEach student from the Students table takes every course from Subjects table.\nEach row of this table indicates that a student with ID student_id attended the exam of subject_name.\n
    \n\n

     

    \n\n

    Write an SQL query to find the number of times each student attended each exam.

    \n\n

    Order the result table by student_id and subject_name.

    \n\n

    The query result format is in the following example:

    \n\n
    \nStudents table:\n+------------+--------------+\n| student_id | student_name |\n+------------+--------------+\n| 1          | Alice        |\n| 2          | Bob          |\n| 13         | John         |\n| 6          | Alex         |\n+------------+--------------+\nSubjects table:\n+--------------+\n| subject_name |\n+--------------+\n| Math         |\n| Physics      |\n| Programming  |\n+--------------+\nExaminations table:\n+------------+--------------+\n| student_id | subject_name |\n+------------+--------------+\n| 1          | Math         |\n| 1          | Physics      |\n| 1          | Programming  |\n| 2          | Programming  |\n| 1          | Physics      |\n| 1          | Math         |\n| 13         | Math         |\n| 13         | Programming  |\n| 13         | Physics      |\n| 2          | Math         |\n| 1          | Math         |\n+------------+--------------+\nResult table:\n+------------+--------------+--------------+----------------+\n| student_id | student_name | subject_name | attended_exams |\n+------------+--------------+--------------+----------------+\n| 1          | Alice        | Math         | 3              |\n| 1          | Alice        | Physics      | 2              |\n| 1          | Alice        | Programming  | 1              |\n| 2          | Bob          | Math         | 1              |\n| 2          | Bob          | Physics      | 0              |\n| 2          | Bob          | Programming  | 1              |\n| 6          | Alex         | Math         | 0              |\n| 6          | Alex         | Physics      | 0              |\n| 6          | Alex         | Programming  | 0              |\n| 13         | John         | Math         | 1              |\n| 13         | John         | Physics      | 1              |\n| 13         | John         | Programming  | 1              |\n+------------+--------------+--------------+----------------+\nThe result table should contain all students and all subjects.\nAlice attended Math exam 3 times, Physics exam 2 times and Programming exam 1 time.\nBob attended Math exam 1 time, Programming exam 1 time and didn't attend the Physics exam.\nAlex didn't attend any exam.\nJohn attended Math exam 1 time, Physics exam 1 time and Programming exam 1 time.\n
    \n", "content_cn": "

    \u5b66\u751f\u8868: Students

    \n\n
    +---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| student_id    | int     |\n| student_name  | varchar |\n+---------------+---------+\n\u4e3b\u952e\u4e3a student_id\uff08\u5b66\u751fID\uff09\uff0c\u8be5\u8868\u5185\u7684\u6bcf\u4e00\u884c\u90fd\u8bb0\u5f55\u6709\u5b66\u6821\u4e00\u540d\u5b66\u751f\u7684\u4fe1\u606f\u3002\n
    \n\n

     

    \n\n

    \u79d1\u76ee\u8868: Subjects

    \n\n
    +--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| subject_name | varchar |\n+--------------+---------+\n\u4e3b\u952e\u4e3a subject_name\uff08\u79d1\u76ee\u540d\u79f0\uff09\uff0c\u6bcf\u4e00\u884c\u8bb0\u5f55\u5b66\u6821\u7684\u4e00\u95e8\u79d1\u76ee\u540d\u79f0\u3002\n
    \n\n

     

    \n\n

    \u8003\u8bd5\u8868: Examinations

    \n\n
    +--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| student_id   | int     |\n| subject_name | varchar |\n+--------------+---------+\n\u8fd9\u5f20\u8868\u538b\u6839\u6ca1\u6709\u4e3b\u952e\uff0c\u53ef\u80fd\u4f1a\u6709\u91cd\u590d\u884c\u3002\n\u5b66\u751f\u8868\u91cc\u7684\u4e00\u4e2a\u5b66\u751f\u4fee\u8bfb\u79d1\u76ee\u8868\u91cc\u7684\u6bcf\u4e00\u95e8\u79d1\u76ee\uff0c\u800c\u8fd9\u5f20\u8003\u8bd5\u8868\u7684\u6bcf\u4e00\u884c\u8bb0\u5f55\u5c31\u8868\u793a\u5b66\u751f\u8868\u91cc\u7684\u67d0\u4e2a\u5b66\u751f\u53c2\u52a0\u4e86\u4e00\u6b21\u79d1\u76ee\u8868\u91cc\u67d0\u95e8\u79d1\u76ee\u7684\u6d4b\u8bd5\u3002\n
    \n\n

     

    \n\n

    \u8981\u6c42\u5199\u4e00\u6bb5 SQL \u8bed\u53e5\uff0c\u67e5\u8be2\u51fa\u6bcf\u4e2a\u5b66\u751f\u53c2\u52a0\u6bcf\u4e00\u95e8\u79d1\u76ee\u6d4b\u8bd5\u7684\u6b21\u6570\uff0c\u7ed3\u679c\u6309 student_id \u548c subject_name \u6392\u5e8f\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u6784\u683c\u5f0f\u5982\u4e0b\u6240\u793a\uff1a

    \n\n
    Students table:\n+------------+--------------+\n| student_id | student_name |\n+------------+--------------+\n| 1          | Alice        |\n| 2          | Bob          |\n| 13         | John         |\n| 6          | Alex         |\n+------------+--------------+\nSubjects table:\n+--------------+\n| subject_name |\n+--------------+\n| Math         |\n| Physics      |\n| Programming  |\n+--------------+\nExaminations table:\n+------------+--------------+\n| student_id | subject_name |\n+------------+--------------+\n| 1          | Math         |\n| 1          | Physics      |\n| 1          | Programming  |\n| 2          | Programming  |\n| 1          | Physics      |\n| 1          | Math         |\n| 13         | Math         |\n| 13         | Programming  |\n| 13         | Physics      |\n| 2          | Math         |\n| 1          | Math         |\n+------------+--------------+\nResult table:\n+------------+--------------+--------------+----------------+\n| student_id | student_name | subject_name | attended_exams |\n+------------+--------------+--------------+----------------+\n| 1          | Alice        | Math         | 3              |\n| 1          | Alice        | Physics      | 2              |\n| 1          | Alice        | Programming  | 1              |\n| 2          | Bob          | Math         | 1              |\n| 2          | Bob          | Physics      | 0              |\n| 2          | Bob          | Programming  | 1              |\n| 6          | Alex         | Math         | 0              |\n| 6          | Alex         | Physics      | 0              |\n| 6          | Alex         | Programming  | 0              |\n| 13         | John         | Math         | 1              |\n| 13         | John         | Physics      | 1              |\n| 13         | John         | Programming  | 1              |\n+------------+--------------+--------------+----------------+\n\u7ed3\u679c\u8868\u9700\u5305\u542b\u6240\u6709\u5b66\u751f\u548c\u6240\u6709\u79d1\u76ee\uff08\u5373\u4fbf\u6d4b\u8bd5\u6b21\u6570\u4e3a0\uff09\uff1a\nAlice \u53c2\u52a0\u4e86 3 \u6b21\u6570\u5b66\u6d4b\u8bd5, 2 \u6b21\u7269\u7406\u6d4b\u8bd5\uff0c\u4ee5\u53ca 1 \u6b21\u7f16\u7a0b\u6d4b\u8bd5\uff1b\nBob \u53c2\u52a0\u4e86 1 \u6b21\u6570\u5b66\u6d4b\u8bd5, 1 \u6b21\u7f16\u7a0b\u6d4b\u8bd5\uff0c\u6ca1\u6709\u53c2\u52a0\u7269\u7406\u6d4b\u8bd5\uff1b\nAlex \u5565\u6d4b\u8bd5\u90fd\u6ca1\u53c2\u52a0\uff1b\nJohn  \u53c2\u52a0\u4e86\u6570\u5b66\u3001\u7269\u7406\u3001\u7f16\u7a0b\u6d4b\u8bd5\u5404 1 \u6b21\u3002\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1280](https://leetcode-cn.com/problems/students-and-examinations)", "[\u5b66\u751f\u4eec\u53c2\u52a0\u5404\u79d1\u6d4b\u8bd5\u7684\u6b21\u6570](/solution/1200-1299/1280.Students%20and%20Examinations/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1280](https://leetcode.com/problems/students-and-examinations)", "[Students and Examinations](/solution/1200-1299/1280.Students%20and%20Examinations/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1414", "frontend_question_id": "1293", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/shortest-path-in-a-grid-with-obstacles-elimination", "url_en": "https://leetcode.com/problems/shortest-path-in-a-grid-with-obstacles-elimination", "relative_path_cn": "/solution/1200-1299/1293.Shortest%20Path%20in%20a%20Grid%20with%20Obstacles%20Elimination/README.md", "relative_path_en": "/solution/1200-1299/1293.Shortest%20Path%20in%20a%20Grid%20with%20Obstacles%20Elimination/README_EN.md", "title_cn": "\u7f51\u683c\u4e2d\u7684\u6700\u77ed\u8def\u5f84", "title_en": "Shortest Path in a Grid with Obstacles Elimination", "question_title_slug": "shortest-path-in-a-grid-with-obstacles-elimination", "content_en": "

    Given a m * n grid, where each cell is either 0 (empty) or 1 (obstacle). In one step, you can move up, down, left or right from and to an empty cell.

    \n\n

    Return the minimum number of steps to walk from the upper left corner (0, 0) to the lower right corner (m-1, n-1) given that you can eliminate at most k obstacles. If it is not possible to find such walk return -1.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: \ngrid = \n[[0,0,0],\n [1,1,0],\n [0,0,0],\n [0,1,1],\n [0,0,0]], \nk = 1\nOutput: 6\nExplanation: \nThe shortest path without eliminating any obstacle is 10. \nThe shortest path with one obstacle elimination at position (3,2) is 6. Such path is (0,0) -> (0,1) -> (0,2) -> (1,2) -> (2,2) -> (3,2) -> (4,2).\n
    \n\n

     

    \n\n

    Example 2:

    \n\n
    \nInput: \ngrid = \n[[0,1,1],\n [1,1,1],\n [1,0,0]], \nk = 1\nOutput: -1\nExplanation: \nWe need to eliminate at least two obstacles to find such a walk.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • grid.length == m
    • \n\t
    • grid[0].length == n
    • \n\t
    • 1 <= m, n <= 40
    • \n\t
    • 1 <= k <= m*n
    • \n\t
    • grid[i][j] == 0 or 1
    • \n\t
    • grid[0][0] == grid[m-1][n-1] == 0
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a m * n \u7684\u7f51\u683c\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5355\u5143\u683c\u4e0d\u662f 0\uff08\u7a7a\uff09\u5c31\u662f 1\uff08\u969c\u788d\u7269\uff09\u3002\u6bcf\u4e00\u6b65\uff0c\u60a8\u90fd\u53ef\u4ee5\u5728\u7a7a\u767d\u5355\u5143\u683c\u4e2d\u4e0a\u3001\u4e0b\u3001\u5de6\u3001\u53f3\u79fb\u52a8\u3002

    \n\n

    \u5982\u679c\u60a8 \u6700\u591a \u53ef\u4ee5\u6d88\u9664 k \u4e2a\u969c\u788d\u7269\uff0c\u8bf7\u627e\u51fa\u4ece\u5de6\u4e0a\u89d2 (0, 0) \u5230\u53f3\u4e0b\u89d2 (m-1, n-1) \u7684\u6700\u77ed\u8def\u5f84\uff0c\u5e76\u8fd4\u56de\u901a\u8fc7\u8be5\u8def\u5f84\u6240\u9700\u7684\u6b65\u6570\u3002\u5982\u679c\u627e\u4e0d\u5230\u8fd9\u6837\u7684\u8def\u5f84\uff0c\u5219\u8fd4\u56de -1\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a \ngrid = \n[[0,0,0],\n [1,1,0],\n [0,0,0],\n [0,1,1],\n [0,0,0]], \nk = 1\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\n\u4e0d\u6d88\u9664\u4efb\u4f55\u969c\u788d\u7684\u6700\u77ed\u8def\u5f84\u662f 10\u3002\n\u6d88\u9664\u4f4d\u7f6e (3,2) \u5904\u7684\u969c\u788d\u540e\uff0c\u6700\u77ed\u8def\u5f84\u662f 6 \u3002\u8be5\u8def\u5f84\u662f (0,0) -> (0,1) -> (0,2) -> (1,2) -> (2,2) -> (3,2) -> (4,2).\n
    \n\n

     

    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a\ngrid = \n[[0,1,1],\n [1,1,1],\n [1,0,0]], \nk = 1\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\n\u6211\u4eec\u81f3\u5c11\u9700\u8981\u6d88\u9664\u4e24\u4e2a\u969c\u788d\u624d\u80fd\u627e\u5230\u8fd9\u6837\u7684\u8def\u5f84\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • grid.length == m
    • \n\t
    • grid[0].length == n
    • \n\t
    • 1 <= m, n <= 40
    • \n\t
    • 1 <= k <= m*n
    • \n\t
    • grid[i][j] == 0 or 1
    • \n\t
    • grid[0][0] == grid[m-1][n-1] == 0
    • \n
    \n", "tags_en": ["Breadth-first Search"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int shortestPath(vector>& grid, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int shortestPath(int[][] grid, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def shortestPath(self, grid, k):\n \"\"\"\n :type grid: List[List[int]]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def shortestPath(self, grid: List[List[int]], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint shortestPath(int** grid, int gridSize, int* gridColSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ShortestPath(int[][] grid, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @param {number} k\n * @return {number}\n */\nvar shortestPath = function(grid, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @param {Integer} k\n# @return {Integer}\ndef shortest_path(grid, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func shortestPath(_ grid: [[Int]], _ k: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func shortestPath(grid [][]int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def shortestPath(grid: Array[Array[Int]], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun shortestPath(grid: Array, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn shortest_path(grid: Vec>, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @param Integer $k\n * @return Integer\n */\n function shortestPath($grid, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function shortestPath(grid: number[][], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (shortest-path grid k)\n (-> (listof (listof exact-integer?)) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1293](https://leetcode-cn.com/problems/shortest-path-in-a-grid-with-obstacles-elimination)", "[\u7f51\u683c\u4e2d\u7684\u6700\u77ed\u8def\u5f84](/solution/1200-1299/1293.Shortest%20Path%20in%20a%20Grid%20with%20Obstacles%20Elimination/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[1293](https://leetcode.com/problems/shortest-path-in-a-grid-with-obstacles-elimination)", "[Shortest Path in a Grid with Obstacles Elimination](/solution/1200-1299/1293.Shortest%20Path%20in%20a%20Grid%20with%20Obstacles%20Elimination/README_EN.md)", "`Breadth-first Search`", "Hard", ""]}, {"question_id": "1413", "frontend_question_id": "1292", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-side-length-of-a-square-with-sum-less-than-or-equal-to-threshold", "url_en": "https://leetcode.com/problems/maximum-side-length-of-a-square-with-sum-less-than-or-equal-to-threshold", "relative_path_cn": "/solution/1200-1299/1292.Maximum%20Side%20Length%20of%20a%20Square%20with%20Sum%20Less%20than%20or%20Equal%20to%20Threshold/README.md", "relative_path_en": "/solution/1200-1299/1292.Maximum%20Side%20Length%20of%20a%20Square%20with%20Sum%20Less%20than%20or%20Equal%20to%20Threshold/README_EN.md", "title_cn": "\u5143\u7d20\u548c\u5c0f\u4e8e\u7b49\u4e8e\u9608\u503c\u7684\u6b63\u65b9\u5f62\u7684\u6700\u5927\u8fb9\u957f", "title_en": "Maximum Side Length of a Square with Sum Less than or Equal to Threshold", "question_title_slug": "maximum-side-length-of-a-square-with-sum-less-than-or-equal-to-threshold", "content_en": "

    Given a m x n matrix mat and an integer threshold. Return the maximum side-length of a square with a sum less than or equal to threshold or return 0 if there is no such square.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: mat = [[1,1,3,2,4,3,2],[1,1,3,2,4,3,2],[1,1,3,2,4,3,2]], threshold = 4\nOutput: 2\nExplanation: The maximum side length of square with sum less than 4 is 2 as shown.\n
    \n\n

    Example 2:

    \n\n
    \nInput: mat = [[2,2,2,2,2],[2,2,2,2,2],[2,2,2,2,2],[2,2,2,2,2],[2,2,2,2,2]], threshold = 1\nOutput: 0\n
    \n\n

    Example 3:

    \n\n
    \nInput: mat = [[1,1,1,1],[1,0,0,0],[1,0,0,0],[1,0,0,0]], threshold = 6\nOutput: 3\n
    \n\n

    Example 4:

    \n\n
    \nInput: mat = [[18,70],[61,1],[25,85],[14,40],[11,96],[97,96],[63,45]], threshold = 40184\nOutput: 2\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= m, n <= 300
    • \n\t
    • m == mat.length
    • \n\t
    • n == mat[i].length
    • \n\t
    • 0 <= mat[i][j] <= 10000
    • \n\t
    • 0 <= threshold <= 10^5
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5927\u5c0f\u4e3a\u00a0m x n\u00a0\u7684\u77e9\u9635\u00a0mat\u00a0\u548c\u4e00\u4e2a\u6574\u6570\u9608\u503c\u00a0threshold\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u5143\u7d20\u603b\u548c\u5c0f\u4e8e\u6216\u7b49\u4e8e\u9608\u503c\u7684\u6b63\u65b9\u5f62\u533a\u57df\u7684\u6700\u5927\u8fb9\u957f\uff1b\u5982\u679c\u6ca1\u6709\u8fd9\u6837\u7684\u6b63\u65b9\u5f62\u533a\u57df\uff0c\u5219\u8fd4\u56de 0\u00a0\u3002
    \n\u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1amat = [[1,1,3,2,4,3,2],[1,1,3,2,4,3,2],[1,1,3,2,4,3,2]], threshold = 4\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u603b\u548c\u5c0f\u4e8e\u6216\u7b49\u4e8e 4 \u7684\u6b63\u65b9\u5f62\u7684\u6700\u5927\u8fb9\u957f\u4e3a 2\uff0c\u5982\u56fe\u6240\u793a\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1amat = [[2,2,2,2,2],[2,2,2,2,2],[2,2,2,2,2],[2,2,2,2,2],[2,2,2,2,2]], threshold = 1\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1amat = [[1,1,1,1],[1,0,0,0],[1,0,0,0],[1,0,0,0]], threshold = 6\n\u8f93\u51fa\uff1a3\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1amat = [[18,70],[61,1],[25,85],[14,40],[11,96],[97,96],[63,45]], threshold = 40184\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= m, n <= 300
    • \n\t
    • m == mat.length
    • \n\t
    • n == mat[i].length
    • \n\t
    • 0 <= mat[i][j] <= 10000
    • \n\t
    • 0 <= threshold\u00a0<= 10^5
    • \n
    \n", "tags_en": ["Array", "Binary Search"], "tags_cn": ["\u6570\u7ec4", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxSideLength(vector>& mat, int threshold) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxSideLength(int[][] mat, int threshold) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxSideLength(self, mat, threshold):\n \"\"\"\n :type mat: List[List[int]]\n :type threshold: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxSideLength(self, mat: List[List[int]], threshold: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxSideLength(int** mat, int matSize, int* matColSize, int threshold){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxSideLength(int[][] mat, int threshold) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} mat\n * @param {number} threshold\n * @return {number}\n */\nvar maxSideLength = function(mat, threshold) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} mat\n# @param {Integer} threshold\n# @return {Integer}\ndef max_side_length(mat, threshold)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxSideLength(_ mat: [[Int]], _ threshold: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxSideLength(mat [][]int, threshold int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxSideLength(mat: Array[Array[Int]], threshold: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxSideLength(mat: Array, threshold: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_side_length(mat: Vec>, threshold: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $mat\n * @param Integer $threshold\n * @return Integer\n */\n function maxSideLength($mat, $threshold) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxSideLength(mat: number[][], threshold: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-side-length mat threshold)\n (-> (listof (listof exact-integer?)) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1292](https://leetcode-cn.com/problems/maximum-side-length-of-a-square-with-sum-less-than-or-equal-to-threshold)", "[\u5143\u7d20\u548c\u5c0f\u4e8e\u7b49\u4e8e\u9608\u503c\u7684\u6b63\u65b9\u5f62\u7684\u6700\u5927\u8fb9\u957f](/solution/1200-1299/1292.Maximum%20Side%20Length%20of%20a%20Square%20with%20Sum%20Less%20than%20or%20Equal%20to%20Threshold/README.md)", "`\u6570\u7ec4`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1292](https://leetcode.com/problems/maximum-side-length-of-a-square-with-sum-less-than-or-equal-to-threshold)", "[Maximum Side Length of a Square with Sum Less than or Equal to Threshold](/solution/1200-1299/1292.Maximum%20Side%20Length%20of%20a%20Square%20with%20Sum%20Less%20than%20or%20Equal%20to%20Threshold/README_EN.md)", "`Array`,`Binary Search`", "Medium", ""]}, {"question_id": "1411", "frontend_question_id": "1290", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/convert-binary-number-in-a-linked-list-to-integer", "url_en": "https://leetcode.com/problems/convert-binary-number-in-a-linked-list-to-integer", "relative_path_cn": "/solution/1200-1299/1290.Convert%20Binary%20Number%20in%20a%20Linked%20List%20to%20Integer/README.md", "relative_path_en": "/solution/1200-1299/1290.Convert%20Binary%20Number%20in%20a%20Linked%20List%20to%20Integer/README_EN.md", "title_cn": "\u4e8c\u8fdb\u5236\u94fe\u8868\u8f6c\u6574\u6570", "title_en": "Convert Binary Number in a Linked List to Integer", "question_title_slug": "convert-binary-number-in-a-linked-list-to-integer", "content_en": "

    Given head which is a reference node to a singly-linked list. The value of each node in the linked list is either 0 or 1. The linked list holds the binary representation of a number.

    \r\n\r\n

    Return the decimal value of the number in the linked list.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\"\"\r\n
    \r\nInput: head = [1,0,1]\r\nOutput: 5\r\nExplanation: (101) in base 2 = (5) in base 10\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: head = [0]\r\nOutput: 0\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: head = [1]\r\nOutput: 1\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: head = [1,0,0,1,0,0,1,1,1,0,0,0,0,0,0]\r\nOutput: 18880\r\n
    \r\n\r\n

    Example 5:

    \r\n\r\n
    \r\nInput: head = [0,0]\r\nOutput: 0\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • The Linked List is not empty.
    • \r\n\t
    • Number of nodes will not exceed 30.
    • \r\n\t
    • Each node's value is either 0 or 1.
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5355\u94fe\u8868\u7684\u5f15\u7528\u7ed3\u70b9 head\u3002\u94fe\u8868\u4e2d\u6bcf\u4e2a\u7ed3\u70b9\u7684\u503c\u4e0d\u662f 0 \u5c31\u662f 1\u3002\u5df2\u77e5\u6b64\u94fe\u8868\u662f\u4e00\u4e2a\u6574\u6570\u6570\u5b57\u7684\u4e8c\u8fdb\u5236\u8868\u793a\u5f62\u5f0f\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u8be5\u94fe\u8868\u6240\u8868\u793a\u6570\u5b57\u7684 \u5341\u8fdb\u5236\u503c \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1ahead = [1,0,1]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u4e8c\u8fdb\u5236\u6570 (101) \u8f6c\u5316\u4e3a\u5341\u8fdb\u5236\u6570 (5)\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1ahead = [0]\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1ahead = [1]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1ahead = [1,0,0,1,0,0,1,1,1,0,0,0,0,0,0]\n\u8f93\u51fa\uff1a18880\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1ahead = [0,0]\n\u8f93\u51fa\uff1a0\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u94fe\u8868\u4e0d\u4e3a\u7a7a\u3002
    • \n\t
    • \u94fe\u8868\u7684\u7ed3\u70b9\u603b\u6570\u4e0d\u8d85\u8fc7 30\u3002
    • \n\t
    • \u6bcf\u4e2a\u7ed3\u70b9\u7684\u503c\u4e0d\u662f 0 \u5c31\u662f 1\u3002
    • \n
    \n", "tags_en": ["Bit Manipulation", "Linked List"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u94fe\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\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 int getDecimalValue(ListNode* head) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode(int x) { val = x; }\n * }\n */\nclass Solution {\n public int getDecimalValue(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.next = None\n\nclass Solution(object):\n def getDecimalValue(self, head):\n \"\"\"\n :type head: ListNode\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, x):\n# self.val = x\n# self.next = None\n\nclass Solution:\n def getDecimalValue(self, head: ListNode) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nint getDecimalValue(struct ListNode* head){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int x) { val = x; }\n * }\n */\npublic class Solution {\n public int GetDecimalValue(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val) {\n * this.val = val;\n * this.next = null;\n * }\n */\n/**\n * @param {ListNode} head\n * @return {number}\n */\nvar getDecimalValue = function(head) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val)\n# @val = val\n# @next = nil\n# end\n# end\n\n# @param {ListNode} head\n# @return {Integer}\ndef get_decimal_value(head)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.next = nil\n * }\n * }\n */\nclass Solution {\n func getDecimalValue(_ head: ListNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc getDecimalValue(head *ListNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(var _x: Int = 0) {\n * var next: ListNode = null\n * var x: Int = _x\n * }\n */\nobject Solution {\n def getDecimalValue(head: ListNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun getDecimalValue(head: ListNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n// \n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn get_decimal_value(head: Option>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val) { $this->val = $val; }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @return Integer\n */\n function getDecimalValue($head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction getDecimalValue(head: ListNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (get-decimal-value head)\n (-> (or/c list-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1290](https://leetcode-cn.com/problems/convert-binary-number-in-a-linked-list-to-integer)", "[\u4e8c\u8fdb\u5236\u94fe\u8868\u8f6c\u6574\u6570](/solution/1200-1299/1290.Convert%20Binary%20Number%20in%20a%20Linked%20List%20to%20Integer/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u94fe\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[1290](https://leetcode.com/problems/convert-binary-number-in-a-linked-list-to-integer)", "[Convert Binary Number in a Linked List to Integer](/solution/1200-1299/1290.Convert%20Binary%20Number%20in%20a%20Linked%20List%20to%20Integer/README_EN.md)", "`Bit Manipulation`,`Linked List`", "Easy", ""]}, {"question_id": "1410", "frontend_question_id": "1279", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/traffic-light-controlled-intersection", "url_en": "https://leetcode.com/problems/traffic-light-controlled-intersection", "relative_path_cn": "/solution/1200-1299/1279.Traffic%20Light%20Controlled%20Intersection/README.md", "relative_path_en": "/solution/1200-1299/1279.Traffic%20Light%20Controlled%20Intersection/README_EN.md", "title_cn": "\u7ea2\u7eff\u706f\u8def\u53e3", "title_en": "Traffic Light Controlled Intersection", "question_title_slug": "traffic-light-controlled-intersection", "content_en": "

    There is an intersection of two roads. First road is road A where cars travel from North to South in direction 1 and from South to North in direction 2. Second road is road B where cars travel from West to East in direction 3 and from East to West in direction 4.

    \n\n

    \"\"

    \n\n

    There is a traffic light located on each road before the intersection. A traffic light can either be green or red.

    \n\n
      \n\t
    1. Green means cars can cross the intersection in both directions of the road.
    2. \n\t
    3. Red means cars in both directions cannot cross the intersection and must wait until the light turns green.
    4. \n
    \n\n

    The traffic lights cannot be green on both roads at the same time. That means when the light is green on road A, it is red on road B and when the light is green on road B, it is red on road A.

    \n\n

    Initially, the traffic light is green on road A and red on road B. When the light is green on one road, all cars can cross the intersection in both directions until the light becomes green on the other road. No two cars traveling on different roads should cross at the same time.

    \n\n

    Design a deadlock-free traffic light controlled system at this intersection.

    \n\n

    Implement the function void carArrived(carId, roadId, direction, turnGreen, crossCar) where:

    \n\n
      \n\t
    • carId is the id of the car that arrived.
    • \n\t
    • roadId is the id of the road that the car travels on.
    • \n\t
    • direction is the direction of the car.
    • \n\t
    • turnGreen is a function you can call to turn the traffic light to green on the current road.
    • \n\t
    • crossCar is a function you can call to let the current car cross the intersection.
    • \n
    \n\n

    Your answer is considered correct if it avoids cars deadlock in the intersection. Turning the light green on a road when it was already green is considered a wrong answer.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: cars = [1,3,5,2,4], directions = [2,1,2,4,3], arrivalTimes = [10,20,30,40,50]\nOutput: [\n"Car 1 Has Passed Road A In Direction 2",    // Traffic light on road A is green, car 1 can cross the intersection.\n"Car 3 Has Passed Road A In Direction 1",    // Car 3 crosses the intersection as the light is still green.\n"Car 5 Has Passed Road A In Direction 2",    // Car 5 crosses the intersection as the light is still green.\n"Traffic Light On Road B Is Green",          // Car 2 requests green light for road B.\n"Car 2 Has Passed Road B In Direction 4",    // Car 2 crosses as the light is green on road B now.\n"Car 4 Has Passed Road B In Direction 3"     // Car 4 crosses the intersection as the light is still green.\n]\n
    \n\n

    Example 2:

    \n\n
    \nInput: cars = [1,2,3,4,5], directions = [2,4,3,3,1], arrivalTimes = [10,20,30,40,40]\nOutput: [\n"Car 1 Has Passed Road A In Direction 2",    // Traffic light on road A is green, car 1 can cross the intersection.\n"Traffic Light On Road B Is Green",          // Car 2 requests green light for road B.\n"Car 2 Has Passed Road B In Direction 4",    // Car 2 crosses as the light is green on road B now.\n"Car 3 Has Passed Road B In Direction 3",    // Car 3 crosses as the light is green on road B now.\n"Traffic Light On Road A Is Green",          // Car 5 requests green light for road A.\n"Car 5 Has Passed Road A In Direction 1",    // Car 5 crosses as the light is green on road A now.\n"Traffic Light On Road B Is Green",          // Car 4 requests green light for road B. Car 4 blocked until car 5 crosses and then traffic light is green on road B.\n"Car 4 Has Passed Road B In Direction 3"     // Car 4 crosses as the light is green on road B now.\n]\nExplanation: This is a dead-lock free scenario. Note that the scenario when car 4 crosses before turning light into green on road A and allowing car 5 to pass is also correct and Accepted scenario.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= cars.length <= 20
    • \n\t
    • cars.length = directions.length
    • \n\t
    • cars.length = arrivalTimes.length
    • \n\t
    • All values of cars are unique
    • \n\t
    • 1 <= directions[i] <= 4
    • \n\t
    • arrivalTimes is non-decreasing
    • \n
    \n", "content_cn": "

    \u8fd9\u662f\u4e24\u6761\u8def\u7684\u4ea4\u53c9\u8def\u53e3\u3002\u7b2c\u4e00\u6761\u8def\u662f A \u8def\uff0c\u8f66\u8f86\u53ef\u6cbf 1 \u53f7\u65b9\u5411\u7531\u5317\u5411\u5357\u884c\u9a76\uff0c\u4e5f\u53ef\u6cbf 2 \u53f7\u65b9\u5411\u7531\u5357\u5411\u5317\u884c\u9a76\u3002\u7b2c\u4e8c\u6761\u8def\u662f B \u8def\uff0c\u8f66\u8f86\u53ef\u6cbf 3 \u53f7\u65b9\u5411\u7531\u897f\u5411\u4e1c\u884c\u9a76\uff0c\u4e5f\u53ef\u6cbf 4 \u53f7\u65b9\u5411\u7531\u4e1c\u5411\u897f\u884c\u9a76\u3002

    \n\n

    \"\"

    \n\n

    \u6bcf\u6761\u8def\u5728\u8def\u53e3\u524d\u90fd\u6709\u4e00\u4e2a\u7ea2\u7eff\u706f\u3002\u7ea2\u7eff\u706f\u53ef\u4ee5\u4eae\u8d77\u7ea2\u706f\u6216\u7eff\u706f\u3002

    \n\n
      \n\t
    1. \u7eff\u706f\u8868\u793a\u4e24\u4e2a\u65b9\u5411\u7684\u8f66\u8f86\u90fd\u53ef\u901a\u8fc7\u8def\u53e3\u3002
    2. \n\t
    3. \u7ea2\u706f\u8868\u793a\u4e24\u4e2a\u65b9\u5411\u7684\u8f66\u8f86\u90fd\u4e0d\u53ef\u4ee5\u901a\u8fc7\u8def\u53e3\uff0c\u5fc5\u987b\u7b49\u5f85\u7eff\u706f\u4eae\u8d77\u3002
    4. \n
    \n\n

    \u4e24\u6761\u8def\u4e0a\u7684\u7ea2\u7eff\u706f\u4e0d\u53ef\u4ee5\u540c\u65f6\u4e3a\u7eff\u706f\u3002\u8fd9\u610f\u5473\u7740\uff0c\u5f53 A \u8def\u4e0a\u7684\u7eff\u706f\u4eae\u8d77\u65f6\uff0cB \u8def\u4e0a\u7684\u7ea2\u706f\u4f1a\u4eae\u8d77\uff1b\u5f53 B \u8def\u4e0a\u7684\u7eff\u706f\u4eae\u8d77\u65f6\uff0cA \u8def\u4e0a\u7684\u7ea2\u706f\u4f1a\u4eae\u8d77.

    \n\n

    \u5f00\u59cb\u65f6\uff0cA \u8def\u4e0a\u7684\u7eff\u706f\u4eae\u8d77\uff0cB \u8def\u4e0a\u7684\u7ea2\u706f\u4eae\u8d77\u3002\u5f53\u4e00\u6761\u8def\u4e0a\u7684\u7eff\u706f\u4eae\u8d77\u65f6\uff0c\u6240\u6709\u8f66\u8f86\u90fd\u53ef\u4ee5\u4ece\u4efb\u610f\u4e24\u4e2a\u65b9\u5411\u901a\u8fc7\u8def\u53e3\uff0c\u76f4\u5230\u53e6\u4e00\u6761\u8def\u4e0a\u7684\u7eff\u706f\u4eae\u8d77\u3002\u4e0d\u540c\u8def\u4e0a\u7684\u8f66\u8f86\u4e0d\u53ef\u4ee5\u540c\u65f6\u901a\u8fc7\u8def\u53e3\u3002

    \n\n

    \u7ed9\u8fd9\u4e2a\u8def\u53e3\u8bbe\u8ba1\u4e00\u4e2a\u6ca1\u6709\u6b7b\u9501\u7684\u7ea2\u7eff\u706f\u63a7\u5236\u7cfb\u7edf\u3002

    \n\n

    \u5b9e\u73b0\u51fd\u6570 void carArrived(carId, roadId, direction, turnGreen, crossCar) :

    \n\n
      \n\t
    • carId \u4e3a\u5230\u8fbe\u8f66\u8f86\u7684\u7f16\u53f7\u3002
    • \n\t
    • roadId \u4e3a\u8f66\u8f86\u6240\u5728\u9053\u8def\u7684\u7f16\u53f7\u3002
    • \n\t
    • direction \u4e3a\u8f66\u8f86\u7684\u884c\u8fdb\u65b9\u5411\u3002
    • \n\t
    • turnGreen \u662f\u4e00\u4e2a\u51fd\u6570\uff0c\u8c03\u7528\u6b64\u51fd\u6570\u4f1a\u4f7f\u5f53\u524d\u9053\u8def\u4e0a\u7684\u7eff\u706f\u4eae\u8d77\u3002
    • \n\t
    • crossCar \u662f\u4e00\u4e2a\u51fd\u6570\uff0c\u8c03\u7528\u6b64\u51fd\u6570\u4f1a\u5141\u8bb8\u8f66\u8f86\u901a\u8fc7\u8def\u53e3\u3002
    • \n
    \n\n

    \u5f53\u4f60\u7684\u7b54\u6848\u907f\u514d\u4e86\u8f66\u8f86\u5728\u8def\u53e3\u51fa\u73b0\u6b7b\u9501\uff0c\u6b64\u7b54\u6848\u4f1a\u88ab\u8ba4\u5b9a\u4e3a\u6b63\u786e\u7684\u3002\u5f53\u8def\u53e3\u5df2\u7ecf\u4eae\u8d77\u7eff\u706f\u65f6\u4ecd\u6253\u5f00\u7eff\u706f\uff0c\u6b64\u7b54\u6848\u4f1a\u88ab\u8ba4\u5b9a\u4e3a\u9519\u8bef\u7684\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: cars = [1,3,5,2,4], directions = [2,1,2,4,3], arrivalTimes = [10,20,30,40,50]\n\u8f93\u51fa: [\n"Car 1 Has Passed Road A In Direction 2",    // A \u8def\u4e0a\u7684\u7ea2\u7eff\u706f\u4e3a\u7eff\u8272\uff0c1 \u53f7\u8f66\u53ef\u901a\u8fc7\u8def\u53e3\u3002\n"Car 3 Has Passed Road A In Direction 1",    // \u7ea2\u7eff\u706f\u4ecd\u4e3a\u7eff\u8272\uff0c3 \u53f7\u8f66\u901a\u8fc7\u8def\u53e3\u3002\n"Car 5 Has Passed Road A In Direction 2",    // \u7ea2\u7eff\u706f\u4ecd\u4e3a\u7eff\u8272\uff0c5 \u53f7\u8f66\u901a\u8fc7\u8def\u53e3\u3002\n"Traffic Light On Road B Is Green",          // 2 \u53f7\u8f66\u5728 B \u8def\u8bf7\u6c42\u7eff\u706f\u3002\n"Car 2 Has Passed Road B In Direction 4",    // B \u8def\u4e0a\u7684\u7eff\u706f\u73b0\u5df2\u4eae\u8d77\uff0c2 \u53f7\u8f66\u901a\u8fc7\u8def\u53e3\u3002\n"Car 4 Has Passed Road B In Direction 3"     // \u7ea2\u7eff\u706f\u4ecd\u4e3a\u7eff\u8272\uff0c4 \u53f7\u8f66\u901a\u8fc7\u8def\u53e3\u3002\n]\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: cars = [1,2,3,4,5], directions = [2,4,3,3,1], arrivalTimes = [10,20,30,40,40]\n\u8f93\u51fa: [\n"Car 1 Has Passed Road A In Direction 2",    // A \u8def\u4e0a\u7684\u7ea2\u7eff\u706f\u4e3a\u7eff\u8272\uff0c1 \u53f7\u8f66\u53ef\u901a\u8fc7\u8def\u53e3\u3002\n"Traffic Light On Road B Is Green",          // 2 \u53f7\u8f66\u5728 B \u8def\u8bf7\u6c42\u7eff\u706f\u3002\n"Car 2 Has Passed Road B In Direction 4",    // B \u8def\u4e0a\u7684\u7eff\u706f\u73b0\u5df2\u4eae\u8d77\uff0c2 \u53f7\u8f66\u901a\u8fc7\u8def\u53e3\u3002\n"Car 3 Has Passed Road B In Direction 3",    // B \u8def\u4e0a\u7684\u7eff\u706f\u73b0\u5df2\u4eae\u8d77\uff0c3 \u53f7\u8f66\u901a\u8fc7\u8def\u53e3\u3002\n"Traffic Light On Road A Is Green",          // 5 \u53f7\u8f66\u5728 A \u8def\u8bf7\u6c42\u7eff\u706f\u3002\n"Car 5 Has Passed Road A In Direction 1",    // A \u8def\u4e0a\u7684\u7eff\u706f\u73b0\u5df2\u4eae\u8d77\uff0c5 \u53f7\u8f66\u901a\u8fc7\u8def\u53e3\u3002\n"Traffic Light On Road B Is Green",          // 4 \u53f7\u8f66\u5728 B \u8def\u8bf7\u6c42\u7eff\u706f\u30024 \u53f7\u8f66\u5728\u8def\u53e3\u7b49\u706f\uff0c\u76f4\u5230 5 \u53f7\u8f66\u901a\u8fc7\u8def\u53e3\uff0cB \u8def\u7684\u7eff\u706f\u4eae\u8d77\u3002\n"Car 4 Has Passed Road B In Direction 3"     // B \u8def\u4e0a\u7684\u7eff\u706f\u73b0\u5df2\u4eae\u8d77\uff0c4 \u53f7\u8f66\u901a\u8fc7\u8def\u53e3\u3002\n]\n\u89e3\u91ca: \u8fd9\u662f\u4e00\u4e2a\u65e0\u6b7b\u9501\u7684\u65b9\u6848\u3002\u6ce8\u610f\uff0c\u5728 A \u8def\u4e0a\u7684\u7eff\u706f\u4eae\u8d77\u30015 \u53f7\u8f66\u901a\u8fc7\u524d\u8ba9 4 \u53f7\u8f66\u901a\u8fc7\uff0c\u4e5f\u662f\u4e00\u4e2a\u6b63\u786e\u4e14\u53ef\u88ab\u63a5\u53d7\u7684\u65b9\u6848\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= cars.length <= 20
    • \n\t
    • cars.length = directions.length
    • \n\t
    • cars.length = arrivalTimes.length
    • \n\t
    • cars \u4e2d\u7684\u6240\u6709\u503c\u90fd\u662f\u552f\u4e00\u7684\u3002
    • \n\t
    • 1 <= directions[i] <= 4
    • \n\t
    • arrivalTimes \u662f\u975e\u9012\u51cf\u7684\u3002
    • \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class TrafficLight {\npublic:\n TrafficLight() {\n \n }\n\n void carArrived(\n int carId, // ID of the car\n int roadId, // ID of the road the car travels on. Can be 1 (road A) or 2 (road B)\n int direction, // Direction of the car\n function turnGreen, // Use turnGreen() to turn light to green on current road\n function crossCar // Use crossCar() to make car cross the intersection\n ) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class TrafficLight {\n\n public TrafficLight() {\n \n }\n \n public void carArrived(\n int carId, // ID of the car\n int roadId, // ID of the road the car travels on. Can be 1 (road A) or 2 (road B)\n int direction, // Direction of the car\n Runnable turnGreen, // Use turnGreen.run() to turn light to green on current road\n Runnable crossCar // Use crossCar.run() to make car cross the intersection \n ) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class TrafficLight(object):\n \n def __init__(self):\n pass\n\n def carArrived(self, carId, roadId, direction, turnGreen, crossCar):\n \"\"\"\n :type roadId: int --> // ID of the car\n :type carId: int --> // ID of the road the car travels on. Can be 1 (road A) or 2 (road B)\n :type direction: int --> // Direction of the car\n :type turnGreen: method --> // Use turnGreen() to turn light to green on current road\n :type crossCar: method --> // Use crossCar() to make car cross the intersection\n :rtype: void\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class TrafficLight:\n def __init__(self):\n pass\n\n def carArrived(\n self,\n carId: int, # ID of the car\n roadId: int, # ID of the road the car travels on. Can be 1 (road A) or 2 (road B)\n direction: int, # Direction of the car\n turnGreen: 'Callable[[], None]', # Use turnGreen() to turn light to green on current road\n crossCar: 'Callable[[], None]' # Use crossCar() to make car cross the intersection\n ) -> None:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class TrafficLight {\n \n public TrafficLight() {\n \n }\n \n public void CarArrived(\n int carId, // ID of the car\n int roadId, // ID of the road the car travels on. Can be 1 (road A) or 2 (road B)\n int direction, // Direction of the car\n Action turnGreen, // Use turnGreen() to turn light to green on current road\n Action crossCar // Use crossCar() to make car cross the intersection\n ) {\n \n }\n}", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1279](https://leetcode-cn.com/problems/traffic-light-controlled-intersection)", "[\u7ea2\u7eff\u706f\u8def\u53e3](/solution/1200-1299/1279.Traffic%20Light%20Controlled%20Intersection/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1279](https://leetcode.com/problems/traffic-light-controlled-intersection)", "[Traffic Light Controlled Intersection](/solution/1200-1299/1279.Traffic%20Light%20Controlled%20Intersection/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1409", "frontend_question_id": "1284", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-number-of-flips-to-convert-binary-matrix-to-zero-matrix", "url_en": "https://leetcode.com/problems/minimum-number-of-flips-to-convert-binary-matrix-to-zero-matrix", "relative_path_cn": "/solution/1200-1299/1284.Minimum%20Number%20of%20Flips%20to%20Convert%20Binary%20Matrix%20to%20Zero%20Matrix/README.md", "relative_path_en": "/solution/1200-1299/1284.Minimum%20Number%20of%20Flips%20to%20Convert%20Binary%20Matrix%20to%20Zero%20Matrix/README_EN.md", "title_cn": "\u8f6c\u5316\u4e3a\u5168\u96f6\u77e9\u9635\u7684\u6700\u5c11\u53cd\u8f6c\u6b21\u6570", "title_en": "Minimum Number of Flips to Convert Binary Matrix to Zero Matrix", "question_title_slug": "minimum-number-of-flips-to-convert-binary-matrix-to-zero-matrix", "content_en": "

    Given a m x n binary matrix mat. In one step, you can choose one cell and flip it and all the four neighbors of it if they exist (Flip is changing 1 to 0 and 0 to 1). A pair of cells are called neighbors if they share one edge.

    \n\n

    Return the minimum number of steps required to convert mat to a zero matrix or -1 if you cannot.

    \n\n

    A binary matrix is a matrix with all cells equal to 0 or 1 only.

    \n\n

    A zero matrix is a matrix with all cells equal to 0.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: mat = [[0,0],[0,1]]\nOutput: 3\nExplanation: One possible solution is to flip (1, 0) then (0, 1) and finally (1, 1) as shown.\n
    \n\n

    Example 2:

    \n\n
    \nInput: mat = [[0]]\nOutput: 0\nExplanation: Given matrix is a zero matrix. We don't need to change it.\n
    \n\n

    Example 3:

    \n\n
    \nInput: mat = [[1,1,1],[1,0,1],[0,0,0]]\nOutput: 6\n
    \n\n

    Example 4:

    \n\n
    \nInput: mat = [[1,0,0],[1,0,0]]\nOutput: -1\nExplanation: Given matrix can't be a zero matrix\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == mat.length
    • \n\t
    • n == mat[i].length
    • \n\t
    • 1 <= m, n <= 3
    • \n\t
    • mat[i][j] is either 0 or 1.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a m x n \u7684\u4e8c\u8fdb\u5236\u77e9\u9635 mat\u3002

    \n\n

    \u6bcf\u4e00\u6b65\uff0c\u4f60\u53ef\u4ee5\u9009\u62e9\u4e00\u4e2a\u5355\u5143\u683c\u5e76\u5c06\u5b83\u53cd\u8f6c\uff08\u53cd\u8f6c\u8868\u793a 0 \u53d8 1 \uff0c1 \u53d8 0 \uff09\u3002\u5982\u679c\u5b58\u5728\u548c\u5b83\u76f8\u90bb\u7684\u5355\u5143\u683c\uff0c\u90a3\u4e48\u8fd9\u4e9b\u76f8\u90bb\u7684\u5355\u5143\u683c\u4e5f\u4f1a\u88ab\u53cd\u8f6c\u3002\uff08\u6ce8\uff1a\u76f8\u90bb\u7684\u4e24\u4e2a\u5355\u5143\u683c\u5171\u4eab\u540c\u4e00\u6761\u8fb9\u3002\uff09

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u5c06\u77e9\u9635 mat \u8f6c\u5316\u4e3a\u5168\u96f6\u77e9\u9635\u7684\u6700\u5c11\u53cd\u8f6c\u6b21\u6570\uff0c\u5982\u679c\u65e0\u6cd5\u8f6c\u5316\u4e3a\u5168\u96f6\u77e9\u9635\uff0c\u8bf7\u8fd4\u56de -1 \u3002

    \n\n

    \u4e8c\u8fdb\u5236\u77e9\u9635\u7684\u6bcf\u4e00\u4e2a\u683c\u5b50\u8981\u4e48\u662f 0 \u8981\u4e48\u662f 1 \u3002

    \n\n

    \u5168\u96f6\u77e9\u9635\u662f\u6240\u6709\u683c\u5b50\u90fd\u4e3a 0 \u7684\u77e9\u9635\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1amat = [[0,0],[0,1]]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u4e00\u4e2a\u53ef\u80fd\u7684\u89e3\u662f\u53cd\u8f6c (1, 0)\uff0c\u7136\u540e (0, 1) \uff0c\u6700\u540e\u662f (1, 1) \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1amat = [[0]]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u7ed9\u51fa\u7684\u77e9\u9635\u662f\u5168\u96f6\u77e9\u9635\uff0c\u6240\u4ee5\u4f60\u4e0d\u9700\u8981\u6539\u53d8\u5b83\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1amat = [[1,1,1],[1,0,1],[0,0,0]]\n\u8f93\u51fa\uff1a6\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1amat = [[1,0,0],[1,0,0]]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u8be5\u77e9\u9635\u65e0\u6cd5\u8f6c\u53d8\u6210\u5168\u96f6\u77e9\u9635\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == mat.length
    • \n\t
    • n == mat[0].length
    • \n\t
    • 1 <= m <= 3
    • \n\t
    • 1 <= n <= 3
    • \n\t
    • mat[i][j] \u662f 0 \u6216 1 \u3002
    • \n
    \n", "tags_en": ["Breadth-first Search"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minFlips(vector>& mat) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minFlips(int[][] mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minFlips(self, mat):\n \"\"\"\n :type mat: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minFlips(self, mat: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minFlips(int** mat, int matSize, int* matColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinFlips(int[][] mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} mat\n * @return {number}\n */\nvar minFlips = function(mat) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} mat\n# @return {Integer}\ndef min_flips(mat)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minFlips(_ mat: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minFlips(mat [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minFlips(mat: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minFlips(mat: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_flips(mat: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $mat\n * @return Integer\n */\n function minFlips($mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minFlips(mat: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-flips mat)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1284](https://leetcode-cn.com/problems/minimum-number-of-flips-to-convert-binary-matrix-to-zero-matrix)", "[\u8f6c\u5316\u4e3a\u5168\u96f6\u77e9\u9635\u7684\u6700\u5c11\u53cd\u8f6c\u6b21\u6570](/solution/1200-1299/1284.Minimum%20Number%20of%20Flips%20to%20Convert%20Binary%20Matrix%20to%20Zero%20Matrix/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[1284](https://leetcode.com/problems/minimum-number-of-flips-to-convert-binary-matrix-to-zero-matrix)", "[Minimum Number of Flips to Convert Binary Matrix to Zero Matrix](/solution/1200-1299/1284.Minimum%20Number%20of%20Flips%20to%20Convert%20Binary%20Matrix%20to%20Zero%20Matrix/README_EN.md)", "`Breadth-first Search`", "Hard", ""]}, {"question_id": "1408", "frontend_question_id": "1283", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-the-smallest-divisor-given-a-threshold", "url_en": "https://leetcode.com/problems/find-the-smallest-divisor-given-a-threshold", "relative_path_cn": "/solution/1200-1299/1283.Find%20the%20Smallest%20Divisor%20Given%20a%20Threshold/README.md", "relative_path_en": "/solution/1200-1299/1283.Find%20the%20Smallest%20Divisor%20Given%20a%20Threshold/README_EN.md", "title_cn": "\u4f7f\u7ed3\u679c\u4e0d\u8d85\u8fc7\u9608\u503c\u7684\u6700\u5c0f\u9664\u6570", "title_en": "Find the Smallest Divisor Given a Threshold", "question_title_slug": "find-the-smallest-divisor-given-a-threshold", "content_en": "

    Given an array of integers nums and an integer threshold, we will choose a positive integer divisor, divide all the array by it, and sum the division's result. Find the smallest divisor such that the result mentioned above is less than or equal to threshold.

    \n\n

    Each result of the division is rounded to the nearest integer greater than or equal to that element. (For example: 7/3 = 3 and 10/2 = 5).

    \n\n

    It is guaranteed that there will be an answer.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,5,9], threshold = 6\nOutput: 5\nExplanation: We can get a sum to 17 (1+2+5+9) if the divisor is 1. \nIf the divisor is 4 we can get a sum of 7 (1+1+2+3) and if the divisor is 5 the sum will be 5 (1+1+1+2). \n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [44,22,33,11,1], threshold = 5\nOutput: 44\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [21212,10101,12121], threshold = 1000000\nOutput: 1\n
    \n\n

    Example 4:

    \n\n
    \nInput: nums = [2,3,5,7,11], threshold = 11\nOutput: 3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 5 * 104
    • \n\t
    • 1 <= nums[i] <= 106
    • \n\t
    • nums.length <= threshold <= 106
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \u548c\u4e00\u4e2a\u6b63\u6574\u6570 threshold  \uff0c\u4f60\u9700\u8981\u9009\u62e9\u4e00\u4e2a\u6b63\u6574\u6570\u4f5c\u4e3a\u9664\u6570\uff0c\u7136\u540e\u5c06\u6570\u7ec4\u91cc\u6bcf\u4e2a\u6570\u90fd\u9664\u4ee5\u5b83\uff0c\u5e76\u5bf9\u9664\u6cd5\u7ed3\u679c\u6c42\u548c\u3002

    \n\n

    \u8bf7\u4f60\u627e\u51fa\u80fd\u591f\u4f7f\u4e0a\u8ff0\u7ed3\u679c\u5c0f\u4e8e\u7b49\u4e8e\u9608\u503c threshold \u7684\u9664\u6570\u4e2d \u6700\u5c0f \u7684\u90a3\u4e2a\u3002

    \n\n

    \u6bcf\u4e2a\u6570\u9664\u4ee5\u9664\u6570\u540e\u90fd\u5411\u4e0a\u53d6\u6574\uff0c\u6bd4\u65b9\u8bf4 7/3 = 3 \uff0c 10/2 = 5 \u3002

    \n\n

    \u9898\u76ee\u4fdd\u8bc1\u4e00\u5b9a\u6709\u89e3\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,5,9], threshold = 6\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u5982\u679c\u9664\u6570\u4e3a 1 \uff0c\u6211\u4eec\u53ef\u4ee5\u5f97\u5230\u548c\u4e3a 17 \uff081+2+5+9\uff09\u3002\n\u5982\u679c\u9664\u6570\u4e3a 4 \uff0c\u6211\u4eec\u53ef\u4ee5\u5f97\u5230\u548c\u4e3a 7 (1+1+2+3) \u3002\u5982\u679c\u9664\u6570\u4e3a 5 \uff0c\u548c\u4e3a 5 (1+1+1+2)\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [2,3,5,7,11], threshold = 11\n\u8f93\u51fa\uff1a3\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [19], threshold = 5\n\u8f93\u51fa\uff1a4\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 5 * 10^4
    • \n\t
    • 1 <= nums[i] <= 10^6
    • \n\t
    • nums.length <= threshold <= 10^6
    • \n
    \n", "tags_en": ["Binary Search"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int smallestDivisor(vector& nums, int threshold) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int smallestDivisor(int[] nums, int threshold) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def smallestDivisor(self, nums, threshold):\n \"\"\"\n :type nums: List[int]\n :type threshold: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def smallestDivisor(self, nums: List[int], threshold: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint smallestDivisor(int* nums, int numsSize, int threshold){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SmallestDivisor(int[] nums, int threshold) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} threshold\n * @return {number}\n */\nvar smallestDivisor = function(nums, threshold) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} threshold\n# @return {Integer}\ndef smallest_divisor(nums, threshold)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func smallestDivisor(_ nums: [Int], _ threshold: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func smallestDivisor(nums []int, threshold int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def smallestDivisor(nums: Array[Int], threshold: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun smallestDivisor(nums: IntArray, threshold: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn smallest_divisor(nums: Vec, threshold: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $threshold\n * @return Integer\n */\n function smallestDivisor($nums, $threshold) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function smallestDivisor(nums: number[], threshold: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (smallest-divisor nums threshold)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1283](https://leetcode-cn.com/problems/find-the-smallest-divisor-given-a-threshold)", "[\u4f7f\u7ed3\u679c\u4e0d\u8d85\u8fc7\u9608\u503c\u7684\u6700\u5c0f\u9664\u6570](/solution/1200-1299/1283.Find%20the%20Smallest%20Divisor%20Given%20a%20Threshold/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1283](https://leetcode.com/problems/find-the-smallest-divisor-given-a-threshold)", "[Find the Smallest Divisor Given a Threshold](/solution/1200-1299/1283.Find%20the%20Smallest%20Divisor%20Given%20a%20Threshold/README_EN.md)", "`Binary Search`", "Medium", ""]}, {"question_id": "1407", "frontend_question_id": "1282", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/group-the-people-given-the-group-size-they-belong-to", "url_en": "https://leetcode.com/problems/group-the-people-given-the-group-size-they-belong-to", "relative_path_cn": "/solution/1200-1299/1282.Group%20the%20People%20Given%20the%20Group%20Size%20They%20Belong%20To/README.md", "relative_path_en": "/solution/1200-1299/1282.Group%20the%20People%20Given%20the%20Group%20Size%20They%20Belong%20To/README_EN.md", "title_cn": "\u7528\u6237\u5206\u7ec4", "title_en": "Group the People Given the Group Size They Belong To", "question_title_slug": "group-the-people-given-the-group-size-they-belong-to", "content_en": "

    There are n people that are split into some unknown number of groups. Each person is labeled with a unique ID from 0 to n - 1.

    \n\n

    You are given an integer array groupSizes, where groupSizes[i] is the size of the group that person i is in. For example, if groupSizes[1] = 3, then person 1 must be in a group of size 3.

    \n\n

    Return a list of groups such that each person i is in a group of size groupSizes[i].

    \n\n

    Each person should appear in exactly one group, and every person must be in a group. If there are multiple answers, return any of them. It is guaranteed that there will be at least one valid solution for the given input.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: groupSizes = [3,3,3,3,3,1,3]\nOutput: [[5],[0,1,2],[3,4,6]]\nExplanation: \nThe first group is [5]. The size is 1, and groupSizes[5] = 1.\nThe second group is [0,1,2]. The size is 3, and groupSizes[0] = groupSizes[1] = groupSizes[2] = 3.\nThe third group is [3,4,6]. The size is 3, and groupSizes[3] = groupSizes[4] = groupSizes[6] = 3.\nOther possible solutions are [[2,1,6],[5],[0,4,3]] and [[5],[0,6,2],[4,3,1]].\n
    \n\n

    Example 2:

    \n\n
    \nInput: groupSizes = [2,1,3,3,3,2]\nOutput: [[1],[0,5],[2,3,4]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • groupSizes.length == n
    • \n\t
    • 1 <= n <= 500
    • \n\t
    • 1 <= groupSizes[i] <= n
    • \n
    \n", "content_cn": "

    \u6709 n \u4f4d\u7528\u6237\u53c2\u52a0\u6d3b\u52a8\uff0c\u4ed6\u4eec\u7684 ID \u4ece 0 \u5230 n - 1\uff0c\u6bcf\u4f4d\u7528\u6237\u90fd \u6070\u597d \u5c5e\u4e8e\u67d0\u4e00\u7528\u6237\u7ec4\u3002\u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u6570\u7ec4 groupSizes\uff0c\u5176\u4e2d\u5305\u542b\u6bcf\u4f4d\u7528\u6237\u6240\u5904\u7684\u7528\u6237\u7ec4\u7684\u5927\u5c0f\uff0c\u8bf7\u4f60\u8fd4\u56de\u7528\u6237\u5206\u7ec4\u60c5\u51b5\uff08\u5b58\u5728\u7684\u7528\u6237\u7ec4\u4ee5\u53ca\u6bcf\u4e2a\u7ec4\u4e2d\u7528\u6237\u7684 ID\uff09\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u4efb\u4f55\u987a\u5e8f\u8fd4\u56de\u89e3\u51b3\u65b9\u6848\uff0cID \u7684\u987a\u5e8f\u4e5f\u4e0d\u53d7\u9650\u5236\u3002\u6b64\u5916\uff0c\u9898\u76ee\u7ed9\u51fa\u7684\u6570\u636e\u4fdd\u8bc1\u81f3\u5c11\u5b58\u5728\u4e00\u79cd\u89e3\u51b3\u65b9\u6848\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1agroupSizes = [3,3,3,3,3,1,3]\n\u8f93\u51fa\uff1a[[5],[0,1,2],[3,4,6]]\n\u89e3\u91ca\uff1a \n\u5176\u4ed6\u53ef\u80fd\u7684\u89e3\u51b3\u65b9\u6848\u6709 [[2,1,6],[5],[0,4,3]] \u548c [[5],[0,6,2],[4,3,1]]\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1agroupSizes = [2,1,3,3,3,2]\n\u8f93\u51fa\uff1a[[1],[0,5],[2,3,4]]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • groupSizes.length == n
    • \n\t
    • 1 <= n <= 500
    • \n\t
    • 1 <= groupSizes[i] <= n
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> groupThePeople(vector& groupSizes) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> groupThePeople(int[] groupSizes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def groupThePeople(self, groupSizes):\n \"\"\"\n :type groupSizes: List[int]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def groupThePeople(self, groupSizes: List[int]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** groupThePeople(int* groupSizes, int groupSizesSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> GroupThePeople(int[] groupSizes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} groupSizes\n * @return {number[][]}\n */\nvar groupThePeople = function(groupSizes) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} group_sizes\n# @return {Integer[][]}\ndef group_the_people(group_sizes)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func groupThePeople(_ groupSizes: [Int]) -> [[Int]] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func groupThePeople(groupSizes []int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def groupThePeople(groupSizes: Array[Int]): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun groupThePeople(groupSizes: IntArray): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn group_the_people(group_sizes: Vec) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $groupSizes\n * @return Integer[][]\n */\n function groupThePeople($groupSizes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function groupThePeople(groupSizes: number[]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (group-the-people groupSizes)\n (-> (listof exact-integer?) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1282](https://leetcode-cn.com/problems/group-the-people-given-the-group-size-they-belong-to)", "[\u7528\u6237\u5206\u7ec4](/solution/1200-1299/1282.Group%20the%20People%20Given%20the%20Group%20Size%20They%20Belong%20To/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1282](https://leetcode.com/problems/group-the-people-given-the-group-size-they-belong-to)", "[Group the People Given the Group Size They Belong To](/solution/1200-1299/1282.Group%20the%20People%20Given%20the%20Group%20Size%20They%20Belong%20To/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1406", "frontend_question_id": "1281", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer", "url_en": "https://leetcode.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer", "relative_path_cn": "/solution/1200-1299/1281.Subtract%20the%20Product%20and%20Sum%20of%20Digits%20of%20an%20Integer/README.md", "relative_path_en": "/solution/1200-1299/1281.Subtract%20the%20Product%20and%20Sum%20of%20Digits%20of%20an%20Integer/README_EN.md", "title_cn": "\u6574\u6570\u7684\u5404\u4f4d\u79ef\u548c\u4e4b\u5dee", "title_en": "Subtract the Product and Sum of Digits of an Integer", "question_title_slug": "subtract-the-product-and-sum-of-digits-of-an-integer", "content_en": "Given an integer number n, return the difference between the product of its digits and the sum of its digits.\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 234\nOutput: 15 \nExplanation: \nProduct of digits = 2 * 3 * 4 = 24 \nSum of digits = 2 + 3 + 4 = 9 \nResult = 24 - 9 = 15\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 4421\nOutput: 21\nExplanation: \nProduct of digits = 4 * 4 * 2 * 1 = 32 \nSum of digits = 4 + 4 + 2 + 1 = 11 \nResult = 32 - 11 = 21\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 10^5
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n\uff0c\u8bf7\u4f60\u5e2e\u5fd9\u8ba1\u7b97\u5e76\u8fd4\u56de\u8be5\u6574\u6570\u300c\u5404\u4f4d\u6570\u5b57\u4e4b\u79ef\u300d\u4e0e\u300c\u5404\u4f4d\u6570\u5b57\u4e4b\u548c\u300d\u7684\u5dee\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1an = 234\n\u8f93\u51fa\uff1a15 \n\u89e3\u91ca\uff1a\n\u5404\u4f4d\u6570\u4e4b\u79ef = 2 * 3 * 4 = 24 \n\u5404\u4f4d\u6570\u4e4b\u548c = 2 + 3 + 4 = 9 \n\u7ed3\u679c = 24 - 9 = 15\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1an = 4421\n\u8f93\u51fa\uff1a21\n\u89e3\u91ca\uff1a \n\u5404\u4f4d\u6570\u4e4b\u79ef = 4 * 4 * 2 * 1 = 32 \n\u5404\u4f4d\u6570\u4e4b\u548c = 4 + 4 + 2 + 1 = 11 \n\u7ed3\u679c = 32 - 11 = 21\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 10^5
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int subtractProductAndSum(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int subtractProductAndSum(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def subtractProductAndSum(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def subtractProductAndSum(self, n: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint subtractProductAndSum(int n){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SubtractProductAndSum(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar subtractProductAndSum = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef subtract_product_and_sum(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func subtractProductAndSum(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func subtractProductAndSum(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def subtractProductAndSum(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun subtractProductAndSum(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn subtract_product_and_sum(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function subtractProductAndSum($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function subtractProductAndSum(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (subtract-product-and-sum n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1281](https://leetcode-cn.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer)", "[\u6574\u6570\u7684\u5404\u4f4d\u79ef\u548c\u4e4b\u5dee](/solution/1200-1299/1281.Subtract%20the%20Product%20and%20Sum%20of%20Digits%20of%20an%20Integer/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[1281](https://leetcode.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer)", "[Subtract the Product and Sum of Digits of an Integer](/solution/1200-1299/1281.Subtract%20the%20Product%20and%20Sum%20of%20Digits%20of%20an%20Integer/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "1405", "frontend_question_id": "1270", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/all-people-report-to-the-given-manager", "url_en": "https://leetcode.com/problems/all-people-report-to-the-given-manager", "relative_path_cn": "/solution/1200-1299/1270.All%20People%20Report%20to%20the%20Given%20Manager/README.md", "relative_path_en": "/solution/1200-1299/1270.All%20People%20Report%20to%20the%20Given%20Manager/README_EN.md", "title_cn": "\u5411\u516c\u53f8CEO\u6c47\u62a5\u5de5\u4f5c\u7684\u6240\u6709\u4eba", "title_en": "All People Report to the Given Manager", "question_title_slug": "all-people-report-to-the-given-manager", "content_en": "

    Table: Employees

    \r\n\r\n
    \r\n+---------------+---------+\r\n| Column Name   | Type    |\r\n+---------------+---------+\r\n| employee_id   | int     |\r\n| employee_name | varchar |\r\n| manager_id    | int     |\r\n+---------------+---------+\r\nemployee_id is the primary key for this table.\r\nEach row of this table indicates that the employee with ID employee_id and name employee_name reports his work to his/her direct manager with manager_id\r\nThe head of the company is the employee with employee_id = 1.\r\n
    \r\n\r\n

     

    \r\n\r\n

    Write an SQL query to find employee_id of all employees that directly or indirectly report their work to the head of the company.

    \r\n\r\n

    The indirect relation between managers will not exceed 3 managers as the company is small.

    \r\n\r\n

    Return result table in any order without duplicates.

    \r\n\r\n

    The query result format is in the following example:

    \r\n\r\n
    \r\nEmployees table:\r\n+-------------+---------------+------------+\r\n| employee_id | employee_name | manager_id |\r\n+-------------+---------------+------------+\r\n| 1           | Boss          | 1          |\r\n| 3           | Alice         | 3          |\r\n| 2           | Bob           | 1          |\r\n| 4           | Daniel        | 2          |\r\n| 7           | Luis          | 4          |\r\n| 8           | Jhon          | 3          |\r\n| 9           | Angela        | 8          |\r\n| 77          | Robert        | 1          |\r\n+-------------+---------------+------------+\r\n\r\nResult table:\r\n+-------------+\r\n| employee_id |\r\n+-------------+\r\n| 2           |\r\n| 77          |\r\n| 4           |\r\n| 7           |\r\n+-------------+\r\n\r\nThe head of the company is the employee with employee_id 1.\r\nThe employees with employee_id 2 and 77 report their work directly to the head of the company.\r\nThe employee with employee_id 4 report his work indirectly to the head of the company 4 --> 2 --> 1. \r\nThe employee with employee_id 7 report his work indirectly to the head of the company 7 --> 4 --> 2 --> 1.\r\nThe employees with employee_id 3, 8 and 9 don't report their work to head of company directly or indirectly. \r\n
    ", "content_cn": "

    \u5458\u5de5\u8868\uff1aEmployees

    \n\n
    +---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| employee_id   | int     |\n| employee_name | varchar |\n| manager_id    | int     |\n+---------------+---------+\nemployee_id \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\u3002\n\u8fd9\u4e2a\u8868\u4e2d\u6bcf\u4e00\u884c\u4e2d\uff0cemployee_id \u8868\u793a\u804c\u5de5\u7684 ID\uff0cemployee_name \u8868\u793a\u804c\u5de5\u7684\u540d\u5b57\uff0cmanager_id \u8868\u793a\u8be5\u804c\u5de5\u6c47\u62a5\u5de5\u4f5c\u7684\u76f4\u7ebf\u7ecf\u7406\u3002\n\u8fd9\u4e2a\u516c\u53f8 CEO \u662f employee_id = 1 \u7684\u4eba\u3002\n
    \n\n

     

    \n\n

    \u7528 SQL \u67e5\u8be2\u51fa\u6240\u6709\u76f4\u63a5\u6216\u95f4\u63a5\u5411\u516c\u53f8 CEO \u6c47\u62a5\u5de5\u4f5c\u7684\u804c\u5de5\u7684 employee_id \u3002

    \n\n

    \u7531\u4e8e\u516c\u53f8\u89c4\u6a21\u8f83\u5c0f\uff0c\u7ecf\u7406\u4e4b\u95f4\u7684\u95f4\u63a5\u5173\u7cfb\u4e0d\u8d85\u8fc7 3 \u4e2a\u7ecf\u7406\u3002

    \n\n

    \u53ef\u4ee5\u4ee5\u4efb\u4f55\u987a\u5e8f\u8fd4\u56de\u7684\u7ed3\u679c\uff0c\u4e0d\u9700\u8981\u53bb\u91cd\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u793a\u4f8b\u5982\u4e0b\uff1a

    \n\n
    Employees table:\n+-------------+---------------+------------+\n| employee_id | employee_name | manager_id |\n+-------------+---------------+------------+\n| 1           | Boss          | 1          |\n| 3           | Alice         | 3          |\n| 2           | Bob           | 1          |\n| 4           | Daniel        | 2          |\n| 7           | Luis          | 4          |\n| 8           | Jhon          | 3          |\n| 9           | Angela        | 8          |\n| 77          | Robert        | 1          |\n+-------------+---------------+------------+\n\nResult table:\n+-------------+\n| employee_id |\n+-------------+\n| 2           |\n| 77          |\n| 4           |\n| 7           |\n+-------------+\n\n\u516c\u53f8 CEO \u7684 employee_id \u662f 1.\nemployee_id \u662f 2 \u548c 77 \u7684\u804c\u5458\u76f4\u63a5\u6c47\u62a5\u7ed9\u516c\u53f8 CEO\u3002\nemployee_id \u662f 4 \u7684\u804c\u5458\u95f4\u63a5\u6c47\u62a5\u7ed9\u516c\u53f8 CEO 4 --> 2 --> 1 \u3002\nemployee_id \u662f 7 \u7684\u804c\u5458\u95f4\u63a5\u6c47\u62a5\u7ed9\u516c\u53f8 CEO 7 --> 4 --> 2 --> 1 \u3002\nemployee_id \u662f 3, 8 \uff0c9 \u7684\u804c\u5458\u4e0d\u4f1a\u76f4\u63a5\u6216\u95f4\u63a5\u7684\u6c47\u62a5\u7ed9\u516c\u53f8 CEO\u3002 \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1270](https://leetcode-cn.com/problems/all-people-report-to-the-given-manager)", "[\u5411\u516c\u53f8CEO\u6c47\u62a5\u5de5\u4f5c\u7684\u6240\u6709\u4eba](/solution/1200-1299/1270.All%20People%20Report%20to%20the%20Given%20Manager/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1270](https://leetcode.com/problems/all-people-report-to-the-given-manager)", "[All People Report to the Given Manager](/solution/1200-1299/1270.All%20People%20Report%20to%20the%20Given%20Manager/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1404", "frontend_question_id": "1265", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/print-immutable-linked-list-in-reverse", "url_en": "https://leetcode.com/problems/print-immutable-linked-list-in-reverse", "relative_path_cn": "/solution/1200-1299/1265.Print%20Immutable%20Linked%20List%20in%20Reverse/README.md", "relative_path_en": "/solution/1200-1299/1265.Print%20Immutable%20Linked%20List%20in%20Reverse/README_EN.md", "title_cn": "\u9006\u5e8f\u6253\u5370\u4e0d\u53ef\u53d8\u94fe\u8868", "title_en": "Print Immutable Linked List in Reverse", "question_title_slug": "print-immutable-linked-list-in-reverse", "content_en": "

    You are given an immutable linked list, print out all values of each node in reverse with the help of the following interface:

    \n\n
      \n\t
    • ImmutableListNode: An interface of immutable linked list, you are given the head of the list.
    • \n
    \n\n

    You need to use the following functions to access the linked list (you can't access the ImmutableListNode directly):

    \n\n
      \n\t
    • ImmutableListNode.printValue(): Print value of the current node.
    • \n\t
    • ImmutableListNode.getNext(): Return the next node.
    • \n
    \n\n

    The input is only given to initialize the linked list internally. You must solve this problem without modifying the linked list. In other words, you must operate the linked list using only the mentioned APIs.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: head = [1,2,3,4]\nOutput: [4,3,2,1]\n
    \n\n

    Example 2:

    \n\n
    \nInput: head = [0,-4,-1,3,-5]\nOutput: [-5,3,-1,-4,0]\n
    \n\n

    Example 3:

    \n\n
    \nInput: head = [-2,0,6,4,4,-6]\nOutput: [-6,4,4,6,0,-2]\n
    \n\n
      \n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The length of the linked list is between [1, 1000].
    • \n\t
    • The value of each node in the linked list is between [-1000, 1000].
    • \n
    \n\n

     

    \n\n

    Follow up:

    \n\n

    Could you solve this problem in:

    \n\n
      \n\t
    • Constant space complexity?
    • \n\t
    • Linear time complexity and less than linear space complexity?
    • \n
    \n", "content_cn": "

    \u7ed9\u60a8\u4e00\u4e2a\u4e0d\u53ef\u53d8\u7684\u94fe\u8868\uff0c\u4f7f\u7528\u4e0b\u5217\u63a5\u53e3\u9006\u5e8f\u6253\u5370\u6bcf\u4e2a\u8282\u70b9\u7684\u503c\uff1a

    \n\n
      \n\t
    • ImmutableListNode: \u63cf\u8ff0\u4e0d\u53ef\u53d8\u94fe\u8868\u7684\u63a5\u53e3\uff0c\u94fe\u8868\u7684\u5934\u8282\u70b9\u5df2\u7ed9\u51fa\u3002
    • \n
    \n\n

    \u60a8\u9700\u8981\u4f7f\u7528\u4ee5\u4e0b\u51fd\u6570\u6765\u8bbf\u95ee\u6b64\u94fe\u8868\uff08\u60a8 \u4e0d\u80fd \u76f4\u63a5\u8bbf\u95ee ImmutableListNode\uff09\uff1a

    \n\n
      \n\t
    • ImmutableListNode.printValue()\uff1a\u6253\u5370\u5f53\u524d\u8282\u70b9\u7684\u503c\u3002
    • \n\t
    • ImmutableListNode.getNext()\uff1a\u8fd4\u56de\u4e0b\u4e00\u4e2a\u8282\u70b9\u3002
    • \n
    \n\n

    \u8f93\u5165\u53ea\u7528\u6765\u5185\u90e8\u521d\u59cb\u5316\u94fe\u8868\u3002\u60a8\u4e0d\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539\u94fe\u8868\u89e3\u51b3\u95ee\u9898\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u60a8\u53ea\u80fd\u901a\u8fc7\u4e0a\u8ff0 API \u6765\u64cd\u4f5c\u94fe\u8868\u3002

    \n\n

     

    \n\n

    \u8fdb\u9636\uff1a

    \n\n

    \u60a8\u662f\u5426\u53ef\u4ee5\uff1a

    \n\n
      \n\t
    • \u4f7f\u7528\u5e38\u6570\u7ea7\u7a7a\u95f4\u590d\u6742\u5ea6\u89e3\u51b3\u95ee\u9898\uff1f
    • \n\t
    • \u4f7f\u7528\u7ebf\u6027\u7ea7\u65f6\u95f4\u590d\u6742\u5ea6\u548c\u4f4e\u4e8e\u7ebf\u6027\u7ea7\u7a7a\u95f4\u590d\u6742\u5ea6\u89e3\u51b3\u95ee\u9898\uff1f
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahead = [1,2,3,4]\n\u8f93\u51fa\uff1a[4,3,2,1]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahead = [0,-4,-1,3,-5]\n\u8f93\u51fa\uff1a[-5,3,-1,-4,0]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahead = [-2,0,6,4,4,-6]\n\u8f93\u51fa\uff1a[-6,4,4,6,0,-2]\n
    \n\n
      \n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u94fe\u8868\u7684\u957f\u5ea6\u5728 [1, 1000] \u4e4b\u95f4\u3002
    • \n\t
    • \u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u5728 [-1000, 1000] \u4e4b\u95f4\u3002
    • \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * // This is the ImmutableListNode's API interface.\n * // You should not implement it, or speculate about its implementation.\n * class ImmutableListNode {\n * public:\n * void printValue(); // print the value of the node.\n * ImmutableListNode* getNext(); // return the next node.\n * };\n */\n\nclass Solution {\npublic:\n void printLinkedListInReverse(ImmutableListNode* head) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * // This is the ImmutableListNode's API interface.\n * // You should not implement it, or speculate about its implementation.\n * interface ImmutableListNode {\n * public void printValue(); // print the value of this node.\n * public ImmutableListNode getNext(); // return the next node.\n * };\n */\n\nclass Solution {\n public void printLinkedListInReverse(ImmutableListNode head) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# \"\"\"\n# This is the ImmutableListNode's API interface.\n# You should not implement it, or speculate about its implementation.\n# \"\"\"\n# class ImmutableListNode(object):\n# def printValue(self): # print the value of this node.\n# . \"\"\"\n# :rtype None\n# \"\"\"\n#\n# def getNext(self): # return the next node.\n# . \"\"\"\n# :rtype ImmutableListNode\n# \"\"\"\n\nclass Solution(object):\n def printLinkedListInReverse(self, head):\n \"\"\"\n :type head: ImmutableListNode\n :rtype: None\n \"\"\"\n\t\t", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# \"\"\"\n# This is the ImmutableListNode's API interface.\n# You should not implement it, or speculate about its implementation.\n# \"\"\"\n# class ImmutableListNode:\n# def printValue(self) -> None: # print the value of this node.\n# def getNext(self) -> 'ImmutableListNode': # return the next node.\n\nclass Solution:\n def printLinkedListInReverse(self, head: 'ImmutableListNode') -> None:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for ImmutableListNode.\n * struct ImmutableListNode {\n * struct ImmutableListNode* (*getNext)(struct ImmutableListNode*); // return the next node.\n * void (*printValue)(struct ImmutableListNode*); // print the value of the node.\n * };\n */\n\nvoid printLinkedListInReverse(struct ImmutableListNode* head) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * // This is the ImmutableListNode's API interface.\n * // You should not implement it, or speculate about its implementation.\n * class ImmutableListNode {\n * public void PrintValue(); // print the value of this node.\n * public ImmutableListNode GetNext(); // return the next node.\n * }\n */\n\npublic class Solution {\n public void PrintLinkedListInReverse(ImmutableListNode head) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // This is the ImmutableListNode's API interface.\n * // You should not implement it, or speculate about its implementation.\n * function ImmutableListNode() {\n * @ return {void}\n * this.printValue = function() { // print the value of this node.\n * ...\n * }; \n *\n * @return {ImmutableListNode}\n * this.getNext = function() { // return the next node.\n * ...\n * };\n * };\n */\n\n/**\n * @param {ImmutableListNode} head\n * @return {void}\n */\nvar printLinkedListInReverse = function(head) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# This is the ImmutableListNode's API interface.\n# You should not implement it, or speculate about its implementation.\n#\n# class ImmutableListNode\n# def printValue()\n# . print the value of this node.\n# def end\n# \"\"\"\n#\n# def getNext()\n# . return the next node.\n# end\n# end\n\ndef printLinkedListInReverse(head)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for ImmutableListNode.\n * public class ImmutableListNode {\n * public func printValue() {}\n * public func getNext() -> ImmutableListNode? {}\n * }\n */\n\nclass Solution {\n func printLinkedListInReverse(_ head: ImmutableListNode?) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/* Below is the interface for ImmutableListNode, which is already defined for you.\n *\n * type ImmutableListNode struct {\n * \n * }\n *\n * func (this *ImmutableListNode) getNext() ImmutableListNode {\n *\t\t// return the next node.\n * }\n *\n * func (this *ImmutableListNode) printValue() {\n *\t\t// print the value of this node.\n * }\n */\n\nfunc printLinkedListInReverse(head ImmutableListNode) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * // This is the ImmutableListNode's API interface.\n * // You should not implement it, or speculate about its implementation.\n * class ImmutableListNode{\n * def printValue(): Unit = {} // print the value of this node.\n * def getNext(): ImmutableListNode = {} // return the next node.\n * };\n */\n\nobject Solution {\n def printLinkedListInReverse(head: ImmutableListNode): Unit = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * // This is the ImmutableListNode's API interface.\n * // You should not implement it, or speculate about its implementation.\n * class ImmutableListNode {\n * fun getNext(): ImmutableListNode? {} // return the next node.\n * fun printValue() {} // print the value of this node.\n * };\n */\n\nclass Solution {\n\tfun printLinkedListInReverse(head:ImmutableListNode?) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * // This is the ImmutableListNode's API interface.\n * // You should not implement it, or speculate about its implementation.\n * class ImmutableListNode {\n * public function printValue() {} // print the value of this node.\n * public function getNext() {} // return the next node.\n * };\n */\n\nclass Solution {\n /**\n * @param ImmutableListNode $head\n * @return void\n */\n function printLinkedListInReverse($head) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * // This is the ImmutableListNode's API interface.\n * // You should not implement it, or speculate about its implementation\n * class ImmutableListNode {\n * printValue() {}\n *\n * getNext(): ImmutableListNode {}\n * }\n */\n\nfunction printLinkedListInReverse(head: ImmutableListNode) {\n\t\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1265](https://leetcode-cn.com/problems/print-immutable-linked-list-in-reverse)", "[\u9006\u5e8f\u6253\u5370\u4e0d\u53ef\u53d8\u94fe\u8868](/solution/1200-1299/1265.Print%20Immutable%20Linked%20List%20in%20Reverse/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1265](https://leetcode.com/problems/print-immutable-linked-list-in-reverse)", "[Print Immutable Linked List in Reverse](/solution/1200-1299/1265.Print%20Immutable%20Linked%20List%20in%20Reverse/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1403", "frontend_question_id": "1278", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/palindrome-partitioning-iii", "url_en": "https://leetcode.com/problems/palindrome-partitioning-iii", "relative_path_cn": "/solution/1200-1299/1278.Palindrome%20Partitioning%20III/README.md", "relative_path_en": "/solution/1200-1299/1278.Palindrome%20Partitioning%20III/README_EN.md", "title_cn": "\u5206\u5272\u56de\u6587\u4e32 III", "title_en": "Palindrome Partitioning III", "question_title_slug": "palindrome-partitioning-iii", "content_en": "

    You are given a string s containing lowercase letters and an integer k. You need to :

    \r\n\r\n
      \r\n\t
    • First, change some characters of s to other lowercase English letters.
    • \r\n\t
    • Then divide s into k non-empty disjoint substrings such that each substring is palindrome.
    • \r\n
    \r\n\r\n

    Return the minimal number of characters that you need to change to divide the string.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: s = "abc", k = 2\r\nOutput: 1\r\nExplanation: You can split the string into "ab" and "c", and change 1 character in "ab" to make it palindrome.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: s = "aabbc", k = 3\r\nOutput: 0\r\nExplanation: You can split the string into "aa", "bb" and "c", all of them are palindrome.
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: s = "leetcode", k = 8\r\nOutput: 0\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= k <= s.length <= 100.
    • \r\n\t
    • s only contains lowercase English letters.
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210\u7684\u5b57\u7b26\u4e32 s\uff0c\u548c\u4e00\u4e2a\u6574\u6570 k\u3002

    \n\n

    \u8bf7\u4f60\u6309\u4e0b\u9762\u7684\u8981\u6c42\u5206\u5272\u5b57\u7b26\u4e32\uff1a

    \n\n
      \n\t
    • \u9996\u5148\uff0c\u4f60\u53ef\u4ee5\u5c06 s \u4e2d\u7684\u90e8\u5206\u5b57\u7b26\u4fee\u6539\u4e3a\u5176\u4ed6\u7684\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    • \n\t
    • \u63a5\u7740\uff0c\u4f60\u9700\u8981\u628a s \u5206\u5272\u6210 k \u4e2a\u975e\u7a7a\u4e14\u4e0d\u76f8\u4ea4\u7684\u5b50\u4e32\uff0c\u5e76\u4e14\u6bcf\u4e2a\u5b50\u4e32\u90fd\u662f\u56de\u6587\u4e32\u3002
    • \n
    \n\n

    \u8bf7\u8fd4\u56de\u4ee5\u8fd9\u79cd\u65b9\u5f0f\u5206\u5272\u5b57\u7b26\u4e32\u6240\u9700\u4fee\u6539\u7684\u6700\u5c11\u5b57\u7b26\u6570\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1as = "abc", k = 2\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u628a\u5b57\u7b26\u4e32\u5206\u5272\u6210 "ab" \u548c "c"\uff0c\u5e76\u4fee\u6539 "ab" \u4e2d\u7684 1 \u4e2a\u5b57\u7b26\uff0c\u5c06\u5b83\u53d8\u6210\u56de\u6587\u4e32\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1as = "aabbc", k = 3\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u628a\u5b57\u7b26\u4e32\u5206\u5272\u6210 "aa"\u3001"bb" \u548c "c"\uff0c\u5b83\u4eec\u90fd\u662f\u56de\u6587\u4e32\u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1as = "leetcode", k = 8\n\u8f93\u51fa\uff1a0\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= k <= s.length <= 100
    • \n\t
    • s \u4e2d\u53ea\u542b\u6709\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int palindromePartition(string s, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int palindromePartition(String s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def palindromePartition(self, s, k):\n \"\"\"\n :type s: str\n :type k: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def palindromePartition(self, s: str, k: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint palindromePartition(char * s, int k){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int PalindromePartition(string s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number} k\n * @return {number}\n */\nvar palindromePartition = function(s, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer} k\n# @return {Integer}\ndef palindrome_partition(s, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func palindromePartition(_ s: String, _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func palindromePartition(s string, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def palindromePartition(s: String, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun palindromePartition(s: String, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn palindrome_partition(s: String, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer $k\n * @return Integer\n */\n function palindromePartition($s, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function palindromePartition(s: string, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (palindrome-partition s k)\n (-> string? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1278](https://leetcode-cn.com/problems/palindrome-partitioning-iii)", "[\u5206\u5272\u56de\u6587\u4e32 III](/solution/1200-1299/1278.Palindrome%20Partitioning%20III/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1278](https://leetcode.com/problems/palindrome-partitioning-iii)", "[Palindrome Partitioning III](/solution/1200-1299/1278.Palindrome%20Partitioning%20III/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1402", "frontend_question_id": "1277", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-square-submatrices-with-all-ones", "url_en": "https://leetcode.com/problems/count-square-submatrices-with-all-ones", "relative_path_cn": "/solution/1200-1299/1277.Count%20Square%20Submatrices%20with%20All%20Ones/README.md", "relative_path_en": "/solution/1200-1299/1277.Count%20Square%20Submatrices%20with%20All%20Ones/README_EN.md", "title_cn": "\u7edf\u8ba1\u5168\u4e3a 1 \u7684\u6b63\u65b9\u5f62\u5b50\u77e9\u9635", "title_en": "Count Square Submatrices with All Ones", "question_title_slug": "count-square-submatrices-with-all-ones", "content_en": "

    Given a m * n matrix of ones and zeros, return how many square submatrices have all ones.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: matrix =\n[\n  [0,1,1,1],\n  [1,1,1,1],\n  [0,1,1,1]\n]\nOutput: 15\nExplanation: \nThere are 10 squares of side 1.\nThere are 4 squares of side 2.\nThere is  1 square of side 3.\nTotal number of squares = 10 + 4 + 1 = 15.\n
    \n\n

    Example 2:

    \n\n
    \nInput: matrix = \n[\n  [1,0,1],\n  [1,1,0],\n  [1,1,0]\n]\nOutput: 7\nExplanation: \nThere are 6 squares of side 1.  \nThere is 1 square of side 2. \nTotal number of squares = 6 + 1 = 7.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= arr.length <= 300
    • \n\t
    • 1 <= arr[0].length <= 300
    • \n\t
    • 0 <= arr[i][j] <= 1
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a m * n \u7684\u77e9\u9635\uff0c\u77e9\u9635\u4e2d\u7684\u5143\u7d20\u4e0d\u662f 0 \u5c31\u662f 1\uff0c\u8bf7\u4f60\u7edf\u8ba1\u5e76\u8fd4\u56de\u5176\u4e2d\u5b8c\u5168\u7531 1 \u7ec4\u6210\u7684 \u6b63\u65b9\u5f62 \u5b50\u77e9\u9635\u7684\u4e2a\u6570\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1amatrix =\n[\n  [0,1,1,1],\n  [1,1,1,1],\n  [0,1,1,1]\n]\n\u8f93\u51fa\uff1a15\n\u89e3\u91ca\uff1a \n\u8fb9\u957f\u4e3a 1 \u7684\u6b63\u65b9\u5f62\u6709 10 \u4e2a\u3002\n\u8fb9\u957f\u4e3a 2 \u7684\u6b63\u65b9\u5f62\u6709 4 \u4e2a\u3002\n\u8fb9\u957f\u4e3a 3 \u7684\u6b63\u65b9\u5f62\u6709 1 \u4e2a\u3002\n\u6b63\u65b9\u5f62\u7684\u603b\u6570 = 10 + 4 + 1 = 15.\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1amatrix = \n[\n  [1,0,1],\n  [1,1,0],\n  [1,1,0]\n]\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\n\u8fb9\u957f\u4e3a 1 \u7684\u6b63\u65b9\u5f62\u6709 6 \u4e2a\u3002 \n\u8fb9\u957f\u4e3a 2 \u7684\u6b63\u65b9\u5f62\u6709 1 \u4e2a\u3002\n\u6b63\u65b9\u5f62\u7684\u603b\u6570 = 6 + 1 = 7.\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= arr.length <= 300
    • \n\t
    • 1 <= arr[0].length <= 300
    • \n\t
    • 0 <= arr[i][j] <= 1
    • \n
    \n", "tags_en": ["Array", "Dynamic Programming"], "tags_cn": ["\u6570\u7ec4", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countSquares(vector>& matrix) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countSquares(int[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countSquares(self, matrix):\n \"\"\"\n :type matrix: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countSquares(self, matrix: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countSquares(int** matrix, int matrixSize, int* matrixColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountSquares(int[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} matrix\n * @return {number}\n */\nvar countSquares = function(matrix) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} matrix\n# @return {Integer}\ndef count_squares(matrix)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countSquares(_ matrix: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countSquares(matrix [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countSquares(matrix: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countSquares(matrix: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_squares(matrix: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $matrix\n * @return Integer\n */\n function countSquares($matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countSquares(matrix: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-squares matrix)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1277](https://leetcode-cn.com/problems/count-square-submatrices-with-all-ones)", "[\u7edf\u8ba1\u5168\u4e3a 1 \u7684\u6b63\u65b9\u5f62\u5b50\u77e9\u9635](/solution/1200-1299/1277.Count%20Square%20Submatrices%20with%20All%20Ones/README.md)", "`\u6570\u7ec4`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1277](https://leetcode.com/problems/count-square-submatrices-with-all-ones)", "[Count Square Submatrices with All Ones](/solution/1200-1299/1277.Count%20Square%20Submatrices%20with%20All%20Ones/README_EN.md)", "`Array`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "1401", "frontend_question_id": "1276", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-burgers-with-no-waste-of-ingredients", "url_en": "https://leetcode.com/problems/number-of-burgers-with-no-waste-of-ingredients", "relative_path_cn": "/solution/1200-1299/1276.Number%20of%20Burgers%20with%20No%20Waste%20of%20Ingredients/README.md", "relative_path_en": "/solution/1200-1299/1276.Number%20of%20Burgers%20with%20No%20Waste%20of%20Ingredients/README_EN.md", "title_cn": "\u4e0d\u6d6a\u8d39\u539f\u6599\u7684\u6c49\u5821\u5236\u4f5c\u65b9\u6848", "title_en": "Number of Burgers with No Waste of Ingredients", "question_title_slug": "number-of-burgers-with-no-waste-of-ingredients", "content_en": "

    Given two integers tomatoSlices and cheeseSlices. The ingredients of different burgers are as follows:

    \r\n\r\n
      \r\n\t
    • Jumbo Burger: 4 tomato slices and 1 cheese slice.
    • \r\n\t
    • Small Burger: 2 Tomato slices and 1 cheese slice.
    • \r\n
    \r\n\r\n

    Return [total_jumbo, total_small] so that the number of remaining tomatoSlices equal to 0 and the number of remaining cheeseSlices equal to 0. If it is not possible to make the remaining tomatoSlices and cheeseSlices equal to 0 return [].

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: tomatoSlices = 16, cheeseSlices = 7\r\nOutput: [1,6]\r\nExplantion: To make one jumbo burger and 6 small burgers we need 4*1 + 2*6 = 16 tomato and 1 + 6 = 7 cheese. There will be no remaining ingredients.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: tomatoSlices = 17, cheeseSlices = 4\r\nOutput: []\r\nExplantion: There will be no way to use all ingredients to make small and jumbo burgers.\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: tomatoSlices = 4, cheeseSlices = 17\r\nOutput: []\r\nExplantion: Making 1 jumbo burger there will be 16 cheese remaining and making 2 small burgers there will be 15 cheese remaining.\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: tomatoSlices = 0, cheeseSlices = 0\r\nOutput: [0,0]\r\n
    \r\n\r\n

    Example 5:

    \r\n\r\n
    \r\nInput: tomatoSlices = 2, cheeseSlices = 1\r\nOutput: [0,1]\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 0 <= tomatoSlices <= 10^7
    • \r\n\t
    • 0 <= cheeseSlices <= 10^7
    • \r\n
    ", "content_cn": "

    \u5723\u8bde\u6d3b\u52a8\u9884\u70ed\u5f00\u59cb\u5566\uff0c\u6c49\u5821\u5e97\u63a8\u51fa\u4e86\u5168\u65b0\u7684\u6c49\u5821\u5957\u9910\u3002\u4e3a\u4e86\u907f\u514d\u6d6a\u8d39\u539f\u6599\uff0c\u8bf7\u4f60\u5e2e\u4ed6\u4eec\u5236\u5b9a\u5408\u9002\u7684\u5236\u4f5c\u8ba1\u5212\u3002

    \n\n

    \u7ed9\u4f60\u4e24\u4e2a\u6574\u6570 tomatoSlices \u548c cheeseSlices\uff0c\u5206\u522b\u8868\u793a\u756a\u8304\u7247\u548c\u5976\u916a\u7247\u7684\u6570\u76ee\u3002\u4e0d\u540c\u6c49\u5821\u7684\u539f\u6599\u642d\u914d\u5982\u4e0b\uff1a

    \n\n
      \n\t
    • \u5de8\u65e0\u9738\u6c49\u5821\uff1a4 \u7247\u756a\u8304\u548c 1 \u7247\u5976\u916a
    • \n\t
    • \u5c0f\u7687\u5821\uff1a2 \u7247\u756a\u8304\u548c 1 \u7247\u5976\u916a
    • \n
    \n\n

    \u8bf7\u4f60\u4ee5 [total_jumbo, total_small]\uff08[\u5de8\u65e0\u9738\u6c49\u5821\u603b\u6570\uff0c\u5c0f\u7687\u5821\u603b\u6570]\uff09\u7684\u683c\u5f0f\u8fd4\u56de\u6070\u5f53\u7684\u5236\u4f5c\u65b9\u6848\uff0c\u4f7f\u5f97\u5269\u4e0b\u7684\u756a\u8304\u7247 tomatoSlices \u548c\u5976\u916a\u7247 cheeseSlices \u7684\u6570\u91cf\u90fd\u662f 0\u3002

    \n\n

    \u5982\u679c\u65e0\u6cd5\u4f7f\u5269\u4e0b\u7684\u756a\u8304\u7247 tomatoSlices \u548c\u5976\u916a\u7247 cheeseSlices \u7684\u6570\u91cf\u4e3a 0\uff0c\u5c31\u8bf7\u8fd4\u56de []\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1atomatoSlices = 16, cheeseSlices = 7\n\u8f93\u51fa\uff1a[1,6]\n\u89e3\u91ca\uff1a\u5236\u4f5c 1 \u4e2a\u5de8\u65e0\u9738\u6c49\u5821\u548c 6 \u4e2a\u5c0f\u7687\u5821\u9700\u8981 4*1 + 2*6 = 16 \u7247\u756a\u8304\u548c 1 + 6 = 7 \u7247\u5976\u916a\u3002\u4e0d\u4f1a\u5269\u4e0b\u539f\u6599\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1atomatoSlices = 17, cheeseSlices = 4\n\u8f93\u51fa\uff1a[]\n\u89e3\u91ca\uff1a\u53ea\u5236\u4f5c\u5c0f\u7687\u5821\u548c\u5de8\u65e0\u9738\u6c49\u5821\u65e0\u6cd5\u7528\u5149\u5168\u90e8\u539f\u6599\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1atomatoSlices = 4, cheeseSlices = 17\n\u8f93\u51fa\uff1a[]\n\u89e3\u91ca\uff1a\u5236\u4f5c 1 \u4e2a\u5de8\u65e0\u9738\u6c49\u5821\u4f1a\u5269\u4e0b 16 \u7247\u5976\u916a\uff0c\u5236\u4f5c 2 \u4e2a\u5c0f\u7687\u5821\u4f1a\u5269\u4e0b 15 \u7247\u5976\u916a\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1atomatoSlices = 0, cheeseSlices = 0\n\u8f93\u51fa\uff1a[0,0]\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1atomatoSlices = 2, cheeseSlices = 1\n\u8f93\u51fa\uff1a[0,1]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= tomatoSlices <= 10^7
    • \n\t
    • 0 <= cheeseSlices <= 10^7
    • \n
    \n", "tags_en": ["Greedy", "Math"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector numOfBurgers(int tomatoSlices, int cheeseSlices) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List numOfBurgers(int tomatoSlices, int cheeseSlices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numOfBurgers(self, tomatoSlices, cheeseSlices):\n \"\"\"\n :type tomatoSlices: int\n :type cheeseSlices: int\n :rtype: List[int]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* numOfBurgers(int tomatoSlices, int cheeseSlices, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList NumOfBurgers(int tomatoSlices, int cheeseSlices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} tomatoSlices\n * @param {number} cheeseSlices\n * @return {number[]}\n */\nvar numOfBurgers = function(tomatoSlices, cheeseSlices) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} tomato_slices\n# @param {Integer} cheese_slices\n# @return {Integer[]}\ndef num_of_burgers(tomato_slices, cheese_slices)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numOfBurgers(_ tomatoSlices: Int, _ cheeseSlices: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numOfBurgers(tomatoSlices int, cheeseSlices int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numOfBurgers(tomatoSlices: Int, cheeseSlices: Int): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numOfBurgers(tomatoSlices: Int, cheeseSlices: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_of_burgers(tomato_slices: i32, cheese_slices: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $tomatoSlices\n * @param Integer $cheeseSlices\n * @return Integer[]\n */\n function numOfBurgers($tomatoSlices, $cheeseSlices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numOfBurgers(tomatoSlices: number, cheeseSlices: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-of-burgers tomatoSlices cheeseSlices)\n (-> exact-integer? exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1276](https://leetcode-cn.com/problems/number-of-burgers-with-no-waste-of-ingredients)", "[\u4e0d\u6d6a\u8d39\u539f\u6599\u7684\u6c49\u5821\u5236\u4f5c\u65b9\u6848](/solution/1200-1299/1276.Number%20of%20Burgers%20with%20No%20Waste%20of%20Ingredients/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1276](https://leetcode.com/problems/number-of-burgers-with-no-waste-of-ingredients)", "[Number of Burgers with No Waste of Ingredients](/solution/1200-1299/1276.Number%20of%20Burgers%20with%20No%20Waste%20of%20Ingredients/README_EN.md)", "`Greedy`,`Math`", "Medium", ""]}, {"question_id": "1400", "frontend_question_id": "1275", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-winner-on-a-tic-tac-toe-game", "url_en": "https://leetcode.com/problems/find-winner-on-a-tic-tac-toe-game", "relative_path_cn": "/solution/1200-1299/1275.Find%20Winner%20on%20a%20Tic%20Tac%20Toe%20Game/README.md", "relative_path_en": "/solution/1200-1299/1275.Find%20Winner%20on%20a%20Tic%20Tac%20Toe%20Game/README_EN.md", "title_cn": "\u627e\u51fa\u4e95\u5b57\u68cb\u7684\u83b7\u80dc\u8005", "title_en": "Find Winner on a Tic Tac Toe Game", "question_title_slug": "find-winner-on-a-tic-tac-toe-game", "content_en": "

    Tic-tac-toe is played by two players A and B on a 3 x 3 grid.

    \r\n\r\n

    Here are the rules of Tic-Tac-Toe:

    \r\n\r\n
      \r\n\t
    • Players take turns placing characters into empty squares (" ").
    • \r\n\t
    • The first player A always places "X" characters, while the second player B always places "O" characters.
    • \r\n\t
    • "X" and "O" characters are always placed into empty squares, never on filled ones.
    • \r\n\t
    • The game ends when there are 3 of the same (non-empty) character filling any row, column, or diagonal.
    • \r\n\t
    • The game also ends if all squares are non-empty.
    • \r\n\t
    • No more moves can be played if the game is over.
    • \r\n
    \r\n\r\n

    Given an array moves where each element is another array of size 2 corresponding to the row and column of the grid where they mark their respective character in the order in which A and B play.

    \r\n\r\n

    Return the winner of the game if it exists (A or B), in case the game ends in a draw return "Draw", if there are still movements to play return "Pending".

    \r\n\r\n

    You can assume that moves is valid (It follows the rules of Tic-Tac-Toe), the grid is initially empty and A will play first.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: moves = [[0,0],[2,0],[1,1],[2,1],[2,2]]\r\nOutput: "A"\r\nExplanation: "A" wins, he always plays first.\r\n"X  "    "X  "    "X  "    "X  "    "X  "\r\n"   " -> "   " -> " X " -> " X " -> " X "\r\n"   "    "O  "    "O  "    "OO "    "OOX"\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: moves = [[0,0],[1,1],[0,1],[0,2],[1,0],[2,0]]\r\nOutput: "B"\r\nExplanation: "B" wins.\r\n"X  "    "X  "    "XX "    "XXO"    "XXO"    "XXO"\r\n"   " -> " O " -> " O " -> " O " -> "XO " -> "XO " \r\n"   "    "   "    "   "    "   "    "   "    "O  "\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: moves = [[0,0],[1,1],[2,0],[1,0],[1,2],[2,1],[0,1],[0,2],[2,2]]\r\nOutput: "Draw"\r\nExplanation: The game ends in a draw since there are no moves to make.\r\n"XXO"\r\n"OOX"\r\n"XOX"\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: moves = [[0,0],[1,1]]\r\nOutput: "Pending"\r\nExplanation: The game has not finished yet.\r\n"X  "\r\n" O "\r\n"   "\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= moves.length <= 9
    • \r\n\t
    • moves[i].length == 2
    • \r\n\t
    • 0 <= moves[i][j] <= 2
    • \r\n\t
    • There are no repeated elements on moves.
    • \r\n\t
    • moves follow the rules of tic tac toe.
    • \r\n
    ", "content_cn": "

    A \u548c B \u5728\u4e00\u4e2a 3 x 3 \u7684\u7f51\u683c\u4e0a\u73a9\u4e95\u5b57\u68cb\u3002

    \n\n

    \u4e95\u5b57\u68cb\u6e38\u620f\u7684\u89c4\u5219\u5982\u4e0b\uff1a

    \n\n
      \n\t
    • \u73a9\u5bb6\u8f6e\u6d41\u5c06\u68cb\u5b50\u653e\u5728\u7a7a\u65b9\u683c (" ") \u4e0a\u3002
    • \n\t
    • \u7b2c\u4e00\u4e2a\u73a9\u5bb6 A \u603b\u662f\u7528 "X" \u4f5c\u4e3a\u68cb\u5b50\uff0c\u800c\u7b2c\u4e8c\u4e2a\u73a9\u5bb6 B \u603b\u662f\u7528 "O" \u4f5c\u4e3a\u68cb\u5b50\u3002
    • \n\t
    • "X" \u548c "O" \u53ea\u80fd\u653e\u5728\u7a7a\u65b9\u683c\u4e2d\uff0c\u800c\u4e0d\u80fd\u653e\u5728\u5df2\u7ecf\u88ab\u5360\u7528\u7684\u65b9\u683c\u4e0a\u3002
    • \n\t
    • \u53ea\u8981\u6709 3 \u4e2a\u76f8\u540c\u7684\uff08\u975e\u7a7a\uff09\u68cb\u5b50\u6392\u6210\u4e00\u6761\u76f4\u7ebf\uff08\u884c\u3001\u5217\u3001\u5bf9\u89d2\u7ebf\uff09\u65f6\uff0c\u6e38\u620f\u7ed3\u675f\u3002
    • \n\t
    • \u5982\u679c\u6240\u6709\u65b9\u5757\u90fd\u653e\u6ee1\u68cb\u5b50\uff08\u4e0d\u4e3a\u7a7a\uff09\uff0c\u6e38\u620f\u4e5f\u4f1a\u7ed3\u675f\u3002
    • \n\t
    • \u6e38\u620f\u7ed3\u675f\u540e\uff0c\u68cb\u5b50\u65e0\u6cd5\u518d\u8fdb\u884c\u4efb\u4f55\u79fb\u52a8\u3002
    • \n
    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 moves\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5143\u7d20\u662f\u5927\u5c0f\u4e3a 2 \u7684\u53e6\u4e00\u4e2a\u6570\u7ec4\uff08\u5143\u7d20\u5206\u522b\u5bf9\u5e94\u7f51\u683c\u7684\u884c\u548c\u5217\uff09\uff0c\u5b83\u6309\u7167 A \u548c B \u7684\u884c\u52a8\u987a\u5e8f\uff08\u5148 A \u540e B\uff09\u8bb0\u5f55\u4e86\u4e24\u4eba\u5404\u81ea\u7684\u68cb\u5b50\u4f4d\u7f6e\u3002

    \n\n

    \u5982\u679c\u6e38\u620f\u5b58\u5728\u83b7\u80dc\u8005\uff08A \u6216 B\uff09\uff0c\u5c31\u8fd4\u56de\u8be5\u6e38\u620f\u7684\u83b7\u80dc\u8005\uff1b\u5982\u679c\u6e38\u620f\u4ee5\u5e73\u5c40\u7ed3\u675f\uff0c\u5219\u8fd4\u56de "Draw"\uff1b\u5982\u679c\u4ecd\u4f1a\u6709\u884c\u52a8\uff08\u6e38\u620f\u672a\u7ed3\u675f\uff09\uff0c\u5219\u8fd4\u56de "Pending"\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u5047\u8bbe moves \u90fd \u6709\u6548\uff08\u9075\u5faa\u4e95\u5b57\u68cb\u89c4\u5219\uff09\uff0c\u7f51\u683c\u6700\u521d\u662f\u7a7a\u7684\uff0cA \u5c06\u5148\u884c\u52a8\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1amoves = [[0,0],[2,0],[1,1],[2,1],[2,2]]\n\u8f93\u51fa\uff1a"A"\n\u89e3\u91ca\uff1a"A" \u83b7\u80dc\uff0c\u4ed6\u603b\u662f\u5148\u8d70\u3002\n"X  "    "X  "    "X  "    "X  "    "X  "\n"   " -> "   " -> " X " -> " X " -> " X "\n"   "    "O  "    "O  "    "OO "    "OOX"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1amoves = [[0,0],[1,1],[0,1],[0,2],[1,0],[2,0]]\n\u8f93\u51fa\uff1a"B"\n\u89e3\u91ca\uff1a"B" \u83b7\u80dc\u3002\n"X  "    "X  "    "XX "    "XXO"    "XXO"    "XXO"\n"   " -> " O " -> " O " -> " O " -> "XO " -> "XO " \n"   "    "   "    "   "    "   "    "   "    "O  "\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1amoves = [[0,0],[1,1],[2,0],[1,0],[1,2],[2,1],[0,1],[0,2],[2,2]]\n\u8f93\u51fa\uff1a"Draw"\n\u8f93\u51fa\uff1a\u7531\u4e8e\u6ca1\u6709\u529e\u6cd5\u518d\u884c\u52a8\uff0c\u6e38\u620f\u4ee5\u5e73\u5c40\u7ed3\u675f\u3002\n"XXO"\n"OOX"\n"XOX"\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1amoves = [[0,0],[1,1]]\n\u8f93\u51fa\uff1a"Pending"\n\u89e3\u91ca\uff1a\u6e38\u620f\u8fd8\u6ca1\u6709\u7ed3\u675f\u3002\n"X  "\n" O "\n"   "\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= moves.length <= 9
    • \n\t
    • moves[i].length == 2
    • \n\t
    • 0 <= moves[i][j] <= 2
    • \n\t
    • moves \u91cc\u6ca1\u6709\u91cd\u590d\u7684\u5143\u7d20\u3002
    • \n\t
    • moves \u9075\u5faa\u4e95\u5b57\u68cb\u7684\u89c4\u5219\u3002
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string tictactoe(vector>& moves) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String tictactoe(int[][] moves) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def tictactoe(self, moves):\n \"\"\"\n :type moves: List[List[int]]\n :rtype: str\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def tictactoe(self, moves: List[List[int]]) -> str:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * tictactoe(int** moves, int movesSize, int* movesColSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string Tictactoe(int[][] moves) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} moves\n * @return {string}\n */\nvar tictactoe = function(moves) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} moves\n# @return {String}\ndef tictactoe(moves)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func tictactoe(_ moves: [[Int]]) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func tictactoe(moves [][]int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def tictactoe(moves: Array[Array[Int]]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun tictactoe(moves: Array): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn tictactoe(moves: Vec>) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $moves\n * @return String\n */\n function tictactoe($moves) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function tictactoe(moves: number[][]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (tictactoe moves)\n (-> (listof (listof exact-integer?)) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1275](https://leetcode-cn.com/problems/find-winner-on-a-tic-tac-toe-game)", "[\u627e\u51fa\u4e95\u5b57\u68cb\u7684\u83b7\u80dc\u8005](/solution/1200-1299/1275.Find%20Winner%20on%20a%20Tic%20Tac%20Toe%20Game/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1275](https://leetcode.com/problems/find-winner-on-a-tic-tac-toe-game)", "[Find Winner on a Tic Tac Toe Game](/solution/1200-1299/1275.Find%20Winner%20on%20a%20Tic%20Tac%20Toe%20Game/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1399", "frontend_question_id": "1264", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/page-recommendations", "url_en": "https://leetcode.com/problems/page-recommendations", "relative_path_cn": "/solution/1200-1299/1264.Page%20Recommendations/README.md", "relative_path_en": "/solution/1200-1299/1264.Page%20Recommendations/README_EN.md", "title_cn": "\u9875\u9762\u63a8\u8350", "title_en": "Page Recommendations", "question_title_slug": "page-recommendations", "content_en": "

    Table: Friendship

    \r\n\r\n
    \r\n+---------------+---------+\r\n| Column Name   | Type    |\r\n+---------------+---------+\r\n| user1_id      | int     |\r\n| user2_id      | int     |\r\n+---------------+---------+\r\n(user1_id, user2_id) is the primary key for this table.\r\nEach row of this table indicates that there is a friendship relation between user1_id and user2_id.\r\n
    \r\n\r\n

     

    \r\n\r\n

    Table: Likes

    \r\n\r\n
    \r\n+-------------+---------+\r\n| Column Name | Type    |\r\n+-------------+---------+\r\n| user_id     | int     |\r\n| page_id     | int     |\r\n+-------------+---------+\r\n(user_id, page_id) is the primary key for this table.\r\nEach row of this table indicates that user_id likes page_id.\r\n
    \r\n\r\n

     

    \r\n\r\n

    Write an SQL query to recommend pages to the user with user_id = 1 using the pages that your friends liked. It should not recommend pages you already liked.

    \r\n\r\n

    Return result table in any order without duplicates.

    \r\n\r\n

    The query result format is in the following example:

    \r\n\r\n
    \r\nFriendship table:\r\n+----------+----------+\r\n| user1_id | user2_id |\r\n+----------+----------+\r\n| 1        | 2        |\r\n| 1        | 3        |\r\n| 1        | 4        |\r\n| 2        | 3        |\r\n| 2        | 4        |\r\n| 2        | 5        |\r\n| 6        | 1        |\r\n+----------+----------+\r\n \r\nLikes table:\r\n+---------+---------+\r\n| user_id | page_id |\r\n+---------+---------+\r\n| 1       | 88      |\r\n| 2       | 23      |\r\n| 3       | 24      |\r\n| 4       | 56      |\r\n| 5       | 11      |\r\n| 6       | 33      |\r\n| 2       | 77      |\r\n| 3       | 77      |\r\n| 6       | 88      |\r\n+---------+---------+\r\n\r\nResult table:\r\n+------------------+\r\n| recommended_page |\r\n+------------------+\r\n| 23               |\r\n| 24               |\r\n| 56               |\r\n| 33               |\r\n| 77               |\r\n+------------------+\r\nUser one is friend with users 2, 3, 4 and 6.\r\nSuggested pages are 23 from user 2, 24 from user 3, 56 from user 3 and 33 from user 6.\r\nPage 77 is suggested from both user 2 and user 3.\r\nPage 88 is not suggested because user 1 already likes it.\r\n
    ", "content_cn": "

    \u670b\u53cb\u5173\u7cfb\u5217\u8868\uff1a Friendship

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| user1_id      | int     |\n| user2_id      | int     |\n+---------------+---------+\n\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\u662f (user1_id, user2_id)\u3002\n\u8fd9\u5f20\u8868\u7684\u6bcf\u4e00\u884c\u4ee3\u8868\u7740 user1_id \u548c user2_id \u4e4b\u95f4\u5b58\u5728\u7740\u670b\u53cb\u5173\u7cfb\u3002\n
    \n\n

     

    \n\n

    \u559c\u6b22\u5217\u8868\uff1a Likes

    \n\n
    \n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| user_id     | int     |\n| page_id     | int     |\n+-------------+---------+\n\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\u662f (user_id, page_id)\u3002\n\u8fd9\u5f20\u8868\u7684\u6bcf\u4e00\u884c\u4ee3\u8868\u7740 user_id \u559c\u6b22 page_id\u3002\n
    \n\n

     

    \n\n

    \u5199\u4e00\u6bb5 SQL  \u5411user_id = 1 \u7684\u7528\u6237\uff0c\u63a8\u8350\u5176\u670b\u53cb\u4eec\u559c\u6b22\u7684\u9875\u9762\u3002\u4e0d\u8981\u63a8\u8350\u8be5\u7528\u6237\u5df2\u7ecf\u559c\u6b22\u7684\u9875\u9762\u3002

    \n\n

    \u4f60\u8fd4\u56de\u7684\u7ed3\u679c\u4e2d\u4e0d\u5e94\u5f53\u5305\u542b\u91cd\u590d\u9879\u3002

    \n\n

    \u8fd4\u56de\u7ed3\u679c\u7684\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a\uff1a

    \n\n
    \nFriendship table:\n+----------+----------+\n| user1_id | user2_id |\n+----------+----------+\n| 1        | 2        |\n| 1        | 3        |\n| 1        | 4        |\n| 2        | 3        |\n| 2        | 4        |\n| 2        | 5        |\n| 6        | 1        |\n+----------+----------+\n \nLikes table:\n+---------+---------+\n| user_id | page_id |\n+---------+---------+\n| 1       | 88      |\n| 2       | 23      |\n| 3       | 24      |\n| 4       | 56      |\n| 5       | 11      |\n| 6       | 33      |\n| 2       | 77      |\n| 3       | 77      |\n| 6       | 88      |\n+---------+---------+\n\nResult table:\n+------------------+\n| recommended_page |\n+------------------+\n| 23               |\n| 24               |\n| 56               |\n| 33               |\n| 77               |\n+------------------+\n\u7528\u62371 \u540c \u7528\u62372, 3, 4, 6 \u662f\u670b\u53cb\u5173\u7cfb\u3002\n\u63a8\u8350\u9875\u9762\u4e3a\uff1a \u9875\u976223 \u6765\u81ea\u4e8e \u7528\u62372, \u9875\u976224 \u6765\u81ea\u4e8e \u7528\u62373, \u9875\u976256 \u6765\u81ea\u4e8e \u7528\u62373 \u4ee5\u53ca \u9875\u976233 \u6765\u81ea\u4e8e \u7528\u62376\u3002\n\u9875\u976277 \u540c\u65f6\u88ab \u7528\u62372 \u548c \u7528\u62373 \u63a8\u8350\u3002\n\u9875\u976288 \u6ca1\u6709\u88ab\u63a8\u8350\uff0c\u56e0\u4e3a \u7528\u62371 \u5df2\u7ecf\u559c\u6b22\u4e86\u5b83\u3002\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1264](https://leetcode-cn.com/problems/page-recommendations)", "[\u9875\u9762\u63a8\u8350](/solution/1200-1299/1264.Page%20Recommendations/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1264](https://leetcode.com/problems/page-recommendations)", "[Page Recommendations](/solution/1200-1299/1264.Page%20Recommendations/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1398", "frontend_question_id": "1269", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-ways-to-stay-in-the-same-place-after-some-steps", "url_en": "https://leetcode.com/problems/number-of-ways-to-stay-in-the-same-place-after-some-steps", "relative_path_cn": "/solution/1200-1299/1269.Number%20of%20Ways%20to%20Stay%20in%20the%20Same%20Place%20After%20Some%20Steps/README.md", "relative_path_en": "/solution/1200-1299/1269.Number%20of%20Ways%20to%20Stay%20in%20the%20Same%20Place%20After%20Some%20Steps/README_EN.md", "title_cn": "\u505c\u5728\u539f\u5730\u7684\u65b9\u6848\u6570", "title_en": "Number of Ways to Stay in the Same Place After Some Steps", "question_title_slug": "number-of-ways-to-stay-in-the-same-place-after-some-steps", "content_en": "

    You have a pointer at index 0 in an array of size arrLen. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).

    \n\n

    Given two integers steps and arrLen, return the number of ways such that your pointer still at index 0 after exactly steps steps. Since the answer may be too large, return it modulo 109 + 7.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: steps = 3, arrLen = 2\nOutput: 4\nExplanation: There are 4 differents ways to stay at index 0 after 3 steps.\nRight, Left, Stay\nStay, Right, Left\nRight, Stay, Left\nStay, Stay, Stay\n
    \n\n

    Example 2:

    \n\n
    \nInput: steps = 2, arrLen = 4\nOutput: 2\nExplanation: There are 2 differents ways to stay at index 0 after 2 steps\nRight, Left\nStay, Stay\n
    \n\n

    Example 3:

    \n\n
    \nInput: steps = 4, arrLen = 2\nOutput: 8\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= steps <= 500
    • \n\t
    • 1 <= arrLen <= 106
    • \n
    \n", "content_cn": "

    \u6709\u4e00\u4e2a\u957f\u5ea6\u4e3a\u00a0arrLen\u00a0\u7684\u6570\u7ec4\uff0c\u5f00\u59cb\u6709\u4e00\u4e2a\u6307\u9488\u5728\u7d22\u5f15\u00a00 \u5904\u3002

    \n\n

    \u6bcf\u4e00\u6b65\u64cd\u4f5c\u4e2d\uff0c\u4f60\u53ef\u4ee5\u5c06\u6307\u9488\u5411\u5de6\u6216\u5411\u53f3\u79fb\u52a8 1 \u6b65\uff0c\u6216\u8005\u505c\u5728\u539f\u5730\uff08\u6307\u9488\u4e0d\u80fd\u88ab\u79fb\u52a8\u5230\u6570\u7ec4\u8303\u56f4\u5916\uff09\u3002

    \n\n

    \u7ed9\u4f60\u4e24\u4e2a\u6574\u6570\u00a0steps \u548c\u00a0arrLen \uff0c\u8bf7\u4f60\u8ba1\u7b97\u5e76\u8fd4\u56de\uff1a\u5728\u6070\u597d\u6267\u884c\u00a0steps\u00a0\u6b21\u64cd\u4f5c\u4ee5\u540e\uff0c\u6307\u9488\u4ecd\u7136\u6307\u5411\u7d22\u5f15\u00a00 \u5904\u7684\u65b9\u6848\u6570\u3002

    \n\n

    \u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u4f1a\u5f88\u5927\uff0c\u8bf7\u8fd4\u56de\u65b9\u6848\u6570 \u6a21\u00a010^9 + 7 \u540e\u7684\u7ed3\u679c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1asteps = 3, arrLen = 2\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a3 \u6b65\u540e\uff0c\u603b\u5171\u6709 4 \u79cd\u4e0d\u540c\u7684\u65b9\u6cd5\u53ef\u4ee5\u505c\u5728\u7d22\u5f15 0 \u5904\u3002\n\u5411\u53f3\uff0c\u5411\u5de6\uff0c\u4e0d\u52a8\n\u4e0d\u52a8\uff0c\u5411\u53f3\uff0c\u5411\u5de6\n\u5411\u53f3\uff0c\u4e0d\u52a8\uff0c\u5411\u5de6\n\u4e0d\u52a8\uff0c\u4e0d\u52a8\uff0c\u4e0d\u52a8\n
    \n\n

    \u793a\u4f8b\u00a0 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1asteps = 2, arrLen = 4\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a2 \u6b65\u540e\uff0c\u603b\u5171\u6709 2 \u79cd\u4e0d\u540c\u7684\u65b9\u6cd5\u53ef\u4ee5\u505c\u5728\u7d22\u5f15 0 \u5904\u3002\n\u5411\u53f3\uff0c\u5411\u5de6\n\u4e0d\u52a8\uff0c\u4e0d\u52a8\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1asteps = 4, arrLen = 2\n\u8f93\u51fa\uff1a8\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= steps <= 500
    • \n\t
    • 1 <= arrLen <= 106
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numWays(int steps, int arrLen) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numWays(int steps, int arrLen) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numWays(self, steps, arrLen):\n \"\"\"\n :type steps: int\n :type arrLen: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numWays(self, steps: int, arrLen: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numWays(int steps, int arrLen){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumWays(int steps, int arrLen) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} steps\n * @param {number} arrLen\n * @return {number}\n */\nvar numWays = function(steps, arrLen) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} steps\n# @param {Integer} arr_len\n# @return {Integer}\ndef num_ways(steps, arr_len)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numWays(_ steps: Int, _ arrLen: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numWays(steps int, arrLen int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numWays(steps: Int, arrLen: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numWays(steps: Int, arrLen: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_ways(steps: i32, arr_len: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $steps\n * @param Integer $arrLen\n * @return Integer\n */\n function numWays($steps, $arrLen) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numWays(steps: number, arrLen: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-ways steps arrLen)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1269](https://leetcode-cn.com/problems/number-of-ways-to-stay-in-the-same-place-after-some-steps)", "[\u505c\u5728\u539f\u5730\u7684\u65b9\u6848\u6570](/solution/1200-1299/1269.Number%20of%20Ways%20to%20Stay%20in%20the%20Same%20Place%20After%20Some%20Steps/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1269](https://leetcode.com/problems/number-of-ways-to-stay-in-the-same-place-after-some-steps)", "[Number of Ways to Stay in the Same Place After Some Steps](/solution/1200-1299/1269.Number%20of%20Ways%20to%20Stay%20in%20the%20Same%20Place%20After%20Some%20Steps/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1397", "frontend_question_id": "1268", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/search-suggestions-system", "url_en": "https://leetcode.com/problems/search-suggestions-system", "relative_path_cn": "/solution/1200-1299/1268.Search%20Suggestions%20System/README.md", "relative_path_en": "/solution/1200-1299/1268.Search%20Suggestions%20System/README_EN.md", "title_cn": "\u641c\u7d22\u63a8\u8350\u7cfb\u7edf", "title_en": "Search Suggestions System", "question_title_slug": "search-suggestions-system", "content_en": "

    Given an array of strings products and a string searchWord. We want to design a system that suggests at most three product names from products after each character of searchWord is typed. Suggested products should have common prefix with the searchWord. If there are more than three products with a common prefix return the three lexicographically minimums products.

    \n\n

    Return list of lists of the suggested products after each character of searchWord is typed. 

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: products = ["mobile","mouse","moneypot","monitor","mousepad"], searchWord = "mouse"\nOutput: [\n["mobile","moneypot","monitor"],\n["mobile","moneypot","monitor"],\n["mouse","mousepad"],\n["mouse","mousepad"],\n["mouse","mousepad"]\n]\nExplanation: products sorted lexicographically = ["mobile","moneypot","monitor","mouse","mousepad"]\nAfter typing m and mo all products match and we show user ["mobile","moneypot","monitor"]\nAfter typing mou, mous and mouse the system suggests ["mouse","mousepad"]\n
    \n\n

    Example 2:

    \n\n
    \nInput: products = ["havana"], searchWord = "havana"\nOutput: [["havana"],["havana"],["havana"],["havana"],["havana"],["havana"]]\n
    \n\n

    Example 3:

    \n\n
    \nInput: products = ["bags","baggage","banner","box","cloths"], searchWord = "bags"\nOutput: [["baggage","bags","banner"],["baggage","bags","banner"],["baggage","bags"],["bags"]]\n
    \n\n

    Example 4:

    \n\n
    \nInput: products = ["havana"], searchWord = "tatiana"\nOutput: [[],[],[],[],[],[],[]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= products.length <= 1000
    • \n\t
    • There are no repeated elements in products.
    • \n\t
    • 1 <= Σ products[i].length <= 2 * 10^4
    • \n\t
    • All characters of products[i] are lower-case English letters.
    • \n\t
    • 1 <= searchWord.length <= 1000
    • \n\t
    • All characters of searchWord are lower-case English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u4ea7\u54c1\u6570\u7ec4 products \u548c\u4e00\u4e2a\u5b57\u7b26\u4e32 searchWord \uff0cproducts  \u6570\u7ec4\u4e2d\u6bcf\u4e2a\u4ea7\u54c1\u90fd\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\u3002

    \n\n

    \u8bf7\u4f60\u8bbe\u8ba1\u4e00\u4e2a\u63a8\u8350\u7cfb\u7edf\uff0c\u5728\u4f9d\u6b21\u8f93\u5165\u5355\u8bcd searchWord \u7684\u6bcf\u4e00\u4e2a\u5b57\u6bcd\u540e\uff0c\u63a8\u8350 products \u6570\u7ec4\u4e2d\u524d\u7f00\u4e0e searchWord \u76f8\u540c\u7684\u6700\u591a\u4e09\u4e2a\u4ea7\u54c1\u3002\u5982\u679c\u524d\u7f00\u76f8\u540c\u7684\u53ef\u63a8\u8350\u4ea7\u54c1\u8d85\u8fc7\u4e09\u4e2a\uff0c\u8bf7\u6309\u5b57\u5178\u5e8f\u8fd4\u56de\u6700\u5c0f\u7684\u4e09\u4e2a\u3002

    \n\n

    \u8bf7\u4f60\u4ee5\u4e8c\u7ef4\u5217\u8868\u7684\u5f62\u5f0f\uff0c\u8fd4\u56de\u5728\u8f93\u5165 searchWord \u6bcf\u4e2a\u5b57\u6bcd\u540e\u76f8\u5e94\u7684\u63a8\u8350\u4ea7\u54c1\u7684\u5217\u8868\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aproducts = ["mobile","mouse","moneypot","monitor","mousepad"], searchWord = "mouse"\n\u8f93\u51fa\uff1a[\n["mobile","moneypot","monitor"],\n["mobile","moneypot","monitor"],\n["mouse","mousepad"],\n["mouse","mousepad"],\n["mouse","mousepad"]\n]\n\u89e3\u91ca\uff1a\u6309\u5b57\u5178\u5e8f\u6392\u5e8f\u540e\u7684\u4ea7\u54c1\u5217\u8868\u662f ["mobile","moneypot","monitor","mouse","mousepad"]\n\u8f93\u5165 m \u548c mo\uff0c\u7531\u4e8e\u6240\u6709\u4ea7\u54c1\u7684\u524d\u7f00\u90fd\u76f8\u540c\uff0c\u6240\u4ee5\u7cfb\u7edf\u8fd4\u56de\u5b57\u5178\u5e8f\u6700\u5c0f\u7684\u4e09\u4e2a\u4ea7\u54c1 ["mobile","moneypot","monitor"]\n\u8f93\u5165 mou\uff0c mous \u548c mouse \u540e\u7cfb\u7edf\u90fd\u8fd4\u56de ["mouse","mousepad"]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aproducts = ["havana"], searchWord = "havana"\n\u8f93\u51fa\uff1a[["havana"],["havana"],["havana"],["havana"],["havana"],["havana"]]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aproducts = ["bags","baggage","banner","box","cloths"], searchWord = "bags"\n\u8f93\u51fa\uff1a[["baggage","bags","banner"],["baggage","bags","banner"],["baggage","bags"],["bags"]]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1aproducts = ["havana"], searchWord = "tatiana"\n\u8f93\u51fa\uff1a[[],[],[],[],[],[],[]]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= products.length <= 1000
    • \n\t
    • 1 <= Σ products[i].length <= 2 * 10^4
    • \n\t
    • products[i] \u4e2d\u6240\u6709\u7684\u5b57\u7b26\u90fd\u662f\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    • \n\t
    • 1 <= searchWord.length <= 1000
    • \n\t
    • searchWord \u4e2d\u6240\u6709\u5b57\u7b26\u90fd\u662f\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> suggestedProducts(vector& products, string searchWord) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> suggestedProducts(String[] products, String searchWord) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def suggestedProducts(self, products, searchWord):\n \"\"\"\n :type products: List[str]\n :type searchWord: str\n :rtype: List[List[str]]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def suggestedProducts(self, products: List[str], searchWord: str) -> List[List[str]]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nchar *** suggestedProducts(char ** products, int productsSize, char * searchWord, int* returnSize, int** returnColumnSizes){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> SuggestedProducts(string[] products, string searchWord) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} products\n * @param {string} searchWord\n * @return {string[][]}\n */\nvar suggestedProducts = function(products, searchWord) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} products\n# @param {String} search_word\n# @return {String[][]}\ndef suggested_products(products, search_word)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func suggestedProducts(_ products: [String], _ searchWord: String) -> [[String]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func suggestedProducts(products []string, searchWord string) [][]string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def suggestedProducts(products: Array[String], searchWord: String): List[List[String]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun suggestedProducts(products: Array, searchWord: String): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn suggested_products(products: Vec, search_word: String) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $products\n * @param String $searchWord\n * @return String[][]\n */\n function suggestedProducts($products, $searchWord) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function suggestedProducts(products: string[], searchWord: string): string[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (suggested-products products searchWord)\n (-> (listof string?) string? (listof (listof string?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1268](https://leetcode-cn.com/problems/search-suggestions-system)", "[\u641c\u7d22\u63a8\u8350\u7cfb\u7edf](/solution/1200-1299/1268.Search%20Suggestions%20System/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1268](https://leetcode.com/problems/search-suggestions-system)", "[Search Suggestions System](/solution/1200-1299/1268.Search%20Suggestions%20System/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "1396", "frontend_question_id": "1267", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-servers-that-communicate", "url_en": "https://leetcode.com/problems/count-servers-that-communicate", "relative_path_cn": "/solution/1200-1299/1267.Count%20Servers%20that%20Communicate/README.md", "relative_path_en": "/solution/1200-1299/1267.Count%20Servers%20that%20Communicate/README_EN.md", "title_cn": "\u7edf\u8ba1\u53c2\u4e0e\u901a\u4fe1\u7684\u670d\u52a1\u5668", "title_en": "Count Servers that Communicate", "question_title_slug": "count-servers-that-communicate", "content_en": "

    You are given a map of a server center, represented as a m * n integer matrix grid, where 1 means that on that cell there is a server and 0 means that it is no server. Two servers are said to communicate if they are on the same row or on the same column.
    \n
    \nReturn the number of servers that communicate with any other server.

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: grid = [[1,0],[0,1]]\nOutput: 0\nExplanation: No servers can communicate with others.
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: grid = [[1,0],[1,1]]\nOutput: 3\nExplanation: All three servers can communicate with at least one other server.\n
    \n\n

    Example 3:

    \n\n

    \"\"

    \n\n
    \nInput: grid = [[1,1,0,0],[0,0,1,0],[0,0,1,0],[0,0,0,1]]\nOutput: 4\nExplanation: The two servers in the first row can communicate with each other. The two servers in the third column can communicate with each other. The server at right bottom corner can't communicate with any other server.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= m <= 250
    • \n\t
    • 1 <= n <= 250
    • \n\t
    • grid[i][j] == 0 or 1
    • \n
    \n", "content_cn": "

    \u8fd9\u91cc\u6709\u4e00\u5e45\u670d\u52a1\u5668\u5206\u5e03\u56fe\uff0c\u670d\u52a1\u5668\u7684\u4f4d\u7f6e\u6807\u8bc6\u5728 m * n \u7684\u6574\u6570\u77e9\u9635\u7f51\u683c grid \u4e2d\uff0c1 \u8868\u793a\u5355\u5143\u683c\u4e0a\u6709\u670d\u52a1\u5668\uff0c0 \u8868\u793a\u6ca1\u6709\u3002

    \n\n

    \u5982\u679c\u4e24\u53f0\u670d\u52a1\u5668\u4f4d\u4e8e\u540c\u4e00\u884c\u6216\u8005\u540c\u4e00\u5217\uff0c\u6211\u4eec\u5c31\u8ba4\u4e3a\u5b83\u4eec\u4e4b\u95f4\u53ef\u4ee5\u8fdb\u884c\u901a\u4fe1\u3002

    \n\n

    \u8bf7\u4f60\u7edf\u8ba1\u5e76\u8fd4\u56de\u80fd\u591f\u4e0e\u81f3\u5c11\u4e00\u53f0\u5176\u4ed6\u670d\u52a1\u5668\u8fdb\u884c\u901a\u4fe1\u7684\u670d\u52a1\u5668\u7684\u6570\u91cf\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1agrid = [[1,0],[0,1]]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6ca1\u6709\u4e00\u53f0\u670d\u52a1\u5668\u80fd\u4e0e\u5176\u4ed6\u670d\u52a1\u5668\u8fdb\u884c\u901a\u4fe1\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1agrid = [[1,0],[1,1]]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6240\u6709\u8fd9\u4e9b\u670d\u52a1\u5668\u90fd\u81f3\u5c11\u53ef\u4ee5\u4e0e\u4e00\u53f0\u522b\u7684\u670d\u52a1\u5668\u8fdb\u884c\u901a\u4fe1\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1agrid = [[1,1,0,0],[0,0,1,0],[0,0,1,0],[0,0,0,1]]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u7b2c\u4e00\u884c\u7684\u4e24\u53f0\u670d\u52a1\u5668\u4e92\u76f8\u901a\u4fe1\uff0c\u7b2c\u4e09\u5217\u7684\u4e24\u53f0\u670d\u52a1\u5668\u4e92\u76f8\u901a\u4fe1\uff0c\u4f46\u53f3\u4e0b\u89d2\u7684\u670d\u52a1\u5668\u65e0\u6cd5\u4e0e\u5176\u4ed6\u670d\u52a1\u5668\u901a\u4fe1\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= m <= 250
    • \n\t
    • 1 <= n <= 250
    • \n\t
    • grid[i][j] == 0 or 1
    • \n
    \n", "tags_en": ["Graph", "Array"], "tags_cn": ["\u56fe", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countServers(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countServers(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countServers(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countServers(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countServers(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountServers(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar countServers = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef count_servers(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countServers(_ grid: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countServers(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countServers(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countServers(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_servers(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function countServers($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countServers(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-servers grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1267](https://leetcode-cn.com/problems/count-servers-that-communicate)", "[\u7edf\u8ba1\u53c2\u4e0e\u901a\u4fe1\u7684\u670d\u52a1\u5668](/solution/1200-1299/1267.Count%20Servers%20that%20Communicate/README.md)", "`\u56fe`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1267](https://leetcode.com/problems/count-servers-that-communicate)", "[Count Servers that Communicate](/solution/1200-1299/1267.Count%20Servers%20that%20Communicate/README_EN.md)", "`Graph`,`Array`", "Medium", ""]}, {"question_id": "1395", "frontend_question_id": "1266", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-time-visiting-all-points", "url_en": "https://leetcode.com/problems/minimum-time-visiting-all-points", "relative_path_cn": "/solution/1200-1299/1266.Minimum%20Time%20Visiting%20All%20Points/README.md", "relative_path_en": "/solution/1200-1299/1266.Minimum%20Time%20Visiting%20All%20Points/README_EN.md", "title_cn": "\u8bbf\u95ee\u6240\u6709\u70b9\u7684\u6700\u5c0f\u65f6\u95f4", "title_en": "Minimum Time Visiting All Points", "question_title_slug": "minimum-time-visiting-all-points", "content_en": "

    On a 2D plane, there are n points with integer coordinates points[i] = [xi, yi]. Return the minimum time in seconds to visit all the points in the order given by points.

    \n\n

    You can move according to these rules:

    \n\n
      \n\t
    • In 1 second, you can either:\n\n\t
        \n\t\t
      • move vertically by one unit,
      • \n\t\t
      • move horizontally by one unit, or
      • \n\t\t
      • move diagonally sqrt(2) units (in other words, move one unit vertically then one unit horizontally in 1 second).
      • \n\t
      \n\t
    • \n\t
    • You have to visit the points in the same order as they appear in the array.
    • \n\t
    • You are allowed to pass through points that appear later in the order, but these do not count as visits.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: points = [[1,1],[3,4],[-1,0]]\nOutput: 7\nExplanation: One optimal path is [1,1] -> [2,2] -> [3,3] -> [3,4] -> [2,3] -> [1,2] -> [0,1] -> [-1,0]   \nTime from [1,1] to [3,4] = 3 seconds \nTime from [3,4] to [-1,0] = 4 seconds\nTotal time = 7 seconds
    \n\n

    Example 2:

    \n\n
    \nInput: points = [[3,2],[-2,2]]\nOutput: 5\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • points.length == n
    • \n\t
    • 1 <= n <= 100
    • \n\t
    • points[i].length == 2
    • \n\t
    • -1000 <= points[i][0], points[i][1] <= 1000
    • \n
    \n", "content_cn": "

    \u5e73\u9762\u4e0a\u6709\u00a0n\u00a0\u4e2a\u70b9\uff0c\u70b9\u7684\u4f4d\u7f6e\u7528\u6574\u6570\u5750\u6807\u8868\u793a points[i] = [xi, yi] \u3002\u8bf7\u4f60\u8ba1\u7b97\u8bbf\u95ee\u6240\u6709\u8fd9\u4e9b\u70b9\u9700\u8981\u7684 \u6700\u5c0f\u65f6\u95f4\uff08\u4ee5\u79d2\u4e3a\u5355\u4f4d\uff09\u3002

    \n\n

    \u4f60\u9700\u8981\u6309\u7167\u4e0b\u9762\u7684\u89c4\u5219\u5728\u5e73\u9762\u4e0a\u79fb\u52a8\uff1a

    \n\n
      \n\t
    • \u6bcf\u4e00\u79d2\u5185\uff0c\u4f60\u53ef\u4ee5\uff1a\n\t
        \n\t\t
      • \u6cbf\u6c34\u5e73\u65b9\u5411\u79fb\u52a8\u4e00\u4e2a\u5355\u4f4d\u957f\u5ea6\uff0c\u6216\u8005
      • \n\t\t
      • \u6cbf\u7ad6\u76f4\u65b9\u5411\u79fb\u52a8\u4e00\u4e2a\u5355\u4f4d\u957f\u5ea6\uff0c\u6216\u8005
      • \n\t\t
      • \u8de8\u8fc7\u5bf9\u89d2\u7ebf\u79fb\u52a8 sqrt(2) \u4e2a\u5355\u4f4d\u957f\u5ea6\uff08\u53ef\u4ee5\u770b\u4f5c\u5728\u4e00\u79d2\u5185\u5411\u6c34\u5e73\u548c\u7ad6\u76f4\u65b9\u5411\u5404\u79fb\u52a8\u4e00\u4e2a\u5355\u4f4d\u957f\u5ea6\uff09\u3002
      • \n\t
      \n\t
    • \n\t
    • \u5fc5\u987b\u6309\u7167\u6570\u7ec4\u4e2d\u51fa\u73b0\u7684\u987a\u5e8f\u6765\u8bbf\u95ee\u8fd9\u4e9b\u70b9\u3002
    • \n\t
    • \u5728\u8bbf\u95ee\u67d0\u4e2a\u70b9\u65f6\uff0c\u53ef\u4ee5\u7ecf\u8fc7\u8be5\u70b9\u540e\u9762\u51fa\u73b0\u7684\u70b9\uff0c\u4f46\u7ecf\u8fc7\u7684\u90a3\u4e9b\u70b9\u4e0d\u7b97\u4f5c\u6709\u6548\u8bbf\u95ee\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1apoints = [[1,1],[3,4],[-1,0]]\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\u4e00\u6761\u6700\u4f73\u7684\u8bbf\u95ee\u8def\u5f84\u662f\uff1a [1,1] -> [2,2] -> [3,3] -> [3,4] -> [2,3] -> [1,2] -> [0,1] -> [-1,0]   \n\u4ece [1,1] \u5230 [3,4] \u9700\u8981 3 \u79d2 \n\u4ece [3,4] \u5230 [-1,0] \u9700\u8981 4 \u79d2\n\u4e00\u5171\u9700\u8981 7 \u79d2
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1apoints = [[3,2],[-2,2]]\n\u8f93\u51fa\uff1a5\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • points.length == n
    • \n\t
    • 1 <= n\u00a0<= 100
    • \n\t
    • points[i].length == 2
    • \n\t
    • -1000\u00a0<= points[i][0], points[i][1]\u00a0<= 1000
    • \n
    \n", "tags_en": ["Geometry", "Array"], "tags_cn": ["\u51e0\u4f55", "\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minTimeToVisitAllPoints(vector>& points) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minTimeToVisitAllPoints(int[][] points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minTimeToVisitAllPoints(self, points):\n \"\"\"\n :type points: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minTimeToVisitAllPoints(self, points: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minTimeToVisitAllPoints(int** points, int pointsSize, int* pointsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinTimeToVisitAllPoints(int[][] points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} points\n * @return {number}\n */\nvar minTimeToVisitAllPoints = function(points) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} points\n# @return {Integer}\ndef min_time_to_visit_all_points(points)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minTimeToVisitAllPoints(_ points: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minTimeToVisitAllPoints(points [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minTimeToVisitAllPoints(points: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minTimeToVisitAllPoints(points: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_time_to_visit_all_points(points: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $points\n * @return Integer\n */\n function minTimeToVisitAllPoints($points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minTimeToVisitAllPoints(points: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-time-to-visit-all-points points)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1266](https://leetcode-cn.com/problems/minimum-time-visiting-all-points)", "[\u8bbf\u95ee\u6240\u6709\u70b9\u7684\u6700\u5c0f\u65f6\u95f4](/solution/1200-1299/1266.Minimum%20Time%20Visiting%20All%20Points/README.md)", "`\u51e0\u4f55`,`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1266](https://leetcode.com/problems/minimum-time-visiting-all-points)", "[Minimum Time Visiting All Points](/solution/1200-1299/1266.Minimum%20Time%20Visiting%20All%20Points/README_EN.md)", "`Geometry`,`Array`", "Easy", ""]}, {"question_id": "1391", "frontend_question_id": "1426", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/counting-elements", "url_en": "https://leetcode.com/problems/counting-elements", "relative_path_cn": "/solution/1400-1499/1426.Counting%20Elements/README.md", "relative_path_en": "/solution/1400-1499/1426.Counting%20Elements/README_EN.md", "title_cn": "\u6570\u5143\u7d20", "title_en": "Counting Elements", "question_title_slug": "counting-elements", "content_en": "

    Given an integer array arr, count how many elements x there are, such that x + 1 is also in arr. If there are duplicates in arr, count them separately.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr = [1,2,3]\nOutput: 2\nExplanation: 1 and 2 are counted cause 2 and 3 are in arr.
    \n\n

    Example 2:

    \n\n
    \nInput: arr = [1,1,3,3,5,5,7,7]\nOutput: 0\nExplanation: No numbers are counted, cause there's no 2, 4, 6, or 8 in arr.\n
    \n\n

    Example 3:

    \n\n
    \nInput: arr = [1,3,2,3,5,0]\nOutput: 3\nExplanation: 0, 1 and 2 are counted cause 1, 2 and 3 are in arr.\n
    \n\n

    Example 4:

    \n\n
    \nInput: arr = [1,1,2,2]\nOutput: 2\nExplanation: Two 1s are counted cause 2 is in arr.\n
    \n\n

    Example 5:

    \n\n
    \nInput: arr = [1,1,2]\nOutput: 2\nExplanation: Both 1s are counted because 2 is in the array.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= arr.length <= 1000
    • \n\t
    • 0 <= arr[i] <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr\uff0c \u5bf9\u4e8e\u5143\u7d20 x \uff0c\u53ea\u6709\u5f53 x + 1 \u4e5f\u5728\u6570\u7ec4 arr \u91cc\u65f6\uff0c\u624d\u80fd\u8bb0\u4e3a 1 \u4e2a\u6570\u3002

    \n\n

    \u5982\u679c\u6570\u7ec4 arr \u91cc\u6709\u91cd\u590d\u7684\u6570\uff0c\u6bcf\u4e2a\u91cd\u590d\u7684\u6570\u5355\u72ec\u8ba1\u7b97\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [1,2,3]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a1 \u548c 2 \u88ab\u8ba1\u7b97\u6b21\u6570\u56e0\u4e3a 2 \u548c 3 \u5728\u6570\u7ec4 arr \u91cc\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [1,1,3,3,5,5,7,7]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6240\u6709\u7684\u6570\u90fd\u4e0d\u7b97, \u56e0\u4e3a\u6570\u7ec4\u91cc\u6ca1\u6709 2\u30014\u30016\u30018\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [1,3,2,3,5,0]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a0\u30011\u30012 \u88ab\u8ba1\u7b97\u4e86\u56e0\u4e3a 1\u30012\u30013 \u5728\u6570\u7ec4\u91cc\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [1,1,2,2]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u4e24\u4e2a 1 \u88ab\u8ba1\u7b97\u4e86\u56e0\u4e3a\u6709 2 \u5728\u6570\u7ec4\u91cc\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= arr.length <= 1000
    • \n\t
    • 0 <= arr[i] <= 1000
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countElements(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countElements(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countElements(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countElements(self, arr: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countElements(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountElements(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar countElements = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef count_elements(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countElements(_ arr: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countElements(arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countElements(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countElements(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_elements(arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function countElements($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countElements(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-elements arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1426](https://leetcode-cn.com/problems/counting-elements)", "[\u6570\u5143\u7d20](/solution/1400-1499/1426.Counting%20Elements/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1426](https://leetcode.com/problems/counting-elements)", "[Counting Elements](/solution/1400-1499/1426.Counting%20Elements/README_EN.md)", "`Array`", "Easy", "\ud83d\udd12"]}, {"question_id": "1390", "frontend_question_id": "1251", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/average-selling-price", "url_en": "https://leetcode.com/problems/average-selling-price", "relative_path_cn": "/solution/1200-1299/1251.Average%20Selling%20Price/README.md", "relative_path_en": "/solution/1200-1299/1251.Average%20Selling%20Price/README_EN.md", "title_cn": "\u5e73\u5747\u552e\u4ef7", "title_en": "Average Selling Price", "question_title_slug": "average-selling-price", "content_en": "

    Table: Prices

    \r\n\r\n
    \r\n+---------------+---------+\r\n| Column Name   | Type    |\r\n+---------------+---------+\r\n| product_id    | int     |\r\n| start_date    | date    |\r\n| end_date      | date    |\r\n| price         | int     |\r\n+---------------+---------+\r\n(product_id, start_date, end_date) is the primary key for this table.\r\nEach row of this table indicates the price of the product_id in the period from start_date to end_date.\r\nFor each product_id there will be no two overlapping periods. That means there will be no two intersecting periods for the same product_id.\r\n
    \r\n\r\n

     

    \r\n\r\n

    Table: UnitsSold

    \r\n\r\n
    \r\n+---------------+---------+\r\n| Column Name   | Type    |\r\n+---------------+---------+\r\n| product_id    | int     |\r\n| purchase_date | date    |\r\n| units         | int     |\r\n+---------------+---------+\r\nThere is no primary key for this table, it may contain duplicates.\r\nEach row of this table indicates the date, units and product_id of each product sold. \r\n
    \r\n\r\n

     

    \r\n\r\n

    Write an SQL query to find the average selling price for each product.

    \r\n\r\n

    average_price should be rounded to 2 decimal places.

    \r\n\r\n

    The query result format is in the following example:

    \r\n\r\n
    \r\nPrices table:\r\n+------------+------------+------------+--------+\r\n| product_id | start_date | end_date   | price  |\r\n+------------+------------+------------+--------+\r\n| 1          | 2019-02-17 | 2019-02-28 | 5      |\r\n| 1          | 2019-03-01 | 2019-03-22 | 20     |\r\n| 2          | 2019-02-01 | 2019-02-20 | 15     |\r\n| 2          | 2019-02-21 | 2019-03-31 | 30     |\r\n+------------+------------+------------+--------+\r\n \r\nUnitsSold table:\r\n+------------+---------------+-------+\r\n| product_id | purchase_date | units |\r\n+------------+---------------+-------+\r\n| 1          | 2019-02-25    | 100   |\r\n| 1          | 2019-03-01    | 15    |\r\n| 2          | 2019-02-10    | 200   |\r\n| 2          | 2019-03-22    | 30    |\r\n+------------+---------------+-------+\r\n\r\nResult table:\r\n+------------+---------------+\r\n| product_id | average_price |\r\n+------------+---------------+\r\n| 1          | 6.96          |\r\n| 2          | 16.96         |\r\n+------------+---------------+\r\nAverage selling price = Total Price of Product / Number of products sold.\r\nAverage selling price for product 1 = ((100 * 5) + (15 * 20)) / 115 = 6.96\r\nAverage selling price for product 2 = ((200 * 15) + (30 * 30)) / 230 = 16.96\r\n
    ", "content_cn": "

    Table: Prices

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| product_id    | int     |\n| start_date    | date    |\n| end_date      | date    |\n| price         | int     |\n+---------------+---------+\n(product_id\uff0cstart_date\uff0cend_date) \u662f Prices \u8868\u7684\u4e3b\u952e\u3002\nPrices \u8868\u7684\u6bcf\u4e00\u884c\u8868\u793a\u7684\u662f\u67d0\u4e2a\u4ea7\u54c1\u5728\u4e00\u6bb5\u65f6\u671f\u5185\u7684\u4ef7\u683c\u3002\n\u6bcf\u4e2a\u4ea7\u54c1\u7684\u5bf9\u5e94\u65f6\u95f4\u6bb5\u662f\u4e0d\u4f1a\u91cd\u53e0\u7684\uff0c\u8fd9\u4e5f\u610f\u5473\u7740\u540c\u4e00\u4e2a\u4ea7\u54c1\u7684\u4ef7\u683c\u65f6\u6bb5\u4e0d\u4f1a\u51fa\u73b0\u4ea4\u53c9\u3002
    \n\n

     

    \n\n

    Table: UnitsSold

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| product_id    | int     |\n| purchase_date | date    |\n| units         | int     |\n+---------------+---------+\nUnitsSold \u8868\u6ca1\u6709\u4e3b\u952e\uff0c\u5b83\u53ef\u80fd\u5305\u542b\u91cd\u590d\u9879\u3002\nUnitsSold \u8868\u7684\u6bcf\u4e00\u884c\u8868\u793a\u7684\u662f\u6bcf\u79cd\u4ea7\u54c1\u7684\u51fa\u552e\u65e5\u671f\uff0c\u5355\u4f4d\u548c\u4ea7\u54c1 id\u3002
    \n\n

     

    \n\n

    \u7f16\u5199SQL\u67e5\u8be2\u4ee5\u67e5\u627e\u6bcf\u79cd\u4ea7\u54c1\u7684\u5e73\u5747\u552e\u4ef7\u3002
    \naverage_price \u5e94\u8be5\u56db\u820d\u4e94\u5165\u5230\u5c0f\u6570\u70b9\u540e\u4e24\u4f4d\u3002
    \n\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a\uff1a

    \n\n
    \nPrices table:\n+------------+------------+------------+--------+\n| product_id | start_date | end_date   | price  |\n+------------+------------+------------+--------+\n| 1          | 2019-02-17 | 2019-02-28 | 5      |\n| 1          | 2019-03-01 | 2019-03-22 | 20     |\n| 2          | 2019-02-01 | 2019-02-20 | 15     |\n| 2          | 2019-02-21 | 2019-03-31 | 30     |\n+------------+------------+------------+--------+\n \nUnitsSold table:\n+------------+---------------+-------+\n| product_id | purchase_date | units |\n+------------+---------------+-------+\n| 1          | 2019-02-25    | 100   |\n| 1          | 2019-03-01    | 15    |\n| 2          | 2019-02-10    | 200   |\n| 2          | 2019-03-22    | 30    |\n+------------+---------------+-------+\n\nResult table:\n+------------+---------------+\n| product_id | average_price |\n+------------+---------------+\n| 1          | 6.96          |\n| 2          | 16.96         |\n+------------+---------------+\n\u5e73\u5747\u552e\u4ef7 = \u4ea7\u54c1\u603b\u4ef7 / \u9500\u552e\u7684\u4ea7\u54c1\u6570\u91cf\u3002\n\u4ea7\u54c1 1 \u7684\u5e73\u5747\u552e\u4ef7 = ((100 * 5)+(15 * 20) )/ 115 = 6.96\n\u4ea7\u54c1 2 \u7684\u5e73\u5747\u552e\u4ef7 = ((200 * 15)+(30 * 30) )/ 230 = 16.96
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1251](https://leetcode-cn.com/problems/average-selling-price)", "[\u5e73\u5747\u552e\u4ef7](/solution/1200-1299/1251.Average%20Selling%20Price/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1251](https://leetcode.com/problems/average-selling-price)", "[Average Selling Price](/solution/1200-1299/1251.Average%20Selling%20Price/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1389", "frontend_question_id": "1263", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-moves-to-move-a-box-to-their-target-location", "url_en": "https://leetcode.com/problems/minimum-moves-to-move-a-box-to-their-target-location", "relative_path_cn": "/solution/1200-1299/1263.Minimum%20Moves%20to%20Move%20a%20Box%20to%20Their%20Target%20Location/README.md", "relative_path_en": "/solution/1200-1299/1263.Minimum%20Moves%20to%20Move%20a%20Box%20to%20Their%20Target%20Location/README_EN.md", "title_cn": "\u63a8\u7bb1\u5b50", "title_en": "Minimum Moves to Move a Box to Their Target Location", "question_title_slug": "minimum-moves-to-move-a-box-to-their-target-location", "content_en": "

    Storekeeper is a game in which the player pushes boxes around in a warehouse trying to get them to target locations.

    \n\n

    The game is represented by a grid of size m x n, where each element is a wall, floor, or a box.

    \n\n

    Your task is move the box 'B' to the target position 'T' under the following rules:

    \n\n
      \n\t
    • Player is represented by character 'S' and can move up, down, left, right in the grid if it is a floor (empy cell).
    • \n\t
    • Floor is represented by character '.' that means free cell to walk.
    • \n\t
    • Wall is represented by character '#' that means obstacle  (impossible to walk there). 
    • \n\t
    • There is only one box 'B' and one target cell 'T' in the grid.
    • \n\t
    • The box can be moved to an adjacent free cell by standing next to the box and then moving in the direction of the box. This is a push.
    • \n\t
    • The player cannot walk through the box.
    • \n
    \n\n

    Return the minimum number of pushes to move the box to the target. If there is no way to reach the target, return -1.

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: grid = [["#","#","#","#","#","#"],\n               ["#","T","#","#","#","#"],\n               ["#",".",".","B",".","#"],\n               ["#",".","#","#",".","#"],\n               ["#",".",".",".","S","#"],\n               ["#","#","#","#","#","#"]]\nOutput: 3\nExplanation: We return only the number of times the box is pushed.
    \n\n

    Example 2:

    \n\n
    \nInput: grid = [["#","#","#","#","#","#"],\n               ["#","T","#","#","#","#"],\n               ["#",".",".","B",".","#"],\n               ["#","#","#","#",".","#"],\n               ["#",".",".",".","S","#"],\n               ["#","#","#","#","#","#"]]\nOutput: -1\n
    \n\n

    Example 3:

    \n\n
    \nInput: grid = [["#","#","#","#","#","#"],\n               ["#","T",".",".","#","#"],\n               ["#",".","#","B",".","#"],\n               ["#",".",".",".",".","#"],\n               ["#",".",".",".","S","#"],\n               ["#","#","#","#","#","#"]]\nOutput: 5\nExplanation:  push the box down, left, left, up and up.\n
    \n\n

    Example 4:

    \n\n
    \nInput: grid = [["#","#","#","#","#","#","#"],\n               ["#","S","#",".","B","T","#"],\n               ["#","#","#","#","#","#","#"]]\nOutput: -1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= m <= 20
    • \n\t
    • 1 <= n <= 20
    • \n\t
    • grid contains only characters '.', '#''S' , 'T', or 'B'.
    • \n\t
    • There is only one character 'S', 'B' and 'T' in the grid.
    • \n
    \n", "content_cn": "

    \u300c\u63a8\u7bb1\u5b50\u300d\u662f\u4e00\u6b3e\u98ce\u9761\u5168\u7403\u7684\u76ca\u667a\u5c0f\u6e38\u620f\uff0c\u73a9\u5bb6\u9700\u8981\u5c06\u7bb1\u5b50\u63a8\u5230\u4ed3\u5e93\u4e2d\u7684\u76ee\u6807\u4f4d\u7f6e\u3002

    \n\n

    \u6e38\u620f\u5730\u56fe\u7528\u5927\u5c0f\u4e3a n * m \u7684\u7f51\u683c grid \u8868\u793a\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5143\u7d20\u53ef\u4ee5\u662f\u5899\u3001\u5730\u677f\u6216\u8005\u662f\u7bb1\u5b50\u3002

    \n\n

    \u73b0\u5728\u4f60\u5c06\u4f5c\u4e3a\u73a9\u5bb6\u53c2\u4e0e\u6e38\u620f\uff0c\u6309\u89c4\u5219\u5c06\u7bb1\u5b50 'B' \u79fb\u52a8\u5230\u76ee\u6807\u4f4d\u7f6e 'T' \uff1a

    \n\n
      \n\t
    • \u73a9\u5bb6\u7528\u5b57\u7b26 'S' \u8868\u793a\uff0c\u53ea\u8981\u4ed6\u5728\u5730\u677f\u4e0a\uff0c\u5c31\u53ef\u4ee5\u5728\u7f51\u683c\u4e2d\u5411\u4e0a\u3001\u4e0b\u3001\u5de6\u3001\u53f3\u56db\u4e2a\u65b9\u5411\u79fb\u52a8\u3002
    • \n\t
    • \u5730\u677f\u7528\u5b57\u7b26 '.' \u8868\u793a\uff0c\u610f\u5473\u7740\u53ef\u4ee5\u81ea\u7531\u884c\u8d70\u3002
    • \n\t
    • \u5899\u7528\u5b57\u7b26 '#' \u8868\u793a\uff0c\u610f\u5473\u7740\u969c\u788d\u7269\uff0c\u4e0d\u80fd\u901a\u884c\u3002 
    • \n\t
    • \u7bb1\u5b50\u4ec5\u6709\u4e00\u4e2a\uff0c\u7528\u5b57\u7b26 'B' \u8868\u793a\u3002\u76f8\u5e94\u5730\uff0c\u7f51\u683c\u4e0a\u6709\u4e00\u4e2a\u76ee\u6807\u4f4d\u7f6e 'T'\u3002
    • \n\t
    • \u73a9\u5bb6\u9700\u8981\u7ad9\u5728\u7bb1\u5b50\u65c1\u8fb9\uff0c\u7136\u540e\u6cbf\u7740\u7bb1\u5b50\u7684\u65b9\u5411\u8fdb\u884c\u79fb\u52a8\uff0c\u6b64\u65f6\u7bb1\u5b50\u4f1a\u88ab\u79fb\u52a8\u5230\u76f8\u90bb\u7684\u5730\u677f\u5355\u5143\u683c\u3002\u8bb0\u4f5c\u4e00\u6b21\u300c\u63a8\u52a8\u300d\u3002
    • \n\t
    • \u73a9\u5bb6\u65e0\u6cd5\u8d8a\u8fc7\u7bb1\u5b50\u3002
    • \n
    \n\n

    \u8fd4\u56de\u5c06\u7bb1\u5b50\u63a8\u5230\u76ee\u6807\u4f4d\u7f6e\u7684\u6700\u5c0f \u63a8\u52a8 \u6b21\u6570\uff0c\u5982\u679c\u65e0\u6cd5\u505a\u5230\uff0c\u8bf7\u8fd4\u56de -1\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1agrid = [["#","#","#","#","#","#"],\n             ["#","T","#","#","#","#"],\n             ["#",".",".","B",".","#"],\n             ["#",".","#","#",".","#"],\n             ["#",".",".",".","S","#"],\n             ["#","#","#","#","#","#"]]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6211\u4eec\u53ea\u9700\u8981\u8fd4\u56de\u63a8\u7bb1\u5b50\u7684\u6b21\u6570\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1agrid = [["#","#","#","#","#","#"],\n             ["#","T","#","#","#","#"],\n             ["#",".",".","B",".","#"],\n             ["#","#","#","#",".","#"],\n             ["#",".",".",".","S","#"],\n             ["#","#","#","#","#","#"]]\n\u8f93\u51fa\uff1a-1\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1agrid = [["#","#","#","#","#","#"],\n             ["#","T",".",".","#","#"],\n             ["#",".","#","B",".","#"],\n             ["#",".",".",".",".","#"],\n             ["#",".",".",".","S","#"],\n             ["#","#","#","#","#","#"]]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u5411\u4e0b\u3001\u5411\u5de6\u3001\u5411\u5de6\u3001\u5411\u4e0a\u518d\u5411\u4e0a\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1agrid = [["#","#","#","#","#","#","#"],\n             ["#","S","#",".","B","T","#"],\n             ["#","#","#","#","#","#","#"]]\n\u8f93\u51fa\uff1a-1\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= grid.length <= 20
    • \n\t
    • 1 <= grid[i].length <= 20
    • \n\t
    • grid \u4ec5\u5305\u542b\u5b57\u7b26 '.', '#''S' , 'T', \u4ee5\u53ca 'B'\u3002
    • \n\t
    • grid \u4e2d 'S', 'B' \u548c 'T' \u5404\u53ea\u80fd\u51fa\u73b0\u4e00\u4e2a\u3002
    • \n
    \n", "tags_en": ["Breadth-first Search"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minPushBox(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minPushBox(char[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minPushBox(self, grid):\n \"\"\"\n :type grid: List[List[str]]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minPushBox(self, grid: List[List[str]]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minPushBox(char** grid, int gridSize, int* gridColSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinPushBox(char[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {character[][]} grid\n * @return {number}\n */\nvar minPushBox = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Character[][]} grid\n# @return {Integer}\ndef min_push_box(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minPushBox(_ grid: [[Character]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minPushBox(grid [][]byte) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minPushBox(grid: Array[Array[Char]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minPushBox(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_push_box(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $grid\n * @return Integer\n */\n function minPushBox($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minPushBox(grid: string[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-push-box grid)\n (-> (listof (listof char?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1263](https://leetcode-cn.com/problems/minimum-moves-to-move-a-box-to-their-target-location)", "[\u63a8\u7bb1\u5b50](/solution/1200-1299/1263.Minimum%20Moves%20to%20Move%20a%20Box%20to%20Their%20Target%20Location/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[1263](https://leetcode.com/problems/minimum-moves-to-move-a-box-to-their-target-location)", "[Minimum Moves to Move a Box to Their Target Location](/solution/1200-1299/1263.Minimum%20Moves%20to%20Move%20a%20Box%20to%20Their%20Target%20Location/README_EN.md)", "`Breadth-first Search`", "Hard", ""]}, {"question_id": "1388", "frontend_question_id": "1262", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/greatest-sum-divisible-by-three", "url_en": "https://leetcode.com/problems/greatest-sum-divisible-by-three", "relative_path_cn": "/solution/1200-1299/1262.Greatest%20Sum%20Divisible%20by%20Three/README.md", "relative_path_en": "/solution/1200-1299/1262.Greatest%20Sum%20Divisible%20by%20Three/README_EN.md", "title_cn": "\u53ef\u88ab\u4e09\u6574\u9664\u7684\u6700\u5927\u548c", "title_en": "Greatest Sum Divisible by Three", "question_title_slug": "greatest-sum-divisible-by-three", "content_en": "

    Given an array nums of integers, we need to find the maximum possible sum of elements of the array such that it is divisible by three.

    \n\n
      \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [3,6,5,1,8]\nOutput: 18\nExplanation: Pick numbers 3, 6, 1 and 8 their sum is 18 (maximum sum divisible by 3).
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [4]\nOutput: 0\nExplanation: Since 4 is not divisible by 3, do not pick any number.\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [1,2,3,4,4]\nOutput: 12\nExplanation: Pick numbers 1, 3, 4 and 4 their sum is 12 (maximum sum divisible by 3).\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 4 * 10^4
    • \n\t
    • 1 <= nums[i] <= 10^4
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums\uff0c\u8bf7\u4f60\u627e\u51fa\u5e76\u8fd4\u56de\u80fd\u88ab\u4e09\u6574\u9664\u7684\u5143\u7d20\u6700\u5927\u548c\u3002

    \n\n
      \n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [3,6,5,1,8]\n\u8f93\u51fa\uff1a18\n\u89e3\u91ca\uff1a\u9009\u51fa\u6570\u5b57 3, 6, 1 \u548c 8\uff0c\u5b83\u4eec\u7684\u548c\u662f 18\uff08\u53ef\u88ab 3 \u6574\u9664\u7684\u6700\u5927\u548c\uff09\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [4]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a4 \u4e0d\u80fd\u88ab 3 \u6574\u9664\uff0c\u6240\u4ee5\u65e0\u6cd5\u9009\u51fa\u6570\u5b57\uff0c\u8fd4\u56de 0\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,2,3,4,4]\n\u8f93\u51fa\uff1a12\n\u89e3\u91ca\uff1a\u9009\u51fa\u6570\u5b57 1, 3, 4 \u4ee5\u53ca 4\uff0c\u5b83\u4eec\u7684\u548c\u662f 12\uff08\u53ef\u88ab 3 \u6574\u9664\u7684\u6700\u5927\u548c\uff09\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 4 * 10^4
    • \n\t
    • 1 <= nums[i] <= 10^4
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxSumDivThree(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxSumDivThree(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxSumDivThree(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxSumDivThree(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxSumDivThree(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxSumDivThree(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar maxSumDivThree = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef max_sum_div_three(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxSumDivThree(_ nums: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxSumDivThree(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxSumDivThree(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxSumDivThree(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_sum_div_three(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function maxSumDivThree($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxSumDivThree(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-sum-div-three nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1262](https://leetcode-cn.com/problems/greatest-sum-divisible-by-three)", "[\u53ef\u88ab\u4e09\u6574\u9664\u7684\u6700\u5927\u548c](/solution/1200-1299/1262.Greatest%20Sum%20Divisible%20by%20Three/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1262](https://leetcode.com/problems/greatest-sum-divisible-by-three)", "[Greatest Sum Divisible by Three](/solution/1200-1299/1262.Greatest%20Sum%20Divisible%20by%20Three/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "1387", "frontend_question_id": "1261", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-elements-in-a-contaminated-binary-tree", "url_en": "https://leetcode.com/problems/find-elements-in-a-contaminated-binary-tree", "relative_path_cn": "/solution/1200-1299/1261.Find%20Elements%20in%20a%20Contaminated%20Binary%20Tree/README.md", "relative_path_en": "/solution/1200-1299/1261.Find%20Elements%20in%20a%20Contaminated%20Binary%20Tree/README_EN.md", "title_cn": "\u5728\u53d7\u6c61\u67d3\u7684\u4e8c\u53c9\u6811\u4e2d\u67e5\u627e\u5143\u7d20", "title_en": "Find Elements in a Contaminated Binary Tree", "question_title_slug": "find-elements-in-a-contaminated-binary-tree", "content_en": "

    Given a binary tree with the following rules:

    \n\n
      \n\t
    1. root.val == 0
    2. \n\t
    3. If treeNode.val == x and treeNode.left != null, then treeNode.left.val == 2 * x + 1
    4. \n\t
    5. If treeNode.val == x and treeNode.right != null, then treeNode.right.val == 2 * x + 2
    6. \n
    \n\n

    Now the binary tree is contaminated, which means all treeNode.val have been changed to -1.

    \n\n

    Implement the FindElements class:

    \n\n
      \n\t
    • FindElements(TreeNode* root) Initializes the object with a contaminated binary tree and recovers it.
    • \n\t
    • bool find(int target) Returns true if the target value exists in the recovered binary tree.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput\n["FindElements","find","find"]\n[[[-1,null,-1]],[1],[2]]\nOutput\n[null,false,true]\nExplanation\nFindElements findElements = new FindElements([-1,null,-1]); \nfindElements.find(1); // return False \nfindElements.find(2); // return True 
    \n\n

    Example 2:

    \n\"\"\n
    \nInput\n["FindElements","find","find","find"]\n[[[-1,-1,-1,-1,-1]],[1],[3],[5]]\nOutput\n[null,true,true,false]\nExplanation\nFindElements findElements = new FindElements([-1,-1,-1,-1,-1]);\nfindElements.find(1); // return True\nfindElements.find(3); // return True\nfindElements.find(5); // return False
    \n\n

    Example 3:

    \n\"\"\n
    \nInput\n["FindElements","find","find","find","find"]\n[[[-1,null,-1,-1,null,-1]],[2],[3],[4],[5]]\nOutput\n[null,true,false,false,true]\nExplanation\nFindElements findElements = new FindElements([-1,null,-1,-1,null,-1]);\nfindElements.find(2); // return True\nfindElements.find(3); // return False\nfindElements.find(4); // return False\nfindElements.find(5); // return True\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • TreeNode.val == -1
    • \n\t
    • The height of the binary tree is less than or equal to 20
    • \n\t
    • The total number of nodes is between [1, 104]
    • \n\t
    • Total calls of find() is between [1, 104]
    • \n\t
    • 0 <= target <= 106
    • \n
    \n", "content_cn": "

    \u7ed9\u51fa\u4e00\u4e2a\u6ee1\u8db3\u4e0b\u8ff0\u89c4\u5219\u7684\u4e8c\u53c9\u6811\uff1a

    \n\n
      \n\t
    1. root.val == 0
    2. \n\t
    3. \u5982\u679c treeNode.val == x \u4e14 treeNode.left != null\uff0c\u90a3\u4e48 treeNode.left.val == 2 * x + 1
    4. \n\t
    5. \u5982\u679c treeNode.val == x \u4e14 treeNode.right != null\uff0c\u90a3\u4e48 treeNode.right.val == 2 * x + 2
    6. \n
    \n\n

    \u73b0\u5728\u8fd9\u4e2a\u4e8c\u53c9\u6811\u53d7\u5230\u300c\u6c61\u67d3\u300d\uff0c\u6240\u6709\u7684 treeNode.val \u90fd\u53d8\u6210\u4e86 -1\u3002

    \n\n

    \u8bf7\u4f60\u5148\u8fd8\u539f\u4e8c\u53c9\u6811\uff0c\u7136\u540e\u5b9e\u73b0 FindElements \u7c7b\uff1a

    \n\n
      \n\t
    • FindElements(TreeNode* root) \u7528\u53d7\u6c61\u67d3\u7684\u4e8c\u53c9\u6811\u521d\u59cb\u5316\u5bf9\u8c61\uff0c\u4f60\u9700\u8981\u5148\u628a\u5b83\u8fd8\u539f\u3002
    • \n\t
    • bool find(int target) \u5224\u65ad\u76ee\u6807\u503c target \u662f\u5426\u5b58\u5728\u4e8e\u8fd8\u539f\u540e\u7684\u4e8c\u53c9\u6811\u4e2d\u5e76\u8fd4\u56de\u7ed3\u679c\u3002
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1a\n["FindElements","find","find"]\n[[[-1,null,-1]],[1],[2]]\n\u8f93\u51fa\uff1a\n[null,false,true]\n\u89e3\u91ca\uff1a\nFindElements findElements = new FindElements([-1,null,-1]); \nfindElements.find(1); // return False \nfindElements.find(2); // return True 
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1a\n["FindElements","find","find","find"]\n[[[-1,-1,-1,-1,-1]],[1],[3],[5]]\n\u8f93\u51fa\uff1a\n[null,true,true,false]\n\u89e3\u91ca\uff1a\nFindElements findElements = new FindElements([-1,-1,-1,-1,-1]);\nfindElements.find(1); // return True\nfindElements.find(3); // return True\nfindElements.find(5); // return False
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1a\n["FindElements","find","find","find","find"]\n[[[-1,null,-1,-1,null,-1]],[2],[3],[4],[5]]\n\u8f93\u51fa\uff1a\n[null,true,false,false,true]\n\u89e3\u91ca\uff1a\nFindElements findElements = new FindElements([-1,null,-1,-1,null,-1]);\nfindElements.find(2); // return True\nfindElements.find(3); // return False\nfindElements.find(4); // return False\nfindElements.find(5); // return True\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • TreeNode.val == -1
    • \n\t
    • \u4e8c\u53c9\u6811\u7684\u9ad8\u5ea6\u4e0d\u8d85\u8fc7 20
    • \n\t
    • \u8282\u70b9\u7684\u603b\u6570\u5728 [1, 10^4] \u4e4b\u95f4
    • \n\t
    • \u8c03\u7528 find() \u7684\u603b\u6b21\u6570\u5728 [1, 10^4] \u4e4b\u95f4
    • \n\t
    • 0 <= target <= 10^6
    • \n
    \n", "tags_en": ["Tree", "Hash Table"], "tags_cn": ["\u6811", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass FindElements {\npublic:\n FindElements(TreeNode* root) {\n\n }\n \n bool find(int target) {\n\n }\n};\n\n/**\n * Your FindElements object will be instantiated and called as such:\n * FindElements* obj = new FindElements(root);\n * bool param_1 = obj->find(target);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass FindElements {\n\n public FindElements(TreeNode root) {\n\n }\n \n public boolean find(int target) {\n\n }\n}\n\n/**\n * Your FindElements object will be instantiated and called as such:\n * FindElements obj = new FindElements(root);\n * boolean param_1 = obj.find(target);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass FindElements(object):\n\n def __init__(self, root):\n \"\"\"\n :type root: TreeNode\n \"\"\"\n\n\n def find(self, target):\n \"\"\"\n :type target: int\n :rtype: bool\n \"\"\"\n\n\n\n# Your FindElements object will be instantiated and called as such:\n# obj = FindElements(root)\n# param_1 = obj.find(target)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass FindElements:\n\n def __init__(self, root: TreeNode):\n\n\n def find(self, target: int) -> bool:\n\n\n\n# Your FindElements object will be instantiated and called as such:\n# obj = FindElements(root)\n# param_1 = obj.find(target)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n\ntypedef struct {\n\n} FindElements;\n\n\nFindElements* findElementsCreate(struct TreeNode* root) {\n\n}\n\nbool findElementsFind(FindElements* obj, int target) {\n\n}\n\nvoid findElementsFree(FindElements* obj) {\n\n}\n\n/**\n * Your FindElements struct will be instantiated and called as such:\n * FindElements* obj = findElementsCreate(root);\n * bool param_1 = findElementsFind(obj, target);\n \n * findElementsFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class FindElements {\n\n public FindElements(TreeNode root) {\n\n }\n \n public bool Find(int target) {\n\n }\n}\n\n/**\n * Your FindElements object will be instantiated and called as such:\n * FindElements obj = new FindElements(root);\n * bool param_1 = obj.Find(target);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n */\nvar FindElements = function(root) {\n\n};\n\n/** \n * @param {number} target\n * @return {boolean}\n */\nFindElements.prototype.find = function(target) {\n\n};\n\n/**\n * Your FindElements object will be instantiated and called as such:\n * var obj = new FindElements(root)\n * var param_1 = obj.find(target)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\nclass FindElements\n\n=begin\n :type root: TreeNode\n=end\n def initialize(root)\n\n end\n\n\n=begin\n :type target: Integer\n :rtype: Boolean\n=end\n def find(target)\n\n end\n\n\nend\n\n# Your FindElements object will be instantiated and called as such:\n# obj = FindElements.new(root)\n# param_1 = obj.find(target)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\n\nclass FindElements {\n\n init(_ root: TreeNode?) {\n\n }\n \n func find(_ target: Int) -> Bool {\n\n }\n}\n\n/**\n * Your FindElements object will be instantiated and called as such:\n * let obj = FindElements(root)\n * let ret_1: Bool = obj.find(target)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\ntype FindElements struct {\n\n}\n\n\nfunc Constructor(root *TreeNode) FindElements {\n\n}\n\n\nfunc (this *FindElements) Find(target int) bool {\n\n}\n\n\n/**\n * Your FindElements object will be instantiated and called as such:\n * obj := Constructor(root);\n * param_1 := obj.Find(target);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nclass FindElements(_root: TreeNode) {\n\n def find(target: Int): Boolean = {\n\n }\n\n}\n\n/**\n * Your FindElements object will be instantiated and called as such:\n * var obj = new FindElements(root)\n * var param_1 = obj.find(target)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass FindElements(root: TreeNode?) {\n\n fun find(target: Int): Boolean {\n\n }\n\n}\n\n/**\n * Your FindElements object will be instantiated and called as such:\n * var obj = FindElements(root)\n * var param_1 = obj.find(target)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nstruct FindElements {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl FindElements {\n\n fn new(root: Option>>) -> Self {\n\n }\n \n fn find(&self, target: i32) -> bool {\n\n }\n}\n\n/**\n * Your FindElements object will be instantiated and called as such:\n * let obj = FindElements::new(root);\n * let ret_1: bool = obj.find(target);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass FindElements {\n /**\n * @param TreeNode $root\n */\n function __construct($root) {\n\n }\n\n /**\n * @param Integer $target\n * @return Boolean\n */\n function find($target) {\n\n }\n}\n\n/**\n * Your FindElements object will be instantiated and called as such:\n * $obj = FindElements($root);\n * $ret_1 = $obj->find($target);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nclass FindElements {\n constructor(root: TreeNode | null) {\n\n }\n\n find(target: number): boolean {\n\n }\n}\n\n/**\n * Your FindElements object will be instantiated and called as such:\n * var obj = new FindElements(root)\n * var param_1 = obj.find(target)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define find-elements%\n (class object%\n (super-new)\n\n ; root : (or/c tree-node? #f)\n (init-field\n root)\n \n ; find : exact-integer? -> boolean?\n (define/public (find target)\n\n )))\n\n;; Your find-elements% object will be instantiated and called as such:\n;; (define obj (new find-elements% [root root]))\n;; (define param_1 (send obj find target))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1261](https://leetcode-cn.com/problems/find-elements-in-a-contaminated-binary-tree)", "[\u5728\u53d7\u6c61\u67d3\u7684\u4e8c\u53c9\u6811\u4e2d\u67e5\u627e\u5143\u7d20](/solution/1200-1299/1261.Find%20Elements%20in%20a%20Contaminated%20Binary%20Tree/README.md)", "`\u6811`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1261](https://leetcode.com/problems/find-elements-in-a-contaminated-binary-tree)", "[Find Elements in a Contaminated Binary Tree](/solution/1200-1299/1261.Find%20Elements%20in%20a%20Contaminated%20Binary%20Tree/README_EN.md)", "`Tree`,`Hash Table`", "Medium", ""]}, {"question_id": "1386", "frontend_question_id": "1260", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/shift-2d-grid", "url_en": "https://leetcode.com/problems/shift-2d-grid", "relative_path_cn": "/solution/1200-1299/1260.Shift%202D%20Grid/README.md", "relative_path_en": "/solution/1200-1299/1260.Shift%202D%20Grid/README_EN.md", "title_cn": "\u4e8c\u7ef4\u7f51\u683c\u8fc1\u79fb", "title_en": "Shift 2D Grid", "question_title_slug": "shift-2d-grid", "content_en": "

    Given a 2D grid of size m x n and an integer k. You need to shift the grid k times.

    \n\n

    In one shift operation:

    \n\n
      \n\t
    • Element at grid[i][j] moves to grid[i][j + 1].
    • \n\t
    • Element at grid[i][n - 1] moves to grid[i + 1][0].
    • \n\t
    • Element at grid[m - 1][n - 1] moves to grid[0][0].
    • \n
    \n\n

    Return the 2D grid after applying shift operation k times.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: grid = [[1,2,3],[4,5,6],[7,8,9]], k = 1\nOutput: [[9,1,2],[3,4,5],[6,7,8]]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: grid = [[3,8,1,9],[19,7,2,5],[4,6,11,10],[12,0,21,13]], k = 4\nOutput: [[12,0,21,13],[3,8,1,9],[19,7,2,5],[4,6,11,10]]\n
    \n\n

    Example 3:

    \n\n
    \nInput: grid = [[1,2,3],[4,5,6],[7,8,9]], k = 9\nOutput: [[1,2,3],[4,5,6],[7,8,9]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= m <= 50
    • \n\t
    • 1 <= n <= 50
    • \n\t
    • -1000 <= grid[i][j] <= 1000
    • \n\t
    • 0 <= k <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a m \u884c n\u00a0\u5217\u7684\u4e8c\u7ef4\u7f51\u683c\u00a0grid\u00a0\u548c\u4e00\u4e2a\u6574\u6570\u00a0k\u3002\u4f60\u9700\u8981\u5c06\u00a0grid\u00a0\u8fc1\u79fb\u00a0k\u00a0\u6b21\u3002

    \n\n

    \u6bcf\u6b21\u300c\u8fc1\u79fb\u300d\u64cd\u4f5c\u5c06\u4f1a\u5f15\u53d1\u4e0b\u8ff0\u6d3b\u52a8\uff1a

    \n\n
      \n\t
    • \u4f4d\u4e8e grid[i][j]\u00a0\u7684\u5143\u7d20\u5c06\u4f1a\u79fb\u52a8\u5230\u00a0grid[i][j + 1]\u3002
    • \n\t
    • \u4f4d\u4e8e\u00a0grid[i][n\u00a0- 1] \u7684\u5143\u7d20\u5c06\u4f1a\u79fb\u52a8\u5230\u00a0grid[i + 1][0]\u3002
    • \n\t
    • \u4f4d\u4e8e grid[m\u00a0- 1][n - 1]\u00a0\u7684\u5143\u7d20\u5c06\u4f1a\u79fb\u52a8\u5230\u00a0grid[0][0]\u3002
    • \n
    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u00a0k \u6b21\u8fc1\u79fb\u64cd\u4f5c\u540e\u6700\u7ec8\u5f97\u5230\u7684 \u4e8c\u7ef4\u7f51\u683c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1agrid = [[1,2,3],[4,5,6],[7,8,9]], k = 1\n\u8f93\u51fa\uff1a[[9,1,2],[3,4,5],[6,7,8]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1agrid = [[3,8,1,9],[19,7,2,5],[4,6,11,10],[12,0,21,13]], k = 4\n\u8f93\u51fa\uff1a[[12,0,21,13],[3,8,1,9],[19,7,2,5],[4,6,11,10]]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1agrid = [[1,2,3],[4,5,6],[7,8,9]], k = 9\n\u8f93\u51fa\uff1a[[1,2,3],[4,5,6],[7,8,9]]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m ==\u00a0grid.length
    • \n\t
    • n ==\u00a0grid[i].length
    • \n\t
    • 1 <= m <= 50
    • \n\t
    • 1 <= n <= 50
    • \n\t
    • -1000 <= grid[i][j] <= 1000
    • \n\t
    • 0 <= k <= 100
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> shiftGrid(vector>& grid, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> shiftGrid(int[][] grid, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def shiftGrid(self, grid, k):\n \"\"\"\n :type grid: List[List[int]]\n :type k: int\n :rtype: List[List[int]]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def shiftGrid(self, grid: List[List[int]], k: int) -> List[List[int]]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** shiftGrid(int** grid, int gridSize, int* gridColSize, int k, int* returnSize, int** returnColumnSizes){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> ShiftGrid(int[][] grid, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @param {number} k\n * @return {number[][]}\n */\nvar shiftGrid = function(grid, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @param {Integer} k\n# @return {Integer[][]}\ndef shift_grid(grid, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func shiftGrid(_ grid: [[Int]], _ k: Int) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func shiftGrid(grid [][]int, k int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def shiftGrid(grid: Array[Array[Int]], k: Int): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun shiftGrid(grid: Array, k: Int): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn shift_grid(grid: Vec>, k: i32) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @param Integer $k\n * @return Integer[][]\n */\n function shiftGrid($grid, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function shiftGrid(grid: number[][], k: number): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (shift-grid grid k)\n (-> (listof (listof exact-integer?)) exact-integer? (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1260](https://leetcode-cn.com/problems/shift-2d-grid)", "[\u4e8c\u7ef4\u7f51\u683c\u8fc1\u79fb](/solution/1200-1299/1260.Shift%202D%20Grid/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1260](https://leetcode.com/problems/shift-2d-grid)", "[Shift 2D Grid](/solution/1200-1299/1260.Shift%202D%20Grid/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1384", "frontend_question_id": "1618", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/maximum-font-to-fit-a-sentence-in-a-screen", "url_en": "https://leetcode.com/problems/maximum-font-to-fit-a-sentence-in-a-screen", "relative_path_cn": "/solution/1600-1699/1618.Maximum%20Font%20to%20Fit%20a%20Sentence%20in%20a%20Screen/README.md", "relative_path_en": "/solution/1600-1699/1618.Maximum%20Font%20to%20Fit%20a%20Sentence%20in%20a%20Screen/README_EN.md", "title_cn": "\u627e\u51fa\u9002\u5e94\u5c4f\u5e55\u7684\u6700\u5927\u5b57\u53f7", "title_en": "Maximum Font to Fit a Sentence in a Screen", "question_title_slug": "maximum-font-to-fit-a-sentence-in-a-screen", "content_en": "

    You are given a string text. We want to display text on a screen of width w and height h. You can choose any font size from array fonts, which contains the available font sizes in ascending order.

    \r\n\r\n

    You can use the FontInfo interface to get the width and height of any character at any available font size.

    \r\n\r\n

    The FontInfo interface is defined as such:

    \r\n\r\n
    \r\ninterface FontInfo {\r\n  // Returns the width of character ch on the screen using font size fontSize.\r\n  // O(1) per call\r\n  public int getWidth(int fontSize, char ch);\r\n\r\n  // Returns the height of any character on the screen using font size fontSize.\r\n  // O(1) per call\r\n  public int getHeight(int fontSize);\r\n}
    \r\n\r\n

    The calculated width of text for some fontSize is the sum of every getWidth(fontSize, text[i]) call for each 0 <= i < text.length (0-indexed). The calculated height of text for some fontSize is getHeight(fontSize). Note that text is displayed on a single line.

    \r\n\r\n

    It is guaranteed that FontInfo will return the same value if you call getHeight or getWidth with the same parameters.

    \r\n\r\n

    It is also guaranteed that for any font size fontSize and any character ch:

    \r\n\r\n
      \r\n\t
    • getHeight(fontSize) <= getHeight(fontSize+1)
    • \r\n\t
    • getWidth(fontSize, ch) <= getWidth(fontSize+1, ch)
    • \r\n
    \r\n\r\n

    Return the maximum font size you can use to display text on the screen. If text cannot fit on the display with any font size, return -1.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: text = "helloworld", w = 80, h = 20, fonts = [6,8,10,12,14,16,18,24,36]\r\nOutput: 6\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: text = "leetcode", w = 1000, h = 50, fonts = [1,2,4]\r\nOutput: 4\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: text = "easyquestion", w = 100, h = 100, fonts = [10,15,20,25]\r\nOutput: -1\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= text.length <= 50000
    • \r\n\t
    • text contains only lowercase English letters.
    • \r\n\t
    • 1 <= w <= 107
    • \r\n\t
    • 1 <= h <= 104
    • \r\n\t
    • 1 <= fonts.length <= 105
    • \r\n\t
    • 1 <= fonts[i] <= 105
    • \r\n\t
    • fonts is sorted in ascending order and does not contain duplicates.
    • \r\n
    ", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\u00a0text\u3002\u5e76\u80fd\u591f\u5728 \u5bbd\u4e3a w \u9ad8\u4e3a h \u7684\u5c4f\u5e55\u4e0a\u663e\u793a\u8be5\u6587\u672c\u3002

    \n\n

    \u5b57\u4f53\u6570\u7ec4\u4e2d\u5305\u542b\u6309\u5347\u5e8f\u6392\u5217\u7684\u53ef\u7528\u5b57\u53f7\uff0c\u60a8\u53ef\u4ee5\u4ece\u8be5\u6570\u7ec4\u4e2d\u9009\u62e9\u4efb\u4f55\u5b57\u4f53\u5927\u5c0f\u3002

    \n\n

    \u60a8\u53ef\u4ee5\u4f7f\u7528FontInfo\u63a5\u53e3\u6765\u83b7\u53d6\u4efb\u4f55\u53ef\u7528\u5b57\u4f53\u5927\u5c0f\u7684\u4efb\u4f55\u5b57\u7b26\u7684\u5bbd\u5ea6\u548c\u9ad8\u5ea6\u3002

    \n\n

    FontInfo\u63a5\u53e3\u5b9a\u4e49\u5982\u4e0b\uff1a

    \n\n
    interface FontInfo {\n  // \u8fd4\u56de fontSize \u5927\u5c0f\u7684\u5b57\u7b26 ch \u5728\u5c4f\u5e55\u4e0a\u7684\u5bbd\u5ea6\u3002\n  // \u6bcf\u8c03\u7528\u8be5\u51fd\u6570\u590d\u6742\u5ea6\u4e3a O(1)\n  public int getWidth(int fontSize, char ch);\n\n  // \u8fd4\u56de fontSize \u5927\u5c0f\u7684\u4efb\u610f\u5b57\u7b26\u5728\u5c4f\u5e55\u4e0a\u7684\u9ad8\u5ea6\u3002\n  // \u6bcf\u8c03\u7528\u8be5\u51fd\u6570\u590d\u6742\u5ea6\u4e3a O(1)\n  public int getHeight(int fontSize);\n}
    \n\n

    \u4e00\u4e32\u5b57\u7b26\u7684\u6587\u672c\u5bbd\u5ea6\u5e94\u8be5\u662f\u6bcf\u4e00\u4e2a\u5b57\u7b26\u5728\u5bf9\u5e94\u5b57\u53f7(fontSize)\u4e0b\u8fd4\u56de\u7684\u5bbd\u5ea6getHeight(fontSize)\u7684\u603b\u548c\u3002

    \n\n

    \u8bf7\u6ce8\u610f\uff1a\u6587\u672c\u6700\u591a\u53ea\u80fd\u6392\u653e\u4e00\u6392

    \n\n

    \u5982\u679c\u4f7f\u7528\u76f8\u540c\u7684\u53c2\u6570\u8c03\u7528 getHeight\u00a0\u6216\u00a0getWidth \uff0c\u5219\u53ef\u4ee5\u4fdd\u8bc1 FontInfo \u5c06\u8fd4\u56de\u76f8\u540c\u7684\u503c\u3002

    \n\n

    \u540c\u65f6\uff0c\u5bf9\u4e8e\u4efb\u4f55\u5b57\u4f53\u5927\u5c0f\u7684\u00a0fontSize \u548c\u4efb\u4f55\u5b57\u7b26 ch \uff1a

    \n\n
      \n\t
    • getHeight(fontSize) <= getHeight(fontSize+1)
    • \n\t
    • getWidth(fontSize, ch) <= getWidth(fontSize+1, ch)
    • \n
    \n\n

    \u8fd4\u56de\u53ef\u7528\u4e8e\u5728\u5c4f\u5e55\u4e0a\u663e\u793a\u6587\u672c\u7684\u6700\u5927\u5b57\u4f53\u5927\u5c0f\u3002\u5982\u679c\u6587\u672c\u4e0d\u80fd\u4ee5\u4efb\u4f55\u5b57\u4f53\u5927\u5c0f\u663e\u793a\uff0c\u5219\u8fd4\u56de-1\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: text = \"helloworld\", w = 80, h = 20, fonts = [6,8,10,12,14,16,18,24,36]\n\u8f93\u51fa: 6\n
    \n\n

    Example 2:

    \n\n
    \u8f93\u5165: text = \"leetcode\", w = 1000, h = 50, fonts = [1,2,4]\n\u8f93\u51fa: 4\n
    \n\n

    Example 3:

    \n\n
    \u8f93\u5165: text = \"easyquestion\", w = 100, h = 100, fonts = [10,15,20,25]\n\u8f93\u51fa: -1\n
    \n\n

    \u00a0

    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    • 1 <= text.length <= 50000
    • \n\t
    • text \u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd
    • \n\t
    • 1 <= w <= 107
    • \n\t
    • 1 <= h <= 104
    • \n\t
    • 1 <= fonts.length <= 105
    • \n\t
    • 1 <= fonts[i] <= 105
    • \n\t
    • fonts\u00a0\u5df2\u7ecf\u6309\u5347\u5e8f\u6392\u5e8f\uff0c\u4e14\u4e0d\u5305\u542b\u91cd\u590d\u9879\u3002
    • \n
    \n", "tags_en": ["String", "Binary Search"], "tags_cn": ["\u5b57\u7b26\u4e32", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * // This is the FontInfo's API interface.\n * // You should not implement it, or speculate about its implementation\n * class FontInfo {\n * public:\n * // Return the width of char ch when fontSize is used.\n * int getWidth(int fontSize, char ch);\n * \n * // Return Height of any char when fontSize is used.\n * int getHeight(int fontSize)\n * };\n */\nclass Solution {\npublic:\n int maxFont(string text, int w, int h, vector& fonts, FontInfo fontInfo) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * // This is the FontInfo's API interface.\n * // You should not implement it, or speculate about its implementation\n * interface FontInfo {\n * // Return the width of char ch when fontSize is used.\n * public int getWidth(int fontSize, char ch) {}\n * // Return Height of any char when fontSize is used.\n * public int getHeight(int fontSize)\n * }\n */\nclass Solution {\n public int maxFont(String text, int w, int h, int[] fonts, FontInfo fontInfo) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# \"\"\"\n# This is FontInfo's API interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class FontInfo(object):\n# Return the width of char ch when fontSize is used.\n# def getWidth(self, fontSize, ch):\n# \"\"\"\n# :type fontSize: int\n# :type ch: char\n# :rtype int\n# \"\"\"\n# \n# def getHeight(self, fontSize):\n# \"\"\"\n# :type fontSize: int\n# :rtype int\n# \"\"\"\nclass Solution(object):\n def maxFont(self, text, w, h, fonts, fontInfo):\n \"\"\"\n :type text: str\n :type w: int\n :type h: int\n :type fonts: List[int]\n :type fontInfo: FontInfo\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# \"\"\"\n# This is FontInfo's API interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class FontInfo(object):\n# Return the width of char ch when fontSize is used.\n# def getWidth(self, fontSize, ch):\n# \"\"\"\n# :type fontSize: int\n# :type ch: char\n# :rtype int\n# \"\"\"\n# \n# def getHeight(self, fontSize):\n# \"\"\"\n# :type fontSize: int\n# :rtype int\n# \"\"\"\nclass Solution:\n def maxFont(self, text: str, w: int, h: int, fonts: List[int], fontInfo : 'FontInfo') -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * // This is the FontInfo's API interface.\n * // You should not implement it, or speculate about its implementation\n * interface FontInfo {\n * // Return the width of char ch when fontSize is used.\n * public int GetWidth(int fontSize, char ch) {}\n * // Return Height of any char when fontSize is used.\n * public int GetHeight(int fontSize)\n * }\n */\npublic class Solution {\n public int MaxFont(string text, int w, int h, int[] fonts, FontInfo fontInfo) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // This is the FontInfo's API interface.\n * // You should not implement it, or speculate about its implementation\n * function FontInfo() {\n *\n *\t\t@param {number} fontSize\n *\t\t@param {char} ch\n * \t@return {number}\n * \tthis.getWidth = function(fontSize, ch) {\n * \t...\n * \t};\n *\n *\t\t@param {number} fontSize\n * \t@return {number}\n * \tthis.getHeight = function(fontSize) {\n * \t...\n * \t};\n * };\n */\n/**\n * @param {string} text\n * @param {number} w\n * @param {number} h\n * @param {number[]} fonts\n * @param {FontInfo} fontInfo\n * @return {number}\n */\nvar maxFont = function(text, w, h, fonts, fontInfo) {\n \n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1618](https://leetcode-cn.com/problems/maximum-font-to-fit-a-sentence-in-a-screen)", "[\u627e\u51fa\u9002\u5e94\u5c4f\u5e55\u7684\u6700\u5927\u5b57\u53f7](/solution/1600-1699/1618.Maximum%20Font%20to%20Fit%20a%20Sentence%20in%20a%20Screen/README.md)", "`\u5b57\u7b26\u4e32`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1618](https://leetcode.com/problems/maximum-font-to-fit-a-sentence-in-a-screen)", "[Maximum Font to Fit a Sentence in a Screen](/solution/1600-1699/1618.Maximum%20Font%20to%20Fit%20a%20Sentence%20in%20a%20Screen/README_EN.md)", "`String`,`Binary Search`", "Medium", "\ud83d\udd12"]}, {"question_id": "1381", "frontend_question_id": "1255", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-score-words-formed-by-letters", "url_en": "https://leetcode.com/problems/maximum-score-words-formed-by-letters", "relative_path_cn": "/solution/1200-1299/1255.Maximum%20Score%20Words%20Formed%20by%20Letters/README.md", "relative_path_en": "/solution/1200-1299/1255.Maximum%20Score%20Words%20Formed%20by%20Letters/README_EN.md", "title_cn": "\u5f97\u5206\u6700\u9ad8\u7684\u5355\u8bcd\u96c6\u5408", "title_en": "Maximum Score Words Formed by Letters", "question_title_slug": "maximum-score-words-formed-by-letters", "content_en": "

    Given a list of words, list of  single letters (might be repeating) and score of every character.

    \n\n

    Return the maximum score of any valid set of words formed by using the given letters (words[i] cannot be used two or more times).

    \n\n

    It is not necessary to use all characters in letters and each letter can only be used once. Score of letters 'a', 'b', 'c', ... ,'z' is given by score[0], score[1], ... , score[25] respectively.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: words = ["dog","cat","dad","good"], letters = ["a","a","c","d","d","d","g","o","o"], score = [1,0,9,5,0,0,3,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0]\nOutput: 23\nExplanation:\nScore  a=1, c=9, d=5, g=3, o=2\nGiven letters, we can form the words "dad" (5+1+5) and "good" (3+2+2+5) with a score of 23.\nWords "dad" and "dog" only get a score of 21.
    \n\n

    Example 2:

    \n\n
    \nInput: words = ["xxxz","ax","bx","cx"], letters = ["z","a","b","c","x","x","x"], score = [4,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,0,10]\nOutput: 27\nExplanation:\nScore  a=4, b=4, c=4, x=5, z=10\nGiven letters, we can form the words "ax" (4+5), "bx" (4+5) and "cx" (4+5) with a score of 27.\nWord "xxxz" only get a score of 25.
    \n\n

    Example 3:

    \n\n
    \nInput: words = ["leetcode"], letters = ["l","e","t","c","o","d"], score = [0,0,1,1,1,0,0,0,0,0,0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0]\nOutput: 0\nExplanation:\nLetter "e" can only be used once.
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= words.length <= 14
    • \n\t
    • 1 <= words[i].length <= 15
    • \n\t
    • 1 <= letters.length <= 100
    • \n\t
    • letters[i].length == 1
    • \n\t
    • score.length == 26
    • \n\t
    • 0 <= score[i] <= 10
    • \n\t
    • words[i], letters[i] contains only lower case English letters.
    • \n
    \n", "content_cn": "

    \u4f60\u5c06\u4f1a\u5f97\u5230\u4e00\u4efd\u5355\u8bcd\u8868 words\uff0c\u4e00\u4e2a\u5b57\u6bcd\u8868 letters \uff08\u53ef\u80fd\u4f1a\u6709\u91cd\u590d\u5b57\u6bcd\uff09\uff0c\u4ee5\u53ca\u6bcf\u4e2a\u5b57\u6bcd\u5bf9\u5e94\u7684\u5f97\u5206\u60c5\u51b5\u8868 score\u3002

    \n\n

    \u8bf7\u4f60\u5e2e\u5fd9\u8ba1\u7b97\u73a9\u5bb6\u5728\u5355\u8bcd\u62fc\u5199\u6e38\u620f\u4e2d\u6240\u80fd\u83b7\u5f97\u7684\u300c\u6700\u9ad8\u5f97\u5206\u300d\uff1a\u80fd\u591f\u7531 letters \u91cc\u7684\u5b57\u6bcd\u62fc\u5199\u51fa\u7684 \u4efb\u610f \u5c5e\u4e8e words \u5355\u8bcd\u5b50\u96c6\u4e2d\uff0c\u5206\u6570\u6700\u9ad8\u7684\u5355\u8bcd\u96c6\u5408\u7684\u5f97\u5206\u3002

    \n\n

    \u5355\u8bcd\u62fc\u5199\u6e38\u620f\u7684\u89c4\u5219\u6982\u8ff0\u5982\u4e0b\uff1a

    \n\n
      \n\t
    • \u73a9\u5bb6\u9700\u8981\u7528\u5b57\u6bcd\u8868 letters \u91cc\u7684\u5b57\u6bcd\u6765\u62fc\u5199\u5355\u8bcd\u8868 words \u4e2d\u7684\u5355\u8bcd\u3002
    • \n\t
    • \u53ef\u4ee5\u53ea\u4f7f\u7528\u5b57\u6bcd\u8868 letters \u4e2d\u7684\u90e8\u5206\u5b57\u6bcd\uff0c\u4f46\u662f\u6bcf\u4e2a\u5b57\u6bcd\u6700\u591a\u88ab\u4f7f\u7528\u4e00\u6b21\u3002
    • \n\t
    • \u5355\u8bcd\u8868 words \u4e2d\u6bcf\u4e2a\u5355\u8bcd\u53ea\u80fd\u8ba1\u5206\uff08\u4f7f\u7528\uff09\u4e00\u6b21\u3002
    • \n\t
    • \u6839\u636e\u5b57\u6bcd\u5f97\u5206\u60c5\u51b5\u8868score\uff0c\u5b57\u6bcd 'a''b''c', ... , 'z' \u5bf9\u5e94\u7684\u5f97\u5206\u5206\u522b\u4e3a score[0], score[1], ..., score[25]\u3002
    • \n\t
    • \u672c\u573a\u6e38\u620f\u7684\u300c\u5f97\u5206\u300d\u662f\u6307\uff1a\u73a9\u5bb6\u6240\u62fc\u5199\u51fa\u7684\u5355\u8bcd\u96c6\u5408\u91cc\u5305\u542b\u7684\u6240\u6709\u5b57\u6bcd\u7684\u5f97\u5206\u4e4b\u548c\u3002
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1awords = ["dog","cat","dad","good"], letters = ["a","a","c","d","d","d","g","o","o"], score = [1,0,9,5,0,0,3,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0]\n\u8f93\u51fa\uff1a23\n\u89e3\u91ca\uff1a\n\u5b57\u6bcd\u5f97\u5206\u4e3a  a=1, c=9, d=5, g=3, o=2\n\u4f7f\u7528\u7ed9\u5b9a\u7684\u5b57\u6bcd\u8868 letters\uff0c\u6211\u4eec\u53ef\u4ee5\u62fc\u5199\u5355\u8bcd "dad" (5+1+5)\u548c "good" (3+2+2+5)\uff0c\u5f97\u5206\u4e3a 23 \u3002\n\u800c\u5355\u8bcd "dad" \u548c "dog" \u53ea\u80fd\u5f97\u5230 21 \u5206\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1awords = ["xxxz","ax","bx","cx"], letters = ["z","a","b","c","x","x","x"], score = [4,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,0,10]\n\u8f93\u51fa\uff1a27\n\u89e3\u91ca\uff1a\n\u5b57\u6bcd\u5f97\u5206\u4e3a  a=4, b=4, c=4, x=5, z=10\n\u4f7f\u7528\u7ed9\u5b9a\u7684\u5b57\u6bcd\u8868 letters\uff0c\u6211\u4eec\u53ef\u4ee5\u7ec4\u6210\u5355\u8bcd "ax" (4+5)\uff0c "bx" (4+5) \u548c "cx" (4+5) \uff0c\u603b\u5f97\u5206\u4e3a 27 \u3002\n\u5355\u8bcd "xxxz" \u7684\u5f97\u5206\u4ec5\u4e3a 25 \u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1awords = ["leetcode"], letters = ["l","e","t","c","o","d"], score = [0,0,1,1,1,0,0,0,0,0,0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\n\u5b57\u6bcd "e" \u5728\u5b57\u6bcd\u8868 letters \u4e2d\u53ea\u51fa\u73b0\u4e86\u4e00\u6b21\uff0c\u6240\u4ee5\u65e0\u6cd5\u7ec4\u6210\u5355\u8bcd\u8868 words \u4e2d\u7684\u5355\u8bcd\u3002
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= words.length <= 14
    • \n\t
    • 1 <= words[i].length <= 15
    • \n\t
    • 1 <= letters.length <= 100
    • \n\t
    • letters[i].length == 1
    • \n\t
    • score.length == 26
    • \n\t
    • 0 <= score[i] <= 10
    • \n\t
    • words[i] \u548c letters[i] \u53ea\u5305\u542b\u5c0f\u5199\u7684\u82f1\u6587\u5b57\u6bcd\u3002
    • \n
    \n", "tags_en": ["Bit Manipulation"], "tags_cn": ["\u4f4d\u8fd0\u7b97"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxScoreWords(vector& words, vector& letters, vector& score) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxScoreWords(String[] words, char[] letters, int[] score) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxScoreWords(self, words, letters, score):\n \"\"\"\n :type words: List[str]\n :type letters: List[str]\n :type score: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxScoreWords(self, words: List[str], letters: List[str], score: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxScoreWords(char ** words, int wordsSize, char* letters, int lettersSize, int* score, int scoreSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxScoreWords(string[] words, char[] letters, int[] score) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @param {character[]} letters\n * @param {number[]} score\n * @return {number}\n */\nvar maxScoreWords = function(words, letters, score) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @param {Character[]} letters\n# @param {Integer[]} score\n# @return {Integer}\ndef max_score_words(words, letters, score)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxScoreWords(_ words: [String], _ letters: [Character], _ score: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxScoreWords(words []string, letters []byte, score []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxScoreWords(words: Array[String], letters: Array[Char], score: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxScoreWords(words: Array, letters: CharArray, score: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_score_words(words: Vec, letters: Vec, score: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @param String[] $letters\n * @param Integer[] $score\n * @return Integer\n */\n function maxScoreWords($words, $letters, $score) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxScoreWords(words: string[], letters: string[], score: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-score-words words letters score)\n (-> (listof string?) (listof char?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1255](https://leetcode-cn.com/problems/maximum-score-words-formed-by-letters)", "[\u5f97\u5206\u6700\u9ad8\u7684\u5355\u8bcd\u96c6\u5408](/solution/1200-1299/1255.Maximum%20Score%20Words%20Formed%20by%20Letters/README.md)", "`\u4f4d\u8fd0\u7b97`", "\u56f0\u96be", ""], "md_table_row_en": ["[1255](https://leetcode.com/problems/maximum-score-words-formed-by-letters)", "[Maximum Score Words Formed by Letters](/solution/1200-1299/1255.Maximum%20Score%20Words%20Formed%20by%20Letters/README_EN.md)", "`Bit Manipulation`", "Hard", ""]}, {"question_id": "1380", "frontend_question_id": "1254", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-closed-islands", "url_en": "https://leetcode.com/problems/number-of-closed-islands", "relative_path_cn": "/solution/1200-1299/1254.Number%20of%20Closed%20Islands/README.md", "relative_path_en": "/solution/1200-1299/1254.Number%20of%20Closed%20Islands/README_EN.md", "title_cn": "\u7edf\u8ba1\u5c01\u95ed\u5c9b\u5c7f\u7684\u6570\u76ee", "title_en": "Number of Closed Islands", "question_title_slug": "number-of-closed-islands", "content_en": "

    Given a 2D grid consists of 0s (land) and 1s (water).  An island is a maximal 4-directionally connected group of 0s and a closed island is an island totally (all left, top, right, bottom) surrounded by 1s.

    \n\n

    Return the number of closed islands.

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: grid = [[1,1,1,1,1,1,1,0],[1,0,0,0,0,1,1,0],[1,0,1,0,1,1,1,0],[1,0,0,0,0,1,0,1],[1,1,1,1,1,1,1,0]]\nOutput: 2\nExplanation: \nIslands in gray are closed because they are completely surrounded by water (group of 1s).
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: grid = [[0,0,1,0,0],[0,1,0,1,0],[0,1,1,1,0]]\nOutput: 1\n
    \n\n

    Example 3:

    \n\n
    \nInput: grid = [[1,1,1,1,1,1,1],\n               [1,0,0,0,0,0,1],\n               [1,0,1,1,1,0,1],\n               [1,0,1,0,1,0,1],\n               [1,0,1,1,1,0,1],\n               [1,0,0,0,0,0,1],\n               [1,1,1,1,1,1,1]]\nOutput: 2\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= grid.length, grid[0].length <= 100
    • \n\t
    • 0 <= grid[i][j] <=1
    • \n
    \n", "content_cn": "

    \u6709\u4e00\u4e2a\u4e8c\u7ef4\u77e9\u9635 grid \uff0c\u6bcf\u4e2a\u4f4d\u7f6e\u8981\u4e48\u662f\u9646\u5730\uff08\u8bb0\u53f7\u4e3a 0 \uff09\u8981\u4e48\u662f\u6c34\u57df\uff08\u8bb0\u53f7\u4e3a 1 \uff09\u3002

    \n\n

    \u6211\u4eec\u4ece\u4e00\u5757\u9646\u5730\u51fa\u53d1\uff0c\u6bcf\u6b21\u53ef\u4ee5\u5f80\u4e0a\u4e0b\u5de6\u53f3 4 \u4e2a\u65b9\u5411\u76f8\u90bb\u533a\u57df\u8d70\uff0c\u80fd\u8d70\u5230\u7684\u6240\u6709\u9646\u5730\u533a\u57df\uff0c\u6211\u4eec\u5c06\u5176\u79f0\u4e3a\u4e00\u5ea7\u300c\u5c9b\u5c7f\u300d\u3002

    \n\n

    \u5982\u679c\u4e00\u5ea7\u5c9b\u5c7f \u5b8c\u5168 \u7531\u6c34\u57df\u5305\u56f4\uff0c\u5373\u9646\u5730\u8fb9\u7f18\u4e0a\u4e0b\u5de6\u53f3\u6240\u6709\u76f8\u90bb\u533a\u57df\u90fd\u662f\u6c34\u57df\uff0c\u90a3\u4e48\u6211\u4eec\u5c06\u5176\u79f0\u4e3a \u300c\u5c01\u95ed\u5c9b\u5c7f\u300d\u3002

    \n\n

    \u8bf7\u8fd4\u56de\u5c01\u95ed\u5c9b\u5c7f\u7684\u6570\u76ee\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \n\n
    \u8f93\u5165\uff1agrid = [[1,1,1,1,1,1,1,0],[1,0,0,0,0,1,1,0],[1,0,1,0,1,1,1,0],[1,0,0,0,0,1,0,1],[1,1,1,1,1,1,1,0]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n\u7070\u8272\u533a\u57df\u7684\u5c9b\u5c7f\u662f\u5c01\u95ed\u5c9b\u5c7f\uff0c\u56e0\u4e3a\u8fd9\u5ea7\u5c9b\u5c7f\u5b8c\u5168\u88ab\u6c34\u57df\u5305\u56f4\uff08\u5373\u88ab 1 \u533a\u57df\u5305\u56f4\uff09\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \n\n
    \u8f93\u5165\uff1agrid = [[0,0,1,0,0],[0,1,0,1,0],[0,1,1,1,0]]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1agrid = [[1,1,1,1,1,1,1],\n             [1,0,0,0,0,0,1],\n             [1,0,1,1,1,0,1],\n             [1,0,1,0,1,0,1],\n             [1,0,1,1,1,0,1],\n             [1,0,0,0,0,0,1],\n             [1,1,1,1,1,1,1]]\n\u8f93\u51fa\uff1a2\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= grid.length, grid[0].length <= 100
    • \n\t
    • 0 <= grid[i][j] <=1
    • \n
    \n", "tags_en": ["Depth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int closedIsland(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int closedIsland(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def closedIsland(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def closedIsland(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint closedIsland(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ClosedIsland(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar closedIsland = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef closed_island(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func closedIsland(_ grid: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func closedIsland(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def closedIsland(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun closedIsland(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn closed_island(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function closedIsland($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function closedIsland(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (closed-island grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1254](https://leetcode-cn.com/problems/number-of-closed-islands)", "[\u7edf\u8ba1\u5c01\u95ed\u5c9b\u5c7f\u7684\u6570\u76ee](/solution/1200-1299/1254.Number%20of%20Closed%20Islands/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1254](https://leetcode.com/problems/number-of-closed-islands)", "[Number of Closed Islands](/solution/1200-1299/1254.Number%20of%20Closed%20Islands/README_EN.md)", "`Depth-first Search`", "Medium", ""]}, {"question_id": "1379", "frontend_question_id": "1253", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reconstruct-a-2-row-binary-matrix", "url_en": "https://leetcode.com/problems/reconstruct-a-2-row-binary-matrix", "relative_path_cn": "/solution/1200-1299/1253.Reconstruct%20a%202-Row%20Binary%20Matrix/README.md", "relative_path_en": "/solution/1200-1299/1253.Reconstruct%20a%202-Row%20Binary%20Matrix/README_EN.md", "title_cn": "\u91cd\u6784 2 \u884c\u4e8c\u8fdb\u5236\u77e9\u9635", "title_en": "Reconstruct a 2-Row Binary Matrix", "question_title_slug": "reconstruct-a-2-row-binary-matrix", "content_en": "

    Given the following details of a matrix with n columns and 2 rows :

    \n\n
      \n\t
    • The matrix is a binary matrix, which means each element in the matrix can be 0 or 1.
    • \n\t
    • The sum of elements of the 0-th(upper) row is given as upper.
    • \n\t
    • The sum of elements of the 1-st(lower) row is given as lower.
    • \n\t
    • The sum of elements in the i-th column(0-indexed) is colsum[i], where colsum is given as an integer array with length n.
    • \n
    \n\n

    Your task is to reconstruct the matrix with upper, lower and colsum.

    \n\n

    Return it as a 2-D integer array.

    \n\n

    If there are more than one valid solution, any of them will be accepted.

    \n\n

    If no valid solution exists, return an empty 2-D array.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: upper = 2, lower = 1, colsum = [1,1,1]\nOutput: [[1,1,0],[0,0,1]]\nExplanation: [[1,0,1],[0,1,0]], and [[0,1,1],[1,0,0]] are also correct answers.\n
    \n\n

    Example 2:

    \n\n
    \nInput: upper = 2, lower = 3, colsum = [2,2,1,1]\nOutput: []\n
    \n\n

    Example 3:

    \n\n
    \nInput: upper = 5, lower = 5, colsum = [2,1,2,0,1,0,1,2,0,1]\nOutput: [[1,1,1,0,1,0,0,1,0,0],[1,0,1,0,0,0,1,1,0,1]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= colsum.length <= 10^5
    • \n\t
    • 0 <= upper, lower <= colsum.length
    • \n\t
    • 0 <= colsum[i] <= 2
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a 2 \u884c n \u5217\u7684\u4e8c\u8fdb\u5236\u6570\u7ec4\uff1a

    \n\n
      \n\t
    • \u77e9\u9635\u662f\u4e00\u4e2a\u4e8c\u8fdb\u5236\u77e9\u9635\uff0c\u8fd9\u610f\u5473\u7740\u77e9\u9635\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u4e0d\u662f 0 \u5c31\u662f 1\u3002
    • \n\t
    • \u7b2c 0 \u884c\u7684\u5143\u7d20\u4e4b\u548c\u4e3a upper\u3002
    • \n\t
    • \u7b2c 1 \u884c\u7684\u5143\u7d20\u4e4b\u548c\u4e3a lower\u3002
    • \n\t
    • \u7b2c i \u5217\uff08\u4ece 0 \u5f00\u59cb\u7f16\u53f7\uff09\u7684\u5143\u7d20\u4e4b\u548c\u4e3a colsum[i]\uff0ccolsum \u662f\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u6574\u6570\u6570\u7ec4\u3002
    • \n
    \n\n

    \u4f60\u9700\u8981\u5229\u7528 upper\uff0clower \u548c colsum \u6765\u91cd\u6784\u8fd9\u4e2a\u77e9\u9635\uff0c\u5e76\u4ee5\u4e8c\u7ef4\u6574\u6570\u6570\u7ec4\u7684\u5f62\u5f0f\u8fd4\u56de\u5b83\u3002

    \n\n

    \u5982\u679c\u6709\u591a\u4e2a\u4e0d\u540c\u7684\u7b54\u6848\uff0c\u90a3\u4e48\u4efb\u610f\u4e00\u4e2a\u90fd\u53ef\u4ee5\u901a\u8fc7\u672c\u9898\u3002

    \n\n

    \u5982\u679c\u4e0d\u5b58\u5728\u7b26\u5408\u8981\u6c42\u7684\u7b54\u6848\uff0c\u5c31\u8bf7\u8fd4\u56de\u4e00\u4e2a\u7a7a\u7684\u4e8c\u7ef4\u6570\u7ec4\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aupper = 2, lower = 1, colsum = [1,1,1]\n\u8f93\u51fa\uff1a[[1,1,0],[0,0,1]]\n\u89e3\u91ca\uff1a[[1,0,1],[0,1,0]] \u548c [[0,1,1],[1,0,0]] \u4e5f\u662f\u6b63\u786e\u7b54\u6848\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aupper = 2, lower = 3, colsum = [2,2,1,1]\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aupper = 5, lower = 5, colsum = [2,1,2,0,1,0,1,2,0,1]\n\u8f93\u51fa\uff1a[[1,1,1,0,1,0,0,1,0,0],[1,0,1,0,0,0,1,1,0,1]]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= colsum.length <= 10^5
    • \n\t
    • 0 <= upper, lower <= colsum.length
    • \n\t
    • 0 <= colsum[i] <= 2
    • \n
    \n", "tags_en": ["Greedy", "Math"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> reconstructMatrix(int upper, int lower, vector& colsum) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> reconstructMatrix(int upper, int lower, int[] colsum) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def reconstructMatrix(self, upper, lower, colsum):\n \"\"\"\n :type upper: int\n :type lower: int\n :type colsum: List[int]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def reconstructMatrix(self, upper: int, lower: int, colsum: List[int]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** reconstructMatrix(int upper, int lower, int* colsum, int colsumSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> ReconstructMatrix(int upper, int lower, int[] colsum) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} upper\n * @param {number} lower\n * @param {number[]} colsum\n * @return {number[][]}\n */\nvar reconstructMatrix = function(upper, lower, colsum) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} upper\n# @param {Integer} lower\n# @param {Integer[]} colsum\n# @return {Integer[][]}\ndef reconstruct_matrix(upper, lower, colsum)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func reconstructMatrix(_ upper: Int, _ lower: Int, _ colsum: [Int]) -> [[Int]] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func reconstructMatrix(upper int, lower int, colsum []int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def reconstructMatrix(upper: Int, lower: Int, colsum: Array[Int]): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun reconstructMatrix(upper: Int, lower: Int, colsum: IntArray): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn reconstruct_matrix(upper: i32, lower: i32, colsum: Vec) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $upper\n * @param Integer $lower\n * @param Integer[] $colsum\n * @return Integer[][]\n */\n function reconstructMatrix($upper, $lower, $colsum) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function reconstructMatrix(upper: number, lower: number, colsum: number[]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (reconstruct-matrix upper lower colsum)\n (-> exact-integer? exact-integer? (listof exact-integer?) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1253](https://leetcode-cn.com/problems/reconstruct-a-2-row-binary-matrix)", "[\u91cd\u6784 2 \u884c\u4e8c\u8fdb\u5236\u77e9\u9635](/solution/1200-1299/1253.Reconstruct%20a%202-Row%20Binary%20Matrix/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1253](https://leetcode.com/problems/reconstruct-a-2-row-binary-matrix)", "[Reconstruct a 2-Row Binary Matrix](/solution/1200-1299/1253.Reconstruct%20a%202-Row%20Binary%20Matrix/README_EN.md)", "`Greedy`,`Math`", "Medium", ""]}, {"question_id": "1378", "frontend_question_id": "1252", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/cells-with-odd-values-in-a-matrix", "url_en": "https://leetcode.com/problems/cells-with-odd-values-in-a-matrix", "relative_path_cn": "/solution/1200-1299/1252.Cells%20with%20Odd%20Values%20in%20a%20Matrix/README.md", "relative_path_en": "/solution/1200-1299/1252.Cells%20with%20Odd%20Values%20in%20a%20Matrix/README_EN.md", "title_cn": "\u5947\u6570\u503c\u5355\u5143\u683c\u7684\u6570\u76ee", "title_en": "Cells with Odd Values in a Matrix", "question_title_slug": "cells-with-odd-values-in-a-matrix", "content_en": "

    There is an m x n matrix that is initialized to all 0's. There is also a 2D array indices where each indices[i] = [ri, ci] represents a 0-indexed location to perform some increment operations on the matrix.

    \n\n

    For each location indices[i], do both of the following:

    \n\n
      \n\t
    1. Increment all the cells on row ri.
    2. \n\t
    3. Increment all the cells on column ci.
    4. \n
    \n\n

    Given m, n, and indices, return the number of odd-valued cells in the matrix after applying the increment to all locations in indices.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: m = 2, n = 3, indices = [[0,1],[1,1]]\nOutput: 6\nExplanation: Initial matrix = [[0,0,0],[0,0,0]].\nAfter applying first increment it becomes [[1,2,1],[0,1,0]].\nThe final matrix is [[1,3,1],[1,3,1]], which contains 6 odd numbers.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: m = 2, n = 2, indices = [[1,1],[0,0]]\nOutput: 0\nExplanation: Final matrix = [[2,2],[2,2]]. There are no odd numbers in the final matrix.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= m, n <= 50
    • \n\t
    • 1 <= indices.length <= 100
    • \n\t
    • 0 <= ri < m
    • \n\t
    • 0 <= ci < n
    • \n
    \n\n

     

    \n

    Follow up: Could you solve this in O(n + m + indices.length) time with only O(n + m) extra space?

    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a m x n \u7684\u77e9\u9635\uff0c\u6700\u5f00\u59cb\u7684\u65f6\u5019\uff0c\u6bcf\u4e2a\u5355\u5143\u683c\u4e2d\u7684\u503c\u90fd\u662f 0\u3002

    \n\n

    \u53e6\u6709\u4e00\u4e2a\u4e8c\u7ef4\u7d22\u5f15\u6570\u7ec4\u00a0indices\uff0cindices[i] = [ri, ci] \u6307\u5411\u77e9\u9635\u4e2d\u7684\u67d0\u4e2a\u4f4d\u7f6e\uff0c\u5176\u4e2d ri \u548c ci \u5206\u522b\u8868\u793a\u6307\u5b9a\u7684\u884c\u548c\u5217\uff08\u4ece 0 \u5f00\u59cb\u7f16\u53f7\uff09\u3002

    \n\n

    \u5bf9 indices[i] \u6240\u6307\u5411\u7684\u6bcf\u4e2a\u4f4d\u7f6e\uff0c\u5e94\u540c\u65f6\u6267\u884c\u4e0b\u8ff0\u589e\u91cf\u64cd\u4f5c\uff1a

    \n\n
      \n\t
    1. ri \u884c\u4e0a\u7684\u6240\u6709\u5355\u5143\u683c\uff0c\u52a0 1 \u3002
    2. \n\t
    3. ci \u5217\u4e0a\u7684\u6240\u6709\u5355\u5143\u683c\uff0c\u52a0 1 \u3002
    4. \n
    \n\n

    \u7ed9\u4f60 m\u3001n \u548c indices \u3002\u8bf7\u4f60\u5728\u6267\u884c\u5b8c\u6240\u6709\u00a0indices\u00a0\u6307\u5b9a\u7684\u589e\u91cf\u64cd\u4f5c\u540e\uff0c\u8fd4\u56de\u77e9\u9635\u4e2d \u5947\u6570\u503c\u5355\u5143\u683c \u7684\u6570\u76ee\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1am = 2, n = 3, indices = [[0,1],[1,1]]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u6700\u5f00\u59cb\u7684\u77e9\u9635\u662f [[0,0,0],[0,0,0]]\u3002\n\u7b2c\u4e00\u6b21\u589e\u91cf\u64cd\u4f5c\u540e\u5f97\u5230 [[1,2,1],[0,1,0]]\u3002\n\u6700\u540e\u7684\u77e9\u9635\u662f [[1,3,1],[1,3,1]]\uff0c\u91cc\u9762\u6709 6 \u4e2a\u5947\u6570\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1am = 2, n = 2, indices = [[1,1],[0,0]]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6700\u540e\u7684\u77e9\u9635\u662f [[2,2],[2,2]]\uff0c\u91cc\u9762\u6ca1\u6709\u5947\u6570\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= m, n <= 50
    • \n\t
    • 1 <= indices.length <= 100
    • \n\t
    • 0 <= ri < m
    • \n\t
    • 0 <= ci < n
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u53ef\u4ee5\u8bbe\u8ba1\u4e00\u4e2a\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n + m + indices.length) \u4e14\u4ec5\u7528 O(n + m) \u989d\u5916\u7a7a\u95f4\u7684\u7b97\u6cd5\u6765\u89e3\u51b3\u6b64\u95ee\u9898\u5417\uff1f

    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int oddCells(int m, int n, vector>& indices) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int oddCells(int m, int n, int[][] indices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def oddCells(self, m, n, indices):\n \"\"\"\n :type m: int\n :type n: int\n :type indices: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint oddCells(int m, int n, int** indices, int indicesSize, int* indicesColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int OddCells(int m, int n, int[][] indices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} m\n * @param {number} n\n * @param {number[][]} indices\n * @return {number}\n */\nvar oddCells = function(m, n, indices) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} m\n# @param {Integer} n\n# @param {Integer[][]} indices\n# @return {Integer}\ndef odd_cells(m, n, indices)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func oddCells(_ m: Int, _ n: Int, _ indices: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func oddCells(m int, n int, indices [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def oddCells(m: Int, n: Int, indices: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun oddCells(m: Int, n: Int, indices: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn odd_cells(m: i32, n: i32, indices: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $m\n * @param Integer $n\n * @param Integer[][] $indices\n * @return Integer\n */\n function oddCells($m, $n, $indices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function oddCells(m: number, n: number, indices: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (odd-cells m n indices)\n (-> exact-integer? exact-integer? (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1252](https://leetcode-cn.com/problems/cells-with-odd-values-in-a-matrix)", "[\u5947\u6570\u503c\u5355\u5143\u683c\u7684\u6570\u76ee](/solution/1200-1299/1252.Cells%20with%20Odd%20Values%20in%20a%20Matrix/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1252](https://leetcode.com/problems/cells-with-odd-values-in-a-matrix)", "[Cells with Odd Values in a Matrix](/solution/1200-1299/1252.Cells%20with%20Odd%20Values%20in%20a%20Matrix/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1377", "frontend_question_id": "1241", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/number-of-comments-per-post", "url_en": "https://leetcode.com/problems/number-of-comments-per-post", "relative_path_cn": "/solution/1200-1299/1241.Number%20of%20Comments%20per%20Post/README.md", "relative_path_en": "/solution/1200-1299/1241.Number%20of%20Comments%20per%20Post/README_EN.md", "title_cn": "\u6bcf\u4e2a\u5e16\u5b50\u7684\u8bc4\u8bba\u6570", "title_en": "Number of Comments per Post", "question_title_slug": "number-of-comments-per-post", "content_en": "

    Table: Submissions

    \n\n
    \n+---------------+----------+\n| Column Name   | Type     |\n+---------------+----------+\n| sub_id        | int      |\n| parent_id     | int      |\n+---------------+----------+\nThere is no primary key for this table, it may have duplicate rows.\nEach row can be a post or comment on the post.\nparent_id is null for posts.\nparent_id for comments is sub_id for another post in the table.\n
    \n\n

     

    \n\n

    Write an SQL query to find number of comments per each post.

    \n\n

    Result table should contain post_id and its corresponding number_of_comments, and must be sorted by post_id in ascending order.

    \n\n

    Submissions may contain duplicate comments. You should count the number of unique comments per post.

    \n\n

    Submissions may contain duplicate posts. You should treat them as one post.

    \n\n

    The query result format is in the following example:

    \n\n
    \nSubmissions table:\n+---------+------------+\n| sub_id  | parent_id  |\n+---------+------------+\n| 1       | Null       |\n| 2       | Null       |\n| 1       | Null       |\n| 12      | Null       |\n| 3       | 1          |\n| 5       | 2          |\n| 3       | 1          |\n| 4       | 1          |\n| 9       | 1          |\n| 10      | 2          |\n| 6       | 7          |\n+---------+------------+\n\nResult table:\n+---------+--------------------+\n| post_id | number_of_comments |\n+---------+--------------------+\n| 1       | 3                  |\n| 2       | 2                  |\n| 12      | 0                  |\n+---------+--------------------+\n\nThe post with id 1 has three comments in the table with id 3, 4 and 9. The comment with id 3 is repeated in the table, we counted it only once.\nThe post with id 2 has two comments in the table with id 5 and 10.\nThe post with id 12 has no comments in the table.\nThe comment with id 6 is a comment on a deleted post with id 7 so we ignored it.\n
    \n", "content_cn": "

    \u8868 Submissions \u7ed3\u6784\u5982\u4e0b\uff1a

    \n\n
    \n+---------------+----------+\n| \u5217\u540d           | \u7c7b\u578b     |\n+---------------+----------+\n| sub_id        | int      |\n| parent_id     | int      |\n+---------------+----------+\n\u4e0a\u8868\u6ca1\u6709\u4e3b\u952e, \u6240\u4ee5\u53ef\u80fd\u4f1a\u51fa\u73b0\u91cd\u590d\u7684\u884c\u3002\n\u6bcf\u884c\u53ef\u4ee5\u662f\u4e00\u4e2a\u5e16\u5b50\u6216\u5bf9\u8be5\u5e16\u5b50\u7684\u8bc4\u8bba\u3002\n\u5982\u679c\u662f\u5e16\u5b50\u7684\u8bdd\uff0cparent_id \u5c31\u662f null\u3002\n\u5bf9\u4e8e\u8bc4\u8bba\u6765\u8bf4\uff0cparent_id \u5c31\u662f\u8868\u4e2d\u5bf9\u5e94\u5e16\u5b50\u7684 sub_id\u3002\n
    \n\n

     

    \n\n

    \u7f16\u5199 SQL \u8bed\u53e5\u4ee5\u67e5\u627e\u6bcf\u4e2a\u5e16\u5b50\u7684\u8bc4\u8bba\u6570\u3002

    \n\n

    \u7ed3\u679c\u8868\u5e94\u5305\u542b\u5e16\u5b50\u7684 post_id \u548c\u5bf9\u5e94\u7684\u8bc4\u8bba\u6570 number_of_comments \u5e76\u4e14\u6309 post_id \u5347\u5e8f\u6392\u5217\u3002

    \n\n

    Submissions \u53ef\u80fd\u5305\u542b\u91cd\u590d\u7684\u8bc4\u8bba\u3002\u60a8\u5e94\u8be5\u8ba1\u7b97\u6bcf\u4e2a\u5e16\u5b50\u7684\u552f\u4e00\u8bc4\u8bba\u6570\u3002

    \n\n

    Submissions \u53ef\u80fd\u5305\u542b\u91cd\u590d\u7684\u5e16\u5b50\u3002\u60a8\u5e94\u8be5\u5c06\u5b83\u4eec\u89c6\u4e3a\u4e00\u4e2a\u5e16\u5b50\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a\uff1a

    \n\n
    \nSubmissions table:\n+---------+------------+\n| sub_id  | parent_id  |\n+---------+------------+\n| 1       | Null       |\n| 2       | Null       |\n| 1       | Null       |\n| 12      | Null       |\n| 3       | 1          |\n| 5       | 2          |\n| 3       | 1          |\n| 4       | 1          |\n| 9       | 1          |\n| 10      | 2          |\n| 6       | 7          |\n+---------+------------+\n\n\u7ed3\u679c\u8868\uff1a\n+---------+--------------------+\n| post_id | number_of_comments |\n+---------+--------------------+\n| 1       | 3                  |\n| 2       | 2                  |\n| 12      | 0                  |\n+---------+--------------------+\n\n\u8868\u4e2d ID \u4e3a 1 \u7684\u5e16\u5b50\u6709 ID \u4e3a 3\u30014 \u548c 9 \u7684\u4e09\u4e2a\u8bc4\u8bba\u3002\u8868\u4e2d ID \u4e3a 3 \u7684\u8bc4\u8bba\u91cd\u590d\u51fa\u73b0\u4e86\uff0c\u6240\u4ee5\u6211\u4eec\u53ea\u5bf9\u5b83\u8fdb\u884c\u4e86\u4e00\u6b21\u8ba1\u6570\u3002\n\u8868\u4e2d ID \u4e3a 2 \u7684\u5e16\u5b50\u6709 ID \u4e3a 5 \u548c 10 \u7684\u4e24\u4e2a\u8bc4\u8bba\u3002\nID \u4e3a 12 \u7684\u5e16\u5b50\u5728\u8868\u4e2d\u6ca1\u6709\u8bc4\u8bba\u3002\n\u8868\u4e2d ID \u4e3a 6 \u7684\u8bc4\u8bba\u662f\u5bf9 ID \u4e3a 7 \u7684\u5df2\u5220\u9664\u5e16\u5b50\u7684\u8bc4\u8bba\uff0c\u56e0\u6b64\u6211\u4eec\u5c06\u5176\u5ffd\u7565\u3002\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1241](https://leetcode-cn.com/problems/number-of-comments-per-post)", "[\u6bcf\u4e2a\u5e16\u5b50\u7684\u8bc4\u8bba\u6570](/solution/1200-1299/1241.Number%20of%20Comments%20per%20Post/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1241](https://leetcode.com/problems/number-of-comments-per-post)", "[Number of Comments per Post](/solution/1200-1299/1241.Number%20of%20Comments%20per%20Post/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1374", "frontend_question_id": "1428", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/leftmost-column-with-at-least-a-one", "url_en": "https://leetcode.com/problems/leftmost-column-with-at-least-a-one", "relative_path_cn": "/solution/1400-1499/1428.Leftmost%20Column%20with%20at%20Least%20a%20One/README.md", "relative_path_en": "/solution/1400-1499/1428.Leftmost%20Column%20with%20at%20Least%20a%20One/README_EN.md", "title_cn": "\u81f3\u5c11\u6709\u4e00\u4e2a 1 \u7684\u6700\u5de6\u7aef\u5217", "title_en": "Leftmost Column with at Least a One", "question_title_slug": "leftmost-column-with-at-least-a-one", "content_en": "

    (This problem is an interactive problem.)

    \n\n

    A row-sorted binary matrix means that all elements are 0 or 1 and each row of the matrix is sorted in non-decreasing order.

    \n\n

    Given a row-sorted binary matrix binaryMatrix, return the index (0-indexed) of the leftmost column with a 1 in it. If such an index does not exist, return -1.

    \n\n

    You can't access the Binary Matrix directly. You may only access the matrix using a BinaryMatrix interface:

    \n\n
      \n\t
    • BinaryMatrix.get(row, col) returns the element of the matrix at index (row, col) (0-indexed).
    • \n\t
    • BinaryMatrix.dimensions() returns the dimensions of the matrix as a list of 2 elements [rows, cols], which means the matrix is rows x cols.
    • \n
    \n\n

    Submissions making more than 1000 calls to BinaryMatrix.get will be judged Wrong Answer. Also, any solutions that attempt to circumvent the judge will result in disqualification.

    \n\n

    For custom testing purposes, the input will be the entire binary matrix mat. You will not have access to the binary matrix directly.

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: mat = [[0,0],[1,1]]\nOutput: 0\n
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: mat = [[0,0],[0,1]]\nOutput: 1\n
    \n\n

    Example 3:

    \n\n

    \"\"

    \n\n
    \nInput: mat = [[0,0],[0,0]]\nOutput: -1
    \n\n

    Example 4:

    \n\n

    \"\"

    \n\n
    \nInput: mat = [[0,0,0,1],[0,0,1,1],[0,1,1,1]]\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • rows == mat.length
    • \n\t
    • cols == mat[i].length
    • \n\t
    • 1 <= rows, cols <= 100
    • \n\t
    • mat[i][j] is either 0 or 1.
    • \n\t
    • mat[i] is sorted in non-decreasing order.
    • \n
    \n", "content_cn": "

    \uff08\u8fd9\u662f\u4e00\u4e2a\u4ea4\u4e92\u9898\uff09

    \n\n

    \u6211\u4eec\u79f0\u53ea\u5305\u542b\u5143\u7d20 0 \u6216 1 \u7684\u77e9\u9635\u4e3a\u4e8c\u8fdb\u5236\u77e9\u9635\u3002\u77e9\u9635\u4e2d\u6bcf\u4e2a\u5355\u72ec\u7684\u884c\u90fd\u6309\u975e\u9012\u51cf\u987a\u5e8f\u6392\u5e8f\u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u8fd9\u6837\u7684\u4e8c\u8fdb\u5236\u77e9\u9635\uff0c\u8fd4\u56de\u81f3\u5c11\u5305\u542b\u4e00\u4e2a 1 \u7684\u6700\u5de6\u7aef\u5217\u7684\u7d22\u5f15\uff08\u4ece 0 \u5f00\u59cb\uff09\u3002\u5982\u679c\u8fd9\u6837\u7684\u5217\u4e0d\u5b58\u5728\uff0c\u8fd4\u56de -1\u3002

    \n\n

    \u60a8\u4e0d\u80fd\u76f4\u63a5\u8bbf\u95ee\u8be5\u4e8c\u8fdb\u5236\u77e9\u9635\u3002\u4f60\u53ea\u53ef\u4ee5\u901a\u8fc7 BinaryMatrix \u63a5\u53e3\u6765\u8bbf\u95ee\u3002

    \n\n
      \n\t
    • BinaryMatrix.get(row, col) \u8fd4\u56de\u4f4d\u4e8e\u7d22\u5f15 (row, col) \uff08\u4ece 0 \u5f00\u59cb\uff09\u7684\u5143\u7d20\u3002
    • \n\t
    • BinaryMatrix.dimensions() \u8fd4\u56de\u542b\u6709 2 \u4e2a\u5143\u7d20\u7684\u5217\u8868 [rows, cols]\uff0c\u8868\u793a\u8fd9\u662f\u4e00\u4e2a rows * cols\u7684\u77e9\u9635\u3002
    • \n
    \n\n

    \u5982\u679c\u63d0\u4ea4\u7684\u7b54\u6848\u8c03\u7528 BinaryMatrix.get \u8d85\u8fc7 1000 \u6b21\uff0c\u5219\u8be5\u7b54\u6848\u4f1a\u88ab\u5224\u5b9a\u4e3a\u9519\u8bef\u7b54\u6848\u3002\u63d0\u4ea4\u4efb\u4f55\u8bd5\u56fe\u89c4\u907f\u5224\u5b9a\u673a\u5236\u7684\u7b54\u6848\u5c06\u4f1a\u88ab\u53d6\u6d88\u8d44\u683c\u3002

    \n\n

    \u4e0b\u5217\u793a\u4f8b\u4e2d\uff0c mat \u4e3a\u7ed9\u5b9a\u7684\u4e8c\u8fdb\u5236\u77e9\u9635\u3002\u60a8\u4e0d\u80fd\u76f4\u63a5\u8bbf\u95ee\u8be5\u77e9\u9635\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1:

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165: mat = [[0,0],[1,1]]\n\u8f93\u51fa: 0\n
    \n\n

    \u793a\u4f8b 2:

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165: mat = [[0,0],[0,1]]\n\u8f93\u51fa: 1\n
    \n\n

    \u793a\u4f8b 3:

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165: mat = [[0,0],[0,0]]\n\u8f93\u51fa: -1
    \n\n

    \u793a\u4f8b 4:

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165: mat = [[0,0,0,1],[0,0,1,1],[0,1,1,1]]\n\u8f93\u51fa: 1\n
    \n\n

     

    \n\n

    \u63d0\u793a:

    \n\n
      \n\t
    • rows == mat.length
    • \n\t
    • cols == mat[i].length
    • \n\t
    • 1 <= rows, cols <= 100
    • \n\t
    • mat[i][j] \u53ea\u4f1a\u662f 0 \u6216 1\u3002
    • \n\t
    • mat[i] \u5df2\u6309\u975e\u9012\u51cf\u987a\u5e8f\u6392\u5e8f\u3002
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * // This is the BinaryMatrix's API interface.\n * // You should not implement it, or speculate about its implementation\n * class BinaryMatrix {\n * public:\n * int get(int row, int col);\n * vector dimensions();\n * };\n */\n\nclass Solution {\npublic:\n int leftMostColumnWithOne(BinaryMatrix &binaryMatrix) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * // This is the BinaryMatrix's API interface.\n * // You should not implement it, or speculate about its implementation\n * interface BinaryMatrix {\n * public int get(int row, int col) {}\n * public List dimensions {}\n * };\n */\n\nclass Solution {\n public int leftMostColumnWithOne(BinaryMatrix binaryMatrix) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# \"\"\"\n# This is BinaryMatrix's API interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class BinaryMatrix(object):\n# def get(self, row, col):\n# \"\"\"\n# :type row : int, col : int\n# :rtype int\n# \"\"\"\n#\n# def dimensions:\n# \"\"\"\n# :rtype list[]\n# \"\"\"\n\nclass Solution(object):\n def leftMostColumnWithOne(self, binaryMatrix):\n \"\"\"\n :type binaryMatrix: BinaryMatrix\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# \"\"\"\n# This is BinaryMatrix's API interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class BinaryMatrix(object):\n# def get(self, row: int, col: int) -> int:\n# def dimensions(self) -> list[]:\n\nclass Solution:\n def leftMostColumnWithOne(self, binaryMatrix: 'BinaryMatrix') -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * // This is the BinaryMatrix's API interface.\n * // You should not implement it, or speculate about its implementation\n * struct BinaryMatrix {\n * int (*get)(struct BinaryMatrix*, int, int);\n * int* (*dimensions)(struct BinaryMatrix*);\n * };\n */\n\nint leftMostColumnWithOne(struct BinaryMatrix* matrix) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * // This is BinaryMatrix's API interface.\n * // You should not implement it, or speculate about its implementation\n * class BinaryMatrix {\n * public int Get(int row, int col) {}\n * public IList Dimensions() {}\n * }\n */\n\nclass Solution {\n public int LeftMostColumnWithOne(BinaryMatrix binaryMatrix) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // This is the BinaryMatrix's API interface.\n * // You should not implement it, or speculate about its implementation\n * function BinaryMatrix() {\n * @param {integer} row, col\n * @return {integer}\n * this.get = function(row, col) {\n * ...\n * };\n *\n * @return {[integer, integer]}\n * this.dimensions = function() {\n * ...\n * };\n * };\n */\n\n/**\n * @param {BinaryMatrix} binaryMatrix\n * @return {number}\n */\nvar leftMostColumnWithOne = function(binaryMatrix) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# \"\"\"\n# This is BinaryMatrix's API interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n# class BinaryMatrix\n# \tdef get(row, col)\n# \t\t@return {Integer}\n# \tend\n#\n# \tdef dimensions()\n# \t\t@return {List[Integer]}\n# \tend\n# end\n\n# @param {BinaryMatrix} binaryMatrix\n# @return {Integer}\ndef leftMostColumnWithOne(binaryMatrix)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * // This is the BinaryMatrix's API interface.\n * // You should not implement it, or speculate about its implementation\n * public class BinaryMatrix {\n * public func get(_ row: Int, _ col: Int) -> Int {}\n * public func dimensions() -> [Int] {}\n * };\n */\n\nclass Solution {\n func leftMostColumnWithOne(_ binaryMatrix: BinaryMatrix) -> Int {\n\t\t\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * // This is the BinaryMatrix's API interface.\n * // You should not implement it, or speculate about its implementation\n * type BinaryMatrix struct {\n * Get func(int, int) int\n * Dimensions func() []int\n * }\n */\n\nfunc leftMostColumnWithOne(binaryMatrix BinaryMatrix) int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * // This is the BinaryMatrix's API interface.\n * // You should not implement it, or speculate about its implementation\n * class BinaryMatrix {\n * def get(row: Int, col: Int): Int = {}\n * def dimensions(): Array[Int] = {}\n * }\n */\n\nobject Solution {\n def leftMostColumnWithOne(binaryMatrix: BinaryMatrix): Int = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * // This is the BinaryMatrix's API interface.\n * // You should not implement it, or speculate about its implementation\n * class BinaryMatrix {\n * fun get(row:Int, col:Int):Int {}\n * fun dimensions():List {}\n * }\n */\n\nclass Solution {\n fun leftMostColumnWithOne(binaryMatrix:BinaryMatrix):Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "/**\n * // This is the BinaryMatrix's API interface.\n * // You should not implement it, or speculate about its implementation\n * struct BinaryMatrix;\n * impl BinaryMatrix {\n * fn get(row: i32, col: i32) -> i32;\n * fn dimensions() -> Vec;\n * };\n */\n\nimpl Solution {\n pub fn left_most_column_with_one(binaryMatrix: &BinaryMatrix) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * // This is the BinaryMatrix's API interface.\n * // You should not implement it, or speculate about its implementation\n * class BinaryMatrix {\n * public function get($row, $col) {} @return Integer\n * public function dimensions() {} @return Integer[]\n * }\n */\n\nclass Solution {\n /**\n * @param BinaryMatrix $binaryMatrix\n * @return Integer\n */\n public function leftMostColumnWithOne($binaryMatrix) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * // This is the BinaryMatrix's API interface.\n * // You should not implement it, or speculate about its implementation\n * class BinaryMatrix {\n * get(row: number, col: number): number {}\n *\n * dimensions(): number[] {}\n * }\n */\n\nfunction leftMostColumnWithOne(binaryMatrix: BinaryMatrix) {\n\t\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1428](https://leetcode-cn.com/problems/leftmost-column-with-at-least-a-one)", "[\u81f3\u5c11\u6709\u4e00\u4e2a 1 \u7684\u6700\u5de6\u7aef\u5217](/solution/1400-1499/1428.Leftmost%20Column%20with%20at%20Least%20a%20One/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1428](https://leetcode.com/problems/leftmost-column-with-at-least-a-one)", "[Leftmost Column with at Least a One](/solution/1400-1499/1428.Leftmost%20Column%20with%20at%20Least%20a%20One/README_EN.md)", "`Array`", "Medium", "\ud83d\udd12"]}, {"question_id": "1372", "frontend_question_id": "1250", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/check-if-it-is-a-good-array", "url_en": "https://leetcode.com/problems/check-if-it-is-a-good-array", "relative_path_cn": "/solution/1200-1299/1250.Check%20If%20It%20Is%20a%20Good%20Array/README.md", "relative_path_en": "/solution/1200-1299/1250.Check%20If%20It%20Is%20a%20Good%20Array/README_EN.md", "title_cn": "\u68c0\u67e5\u300c\u597d\u6570\u7ec4\u300d", "title_en": "Check If It Is a Good Array", "question_title_slug": "check-if-it-is-a-good-array", "content_en": "

    Given an array nums of positive integers. Your task is to select some subset of nums, multiply each element by an integer and add all these numbers. The array is said to be good if you can obtain a sum of 1 from the array by any possible subset and multiplicand.

    \n\n

    Return True if the array is good otherwise return False.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [12,5,7,23]\nOutput: true\nExplanation: Pick numbers 5 and 7.\n5*3 + 7*(-2) = 1\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [29,6,10]\nOutput: true\nExplanation: Pick numbers 29, 6 and 10.\n29*1 + 6*(-3) + 10*(-1) = 1\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [3,6]\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 10^5
    • \n\t
    • 1 <= nums[i] <= 10^9
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6b63\u6574\u6570\u6570\u7ec4 nums\uff0c\u4f60\u9700\u8981\u4ece\u4e2d\u4efb\u9009\u4e00\u4e9b\u5b50\u96c6\uff0c\u7136\u540e\u5c06\u5b50\u96c6\u4e2d\u6bcf\u4e00\u4e2a\u6570\u4e58\u4ee5\u4e00\u4e2a \u4efb\u610f\u6574\u6570\uff0c\u5e76\u6c42\u51fa\u4ed6\u4eec\u7684\u548c\u3002

    \n\n

    \u5047\u5982\u8be5\u548c\u7ed3\u679c\u4e3a 1\uff0c\u90a3\u4e48\u539f\u6570\u7ec4\u5c31\u662f\u4e00\u4e2a\u300c\u597d\u6570\u7ec4\u300d\uff0c\u5219\u8fd4\u56de True\uff1b\u5426\u5219\u8bf7\u8fd4\u56de False\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [12,5,7,23]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u6311\u9009\u6570\u5b57 5 \u548c 7\u3002\n5*3 + 7*(-2) = 1\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [29,6,10]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u6311\u9009\u6570\u5b57 29, 6 \u548c 10\u3002\n29*1 + 6*(-3) + 10*(-1) = 1\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [3,6]\n\u8f93\u51fa\uff1afalse\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 10^5
    • \n\t
    • 1 <= nums[i] <= 10^9
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isGoodArray(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isGoodArray(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isGoodArray(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: bool\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isGoodArray(self, nums: List[int]) -> bool:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isGoodArray(int* nums, int numsSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsGoodArray(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {boolean}\n */\nvar isGoodArray = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Boolean}\ndef is_good_array(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isGoodArray(_ nums: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isGoodArray(nums []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isGoodArray(nums: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isGoodArray(nums: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_good_array(nums: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Boolean\n */\n function isGoodArray($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isGoodArray(nums: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-good-array nums)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1250](https://leetcode-cn.com/problems/check-if-it-is-a-good-array)", "[\u68c0\u67e5\u300c\u597d\u6570\u7ec4\u300d](/solution/1200-1299/1250.Check%20If%20It%20Is%20a%20Good%20Array/README.md)", "`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[1250](https://leetcode.com/problems/check-if-it-is-a-good-array)", "[Check If It Is a Good Array](/solution/1200-1299/1250.Check%20If%20It%20Is%20a%20Good%20Array/README_EN.md)", "`Math`", "Hard", ""]}, {"question_id": "1371", "frontend_question_id": "1249", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-remove-to-make-valid-parentheses", "url_en": "https://leetcode.com/problems/minimum-remove-to-make-valid-parentheses", "relative_path_cn": "/solution/1200-1299/1249.Minimum%20Remove%20to%20Make%20Valid%20Parentheses/README.md", "relative_path_en": "/solution/1200-1299/1249.Minimum%20Remove%20to%20Make%20Valid%20Parentheses/README_EN.md", "title_cn": "\u79fb\u9664\u65e0\u6548\u7684\u62ec\u53f7", "title_en": "Minimum Remove to Make Valid Parentheses", "question_title_slug": "minimum-remove-to-make-valid-parentheses", "content_en": "

    Given a string s of '(' , ')' and lowercase English characters. 

    \r\n\r\n

    Your task is to remove the minimum number of parentheses ( '(' or ')', in any positions ) so that the resulting parentheses string is valid and return any valid string.

    \r\n\r\n

    Formally, a parentheses string is valid if and only if:

    \r\n\r\n
      \r\n\t
    • It is the empty string, contains only lowercase characters, or
    • \r\n\t
    • It can be written as AB (A concatenated with B), where A and B are valid strings, or
    • \r\n\t
    • It can be written as (A), where A is a valid string.
    • \r\n
    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: s = "lee(t(c)o)de)"\r\nOutput: "lee(t(c)o)de"\r\nExplanation: "lee(t(co)de)" , "lee(t(c)ode)" would also be accepted.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: s = "a)b(c)d"\r\nOutput: "ab(c)d"\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: s = "))(("\r\nOutput: ""\r\nExplanation: An empty string is also valid.\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: s = "(a(b(c)d)"\r\nOutput: "a(b(c)d)"\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= s.length <= 10^5
    • \r\n\t
    • s[i] is one of  '(' , ')' and lowercase English letters.
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u7531 '('\u3001')' \u548c\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210\u7684\u5b57\u7b26\u4e32 s\u3002

    \n\n

    \u4f60\u9700\u8981\u4ece\u5b57\u7b26\u4e32\u4e2d\u5220\u9664\u6700\u5c11\u6570\u76ee\u7684 '(' \u6216\u8005 ')' \uff08\u53ef\u4ee5\u5220\u9664\u4efb\u610f\u4f4d\u7f6e\u7684\u62ec\u53f7)\uff0c\u4f7f\u5f97\u5269\u4e0b\u7684\u300c\u62ec\u53f7\u5b57\u7b26\u4e32\u300d\u6709\u6548\u3002

    \n\n

    \u8bf7\u8fd4\u56de\u4efb\u610f\u4e00\u4e2a\u5408\u6cd5\u5b57\u7b26\u4e32\u3002

    \n\n

    \u6709\u6548\u300c\u62ec\u53f7\u5b57\u7b26\u4e32\u300d\u5e94\u5f53\u7b26\u5408\u4ee5\u4e0b \u4efb\u610f\u4e00\u6761 \u8981\u6c42\uff1a

    \n\n
      \n\t
    • \u7a7a\u5b57\u7b26\u4e32\u6216\u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd\u7684\u5b57\u7b26\u4e32
    • \n\t
    • \u53ef\u4ee5\u88ab\u5199\u4f5c AB\uff08A \u8fde\u63a5 B\uff09\u7684\u5b57\u7b26\u4e32\uff0c\u5176\u4e2d A \u548c B \u90fd\u662f\u6709\u6548\u300c\u62ec\u53f7\u5b57\u7b26\u4e32\u300d
    • \n\t
    • \u53ef\u4ee5\u88ab\u5199\u4f5c (A) \u7684\u5b57\u7b26\u4e32\uff0c\u5176\u4e2d A \u662f\u4e00\u4e2a\u6709\u6548\u7684\u300c\u62ec\u53f7\u5b57\u7b26\u4e32\u300d
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1as = "lee(t(c)o)de)"\n\u8f93\u51fa\uff1a"lee(t(c)o)de"\n\u89e3\u91ca\uff1a"lee(t(co)de)" , "lee(t(c)ode)" \u4e5f\u662f\u4e00\u4e2a\u53ef\u884c\u7b54\u6848\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1as = "a)b(c)d"\n\u8f93\u51fa\uff1a"ab(c)d"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1as = "))(("\n\u8f93\u51fa\uff1a""\n\u89e3\u91ca\uff1a\u7a7a\u5b57\u7b26\u4e32\u4e5f\u662f\u6709\u6548\u7684\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1as = "(a(b(c)d)"\n\u8f93\u51fa\uff1a"a(b(c)d)"\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 10^5
    • \n\t
    • s[i] \u53ef\u80fd\u662f '('\u3001')' \u6216\u82f1\u6587\u5c0f\u5199\u5b57\u6bcd
    • \n
    \n", "tags_en": ["Stack", "String"], "tags_cn": ["\u6808", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string minRemoveToMakeValid(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String minRemoveToMakeValid(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minRemoveToMakeValid(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minRemoveToMakeValid(self, s: str) -> str:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * minRemoveToMakeValid(char * s){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string MinRemoveToMakeValid(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar minRemoveToMakeValid = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef min_remove_to_make_valid(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minRemoveToMakeValid(_ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minRemoveToMakeValid(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minRemoveToMakeValid(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minRemoveToMakeValid(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_remove_to_make_valid(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function minRemoveToMakeValid($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minRemoveToMakeValid(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-remove-to-make-valid s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1249](https://leetcode-cn.com/problems/minimum-remove-to-make-valid-parentheses)", "[\u79fb\u9664\u65e0\u6548\u7684\u62ec\u53f7](/solution/1200-1299/1249.Minimum%20Remove%20to%20Make%20Valid%20Parentheses/README.md)", "`\u6808`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1249](https://leetcode.com/problems/minimum-remove-to-make-valid-parentheses)", "[Minimum Remove to Make Valid Parentheses](/solution/1200-1299/1249.Minimum%20Remove%20to%20Make%20Valid%20Parentheses/README_EN.md)", "`Stack`,`String`", "Medium", ""]}, {"question_id": "1370", "frontend_question_id": "1248", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-number-of-nice-subarrays", "url_en": "https://leetcode.com/problems/count-number-of-nice-subarrays", "relative_path_cn": "/solution/1200-1299/1248.Count%20Number%20of%20Nice%20Subarrays/README.md", "relative_path_en": "/solution/1200-1299/1248.Count%20Number%20of%20Nice%20Subarrays/README_EN.md", "title_cn": "\u7edf\u8ba1\u300c\u4f18\u7f8e\u5b50\u6570\u7ec4\u300d", "title_en": "Count Number of Nice Subarrays", "question_title_slug": "count-number-of-nice-subarrays", "content_en": "

    Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it.

    \n\n

    Return the number of nice sub-arrays.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,1,2,1,1], k = 3\nOutput: 2\nExplanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1].\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [2,4,6], k = 1\nOutput: 0\nExplanation: There is no odd numbers in the array.\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [2,2,2,1,2,2,1,2,2,2], k = 2\nOutput: 16\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 50000
    • \n\t
    • 1 <= nums[i] <= 10^5
    • \n\t
    • 1 <= k <= nums.length
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \u548c\u4e00\u4e2a\u6574\u6570 k\u3002

    \n\n

    \u5982\u679c\u67d0\u4e2a \u8fde\u7eed \u5b50\u6570\u7ec4\u4e2d\u6070\u597d\u6709 k \u4e2a\u5947\u6570\u6570\u5b57\uff0c\u6211\u4eec\u5c31\u8ba4\u4e3a\u8fd9\u4e2a\u5b50\u6570\u7ec4\u662f\u300c\u4f18\u7f8e\u5b50\u6570\u7ec4\u300d\u3002

    \n\n

    \u8bf7\u8fd4\u56de\u8fd9\u4e2a\u6570\u7ec4\u4e2d\u300c\u4f18\u7f8e\u5b50\u6570\u7ec4\u300d\u7684\u6570\u76ee\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,1,2,1,1], k = 3\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5305\u542b 3 \u4e2a\u5947\u6570\u7684\u5b50\u6570\u7ec4\u662f [1,1,2,1] \u548c [1,2,1,1] \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [2,4,6], k = 1\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6570\u5217\u4e2d\u4e0d\u5305\u542b\u4efb\u4f55\u5947\u6570\uff0c\u6240\u4ee5\u4e0d\u5b58\u5728\u4f18\u7f8e\u5b50\u6570\u7ec4\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [2,2,2,1,2,2,1,2,2,2], k = 2\n\u8f93\u51fa\uff1a16\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 50000
    • \n\t
    • 1 <= nums[i] <= 10^5
    • \n\t
    • 1 <= k <= nums.length
    • \n
    \n", "tags_en": ["Two Pointers"], "tags_cn": ["\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numberOfSubarrays(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numberOfSubarrays(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numberOfSubarrays(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numberOfSubarrays(self, nums: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numberOfSubarrays(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumberOfSubarrays(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar numberOfSubarrays = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef number_of_subarrays(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numberOfSubarrays(_ nums: [Int], _ k: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numberOfSubarrays(nums []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numberOfSubarrays(nums: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numberOfSubarrays(nums: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn number_of_subarrays(nums: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer\n */\n function numberOfSubarrays($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numberOfSubarrays(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (number-of-subarrays nums k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1248](https://leetcode-cn.com/problems/count-number-of-nice-subarrays)", "[\u7edf\u8ba1\u300c\u4f18\u7f8e\u5b50\u6570\u7ec4\u300d](/solution/1200-1299/1248.Count%20Number%20of%20Nice%20Subarrays/README.md)", "`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1248](https://leetcode.com/problems/count-number-of-nice-subarrays)", "[Count Number of Nice Subarrays](/solution/1200-1299/1248.Count%20Number%20of%20Nice%20Subarrays/README_EN.md)", "`Two Pointers`", "Medium", ""]}, {"question_id": "1369", "frontend_question_id": "1247", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-swaps-to-make-strings-equal", "url_en": "https://leetcode.com/problems/minimum-swaps-to-make-strings-equal", "relative_path_cn": "/solution/1200-1299/1247.Minimum%20Swaps%20to%20Make%20Strings%20Equal/README.md", "relative_path_en": "/solution/1200-1299/1247.Minimum%20Swaps%20to%20Make%20Strings%20Equal/README_EN.md", "title_cn": "\u4ea4\u6362\u5b57\u7b26\u4f7f\u5f97\u5b57\u7b26\u4e32\u76f8\u540c", "title_en": "Minimum Swaps to Make Strings Equal", "question_title_slug": "minimum-swaps-to-make-strings-equal", "content_en": "

    You are given two strings s1 and s2 of equal length consisting of letters "x" and "y" only. Your task is to make these two strings equal to each other. You can swap any two characters that belong to different strings, which means: swap s1[i] and s2[j].

    \r\n\r\n

    Return the minimum number of swaps required to make s1 and s2 equal, or return -1 if it is impossible to do so.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: s1 = "xx", s2 = "yy"\r\nOutput: 1\r\nExplanation: \r\nSwap s1[0] and s2[1], s1 = "yx", s2 = "yx".
    \r\n\r\n

    Example 2: 

    \r\n\r\n
    \r\nInput: s1 = "xy", s2 = "yx"\r\nOutput: 2\r\nExplanation: \r\nSwap s1[0] and s2[0], s1 = "yy", s2 = "xx".\r\nSwap s1[0] and s2[1], s1 = "xy", s2 = "xy".\r\nNote that you can't swap s1[0] and s1[1] to make s1 equal to "yx", cause we can only swap chars in different strings.
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: s1 = "xx", s2 = "xy"\r\nOutput: -1\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: s1 = "xxyyxyxyxx", s2 = "xyyxyxxxyx"\r\nOutput: 4\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= s1.length, s2.length <= 1000
    • \r\n\t
    • s1, s2 only contain 'x' or 'y'.
    • \r\n
    ", "content_cn": "

    \u6709\u4e24\u4e2a\u957f\u5ea6\u76f8\u540c\u7684\u5b57\u7b26\u4e32 s1 \u548c s2\uff0c\u4e14\u5b83\u4eec\u5176\u4e2d \u53ea\u542b\u6709 \u5b57\u7b26 "x" \u548c "y"\uff0c\u4f60\u9700\u8981\u901a\u8fc7\u300c\u4ea4\u6362\u5b57\u7b26\u300d\u7684\u65b9\u5f0f\u4f7f\u8fd9\u4e24\u4e2a\u5b57\u7b26\u4e32\u76f8\u540c\u3002

    \n\n

    \u6bcf\u6b21\u300c\u4ea4\u6362\u5b57\u7b26\u300d\u7684\u65f6\u5019\uff0c\u4f60\u90fd\u53ef\u4ee5\u5728\u4e24\u4e2a\u5b57\u7b26\u4e32\u4e2d\u5404\u9009\u4e00\u4e2a\u5b57\u7b26\u8fdb\u884c\u4ea4\u6362\u3002

    \n\n

    \u4ea4\u6362\u53ea\u80fd\u53d1\u751f\u5728\u4e24\u4e2a\u4e0d\u540c\u7684\u5b57\u7b26\u4e32\u4e4b\u95f4\uff0c\u7edd\u5bf9\u4e0d\u80fd\u53d1\u751f\u5728\u540c\u4e00\u4e2a\u5b57\u7b26\u4e32\u5185\u90e8\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u6211\u4eec\u53ef\u4ee5\u4ea4\u6362 s1[i] \u548c s2[j]\uff0c\u4f46\u4e0d\u80fd\u4ea4\u6362 s1[i] \u548c s1[j]\u3002

    \n\n

    \u6700\u540e\uff0c\u8bf7\u4f60\u8fd4\u56de\u4f7f s1 \u548c s2 \u76f8\u540c\u7684\u6700\u5c0f\u4ea4\u6362\u6b21\u6570\uff0c\u5982\u679c\u6ca1\u6709\u65b9\u6cd5\u80fd\u591f\u4f7f\u5f97\u8fd9\u4e24\u4e2a\u5b57\u7b26\u4e32\u76f8\u540c\uff0c\u5219\u8fd4\u56de -1 \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1as1 = "xx", s2 = "yy"\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\n\u4ea4\u6362 s1[0] \u548c s2[1]\uff0c\u5f97\u5230 s1 = "yx"\uff0cs2 = "yx"\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1as1 = "xy", s2 = "yx"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n\u4ea4\u6362 s1[0] \u548c s2[0]\uff0c\u5f97\u5230 s1 = "yy"\uff0cs2 = "xx" \u3002\n\u4ea4\u6362 s1[0] \u548c s2[1]\uff0c\u5f97\u5230 s1 = "xy"\uff0cs2 = "xy" \u3002\n\u6ce8\u610f\uff0c\u4f60\u4e0d\u80fd\u4ea4\u6362 s1[0] \u548c s1[1] \u4f7f\u5f97 s1 \u53d8\u6210 "yx"\uff0c\u56e0\u4e3a\u6211\u4eec\u53ea\u80fd\u4ea4\u6362\u5c5e\u4e8e\u4e24\u4e2a\u4e0d\u540c\u5b57\u7b26\u4e32\u7684\u5b57\u7b26\u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1as1 = "xx", s2 = "xy"\n\u8f93\u51fa\uff1a-1\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1as1 = "xxyyxyxyxx", s2 = "xyyxyxxxyx"\n\u8f93\u51fa\uff1a4\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s1.length, s2.length <= 1000
    • \n\t
    • s1, s2 \u53ea\u5305\u542b 'x' \u6216 'y'\u3002
    • \n
    \n", "tags_en": ["Greedy", "String"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minimumSwap(string s1, string s2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minimumSwap(String s1, String s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimumSwap(self, s1, s2):\n \"\"\"\n :type s1: str\n :type s2: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimumSwap(self, s1: str, s2: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "int minimumSwap(char * s1, char * s2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinimumSwap(string s1, string s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s1\n * @param {string} s2\n * @return {number}\n */\nvar minimumSwap = function(s1, s2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s1\n# @param {String} s2\n# @return {Integer}\ndef minimum_swap(s1, s2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimumSwap(_ s1: String, _ s2: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimumSwap(s1 string, s2 string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimumSwap(s1: String, s2: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimumSwap(s1: String, s2: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimum_swap(s1: String, s2: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s1\n * @param String $s2\n * @return Integer\n */\n function minimumSwap($s1, $s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimumSwap(s1: string, s2: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimum-swap s1 s2)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1247](https://leetcode-cn.com/problems/minimum-swaps-to-make-strings-equal)", "[\u4ea4\u6362\u5b57\u7b26\u4f7f\u5f97\u5b57\u7b26\u4e32\u76f8\u540c](/solution/1200-1299/1247.Minimum%20Swaps%20to%20Make%20Strings%20Equal/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1247](https://leetcode.com/problems/minimum-swaps-to-make-strings-equal)", "[Minimum Swaps to Make Strings Equal](/solution/1200-1299/1247.Minimum%20Swaps%20to%20Make%20Strings%20Equal/README_EN.md)", "`Greedy`,`String`", "Medium", ""]}, {"question_id": "1368", "frontend_question_id": "1242", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/web-crawler-multithreaded", "url_en": "https://leetcode.com/problems/web-crawler-multithreaded", "relative_path_cn": "/solution/1200-1299/1242.Web%20Crawler%20Multithreaded/README.md", "relative_path_en": "/solution/1200-1299/1242.Web%20Crawler%20Multithreaded/README_EN.md", "title_cn": "\u591a\u7ebf\u7a0b\u7f51\u9875\u722c\u866b", "title_en": "Web Crawler Multithreaded", "question_title_slug": "web-crawler-multithreaded", "content_en": "

    Given a url startUrl and an interface HtmlParser, implement a Multi-threaded web crawler to crawl all links that are under the same hostname as startUrl

    \n\n

    Return all urls obtained by your web crawler in any order.

    \n\n

    Your crawler should:

    \n\n
      \n\t
    • Start from the page: startUrl
    • \n\t
    • Call HtmlParser.getUrls(url) to get all urls from a webpage of given url.
    • \n\t
    • Do not crawl the same link twice.
    • \n\t
    • Explore only the links that are under the same hostname as startUrl.
    • \n
    \n\n

    \"\"

    \n\n

    As shown in the example url above, the hostname is example.org. For simplicity sake, you may assume all urls use http protocol without any port specified. For example, the urls http://leetcode.com/problems and http://leetcode.com/contest are under the same hostname, while urls http://example.org/test and http://example.com/abc are not under the same hostname.

    \n\n

    The HtmlParser interface is defined as such: 

    \n\n
    \ninterface HtmlParser {\n  // Return a list of all urls from a webpage of given url.\n  // This is a blocking call, that means it will do HTTP request and return when this request is finished.\n  public List<String> getUrls(String url);\n}
    \n\n

    Note that getUrls(String url) simulates performing a HTTP request. You can treat it as a blocking function call which waits for a HTTP request to finish. It is guaranteed that getUrls(String url) will return the urls within 15ms.  Single-threaded solutions will exceed the time limit so, can your multi-threaded web crawler do better?

    \n\n

    Below are two examples explaining the functionality of the problem, for custom testing purposes you'll have three variables urlsedges and startUrl. Notice that you will only have access to startUrl in your code, while urls and edges are not directly accessible to you in code.

    \n\n

     

    \n\n

    Follow up:

    \n\n
      \n\t
    1. Assume we have 10,000 nodes and 1 billion URLs to crawl. We will deploy the same software onto each node. The software can know about all the nodes. We have to minimize communication between machines and make sure each node does equal amount of work. How would your web crawler design change?
    2. \n\t
    3. What if one node fails or does not work?
    4. \n\t
    5. How do you know when the crawler is done?
    6. \n
    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput:\nurls = [\n  "http://news.yahoo.com",\n  "http://news.yahoo.com/news",\n  "http://news.yahoo.com/news/topics/",\n  "http://news.google.com",\n  "http://news.yahoo.com/us"\n]\nedges = [[2,0],[2,1],[3,2],[3,1],[0,4]]\nstartUrl = "http://news.yahoo.com/news/topics/"\nOutput: [\n  "http://news.yahoo.com",\n  "http://news.yahoo.com/news",\n  "http://news.yahoo.com/news/topics/",\n  "http://news.yahoo.com/us"\n]\n
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: \nurls = [\n  "http://news.yahoo.com",\n  "http://news.yahoo.com/news",\n  "http://news.yahoo.com/news/topics/",\n  "http://news.google.com"\n]\nedges = [[0,2],[2,1],[3,2],[3,1],[3,0]]\nstartUrl = "http://news.google.com"\nOutput: ["http://news.google.com"]\nExplanation: The startUrl links to all other pages that do not share the same hostname.
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= urls.length <= 1000
    • \n\t
    • 1 <= urls[i].length <= 300
    • \n\t
    • startUrl is one of the urls.
    • \n\t
    • Hostname label must be from 1 to 63 characters long, including the dots, may contain only the ASCII letters from 'a' to 'z', digits from '0' to '9' and the hyphen-minus character ('-').
    • \n\t
    • The hostname may not start or end with the hyphen-minus character ('-'). 
    • \n\t
    • See:  https://en.wikipedia.org/wiki/Hostname#Restrictions_on_valid_hostnames
    • \n\t
    • You may assume there're no duplicates in url library.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u521d\u59cb\u5730\u5740 startUrl \u548c\u4e00\u4e2a HTML \u89e3\u6790\u5668\u63a5\u53e3 HtmlParser\uff0c\u8bf7\u4f60\u5b9e\u73b0\u4e00\u4e2a \u591a\u7ebf\u7a0b\u7684\u7f51\u9875\u722c\u866b\uff0c\u7528\u4e8e\u83b7\u53d6\u4e0e startUrl \u6709 \u76f8\u540c\u4e3b\u673a\u540d \u7684\u6240\u6709\u94fe\u63a5\u3002 

    \n\n

    \u4ee5 \u4efb\u610f \u987a\u5e8f\u8fd4\u56de\u722c\u866b\u83b7\u53d6\u7684\u8def\u5f84\u3002

    \n\n

    \u722c\u866b\u5e94\u8be5\u9075\u5faa\uff1a

    \n\n
      \n\t
    • \u4ece startUrl \u5f00\u59cb
    • \n\t
    • \u8c03\u7528 HtmlParser.getUrls(url) \u4ece\u6307\u5b9a\u7f51\u9875\u8def\u5f84\u83b7\u5f97\u7684\u6240\u6709\u8def\u5f84\u3002
    • \n\t
    • \u4e0d\u8981\u6293\u53d6\u76f8\u540c\u7684\u94fe\u63a5\u4e24\u6b21\u3002
    • \n\t
    • \u4ec5\u6d4f\u89c8\u4e0e startUrl \u76f8\u540c\u4e3b\u673a\u540d \u7684\u94fe\u63a5\u3002
    • \n
    \n\n

    \"\"\"\"

    \n\n

    \u5982\u4e0a\u56fe\u6240\u793a\uff0c\u4e3b\u673a\u540d\u662f example.org \u3002\u7b80\u5355\u8d77\u89c1\uff0c\u4f60\u53ef\u4ee5\u5047\u8bbe\u6240\u6709\u94fe\u63a5\u90fd\u91c7\u7528 http \u534f\u8bae\uff0c\u5e76\u4e14\u6ca1\u6709\u6307\u5b9a \u7aef\u53e3\u53f7\u3002\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u94fe\u63a5 http://leetcode.com/problems \u548c\u94fe\u63a5 http://leetcode.com/contest \u5c5e\u4e8e\u540c\u4e00\u4e2a \u4e3b\u673a\u540d\uff0c \u800c http://example.org/test \u4e0e http://example.com/abc \u5e76\u4e0d\u5c5e\u4e8e\u540c\u4e00\u4e2a \u4e3b\u673a\u540d\u3002

    \n\n

    HtmlParser \u7684\u63a5\u53e3\u5b9a\u4e49\u5982\u4e0b\uff1a

    \n\n
    \ninterface HtmlParser {\n  // Return a list of all urls from a webpage of given url.\n  // This is a blocking call, that means it will do HTTP request and return when this request is finished.\n  public List<String> getUrls(String url);\n}
    \n\n

    \u6ce8\u610f\u4e00\u70b9\uff0cgetUrls(String url) \u6a21\u62df\u6267\u884c\u4e00\u4e2aHTTP\u7684\u8bf7\u6c42\u3002 \u4f60\u53ef\u4ee5\u5c06\u5b83\u5f53\u505a\u4e00\u4e2a\u963b\u585e\u5f0f\u7684\u65b9\u6cd5\uff0c\u76f4\u5230\u8bf7\u6c42\u7ed3\u675f\u3002 getUrls(String url) \u4fdd\u8bc1\u4f1a\u5728 15ms \u5185\u8fd4\u56de\u6240\u6709\u7684\u8def\u5f84\u3002 \u5355\u7ebf\u7a0b\u7684\u65b9\u6848\u4f1a\u8d85\u8fc7\u65f6\u95f4\u9650\u5236\uff0c\u4f60\u80fd\u7528\u591a\u7ebf\u7a0b\u65b9\u6848\u505a\u7684\u66f4\u597d\u5417\uff1f

    \n\n

    \u5bf9\u4e8e\u95ee\u9898\u6240\u9700\u7684\u529f\u80fd\uff0c\u4e0b\u9762\u63d0\u4f9b\u4e86\u4e24\u4e2a\u4f8b\u5b50\u3002\u4e3a\u4e86\u65b9\u4fbf\u81ea\u5b9a\u4e49\u6d4b\u8bd5\uff0c\u4f60\u53ef\u4ee5\u58f0\u660e\u4e09\u4e2a\u53d8\u91cf urls\uff0cedges \u548c startUrl\u3002\u4f46\u8981\u6ce8\u610f\u4f60\u53ea\u80fd\u5728\u4ee3\u7801\u4e2d\u8bbf\u95ee startUrl\uff0c\u5e76\u4e0d\u80fd\u76f4\u63a5\u8bbf\u95ee urls \u548c edges\u3002

    \n\n

     

    \n\n

    \u62d3\u5c55\u95ee\u9898\uff1a

    \n\n
      \n\t
    1. \u5047\u8bbe\u6211\u4eec\u8981\u8981\u6293\u53d6 10000 \u4e2a\u8282\u70b9\u548c 10 \u4ebf\u4e2a\u8def\u5f84\u3002\u5e76\u4e14\u5728\u6bcf\u4e2a\u8282\u70b9\u90e8\u7f72\u76f8\u540c\u7684\u7684\u8f6f\u4ef6\u3002\u8f6f\u4ef6\u53ef\u4ee5\u53d1\u73b0\u6240\u6709\u7684\u8282\u70b9\u3002\u6211\u4eec\u5fc5\u987b\u5c3d\u53ef\u80fd\u51cf\u5c11\u673a\u5668\u4e4b\u95f4\u7684\u901a\u8baf\uff0c\u5e76\u786e\u4fdd\u6bcf\u4e2a\u8282\u70b9\u8d1f\u8f7d\u5747\u8861\u3002\u4f60\u5c06\u5982\u4f55\u8bbe\u8ba1\u8fd9\u4e2a\u7f51\u9875\u722c\u866b\uff1f
    2. \n\t
    3. \u5982\u679c\u6709\u4e00\u4e2a\u8282\u70b9\u53d1\u751f\u6545\u969c\u4e0d\u5de5\u4f5c\u8be5\u600e\u4e48\u529e\uff1f
    4. \n\t
    5. \u5982\u4f55\u786e\u8ba4\u722c\u866b\u4efb\u52a1\u5df2\u7ecf\u5b8c\u6210\uff1f
    6. \n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"\"\"

    \n\n
    \n\u8f93\u5165\uff1a\nurls = [\n  "http://news.yahoo.com",\n  "http://news.yahoo.com/news",\n  "http://news.yahoo.com/news/topics/",\n  "http://news.google.com",\n  "http://news.yahoo.com/us"\n]\nedges = [[2,0],[2,1],[3,2],[3,1],[0,4]]\nstartUrl = "http://news.yahoo.com/news/topics/"\n\u8f93\u51fa\uff1a[\n  "http://news.yahoo.com",\n  "http://news.yahoo.com/news",\n  "http://news.yahoo.com/news/topics/",\n  "http://news.yahoo.com/us"\n]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"\"\"

    \n\n
    \n\u8f93\u5165\uff1a\nurls = [\n  "http://news.yahoo.com",\n  "http://news.yahoo.com/news",\n  "http://news.yahoo.com/news/topics/",\n  "http://news.google.com"\n]\nedges = [[0,2],[2,1],[3,2],[3,1],[3,0]]\nstartUrl = "http://news.google.com"\n\u8f93\u51fa\uff1a["http://news.google.com"]\n\u89e3\u91ca\uff1astartUrl \u94fe\u63a5\u4e0e\u5176\u4ed6\u9875\u9762\u4e0d\u5171\u4eab\u4e00\u4e2a\u4e3b\u673a\u540d\u3002
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= urls.length <= 1000
    • \n\t
    • 1 <= urls[i].length <= 300
    • \n\t
    • startUrl \u662f urls \u4e2d\u7684\u4e00\u4e2a\u3002
    • \n\t
    • \u4e3b\u673a\u540d\u7684\u957f\u5ea6\u5fc5\u987b\u4e3a 1 \u5230 63 \u4e2a\u5b57\u7b26\uff08\u5305\u62ec\u70b9 . \u5728\u5185\uff09\uff0c\u53ea\u80fd\u5305\u542b\u4ece “a” \u5230 “z” \u7684 ASCII \u5b57\u6bcd\u548c “0” \u5230 “9” \u7684\u6570\u5b57\uff0c\u4ee5\u53ca\u4e2d\u5212\u7ebf “-”\u3002
    • \n\t
    • \u4e3b\u673a\u540d\u5f00\u5934\u548c\u7ed3\u5c3e\u4e0d\u80fd\u662f\u4e2d\u5212\u7ebf “-”\u3002
    • \n\t
    • \u53c2\u8003\u8d44\u6599\uff1ahttps://en.wikipedia.org/wiki/Hostname#Restrictions_on_valid_hostnames
    • \n\t
    • \u4f60\u53ef\u4ee5\u5047\u8bbe\u8def\u5f84\u90fd\u662f\u4e0d\u91cd\u590d\u7684\u3002
    • \n
    \n", "tags_en": ["Depth-first Search", "Breadth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * // This is the HtmlParser's API interface.\n * // You should not implement it, or speculate about its implementation\n * class HtmlParser {\n * public:\n * vector getUrls(string url);\n * };\n */\nclass Solution {\npublic:\n vector crawl(string startUrl, HtmlParser htmlParser) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * // This is the HtmlParser's API interface.\n * // You should not implement it, or speculate about its implementation\n * interface HtmlParser {\n * public List getUrls(String url) {}\n * }\n */\nclass Solution {\n public List crawl(String startUrl, HtmlParser htmlParser) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# \"\"\"\n# This is HtmlParser's API interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class HtmlParser(object):\n# def getUrls(self, url):\n# \"\"\"\n# :type url: str\n# :rtype List[str]\n# \"\"\"\n\nclass Solution(object):\n def crawl(self, startUrl, htmlParser):\n \"\"\"\n :type startUrl: str\n :type htmlParser: HtmlParser\n :rtype: List[str]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# \"\"\"\n# This is HtmlParser's API interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class HtmlParser(object):\n# def getUrls(self, url):\n# \"\"\"\n# :type url: str\n# :rtype List[str]\n# \"\"\"\n\nclass Solution:\n def crawl(self, startUrl: str, htmlParser: 'HtmlParser') -> List[str]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * // This is the HtmlParser's API interface.\n * // You should not implement it, or speculate about its implementation\n * class HtmlParser {\n * public List GetUrls(String url) {}\n * }\n */\nclass Solution {\n public IList Crawl(string startUrl, HtmlParser htmlParser) {\n \n }\n}", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1242](https://leetcode-cn.com/problems/web-crawler-multithreaded)", "[\u591a\u7ebf\u7a0b\u7f51\u9875\u722c\u866b](/solution/1200-1299/1242.Web%20Crawler%20Multithreaded/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1242](https://leetcode.com/problems/web-crawler-multithreaded)", "[Web Crawler Multithreaded](/solution/1200-1299/1242.Web%20Crawler%20Multithreaded/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`", "Medium", "\ud83d\udd12"]}, {"question_id": "1367", "frontend_question_id": "1691", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-height-by-stacking-cuboids", "url_en": "https://leetcode.com/problems/maximum-height-by-stacking-cuboids", "relative_path_cn": "/solution/1600-1699/1691.Maximum%20Height%20by%20Stacking%20Cuboids/README.md", "relative_path_en": "/solution/1600-1699/1691.Maximum%20Height%20by%20Stacking%20Cuboids/README_EN.md", "title_cn": "\u5806\u53e0\u957f\u65b9\u4f53\u7684\u6700\u5927\u9ad8\u5ea6", "title_en": "Maximum Height by Stacking Cuboids", "question_title_slug": "maximum-height-by-stacking-cuboids", "content_en": "

    Given n cuboids where the dimensions of the ith cuboid is cuboids[i] = [widthi, lengthi, heighti] (0-indexed). Choose a subset of cuboids and place them on each other.

    \n\n

    You can place cuboid i on cuboid j if widthi <= widthj and lengthi <= lengthj and heighti <= heightj. You can rearrange any cuboid's dimensions by rotating it to put it on another cuboid.

    \n\n

    Return the maximum height of the stacked cuboids.

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: cuboids = [[50,45,20],[95,37,53],[45,23,12]]\nOutput: 190\nExplanation:\nCuboid 1 is placed on the bottom with the 53x37 side facing down with height 95.\nCuboid 0 is placed next with the 45x20 side facing down with height 50.\nCuboid 2 is placed next with the 23x12 side facing down with height 45.\nThe total height is 95 + 50 + 45 = 190.\n
    \n\n

    Example 2:

    \n\n
    \nInput: cuboids = [[38,25,45],[76,35,3]]\nOutput: 76\nExplanation:\nYou can't place any of the cuboids on the other.\nWe choose cuboid 1 and rotate it so that the 35x3 side is facing down and its height is 76.\n
    \n\n

    Example 3:

    \n\n
    \nInput: cuboids = [[7,11,17],[7,17,11],[11,7,17],[11,17,7],[17,7,11],[17,11,7]]\nOutput: 102\nExplanation:\nAfter rearranging the cuboids, you can see that all cuboids have the same dimension.\nYou can place the 11x7 side down on all cuboids so their heights are 17.\nThe maximum height of stacked cuboids is 6 * 17 = 102.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == cuboids.length
    • \n\t
    • 1 <= n <= 100
    • \n\t
    • 1 <= widthi, lengthi, heighti <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60 n \u4e2a\u957f\u65b9\u4f53 cuboids \uff0c\u5176\u4e2d\u7b2c i \u4e2a\u957f\u65b9\u4f53\u7684\u957f\u5bbd\u9ad8\u8868\u793a\u4e3a cuboids[i] = [widthi, lengthi, heighti]\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\u3002\u8bf7\u4f60\u4ece cuboids \u9009\u51fa\u4e00\u4e2a \u5b50\u96c6 \uff0c\u5e76\u5c06\u5b83\u4eec\u5806\u53e0\u8d77\u6765\u3002

    \n\n

    \u5982\u679c widthi <= widthj \u4e14 lengthi <= lengthj \u4e14 heighti <= heightj \uff0c\u4f60\u5c31\u53ef\u4ee5\u5c06\u957f\u65b9\u4f53 i \u5806\u53e0\u5728\u957f\u65b9\u4f53 j \u4e0a\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u65cb\u8f6c\u628a\u957f\u65b9\u4f53\u7684\u957f\u5bbd\u9ad8\u91cd\u65b0\u6392\u5217\uff0c\u4ee5\u5c06\u5b83\u653e\u5728\u53e6\u4e00\u4e2a\u957f\u65b9\u4f53\u4e0a\u3002

    \n\n

    \u8fd4\u56de \u5806\u53e0\u957f\u65b9\u4f53\u00a0cuboids \u53ef\u4ee5\u5f97\u5230\u7684 \u6700\u5927\u9ad8\u5ea6 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1acuboids = [[50,45,20],[95,37,53],[45,23,12]]\n\u8f93\u51fa\uff1a190\n\u89e3\u91ca\uff1a\n\u7b2c 1 \u4e2a\u957f\u65b9\u4f53\u653e\u5728\u5e95\u90e8\uff0c53x37 \u7684\u4e00\u9762\u671d\u4e0b\uff0c\u9ad8\u5ea6\u4e3a 95 \u3002\n\u7b2c 0 \u4e2a\u957f\u65b9\u4f53\u653e\u5728\u4e2d\u95f4\uff0c45x20 \u7684\u4e00\u9762\u671d\u4e0b\uff0c\u9ad8\u5ea6\u4e3a 50 \u3002\n\u7b2c 2 \u4e2a\u957f\u65b9\u4f53\u653e\u5728\u4e0a\u9762\uff0c23x12 \u7684\u4e00\u9762\u671d\u4e0b\uff0c\u9ad8\u5ea6\u4e3a 45 \u3002\n\u603b\u9ad8\u5ea6\u662f 95 + 50 + 45 = 190 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1acuboids = [[38,25,45],[76,35,3]]\n\u8f93\u51fa\uff1a76\n\u89e3\u91ca\uff1a\n\u65e0\u6cd5\u5c06\u4efb\u4f55\u957f\u65b9\u4f53\u653e\u5728\u53e6\u4e00\u4e2a\u4e0a\u9762\u3002\n\u9009\u62e9\u7b2c 1 \u4e2a\u957f\u65b9\u4f53\u7136\u540e\u65cb\u8f6c\u5b83\uff0c\u4f7f 35x3 \u7684\u4e00\u9762\u671d\u4e0b\uff0c\u5176\u9ad8\u5ea6\u4e3a 76 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1acuboids = [[7,11,17],[7,17,11],[11,7,17],[11,17,7],[17,7,11],[17,11,7]]\n\u8f93\u51fa\uff1a102\n\u89e3\u91ca\uff1a\n\u91cd\u65b0\u6392\u5217\u957f\u65b9\u4f53\u540e\uff0c\u53ef\u4ee5\u770b\u5230\u6240\u6709\u957f\u65b9\u4f53\u7684\u5c3a\u5bf8\u90fd\u76f8\u540c\u3002\n\u4f60\u53ef\u4ee5\u628a 11x7 \u7684\u4e00\u9762\u671d\u4e0b\uff0c\u8fd9\u6837\u5b83\u4eec\u7684\u9ad8\u5ea6\u5c31\u662f 17 \u3002\n\u5806\u53e0\u957f\u65b9\u4f53\u7684\u6700\u5927\u9ad8\u5ea6\u4e3a 6 * 17 = 102 \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == cuboids.length
    • \n\t
    • 1 <= n <= 100
    • \n\t
    • 1 <= widthi, lengthi, heighti <= 100
    • \n
    \n", "tags_en": ["Sort", "Dynamic Programming"], "tags_cn": ["\u6392\u5e8f", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxHeight(vector>& cuboids) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxHeight(int[][] cuboids) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxHeight(self, cuboids):\n \"\"\"\n :type cuboids: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxHeight(self, cuboids: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxHeight(int** cuboids, int cuboidsSize, int* cuboidsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxHeight(int[][] cuboids) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} cuboids\n * @return {number}\n */\nvar maxHeight = function(cuboids) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} cuboids\n# @return {Integer}\ndef max_height(cuboids)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxHeight(_ cuboids: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxHeight(cuboids [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxHeight(cuboids: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxHeight(cuboids: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_height(cuboids: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $cuboids\n * @return Integer\n */\n function maxHeight($cuboids) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxHeight(cuboids: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-height cuboids)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1691](https://leetcode-cn.com/problems/maximum-height-by-stacking-cuboids)", "[\u5806\u53e0\u957f\u65b9\u4f53\u7684\u6700\u5927\u9ad8\u5ea6](/solution/1600-1699/1691.Maximum%20Height%20by%20Stacking%20Cuboids/README.md)", "`\u6392\u5e8f`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1691](https://leetcode.com/problems/maximum-height-by-stacking-cuboids)", "[Maximum Height by Stacking Cuboids](/solution/1600-1699/1691.Maximum%20Height%20by%20Stacking%20Cuboids/README_EN.md)", "`Sort`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "1366", "frontend_question_id": "1429", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/first-unique-number", "url_en": "https://leetcode.com/problems/first-unique-number", "relative_path_cn": "/solution/1400-1499/1429.First%20Unique%20Number/README.md", "relative_path_en": "/solution/1400-1499/1429.First%20Unique%20Number/README_EN.md", "title_cn": "\u7b2c\u4e00\u4e2a\u552f\u4e00\u6570\u5b57", "title_en": "First Unique Number", "question_title_slug": "first-unique-number", "content_en": "

    You have a queue of integers, you need to retrieve the first unique integer in the queue.

    \n\n

    Implement the FirstUnique class:

    \n\n
      \n\t
    • FirstUnique(int[] nums) Initializes the object with the numbers in the queue.
    • \n\t
    • int showFirstUnique() returns the value of the first unique integer of the queue, and returns -1 if there is no such integer.
    • \n\t
    • void add(int value) insert value to the queue.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: \n["FirstUnique","showFirstUnique","add","showFirstUnique","add","showFirstUnique","add","showFirstUnique"]\n[[[2,3,5]],[],[5],[],[2],[],[3],[]]\nOutput: \n[null,2,null,2,null,3,null,-1]\nExplanation: \nFirstUnique firstUnique = new FirstUnique([2,3,5]);\nfirstUnique.showFirstUnique(); // return 2\nfirstUnique.add(5);            // the queue is now [2,3,5,5]\nfirstUnique.showFirstUnique(); // return 2\nfirstUnique.add(2);            // the queue is now [2,3,5,5,2]\nfirstUnique.showFirstUnique(); // return 3\nfirstUnique.add(3);            // the queue is now [2,3,5,5,2,3]\nfirstUnique.showFirstUnique(); // return -1\n
    \n\n

    Example 2:

    \n\n
    \nInput: \n["FirstUnique","showFirstUnique","add","add","add","add","add","showFirstUnique"]\n[[[7,7,7,7,7,7]],[],[7],[3],[3],[7],[17],[]]\nOutput: \n[null,-1,null,null,null,null,null,17]\nExplanation: \nFirstUnique firstUnique = new FirstUnique([7,7,7,7,7,7]);\nfirstUnique.showFirstUnique(); // return -1\nfirstUnique.add(7);            // the queue is now [7,7,7,7,7,7,7]\nfirstUnique.add(3);            // the queue is now [7,7,7,7,7,7,7,3]\nfirstUnique.add(3);            // the queue is now [7,7,7,7,7,7,7,3,3]\nfirstUnique.add(7);            // the queue is now [7,7,7,7,7,7,7,3,3,7]\nfirstUnique.add(17);           // the queue is now [7,7,7,7,7,7,7,3,3,7,17]\nfirstUnique.showFirstUnique(); // return 17\n
    \n\n

    Example 3:

    \n\n
    \nInput: \n["FirstUnique","showFirstUnique","add","showFirstUnique"]\n[[[809]],[],[809],[]]\nOutput: \n[null,809,null,-1]\nExplanation: \nFirstUnique firstUnique = new FirstUnique([809]);\nfirstUnique.showFirstUnique(); // return 809\nfirstUnique.add(809);          // the queue is now [809,809]\nfirstUnique.showFirstUnique(); // return -1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 10^5
    • \n\t
    • 1 <= nums[i] <= 10^8
    • \n\t
    • 1 <= value <= 10^8
    • \n\t
    • At most 50000 calls will be made to showFirstUnique and add.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u7cfb\u5217\u6574\u6570\uff0c\u63d2\u5165\u4e00\u4e2a\u961f\u5217\u4e2d\uff0c\u627e\u51fa\u961f\u5217\u4e2d\u7b2c\u4e00\u4e2a\u552f\u4e00\u6574\u6570\u3002

    \n\n

    \u5b9e\u73b0\u00a0FirstUnique\u00a0\u7c7b\uff1a

    \n\n
      \n\t
    • FirstUnique(int[] nums) \u7528\u6570\u7ec4\u91cc\u7684\u6570\u5b57\u521d\u59cb\u5316\u961f\u5217\u3002
    • \n\t
    • int showFirstUnique()\u00a0\u8fd4\u56de\u961f\u5217\u4e2d\u7684 \u7b2c\u4e00\u4e2a\u552f\u4e00 \u6574\u6570\u7684\u503c\u3002\u5982\u679c\u6ca1\u6709\u552f\u4e00\u6574\u6570\uff0c\u8fd4\u56de -1\u3002\uff08\u8bd1\u8005\u6ce8\uff1a\u6b64\u65b9\u6cd5\u4e0d\u79fb\u9664\u961f\u5217\u4e2d\u7684\u4efb\u4f55\u5143\u7d20\uff09
    • \n\t
    • void add(int value)\u00a0\u5c06 value \u63d2\u5165\u961f\u5217\u4e2d\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\n[\"FirstUnique\",\"showFirstUnique\",\"add\",\"showFirstUnique\",\"add\",\"showFirstUnique\",\"add\",\"showFirstUnique\"]\n[[[2,3,5]],[],[5],[],[2],[],[3],[]]\n\u8f93\u51fa\uff1a\n[null,2,null,2,null,3,null,-1]\n\u89e3\u91ca\uff1a\nFirstUnique firstUnique = new FirstUnique([2,3,5]);\nfirstUnique.showFirstUnique(); // \u8fd4\u56de 2\nfirstUnique.add(5);            // \u6b64\u65f6\u961f\u5217\u4e3a [2,3,5,5]\nfirstUnique.showFirstUnique(); // \u8fd4\u56de 2\nfirstUnique.add(2);\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 // \u6b64\u65f6\u961f\u5217\u4e3a [2,3,5,5,2]\nfirstUnique.showFirstUnique(); // \u8fd4\u56de 3\nfirstUnique.add(3);\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 // \u6b64\u65f6\u961f\u5217\u4e3a [2,3,5,5,2,3]\nfirstUnique.showFirstUnique(); // \u8fd4\u56de -1\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\n[\"FirstUnique\",\"showFirstUnique\",\"add\",\"add\",\"add\",\"add\",\"add\",\"showFirstUnique\"]\n[[[7,7,7,7,7,7]],[],[7],[3],[3],[7],[17],[]]\n\u8f93\u51fa\uff1a\n[null,-1,null,null,null,null,null,17]\n\u89e3\u91ca\uff1a\nFirstUnique firstUnique = new FirstUnique([7,7,7,7,7,7]);\nfirstUnique.showFirstUnique(); // \u8fd4\u56de -1\nfirstUnique.add(7);            // \u6b64\u65f6\u961f\u5217\u4e3a [7,7,7,7,7,7,7]\nfirstUnique.add(3);\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 // \u6b64\u65f6\u961f\u5217\u4e3a [7,7,7,7,7,7,7,3]\nfirstUnique.add(3);\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 // \u6b64\u65f6\u961f\u5217\u4e3a [7,7,7,7,7,7,7,3,3]\nfirstUnique.add(7);\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 // \u6b64\u65f6\u961f\u5217\u4e3a [7,7,7,7,7,7,7,3,3,7]\nfirstUnique.add(17);\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0// \u6b64\u65f6\u961f\u5217\u4e3a [7,7,7,7,7,7,7,3,3,7,17]\nfirstUnique.showFirstUnique(); // \u8fd4\u56de 17\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\n[\"FirstUnique\",\"showFirstUnique\",\"add\",\"showFirstUnique\"]\n[[[809]],[],[809],[]]\n\u8f93\u51fa\uff1a\n[null,809,null,-1]\n\u89e3\u91ca\uff1a\nFirstUnique firstUnique = new FirstUnique([809]);\nfirstUnique.showFirstUnique(); // \u8fd4\u56de 809\nfirstUnique.add(809);          // \u6b64\u65f6\u961f\u5217\u4e3a [809,809]\nfirstUnique.showFirstUnique(); // \u8fd4\u56de -1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 10^5
    • \n\t
    • 1 <= nums[i] <= 10^8
    • \n\t
    • 1 <= value <= 10^8
    • \n\t
    • \u6700\u591a\u8c03\u7528 5000 \u6b21\u00a0showFirstUnique\u00a0\u548c\u00a0add \u3002
    • \n
    \n", "tags_en": ["Design", "Hash Table"], "tags_cn": ["\u8bbe\u8ba1", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class FirstUnique {\npublic:\n FirstUnique(vector& nums) {\n\n }\n \n int showFirstUnique() {\n\n }\n \n void add(int value) {\n\n }\n};\n\n/**\n * Your FirstUnique object will be instantiated and called as such:\n * FirstUnique* obj = new FirstUnique(nums);\n * int param_1 = obj->showFirstUnique();\n * obj->add(value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class FirstUnique {\n\n public FirstUnique(int[] nums) {\n\n }\n \n public int showFirstUnique() {\n\n }\n \n public void add(int value) {\n\n }\n}\n\n/**\n * Your FirstUnique object will be instantiated and called as such:\n * FirstUnique obj = new FirstUnique(nums);\n * int param_1 = obj.showFirstUnique();\n * obj.add(value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class FirstUnique(object):\n\n def __init__(self, nums):\n \"\"\"\n :type nums: List[int]\n \"\"\"\n\n\n def showFirstUnique(self):\n \"\"\"\n :rtype: int\n \"\"\"\n\n\n def add(self, value):\n \"\"\"\n :type value: int\n :rtype: None\n \"\"\"\n\n\n\n# Your FirstUnique object will be instantiated and called as such:\n# obj = FirstUnique(nums)\n# param_1 = obj.showFirstUnique()\n# obj.add(value)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class FirstUnique:\n\n def __init__(self, nums: List[int]):\n\n\n def showFirstUnique(self) -> int:\n\n\n def add(self, value: int) -> None:\n\n\n\n# Your FirstUnique object will be instantiated and called as such:\n# obj = FirstUnique(nums)\n# param_1 = obj.showFirstUnique()\n# obj.add(value)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} FirstUnique;\n\n\nFirstUnique* firstUniqueCreate(int* nums, int numsSize) {\n\n}\n\nint firstUniqueShowFirstUnique(FirstUnique* obj) {\n\n}\n\nvoid firstUniqueAdd(FirstUnique* obj, int value) {\n\n}\n\nvoid firstUniqueFree(FirstUnique* obj) {\n\n}\n\n/**\n * Your FirstUnique struct will be instantiated and called as such:\n * FirstUnique* obj = firstUniqueCreate(nums, numsSize);\n * int param_1 = firstUniqueShowFirstUnique(obj);\n \n * firstUniqueAdd(obj, value);\n \n * firstUniqueFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class FirstUnique {\n\n public FirstUnique(int[] nums) {\n\n }\n \n public int ShowFirstUnique() {\n\n }\n \n public void Add(int value) {\n\n }\n}\n\n/**\n * Your FirstUnique object will be instantiated and called as such:\n * FirstUnique obj = new FirstUnique(nums);\n * int param_1 = obj.ShowFirstUnique();\n * obj.Add(value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n */\nvar FirstUnique = function(nums) {\n\n};\n\n/**\n * @return {number}\n */\nFirstUnique.prototype.showFirstUnique = function() {\n\n};\n\n/** \n * @param {number} value\n * @return {void}\n */\nFirstUnique.prototype.add = function(value) {\n\n};\n\n/**\n * Your FirstUnique object will be instantiated and called as such:\n * var obj = new FirstUnique(nums)\n * var param_1 = obj.showFirstUnique()\n * obj.add(value)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class FirstUnique\n\n=begin\n :type nums: Integer[]\n=end\n def initialize(nums)\n\n end\n\n\n=begin\n :rtype: Integer\n=end\n def show_first_unique()\n\n end\n\n\n=begin\n :type value: Integer\n :rtype: Void\n=end\n def add(value)\n\n end\n\n\nend\n\n# Your FirstUnique object will be instantiated and called as such:\n# obj = FirstUnique.new(nums)\n# param_1 = obj.show_first_unique()\n# obj.add(value)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass FirstUnique {\n\n init(_ nums: [Int]) {\n\n }\n \n func showFirstUnique() -> Int {\n\n }\n \n func add(_ value: Int) {\n\n }\n}\n\n/**\n * Your FirstUnique object will be instantiated and called as such:\n * let obj = FirstUnique(nums)\n * let ret_1: Int = obj.showFirstUnique()\n * obj.add(value)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type FirstUnique struct {\n\n}\n\n\nfunc Constructor(nums []int) FirstUnique {\n\n}\n\n\nfunc (this *FirstUnique) ShowFirstUnique() int {\n\n}\n\n\nfunc (this *FirstUnique) Add(value int) {\n\n}\n\n\n/**\n * Your FirstUnique object will be instantiated and called as such:\n * obj := Constructor(nums);\n * param_1 := obj.ShowFirstUnique();\n * obj.Add(value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class FirstUnique(_nums: Array[Int]) {\n\n def showFirstUnique(): Int = {\n\n }\n\n def add(value: Int) {\n\n }\n\n}\n\n/**\n * Your FirstUnique object will be instantiated and called as such:\n * var obj = new FirstUnique(nums)\n * var param_1 = obj.showFirstUnique()\n * obj.add(value)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class FirstUnique(nums: IntArray) {\n\n fun showFirstUnique(): Int {\n\n }\n\n fun add(value: Int) {\n\n }\n\n}\n\n/**\n * Your FirstUnique object will be instantiated and called as such:\n * var obj = FirstUnique(nums)\n * var param_1 = obj.showFirstUnique()\n * obj.add(value)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct FirstUnique {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl FirstUnique {\n\n fn new(nums: Vec) -> Self {\n\n }\n \n fn show_first_unique(&self) -> i32 {\n\n }\n \n fn add(&self, value: i32) {\n\n }\n}\n\n/**\n * Your FirstUnique object will be instantiated and called as such:\n * let obj = FirstUnique::new(nums);\n * let ret_1: i32 = obj.show_first_unique();\n * obj.add(value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class FirstUnique {\n /**\n * @param Integer[] $nums\n */\n function __construct($nums) {\n\n }\n\n /**\n * @return Integer\n */\n function showFirstUnique() {\n\n }\n\n /**\n * @param Integer $value\n * @return NULL\n */\n function add($value) {\n\n }\n}\n\n/**\n * Your FirstUnique object will be instantiated and called as such:\n * $obj = FirstUnique($nums);\n * $ret_1 = $obj->showFirstUnique();\n * $obj->add($value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class FirstUnique {\n constructor(nums: number[]) {\n\n }\n\n showFirstUnique(): number {\n\n }\n\n add(value: number): void {\n\n }\n}\n\n/**\n * Your FirstUnique object will be instantiated and called as such:\n * var obj = new FirstUnique(nums)\n * var param_1 = obj.showFirstUnique()\n * obj.add(value)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define first-unique%\n (class object%\n (super-new)\n\n ; nums : (listof exact-integer?)\n (init-field\n nums)\n \n ; show-first-unique : -> exact-integer?\n (define/public (show-first-unique)\n\n )\n ; add : exact-integer? -> void?\n (define/public (add value)\n\n )))\n\n;; Your first-unique% object will be instantiated and called as such:\n;; (define obj (new first-unique% [nums nums]))\n;; (define param_1 (send obj show-first-unique))\n;; (send obj add value)", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1429](https://leetcode-cn.com/problems/first-unique-number)", "[\u7b2c\u4e00\u4e2a\u552f\u4e00\u6570\u5b57](/solution/1400-1499/1429.First%20Unique%20Number/README.md)", "`\u8bbe\u8ba1`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1429](https://leetcode.com/problems/first-unique-number)", "[First Unique Number](/solution/1400-1499/1429.First%20Unique%20Number/README_EN.md)", "`Design`,`Hash Table`", "Medium", "\ud83d\udd12"]}, {"question_id": "1364", "frontend_question_id": "1726", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/tuple-with-same-product", "url_en": "https://leetcode.com/problems/tuple-with-same-product", "relative_path_cn": "/solution/1700-1799/1726.Tuple%20with%20Same%20Product/README.md", "relative_path_en": "/solution/1700-1799/1726.Tuple%20with%20Same%20Product/README_EN.md", "title_cn": "\u540c\u79ef\u5143\u7ec4", "title_en": "Tuple with Same Product", "question_title_slug": "tuple-with-same-product", "content_en": "

    Given an array nums of distinct positive integers, return the number of tuples (a, b, c, d) such that a * b = c * d where a, b, c, and d are elements of nums, and a != b != c != d.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: nums = [2,3,4,6]\r\nOutput: 8\r\nExplanation: There are 8 valid tuples:\r\n(2,6,3,4) , (2,6,4,3) , (6,2,3,4) , (6,2,4,3)\r\n(3,4,2,6) , (4,3,2,6) , (3,4,6,2) , (4,3,6,2)\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: nums = [1,2,4,5,10]\r\nOutput: 16\r\nExplanation: There are 16 valids tuples:\r\n(1,10,2,5) , (1,10,5,2) , (10,1,2,5) , (10,1,5,2)\r\n(2,5,1,10) , (2,5,10,1) , (5,2,1,10) , (5,2,10,1)\r\n(2,10,4,5) , (2,10,5,4) , (10,2,4,5) , (10,2,4,5)\r\n(4,5,2,10) , (4,5,10,2) , (5,4,2,10) , (5,4,10,2)\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: nums = [2,3,4,6,8,12]\r\nOutput: 40\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: nums = [2,3,5,7]\r\nOutput: 0\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= nums.length <= 1000
    • \r\n\t
    • 1 <= nums[i] <= 104
    • \r\n\t
    • All elements in nums are distinct.
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u7531 \u4e0d\u540c \u6b63\u6574\u6570\u7ec4\u6210\u7684\u6570\u7ec4 nums \uff0c\u8bf7\u4f60\u8fd4\u56de\u6ee1\u8db3\u00a0a * b = c * d \u7684\u5143\u7ec4 (a, b, c, d) \u7684\u6570\u91cf\u3002\u5176\u4e2d a\u3001b\u3001c \u548c d \u90fd\u662f nums \u4e2d\u7684\u5143\u7d20\uff0c\u4e14 a != b != c != d \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [2,3,4,6]\n\u8f93\u51fa\uff1a8\n\u89e3\u91ca\uff1a\u5b58\u5728 8 \u4e2a\u6ee1\u8db3\u9898\u610f\u7684\u5143\u7ec4\uff1a\n(2,6,3,4) , (2,6,4,3) , (6,2,3,4) , (6,2,4,3)\n(3,4,2,6) , (4,3,2,6) , (3,4,6,2) , (4,3,6,2)\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,4,5,10]\n\u8f93\u51fa\uff1a16\n\u89e3\u91ca\uff1a\u5b58\u5728 16 \u4e2a\u6ee1\u8db3\u9898\u610f\u7684\u5143\u7ec4\uff1a\n(1,10,2,5) , (1,10,5,2) , (10,1,2,5) , (10,1,5,2)\n(2,5,1,10) , (2,5,10,1) , (5,2,1,10) , (5,2,10,1)\n(2,10,4,5) , (2,10,5,4) , (10,2,4,5) , (10,2,4,5)\n(4,5,2,10) , (4,5,10,2) , (5,4,2,10) , (5,4,10,2)\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [2,3,4,6,8,12]\n\u8f93\u51fa\uff1a40\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [2,3,5,7]\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 1000
    • \n\t
    • 1 <= nums[i] <= 104
    • \n\t
    • nums \u4e2d\u7684\u6240\u6709\u5143\u7d20 \u4e92\u4e0d\u76f8\u540c
    • \n
    \n", "tags_en": ["Array", "Hash Table"], "tags_cn": ["\u6570\u7ec4", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int tupleSameProduct(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int tupleSameProduct(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def tupleSameProduct(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def tupleSameProduct(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint tupleSameProduct(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int TupleSameProduct(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar tupleSameProduct = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef tuple_same_product(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func tupleSameProduct(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func tupleSameProduct(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def tupleSameProduct(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun tupleSameProduct(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn tuple_same_product(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function tupleSameProduct($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function tupleSameProduct(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (tuple-same-product nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1726](https://leetcode-cn.com/problems/tuple-with-same-product)", "[\u540c\u79ef\u5143\u7ec4](/solution/1700-1799/1726.Tuple%20with%20Same%20Product/README.md)", "`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1726](https://leetcode.com/problems/tuple-with-same-product)", "[Tuple with Same Product](/solution/1700-1799/1726.Tuple%20with%20Same%20Product/README_EN.md)", "`Array`,`Hash Table`", "Medium", ""]}, {"question_id": "1362", "frontend_question_id": "1227", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/airplane-seat-assignment-probability", "url_en": "https://leetcode.com/problems/airplane-seat-assignment-probability", "relative_path_cn": "/solution/1200-1299/1227.Airplane%20Seat%20Assignment%20Probability/README.md", "relative_path_en": "/solution/1200-1299/1227.Airplane%20Seat%20Assignment%20Probability/README_EN.md", "title_cn": "\u98de\u673a\u5ea7\u4f4d\u5206\u914d\u6982\u7387", "title_en": "Airplane Seat Assignment Probability", "question_title_slug": "airplane-seat-assignment-probability", "content_en": "

    n passengers board an airplane with exactly n seats. The first passenger has lost the ticket and picks a seat randomly. But after that, the rest of passengers will:

    \r\n\r\n
      \r\n\t
    • Take their own seat if it is still available, 
    • \r\n\t
    • Pick other seats randomly when they find their seat occupied 
    • \r\n
    \r\n\r\n

    What is the probability that the n-th person can get his own seat?

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: n = 1\r\nOutput: 1.00000\r\nExplanation: The first person can only get the first seat.
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: n = 2\r\nOutput: 0.50000\r\nExplanation: The second person has a probability of 0.5 to get the second seat (when first person gets the first seat).\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= n <= 10^5
    • \r\n
    ", "content_cn": "

    \u6709 n \u4f4d\u4e58\u5ba2\u5373\u5c06\u767b\u673a\uff0c\u98de\u673a\u6b63\u597d\u6709 n \u4e2a\u5ea7\u4f4d\u3002\u7b2c\u4e00\u4f4d\u4e58\u5ba2\u7684\u7968\u4e22\u4e86\uff0c\u4ed6\u968f\u4fbf\u9009\u4e86\u4e00\u4e2a\u5ea7\u4f4d\u5750\u4e0b\u3002

    \n\n

    \u5269\u4e0b\u7684\u4e58\u5ba2\u5c06\u4f1a\uff1a

    \n\n
      \n\t
    • \n\t

      \u5982\u679c\u4ed6\u4eec\u81ea\u5df1\u7684\u5ea7\u4f4d\u8fd8\u7a7a\u7740\uff0c\u5c31\u5750\u5230\u81ea\u5df1\u7684\u5ea7\u4f4d\u4e0a\uff0c

      \n\t
    • \n\t
    • \u5f53\u4ed6\u4eec\u81ea\u5df1\u7684\u5ea7\u4f4d\u88ab\u5360\u7528\u65f6\uff0c\u968f\u673a\u9009\u62e9\u5176\u4ed6\u5ea7\u4f4d
    • \n
    \n\n

    \u7b2c n \u4f4d\u4e58\u5ba2\u5750\u5728\u81ea\u5df1\u7684\u5ea7\u4f4d\u4e0a\u7684\u6982\u7387\u662f\u591a\u5c11\uff1f

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1a1.00000\n\u89e3\u91ca\uff1a\u7b2c\u4e00\u4e2a\u4eba\u53ea\u4f1a\u5750\u5728\u81ea\u5df1\u7684\u4f4d\u7f6e\u4e0a\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165: n = 2\n\u8f93\u51fa: 0.50000\n\u89e3\u91ca\uff1a\u5728\u7b2c\u4e00\u4e2a\u4eba\u9009\u597d\u5ea7\u4f4d\u5750\u4e0b\u540e\uff0c\u7b2c\u4e8c\u4e2a\u4eba\u5750\u5728\u81ea\u5df1\u7684\u5ea7\u4f4d\u4e0a\u7684\u6982\u7387\u662f 0.5\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 10^5
    • \n
    \n", "tags_en": ["Brainteaser", "Math", "Dynamic Programming"], "tags_cn": ["\u8111\u7b4b\u6025\u8f6c\u5f2f", "\u6570\u5b66", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n double nthPersonGetsNthSeat(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double nthPersonGetsNthSeat(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def nthPersonGetsNthSeat(self, n):\n \"\"\"\n :type n: int\n :rtype: float\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def nthPersonGetsNthSeat(self, n: int) -> float:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\ndouble nthPersonGetsNthSeat(int n){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double NthPersonGetsNthSeat(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar nthPersonGetsNthSeat = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Float}\ndef nth_person_gets_nth_seat(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func nthPersonGetsNthSeat(_ n: Int) -> Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func nthPersonGetsNthSeat(n int) float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def nthPersonGetsNthSeat(n: Int): Double = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun nthPersonGetsNthSeat(n: Int): Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn nth_person_gets_nth_seat(n: i32) -> f64 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Float\n */\n function nthPersonGetsNthSeat($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function nthPersonGetsNthSeat(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (nth-person-gets-nth-seat n)\n (-> exact-integer? flonum?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1227](https://leetcode-cn.com/problems/airplane-seat-assignment-probability)", "[\u98de\u673a\u5ea7\u4f4d\u5206\u914d\u6982\u7387](/solution/1200-1299/1227.Airplane%20Seat%20Assignment%20Probability/README.md)", "`\u8111\u7b4b\u6025\u8f6c\u5f2f`,`\u6570\u5b66`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1227](https://leetcode.com/problems/airplane-seat-assignment-probability)", "[Airplane Seat Assignment Probability](/solution/1200-1299/1227.Airplane%20Seat%20Assignment%20Probability/README_EN.md)", "`Brainteaser`,`Math`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "1361", "frontend_question_id": "1240", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/tiling-a-rectangle-with-the-fewest-squares", "url_en": "https://leetcode.com/problems/tiling-a-rectangle-with-the-fewest-squares", "relative_path_cn": "/solution/1200-1299/1240.Tiling%20a%20Rectangle%20with%20the%20Fewest%20Squares/README.md", "relative_path_en": "/solution/1200-1299/1240.Tiling%20a%20Rectangle%20with%20the%20Fewest%20Squares/README_EN.md", "title_cn": "\u94fa\u74f7\u7816", "title_en": "Tiling a Rectangle with the Fewest Squares", "question_title_slug": "tiling-a-rectangle-with-the-fewest-squares", "content_en": "

    Given a rectangle of size n x m, find the minimum number of integer-sided squares that tile the rectangle.

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: n = 2, m = 3\nOutput: 3\nExplanation: 3 squares are necessary to cover the rectangle.\n2 (squares of 1x1)\n1 (square of 2x2)
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: n = 5, m = 8\nOutput: 5\n
    \n\n

    Example 3:

    \n\n

    \"\"

    \n\n
    \nInput: n = 11, m = 13\nOutput: 6\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 13
    • \n\t
    • 1 <= m <= 13
    • \n
    \n", "content_cn": "

    \u4f60\u662f\u4e00\u4f4d\u65bd\u5de5\u961f\u7684\u5de5\u957f\uff0c\u6839\u636e\u8bbe\u8ba1\u5e08\u7684\u8981\u6c42\u51c6\u5907\u4e3a\u4e00\u5957\u8bbe\u8ba1\u98ce\u683c\u72ec\u7279\u7684\u623f\u5b50\u8fdb\u884c\u5ba4\u5185\u88c5\u4fee\u3002

    \n\n

    \u623f\u5b50\u7684\u5ba2\u5385\u5927\u5c0f\u4e3a n x m\uff0c\u4e3a\u4fdd\u6301\u6781\u7b80\u7684\u98ce\u683c\uff0c\u9700\u8981\u4f7f\u7528\u5c3d\u53ef\u80fd\u5c11\u7684 \u6b63\u65b9\u5f62 \u74f7\u7816\u6765\u94fa\u76d6\u5730\u9762\u3002

    \n\n

    \u5047\u8bbe\u6b63\u65b9\u5f62\u74f7\u7816\u7684\u89c4\u683c\u4e0d\u9650\uff0c\u8fb9\u957f\u90fd\u662f\u6574\u6570\u3002

    \n\n

    \u8bf7\u4f60\u5e2e\u8bbe\u8ba1\u5e08\u8ba1\u7b97\u4e00\u4e0b\uff0c\u6700\u5c11\u9700\u8981\u7528\u5230\u591a\u5c11\u5757\u65b9\u5f62\u74f7\u7816\uff1f

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 2, m = 3\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a3 \u5757\u5730\u7816\u5c31\u53ef\u4ee5\u94fa\u6ee1\u5367\u5ba4\u3002\n     2 \u5757 1x1 \u5730\u7816\n     1 \u5757 2x2 \u5730\u7816
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 5, m = 8\n\u8f93\u51fa\uff1a5\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 11, m = 13\n\u8f93\u51fa\uff1a6\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 13
    • \n\t
    • 1 <= m <= 13
    • \n
    \n", "tags_en": ["Dynamic Programming", "Backtracking"], "tags_cn": ["\u52a8\u6001\u89c4\u5212", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int tilingRectangle(int n, int m) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int tilingRectangle(int n, int m) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def tilingRectangle(self, n, m):\n \"\"\"\n :type n: int\n :type m: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def tilingRectangle(self, n: int, m: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint tilingRectangle(int n, int m){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int TilingRectangle(int n, int m) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} m\n * @return {number}\n */\nvar tilingRectangle = function(n, m) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} m\n# @return {Integer}\ndef tiling_rectangle(n, m)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func tilingRectangle(_ n: Int, _ m: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func tilingRectangle(n int, m int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def tilingRectangle(n: Int, m: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun tilingRectangle(n: Int, m: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn tiling_rectangle(n: i32, m: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $m\n * @return Integer\n */\n function tilingRectangle($n, $m) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function tilingRectangle(n: number, m: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (tiling-rectangle n m)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1240](https://leetcode-cn.com/problems/tiling-a-rectangle-with-the-fewest-squares)", "[\u94fa\u74f7\u7816](/solution/1200-1299/1240.Tiling%20a%20Rectangle%20with%20the%20Fewest%20Squares/README.md)", "`\u52a8\u6001\u89c4\u5212`,`\u56de\u6eaf\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[1240](https://leetcode.com/problems/tiling-a-rectangle-with-the-fewest-squares)", "[Tiling a Rectangle with the Fewest Squares](/solution/1200-1299/1240.Tiling%20a%20Rectangle%20with%20the%20Fewest%20Squares/README_EN.md)", "`Dynamic Programming`,`Backtracking`", "Hard", ""]}, {"question_id": "1360", "frontend_question_id": "1239", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-length-of-a-concatenated-string-with-unique-characters", "url_en": "https://leetcode.com/problems/maximum-length-of-a-concatenated-string-with-unique-characters", "relative_path_cn": "/solution/1200-1299/1239.Maximum%20Length%20of%20a%20Concatenated%20String%20with%20Unique%20Characters/README.md", "relative_path_en": "/solution/1200-1299/1239.Maximum%20Length%20of%20a%20Concatenated%20String%20with%20Unique%20Characters/README_EN.md", "title_cn": "\u4e32\u8054\u5b57\u7b26\u4e32\u7684\u6700\u5927\u957f\u5ea6", "title_en": "Maximum Length of a Concatenated String with Unique Characters", "question_title_slug": "maximum-length-of-a-concatenated-string-with-unique-characters", "content_en": "

    Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters.

    \n\n

    Return the maximum possible length of s.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr = ["un","iq","ue"]\nOutput: 4\nExplanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".\nMaximum length is 4.\n
    \n\n

    Example 2:

    \n\n
    \nInput: arr = ["cha","r","act","ers"]\nOutput: 6\nExplanation: Possible solutions are "chaers" and "acters".\n
    \n\n

    Example 3:

    \n\n
    \nInput: arr = ["abcdefghijklmnopqrstuvwxyz"]\nOutput: 26\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= arr.length <= 16
    • \n\t
    • 1 <= arr[i].length <= 26
    • \n\t
    • arr[i] contains only lower case English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4 arr\uff0c\u5b57\u7b26\u4e32 s \u662f\u5c06 arr \u67d0\u4e00\u5b50\u5e8f\u5217\u5b57\u7b26\u4e32\u8fde\u63a5\u6240\u5f97\u7684\u5b57\u7b26\u4e32\uff0c\u5982\u679c s \u4e2d\u7684\u6bcf\u4e00\u4e2a\u5b57\u7b26\u90fd\u53ea\u51fa\u73b0\u8fc7\u4e00\u6b21\uff0c\u90a3\u4e48\u5b83\u5c31\u662f\u4e00\u4e2a\u53ef\u884c\u89e3\u3002

    \n\n

    \u8bf7\u8fd4\u56de\u6240\u6709\u53ef\u884c\u89e3 s \u4e2d\u6700\u957f\u957f\u5ea6\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = ["un","iq","ue"]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u6240\u6709\u53ef\u80fd\u7684\u4e32\u8054\u7ec4\u5408\u662f "","un","iq","ue","uniq" \u548c "ique"\uff0c\u6700\u5927\u957f\u5ea6\u4e3a 4\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = ["cha","r","act","ers"]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u53ef\u80fd\u7684\u89e3\u7b54\u6709 "chaers" \u548c "acters"\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = ["abcdefghijklmnopqrstuvwxyz"]\n\u8f93\u51fa\uff1a26\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= arr.length <= 16
    • \n\t
    • 1 <= arr[i].length <= 26
    • \n\t
    • arr[i] \u4e2d\u53ea\u542b\u6709\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd
    • \n
    \n", "tags_en": ["Bit Manipulation", "Backtracking"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxLength(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxLength(List arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxLength(self, arr):\n \"\"\"\n :type arr: List[str]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxLength(self, arr: List[str]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxLength(char ** arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxLength(IList arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} arr\n * @return {number}\n */\nvar maxLength = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} arr\n# @return {Integer}\ndef max_length(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxLength(_ arr: [String]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxLength(arr []string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxLength(arr: List[String]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxLength(arr: List): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_length(arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $arr\n * @return Integer\n */\n function maxLength($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxLength(arr: string[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-length arr)\n (-> (listof string?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1239](https://leetcode-cn.com/problems/maximum-length-of-a-concatenated-string-with-unique-characters)", "[\u4e32\u8054\u5b57\u7b26\u4e32\u7684\u6700\u5927\u957f\u5ea6](/solution/1200-1299/1239.Maximum%20Length%20of%20a%20Concatenated%20String%20with%20Unique%20Characters/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1239](https://leetcode.com/problems/maximum-length-of-a-concatenated-string-with-unique-characters)", "[Maximum Length of a Concatenated String with Unique Characters](/solution/1200-1299/1239.Maximum%20Length%20of%20a%20Concatenated%20String%20with%20Unique%20Characters/README_EN.md)", "`Bit Manipulation`,`Backtracking`", "Medium", ""]}, {"question_id": "1359", "frontend_question_id": "1238", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/circular-permutation-in-binary-representation", "url_en": "https://leetcode.com/problems/circular-permutation-in-binary-representation", "relative_path_cn": "/solution/1200-1299/1238.Circular%20Permutation%20in%20Binary%20Representation/README.md", "relative_path_en": "/solution/1200-1299/1238.Circular%20Permutation%20in%20Binary%20Representation/README_EN.md", "title_cn": "\u5faa\u73af\u7801\u6392\u5217", "title_en": "Circular Permutation in Binary Representation", "question_title_slug": "circular-permutation-in-binary-representation", "content_en": "

    Given 2 integers n and start. Your task is return any permutation p of (0,1,2.....,2^n -1) such that :

    \r\n\r\n
      \r\n\t
    • p[0] = start
    • \r\n\t
    • p[i] and p[i+1] differ by only one bit in their binary representation.
    • \r\n\t
    • p[0] and p[2^n -1] must also differ by only one bit in their binary representation.
    • \r\n
    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: n = 2, start = 3\r\nOutput: [3,2,0,1]\r\nExplanation: The binary representation of the permutation is (11,10,00,01). \r\nAll the adjacent element differ by one bit. Another valid permutation is [3,1,0,2]\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: n = 3, start = 2\r\nOutput: [2,6,7,5,4,0,1,3]\r\nExplanation: The binary representation of the permutation is (010,110,111,101,100,000,001,011).\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= n <= 16
    • \r\n\t
    • 0 <= start < 2 ^ n
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u6574\u6570 n \u548c start\u3002\u4f60\u7684\u4efb\u52a1\u662f\u8fd4\u56de\u4efb\u610f (0,1,2,,...,2^n-1) \u7684\u6392\u5217 p\uff0c\u5e76\u4e14\u6ee1\u8db3\uff1a

    \n\n
      \n\t
    • p[0] = start
    • \n\t
    • p[i] \u548c p[i+1] \u7684\u4e8c\u8fdb\u5236\u8868\u793a\u5f62\u5f0f\u53ea\u6709\u4e00\u4f4d\u4e0d\u540c
    • \n\t
    • p[0] \u548c p[2^n -1] \u7684\u4e8c\u8fdb\u5236\u8868\u793a\u5f62\u5f0f\u4e5f\u53ea\u6709\u4e00\u4f4d\u4e0d\u540c
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1an = 2, start = 3\n\u8f93\u51fa\uff1a[3,2,0,1]\n\u89e3\u91ca\uff1a\u8fd9\u4e2a\u6392\u5217\u7684\u4e8c\u8fdb\u5236\u8868\u793a\u662f (11,10,00,01)\n     \u6240\u6709\u7684\u76f8\u90bb\u5143\u7d20\u90fd\u6709\u4e00\u4f4d\u662f\u4e0d\u540c\u7684\uff0c\u53e6\u4e00\u4e2a\u6709\u6548\u7684\u6392\u5217\u662f [3,1,0,2]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u51fa\uff1an = 3, start = 2\n\u8f93\u51fa\uff1a[2,6,7,5,4,0,1,3]\n\u89e3\u91ca\uff1a\u8fd9\u4e2a\u6392\u5217\u7684\u4e8c\u8fdb\u5236\u8868\u793a\u662f (010,110,111,101,100,000,001,011)\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 16
    • \n\t
    • 0 <= start < 2^n
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector circularPermutation(int n, int start) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List circularPermutation(int n, int start) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def circularPermutation(self, n, start):\n \"\"\"\n :type n: int\n :type start: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def circularPermutation(self, n: int, start: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* circularPermutation(int n, int start, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList CircularPermutation(int n, int start) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} start\n * @return {number[]}\n */\nvar circularPermutation = function(n, start) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} start\n# @return {Integer[]}\ndef circular_permutation(n, start)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func circularPermutation(_ n: Int, _ start: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func circularPermutation(n int, start int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def circularPermutation(n: Int, start: Int): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun circularPermutation(n: Int, start: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn circular_permutation(n: i32, start: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $start\n * @return Integer[]\n */\n function circularPermutation($n, $start) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function circularPermutation(n: number, start: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (circular-permutation n start)\n (-> exact-integer? exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1238](https://leetcode-cn.com/problems/circular-permutation-in-binary-representation)", "[\u5faa\u73af\u7801\u6392\u5217](/solution/1200-1299/1238.Circular%20Permutation%20in%20Binary%20Representation/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1238](https://leetcode.com/problems/circular-permutation-in-binary-representation)", "[Circular Permutation in Binary Representation](/solution/1200-1299/1238.Circular%20Permutation%20in%20Binary%20Representation/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "1358", "frontend_question_id": "1237", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-positive-integer-solution-for-a-given-equation", "url_en": "https://leetcode.com/problems/find-positive-integer-solution-for-a-given-equation", "relative_path_cn": "/solution/1200-1299/1237.Find%20Positive%20Integer%20Solution%20for%20a%20Given%20Equation/README.md", "relative_path_en": "/solution/1200-1299/1237.Find%20Positive%20Integer%20Solution%20for%20a%20Given%20Equation/README_EN.md", "title_cn": "\u627e\u51fa\u7ed9\u5b9a\u65b9\u7a0b\u7684\u6b63\u6574\u6570\u89e3", "title_en": "Find Positive Integer Solution for a Given Equation", "question_title_slug": "find-positive-integer-solution-for-a-given-equation", "content_en": "

    Given a callable function f(x, y) with a hidden formula and a value z, reverse engineer the formula and return all positive integer pairs x and y where f(x,y) == z. You may return the pairs in any order.

    \n\n

    While the exact formula is hidden, the function is monotonically increasing, i.e.:

    \n\n
      \n\t
    • f(x, y) < f(x + 1, y)
    • \n\t
    • f(x, y) < f(x, y + 1)
    • \n
    \n\n

    The function interface is defined like this:

    \n\n
    \ninterface CustomFunction {\npublic:\n  // Returns some positive integer f(x, y) for two positive integers x and y based on a formula.\n  int f(int x, int y);\n};\n
    \n\n

    We will judge your solution as follows:

    \n\n
      \n\t
    • The judge has a list of 9 hidden implementations of CustomFunction, along with a way to generate an answer key of all valid pairs for a specific z.
    • \n\t
    • The judge will receive two inputs: a function_id (to determine which implementation to test your code with), and the target z.
    • \n\t
    • The judge will call your findSolution and compare your results with the answer key.
    • \n\t
    • If your results match the answer key, your solution will be Accepted.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: function_id = 1, z = 5\nOutput: [[1,4],[2,3],[3,2],[4,1]]\nExplanation: The hidden formula for function_id = 1 is f(x, y) = x + y.\nThe following positive integer values of x and y make f(x, y) equal to 5:\nx=1, y=4 -> f(1, 4) = 1 + 4 = 5.\nx=2, y=3 -> f(2, 3) = 2 + 3 = 5.\nx=3, y=2 -> f(3, 2) = 3 + 2 = 5.\nx=4, y=1 -> f(4, 1) = 4 + 1 = 5.\n
    \n\n

    Example 2:

    \n\n
    \nInput: function_id = 2, z = 5\nOutput: [[1,5],[5,1]]\nExplanation: The hidden formula for function_id = 2 is f(x, y) = x * y.\nThe following positive integer values of x and y make f(x, y) equal to 5:\nx=1, y=5 -> f(1, 5) = 1 * 5 = 5.\nx=5, y=1 -> f(5, 1) = 5 * 1 = 5.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= function_id <= 9
    • \n\t
    • 1 <= z <= 100
    • \n\t
    • It is guaranteed that the solutions of f(x, y) == z will be in the range 1 <= x, y <= 1000.
    • \n\t
    • It is also guaranteed that f(x, y) will fit in 32 bit signed integer if 1 <= x, y <= 1000.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u51fd\u6570\u00a0\u00a0f(x, y)\u00a0\u548c\u4e00\u4e2a\u76ee\u6807\u7ed3\u679c\u00a0z\uff0c\u51fd\u6570\u516c\u5f0f\u672a\u77e5\uff0c\u8bf7\u4f60\u8ba1\u7b97\u65b9\u7a0b\u00a0f(x,y) == z\u00a0\u6240\u6709\u53ef\u80fd\u7684\u6b63\u6574\u6570 \u6570\u5bf9\u00a0x \u548c y\u3002\u6ee1\u8db3\u6761\u4ef6\u7684\u7ed3\u679c\u6570\u5bf9\u53ef\u4ee5\u6309\u4efb\u610f\u987a\u5e8f\u8fd4\u56de\u3002

    \n\n

    \u5c3d\u7ba1\u51fd\u6570\u7684\u5177\u4f53\u5f0f\u5b50\u672a\u77e5\uff0c\u4f46\u5b83\u662f\u5355\u8c03\u9012\u589e\u51fd\u6570\uff0c\u4e5f\u5c31\u662f\u8bf4\uff1a

    \n\n
      \n\t
    • f(x, y) < f(x + 1, y)
    • \n\t
    • f(x, y) < f(x, y + 1)
    • \n
    \n\n

    \u51fd\u6570\u63a5\u53e3\u5b9a\u4e49\u5982\u4e0b\uff1a

    \n\n
    \ninterface CustomFunction {\npublic:\n  // Returns some positive integer f(x, y) for two positive integers x and y based on a formula.\n  int f(int x, int y);\n};
    \n\n

    \u4f60\u7684\u89e3\u51b3\u65b9\u6848\u5c06\u6309\u5982\u4e0b\u89c4\u5219\u8fdb\u884c\u8bc4\u5224\uff1a

    \n\n
      \n\t
    • \u5224\u9898\u7a0b\u5e8f\u6709\u4e00\u4e2a\u7531 CustomFunction \u7684 9 \u79cd\u5b9e\u73b0\u7ec4\u6210\u7684\u5217\u8868\uff0c\u4ee5\u53ca\u4e00\u79cd\u4e3a\u7279\u5b9a\u7684 z \u751f\u6210\u6240\u6709\u6709\u6548\u6570\u5bf9\u7684\u7b54\u6848\u7684\u65b9\u6cd5\u3002
    • \n\t
    • \u5224\u9898\u7a0b\u5e8f\u63a5\u53d7\u4e24\u4e2a\u8f93\u5165\uff1afunction_id\uff08\u51b3\u5b9a\u4f7f\u7528\u54ea\u79cd\u5b9e\u73b0\u6d4b\u8bd5\u4f60\u7684\u4ee3\u7801\uff09\u4ee5\u53ca\u76ee\u6807\u7ed3\u679c z \u3002
    • \n\t
    • \u5224\u9898\u7a0b\u5e8f\u5c06\u4f1a\u8c03\u7528\u4f60\u5b9e\u73b0\u7684 findSolution \u5e76\u5c06\u4f60\u7684\u7ed3\u679c\u4e0e\u7b54\u6848\u8fdb\u884c\u6bd4\u8f83\u3002
    • \n\t
    • \u5982\u679c\u4f60\u7684\u7ed3\u679c\u4e0e\u7b54\u6848\u76f8\u7b26\uff0c\u90a3\u4e48\u89e3\u51b3\u65b9\u6848\u5c06\u88ab\u89c6\u4f5c\u6b63\u786e\u7b54\u6848\uff0c\u5373 Accepted \u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1afunction_id = 1, z = 5\n\u8f93\u51fa\uff1a[[1,4],[2,3],[3,2],[4,1]]\n\u89e3\u91ca\uff1afunction_id = 1 \u6697\u542b\u7684\u51fd\u6570\u5f0f\u5b50\u4e3a f(x, y) = x + y\n\u4ee5\u4e0b x \u548c y \u6ee1\u8db3 f(x, y) \u7b49\u4e8e 5\uff1a\nx=1, y=4 -> f(1, 4) = 1 + 4 = 5\nx=2, y=3 -> f(2, 3) = 2 + 3 = 5\nx=3, y=2 -> f(3, 2) = 3 + 2 = 5\nx=4, y=1 -> f(4, 1) = 4 + 1 = 5\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1afunction_id = 2, z = 5\n\u8f93\u51fa\uff1a[[1,5],[5,1]]\n\u89e3\u91ca\uff1afunction_id = 2 \u6697\u542b\u7684\u51fd\u6570\u5f0f\u5b50\u4e3a f(x, y) = x * y\n\u4ee5\u4e0b x \u548c y \u6ee1\u8db3 f(x, y) \u7b49\u4e8e 5\uff1a\nx=1, y=5 -> f(1, 5) = 1 * 5 = 5\nx=5, y=1 -> f(5, 1) = 5 * 1 = 5
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= function_id <= 9
    • \n\t
    • 1 <= z <= 100
    • \n\t
    • \u9898\u76ee\u4fdd\u8bc1\u00a0f(x, y) == z\u00a0\u7684\u89e3\u5904\u4e8e\u00a01 <= x, y <= 1000\u00a0\u7684\u8303\u56f4\u5185\u3002
    • \n\t
    • \u5728 1 <= x, y <= 1000\u00a0\u7684\u524d\u63d0\u4e0b\uff0c\u9898\u76ee\u4fdd\u8bc1\u00a0f(x, y)\u00a0\u662f\u4e00\u4e2a\u00a032 \u4f4d\u6709\u7b26\u53f7\u6574\u6570\u3002
    • \n
    \n", "tags_en": ["Math", "Binary Search"], "tags_cn": ["\u6570\u5b66", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n * // This is the custom function interface.\n * // You should not implement it, or speculate about its implementation\n * class CustomFunction {\n * public:\n * // Returns f(x, y) for any given positive integers x and y.\n * // Note that f(x, y) is increasing with respect to both x and y.\n * // i.e. f(x, y) < f(x + 1, y), f(x, y) < f(x, y + 1)\n * int f(int x, int y);\n * };\n */\n\nclass Solution {\npublic:\n vector> findSolution(CustomFunction& customfunction, int z) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/*\n * // This is the custom function interface.\n * // You should not implement it, or speculate about its implementation\n * class CustomFunction {\n * // Returns f(x, y) for any given positive integers x and y.\n * // Note that f(x, y) is increasing with respect to both x and y.\n * // i.e. f(x, y) < f(x + 1, y), f(x, y) < f(x, y + 1)\n * public int f(int x, int y);\n * };\n */\n\nclass Solution {\n public List> findSolution(CustomFunction customfunction, int z) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "\"\"\"\n This is the custom function interface.\n You should not implement it, or speculate about its implementation\n class CustomFunction:\n # Returns f(x, y) for any given positive integers x and y.\n # Note that f(x, y) is increasing with respect to both x and y.\n # i.e. f(x, y) < f(x + 1, y), f(x, y) < f(x, y + 1)\n def f(self, x, y):\n\"\"\"\n\nclass Solution(object):\n def findSolution(self, customfunction, z):\n \"\"\"\n :type num: int\n :type z: int\n :rtype: List[List[int]]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "\"\"\"\n This is the custom function interface.\n You should not implement it, or speculate about its implementation\n class CustomFunction:\n # Returns f(x, y) for any given positive integers x and y.\n # Note that f(x, y) is increasing with respect to both x and y.\n # i.e. f(x, y) < f(x + 1, y), f(x, y) < f(x, y + 1)\n def f(self, x, y):\n \n\"\"\"\n\nclass Solution:\n def findSolution(self, customfunction: 'CustomFunction', z: int) -> List[List[int]]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/*\n * // This is the definition for customFunction API.\n * // You should not implement it, or speculate about its implementation\n *\n * // Returns f(x, y) for any given positive integers x and y.\n * // Note that f(x, y) is increasing with respect to both x and y.\n * // i.e. f(x, y) < f(x + 1, y), f(x, y) < f(x, y + 1)\n */\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** findSolution(int (*customFunction)(int, int), int z, int* returnSize, int** returnColumnSizes) {\n\t\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/*\n * // This is the custom function interface.\n * // You should not implement it, or speculate about its implementation\n * public class CustomFunction {\n * // Returns f(x, y) for any given positive integers x and y.\n * // Note that f(x, y) is increasing with respect to both x and y.\n * // i.e. f(x, y) < f(x + 1, y), f(x, y) < f(x, y + 1)\n * public int f(int x, int y);\n * };\n */\n\npublic class Solution {\n public IList> FindSolution(CustomFunction customfunction, int z) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // This is the CustomFunction's API interface.\n * // You should not implement it, or speculate about its implementation\n * function CustomFunction() {\n * @param {integer, integer} x, y\n * @return {integer}\n * this.f = function(x, y) {\n * ...\n * };\n * };\n */\n\n/**\n * @param {CustomFunction} customfunction\n * @param {integer} z\n * @return {integer[][]}\n */\nvar findSolution = function(customfunction, z) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# \tThis is the custom function interface.\n#\tYou should not implement it, or speculate about its implementation\n#\tclass CustomFunction:\n#\t\tdef f(self, x, y):\n# \t\t\tReturns f(x, y) for any given positive integers x and y.\n# \t\t\tNote that f(x, y) is increasing with respect to both x and y.\n# \t\t\ti.e. f(x, y) < f(x + 1, y), f(x, y) < f(x, y + 1)\n# \t\tend\n# \tend\n# \n\n# @param {CustomFunction} customfunction\n# @param {Integer} z\n# @return {List[List[Integer]]}\ndef findSolution(customfunction, z)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/*\n * // This is the custom function interface.\n * // You should not implement it, or speculate about its implementation\n * class CustomFunction {\n * // Returns f(x, y) for any given positive integers x and y.\n * // Note that f(x, y) is increasing with respect to both x and y.\n * // i.e. f(x, y) < f(x + 1, y), f(x, y) < f(x, y + 1)\n * func f(_ x: Int, _ y: Int) -> Int {}\n * }\n */\n\nclass Solution {\n func findSolution(_ customfunction: CustomFunction, _ z: Int) -> [[Int]] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/** \n * This is the declaration of customFunction API.\n * @param x int\n * @param x int\n * @return \t Returns f(x, y) for any given positive integers x and y.\n *\t\t\t Note that f(x, y) is increasing with respect to both x and y.\n * i.e. f(x, y) < f(x + 1, y), f(x, y) < f(x, y + 1)\n */\n\nfunc findSolution(customFunction func(int, int) int, z int) [][]int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/*\n * // This is the custom function interface.\n * // You should not implement it, or speculate about its implementation\n * class CustomFunction {\n * // Returns f(x, y) for any given positive integers x and y.\n * // Note that f(x, y) is increasing with respect to both x and y.\n * // i.e. f(x, y) < f(x + 1, y), f(x, y) < f(x, y + 1)\n * def f(x: Int, y: Int): Int = {}\n * };\n */\n\nobject Solution {\n def findSolution(customfunction: CustomFunction, z: Int): List[List[Int]] = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/*\n * // This is the custom function interface.\n * // You should not implement it, or speculate about its implementation\n * class CustomFunction {\n * // Returns f(x, y) for any given positive integers x and y.\n * // Note that f(x, y) is increasing with respect to both x and y.\n * // i.e. f(x, y) < f(x + 1, y), f(x, y) < f(x, y + 1)\n * fun f(x:Int, y:Int):Int {}\n * };\n */\n\nclass Solution {\n\tfun findSolution(customfunction:CustomFunction, z:Int):List> {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "/*\n * // This is the custom function interface.\n * // You should not implement it, or speculate about its implementation\n * struct CustomFunction;\n * impl CustomFunction {\n * pub fn f(x:i32,y:i32)->i32{}\n * }\n */\n\nimpl Solution {\n pub fn find_solution(customfunction: &CustomFunction, z: i32) -> Vec> {\n\t\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/*\n * // This is the custom function interface.\n * // You should not implement it, or speculate about its implementation\n * class CustomFunction {\n * // Returns f(x, y) for any given positive integers x and y.\n * // Note that f(x, y) is increasing with respect to both x and y.\n * // i.e. f(x, y) < f(x + 1, y), f(x, y) < f(x, y + 1)\n * public function f($x, $y){}\n * };\n */\n\nclass Solution {\n /**\n * @param CustomFunction $customfunction\n * @param Integer $z\n * @return Integer[][]\n */\n function findSolution($customfunction, $n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * // This is the CustomFunction's API interface.\n * // You should not implement it, or speculate about its implementation\n * class CustomFunction {\n * f(x: number, y: number): number {}\n * }\n */\n\nfunction findSolution(customfunction: CustomFunction, z: number): number[][] {\n\t\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1237](https://leetcode-cn.com/problems/find-positive-integer-solution-for-a-given-equation)", "[\u627e\u51fa\u7ed9\u5b9a\u65b9\u7a0b\u7684\u6b63\u6574\u6570\u89e3](/solution/1200-1299/1237.Find%20Positive%20Integer%20Solution%20for%20a%20Given%20Equation/README.md)", "`\u6570\u5b66`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1237](https://leetcode.com/problems/find-positive-integer-solution-for-a-given-equation)", "[Find Positive Integer Solution for a Given Equation](/solution/1200-1299/1237.Find%20Positive%20Integer%20Solution%20for%20a%20Given%20Equation/README_EN.md)", "`Math`,`Binary Search`", "Medium", ""]}, {"question_id": "1357", "frontend_question_id": "1225", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/report-contiguous-dates", "url_en": "https://leetcode.com/problems/report-contiguous-dates", "relative_path_cn": "/solution/1200-1299/1225.Report%20Contiguous%20Dates/README.md", "relative_path_en": "/solution/1200-1299/1225.Report%20Contiguous%20Dates/README_EN.md", "title_cn": "\u62a5\u544a\u7cfb\u7edf\u72b6\u6001\u7684\u8fde\u7eed\u65e5\u671f", "title_en": "Report Contiguous Dates", "question_title_slug": "report-contiguous-dates", "content_en": "

    Table: Failed

    \n\n
    \n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| fail_date    | date    |\n+--------------+---------+\nPrimary key for this table is fail_date.\nFailed table contains the days of failed tasks.\n
    \n\n

    Table: Succeeded

    \n\n
    \n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| success_date | date    |\n+--------------+---------+\nPrimary key for this table is success_date.\nSucceeded table contains the days of succeeded tasks.\n
    \n\n

     

    \n\n

    A system is running one task every day. Every task is independent of the previous tasks. The tasks can fail or succeed.

    \n\n

    Write an SQL query to generate a report of period_state for each continuous interval of days in the period from 2019-01-01 to 2019-12-31.

    \n\n

    period_state is 'failed' if tasks in this interval failed or 'succeeded' if tasks in this interval succeeded. Interval of days are retrieved as start_date and end_date.

    \n\n

    Order result by start_date.

    \n\n

    The query result format is in the following example:

    \n\n
    \nFailed table:\n+-------------------+\n| fail_date         |\n+-------------------+\n| 2018-12-28        |\n| 2018-12-29        |\n| 2019-01-04        |\n| 2019-01-05        |\n+-------------------+\n\nSucceeded table:\n+-------------------+\n| success_date      |\n+-------------------+\n| 2018-12-30        |\n| 2018-12-31        |\n| 2019-01-01        |\n| 2019-01-02        |\n| 2019-01-03        |\n| 2019-01-06        |\n+-------------------+\n\n\nResult table:\n+--------------+--------------+--------------+\n| period_state | start_date   | end_date     |\n+--------------+--------------+--------------+\n| succeeded    | 2019-01-01   | 2019-01-03   |\n| failed       | 2019-01-04   | 2019-01-05   |\n| succeeded    | 2019-01-06   | 2019-01-06   |\n+--------------+--------------+--------------+\n\nThe report ignored the system state in 2018 as we care about the system in the period 2019-01-01 to 2019-12-31.\nFrom 2019-01-01 to 2019-01-03 all tasks succeeded and the system state was "succeeded".\nFrom 2019-01-04 to 2019-01-05 all tasks failed and system state was "failed".\nFrom 2019-01-06 to 2019-01-06 all tasks succeeded and system state was "succeeded".\n
    \n", "content_cn": "

    Table: Failed

    \n\n
    +--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| fail_date    | date    |\n+--------------+---------+\n\u8be5\u8868\u4e3b\u952e\u4e3a fail_date\u3002\n\u8be5\u8868\u5305\u542b\u5931\u8d25\u4efb\u52a1\u7684\u5929\u6570.\n
    \n\n

    Table: Succeeded

    \n\n
    +--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| success_date | date    |\n+--------------+---------+\n\u8be5\u8868\u4e3b\u952e\u4e3a success_date\u3002\n\u8be5\u8868\u5305\u542b\u6210\u529f\u4efb\u52a1\u7684\u5929\u6570.\n
    \n\n

     

    \n\n

    \u7cfb\u7edf \u6bcf\u5929 \u8fd0\u884c\u4e00\u4e2a\u4efb\u52a1\u3002\u6bcf\u4e2a\u4efb\u52a1\u90fd\u72ec\u7acb\u4e8e\u5148\u524d\u7684\u4efb\u52a1\u3002\u4efb\u52a1\u7684\u72b6\u6001\u53ef\u4ee5\u662f\u5931\u8d25\u6216\u662f\u6210\u529f\u3002

    \n\n

    \u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2 2019-01-01 \u5230 2019-12-31 \u671f\u95f4\u4efb\u52a1\u8fde\u7eed\u540c\u72b6\u6001 period_state \u7684\u8d77\u6b62\u65e5\u671f\uff08start_date \u548c end_date\uff09\u3002\u5373\u5982\u679c\u4efb\u52a1\u5931\u8d25\u4e86\uff0c\u5c31\u662f\u5931\u8d25\u72b6\u6001\u7684\u8d77\u6b62\u65e5\u671f\uff0c\u5982\u679c\u4efb\u52a1\u6210\u529f\u4e86\uff0c\u5c31\u662f\u6210\u529f\u72b6\u6001\u7684\u8d77\u6b62\u65e5\u671f\u3002

    \n\n

    \u6700\u540e\u7ed3\u679c\u6309\u7167\u8d77\u59cb\u65e5\u671f start_date \u6392\u5e8f

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u6837\u4f8b\u5982\u4e0b\u6240\u793a:

    \n\n
    Failed table:\n+-------------------+\n| fail_date         |\n+-------------------+\n| 2018-12-28        |\n| 2018-12-29        |\n| 2019-01-04        |\n| 2019-01-05        |\n+-------------------+\n\nSucceeded table:\n+-------------------+\n| success_date      |\n+-------------------+\n| 2018-12-30        |\n| 2018-12-31        |\n| 2019-01-01        |\n| 2019-01-02        |\n| 2019-01-03        |\n| 2019-01-06        |\n+-------------------+\n\n\nResult table:\n+--------------+--------------+--------------+\n| period_state | start_date   | end_date     |\n+--------------+--------------+--------------+\n| succeeded    | 2019-01-01   | 2019-01-03   |\n| failed       | 2019-01-04   | 2019-01-05   |\n| succeeded    | 2019-01-06   | 2019-01-06   |\n+--------------+--------------+--------------+\n\n\u7ed3\u679c\u5ffd\u7565\u4e86 2018 \u5e74\u7684\u8bb0\u5f55\uff0c\u56e0\u4e3a\u6211\u4eec\u53ea\u5173\u5fc3\u4ece 2019-01-01 \u5230 2019-12-31 \u7684\u8bb0\u5f55\n\u4ece 2019-01-01 \u5230 2019-01-03 \u6240\u6709\u4efb\u52a1\u6210\u529f\uff0c\u7cfb\u7edf\u72b6\u6001\u4e3a "succeeded"\u3002\n\u4ece 2019-01-04 \u5230 2019-01-05 \u6240\u6709\u4efb\u52a1\u5931\u8d25\uff0c\u7cfb\u7edf\u72b6\u6001\u4e3a "failed"\u3002\n\u4ece 2019-01-06 \u5230 2019-01-06 \u6240\u6709\u4efb\u52a1\u6210\u529f\uff0c\u7cfb\u7edf\u72b6\u6001\u4e3a "succeeded"\u3002\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1225](https://leetcode-cn.com/problems/report-contiguous-dates)", "[\u62a5\u544a\u7cfb\u7edf\u72b6\u6001\u7684\u8fde\u7eed\u65e5\u671f](/solution/1200-1299/1225.Report%20Contiguous%20Dates/README.md)", "", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1225](https://leetcode.com/problems/report-contiguous-dates)", "[Report Contiguous Dates](/solution/1200-1299/1225.Report%20Contiguous%20Dates/README_EN.md)", "", "Hard", "\ud83d\udd12"]}, {"question_id": "1352", "frontend_question_id": "1235", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-profit-in-job-scheduling", "url_en": "https://leetcode.com/problems/maximum-profit-in-job-scheduling", "relative_path_cn": "/solution/1200-1299/1235.Maximum%20Profit%20in%20Job%20Scheduling/README.md", "relative_path_en": "/solution/1200-1299/1235.Maximum%20Profit%20in%20Job%20Scheduling/README_EN.md", "title_cn": "\u89c4\u5212\u517c\u804c\u5de5\u4f5c", "title_en": "Maximum Profit in Job Scheduling", "question_title_slug": "maximum-profit-in-job-scheduling", "content_en": "

    We have n jobs, where every job is scheduled to be done from startTime[i] to endTime[i], obtaining a profit of profit[i].

    \n\n

    You're given the startTime, endTime and profit arrays, return the maximum profit you can take such that there are no two jobs in the subset with overlapping time range.

    \n\n

    If you choose a job that ends at time X you will be able to start another job that starts at time X.

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: startTime = [1,2,3,3], endTime = [3,4,5,6], profit = [50,10,40,70]\nOutput: 120\nExplanation: The subset chosen is the first and fourth job. \nTime range [1-3]+[3-6] , we get profit of 120 = 50 + 70.\n
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: startTime = [1,2,3,4,6], endTime = [3,5,10,6,9], profit = [20,20,100,70,60]\nOutput: 150\nExplanation: The subset chosen is the first, fourth and fifth job. \nProfit obtained 150 = 20 + 70 + 60.\n
    \n\n

    Example 3:

    \n\n

    \"\"

    \n\n
    \nInput: startTime = [1,1,1], endTime = [2,3,4], profit = [5,6,4]\nOutput: 6\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= startTime.length == endTime.length == profit.length <= 5 * 104
    • \n\t
    • 1 <= startTime[i] < endTime[i] <= 109
    • \n\t
    • 1 <= profit[i] <= 104
    • \n
    \n", "content_cn": "

    \u4f60\u6253\u7b97\u5229\u7528\u7a7a\u95f2\u65f6\u95f4\u6765\u505a\u517c\u804c\u5de5\u4f5c\u8d5a\u4e9b\u96f6\u82b1\u94b1\u3002

    \n\n

    \u8fd9\u91cc\u6709 n \u4efd\u517c\u804c\u5de5\u4f5c\uff0c\u6bcf\u4efd\u5de5\u4f5c\u9884\u8ba1\u4ece startTime[i] \u5f00\u59cb\u5230 endTime[i] \u7ed3\u675f\uff0c\u62a5\u916c\u4e3a profit[i]\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4efd\u517c\u804c\u5de5\u4f5c\u8868\uff0c\u5305\u542b\u5f00\u59cb\u65f6\u95f4 startTime\uff0c\u7ed3\u675f\u65f6\u95f4 endTime \u548c\u9884\u8ba1\u62a5\u916c profit \u4e09\u4e2a\u6570\u7ec4\uff0c\u8bf7\u4f60\u8ba1\u7b97\u5e76\u8fd4\u56de\u53ef\u4ee5\u83b7\u5f97\u7684\u6700\u5927\u62a5\u916c\u3002

    \n\n

    \u6ce8\u610f\uff0c\u65f6\u95f4\u4e0a\u51fa\u73b0\u91cd\u53e0\u7684 2 \u4efd\u5de5\u4f5c\u4e0d\u80fd\u540c\u65f6\u8fdb\u884c\u3002

    \n\n

    \u5982\u679c\u4f60\u9009\u62e9\u7684\u5de5\u4f5c\u5728\u65f6\u95f4 X \u7ed3\u675f\uff0c\u90a3\u4e48\u4f60\u53ef\u4ee5\u7acb\u523b\u8fdb\u884c\u5728\u65f6\u95f4 X \u5f00\u59cb\u7684\u4e0b\u4e00\u4efd\u5de5\u4f5c\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1astartTime = [1,2,3,3], endTime = [3,4,5,6], profit = [50,10,40,70]\n\u8f93\u51fa\uff1a120\n\u89e3\u91ca\uff1a\n\u6211\u4eec\u9009\u51fa\u7b2c 1 \u4efd\u548c\u7b2c 4 \u4efd\u5de5\u4f5c\uff0c \n\u65f6\u95f4\u8303\u56f4\u662f [1-3]+[3-6]\uff0c\u5171\u83b7\u5f97\u62a5\u916c 120 = 50 + 70\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1astartTime = [1,2,3,4,6], endTime = [3,5,10,6,9], profit = [20,20,100,70,60]\n\u8f93\u51fa\uff1a150\n\u89e3\u91ca\uff1a\n\u6211\u4eec\u9009\u62e9\u7b2c 1\uff0c4\uff0c5 \u4efd\u5de5\u4f5c\u3002 \n\u5171\u83b7\u5f97\u62a5\u916c 150 = 20 + 70 + 60\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1astartTime = [1,1,1], endTime = [2,3,4], profit = [5,6,4]\n\u8f93\u51fa\uff1a6\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= startTime.length == endTime.length == profit.length <= 5 * 10^4
    • \n\t
    • 1 <= startTime[i] < endTime[i] <= 10^9
    • \n\t
    • 1 <= profit[i] <= 10^4
    • \n
    \n", "tags_en": ["Sort", "Binary Search", "Dynamic Programming"], "tags_cn": ["\u6392\u5e8f", "\u4e8c\u5206\u67e5\u627e", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int jobScheduling(vector& startTime, vector& endTime, vector& profit) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int jobScheduling(int[] startTime, int[] endTime, int[] profit) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def jobScheduling(self, startTime, endTime, profit):\n \"\"\"\n :type startTime: List[int]\n :type endTime: List[int]\n :type profit: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def jobScheduling(self, startTime: List[int], endTime: List[int], profit: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint jobScheduling(int* startTime, int startTimeSize, int* endTime, int endTimeSize, int* profit, int profitSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int JobScheduling(int[] startTime, int[] endTime, int[] profit) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} startTime\n * @param {number[]} endTime\n * @param {number[]} profit\n * @return {number}\n */\nvar jobScheduling = function(startTime, endTime, profit) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} start_time\n# @param {Integer[]} end_time\n# @param {Integer[]} profit\n# @return {Integer}\ndef job_scheduling(start_time, end_time, profit)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func jobScheduling(_ startTime: [Int], _ endTime: [Int], _ profit: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func jobScheduling(startTime []int, endTime []int, profit []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def jobScheduling(startTime: Array[Int], endTime: Array[Int], profit: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun jobScheduling(startTime: IntArray, endTime: IntArray, profit: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn job_scheduling(start_time: Vec, end_time: Vec, profit: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $startTime\n * @param Integer[] $endTime\n * @param Integer[] $profit\n * @return Integer\n */\n function jobScheduling($startTime, $endTime, $profit) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function jobScheduling(startTime: number[], endTime: number[], profit: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (job-scheduling startTime endTime profit)\n (-> (listof exact-integer?) (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1235](https://leetcode-cn.com/problems/maximum-profit-in-job-scheduling)", "[\u89c4\u5212\u517c\u804c\u5de5\u4f5c](/solution/1200-1299/1235.Maximum%20Profit%20in%20Job%20Scheduling/README.md)", "`\u6392\u5e8f`,`\u4e8c\u5206\u67e5\u627e`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1235](https://leetcode.com/problems/maximum-profit-in-job-scheduling)", "[Maximum Profit in Job Scheduling](/solution/1200-1299/1235.Maximum%20Profit%20in%20Job%20Scheduling/README_EN.md)", "`Sort`,`Binary Search`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "1351", "frontend_question_id": "1234", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/replace-the-substring-for-balanced-string", "url_en": "https://leetcode.com/problems/replace-the-substring-for-balanced-string", "relative_path_cn": "/solution/1200-1299/1234.Replace%20the%20Substring%20for%20Balanced%20String/README.md", "relative_path_en": "/solution/1200-1299/1234.Replace%20the%20Substring%20for%20Balanced%20String/README_EN.md", "title_cn": "\u66ff\u6362\u5b50\u4e32\u5f97\u5230\u5e73\u8861\u5b57\u7b26\u4e32", "title_en": "Replace the Substring for Balanced String", "question_title_slug": "replace-the-substring-for-balanced-string", "content_en": "

    You are given a string containing only 4 kinds of characters 'Q', 'W', 'E' and 'R'.

    \n\n

    A string is said to be balanced if each of its characters appears n/4 times where n is the length of the string.

    \n\n

    Return the minimum length of the substring that can be replaced with any other string of the same length to make the original string s balanced.

    \n\n

    Return 0 if the string is already balanced.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "QWER"\nOutput: 0\nExplanation: s is already balanced.
    \n\n

    Example 2:

    \n\n
    \nInput: s = "QQWE"\nOutput: 1\nExplanation: We need to replace a 'Q' to 'R', so that "RQWE" (or "QRWE") is balanced.\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "QQQW"\nOutput: 2\nExplanation: We can replace the first "QQ" to "ER". \n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "QQQQ"\nOutput: 3\nExplanation: We can replace the last 3 'Q' to make s = "QWER".\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 10^5
    • \n\t
    • s.length is a multiple of 4
    • \n\t
    • contains only 'Q', 'W', 'E' and 'R'.
    • \n
    \n", "content_cn": "

    \u6709\u4e00\u4e2a\u53ea\u542b\u6709 'Q', 'W', 'E', 'R' \u56db\u79cd\u5b57\u7b26\uff0c\u4e14\u957f\u5ea6\u4e3a n \u7684\u5b57\u7b26\u4e32\u3002

    \n\n

    \u5047\u5982\u5728\u8be5\u5b57\u7b26\u4e32\u4e2d\uff0c\u8fd9\u56db\u4e2a\u5b57\u7b26\u90fd\u6070\u597d\u51fa\u73b0 n/4 \u6b21\uff0c\u90a3\u4e48\u5b83\u5c31\u662f\u4e00\u4e2a\u300c\u5e73\u8861\u5b57\u7b26\u4e32\u300d\u3002

    \n\n

     

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u8fd9\u6837\u7684\u5b57\u7b26\u4e32 s\uff0c\u8bf7\u901a\u8fc7\u300c\u66ff\u6362\u4e00\u4e2a\u5b50\u4e32\u300d\u7684\u65b9\u5f0f\uff0c\u4f7f\u539f\u5b57\u7b26\u4e32 s \u53d8\u6210\u4e00\u4e2a\u300c\u5e73\u8861\u5b57\u7b26\u4e32\u300d\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u7528\u548c\u300c\u5f85\u66ff\u6362\u5b50\u4e32\u300d\u957f\u5ea6\u76f8\u540c\u7684 \u4efb\u4f55 \u5176\u4ed6\u5b57\u7b26\u4e32\u6765\u5b8c\u6210\u66ff\u6362\u3002

    \n\n

    \u8bf7\u8fd4\u56de\u5f85\u66ff\u6362\u5b50\u4e32\u7684\u6700\u5c0f\u53ef\u80fd\u957f\u5ea6\u3002

    \n\n

    \u5982\u679c\u539f\u5b57\u7b26\u4e32\u81ea\u8eab\u5c31\u662f\u4e00\u4e2a\u5e73\u8861\u5b57\u7b26\u4e32\uff0c\u5219\u8fd4\u56de 0\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1as = "QWER"\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1as \u5df2\u7ecf\u662f\u5e73\u8861\u7684\u4e86\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1as = "QQWE"\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u6211\u4eec\u9700\u8981\u628a\u4e00\u4e2a 'Q' \u66ff\u6362\u6210 'R'\uff0c\u8fd9\u6837\u5f97\u5230\u7684 "RQWE" (\u6216 "QRWE") \u662f\u5e73\u8861\u7684\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1as = "QQQW"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6211\u4eec\u53ef\u4ee5\u628a\u524d\u9762\u7684 "QQ" \u66ff\u6362\u6210 "ER"\u3002 \n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1as = "QQQQ"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6211\u4eec\u53ef\u4ee5\u66ff\u6362\u540e 3 \u4e2a 'Q'\uff0c\u4f7f s = "QWER"\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 10^5
    • \n\t
    • s.length \u662f 4 \u7684\u500d\u6570
    • \n\t
    • s \u4e2d\u53ea\u542b\u6709 'Q', 'W', 'E''R' \u56db\u79cd\u5b57\u7b26
    • \n
    \n", "tags_en": ["Two Pointers", "String"], "tags_cn": ["\u53cc\u6307\u9488", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int balancedString(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int balancedString(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def balancedString(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def balancedString(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint balancedString(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int BalancedString(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar balancedString = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef balanced_string(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func balancedString(_ s: String) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func balancedString(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def balancedString(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun balancedString(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn balanced_string(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function balancedString($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function balancedString(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (balanced-string s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1234](https://leetcode-cn.com/problems/replace-the-substring-for-balanced-string)", "[\u66ff\u6362\u5b50\u4e32\u5f97\u5230\u5e73\u8861\u5b57\u7b26\u4e32](/solution/1200-1299/1234.Replace%20the%20Substring%20for%20Balanced%20String/README.md)", "`\u53cc\u6307\u9488`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1234](https://leetcode.com/problems/replace-the-substring-for-balanced-string)", "[Replace the Substring for Balanced String](/solution/1200-1299/1234.Replace%20the%20Substring%20for%20Balanced%20String/README_EN.md)", "`Two Pointers`,`String`", "Medium", ""]}, {"question_id": "1350", "frontend_question_id": "1233", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/remove-sub-folders-from-the-filesystem", "url_en": "https://leetcode.com/problems/remove-sub-folders-from-the-filesystem", "relative_path_cn": "/solution/1200-1299/1233.Remove%20Sub-Folders%20from%20the%20Filesystem/README.md", "relative_path_en": "/solution/1200-1299/1233.Remove%20Sub-Folders%20from%20the%20Filesystem/README_EN.md", "title_cn": "\u5220\u9664\u5b50\u6587\u4ef6\u5939", "title_en": "Remove Sub-Folders from the Filesystem", "question_title_slug": "remove-sub-folders-from-the-filesystem", "content_en": "

    Given a list of folders, remove all sub-folders in those folders and return in any order the folders after removing.

    \n\n

    If a folder[i] is located within another folder[j], it is called a sub-folder of it.

    \n\n

    The format of a path is one or more concatenated strings of the form: / followed by one or more lowercase English letters. For example, /leetcode and /leetcode/problems are valid paths while an empty string and / are not.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: folder = ["/a","/a/b","/c/d","/c/d/e","/c/f"]\nOutput: ["/a","/c/d","/c/f"]\nExplanation: Folders "/a/b/" is a subfolder of "/a" and "/c/d/e" is inside of folder "/c/d" in our filesystem.\n
    \n\n

    Example 2:

    \n\n
    \nInput: folder = ["/a","/a/b/c","/a/b/d"]\nOutput: ["/a"]\nExplanation: Folders "/a/b/c" and "/a/b/d/" will be removed because they are subfolders of "/a".\n
    \n\n

    Example 3:

    \n\n
    \nInput: folder = ["/a/b/c","/a/b/ca","/a/b/d"]\nOutput: ["/a/b/c","/a/b/ca","/a/b/d"]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= folder.length <= 4 * 10^4
    • \n\t
    • 2 <= folder[i].length <= 100
    • \n\t
    • folder[i] contains only lowercase letters and '/'
    • \n\t
    • folder[i] always starts with character '/'
    • \n\t
    • Each folder name is unique.
    • \n
    \n", "content_cn": "

    \u4f60\u662f\u4e00\u4f4d\u7cfb\u7edf\u7ba1\u7406\u5458\uff0c\u624b\u91cc\u6709\u4e00\u4efd\u6587\u4ef6\u5939\u5217\u8868 folder\uff0c\u4f60\u7684\u4efb\u52a1\u662f\u8981\u5220\u9664\u8be5\u5217\u8868\u4e2d\u7684\u6240\u6709 \u5b50\u6587\u4ef6\u5939\uff0c\u5e76\u4ee5 \u4efb\u610f\u987a\u5e8f \u8fd4\u56de\u5269\u4e0b\u7684\u6587\u4ef6\u5939\u3002

    \n\n

    \u6211\u4eec\u8fd9\u6837\u5b9a\u4e49\u300c\u5b50\u6587\u4ef6\u5939\u300d\uff1a

    \n\n
      \n\t
    • \u5982\u679c\u6587\u4ef6\u5939 folder[i] \u4f4d\u4e8e\u53e6\u4e00\u4e2a\u6587\u4ef6\u5939 folder[j] \u4e0b\uff0c\u90a3\u4e48 folder[i] \u5c31\u662f folder[j] \u7684\u5b50\u6587\u4ef6\u5939\u3002
    • \n
    \n\n

    \u6587\u4ef6\u5939\u7684\u300c\u8def\u5f84\u300d\u662f\u7531\u4e00\u4e2a\u6216\u591a\u4e2a\u6309\u4ee5\u4e0b\u683c\u5f0f\u4e32\u8054\u5f62\u6210\u7684\u5b57\u7b26\u4e32\uff1a

    \n\n
      \n\t
    • / \u540e\u8ddf\u4e00\u4e2a\u6216\u8005\u591a\u4e2a\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    • \n
    \n\n

    \u4f8b\u5982\uff0c/leetcode \u548c /leetcode/problems \u90fd\u662f\u6709\u6548\u7684\u8def\u5f84\uff0c\u800c\u7a7a\u5b57\u7b26\u4e32\u548c / \u4e0d\u662f\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1afolder = ["/a","/a/b","/c/d","/c/d/e","/c/f"]\n\u8f93\u51fa\uff1a["/a","/c/d","/c/f"]\n\u89e3\u91ca\uff1a"/a/b/" \u662f "/a" \u7684\u5b50\u6587\u4ef6\u5939\uff0c\u800c "/c/d/e" \u662f "/c/d" \u7684\u5b50\u6587\u4ef6\u5939\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1afolder = ["/a","/a/b/c","/a/b/d"]\n\u8f93\u51fa\uff1a["/a"]\n\u89e3\u91ca\uff1a\u6587\u4ef6\u5939 "/a/b/c" \u548c "/a/b/d/" \u90fd\u4f1a\u88ab\u5220\u9664\uff0c\u56e0\u4e3a\u5b83\u4eec\u90fd\u662f "/a" \u7684\u5b50\u6587\u4ef6\u5939\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1afolder = ["/a/b/c","/a/b/d","/a/b/ca"]\n\u8f93\u51fa\uff1a["/a/b/c","/a/b/ca","/a/b/d"]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= folder.length <= 4 * 10^4
    • \n\t
    • 2 <= folder[i].length <= 100
    • \n\t
    • folder[i] \u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd\u548c /
    • \n\t
    • folder[i] \u603b\u662f\u4ee5\u5b57\u7b26 / \u8d77\u59cb
    • \n\t
    • \u6bcf\u4e2a\u6587\u4ef6\u5939\u540d\u90fd\u662f\u552f\u4e00\u7684
    • \n
    \n", "tags_en": ["Array", "String"], "tags_cn": ["\u6570\u7ec4", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector removeSubfolders(vector& folder) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List removeSubfolders(String[] folder) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def removeSubfolders(self, folder):\n \"\"\"\n :type folder: List[str]\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def removeSubfolders(self, folder: List[str]) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** removeSubfolders(char ** folder, int folderSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList RemoveSubfolders(string[] folder) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} folder\n * @return {string[]}\n */\nvar removeSubfolders = function(folder) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} folder\n# @return {String[]}\ndef remove_subfolders(folder)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func removeSubfolders(_ folder: [String]) -> [String] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func removeSubfolders(folder []string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def removeSubfolders(folder: Array[String]): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun removeSubfolders(folder: Array): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn remove_subfolders(folder: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $folder\n * @return String[]\n */\n function removeSubfolders($folder) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function removeSubfolders(folder: string[]): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (remove-subfolders folder)\n (-> (listof string?) (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1233](https://leetcode-cn.com/problems/remove-sub-folders-from-the-filesystem)", "[\u5220\u9664\u5b50\u6587\u4ef6\u5939](/solution/1200-1299/1233.Remove%20Sub-Folders%20from%20the%20Filesystem/README.md)", "`\u6570\u7ec4`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1233](https://leetcode.com/problems/remove-sub-folders-from-the-filesystem)", "[Remove Sub-Folders from the Filesystem](/solution/1200-1299/1233.Remove%20Sub-Folders%20from%20the%20Filesystem/README_EN.md)", "`Array`,`String`", "Medium", ""]}, {"question_id": "1349", "frontend_question_id": "1232", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/check-if-it-is-a-straight-line", "url_en": "https://leetcode.com/problems/check-if-it-is-a-straight-line", "relative_path_cn": "/solution/1200-1299/1232.Check%20If%20It%20Is%20a%20Straight%20Line/README.md", "relative_path_en": "/solution/1200-1299/1232.Check%20If%20It%20Is%20a%20Straight%20Line/README_EN.md", "title_cn": "\u7f00\u70b9\u6210\u7ebf", "title_en": "Check If It Is a Straight Line", "question_title_slug": "check-if-it-is-a-straight-line", "content_en": "

    You are given an array coordinates, coordinates[i] = [x, y], where [x, y] represents the coordinate of a point. Check if these points make a straight line in the XY plane.

    \r\n\r\n

     

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n

    \"\"

    \r\n\r\n
    \r\nInput: coordinates = [[1,2],[2,3],[3,4],[4,5],[5,6],[6,7]]\r\nOutput: true\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n

    \"\"

    \r\n\r\n
    \r\nInput: coordinates = [[1,1],[2,2],[3,4],[4,5],[5,6],[7,7]]\r\nOutput: false\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 2 <= coordinates.length <= 1000
    • \r\n\t
    • coordinates[i].length == 2
    • \r\n\t
    • -10^4 <= coordinates[i][0], coordinates[i][1] <= 10^4
    • \r\n\t
    • coordinates contains no duplicate point.
    • \r\n
    ", "content_cn": "

    \u5728\u4e00\u4e2a XY \u5750\u6807\u7cfb\u4e2d\u6709\u4e00\u4e9b\u70b9\uff0c\u6211\u4eec\u7528\u6570\u7ec4 coordinates \u6765\u5206\u522b\u8bb0\u5f55\u5b83\u4eec\u7684\u5750\u6807\uff0c\u5176\u4e2d coordinates[i] = [x, y] \u8868\u793a\u6a2a\u5750\u6807\u4e3a x\u3001\u7eb5\u5750\u6807\u4e3a y \u7684\u70b9\u3002

    \n\n

    \u8bf7\u4f60\u6765\u5224\u65ad\uff0c\u8fd9\u4e9b\u70b9\u662f\u5426\u5728\u8be5\u5750\u6807\u7cfb\u4e2d\u5c5e\u4e8e\u540c\u4e00\u6761\u76f4\u7ebf\u4e0a\uff0c\u662f\u5219\u8fd4\u56de true\uff0c\u5426\u5219\u8bf7\u8fd4\u56de false\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1acoordinates = [[1,2],[2,3],[3,4],[4,5],[5,6],[6,7]]\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1acoordinates = [[1,1],[2,2],[3,4],[4,5],[5,6],[7,7]]\n\u8f93\u51fa\uff1afalse\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= coordinates.length <= 1000
    • \n\t
    • coordinates[i].length == 2
    • \n\t
    • -10^4 <= coordinates[i][0], coordinates[i][1] <= 10^4
    • \n\t
    • coordinates \u4e2d\u4e0d\u542b\u91cd\u590d\u7684\u70b9
    • \n
    \n", "tags_en": ["Geometry", "Array", "Math"], "tags_cn": ["\u51e0\u4f55", "\u6570\u7ec4", "\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool checkStraightLine(vector>& coordinates) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean checkStraightLine(int[][] coordinates) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def checkStraightLine(self, coordinates):\n \"\"\"\n :type coordinates: List[List[int]]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def checkStraightLine(self, coordinates: List[List[int]]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "bool checkStraightLine(int** coordinates, int coordinatesSize, int* coordinatesColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CheckStraightLine(int[][] coordinates) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} coordinates\n * @return {boolean}\n */\nvar checkStraightLine = function(coordinates) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} coordinates\n# @return {Boolean}\ndef check_straight_line(coordinates)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func checkStraightLine(_ coordinates: [[Int]]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func checkStraightLine(coordinates [][]int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def checkStraightLine(coordinates: Array[Array[Int]]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun checkStraightLine(coordinates: Array): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn check_straight_line(coordinates: Vec>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $coordinates\n * @return Boolean\n */\n function checkStraightLine($coordinates) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function checkStraightLine(coordinates: number[][]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (check-straight-line coordinates)\n (-> (listof (listof exact-integer?)) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1232](https://leetcode-cn.com/problems/check-if-it-is-a-straight-line)", "[\u7f00\u70b9\u6210\u7ebf](/solution/1200-1299/1232.Check%20If%20It%20Is%20a%20Straight%20Line/README.md)", "`\u51e0\u4f55`,`\u6570\u7ec4`,`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[1232](https://leetcode.com/problems/check-if-it-is-a-straight-line)", "[Check If It Is a Straight Line](/solution/1200-1299/1232.Check%20If%20It%20Is%20a%20Straight%20Line/README_EN.md)", "`Geometry`,`Array`,`Math`", "Easy", ""]}, {"question_id": "1345", "frontend_question_id": "1427", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/perform-string-shifts", "url_en": "https://leetcode.com/problems/perform-string-shifts", "relative_path_cn": "/solution/1400-1499/1427.Perform%20String%20Shifts/README.md", "relative_path_en": "/solution/1400-1499/1427.Perform%20String%20Shifts/README_EN.md", "title_cn": "\u5b57\u7b26\u4e32\u7684\u5de6\u53f3\u79fb", "title_en": "Perform String Shifts", "question_title_slug": "perform-string-shifts", "content_en": "

    You are given a string s containing lowercase English letters, and a matrix shift, where shift[i] = [directioni, amounti]:

    \n\n
      \n\t
    • directioni can be 0 (for left shift) or 1 (for right shift).
    • \n\t
    • amounti is the amount by which string s is to be shifted.
    • \n\t
    • A left shift by 1 means remove the first character of s and append it to the end.
    • \n\t
    • Similarly, a right shift by 1 means remove the last character of s and add it to the beginning.
    • \n
    \n\n

    Return the final string after all operations.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "abc", shift = [[0,1],[1,2]]\nOutput: "cab"\nExplanation: \n[0,1] means shift to left by 1. "abc" -> "bca"\n[1,2] means shift to right by 2. "bca" -> "cab"
    \n\n

    Example 2:

    \n\n
    \nInput: s = "abcdefg", shift = [[1,1],[1,1],[0,2],[1,3]]\nOutput: "efgabcd"\nExplanation:  \n[1,1] means shift to right by 1. "abcdefg" -> "gabcdef"\n[1,1] means shift to right by 1. "gabcdef" -> "fgabcde"\n[0,2] means shift to left by 2. "fgabcde" -> "abcdefg"\n[1,3] means shift to right by 3. "abcdefg" -> "efgabcd"
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 100
    • \n\t
    • s only contains lower case English letters.
    • \n\t
    • 1 <= shift.length <= 100
    • \n\t
    • shift[i].length == 2
    • \n\t
    • directioni is either 0 or 1.
    • \n\t
    • 0 <= amounti <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7684\u5b57\u7b26\u4e32 s \u4ee5\u53ca\u4e00\u4e2a\u77e9\u9635 shift\uff0c\u5176\u4e2d shift[i] = [direction, amount]\uff1a

    \n\n
      \n\t
    • direction \u53ef\u4ee5\u4e3a 0 \uff08\u8868\u793a\u5de6\u79fb\uff09\u6216 1 \uff08\u8868\u793a\u53f3\u79fb\uff09\u3002
    • \n\t
    • amount \u8868\u793a s \u5de6\u53f3\u79fb\u7684\u4f4d\u6570\u3002
    • \n\t
    • \u5de6\u79fb 1 \u4f4d\u8868\u793a\u79fb\u9664 s \u7684\u7b2c\u4e00\u4e2a\u5b57\u7b26\uff0c\u5e76\u5c06\u8be5\u5b57\u7b26\u63d2\u5165\u5230 s \u7684\u7ed3\u5c3e\u3002
    • \n\t
    • \u7c7b\u4f3c\u5730\uff0c\u53f3\u79fb 1 \u4f4d\u8868\u793a\u79fb\u9664 s \u7684\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\uff0c\u5e76\u5c06\u8be5\u5b57\u7b26\u63d2\u5165\u5230 s \u7684\u5f00\u5934\u3002
    • \n
    \n\n

    \u5bf9\u8fd9\u4e2a\u5b57\u7b26\u4e32\u8fdb\u884c\u6240\u6709\u64cd\u4f5c\u540e\uff0c\u8fd4\u56de\u6700\u7ec8\u7ed3\u679c\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = "abc", shift = [[0,1],[1,2]]\n\u8f93\u51fa\uff1a"cab"\n\u89e3\u91ca\uff1a\n[0,1] \u8868\u793a\u5de6\u79fb 1 \u4f4d\u3002 "abc" -> "bca"\n[1,2] \u8868\u793a\u53f3\u79fb 2 \u4f4d\u3002 "bca" -> "cab"
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = "abcdefg", shift = [[1,1],[1,1],[0,2],[1,3]]\n\u8f93\u51fa\uff1a"efgabcd"\n\u89e3\u91ca\uff1a \n[1,1] \u8868\u793a\u53f3\u79fb 1 \u4f4d\u3002 "abcdefg" -> "gabcdef"\n[1,1] \u8868\u793a\u53f3\u79fb 1 \u4f4d\u3002 "gabcdef" -> "fgabcde"\n[0,2] \u8868\u793a\u5de6\u79fb 2 \u4f4d\u3002 "fgabcde" -> "abcdefg"\n[1,3] \u8868\u793a\u53f3\u79fb 3 \u4f4d\u3002 "abcdefg" -> "efgabcd"
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 100
    • \n\t
    • s \u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd
    • \n\t
    • 1 <= shift.length <= 100
    • \n\t
    • shift[i].length == 2
    • \n\t
    • 0 <= shift[i][0] <= 1
    • \n\t
    • 0 <= shift[i][1] <= 100
    • \n
    \n", "tags_en": ["Array", "Math"], "tags_cn": ["\u6570\u7ec4", "\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string stringShift(string s, vector>& shift) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String stringShift(String s, int[][] shift) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def stringShift(self, s, shift):\n \"\"\"\n :type s: str\n :type shift: List[List[int]]\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def stringShift(self, s: str, shift: List[List[int]]) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * stringShift(char * s, int** shift, int shiftSize, int* shiftColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string StringShift(string s, int[][] shift) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number[][]} shift\n * @return {string}\n */\nvar stringShift = function(s, shift) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer[][]} shift\n# @return {String}\ndef string_shift(s, shift)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func stringShift(_ s: String, _ shift: [[Int]]) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func stringShift(s string, shift [][]int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def stringShift(s: String, shift: Array[Array[Int]]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun stringShift(s: String, shift: Array): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn string_shift(s: String, shift: Vec>) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer[][] $shift\n * @return String\n */\n function stringShift($s, $shift) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function stringShift(s: string, shift: number[][]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (string-shift s shift)\n (-> string? (listof (listof exact-integer?)) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1427](https://leetcode-cn.com/problems/perform-string-shifts)", "[\u5b57\u7b26\u4e32\u7684\u5de6\u53f3\u79fb](/solution/1400-1499/1427.Perform%20String%20Shifts/README.md)", "`\u6570\u7ec4`,`\u6570\u5b66`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1427](https://leetcode.com/problems/perform-string-shifts)", "[Perform String Shifts](/solution/1400-1499/1427.Perform%20String%20Shifts/README_EN.md)", "`Array`,`Math`", "Easy", "\ud83d\udd12"]}, {"question_id": "1344", "frontend_question_id": "1224", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-equal-frequency", "url_en": "https://leetcode.com/problems/maximum-equal-frequency", "relative_path_cn": "/solution/1200-1299/1224.Maximum%20Equal%20Frequency/README.md", "relative_path_en": "/solution/1200-1299/1224.Maximum%20Equal%20Frequency/README_EN.md", "title_cn": "\u6700\u5927\u76f8\u7b49\u9891\u7387", "title_en": "Maximum Equal Frequency", "question_title_slug": "maximum-equal-frequency", "content_en": "

    Given an array nums of positive integers, return the longest possible length of an array prefix of nums, such that it is possible to remove exactly one element from this prefix so that every number that has appeared in it will have the same number of occurrences.

    \n\n

    If after removing one element there are no remaining elements, it's still considered that every appeared number has the same number of ocurrences (0).

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [2,2,1,1,5,3,3,5]\nOutput: 7\nExplanation: For the subarray [2,2,1,1,5,3,3] of length 7, if we remove nums[4]=5, we will get [2,2,1,1,3,3], so that each number will appear exactly twice.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,1,1,2,2,2,3,3,3,4,4,4,5]\nOutput: 13\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [1,1,1,2,2,2]\nOutput: 5\n
    \n\n

    Example 4:

    \n\n
    \nInput: nums = [10,2,8,9,3,8,1,5,2,3,7,6]\nOutput: 8\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= nums.length <= 10^5
    • \n\t
    • 1 <= nums[i] <= 10^5
    • \n
    \n", "content_cn": "

    \u7ed9\u51fa\u4e00\u4e2a\u6b63\u6574\u6570\u6570\u7ec4 nums\uff0c\u8bf7\u4f60\u5e2e\u5fd9\u4ece\u8be5\u6570\u7ec4\u4e2d\u627e\u51fa\u80fd\u6ee1\u8db3\u4e0b\u9762\u8981\u6c42\u7684 \u6700\u957f \u524d\u7f00\uff0c\u5e76\u8fd4\u56de\u5176\u957f\u5ea6\uff1a

    \n\n
      \n\t
    • \u4ece\u524d\u7f00\u4e2d \u5220\u9664\u4e00\u4e2a \u5143\u7d20\u540e\uff0c\u4f7f\u5f97\u6240\u5269\u4e0b\u7684\u6bcf\u4e2a\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\u76f8\u540c\u3002
    • \n
    \n\n

    \u5982\u679c\u5220\u9664\u8fd9\u4e2a\u5143\u7d20\u540e\u6ca1\u6709\u5269\u4f59\u5143\u7d20\u5b58\u5728\uff0c\u4ecd\u53ef\u8ba4\u4e3a\u6bcf\u4e2a\u6570\u5b57\u90fd\u5177\u6709\u76f8\u540c\u7684\u51fa\u73b0\u6b21\u6570\uff08\u4e5f\u5c31\u662f 0 \u6b21\uff09\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [2,2,1,1,5,3,3,5]\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\u5bf9\u4e8e\u957f\u5ea6\u4e3a 7 \u7684\u5b50\u6570\u7ec4 [2,2,1,1,5,3,3]\uff0c\u5982\u679c\u6211\u4eec\u4ece\u4e2d\u5220\u53bb nums[4]=5\uff0c\u5c31\u53ef\u4ee5\u5f97\u5230 [2,2,1,1,3,3]\uff0c\u91cc\u9762\u6bcf\u4e2a\u6570\u5b57\u90fd\u51fa\u73b0\u4e86\u4e24\u6b21\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,1,1,2,2,2,3,3,3,4,4,4,5]\n\u8f93\u51fa\uff1a13\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,1,1,2,2,2]\n\u8f93\u51fa\uff1a5\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [10,2,8,9,3,8,1,5,2,3,7,6]\n\u8f93\u51fa\uff1a8\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= nums.length <= 10^5
    • \n\t
    • 1 <= nums[i] <= 10^5
    • \n
    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxEqualFreq(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxEqualFreq(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxEqualFreq(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxEqualFreq(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxEqualFreq(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxEqualFreq(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar maxEqualFreq = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef max_equal_freq(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxEqualFreq(_ nums: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxEqualFreq(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxEqualFreq(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxEqualFreq(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_equal_freq(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function maxEqualFreq($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxEqualFreq(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-equal-freq nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1224](https://leetcode-cn.com/problems/maximum-equal-frequency)", "[\u6700\u5927\u76f8\u7b49\u9891\u7387](/solution/1200-1299/1224.Maximum%20Equal%20Frequency/README.md)", "`\u54c8\u5e0c\u8868`", "\u56f0\u96be", ""], "md_table_row_en": ["[1224](https://leetcode.com/problems/maximum-equal-frequency)", "[Maximum Equal Frequency](/solution/1200-1299/1224.Maximum%20Equal%20Frequency/README_EN.md)", "`Hash Table`", "Hard", ""]}, {"question_id": "1343", "frontend_question_id": "1223", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/dice-roll-simulation", "url_en": "https://leetcode.com/problems/dice-roll-simulation", "relative_path_cn": "/solution/1200-1299/1223.Dice%20Roll%20Simulation/README.md", "relative_path_en": "/solution/1200-1299/1223.Dice%20Roll%20Simulation/README_EN.md", "title_cn": "\u63b7\u9ab0\u5b50\u6a21\u62df", "title_en": "Dice Roll Simulation", "question_title_slug": "dice-roll-simulation", "content_en": "

    A die simulator generates a random number from 1 to 6 for each roll. You introduced a constraint to the generator such that it cannot roll the number i more than rollMax[i] (1-indexed) consecutive times. 

    \n\n

    Given an array of integers rollMax and an integer n, return the number of distinct sequences that can be obtained with exact n rolls.

    \n\n

    Two sequences are considered different if at least one element differs from each other. Since the answer may be too large, return it modulo 10^9 + 7.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 2, rollMax = [1,1,2,2,2,3]\nOutput: 34\nExplanation: There will be 2 rolls of die, if there are no constraints on the die, there are 6 * 6 = 36 possible combinations. In this case, looking at rollMax array, the numbers 1 and 2 appear at most once consecutively, therefore sequences (1,1) and (2,2) cannot occur, so the final answer is 36-2 = 34.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 2, rollMax = [1,1,1,1,1,1]\nOutput: 30\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 3, rollMax = [1,1,1,2,2,3]\nOutput: 181\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 5000
    • \n\t
    • rollMax.length == 6
    • \n\t
    • 1 <= rollMax[i] <= 15
    • \n
    \n", "content_cn": "

    \u6709\u4e00\u4e2a\u9ab0\u5b50\u6a21\u62df\u5668\u4f1a\u6bcf\u6b21\u6295\u63b7\u7684\u65f6\u5019\u751f\u6210\u4e00\u4e2a 1 \u5230 6 \u7684\u968f\u673a\u6570\u3002

    \n\n

    \u4e0d\u8fc7\u6211\u4eec\u5728\u4f7f\u7528\u5b83\u65f6\u6709\u4e2a\u7ea6\u675f\uff0c\u5c31\u662f\u4f7f\u5f97\u6295\u63b7\u9ab0\u5b50\u65f6\uff0c\u8fde\u7eed \u63b7\u51fa\u6570\u5b57 i \u7684\u6b21\u6570\u4e0d\u80fd\u8d85\u8fc7 rollMax[i]\uff08i \u4ece 1 \u5f00\u59cb\u7f16\u53f7\uff09\u3002

    \n\n

    \u73b0\u5728\uff0c\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 rollMax \u548c\u4e00\u4e2a\u6574\u6570 n\uff0c\u8bf7\u4f60\u6765\u8ba1\u7b97\u63b7 n \u6b21\u9ab0\u5b50\u53ef\u5f97\u5230\u7684\u4e0d\u540c\u70b9\u6570\u5e8f\u5217\u7684\u6570\u91cf\u3002

    \n\n

    \u5047\u5982\u4e24\u4e2a\u5e8f\u5217\u4e2d\u81f3\u5c11\u5b58\u5728\u4e00\u4e2a\u5143\u7d20\u4e0d\u540c\uff0c\u5c31\u8ba4\u4e3a\u8fd9\u4e24\u4e2a\u5e8f\u5217\u662f\u4e0d\u540c\u7684\u3002\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u5f88\u5927\uff0c\u6240\u4ee5\u8bf7\u8fd4\u56de \u6a21 10^9 + 7 \u4e4b\u540e\u7684\u7ed3\u679c\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1an = 2, rollMax = [1,1,2,2,2,3]\n\u8f93\u51fa\uff1a34\n\u89e3\u91ca\uff1a\u6211\u4eec\u63b7 2 \u6b21\u9ab0\u5b50\uff0c\u5982\u679c\u6ca1\u6709\u7ea6\u675f\u7684\u8bdd\uff0c\u5171\u6709 6 * 6 = 36 \u79cd\u53ef\u80fd\u7684\u7ec4\u5408\u3002\u4f46\u662f\u6839\u636e rollMax \u6570\u7ec4\uff0c\u6570\u5b57 1 \u548c 2 \u6700\u591a\u8fde\u7eed\u51fa\u73b0\u4e00\u6b21\uff0c\u6240\u4ee5\u4e0d\u4f1a\u51fa\u73b0\u5e8f\u5217 (1,1) \u548c (2,2)\u3002\u56e0\u6b64\uff0c\u6700\u7ec8\u7b54\u6848\u662f 36-2 = 34\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1an = 2, rollMax = [1,1,1,1,1,1]\n\u8f93\u51fa\uff1a30\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1an = 3, rollMax = [1,1,1,2,2,3]\n\u8f93\u51fa\uff1a181\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 5000
    • \n\t
    • rollMax.length == 6
    • \n\t
    • 1 <= rollMax[i] <= 15
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int dieSimulator(int n, vector& rollMax) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int dieSimulator(int n, int[] rollMax) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def dieSimulator(self, n, rollMax):\n \"\"\"\n :type n: int\n :type rollMax: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def dieSimulator(self, n: int, rollMax: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint dieSimulator(int n, int* rollMax, int rollMaxSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int DieSimulator(int n, int[] rollMax) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[]} rollMax\n * @return {number}\n */\nvar dieSimulator = function(n, rollMax) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[]} roll_max\n# @return {Integer}\ndef die_simulator(n, roll_max)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func dieSimulator(_ n: Int, _ rollMax: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func dieSimulator(n int, rollMax []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def dieSimulator(n: Int, rollMax: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun dieSimulator(n: Int, rollMax: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn die_simulator(n: i32, roll_max: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[] $rollMax\n * @return Integer\n */\n function dieSimulator($n, $rollMax) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function dieSimulator(n: number, rollMax: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (die-simulator n rollMax)\n (-> exact-integer? (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1223](https://leetcode-cn.com/problems/dice-roll-simulation)", "[\u63b7\u9ab0\u5b50\u6a21\u62df](/solution/1200-1299/1223.Dice%20Roll%20Simulation/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1223](https://leetcode.com/problems/dice-roll-simulation)", "[Dice Roll Simulation](/solution/1200-1299/1223.Dice%20Roll%20Simulation/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "1342", "frontend_question_id": "1222", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/queens-that-can-attack-the-king", "url_en": "https://leetcode.com/problems/queens-that-can-attack-the-king", "relative_path_cn": "/solution/1200-1299/1222.Queens%20That%20Can%20Attack%20the%20King/README.md", "relative_path_en": "/solution/1200-1299/1222.Queens%20That%20Can%20Attack%20the%20King/README_EN.md", "title_cn": "\u53ef\u4ee5\u653b\u51fb\u56fd\u738b\u7684\u7687\u540e", "title_en": "Queens That Can Attack the King", "question_title_slug": "queens-that-can-attack-the-king", "content_en": "

    On an 8x8 chessboard, there can be multiple Black Queens and one White King.

    \r\n\r\n

    Given an array of integer coordinates queens that represents the positions of the Black Queens, and a pair of coordinates king that represent the position of the White King, return the coordinates of all the queens (in any order) that can attack the King.

    \n

     

    \n

    Example 1:

    \r\n\r\n

    \"\"

    \r\n\r\n
    \r\nInput: queens = [[0,1],[1,0],[4,0],[0,4],[3,3],[2,4]], king = [0,0]\r\nOutput: [[0,1],[1,0],[3,3]]\r\nExplanation:  \r\nThe queen at [0,1] can attack the king cause they're in the same row. \r\nThe queen at [1,0] can attack the king cause they're in the same column. \r\nThe queen at [3,3] can attack the king cause they're in the same diagnal. \r\nThe queen at [0,4] can't attack the king cause it's blocked by the queen at [0,1]. \r\nThe queen at [4,0] can't attack the king cause it's blocked by the queen at [1,0]. \r\nThe queen at [2,4] can't attack the king cause it's not in the same row/column/diagnal as the king.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n

    \"\"

    \r\n\r\n
    \r\nInput: queens = [[0,0],[1,1],[2,2],[3,4],[3,5],[4,4],[4,5]], king = [3,3]\r\nOutput: [[2,2],[3,4],[4,4]]\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n

    \"\"

    \r\n\r\n
    \r\nInput: queens = [[5,6],[7,7],[2,1],[0,7],[1,6],[5,1],[3,7],[0,3],[4,0],[1,2],[6,3],[5,0],[0,4],[2,2],[1,1],[6,4],[5,4],[0,0],[2,6],[4,5],[5,2],[1,4],[7,5],[2,3],[0,5],[4,2],[1,0],[2,7],[0,1],[4,6],[6,1],[0,6],[4,3],[1,7]], king = [3,4]\r\nOutput: [[2,3],[1,4],[1,6],[3,7],[4,3],[5,4],[4,5]]\r\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= queens.length <= 63
    • \n\t
    • queens[i].length == 2
    • \n\t
    • 0 <= queens[i][j] < 8
    • \n\t
    • king.length == 2
    • \n\t
    • 0 <= king[0], king[1] < 8
    • \n\t
    • At most one piece is allowed in a cell.
    • \n
    \n", "content_cn": "

    \u5728\u4e00\u4e2a\u00a08x8\u00a0\u7684\u68cb\u76d8\u4e0a\uff0c\u653e\u7f6e\u7740\u82e5\u5e72\u300c\u9ed1\u7687\u540e\u300d\u548c\u4e00\u4e2a\u300c\u767d\u56fd\u738b\u300d\u3002

    \n\n

    \u300c\u9ed1\u7687\u540e\u300d\u5728\u68cb\u76d8\u4e0a\u7684\u4f4d\u7f6e\u5206\u5e03\u7528\u6574\u6570\u5750\u6807\u6570\u7ec4\u00a0queens\u00a0\u8868\u793a\uff0c\u300c\u767d\u56fd\u738b\u300d\u7684\u5750\u6807\u7528\u6570\u7ec4 king \u8868\u793a\u3002

    \n\n

    \u300c\u9ed1\u7687\u540e\u300d\u7684\u884c\u68cb\u89c4\u5b9a\u662f\uff1a\u6a2a\u3001\u76f4\u3001\u659c\u90fd\u53ef\u4ee5\u8d70\uff0c\u6b65\u6570\u4e0d\u53d7\u9650\u5236\uff0c\u4f46\u662f\uff0c\u4e0d\u80fd\u8d8a\u5b50\u884c\u68cb\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u53ef\u4ee5\u76f4\u63a5\u653b\u51fb\u5230\u300c\u767d\u56fd\u738b\u300d\u7684\u6240\u6709\u300c\u9ed1\u7687\u540e\u300d\u7684\u5750\u6807\uff08\u4efb\u610f\u987a\u5e8f\uff09\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aqueens = [[0,1],[1,0],[4,0],[0,4],[3,3],[2,4]], king = [0,0]\n\u8f93\u51fa\uff1a[[0,1],[1,0],[3,3]]\n\u89e3\u91ca\uff1a \n[0,1] \u7684\u7687\u540e\u53ef\u4ee5\u653b\u51fb\u5230\u56fd\u738b\uff0c\u56e0\u4e3a\u4ed6\u4eec\u5728\u540c\u4e00\u884c\u4e0a\u3002 \n[1,0] \u7684\u7687\u540e\u53ef\u4ee5\u653b\u51fb\u5230\u56fd\u738b\uff0c\u56e0\u4e3a\u4ed6\u4eec\u5728\u540c\u4e00\u5217\u4e0a\u3002 \n[3,3] \u7684\u7687\u540e\u53ef\u4ee5\u653b\u51fb\u5230\u56fd\u738b\uff0c\u56e0\u4e3a\u4ed6\u4eec\u5728\u540c\u4e00\u6761\u5bf9\u89d2\u7ebf\u4e0a\u3002 \n[0,4] \u7684\u7687\u540e\u65e0\u6cd5\u653b\u51fb\u5230\u56fd\u738b\uff0c\u56e0\u4e3a\u5979\u88ab\u4f4d\u4e8e [0,1] \u7684\u7687\u540e\u6321\u4f4f\u4e86\u3002 \n[4,0] \u7684\u7687\u540e\u65e0\u6cd5\u653b\u51fb\u5230\u56fd\u738b\uff0c\u56e0\u4e3a\u5979\u88ab\u4f4d\u4e8e [1,0] \u7684\u7687\u540e\u6321\u4f4f\u4e86\u3002 \n[2,4] \u7684\u7687\u540e\u65e0\u6cd5\u653b\u51fb\u5230\u56fd\u738b\uff0c\u56e0\u4e3a\u5979\u548c\u56fd\u738b\u4e0d\u5728\u540c\u4e00\u884c/\u5217/\u5bf9\u89d2\u7ebf\u4e0a\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aqueens = [[0,0],[1,1],[2,2],[3,4],[3,5],[4,4],[4,5]], king = [3,3]\n\u8f93\u51fa\uff1a[[2,2],[3,4],[4,4]]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aqueens = [[5,6],[7,7],[2,1],[0,7],[1,6],[5,1],[3,7],[0,3],[4,0],[1,2],[6,3],[5,0],[0,4],[2,2],[1,1],[6,4],[5,4],[0,0],[2,6],[4,5],[5,2],[1,4],[7,5],[2,3],[0,5],[4,2],[1,0],[2,7],[0,1],[4,6],[6,1],[0,6],[4,3],[1,7]], king = [3,4]\n\u8f93\u51fa\uff1a[[2,3],[1,4],[1,6],[3,7],[4,3],[5,4],[4,5]]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= queens.length\u00a0<= 63
    • \n\t
    • queens[i].length == 2
    • \n\t
    • 0 <= queens[i][j] <\u00a08
    • \n\t
    • king.length == 2
    • \n\t
    • 0 <= king[0], king[1] < 8
    • \n\t
    • \u4e00\u4e2a\u68cb\u76d8\u683c\u4e0a\u6700\u591a\u53ea\u80fd\u653e\u7f6e\u4e00\u679a\u68cb\u5b50\u3002
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> queensAttacktheKing(vector>& queens, vector& king) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> queensAttacktheKing(int[][] queens, int[] king) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def queensAttacktheKing(self, queens, king):\n \"\"\"\n :type queens: List[List[int]]\n :type king: List[int]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def queensAttacktheKing(self, queens: List[List[int]], king: List[int]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** queensAttacktheKing(int** queens, int queensSize, int* queensColSize, int* king, int kingSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> QueensAttacktheKing(int[][] queens, int[] king) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} queens\n * @param {number[]} king\n * @return {number[][]}\n */\nvar queensAttacktheKing = function(queens, king) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} queens\n# @param {Integer[]} king\n# @return {Integer[][]}\ndef queens_attackthe_king(queens, king)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func queensAttacktheKing(_ queens: [[Int]], _ king: [Int]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func queensAttacktheKing(queens [][]int, king []int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def queensAttacktheKing(queens: Array[Array[Int]], king: Array[Int]): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun queensAttacktheKing(queens: Array, king: IntArray): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn queens_attackthe_king(queens: Vec>, king: Vec) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $queens\n * @param Integer[] $king\n * @return Integer[][]\n */\n function queensAttacktheKing($queens, $king) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function queensAttacktheKing(queens: number[][], king: number[]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (queens-attackthe-king queens king)\n (-> (listof (listof exact-integer?)) (listof exact-integer?) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1222](https://leetcode-cn.com/problems/queens-that-can-attack-the-king)", "[\u53ef\u4ee5\u653b\u51fb\u56fd\u738b\u7684\u7687\u540e](/solution/1200-1299/1222.Queens%20That%20Can%20Attack%20the%20King/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1222](https://leetcode.com/problems/queens-that-can-attack-the-king)", "[Queens That Can Attack the King](/solution/1200-1299/1222.Queens%20That%20Can%20Attack%20the%20King/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "1341", "frontend_question_id": "1221", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/split-a-string-in-balanced-strings", "url_en": "https://leetcode.com/problems/split-a-string-in-balanced-strings", "relative_path_cn": "/solution/1200-1299/1221.Split%20a%20String%20in%20Balanced%20Strings/README.md", "relative_path_en": "/solution/1200-1299/1221.Split%20a%20String%20in%20Balanced%20Strings/README_EN.md", "title_cn": "\u5206\u5272\u5e73\u8861\u5b57\u7b26\u4e32", "title_en": "Split a String in Balanced Strings", "question_title_slug": "split-a-string-in-balanced-strings", "content_en": "

    Balanced strings are those that have an equal quantity of 'L' and 'R' characters.

    \n\n

    Given a balanced string s, split it in the maximum amount of balanced strings.

    \n\n

    Return the maximum amount of split balanced strings.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "RLRRLLRLRL"\nOutput: 4\nExplanation: s can be split into "RL", "RRLL", "RL", "RL", each substring contains same number of 'L' and 'R'.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "RLLLLRRRLR"\nOutput: 3\nExplanation: s can be split into "RL", "LLLRRR", "LR", each substring contains same number of 'L' and 'R'.\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "LLLLRRRR"\nOutput: 1\nExplanation: s can be split into "LLLLRRRR".\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "RLRRRLLRLL"\nOutput: 2\nExplanation: s can be split into "RL", "RRRLLRLL", since each substring contains an equal number of 'L' and 'R'\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 1000
    • \n\t
    • s[i] is either 'L' or 'R'.
    • \n\t
    • s is a balanced string.
    • \n
    \n", "content_cn": "

    \u5728\u4e00\u4e2a \u5e73\u8861\u5b57\u7b26\u4e32 \u4e2d\uff0c'L' \u548c 'R' \u5b57\u7b26\u7684\u6570\u91cf\u662f\u76f8\u540c\u7684\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u5e73\u8861\u5b57\u7b26\u4e32\u00a0s\uff0c\u8bf7\u4f60\u5c06\u5b83\u5206\u5272\u6210\u5c3d\u53ef\u80fd\u591a\u7684\u5e73\u8861\u5b57\u7b26\u4e32\u3002

    \n\n

    \u6ce8\u610f\uff1a\u5206\u5272\u5f97\u5230\u7684\u6bcf\u4e2a\u5b57\u7b26\u4e32\u90fd\u5fc5\u987b\u662f\u5e73\u8861\u5b57\u7b26\u4e32\u3002

    \n\n

    \u8fd4\u56de\u53ef\u4ee5\u901a\u8fc7\u5206\u5272\u5f97\u5230\u7684\u5e73\u8861\u5b57\u7b26\u4e32\u7684 \u6700\u5927\u6570\u91cf \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"RLRRLLRLRL\"\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1as \u53ef\u4ee5\u5206\u5272\u4e3a \"RL\"\u3001\"RRLL\"\u3001\"RL\"\u3001\"RL\" \uff0c\u6bcf\u4e2a\u5b50\u5b57\u7b26\u4e32\u4e2d\u90fd\u5305\u542b\u76f8\u540c\u6570\u91cf\u7684 'L' \u548c 'R' \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"RLLLLRRRLR\"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1as \u53ef\u4ee5\u5206\u5272\u4e3a \"RL\"\u3001\"LLLRRR\"\u3001\"LR\" \uff0c\u6bcf\u4e2a\u5b50\u5b57\u7b26\u4e32\u4e2d\u90fd\u5305\u542b\u76f8\u540c\u6570\u91cf\u7684 'L' \u548c 'R' \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"LLLLRRRR\"\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1as \u53ea\u80fd\u4fdd\u6301\u539f\u6837 \"LLLLRRRR\".\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"RLRRRLLRLL\"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1as \u53ef\u4ee5\u5206\u5272\u4e3a \"RL\"\u3001\"RRRLLRLL\" \uff0c\u6bcf\u4e2a\u5b50\u5b57\u7b26\u4e32\u4e2d\u90fd\u5305\u542b\u76f8\u540c\u6570\u91cf\u7684 'L' \u548c 'R' \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 1000
    • \n\t
    • s[i] = 'L' \u6216 'R'
    • \n\t
    • s \u662f\u4e00\u4e2a \u5e73\u8861 \u5b57\u7b26\u4e32
    • \n
    \n", "tags_en": ["Greedy", "String"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int balancedStringSplit(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int balancedStringSplit(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def balancedStringSplit(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def balancedStringSplit(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint balancedStringSplit(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int BalancedStringSplit(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar balancedStringSplit = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef balanced_string_split(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func balancedStringSplit(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func balancedStringSplit(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def balancedStringSplit(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun balancedStringSplit(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn balanced_string_split(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function balancedStringSplit($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function balancedStringSplit(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (balanced-string-split s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1221](https://leetcode-cn.com/problems/split-a-string-in-balanced-strings)", "[\u5206\u5272\u5e73\u8861\u5b57\u7b26\u4e32](/solution/1200-1299/1221.Split%20a%20String%20in%20Balanced%20Strings/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1221](https://leetcode.com/problems/split-a-string-in-balanced-strings)", "[Split a String in Balanced Strings](/solution/1200-1299/1221.Split%20a%20String%20in%20Balanced%20Strings/README_EN.md)", "`Greedy`,`String`", "Easy", ""]}, {"question_id": "1340", "frontend_question_id": "1226", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/the-dining-philosophers", "url_en": "https://leetcode.com/problems/the-dining-philosophers", "relative_path_cn": "/solution/1200-1299/1226.The%20Dining%20Philosophers/README.md", "relative_path_en": "/solution/1200-1299/1226.The%20Dining%20Philosophers/README_EN.md", "title_cn": "\u54f2\u5b66\u5bb6\u8fdb\u9910", "title_en": "The Dining Philosophers", "question_title_slug": "the-dining-philosophers", "content_en": "

    Five silent philosophers sit at a round table with bowls of spaghetti. Forks are placed between each pair of adjacent philosophers.

    \n\n

    Each philosopher must alternately think and eat. However, a philosopher can only eat spaghetti when they have both left and right forks. Each fork can be held by only one philosopher and so a philosopher can use the fork only if it is not being used by another philosopher. After an individual philosopher finishes eating, they need to put down both forks so that the forks become available to others. A philosopher can take the fork on their right or the one on their left as they become available, but cannot start eating before getting both forks.

    \n\n

    Eating is not limited by the remaining amounts of spaghetti or stomach space; an infinite supply and an infinite demand are assumed.

    \n\n

    Design a discipline of behaviour (a concurrent algorithm) such that no philosopher will starve; i.e., each can forever continue to alternate between eating and thinking, assuming that no philosopher can know when others may want to eat or think.

    \n\n

    \"\"

    \n\n

    The problem statement and the image above are taken from wikipedia.org

    \n\n

     

    \n\n

    The philosophers' ids are numbered from 0 to 4 in a clockwise order. Implement the function void wantsToEat(philosopher, pickLeftFork, pickRightFork, eat, putLeftFork, putRightFork) where:

    \n\n
      \n\t
    • philosopher is the id of the philosopher who wants to eat.
    • \n\t
    • pickLeftFork and pickRightFork are functions you can call to pick the corresponding forks of that philosopher.
    • \n\t
    • eat is a function you can call to let the philosopher eat once he has picked both forks.
    • \n\t
    • putLeftFork and putRightFork are functions you can call to put down the corresponding forks of that philosopher.
    • \n\t
    • The philosophers are assumed to be thinking as long as they are not asking to eat (the function is not being called with their number).
    • \n
    \n\n

    Five threads, each representing a philosopher, will simultaneously use one object of your class to simulate the process. The function may be called for the same philosopher more than once, even before the last call ends.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 1\nOutput: [[4,2,1],[4,1,1],[0,1,1],[2,2,1],[2,1,1],[2,0,3],[2,1,2],[2,2,2],[4,0,3],[4,1,2],[0,2,1],[4,2,2],[3,2,1],[3,1,1],[0,0,3],[0,1,2],[0,2,2],[1,2,1],[1,1,1],[3,0,3],[3,1,2],[3,2,2],[1,0,3],[1,1,2],[1,2,2]]\nExplanation:\nn is the number of times each philosopher will call the function.\nThe output array describes the calls you made to the functions controlling the forks and the eat function, its format is:\noutput[i] = [a, b, c] (three integers)\n- a is the id of a philosopher.\n- b specifies the fork: {1 : left, 2 : right}.\n- c specifies the operation: {1 : pick, 2 : put, 3 : eat}.
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 60
    • \n
    \n", "content_cn": "

    5 \u4e2a\u6c89\u9ed8\u5be1\u8a00\u7684\u54f2\u5b66\u5bb6\u56f4\u5750\u5728\u5706\u684c\u524d\uff0c\u6bcf\u4eba\u9762\u524d\u4e00\u76d8\u610f\u9762\u3002\u53c9\u5b50\u653e\u5728\u54f2\u5b66\u5bb6\u4e4b\u95f4\u7684\u684c\u9762\u4e0a\u3002\uff085 \u4e2a\u54f2\u5b66\u5bb6\uff0c5 \u6839\u53c9\u5b50\uff09

    \n\n

    \u6240\u6709\u7684\u54f2\u5b66\u5bb6\u90fd\u53ea\u4f1a\u5728\u601d\u8003\u548c\u8fdb\u9910\u4e24\u79cd\u884c\u4e3a\u95f4\u4ea4\u66ff\u3002\u54f2\u5b66\u5bb6\u53ea\u6709\u540c\u65f6\u62ff\u5230\u5de6\u8fb9\u548c\u53f3\u8fb9\u7684\u53c9\u5b50\u624d\u80fd\u5403\u5230\u9762\uff0c\u800c\u540c\u4e00\u6839\u53c9\u5b50\u5728\u540c\u4e00\u65f6\u95f4\u53ea\u80fd\u88ab\u4e00\u4e2a\u54f2\u5b66\u5bb6\u4f7f\u7528\u3002\u6bcf\u4e2a\u54f2\u5b66\u5bb6\u5403\u5b8c\u9762\u540e\u90fd\u9700\u8981\u628a\u53c9\u5b50\u653e\u56de\u684c\u9762\u4ee5\u4f9b\u5176\u4ed6\u54f2\u5b66\u5bb6\u5403\u9762\u3002\u53ea\u8981\u6761\u4ef6\u5141\u8bb8\uff0c\u54f2\u5b66\u5bb6\u53ef\u4ee5\u62ff\u8d77\u5de6\u8fb9\u6216\u8005\u53f3\u8fb9\u7684\u53c9\u5b50\uff0c\u4f46\u5728\u6ca1\u6709\u540c\u65f6\u62ff\u5230\u5de6\u53f3\u53c9\u5b50\u65f6\u4e0d\u80fd\u8fdb\u98df\u3002

    \n\n

    \u5047\u8bbe\u9762\u7684\u6570\u91cf\u6ca1\u6709\u9650\u5236\uff0c\u54f2\u5b66\u5bb6\u4e5f\u80fd\u968f\u4fbf\u5403\uff0c\u4e0d\u9700\u8981\u8003\u8651\u5403\u4e0d\u5403\u5f97\u4e0b\u3002

    \n\n

    \u8bbe\u8ba1\u4e00\u4e2a\u8fdb\u9910\u89c4\u5219\uff08\u5e76\u884c\u7b97\u6cd5\uff09\u4f7f\u5f97\u6bcf\u4e2a\u54f2\u5b66\u5bb6\u90fd\u4e0d\u4f1a\u6328\u997f\uff1b\u4e5f\u5c31\u662f\u8bf4\uff0c\u5728\u6ca1\u6709\u4eba\u77e5\u9053\u522b\u4eba\u4ec0\u4e48\u65f6\u5019\u60f3\u5403\u4e1c\u897f\u6216\u601d\u8003\u7684\u60c5\u51b5\u4e0b\uff0c\u6bcf\u4e2a\u54f2\u5b66\u5bb6\u90fd\u53ef\u4ee5\u5728\u5403\u996d\u548c\u601d\u8003\u4e4b\u95f4\u4e00\u76f4\u4ea4\u66ff\u4e0b\u53bb\u3002

    \n\n

    \"\"

    \n\n

    \u95ee\u9898\u63cf\u8ff0\u548c\u56fe\u7247\u6765\u81ea\u7ef4\u57fa\u767e\u79d1 wikipedia.org

    \n\n

     

    \n\n

    \u54f2\u5b66\u5bb6\u4ece 0 \u5230 4 \u6309 \u987a\u65f6\u9488 \u7f16\u53f7\u3002\u8bf7\u5b9e\u73b0\u51fd\u6570 void wantsToEat(philosopher, pickLeftFork, pickRightFork, eat, putLeftFork, putRightFork)\uff1a

    \n\n
      \n\t
    • philosopher \u54f2\u5b66\u5bb6\u7684\u7f16\u53f7\u3002
    • \n\t
    • pickLeftFork \u548c pickRightFork \u8868\u793a\u62ff\u8d77\u5de6\u8fb9\u6216\u53f3\u8fb9\u7684\u53c9\u5b50\u3002
    • \n\t
    • eat \u8868\u793a\u5403\u9762\u3002
    • \n\t
    • putLeftFork \u548c putRightFork \u8868\u793a\u653e\u4e0b\u5de6\u8fb9\u6216\u53f3\u8fb9\u7684\u53c9\u5b50\u3002
    • \n\t
    • \u7531\u4e8e\u54f2\u5b66\u5bb6\u4e0d\u662f\u5728\u5403\u9762\u5c31\u662f\u5728\u60f3\u7740\u5565\u65f6\u5019\u5403\u9762\uff0c\u6240\u4ee5\u601d\u8003\u8fd9\u4e2a\u65b9\u6cd5\u6ca1\u6709\u5bf9\u5e94\u7684\u56de\u8c03\u3002
    • \n
    \n\n

    \u7ed9\u4f60 5 \u4e2a\u7ebf\u7a0b\uff0c\u6bcf\u4e2a\u90fd\u4ee3\u8868\u4e00\u4e2a\u54f2\u5b66\u5bb6\uff0c\u8bf7\u4f60\u4f7f\u7528\u7c7b\u7684\u540c\u4e00\u4e2a\u5bf9\u8c61\u6765\u6a21\u62df\u8fd9\u4e2a\u8fc7\u7a0b\u3002\u5728\u6700\u540e\u4e00\u6b21\u8c03\u7528\u7ed3\u675f\u4e4b\u524d\uff0c\u53ef\u80fd\u4f1a\u4e3a\u540c\u4e00\u4e2a\u54f2\u5b66\u5bb6\u591a\u6b21\u8c03\u7528\u8be5\u51fd\u6570\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1a[[4,2,1],[4,1,1],[0,1,1],[2,2,1],[2,1,1],[2,0,3],[2,1,2],[2,2,2],[4,0,3],[4,1,2],[0,2,1],[4,2,2],[3,2,1],[3,1,1],[0,0,3],[0,1,2],[0,2,2],[1,2,1],[1,1,1],[3,0,3],[3,1,2],[3,2,2],[1,0,3],[1,1,2],[1,2,2]]\n\u89e3\u91ca:\nn \u8868\u793a\u6bcf\u4e2a\u54f2\u5b66\u5bb6\u9700\u8981\u8fdb\u9910\u7684\u6b21\u6570\u3002\n\u8f93\u51fa\u6570\u7ec4\u63cf\u8ff0\u4e86\u53c9\u5b50\u7684\u63a7\u5236\u548c\u8fdb\u9910\u7684\u8c03\u7528\uff0c\u5b83\u7684\u683c\u5f0f\u5982\u4e0b\uff1a\noutput[i] = [a, b, c] (3\u4e2a\u6574\u6570)\n- a \u54f2\u5b66\u5bb6\u7f16\u53f7\u3002\n- b \u6307\u5b9a\u53c9\u5b50\uff1a{1 : \u5de6\u8fb9, 2 : \u53f3\u8fb9}.\n- c \u6307\u5b9a\u884c\u4e3a\uff1a{1 : \u62ff\u8d77, 2 : \u653e\u4e0b, 3 : \u5403\u9762}\u3002\n\u5982 [4,2,1] \u8868\u793a 4 \u53f7\u54f2\u5b66\u5bb6\u62ff\u8d77\u4e86\u53f3\u8fb9\u7684\u53c9\u5b50\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 60
    • \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class DiningPhilosophers {\npublic:\n DiningPhilosophers() {\n \n }\n\n void wantsToEat(int philosopher,\n function pickLeftFork,\n function pickRightFork,\n function eat,\n function putLeftFork,\n function putRightFork) {\n\t\t\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class DiningPhilosophers {\n\n public DiningPhilosophers() {\n \n }\n\n // call the run() method of any runnable to execute its code\n public void wantsToEat(int philosopher,\n Runnable pickLeftFork,\n Runnable pickRightFork,\n Runnable eat,\n Runnable putLeftFork,\n Runnable putRightFork) throws InterruptedException {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class DiningPhilosophers(object):\n\n # call the functions directly to execute, for example, eat()\n def wantsToEat(self, philosopher, pickLeftFork, pickRightFork, eat, putLeftFork, putRightFork):\n \"\"\"\n :type philosopher: int\n :type pickLeftFork: method\n :type pickRightFork: method\n :type eat: method\n :type putLeftFork: method\n :type putRightFork: method\n :rtype: void\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class DiningPhilosophers:\n\n # call the functions directly to execute, for example, eat()\n def wantsToEat(self,\n philosopher: int,\n pickLeftFork: 'Callable[[], None]',\n pickRightFork: 'Callable[[], None]',\n eat: 'Callable[[], None]',\n putLeftFork: 'Callable[[], None]',\n putRightFork: 'Callable[[], None]') -> None:\n ", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1226](https://leetcode-cn.com/problems/the-dining-philosophers)", "[\u54f2\u5b66\u5bb6\u8fdb\u9910](/solution/1200-1299/1226.The%20Dining%20Philosophers/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1226](https://leetcode.com/problems/the-dining-philosophers)", "[The Dining Philosophers](/solution/1200-1299/1226.The%20Dining%20Philosophers/README_EN.md)", "", "Medium", ""]}, {"question_id": "1339", "frontend_question_id": "1212", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/team-scores-in-football-tournament", "url_en": "https://leetcode.com/problems/team-scores-in-football-tournament", "relative_path_cn": "/solution/1200-1299/1212.Team%20Scores%20in%20Football%20Tournament/README.md", "relative_path_en": "/solution/1200-1299/1212.Team%20Scores%20in%20Football%20Tournament/README_EN.md", "title_cn": "\u67e5\u8be2\u7403\u961f\u79ef\u5206", "title_en": "Team Scores in Football Tournament", "question_title_slug": "team-scores-in-football-tournament", "content_en": "

    Table: Teams

    \n\n
    \n+---------------+----------+\n| Column Name   | Type     |\n+---------------+----------+\n| team_id       | int      |\n| team_name     | varchar  |\n+---------------+----------+\nteam_id is the primary key of this table.\nEach row of this table represents a single football team.\n
    \n\n

    Table: Matches

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| match_id      | int     |\n| host_team     | int     |\n| guest_team    | int     | \n| host_goals    | int     |\n| guest_goals   | int     |\n+---------------+---------+\nmatch_id is the primary key of this table.\nEach row is a record of a finished match between two different teams. \nTeams host_team and guest_team are represented by their IDs in the teams table (team_id) and they scored host_goals and guest_goals goals respectively.\n
    \n\n

     

    \nYou would like to compute the scores of all teams after all matches. Points are awarded as follows:\n\n
      \n\t
    • A team receives three points if they win a match (Score strictly more goals than the opponent team).
    • \n\t
    • A team receives one point if they draw a match (Same number of goals as the opponent team).
    • \n\t
    • A team receives no points if they lose a match (Score less goals than the opponent team).
    • \n
    \n\n

    Write an SQL query that selects the team_id, team_name and num_points of each team in the tournament after all described matches. Result table should be ordered by num_points (decreasing order). In case of a tie, order the records by team_id (increasing order).

    \n\n

    The query result format is in the following example:

    \n\n
    \nTeams table:\n+-----------+--------------+\n| team_id   | team_name    |\n+-----------+--------------+\n| 10        | Leetcode FC  |\n| 20        | NewYork FC   |\n| 30        | Atlanta FC   |\n| 40        | Chicago FC   |\n| 50        | Toronto FC   |\n+-----------+--------------+\n\nMatches table:\n+------------+--------------+---------------+-------------+--------------+\n| match_id   | host_team    | guest_team    | host_goals  | guest_goals  |\n+------------+--------------+---------------+-------------+--------------+\n| 1          | 10           | 20            | 3           | 0            |\n| 2          | 30           | 10            | 2           | 2            |\n| 3          | 10           | 50            | 5           | 1            |\n| 4          | 20           | 30            | 1           | 0            |\n| 5          | 50           | 30            | 1           | 0            |\n+------------+--------------+---------------+-------------+--------------+\n\nResult table:\n+------------+--------------+---------------+\n| team_id    | team_name    | num_points    |\n+------------+--------------+---------------+\n| 10         | Leetcode FC  | 7             |\n| 20         | NewYork FC   | 3             |\n| 50         | Toronto FC   | 3             |\n| 30         | Atlanta FC   | 1             |\n| 40         | Chicago FC   | 0             |\n+------------+--------------+---------------+\n
    \n", "content_cn": "

    Table: Teams

    \n\n
    \n+---------------+----------+\n| Column Name   | Type     |\n+---------------+----------+\n| team_id       | int      |\n| team_name     | varchar  |\n+---------------+----------+\n\u6b64\u8868\u7684\u4e3b\u952e\u662f team_id\uff0c\u8868\u4e2d\u7684\u6bcf\u4e00\u884c\u90fd\u4ee3\u8868\u4e00\u652f\u72ec\u7acb\u8db3\u7403\u961f\u3002\n
    \n\n

    Table: Matches

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| match_id      | int     |\n| host_team     | int     |\n| guest_team    | int     | \n| host_goals    | int     |\n| guest_goals   | int     |\n+---------------+---------+\n\u6b64\u8868\u7684\u4e3b\u952e\u662f match_id\uff0c\u8868\u4e2d\u7684\u6bcf\u4e00\u884c\u90fd\u4ee3\u8868\u4e00\u573a\u5df2\u7ed3\u675f\u7684\u6bd4\u8d5b\uff0c\u6bd4\u8d5b\u7684\u4e3b\u5ba2\u961f\u5206\u522b\u7531\u5b83\u4eec\u81ea\u5df1\u7684 id \u8868\u793a\uff0c\u4ed6\u4eec\u7684\u8fdb\u7403\u7531 host_goals \u548c guest_goals \u5206\u522b\u8868\u793a\u3002\n
    \n\n

     

    \n\n

    \u79ef\u5206\u89c4\u5219\u5982\u4e0b\uff1a

    \n\n
      \n\t
    • \u8d62\u4e00\u573a\u5f97\u4e09\u5206\uff1b
    • \n\t
    • \u5e73\u4e00\u573a\u5f97\u4e00\u5206\uff1b
    • \n\t
    • \u8f93\u4e00\u573a\u4e0d\u5f97\u5206\u3002
    • \n
    \n\n

    \u5199\u51fa\u4e00\u6761SQL\u8bed\u53e5\u4ee5\u67e5\u8be2\u6bcf\u4e2a\u961f\u7684 team_id\uff0cteam_name \u548c num_points\u3002\u7ed3\u679c\u6839\u636e num_points \u964d\u5e8f\u6392\u5e8f\uff0c\u5982\u679c\u6709\u4e24\u961f\u79ef\u5206\u76f8\u540c\uff0c\u90a3\u4e48\u8fd9\u4e24\u961f\u6309 team_id  \u5347\u5e8f\u6392\u5e8f\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\uff1a

    \n\n
    \nTeams table:\n+-----------+--------------+\n| team_id   | team_name    |\n+-----------+--------------+\n| 10        | Leetcode FC  |\n| 20        | NewYork FC   |\n| 30        | Atlanta FC   |\n| 40        | Chicago FC   |\n| 50        | Toronto FC   |\n+-----------+--------------+\n\nMatches table:\n+------------+--------------+---------------+-------------+--------------+\n| match_id   | host_team    | guest_team    | host_goals  | guest_goals  |\n+------------+--------------+---------------+-------------+--------------+\n| 1          | 10           | 20            | 3           | 0            |\n| 2          | 30           | 10            | 2           | 2            |\n| 3          | 10           | 50            | 5           | 1            |\n| 4          | 20           | 30            | 1           | 0            |\n| 5          | 50           | 30            | 1           | 0            |\n+------------+--------------+---------------+-------------+--------------+\n\nResult table:\n+------------+--------------+---------------+\n| team_id    | team_name    | num_points    |\n+------------+--------------+---------------+\n| 10         | Leetcode FC  | 7             |\n| 20         | NewYork FC   | 3             |\n| 50         | Toronto FC   | 3             |\n| 30         | Atlanta FC   | 1             |\n| 40         | Chicago FC   | 0             |\n+------------+--------------+---------------+\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1212](https://leetcode-cn.com/problems/team-scores-in-football-tournament)", "[\u67e5\u8be2\u7403\u961f\u79ef\u5206](/solution/1200-1299/1212.Team%20Scores%20in%20Football%20Tournament/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1212](https://leetcode.com/problems/team-scores-in-football-tournament)", "[Team Scores in Football Tournament](/solution/1200-1299/1212.Team%20Scores%20in%20Football%20Tournament/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1338", "frontend_question_id": "1211", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/queries-quality-and-percentage", "url_en": "https://leetcode.com/problems/queries-quality-and-percentage", "relative_path_cn": "/solution/1200-1299/1211.Queries%20Quality%20and%20Percentage/README.md", "relative_path_en": "/solution/1200-1299/1211.Queries%20Quality%20and%20Percentage/README_EN.md", "title_cn": "\u67e5\u8be2\u7ed3\u679c\u7684\u8d28\u91cf\u548c\u5360\u6bd4", "title_en": "Queries Quality and Percentage", "question_title_slug": "queries-quality-and-percentage", "content_en": "

    Table: Queries

    \n\n
    \n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| query_name  | varchar |\n| result      | varchar |\n| position    | int     |\n| rating      | int     |\n+-------------+---------+\nThere is no primary key for this table, it may have duplicate rows.\nThis table contains information collected from some queries on a database.\nThe position column has a value from 1 to 500.\nThe rating column has a value from 1 to 5. Query with rating less than 3 is a poor query.\n
    \n\n

     

    \n\n

    We define query quality as:

    \n\n
    \n

    The average of the ratio between query rating and its position.

    \n
    \n\n

    We also define poor query percentage as:

    \n\n
    \n

    The percentage of all queries with rating less than 3.

    \n
    \n\n

    Write an SQL query to find each query_name, the quality and poor_query_percentage.

    \n\n

    Both quality and poor_query_percentage should be rounded to 2 decimal places.

    \n\n

    The query result format is in the following example:

    \n\n
    \nQueries table:\n+------------+-------------------+----------+--------+\n| query_name | result            | position | rating |\n+------------+-------------------+----------+--------+\n| Dog        | Golden Retriever  | 1        | 5      |\n| Dog        | German Shepherd   | 2        | 5      |\n| Dog        | Mule              | 200      | 1      |\n| Cat        | Shirazi           | 5        | 2      |\n| Cat        | Siamese           | 3        | 3      |\n| Cat        | Sphynx            | 7        | 4      |\n+------------+-------------------+----------+--------+\n\nResult table:\n+------------+---------+-----------------------+\n| query_name | quality | poor_query_percentage |\n+------------+---------+-----------------------+\n| Dog        | 2.50    | 33.33                 |\n| Cat        | 0.66    | 33.33                 |\n+------------+---------+-----------------------+\n\nDog queries quality is ((5 / 1) + (5 / 2) + (1 / 200)) / 3 = 2.50\nDog queries poor_ query_percentage is (1 / 3) * 100 = 33.33\n\nCat queries quality equals ((2 / 5) + (3 / 3) + (4 / 7)) / 3 = 0.66\nCat queries poor_ query_percentage is (1 / 3) * 100 = 33.33\n
    \n", "content_cn": "

    \u67e5\u8be2\u8868 Queries\uff1a 

    \n\n
    \n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| query_name  | varchar |\n| result      | varchar |\n| position    | int     |\n| rating      | int     |\n+-------------+---------+\n\u6b64\u8868\u6ca1\u6709\u4e3b\u952e\uff0c\u5e76\u53ef\u80fd\u6709\u91cd\u590d\u7684\u884c\u3002\n\u6b64\u8868\u5305\u542b\u4e86\u4e00\u4e9b\u4ece\u6570\u636e\u5e93\u4e2d\u6536\u96c6\u7684\u67e5\u8be2\u4fe1\u606f\u3002\n“\u4f4d\u7f6e”\uff08position\uff09\u5217\u7684\u503c\u4e3a 1 \u5230 500 \u3002\n“\u8bc4\u5206”\uff08rating\uff09\u5217\u7684\u503c\u4e3a 1 \u5230 5 \u3002\u8bc4\u5206\u5c0f\u4e8e 3 \u7684\u67e5\u8be2\u88ab\u5b9a\u4e49\u4e3a\u8d28\u91cf\u5f88\u5dee\u7684\u67e5\u8be2\u3002\n
    \n\n

     

    \n\n

    \u5c06\u67e5\u8be2\u7ed3\u679c\u7684\u8d28\u91cf quality \u5b9a\u4e49\u4e3a\uff1a

    \n\n
    \n

    \u5404\u67e5\u8be2\u7ed3\u679c\u7684\u8bc4\u5206\u4e0e\u5176\u4f4d\u7f6e\u4e4b\u95f4\u6bd4\u7387\u7684\u5e73\u5747\u503c\u3002

    \n
    \n\n

    \u5c06\u52a3\u8d28\u67e5\u8be2\u767e\u5206\u6bd4 poor_query_percentage \u4e3a\uff1a

    \n\n
    \n

    \u8bc4\u5206\u5c0f\u4e8e 3 \u7684\u67e5\u8be2\u7ed3\u679c\u5360\u5168\u90e8\u67e5\u8be2\u7ed3\u679c\u7684\u767e\u5206\u6bd4\u3002

    \n
    \n\n

    \u7f16\u5199\u4e00\u7ec4 SQL \u6765\u67e5\u627e\u6bcf\u6b21\u67e5\u8be2\u7684\u540d\u79f0(query_name)\u3001\u8d28\u91cf(quality) \u548c \u52a3\u8d28\u67e5\u8be2\u767e\u5206\u6bd4(poor_query_percentage)\u3002

    \n\n

    \u8d28\u91cf(quality) \u548c\u52a3\u8d28\u67e5\u8be2\u767e\u5206\u6bd4(poor_query_percentage) \u90fd\u5e94\u56db\u820d\u4e94\u5165\u5230\u5c0f\u6570\u70b9\u540e\u4e24\u4f4d\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u6240\u793a\uff1a

    \n\n
    \nQueries table:\n+------------+-------------------+----------+--------+\n| query_name | result            | position | rating |\n+------------+-------------------+----------+--------+\n| Dog        | Golden Retriever  | 1        | 5      |\n| Dog        | German Shepherd   | 2        | 5      |\n| Dog        | Mule              | 200      | 1      |\n| Cat        | Shirazi           | 5        | 2      |\n| Cat        | Siamese           | 3        | 3      |\n| Cat        | Sphynx            | 7        | 4      |\n+------------+-------------------+----------+--------+\n\nResult table:\n+------------+---------+-----------------------+\n| query_name | quality | poor_query_percentage |\n+------------+---------+-----------------------+\n| Dog        | 2.50    | 33.33                 |\n| Cat        | 0.66    | 33.33                 |\n+------------+---------+-----------------------+\n\nDog \u67e5\u8be2\u7ed3\u679c\u7684\u8d28\u91cf\u4e3a ((5 / 1) + (5 / 2) + (1 / 200)) / 3 = 2.50\nDog \u67e5\u8be2\u7ed3\u679c\u7684\u52a3\u8d28\u67e5\u8be2\u767e\u5206\u6bd4\u4e3a (1 / 3) * 100 = 33.33\n\nCat \u67e5\u8be2\u7ed3\u679c\u7684\u8d28\u91cf\u4e3a ((2 / 5) + (3 / 3) + (4 / 7)) / 3 = 0.66\nCat \u67e5\u8be2\u7ed3\u679c\u7684\u52a3\u8d28\u67e5\u8be2\u767e\u5206\u6bd4\u4e3a (1 / 3) * 100 = 33.33\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1211](https://leetcode-cn.com/problems/queries-quality-and-percentage)", "[\u67e5\u8be2\u7ed3\u679c\u7684\u8d28\u91cf\u548c\u5360\u6bd4](/solution/1200-1299/1211.Queries%20Quality%20and%20Percentage/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1211](https://leetcode.com/problems/queries-quality-and-percentage)", "[Queries Quality and Percentage](/solution/1200-1299/1211.Queries%20Quality%20and%20Percentage/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1337", "frontend_question_id": "1206", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/design-skiplist", "url_en": "https://leetcode.com/problems/design-skiplist", "relative_path_cn": "/solution/1200-1299/1206.Design%20Skiplist/README.md", "relative_path_en": "/solution/1200-1299/1206.Design%20Skiplist/README_EN.md", "title_cn": "\u8bbe\u8ba1\u8df3\u8868", "title_en": "Design Skiplist", "question_title_slug": "design-skiplist", "content_en": "

    Design a Skiplist without using any built-in libraries.

    \r\n\r\n

    A Skiplist is a data structure that takes O(log(n)) time to add, erase and search. Comparing with treap and red-black tree which has the same function and performance, the code length of Skiplist can be comparatively short and the idea behind Skiplists are just simple linked lists.

    \r\n\r\n

    For example: we have a Skiplist containing [30,40,50,60,70,90] and we want to add 80 and 45 into it. The Skiplist works this way:

    \r\n\r\n

    \"\"
    \r\nArtyom Kalinin [CC BY-SA 3.0], via Wikimedia Commons

    \r\n\r\n

    You can see there are many layers in the Skiplist. Each layer is a sorted linked list. With the help of the top layers, add , erase and search can be faster than O(n). It can be proven that the average time complexity for each operation is O(log(n)) and space complexity is O(n).

    \r\n\r\n

    To be specific, your design should include these functions:

    \r\n\r\n
      \r\n\t
    • bool search(int target) : Return whether the target exists in the Skiplist or not.
    • \r\n\t
    • void add(int num): Insert a value into the SkipList. 
    • \r\n\t
    • bool erase(int num): Remove a value in the Skiplist. If num does not exist in the Skiplist, do nothing and return false. If there exists multiple num values, removing any one of them is fine.
    • \r\n
    \r\n\r\n

    See more about Skiplist : https://en.wikipedia.org/wiki/Skip_list

    \r\n\r\n

    Note that duplicates may exist in the Skiplist, your code needs to handle this situation.

    \r\n\r\n

     

    \r\n\r\n

    Example:

    \r\n\r\n
    \r\nSkiplist skiplist = new Skiplist();\r\n\r\nskiplist.add(1);\r\nskiplist.add(2);\r\nskiplist.add(3);\r\nskiplist.search(0);   // return false.\r\nskiplist.add(4);\r\nskiplist.search(1);   // return true.\r\nskiplist.erase(0);    // return false, 0 is not in skiplist.\r\nskiplist.erase(1);    // return true.\r\nskiplist.search(1);   // return false, 1 has already been erased.
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 0 <= num, target <= 20000
    • \r\n\t
    • At most 50000 calls will be made to search, add, and erase.
    • \r\n
    ", "content_cn": "

    \u4e0d\u4f7f\u7528\u4efb\u4f55\u5e93\u51fd\u6570\uff0c\u8bbe\u8ba1\u4e00\u4e2a\u8df3\u8868\u3002

    \n\n

    \u8df3\u8868\u662f\u5728 O(log(n)) \u65f6\u95f4\u5185\u5b8c\u6210\u589e\u52a0\u3001\u5220\u9664\u3001\u641c\u7d22\u64cd\u4f5c\u7684\u6570\u636e\u7ed3\u6784\u3002\u8df3\u8868\u76f8\u6bd4\u4e8e\u6811\u5806\u4e0e\u7ea2\u9ed1\u6811\uff0c\u5176\u529f\u80fd\u4e0e\u6027\u80fd\u76f8\u5f53\uff0c\u5e76\u4e14\u8df3\u8868\u7684\u4ee3\u7801\u957f\u5ea6\u76f8\u8f83\u4e0b\u66f4\u77ed\uff0c\u5176\u8bbe\u8ba1\u601d\u60f3\u4e0e\u94fe\u8868\u76f8\u4f3c\u3002

    \n\n

    \u4f8b\u5982\uff0c\u4e00\u4e2a\u8df3\u8868\u5305\u542b [30, 40, 50, 60, 70, 90]\uff0c\u7136\u540e\u589e\u52a0 80\u300145 \u5230\u8df3\u8868\u4e2d\uff0c\u4ee5\u4e0b\u56fe\u7684\u65b9\u5f0f\u64cd\u4f5c\uff1a

    \n\n

    \"\"
    \nArtyom Kalinin [CC BY-SA 3.0], via Wikimedia Commons

    \n\n

    \u8df3\u8868\u4e2d\u6709\u5f88\u591a\u5c42\uff0c\u6bcf\u4e00\u5c42\u662f\u4e00\u4e2a\u77ed\u7684\u94fe\u8868\u3002\u5728\u7b2c\u4e00\u5c42\u7684\u4f5c\u7528\u4e0b\uff0c\u589e\u52a0\u3001\u5220\u9664\u548c\u641c\u7d22\u64cd\u4f5c\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e0d\u8d85\u8fc7 O(n)\u3002\u8df3\u8868\u7684\u6bcf\u4e00\u4e2a\u64cd\u4f5c\u7684\u5e73\u5747\u65f6\u95f4\u590d\u6742\u5ea6\u662f O(log(n))\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u662f O(n)\u3002

    \n\n

    \u5728\u672c\u9898\u4e2d\uff0c\u4f60\u7684\u8bbe\u8ba1\u5e94\u8be5\u8981\u5305\u542b\u8fd9\u4e9b\u51fd\u6570\uff1a

    \n\n
      \n\t
    • bool search(int target) : \u8fd4\u56detarget\u662f\u5426\u5b58\u5728\u4e8e\u8df3\u8868\u4e2d\u3002
    • \n\t
    • void add(int num): \u63d2\u5165\u4e00\u4e2a\u5143\u7d20\u5230\u8df3\u8868\u3002
    • \n\t
    • bool erase(int num): \u5728\u8df3\u8868\u4e2d\u5220\u9664\u4e00\u4e2a\u503c\uff0c\u5982\u679c num \u4e0d\u5b58\u5728\uff0c\u76f4\u63a5\u8fd4\u56defalse. \u5982\u679c\u5b58\u5728\u591a\u4e2a num \uff0c\u5220\u9664\u5176\u4e2d\u4efb\u610f\u4e00\u4e2a\u5373\u53ef\u3002
    • \n
    \n\n

    \u4e86\u89e3\u66f4\u591a : https://en.wikipedia.org/wiki/Skip_list

    \n\n

    \u6ce8\u610f\uff0c\u8df3\u8868\u4e2d\u53ef\u80fd\u5b58\u5728\u591a\u4e2a\u76f8\u540c\u7684\u503c\uff0c\u4f60\u7684\u4ee3\u7801\u9700\u8981\u5904\u7406\u8fd9\u79cd\u60c5\u51b5\u3002

    \n\n

    \u6837\u4f8b:

    \n\n
    Skiplist skiplist = new Skiplist();\n\nskiplist.add(1);\nskiplist.add(2);\nskiplist.add(3);\nskiplist.search(0);   // \u8fd4\u56de false\nskiplist.add(4);\nskiplist.search(1);   // \u8fd4\u56de true\nskiplist.erase(0);    // \u8fd4\u56de false\uff0c0 \u4e0d\u5728\u8df3\u8868\u4e2d\nskiplist.erase(1);    // \u8fd4\u56de true\nskiplist.search(1);   // \u8fd4\u56de false\uff0c1 \u5df2\u88ab\u64e6\u9664\n
    \n\n

    \u7ea6\u675f\u6761\u4ef6:

    \n\n
      \n\t
    • 0 <= num, target <= 20000
    • \n\t
    • \u6700\u591a\u8c03\u7528 50000 \u6b21 search, add, \u4ee5\u53ca erase\u64cd\u4f5c\u3002
    • \n
    \n", "tags_en": ["Design"], "tags_cn": ["\u8bbe\u8ba1"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Skiplist {\npublic:\n Skiplist() {\n\n }\n \n bool search(int target) {\n\n }\n \n void add(int num) {\n\n }\n \n bool erase(int num) {\n\n }\n};\n\n/**\n * Your Skiplist object will be instantiated and called as such:\n * Skiplist* obj = new Skiplist();\n * bool param_1 = obj->search(target);\n * obj->add(num);\n * bool param_3 = obj->erase(num);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Skiplist {\n\n public Skiplist() {\n\n }\n \n public boolean search(int target) {\n\n }\n \n public void add(int num) {\n\n }\n \n public boolean erase(int num) {\n\n }\n}\n\n/**\n * Your Skiplist object will be instantiated and called as such:\n * Skiplist obj = new Skiplist();\n * boolean param_1 = obj.search(target);\n * obj.add(num);\n * boolean param_3 = obj.erase(num);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Skiplist(object):\n\n def __init__(self):\n \n\n def search(self, target):\n \"\"\"\n :type target: int\n :rtype: bool\n \"\"\"\n \n\n def add(self, num):\n \"\"\"\n :type num: int\n :rtype: None\n \"\"\"\n \n\n def erase(self, num):\n \"\"\"\n :type num: int\n :rtype: bool\n \"\"\"\n \n\n\n# Your Skiplist object will be instantiated and called as such:\n# obj = Skiplist()\n# param_1 = obj.search(target)\n# obj.add(num)\n# param_3 = obj.erase(num)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Skiplist:\n\n def __init__(self):\n \n\n def search(self, target: int) -> bool:\n \n\n def add(self, num: int) -> None:\n \n\n def erase(self, num: int) -> bool:\n \n\n\n# Your Skiplist object will be instantiated and called as such:\n# obj = Skiplist()\n# param_1 = obj.search(target)\n# obj.add(num)\n# param_3 = obj.erase(num)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} Skiplist;\n\n\nSkiplist* skiplistCreate() {\n \n}\n\nbool skiplistSearch(Skiplist* obj, int target) {\n \n}\n\nvoid skiplistAdd(Skiplist* obj, int num) {\n \n}\n\nbool skiplistErase(Skiplist* obj, int num) {\n \n}\n\nvoid skiplistFree(Skiplist* obj) {\n \n}\n\n/**\n * Your Skiplist struct will be instantiated and called as such:\n * Skiplist* obj = skiplistCreate();\n * bool param_1 = skiplistSearch(obj, target);\n \n * skiplistAdd(obj, num);\n \n * bool param_3 = skiplistErase(obj, num);\n \n * skiplistFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Skiplist {\n\n public Skiplist() {\n\n }\n \n public bool Search(int target) {\n\n }\n \n public void Add(int num) {\n\n }\n \n public bool Erase(int num) {\n\n }\n}\n\n/**\n * Your Skiplist object will be instantiated and called as such:\n * Skiplist obj = new Skiplist();\n * bool param_1 = obj.Search(target);\n * obj.Add(num);\n * bool param_3 = obj.Erase(num);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "\nvar Skiplist = function() {\n\n};\n\n/** \n * @param {number} target\n * @return {boolean}\n */\nSkiplist.prototype.search = function(target) {\n\n};\n\n/** \n * @param {number} num\n * @return {void}\n */\nSkiplist.prototype.add = function(num) {\n\n};\n\n/** \n * @param {number} num\n * @return {boolean}\n */\nSkiplist.prototype.erase = function(num) {\n\n};\n\n/**\n * Your Skiplist object will be instantiated and called as such:\n * var obj = new Skiplist()\n * var param_1 = obj.search(target)\n * obj.add(num)\n * var param_3 = obj.erase(num)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class Skiplist\n def initialize()\n\n end\n\n\n=begin\n :type target: Integer\n :rtype: Boolean\n=end\n def search(target)\n\n end\n\n\n=begin\n :type num: Integer\n :rtype: Void\n=end\n def add(num)\n\n end\n\n\n=begin\n :type num: Integer\n :rtype: Boolean\n=end\n def erase(num)\n\n end\n\n\nend\n\n# Your Skiplist object will be instantiated and called as such:\n# obj = Skiplist.new()\n# param_1 = obj.search(target)\n# obj.add(num)\n# param_3 = obj.erase(num)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass Skiplist {\n\n init() {\n\n }\n \n func search(_ target: Int) -> Bool {\n\n }\n \n func add(_ num: Int) {\n\n }\n \n func erase(_ num: Int) -> Bool {\n\n }\n}\n\n/**\n * Your Skiplist object will be instantiated and called as such:\n * let obj = Skiplist()\n * let ret_1: Bool = obj.search(target)\n * obj.add(num)\n * let ret_3: Bool = obj.erase(num)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type Skiplist struct {\n\n}\n\n\nfunc Constructor() Skiplist {\n\n}\n\n\nfunc (this *Skiplist) Search(target int) bool {\n\n}\n\n\nfunc (this *Skiplist) Add(num int) {\n\n}\n\n\nfunc (this *Skiplist) Erase(num int) bool {\n\n}\n\n\n/**\n * Your Skiplist object will be instantiated and called as such:\n * obj := Constructor();\n * param_1 := obj.Search(target);\n * obj.Add(num);\n * param_3 := obj.Erase(num);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class Skiplist() {\n\n def search(target: Int): Boolean = {\n\n }\n\n def add(num: Int) {\n\n }\n\n def erase(num: Int): Boolean = {\n\n }\n\n}\n\n/**\n * Your Skiplist object will be instantiated and called as such:\n * var obj = new Skiplist()\n * var param_1 = obj.search(target)\n * obj.add(num)\n * var param_3 = obj.erase(num)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Skiplist() {\n\n fun search(target: Int): Boolean {\n\n }\n\n fun add(num: Int) {\n\n }\n\n fun erase(num: Int): Boolean {\n\n }\n\n}\n\n/**\n * Your Skiplist object will be instantiated and called as such:\n * var obj = Skiplist()\n * var param_1 = obj.search(target)\n * obj.add(num)\n * var param_3 = obj.erase(num)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct Skiplist {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl Skiplist {\n\n fn new() -> Self {\n\n }\n \n fn search(&self, target: i32) -> bool {\n\n }\n \n fn add(&self, num: i32) {\n\n }\n \n fn erase(&self, num: i32) -> bool {\n\n }\n}\n\n/**\n * Your Skiplist object will be instantiated and called as such:\n * let obj = Skiplist::new();\n * let ret_1: bool = obj.search(target);\n * obj.add(num);\n * let ret_3: bool = obj.erase(num);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Skiplist {\n /**\n */\n function __construct() {\n\n }\n\n /**\n * @param Integer $target\n * @return Boolean\n */\n function search($target) {\n\n }\n\n /**\n * @param Integer $num\n * @return NULL\n */\n function add($num) {\n\n }\n\n /**\n * @param Integer $num\n * @return Boolean\n */\n function erase($num) {\n\n }\n}\n\n/**\n * Your Skiplist object will be instantiated and called as such:\n * $obj = Skiplist();\n * $ret_1 = $obj->search($target);\n * $obj->add($num);\n * $ret_3 = $obj->erase($num);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class Skiplist {\n constructor() {\n\n }\n\n search(target: number): boolean {\n\n }\n\n add(num: number): void {\n\n }\n\n erase(num: number): boolean {\n\n }\n}\n\n/**\n * Your Skiplist object will be instantiated and called as such:\n * var obj = new Skiplist()\n * var param_1 = obj.search(target)\n * obj.add(num)\n * var param_3 = obj.erase(num)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define skiplist%\n (class object%\n (super-new)\n (init-field)\n \n ; search : exact-integer? -> boolean?\n (define/public (search target)\n\n )\n ; add : exact-integer? -> void?\n (define/public (add num)\n\n )\n ; erase : exact-integer? -> boolean?\n (define/public (erase num)\n\n )))\n\n;; Your skiplist% object will be instantiated and called as such:\n;; (define obj (new skiplist%))\n;; (define param_1 (send obj search target))\n;; (send obj add num)\n;; (define param_3 (send obj erase num))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1206](https://leetcode-cn.com/problems/design-skiplist)", "[\u8bbe\u8ba1\u8df3\u8868](/solution/1200-1299/1206.Design%20Skiplist/README.md)", "`\u8bbe\u8ba1`", "\u56f0\u96be", ""], "md_table_row_en": ["[1206](https://leetcode.com/problems/design-skiplist)", "[Design Skiplist](/solution/1200-1299/1206.Design%20Skiplist/README_EN.md)", "`Design`", "Hard", ""]}, {"question_id": "1332", "frontend_question_id": "1220", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-vowels-permutation", "url_en": "https://leetcode.com/problems/count-vowels-permutation", "relative_path_cn": "/solution/1200-1299/1220.Count%20Vowels%20Permutation/README.md", "relative_path_en": "/solution/1200-1299/1220.Count%20Vowels%20Permutation/README_EN.md", "title_cn": "\u7edf\u8ba1\u5143\u97f3\u5b57\u6bcd\u5e8f\u5217\u7684\u6570\u76ee", "title_en": "Count Vowels Permutation", "question_title_slug": "count-vowels-permutation", "content_en": "

    Given an integer n, your task is to count how many strings of length n can be formed under the following rules:

    \n\n
      \n\t
    • Each character is a lower case vowel ('a', 'e', 'i', 'o', 'u')
    • \n\t
    • Each vowel 'a' may only be followed by an 'e'.
    • \n\t
    • Each vowel 'e' may only be followed by an 'a' or an 'i'.
    • \n\t
    • Each vowel 'i' may not be followed by another 'i'.
    • \n\t
    • Each vowel 'o' may only be followed by an 'i' or a 'u'.
    • \n\t
    • Each vowel 'u' may only be followed by an 'a'.
    • \n
    \n\n

    Since the answer may be too large, return it modulo 10^9 + 7.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 1\nOutput: 5\nExplanation: All possible strings are: "a", "e", "i" , "o" and "u".\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 2\nOutput: 10\nExplanation: All possible strings are: "ae", "ea", "ei", "ia", "ie", "io", "iu", "oi", "ou" and "ua".\n
    \n\n

    Example 3: 

    \n\n
    \nInput: n = 5\nOutput: 68
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 2 * 10^4
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n\uff0c\u8bf7\u4f60\u5e2e\u5fd9\u7edf\u8ba1\u4e00\u4e0b\u6211\u4eec\u53ef\u4ee5\u6309\u4e0b\u8ff0\u89c4\u5219\u5f62\u6210\u591a\u5c11\u4e2a\u957f\u5ea6\u4e3a n \u7684\u5b57\u7b26\u4e32\uff1a

    \n\n
      \n\t
    • \u5b57\u7b26\u4e32\u4e2d\u7684\u6bcf\u4e2a\u5b57\u7b26\u90fd\u5e94\u5f53\u662f\u5c0f\u5199\u5143\u97f3\u5b57\u6bcd\uff08'a', 'e', 'i', 'o', 'u'\uff09
    • \n\t
    • \u6bcf\u4e2a\u5143\u97f3 'a' \u540e\u9762\u90fd\u53ea\u80fd\u8ddf\u7740 'e'
    • \n\t
    • \u6bcf\u4e2a\u5143\u97f3 'e' \u540e\u9762\u53ea\u80fd\u8ddf\u7740 'a' \u6216\u8005\u662f 'i'
    • \n\t
    • \u6bcf\u4e2a\u5143\u97f3 'i' \u540e\u9762 \u4e0d\u80fd \u518d\u8ddf\u7740\u53e6\u4e00\u4e2a 'i'
    • \n\t
    • \u6bcf\u4e2a\u5143\u97f3 'o' \u540e\u9762\u53ea\u80fd\u8ddf\u7740 'i' \u6216\u8005\u662f 'u'
    • \n\t
    • \u6bcf\u4e2a\u5143\u97f3 'u' \u540e\u9762\u53ea\u80fd\u8ddf\u7740 'a'
    • \n
    \n\n

    \u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u4f1a\u5f88\u5927\uff0c\u6240\u4ee5\u8bf7\u4f60\u8fd4\u56de \u6a21 10^9 + 7 \u4e4b\u540e\u7684\u7ed3\u679c\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u6240\u6709\u53ef\u80fd\u7684\u5b57\u7b26\u4e32\u5206\u522b\u662f\uff1a"a", "e", "i" , "o" \u548c "u"\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1an = 2\n\u8f93\u51fa\uff1a10\n\u89e3\u91ca\uff1a\u6240\u6709\u53ef\u80fd\u7684\u5b57\u7b26\u4e32\u5206\u522b\u662f\uff1a"ae", "ea", "ei", "ia", "ie", "io", "iu", "oi", "ou" \u548c "ua"\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1an = 5\n\u8f93\u51fa\uff1a68
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 2 * 10^4
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countVowelPermutation(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countVowelPermutation(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countVowelPermutation(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countVowelPermutation(self, n: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countVowelPermutation(int n){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountVowelPermutation(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar countVowelPermutation = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef count_vowel_permutation(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countVowelPermutation(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countVowelPermutation(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countVowelPermutation(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countVowelPermutation(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_vowel_permutation(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function countVowelPermutation($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countVowelPermutation(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-vowel-permutation n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1220](https://leetcode-cn.com/problems/count-vowels-permutation)", "[\u7edf\u8ba1\u5143\u97f3\u5b57\u6bcd\u5e8f\u5217\u7684\u6570\u76ee](/solution/1200-1299/1220.Count%20Vowels%20Permutation/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1220](https://leetcode.com/problems/count-vowels-permutation)", "[Count Vowels Permutation](/solution/1200-1299/1220.Count%20Vowels%20Permutation/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1331", "frontend_question_id": "1219", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/path-with-maximum-gold", "url_en": "https://leetcode.com/problems/path-with-maximum-gold", "relative_path_cn": "/solution/1200-1299/1219.Path%20with%20Maximum%20Gold/README.md", "relative_path_en": "/solution/1200-1299/1219.Path%20with%20Maximum%20Gold/README_EN.md", "title_cn": "\u9ec4\u91d1\u77ff\u5de5", "title_en": "Path with Maximum Gold", "question_title_slug": "path-with-maximum-gold", "content_en": "

    In a gold mine grid of size m x n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.

    \n\n

    Return the maximum amount of gold you can collect under the conditions:

    \n\n
      \n\t
    • Every time you are located in a cell you will collect all the gold in that cell.
    • \n\t
    • From your position, you can walk one step to the left, right, up, or down.
    • \n\t
    • You can't visit the same cell more than once.
    • \n\t
    • Never visit a cell with 0 gold.
    • \n\t
    • You can start and stop collecting gold from any position in the grid that has some gold.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: grid = [[0,6,0],[5,8,7],[0,9,0]]\nOutput: 24\nExplanation:\n[[0,6,0],\n [5,8,7],\n [0,9,0]]\nPath to get the maximum gold, 9 -> 8 -> 7.\n
    \n\n

    Example 2:

    \n\n
    \nInput: grid = [[1,0,7],[2,0,6],[3,4,5],[0,3,0],[9,0,20]]\nOutput: 28\nExplanation:\n[[1,0,7],\n [2,0,6],\n [3,4,5],\n [0,3,0],\n [9,0,20]]\nPath to get the maximum gold, 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= m, n <= 15
    • \n\t
    • 0 <= grid[i][j] <= 100
    • \n\t
    • There are at most 25 cells containing gold.
    • \n
    \n", "content_cn": "

    \u4f60\u8981\u5f00\u53d1\u4e00\u5ea7\u91d1\u77ff\uff0c\u5730\u8d28\u52d8\u6d4b\u5b66\u5bb6\u5df2\u7ecf\u63a2\u660e\u4e86\u8fd9\u5ea7\u91d1\u77ff\u4e2d\u7684\u8d44\u6e90\u5206\u5e03\uff0c\u5e76\u7528\u5927\u5c0f\u4e3a m * n \u7684\u7f51\u683c grid \u8fdb\u884c\u4e86\u6807\u6ce8\u3002\u6bcf\u4e2a\u5355\u5143\u683c\u4e2d\u7684\u6574\u6570\u5c31\u8868\u793a\u8fd9\u4e00\u5355\u5143\u683c\u4e2d\u7684\u9ec4\u91d1\u6570\u91cf\uff1b\u5982\u679c\u8be5\u5355\u5143\u683c\u662f\u7a7a\u7684\uff0c\u90a3\u4e48\u5c31\u662f 0\u3002

    \n\n

    \u4e3a\u4e86\u4f7f\u6536\u76ca\u6700\u5927\u5316\uff0c\u77ff\u5de5\u9700\u8981\u6309\u4ee5\u4e0b\u89c4\u5219\u6765\u5f00\u91c7\u9ec4\u91d1\uff1a

    \n\n
      \n\t
    • \u6bcf\u5f53\u77ff\u5de5\u8fdb\u5165\u4e00\u4e2a\u5355\u5143\uff0c\u5c31\u4f1a\u6536\u96c6\u8be5\u5355\u5143\u683c\u4e2d\u7684\u6240\u6709\u9ec4\u91d1\u3002
    • \n\t
    • \u77ff\u5de5\u6bcf\u6b21\u53ef\u4ee5\u4ece\u5f53\u524d\u4f4d\u7f6e\u5411\u4e0a\u4e0b\u5de6\u53f3\u56db\u4e2a\u65b9\u5411\u8d70\u3002
    • \n\t
    • \u6bcf\u4e2a\u5355\u5143\u683c\u53ea\u80fd\u88ab\u5f00\u91c7\uff08\u8fdb\u5165\uff09\u4e00\u6b21\u3002
    • \n\t
    • \u4e0d\u5f97\u5f00\u91c7\uff08\u8fdb\u5165\uff09\u9ec4\u91d1\u6570\u76ee\u4e3a 0 \u7684\u5355\u5143\u683c\u3002
    • \n\t
    • \u77ff\u5de5\u53ef\u4ee5\u4ece\u7f51\u683c\u4e2d \u4efb\u610f\u4e00\u4e2a \u6709\u9ec4\u91d1\u7684\u5355\u5143\u683c\u51fa\u53d1\u6216\u8005\u662f\u505c\u6b62\u3002
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1agrid = [[0,6,0],[5,8,7],[0,9,0]]\n\u8f93\u51fa\uff1a24\n\u89e3\u91ca\uff1a\n[[0,6,0],\n [5,8,7],\n [0,9,0]]\n\u4e00\u79cd\u6536\u96c6\u6700\u591a\u9ec4\u91d1\u7684\u8def\u7ebf\u662f\uff1a9 -> 8 -> 7\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1agrid = [[1,0,7],[2,0,6],[3,4,5],[0,3,0],[9,0,20]]\n\u8f93\u51fa\uff1a28\n\u89e3\u91ca\uff1a\n[[1,0,7],\n [2,0,6],\n [3,4,5],\n [0,3,0],\n [9,0,20]]\n\u4e00\u79cd\u6536\u96c6\u6700\u591a\u9ec4\u91d1\u7684\u8def\u7ebf\u662f\uff1a1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= grid.length, grid[i].length <= 15
    • \n\t
    • 0 <= grid[i][j] <= 100
    • \n\t
    • \u6700\u591a 25 \u4e2a\u5355\u5143\u683c\u4e2d\u6709\u9ec4\u91d1\u3002
    • \n
    \n", "tags_en": ["Backtracking"], "tags_cn": ["\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int getMaximumGold(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int getMaximumGold(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getMaximumGold(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getMaximumGold(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint getMaximumGold(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int GetMaximumGold(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar getMaximumGold = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef get_maximum_gold(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getMaximumGold(_ grid: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getMaximumGold(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getMaximumGold(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getMaximumGold(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_maximum_gold(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function getMaximumGold($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getMaximumGold(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-maximum-gold grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1219](https://leetcode-cn.com/problems/path-with-maximum-gold)", "[\u9ec4\u91d1\u77ff\u5de5](/solution/1200-1299/1219.Path%20with%20Maximum%20Gold/README.md)", "`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1219](https://leetcode.com/problems/path-with-maximum-gold)", "[Path with Maximum Gold](/solution/1200-1299/1219.Path%20with%20Maximum%20Gold/README_EN.md)", "`Backtracking`", "Medium", ""]}, {"question_id": "1330", "frontend_question_id": "1218", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-arithmetic-subsequence-of-given-difference", "url_en": "https://leetcode.com/problems/longest-arithmetic-subsequence-of-given-difference", "relative_path_cn": "/solution/1200-1299/1218.Longest%20Arithmetic%20Subsequence%20of%20Given%20Difference/README.md", "relative_path_en": "/solution/1200-1299/1218.Longest%20Arithmetic%20Subsequence%20of%20Given%20Difference/README_EN.md", "title_cn": "\u6700\u957f\u5b9a\u5dee\u5b50\u5e8f\u5217", "title_en": "Longest Arithmetic Subsequence of Given Difference", "question_title_slug": "longest-arithmetic-subsequence-of-given-difference", "content_en": "

    Given an integer array arr and an integer difference, return the length of the longest subsequence in arr which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals difference.

    \r\n\r\n

    A subsequence is a sequence that can be derived from arr by deleting some or no elements without changing the order of the remaining elements.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: arr = [1,2,3,4], difference = 1\r\nOutput: 4\r\nExplanation: The longest arithmetic subsequence is [1,2,3,4].
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: arr = [1,3,5,7], difference = 1\r\nOutput: 1\r\nExplanation: The longest arithmetic subsequence is any single element.\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: arr = [1,5,7,8,5,3,4,2,1], difference = -2\r\nOutput: 4\r\nExplanation: The longest arithmetic subsequence is [7,5,3,1].\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= arr.length <= 105
    • \r\n\t
    • -104 <= arr[i], difference <= 104
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0arr\u00a0\u548c\u4e00\u4e2a\u6574\u6570\u00a0difference\uff0c\u8bf7\u4f60\u627e\u51fa\u5e76\u8fd4\u56de arr\u00a0\u4e2d\u6700\u957f\u7b49\u5dee\u5b50\u5e8f\u5217\u7684\u957f\u5ea6\uff0c\u8be5\u5b50\u5e8f\u5217\u4e2d\u76f8\u90bb\u5143\u7d20\u4e4b\u95f4\u7684\u5dee\u7b49\u4e8e difference \u3002

    \n\n

    \u5b50\u5e8f\u5217 \u662f\u6307\u5728\u4e0d\u6539\u53d8\u5176\u4f59\u5143\u7d20\u987a\u5e8f\u7684\u60c5\u51b5\u4e0b\uff0c\u901a\u8fc7\u5220\u9664\u4e00\u4e9b\u5143\u7d20\u6216\u4e0d\u5220\u9664\u4efb\u4f55\u5143\u7d20\u800c\u4ece arr \u6d3e\u751f\u51fa\u6765\u7684\u5e8f\u5217\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [1,2,3,4], difference = 1\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u6700\u957f\u7684\u7b49\u5dee\u5b50\u5e8f\u5217\u662f [1,2,3,4]\u3002
    \n\n

    \u793a\u4f8b\u00a02\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [1,3,5,7], difference = 1\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u6700\u957f\u7684\u7b49\u5dee\u5b50\u5e8f\u5217\u662f\u4efb\u610f\u5355\u4e2a\u5143\u7d20\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [1,5,7,8,5,3,4,2,1], difference = -2\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u6700\u957f\u7684\u7b49\u5dee\u5b50\u5e8f\u5217\u662f [7,5,3,1]\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= arr.length <= 105
    • \n\t
    • -104 <= arr[i], difference <= 104
    • \n
    \n", "tags_en": ["Hash Table", "Math", "Dynamic Programming"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u6570\u5b66", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int longestSubsequence(vector& arr, int difference) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int longestSubsequence(int[] arr, int difference) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestSubsequence(self, arr, difference):\n \"\"\"\n :type arr: List[int]\n :type difference: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestSubsequence(self, arr: List[int], difference: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint longestSubsequence(int* arr, int arrSize, int difference){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LongestSubsequence(int[] arr, int difference) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @param {number} difference\n * @return {number}\n */\nvar longestSubsequence = function(arr, difference) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @param {Integer} difference\n# @return {Integer}\ndef longest_subsequence(arr, difference)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestSubsequence(_ arr: [Int], _ difference: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestSubsequence(arr []int, difference int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestSubsequence(arr: Array[Int], difference: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestSubsequence(arr: IntArray, difference: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_subsequence(arr: Vec, difference: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @param Integer $difference\n * @return Integer\n */\n function longestSubsequence($arr, $difference) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestSubsequence(arr: number[], difference: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-subsequence arr difference)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1218](https://leetcode-cn.com/problems/longest-arithmetic-subsequence-of-given-difference)", "[\u6700\u957f\u5b9a\u5dee\u5b50\u5e8f\u5217](/solution/1200-1299/1218.Longest%20Arithmetic%20Subsequence%20of%20Given%20Difference/README.md)", "`\u54c8\u5e0c\u8868`,`\u6570\u5b66`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1218](https://leetcode.com/problems/longest-arithmetic-subsequence-of-given-difference)", "[Longest Arithmetic Subsequence of Given Difference](/solution/1200-1299/1218.Longest%20Arithmetic%20Subsequence%20of%20Given%20Difference/README_EN.md)", "`Hash Table`,`Math`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "1329", "frontend_question_id": "1217", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-cost-to-move-chips-to-the-same-position", "url_en": "https://leetcode.com/problems/minimum-cost-to-move-chips-to-the-same-position", "relative_path_cn": "/solution/1200-1299/1217.Minimum%20Cost%20to%20Move%20Chips%20to%20The%20Same%20Position/README.md", "relative_path_en": "/solution/1200-1299/1217.Minimum%20Cost%20to%20Move%20Chips%20to%20The%20Same%20Position/README_EN.md", "title_cn": "\u73a9\u7b79\u7801", "title_en": "Minimum Cost to Move Chips to The Same Position", "question_title_slug": "minimum-cost-to-move-chips-to-the-same-position", "content_en": "

    We have n chips, where the position of the ith chip is position[i].

    \n\n

    We need to move all the chips to the same position. In one step, we can change the position of the ith chip from position[i] to:

    \n\n
      \n\t
    • position[i] + 2 or position[i] - 2 with cost = 0.
    • \n\t
    • position[i] + 1 or position[i] - 1 with cost = 1.
    • \n
    \n\n

    Return the minimum cost needed to move all the chips to the same position.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: position = [1,2,3]\nOutput: 1\nExplanation: First step: Move the chip at position 3 to position 1 with cost = 0.\nSecond step: Move the chip at position 2 to position 1 with cost = 1.\nTotal cost is 1.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: position = [2,2,2,3,3]\nOutput: 2\nExplanation: We can move the two chips at position  3 to position 2. Each move has cost = 1. The total cost = 2.\n
    \n\n

    Example 3:

    \n\n
    \nInput: position = [1,1000000000]\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= position.length <= 100
    • \n\t
    • 1 <= position[i] <= 10^9
    • \n
    \n", "content_cn": "

    \u6570\u8f74\u4e0a\u653e\u7f6e\u4e86\u4e00\u4e9b\u7b79\u7801\uff0c\u6bcf\u4e2a\u7b79\u7801\u7684\u4f4d\u7f6e\u5b58\u5728\u6570\u7ec4 chips \u5f53\u4e2d\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u5bf9 \u4efb\u4f55\u7b79\u7801 \u6267\u884c\u4e0b\u9762\u4e24\u79cd\u64cd\u4f5c\u4e4b\u4e00\uff08\u4e0d\u9650\u64cd\u4f5c\u6b21\u6570\uff0c0 \u6b21\u4e5f\u53ef\u4ee5\uff09\uff1a

    \n\n
      \n\t
    • \u5c06\u7b2c i \u4e2a\u7b79\u7801\u5411\u5de6\u6216\u8005\u53f3\u79fb\u52a8 2 \u4e2a\u5355\u4f4d\uff0c\u4ee3\u4ef7\u4e3a 0\u3002
    • \n\t
    • \u5c06\u7b2c i \u4e2a\u7b79\u7801\u5411\u5de6\u6216\u8005\u53f3\u79fb\u52a8 1 \u4e2a\u5355\u4f4d\uff0c\u4ee3\u4ef7\u4e3a 1\u3002
    • \n
    \n\n

    \u6700\u5f00\u59cb\u7684\u65f6\u5019\uff0c\u540c\u4e00\u4f4d\u7f6e\u4e0a\u4e5f\u53ef\u80fd\u653e\u7740\u4e24\u4e2a\u6216\u8005\u66f4\u591a\u7684\u7b79\u7801\u3002

    \n\n

    \u8fd4\u56de\u5c06\u6240\u6709\u7b79\u7801\u79fb\u52a8\u5230\u540c\u4e00\u4f4d\u7f6e\uff08\u4efb\u610f\u4f4d\u7f6e\uff09\u4e0a\u6240\u9700\u8981\u7684\u6700\u5c0f\u4ee3\u4ef7\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1achips = [1,2,3]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u7b2c\u4e8c\u4e2a\u7b79\u7801\u79fb\u52a8\u5230\u4f4d\u7f6e\u4e09\u7684\u4ee3\u4ef7\u662f 1\uff0c\u7b2c\u4e00\u4e2a\u7b79\u7801\u79fb\u52a8\u5230\u4f4d\u7f6e\u4e09\u7684\u4ee3\u4ef7\u662f 0\uff0c\u603b\u4ee3\u4ef7\u4e3a 1\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1achips = [2,2,2,3,3]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u7b2c\u56db\u548c\u7b2c\u4e94\u4e2a\u7b79\u7801\u79fb\u52a8\u5230\u4f4d\u7f6e\u4e8c\u7684\u4ee3\u4ef7\u90fd\u662f 1\uff0c\u6240\u4ee5\u6700\u5c0f\u603b\u4ee3\u4ef7\u4e3a 2\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= chips.length <= 100
    • \n\t
    • 1 <= chips[i] <= 10^9
    • \n
    \n", "tags_en": ["Greedy", "Array", "Math"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u7ec4", "\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minCostToMoveChips(vector& position) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minCostToMoveChips(int[] position) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minCostToMoveChips(self, position):\n \"\"\"\n :type position: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minCostToMoveChips(self, position: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minCostToMoveChips(int* position, int positionSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinCostToMoveChips(int[] position) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} position\n * @return {number}\n */\nvar minCostToMoveChips = function(position) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} position\n# @return {Integer}\ndef min_cost_to_move_chips(position)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minCostToMoveChips(_ position: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minCostToMoveChips(position []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minCostToMoveChips(position: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minCostToMoveChips(position: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_cost_to_move_chips(position: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $position\n * @return Integer\n */\n function minCostToMoveChips($position) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minCostToMoveChips(position: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-cost-to-move-chips position)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1217](https://leetcode-cn.com/problems/minimum-cost-to-move-chips-to-the-same-position)", "[\u73a9\u7b79\u7801](/solution/1200-1299/1217.Minimum%20Cost%20to%20Move%20Chips%20to%20The%20Same%20Position/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u7ec4`,`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[1217](https://leetcode.com/problems/minimum-cost-to-move-chips-to-the-same-position)", "[Minimum Cost to Move Chips to The Same Position](/solution/1200-1299/1217.Minimum%20Cost%20to%20Move%20Chips%20to%20The%20Same%20Position/README_EN.md)", "`Greedy`,`Array`,`Math`", "Easy", ""]}, {"question_id": "1328", "frontend_question_id": "1205", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/monthly-transactions-ii", "url_en": "https://leetcode.com/problems/monthly-transactions-ii", "relative_path_cn": "/solution/1200-1299/1205.Monthly%20Transactions%20II/README.md", "relative_path_en": "/solution/1200-1299/1205.Monthly%20Transactions%20II/README_EN.md", "title_cn": "\u6bcf\u6708\u4ea4\u6613II", "title_en": "Monthly Transactions II", "question_title_slug": "monthly-transactions-ii", "content_en": "

    Table: Transactions

    \n\n
    \n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| id             | int     |\n| country        | varchar |\n| state          | enum    |\n| amount         | int     |\n| trans_date     | date    |\n+----------------+---------+\nid is the primary key of this table.\nThe table has information about incoming transactions.\nThe state column is an enum of type ["approved", "declined"].\n
    \n\n

    Table: Chargebacks

    \n\n
    \n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| trans_id       | int     |\n| trans_date     | date    |\n+----------------+---------+\nChargebacks contains basic information regarding incoming chargebacks from some transactions placed in Transactions table.\ntrans_id is a foreign key to the id column of Transactions table.\nEach chargeback corresponds to a transaction made previously even if they were not approved.
    \n\n

     

    \n\n

    Write an SQL query to find for each month and country: the number of approved transactions and their total amount, the number of chargebacks, and their total amount.

    \n\n

    Note: In your query, given the month and country, ignore rows with all zeros.

    \n\n

    The query result format is in the following example:

    \n\n

     

    \n\n
    \nTransactions table:\n+-----+---------+----------+--------+------------+\n| id  | country | state    | amount | trans_date |\n+-----+---------+----------+--------+------------+\n| 101 | US      | approved | 1000   | 2019-05-18 |\n| 102 | US      | declined | 2000   | 2019-05-19 |\n| 103 | US      | approved | 3000   | 2019-06-10 |\n| 104 | US      | declined | 4000   | 2019-06-13 |\n| 105 | US      | approved | 5000   | 2019-06-15 |\n+-----+---------+----------+--------+------------+\n\nChargebacks table:\n+----------+------------+\n| trans_id | trans_date |\n+----------+------------+\n| 102      | 2019-05-29 |\n| 101      | 2019-06-30 |\n| 105      | 2019-09-18 |\n+----------+------------+\n\nResult table:\n+---------+---------+----------------+-----------------+------------------+-------------------+\n| month   | country | approved_count | approved_amount | chargeback_count | chargeback_amount |\n+---------+---------+----------------+-----------------+------------------+-------------------+\n| 2019-05 | US      | 1              | 1000            | 1                | 2000              |\n| 2019-06 | US      | 2              | 8000            | 1                | 1000              |\n| 2019-09 | US      | 0              | 0               | 1                | 5000              |\n+---------+---------+----------------+-----------------+------------------+-------------------+\n\n
    \n", "content_cn": "

    Transactions \u8bb0\u5f55\u8868

    \n\n
    +----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| id             | int     |\n| country        | varchar |\n| state          | enum    |\n| amount         | int     |\n| trans_date     | date    |\n+----------------+---------+\nid \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\u3002\n\u8be5\u8868\u5305\u542b\u6709\u5173\u4f20\u5165\u4e8b\u52a1\u7684\u4fe1\u606f\u3002\n\u72b6\u6001\u5217\u662f\u7c7b\u578b\u4e3a [approved\uff08\u5df2\u6279\u51c6\uff09\u3001declined\uff08\u5df2\u62d2\u7edd\uff09] \u7684\u679a\u4e3e\u3002
    \n\n

     

    \n\n

    Chargebacks \u8868

    \n\n
    +----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| trans_id       | int     |\n| charge_date    | date    |\n+----------------+---------+\n\u9000\u5355\u5305\u542b\u6709\u5173\u653e\u7f6e\u5728\u4e8b\u52a1\u8868\u4e2d\u7684\u67d0\u4e9b\u4e8b\u52a1\u7684\u4f20\u5165\u9000\u5355\u7684\u57fa\u672c\u4fe1\u606f\u3002\ntrans_id \u662f transactions \u8868\u7684 id \u5217\u7684\u5916\u952e\u3002\n\u6bcf\u9879\u9000\u5355\u90fd\u5bf9\u5e94\u4e8e\u4e4b\u524d\u8fdb\u884c\u7684\u4ea4\u6613\uff0c\u5373\u4f7f\u672a\u7ecf\u6279\u51c6\u3002
    \n\n

     

    \n\n

    \u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\uff0c\u4ee5\u67e5\u627e\u6bcf\u4e2a\u6708\u548c\u6bcf\u4e2a\u56fd\u5bb6/\u5730\u533a\u7684\u5df2\u6279\u51c6\u4ea4\u6613\u7684\u6570\u91cf\u53ca\u5176\u603b\u91d1\u989d\u3001\u9000\u5355\u7684\u6570\u91cf\u53ca\u5176\u603b\u91d1\u989d\u3002

    \n\n

    \u6ce8\u610f\uff1a\u5728\u60a8\u7684\u67e5\u8be2\u4e2d\uff0c\u7ed9\u5b9a\u6708\u4efd\u548c\u56fd\u5bb6\uff0c\u5ffd\u7565\u6240\u6709\u4e3a\u96f6\u7684\u884c\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u6240\u793a\uff1a

    \n\n
    Transactions \u8868\uff1a\n+------+---------+----------+--------+------------+\n| id   | country | state    | amount | trans_date |\n+------+---------+----------+--------+------------+\n| 101  | US      | approved | 1000   | 2019-05-18 |\n| 102  | US      | declined | 2000   | 2019-05-19 |\n| 103  | US      | approved | 3000   | 2019-06-10 |\n| 104  | US      | declined | 4000   | 2019-06-13 |\n| 105  | US      | approved | 5000   | 2019-06-15 |\n+------+---------+----------+--------+------------+\n\nChargebacks \u8868\uff1a\n+------------+------------+\n| trans_id   | trans_date |\n+------------+------------+\n| 102        | 2019-05-29 |\n| 101        | 2019-06-30 |\n| 105        | 2019-09-18 |\n+------------+------------+\n\nResult \u8868\uff1a\n+----------+---------+----------------+-----------------+-------------------+--------------------+\n| month    | country | approved_count | approved_amount | chargeback_count  | chargeback_amount  |\n+----------+---------+----------------+-----------------+-------------------+--------------------+\n| 2019-05  | US      | 1              | 1000            | 1                 | 2000               |\n| 2019-06  | US      | 2              | 8000            | 1                 | 1000               |\n| 2019-09  | US      | 0              | 0               | 1                 | 5000               |\n+----------+---------+----------------+-----------------+-------------------+--------------------+\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1205](https://leetcode-cn.com/problems/monthly-transactions-ii)", "[\u6bcf\u6708\u4ea4\u6613II](/solution/1200-1299/1205.Monthly%20Transactions%20II/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1205](https://leetcode.com/problems/monthly-transactions-ii)", "[Monthly Transactions II](/solution/1200-1299/1205.Monthly%20Transactions%20II/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1327", "frontend_question_id": "1204", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/last-person-to-fit-in-the-elevator", "url_en": "https://leetcode.com/problems/last-person-to-fit-in-the-elevator", "relative_path_cn": "/solution/1200-1299/1204.Last%20Person%20to%20Fit%20in%20the%20Elevator/README.md", "relative_path_en": "/solution/1200-1299/1204.Last%20Person%20to%20Fit%20in%20the%20Elevator/README_EN.md", "title_cn": "\u6700\u540e\u4e00\u4e2a\u80fd\u8fdb\u5165\u7535\u68af\u7684\u4eba", "title_en": "Last Person to Fit in the Elevator", "question_title_slug": "last-person-to-fit-in-the-elevator", "content_en": "

    Table: Queue

    \r\n\r\n
    \r\n+-------------+---------+\r\n| Column Name | Type    |\r\n+-------------+---------+\r\n| person_id   | int     |\r\n| person_name | varchar |\r\n| weight      | int     |\r\n| turn        | int     |\r\n+-------------+---------+\r\nperson_id is the primary key column for this table.\r\nThis table has the information about all people waiting for an elevator.\r\nThe person_id and turn columns will contain all numbers from 1 to n, where n is the number of rows in the table.\r\n
    \r\n\r\n

     

    \r\n\r\n

    The maximum weight the elevator can hold is 1000.

    \r\n\r\n

    Write an SQL query to find the person_name of the last person who will fit in the elevator without exceeding the weight limit. It is guaranteed that the person who is first in the queue can fit in the elevator.

    \r\n\r\n

    The query result format is in the following example:

    \r\n\r\n
    \r\nQueue table\r\n+-----------+-------------------+--------+------+\r\n| person_id | person_name       | weight | turn |\r\n+-----------+-------------------+--------+------+\r\n| 5         | George Washington | 250    | 1    |\r\n| 3         | John Adams        | 350    | 2    |\r\n| 6         | Thomas Jefferson  | 400    | 3    |\r\n| 2         | Will Johnliams    | 200    | 4    |\r\n| 4         | Thomas Jefferson  | 175    | 5    |\r\n| 1         | James Elephant    | 500    | 6    |\r\n+-----------+-------------------+--------+------+\r\n\r\nResult table\r\n+-------------------+\r\n| person_name       |\r\n+-------------------+\r\n| Thomas Jefferson  |\r\n+-------------------+\r\n\r\nQueue table is ordered by turn in the example for simplicity.\r\nIn the example George Washington(id 5), John Adams(id 3) and Thomas Jefferson(id 6) will enter the elevator as their weight sum is 250 + 350 + 400 = 1000.\r\nThomas Jefferson(id 6) is the last person to fit in the elevator because he has the last turn in these three people.\r\n
    \r\n", "content_cn": "

    \u8868: Queue

    \n\n
    +-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| person_id   | int     |\n| person_name | varchar |\n| weight      | int     |\n| turn        | int     |\n+-------------+---------+\nperson_id \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\u3002\n\u8be5\u8868\u5c55\u793a\u4e86\u6240\u6709\u7b49\u5f85\u7535\u68af\u7684\u4eba\u7684\u4fe1\u606f\u3002\n\u8868\u4e2d person_id \u548c turn \u5217\u5c06\u5305\u542b\u4ece 1 \u5230 n \u7684\u6240\u6709\u6570\u5b57\uff0c\u5176\u4e2d n \u662f\u8868\u4e2d\u7684\u884c\u6570\u3002\n
    \n\n

     

    \n\n

    \u7535\u68af\u6700\u5927\u8f7d\u91cd\u91cf\u4e3a 1000\u3002

    \n\n

    \u5199\u4e00\u6761 SQL \u67e5\u8be2\u8bed\u53e5\u67e5\u627e\u6700\u540e\u4e00\u4e2a\u80fd\u8fdb\u5165\u7535\u68af\u4e14\u4e0d\u8d85\u8fc7\u91cd\u91cf\u9650\u5236\u7684 person_name \u3002\u9898\u76ee\u786e\u4fdd\u961f\u5217\u4e2d\u7b2c\u4e00\u4f4d\u7684\u4eba\u53ef\u4ee5\u8fdb\u5165\u7535\u68af \u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u5982\u4e0b\u6240\u793a :

    \n\n
    Queue \u8868\n+-----------+-------------------+--------+------+\n| person_id | person_name       | weight | turn |\n+-----------+-------------------+--------+------+\n| 5         | George Washington | 250    | 1    |\n| 3         | John Adams        | 350    | 2    |\n| 6         | Thomas Jefferson  | 400    | 3    |\n| 2         | Will Johnliams    | 200    | 4    |\n| 4         | Thomas Jefferson  | 175    | 5    |\n| 1         | James Elephant    | 500    | 6    |\n+-----------+-------------------+--------+------+\n\nResult \u8868\n+-------------------+\n| person_name       |\n+-------------------+\n| Thomas Jefferson  |\n+-------------------+\n\n\u4e3a\u4e86\u7b80\u5316\uff0cQueue \u8868\u6309 turn \u5217\u7531\u5c0f\u5230\u5927\u6392\u5e8f\u3002\n\u4e0a\u4f8b\u4e2d George Washington(id 5), John Adams(id 3) \u548c Thomas Jefferson(id 6) \u5c06\u53ef\u4ee5\u8fdb\u5165\u7535\u68af,\u56e0\u4e3a\u4ed6\u4eec\u7684\u4f53\u91cd\u548c\u4e3a 250 + 350 + 400 = 1000\u3002\nThomas Jefferson(id 6) \u662f\u6700\u540e\u4e00\u4e2a\u4f53\u91cd\u5408\u9002\u5e76\u8fdb\u5165\u7535\u68af\u7684\u4eba\u3002\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1204](https://leetcode-cn.com/problems/last-person-to-fit-in-the-elevator)", "[\u6700\u540e\u4e00\u4e2a\u80fd\u8fdb\u5165\u7535\u68af\u7684\u4eba](/solution/1200-1299/1204.Last%20Person%20to%20Fit%20in%20the%20Elevator/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1204](https://leetcode.com/problems/last-person-to-fit-in-the-elevator)", "[Last Person to Fit in the Elevator](/solution/1200-1299/1204.Last%20Person%20to%20Fit%20in%20the%20Elevator/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1326", "frontend_question_id": "1862", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sum-of-floored-pairs", "url_en": "https://leetcode.com/problems/sum-of-floored-pairs", "relative_path_cn": "/solution/1800-1899/1862.Sum%20of%20Floored%20Pairs/README.md", "relative_path_en": "/solution/1800-1899/1862.Sum%20of%20Floored%20Pairs/README_EN.md", "title_cn": "\u5411\u4e0b\u53d6\u6574\u6570\u5bf9\u548c", "title_en": "Sum of Floored Pairs", "question_title_slug": "sum-of-floored-pairs", "content_en": "

    Given an integer array nums, return the sum of floor(nums[i] / nums[j]) for all pairs of indices 0 <= i, j < nums.length in the array. Since the answer may be too large, return it modulo 109 + 7.

    \n\n

    The floor() function returns the integer part of the division.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [2,5,9]\nOutput: 10\nExplanation:\nfloor(2 / 5) = floor(2 / 9) = floor(5 / 9) = 0\nfloor(2 / 2) = floor(5 / 5) = floor(9 / 9) = 1\nfloor(5 / 2) = 2\nfloor(9 / 2) = 4\nfloor(9 / 5) = 1\nWe calculate the floor of the division for every pair of indices in the array then sum them up.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [7,7,7,7,7,7,7]\nOutput: 49\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • 1 <= nums[i] <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0nums\u00a0\uff0c\u8bf7\u4f60\u8fd4\u56de\u6240\u6709\u4e0b\u6807\u5bf9\u00a00 <= i, j < nums.length\u00a0\u7684\u00a0floor(nums[i] / nums[j])\u00a0\u7ed3\u679c\u4e4b\u548c\u3002\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u4f1a\u5f88\u5927\uff0c\u8bf7\u4f60\u8fd4\u56de\u7b54\u6848\u5bf9109 + 7\u00a0\u53d6\u4f59\u00a0\u7684\u7ed3\u679c\u3002

    \n\n

    \u51fd\u6570\u00a0floor()\u00a0\u8fd4\u56de\u8f93\u5165\u6570\u5b57\u7684\u6574\u6570\u90e8\u5206\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [2,5,9]\n\u8f93\u51fa\uff1a10\n\u89e3\u91ca\uff1a\nfloor(2 / 5) = floor(2 / 9) = floor(5 / 9) = 0\nfloor(2 / 2) = floor(5 / 5) = floor(9 / 9) = 1\nfloor(5 / 2) = 2\nfloor(9 / 2) = 4\nfloor(9 / 5) = 1\n\u6211\u4eec\u8ba1\u7b97\u6bcf\u4e00\u4e2a\u6570\u5bf9\u5546\u5411\u4e0b\u53d6\u6574\u7684\u7ed3\u679c\u5e76\u6c42\u548c\u5f97\u5230 10 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [7,7,7,7,7,7,7]\n\u8f93\u51fa\uff1a49\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • 1 <= nums[i] <= 105
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int sumOfFlooredPairs(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int sumOfFlooredPairs(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def sumOfFlooredPairs(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def sumOfFlooredPairs(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint sumOfFlooredPairs(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SumOfFlooredPairs(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar sumOfFlooredPairs = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef sum_of_floored_pairs(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func sumOfFlooredPairs(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func sumOfFlooredPairs(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def sumOfFlooredPairs(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun sumOfFlooredPairs(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sum_of_floored_pairs(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function sumOfFlooredPairs($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function sumOfFlooredPairs(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (sum-of-floored-pairs nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1862](https://leetcode-cn.com/problems/sum-of-floored-pairs)", "[\u5411\u4e0b\u53d6\u6574\u6570\u5bf9\u548c](/solution/1800-1899/1862.Sum%20of%20Floored%20Pairs/README.md)", "`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[1862](https://leetcode.com/problems/sum-of-floored-pairs)", "[Sum of Floored Pairs](/solution/1800-1899/1862.Sum%20of%20Floored%20Pairs/README_EN.md)", "`Math`", "Hard", ""]}, {"question_id": "1325", "frontend_question_id": "1514", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/path-with-maximum-probability", "url_en": "https://leetcode.com/problems/path-with-maximum-probability", "relative_path_cn": "/solution/1500-1599/1514.Path%20with%20Maximum%20Probability/README.md", "relative_path_en": "/solution/1500-1599/1514.Path%20with%20Maximum%20Probability/README_EN.md", "title_cn": "\u6982\u7387\u6700\u5927\u7684\u8def\u5f84", "title_en": "Path with Maximum Probability", "question_title_slug": "path-with-maximum-probability", "content_en": "

    You are given an undirected weighted graph of n nodes (0-indexed), represented by an edge list where edges[i] = [a, b] is an undirected edge connecting the nodes a and b with a probability of success of traversing that edge succProb[i].

    \r\n\r\n

    Given two nodes start and end, find the path with the maximum probability of success to go from start to end and return its success probability.

    \r\n\r\n

    If there is no path from start to end, return 0. Your answer will be accepted if it differs from the correct answer by at most 1e-5.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n

    \"\"

    \r\n\r\n
    \r\nInput: n = 3, edges = [[0,1],[1,2],[0,2]], succProb = [0.5,0.5,0.2], start = 0, end = 2\r\nOutput: 0.25000\r\nExplanation: There are two paths from start to end, one having a probability of success = 0.2 and the other has 0.5 * 0.5 = 0.25.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n

    \"\"

    \r\n\r\n
    \r\nInput: n = 3, edges = [[0,1],[1,2],[0,2]], succProb = [0.5,0.5,0.3], start = 0, end = 2\r\nOutput: 0.30000\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n

    \"\"

    \r\n\r\n
    \r\nInput: n = 3, edges = [[0,1]], succProb = [0.5], start = 0, end = 2\r\nOutput: 0.00000\r\nExplanation: There is no path between 0 and 2.\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 2 <= n <= 10^4
    • \r\n\t
    • 0 <= start, end < n
    • \r\n\t
    • start != end
    • \r\n\t
    • 0 <= a, b < n
    • \r\n\t
    • a != b
    • \r\n\t
    • 0 <= succProb.length == edges.length <= 2*10^4
    • \r\n\t
    • 0 <= succProb[i] <= 1
    • \r\n\t
    • There is at most one edge between every two nodes.
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u7531 n \u4e2a\u8282\u70b9\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\u7ec4\u6210\u7684\u65e0\u5411\u52a0\u6743\u56fe\uff0c\u8be5\u56fe\u7531\u4e00\u4e2a\u63cf\u8ff0\u8fb9\u7684\u5217\u8868\u7ec4\u6210\uff0c\u5176\u4e2d edges[i] = [a, b] \u8868\u793a\u8fde\u63a5\u8282\u70b9 a \u548c b \u7684\u4e00\u6761\u65e0\u5411\u8fb9\uff0c\u4e14\u8be5\u8fb9\u904d\u5386\u6210\u529f\u7684\u6982\u7387\u4e3a succProb[i] \u3002

    \n\n

    \u6307\u5b9a\u4e24\u4e2a\u8282\u70b9\u5206\u522b\u4f5c\u4e3a\u8d77\u70b9 start \u548c\u7ec8\u70b9 end \uff0c\u8bf7\u4f60\u627e\u51fa\u4ece\u8d77\u70b9\u5230\u7ec8\u70b9\u6210\u529f\u6982\u7387\u6700\u5927\u7684\u8def\u5f84\uff0c\u5e76\u8fd4\u56de\u5176\u6210\u529f\u6982\u7387\u3002

    \n\n

    \u5982\u679c\u4e0d\u5b58\u5728\u4ece start \u5230 end \u7684\u8def\u5f84\uff0c\u8bf7 \u8fd4\u56de 0 \u3002\u53ea\u8981\u7b54\u6848\u4e0e\u6807\u51c6\u7b54\u6848\u7684\u8bef\u5dee\u4e0d\u8d85\u8fc7 1e-5 \uff0c\u5c31\u4f1a\u88ab\u89c6\u4f5c\u6b63\u786e\u7b54\u6848\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 3, edges = [[0,1],[1,2],[0,2]], succProb = [0.5,0.5,0.2], start = 0, end = 2\n\u8f93\u51fa\uff1a0.25000\n\u89e3\u91ca\uff1a\u4ece\u8d77\u70b9\u5230\u7ec8\u70b9\u6709\u4e24\u6761\u8def\u5f84\uff0c\u5176\u4e2d\u4e00\u6761\u7684\u6210\u529f\u6982\u7387\u4e3a 0.2 \uff0c\u800c\u53e6\u4e00\u6761\u4e3a 0.5 * 0.5 = 0.25\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 3, edges = [[0,1],[1,2],[0,2]], succProb = [0.5,0.5,0.3], start = 0, end = 2\n\u8f93\u51fa\uff1a0.30000\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 3, edges = [[0,1]], succProb = [0.5], start = 0, end = 2\n\u8f93\u51fa\uff1a0.00000\n\u89e3\u91ca\uff1a\u8282\u70b9 0 \u548c \u8282\u70b9 2 \u4e4b\u95f4\u4e0d\u5b58\u5728\u8def\u5f84\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= n <= 10^4
    • \n\t
    • 0 <= start, end < n
    • \n\t
    • start != end
    • \n\t
    • 0 <= a, b < n
    • \n\t
    • a != b
    • \n\t
    • 0 <= succProb.length == edges.length <= 2*10^4
    • \n\t
    • 0 <= succProb[i] <= 1
    • \n\t
    • \u6bcf\u4e24\u4e2a\u8282\u70b9\u4e4b\u95f4\u6700\u591a\u6709\u4e00\u6761\u8fb9
    • \n
    \n", "tags_en": ["Graph"], "tags_cn": ["\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n double maxProbability(int n, vector>& edges, vector& succProb, int start, int end) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double maxProbability(int n, int[][] edges, double[] succProb, int start, int end) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxProbability(self, n, edges, succProb, start, end):\n \"\"\"\n :type n: int\n :type edges: List[List[int]]\n :type succProb: List[float]\n :type start: int\n :type end: int\n :rtype: float\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxProbability(self, n: int, edges: List[List[int]], succProb: List[float], start: int, end: int) -> float:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\ndouble maxProbability(int n, int** edges, int edgesSize, int* edgesColSize, double* succProb, int succProbSize, int start, int end){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double MaxProbability(int n, int[][] edges, double[] succProb, int start, int end) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} edges\n * @param {number[]} succProb\n * @param {number} start\n * @param {number} end\n * @return {number}\n */\nvar maxProbability = function(n, edges, succProb, start, end) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} edges\n# @param {Float[]} succ_prob\n# @param {Integer} start\n# @param {Integer} end\n# @return {Float}\ndef max_probability(n, edges, succ_prob, start, end)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxProbability(_ n: Int, _ edges: [[Int]], _ succProb: [Double], _ start: Int, _ end: Int) -> Double {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxProbability(n int, edges [][]int, succProb []float64, start int, end int) float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxProbability(n: Int, edges: Array[Array[Int]], succProb: Array[Double], start: Int, end: Int): Double = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxProbability(n: Int, edges: Array, succProb: DoubleArray, start: Int, end: Int): Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_probability(n: i32, edges: Vec>, succ_prob: Vec, start: i32, end: i32) -> f64 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $edges\n * @param Float[] $succProb\n * @param Integer $start\n * @param Integer $end\n * @return Float\n */\n function maxProbability($n, $edges, $succProb, $start, $end) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxProbability(n: number, edges: number[][], succProb: number[], start: number, end: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-probability n edges succProb start end)\n (-> exact-integer? (listof (listof exact-integer?)) (listof flonum?) exact-integer? exact-integer? flonum?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1514](https://leetcode-cn.com/problems/path-with-maximum-probability)", "[\u6982\u7387\u6700\u5927\u7684\u8def\u5f84](/solution/1500-1599/1514.Path%20with%20Maximum%20Probability/README.md)", "`\u56fe`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1514](https://leetcode.com/problems/path-with-maximum-probability)", "[Path with Maximum Probability](/solution/1500-1599/1514.Path%20with%20Maximum%20Probability/README_EN.md)", "`Graph`", "Medium", ""]}, {"question_id": "1324", "frontend_question_id": "1706", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/where-will-the-ball-fall", "url_en": "https://leetcode.com/problems/where-will-the-ball-fall", "relative_path_cn": "/solution/1700-1799/1706.Where%20Will%20the%20Ball%20Fall/README.md", "relative_path_en": "/solution/1700-1799/1706.Where%20Will%20the%20Ball%20Fall/README_EN.md", "title_cn": "\u7403\u4f1a\u843d\u4f55\u5904", "title_en": "Where Will the Ball Fall", "question_title_slug": "where-will-the-ball-fall", "content_en": "

    You have a 2-D grid of size m x n representing a box, and you have n balls. The box is open on the top and bottom sides.

    \n\n

    Each cell in the box has a diagonal board spanning two corners of the cell that can redirect a ball to the right or to the left.

    \n\n
      \n\t
    • A board that redirects the ball to the right spans the top-left corner to the bottom-right corner and is represented in the grid as 1.
    • \n\t
    • A board that redirects the ball to the left spans the top-right corner to the bottom-left corner and is represented in the grid as -1.
    • \n
    \n\n

    We drop one ball at the top of each column of the box. Each ball can get stuck in the box or fall out of the bottom. A ball gets stuck if it hits a "V" shaped pattern between two boards or if a board redirects the ball into either wall of the box.

    \n\n

    Return an array answer of size n where answer[i] is the column that the ball falls out of at the bottom after dropping the ball from the ith column at the top, or -1 if the ball gets stuck in the box.

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: grid = [[1,1,1,-1,-1],[1,1,1,-1,-1],[-1,-1,-1,1,1],[1,1,1,1,-1],[-1,-1,-1,-1,-1]]\nOutput: [1,-1,-1,-1,-1]\nExplanation: This example is shown in the photo.\nBall b0 is dropped at column 0 and falls out of the box at column 1.\nBall b1 is dropped at column 1 and will get stuck in the box between column 2 and 3 and row 1.\nBall b2 is dropped at column 2 and will get stuck on the box between column 2 and 3 and row 0.\nBall b3 is dropped at column 3 and will get stuck on the box between column 2 and 3 and row 0.\nBall b4 is dropped at column 4 and will get stuck on the box between column 2 and 3 and row 1.\n
    \n\n

    Example 2:

    \n\n
    \nInput: grid = [[-1]]\nOutput: [-1]\nExplanation: The ball gets stuck against the left wall.\n
    \n\n

    Example 3:

    \n\n
    \nInput: grid = [[1,1,1,1,1,1],[-1,-1,-1,-1,-1,-1],[1,1,1,1,1,1],[-1,-1,-1,-1,-1,-1]]\nOutput: [0,1,2,3,4,-1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= m, n <= 100
    • \n\t
    • grid[i][j] is 1 or -1.
    • \n
    \n", "content_cn": "

    \u7528\u4e00\u4e2a\u5927\u5c0f\u4e3a m x n \u7684\u4e8c\u7ef4\u7f51\u683c grid \u8868\u793a\u4e00\u4e2a\u7bb1\u5b50\u3002\u4f60\u6709 n \u9897\u7403\u3002\u7bb1\u5b50\u7684\u9876\u90e8\u548c\u5e95\u90e8\u90fd\u662f\u5f00\u7740\u7684\u3002

    \n\n

    \u7bb1\u5b50\u4e2d\u7684\u6bcf\u4e2a\u5355\u5143\u683c\u90fd\u6709\u4e00\u4e2a\u5bf9\u89d2\u7ebf\u6321\u677f\uff0c\u8de8\u8fc7\u5355\u5143\u683c\u7684\u4e24\u4e2a\u89d2\uff0c\u53ef\u4ee5\u5c06\u7403\u5bfc\u5411\u5de6\u4fa7\u6216\u8005\u53f3\u4fa7\u3002

    \n\n
      \n\t
    • \u5c06\u7403\u5bfc\u5411\u53f3\u4fa7\u7684\u6321\u677f\u8de8\u8fc7\u5de6\u4e0a\u89d2\u548c\u53f3\u4e0b\u89d2\uff0c\u5728\u7f51\u683c\u4e2d\u7528 1 \u8868\u793a\u3002
    • \n\t
    • \u5c06\u7403\u5bfc\u5411\u5de6\u4fa7\u7684\u6321\u677f\u8de8\u8fc7\u53f3\u4e0a\u89d2\u548c\u5de6\u4e0b\u89d2\uff0c\u5728\u7f51\u683c\u4e2d\u7528 -1 \u8868\u793a\u3002
    • \n
    \n\n

    \u5728\u7bb1\u5b50\u6bcf\u4e00\u5217\u7684\u9876\u7aef\u5404\u653e\u4e00\u9897\u7403\u3002\u6bcf\u9897\u7403\u90fd\u53ef\u80fd\u5361\u5728\u7bb1\u5b50\u91cc\u6216\u4ece\u5e95\u90e8\u6389\u51fa\u6765\u3002\u5982\u679c\u7403\u6070\u597d\u5361\u5728\u4e24\u5757\u6321\u677f\u4e4b\u95f4\u7684 \"V\" \u5f62\u56fe\u6848\uff0c\u6216\u8005\u88ab\u4e00\u5757\u6321\u5bfc\u5411\u5230\u7bb1\u5b50\u7684\u4efb\u610f\u4e00\u4fa7\u8fb9\u4e0a\uff0c\u5c31\u4f1a\u5361\u4f4f\u3002

    \n\n

    \u8fd4\u56de\u4e00\u4e2a\u5927\u5c0f\u4e3a n \u7684\u6570\u7ec4 answer \uff0c\u5176\u4e2d answer[i] \u662f\u7403\u653e\u5728\u9876\u90e8\u7684\u7b2c i \u5217\u540e\u4ece\u5e95\u90e8\u6389\u51fa\u6765\u7684\u90a3\u4e00\u5217\u5bf9\u5e94\u7684\u4e0b\u6807\uff0c\u5982\u679c\u7403\u5361\u5728\u76d2\u5b50\u91cc\uff0c\u5219\u8fd4\u56de -1 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1agrid = [[1,1,1,-1,-1],[1,1,1,-1,-1],[-1,-1,-1,1,1],[1,1,1,1,-1],[-1,-1,-1,-1,-1]]\n\u8f93\u51fa\uff1a[1,-1,-1,-1,-1]\n\u89e3\u91ca\uff1a\u793a\u4f8b\u5982\u56fe\uff1a\nb0 \u7403\u5f00\u59cb\u653e\u5728\u7b2c 0 \u5217\u4e0a\uff0c\u6700\u7ec8\u4ece\u7bb1\u5b50\u5e95\u90e8\u7b2c 1 \u5217\u6389\u51fa\u3002\nb1 \u7403\u5f00\u59cb\u653e\u5728\u7b2c 1 \u5217\u4e0a\uff0c\u4f1a\u5361\u5728\u7b2c 2\u30013 \u5217\u548c\u7b2c 1 \u884c\u4e4b\u95f4\u7684 \"V\" \u5f62\u91cc\u3002\nb2 \u7403\u5f00\u59cb\u653e\u5728\u7b2c 2 \u5217\u4e0a\uff0c\u4f1a\u5361\u5728\u7b2c 2\u30013 \u5217\u548c\u7b2c 0 \u884c\u4e4b\u95f4\u7684 \"V\" \u5f62\u91cc\u3002\nb3 \u7403\u5f00\u59cb\u653e\u5728\u7b2c 3 \u5217\u4e0a\uff0c\u4f1a\u5361\u5728\u7b2c 2\u30013 \u5217\u548c\u7b2c 0 \u884c\u4e4b\u95f4\u7684 \"V\" \u5f62\u91cc\u3002\nb4 \u7403\u5f00\u59cb\u653e\u5728\u7b2c 4 \u5217\u4e0a\uff0c\u4f1a\u5361\u5728\u7b2c 2\u30013 \u5217\u548c\u7b2c 1 \u884c\u4e4b\u95f4\u7684 \"V\" \u5f62\u91cc\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1agrid = [[-1]]\n\u8f93\u51fa\uff1a[-1]\n\u89e3\u91ca\uff1a\u7403\u88ab\u5361\u5728\u7bb1\u5b50\u5de6\u4fa7\u8fb9\u4e0a\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1agrid = [[1,1,1,1,1,1],[-1,-1,-1,-1,-1,-1],[1,1,1,1,1,1],[-1,-1,-1,-1,-1,-1]]\n\u8f93\u51fa\uff1a[0,1,2,3,4,-1]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= m, n <= 100
    • \n\t
    • grid[i][j] \u4e3a 1 \u6216 -1
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findBall(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] findBall(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findBall(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findBall(self, grid: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* findBall(int** grid, int gridSize, int* gridColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] FindBall(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number[]}\n */\nvar findBall = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer[]}\ndef find_ball(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findBall(_ grid: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findBall(grid [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findBall(grid: Array[Array[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findBall(grid: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_ball(grid: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer[]\n */\n function findBall($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findBall(grid: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-ball grid)\n (-> (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1706](https://leetcode-cn.com/problems/where-will-the-ball-fall)", "[\u7403\u4f1a\u843d\u4f55\u5904](/solution/1700-1799/1706.Where%20Will%20the%20Ball%20Fall/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1706](https://leetcode.com/problems/where-will-the-ball-fall)", "[Where Will the Ball Fall](/solution/1700-1799/1706.Where%20Will%20the%20Ball%20Fall/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "1322", "frontend_question_id": "1210", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-moves-to-reach-target-with-rotations", "url_en": "https://leetcode.com/problems/minimum-moves-to-reach-target-with-rotations", "relative_path_cn": "/solution/1200-1299/1210.Minimum%20Moves%20to%20Reach%20Target%20with%20Rotations/README.md", "relative_path_en": "/solution/1200-1299/1210.Minimum%20Moves%20to%20Reach%20Target%20with%20Rotations/README_EN.md", "title_cn": "\u7a7f\u8fc7\u8ff7\u5bab\u7684\u6700\u5c11\u79fb\u52a8\u6b21\u6570", "title_en": "Minimum Moves to Reach Target with Rotations", "question_title_slug": "minimum-moves-to-reach-target-with-rotations", "content_en": "

    In an n*n grid, there is a snake that spans 2 cells and starts moving from the top left corner at (0, 0) and (0, 1). The grid has empty cells represented by zeros and blocked cells represented by ones. The snake wants to reach the lower right corner at (n-1, n-2) and (n-1, n-1).

    \n\n

    In one move the snake can:

    \n\n
      \n\t
    • Move one cell to the right if there are no blocked cells there. This move keeps the horizontal/vertical position of the snake as it is.
    • \n\t
    • Move down one cell if there are no blocked cells there. This move keeps the horizontal/vertical position of the snake as it is.
    • \n\t
    • Rotate clockwise if it's in a horizontal position and the two cells under it are both empty. In that case the snake moves from (r, c) and (r, c+1) to (r, c) and (r+1, c).
      \n\t\"\"
    • \n\t
    • Rotate counterclockwise if it's in a vertical position and the two cells to its right are both empty. In that case the snake moves from (r, c) and (r+1, c) to (r, c) and (r, c+1).
      \n\t\"\"
    • \n
    \n\n

    Return the minimum number of moves to reach the target.

    \n\n

    If there is no way to reach the target, return -1.

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: grid = [[0,0,0,0,0,1],\n               [1,1,0,0,1,0],\n               [0,0,0,0,1,1],\n               [0,0,1,0,1,0],\n               [0,1,1,0,0,0],\n               [0,1,1,0,0,0]]\nOutput: 11\nExplanation:\nOne possible solution is [right, right, rotate clockwise, right, down, down, down, down, rotate counterclockwise, right, down].\n
    \n\n

    Example 2:

    \n\n
    \nInput: grid = [[0,0,1,1,1,1],\n               [0,0,0,0,1,1],\n               [1,1,0,0,0,1],\n               [1,1,1,0,0,1],\n               [1,1,1,0,0,1],\n               [1,1,1,0,0,0]]\nOutput: 9\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= n <= 100
    • \n\t
    • 0 <= grid[i][j] <= 1
    • \n\t
    • It is guaranteed that the snake starts at empty cells.
    • \n
    \n", "content_cn": "

    \u4f60\u8fd8\u8bb0\u5f97\u90a3\u6761\u98ce\u9761\u5168\u7403\u7684\u8d2a\u5403\u86c7\u5417\uff1f

    \n\n

    \u6211\u4eec\u5728\u4e00\u4e2a n*n \u7684\u7f51\u683c\u4e0a\u6784\u5efa\u4e86\u65b0\u7684\u8ff7\u5bab\u5730\u56fe\uff0c\u86c7\u7684\u957f\u5ea6\u4e3a 2\uff0c\u4e5f\u5c31\u662f\u8bf4\u5b83\u4f1a\u5360\u53bb\u4e24\u4e2a\u5355\u5143\u683c\u3002\u86c7\u4f1a\u4ece\u5de6\u4e0a\u89d2\uff08(0, 0) \u548c (0, 1)\uff09\u5f00\u59cb\u79fb\u52a8\u3002\u6211\u4eec\u7528 0 \u8868\u793a\u7a7a\u5355\u5143\u683c\uff0c\u7528 1 \u8868\u793a\u969c\u788d\u7269\u3002\u86c7\u9700\u8981\u79fb\u52a8\u5230\u8ff7\u5bab\u7684\u53f3\u4e0b\u89d2\uff08(n-1, n-2) \u548c (n-1, n-1)\uff09\u3002

    \n\n

    \u6bcf\u6b21\u79fb\u52a8\uff0c\u86c7\u53ef\u4ee5\u8fd9\u6837\u8d70\uff1a

    \n\n
      \n\t
    • \u5982\u679c\u6ca1\u6709\u969c\u788d\uff0c\u5219\u5411\u53f3\u79fb\u52a8\u4e00\u4e2a\u5355\u5143\u683c\u3002\u5e76\u4ecd\u7136\u4fdd\u6301\u8eab\u4f53\u7684\u6c34\u5e73\uff0f\u7ad6\u76f4\u72b6\u6001\u3002
    • \n\t
    • \u5982\u679c\u6ca1\u6709\u969c\u788d\uff0c\u5219\u5411\u4e0b\u79fb\u52a8\u4e00\u4e2a\u5355\u5143\u683c\u3002\u5e76\u4ecd\u7136\u4fdd\u6301\u8eab\u4f53\u7684\u6c34\u5e73\uff0f\u7ad6\u76f4\u72b6\u6001\u3002
    • \n\t
    • \u5982\u679c\u5b83\u5904\u4e8e\u6c34\u5e73\u72b6\u6001\u5e76\u4e14\u5176\u4e0b\u9762\u7684\u4e24\u4e2a\u5355\u5143\u90fd\u662f\u7a7a\u7684\uff0c\u5c31\u987a\u65f6\u9488\u65cb\u8f6c 90 \u5ea6\u3002\u86c7\u4ece\uff08(r, c)\u3001(r, c+1)\uff09\u79fb\u52a8\u5230 \uff08(r, c)\u3001(r+1, c)\uff09\u3002
      \n\t\"\"
    • \n\t
    • \u5982\u679c\u5b83\u5904\u4e8e\u7ad6\u76f4\u72b6\u6001\u5e76\u4e14\u5176\u53f3\u9762\u7684\u4e24\u4e2a\u5355\u5143\u90fd\u662f\u7a7a\u7684\uff0c\u5c31\u9006\u65f6\u9488\u65cb\u8f6c 90 \u5ea6\u3002\u86c7\u4ece\uff08(r, c)\u3001(r+1, c)\uff09\u79fb\u52a8\u5230\uff08(r, c)\u3001(r, c+1)\uff09\u3002
      \n\t\"\"
    • \n
    \n\n

    \u8fd4\u56de\u86c7\u62b5\u8fbe\u76ee\u7684\u5730\u6240\u9700\u7684\u6700\u5c11\u79fb\u52a8\u6b21\u6570\u3002

    \n\n

    \u5982\u679c\u65e0\u6cd5\u5230\u8fbe\u76ee\u7684\u5730\uff0c\u8bf7\u8fd4\u56de -1\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1agrid = [[0,0,0,0,0,1],\n               [1,1,0,0,1,0],\n               [0,0,0,0,1,1],\n               [0,0,1,0,1,0],\n               [0,1,1,0,0,0],\n               [0,1,1,0,0,0]]\n\u8f93\u51fa\uff1a11\n\u89e3\u91ca\uff1a\n\u4e00\u79cd\u53ef\u80fd\u7684\u89e3\u51b3\u65b9\u6848\u662f [\u53f3, \u53f3, \u987a\u65f6\u9488\u65cb\u8f6c, \u53f3, \u4e0b, \u4e0b, \u4e0b, \u4e0b, \u9006\u65f6\u9488\u65cb\u8f6c, \u53f3, \u4e0b]\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1agrid = [[0,0,1,1,1,1],\n               [0,0,0,0,1,1],\n               [1,1,0,0,0,1],\n               [1,1,1,0,0,1],\n               [1,1,1,0,0,1],\n               [1,1,1,0,0,0]]\n\u8f93\u51fa\uff1a9\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= n <= 100
    • \n\t
    • 0 <= grid[i][j] <= 1
    • \n\t
    • \u86c7\u4fdd\u8bc1\u4ece\u7a7a\u5355\u5143\u683c\u5f00\u59cb\u51fa\u53d1\u3002
    • \n
    \n", "tags_en": ["Breadth-first Search"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minimumMoves(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minimumMoves(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimumMoves(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimumMoves(self, grid: List[List[int]]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minimumMoves(int** grid, int gridSize, int* gridColSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinimumMoves(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar minimumMoves = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef minimum_moves(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimumMoves(_ grid: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimumMoves(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimumMoves(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimumMoves(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimum_moves(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function minimumMoves($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimumMoves(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimum-moves grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1210](https://leetcode-cn.com/problems/minimum-moves-to-reach-target-with-rotations)", "[\u7a7f\u8fc7\u8ff7\u5bab\u7684\u6700\u5c11\u79fb\u52a8\u6b21\u6570](/solution/1200-1299/1210.Minimum%20Moves%20to%20Reach%20Target%20with%20Rotations/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[1210](https://leetcode.com/problems/minimum-moves-to-reach-target-with-rotations)", "[Minimum Moves to Reach Target with Rotations](/solution/1200-1299/1210.Minimum%20Moves%20to%20Reach%20Target%20with%20Rotations/README_EN.md)", "`Breadth-first Search`", "Hard", ""]}, {"question_id": "1321", "frontend_question_id": "1208", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/get-equal-substrings-within-budget", "url_en": "https://leetcode.com/problems/get-equal-substrings-within-budget", "relative_path_cn": "/solution/1200-1299/1208.Get%20Equal%20Substrings%20Within%20Budget/README.md", "relative_path_en": "/solution/1200-1299/1208.Get%20Equal%20Substrings%20Within%20Budget/README_EN.md", "title_cn": "\u5c3d\u53ef\u80fd\u4f7f\u5b57\u7b26\u4e32\u76f8\u7b49", "title_en": "Get Equal Substrings Within Budget", "question_title_slug": "get-equal-substrings-within-budget", "content_en": "

    You are given two strings s and t of the same length. You want to change s to t. Changing the i-th character of s to i-th character of t costs |s[i] - t[i]| that is, the absolute difference between the ASCII values of the characters.

    \n\n

    You are also given an integer maxCost.

    \n\n

    Return the maximum length of a substring of s that can be changed to be the same as the corresponding substring of twith a cost less than or equal to maxCost.

    \n\n

    If there is no substring from s that can be changed to its corresponding substring from t, return 0.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "abcd", t = "bcdf", maxCost = 3\nOutput: 3\nExplanation: "abc" of s can change to "bcd". That costs 3, so the maximum length is 3.
    \n\n

    Example 2:

    \n\n
    \nInput: s = "abcd", t = "cdef", maxCost = 3\nOutput: 1\nExplanation: Each character in s costs 2 to change to charactor in t, so the maximum length is 1.\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "abcd", t = "acde", maxCost = 0\nOutput: 1\nExplanation: You can't make any change, so the maximum length is 1.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length, t.length <= 10^5
    • \n\t
    • 0 <= maxCost <= 10^6
    • \n\t
    • s and t only contain lower case English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u957f\u5ea6\u76f8\u540c\u7684\u5b57\u7b26\u4e32\uff0cs \u548c t\u3002

    \n\n

    \u5c06 s\u00a0\u4e2d\u7684\u7b2c\u00a0i\u00a0\u4e2a\u5b57\u7b26\u53d8\u5230\u00a0t\u00a0\u4e2d\u7684\u7b2c i \u4e2a\u5b57\u7b26\u9700\u8981\u00a0|s[i] - t[i]|\u00a0\u7684\u5f00\u9500\uff08\u5f00\u9500\u53ef\u80fd\u4e3a 0\uff09\uff0c\u4e5f\u5c31\u662f\u4e24\u4e2a\u5b57\u7b26\u7684 ASCII \u7801\u503c\u7684\u5dee\u7684\u7edd\u5bf9\u503c\u3002

    \n\n

    \u7528\u4e8e\u53d8\u66f4\u5b57\u7b26\u4e32\u7684\u6700\u5927\u9884\u7b97\u662f\u00a0maxCost\u3002\u5728\u8f6c\u5316\u5b57\u7b26\u4e32\u65f6\uff0c\u603b\u5f00\u9500\u5e94\u5f53\u5c0f\u4e8e\u7b49\u4e8e\u8be5\u9884\u7b97\uff0c\u8fd9\u4e5f\u610f\u5473\u7740\u5b57\u7b26\u4e32\u7684\u8f6c\u5316\u53ef\u80fd\u662f\u4e0d\u5b8c\u5168\u7684\u3002

    \n\n

    \u5982\u679c\u4f60\u53ef\u4ee5\u5c06 s \u7684\u5b50\u5b57\u7b26\u4e32\u8f6c\u5316\u4e3a\u5b83\u5728 t \u4e2d\u5bf9\u5e94\u7684\u5b50\u5b57\u7b26\u4e32\uff0c\u5219\u8fd4\u56de\u53ef\u4ee5\u8f6c\u5316\u7684\u6700\u5927\u957f\u5ea6\u3002

    \n\n

    \u5982\u679c s \u4e2d\u6ca1\u6709\u5b50\u5b57\u7b26\u4e32\u53ef\u4ee5\u8f6c\u5316\u6210 t \u4e2d\u5bf9\u5e94\u7684\u5b50\u5b57\u7b26\u4e32\uff0c\u5219\u8fd4\u56de 0\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"abcd\", t = \"bcdf\", maxCost = 3\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1as \u4e2d\u7684 \"abc\" \u53ef\u4ee5\u53d8\u4e3a \"bcd\"\u3002\u5f00\u9500\u4e3a 3\uff0c\u6240\u4ee5\u6700\u5927\u957f\u5ea6\u4e3a 3\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"abcd\", t = \"cdef\", maxCost = 3\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1as \u4e2d\u7684\u4efb\u4e00\u5b57\u7b26\u8981\u60f3\u53d8\u6210 t \u4e2d\u5bf9\u5e94\u7684\u5b57\u7b26\uff0c\u5176\u5f00\u9500\u90fd\u662f 2\u3002\u56e0\u6b64\uff0c\u6700\u5927\u957f\u5ea6\u4e3a 1\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"abcd\", t = \"acde\", maxCost = 0\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1aa -> a, cost = 0\uff0c\u5b57\u7b26\u4e32\u672a\u53d1\u751f\u53d8\u5316\uff0c\u6240\u4ee5\u6700\u5927\u957f\u5ea6\u4e3a 1\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length, t.length <= 10^5
    • \n\t
    • 0 <= maxCost <= 10^6
    • \n\t
    • s \u548c\u00a0t\u00a0\u90fd\u53ea\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    • \n
    \n", "tags_en": ["Array", "Sliding Window"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int equalSubstring(string s, string t, int maxCost) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int equalSubstring(String s, String t, int maxCost) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def equalSubstring(self, s, t, maxCost):\n \"\"\"\n :type s: str\n :type t: str\n :type maxCost: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def equalSubstring(self, s: str, t: str, maxCost: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint equalSubstring(char * s, char * t, int maxCost){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int EqualSubstring(string s, string t, int maxCost) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string} t\n * @param {number} maxCost\n * @return {number}\n */\nvar equalSubstring = function(s, t, maxCost) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String} t\n# @param {Integer} max_cost\n# @return {Integer}\ndef equal_substring(s, t, max_cost)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func equalSubstring(_ s: String, _ t: String, _ maxCost: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func equalSubstring(s string, t string, maxCost int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def equalSubstring(s: String, t: String, maxCost: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun equalSubstring(s: String, t: String, maxCost: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn equal_substring(s: String, t: String, max_cost: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String $t\n * @param Integer $maxCost\n * @return Integer\n */\n function equalSubstring($s, $t, $maxCost) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function equalSubstring(s: string, t: string, maxCost: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (equal-substring s t maxCost)\n (-> string? string? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1208](https://leetcode-cn.com/problems/get-equal-substrings-within-budget)", "[\u5c3d\u53ef\u80fd\u4f7f\u5b57\u7b26\u4e32\u76f8\u7b49](/solution/1200-1299/1208.Get%20Equal%20Substrings%20Within%20Budget/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1208](https://leetcode.com/problems/get-equal-substrings-within-budget)", "[Get Equal Substrings Within Budget](/solution/1200-1299/1208.Get%20Equal%20Substrings%20Within%20Budget/README_EN.md)", "`Array`,`Sliding Window`", "Medium", ""]}, {"question_id": "1320", "frontend_question_id": "1209", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string-ii", "url_en": "https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string-ii", "relative_path_cn": "/solution/1200-1299/1209.Remove%20All%20Adjacent%20Duplicates%20in%20String%20II/README.md", "relative_path_en": "/solution/1200-1299/1209.Remove%20All%20Adjacent%20Duplicates%20in%20String%20II/README_EN.md", "title_cn": "\u5220\u9664\u5b57\u7b26\u4e32\u4e2d\u7684\u6240\u6709\u76f8\u90bb\u91cd\u590d\u9879 II", "title_en": "Remove All Adjacent Duplicates in String II", "question_title_slug": "remove-all-adjacent-duplicates-in-string-ii", "content_en": "

    You are given a string s and an integer k, a k duplicate removal consists of choosing k adjacent and equal letters from s and removing them, causing the left and the right side of the deleted substring to concatenate together.

    \n\n

    We repeatedly make k duplicate removals on s until we no longer can.

    \n\n

    Return the final string after all such duplicate removals have been made. It is guaranteed that the answer is unique.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "abcd", k = 2\nOutput: "abcd"\nExplanation: There's nothing to delete.
    \n\n

    Example 2:

    \n\n
    \nInput: s = "deeedbbcccbdaa", k = 3\nOutput: "aa"\nExplanation: \nFirst delete "eee" and "ccc", get "ddbbbdaa"\nThen delete "bbb", get "dddaa"\nFinally delete "ddd", get "aa"
    \n\n

    Example 3:

    \n\n
    \nInput: s = "pbbcggttciiippooaais", k = 2\nOutput: "ps"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 105
    • \n\t
    • 2 <= k <= 104
    • \n\t
    • s only contains lower case English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s\uff0c\u300ck \u500d\u91cd\u590d\u9879\u5220\u9664\u64cd\u4f5c\u300d\u5c06\u4f1a\u4ece s \u4e2d\u9009\u62e9 k \u4e2a\u76f8\u90bb\u4e14\u76f8\u7b49\u7684\u5b57\u6bcd\uff0c\u5e76\u5220\u9664\u5b83\u4eec\uff0c\u4f7f\u88ab\u5220\u53bb\u7684\u5b57\u7b26\u4e32\u7684\u5de6\u4fa7\u548c\u53f3\u4fa7\u8fde\u5728\u4e00\u8d77\u3002

    \n\n

    \u4f60\u9700\u8981\u5bf9 s \u91cd\u590d\u8fdb\u884c\u65e0\u9650\u6b21\u8fd9\u6837\u7684\u5220\u9664\u64cd\u4f5c\uff0c\u76f4\u5230\u65e0\u6cd5\u7ee7\u7eed\u4e3a\u6b62\u3002

    \n\n

    \u5728\u6267\u884c\u5b8c\u6240\u6709\u5220\u9664\u64cd\u4f5c\u540e\uff0c\u8fd4\u56de\u6700\u7ec8\u5f97\u5230\u7684\u5b57\u7b26\u4e32\u3002

    \n\n

    \u672c\u9898\u7b54\u6848\u4fdd\u8bc1\u552f\u4e00\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1as = "abcd", k = 2\n\u8f93\u51fa\uff1a"abcd"\n\u89e3\u91ca\uff1a\u6ca1\u6709\u8981\u5220\u9664\u7684\u5185\u5bb9\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1as = "deeedbbcccbdaa", k = 3\n\u8f93\u51fa\uff1a"aa"\n\u89e3\u91ca\uff1a \n\u5148\u5220\u9664 "eee" \u548c "ccc"\uff0c\u5f97\u5230 "ddbbbdaa"\n\u518d\u5220\u9664 "bbb"\uff0c\u5f97\u5230 "dddaa"\n\u6700\u540e\u5220\u9664 "ddd"\uff0c\u5f97\u5230 "aa"
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1as = "pbbcggttciiippooaais", k = 2\n\u8f93\u51fa\uff1a"ps"\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 10^5
    • \n\t
    • 2 <= k <= 10^4
    • \n\t
    • s \u4e2d\u53ea\u542b\u6709\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    • \n
    \n", "tags_en": ["Stack"], "tags_cn": ["\u6808"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string removeDuplicates(string s, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String removeDuplicates(String s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def removeDuplicates(self, s, k):\n \"\"\"\n :type s: str\n :type k: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def removeDuplicates(self, s: str, k: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * removeDuplicates(char * s, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string RemoveDuplicates(string s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number} k\n * @return {string}\n */\nvar removeDuplicates = function(s, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer} k\n# @return {String}\ndef remove_duplicates(s, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func removeDuplicates(_ s: String, _ k: Int) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func removeDuplicates(s string, k int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def removeDuplicates(s: String, k: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun removeDuplicates(s: String, k: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn remove_duplicates(s: String, k: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer $k\n * @return String\n */\n function removeDuplicates($s, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function removeDuplicates(s: string, k: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (remove-duplicates s k)\n (-> string? exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1209](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string-ii)", "[\u5220\u9664\u5b57\u7b26\u4e32\u4e2d\u7684\u6240\u6709\u76f8\u90bb\u91cd\u590d\u9879 II](/solution/1200-1299/1209.Remove%20All%20Adjacent%20Duplicates%20in%20String%20II/README.md)", "`\u6808`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1209](https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string-ii)", "[Remove All Adjacent Duplicates in String II](/solution/1200-1299/1209.Remove%20All%20Adjacent%20Duplicates%20in%20String%20II/README_EN.md)", "`Stack`", "Medium", ""]}, {"question_id": "1319", "frontend_question_id": "1207", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/unique-number-of-occurrences", "url_en": "https://leetcode.com/problems/unique-number-of-occurrences", "relative_path_cn": "/solution/1200-1299/1207.Unique%20Number%20of%20Occurrences/README.md", "relative_path_en": "/solution/1200-1299/1207.Unique%20Number%20of%20Occurrences/README_EN.md", "title_cn": "\u72ec\u4e00\u65e0\u4e8c\u7684\u51fa\u73b0\u6b21\u6570", "title_en": "Unique Number of Occurrences", "question_title_slug": "unique-number-of-occurrences", "content_en": "

    Given an array of integers arr, write a function that returns true if and only if the number of occurrences of each value in the array is unique.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr = [1,2,2,1,1,3]\nOutput: true\nExplanation: The value 1 has 3 occurrences, 2 has 2 and 3 has 1. No two values have the same number of occurrences.
    \n\n

    Example 2:

    \n\n
    \nInput: arr = [1,2]\nOutput: false\n
    \n\n

    Example 3:

    \n\n
    \nInput: arr = [-3,0,1,-3,1,1,1,-3,10,0]\nOutput: true\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= arr.length <= 1000
    • \n\t
    • -1000 <= arr[i] <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr\uff0c\u8bf7\u4f60\u5e2e\u5fd9\u7edf\u8ba1\u6570\u7ec4\u4e2d\u6bcf\u4e2a\u6570\u7684\u51fa\u73b0\u6b21\u6570\u3002

    \n\n

    \u5982\u679c\u6bcf\u4e2a\u6570\u7684\u51fa\u73b0\u6b21\u6570\u90fd\u662f\u72ec\u4e00\u65e0\u4e8c\u7684\uff0c\u5c31\u8fd4\u56de true\uff1b\u5426\u5219\u8fd4\u56de false\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [1,2,2,1,1,3]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u5728\u8be5\u6570\u7ec4\u4e2d\uff0c1 \u51fa\u73b0\u4e86 3 \u6b21\uff0c2 \u51fa\u73b0\u4e86 2 \u6b21\uff0c3 \u53ea\u51fa\u73b0\u4e86 1 \u6b21\u3002\u6ca1\u6709\u4e24\u4e2a\u6570\u7684\u51fa\u73b0\u6b21\u6570\u76f8\u540c\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [1,2]\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [-3,0,1,-3,1,1,1,-3,10,0]\n\u8f93\u51fa\uff1atrue\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= arr.length <= 1000
    • \n\t
    • -1000 <= arr[i] <= 1000
    • \n
    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool uniqueOccurrences(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean uniqueOccurrences(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def uniqueOccurrences(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: bool\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def uniqueOccurrences(self, arr: List[int]) -> bool:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool uniqueOccurrences(int* arr, int arrSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool UniqueOccurrences(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {boolean}\n */\nvar uniqueOccurrences = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Boolean}\ndef unique_occurrences(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func uniqueOccurrences(_ arr: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func uniqueOccurrences(arr []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def uniqueOccurrences(arr: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun uniqueOccurrences(arr: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn unique_occurrences(arr: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Boolean\n */\n function uniqueOccurrences($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function uniqueOccurrences(arr: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (unique-occurrences arr)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1207](https://leetcode-cn.com/problems/unique-number-of-occurrences)", "[\u72ec\u4e00\u65e0\u4e8c\u7684\u51fa\u73b0\u6b21\u6570](/solution/1200-1299/1207.Unique%20Number%20of%20Occurrences/README.md)", "`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[1207](https://leetcode.com/problems/unique-number-of-occurrences)", "[Unique Number of Occurrences](/solution/1200-1299/1207.Unique%20Number%20of%20Occurrences/README_EN.md)", "`Hash Table`", "Easy", ""]}, {"question_id": "1318", "frontend_question_id": "1194", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/tournament-winners", "url_en": "https://leetcode.com/problems/tournament-winners", "relative_path_cn": "/solution/1100-1199/1194.Tournament%20Winners/README.md", "relative_path_en": "/solution/1100-1199/1194.Tournament%20Winners/README_EN.md", "title_cn": "\u9526\u6807\u8d5b\u4f18\u80dc\u8005", "title_en": "Tournament Winners", "question_title_slug": "tournament-winners", "content_en": "

    Table: Players

    \n\n
    \n+-------------+-------+\n| Column Name | Type  |\n+-------------+-------+\n| player_id   | int   |\n| group_id    | int   |\n+-------------+-------+\nplayer_id is the primary key of this table.\nEach row of this table indicates the group of each player.\n
    \n\n

    Table: Matches

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| match_id      | int     |\n| first_player  | int     |\n| second_player | int     | \n| first_score   | int     |\n| second_score  | int     |\n+---------------+---------+\nmatch_id is the primary key of this table.\nEach row is a record of a match, first_player and second_player contain the player_id of each match.\nfirst_score and second_score contain the number of points of the first_player and second_player respectively.\nYou may assume that, in each match, players belongs to the same group.\n
    \n\n

     

    \n\n

    The winner in each group is the player who scored the maximum total points within the group. In the case of a tie, the lowest player_id wins.

    \n\n

    Write an SQL query to find the winner in each group.

    \n\n

    The query result format is in the following example:

    \n\n
    \nPlayers table:\n+-----------+------------+\n| player_id | group_id   |\n+-----------+------------+\n| 15        | 1          |\n| 25        | 1          |\n| 30        | 1          |\n| 45        | 1          |\n| 10        | 2          |\n| 35        | 2          |\n| 50        | 2          |\n| 20        | 3          |\n| 40        | 3          |\n+-----------+------------+\n\nMatches table:\n+------------+--------------+---------------+-------------+--------------+\n| match_id   | first_player | second_player | first_score | second_score |\n+------------+--------------+---------------+-------------+--------------+\n| 1          | 15           | 45            | 3           | 0            |\n| 2          | 30           | 25            | 1           | 2            |\n| 3          | 30           | 15            | 2           | 0            |\n| 4          | 40           | 20            | 5           | 2            |\n| 5          | 35           | 50            | 1           | 1            |\n+------------+--------------+---------------+-------------+--------------+\n\nResult table:\n+-----------+------------+\n| group_id  | player_id  |\n+-----------+------------+ \n| 1         | 15         |\n| 2         | 35         |\n| 3         | 40         |\n+-----------+------------+\n
    \n", "content_cn": "

    Players\u00a0\u73a9\u5bb6\u8868

    \n\n
    \n+-------------+-------+\n| Column Name | Type  |\n+-------------+-------+\n| player_id   | int   |\n| group_id    | int   |\n+-------------+-------+\nplayer_id \u662f\u6b64\u8868\u7684\u4e3b\u952e\u3002\n\u6b64\u8868\u7684\u6bcf\u4e00\u884c\u8868\u793a\u6bcf\u4e2a\u73a9\u5bb6\u7684\u7ec4\u3002\n
    \n\n

    Matches\u00a0\u8d5b\u4e8b\u8868

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| match_id      | int     |\n| first_player  | int     |\n| second_player | int     | \n| first_score   | int     |\n| second_score  | int     |\n+---------------+---------+\nmatch_id \u662f\u6b64\u8868\u7684\u4e3b\u952e\u3002\n\u6bcf\u4e00\u884c\u662f\u4e00\u573a\u6bd4\u8d5b\u7684\u8bb0\u5f55\uff0cfirst_player \u548c second_player \u8868\u793a\u8be5\u573a\u6bd4\u8d5b\u7684\u7403\u5458 ID\u3002\nfirst_score \u548c second_score \u5206\u522b\u8868\u793a first_player \u548c second_player \u7684\u5f97\u5206\u3002\n\u4f60\u53ef\u4ee5\u5047\u8bbe\uff0c\u5728\u6bcf\u4e00\u573a\u6bd4\u8d5b\u4e2d\uff0c\u7403\u5458\u90fd\u5c5e\u4e8e\u540c\u4e00\u7ec4\u3002\n
    \n\n

    \u00a0

    \n\n

    \u6bcf\u7ec4\u7684\u83b7\u80dc\u8005\u662f\u5728\u7ec4\u5185\u7d2f\u79ef\u5f97\u5206\u6700\u9ad8\u7684\u9009\u624b\u3002\u5982\u679c\u5e73\u5c40\uff0cplayer_id \u6700\u5c0f\u00a0\u7684\u9009\u624b\u83b7\u80dc\u3002

    \n\n

    \u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\u6765\u67e5\u627e\u6bcf\u7ec4\u4e2d\u7684\u83b7\u80dc\u8005\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u6240\u793a

    \n\n
    \nPlayers \u8868:\n+-----------+------------+\n| player_id | group_id   |\n+-----------+------------+\n| 15        | 1          |\n| 25        | 1          |\n| 30        | 1          |\n| 45        | 1          |\n| 10        | 2          |\n| 35        | 2          |\n| 50        | 2          |\n| 20        | 3          |\n| 40        | 3          |\n+-----------+------------+\n\nMatches \u8868:\n+------------+--------------+---------------+-------------+--------------+\n| match_id   | first_player | second_player | first_score | second_score |\n+------------+--------------+---------------+-------------+--------------+\n| 1          | 15           | 45            | 3           | 0            |\n| 2          | 30           | 25            | 1           | 2            |\n| 3          | 30           | 15            | 2           | 0            |\n| 4          | 40           | 20            | 5           | 2            |\n| 5          | 35           | 50            | 1           | 1            |\n+------------+--------------+---------------+-------------+--------------+\n\nResult \u8868:\n+-----------+------------+\n| group_id  | player_id  |\n+-----------+------------+ \n| 1         | 15         |\n| 2         | 35         |\n| 3         | 40         |\n+-----------+------------+\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1194](https://leetcode-cn.com/problems/tournament-winners)", "[\u9526\u6807\u8d5b\u4f18\u80dc\u8005](/solution/1100-1199/1194.Tournament%20Winners/README.md)", "", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1194](https://leetcode.com/problems/tournament-winners)", "[Tournament Winners](/solution/1100-1199/1194.Tournament%20Winners/README_EN.md)", "", "Hard", "\ud83d\udd12"]}, {"question_id": "1317", "frontend_question_id": "1193", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/monthly-transactions-i", "url_en": "https://leetcode.com/problems/monthly-transactions-i", "relative_path_cn": "/solution/1100-1199/1193.Monthly%20Transactions%20I/README.md", "relative_path_en": "/solution/1100-1199/1193.Monthly%20Transactions%20I/README_EN.md", "title_cn": "\u6bcf\u6708\u4ea4\u6613 I", "title_en": "Monthly Transactions I", "question_title_slug": "monthly-transactions-i", "content_en": "

    Table: Transactions

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| country       | varchar |\n| state         | enum    |\n| amount        | int     |\n| trans_date    | date    |\n+---------------+---------+\nid is the primary key of this table.\nThe table has information about incoming transactions.\nThe state column is an enum of type ["approved", "declined"].\n
    \n\n

     

    \n\n

    Write an SQL query to find for each month and country, the number of transactions and their total amount, the number of approved transactions and their total amount.

    \n\n

    The query result format is in the following example:

    \n\n
    \nTransactions table:\n+------+---------+----------+--------+------------+\n| id   | country | state    | amount | trans_date |\n+------+---------+----------+--------+------------+\n| 121  | US      | approved | 1000   | 2018-12-18 |\n| 122  | US      | declined | 2000   | 2018-12-19 |\n| 123  | US      | approved | 2000   | 2019-01-01 |\n| 124  | DE      | approved | 2000   | 2019-01-07 |\n+------+---------+----------+--------+------------+\n\nResult table:\n+----------+---------+-------------+----------------+--------------------+-----------------------+\n| month    | country | trans_count | approved_count | trans_total_amount | approved_total_amount |\n+----------+---------+-------------+----------------+--------------------+-----------------------+\n| 2018-12  | US      | 2           | 1              | 3000               | 1000                  |\n| 2019-01  | US      | 1           | 1              | 2000               | 2000                  |\n| 2019-01  | DE      | 1           | 1              | 2000               | 2000                  |\n+----------+---------+-------------+----------------+--------------------+-----------------------+\n
    \n", "content_cn": "

    Table: Transactions

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| country       | varchar |\n| state         | enum    |\n| amount        | int     |\n| trans_date    | date    |\n+---------------+---------+\nid \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\u3002\n\u8be5\u8868\u5305\u542b\u6709\u5173\u4f20\u5165\u4e8b\u52a1\u7684\u4fe1\u606f\u3002\nstate \u5217\u7c7b\u578b\u4e3a “[”\u6279\u51c6“\uff0c”\u62d2\u7edd“] \u4e4b\u4e00\u3002\n
    \n\n

     

    \n\n

    \u7f16\u5199\u4e00\u4e2a sql \u67e5\u8be2\u6765\u67e5\u627e\u6bcf\u4e2a\u6708\u548c\u6bcf\u4e2a\u56fd\u5bb6/\u5730\u533a\u7684\u4e8b\u52a1\u6570\u53ca\u5176\u603b\u91d1\u989d\u3001\u5df2\u6279\u51c6\u7684\u4e8b\u52a1\u6570\u53ca\u5176\u603b\u91d1\u989d\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u6240\u793a\uff1a

    \n\n
    \nTransactions table:\n+------+---------+----------+--------+------------+\n| id   | country | state    | amount | trans_date |\n+------+---------+----------+--------+------------+\n| 121  | US      | approved | 1000   | 2018-12-18 |\n| 122  | US      | declined | 2000   | 2018-12-19 |\n| 123  | US      | approved | 2000   | 2019-01-01 |\n| 124  | DE      | approved | 2000   | 2019-01-07 |\n+------+---------+----------+--------+------------+\n\nResult table:\n+----------+---------+-------------+----------------+--------------------+-----------------------+\n| month    | country | trans_count | approved_count | trans_total_amount | approved_total_amount |\n+----------+---------+-------------+----------------+--------------------+-----------------------+\n| 2018-12  | US      | 2           | 1              | 3000               | 1000                  |\n| 2019-01  | US      | 1           | 1              | 2000               | 2000                  |\n| 2019-01  | DE      | 1           | 1              | 2000               | 2000                  |\n+----------+---------+-------------+----------------+--------------------+-----------------------+\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1193](https://leetcode-cn.com/problems/monthly-transactions-i)", "[\u6bcf\u6708\u4ea4\u6613 I](/solution/1100-1199/1193.Monthly%20Transactions%20I/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1193](https://leetcode.com/problems/monthly-transactions-i)", "[Monthly Transactions I](/solution/1100-1199/1193.Monthly%20Transactions%20I/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1316", "frontend_question_id": "1195", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/fizz-buzz-multithreaded", "url_en": "https://leetcode.com/problems/fizz-buzz-multithreaded", "relative_path_cn": "/solution/1100-1199/1195.Fizz%20Buzz%20Multithreaded/README.md", "relative_path_en": "/solution/1100-1199/1195.Fizz%20Buzz%20Multithreaded/README_EN.md", "title_cn": "\u4ea4\u66ff\u6253\u5370\u5b57\u7b26\u4e32", "title_en": "Fizz Buzz Multithreaded", "question_title_slug": "fizz-buzz-multithreaded", "content_en": "

    Write a program that outputs the string representation of numbers from 1 to n, however:

    \n\n
      \n\t
    • If the number is divisible by 3, output "fizz".
    • \n\t
    • If the number is divisible by 5, output "buzz".
    • \n\t
    • If the number is divisible by both 3 and 5, output "fizzbuzz".
    • \n
    \n\n

    For example, for n = 15, we output: 1, 2, fizz, 4, buzz, fizz, 7, 8, fizz, buzz, 11, fizz, 13, 14, fizzbuzz.

    \n\n

    Suppose you are given the following code:

    \n\n
    \nclass FizzBuzz {\n  public FizzBuzz(int n) { ... }               // constructor\n  public void fizz(printFizz) { ... }          // only output "fizz"\n  public void buzz(printBuzz) { ... }          // only output "buzz"\n  public void fizzbuzz(printFizzBuzz) { ... }  // only output "fizzbuzz"\n  public void number(printNumber) { ... }      // only output the numbers\n}
    \n\n

    Implement a multithreaded version of FizzBuzz with four threads. The same instance of FizzBuzz will be passed to four different threads:

    \n\n
      \n\t
    1. Thread A will call fizz() to check for divisibility of 3 and outputs fizz.
    2. \n\t
    3. Thread B will call buzz() to check for divisibility of 5 and outputs buzz.
    4. \n\t
    5. Thread C will call fizzbuzz() to check for divisibility of 3 and 5 and outputs fizzbuzz.
    6. \n\t
    7. Thread D will call number() which should only output the numbers.
    8. \n
    \n", "content_cn": "

    \u7f16\u5199\u4e00\u4e2a\u53ef\u4ee5\u4ece 1 \u5230 n \u8f93\u51fa\u4ee3\u8868\u8fd9\u4e2a\u6570\u5b57\u7684\u5b57\u7b26\u4e32\u7684\u7a0b\u5e8f\uff0c\u4f46\u662f\uff1a

    \n\n
      \n\t
    • \u5982\u679c\u8fd9\u4e2a\u6570\u5b57\u53ef\u4ee5\u88ab 3 \u6574\u9664\uff0c\u8f93\u51fa \"fizz\"\u3002
    • \n\t
    • \u5982\u679c\u8fd9\u4e2a\u6570\u5b57\u53ef\u4ee5\u88ab 5 \u6574\u9664\uff0c\u8f93\u51fa\u00a0\"buzz\"\u3002
    • \n\t
    • \u5982\u679c\u8fd9\u4e2a\u6570\u5b57\u53ef\u4ee5\u540c\u65f6\u88ab 3 \u548c 5 \u6574\u9664\uff0c\u8f93\u51fa \"fizzbuzz\"\u3002
    • \n
    \n\n

    \u4f8b\u5982\uff0c\u5f53\u00a0n = 15\uff0c\u8f93\u51fa\uff1a\u00a01, 2, fizz, 4, buzz, fizz, 7, 8, fizz, buzz, 11, fizz, 13, 14, fizzbuzz\u3002

    \n\n

    \u5047\u8bbe\u6709\u8fd9\u4e48\u4e00\u4e2a\u7c7b\uff1a

    \n\n
    \nclass FizzBuzz {\n\u00a0 public FizzBuzz(int n) { ... }\u00a0              // constructor\n  public void fizz(printFizz) { ... }          // only output \"fizz\"\n  public void buzz(printBuzz) { ... }          // only output \"buzz\"\n  public void fizzbuzz(printFizzBuzz) { ... }  // only output \"fizzbuzz\"\n  public void number(printNumber) { ... }      // only output the numbers\n}
    \n\n

    \u8bf7\u4f60\u5b9e\u73b0\u4e00\u4e2a\u6709\u56db\u4e2a\u7ebf\u7a0b\u7684\u591a\u7ebf\u7a0b\u7248\u00a0\u00a0FizzBuzz\uff0c\u00a0\u540c\u4e00\u4e2a\u00a0FizzBuzz\u00a0\u5b9e\u4f8b\u4f1a\u88ab\u5982\u4e0b\u56db\u4e2a\u7ebf\u7a0b\u4f7f\u7528\uff1a

    \n\n
      \n\t
    1. \u7ebf\u7a0bA\u5c06\u8c03\u7528\u00a0fizz()\u00a0\u6765\u5224\u65ad\u662f\u5426\u80fd\u88ab 3 \u6574\u9664\uff0c\u5982\u679c\u53ef\u4ee5\uff0c\u5219\u8f93\u51fa\u00a0fizz\u3002
    2. \n\t
    3. \u7ebf\u7a0bB\u5c06\u8c03\u7528\u00a0buzz()\u00a0\u6765\u5224\u65ad\u662f\u5426\u80fd\u88ab 5 \u6574\u9664\uff0c\u5982\u679c\u53ef\u4ee5\uff0c\u5219\u8f93\u51fa\u00a0buzz\u3002
    4. \n\t
    5. \u7ebf\u7a0bC\u5c06\u8c03\u7528\u00a0fizzbuzz()\u00a0\u6765\u5224\u65ad\u662f\u5426\u540c\u65f6\u80fd\u88ab 3 \u548c 5 \u6574\u9664\uff0c\u5982\u679c\u53ef\u4ee5\uff0c\u5219\u8f93\u51fa\u00a0fizzbuzz\u3002
    6. \n\t
    7. \u7ebf\u7a0bD\u5c06\u8c03\u7528\u00a0number()\u00a0\u6765\u5b9e\u73b0\u8f93\u51fa\u65e2\u4e0d\u80fd\u88ab 3 \u6574\u9664\u4e5f\u4e0d\u80fd\u88ab 5 \u6574\u9664\u7684\u6570\u5b57\u3002
    8. \n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u672c\u9898\u5df2\u7ecf\u63d0\u4f9b\u4e86\u6253\u5370\u5b57\u7b26\u4e32\u7684\u76f8\u5173\u65b9\u6cd5\uff0c\u5982 printFizz() \u7b49\uff0c\u5177\u4f53\u65b9\u6cd5\u540d\u8bf7\u53c2\u8003\u7b54\u9898\u6a21\u677f\u4e2d\u7684\u6ce8\u91ca\u90e8\u5206\u3002
    • \n
    \n\n

    \u00a0

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class FizzBuzz {\nprivate:\n int n;\n\npublic:\n FizzBuzz(int n) {\n this->n = n;\n }\n\n // printFizz() outputs \"fizz\".\n void fizz(function printFizz) {\n \n }\n\n // printBuzz() outputs \"buzz\".\n void buzz(function printBuzz) {\n \n }\n\n // printFizzBuzz() outputs \"fizzbuzz\".\n\tvoid fizzbuzz(function printFizzBuzz) {\n \n }\n\n // printNumber(x) outputs \"x\", where x is an integer.\n void number(function printNumber) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class FizzBuzz {\n private int n;\n\n public FizzBuzz(int n) {\n this.n = n;\n }\n\n // printFizz.run() outputs \"fizz\".\n public void fizz(Runnable printFizz) throws InterruptedException {\n \n }\n\n // printBuzz.run() outputs \"buzz\".\n public void buzz(Runnable printBuzz) throws InterruptedException {\n \n }\n\n // printFizzBuzz.run() outputs \"fizzbuzz\".\n public void fizzbuzz(Runnable printFizzBuzz) throws InterruptedException {\n \n }\n\n // printNumber.accept(x) outputs \"x\", where x is an integer.\n public void number(IntConsumer printNumber) throws InterruptedException {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class FizzBuzz(object):\n def __init__(self, n):\n self.n = n\n\n # printFizz() outputs \"fizz\"\n def fizz(self, printFizz):\n \"\"\"\n :type printFizz: method\n :rtype: void\n \"\"\"\n \t\n\n # printBuzz() outputs \"buzz\"\n def buzz(self, printBuzz):\n \"\"\"\n :type printBuzz: method\n :rtype: void\n \"\"\"\n \t\n\n # printFizzBuzz() outputs \"fizzbuzz\"\n def fizzbuzz(self, printFizzBuzz):\n \"\"\"\n :type printFizzBuzz: method\n :rtype: void\n \"\"\"\n \n\n # printNumber(x) outputs \"x\", where x is an integer.\n def number(self, printNumber):\n \"\"\"\n :type printNumber: method\n :rtype: void\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class FizzBuzz:\n def __init__(self, n: int):\n self.n = n\n\n # printFizz() outputs \"fizz\"\n def fizz(self, printFizz: 'Callable[[], None]') -> None:\n \t\n\n # printBuzz() outputs \"buzz\"\n def buzz(self, printBuzz: 'Callable[[], None]') -> None:\n \t\n\n # printFizzBuzz() outputs \"fizzbuzz\"\n def fizzbuzz(self, printFizzBuzz: 'Callable[[], None]') -> None:\n \n\n # printNumber(x) outputs \"x\", where x is an integer.\n def number(self, printNumber: 'Callable[[int], None]') -> None:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "typedef struct {\n int n;\n} FizzBuzz;\n\nFizzBuzz* fizzBuzzCreate(int n) {\n FizzBuzz* obj = (FizzBuzz*) malloc(sizeof(FizzBuzz));\n obj->n = n;\n return obj;\n}\n\n// printFizz() outputs \"fizz\".\nvoid fizz(FizzBuzz* obj) {\n \n}\n\n// printBuzz() outputs \"buzz\".\nvoid buzz(FizzBuzz* obj) {\n \n}\n\n// printFizzBuzz() outputs \"fizzbuzz\".\nvoid fizzbuzz(FizzBuzz* obj) {\n \n}\n\n// You may call global function `void printNumber(int x)`\n// to output \"x\", where x is an integer.\nvoid number(FizzBuzz* obj) {\n \n}\n\nvoid fizzBuzzFree(FizzBuzz* obj) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class FizzBuzz {\n private int n;\n\n public FizzBuzz(int n) {\n this.n = n;\n }\n\n // printFizz() outputs \"fizz\".\n public void Fizz(Action printFizz) {\n \n }\n\n // printBuzzz() outputs \"buzz\".\n public void Buzz(Action printBuzz) {\n \n }\n\n // printFizzBuzz() outputs \"fizzbuzz\".\n public void Fizzbuzz(Action printFizzBuzz) {\n \n }\n\n // printNumber(x) outputs \"x\", where x is an integer.\n public void Number(Action printNumber) {\n \n }\n}", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1195](https://leetcode-cn.com/problems/fizz-buzz-multithreaded)", "[\u4ea4\u66ff\u6253\u5370\u5b57\u7b26\u4e32](/solution/1100-1199/1195.Fizz%20Buzz%20Multithreaded/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1195](https://leetcode.com/problems/fizz-buzz-multithreaded)", "[Fizz Buzz Multithreaded](/solution/1100-1199/1195.Fizz%20Buzz%20Multithreaded/README_EN.md)", "", "Medium", ""]}, {"question_id": "1309", "frontend_question_id": "1203", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sort-items-by-groups-respecting-dependencies", "url_en": "https://leetcode.com/problems/sort-items-by-groups-respecting-dependencies", "relative_path_cn": "/solution/1200-1299/1203.Sort%20Items%20by%20Groups%20Respecting%20Dependencies/README.md", "relative_path_en": "/solution/1200-1299/1203.Sort%20Items%20by%20Groups%20Respecting%20Dependencies/README_EN.md", "title_cn": "\u9879\u76ee\u7ba1\u7406", "title_en": "Sort Items by Groups Respecting Dependencies", "question_title_slug": "sort-items-by-groups-respecting-dependencies", "content_en": "

    There are n items each belonging to zero or one of m groups where group[i] is the group that the i-th item belongs to and it's equal to -1 if the i-th item belongs to no group. The items and the groups are zero indexed. A group can have no item belonging to it.

    \n\n

    Return a sorted list of the items such that:

    \n\n
      \n\t
    • The items that belong to the same group are next to each other in the sorted list.
    • \n\t
    • There are some relations between these items where beforeItems[i] is a list containing all the items that should come before the i-th item in the sorted array (to the left of the i-th item).
    • \n
    \n\n

    Return any solution if there is more than one solution and return an empty list if there is no solution.

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: n = 8, m = 2, group = [-1,-1,1,0,0,1,0,-1], beforeItems = [[],[6],[5],[6],[3,6],[],[],[]]\nOutput: [6,3,4,1,5,2,0,7]\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 8, m = 2, group = [-1,-1,1,0,0,1,0,-1], beforeItems = [[],[6],[5],[6],[3],[],[4],[]]\nOutput: []\nExplanation: This is the same as example 1 except that 4 needs to be before 6 in the sorted list.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= m <= n <= 3 * 104
    • \n\t
    • group.length == beforeItems.length == n
    • \n\t
    • -1 <= group[i] <= m - 1
    • \n\t
    • 0 <= beforeItems[i].length <= n - 1
    • \n\t
    • 0 <= beforeItems[i][j] <= n - 1
    • \n\t
    • i != beforeItems[i][j]
    • \n\t
    • beforeItems[i] does not contain duplicates elements.
    • \n
    \n", "content_cn": "

    \u6709 n \u4e2a\u9879\u76ee\uff0c\u6bcf\u4e2a\u9879\u76ee\u6216\u8005\u4e0d\u5c5e\u4e8e\u4efb\u4f55\u5c0f\u7ec4\uff0c\u6216\u8005\u5c5e\u4e8e m \u4e2a\u5c0f\u7ec4\u4e4b\u4e00\u3002group[i] \u8868\u793a\u7b2c i \u4e2a\u9879\u76ee\u6240\u5c5e\u7684\u5c0f\u7ec4\uff0c\u5982\u679c\u7b2c i \u4e2a\u9879\u76ee\u4e0d\u5c5e\u4e8e\u4efb\u4f55\u5c0f\u7ec4\uff0c\u5219 group[i] \u7b49\u4e8e -1\u3002\u9879\u76ee\u548c\u5c0f\u7ec4\u90fd\u662f\u4ece\u96f6\u5f00\u59cb\u7f16\u53f7\u7684\u3002\u53ef\u80fd\u5b58\u5728\u5c0f\u7ec4\u4e0d\u8d1f\u8d23\u4efb\u4f55\u9879\u76ee\uff0c\u5373\u6ca1\u6709\u4efb\u4f55\u9879\u76ee\u5c5e\u4e8e\u8fd9\u4e2a\u5c0f\u7ec4\u3002

    \n\n

    \u8bf7\u4f60\u5e2e\u5fd9\u6309\u8981\u6c42\u5b89\u6392\u8fd9\u4e9b\u9879\u76ee\u7684\u8fdb\u5ea6\uff0c\u5e76\u8fd4\u56de\u6392\u5e8f\u540e\u7684\u9879\u76ee\u5217\u8868\uff1a

    \n\n
      \n\t
    • \u540c\u4e00\u5c0f\u7ec4\u7684\u9879\u76ee\uff0c\u6392\u5e8f\u540e\u5728\u5217\u8868\u4e2d\u5f7c\u6b64\u76f8\u90bb\u3002
    • \n\t
    • \u9879\u76ee\u4e4b\u95f4\u5b58\u5728\u4e00\u5b9a\u7684\u4f9d\u8d56\u5173\u7cfb\uff0c\u6211\u4eec\u7528\u4e00\u4e2a\u5217\u8868 beforeItems\u00a0\u6765\u8868\u793a\uff0c\u5176\u4e2d\u00a0beforeItems[i]\u00a0\u8868\u793a\u5728\u8fdb\u884c\u7b2c\u00a0i\u00a0\u4e2a\u9879\u76ee\u524d\uff08\u4f4d\u4e8e\u7b2c i\u00a0\u4e2a\u9879\u76ee\u5de6\u4fa7\uff09\u5e94\u8be5\u5b8c\u6210\u7684\u6240\u6709\u9879\u76ee\u3002
    • \n
    \n\n

    \u5982\u679c\u5b58\u5728\u591a\u4e2a\u89e3\u51b3\u65b9\u6848\uff0c\u53ea\u9700\u8981\u8fd4\u56de\u5176\u4e2d\u4efb\u610f\u4e00\u4e2a\u5373\u53ef\u3002\u5982\u679c\u6ca1\u6709\u5408\u9002\u7684\u89e3\u51b3\u65b9\u6848\uff0c\u5c31\u8bf7\u8fd4\u56de\u4e00\u4e2a \u7a7a\u5217\u8868 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1an = 8, m = 2, group = [-1,-1,1,0,0,1,0,-1], beforeItems = [[],[6],[5],[6],[3,6],[],[],[]]\n\u8f93\u51fa\uff1a[6,3,4,1,5,2,0,7]\n
    \n\n

    \u793a\u4f8b\u00a02\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 8, m = 2, group = [-1,-1,1,0,0,1,0,-1], beforeItems = [[],[6],[5],[6],[3],[],[4],[]]\n\u8f93\u51fa\uff1a[]\n\u89e3\u91ca\uff1a\u4e0e\u793a\u4f8b 1 \u5927\u81f4\u76f8\u540c\uff0c\u4f46\u662f\u5728\u6392\u5e8f\u540e\u7684\u5217\u8868\u4e2d\uff0c4 \u5fc5\u987b\u653e\u5728 6 \u7684\u524d\u9762\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= m <= n <= 3 * 104
    • \n\t
    • group.length == beforeItems.length == n
    • \n\t
    • -1 <= group[i] <= m - 1
    • \n\t
    • 0 <= beforeItems[i].length <= n - 1
    • \n\t
    • 0 <= beforeItems[i][j] <= n - 1
    • \n\t
    • i != beforeItems[i][j]
    • \n\t
    • beforeItems[i] \u4e0d\u542b\u91cd\u590d\u5143\u7d20
    • \n
    \n", "tags_en": ["Depth-first Search", "Graph", "Topological Sort"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u56fe", "\u62d3\u6251\u6392\u5e8f"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector sortItems(int n, int m, vector& group, vector>& beforeItems) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] sortItems(int n, int m, int[] group, List> beforeItems) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def sortItems(self, n, m, group, beforeItems):\n \"\"\"\n :type n: int\n :type m: int\n :type group: List[int]\n :type beforeItems: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def sortItems(self, n: int, m: int, group: List[int], beforeItems: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* sortItems(int n, int m, int* group, int groupSize, int** beforeItems, int beforeItemsSize, int* beforeItemsColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] SortItems(int n, int m, int[] group, IList> beforeItems) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} m\n * @param {number[]} group\n * @param {number[][]} beforeItems\n * @return {number[]}\n */\nvar sortItems = function(n, m, group, beforeItems) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} m\n# @param {Integer[]} group\n# @param {Integer[][]} before_items\n# @return {Integer[]}\ndef sort_items(n, m, group, before_items)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func sortItems(_ n: Int, _ m: Int, _ group: [Int], _ beforeItems: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func sortItems(n int, m int, group []int, beforeItems [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def sortItems(n: Int, m: Int, group: Array[Int], beforeItems: List[List[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun sortItems(n: Int, m: Int, group: IntArray, beforeItems: List>): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sort_items(n: i32, m: i32, group: Vec, before_items: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $m\n * @param Integer[] $group\n * @param Integer[][] $beforeItems\n * @return Integer[]\n */\n function sortItems($n, $m, $group, $beforeItems) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function sortItems(n: number, m: number, group: number[], beforeItems: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (sort-items n m group beforeItems)\n (-> exact-integer? exact-integer? (listof exact-integer?) (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1203](https://leetcode-cn.com/problems/sort-items-by-groups-respecting-dependencies)", "[\u9879\u76ee\u7ba1\u7406](/solution/1200-1299/1203.Sort%20Items%20by%20Groups%20Respecting%20Dependencies/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u56fe`,`\u62d3\u6251\u6392\u5e8f`", "\u56f0\u96be", ""], "md_table_row_en": ["[1203](https://leetcode.com/problems/sort-items-by-groups-respecting-dependencies)", "[Sort Items by Groups Respecting Dependencies](/solution/1200-1299/1203.Sort%20Items%20by%20Groups%20Respecting%20Dependencies/README_EN.md)", "`Depth-first Search`,`Graph`,`Topological Sort`", "Hard", ""]}, {"question_id": "1308", "frontend_question_id": "1202", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/smallest-string-with-swaps", "url_en": "https://leetcode.com/problems/smallest-string-with-swaps", "relative_path_cn": "/solution/1200-1299/1202.Smallest%20String%20With%20Swaps/README.md", "relative_path_en": "/solution/1200-1299/1202.Smallest%20String%20With%20Swaps/README_EN.md", "title_cn": "\u4ea4\u6362\u5b57\u7b26\u4e32\u4e2d\u7684\u5143\u7d20", "title_en": "Smallest String With Swaps", "question_title_slug": "smallest-string-with-swaps", "content_en": "

    You are given a string s, and an array of pairs of indices in the string pairs where pairs[i] = [a, b] indicates 2 indices(0-indexed) of the string.

    \n\n

    You can swap the characters at any pair of indices in the given pairs any number of times.

    \n\n

    Return the lexicographically smallest string that s can be changed to after using the swaps.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "dcab", pairs = [[0,3],[1,2]]\nOutput: "bacd"\nExplaination: \nSwap s[0] and s[3], s = "bcad"\nSwap s[1] and s[2], s = "bacd"\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "dcab", pairs = [[0,3],[1,2],[0,2]]\nOutput: "abcd"\nExplaination: \nSwap s[0] and s[3], s = "bcad"\nSwap s[0] and s[2], s = "acbd"\nSwap s[1] and s[2], s = "abcd"
    \n\n

    Example 3:

    \n\n
    \nInput: s = "cba", pairs = [[0,1],[1,2]]\nOutput: "abc"\nExplaination: \nSwap s[0] and s[1], s = "bca"\nSwap s[1] and s[2], s = "bac"\nSwap s[0] and s[1], s = "abc"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 10^5
    • \n\t
    • 0 <= pairs.length <= 10^5
    • \n\t
    • 0 <= pairs[i][0], pairs[i][1] < s.length
    • \n\t
    • s only contains lower case English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s\uff0c\u4ee5\u53ca\u8be5\u5b57\u7b26\u4e32\u4e2d\u7684\u4e00\u4e9b\u300c\u7d22\u5f15\u5bf9\u300d\u6570\u7ec4 pairs\uff0c\u5176\u4e2d pairs[i] = [a, b] \u8868\u793a\u5b57\u7b26\u4e32\u4e2d\u7684\u4e24\u4e2a\u7d22\u5f15\uff08\u7f16\u53f7\u4ece 0 \u5f00\u59cb\uff09\u3002

    \n\n

    \u4f60\u53ef\u4ee5 \u4efb\u610f\u591a\u6b21\u4ea4\u6362 \u5728 pairs \u4e2d\u4efb\u610f\u4e00\u5bf9\u7d22\u5f15\u5904\u7684\u5b57\u7b26\u3002

    \n\n

    \u8fd4\u56de\u5728\u7ecf\u8fc7\u82e5\u5e72\u6b21\u4ea4\u6362\u540e\uff0cs \u53ef\u4ee5\u53d8\u6210\u7684\u6309\u5b57\u5178\u5e8f\u6700\u5c0f\u7684\u5b57\u7b26\u4e32\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165\uff1as = "dcab", pairs = [[0,3],[1,2]]\n\u8f93\u51fa\uff1a"bacd"\n\u89e3\u91ca\uff1a \n\u4ea4\u6362 s[0] \u548c s[3], s = "bcad"\n\u4ea4\u6362 s[1] \u548c s[2], s = "bacd"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1as = "dcab", pairs = [[0,3],[1,2],[0,2]]\n\u8f93\u51fa\uff1a"abcd"\n\u89e3\u91ca\uff1a\n\u4ea4\u6362 s[0] \u548c s[3], s = "bcad"\n\u4ea4\u6362 s[0] \u548c s[2], s = "acbd"\n\u4ea4\u6362 s[1] \u548c s[2], s = "abcd"
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1as = "cba", pairs = [[0,1],[1,2]]\n\u8f93\u51fa\uff1a"abc"\n\u89e3\u91ca\uff1a\n\u4ea4\u6362 s[0] \u548c s[1], s = "bca"\n\u4ea4\u6362 s[1] \u548c s[2], s = "bac"\n\u4ea4\u6362 s[0] \u548c s[1], s = "abc"\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 10^5
    • \n\t
    • 0 <= pairs.length <= 10^5
    • \n\t
    • 0 <= pairs[i][0], pairs[i][1] < s.length
    • \n\t
    • s \u4e2d\u53ea\u542b\u6709\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd
    • \n
    \n", "tags_en": ["Union Find", "Array"], "tags_cn": ["\u5e76\u67e5\u96c6", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string smallestStringWithSwaps(string s, vector>& pairs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String smallestStringWithSwaps(String s, List> pairs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def smallestStringWithSwaps(self, s, pairs):\n \"\"\"\n :type s: str\n :type pairs: List[List[int]]\n :rtype: str\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def smallestStringWithSwaps(self, s: str, pairs: List[List[int]]) -> str:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * smallestStringWithSwaps(char * s, int** pairs, int pairsSize, int* pairsColSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string SmallestStringWithSwaps(string s, IList> pairs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number[][]} pairs\n * @return {string}\n */\nvar smallestStringWithSwaps = function(s, pairs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer[][]} pairs\n# @return {String}\ndef smallest_string_with_swaps(s, pairs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func smallestStringWithSwaps(_ s: String, _ pairs: [[Int]]) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func smallestStringWithSwaps(s string, pairs [][]int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def smallestStringWithSwaps(s: String, pairs: List[List[Int]]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun smallestStringWithSwaps(s: String, pairs: List>): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn smallest_string_with_swaps(s: String, pairs: Vec>) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer[][] $pairs\n * @return String\n */\n function smallestStringWithSwaps($s, $pairs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function smallestStringWithSwaps(s: string, pairs: number[][]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (smallest-string-with-swaps s pairs)\n (-> string? (listof (listof exact-integer?)) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1202](https://leetcode-cn.com/problems/smallest-string-with-swaps)", "[\u4ea4\u6362\u5b57\u7b26\u4e32\u4e2d\u7684\u5143\u7d20](/solution/1200-1299/1202.Smallest%20String%20With%20Swaps/README.md)", "`\u5e76\u67e5\u96c6`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1202](https://leetcode.com/problems/smallest-string-with-swaps)", "[Smallest String With Swaps](/solution/1200-1299/1202.Smallest%20String%20With%20Swaps/README_EN.md)", "`Union Find`,`Array`", "Medium", ""]}, {"question_id": "1307", "frontend_question_id": "1201", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/ugly-number-iii", "url_en": "https://leetcode.com/problems/ugly-number-iii", "relative_path_cn": "/solution/1200-1299/1201.Ugly%20Number%20III/README.md", "relative_path_en": "/solution/1200-1299/1201.Ugly%20Number%20III/README_EN.md", "title_cn": "\u4e11\u6570 III", "title_en": "Ugly Number III", "question_title_slug": "ugly-number-iii", "content_en": "

    An ugly number is a positive integer that is divisible by a, b, or c.

    \n\n

    Given four integers n, a, b, and c, return the nth ugly number.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 3, a = 2, b = 3, c = 5\nOutput: 4\nExplanation: The ugly numbers are 2, 3, 4, 5, 6, 8, 9, 10... The 3rd is 4.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 4, a = 2, b = 3, c = 4\nOutput: 6\nExplanation: The ugly numbers are 2, 3, 4, 6, 8, 9, 10, 12... The 4th is 6.\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 5, a = 2, b = 11, c = 13\nOutput: 10\nExplanation: The ugly numbers are 2, 4, 6, 8, 10, 11, 12, 13... The 5th is 10.\n
    \n\n

    Example 4:

    \n\n
    \nInput: n = 1000000000, a = 2, b = 217983653, c = 336916467\nOutput: 1999999984\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n, a, b, c <= 109
    • \n\t
    • 1 <= a * b * c <= 1018
    • \n\t
    • It is guaranteed that the result will be in range [1, 2 * 109].
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u56db\u4e2a\u6574\u6570\uff1an \u3001a \u3001b \u3001c \uff0c\u8bf7\u4f60\u8bbe\u8ba1\u4e00\u4e2a\u7b97\u6cd5\u6765\u627e\u51fa\u7b2c\u00a0n\u00a0\u4e2a\u4e11\u6570\u3002

    \n\n

    \u4e11\u6570\u662f\u53ef\u4ee5\u88ab\u00a0a\u00a0\u6216\u00a0b\u00a0\u6216 c\u00a0\u6574\u9664\u7684 \u6b63\u6574\u6570 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 3, a = 2, b = 3, c = 5\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u4e11\u6570\u5e8f\u5217\u4e3a 2, 3, 4, 5, 6, 8, 9, 10... \u5176\u4e2d\u7b2c 3 \u4e2a\u662f 4\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 4, a = 2, b = 3, c = 4\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u4e11\u6570\u5e8f\u5217\u4e3a 2, 3, 4, 6, 8, 9, 10, 12... \u5176\u4e2d\u7b2c 4 \u4e2a\u662f 6\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 5, a = 2, b = 11, c = 13\n\u8f93\u51fa\uff1a10\n\u89e3\u91ca\uff1a\u4e11\u6570\u5e8f\u5217\u4e3a 2, 4, 6, 8, 10, 11, 12, 13... \u5176\u4e2d\u7b2c 5 \u4e2a\u662f 10\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 1000000000, a = 2, b = 217983653, c = 336916467\n\u8f93\u51fa\uff1a1999999984\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n, a, b, c <= 10^9
    • \n\t
    • 1 <= a * b * c <= 10^18
    • \n\t
    • \u672c\u9898\u7ed3\u679c\u5728\u00a0[1,\u00a02 * 10^9]\u00a0\u7684\u8303\u56f4\u5185
    • \n
    \n", "tags_en": ["Math", "Binary Search"], "tags_cn": ["\u6570\u5b66", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int nthUglyNumber(int n, int a, int b, int c) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int nthUglyNumber(int n, int a, int b, int c) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def nthUglyNumber(self, n, a, b, c):\n \"\"\"\n :type n: int\n :type a: int\n :type b: int\n :type c: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def nthUglyNumber(self, n: int, a: int, b: int, c: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint nthUglyNumber(int n, int a, int b, int c){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NthUglyNumber(int n, int a, int b, int c) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} a\n * @param {number} b\n * @param {number} c\n * @return {number}\n */\nvar nthUglyNumber = function(n, a, b, c) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} a\n# @param {Integer} b\n# @param {Integer} c\n# @return {Integer}\ndef nth_ugly_number(n, a, b, c)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func nthUglyNumber(_ n: Int, _ a: Int, _ b: Int, _ c: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func nthUglyNumber(n int, a int, b int, c int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def nthUglyNumber(n: Int, a: Int, b: Int, c: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun nthUglyNumber(n: Int, a: Int, b: Int, c: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn nth_ugly_number(n: i32, a: i32, b: i32, c: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $a\n * @param Integer $b\n * @param Integer $c\n * @return Integer\n */\n function nthUglyNumber($n, $a, $b, $c) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function nthUglyNumber(n: number, a: number, b: number, c: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (nth-ugly-number n a b c)\n (-> exact-integer? exact-integer? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1201](https://leetcode-cn.com/problems/ugly-number-iii)", "[\u4e11\u6570 III](/solution/1200-1299/1201.Ugly%20Number%20III/README.md)", "`\u6570\u5b66`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1201](https://leetcode.com/problems/ugly-number-iii)", "[Ugly Number III](/solution/1200-1299/1201.Ugly%20Number%20III/README_EN.md)", "`Math`,`Binary Search`", "Medium", ""]}, {"question_id": "1306", "frontend_question_id": "1200", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-absolute-difference", "url_en": "https://leetcode.com/problems/minimum-absolute-difference", "relative_path_cn": "/solution/1200-1299/1200.Minimum%20Absolute%20Difference/README.md", "relative_path_en": "/solution/1200-1299/1200.Minimum%20Absolute%20Difference/README_EN.md", "title_cn": "\u6700\u5c0f\u7edd\u5bf9\u5dee", "title_en": "Minimum Absolute Difference", "question_title_slug": "minimum-absolute-difference", "content_en": "

    Given an array of distinct integers arr, find all pairs of elements with the minimum absolute difference of any two elements. 

    \n\n

    Return a list of pairs in ascending order(with respect to pairs), each pair [a, b] follows

    \n\n
      \n\t
    • a, b are from arr
    • \n\t
    • a < b
    • \n\t
    • b - a equals to the minimum absolute difference of any two elements in arr
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr = [4,2,1,3]\nOutput: [[1,2],[2,3],[3,4]]\nExplanation: The minimum absolute difference is 1. List all pairs with difference equal to 1 in ascending order.
    \n\n

    Example 2:

    \n\n
    \nInput: arr = [1,3,6,10,15]\nOutput: [[1,3]]\n
    \n\n

    Example 3:

    \n\n
    \nInput: arr = [3,8,-10,23,19,-4,-14,27]\nOutput: [[-14,-10],[19,23],[23,27]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= arr.length <= 10^5
    • \n\t
    • -10^6 <= arr[i] <= 10^6
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e2a\u6574\u6570\u6570\u7ec4 arr\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5143\u7d20\u90fd \u4e0d\u76f8\u540c\u3002

    \n\n

    \u8bf7\u4f60\u627e\u5230\u6240\u6709\u5177\u6709\u6700\u5c0f\u7edd\u5bf9\u5dee\u7684\u5143\u7d20\u5bf9\uff0c\u5e76\u4e14\u6309\u5347\u5e8f\u7684\u987a\u5e8f\u8fd4\u56de\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [4,2,1,3]\n\u8f93\u51fa\uff1a[[1,2],[2,3],[3,4]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [1,3,6,10,15]\n\u8f93\u51fa\uff1a[[1,3]]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [3,8,-10,23,19,-4,-14,27]\n\u8f93\u51fa\uff1a[[-14,-10],[19,23],[23,27]]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= arr.length <= 10^5
    • \n\t
    • -10^6 <= arr[i] <= 10^6
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> minimumAbsDifference(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> minimumAbsDifference(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimumAbsDifference(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: List[List[int]]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimumAbsDifference(self, arr: List[int]) -> List[List[int]]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** minimumAbsDifference(int* arr, int arrSize, int* returnSize, int** returnColumnSizes){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> MinimumAbsDifference(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number[][]}\n */\nvar minimumAbsDifference = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer[][]}\ndef minimum_abs_difference(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimumAbsDifference(_ arr: [Int]) -> [[Int]] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimumAbsDifference(arr []int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimumAbsDifference(arr: Array[Int]): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimumAbsDifference(arr: IntArray): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimum_abs_difference(arr: Vec) -> Vec> {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer[][]\n */\n function minimumAbsDifference($arr) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimumAbsDifference(arr: number[]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimum-abs-difference arr)\n (-> (listof exact-integer?) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1200](https://leetcode-cn.com/problems/minimum-absolute-difference)", "[\u6700\u5c0f\u7edd\u5bf9\u5dee](/solution/1200-1299/1200.Minimum%20Absolute%20Difference/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1200](https://leetcode.com/problems/minimum-absolute-difference)", "[Minimum Absolute Difference](/solution/1200-1299/1200.Minimum%20Absolute%20Difference/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1304", "frontend_question_id": "1405", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-happy-string", "url_en": "https://leetcode.com/problems/longest-happy-string", "relative_path_cn": "/solution/1400-1499/1405.Longest%20Happy%20String/README.md", "relative_path_en": "/solution/1400-1499/1405.Longest%20Happy%20String/README_EN.md", "title_cn": "\u6700\u957f\u5feb\u4e50\u5b57\u7b26\u4e32", "title_en": "Longest Happy String", "question_title_slug": "longest-happy-string", "content_en": "

    A string is called happy if it does not have any of the strings 'aaa', 'bbb' or 'ccc' as a substring.

    \n\n

    Given three integers a, b and c, return any string s, which satisfies following conditions:

    \n\n
      \n\t
    • s is happy and longest possible.
    • \n\t
    • s contains at most a occurrences of the letter 'a', at most b occurrences of the letter 'b' and at most c occurrences of the letter 'c'.
    • \n\t
    • will only contain 'a', 'b' and 'c' letters.
    • \n
    \n\n

    If there is no such string s return the empty string "".

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: a = 1, b = 1, c = 7\nOutput: "ccaccbcc"\nExplanation: "ccbccacc" would also be a correct answer.\n
    \n\n

    Example 2:

    \n\n
    \nInput: a = 2, b = 2, c = 1\nOutput: "aabbc"\n
    \n\n

    Example 3:

    \n\n
    \nInput: a = 7, b = 1, c = 0\nOutput: "aabaa"\nExplanation: It's the only correct answer in this case.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= a, b, c <= 100
    • \n\t
    • a + b + c > 0
    • \n
    \n", "content_cn": "

    \u5982\u679c\u5b57\u7b26\u4e32\u4e2d\u4e0d\u542b\u6709\u4efb\u4f55 'aaa'\uff0c'bbb' \u6216 'ccc' \u8fd9\u6837\u7684\u5b57\u7b26\u4e32\u4f5c\u4e3a\u5b50\u4e32\uff0c\u90a3\u4e48\u8be5\u5b57\u7b26\u4e32\u5c31\u662f\u4e00\u4e2a\u300c\u5feb\u4e50\u5b57\u7b26\u4e32\u300d\u3002

    \n\n

    \u7ed9\u4f60\u4e09\u4e2a\u6574\u6570 a\uff0cb \uff0cc\uff0c\u8bf7\u4f60\u8fd4\u56de \u4efb\u610f\u4e00\u4e2a \u6ee1\u8db3\u4e0b\u5217\u5168\u90e8\u6761\u4ef6\u7684\u5b57\u7b26\u4e32 s\uff1a

    \n\n
      \n\t
    • s \u662f\u4e00\u4e2a\u5c3d\u53ef\u80fd\u957f\u7684\u5feb\u4e50\u5b57\u7b26\u4e32\u3002
    • \n\t
    • s \u4e2d \u6700\u591a \u6709a \u4e2a\u5b57\u6bcd 'a'\u3001b \u4e2a\u5b57\u6bcd 'b'\u3001c \u4e2a\u5b57\u6bcd 'c' \u3002
    • \n\t
    • s \u4e2d\u53ea\u542b\u6709 'a'\u3001'b' \u3001'c' \u4e09\u79cd\u5b57\u6bcd\u3002
    • \n
    \n\n

    \u5982\u679c\u4e0d\u5b58\u5728\u8fd9\u6837\u7684\u5b57\u7b26\u4e32 s \uff0c\u8bf7\u8fd4\u56de\u4e00\u4e2a\u7a7a\u5b57\u7b26\u4e32 ""\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aa = 1, b = 1, c = 7\n\u8f93\u51fa\uff1a"ccaccbcc"\n\u89e3\u91ca\uff1a"ccbccacc" \u4e5f\u662f\u4e00\u79cd\u6b63\u786e\u7b54\u6848\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aa = 2, b = 2, c = 1\n\u8f93\u51fa\uff1a"aabbc"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aa = 7, b = 1, c = 0\n\u8f93\u51fa\uff1a"aabaa"\n\u89e3\u91ca\uff1a\u8fd9\u662f\u8be5\u6d4b\u8bd5\u7528\u4f8b\u7684\u552f\u4e00\u6b63\u786e\u7b54\u6848\u3002
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= a, b, c <= 100
    • \n\t
    • a + b + c > 0
    • \n
    \n", "tags_en": ["Greedy", "Dynamic Programming"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string longestDiverseString(int a, int b, int c) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String longestDiverseString(int a, int b, int c) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestDiverseString(self, a, b, c):\n \"\"\"\n :type a: int\n :type b: int\n :type c: int\n :rtype: str\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestDiverseString(self, a: int, b: int, c: int) -> str:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * longestDiverseString(int a, int b, int c){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string LongestDiverseString(int a, int b, int c) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} a\n * @param {number} b\n * @param {number} c\n * @return {string}\n */\nvar longestDiverseString = function(a, b, c) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} a\n# @param {Integer} b\n# @param {Integer} c\n# @return {String}\ndef longest_diverse_string(a, b, c)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestDiverseString(_ a: Int, _ b: Int, _ c: Int) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestDiverseString(a int, b int, c int) string {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestDiverseString(a: Int, b: Int, c: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestDiverseString(a: Int, b: Int, c: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_diverse_string(a: i32, b: i32, c: i32) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $a\n * @param Integer $b\n * @param Integer $c\n * @return String\n */\n function longestDiverseString($a, $b, $c) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestDiverseString(a: number, b: number, c: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-diverse-string a b c)\n (-> exact-integer? exact-integer? exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1405](https://leetcode-cn.com/problems/longest-happy-string)", "[\u6700\u957f\u5feb\u4e50\u5b57\u7b26\u4e32](/solution/1400-1499/1405.Longest%20Happy%20String/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1405](https://leetcode.com/problems/longest-happy-string)", "[Longest Happy String](/solution/1400-1499/1405.Longest%20Happy%20String/README_EN.md)", "`Greedy`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "1301", "frontend_question_id": "1179", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reformat-department-table", "url_en": "https://leetcode.com/problems/reformat-department-table", "relative_path_cn": "/solution/1100-1199/1179.Reformat%20Department%20Table/README.md", "relative_path_en": "/solution/1100-1199/1179.Reformat%20Department%20Table/README_EN.md", "title_cn": "\u91cd\u65b0\u683c\u5f0f\u5316\u90e8\u95e8\u8868", "title_en": "Reformat Department Table", "question_title_slug": "reformat-department-table", "content_en": "

    Table: Department

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| revenue       | int     |\n| month         | varchar |\n+---------------+---------+\n(id, month) is the primary key of this table.\nThe table has information about the revenue of each department per month.\nThe month has values in ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"].\n
    \n\n

     

    \n\n

    Write an SQL query to reformat the table such that there is a department id column and a revenue column for each month.

    \n\n

    The query result format is in the following example:

    \n\n
    \nDepartment table:\n+------+---------+-------+\n| id   | revenue | month |\n+------+---------+-------+\n| 1    | 8000    | Jan   |\n| 2    | 9000    | Jan   |\n| 3    | 10000   | Feb   |\n| 1    | 7000    | Feb   |\n| 1    | 6000    | Mar   |\n+------+---------+-------+\n\nResult table:\n+------+-------------+-------------+-------------+-----+-------------+\n| id   | Jan_Revenue | Feb_Revenue | Mar_Revenue | ... | Dec_Revenue |\n+------+-------------+-------------+-------------+-----+-------------+\n| 1    | 8000        | 7000        | 6000        | ... | null        |\n| 2    | 9000        | null        | null        | ... | null        |\n| 3    | null        | 10000       | null        | ... | null        |\n+------+-------------+-------------+-------------+-----+-------------+\n\nNote that the result table has 13 columns (1 for the department id + 12 for the months).\n
    \n", "content_cn": "

    \u90e8\u95e8\u8868 Department\uff1a

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| revenue       | int     |\n| month         | varchar |\n+---------------+---------+\n(id, month) \u662f\u8868\u7684\u8054\u5408\u4e3b\u952e\u3002\n\u8fd9\u4e2a\u8868\u683c\u6709\u5173\u4e8e\u6bcf\u4e2a\u90e8\u95e8\u6bcf\u6708\u6536\u5165\u7684\u4fe1\u606f\u3002\n\u6708\u4efd\uff08month\uff09\u53ef\u4ee5\u53d6\u4e0b\u5217\u503c ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]\u3002\n
    \n\n

     

    \n\n

    \u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\u6765\u91cd\u65b0\u683c\u5f0f\u5316\u8868\uff0c\u4f7f\u5f97\u65b0\u7684\u8868\u4e2d\u6709\u4e00\u4e2a\u90e8\u95e8 id \u5217\u548c\u4e00\u4e9b\u5bf9\u5e94 \u6bcf\u4e2a\u6708 \u7684\u6536\u5165\uff08revenue\uff09\u5217\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u9762\u7684\u793a\u4f8b\u6240\u793a\uff1a

    \n\n
    \nDepartment \u8868\uff1a\n+------+---------+-------+\n| id   | revenue | month |\n+------+---------+-------+\n| 1    | 8000    | Jan   |\n| 2    | 9000    | Jan   |\n| 3    | 10000   | Feb   |\n| 1    | 7000    | Feb   |\n| 1    | 6000    | Mar   |\n+------+---------+-------+\n\n\u67e5\u8be2\u5f97\u5230\u7684\u7ed3\u679c\u8868\uff1a\n+------+-------------+-------------+-------------+-----+-------------+\n| id   | Jan_Revenue | Feb_Revenue | Mar_Revenue | ... | Dec_Revenue |\n+------+-------------+-------------+-------------+-----+-------------+\n| 1    | 8000        | 7000        | 6000        | ... | null        |\n| 2    | 9000        | null        | null        | ... | null        |\n| 3    | null        | 10000       | null        | ... | null        |\n+------+-------------+-------------+-------------+-----+-------------+\n\n\u6ce8\u610f\uff0c\u7ed3\u679c\u8868\u6709 13 \u5217 (1\u4e2a\u90e8\u95e8 id \u5217 + 12\u4e2a\u6708\u4efd\u7684\u6536\u5165\u5217)\u3002\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1179](https://leetcode-cn.com/problems/reformat-department-table)", "[\u91cd\u65b0\u683c\u5f0f\u5316\u90e8\u95e8\u8868](/solution/1100-1199/1179.Reformat%20Department%20Table/README.md)", "", "\u7b80\u5355", ""], "md_table_row_en": ["[1179](https://leetcode.com/problems/reformat-department-table)", "[Reformat Department Table](/solution/1100-1199/1179.Reformat%20Department%20Table/README_EN.md)", "", "Easy", ""]}, {"question_id": "1300", "frontend_question_id": "1192", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/critical-connections-in-a-network", "url_en": "https://leetcode.com/problems/critical-connections-in-a-network", "relative_path_cn": "/solution/1100-1199/1192.Critical%20Connections%20in%20a%20Network/README.md", "relative_path_en": "/solution/1100-1199/1192.Critical%20Connections%20in%20a%20Network/README_EN.md", "title_cn": "\u67e5\u627e\u96c6\u7fa4\u5185\u7684\u300c\u5173\u952e\u8fde\u63a5\u300d", "title_en": "Critical Connections in a Network", "question_title_slug": "critical-connections-in-a-network", "content_en": "

    There are n servers numbered from 0 to n - 1 connected by undirected server-to-server connections forming a network where connections[i] = [ai, bi] represents a connection between servers ai and bi. Any server can reach other servers directly or indirectly through the network.

    \n\n

    A critical connection is a connection that, if removed, will make some servers unable to reach some other server.

    \n\n

    Return all critical connections in the network in any order.

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: n = 4, connections = [[0,1],[1,2],[2,0],[1,3]]\nOutput: [[1,3]]\nExplanation: [[3,1]] is also accepted.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= n <= 105
    • \n\t
    • n - 1 <= connections.length <= 105
    • \n\t
    • 0 <= ai, bi <= n - 1
    • \n\t
    • ai != bi
    • \n\t
    • There are no repeated connections.
    • \n
    \n", "content_cn": "

    \u529b\u6263\u6570\u636e\u4e2d\u5fc3\u6709 n \u53f0\u670d\u52a1\u5668\uff0c\u5206\u522b\u6309\u4ece 0 \u5230 n-1 \u7684\u65b9\u5f0f\u8fdb\u884c\u4e86\u7f16\u53f7\u3002

    \n\n

    \u5b83\u4eec\u4e4b\u95f4\u4ee5\u300c\u670d\u52a1\u5668\u5230\u670d\u52a1\u5668\u300d\u70b9\u5bf9\u70b9\u7684\u5f62\u5f0f\u76f8\u4e92\u8fde\u63a5\u7ec4\u6210\u4e86\u4e00\u4e2a\u5185\u90e8\u96c6\u7fa4\uff0c\u5176\u4e2d\u8fde\u63a5 connections \u662f\u65e0\u5411\u7684\u3002

    \n\n

    \u4ece\u5f62\u5f0f\u4e0a\u8bb2\uff0cconnections[i] = [a, b] \u8868\u793a\u670d\u52a1\u5668 a \u548c b \u4e4b\u95f4\u5f62\u6210\u8fde\u63a5\u3002\u4efb\u4f55\u670d\u52a1\u5668\u90fd\u53ef\u4ee5\u76f4\u63a5\u6216\u8005\u95f4\u63a5\u5730\u901a\u8fc7\u7f51\u7edc\u5230\u8fbe\u4efb\u4f55\u5176\u4ed6\u670d\u52a1\u5668\u3002

    \n\n

    \u300c\u5173\u952e\u8fde\u63a5\u300d\u662f\u5728\u8be5\u96c6\u7fa4\u4e2d\u7684\u91cd\u8981\u8fde\u63a5\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u5047\u5982\u6211\u4eec\u5c06\u5b83\u79fb\u9664\uff0c\u4fbf\u4f1a\u5bfc\u81f4\u67d0\u4e9b\u670d\u52a1\u5668\u65e0\u6cd5\u8bbf\u95ee\u5176\u4ed6\u670d\u52a1\u5668\u3002

    \n\n

    \u8bf7\u4f60\u4ee5\u4efb\u610f\u987a\u5e8f\u8fd4\u56de\u8be5\u96c6\u7fa4\u5185\u7684\u6240\u6709 \u300c\u5173\u952e\u8fde\u63a5\u300d\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 4, connections = [[0,1],[1,2],[2,0],[1,3]]\n\u8f93\u51fa\uff1a[[1,3]]\n\u89e3\u91ca\uff1a[[3,1]] \u4e5f\u662f\u6b63\u786e\u7684\u3002
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 10^5
    • \n\t
    • n-1 <= connections.length <= 10^5
    • \n\t
    • connections[i][0] != connections[i][1]
    • \n\t
    • \u4e0d\u5b58\u5728\u91cd\u590d\u7684\u8fde\u63a5
    • \n
    \n", "tags_en": ["Depth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> criticalConnections(int n, vector>& connections) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> criticalConnections(int n, List> connections) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def criticalConnections(self, n, connections):\n \"\"\"\n :type n: int\n :type connections: List[List[int]]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def criticalConnections(self, n: int, connections: List[List[int]]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** criticalConnections(int n, int** connections, int connectionsSize, int* connectionsColSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> CriticalConnections(int n, IList> connections) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} connections\n * @return {number[][]}\n */\nvar criticalConnections = function(n, connections) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} connections\n# @return {Integer[][]}\ndef critical_connections(n, connections)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func criticalConnections(_ n: Int, _ connections: [[Int]]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func criticalConnections(n int, connections [][]int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def criticalConnections(n: Int, connections: List[List[Int]]): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun criticalConnections(n: Int, connections: List>): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn critical_connections(n: i32, connections: Vec>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $connections\n * @return Integer[][]\n */\n function criticalConnections($n, $connections) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function criticalConnections(n: number, connections: number[][]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (critical-connections n connections)\n (-> exact-integer? (listof (listof exact-integer?)) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1192](https://leetcode-cn.com/problems/critical-connections-in-a-network)", "[\u67e5\u627e\u96c6\u7fa4\u5185\u7684\u300c\u5173\u952e\u8fde\u63a5\u300d](/solution/1100-1199/1192.Critical%20Connections%20in%20a%20Network/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[1192](https://leetcode.com/problems/critical-connections-in-a-network)", "[Critical Connections in a Network](/solution/1100-1199/1192.Critical%20Connections%20in%20a%20Network/README_EN.md)", "`Depth-first Search`", "Hard", ""]}, {"question_id": "1299", "frontend_question_id": "1191", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/k-concatenation-maximum-sum", "url_en": "https://leetcode.com/problems/k-concatenation-maximum-sum", "relative_path_cn": "/solution/1100-1199/1191.K-Concatenation%20Maximum%20Sum/README.md", "relative_path_en": "/solution/1100-1199/1191.K-Concatenation%20Maximum%20Sum/README_EN.md", "title_cn": "K \u6b21\u4e32\u8054\u540e\u6700\u5927\u5b50\u6570\u7ec4\u4e4b\u548c", "title_en": "K-Concatenation Maximum Sum", "question_title_slug": "k-concatenation-maximum-sum", "content_en": "

    Given an integer array arr and an integer k, modify the array by repeating it k times.

    \n\n

    For example, if arr = [1, 2] and k = 3 then the modified array will be [1, 2, 1, 2, 1, 2].

    \n\n

    Return the maximum sub-array sum in the modified array. Note that the length of the sub-array can be 0 and its sum in that case is 0.

    \n\n

    As the answer can be very large, return the answer modulo 109 + 7.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr = [1,2], k = 3\nOutput: 9\n
    \n\n

    Example 2:

    \n\n
    \nInput: arr = [1,-2,1], k = 5\nOutput: 2\n
    \n\n

    Example 3:

    \n\n
    \nInput: arr = [-1,-2], k = 7\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= arr.length <= 105
    • \n\t
    • 1 <= k <= 105
    • \n\t
    • -104 <= arr[i] <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr \u548c\u4e00\u4e2a\u6574\u6570 k\u3002

    \n\n

    \u9996\u5148\uff0c\u6211\u4eec\u8981\u5bf9\u8be5\u6570\u7ec4\u8fdb\u884c\u4fee\u6539\uff0c\u5373\u628a\u539f\u6570\u7ec4 arr \u91cd\u590d k \u6b21\u3002

    \n\n
    \n

    \u4e3e\u4e2a\u4f8b\u5b50\uff0c\u5982\u679c arr = [1, 2] \u4e14 k = 3\uff0c\u90a3\u4e48\u4fee\u6539\u540e\u7684\u6570\u7ec4\u5c31\u662f [1, 2, 1, 2, 1, 2]\u3002

    \n
    \n\n

    \u7136\u540e\uff0c\u8bf7\u4f60\u8fd4\u56de\u4fee\u6539\u540e\u7684\u6570\u7ec4\u4e2d\u7684\u6700\u5927\u7684\u5b50\u6570\u7ec4\u4e4b\u548c\u3002

    \n\n

    \u6ce8\u610f\uff0c\u5b50\u6570\u7ec4\u957f\u5ea6\u53ef\u4ee5\u662f 0\uff0c\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\u5b83\u7684\u603b\u548c\u4e5f\u662f 0\u3002

    \n\n

    \u7531\u4e8e \u7ed3\u679c\u53ef\u80fd\u4f1a\u5f88\u5927\uff0c\u6240\u4ee5\u9700\u8981 \u6a21\uff08mod\uff09 10^9 + 7 \u540e\u518d\u8fd4\u56de\u3002 

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [1,2], k = 3\n\u8f93\u51fa\uff1a9\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [1,-2,1], k = 5\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [-1,-2], k = 7\n\u8f93\u51fa\uff1a0\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= arr.length <= 10^5
    • \n\t
    • 1 <= k <= 10^5
    • \n\t
    • -10^4 <= arr[i] <= 10^4
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int kConcatenationMaxSum(vector& arr, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int kConcatenationMaxSum(int[] arr, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def kConcatenationMaxSum(self, arr, k):\n \"\"\"\n :type arr: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def kConcatenationMaxSum(self, arr: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint kConcatenationMaxSum(int* arr, int arrSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int KConcatenationMaxSum(int[] arr, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @param {number} k\n * @return {number}\n */\nvar kConcatenationMaxSum = function(arr, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @param {Integer} k\n# @return {Integer}\ndef k_concatenation_max_sum(arr, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func kConcatenationMaxSum(_ arr: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func kConcatenationMaxSum(arr []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def kConcatenationMaxSum(arr: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun kConcatenationMaxSum(arr: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn k_concatenation_max_sum(arr: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @param Integer $k\n * @return Integer\n */\n function kConcatenationMaxSum($arr, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function kConcatenationMaxSum(arr: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (k-concatenation-max-sum arr k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1191](https://leetcode-cn.com/problems/k-concatenation-maximum-sum)", "[K \u6b21\u4e32\u8054\u540e\u6700\u5927\u5b50\u6570\u7ec4\u4e4b\u548c](/solution/1100-1199/1191.K-Concatenation%20Maximum%20Sum/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1191](https://leetcode.com/problems/k-concatenation-maximum-sum)", "[K-Concatenation Maximum Sum](/solution/1100-1199/1191.K-Concatenation%20Maximum%20Sum/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "1298", "frontend_question_id": "1190", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reverse-substrings-between-each-pair-of-parentheses", "url_en": "https://leetcode.com/problems/reverse-substrings-between-each-pair-of-parentheses", "relative_path_cn": "/solution/1100-1199/1190.Reverse%20Substrings%20Between%20Each%20Pair%20of%20Parentheses/README.md", "relative_path_en": "/solution/1100-1199/1190.Reverse%20Substrings%20Between%20Each%20Pair%20of%20Parentheses/README_EN.md", "title_cn": "\u53cd\u8f6c\u6bcf\u5bf9\u62ec\u53f7\u95f4\u7684\u5b50\u4e32", "title_en": "Reverse Substrings Between Each Pair of Parentheses", "question_title_slug": "reverse-substrings-between-each-pair-of-parentheses", "content_en": "

    You are given a string s that consists of lower case English letters and brackets. 

    \n\n

    Reverse the strings in each pair of matching parentheses, starting from the innermost one.

    \n\n

    Your result should not contain any brackets.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "(abcd)"\nOutput: "dcba"\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "(u(love)i)"\nOutput: "iloveu"\nExplanation: The substring "love" is reversed first, then the whole string is reversed.\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "(ed(et(oc))el)"\nOutput: "leetcode"\nExplanation: First, we reverse the substring "oc", then "etco", and finally, the whole string.\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "a(bcdefghijkl(mno)p)q"\nOutput: "apmnolkjihgfedcbq"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= s.length <= 2000
    • \n\t
    • s only contains lower case English characters and parentheses.
    • \n\t
    • It's guaranteed that all parentheses are balanced.
    • \n
    \n", "content_cn": "

    \u7ed9\u51fa\u4e00\u4e2a\u5b57\u7b26\u4e32\u00a0s\uff08\u4ec5\u542b\u6709\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u548c\u62ec\u53f7\uff09\u3002

    \n\n

    \u8bf7\u4f60\u6309\u7167\u4ece\u62ec\u53f7\u5185\u5230\u5916\u7684\u987a\u5e8f\uff0c\u9010\u5c42\u53cd\u8f6c\u6bcf\u5bf9\u5339\u914d\u62ec\u53f7\u4e2d\u7684\u5b57\u7b26\u4e32\uff0c\u5e76\u8fd4\u56de\u6700\u7ec8\u7684\u7ed3\u679c\u3002

    \n\n

    \u6ce8\u610f\uff0c\u60a8\u7684\u7ed3\u679c\u4e2d \u4e0d\u5e94 \u5305\u542b\u4efb\u4f55\u62ec\u53f7\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"(abcd)\"\n\u8f93\u51fa\uff1a\"dcba\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"(u(love)i)\"\n\u8f93\u51fa\uff1a\"iloveu\"\n\u89e3\u91ca\uff1a\u5148\u53cd\u8f6c\u5b50\u5b57\u7b26\u4e32 \"love\" \uff0c\u7136\u540e\u53cd\u8f6c\u6574\u4e2a\u5b57\u7b26\u4e32\u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"(ed(et(oc))el)\"\n\u8f93\u51fa\uff1a\"leetcode\"\n\u89e3\u91ca\uff1a\u5148\u53cd\u8f6c\u5b50\u5b57\u7b26\u4e32 \"oc\" \uff0c\u63a5\u7740\u53cd\u8f6c \"etco\" \uff0c\u7136\u540e\u53cd\u8f6c\u6574\u4e2a\u5b57\u7b26\u4e32\u3002
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"a(bcdefghijkl(mno)p)q\"\n\u8f93\u51fa\uff1a\"apmnolkjihgfedcbq\"\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= s.length <= 2000
    • \n\t
    • s \u4e2d\u53ea\u6709\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u548c\u62ec\u53f7
    • \n\t
    • \u9898\u76ee\u6d4b\u8bd5\u7528\u4f8b\u786e\u4fdd\u6240\u6709\u62ec\u53f7\u90fd\u662f\u6210\u5bf9\u51fa\u73b0\u7684
    • \n
    \n", "tags_en": ["Stack"], "tags_cn": ["\u6808"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string reverseParentheses(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String reverseParentheses(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def reverseParentheses(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def reverseParentheses(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * reverseParentheses(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ReverseParentheses(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar reverseParentheses = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef reverse_parentheses(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func reverseParentheses(_ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func reverseParentheses(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def reverseParentheses(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun reverseParentheses(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn reverse_parentheses(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function reverseParentheses($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function reverseParentheses(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (reverse-parentheses s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1190](https://leetcode-cn.com/problems/reverse-substrings-between-each-pair-of-parentheses)", "[\u53cd\u8f6c\u6bcf\u5bf9\u62ec\u53f7\u95f4\u7684\u5b50\u4e32](/solution/1100-1199/1190.Reverse%20Substrings%20Between%20Each%20Pair%20of%20Parentheses/README.md)", "`\u6808`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1190](https://leetcode.com/problems/reverse-substrings-between-each-pair-of-parentheses)", "[Reverse Substrings Between Each Pair of Parentheses](/solution/1100-1199/1190.Reverse%20Substrings%20Between%20Each%20Pair%20of%20Parentheses/README_EN.md)", "`Stack`", "Medium", ""]}, {"question_id": "1297", "frontend_question_id": "1189", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-number-of-balloons", "url_en": "https://leetcode.com/problems/maximum-number-of-balloons", "relative_path_cn": "/solution/1100-1199/1189.Maximum%20Number%20of%20Balloons/README.md", "relative_path_en": "/solution/1100-1199/1189.Maximum%20Number%20of%20Balloons/README_EN.md", "title_cn": "\u201c\u6c14\u7403\u201d \u7684\u6700\u5927\u6570\u91cf", "title_en": "Maximum Number of Balloons", "question_title_slug": "maximum-number-of-balloons", "content_en": "

    Given a string text, you want to use the characters of text to form as many instances of the word "balloon" as possible.

    \n\n

    You can use each character in text at most once. Return the maximum number of instances that can be formed.

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: text = "nlaebolko"\nOutput: 1\n
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: text = "loonbalxballpoon"\nOutput: 2\n
    \n\n

    Example 3:

    \n\n
    \nInput: text = "leetcode"\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= text.length <= 104
    • \n\t
    • text consists of lower case English letters only.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 text\uff0c\u4f60\u9700\u8981\u4f7f\u7528 text \u4e2d\u7684\u5b57\u6bcd\u6765\u62fc\u51d1\u5c3d\u53ef\u80fd\u591a\u7684\u5355\u8bcd "balloon"\uff08\u6c14\u7403\uff09\u3002

    \n\n

    \u5b57\u7b26\u4e32 text \u4e2d\u7684\u6bcf\u4e2a\u5b57\u6bcd\u6700\u591a\u53ea\u80fd\u88ab\u4f7f\u7528\u4e00\u6b21\u3002\u8bf7\u4f60\u8fd4\u56de\u6700\u591a\u53ef\u4ee5\u62fc\u51d1\u51fa\u591a\u5c11\u4e2a\u5355\u8bcd "balloon"\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1atext = "nlaebolko"\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1atext = "loonbalxballpoon"\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1atext = "leetcode"\n\u8f93\u51fa\uff1a0\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= text.length <= 10^4
    • \n\t
    • text \u5168\u90e8\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n", "tags_en": ["Hash Table", "String"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxNumberOfBalloons(string text) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxNumberOfBalloons(String text) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxNumberOfBalloons(self, text):\n \"\"\"\n :type text: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxNumberOfBalloons(self, text: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxNumberOfBalloons(char * text){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxNumberOfBalloons(string text) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} text\n * @return {number}\n */\nvar maxNumberOfBalloons = function(text) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} text\n# @return {Integer}\ndef max_number_of_balloons(text)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxNumberOfBalloons(_ text: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxNumberOfBalloons(text string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxNumberOfBalloons(text: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxNumberOfBalloons(text: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_number_of_balloons(text: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $text\n * @return Integer\n */\n function maxNumberOfBalloons($text) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxNumberOfBalloons(text: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-number-of-balloons text)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1189](https://leetcode-cn.com/problems/maximum-number-of-balloons)", "[\u201c\u6c14\u7403\u201d \u7684\u6700\u5927\u6570\u91cf](/solution/1100-1199/1189.Maximum%20Number%20of%20Balloons/README.md)", "`\u54c8\u5e0c\u8868`,`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1189](https://leetcode.com/problems/maximum-number-of-balloons)", "[Maximum Number of Balloons](/solution/1100-1199/1189.Maximum%20Number%20of%20Balloons/README_EN.md)", "`Hash Table`,`String`", "Easy", ""]}, {"question_id": "1296", "frontend_question_id": "1483", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/kth-ancestor-of-a-tree-node", "url_en": "https://leetcode.com/problems/kth-ancestor-of-a-tree-node", "relative_path_cn": "/solution/1400-1499/1483.Kth%20Ancestor%20of%20a%20Tree%20Node/README.md", "relative_path_en": "/solution/1400-1499/1483.Kth%20Ancestor%20of%20a%20Tree%20Node/README_EN.md", "title_cn": "\u6811\u8282\u70b9\u7684\u7b2c K \u4e2a\u7956\u5148", "title_en": "Kth Ancestor of a Tree Node", "question_title_slug": "kth-ancestor-of-a-tree-node", "content_en": "

    You are given a tree with n nodes numbered from 0 to n-1 in the form of a parent array where parent[i] is the parent of node i. The root of the tree is node 0.

    \r\n\r\n

    Implement the function getKthAncestor(int node, int k) to return the k-th ancestor of the given node. If there is no such ancestor, return -1.

    \r\n\r\n

    The k-th ancestor of a tree node is the k-th node in the path from that node to the root.

    \r\n\r\n

     

    \r\n\r\n

    Example:

    \r\n\r\n

    \"\"

    \r\n\r\n
    \r\nInput:\r\n["TreeAncestor","getKthAncestor","getKthAncestor","getKthAncestor"]\r\n[[7,[-1,0,0,1,1,2,2]],[3,1],[5,2],[6,3]]\r\n\r\nOutput:\r\n[null,1,0,-1]\r\n\r\nExplanation:\r\nTreeAncestor treeAncestor = new TreeAncestor(7, [-1, 0, 0, 1, 1, 2, 2]);\r\n\r\ntreeAncestor.getKthAncestor(3, 1);  // returns 1 which is the parent of 3\r\ntreeAncestor.getKthAncestor(5, 2);  // returns 0 which is the grandparent of 5\r\ntreeAncestor.getKthAncestor(6, 3);  // returns -1 because there is no such ancestor\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= k <= n <= 5*10^4
    • \r\n\t
    • parent[0] == -1 indicating that 0 is the root node.
    • \r\n\t
    • 0 <= parent[i] < n for all 0 < i < n
    • \r\n\t
    • 0 <= node < n
    • \r\n\t
    • There will be at most 5*10^4 queries.
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u68f5\u6811\uff0c\u6811\u4e0a\u6709 n \u4e2a\u8282\u70b9\uff0c\u6309\u4ece 0 \u5230 n-1 \u7f16\u53f7\u3002\u6811\u4ee5\u7236\u8282\u70b9\u6570\u7ec4\u7684\u5f62\u5f0f\u7ed9\u51fa\uff0c\u5176\u4e2d parent[i] \u662f\u8282\u70b9 i \u7684\u7236\u8282\u70b9\u3002\u6811\u7684\u6839\u8282\u70b9\u662f\u7f16\u53f7\u4e3a 0 \u7684\u8282\u70b9\u3002

    \n\n

    \u8bf7\u4f60\u8bbe\u8ba1\u5e76\u5b9e\u73b0 getKthAncestor(int node, int k) \u51fd\u6570\uff0c\u51fd\u6570\u8fd4\u56de\u8282\u70b9 node \u7684\u7b2c k \u4e2a\u7956\u5148\u8282\u70b9\u3002\u5982\u679c\u4e0d\u5b58\u5728\u8fd9\u6837\u7684\u7956\u5148\u8282\u70b9\uff0c\u8fd4\u56de -1 \u3002

    \n\n

    \u6811\u8282\u70b9\u7684\u7b2c k \u4e2a\u7956\u5148\u8282\u70b9\u662f\u4ece\u8be5\u8282\u70b9\u5230\u6839\u8282\u70b9\u8def\u5f84\u4e0a\u7684\u7b2c k \u4e2a\u8282\u70b9\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1a\n["TreeAncestor","getKthAncestor","getKthAncestor","getKthAncestor"]\n[[7,[-1,0,0,1,1,2,2]],[3,1],[5,2],[6,3]]\n\n\u8f93\u51fa\uff1a\n[null,1,0,-1]\n\n\u89e3\u91ca\uff1a\nTreeAncestor treeAncestor = new TreeAncestor(7, [-1, 0, 0, 1, 1, 2, 2]);\n\ntreeAncestor.getKthAncestor(3, 1);  // \u8fd4\u56de 1 \uff0c\u5b83\u662f 3 \u7684\u7236\u8282\u70b9\ntreeAncestor.getKthAncestor(5, 2);  // \u8fd4\u56de 0 \uff0c\u5b83\u662f 5 \u7684\u7956\u7236\u8282\u70b9\ntreeAncestor.getKthAncestor(6, 3);  // \u8fd4\u56de -1 \u56e0\u4e3a\u4e0d\u5b58\u5728\u6ee1\u8db3\u8981\u6c42\u7684\u7956\u5148\u8282\u70b9\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= k <= n <= 5*10^4
    • \n\t
    • parent[0] == -1 \u8868\u793a\u7f16\u53f7\u4e3a 0 \u7684\u8282\u70b9\u662f\u6839\u8282\u70b9\u3002
    • \n\t
    • \u5bf9\u4e8e\u6240\u6709\u7684 0 < i < n \uff0c0 <= parent[i] < n \u603b\u6210\u7acb
    • \n\t
    • 0 <= node < n
    • \n\t
    • \u81f3\u591a\u67e5\u8be2 5*10^4 \u6b21
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class TreeAncestor {\npublic:\n TreeAncestor(int n, vector& parent) {\n\n }\n \n int getKthAncestor(int node, int k) {\n\n }\n};\n\n/**\n * Your TreeAncestor object will be instantiated and called as such:\n * TreeAncestor* obj = new TreeAncestor(n, parent);\n * int param_1 = obj->getKthAncestor(node,k);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class TreeAncestor {\n\n public TreeAncestor(int n, int[] parent) {\n\n }\n \n public int getKthAncestor(int node, int k) {\n\n }\n}\n\n/**\n * Your TreeAncestor object will be instantiated and called as such:\n * TreeAncestor obj = new TreeAncestor(n, parent);\n * int param_1 = obj.getKthAncestor(node,k);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class TreeAncestor(object):\n\n def __init__(self, n, parent):\n \"\"\"\n :type n: int\n :type parent: List[int]\n \"\"\"\n\n\n def getKthAncestor(self, node, k):\n \"\"\"\n :type node: int\n :type k: int\n :rtype: int\n \"\"\"\n\n\n\n# Your TreeAncestor object will be instantiated and called as such:\n# obj = TreeAncestor(n, parent)\n# param_1 = obj.getKthAncestor(node,k)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class TreeAncestor:\n\n def __init__(self, n: int, parent: List[int]):\n\n\n def getKthAncestor(self, node: int, k: int) -> int:\n\n\n\n# Your TreeAncestor object will be instantiated and called as such:\n# obj = TreeAncestor(n, parent)\n# param_1 = obj.getKthAncestor(node,k)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} TreeAncestor;\n\n\nTreeAncestor* treeAncestorCreate(int n, int* parent, int parentSize) {\n\n}\n\nint treeAncestorGetKthAncestor(TreeAncestor* obj, int node, int k) {\n\n}\n\nvoid treeAncestorFree(TreeAncestor* obj) {\n\n}\n\n/**\n * Your TreeAncestor struct will be instantiated and called as such:\n * TreeAncestor* obj = treeAncestorCreate(n, parent, parentSize);\n * int param_1 = treeAncestorGetKthAncestor(obj, node, k);\n \n * treeAncestorFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class TreeAncestor {\n\n public TreeAncestor(int n, int[] parent) {\n\n }\n \n public int GetKthAncestor(int node, int k) {\n\n }\n}\n\n/**\n * Your TreeAncestor object will be instantiated and called as such:\n * TreeAncestor obj = new TreeAncestor(n, parent);\n * int param_1 = obj.GetKthAncestor(node,k);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[]} parent\n */\nvar TreeAncestor = function(n, parent) {\n\n};\n\n/** \n * @param {number} node \n * @param {number} k\n * @return {number}\n */\nTreeAncestor.prototype.getKthAncestor = function(node, k) {\n\n};\n\n/**\n * Your TreeAncestor object will be instantiated and called as such:\n * var obj = new TreeAncestor(n, parent)\n * var param_1 = obj.getKthAncestor(node,k)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class TreeAncestor\n\n=begin\n :type n: Integer\n :type parent: Integer[]\n=end\n def initialize(n, parent)\n\n end\n\n\n=begin\n :type node: Integer\n :type k: Integer\n :rtype: Integer\n=end\n def get_kth_ancestor(node, k)\n\n end\n\n\nend\n\n# Your TreeAncestor object will be instantiated and called as such:\n# obj = TreeAncestor.new(n, parent)\n# param_1 = obj.get_kth_ancestor(node, k)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass TreeAncestor {\n\n init(_ n: Int, _ parent: [Int]) {\n \n }\n \n func getKthAncestor(_ node: Int, _ k: Int) -> Int {\n \n }\n}\n\n/**\n * Your TreeAncestor object will be instantiated and called as such:\n * let obj = TreeAncestor(n, parent)\n * let ret_1: Int = obj.getKthAncestor(node, k)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type TreeAncestor struct {\n\n}\n\n\nfunc Constructor(n int, parent []int) TreeAncestor {\n\n}\n\n\nfunc (this *TreeAncestor) GetKthAncestor(node int, k int) int {\n\n}\n\n\n/**\n * Your TreeAncestor object will be instantiated and called as such:\n * obj := Constructor(n, parent);\n * param_1 := obj.GetKthAncestor(node,k);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class TreeAncestor(_n: Int, _parent: Array[Int]) {\n\n def getKthAncestor(node: Int, k: Int): Int = {\n\n }\n\n}\n\n/**\n * Your TreeAncestor object will be instantiated and called as such:\n * var obj = new TreeAncestor(n, parent)\n * var param_1 = obj.getKthAncestor(node,k)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class TreeAncestor(n: Int, parent: IntArray) {\n\n fun getKthAncestor(node: Int, k: Int): Int {\n\n }\n\n}\n\n/**\n * Your TreeAncestor object will be instantiated and called as such:\n * var obj = TreeAncestor(n, parent)\n * var param_1 = obj.getKthAncestor(node,k)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct TreeAncestor {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl TreeAncestor {\n\n fn new(n: i32, parent: Vec) -> Self {\n\n }\n \n fn get_kth_ancestor(&self, node: i32, k: i32) -> i32 {\n\n }\n}\n\n/**\n * Your TreeAncestor object will be instantiated and called as such:\n * let obj = TreeAncestor::new(n, parent);\n * let ret_1: i32 = obj.get_kth_ancestor(node, k);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class TreeAncestor {\n /**\n * @param Integer $n\n * @param Integer[] $parent\n */\n function __construct($n, $parent) {\n \n }\n \n /**\n * @param Integer $node\n * @param Integer $k\n * @return Integer\n */\n function getKthAncestor($node, $k) {\n \n }\n}\n\n/**\n * Your TreeAncestor object will be instantiated and called as such:\n * $obj = TreeAncestor($n, $parent);\n * $ret_1 = $obj->getKthAncestor($node, $k);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class TreeAncestor {\n constructor(n: number, parent: number[]) {\n\n }\n\n getKthAncestor(node: number, k: number): number {\n\n }\n}\n\n/**\n * Your TreeAncestor object will be instantiated and called as such:\n * var obj = new TreeAncestor(n, parent)\n * var param_1 = obj.getKthAncestor(node,k)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define tree-ancestor%\n (class object%\n (super-new)\n\n ; n : exact-integer?\n\n ; parent : (listof exact-integer?)\n (init-field\n n\n parent)\n \n ; get-kth-ancestor : exact-integer? exact-integer? -> exact-integer?\n (define/public (get-kth-ancestor node k)\n\n )))\n\n;; Your tree-ancestor% object will be instantiated and called as such:\n;; (define obj (new tree-ancestor% [n n] [parent parent]))\n;; (define param_1 (send obj get-kth-ancestor node k))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1483](https://leetcode-cn.com/problems/kth-ancestor-of-a-tree-node)", "[\u6811\u8282\u70b9\u7684\u7b2c K \u4e2a\u7956\u5148](/solution/1400-1499/1483.Kth%20Ancestor%20of%20a%20Tree%20Node/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1483](https://leetcode.com/problems/kth-ancestor-of-a-tree-node)", "[Kth Ancestor of a Tree Node](/solution/1400-1499/1483.Kth%20Ancestor%20of%20a%20Tree%20Node/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1293", "frontend_question_id": "1550", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/three-consecutive-odds", "url_en": "https://leetcode.com/problems/three-consecutive-odds", "relative_path_cn": "/solution/1500-1599/1550.Three%20Consecutive%20Odds/README.md", "relative_path_en": "/solution/1500-1599/1550.Three%20Consecutive%20Odds/README_EN.md", "title_cn": "\u5b58\u5728\u8fde\u7eed\u4e09\u4e2a\u5947\u6570\u7684\u6570\u7ec4", "title_en": "Three Consecutive Odds", "question_title_slug": "three-consecutive-odds", "content_en": "Given an integer array arr, return true if there are three consecutive odd numbers in the array. Otherwise, return false.\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr = [2,6,4,1]\nOutput: false\nExplanation: There are no three consecutive odds.\n
    \n\n

    Example 2:

    \n\n
    \nInput: arr = [1,2,34,3,4,5,7,23,12]\nOutput: true\nExplanation: [5,7,23] are three consecutive odds.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= arr.length <= 1000
    • \n\t
    • 1 <= arr[i] <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr\uff0c\u8bf7\u4f60\u5224\u65ad\u6570\u7ec4\u4e2d\u662f\u5426\u5b58\u5728\u8fde\u7eed\u4e09\u4e2a\u5143\u7d20\u90fd\u662f\u5947\u6570\u7684\u60c5\u51b5\uff1a\u5982\u679c\u5b58\u5728\uff0c\u8bf7\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [2,6,4,1]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u4e0d\u5b58\u5728\u8fde\u7eed\u4e09\u4e2a\u5143\u7d20\u90fd\u662f\u5947\u6570\u7684\u60c5\u51b5\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [1,2,34,3,4,5,7,23,12]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u5b58\u5728\u8fde\u7eed\u4e09\u4e2a\u5143\u7d20\u90fd\u662f\u5947\u6570\u7684\u60c5\u51b5\uff0c\u5373 [5,7,23] \u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= arr.length <= 1000
    • \n\t
    • 1 <= arr[i] <= 1000
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool threeConsecutiveOdds(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean threeConsecutiveOdds(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def threeConsecutiveOdds(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def threeConsecutiveOdds(self, arr: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool threeConsecutiveOdds(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool ThreeConsecutiveOdds(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {boolean}\n */\nvar threeConsecutiveOdds = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Boolean}\ndef three_consecutive_odds(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func threeConsecutiveOdds(_ arr: [Int]) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func threeConsecutiveOdds(arr []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def threeConsecutiveOdds(arr: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun threeConsecutiveOdds(arr: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn three_consecutive_odds(arr: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Boolean\n */\n function threeConsecutiveOdds($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function threeConsecutiveOdds(arr: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (three-consecutive-odds arr)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1550](https://leetcode-cn.com/problems/three-consecutive-odds)", "[\u5b58\u5728\u8fde\u7eed\u4e09\u4e2a\u5947\u6570\u7684\u6570\u7ec4](/solution/1500-1599/1550.Three%20Consecutive%20Odds/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1550](https://leetcode.com/problems/three-consecutive-odds)", "[Three Consecutive Odds](/solution/1500-1599/1550.Three%20Consecutive%20Odds/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1292", "frontend_question_id": "1174", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/immediate-food-delivery-ii", "url_en": "https://leetcode.com/problems/immediate-food-delivery-ii", "relative_path_cn": "/solution/1100-1199/1174.Immediate%20Food%20Delivery%20II/README.md", "relative_path_en": "/solution/1100-1199/1174.Immediate%20Food%20Delivery%20II/README_EN.md", "title_cn": "\u5373\u65f6\u98df\u7269\u914d\u9001 II", "title_en": "Immediate Food Delivery II", "question_title_slug": "immediate-food-delivery-ii", "content_en": "

    Table: Delivery

    \n\n
    \n+-----------------------------+---------+\n| Column Name                 | Type    |\n+-----------------------------+---------+\n| delivery_id                 | int     |\n| customer_id                 | int     |\n| order_date                  | date    |\n| customer_pref_delivery_date | date    |\n+-----------------------------+---------+\ndelivery_id is the primary key of this table.\nThe table holds information about food delivery to customers that make orders at some date and specify a preferred delivery date (on the same order date or after it).\n
    \n\n

     

    \n\n

    If the preferred delivery date of the customer is the same as the order date then the order is called immediate otherwise it's called scheduled.

    \n\n

    The first order of a customer is the order with the earliest order date that customer made. It is guaranteed that a customer has exactly one first order.

    \n\n

    Write an SQL query to find the percentage of immediate orders in the first orders of all customers, rounded to 2 decimal places.

    \n\n

    The query result format is in the following example:

    \n\n
    \nDelivery table:\n+-------------+-------------+------------+-----------------------------+\n| delivery_id | customer_id | order_date | customer_pref_delivery_date |\n+-------------+-------------+------------+-----------------------------+\n| 1           | 1           | 2019-08-01 | 2019-08-02                  |\n| 2           | 2           | 2019-08-02 | 2019-08-02                  |\n| 3           | 1           | 2019-08-11 | 2019-08-12                  |\n| 4           | 3           | 2019-08-24 | 2019-08-24                  |\n| 5           | 3           | 2019-08-21 | 2019-08-22                  |\n| 6           | 2           | 2019-08-11 | 2019-08-13                  |\n| 7           | 4           | 2019-08-09 | 2019-08-09                  |\n+-------------+-------------+------------+-----------------------------+\n\nResult table:\n+----------------------+\n| immediate_percentage |\n+----------------------+\n| 50.00                |\n+----------------------+\nThe customer id 1 has a first order with delivery id 1 and it is scheduled.\nThe customer id 2 has a first order with delivery id 2 and it is immediate.\nThe customer id 3 has a first order with delivery id 5 and it is scheduled.\nThe customer id 4 has a first order with delivery id 7 and it is immediate.\nHence, half the customers have immediate first orders.\n
    \n", "content_cn": "

    \u914d\u9001\u8868: Delivery

    \n\n
    +-----------------------------+---------+\n| Column Name                 | Type    |\n+-----------------------------+---------+\n| delivery_id                 | int     |\n| customer_id                 | int     |\n| order_date                  | date    |\n| customer_pref_delivery_date | date    |\n+-----------------------------+---------+\ndelivery_id \u662f\u8868\u7684\u4e3b\u952e\u3002\n\u8be5\u8868\u4fdd\u5b58\u7740\u987e\u5ba2\u7684\u98df\u7269\u914d\u9001\u4fe1\u606f\uff0c\u987e\u5ba2\u5728\u67d0\u4e2a\u65e5\u671f\u4e0b\u4e86\u8ba2\u5355\uff0c\u5e76\u6307\u5b9a\u4e86\u4e00\u4e2a\u671f\u671b\u7684\u914d\u9001\u65e5\u671f\uff08\u548c\u4e0b\u5355\u65e5\u671f\u76f8\u540c\u6216\u8005\u5728\u90a3\u4e4b\u540e\uff09\u3002\n
    \n\n

     

    \n\n

    \u5982\u679c\u987e\u5ba2\u671f\u671b\u7684\u914d\u9001\u65e5\u671f\u548c\u4e0b\u5355\u65e5\u671f\u76f8\u540c\uff0c\u5219\u8be5\u8ba2\u5355\u79f0\u4e3a \u300c\u5373\u65f6\u8ba2\u5355\u300d\uff0c\u5426\u5219\u79f0\u4e3a\u300c\u8ba1\u5212\u8ba2\u5355\u300d\u3002

    \n\n

    \u300c\u9996\u6b21\u8ba2\u5355\u300d\u662f\u987e\u5ba2\u6700\u65e9\u521b\u5efa\u7684\u8ba2\u5355\u3002\u6211\u4eec\u4fdd\u8bc1\u4e00\u4e2a\u987e\u5ba2\u53ea\u4f1a\u6709\u4e00\u4e2a\u300c\u9996\u6b21\u8ba2\u5355\u300d\u3002

    \n\n

    \u5199\u4e00\u6761 SQL \u67e5\u8be2\u8bed\u53e5\u83b7\u53d6\u5373\u65f6\u8ba2\u5355\u5728\u6240\u6709\u7528\u6237\u7684\u9996\u6b21\u8ba2\u5355\u4e2d\u7684\u6bd4\u4f8b\u3002\u4fdd\u7559\u4e24\u4f4d\u5c0f\u6570\u3002

    \n\n

     

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u5982\u4e0b\u6240\u793a\uff1a

    \n\n
    Delivery \u8868\uff1a\n+-------------+-------------+------------+-----------------------------+\n| delivery_id | customer_id | order_date | customer_pref_delivery_date |\n+-------------+-------------+------------+-----------------------------+\n| 1           | 1           | 2019-08-01 | 2019-08-02                  |\n| 2           | 2           | 2019-08-02 | 2019-08-02                  |\n| 3           | 1           | 2019-08-11 | 2019-08-12                  |\n| 4           | 3           | 2019-08-24 | 2019-08-24                  |\n| 5           | 3           | 2019-08-21 | 2019-08-22                  |\n| 6           | 2           | 2019-08-11 | 2019-08-13                  |\n| 7           | 4           | 2019-08-09 | 2019-08-09                  |\n+-------------+-------------+------------+-----------------------------+\n\nResult \u8868\uff1a\n+----------------------+\n| immediate_percentage |\n+----------------------+\n| 50.00                |\n+----------------------+\n1 \u53f7\u987e\u5ba2\u7684 1 \u53f7\u8ba2\u5355\u662f\u9996\u6b21\u8ba2\u5355\uff0c\u5e76\u4e14\u662f\u8ba1\u5212\u8ba2\u5355\u3002\n2 \u53f7\u987e\u5ba2\u7684 2 \u53f7\u8ba2\u5355\u662f\u9996\u6b21\u8ba2\u5355\uff0c\u5e76\u4e14\u662f\u5373\u65f6\u8ba2\u5355\u3002\n3 \u53f7\u987e\u5ba2\u7684 5 \u53f7\u8ba2\u5355\u662f\u9996\u6b21\u8ba2\u5355\uff0c\u5e76\u4e14\u662f\u8ba1\u5212\u8ba2\u5355\u3002\n4 \u53f7\u987e\u5ba2\u7684 7 \u53f7\u8ba2\u5355\u662f\u9996\u6b21\u8ba2\u5355\uff0c\u5e76\u4e14\u662f\u5373\u65f6\u8ba2\u5355\u3002\n\u56e0\u6b64\uff0c\u4e00\u534a\u987e\u5ba2\u7684\u9996\u6b21\u8ba2\u5355\u662f\u5373\u65f6\u7684\u3002\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1174](https://leetcode-cn.com/problems/immediate-food-delivery-ii)", "[\u5373\u65f6\u98df\u7269\u914d\u9001 II](/solution/1100-1199/1174.Immediate%20Food%20Delivery%20II/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1174](https://leetcode.com/problems/immediate-food-delivery-ii)", "[Immediate Food Delivery II](/solution/1100-1199/1174.Immediate%20Food%20Delivery%20II/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1291", "frontend_question_id": "1173", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/immediate-food-delivery-i", "url_en": "https://leetcode.com/problems/immediate-food-delivery-i", "relative_path_cn": "/solution/1100-1199/1173.Immediate%20Food%20Delivery%20I/README.md", "relative_path_en": "/solution/1100-1199/1173.Immediate%20Food%20Delivery%20I/README_EN.md", "title_cn": "\u5373\u65f6\u98df\u7269\u914d\u9001 I", "title_en": "Immediate Food Delivery I", "question_title_slug": "immediate-food-delivery-i", "content_en": "

    Table: Delivery

    \n\n
    \n+-----------------------------+---------+\n| Column Name                 | Type    |\n+-----------------------------+---------+\n| delivery_id                 | int     |\n| customer_id                 | int     |\n| order_date                  | date    |\n| customer_pref_delivery_date | date    |\n+-----------------------------+---------+\ndelivery_id is the primary key of this table.\nThe table holds information about food delivery to customers that make orders at some date and specify a preferred delivery date (on the same order date or after it).\n
    \n\n

     

    \n\n

    If the preferred delivery date of the customer is the same as the order date then the order is called immediate otherwise it's called scheduled.

    \n\n

    Write an SQL query to find the percentage of immediate orders in the table, rounded to 2 decimal places.

    \n\n

    The query result format is in the following example:

    \n\n
    \nDelivery table:\n+-------------+-------------+------------+-----------------------------+\n| delivery_id | customer_id | order_date | customer_pref_delivery_date |\n+-------------+-------------+------------+-----------------------------+\n| 1           | 1           | 2019-08-01 | 2019-08-02                  |\n| 2           | 5           | 2019-08-02 | 2019-08-02                  |\n| 3           | 1           | 2019-08-11 | 2019-08-11                  |\n| 4           | 3           | 2019-08-24 | 2019-08-26                  |\n| 5           | 4           | 2019-08-21 | 2019-08-22                  |\n| 6           | 2           | 2019-08-11 | 2019-08-13                  |\n+-------------+-------------+------------+-----------------------------+\n\nResult table:\n+----------------------+\n| immediate_percentage |\n+----------------------+\n| 33.33                |\n+----------------------+\nThe orders with delivery id 2 and 3 are immediate while the others are scheduled.\n
    \n", "content_cn": "

    \u914d\u9001\u8868: Delivery

    \n\n
    +-----------------------------+---------+\n| Column Name                 | Type    |\n+-----------------------------+---------+\n| delivery_id                 | int     |\n| customer_id                 | int     |\n| order_date                  | date    |\n| customer_pref_delivery_date | date    |\n+-----------------------------+---------+\ndelivery_id \u662f\u8868\u7684\u4e3b\u952e\u3002\n\u8be5\u8868\u4fdd\u5b58\u7740\u987e\u5ba2\u7684\u98df\u7269\u914d\u9001\u4fe1\u606f\uff0c\u987e\u5ba2\u5728\u67d0\u4e2a\u65e5\u671f\u4e0b\u4e86\u8ba2\u5355\uff0c\u5e76\u6307\u5b9a\u4e86\u4e00\u4e2a\u671f\u671b\u7684\u914d\u9001\u65e5\u671f\uff08\u548c\u4e0b\u5355\u65e5\u671f\u76f8\u540c\u6216\u8005\u5728\u90a3\u4e4b\u540e\uff09\u3002\n
    \n\n

     

    \n\n

    \u5982\u679c\u987e\u5ba2\u671f\u671b\u7684\u914d\u9001\u65e5\u671f\u548c\u4e0b\u5355\u65e5\u671f\u76f8\u540c\uff0c\u5219\u8be5\u8ba2\u5355\u79f0\u4e3a \u300c\u5373\u65f6\u8ba2\u5355\u300d\uff0c\u5426\u5219\u79f0\u4e3a\u300c\u8ba1\u5212\u8ba2\u5355\u300d\u3002

    \n\n

    \u5199\u4e00\u6761 SQL \u67e5\u8be2\u8bed\u53e5\u83b7\u53d6\u5373\u65f6\u8ba2\u5355\u6240\u5360\u7684\u767e\u5206\u6bd4\uff0c \u4fdd\u7559\u4e24\u4f4d\u5c0f\u6570\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u5982\u4e0b\u6240\u793a\uff1a

    \n\n
    Delivery \u8868:\n+-------------+-------------+------------+-----------------------------+\n| delivery_id | customer_id | order_date | customer_pref_delivery_date |\n+-------------+-------------+------------+-----------------------------+\n| 1           | 1           | 2019-08-01 | 2019-08-02                  |\n| 2           | 5           | 2019-08-02 | 2019-08-02                  |\n| 3           | 1           | 2019-08-11 | 2019-08-11                  |\n| 4           | 3           | 2019-08-24 | 2019-08-26                  |\n| 5           | 4           | 2019-08-21 | 2019-08-22                  |\n| 6           | 2           | 2019-08-11 | 2019-08-13                  |\n+-------------+-------------+------------+-----------------------------+\n\nResult \u8868:\n+----------------------+\n| immediate_percentage |\n+----------------------+\n| 33.33                |\n+----------------------+\n2 \u548c 3 \u53f7\u8ba2\u5355\u4e3a\u5373\u65f6\u8ba2\u5355\uff0c\u5176\u4ed6\u7684\u4e3a\u8ba1\u5212\u8ba2\u5355\u3002
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1173](https://leetcode-cn.com/problems/immediate-food-delivery-i)", "[\u5373\u65f6\u98df\u7269\u914d\u9001 I](/solution/1100-1199/1173.Immediate%20Food%20Delivery%20I/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1173](https://leetcode.com/problems/immediate-food-delivery-i)", "[Immediate Food Delivery I](/solution/1100-1199/1173.Immediate%20Food%20Delivery%20I/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1290", "frontend_question_id": "1187", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/make-array-strictly-increasing", "url_en": "https://leetcode.com/problems/make-array-strictly-increasing", "relative_path_cn": "/solution/1100-1199/1187.Make%20Array%20Strictly%20Increasing/README.md", "relative_path_en": "/solution/1100-1199/1187.Make%20Array%20Strictly%20Increasing/README_EN.md", "title_cn": "\u4f7f\u6570\u7ec4\u4e25\u683c\u9012\u589e", "title_en": "Make Array Strictly Increasing", "question_title_slug": "make-array-strictly-increasing", "content_en": "

    Given two integer arrays arr1 and arr2, return the minimum number of operations (possibly zero) needed to make arr1 strictly increasing.

    \r\n\r\n

    In one operation, you can choose two indices 0 <= i < arr1.length and 0 <= j < arr2.length and do the assignment arr1[i] = arr2[j].

    \r\n\r\n

    If there is no way to make arr1 strictly increasing, return -1.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: arr1 = [1,5,3,6,7], arr2 = [1,3,2,4]\r\nOutput: 1\r\nExplanation: Replace 5 with 2, then arr1 = [1, 2, 3, 6, 7].\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: arr1 = [1,5,3,6,7], arr2 = [4,3,1]\r\nOutput: 2\r\nExplanation: Replace 5 with 3 and then replace 3 with 4. arr1 = [1, 3, 4, 6, 7].\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: arr1 = [1,5,3,6,7], arr2 = [1,6,3,3]\r\nOutput: -1\r\nExplanation: You can't make arr1 strictly increasing.
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= arr1.length, arr2.length <= 2000
    • \r\n\t
    • 0 <= arr1[i], arr2[i] <= 10^9
    • \r\n
    \r\n\r\n

     

    ", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u6574\u6570\u6570\u7ec4 arr1 \u548c arr2\uff0c\u8fd4\u56de\u4f7f arr1 \u4e25\u683c\u9012\u589e\u6240\u9700\u8981\u7684\u6700\u5c0f\u300c\u64cd\u4f5c\u300d\u6570\uff08\u53ef\u80fd\u4e3a 0\uff09\u3002

    \n\n

    \u6bcf\u4e00\u6b65\u300c\u64cd\u4f5c\u300d\u4e2d\uff0c\u4f60\u53ef\u4ee5\u5206\u522b\u4ece arr1 \u548c arr2 \u4e2d\u5404\u9009\u51fa\u4e00\u4e2a\u7d22\u5f15\uff0c\u5206\u522b\u4e3a i \u548c j\uff0c0 <= i < arr1.length \u548c 0 <= j < arr2.length\uff0c\u7136\u540e\u8fdb\u884c\u8d4b\u503c\u8fd0\u7b97 arr1[i] = arr2[j]\u3002

    \n\n

    \u5982\u679c\u65e0\u6cd5\u8ba9 arr1 \u4e25\u683c\u9012\u589e\uff0c\u8bf7\u8fd4\u56de -1\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aarr1 = [1,5,3,6,7], arr2 = [1,3,2,4]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u7528 2 \u6765\u66ff\u6362 5\uff0c\u4e4b\u540e arr1 = [1, 2, 3, 6, 7]\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aarr1 = [1,5,3,6,7], arr2 = [4,3,1]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u7528 3 \u6765\u66ff\u6362 5\uff0c\u7136\u540e\u7528 4 \u6765\u66ff\u6362 3\uff0c\u5f97\u5230 arr1 = [1, 3, 4, 6, 7]\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aarr1 = [1,5,3,6,7], arr2 = [1,6,3,3]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u65e0\u6cd5\u4f7f arr1 \u4e25\u683c\u9012\u589e\u3002
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= arr1.length, arr2.length <= 2000
    • \n\t
    • 0 <= arr1[i], arr2[i] <= 10^9
    • \n
    \n\n

     

    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int makeArrayIncreasing(vector& arr1, vector& arr2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int makeArrayIncreasing(int[] arr1, int[] arr2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def makeArrayIncreasing(self, arr1, arr2):\n \"\"\"\n :type arr1: List[int]\n :type arr2: List[int]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def makeArrayIncreasing(self, arr1: List[int], arr2: List[int]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint makeArrayIncreasing(int* arr1, int arr1Size, int* arr2, int arr2Size){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MakeArrayIncreasing(int[] arr1, int[] arr2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr1\n * @param {number[]} arr2\n * @return {number}\n */\nvar makeArrayIncreasing = function(arr1, arr2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr1\n# @param {Integer[]} arr2\n# @return {Integer}\ndef make_array_increasing(arr1, arr2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func makeArrayIncreasing(_ arr1: [Int], _ arr2: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func makeArrayIncreasing(arr1 []int, arr2 []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def makeArrayIncreasing(arr1: Array[Int], arr2: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun makeArrayIncreasing(arr1: IntArray, arr2: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn make_array_increasing(arr1: Vec, arr2: Vec) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr1\n * @param Integer[] $arr2\n * @return Integer\n */\n function makeArrayIncreasing($arr1, $arr2) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function makeArrayIncreasing(arr1: number[], arr2: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (make-array-increasing arr1 arr2)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1187](https://leetcode-cn.com/problems/make-array-strictly-increasing)", "[\u4f7f\u6570\u7ec4\u4e25\u683c\u9012\u589e](/solution/1100-1199/1187.Make%20Array%20Strictly%20Increasing/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1187](https://leetcode.com/problems/make-array-strictly-increasing)", "[Make Array Strictly Increasing](/solution/1100-1199/1187.Make%20Array%20Strictly%20Increasing/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1289", "frontend_question_id": "1185", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/day-of-the-week", "url_en": "https://leetcode.com/problems/day-of-the-week", "relative_path_cn": "/solution/1100-1199/1185.Day%20of%20the%20Week/README.md", "relative_path_en": "/solution/1100-1199/1185.Day%20of%20the%20Week/README_EN.md", "title_cn": "\u4e00\u5468\u4e2d\u7684\u7b2c\u51e0\u5929", "title_en": "Day of the Week", "question_title_slug": "day-of-the-week", "content_en": "

    Given a date, return the corresponding day of the week for that date.

    \n\n

    The input is given as three integers representing the day, month and year respectively.

    \n\n

    Return the answer as one of the following values {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: day = 31, month = 8, year = 2019\nOutput: "Saturday"\n
    \n\n

    Example 2:

    \n\n
    \nInput: day = 18, month = 7, year = 1999\nOutput: "Sunday"\n
    \n\n

    Example 3:

    \n\n
    \nInput: day = 15, month = 8, year = 1993\nOutput: "Sunday"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The given dates are valid dates between the years 1971 and 2100.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u65e5\u671f\uff0c\u8bf7\u4f60\u8bbe\u8ba1\u4e00\u4e2a\u7b97\u6cd5\u6765\u5224\u65ad\u5b83\u662f\u5bf9\u5e94\u4e00\u5468\u4e2d\u7684\u54ea\u4e00\u5929\u3002

    \n\n

    \u8f93\u5165\u4e3a\u4e09\u4e2a\u6574\u6570\uff1aday\u3001month \u548c year\uff0c\u5206\u522b\u8868\u793a\u65e5\u3001\u6708\u3001\u5e74\u3002

    \n\n

    \u60a8\u8fd4\u56de\u7684\u7ed3\u679c\u5fc5\u987b\u662f\u8fd9\u51e0\u4e2a\u503c\u4e2d\u7684\u4e00\u4e2a {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aday = 31, month = 8, year = 2019\n\u8f93\u51fa\uff1a"Saturday"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aday = 18, month = 7, year = 1999\n\u8f93\u51fa\uff1a"Sunday"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aday = 15, month = 8, year = 1993\n\u8f93\u51fa\uff1a"Sunday"\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u7ed9\u51fa\u7684\u65e5\u671f\u4e00\u5b9a\u662f\u5728 1971 \u5230 2100 \u5e74\u4e4b\u95f4\u7684\u6709\u6548\u65e5\u671f\u3002
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string dayOfTheWeek(int day, int month, int year) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String dayOfTheWeek(int day, int month, int year) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def dayOfTheWeek(self, day, month, year):\n \"\"\"\n :type day: int\n :type month: int\n :type year: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def dayOfTheWeek(self, day: int, month: int, year: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * dayOfTheWeek(int day, int month, int year){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string DayOfTheWeek(int day, int month, int year) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} day\n * @param {number} month\n * @param {number} year\n * @return {string}\n */\nvar dayOfTheWeek = function(day, month, year) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} day\n# @param {Integer} month\n# @param {Integer} year\n# @return {String}\ndef day_of_the_week(day, month, year)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func dayOfTheWeek(_ day: Int, _ month: Int, _ year: Int) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func dayOfTheWeek(day int, month int, year int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def dayOfTheWeek(day: Int, month: Int, year: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun dayOfTheWeek(day: Int, month: Int, year: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn day_of_the_week(day: i32, month: i32, year: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $day\n * @param Integer $month\n * @param Integer $year\n * @return String\n */\n function dayOfTheWeek($day, $month, $year) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function dayOfTheWeek(day: number, month: number, year: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (day-of-the-week day month year)\n (-> exact-integer? exact-integer? exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1185](https://leetcode-cn.com/problems/day-of-the-week)", "[\u4e00\u5468\u4e2d\u7684\u7b2c\u51e0\u5929](/solution/1100-1199/1185.Day%20of%20the%20Week/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1185](https://leetcode.com/problems/day-of-the-week)", "[Day of the Week](/solution/1100-1199/1185.Day%20of%20the%20Week/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1288", "frontend_question_id": "1186", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-subarray-sum-with-one-deletion", "url_en": "https://leetcode.com/problems/maximum-subarray-sum-with-one-deletion", "relative_path_cn": "/solution/1100-1199/1186.Maximum%20Subarray%20Sum%20with%20One%20Deletion/README.md", "relative_path_en": "/solution/1100-1199/1186.Maximum%20Subarray%20Sum%20with%20One%20Deletion/README_EN.md", "title_cn": "\u5220\u9664\u4e00\u6b21\u5f97\u5230\u5b50\u6570\u7ec4\u6700\u5927\u548c", "title_en": "Maximum Subarray Sum with One Deletion", "question_title_slug": "maximum-subarray-sum-with-one-deletion", "content_en": "

    Given an array of integers, return the maximum sum for a non-empty subarray (contiguous elements) with at most one element deletion. In other words, you want to choose a subarray and optionally delete one element from it so that there is still at least one element left and the sum of the remaining elements is maximum possible.

    \n\n

    Note that the subarray needs to be non-empty after deleting one element.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr = [1,-2,0,3]\nOutput: 4\nExplanation: Because we can choose [1, -2, 0, 3] and drop -2, thus the subarray [1, 0, 3] becomes the maximum value.
    \n\n

    Example 2:

    \n\n
    \nInput: arr = [1,-2,-2,3]\nOutput: 3\nExplanation: We just choose [3] and it's the maximum sum.\n
    \n\n

    Example 3:

    \n\n
    \nInput: arr = [-1,-1,-1,-1]\nOutput: -1\nExplanation: The final subarray needs to be non-empty. You can't choose [-1] and delete -1 from it, then get an empty subarray to make the sum equals to 0.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= arr.length <= 105
    • \n\t
    • -104 <= arr[i] <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\uff0c\u8fd4\u56de\u5b83\u7684\u67d0\u4e2a \u975e\u7a7a \u5b50\u6570\u7ec4\uff08\u8fde\u7eed\u5143\u7d20\uff09\u5728\u6267\u884c\u4e00\u6b21\u53ef\u9009\u7684\u5220\u9664\u64cd\u4f5c\u540e\uff0c\u6240\u80fd\u5f97\u5230\u7684\u6700\u5927\u5143\u7d20\u603b\u548c\u3002

    \n\n

    \u6362\u53e5\u8bdd\u8bf4\uff0c\u4f60\u53ef\u4ee5\u4ece\u539f\u6570\u7ec4\u4e2d\u9009\u51fa\u4e00\u4e2a\u5b50\u6570\u7ec4\uff0c\u5e76\u53ef\u4ee5\u51b3\u5b9a\u8981\u4e0d\u8981\u4ece\u4e2d\u5220\u9664\u4e00\u4e2a\u5143\u7d20\uff08\u53ea\u80fd\u5220\u4e00\u6b21\u54e6\uff09\uff0c\uff08\u5220\u9664\u540e\uff09\u5b50\u6570\u7ec4\u4e2d\u81f3\u5c11\u5e94\u5f53\u6709\u4e00\u4e2a\u5143\u7d20\uff0c\u7136\u540e\u8be5\u5b50\u6570\u7ec4\uff08\u5269\u4e0b\uff09\u7684\u5143\u7d20\u603b\u548c\u662f\u6240\u6709\u5b50\u6570\u7ec4\u4e4b\u4e2d\u6700\u5927\u7684\u3002

    \n\n

    \u6ce8\u610f\uff0c\u5220\u9664\u4e00\u4e2a\u5143\u7d20\u540e\uff0c\u5b50\u6570\u7ec4 \u4e0d\u80fd\u4e3a\u7a7a\u3002

    \n\n

    \u8bf7\u770b\u793a\u4f8b\uff1a

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [1,-2,0,3]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u6211\u4eec\u53ef\u4ee5\u9009\u51fa [1, -2, 0, 3]\uff0c\u7136\u540e\u5220\u6389 -2\uff0c\u8fd9\u6837\u5f97\u5230 [1, 0, 3]\uff0c\u548c\u6700\u5927\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [1,-2,-2,3]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6211\u4eec\u76f4\u63a5\u9009\u51fa [3]\uff0c\u8fd9\u5c31\u662f\u6700\u5927\u548c\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [-1,-1,-1,-1]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u6700\u540e\u5f97\u5230\u7684\u5b50\u6570\u7ec4\u4e0d\u80fd\u4e3a\u7a7a\uff0c\u6240\u4ee5\u6211\u4eec\u4e0d\u80fd\u9009\u62e9 [-1] \u5e76\u4ece\u4e2d\u5220\u53bb -1 \u6765\u5f97\u5230 0\u3002\n     \u6211\u4eec\u5e94\u8be5\u76f4\u63a5\u9009\u62e9 [-1]\uff0c\u6216\u8005\u9009\u62e9 [-1, -1] \u518d\u4ece\u4e2d\u5220\u53bb\u4e00\u4e2a -1\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= arr.length <= 10^5
    • \n\t
    • -10^4 <= arr[i] <= 10^4
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maximumSum(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maximumSum(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximumSum(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximumSum(self, arr: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maximumSum(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaximumSum(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar maximumSum = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef maximum_sum(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximumSum(_ arr: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximumSum(arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximumSum(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximumSum(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximum_sum(arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function maximumSum($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximumSum(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximum-sum arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1186](https://leetcode-cn.com/problems/maximum-subarray-sum-with-one-deletion)", "[\u5220\u9664\u4e00\u6b21\u5f97\u5230\u5b50\u6570\u7ec4\u6700\u5927\u548c](/solution/1100-1199/1186.Maximum%20Subarray%20Sum%20with%20One%20Deletion/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1186](https://leetcode.com/problems/maximum-subarray-sum-with-one-deletion)", "[Maximum Subarray Sum with One Deletion](/solution/1100-1199/1186.Maximum%20Subarray%20Sum%20with%20One%20Deletion/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "1287", "frontend_question_id": "1184", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/distance-between-bus-stops", "url_en": "https://leetcode.com/problems/distance-between-bus-stops", "relative_path_cn": "/solution/1100-1199/1184.Distance%20Between%20Bus%20Stops/README.md", "relative_path_en": "/solution/1100-1199/1184.Distance%20Between%20Bus%20Stops/README_EN.md", "title_cn": "\u516c\u4ea4\u7ad9\u95f4\u7684\u8ddd\u79bb", "title_en": "Distance Between Bus Stops", "question_title_slug": "distance-between-bus-stops", "content_en": "

    A bus has n stops numbered from 0 to n - 1 that form a circle. We know the distance between all pairs of neighboring stops where distance[i] is the distance between the stops number i and (i + 1) % n.

    \r\n\r\n

    The bus goes along both directions i.e. clockwise and counterclockwise.

    \r\n\r\n

    Return the shortest distance between the given start and destination stops.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n

    \"\"

    \r\n\r\n
    \r\nInput: distance = [1,2,3,4], start = 0, destination = 1\r\nOutput: 1\r\nExplanation: Distance between 0 and 1 is 1 or 9, minimum is 1.
    \r\n\r\n

     

    \r\n\r\n

    Example 2:

    \r\n\r\n

    \"\"

    \r\n\r\n
    \r\nInput: distance = [1,2,3,4], start = 0, destination = 2\r\nOutput: 3\r\nExplanation: Distance between 0 and 2 is 3 or 7, minimum is 3.\r\n
    \r\n\r\n

     

    \r\n\r\n

    Example 3:

    \r\n\r\n

    \"\"

    \r\n\r\n
    \r\nInput: distance = [1,2,3,4], start = 0, destination = 3\r\nOutput: 4\r\nExplanation: Distance between 0 and 3 is 6 or 4, minimum is 4.\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= n <= 10^4
    • \r\n\t
    • distance.length == n
    • \r\n\t
    • 0 <= start, destination < n
    • \r\n\t
    • 0 <= distance[i] <= 10^4
    • \r\n
    ", "content_cn": "

    \u73af\u5f62\u516c\u4ea4\u8def\u7ebf\u4e0a\u6709 n \u4e2a\u7ad9\uff0c\u6309\u6b21\u5e8f\u4ece 0 \u5230 n - 1 \u8fdb\u884c\u7f16\u53f7\u3002\u6211\u4eec\u5df2\u77e5\u6bcf\u4e00\u5bf9\u76f8\u90bb\u516c\u4ea4\u7ad9\u4e4b\u95f4\u7684\u8ddd\u79bb\uff0cdistance[i] \u8868\u793a\u7f16\u53f7\u4e3a i \u7684\u8f66\u7ad9\u548c\u7f16\u53f7\u4e3a (i + 1) % n \u7684\u8f66\u7ad9\u4e4b\u95f4\u7684\u8ddd\u79bb\u3002

    \n\n

    \u73af\u7ebf\u4e0a\u7684\u516c\u4ea4\u8f66\u90fd\u53ef\u4ee5\u6309\u987a\u65f6\u9488\u548c\u9006\u65f6\u9488\u7684\u65b9\u5411\u884c\u9a76\u3002

    \n\n

    \u8fd4\u56de\u4e58\u5ba2\u4ece\u51fa\u53d1\u70b9 start \u5230\u76ee\u7684\u5730 destination \u4e4b\u95f4\u7684\u6700\u77ed\u8ddd\u79bb\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1adistance = [1,2,3,4], start = 0, destination = 1\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u516c\u4ea4\u7ad9 0 \u548c 1 \u4e4b\u95f4\u7684\u8ddd\u79bb\u662f 1 \u6216 9\uff0c\u6700\u5c0f\u503c\u662f 1\u3002
    \n\n

     

    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1adistance = [1,2,3,4], start = 0, destination = 2\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u516c\u4ea4\u7ad9 0 \u548c 2 \u4e4b\u95f4\u7684\u8ddd\u79bb\u662f 3 \u6216 7\uff0c\u6700\u5c0f\u503c\u662f 3\u3002\n
    \n\n

     

    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1adistance = [1,2,3,4], start = 0, destination = 3\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u516c\u4ea4\u7ad9 0 \u548c 3 \u4e4b\u95f4\u7684\u8ddd\u79bb\u662f 6 \u6216 4\uff0c\u6700\u5c0f\u503c\u662f 4\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 10^4
    • \n\t
    • distance.length == n
    • \n\t
    • 0 <= start, destination < n
    • \n\t
    • 0 <= distance[i] <= 10^4
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int distanceBetweenBusStops(vector& distance, int start, int destination) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int distanceBetweenBusStops(int[] distance, int start, int destination) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def distanceBetweenBusStops(self, distance, start, destination):\n \"\"\"\n :type distance: List[int]\n :type start: int\n :type destination: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def distanceBetweenBusStops(self, distance: List[int], start: int, destination: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint distanceBetweenBusStops(int* distance, int distanceSize, int start, int destination){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int DistanceBetweenBusStops(int[] distance, int start, int destination) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} distance\n * @param {number} start\n * @param {number} destination\n * @return {number}\n */\nvar distanceBetweenBusStops = function(distance, start, destination) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} distance\n# @param {Integer} start\n# @param {Integer} destination\n# @return {Integer}\ndef distance_between_bus_stops(distance, start, destination)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func distanceBetweenBusStops(_ distance: [Int], _ start: Int, _ destination: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func distanceBetweenBusStops(distance []int, start int, destination int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def distanceBetweenBusStops(distance: Array[Int], start: Int, destination: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun distanceBetweenBusStops(distance: IntArray, start: Int, destination: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn distance_between_bus_stops(distance: Vec, start: i32, destination: i32) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $distance\n * @param Integer $start\n * @param Integer $destination\n * @return Integer\n */\n function distanceBetweenBusStops($distance, $start, $destination) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function distanceBetweenBusStops(distance: number[], start: number, destination: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (distance-between-bus-stops distance start destination)\n (-> (listof exact-integer?) exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1184](https://leetcode-cn.com/problems/distance-between-bus-stops)", "[\u516c\u4ea4\u7ad9\u95f4\u7684\u8ddd\u79bb](/solution/1100-1199/1184.Distance%20Between%20Bus%20Stops/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1184](https://leetcode.com/problems/distance-between-bus-stops)", "[Distance Between Bus Stops](/solution/1100-1199/1184.Distance%20Between%20Bus%20Stops/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1286", "frontend_question_id": "1425", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/constrained-subsequence-sum", "url_en": "https://leetcode.com/problems/constrained-subsequence-sum", "relative_path_cn": "/solution/1400-1499/1425.Constrained%20Subsequence%20Sum/README.md", "relative_path_en": "/solution/1400-1499/1425.Constrained%20Subsequence%20Sum/README_EN.md", "title_cn": "\u5e26\u9650\u5236\u7684\u5b50\u5e8f\u5217\u548c", "title_en": "Constrained Subsequence Sum", "question_title_slug": "constrained-subsequence-sum", "content_en": "

    Given an integer array nums and an integer k, return the maximum sum of a non-empty subsequence of that array such that for every two consecutive integers in the subsequence, nums[i] and nums[j], where i < j, the condition j - i <= k is satisfied.

    \n\n

    A subsequence of an array is obtained by deleting some number of elements (can be zero) from the array, leaving the remaining elements in their original order.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [10,2,-10,5,20], k = 2\nOutput: 37\nExplanation: The subsequence is [10, 2, 5, 20].\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [-1,-2,-3], k = 1\nOutput: -1\nExplanation: The subsequence must be non-empty, so we choose the largest number.\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [10,-2,-10,-5,20], k = 2\nOutput: 23\nExplanation: The subsequence is [10, -2, -5, 20].\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= k <= nums.length <= 105
    • \n\t
    • -104 <= nums[i] <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \u548c\u4e00\u4e2a\u6574\u6570 k \uff0c\u8bf7\u4f60\u8fd4\u56de \u975e\u7a7a \u5b50\u5e8f\u5217\u5143\u7d20\u548c\u7684\u6700\u5927\u503c\uff0c\u5b50\u5e8f\u5217\u9700\u8981\u6ee1\u8db3\uff1a\u5b50\u5e8f\u5217\u4e2d\u6bcf\u4e24\u4e2a \u76f8\u90bb \u7684\u6574\u6570 nums[i] \u548c nums[j] \uff0c\u5b83\u4eec\u5728\u539f\u6570\u7ec4\u4e2d\u7684\u4e0b\u6807 i \u548c j \u6ee1\u8db3 i < j \u4e14 j - i <= k \u3002

    \n\n

    \u6570\u7ec4\u7684\u5b50\u5e8f\u5217\u5b9a\u4e49\u4e3a\uff1a\u5c06\u6570\u7ec4\u4e2d\u7684\u82e5\u5e72\u4e2a\u6570\u5b57\u5220\u9664\uff08\u53ef\u4ee5\u5220\u9664 0 \u4e2a\u6570\u5b57\uff09\uff0c\u5269\u4e0b\u7684\u6570\u5b57\u6309\u7167\u539f\u672c\u7684\u987a\u5e8f\u6392\u5e03\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [10,2,-10,5,20], k = 2\n\u8f93\u51fa\uff1a37\n\u89e3\u91ca\uff1a\u5b50\u5e8f\u5217\u4e3a [10, 2, 5, 20] \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [-1,-2,-3], k = 1\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u5b50\u5e8f\u5217\u5fc5\u987b\u662f\u975e\u7a7a\u7684\uff0c\u6240\u4ee5\u6211\u4eec\u9009\u62e9\u6700\u5927\u7684\u6570\u5b57\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [10,-2,-10,-5,20], k = 2\n\u8f93\u51fa\uff1a23\n\u89e3\u91ca\uff1a\u5b50\u5e8f\u5217\u4e3a [10, -2, -5, 20] \u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= k <= nums.length <= 10^5
    • \n\t
    • -10^4 <= nums[i] <= 10^4
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int constrainedSubsetSum(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int constrainedSubsetSum(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def constrainedSubsetSum(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def constrainedSubsetSum(self, nums: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint constrainedSubsetSum(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ConstrainedSubsetSum(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar constrainedSubsetSum = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef constrained_subset_sum(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func constrainedSubsetSum(_ nums: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func constrainedSubsetSum(nums []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def constrainedSubsetSum(nums: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun constrainedSubsetSum(nums: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn constrained_subset_sum(nums: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer\n */\n function constrainedSubsetSum($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function constrainedSubsetSum(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (constrained-subset-sum nums k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1425](https://leetcode-cn.com/problems/constrained-subsequence-sum)", "[\u5e26\u9650\u5236\u7684\u5b50\u5e8f\u5217\u548c](/solution/1400-1499/1425.Constrained%20Subsequence%20Sum/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1425](https://leetcode.com/problems/constrained-subsequence-sum)", "[Constrained Subsequence Sum](/solution/1400-1499/1425.Constrained%20Subsequence%20Sum/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1285", "frontend_question_id": "1382", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/balance-a-binary-search-tree", "url_en": "https://leetcode.com/problems/balance-a-binary-search-tree", "relative_path_cn": "/solution/1300-1399/1382.Balance%20a%20Binary%20Search%20Tree/README.md", "relative_path_en": "/solution/1300-1399/1382.Balance%20a%20Binary%20Search%20Tree/README_EN.md", "title_cn": "\u5c06\u4e8c\u53c9\u641c\u7d22\u6811\u53d8\u5e73\u8861", "title_en": "Balance a Binary Search Tree", "question_title_slug": "balance-a-binary-search-tree", "content_en": "

    Given a binary search tree, return a balanced binary search tree with the same node values.

    \r\n\r\n

    A binary search tree is balanced if and only if the depth of the two subtrees of every node never differ by more than 1.

    \r\n\r\n

    If there is more than one answer, return any of them.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n

    \"\"\"\"

    \r\n\r\n
    \r\nInput: root = [1,null,2,null,3,null,4,null,null]\r\nOutput: [2,1,3,null,null,null,4]\r\nExplanation: This is not the only correct answer, [3,1,4,null,2,null,null] is also correct.\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • The number of nodes in the tree is between 1 and 10^4.
    • \r\n\t
    • The tree nodes will have distinct values between 1 and 10^5.
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u68f5\u4e8c\u53c9\u641c\u7d22\u6811\uff0c\u8bf7\u4f60\u8fd4\u56de\u4e00\u68f5 \u5e73\u8861\u540e \u7684\u4e8c\u53c9\u641c\u7d22\u6811\uff0c\u65b0\u751f\u6210\u7684\u6811\u5e94\u8be5\u4e0e\u539f\u6765\u7684\u6811\u6709\u7740\u76f8\u540c\u7684\u8282\u70b9\u503c\u3002

    \n\n

    \u5982\u679c\u4e00\u68f5\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\uff0c\u6bcf\u4e2a\u8282\u70b9\u7684\u4e24\u68f5\u5b50\u6811\u9ad8\u5ea6\u5dee\u4e0d\u8d85\u8fc7 1 \uff0c\u6211\u4eec\u5c31\u79f0\u8fd9\u68f5\u4e8c\u53c9\u641c\u7d22\u6811\u662f \u5e73\u8861\u7684 \u3002

    \n\n

    \u5982\u679c\u6709\u591a\u79cd\u6784\u9020\u65b9\u6cd5\uff0c\u8bf7\u4f60\u8fd4\u56de\u4efb\u610f\u4e00\u79cd\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n

    \"\"\"\"

    \n\n
    \u8f93\u5165\uff1aroot = [1,null,2,null,3,null,4,null,null]\n\u8f93\u51fa\uff1a[2,1,3,null,null,null,4]\n\u89e3\u91ca\uff1a\u8fd9\u4e0d\u662f\u552f\u4e00\u7684\u6b63\u786e\u7b54\u6848\uff0c[3,1,4,null,2,null,null] \u4e5f\u662f\u4e00\u4e2a\u53ef\u884c\u7684\u6784\u9020\u65b9\u6848\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u8282\u70b9\u7684\u6570\u76ee\u5728 1 \u5230 10^4 \u4e4b\u95f4\u3002
    • \n\t
    • \u6811\u8282\u70b9\u7684\u503c\u4e92\u4e0d\u76f8\u540c\uff0c\u4e14\u5728 1 \u5230 10^5 \u4e4b\u95f4\u3002
    • \n
    \n", "tags_en": ["Binary Search Tree"], "tags_cn": ["\u4e8c\u53c9\u641c\u7d22\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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 */\nclass Solution {\npublic:\n TreeNode* balanceBST(TreeNode* root) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode(int x) { val = x; }\n * }\n */\nclass Solution {\n public TreeNode balanceBST(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution(object):\n def balanceBST(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: TreeNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution:\n def balanceBST(self, root: TreeNode) -> TreeNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* balanceBST(struct TreeNode* root){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int x) { val = x; }\n * }\n */\npublic class Solution {\n public TreeNode BalanceBST(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val) {\n * this.val = val;\n * this.left = this.right = null;\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {TreeNode}\n */\nvar balanceBST = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val)\n# @val = val\n# @left, @right = nil, nil\n# end\n# end\n\n# @param {TreeNode} root\n# @return {TreeNode}\ndef balance_bst(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.left = nil\n * self.right = nil\n * }\n * }\n */\nclass Solution {\n func balanceBST(_ root: TreeNode?) -> TreeNode? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc balanceBST(root *TreeNode) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(var _value: Int) {\n * var value: Int = _value\n * var left: TreeNode = null\n * var right: TreeNode = null\n * }\n */\nobject Solution {\n def balanceBST(root: TreeNode): TreeNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun balanceBST(root: TreeNode?): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n// \n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn balance_bst(root: Option>>) -> Option>> {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($value) { $this->val = $value; }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return TreeNode\n */\n function balanceBST($root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction balanceBST(root: TreeNode | null): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (balance-bst root)\n (-> (or/c tree-node? #f) (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1382](https://leetcode-cn.com/problems/balance-a-binary-search-tree)", "[\u5c06\u4e8c\u53c9\u641c\u7d22\u6811\u53d8\u5e73\u8861](/solution/1300-1399/1382.Balance%20a%20Binary%20Search%20Tree/README.md)", "`\u4e8c\u53c9\u641c\u7d22\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1382](https://leetcode.com/problems/balance-a-binary-search-tree)", "[Balance a Binary Search Tree](/solution/1300-1399/1382.Balance%20a%20Binary%20Search%20Tree/README_EN.md)", "`Binary Search Tree`", "Medium", ""]}, {"question_id": "1284", "frontend_question_id": "1390", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/four-divisors", "url_en": "https://leetcode.com/problems/four-divisors", "relative_path_cn": "/solution/1300-1399/1390.Four%20Divisors/README.md", "relative_path_en": "/solution/1300-1399/1390.Four%20Divisors/README_EN.md", "title_cn": "\u56db\u56e0\u6570", "title_en": "Four Divisors", "question_title_slug": "four-divisors", "content_en": "

    Given an integer array nums, return the sum of divisors of the integers in that array that have exactly four divisors.

    \n\n

    If there is no such integer in the array, return 0.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [21,4,7]\nOutput: 32\nExplanation:\n21 has 4 divisors: 1, 3, 7, 21\n4 has 3 divisors: 1, 2, 4\n7 has 2 divisors: 1, 7\nThe answer is the sum of divisors of 21 only.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 10^4
    • \n\t
    • 1 <= nums[i] <= 10^5
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums\uff0c\u8bf7\u4f60\u8fd4\u56de\u8be5\u6570\u7ec4\u4e2d\u6070\u6709\u56db\u4e2a\u56e0\u6570\u7684\u8fd9\u4e9b\u6574\u6570\u7684\u5404\u56e0\u6570\u4e4b\u548c\u3002

    \n\n

    \u5982\u679c\u6570\u7ec4\u4e2d\u4e0d\u5b58\u5728\u6ee1\u8db3\u9898\u610f\u7684\u6574\u6570\uff0c\u5219\u8fd4\u56de 0 \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [21,4,7]\n\u8f93\u51fa\uff1a32\n\u89e3\u91ca\uff1a\n21 \u6709 4 \u4e2a\u56e0\u6570\uff1a1, 3, 7, 21\n4 \u6709 3 \u4e2a\u56e0\u6570\uff1a1, 2, 4\n7 \u6709 2 \u4e2a\u56e0\u6570\uff1a1, 7\n\u7b54\u6848\u4ec5\u4e3a 21 \u7684\u6240\u6709\u56e0\u6570\u7684\u548c\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 10^4
    • \n\t
    • 1 <= nums[i] <= 10^5
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int sumFourDivisors(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int sumFourDivisors(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def sumFourDivisors(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def sumFourDivisors(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint sumFourDivisors(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SumFourDivisors(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar sumFourDivisors = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef sum_four_divisors(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func sumFourDivisors(_ nums: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func sumFourDivisors(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def sumFourDivisors(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun sumFourDivisors(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sum_four_divisors(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function sumFourDivisors($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function sumFourDivisors(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (sum-four-divisors nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1390](https://leetcode-cn.com/problems/four-divisors)", "[\u56db\u56e0\u6570](/solution/1300-1399/1390.Four%20Divisors/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1390](https://leetcode.com/problems/four-divisors)", "[Four Divisors](/solution/1300-1399/1390.Four%20Divisors/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "1283", "frontend_question_id": "1507", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reformat-date", "url_en": "https://leetcode.com/problems/reformat-date", "relative_path_cn": "/solution/1500-1599/1507.Reformat%20Date/README.md", "relative_path_en": "/solution/1500-1599/1507.Reformat%20Date/README_EN.md", "title_cn": "\u8f6c\u53d8\u65e5\u671f\u683c\u5f0f", "title_en": "Reformat Date", "question_title_slug": "reformat-date", "content_en": "

    Given a date string in the form Day Month Year, where:

    \n\n
      \n\t
    • Day is in the set {"1st", "2nd", "3rd", "4th", ..., "30th", "31st"}.
    • \n\t
    • Month is in the set {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}.
    • \n\t
    • Year is in the range [1900, 2100].
    • \n
    \n\n

    Convert the date string to the format YYYY-MM-DD, where:

    \n\n
      \n\t
    • YYYY denotes the 4 digit year.
    • \n\t
    • MM denotes the 2 digit month.
    • \n\t
    • DD denotes the 2 digit day.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: date = "20th Oct 2052"\nOutput: "2052-10-20"\n
    \n\n

    Example 2:

    \n\n
    \nInput: date = "6th Jun 1933"\nOutput: "1933-06-06"\n
    \n\n

    Example 3:

    \n\n
    \nInput: date = "26th May 1960"\nOutput: "1960-05-26"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The given dates are guaranteed to be valid, so no error handling is necessary.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 date \uff0c\u5b83\u7684\u683c\u5f0f\u4e3a Day Month Year \uff0c\u5176\u4e2d\uff1a

    \n\n
      \n\t
    • Day \u662f\u96c6\u5408 {"1st", "2nd", "3rd", "4th", ..., "30th", "31st"} \u4e2d\u7684\u4e00\u4e2a\u5143\u7d20\u3002
    • \n\t
    • Month \u662f\u96c6\u5408 {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"} \u4e2d\u7684\u4e00\u4e2a\u5143\u7d20\u3002
    • \n\t
    • Year \u7684\u8303\u56f4\u5728 \u200b[1900, 2100] \u4e4b\u95f4\u3002
    • \n
    \n\n

    \u8bf7\u4f60\u5c06\u5b57\u7b26\u4e32\u8f6c\u53d8\u4e3a YYYY-MM-DD \u7684\u683c\u5f0f\uff0c\u5176\u4e2d\uff1a

    \n\n
      \n\t
    • YYYY \u8868\u793a 4 \u4f4d\u7684\u5e74\u4efd\u3002
    • \n\t
    • MM \u8868\u793a 2 \u4f4d\u7684\u6708\u4efd\u3002
    • \n\t
    • DD \u8868\u793a 2 \u4f4d\u7684\u5929\u6570\u3002
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1adate = "20th Oct 2052"\n\u8f93\u51fa\uff1a"2052-10-20"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1adate = "6th Jun 1933"\n\u8f93\u51fa\uff1a"1933-06-06"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1adate = "26th May 1960"\n\u8f93\u51fa\uff1a"1960-05-26"\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u7ed9\u5b9a\u65e5\u671f\u4fdd\u8bc1\u662f\u5408\u6cd5\u7684\uff0c\u6240\u4ee5\u4e0d\u9700\u8981\u5904\u7406\u5f02\u5e38\u8f93\u5165\u3002
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string reformatDate(string date) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String reformatDate(String date) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def reformatDate(self, date):\n \"\"\"\n :type date: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def reformatDate(self, date: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * reformatDate(char * date){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ReformatDate(string date) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} date\n * @return {string}\n */\nvar reformatDate = function(date) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} date\n# @return {String}\ndef reformat_date(date)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func reformatDate(_ date: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func reformatDate(date string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def reformatDate(date: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun reformatDate(date: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn reformat_date(date: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $date\n * @return String\n */\n function reformatDate($date) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function reformatDate(date: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (reformat-date date)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1507](https://leetcode-cn.com/problems/reformat-date)", "[\u8f6c\u53d8\u65e5\u671f\u683c\u5f0f](/solution/1500-1599/1507.Reformat%20Date/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1507](https://leetcode.com/problems/reformat-date)", "[Reformat Date](/solution/1500-1599/1507.Reformat%20Date/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1282", "frontend_question_id": "1178", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-valid-words-for-each-puzzle", "url_en": "https://leetcode.com/problems/number-of-valid-words-for-each-puzzle", "relative_path_cn": "/solution/1100-1199/1178.Number%20of%20Valid%20Words%20for%20Each%20Puzzle/README.md", "relative_path_en": "/solution/1100-1199/1178.Number%20of%20Valid%20Words%20for%20Each%20Puzzle/README_EN.md", "title_cn": "\u731c\u5b57\u8c1c", "title_en": "Number of Valid Words for Each Puzzle", "question_title_slug": "number-of-valid-words-for-each-puzzle", "content_en": "With respect to a given puzzle string, a word is valid if both the following conditions are satisfied:\n
      \n\t
    • word contains the first letter of puzzle.
    • \n\t
    • For each letter in word, that letter is in puzzle.
      \n\tFor example, if the puzzle is "abcdefg", then valid words are "faced", "cabbage", and "baggage"; while invalid words are "beefed" (doesn't include "a") and "based" (includes "s" which isn't in the puzzle).
    • \n
    \nReturn an array answer, where answer[i] is the number of words in the given word list words that are valid with respect to the puzzle puzzles[i].\n

     

    \n

    Example :

    \n\n
    \nInput: \nwords = ["aaaa","asas","able","ability","actt","actor","access"], \npuzzles = ["aboveyz","abrodyz","abslute","absoryz","actresz","gaswxyz"]\nOutput: [1,1,3,2,4,0]\nExplanation:\n1 valid word for "aboveyz" : "aaaa" \n1 valid word for "abrodyz" : "aaaa"\n3 valid words for "abslute" : "aaaa", "asas", "able"\n2 valid words for "absoryz" : "aaaa", "asas"\n4 valid words for "actresz" : "aaaa", "asas", "actt", "access"\nThere're no valid words for "gaswxyz" cause none of the words in the list contains letter 'g'.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= words.length <= 10^5
    • \n\t
    • 4 <= words[i].length <= 50
    • \n\t
    • 1 <= puzzles.length <= 10^4
    • \n\t
    • puzzles[i].length == 7
    • \n\t
    • words[i][j], puzzles[i][j] are English lowercase letters.
    • \n\t
    • Each puzzles[i] doesn't contain repeated characters.
    • \n
    \n", "content_cn": "

    \u5916\u56fd\u53cb\u4eba\u4eff\u7167\u4e2d\u56fd\u5b57\u8c1c\u8bbe\u8ba1\u4e86\u4e00\u4e2a\u82f1\u6587\u7248\u731c\u5b57\u8c1c\u5c0f\u6e38\u620f\uff0c\u8bf7\u4f60\u6765\u731c\u731c\u770b\u5427\u3002

    \n\n

    \u5b57\u8c1c\u7684\u8ff7\u9762\u00a0puzzle \u6309\u5b57\u7b26\u4e32\u5f62\u5f0f\u7ed9\u51fa\uff0c\u5982\u679c\u4e00\u4e2a\u5355\u8bcd\u00a0word\u00a0\u7b26\u5408\u4e0b\u9762\u4e24\u4e2a\u6761\u4ef6\uff0c\u90a3\u4e48\u5b83\u5c31\u53ef\u4ee5\u7b97\u4f5c\u8c1c\u5e95\uff1a

    \n\n
      \n\t
    • \u5355\u8bcd\u00a0word\u00a0\u4e2d\u5305\u542b\u8c1c\u9762\u00a0puzzle\u00a0\u7684\u7b2c\u4e00\u4e2a\u5b57\u6bcd\u3002
    • \n\t
    • \u5355\u8bcd\u00a0word\u00a0\u4e2d\u7684\u6bcf\u4e00\u4e2a\u5b57\u6bcd\u90fd\u53ef\u4ee5\u5728\u8c1c\u9762\u00a0puzzle\u00a0\u4e2d\u627e\u5230\u3002
      \n\t\u4f8b\u5982\uff0c\u5982\u679c\u5b57\u8c1c\u7684\u8c1c\u9762\u662f \"abcdefg\"\uff0c\u90a3\u4e48\u53ef\u4ee5\u4f5c\u4e3a\u8c1c\u5e95\u7684\u5355\u8bcd\u6709 \"faced\", \"cabbage\", \u548c \"baggage\"\uff1b\u800c \"beefed\"\uff08\u4e0d\u542b\u5b57\u6bcd \"a\"\uff09\u4ee5\u53ca\u00a0\"based\"\uff08\u5176\u4e2d\u7684 \"s\" \u6ca1\u6709\u51fa\u73b0\u5728\u8c1c\u9762\u4e2d\uff09\u90fd\u4e0d\u80fd\u4f5c\u4e3a\u8c1c\u5e95\u3002
    • \n
    \n\n

    \u8fd4\u56de\u4e00\u4e2a\u7b54\u6848\u6570\u7ec4\u00a0answer\uff0c\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u00a0answer[i]\u00a0\u662f\u5728\u7ed9\u51fa\u7684\u5355\u8bcd\u5217\u8868 words \u4e2d\u53ef\u4ee5\u4f5c\u4e3a\u5b57\u8c1c\u8ff7\u9762\u00a0puzzles[i]\u00a0\u6240\u5bf9\u5e94\u7684\u8c1c\u5e95\u7684\u5355\u8bcd\u6570\u76ee\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\nwords = [\"aaaa\",\"asas\",\"able\",\"ability\",\"actt\",\"actor\",\"access\"], \npuzzles = [\"aboveyz\",\"abrodyz\",\"abslute\",\"absoryz\",\"actresz\",\"gaswxyz\"]\n\u8f93\u51fa\uff1a[1,1,3,2,4,0]\n\u89e3\u91ca\uff1a\n1 \u4e2a\u5355\u8bcd\u53ef\u4ee5\u4f5c\u4e3a \"aboveyz\" \u7684\u8c1c\u5e95 : \"aaaa\" \n1 \u4e2a\u5355\u8bcd\u53ef\u4ee5\u4f5c\u4e3a \"abrodyz\" \u7684\u8c1c\u5e95 : \"aaaa\"\n3 \u4e2a\u5355\u8bcd\u53ef\u4ee5\u4f5c\u4e3a \"abslute\" \u7684\u8c1c\u5e95 : \"aaaa\", \"asas\", \"able\"\n2 \u4e2a\u5355\u8bcd\u53ef\u4ee5\u4f5c\u4e3a\u00a0\"absoryz\" \u7684\u8c1c\u5e95 : \"aaaa\", \"asas\"\n4 \u4e2a\u5355\u8bcd\u53ef\u4ee5\u4f5c\u4e3a\u00a0\"actresz\" \u7684\u8c1c\u5e95 : \"aaaa\", \"asas\", \"actt\", \"access\"\n\u6ca1\u6709\u5355\u8bcd\u53ef\u4ee5\u4f5c\u4e3a\u00a0\"gaswxyz\" \u7684\u8c1c\u5e95\uff0c\u56e0\u4e3a\u5217\u8868\u4e2d\u7684\u5355\u8bcd\u90fd\u4e0d\u542b\u5b57\u6bcd 'g'\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= words.length <= 10^5
    • \n\t
    • 4 <= words[i].length <= 50
    • \n\t
    • 1 <= puzzles.length <= 10^4
    • \n\t
    • puzzles[i].length == 7
    • \n\t
    • words[i][j], puzzles[i][j]\u00a0\u90fd\u662f\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    • \n\t
    • \u6bcf\u4e2a\u00a0puzzles[i]\u00a0\u6240\u5305\u542b\u7684\u5b57\u7b26\u90fd\u4e0d\u91cd\u590d\u3002
    • \n
    \n", "tags_en": ["Bit Manipulation", "Hash Table"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u54c8\u5e0c\u8868"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findNumOfValidWords(vector& words, vector& puzzles) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List findNumOfValidWords(String[] words, String[] puzzles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findNumOfValidWords(self, words, puzzles):\n \"\"\"\n :type words: List[str]\n :type puzzles: List[str]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findNumOfValidWords(self, words: List[str], puzzles: List[str]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* findNumOfValidWords(char ** words, int wordsSize, char ** puzzles, int puzzlesSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList FindNumOfValidWords(string[] words, string[] puzzles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @param {string[]} puzzles\n * @return {number[]}\n */\nvar findNumOfValidWords = function(words, puzzles) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @param {String[]} puzzles\n# @return {Integer[]}\ndef find_num_of_valid_words(words, puzzles)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findNumOfValidWords(_ words: [String], _ puzzles: [String]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findNumOfValidWords(words []string, puzzles []string) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findNumOfValidWords(words: Array[String], puzzles: Array[String]): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findNumOfValidWords(words: Array, puzzles: Array): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_num_of_valid_words(words: Vec, puzzles: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @param String[] $puzzles\n * @return Integer[]\n */\n function findNumOfValidWords($words, $puzzles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findNumOfValidWords(words: string[], puzzles: string[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-num-of-valid-words words puzzles)\n (-> (listof string?) (listof string?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1178](https://leetcode-cn.com/problems/number-of-valid-words-for-each-puzzle)", "[\u731c\u5b57\u8c1c](/solution/1100-1199/1178.Number%20of%20Valid%20Words%20for%20Each%20Puzzle/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u54c8\u5e0c\u8868`", "\u56f0\u96be", ""], "md_table_row_en": ["[1178](https://leetcode.com/problems/number-of-valid-words-for-each-puzzle)", "[Number of Valid Words for Each Puzzle](/solution/1100-1199/1178.Number%20of%20Valid%20Words%20for%20Each%20Puzzle/README_EN.md)", "`Bit Manipulation`,`Hash Table`", "Hard", ""]}, {"question_id": "1281", "frontend_question_id": "1177", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/can-make-palindrome-from-substring", "url_en": "https://leetcode.com/problems/can-make-palindrome-from-substring", "relative_path_cn": "/solution/1100-1199/1177.Can%20Make%20Palindrome%20from%20Substring/README.md", "relative_path_en": "/solution/1100-1199/1177.Can%20Make%20Palindrome%20from%20Substring/README_EN.md", "title_cn": "\u6784\u5efa\u56de\u6587\u4e32\u68c0\u6d4b", "title_en": "Can Make Palindrome from Substring", "question_title_slug": "can-make-palindrome-from-substring", "content_en": "

    Given a string s, we make queries on substrings of s.

    \n\n

    For each query queries[i] = [left, right, k], we may rearrange the substring s[left], ..., s[right], and then choose up to k of them to replace with any lowercase English letter. 

    \n\n

    If the substring is possible to be a palindrome string after the operations above, the result of the query is true. Otherwise, the result is false.

    \n\n

    Return an array answer[], where answer[i] is the result of the i-th query queries[i].

    \n\n

    Note that: Each letter is counted individually for replacement so if for example s[left..right] = "aaa", and k = 2, we can only replace two of the letters.  (Also, note that the initial string s is never modified by any query.)

    \n\n

     

    \n

    Example :

    \n\n
    \nInput: s = "abcda", queries = [[3,3,0],[1,2,0],[0,3,1],[0,3,2],[0,4,1]]\nOutput: [true,false,false,true,true]\nExplanation:\nqueries[0] : substring = "d", is palidrome.\nqueries[1] : substring = "bc", is not palidrome.\nqueries[2] : substring = "abcd", is not palidrome after replacing only 1 character.\nqueries[3] : substring = "abcd", could be changed to "abba" which is palidrome. Also this can be changed to "baab" first rearrange it "bacd" then replace "cd" with "ab".\nqueries[4] : substring = "abcda", could be changed to "abcba" which is palidrome.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length, queries.length <= 10^5
    • \n\t
    • 0 <= queries[i][0] <= queries[i][1] < s.length
    • \n\t
    • 0 <= queries[i][2] <= s.length
    • \n\t
    • s only contains lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s\uff0c\u8bf7\u4f60\u5bf9 s \u7684\u5b50\u4e32\u8fdb\u884c\u68c0\u6d4b\u3002

    \n\n

    \u6bcf\u6b21\u68c0\u6d4b\uff0c\u5f85\u68c0\u5b50\u4e32\u90fd\u53ef\u4ee5\u8868\u793a\u4e3a queries[i] = [left, right, k]\u3002\u6211\u4eec\u53ef\u4ee5 \u91cd\u65b0\u6392\u5217 \u5b50\u4e32 s[left], ..., s[right]\uff0c\u5e76\u4ece\u4e2d\u9009\u62e9 \u6700\u591a k \u9879\u66ff\u6362\u6210\u4efb\u4f55\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002 

    \n\n

    \u5982\u679c\u5728\u4e0a\u8ff0\u68c0\u6d4b\u8fc7\u7a0b\u4e2d\uff0c\u5b50\u4e32\u53ef\u4ee5\u53d8\u6210\u56de\u6587\u5f62\u5f0f\u7684\u5b57\u7b26\u4e32\uff0c\u90a3\u4e48\u68c0\u6d4b\u7ed3\u679c\u4e3a true\uff0c\u5426\u5219\u7ed3\u679c\u4e3a false\u3002

    \n\n

    \u8fd4\u56de\u7b54\u6848\u6570\u7ec4 answer[]\uff0c\u5176\u4e2d answer[i] \u662f\u7b2c i \u4e2a\u5f85\u68c0\u5b50\u4e32 queries[i] \u7684\u68c0\u6d4b\u7ed3\u679c\u3002

    \n\n

    \u6ce8\u610f\uff1a\u5728\u66ff\u6362\u65f6\uff0c\u5b50\u4e32\u4e2d\u7684\u6bcf\u4e2a\u5b57\u6bcd\u90fd\u5fc5\u987b\u4f5c\u4e3a \u72ec\u7acb\u7684 \u9879\u8fdb\u884c\u8ba1\u6570\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u5982\u679c s[left..right] = "aaa" \u4e14 k = 2\uff0c\u6211\u4eec\u53ea\u80fd\u66ff\u6362\u5176\u4e2d\u7684\u4e24\u4e2a\u5b57\u6bcd\u3002\uff08\u53e6\u5916\uff0c\u4efb\u4f55\u68c0\u6d4b\u90fd\u4e0d\u4f1a\u4fee\u6539\u539f\u59cb\u5b57\u7b26\u4e32 s\uff0c\u53ef\u4ee5\u8ba4\u4e3a\u6bcf\u6b21\u68c0\u6d4b\u90fd\u662f\u72ec\u7acb\u7684\uff09

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1as = "abcda", queries = [[3,3,0],[1,2,0],[0,3,1],[0,3,2],[0,4,1]]\n\u8f93\u51fa\uff1a[true,false,false,true,true]\n\u89e3\u91ca\uff1a\nqueries[0] : \u5b50\u4e32 = "d"\uff0c\u56de\u6587\u3002\nqueries[1] : \u5b50\u4e32 = "bc"\uff0c\u4e0d\u662f\u56de\u6587\u3002\nqueries[2] : \u5b50\u4e32 = "abcd"\uff0c\u53ea\u66ff\u6362 1 \u4e2a\u5b57\u7b26\u662f\u53d8\u4e0d\u6210\u56de\u6587\u4e32\u7684\u3002\nqueries[3] : \u5b50\u4e32 = "abcd"\uff0c\u53ef\u4ee5\u53d8\u6210\u56de\u6587\u7684 "abba"\u3002 \u4e5f\u53ef\u4ee5\u53d8\u6210 "baab"\uff0c\u5148\u91cd\u65b0\u6392\u5e8f\u53d8\u6210 "bacd"\uff0c\u7136\u540e\u628a "cd" \u66ff\u6362\u4e3a "ab"\u3002\nqueries[4] : \u5b50\u4e32 = "abcda"\uff0c\u53ef\u4ee5\u53d8\u6210\u56de\u6587\u7684 "abcba"\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length, queries.length <= 10^5
    • \n\t
    • 0 <= queries[i][0] <= queries[i][1] < s.length
    • \n\t
    • 0 <= queries[i][2] <= s.length
    • \n\t
    • s \u4e2d\u53ea\u6709\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd
    • \n
    \n", "tags_en": ["Array", "String"], "tags_cn": ["\u6570\u7ec4", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector canMakePaliQueries(string s, vector>& queries) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List canMakePaliQueries(String s, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canMakePaliQueries(self, s, queries):\n \"\"\"\n :type s: str\n :type queries: List[List[int]]\n :rtype: List[bool]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canMakePaliQueries(self, s: str, queries: List[List[int]]) -> List[bool]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nbool* canMakePaliQueries(char * s, int** queries, int queriesSize, int* queriesColSize, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList CanMakePaliQueries(string s, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number[][]} queries\n * @return {boolean[]}\n */\nvar canMakePaliQueries = function(s, queries) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer[][]} queries\n# @return {Boolean[]}\ndef can_make_pali_queries(s, queries)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canMakePaliQueries(_ s: String, _ queries: [[Int]]) -> [Bool] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canMakePaliQueries(s string, queries [][]int) []bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canMakePaliQueries(s: String, queries: Array[Array[Int]]): Array[Boolean] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canMakePaliQueries(s: String, queries: Array): BooleanArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_make_pali_queries(s: String, queries: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer[][] $queries\n * @return Boolean[]\n */\n function canMakePaliQueries($s, $queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canMakePaliQueries(s: string, queries: number[][]): boolean[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-make-pali-queries s queries)\n (-> string? (listof (listof exact-integer?)) (listof boolean?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1177](https://leetcode-cn.com/problems/can-make-palindrome-from-substring)", "[\u6784\u5efa\u56de\u6587\u4e32\u68c0\u6d4b](/solution/1100-1199/1177.Can%20Make%20Palindrome%20from%20Substring/README.md)", "`\u6570\u7ec4`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1177](https://leetcode.com/problems/can-make-palindrome-from-substring)", "[Can Make Palindrome from Substring](/solution/1100-1199/1177.Can%20Make%20Palindrome%20from%20Substring/README_EN.md)", "`Array`,`String`", "Medium", ""]}, {"question_id": "1280", "frontend_question_id": "1176", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/diet-plan-performance", "url_en": "https://leetcode.com/problems/diet-plan-performance", "relative_path_cn": "/solution/1100-1199/1176.Diet%20Plan%20Performance/README.md", "relative_path_en": "/solution/1100-1199/1176.Diet%20Plan%20Performance/README_EN.md", "title_cn": "\u5065\u8eab\u8ba1\u5212\u8bc4\u4f30", "title_en": "Diet Plan Performance", "question_title_slug": "diet-plan-performance", "content_en": "

    A dieter consumes calories[i] calories on the i-th day. 

    \n\n

    Given an integer k, for every consecutive sequence of k days (calories[i], calories[i+1], ..., calories[i+k-1] for all 0 <= i <= n-k), they look at T, the total calories consumed during that sequence of k days (calories[i] + calories[i+1] + ... + calories[i+k-1]):

    \n\n
      \n\t
    • If T < lower, they performed poorly on their diet and lose 1 point; 
    • \n\t
    • If T > upper, they performed well on their diet and gain 1 point;
    • \n\t
    • Otherwise, they performed normally and there is no change in points.
    • \n
    \n\n

    Initially, the dieter has zero points. Return the total number of points the dieter has after dieting for calories.length days.

    \n\n

    Note that the total points can be negative.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: calories = [1,2,3,4,5], k = 1, lower = 3, upper = 3\nOutput: 0\nExplanation: Since k = 1, we consider each element of the array separately and compare it to lower and upper.\ncalories[0] and calories[1] are less than lower so 2 points are lost.\ncalories[3] and calories[4] are greater than upper so 2 points are gained.\n
    \n\n

    Example 2:

    \n\n
    \nInput: calories = [3,2], k = 2, lower = 0, upper = 1\nOutput: 1\nExplanation: Since k = 2, we consider subarrays of length 2.\ncalories[0] + calories[1] > upper so 1 point is gained.\n
    \n\n

    Example 3:

    \n\n
    \nInput: calories = [6,5,0,0], k = 2, lower = 1, upper = 5\nOutput: 0\nExplanation:\ncalories[0] + calories[1] > upper so 1 point is gained.\nlower <= calories[1] + calories[2] <= upper so no change in points.\ncalories[2] + calories[3] < lower so 1 point is lost.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= k <= calories.length <= 10^5
    • \n\t
    • 0 <= calories[i] <= 20000
    • \n\t
    • 0 <= lower <= upper
    • \n
    \n", "content_cn": "

    \u4f60\u7684\u597d\u53cb\u662f\u4e00\u4f4d\u5065\u8eab\u7231\u597d\u8005\u3002\u524d\u6bb5\u65e5\u5b50\uff0c\u4ed6\u7ed9\u81ea\u5df1\u5236\u5b9a\u4e86\u4e00\u4efd\u5065\u8eab\u8ba1\u5212\u3002\u73b0\u5728\u60f3\u8bf7\u4f60\u5e2e\u4ed6\u8bc4\u4f30\u4e00\u4e0b\u8fd9\u4efd\u8ba1\u5212\u662f\u5426\u5408\u7406\u3002

    \n\n

    \u4ed6\u4f1a\u6709\u4e00\u4efd\u8ba1\u5212\u6d88\u8017\u7684\u5361\u8def\u91cc\u8868\uff0c\u5176\u4e2d calories[i] \u7ed9\u51fa\u4e86\u4f60\u7684\u8fd9\u4f4d\u597d\u53cb\u5728\u7b2c i \u5929\u9700\u8981\u6d88\u8017\u7684\u5361\u8def\u91cc\u603b\u91cf\u3002

    \n\n

    \u4e3a\u4e86\u66f4\u597d\u5730\u8bc4\u4f30\u8fd9\u4efd\u8ba1\u5212\uff0c\u5bf9\u4e8e\u5361\u8def\u91cc\u8868\u4e2d\u7684\u6bcf\u4e00\u5929\uff0c\u4f60\u90fd\u9700\u8981\u8ba1\u7b97\u4ed6 \u300c\u8fd9\u4e00\u5929\u4ee5\u53ca\u4e4b\u540e\u7684\u8fde\u7eed\u51e0\u5929\u300d \uff08\u5171 k \u5929\uff09\u5185\u6d88\u8017\u7684\u603b\u5361\u8def\u91cc T\uff1a

    \n\n
      \n\t
    • \u5982\u679c T < lower\uff0c\u90a3\u4e48\u8fd9\u4efd\u8ba1\u5212\u76f8\u5bf9\u7cdf\u7cd5\uff0c\u5e76\u5931\u53bb 1 \u5206\uff1b 
    • \n\t
    • \u5982\u679c T > upper\uff0c\u90a3\u4e48\u8fd9\u4efd\u8ba1\u5212\u76f8\u5bf9\u4f18\u79c0\uff0c\u5e76\u83b7\u5f97 1 \u5206\uff1b
    • \n\t
    • \u5426\u5219\uff0c\u8fd9\u4efd\u8ba1\u5212\u666e\u666e\u901a\u901a\uff0c\u5206\u503c\u4e0d\u505a\u53d8\u52a8\u3002
    • \n
    \n\n

    \u8bf7\u8fd4\u56de\u7edf\u8ba1\u5b8c\u6240\u6709 calories.length \u5929\u540e\u5f97\u5230\u7684\u603b\u5206\u4f5c\u4e3a\u8bc4\u4f30\u7ed3\u679c\u3002

    \n\n

    \u6ce8\u610f\uff1a\u603b\u5206\u53ef\u80fd\u662f\u8d1f\u6570\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1acalories = [1,2,3,4,5], k = 1, lower = 3, upper = 3\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1acalories[0], calories[1] < lower \u800c calories[3], calories[4] > upper, \u603b\u5206 = 0.
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1acalories = [3,2], k = 2, lower = 0, upper = 1\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1acalories[0] + calories[1] > upper, \u603b\u5206 = 1.\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1acalories = [6,5,0,0], k = 2, lower = 1, upper = 5\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1acalories[0] + calories[1] > upper, calories[2] + calories[3] < lower, \u603b\u5206 = 0.\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= k <= calories.length <= 10^5
    • \n\t
    • 0 <= calories[i] <= 20000
    • \n\t
    • 0 <= lower <= upper
    • \n
    \n", "tags_en": ["Array", "Sliding Window"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int dietPlanPerformance(vector& calories, int k, int lower, int upper) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int dietPlanPerformance(int[] calories, int k, int lower, int upper) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def dietPlanPerformance(self, calories, k, lower, upper):\n \"\"\"\n :type calories: List[int]\n :type k: int\n :type lower: int\n :type upper: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def dietPlanPerformance(self, calories: List[int], k: int, lower: int, upper: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint dietPlanPerformance(int* calories, int caloriesSize, int k, int lower, int upper){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int DietPlanPerformance(int[] calories, int k, int lower, int upper) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} calories\n * @param {number} k\n * @param {number} lower\n * @param {number} upper\n * @return {number}\n */\nvar dietPlanPerformance = function(calories, k, lower, upper) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} calories\n# @param {Integer} k\n# @param {Integer} lower\n# @param {Integer} upper\n# @return {Integer}\ndef diet_plan_performance(calories, k, lower, upper)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func dietPlanPerformance(_ calories: [Int], _ k: Int, _ lower: Int, _ upper: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func dietPlanPerformance(calories []int, k int, lower int, upper int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def dietPlanPerformance(calories: Array[Int], k: Int, lower: Int, upper: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun dietPlanPerformance(calories: IntArray, k: Int, lower: Int, upper: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn diet_plan_performance(calories: Vec, k: i32, lower: i32, upper: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $calories\n * @param Integer $k\n * @param Integer $lower\n * @param Integer $upper\n * @return Integer\n */\n function dietPlanPerformance($calories, $k, $lower, $upper) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function dietPlanPerformance(calories: number[], k: number, lower: number, upper: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (diet-plan-performance calories k lower upper)\n (-> (listof exact-integer?) exact-integer? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1176](https://leetcode-cn.com/problems/diet-plan-performance)", "[\u5065\u8eab\u8ba1\u5212\u8bc4\u4f30](/solution/1100-1199/1176.Diet%20Plan%20Performance/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1176](https://leetcode.com/problems/diet-plan-performance)", "[Diet Plan Performance](/solution/1100-1199/1176.Diet%20Plan%20Performance/README_EN.md)", "`Array`,`Sliding Window`", "Easy", "\ud83d\udd12"]}, {"question_id": "1279", "frontend_question_id": "1175", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/prime-arrangements", "url_en": "https://leetcode.com/problems/prime-arrangements", "relative_path_cn": "/solution/1100-1199/1175.Prime%20Arrangements/README.md", "relative_path_en": "/solution/1100-1199/1175.Prime%20Arrangements/README_EN.md", "title_cn": "\u8d28\u6570\u6392\u5217", "title_en": "Prime Arrangements", "question_title_slug": "prime-arrangements", "content_en": "

    Return the number of permutations of 1 to n so that prime numbers are at prime indices (1-indexed.)

    \n\n

    (Recall that an integer is prime if and only if it is greater than 1, and cannot be written as a product of two positive integers both smaller than it.)

    \n\n

    Since the answer may be large, return the answer modulo 10^9 + 7.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 5\nOutput: 12\nExplanation: For example [1,2,5,4,3] is a valid permutation, but [5,2,3,4,1] is not because the prime number 5 is at index 1.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 100\nOutput: 682289015\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 100
    • \n
    \n", "content_cn": "

    \u8bf7\u4f60\u5e2e\u5fd9\u7ed9\u4ece 1 \u5230 n \u7684\u6570\u8bbe\u8ba1\u6392\u5217\u65b9\u6848\uff0c\u4f7f\u5f97\u6240\u6709\u7684\u300c\u8d28\u6570\u300d\u90fd\u5e94\u8be5\u88ab\u653e\u5728\u300c\u8d28\u6570\u7d22\u5f15\u300d\uff08\u7d22\u5f15\u4ece 1 \u5f00\u59cb\uff09\u4e0a\uff1b\u4f60\u9700\u8981\u8fd4\u56de\u53ef\u80fd\u7684\u65b9\u6848\u603b\u6570\u3002

    \n\n

    \u8ba9\u6211\u4eec\u4e00\u8d77\u6765\u56de\u987e\u4e00\u4e0b\u300c\u8d28\u6570\u300d\uff1a\u8d28\u6570\u4e00\u5b9a\u662f\u5927\u4e8e 1 \u7684\uff0c\u5e76\u4e14\u4e0d\u80fd\u7528\u4e24\u4e2a\u5c0f\u4e8e\u5b83\u7684\u6b63\u6574\u6570\u7684\u4e58\u79ef\u6765\u8868\u793a\u3002

    \n\n

    \u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u4f1a\u5f88\u5927\uff0c\u6240\u4ee5\u8bf7\u4f60\u8fd4\u56de\u7b54\u6848 \u6a21 mod 10^9 + 7 \u4e4b\u540e\u7684\u7ed3\u679c\u5373\u53ef\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1an = 5\n\u8f93\u51fa\uff1a12\n\u89e3\u91ca\uff1a\u4e3e\u4e2a\u4f8b\u5b50\uff0c[1,2,5,4,3] \u662f\u4e00\u4e2a\u6709\u6548\u7684\u6392\u5217\uff0c\u4f46 [5,2,3,4,1] \u4e0d\u662f\uff0c\u56e0\u4e3a\u5728\u7b2c\u4e8c\u79cd\u60c5\u51b5\u91cc\u8d28\u6570 5 \u88ab\u9519\u8bef\u5730\u653e\u5728\u7d22\u5f15\u4e3a 1 \u7684\u4f4d\u7f6e\u4e0a\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1an = 100\n\u8f93\u51fa\uff1a682289015\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 100
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numPrimeArrangements(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numPrimeArrangements(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numPrimeArrangements(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numPrimeArrangements(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numPrimeArrangements(int n){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumPrimeArrangements(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar numPrimeArrangements = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef num_prime_arrangements(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numPrimeArrangements(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numPrimeArrangements(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numPrimeArrangements(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numPrimeArrangements(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_prime_arrangements(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function numPrimeArrangements($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numPrimeArrangements(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-prime-arrangements n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1175](https://leetcode-cn.com/problems/prime-arrangements)", "[\u8d28\u6570\u6392\u5217](/solution/1100-1199/1175.Prime%20Arrangements/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[1175](https://leetcode.com/problems/prime-arrangements)", "[Prime Arrangements](/solution/1100-1199/1175.Prime%20Arrangements/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "1278", "frontend_question_id": "1164", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/product-price-at-a-given-date", "url_en": "https://leetcode.com/problems/product-price-at-a-given-date", "relative_path_cn": "/solution/1100-1199/1164.Product%20Price%20at%20a%20Given%20Date/README.md", "relative_path_en": "/solution/1100-1199/1164.Product%20Price%20at%20a%20Given%20Date/README_EN.md", "title_cn": "\u6307\u5b9a\u65e5\u671f\u7684\u4ea7\u54c1\u4ef7\u683c", "title_en": "Product Price at a Given Date", "question_title_slug": "product-price-at-a-given-date", "content_en": "

    Table: Products

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| product_id    | int     |\n| new_price     | int     |\n| change_date   | date    |\n+---------------+---------+\n(product_id, change_date) is the primary key of this table.\nEach row of this table indicates that the price of some product was changed to a new price at some date.
    \n\n

     

    \n\n

    Write an SQL query to find the prices of all products on 2019-08-16. Assume the price of all products before any change is 10.

    \n\n

    The query result format is in the following example:

    \n\n
    \nProducts table:\n+------------+-----------+-------------+\n| product_id | new_price | change_date |\n+------------+-----------+-------------+\n| 1          | 20        | 2019-08-14  |\n| 2          | 50        | 2019-08-14  |\n| 1          | 30        | 2019-08-15  |\n| 1          | 35        | 2019-08-16  |\n| 2          | 65        | 2019-08-17  |\n| 3          | 20        | 2019-08-18  |\n+------------+-----------+-------------+\n\nResult table:\n+------------+-------+\n| product_id | price |\n+------------+-------+\n| 2          | 50    |\n| 1          | 35    |\n| 3          | 10    |\n+------------+-------+\n
    \n", "content_cn": "

    \u4ea7\u54c1\u6570\u636e\u8868: Products

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| product_id    | int     |\n| new_price     | int     |\n| change_date   | date    |\n+---------------+---------+\n\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\u662f (product_id, change_date)\u3002\n\u8fd9\u5f20\u8868\u7684\u6bcf\u4e00\u884c\u5206\u522b\u8bb0\u5f55\u4e86 \u67d0\u4ea7\u54c1 \u5728\u67d0\u4e2a\u65e5\u671f \u66f4\u6539\u540e \u7684\u65b0\u4ef7\u683c\u3002
    \n\n

     

    \n\n

    \u5199\u4e00\u6bb5 SQL\u6765\u67e5\u627e\u5728 2019-08-16 \u65f6\u5168\u90e8\u4ea7\u54c1\u7684\u4ef7\u683c\uff0c\u5047\u8bbe\u6240\u6709\u4ea7\u54c1\u5728\u4fee\u6539\u524d\u7684\u4ef7\u683c\u90fd\u662f 10\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a\uff1a

    \n\n
    \nProducts table:\n+------------+-----------+-------------+\n| product_id | new_price | change_date |\n+------------+-----------+-------------+\n| 1          | 20        | 2019-08-14  |\n| 2          | 50        | 2019-08-14  |\n| 1          | 30        | 2019-08-15  |\n| 1          | 35        | 2019-08-16  |\n| 2          | 65        | 2019-08-17  |\n| 3          | 20        | 2019-08-18  |\n+------------+-----------+-------------+\n\nResult table:\n+------------+-------+\n| product_id | price |\n+------------+-------+\n| 2          | 50    |\n| 1          | 35    |\n| 3          | 10    |\n+------------+-------+\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1164](https://leetcode-cn.com/problems/product-price-at-a-given-date)", "[\u6307\u5b9a\u65e5\u671f\u7684\u4ea7\u54c1\u4ef7\u683c](/solution/1100-1199/1164.Product%20Price%20at%20a%20Given%20Date/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1164](https://leetcode.com/problems/product-price-at-a-given-date)", "[Product Price at a Given Date](/solution/1100-1199/1164.Product%20Price%20at%20a%20Given%20Date/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1277", "frontend_question_id": "1363", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/largest-multiple-of-three", "url_en": "https://leetcode.com/problems/largest-multiple-of-three", "relative_path_cn": "/solution/1300-1399/1363.Largest%20Multiple%20of%20Three/README.md", "relative_path_en": "/solution/1300-1399/1363.Largest%20Multiple%20of%20Three/README_EN.md", "title_cn": "\u5f62\u6210\u4e09\u7684\u6700\u5927\u500d\u6570", "title_en": "Largest Multiple of Three", "question_title_slug": "largest-multiple-of-three", "content_en": "

    Given an integer array of digits, return the largest multiple of three that can be formed by concatenating some of the given digits in any order.

    \n\n

    Since the answer may not fit in an integer data type, return the answer as a string.

    \n\n

    If there is no answer return an empty string.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: digits = [8,1,9]\nOutput: "981"\n
    \n\n

    Example 2:

    \n\n
    \nInput: digits = [8,6,7,1,0]\nOutput: "8760"\n
    \n\n

    Example 3:

    \n\n
    \nInput: digits = [1]\nOutput: ""\n
    \n\n

    Example 4:

    \n\n
    \nInput: digits = [0,0,0,0,0,0]\nOutput: "0"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= digits.length <= 10^4
    • \n\t
    • 0 <= digits[i] <= 9
    • \n\t
    • The returning answer must not contain unnecessary leading zeros.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 digits\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u6309\u4efb\u610f\u987a\u5e8f\u8fde\u63a5\u5176\u4e2d\u67d0\u4e9b\u6570\u5b57\u6765\u5f62\u6210 3 \u7684\u500d\u6570\uff0c\u8bf7\u4f60\u8fd4\u56de\u6240\u80fd\u5f97\u5230\u7684\u6700\u5927\u7684 3 \u7684\u500d\u6570\u3002

    \n\n

    \u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u4e0d\u5728\u6574\u6570\u6570\u636e\u7c7b\u578b\u8303\u56f4\u5185\uff0c\u8bf7\u4ee5\u5b57\u7b26\u4e32\u5f62\u5f0f\u8fd4\u56de\u7b54\u6848\u3002

    \n\n

    \u5982\u679c\u65e0\u6cd5\u5f97\u5230\u7b54\u6848\uff0c\u8bf7\u8fd4\u56de\u4e00\u4e2a\u7a7a\u5b57\u7b26\u4e32\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1adigits = [8,1,9]\n\u8f93\u51fa\uff1a"981"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1adigits = [8,6,7,1,0]\n\u8f93\u51fa\uff1a"8760"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1adigits = [1]\n\u8f93\u51fa\uff1a""\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1adigits = [0,0,0,0,0,0]\n\u8f93\u51fa\uff1a"0"\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= digits.length <= 10^4
    • \n\t
    • 0 <= digits[i] <= 9
    • \n\t
    • \u8fd4\u56de\u7684\u7ed3\u679c\u4e0d\u5e94\u5305\u542b\u4e0d\u5fc5\u8981\u7684\u524d\u5bfc\u96f6\u3002
    • \n
    \n", "tags_en": ["Math", "Dynamic Programming"], "tags_cn": ["\u6570\u5b66", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string largestMultipleOfThree(vector& digits) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String largestMultipleOfThree(int[] digits) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def largestMultipleOfThree(self, digits):\n \"\"\"\n :type digits: List[int]\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def largestMultipleOfThree(self, digits: List[int]) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * largestMultipleOfThree(int* digits, int digitsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string LargestMultipleOfThree(int[] digits) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} digits\n * @return {string}\n */\nvar largestMultipleOfThree = function(digits) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} digits\n# @return {String}\ndef largest_multiple_of_three(digits)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func largestMultipleOfThree(_ digits: [Int]) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func largestMultipleOfThree(digits []int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def largestMultipleOfThree(digits: Array[Int]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun largestMultipleOfThree(digits: IntArray): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn largest_multiple_of_three(digits: Vec) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $digits\n * @return String\n */\n function largestMultipleOfThree($digits) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function largestMultipleOfThree(digits: number[]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (largest-multiple-of-three digits)\n (-> (listof exact-integer?) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1363](https://leetcode-cn.com/problems/largest-multiple-of-three)", "[\u5f62\u6210\u4e09\u7684\u6700\u5927\u500d\u6570](/solution/1300-1399/1363.Largest%20Multiple%20of%20Three/README.md)", "`\u6570\u5b66`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1363](https://leetcode.com/problems/largest-multiple-of-three)", "[Largest Multiple of Three](/solution/1300-1399/1363.Largest%20Multiple%20of%20Three/README_EN.md)", "`Math`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "1276", "frontend_question_id": "1362", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/closest-divisors", "url_en": "https://leetcode.com/problems/closest-divisors", "relative_path_cn": "/solution/1300-1399/1362.Closest%20Divisors/README.md", "relative_path_en": "/solution/1300-1399/1362.Closest%20Divisors/README_EN.md", "title_cn": "\u6700\u63a5\u8fd1\u7684\u56e0\u6570", "title_en": "Closest Divisors", "question_title_slug": "closest-divisors", "content_en": "

    Given an integer num, find the closest two integers in absolute difference whose product equals num + 1 or num + 2.

    \n\n

    Return the two integers in any order.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: num = 8\nOutput: [3,3]\nExplanation: For num + 1 = 9, the closest divisors are 3 & 3, for num + 2 = 10, the closest divisors are 2 & 5, hence 3 & 3 is chosen.\n
    \n\n

    Example 2:

    \n\n
    \nInput: num = 123\nOutput: [5,25]\n
    \n\n

    Example 3:

    \n\n
    \nInput: num = 999\nOutput: [40,25]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= num <= 10^9
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 num\uff0c\u8bf7\u4f60\u627e\u51fa\u540c\u65f6\u6ee1\u8db3\u4e0b\u9762\u5168\u90e8\u8981\u6c42\u7684\u4e24\u4e2a\u6574\u6570\uff1a

    \n\n
      \n\t
    • \u4e24\u6570\u4e58\u79ef\u7b49\u4e8e  num + 1 \u6216 num + 2
    • \n\t
    • \u4ee5\u7edd\u5bf9\u5dee\u8fdb\u884c\u5ea6\u91cf\uff0c\u4e24\u6570\u5927\u5c0f\u6700\u63a5\u8fd1
    • \n
    \n\n

    \u4f60\u53ef\u4ee5\u6309\u4efb\u610f\u987a\u5e8f\u8fd4\u56de\u8fd9\u4e24\u4e2a\u6574\u6570\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anum = 8\n\u8f93\u51fa\uff1a[3,3]\n\u89e3\u91ca\uff1a\u5bf9\u4e8e num + 1 = 9\uff0c\u6700\u63a5\u8fd1\u7684\u4e24\u4e2a\u56e0\u6570\u662f 3 & 3\uff1b\u5bf9\u4e8e num + 2 = 10, \u6700\u63a5\u8fd1\u7684\u4e24\u4e2a\u56e0\u6570\u662f 2 & 5\uff0c\u56e0\u6b64\u8fd4\u56de 3 & 3 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anum = 123\n\u8f93\u51fa\uff1a[5,25]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1anum = 999\n\u8f93\u51fa\uff1a[40,25]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= num <= 10^9
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector closestDivisors(int num) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] closestDivisors(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def closestDivisors(self, num):\n \"\"\"\n :type num: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def closestDivisors(self, num: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* closestDivisors(int num, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] ClosestDivisors(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} num\n * @return {number[]}\n */\nvar closestDivisors = function(num) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} num\n# @return {Integer[]}\ndef closest_divisors(num)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func closestDivisors(_ num: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func closestDivisors(num int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def closestDivisors(num: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun closestDivisors(num: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn closest_divisors(num: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $num\n * @return Integer[]\n */\n function closestDivisors($num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function closestDivisors(num: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (closest-divisors num)\n (-> exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1362](https://leetcode-cn.com/problems/closest-divisors)", "[\u6700\u63a5\u8fd1\u7684\u56e0\u6570](/solution/1300-1399/1362.Closest%20Divisors/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1362](https://leetcode.com/problems/closest-divisors)", "[Closest Divisors](/solution/1300-1399/1362.Closest%20Divisors/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "1275", "frontend_question_id": "1361", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/validate-binary-tree-nodes", "url_en": "https://leetcode.com/problems/validate-binary-tree-nodes", "relative_path_cn": "/solution/1300-1399/1361.Validate%20Binary%20Tree%20Nodes/README.md", "relative_path_en": "/solution/1300-1399/1361.Validate%20Binary%20Tree%20Nodes/README_EN.md", "title_cn": "\u9a8c\u8bc1\u4e8c\u53c9\u6811", "title_en": "Validate Binary Tree Nodes", "question_title_slug": "validate-binary-tree-nodes", "content_en": "

    You have n binary tree nodes numbered from 0 to n - 1 where node i has two children leftChild[i] and rightChild[i], return true if and only if all the given nodes form exactly one valid binary tree.

    \n\n

    If node i has no left child then leftChild[i] will equal -1, similarly for the right child.

    \n\n

    Note that the nodes have no values and that we only use the node numbers in this problem.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: n = 4, leftChild = [1,-1,3,-1], rightChild = [2,-1,-1,-1]\nOutput: true\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: n = 4, leftChild = [1,-1,3,-1], rightChild = [2,3,-1,-1]\nOutput: false\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: n = 2, leftChild = [1,0], rightChild = [-1,-1]\nOutput: false\n
    \n\n

    Example 4:

    \n\"\"\n
    \nInput: n = 6, leftChild = [1,-1,-1,4,-1,-1], rightChild = [2,-1,-1,5,-1,-1]\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 104
    • \n\t
    • leftChild.length == rightChild.length == n
    • \n\t
    • -1 <= leftChild[i], rightChild[i] <= n - 1
    • \n
    \n", "content_cn": "

    \u4e8c\u53c9\u6811\u4e0a\u6709 n \u4e2a\u8282\u70b9\uff0c\u6309\u4ece 0 \u5230 n - 1 \u7f16\u53f7\uff0c\u5176\u4e2d\u8282\u70b9 i \u7684\u4e24\u4e2a\u5b50\u8282\u70b9\u5206\u522b\u662f leftChild[i] \u548c rightChild[i]\u3002

    \n\n

    \u53ea\u6709 \u6240\u6709 \u8282\u70b9\u80fd\u591f\u5f62\u6210\u4e14 \u53ea \u5f62\u6210 \u4e00\u9897 \u6709\u6548\u7684\u4e8c\u53c9\u6811\u65f6\uff0c\u8fd4\u56de true\uff1b\u5426\u5219\u8fd4\u56de false\u3002

    \n\n

    \u5982\u679c\u8282\u70b9 i \u6ca1\u6709\u5de6\u5b50\u8282\u70b9\uff0c\u90a3\u4e48 leftChild[i] \u5c31\u7b49\u4e8e -1\u3002\u53f3\u5b50\u8282\u70b9\u4e5f\u7b26\u5408\u8be5\u89c4\u5219\u3002

    \n\n

    \u6ce8\u610f\uff1a\u8282\u70b9\u6ca1\u6709\u503c\uff0c\u672c\u95ee\u9898\u4e2d\u4ec5\u4ec5\u4f7f\u7528\u8282\u70b9\u7f16\u53f7\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 4, leftChild = [1,-1,3,-1], rightChild = [2,-1,-1,-1]\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 4, leftChild = [1,-1,3,-1], rightChild = [2,3,-1,-1]\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 2, leftChild = [1,0], rightChild = [-1,-1]\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 6, leftChild = [1,-1,-1,4,-1,-1], rightChild = [2,-1,-1,5,-1,-1]\n\u8f93\u51fa\uff1afalse\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 10^4
    • \n\t
    • leftChild.length == rightChild.length == n
    • \n\t
    • -1 <= leftChild[i], rightChild[i] <= n - 1
    • \n
    \n", "tags_en": ["Graph"], "tags_cn": ["\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool validateBinaryTreeNodes(int n, vector& leftChild, vector& rightChild) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean validateBinaryTreeNodes(int n, int[] leftChild, int[] rightChild) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def validateBinaryTreeNodes(self, n, leftChild, rightChild):\n \"\"\"\n :type n: int\n :type leftChild: List[int]\n :type rightChild: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def validateBinaryTreeNodes(self, n: int, leftChild: List[int], rightChild: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool validateBinaryTreeNodes(int n, int* leftChild, int leftChildSize, int* rightChild, int rightChildSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool ValidateBinaryTreeNodes(int n, int[] leftChild, int[] rightChild) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[]} leftChild\n * @param {number[]} rightChild\n * @return {boolean}\n */\nvar validateBinaryTreeNodes = function(n, leftChild, rightChild) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[]} left_child\n# @param {Integer[]} right_child\n# @return {Boolean}\ndef validate_binary_tree_nodes(n, left_child, right_child)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func validateBinaryTreeNodes(_ n: Int, _ leftChild: [Int], _ rightChild: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func validateBinaryTreeNodes(n int, leftChild []int, rightChild []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def validateBinaryTreeNodes(n: Int, leftChild: Array[Int], rightChild: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun validateBinaryTreeNodes(n: Int, leftChild: IntArray, rightChild: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn validate_binary_tree_nodes(n: i32, left_child: Vec, right_child: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[] $leftChild\n * @param Integer[] $rightChild\n * @return Boolean\n */\n function validateBinaryTreeNodes($n, $leftChild, $rightChild) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function validateBinaryTreeNodes(n: number, leftChild: number[], rightChild: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (validate-binary-tree-nodes n leftChild rightChild)\n (-> exact-integer? (listof exact-integer?) (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1361](https://leetcode-cn.com/problems/validate-binary-tree-nodes)", "[\u9a8c\u8bc1\u4e8c\u53c9\u6811](/solution/1300-1399/1361.Validate%20Binary%20Tree%20Nodes/README.md)", "`\u56fe`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1361](https://leetcode.com/problems/validate-binary-tree-nodes)", "[Validate Binary Tree Nodes](/solution/1300-1399/1361.Validate%20Binary%20Tree%20Nodes/README_EN.md)", "`Graph`", "Medium", ""]}, {"question_id": "1274", "frontend_question_id": "1360", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-days-between-two-dates", "url_en": "https://leetcode.com/problems/number-of-days-between-two-dates", "relative_path_cn": "/solution/1300-1399/1360.Number%20of%20Days%20Between%20Two%20Dates/README.md", "relative_path_en": "/solution/1300-1399/1360.Number%20of%20Days%20Between%20Two%20Dates/README_EN.md", "title_cn": "\u65e5\u671f\u4e4b\u95f4\u9694\u51e0\u5929", "title_en": "Number of Days Between Two Dates", "question_title_slug": "number-of-days-between-two-dates", "content_en": "

    Write a program to count the number of days between two dates.

    \n\n

    The two dates are given as strings, their format is YYYY-MM-DD as shown in the examples.

    \n\n

     

    \n

    Example 1:

    \n
    Input: date1 = \"2019-06-29\", date2 = \"2019-06-30\"\nOutput: 1\n

    Example 2:

    \n
    Input: date1 = \"2020-01-15\", date2 = \"2019-12-31\"\nOutput: 15\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The given dates are valid dates between the years 1971 and 2100.
    • \n
    \n", "content_cn": "

    \u8bf7\u4f60\u7f16\u5199\u4e00\u4e2a\u7a0b\u5e8f\u6765\u8ba1\u7b97\u4e24\u4e2a\u65e5\u671f\u4e4b\u95f4\u9694\u4e86\u591a\u5c11\u5929\u3002

    \n\n

    \u65e5\u671f\u4ee5\u5b57\u7b26\u4e32\u5f62\u5f0f\u7ed9\u51fa\uff0c\u683c\u5f0f\u4e3a YYYY-MM-DD\uff0c\u5982\u793a\u4f8b\u6240\u793a\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1adate1 = "2019-06-29", date2 = "2019-06-30"\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1adate1 = "2020-01-15", date2 = "2019-12-31"\n\u8f93\u51fa\uff1a15\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u7ed9\u5b9a\u7684\u65e5\u671f\u662f 1971 \u5e74\u5230 2100 \u5e74\u4e4b\u95f4\u7684\u6709\u6548\u65e5\u671f\u3002
    • \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int daysBetweenDates(string date1, string date2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int daysBetweenDates(String date1, String date2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def daysBetweenDates(self, date1, date2):\n \"\"\"\n :type date1: str\n :type date2: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def daysBetweenDates(self, date1: str, date2: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint daysBetweenDates(char * date1, char * date2){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int DaysBetweenDates(string date1, string date2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} date1\n * @param {string} date2\n * @return {number}\n */\nvar daysBetweenDates = function(date1, date2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} date1\n# @param {String} date2\n# @return {Integer}\ndef days_between_dates(date1, date2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func daysBetweenDates(_ date1: String, _ date2: String) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func daysBetweenDates(date1 string, date2 string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def daysBetweenDates(date1: String, date2: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun daysBetweenDates(date1: String, date2: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn days_between_dates(date1: String, date2: String) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $date1\n * @param String $date2\n * @return Integer\n */\n function daysBetweenDates($date1, $date2) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function daysBetweenDates(date1: string, date2: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (days-between-dates date1 date2)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1360](https://leetcode-cn.com/problems/number-of-days-between-two-dates)", "[\u65e5\u671f\u4e4b\u95f4\u9694\u51e0\u5929](/solution/1300-1399/1360.Number%20of%20Days%20Between%20Two%20Dates/README.md)", "", "\u7b80\u5355", ""], "md_table_row_en": ["[1360](https://leetcode.com/problems/number-of-days-between-two-dates)", "[Number of Days Between Two Dates](/solution/1300-1399/1360.Number%20of%20Days%20Between%20Two%20Dates/README_EN.md)", "", "Easy", ""]}, {"question_id": "1273", "frontend_question_id": "1170", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/compare-strings-by-frequency-of-the-smallest-character", "url_en": "https://leetcode.com/problems/compare-strings-by-frequency-of-the-smallest-character", "relative_path_cn": "/solution/1100-1199/1170.Compare%20Strings%20by%20Frequency%20of%20the%20Smallest%20Character/README.md", "relative_path_en": "/solution/1100-1199/1170.Compare%20Strings%20by%20Frequency%20of%20the%20Smallest%20Character/README_EN.md", "title_cn": "\u6bd4\u8f83\u5b57\u7b26\u4e32\u6700\u5c0f\u5b57\u6bcd\u51fa\u73b0\u9891\u6b21", "title_en": "Compare Strings by Frequency of the Smallest Character", "question_title_slug": "compare-strings-by-frequency-of-the-smallest-character", "content_en": "

    Let the function f(s) be the frequency of the lexicographically smallest character in a non-empty string s. For example, if s = "dcce" then f(s) = 2 because the lexicographically smallest character is 'c', which has a frequency of 2.

    \n\n

    You are given an array of strings words and another array of query strings queries. For each query queries[i], count the number of words in words such that f(queries[i]) < f(W) for each W in words.

    \n\n

    Return an integer array answer, where each answer[i] is the answer to the ith query.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: queries = ["cbd"], words = ["zaaaz"]\nOutput: [1]\nExplanation: On the first query we have f("cbd") = 1, f("zaaaz") = 3 so f("cbd") < f("zaaaz").\n
    \n\n

    Example 2:

    \n\n
    \nInput: queries = ["bbb","cc"], words = ["a","aa","aaa","aaaa"]\nOutput: [1,2]\nExplanation: On the first query only f("bbb") < f("aaaa"). On the second query both f("aaa") and f("aaaa") are both > f("cc").\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= queries.length <= 2000
    • \n\t
    • 1 <= words.length <= 2000
    • \n\t
    • 1 <= queries[i].length, words[i].length <= 10
    • \n\t
    • queries[i][j], words[i][j] consist of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u5b9a\u4e49\u4e00\u4e2a\u51fd\u6570\u00a0f(s)\uff0c\u7edf\u8ba1\u00a0s \u00a0\u4e2d\uff08\u6309\u5b57\u5178\u5e8f\u6bd4\u8f83\uff09\u6700\u5c0f\u5b57\u6bcd\u7684\u51fa\u73b0\u9891\u6b21 \uff0c\u5176\u4e2d s\u00a0\u662f\u4e00\u4e2a\u975e\u7a7a\u5b57\u7b26\u4e32\u3002

    \n\n

    \u4f8b\u5982\uff0c\u82e5\u00a0s = \"dcce\"\uff0c\u90a3\u4e48\u00a0f(s) = 2\uff0c\u56e0\u4e3a\u5b57\u5178\u5e8f\u6700\u5c0f\u5b57\u6bcd\u662f\u00a0\"c\"\uff0c\u5b83\u51fa\u73b0\u4e86\u00a02 \u6b21\u3002

    \n\n

    \u73b0\u5728\uff0c\u7ed9\u4f60\u4e24\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4\u5f85\u67e5\u8868\u00a0queries\u00a0\u548c\u8bcd\u6c47\u8868\u00a0words \u3002\u5bf9\u4e8e\u6bcf\u6b21\u67e5\u8be2\u00a0queries[i] \uff0c\u9700\u7edf\u8ba1 words \u4e2d\u6ee1\u8db3\u00a0f(queries[i])\u00a0< f(W)\u00a0\u7684 \u8bcd\u7684\u6570\u76ee \uff0cW \u8868\u793a\u8bcd\u6c47\u8868\u00a0words\u00a0\u4e2d\u7684\u6bcf\u4e2a\u8bcd\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0answer\u00a0\u4f5c\u4e3a\u7b54\u6848\uff0c\u5176\u4e2d\u6bcf\u4e2a\u00a0answer[i]\u00a0\u662f\u7b2c i \u6b21\u67e5\u8be2\u7684\u7ed3\u679c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aqueries = [\"cbd\"], words = [\"zaaaz\"]\n\u8f93\u51fa\uff1a[1]\n\u89e3\u91ca\uff1a\u67e5\u8be2 f(\"cbd\") = 1\uff0c\u800c f(\"zaaaz\") = 3 \u6240\u4ee5 f(\"cbd\") < f(\"zaaaz\")\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aqueries = [\"bbb\",\"cc\"], words = [\"a\",\"aa\",\"aaa\",\"aaaa\"]\n\u8f93\u51fa\uff1a[1,2]\n\u89e3\u91ca\uff1a\u7b2c\u4e00\u4e2a\u67e5\u8be2 f(\"bbb\") < f(\"aaaa\")\uff0c\u7b2c\u4e8c\u4e2a\u67e5\u8be2 f(\"aaa\") \u548c f(\"aaaa\") \u90fd > f(\"cc\")\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= queries.length <= 2000
    • \n\t
    • 1 <= words.length <= 2000
    • \n\t
    • 1 <= queries[i].length, words[i].length <= 10
    • \n\t
    • queries[i][j]\u3001words[i][j] \u90fd\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n", "tags_en": ["Array", "String", "Binary Search"], "tags_cn": ["\u6570\u7ec4", "\u5b57\u7b26\u4e32", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector numSmallerByFrequency(vector& queries, vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] numSmallerByFrequency(String[] queries, String[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numSmallerByFrequency(self, queries, words):\n \"\"\"\n :type queries: List[str]\n :type words: List[str]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numSmallerByFrequency(self, queries: List[str], words: List[str]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* numSmallerByFrequency(char ** queries, int queriesSize, char ** words, int wordsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] NumSmallerByFrequency(string[] queries, string[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} queries\n * @param {string[]} words\n * @return {number[]}\n */\nvar numSmallerByFrequency = function(queries, words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} queries\n# @param {String[]} words\n# @return {Integer[]}\ndef num_smaller_by_frequency(queries, words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numSmallerByFrequency(_ queries: [String], _ words: [String]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numSmallerByFrequency(queries []string, words []string) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numSmallerByFrequency(queries: Array[String], words: Array[String]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numSmallerByFrequency(queries: Array, words: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_smaller_by_frequency(queries: Vec, words: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $queries\n * @param String[] $words\n * @return Integer[]\n */\n function numSmallerByFrequency($queries, $words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numSmallerByFrequency(queries: string[], words: string[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-smaller-by-frequency queries words)\n (-> (listof string?) (listof string?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1170](https://leetcode-cn.com/problems/compare-strings-by-frequency-of-the-smallest-character)", "[\u6bd4\u8f83\u5b57\u7b26\u4e32\u6700\u5c0f\u5b57\u6bcd\u51fa\u73b0\u9891\u6b21](/solution/1100-1199/1170.Compare%20Strings%20by%20Frequency%20of%20the%20Smallest%20Character/README.md)", "`\u6570\u7ec4`,`\u5b57\u7b26\u4e32`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1170](https://leetcode.com/problems/compare-strings-by-frequency-of-the-smallest-character)", "[Compare Strings by Frequency of the Smallest Character](/solution/1100-1199/1170.Compare%20Strings%20by%20Frequency%20of%20the%20Smallest%20Character/README_EN.md)", "`Array`,`String`,`Binary Search`", "Medium", ""]}, {"question_id": "1272", "frontend_question_id": "1169", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/invalid-transactions", "url_en": "https://leetcode.com/problems/invalid-transactions", "relative_path_cn": "/solution/1100-1199/1169.Invalid%20Transactions/README.md", "relative_path_en": "/solution/1100-1199/1169.Invalid%20Transactions/README_EN.md", "title_cn": "\u67e5\u8be2\u65e0\u6548\u4ea4\u6613", "title_en": "Invalid Transactions", "question_title_slug": "invalid-transactions", "content_en": "

    A transaction is possibly invalid if:

    \n\n
      \n\t
    • the amount exceeds $1000, or;
    • \n\t
    • if it occurs within (and including) 60 minutes of another transaction with the same name in a different city.
    • \n
    \n\n

    You are given an array of strings transaction where transactions[i] consists of comma-separated values representing the name, time (in minutes), amount, and city of the transaction.

    \n\n

    Return a list of transactions that are possibly invalid. You may return the answer in any order.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: transactions = ["alice,20,800,mtv","alice,50,100,beijing"]\nOutput: ["alice,20,800,mtv","alice,50,100,beijing"]\nExplanation: The first transaction is invalid because the second transaction occurs within a difference of 60 minutes, have the same name and is in a different city. Similarly the second one is invalid too.
    \n\n

    Example 2:

    \n\n
    \nInput: transactions = ["alice,20,800,mtv","alice,50,1200,mtv"]\nOutput: ["alice,50,1200,mtv"]\n
    \n\n

    Example 3:

    \n\n
    \nInput: transactions = ["alice,20,800,mtv","bob,50,1200,mtv"]\nOutput: ["bob,50,1200,mtv"]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • transactions.length <= 1000
    • \n\t
    • Each transactions[i] takes the form "{name},{time},{amount},{city}"
    • \n\t
    • Each {name} and {city} consist of lowercase English letters, and have lengths between 1 and 10.
    • \n\t
    • Each {time} consist of digits, and represent an integer between 0 and 1000.
    • \n\t
    • Each {amount} consist of digits, and represent an integer between 0 and 2000.
    • \n
    \n", "content_cn": "

    \u5982\u679c\u51fa\u73b0\u4e0b\u8ff0\u4e24\u79cd\u60c5\u51b5\uff0c\u4ea4\u6613 \u53ef\u80fd\u65e0\u6548\uff1a

    \n\n
      \n\t
    • \u4ea4\u6613\u91d1\u989d\u8d85\u8fc7 ¥1000
    • \n\t
    • \u6216\u8005\uff0c\u5b83\u548c\u53e6\u4e00\u4e2a\u57ce\u5e02\u4e2d\u540c\u540d\u7684\u53e6\u4e00\u7b14\u4ea4\u6613\u76f8\u9694\u4e0d\u8d85\u8fc7 60 \u5206\u949f\uff08\u5305\u542b 60 \u5206\u949f\u6574\uff09
    • \n
    \n\n

    \u6bcf\u4e2a\u4ea4\u6613\u5b57\u7b26\u4e32 transactions[i] \u7531\u4e00\u4e9b\u7528\u9017\u53f7\u5206\u9694\u7684\u503c\u7ec4\u6210\uff0c\u8fd9\u4e9b\u503c\u5206\u522b\u8868\u793a\u4ea4\u6613\u7684\u540d\u79f0\uff0c\u65f6\u95f4\uff08\u4ee5\u5206\u949f\u8ba1\uff09\uff0c\u91d1\u989d\u4ee5\u53ca\u57ce\u5e02\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4efd\u4ea4\u6613\u6e05\u5355 transactions\uff0c\u8fd4\u56de\u53ef\u80fd\u65e0\u6548\u7684\u4ea4\u6613\u5217\u8868\u3002\u4f60\u53ef\u4ee5\u6309\u4efb\u4f55\u987a\u5e8f\u8fd4\u56de\u7b54\u6848\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1atransactions = ["alice,20,800,mtv","alice,50,100,beijing"]\n\u8f93\u51fa\uff1a["alice,20,800,mtv","alice,50,100,beijing"]\n\u89e3\u91ca\uff1a\u7b2c\u4e00\u7b14\u4ea4\u6613\u662f\u65e0\u6548\u7684\uff0c\u56e0\u4e3a\u7b2c\u4e8c\u7b14\u4ea4\u6613\u548c\u5b83\u95f4\u9694\u4e0d\u8d85\u8fc7 60 \u5206\u949f\u3001\u540d\u79f0\u76f8\u540c\u4e14\u53d1\u751f\u5728\u4e0d\u540c\u7684\u57ce\u5e02\u3002\u540c\u6837\uff0c\u7b2c\u4e8c\u7b14\u4ea4\u6613\u4e5f\u662f\u65e0\u6548\u7684\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1atransactions = ["alice,20,800,mtv","alice,50,1200,mtv"]\n\u8f93\u51fa\uff1a["alice,50,1200,mtv"]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1atransactions = ["alice,20,800,mtv","bob,50,1200,mtv"]\n\u8f93\u51fa\uff1a["bob,50,1200,mtv"]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • transactions.length <= 1000
    • \n\t
    • \u6bcf\u7b14\u4ea4\u6613 transactions[i] \u6309 "{name},{time},{amount},{city}" \u7684\u683c\u5f0f\u8fdb\u884c\u8bb0\u5f55
    • \n\t
    • \u6bcf\u4e2a\u4ea4\u6613\u540d\u79f0 {name} \u548c\u57ce\u5e02 {city} \u90fd\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\uff0c\u957f\u5ea6\u5728 1 \u5230 10 \u4e4b\u95f4
    • \n\t
    • \u6bcf\u4e2a\u4ea4\u6613\u65f6\u95f4 {time} \u7531\u4e00\u4e9b\u6570\u5b57\u7ec4\u6210\uff0c\u8868\u793a\u4e00\u4e2a 0 \u5230 1000 \u4e4b\u95f4\u7684\u6574\u6570
    • \n\t
    • \u6bcf\u7b14\u4ea4\u6613\u91d1\u989d {amount} \u7531\u4e00\u4e9b\u6570\u5b57\u7ec4\u6210\uff0c\u8868\u793a\u4e00\u4e2a 0 \u5230 2000 \u4e4b\u95f4\u7684\u6574\u6570
    • \n
    \n", "tags_en": ["Array", "String"], "tags_cn": ["\u6570\u7ec4", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector invalidTransactions(vector& transactions) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List invalidTransactions(String[] transactions) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def invalidTransactions(self, transactions):\n \"\"\"\n :type transactions: List[str]\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def invalidTransactions(self, transactions: List[str]) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** invalidTransactions(char ** transactions, int transactionsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList InvalidTransactions(string[] transactions) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} transactions\n * @return {string[]}\n */\nvar invalidTransactions = function(transactions) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} transactions\n# @return {String[]}\ndef invalid_transactions(transactions)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func invalidTransactions(_ transactions: [String]) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func invalidTransactions(transactions []string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def invalidTransactions(transactions: Array[String]): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun invalidTransactions(transactions: Array): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn invalid_transactions(transactions: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $transactions\n * @return String[]\n */\n function invalidTransactions($transactions) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function invalidTransactions(transactions: string[]): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (invalid-transactions transactions)\n (-> (listof string?) (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1169](https://leetcode-cn.com/problems/invalid-transactions)", "[\u67e5\u8be2\u65e0\u6548\u4ea4\u6613](/solution/1100-1199/1169.Invalid%20Transactions/README.md)", "`\u6570\u7ec4`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1169](https://leetcode.com/problems/invalid-transactions)", "[Invalid Transactions](/solution/1100-1199/1169.Invalid%20Transactions/README_EN.md)", "`Array`,`String`", "Medium", ""]}, {"question_id": "1271", "frontend_question_id": "1236", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/web-crawler", "url_en": "https://leetcode.com/problems/web-crawler", "relative_path_cn": "/solution/1200-1299/1236.Web%20Crawler/README.md", "relative_path_en": "/solution/1200-1299/1236.Web%20Crawler/README_EN.md", "title_cn": "\u7f51\u7edc\u722c\u866b", "title_en": "Web Crawler", "question_title_slug": "web-crawler", "content_en": "

    Given a url startUrl and an interface HtmlParser, implement a web crawler to crawl all links that are under the same hostname as startUrl

    \n\n

    Return all urls obtained by your web crawler in any order.

    \n\n

    Your crawler should:

    \n\n
      \n\t
    • Start from the page: startUrl
    • \n\t
    • Call HtmlParser.getUrls(url) to get all urls from a webpage of given url.
    • \n\t
    • Do not crawl the same link twice.
    • \n\t
    • Explore only the links that are under the same hostname as startUrl.
    • \n
    \n\n

    \"\"

    \n\n

    As shown in the example url above, the hostname is example.org. For simplicity sake, you may assume all urls use http protocol without any port specified. For example, the urls http://leetcode.com/problems and http://leetcode.com/contest are under the same hostname, while urls http://example.org/test and http://example.com/abc are not under the same hostname.

    \n\n

    The HtmlParser interface is defined as such: 

    \n\n
    \ninterface HtmlParser {\n  // Return a list of all urls from a webpage of given url.\n  public List<String> getUrls(String url);\n}
    \n\n

    Below are two examples explaining the functionality of the problem, for custom testing purposes you'll have three variables urlsedges and startUrl. Notice that you will only have access to startUrl in your code, while urls and edges are not directly accessible to you in code.

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput:\nurls = [\n  "http://news.yahoo.com",\n  "http://news.yahoo.com/news",\n  "http://news.yahoo.com/news/topics/",\n  "http://news.google.com",\n  "http://news.yahoo.com/us"\n]\nedges = [[2,0],[2,1],[3,2],[3,1],[0,4]]\nstartUrl = "http://news.yahoo.com/news/topics/"\nOutput: [\n  "http://news.yahoo.com",\n  "http://news.yahoo.com/news",\n  "http://news.yahoo.com/news/topics/",\n  "http://news.yahoo.com/us"\n]\n
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: \nurls = [\n  "http://news.yahoo.com",\n  "http://news.yahoo.com/news",\n  "http://news.yahoo.com/news/topics/",\n  "http://news.google.com"\n]\nedges = [[0,2],[2,1],[3,2],[3,1],[3,0]]\nstartUrl = "http://news.google.com"\nOutput: ["http://news.google.com"]\nExplanation: The startUrl links to all other pages that do not share the same hostname.
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= urls.length <= 1000
    • \n\t
    • 1 <= urls[i].length <= 300
    • \n\t
    • startUrl is one of the urls.
    • \n\t
    • Hostname label must be from 1 to 63 characters long, including the dots, may contain only the ASCII letters from 'a' to 'z', digits  from '0' to '9' and the hyphen-minus character ('-').
    • \n\t
    • The hostname may not start or end with the hyphen-minus character ('-'). 
    • \n\t
    • See:  https://en.wikipedia.org/wiki/Hostname#Restrictions_on_valid_hostnames
    • \n\t
    • You may assume there're no duplicates in url library.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u94fe\u63a5 startUrl \u548c\u4e00\u4e2a\u63a5\u53e3 HtmlParser \uff0c\u8bf7\u4f60\u5b9e\u73b0\u4e00\u4e2a\u7f51\u7edc\u722c\u866b\uff0c\u4ee5\u5b9e\u73b0\u722c\u53d6\u540c startUrl \u62e5\u6709\u76f8\u540c \u57df\u540d\u6807\u7b7e \u7684\u5168\u90e8\u94fe\u63a5\u3002\u8be5\u722c\u866b\u5f97\u5230\u7684\u5168\u90e8\u94fe\u63a5\u53ef\u4ee5 \u4efb\u4f55\u987a\u5e8f \u8fd4\u56de\u7ed3\u679c\u3002

    \n\n

    \u4f60\u7684\u7f51\u7edc\u722c\u866b\u5e94\u5f53\u6309\u7167\u5982\u4e0b\u6a21\u5f0f\u5de5\u4f5c\uff1a

    \n\n
      \n\t
    • \u81ea\u94fe\u63a5 startUrl \u5f00\u59cb\u722c\u53d6
    • \n\t
    • \u8c03\u7528 HtmlParser.getUrls(url) \u6765\u83b7\u5f97\u94fe\u63a5url\u9875\u9762\u4e2d\u7684\u5168\u90e8\u94fe\u63a5
    • \n\t
    • \u540c\u4e00\u4e2a\u94fe\u63a5\u6700\u591a\u53ea\u722c\u53d6\u4e00\u6b21
    • \n\t
    • \u53ea\u8f93\u51fa \u57df\u540d \u4e0e startUrl \u76f8\u540c \u7684\u94fe\u63a5\u96c6\u5408
    • \n
    \n\n

    \"\"

    \n\n

    \u5982\u4e0a\u6240\u793a\u7684\u4e00\u4e2a\u94fe\u63a5\uff0c\u5176\u57df\u540d\u4e3a example.org\u3002\u7b80\u5355\u8d77\u89c1\uff0c\u4f60\u53ef\u4ee5\u5047\u8bbe\u6240\u6709\u7684\u94fe\u63a5\u90fd\u91c7\u7528 http\u534f\u8bae \u5e76\u6ca1\u6709\u6307\u5b9a \u7aef\u53e3\u3002\u4f8b\u5982\uff0c\u94fe\u63a5 http://leetcode.com/problems \u548c http://leetcode.com/contest \u662f\u540c\u4e00\u4e2a\u57df\u540d\u4e0b\u7684\uff0c\u800c\u94fe\u63a5http://example.org/test \u548c http://example.com/abc \u662f\u4e0d\u5728\u540c\u4e00\u57df\u540d\u4e0b\u7684\u3002

    \n\n

    HtmlParser \u63a5\u53e3\u5b9a\u4e49\u5982\u4e0b\uff1a 

    \n\n
    interface HtmlParser {\n  // \u8fd4\u56de\u7ed9\u5b9a url \u5bf9\u5e94\u7684\u9875\u9762\u4e2d\u7684\u5168\u90e8 url \u3002\n  public List<String> getUrls(String url);\n}
    \n\n

    \u4e0b\u9762\u662f\u4e24\u4e2a\u5b9e\u4f8b\uff0c\u7528\u4ee5\u89e3\u91ca\u8be5\u95ee\u9898\u7684\u8bbe\u8ba1\u529f\u80fd\uff0c\u5bf9\u4e8e\u81ea\u5b9a\u4e49\u6d4b\u8bd5\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4e09\u4e2a\u53d8\u91cf  urlsedges \u548c startUrl\u3002\u6ce8\u610f\u5728\u4ee3\u7801\u5b9e\u73b0\u4e2d\uff0c\u4f60\u53ea\u53ef\u4ee5\u8bbf\u95ee startUrl \uff0c\u800c urls \u548c edges \u4e0d\u53ef\u4ee5\u5728\u4f60\u7684\u4ee3\u7801\u4e2d\u88ab\u76f4\u63a5\u8bbf\u95ee\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1a\nurls = [\n  "http://news.yahoo.com",\n  "http://news.yahoo.com/news",\n  "http://news.yahoo.com/news/topics/",\n  "http://news.google.com",\n  "http://news.yahoo.com/us"\n]\nedges = [[2,0],[2,1],[3,2],[3,1],[0,4]]\nstartUrl = "http://news.yahoo.com/news/topics/"\n\u8f93\u51fa\uff1a[\n  "http://news.yahoo.com",\n  "http://news.yahoo.com/news",\n  "http://news.yahoo.com/news/topics/",\n  "http://news.yahoo.com/us"\n]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1a\nurls = [\n  "http://news.yahoo.com",\n  "http://news.yahoo.com/news",\n  "http://news.yahoo.com/news/topics/",\n  "http://news.google.com"\n]\nedges = [[0,2],[2,1],[3,2],[3,1],[3,0]]\nstartUrl = "http://news.google.com"\n\u8f93\u5165\uff1a["http://news.google.com"]\n\u89e3\u91ca\uff1astartUrl \u94fe\u63a5\u5230\u6240\u6709\u5176\u4ed6\u4e0d\u5171\u4eab\u76f8\u540c\u4e3b\u673a\u540d\u7684\u9875\u9762\u3002
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= urls.length <= 1000
    • \n\t
    • 1 <= urls[i].length <= 300
    • \n\t
    • startUrl \u4e3a urls \u4e2d\u7684\u4e00\u4e2a\u3002
    • \n\t
    • \u57df\u540d\u6807\u7b7e\u7684\u957f\u4e3a1\u523063\u4e2a\u5b57\u7b26\uff08\u5305\u62ec\u70b9\uff09\uff0c\u53ea\u80fd\u5305\u542b\u4ece‘a’\u5230‘z’\u7684ASCII\u5b57\u6bcd\u3001‘0’\u5230‘9’\u7684\u6570\u5b57\u4ee5\u53ca\u8fde\u5b57\u7b26\u5373\u51cf\u53f7\uff08‘-’\uff09\u3002
    • \n\t
    • \u57df\u540d\u6807\u7b7e\u4e0d\u4f1a\u4ee5\u8fde\u5b57\u7b26\u5373\u51cf\u53f7\uff08‘-’\uff09\u5f00\u5934\u6216\u7ed3\u5c3e\u3002
    • \n\t
    • \u5173\u4e8e\u57df\u540d\u6709\u6548\u6027\u7684\u7ea6\u675f\u53ef\u53c2\u8003:  https://en.wikipedia.org/wiki/Hostname#Restrictions_on_valid_hostnames
    • \n\t
    • \u4f60\u53ef\u4ee5\u5047\u5b9aurl\u5e93\u4e2d\u4e0d\u5305\u542b\u91cd\u590d\u9879\u3002
    • \n
    \n", "tags_en": ["Depth-first Search", "Breadth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * // This is the HtmlParser's API interface.\n * // You should not implement it, or speculate about its implementation\n * class HtmlParser {\n * public:\n * vector getUrls(string url);\n * };\n */\n\nclass Solution {\npublic:\n vector crawl(string startUrl, HtmlParser htmlParser) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * // This is the HtmlParser's API interface.\n * // You should not implement it, or speculate about its implementation\n * interface HtmlParser {\n * public List getUrls(String url) {}\n * }\n */\n\nclass Solution {\n public List crawl(String startUrl, HtmlParser htmlParser) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# \"\"\"\n# This is HtmlParser's API interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class HtmlParser(object):\n# def getUrls(self, url):\n# \"\"\"\n# :type url: str\n# :rtype List[str]\n# \"\"\"\n\nclass Solution(object):\n def crawl(self, startUrl, htmlParser):\n \"\"\"\n :type startUrl: str\n :type htmlParser: HtmlParser\n :rtype: List[str]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# \"\"\"\n# This is HtmlParser's API interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class HtmlParser(object):\n# def getUrls(self, url):\n# \"\"\"\n# :type url: str\n# :rtype List[str]\n# \"\"\"\n\nclass Solution:\n def crawl(self, startUrl: str, htmlParser: 'HtmlParser') -> List[str]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * // This is the HtmlParser's API interface.\n * // You should not implement it, or speculate about its implementation\n * class HtmlParser {\n * public List GetUrls(String url) {}\n * }\n */\n\nclass Solution {\n public IList Crawl(string startUrl, HtmlParser htmlParser) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // This is the HtmlParser's API interface.\n * // You should not implement it, or speculate about its implementation\n * function HtmlParser() {\n *\n *\t\t@param {string} url\n * \t@return {string[]}\n * \tthis.getUrls = function(url) {\n * \t...\n * \t};\n * };\n */\n\n/**\n * @param {string} startUrl\n * @param {HtmlParser} htmlParser\n * @return {string[]}\n*/\nvar crawl = function(startUrl, htmlParser) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# This is HtmlParser's API interface.\n# You should not implement it, or speculate about its implementation\n# class HtmlParser\n# def getUrls(url)\n# @return {List[String]}\n# end\n# end\n\n# @param {String} startUrl\n# @param {HtmlParser} htmlParser\n# @return {String}\ndef crawl(startUrl, htmlParser)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * // This is the HtmlParser's API interface.\n * // You should not implement it, or speculate about its implementation\n * public class HtmlParser {\n * public func getUrls(_ url: String) -> [String] {}\n * }\n */\n\nclass Solution { \n func crawl(_ startUrl: String, _ htmlParser: HtmlParser) -> [String] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * // This is HtmlParser's API interface.\n * // You should not implement it, or speculate about its implementation\n * type HtmlParser struct {\n * func GetUrls(url string) []string {}\n * }\n */\n\nfunc crawl(startUrl string, htmlParser HtmlParser) []string {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * // This is the HtmlParser's API interface.\n * // You should not implement it, or speculate about its implementation\n * class HtmlParser {\n * def getUrls(url: String): List[String] = {}\n * }\n */\n\nobject Solution {\n def crawl(startUrl: String, htmlParser: HtmlParser): Array[String] = {\n \t\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * // This is the HtmlParser's API interface.\n * // You should not implement it, or speculate about its implementation\n * class HtmlParser {\n * fun getUrls(url:String):List {}\n * }\n */\n\nclass Solution {\n fun crawl(startUrl:String, htmlParser:HtmlParser):List {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * // This is the HtmlParser's API interface.\n * // You should not implement it, or speculate about its implementation\n * class {\n * public function getUrls($url) {}\n * }\n */\n\nclass Solution {\n /**\n * @param String $startUrl\n * @param HtmlParser $htmlParser\n * @return String[]\n */\n function crawl($startUrl, $htmlParser) {\n\t\t\n\t}\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * // This is the HtmlParser's API interface.\n * // You should not implement it, or speculate about its implementation\n * class HtmlParser {\n * getUrls(url: string): string[] {}\n * }\n */\n\nfunction crawl(startUrl: string, htmlParser: HtmlParser): string[] {\n\t\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1236](https://leetcode-cn.com/problems/web-crawler)", "[\u7f51\u7edc\u722c\u866b](/solution/1200-1299/1236.Web%20Crawler/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1236](https://leetcode.com/problems/web-crawler)", "[Web Crawler](/solution/1200-1299/1236.Web%20Crawler/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`", "Medium", "\ud83d\udd12"]}, {"question_id": "1270", "frontend_question_id": "1172", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/dinner-plate-stacks", "url_en": "https://leetcode.com/problems/dinner-plate-stacks", "relative_path_cn": "/solution/1100-1199/1172.Dinner%20Plate%20Stacks/README.md", "relative_path_en": "/solution/1100-1199/1172.Dinner%20Plate%20Stacks/README_EN.md", "title_cn": "\u9910\u76d8\u6808", "title_en": "Dinner Plate Stacks", "question_title_slug": "dinner-plate-stacks", "content_en": "

    You have an infinite number of stacks arranged in a row and numbered (left to right) from 0, each of the stacks has the same maximum capacity.

    \n\n

    Implement the DinnerPlates class:

    \n\n
      \n\t
    • DinnerPlates(int capacity) Initializes the object with the maximum capacity of the stacks.
    • \n\t
    • void push(int val) Pushes the given positive integer val into the leftmost stack with size less than capacity.
    • \n\t
    • int pop() Returns the value at the top of the rightmost non-empty stack and removes it from that stack, and returns -1 if all stacks are empty.
    • \n\t
    • int popAtStack(int index) Returns the value at the top of the stack with the given index and removes it from that stack, and returns -1 if the stack with that given index is empty.
    • \n
    \n\n

    Example:

    \n\n
    \nInput: \n["DinnerPlates","push","push","push","push","push","popAtStack","push","push","popAtStack","popAtStack","pop","pop","pop","pop","pop"]\n[[2],[1],[2],[3],[4],[5],[0],[20],[21],[0],[2],[],[],[],[],[]]\nOutput: \n[null,null,null,null,null,null,2,null,null,20,21,5,4,3,1,-1]\n\nExplanation: \nDinnerPlates D = DinnerPlates(2);  // Initialize with capacity = 2\nD.push(1);\nD.push(2);\nD.push(3);\nD.push(4);\nD.push(5);         // The stacks are now:  2  4\n                                           1  3  5\n                                           \ufe48 \ufe48 \ufe48\nD.popAtStack(0);   // Returns 2.  The stacks are now:     4\n                                                       1  3  5\n                                                       \ufe48 \ufe48 \ufe48\nD.push(20);        // The stacks are now: 20  4\n                                           1  3  5\n                                           \ufe48 \ufe48 \ufe48\nD.push(21);        // The stacks are now: 20  4 21\n                                           1  3  5\n                                           \ufe48 \ufe48 \ufe48\nD.popAtStack(0);   // Returns 20.  The stacks are now:     4 21\n                                                        1  3  5\n                                                        \ufe48 \ufe48 \ufe48\nD.popAtStack(2);   // Returns 21.  The stacks are now:     4\n                                                        1  3  5\n                                                        \ufe48 \ufe48 \ufe48 \nD.pop()            // Returns 5.  The stacks are now:      4\n                                                        1  3 \n                                                        \ufe48 \ufe48  \nD.pop()            // Returns 4.  The stacks are now:   1  3 \n                                                        \ufe48 \ufe48   \nD.pop()            // Returns 3.  The stacks are now:   1 \n                                                        \ufe48   \nD.pop()            // Returns 1.  There are no stacks.\nD.pop()            // Returns -1.  There are still no stacks.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= capacity <= 20000
    • \n\t
    • 1 <= val <= 20000
    • \n\t
    • 0 <= index <= 100000
    • \n\t
    • At most 200000 calls will be made to push, pop, and popAtStack.
    • \n
    \n", "content_cn": "

    \u6211\u4eec\u628a\u65e0\u9650\u6570\u91cf ∞ \u7684\u6808\u6392\u6210\u4e00\u884c\uff0c\u6309\u4ece\u5de6\u5230\u53f3\u7684\u6b21\u5e8f\u4ece 0 \u5f00\u59cb\u7f16\u53f7\u3002\u6bcf\u4e2a\u6808\u7684\u7684\u6700\u5927\u5bb9\u91cf capacity \u90fd\u76f8\u540c\u3002

    \n\n

    \u5b9e\u73b0\u4e00\u4e2a\u53eb\u300c\u9910\u76d8\u300d\u7684\u7c7b DinnerPlates\uff1a

    \n\n
      \n\t
    • DinnerPlates(int capacity) - \u7ed9\u51fa\u6808\u7684\u6700\u5927\u5bb9\u91cf capacity\u3002
    • \n\t
    • void push(int val) - \u5c06\u7ed9\u51fa\u7684\u6b63\u6574\u6570 val \u63a8\u5165 \u4ece\u5de6\u5f80\u53f3\u7b2c\u4e00\u4e2a \u6ca1\u6709\u6ee1\u7684\u6808\u3002
    • \n\t
    • int pop() - \u8fd4\u56de \u4ece\u53f3\u5f80\u5de6\u7b2c\u4e00\u4e2a \u975e\u7a7a\u6808\u9876\u90e8\u7684\u503c\uff0c\u5e76\u5c06\u5176\u4ece\u6808\u4e2d\u5220\u9664\uff1b\u5982\u679c\u6240\u6709\u7684\u6808\u90fd\u662f\u7a7a\u7684\uff0c\u8bf7\u8fd4\u56de -1\u3002
    • \n\t
    • int popAtStack(int index) - \u8fd4\u56de\u7f16\u53f7 index \u7684\u6808\u9876\u90e8\u7684\u503c\uff0c\u5e76\u5c06\u5176\u4ece\u6808\u4e2d\u5220\u9664\uff1b\u5982\u679c\u7f16\u53f7 index \u7684\u6808\u662f\u7a7a\u7684\uff0c\u8bf7\u8fd4\u56de -1\u3002
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1a \n["DinnerPlates","push","push","push","push","push","popAtStack","push","push","popAtStack","popAtStack","pop","pop","pop","pop","pop"]\n[[2],[1],[2],[3],[4],[5],[0],[20],[21],[0],[2],[],[],[],[],[]]\n\u8f93\u51fa\uff1a\n[null,null,null,null,null,null,2,null,null,20,21,5,4,3,1,-1]\n\n\u89e3\u91ca\uff1a\nDinnerPlates D = DinnerPlates(2);  // \u521d\u59cb\u5316\uff0c\u6808\u6700\u5927\u5bb9\u91cf capacity = 2\nD.push(1);\nD.push(2);\nD.push(3);\nD.push(4);\nD.push(5);         // \u6808\u7684\u73b0\u72b6\u4e3a\uff1a    2  4\n                                    1  3  5\n                                    \ufe48 \ufe48 \ufe48\nD.popAtStack(0);   // \u8fd4\u56de 2\u3002\u6808\u7684\u73b0\u72b6\u4e3a\uff1a      4\n                                          1  3  5\n                                          \ufe48 \ufe48 \ufe48\nD.push(20);        // \u6808\u7684\u73b0\u72b6\u4e3a\uff1a  20  4\n                                   1  3  5\n                                   \ufe48 \ufe48 \ufe48\nD.push(21);        // \u6808\u7684\u73b0\u72b6\u4e3a\uff1a  20  4 21\n                                   1  3  5\n                                   \ufe48 \ufe48 \ufe48\nD.popAtStack(0);   // \u8fd4\u56de 20\u3002\u6808\u7684\u73b0\u72b6\u4e3a\uff1a       4 21\n                                            1  3  5\n                                            \ufe48 \ufe48 \ufe48\nD.popAtStack(2);   // \u8fd4\u56de 21\u3002\u6808\u7684\u73b0\u72b6\u4e3a\uff1a       4\n                                            1  3  5\n                                            \ufe48 \ufe48 \ufe48 \nD.pop()            // \u8fd4\u56de 5\u3002\u6808\u7684\u73b0\u72b6\u4e3a\uff1a        4\n                                            1  3 \n                                            \ufe48 \ufe48  \nD.pop()            // \u8fd4\u56de 4\u3002\u6808\u7684\u73b0\u72b6\u4e3a\uff1a    1  3 \n                                           \ufe48 \ufe48   \nD.pop()            // \u8fd4\u56de 3\u3002\u6808\u7684\u73b0\u72b6\u4e3a\uff1a    1 \n                                           \ufe48   \nD.pop()            // \u8fd4\u56de 1\u3002\u73b0\u5728\u6ca1\u6709\u6808\u3002\nD.pop()            // \u8fd4\u56de -1\u3002\u4ecd\u7136\u6ca1\u6709\u6808\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= capacity <= 20000
    • \n\t
    • 1 <= val <= 20000
    • \n\t
    • 0 <= index <= 100000
    • \n\t
    • \u6700\u591a\u4f1a\u5bf9 push\uff0cpop\uff0c\u548c popAtStack \u8fdb\u884c 200000 \u6b21\u8c03\u7528\u3002
    • \n
    \n", "tags_en": ["Design"], "tags_cn": ["\u8bbe\u8ba1"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class DinnerPlates {\npublic:\n DinnerPlates(int capacity) {\n\n }\n \n void push(int val) {\n\n }\n \n int pop() {\n\n }\n \n int popAtStack(int index) {\n\n }\n};\n\n/**\n * Your DinnerPlates object will be instantiated and called as such:\n * DinnerPlates* obj = new DinnerPlates(capacity);\n * obj->push(val);\n * int param_2 = obj->pop();\n * int param_3 = obj->popAtStack(index);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class DinnerPlates {\n\n public DinnerPlates(int capacity) {\n\n }\n \n public void push(int val) {\n\n }\n \n public int pop() {\n\n }\n \n public int popAtStack(int index) {\n\n }\n}\n\n/**\n * Your DinnerPlates object will be instantiated and called as such:\n * DinnerPlates obj = new DinnerPlates(capacity);\n * obj.push(val);\n * int param_2 = obj.pop();\n * int param_3 = obj.popAtStack(index);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class DinnerPlates(object):\n\n def __init__(self, capacity):\n \"\"\"\n :type capacity: int\n \"\"\"\n\n\n def push(self, val):\n \"\"\"\n :type val: int\n :rtype: None\n \"\"\"\n\n\n def pop(self):\n \"\"\"\n :rtype: int\n \"\"\"\n\n\n def popAtStack(self, index):\n \"\"\"\n :type index: int\n :rtype: int\n \"\"\"\n\n\n\n# Your DinnerPlates object will be instantiated and called as such:\n# obj = DinnerPlates(capacity)\n# obj.push(val)\n# param_2 = obj.pop()\n# param_3 = obj.popAtStack(index)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class DinnerPlates:\n\n def __init__(self, capacity: int):\n\n\n def push(self, val: int) -> None:\n\n\n def pop(self) -> int:\n\n\n def popAtStack(self, index: int) -> int:\n\n\n\n# Your DinnerPlates object will be instantiated and called as such:\n# obj = DinnerPlates(capacity)\n# obj.push(val)\n# param_2 = obj.pop()\n# param_3 = obj.popAtStack(index)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} DinnerPlates;\n\n\nDinnerPlates* dinnerPlatesCreate(int capacity) {\n\n}\n\nvoid dinnerPlatesPush(DinnerPlates* obj, int val) {\n\n}\n\nint dinnerPlatesPop(DinnerPlates* obj) {\n\n}\n\nint dinnerPlatesPopAtStack(DinnerPlates* obj, int index) {\n\n}\n\nvoid dinnerPlatesFree(DinnerPlates* obj) {\n\n}\n\n/**\n * Your DinnerPlates struct will be instantiated and called as such:\n * DinnerPlates* obj = dinnerPlatesCreate(capacity);\n * dinnerPlatesPush(obj, val);\n \n * int param_2 = dinnerPlatesPop(obj);\n \n * int param_3 = dinnerPlatesPopAtStack(obj, index);\n \n * dinnerPlatesFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class DinnerPlates {\n\n public DinnerPlates(int capacity) {\n\n }\n \n public void Push(int val) {\n\n }\n \n public int Pop() {\n\n }\n \n public int PopAtStack(int index) {\n\n }\n}\n\n/**\n * Your DinnerPlates object will be instantiated and called as such:\n * DinnerPlates obj = new DinnerPlates(capacity);\n * obj.Push(val);\n * int param_2 = obj.Pop();\n * int param_3 = obj.PopAtStack(index);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} capacity\n */\nvar DinnerPlates = function(capacity) {\n\n};\n\n/** \n * @param {number} val\n * @return {void}\n */\nDinnerPlates.prototype.push = function(val) {\n\n};\n\n/**\n * @return {number}\n */\nDinnerPlates.prototype.pop = function() {\n\n};\n\n/** \n * @param {number} index\n * @return {number}\n */\nDinnerPlates.prototype.popAtStack = function(index) {\n\n};\n\n/**\n * Your DinnerPlates object will be instantiated and called as such:\n * var obj = new DinnerPlates(capacity)\n * obj.push(val)\n * var param_2 = obj.pop()\n * var param_3 = obj.popAtStack(index)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class DinnerPlates\n\n=begin\n :type capacity: Integer\n=end\n def initialize(capacity)\n\n end\n\n\n=begin\n :type val: Integer\n :rtype: Void\n=end\n def push(val)\n\n end\n\n\n=begin\n :rtype: Integer\n=end\n def pop()\n\n end\n\n\n=begin\n :type index: Integer\n :rtype: Integer\n=end\n def pop_at_stack(index)\n\n end\n\n\nend\n\n# Your DinnerPlates object will be instantiated and called as such:\n# obj = DinnerPlates.new(capacity)\n# obj.push(val)\n# param_2 = obj.pop()\n# param_3 = obj.pop_at_stack(index)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass DinnerPlates {\n\n init(_ capacity: Int) {\n\n }\n \n func push(_ val: Int) {\n\n }\n \n func pop() -> Int {\n\n }\n \n func popAtStack(_ index: Int) -> Int {\n\n }\n}\n\n/**\n * Your DinnerPlates object will be instantiated and called as such:\n * let obj = DinnerPlates(capacity)\n * obj.push(val)\n * let ret_2: Int = obj.pop()\n * let ret_3: Int = obj.popAtStack(index)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type DinnerPlates struct {\n\n}\n\n\nfunc Constructor(capacity int) DinnerPlates {\n\n}\n\n\nfunc (this *DinnerPlates) Push(val int) {\n\n}\n\n\nfunc (this *DinnerPlates) Pop() int {\n\n}\n\n\nfunc (this *DinnerPlates) PopAtStack(index int) int {\n\n}\n\n\n/**\n * Your DinnerPlates object will be instantiated and called as such:\n * obj := Constructor(capacity);\n * obj.Push(val);\n * param_2 := obj.Pop();\n * param_3 := obj.PopAtStack(index);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class DinnerPlates(_capacity: Int) {\n\n def push(`val`: Int) {\n\n }\n\n def pop(): Int = {\n\n }\n\n def popAtStack(index: Int): Int = {\n\n }\n\n}\n\n/**\n * Your DinnerPlates object will be instantiated and called as such:\n * var obj = new DinnerPlates(capacity)\n * obj.push(`val`)\n * var param_2 = obj.pop()\n * var param_3 = obj.popAtStack(index)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class DinnerPlates(capacity: Int) {\n\n fun push(`val`: Int) {\n\n }\n\n fun pop(): Int {\n\n }\n\n fun popAtStack(index: Int): Int {\n\n }\n\n}\n\n/**\n * Your DinnerPlates object will be instantiated and called as such:\n * var obj = DinnerPlates(capacity)\n * obj.push(`val`)\n * var param_2 = obj.pop()\n * var param_3 = obj.popAtStack(index)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct DinnerPlates {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl DinnerPlates {\n\n fn new(capacity: i32) -> Self {\n\n }\n \n fn push(&self, val: i32) {\n\n }\n \n fn pop(&self) -> i32 {\n\n }\n \n fn pop_at_stack(&self, index: i32) -> i32 {\n\n }\n}\n\n/**\n * Your DinnerPlates object will be instantiated and called as such:\n * let obj = DinnerPlates::new(capacity);\n * obj.push(val);\n * let ret_2: i32 = obj.pop();\n * let ret_3: i32 = obj.pop_at_stack(index);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class DinnerPlates {\n /**\n * @param Integer $capacity\n */\n function __construct($capacity) {\n\n }\n\n /**\n * @param Integer $val\n * @return NULL\n */\n function push($val) {\n\n }\n\n /**\n * @return Integer\n */\n function pop() {\n\n }\n\n /**\n * @param Integer $index\n * @return Integer\n */\n function popAtStack($index) {\n\n }\n}\n\n/**\n * Your DinnerPlates object will be instantiated and called as such:\n * $obj = DinnerPlates($capacity);\n * $obj->push($val);\n * $ret_2 = $obj->pop();\n * $ret_3 = $obj->popAtStack($index);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class DinnerPlates {\n constructor(capacity: number) {\n\n }\n\n push(val: number): void {\n\n }\n\n pop(): number {\n\n }\n\n popAtStack(index: number): number {\n\n }\n}\n\n/**\n * Your DinnerPlates object will be instantiated and called as such:\n * var obj = new DinnerPlates(capacity)\n * obj.push(val)\n * var param_2 = obj.pop()\n * var param_3 = obj.popAtStack(index)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define dinner-plates%\n (class object%\n (super-new)\n\n ; capacity : exact-integer?\n (init-field\n capacity)\n \n ; push : exact-integer? -> void?\n (define/public (push val)\n\n )\n ; pop : -> exact-integer?\n (define/public (pop)\n\n )\n ; pop-at-stack : exact-integer? -> exact-integer?\n (define/public (pop-at-stack index)\n\n )))\n\n;; Your dinner-plates% object will be instantiated and called as such:\n;; (define obj (new dinner-plates% [capacity capacity]))\n;; (send obj push val)\n;; (define param_2 (send obj pop))\n;; (define param_3 (send obj pop-at-stack index))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1172](https://leetcode-cn.com/problems/dinner-plate-stacks)", "[\u9910\u76d8\u6808](/solution/1100-1199/1172.Dinner%20Plate%20Stacks/README.md)", "`\u8bbe\u8ba1`", "\u56f0\u96be", ""], "md_table_row_en": ["[1172](https://leetcode.com/problems/dinner-plate-stacks)", "[Dinner Plate Stacks](/solution/1100-1199/1172.Dinner%20Plate%20Stacks/README_EN.md)", "`Design`", "Hard", ""]}, {"question_id": "1269", "frontend_question_id": "1159", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/market-analysis-ii", "url_en": "https://leetcode.com/problems/market-analysis-ii", "relative_path_cn": "/solution/1100-1199/1159.Market%20Analysis%20II/README.md", "relative_path_en": "/solution/1100-1199/1159.Market%20Analysis%20II/README_EN.md", "title_cn": "\u5e02\u573a\u5206\u6790 II", "title_en": "Market Analysis II", "question_title_slug": "market-analysis-ii", "content_en": "

    Table: Users

    \n\n
    \n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| user_id        | int     |\n| join_date      | date    |\n| favorite_brand | varchar |\n+----------------+---------+\nuser_id is the primary key of this table.\nThis table has the info of the users of an online shopping website where users can sell and buy items.
    \n\n

    Table: Orders

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| order_id      | int     |\n| order_date    | date    |\n| item_id       | int     |\n| buyer_id      | int     |\n| seller_id     | int     |\n+---------------+---------+\norder_id is the primary key of this table.\nitem_id is a foreign key to the Items table.\nbuyer_id and seller_id are foreign keys to the Users table.\n
    \n\n

    Table: Items

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| item_id       | int     |\n| item_brand    | varchar |\n+---------------+---------+\nitem_id is the primary key of this table.\n
    \n\n

     

    \n\n

    Write an SQL query to find for each user, whether the brand of the second item (by date) they sold is their favorite brand. If a user sold less than two items, report the answer for that user as no.

    \n\n

    It is guaranteed that no seller sold more than one item on a day.

    \n\n

    The query result format is in the following example:

    \n\n
    \nUsers table:\n+---------+------------+----------------+\n| user_id | join_date  | favorite_brand |\n+---------+------------+----------------+\n| 1       | 2019-01-01 | Lenovo         |\n| 2       | 2019-02-09 | Samsung        |\n| 3       | 2019-01-19 | LG             |\n| 4       | 2019-05-21 | HP             |\n+---------+------------+----------------+\n\nOrders table:\n+----------+------------+---------+----------+-----------+\n| order_id | order_date | item_id | buyer_id | seller_id |\n+----------+------------+---------+----------+-----------+\n| 1        | 2019-08-01 | 4       | 1        | 2         |\n| 2        | 2019-08-02 | 2       | 1        | 3         |\n| 3        | 2019-08-03 | 3       | 2        | 3         |\n| 4        | 2019-08-04 | 1       | 4        | 2         |\n| 5        | 2019-08-04 | 1       | 3        | 4         |\n| 6        | 2019-08-05 | 2       | 2        | 4         |\n+----------+------------+---------+----------+-----------+\n\nItems table:\n+---------+------------+\n| item_id | item_brand |\n+---------+------------+\n| 1       | Samsung    |\n| 2       | Lenovo     |\n| 3       | LG         |\n| 4       | HP         |\n+---------+------------+\n\nResult table:\n+-----------+--------------------+\n| seller_id | 2nd_item_fav_brand |\n+-----------+--------------------+\n| 1         | no                 |\n| 2         | yes                |\n| 3         | yes                |\n| 4         | no                 |\n+-----------+--------------------+\n\nThe answer for the user with id 1 is no because they sold nothing.\nThe answer for the users with id 2 and 3 is yes because the brands of their second sold items are their favorite brands.\nThe answer for the user with id 4 is no because the brand of their second sold item is not their favorite brand.
    \n", "content_cn": "

    \u8868: Users

    \n\n
    \n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| user_id        | int     |\n| join_date      | date    |\n| favorite_brand | varchar |\n+----------------+---------+\nuser_id \u662f\u8be5\u8868\u7684\u4e3b\u952e\n\u8868\u4e2d\u5305\u542b\u4e00\u4f4d\u5728\u7ebf\u8d2d\u7269\u7f51\u7ad9\u7528\u6237\u7684\u4e2a\u4eba\u4fe1\u606f\uff0c\u7528\u6237\u53ef\u4ee5\u5728\u8be5\u7f51\u7ad9\u51fa\u552e\u548c\u8d2d\u4e70\u5546\u54c1\u3002\n
    \n\n

    \u8868: Orders

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| order_id      | int     |\n| order_date    | date    |\n| item_id       | int     |\n| buyer_id      | int     |\n| seller_id     | int     |\n+---------------+---------+\norder_id \u662f\u8be5\u8868\u7684\u4e3b\u952e\nitem_id \u662f Items \u8868\u7684\u5916\u952e\nbuyer_id \u548c seller_id \u662f Users \u8868\u7684\u5916\u952e\n
    \n\n

    \u8868: Items

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| item_id       | int     |\n| item_brand    | varchar |\n+---------------+---------+\nitem_id \u662f\u8be5\u8868\u7684\u4e3b\u952e\n
    \n\n

     

    \n\n

    \u5199\u4e00\u4e2a SQL \u67e5\u8be2\u786e\u5b9a\u6bcf\u4e00\u4e2a\u7528\u6237\u6309\u65e5\u671f\u987a\u5e8f\u5356\u51fa\u7684\u7b2c\u4e8c\u4ef6\u5546\u54c1\u7684\u54c1\u724c\u662f\u5426\u662f\u4ed6\u4eec\u6700\u559c\u7231\u7684\u54c1\u724c\u3002\u5982\u679c\u4e00\u4e2a\u7528\u6237\u5356\u51fa\u5c11\u4e8e\u4e24\u4ef6\u5546\u54c1\uff0c\u67e5\u8be2\u7684\u7ed3\u679c\u662f no \u3002

    \n\n

    \u9898\u76ee\u4fdd\u8bc1\u6ca1\u6709\u4e00\u4e2a\u7528\u6237\u5728\u4e00\u5929\u4e2d\u5356\u51fa\u8d85\u8fc7\u4e00\u4ef6\u5546\u54c1

    \n\n

    \u4e0b\u9762\u662f\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u7684\u4f8b\u5b50\uff1a

    \n\n
    \nUsers table:\n+---------+------------+----------------+\n| user_id | join_date  | favorite_brand |\n+---------+------------+----------------+\n| 1       | 2019-01-01 | Lenovo         |\n| 2       | 2019-02-09 | Samsung        |\n| 3       | 2019-01-19 | LG             |\n| 4       | 2019-05-21 | HP             |\n+---------+------------+----------------+\n\nOrders table:\n+----------+------------+---------+----------+-----------+\n| order_id | order_date | item_id | buyer_id | seller_id |\n+----------+------------+---------+----------+-----------+\n| 1        | 2019-08-01 | 4       | 1        | 2         |\n| 2        | 2019-08-02 | 2       | 1        | 3         |\n| 3        | 2019-08-03 | 3       | 2        | 3         |\n| 4        | 2019-08-04 | 1       | 4        | 2         |\n| 5        | 2019-08-04 | 1       | 3        | 4         |\n| 6        | 2019-08-05 | 2       | 2        | 4         |\n+----------+------------+---------+----------+-----------+\n\nItems table:\n+---------+------------+\n| item_id | item_brand |\n+---------+------------+\n| 1       | Samsung    |\n| 2       | Lenovo     |\n| 3       | LG         |\n| 4       | HP         |\n+---------+------------+\n\nResult table:\n+-----------+--------------------+\n| seller_id | 2nd_item_fav_brand |\n+-----------+--------------------+\n| 1         | no                 |\n| 2         | yes                |\n| 3         | yes                |\n| 4         | no                 |\n+-----------+--------------------+\n\nid \u4e3a 1 \u7684\u7528\u6237\u7684\u67e5\u8be2\u7ed3\u679c\u662f no\uff0c\u56e0\u4e3a\u4ed6\u4ec0\u4e48\u4e5f\u6ca1\u6709\u5356\u51fa\nid\u4e3a 2 \u548c 3 \u7684\u7528\u6237\u7684\u67e5\u8be2\u7ed3\u679c\u662f yes\uff0c\u56e0\u4e3a\u4ed6\u4eec\u5356\u51fa\u7684\u7b2c\u4e8c\u4ef6\u5546\u54c1\u7684\u54c1\u724c\u662f\u4ed6\u4eec\u81ea\u5df1\u6700\u559c\u7231\u7684\u54c1\u724c\nid\u4e3a 4 \u7684\u7528\u6237\u7684\u67e5\u8be2\u7ed3\u679c\u662f no\uff0c\u56e0\u4e3a\u4ed6\u5356\u51fa\u7684\u7b2c\u4e8c\u4ef6\u5546\u54c1\u7684\u54c1\u724c\u4e0d\u662f\u4ed6\u6700\u559c\u7231\u7684\u54c1\u724c\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1159](https://leetcode-cn.com/problems/market-analysis-ii)", "[\u5e02\u573a\u5206\u6790 II](/solution/1100-1199/1159.Market%20Analysis%20II/README.md)", "", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1159](https://leetcode.com/problems/market-analysis-ii)", "[Market Analysis II](/solution/1100-1199/1159.Market%20Analysis%20II/README_EN.md)", "", "Hard", "\ud83d\udd12"]}, {"question_id": "1268", "frontend_question_id": "1158", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/market-analysis-i", "url_en": "https://leetcode.com/problems/market-analysis-i", "relative_path_cn": "/solution/1100-1199/1158.Market%20Analysis%20I/README.md", "relative_path_en": "/solution/1100-1199/1158.Market%20Analysis%20I/README_EN.md", "title_cn": "\u5e02\u573a\u5206\u6790 I", "title_en": "Market Analysis I", "question_title_slug": "market-analysis-i", "content_en": "

    Table: Users

    \n\n
    \n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| user_id        | int     |\n| join_date      | date    |\n| favorite_brand | varchar |\n+----------------+---------+\nuser_id is the primary key of this table.\nThis table has the info of the users of an online shopping website where users can sell and buy items.
    \n\n

    Table: Orders

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| order_id      | int     |\n| order_date    | date    |\n| item_id       | int     |\n| buyer_id      | int     |\n| seller_id     | int     |\n+---------------+---------+\norder_id is the primary key of this table.\nitem_id is a foreign key to the Items table.\nbuyer_id and seller_id are foreign keys to the Users table.\n
    \n\n

    Table: Items

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| item_id       | int     |\n| item_brand    | varchar |\n+---------------+---------+\nitem_id is the primary key of this table.\n
    \n\n

     

    \n\n

    Write an SQL query to find for each user, the join date and the number of orders they made as a buyer in 2019.

    \n\n

    The query result format is in the following example:

    \n\n
    \nUsers table:\n+---------+------------+----------------+\n| user_id | join_date  | favorite_brand |\n+---------+------------+----------------+\n| 1       | 2018-01-01 | Lenovo         |\n| 2       | 2018-02-09 | Samsung        |\n| 3       | 2018-01-19 | LG             |\n| 4       | 2018-05-21 | HP             |\n+---------+------------+----------------+\n\nOrders table:\n+----------+------------+---------+----------+-----------+\n| order_id | order_date | item_id | buyer_id | seller_id |\n+----------+------------+---------+----------+-----------+\n| 1        | 2019-08-01 | 4       | 1        | 2         |\n| 2        | 2018-08-02 | 2       | 1        | 3         |\n| 3        | 2019-08-03 | 3       | 2        | 3         |\n| 4        | 2018-08-04 | 1       | 4        | 2         |\n| 5        | 2018-08-04 | 1       | 3        | 4         |\n| 6        | 2019-08-05 | 2       | 2        | 4         |\n+----------+------------+---------+----------+-----------+\n\nItems table:\n+---------+------------+\n| item_id | item_brand |\n+---------+------------+\n| 1       | Samsung    |\n| 2       | Lenovo     |\n| 3       | LG         |\n| 4       | HP         |\n+---------+------------+\n\nResult table:\n+-----------+------------+----------------+\n| buyer_id  | join_date  | orders_in_2019 |\n+-----------+------------+----------------+\n| 1         | 2018-01-01 | 1              |\n| 2         | 2018-02-09 | 2              |\n| 3         | 2018-01-19 | 0              |\n| 4         | 2018-05-21 | 0              |\n+-----------+------------+----------------+\n
    \n", "content_cn": "

    Table: Users

    \n\n
    \n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| user_id        | int     |\n| join_date      | date    |\n| favorite_brand | varchar |\n+----------------+---------+\n\u6b64\u8868\u4e3b\u952e\u662f user_id\uff0c\u8868\u4e2d\u63cf\u8ff0\u4e86\u8d2d\u7269\u7f51\u7ad9\u7684\u7528\u6237\u4fe1\u606f\uff0c\u7528\u6237\u53ef\u4ee5\u5728\u6b64\u7f51\u7ad9\u4e0a\u8fdb\u884c\u5546\u54c1\u4e70\u5356\u3002\n
    \n\n

    Table: Orders

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| order_id      | int     |\n| order_date    | date    |\n| item_id       | int     |\n| buyer_id      | int     |\n| seller_id     | int     |\n+---------------+---------+\n\u6b64\u8868\u4e3b\u952e\u662f order_id\uff0c\u5916\u952e\u662f item_id \u548c\uff08buyer_id\uff0cseller_id\uff09\u3002\n
    \n\n

    Table: Item

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| item_id       | int     |\n| item_brand    | varchar |\n+---------------+---------+\n\u6b64\u8868\u4e3b\u952e\u662f item_id\u3002\n
    \n\n

     

    \n\n

    \u8bf7\u5199\u51fa\u4e00\u6761SQL\u8bed\u53e5\u4ee5\u67e5\u8be2\u6bcf\u4e2a\u7528\u6237\u7684\u6ce8\u518c\u65e5\u671f\u548c\u5728 2019 \u5e74\u4f5c\u4e3a\u4e70\u5bb6\u7684\u8ba2\u5355\u603b\u6570\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\uff1a

    \n\n
    \nUsers table:\n+---------+------------+----------------+\n| user_id | join_date  | favorite_brand |\n+---------+------------+----------------+\n| 1       | 2018-01-01 | Lenovo         |\n| 2       | 2018-02-09 | Samsung        |\n| 3       | 2018-01-19 | LG             |\n| 4       | 2018-05-21 | HP             |\n+---------+------------+----------------+\n\nOrders table:\n+----------+------------+---------+----------+-----------+\n| order_id | order_date | item_id | buyer_id | seller_id |\n+----------+------------+---------+----------+-----------+\n| 1        | 2019-08-01 | 4       | 1        | 2         |\n| 2        | 2018-08-02 | 2       | 1        | 3         |\n| 3        | 2019-08-03 | 3       | 2        | 3         |\n| 4        | 2018-08-04 | 1       | 4        | 2         |\n| 5        | 2018-08-04 | 1       | 3        | 4         |\n| 6        | 2019-08-05 | 2       | 2        | 4         |\n+----------+------------+---------+----------+-----------+\n\nItems table:\n+---------+------------+\n| item_id | item_brand |\n+---------+------------+\n| 1       | Samsung    |\n| 2       | Lenovo     |\n| 3       | LG         |\n| 4       | HP         |\n+---------+------------+\n\nResult table:\n+-----------+------------+----------------+\n| buyer_id  | join_date  | orders_in_2019 |\n+-----------+------------+----------------+\n| 1         | 2018-01-01 | 1              |\n| 2         | 2018-02-09 | 2              |\n| 3         | 2018-01-19 | 0              |\n| 4         | 2018-05-21 | 0              |\n+-----------+------------+----------------+\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1158](https://leetcode-cn.com/problems/market-analysis-i)", "[\u5e02\u573a\u5206\u6790 I](/solution/1100-1199/1158.Market%20Analysis%20I/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1158](https://leetcode.com/problems/market-analysis-i)", "[Market Analysis I](/solution/1100-1199/1158.Market%20Analysis%20I/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1267", "frontend_question_id": "1171", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/remove-zero-sum-consecutive-nodes-from-linked-list", "url_en": "https://leetcode.com/problems/remove-zero-sum-consecutive-nodes-from-linked-list", "relative_path_cn": "/solution/1100-1199/1171.Remove%20Zero%20Sum%20Consecutive%20Nodes%20from%20Linked%20List/README.md", "relative_path_en": "/solution/1100-1199/1171.Remove%20Zero%20Sum%20Consecutive%20Nodes%20from%20Linked%20List/README_EN.md", "title_cn": "\u4ece\u94fe\u8868\u4e2d\u5220\u53bb\u603b\u548c\u503c\u4e3a\u96f6\u7684\u8fde\u7eed\u8282\u70b9", "title_en": "Remove Zero Sum Consecutive Nodes from Linked List", "question_title_slug": "remove-zero-sum-consecutive-nodes-from-linked-list", "content_en": "

    Given the head of a linked list, we repeatedly delete consecutive sequences of nodes that sum to 0 until there are no such sequences.

    \r\n\r\n

    After doing so, return the head of the final linked list.  You may return any such answer.

    \r\n\n

     

    \n

    (Note that in the examples below, all sequences are serializations of ListNode objects.)

    \n\n

    Example 1:

    \n\n
    \nInput: head = [1,2,-3,3,1]\nOutput: [3,1]\nNote: The answer [1,2,1] would also be accepted.\n
    \n\n

    Example 2:

    \n\n
    \nInput: head = [1,2,3,-3,4]\nOutput: [1,2,4]\n
    \n\n

    Example 3:

    \n\n
    \nInput: head = [1,2,3,-3,-2]\nOutput: [1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The given linked list will contain between 1 and 1000 nodes.
    • \n\t
    • Each node in the linked list has -1000 <= node.val <= 1000.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u94fe\u8868\u7684\u5934\u8282\u70b9 head\uff0c\u8bf7\u4f60\u7f16\u5199\u4ee3\u7801\uff0c\u53cd\u590d\u5220\u53bb\u94fe\u8868\u4e2d\u7531 \u603b\u548c \u503c\u4e3a 0 \u7684\u8fde\u7eed\u8282\u70b9\u7ec4\u6210\u7684\u5e8f\u5217\uff0c\u76f4\u5230\u4e0d\u5b58\u5728\u8fd9\u6837\u7684\u5e8f\u5217\u4e3a\u6b62\u3002

    \n\n

    \u5220\u9664\u5b8c\u6bd5\u540e\uff0c\u8bf7\u4f60\u8fd4\u56de\u6700\u7ec8\u7ed3\u679c\u94fe\u8868\u7684\u5934\u8282\u70b9\u3002

    \n\n

     

    \n\n

    \u4f60\u53ef\u4ee5\u8fd4\u56de\u4efb\u4f55\u6ee1\u8db3\u9898\u76ee\u8981\u6c42\u7684\u7b54\u6848\u3002

    \n\n

    \uff08\u6ce8\u610f\uff0c\u4e0b\u9762\u793a\u4f8b\u4e2d\u7684\u6240\u6709\u5e8f\u5217\uff0c\u90fd\u662f\u5bf9 ListNode \u5bf9\u8c61\u5e8f\u5217\u5316\u7684\u8868\u793a\u3002\uff09

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1ahead = [1,2,-3,3,1]\n\u8f93\u51fa\uff1a[3,1]\n\u63d0\u793a\uff1a\u7b54\u6848 [1,2,1] \u4e5f\u662f\u6b63\u786e\u7684\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1ahead = [1,2,3,-3,4]\n\u8f93\u51fa\uff1a[1,2,4]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1ahead = [1,2,3,-3,-2]\n\u8f93\u51fa\uff1a[1]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u7ed9\u4f60\u7684\u94fe\u8868\u4e2d\u53ef\u80fd\u6709 1 \u5230 1000 \u4e2a\u8282\u70b9\u3002
    • \n\t
    • \u5bf9\u4e8e\u94fe\u8868\u4e2d\u7684\u6bcf\u4e2a\u8282\u70b9\uff0c\u8282\u70b9\u7684\u503c\uff1a-1000 <= node.val <= 1000.
    • \n
    \n", "tags_en": ["Linked List"], "tags_cn": ["\u94fe\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\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 ListNode* removeZeroSumSublists(ListNode* head) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode(int x) { val = x; }\n * }\n */\nclass Solution {\n public ListNode removeZeroSumSublists(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.next = None\n\nclass Solution(object):\n def removeZeroSumSublists(self, head):\n \"\"\"\n :type head: ListNode\n :rtype: ListNode\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, x):\n# self.val = x\n# self.next = None\n\nclass Solution:\n def removeZeroSumSublists(self, head: ListNode) -> ListNode:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nstruct ListNode* removeZeroSumSublists(struct ListNode* head){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int x) { val = x; }\n * }\n */\npublic class Solution {\n public ListNode RemoveZeroSumSublists(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val) {\n * this.val = val;\n * this.next = null;\n * }\n */\n/**\n * @param {ListNode} head\n * @return {ListNode}\n */\nvar removeZeroSumSublists = function(head) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val)\n# @val = val\n# @next = nil\n# end\n# end\n\n# @param {ListNode} head\n# @return {ListNode}\ndef remove_zero_sum_sublists(head)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.next = nil\n * }\n * }\n */\nclass Solution {\n func removeZeroSumSublists(_ head: ListNode?) -> ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc removeZeroSumSublists(head *ListNode) *ListNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(var _x: Int = 0) {\n * var next: ListNode = null\n * var x: Int = _x\n * }\n */\nobject Solution {\n def removeZeroSumSublists(head: ListNode): ListNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun removeZeroSumSublists(head: ListNode?): ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n// \n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn remove_zero_sum_sublists(head: Option>) -> Option> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val) { $this->val = $val; }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @return ListNode\n */\n function removeZeroSumSublists($head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction removeZeroSumSublists(head: ListNode | null): ListNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (remove-zero-sum-sublists head)\n (-> (or/c list-node? #f) (or/c list-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1171](https://leetcode-cn.com/problems/remove-zero-sum-consecutive-nodes-from-linked-list)", "[\u4ece\u94fe\u8868\u4e2d\u5220\u53bb\u603b\u548c\u503c\u4e3a\u96f6\u7684\u8fde\u7eed\u8282\u70b9](/solution/1100-1199/1171.Remove%20Zero%20Sum%20Consecutive%20Nodes%20from%20Linked%20List/README.md)", "`\u94fe\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1171](https://leetcode.com/problems/remove-zero-sum-consecutive-nodes-from-linked-list)", "[Remove Zero Sum Consecutive Nodes from Linked List](/solution/1100-1199/1171.Remove%20Zero%20Sum%20Consecutive%20Nodes%20from%20Linked%20List/README_EN.md)", "`Linked List`", "Medium", ""]}, {"question_id": "1263", "frontend_question_id": "1155", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-dice-rolls-with-target-sum", "url_en": "https://leetcode.com/problems/number-of-dice-rolls-with-target-sum", "relative_path_cn": "/solution/1100-1199/1155.Number%20of%20Dice%20Rolls%20With%20Target%20Sum/README.md", "relative_path_en": "/solution/1100-1199/1155.Number%20of%20Dice%20Rolls%20With%20Target%20Sum/README_EN.md", "title_cn": "\u63b7\u9ab0\u5b50\u7684N\u79cd\u65b9\u6cd5", "title_en": "Number of Dice Rolls With Target Sum", "question_title_slug": "number-of-dice-rolls-with-target-sum", "content_en": "

    You have d dice and each die has f faces numbered 1, 2, ..., f.

    \n\n

    Return the number of possible ways (out of fd total ways) modulo 109 + 7 to roll the dice so the sum of the face-up numbers equals target.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: d = 1, f = 6, target = 3\nOutput: 1\nExplanation: \nYou throw one die with 6 faces.  There is only one way to get a sum of 3.\n
    \n\n

    Example 2:

    \n\n
    \nInput: d = 2, f = 6, target = 7\nOutput: 6\nExplanation: \nYou throw two dice, each with 6 faces.  There are 6 ways to get a sum of 7:\n1+6, 2+5, 3+4, 4+3, 5+2, 6+1.\n
    \n\n

    Example 3:

    \n\n
    \nInput: d = 2, f = 5, target = 10\nOutput: 1\nExplanation: \nYou throw two dice, each with 5 faces.  There is only one way to get a sum of 10: 5+5.\n
    \n\n

    Example 4:

    \n\n
    \nInput: d = 1, f = 2, target = 3\nOutput: 0\nExplanation: \nYou throw one die with 2 faces.  There is no way to get a sum of 3.\n
    \n\n

    Example 5:

    \n\n
    \nInput: d = 30, f = 30, target = 500\nOutput: 222616187\nExplanation: \nThe answer must be returned modulo 10^9 + 7.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= d, f <= 30
    • \n\t
    • 1 <= target <= 1000
    • \n
    \n", "content_cn": "

    \u8fd9\u91cc\u6709 d \u4e2a\u4e00\u6837\u7684\u9ab0\u5b50\uff0c\u6bcf\u4e2a\u9ab0\u5b50\u4e0a\u90fd\u6709 f \u4e2a\u9762\uff0c\u5206\u522b\u6807\u53f7\u4e3a 1, 2, ..., f\u3002

    \n\n

    \u6211\u4eec\u7ea6\u5b9a\uff1a\u63b7\u9ab0\u5b50\u7684\u5f97\u5230\u603b\u70b9\u6570\u4e3a\u5404\u9ab0\u5b50\u9762\u671d\u4e0a\u7684\u6570\u5b57\u7684\u603b\u548c\u3002

    \n\n

    \u5982\u679c\u9700\u8981\u63b7\u51fa\u7684\u603b\u70b9\u6570\u4e3a target\uff0c\u8bf7\u4f60\u8ba1\u7b97\u51fa\u6709\u591a\u5c11\u79cd\u4e0d\u540c\u7684\u7ec4\u5408\u60c5\u51b5\uff08\u6240\u6709\u7684\u7ec4\u5408\u60c5\u51b5\u603b\u5171\u6709 f^d \u79cd\uff09\uff0c\u6a21 10^9 + 7 \u540e\u8fd4\u56de\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1ad = 1, f = 6, target = 3\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1ad = 2, f = 6, target = 7\n\u8f93\u51fa\uff1a6\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1ad = 2, f = 5, target = 10\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1ad = 1, f = 2, target = 3\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1ad = 30, f = 30, target = 500\n\u8f93\u51fa\uff1a222616187
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= d, f <= 30
    • \n\t
    • 1 <= target <= 1000
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numRollsToTarget(int d, int f, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numRollsToTarget(int d, int f, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numRollsToTarget(self, d, f, target):\n \"\"\"\n :type d: int\n :type f: int\n :type target: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numRollsToTarget(self, d: int, f: int, target: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numRollsToTarget(int d, int f, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumRollsToTarget(int d, int f, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} d\n * @param {number} f\n * @param {number} target\n * @return {number}\n */\nvar numRollsToTarget = function(d, f, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} d\n# @param {Integer} f\n# @param {Integer} target\n# @return {Integer}\ndef num_rolls_to_target(d, f, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numRollsToTarget(_ d: Int, _ f: Int, _ target: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numRollsToTarget(d int, f int, target int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numRollsToTarget(d: Int, f: Int, target: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numRollsToTarget(d: Int, f: Int, target: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_rolls_to_target(d: i32, f: i32, target: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $d\n * @param Integer $f\n * @param Integer $target\n * @return Integer\n */\n function numRollsToTarget($d, $f, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numRollsToTarget(d: number, f: number, target: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-rolls-to-target d f target)\n (-> exact-integer? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1155](https://leetcode-cn.com/problems/number-of-dice-rolls-with-target-sum)", "[\u63b7\u9ab0\u5b50\u7684N\u79cd\u65b9\u6cd5](/solution/1100-1199/1155.Number%20of%20Dice%20Rolls%20With%20Target%20Sum/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1155](https://leetcode.com/problems/number-of-dice-rolls-with-target-sum)", "[Number of Dice Rolls With Target Sum](/solution/1100-1199/1155.Number%20of%20Dice%20Rolls%20With%20Target%20Sum/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "1262", "frontend_question_id": "1157", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/online-majority-element-in-subarray", "url_en": "https://leetcode.com/problems/online-majority-element-in-subarray", "relative_path_cn": "/solution/1100-1199/1157.Online%20Majority%20Element%20In%20Subarray/README.md", "relative_path_en": "/solution/1100-1199/1157.Online%20Majority%20Element%20In%20Subarray/README_EN.md", "title_cn": "\u5b50\u6570\u7ec4\u4e2d\u5360\u7edd\u5927\u591a\u6570\u7684\u5143\u7d20", "title_en": "Online Majority Element In Subarray", "question_title_slug": "online-majority-element-in-subarray", "content_en": "

    Implementing the class MajorityChecker, which has the following API:

    \n\n
      \n\t
    • MajorityChecker(int[] arr) constructs an instance of MajorityChecker with the given array arr;
    • \n\t
    • int query(int left, int right, int threshold) has arguments such that:\n\t
        \n\t\t
      • 0 <= left <= right < arr.length representing a subarray of arr;
      • \n\t\t
      • 2 * threshold > right - left + 1, ie. the threshold is always a strict majority of the length of the subarray
      • \n\t
      \n\t
    • \n
    \n\n

    Each query(...) returns the element in arr[left], arr[left+1], ..., arr[right] that occurs at least threshold times, or -1 if no such element exists.

    \n\n

     

    \n\n

    Example:

    \n\n
    \nMajorityChecker majorityChecker = new MajorityChecker([1,1,2,2,1,1]);\nmajorityChecker.query(0,5,4); // returns 1\nmajorityChecker.query(0,3,3); // returns -1\nmajorityChecker.query(2,3,2); // returns 2\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= arr.length <= 20000
    • \n\t
    • 1 <= arr[i] <= 20000
    • \n\t
    • For each query, 0 <= left <= right < len(arr)
    • \n\t
    • For each query, 2 * threshold > right - left + 1
    • \n\t
    • The number of queries is at most 10000
    • \n
    \n", "content_cn": "

    \u5b9e\u73b0\u4e00\u4e2a MajorityChecker \u7684\u7c7b\uff0c\u5b83\u5e94\u8be5\u5177\u6709\u4e0b\u8ff0\u51e0\u4e2a API\uff1a

    \n\n
      \n\t
    • MajorityChecker(int[] arr) \u4f1a\u7528\u7ed9\u5b9a\u7684\u6570\u7ec4 arr \u6765\u6784\u9020\u4e00\u4e2a MajorityChecker \u7684\u5b9e\u4f8b\u3002
    • \n\t
    • int query(int left, int right, int threshold) \u6709\u8fd9\u4e48\u51e0\u4e2a\u53c2\u6570\uff1a\n\t
        \n\t\t
      • 0 <= left <= right < arr.length \u8868\u793a\u6570\u7ec4 arr \u7684\u5b50\u6570\u7ec4\u7684\u957f\u5ea6\u3002
      • \n\t\t
      • 2 * threshold > right - left + 1\uff0c\u4e5f\u5c31\u662f\u8bf4\u9608\u503c threshold \u59cb\u7ec8\u6bd4\u5b50\u5e8f\u5217\u957f\u5ea6\u7684\u4e00\u534a\u8fd8\u8981\u5927\u3002
      • \n\t
      \n\t
    • \n
    \n\n

    \u6bcf\u6b21\u67e5\u8be2 query(...) \u4f1a\u8fd4\u56de\u5728 arr[left], arr[left+1], ..., arr[right] \u4e2d\u81f3\u5c11\u51fa\u73b0\u9608\u503c\u6b21\u6570 threshold \u7684\u5143\u7d20\uff0c\u5982\u679c\u4e0d\u5b58\u5728\u8fd9\u6837\u7684\u5143\u7d20\uff0c\u5c31\u8fd4\u56de -1\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    MajorityChecker majorityChecker = new MajorityChecker([1,1,2,2,1,1]);\nmajorityChecker.query(0,5,4); // \u8fd4\u56de 1\nmajorityChecker.query(0,3,3); // \u8fd4\u56de -1\nmajorityChecker.query(2,3,2); // \u8fd4\u56de 2\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= arr.length <= 20000
    • \n\t
    • 1 <= arr[i] <= 20000
    • \n\t
    • \u5bf9\u4e8e\u6bcf\u6b21\u67e5\u8be2\uff0c0 <= left <= right < len(arr)
    • \n\t
    • \u5bf9\u4e8e\u6bcf\u6b21\u67e5\u8be2\uff0c2 * threshold > right - left + 1
    • \n\t
    • \u67e5\u8be2\u6b21\u6570\u6700\u591a\u4e3a 10000
    • \n
    \n", "tags_en": ["Segment Tree", "Array", "Binary Search"], "tags_cn": ["\u7ebf\u6bb5\u6811", "\u6570\u7ec4", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class MajorityChecker {\npublic:\n MajorityChecker(vector& arr) {\n\n }\n \n int query(int left, int right, int threshold) {\n\n }\n};\n\n/**\n * Your MajorityChecker object will be instantiated and called as such:\n * MajorityChecker* obj = new MajorityChecker(arr);\n * int param_1 = obj->query(left,right,threshold);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class MajorityChecker {\n\n public MajorityChecker(int[] arr) {\n\n }\n \n public int query(int left, int right, int threshold) {\n\n }\n}\n\n/**\n * Your MajorityChecker object will be instantiated and called as such:\n * MajorityChecker obj = new MajorityChecker(arr);\n * int param_1 = obj.query(left,right,threshold);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class MajorityChecker(object):\n\n def __init__(self, arr):\n \"\"\"\n :type arr: List[int]\n \"\"\"\n\n\n def query(self, left, right, threshold):\n \"\"\"\n :type left: int\n :type right: int\n :type threshold: int\n :rtype: int\n \"\"\"\n\n\n\n# Your MajorityChecker object will be instantiated and called as such:\n# obj = MajorityChecker(arr)\n# param_1 = obj.query(left,right,threshold)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class MajorityChecker:\n\n def __init__(self, arr: List[int]):\n\n\n def query(self, left: int, right: int, threshold: int) -> int:\n\n\n\n# Your MajorityChecker object will be instantiated and called as such:\n# obj = MajorityChecker(arr)\n# param_1 = obj.query(left,right,threshold)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} MajorityChecker;\n\n\nMajorityChecker* majorityCheckerCreate(int* arr, int arrSize) {\n\n}\n\nint majorityCheckerQuery(MajorityChecker* obj, int left, int right, int threshold) {\n\n}\n\nvoid majorityCheckerFree(MajorityChecker* obj) {\n\n}\n\n/**\n * Your MajorityChecker struct will be instantiated and called as such:\n * MajorityChecker* obj = majorityCheckerCreate(arr, arrSize);\n * int param_1 = majorityCheckerQuery(obj, left, right, threshold);\n \n * majorityCheckerFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class MajorityChecker {\n\n public MajorityChecker(int[] arr) {\n\n }\n \n public int Query(int left, int right, int threshold) {\n\n }\n}\n\n/**\n * Your MajorityChecker object will be instantiated and called as such:\n * MajorityChecker obj = new MajorityChecker(arr);\n * int param_1 = obj.Query(left,right,threshold);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n */\nvar MajorityChecker = function(arr) {\n\n};\n\n/** \n * @param {number} left \n * @param {number} right \n * @param {number} threshold\n * @return {number}\n */\nMajorityChecker.prototype.query = function(left, right, threshold) {\n\n};\n\n/**\n * Your MajorityChecker object will be instantiated and called as such:\n * var obj = new MajorityChecker(arr)\n * var param_1 = obj.query(left,right,threshold)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class MajorityChecker\n\n=begin\n :type arr: Integer[]\n=end\n def initialize(arr)\n\n end\n\n\n=begin\n :type left: Integer\n :type right: Integer\n :type threshold: Integer\n :rtype: Integer\n=end\n def query(left, right, threshold)\n\n end\n\n\nend\n\n# Your MajorityChecker object will be instantiated and called as such:\n# obj = MajorityChecker.new(arr)\n# param_1 = obj.query(left, right, threshold)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass MajorityChecker {\n\n init(_ arr: [Int]) {\n\n }\n \n func query(_ left: Int, _ right: Int, _ threshold: Int) -> Int {\n\n }\n}\n\n/**\n * Your MajorityChecker object will be instantiated and called as such:\n * let obj = MajorityChecker(arr)\n * let ret_1: Int = obj.query(left, right, threshold)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type MajorityChecker struct {\n\n}\n\n\nfunc Constructor(arr []int) MajorityChecker {\n\n}\n\n\nfunc (this *MajorityChecker) Query(left int, right int, threshold int) int {\n\n}\n\n\n/**\n * Your MajorityChecker object will be instantiated and called as such:\n * obj := Constructor(arr);\n * param_1 := obj.Query(left,right,threshold);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class MajorityChecker(_arr: Array[Int]) {\n\n def query(left: Int, right: Int, threshold: Int): Int = {\n\n }\n\n}\n\n/**\n * Your MajorityChecker object will be instantiated and called as such:\n * var obj = new MajorityChecker(arr)\n * var param_1 = obj.query(left,right,threshold)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class MajorityChecker(arr: IntArray) {\n\n fun query(left: Int, right: Int, threshold: Int): Int {\n\n }\n\n}\n\n/**\n * Your MajorityChecker object will be instantiated and called as such:\n * var obj = MajorityChecker(arr)\n * var param_1 = obj.query(left,right,threshold)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct MajorityChecker {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl MajorityChecker {\n\n fn new(arr: Vec) -> Self {\n\n }\n \n fn query(&self, left: i32, right: i32, threshold: i32) -> i32 {\n\n }\n}\n\n/**\n * Your MajorityChecker object will be instantiated and called as such:\n * let obj = MajorityChecker::new(arr);\n * let ret_1: i32 = obj.query(left, right, threshold);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class MajorityChecker {\n /**\n * @param Integer[] $arr\n */\n function __construct($arr) {\n\n }\n\n /**\n * @param Integer $left\n * @param Integer $right\n * @param Integer $threshold\n * @return Integer\n */\n function query($left, $right, $threshold) {\n\n }\n}\n\n/**\n * Your MajorityChecker object will be instantiated and called as such:\n * $obj = MajorityChecker($arr);\n * $ret_1 = $obj->query($left, $right, $threshold);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class MajorityChecker {\n constructor(arr: number[]) {\n\n }\n\n query(left: number, right: number, threshold: number): number {\n\n }\n}\n\n/**\n * Your MajorityChecker object will be instantiated and called as such:\n * var obj = new MajorityChecker(arr)\n * var param_1 = obj.query(left,right,threshold)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define majority-checker%\n (class object%\n (super-new)\n\n ; arr : (listof exact-integer?)\n (init-field\n arr)\n \n ; query : exact-integer? exact-integer? exact-integer? -> exact-integer?\n (define/public (query left right threshold)\n\n )))\n\n;; Your majority-checker% object will be instantiated and called as such:\n;; (define obj (new majority-checker% [arr arr]))\n;; (define param_1 (send obj query left right threshold))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1157](https://leetcode-cn.com/problems/online-majority-element-in-subarray)", "[\u5b50\u6570\u7ec4\u4e2d\u5360\u7edd\u5927\u591a\u6570\u7684\u5143\u7d20](/solution/1100-1199/1157.Online%20Majority%20Element%20In%20Subarray/README.md)", "`\u7ebf\u6bb5\u6811`,`\u6570\u7ec4`,`\u4e8c\u5206\u67e5\u627e`", "\u56f0\u96be", ""], "md_table_row_en": ["[1157](https://leetcode.com/problems/online-majority-element-in-subarray)", "[Online Majority Element In Subarray](/solution/1100-1199/1157.Online%20Majority%20Element%20In%20Subarray/README_EN.md)", "`Segment Tree`,`Array`,`Binary Search`", "Hard", ""]}, {"question_id": "1261", "frontend_question_id": "1156", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/swap-for-longest-repeated-character-substring", "url_en": "https://leetcode.com/problems/swap-for-longest-repeated-character-substring", "relative_path_cn": "/solution/1100-1199/1156.Swap%20For%20Longest%20Repeated%20Character%20Substring/README.md", "relative_path_en": "/solution/1100-1199/1156.Swap%20For%20Longest%20Repeated%20Character%20Substring/README_EN.md", "title_cn": "\u5355\u5b57\u7b26\u91cd\u590d\u5b50\u4e32\u7684\u6700\u5927\u957f\u5ea6", "title_en": "Swap For Longest Repeated Character Substring", "question_title_slug": "swap-for-longest-repeated-character-substring", "content_en": "

    Given a string text, we are allowed to swap two of the characters in the string. Find the length of the longest substring with repeated characters.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: text = "ababa"\nOutput: 3\nExplanation: We can swap the first 'b' with the last 'a', or the last 'b' with the first 'a'. Then, the longest repeated character substring is "aaa", which its length is 3.\n
    \n\n

    Example 2:

    \n\n
    \nInput: text = "aaabaaa"\nOutput: 6\nExplanation: Swap 'b' with the last 'a' (or the first 'a'), and we get longest repeated character substring "aaaaaa", which its length is 6.\n
    \n\n

    Example 3:

    \n\n
    \nInput: text = "aaabbaaa"\nOutput: 4\n
    \n\n

    Example 4:

    \n\n
    \nInput: text = "aaaaa"\nOutput: 5\nExplanation: No need to swap, longest repeated character substring is "aaaaa", length is 5.\n
    \n\n

    Example 5:

    \n\n
    \nInput: text = "abcdef"\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= text.length <= 20000
    • \n\t
    • text consist of lowercase English characters only.
    • \n
    \n", "content_cn": "

    \u5982\u679c\u5b57\u7b26\u4e32\u4e2d\u7684\u6240\u6709\u5b57\u7b26\u90fd\u76f8\u540c\uff0c\u90a3\u4e48\u8fd9\u4e2a\u5b57\u7b26\u4e32\u662f\u5355\u5b57\u7b26\u91cd\u590d\u7684\u5b57\u7b26\u4e32\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 text\uff0c\u4f60\u53ea\u80fd\u4ea4\u6362\u5176\u4e2d\u4e24\u4e2a\u5b57\u7b26\u4e00\u6b21\u6216\u8005\u4ec0\u4e48\u90fd\u4e0d\u505a\uff0c\u7136\u540e\u5f97\u5230\u4e00\u4e9b\u5355\u5b57\u7b26\u91cd\u590d\u7684\u5b50\u4e32\u3002\u8fd4\u56de\u5176\u4e2d\u6700\u957f\u7684\u5b50\u4e32\u7684\u957f\u5ea6\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1atext = "ababa"\n\u8f93\u51fa\uff1a3\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1atext = "aaabaaa"\n\u8f93\u51fa\uff1a6\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1atext = "aaabbaaa"\n\u8f93\u51fa\uff1a4\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1atext = "aaaaa"\n\u8f93\u51fa\uff1a5\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1atext = "abcdef"\n\u8f93\u51fa\uff1a1\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= text.length <= 20000
    • \n\t
    • text \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\u3002
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxRepOpt1(string text) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxRepOpt1(String text) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxRepOpt1(self, text):\n \"\"\"\n :type text: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxRepOpt1(self, text: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxRepOpt1(char * text){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxRepOpt1(string text) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} text\n * @return {number}\n */\nvar maxRepOpt1 = function(text) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} text\n# @return {Integer}\ndef max_rep_opt1(text)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxRepOpt1(_ text: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxRepOpt1(text string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxRepOpt1(text: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxRepOpt1(text: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_rep_opt1(text: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $text\n * @return Integer\n */\n function maxRepOpt1($text) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxRepOpt1(text: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-rep-opt1 text)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1156](https://leetcode-cn.com/problems/swap-for-longest-repeated-character-substring)", "[\u5355\u5b57\u7b26\u91cd\u590d\u5b50\u4e32\u7684\u6700\u5927\u957f\u5ea6](/solution/1100-1199/1156.Swap%20For%20Longest%20Repeated%20Character%20Substring/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1156](https://leetcode.com/problems/swap-for-longest-repeated-character-substring)", "[Swap For Longest Repeated Character Substring](/solution/1100-1199/1156.Swap%20For%20Longest%20Repeated%20Character%20Substring/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "1260", "frontend_question_id": "1154", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/day-of-the-year", "url_en": "https://leetcode.com/problems/day-of-the-year", "relative_path_cn": "/solution/1100-1199/1154.Day%20of%20the%20Year/README.md", "relative_path_en": "/solution/1100-1199/1154.Day%20of%20the%20Year/README_EN.md", "title_cn": "\u4e00\u5e74\u4e2d\u7684\u7b2c\u51e0\u5929", "title_en": "Day of the Year", "question_title_slug": "day-of-the-year", "content_en": "

    Given a string date representing a Gregorian calendar date formatted as YYYY-MM-DD, return the day number of the year.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: date = "2019-01-09"\nOutput: 9\nExplanation: Given date is the 9th day of the year in 2019.\n
    \n\n

    Example 2:

    \n\n
    \nInput: date = "2019-02-10"\nOutput: 41\n
    \n\n

    Example 3:

    \n\n
    \nInput: date = "2003-03-01"\nOutput: 60\n
    \n\n

    Example 4:

    \n\n
    \nInput: date = "2004-03-01"\nOutput: 61\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • date.length == 10
    • \n\t
    • date[4] == date[7] == '-', and all other date[i]'s are digits
    • \n\t
    • date represents a calendar date between Jan 1st, 1900 and Dec 31, 2019.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6309 YYYY-MM-DD \u683c\u5f0f\u8868\u793a\u65e5\u671f\u7684\u5b57\u7b26\u4e32 date\uff0c\u8bf7\u4f60\u8ba1\u7b97\u5e76\u8fd4\u56de\u8be5\u65e5\u671f\u662f\u5f53\u5e74\u7684\u7b2c\u51e0\u5929\u3002

    \n\n

    \u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u8ba4\u4e3a 1 \u6708 1 \u65e5\u662f\u6bcf\u5e74\u7684\u7b2c 1 \u5929\uff0c1 \u6708 2 \u65e5\u662f\u6bcf\u5e74\u7684\u7b2c 2 \u5929\uff0c\u4f9d\u6b64\u7c7b\u63a8\u3002\u6bcf\u4e2a\u6708\u7684\u5929\u6570\u4e0e\u73b0\u884c\u516c\u5143\u7eaa\u5e74\u6cd5\uff08\u683c\u91cc\u9ad8\u5229\u5386\uff09\u4e00\u81f4\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1adate = "2019-01-09"\n\u8f93\u51fa\uff1a9\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1adate = "2019-02-10"\n\u8f93\u51fa\uff1a41\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1adate = "2003-03-01"\n\u8f93\u51fa\uff1a60\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1adate = "2004-03-01"\n\u8f93\u51fa\uff1a61
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • date.length == 10
    • \n\t
    • date[4] == date[7] == '-'\uff0c\u5176\u4ed6\u7684 date[i] \u90fd\u662f\u6570\u5b57\u3002
    • \n\t
    • date \u8868\u793a\u7684\u8303\u56f4\u4ece 1900 \u5e74 1 \u6708 1 \u65e5\u81f3 2019 \u5e74 12 \u6708 31 \u65e5\u3002
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int dayOfYear(string date) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int dayOfYear(String date) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def dayOfYear(self, date):\n \"\"\"\n :type date: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def dayOfYear(self, date: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint dayOfYear(char * date){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int DayOfYear(string date) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} date\n * @return {number}\n */\nvar dayOfYear = function(date) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} date\n# @return {Integer}\ndef day_of_year(date)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func dayOfYear(_ date: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func dayOfYear(date string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def dayOfYear(date: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun dayOfYear(date: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn day_of_year(date: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $date\n * @return Integer\n */\n function dayOfYear($date) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function dayOfYear(date: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (day-of-year date)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1154](https://leetcode-cn.com/problems/day-of-the-year)", "[\u4e00\u5e74\u4e2d\u7684\u7b2c\u51e0\u5929](/solution/1100-1199/1154.Day%20of%20the%20Year/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[1154](https://leetcode.com/problems/day-of-the-year)", "[Day of the Year](/solution/1100-1199/1154.Day%20of%20the%20Year/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "1259", "frontend_question_id": "1149", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/article-views-ii", "url_en": "https://leetcode.com/problems/article-views-ii", "relative_path_cn": "/solution/1100-1199/1149.Article%20Views%20II/README.md", "relative_path_en": "/solution/1100-1199/1149.Article%20Views%20II/README_EN.md", "title_cn": "\u6587\u7ae0\u6d4f\u89c8 II", "title_en": "Article Views II", "question_title_slug": "article-views-ii", "content_en": "

    Table: Views

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| article_id    | int     |\n| author_id     | int     |\n| viewer_id     | int     |\n| view_date     | date    |\n+---------------+---------+\nThere is no primary key for this table, it may have duplicate rows.\nEach row of this table indicates that some viewer viewed an article (written by some author) on some date. \nNote that equal author_id and viewer_id indicate the same person.
    \n\n

     

    \n\n

    Write an SQL query to find all the people who viewed more than one article on the same date, sorted in ascending order by their id.

    \n\n

    The query result format is in the following example:

    \n\n
    \nViews table:\n+------------+-----------+-----------+------------+\n| article_id | author_id | viewer_id | view_date  |\n+------------+-----------+-----------+------------+\n| 1          | 3         | 5         | 2019-08-01 |\n| 3          | 4         | 5         | 2019-08-01 |\n| 1          | 3         | 6         | 2019-08-02 |\n| 2          | 7         | 7         | 2019-08-01 |\n| 2          | 7         | 6         | 2019-08-02 |\n| 4          | 7         | 1         | 2019-07-22 |\n| 3          | 4         | 4         | 2019-07-21 |\n| 3          | 4         | 4         | 2019-07-21 |\n+------------+-----------+-----------+------------+\n\nResult table:\n+------+\n| id   |\n+------+\n| 5    |\n| 6    |\n+------+
    \n", "content_cn": "

    Table: Views

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| article_id    | int     |\n| author_id     | int     |\n| viewer_id     | int     |\n| view_date     | date    |\n+---------------+---------+\n\u6b64\u8868\u65e0\u4e3b\u952e\uff0c\u56e0\u6b64\u53ef\u80fd\u4f1a\u5b58\u5728\u91cd\u590d\u884c\u3002\u6b64\u8868\u7684\u6bcf\u4e00\u884c\u90fd\u8868\u793a\u67d0\u4eba\u5728\u67d0\u5929\u6d4f\u89c8\u4e86\u67d0\u4f4d\u4f5c\u8005\u7684\u67d0\u7bc7\u6587\u7ae0\u3002 \u8bf7\u6ce8\u610f\uff0c\u540c\u4e00\u4eba\u7684 author_id \u548c viewer_id \u662f\u76f8\u540c\u7684\u3002\n
    \n\n

     

    \n\n

    \u7f16\u5199\u4e00\u6761 SQL \u67e5\u8be2\u6765\u627e\u51fa\u5728\u540c\u4e00\u5929\u9605\u8bfb\u81f3\u5c11\u4e24\u7bc7\u6587\u7ae0\u7684\u4eba\uff0c\u7ed3\u679c\u6309\u7167 id \u5347\u5e8f\u6392\u5e8f\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u7684\u683c\u5f0f\u5982\u4e0b\uff1a

    \n\n
    \nViews table:\n+------------+-----------+-----------+------------+\n| article_id | author_id | viewer_id | view_date  |\n+------------+-----------+-----------+------------+\n| 1          | 3         | 5         | 2019-08-01 |\n| 3          | 4         | 5         | 2019-08-01 |\n| 1          | 3         | 6         | 2019-08-02 |\n| 2          | 7         | 7         | 2019-08-01 |\n| 2          | 7         | 6         | 2019-08-02 |\n| 4          | 7         | 1         | 2019-07-22 |\n| 3          | 4         | 4         | 2019-07-21 |\n| 3          | 4         | 4         | 2019-07-21 |\n+------------+-----------+-----------+------------+\n\nResult table:\n+------+\n| id   |\n+------+\n| 5    |\n| 6    |\n+------+
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1149](https://leetcode-cn.com/problems/article-views-ii)", "[\u6587\u7ae0\u6d4f\u89c8 II](/solution/1100-1199/1149.Article%20Views%20II/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1149](https://leetcode.com/problems/article-views-ii)", "[Article Views II](/solution/1100-1199/1149.Article%20Views%20II/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1258", "frontend_question_id": "1148", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/article-views-i", "url_en": "https://leetcode.com/problems/article-views-i", "relative_path_cn": "/solution/1100-1199/1148.Article%20Views%20I/README.md", "relative_path_en": "/solution/1100-1199/1148.Article%20Views%20I/README_EN.md", "title_cn": "\u6587\u7ae0\u6d4f\u89c8 I", "title_en": "Article Views I", "question_title_slug": "article-views-i", "content_en": "

    Table: Views

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| article_id    | int     |\n| author_id     | int     |\n| viewer_id     | int     |\n| view_date     | date    |\n+---------------+---------+\nThere is no primary key for this table, it may have duplicate rows.\nEach row of this table indicates that some viewer viewed an article (written by some author) on some date. \nNote that equal author_id and viewer_id indicate the same person.
    \n\n

     

    \n\n

    Write an SQL query to find all the authors that viewed at least one of their own articles, sorted in ascending order by their id.

    \n\n

    The query result format is in the following example:

    \n\n
    \nViews table:\n+------------+-----------+-----------+------------+\n| article_id | author_id | viewer_id | view_date  |\n+------------+-----------+-----------+------------+\n| 1          | 3         | 5         | 2019-08-01 |\n| 1          | 3         | 6         | 2019-08-02 |\n| 2          | 7         | 7         | 2019-08-01 |\n| 2          | 7         | 6         | 2019-08-02 |\n| 4          | 7         | 1         | 2019-07-22 |\n| 3          | 4         | 4         | 2019-07-21 |\n| 3          | 4         | 4         | 2019-07-21 |\n+------------+-----------+-----------+------------+\n\nResult table:\n+------+\n| id   |\n+------+\n| 4    |\n| 7    |\n+------+\n
    \n", "content_cn": "

    Views \u8868\uff1a

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| article_id    | int     |\n| author_id     | int     |\n| viewer_id     | int     |\n| view_date     | date    |\n+---------------+---------+\n\u6b64\u8868\u65e0\u4e3b\u952e\uff0c\u56e0\u6b64\u53ef\u80fd\u4f1a\u5b58\u5728\u91cd\u590d\u884c\u3002\n\u6b64\u8868\u7684\u6bcf\u4e00\u884c\u90fd\u8868\u793a\u67d0\u4eba\u5728\u67d0\u5929\u6d4f\u89c8\u4e86\u67d0\u4f4d\u4f5c\u8005\u7684\u67d0\u7bc7\u6587\u7ae0\u3002\n\u8bf7\u6ce8\u610f\uff0c\u540c\u4e00\u4eba\u7684 author_id \u548c viewer_id \u662f\u76f8\u540c\u7684\u3002\n
    \n\n

     

    \n\n

    \u8bf7\u7f16\u5199\u4e00\u6761 SQL \u67e5\u8be2\u4ee5\u627e\u51fa\u6240\u6709\u6d4f\u89c8\u8fc7\u81ea\u5df1\u6587\u7ae0\u7684\u4f5c\u8005\uff0c\u7ed3\u679c\u6309\u7167 id \u5347\u5e8f\u6392\u5217\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u7684\u683c\u5f0f\u5982\u4e0b\u6240\u793a\uff1a

    \n\n
    \nViews \u8868\uff1a\n+------------+-----------+-----------+------------+\n| article_id | author_id | viewer_id | view_date  |\n+------------+-----------+-----------+------------+\n| 1          | 3         | 5         | 2019-08-01 |\n| 1          | 3         | 6         | 2019-08-02 |\n| 2          | 7         | 7         | 2019-08-01 |\n| 2          | 7         | 6         | 2019-08-02 |\n| 4          | 7         | 1         | 2019-07-22 |\n| 3          | 4         | 4         | 2019-07-21 |\n| 3          | 4         | 4         | 2019-07-21 |\n+------------+-----------+-----------+------------+\n\n\u7ed3\u679c\u8868\uff1a\n+------+\n| id   |\n+------+\n| 4    |\n| 7    |\n+------+\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1148](https://leetcode-cn.com/problems/article-views-i)", "[\u6587\u7ae0\u6d4f\u89c8 I](/solution/1100-1199/1148.Article%20Views%20I/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1148](https://leetcode.com/problems/article-views-i)", "[Article Views I](/solution/1100-1199/1148.Article%20Views%20I/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1257", "frontend_question_id": "1632", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/rank-transform-of-a-matrix", "url_en": "https://leetcode.com/problems/rank-transform-of-a-matrix", "relative_path_cn": "/solution/1600-1699/1632.Rank%20Transform%20of%20a%20Matrix/README.md", "relative_path_en": "/solution/1600-1699/1632.Rank%20Transform%20of%20a%20Matrix/README_EN.md", "title_cn": "\u77e9\u9635\u8f6c\u6362\u540e\u7684\u79e9", "title_en": "Rank Transform of a Matrix", "question_title_slug": "rank-transform-of-a-matrix", "content_en": "

    Given an m x n matrix, return a new matrix answer where answer[row][col] is the rank of matrix[row][col].

    \n\n

    The rank is an integer that represents how large an element is compared to other elements. It is calculated using the following rules:

    \n\n
      \n\t
    • The rank is an integer starting from 1.
    • \n\t
    • If two elements p and q are in the same row or column, then:\n\t
        \n\t\t
      • If p < q then rank(p) < rank(q)
      • \n\t\t
      • If p == q then rank(p) == rank(q)
      • \n\t\t
      • If p > q then rank(p) > rank(q)
      • \n\t
      \n\t
    • \n\t
    • The rank should be as small as possible.
    • \n
    \n\n

    It is guaranteed that answer is unique under the given rules.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: matrix = [[1,2],[3,4]]\nOutput: [[1,2],[2,3]]\nExplanation:\nThe rank of matrix[0][0] is 1 because it is the smallest integer in its row and column.\nThe rank of matrix[0][1] is 2 because matrix[0][1] > matrix[0][0] and matrix[0][0] is rank 1.\nThe rank of matrix[1][0] is 2 because matrix[1][0] > matrix[0][0] and matrix[0][0] is rank 1.\nThe rank of matrix[1][1] is 3 because matrix[1][1] > matrix[0][1], matrix[1][1] > matrix[1][0], and both matrix[0][1] and matrix[1][0] are rank 2.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: matrix = [[7,7],[7,7]]\nOutput: [[1,1],[1,1]]\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: matrix = [[20,-21,14],[-19,4,19],[22,-47,24],[-19,4,19]]\nOutput: [[4,2,3],[1,3,4],[5,1,6],[1,3,4]]\n
    \n\n

    Example 4:

    \n\"\"\n
    \nInput: matrix = [[7,3,6],[1,4,5],[9,8,2]]\nOutput: [[5,1,4],[1,2,3],[6,3,1]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == matrix.length
    • \n\t
    • n == matrix[i].length
    • \n\t
    • 1 <= m, n <= 500
    • \n\t
    • -109 <= matrix[row][col] <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u00a0m x n\u00a0\u7684\u77e9\u9635 matrix\u00a0\uff0c\u8bf7\u4f60\u8fd4\u56de\u4e00\u4e2a\u65b0\u7684\u77e9\u9635\u00a0answer\u00a0\uff0c\u5176\u4e2d\u00a0answer[row][col]\u00a0\u662f\u00a0matrix[row][col]\u00a0\u7684\u79e9\u3002

    \n\n

    \u6bcf\u4e2a\u5143\u7d20\u7684\u00a0\u79e9\u00a0\u662f\u4e00\u4e2a\u6574\u6570\uff0c\u8868\u793a\u8fd9\u4e2a\u5143\u7d20\u76f8\u5bf9\u4e8e\u5176\u4ed6\u5143\u7d20\u7684\u5927\u5c0f\u5173\u7cfb\uff0c\u5b83\u6309\u7167\u5982\u4e0b\u89c4\u5219\u8ba1\u7b97\uff1a

    \n\n
      \n\t
    • \u79e9\u662f\u4ece 1 \u5f00\u59cb\u7684\u4e00\u4e2a\u6574\u6570\u3002
    • \n\t
    • \u5982\u679c\u4e24\u4e2a\u5143\u7d20\u00a0p \u548c\u00a0q\u00a0\u5728 \u540c\u4e00\u884c\u00a0\u6216\u8005 \u540c\u4e00\u5217\u00a0\uff0c\u90a3\u4e48\uff1a\n\t
        \n\t\t
      • \u5982\u679c\u00a0p < q \uff0c\u90a3\u4e48\u00a0rank(p) < rank(q)
      • \n\t\t
      • \u5982\u679c\u00a0p == q\u00a0\uff0c\u90a3\u4e48\u00a0rank(p) == rank(q)
      • \n\t\t
      • \u5982\u679c\u00a0p > q\u00a0\uff0c\u90a3\u4e48\u00a0rank(p) > rank(q)
      • \n\t
      \n\t
    • \n\t
    • \u79e9\u00a0\u9700\u8981\u8d8a \u5c0f\u00a0\u8d8a\u597d\u3002
    • \n
    \n\n

    \u9898\u76ee\u4fdd\u8bc1\u6309\u7167\u4e0a\u9762\u89c4\u5219\u00a0answer\u00a0\u6570\u7ec4\u662f\u552f\u4e00\u7684\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1amatrix = [[1,2],[3,4]]\n\u8f93\u51fa\uff1a[[1,2],[2,3]]\n\u89e3\u91ca\uff1a\nmatrix[0][0] \u7684\u79e9\u4e3a 1 \uff0c\u56e0\u4e3a\u5b83\u662f\u6240\u5728\u884c\u548c\u5217\u7684\u6700\u5c0f\u6574\u6570\u3002\nmatrix[0][1] \u7684\u79e9\u4e3a 2 \uff0c\u56e0\u4e3a matrix[0][1] > matrix[0][0] \u4e14 matrix[0][0] \u7684\u79e9\u4e3a 1 \u3002\nmatrix[1][0] \u7684\u79e9\u4e3a 2 \uff0c\u56e0\u4e3a matrix[1][0] > matrix[0][0] \u4e14 matrix[0][0] \u7684\u79e9\u4e3a 1 \u3002\nmatrix[1][1] \u7684\u79e9\u4e3a 3 \uff0c\u56e0\u4e3a matrix[1][1] > matrix[0][1]\uff0c matrix[1][1] > matrix[1][0] \u4e14 matrix[0][1] \u548c matrix[1][0] \u7684\u79e9\u90fd\u4e3a 2 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1amatrix = [[7,7],[7,7]]\n\u8f93\u51fa\uff1a[[1,1],[1,1]]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1amatrix = [[20,-21,14],[-19,4,19],[22,-47,24],[-19,4,19]]\n\u8f93\u51fa\uff1a[[4,2,3],[1,3,4],[5,1,6],[1,3,4]]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1amatrix = [[7,3,6],[1,4,5],[9,8,2]]\n\u8f93\u51fa\uff1a[[5,1,4],[1,2,3],[6,3,1]]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == matrix.length
    • \n\t
    • n == matrix[i].length
    • \n\t
    • 1 <= m, n <= 500
    • \n\t
    • -109 <= matrix[row][col] <= 109
    • \n
    \n", "tags_en": ["Greedy", "Union Find"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u5e76\u67e5\u96c6"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> matrixRankTransform(vector>& matrix) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[][] matrixRankTransform(int[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def matrixRankTransform(self, matrix):\n \"\"\"\n :type matrix: List[List[int]]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def matrixRankTransform(self, matrix: List[List[int]]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** matrixRankTransform(int** matrix, int matrixSize, int* matrixColSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[][] MatrixRankTransform(int[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} matrix\n * @return {number[][]}\n */\nvar matrixRankTransform = function(matrix) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} matrix\n# @return {Integer[][]}\ndef matrix_rank_transform(matrix)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func matrixRankTransform(_ matrix: [[Int]]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func matrixRankTransform(matrix [][]int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def matrixRankTransform(matrix: Array[Array[Int]]): Array[Array[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun matrixRankTransform(matrix: Array): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn matrix_rank_transform(matrix: Vec>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $matrix\n * @return Integer[][]\n */\n function matrixRankTransform($matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function matrixRankTransform(matrix: number[][]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (matrix-rank-transform matrix)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1632](https://leetcode-cn.com/problems/rank-transform-of-a-matrix)", "[\u77e9\u9635\u8f6c\u6362\u540e\u7684\u79e9](/solution/1600-1699/1632.Rank%20Transform%20of%20a%20Matrix/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u5e76\u67e5\u96c6`", "\u56f0\u96be", ""], "md_table_row_en": ["[1632](https://leetcode.com/problems/rank-transform-of-a-matrix)", "[Rank Transform of a Matrix](/solution/1600-1699/1632.Rank%20Transform%20of%20a%20Matrix/README_EN.md)", "`Greedy`,`Union Find`", "Hard", ""]}, {"question_id": "1256", "frontend_question_id": "1331", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/rank-transform-of-an-array", "url_en": "https://leetcode.com/problems/rank-transform-of-an-array", "relative_path_cn": "/solution/1300-1399/1331.Rank%20Transform%20of%20an%20Array/README.md", "relative_path_en": "/solution/1300-1399/1331.Rank%20Transform%20of%20an%20Array/README_EN.md", "title_cn": "\u6570\u7ec4\u5e8f\u53f7\u8f6c\u6362", "title_en": "Rank Transform of an Array", "question_title_slug": "rank-transform-of-an-array", "content_en": "

    Given an array of integers arr, replace each element with its rank.

    \r\n\r\n

    The rank represents how large the element is. The rank has the following rules:

    \r\n\r\n
      \r\n\t
    • Rank is an integer starting from 1.
    • \r\n\t
    • The larger the element, the larger the rank. If two elements are equal, their rank must be the same.
    • \r\n\t
    • Rank should be as small as possible.
    • \r\n
    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: arr = [40,10,20,30]\r\nOutput: [4,1,2,3]\r\nExplanation: 40 is the largest element. 10 is the smallest. 20 is the second smallest. 30 is the third smallest.
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: arr = [100,100,100]\r\nOutput: [1,1,1]\r\nExplanation: Same elements share the same rank.\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: arr = [37,12,28,9,100,56,80,5,12]\r\nOutput: [5,3,4,2,8,6,7,1,3]\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 0 <= arr.length <= 105
    • \r\n\t
    • -109 <= arr[i] <= 109
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr \uff0c\u8bf7\u4f60\u5c06\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u66ff\u6362\u4e3a\u5b83\u4eec\u6392\u5e8f\u540e\u7684\u5e8f\u53f7\u3002

    \n\n

    \u5e8f\u53f7\u4ee3\u8868\u4e86\u4e00\u4e2a\u5143\u7d20\u6709\u591a\u5927\u3002\u5e8f\u53f7\u7f16\u53f7\u7684\u89c4\u5219\u5982\u4e0b\uff1a

    \n\n
      \n\t
    • \u5e8f\u53f7\u4ece 1 \u5f00\u59cb\u7f16\u53f7\u3002
    • \n\t
    • \u4e00\u4e2a\u5143\u7d20\u8d8a\u5927\uff0c\u90a3\u4e48\u5e8f\u53f7\u8d8a\u5927\u3002\u5982\u679c\u4e24\u4e2a\u5143\u7d20\u76f8\u7b49\uff0c\u90a3\u4e48\u5b83\u4eec\u7684\u5e8f\u53f7\u76f8\u540c\u3002
    • \n\t
    • \u6bcf\u4e2a\u6570\u5b57\u7684\u5e8f\u53f7\u90fd\u5e94\u8be5\u5c3d\u53ef\u80fd\u5730\u5c0f\u3002
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [40,10,20,30]\n\u8f93\u51fa\uff1a[4,1,2,3]\n\u89e3\u91ca\uff1a40 \u662f\u6700\u5927\u7684\u5143\u7d20\u3002 10 \u662f\u6700\u5c0f\u7684\u5143\u7d20\u3002 20 \u662f\u7b2c\u4e8c\u5c0f\u7684\u6570\u5b57\u3002 30 \u662f\u7b2c\u4e09\u5c0f\u7684\u6570\u5b57\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [100,100,100]\n\u8f93\u51fa\uff1a[1,1,1]\n\u89e3\u91ca\uff1a\u6240\u6709\u5143\u7d20\u6709\u76f8\u540c\u7684\u5e8f\u53f7\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [37,12,28,9,100,56,80,5,12]\n\u8f93\u51fa\uff1a[5,3,4,2,8,6,7,1,3]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= arr.length <= 105
    • \n\t
    • -109 <= arr[i] <= 109
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector arrayRankTransform(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] arrayRankTransform(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def arrayRankTransform(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: List[int]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def arrayRankTransform(self, arr: List[int]) -> List[int]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* arrayRankTransform(int* arr, int arrSize, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] ArrayRankTransform(int[] arr) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number[]}\n */\nvar arrayRankTransform = function(arr) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer[]}\ndef array_rank_transform(arr)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func arrayRankTransform(_ arr: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func arrayRankTransform(arr []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def arrayRankTransform(arr: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun arrayRankTransform(arr: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn array_rank_transform(arr: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer[]\n */\n function arrayRankTransform($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function arrayRankTransform(arr: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (array-rank-transform arr)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1331](https://leetcode-cn.com/problems/rank-transform-of-an-array)", "[\u6570\u7ec4\u5e8f\u53f7\u8f6c\u6362](/solution/1300-1399/1331.Rank%20Transform%20of%20an%20Array/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1331](https://leetcode.com/problems/rank-transform-of-an-array)", "[Rank Transform of an Array](/solution/1300-1399/1331.Rank%20Transform%20of%20an%20Array/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1255", "frontend_question_id": "1330", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reverse-subarray-to-maximize-array-value", "url_en": "https://leetcode.com/problems/reverse-subarray-to-maximize-array-value", "relative_path_cn": "/solution/1300-1399/1330.Reverse%20Subarray%20To%20Maximize%20Array%20Value/README.md", "relative_path_en": "/solution/1300-1399/1330.Reverse%20Subarray%20To%20Maximize%20Array%20Value/README_EN.md", "title_cn": "\u7ffb\u8f6c\u5b50\u6570\u7ec4\u5f97\u5230\u6700\u5927\u7684\u6570\u7ec4\u503c", "title_en": "Reverse Subarray To Maximize Array Value", "question_title_slug": "reverse-subarray-to-maximize-array-value", "content_en": "

    You are given an integer array nums. The value of this array is defined as the sum of |nums[i]-nums[i+1]| for all 0 <= i < nums.length-1.

    \r\n\r\n

    You are allowed to select any subarray of the given array and reverse it. You can perform this operation only once.

    \r\n\r\n

    Find maximum possible value of the final array.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: nums = [2,3,1,5,4]\r\nOutput: 10\r\nExplanation: By reversing the subarray [3,1,5] the array becomes [2,5,1,3,4] whose value is 10.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: nums = [2,4,9,24,2,1,10]\r\nOutput: 68\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= nums.length <= 3*10^4
    • \r\n\t
    • -10^5 <= nums[i] <= 10^5
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \u3002\u300c\u6570\u7ec4\u503c\u300d\u5b9a\u4e49\u4e3a\u6240\u6709\u6ee1\u8db3 0 <= i < nums.length-1 \u7684 |nums[i]-nums[i+1]| \u7684\u548c\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u9009\u62e9\u7ed9\u5b9a\u6570\u7ec4\u7684\u4efb\u610f\u5b50\u6570\u7ec4\uff0c\u5e76\u5c06\u8be5\u5b50\u6570\u7ec4\u7ffb\u8f6c\u3002\u4f46\u4f60\u53ea\u80fd\u6267\u884c\u8fd9\u4e2a\u64cd\u4f5c \u4e00\u6b21 \u3002

    \n\n

    \u8bf7\u4f60\u627e\u5230\u53ef\u884c\u7684\u6700\u5927 \u6570\u7ec4\u503c \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [2,3,1,5,4]\n\u8f93\u51fa\uff1a10\n\u89e3\u91ca\uff1a\u901a\u8fc7\u7ffb\u8f6c\u5b50\u6570\u7ec4 [3,1,5] \uff0c\u6570\u7ec4\u53d8\u6210 [2,5,1,3,4] \uff0c\u6570\u7ec4\u503c\u4e3a 10 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [2,4,9,24,2,1,10]\n\u8f93\u51fa\uff1a68\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 3*10^4
    • \n\t
    • -10^5 <= nums[i] <= 10^5
    • \n
    \n", "tags_en": ["Array", "Math"], "tags_cn": ["\u6570\u7ec4", "\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxValueAfterReverse(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxValueAfterReverse(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxValueAfterReverse(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxValueAfterReverse(self, nums: List[int]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxValueAfterReverse(int* nums, int numsSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxValueAfterReverse(int[] nums) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar maxValueAfterReverse = function(nums) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef max_value_after_reverse(nums)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxValueAfterReverse(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxValueAfterReverse(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxValueAfterReverse(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxValueAfterReverse(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_value_after_reverse(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function maxValueAfterReverse($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxValueAfterReverse(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-value-after-reverse nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1330](https://leetcode-cn.com/problems/reverse-subarray-to-maximize-array-value)", "[\u7ffb\u8f6c\u5b50\u6570\u7ec4\u5f97\u5230\u6700\u5927\u7684\u6570\u7ec4\u503c](/solution/1300-1399/1330.Reverse%20Subarray%20To%20Maximize%20Array%20Value/README.md)", "`\u6570\u7ec4`,`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[1330](https://leetcode.com/problems/reverse-subarray-to-maximize-array-value)", "[Reverse Subarray To Maximize Array Value](/solution/1300-1399/1330.Reverse%20Subarray%20To%20Maximize%20Array%20Value/README_EN.md)", "`Array`,`Math`", "Hard", ""]}, {"question_id": "1254", "frontend_question_id": "1302", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/deepest-leaves-sum", "url_en": "https://leetcode.com/problems/deepest-leaves-sum", "relative_path_cn": "/solution/1300-1399/1302.Deepest%20Leaves%20Sum/README.md", "relative_path_en": "/solution/1300-1399/1302.Deepest%20Leaves%20Sum/README_EN.md", "title_cn": "\u5c42\u6570\u6700\u6df1\u53f6\u5b50\u8282\u70b9\u7684\u548c", "title_en": "Deepest Leaves Sum", "question_title_slug": "deepest-leaves-sum", "content_en": "Given the root of a binary tree, return the sum of values of its deepest leaves.\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,2,3,4,5,null,6,7,null,null,null,null,8]\nOutput: 15\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = [6,7,8,2,7,1,3,9,null,1,4,null,null,null,5]\nOutput: 19\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 104].
    • \n\t
    • 1 <= Node.val <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u68f5\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9 root \uff0c\u8bf7\u4f60\u8fd4\u56de \u5c42\u6570\u6700\u6df1\u7684\u53f6\u5b50\u8282\u70b9\u7684\u548c \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aroot = [1,2,3,4,5,null,6,7,null,null,null,null,8]\n\u8f93\u51fa\uff1a15\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [6,7,8,2,7,1,3,9,null,1,4,null,null,null,5]\n\u8f93\u51fa\uff1a19\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u6570\u76ee\u5728\u8303\u56f4 [1, 104]\u00a0\u4e4b\u95f4\u3002
    • \n\t
    • 1 <= Node.val <= 100
    • \n
    \n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int deepestLeavesSum(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int deepestLeavesSum(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def deepestLeavesSum(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def deepestLeavesSum(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint deepestLeavesSum(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int DeepestLeavesSum(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar deepestLeavesSum = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef deepest_leaves_sum(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func deepestLeavesSum(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc deepestLeavesSum(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def deepestLeavesSum(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun deepestLeavesSum(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn deepest_leaves_sum(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function deepestLeavesSum($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction deepestLeavesSum(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (deepest-leaves-sum root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1302](https://leetcode-cn.com/problems/deepest-leaves-sum)", "[\u5c42\u6570\u6700\u6df1\u53f6\u5b50\u8282\u70b9\u7684\u548c](/solution/1300-1399/1302.Deepest%20Leaves%20Sum/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1302](https://leetcode.com/problems/deepest-leaves-sum)", "[Deepest Leaves Sum](/solution/1300-1399/1302.Deepest%20Leaves%20Sum/README_EN.md)", "`Tree`,`Depth-first Search`", "Medium", ""]}, {"question_id": "1253", "frontend_question_id": "1329", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sort-the-matrix-diagonally", "url_en": "https://leetcode.com/problems/sort-the-matrix-diagonally", "relative_path_cn": "/solution/1300-1399/1329.Sort%20the%20Matrix%20Diagonally/README.md", "relative_path_en": "/solution/1300-1399/1329.Sort%20the%20Matrix%20Diagonally/README_EN.md", "title_cn": "\u5c06\u77e9\u9635\u6309\u5bf9\u89d2\u7ebf\u6392\u5e8f", "title_en": "Sort the Matrix Diagonally", "question_title_slug": "sort-the-matrix-diagonally", "content_en": "

    A matrix diagonal is a diagonal line of cells starting from some cell in either the topmost row or leftmost column and going in the bottom-right direction until reaching the matrix's end. For example, the matrix diagonal starting from mat[2][0], where mat is a 6 x 3 matrix, includes cells mat[2][0], mat[3][1], and mat[4][2].

    \n\n

    Given an m x n matrix mat of integers, sort each matrix diagonal in ascending order and return the resulting matrix.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: mat = [[3,3,1,1],[2,2,1,2],[1,1,1,2]]\nOutput: [[1,1,1,1],[1,2,2,2],[1,2,3,3]]\n
    \n\n

    Example 2:

    \n\n
    \nInput: mat = [[11,25,66,1,69,7],[23,55,17,45,15,52],[75,31,36,44,58,8],[22,27,33,25,68,4],[84,28,14,11,5,50]]\nOutput: [[5,17,4,1,52,7],[11,11,25,45,8,69],[14,23,25,44,58,15],[22,27,31,36,50,66],[84,28,75,33,55,68]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == mat.length
    • \n\t
    • n == mat[i].length
    • \n\t
    • 1 <= m, n <= 100
    • \n\t
    • 1 <= mat[i][j] <= 100
    • \n
    \n", "content_cn": "

    \u77e9\u9635\u5bf9\u89d2\u7ebf \u662f\u4e00\u6761\u4ece\u77e9\u9635\u6700\u4e0a\u9762\u884c\u6216\u8005\u6700\u5de6\u4fa7\u5217\u4e2d\u7684\u67d0\u4e2a\u5143\u7d20\u5f00\u59cb\u7684\u5bf9\u89d2\u7ebf\uff0c\u6cbf\u53f3\u4e0b\u65b9\u5411\u4e00\u76f4\u5230\u77e9\u9635\u672b\u5c3e\u7684\u5143\u7d20\u3002\u4f8b\u5982\uff0c\u77e9\u9635 mat \u6709 6 \u884c 3 \u5217\uff0c\u4ece mat[2][0] \u5f00\u59cb\u7684 \u77e9\u9635\u5bf9\u89d2\u7ebf \u5c06\u4f1a\u7ecf\u8fc7 mat[2][0]\u3001mat[3][1] \u548c mat[4][2] \u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u00a0m * n\u00a0\u7684\u6574\u6570\u77e9\u9635\u00a0mat\u00a0\uff0c\u8bf7\u4f60\u5c06\u540c\u4e00\u6761 \u77e9\u9635\u5bf9\u89d2\u7ebf \u4e0a\u7684\u5143\u7d20\u6309\u5347\u5e8f\u6392\u5e8f\u540e\uff0c\u8fd4\u56de\u6392\u597d\u5e8f\u7684\u77e9\u9635\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1amat = [[3,3,1,1],[2,2,1,2],[1,1,1,2]]\n\u8f93\u51fa\uff1a[[1,1,1,1],[1,2,2,2],[1,2,3,3]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1amat = [[11,25,66,1,69,7],[23,55,17,45,15,52],[75,31,36,44,58,8],[22,27,33,25,68,4],[84,28,14,11,5,50]]\n\u8f93\u51fa\uff1a[[5,17,4,1,52,7],[11,11,25,45,8,69],[14,23,25,44,58,15],[22,27,31,36,50,66],[84,28,75,33,55,68]]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m ==\u00a0mat.length
    • \n\t
    • n ==\u00a0mat[i].length
    • \n\t
    • 1 <= m, n\u00a0<= 100
    • \n\t
    • 1 <= mat[i][j] <= 100
    • \n
    \n", "tags_en": ["Sort", "Array"], "tags_cn": ["\u6392\u5e8f", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> diagonalSort(vector>& mat) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[][] diagonalSort(int[][] mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def diagonalSort(self, mat):\n \"\"\"\n :type mat: List[List[int]]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def diagonalSort(self, mat: List[List[int]]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** diagonalSort(int** mat, int matSize, int* matColSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[][] DiagonalSort(int[][] mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} mat\n * @return {number[][]}\n */\nvar diagonalSort = function(mat) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} mat\n# @return {Integer[][]}\ndef diagonal_sort(mat)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func diagonalSort(_ mat: [[Int]]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func diagonalSort(mat [][]int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def diagonalSort(mat: Array[Array[Int]]): Array[Array[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun diagonalSort(mat: Array): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn diagonal_sort(mat: Vec>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $mat\n * @return Integer[][]\n */\n function diagonalSort($mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function diagonalSort(mat: number[][]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (diagonal-sort mat)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1329](https://leetcode-cn.com/problems/sort-the-matrix-diagonally)", "[\u5c06\u77e9\u9635\u6309\u5bf9\u89d2\u7ebf\u6392\u5e8f](/solution/1300-1399/1329.Sort%20the%20Matrix%20Diagonally/README.md)", "`\u6392\u5e8f`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1329](https://leetcode.com/problems/sort-the-matrix-diagonally)", "[Sort the Matrix Diagonally](/solution/1300-1399/1329.Sort%20the%20Matrix%20Diagonally/README_EN.md)", "`Sort`,`Array`", "Medium", ""]}, {"question_id": "1252", "frontend_question_id": "1328", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/break-a-palindrome", "url_en": "https://leetcode.com/problems/break-a-palindrome", "relative_path_cn": "/solution/1300-1399/1328.Break%20a%20Palindrome/README.md", "relative_path_en": "/solution/1300-1399/1328.Break%20a%20Palindrome/README_EN.md", "title_cn": "\u7834\u574f\u56de\u6587\u4e32", "title_en": "Break a Palindrome", "question_title_slug": "break-a-palindrome", "content_en": "

    Given a palindromic string of lowercase English letters palindrome, replace exactly one character with any lowercase English letter so that the resulting string is not a palindrome and that it is the lexicographically smallest one possible.

    \n\n

    Return the resulting string. If there is no way to replace a character to make it not a palindrome, return an empty string.

    \n\n

    A string a is lexicographically smaller than a string b (of the same length) if in the first position where a and b differ, a has a character strictly smaller than the corresponding character in b. For example, "abcc" is lexicographically smaller than "abcd" because the first position they differ is at the fourth character, and 'c' is smaller than 'd'.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: palindrome = "abccba"\nOutput: "aaccba"\nExplanation: There are many ways to make "abccba" not a palindrome, such as "zbccba", "aaccba", and "abacba".\nOf all the ways, "aaccba" is the lexicographically smallest.\n
    \n\n

    Example 2:

    \n\n
    \nInput: palindrome = "a"\nOutput: ""\nExplanation: There is no way to replace a single character to make "a" not a palindrome, so return an empty string.\n
    \n\n

    Example 3:

    \n\n
    \nInput: palindrome = "aa"\nOutput: "ab"
    \n\n

    Example 4:

    \n\n
    \nInput: palindrome = "aba"\nOutput: "abb"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= palindrome.length <= 1000
    • \n\t
    • palindrome consists of only lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u56de\u6587\u5b57\u7b26\u4e32 palindrome \uff0c\u8bf7\u4f60\u5c06\u5176\u4e2d \u4e00\u4e2a \u5b57\u7b26\u7528\u4efb\u610f\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u66ff\u6362\uff0c\u4f7f\u5f97\u7ed3\u679c\u5b57\u7b26\u4e32\u7684\u5b57\u5178\u5e8f\u6700\u5c0f\uff0c\u4e14 \u4e0d\u662f \u56de\u6587\u4e32\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u7ed3\u679c\u5b57\u7b26\u4e32\u3002\u5982\u679c\u65e0\u6cd5\u505a\u5230\uff0c\u5219\u8fd4\u56de\u4e00\u4e2a\u7a7a\u4e32\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1apalindrome = "abccba"\n\u8f93\u51fa\uff1a"aaccba"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1apalindrome = "a"\n\u8f93\u51fa\uff1a""\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= palindrome.length <= 1000
    • \n\t
    • palindrome \u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string breakPalindrome(string palindrome) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String breakPalindrome(String palindrome) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def breakPalindrome(self, palindrome):\n \"\"\"\n :type palindrome: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def breakPalindrome(self, palindrome: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * breakPalindrome(char * palindrome){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string BreakPalindrome(string palindrome) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} palindrome\n * @return {string}\n */\nvar breakPalindrome = function(palindrome) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} palindrome\n# @return {String}\ndef break_palindrome(palindrome)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func breakPalindrome(_ palindrome: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func breakPalindrome(palindrome string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def breakPalindrome(palindrome: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun breakPalindrome(palindrome: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn break_palindrome(palindrome: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $palindrome\n * @return String\n */\n function breakPalindrome($palindrome) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function breakPalindrome(palindrome: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (break-palindrome palindrome)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1328](https://leetcode-cn.com/problems/break-a-palindrome)", "[\u7834\u574f\u56de\u6587\u4e32](/solution/1300-1399/1328.Break%20a%20Palindrome/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1328](https://leetcode.com/problems/break-a-palindrome)", "[Break a Palindrome](/solution/1300-1399/1328.Break%20a%20Palindrome/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "1251", "frontend_question_id": "1147", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-chunked-palindrome-decomposition", "url_en": "https://leetcode.com/problems/longest-chunked-palindrome-decomposition", "relative_path_cn": "/solution/1100-1199/1147.Longest%20Chunked%20Palindrome%20Decomposition/README.md", "relative_path_en": "/solution/1100-1199/1147.Longest%20Chunked%20Palindrome%20Decomposition/README_EN.md", "title_cn": "\u6bb5\u5f0f\u56de\u6587", "title_en": "Longest Chunked Palindrome Decomposition", "question_title_slug": "longest-chunked-palindrome-decomposition", "content_en": "

    You are given a string text. You should split it to k substrings (subtext1, subtext2, ..., subtextk) such that:

    \n\n
      \n\t
    • subtexti is a non-empty string.
    • \n\t
    • The concatenation of all the substrings is equal to text (i.e., subtext1 + subtext2 + ... + subtextk == text).
    • \n\t
    • subtexti == subtextk - i + 1 for all valid values of i (i.e., 1 <= i <= k).
    • \n
    \n\n

    Return the largest possible value of k.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: text = "ghiabcdefhelloadamhelloabcdefghi"\nOutput: 7\nExplanation: We can split the string on "(ghi)(abcdef)(hello)(adam)(hello)(abcdef)(ghi)".\n
    \n\n

    Example 2:

    \n\n
    \nInput: text = "merchant"\nOutput: 1\nExplanation: We can split the string on "(merchant)".\n
    \n\n

    Example 3:

    \n\n
    \nInput: text = "antaprezatepzapreanta"\nOutput: 11\nExplanation: We can split the string on "(a)(nt)(a)(pre)(za)(tpe)(za)(pre)(a)(nt)(a)".\n
    \n\n

    Example 4:

    \n\n
    \nInput: text = "aaa"\nOutput: 3\nExplanation: We can split the string on "(a)(a)(a)".\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= text.length <= 1000
    • \n\t
    • text consists only of lowercase English characters.
    • \n
    \n", "content_cn": "

    \u6bb5\u5f0f\u56de\u6587 \u5176\u5b9e\u4e0e \u4e00\u822c\u56de\u6587 \u7c7b\u4f3c\uff0c\u53ea\u4e0d\u8fc7\u662f\u6700\u5c0f\u7684\u5355\u4f4d\u662f \u4e00\u6bb5\u5b57\u7b26 \u800c\u4e0d\u662f \u5355\u4e2a\u5b57\u6bcd\u3002

    \n\n

    \u4e3e\u4e2a\u4f8b\u5b50\uff0c\u5bf9\u4e8e\u4e00\u822c\u56de\u6587 "abcba" \u662f\u56de\u6587\uff0c\u800c "volvo" \u4e0d\u662f\uff0c\u4f46\u5982\u679c\u6211\u4eec\u628a "volvo" \u5206\u4e3a "vo"\u3001"l"\u3001"vo" \u4e09\u6bb5\uff0c\u5219\u53ef\u4ee5\u8ba4\u4e3a “(vo)(l)(vo)” \u662f\u6bb5\u5f0f\u56de\u6587\uff08\u5206\u4e3a 3 \u6bb5\uff09\u3002

    \n\n

     

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 text\uff0c\u5728\u786e\u4fdd\u5b83\u6ee1\u8db3\u6bb5\u5f0f\u56de\u6587\u7684\u524d\u63d0\u4e0b\uff0c\u8bf7\u4f60\u8fd4\u56de \u6bb5 \u7684 \u6700\u5927\u6570\u91cf k\u3002

    \n\n

    \u5982\u679c\u6bb5\u7684\u6700\u5927\u6570\u91cf\u4e3a k\uff0c\u90a3\u4e48\u5b58\u5728\u6ee1\u8db3\u4ee5\u4e0b\u6761\u4ef6\u7684 a_1, a_2, ..., a_k\uff1a

    \n\n
      \n\t
    • \u6bcf\u4e2a a_i \u90fd\u662f\u4e00\u4e2a\u975e\u7a7a\u5b57\u7b26\u4e32\uff1b
    • \n\t
    • \u5c06\u8fd9\u4e9b\u5b57\u7b26\u4e32\u9996\u4f4d\u76f8\u8fde\u7684\u7ed3\u679c a_1 + a_2 + ... + a_k \u548c\u539f\u59cb\u5b57\u7b26\u4e32 text \u76f8\u540c\uff1b
    • \n\t
    • \u5bf9\u4e8e\u6240\u67091 <= i <= k\uff0c\u90fd\u6709 a_i = a_{k+1 - i}\u3002
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1atext = "ghiabcdefhelloadamhelloabcdefghi"\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\u6211\u4eec\u53ef\u4ee5\u628a\u5b57\u7b26\u4e32\u62c6\u5206\u6210 "(ghi)(abcdef)(hello)(adam)(hello)(abcdef)(ghi)"\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1atext = "merchant"\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u6211\u4eec\u53ef\u4ee5\u628a\u5b57\u7b26\u4e32\u62c6\u5206\u6210 "(merchant)"\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1atext = "antaprezatepzapreanta"\n\u8f93\u51fa\uff1a11\n\u89e3\u91ca\uff1a\u6211\u4eec\u53ef\u4ee5\u628a\u5b57\u7b26\u4e32\u62c6\u5206\u6210 "(a)(nt)(a)(pre)(za)(tpe)(za)(pre)(a)(nt)(a)"\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1atext = "aaa"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6211\u4eec\u53ef\u4ee5\u628a\u5b57\u7b26\u4e32\u62c6\u5206\u6210 "(a)(a)(a)"\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • text \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u7b26\u7ec4\u6210\u3002
    • \n\t
    • 1 <= text.length <= 1000
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int longestDecomposition(string text) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int longestDecomposition(String text) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestDecomposition(self, text):\n \"\"\"\n :type text: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestDecomposition(self, text: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint longestDecomposition(char * text){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LongestDecomposition(string text) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} text\n * @return {number}\n */\nvar longestDecomposition = function(text) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} text\n# @return {Integer}\ndef longest_decomposition(text)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestDecomposition(_ text: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestDecomposition(text string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestDecomposition(text: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestDecomposition(text: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_decomposition(text: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $text\n * @return Integer\n */\n function longestDecomposition($text) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestDecomposition(text: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-decomposition text)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1147](https://leetcode-cn.com/problems/longest-chunked-palindrome-decomposition)", "[\u6bb5\u5f0f\u56de\u6587](/solution/1100-1199/1147.Longest%20Chunked%20Palindrome%20Decomposition/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1147](https://leetcode.com/problems/longest-chunked-palindrome-decomposition)", "[Longest Chunked Palindrome Decomposition](/solution/1100-1199/1147.Longest%20Chunked%20Palindrome%20Decomposition/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1250", "frontend_question_id": "1143", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-common-subsequence", "url_en": "https://leetcode.com/problems/longest-common-subsequence", "relative_path_cn": "/solution/1100-1199/1143.Longest%20Common%20Subsequence/README.md", "relative_path_en": "/solution/1100-1199/1143.Longest%20Common%20Subsequence/README_EN.md", "title_cn": "\u6700\u957f\u516c\u5171\u5b50\u5e8f\u5217", "title_en": "Longest Common Subsequence", "question_title_slug": "longest-common-subsequence", "content_en": "

    Given two strings text1 and text2, return the length of their longest common subsequence. If there is no common subsequence, return 0.

    \n\n

    A subsequence of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters.

    \n\n
      \n\t
    • For example, "ace" is a subsequence of "abcde".
    • \n
    \n\n

    A common subsequence of two strings is a subsequence that is common to both strings.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: text1 = "abcde", text2 = "ace" \nOutput: 3  \nExplanation: The longest common subsequence is "ace" and its length is 3.\n
    \n\n

    Example 2:

    \n\n
    \nInput: text1 = "abc", text2 = "abc"\nOutput: 3\nExplanation: The longest common subsequence is "abc" and its length is 3.\n
    \n\n

    Example 3:

    \n\n
    \nInput: text1 = "abc", text2 = "def"\nOutput: 0\nExplanation: There is no such common subsequence, so the result is 0.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= text1.length, text2.length <= 1000
    • \n\t
    • text1 and text2 consist of only lowercase English characters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u5b57\u7b26\u4e32\u00a0text1 \u548c\u00a0text2\uff0c\u8fd4\u56de\u8fd9\u4e24\u4e2a\u5b57\u7b26\u4e32\u7684\u6700\u957f \u516c\u5171\u5b50\u5e8f\u5217 \u7684\u957f\u5ea6\u3002\u5982\u679c\u4e0d\u5b58\u5728 \u516c\u5171\u5b50\u5e8f\u5217 \uff0c\u8fd4\u56de 0 \u3002

    \n\n

    \u4e00\u4e2a\u5b57\u7b26\u4e32\u7684\u00a0\u5b50\u5e8f\u5217\u00a0\u662f\u6307\u8fd9\u6837\u4e00\u4e2a\u65b0\u7684\u5b57\u7b26\u4e32\uff1a\u5b83\u662f\u7531\u539f\u5b57\u7b26\u4e32\u5728\u4e0d\u6539\u53d8\u5b57\u7b26\u7684\u76f8\u5bf9\u987a\u5e8f\u7684\u60c5\u51b5\u4e0b\u5220\u9664\u67d0\u4e9b\u5b57\u7b26\uff08\u4e5f\u53ef\u4ee5\u4e0d\u5220\u9664\u4efb\u4f55\u5b57\u7b26\uff09\u540e\u7ec4\u6210\u7684\u65b0\u5b57\u7b26\u4e32\u3002

    \n\n
      \n\t
    • \u4f8b\u5982\uff0c\"ace\" \u662f \"abcde\" \u7684\u5b50\u5e8f\u5217\uff0c\u4f46 \"aec\" \u4e0d\u662f \"abcde\" \u7684\u5b50\u5e8f\u5217\u3002
    • \n
    \n\n

    \u4e24\u4e2a\u5b57\u7b26\u4e32\u7684 \u516c\u5171\u5b50\u5e8f\u5217 \u662f\u8fd9\u4e24\u4e2a\u5b57\u7b26\u4e32\u6240\u5171\u540c\u62e5\u6709\u7684\u5b50\u5e8f\u5217\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1atext1 = \"abcde\", text2 = \"ace\" \n\u8f93\u51fa\uff1a3  \n\u89e3\u91ca\uff1a\u6700\u957f\u516c\u5171\u5b50\u5e8f\u5217\u662f \"ace\" \uff0c\u5b83\u7684\u957f\u5ea6\u4e3a 3 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1atext1 = \"abc\", text2 = \"abc\"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6700\u957f\u516c\u5171\u5b50\u5e8f\u5217\u662f \"abc\" \uff0c\u5b83\u7684\u957f\u5ea6\u4e3a 3 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1atext1 = \"abc\", text2 = \"def\"\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u4e24\u4e2a\u5b57\u7b26\u4e32\u6ca1\u6709\u516c\u5171\u5b50\u5e8f\u5217\uff0c\u8fd4\u56de 0 \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= text1.length, text2.length <= 1000
    • \n\t
    • text1 \u548c\u00a0text2 \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u7b26\u7ec4\u6210\u3002
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int longestCommonSubsequence(string text1, string text2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int longestCommonSubsequence(String text1, String text2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestCommonSubsequence(self, text1, text2):\n \"\"\"\n :type text1: str\n :type text2: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestCommonSubsequence(self, text1: str, text2: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint longestCommonSubsequence(char * text1, char * text2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LongestCommonSubsequence(string text1, string text2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} text1\n * @param {string} text2\n * @return {number}\n */\nvar longestCommonSubsequence = function(text1, text2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} text1\n# @param {String} text2\n# @return {Integer}\ndef longest_common_subsequence(text1, text2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestCommonSubsequence(_ text1: String, _ text2: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestCommonSubsequence(text1 string, text2 string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestCommonSubsequence(text1: String, text2: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestCommonSubsequence(text1: String, text2: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_common_subsequence(text1: String, text2: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $text1\n * @param String $text2\n * @return Integer\n */\n function longestCommonSubsequence($text1, $text2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestCommonSubsequence(text1: string, text2: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-common-subsequence text1 text2)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1143](https://leetcode-cn.com/problems/longest-common-subsequence)", "[\u6700\u957f\u516c\u5171\u5b50\u5e8f\u5217](/solution/1100-1199/1143.Longest%20Common%20Subsequence/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1143](https://leetcode.com/problems/longest-common-subsequence)", "[Longest Common Subsequence](/solution/1100-1199/1143.Longest%20Common%20Subsequence/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "1249", "frontend_question_id": "1146", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/snapshot-array", "url_en": "https://leetcode.com/problems/snapshot-array", "relative_path_cn": "/solution/1100-1199/1146.Snapshot%20Array/README.md", "relative_path_en": "/solution/1100-1199/1146.Snapshot%20Array/README_EN.md", "title_cn": "\u5feb\u7167\u6570\u7ec4", "title_en": "Snapshot Array", "question_title_slug": "snapshot-array", "content_en": "

    Implement a SnapshotArray that supports the following interface:

    \n\n
      \n\t
    • SnapshotArray(int length) initializes an array-like data structure with the given length.  Initially, each element equals 0.
    • \n\t
    • void set(index, val) sets the element at the given index to be equal to val.
    • \n\t
    • int snap() takes a snapshot of the array and returns the snap_id: the total number of times we called snap() minus 1.
    • \n\t
    • int get(index, snap_id) returns the value at the given index, at the time we took the snapshot with the given snap_id
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: ["SnapshotArray","set","snap","set","get"]\n[[3],[0,5],[],[0,6],[0,0]]\nOutput: [null,null,0,null,5]\nExplanation: \nSnapshotArray snapshotArr = new SnapshotArray(3); // set the length to be 3\nsnapshotArr.set(0,5);  // Set array[0] = 5\nsnapshotArr.snap();  // Take a snapshot, return snap_id = 0\nsnapshotArr.set(0,6);\nsnapshotArr.get(0,0);  // Get the value of array[0] with snap_id = 0, return 5
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= length <= 50000
    • \n\t
    • At most 50000 calls will be made to set, snap, and get.
    • \n\t
    • 0 <= index < length
    • \n\t
    • 0 <= snap_id < (the total number of times we call snap())
    • \n\t
    • 0 <= val <= 10^9
    • \n
    \n", "content_cn": "

    \u5b9e\u73b0\u652f\u6301\u4e0b\u5217\u63a5\u53e3\u7684\u300c\u5feb\u7167\u6570\u7ec4\u300d- SnapshotArray\uff1a

    \n\n
      \n\t
    • SnapshotArray(int length) - \u521d\u59cb\u5316\u4e00\u4e2a\u4e0e\u6307\u5b9a\u957f\u5ea6\u76f8\u7b49\u7684 \u7c7b\u6570\u7ec4 \u7684\u6570\u636e\u7ed3\u6784\u3002\u521d\u59cb\u65f6\uff0c\u6bcf\u4e2a\u5143\u7d20\u90fd\u7b49\u4e8e 0\u3002
    • \n\t
    • void set(index, val) - \u4f1a\u5c06\u6307\u5b9a\u7d22\u5f15 index \u5904\u7684\u5143\u7d20\u8bbe\u7f6e\u4e3a val\u3002
    • \n\t
    • int snap() - \u83b7\u53d6\u8be5\u6570\u7ec4\u7684\u5feb\u7167\uff0c\u5e76\u8fd4\u56de\u5feb\u7167\u7684\u7f16\u53f7 snap_id\uff08\u5feb\u7167\u53f7\u662f\u8c03\u7528 snap() \u7684\u603b\u6b21\u6570\u51cf\u53bb 1\uff09\u3002
    • \n\t
    • int get(index, snap_id) - \u6839\u636e\u6307\u5b9a\u7684 snap_id \u9009\u62e9\u5feb\u7167\uff0c\u5e76\u8fd4\u56de\u8be5\u5feb\u7167\u6307\u5b9a\u7d22\u5f15 index \u7684\u503c\u3002
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1a["SnapshotArray","set","snap","set","get"]\n     [[3],[0,5],[],[0,6],[0,0]]\n\u8f93\u51fa\uff1a[null,null,0,null,5]\n\u89e3\u91ca\uff1a\nSnapshotArray snapshotArr = new SnapshotArray(3); // \u521d\u59cb\u5316\u4e00\u4e2a\u957f\u5ea6\u4e3a 3 \u7684\u5feb\u7167\u6570\u7ec4\nsnapshotArr.set(0,5);  // \u4ee4 array[0] = 5\nsnapshotArr.snap();  // \u83b7\u53d6\u5feb\u7167\uff0c\u8fd4\u56de snap_id = 0\nsnapshotArr.set(0,6);\nsnapshotArr.get(0,0);  // \u83b7\u53d6 snap_id = 0 \u7684\u5feb\u7167\u4e2d array[0] \u7684\u503c\uff0c\u8fd4\u56de 5
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= length <= 50000
    • \n\t
    • \u9898\u76ee\u6700\u591a\u8fdb\u884c50000 \u6b21set\uff0csnap\uff0c\u548c get\u7684\u8c03\u7528 \u3002
    • \n\t
    • 0 <= index < length
    • \n\t
    • 0 <= snap_id < \u6211\u4eec\u8c03\u7528 snap() \u7684\u603b\u6b21\u6570
    • \n\t
    • 0 <= val <= 10^9
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class SnapshotArray {\npublic:\n SnapshotArray(int length) {\n\n }\n \n void set(int index, int val) {\n\n }\n \n int snap() {\n\n }\n \n int get(int index, int snap_id) {\n\n }\n};\n\n/**\n * Your SnapshotArray object will be instantiated and called as such:\n * SnapshotArray* obj = new SnapshotArray(length);\n * obj->set(index,val);\n * int param_2 = obj->snap();\n * int param_3 = obj->get(index,snap_id);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class SnapshotArray {\n\n public SnapshotArray(int length) {\n\n }\n \n public void set(int index, int val) {\n\n }\n \n public int snap() {\n\n }\n \n public int get(int index, int snap_id) {\n\n }\n}\n\n/**\n * Your SnapshotArray object will be instantiated and called as such:\n * SnapshotArray obj = new SnapshotArray(length);\n * obj.set(index,val);\n * int param_2 = obj.snap();\n * int param_3 = obj.get(index,snap_id);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class SnapshotArray(object):\n\n def __init__(self, length):\n \"\"\"\n :type length: int\n \"\"\"\n\n\n def set(self, index, val):\n \"\"\"\n :type index: int\n :type val: int\n :rtype: None\n \"\"\"\n\n\n def snap(self):\n \"\"\"\n :rtype: int\n \"\"\"\n\n\n def get(self, index, snap_id):\n \"\"\"\n :type index: int\n :type snap_id: int\n :rtype: int\n \"\"\"\n\n\n\n# Your SnapshotArray object will be instantiated and called as such:\n# obj = SnapshotArray(length)\n# obj.set(index,val)\n# param_2 = obj.snap()\n# param_3 = obj.get(index,snap_id)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class SnapshotArray:\n\n def __init__(self, length: int):\n\n\n def set(self, index: int, val: int) -> None:\n\n\n def snap(self) -> int:\n\n\n def get(self, index: int, snap_id: int) -> int:\n\n\n\n# Your SnapshotArray object will be instantiated and called as such:\n# obj = SnapshotArray(length)\n# obj.set(index,val)\n# param_2 = obj.snap()\n# param_3 = obj.get(index,snap_id)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} SnapshotArray;\n\n\nSnapshotArray* snapshotArrayCreate(int length) {\n\n}\n\nvoid snapshotArraySet(SnapshotArray* obj, int index, int val) {\n\n}\n\nint snapshotArraySnap(SnapshotArray* obj) {\n\n}\n\nint snapshotArrayGet(SnapshotArray* obj, int index, int snap_id) {\n\n}\n\nvoid snapshotArrayFree(SnapshotArray* obj) {\n\n}\n\n/**\n * Your SnapshotArray struct will be instantiated and called as such:\n * SnapshotArray* obj = snapshotArrayCreate(length);\n * snapshotArraySet(obj, index, val);\n \n * int param_2 = snapshotArraySnap(obj);\n \n * int param_3 = snapshotArrayGet(obj, index, snap_id);\n \n * snapshotArrayFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class SnapshotArray {\n\n public SnapshotArray(int length) {\n\n }\n \n public void Set(int index, int val) {\n\n }\n \n public int Snap() {\n\n }\n \n public int Get(int index, int snap_id) {\n\n }\n}\n\n/**\n * Your SnapshotArray object will be instantiated and called as such:\n * SnapshotArray obj = new SnapshotArray(length);\n * obj.Set(index,val);\n * int param_2 = obj.Snap();\n * int param_3 = obj.Get(index,snap_id);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} length\n */\nvar SnapshotArray = function(length) {\n\n};\n\n/** \n * @param {number} index \n * @param {number} val\n * @return {void}\n */\nSnapshotArray.prototype.set = function(index, val) {\n\n};\n\n/**\n * @return {number}\n */\nSnapshotArray.prototype.snap = function() {\n\n};\n\n/** \n * @param {number} index \n * @param {number} snap_id\n * @return {number}\n */\nSnapshotArray.prototype.get = function(index, snap_id) {\n\n};\n\n/**\n * Your SnapshotArray object will be instantiated and called as such:\n * var obj = new SnapshotArray(length)\n * obj.set(index,val)\n * var param_2 = obj.snap()\n * var param_3 = obj.get(index,snap_id)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class SnapshotArray\n\n=begin\n :type length: Integer\n=end\n def initialize(length)\n\n end\n\n\n=begin\n :type index: Integer\n :type val: Integer\n :rtype: Void\n=end\n def set(index, val)\n\n end\n\n\n=begin\n :rtype: Integer\n=end\n def snap()\n\n end\n\n\n=begin\n :type index: Integer\n :type snap_id: Integer\n :rtype: Integer\n=end\n def get(index, snap_id)\n\n end\n\n\nend\n\n# Your SnapshotArray object will be instantiated and called as such:\n# obj = SnapshotArray.new(length)\n# obj.set(index, val)\n# param_2 = obj.snap()\n# param_3 = obj.get(index, snap_id)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass SnapshotArray {\n\n init(_ length: Int) {\n\n }\n \n func set(_ index: Int, _ val: Int) {\n\n }\n \n func snap() -> Int {\n\n }\n \n func get(_ index: Int, _ snap_id: Int) -> Int {\n\n }\n}\n\n/**\n * Your SnapshotArray object will be instantiated and called as such:\n * let obj = SnapshotArray(length)\n * obj.set(index, val)\n * let ret_2: Int = obj.snap()\n * let ret_3: Int = obj.get(index, snap_id)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type SnapshotArray struct {\n\n}\n\n\nfunc Constructor(length int) SnapshotArray {\n\n}\n\n\nfunc (this *SnapshotArray) Set(index int, val int) {\n\n}\n\n\nfunc (this *SnapshotArray) Snap() int {\n\n}\n\n\nfunc (this *SnapshotArray) Get(index int, snap_id int) int {\n\n}\n\n\n/**\n * Your SnapshotArray object will be instantiated and called as such:\n * obj := Constructor(length);\n * obj.Set(index,val);\n * param_2 := obj.Snap();\n * param_3 := obj.Get(index,snap_id);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class SnapshotArray(_length: Int) {\n\n def set(index: Int, `val`: Int) {\n\n }\n\n def snap(): Int = {\n\n }\n\n def get(index: Int, snap_id: Int): Int = {\n\n }\n\n}\n\n/**\n * Your SnapshotArray object will be instantiated and called as such:\n * var obj = new SnapshotArray(length)\n * obj.set(index,`val`)\n * var param_2 = obj.snap()\n * var param_3 = obj.get(index,snap_id)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class SnapshotArray(length: Int) {\n\n fun set(index: Int, `val`: Int) {\n\n }\n\n fun snap(): Int {\n\n }\n\n fun get(index: Int, snap_id: Int): Int {\n\n }\n\n}\n\n/**\n * Your SnapshotArray object will be instantiated and called as such:\n * var obj = SnapshotArray(length)\n * obj.set(index,`val`)\n * var param_2 = obj.snap()\n * var param_3 = obj.get(index,snap_id)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct SnapshotArray {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl SnapshotArray {\n\n fn new(length: i32) -> Self {\n\n }\n \n fn set(&self, index: i32, val: i32) {\n\n }\n \n fn snap(&self) -> i32 {\n\n }\n \n fn get(&self, index: i32, snap_id: i32) -> i32 {\n\n }\n}\n\n/**\n * Your SnapshotArray object will be instantiated and called as such:\n * let obj = SnapshotArray::new(length);\n * obj.set(index, val);\n * let ret_2: i32 = obj.snap();\n * let ret_3: i32 = obj.get(index, snap_id);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class SnapshotArray {\n /**\n * @param Integer $length\n */\n function __construct($length) {\n\n }\n\n /**\n * @param Integer $index\n * @param Integer $val\n * @return NULL\n */\n function set($index, $val) {\n\n }\n\n /**\n * @return Integer\n */\n function snap() {\n\n }\n\n /**\n * @param Integer $index\n * @param Integer $snap_id\n * @return Integer\n */\n function get($index, $snap_id) {\n\n }\n}\n\n/**\n * Your SnapshotArray object will be instantiated and called as such:\n * $obj = SnapshotArray($length);\n * $obj->set($index, $val);\n * $ret_2 = $obj->snap();\n * $ret_3 = $obj->get($index, $snap_id);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class SnapshotArray {\n constructor(length: number) {\n\n }\n\n set(index: number, val: number): void {\n\n }\n\n snap(): number {\n\n }\n\n get(index: number, snap_id: number): number {\n\n }\n}\n\n/**\n * Your SnapshotArray object will be instantiated and called as such:\n * var obj = new SnapshotArray(length)\n * obj.set(index,val)\n * var param_2 = obj.snap()\n * var param_3 = obj.get(index,snap_id)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define snapshot-array%\n (class object%\n (super-new)\n\n ; length : exact-integer?\n (init-field\n length)\n \n ; set : exact-integer? exact-integer? -> void?\n (define/public (set index val)\n\n )\n ; snap : -> exact-integer?\n (define/public (snap)\n\n )\n ; get : exact-integer? exact-integer? -> exact-integer?\n (define/public (get index snap_id)\n\n )))\n\n;; Your snapshot-array% object will be instantiated and called as such:\n;; (define obj (new snapshot-array% [length length]))\n;; (send obj set index val)\n;; (define param_2 (send obj snap))\n;; (define param_3 (send obj get index snap_id))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1146](https://leetcode-cn.com/problems/snapshot-array)", "[\u5feb\u7167\u6570\u7ec4](/solution/1100-1199/1146.Snapshot%20Array/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1146](https://leetcode.com/problems/snapshot-array)", "[Snapshot Array](/solution/1100-1199/1146.Snapshot%20Array/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "1248", "frontend_question_id": "1145", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/binary-tree-coloring-game", "url_en": "https://leetcode.com/problems/binary-tree-coloring-game", "relative_path_cn": "/solution/1100-1199/1145.Binary%20Tree%20Coloring%20Game/README.md", "relative_path_en": "/solution/1100-1199/1145.Binary%20Tree%20Coloring%20Game/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u7740\u8272\u6e38\u620f", "title_en": "Binary Tree Coloring Game", "question_title_slug": "binary-tree-coloring-game", "content_en": "

    Two players play a turn based game on a binary tree.  We are given the root of this binary tree, and the number of nodes n in the tree.  n is odd, and each node has a distinct value from 1 to n.

    \n\n

    Initially, the first player names a value x with 1 <= x <= n, and the second player names a value y with 1 <= y <= n and y != x.  The first player colors the node with value x red, and the second player colors the node with value y blue.

    \n\n

    Then, the players take turns starting with the first player.  In each turn, that player chooses a node of their color (red if player 1, blue if player 2) and colors an uncolored neighbor of the chosen node (either the left child, right child, or parent of the chosen node.)

    \n\n

    If (and only if) a player cannot choose such a node in this way, they must pass their turn.  If both players pass their turn, the game ends, and the winner is the player that colored more nodes.

    \n\n

    You are the second player.  If it is possible to choose such a y to ensure you win the game, return true.  If it is not possible, return false.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,2,3,4,5,6,7,8,9,10,11], n = 11, x = 3\nOutput: true\nExplanation: The second player can choose the node with value 2.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • root is the root of a binary tree with n nodes and distinct node values from 1 to n.
    • \n\t
    • n is odd.
    • \n\t
    • 1 <= x <= n <= 100
    • \n
    \n", "content_cn": "

    \u6709\u4e24\u4f4d\u6781\u5ba2\u73a9\u5bb6\u53c2\u4e0e\u4e86\u4e00\u573a\u300c\u4e8c\u53c9\u6811\u7740\u8272\u300d\u7684\u6e38\u620f\u3002\u6e38\u620f\u4e2d\uff0c\u7ed9\u51fa\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9 root\uff0c\u6811\u4e0a\u603b\u5171\u6709 n \u4e2a\u8282\u70b9\uff0c\u4e14 n \u4e3a\u5947\u6570\uff0c\u5176\u4e2d\u6bcf\u4e2a\u8282\u70b9\u4e0a\u7684\u503c\u4ece 1 \u5230 n \u5404\u4e0d\u76f8\u540c\u3002

    \n\n

     

    \n\n

    \u6e38\u620f\u4ece\u300c\u4e00\u53f7\u300d\u73a9\u5bb6\u5f00\u59cb\uff08\u300c\u4e00\u53f7\u300d\u73a9\u5bb6\u4e3a\u7ea2\u8272\uff0c\u300c\u4e8c\u53f7\u300d\u73a9\u5bb6\u4e3a\u84dd\u8272\uff09\uff0c\u6700\u5f00\u59cb\u65f6\uff0c

    \n\n

    \u300c\u4e00\u53f7\u300d\u73a9\u5bb6\u4ece [1, n] \u4e2d\u53d6\u4e00\u4e2a\u503c x\uff081 <= x <= n\uff09\uff1b

    \n\n

    \u300c\u4e8c\u53f7\u300d\u73a9\u5bb6\u4e5f\u4ece [1, n] \u4e2d\u53d6\u4e00\u4e2a\u503c y\uff081 <= y <= n\uff09\u4e14 y != x\u3002

    \n\n

    \u300c\u4e00\u53f7\u300d\u73a9\u5bb6\u7ed9\u503c\u4e3a x \u7684\u8282\u70b9\u67d3\u4e0a\u7ea2\u8272\uff0c\u800c\u300c\u4e8c\u53f7\u300d\u73a9\u5bb6\u7ed9\u503c\u4e3a y \u7684\u8282\u70b9\u67d3\u4e0a\u84dd\u8272\u3002

    \n\n

     

    \n\n

    \u4e4b\u540e\u4e24\u4f4d\u73a9\u5bb6\u8f6e\u6d41\u8fdb\u884c\u64cd\u4f5c\uff0c\u6bcf\u4e00\u56de\u5408\uff0c\u73a9\u5bb6\u9009\u62e9\u4e00\u4e2a\u4ed6\u4e4b\u524d\u6d82\u597d\u989c\u8272\u7684\u8282\u70b9\uff0c\u5c06\u6240\u9009\u8282\u70b9\u4e00\u4e2a \u672a\u7740\u8272 \u7684\u90bb\u8282\u70b9\uff08\u5373\u5de6\u53f3\u5b50\u8282\u70b9\u3001\u6216\u7236\u8282\u70b9\uff09\u8fdb\u884c\u67d3\u8272\u3002

    \n\n

    \u5982\u679c\u5f53\u524d\u73a9\u5bb6\u65e0\u6cd5\u627e\u5230\u8fd9\u6837\u7684\u8282\u70b9\u6765\u67d3\u8272\u65f6\uff0c\u4ed6\u7684\u56de\u5408\u5c31\u4f1a\u88ab\u8df3\u8fc7\u3002

    \n\n

    \u82e5\u4e24\u4e2a\u73a9\u5bb6\u90fd\u6ca1\u6709\u53ef\u4ee5\u67d3\u8272\u7684\u8282\u70b9\u65f6\uff0c\u6e38\u620f\u7ed3\u675f\u3002\u7740\u8272\u8282\u70b9\u6700\u591a\u7684\u90a3\u4f4d\u73a9\u5bb6\u83b7\u5f97\u80dc\u5229 \u270c\ufe0f\u3002

    \n\n

     

    \n\n

    \u73b0\u5728\uff0c\u5047\u8bbe\u4f60\u662f\u300c\u4e8c\u53f7\u300d\u73a9\u5bb6\uff0c\u6839\u636e\u6240\u7ed9\u51fa\u7684\u8f93\u5165\uff0c\u5047\u5982\u5b58\u5728\u4e00\u4e2a y \u503c\u53ef\u4ee5\u786e\u4fdd\u4f60\u8d62\u5f97\u8fd9\u573a\u6e38\u620f\uff0c\u5219\u8fd4\u56de true\uff1b\u82e5\u65e0\u6cd5\u83b7\u80dc\uff0c\u5c31\u8bf7\u8fd4\u56de false\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1aroot = [1,2,3,4,5,6,7,8,9,10,11], n = 11, x = 3\n\u8f93\u51fa\uff1aTrue\n\u89e3\u91ca\uff1a\u7b2c\u4e8c\u4e2a\u73a9\u5bb6\u53ef\u4ee5\u9009\u62e9\u503c\u4e3a 2 \u7684\u8282\u70b9\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9\u4e3a root\uff0c\u6811\u4e0a\u7531 n \u4e2a\u8282\u70b9\uff0c\u8282\u70b9\u4e0a\u7684\u503c\u4ece 1 \u5230 n \u5404\u4e0d\u76f8\u540c\u3002
    • \n\t
    • n \u4e3a\u5947\u6570\u3002
    • \n\t
    • 1 <= x <= n <= 100
    • \n
    \n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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 */\nclass Solution {\npublic:\n bool btreeGameWinningMove(TreeNode* root, int n, int x) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode(int x) { val = x; }\n * }\n */\nclass Solution {\n public boolean btreeGameWinningMove(TreeNode root, int n, int x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution(object):\n def btreeGameWinningMove(self, root, n, x):\n \"\"\"\n :type root: TreeNode\n :type n: int\n :type x: int\n :rtype: bool\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution:\n def btreeGameWinningMove(self, root: TreeNode, n: int, x: int) -> bool:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nbool btreeGameWinningMove(struct TreeNode* root, int n, int x){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int x) { val = x; }\n * }\n */\npublic class Solution {\n public bool BtreeGameWinningMove(TreeNode root, int n, int x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val) {\n * this.val = val;\n * this.left = this.right = null;\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number} n\n * @param {number} x\n * @return {boolean}\n */\nvar btreeGameWinningMove = function(root, n, x) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val)\n# @val = val\n# @left, @right = nil, nil\n# end\n# end\n\n# @param {TreeNode} root\n# @param {Integer} n\n# @param {Integer} x\n# @return {Boolean}\ndef btree_game_winning_move(root, n, x)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.left = nil\n * self.right = nil\n * }\n * }\n */\nclass Solution {\n func btreeGameWinningMove(_ root: TreeNode?, _ n: Int, _ x: Int) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc btreeGameWinningMove(root *TreeNode, n int, x int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(var _value: Int) {\n * var value: Int = _value\n * var left: TreeNode = null\n * var right: TreeNode = null\n * }\n */\nobject Solution {\n def btreeGameWinningMove(root: TreeNode, n: Int, x: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun btreeGameWinningMove(root: TreeNode?, n: Int, x: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n// \n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn btree_game_winning_move(root: Option>>, n: i32, x: i32) -> bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($value) { $this->val = $value; }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param Integer $n\n * @param Integer $x\n * @return Boolean\n */\n function btreeGameWinningMove($root, $n, $x) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction btreeGameWinningMove(root: TreeNode | null, n: number, x: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (btree-game-winning-move root n x)\n (-> (or/c tree-node? #f) exact-integer? exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1145](https://leetcode-cn.com/problems/binary-tree-coloring-game)", "[\u4e8c\u53c9\u6811\u7740\u8272\u6e38\u620f](/solution/1100-1199/1145.Binary%20Tree%20Coloring%20Game/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1145](https://leetcode.com/problems/binary-tree-coloring-game)", "[Binary Tree Coloring Game](/solution/1100-1199/1145.Binary%20Tree%20Coloring%20Game/README_EN.md)", "`Tree`,`Depth-first Search`", "Medium", ""]}, {"question_id": "1247", "frontend_question_id": "1144", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/decrease-elements-to-make-array-zigzag", "url_en": "https://leetcode.com/problems/decrease-elements-to-make-array-zigzag", "relative_path_cn": "/solution/1100-1199/1144.Decrease%20Elements%20To%20Make%20Array%20Zigzag/README.md", "relative_path_en": "/solution/1100-1199/1144.Decrease%20Elements%20To%20Make%20Array%20Zigzag/README_EN.md", "title_cn": "\u9012\u51cf\u5143\u7d20\u4f7f\u6570\u7ec4\u5448\u952f\u9f7f\u72b6", "title_en": "Decrease Elements To Make Array Zigzag", "question_title_slug": "decrease-elements-to-make-array-zigzag", "content_en": "

    Given an array nums of integers, a move consists of choosing any element and decreasing it by 1.

    \n\n

    An array A is a zigzag array if either:

    \n\n
      \n\t
    • Every even-indexed element is greater than adjacent elements, ie. A[0] > A[1] < A[2] > A[3] < A[4] > ...
    • \n\t
    • OR, every odd-indexed element is greater than adjacent elements, ie. A[0] < A[1] > A[2] < A[3] > A[4] < ...
    • \n
    \n\n

    Return the minimum number of moves to transform the given array nums into a zigzag array.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,3]\nOutput: 2\nExplanation: We can decrease 2 to 0 or 3 to 1.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [9,6,1,6,2]\nOutput: 4\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 1000
    • \n\t
    • 1 <= nums[i] <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums\uff0c\u6bcf\u6b21 \u64cd\u4f5c \u4f1a\u4ece\u4e2d\u9009\u62e9\u4e00\u4e2a\u5143\u7d20\u5e76 \u5c06\u8be5\u5143\u7d20\u7684\u503c\u51cf\u5c11 1\u3002

    \n\n

    \u5982\u679c\u7b26\u5408\u4e0b\u5217\u60c5\u51b5\u4e4b\u4e00\uff0c\u5219\u6570\u7ec4 A \u5c31\u662f \u952f\u9f7f\u6570\u7ec4\uff1a

    \n\n
      \n\t
    • \u6bcf\u4e2a\u5076\u6570\u7d22\u5f15\u5bf9\u5e94\u7684\u5143\u7d20\u90fd\u5927\u4e8e\u76f8\u90bb\u7684\u5143\u7d20\uff0c\u5373 A[0] > A[1] < A[2] > A[3] < A[4] > ...
    • \n\t
    • \u6216\u8005\uff0c\u6bcf\u4e2a\u5947\u6570\u7d22\u5f15\u5bf9\u5e94\u7684\u5143\u7d20\u90fd\u5927\u4e8e\u76f8\u90bb\u7684\u5143\u7d20\uff0c\u5373 A[0] < A[1] > A[2] < A[3] > A[4] < ...
    • \n
    \n\n

    \u8fd4\u56de\u5c06\u6570\u7ec4 nums \u8f6c\u6362\u4e3a\u952f\u9f7f\u6570\u7ec4\u6240\u9700\u7684\u6700\u5c0f\u64cd\u4f5c\u6b21\u6570\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,2,3]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6211\u4eec\u53ef\u4ee5\u628a 2 \u9012\u51cf\u5230 0\uff0c\u6216\u628a 3 \u9012\u51cf\u5230 1\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [9,6,1,6,2]\n\u8f93\u51fa\uff1a4\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 1000
    • \n\t
    • 1 <= nums[i] <= 1000
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int movesToMakeZigzag(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int movesToMakeZigzag(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def movesToMakeZigzag(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def movesToMakeZigzag(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint movesToMakeZigzag(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MovesToMakeZigzag(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar movesToMakeZigzag = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef moves_to_make_zigzag(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func movesToMakeZigzag(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func movesToMakeZigzag(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def movesToMakeZigzag(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun movesToMakeZigzag(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn moves_to_make_zigzag(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function movesToMakeZigzag($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function movesToMakeZigzag(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (moves-to-make-zigzag nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1144](https://leetcode-cn.com/problems/decrease-elements-to-make-array-zigzag)", "[\u9012\u51cf\u5143\u7d20\u4f7f\u6570\u7ec4\u5448\u952f\u9f7f\u72b6](/solution/1100-1199/1144.Decrease%20Elements%20To%20Make%20Array%20Zigzag/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1144](https://leetcode.com/problems/decrease-elements-to-make-array-zigzag)", "[Decrease Elements To Make Array Zigzag](/solution/1100-1199/1144.Decrease%20Elements%20To%20Make%20Array%20Zigzag/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "1246", "frontend_question_id": "1142", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/user-activity-for-the-past-30-days-ii", "url_en": "https://leetcode.com/problems/user-activity-for-the-past-30-days-ii", "relative_path_cn": "/solution/1100-1199/1142.User%20Activity%20for%20the%20Past%2030%20Days%20II/README.md", "relative_path_en": "/solution/1100-1199/1142.User%20Activity%20for%20the%20Past%2030%20Days%20II/README_EN.md", "title_cn": "\u8fc7\u53bb30\u5929\u7684\u7528\u6237\u6d3b\u52a8 II", "title_en": "User Activity for the Past 30 Days II", "question_title_slug": "user-activity-for-the-past-30-days-ii", "content_en": "

    Table: Activity

    \r\n\r\n
    \r\n+---------------+---------+\r\n| Column Name   | Type    |\r\n+---------------+---------+\r\n| user_id       | int     |\r\n| session_id    | int     |\r\n| activity_date | date    |\r\n| activity_type | enum    |\r\n+---------------+---------+\r\nThere is no primary key for this table, it may have duplicate rows.\r\nThe activity_type column is an ENUM of type ('open_session', 'end_session', 'scroll_down', 'send_message').\r\nThe table shows the user activities for a social media website.\r\nNote that each session belongs to exactly one user.
    \r\n\r\n

     

    \r\n\r\n

    Write an SQL query to find the average number of sessions per user for a period of 30 days ending 2019-07-27 inclusively, rounded to 2 decimal places. The sessions we want to count for a user are those with at least one activity in that time period.

    \r\n\r\n

    The query result format is in the following example:

    \r\n\r\n
    \r\nActivity table:\r\n+---------+------------+---------------+---------------+\r\n| user_id | session_id | activity_date | activity_type |\r\n+---------+------------+---------------+---------------+\r\n| 1       | 1          | 2019-07-20    | open_session  |\r\n| 1       | 1          | 2019-07-20    | scroll_down   |\r\n| 1       | 1          | 2019-07-20    | end_session   |\r\n| 2       | 4          | 2019-07-20    | open_session  |\r\n| 2       | 4          | 2019-07-21    | send_message  |\r\n| 2       | 4          | 2019-07-21    | end_session   |\r\n| 3       | 2          | 2019-07-21    | open_session  |\r\n| 3       | 2          | 2019-07-21    | send_message  |\r\n| 3       | 2          | 2019-07-21    | end_session   |\r\n| 3       | 5          | 2019-07-21    | open_session  |\r\n| 3       | 5          | 2019-07-21    | scroll_down   |\r\n| 3       | 5          | 2019-07-21    | end_session   |\r\n| 4       | 3          | 2019-06-25    | open_session  |\r\n| 4       | 3          | 2019-06-25    | end_session   |\r\n+---------+------------+---------------+---------------+\r\n\r\nResult table:\r\n+---------------------------+ \r\n| average_sessions_per_user |\r\n+---------------------------+ \r\n| 1.33                      |\r\n+---------------------------+ \r\nUser 1 and 2 each had 1 session in the past 30 days while user 3 had 2 sessions so the average is (1 + 1 + 2) / 3 = 1.33.
    ", "content_cn": "

    Table: Activity

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| user_id       | int     |\n| session_id    | int     |\n| activity_date | date    |\n| activity_type | enum    |\n+---------------+---------+\n\u8be5\u8868\u6ca1\u6709\u4e3b\u952e\uff0c\u5b83\u53ef\u80fd\u6709\u91cd\u590d\u7684\u884c\u3002\nactivity_type \u5217\u662f ENUM\uff08\u201c open_session\u201d\uff0c\u201c end_session\u201d\uff0c\u201c scroll_down\u201d\uff0c\u201c send_message\u201d\uff09\u4e2d\u7684\u67d0\u4e00\u7c7b\u578b\u3002\n\u8be5\u8868\u663e\u793a\u4e86\u793e\u4ea4\u5a92\u4f53\u7f51\u7ad9\u7684\u7528\u6237\u6d3b\u52a8\u3002\n\u8bf7\u6ce8\u610f\uff0c\u6bcf\u4e2a\u4f1a\u8bdd\u5b8c\u5168\u5c5e\u4e8e\u4e00\u4e2a\u7528\u6237\u3002
    \n\n

    \u00a0

    \n\n

    \u7f16\u5199SQL\u67e5\u8be2\u4ee5\u67e5\u627e\u622a\u81f32019\u5e747\u670827\u65e5\uff08\u542b\uff09\u768430\u5929\u5185\u6bcf\u4e2a\u7528\u6237\u7684\u5e73\u5747\u4f1a\u8bdd\u6570\uff0c\u56db\u820d\u4e94\u5165\u5230\u5c0f\u6570\u70b9\u540e\u4e24\u4f4d\u3002\u6211\u4eec\u53ea\u7edf\u8ba1\u90a3\u4e9b\u4f1a\u8bdd\u671f\u95f4\u7528\u6237\u81f3\u5c11\u8fdb\u884c\u4e00\u9879\u6d3b\u52a8\u7684\u6709\u6548\u4f1a\u8bdd\u3002

    \n\n

    \u00a0

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a\uff1a

    \n\n
    \nActivity table:\n+---------+------------+---------------+---------------+\n| user_id | session_id | activity_date | activity_type |\n+---------+------------+---------------+---------------+\n| 1       | 1          | 2019-07-20    | open_session  |\n| 1       | 1          | 2019-07-20    | scroll_down   |\n| 1       | 1          | 2019-07-20    | end_session   |\n| 2       | 4          | 2019-07-20    | open_session  |\n| 2       | 4          | 2019-07-21    | send_message  |\n| 2       | 4          | 2019-07-21    | end_session   |\n| 3       | 2          | 2019-07-21    | open_session  |\n| 3       | 2          | 2019-07-21    | send_message  |\n| 3       | 2          | 2019-07-21    | end_session   |\n| 3       | 5          | 2019-07-21    | open_session  |\n| 3       | 5          | 2019-07-21    | scroll_down   |\n| 3       | 5          | 2019-07-21    | end_session   |\n| 4       | 3          | 2019-06-25    | open_session  |\n| 4       | 3          | 2019-06-25    | end_session   |\n+---------+------------+---------------+---------------+\n\nResult table:\n+---------------------------+ \n| average_sessions_per_user |\n+---------------------------+ \n| 1.33                      |\n+---------------------------+ \nUser 1 \u548c 2 \u5728\u8fc7\u53bb30\u5929\u5185\u5404\u81ea\u8fdb\u884c\u4e861\u6b21\u4f1a\u8bdd\uff0c\u800c\u7528\u62373\u8fdb\u884c\u4e862\u6b21\u4f1a\u8bdd\uff0c\u56e0\u6b64\u5e73\u5747\u503c\u4e3a\uff081 +1 + 2\uff09/ 3 = 1.33\u3002
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1142](https://leetcode-cn.com/problems/user-activity-for-the-past-30-days-ii)", "[\u8fc7\u53bb30\u5929\u7684\u7528\u6237\u6d3b\u52a8 II](/solution/1100-1199/1142.User%20Activity%20for%20the%20Past%2030%20Days%20II/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1142](https://leetcode.com/problems/user-activity-for-the-past-30-days-ii)", "[User Activity for the Past 30 Days II](/solution/1100-1199/1142.User%20Activity%20for%20the%20Past%2030%20Days%20II/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1245", "frontend_question_id": "1141", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/user-activity-for-the-past-30-days-i", "url_en": "https://leetcode.com/problems/user-activity-for-the-past-30-days-i", "relative_path_cn": "/solution/1100-1199/1141.User%20Activity%20for%20the%20Past%2030%20Days%20I/README.md", "relative_path_en": "/solution/1100-1199/1141.User%20Activity%20for%20the%20Past%2030%20Days%20I/README_EN.md", "title_cn": "\u67e5\u8be2\u8fd130\u5929\u6d3b\u8dc3\u7528\u6237\u6570", "title_en": "User Activity for the Past 30 Days I", "question_title_slug": "user-activity-for-the-past-30-days-i", "content_en": "

    Table: Activity

    \r\n\r\n
    \r\n+---------------+---------+\r\n| Column Name   | Type    |\r\n+---------------+---------+\r\n| user_id       | int     |\r\n| session_id    | int     |\r\n| activity_date | date    |\r\n| activity_type | enum    |\r\n+---------------+---------+\r\nThere is no primary key for this table, it may have duplicate rows.\r\nThe activity_type column is an ENUM of type ('open_session', 'end_session', 'scroll_down', 'send_message').\r\nThe table shows the user activities for a social media website. \r\nNote that each session belongs to exactly one user.\r\n
    \r\n\r\n

     

    \r\n\r\n

    Write an SQL query to find the daily active user count for a period of 30 days ending 2019-07-27 inclusively. A user was active on some day if he/she made at least one activity on that day.

    \r\n\r\n

    The query result format is in the following example:

    \r\n\r\n
    \r\nActivity table:\r\n+---------+------------+---------------+---------------+\r\n| user_id | session_id | activity_date | activity_type |\r\n+---------+------------+---------------+---------------+\r\n| 1       | 1          | 2019-07-20    | open_session  |\r\n| 1       | 1          | 2019-07-20    | scroll_down   |\r\n| 1       | 1          | 2019-07-20    | end_session   |\r\n| 2       | 4          | 2019-07-20    | open_session  |\r\n| 2       | 4          | 2019-07-21    | send_message  |\r\n| 2       | 4          | 2019-07-21    | end_session   |\r\n| 3       | 2          | 2019-07-21    | open_session  |\r\n| 3       | 2          | 2019-07-21    | send_message  |\r\n| 3       | 2          | 2019-07-21    | end_session   |\r\n| 4       | 3          | 2019-06-25    | open_session  |\r\n| 4       | 3          | 2019-06-25    | end_session   |\r\n+---------+------------+---------------+---------------+\r\n\r\nResult table:\r\n+------------+--------------+ \r\n| day        | active_users |\r\n+------------+--------------+ \r\n| 2019-07-20 | 2            |\r\n| 2019-07-21 | 2            |\r\n+------------+--------------+ \r\nNote that we do not care about days with zero active users.\r\n
    ", "content_cn": "

    \u6d3b\u52a8\u8bb0\u5f55\u8868\uff1aActivity

    \n\n
    +---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| user_id       | int     |\n| session_id    | int     |\n| activity_date | date    |\n| activity_type | enum    |\n+---------------+---------+\n\u8be5\u8868\u662f\u7528\u6237\u5728\u793e\u4ea4\u7f51\u7ad9\u7684\u6d3b\u52a8\u8bb0\u5f55\u3002\n\u8be5\u8868\u6ca1\u6709\u4e3b\u952e\uff0c\u53ef\u80fd\u5305\u542b\u91cd\u590d\u6570\u636e\u3002\nactivity_type \u5b57\u6bb5\u4e3a\u4ee5\u4e0b\u56db\u79cd\u503c ('open_session', 'end_session', 'scroll_down', 'send_message')\u3002\n\u6bcf\u4e2a session_id \u53ea\u5c5e\u4e8e\u4e00\u4e2a\u7528\u6237\u3002\n
    \n\n

     

    \n\n

    \u8bf7\u5199SQL\u67e5\u8be2\u51fa\u622a\u81f3 2019-07-27\uff08\u5305\u542b2019-07-27\uff09\uff0c\u8fd1 30\u5929\u7684\u6bcf\u65e5\u6d3b\u8dc3\u7528\u6237\u6570\uff08\u5f53\u5929\u53ea\u8981\u6709\u4e00\u6761\u6d3b\u52a8\u8bb0\u5f55\uff0c\u5373\u4e3a\u6d3b\u8dc3\u7528\u6237\uff09\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u793a\u4f8b\u5982\u4e0b\uff1a

    \n\n
    Activity table:\n+---------+------------+---------------+---------------+\n| user_id | session_id | activity_date | activity_type |\n+---------+------------+---------------+---------------+\n| 1       | 1          | 2019-07-20    | open_session  |\n| 1       | 1          | 2019-07-20    | scroll_down   |\n| 1       | 1          | 2019-07-20    | end_session   |\n| 2       | 4          | 2019-07-20    | open_session  |\n| 2       | 4          | 2019-07-21    | send_message  |\n| 2       | 4          | 2019-07-21    | end_session   |\n| 3       | 2          | 2019-07-21    | open_session  |\n| 3       | 2          | 2019-07-21    | send_message  |\n| 3       | 2          | 2019-07-21    | end_session   |\n| 4       | 3          | 2019-06-25    | open_session  |\n| 4       | 3          | 2019-06-25    | end_session   |\n+---------+------------+---------------+---------------+\n\nResult table:\n+------------+--------------+ \n| day        | active_users |\n+------------+--------------+ \n| 2019-07-20 | 2            |\n| 2019-07-21 | 2            |\n+------------+--------------+ \n\u975e\u6d3b\u8dc3\u7528\u6237\u7684\u8bb0\u5f55\u4e0d\u9700\u8981\u5c55\u793a\u3002
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1141](https://leetcode-cn.com/problems/user-activity-for-the-past-30-days-i)", "[\u67e5\u8be2\u8fd130\u5929\u6d3b\u8dc3\u7528\u6237\u6570](/solution/1100-1199/1141.User%20Activity%20for%20the%20Past%2030%20Days%20I/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1141](https://leetcode.com/problems/user-activity-for-the-past-30-days-i)", "[User Activity for the Past 30 Days I](/solution/1100-1199/1141.User%20Activity%20for%20the%20Past%2030%20Days%20I/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1244", "frontend_question_id": "1316", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/distinct-echo-substrings", "url_en": "https://leetcode.com/problems/distinct-echo-substrings", "relative_path_cn": "/solution/1300-1399/1316.Distinct%20Echo%20Substrings/README.md", "relative_path_en": "/solution/1300-1399/1316.Distinct%20Echo%20Substrings/README_EN.md", "title_cn": "\u4e0d\u540c\u7684\u5faa\u73af\u5b50\u5b57\u7b26\u4e32", "title_en": "Distinct Echo Substrings", "question_title_slug": "distinct-echo-substrings", "content_en": "

    Return the number of distinct non-empty substrings of text that can be written as the concatenation of some string with itself (i.e. it can be written as a + a where a is some string).

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: text = "abcabcabc"\nOutput: 3\nExplanation: The 3 substrings are "abcabc", "bcabca" and "cabcab".\n
    \n\n

    Example 2:

    \n\n
    \nInput: text = "leetcodeleetcode"\nOutput: 2\nExplanation: The 2 substrings are "ee" and "leetcodeleetcode".\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= text.length <= 2000
    • \n\t
    • text has only lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 text \uff0c\u8bf7\u4f60\u8fd4\u56de\u6ee1\u8db3\u4e0b\u8ff0\u6761\u4ef6\u7684 \u4e0d\u540c \u975e\u7a7a\u5b50\u5b57\u7b26\u4e32\u7684\u6570\u76ee\uff1a

    \n\n
      \n\t
    • \u53ef\u4ee5\u5199\u6210\u67d0\u4e2a\u5b57\u7b26\u4e32\u4e0e\u5176\u81ea\u8eab\u76f8\u8fde\u63a5\u7684\u5f62\u5f0f\uff08\u5373\uff0c\u53ef\u4ee5\u5199\u4e3a a + a\uff0c\u5176\u4e2d a \u662f\u67d0\u4e2a\u5b57\u7b26\u4e32\uff09\u3002
    • \n
    \n\n

    \u4f8b\u5982\uff0cabcabc \u5c31\u662f abc \u548c\u5b83\u81ea\u8eab\u8fde\u63a5\u5f62\u6210\u7684\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1atext = "abcabcabc"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a3 \u4e2a\u5b50\u5b57\u7b26\u4e32\u5206\u522b\u4e3a "abcabc"\uff0c"bcabca" \u548c "cabcab" \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1atext = "leetcodeleetcode"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a2 \u4e2a\u5b50\u5b57\u7b26\u4e32\u4e3a "ee" \u548c "leetcodeleetcode" \u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= text.length <= 2000
    • \n\t
    • text \u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int distinctEchoSubstrings(string text) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int distinctEchoSubstrings(String text) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def distinctEchoSubstrings(self, text):\n \"\"\"\n :type text: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def distinctEchoSubstrings(self, text: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint distinctEchoSubstrings(char * text){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int DistinctEchoSubstrings(string text) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} text\n * @return {number}\n */\nvar distinctEchoSubstrings = function(text) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} text\n# @return {Integer}\ndef distinct_echo_substrings(text)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func distinctEchoSubstrings(_ text: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func distinctEchoSubstrings(text string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def distinctEchoSubstrings(text: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun distinctEchoSubstrings(text: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn distinct_echo_substrings(text: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $text\n * @return Integer\n */\n function distinctEchoSubstrings($text) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function distinctEchoSubstrings(text: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (distinct-echo-substrings text)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1316](https://leetcode-cn.com/problems/distinct-echo-substrings)", "[\u4e0d\u540c\u7684\u5faa\u73af\u5b50\u5b57\u7b26\u4e32](/solution/1300-1399/1316.Distinct%20Echo%20Substrings/README.md)", "`\u5b57\u7b26\u4e32`", "\u56f0\u96be", ""], "md_table_row_en": ["[1316](https://leetcode.com/problems/distinct-echo-substrings)", "[Distinct Echo Substrings](/solution/1300-1399/1316.Distinct%20Echo%20Substrings/README_EN.md)", "`String`", "Hard", ""]}, {"question_id": "1243", "frontend_question_id": "1315", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sum-of-nodes-with-even-valued-grandparent", "url_en": "https://leetcode.com/problems/sum-of-nodes-with-even-valued-grandparent", "relative_path_cn": "/solution/1300-1399/1315.Sum%20of%20Nodes%20with%20Even-Valued%20Grandparent/README.md", "relative_path_en": "/solution/1300-1399/1315.Sum%20of%20Nodes%20with%20Even-Valued%20Grandparent/README_EN.md", "title_cn": "\u7956\u7236\u8282\u70b9\u503c\u4e3a\u5076\u6570\u7684\u8282\u70b9\u548c", "title_en": "Sum of Nodes with Even-Valued Grandparent", "question_title_slug": "sum-of-nodes-with-even-valued-grandparent", "content_en": "

    Given a binary tree, return the sum of values of nodes with even-valued grandparent.  (A grandparent of a node is the parent of its parent, if it exists.)

    \r\n\r\n

    If there are no nodes with an even-valued grandparent, return 0.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n

    \"\"

    \r\n\r\n
    \r\nInput: root = [6,7,8,2,7,1,3,9,null,1,4,null,null,null,5]\r\nOutput: 18\r\nExplanation: The red nodes are the nodes with even-value grandparent while the blue nodes are the even-value grandparents.\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • The number of nodes in the tree is between 1 and 10^4.
    • \r\n\t
    • The value of nodes is between 1 and 100.
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u68f5\u4e8c\u53c9\u6811\uff0c\u8bf7\u4f60\u8fd4\u56de\u6ee1\u8db3\u4ee5\u4e0b\u6761\u4ef6\u7684\u6240\u6709\u8282\u70b9\u7684\u503c\u4e4b\u548c\uff1a

    \n\n
      \n\t
    • \u8be5\u8282\u70b9\u7684\u7956\u7236\u8282\u70b9\u7684\u503c\u4e3a\u5076\u6570\u3002\uff08\u4e00\u4e2a\u8282\u70b9\u7684\u7956\u7236\u8282\u70b9\u662f\u6307\u8be5\u8282\u70b9\u7684\u7236\u8282\u70b9\u7684\u7236\u8282\u70b9\u3002\uff09
    • \n
    \n\n

    \u5982\u679c\u4e0d\u5b58\u5728\u7956\u7236\u8282\u70b9\u503c\u4e3a\u5076\u6570\u7684\u8282\u70b9\uff0c\u90a3\u4e48\u8fd4\u56de 0 \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1aroot = [6,7,8,2,7,1,3,9,null,1,4,null,null,null,5]\n\u8f93\u51fa\uff1a18\n\u89e3\u91ca\uff1a\u56fe\u4e2d\u7ea2\u8272\u8282\u70b9\u7684\u7956\u7236\u8282\u70b9\u7684\u503c\u4e3a\u5076\u6570\uff0c\u84dd\u8272\u8282\u70b9\u4e3a\u8fd9\u4e9b\u7ea2\u8272\u8282\u70b9\u7684\u7956\u7236\u8282\u70b9\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u7684\u6570\u76ee\u5728 1 \u5230 10^4 \u4e4b\u95f4\u3002
    • \n\t
    • \u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u5728 1 \u5230 100 \u4e4b\u95f4\u3002
    • \n
    \n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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 */\nclass Solution {\npublic:\n int sumEvenGrandparent(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode(int x) { val = x; }\n * }\n */\nclass Solution {\n public int sumEvenGrandparent(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution(object):\n def sumEvenGrandparent(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution:\n def sumEvenGrandparent(self, root: TreeNode) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint sumEvenGrandparent(struct TreeNode* root){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int x) { val = x; }\n * }\n */\npublic class Solution {\n public int SumEvenGrandparent(TreeNode root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val) {\n * this.val = val;\n * this.left = this.right = null;\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar sumEvenGrandparent = function(root) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val)\n# @val = val\n# @left, @right = nil, nil\n# end\n# end\n\n# @param {TreeNode} root\n# @return {Integer}\ndef sum_even_grandparent(root)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.left = nil\n * self.right = nil\n * }\n * }\n */\nclass Solution {\n func sumEvenGrandparent(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc sumEvenGrandparent(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(var _value: Int) {\n * var value: Int = _value\n * var left: TreeNode = null\n * var right: TreeNode = null\n * }\n */\nobject Solution {\n def sumEvenGrandparent(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun sumEvenGrandparent(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n// \n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn sum_even_grandparent(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($value) { $this->val = $value; }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function sumEvenGrandparent($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction sumEvenGrandparent(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (sum-even-grandparent root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1315](https://leetcode-cn.com/problems/sum-of-nodes-with-even-valued-grandparent)", "[\u7956\u7236\u8282\u70b9\u503c\u4e3a\u5076\u6570\u7684\u8282\u70b9\u548c](/solution/1300-1399/1315.Sum%20of%20Nodes%20with%20Even-Valued%20Grandparent/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1315](https://leetcode.com/problems/sum-of-nodes-with-even-valued-grandparent)", "[Sum of Nodes with Even-Valued Grandparent](/solution/1300-1399/1315.Sum%20of%20Nodes%20with%20Even-Valued%20Grandparent/README_EN.md)", "`Tree`,`Depth-first Search`", "Medium", ""]}, {"question_id": "1242", "frontend_question_id": "1314", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/matrix-block-sum", "url_en": "https://leetcode.com/problems/matrix-block-sum", "relative_path_cn": "/solution/1300-1399/1314.Matrix%20Block%20Sum/README.md", "relative_path_en": "/solution/1300-1399/1314.Matrix%20Block%20Sum/README_EN.md", "title_cn": "\u77e9\u9635\u533a\u57df\u548c", "title_en": "Matrix Block Sum", "question_title_slug": "matrix-block-sum", "content_en": "

    Given a m x n matrix mat and an integer k, return a matrix answer where each answer[i][j] is the sum of all elements mat[r][c] for:

    \n\n
      \n\t
    • i - k <= r <= i + k,
    • \n\t
    • j - k <= c <= j + k, and
    • \n\t
    • (r, c) is a valid position in the matrix.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: mat = [[1,2,3],[4,5,6],[7,8,9]], k = 1\nOutput: [[12,21,16],[27,45,33],[24,39,28]]\n
    \n\n

    Example 2:

    \n\n
    \nInput: mat = [[1,2,3],[4,5,6],[7,8,9]], k = 2\nOutput: [[45,45,45],[45,45,45],[45,45,45]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == mat.length
    • \n\t
    • n == mat[i].length
    • \n\t
    • 1 <= m, n, k <= 100
    • \n\t
    • 1 <= mat[i][j] <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u00a0m x n\u00a0\u7684\u77e9\u9635\u00a0mat\u00a0\u548c\u4e00\u4e2a\u6574\u6570 k \uff0c\u8bf7\u4f60\u8fd4\u56de\u4e00\u4e2a\u77e9\u9635\u00a0answer\u00a0\uff0c\u5176\u4e2d\u6bcf\u4e2a\u00a0answer[i][j]\u00a0\u662f\u6240\u6709\u6ee1\u8db3\u4e0b\u8ff0\u6761\u4ef6\u7684\u5143\u7d20\u00a0mat[r][c] \u7684\u548c\uff1a\u00a0

    \n\n
      \n\t
    • i - k <= r <= i + k,
    • \n\t
    • j - k <= c <= j + k \u4e14
    • \n\t
    • (r, c)\u00a0\u5728\u77e9\u9635\u5185\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1amat = [[1,2,3],[4,5,6],[7,8,9]], k = 1\n\u8f93\u51fa\uff1a[[12,21,16],[27,45,33],[24,39,28]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1amat = [[1,2,3],[4,5,6],[7,8,9]], k = 2\n\u8f93\u51fa\uff1a[[45,45,45],[45,45,45],[45,45,45]]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m ==\u00a0mat.length
    • \n\t
    • n ==\u00a0mat[i].length
    • \n\t
    • 1 <= m, n, k <= 100
    • \n\t
    • 1 <= mat[i][j] <= 100
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> matrixBlockSum(vector>& mat, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[][] matrixBlockSum(int[][] mat, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def matrixBlockSum(self, mat, k):\n \"\"\"\n :type mat: List[List[int]]\n :type k: int\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def matrixBlockSum(self, mat: List[List[int]], k: int) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** matrixBlockSum(int** mat, int matSize, int* matColSize, int k, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[][] MatrixBlockSum(int[][] mat, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} mat\n * @param {number} k\n * @return {number[][]}\n */\nvar matrixBlockSum = function(mat, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} mat\n# @param {Integer} k\n# @return {Integer[][]}\ndef matrix_block_sum(mat, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func matrixBlockSum(_ mat: [[Int]], _ k: Int) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func matrixBlockSum(mat [][]int, k int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def matrixBlockSum(mat: Array[Array[Int]], k: Int): Array[Array[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun matrixBlockSum(mat: Array, k: Int): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn matrix_block_sum(mat: Vec>, k: i32) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $mat\n * @param Integer $k\n * @return Integer[][]\n */\n function matrixBlockSum($mat, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function matrixBlockSum(mat: number[][], k: number): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (matrix-block-sum mat k)\n (-> (listof (listof exact-integer?)) exact-integer? (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1314](https://leetcode-cn.com/problems/matrix-block-sum)", "[\u77e9\u9635\u533a\u57df\u548c](/solution/1300-1399/1314.Matrix%20Block%20Sum/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1314](https://leetcode.com/problems/matrix-block-sum)", "[Matrix Block Sum](/solution/1300-1399/1314.Matrix%20Block%20Sum/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "1241", "frontend_question_id": "1313", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/decompress-run-length-encoded-list", "url_en": "https://leetcode.com/problems/decompress-run-length-encoded-list", "relative_path_cn": "/solution/1300-1399/1313.Decompress%20Run-Length%20Encoded%20List/README.md", "relative_path_en": "/solution/1300-1399/1313.Decompress%20Run-Length%20Encoded%20List/README_EN.md", "title_cn": "\u89e3\u538b\u7f29\u7f16\u7801\u5217\u8868", "title_en": "Decompress Run-Length Encoded List", "question_title_slug": "decompress-run-length-encoded-list", "content_en": "

    We are given a list nums of integers representing a list compressed with run-length encoding.

    \n\n

    Consider each adjacent pair of elements [freq, val] = [nums[2*i], nums[2*i+1]] (with i >= 0).  For each such pair, there are freq elements with value val concatenated in a sublist. Concatenate all the sublists from left to right to generate the decompressed list.

    \n\n

    Return the decompressed list.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,3,4]\nOutput: [2,4,4,4]\nExplanation: The first pair [1,2] means we have freq = 1 and val = 2 so we generate the array [2].\nThe second pair [3,4] means we have freq = 3 and val = 4 so we generate [4,4,4].\nAt the end the concatenation [2] + [4,4,4] is [2,4,4,4].\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,1,2,3]\nOutput: [1,3,3]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= nums.length <= 100
    • \n\t
    • nums.length % 2 == 0
    • \n\t
    • 1 <= nums[i] <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u4ee5\u884c\u7a0b\u957f\u5ea6\u7f16\u7801\u538b\u7f29\u7684\u6574\u6570\u5217\u8868\u00a0nums\u00a0\u3002

    \n\n

    \u8003\u8651\u6bcf\u5bf9\u76f8\u90bb\u7684\u4e24\u4e2a\u5143\u7d20 [freq, val] = [nums[2*i], nums[2*i+1]]\u00a0\uff08\u5176\u4e2d\u00a0i >= 0\u00a0\uff09\uff0c\u6bcf\u4e00\u5bf9\u90fd\u8868\u793a\u89e3\u538b\u540e\u5b50\u5217\u8868\u4e2d\u6709 freq\u00a0\u4e2a\u503c\u4e3a\u00a0val\u00a0\u7684\u5143\u7d20\uff0c\u4f60\u9700\u8981\u4ece\u5de6\u5230\u53f3\u8fde\u63a5\u6240\u6709\u5b50\u5217\u8868\u4ee5\u751f\u6210\u89e3\u538b\u540e\u7684\u5217\u8868\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u89e3\u538b\u540e\u7684\u5217\u8868\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,3,4]\n\u8f93\u51fa\uff1a[2,4,4,4]\n\u89e3\u91ca\uff1a\u7b2c\u4e00\u5bf9 [1,2] \u4ee3\u8868\u7740 2 \u7684\u51fa\u73b0\u9891\u6b21\u4e3a 1\uff0c\u6240\u4ee5\u751f\u6210\u6570\u7ec4 [2]\u3002\n\u7b2c\u4e8c\u5bf9 [3,4] \u4ee3\u8868\u7740 4 \u7684\u51fa\u73b0\u9891\u6b21\u4e3a 3\uff0c\u6240\u4ee5\u751f\u6210\u6570\u7ec4 [4,4,4]\u3002\n\u6700\u540e\u5c06\u5b83\u4eec\u4e32\u8054\u5230\u4e00\u8d77 [2] + [4,4,4] = [2,4,4,4]\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,1,2,3]\n\u8f93\u51fa\uff1a[1,3,3]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= nums.length <= 100
    • \n\t
    • nums.length % 2 == 0
    • \n\t
    • 1 <= nums[i] <= 100
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector decompressRLElist(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] decompressRLElist(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def decompressRLElist(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def decompressRLElist(self, nums: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* decompressRLElist(int* nums, int numsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] DecompressRLElist(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar decompressRLElist = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer[]}\ndef decompress_rl_elist(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func decompressRLElist(_ nums: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func decompressRLElist(nums []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def decompressRLElist(nums: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun decompressRLElist(nums: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn decompress_rl_elist(nums: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer[]\n */\n function decompressRLElist($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function decompressRLElist(nums: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (decompress-rl-elist nums)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1313](https://leetcode-cn.com/problems/decompress-run-length-encoded-list)", "[\u89e3\u538b\u7f29\u7f16\u7801\u5217\u8868](/solution/1300-1399/1313.Decompress%20Run-Length%20Encoded%20List/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1313](https://leetcode.com/problems/decompress-run-length-encoded-list)", "[Decompress Run-Length Encoded List](/solution/1300-1399/1313.Decompress%20Run-Length%20Encoded%20List/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1240", "frontend_question_id": "1140", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/stone-game-ii", "url_en": "https://leetcode.com/problems/stone-game-ii", "relative_path_cn": "/solution/1100-1199/1140.Stone%20Game%20II/README.md", "relative_path_en": "/solution/1100-1199/1140.Stone%20Game%20II/README_EN.md", "title_cn": "\u77f3\u5b50\u6e38\u620f II", "title_en": "Stone Game II", "question_title_slug": "stone-game-ii", "content_en": "

    Alice and Bob continue their games with piles of stones.  There are a number of piles arranged in a row, and each pile has a positive integer number of stones piles[i].  The objective of the game is to end with the most stones. 

    \n\n

    Alice and Bob take turns, with Alice starting first.  Initially, M = 1.

    \n\n

    On each player's turn, that player can take all the stones in the first X remaining piles, where 1 <= X <= 2M.  Then, we set M = max(M, X).

    \n\n

    The game continues until all the stones have been taken.

    \n\n

    Assuming Alice and Bob play optimally, return the maximum number of stones Alice can get.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: piles = [2,7,9,4,4]\nOutput: 10\nExplanation:  If Alice takes one pile at the beginning, Bob takes two piles, then Alice takes 2 piles again. Alice can get 2 + 4 + 4 = 10 piles in total. If Alice takes two piles at the beginning, then Bob can take all three piles left. In this case, Alice get 2 + 7 = 9 piles in total. So we return 10 since it's larger. \n
    \n\n

    Example 2:

    \n\n
    \nInput: piles = [1,2,3,4,5,100]\nOutput: 104\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= piles.length <= 100
    • \n\t
    • 1 <= piles[i] <= 104
    • \n
    \n", "content_cn": "

    \u4e9a\u5386\u514b\u65af\u548c\u674e\u7ee7\u7eed\u4ed6\u4eec\u7684\u77f3\u5b50\u6e38\u620f\u3002\u8bb8\u591a\u5806\u77f3\u5b50 \u6392\u6210\u4e00\u884c\uff0c\u6bcf\u5806\u90fd\u6709\u6b63\u6574\u6570\u9897\u77f3\u5b50 piles[i]\u3002\u6e38\u620f\u4ee5\u8c01\u624b\u4e2d\u7684\u77f3\u5b50\u6700\u591a\u6765\u51b3\u51fa\u80dc\u8d1f\u3002

    \n\n

    \u4e9a\u5386\u514b\u65af\u548c\u674e\u8f6e\u6d41\u8fdb\u884c\uff0c\u4e9a\u5386\u514b\u65af\u5148\u5f00\u59cb\u3002\u6700\u521d\uff0cM = 1\u3002

    \n\n

    \u5728\u6bcf\u4e2a\u73a9\u5bb6\u7684\u56de\u5408\u4e2d\uff0c\u8be5\u73a9\u5bb6\u53ef\u4ee5\u62ff\u8d70\u5269\u4e0b\u7684 \u524d X \u5806\u7684\u6240\u6709\u77f3\u5b50\uff0c\u5176\u4e2d 1 <= X <= 2M\u3002\u7136\u540e\uff0c\u4ee4 M = max(M, X)\u3002

    \n\n

    \u6e38\u620f\u4e00\u76f4\u6301\u7eed\u5230\u6240\u6709\u77f3\u5b50\u90fd\u88ab\u62ff\u8d70\u3002

    \n\n

    \u5047\u8bbe\u4e9a\u5386\u514b\u65af\u548c\u674e\u90fd\u53d1\u6325\u51fa\u6700\u4f73\u6c34\u5e73\uff0c\u8fd4\u56de\u4e9a\u5386\u514b\u65af\u53ef\u4ee5\u5f97\u5230\u7684\u6700\u5927\u6570\u91cf\u7684\u77f3\u5934\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1apiles = [2,7,9,4,4]\n\u8f93\u51fa\uff1a10\n\u89e3\u91ca\uff1a\n\u5982\u679c\u4e9a\u5386\u514b\u65af\u5728\u5f00\u59cb\u65f6\u62ff\u8d70\u4e00\u5806\u77f3\u5b50\uff0c\u674e\u62ff\u8d70\u4e24\u5806\uff0c\u63a5\u7740\u4e9a\u5386\u514b\u65af\u4e5f\u62ff\u8d70\u4e24\u5806\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u4e9a\u5386\u514b\u65af\u53ef\u4ee5\u62ff\u5230 2 + 4 + 4 = 10 \u9897\u77f3\u5b50\u3002 \n\u5982\u679c\u4e9a\u5386\u514b\u65af\u5728\u5f00\u59cb\u65f6\u62ff\u8d70\u4e24\u5806\u77f3\u5b50\uff0c\u90a3\u4e48\u674e\u5c31\u53ef\u4ee5\u62ff\u8d70\u5269\u4e0b\u5168\u90e8\u4e09\u5806\u77f3\u5b50\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u4e9a\u5386\u514b\u65af\u53ef\u4ee5\u62ff\u5230 2 + 7 = 9 \u9897\u77f3\u5b50\u3002\n\u6240\u4ee5\u6211\u4eec\u8fd4\u56de\u66f4\u5927\u7684 10\u3002 \n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= piles.length <= 100
    • \n\t
    • 1 <= piles[i] <= 10 ^ 4
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int stoneGameII(vector& piles) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int stoneGameII(int[] piles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def stoneGameII(self, piles):\n \"\"\"\n :type piles: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def stoneGameII(self, piles: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint stoneGameII(int* piles, int pilesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int StoneGameII(int[] piles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} piles\n * @return {number}\n */\nvar stoneGameII = function(piles) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} piles\n# @return {Integer}\ndef stone_game_ii(piles)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func stoneGameII(_ piles: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func stoneGameII(piles []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def stoneGameII(piles: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun stoneGameII(piles: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn stone_game_ii(piles: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $piles\n * @return Integer\n */\n function stoneGameII($piles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function stoneGameII(piles: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (stone-game-ii piles)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1140](https://leetcode-cn.com/problems/stone-game-ii)", "[\u77f3\u5b50\u6e38\u620f II](/solution/1100-1199/1140.Stone%20Game%20II/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1140](https://leetcode.com/problems/stone-game-ii)", "[Stone Game II](/solution/1100-1199/1140.Stone%20Game%20II/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "1239", "frontend_question_id": "1139", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/largest-1-bordered-square", "url_en": "https://leetcode.com/problems/largest-1-bordered-square", "relative_path_cn": "/solution/1100-1199/1139.Largest%201-Bordered%20Square/README.md", "relative_path_en": "/solution/1100-1199/1139.Largest%201-Bordered%20Square/README_EN.md", "title_cn": "\u6700\u5927\u7684\u4ee5 1 \u4e3a\u8fb9\u754c\u7684\u6b63\u65b9\u5f62", "title_en": "Largest 1-Bordered Square", "question_title_slug": "largest-1-bordered-square", "content_en": "

    Given a 2D grid of 0s and 1s, return the number of elements in the largest square subgrid that has all 1s on its border, or 0 if such a subgrid doesn't exist in the grid.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: grid = [[1,1,1],[1,0,1],[1,1,1]]\r\nOutput: 9\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: grid = [[1,1,0,0]]\r\nOutput: 1\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= grid.length <= 100
    • \r\n\t
    • 1 <= grid[0].length <= 100
    • \r\n\t
    • grid[i][j] is 0 or 1
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u7531\u82e5\u5e72 0 \u548c 1 \u7ec4\u6210\u7684\u4e8c\u7ef4\u7f51\u683c grid\uff0c\u8bf7\u4f60\u627e\u51fa\u8fb9\u754c\u5168\u90e8\u7531 1 \u7ec4\u6210\u7684\u6700\u5927 \u6b63\u65b9\u5f62 \u5b50\u7f51\u683c\uff0c\u5e76\u8fd4\u56de\u8be5\u5b50\u7f51\u683c\u4e2d\u7684\u5143\u7d20\u6570\u91cf\u3002\u5982\u679c\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de 0\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1agrid = [[1,1,1],[1,0,1],[1,1,1]]\n\u8f93\u51fa\uff1a9\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1agrid = [[1,1,0,0]]\n\u8f93\u51fa\uff1a1\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= grid.length <= 100
    • \n\t
    • 1 <= grid[0].length <= 100
    • \n\t
    • grid[i][j] \u4e3a 0 \u6216 1
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int largest1BorderedSquare(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int largest1BorderedSquare(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def largest1BorderedSquare(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def largest1BorderedSquare(self, grid: List[List[int]]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint largest1BorderedSquare(int** grid, int gridSize, int* gridColSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int Largest1BorderedSquare(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar largest1BorderedSquare = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef largest1_bordered_square(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func largest1BorderedSquare(_ grid: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func largest1BorderedSquare(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def largest1BorderedSquare(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun largest1BorderedSquare(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn largest1_bordered_square(grid: Vec>) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function largest1BorderedSquare($grid) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function largest1BorderedSquare(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (largest1-bordered-square grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1139](https://leetcode-cn.com/problems/largest-1-bordered-square)", "[\u6700\u5927\u7684\u4ee5 1 \u4e3a\u8fb9\u754c\u7684\u6b63\u65b9\u5f62](/solution/1100-1199/1139.Largest%201-Bordered%20Square/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1139](https://leetcode.com/problems/largest-1-bordered-square)", "[Largest 1-Bordered Square](/solution/1100-1199/1139.Largest%201-Bordered%20Square/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "1238", "frontend_question_id": "1138", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/alphabet-board-path", "url_en": "https://leetcode.com/problems/alphabet-board-path", "relative_path_cn": "/solution/1100-1199/1138.Alphabet%20Board%20Path/README.md", "relative_path_en": "/solution/1100-1199/1138.Alphabet%20Board%20Path/README_EN.md", "title_cn": "\u5b57\u6bcd\u677f\u4e0a\u7684\u8def\u5f84", "title_en": "Alphabet Board Path", "question_title_slug": "alphabet-board-path", "content_en": "

    On an alphabet board, we start at position (0, 0), corresponding to character board[0][0].

    \r\n\r\n

    Here, board = ["abcde", "fghij", "klmno", "pqrst", "uvwxy", "z"], as shown in the diagram below.

    \r\n\r\n

    \"\"

    \r\n\r\n

    We may make the following moves:

    \r\n\r\n
      \r\n\t
    • 'U' moves our position up one row, if the position exists on the board;
    • \r\n\t
    • 'D' moves our position down one row, if the position exists on the board;
    • \r\n\t
    • 'L' moves our position left one column, if the position exists on the board;
    • \r\n\t
    • 'R' moves our position right one column, if the position exists on the board;
    • \r\n\t
    • '!' adds the character board[r][c] at our current position (r, c) to the answer.
    • \r\n
    \r\n\r\n

    (Here, the only positions that exist on the board are positions with letters on them.)

    \r\n\r\n

    Return a sequence of moves that makes our answer equal to target in the minimum number of moves.  You may return any path that does so.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n
    Input: target = \"leet\"\r\nOutput: \"DDR!UURRR!!DDD!\"\r\n

    Example 2:

    \r\n
    Input: target = \"code\"\r\nOutput: \"RR!DDRR!UUL!R!\"\r\n
    \r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= target.length <= 100
    • \r\n\t
    • target consists only of English lowercase letters.
    • \r\n
    ", "content_cn": "

    \u6211\u4eec\u4ece\u4e00\u5757\u5b57\u6bcd\u677f\u4e0a\u7684\u4f4d\u7f6e (0, 0) \u51fa\u53d1\uff0c\u8be5\u5750\u6807\u5bf9\u5e94\u7684\u5b57\u7b26\u4e3a board[0][0]\u3002

    \n\n

    \u5728\u672c\u9898\u91cc\uff0c\u5b57\u6bcd\u677f\u4e3aboard = ["abcde", "fghij", "klmno", "pqrst", "uvwxy", "z"]\uff0c\u5982\u4e0b\u6240\u793a\u3002

    \n\n

    \"\"

    \n\n

    \u6211\u4eec\u53ef\u4ee5\u6309\u4e0b\u9762\u7684\u6307\u4ee4\u89c4\u5219\u884c\u52a8\uff1a

    \n\n
      \n\t
    • \u5982\u679c\u65b9\u683c\u5b58\u5728\uff0c'U' \u610f\u5473\u7740\u5c06\u6211\u4eec\u7684\u4f4d\u7f6e\u4e0a\u79fb\u4e00\u884c\uff1b
    • \n\t
    • \u5982\u679c\u65b9\u683c\u5b58\u5728\uff0c'D' \u610f\u5473\u7740\u5c06\u6211\u4eec\u7684\u4f4d\u7f6e\u4e0b\u79fb\u4e00\u884c\uff1b
    • \n\t
    • \u5982\u679c\u65b9\u683c\u5b58\u5728\uff0c'L' \u610f\u5473\u7740\u5c06\u6211\u4eec\u7684\u4f4d\u7f6e\u5de6\u79fb\u4e00\u5217\uff1b
    • \n\t
    • \u5982\u679c\u65b9\u683c\u5b58\u5728\uff0c'R' \u610f\u5473\u7740\u5c06\u6211\u4eec\u7684\u4f4d\u7f6e\u53f3\u79fb\u4e00\u5217\uff1b
    • \n\t
    • '!' \u4f1a\u628a\u5728\u6211\u4eec\u5f53\u524d\u4f4d\u7f6e (r, c) \u7684\u5b57\u7b26 board[r][c] \u6dfb\u52a0\u5230\u7b54\u6848\u4e2d\u3002
    • \n
    \n\n

    \uff08\u6ce8\u610f\uff0c\u5b57\u6bcd\u677f\u4e0a\u53ea\u5b58\u5728\u6709\u5b57\u6bcd\u7684\u4f4d\u7f6e\u3002\uff09

    \n\n

    \u8fd4\u56de\u6307\u4ee4\u5e8f\u5217\uff0c\u7528\u6700\u5c0f\u7684\u884c\u52a8\u6b21\u6570\u8ba9\u7b54\u6848\u548c\u76ee\u6807 target \u76f8\u540c\u3002\u4f60\u53ef\u4ee5\u8fd4\u56de\u4efb\u4f55\u8fbe\u6210\u76ee\u6807\u7684\u8def\u5f84\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1atarget = "leet"\n\u8f93\u51fa\uff1a"DDR!UURRR!!DDD!"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1atarget = "code"\n\u8f93\u51fa\uff1a"RR!DDRR!UUL!R!"\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= target.length <= 100
    • \n\t
    • target \u4ec5\u542b\u6709\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    • \n
    \n", "tags_en": ["Hash Table", "String"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string alphabetBoardPath(string target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String alphabetBoardPath(String target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def alphabetBoardPath(self, target):\n \"\"\"\n :type target: str\n :rtype: str\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def alphabetBoardPath(self, target: str) -> str:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * alphabetBoardPath(char * target){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string AlphabetBoardPath(string target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} target\n * @return {string}\n */\nvar alphabetBoardPath = function(target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} target\n# @return {String}\ndef alphabet_board_path(target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func alphabetBoardPath(_ target: String) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func alphabetBoardPath(target string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def alphabetBoardPath(target: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun alphabetBoardPath(target: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn alphabet_board_path(target: String) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $target\n * @return String\n */\n function alphabetBoardPath($target) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function alphabetBoardPath(target: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (alphabet-board-path target)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1138](https://leetcode-cn.com/problems/alphabet-board-path)", "[\u5b57\u6bcd\u677f\u4e0a\u7684\u8def\u5f84](/solution/1100-1199/1138.Alphabet%20Board%20Path/README.md)", "`\u54c8\u5e0c\u8868`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1138](https://leetcode.com/problems/alphabet-board-path)", "[Alphabet Board Path](/solution/1100-1199/1138.Alphabet%20Board%20Path/README_EN.md)", "`Hash Table`,`String`", "Medium", ""]}, {"question_id": "1237", "frontend_question_id": "1132", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/reported-posts-ii", "url_en": "https://leetcode.com/problems/reported-posts-ii", "relative_path_cn": "/solution/1100-1199/1132.Reported%20Posts%20II/README.md", "relative_path_en": "/solution/1100-1199/1132.Reported%20Posts%20II/README_EN.md", "title_cn": "\u62a5\u544a\u7684\u8bb0\u5f55 II", "title_en": "Reported Posts II", "question_title_slug": "reported-posts-ii", "content_en": "

    Table: Actions

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| user_id       | int     |\n| post_id       | int     |\n| action_date   | date    |\n| action        | enum    |\n| extra         | varchar |\n+---------------+---------+\nThere is no primary key for this table, it may have duplicate rows.\nThe action column is an ENUM type of ('view', 'like', 'reaction', 'comment', 'report', 'share').\nThe extra column has optional information about the action such as a reason for report or a type of reaction. 
    \n\n

    Table: Removals

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| post_id       | int     |\n| remove_date   | date    | \n+---------------+---------+\npost_id is the primary key of this table.\nEach row in this table indicates that some post was removed as a result of being reported or as a result of an admin review.\n
    \n\n

     

    \n\n

    Write an SQL query to find the average for daily percentage of posts that got removed after being reported as spam, rounded to 2 decimal places.

    \n\n

    The query result format is in the following example:

    \n\n
    \nActions table:\n+---------+---------+-------------+--------+--------+\n| user_id | post_id | action_date | action | extra  |\n+---------+---------+-------------+--------+--------+\n| 1       | 1       | 2019-07-01  | view   | null   |\n| 1       | 1       | 2019-07-01  | like   | null   |\n| 1       | 1       | 2019-07-01  | share  | null   |\n| 2       | 2       | 2019-07-04  | view   | null   |\n| 2       | 2       | 2019-07-04  | report | spam   |\n| 3       | 4       | 2019-07-04  | view   | null   |\n| 3       | 4       | 2019-07-04  | report | spam   |\n| 4       | 3       | 2019-07-02  | view   | null   |\n| 4       | 3       | 2019-07-02  | report | spam   |\n| 5       | 2       | 2019-07-03  | view   | null   |\n| 5       | 2       | 2019-07-03  | report | racism |\n| 5       | 5       | 2019-07-03  | view   | null   |\n| 5       | 5       | 2019-07-03  | report | racism |\n+---------+---------+-------------+--------+--------+\n\nRemovals table:\n+---------+-------------+\n| post_id | remove_date |\n+---------+-------------+\n| 2       | 2019-07-20  |\n| 3       | 2019-07-18  |\n+---------+-------------+\n\nResult table:\n+-----------------------+\n| average_daily_percent |\n+-----------------------+\n| 75.00                 |\n+-----------------------+\nThe percentage for 2019-07-04 is 50% because only one post of two spam reported posts was removed.\nThe percentage for 2019-07-02 is 100% because one post was reported as spam and it was removed.\nThe other days had no spam reports so the average is (50 + 100) / 2 = 75%\nNote that the output is only one number and that we do not care about the remove dates.
    \n", "content_cn": "

    \u52a8\u4f5c\u8868\uff1a Actions

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| user_id       | int     |\n| post_id       | int     |\n| action_date   | date    |\n| action        | enum    |\n| extra         | varchar |\n+---------------+---------+\n\u8fd9\u5f20\u8868\u6ca1\u6709\u4e3b\u952e\uff0c\u5e76\u6709\u53ef\u80fd\u5b58\u5728\u91cd\u590d\u7684\u884c\u3002\naction \u5217\u7684\u7c7b\u578b\u662f ENUM\uff0c\u53ef\u80fd\u7684\u503c\u4e3a ('view', 'like', 'reaction', 'comment', 'report', 'share')\u3002\nextra \u5217\u62e5\u6709\u4e00\u4e9b\u53ef\u9009\u4fe1\u606f\uff0c\u4f8b\u5982\uff1a\u62a5\u544a\u7406\u7531\uff08a reason for report\uff09\u6216\u53cd\u5e94\u7c7b\u578b\uff08a type of reaction\uff09\u7b49\u3002
    \n\n

    \u79fb\u9664\u8868\uff1a Removals

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| post_id       | int     |\n| remove_date   | date    | \n+---------------+---------+\n\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\u662f post_id\u3002\n\u8fd9\u5f20\u8868\u7684\u6bcf\u4e00\u884c\u8868\u793a\u4e00\u4e2a\u88ab\u79fb\u9664\u7684\u5e16\u5b50\uff0c\u539f\u56e0\u53ef\u80fd\u662f\u7531\u4e8e\u88ab\u4e3e\u62a5\u6216\u88ab\u7ba1\u7406\u5458\u5ba1\u67e5\u3002\n
    \n\n

     

    \n\n

    \u7f16\u5199\u4e00\u6bb5 SQL \u6765\u67e5\u627e\uff1a\u5728\u88ab\u62a5\u544a\u4e3a\u5783\u573e\u5e7f\u544a\u7684\u5e16\u5b50\u4e2d\uff0c\u88ab\u79fb\u9664\u7684\u5e16\u5b50\u7684\u6bcf\u65e5\u5e73\u5747\u5360\u6bd4\uff0c\u56db\u820d\u4e94\u5165\u5230\u5c0f\u6570\u70b9\u540e 2 \u4f4d\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u7684\u683c\u5f0f\u5982\u4e0b\uff1a

    \n\n
    \nActions table:\n+---------+---------+-------------+--------+--------+\n| user_id | post_id | action_date | action | extra  |\n+---------+---------+-------------+--------+--------+\n| 1       | 1       | 2019-07-01  | view   | null   |\n| 1       | 1       | 2019-07-01  | like   | null   |\n| 1       | 1       | 2019-07-01  | share  | null   |\n| 2       | 2       | 2019-07-04  | view   | null   |\n| 2       | 2       | 2019-07-04  | report | spam   |\n| 3       | 4       | 2019-07-04  | view   | null   |\n| 3       | 4       | 2019-07-04  | report | spam   |\n| 4       | 3       | 2019-07-02  | view   | null   |\n| 4       | 3       | 2019-07-02  | report | spam   |\n| 5       | 2       | 2019-07-03  | view   | null   |\n| 5       | 2       | 2019-07-03  | report | racism |\n| 5       | 5       | 2019-07-03  | view   | null   |\n| 5       | 5       | 2019-07-03  | report | racism |\n+---------+---------+-------------+--------+--------+\n\nRemovals table:\n+---------+-------------+\n| post_id | remove_date |\n+---------+-------------+\n| 2       | 2019-07-20  |\n| 3       | 2019-07-18  |\n+---------+-------------+\n\nResult table:\n+-----------------------+\n| average_daily_percent |\n+-----------------------+\n| 75.00                 |\n+-----------------------+\n2019-07-04 \u7684\u5783\u573e\u5e7f\u544a\u79fb\u9664\u7387\u662f 50%\uff0c\u56e0\u4e3a\u6709\u4e24\u5f20\u5e16\u5b50\u88ab\u62a5\u544a\u4e3a\u5783\u573e\u5e7f\u544a\uff0c\u4f46\u53ea\u6709\u4e00\u4e2a\u5f97\u5230\u79fb\u9664\u3002\n2019-07-02 \u7684\u5783\u573e\u5e7f\u544a\u79fb\u9664\u7387\u662f 100%\uff0c\u56e0\u4e3a\u6709\u4e00\u5f20\u5e16\u5b50\u88ab\u4e3e\u62a5\u4e3a\u5783\u573e\u5e7f\u544a\u5e76\u5f97\u5230\u79fb\u9664\u3002\n\u5176\u4f59\u51e0\u5929\u6ca1\u6709\u6536\u5230\u5783\u573e\u5e7f\u544a\u7684\u4e3e\u62a5\uff0c\u56e0\u6b64\u5e73\u5747\u503c\u4e3a\uff1a(50 + 100) / 2 = 75%\n\u6ce8\u610f\uff0c\u8f93\u51fa\u4ec5\u9700\u8981\u4e00\u4e2a\u5e73\u5747\u503c\u5373\u53ef\uff0c\u6211\u4eec\u5e76\u4e0d\u5173\u6ce8\u79fb\u9664\u64cd\u4f5c\u7684\u65e5\u671f\u3002
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1132](https://leetcode-cn.com/problems/reported-posts-ii)", "[\u62a5\u544a\u7684\u8bb0\u5f55 II](/solution/1100-1199/1132.Reported%20Posts%20II/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1132](https://leetcode.com/problems/reported-posts-ii)", "[Reported Posts II](/solution/1100-1199/1132.Reported%20Posts%20II/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1236", "frontend_question_id": "1137", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/n-th-tribonacci-number", "url_en": "https://leetcode.com/problems/n-th-tribonacci-number", "relative_path_cn": "/solution/1100-1199/1137.N-th%20Tribonacci%20Number/README.md", "relative_path_en": "/solution/1100-1199/1137.N-th%20Tribonacci%20Number/README_EN.md", "title_cn": "\u7b2c N \u4e2a\u6cf0\u6ce2\u90a3\u5951\u6570", "title_en": "N-th Tribonacci Number", "question_title_slug": "n-th-tribonacci-number", "content_en": "

    The Tribonacci sequence Tn is defined as follows: 

    \r\n\r\n

    T0 = 0, T1 = 1, T2 = 1, and Tn+3 = Tn + Tn+1 + Tn+2 for n >= 0.

    \r\n\r\n

    Given n, return the value of Tn.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: n = 4\r\nOutput: 4\r\nExplanation:\r\nT_3 = 0 + 1 + 1 = 2\r\nT_4 = 1 + 1 + 2 = 4\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: n = 25\r\nOutput: 1389537\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 0 <= n <= 37
    • \r\n\t
    • The answer is guaranteed to fit within a 32-bit integer, ie. answer <= 2^31 - 1.
    • \r\n
    ", "content_cn": "

    \u6cf0\u6ce2\u90a3\u5951\u5e8f\u5217 Tn \u5b9a\u4e49\u5982\u4e0b\uff1a 

    \n\n

    T0 = 0, T1 = 1, T2 = 1, \u4e14\u5728 n >= 0 \u7684\u6761\u4ef6\u4e0b Tn+3 = Tn + Tn+1 + Tn+2

    \n\n

    \u7ed9\u4f60\u6574\u6570 n\uff0c\u8bf7\u8fd4\u56de\u7b2c n \u4e2a\u6cf0\u6ce2\u90a3\u5951\u6570 Tn \u7684\u503c\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1an = 4\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\nT_3 = 0 + 1 + 1 = 2\nT_4 = 1 + 1 + 2 = 4\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1an = 25\n\u8f93\u51fa\uff1a1389537\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= n <= 37
    • \n\t
    • \u7b54\u6848\u4fdd\u8bc1\u662f\u4e00\u4e2a 32 \u4f4d\u6574\u6570\uff0c\u5373 answer <= 2^31 - 1\u3002
    • \n
    \n", "tags_en": ["Recursion"], "tags_cn": ["\u9012\u5f52"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int tribonacci(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int tribonacci(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def tribonacci(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def tribonacci(self, n: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint tribonacci(int n){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int Tribonacci(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar tribonacci = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef tribonacci(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func tribonacci(_ n: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func tribonacci(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def tribonacci(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun tribonacci(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn tribonacci(n: i32) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function tribonacci($n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function tribonacci(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (tribonacci n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1137](https://leetcode-cn.com/problems/n-th-tribonacci-number)", "[\u7b2c N \u4e2a\u6cf0\u6ce2\u90a3\u5951\u6570](/solution/1100-1199/1137.N-th%20Tribonacci%20Number/README.md)", "`\u9012\u5f52`", "\u7b80\u5355", ""], "md_table_row_en": ["[1137](https://leetcode.com/problems/n-th-tribonacci-number)", "[N-th Tribonacci Number](/solution/1100-1199/1137.N-th%20Tribonacci%20Number/README_EN.md)", "`Recursion`", "Easy", ""]}, {"question_id": "1234", "frontend_question_id": "1301", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-paths-with-max-score", "url_en": "https://leetcode.com/problems/number-of-paths-with-max-score", "relative_path_cn": "/solution/1300-1399/1301.Number%20of%20Paths%20with%20Max%20Score/README.md", "relative_path_en": "/solution/1300-1399/1301.Number%20of%20Paths%20with%20Max%20Score/README_EN.md", "title_cn": "\u6700\u5927\u5f97\u5206\u7684\u8def\u5f84\u6570\u76ee", "title_en": "Number of Paths with Max Score", "question_title_slug": "number-of-paths-with-max-score", "content_en": "

    You are given a square board of characters. You can move on the board starting at the bottom right square marked with the character 'S'.

    \r\n\r\n

    You need to reach the top left square marked with the character 'E'. The rest of the squares are labeled either with a numeric character 1, 2, ..., 9 or with an obstacle 'X'. In one move you can go up, left or up-left (diagonally) only if there is no obstacle there.

    \r\n\r\n

    Return a list of two integers: the first integer is the maximum sum of numeric characters you can collect, and the second is the number of such paths that you can take to get that maximum sum, taken modulo 10^9 + 7.

    \r\n\r\n

    In case there is no path, return [0, 0].

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n
    Input: board = [\"E23\",\"2X2\",\"12S\"]\r\nOutput: [7,1]\r\n

    Example 2:

    \r\n
    Input: board = [\"E12\",\"1X1\",\"21S\"]\r\nOutput: [4,2]\r\n

    Example 3:

    \r\n
    Input: board = [\"E11\",\"XXX\",\"11S\"]\r\nOutput: [0,0]\r\n
    \r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 2 <= board.length == board[i].length <= 100
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6b63\u65b9\u5f62\u5b57\u7b26\u6570\u7ec4 board \uff0c\u4f60\u4ece\u6570\u7ec4\u6700\u53f3\u4e0b\u65b9\u7684\u5b57\u7b26 'S' \u51fa\u53d1\u3002

    \n\n

    \u4f60\u7684\u76ee\u6807\u662f\u5230\u8fbe\u6570\u7ec4\u6700\u5de6\u4e0a\u89d2\u7684\u5b57\u7b26 'E' \uff0c\u6570\u7ec4\u5269\u4f59\u7684\u90e8\u5206\u4e3a\u6570\u5b57\u5b57\u7b26 1, 2, ..., 9 \u6216\u8005\u969c\u788d 'X'\u3002\u5728\u6bcf\u4e00\u6b65\u79fb\u52a8\u4e2d\uff0c\u4f60\u53ef\u4ee5\u5411\u4e0a\u3001\u5411\u5de6\u6216\u8005\u5de6\u4e0a\u65b9\u79fb\u52a8\uff0c\u53ef\u4ee5\u79fb\u52a8\u7684\u524d\u63d0\u662f\u5230\u8fbe\u7684\u683c\u5b50\u6ca1\u6709\u969c\u788d\u3002

    \n\n

    \u4e00\u6761\u8def\u5f84\u7684 \u300c\u5f97\u5206\u300d \u5b9a\u4e49\u4e3a\uff1a\u8def\u5f84\u4e0a\u6240\u6709\u6570\u5b57\u7684\u548c\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u4e00\u4e2a\u5217\u8868\uff0c\u5305\u542b\u4e24\u4e2a\u6574\u6570\uff1a\u7b2c\u4e00\u4e2a\u6574\u6570\u662f \u300c\u5f97\u5206\u300d \u7684\u6700\u5927\u503c\uff0c\u7b2c\u4e8c\u4e2a\u6574\u6570\u662f\u5f97\u5230\u6700\u5927\u5f97\u5206\u7684\u65b9\u6848\u6570\uff0c\u8bf7\u628a\u7ed3\u679c\u5bf9 10^9 + 7 \u53d6\u4f59\u3002

    \n\n

    \u5982\u679c\u6ca1\u6709\u4efb\u4f55\u8def\u5f84\u53ef\u4ee5\u5230\u8fbe\u7ec8\u70b9\uff0c\u8bf7\u8fd4\u56de [0, 0] \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aboard = ["E23","2X2","12S"]\n\u8f93\u51fa\uff1a[7,1]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aboard = ["E12","1X1","21S"]\n\u8f93\u51fa\uff1a[4,2]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aboard = ["E11","XXX","11S"]\n\u8f93\u51fa\uff1a[0,0]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= board.length == board[i].length <= 100
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector pathsWithMaxScore(vector& board) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] pathsWithMaxScore(List board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def pathsWithMaxScore(self, board):\n \"\"\"\n :type board: List[str]\n :rtype: List[int]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def pathsWithMaxScore(self, board: List[str]) -> List[int]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* pathsWithMaxScore(char ** board, int boardSize, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] PathsWithMaxScore(IList board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} board\n * @return {number[]}\n */\nvar pathsWithMaxScore = function(board) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} board\n# @return {Integer[]}\ndef paths_with_max_score(board)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func pathsWithMaxScore(_ board: [String]) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func pathsWithMaxScore(board []string) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def pathsWithMaxScore(board: List[String]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun pathsWithMaxScore(board: List): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn paths_with_max_score(board: Vec) -> Vec {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $board\n * @return Integer[]\n */\n function pathsWithMaxScore($board) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function pathsWithMaxScore(board: string[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (paths-with-max-score board)\n (-> (listof string?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1301](https://leetcode-cn.com/problems/number-of-paths-with-max-score)", "[\u6700\u5927\u5f97\u5206\u7684\u8def\u5f84\u6570\u76ee](/solution/1300-1399/1301.Number%20of%20Paths%20with%20Max%20Score/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1301](https://leetcode.com/problems/number-of-paths-with-max-score)", "[Number of Paths with Max Score](/solution/1300-1399/1301.Number%20of%20Paths%20with%20Max%20Score/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1233", "frontend_question_id": "1274", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/number-of-ships-in-a-rectangle", "url_en": "https://leetcode.com/problems/number-of-ships-in-a-rectangle", "relative_path_cn": "/solution/1200-1299/1274.Number%20of%20Ships%20in%20a%20Rectangle/README.md", "relative_path_en": "/solution/1200-1299/1274.Number%20of%20Ships%20in%20a%20Rectangle/README_EN.md", "title_cn": "\u77e9\u5f62\u5185\u8239\u53ea\u7684\u6570\u76ee", "title_en": "Number of Ships in a Rectangle", "question_title_slug": "number-of-ships-in-a-rectangle", "content_en": "

    (This problem is an interactive problem.)

    \n\n

    Each ship is located at an integer point on the sea represented by a cartesian plane, and each integer point may contain at most 1 ship.

    \n\n

    You have a function Sea.hasShips(topRight, bottomLeft) which takes two points as arguments and returns true If there is at least one ship in the rectangle represented by the two points, including on the boundary.

    \n\n

    Given two points: the top right and bottom left corners of a rectangle, return the number of ships present in that rectangle. It is guaranteed that there are at most 10 ships in that rectangle.

    \n\n

    Submissions making more than 400 calls to hasShips will be judged Wrong Answer. Also, any solutions that attempt to circumvent the judge will result in disqualification.

    \n\n

     

    \n

    Example :

    \n\n

    \"\"

    \n\n
    \nInput: \nships = [[1,1],[2,2],[3,3],[5,5]], topRight = [4,4], bottomLeft = [0,0]\nOutput: 3\nExplanation: From [0,0] to [4,4] we can count 3 ships within the range.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • On the input ships is only given to initialize the map internally. You must solve this problem "blindfolded". In other words, you must find the answer using the given hasShips API, without knowing the ships position.
    • \n\t
    • 0 <= bottomLeft[0] <= topRight[0] <= 1000
    • \n\t
    • 0 <= bottomLeft[1] <= topRight[1] <= 1000
    • \n\t
    • topRight != bottomLeft
    • \n
    \n", "content_cn": "

    (\u6b64\u9898\u662f \u4ea4\u4e92\u5f0f\u95ee\u9898 )

    \n\n

    \u5728\u7528\u7b1b\u5361\u5c14\u5750\u6807\u7cfb\u8868\u793a\u7684\u4e8c\u7ef4\u6d77\u5e73\u9762\u4e0a\uff0c\u6709\u4e00\u4e9b\u8239\u3002\u6bcf\u4e00\u8258\u8239\u90fd\u5728\u4e00\u4e2a\u6574\u6570\u70b9\u4e0a\uff0c\u4e14\u6bcf\u4e00\u4e2a\u6574\u6570\u70b9\u6700\u591a\u53ea\u6709 1 \u8258\u8239\u3002

    \n\n

    \u6709\u4e00\u4e2a\u51fd\u6570 Sea.hasShips(topRight, bottomLeft) \uff0c\u8f93\u5165\u53c2\u6570\u4e3a\u53f3\u4e0a\u89d2\u548c\u5de6\u4e0b\u89d2\u4e24\u4e2a\u70b9\u7684\u5750\u6807\uff0c\u5f53\u4e14\u4ec5\u5f53\u8fd9\u4e24\u4e2a\u70b9\u6240\u8868\u793a\u7684\u77e9\u5f62\u533a\u57df\uff08\u5305\u542b\u8fb9\u754c\uff09\u5185\u81f3\u5c11\u6709\u4e00\u8258\u8239\u65f6\uff0c\u8fd9\u4e2a\u51fd\u6570\u624d\u8fd4\u56de true \uff0c\u5426\u5219\u8fd4\u56de false \u3002

    \n\n

    \u7ed9\u4f60\u77e9\u5f62\u7684\u53f3\u4e0a\u89d2 topRight \u548c\u5de6\u4e0b\u89d2 bottomLeft \u7684\u5750\u6807\uff0c\u8bf7\u4f60\u8fd4\u56de\u6b64\u77e9\u5f62\u5185\u8239\u53ea\u7684\u6570\u76ee\u3002\u9898\u76ee\u4fdd\u8bc1\u77e9\u5f62\u5185 \u81f3\u591a\u53ea\u6709 10 \u8258\u8239\u3002

    \n\n

    \u8c03\u7528\u51fd\u6570 hasShips \u8d85\u8fc7400\u6b21 \u7684\u63d0\u4ea4\u5c06\u88ab\u5224\u4e3a \u9519\u8bef\u7b54\u6848\uff08Wrong Answer\uff09 \u3002\u540c\u65f6\uff0c\u4efb\u4f55\u5c1d\u8bd5\u7ed5\u8fc7\u8bc4\u6d4b\u7cfb\u7edf\u7684\u884c\u4e3a\u90fd\u5c06\u88ab\u53d6\u6d88\u6bd4\u8d5b\u8d44\u683c\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1a\nships = [[1,1],[2,2],[3,3],[5,5]], topRight = [4,4], bottomLeft = [0,0]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u5728 [0,0] \u5230 [4,4] \u7684\u8303\u56f4\u5185\u603b\u5171\u6709 3 \u8258\u8239\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • ships \u6570\u7ec4\u53ea\u7528\u4e8e\u8bc4\u6d4b\u7cfb\u7edf\u5185\u90e8\u521d\u59cb\u5316\u3002\u4f60\u65e0\u6cd5\u5f97\u77e5 ships \u7684\u4fe1\u606f\uff0c\u6240\u4ee5\u53ea\u80fd\u901a\u8fc7\u8c03\u7528 hasShips \u63a5\u53e3\u6765\u6c42\u89e3\u3002
    • \n\t
    • 0 <= bottomLeft[0] <= topRight[0] <= 1000
    • \n\t
    • 0 <= bottomLeft[1] <= topRight[1] <= 1000
    • \n
    \n", "tags_en": ["Divide and Conquer"], "tags_cn": ["\u5206\u6cbb\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * // This is Sea's API interface.\n * // You should not implement it, or speculate about its implementation\n * class Sea {\n * public:\n * bool hasShips(vector topRight, vector bottomLeft);\n * };\n */\n\nclass Solution {\npublic:\n int countShips(Sea sea, vector topRight, vector bottomLeft) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * // This is Sea's API interface.\n * // You should not implement it, or speculate about its implementation\n * class Sea {\n * public boolean hasShips(int[] topRight, int[] bottomLeft);\n * }\n */\n\nclass Solution {\n public int countShips(Sea sea, int[] topRight, int[] bottomLeft) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# \"\"\"\n# This is Sea's API interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class Sea(object):\n# def hasShips(self, topRight, bottomLeft):\n# \"\"\"\n# :type topRight: Point\n#\t\t :type bottomLeft: Point\n# :rtype bool\n# \"\"\"\n#\n#class Point(object):\n#\tdef __init__(self, x, y):\n#\t\tself.x = x\n#\t\tself.y = y\n\nclass Solution(object):\n def countShips(self, sea, topRight, bottomLeft):\n \"\"\"\n :type sea: Sea\n :type topRight: Point\n :type bottomLeft: Point\n :rtype: integer\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# \"\"\"\n# This is Sea's API interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class Sea(object):\n# def hasShips(self, topRight: 'Point', bottomLeft: 'Point') -> bool:\n#\n#class Point(object):\n#\tdef __init__(self, x: int, y: int):\n#\t\tself.x = x\n#\t\tself.y = y\n\nclass Solution(object):\n def countShips(self, sea: 'Sea', topRight: 'Point', bottomLeft: 'Point') -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * // The hasShips API is already defined for you.\n * // You should not implement it, or speculate about its implementation\n * bool hasShips(int topRightX, int topRightY, int bottomLeftX, int bottomLeftY);\n */\n\nint countShips(int topRightX, int topRightY, int bottomLeftX, int bottomLeftY) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * // This is Sea's API interface.\n * // You should not implement it, or speculate about its implementation\n * class Sea {\n * public bool HasShips(int[] topRight, int[] bottomLeft);\n * }\n */\n\nclass Solution {\n public int CountShips(Sea sea, int[] topRight, int[] bottomLeft) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // This is Sea's API interface.\n * // You should not implement it, or speculate about its implementation\n * function Sea() {\n * @param {integer[]} topRight\n * @param {integer[]} bottomLeft\n * @return {boolean}\n * this.hasShips = function(topRight, bottomLeft) {\n * ...\n * };\n * };\n */\n\n/**\n * @param {Sea} sea\n * @param {integer[]} topRight\n * @param {integer[]} bottomLeft\n * @return {integer}\n */\nvar countShips = function(sea, topRight, bottomLeft) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# This is Sea's API interface.\n# You should not implement it, or speculate about its implementation\n# class Sea\n# def hasShips(topRight, bottomLeft)\n#\t\t\n# end\n# end\n\n# @param {Sea} sea\n# @param {List[int]} topRight\n# @param {List[int]} bottomLeft\n# @return {int}\ndef countShips(sea, topRight, bottomLeft)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * // This is Sea's API interface.\n * // You should not implement it, or speculate about its implementation\n * class Sea {\n * public func hasShips(_ topRight: [Int], _ bottomLeft: [Int]) -> Bool {}\n * }\n */\n\nclass Solution {\n func countShips(_ sea: Sea, _ topRight: [Int], _ bottomLeft: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * // This is Sea's API interface.\n * // You should not implement it, or speculate about its implementation\n * type Sea struct {\n * func hasShips(topRight, bottomLeft []int) bool {}\n * }\n */\n\nfunc countShips(sea Sea, topRight, bottomLeft []int) int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * // This is Sea's API interface.\n * // You should not implement it, or speculate about its implementation\n * class Sea {\n * def hasShips(topRight: Array[Int], bottomLeft: Array[Int]): Boolean = {}\n * }\n */\n\nobject Solution {\n def countShips(sea: Sea, topRight: Array[Int], bottomLeft: Array[Int]): Int = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * // This is Sea's API interface.\n * // You should not implement it, or speculate about its implementation\n * class Sea {\n * fun hasShips(topRight: IntArray, bottomLeft: IntArray): Boolean{}\n * }\n */\n\nclass Solution {\n fun countShips(sea: Sea, topRight: IntArray, bottomLeft: IntArray): Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "/**\n * // This is Sea's API interface.\n * // You should not implement it, or speculate about its implementation\n * struct Sea;\n * impl Sea {\n * pub fn hasShips(topRight: Vec,bottomLeft: Vec)->bool{}\n * }\n */\n\nimpl Solution {\n pub fn count_ships(sea: &Sea, topRight: Vec, bottomLeft: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * // This is Sea's API interface.\n * // You should not implement it, or speculate about its implementation\n * class Sea {\n * function hasShips ($topRight, $bottomLeft) {}\n * }\n */\n\nclass Solution {\n /**\n * @param Sea $sea\n * @param Integer[] $topRight\n * @param Integer[] $bottomLeft\n * @return Integer[]\n */\n function countShips ($sea, $topRight, $bottomLeft) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * // This is the Sea's API interface.\n * // You should not implement it, or speculate about its implementation\n * class Sea {\n * hasShips(topRight: number[], bottomLeft: number[]): boolean {}\n * }\n */\n\nfunction countShips(sea: Sea, topRight: number[], bottomLeft: number[]): number {\n\t\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1274](https://leetcode-cn.com/problems/number-of-ships-in-a-rectangle)", "[\u77e9\u5f62\u5185\u8239\u53ea\u7684\u6570\u76ee](/solution/1200-1299/1274.Number%20of%20Ships%20in%20a%20Rectangle/README.md)", "`\u5206\u6cbb\u7b97\u6cd5`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1274](https://leetcode.com/problems/number-of-ships-in-a-rectangle)", "[Number of Ships in a Rectangle](/solution/1200-1299/1274.Number%20of%20Ships%20in%20a%20Rectangle/README_EN.md)", "`Divide and Conquer`", "Hard", "\ud83d\udd12"]}, {"question_id": "1232", "frontend_question_id": "1300", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sum-of-mutated-array-closest-to-target", "url_en": "https://leetcode.com/problems/sum-of-mutated-array-closest-to-target", "relative_path_cn": "/solution/1300-1399/1300.Sum%20of%20Mutated%20Array%20Closest%20to%20Target/README.md", "relative_path_en": "/solution/1300-1399/1300.Sum%20of%20Mutated%20Array%20Closest%20to%20Target/README_EN.md", "title_cn": "\u8f6c\u53d8\u6570\u7ec4\u540e\u6700\u63a5\u8fd1\u76ee\u6807\u503c\u7684\u6570\u7ec4\u548c", "title_en": "Sum of Mutated Array Closest to Target", "question_title_slug": "sum-of-mutated-array-closest-to-target", "content_en": "

    Given an integer array arr and a target value target, return the integer value such that when we change all the integers larger than value in the given array to be equal to value, the sum of the array gets as close as possible (in absolute difference) to target.

    \n\n

    In case of a tie, return the minimum such integer.

    \n\n

    Notice that the answer is not neccesarilly a number from arr.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr = [4,9,3], target = 10\nOutput: 3\nExplanation: When using 3 arr converts to [3, 3, 3] which sums 9 and that's the optimal answer.\n
    \n\n

    Example 2:

    \n\n
    \nInput: arr = [2,3,5], target = 10\nOutput: 5\n
    \n\n

    Example 3:

    \n\n
    \nInput: arr = [60864,25176,27249,21296,20204], target = 56803\nOutput: 11361\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= arr.length <= 104
    • \n\t
    • 1 <= arr[i], target <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr \u548c\u4e00\u4e2a\u76ee\u6807\u503c target \uff0c\u8bf7\u4f60\u8fd4\u56de\u4e00\u4e2a\u6574\u6570 value \uff0c\u4f7f\u5f97\u5c06\u6570\u7ec4\u4e2d\u6240\u6709\u5927\u4e8e value \u7684\u503c\u53d8\u6210 value \u540e\uff0c\u6570\u7ec4\u7684\u548c\u6700\u63a5\u8fd1  target \uff08\u6700\u63a5\u8fd1\u8868\u793a\u4e24\u8005\u4e4b\u5dee\u7684\u7edd\u5bf9\u503c\u6700\u5c0f\uff09\u3002

    \n\n

    \u5982\u679c\u6709\u591a\u79cd\u4f7f\u5f97\u548c\u6700\u63a5\u8fd1 target \u7684\u65b9\u6848\uff0c\u8bf7\u4f60\u8fd4\u56de\u8fd9\u4e9b\u6574\u6570\u4e2d\u7684\u6700\u5c0f\u503c\u3002

    \n\n

    \u8bf7\u6ce8\u610f\uff0c\u7b54\u6848\u4e0d\u4e00\u5b9a\u662f arr \u4e2d\u7684\u6570\u5b57\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [4,9,3], target = 10\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u5f53\u9009\u62e9 value \u4e3a 3 \u65f6\uff0c\u6570\u7ec4\u4f1a\u53d8\u6210 [3, 3, 3]\uff0c\u548c\u4e3a 9 \uff0c\u8fd9\u662f\u6700\u63a5\u8fd1 target \u7684\u65b9\u6848\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [2,3,5], target = 10\n\u8f93\u51fa\uff1a5\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [60864,25176,27249,21296,20204], target = 56803\n\u8f93\u51fa\uff1a11361\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= arr.length <= 10^4
    • \n\t
    • 1 <= arr[i], target <= 10^5
    • \n
    \n", "tags_en": ["Array", "Binary Search"], "tags_cn": ["\u6570\u7ec4", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findBestValue(vector& arr, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findBestValue(int[] arr, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findBestValue(self, arr, target):\n \"\"\"\n :type arr: List[int]\n :type target: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findBestValue(self, arr: List[int], target: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findBestValue(int* arr, int arrSize, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindBestValue(int[] arr, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @param {number} target\n * @return {number}\n */\nvar findBestValue = function(arr, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @param {Integer} target\n# @return {Integer}\ndef find_best_value(arr, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findBestValue(_ arr: [Int], _ target: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findBestValue(arr []int, target int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findBestValue(arr: Array[Int], target: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findBestValue(arr: IntArray, target: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_best_value(arr: Vec, target: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @param Integer $target\n * @return Integer\n */\n function findBestValue($arr, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findBestValue(arr: number[], target: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-best-value arr target)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1300](https://leetcode-cn.com/problems/sum-of-mutated-array-closest-to-target)", "[\u8f6c\u53d8\u6570\u7ec4\u540e\u6700\u63a5\u8fd1\u76ee\u6807\u503c\u7684\u6570\u7ec4\u548c](/solution/1300-1399/1300.Sum%20of%20Mutated%20Array%20Closest%20to%20Target/README.md)", "`\u6570\u7ec4`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1300](https://leetcode.com/problems/sum-of-mutated-array-closest-to-target)", "[Sum of Mutated Array Closest to Target](/solution/1300-1399/1300.Sum%20of%20Mutated%20Array%20Closest%20to%20Target/README_EN.md)", "`Array`,`Binary Search`", "Medium", ""]}, {"question_id": "1231", "frontend_question_id": "1299", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/replace-elements-with-greatest-element-on-right-side", "url_en": "https://leetcode.com/problems/replace-elements-with-greatest-element-on-right-side", "relative_path_cn": "/solution/1200-1299/1299.Replace%20Elements%20with%20Greatest%20Element%20on%20Right%20Side/README.md", "relative_path_en": "/solution/1200-1299/1299.Replace%20Elements%20with%20Greatest%20Element%20on%20Right%20Side/README_EN.md", "title_cn": "\u5c06\u6bcf\u4e2a\u5143\u7d20\u66ff\u6362\u4e3a\u53f3\u4fa7\u6700\u5927\u5143\u7d20", "title_en": "Replace Elements with Greatest Element on Right Side", "question_title_slug": "replace-elements-with-greatest-element-on-right-side", "content_en": "

    Given an array arr, replace every element in that array with the greatest element among the elements to its right, and replace the last element with -1.

    \n\n

    After doing so, return the array.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr = [17,18,5,4,6,1]\nOutput: [18,6,6,6,1,-1]\nExplanation: \n- index 0 --> the greatest element to the right of index 0 is index 1 (18).\n- index 1 --> the greatest element to the right of index 1 is index 4 (6).\n- index 2 --> the greatest element to the right of index 2 is index 4 (6).\n- index 3 --> the greatest element to the right of index 3 is index 4 (6).\n- index 4 --> the greatest element to the right of index 4 is index 5 (1).\n- index 5 --> there are no elements to the right of index 5, so we put -1.\n
    \n\n

    Example 2:

    \n\n
    \nInput: arr = [400]\nOutput: [-1]\nExplanation: There are no elements to the right of index 0.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= arr.length <= 104
    • \n\t
    • 1 <= arr[i] <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4\u00a0arr\u00a0\uff0c\u8bf7\u4f60\u5c06\u6bcf\u4e2a\u5143\u7d20\u7528\u5b83\u53f3\u8fb9\u6700\u5927\u7684\u5143\u7d20\u66ff\u6362\uff0c\u5982\u679c\u662f\u6700\u540e\u4e00\u4e2a\u5143\u7d20\uff0c\u7528\u00a0-1 \u66ff\u6362\u3002

    \n\n

    \u5b8c\u6210\u6240\u6709\u66ff\u6362\u64cd\u4f5c\u540e\uff0c\u8bf7\u4f60\u8fd4\u56de\u8fd9\u4e2a\u6570\u7ec4\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [17,18,5,4,6,1]\n\u8f93\u51fa\uff1a[18,6,6,6,1,-1]\n\u89e3\u91ca\uff1a\n- \u4e0b\u6807 0 \u7684\u5143\u7d20 --> \u53f3\u4fa7\u6700\u5927\u5143\u7d20\u662f\u4e0b\u6807 1 \u7684\u5143\u7d20 (18)\n- \u4e0b\u6807 1 \u7684\u5143\u7d20 --> \u53f3\u4fa7\u6700\u5927\u5143\u7d20\u662f\u4e0b\u6807 4 \u7684\u5143\u7d20 (6)\n- \u4e0b\u6807 2 \u7684\u5143\u7d20 --> \u53f3\u4fa7\u6700\u5927\u5143\u7d20\u662f\u4e0b\u6807 4 \u7684\u5143\u7d20 (6)\n- \u4e0b\u6807 3 \u7684\u5143\u7d20 --> \u53f3\u4fa7\u6700\u5927\u5143\u7d20\u662f\u4e0b\u6807 4 \u7684\u5143\u7d20 (6)\n- \u4e0b\u6807 4 \u7684\u5143\u7d20 --> \u53f3\u4fa7\u6700\u5927\u5143\u7d20\u662f\u4e0b\u6807 5 \u7684\u5143\u7d20 (1)\n- \u4e0b\u6807 5 \u7684\u5143\u7d20 --> \u53f3\u4fa7\u6ca1\u6709\u5176\u4ed6\u5143\u7d20\uff0c\u66ff\u6362\u4e3a -1\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [400]\n\u8f93\u51fa\uff1a[-1]\n\u89e3\u91ca\uff1a\u4e0b\u6807 0 \u7684\u5143\u7d20\u53f3\u4fa7\u6ca1\u6709\u5176\u4ed6\u5143\u7d20\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= arr.length <= 104
    • \n\t
    • 1 <= arr[i] <= 105
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector replaceElements(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] replaceElements(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def replaceElements(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def replaceElements(self, arr: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* replaceElements(int* arr, int arrSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] ReplaceElements(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number[]}\n */\nvar replaceElements = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer[]}\ndef replace_elements(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func replaceElements(_ arr: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func replaceElements(arr []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def replaceElements(arr: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun replaceElements(arr: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn replace_elements(arr: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer[]\n */\n function replaceElements($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function replaceElements(arr: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (replace-elements arr)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1299](https://leetcode-cn.com/problems/replace-elements-with-greatest-element-on-right-side)", "[\u5c06\u6bcf\u4e2a\u5143\u7d20\u66ff\u6362\u4e3a\u53f3\u4fa7\u6700\u5927\u5143\u7d20](/solution/1200-1299/1299.Replace%20Elements%20with%20Greatest%20Element%20on%20Right%20Side/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1299](https://leetcode.com/problems/replace-elements-with-greatest-element-on-right-side)", "[Replace Elements with Greatest Element on Right Side](/solution/1200-1299/1299.Replace%20Elements%20with%20Greatest%20Element%20on%20Right%20Side/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1230", "frontend_question_id": "1131", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-of-absolute-value-expression", "url_en": "https://leetcode.com/problems/maximum-of-absolute-value-expression", "relative_path_cn": "/solution/1100-1199/1131.Maximum%20of%20Absolute%20Value%20Expression/README.md", "relative_path_en": "/solution/1100-1199/1131.Maximum%20of%20Absolute%20Value%20Expression/README_EN.md", "title_cn": "\u7edd\u5bf9\u503c\u8868\u8fbe\u5f0f\u7684\u6700\u5927\u503c", "title_en": "Maximum of Absolute Value Expression", "question_title_slug": "maximum-of-absolute-value-expression", "content_en": "

    Given two arrays of integers with equal lengths, return the maximum value of:

    \r\n\r\n

    |arr1[i] - arr1[j]| + |arr2[i] - arr2[j]| + |i - j|

    \r\n\r\n

    where the maximum is taken over all 0 <= i, j < arr1.length.

    \r\n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr1 = [1,2,3,4], arr2 = [-1,4,5,6]\nOutput: 13\n
    \n\n

    Example 2:

    \n\n
    \nInput: arr1 = [1,-2,-5,0,10], arr2 = [0,-2,-1,-7,-4]\nOutput: 20\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= arr1.length == arr2.length <= 40000
    • \n\t
    • -10^6 <= arr1[i], arr2[i] <= 10^6
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u957f\u5ea6\u76f8\u7b49\u7684\u6574\u6570\u6570\u7ec4\uff0c\u8fd4\u56de\u4e0b\u9762\u8868\u8fbe\u5f0f\u7684\u6700\u5927\u503c\uff1a

    \n\n

    |arr1[i] - arr1[j]| + |arr2[i] - arr2[j]| + |i - j|

    \n\n

    \u5176\u4e2d\u4e0b\u6807 i\uff0cj \u6ee1\u8db3 0 <= i, j < arr1.length\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aarr1 = [1,2,3,4], arr2 = [-1,4,5,6]\n\u8f93\u51fa\uff1a13\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aarr1 = [1,-2,-5,0,10], arr2 = [0,-2,-1,-7,-4]\n\u8f93\u51fa\uff1a20
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= arr1.length == arr2.length <= 40000
    • \n\t
    • -10^6 <= arr1[i], arr2[i] <= 10^6
    • \n
    \n", "tags_en": ["Bit Manipulation", "Math"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxAbsValExpr(vector& arr1, vector& arr2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxAbsValExpr(int[] arr1, int[] arr2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxAbsValExpr(self, arr1, arr2):\n \"\"\"\n :type arr1: List[int]\n :type arr2: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxAbsValExpr(self, arr1: List[int], arr2: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxAbsValExpr(int* arr1, int arr1Size, int* arr2, int arr2Size){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxAbsValExpr(int[] arr1, int[] arr2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr1\n * @param {number[]} arr2\n * @return {number}\n */\nvar maxAbsValExpr = function(arr1, arr2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr1\n# @param {Integer[]} arr2\n# @return {Integer}\ndef max_abs_val_expr(arr1, arr2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxAbsValExpr(_ arr1: [Int], _ arr2: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxAbsValExpr(arr1 []int, arr2 []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxAbsValExpr(arr1: Array[Int], arr2: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxAbsValExpr(arr1: IntArray, arr2: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_abs_val_expr(arr1: Vec, arr2: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr1\n * @param Integer[] $arr2\n * @return Integer\n */\n function maxAbsValExpr($arr1, $arr2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxAbsValExpr(arr1: number[], arr2: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-abs-val-expr arr1 arr2)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1131](https://leetcode-cn.com/problems/maximum-of-absolute-value-expression)", "[\u7edd\u5bf9\u503c\u8868\u8fbe\u5f0f\u7684\u6700\u5927\u503c](/solution/1100-1199/1131.Maximum%20of%20Absolute%20Value%20Expression/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1131](https://leetcode.com/problems/maximum-of-absolute-value-expression)", "[Maximum of Absolute Value Expression](/solution/1100-1199/1131.Maximum%20of%20Absolute%20Value%20Expression/README_EN.md)", "`Bit Manipulation`,`Math`", "Medium", ""]}, {"question_id": "1229", "frontend_question_id": "1129", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/shortest-path-with-alternating-colors", "url_en": "https://leetcode.com/problems/shortest-path-with-alternating-colors", "relative_path_cn": "/solution/1100-1199/1129.Shortest%20Path%20with%20Alternating%20Colors/README.md", "relative_path_en": "/solution/1100-1199/1129.Shortest%20Path%20with%20Alternating%20Colors/README_EN.md", "title_cn": "\u989c\u8272\u4ea4\u66ff\u7684\u6700\u77ed\u8def\u5f84", "title_en": "Shortest Path with Alternating Colors", "question_title_slug": "shortest-path-with-alternating-colors", "content_en": "

    Consider a directed graph, with nodes labelled 0, 1, ..., n-1.  In this graph, each edge is either red or blue, and there could be self-edges or parallel edges.

    \r\n\r\n

    Each [i, j] in red_edges denotes a red directed edge from node i to node j.  Similarly, each [i, j] in blue_edges denotes a blue directed edge from node i to node j.

    \r\n\r\n

    Return an array answer of length n, where each answer[X] is the length of the shortest path from node 0 to node X such that the edge colors alternate along the path (or -1 if such a path doesn't exist).

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n
    Input: n = 3, red_edges = [[0,1],[1,2]], blue_edges = []\r\nOutput: [0,1,-1]\r\n

    Example 2:

    \r\n
    Input: n = 3, red_edges = [[0,1]], blue_edges = [[2,1]]\r\nOutput: [0,1,-1]\r\n

    Example 3:

    \r\n
    Input: n = 3, red_edges = [[1,0]], blue_edges = [[2,1]]\r\nOutput: [0,-1,-1]\r\n

    Example 4:

    \r\n
    Input: n = 3, red_edges = [[0,1]], blue_edges = [[1,2]]\r\nOutput: [0,1,2]\r\n

    Example 5:

    \r\n
    Input: n = 3, red_edges = [[0,1],[0,2]], blue_edges = [[1,0]]\r\nOutput: [0,1,1]\r\n
    \r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= n <= 100
    • \r\n\t
    • red_edges.length <= 400
    • \r\n\t
    • blue_edges.length <= 400
    • \r\n\t
    • red_edges[i].length == blue_edges[i].length == 2
    • \r\n\t
    • 0 <= red_edges[i][j], blue_edges[i][j] < n
    • \r\n
    ", "content_cn": "

    \u5728\u4e00\u4e2a\u6709\u5411\u56fe\u4e2d\uff0c\u8282\u70b9\u5206\u522b\u6807\u8bb0\u4e3a 0, 1, ..., n-1\u3002\u8fd9\u4e2a\u56fe\u4e2d\u7684\u6bcf\u6761\u8fb9\u4e0d\u662f\u7ea2\u8272\u5c31\u662f\u84dd\u8272\uff0c\u4e14\u5b58\u5728\u81ea\u73af\u6216\u5e73\u884c\u8fb9\u3002

    \n\n

    red_edges \u4e2d\u7684\u6bcf\u4e00\u4e2a [i, j] \u5bf9\u8868\u793a\u4ece\u8282\u70b9 i \u5230\u8282\u70b9 j \u7684\u7ea2\u8272\u6709\u5411\u8fb9\u3002\u7c7b\u4f3c\u5730\uff0cblue_edges \u4e2d\u7684\u6bcf\u4e00\u4e2a [i, j] \u5bf9\u8868\u793a\u4ece\u8282\u70b9 i \u5230\u8282\u70b9 j \u7684\u84dd\u8272\u6709\u5411\u8fb9\u3002

    \n\n

    \u8fd4\u56de\u957f\u5ea6\u4e3a n \u7684\u6570\u7ec4 answer\uff0c\u5176\u4e2d answer[X] \u662f\u4ece\u8282\u70b9 0 \u5230\u8282\u70b9 X \u7684\u7ea2\u8272\u8fb9\u548c\u84dd\u8272\u8fb9\u4ea4\u66ff\u51fa\u73b0\u7684\u6700\u77ed\u8def\u5f84\u7684\u957f\u5ea6\u3002\u5982\u679c\u4e0d\u5b58\u5728\u8fd9\u6837\u7684\u8def\u5f84\uff0c\u90a3\u4e48 answer[x] = -1\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1an = 3, red_edges = [[0,1],[1,2]], blue_edges = []\n\u8f93\u51fa\uff1a[0,1,-1]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1an = 3, red_edges = [[0,1]], blue_edges = [[2,1]]\n\u8f93\u51fa\uff1a[0,1,-1]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1an = 3, red_edges = [[1,0]], blue_edges = [[2,1]]\n\u8f93\u51fa\uff1a[0,-1,-1]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1an = 3, red_edges = [[0,1]], blue_edges = [[1,2]]\n\u8f93\u51fa\uff1a[0,1,2]\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1an = 3, red_edges = [[0,1],[0,2]], blue_edges = [[1,0]]\n\u8f93\u51fa\uff1a[0,1,1]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 100
    • \n\t
    • red_edges.length <= 400
    • \n\t
    • blue_edges.length <= 400
    • \n\t
    • red_edges[i].length == blue_edges[i].length == 2
    • \n\t
    • 0 <= red_edges[i][j], blue_edges[i][j] < n
    • \n
    \n", "tags_en": ["Breadth-first Search", "Graph"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector shortestAlternatingPaths(int n, vector>& red_edges, vector>& blue_edges) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] shortestAlternatingPaths(int n, int[][] red_edges, int[][] blue_edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def shortestAlternatingPaths(self, n, red_edges, blue_edges):\n \"\"\"\n :type n: int\n :type red_edges: List[List[int]]\n :type blue_edges: List[List[int]]\n :rtype: List[int]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def shortestAlternatingPaths(self, n: int, red_edges: List[List[int]], blue_edges: List[List[int]]) -> List[int]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* shortestAlternatingPaths(int n, int** red_edges, int red_edgesSize, int* red_edgesColSize, int** blue_edges, int blue_edgesSize, int* blue_edgesColSize, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] ShortestAlternatingPaths(int n, int[][] red_edges, int[][] blue_edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} red_edges\n * @param {number[][]} blue_edges\n * @return {number[]}\n */\nvar shortestAlternatingPaths = function(n, red_edges, blue_edges) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} red_edges\n# @param {Integer[][]} blue_edges\n# @return {Integer[]}\ndef shortest_alternating_paths(n, red_edges, blue_edges)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func shortestAlternatingPaths(_ n: Int, _ red_edges: [[Int]], _ blue_edges: [[Int]]) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func shortestAlternatingPaths(n int, red_edges [][]int, blue_edges [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def shortestAlternatingPaths(n: Int, red_edges: Array[Array[Int]], blue_edges: Array[Array[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun shortestAlternatingPaths(n: Int, red_edges: Array, blue_edges: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn shortest_alternating_paths(n: i32, red_edges: Vec>, blue_edges: Vec>) -> Vec {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $red_edges\n * @param Integer[][] $blue_edges\n * @return Integer[]\n */\n function shortestAlternatingPaths($n, $red_edges, $blue_edges) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function shortestAlternatingPaths(n: number, red_edges: number[][], blue_edges: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (shortest-alternating-paths n red_edges blue_edges)\n (-> exact-integer? (listof (listof exact-integer?)) (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1129](https://leetcode-cn.com/problems/shortest-path-with-alternating-colors)", "[\u989c\u8272\u4ea4\u66ff\u7684\u6700\u77ed\u8def\u5f84](/solution/1100-1199/1129.Shortest%20Path%20with%20Alternating%20Colors/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u56fe`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1129](https://leetcode.com/problems/shortest-path-with-alternating-colors)", "[Shortest Path with Alternating Colors](/solution/1100-1199/1129.Shortest%20Path%20with%20Alternating%20Colors/README_EN.md)", "`Breadth-first Search`,`Graph`", "Medium", ""]}, {"question_id": "1228", "frontend_question_id": "1130", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-cost-tree-from-leaf-values", "url_en": "https://leetcode.com/problems/minimum-cost-tree-from-leaf-values", "relative_path_cn": "/solution/1100-1199/1130.Minimum%20Cost%20Tree%20From%20Leaf%20Values/README.md", "relative_path_en": "/solution/1100-1199/1130.Minimum%20Cost%20Tree%20From%20Leaf%20Values/README_EN.md", "title_cn": "\u53f6\u503c\u7684\u6700\u5c0f\u4ee3\u4ef7\u751f\u6210\u6811", "title_en": "Minimum Cost Tree From Leaf Values", "question_title_slug": "minimum-cost-tree-from-leaf-values", "content_en": "

    Given an array arr of positive integers, consider all binary trees such that:

    \r\n\r\n
      \r\n\t
    • Each node has either 0 or 2 children;
    • \r\n\t
    • The values of arr correspond to the values of each leaf in an in-order traversal of the tree.  (Recall that a node is a leaf if and only if it has 0 children.)
    • \r\n\t
    • The value of each non-leaf node is equal to the product of the largest leaf value in its left and right subtree respectively.
    • \r\n
    \r\n\r\n

    Among all possible binary trees considered, return the smallest possible sum of the values of each non-leaf node.  It is guaranteed this sum fits into a 32-bit integer.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: arr = [6,2,4]\r\nOutput: 32\r\nExplanation:\r\nThere are two possible trees.  The first has non-leaf node sum 36, and the second has non-leaf node sum 32.\r\n\r\n    24            24\r\n   /  \\          /  \\\r\n  12   4        6    8\r\n /  \\               / \\\r\n6    2             2   4\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 2 <= arr.length <= 40
    • \r\n\t
    • 1 <= arr[i] <= 15
    • \r\n\t
    • It is guaranteed that the answer fits into a 32-bit signed integer (ie. it is less than 2^31).
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6b63\u6574\u6570\u6570\u7ec4 arr\uff0c\u8003\u8651\u6240\u6709\u6ee1\u8db3\u4ee5\u4e0b\u6761\u4ef6\u7684\u4e8c\u53c9\u6811\uff1a

    \n\n
      \n\t
    • \u6bcf\u4e2a\u8282\u70b9\u90fd\u6709 0 \u4e2a\u6216\u662f 2 \u4e2a\u5b50\u8282\u70b9\u3002
    • \n\t
    • \u6570\u7ec4 arr \u4e2d\u7684\u503c\u4e0e\u6811\u7684\u4e2d\u5e8f\u904d\u5386\u4e2d\u6bcf\u4e2a\u53f6\u8282\u70b9\u7684\u503c\u4e00\u4e00\u5bf9\u5e94\u3002\uff08\u77e5\u8bc6\u56de\u987e\uff1a\u5982\u679c\u4e00\u4e2a\u8282\u70b9\u6709 0 \u4e2a\u5b50\u8282\u70b9\uff0c\u90a3\u4e48\u8be5\u8282\u70b9\u4e3a\u53f6\u8282\u70b9\u3002\uff09
    • \n\t
    • \u6bcf\u4e2a\u975e\u53f6\u8282\u70b9\u7684\u503c\u7b49\u4e8e\u5176\u5de6\u5b50\u6811\u548c\u53f3\u5b50\u6811\u4e2d\u53f6\u8282\u70b9\u7684\u6700\u5927\u503c\u7684\u4e58\u79ef\u3002
    • \n
    \n\n

    \u5728\u6240\u6709\u8fd9\u6837\u7684\u4e8c\u53c9\u6811\u4e2d\uff0c\u8fd4\u56de\u6bcf\u4e2a\u975e\u53f6\u8282\u70b9\u7684\u503c\u7684\u6700\u5c0f\u53ef\u80fd\u603b\u548c\u3002\u8fd9\u4e2a\u548c\u7684\u503c\u662f\u4e00\u4e2a 32 \u4f4d\u6574\u6570\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [6,2,4]\n\u8f93\u51fa\uff1a32\n\u89e3\u91ca\uff1a\n\u6709\u4e24\u79cd\u53ef\u80fd\u7684\u6811\uff0c\u7b2c\u4e00\u79cd\u7684\u975e\u53f6\u8282\u70b9\u7684\u603b\u548c\u4e3a 36\uff0c\u7b2c\u4e8c\u79cd\u975e\u53f6\u8282\u70b9\u7684\u603b\u548c\u4e3a 32\u3002\n\n    24            24\n   /  \\          /  \\\n  12   4        6    8\n /  \\               / \\\n6    2             2   4
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= arr.length <= 40
    • \n\t
    • 1 <= arr[i] <= 15
    • \n\t
    • \u7b54\u6848\u4fdd\u8bc1\u662f\u4e00\u4e2a 32 \u4f4d\u5e26\u7b26\u53f7\u6574\u6570\uff0c\u5373\u5c0f\u4e8e 2^31\u3002
    • \n
    \n", "tags_en": ["Stack", "Tree", "Dynamic Programming"], "tags_cn": ["\u6808", "\u6811", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int mctFromLeafValues(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int mctFromLeafValues(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def mctFromLeafValues(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def mctFromLeafValues(self, arr: List[int]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint mctFromLeafValues(int* arr, int arrSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MctFromLeafValues(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar mctFromLeafValues = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef mct_from_leaf_values(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func mctFromLeafValues(_ arr: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func mctFromLeafValues(arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def mctFromLeafValues(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun mctFromLeafValues(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn mct_from_leaf_values(arr: Vec) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function mctFromLeafValues($arr) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function mctFromLeafValues(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (mct-from-leaf-values arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1130](https://leetcode-cn.com/problems/minimum-cost-tree-from-leaf-values)", "[\u53f6\u503c\u7684\u6700\u5c0f\u4ee3\u4ef7\u751f\u6210\u6811](/solution/1100-1199/1130.Minimum%20Cost%20Tree%20From%20Leaf%20Values/README.md)", "`\u6808`,`\u6811`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1130](https://leetcode.com/problems/minimum-cost-tree-from-leaf-values)", "[Minimum Cost Tree From Leaf Values](/solution/1100-1199/1130.Minimum%20Cost%20Tree%20From%20Leaf%20Values/README_EN.md)", "`Stack`,`Tree`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "1227", "frontend_question_id": "1128", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-equivalent-domino-pairs", "url_en": "https://leetcode.com/problems/number-of-equivalent-domino-pairs", "relative_path_cn": "/solution/1100-1199/1128.Number%20of%20Equivalent%20Domino%20Pairs/README.md", "relative_path_en": "/solution/1100-1199/1128.Number%20of%20Equivalent%20Domino%20Pairs/README_EN.md", "title_cn": "\u7b49\u4ef7\u591a\u7c73\u8bfa\u9aa8\u724c\u5bf9\u7684\u6570\u91cf", "title_en": "Number of Equivalent Domino Pairs", "question_title_slug": "number-of-equivalent-domino-pairs", "content_en": "

    Given a list of dominoesdominoes[i] = [a, b] is equivalent to dominoes[j] = [c, d] if and only if either (a==c and b==d), or (a==d and b==c) - that is, one domino can be rotated to be equal to another domino.

    \r\n\r\n

    Return the number of pairs (i, j) for which 0 <= i < j < dominoes.length, and dominoes[i] is equivalent to dominoes[j].

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n
    Input: dominoes = [[1,2],[2,1],[3,4],[5,6]]\r\nOutput: 1\r\n
    \r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= dominoes.length <= 40000
    • \r\n\t
    • 1 <= dominoes[i][j] <= 9
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u7531\u4e00\u4e9b\u591a\u7c73\u8bfa\u9aa8\u724c\u7ec4\u6210\u7684\u5217\u8868 dominoes\u3002

    \n\n

    \u5982\u679c\u5176\u4e2d\u67d0\u4e00\u5f20\u591a\u7c73\u8bfa\u9aa8\u724c\u53ef\u4ee5\u901a\u8fc7\u65cb\u8f6c 0 \u5ea6\u6216 180 \u5ea6\u5f97\u5230\u53e6\u4e00\u5f20\u591a\u7c73\u8bfa\u9aa8\u724c\uff0c\u6211\u4eec\u5c31\u8ba4\u4e3a\u8fd9\u4e24\u5f20\u724c\u662f\u7b49\u4ef7\u7684\u3002

    \n\n

    \u5f62\u5f0f\u4e0a\uff0cdominoes[i] = [a, b] \u548c dominoes[j] = [c, d] \u7b49\u4ef7\u7684\u524d\u63d0\u662f a==c \u4e14 b==d\uff0c\u6216\u662f a==d \u4e14 b==c\u3002

    \n\n

    \u5728 0 <= i < j < dominoes.length \u7684\u524d\u63d0\u4e0b\uff0c\u627e\u51fa\u6ee1\u8db3 dominoes[i] \u548c dominoes[j] \u7b49\u4ef7\u7684\u9aa8\u724c\u5bf9 (i, j) \u7684\u6570\u91cf\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1adominoes = [[1,2],[2,1],[3,4],[5,6]]\n\u8f93\u51fa\uff1a1\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= dominoes.length <= 40000
    • \n\t
    • 1 <= dominoes[i][j] <= 9
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numEquivDominoPairs(vector>& dominoes) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numEquivDominoPairs(int[][] dominoes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numEquivDominoPairs(self, dominoes):\n \"\"\"\n :type dominoes: List[List[int]]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numEquivDominoPairs(self, dominoes: List[List[int]]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numEquivDominoPairs(int** dominoes, int dominoesSize, int* dominoesColSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumEquivDominoPairs(int[][] dominoes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} dominoes\n * @return {number}\n */\nvar numEquivDominoPairs = function(dominoes) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} dominoes\n# @return {Integer}\ndef num_equiv_domino_pairs(dominoes)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numEquivDominoPairs(_ dominoes: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numEquivDominoPairs(dominoes [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numEquivDominoPairs(dominoes: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numEquivDominoPairs(dominoes: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_equiv_domino_pairs(dominoes: Vec>) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $dominoes\n * @return Integer\n */\n function numEquivDominoPairs($dominoes) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numEquivDominoPairs(dominoes: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-equiv-domino-pairs dominoes)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1128](https://leetcode-cn.com/problems/number-of-equivalent-domino-pairs)", "[\u7b49\u4ef7\u591a\u7c73\u8bfa\u9aa8\u724c\u5bf9\u7684\u6570\u91cf](/solution/1100-1199/1128.Number%20of%20Equivalent%20Domino%20Pairs/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1128](https://leetcode.com/problems/number-of-equivalent-domino-pairs)", "[Number of Equivalent Domino Pairs](/solution/1100-1199/1128.Number%20of%20Equivalent%20Domino%20Pairs/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1226", "frontend_question_id": "1127", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/user-purchase-platform", "url_en": "https://leetcode.com/problems/user-purchase-platform", "relative_path_cn": "/solution/1100-1199/1127.User%20Purchase%20Platform/README.md", "relative_path_en": "/solution/1100-1199/1127.User%20Purchase%20Platform/README_EN.md", "title_cn": "\u7528\u6237\u8d2d\u4e70\u5e73\u53f0", "title_en": "User Purchase Platform", "question_title_slug": "user-purchase-platform", "content_en": "

    Table: Spending

    \n\n
    \n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| user_id     | int     |\n| spend_date  | date    |\n| platform    | enum    | \n| amount      | int     |\n+-------------+---------+\nThe table logs the spendings history of users that make purchases from an online shopping website which has a desktop and a mobile application.\n(user_id, spend_date, platform) is the primary key of this table.\nThe platform column is an ENUM type of ('desktop', 'mobile').\n
    \n\n

    Write an SQL query to find the total number of users and the total amount spent using mobile only, desktop only and both mobile and desktop together for each date.

    \n\n

    The query result format is in the following example:

    \n\n
    \nSpending table:\n+---------+------------+----------+--------+\n| user_id | spend_date | platform | amount |\n+---------+------------+----------+--------+\n| 1       | 2019-07-01 | mobile   | 100    |\n| 1       | 2019-07-01 | desktop  | 100    |\n| 2       | 2019-07-01 | mobile   | 100    |\n| 2       | 2019-07-02 | mobile   | 100    |\n| 3       | 2019-07-01 | desktop  | 100    |\n| 3       | 2019-07-02 | desktop  | 100    |\n+---------+------------+----------+--------+\n\nResult table:\n+------------+----------+--------------+-------------+\n| spend_date | platform | total_amount | total_users |\n+------------+----------+--------------+-------------+\n| 2019-07-01 | desktop  | 100          | 1           |\n| 2019-07-01 | mobile   | 100          | 1           |\n| 2019-07-01 | both     | 200          | 1           |\n| 2019-07-02 | desktop  | 100          | 1           |\n| 2019-07-02 | mobile   | 100          | 1           |\n| 2019-07-02 | both     | 0            | 0           |\n+------------+----------+--------------+-------------+ \nOn 2019-07-01, user 1 purchased using both desktop and mobile, user 2 purchased using mobile only and user 3 purchased using desktop only.\nOn 2019-07-02, user 2 purchased using mobile only, user 3 purchased using desktop only and no one purchased using both platforms.
    \n", "content_cn": "

    \u652f\u51fa\u8868: Spending

    \n\n
    \n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| user_id     | int     |\n| spend_date  | date    |\n| platform    | enum    | \n| amount      | int     |\n+-------------+---------+\n\u8fd9\u5f20\u8868\u8bb0\u5f55\u4e86\u7528\u6237\u5728\u4e00\u4e2a\u5728\u7ebf\u8d2d\u7269\u7f51\u7ad9\u7684\u652f\u51fa\u5386\u53f2\uff0c\u8be5\u5728\u7ebf\u8d2d\u7269\u5e73\u53f0\u540c\u65f6\u62e5\u6709\u684c\u9762\u7aef\uff08'desktop'\uff09\u548c\u624b\u673a\u7aef\uff08'mobile'\uff09\u7684\u5e94\u7528\u7a0b\u5e8f\u3002\n\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\u662f (user_id, spend_date, platform)\u3002\n\u5e73\u53f0\u5217 platform \u662f\u4e00\u79cd ENUM \uff0c\u7c7b\u578b\u4e3a\uff08'desktop', 'mobile'\uff09\u3002
    \n\n

     

    \n\n

    \u5199\u4e00\u6bb5 SQL \u6765\u67e5\u627e\u6bcf\u5929 \u4ec5 \u4f7f\u7528\u624b\u673a\u7aef\u7528\u6237\u3001\u4ec5 \u4f7f\u7528\u684c\u9762\u7aef\u7528\u6237\u548c \u540c\u65f6 \u4f7f\u7528\u684c\u9762\u7aef\u548c\u624b\u673a\u7aef\u7684\u7528\u6237\u4eba\u6570\u548c\u603b\u652f\u51fa\u91d1\u989d\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a\uff1a

    \n\n
    \nSpending table:\n+---------+------------+----------+--------+\n| user_id | spend_date | platform | amount |\n+---------+------------+----------+--------+\n| 1       | 2019-07-01 | mobile   | 100    |\n| 1       | 2019-07-01 | desktop  | 100    |\n| 2       | 2019-07-01 | mobile   | 100    |\n| 2       | 2019-07-02 | mobile   | 100    |\n| 3       | 2019-07-01 | desktop  | 100    |\n| 3       | 2019-07-02 | desktop  | 100    |\n+---------+------------+----------+--------+\n\nResult table:\n+------------+----------+--------------+-------------+\n| spend_date | platform | total_amount | total_users |\n+------------+----------+--------------+-------------+\n| 2019-07-01 | desktop  | 100          | 1           |\n| 2019-07-01 | mobile   | 100          | 1           |\n| 2019-07-01 | both     | 200          | 1           |\n| 2019-07-02 | desktop  | 100          | 1           |\n| 2019-07-02 | mobile   | 100          | 1           |\n| 2019-07-02 | both     | 0            | 0           |\n+------------+----------+--------------+-------------+ \n\u5728 2019-07-01, \u7528\u62371 \u540c\u65f6 \u4f7f\u7528\u684c\u9762\u7aef\u548c\u624b\u673a\u7aef\u8d2d\u4e70, \u7528\u62372 \u4ec5 \u4f7f\u7528\u4e86\u624b\u673a\u7aef\u8d2d\u4e70\uff0c\u800c\u7528\u62373 \u4ec5 \u4f7f\u7528\u4e86\u684c\u9762\u7aef\u8d2d\u4e70\u3002\n\u5728 2019-07-02, \u7528\u62372 \u4ec5 \u4f7f\u7528\u4e86\u624b\u673a\u7aef\u8d2d\u4e70, \u7528\u62373 \u4ec5 \u4f7f\u7528\u4e86\u684c\u9762\u7aef\u8d2d\u4e70\uff0c\u4e14\u6ca1\u6709\u7528\u6237 \u540c\u65f6 \u4f7f\u7528\u684c\u9762\u7aef\u548c\u624b\u673a\u7aef\u8d2d\u4e70\u3002
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1127](https://leetcode-cn.com/problems/user-purchase-platform)", "[\u7528\u6237\u8d2d\u4e70\u5e73\u53f0](/solution/1100-1199/1127.User%20Purchase%20Platform/README.md)", "", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1127](https://leetcode.com/problems/user-purchase-platform)", "[User Purchase Platform](/solution/1100-1199/1127.User%20Purchase%20Platform/README_EN.md)", "", "Hard", "\ud83d\udd12"]}, {"question_id": "1225", "frontend_question_id": "1126", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/active-businesses", "url_en": "https://leetcode.com/problems/active-businesses", "relative_path_cn": "/solution/1100-1199/1126.Active%20Businesses/README.md", "relative_path_en": "/solution/1100-1199/1126.Active%20Businesses/README_EN.md", "title_cn": "\u67e5\u8be2\u6d3b\u8dc3\u4e1a\u52a1", "title_en": "Active Businesses", "question_title_slug": "active-businesses", "content_en": "

    Table: Events

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| business_id   | int     |\n| event_type    | varchar |\n| occurences    | int     | \n+---------------+---------+\n(business_id, event_type) is the primary key of this table.\nEach row in the table logs the info that an event of some type occured at some business for a number of times.
    \n\n

     

    \n\n

    Write an SQL query to find all active businesses.

    \n\n

    An active business is a business that has more than one event type with occurences greater than the average occurences of that event type among all businesses.

    \n\n

    The query result format is in the following example:

    \n\n
    \nEvents table:\n+-------------+------------+------------+\n| business_id | event_type | occurences |\n+-------------+------------+------------+\n| 1           | reviews    | 7          |\n| 3           | reviews    | 3          |\n| 1           | ads        | 11         |\n| 2           | ads        | 7          |\n| 3           | ads        | 6          |\n| 1           | page views | 3          |\n| 2           | page views | 12         |\n+-------------+------------+------------+\n\nResult table:\n+-------------+\n| business_id |\n+-------------+\n| 1           |\n+-------------+ \nAverage for 'reviews', 'ads' and 'page views' are (7+3)/2=5, (11+7+6)/3=8, (3+12)/2=7.5 respectively.\nBusiness with id 1 has 7 'reviews' events (more than 5) and 11 'ads' events (more than 8) so it is an active business.
    \n", "content_cn": "

    \u4e8b\u4ef6\u8868\uff1aEvents

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| business_id   | int     |\n| event_type    | varchar |\n| occurences    | int     | \n+---------------+---------+\n\u6b64\u8868\u7684\u4e3b\u952e\u662f (business_id, event_type)\u3002\n\u8868\u4e2d\u7684\u6bcf\u4e00\u884c\u8bb0\u5f55\u4e86\u67d0\u79cd\u7c7b\u578b\u7684\u4e8b\u4ef6\u5728\u67d0\u4e9b\u4e1a\u52a1\u4e2d\u591a\u6b21\u53d1\u751f\u7684\u4fe1\u606f\u3002\n
    \n\n

     

    \n\n

    \u5199\u4e00\u6bb5 SQL \u6765\u67e5\u8be2\u6240\u6709\u6d3b\u8dc3\u7684\u4e1a\u52a1\u3002

    \n\n

    \u5982\u679c\u4e00\u4e2a\u4e1a\u52a1\u7684\u67d0\u4e2a\u4e8b\u4ef6\u7c7b\u578b\u7684\u53d1\u751f\u6b21\u6570\u5927\u4e8e\u6b64\u4e8b\u4ef6\u7c7b\u578b\u5728\u6240\u6709\u4e1a\u52a1\u4e2d\u7684\u5e73\u5747\u53d1\u751f\u6b21\u6570\uff0c\u5e76\u4e14\u8be5\u4e1a\u52a1\u81f3\u5c11\u6709\u4e24\u4e2a\u8fd9\u6837\u7684\u4e8b\u4ef6\u7c7b\u578b\uff0c\u90a3\u4e48\u8be5\u4e1a\u52a1\u5c31\u53ef\u88ab\u770b\u505a\u662f\u6d3b\u8dc3\u4e1a\u52a1\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u6240\u793a\uff1a

    \n\n
    \nEvents table:\n+-------------+------------+------------+\n| business_id | event_type | occurences |\n+-------------+------------+------------+\n| 1           | reviews    | 7          |\n| 3           | reviews    | 3          |\n| 1           | ads        | 11         |\n| 2           | ads        | 7          |\n| 3           | ads        | 6          |\n| 1           | page views | 3          |\n| 2           | page views | 12         |\n+-------------+------------+------------+\n\n\u7ed3\u679c\u8868\n+-------------+\n| business_id |\n+-------------+\n| 1           |\n+-------------+ \n'reviews'\u3001 'ads' \u548c 'page views' \u7684\u603b\u5e73\u5747\u53d1\u751f\u6b21\u6570\u5206\u522b\u662f (7+3)/2=5, (11+7+6)/3=8, (3+12)/2=7.5\u3002\nid \u4e3a 1 \u7684\u4e1a\u52a1\u6709 7 \u4e2a 'reviews' \u4e8b\u4ef6\uff08\u5927\u4e8e 5\uff09\u548c 11 \u4e2a 'ads' \u4e8b\u4ef6\uff08\u5927\u4e8e 8\uff09\uff0c\u6240\u4ee5\u5b83\u662f\u6d3b\u8dc3\u4e1a\u52a1\u3002
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1126](https://leetcode-cn.com/problems/active-businesses)", "[\u67e5\u8be2\u6d3b\u8dc3\u4e1a\u52a1](/solution/1100-1199/1126.Active%20Businesses/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1126](https://leetcode.com/problems/active-businesses)", "[Active Businesses](/solution/1100-1199/1126.Active%20Businesses/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1224", "frontend_question_id": "1289", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-falling-path-sum-ii", "url_en": "https://leetcode.com/problems/minimum-falling-path-sum-ii", "relative_path_cn": "/solution/1200-1299/1289.Minimum%20Falling%20Path%20Sum%20II/README.md", "relative_path_en": "/solution/1200-1299/1289.Minimum%20Falling%20Path%20Sum%20II/README_EN.md", "title_cn": "\u4e0b\u964d\u8def\u5f84\u6700\u5c0f\u548c II", "title_en": "Minimum Falling Path Sum II", "question_title_slug": "minimum-falling-path-sum-ii", "content_en": "

    Given a square grid of integers arr, a falling path with non-zero shifts is a choice of exactly one element from each row of arr, such that no two elements chosen in adjacent rows are in the same column.

    \n\n

    Return the minimum sum of a falling path with non-zero shifts.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr = [[1,2,3],[4,5,6],[7,8,9]]\nOutput: 13\nExplanation: \nThe possible falling paths are:\n[1,5,9], [1,5,7], [1,6,7], [1,6,8],\n[2,4,8], [2,4,9], [2,6,7], [2,6,8],\n[3,4,8], [3,4,9], [3,5,7], [3,5,9]\nThe falling path with the smallest sum is [1,5,7], so the answer is 13.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= arr.length == arr[i].length <= 200
    • \n\t
    • -99 <= arr[i][j] <= 99
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u65b9\u9635 arr \uff0c\u5b9a\u4e49\u300c\u975e\u96f6\u504f\u79fb\u4e0b\u964d\u8def\u5f84\u300d\u4e3a\uff1a\u4ece arr \u6570\u7ec4\u4e2d\u7684\u6bcf\u4e00\u884c\u9009\u62e9\u4e00\u4e2a\u6570\u5b57\uff0c\u4e14\u6309\u987a\u5e8f\u9009\u51fa\u6765\u7684\u6570\u5b57\u4e2d\uff0c\u76f8\u90bb\u6570\u5b57\u4e0d\u5728\u539f\u6570\u7ec4\u7684\u540c\u4e00\u5217\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u975e\u96f6\u504f\u79fb\u4e0b\u964d\u8def\u5f84\u6570\u5b57\u548c\u7684\u6700\u5c0f\u503c\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [[1,2,3],[4,5,6],[7,8,9]]\n\u8f93\u51fa\uff1a13\n\u89e3\u91ca\uff1a\n\u6240\u6709\u975e\u96f6\u504f\u79fb\u4e0b\u964d\u8def\u5f84\u5305\u62ec\uff1a\n[1,5,9], [1,5,7], [1,6,7], [1,6,8],\n[2,4,8], [2,4,9], [2,6,7], [2,6,8],\n[3,4,8], [3,4,9], [3,5,7], [3,5,9]\n\u4e0b\u964d\u8def\u5f84\u4e2d\u6570\u5b57\u548c\u6700\u5c0f\u7684\u662f [1,5,7] \uff0c\u6240\u4ee5\u7b54\u6848\u662f 13 \u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= arr.length == arr[i].length <= 200
    • \n\t
    • -99 <= arr[i][j] <= 99
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minFallingPathSum(vector>& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minFallingPathSum(int[][] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minFallingPathSum(self, arr):\n \"\"\"\n :type arr: List[List[int]]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minFallingPathSum(self, arr: List[List[int]]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minFallingPathSum(int** arr, int arrSize, int* arrColSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinFallingPathSum(int[][] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} arr\n * @return {number}\n */\nvar minFallingPathSum = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} arr\n# @return {Integer}\ndef min_falling_path_sum(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minFallingPathSum(_ arr: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minFallingPathSum(arr [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minFallingPathSum(arr: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minFallingPathSum(arr: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_falling_path_sum(arr: Vec>) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $arr\n * @return Integer\n */\n function minFallingPathSum($arr) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minFallingPathSum(arr: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-falling-path-sum arr)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1289](https://leetcode-cn.com/problems/minimum-falling-path-sum-ii)", "[\u4e0b\u964d\u8def\u5f84\u6700\u5c0f\u548c II](/solution/1200-1299/1289.Minimum%20Falling%20Path%20Sum%20II/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1289](https://leetcode.com/problems/minimum-falling-path-sum-ii)", "[Minimum Falling Path Sum II](/solution/1200-1299/1289.Minimum%20Falling%20Path%20Sum%20II/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1223", "frontend_question_id": "1627", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/graph-connectivity-with-threshold", "url_en": "https://leetcode.com/problems/graph-connectivity-with-threshold", "relative_path_cn": "/solution/1600-1699/1627.Graph%20Connectivity%20With%20Threshold/README.md", "relative_path_en": "/solution/1600-1699/1627.Graph%20Connectivity%20With%20Threshold/README_EN.md", "title_cn": "\u5e26\u9608\u503c\u7684\u56fe\u8fde\u901a\u6027", "title_en": "Graph Connectivity With Threshold", "question_title_slug": "graph-connectivity-with-threshold", "content_en": "

    We have n cities labeled from 1 to n. Two different cities with labels x and y are directly connected by a bidirectional road if and only if x and y share a common divisor strictly greater than some threshold. More formally, cities with labels x and y have a road between them if there exists an integer z such that all of the following are true:

    \n\n
      \n\t
    • x % z == 0,
    • \n\t
    • y % z == 0, and
    • \n\t
    • z > threshold.
    • \n
    \n\n

    Given the two integers, n and threshold, and an array of queries, you must determine for each queries[i] = [ai, bi] if cities ai and bi are connected directly or indirectly. (i.e. there is some path between them).

    \n\n

    Return an array answer, where answer.length == queries.length and answer[i] is true if for the ith query, there is a path between ai and bi, or answer[i] is false if there is no path.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: n = 6, threshold = 2, queries = [[1,4],[2,5],[3,6]]\nOutput: [false,false,true]\nExplanation: The divisors for each number:\n1:   1\n2:   1, 2\n3:   1, 3\n4:   1, 2, 4\n5:   1, 5\n6:   1, 2, 3, 6\nUsing the underlined divisors above the threshold, only cities 3 and 6 share a common divisor, so they are the\nonly ones directly connected. The result of each query:\n[1,4]   1 is not connected to 4\n[2,5]   2 is not connected to 5\n[3,6]   3 is connected to 6 through path 3--6\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: n = 6, threshold = 0, queries = [[4,5],[3,4],[3,2],[2,6],[1,3]]\nOutput: [true,true,true,true,true]\nExplanation: The divisors for each number are the same as the previous example. However, since the threshold is 0,\nall divisors can be used. Since all numbers share 1 as a divisor, all cities are connected.\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: n = 5, threshold = 1, queries = [[4,5],[4,5],[3,2],[2,3],[3,4]]\nOutput: [false,false,false,false,false]\nExplanation: Only cities 2 and 4 share a common divisor 2 which is strictly greater than the threshold 1, so they are the only ones directly connected.\nPlease notice that there can be multiple queries for the same pair of nodes [x, y], and that the query [x, y] is equivalent to the query [y, x].\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= n <= 104
    • \n\t
    • 0 <= threshold <= n
    • \n\t
    • 1 <= queries.length <= 105
    • \n\t
    • queries[i].length == 2
    • \n\t
    • 1 <= ai, bi <= cities
    • \n\t
    • ai != bi
    • \n
    \n", "content_cn": "

    \u6709 n \u5ea7\u57ce\u5e02\uff0c\u7f16\u53f7\u4ece 1 \u5230 n \u3002\u7f16\u53f7\u4e3a x \u548c y \u7684\u4e24\u5ea7\u57ce\u5e02\u76f4\u63a5\u8fde\u901a\u7684\u524d\u63d0\u662f\uff1a x \u548c y \u7684\u516c\u56e0\u6570\u4e2d\uff0c\u81f3\u5c11\u6709\u4e00\u4e2a \u4e25\u683c\u5927\u4e8e \u67d0\u4e2a\u9608\u503c threshold \u3002\u66f4\u6b63\u5f0f\u5730\u8bf4\uff0c\u5982\u679c\u5b58\u5728\u6574\u6570 z \uff0c\u4e14\u6ee1\u8db3\u4ee5\u4e0b\u6240\u6709\u6761\u4ef6\uff0c\u5219\u7f16\u53f7 x \u548c y \u7684\u57ce\u5e02\u4e4b\u95f4\u6709\u4e00\u6761\u9053\u8def\uff1a

    \n\n
      \n\t
    • x % z == 0
    • \n\t
    • y % z == 0
    • \n\t
    • z > threshold
    • \n
    \n\n

    \u7ed9\u4f60\u4e24\u4e2a\u6574\u6570 n \u548c threshold \uff0c\u4ee5\u53ca\u4e00\u4e2a\u5f85\u67e5\u8be2\u6570\u7ec4\uff0c\u8bf7\u4f60\u5224\u65ad\u6bcf\u4e2a\u67e5\u8be2 queries[i] = [ai, bi] \u6307\u5411\u7684\u57ce\u5e02 ai \u548c bi \u662f\u5426\u8fde\u901a\uff08\u5373\uff0c\u5b83\u4eec\u4e4b\u95f4\u662f\u5426\u5b58\u5728\u4e00\u6761\u8def\u5f84\uff09\u3002

    \n\n

    \u8fd4\u56de\u6570\u7ec4 answer \uff0c\u5176\u4e2danswer.length == queries.length \u3002\u5982\u679c\u7b2c i \u4e2a\u67e5\u8be2\u4e2d\u6307\u5411\u7684\u57ce\u5e02 ai \u548c bi \u8fde\u901a\uff0c\u5219 answer[i] \u4e3a true \uff1b\u5982\u679c\u4e0d\u8fde\u901a\uff0c\u5219 answer[i] \u4e3a false \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n

    \u00a0

    \n\n
    \n\u8f93\u5165\uff1an = 6, threshold = 2, queries = [[1,4],[2,5],[3,6]]\n\u8f93\u51fa\uff1a[false,false,true]\n\u89e3\u91ca\uff1a\u6bcf\u4e2a\u6570\u7684\u56e0\u6570\u5982\u4e0b\uff1a\n1:   1\n2:   1, 2\n3:   1, 3\n4:   1, 2, 4\n5:   1, 5\n6:   1, 2, 3, 6\n\u6240\u6709\u5927\u4e8e\u9608\u503c\u7684\u7684\u56e0\u6570\u5df2\u7ecf\u52a0\u7c97\u6807\u8bc6\uff0c\u53ea\u6709\u57ce\u5e02 3 \u548c 6 \u5171\u4eab\u516c\u7ea6\u6570 3 \uff0c\u56e0\u6b64\u7ed3\u679c\u662f\uff1a \n[1,4]   1 \u4e0e 4 \u4e0d\u8fde\u901a\n[2,5]   2 \u4e0e 5 \u4e0d\u8fde\u901a\n[3,6]   3 \u4e0e 6 \u8fde\u901a\uff0c\u5b58\u5728\u8def\u5f84 3--6\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n

    \u00a0

    \n\n
    \n\u8f93\u5165\uff1an = 6, threshold = 0, queries = [[4,5],[3,4],[3,2],[2,6],[1,3]]\n\u8f93\u51fa\uff1a[true,true,true,true,true]\n\u89e3\u91ca\uff1a\u6bcf\u4e2a\u6570\u7684\u56e0\u6570\u4e0e\u4e0a\u4e00\u4e2a\u4f8b\u5b50\u76f8\u540c\u3002\u4f46\u662f\uff0c\u7531\u4e8e\u9608\u503c\u4e3a 0 \uff0c\u6240\u6709\u7684\u56e0\u6570\u90fd\u5927\u4e8e\u9608\u503c\u3002\u56e0\u4e3a\u6240\u6709\u7684\u6570\u5b57\u5171\u4eab\u516c\u56e0\u6570 1 \uff0c\u6240\u4ee5\u6240\u6709\u7684\u57ce\u5e02\u90fd\u4e92\u76f8\u8fde\u901a\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n

    \"\"

    \n\n

    \u00a0

    \n\n
    \n\u8f93\u5165\uff1an = 5, threshold = 1, queries = [[4,5],[4,5],[3,2],[2,3],[3,4]]\n\u8f93\u51fa\uff1a[false,false,false,false,false]\n\u89e3\u91ca\uff1a\u53ea\u6709\u57ce\u5e02 2 \u548c 4 \u5171\u4eab\u7684\u516c\u7ea6\u6570 2 \u4e25\u683c\u5927\u4e8e\u9608\u503c 1 \uff0c\u6240\u4ee5\u53ea\u6709\u8fd9\u4e24\u5ea7\u57ce\u5e02\u662f\u8fde\u901a\u7684\u3002\n\u6ce8\u610f\uff0c\u540c\u4e00\u5bf9\u8282\u70b9 [x, y] \u53ef\u4ee5\u6709\u591a\u4e2a\u67e5\u8be2\uff0c\u5e76\u4e14\u67e5\u8be2 [x\uff0cy] \u7b49\u540c\u4e8e\u67e5\u8be2 [y\uff0cx] \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= n <= 104
    • \n\t
    • 0 <= threshold <= n
    • \n\t
    • 1 <= queries.length <= 105
    • \n\t
    • queries[i].length == 2
    • \n\t
    • 1 <= ai, bi <= cities
    • \n\t
    • ai != bi
    • \n
    \n", "tags_en": ["Union Find", "Math"], "tags_cn": ["\u5e76\u67e5\u96c6", "\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector areConnected(int n, int threshold, vector>& queries) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List areConnected(int n, int threshold, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def areConnected(self, n, threshold, queries):\n \"\"\"\n :type n: int\n :type threshold: int\n :type queries: List[List[int]]\n :rtype: List[bool]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def areConnected(self, n: int, threshold: int, queries: List[List[int]]) -> List[bool]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nbool* areConnected(int n, int threshold, int** queries, int queriesSize, int* queriesColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList AreConnected(int n, int threshold, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} threshold\n * @param {number[][]} queries\n * @return {boolean[]}\n */\nvar areConnected = function(n, threshold, queries) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} threshold\n# @param {Integer[][]} queries\n# @return {Boolean[]}\ndef are_connected(n, threshold, queries)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func areConnected(_ n: Int, _ threshold: Int, _ queries: [[Int]]) -> [Bool] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func areConnected(n int, threshold int, queries [][]int) []bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def areConnected(n: Int, threshold: Int, queries: Array[Array[Int]]): List[Boolean] = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun areConnected(n: Int, threshold: Int, queries: Array): List {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn are_connected(n: i32, threshold: i32, queries: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $threshold\n * @param Integer[][] $queries\n * @return Boolean[]\n */\n function areConnected($n, $threshold, $queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function areConnected(n: number, threshold: number, queries: number[][]): boolean[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (are-connected n threshold queries)\n (-> exact-integer? exact-integer? (listof (listof exact-integer?)) (listof boolean?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1627](https://leetcode-cn.com/problems/graph-connectivity-with-threshold)", "[\u5e26\u9608\u503c\u7684\u56fe\u8fde\u901a\u6027](/solution/1600-1699/1627.Graph%20Connectivity%20With%20Threshold/README.md)", "`\u5e76\u67e5\u96c6`,`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[1627](https://leetcode.com/problems/graph-connectivity-with-threshold)", "[Graph Connectivity With Threshold](/solution/1600-1699/1627.Graph%20Connectivity%20With%20Threshold/README_EN.md)", "`Union Find`,`Math`", "Hard", ""]}, {"question_id": "1222", "frontend_question_id": "1288", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/remove-covered-intervals", "url_en": "https://leetcode.com/problems/remove-covered-intervals", "relative_path_cn": "/solution/1200-1299/1288.Remove%20Covered%20Intervals/README.md", "relative_path_en": "/solution/1200-1299/1288.Remove%20Covered%20Intervals/README_EN.md", "title_cn": "\u5220\u9664\u88ab\u8986\u76d6\u533a\u95f4", "title_en": "Remove Covered Intervals", "question_title_slug": "remove-covered-intervals", "content_en": "

    Given a list of intervals, remove all intervals that are covered by another interval in the list.

    \r\n\r\n

    Interval [a,b) is covered by interval [c,d) if and only if c <= a and b <= d.

    \r\n\r\n

    After doing so, return the number of remaining intervals.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: intervals = [[1,4],[3,6],[2,8]]\r\nOutput: 2\r\nExplanation: Interval [3,6] is covered by [2,8], therefore it is removed.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: intervals = [[1,4],[2,3]]\r\nOutput: 1\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: intervals = [[0,10],[5,12]]\r\nOutput: 2\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: intervals = [[3,10],[4,10],[5,11]]\r\nOutput: 2\r\n
    \r\n\r\n

    Example 5:

    \r\n\r\n
    \r\nInput: intervals = [[1,2],[1,4],[3,4]]\r\nOutput: 1\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= intervals.length <= 1000
    • \r\n\t
    • intervals[i].length == 2
    • \r\n\t
    • 0 <= intervals[i][0] < intervals[i][1] <= 10^5
    • \r\n\t
    • All the intervals are unique.
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u533a\u95f4\u5217\u8868\uff0c\u8bf7\u4f60\u5220\u9664\u5217\u8868\u4e2d\u88ab\u5176\u4ed6\u533a\u95f4\u6240\u8986\u76d6\u7684\u533a\u95f4\u3002

    \n\n

    \u53ea\u6709\u5f53 c <= a \u4e14 b <= d \u65f6\uff0c\u6211\u4eec\u624d\u8ba4\u4e3a\u533a\u95f4 [a,b) \u88ab\u533a\u95f4 [c,d) \u8986\u76d6\u3002

    \n\n

    \u5728\u5b8c\u6210\u6240\u6709\u5220\u9664\u64cd\u4f5c\u540e\uff0c\u8bf7\u4f60\u8fd4\u56de\u5217\u8868\u4e2d\u5269\u4f59\u533a\u95f4\u7684\u6570\u76ee\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1aintervals = [[1,4],[3,6],[2,8]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u533a\u95f4 [3,6] \u88ab\u533a\u95f4 [2,8] \u8986\u76d6\uff0c\u6240\u4ee5\u5b83\u88ab\u5220\u9664\u4e86\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a\u200b\u200b\u200b\u200b\u200b\u200b

    \n\n
      \n\t
    • 1 <= intervals.length <= 1000
    • \n\t
    • 0 <= intervals[i][0] < intervals[i][1] <= 10^5
    • \n\t
    • \u5bf9\u4e8e\u6240\u6709\u7684 i != j\uff1aintervals[i] != intervals[j]
    • \n
    \n", "tags_en": ["Greedy", "Sort", "Line Sweep"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6392\u5e8f"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int removeCoveredIntervals(vector>& intervals) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int removeCoveredIntervals(int[][] intervals) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def removeCoveredIntervals(self, intervals):\n \"\"\"\n :type intervals: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint removeCoveredIntervals(int** intervals, int intervalsSize, int* intervalsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int RemoveCoveredIntervals(int[][] intervals) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} intervals\n * @return {number}\n */\nvar removeCoveredIntervals = function(intervals) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} intervals\n# @return {Integer}\ndef remove_covered_intervals(intervals)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func removeCoveredIntervals(_ intervals: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func removeCoveredIntervals(intervals [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def removeCoveredIntervals(intervals: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun removeCoveredIntervals(intervals: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn remove_covered_intervals(intervals: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $intervals\n * @return Integer\n */\n function removeCoveredIntervals($intervals) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function removeCoveredIntervals(intervals: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (remove-covered-intervals intervals)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1288](https://leetcode-cn.com/problems/remove-covered-intervals)", "[\u5220\u9664\u88ab\u8986\u76d6\u533a\u95f4](/solution/1200-1299/1288.Remove%20Covered%20Intervals/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6392\u5e8f`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1288](https://leetcode.com/problems/remove-covered-intervals)", "[Remove Covered Intervals](/solution/1200-1299/1288.Remove%20Covered%20Intervals/README_EN.md)", "`Greedy`,`Sort`,`Line Sweep`", "Medium", ""]}, {"question_id": "1221", "frontend_question_id": "1287", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/element-appearing-more-than-25-in-sorted-array", "url_en": "https://leetcode.com/problems/element-appearing-more-than-25-in-sorted-array", "relative_path_cn": "/solution/1200-1299/1287.Element%20Appearing%20More%20Than%2025%25%20In%20Sorted%20Array/README.md", "relative_path_en": "/solution/1200-1299/1287.Element%20Appearing%20More%20Than%2025%25%20In%20Sorted%20Array/README_EN.md", "title_cn": "\u6709\u5e8f\u6570\u7ec4\u4e2d\u51fa\u73b0\u6b21\u6570\u8d85\u8fc725%\u7684\u5143\u7d20", "title_en": "Element Appearing More Than 25% In Sorted Array", "question_title_slug": "element-appearing-more-than-25-in-sorted-array", "content_en": "

    Given an integer array sorted in non-decreasing order, there is exactly one integer in the array that occurs more than 25% of the time, return that integer.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr = [1,2,2,6,6,6,6,7,10]\nOutput: 6\n
    \n\n

    Example 2:

    \n\n
    \nInput: arr = [1,1]\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= arr.length <= 104
    • \n\t
    • 0 <= arr[i] <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u975e\u9012\u51cf\u7684 \u6709\u5e8f \u6574\u6570\u6570\u7ec4\uff0c\u5df2\u77e5\u8fd9\u4e2a\u6570\u7ec4\u4e2d\u6070\u597d\u6709\u4e00\u4e2a\u6574\u6570\uff0c\u5b83\u7684\u51fa\u73b0\u6b21\u6570\u8d85\u8fc7\u6570\u7ec4\u5143\u7d20\u603b\u6570\u7684 25%\u3002

    \n\n

    \u8bf7\u4f60\u627e\u5230\u5e76\u8fd4\u56de\u8fd9\u4e2a\u6574\u6570

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [1,2,2,6,6,6,6,7,10]\n\u8f93\u51fa\uff1a6\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= arr.length <= 10^4
    • \n\t
    • 0 <= arr[i] <= 10^5
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findSpecialInteger(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findSpecialInteger(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findSpecialInteger(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findSpecialInteger(self, arr: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findSpecialInteger(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindSpecialInteger(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar findSpecialInteger = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef find_special_integer(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findSpecialInteger(_ arr: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findSpecialInteger(arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findSpecialInteger(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findSpecialInteger(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_special_integer(arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function findSpecialInteger($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findSpecialInteger(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-special-integer arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1287](https://leetcode-cn.com/problems/element-appearing-more-than-25-in-sorted-array)", "[\u6709\u5e8f\u6570\u7ec4\u4e2d\u51fa\u73b0\u6b21\u6570\u8d85\u8fc725%\u7684\u5143\u7d20](/solution/1200-1299/1287.Element%20Appearing%20More%20Than%2025%25%20In%20Sorted%20Array/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1287](https://leetcode.com/problems/element-appearing-more-than-25-in-sorted-array)", "[Element Appearing More Than 25% In Sorted Array](/solution/1200-1299/1287.Element%20Appearing%20More%20Than%2025%25%20In%20Sorted%20Array/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1220", "frontend_question_id": "1125", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/smallest-sufficient-team", "url_en": "https://leetcode.com/problems/smallest-sufficient-team", "relative_path_cn": "/solution/1100-1199/1125.Smallest%20Sufficient%20Team/README.md", "relative_path_en": "/solution/1100-1199/1125.Smallest%20Sufficient%20Team/README_EN.md", "title_cn": "\u6700\u5c0f\u7684\u5fc5\u8981\u56e2\u961f", "title_en": "Smallest Sufficient Team", "question_title_slug": "smallest-sufficient-team", "content_en": "

    In a project, you have a list of required skills req_skills, and a list of people. The ith person people[i] contains a list of skills that the person has.

    \n\n

    Consider a sufficient team: a set of people such that for every required skill in req_skills, there is at least one person in the team who has that skill. We can represent these teams by the index of each person.

    \n\n
      \n\t
    • For example, team = [0, 1, 3] represents the people with skills people[0], people[1], and people[3].
    • \n
    \n\n

    Return any sufficient team of the smallest possible size, represented by the index of each person. You may return the answer in any order.

    \n\n

    It is guaranteed an answer exists.

    \n\n

     

    \n

    Example 1:

    \n
    Input: req_skills = [\"java\",\"nodejs\",\"reactjs\"], people = [[\"java\"],[\"nodejs\"],[\"nodejs\",\"reactjs\"]]\nOutput: [0,2]\n

    Example 2:

    \n
    Input: req_skills = [\"algorithms\",\"math\",\"java\",\"reactjs\",\"csharp\",\"aws\"], people = [[\"algorithms\",\"math\",\"java\"],[\"algorithms\",\"math\",\"reactjs\"],[\"java\",\"csharp\",\"aws\"],[\"reactjs\",\"csharp\"],[\"csharp\",\"math\"],[\"aws\",\"java\"]]\nOutput: [1,2]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= req_skills.length <= 16
    • \n\t
    • 1 <= req_skills[i].length <= 16
    • \n\t
    • req_skills[i] consists of lowercase English letters.
    • \n\t
    • All the strings of req_skills are unique.
    • \n\t
    • 1 <= people.length <= 60
    • \n\t
    • 0 <= people[i].length <= 16
    • \n\t
    • 1 <= people[i][j].length <= 16
    • \n\t
    • people[i][j] consists of lowercase English letters.
    • \n\t
    • All the strings of people[i] are unique.
    • \n\t
    • Every skill in people[i] is a skill in req_skills.
    • \n\t
    • It is guaranteed a sufficient team exists.
    • \n
    \n", "content_cn": "

    \u4f5c\u4e3a\u9879\u76ee\u7ecf\u7406\uff0c\u4f60\u89c4\u5212\u4e86\u4e00\u4efd\u9700\u6c42\u7684\u6280\u80fd\u6e05\u5355\u00a0req_skills\uff0c\u5e76\u6253\u7b97\u4ece\u5907\u9009\u4eba\u5458\u540d\u5355\u00a0people\u00a0\u4e2d\u9009\u51fa\u4e9b\u4eba\u7ec4\u6210\u4e00\u4e2a\u300c\u5fc5\u8981\u56e2\u961f\u300d\uff08 \u7f16\u53f7\u4e3a\u00a0i\u00a0\u7684\u5907\u9009\u4eba\u5458\u00a0people[i]\u00a0\u542b\u6709\u4e00\u4efd\u8be5\u5907\u9009\u4eba\u5458\u638c\u63e1\u7684\u6280\u80fd\u5217\u8868\uff09\u3002

    \n\n

    \u6240\u8c13\u300c\u5fc5\u8981\u56e2\u961f\u300d\uff0c\u5c31\u662f\u5728\u8fd9\u4e2a\u56e2\u961f\u4e2d\uff0c\u5bf9\u4e8e\u6240\u9700\u6c42\u7684\u6280\u80fd\u5217\u8868\u00a0req_skills \u4e2d\u5217\u51fa\u7684\u6bcf\u9879\u6280\u80fd\uff0c\u56e2\u961f\u4e2d\u81f3\u5c11\u6709\u4e00\u540d\u6210\u5458\u5df2\u7ecf\u638c\u63e1\u3002\u53ef\u4ee5\u7528\u6bcf\u4e2a\u4eba\u7684\u7f16\u53f7\u6765\u8868\u793a\u56e2\u961f\u4e2d\u7684\u6210\u5458\uff1a

    \n\n
      \n\t
    • \u4f8b\u5982\uff0c\u56e2\u961f\u00a0team = [0, 1, 3]\u00a0\u8868\u793a\u638c\u63e1\u6280\u80fd\u5206\u522b\u4e3a\u00a0people[0]\uff0cpeople[1]\uff0c\u548c\u00a0people[3]\u00a0\u7684\u5907\u9009\u4eba\u5458\u3002
    • \n
    \n\n

    \u8bf7\u4f60\u8fd4\u56de \u4efb\u4e00\u00a0\u89c4\u6a21\u6700\u5c0f\u7684\u5fc5\u8981\u56e2\u961f\uff0c\u56e2\u961f\u6210\u5458\u7528\u4eba\u5458\u7f16\u53f7\u8868\u793a\u3002\u4f60\u53ef\u4ee5\u6309 \u4efb\u610f\u987a\u5e8f \u8fd4\u56de\u7b54\u6848\uff0c\u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u7b54\u6848\u5b58\u5728\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1areq_skills = [\"java\",\"nodejs\",\"reactjs\"], people = [[\"java\"],[\"nodejs\"],[\"nodejs\",\"reactjs\"]]\n\u8f93\u51fa\uff1a[0,2]\n
    \n\n

    \u793a\u4f8b\u00a02\uff1a

    \n\n
    \n\u8f93\u5165\uff1areq_skills = [\"algorithms\",\"math\",\"java\",\"reactjs\",\"csharp\",\"aws\"], people = [[\"algorithms\",\"math\",\"java\"],[\"algorithms\",\"math\",\"reactjs\"],[\"java\",\"csharp\",\"aws\"],[\"reactjs\",\"csharp\"],[\"csharp\",\"math\"],[\"aws\",\"java\"]]\n\u8f93\u51fa\uff1a[1,2]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= req_skills.length <= 16
    • \n\t
    • 1 <= req_skills[i].length <= 16
    • \n\t
    • req_skills[i] \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n\t
    • req_skills \u4e2d\u7684\u6240\u6709\u5b57\u7b26\u4e32 \u4e92\u4e0d\u76f8\u540c
    • \n\t
    • 1 <= people.length <= 60
    • \n\t
    • 0 <= people[i].length <= 16
    • \n\t
    • 1 <= people[i][j].length <= 16
    • \n\t
    • people[i][j] \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n\t
    • people[i] \u4e2d\u7684\u6240\u6709\u5b57\u7b26\u4e32 \u4e92\u4e0d\u76f8\u540c
    • \n\t
    • people[i] \u4e2d\u7684\u6bcf\u4e2a\u6280\u80fd\u662f req_skills \u4e2d\u7684\u6280\u80fd
    • \n\t
    • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u300c\u5fc5\u8981\u56e2\u961f\u300d\u4e00\u5b9a\u5b58\u5728
    • \n
    \n", "tags_en": ["Bit Manipulation", "Dynamic Programming"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector smallestSufficientTeam(vector& req_skills, vector>& people) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] smallestSufficientTeam(String[] req_skills, List> people) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def smallestSufficientTeam(self, req_skills, people):\n \"\"\"\n :type req_skills: List[str]\n :type people: List[List[str]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def smallestSufficientTeam(self, req_skills: List[str], people: List[List[str]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* smallestSufficientTeam(char ** req_skills, int req_skillsSize, char *** people, int peopleSize, int* peopleColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] SmallestSufficientTeam(string[] req_skills, IList> people) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} req_skills\n * @param {string[][]} people\n * @return {number[]}\n */\nvar smallestSufficientTeam = function(req_skills, people) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} req_skills\n# @param {String[][]} people\n# @return {Integer[]}\ndef smallest_sufficient_team(req_skills, people)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func smallestSufficientTeam(_ req_skills: [String], _ people: [[String]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func smallestSufficientTeam(req_skills []string, people [][]string) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def smallestSufficientTeam(req_skills: Array[String], people: List[List[String]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun smallestSufficientTeam(req_skills: Array, people: List>): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn smallest_sufficient_team(req_skills: Vec, people: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $req_skills\n * @param String[][] $people\n * @return Integer[]\n */\n function smallestSufficientTeam($req_skills, $people) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function smallestSufficientTeam(req_skills: string[], people: string[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (smallest-sufficient-team req_skills people)\n (-> (listof string?) (listof (listof string?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1125](https://leetcode-cn.com/problems/smallest-sufficient-team)", "[\u6700\u5c0f\u7684\u5fc5\u8981\u56e2\u961f](/solution/1100-1199/1125.Smallest%20Sufficient%20Team/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1125](https://leetcode.com/problems/smallest-sufficient-team)", "[Smallest Sufficient Team](/solution/1100-1199/1125.Smallest%20Sufficient%20Team/README_EN.md)", "`Bit Manipulation`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "1219", "frontend_question_id": "1124", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-well-performing-interval", "url_en": "https://leetcode.com/problems/longest-well-performing-interval", "relative_path_cn": "/solution/1100-1199/1124.Longest%20Well-Performing%20Interval/README.md", "relative_path_en": "/solution/1100-1199/1124.Longest%20Well-Performing%20Interval/README_EN.md", "title_cn": "\u8868\u73b0\u826f\u597d\u7684\u6700\u957f\u65f6\u95f4\u6bb5", "title_en": "Longest Well-Performing Interval", "question_title_slug": "longest-well-performing-interval", "content_en": "

    We are given hours, a list of the number of hours worked per day for a given employee.

    \n\n

    A day is considered to be a tiring day if and only if the number of hours worked is (strictly) greater than 8.

    \n\n

    A well-performing interval is an interval of days for which the number of tiring days is strictly larger than the number of non-tiring days.

    \n\n

    Return the length of the longest well-performing interval.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: hours = [9,9,6,0,6,6,9]\nOutput: 3\nExplanation: The longest well-performing interval is [9,9,6].\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= hours.length <= 10000
    • \n\t
    • 0 <= hours[i] <= 16
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4efd\u5de5\u4f5c\u65f6\u95f4\u8868 hours\uff0c\u4e0a\u9762\u8bb0\u5f55\u7740\u67d0\u4e00\u4f4d\u5458\u5de5\u6bcf\u5929\u7684\u5de5\u4f5c\u5c0f\u65f6\u6570\u3002

    \n\n

    \u6211\u4eec\u8ba4\u4e3a\u5f53\u5458\u5de5\u4e00\u5929\u4e2d\u7684\u5de5\u4f5c\u5c0f\u65f6\u6570\u5927\u4e8e 8 \u5c0f\u65f6\u7684\u65f6\u5019\uff0c\u90a3\u4e48\u8fd9\u4e00\u5929\u5c31\u662f\u300c\u52b3\u7d2f\u7684\u4e00\u5929\u300d\u3002

    \n\n

    \u6240\u8c13\u300c\u8868\u73b0\u826f\u597d\u7684\u65f6\u95f4\u6bb5\u300d\uff0c\u610f\u5473\u5728\u8fd9\u6bb5\u65f6\u95f4\u5185\uff0c\u300c\u52b3\u7d2f\u7684\u5929\u6570\u300d\u662f\u4e25\u683c \u5927\u4e8e\u300c\u4e0d\u52b3\u7d2f\u7684\u5929\u6570\u300d\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u300c\u8868\u73b0\u826f\u597d\u65f6\u95f4\u6bb5\u300d\u7684\u6700\u5927\u957f\u5ea6\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1ahours = [9,9,6,0,6,6,9]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6700\u957f\u7684\u8868\u73b0\u826f\u597d\u65f6\u95f4\u6bb5\u662f [9,9,6]\u3002
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= hours.length <= 10000
    • \n\t
    • 0 <= hours[i] <= 16
    • \n
    \n", "tags_en": ["Stack"], "tags_cn": ["\u6808"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int longestWPI(vector& hours) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int longestWPI(int[] hours) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestWPI(self, hours):\n \"\"\"\n :type hours: List[int]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestWPI(self, hours: List[int]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint longestWPI(int* hours, int hoursSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LongestWPI(int[] hours) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} hours\n * @return {number}\n */\nvar longestWPI = function(hours) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} hours\n# @return {Integer}\ndef longest_wpi(hours)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestWPI(_ hours: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestWPI(hours []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestWPI(hours: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestWPI(hours: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_wpi(hours: Vec) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $hours\n * @return Integer\n */\n function longestWPI($hours) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestWPI(hours: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-wpi hours)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1124](https://leetcode-cn.com/problems/longest-well-performing-interval)", "[\u8868\u73b0\u826f\u597d\u7684\u6700\u957f\u65f6\u95f4\u6bb5](/solution/1100-1199/1124.Longest%20Well-Performing%20Interval/README.md)", "`\u6808`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1124](https://leetcode.com/problems/longest-well-performing-interval)", "[Longest Well-Performing Interval](/solution/1100-1199/1124.Longest%20Well-Performing%20Interval/README_EN.md)", "`Stack`", "Medium", ""]}, {"question_id": "1218", "frontend_question_id": "1123", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/lowest-common-ancestor-of-deepest-leaves", "url_en": "https://leetcode.com/problems/lowest-common-ancestor-of-deepest-leaves", "relative_path_cn": "/solution/1100-1199/1123.Lowest%20Common%20Ancestor%20of%20Deepest%20Leaves/README.md", "relative_path_en": "/solution/1100-1199/1123.Lowest%20Common%20Ancestor%20of%20Deepest%20Leaves/README_EN.md", "title_cn": "\u6700\u6df1\u53f6\u8282\u70b9\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148", "title_en": "Lowest Common Ancestor of Deepest Leaves", "question_title_slug": "lowest-common-ancestor-of-deepest-leaves", "content_en": "

    Given the root of a binary tree, return the lowest common ancestor of its deepest leaves.

    \n\n

    Recall that:

    \n\n
      \n\t
    • The node of a binary tree is a leaf if and only if it has no children
    • \n\t
    • The depth of the root of the tree is 0. if the depth of a node is d, the depth of each of its children is d + 1.
    • \n\t
    • The lowest common ancestor of a set S of nodes, is the node A with the largest depth such that every node in S is in the subtree with root A.
    • \n
    \n\n

    Note: This question is the same as 865: https://leetcode.com/problems/smallest-subtree-with-all-the-deepest-nodes/

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [3,5,1,6,2,0,8,null,null,7,4]\nOutput: [2,7,4]\nExplanation: We return the node with value 2, colored in yellow in the diagram.\nThe nodes coloured in blue are the deepest leaf-nodes of the tree.\nNote that nodes 6, 0, and 8 are also leaf nodes, but the depth of them is 2, but the depth of nodes 7 and 4 is 3.
    \n\n

    Example 2:

    \n\n
    \nInput: root = [1]\nOutput: [1]\nExplanation: The root is the deepest node in the tree, and it's the lca of itself.\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = [0,1,3,null,2]\nOutput: [2]\nExplanation: The deepest leaf node in the tree is 2, the lca of one node is itself.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree will be in the range [1, 1000].
    • \n\t
    • 0 <= Node.val <= 1000
    • \n\t
    • The values of the nodes in the tree are unique.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6709\u6839\u8282\u70b9\u7684\u4e8c\u53c9\u6811\uff0c\u627e\u5230\u5b83\u6700\u6df1\u7684\u53f6\u8282\u70b9\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148\u3002

    \n\n

    \u56de\u60f3\u4e00\u4e0b\uff1a

    \n\n
      \n\t
    • \u53f6\u8282\u70b9 \u662f\u4e8c\u53c9\u6811\u4e2d\u6ca1\u6709\u5b50\u8282\u70b9\u7684\u8282\u70b9
    • \n\t
    • \u6811\u7684\u6839\u8282\u70b9\u7684\u00a0\u6df1\u5ea6\u00a0\u4e3a\u00a00\uff0c\u5982\u679c\u67d0\u4e00\u8282\u70b9\u7684\u6df1\u5ea6\u4e3a\u00a0d\uff0c\u90a3\u5b83\u7684\u5b50\u8282\u70b9\u7684\u6df1\u5ea6\u5c31\u662f\u00a0d+1
    • \n\t
    • \u5982\u679c\u6211\u4eec\u5047\u5b9a A \u662f\u4e00\u7ec4\u8282\u70b9\u00a0S\u00a0\u7684 \u6700\u8fd1\u516c\u5171\u7956\u5148\uff0cS\u00a0\u4e2d\u7684\u6bcf\u4e2a\u8282\u70b9\u90fd\u5728\u4ee5 A \u4e3a\u6839\u8282\u70b9\u7684\u5b50\u6811\u4e2d\uff0c\u4e14 A\u00a0\u7684\u6df1\u5ea6\u8fbe\u5230\u6b64\u6761\u4ef6\u4e0b\u53ef\u80fd\u7684\u6700\u5927\u503c\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u6ce8\u610f\uff1a\u672c\u9898\u4e0e\u529b\u6263 865 \u91cd\u590d\uff1ahttps://leetcode-cn.com/problems/smallest-subtree-with-all-the-deepest-nodes/

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [3,5,1,6,2,0,8,null,null,7,4]\n\u8f93\u51fa\uff1a[2,7,4]\n\u89e3\u91ca\uff1a\n\u6211\u4eec\u8fd4\u56de\u503c\u4e3a 2 \u7684\u8282\u70b9\uff0c\u5728\u56fe\u4e2d\u7528\u9ec4\u8272\u6807\u8bb0\u3002\n\u5728\u56fe\u4e2d\u7528\u84dd\u8272\u6807\u8bb0\u7684\u662f\u6811\u7684\u6700\u6df1\u7684\u8282\u70b9\u3002\n\u6ce8\u610f\uff0c\u8282\u70b9 6\u30010 \u548c 8 \u4e5f\u662f\u53f6\u8282\u70b9\uff0c\u4f46\u662f\u5b83\u4eec\u7684\u6df1\u5ea6\u662f 2 \uff0c\u800c\u8282\u70b9 7 \u548c 4 \u7684\u6df1\u5ea6\u662f 3 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [1]\n\u8f93\u51fa\uff1a[1]\n\u89e3\u91ca\uff1a\u6839\u8282\u70b9\u662f\u6811\u4e2d\u6700\u6df1\u7684\u8282\u70b9\uff0c\u5b83\u662f\u5b83\u672c\u8eab\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [0,1,3,null,2]\n\u8f93\u51fa\uff1a[2]\n\u89e3\u91ca\uff1a\u6811\u4e2d\u6700\u6df1\u7684\u53f6\u8282\u70b9\u662f 2 \uff0c\u6700\u8fd1\u516c\u5171\u7956\u5148\u662f\u5b83\u81ea\u5df1\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u7ed9\u4f60\u7684\u6811\u4e2d\u5c06\u6709\u00a01 \u5230 1000 \u4e2a\u8282\u70b9\u3002
    • \n\t
    • \u6811\u4e2d\u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u90fd\u5728 1 \u5230 1000 \u4e4b\u95f4\u3002
    • \n\t
    • \u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u90fd\u662f\u72ec\u4e00\u65e0\u4e8c\u7684\u3002
    • \n
    \n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* lcaDeepestLeaves(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode lcaDeepestLeaves(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def lcaDeepestLeaves(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: TreeNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def lcaDeepestLeaves(self, root: TreeNode) -> TreeNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* lcaDeepestLeaves(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode LcaDeepestLeaves(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {TreeNode}\n */\nvar lcaDeepestLeaves = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {TreeNode}\ndef lca_deepest_leaves(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func lcaDeepestLeaves(_ root: TreeNode?) -> TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc lcaDeepestLeaves(root *TreeNode) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def lcaDeepestLeaves(root: TreeNode): TreeNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun lcaDeepestLeaves(root: TreeNode?): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn lca_deepest_leaves(root: Option>>) -> Option>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return TreeNode\n */\n function lcaDeepestLeaves($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction lcaDeepestLeaves(root: TreeNode | null): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (lca-deepest-leaves root)\n (-> (or/c tree-node? #f) (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1123](https://leetcode-cn.com/problems/lowest-common-ancestor-of-deepest-leaves)", "[\u6700\u6df1\u53f6\u8282\u70b9\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148](/solution/1100-1199/1123.Lowest%20Common%20Ancestor%20of%20Deepest%20Leaves/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1123](https://leetcode.com/problems/lowest-common-ancestor-of-deepest-leaves)", "[Lowest Common Ancestor of Deepest Leaves](/solution/1100-1199/1123.Lowest%20Common%20Ancestor%20of%20Deepest%20Leaves/README_EN.md)", "`Tree`,`Depth-first Search`", "Medium", ""]}, {"question_id": "1217", "frontend_question_id": "1122", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/relative-sort-array", "url_en": "https://leetcode.com/problems/relative-sort-array", "relative_path_cn": "/solution/1100-1199/1122.Relative%20Sort%20Array/README.md", "relative_path_en": "/solution/1100-1199/1122.Relative%20Sort%20Array/README_EN.md", "title_cn": "\u6570\u7ec4\u7684\u76f8\u5bf9\u6392\u5e8f", "title_en": "Relative Sort Array", "question_title_slug": "relative-sort-array", "content_en": "

    Given two arrays arr1 and arr2, the elements of arr2 are distinct, and all elements in arr2 are also in arr1.

    \n\n

    Sort the elements of arr1 such that the relative ordering of items in arr1 are the same as in arr2.  Elements that don't appear in arr2 should be placed at the end of arr1 in ascending order.

    \n\n

     

    \n

    Example 1:

    \n
    Input: arr1 = [2,3,1,3,2,4,6,7,9,2,19], arr2 = [2,1,4,3,9,6]\nOutput: [2,2,2,1,4,3,3,9,6,7,19]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= arr1.length, arr2.length <= 1000
    • \n\t
    • 0 <= arr1[i], arr2[i] <= 1000
    • \n\t
    • All the elements of arr2 are distinct.
    • \n\t
    • Each arr2[i] is in arr1.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u6570\u7ec4\uff0carr1 \u548c\u00a0arr2\uff0c

    \n\n
      \n\t
    • arr2\u00a0\u4e2d\u7684\u5143\u7d20\u5404\u4e0d\u76f8\u540c
    • \n\t
    • arr2 \u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u90fd\u51fa\u73b0\u5728\u00a0arr1\u00a0\u4e2d
    • \n
    \n\n

    \u5bf9 arr1\u00a0\u4e2d\u7684\u5143\u7d20\u8fdb\u884c\u6392\u5e8f\uff0c\u4f7f arr1 \u4e2d\u9879\u7684\u76f8\u5bf9\u987a\u5e8f\u548c\u00a0arr2\u00a0\u4e2d\u7684\u76f8\u5bf9\u987a\u5e8f\u76f8\u540c\u3002\u672a\u5728\u00a0arr2\u00a0\u4e2d\u51fa\u73b0\u8fc7\u7684\u5143\u7d20\u9700\u8981\u6309\u7167\u5347\u5e8f\u653e\u5728\u00a0arr1\u00a0\u7684\u672b\u5c3e\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr1 = [2,3,1,3,2,4,6,7,9,2,19], arr2 = [2,1,4,3,9,6]\n\u8f93\u51fa\uff1a[2,2,2,1,4,3,3,9,6,7,19]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= arr1.length, arr2.length <= 1000
    • \n\t
    • 0 <= arr1[i], arr2[i] <= 1000
    • \n\t
    • arr2\u00a0\u4e2d\u7684\u5143\u7d20\u00a0arr2[i]\u00a0\u5404\u4e0d\u76f8\u540c
    • \n\t
    • arr2 \u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u00a0arr2[i]\u00a0\u90fd\u51fa\u73b0\u5728\u00a0arr1\u00a0\u4e2d
    • \n
    \n", "tags_en": ["Sort", "Array"], "tags_cn": ["\u6392\u5e8f", "\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector relativeSortArray(vector& arr1, vector& arr2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] relativeSortArray(int[] arr1, int[] arr2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def relativeSortArray(self, arr1, arr2):\n \"\"\"\n :type arr1: List[int]\n :type arr2: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def relativeSortArray(self, arr1: List[int], arr2: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* relativeSortArray(int* arr1, int arr1Size, int* arr2, int arr2Size, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] RelativeSortArray(int[] arr1, int[] arr2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr1\n * @param {number[]} arr2\n * @return {number[]}\n */\nvar relativeSortArray = function(arr1, arr2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr1\n# @param {Integer[]} arr2\n# @return {Integer[]}\ndef relative_sort_array(arr1, arr2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func relativeSortArray(_ arr1: [Int], _ arr2: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func relativeSortArray(arr1 []int, arr2 []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def relativeSortArray(arr1: Array[Int], arr2: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun relativeSortArray(arr1: IntArray, arr2: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn relative_sort_array(arr1: Vec, arr2: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr1\n * @param Integer[] $arr2\n * @return Integer[]\n */\n function relativeSortArray($arr1, $arr2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function relativeSortArray(arr1: number[], arr2: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (relative-sort-array arr1 arr2)\n (-> (listof exact-integer?) (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1122](https://leetcode-cn.com/problems/relative-sort-array)", "[\u6570\u7ec4\u7684\u76f8\u5bf9\u6392\u5e8f](/solution/1100-1199/1122.Relative%20Sort%20Array/README.md)", "`\u6392\u5e8f`,`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1122](https://leetcode.com/problems/relative-sort-array)", "[Relative Sort Array](/solution/1100-1199/1122.Relative%20Sort%20Array/README_EN.md)", "`Sort`,`Array`", "Easy", ""]}, {"question_id": "1216", "frontend_question_id": "1116", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/print-zero-even-odd", "url_en": "https://leetcode.com/problems/print-zero-even-odd", "relative_path_cn": "/solution/1100-1199/1116.Print%20Zero%20Even%20Odd/README.md", "relative_path_en": "/solution/1100-1199/1116.Print%20Zero%20Even%20Odd/README_EN.md", "title_cn": "\u6253\u5370\u96f6\u4e0e\u5947\u5076\u6570", "title_en": "Print Zero Even Odd", "question_title_slug": "print-zero-even-odd", "content_en": "

    Suppose you are given the following code:

    \n\n
    \nclass ZeroEvenOdd {\n  public ZeroEvenOdd(int n) { ... }      // constructor\n  public void zero(printNumber) { ... }  // only output 0's\n  public void even(printNumber) { ... }  // only output even numbers\n  public void odd(printNumber) { ... }   // only output odd numbers\n}\n
    \n\n

    The same instance of ZeroEvenOdd will be passed to three different threads:

    \n\n
      \n\t
    1. Thread A will call zero() which should only output 0's.
    2. \n\t
    3. Thread B will call even() which should only ouput even numbers.
    4. \n\t
    5. Thread C will call odd() which should only output odd numbers.
    6. \n
    \n\n

    Each of the threads is given a printNumber method to output an integer. Modify the given program to output the series 010203040506... where the length of the series must be 2n.

    \n\n

     

    \n\n

    Example 1:

    \n\n
    \nInput: n = 2\nOutput: "0102"\nExplanation: There are three threads being fired asynchronously. One of them calls zero(), the other calls even(), and the last one calls odd(). "0102" is the correct output.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 5\nOutput: "0102030405"\n
    \n", "content_cn": "

    \u5047\u8bbe\u6709\u8fd9\u4e48\u4e00\u4e2a\u7c7b\uff1a

    \n\n
    class ZeroEvenOdd {\n  public ZeroEvenOdd(int n) { ... }      // \u6784\u9020\u51fd\u6570\n  public void zero(printNumber) { ... }  // \u4ec5\u6253\u5370\u51fa 0\n  public void even(printNumber) { ... }  // \u4ec5\u6253\u5370\u51fa \u5076\u6570\n  public void odd(printNumber) { ... }   // \u4ec5\u6253\u5370\u51fa \u5947\u6570\n}\n
    \n\n

    \u76f8\u540c\u7684\u4e00\u4e2a ZeroEvenOdd \u7c7b\u5b9e\u4f8b\u5c06\u4f1a\u4f20\u9012\u7ed9\u4e09\u4e2a\u4e0d\u540c\u7684\u7ebf\u7a0b\uff1a

    \n\n
      \n\t
    1. \u7ebf\u7a0b A \u5c06\u8c03\u7528 zero()\uff0c\u5b83\u53ea\u8f93\u51fa 0 \u3002
    2. \n\t
    3. \u7ebf\u7a0b B \u5c06\u8c03\u7528 even()\uff0c\u5b83\u53ea\u8f93\u51fa\u5076\u6570\u3002
    4. \n\t
    5. \u7ebf\u7a0b C \u5c06\u8c03\u7528 odd()\uff0c\u5b83\u53ea\u8f93\u51fa\u5947\u6570\u3002
    6. \n
    \n\n

    \u6bcf\u4e2a\u7ebf\u7a0b\u90fd\u6709\u4e00\u4e2a printNumber \u65b9\u6cd5\u6765\u8f93\u51fa\u4e00\u4e2a\u6574\u6570\u3002\u8bf7\u4fee\u6539\u7ed9\u51fa\u7684\u4ee3\u7801\u4ee5\u8f93\u51fa\u6574\u6570\u5e8f\u5217 010203040506... \uff0c\u5176\u4e2d\u5e8f\u5217\u7684\u957f\u5ea6\u5fc5\u987b\u4e3a 2n\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1an = 2\n\u8f93\u51fa\uff1a"0102"\n\u8bf4\u660e\uff1a\u4e09\u6761\u7ebf\u7a0b\u5f02\u6b65\u6267\u884c\uff0c\u5176\u4e2d\u4e00\u4e2a\u8c03\u7528 zero()\uff0c\u53e6\u4e00\u4e2a\u7ebf\u7a0b\u8c03\u7528 even()\uff0c\u6700\u540e\u4e00\u4e2a\u7ebf\u7a0b\u8c03\u7528odd()\u3002\u6b63\u786e\u7684\u8f93\u51fa\u4e3a "0102"\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1an = 5\n\u8f93\u51fa\uff1a"0102030405"\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class ZeroEvenOdd {\nprivate:\n int n;\n\npublic:\n ZeroEvenOdd(int n) {\n this->n = n;\n }\n\n // printNumber(x) outputs \"x\", where x is an integer.\n void zero(function printNumber) {\n \n }\n\n void even(function printNumber) {\n \n }\n\n void odd(function printNumber) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class ZeroEvenOdd {\n private int n;\n \n public ZeroEvenOdd(int n) {\n this.n = n;\n }\n\n // printNumber.accept(x) outputs \"x\", where x is an integer.\n public void zero(IntConsumer printNumber) throws InterruptedException {\n \n }\n\n public void even(IntConsumer printNumber) throws InterruptedException {\n \n }\n\n public void odd(IntConsumer printNumber) throws InterruptedException {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class ZeroEvenOdd(object):\n def __init__(self, n):\n self.n = n\n \n \n\t# printNumber(x) outputs \"x\", where x is an integer.\n def zero(self, printNumber):\n \"\"\"\n :type printNumber: method\n :rtype: void\n \"\"\"\n \n \n \n def even(self, printNumber):\n \"\"\"\n :type printNumber: method\n :rtype: void\n \"\"\"\n \n \n \n def odd(self, printNumber):\n \"\"\"\n :type printNumber: method\n :rtype: void\n \"\"\"\n \n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class ZeroEvenOdd:\n def __init__(self, n):\n self.n = n\n \n \n\t# printNumber(x) outputs \"x\", where x is an integer.\n def zero(self, printNumber: 'Callable[[int], None]') -> None:\n \n \n \n def even(self, printNumber: 'Callable[[int], None]') -> None:\n \n \n \n def odd(self, printNumber: 'Callable[[int], None]') -> None:\n \n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "typedef struct {\n int n;\n} ZeroEvenOdd;\n\nZeroEvenOdd* zeroEvenOddCreate(int n) {\n ZeroEvenOdd* obj = (ZeroEvenOdd*) malloc(sizeof(ZeroEvenOdd));\n obj->n = n;\n return obj;\n}\n\n// You may call global function `void printNumber(int x)`\n// to output \"x\", where x is an integer.\n\nvoid zero(ZeroEvenOdd* obj) {\n \n}\n\nvoid even(ZeroEvenOdd* obj) {\n \n}\n\nvoid odd(ZeroEvenOdd* obj) {\n \n}\n\nvoid zeroEvenOddFree(ZeroEvenOdd* obj) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class ZeroEvenOdd {\n private int n;\n \n public ZeroEvenOdd(int n) {\n this.n = n;\n }\n\n // printNumber(x) outputs \"x\", where x is an integer.\n public void Zero(Action printNumber) {\n \n }\n\n public void Even(Action printNumber) {\n \n }\n\n public void Odd(Action printNumber) {\n \n }\n}", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1116](https://leetcode-cn.com/problems/print-zero-even-odd)", "[\u6253\u5370\u96f6\u4e0e\u5947\u5076\u6570](/solution/1100-1199/1116.Print%20Zero%20Even%20Odd/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1116](https://leetcode.com/problems/print-zero-even-odd)", "[Print Zero Even Odd](/solution/1100-1199/1116.Print%20Zero%20Even%20Odd/README_EN.md)", "", "Medium", ""]}, {"question_id": "1215", "frontend_question_id": "1113", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/reported-posts", "url_en": "https://leetcode.com/problems/reported-posts", "relative_path_cn": "/solution/1100-1199/1113.Reported%20Posts/README.md", "relative_path_en": "/solution/1100-1199/1113.Reported%20Posts/README_EN.md", "title_cn": "\u62a5\u544a\u7684\u8bb0\u5f55", "title_en": "Reported Posts", "question_title_slug": "reported-posts", "content_en": "

    Table: Actions

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| user_id       | int     |\n| post_id       | int     |\n| action_date   | date    | \n| action        | enum    |\n| extra         | varchar |\n+---------------+---------+\nThere is no primary key for this table, it may have duplicate rows.\nThe action column is an ENUM type of ('view', 'like', 'reaction', 'comment', 'report', 'share').\nThe extra column has optional information about the action such as a reason for report or a type of reaction. 
    \n\n

     

    \n\n

    Write an SQL query that reports the number of posts reported yesterday for each report reason. Assume today is 2019-07-05.

    \n\n

    The query result format is in the following example:

    \n\n
    \nActions table:\n+---------+---------+-------------+--------+--------+\n| user_id | post_id | action_date | action | extra  |\n+---------+---------+-------------+--------+--------+\n| 1       | 1       | 2019-07-01  | view   | null   |\n| 1       | 1       | 2019-07-01  | like   | null   |\n| 1       | 1       | 2019-07-01  | share  | null   |\n| 2       | 4       | 2019-07-04  | view   | null   |\n| 2       | 4       | 2019-07-04  | report | spam   |\n| 3       | 4       | 2019-07-04  | view   | null   |\n| 3       | 4       | 2019-07-04  | report | spam   |\n| 4       | 3       | 2019-07-02  | view   | null   |\n| 4       | 3       | 2019-07-02  | report | spam   |\n| 5       | 2       | 2019-07-04  | view   | null   |\n| 5       | 2       | 2019-07-04  | report | racism |\n| 5       | 5       | 2019-07-04  | view   | null   |\n| 5       | 5       | 2019-07-04  | report | racism |\n+---------+---------+-------------+--------+--------+\n\nResult table:\n+---------------+--------------+\n| report_reason | report_count |\n+---------------+--------------+\n| spam          | 1            |\n| racism        | 2            |\n+---------------+--------------+ \nNote that we only care about report reasons with non zero number of reports.
    \n", "content_cn": "

    \u52a8\u4f5c\u8868\uff1aActions

    \n\n
    +---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| user_id       | int     |\n| post_id       | int     |\n| action_date   | date    | \n| action        | enum    |\n| extra         | varchar |\n+---------------+---------+\n\u6b64\u8868\u6ca1\u6709\u4e3b\u952e\uff0c\u6240\u4ee5\u53ef\u80fd\u4f1a\u6709\u91cd\u590d\u7684\u884c\u3002\naction \u5b57\u6bb5\u662f ENUM \u7c7b\u578b\u7684\uff0c\u5305\u542b:('view', 'like', 'reaction', 'comment', 'report', 'share')\nextra \u5b57\u6bb5\u662f\u53ef\u9009\u7684\u4fe1\u606f\uff08\u53ef\u80fd\u4e3a null\uff09\uff0c\u5176\u4e2d\u7684\u4fe1\u606f\u4f8b\u5982\u6709\uff1a1.\u62a5\u544a\u7406\u7531(a reason for report) 2.\u53cd\u5e94\u7c7b\u578b(a type of reaction)\n
    \n\n

     

    \n\n

    \u7f16\u5199\u4e00\u6761SQL\uff0c\u67e5\u8be2\u6bcf\u79cd \u62a5\u544a\u7406\u7531\uff08report reason\uff09\u5728\u6628\u5929\u7684\u4e0d\u540c\u62a5\u544a\u6570\u91cf\uff08post_id\uff09\u3002\u5047\u8bbe\u4eca\u5929\u662f 2019-07-05\u3002

    \n\n

    \u67e5\u8be2\u53ca\u7ed3\u679c\u7684\u683c\u5f0f\u793a\u4f8b\uff1a

    \n\n
    Actions table:\n+---------+---------+-------------+--------+--------+\n| user_id | post_id | action_date | action | extra  |\n+---------+---------+-------------+--------+--------+\n| 1       | 1       | 2019-07-01  | view   | null   |\n| 1       | 1       | 2019-07-01  | like   | null   |\n| 1       | 1       | 2019-07-01  | share  | null   |\n| 2       | 4       | 2019-07-04  | view   | null   |\n| 2       | 4       | 2019-07-04  | report | spam   |\n| 3       | 4       | 2019-07-04  | view   | null   |\n| 3       | 4       | 2019-07-04  | report | spam   |\n| 4       | 3       | 2019-07-02  | view   | null   |\n| 4       | 3       | 2019-07-02  | report | spam   |\n| 5       | 2       | 2019-07-04  | view   | null   |\n| 5       | 2       | 2019-07-04  | report | racism |\n| 5       | 5       | 2019-07-04  | view   | null   |\n| 5       | 5       | 2019-07-04  | report | racism |\n+---------+---------+-------------+--------+--------+\n\nResult table:\n+---------------+--------------+\n| report_reason | report_count |\n+---------------+--------------+\n| spam          | 1            |\n| racism        | 2            |\n+---------------+--------------+ \n\u6ce8\u610f\uff0c\u6211\u4eec\u53ea\u5173\u5fc3\u62a5\u544a\u6570\u91cf\u975e\u96f6\u7684\u7ed3\u679c\u3002\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1113](https://leetcode-cn.com/problems/reported-posts)", "[\u62a5\u544a\u7684\u8bb0\u5f55](/solution/1100-1199/1113.Reported%20Posts/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1113](https://leetcode.com/problems/reported-posts)", "[Reported Posts](/solution/1100-1199/1113.Reported%20Posts/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1214", "frontend_question_id": "1112", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/highest-grade-for-each-student", "url_en": "https://leetcode.com/problems/highest-grade-for-each-student", "relative_path_cn": "/solution/1100-1199/1112.Highest%20Grade%20For%20Each%20Student/README.md", "relative_path_en": "/solution/1100-1199/1112.Highest%20Grade%20For%20Each%20Student/README_EN.md", "title_cn": "\u6bcf\u4f4d\u5b66\u751f\u7684\u6700\u9ad8\u6210\u7ee9", "title_en": "Highest Grade For Each Student", "question_title_slug": "highest-grade-for-each-student", "content_en": "

    Table: Enrollments

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| student_id    | int     |\n| course_id     | int     |\n| grade         | int     |\n+---------------+---------+\n(student_id, course_id) is the primary key of this table.\n\n
    \n\n

    Write a SQL query to find the highest grade with its corresponding course for each student. In case of a tie, you should find the course with the smallest course_id. The output must be sorted by increasing student_id.

    \n\n

    The query result format is in the following example:

    \n\n
    \nEnrollments table:\n+------------+-------------------+\n| student_id | course_id | grade |\n+------------+-----------+-------+\n| 2          | 2         | 95    |\n| 2          | 3         | 95    |\n| 1          | 1         | 90    |\n| 1          | 2         | 99    |\n| 3          | 1         | 80    |\n| 3          | 2         | 75    |\n| 3          | 3         | 82    |\n+------------+-----------+-------+\n\nResult table:\n+------------+-------------------+\n| student_id | course_id | grade |\n+------------+-----------+-------+\n| 1          | 2         | 99    |\n| 2          | 2         | 95    |\n| 3          | 3         | 82    |\n+------------+-----------+-------+\n
    \n", "content_cn": "

    \u8868\uff1aEnrollments

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| student_id    | int     |\n| course_id     | int     |\n| grade         | int     |\n+---------------+---------+\n(student_id, course_id) \u662f\u8be5\u8868\u7684\u4e3b\u952e\u3002\n\n
    \n\n

     

    \n\n

    \u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\uff0c\u67e5\u8be2\u6bcf\u4f4d\u5b66\u751f\u83b7\u5f97\u7684\u6700\u9ad8\u6210\u7ee9\u548c\u5b83\u6240\u5bf9\u5e94\u7684\u79d1\u76ee\uff0c\u82e5\u79d1\u76ee\u6210\u7ee9\u5e76\u5217\uff0c\u53d6 course_id \u6700\u5c0f\u7684\u4e00\u95e8\u3002\u67e5\u8be2\u7ed3\u679c\u9700\u6309 student_id \u589e\u5e8f\u8fdb\u884c\u6392\u5e8f\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u6240\u793a\uff1a

    \n\n
    \nEnrollments \u8868\uff1a\n+------------+-------------------+\n| student_id | course_id | grade |\n+------------+-----------+-------+\n| 2          | 2         | 95    |\n| 2          | 3         | 95    |\n| 1          | 1         | 90    |\n| 1          | 2         | 99    |\n| 3          | 1         | 80    |\n| 3          | 2         | 75    |\n| 3          | 3         | 82    |\n+------------+-----------+-------+\n\nResult \u8868\uff1a\n+------------+-------------------+\n| student_id | course_id | grade |\n+------------+-----------+-------+\n| 1          | 2         | 99    |\n| 2          | 2         | 95    |\n| 3          | 3         | 82    |\n+------------+-----------+-------+\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1112](https://leetcode-cn.com/problems/highest-grade-for-each-student)", "[\u6bcf\u4f4d\u5b66\u751f\u7684\u6700\u9ad8\u6210\u7ee9](/solution/1100-1199/1112.Highest%20Grade%20For%20Each%20Student/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1112](https://leetcode.com/problems/highest-grade-for-each-student)", "[Highest Grade For Each Student](/solution/1100-1199/1112.Highest%20Grade%20For%20Each%20Student/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1213", "frontend_question_id": "1259", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/handshakes-that-dont-cross", "url_en": "https://leetcode.com/problems/handshakes-that-dont-cross", "relative_path_cn": "/solution/1200-1299/1259.Handshakes%20That%20Don%27t%20Cross/README.md", "relative_path_en": "/solution/1200-1299/1259.Handshakes%20That%20Don%27t%20Cross/README_EN.md", "title_cn": "\u4e0d\u76f8\u4ea4\u7684\u63e1\u624b", "title_en": "Handshakes That Don't Cross", "question_title_slug": "handshakes-that-dont-cross", "content_en": "

    You are given an even number of people num_people that stand around a circle and each person shakes hands with someone else, so that there are num_people / 2 handshakes total.

    \n\n

    Return the number of ways these handshakes could occur such that none of the handshakes cross.

    \n\n

    Since this number could be very big, return the answer mod 10^9 + 7

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: num_people = 2\nOutput: 1\n
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: num_people = 4\nOutput: 2\nExplanation: There are two ways to do it, the first way is [(1,2),(3,4)] and the second one is [(2,3),(4,1)].\n
    \n\n

    Example 3:

    \n\n

    \"\"

    \n\n
    \nInput: num_people = 6\nOutput: 5\n
    \n\n

    Example 4:

    \n\n
    \nInput: num_people = 8\nOutput: 14\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= num_people <= 1000
    • \n\t
    • num_people % 2 == 0
    • \n
    \n", "content_cn": "

    \u5076\u6570 \u4e2a\u4eba\u7ad9\u6210\u4e00\u4e2a\u5706\uff0c\u603b\u4eba\u6570\u4e3a num_people \u3002\u6bcf\u4e2a\u4eba\u4e0e\u9664\u81ea\u5df1\u5916\u7684\u4e00\u4e2a\u4eba\u63e1\u624b\uff0c\u6240\u4ee5\u603b\u5171\u4f1a\u6709 num_people / 2 \u6b21\u63e1\u624b\u3002

    \n\n

    \u5c06\u63e1\u624b\u7684\u4eba\u4e4b\u95f4\u8fde\u7ebf\uff0c\u8bf7\u4f60\u8fd4\u56de\u8fde\u7ebf\u4e0d\u4f1a\u76f8\u4ea4\u7684\u63e1\u624b\u65b9\u6848\u6570\u3002

    \n\n

    \u7531\u4e8e\u7ed3\u679c\u53ef\u80fd\u4f1a\u5f88\u5927\uff0c\u8bf7\u4f60\u8fd4\u56de\u7b54\u6848 \u6a21 10^9+7 \u540e\u7684\u7ed3\u679c\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anum_people = 2\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1anum_people = 4\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u603b\u5171\u6709\u4e24\u79cd\u65b9\u6848\uff0c\u7b2c\u4e00\u79cd\u65b9\u6848\u662f [(1,2),(3,4)] \uff0c\u7b2c\u4e8c\u79cd\u65b9\u6848\u662f [(2,3),(4,1)] \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1anum_people = 6\n\u8f93\u51fa\uff1a5\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1anum_people = 8\n\u8f93\u51fa\uff1a14\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= num_people <= 1000
    • \n\t
    • num_people % 2 == 0
    • \n
    \n", "tags_en": ["Math", "Dynamic Programming"], "tags_cn": ["\u6570\u5b66", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numberOfWays(int num_people) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numberOfWays(int num_people) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numberOfWays(self, num_people):\n \"\"\"\n :type num_people: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numberOfWays(self, num_people: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numberOfWays(int num_people){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumberOfWays(int num_people) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} num_people\n * @return {number}\n */\nvar numberOfWays = function(num_people) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} num_people\n# @return {Integer}\ndef number_of_ways(num_people)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numberOfWays(_ num_people: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numberOfWays(num_people int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numberOfWays(num_people: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numberOfWays(num_people: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn number_of_ways(num_people: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $num_people\n * @return Integer\n */\n function numberOfWays($num_people) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numberOfWays(num_people: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (number-of-ways num_people)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1259](https://leetcode-cn.com/problems/handshakes-that-dont-cross)", "[\u4e0d\u76f8\u4ea4\u7684\u63e1\u624b](/solution/1200-1299/1259.Handshakes%20That%20Don%27t%20Cross/README.md)", "`\u6570\u5b66`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1259](https://leetcode.com/problems/handshakes-that-dont-cross)", "[Handshakes That Don't Cross](/solution/1200-1299/1259.Handshakes%20That%20Don%27t%20Cross/README_EN.md)", "`Math`,`Dynamic Programming`", "Hard", "\ud83d\udd12"]}, {"question_id": "1212", "frontend_question_id": "1291", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sequential-digits", "url_en": "https://leetcode.com/problems/sequential-digits", "relative_path_cn": "/solution/1200-1299/1291.Sequential%20Digits/README.md", "relative_path_en": "/solution/1200-1299/1291.Sequential%20Digits/README_EN.md", "title_cn": "\u987a\u6b21\u6570", "title_en": "Sequential Digits", "question_title_slug": "sequential-digits", "content_en": "

    An integer has sequential digits if and only if each digit in the number is one more than the previous digit.

    \n\n

    Return a sorted list of all the integers in the range [low, high] inclusive that have sequential digits.

    \n\n

     

    \n

    Example 1:

    \n
    Input: low = 100, high = 300\nOutput: [123,234]\n

    Example 2:

    \n
    Input: low = 1000, high = 13000\nOutput: [1234,2345,3456,4567,5678,6789,12345]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 10 <= low <= high <= 10^9
    • \n
    \n", "content_cn": "

    \u6211\u4eec\u5b9a\u4e49\u300c\u987a\u6b21\u6570\u300d\u4e3a\uff1a\u6bcf\u4e00\u4f4d\u4e0a\u7684\u6570\u5b57\u90fd\u6bd4\u524d\u4e00\u4f4d\u4e0a\u7684\u6570\u5b57\u5927 1 \u7684\u6574\u6570\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u7531 [low, high] \u8303\u56f4\u5185\u6240\u6709\u987a\u6b21\u6570\u7ec4\u6210\u7684 \u6709\u5e8f \u5217\u8868\uff08\u4ece\u5c0f\u5230\u5927\u6392\u5e8f\uff09\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u51fa\uff1alow = 100, high = 300\n\u8f93\u51fa\uff1a[123,234]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u51fa\uff1alow = 1000, high = 13000\n\u8f93\u51fa\uff1a[1234,2345,3456,4567,5678,6789,12345]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 10 <= low <= high <= 10^9
    • \n
    \n", "tags_en": ["Backtracking"], "tags_cn": ["\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector sequentialDigits(int low, int high) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List sequentialDigits(int low, int high) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def sequentialDigits(self, low, high):\n \"\"\"\n :type low: int\n :type high: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def sequentialDigits(self, low: int, high: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* sequentialDigits(int low, int high, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList SequentialDigits(int low, int high) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} low\n * @param {number} high\n * @return {number[]}\n */\nvar sequentialDigits = function(low, high) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} low\n# @param {Integer} high\n# @return {Integer[]}\ndef sequential_digits(low, high)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func sequentialDigits(_ low: Int, _ high: Int) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func sequentialDigits(low int, high int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def sequentialDigits(low: Int, high: Int): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun sequentialDigits(low: Int, high: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sequential_digits(low: i32, high: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $low\n * @param Integer $high\n * @return Integer[]\n */\n function sequentialDigits($low, $high) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function sequentialDigits(low: number, high: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (sequential-digits low high)\n (-> exact-integer? exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1291](https://leetcode-cn.com/problems/sequential-digits)", "[\u987a\u6b21\u6570](/solution/1200-1299/1291.Sequential%20Digits/README.md)", "`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1291](https://leetcode.com/problems/sequential-digits)", "[Sequential Digits](/solution/1200-1299/1291.Sequential%20Digits/README_EN.md)", "`Backtracking`", "Medium", ""]}, {"question_id": "1211", "frontend_question_id": "1286", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/iterator-for-combination", "url_en": "https://leetcode.com/problems/iterator-for-combination", "relative_path_cn": "/solution/1200-1299/1286.Iterator%20for%20Combination/README.md", "relative_path_en": "/solution/1200-1299/1286.Iterator%20for%20Combination/README_EN.md", "title_cn": "\u5b57\u6bcd\u7ec4\u5408\u8fed\u4ee3\u5668", "title_en": "Iterator for Combination", "question_title_slug": "iterator-for-combination", "content_en": "

    Design the CombinationIterator class:

    \n\n
      \n\t
    • CombinationIterator(string characters, int combinationLength) Initializes the object with a string characters of sorted distinct lowercase English letters and a number combinationLength as arguments.
    • \n\t
    • next() Returns the next combination of length combinationLength in lexicographical order.
    • \n\t
    • hasNext() Returns true if and only if there exists a next combination.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["CombinationIterator", "next", "hasNext", "next", "hasNext", "next", "hasNext"]\n[["abc", 2], [], [], [], [], [], []]\nOutput\n[null, "ab", true, "ac", true, "bc", false]\n\nExplanation\nCombinationIterator itr = new CombinationIterator("abc", 2);\nitr.next();    // return "ab"\nitr.hasNext(); // return True\nitr.next();    // return "ac"\nitr.hasNext(); // return True\nitr.next();    // return "bc"\nitr.hasNext(); // return False\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= combinationLength <= characters.length <= 15
    • \n\t
    • All the characters of characters are unique.
    • \n\t
    • At most 104 calls will be made to next and hasNext.
    • \n\t
    • It's guaranteed that all calls of the function next are valid.
    • \n
    \n", "content_cn": "

    \u8bf7\u4f60\u8bbe\u8ba1\u4e00\u4e2a\u8fed\u4ee3\u5668\u7c7b\uff0c\u5305\u62ec\u4ee5\u4e0b\u5185\u5bb9\uff1a

    \n\n
      \n\t
    • \u4e00\u4e2a\u6784\u9020\u51fd\u6570\uff0c\u8f93\u5165\u53c2\u6570\u5305\u62ec\uff1a\u4e00\u4e2a \u6709\u5e8f\u4e14\u5b57\u7b26\u552f\u4e00 \u7684\u5b57\u7b26\u4e32 characters\uff08\u8be5\u5b57\u7b26\u4e32\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\uff09\u548c\u4e00\u4e2a\u6570\u5b57 combinationLength \u3002
    • \n\t
    • \u51fd\u6570 next() \uff0c\u6309 \u5b57\u5178\u5e8f \u8fd4\u56de\u957f\u5ea6\u4e3a combinationLength \u7684\u4e0b\u4e00\u4e2a\u5b57\u6bcd\u7ec4\u5408\u3002
    • \n\t
    • \u51fd\u6570 hasNext() \uff0c\u53ea\u6709\u5b58\u5728\u957f\u5ea6\u4e3a combinationLength \u7684\u4e0b\u4e00\u4e2a\u5b57\u6bcd\u7ec4\u5408\u65f6\uff0c\u624d\u8fd4\u56de True\uff1b\u5426\u5219\uff0c\u8fd4\u56de False\u3002
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    CombinationIterator iterator = new CombinationIterator("abc", 2); // \u521b\u5efa\u8fed\u4ee3\u5668 iterator\n\niterator.next(); // \u8fd4\u56de "ab"\niterator.hasNext(); // \u8fd4\u56de true\niterator.next(); // \u8fd4\u56de "ac"\niterator.hasNext(); // \u8fd4\u56de true\niterator.next(); // \u8fd4\u56de "bc"\niterator.hasNext(); // \u8fd4\u56de false\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= combinationLength <= characters.length <= 15
    • \n\t
    • \u6bcf\u7ec4\u6d4b\u8bd5\u6570\u636e\u6700\u591a\u5305\u542b 10^4 \u6b21\u51fd\u6570\u8c03\u7528\u3002
    • \n\t
    • \u9898\u76ee\u4fdd\u8bc1\u6bcf\u6b21\u8c03\u7528\u51fd\u6570 next \u65f6\u90fd\u5b58\u5728\u4e0b\u4e00\u4e2a\u5b57\u6bcd\u7ec4\u5408\u3002
    • \n
    \n", "tags_en": ["Design", "Backtracking"], "tags_cn": ["\u8bbe\u8ba1", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class CombinationIterator {\npublic:\n CombinationIterator(string characters, int combinationLength) {\n\n }\n \n string next() {\n\n }\n \n bool hasNext() {\n\n }\n};\n\n/**\n * Your CombinationIterator object will be instantiated and called as such:\n * CombinationIterator* obj = new CombinationIterator(characters, combinationLength);\n * string param_1 = obj->next();\n * bool param_2 = obj->hasNext();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class CombinationIterator {\n\n public CombinationIterator(String characters, int combinationLength) {\n\n }\n \n public String next() {\n\n }\n \n public boolean hasNext() {\n\n }\n}\n\n/**\n * Your CombinationIterator object will be instantiated and called as such:\n * CombinationIterator obj = new CombinationIterator(characters, combinationLength);\n * String param_1 = obj.next();\n * boolean param_2 = obj.hasNext();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class CombinationIterator(object):\n\n def __init__(self, characters, combinationLength):\n \"\"\"\n :type characters: str\n :type combinationLength: int\n \"\"\"\n\n\n def next(self):\n \"\"\"\n :rtype: str\n \"\"\"\n\n\n def hasNext(self):\n \"\"\"\n :rtype: bool\n \"\"\"\n\n\n\n# Your CombinationIterator object will be instantiated and called as such:\n# obj = CombinationIterator(characters, combinationLength)\n# param_1 = obj.next()\n# param_2 = obj.hasNext()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class CombinationIterator:\n\n def __init__(self, characters: str, combinationLength: int):\n\n\n def next(self) -> str:\n\n\n def hasNext(self) -> bool:\n\n\n\n# Your CombinationIterator object will be instantiated and called as such:\n# obj = CombinationIterator(characters, combinationLength)\n# param_1 = obj.next()\n# param_2 = obj.hasNext()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} CombinationIterator;\n\n\nCombinationIterator* combinationIteratorCreate(char * characters, int combinationLength) {\n \n}\n\nchar * combinationIteratorNext(CombinationIterator* obj) {\n \n}\n\nbool combinationIteratorHasNext(CombinationIterator* obj) {\n \n}\n\nvoid combinationIteratorFree(CombinationIterator* obj) {\n \n}\n\n/**\n * Your CombinationIterator struct will be instantiated and called as such:\n * CombinationIterator* obj = combinationIteratorCreate(characters, combinationLength);\n * char * param_1 = combinationIteratorNext(obj);\n \n * bool param_2 = combinationIteratorHasNext(obj);\n \n * combinationIteratorFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class CombinationIterator {\n\n public CombinationIterator(string characters, int combinationLength) {\n\n }\n \n public string Next() {\n\n }\n \n public bool HasNext() {\n\n }\n}\n\n/**\n * Your CombinationIterator object will be instantiated and called as such:\n * CombinationIterator obj = new CombinationIterator(characters, combinationLength);\n * string param_1 = obj.Next();\n * bool param_2 = obj.HasNext();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} characters\n * @param {number} combinationLength\n */\nvar CombinationIterator = function(characters, combinationLength) {\n\n};\n\n/**\n * @return {string}\n */\nCombinationIterator.prototype.next = function() {\n\n};\n\n/**\n * @return {boolean}\n */\nCombinationIterator.prototype.hasNext = function() {\n\n};\n\n/**\n * Your CombinationIterator object will be instantiated and called as such:\n * var obj = new CombinationIterator(characters, combinationLength)\n * var param_1 = obj.next()\n * var param_2 = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class CombinationIterator\n\n=begin\n :type characters: String\n :type combination_length: Integer\n=end\n def initialize(characters, combination_length)\n\n end\n\n\n=begin\n :rtype: String\n=end\n def next()\n\n end\n\n\n=begin\n :rtype: Boolean\n=end\n def has_next()\n\n end\n\n\nend\n\n# Your CombinationIterator object will be instantiated and called as such:\n# obj = CombinationIterator.new(characters, combination_length)\n# param_1 = obj.next()\n# param_2 = obj.has_next()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass CombinationIterator {\n\n init(_ characters: String, _ combinationLength: Int) {\n\n }\n \n func next() -> String {\n\n }\n \n func hasNext() -> Bool {\n\n }\n}\n\n/**\n * Your CombinationIterator object will be instantiated and called as such:\n * let obj = CombinationIterator(characters, combinationLength)\n * let ret_1: String = obj.next()\n * let ret_2: Bool = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type CombinationIterator struct {\n\n}\n\n\nfunc Constructor(characters string, combinationLength int) CombinationIterator {\n\n}\n\n\nfunc (this *CombinationIterator) Next() string {\n\n}\n\n\nfunc (this *CombinationIterator) HasNext() bool {\n\n}\n\n\n/**\n * Your CombinationIterator object will be instantiated and called as such:\n * obj := Constructor(characters, combinationLength);\n * param_1 := obj.Next();\n * param_2 := obj.HasNext();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class CombinationIterator(_characters: String, _combinationLength: Int) {\n\n def next(): String = {\n\n }\n\n def hasNext(): Boolean = {\n\n }\n\n}\n\n/**\n * Your CombinationIterator object will be instantiated and called as such:\n * var obj = new CombinationIterator(characters, combinationLength)\n * var param_1 = obj.next()\n * var param_2 = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class CombinationIterator(characters: String, combinationLength: Int) {\n\n fun next(): String {\n\n }\n\n fun hasNext(): Boolean {\n\n }\n\n}\n\n/**\n * Your CombinationIterator object will be instantiated and called as such:\n * var obj = CombinationIterator(characters, combinationLength)\n * var param_1 = obj.next()\n * var param_2 = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct CombinationIterator {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl CombinationIterator {\n\n fn new(characters: String, combinationLength: i32) -> Self {\n\n }\n \n fn next(&self) -> String {\n\n }\n \n fn has_next(&self) -> bool {\n\n }\n}\n\n/**\n * Your CombinationIterator object will be instantiated and called as such:\n * let obj = CombinationIterator::new(characters, combinationLength);\n * let ret_1: String = obj.next();\n * let ret_2: bool = obj.has_next();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class CombinationIterator {\n /**\n * @param String $characters\n * @param Integer $combinationLength\n */\n function __construct($characters, $combinationLength) {\n\n }\n\n /**\n * @return String\n */\n function next() {\n\n }\n\n /**\n * @return Boolean\n */\n function hasNext() {\n\n }\n}\n\n/**\n * Your CombinationIterator object will be instantiated and called as such:\n * $obj = CombinationIterator($characters, $combinationLength);\n * $ret_1 = $obj->next();\n * $ret_2 = $obj->hasNext();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class CombinationIterator {\n constructor(characters: string, combinationLength: number) {\n\n }\n\n next(): string {\n\n }\n\n hasNext(): boolean {\n\n }\n}\n\n/**\n * Your CombinationIterator object will be instantiated and called as such:\n * var obj = new CombinationIterator(characters, combinationLength)\n * var param_1 = obj.next()\n * var param_2 = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define combination-iterator%\n (class object%\n (super-new)\n\n ; characters : string?\n\n ; combination-length : exact-integer?\n (init-field\n characters\n combination-length)\n \n ; next : -> string?\n (define/public (next)\n\n )\n ; has-next : -> boolean?\n (define/public (has-next)\n\n )))\n\n;; Your combination-iterator% object will be instantiated and called as such:\n;; (define obj (new combination-iterator% [characters characters] [combinationLength combinationLength]))\n;; (define param_1 (send obj next))\n;; (define param_2 (send obj has-next))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1286](https://leetcode-cn.com/problems/iterator-for-combination)", "[\u5b57\u6bcd\u7ec4\u5408\u8fed\u4ee3\u5668](/solution/1200-1299/1286.Iterator%20for%20Combination/README.md)", "`\u8bbe\u8ba1`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1286](https://leetcode.com/problems/iterator-for-combination)", "[Iterator for Combination](/solution/1200-1299/1286.Iterator%20for%20Combination/README_EN.md)", "`Design`,`Backtracking`", "Medium", ""]}, {"question_id": "1210", "frontend_question_id": "1619", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/mean-of-array-after-removing-some-elements", "url_en": "https://leetcode.com/problems/mean-of-array-after-removing-some-elements", "relative_path_cn": "/solution/1600-1699/1619.Mean%20of%20Array%20After%20Removing%20Some%20Elements/README.md", "relative_path_en": "/solution/1600-1699/1619.Mean%20of%20Array%20After%20Removing%20Some%20Elements/README_EN.md", "title_cn": "\u5220\u9664\u67d0\u4e9b\u5143\u7d20\u540e\u7684\u6570\u7ec4\u5747\u503c", "title_en": "Mean of Array After Removing Some Elements", "question_title_slug": "mean-of-array-after-removing-some-elements", "content_en": "

    Given an integer array arr, return the mean of the remaining integers after removing the smallest 5% and the largest 5% of the elements.

    \n\n

    Answers within 10-5 of the actual answer will be considered accepted.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr = [1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3]\nOutput: 2.00000\nExplanation: After erasing the minimum and the maximum values of this array, all elements are equal to 2, so the mean is 2.\n
    \n\n

    Example 2:

    \n\n
    \nInput: arr = [6,2,7,5,1,2,0,3,10,2,5,0,5,5,0,8,7,6,8,0]\nOutput: 4.00000\n
    \n\n

    Example 3:

    \n\n
    \nInput: arr = [6,0,7,0,7,5,7,8,3,4,0,7,8,1,6,8,1,1,2,4,8,1,9,5,4,3,8,5,10,8,6,6,1,0,6,10,8,2,3,4]\nOutput: 4.77778\n
    \n\n

    Example 4:

    \n\n
    \nInput: arr = [9,7,8,7,7,8,4,4,6,8,8,7,6,8,8,9,2,6,0,0,1,10,8,6,3,3,5,1,10,9,0,7,10,0,10,4,1,10,6,9,3,6,0,0,2,7,0,6,7,2,9,7,7,3,0,1,6,1,10,3]\nOutput: 5.27778\n
    \n\n

    Example 5:

    \n\n
    \nInput: arr = [4,8,4,10,0,7,1,3,7,8,8,3,4,1,6,2,1,1,8,0,9,8,0,3,9,10,3,10,1,10,7,3,2,1,4,9,10,7,6,4,0,8,5,1,2,1,6,2,5,0,7,10,9,10,3,7,10,5,8,5,7,6,7,6,10,9,5,10,5,5,7,2,10,7,7,8,2,0,1,1]\nOutput: 5.29167\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 20 <= arr.length <= 1000
    • \n\t
    • arr.length is a multiple of 20.
    • \n\t
    • 0 <= arr[i] <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0arr\u00a0\uff0c\u8bf7\u4f60\u5220\u9664\u6700\u5c0f\u00a05%\u00a0\u7684\u6570\u5b57\u548c\u6700\u5927 5%\u00a0\u7684\u6570\u5b57\u540e\uff0c\u5269\u4f59\u6570\u5b57\u7684\u5e73\u5747\u503c\u3002

    \n\n

    \u4e0e \u6807\u51c6\u7b54\u6848\u00a0\u8bef\u5dee\u5728\u00a010-5\u00a0\u7684\u7ed3\u679c\u90fd\u88ab\u89c6\u4e3a\u6b63\u786e\u7ed3\u679c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3]\n\u8f93\u51fa\uff1a2.00000\n\u89e3\u91ca\uff1a\u5220\u9664\u6570\u7ec4\u4e2d\u6700\u5927\u548c\u6700\u5c0f\u7684\u5143\u7d20\u540e\uff0c\u6240\u6709\u5143\u7d20\u90fd\u7b49\u4e8e 2\uff0c\u6240\u4ee5\u5e73\u5747\u503c\u4e3a 2 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [6,2,7,5,1,2,0,3,10,2,5,0,5,5,0,8,7,6,8,0]\n\u8f93\u51fa\uff1a4.00000\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [6,0,7,0,7,5,7,8,3,4,0,7,8,1,6,8,1,1,2,4,8,1,9,5,4,3,8,5,10,8,6,6,1,0,6,10,8,2,3,4]\n\u8f93\u51fa\uff1a4.77778\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [9,7,8,7,7,8,4,4,6,8,8,7,6,8,8,9,2,6,0,0,1,10,8,6,3,3,5,1,10,9,0,7,10,0,10,4,1,10,6,9,3,6,0,0,2,7,0,6,7,2,9,7,7,3,0,1,6,1,10,3]\n\u8f93\u51fa\uff1a5.27778\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [4,8,4,10,0,7,1,3,7,8,8,3,4,1,6,2,1,1,8,0,9,8,0,3,9,10,3,10,1,10,7,3,2,1,4,9,10,7,6,4,0,8,5,1,2,1,6,2,5,0,7,10,9,10,3,7,10,5,8,5,7,6,7,6,10,9,5,10,5,5,7,2,10,7,7,8,2,0,1,1]\n\u8f93\u51fa\uff1a5.29167\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 20 <= arr.length <= 1000
    • \n\t
    • arr.length\u00a0\u662f\u00a020\u00a0\u7684\u00a0\u500d\u6570\u00a0
    • \n\t
    • 0 <= arr[i] <= 105
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n double trimMean(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double trimMean(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def trimMean(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: float\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def trimMean(self, arr: List[int]) -> float:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\ndouble trimMean(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double TrimMean(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar trimMean = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Float}\ndef trim_mean(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func trimMean(_ arr: [Int]) -> Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func trimMean(arr []int) float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def trimMean(arr: Array[Int]): Double = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun trimMean(arr: IntArray): Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn trim_mean(arr: Vec) -> f64 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Float\n */\n function trimMean($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function trimMean(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (trim-mean arr)\n (-> (listof exact-integer?) flonum?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1619](https://leetcode-cn.com/problems/mean-of-array-after-removing-some-elements)", "[\u5220\u9664\u67d0\u4e9b\u5143\u7d20\u540e\u7684\u6570\u7ec4\u5747\u503c](/solution/1600-1699/1619.Mean%20of%20Array%20After%20Removing%20Some%20Elements/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1619](https://leetcode.com/problems/mean-of-array-after-removing-some-elements)", "[Mean of Array After Removing Some Elements](/solution/1600-1699/1619.Mean%20of%20Array%20After%20Removing%20Some%20Elements/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1209", "frontend_question_id": "1188", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/design-bounded-blocking-queue", "url_en": "https://leetcode.com/problems/design-bounded-blocking-queue", "relative_path_cn": "/solution/1100-1199/1188.Design%20Bounded%20Blocking%20Queue/README.md", "relative_path_en": "/solution/1100-1199/1188.Design%20Bounded%20Blocking%20Queue/README_EN.md", "title_cn": "\u8bbe\u8ba1\u6709\u9650\u963b\u585e\u961f\u5217", "title_en": "Design Bounded Blocking Queue", "question_title_slug": "design-bounded-blocking-queue", "content_en": "

    Implement a thread-safe bounded blocking queue that has the following methods:

    \n\n
      \n\t
    • BoundedBlockingQueue(int capacity) The constructor initializes the queue with a maximum capacity.
    • \n\t
    • void enqueue(int element) Adds an element to the front of the queue. If the queue is full, the calling thread is blocked until the queue is no longer full.
    • \n\t
    • int dequeue() Returns the element at the rear of the queue and removes it. If the queue is empty, the calling thread is blocked until the queue is no longer empty.
    • \n\t
    • int size() Returns the number of elements currently in the queue.
    • \n
    \n\n

    Your implementation will be tested using multiple threads at the same time. Each thread will either be a producer thread that only makes calls to the enqueue method or a consumer thread that only makes calls to the dequeue method. The size method will be called after every test case.

    \n\n

    Please do not use built-in implementations of bounded blocking queue as this will not be accepted in an interview.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput:\n1\n1\n["BoundedBlockingQueue","enqueue","dequeue","dequeue","enqueue","enqueue","enqueue","enqueue","dequeue"]\n[[2],[1],[],[],[0],[2],[3],[4],[]]\n\nOutput:\n[1,0,2,2]\n\nExplanation:\nNumber of producer threads = 1\nNumber of consumer threads = 1\n\nBoundedBlockingQueue queue = new BoundedBlockingQueue(2);   // initialize the queue with capacity = 2.\n\nqueue.enqueue(1);   // The producer thread enqueues 1 to the queue.\nqueue.dequeue();    // The consumer thread calls dequeue and returns 1 from the queue.\nqueue.dequeue();    // Since the queue is empty, the consumer thread is blocked.\nqueue.enqueue(0);   // The producer thread enqueues 0 to the queue. The consumer thread is unblocked and returns 0 from the queue.\nqueue.enqueue(2);   // The producer thread enqueues 2 to the queue.\nqueue.enqueue(3);   // The producer thread enqueues 3 to the queue.\nqueue.enqueue(4);   // The producer thread is blocked because the queue's capacity (2) is reached.\nqueue.dequeue();    // The consumer thread returns 2 from the queue. The producer thread is unblocked and enqueues 4 to the queue.\nqueue.size();       // 2 elements remaining in the queue. size() is always called at the end of each test case.\n
    \n\n

    Example 2:

    \n\n
    \nInput:\n3\n4\n["BoundedBlockingQueue","enqueue","enqueue","enqueue","dequeue","dequeue","dequeue","enqueue"]\n[[3],[1],[0],[2],[],[],[],[3]]\nOutput:\n[1,0,2,1]\n\nExplanation:\nNumber of producer threads = 3\nNumber of consumer threads = 4\n\nBoundedBlockingQueue queue = new BoundedBlockingQueue(3);   // initialize the queue with capacity = 3.\n\nqueue.enqueue(1);   // Producer thread P1 enqueues 1 to the queue.\nqueue.enqueue(0);   // Producer thread P2 enqueues 0 to the queue.\nqueue.enqueue(2);   // Producer thread P3 enqueues 2 to the queue.\nqueue.dequeue();    // Consumer thread C1 calls dequeue.\nqueue.dequeue();    // Consumer thread C2 calls dequeue.\nqueue.dequeue();    // Consumer thread C3 calls dequeue.\nqueue.enqueue(3);   // One of the producer threads enqueues 3 to the queue.\nqueue.size();       // 1 element remaining in the queue.\n\nSince the number of threads for producer/consumer is greater than 1, we do not know how the threads will be scheduled in the operating system, even though the input seems to imply the ordering. Therefore, any of the output [1,0,2] or [1,2,0] or [0,1,2] or [0,2,1] or [2,0,1] or [2,1,0] will be accepted.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= Number of Prdoucers <= 8
    • \n\t
    • 1 <= Number of Consumers <= 8
    • \n\t
    • 1 <= size <= 30
    • \n\t
    • 0 <= element <= 20
    • \n\t
    • The number of calls to enqueue is greater than or equal to the number of calls to dequeue.
    • \n\t
    • At most 40 calls will be made to enque, deque, and size.
    • \n
    \n", "content_cn": "

    \u5b9e\u73b0\u4e00\u4e2a\u62e5\u6709\u5982\u4e0b\u65b9\u6cd5\u7684\u7ebf\u7a0b\u5b89\u5168\u6709\u9650\u963b\u585e\u961f\u5217\uff1a

    \n\n
      \n\t
    • BoundedBlockingQueue(int capacity) \u6784\u9020\u65b9\u6cd5\u521d\u59cb\u5316\u961f\u5217\uff0c\u5176\u4e2dcapacity\u4ee3\u8868\u961f\u5217\u957f\u5ea6\u4e0a\u9650\u3002
    • \n\t
    • void enqueue(int element) \u5728\u961f\u9996\u589e\u52a0\u4e00\u4e2aelement. \u5982\u679c\u961f\u5217\u6ee1\uff0c\u8c03\u7528\u7ebf\u7a0b\u88ab\u963b\u585e\u76f4\u5230\u961f\u5217\u975e\u6ee1\u3002
    • \n\t
    • int dequeue() \u8fd4\u56de\u961f\u5c3e\u5143\u7d20\u5e76\u4ece\u961f\u5217\u4e2d\u5c06\u5176\u5220\u9664. \u5982\u679c\u961f\u5217\u4e3a\u7a7a\uff0c\u8c03\u7528\u7ebf\u7a0b\u88ab\u963b\u585e\u76f4\u5230\u961f\u5217\u975e\u7a7a\u3002
    • \n\t
    • int size() \u8fd4\u56de\u5f53\u524d\u961f\u5217\u5143\u7d20\u4e2a\u6570\u3002
    • \n
    \n\n

    \u4f60\u7684\u5b9e\u73b0\u5c06\u4f1a\u88ab\u591a\u7ebf\u7a0b\u540c\u65f6\u8bbf\u95ee\u8fdb\u884c\u6d4b\u8bd5\u3002\u6bcf\u4e00\u4e2a\u7ebf\u7a0b\u8981\u4e48\u662f\u4e00\u4e2a\u53ea\u8c03\u7528enqueue\u65b9\u6cd5\u7684\u751f\u4ea7\u8005\u7ebf\u7a0b\uff0c\u8981\u4e48\u662f\u4e00\u4e2a\u53ea\u8c03\u7528dequeue\u65b9\u6cd5\u7684\u6d88\u8d39\u8005\u7ebf\u7a0b\u3002size\u65b9\u6cd5\u5c06\u4f1a\u5728\u6bcf\u4e00\u4e2a\u6d4b\u8bd5\u7528\u4f8b\u4e4b\u540e\u8fdb\u884c\u8c03\u7528\u3002

    \n\n

    \u8bf7\u4e0d\u8981\u4f7f\u7528\u5185\u7f6e\u7684\u6709\u9650\u963b\u585e\u961f\u5217\u5b9e\u73b0\uff0c\u5426\u5219\u9762\u8bd5\u5c06\u4e0d\u4f1a\u901a\u8fc7\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165:\n1\n1\n["BoundedBlockingQueue","enqueue","dequeue","dequeue","enqueue","enqueue","enqueue","enqueue","dequeue"]\n[[2],[1],[],[],[0],[2],[3],[4],[]]\n\n\u8f93\u51fa:\n[1,0,2,2]\n\n\u89e3\u91ca:\n\u751f\u4ea7\u8005\u7ebf\u7a0b\u6570\u76ee = 1\n\u6d88\u8d39\u8005\u7ebf\u7a0b\u6570\u76ee = 1\n\nBoundedBlockingQueue queue = new BoundedBlockingQueue(2);   // \u4f7f\u7528capacity = 2\u521d\u59cb\u5316\u961f\u5217\u3002\n\nqueue.enqueue(1);   // \u751f\u4ea7\u8005\u7ebf\u7a0b\u5c061\u63d2\u5165\u961f\u5217\u3002\nqueue.dequeue();    // \u6d88\u8d39\u8005\u7ebf\u7a0b\u8c03\u7528dequeue\u5e76\u8fd4\u56de1\u3002\nqueue.dequeue();    // \u7531\u4e8e\u961f\u5217\u4e3a\u7a7a\uff0c\u6d88\u8d39\u8005\u7ebf\u7a0b\u88ab\u963b\u585e\u3002\nqueue.enqueue(0);   // \u751f\u4ea7\u8005\u7ebf\u7a0b\u5c060\u63d2\u5165\u961f\u5217\u3002\u6d88\u8d39\u8005\u7ebf\u7a0b\u88ab\u89e3\u9664\u963b\u585e\u540c\u65f6\u5c060\u5f39\u51fa\u961f\u5217\u5e76\u8fd4\u56de\u3002\nqueue.enqueue(2);   // \u751f\u4ea7\u8005\u7ebf\u7a0b\u5c062\u63d2\u5165\u961f\u5217\u3002\nqueue.enqueue(3);   // \u751f\u4ea7\u8005\u7ebf\u7a0b\u5c063\u63d2\u5165\u961f\u5217\u3002\nqueue.enqueue(4);   // \u751f\u4ea7\u8005\u7ebf\u7a0b\u7531\u4e8e\u961f\u5217\u957f\u5ea6\u5df2\u8fbe\u5230\u4e0a\u96502\u800c\u88ab\u963b\u585e\u3002\nqueue.dequeue();    // \u6d88\u8d39\u8005\u7ebf\u7a0b\u5c062\u4ece\u961f\u5217\u5f39\u51fa\u5e76\u8fd4\u56de\u3002\u751f\u4ea7\u8005\u7ebf\u7a0b\u89e3\u9664\u963b\u585e\u540c\u65f6\u5c064\u63d2\u5165\u961f\u5217\u3002\nqueue.size();       // \u961f\u5217\u4e2d\u8fd8\u67092\u4e2a\u5143\u7d20\u3002size()\u65b9\u6cd5\u5728\u6bcf\u7ec4\u6d4b\u8bd5\u7528\u4f8b\u6700\u540e\u8c03\u7528\u3002\n
    \n\n

     

    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165:\n3\n4\n["BoundedBlockingQueue","enqueue","enqueue","enqueue","dequeue","dequeue","dequeue","enqueue"]\n[[3],[1],[0],[2],[],[],[],[3]]\n\n\u8f93\u51fa:\n[1,0,2,1]\n\n\u89e3\u91ca:\n\u751f\u4ea7\u8005\u7ebf\u7a0b\u6570\u76ee = 3\n\u6d88\u8d39\u8005\u7ebf\u7a0b\u6570\u76ee = 4\n\nBoundedBlockingQueue queue = new BoundedBlockingQueue(3);   // \u4f7f\u7528capacity = 3\u521d\u59cb\u5316\u961f\u5217\u3002\n\nqueue.enqueue(1);   // \u751f\u4ea7\u8005\u7ebf\u7a0bP1\u5c061\u63d2\u5165\u961f\u5217\u3002\nqueue.enqueue(0);   // \u751f\u4ea7\u8005\u7ebf\u7a0bP2\u5c060\u63d2\u5165\u961f\u5217\u3002\nqueue.enqueue(2);   // \u751f\u4ea7\u8005\u7ebf\u7a0bP3\u5c062\u63d2\u5165\u961f\u5217\u3002\nqueue.dequeue();    // \u6d88\u8d39\u8005\u7ebf\u7a0bC1\u8c03\u7528dequeue\u3002\nqueue.dequeue();    // \u6d88\u8d39\u8005\u7ebf\u7a0bC2\u8c03\u7528dequeue\u3002\nqueue.dequeue();    // \u6d88\u8d39\u8005\u7ebf\u7a0bC3\u8c03\u7528dequeue\u3002\nqueue.enqueue(3);   // \u5176\u4e2d\u4e00\u4e2a\u751f\u4ea7\u8005\u7ebf\u7a0b\u5c063\u63d2\u5165\u961f\u5217\u3002\nqueue.size();       // \u961f\u5217\u4e2d\u8fd8\u67091\u4e2a\u5143\u7d20\u3002\n\n\u7531\u4e8e\u751f\u4ea7\u8005/\u6d88\u8d39\u8005\u7ebf\u7a0b\u7684\u6570\u76ee\u53ef\u80fd\u5927\u4e8e1\uff0c\u6211\u4eec\u5e76\u4e0d\u77e5\u9053\u7ebf\u7a0b\u5982\u4f55\u88ab\u64cd\u4f5c\u7cfb\u7edf\u8c03\u5ea6\uff0c\u5373\u4f7f\u8f93\u5165\u770b\u4e0a\u53bb\u9690\u542b\u4e86\u987a\u5e8f\u3002\u56e0\u6b64\u4efb\u610f\u4e00\u79cd\u8f93\u51fa[1,0,2]\u6216[1,2,0]\u6216[0,1,2]\u6216[0,2,1]\u6216[2,0,1]\u6216[2,1,0]\u90fd\u53ef\u88ab\u63a5\u53d7\u3002
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class BoundedBlockingQueue {\npublic:\n BoundedBlockingQueue(int capacity) {\n \n }\n \n void enqueue(int element) {\n \n }\n \n int dequeue() {\n \n }\n \n int size() {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class BoundedBlockingQueue {\n\n public BoundedBlockingQueue(int capacity) {\n \n }\n \n public void enqueue(int element) throws InterruptedException {\n \n }\n \n public int dequeue() throws InterruptedException {\n \n }\n \n public int size() {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class BoundedBlockingQueue(object):\n def __init__(self, capacity):\n \"\"\"\n :type capacity: int\n \"\"\"\n \n\n def enqueue(self, element):\n \"\"\"\n :type element: int\n :rtype: void\n \"\"\"\n \n\n def dequeue(self):\n \"\"\"\n :rtype: int\n \"\"\"\n \n\n def size(self):\n \"\"\"\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class BoundedBlockingQueue(object):\n\n def __init__(self, capacity: int):\n \n\n def enqueue(self, element: int) -> None:\n \n\n def dequeue(self) -> int:\n \n\n def size(self) -> int:\n ", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1188](https://leetcode-cn.com/problems/design-bounded-blocking-queue)", "[\u8bbe\u8ba1\u6709\u9650\u963b\u585e\u961f\u5217](/solution/1100-1199/1188.Design%20Bounded%20Blocking%20Queue/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1188](https://leetcode.com/problems/design-bounded-blocking-queue)", "[Design Bounded Blocking Queue](/solution/1100-1199/1188.Design%20Bounded%20Blocking%20Queue/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1208", "frontend_question_id": "1111", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-nesting-depth-of-two-valid-parentheses-strings", "url_en": "https://leetcode.com/problems/maximum-nesting-depth-of-two-valid-parentheses-strings", "relative_path_cn": "/solution/1100-1199/1111.Maximum%20Nesting%20Depth%20of%20Two%20Valid%20Parentheses%20Strings/README.md", "relative_path_en": "/solution/1100-1199/1111.Maximum%20Nesting%20Depth%20of%20Two%20Valid%20Parentheses%20Strings/README_EN.md", "title_cn": "\u6709\u6548\u62ec\u53f7\u7684\u5d4c\u5957\u6df1\u5ea6", "title_en": "Maximum Nesting Depth of Two Valid Parentheses Strings", "question_title_slug": "maximum-nesting-depth-of-two-valid-parentheses-strings", "content_en": "

    A string is a valid parentheses string (denoted VPS) if and only if it consists of "(" and ")" characters only, and:

    \r\n\r\n
      \r\n\t
    • It is the empty string, or
    • \r\n\t
    • It can be written as AB (A concatenated with B), where A and B are VPS's, or
    • \r\n\t
    • It can be written as (A), where A is a VPS.
    • \r\n
    \r\n\r\n

    We can similarly define the nesting depth depth(S) of any VPS S as follows:

    \r\n\r\n
      \r\n\t
    • depth("") = 0
    • \r\n\t
    • depth(A + B) = max(depth(A), depth(B)), where A and B are VPS's
    • \r\n\t
    • depth("(" + A + ")") = 1 + depth(A), where A is a VPS.
    • \r\n
    \r\n\r\n

    For example,  """()()", and "()(()())" are VPS's (with nesting depths 0, 1, and 2), and ")(" and "(()" are not VPS's.

    \r\n\r\n

     

    \r\n\r\n

    Given a VPS seq, split it into two disjoint subsequences A and B, such that A and B are VPS's (and A.length + B.length = seq.length).

    \r\n\r\n

    Now choose any such A and B such that max(depth(A), depth(B)) is the minimum possible value.

    \r\n\r\n

    Return an answer array (of length seq.length) that encodes such a choice of A and Banswer[i] = 0 if seq[i] is part of A, else answer[i] = 1.  Note that even though multiple answers may exist, you may return any of them.

    \r\n\n

     

    \n

    Example 1:

    \n\n
    \nInput: seq = "(()())"\nOutput: [0,1,1,1,1,0]\n
    \n\n

    Example 2:

    \n\n
    \nInput: seq = "()(())()"\nOutput: [0,0,0,1,1,0,1,1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= seq.size <= 10000
    • \n
    \n", "content_cn": "

    \u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32 \u5b9a\u4e49\uff1a\u5bf9\u4e8e\u6bcf\u4e2a\u5de6\u62ec\u53f7\uff0c\u90fd\u80fd\u627e\u5230\u4e0e\u4e4b\u5bf9\u5e94\u7684\u53f3\u62ec\u53f7\uff0c\u53cd\u4e4b\u4ea6\u7136\u3002\u8be6\u60c5\u53c2\u89c1\u9898\u672b\u300c\u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32\u300d\u90e8\u5206\u3002

    \n\n

    \u5d4c\u5957\u6df1\u5ea6 depth \u5b9a\u4e49\uff1a\u5373\u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32\u5d4c\u5957\u7684\u5c42\u6570\uff0cdepth(A) \u8868\u793a\u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32 A \u7684\u5d4c\u5957\u6df1\u5ea6\u3002\u8be6\u60c5\u53c2\u89c1\u9898\u672b\u300c\u5d4c\u5957\u6df1\u5ea6\u300d\u90e8\u5206\u3002

    \n\n

    \u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32\u7c7b\u578b\u4e0e\u5bf9\u5e94\u7684\u5d4c\u5957\u6df1\u5ea6\u8ba1\u7b97\u65b9\u6cd5\u5982\u4e0b\u56fe\u6240\u793a\uff1a

    \n\n

    \"\"

    \n\n

     

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u300c\u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32\u300d seq\uff0c\u8bf7\u4f60\u5c06\u5176\u5206\u6210\u4e24\u4e2a\u4e0d\u76f8\u4ea4\u7684\u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32\uff0cA \u548c B\uff0c\u5e76\u4f7f\u8fd9\u4e24\u4e2a\u5b57\u7b26\u4e32\u7684\u6df1\u5ea6\u6700\u5c0f\u3002

    \n\n
      \n\t
    • \u4e0d\u76f8\u4ea4\uff1a\u6bcf\u4e2a seq[i] \u53ea\u80fd\u5206\u7ed9 A \u548c B \u4e8c\u8005\u4e2d\u7684\u4e00\u4e2a\uff0c\u4e0d\u80fd\u65e2\u5c5e\u4e8e A \u4e5f\u5c5e\u4e8e B \u3002
    • \n\t
    • A \u6216 B \u4e2d\u7684\u5143\u7d20\u5728\u539f\u5b57\u7b26\u4e32\u4e2d\u53ef\u4ee5\u4e0d\u8fde\u7eed\u3002
    • \n\t
    • A.length + B.length = seq.length
    • \n\t
    • \u6df1\u5ea6\u6700\u5c0f\uff1amax(depth(A), depth(B)) \u7684\u53ef\u80fd\u53d6\u503c\u6700\u5c0f\u3002 
    • \n
    \n\n

    \u5212\u5206\u65b9\u6848\u7528\u4e00\u4e2a\u957f\u5ea6\u4e3a seq.length \u7684\u7b54\u6848\u6570\u7ec4 answer \u8868\u793a\uff0c\u7f16\u7801\u89c4\u5219\u5982\u4e0b\uff1a

    \n\n
      \n\t
    • answer[i] = 0\uff0cseq[i] \u5206\u7ed9 A \u3002
    • \n\t
    • answer[i] = 1\uff0cseq[i] \u5206\u7ed9 B \u3002
    • \n
    \n\n

    \u5982\u679c\u5b58\u5728\u591a\u4e2a\u6ee1\u8db3\u8981\u6c42\u7684\u7b54\u6848\uff0c\u53ea\u9700\u8fd4\u56de\u5176\u4e2d\u4efb\u610f \u4e00\u4e2a \u5373\u53ef\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aseq = "(()())"\n\u8f93\u51fa\uff1a[0,1,1,1,1,0]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aseq = "()(())()"\n\u8f93\u51fa\uff1a[0,0,0,1,1,0,1,1]\n\u89e3\u91ca\uff1a\u672c\u793a\u4f8b\u7b54\u6848\u4e0d\u552f\u4e00\u3002\n\u6309\u6b64\u8f93\u51fa A = "()()", B = "()()", max(depth(A), depth(B)) = 1\uff0c\u5b83\u4eec\u7684\u6df1\u5ea6\u6700\u5c0f\u3002\n\u50cf [1,1,1,0,0,1,1,1]\uff0c\u4e5f\u662f\u6b63\u786e\u7ed3\u679c\uff0c\u5176\u4e2d A = "()()()", B = "()", max(depth(A), depth(B)) = 1 \u3002 \n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 < seq.size <= 10000
    • \n
    \n\n

     

    \n\n

    \u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32\uff1a

    \n\n
    \u4ec5\u7531 "(" \u548c ")" \u6784\u6210\u7684\u5b57\u7b26\u4e32\uff0c\u5bf9\u4e8e\u6bcf\u4e2a\u5de6\u62ec\u53f7\uff0c\u90fd\u80fd\u627e\u5230\u4e0e\u4e4b\u5bf9\u5e94\u7684\u53f3\u62ec\u53f7\uff0c\u53cd\u4e4b\u4ea6\u7136\u3002\n\u4e0b\u8ff0\u51e0\u79cd\u60c5\u51b5\u540c\u6837\u5c5e\u4e8e\u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32\uff1a\n\n  1. \u7a7a\u5b57\u7b26\u4e32\n  2. \u8fde\u63a5\uff0c\u53ef\u4ee5\u8bb0\u4f5c AB\uff08A \u4e0e B \u8fde\u63a5\uff09\uff0c\u5176\u4e2d A \u548c B \u90fd\u662f\u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32\n  3. \u5d4c\u5957\uff0c\u53ef\u4ee5\u8bb0\u4f5c (A)\uff0c\u5176\u4e2d A \u662f\u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32\n
    \n\n

    \u5d4c\u5957\u6df1\u5ea6\uff1a

    \n\n
    \u7c7b\u4f3c\u5730\uff0c\u6211\u4eec\u53ef\u4ee5\u5b9a\u4e49\u4efb\u610f\u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32 s \u7684 \u5d4c\u5957\u6df1\u5ea6 depth(S)\uff1a\n\n  1. s \u4e3a\u7a7a\u65f6\uff0cdepth("") = 0\n  2. s \u4e3a A \u4e0e B \u8fde\u63a5\u65f6\uff0cdepth(A + B) = max(depth(A), depth(B))\uff0c\u5176\u4e2d A \u548c B \u90fd\u662f\u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32\n  3. s \u4e3a\u5d4c\u5957\u60c5\u51b5\uff0cdepth("(" + A + ")") = 1 + depth(A)\uff0c\u5176\u4e2d A \u662f\u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32\n\n\u4f8b\u5982\uff1a""\uff0c"()()"\uff0c\u548c "()(()())" \u90fd\u662f\u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32\uff0c\u5d4c\u5957\u6df1\u5ea6\u5206\u522b\u4e3a 0\uff0c1\uff0c2\uff0c\u800c ")(" \u548c "(()" \u90fd\u4e0d\u662f\u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32\u3002\n
    \n", "tags_en": ["Greedy", "Binary Search"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector maxDepthAfterSplit(string seq) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] maxDepthAfterSplit(String seq) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxDepthAfterSplit(self, seq):\n \"\"\"\n :type seq: str\n :rtype: List[int]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxDepthAfterSplit(self, seq: str) -> List[int]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* maxDepthAfterSplit(char * seq, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] MaxDepthAfterSplit(string seq) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} seq\n * @return {number[]}\n */\nvar maxDepthAfterSplit = function(seq) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} seq\n# @return {Integer[]}\ndef max_depth_after_split(seq)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxDepthAfterSplit(_ seq: String) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxDepthAfterSplit(seq string) []int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxDepthAfterSplit(seq: String): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxDepthAfterSplit(seq: String): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_depth_after_split(seq: String) -> Vec {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $seq\n * @return Integer[]\n */\n function maxDepthAfterSplit($seq) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxDepthAfterSplit(seq: string): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-depth-after-split seq)\n (-> string? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1111](https://leetcode-cn.com/problems/maximum-nesting-depth-of-two-valid-parentheses-strings)", "[\u6709\u6548\u62ec\u53f7\u7684\u5d4c\u5957\u6df1\u5ea6](/solution/1100-1199/1111.Maximum%20Nesting%20Depth%20of%20Two%20Valid%20Parentheses%20Strings/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1111](https://leetcode.com/problems/maximum-nesting-depth-of-two-valid-parentheses-strings)", "[Maximum Nesting Depth of Two Valid Parentheses Strings](/solution/1100-1199/1111.Maximum%20Nesting%20Depth%20of%20Two%20Valid%20Parentheses%20Strings/README_EN.md)", "`Greedy`,`Binary Search`", "Medium", ""]}, {"question_id": "1207", "frontend_question_id": "1110", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/delete-nodes-and-return-forest", "url_en": "https://leetcode.com/problems/delete-nodes-and-return-forest", "relative_path_cn": "/solution/1100-1199/1110.Delete%20Nodes%20And%20Return%20Forest/README.md", "relative_path_en": "/solution/1100-1199/1110.Delete%20Nodes%20And%20Return%20Forest/README_EN.md", "title_cn": "\u5220\u70b9\u6210\u6797", "title_en": "Delete Nodes And Return Forest", "question_title_slug": "delete-nodes-and-return-forest", "content_en": "

    Given the root of a binary tree, each node in the tree has a distinct value.

    \n\n

    After deleting all nodes with a value in to_delete, we are left with a forest (a disjoint union of trees).

    \n\n

    Return the roots of the trees in the remaining forest. You may return the result in any order.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,2,3,4,5,6,7], to_delete = [3,5]\nOutput: [[1,2,null,4],[6],[7]]\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = [1,2,4,null,3], to_delete = [3]\nOutput: [[1,2,4]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the given tree is at most 1000.
    • \n\t
    • Each node has a distinct value between 1 and 1000.
    • \n\t
    • to_delete.length <= 1000
    • \n\t
    • to_delete contains distinct values between 1 and 1000.
    • \n
    \n", "content_cn": "

    \u7ed9\u51fa\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9 root\uff0c\u6811\u4e0a\u6bcf\u4e2a\u8282\u70b9\u90fd\u6709\u4e00\u4e2a\u4e0d\u540c\u7684\u503c\u3002

    \n\n

    \u5982\u679c\u8282\u70b9\u503c\u5728 to_delete \u4e2d\u51fa\u73b0\uff0c\u6211\u4eec\u5c31\u628a\u8be5\u8282\u70b9\u4ece\u6811\u4e0a\u5220\u53bb\uff0c\u6700\u540e\u5f97\u5230\u4e00\u4e2a\u68ee\u6797\uff08\u4e00\u4e9b\u4e0d\u76f8\u4ea4\u7684\u6811\u6784\u6210\u7684\u96c6\u5408\uff09\u3002

    \n\n

    \u8fd4\u56de\u68ee\u6797\u4e2d\u7684\u6bcf\u68f5\u6811\u3002\u4f60\u53ef\u4ee5\u6309\u4efb\u610f\u987a\u5e8f\u7ec4\u7ec7\u7b54\u6848\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1aroot = [1,2,3,4,5,6,7], to_delete = [3,5]\n\u8f93\u51fa\uff1a[[1,2,null,4],[6],[7]]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u7684\u8282\u70b9\u6570\u6700\u5927\u4e3a 1000\u3002
    • \n\t
    • \u6bcf\u4e2a\u8282\u70b9\u90fd\u6709\u4e00\u4e2a\u4ecb\u4e8e 1 \u5230 1000 \u4e4b\u95f4\u7684\u503c\uff0c\u4e14\u5404\u4e0d\u76f8\u540c\u3002
    • \n\t
    • to_delete.length <= 1000
    • \n\t
    • to_delete \u5305\u542b\u4e00\u4e9b\u4ece 1 \u5230 1000\u3001\u5404\u4e0d\u76f8\u540c\u7684\u503c\u3002
    • \n
    \n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector delNodes(TreeNode* root, vector& to_delete) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public List delNodes(TreeNode root, int[] to_delete) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def delNodes(self, root, to_delete):\n \"\"\"\n :type root: TreeNode\n :type to_delete: List[int]\n :rtype: List[TreeNode]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def delNodes(self, root: TreeNode, to_delete: List[int]) -> List[TreeNode]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nstruct TreeNode** delNodes(struct TreeNode* root, int* to_delete, int to_deleteSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public IList DelNodes(TreeNode root, int[] to_delete) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number[]} to_delete\n * @return {TreeNode[]}\n */\nvar delNodes = function(root, to_delete) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @param {Integer[]} to_delete\n# @return {TreeNode[]}\ndef del_nodes(root, to_delete)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func delNodes(_ root: TreeNode?, _ to_delete: [Int]) -> [TreeNode?] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc delNodes(root *TreeNode, to_delete []int) []*TreeNode {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def delNodes(root: TreeNode, to_delete: Array[Int]): List[TreeNode] = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun delNodes(root: TreeNode?, to_delete: IntArray): List {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n// \n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn del_nodes(root: Option>>, to_delete: Vec) -> Vec>>> {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param Integer[] $to_delete\n * @return TreeNode[]\n */\n function delNodes($root, $to_delete) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction delNodes(root: TreeNode | null, to_delete: number[]): Array {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1110](https://leetcode-cn.com/problems/delete-nodes-and-return-forest)", "[\u5220\u70b9\u6210\u6797](/solution/1100-1199/1110.Delete%20Nodes%20And%20Return%20Forest/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1110](https://leetcode.com/problems/delete-nodes-and-return-forest)", "[Delete Nodes And Return Forest](/solution/1100-1199/1110.Delete%20Nodes%20And%20Return%20Forest/README_EN.md)", "`Tree`,`Depth-first Search`", "Medium", ""]}, {"question_id": "1206", "frontend_question_id": "1109", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/corporate-flight-bookings", "url_en": "https://leetcode.com/problems/corporate-flight-bookings", "relative_path_cn": "/solution/1100-1199/1109.Corporate%20Flight%20Bookings/README.md", "relative_path_en": "/solution/1100-1199/1109.Corporate%20Flight%20Bookings/README_EN.md", "title_cn": "\u822a\u73ed\u9884\u8ba2\u7edf\u8ba1", "title_en": "Corporate Flight Bookings", "question_title_slug": "corporate-flight-bookings", "content_en": "

    There are n flights that are labeled from 1 to n.

    \n\n

    You are given an array of flight bookings bookings, where bookings[i] = [firsti, lasti, seatsi] represents a booking for flights firsti through lasti (inclusive) with seatsi seats reserved for each flight in the range.

    \n\n

    Return an array answer of length n, where answer[i] is the total number of seats reserved for flight i.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: bookings = [[1,2,10],[2,3,20],[2,5,25]], n = 5\nOutput: [10,55,45,25,25]\nExplanation:\nFlight labels:        1   2   3   4   5\nBooking 1 reserved:  10  10\nBooking 2 reserved:      20  20\nBooking 3 reserved:      25  25  25  25\nTotal seats:         10  55  45  25  25\nHence, answer = [10,55,45,25,25]\n
    \n\n

    Example 2:

    \n\n
    \nInput: bookings = [[1,2,10],[2,2,15]], n = 2\nOutput: [10,25]\nExplanation:\nFlight labels:        1   2\nBooking 1 reserved:  10  10\nBooking 2 reserved:      15\nTotal seats:         10  25\nHence, answer = [10,25]\n\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 2 * 104
    • \n\t
    • 1 <= bookings.length <= 2 * 104
    • \n\t
    • bookings[i].length == 3
    • \n\t
    • 1 <= firsti <= lasti <= n
    • \n\t
    • 1 <= seatsi <= 104
    • \n
    \n", "content_cn": "

    \u8fd9\u91cc\u6709\u00a0n\u00a0\u4e2a\u822a\u73ed\uff0c\u5b83\u4eec\u5206\u522b\u4ece 1 \u5230 n \u8fdb\u884c\u7f16\u53f7\u3002

    \n\n

    \u6709\u4e00\u4efd\u822a\u73ed\u9884\u8ba2\u8868\u00a0bookings \uff0c\u8868\u4e2d\u7b2c\u00a0i\u00a0\u6761\u9884\u8ba2\u8bb0\u5f55\u00a0bookings[i] = [firsti, lasti, seatsi]\u00a0\u610f\u5473\u7740\u5728\u4ece firsti\u00a0\u5230 lasti \uff08\u5305\u542b firsti \u548c lasti \uff09\u7684 \u6bcf\u4e2a\u822a\u73ed \u4e0a\u9884\u8ba2\u4e86 seatsi\u00a0\u4e2a\u5ea7\u4f4d\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u6570\u7ec4\u00a0answer\uff0c\u5176\u4e2d answer[i] \u662f\u822a\u73ed i \u4e0a\u9884\u8ba2\u7684\u5ea7\u4f4d\u603b\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1abookings = [[1,2,10],[2,3,20],[2,5,25]], n = 5\n\u8f93\u51fa\uff1a[10,55,45,25,25]\n\u89e3\u91ca\uff1a\n\u822a\u73ed\u7f16\u53f7        1   2   3   4   5\n\u9884\u8ba2\u8bb0\u5f55 1 \uff1a   10  10\n\u9884\u8ba2\u8bb0\u5f55 2 \uff1a       20  20\n\u9884\u8ba2\u8bb0\u5f55 3 \uff1a       25  25  25  25\n\u603b\u5ea7\u4f4d\u6570\uff1a      10  55  45  25  25\n\u56e0\u6b64\uff0canswer = [10,55,45,25,25]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1abookings = [[1,2,10],[2,2,15]], n = 2\n\u8f93\u51fa\uff1a[10,25]\n\u89e3\u91ca\uff1a\n\u822a\u73ed\u7f16\u53f7        1   2\n\u9884\u8ba2\u8bb0\u5f55 1 \uff1a   10  10\n\u9884\u8ba2\u8bb0\u5f55 2 \uff1a       15\n\u603b\u5ea7\u4f4d\u6570\uff1a      10  25\n\u56e0\u6b64\uff0canswer = [10,25]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 2 * 104
    • \n\t
    • 1 <= bookings.length <= 2 * 104
    • \n\t
    • bookings[i].length == 3
    • \n\t
    • 1 <= firsti <= lasti <= n
    • \n\t
    • 1 <= seatsi <= 104
    • \n
    \n", "tags_en": ["Array", "Math"], "tags_cn": ["\u6570\u7ec4", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector corpFlightBookings(vector>& bookings, int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] corpFlightBookings(int[][] bookings, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def corpFlightBookings(self, bookings, n):\n \"\"\"\n :type bookings: List[List[int]]\n :type n: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def corpFlightBookings(self, bookings: List[List[int]], n: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* corpFlightBookings(int** bookings, int bookingsSize, int* bookingsColSize, int n, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] CorpFlightBookings(int[][] bookings, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} bookings\n * @param {number} n\n * @return {number[]}\n */\nvar corpFlightBookings = function(bookings, n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} bookings\n# @param {Integer} n\n# @return {Integer[]}\ndef corp_flight_bookings(bookings, n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func corpFlightBookings(_ bookings: [[Int]], _ n: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func corpFlightBookings(bookings [][]int, n int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def corpFlightBookings(bookings: Array[Array[Int]], n: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun corpFlightBookings(bookings: Array, n: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn corp_flight_bookings(bookings: Vec>, n: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $bookings\n * @param Integer $n\n * @return Integer[]\n */\n function corpFlightBookings($bookings, $n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function corpFlightBookings(bookings: number[][], n: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (corp-flight-bookings bookings n)\n (-> (listof (listof exact-integer?)) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1109](https://leetcode-cn.com/problems/corporate-flight-bookings)", "[\u822a\u73ed\u9884\u8ba2\u7edf\u8ba1](/solution/1100-1199/1109.Corporate%20Flight%20Bookings/README.md)", "`\u6570\u7ec4`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1109](https://leetcode.com/problems/corporate-flight-bookings)", "[Corporate Flight Bookings](/solution/1100-1199/1109.Corporate%20Flight%20Bookings/README_EN.md)", "`Array`,`Math`", "Medium", ""]}, {"question_id": "1205", "frontend_question_id": "1108", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/defanging-an-ip-address", "url_en": "https://leetcode.com/problems/defanging-an-ip-address", "relative_path_cn": "/solution/1100-1199/1108.Defanging%20an%20IP%20Address/README.md", "relative_path_en": "/solution/1100-1199/1108.Defanging%20an%20IP%20Address/README_EN.md", "title_cn": "IP \u5730\u5740\u65e0\u6548\u5316", "title_en": "Defanging an IP Address", "question_title_slug": "defanging-an-ip-address", "content_en": "

    Given a valid (IPv4) IP address, return a defanged version of that IP address.

    \r\n\r\n

    A defanged IP address replaces every period "." with "[.]".

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n
    Input: address = \"1.1.1.1\"\r\nOutput: \"1[.]1[.]1[.]1\"\r\n

    Example 2:

    \r\n
    Input: address = \"255.100.50.0\"\r\nOutput: \"255[.]100[.]50[.]0\"\r\n
    \r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • The given address is a valid IPv4 address.
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6709\u6548\u7684 IPv4 \u5730\u5740 address\uff0c\u8fd4\u56de\u8fd9\u4e2a IP \u5730\u5740\u7684\u65e0\u6548\u5316\u7248\u672c\u3002

    \n\n

    \u6240\u8c13\u65e0\u6548\u5316 IP \u5730\u5740\uff0c\u5176\u5b9e\u5c31\u662f\u7528 "[.]" \u4ee3\u66ff\u4e86\u6bcf\u4e2a "."\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aaddress = "1.1.1.1"\n\u8f93\u51fa\uff1a"1[.]1[.]1[.]1"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aaddress = "255.100.50.0"\n\u8f93\u51fa\uff1a"255[.]100[.]50[.]0"\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u7ed9\u51fa\u7684 address \u662f\u4e00\u4e2a\u6709\u6548\u7684 IPv4 \u5730\u5740
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string defangIPaddr(string address) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String defangIPaddr(String address) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def defangIPaddr(self, address):\n \"\"\"\n :type address: str\n :rtype: str\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def defangIPaddr(self, address: str) -> str:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * defangIPaddr(char * address){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string DefangIPaddr(string address) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} address\n * @return {string}\n */\nvar defangIPaddr = function(address) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} address\n# @return {String}\ndef defang_i_paddr(address)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func defangIPaddr(_ address: String) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func defangIPaddr(address string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def defangIPaddr(address: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun defangIPaddr(address: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn defang_i_paddr(address: String) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $address\n * @return String\n */\n function defangIPaddr($address) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function defangIPaddr(address: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (defang-i-paddr address)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1108](https://leetcode-cn.com/problems/defanging-an-ip-address)", "[IP \u5730\u5740\u65e0\u6548\u5316](/solution/1100-1199/1108.Defanging%20an%20IP%20Address/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1108](https://leetcode.com/problems/defanging-an-ip-address)", "[Defanging an IP Address](/solution/1100-1199/1108.Defanging%20an%20IP%20Address/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1204", "frontend_question_id": "1107", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/new-users-daily-count", "url_en": "https://leetcode.com/problems/new-users-daily-count", "relative_path_cn": "/solution/1100-1199/1107.New%20Users%20Daily%20Count/README.md", "relative_path_en": "/solution/1100-1199/1107.New%20Users%20Daily%20Count/README_EN.md", "title_cn": "\u6bcf\u65e5\u65b0\u7528\u6237\u7edf\u8ba1", "title_en": "New Users Daily Count", "question_title_slug": "new-users-daily-count", "content_en": "

    Table: Traffic

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| user_id       | int     |\n| activity      | enum    |\n| activity_date | date    |\n+---------------+---------+\nThere is no primary key for this table, it may have duplicate rows.\nThe activity column is an ENUM type of ('login', 'logout', 'jobs', 'groups', 'homepage').\n
    \n\n

     

    \n\n

    Write an SQL query that reports for every date within at most 90 days from today, the number of users that logged in for the first time on that date. Assume today is 2019-06-30.

    \n\n

    The query result format is in the following example:

    \n\n
    \nTraffic table:\n+---------+----------+---------------+\n| user_id | activity | activity_date |\n+---------+----------+---------------+\n| 1       | login    | 2019-05-01    |\n| 1       | homepage | 2019-05-01    |\n| 1       | logout   | 2019-05-01    |\n| 2       | login    | 2019-06-21    |\n| 2       | logout   | 2019-06-21    |\n| 3       | login    | 2019-01-01    |\n| 3       | jobs     | 2019-01-01    |\n| 3       | logout   | 2019-01-01    |\n| 4       | login    | 2019-06-21    |\n| 4       | groups   | 2019-06-21    |\n| 4       | logout   | 2019-06-21    |\n| 5       | login    | 2019-03-01    |\n| 5       | logout   | 2019-03-01    |\n| 5       | login    | 2019-06-21    |\n| 5       | logout   | 2019-06-21    |\n+---------+----------+---------------+\n\nResult table:\n+------------+-------------+\n| login_date | user_count  |\n+------------+-------------+\n| 2019-05-01 | 1           |\n| 2019-06-21 | 2           |\n+------------+-------------+\nNote that we only care about dates with non zero user count.\nThe user with id 5 first logged in on 2019-03-01 so he's not counted on 2019-06-21.\n
    \n", "content_cn": "

    Traffic \u8868\uff1a

    \n\n
    +---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| user_id       | int     |\n| activity      | enum    |\n| activity_date | date    |\n+---------------+---------+\n\u8be5\u8868\u6ca1\u6709\u4e3b\u952e\uff0c\u5b83\u53ef\u80fd\u6709\u91cd\u590d\u7684\u884c\u3002\nactivity \u5217\u662f ENUM \u7c7b\u578b\uff0c\u53ef\u80fd\u53d6 ('login', 'logout', 'jobs', 'groups', 'homepage') \u51e0\u4e2a\u503c\u4e4b\u4e00\u3002\n
    \n\n

     

    \n\n

    \u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\uff0c\u4ee5\u67e5\u8be2\u4ece\u4eca\u5929\u8d77\u6700\u591a 90 \u5929\u5185\uff0c\u6bcf\u4e2a\u65e5\u671f\u8be5\u65e5\u671f\u9996\u6b21\u767b\u5f55\u7684\u7528\u6237\u6570\u3002\u5047\u8bbe\u4eca\u5929\u662f 2019-06-30.

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a\uff1a

    \n\n
    Traffic \u8868\uff1a\n+---------+----------+---------------+\n| user_id | activity | activity_date |\n+---------+----------+---------------+\n| 1       | login    | 2019-05-01    |\n| 1       | homepage | 2019-05-01    |\n| 1       | logout   | 2019-05-01    |\n| 2       | login    | 2019-06-21    |\n| 2       | logout   | 2019-06-21    |\n| 3       | login    | 2019-01-01    |\n| 3       | jobs     | 2019-01-01    |\n| 3       | logout   | 2019-01-01    |\n| 4       | login    | 2019-06-21    |\n| 4       | groups   | 2019-06-21    |\n| 4       | logout   | 2019-06-21    |\n| 5       | login    | 2019-03-01    |\n| 5       | logout   | 2019-03-01    |\n| 5       | login    | 2019-06-21    |\n| 5       | logout   | 2019-06-21    |\n+---------+----------+---------------+\n\nResult \u8868\uff1a\n+------------+-------------+\n| login_date | user_count  |\n+------------+-------------+\n| 2019-05-01 | 1           |\n| 2019-06-21 | 2           |\n+------------+-------------+\n\u8bf7\u6ce8\u610f\uff0c\u6211\u4eec\u53ea\u5173\u5fc3\u7528\u6237\u6570\u975e\u96f6\u7684\u65e5\u671f.\nID \u4e3a 5 \u7684\u7528\u6237\u7b2c\u4e00\u6b21\u767b\u9646\u4e8e 2019-03-01\uff0c\u56e0\u6b64\u4ed6\u4e0d\u7b97\u5728 2019-06-21 \u7684\u7684\u7edf\u8ba1\u5185\u3002\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1107](https://leetcode-cn.com/problems/new-users-daily-count)", "[\u6bcf\u65e5\u65b0\u7528\u6237\u7edf\u8ba1](/solution/1100-1199/1107.New%20Users%20Daily%20Count/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1107](https://leetcode.com/problems/new-users-daily-count)", "[New Users Daily Count](/solution/1100-1199/1107.New%20Users%20Daily%20Count/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1203", "frontend_question_id": "1114", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/print-in-order", "url_en": "https://leetcode.com/problems/print-in-order", "relative_path_cn": "/solution/1100-1199/1114.Print%20in%20Order/README.md", "relative_path_en": "/solution/1100-1199/1114.Print%20in%20Order/README_EN.md", "title_cn": "\u6309\u5e8f\u6253\u5370", "title_en": "Print in Order", "question_title_slug": "print-in-order", "content_en": "

    Suppose we have a class:

    \n\n
    \npublic class Foo {\n  public void first() { print("first"); }\n  public void second() { print("second"); }\n  public void third() { print("third"); }\n}\n
    \n\n

    The same instance of Foo will be passed to three different threads. Thread A will call first(), thread B will call second(), and thread C will call third(). Design a mechanism and modify the program to ensure that second() is executed after first(), and third() is executed after second().

    \n\n

    Note:

    \n\n

    We do not know how the threads will be scheduled in the operating system, even though the numbers in the input seem to imply the ordering. The input format you see is mainly to ensure our tests' comprehensiveness.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,3]\nOutput: "firstsecondthird"\nExplanation: There are three threads being fired asynchronously. The input [1,2,3] means thread A calls first(), thread B calls second(), and thread C calls third(). "firstsecondthird" is the correct output.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,3,2]\nOutput: "firstsecondthird"\nExplanation: The input [1,3,2] means thread A calls first(), thread B calls third(), and thread C calls second(). "firstsecondthird" is the correct output.\n
    \n", "content_cn": "

    \u6211\u4eec\u63d0\u4f9b\u4e86\u4e00\u4e2a\u7c7b\uff1a

    \n\n
    \npublic class Foo {\n\u00a0 public void first() { print(\"first\"); }\n\u00a0 public void second() { print(\"second\"); }\n\u00a0 public void third() { print(\"third\"); }\n}
    \n\n

    \u4e09\u4e2a\u4e0d\u540c\u7684\u7ebf\u7a0b A\u3001B\u3001C \u5c06\u4f1a\u5171\u7528\u4e00\u4e2a\u00a0Foo\u00a0\u5b9e\u4f8b\u3002

    \n\n
      \n\t
    • \u4e00\u4e2a\u5c06\u4f1a\u8c03\u7528 first() \u65b9\u6cd5
    • \n\t
    • \u4e00\u4e2a\u5c06\u4f1a\u8c03\u7528\u00a0second() \u65b9\u6cd5
    • \n\t
    • \u8fd8\u6709\u4e00\u4e2a\u5c06\u4f1a\u8c03\u7528 third() \u65b9\u6cd5
    • \n
    \n\n

    \u8bf7\u8bbe\u8ba1\u4fee\u6539\u7a0b\u5e8f\uff0c\u4ee5\u786e\u4fdd second() \u65b9\u6cd5\u5728 first() \u65b9\u6cd5\u4e4b\u540e\u88ab\u6267\u884c\uff0cthird() \u65b9\u6cd5\u5728 second() \u65b9\u6cd5\u4e4b\u540e\u88ab\u6267\u884c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: [1,2,3]\n\u8f93\u51fa: \"firstsecondthird\"\n\u89e3\u91ca: \n\u6709\u4e09\u4e2a\u7ebf\u7a0b\u4f1a\u88ab\u5f02\u6b65\u542f\u52a8\u3002\n\u8f93\u5165 [1,2,3] \u8868\u793a\u7ebf\u7a0b A \u5c06\u4f1a\u8c03\u7528 first() \u65b9\u6cd5\uff0c\u7ebf\u7a0b B \u5c06\u4f1a\u8c03\u7528 second() \u65b9\u6cd5\uff0c\u7ebf\u7a0b C \u5c06\u4f1a\u8c03\u7528 third() \u65b9\u6cd5\u3002\n\u6b63\u786e\u7684\u8f93\u51fa\u662f \"firstsecondthird\"\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: [1,3,2]\n\u8f93\u51fa: \"firstsecondthird\"\n\u89e3\u91ca: \n\u8f93\u5165 [1,3,2] \u8868\u793a\u7ebf\u7a0b A \u5c06\u4f1a\u8c03\u7528 first() \u65b9\u6cd5\uff0c\u7ebf\u7a0b B \u5c06\u4f1a\u8c03\u7528 third() \u65b9\u6cd5\uff0c\u7ebf\u7a0b C \u5c06\u4f1a\u8c03\u7528 second() \u65b9\u6cd5\u3002\n\u6b63\u786e\u7684\u8f93\u51fa\u662f \"firstsecondthird\"\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u5c3d\u7ba1\u8f93\u5165\u4e2d\u7684\u6570\u5b57\u4f3c\u4e4e\u6697\u793a\u4e86\u987a\u5e8f\uff0c\u4f46\u662f\u6211\u4eec\u5e76\u4e0d\u4fdd\u8bc1\u7ebf\u7a0b\u5728\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u7684\u8c03\u5ea6\u987a\u5e8f\u3002
    • \n\t
    • \u4f60\u770b\u5230\u7684\u8f93\u5165\u683c\u5f0f\u4e3b\u8981\u662f\u4e3a\u4e86\u786e\u4fdd\u6d4b\u8bd5\u7684\u5168\u9762\u6027\u3002
    • \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Foo {\npublic:\n Foo() {\n \n }\n\n void first(function printFirst) {\n \n // printFirst() outputs \"first\". Do not change or remove this line.\n printFirst();\n }\n\n void second(function printSecond) {\n \n // printSecond() outputs \"second\". Do not change or remove this line.\n printSecond();\n }\n\n void third(function printThird) {\n \n // printThird() outputs \"third\". Do not change or remove this line.\n printThird();\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Foo {\n\n public Foo() {\n \n }\n\n public void first(Runnable printFirst) throws InterruptedException {\n \n // printFirst.run() outputs \"first\". Do not change or remove this line.\n printFirst.run();\n }\n\n public void second(Runnable printSecond) throws InterruptedException {\n \n // printSecond.run() outputs \"second\". Do not change or remove this line.\n printSecond.run();\n }\n\n public void third(Runnable printThird) throws InterruptedException {\n \n // printThird.run() outputs \"third\". Do not change or remove this line.\n printThird.run();\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Foo(object):\n def __init__(self):\n pass\n\n\n def first(self, printFirst):\n \"\"\"\n :type printFirst: method\n :rtype: void\n \"\"\"\n \n # printFirst() outputs \"first\". Do not change or remove this line.\n printFirst()\n\n\n def second(self, printSecond):\n \"\"\"\n :type printSecond: method\n :rtype: void\n \"\"\"\n \n # printSecond() outputs \"second\". Do not change or remove this line.\n printSecond()\n \n \n def third(self, printThird):\n \"\"\"\n :type printThird: method\n :rtype: void\n \"\"\"\n \n # printThird() outputs \"third\". Do not change or remove this line.\n printThird()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Foo:\n def __init__(self):\n pass\n\n\n def first(self, printFirst: 'Callable[[], None]') -> None:\n \n # printFirst() outputs \"first\". Do not change or remove this line.\n printFirst()\n\n\n def second(self, printSecond: 'Callable[[], None]') -> None:\n \n # printSecond() outputs \"second\". Do not change or remove this line.\n printSecond()\n\n\n def third(self, printThird: 'Callable[[], None]') -> None:\n \n # printThird() outputs \"third\". Do not change or remove this line.\n printThird()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "typedef struct {\n // User defined data may be declared here.\n \n} Foo;\n\nFoo* fooCreate() {\n Foo* obj = (Foo*) malloc(sizeof(Foo));\n \n // Initialize user defined data here.\n \n return obj;\n}\n\nvoid first(Foo* obj) {\n \n // printFirst() outputs \"first\". Do not change or remove this line.\n printFirst();\n}\n\nvoid second(Foo* obj) {\n \n // printSecond() outputs \"second\". Do not change or remove this line.\n printSecond();\n}\n\nvoid third(Foo* obj) {\n \n // printThird() outputs \"third\". Do not change or remove this line.\n printThird();\n}\n\nvoid fooFree(Foo* obj) {\n // User defined data may be cleaned up here.\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Foo {\n\n public Foo() {\n \n }\n\n public void First(Action printFirst) {\n \n // printFirst() outputs \"first\". Do not change or remove this line.\n printFirst();\n }\n\n public void Second(Action printSecond) {\n \n // printSecond() outputs \"second\". Do not change or remove this line.\n printSecond();\n }\n\n public void Third(Action printThird) {\n \n // printThird() outputs \"third\". Do not change or remove this line.\n printThird();\n }\n}", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1114](https://leetcode-cn.com/problems/print-in-order)", "[\u6309\u5e8f\u6253\u5370](/solution/1100-1199/1114.Print%20in%20Order/README.md)", "", "\u7b80\u5355", ""], "md_table_row_en": ["[1114](https://leetcode.com/problems/print-in-order)", "[Print in Order](/solution/1100-1199/1114.Print%20in%20Order/README_EN.md)", "", "Easy", ""]}, {"question_id": "1202", "frontend_question_id": "1246", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/palindrome-removal", "url_en": "https://leetcode.com/problems/palindrome-removal", "relative_path_cn": "/solution/1200-1299/1246.Palindrome%20Removal/README.md", "relative_path_en": "/solution/1200-1299/1246.Palindrome%20Removal/README_EN.md", "title_cn": "\u5220\u9664\u56de\u6587\u5b50\u6570\u7ec4", "title_en": "Palindrome Removal", "question_title_slug": "palindrome-removal", "content_en": "

    Given an integer array arr, in one move you can select a palindromic subarray arr[i], arr[i+1], ..., arr[j] where i <= j, and remove that subarray from the given array. Note that after removing a subarray, the elements on the left and on the right of that subarray move to fill the gap left by the removal.

    \n\n

    Return the minimum number of moves needed to remove all numbers from the array.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr = [1,2]\nOutput: 2\n
    \n\n

    Example 2:

    \n\n
    \nInput: arr = [1,3,4,1,5]\nOutput: 3\nExplanation: Remove [4] then remove [1,3,1] then remove [5].\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= arr.length <= 100
    • \n\t
    • 1 <= arr[i] <= 20
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr\uff0c\u6bcf\u4e00\u6b21\u64cd\u4f5c\u4f60\u90fd\u53ef\u4ee5\u9009\u62e9\u5e76\u5220\u9664\u5b83\u7684\u4e00\u4e2a \u56de\u6587 \u5b50\u6570\u7ec4 arr[i], arr[i+1], ..., arr[j]\uff08 i <= j\uff09\u3002

    \n\n

    \u6ce8\u610f\uff0c\u6bcf\u5f53\u4f60\u5220\u9664\u6389\u4e00\u4e2a\u5b50\u6570\u7ec4\uff0c\u53f3\u4fa7\u5143\u7d20\u90fd\u4f1a\u81ea\u884c\u5411\u524d\u79fb\u52a8\u586b\u8865\u7a7a\u4f4d\u3002

    \n\n

    \u8bf7\u4f60\u8ba1\u7b97\u5e76\u8fd4\u56de\u4ece\u6570\u7ec4\u4e2d\u5220\u9664\u6240\u6709\u6570\u5b57\u6240\u9700\u7684\u6700\u5c11\u64cd\u4f5c\u6b21\u6570\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [1,2]\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [1,3,4,1,5]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u5148\u5220\u9664 [4]\uff0c\u7136\u540e\u5220\u9664 [1,3,1]\uff0c\u6700\u540e\u518d\u5220\u9664 [5]\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= arr.length <= 100
    • \n\t
    • 1 <= arr[i] <= 20
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minimumMoves(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minimumMoves(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimumMoves(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimumMoves(self, arr: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minimumMoves(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinimumMoves(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar minimumMoves = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef minimum_moves(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimumMoves(_ arr: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimumMoves(arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimumMoves(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimumMoves(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimum_moves(arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function minimumMoves($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimumMoves(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimum-moves arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1246](https://leetcode-cn.com/problems/palindrome-removal)", "[\u5220\u9664\u56de\u6587\u5b50\u6570\u7ec4](/solution/1200-1299/1246.Palindrome%20Removal/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1246](https://leetcode.com/problems/palindrome-removal)", "[Palindrome Removal](/solution/1200-1299/1246.Palindrome%20Removal/README_EN.md)", "`Dynamic Programming`", "Hard", "\ud83d\udd12"]}, {"question_id": "1201", "frontend_question_id": "1273", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/delete-tree-nodes", "url_en": "https://leetcode.com/problems/delete-tree-nodes", "relative_path_cn": "/solution/1200-1299/1273.Delete%20Tree%20Nodes/README.md", "relative_path_en": "/solution/1200-1299/1273.Delete%20Tree%20Nodes/README_EN.md", "title_cn": "\u5220\u9664\u6811\u8282\u70b9", "title_en": "Delete Tree Nodes", "question_title_slug": "delete-tree-nodes", "content_en": "

    A tree rooted at node 0 is given as follows:

    \n\n
      \n\t
    • The number of nodes is nodes;
    • \n\t
    • The value of the i-th node is value[i];
    • \n\t
    • The parent of the i-th node is parent[i].
    • \n
    \n\n

    Remove every subtree whose sum of values of nodes is zero.

    \n\n

    After doing so, return the number of nodes remaining in the tree.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: nodes = 7, parent = [-1,0,0,1,2,2,2], value = [1,-2,4,0,-2,-1,-1]\nOutput: 2\n
    \n\n

    Example 2:

    \n\n
    \nInput: nodes = 7, parent = [-1,0,0,1,2,2,2], value = [1,-2,4,0,-2,-1,-2]\nOutput: 6\n
    \n\n

    Example 3:

    \n\n
    \nInput: nodes = 5, parent = [-1,0,1,0,0], value = [-672,441,18,728,378]\nOutput: 5\n
    \n\n

    Example 4:

    \n\n
    \nInput: nodes = 5, parent = [-1,0,0,1,1], value = [-686,-842,616,-739,-746]\nOutput: 5\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nodes <= 10^4
    • \n\t
    • parent.length == nodes
    • \n\t
    • 0 <= parent[i] <= nodes - 1
    • \n\t
    • parent[0] == -1 which indicates that 0 is the root.
    • \n\t
    • value.length == nodes
    • \n\t
    • -10^5 <= value[i] <= 10^5
    • \n\t
    • The given input is guaranteed to represent a valid tree.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u68f5\u4ee5\u8282\u70b9 0 \u4e3a\u6839\u8282\u70b9\u7684\u6811\uff0c\u5b9a\u4e49\u5982\u4e0b\uff1a

    \n\n
      \n\t
    • \u8282\u70b9\u7684\u603b\u6570\u4e3a nodes \u4e2a\uff1b
    • \n\t
    • \u7b2c i \u4e2a\u8282\u70b9\u7684\u503c\u4e3a value[i] \uff1b
    • \n\t
    • \u7b2c i \u4e2a\u8282\u70b9\u7684\u7236\u8282\u70b9\u662f parent[i] \u3002
    • \n
    \n\n

    \u8bf7\u4f60\u5220\u9664\u8282\u70b9\u503c\u4e4b\u548c\u4e3a 0 \u7684\u6bcf\u4e00\u68f5\u5b50\u6811\u3002

    \n\n

    \u5728\u5b8c\u6210\u6240\u6709\u5220\u9664\u4e4b\u540e\uff0c\u8fd4\u56de\u6811\u4e2d\u5269\u4f59\u8282\u70b9\u7684\u6570\u76ee\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1anodes = 7, parent = [-1,0,0,1,2,2,2], value = [1,-2,4,0,-2,-1,-1]\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anodes = 7, parent = [-1,0,0,1,2,2,2], value = [1,-2,4,0,-2,-1,-2]\n\u8f93\u51fa\uff1a6\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1anodes = 5, parent = [-1,0,1,0,0], value = [-672,441,18,728,378]\n\u8f93\u51fa\uff1a5\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1anodes = 5, parent = [-1,0,0,1,1], value = [-686,-842,616,-739,-746]\n\u8f93\u51fa\uff1a5\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nodes <= 10^4
    • \n\t
    • parent.length == nodes
    • \n\t
    • 0 <= parent[i] <= nodes - 1
    • \n\t
    • parent[0] == -1 \u8868\u793a\u8282\u70b9 0 \u662f\u6811\u7684\u6839\u3002
    • \n\t
    • value.length == nodes
    • \n\t
    • -10^5 <= value[i] <= 10^5
    • \n\t
    • \u9898\u76ee\u8f93\u5165\u6570\u636e \u4fdd\u8bc1 \u662f\u4e00\u68f5 \u6709\u6548\u7684\u6811 \u3002
    • \n
    \n", "tags_en": ["Depth-first Search", "Dynamic Programming"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int deleteTreeNodes(int nodes, vector& parent, vector& value) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int deleteTreeNodes(int nodes, int[] parent, int[] value) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def deleteTreeNodes(self, nodes, parent, value):\n \"\"\"\n :type nodes: int\n :type parent: List[int]\n :type value: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def deleteTreeNodes(self, nodes: int, parent: List[int], value: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint deleteTreeNodes(int nodes, int* parent, int parentSize, int* value, int valueSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int DeleteTreeNodes(int nodes, int[] parent, int[] value) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} nodes\n * @param {number[]} parent\n * @param {number[]} value\n * @return {number}\n */\nvar deleteTreeNodes = function(nodes, parent, value) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} nodes\n# @param {Integer[]} parent\n# @param {Integer[]} value\n# @return {Integer}\ndef delete_tree_nodes(nodes, parent, value)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func deleteTreeNodes(_ nodes: Int, _ parent: [Int], _ value: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func deleteTreeNodes(nodes int, parent []int, value []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def deleteTreeNodes(nodes: Int, parent: Array[Int], value: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun deleteTreeNodes(nodes: Int, parent: IntArray, value: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn delete_tree_nodes(nodes: i32, parent: Vec, value: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $nodes\n * @param Integer[] $parent\n * @param Integer[] $value\n * @return Integer\n */\n function deleteTreeNodes($nodes, $parent, $value) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function deleteTreeNodes(nodes: number, parent: number[], value: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (delete-tree-nodes nodes parent value)\n (-> exact-integer? (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1273](https://leetcode-cn.com/problems/delete-tree-nodes)", "[\u5220\u9664\u6811\u8282\u70b9](/solution/1200-1299/1273.Delete%20Tree%20Nodes/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1273](https://leetcode.com/problems/delete-tree-nodes)", "[Delete Tree Nodes](/solution/1200-1299/1273.Delete%20Tree%20Nodes/README_EN.md)", "`Depth-first Search`,`Dynamic Programming`", "Medium", "\ud83d\udd12"]}, {"question_id": "1200", "frontend_question_id": "1272", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/remove-interval", "url_en": "https://leetcode.com/problems/remove-interval", "relative_path_cn": "/solution/1200-1299/1272.Remove%20Interval/README.md", "relative_path_en": "/solution/1200-1299/1272.Remove%20Interval/README_EN.md", "title_cn": "\u5220\u9664\u533a\u95f4", "title_en": "Remove Interval", "question_title_slug": "remove-interval", "content_en": "

    A set of real numbers can be represented as the union of several disjoint intervals, where each interval is in the form [a, b). A real number x is in the set if one of its intervals [a, b) contains x (i.e. a <= x < b).

    \n\n

    You are given a sorted list of disjoint intervals intervals representing a set of real numbers as described above, where intervals[i] = [ai, bi] represents the interval [ai, bi). You are also given another interval toBeRemoved.

    \n\n

    Return the set of real numbers with the interval toBeRemoved removed from intervals. In other words, return the set of real numbers such that every x in the set is in intervals but not in toBeRemoved. Your answer should be a sorted list of disjoint intervals as described above.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: intervals = [[0,2],[3,4],[5,7]], toBeRemoved = [1,6]\nOutput: [[0,1],[6,7]]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: intervals = [[0,5]], toBeRemoved = [2,3]\nOutput: [[0,2],[3,5]]\n
    \n\n

    Example 3:

    \n\n
    \nInput: intervals = [[-5,-4],[-3,-2],[1,2],[3,5],[8,9]], toBeRemoved = [-1,4]\nOutput: [[-5,-4],[-3,-2],[4,5],[8,9]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= intervals.length <= 104
    • \n\t
    • -109 <= ai < bi <= 109
    • \n
    \n", "content_cn": "

    \u5b9e\u6570\u96c6\u5408\u53ef\u4ee5\u8868\u793a\u4e3a\u82e5\u5e72\u4e0d\u76f8\u4ea4\u533a\u95f4\u7684\u5e76\u96c6\uff0c\u5176\u4e2d\u6bcf\u4e2a\u533a\u95f4\u7684\u5f62\u5f0f\u4e3a [a, b)\uff08\u5de6\u95ed\u53f3\u5f00\uff09\uff0c\u8868\u793a\u6ee1\u8db3\u00a0a <= x < b \u7684\u6240\u6709\u5b9e\u6570\u00a0 x\u00a0\u7684\u96c6\u5408\u3002\u5982\u679c\u67d0\u4e2a\u533a\u95f4\u00a0[a, b) \u4e2d\u5305\u542b\u5b9e\u6570 x \uff0c\u5219\u79f0\u5b9e\u6570 x \u5728\u96c6\u5408\u4e2d\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a \u6709\u5e8f\u7684 \u4e0d\u76f8\u4ea4\u533a\u95f4\u5217\u8868 intervals \u548c\u4e00\u4e2a\u8981\u5220\u9664\u7684\u533a\u95f4 toBeRemoved \u3002intervals \u8868\u793a\u4e00\u4e2a\u5b9e\u6570\u96c6\u5408\uff0c\u5176\u4e2d\u6bcf\u4e00\u9879 intervals[i] = [ai, bi] \u90fd\u8868\u793a\u4e00\u4e2a\u533a\u95f4 [ai, bi) \u3002

    \n\n

    \u8bf7\u4f60 intervals \u4e2d\u4efb\u610f\u533a\u95f4\u4e0e toBeRemoved \u6709\u4ea4\u96c6\u7684\u90e8\u5206\u90fd\u5220\u9664\u3002\u8fd4\u56de\u5220\u9664\u6240\u6709\u4ea4\u96c6\u533a\u95f4\u540e\uff0c intervals \u5269\u4f59\u90e8\u5206\u7684 \u6709\u5e8f \u5217\u8868\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u8fd4\u56de\u5b9e\u6570\u96c6\u5408\uff0c\u5e76\u6ee1\u8db3\u96c6\u5408\u4e2d\u7684\u6bcf\u4e2a\u5b9e\u6570 x \u90fd\u5728\u00a0intervals \u4e2d\uff0c\u4f46\u4e0d\u5728 toBeRemoved \u4e2d\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aintervals = [[0,2],[3,4],[5,7]], toBeRemoved = [1,6]\n\u8f93\u51fa\uff1a[[0,1],[6,7]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aintervals = [[0,5]], toBeRemoved = [2,3]\n\u8f93\u51fa\uff1a[[0,2],[3,5]]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aintervals = [[-5,-4],[-3,-2],[1,2],[3,5],[8,9]], toBeRemoved = [-1,4]\n\u8f93\u51fa\uff1a[[-5,-4],[-3,-2],[4,5],[8,9]]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= intervals.length <= 104
    • \n\t
    • -109 <= ai < bi <= 109
    • \n
    \n", "tags_en": ["Math", "Line Sweep"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> removeInterval(vector>& intervals, vector& toBeRemoved) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> removeInterval(int[][] intervals, int[] toBeRemoved) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def removeInterval(self, intervals, toBeRemoved):\n \"\"\"\n :type intervals: List[List[int]]\n :type toBeRemoved: List[int]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def removeInterval(self, intervals: List[List[int]], toBeRemoved: List[int]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** removeInterval(int** intervals, int intervalsSize, int* intervalsColSize, int* toBeRemoved, int toBeRemovedSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> RemoveInterval(int[][] intervals, int[] toBeRemoved) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} intervals\n * @param {number[]} toBeRemoved\n * @return {number[][]}\n */\nvar removeInterval = function(intervals, toBeRemoved) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} intervals\n# @param {Integer[]} to_be_removed\n# @return {Integer[][]}\ndef remove_interval(intervals, to_be_removed)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func removeInterval(_ intervals: [[Int]], _ toBeRemoved: [Int]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func removeInterval(intervals [][]int, toBeRemoved []int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def removeInterval(intervals: Array[Array[Int]], toBeRemoved: Array[Int]): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun removeInterval(intervals: Array, toBeRemoved: IntArray): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn remove_interval(intervals: Vec>, to_be_removed: Vec) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $intervals\n * @param Integer[] $toBeRemoved\n * @return Integer[][]\n */\n function removeInterval($intervals, $toBeRemoved) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function removeInterval(intervals: number[][], toBeRemoved: number[]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (remove-interval intervals toBeRemoved)\n (-> (listof (listof exact-integer?)) (listof exact-integer?) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1272](https://leetcode-cn.com/problems/remove-interval)", "[\u5220\u9664\u533a\u95f4](/solution/1200-1299/1272.Remove%20Interval/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1272](https://leetcode.com/problems/remove-interval)", "[Remove Interval](/solution/1200-1299/1272.Remove%20Interval/README_EN.md)", "`Math`,`Line Sweep`", "Medium", "\ud83d\udd12"]}, {"question_id": "1199", "frontend_question_id": "1271", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/hexspeak", "url_en": "https://leetcode.com/problems/hexspeak", "relative_path_cn": "/solution/1200-1299/1271.Hexspeak/README.md", "relative_path_en": "/solution/1200-1299/1271.Hexspeak/README_EN.md", "title_cn": "\u5341\u516d\u8fdb\u5236\u9b54\u672f\u6570\u5b57", "title_en": "Hexspeak", "question_title_slug": "hexspeak", "content_en": "

    A decimal number can be converted to its Hexspeak representation by first converting it to an uppercase hexadecimal string, then replacing all occurrences of the digit 0 with the letter O, and the digit 1 with the letter I.  Such a representation is valid if and only if it consists only of the letters in the set {"A", "B", "C", "D", "E", "F", "I", "O"}.

    \n\n

    Given a string num representing a decimal integer N, return the Hexspeak representation of N if it is valid, otherwise return "ERROR".

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: num = "257"\nOutput: "IOI"\nExplanation:  257 is 101 in hexadecimal.\n
    \n\n

    Example 2:

    \n\n
    \nInput: num = "3"\nOutput: "ERROR"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= N <= 10^12
    • \n\t
    • There are no leading zeros in the given string.
    • \n\t
    • All answers must be in uppercase letters.
    • \n
    \n", "content_cn": "

    \u4f60\u6709\u4e00\u4e2a\u5341\u8fdb\u5236\u6570\u5b57\uff0c\u8bf7\u6309\u7167\u6b64\u89c4\u5219\u5c06\u5b83\u53d8\u6210\u300c\u5341\u516d\u8fdb\u5236\u9b54\u672f\u6570\u5b57\u300d\uff1a\u9996\u5148\u5c06\u5b83\u53d8\u6210\u5b57\u6bcd\u5927\u5199\u7684\u5341\u516d\u8fdb\u5236\u5b57\u7b26\u4e32\uff0c\u7136\u540e\u5c06\u6240\u6709\u7684\u6570\u5b57 0 \u53d8\u6210\u5b57\u6bcd O \uff0c\u5c06\u6570\u5b57 1  \u53d8\u6210\u5b57\u6bcd I \u3002

    \n\n

    \u5982\u679c\u4e00\u4e2a\u6570\u5b57\u5728\u8f6c\u6362\u540e\u53ea\u5305\u542b {"A", "B", "C", "D", "E", "F", "I", "O"} \uff0c\u90a3\u4e48\u6211\u4eec\u5c31\u8ba4\u4e3a\u8fd9\u4e2a\u8f6c\u6362\u662f\u6709\u6548\u7684\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 num \uff0c\u5b83\u8868\u793a\u4e00\u4e2a\u5341\u8fdb\u5236\u6570 N\uff0c\u5982\u679c\u5b83\u7684\u5341\u516d\u8fdb\u5236\u9b54\u672f\u6570\u5b57\u8f6c\u6362\u662f\u6709\u6548\u7684\uff0c\u8bf7\u8fd4\u56de\u8f6c\u6362\u540e\u7684\u7ed3\u679c\uff0c\u5426\u5219\u8fd4\u56de "ERROR" \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anum = "257"\n\u8f93\u51fa\uff1a"IOI"\n\u89e3\u91ca\uff1a257 \u7684\u5341\u516d\u8fdb\u5236\u8868\u793a\u662f 101 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anum = "3"\n\u8f93\u51fa\uff1a"ERROR"\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= N <= 10^12
    • \n\t
    • \u7ed9\u5b9a\u5b57\u7b26\u4e32\u4e0d\u4f1a\u6709\u524d\u5bfc 0 \u3002
    • \n\t
    • \u7ed3\u679c\u4e2d\u7684\u6240\u6709\u5b57\u6bcd\u90fd\u5e94\u8be5\u662f\u5927\u5199\u5b57\u6bcd\u3002
    • \n
    \n", "tags_en": ["Math", "String"], "tags_cn": ["\u6570\u5b66", "\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string toHexspeak(string num) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String toHexspeak(String num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def toHexspeak(self, num):\n \"\"\"\n :type num: str\n :rtype: str\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def toHexspeak(self, num: str) -> str:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * toHexspeak(char * num){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ToHexspeak(string num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} num\n * @return {string}\n */\nvar toHexspeak = function(num) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} num\n# @return {String}\ndef to_hexspeak(num)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func toHexspeak(_ num: String) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func toHexspeak(num string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def toHexspeak(num: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun toHexspeak(num: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn to_hexspeak(num: String) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $num\n * @return String\n */\n function toHexspeak($num) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function toHexspeak(num: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (to-hexspeak num)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1271](https://leetcode-cn.com/problems/hexspeak)", "[\u5341\u516d\u8fdb\u5236\u9b54\u672f\u6570\u5b57](/solution/1200-1299/1271.Hexspeak/README.md)", "`\u6570\u5b66`,`\u5b57\u7b26\u4e32`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1271](https://leetcode.com/problems/hexspeak)", "[Hexspeak](/solution/1200-1299/1271.Hexspeak/README_EN.md)", "`Math`,`String`", "Easy", "\ud83d\udd12"]}, {"question_id": "1198", "frontend_question_id": "1098", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/unpopular-books", "url_en": "https://leetcode.com/problems/unpopular-books", "relative_path_cn": "/solution/1000-1099/1098.Unpopular%20Books/README.md", "relative_path_en": "/solution/1000-1099/1098.Unpopular%20Books/README_EN.md", "title_cn": "\u5c0f\u4f17\u4e66\u7c4d", "title_en": "Unpopular Books", "question_title_slug": "unpopular-books", "content_en": "

    Table: Books

    \n\n
    \n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| book_id        | int     |\n| name           | varchar |\n| available_from | date    |\n+----------------+---------+\nbook_id is the primary key of this table.\n
    \n\n

    Table: Orders

    \n\n
    \n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| order_id       | int     |\n| book_id        | int     |\n| quantity       | int     |\n| dispatch_date  | date    |\n+----------------+---------+\norder_id is the primary key of this table.\nbook_id is a foreign key to the Books table.\n
    \n\n

     

    \n\n

    Write an SQL query that reports the books that have sold less than 10 copies in the last year, excluding books that have been available for less than 1 month from today. Assume today is 2019-06-23.

    \n\n

    The query result format is in the following example:

    \n\n
    \nBooks table:\n+---------+--------------------+----------------+\n| book_id | name               | available_from |\n+---------+--------------------+----------------+\n| 1       | "Kalila And Demna" | 2010-01-01     |\n| 2       | "28 Letters"       | 2012-05-12     |\n| 3       | "The Hobbit"       | 2019-06-10     |\n| 4       | "13 Reasons Why"   | 2019-06-01     |\n| 5       | "The Hunger Games" | 2008-09-21     |\n+---------+--------------------+----------------+\n\nOrders table:\n+----------+---------+----------+---------------+\n| order_id | book_id | quantity | dispatch_date |\n+----------+---------+----------+---------------+\n| 1        | 1       | 2        | 2018-07-26    |\n| 2        | 1       | 1        | 2018-11-05    |\n| 3        | 3       | 8        | 2019-06-11    |\n| 4        | 4       | 6        | 2019-06-05    |\n| 5        | 4       | 5        | 2019-06-20    |\n| 6        | 5       | 9        | 2009-02-02    |\n| 7        | 5       | 8        | 2010-04-13    |\n+----------+---------+----------+---------------+\n\nResult table:\n+-----------+--------------------+\n| book_id   | name               |\n+-----------+--------------------+\n| 1         | "Kalila And Demna" |\n| 2         | "28 Letters"       |\n| 5         | "The Hunger Games" |\n+-----------+--------------------+\n
    \n", "content_cn": "

    \u4e66\u7c4d\u8868 Books\uff1a

    \n\n
    +----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| book_id        | int     |\n| name           | varchar |\n| available_from | date    |\n+----------------+---------+\nbook_id \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\u3002\n
    \n\n

    \u8ba2\u5355\u8868 Orders\uff1a

    \n\n
    +----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| order_id       | int     |\n| book_id        | int     |\n| quantity       | int     |\n| dispatch_date  | date    |\n+----------------+---------+\norder_id \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\u3002\nbook_id  \u662f Books \u8868\u7684\u5916\u952e\u3002\n
    \n\n

     

    \n\n

    \u4f60\u9700\u8981\u5199\u4e00\u6bb5 SQL \u547d\u4ee4\uff0c\u7b5b\u9009\u51fa\u8fc7\u53bb\u4e00\u5e74\u4e2d\u8ba2\u5355\u603b\u91cf \u5c11\u4e8e10\u672c \u7684 \u4e66\u7c4d \u3002

    \n\n

    \u6ce8\u610f\uff1a\u4e0d\u8003\u8651 \u4e0a\u67b6\uff08available from\uff09\u8ddd\u4eca \u4e0d\u6ee1\u4e00\u4e2a\u6708 \u7684\u4e66\u7c4d\u3002\u5e76\u4e14 \u5047\u8bbe\u4eca\u5929\u662f 2019-06-23 \u3002

    \n\n

     

    \n\n

    \u4e0b\u9762\u662f\u6837\u4f8b\u8f93\u51fa\u7ed3\u679c\uff1a

    \n\n
    Books \u8868\uff1a\n+---------+--------------------+----------------+\n| book_id | name               | available_from |\n+---------+--------------------+----------------+\n| 1       | "Kalila And Demna" | 2010-01-01     |\n| 2       | "28 Letters"       | 2012-05-12     |\n| 3       | "The Hobbit"       | 2019-06-10     |\n| 4       | "13 Reasons Why"   | 2019-06-01     |\n| 5       | "The Hunger Games" | 2008-09-21     |\n+---------+--------------------+----------------+\n\nOrders \u8868\uff1a\n+----------+---------+----------+---------------+\n| order_id | book_id | quantity | dispatch_date |\n+----------+---------+----------+---------------+\n| 1        | 1       | 2        | 2018-07-26    |\n| 2        | 1       | 1        | 2018-11-05    |\n| 3        | 3       | 8        | 2019-06-11    |\n| 4        | 4       | 6        | 2019-06-05    |\n| 5        | 4       | 5        | 2019-06-20    |\n| 6        | 5       | 9        | 2009-02-02    |\n| 7        | 5       | 8        | 2010-04-13    |\n+----------+---------+----------+---------------+\n\nResult \u8868\uff1a\n+-----------+--------------------+\n| book_id   | name               |\n+-----------+--------------------+\n| 1         | "Kalila And Demna" |\n| 2         | "28 Letters"       |\n| 5         | "The Hunger Games" |\n+-----------+--------------------+\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1098](https://leetcode-cn.com/problems/unpopular-books)", "[\u5c0f\u4f17\u4e66\u7c4d](/solution/1000-1099/1098.Unpopular%20Books/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1098](https://leetcode.com/problems/unpopular-books)", "[Unpopular Books](/solution/1000-1099/1098.Unpopular%20Books/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1197", "frontend_question_id": "1106", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/parsing-a-boolean-expression", "url_en": "https://leetcode.com/problems/parsing-a-boolean-expression", "relative_path_cn": "/solution/1100-1199/1106.Parsing%20A%20Boolean%20Expression/README.md", "relative_path_en": "/solution/1100-1199/1106.Parsing%20A%20Boolean%20Expression/README_EN.md", "title_cn": "\u89e3\u6790\u5e03\u5c14\u8868\u8fbe\u5f0f", "title_en": "Parsing A Boolean Expression", "question_title_slug": "parsing-a-boolean-expression", "content_en": "

    Return the result of evaluating a given boolean expression, represented as a string.

    \n\n

    An expression can either be:

    \n\n
      \n\t
    • "t", evaluating to True;
    • \n\t
    • "f", evaluating to False;
    • \n\t
    • "!(expr)", evaluating to the logical NOT of the inner expression expr;
    • \n\t
    • "&(expr1,expr2,...)", evaluating to the logical AND of 2 or more inner expressions expr1, expr2, ...;
    • \n\t
    • "|(expr1,expr2,...)", evaluating to the logical OR of 2 or more inner expressions expr1, expr2, ...
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: expression = "!(f)"\nOutput: true\n
    \n\n

    Example 2:

    \n\n
    \nInput: expression = "|(f,t)"\nOutput: true\n
    \n\n

    Example 3:

    \n\n
    \nInput: expression = "&(t,f)"\nOutput: false\n
    \n\n

    Example 4:

    \n\n
    \nInput: expression = "|(&(t,f,t),!(t))"\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= expression.length <= 20000
    • \n\t
    • expression[i] consists of characters in {'(', ')', '&', '|', '!', 't', 'f', ','}.
    • \n\t
    • expression is a valid expression representing a boolean, as given in the description.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u4ee5\u5b57\u7b26\u4e32\u5f62\u5f0f\u8868\u8ff0\u7684 \u5e03\u5c14\u8868\u8fbe\u5f0f\uff08boolean\uff09 expression\uff0c\u8fd4\u56de\u8be5\u5f0f\u7684\u8fd0\u7b97\u7ed3\u679c\u3002

    \n\n

    \u6709\u6548\u7684\u8868\u8fbe\u5f0f\u9700\u9075\u5faa\u4ee5\u4e0b\u7ea6\u5b9a\uff1a

    \n\n
      \n\t
    • "t"\uff0c\u8fd0\u7b97\u7ed3\u679c\u4e3a True
    • \n\t
    • "f"\uff0c\u8fd0\u7b97\u7ed3\u679c\u4e3a False
    • \n\t
    • "!(expr)"\uff0c\u8fd0\u7b97\u8fc7\u7a0b\u4e3a\u5bf9\u5185\u90e8\u8868\u8fbe\u5f0f expr \u8fdb\u884c\u903b\u8f91 \u975e\u7684\u8fd0\u7b97\uff08NOT\uff09
    • \n\t
    • "&(expr1,expr2,...)"\uff0c\u8fd0\u7b97\u8fc7\u7a0b\u4e3a\u5bf9 2 \u4e2a\u6216\u4ee5\u4e0a\u5185\u90e8\u8868\u8fbe\u5f0f expr1, expr2, ... \u8fdb\u884c\u903b\u8f91 \u4e0e\u7684\u8fd0\u7b97\uff08AND\uff09
    • \n\t
    • "|(expr1,expr2,...)"\uff0c\u8fd0\u7b97\u8fc7\u7a0b\u4e3a\u5bf9 2 \u4e2a\u6216\u4ee5\u4e0a\u5185\u90e8\u8868\u8fbe\u5f0f expr1, expr2, ... \u8fdb\u884c\u903b\u8f91 \u6216\u7684\u8fd0\u7b97\uff08OR\uff09
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aexpression = "!(f)"\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aexpression = "|(f,t)"\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aexpression = "&(t,f)"\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1aexpression = "|(&(t,f,t),!(t))"\n\u8f93\u51fa\uff1afalse\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= expression.length <= 20000
    • \n\t
    • expression[i] \u7531 {'(', ')', '&', '|', '!', 't', 'f', ','} \u4e2d\u7684\u5b57\u7b26\u7ec4\u6210\u3002
    • \n\t
    • expression \u662f\u4ee5\u4e0a\u8ff0\u5f62\u5f0f\u7ed9\u51fa\u7684\u6709\u6548\u8868\u8fbe\u5f0f\uff0c\u8868\u793a\u4e00\u4e2a\u5e03\u5c14\u503c\u3002
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool parseBoolExpr(string expression) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean parseBoolExpr(String expression) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def parseBoolExpr(self, expression):\n \"\"\"\n :type expression: str\n :rtype: bool\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def parseBoolExpr(self, expression: str) -> bool:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool parseBoolExpr(char * expression){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool ParseBoolExpr(string expression) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} expression\n * @return {boolean}\n */\nvar parseBoolExpr = function(expression) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} expression\n# @return {Boolean}\ndef parse_bool_expr(expression)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func parseBoolExpr(_ expression: String) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func parseBoolExpr(expression string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def parseBoolExpr(expression: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun parseBoolExpr(expression: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn parse_bool_expr(expression: String) -> bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $expression\n * @return Boolean\n */\n function parseBoolExpr($expression) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function parseBoolExpr(expression: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (parse-bool-expr expression)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1106](https://leetcode-cn.com/problems/parsing-a-boolean-expression)", "[\u89e3\u6790\u5e03\u5c14\u8868\u8fbe\u5f0f](/solution/1100-1199/1106.Parsing%20A%20Boolean%20Expression/README.md)", "`\u5b57\u7b26\u4e32`", "\u56f0\u96be", ""], "md_table_row_en": ["[1106](https://leetcode.com/problems/parsing-a-boolean-expression)", "[Parsing A Boolean Expression](/solution/1100-1199/1106.Parsing%20A%20Boolean%20Expression/README_EN.md)", "`String`", "Hard", ""]}, {"question_id": "1196", "frontend_question_id": "1105", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/filling-bookcase-shelves", "url_en": "https://leetcode.com/problems/filling-bookcase-shelves", "relative_path_cn": "/solution/1100-1199/1105.Filling%20Bookcase%20Shelves/README.md", "relative_path_en": "/solution/1100-1199/1105.Filling%20Bookcase%20Shelves/README_EN.md", "title_cn": "\u586b\u5145\u4e66\u67b6", "title_en": "Filling Bookcase Shelves", "question_title_slug": "filling-bookcase-shelves", "content_en": "

    We have a sequence of books: the i-th book has thickness books[i][0] and height books[i][1].

    \n\n

    We want to place these books in order onto bookcase shelves that have total width shelf_width.

    \n\n

    We choose some of the books to place on this shelf (such that the sum of their thickness is <= shelf_width), then build another level of shelf of the bookcase so that the total height of the bookcase has increased by the maximum height of the books we just put down.  We repeat this process until there are no more books to place.

    \n\n

    Note again that at each step of the above process, the order of the books we place is the same order as the given sequence of books.  For example, if we have an ordered list of 5 books, we might place the first and second book onto the first shelf, the third book on the second shelf, and the fourth and fifth book on the last shelf.

    \n\n

    Return the minimum possible height that the total bookshelf can be after placing shelves in this manner.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: books = [[1,1],[2,3],[2,3],[1,1],[1,1],[1,1],[1,2]], shelf_width = 4\nOutput: 6\nExplanation:\nThe sum of the heights of the 3 shelves are 1 + 3 + 2 = 6.\nNotice that book number 2 does not have to be on the first shelf.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= books.length <= 1000
    • \n\t
    • 1 <= books[i][0] <= shelf_width <= 1000
    • \n\t
    • 1 <= books[i][1] <= 1000
    • \n
    \n", "content_cn": "

    \u9644\u8fd1\u7684\u5bb6\u5c45\u57ce\u4fc3\u9500\uff0c\u4f60\u4e70\u56de\u4e86\u4e00\u76f4\u5fc3\u4eea\u7684\u53ef\u8c03\u8282\u4e66\u67b6\uff0c\u6253\u7b97\u628a\u81ea\u5df1\u7684\u4e66\u90fd\u6574\u7406\u5230\u65b0\u7684\u4e66\u67b6\u4e0a\u3002

    \n\n

    \u4f60\u628a\u8981\u6446\u653e\u7684\u4e66 books \u90fd\u6574\u7406\u597d\uff0c\u53e0\u6210\u4e00\u645e\uff1a\u4ece\u4e0a\u5f80\u4e0b\uff0c\u7b2c i \u672c\u4e66\u7684\u539a\u5ea6\u4e3a books[i][0]\uff0c\u9ad8\u5ea6\u4e3a books[i][1]\u3002

    \n\n

    \u6309\u987a\u5e8f \u5c06\u8fd9\u4e9b\u4e66\u6446\u653e\u5230\u603b\u5bbd\u5ea6\u4e3a shelf_width \u7684\u4e66\u67b6\u4e0a\u3002

    \n\n

    \u5148\u9009\u51e0\u672c\u4e66\u653e\u5728\u4e66\u67b6\u4e0a\uff08\u5b83\u4eec\u7684\u539a\u5ea6\u4e4b\u548c\u5c0f\u4e8e\u7b49\u4e8e\u4e66\u67b6\u7684\u5bbd\u5ea6 shelf_width\uff09\uff0c\u7136\u540e\u518d\u5efa\u4e00\u5c42\u4e66\u67b6\u3002\u91cd\u590d\u8fd9\u4e2a\u8fc7\u7a0b\uff0c\u76f4\u5230\u628a\u6240\u6709\u7684\u4e66\u90fd\u653e\u5728\u4e66\u67b6\u4e0a\u3002

    \n\n

    \u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5728\u4e0a\u8ff0\u8fc7\u7a0b\u7684\u6bcf\u4e2a\u6b65\u9aa4\u4e2d\uff0c\u6446\u653e\u4e66\u7684\u987a\u5e8f\u4e0e\u4f60\u6574\u7406\u597d\u7684\u987a\u5e8f\u76f8\u540c\u3002 \u4f8b\u5982\uff0c\u5982\u679c\u8fd9\u91cc\u6709 5 \u672c\u4e66\uff0c\u90a3\u4e48\u53ef\u80fd\u7684\u4e00\u79cd\u6446\u653e\u60c5\u51b5\u662f\uff1a\u7b2c\u4e00\u548c\u7b2c\u4e8c\u672c\u4e66\u653e\u5728\u7b2c\u4e00\u5c42\u4e66\u67b6\u4e0a\uff0c\u7b2c\u4e09\u672c\u4e66\u653e\u5728\u7b2c\u4e8c\u5c42\u4e66\u67b6\u4e0a\uff0c\u7b2c\u56db\u548c\u7b2c\u4e94\u672c\u4e66\u653e\u5728\u6700\u540e\u4e00\u5c42\u4e66\u67b6\u4e0a\u3002

    \n\n

    \u6bcf\u4e00\u5c42\u6240\u6446\u653e\u7684\u4e66\u7684\u6700\u5927\u9ad8\u5ea6\u5c31\u662f\u8fd9\u4e00\u5c42\u4e66\u67b6\u7684\u5c42\u9ad8\uff0c\u4e66\u67b6\u6574\u4f53\u7684\u9ad8\u5ea6\u4e3a\u5404\u5c42\u9ad8\u4e4b\u548c\u3002

    \n\n

    \u4ee5\u8fd9\u79cd\u65b9\u5f0f\u5e03\u7f6e\u4e66\u67b6\uff0c\u8fd4\u56de\u4e66\u67b6\u6574\u4f53\u53ef\u80fd\u7684\u6700\u5c0f\u9ad8\u5ea6\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1abooks = [[1,1],[2,3],[2,3],[1,1],[1,1],[1,1],[1,2]], shelf_width = 4\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\n3 \u5c42\u4e66\u67b6\u7684\u9ad8\u5ea6\u548c\u4e3a 1 + 3 + 2 = 6 \u3002\n\u7b2c 2 \u672c\u4e66\u4e0d\u5fc5\u653e\u5728\u7b2c\u4e00\u5c42\u4e66\u67b6\u4e0a\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= books.length <= 1000
    • \n\t
    • 1 <= books[i][0] <= shelf_width <= 1000
    • \n\t
    • 1 <= books[i][1] <= 1000
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minHeightShelves(vector>& books, int shelf_width) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minHeightShelves(int[][] books, int shelf_width) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minHeightShelves(self, books, shelf_width):\n \"\"\"\n :type books: List[List[int]]\n :type shelf_width: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minHeightShelves(self, books: List[List[int]], shelf_width: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minHeightShelves(int** books, int booksSize, int* booksColSize, int shelf_width){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinHeightShelves(int[][] books, int shelf_width) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} books\n * @param {number} shelf_width\n * @return {number}\n */\nvar minHeightShelves = function(books, shelf_width) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} books\n# @param {Integer} shelf_width\n# @return {Integer}\ndef min_height_shelves(books, shelf_width)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minHeightShelves(_ books: [[Int]], _ shelf_width: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minHeightShelves(books [][]int, shelf_width int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minHeightShelves(books: Array[Array[Int]], shelf_width: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minHeightShelves(books: Array, shelf_width: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_height_shelves(books: Vec>, shelf_width: i32) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $books\n * @param Integer $shelf_width\n * @return Integer\n */\n function minHeightShelves($books, $shelf_width) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minHeightShelves(books: number[][], shelf_width: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-height-shelves books shelf_width)\n (-> (listof (listof exact-integer?)) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1105](https://leetcode-cn.com/problems/filling-bookcase-shelves)", "[\u586b\u5145\u4e66\u67b6](/solution/1100-1199/1105.Filling%20Bookcase%20Shelves/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1105](https://leetcode.com/problems/filling-bookcase-shelves)", "[Filling Bookcase Shelves](/solution/1100-1199/1105.Filling%20Bookcase%20Shelves/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "1195", "frontend_question_id": "1103", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/distribute-candies-to-people", "url_en": "https://leetcode.com/problems/distribute-candies-to-people", "relative_path_cn": "/solution/1100-1199/1103.Distribute%20Candies%20to%20People/README.md", "relative_path_en": "/solution/1100-1199/1103.Distribute%20Candies%20to%20People/README_EN.md", "title_cn": "\u5206\u7cd6\u679c II", "title_en": "Distribute Candies to People", "question_title_slug": "distribute-candies-to-people", "content_en": "

    We distribute some number of candies, to a row of n = num_people people in the following way:

    \n\n

    We then give 1 candy to the first person, 2 candies to the second person, and so on until we give n candies to the last person.

    \n\n

    Then, we go back to the start of the row, giving n + 1 candies to the first person, n + 2 candies to the second person, and so on until we give 2 * n candies to the last person.

    \n\n

    This process repeats (with us giving one more candy each time, and moving to the start of the row after we reach the end) until we run out of candies.  The last person will receive all of our remaining candies (not necessarily one more than the previous gift).

    \n\n

    Return an array (of length num_people and sum candies) that represents the final distribution of candies.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: candies = 7, num_people = 4\nOutput: [1,2,3,1]\nExplanation:\nOn the first turn, ans[0] += 1, and the array is [1,0,0,0].\nOn the second turn, ans[1] += 2, and the array is [1,2,0,0].\nOn the third turn, ans[2] += 3, and the array is [1,2,3,0].\nOn the fourth turn, ans[3] += 1 (because there is only one candy left), and the final array is [1,2,3,1].\n
    \n\n

    Example 2:

    \n\n
    \nInput: candies = 10, num_people = 3\nOutput: [5,2,3]\nExplanation: \nOn the first turn, ans[0] += 1, and the array is [1,0,0].\nOn the second turn, ans[1] += 2, and the array is [1,2,0].\nOn the third turn, ans[2] += 3, and the array is [1,2,3].\nOn the fourth turn, ans[0] += 4, and the final array is [5,2,3].\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= candies <= 10^9
    • \n\t
    • 1 <= num_people <= 1000
    • \n
    \n", "content_cn": "

    \u6392\u6392\u5750\uff0c\u5206\u7cd6\u679c\u3002

    \n\n

    \u6211\u4eec\u4e70\u4e86\u4e00\u4e9b\u7cd6\u679c candies\uff0c\u6253\u7b97\u628a\u5b83\u4eec\u5206\u7ed9\u6392\u597d\u961f\u7684 n = num_people \u4e2a\u5c0f\u670b\u53cb\u3002

    \n\n

    \u7ed9\u7b2c\u4e00\u4e2a\u5c0f\u670b\u53cb 1 \u9897\u7cd6\u679c\uff0c\u7b2c\u4e8c\u4e2a\u5c0f\u670b\u53cb 2 \u9897\uff0c\u4f9d\u6b64\u7c7b\u63a8\uff0c\u76f4\u5230\u7ed9\u6700\u540e\u4e00\u4e2a\u5c0f\u670b\u53cb n \u9897\u7cd6\u679c\u3002

    \n\n

    \u7136\u540e\uff0c\u6211\u4eec\u518d\u56de\u5230\u961f\u4f0d\u7684\u8d77\u70b9\uff0c\u7ed9\u7b2c\u4e00\u4e2a\u5c0f\u670b\u53cb n + 1 \u9897\u7cd6\u679c\uff0c\u7b2c\u4e8c\u4e2a\u5c0f\u670b\u53cb n + 2 \u9897\uff0c\u4f9d\u6b64\u7c7b\u63a8\uff0c\u76f4\u5230\u7ed9\u6700\u540e\u4e00\u4e2a\u5c0f\u670b\u53cb 2 * n \u9897\u7cd6\u679c\u3002

    \n\n

    \u91cd\u590d\u4e0a\u8ff0\u8fc7\u7a0b\uff08\u6bcf\u6b21\u90fd\u6bd4\u4e0a\u4e00\u6b21\u591a\u7ed9\u51fa\u4e00\u9897\u7cd6\u679c\uff0c\u5f53\u5230\u8fbe\u961f\u4f0d\u7ec8\u70b9\u540e\u518d\u6b21\u4ece\u961f\u4f0d\u8d77\u70b9\u5f00\u59cb\uff09\uff0c\u76f4\u5230\u6211\u4eec\u5206\u5b8c\u6240\u6709\u7684\u7cd6\u679c\u3002\u6ce8\u610f\uff0c\u5c31\u7b97\u6211\u4eec\u624b\u4e2d\u7684\u5269\u4e0b\u7cd6\u679c\u6570\u4e0d\u591f\uff08\u4e0d\u6bd4\u524d\u4e00\u6b21\u53d1\u51fa\u7684\u7cd6\u679c\u591a\uff09\uff0c\u8fd9\u4e9b\u7cd6\u679c\u4e5f\u4f1a\u5168\u90e8\u53d1\u7ed9\u5f53\u524d\u7684\u5c0f\u670b\u53cb\u3002

    \n\n

    \u8fd4\u56de\u4e00\u4e2a\u957f\u5ea6\u4e3a num_people\u3001\u5143\u7d20\u4e4b\u548c\u4e3a candies \u7684\u6570\u7ec4\uff0c\u4ee5\u8868\u793a\u7cd6\u679c\u7684\u6700\u7ec8\u5206\u53d1\u60c5\u51b5\uff08\u5373 ans[i] \u8868\u793a\u7b2c i \u4e2a\u5c0f\u670b\u53cb\u5206\u5230\u7684\u7cd6\u679c\u6570\uff09\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1acandies = 7, num_people = 4\n\u8f93\u51fa\uff1a[1,2,3,1]\n\u89e3\u91ca\uff1a\n\u7b2c\u4e00\u6b21\uff0cans[0] += 1\uff0c\u6570\u7ec4\u53d8\u4e3a [1,0,0,0]\u3002\n\u7b2c\u4e8c\u6b21\uff0cans[1] += 2\uff0c\u6570\u7ec4\u53d8\u4e3a [1,2,0,0]\u3002\n\u7b2c\u4e09\u6b21\uff0cans[2] += 3\uff0c\u6570\u7ec4\u53d8\u4e3a [1,2,3,0]\u3002\n\u7b2c\u56db\u6b21\uff0cans[3] += 1\uff08\u56e0\u4e3a\u6b64\u65f6\u53ea\u5269\u4e0b 1 \u9897\u7cd6\u679c\uff09\uff0c\u6700\u7ec8\u6570\u7ec4\u53d8\u4e3a [1,2,3,1]\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1acandies = 10, num_people = 3\n\u8f93\u51fa\uff1a[5,2,3]\n\u89e3\u91ca\uff1a\n\u7b2c\u4e00\u6b21\uff0cans[0] += 1\uff0c\u6570\u7ec4\u53d8\u4e3a [1,0,0]\u3002\n\u7b2c\u4e8c\u6b21\uff0cans[1] += 2\uff0c\u6570\u7ec4\u53d8\u4e3a [1,2,0]\u3002\n\u7b2c\u4e09\u6b21\uff0cans[2] += 3\uff0c\u6570\u7ec4\u53d8\u4e3a [1,2,3]\u3002\n\u7b2c\u56db\u6b21\uff0cans[0] += 4\uff0c\u6700\u7ec8\u6570\u7ec4\u53d8\u4e3a [5,2,3]\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= candies <= 10^9
    • \n\t
    • 1 <= num_people <= 1000
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector distributeCandies(int candies, int num_people) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] distributeCandies(int candies, int num_people) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def distributeCandies(self, candies, num_people):\n \"\"\"\n :type candies: int\n :type num_people: int\n :rtype: List[int]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def distributeCandies(self, candies: int, num_people: int) -> List[int]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* distributeCandies(int candies, int num_people, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] DistributeCandies(int candies, int num_people) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} candies\n * @param {number} num_people\n * @return {number[]}\n */\nvar distributeCandies = function(candies, num_people) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} candies\n# @param {Integer} num_people\n# @return {Integer[]}\ndef distribute_candies(candies, num_people)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func distributeCandies(_ candies: Int, _ num_people: Int) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func distributeCandies(candies int, num_people int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def distributeCandies(candies: Int, num_people: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun distributeCandies(candies: Int, num_people: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn distribute_candies(candies: i32, num_people: i32) -> Vec {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $candies\n * @param Integer $num_people\n * @return Integer[]\n */\n function distributeCandies($candies, $num_people) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function distributeCandies(candies: number, num_people: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (distribute-candies candies num_people)\n (-> exact-integer? exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1103](https://leetcode-cn.com/problems/distribute-candies-to-people)", "[\u5206\u7cd6\u679c II](/solution/1100-1199/1103.Distribute%20Candies%20to%20People/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[1103](https://leetcode.com/problems/distribute-candies-to-people)", "[Distribute Candies to People](/solution/1100-1199/1103.Distribute%20Candies%20to%20People/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "1194", "frontend_question_id": "1104", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/path-in-zigzag-labelled-binary-tree", "url_en": "https://leetcode.com/problems/path-in-zigzag-labelled-binary-tree", "relative_path_cn": "/solution/1100-1199/1104.Path%20In%20Zigzag%20Labelled%20Binary%20Tree/README.md", "relative_path_en": "/solution/1100-1199/1104.Path%20In%20Zigzag%20Labelled%20Binary%20Tree/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u5bfb\u8def", "title_en": "Path In Zigzag Labelled Binary Tree", "question_title_slug": "path-in-zigzag-labelled-binary-tree", "content_en": "

    In an infinite binary tree where every node has two children, the nodes are labelled in row order.

    \n\n

    In the odd numbered rows (ie., the first, third, fifth,...), the labelling is left to right, while in the even numbered rows (second, fourth, sixth,...), the labelling is right to left.

    \n\n

    \"\"

    \n\n

    Given the label of a node in this tree, return the labels in the path from the root of the tree to the node with that label.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: label = 14\nOutput: [1,3,4,14]\n
    \n\n

    Example 2:

    \n\n
    \nInput: label = 26\nOutput: [1,2,6,10,26]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= label <= 10^6
    • \n
    \n", "content_cn": "

    \u5728\u4e00\u68f5\u65e0\u9650\u7684\u4e8c\u53c9\u6811\u4e0a\uff0c\u6bcf\u4e2a\u8282\u70b9\u90fd\u6709\u4e24\u4e2a\u5b50\u8282\u70b9\uff0c\u6811\u4e2d\u7684\u8282\u70b9 \u9010\u884c \u4f9d\u6b21\u6309 “\u4e4b” \u5b57\u5f62\u8fdb\u884c\u6807\u8bb0\u3002

    \n\n

    \u5982\u4e0b\u56fe\u6240\u793a\uff0c\u5728\u5947\u6570\u884c\uff08\u5373\uff0c\u7b2c\u4e00\u884c\u3001\u7b2c\u4e09\u884c\u3001\u7b2c\u4e94\u884c……\uff09\u4e2d\uff0c\u6309\u4ece\u5de6\u5230\u53f3\u7684\u987a\u5e8f\u8fdb\u884c\u6807\u8bb0\uff1b

    \n\n

    \u800c\u5076\u6570\u884c\uff08\u5373\uff0c\u7b2c\u4e8c\u884c\u3001\u7b2c\u56db\u884c\u3001\u7b2c\u516d\u884c……\uff09\u4e2d\uff0c\u6309\u4ece\u53f3\u5230\u5de6\u7684\u987a\u5e8f\u8fdb\u884c\u6807\u8bb0\u3002

    \n\n

    \"\"

    \n\n

    \u7ed9\u4f60\u6811\u4e0a\u67d0\u4e00\u4e2a\u8282\u70b9\u7684\u6807\u53f7 label\uff0c\u8bf7\u4f60\u8fd4\u56de\u4ece\u6839\u8282\u70b9\u5230\u8be5\u6807\u53f7\u4e3a label \u8282\u70b9\u7684\u8def\u5f84\uff0c\u8be5\u8def\u5f84\u662f\u7531\u9014\u7ecf\u7684\u8282\u70b9\u6807\u53f7\u6240\u7ec4\u6210\u7684\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1alabel = 14\n\u8f93\u51fa\uff1a[1,3,4,14]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1alabel = 26\n\u8f93\u51fa\uff1a[1,2,6,10,26]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= label <= 10^6
    • \n
    \n", "tags_en": ["Tree", "Math"], "tags_cn": ["\u6811", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector pathInZigZagTree(int label) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List pathInZigZagTree(int label) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def pathInZigZagTree(self, label):\n \"\"\"\n :type label: int\n :rtype: List[int]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def pathInZigZagTree(self, label: int) -> List[int]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* pathInZigZagTree(int label, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList PathInZigZagTree(int label) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} label\n * @return {number[]}\n */\nvar pathInZigZagTree = function(label) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} label\n# @return {Integer[]}\ndef path_in_zig_zag_tree(label)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func pathInZigZagTree(_ label: Int) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func pathInZigZagTree(label int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def pathInZigZagTree(label: Int): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun pathInZigZagTree(label: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn path_in_zig_zag_tree(label: i32) -> Vec {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $label\n * @return Integer[]\n */\n function pathInZigZagTree($label) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function pathInZigZagTree(label: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (path-in-zig-zag-tree label)\n (-> exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1104](https://leetcode-cn.com/problems/path-in-zigzag-labelled-binary-tree)", "[\u4e8c\u53c9\u6811\u5bfb\u8def](/solution/1100-1199/1104.Path%20In%20Zigzag%20Labelled%20Binary%20Tree/README.md)", "`\u6811`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1104](https://leetcode.com/problems/path-in-zigzag-labelled-binary-tree)", "[Path In Zigzag Labelled Binary Tree](/solution/1100-1199/1104.Path%20In%20Zigzag%20Labelled%20Binary%20Tree/README_EN.md)", "`Tree`,`Math`", "Medium", ""]}, {"question_id": "1193", "frontend_question_id": "1097", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/game-play-analysis-v", "url_en": "https://leetcode.com/problems/game-play-analysis-v", "relative_path_cn": "/solution/1000-1099/1097.Game%20Play%20Analysis%20V/README.md", "relative_path_en": "/solution/1000-1099/1097.Game%20Play%20Analysis%20V/README_EN.md", "title_cn": "\u6e38\u620f\u73a9\u6cd5\u5206\u6790 V", "title_en": "Game Play Analysis V", "question_title_slug": "game-play-analysis-v", "content_en": "

    Table: Activity

    \n\n
    \n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| player_id    | int     |\n| device_id    | int     |\n| event_date   | date    |\n| games_played | int     |\n+--------------+---------+\n(player_id, event_date) is the primary key of this table.\nThis table shows the activity of players of some game.\nEach row is a record of a player who logged in and played a number of games (possibly 0) before logging out on some day using some device.\n
    \n\n

     

    \n\n

    We define the install date of a player to be the first login day of that player.

    \n\n

    We also define day 1 retention of some date X to be the number of players whose install date is X and they logged back in on the day right after X, divided by the number of players whose install date is X, rounded to 2 decimal places.

    \n\n

    Write an SQL query that reports for each install date, the number of players that installed the game on that day and the day 1 retention.

    \n\n

    The query result format is in the following example:

    \n\n
    \nActivity table:\n+-----------+-----------+------------+--------------+\n| player_id | device_id | event_date | games_played |\n+-----------+-----------+------------+--------------+\n| 1         | 2         | 2016-03-01 | 5            |\n| 1         | 2         | 2016-03-02 | 6            |\n| 2         | 3         | 2017-06-25 | 1            |\n| 3         | 1         | 2016-03-01 | 0            |\n| 3         | 4         | 2016-07-03 | 5            |\n+-----------+-----------+------------+--------------+\n\nResult table:\n+------------+----------+----------------+\n| install_dt | installs | Day1_retention |\n+------------+----------+----------------+\n| 2016-03-01 | 2        | 0.50           |\n| 2017-06-25 | 1        | 0.00           |\n+------------+----------+----------------+\nPlayer 1 and 3 installed the game on 2016-03-01 but only player 1 logged back in on 2016-03-02 so the day 1 retention of 2016-03-01 is 1 / 2 = 0.50\nPlayer 2 installed the game on 2017-06-25 but didn't log back in on 2017-06-26 so the day 1 retention of 2017-06-25 is 0 / 1 = 0.00\n
    \n", "content_cn": "

    Activity \u6d3b\u52a8\u8bb0\u5f55\u8868

    \n\n
    \n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| player_id    | int     |\n| device_id    | int     |\n| event_date   | date    |\n| games_played | int     |\n+--------------+---------+\n\uff08player_id\uff0cevent_date\uff09\u662f\u6b64\u8868\u7684\u4e3b\u952e\n\u8fd9\u5f20\u8868\u663e\u793a\u4e86\u67d0\u4e9b\u6e38\u620f\u7684\u73a9\u5bb6\u7684\u6d3b\u52a8\u60c5\u51b5\n\u6bcf\u4e00\u884c\u8868\u793a\u4e00\u4e2a\u73a9\u5bb6\u7684\u8bb0\u5f55\uff0c\u5728\u67d0\u4e00\u5929\u4f7f\u7528\u67d0\u4e2a\u8bbe\u5907\u6ce8\u9500\u4e4b\u524d\uff0c\u767b\u5f55\u5e76\u73a9\u4e86\u5f88\u591a\u6e38\u620f\uff08\u53ef\u80fd\u662f 0\uff09\n
    \n\n

    \u00a0

    \n\n

    \u73a9\u5bb6\u7684 \u5b89\u88c5\u65e5\u671f \u5b9a\u4e49\u4e3a\u8be5\u73a9\u5bb6\u7684\u7b2c\u4e00\u4e2a\u767b\u5f55\u65e5\u3002

    \n\n

    \u73a9\u5bb6\u7684 \u7b2c\u4e00\u5929\u7559\u5b58\u7387 \u5b9a\u4e49\u4e3a\uff1a\u5047\u5b9a\u5b89\u88c5\u65e5\u671f\u4e3a X\u00a0\u7684\u73a9\u5bb6\u7684\u6570\u91cf\u4e3a N \uff0c\u5176\u4e2d\u5728 X\u00a0\u4e4b\u540e\u7684\u4e00\u5929\u91cd\u65b0\u767b\u5f55\u7684\u73a9\u5bb6\u6570\u91cf\u4e3a M \uff0cM/N \u5c31\u662f\u7b2c\u4e00\u5929\u7559\u5b58\u7387\uff0c\u56db\u820d\u4e94\u5165\u5230\u5c0f\u6570\u70b9\u540e\u4e24\u4f4d\u3002

    \n\n

    \u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\uff0c\u62a5\u544a\u6240\u6709\u5b89\u88c5\u65e5\u671f\u3001\u5f53\u5929\u5b89\u88c5\u6e38\u620f\u7684\u73a9\u5bb6\u6570\u91cf\u548c\u73a9\u5bb6\u7684\u7b2c\u4e00\u5929\u7559\u5b58\u7387\u3002

    \n\n

    \u00a0

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u6240\u793a\uff1a

    \n\n
    \nActivity \u8868\uff1a\n+-----------+-----------+------------+--------------+\n| player_id | device_id | event_date | games_played |\n+-----------+-----------+------------+--------------+\n| 1         | 2         | 2016-03-01 | 5            |\n| 1         | 2         | 2016-03-02 | 6            |\n| 2         | 3         | 2017-06-25 | 1            |\n| 3         | 1         | 2016-03-01 | 0            |\n| 3         | 4         | 2016-07-03 | 5            |\n+-----------+-----------+------------+--------------+\n\nResult \u8868\uff1a\n+------------+----------+----------------+\n| install_dt | installs | Day1_retention |\n+------------+----------+----------------+\n| 2016-03-01 | 2        | 0.50           |\n| 2017-06-25 | 1        | 0.00           |\n+------------+----------+----------------+\n\u73a9\u5bb6 1 \u548c 3 \u5728 2016-03-01 \u5b89\u88c5\u4e86\u6e38\u620f\uff0c\u4f46\u53ea\u6709\u73a9\u5bb6 1 \u5728 2016-03-02 \u91cd\u65b0\u767b\u5f55\uff0c\u6240\u4ee5 2016-03-01 \u7684\u7b2c\u4e00\u5929\u7559\u5b58\u7387\u662f 1/2=0.50\n\u73a9\u5bb6 2 \u5728 2017-06-25 \u5b89\u88c5\u4e86\u6e38\u620f\uff0c\u4f46\u5728 2017-06-26 \u6ca1\u6709\u91cd\u65b0\u767b\u5f55\uff0c\u56e0\u6b64 2017-06-25 \u7684\u7b2c\u4e00\u5929\u7559\u5b58\u7387\u4e3a 0/1=0.00\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1097](https://leetcode-cn.com/problems/game-play-analysis-v)", "[\u6e38\u620f\u73a9\u6cd5\u5206\u6790 V](/solution/1000-1099/1097.Game%20Play%20Analysis%20V/README.md)", "", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1097](https://leetcode.com/problems/game-play-analysis-v)", "[Game Play Analysis V](/solution/1000-1099/1097.Game%20Play%20Analysis%20V/README_EN.md)", "", "Hard", "\ud83d\udd12"]}, {"question_id": "1192", "frontend_question_id": "1231", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/divide-chocolate", "url_en": "https://leetcode.com/problems/divide-chocolate", "relative_path_cn": "/solution/1200-1299/1231.Divide%20Chocolate/README.md", "relative_path_en": "/solution/1200-1299/1231.Divide%20Chocolate/README_EN.md", "title_cn": "\u5206\u4eab\u5de7\u514b\u529b", "title_en": "Divide Chocolate", "question_title_slug": "divide-chocolate", "content_en": "

    You have one chocolate bar that consists of some chunks. Each chunk has its own sweetness given by the array sweetness.

    \n\n

    You want to share the chocolate with your K friends so you start cutting the chocolate bar into K+1 pieces using K cuts, each piece consists of some consecutive chunks.

    \n\n

    Being generous, you will eat the piece with the minimum total sweetness and give the other pieces to your friends.

    \n\n

    Find the maximum total sweetness of the piece you can get by cutting the chocolate bar optimally.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: sweetness = [1,2,3,4,5,6,7,8,9], K = 5\nOutput: 6\nExplanation: You can divide the chocolate to [1,2,3], [4,5], [6], [7], [8], [9]\n
    \n\n

    Example 2:

    \n\n
    \nInput: sweetness = [5,6,7,8,9,1,2,3,4], K = 8\nOutput: 1\nExplanation: There is only one way to cut the bar into 9 pieces.\n
    \n\n

    Example 3:

    \n\n
    \nInput: sweetness = [1,2,2,1,2,2,1,2,2], K = 2\nOutput: 5\nExplanation: You can divide the chocolate to [1,2,2], [1,2,2], [1,2,2]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= K < sweetness.length <= 10^4
    • \n\t
    • 1 <= sweetness[i] <= 10^5
    • \n
    \n", "content_cn": "

    \u4f60\u6709\u4e00\u5927\u5757\u5de7\u514b\u529b\uff0c\u5b83\u7531\u4e00\u4e9b\u751c\u5ea6\u4e0d\u5b8c\u5168\u76f8\u540c\u7684\u5c0f\u5757\u7ec4\u6210\u3002\u6211\u4eec\u7528\u6570\u7ec4 sweetness \u6765\u8868\u793a\u6bcf\u4e00\u5c0f\u5757\u7684\u751c\u5ea6\u3002

    \n\n

    \u4f60\u6253\u7b97\u548c K \u540d\u670b\u53cb\u4e00\u8d77\u5206\u4eab\u8fd9\u5757\u5de7\u514b\u529b\uff0c\u6240\u4ee5\u4f60\u9700\u8981\u5c06\u5207\u5272 K \u6b21\u624d\u80fd\u5f97\u5230 K+1 \u5757\uff0c\u6bcf\u4e00\u5757\u90fd\u7531\u4e00\u4e9b \u8fde\u7eed \u7684\u5c0f\u5757\u7ec4\u6210\u3002

    \n\n

    \u4e3a\u4e86\u8868\u73b0\u51fa\u4f60\u7684\u6177\u6168\uff0c\u4f60\u5c06\u4f1a\u5403\u6389 \u603b\u751c\u5ea6\u6700\u5c0f \u7684\u4e00\u5757\uff0c\u5e76\u5c06\u5176\u4f59\u51e0\u5757\u5206\u7ed9\u4f60\u7684\u670b\u53cb\u4eec\u3002

    \n\n

    \u8bf7\u627e\u51fa\u4e00\u4e2a\u6700\u4f73\u7684\u5207\u5272\u7b56\u7565\uff0c\u4f7f\u5f97\u4f60\u6240\u5206\u5f97\u7684\u5de7\u514b\u529b \u603b\u751c\u5ea6\u6700\u5927\uff0c\u5e76\u8fd4\u56de\u8fd9\u4e2a \u6700\u5927\u603b\u751c\u5ea6\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1asweetness = [1,2,3,4,5,6,7,8,9], K = 5\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u628a\u5de7\u514b\u529b\u5206\u6210 [1,2,3], [4,5], [6], [7], [8], [9]\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1asweetness = [5,6,7,8,9,1,2,3,4], K = 8\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u53ea\u6709\u4e00\u79cd\u529e\u6cd5\u53ef\u4ee5\u628a\u5de7\u514b\u529b\u5206\u6210 9 \u5757\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1asweetness = [1,2,2,1,2,2,1,2,2], K = 2\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u628a\u5de7\u514b\u529b\u5206\u6210 [1,2,2], [1,2,2], [1,2,2]\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= K < sweetness.length <= 10^4
    • \n\t
    • 1 <= sweetness[i] <= 10^5
    • \n
    \n", "tags_en": ["Greedy", "Binary Search"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maximizeSweetness(vector& sweetness, int K) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maximizeSweetness(int[] sweetness, int K) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximizeSweetness(self, sweetness, K):\n \"\"\"\n :type sweetness: List[int]\n :type K: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximizeSweetness(self, sweetness: List[int], K: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maximizeSweetness(int* sweetness, int sweetnessSize, int K){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaximizeSweetness(int[] sweetness, int K) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} sweetness\n * @param {number} K\n * @return {number}\n */\nvar maximizeSweetness = function(sweetness, K) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} sweetness\n# @param {Integer} k\n# @return {Integer}\ndef maximize_sweetness(sweetness, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximizeSweetness(_ sweetness: [Int], _ K: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximizeSweetness(sweetness []int, K int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximizeSweetness(sweetness: Array[Int], K: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximizeSweetness(sweetness: IntArray, K: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximize_sweetness(sweetness: Vec, k: i32) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $sweetness\n * @param Integer $K\n * @return Integer\n */\n function maximizeSweetness($sweetness, $K) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximizeSweetness(sweetness: number[], K: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximize-sweetness sweetness K)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1231](https://leetcode-cn.com/problems/divide-chocolate)", "[\u5206\u4eab\u5de7\u514b\u529b](/solution/1200-1299/1231.Divide%20Chocolate/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u4e8c\u5206\u67e5\u627e`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1231](https://leetcode.com/problems/divide-chocolate)", "[Divide Chocolate](/solution/1200-1299/1231.Divide%20Chocolate/README_EN.md)", "`Greedy`,`Binary Search`", "Hard", "\ud83d\udd12"]}, {"question_id": "1191", "frontend_question_id": "1258", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/synonymous-sentences", "url_en": "https://leetcode.com/problems/synonymous-sentences", "relative_path_cn": "/solution/1200-1299/1258.Synonymous%20Sentences/README.md", "relative_path_en": "/solution/1200-1299/1258.Synonymous%20Sentences/README_EN.md", "title_cn": "\u8fd1\u4e49\u8bcd\u53e5\u5b50", "title_en": "Synonymous Sentences", "question_title_slug": "synonymous-sentences", "content_en": "Given a list of pairs of equivalent words synonyms and a sentence text, Return all possible synonymous sentences sorted lexicographically.\n

     

    \n

    Example 1:

    \n\n
    \nInput:\nsynonyms = [["happy","joy"],["sad","sorrow"],["joy","cheerful"]],\ntext = "I am happy today but was sad yesterday"\nOutput:\n["I am cheerful today but was sad yesterday",\n"I am cheerful today but was sorrow yesterday",\n"I am happy today but was sad yesterday",\n"I am happy today but was sorrow yesterday",\n"I am joy today but was sad yesterday",\n"I am joy today but was sorrow yesterday"]\n
    \n\n

    Example 2:

    \n\n
    \nInput: synonyms = [["happy","joy"],["cheerful","glad"]], text = "I am happy today but was sad yesterday"\nOutput: ["I am happy today but was sad yesterday","I am joy today but was sad yesterday"]\n
    \n\n

    Example 3:

    \n\n
    \nInput: synonyms = [["a","b"],["c","d"],["e","f"]], text = "a c e"\nOutput: ["a c e","a c f","a d e","a d f","b c e","b c f","b d e","b d f"]\n
    \n\n

    Example 4:

    \n\n
    \nInput: synonyms = [["a","QrbCl"]], text = "d QrbCl ya ya NjZQ"\nOutput: ["d QrbCl ya ya NjZQ","d a ya ya NjZQ"]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= synonyms.length <= 10
    • \n\t
    • synonyms[i].length == 2
    • \n\t
    • synonyms[i][0] != synonyms[i][1]
    • \n\t
    • All words consist of at most 10 English letters only.
    • \n\t
    • text is a single space separated sentence of at most 10 words.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u8fd1\u4e49\u8bcd\u8868 synonyms \u548c\u4e00\u4e2a\u53e5\u5b50 text \uff0c synonyms \u8868\u4e2d\u662f\u4e00\u4e9b\u8fd1\u4e49\u8bcd\u5bf9 \uff0c\u4f60\u53ef\u4ee5\u5c06\u53e5\u5b50 text \u4e2d\u6bcf\u4e2a\u5355\u8bcd\u7528\u5b83\u7684\u8fd1\u4e49\u8bcd\u6765\u66ff\u6362\u3002

    \n\n

    \u8bf7\u4f60\u627e\u51fa\u6240\u6709\u7528\u8fd1\u4e49\u8bcd\u66ff\u6362\u540e\u7684\u53e5\u5b50\uff0c\u6309 \u5b57\u5178\u5e8f\u6392\u5e8f \u540e\u8fd4\u56de\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\nsynonyms = [["happy","joy"],["sad","sorrow"],["joy","cheerful"]],\ntext = "I am happy today but was sad yesterday"\n\u8f93\u51fa\uff1a\n["I am cheerful today but was sad yesterday",\n"I am cheerful today but was sorrow yesterday",\n"I am happy today but was sad yesterday",\n"I am happy today but was sorrow yesterday",\n"I am joy today but was sad yesterday",\n"I am joy today but was sorrow yesterday"]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= synonyms.length <= 10
    • \n\t
    • synonyms[i].length == 2
    • \n\t
    • synonyms[0] != synonyms[1]
    • \n\t
    • \u6240\u6709\u5355\u8bcd\u4ec5\u5305\u542b\u82f1\u6587\u5b57\u6bcd\uff0c\u4e14\u957f\u5ea6\u6700\u591a\u4e3a 10 \u3002
    • \n\t
    • text \u6700\u591a\u5305\u542b 10 \u4e2a\u5355\u8bcd\uff0c\u4e14\u5355\u8bcd\u95f4\u7528\u5355\u4e2a\u7a7a\u683c\u5206\u9694\u5f00\u3002
    • \n
    \n", "tags_en": ["Backtracking"], "tags_cn": ["\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector generateSentences(vector>& synonyms, string text) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List generateSentences(List> synonyms, String text) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def generateSentences(self, synonyms, text):\n \"\"\"\n :type synonyms: List[List[str]]\n :type text: str\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def generateSentences(self, synonyms: List[List[str]], text: str) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** generateSentences(char *** synonyms, int synonymsSize, int* synonymsColSize, char * text, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList GenerateSentences(IList> synonyms, string text) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[][]} synonyms\n * @param {string} text\n * @return {string[]}\n */\nvar generateSentences = function(synonyms, text) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[][]} synonyms\n# @param {String} text\n# @return {String[]}\ndef generate_sentences(synonyms, text)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func generateSentences(_ synonyms: [[String]], _ text: String) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func generateSentences(synonyms [][]string, text string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def generateSentences(synonyms: List[List[String]], text: String): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun generateSentences(synonyms: List>, text: String): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn generate_sentences(synonyms: Vec>, text: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $synonyms\n * @param String $text\n * @return String[]\n */\n function generateSentences($synonyms, $text) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function generateSentences(synonyms: string[][], text: string): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (generate-sentences synonyms text)\n (-> (listof (listof string?)) string? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1258](https://leetcode-cn.com/problems/synonymous-sentences)", "[\u8fd1\u4e49\u8bcd\u53e5\u5b50](/solution/1200-1299/1258.Synonymous%20Sentences/README.md)", "`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1258](https://leetcode.com/problems/synonymous-sentences)", "[Synonymous Sentences](/solution/1200-1299/1258.Synonymous%20Sentences/README_EN.md)", "`Backtracking`", "Medium", "\ud83d\udd12"]}, {"question_id": "1190", "frontend_question_id": "1257", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/smallest-common-region", "url_en": "https://leetcode.com/problems/smallest-common-region", "relative_path_cn": "/solution/1200-1299/1257.Smallest%20Common%20Region/README.md", "relative_path_en": "/solution/1200-1299/1257.Smallest%20Common%20Region/README_EN.md", "title_cn": "\u6700\u5c0f\u516c\u5171\u533a\u57df", "title_en": "Smallest Common Region", "question_title_slug": "smallest-common-region", "content_en": "

    You are given some lists of regions where the first region of each list includes all other regions in that list.

    \n\n

    Naturally, if a region X contains another region Y then X is bigger than Y. Also by definition a region X contains itself.

    \n\n

    Given two regions region1, region2, find out the smallest region that contains both of them.

    \n\n

    If you are given regions r1, r2 and r3 such that r1 includes r3, it is guaranteed there is no r2 such that r2 includes r3.
    \n
    \nIt's guaranteed the smallest region exists.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput:\nregions = [["Earth","North America","South America"],\n["North America","United States","Canada"],\n["United States","New York","Boston"],\n["Canada","Ontario","Quebec"],\n["South America","Brazil"]],\nregion1 = "Quebec",\nregion2 = "New York"\nOutput: "North America"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= regions.length <= 10^4
    • \n\t
    • region1 != region2
    • \n\t
    • All strings consist of English letters and spaces with at most 20 letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e9b\u533a\u57df\u5217\u8868 regions \uff0c\u6bcf\u4e2a\u5217\u8868\u7684\u7b2c\u4e00\u4e2a\u533a\u57df\u90fd\u5305\u542b\u8fd9\u4e2a\u5217\u8868\u5185\u6240\u6709\u5176\u4ed6\u533a\u57df\u3002

    \n\n

    \u5f88\u81ea\u7136\u5730\uff0c\u5982\u679c\u533a\u57df X \u5305\u542b\u533a\u57df Y \uff0c\u90a3\u4e48\u533a\u57df X  \u6bd4\u533a\u57df Y \u5927\u3002

    \n\n

    \u7ed9\u5b9a\u4e24\u4e2a\u533a\u57df region1 \u548c region2 \uff0c\u627e\u5230\u540c\u65f6\u5305\u542b\u8fd9\u4e24\u4e2a\u533a\u57df\u7684 \u6700\u5c0f \u533a\u57df\u3002

    \n\n

    \u5982\u679c\u533a\u57df\u5217\u8868\u4e2d r1 \u5305\u542b r2 \u548c r3 \uff0c\u90a3\u4e48\u6570\u636e\u4fdd\u8bc1 r2 \u4e0d\u4f1a\u5305\u542b r3 \u3002

    \n\n

    \u6570\u636e\u540c\u6837\u4fdd\u8bc1\u6700\u5c0f\u516c\u5171\u533a\u57df\u4e00\u5b9a\u5b58\u5728\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\nregions = [["Earth","North America","South America"],\n["North America","United States","Canada"],\n["United States","New York","Boston"],\n["Canada","Ontario","Quebec"],\n["South America","Brazil"]],\nregion1 = "Quebec",\nregion2 = "New York"\n\u8f93\u51fa\uff1a"North America"\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= regions.length <= 10^4
    • \n\t
    • region1 != region2
    • \n\t
    • \u6240\u6709\u5b57\u7b26\u4e32\u53ea\u5305\u542b\u82f1\u6587\u5b57\u6bcd\u548c\u7a7a\u683c\uff0c\u4e14\u6700\u591a\u53ea\u6709 20 \u4e2a\u5b57\u6bcd\u3002
    • \n
    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string findSmallestRegion(vector>& regions, string region1, string region2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String findSmallestRegion(List> regions, String region1, String region2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findSmallestRegion(self, regions, region1, region2):\n \"\"\"\n :type regions: List[List[str]]\n :type region1: str\n :type region2: str\n :rtype: str\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findSmallestRegion(self, regions: List[List[str]], region1: str, region2: str) -> str:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * findSmallestRegion(char *** regions, int regionsSize, int* regionsColSize, char * region1, char * region2){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string FindSmallestRegion(IList> regions, string region1, string region2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[][]} regions\n * @param {string} region1\n * @param {string} region2\n * @return {string}\n */\nvar findSmallestRegion = function(regions, region1, region2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[][]} regions\n# @param {String} region1\n# @param {String} region2\n# @return {String}\ndef find_smallest_region(regions, region1, region2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findSmallestRegion(_ regions: [[String]], _ region1: String, _ region2: String) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findSmallestRegion(regions [][]string, region1 string, region2 string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findSmallestRegion(regions: List[List[String]], region1: String, region2: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findSmallestRegion(regions: List>, region1: String, region2: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_smallest_region(regions: Vec>, region1: String, region2: String) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $regions\n * @param String $region1\n * @param String $region2\n * @return String\n */\n function findSmallestRegion($regions, $region1, $region2) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findSmallestRegion(regions: string[][], region1: string, region2: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-smallest-region regions region1 region2)\n (-> (listof (listof string?)) string? string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1257](https://leetcode-cn.com/problems/smallest-common-region)", "[\u6700\u5c0f\u516c\u5171\u533a\u57df](/solution/1200-1299/1257.Smallest%20Common%20Region/README.md)", "`\u6811`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1257](https://leetcode.com/problems/smallest-common-region)", "[Smallest Common Region](/solution/1200-1299/1257.Smallest%20Common%20Region/README_EN.md)", "`Tree`", "Medium", "\ud83d\udd12"]}, {"question_id": "1189", "frontend_question_id": "1256", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/encode-number", "url_en": "https://leetcode.com/problems/encode-number", "relative_path_cn": "/solution/1200-1299/1256.Encode%20Number/README.md", "relative_path_en": "/solution/1200-1299/1256.Encode%20Number/README_EN.md", "title_cn": "\u52a0\u5bc6\u6570\u5b57", "title_en": "Encode Number", "question_title_slug": "encode-number", "content_en": "

    Given a non-negative integer num, Return its encoding string.

    \r\n\r\n

    The encoding is done by converting the integer to a string using a secret function that you should deduce from the following table:

    \r\n\r\n

    \"\"

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: num = 23\r\nOutput: "1000"\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: num = 107\r\nOutput: "101100"\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 0 <= num <= 10^9
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u975e\u8d1f\u6574\u6570 num \uff0c\u8fd4\u56de\u5b83\u7684\u300c\u52a0\u5bc6\u5b57\u7b26\u4e32\u300d\u3002

    \n\n

    \u52a0\u5bc6\u7684\u8fc7\u7a0b\u662f\u628a\u4e00\u4e2a\u6574\u6570\u7528\u67d0\u4e2a\u672a\u77e5\u51fd\u6570\u8fdb\u884c\u8f6c\u5316\uff0c\u4f60\u9700\u8981\u4ece\u4e0b\u8868\u63a8\u6d4b\u51fa\u8be5\u8f6c\u5316\u51fd\u6570\uff1a

    \n\n

    \"\"

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anum = 23\n\u8f93\u51fa\uff1a"1000"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anum = 107\n\u8f93\u51fa\uff1a"101100"\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= num <= 10^9
    • \n
    \n", "tags_en": ["Bit Manipulation", "Math"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string encode(int num) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String encode(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def encode(self, num):\n \"\"\"\n :type num: int\n :rtype: str\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def encode(self, num: int) -> str:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * encode(int num){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string Encode(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} num\n * @return {string}\n */\nvar encode = function(num) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} num\n# @return {String}\ndef encode(num)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func encode(_ num: Int) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func encode(num int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def encode(num: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun encode(num: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn encode(num: i32) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $num\n * @return String\n */\n function encode($num) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function encode(num: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (encode num)\n (-> exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1256](https://leetcode-cn.com/problems/encode-number)", "[\u52a0\u5bc6\u6570\u5b57](/solution/1200-1299/1256.Encode%20Number/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u6570\u5b66`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1256](https://leetcode.com/problems/encode-number)", "[Encode Number](/solution/1200-1299/1256.Encode%20Number/README_EN.md)", "`Bit Manipulation`,`Math`", "Medium", "\ud83d\udd12"]}, {"question_id": "1188", "frontend_question_id": "1096", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/brace-expansion-ii", "url_en": "https://leetcode.com/problems/brace-expansion-ii", "relative_path_cn": "/solution/1000-1099/1096.Brace%20Expansion%20II/README.md", "relative_path_en": "/solution/1000-1099/1096.Brace%20Expansion%20II/README_EN.md", "title_cn": "\u82b1\u62ec\u53f7\u5c55\u5f00 II", "title_en": "Brace Expansion II", "question_title_slug": "brace-expansion-ii", "content_en": "

    Under a grammar given below, strings can represent a set of lowercase words.  Let's use R(expr) to denote the set of words the expression represents.

    \n\n

    Grammar can best be understood through simple examples:

    \n\n
      \n\t
    • Single letters represent a singleton set containing that word.\n\t
        \n\t\t
      • R("a") = {"a"}
      • \n\t\t
      • R("w") = {"w"}
      • \n\t
      \n\t
    • \n\t
    • When we take a comma delimited list of 2 or more expressions, we take the union of possibilities.\n\t
        \n\t\t
      • R("{a,b,c}") = {"a","b","c"}
      • \n\t\t
      • R("{{a,b},{b,c}}") = {"a","b","c"} (notice the final set only contains each word at most once)
      • \n\t
      \n\t
    • \n\t
    • When we concatenate two expressions, we take the set of possible concatenations between two words where the first word comes from the first expression and the second word comes from the second expression.\n\t
        \n\t\t
      • R("{a,b}{c,d}") = {"ac","ad","bc","bd"}
      • \n\t\t
      • R("a{b,c}{d,e}f{g,h}") = {"abdfg", "abdfh", "abefg", "abefh", "acdfg", "acdfh", "acefg", "acefh"}
      • \n\t
      \n\t
    • \n
    \n\n

    Formally, the 3 rules for our grammar:

    \n\n
      \n\t
    • For every lowercase letter x, we have R(x) = {x}
    • \n\t
    • For expressions e_1, e_2, ... , e_k with k >= 2, we have R({e_1,e_2,...}) = R(e_1) ∪ R(e_2) ∪ ...
    • \n\t
    • For expressions e_1 and e_2, we have R(e_1 + e_2) = {a + b for (a, b) in R(e_1) × R(e_2)}, where + denotes concatenation, and × denotes the cartesian product.
    • \n
    \n\n

    Given an expression representing a set of words under the given grammar, return the sorted list of words that the expression represents.

    \n\n

     

    \n\n
    \n

    Example 1:

    \n\n
    \nInput: "{a,b}{c,{d,e}}"\nOutput: ["ac","ad","ae","bc","bd","be"]\n
    \n\n
    \n

    Example 2:

    \n\n
    \nInput: "{{a,z},a{b,c},{ab,z}}"\nOutput: ["a","ab","ac","z"]\nExplanation: Each distinct word is written only once in the final answer.\n
    \n\n

     

    \n\n

    Constraints:

    \n\n
      \n\t
    1. 1 <= expression.length <= 60
    2. \n\t
    3. expression[i] consists of '{', '}', ','or lowercase English letters.
    4. \n\t
    5. The given expression represents a set of words based on the grammar given in the description.
    6. \n
    \n
    \n
    \n", "content_cn": "

    \u5982\u679c\u4f60\u719f\u6089 Shell \u7f16\u7a0b\uff0c\u90a3\u4e48\u4e00\u5b9a\u4e86\u89e3\u8fc7\u82b1\u62ec\u53f7\u5c55\u5f00\uff0c\u5b83\u53ef\u4ee5\u7528\u6765\u751f\u6210\u4efb\u610f\u5b57\u7b26\u4e32\u3002

    \n\n

    \u82b1\u62ec\u53f7\u5c55\u5f00\u7684\u8868\u8fbe\u5f0f\u53ef\u4ee5\u770b\u4f5c\u4e00\u4e2a\u7531 \u82b1\u62ec\u53f7\u3001\u9017\u53f7 \u548c \u5c0f\u5199\u82f1\u6587\u5b57\u6bcd \u7ec4\u6210\u7684\u5b57\u7b26\u4e32\uff0c\u5b9a\u4e49\u4e0b\u9762\u51e0\u6761\u8bed\u6cd5\u89c4\u5219\uff1a

    \n\n
      \n\t
    • \u5982\u679c\u53ea\u7ed9\u51fa\u5355\u4e00\u7684\u5143\u7d20\u00a0x\uff0c\u90a3\u4e48\u8868\u8fbe\u5f0f\u8868\u793a\u7684\u5b57\u7b26\u4e32\u5c31\u53ea\u6709\u00a0\"x\"\u3002R(x) = {x}\n\n\t
        \n\t\t
      • \u4f8b\u5982\uff0c\u8868\u8fbe\u5f0f {\"a\"}\u00a0\u8868\u793a\u5b57\u7b26\u4e32 \"a\"\u3002
      • \n\t\t
      • \u800c\u8868\u8fbe\u5f0f {\"w\"}\u00a0\u5c31\u8868\u793a\u5b57\u7b26\u4e32 \"w\"\u3002
      • \n\t
      \n\t
    • \n\t
    • \u5f53\u4e24\u4e2a\u6216\u591a\u4e2a\u8868\u8fbe\u5f0f\u5e76\u5217\uff0c\u4ee5\u9017\u53f7\u5206\u9694\u65f6\uff0c\u6211\u4eec\u53d6\u8fd9\u4e9b\u8868\u8fbe\u5f0f\u4e2d\u5143\u7d20\u7684\u5e76\u96c6\u3002R({e_1,e_2,...}) = R(e_1)\u00a0\u222a R(e_2)\u00a0\u222a ...\n\t
        \n\t\t
      • \u4f8b\u5982\uff0c\u8868\u8fbe\u5f0f \"{a,b,c}\" \u8868\u793a\u5b57\u7b26\u4e32\u00a0\"a\",\"b\",\"c\"\u3002
      • \n\t\t
      • \u800c\u8868\u8fbe\u5f0f \"{{a,b},{b,c}}\" \u4e5f\u53ef\u4ee5\u8868\u793a\u5b57\u7b26\u4e32\u00a0\"a\",\"b\",\"c\"\u3002
      • \n\t
      \n\t
    • \n\t
    • \u8981\u662f\u4e24\u4e2a\u6216\u591a\u4e2a\u8868\u8fbe\u5f0f\u76f8\u63a5\uff0c\u4e2d\u95f4\u6ca1\u6709\u9694\u5f00\u65f6\uff0c\u6211\u4eec\u4ece\u8fd9\u4e9b\u8868\u8fbe\u5f0f\u4e2d\u5404\u53d6\u4e00\u4e2a\u5143\u7d20\u4f9d\u6b21\u8fde\u63a5\u5f62\u6210\u5b57\u7b26\u4e32\u3002R(e_1 + e_2) = {a + b for (a, b) in\u00a0R(e_1)\u00a0\u00d7 R(e_2)}\n\t
        \n\t\t
      • \u4f8b\u5982\uff0c\u8868\u8fbe\u5f0f \"{a,b}{c,d}\" \u8868\u793a\u5b57\u7b26\u4e32\u00a0\"ac\",\"ad\",\"bc\",\"bd\"\u3002
      • \n\t
      \n\t
    • \n\t
    • \u8868\u8fbe\u5f0f\u4e4b\u95f4\u5141\u8bb8\u5d4c\u5957\uff0c\u5355\u4e00\u5143\u7d20\u4e0e\u8868\u8fbe\u5f0f\u7684\u8fde\u63a5\u4e5f\u662f\u5141\u8bb8\u7684\u3002\n\t
        \n\t\t
      • \u4f8b\u5982\uff0c\u8868\u8fbe\u5f0f \"a{b,c,d}\" \u8868\u793a\u5b57\u7b26\u4e32\u00a0\"ab\",\"ac\",\"ad\"\u200b\u200b\u200b\u200b\u200b\u200b\u3002
      • \n\t\t
      • \u4f8b\u5982\uff0c\u8868\u8fbe\u5f0f \"a{b,c}{d,e}f{g,h}\" \u53ef\u4ee5\u8868\u793a\u5b57\u7b26\u4e32\u00a0\"abdfg\", \"abdfh\", \"abefg\", \"abefh\", \"acdfg\", \"acdfh\", \"acefg\", \"acefh\"\u3002
      • \n\t
      \n\t
    • \n
    \n\n

    \u7ed9\u51fa\u8868\u793a\u57fa\u4e8e\u7ed9\u5b9a\u8bed\u6cd5\u89c4\u5219\u7684\u8868\u8fbe\u5f0f\u00a0expression\uff0c\u8fd4\u56de\u5b83\u6240\u8868\u793a\u7684\u6240\u6709\u5b57\u7b26\u4e32\u7ec4\u6210\u7684\u6709\u5e8f\u5217\u8868\u3002

    \n\n

    \u5047\u5982\u4f60\u5e0c\u671b\u4ee5\u300c\u96c6\u5408\u300d\u7684\u6982\u5ff5\u4e86\u89e3\u6b64\u9898\uff0c\u4e5f\u53ef\u4ee5\u901a\u8fc7\u70b9\u51fb \u201c\u663e\u793a\u82f1\u6587\u63cf\u8ff0\u201d \u83b7\u53d6\u8be6\u60c5\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\"{a,b}{c,{d,e}}\"\n\u8f93\u51fa\uff1a[\"ac\",\"ad\",\"ae\",\"bc\",\"bd\",\"be\"]
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\"{{a,z},a{b,c},{ab,z}}\"\n\u8f93\u51fa\uff1a[\"a\",\"ab\",\"ac\",\"z\"]\n\u89e3\u91ca\uff1a\u8f93\u51fa\u4e2d \u4e0d\u5e94 \u51fa\u73b0\u91cd\u590d\u7684\u7ec4\u5408\u7ed3\u679c\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= expression.length <= 50
    2. \n\t
    3. expression[i] \u7531 '{'\uff0c'}'\uff0c','\u00a0\u6216\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    4. \n\t
    5. \u7ed9\u51fa\u7684\u8868\u8fbe\u5f0f\u00a0expression\u00a0\u7528\u4ee5\u8868\u793a\u4e00\u7ec4\u57fa\u4e8e\u9898\u76ee\u63cf\u8ff0\u4e2d\u8bed\u6cd5\u6784\u9020\u7684\u5b57\u7b26\u4e32
    6. \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector braceExpansionII(string expression) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List braceExpansionII(String expression) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def braceExpansionII(self, expression):\n \"\"\"\n :type expression: str\n :rtype: List[str]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def braceExpansionII(self, expression: str) -> List[str]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** braceExpansionII(char * expression, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList BraceExpansionII(string expression) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} expression\n * @return {string[]}\n */\nvar braceExpansionII = function(expression) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} expression\n# @return {String[]}\ndef brace_expansion_ii(expression)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func braceExpansionII(_ expression: String) -> [String] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func braceExpansionII(expression string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def braceExpansionII(expression: String): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun braceExpansionII(expression: String): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn brace_expansion_ii(expression: String) -> Vec {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $expression\n * @return String[]\n */\n function braceExpansionII($expression) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function braceExpansionII(expression: string): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (brace-expansion-ii expression)\n (-> string? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1096](https://leetcode-cn.com/problems/brace-expansion-ii)", "[\u82b1\u62ec\u53f7\u5c55\u5f00 II](/solution/1000-1099/1096.Brace%20Expansion%20II/README.md)", "`\u5b57\u7b26\u4e32`", "\u56f0\u96be", ""], "md_table_row_en": ["[1096](https://leetcode.com/problems/brace-expansion-ii)", "[Brace Expansion II](/solution/1000-1099/1096.Brace%20Expansion%20II/README_EN.md)", "`String`", "Hard", ""]}, {"question_id": "1187", "frontend_question_id": "1115", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/print-foobar-alternately", "url_en": "https://leetcode.com/problems/print-foobar-alternately", "relative_path_cn": "/solution/1100-1199/1115.Print%20FooBar%20Alternately/README.md", "relative_path_en": "/solution/1100-1199/1115.Print%20FooBar%20Alternately/README_EN.md", "title_cn": "\u4ea4\u66ff\u6253\u5370FooBar", "title_en": "Print FooBar Alternately", "question_title_slug": "print-foobar-alternately", "content_en": "

    Suppose you are given the following code:

    \n\n
    \nclass FooBar {\n  public void foo() {\n    for (int i = 0; i < n; i++) {\n      print("foo");\n    }\n  }\n\n  public void bar() {\n    for (int i = 0; i < n; i++) {\n      print("bar");\n    }\n  }\n}\n
    \n\n

    The same instance of FooBar will be passed to two different threads. Thread A will call foo() while thread B will call bar(). Modify the given program to output "foobar" n times.

    \n\n

     

    \n\n

    Example 1:

    \n\n
    \nInput: n = 1\nOutput: "foobar"\nExplanation: There are two threads being fired asynchronously. One of them calls foo(), while the other calls bar(). "foobar" is being output 1 time.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 2\nOutput: "foobarfoobar"\nExplanation: "foobar" is being output 2 times.\n
    \n", "content_cn": "

    \u6211\u4eec\u63d0\u4f9b\u4e00\u4e2a\u7c7b\uff1a

    \n\n
    \nclass FooBar {\n  public void foo() {\n    for (int i = 0; i < n; i++) {\n      print("foo");\n    }\n  }\n\n  public void bar() {\n    for (int i = 0; i < n; i++) {\n      print("bar");\n    }\n  }\n}\n
    \n\n

    \u4e24\u4e2a\u4e0d\u540c\u7684\u7ebf\u7a0b\u5c06\u4f1a\u5171\u7528\u4e00\u4e2a FooBar \u5b9e\u4f8b\u3002\u5176\u4e2d\u4e00\u4e2a\u7ebf\u7a0b\u5c06\u4f1a\u8c03\u7528 foo() \u65b9\u6cd5\uff0c\u53e6\u4e00\u4e2a\u7ebf\u7a0b\u5c06\u4f1a\u8c03\u7528 bar() \u65b9\u6cd5\u3002

    \n\n

    \u8bf7\u8bbe\u8ba1\u4fee\u6539\u7a0b\u5e8f\uff0c\u4ee5\u786e\u4fdd "foobar" \u88ab\u8f93\u51fa n \u6b21\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: n = 1\n\u8f93\u51fa: "foobar"\n\u89e3\u91ca: \u8fd9\u91cc\u6709\u4e24\u4e2a\u7ebf\u7a0b\u88ab\u5f02\u6b65\u542f\u52a8\u3002\u5176\u4e2d\u4e00\u4e2a\u8c03\u7528 foo() \u65b9\u6cd5, \u53e6\u4e00\u4e2a\u8c03\u7528 bar() \u65b9\u6cd5\uff0c"foobar" \u5c06\u88ab\u8f93\u51fa\u4e00\u6b21\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: n = 2\n\u8f93\u51fa: "foobarfoobar"\n\u89e3\u91ca: "foobar" \u5c06\u88ab\u8f93\u51fa\u4e24\u6b21\u3002\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class FooBar {\nprivate:\n int n;\n\npublic:\n FooBar(int n) {\n this->n = n;\n }\n\n void foo(function printFoo) {\n \n for (int i = 0; i < n; i++) {\n \n \t// printFoo() outputs \"foo\". Do not change or remove this line.\n \tprintFoo();\n }\n }\n\n void bar(function printBar) {\n \n for (int i = 0; i < n; i++) {\n \n \t// printBar() outputs \"bar\". Do not change or remove this line.\n \tprintBar();\n }\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class FooBar {\n private int n;\n\n public FooBar(int n) {\n this.n = n;\n }\n\n public void foo(Runnable printFoo) throws InterruptedException {\n \n for (int i = 0; i < n; i++) {\n \n \t// printFoo.run() outputs \"foo\". Do not change or remove this line.\n \tprintFoo.run();\n }\n }\n\n public void bar(Runnable printBar) throws InterruptedException {\n \n for (int i = 0; i < n; i++) {\n \n // printBar.run() outputs \"bar\". Do not change or remove this line.\n \tprintBar.run();\n }\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class FooBar(object):\n def __init__(self, n):\n self.n = n\n\n\n def foo(self, printFoo):\n \"\"\"\n :type printFoo: method\n :rtype: void\n \"\"\"\n for i in xrange(self.n):\n \n # printFoo() outputs \"foo\". Do not change or remove this line.\n \tprintFoo()\n\n\n def bar(self, printBar):\n \"\"\"\n :type printBar: method\n :rtype: void\n \"\"\"\n for i in xrange(self.n):\n \n # printBar() outputs \"bar\". Do not change or remove this line.\n \tprintBar()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class FooBar:\n def __init__(self, n):\n self.n = n\n\n\n def foo(self, printFoo: 'Callable[[], None]') -> None:\n \n for i in range(self.n):\n \n # printFoo() outputs \"foo\". Do not change or remove this line.\n \tprintFoo()\n\n\n def bar(self, printBar: 'Callable[[], None]') -> None:\n \n for i in range(self.n):\n \n # printBar() outputs \"bar\". Do not change or remove this line.\n \tprintBar()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "typedef struct {\n int n;\n} FooBar;\n\nFooBar* fooBarCreate(int n) {\n FooBar* obj = (FooBar*) malloc(sizeof(FooBar));\n obj->n = n;\n return obj;\n}\n\nvoid foo(FooBar* obj) {\n \n for (int i = 0; i < obj->n; i++) {\n \n // printFoo() outputs \"foo\". Do not change or remove this line.\n printFoo();\n }\n}\n\nvoid bar(FooBar* obj) {\n \n for (int i = 0; i < obj->n; i++) {\n \n // printBar() outputs \"bar\". Do not change or remove this line.\n printBar();\n }\n}\n\nvoid fooBarFree(FooBar* obj) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class FooBar {\n private int n;\n\n public FooBar(int n) {\n this.n = n;\n }\n\n public void Foo(Action printFoo) {\n \n for (int i = 0; i < n; i++) {\n \n \t// printFoo() outputs \"foo\". Do not change or remove this line.\n \tprintFoo();\n }\n }\n\n public void Bar(Action printBar) {\n \n for (int i = 0; i < n; i++) {\n \n // printBar() outputs \"bar\". Do not change or remove this line.\n \tprintBar();\n }\n }\n}", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1115](https://leetcode-cn.com/problems/print-foobar-alternately)", "[\u4ea4\u66ff\u6253\u5370FooBar](/solution/1100-1199/1115.Print%20FooBar%20Alternately/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1115](https://leetcode.com/problems/print-foobar-alternately)", "[Print FooBar Alternately](/solution/1100-1199/1115.Print%20FooBar%20Alternately/README_EN.md)", "", "Medium", ""]}, {"question_id": "1186", "frontend_question_id": "1117", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/building-h2o", "url_en": "https://leetcode.com/problems/building-h2o", "relative_path_cn": "/solution/1100-1199/1117.Building%20H2O/README.md", "relative_path_en": "/solution/1100-1199/1117.Building%20H2O/README_EN.md", "title_cn": "H2O \u751f\u6210", "title_en": "Building H2O", "question_title_slug": "building-h2o", "content_en": "

    There are two kinds of threads, oxygen and hydrogen. Your goal is to group these threads to form water molecules. There is a barrier where each thread has to wait until a complete molecule can be formed. Hydrogen and oxygen threads will be given releaseHydrogen and releaseOxygen methods respectively, which will allow them to pass the barrier. These threads should pass the barrier in groups of three, and they must be able to immediately bond with each other to form a water molecule. You must guarantee that all the threads from one molecule bond before any other threads from the next molecule do.

    \n\n

    In other words:

    \n\n
      \n\t
    • If an oxygen thread arrives at the barrier when no hydrogen threads are present, it has to wait for two hydrogen threads.
    • \n\t
    • If a hydrogen thread arrives at the barrier when no other threads are present, it has to wait for an oxygen thread and another hydrogen thread.
    • \n
    \n\n

    We don’t have to worry about matching the threads up explicitly; that is, the threads do not necessarily know which other threads they are paired up with. The key is just that threads pass the barrier in complete sets; thus, if we examine the sequence of threads that bond and divide them into groups of three, each group should contain one oxygen and two hydrogen threads.

    \n\n

    Write synchronization code for oxygen and hydrogen molecules that enforces these constraints.

    \n\n
    \n

     

    \n
    \n\n
    \n

    Example 1:

    \n\n
    \nInput: "HOH"\nOutput: "HHO"\nExplanation: "HOH" and "OHH" are also valid answers.\n
    \n\n
    \n

    Example 2:

    \n\n
    \nInput: "OOHHHH"\nOutput: "HHOHHO"\nExplanation: "HOHHHO", "OHHHHO", "HHOHOH", "HOHHOH", "OHHHOH", "HHOOHH", "HOHOHH" and "OHHOHH" are also valid answers.\n
    \n
    \n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • Total length of input string will be 3n, where 1 ≤ n ≤ 20.
    • \n\t
    • Total number of H will be 2n in the input string.
    • \n\t
    • Total number of O will be n in the input string.
    • \n
    \n", "content_cn": "

    \u73b0\u5728\u6709\u4e24\u79cd\u7ebf\u7a0b\uff0c\u6c27 oxygen \u548c\u6c22 hydrogen\uff0c\u4f60\u7684\u76ee\u6807\u662f\u7ec4\u7ec7\u8fd9\u4e24\u79cd\u7ebf\u7a0b\u6765\u4ea7\u751f\u6c34\u5206\u5b50\u3002

    \n\n

    \u5b58\u5728\u4e00\u4e2a\u5c4f\u969c\uff08barrier\uff09\u4f7f\u5f97\u6bcf\u4e2a\u7ebf\u7a0b\u5fc5\u987b\u7b49\u5019\u76f4\u5230\u4e00\u4e2a\u5b8c\u6574\u6c34\u5206\u5b50\u80fd\u591f\u88ab\u4ea7\u751f\u51fa\u6765\u3002

    \n\n

    \u6c22\u548c\u6c27\u7ebf\u7a0b\u4f1a\u88ab\u5206\u522b\u7ed9\u4e88 releaseHydrogen \u548c releaseOxygen \u65b9\u6cd5\u6765\u5141\u8bb8\u5b83\u4eec\u7a81\u7834\u5c4f\u969c\u3002

    \n\n

    \u8fd9\u4e9b\u7ebf\u7a0b\u5e94\u8be5\u4e09\u4e09\u6210\u7ec4\u7a81\u7834\u5c4f\u969c\u5e76\u80fd\u7acb\u5373\u7ec4\u5408\u4ea7\u751f\u4e00\u4e2a\u6c34\u5206\u5b50\u3002

    \n\n

    \u4f60\u5fc5\u987b\u4fdd\u8bc1\u4ea7\u751f\u4e00\u4e2a\u6c34\u5206\u5b50\u6240\u9700\u7ebf\u7a0b\u7684\u7ed3\u5408\u5fc5\u987b\u53d1\u751f\u5728\u4e0b\u4e00\u4e2a\u6c34\u5206\u5b50\u4ea7\u751f\u4e4b\u524d\u3002

    \n\n

    \u6362\u53e5\u8bdd\u8bf4:

    \n\n
      \n\t
    • \u5982\u679c\u4e00\u4e2a\u6c27\u7ebf\u7a0b\u5230\u8fbe\u5c4f\u969c\u65f6\u6ca1\u6709\u6c22\u7ebf\u7a0b\u5230\u8fbe\uff0c\u5b83\u5fc5\u987b\u7b49\u5019\u76f4\u5230\u4e24\u4e2a\u6c22\u7ebf\u7a0b\u5230\u8fbe\u3002
    • \n\t
    • \u5982\u679c\u4e00\u4e2a\u6c22\u7ebf\u7a0b\u5230\u8fbe\u5c4f\u969c\u65f6\u6ca1\u6709\u5176\u5b83\u7ebf\u7a0b\u5230\u8fbe\uff0c\u5b83\u5fc5\u987b\u7b49\u5019\u76f4\u5230\u4e00\u4e2a\u6c27\u7ebf\u7a0b\u548c\u53e6\u4e00\u4e2a\u6c22\u7ebf\u7a0b\u5230\u8fbe\u3002
    • \n
    \n\n

    \u4e66\u5199\u6ee1\u8db3\u8fd9\u4e9b\u9650\u5236\u6761\u4ef6\u7684\u6c22\u3001\u6c27\u7ebf\u7a0b\u540c\u6b65\u4ee3\u7801\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: "HOH"\n\u8f93\u51fa: "HHO"\n\u89e3\u91ca: "HOH" \u548c "OHH" \u4f9d\u7136\u90fd\u662f\u6709\u6548\u89e3\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: "OOHHHH"\n\u8f93\u51fa: "HHOHHO"\n\u89e3\u91ca: "HOHHHO", "OHHHHO", "HHOHOH", "HOHHOH", "OHHHOH", "HHOOHH", "HOHOHH" \u548c "OHHOHH" \u4f9d\u7136\u90fd\u662f\u6709\u6548\u89e3\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u8f93\u5165\u5b57\u7b26\u4e32\u7684\u603b\u957f\u5c06\u4f1a\u662f 3n, 1 ≤ n ≤ 50\uff1b
    • \n\t
    • \u8f93\u5165\u5b57\u7b26\u4e32\u4e2d\u7684 “H” \u603b\u6570\u5c06\u4f1a\u662f 2n \u3002
    • \n\t
    • \u8f93\u5165\u5b57\u7b26\u4e32\u4e2d\u7684 “O” \u603b\u6570\u5c06\u4f1a\u662f n \u3002
    • \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class H2O {\npublic:\n H2O() {\n \n }\n\n void hydrogen(function releaseHydrogen) {\n \n // releaseHydrogen() outputs \"H\". Do not change or remove this line.\n releaseHydrogen();\n }\n\n void oxygen(function releaseOxygen) {\n \n // releaseOxygen() outputs \"O\". Do not change or remove this line.\n releaseOxygen();\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class H2O {\n\n public H2O() {\n \n }\n\n public void hydrogen(Runnable releaseHydrogen) throws InterruptedException {\n\t\t\n // releaseHydrogen.run() outputs \"H\". Do not change or remove this line.\n releaseHydrogen.run();\n }\n\n public void oxygen(Runnable releaseOxygen) throws InterruptedException {\n \n // releaseOxygen.run() outputs \"O\". Do not change or remove this line.\n\t\treleaseOxygen.run();\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class H2O(object):\n def __init__(self):\n pass\n\n\n def hydrogen(self, releaseHydrogen):\n \"\"\"\n :type releaseHydrogen: method\n :rtype: void\n \"\"\"\n \n # releaseHydrogen() outputs \"H\". Do not change or remove this line.\n releaseHydrogen()\n\n\n def oxygen(self, releaseOxygen):\n \"\"\"\n :type releaseOxygen: method\n :rtype: void\n \"\"\"\n \n # releaseOxygen() outputs \"O\". Do not change or remove this line.\n releaseOxygen()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class H2O:\n def __init__(self):\n pass\n\n\n def hydrogen(self, releaseHydrogen: 'Callable[[], None]') -> None:\n \n # releaseHydrogen() outputs \"H\". Do not change or remove this line.\n releaseHydrogen()\n\n\n def oxygen(self, releaseOxygen: 'Callable[[], None]') -> None:\n \n # releaseOxygen() outputs \"O\". Do not change or remove this line.\n releaseOxygen()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "typedef struct {\n // User defined data may be declared here.\n \n} H2O;\n\nH2O* h2oCreate() {\n H2O* obj = (H2O*) malloc(sizeof(H2O));\n \n // Initialize user defined data here.\n \n return obj;\n}\n\nvoid hydrogen(H2O* obj) {\n \n // releaseHydrogen() outputs \"H\". Do not change or remove this line.\n releaseHydrogen();\n}\n\nvoid oxygen(H2O* obj) {\n \n // releaseOxygen() outputs \"O\". Do not change or remove this line.\n releaseOxygen();\n}\n\nvoid h2oFree(H2O* obj) {\n // User defined data may be cleaned up here.\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class H2O {\n\n public H2O() {\n \n }\n\n public void Hydrogen(Action releaseHydrogen) {\n\t\t\n // releaseHydrogen() outputs \"H\". Do not change or remove this line.\n releaseHydrogen();\n }\n\n public void Oxygen(Action releaseOxygen) {\n \n // releaseOxygen() outputs \"O\". Do not change or remove this line.\n\t\treleaseOxygen();\n }\n}", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1117](https://leetcode-cn.com/problems/building-h2o)", "[H2O \u751f\u6210](/solution/1100-1199/1117.Building%20H2O/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1117](https://leetcode.com/problems/building-h2o)", "[Building H2O](/solution/1100-1199/1117.Building%20H2O/README_EN.md)", "", "Medium", ""]}, {"question_id": "1185", "frontend_question_id": "1095", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-in-mountain-array", "url_en": "https://leetcode.com/problems/find-in-mountain-array", "relative_path_cn": "/solution/1000-1099/1095.Find%20in%20Mountain%20Array/README.md", "relative_path_en": "/solution/1000-1099/1095.Find%20in%20Mountain%20Array/README_EN.md", "title_cn": "\u5c71\u8109\u6570\u7ec4\u4e2d\u67e5\u627e\u76ee\u6807\u503c", "title_en": "Find in Mountain Array", "question_title_slug": "find-in-mountain-array", "content_en": "

    (This problem is an interactive problem.)

    \n\n

    You may recall that an array A is a mountain array if and only if:

    \n\n
      \n\t
    • A.length >= 3
    • \n\t
    • There exists some i with 0 < i < A.length - 1 such that:\n\t
        \n\t\t
      • A[0] < A[1] < ... A[i-1] < A[i]
      • \n\t\t
      • A[i] > A[i+1] > ... > A[A.length - 1]
      • \n\t
      \n\t
    • \n
    \n\n

    Given a mountain array mountainArr, return the minimum index such that mountainArr.get(index) == target.  If such an index doesn't exist, return -1.

    \n\n

    You can't access the mountain array directly.  You may only access the array using a MountainArray interface:

    \n\n
      \n\t
    • MountainArray.get(k) returns the element of the array at index k (0-indexed).
    • \n\t
    • MountainArray.length() returns the length of the array.
    • \n
    \n\n

    Submissions making more than 100 calls to MountainArray.get will be judged Wrong Answer.  Also, any solutions that attempt to circumvent the judge will result in disqualification.

    \n\n
      \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: array = [1,2,3,4,5,3,1], target = 3\nOutput: 2\nExplanation: 3 exists in the array, at index=2 and index=5. Return the minimum index, which is 2.
    \n\n

    Example 2:

    \n\n
    \nInput: array = [0,1,2,4,2,1], target = 3\nOutput: -1\nExplanation: 3 does not exist in the array, so we return -1.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 3 <= mountain_arr.length() <= 10000
    • \n\t
    • 0 <= target <= 10^9
    • \n\t
    • 0 <= mountain_arr.get(index) <= 10^9
    • \n
    \n", "content_cn": "

    \uff08\u8fd9\u662f\u4e00\u4e2a \u4ea4\u4e92\u5f0f\u95ee\u9898 \uff09

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a \u5c71\u8109\u6570\u7ec4 mountainArr\uff0c\u8bf7\u4f60\u8fd4\u56de\u80fd\u591f\u4f7f\u5f97 mountainArr.get(index) \u7b49\u4e8e target \u6700\u5c0f \u7684\u4e0b\u6807 index \u503c\u3002

    \n\n

    \u5982\u679c\u4e0d\u5b58\u5728\u8fd9\u6837\u7684\u4e0b\u6807 index\uff0c\u5c31\u8bf7\u8fd4\u56de -1\u3002

    \n\n

     

    \n\n

    \u4f55\u4e3a\u5c71\u8109\u6570\u7ec4\uff1f\u5982\u679c\u6570\u7ec4 A \u662f\u4e00\u4e2a\u5c71\u8109\u6570\u7ec4\u7684\u8bdd\uff0c\u90a3\u5b83\u6ee1\u8db3\u5982\u4e0b\u6761\u4ef6\uff1a

    \n\n

    \u9996\u5148\uff0cA.length >= 3

    \n\n

    \u5176\u6b21\uff0c\u5728 0 < i < A.length - 1 \u6761\u4ef6\u4e0b\uff0c\u5b58\u5728 i \u4f7f\u5f97\uff1a

    \n\n
      \n\t
    • A[0] < A[1] < ... A[i-1] < A[i]
    • \n\t
    • A[i] > A[i+1] > ... > A[A.length - 1]
    • \n
    \n\n

     

    \n\n

    \u4f60\u5c06 \u4e0d\u80fd\u76f4\u63a5\u8bbf\u95ee\u8be5\u5c71\u8109\u6570\u7ec4\uff0c\u5fc5\u987b\u901a\u8fc7 MountainArray \u63a5\u53e3\u6765\u83b7\u53d6\u6570\u636e\uff1a

    \n\n
      \n\t
    • MountainArray.get(k) - \u4f1a\u8fd4\u56de\u6570\u7ec4\u4e2d\u7d22\u5f15\u4e3ak \u7684\u5143\u7d20\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09
    • \n\t
    • MountainArray.length() - \u4f1a\u8fd4\u56de\u8be5\u6570\u7ec4\u7684\u957f\u5ea6
    • \n
    \n\n

     

    \n\n

    \u6ce8\u610f\uff1a

    \n\n

    \u5bf9 MountainArray.get \u53d1\u8d77\u8d85\u8fc7 100 \u6b21\u8c03\u7528\u7684\u63d0\u4ea4\u5c06\u88ab\u89c6\u4e3a\u9519\u8bef\u7b54\u6848\u3002\u6b64\u5916\uff0c\u4efb\u4f55\u8bd5\u56fe\u89c4\u907f\u5224\u9898\u7cfb\u7edf\u7684\u89e3\u51b3\u65b9\u6848\u90fd\u5c06\u4f1a\u5bfc\u81f4\u6bd4\u8d5b\u8d44\u683c\u88ab\u53d6\u6d88\u3002

    \n\n

    \u4e3a\u4e86\u5e2e\u52a9\u5927\u5bb6\u66f4\u597d\u5730\u7406\u89e3\u4ea4\u4e92\u5f0f\u95ee\u9898\uff0c\u6211\u4eec\u51c6\u5907\u4e86\u4e00\u4e2a\u6837\u4f8b “\u7b54\u6848”\uff1ahttps://leetcode-cn.com/playground/RKhe3ave\uff0c\u8bf7\u6ce8\u610f\u8fd9 \u4e0d\u662f\u4e00\u4e2a\u6b63\u786e\u7b54\u6848\u3002

    \n\n
      \n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aarray = [1,2,3,4,5,3,1], target = 3\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a3 \u5728\u6570\u7ec4\u4e2d\u51fa\u73b0\u4e86\u4e24\u6b21\uff0c\u4e0b\u6807\u5206\u522b\u4e3a 2 \u548c 5\uff0c\u6211\u4eec\u8fd4\u56de\u6700\u5c0f\u7684\u4e0b\u6807 2\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aarray = [0,1,2,4,2,1], target = 3\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a3 \u5728\u6570\u7ec4\u4e2d\u6ca1\u6709\u51fa\u73b0\uff0c\u8fd4\u56de -1\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 3 <= mountain_arr.length() <= 10000
    • \n\t
    • 0 <= target <= 10^9
    • \n\t
    • 0 <= mountain_arr.get(index) <= 10^9
    • \n
    \n", "tags_en": ["Binary Search"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * // This is the MountainArray's API interface.\n * // You should not implement it, or speculate about its implementation\n * class MountainArray {\n * public:\n * int get(int index);\n * int length();\n * };\n */\n\nclass Solution {\npublic:\n int findInMountainArray(int target, MountainArray &mountainArr) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * // This is MountainArray's API interface.\n * // You should not implement it, or speculate about its implementation\n * interface MountainArray {\n * public int get(int index) {}\n * public int length() {}\n * }\n */\n \nclass Solution {\n public int findInMountainArray(int target, MountainArray mountainArr) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# \"\"\"\n# This is MountainArray's API interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class MountainArray(object):\n# def get(self, index):\n# \"\"\"\n# :type index: int\n# :rtype int\n# \"\"\"\n#\n# def length(self):\n# \"\"\"\n# :rtype int\n# \"\"\"\n\nclass Solution(object):\n def findInMountainArray(self, target, mountain_arr):\n \"\"\"\n :type target: integer\n :type mountain_arr: MountainArray\n :rtype: integer\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# \"\"\"\n# This is MountainArray's API interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class MountainArray:\n# def get(self, index: int) -> int:\n# def length(self) -> int:\n\nclass Solution:\n def findInMountainArray(self, target: int, mountain_arr: 'MountainArray') -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * *********************************************************************\n * // This is the MountainArray's API interface.\n * // You should not implement it, or speculate about its implementation\n * *********************************************************************\n *\n * int get(MountainArray *, int index);\n * int length(MountainArray *);\n */\n\nint findInMountainArray(int target, MountainArray* mountainArr) {\n\t\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * // This is MountainArray's API interface.\n * // You should not implement it, or speculate about its implementation\n * class MountainArray {\n * public int Get(int index) {}\n * public int Length() {}\n * }\n */\n\nclass Solution {\n public int FindInMountainArray(int target, MountainArray mountainArr) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // This is the MountainArray's API interface.\n * // You should not implement it, or speculate about its implementation\n * function MountainArray() {\n * @param {number} index\n * @return {number}\n * this.get = function(index) {\n * ...\n * };\n *\n * @return {number}\n * this.length = function() {\n * ...\n * };\n * };\n */\n\n/**\n * @param {number} target\n * @param {MountainArray} mountainArr\n * @return {number}\n */\nvar findInMountainArray = function(target, mountainArr) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# This is MountainArray's API interface.\n# You should not implement it, or speculate about its implementation\n# class MountainArray\n# def get(index):\n# \n# end\n#\n# def length()\n#\t\t\n#\t end\n# end\n\n# @param {int} int\n# @param {MountainArray} mountain_arr\n# @return {int}\ndef findInMountainArray(target, mountain_arr)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * // This is MountainArray's API interface.\n * // You should not implement it, or speculate about its implementation\n * interface MountainArray {\n * public func get(_ index: Int) -> Int {}\n * public func length() -> Int {}\n * }\n */\n\nclass Solution {\n func findInMountainArray(_ target: Int, _ mountainArr: MountainArray) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * // This is the MountainArray's API interface.\n * // You should not implement it, or speculate about its implementation\n * type MountainArray struct {\n * }\n *\n * func (this *MountainArray) get(index int) int {}\n * func (this *MountainArray) length() int {}\n */\n\nfunc findInMountainArray(target int, mountainArr *MountainArray) int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * // This is MountainArray's API interface.\n * // You should not implement it, or speculate about its implementation\n * class MountainArray {\n * def get(index: Int): Int = {}\n * def length(): Int = {}\n * }\n */\n\nobject Solution {\n def findInMountainArray(value: Int, mountainArr: MountainArray): Int = {\n \n\t}\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * // This is MountainArray's API interface.\n * // You should not implement it, or speculate about its implementation\n * class MountainArray {\n * fun get(index: Int): Int {}\n * fun length(): Int {}\n * }\n */\n\nclass Solution {\n fun findInMountainArray(target: Int, mountainArr: MountainArray): Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "/**\n * // This is the MountainArray's API interface.\n * // You should not implement it, or speculate about its implementation\n * struct MountainArray;\n * impl MountainArray {\n * fn get(index:i32)->i32;\n * fn length()->i32;\n * };\n */\n\nimpl Solution {\n pub fn find_in_mountain_array(target: i32, mountainArr: &MountainArray) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * // This is MountainArray's API interface.\n * // You should not implement it, or speculate about its implementation\n * class MountainArray {\n * function get($index) {}\n * function length() {}\n * }\n */\n\nclass Solution {\n /**\n * @param Integer $target\n * @param MountainArray $mountainArr\n * @return Integer\n */\n function findInMountainArray($target, $mountainArr) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * // This is the MountainArray's API interface.\n * // You should not implement it, or speculate about its implementation\n * class Master {\n * get(index: number): number {}\n *\n * length(): number {}\n * }\n */\n\nfunction findInMountainArray(target: number, mountainArr: MountainArray) {\n\t\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1095](https://leetcode-cn.com/problems/find-in-mountain-array)", "[\u5c71\u8109\u6570\u7ec4\u4e2d\u67e5\u627e\u76ee\u6807\u503c](/solution/1000-1099/1095.Find%20in%20Mountain%20Array/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u56f0\u96be", ""], "md_table_row_en": ["[1095](https://leetcode.com/problems/find-in-mountain-array)", "[Find in Mountain Array](/solution/1000-1099/1095.Find%20in%20Mountain%20Array/README_EN.md)", "`Binary Search`", "Hard", ""]}, {"question_id": "1184", "frontend_question_id": "1094", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/car-pooling", "url_en": "https://leetcode.com/problems/car-pooling", "relative_path_cn": "/solution/1000-1099/1094.Car%20Pooling/README.md", "relative_path_en": "/solution/1000-1099/1094.Car%20Pooling/README_EN.md", "title_cn": "\u62fc\u8f66", "title_en": "Car Pooling", "question_title_slug": "car-pooling", "content_en": "

    You are driving a vehicle that has capacity empty seats initially available for passengers.  The vehicle only drives east (ie. it cannot turn around and drive west.)

    \n\n

    Given a list of trips, trip[i] = [num_passengers, start_location, end_location] contains information about the i-th trip: the number of passengers that must be picked up, and the locations to pick them up and drop them off.  The locations are given as the number of kilometers due east from your vehicle's initial location.

    \n\n

    Return true if and only if it is possible to pick up and drop off all passengers for all the given trips. 

    \n\n

     

    \n\n

    Example 1:

    \n\n
    \nInput: trips = [[2,1,5],[3,3,7]], capacity = 4\nOutput: false\n
    \n\n
    \n

    Example 2:

    \n\n
    \nInput: trips = [[2,1,5],[3,3,7]], capacity = 5\nOutput: true\n
    \n\n
    \n

    Example 3:

    \n\n
    \nInput: trips = [[2,1,5],[3,5,7]], capacity = 3\nOutput: true\n
    \n\n
    \n

    Example 4:

    \n\n
    \nInput: trips = [[3,2,7],[3,7,9],[8,3,9]], capacity = 11\nOutput: true\n
    \n
    \n
    \n
    \n\n
    \n
    \n
    \n
     
    \n
    \n
    \n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    1. trips.length <= 1000
    2. \n\t
    3. trips[i].length == 3
    4. \n\t
    5. 1 <= trips[i][0] <= 100
    6. \n\t
    7. 0 <= trips[i][1] < trips[i][2] <= 1000
    8. \n\t
    9. 1 <= capacity <= 100000
    10. \n
    \n", "content_cn": "

    \u5047\u8bbe\u4f60\u662f\u4e00\u4f4d\u987a\u98ce\u8f66\u53f8\u673a\uff0c\u8f66\u4e0a\u6700\u521d\u6709 capacity \u4e2a\u7a7a\u5ea7\u4f4d\u53ef\u4ee5\u7528\u6765\u8f7d\u5ba2\u3002\u7531\u4e8e\u9053\u8def\u7684\u9650\u5236\uff0c\u8f66 \u53ea\u80fd \u5411\u4e00\u4e2a\u65b9\u5411\u884c\u9a76\uff08\u4e5f\u5c31\u662f\u8bf4\uff0c\u4e0d\u5141\u8bb8\u6389\u5934\u6216\u6539\u53d8\u65b9\u5411\uff0c\u4f60\u53ef\u4ee5\u5c06\u5176\u60f3\u8c61\u4e3a\u4e00\u4e2a\u5411\u91cf\uff09\u3002

    \n\n

    \u8fd9\u513f\u6709\u4e00\u4efd\u4e58\u5ba2\u884c\u7a0b\u8ba1\u5212\u8868 trips[][]\uff0c\u5176\u4e2d trips[i] = [num_passengers, start_location, end_location] \u5305\u542b\u4e86\u7b2c i \u7ec4\u4e58\u5ba2\u7684\u884c\u7a0b\u4fe1\u606f\uff1a

    \n\n
      \n\t
    • \u5fc5\u987b\u63a5\u9001\u7684\u4e58\u5ba2\u6570\u91cf\uff1b
    • \n\t
    • \u4e58\u5ba2\u7684\u4e0a\u8f66\u5730\u70b9\uff1b
    • \n\t
    • \u4ee5\u53ca\u4e58\u5ba2\u7684\u4e0b\u8f66\u5730\u70b9\u3002
    • \n
    \n\n

    \u8fd9\u4e9b\u7ed9\u51fa\u7684\u5730\u70b9\u4f4d\u7f6e\u662f\u4ece\u4f60\u7684 \u521d\u59cb \u51fa\u53d1\u4f4d\u7f6e\u5411\u524d\u884c\u9a76\u5230\u8fd9\u4e9b\u5730\u70b9\u6240\u9700\u7684\u8ddd\u79bb\uff08\u5b83\u4eec\u4e00\u5b9a\u5728\u4f60\u7684\u884c\u9a76\u65b9\u5411\u4e0a\uff09\u3002

    \n\n

    \u8bf7\u4f60\u6839\u636e\u7ed9\u51fa\u7684\u884c\u7a0b\u8ba1\u5212\u8868\u548c\u8f66\u5b50\u7684\u5ea7\u4f4d\u6570\uff0c\u6765\u5224\u65ad\u4f60\u7684\u8f66\u662f\u5426\u53ef\u4ee5\u987a\u5229\u5b8c\u6210\u63a5\u9001\u6240\u6709\u4e58\u5ba2\u7684\u4efb\u52a1\uff08\u5f53\u4e14\u4ec5\u5f53\u4f60\u53ef\u4ee5\u5728\u6240\u6709\u7ed9\u5b9a\u7684\u884c\u7a0b\u4e2d\u63a5\u9001\u6240\u6709\u4e58\u5ba2\u65f6\uff0c\u8fd4\u56de true\uff0c\u5426\u5219\u8bf7\u8fd4\u56de false\uff09\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1atrips = [[2,1,5],[3,3,7]], capacity = 4\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1atrips = [[2,1,5],[3,3,7]], capacity = 5\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1atrips = [[2,1,5],[3,5,7]], capacity = 3\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1atrips = [[3,2,7],[3,7,9],[8,3,9]], capacity = 11\n\u8f93\u51fa\uff1atrue\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u4f60\u53ef\u4ee5\u5047\u8bbe\u4e58\u5ba2\u4f1a\u81ea\u89c9\u9075\u5b88 “\u5148\u4e0b\u540e\u4e0a” \u7684\u826f\u597d\u7d20\u8d28
    • \n\t
    • trips.length <= 1000
    • \n\t
    • trips[i].length == 3
    • \n\t
    • 1 <= trips[i][0] <= 100
    • \n\t
    • 0 <= trips[i][1] < trips[i][2] <= 1000
    • \n\t
    • 1 <= capacity <= 100000
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool carPooling(vector>& trips, int capacity) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean carPooling(int[][] trips, int capacity) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def carPooling(self, trips, capacity):\n \"\"\"\n :type trips: List[List[int]]\n :type capacity: int\n :rtype: bool\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def carPooling(self, trips: List[List[int]], capacity: int) -> bool:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool carPooling(int** trips, int tripsSize, int* tripsColSize, int capacity){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CarPooling(int[][] trips, int capacity) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} trips\n * @param {number} capacity\n * @return {boolean}\n */\nvar carPooling = function(trips, capacity) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} trips\n# @param {Integer} capacity\n# @return {Boolean}\ndef car_pooling(trips, capacity)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func carPooling(_ trips: [[Int]], _ capacity: Int) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func carPooling(trips [][]int, capacity int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def carPooling(trips: Array[Array[Int]], capacity: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun carPooling(trips: Array, capacity: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn car_pooling(trips: Vec>, capacity: i32) -> bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $trips\n * @param Integer $capacity\n * @return Boolean\n */\n function carPooling($trips, $capacity) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function carPooling(trips: number[][], capacity: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (car-pooling trips capacity)\n (-> (listof (listof exact-integer?)) exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1094](https://leetcode-cn.com/problems/car-pooling)", "[\u62fc\u8f66](/solution/1000-1099/1094.Car%20Pooling/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1094](https://leetcode.com/problems/car-pooling)", "[Car Pooling](/solution/1000-1099/1094.Car%20Pooling/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1183", "frontend_question_id": "1093", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/statistics-from-a-large-sample", "url_en": "https://leetcode.com/problems/statistics-from-a-large-sample", "relative_path_cn": "/solution/1000-1099/1093.Statistics%20from%20a%20Large%20Sample/README.md", "relative_path_en": "/solution/1000-1099/1093.Statistics%20from%20a%20Large%20Sample/README_EN.md", "title_cn": "\u5927\u6837\u672c\u7edf\u8ba1", "title_en": "Statistics from a Large Sample", "question_title_slug": "statistics-from-a-large-sample", "content_en": "

    You are given a large sample of integers in the range [0, 255]. Since the sample is so large, it is represented by an array count where count[k] is the number of times that k appears in the sample.

    \n\n

    Calculate the following statistics:

    \n\n
      \n\t
    • minimum: The minimum element in the sample.
    • \n\t
    • maximum: The maximum element in the sample.
    • \n\t
    • mean: The average of the sample, calculated as the total sum of all elements divided by the total number of elements.
    • \n\t
    • median:\n\t
        \n\t\t
      • If the sample has an odd number of elements, then the median is the middle element once the sample is sorted.
      • \n\t\t
      • If the sample has an even number of elements, then the median is the average of the two middle elements once the sample is sorted.
      • \n\t
      \n\t
    • \n\t
    • mode: The number that appears the most in the sample. It is guaranteed to be unique.
    • \n
    \n\n

    Return the statistics of the sample as an array of floating-point numbers [minimum, maximum, mean, median, mode]. Answers within 10-5 of the actual answer will be accepted.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: count = [0,1,3,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]\nOutput: [1.00000,3.00000,2.37500,2.50000,3.00000]\nExplanation: The sample represented by count is [1,2,2,2,3,3,3,3].\nThe minimum and maximum are 1 and 3 respectively.\nThe mean is (1+2+2+2+3+3+3+3) / 8 = 19 / 8 = 2.375.\nSince the size of the sample is even, the median is the average of the two middle elements 2 and 3, which is 2.5.\nThe mode is 3 as it appears the most in the sample.\n
    \n\n

    Example 2:

    \n\n
    \nInput: count = [0,4,3,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]\nOutput: [1.00000,4.00000,2.18182,2.00000,1.00000]\nExplanation: The sample represented by count is [1,1,1,1,2,2,2,3,3,4,4].\nThe minimum and maximum are 1 and 4 respectively.\nThe mean is (1+1+1+1+2+2+2+3+3+4+4) / 11 = 24 / 11 = 2.18181818... (for display purposes, the output shows the rounded number 2.18182).\nSince the size of the sample is odd, the median is the middle element 2.\nThe mode is 1 as it appears the most in the sample.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • count.length == 256
    • \n\t
    • 0 <= count[i] <= 109
    • \n\t
    • 1 <= sum(count) <= 109
    • \n\t
    • The mode of the sample that count represents is unique.
    • \n
    \n", "content_cn": "

    \u6211\u4eec\u5bf9 0 \u5230 255 \u4e4b\u95f4\u7684\u6574\u6570\u8fdb\u884c\u91c7\u6837\uff0c\u5e76\u5c06\u7ed3\u679c\u5b58\u50a8\u5728\u6570\u7ec4 count \u4e2d\uff1acount[k] \u5c31\u662f\u6574\u6570 k \u7684\u91c7\u6837\u4e2a\u6570\u3002

    \n\n

    \u6211\u4eec\u4ee5 \u6d6e\u70b9\u6570 \u6570\u7ec4\u7684\u5f62\u5f0f\uff0c\u5206\u522b\u8fd4\u56de\u6837\u672c\u7684\u6700\u5c0f\u503c\u3001\u6700\u5927\u503c\u3001\u5e73\u5747\u503c\u3001\u4e2d\u4f4d\u6570\u548c\u4f17\u6570\u3002\u5176\u4e2d\uff0c\u4f17\u6570\u662f\u4fdd\u8bc1\u552f\u4e00\u7684\u3002

    \n\n

    \u6211\u4eec\u5148\u6765\u56de\u987e\u4e00\u4e0b\u4e2d\u4f4d\u6570\u7684\u77e5\u8bc6\uff1a

    \n\n
      \n\t
    • \u5982\u679c\u6837\u672c\u4e2d\u7684\u5143\u7d20\u6709\u5e8f\uff0c\u5e76\u4e14\u5143\u7d20\u6570\u91cf\u4e3a\u5947\u6570\u65f6\uff0c\u4e2d\u4f4d\u6570\u4e3a\u6700\u4e2d\u95f4\u7684\u90a3\u4e2a\u5143\u7d20\uff1b
    • \n\t
    • \u5982\u679c\u6837\u672c\u4e2d\u7684\u5143\u7d20\u6709\u5e8f\uff0c\u5e76\u4e14\u5143\u7d20\u6570\u91cf\u4e3a\u5076\u6570\u65f6\uff0c\u4e2d\u4f4d\u6570\u4e3a\u4e2d\u95f4\u7684\u4e24\u4e2a\u5143\u7d20\u7684\u5e73\u5747\u503c\u3002
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1acount = [0,1,3,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]\n\u8f93\u51fa\uff1a[1.00000,3.00000,2.37500,2.50000,3.00000]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1acount = [0,4,3,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]\n\u8f93\u51fa\uff1a[1.00000,4.00000,2.18182,2.00000,1.00000]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. count.length == 256
    2. \n\t
    3. 1 <= sum(count) <= 10^9
    4. \n\t
    5. \u8ba1\u6570\u8868\u793a\u7684\u4f17\u6570\u662f\u552f\u4e00\u7684
    6. \n\t
    7. \u7b54\u6848\u4e0e\u771f\u5b9e\u503c\u8bef\u5dee\u5728 10^-5 \u4ee5\u5185\u5c31\u4f1a\u88ab\u89c6\u4e3a\u6b63\u786e\u7b54\u6848
    8. \n
    \n", "tags_en": ["Math", "Two Pointers"], "tags_cn": ["\u6570\u5b66", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector sampleStats(vector& count) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double[] sampleStats(int[] count) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def sampleStats(self, count):\n \"\"\"\n :type count: List[int]\n :rtype: List[float]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def sampleStats(self, count: List[int]) -> List[float]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\ndouble* sampleStats(int* count, int countSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double[] SampleStats(int[] count) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} count\n * @return {number[]}\n */\nvar sampleStats = function(count) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} count\n# @return {Float[]}\ndef sample_stats(count)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func sampleStats(_ count: [Int]) -> [Double] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func sampleStats(count []int) []float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def sampleStats(count: Array[Int]): Array[Double] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun sampleStats(count: IntArray): DoubleArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sample_stats(count: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $count\n * @return Float[]\n */\n function sampleStats($count) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function sampleStats(count: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (sample-stats count)\n (-> (listof exact-integer?) (listof flonum?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1093](https://leetcode-cn.com/problems/statistics-from-a-large-sample)", "[\u5927\u6837\u672c\u7edf\u8ba1](/solution/1000-1099/1093.Statistics%20from%20a%20Large%20Sample/README.md)", "`\u6570\u5b66`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1093](https://leetcode.com/problems/statistics-from-a-large-sample)", "[Statistics from a Large Sample](/solution/1000-1099/1093.Statistics%20from%20a%20Large%20Sample/README_EN.md)", "`Math`,`Two Pointers`", "Medium", ""]}, {"question_id": "1182", "frontend_question_id": "0550", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/game-play-analysis-iv", "url_en": "https://leetcode.com/problems/game-play-analysis-iv", "relative_path_cn": "/solution/0500-0599/0550.Game%20Play%20Analysis%20IV/README.md", "relative_path_en": "/solution/0500-0599/0550.Game%20Play%20Analysis%20IV/README_EN.md", "title_cn": "\u6e38\u620f\u73a9\u6cd5\u5206\u6790 IV", "title_en": "Game Play Analysis IV", "question_title_slug": "game-play-analysis-iv", "content_en": "

    Table: Activity

    \n\n
    \n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| player_id    | int     |\n| device_id    | int     |\n| event_date   | date    |\n| games_played | int     |\n+--------------+---------+\n(player_id, event_date) is the primary key of this table.\nThis table shows the activity of players of some game.\nEach row is a record of a player who logged in and played a number of games (possibly 0) before logging out on someday using some device.\n
    \n\n

     

    \n\n

    Write an SQL query that reports the fraction of players that logged in again on the day after the day they first logged in, rounded to 2 decimal places. In other words, you need to count the number of players that logged in for at least two consecutive days starting from their first login date, then divide that number by the total number of players.

    \n\n

    The query result format is in the following example:

    \n\n

     

    \n\n
    \nActivity table:\n+-----------+-----------+------------+--------------+\n| player_id | device_id | event_date | games_played |\n+-----------+-----------+------------+--------------+\n| 1         | 2         | 2016-03-01 | 5            |\n| 1         | 2         | 2016-03-02 | 6            |\n| 2         | 3         | 2017-06-25 | 1            |\n| 3         | 1         | 2016-03-02 | 0            |\n| 3         | 4         | 2018-07-03 | 5            |\n+-----------+-----------+------------+--------------+\n\nResult table:\n+-----------+\n| fraction  |\n+-----------+\n| 0.33      |\n+-----------+\nOnly the player with id 1 logged back in after the first day he had logged in so the answer is 1/3 = 0.33\n
    \n", "content_cn": "

    Table: Activity

    \n\n
    +--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| player_id    | int     |\n| device_id    | int     |\n| event_date   | date    |\n| games_played | int     |\n+--------------+---------+\n\uff08player_id\uff0cevent_date\uff09\u662f\u6b64\u8868\u7684\u4e3b\u952e\u3002\n\u8fd9\u5f20\u8868\u663e\u793a\u4e86\u67d0\u4e9b\u6e38\u620f\u7684\u73a9\u5bb6\u7684\u6d3b\u52a8\u60c5\u51b5\u3002\n\u6bcf\u4e00\u884c\u662f\u4e00\u4e2a\u73a9\u5bb6\u7684\u8bb0\u5f55\uff0c\u4ed6\u5728\u67d0\u4e00\u5929\u4f7f\u7528\u67d0\u4e2a\u8bbe\u5907\u6ce8\u9500\u4e4b\u524d\u767b\u5f55\u5e76\u73a9\u4e86\u5f88\u591a\u6e38\u620f\uff08\u53ef\u80fd\u662f 0\uff09\u3002\n
    \n\n

     

    \n\n

    \u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\uff0c\u62a5\u544a\u5728\u9996\u6b21\u767b\u5f55\u7684\u7b2c\u4e8c\u5929\u518d\u6b21\u767b\u5f55\u7684\u73a9\u5bb6\u7684\u6bd4\u7387\uff0c\u56db\u820d\u4e94\u5165\u5230\u5c0f\u6570\u70b9\u540e\u4e24\u4f4d\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u60a8\u9700\u8981\u8ba1\u7b97\u4ece\u9996\u6b21\u767b\u5f55\u65e5\u671f\u5f00\u59cb\u81f3\u5c11\u8fde\u7eed\u4e24\u5929\u767b\u5f55\u7684\u73a9\u5bb6\u7684\u6570\u91cf\uff0c\u7136\u540e\u9664\u4ee5\u73a9\u5bb6\u603b\u6570\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u6240\u793a\uff1a

    \n\n
    Activity table:\n+-----------+-----------+------------+--------------+\n| player_id | device_id | event_date | games_played |\n+-----------+-----------+------------+--------------+\n| 1         | 2         | 2016-03-01 | 5            |\n| 1         | 2         | 2016-03-02 | 6            |\n| 2         | 3         | 2017-06-25 | 1            |\n| 3         | 1         | 2016-03-02 | 0            |\n| 3         | 4         | 2018-07-03 | 5            |\n+-----------+-----------+------------+--------------+\n\nResult table:\n+-----------+\n| fraction  |\n+-----------+\n| 0.33      |\n+-----------+\n\u53ea\u6709 ID \u4e3a 1 \u7684\u73a9\u5bb6\u5728\u7b2c\u4e00\u5929\u767b\u5f55\u540e\u624d\u91cd\u65b0\u767b\u5f55\uff0c\u6240\u4ee5\u7b54\u6848\u662f 1/3 = 0.33\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0550](https://leetcode-cn.com/problems/game-play-analysis-iv)", "[\u6e38\u620f\u73a9\u6cd5\u5206\u6790 IV](/solution/0500-0599/0550.Game%20Play%20Analysis%20IV/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0550](https://leetcode.com/problems/game-play-analysis-iv)", "[Game Play Analysis IV](/solution/0500-0599/0550.Game%20Play%20Analysis%20IV/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1181", "frontend_question_id": "0534", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/game-play-analysis-iii", "url_en": "https://leetcode.com/problems/game-play-analysis-iii", "relative_path_cn": "/solution/0500-0599/0534.Game%20Play%20Analysis%20III/README.md", "relative_path_en": "/solution/0500-0599/0534.Game%20Play%20Analysis%20III/README_EN.md", "title_cn": "\u6e38\u620f\u73a9\u6cd5\u5206\u6790 III", "title_en": "Game Play Analysis III", "question_title_slug": "game-play-analysis-iii", "content_en": "

    Table: Activity

    \n\n
    \n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| player_id    | int     |\n| device_id    | int     |\n| event_date   | date    |\n| games_played | int     |\n+--------------+---------+\n(player_id, event_date) is the primary key of this table.\nThis table shows the activity of players of some game.\nEach row is a record of a player who logged in and played a number of games (possibly 0) before logging out on some day using some device.\n
    \n\n

     

    \n\n

    Write an SQL query that reports for each player and date, how many games played so far by the player. That is, the total number of games played by the player until that date. Check the example for clarity.

    \n\n

    The query result format is in the following example:

    \n\n
    \nActivity table:\n+-----------+-----------+------------+--------------+\n| player_id | device_id | event_date | games_played |\n+-----------+-----------+------------+--------------+\n| 1         | 2         | 2016-03-01 | 5            |\n| 1         | 2         | 2016-05-02 | 6            |\n| 1         | 3         | 2017-06-25 | 1            |\n| 3         | 1         | 2016-03-02 | 0            |\n| 3         | 4         | 2018-07-03 | 5            |\n+-----------+-----------+------------+--------------+\n\nResult table:\n+-----------+------------+---------------------+\n| player_id | event_date | games_played_so_far |\n+-----------+------------+---------------------+\n| 1         | 2016-03-01 | 5                   |\n| 1         | 2016-05-02 | 11                  |\n| 1         | 2017-06-25 | 12                  |\n| 3         | 2016-03-02 | 0                   |\n| 3         | 2018-07-03 | 5                   |\n+-----------+------------+---------------------+\nFor the player with id 1, 5 + 6 = 11 games played by 2016-05-02, and 5 + 6 + 1 = 12 games played by 2017-06-25.\nFor the player with id 3, 0 + 5 = 5 games played by 2018-07-03.\nNote that for each player we only care about the days when the player logged in.\n
    \n", "content_cn": "

    Table: Activity

    \n\n
    \n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| player_id    | int     |\n| device_id    | int     |\n| event_date   | date    |\n| games_played | int     |\n+--------------+---------+\n\uff08player_id\uff0cevent_date\uff09\u662f\u6b64\u8868\u7684\u4e3b\u952e\u3002\n\u8fd9\u5f20\u8868\u663e\u793a\u4e86\u67d0\u4e9b\u6e38\u620f\u7684\u73a9\u5bb6\u7684\u6d3b\u52a8\u60c5\u51b5\u3002\n\u6bcf\u4e00\u884c\u662f\u4e00\u4e2a\u73a9\u5bb6\u7684\u8bb0\u5f55\uff0c\u4ed6\u5728\u67d0\u4e00\u5929\u4f7f\u7528\u67d0\u4e2a\u8bbe\u5907\u6ce8\u9500\u4e4b\u524d\u767b\u5f55\u5e76\u73a9\u4e86\u5f88\u591a\u6e38\u620f\uff08\u53ef\u80fd\u662f 0 \uff09\u3002\n
    \n\n

     

    \n\n

    \u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\uff0c\u540c\u65f6\u62a5\u544a\u6bcf\u7ec4\u73a9\u5bb6\u548c\u65e5\u671f\uff0c\u4ee5\u53ca\u73a9\u5bb6\u5230\u76ee\u524d\u4e3a\u6b62\u73a9\u4e86\u591a\u5c11\u6e38\u620f\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u5728\u6b64\u65e5\u671f\u4e4b\u524d\u73a9\u5bb6\u6240\u73a9\u7684\u6e38\u620f\u603b\u6570\u3002\u8be6\u7ec6\u60c5\u51b5\u8bf7\u67e5\u770b\u793a\u4f8b\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u6240\u793a\uff1a

    \n\n
    \nActivity table:\n+-----------+-----------+------------+--------------+\n| player_id | device_id | event_date | games_played |\n+-----------+-----------+------------+--------------+\n| 1         | 2         | 2016-03-01 | 5            |\n| 1         | 2         | 2016-05-02 | 6            |\n| 1         | 3         | 2017-06-25 | 1            |\n| 3         | 1         | 2016-03-02 | 0            |\n| 3         | 4         | 2018-07-03 | 5            |\n+-----------+-----------+------------+--------------+\n\nResult table:\n+-----------+------------+---------------------+\n| player_id | event_date | games_played_so_far |\n+-----------+------------+---------------------+\n| 1         | 2016-03-01 | 5                   |\n| 1         | 2016-05-02 | 11                  |\n| 1         | 2017-06-25 | 12                  |\n| 3         | 2016-03-02 | 0                   |\n| 3         | 2018-07-03 | 5                   |\n+-----------+------------+---------------------+\n\u5bf9\u4e8e ID \u4e3a 1 \u7684\u73a9\u5bb6\uff0c2016-05-02 \u5171\u73a9\u4e86 5+6=11 \u4e2a\u6e38\u620f\uff0c2017-06-25 \u5171\u73a9\u4e86 5+6+1=12 \u4e2a\u6e38\u620f\u3002\n\u5bf9\u4e8e ID \u4e3a 3 \u7684\u73a9\u5bb6\uff0c2018-07-03 \u5171\u73a9\u4e86 0+5=5 \u4e2a\u6e38\u620f\u3002\n\u8bf7\u6ce8\u610f\uff0c\u5bf9\u4e8e\u6bcf\u4e2a\u73a9\u5bb6\uff0c\u6211\u4eec\u53ea\u5173\u5fc3\u73a9\u5bb6\u7684\u767b\u5f55\u65e5\u671f\u3002\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0534](https://leetcode-cn.com/problems/game-play-analysis-iii)", "[\u6e38\u620f\u73a9\u6cd5\u5206\u6790 III](/solution/0500-0599/0534.Game%20Play%20Analysis%20III/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0534](https://leetcode.com/problems/game-play-analysis-iii)", "[Game Play Analysis III](/solution/0500-0599/0534.Game%20Play%20Analysis%20III/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1180", "frontend_question_id": "0512", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/game-play-analysis-ii", "url_en": "https://leetcode.com/problems/game-play-analysis-ii", "relative_path_cn": "/solution/0500-0599/0512.Game%20Play%20Analysis%20II/README.md", "relative_path_en": "/solution/0500-0599/0512.Game%20Play%20Analysis%20II/README_EN.md", "title_cn": "\u6e38\u620f\u73a9\u6cd5\u5206\u6790 II", "title_en": "Game Play Analysis II", "question_title_slug": "game-play-analysis-ii", "content_en": "

    Table: Activity

    \n\n
    \n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| player_id    | int     |\n| device_id    | int     |\n| event_date   | date    |\n| games_played | int     |\n+--------------+---------+\n(player_id, event_date) is the primary key of this table.\nThis table shows the activity of players of some game.\nEach row is a record of a player who logged in and played a number of games (possibly 0) before logging out on some day using some device.\n
    \n\n

     

    \n\n

    Write a SQL query that reports the device that is first logged in for each player.

    \n\n

    The query result format is in the following example:

    \n\n
    \nActivity table:\n+-----------+-----------+------------+--------------+\n| player_id | device_id | event_date | games_played |\n+-----------+-----------+------------+--------------+\n| 1         | 2         | 2016-03-01 | 5            |\n| 1         | 2         | 2016-05-02 | 6            |\n| 2         | 3         | 2017-06-25 | 1            |\n| 3         | 1         | 2016-03-02 | 0            |\n| 3         | 4         | 2018-07-03 | 5            |\n+-----------+-----------+------------+--------------+\n\nResult table:\n+-----------+-----------+\n| player_id | device_id |\n+-----------+-----------+\n| 1         | 2         |\n| 2         | 3         |\n| 3         | 1         |\n+-----------+-----------+
    \n", "content_cn": "

    Table: Activity

    \n\n
    \n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| player_id    | int     |\n| device_id    | int     |\n| event_date   | date    |\n| games_played | int     |\n+--------------+---------+\n(player_id, event_date) \u662f\u8fd9\u4e2a\u8868\u7684\u4e24\u4e2a\u4e3b\u952e\n\u8fd9\u4e2a\u8868\u663e\u793a\u7684\u662f\u67d0\u4e9b\u6e38\u620f\u73a9\u5bb6\u7684\u6e38\u620f\u6d3b\u52a8\u60c5\u51b5\n\u6bcf\u4e00\u884c\u662f\u5728\u67d0\u5929\u4f7f\u7528\u67d0\u4e2a\u8bbe\u5907\u767b\u51fa\u4e4b\u524d\u767b\u5f55\u5e76\u73a9\u591a\u4e2a\u6e38\u620f\uff08\u53ef\u80fd\u4e3a0\uff09\u7684\u73a9\u5bb6\u7684\u8bb0\u5f55\n
    \n\n

    \u8bf7\u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\uff0c\u63cf\u8ff0\u6bcf\u4e00\u4e2a\u73a9\u5bb6\u9996\u6b21\u767b\u9646\u7684\u8bbe\u5907\u540d\u79f0

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5728\u4ee5\u4e0b\u793a\u4f8b\u4e2d\uff1a

    \n\n
    \nActivity table:\n+-----------+-----------+------------+--------------+\n| player_id | device_id | event_date | games_played |\n+-----------+-----------+------------+--------------+\n| 1         | 2         | 2016-03-01 | 5            |\n| 1         | 2         | 2016-05-02 | 6            |\n| 2         | 3         | 2017-06-25 | 1            |\n| 3         | 1         | 2016-03-02 | 0            |\n| 3         | 4         | 2018-07-03 | 5            |\n+-----------+-----------+------------+--------------+\n\nResult table:\n+-----------+-----------+\n| player_id | device_id |\n+-----------+-----------+\n| 1         | 2         |\n| 2         | 3         |\n| 3         | 1         |\n+-----------+-----------+
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0512](https://leetcode-cn.com/problems/game-play-analysis-ii)", "[\u6e38\u620f\u73a9\u6cd5\u5206\u6790 II](/solution/0500-0599/0512.Game%20Play%20Analysis%20II/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0512](https://leetcode.com/problems/game-play-analysis-ii)", "[Game Play Analysis II](/solution/0500-0599/0512.Game%20Play%20Analysis%20II/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1179", "frontend_question_id": "0511", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/game-play-analysis-i", "url_en": "https://leetcode.com/problems/game-play-analysis-i", "relative_path_cn": "/solution/0500-0599/0511.Game%20Play%20Analysis%20I/README.md", "relative_path_en": "/solution/0500-0599/0511.Game%20Play%20Analysis%20I/README_EN.md", "title_cn": "\u6e38\u620f\u73a9\u6cd5\u5206\u6790 I", "title_en": "Game Play Analysis I", "question_title_slug": "game-play-analysis-i", "content_en": "

    Table: Activity

    \n\n
    \n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| player_id    | int     |\n| device_id    | int     |\n| event_date   | date    |\n| games_played | int     |\n+--------------+---------+\n(player_id, event_date) is the primary key of this table.\nThis table shows the activity of players of some game.\nEach row is a record of a player who logged in and played a number of games (possibly 0) before logging out on some day using some device.\n
    \n\n

     

    \n\n

    Write an SQL query that reports the first login date for each player.

    \n\n

    The query result format is in the following example:

    \n\n
    \nActivity table:\n+-----------+-----------+------------+--------------+\n| player_id | device_id | event_date | games_played |\n+-----------+-----------+------------+--------------+\n| 1         | 2         | 2016-03-01 | 5            |\n| 1         | 2         | 2016-05-02 | 6            |\n| 2         | 3         | 2017-06-25 | 1            |\n| 3         | 1         | 2016-03-02 | 0            |\n| 3         | 4         | 2018-07-03 | 5            |\n+-----------+-----------+------------+--------------+\n\nResult table:\n+-----------+-------------+\n| player_id | first_login |\n+-----------+-------------+\n| 1         | 2016-03-01  |\n| 2         | 2017-06-25  |\n| 3         | 2016-03-02  |\n+-----------+-------------+\n
    \n", "content_cn": "

    \u6d3b\u52a8\u8868 Activity\uff1a

    \n\n
    \n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| player_id    | int     |\n| device_id    | int     |\n| event_date   | date    |\n| games_played | int     |\n+--------------+---------+\n\u8868\u7684\u4e3b\u952e\u662f (player_id, event_date)\u3002\n\u8fd9\u5f20\u8868\u5c55\u793a\u4e86\u4e00\u4e9b\u6e38\u620f\u73a9\u5bb6\u5728\u6e38\u620f\u5e73\u53f0\u4e0a\u7684\u884c\u4e3a\u6d3b\u52a8\u3002\n\u6bcf\u884c\u6570\u636e\u8bb0\u5f55\u4e86\u4e00\u540d\u73a9\u5bb6\u5728\u9000\u51fa\u5e73\u53f0\u4e4b\u524d\uff0c\u5f53\u5929\u4f7f\u7528\u540c\u4e00\u53f0\u8bbe\u5907\u767b\u5f55\u5e73\u53f0\u540e\u6253\u5f00\u7684\u6e38\u620f\u7684\u6570\u76ee\uff08\u53ef\u80fd\u662f 0 \u4e2a\uff09\u3002\n
    \n\n

     

    \n\n

    \u5199\u4e00\u6761 SQL \u67e5\u8be2\u8bed\u53e5\u83b7\u53d6\u6bcf\u4f4d\u73a9\u5bb6 \u7b2c\u4e00\u6b21\u767b\u9646\u5e73\u53f0\u7684\u65e5\u671f\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u7684\u683c\u5f0f\u5982\u4e0b\u6240\u793a\uff1a

    \n\n
    \nActivity \u8868\uff1a\n+-----------+-----------+------------+--------------+\n| player_id | device_id | event_date | games_played |\n+-----------+-----------+------------+--------------+\n| 1         | 2         | 2016-03-01 | 5            |\n| 1         | 2         | 2016-05-02 | 6            |\n| 2         | 3         | 2017-06-25 | 1            |\n| 3         | 1         | 2016-03-02 | 0            |\n| 3         | 4         | 2018-07-03 | 5            |\n+-----------+-----------+------------+--------------+\n\nResult \u8868\uff1a\n+-----------+-------------+\n| player_id | first_login |\n+-----------+-------------+\n| 1         | 2016-03-01  |\n| 2         | 2017-06-25  |\n| 3         | 2016-03-02  |\n+-----------+-------------+\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0511](https://leetcode-cn.com/problems/game-play-analysis-i)", "[\u6e38\u620f\u73a9\u6cd5\u5206\u6790 I](/solution/0500-0599/0511.Game%20Play%20Analysis%20I/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0511](https://leetcode.com/problems/game-play-analysis-i)", "[Game Play Analysis I](/solution/0500-0599/0511.Game%20Play%20Analysis%20I/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1178", "frontend_question_id": "1216", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/valid-palindrome-iii", "url_en": "https://leetcode.com/problems/valid-palindrome-iii", "relative_path_cn": "/solution/1200-1299/1216.Valid%20Palindrome%20III/README.md", "relative_path_en": "/solution/1200-1299/1216.Valid%20Palindrome%20III/README_EN.md", "title_cn": "\u9a8c\u8bc1\u56de\u6587\u5b57\u7b26\u4e32 III", "title_en": "Valid Palindrome III", "question_title_slug": "valid-palindrome-iii", "content_en": "

    Given a string s and an integer k, return true if s is a k-palindrome.

    \n\n

    A string is k-palindrome if it can be transformed into a palindrome by removing at most k characters from it.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "abcdeca", k = 2\nOutput: true\nExplanation: Remove 'b' and 'e' characters.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "abbababa", k = 1\nOutput: true\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 1000
    • \n\t
    • s consists of only lowercase English letters.
    • \n\t
    • 1 <= k <= s.length
    • \n
    \n", "content_cn": "

    \u7ed9\u51fa\u4e00\u4e2a\u5b57\u7b26\u4e32 s \u548c\u4e00\u4e2a\u6574\u6570 k\uff0c\u8bf7\u4f60\u5e2e\u5fd9\u5224\u65ad\u8fd9\u4e2a\u5b57\u7b26\u4e32\u662f\u4e0d\u662f\u4e00\u4e2a\u300cK \u56de\u6587\u300d\u3002

    \n\n

    \u6240\u8c13\u300cK \u56de\u6587\u300d\uff1a\u5982\u679c\u53ef\u4ee5\u901a\u8fc7\u4ece\u5b57\u7b26\u4e32\u4e2d\u5220\u53bb\u6700\u591a k \u4e2a\u5b57\u7b26\u5c06\u5176\u8f6c\u6362\u4e3a\u56de\u6587\uff0c\u90a3\u4e48\u8fd9\u4e2a\u5b57\u7b26\u4e32\u5c31\u662f\u4e00\u4e2a\u300cK \u56de\u6587\u300d\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1as = "abcdeca", k = 2\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u5220\u9664\u5b57\u7b26 “b” \u548c “e”\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 1000
    • \n\t
    • s \u4e2d\u53ea\u542b\u6709\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd
    • \n\t
    • 1 <= k <= s.length
    • \n
    \n", "tags_en": ["String", "Dynamic Programming"], "tags_cn": ["\u5b57\u7b26\u4e32", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isValidPalindrome(string s, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isValidPalindrome(String s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isValidPalindrome(self, s, k):\n \"\"\"\n :type s: str\n :type k: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isValidPalindrome(self, s: str, k: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isValidPalindrome(char * s, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsValidPalindrome(string s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number} k\n * @return {boolean}\n */\nvar isValidPalindrome = function(s, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer} k\n# @return {Boolean}\ndef is_valid_palindrome(s, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isValidPalindrome(_ s: String, _ k: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isValidPalindrome(s string, k int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isValidPalindrome(s: String, k: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isValidPalindrome(s: String, k: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_valid_palindrome(s: String, k: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer $k\n * @return Boolean\n */\n function isValidPalindrome($s, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isValidPalindrome(s: string, k: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-valid-palindrome s k)\n (-> string? exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1216](https://leetcode-cn.com/problems/valid-palindrome-iii)", "[\u9a8c\u8bc1\u56de\u6587\u5b57\u7b26\u4e32 III](/solution/1200-1299/1216.Valid%20Palindrome%20III/README.md)", "`\u5b57\u7b26\u4e32`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1216](https://leetcode.com/problems/valid-palindrome-iii)", "[Valid Palindrome III](/solution/1200-1299/1216.Valid%20Palindrome%20III/README_EN.md)", "`String`,`Dynamic Programming`", "Hard", "\ud83d\udd12"]}, {"question_id": "1177", "frontend_question_id": "1245", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/tree-diameter", "url_en": "https://leetcode.com/problems/tree-diameter", "relative_path_cn": "/solution/1200-1299/1245.Tree%20Diameter/README.md", "relative_path_en": "/solution/1200-1299/1245.Tree%20Diameter/README_EN.md", "title_cn": "\u6811\u7684\u76f4\u5f84", "title_en": "Tree Diameter", "question_title_slug": "tree-diameter", "content_en": "

    Given an undirected tree, return its diameter: the number of edges in a longest path in that tree.

    \n\n

    The tree is given as an array of edges where edges[i] = [u, v] is a bidirectional edge between nodes u and v.  Each node has labels in the set {0, 1, ..., edges.length}.

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: edges = [[0,1],[0,2]]\nOutput: 2\nExplanation: \nA longest path of the tree is the path 1 - 0 - 2.\n
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: edges = [[0,1],[1,2],[2,3],[1,4],[4,5]]\nOutput: 4\nExplanation: \nA longest path of the tree is the path 3 - 2 - 1 - 4 - 5.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= edges.length < 10^4
    • \n\t
    • edges[i][0] != edges[i][1]
    • \n\t
    • 0 <= edges[i][j] <= edges.length
    • \n\t
    • The given edges form an undirected tree.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u8fd9\u68f5\u300c\u65e0\u5411\u6811\u300d\uff0c\u8bf7\u4f60\u6d4b\u7b97\u5e76\u8fd4\u56de\u5b83\u7684\u300c\u76f4\u5f84\u300d\uff1a\u8fd9\u68f5\u6811\u4e0a\u6700\u957f\u7b80\u5355\u8def\u5f84\u7684 \u8fb9\u6570\u3002

    \n\n

    \u6211\u4eec\u7528\u4e00\u4e2a\u7531\u6240\u6709\u300c\u8fb9\u300d\u7ec4\u6210\u7684\u6570\u7ec4 edges \u6765\u8868\u793a\u4e00\u68f5\u65e0\u5411\u6811\uff0c\u5176\u4e2d edges[i] = [u, v] \u8868\u793a\u8282\u70b9 u \u548c v \u4e4b\u95f4\u7684\u53cc\u5411\u8fb9\u3002

    \n\n

    \u6811\u4e0a\u7684\u8282\u70b9\u90fd\u5df2\u7ecf\u7528 {0, 1, ..., edges.length} \u4e2d\u7684\u6570\u505a\u4e86\u6807\u8bb0\uff0c\u6bcf\u4e2a\u8282\u70b9\u4e0a\u7684\u6807\u8bb0\u90fd\u662f\u72ec\u4e00\u65e0\u4e8c\u7684\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1aedges = [[0,1],[0,2]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n\u8fd9\u68f5\u6811\u4e0a\u6700\u957f\u7684\u8def\u5f84\u662f 1 - 0 - 2\uff0c\u8fb9\u6570\u4e3a 2\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1aedges = [[0,1],[1,2],[2,3],[1,4],[4,5]]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a \n\u8fd9\u68f5\u6811\u4e0a\u6700\u957f\u7684\u8def\u5f84\u662f 3 - 2 - 1 - 4 - 5\uff0c\u8fb9\u6570\u4e3a 4\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= edges.length < 10^4
    • \n\t
    • edges[i][0] != edges[i][1]
    • \n\t
    • 0 <= edges[i][j] <= edges.length
    • \n\t
    • edges \u4f1a\u5f62\u6210\u4e00\u68f5\u65e0\u5411\u6811
    • \n
    \n", "tags_en": ["Tree", "Depth-first Search", "Breadth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int treeDiameter(vector>& edges) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int treeDiameter(int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def treeDiameter(self, edges):\n \"\"\"\n :type edges: List[List[int]]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def treeDiameter(self, edges: List[List[int]]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint treeDiameter(int** edges, int edgesSize, int* edgesColSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int TreeDiameter(int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} edges\n * @return {number}\n */\nvar treeDiameter = function(edges) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} edges\n# @return {Integer}\ndef tree_diameter(edges)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func treeDiameter(_ edges: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func treeDiameter(edges [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def treeDiameter(edges: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun treeDiameter(edges: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn tree_diameter(edges: Vec>) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $edges\n * @return Integer\n */\n function treeDiameter($edges) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function treeDiameter(edges: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (tree-diameter edges)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1245](https://leetcode-cn.com/problems/tree-diameter)", "[\u6811\u7684\u76f4\u5f84](/solution/1200-1299/1245.Tree%20Diameter/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1245](https://leetcode.com/problems/tree-diameter)", "[Tree Diameter](/solution/1200-1299/1245.Tree%20Diameter/README_EN.md)", "`Tree`,`Depth-first Search`,`Breadth-first Search`", "Medium", "\ud83d\udd12"]}, {"question_id": "1176", "frontend_question_id": "1244", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/design-a-leaderboard", "url_en": "https://leetcode.com/problems/design-a-leaderboard", "relative_path_cn": "/solution/1200-1299/1244.Design%20A%20Leaderboard/README.md", "relative_path_en": "/solution/1200-1299/1244.Design%20A%20Leaderboard/README_EN.md", "title_cn": "\u529b\u6263\u6392\u884c\u699c", "title_en": "Design A Leaderboard", "question_title_slug": "design-a-leaderboard", "content_en": "

    Design a Leaderboard class, which has 3 functions:

    \n\n
      \n\t
    1. addScore(playerId, score): Update the leaderboard by adding score to the given player's score. If there is no player with such id in the leaderboard, add him to the leaderboard with the given score.
    2. \n\t
    3. top(K): Return the score sum of the top K players.
    4. \n\t
    5. reset(playerId): Reset the score of the player with the given id to 0 (in other words erase it from the leaderboard). It is guaranteed that the player was added to the leaderboard before calling this function.
    6. \n
    \n\n

    Initially, the leaderboard is empty.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: \n["Leaderboard","addScore","addScore","addScore","addScore","addScore","top","reset","reset","addScore","top"]\n[[],[1,73],[2,56],[3,39],[4,51],[5,4],[1],[1],[2],[2,51],[3]]\nOutput: \n[null,null,null,null,null,null,73,null,null,null,141]\n\nExplanation: \nLeaderboard leaderboard = new Leaderboard ();\nleaderboard.addScore(1,73);   // leaderboard = [[1,73]];\nleaderboard.addScore(2,56);   // leaderboard = [[1,73],[2,56]];\nleaderboard.addScore(3,39);   // leaderboard = [[1,73],[2,56],[3,39]];\nleaderboard.addScore(4,51);   // leaderboard = [[1,73],[2,56],[3,39],[4,51]];\nleaderboard.addScore(5,4);    // leaderboard = [[1,73],[2,56],[3,39],[4,51],[5,4]];\nleaderboard.top(1);           // returns 73;\nleaderboard.reset(1);         // leaderboard = [[2,56],[3,39],[4,51],[5,4]];\nleaderboard.reset(2);         // leaderboard = [[3,39],[4,51],[5,4]];\nleaderboard.addScore(2,51);   // leaderboard = [[2,51],[3,39],[4,51],[5,4]];\nleaderboard.top(3);           // returns 141 = 51 + 51 + 39;\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= playerId, K <= 10000
    • \n\t
    • It's guaranteed that K is less than or equal to the current number of players.
    • \n\t
    • 1 <= score <= 100
    • \n\t
    • There will be at most 1000 function calls.
    • \n
    \n", "content_cn": "

    \u65b0\u4e00\u8f6e\u7684\u300c\u529b\u6263\u676f\u300d\u7f16\u7a0b\u5927\u8d5b\u5373\u5c06\u542f\u52a8\uff0c\u4e3a\u4e86\u52a8\u6001\u663e\u793a\u53c2\u8d5b\u8005\u7684\u5f97\u5206\u6570\u636e\uff0c\u9700\u8981\u8bbe\u8ba1\u4e00\u4e2a\u6392\u884c\u699c Leaderboard\u3002

    \n\n

    \u8bf7\u4f60\u5e2e\u5fd9\u6765\u8bbe\u8ba1\u8fd9\u4e2a\u00a0Leaderboard \u7c7b\uff0c\u4f7f\u5f97\u5b83\u6709\u5982\u4e0b\u00a03 \u4e2a\u51fd\u6570\uff1a

    \n\n
      \n\t
    1. addScore(playerId, score)\uff1a\n\n\t
        \n\t\t
      • \u5047\u5982\u53c2\u8d5b\u8005\u5df2\u7ecf\u5728\u6392\u884c\u699c\u4e0a\uff0c\u5c31\u7ed9\u4ed6\u7684\u5f53\u524d\u5f97\u5206\u589e\u52a0\u00a0score\u00a0\u70b9\u5206\u503c\u5e76\u66f4\u65b0\u6392\u884c\u3002
      • \n\t\t
      • \u5047\u5982\u8be5\u53c2\u8d5b\u8005\u4e0d\u5728\u6392\u884c\u699c\u4e0a\uff0c\u5c31\u628a\u4ed6\u6dfb\u52a0\u5230\u699c\u5355\u4e0a\uff0c\u5e76\u4e14\u5c06\u5206\u6570\u8bbe\u7f6e\u4e3a\u00a0score\u3002
      • \n\t
      \n\t
    2. \n\t
    3. top(K)\uff1a\u8fd4\u56de\u524d\u00a0K\u00a0\u540d\u53c2\u8d5b\u8005\u7684\u00a0\u5f97\u5206\u603b\u548c\u3002
    4. \n\t
    5. reset(playerId)\uff1a\u5c06\u6307\u5b9a\u53c2\u8d5b\u8005\u7684\u6210\u7ee9\u6e05\u96f6\uff08\u6362\u53e5\u8bdd\u8bf4\uff0c\u5c06\u5176\u4ece\u6392\u884c\u699c\u4e2d\u5220\u9664\uff09\u3002\u9898\u76ee\u4fdd\u8bc1\u5728\u8c03\u7528\u6b64\u51fd\u6570\u524d\uff0c\u8be5\u53c2\u8d5b\u8005\u5df2\u6709\u6210\u7ee9\uff0c\u5e76\u4e14\u5728\u699c\u5355\u4e0a\u3002
    6. \n
    \n\n

    \u8bf7\u6ce8\u610f\uff0c\u5728\u521d\u59cb\u72b6\u6001\u4e0b\uff0c\u6392\u884c\u699c\u662f\u7a7a\u7684\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1a \n[\"Leaderboard\",\"addScore\",\"addScore\",\"addScore\",\"addScore\",\"addScore\",\"top\",\"reset\",\"reset\",\"addScore\",\"top\"]\n[[],[1,73],[2,56],[3,39],[4,51],[5,4],[1],[1],[2],[2,51],[3]]\n\u8f93\u51fa\uff1a\n[null,null,null,null,null,null,73,null,null,null,141]\n\n\u89e3\u91ca\uff1a \nLeaderboard leaderboard = new Leaderboard ();\nleaderboard.addScore(1,73);   // leaderboard = [[1,73]];\nleaderboard.addScore(2,56);   // leaderboard = [[1,73],[2,56]];\nleaderboard.addScore(3,39);   // leaderboard = [[1,73],[2,56],[3,39]];\nleaderboard.addScore(4,51);   // leaderboard = [[1,73],[2,56],[3,39],[4,51]];\nleaderboard.addScore(5,4);    // leaderboard = [[1,73],[2,56],[3,39],[4,51],[5,4]];\nleaderboard.top(1);           // returns 73;\nleaderboard.reset(1);         // leaderboard = [[2,56],[3,39],[4,51],[5,4]];\nleaderboard.reset(2);         // leaderboard = [[3,39],[4,51],[5,4]];\nleaderboard.addScore(2,51);   // leaderboard = [[2,51],[3,39],[4,51],[5,4]];\nleaderboard.top(3);           // returns 141 = 51 + 51 + 39;\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= playerId, K <= 10000
    • \n\t
    • \u9898\u76ee\u4fdd\u8bc1\u00a0K\u00a0\u5c0f\u4e8e\u6216\u7b49\u4e8e\u5f53\u524d\u53c2\u8d5b\u8005\u7684\u6570\u91cf
    • \n\t
    • 1 <= score\u00a0<= 100
    • \n\t
    • \u6700\u591a\u8fdb\u884c\u00a01000\u00a0\u6b21\u51fd\u6570\u8c03\u7528
    • \n
    \n", "tags_en": ["Sort", "Design", "Hash Table"], "tags_cn": ["\u6392\u5e8f", "\u8bbe\u8ba1", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Leaderboard {\npublic:\n Leaderboard() {\n\n }\n \n void addScore(int playerId, int score) {\n\n }\n \n int top(int K) {\n\n }\n \n void reset(int playerId) {\n\n }\n};\n\n/**\n * Your Leaderboard object will be instantiated and called as such:\n * Leaderboard* obj = new Leaderboard();\n * obj->addScore(playerId,score);\n * int param_2 = obj->top(K);\n * obj->reset(playerId);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Leaderboard {\n\n public Leaderboard() {\n\n }\n \n public void addScore(int playerId, int score) {\n\n }\n \n public int top(int K) {\n\n }\n \n public void reset(int playerId) {\n\n }\n}\n\n/**\n * Your Leaderboard object will be instantiated and called as such:\n * Leaderboard obj = new Leaderboard();\n * obj.addScore(playerId,score);\n * int param_2 = obj.top(K);\n * obj.reset(playerId);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Leaderboard(object):\n\n def __init__(self):\n\n\n def addScore(self, playerId, score):\n \"\"\"\n :type playerId: int\n :type score: int\n :rtype: None\n \"\"\"\n\n\n def top(self, K):\n \"\"\"\n :type K: int\n :rtype: int\n \"\"\"\n\n\n def reset(self, playerId):\n \"\"\"\n :type playerId: int\n :rtype: None\n \"\"\"\n\n\n\n# Your Leaderboard object will be instantiated and called as such:\n# obj = Leaderboard()\n# obj.addScore(playerId,score)\n# param_2 = obj.top(K)\n# obj.reset(playerId)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Leaderboard:\n\n def __init__(self):\n\n\n def addScore(self, playerId: int, score: int) -> None:\n\n\n def top(self, K: int) -> int:\n\n\n def reset(self, playerId: int) -> None:\n\n\n\n# Your Leaderboard object will be instantiated and called as such:\n# obj = Leaderboard()\n# obj.addScore(playerId,score)\n# param_2 = obj.top(K)\n# obj.reset(playerId)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} Leaderboard;\n\n\nLeaderboard* leaderboardCreate() {\n\n}\n\nvoid leaderboardAddScore(Leaderboard* obj, int playerId, int score) {\n\n}\n\nint leaderboardTop(Leaderboard* obj, int K) {\n\n}\n\nvoid leaderboardReset(Leaderboard* obj, int playerId) {\n\n}\n\nvoid leaderboardFree(Leaderboard* obj) {\n\n}\n\n/**\n * Your Leaderboard struct will be instantiated and called as such:\n * Leaderboard* obj = leaderboardCreate();\n * leaderboardAddScore(obj, playerId, score);\n \n * int param_2 = leaderboardTop(obj, K);\n \n * leaderboardReset(obj, playerId);\n \n * leaderboardFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Leaderboard {\n\n public Leaderboard() {\n\n }\n \n public void AddScore(int playerId, int score) {\n\n }\n \n public int Top(int K) {\n\n }\n \n public void Reset(int playerId) {\n\n }\n}\n\n/**\n * Your Leaderboard object will be instantiated and called as such:\n * Leaderboard obj = new Leaderboard();\n * obj.AddScore(playerId,score);\n * int param_2 = obj.Top(K);\n * obj.Reset(playerId);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "\nvar Leaderboard = function() {\n\n};\n\n/** \n * @param {number} playerId \n * @param {number} score\n * @return {void}\n */\nLeaderboard.prototype.addScore = function(playerId, score) {\n\n};\n\n/** \n * @param {number} K\n * @return {number}\n */\nLeaderboard.prototype.top = function(K) {\n\n};\n\n/** \n * @param {number} playerId\n * @return {void}\n */\nLeaderboard.prototype.reset = function(playerId) {\n\n};\n\n/**\n * Your Leaderboard object will be instantiated and called as such:\n * var obj = new Leaderboard()\n * obj.addScore(playerId,score)\n * var param_2 = obj.top(K)\n * obj.reset(playerId)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class Leaderboard\n def initialize()\n\n end\n\n\n=begin\n :type player_id: Integer\n :type score: Integer\n :rtype: Void\n=end\n def add_score(player_id, score)\n\n end\n\n\n=begin\n :type k: Integer\n :rtype: Integer\n=end\n def top(k)\n\n end\n\n\n=begin\n :type player_id: Integer\n :rtype: Void\n=end\n def reset(player_id)\n\n end\n\n\nend\n\n# Your Leaderboard object will be instantiated and called as such:\n# obj = Leaderboard.new()\n# obj.add_score(player_id, score)\n# param_2 = obj.top(k)\n# obj.reset(player_id)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass Leaderboard {\n\n init() {\n \n }\n \n func addScore(_ playerId: Int, _ score: Int) {\n \n }\n \n func top(_ K: Int) -> Int {\n \n }\n \n func reset(_ playerId: Int) {\n \n }\n}\n\n/**\n * Your Leaderboard object will be instantiated and called as such:\n * let obj = Leaderboard()\n * obj.addScore(playerId, score)\n * let ret_2: Int = obj.top(K)\n * obj.reset(playerId)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type Leaderboard struct {\n\n}\n\n\nfunc Constructor() Leaderboard {\n\n}\n\n\nfunc (this *Leaderboard) AddScore(playerId int, score int) {\n\n}\n\n\nfunc (this *Leaderboard) Top(K int) int {\n\n}\n\n\nfunc (this *Leaderboard) Reset(playerId int) {\n\n}\n\n\n/**\n * Your Leaderboard object will be instantiated and called as such:\n * obj := Constructor();\n * obj.AddScore(playerId,score);\n * param_2 := obj.Top(K);\n * obj.Reset(playerId);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class Leaderboard() {\n\n def addScore(playerId: Int, score: Int) {\n\n }\n\n def top(K: Int): Int = {\n\n }\n\n def reset(playerId: Int) {\n\n }\n\n}\n\n/**\n * Your Leaderboard object will be instantiated and called as such:\n * var obj = new Leaderboard()\n * obj.addScore(playerId,score)\n * var param_2 = obj.top(K)\n * obj.reset(playerId)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Leaderboard() {\n\n fun addScore(playerId: Int, score: Int) {\n\n }\n\n fun top(K: Int): Int {\n\n }\n\n fun reset(playerId: Int) {\n\n }\n\n}\n\n/**\n * Your Leaderboard object will be instantiated and called as such:\n * var obj = Leaderboard()\n * obj.addScore(playerId,score)\n * var param_2 = obj.top(K)\n * obj.reset(playerId)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct Leaderboard {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl Leaderboard {\n\n fn new() -> Self {\n\n }\n \n fn add_score(&self, player_id: i32, score: i32) {\n\n }\n \n fn top(&self, k: i32) -> i32 {\n\n }\n \n fn reset(&self, player_id: i32) {\n\n }\n}\n\n/**\n * Your Leaderboard object will be instantiated and called as such:\n * let obj = Leaderboard::new();\n * obj.add_score(playerId, score);\n * let ret_2: i32 = obj.top(K);\n * obj.reset(playerId);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Leaderboard {\n /**\n */\n function __construct() {\n\n }\n\n /**\n * @param Integer $playerId\n * @param Integer $score\n * @return NULL\n */\n function addScore($playerId, $score) {\n\n }\n\n /**\n * @param Integer $K\n * @return Integer\n */\n function top($K) {\n\n }\n\n /**\n * @param Integer $playerId\n * @return NULL\n */\n function reset($playerId) {\n\n }\n}\n\n/**\n * Your Leaderboard object will be instantiated and called as such:\n * $obj = Leaderboard();\n * $obj->addScore($playerId, $score);\n * $ret_2 = $obj->top($K);\n * $obj->reset($playerId);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class Leaderboard {\n constructor() {\n\n }\n\n addScore(playerId: number, score: number): void {\n\n }\n\n top(K: number): number {\n\n }\n\n reset(playerId: number): void {\n\n }\n}\n\n/**\n * Your Leaderboard object will be instantiated and called as such:\n * var obj = new Leaderboard()\n * obj.addScore(playerId,score)\n * var param_2 = obj.top(K)\n * obj.reset(playerId)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define leaderboard%\n (class object%\n (super-new)\n (init-field)\n \n ; add-score : exact-integer? exact-integer? -> void?\n (define/public (add-score playerId score)\n\n )\n ; top : exact-integer? -> exact-integer?\n (define/public (top K)\n\n )\n ; reset : exact-integer? -> void?\n (define/public (reset playerId)\n\n )))\n\n;; Your leaderboard% object will be instantiated and called as such:\n;; (define obj (new leaderboard%))\n;; (send obj add-score player-id score)\n;; (define param_2 (send obj top k))\n;; (send obj reset player-id)", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1244](https://leetcode-cn.com/problems/design-a-leaderboard)", "[\u529b\u6263\u6392\u884c\u699c](/solution/1200-1299/1244.Design%20A%20Leaderboard/README.md)", "`\u6392\u5e8f`,`\u8bbe\u8ba1`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1244](https://leetcode.com/problems/design-a-leaderboard)", "[Design A Leaderboard](/solution/1200-1299/1244.Design%20A%20Leaderboard/README_EN.md)", "`Sort`,`Design`,`Hash Table`", "Medium", "\ud83d\udd12"]}, {"question_id": "1175", "frontend_question_id": "1243", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/array-transformation", "url_en": "https://leetcode.com/problems/array-transformation", "relative_path_cn": "/solution/1200-1299/1243.Array%20Transformation/README.md", "relative_path_en": "/solution/1200-1299/1243.Array%20Transformation/README_EN.md", "title_cn": "\u6570\u7ec4\u53d8\u6362", "title_en": "Array Transformation", "question_title_slug": "array-transformation", "content_en": "

    Given an initial array arr, every day you produce a new array using the array of the previous day.

    \n\n

    On the i-th day, you do the following operations on the array of day i-1 to produce the array of day i:

    \n\n
      \n\t
    1. If an element is smaller than both its left neighbor and its right neighbor, then this element is incremented.
    2. \n\t
    3. If an element is bigger than both its left neighbor and its right neighbor, then this element is decremented.
    4. \n\t
    5. The first and last elements never change.
    6. \n
    \n\n

    After some days, the array does not change. Return that final array.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr = [6,2,3,4]\nOutput: [6,3,3,4]\nExplanation: \nOn the first day, the array is changed from [6,2,3,4] to [6,3,3,4].\nNo more operations can be done to this array.\n
    \n\n

    Example 2:

    \n\n
    \nInput: arr = [1,6,3,4,3,5]\nOutput: [1,4,4,4,4,5]\nExplanation: \nOn the first day, the array is changed from [1,6,3,4,3,5] to [1,5,4,3,4,5].\nOn the second day, the array is changed from [1,5,4,3,4,5] to [1,4,4,4,4,5].\nNo more operations can be done to this array.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 3 <= arr.length <= 100
    • \n\t
    • 1 <= arr[i] <= 100
    • \n
    \n", "content_cn": "

    \u9996\u5148\uff0c\u7ed9\u4f60\u4e00\u4e2a\u521d\u59cb\u6570\u7ec4 arr\u3002\u7136\u540e\uff0c\u6bcf\u5929\u4f60\u90fd\u8981\u6839\u636e\u524d\u4e00\u5929\u7684\u6570\u7ec4\u751f\u6210\u4e00\u4e2a\u65b0\u7684\u6570\u7ec4\u3002

    \n\n

    \u7b2c i \u5929\u6240\u751f\u6210\u7684\u6570\u7ec4\uff0c\u662f\u7531\u4f60\u5bf9\u7b2c i-1 \u5929\u7684\u6570\u7ec4\u8fdb\u884c\u5982\u4e0b\u64cd\u4f5c\u6240\u5f97\u7684\uff1a

    \n\n
      \n\t
    1. \u5047\u5982\u4e00\u4e2a\u5143\u7d20\u5c0f\u4e8e\u5b83\u7684\u5de6\u53f3\u90bb\u5c45\uff0c\u90a3\u4e48\u8be5\u5143\u7d20\u81ea\u589e 1\u3002
    2. \n\t
    3. \u5047\u5982\u4e00\u4e2a\u5143\u7d20\u5927\u4e8e\u5b83\u7684\u5de6\u53f3\u90bb\u5c45\uff0c\u90a3\u4e48\u8be5\u5143\u7d20\u81ea\u51cf 1\u3002
    4. \n\t
    5. \u9996\u3001\u5c3e\u5143\u7d20 \u6c38\u4e0d \u6539\u53d8\u3002
    6. \n
    \n\n

    \u8fc7\u4e9b\u65f6\u65e5\uff0c\u4f60\u4f1a\u53d1\u73b0\u6570\u7ec4\u5c06\u4f1a\u4e0d\u518d\u53d1\u751f\u53d8\u5316\uff0c\u8bf7\u8fd4\u56de\u6700\u7ec8\u6240\u5f97\u5230\u7684\u6570\u7ec4\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a[6,2,3,4]\n\u8f93\u51fa\uff1a[6,3,3,4]\n\u89e3\u91ca\uff1a\n\u7b2c\u4e00\u5929\uff0c\u6570\u7ec4\u4ece [6,2,3,4] \u53d8\u4e3a [6,3,3,4]\u3002\n\u65e0\u6cd5\u518d\u5bf9\u8be5\u6570\u7ec4\u8fdb\u884c\u66f4\u591a\u64cd\u4f5c\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a[1,6,3,4,3,5]\n\u8f93\u51fa\uff1a[1,4,4,4,4,5]\n\u89e3\u91ca\uff1a\n\u7b2c\u4e00\u5929\uff0c\u6570\u7ec4\u4ece [1,6,3,4,3,5] \u53d8\u4e3a [1,5,4,3,4,5]\u3002\n\u7b2c\u4e8c\u5929\uff0c\u6570\u7ec4\u4ece [1,5,4,3,4,5] \u53d8\u4e3a [1,4,4,4,4,5]\u3002\n\u65e0\u6cd5\u518d\u5bf9\u8be5\u6570\u7ec4\u8fdb\u884c\u66f4\u591a\u64cd\u4f5c\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= arr.length <= 100
    2. \n\t
    3. 1 <= arr[i] <= 100
    4. \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector transformArray(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List transformArray(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def transformArray(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def transformArray(self, arr: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* transformArray(int* arr, int arrSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList TransformArray(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number[]}\n */\nvar transformArray = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer[]}\ndef transform_array(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func transformArray(_ arr: [Int]) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func transformArray(arr []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def transformArray(arr: Array[Int]): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun transformArray(arr: IntArray): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn transform_array(arr: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer[]\n */\n function transformArray($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function transformArray(arr: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (transform-array arr)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1243](https://leetcode-cn.com/problems/array-transformation)", "[\u6570\u7ec4\u53d8\u6362](/solution/1200-1299/1243.Array%20Transformation/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1243](https://leetcode.com/problems/array-transformation)", "[Array Transformation](/solution/1200-1299/1243.Array%20Transformation/README_EN.md)", "`Array`", "Easy", "\ud83d\udd12"]}, {"question_id": "1174", "frontend_question_id": "1084", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/sales-analysis-iii", "url_en": "https://leetcode.com/problems/sales-analysis-iii", "relative_path_cn": "/solution/1000-1099/1084.Sales%20Analysis%20III/README.md", "relative_path_en": "/solution/1000-1099/1084.Sales%20Analysis%20III/README_EN.md", "title_cn": "\u9500\u552e\u5206\u6790III", "title_en": "Sales Analysis III", "question_title_slug": "sales-analysis-iii", "content_en": "

    Table: Product

    \n\n
    \n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| product_id   | int     |\n| product_name | varchar |\n| unit_price   | int     |\n+--------------+---------+\nproduct_id is the primary key of this table.\n
    \n\n

    Table: Sales

    \n\n
    \n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| seller_id   | int     |\n| product_id  | int     |\n| buyer_id    | int     |\n| sale_date   | date    |\n| quantity    | int     |\n| price       | int     |\n+------ ------+---------+\nThis table has no primary key, it can have repeated rows.\nproduct_id is a foreign key to Product table.\n
    \n\n

     

    \n\n

    Write an SQL query that reports the products that were only sold in spring 2019. That is, between 2019-01-01 and 2019-03-31 inclusive.

    \n\n

    The query result format is in the following example:

    \n\n
    \nProduct table:\n+------------+--------------+------------+\n| product_id | product_name | unit_price |\n+------------+--------------+------------+\n| 1          | S8           | 1000       |\n| 2          | G4           | 800        |\n| 3          | iPhone       | 1400       |\n+------------+--------------+------------+\n\nSales table:\n+-----------+------------+----------+------------+----------+-------+\n| seller_id | product_id | buyer_id | sale_date  | quantity | price |\n+-----------+------------+----------+------------+----------+-------+\n| 1         | 1          | 1        | 2019-01-21 | 2        | 2000  |\n| 1         | 2          | 2        | 2019-02-17 | 1        | 800   |\n| 2         | 2          | 3        | 2019-06-02 | 1        | 800   |\n| 3         | 3          | 4        | 2019-05-13 | 2        | 2800  |\n+-----------+------------+----------+------------+----------+-------+\n\nResult table:\n+-------------+--------------+\n| product_id  | product_name |\n+-------------+--------------+\n| 1           | S8           |\n+-------------+--------------+\nThe product with id 1 was only sold in spring 2019 while the other two were sold after.
    \n", "content_cn": "

    Table: Product

    \n\n
    +--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| product_id   | int     |\n| product_name | varchar |\n| unit_price   | int     |\n+--------------+---------+\nproduct_id \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\n
    \n\n

    Table: Sales

    \n\n
    +-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| seller_id   | int     |\n| product_id  | int     |\n| buyer_id    | int     |\n| sale_date   | date    |\n| quantity    | int     |\n| price       | int     |\n+------ ------+---------+\n\u8fd9\u4e2a\u8868\u6ca1\u6709\u4e3b\u952e\uff0c\u5b83\u53ef\u4ee5\u6709\u91cd\u590d\u7684\u884c.\nproduct_id \u662f Product \u8868\u7684\u5916\u952e.
    \n\n

     

    \n\n

    \u7f16\u5199\u4e00\u4e2aSQL\u67e5\u8be2\uff0c\u62a5\u544a2019\u5e74\u6625\u5b63\u624d\u552e\u51fa\u7684\u4ea7\u54c1\u3002\u5373\u4ec5\u57282019-01-01\u81f32019-03-31\uff08\u542b\uff09\u4e4b\u95f4\u51fa\u552e\u7684\u5546\u54c1\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u6240\u793a\uff1a

    \n\n
    Product table:\n+------------+--------------+------------+\n| product_id | product_name | unit_price |\n+------------+--------------+------------+\n| 1          | S8           | 1000       |\n| 2          | G4           | 800        |\n| 3          | iPhone       | 1400       |\n+------------+--------------+------------+\n\nSales table:\n+-----------+------------+----------+------------+----------+-------+\n| seller_id | product_id | buyer_id | sale_date  | quantity | price |\n+-----------+------------+----------+------------+----------+-------+\n| 1         | 1          | 1        | 2019-01-21 | 2        | 2000  |\n| 1         | 2          | 2        | 2019-02-17 | 1        | 800   |\n| 2         | 2          | 3        | 2019-06-02 | 1        | 800   |\n| 3         | 3          | 4        | 2019-05-13 | 2        | 2800  |\n+-----------+------------+----------+------------+----------+-------+\n\nResult table:\n+-------------+--------------+\n| product_id  | product_name |\n+-------------+--------------+\n| 1           | S8           |\n+-------------+--------------+\nid\u4e3a1\u7684\u4ea7\u54c1\u4ec5\u57282019\u5e74\u6625\u5b63\u9500\u552e\uff0c\u5176\u4ed6\u4e24\u4e2a\u4ea7\u54c1\u5728\u4e4b\u540e\u9500\u552e\u3002
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1084](https://leetcode-cn.com/problems/sales-analysis-iii)", "[\u9500\u552e\u5206\u6790III](/solution/1000-1099/1084.Sales%20Analysis%20III/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1084](https://leetcode.com/problems/sales-analysis-iii)", "[Sales Analysis III](/solution/1000-1099/1084.Sales%20Analysis%20III/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1173", "frontend_question_id": "1083", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/sales-analysis-ii", "url_en": "https://leetcode.com/problems/sales-analysis-ii", "relative_path_cn": "/solution/1000-1099/1083.Sales%20Analysis%20II/README.md", "relative_path_en": "/solution/1000-1099/1083.Sales%20Analysis%20II/README_EN.md", "title_cn": "\u9500\u552e\u5206\u6790 II", "title_en": "Sales Analysis II", "question_title_slug": "sales-analysis-ii", "content_en": "

    Table: Product

    \r\n\r\n
    \r\n+--------------+---------+\r\n| Column Name  | Type    |\r\n+--------------+---------+\r\n| product_id   | int     |\r\n| product_name | varchar |\r\n| unit_price   | int     |\r\n+--------------+---------+\r\nproduct_id is the primary key of this table.\r\n
    \r\n\r\n

    Table: Sales

    \r\n\r\n
    \r\n+-------------+---------+\r\n| Column Name | Type    |\r\n+-------------+---------+\r\n| seller_id   | int     |\r\n| product_id  | int     |\r\n| buyer_id    | int     |\r\n| sale_date   | date    |\r\n| quantity    | int     |\r\n| price       | int     |\r\n+------ ------+---------+\r\nThis table has no primary key, it can have repeated rows.\r\nproduct_id is a foreign key to Product table.\r\n
    \r\n\r\n

     

    \r\n\r\n

    Write an SQL query that reports the buyers who have bought S8 but not iPhone. Note that S8 and iPhone are products present in the Product table.

    \r\n\r\n

    The query result format is in the following example:

    \r\n\r\n
    \r\nProduct table:\r\n+------------+--------------+------------+\r\n| product_id | product_name | unit_price |\r\n+------------+--------------+------------+\r\n| 1          | S8           | 1000       |\r\n| 2          | G4           | 800        |\r\n| 3          | iPhone       | 1400       |\r\n+------------+--------------+------------+\r\n\r\nSales table:\r\n+-----------+------------+----------+------------+----------+-------+\r\n| seller_id | product_id | buyer_id | sale_date  | quantity | price |\r\n+-----------+------------+----------+------------+----------+-------+\r\n| 1         | 1          | 1        | 2019-01-21 | 2        | 2000  |\r\n| 1         | 2          | 2        | 2019-02-17 | 1        | 800   |\r\n| 2         | 1          | 3        | 2019-06-02 | 1        | 800   |\r\n| 3         | 3          | 3        | 2019-05-13 | 2        | 2800  |\r\n+-----------+------------+----------+------------+----------+-------+\r\n\r\nResult table:\r\n+-------------+\r\n| buyer_id    |\r\n+-------------+\r\n| 1           |\r\n+-------------+\r\nThe buyer with id 1 bought an S8 but didn't buy an iPhone. The buyer with id 3 bought both.
    \r\n", "content_cn": "

    Table: Product

    \n\n
    +--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| product_id   | int     |\n| product_name | varchar |\n| unit_price   | int     |\n+--------------+---------+\nproduct_id \u662f\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\n
    \n\n

    Table: Sales

    \n\n
    +-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| seller_id   | int     |\n| product_id  | int     |\n| buyer_id    | int     |\n| sale_date   | date    |\n| quantity    | int     |\n| price       | int     |\n+------ ------+---------+\n\u8fd9\u4e2a\u8868\u6ca1\u6709\u4e3b\u952e\uff0c\u5b83\u53ef\u4ee5\u6709\u91cd\u590d\u7684\u884c.\nproduct_id \u662f Product \u8868\u7684\u5916\u952e.\n
    \n\n

    \u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\uff0c\u67e5\u8be2\u8d2d\u4e70\u4e86 S8 \u624b\u673a\u5374\u6ca1\u6709\u8d2d\u4e70 iPhone \u7684\u4e70\u5bb6\u3002\u6ce8\u610f\u8fd9\u91cc S8 \u548c iPhone \u662f Product \u8868\u4e2d\u7684\u4ea7\u54c1\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u56fe\u8868\u793a\uff1a

    \n\n
    Product table:\n+------------+--------------+------------+\n| product_id | product_name | unit_price |\n+------------+--------------+------------+\n| 1          | S8           | 1000       |\n| 2          | G4           | 800        |\n| 3          | iPhone       | 1400       |\n+------------+--------------+------------+\n\nSales table:\n+-----------+------------+----------+------------+----------+-------+\n| seller_id | product_id | buyer_id | sale_date  | quantity | price |\n+-----------+------------+----------+------------+----------+-------+\n| 1         | 1          | 1        | 2019-01-21 | 2        | 2000  |\n| 1         | 2          | 2        | 2019-02-17 | 1        | 800   |\n| 2         | 1          | 3        | 2019-06-02 | 1        | 800   |\n| 3         | 3          | 3        | 2019-05-13 | 2        | 2800  |\n+-----------+------------+----------+------------+----------+-------+\n\nResult table:\n+-------------+\n| buyer_id    |\n+-------------+\n| 1           |\n+-------------+\nid \u4e3a 1 \u7684\u4e70\u5bb6\u8d2d\u4e70\u4e86\u4e00\u90e8 S8\uff0c\u4f46\u662f\u5374\u6ca1\u6709\u8d2d\u4e70 iPhone\uff0c\u800c id \u4e3a 3 \u7684\u4e70\u5bb6\u5374\u540c\u65f6\u8d2d\u4e70\u4e86\u8fd9 2 \u90e8\u624b\u673a\u3002\n\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1083](https://leetcode-cn.com/problems/sales-analysis-ii)", "[\u9500\u552e\u5206\u6790 II](/solution/1000-1099/1083.Sales%20Analysis%20II/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1083](https://leetcode.com/problems/sales-analysis-ii)", "[Sales Analysis II](/solution/1000-1099/1083.Sales%20Analysis%20II/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1172", "frontend_question_id": "1082", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/sales-analysis-i", "url_en": "https://leetcode.com/problems/sales-analysis-i", "relative_path_cn": "/solution/1000-1099/1082.Sales%20Analysis%20I/README.md", "relative_path_en": "/solution/1000-1099/1082.Sales%20Analysis%20I/README_EN.md", "title_cn": "\u9500\u552e\u5206\u6790 I ", "title_en": "Sales Analysis I", "question_title_slug": "sales-analysis-i", "content_en": "

    Table: Product

    \n\n
    \n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| product_id   | int     |\n| product_name | varchar |\n| unit_price   | int     |\n+--------------+---------+\nproduct_id is the primary key of this table.\n
    \n\n

    Table: Sales

    \n\n
    \n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| seller_id   | int     |\n| product_id  | int     |\n| buyer_id    | int     |\n| sale_date   | date    |\n| quantity    | int     |\n| price       | int     |\n+------ ------+---------+\nThis table has no primary key, it can have repeated rows.\nproduct_id is a foreign key to Product table.\n
    \n\n

     

    \n\n

    Write an SQL query that reports the best seller by total sales price, If there is a tie, report them all.

    \n\n

    The query result format is in the following example:

    \n\n
    \nProduct table:\n+------------+--------------+------------+\n| product_id | product_name | unit_price |\n+------------+--------------+------------+\n| 1          | S8           | 1000       |\n| 2          | G4           | 800        |\n| 3          | iPhone       | 1400       |\n+------------+--------------+------------+\n\nSales table:\n+-----------+------------+----------+------------+----------+-------+\n| seller_id | product_id | buyer_id | sale_date  | quantity | price |\n+-----------+------------+----------+------------+----------+-------+\n| 1         | 1          | 1        | 2019-01-21 | 2        | 2000  |\n| 1         | 2          | 2        | 2019-02-17 | 1        | 800   |\n| 2         | 2          | 3        | 2019-06-02 | 1        | 800   |\n| 3         | 3          | 4        | 2019-05-13 | 2        | 2800  |\n+-----------+------------+----------+------------+----------+-------+\n\nResult table:\n+-------------+\n| seller_id   |\n+-------------+\n| 1           |\n| 3           |\n+-------------+\nBoth sellers with id 1 and 3 sold products with the most total price of 2800.
    \n", "content_cn": "

    \u4ea7\u54c1\u8868\uff1aProduct

    \n\n
    +--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| product_id   | int     |\n| product_name | varchar |\n| unit_price   | int     |\n+--------------+---------+\nproduct_id \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e.\n
    \n\n

    \u9500\u552e\u8868\uff1aSales

    \n\n
    +-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| seller_id   | int     |\n| product_id  | int     |\n| buyer_id    | int     |\n| sale_date   | date    |\n| quantity    | int     |\n| price       | int     |\n+------ ------+---------+\n\u8fd9\u4e2a\u8868\u6ca1\u6709\u4e3b\u952e\uff0c\u5b83\u53ef\u4ee5\u6709\u91cd\u590d\u7684\u884c.\nproduct_id \u662f Product \u8868\u7684\u5916\u952e.\n
    \n\n

     

    \n\n

    \u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\uff0c\u67e5\u8be2\u603b\u9500\u552e\u989d\u6700\u9ad8\u7684\u9500\u552e\u8005\uff0c\u5982\u679c\u6709\u5e76\u5217\u7684\uff0c\u5c31\u90fd\u5c55\u793a\u51fa\u6765\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u6240\u793a\uff1a

    \n\n
    Product \u8868\uff1a\n+------------+--------------+------------+\n| product_id | product_name | unit_price |\n+------------+--------------+------------+\n| 1          | S8           | 1000       |\n| 2          | G4           | 800        |\n| 3          | iPhone       | 1400       |\n+------------+--------------+------------+\n\nSales \u8868\uff1a\n+-----------+------------+----------+------------+----------+-------+\n| seller_id | product_id | buyer_id | sale_date  | quantity | price |\n+-----------+------------+----------+------------+----------+-------+\n| 1         | 1          | 1        | 2019-01-21 | 2        | 2000  |\n| 1         | 2          | 2        | 2019-02-17 | 1        | 800   |\n| 2         | 2          | 3        | 2019-06-02 | 1        | 800   |\n| 3         | 3          | 4        | 2019-05-13 | 2        | 2800  |\n+-----------+------------+----------+------------+----------+-------+\n\nResult \u8868\uff1a\n+-------------+\n| seller_id   |\n+-------------+\n| 1           |\n| 3           |\n+-------------+\nId \u4e3a 1 \u548c 3 \u7684\u9500\u552e\u8005\uff0c\u9500\u552e\u603b\u91d1\u989d\u90fd\u4e3a\u6700\u9ad8\u7684 2800\u3002
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1082](https://leetcode-cn.com/problems/sales-analysis-i)", "[\u9500\u552e\u5206\u6790 I ](/solution/1000-1099/1082.Sales%20Analysis%20I/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1082](https://leetcode.com/problems/sales-analysis-i)", "[Sales Analysis I](/solution/1000-1099/1082.Sales%20Analysis%20I/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1171", "frontend_question_id": "1091", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/shortest-path-in-binary-matrix", "url_en": "https://leetcode.com/problems/shortest-path-in-binary-matrix", "relative_path_cn": "/solution/1000-1099/1091.Shortest%20Path%20in%20Binary%20Matrix/README.md", "relative_path_en": "/solution/1000-1099/1091.Shortest%20Path%20in%20Binary%20Matrix/README_EN.md", "title_cn": "\u4e8c\u8fdb\u5236\u77e9\u9635\u4e2d\u7684\u6700\u77ed\u8def\u5f84", "title_en": "Shortest Path in Binary Matrix", "question_title_slug": "shortest-path-in-binary-matrix", "content_en": "

    Given an n x n binary matrix grid, return the length of the shortest clear path in the matrix. If there is no clear path, return -1.

    \n\n

    A clear path in a binary matrix is a path from the top-left cell (i.e., (0, 0)) to the bottom-right cell (i.e., (n - 1, n - 1)) such that:

    \n\n
      \n\t
    • All the visited cells of the path are 0.
    • \n\t
    • All the adjacent cells of the path are 8-directionally connected (i.e., they are different and they share an edge or a corner).
    • \n
    \n\n

    The length of a clear path is the number of visited cells of this path.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: grid = [[0,1],[1,0]]\nOutput: 2\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: grid = [[0,0,0],[1,1,0],[1,1,0]]\nOutput: 4\n
    \n\n

    Example 3:

    \n\n
    \nInput: grid = [[1,0,0],[1,1,0],[1,1,0]]\nOutput: -1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= n <= 100
    • \n\t
    • grid[i][j] is 0 or 1
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a n x n \u7684\u4e8c\u8fdb\u5236\u77e9\u9635 grid \u4e2d\uff0c\u8fd4\u56de\u77e9\u9635\u4e2d\u6700\u77ed \u7545\u901a\u8def\u5f84 \u7684\u957f\u5ea6\u3002\u5982\u679c\u4e0d\u5b58\u5728\u8fd9\u6837\u7684\u8def\u5f84\uff0c\u8fd4\u56de -1 \u3002

    \n\n

    \u4e8c\u8fdb\u5236\u77e9\u9635\u4e2d\u7684 \u7545\u901a\u8def\u5f84 \u662f\u4e00\u6761\u4ece \u5de6\u4e0a\u89d2 \u5355\u5143\u683c\uff08\u5373\uff0c(0, 0)\uff09\u5230 \u53f3\u4e0b\u89d2 \u5355\u5143\u683c\uff08\u5373\uff0c(n - 1, n - 1)\uff09\u7684\u8def\u5f84\uff0c\u8be5\u8def\u5f84\u540c\u65f6\u6ee1\u8db3\u4e0b\u8ff0\u8981\u6c42\uff1a

    \n\n
      \n\t
    • \u8def\u5f84\u9014\u7ecf\u7684\u6240\u6709\u5355\u5143\u683c\u90fd\u7684\u503c\u90fd\u662f 0 \u3002
    • \n\t
    • \u8def\u5f84\u4e2d\u6240\u6709\u76f8\u90bb\u7684\u5355\u5143\u683c\u5e94\u5f53\u5728 8 \u4e2a\u65b9\u5411\u4e4b\u4e00 \u4e0a\u8fde\u901a\uff08\u5373\uff0c\u76f8\u90bb\u4e24\u5355\u5143\u4e4b\u95f4\u5f7c\u6b64\u4e0d\u540c\u4e14\u5171\u4eab\u4e00\u6761\u8fb9\u6216\u8005\u4e00\u4e2a\u89d2\uff09\u3002
    • \n
    \n\n

    \u7545\u901a\u8def\u5f84\u7684\u957f\u5ea6 \u662f\u8be5\u8def\u5f84\u9014\u7ecf\u7684\u5355\u5143\u683c\u603b\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1agrid = [[0,1],[1,0]]\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1agrid = [[0,0,0],[1,1,0],[1,1,0]]\n\u8f93\u51fa\uff1a4\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1agrid = [[1,0,0],[1,1,0],[1,1,0]]\n\u8f93\u51fa\uff1a-1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= n <= 100
    • \n\t
    • grid[i][j] \u4e3a 0 \u6216 1
    • \n
    \n", "tags_en": ["Breadth-first Search"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int shortestPathBinaryMatrix(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int shortestPathBinaryMatrix(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def shortestPathBinaryMatrix(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def shortestPathBinaryMatrix(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint shortestPathBinaryMatrix(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ShortestPathBinaryMatrix(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar shortestPathBinaryMatrix = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef shortest_path_binary_matrix(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func shortestPathBinaryMatrix(_ grid: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func shortestPathBinaryMatrix(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def shortestPathBinaryMatrix(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun shortestPathBinaryMatrix(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn shortest_path_binary_matrix(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function shortestPathBinaryMatrix($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function shortestPathBinaryMatrix(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (shortest-path-binary-matrix grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1091](https://leetcode-cn.com/problems/shortest-path-in-binary-matrix)", "[\u4e8c\u8fdb\u5236\u77e9\u9635\u4e2d\u7684\u6700\u77ed\u8def\u5f84](/solution/1000-1099/1091.Shortest%20Path%20in%20Binary%20Matrix/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1091](https://leetcode.com/problems/shortest-path-in-binary-matrix)", "[Shortest Path in Binary Matrix](/solution/1000-1099/1091.Shortest%20Path%20in%20Binary%20Matrix/README_EN.md)", "`Breadth-first Search`", "Medium", ""]}, {"question_id": "1170", "frontend_question_id": "1092", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/shortest-common-supersequence", "url_en": "https://leetcode.com/problems/shortest-common-supersequence", "relative_path_cn": "/solution/1000-1099/1092.Shortest%20Common%20Supersequence/README.md", "relative_path_en": "/solution/1000-1099/1092.Shortest%20Common%20Supersequence/README_EN.md", "title_cn": "\u6700\u77ed\u516c\u5171\u8d85\u5e8f\u5217", "title_en": "Shortest Common Supersequence", "question_title_slug": "shortest-common-supersequence", "content_en": "

    Given two strings str1 and str2, return the shortest string that has both str1 and str2 as subsequences.  If multiple answers exist, you may return any of them.

    \n\n

    (A string S is a subsequence of string T if deleting some number of characters from T (possibly 0, and the characters are chosen anywhere from T) results in the string S.)

    \n\n

     

    \n\n

    Example 1:

    \n\n
    \nInput: str1 = "abac", str2 = "cab"\nOutput: "cabac"\nExplanation: \nstr1 = "abac" is a subsequence of "cabac" because we can delete the first "c".\nstr2 = "cab" is a subsequence of "cabac" because we can delete the last "ac".\nThe answer provided is the shortest such string that satisfies these properties.\n
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    1. 1 <= str1.length, str2.length <= 1000
    2. \n\t
    3. str1 and str2 consist of lowercase English letters.
    4. \n
    \n", "content_cn": "

    \u7ed9\u51fa\u4e24\u4e2a\u5b57\u7b26\u4e32 str1 \u548c str2\uff0c\u8fd4\u56de\u540c\u65f6\u4ee5 str1 \u548c str2 \u4f5c\u4e3a\u5b50\u5e8f\u5217\u7684\u6700\u77ed\u5b57\u7b26\u4e32\u3002\u5982\u679c\u7b54\u6848\u4e0d\u6b62\u4e00\u4e2a\uff0c\u5219\u53ef\u4ee5\u8fd4\u56de\u6ee1\u8db3\u6761\u4ef6\u7684\u4efb\u610f\u4e00\u4e2a\u7b54\u6848\u3002

    \n\n

    \uff08\u5982\u679c\u4ece\u5b57\u7b26\u4e32 T \u4e2d\u5220\u9664\u4e00\u4e9b\u5b57\u7b26\uff08\u4e5f\u53ef\u80fd\u4e0d\u5220\u9664\uff0c\u5e76\u4e14\u9009\u51fa\u7684\u8fd9\u4e9b\u5b57\u7b26\u53ef\u4ee5\u4f4d\u4e8e T \u4e2d\u7684 \u4efb\u610f\u4f4d\u7f6e\uff09\uff0c\u53ef\u4ee5\u5f97\u5230\u5b57\u7b26\u4e32 S\uff0c\u90a3\u4e48 S \u5c31\u662f T \u7684\u5b50\u5e8f\u5217\uff09

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1astr1 = "abac", str2 = "cab"\n\u8f93\u51fa\uff1a"cabac"\n\u89e3\u91ca\uff1a\nstr1 = "abac" \u662f "cabac" \u7684\u4e00\u4e2a\u5b50\u4e32\uff0c\u56e0\u4e3a\u6211\u4eec\u53ef\u4ee5\u5220\u53bb "cabac" \u7684\u7b2c\u4e00\u4e2a "c"\u5f97\u5230 "abac"\u3002 \nstr2 = "cab" \u662f "cabac" \u7684\u4e00\u4e2a\u5b50\u4e32\uff0c\u56e0\u4e3a\u6211\u4eec\u53ef\u4ee5\u5220\u53bb "cabac" \u672b\u5c3e\u7684 "ac" \u5f97\u5230 "cab"\u3002\n\u6700\u7ec8\u6211\u4eec\u7ed9\u51fa\u7684\u7b54\u6848\u662f\u6ee1\u8db3\u4e0a\u8ff0\u5c5e\u6027\u7684\u6700\u77ed\u5b57\u7b26\u4e32\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= str1.length, str2.length <= 1000
    2. \n\t
    3. str1 \u548c str2 \u90fd\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\u3002
    4. \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string shortestCommonSupersequence(string str1, string str2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String shortestCommonSupersequence(String str1, String str2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def shortestCommonSupersequence(self, str1, str2):\n \"\"\"\n :type str1: str\n :type str2: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def shortestCommonSupersequence(self, str1: str, str2: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * shortestCommonSupersequence(char * str1, char * str2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ShortestCommonSupersequence(string str1, string str2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} str1\n * @param {string} str2\n * @return {string}\n */\nvar shortestCommonSupersequence = function(str1, str2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} str1\n# @param {String} str2\n# @return {String}\ndef shortest_common_supersequence(str1, str2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func shortestCommonSupersequence(_ str1: String, _ str2: String) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func shortestCommonSupersequence(str1 string, str2 string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def shortestCommonSupersequence(str1: String, str2: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun shortestCommonSupersequence(str1: String, str2: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn shortest_common_supersequence(str1: String, str2: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $str1\n * @param String $str2\n * @return String\n */\n function shortestCommonSupersequence($str1, $str2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function shortestCommonSupersequence(str1: string, str2: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (shortest-common-supersequence str1 str2)\n (-> string? string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1092](https://leetcode-cn.com/problems/shortest-common-supersequence)", "[\u6700\u77ed\u516c\u5171\u8d85\u5e8f\u5217](/solution/1000-1099/1092.Shortest%20Common%20Supersequence/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1092](https://leetcode.com/problems/shortest-common-supersequence)", "[Shortest Common Supersequence](/solution/1000-1099/1092.Shortest%20Common%20Supersequence/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1169", "frontend_question_id": "1090", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/largest-values-from-labels", "url_en": "https://leetcode.com/problems/largest-values-from-labels", "relative_path_cn": "/solution/1000-1099/1090.Largest%20Values%20From%20Labels/README.md", "relative_path_en": "/solution/1000-1099/1090.Largest%20Values%20From%20Labels/README_EN.md", "title_cn": "\u53d7\u6807\u7b7e\u5f71\u54cd\u7684\u6700\u5927\u503c", "title_en": "Largest Values From Labels", "question_title_slug": "largest-values-from-labels", "content_en": "

    We have a set of items: the i-th item has value values[i] and label labels[i].

    \r\n\r\n

    Then, we choose a subset S of these items, such that:

    \r\n\r\n
      \r\n\t
    • |S| <= num_wanted
    • \r\n\t
    • For every label L, the number of items in S with label L is <= use_limit.
    • \r\n
    \r\n\r\n

    Return the largest possible sum of the subset S.

    \r\n\r\n

     

    \r\n\r\n
    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: values = [5,4,3,2,1], labels = [1,1,2,2,3], num_wanted = 3, use_limit = 1\r\nOutput: 9\r\nExplanation: The subset chosen is the first, third, and fifth item.\r\n
    \r\n\r\n
    \r\n

    Example 2:

    \r\n\r\n
    \r\nInput: values = [5,4,3,2,1], labels = [1,3,3,3,2], num_wanted = 3, use_limit = 2\r\nOutput: 12\r\nExplanation: The subset chosen is the first, second, and third item.\r\n
    \r\n\r\n
    \r\n

    Example 3:

    \r\n\r\n
    \r\nInput: values = [9,8,8,7,6], labels = [0,0,0,1,1], num_wanted = 3, use_limit = 1\r\nOutput: 16\r\nExplanation: The subset chosen is the first and fourth item.\r\n
    \r\n\r\n
    \r\n

    Example 4:

    \r\n\r\n
    \r\nInput: values = [9,8,8,7,6], labels = [0,0,0,1,1], num_wanted = 3, use_limit = 2\r\nOutput: 24\r\nExplanation: The subset chosen is the first, second, and fourth item.\r\n
    \r\n\r\n

     

    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    1. 1 <= values.length == labels.length <= 20000
    2. \r\n\t
    3. 0 <= values[i], labels[i] <= 20000
    4. \r\n\t
    5. 1 <= num_wanted, use_limit <= values.length
    6. \r\n
    \r\n
    \r\n
    \r\n
    \r\n
    ", "content_cn": "

    \u6211\u4eec\u6709\u4e00\u4e2a\u9879\u7684\u96c6\u5408\uff0c\u5176\u4e2d\u7b2c i \u9879\u7684\u503c\u4e3a values[i]\uff0c\u6807\u7b7e\u4e3a labels[i]\u3002

    \n\n

    \u6211\u4eec\u4ece\u8fd9\u4e9b\u9879\u4e2d\u9009\u51fa\u4e00\u4e2a\u5b50\u96c6 S\uff0c\u8fd9\u6837\u4e00\u6765\uff1a

    \n\n
      \n\t
    • |S| <= num_wanted
    • \n\t
    • \u5bf9\u4e8e\u4efb\u610f\u7684\u6807\u7b7e L\uff0c\u5b50\u96c6 S \u4e2d\u6807\u7b7e\u4e3a L \u7684\u9879\u7684\u6570\u76ee\u603b\u6ee1\u8db3 <= use_limit\u3002
    • \n
    \n\n

    \u8fd4\u56de\u5b50\u96c6 S \u7684\u6700\u5927\u53ef\u80fd\u7684 \u548c\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1avalues = [5,4,3,2,1], labels = [1,1,2,2,3], num_wanted = 3, use_limit = 1\n\u8f93\u51fa\uff1a9\n\u89e3\u91ca\uff1a\u9009\u51fa\u7684\u5b50\u96c6\u662f\u7b2c\u4e00\u9879\uff0c\u7b2c\u4e09\u9879\u548c\u7b2c\u4e94\u9879\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1avalues = [5,4,3,2,1], labels = [1,3,3,3,2], num_wanted = 3, use_limit = 2\n\u8f93\u51fa\uff1a12\n\u89e3\u91ca\uff1a\u9009\u51fa\u7684\u5b50\u96c6\u662f\u7b2c\u4e00\u9879\uff0c\u7b2c\u4e8c\u9879\u548c\u7b2c\u4e09\u9879\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1avalues = [9,8,8,7,6], labels = [0,0,0,1,1], num_wanted = 3, use_limit = 1\n\u8f93\u51fa\uff1a16\n\u89e3\u91ca\uff1a\u9009\u51fa\u7684\u5b50\u96c6\u662f\u7b2c\u4e00\u9879\u548c\u7b2c\u56db\u9879\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1avalues = [9,8,8,7,6], labels = [0,0,0,1,1], num_wanted = 3, use_limit = 2\n\u8f93\u51fa\uff1a24\n\u89e3\u91ca\uff1a\u9009\u51fa\u7684\u5b50\u96c6\u662f\u7b2c\u4e00\u9879\uff0c\u7b2c\u4e8c\u9879\u548c\u7b2c\u56db\u9879\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= values.length == labels.length <= 20000
    2. \n\t
    3. 0 <= values[i], labels[i] <= 20000
    4. \n\t
    5. 1 <= num_wanted, use_limit <= values.length
    6. \n
    \n", "tags_en": ["Greedy", "Hash Table"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int largestValsFromLabels(vector& values, vector& labels, int num_wanted, int use_limit) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int largestValsFromLabels(int[] values, int[] labels, int num_wanted, int use_limit) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def largestValsFromLabels(self, values, labels, num_wanted, use_limit):\n \"\"\"\n :type values: List[int]\n :type labels: List[int]\n :type num_wanted: int\n :type use_limit: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def largestValsFromLabels(self, values: List[int], labels: List[int], num_wanted: int, use_limit: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint largestValsFromLabels(int* values, int valuesSize, int* labels, int labelsSize, int num_wanted, int use_limit){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LargestValsFromLabels(int[] values, int[] labels, int num_wanted, int use_limit) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} values\n * @param {number[]} labels\n * @param {number} num_wanted\n * @param {number} use_limit\n * @return {number}\n */\nvar largestValsFromLabels = function(values, labels, num_wanted, use_limit) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} values\n# @param {Integer[]} labels\n# @param {Integer} num_wanted\n# @param {Integer} use_limit\n# @return {Integer}\ndef largest_vals_from_labels(values, labels, num_wanted, use_limit)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func largestValsFromLabels(_ values: [Int], _ labels: [Int], _ num_wanted: Int, _ use_limit: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func largestValsFromLabels(values []int, labels []int, num_wanted int, use_limit int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def largestValsFromLabels(values: Array[Int], labels: Array[Int], num_wanted: Int, use_limit: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun largestValsFromLabels(values: IntArray, labels: IntArray, num_wanted: Int, use_limit: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn largest_vals_from_labels(values: Vec, labels: Vec, num_wanted: i32, use_limit: i32) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $values\n * @param Integer[] $labels\n * @param Integer $num_wanted\n * @param Integer $use_limit\n * @return Integer\n */\n function largestValsFromLabels($values, $labels, $num_wanted, $use_limit) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function largestValsFromLabels(values: number[], labels: number[], num_wanted: number, use_limit: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (largest-vals-from-labels values labels num_wanted use_limit)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1090](https://leetcode-cn.com/problems/largest-values-from-labels)", "[\u53d7\u6807\u7b7e\u5f71\u54cd\u7684\u6700\u5927\u503c](/solution/1000-1099/1090.Largest%20Values%20From%20Labels/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1090](https://leetcode.com/problems/largest-values-from-labels)", "[Largest Values From Labels](/solution/1000-1099/1090.Largest%20Values%20From%20Labels/README_EN.md)", "`Greedy`,`Hash Table`", "Medium", ""]}, {"question_id": "1168", "frontend_question_id": "1089", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/duplicate-zeros", "url_en": "https://leetcode.com/problems/duplicate-zeros", "relative_path_cn": "/solution/1000-1099/1089.Duplicate%20Zeros/README.md", "relative_path_en": "/solution/1000-1099/1089.Duplicate%20Zeros/README_EN.md", "title_cn": "\u590d\u5199\u96f6", "title_en": "Duplicate Zeros", "question_title_slug": "duplicate-zeros", "content_en": "

    Given a fixed length array arr of integers, duplicate each occurrence of zero, shifting the remaining elements to the right.

    \r\n\r\n

    Note that elements beyond the length of the original array are not written.

    \r\n\r\n

    Do the above modifications to the input array in place, do not return anything from your function.

    \r\n\r\n

     

    \r\n\r\n

    Example 1:

    \r\n\r\n
    \r\nInput: [1,0,2,3,0,4,5,0]\r\nOutput: null\r\nExplanation: After calling your function, the input array is modified to: [1,0,0,2,3,0,0,4]\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: [1,2,3]\r\nOutput: null\r\nExplanation: After calling your function, the input array is modified to: [1,2,3]\r\n
    \r\n\r\n

     

    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    1. 1 <= arr.length <= 10000
    2. \r\n\t
    3. 0 <= arr[i] <= 9
    4. \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u56fa\u5b9a\u7684\u6574\u6570\u6570\u7ec4 arr\uff0c\u8bf7\u4f60\u5c06\u8be5\u6570\u7ec4\u4e2d\u51fa\u73b0\u7684\u6bcf\u4e2a\u96f6\u90fd\u590d\u5199\u4e00\u904d\uff0c\u5e76\u5c06\u5176\u4f59\u7684\u5143\u7d20\u5411\u53f3\u5e73\u79fb\u3002

    \n\n

    \u6ce8\u610f\uff1a\u8bf7\u4e0d\u8981\u5728\u8d85\u8fc7\u8be5\u6570\u7ec4\u957f\u5ea6\u7684\u4f4d\u7f6e\u5199\u5165\u5143\u7d20\u3002

    \n\n

    \u8981\u6c42\uff1a\u8bf7\u5bf9\u8f93\u5165\u7684\u6570\u7ec4 \u5c31\u5730 \u8fdb\u884c\u4e0a\u8ff0\u4fee\u6539\uff0c\u4e0d\u8981\u4ece\u51fd\u6570\u8fd4\u56de\u4efb\u4f55\u4e1c\u897f\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a[1,0,2,3,0,4,5,0]\n\u8f93\u51fa\uff1anull\n\u89e3\u91ca\uff1a\u8c03\u7528\u51fd\u6570\u540e\uff0c\u8f93\u5165\u7684\u6570\u7ec4\u5c06\u88ab\u4fee\u6539\u4e3a\uff1a[1,0,0,2,3,0,0,4]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a[1,2,3]\n\u8f93\u51fa\uff1anull\n\u89e3\u91ca\uff1a\u8c03\u7528\u51fd\u6570\u540e\uff0c\u8f93\u5165\u7684\u6570\u7ec4\u5c06\u88ab\u4fee\u6539\u4e3a\uff1a[1,2,3]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= arr.length <= 10000
    2. \n\t
    3. 0 <= arr[i] <= 9
    4. \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n void duplicateZeros(vector& arr) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public void duplicateZeros(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def duplicateZeros(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: None Do not return anything, modify arr in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def duplicateZeros(self, arr: List[int]) -> None:\n \"\"\"\n Do not return anything, modify arr in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nvoid duplicateZeros(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public void DuplicateZeros(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {void} Do not return anything, modify arr in-place instead.\n */\nvar duplicateZeros = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Void} Do not return anything, modify arr in-place instead.\ndef duplicate_zeros(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func duplicateZeros(_ arr: inout [Int]) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func duplicateZeros(arr []int) {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def duplicateZeros(arr: Array[Int]): Unit = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun duplicateZeros(arr: IntArray): Unit {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn duplicate_zeros(arr: &mut Vec) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return NULL\n */\n function duplicateZeros(&$arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n Do not return anything, modify arr in-place instead.\n */\nfunction duplicateZeros(arr: number[]): void {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1089](https://leetcode-cn.com/problems/duplicate-zeros)", "[\u590d\u5199\u96f6](/solution/1000-1099/1089.Duplicate%20Zeros/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1089](https://leetcode.com/problems/duplicate-zeros)", "[Duplicate Zeros](/solution/1000-1099/1089.Duplicate%20Zeros/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1167", "frontend_question_id": "1199", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/minimum-time-to-build-blocks", "url_en": "https://leetcode.com/problems/minimum-time-to-build-blocks", "relative_path_cn": "/solution/1100-1199/1199.Minimum%20Time%20to%20Build%20Blocks/README.md", "relative_path_en": "/solution/1100-1199/1199.Minimum%20Time%20to%20Build%20Blocks/README_EN.md", "title_cn": "\u5efa\u9020\u8857\u533a\u7684\u6700\u77ed\u65f6\u95f4", "title_en": "Minimum Time to Build Blocks", "question_title_slug": "minimum-time-to-build-blocks", "content_en": "

    You are given a list of blocks, where blocks[i] = t means that the i-th block needs t units of time to be built. A block can only be built by exactly one worker.

    \n\n

    A worker can either split into two workers (number of workers increases by one) or build a block then go home. Both decisions cost some time.

    \n\n

    The time cost of spliting one worker into two workers is given as an integer split. Note that if two workers split at the same time, they split in parallel so the cost would be split.

    \n\n

    Output the minimum time needed to build all blocks.

    \n\n

    Initially, there is only one worker.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: blocks = [1], split = 1\nOutput: 1\nExplanation: We use 1 worker to build 1 block in 1 time unit.\n
    \n\n

    Example 2:

    \n\n
    \nInput: blocks = [1,2], split = 5\nOutput: 7\nExplanation: We split the worker into 2 workers in 5 time units then assign each of them to a block so the cost is 5 + max(1, 2) = 7.\n
    \n\n

    Example 3:

    \n\n
    \nInput: blocks = [1,2,3], split = 1\nOutput: 4\nExplanation: Split 1 worker into 2, then assign the first worker to the last block and split the second worker into 2.\nThen, use the two unassigned workers to build the first two blocks.\nThe cost is 1 + max(3, 1 + max(1, 2)) = 4.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= blocks.length <= 1000
    • \n\t
    • 1 <= blocks[i] <= 10^5
    • \n\t
    • 1 <= split <= 100
    • \n
    \n", "content_cn": "

    \u4f60\u662f\u4e2a\u57ce\u5e02\u89c4\u5212\u5de5\u4f5c\u8005\uff0c\u624b\u91cc\u8d1f\u8d23\u7ba1\u8f96\u4e00\u7cfb\u5217\u7684\u8857\u533a\u3002\u5728\u8fd9\u4e2a\u8857\u533a\u5217\u8868\u4e2d blocks[i] = t \u610f\u5473\u7740\u7b2c  i \u4e2a\u8857\u533a\u9700\u8981 t \u4e2a\u5355\u4f4d\u7684\u65f6\u95f4\u6765\u5efa\u9020\u3002

    \n\n

    \u7531\u4e8e\u4e00\u4e2a\u8857\u533a\u53ea\u80fd\u7531\u4e00\u4e2a\u5de5\u4eba\u6765\u5b8c\u6210\u5efa\u9020\u3002

    \n\n

    \u6240\u4ee5\uff0c\u4e00\u4e2a\u5de5\u4eba\u8981\u4e48\u9700\u8981\u518d\u53ec\u5524\u4e00\u4e2a\u5de5\u4eba\uff08\u5de5\u4eba\u6570\u589e\u52a0 1\uff09\uff1b\u8981\u4e48\u5efa\u9020\u5b8c\u4e00\u4e2a\u8857\u533a\u540e\u56de\u5bb6\u3002\u8fd9\u4e24\u4e2a\u51b3\u5b9a\u90fd\u9700\u8981\u82b1\u8d39\u4e00\u5b9a\u7684\u65f6\u95f4\u3002

    \n\n

    \u4e00\u4e2a\u5de5\u4eba\u518d\u53ec\u5524\u4e00\u4e2a\u5de5\u4eba\u6240\u82b1\u8d39\u7684\u65f6\u95f4\u7531\u6574\u6570 split \u7ed9\u51fa\u3002

    \n\n

    \u6ce8\u610f\uff1a\u5982\u679c\u4e24\u4e2a\u5de5\u4eba\u540c\u65f6\u53ec\u5524\u522b\u7684\u5de5\u4eba\uff0c\u90a3\u4e48\u4ed6\u4eec\u7684\u884c\u4e3a\u662f\u5e76\u884c\u7684\uff0c\u6240\u4ee5\u65f6\u95f4\u82b1\u8d39\u4ecd\u7136\u662f split\u3002

    \n\n

    \u6700\u5f00\u59cb\u7684\u65f6\u5019\u53ea\u6709 \u4e00\u4e2a \u5de5\u4eba\uff0c\u8bf7\u4f60\u6700\u540e\u8f93\u51fa\u5efa\u9020\u5b8c\u6240\u6709\u8857\u533a\u6240\u9700\u8981\u7684\u6700\u5c11\u65f6\u95f4\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1ablocks = [1], split = 1\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u6211\u4eec\u4f7f\u7528 1 \u4e2a\u5de5\u4eba\u5728 1 \u4e2a\u65f6\u95f4\u5355\u4f4d\u5185\u6765\u5efa\u5b8c 1 \u4e2a\u8857\u533a\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1ablocks = [1,2], split = 5\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\u6211\u4eec\u7528 5 \u4e2a\u65f6\u95f4\u5355\u4f4d\u5c06\u8fd9\u4e2a\u5de5\u4eba\u5206\u88c2\u4e3a 2 \u4e2a\u5de5\u4eba\uff0c\u7136\u540e\u6307\u6d3e\u6bcf\u4e2a\u5de5\u4eba\u5206\u522b\u53bb\u5efa\u9020\u8857\u533a\uff0c\u4ece\u800c\u65f6\u95f4\u82b1\u8d39\u4e3a 5 + max(1, 2) = 7\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1ablocks = [1,2,3], split = 1\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\n\u5c06 1 \u4e2a\u5de5\u4eba\u5206\u88c2\u4e3a 2 \u4e2a\u5de5\u4eba\uff0c\u7136\u540e\u6307\u6d3e\u7b2c\u4e00\u4e2a\u5de5\u4eba\u53bb\u5efa\u9020\u6700\u540e\u4e00\u4e2a\u8857\u533a\uff0c\u5e76\u5c06\u7b2c\u4e8c\u4e2a\u5de5\u4eba\u5206\u88c2\u4e3a 2 \u4e2a\u5de5\u4eba\u3002\n\u7136\u540e\uff0c\u7528\u8fd9\u4e24\u4e2a\u672a\u5206\u6d3e\u7684\u5de5\u4eba\u5206\u522b\u53bb\u5efa\u9020\u524d\u4e24\u4e2a\u8857\u533a\u3002\n\u65f6\u95f4\u82b1\u8d39\u4e3a 1 + max(3, 1 + max(1, 2)) = 4\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= blocks.length <= 1000
    2. \n\t
    3. 1 <= blocks[i] <= 10^5
    4. \n\t
    5. 1 <= split <= 100
    6. \n
    \n", "tags_en": ["Math", "Dynamic Programming"], "tags_cn": ["\u6570\u5b66", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minBuildTime(vector& blocks, int split) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minBuildTime(int[] blocks, int split) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minBuildTime(self, blocks, split):\n \"\"\"\n :type blocks: List[int]\n :type split: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minBuildTime(self, blocks: List[int], split: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minBuildTime(int* blocks, int blocksSize, int split){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinBuildTime(int[] blocks, int split) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} blocks\n * @param {number} split\n * @return {number}\n */\nvar minBuildTime = function(blocks, split) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} blocks\n# @param {Integer} split\n# @return {Integer}\ndef min_build_time(blocks, split)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minBuildTime(_ blocks: [Int], _ split: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minBuildTime(blocks []int, split int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minBuildTime(blocks: Array[Int], split: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minBuildTime(blocks: IntArray, split: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_build_time(blocks: Vec, split: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $blocks\n * @param Integer $split\n * @return Integer\n */\n function minBuildTime($blocks, $split) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minBuildTime(blocks: number[], split: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-build-time blocks split)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1199](https://leetcode-cn.com/problems/minimum-time-to-build-blocks)", "[\u5efa\u9020\u8857\u533a\u7684\u6700\u77ed\u65f6\u95f4](/solution/1100-1199/1199.Minimum%20Time%20to%20Build%20Blocks/README.md)", "`\u6570\u5b66`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1199](https://leetcode.com/problems/minimum-time-to-build-blocks)", "[Minimum Time to Build Blocks](/solution/1100-1199/1199.Minimum%20Time%20to%20Build%20Blocks/README_EN.md)", "`Math`,`Dynamic Programming`", "Hard", "\ud83d\udd12"]}, {"question_id": "1166", "frontend_question_id": "1230", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/toss-strange-coins", "url_en": "https://leetcode.com/problems/toss-strange-coins", "relative_path_cn": "/solution/1200-1299/1230.Toss%20Strange%20Coins/README.md", "relative_path_en": "/solution/1200-1299/1230.Toss%20Strange%20Coins/README_EN.md", "title_cn": "\u629b\u63b7\u786c\u5e01", "title_en": "Toss Strange Coins", "question_title_slug": "toss-strange-coins", "content_en": "

    You have some coins.  The i-th coin has a probability prob[i] of facing heads when tossed.

    \n\n

    Return the probability that the number of coins facing heads equals target if you toss every coin exactly once.

    \n\n

     

    \n

    Example 1:

    \n
    Input: prob = [0.4], target = 1\nOutput: 0.40000\n

    Example 2:

    \n
    Input: prob = [0.5,0.5,0.5,0.5,0.5], target = 0\nOutput: 0.03125\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= prob.length <= 1000
    • \n\t
    • 0 <= prob[i] <= 1
    • \n\t
    • 0 <= target <= prob.length
    • \n\t
    • Answers will be accepted as correct if they are within 10^-5 of the correct answer.
    • \n
    \n", "content_cn": "

    \u6709\u4e00\u4e9b\u4e0d\u89c4\u5219\u7684\u786c\u5e01\u3002\u5728\u8fd9\u4e9b\u786c\u5e01\u4e2d\uff0cprob[i] \u8868\u793a\u7b2c i \u679a\u786c\u5e01\u6b63\u9762\u671d\u4e0a\u7684\u6982\u7387\u3002

    \n\n

    \u8bf7\u5bf9\u6bcf\u4e00\u679a\u786c\u5e01\u629b\u63b7 \u4e00\u6b21\uff0c\u7136\u540e\u8fd4\u56de\u6b63\u9762\u671d\u4e0a\u7684\u786c\u5e01\u6570\u7b49\u4e8e target \u7684\u6982\u7387\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aprob = [0.4], target = 1\n\u8f93\u51fa\uff1a0.40000\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aprob = [0.5,0.5,0.5,0.5,0.5], target = 0\n\u8f93\u51fa\uff1a0.03125\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= prob.length <= 1000
    • \n\t
    • 0 <= prob[i] <= 1
    • \n\t
    • 0 <= target <= prob.length
    • \n\t
    • \u5982\u679c\u7b54\u6848\u4e0e\u6807\u51c6\u7b54\u6848\u7684\u8bef\u5dee\u5728 10^-5 \u5185\uff0c\u5219\u88ab\u89c6\u4e3a\u6b63\u786e\u7b54\u6848\u3002
    • \n
    \n", "tags_en": ["Math", "Dynamic Programming"], "tags_cn": ["\u6570\u5b66", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n double probabilityOfHeads(vector& prob, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double probabilityOfHeads(double[] prob, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def probabilityOfHeads(self, prob, target):\n \"\"\"\n :type prob: List[float]\n :type target: int\n :rtype: float\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def probabilityOfHeads(self, prob: List[float], target: int) -> float:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\ndouble probabilityOfHeads(double* prob, int probSize, int target){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double ProbabilityOfHeads(double[] prob, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} prob\n * @param {number} target\n * @return {number}\n */\nvar probabilityOfHeads = function(prob, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Float[]} prob\n# @param {Integer} target\n# @return {Float}\ndef probability_of_heads(prob, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func probabilityOfHeads(_ prob: [Double], _ target: Int) -> Double {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func probabilityOfHeads(prob []float64, target int) float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def probabilityOfHeads(prob: Array[Double], target: Int): Double = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun probabilityOfHeads(prob: DoubleArray, target: Int): Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn probability_of_heads(prob: Vec, target: i32) -> f64 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Float[] $prob\n * @param Integer $target\n * @return Float\n */\n function probabilityOfHeads($prob, $target) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function probabilityOfHeads(prob: number[], target: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (probability-of-heads prob target)\n (-> (listof flonum?) exact-integer? flonum?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1230](https://leetcode-cn.com/problems/toss-strange-coins)", "[\u629b\u63b7\u786c\u5e01](/solution/1200-1299/1230.Toss%20Strange%20Coins/README.md)", "`\u6570\u5b66`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1230](https://leetcode.com/problems/toss-strange-coins)", "[Toss Strange Coins](/solution/1200-1299/1230.Toss%20Strange%20Coins/README_EN.md)", "`Math`,`Dynamic Programming`", "Medium", "\ud83d\udd12"]}, {"question_id": "1165", "frontend_question_id": "1229", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/meeting-scheduler", "url_en": "https://leetcode.com/problems/meeting-scheduler", "relative_path_cn": "/solution/1200-1299/1229.Meeting%20Scheduler/README.md", "relative_path_en": "/solution/1200-1299/1229.Meeting%20Scheduler/README_EN.md", "title_cn": "\u5b89\u6392\u4f1a\u8bae\u65e5\u7a0b", "title_en": "Meeting Scheduler", "question_title_slug": "meeting-scheduler", "content_en": "

    Given the availability time slots arrays slots1 and slots2 of two people and a meeting duration duration, return the earliest time slot that works for both of them and is of duration duration.

    \n\n

    If there is no common time slot that satisfies the requirements, return an empty array.

    \n\n

    The format of a time slot is an array of two elements [start, end] representing an inclusive time range from start to end.

    \n\n

    It is guaranteed that no two availability slots of the same person intersect with each other. That is, for any two time slots [start1, end1] and [start2, end2] of the same person, either start1 > end2 or start2 > end1.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: slots1 = [[10,50],[60,120],[140,210]], slots2 = [[0,15],[60,70]], duration = 8\nOutput: [60,68]\n
    \n\n

    Example 2:

    \n\n
    \nInput: slots1 = [[10,50],[60,120],[140,210]], slots2 = [[0,15],[60,70]], duration = 12\nOutput: []\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= slots1.length, slots2.length <= 104
    • \n\t
    • slots1[i].length, slots2[i].length == 2
    • \n\t
    • slots1[i][0] < slots1[i][1]
    • \n\t
    • slots2[i][0] < slots2[i][1]
    • \n\t
    • 0 <= slots1[i][j], slots2[i][j] <= 109
    • \n\t
    • 1 <= duration <= 106
    • \n
    \n", "content_cn": "

    \u4f60\u662f\u4e00\u540d\u884c\u653f\u52a9\u7406\uff0c\u624b\u91cc\u6709\u4e24\u4f4d\u5ba2\u6237\u7684\u7a7a\u95f2\u65f6\u95f4\u8868\uff1aslots1 \u548c slots2\uff0c\u4ee5\u53ca\u4f1a\u8bae\u7684\u9884\u8ba1\u6301\u7eed\u65f6\u95f4 duration\uff0c\u8bf7\u4f60\u4e3a\u4ed6\u4eec\u5b89\u6392\u5408\u9002\u7684\u4f1a\u8bae\u65f6\u95f4\u3002

    \n\n

    \u300c\u4f1a\u8bae\u65f6\u95f4\u300d\u662f\u4e24\u4f4d\u5ba2\u6237\u90fd\u6709\u7a7a\u53c2\u52a0\uff0c\u5e76\u4e14\u6301\u7eed\u65f6\u95f4\u80fd\u591f\u6ee1\u8db3\u9884\u8ba1\u65f6\u95f4 duration \u7684 \u6700\u65e9\u7684\u65f6\u95f4\u95f4\u9694\u3002

    \n\n

    \u5982\u679c\u6ca1\u6709\u6ee1\u8db3\u8981\u6c42\u7684\u4f1a\u8bae\u65f6\u95f4\uff0c\u5c31\u8bf7\u8fd4\u56de\u4e00\u4e2a \u7a7a\u6570\u7ec4\u3002

    \n\n

     

    \n\n

    \u300c\u7a7a\u95f2\u65f6\u95f4\u300d\u7684\u683c\u5f0f\u662f [start, end]\uff0c\u7531\u5f00\u59cb\u65f6\u95f4 start \u548c\u7ed3\u675f\u65f6\u95f4 end \u7ec4\u6210\uff0c\u8868\u793a\u4ece start \u5f00\u59cb\uff0c\u5230 end \u7ed3\u675f\u3002 

    \n\n

    \u9898\u76ee\u4fdd\u8bc1\u6570\u636e\u6709\u6548\uff1a\u540c\u4e00\u4e2a\u4eba\u7684\u7a7a\u95f2\u65f6\u95f4\u4e0d\u4f1a\u51fa\u73b0\u4ea4\u53e0\u7684\u60c5\u51b5\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u5bf9\u4e8e\u540c\u4e00\u4e2a\u4eba\u7684\u4e24\u4e2a\u7a7a\u95f2\u65f6\u95f4 [start1, end1] \u548c [start2, end2]\uff0c\u8981\u4e48 start1 > end2\uff0c\u8981\u4e48 start2 > end1\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aslots1 = [[10,50],[60,120],[140,210]], slots2 = [[0,15],[60,70]], duration = 8\n\u8f93\u51fa\uff1a[60,68]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aslots1 = [[10,50],[60,120],[140,210]], slots2 = [[0,15],[60,70]], duration = 12\n\u8f93\u51fa\uff1a[]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= slots1.length, slots2.length <= 10^4
    • \n\t
    • slots1[i].length, slots2[i].length == 2
    • \n\t
    • slots1[i][0] < slots1[i][1]
    • \n\t
    • slots2[i][0] < slots2[i][1]
    • \n\t
    • 0 <= slots1[i][j], slots2[i][j] <= 10^9
    • \n\t
    • 1 <= duration <= 10^6 
    • \n
    \n", "tags_en": ["Sort", "Two Pointers", "Line Sweep"], "tags_cn": ["\u6392\u5e8f", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector minAvailableDuration(vector>& slots1, vector>& slots2, int duration) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List minAvailableDuration(int[][] slots1, int[][] slots2, int duration) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minAvailableDuration(self, slots1, slots2, duration):\n \"\"\"\n :type slots1: List[List[int]]\n :type slots2: List[List[int]]\n :type duration: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minAvailableDuration(self, slots1: List[List[int]], slots2: List[List[int]], duration: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* minAvailableDuration(int** slots1, int slots1Size, int* slots1ColSize, int** slots2, int slots2Size, int* slots2ColSize, int duration, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList MinAvailableDuration(int[][] slots1, int[][] slots2, int duration) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} slots1\n * @param {number[][]} slots2\n * @param {number} duration\n * @return {number[]}\n */\nvar minAvailableDuration = function(slots1, slots2, duration) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} slots1\n# @param {Integer[][]} slots2\n# @param {Integer} duration\n# @return {Integer[]}\ndef min_available_duration(slots1, slots2, duration)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minAvailableDuration(_ slots1: [[Int]], _ slots2: [[Int]], _ duration: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minAvailableDuration(slots1 [][]int, slots2 [][]int, duration int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minAvailableDuration(slots1: Array[Array[Int]], slots2: Array[Array[Int]], duration: Int): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minAvailableDuration(slots1: Array, slots2: Array, duration: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_available_duration(slots1: Vec>, slots2: Vec>, duration: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $slots1\n * @param Integer[][] $slots2\n * @param Integer $duration\n * @return Integer[]\n */\n function minAvailableDuration($slots1, $slots2, $duration) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minAvailableDuration(slots1: number[][], slots2: number[][], duration: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-available-duration slots1 slots2 duration)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1229](https://leetcode-cn.com/problems/meeting-scheduler)", "[\u5b89\u6392\u4f1a\u8bae\u65e5\u7a0b](/solution/1200-1299/1229.Meeting%20Scheduler/README.md)", "`\u6392\u5e8f`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1229](https://leetcode.com/problems/meeting-scheduler)", "[Meeting Scheduler](/solution/1200-1299/1229.Meeting%20Scheduler/README_EN.md)", "`Sort`,`Two Pointers`,`Line Sweep`", "Medium", "\ud83d\udd12"]}, {"question_id": "1164", "frontend_question_id": "1228", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/missing-number-in-arithmetic-progression", "url_en": "https://leetcode.com/problems/missing-number-in-arithmetic-progression", "relative_path_cn": "/solution/1200-1299/1228.Missing%20Number%20In%20Arithmetic%20Progression/README.md", "relative_path_en": "/solution/1200-1299/1228.Missing%20Number%20In%20Arithmetic%20Progression/README_EN.md", "title_cn": "\u7b49\u5dee\u6570\u5217\u4e2d\u7f3a\u5931\u7684\u6570\u5b57", "title_en": "Missing Number In Arithmetic Progression", "question_title_slug": "missing-number-in-arithmetic-progression", "content_en": "

    In some array arr, the values were in arithmetic progression: the values arr[i + 1] - arr[i] are all equal for every 0 <= i < arr.length - 1.

    \n\n

    A value from arr was removed that was not the first or last value in the array.

    \n\n

    Given arr, return the removed value.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr = [5,7,11,13]\nOutput: 9\nExplanation: The previous array was [5,7,9,11,13].\n
    \n\n

    Example 2:

    \n\n
    \nInput: arr = [15,13,12]\nOutput: 14\nExplanation: The previous array was [15,14,13,12].
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 3 <= arr.length <= 1000
    • \n\t
    • 0 <= arr[i] <= 105
    • \n\t
    • The given array is guaranteed to be a valid array.
    • \n
    \n", "content_cn": "

    \u6709\u4e00\u4e2a\u6570\u7ec4\uff0c\u5176\u4e2d\u7684\u503c\u7b26\u5408\u7b49\u5dee\u6570\u5217\u7684\u6570\u503c\u89c4\u5f8b\uff0c\u4e5f\u5c31\u662f\u8bf4\uff1a

    \n\n
      \n\t
    • \u5728 0 <= i < arr.length - 1 \u7684\u524d\u63d0\u4e0b\uff0carr[i+1] - arr[i] \u7684\u503c\u90fd\u76f8\u7b49\u3002
    • \n
    \n\n

    \u6211\u4eec\u4f1a\u4ece\u8be5\u6570\u7ec4\u4e2d\u5220\u9664\u4e00\u4e2a \u65e2\u4e0d\u662f\u7b2c\u4e00\u4e2a \u4e5f \u4e0d\u662f\u6700\u540e\u4e00\u4e2a\u7684\u503c\uff0c\u5f97\u5230\u4e00\u4e2a\u65b0\u7684\u6570\u7ec4  arr\u3002

    \n\n

    \u7ed9\u4f60\u8fd9\u4e2a\u7f3a\u503c\u7684\u6570\u7ec4 arr\uff0c\u8bf7\u4f60\u5e2e\u5fd9\u627e\u51fa\u88ab\u5220\u9664\u7684\u90a3\u4e2a\u6570\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [5,7,11,13]\n\u8f93\u51fa\uff1a9\n\u89e3\u91ca\uff1a\u539f\u6765\u7684\u6570\u7ec4\u662f [5,7,9,11,13]\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [15,13,12]\n\u8f93\u51fa\uff1a14\n\u89e3\u91ca\uff1a\u539f\u6765\u7684\u6570\u7ec4\u662f [15,14,13,12]\u3002
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 3 <= arr.length <= 1000
    • \n\t
    • 0 <= arr[i] <= 10^5
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int missingNumber(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int missingNumber(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def missingNumber(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def missingNumber(self, arr: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint missingNumber(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MissingNumber(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar missingNumber = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef missing_number(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func missingNumber(_ arr: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func missingNumber(arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def missingNumber(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun missingNumber(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn missing_number(arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function missingNumber($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function missingNumber(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (missing-number arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1228](https://leetcode-cn.com/problems/missing-number-in-arithmetic-progression)", "[\u7b49\u5dee\u6570\u5217\u4e2d\u7f3a\u5931\u7684\u6570\u5b57](/solution/1200-1299/1228.Missing%20Number%20In%20Arithmetic%20Progression/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1228](https://leetcode.com/problems/missing-number-in-arithmetic-progression)", "[Missing Number In Arithmetic Progression](/solution/1200-1299/1228.Missing%20Number%20In%20Arithmetic%20Progression/README_EN.md)", "`Math`", "Easy", "\ud83d\udd12"]}, {"question_id": "1163", "frontend_question_id": "1077", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/project-employees-iii", "url_en": "https://leetcode.com/problems/project-employees-iii", "relative_path_cn": "/solution/1000-1099/1077.Project%20Employees%20III/README.md", "relative_path_en": "/solution/1000-1099/1077.Project%20Employees%20III/README_EN.md", "title_cn": "\u9879\u76ee\u5458\u5de5 III", "title_en": "Project Employees III", "question_title_slug": "project-employees-iii", "content_en": "

    Table: Project

    \n\n
    \n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| project_id  | int     |\n| employee_id | int     |\n+-------------+---------+\n(project_id, employee_id) is the primary key of this table.\nemployee_id is a foreign key to Employee table.\n
    \n\n

    Table: Employee

    \n\n
    \n+------------------+---------+\n| Column Name      | Type    |\n+------------------+---------+\n| employee_id      | int     |\n| name             | varchar |\n| experience_years | int     |\n+------------------+---------+\nemployee_id is the primary key of this table.\n
    \n\n

     

    \n\n

    Write an SQL query that reports the most experienced employees in each project. In case of a tie, report all employees with the maximum number of experience years.

    \n\n

    The query result format is in the following example:

    \n\n
    \nProject table:\n+-------------+-------------+\n| project_id  | employee_id |\n+-------------+-------------+\n| 1           | 1           |\n| 1           | 2           |\n| 1           | 3           |\n| 2           | 1           |\n| 2           | 4           |\n+-------------+-------------+\n\nEmployee table:\n+-------------+--------+------------------+\n| employee_id | name   | experience_years |\n+-------------+--------+------------------+\n| 1           | Khaled | 3                |\n| 2           | Ali    | 2                |\n| 3           | John   | 3                |\n| 4           | Doe    | 2                |\n+-------------+--------+------------------+\n\nResult table:\n+-------------+---------------+\n| project_id  | employee_id   |\n+-------------+---------------+\n| 1           | 1             |\n| 1           | 3             |\n| 2           | 1             |\n+-------------+---------------+\nBoth employees with id 1 and 3 have the most experience among the employees of the first project. For the second project, the employee with id 1 has the most experience.
    \n", "content_cn": "

    \u9879\u76ee\u8868 Project\uff1a

    \n\n
    \n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| project_id  | int     |\n| employee_id | int     |\n+-------------+---------+\n(project_id, employee_id) \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\nemployee_id \u662f\u5458\u5de5\u8868 Employee \u7684\u5916\u952e\n
    \n\n

    \u5458\u5de5\u8868 Employee\uff1a

    \n\n
    \n+------------------+---------+\n| Column Name      | Type    |\n+------------------+---------+\n| employee_id      | int     |\n| name             | varchar |\n| experience_years | int     |\n+------------------+---------+\nemployee_id \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\n
    \n\n

     

    \n\n

    \u5199 \u4e00\u4e2a SQL \u67e5\u8be2\u8bed\u53e5\uff0c\u62a5\u544a\u5728\u6bcf\u4e00\u4e2a\u9879\u76ee\u4e2d\u7ecf\u9a8c\u6700\u4e30\u5bcc\u7684\u96c7\u5458\u662f\u8c01\u3002\u5982\u679c\u51fa\u73b0\u7ecf\u9a8c\u5e74\u6570\u76f8\u540c\u7684\u60c5\u51b5\uff0c\u8bf7\u62a5\u544a\u6240\u6709\u5177\u6709\u6700\u5927\u7ecf\u9a8c\u5e74\u6570\u7684\u5458\u5de5\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5728\u4ee5\u4e0b\u793a\u4f8b\u4e2d\uff1a

    \n\n
    \nProject \u8868\uff1a\n+-------------+-------------+\n| project_id  | employee_id |\n+-------------+-------------+\n| 1           | 1           |\n| 1           | 2           |\n| 1           | 3           |\n| 2           | 1           |\n| 2           | 4           |\n+-------------+-------------+\n\nEmployee \u8868\uff1a\n+-------------+--------+------------------+\n| employee_id | name   | experience_years |\n+-------------+--------+------------------+\n| 1           | Khaled | 3                |\n| 2           | Ali    | 2                |\n| 3           | John   | 3                |\n| 4           | Doe    | 2                |\n+-------------+--------+------------------+\n\nResult \u8868\uff1a\n+-------------+---------------+\n| project_id  | employee_id   |\n+-------------+---------------+\n| 1           | 1             |\n| 1           | 3             |\n| 2           | 1             |\n+-------------+---------------+\nemployee_id \u4e3a 1 \u548c 3 \u7684\u5458\u5de5\u5728 project_id \u4e3a 1 \u7684\u9879\u76ee\u4e2d\u62e5\u6709\u6700\u4e30\u5bcc\u7684\u7ecf\u9a8c\u3002\u5728 project_id \u4e3a 2 \u7684\u9879\u76ee\u4e2d\uff0cemployee_id \u4e3a 1 \u7684\u5458\u5de5\u62e5\u6709\u6700\u4e30\u5bcc\u7684\u7ecf\u9a8c\u3002
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1077](https://leetcode-cn.com/problems/project-employees-iii)", "[\u9879\u76ee\u5458\u5de5 III](/solution/1000-1099/1077.Project%20Employees%20III/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1077](https://leetcode.com/problems/project-employees-iii)", "[Project Employees III](/solution/1000-1099/1077.Project%20Employees%20III/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1162", "frontend_question_id": "1076", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/project-employees-ii", "url_en": "https://leetcode.com/problems/project-employees-ii", "relative_path_cn": "/solution/1000-1099/1076.Project%20Employees%20II/README.md", "relative_path_en": "/solution/1000-1099/1076.Project%20Employees%20II/README_EN.md", "title_cn": "\u9879\u76ee\u5458\u5de5II", "title_en": "Project Employees II", "question_title_slug": "project-employees-ii", "content_en": "

    Table: Project

    \n\n
    \n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| project_id  | int     |\n| employee_id | int     |\n+-------------+---------+\n(project_id, employee_id) is the primary key of this table.\nemployee_id is a foreign key to Employee table.\n
    \n\n

     

    \n\n

    Table: Employee

    \n\n
    \n+------------------+---------+\n| Column Name      | Type    |\n+------------------+---------+\n| employee_id      | int     |\n| name             | varchar |\n| experience_years | int     |\n+------------------+---------+\nemployee_id is the primary key of this table.\n
    \n\n

     

    \n\n

    Write an SQL query that reports all the projects that have the most employees.

    \n\n

    The query result format is in the following example:

    \n\n

     

    \n\n
    \nProject table:\n+-------------+-------------+\n| project_id  | employee_id |\n+-------------+-------------+\n| 1           | 1           |\n| 1           | 2           |\n| 1           | 3           |\n| 2           | 1           |\n| 2           | 4           |\n+-------------+-------------+\n\nEmployee table:\n+-------------+--------+------------------+\n| employee_id | name   | experience_years |\n+-------------+--------+------------------+\n| 1           | Khaled | 3                |\n| 2           | Ali    | 2                |\n| 3           | John   | 1                |\n| 4           | Doe    | 2                |\n+-------------+--------+------------------+\n\nResult table:\n+-------------+\n| project_id  |\n+-------------+\n| 1           |\n+-------------+\nThe first project has 3 employees while the second one has 2.
    \n", "content_cn": "

    Table: Project

    \n\n
    +-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| project_id  | int     |\n| employee_id | int     |\n+-------------+---------+\n\u4e3b\u952e\u4e3a (project_id, employee_id)\u3002\nemployee_id \u662f\u5458\u5de5\u8868 Employee \u8868\u7684\u5916\u952e\u3002\n
    \n\n

    Table: Employee

    \n\n
    +------------------+---------+\n| Column Name      | Type    |\n+------------------+---------+\n| employee_id      | int     |\n| name             | varchar |\n| experience_years | int     |\n+------------------+---------+\n\u4e3b\u952e\u662f employee_id\u3002
    \n\n

     

    \n\n

    \u7f16\u5199\u4e00\u4e2aSQL\u67e5\u8be2\uff0c\u62a5\u544a\u6240\u6709\u96c7\u5458\u6700\u591a\u7684\u9879\u76ee\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u6240\u793a\uff1a

    \n\n
    Project table:\n+-------------+-------------+\n| project_id  | employee_id |\n+-------------+-------------+\n| 1           | 1           |\n| 1           | 2           |\n| 1           | 3           |\n| 2           | 1           |\n| 2           | 4           |\n+-------------+-------------+\n\nEmployee table:\n+-------------+--------+------------------+\n| employee_id | name   | experience_years |\n+-------------+--------+------------------+\n| 1           | Khaled | 3                |\n| 2           | Ali    | 2                |\n| 3           | John   | 1                |\n| 4           | Doe    | 2                |\n+-------------+--------+------------------+\n\nResult table:\n+-------------+\n| project_id  |\n+-------------+\n| 1           |\n+-------------+\n\u7b2c\u4e00\u4e2a\u9879\u76ee\u67093\u540d\u5458\u5de5\uff0c\u7b2c\u4e8c\u4e2a\u9879\u76ee\u67092\u540d\u5458\u5de5\u3002
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1076](https://leetcode-cn.com/problems/project-employees-ii)", "[\u9879\u76ee\u5458\u5de5II](/solution/1000-1099/1076.Project%20Employees%20II/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1076](https://leetcode.com/problems/project-employees-ii)", "[Project Employees II](/solution/1000-1099/1076.Project%20Employees%20II/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1161", "frontend_question_id": "1075", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/project-employees-i", "url_en": "https://leetcode.com/problems/project-employees-i", "relative_path_cn": "/solution/1000-1099/1075.Project%20Employees%20I/README.md", "relative_path_en": "/solution/1000-1099/1075.Project%20Employees%20I/README_EN.md", "title_cn": "\u9879\u76ee\u5458\u5de5 I", "title_en": "Project Employees I", "question_title_slug": "project-employees-i", "content_en": "

    Table: Project

    \n\n
    \n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| project_id  | int     |\n| employee_id | int     |\n+-------------+---------+\n(project_id, employee_id) is the primary key of this table.\nemployee_id is a foreign key to Employee table.\n
    \n\n

    Table: Employee

    \n\n
    \n+------------------+---------+\n| Column Name      | Type    |\n+------------------+---------+\n| employee_id      | int     |\n| name             | varchar |\n| experience_years | int     |\n+------------------+---------+\nemployee_id is the primary key of this table.\n
    \n\n

     

    \n\n

    Write an SQL query that reports the average experience years of all the employees for each project, rounded to 2 digits.

    \n\n

    The query result format is in the following example:

    \n\n
    \nProject table:\n+-------------+-------------+\n| project_id  | employee_id |\n+-------------+-------------+\n| 1           | 1           |\n| 1           | 2           |\n| 1           | 3           |\n| 2           | 1           |\n| 2           | 4           |\n+-------------+-------------+\n\nEmployee table:\n+-------------+--------+------------------+\n| employee_id | name   | experience_years |\n+-------------+--------+------------------+\n| 1           | Khaled | 3                |\n| 2           | Ali    | 2                |\n| 3           | John   | 1                |\n| 4           | Doe    | 2                |\n+-------------+--------+------------------+\n\nResult table:\n+-------------+---------------+\n| project_id  | average_years |\n+-------------+---------------+\n| 1           | 2.00          |\n| 2           | 2.50          |\n+-------------+---------------+\nThe average experience years for the first project is (3 + 2 + 1) / 3 = 2.00 and for the second project is (3 + 2) / 2 = 2.50\n
    \n", "content_cn": "

    \u9879\u76ee\u8868 Project\uff1a 

    \n\n
    \n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| project_id  | int     |\n| employee_id | int     |\n+-------------+---------+\n\u4e3b\u952e\u4e3a (project_id, employee_id)\u3002\nemployee_id \u662f\u5458\u5de5\u8868 Employee \u8868\u7684\u5916\u952e\u3002\n
    \n\n

    \u5458\u5de5\u8868 Employee\uff1a

    \n\n
    \n+------------------+---------+\n| Column Name      | Type    |\n+------------------+---------+\n| employee_id      | int     |\n| name             | varchar |\n| experience_years | int     |\n+------------------+---------+\n\u4e3b\u952e\u662f employee_id\u3002\n
    \n\n

     

    \n\n

    \u8bf7\u5199\u4e00\u4e2a SQL \u8bed\u53e5\uff0c\u67e5\u8be2\u6bcf\u4e00\u4e2a\u9879\u76ee\u4e2d\u5458\u5de5\u7684 \u5e73\u5747 \u5de5\u4f5c\u5e74\u9650\uff0c\u7cbe\u786e\u5230\u5c0f\u6570\u70b9\u540e\u4e24\u4f4d\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u7684\u683c\u5f0f\u5982\u4e0b\uff1a

    \n\n
    \nProject \u8868\uff1a\n+-------------+-------------+\n| project_id  | employee_id |\n+-------------+-------------+\n| 1           | 1           |\n| 1           | 2           |\n| 1           | 3           |\n| 2           | 1           |\n| 2           | 4           |\n+-------------+-------------+\n\nEmployee \u8868\uff1a\n+-------------+--------+------------------+\n| employee_id | name   | experience_years |\n+-------------+--------+------------------+\n| 1           | Khaled | 3                |\n| 2           | Ali    | 2                |\n| 3           | John   | 1                |\n| 4           | Doe    | 2                |\n+-------------+--------+------------------+\n\nResult \u8868\uff1a\n+-------------+---------------+\n| project_id  | average_years |\n+-------------+---------------+\n| 1           | 2.00          |\n| 2           | 2.50          |\n+-------------+---------------+\n\u7b2c\u4e00\u4e2a\u9879\u76ee\u4e2d\uff0c\u5458\u5de5\u7684\u5e73\u5747\u5de5\u4f5c\u5e74\u9650\u662f (3 + 2 + 1) / 3 = 2.00\uff1b\u7b2c\u4e8c\u4e2a\u9879\u76ee\u4e2d\uff0c\u5458\u5de5\u7684\u5e73\u5747\u5de5\u4f5c\u5e74\u9650\u662f (3 + 2) / 2 = 2.50\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1075](https://leetcode-cn.com/problems/project-employees-i)", "[\u9879\u76ee\u5458\u5de5 I](/solution/1000-1099/1075.Project%20Employees%20I/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1075](https://leetcode.com/problems/project-employees-i)", "[Project Employees I](/solution/1000-1099/1075.Project%20Employees%20I/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1160", "frontend_question_id": "1079", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/letter-tile-possibilities", "url_en": "https://leetcode.com/problems/letter-tile-possibilities", "relative_path_cn": "/solution/1000-1099/1079.Letter%20Tile%20Possibilities/README.md", "relative_path_en": "/solution/1000-1099/1079.Letter%20Tile%20Possibilities/README_EN.md", "title_cn": "\u6d3b\u5b57\u5370\u5237", "title_en": "Letter Tile Possibilities", "question_title_slug": "letter-tile-possibilities", "content_en": "

    You have n  tiles, where each tile has one letter tiles[i] printed on it.

    \n\n

    Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: tiles = "AAB"\nOutput: 8\nExplanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA".\n
    \n\n

    Example 2:

    \n\n
    \nInput: tiles = "AAABBC"\nOutput: 188\n
    \n\n

    Example 3:

    \n\n
    \nInput: tiles = "V"\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= tiles.length <= 7
    • \n\t
    • tiles consists of uppercase English letters.
    • \n
    \n", "content_cn": "

    \u4f60\u6709\u4e00\u5957\u6d3b\u5b57\u5b57\u6a21 tiles\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5b57\u6a21\u4e0a\u90fd\u523b\u6709\u4e00\u4e2a\u5b57\u6bcd tiles[i]\u3002\u8fd4\u56de\u4f60\u53ef\u4ee5\u5370\u51fa\u7684\u975e\u7a7a\u5b57\u6bcd\u5e8f\u5217\u7684\u6570\u76ee\u3002

    \n\n

    \u6ce8\u610f\uff1a\u672c\u9898\u4e2d\uff0c\u6bcf\u4e2a\u6d3b\u5b57\u5b57\u6a21\u53ea\u80fd\u4f7f\u7528\u4e00\u6b21\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a"AAB"\n\u8f93\u51fa\uff1a8\n\u89e3\u91ca\uff1a\u53ef\u80fd\u7684\u5e8f\u5217\u4e3a "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA"\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a"AAABBC"\n\u8f93\u51fa\uff1a188\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= tiles.length <= 7
    2. \n\t
    3. tiles \u7531\u5927\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    4. \n
    \n", "tags_en": ["Backtracking"], "tags_cn": ["\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numTilePossibilities(string tiles) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numTilePossibilities(String tiles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numTilePossibilities(self, tiles):\n \"\"\"\n :type tiles: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numTilePossibilities(self, tiles: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numTilePossibilities(char * tiles){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumTilePossibilities(string tiles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} tiles\n * @return {number}\n */\nvar numTilePossibilities = function(tiles) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} tiles\n# @return {Integer}\ndef num_tile_possibilities(tiles)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numTilePossibilities(_ tiles: String) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numTilePossibilities(tiles string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numTilePossibilities(tiles: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numTilePossibilities(tiles: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_tile_possibilities(tiles: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $tiles\n * @return Integer\n */\n function numTilePossibilities($tiles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numTilePossibilities(tiles: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-tile-possibilities tiles)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1079](https://leetcode-cn.com/problems/letter-tile-possibilities)", "[\u6d3b\u5b57\u5370\u5237](/solution/1000-1099/1079.Letter%20Tile%20Possibilities/README.md)", "`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1079](https://leetcode.com/problems/letter-tile-possibilities)", "[Letter Tile Possibilities](/solution/1000-1099/1079.Letter%20Tile%20Possibilities/README_EN.md)", "`Backtracking`", "Medium", ""]}, {"question_id": "1159", "frontend_question_id": "1081", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/smallest-subsequence-of-distinct-characters", "url_en": "https://leetcode.com/problems/smallest-subsequence-of-distinct-characters", "relative_path_cn": "/solution/1000-1099/1081.Smallest%20Subsequence%20of%20Distinct%20Characters/README.md", "relative_path_en": "/solution/1000-1099/1081.Smallest%20Subsequence%20of%20Distinct%20Characters/README_EN.md", "title_cn": "\u4e0d\u540c\u5b57\u7b26\u7684\u6700\u5c0f\u5b50\u5e8f\u5217", "title_en": "Smallest Subsequence of Distinct Characters", "question_title_slug": "smallest-subsequence-of-distinct-characters", "content_en": "

    Return the lexicographically smallest subsequence of s that contains all the distinct characters of s exactly once.

    \n\n

    Note: This question is the same as 316: https://leetcode.com/problems/remove-duplicate-letters/

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "bcabc"\nOutput: "abc"\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "cbacdcbc"\nOutput: "acdb"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 1000
    • \n\t
    • s consists of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u8fd4\u56de s \u5b57\u5178\u5e8f\u6700\u5c0f\u7684\u5b50\u5e8f\u5217\uff0c\u8be5\u5b50\u5e8f\u5217\u5305\u542b s \u7684\u6240\u6709\u4e0d\u540c\u5b57\u7b26\uff0c\u4e14\u53ea\u5305\u542b\u4e00\u6b21\u3002

    \n\n

    \u6ce8\u610f\uff1a\u8be5\u9898\u4e0e 316 https://leetcode.com/problems/remove-duplicate-letters/ \u76f8\u540c

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"bcabc\"\n\u8f93\u51fa\uff1a\"abc\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"cbacdcbc\"\n\u8f93\u51fa\uff1a\"acdb\"
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 1000
    • \n\t
    • s \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n", "tags_en": ["Stack", "Greedy", "String"], "tags_cn": ["\u6808", "\u8d2a\u5fc3\u7b97\u6cd5", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string smallestSubsequence(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String smallestSubsequence(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def smallestSubsequence(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def smallestSubsequence(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * smallestSubsequence(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string SmallestSubsequence(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar smallestSubsequence = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef smallest_subsequence(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func smallestSubsequence(_ s: String) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func smallestSubsequence(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def smallestSubsequence(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun smallestSubsequence(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn smallest_subsequence(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function smallestSubsequence($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function smallestSubsequence(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (smallest-subsequence s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1081](https://leetcode-cn.com/problems/smallest-subsequence-of-distinct-characters)", "[\u4e0d\u540c\u5b57\u7b26\u7684\u6700\u5c0f\u5b50\u5e8f\u5217](/solution/1000-1099/1081.Smallest%20Subsequence%20of%20Distinct%20Characters/README.md)", "`\u6808`,`\u8d2a\u5fc3\u7b97\u6cd5`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1081](https://leetcode.com/problems/smallest-subsequence-of-distinct-characters)", "[Smallest Subsequence of Distinct Characters](/solution/1000-1099/1081.Smallest%20Subsequence%20of%20Distinct%20Characters/README_EN.md)", "`Stack`,`Greedy`,`String`", "Medium", ""]}, {"question_id": "1157", "frontend_question_id": "1080", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/insufficient-nodes-in-root-to-leaf-paths", "url_en": "https://leetcode.com/problems/insufficient-nodes-in-root-to-leaf-paths", "relative_path_cn": "/solution/1000-1099/1080.Insufficient%20Nodes%20in%20Root%20to%20Leaf%20Paths/README.md", "relative_path_en": "/solution/1000-1099/1080.Insufficient%20Nodes%20in%20Root%20to%20Leaf%20Paths/README_EN.md", "title_cn": "\u6839\u5230\u53f6\u8def\u5f84\u4e0a\u7684\u4e0d\u8db3\u8282\u70b9", "title_en": "Insufficient Nodes in Root to Leaf Paths", "question_title_slug": "insufficient-nodes-in-root-to-leaf-paths", "content_en": "

    Given the root of a binary tree, consider all root to leaf paths: paths from the root to any leaf.  (A leaf is a node with no children.)

    \r\n\r\n

    A node is insufficient if every such root to leaf path intersecting this node has sum strictly less than limit.

    \r\n\r\n

    Delete all insufficient nodes simultaneously, and return the root of the resulting binary tree.

    \r\n\r\n

     

    \r\n\r\n

    Example 1:

    \r\n\r\n
    \r\n\"\"\r\nInput: root = [1,2,3,4,-99,-99,7,8,9,-99,-99,12,13,-99,14], limit = 1\r\n\"\"\r\nOutput: [1,2,3,4,null,null,7,8,9,null,14]\r\n
    \r\n\r\n
    \r\n

    Example 2:

    \r\n\r\n
    \r\n\"\"\r\nInput: root = [5,4,8,11,null,17,4,7,1,null,null,5,3], limit = 22\r\n\"\"\r\nOutput: [5,4,8,11,null,17,4,7,null,null,null,5]
    \r\n\r\n

     

    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\n\"\"\r\nInput: root = [1,2,-3,-5,null,4,null], limit = -1\r\n\"\"\r\nOutput: [1,null,-3,4]
    \r\n
    \r\n\r\n

     

    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    1. The given tree will have between 1 and 5000 nodes.
    2. \r\n\t
    3. -10^5 <= node.val <= 10^5
    4. \r\n\t
    5. -10^9 <= limit <= 10^9
    6. \r\n
    \r\n\r\n
    \r\n
     
    \r\n
    \r\n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u68f5\u4e8c\u53c9\u6811\u7684\u6839 root\uff0c\u8bf7\u4f60\u8003\u8651\u5b83\u6240\u6709 \u4ece\u6839\u5230\u53f6\u7684\u8def\u5f84\uff1a\u4ece\u6839\u5230\u4efb\u4f55\u53f6\u7684\u8def\u5f84\u3002\uff08\u6240\u8c13\u4e00\u4e2a\u53f6\u5b50\u8282\u70b9\uff0c\u5c31\u662f\u4e00\u4e2a\u6ca1\u6709\u5b50\u8282\u70b9\u7684\u8282\u70b9\uff09

    \n\n

    \u5047\u5982\u901a\u8fc7\u8282\u70b9 node \u7684\u6bcf\u79cd\u53ef\u80fd\u7684 “\u6839-\u53f6” \u8def\u5f84\u4e0a\u503c\u7684\u603b\u548c\u5168\u90fd\u5c0f\u4e8e\u7ed9\u5b9a\u7684 limit\uff0c\u5219\u8be5\u8282\u70b9\u88ab\u79f0\u4e4b\u4e3a\u300c\u4e0d\u8db3\u8282\u70b9\u300d\uff0c\u9700\u8981\u88ab\u5220\u9664\u3002

    \n\n

    \u8bf7\u4f60\u5220\u9664\u6240\u6709\u4e0d\u8db3\u8282\u70b9\uff0c\u5e76\u8fd4\u56de\u751f\u6210\u7684\u4e8c\u53c9\u6811\u7684\u6839\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \"\"\n\u8f93\u5165\uff1aroot = [1,2,3,4,-99,-99,7,8,9,-99,-99,12,13,-99,14], limit = 1\n\"\"\n\u8f93\u51fa\uff1a[1,2,3,4,null,null,7,8,9,null,14]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \"\"\n\u8f93\u5165\uff1aroot = [5,4,8,11,null,17,4,7,1,null,null,5,3], limit = 22\n\"\"\n\u8f93\u51fa\uff1a[5,4,8,11,null,17,4,7,null,null,null,5]
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \"\"\n\u8f93\u5165\uff1aroot = [5,-6,-6], limit = 0\n\u8f93\u51fa\uff1a[]
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. \u7ed9\u5b9a\u7684\u6811\u6709 1 \u5230 5000 \u4e2a\u8282\u70b9
    2. \n\t
    3. -10^5 <= node.val <= 10^5
    4. \n\t
    5. -10^9 <= limit <= 10^9
    6. \n
    \n\n

     

    \n", "tags_en": ["Depth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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 */\nclass Solution {\npublic:\n TreeNode* sufficientSubset(TreeNode* root, int limit) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode(int x) { val = x; }\n * }\n */\nclass Solution {\n public TreeNode sufficientSubset(TreeNode root, int limit) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution(object):\n def sufficientSubset(self, root, limit):\n \"\"\"\n :type root: TreeNode\n :type limit: int\n :rtype: TreeNode\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution:\n def sufficientSubset(self, root: TreeNode, limit: int) -> TreeNode:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* sufficientSubset(struct TreeNode* root, int limit){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int x) { val = x; }\n * }\n */\npublic class Solution {\n public TreeNode SufficientSubset(TreeNode root, int limit) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val) {\n * this.val = val;\n * this.left = this.right = null;\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number} limit\n * @return {TreeNode}\n */\nvar sufficientSubset = function(root, limit) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val)\n# @val = val\n# @left, @right = nil, nil\n# end\n# end\n\n# @param {TreeNode} root\n# @param {Integer} limit\n# @return {TreeNode}\ndef sufficient_subset(root, limit)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.left = nil\n * self.right = nil\n * }\n * }\n */\nclass Solution {\n func sufficientSubset(_ root: TreeNode?, _ limit: Int) -> TreeNode? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc sufficientSubset(root *TreeNode, limit int) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(var _value: Int) {\n * var value: Int = _value\n * var left: TreeNode = null\n * var right: TreeNode = null\n * }\n */\nobject Solution {\n def sufficientSubset(root: TreeNode, limit: Int): TreeNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun sufficientSubset(root: TreeNode?, limit: Int): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n// \n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn sufficient_subset(root: Option>>, limit: i32) -> Option>> {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($value) { $this->val = $value; }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param Integer $limit\n * @return TreeNode\n */\n function sufficientSubset($root, $limit) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction sufficientSubset(root: TreeNode | null, limit: number): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (sufficient-subset root limit)\n (-> (or/c tree-node? #f) exact-integer? (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1080](https://leetcode-cn.com/problems/insufficient-nodes-in-root-to-leaf-paths)", "[\u6839\u5230\u53f6\u8def\u5f84\u4e0a\u7684\u4e0d\u8db3\u8282\u70b9](/solution/1000-1099/1080.Insufficient%20Nodes%20in%20Root%20to%20Leaf%20Paths/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1080](https://leetcode.com/problems/insufficient-nodes-in-root-to-leaf-paths)", "[Insufficient Nodes in Root to Leaf Paths](/solution/1000-1099/1080.Insufficient%20Nodes%20in%20Root%20to%20Leaf%20Paths/README_EN.md)", "`Depth-first Search`", "Medium", ""]}, {"question_id": "1156", "frontend_question_id": "1078", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/occurrences-after-bigram", "url_en": "https://leetcode.com/problems/occurrences-after-bigram", "relative_path_cn": "/solution/1000-1099/1078.Occurrences%20After%20Bigram/README.md", "relative_path_en": "/solution/1000-1099/1078.Occurrences%20After%20Bigram/README_EN.md", "title_cn": "Bigram \u5206\u8bcd", "title_en": "Occurrences After Bigram", "question_title_slug": "occurrences-after-bigram", "content_en": "

    Given two strings first and second, consider occurrences in some text of the form "first second third", where second comes immediately after first, and third comes immediately after second.

    \n\n

    Return an array of all the words third for each occurrence of "first second third".

    \n\n

     

    \n

    Example 1:

    \n
    Input: text = \"alice is a good girl she is a good student\", first = \"a\", second = \"good\"\nOutput: [\"girl\",\"student\"]\n

    Example 2:

    \n
    Input: text = \"we will we will rock you\", first = \"we\", second = \"will\"\nOutput: [\"we\",\"rock\"]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= text.length <= 1000
    • \n\t
    • text consists of lowercase English letters and spaces.
    • \n\t
    • All the words in text a separated by a single space.
    • \n\t
    • 1 <= first.length, second.length <= 10
    • \n\t
    • first and second consist of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u51fa\u7b2c\u4e00\u4e2a\u8bcd first \u548c\u7b2c\u4e8c\u4e2a\u8bcd second\uff0c\u8003\u8651\u5728\u67d0\u4e9b\u6587\u672c text \u4e2d\u53ef\u80fd\u4ee5 "first second third" \u5f62\u5f0f\u51fa\u73b0\u7684\u60c5\u51b5\uff0c\u5176\u4e2d second \u7d27\u968f first \u51fa\u73b0\uff0cthird \u7d27\u968f second \u51fa\u73b0\u3002

    \n\n

    \u5bf9\u4e8e\u6bcf\u79cd\u8fd9\u6837\u7684\u60c5\u51b5\uff0c\u5c06\u7b2c\u4e09\u4e2a\u8bcd "third" \u6dfb\u52a0\u5230\u7b54\u6848\u4e2d\uff0c\u5e76\u8fd4\u56de\u7b54\u6848\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1atext = "alice is a good girl she is a good student", first = "a", second = "good"\n\u8f93\u51fa\uff1a["girl","student"]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1atext = "we will we will rock you", first = "we", second = "will"\n\u8f93\u51fa\uff1a["we","rock"]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= text.length <= 1000
    2. \n\t
    3. text \u7531\u4e00\u4e9b\u7528\u7a7a\u683c\u5206\u9694\u7684\u5355\u8bcd\u7ec4\u6210\uff0c\u6bcf\u4e2a\u5355\u8bcd\u90fd\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    4. \n\t
    5. 1 <= first.length, second.length <= 10
    6. \n\t
    7. first \u548c second \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    8. \n
    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findOcurrences(string text, string first, string second) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String[] findOcurrences(String text, String first, String second) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findOcurrences(self, text, first, second):\n \"\"\"\n :type text: str\n :type first: str\n :type second: str\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findOcurrences(self, text: str, first: str, second: str) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** findOcurrences(char * text, char * first, char * second, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string[] FindOcurrences(string text, string first, string second) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} text\n * @param {string} first\n * @param {string} second\n * @return {string[]}\n */\nvar findOcurrences = function(text, first, second) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} text\n# @param {String} first\n# @param {String} second\n# @return {String[]}\ndef find_ocurrences(text, first, second)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findOcurrences(_ text: String, _ first: String, _ second: String) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findOcurrences(text string, first string, second string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findOcurrences(text: String, first: String, second: String): Array[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findOcurrences(text: String, first: String, second: String): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_ocurrences(text: String, first: String, second: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $text\n * @param String $first\n * @param String $second\n * @return String[]\n */\n function findOcurrences($text, $first, $second) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findOcurrences(text: string, first: string, second: string): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-ocurrences text first second)\n (-> string? string? string? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1078](https://leetcode-cn.com/problems/occurrences-after-bigram)", "[Bigram \u5206\u8bcd](/solution/1000-1099/1078.Occurrences%20After%20Bigram/README.md)", "`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[1078](https://leetcode.com/problems/occurrences-after-bigram)", "[Occurrences After Bigram](/solution/1000-1099/1078.Occurrences%20After%20Bigram/README_EN.md)", "`Hash Table`", "Easy", ""]}, {"question_id": "1155", "frontend_question_id": "1070", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/product-sales-analysis-iii", "url_en": "https://leetcode.com/problems/product-sales-analysis-iii", "relative_path_cn": "/solution/1000-1099/1070.Product%20Sales%20Analysis%20III/README.md", "relative_path_en": "/solution/1000-1099/1070.Product%20Sales%20Analysis%20III/README_EN.md", "title_cn": "\u4ea7\u54c1\u9500\u552e\u5206\u6790 III", "title_en": "Product Sales Analysis III", "question_title_slug": "product-sales-analysis-iii", "content_en": "

    Table: Sales

    \r\n\r\n
    \r\n+-------------+-------+\r\n| Column Name | Type  |\r\n+-------------+-------+\r\n| sale_id     | int   |\r\n| product_id  | int   |\r\n| year        | int   |\r\n| quantity    | int   |\r\n| price       | int   |\r\n+-------------+-------+\r\nsale_id is the primary key of this table.\r\nproduct_id is a foreign key to Product table.\r\nNote that the price is per unit.\r\n
    \r\n\r\n

    Table: Product

    \r\n\r\n
    \r\n+--------------+---------+\r\n| Column Name  | Type    |\r\n+--------------+---------+\r\n| product_id   | int     |\r\n| product_name | varchar |\r\n+--------------+---------+\r\nproduct_id is the primary key of this table.\r\n
    \r\n\r\n

     

    \r\n\r\n

    Write an SQL query that selects the product id, year, quantity, and price for the first year of every product sold.

    \r\n\r\n

    The query result format is in the following example:

    \r\n\r\n
    \r\nSales table:\r\n+---------+------------+------+----------+-------+\r\n| sale_id | product_id | year | quantity | price |\r\n+---------+------------+------+----------+-------+ \r\n| 1       | 100        | 2008 | 10       | 5000  |\r\n| 2       | 100        | 2009 | 12       | 5000  |\r\n| 7       | 200        | 2011 | 15       | 9000  |\r\n+---------+------------+------+----------+-------+\r\n\r\nProduct table:\r\n+------------+--------------+\r\n| product_id | product_name |\r\n+------------+--------------+\r\n| 100        | Nokia        |\r\n| 200        | Apple        |\r\n| 300        | Samsung      |\r\n+------------+--------------+\r\n\r\nResult table:\r\n+------------+------------+----------+-------+\r\n| product_id | first_year | quantity | price |\r\n+------------+------------+----------+-------+ \r\n| 100        | 2008       | 10       | 5000  |\r\n| 200        | 2011       | 15       | 9000  |\r\n+------------+------------+----------+-------+\r\n
    \r\n", "content_cn": "

    \u9500\u552e\u8868 Sales\uff1a

    \n\n
    +-------------+-------+\n| Column Name | Type  |\n+-------------+-------+\n| sale_id     | int   |\n| product_id  | int   |\n| year        | int   |\n| quantity    | int   |\n| price       | int   |\n+-------------+-------+\nsale_id \u662f\u6b64\u8868\u7684\u4e3b\u952e\u3002\nproduct_id \u662f\u4ea7\u54c1\u8868\u7684\u5916\u952e\u3002\n\u8bf7\u6ce8\u610f\uff0c\u4ef7\u683c\u662f\u6309\u6bcf\u5355\u4f4d\u8ba1\u7684\u3002\n
    \n\n

    \u4ea7\u54c1\u8868 Product\uff1a

    \n\n
    +--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| product_id   | int     |\n| product_name | varchar |\n+--------------+---------+\nproduct_id \u662f\u6b64\u8868\u7684\u4e3b\u952e\u3002
    \n\n

     

    \n\n

    \u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\uff0c\u9009\u51fa\u6bcf\u4e2a\u9500\u552e\u4ea7\u54c1\u7684 \u7b2c\u4e00\u5e74 \u7684 \u4ea7\u54c1 id\u3001\u5e74\u4efd\u3001\u6570\u91cf \u548c \u4ef7\u683c\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\uff1a

    \n\n
    Sales table:\n+---------+------------+------+----------+-------+\n| sale_id | product_id | year | quantity | price |\n+---------+------------+------+----------+-------+ \n| 1       | 100        | 2008 | 10       | 5000  |\n| 2       | 100        | 2009 | 12       | 5000  |\n| 7       | 200        | 2011 | 15       | 9000  |\n+---------+------------+------+----------+-------+\n\nProduct table:\n+------------+--------------+\n| product_id | product_name |\n+------------+--------------+\n| 100        | Nokia        |\n| 200        | Apple        |\n| 300        | Samsung      |\n+------------+--------------+\n\nResult table:\n+------------+------------+----------+-------+\n| product_id | first_year | quantity | price |\n+------------+------------+----------+-------+ \n| 100        | 2008       | 10       | 5000  |\n| 200        | 2011       | 15       | 9000  |\n+------------+------------+----------+-------+\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1070](https://leetcode-cn.com/problems/product-sales-analysis-iii)", "[\u4ea7\u54c1\u9500\u552e\u5206\u6790 III](/solution/1000-1099/1070.Product%20Sales%20Analysis%20III/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1070](https://leetcode.com/problems/product-sales-analysis-iii)", "[Product Sales Analysis III](/solution/1000-1099/1070.Product%20Sales%20Analysis%20III/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1154", "frontend_question_id": "1069", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/product-sales-analysis-ii", "url_en": "https://leetcode.com/problems/product-sales-analysis-ii", "relative_path_cn": "/solution/1000-1099/1069.Product%20Sales%20Analysis%20II/README.md", "relative_path_en": "/solution/1000-1099/1069.Product%20Sales%20Analysis%20II/README_EN.md", "title_cn": "\u4ea7\u54c1\u9500\u552e\u5206\u6790 II", "title_en": "Product Sales Analysis II", "question_title_slug": "product-sales-analysis-ii", "content_en": "

    Table: Sales

    \r\n\r\n
    \r\n+-------------+-------+\r\n| Column Name | Type  |\r\n+-------------+-------+\r\n| sale_id     | int   |\r\n| product_id  | int   |\r\n| year        | int   |\r\n| quantity    | int   |\r\n| price       | int   |\r\n+-------------+-------+\r\nsale_id is the primary key of this table.\r\nproduct_id is a foreign key to Product table.\r\nNote that the price is per unit.\r\n
    \r\n\r\n

    Table: Product

    \r\n\r\n
    \r\n+--------------+---------+\r\n| Column Name  | Type    |\r\n+--------------+---------+\r\n| product_id   | int     |\r\n| product_name | varchar |\r\n+--------------+---------+\r\nproduct_id is the primary key of this table.\r\n
    \r\n\r\n

     

    \r\n\r\n

    Write an SQL query that reports the total quantity sold for every product id.

    \r\n\r\n

    The query result format is in the following example:

    \r\n\r\n
    \r\nSales table:\r\n+---------+------------+------+----------+-------+\r\n| sale_id | product_id | year | quantity | price |\r\n+---------+------------+------+----------+-------+ \r\n| 1       | 100        | 2008 | 10       | 5000  |\r\n| 2       | 100        | 2009 | 12       | 5000  |\r\n| 7       | 200        | 2011 | 15       | 9000  |\r\n+---------+------------+------+----------+-------+\r\n\r\nProduct table:\r\n+------------+--------------+\r\n| product_id | product_name |\r\n+------------+--------------+\r\n| 100        | Nokia        |\r\n| 200        | Apple        |\r\n| 300        | Samsung      |\r\n+------------+--------------+\r\n\r\nResult table:\r\n+--------------+----------------+\r\n| product_id   | total_quantity |\r\n+--------------+----------------+\r\n| 100          | 22             |\r\n| 200          | 15             |\r\n+--------------+----------------+
    \r\n", "content_cn": "

    \u9500\u552e\u8868\uff1aSales

    \n\n
    +-------------+-------+\n| Column Name | Type  |\n+-------------+-------+\n| sale_id     | int   |\n| product_id  | int   |\n| year        | int   |\n| quantity    | int   |\n| price       | int   |\n+-------------+-------+\nsale_id \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\u3002\nproduct_id \u662f Product \u8868\u7684\u5916\u952e\u3002\n\u8bf7\u6ce8\u610f\u4ef7\u683c\u662f\u6bcf\u5355\u4f4d\u7684\u3002\n
    \n\n

    \u4ea7\u54c1\u8868\uff1aProduct

    \n\n
    +--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| product_id   | int     |\n| product_name | varchar |\n+--------------+---------+\nproduct_id \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\u3002\n
    \n\n

     

    \n\n

    \u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\uff0c\u6309\u4ea7\u54c1 id product_id \u6765\u7edf\u8ba1\u6bcf\u4e2a\u4ea7\u54c1\u7684\u9500\u552e\u603b\u91cf\u3002

    \n\n

     

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u9762\u4f8b\u5b50\u6240\u793a:

    \n\n
    Sales \u8868\uff1a\n+---------+------------+------+----------+-------+\n| sale_id | product_id | year | quantity | price |\n+---------+------------+------+----------+-------+ \n| 1       | 100        | 2008 | 10       | 5000  |\n| 2       | 100        | 2009 | 12       | 5000  |\n| 7       | 200        | 2011 | 15       | 9000  |\n+---------+------------+------+----------+-------+\n\nProduct \u8868\uff1a\n+------------+--------------+\n| product_id | product_name |\n+------------+--------------+\n| 100        | Nokia        |\n| 200        | Apple        |\n| 300        | Samsung      |\n+------------+--------------+\n\nResult \u8868\uff1a\n+--------------+----------------+\n| product_id   | total_quantity |\n+--------------+----------------+\n| 100          | 22             |\n| 200          | 15             |\n+--------------+----------------+
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1069](https://leetcode-cn.com/problems/product-sales-analysis-ii)", "[\u4ea7\u54c1\u9500\u552e\u5206\u6790 II](/solution/1000-1099/1069.Product%20Sales%20Analysis%20II/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1069](https://leetcode.com/problems/product-sales-analysis-ii)", "[Product Sales Analysis II](/solution/1000-1099/1069.Product%20Sales%20Analysis%20II/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1153", "frontend_question_id": "1068", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/product-sales-analysis-i", "url_en": "https://leetcode.com/problems/product-sales-analysis-i", "relative_path_cn": "/solution/1000-1099/1068.Product%20Sales%20Analysis%20I/README.md", "relative_path_en": "/solution/1000-1099/1068.Product%20Sales%20Analysis%20I/README_EN.md", "title_cn": "\u4ea7\u54c1\u9500\u552e\u5206\u6790 I", "title_en": "Product Sales Analysis I", "question_title_slug": "product-sales-analysis-i", "content_en": "

    Table: Sales

    \n\n
    \n+-------------+-------+\n| Column Name | Type  |\n+-------------+-------+\n| sale_id     | int   |\n| product_id  | int   |\n| year        | int   |\n| quantity    | int   |\n| price       | int   |\n+-------------+-------+\n(sale_id, year) is the primary key of this table.\nproduct_id is a foreign key to Product table.\nNote that the price is per unit.\n
    \n\n

     

    \n\n

    Table: Product

    \n\n
    \n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| product_id   | int     |\n| product_name | varchar |\n+--------------+---------+\nproduct_id is the primary key of this table.\n
    \n\n

     

    \n\n

    Write an SQL query that reports the product_name, year, and price for each sale_id in the Sales table.

    \n\n

    Return the resulting table in any order.

    \n\n

    The query result format is in the following example:

    \n\n

     

    \n\n
    \nSales table:\n+---------+------------+------+----------+-------+\n| sale_id | product_id | year | quantity | price |\n+---------+------------+------+----------+-------+ \n| 1       | 100        | 2008 | 10       | 5000  |\n| 2       | 100        | 2009 | 12       | 5000  |\n| 7       | 200        | 2011 | 15       | 9000  |\n+---------+------------+------+----------+-------+\n\nProduct table:\n+------------+--------------+\n| product_id | product_name |\n+------------+--------------+\n| 100        | Nokia        |\n| 200        | Apple        |\n| 300        | Samsung      |\n+------------+--------------+\n\nResult table:\n+--------------+-------+-------+\n| product_name | year  | price |\n+--------------+-------+-------+\n| Nokia        | 2008  | 5000  |\n| Nokia        | 2009  | 5000  |\n| Apple        | 2011  | 9000  |\n+--------------+-------+-------+\nFrom sale_id = 1, we can conclude that Nokia was sold for 5000 in the year 2008.\nFrom sale_id = 2, we can conclude that Nokia was sold for 5000 in the year 2009.\nFrom sale_id = 7, we can conclude that Apple was sold for 9000 in the year 2011.\n
    \n", "content_cn": "

    \u9500\u552e\u8868 Sales\uff1a

    \n\n
    +-------------+-------+\n| Column Name | Type  |\n+-------------+-------+\n| sale_id     | int   |\n| product_id  | int   |\n| year        | int   |\n| quantity    | int   |\n| price       | int   |\n+-------------+-------+\n(sale_id, year) \u662f\u9500\u552e\u8868 Sales \u7684\u4e3b\u952e.\nproduct_id \u662f\u5173\u8054\u5230\u4ea7\u54c1\u8868 Product \u7684\u5916\u952e.\n\u6ce8\u610f: price \u8868\u793a\u6bcf\u5355\u4f4d\u4ef7\u683c\n
    \n\n

    \u4ea7\u54c1\u8868 Product\uff1a

    \n\n
    +--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| product_id   | int     |\n| product_name | varchar |\n+--------------+---------+\nproduct_id \u662f\u8868\u7684\u4e3b\u952e.\n
    \n\n

     

    \n\n

    \u5199\u4e00\u6761SQL \u67e5\u8be2\u8bed\u53e5\u83b7\u53d6 Sales \u8868\u4e2d\u6240\u6709\u4ea7\u54c1\u5bf9\u5e94\u7684 \u4ea7\u54c1\u540d\u79f0 product_name \u4ee5\u53ca\u8be5\u4ea7\u54c1\u7684\u6240\u6709 \u552e\u5356\u5e74\u4efd year \u548c \u4ef7\u683c price \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    Sales \u8868\uff1a\n+---------+------------+------+----------+-------+\n| sale_id | product_id | year | quantity | price |\n+---------+------------+------+----------+-------+ \n| 1       | 100        | 2008 | 10       | 5000  |\n| 2       | 100        | 2009 | 12       | 5000  |\n| 7       | 200        | 2011 | 15       | 9000  |\n+---------+------------+------+----------+-------+\n\nProduct \u8868\uff1a\n+------------+--------------+\n| product_id | product_name |\n+------------+--------------+\n| 100        | Nokia        |\n| 200        | Apple        |\n| 300        | Samsung      |\n+------------+--------------+\n\nResult \u8868\uff1a\n+--------------+-------+-------+\n| product_name | year  | price |\n+--------------+-------+-------+\n| Nokia        | 2008  | 5000  |\n| Nokia        | 2009  | 5000  |\n| Apple        | 2011  | 9000  |\n+--------------+-------+-------+\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1068](https://leetcode-cn.com/problems/product-sales-analysis-i)", "[\u4ea7\u54c1\u9500\u552e\u5206\u6790 I](/solution/1000-1099/1068.Product%20Sales%20Analysis%20I/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1068](https://leetcode.com/problems/product-sales-analysis-i)", "[Product Sales Analysis I](/solution/1000-1099/1068.Product%20Sales%20Analysis%20I/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1152", "frontend_question_id": "1183", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/maximum-number-of-ones", "url_en": "https://leetcode.com/problems/maximum-number-of-ones", "relative_path_cn": "/solution/1100-1199/1183.Maximum%20Number%20of%20Ones/README.md", "relative_path_en": "/solution/1100-1199/1183.Maximum%20Number%20of%20Ones/README_EN.md", "title_cn": "\u77e9\u9635\u4e2d 1 \u7684\u6700\u5927\u6570\u91cf", "title_en": "Maximum Number of Ones", "question_title_slug": "maximum-number-of-ones", "content_en": "

    Consider a matrix M with dimensions width * height, such that every cell has value 0 or 1, and any square sub-matrix of M of size sideLength * sideLength has at most maxOnes ones.

    \n\n

    Return the maximum possible number of ones that the matrix M can have.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: width = 3, height = 3, sideLength = 2, maxOnes = 1\nOutput: 4\nExplanation:\nIn a 3*3 matrix, no 2*2 sub-matrix can have more than 1 one.\nThe best solution that has 4 ones is:\n[1,0,1]\n[0,0,0]\n[1,0,1]\n
    \n\n

    Example 2:

    \n\n
    \nInput: width = 3, height = 3, sideLength = 2, maxOnes = 2\nOutput: 6\nExplanation:\n[1,0,1]\n[1,0,1]\n[1,0,1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= width, height <= 100
    • \n\t
    • 1 <= sideLength <= width, height
    • \n\t
    • 0 <= maxOnes <= sideLength * sideLength
    • \n
    \n", "content_cn": "

    \u73b0\u5728\u6709\u4e00\u4e2a\u5c3a\u5bf8\u4e3a width * height \u7684\u77e9\u9635 M\uff0c\u77e9\u9635\u4e2d\u7684\u6bcf\u4e2a\u5355\u5143\u683c\u7684\u503c\u4e0d\u662f 0 \u5c31\u662f 1\u3002

    \n\n

    \u800c\u4e14\u77e9\u9635 M \u4e2d\u6bcf\u4e2a\u5927\u5c0f\u4e3a sideLength * sideLength \u7684 \u6b63\u65b9\u5f62 \u5b50\u9635\u4e2d\uff0c1 \u7684\u6570\u91cf\u4e0d\u5f97\u8d85\u8fc7 maxOnes\u3002

    \n\n

    \u8bf7\u4f60\u8bbe\u8ba1\u4e00\u4e2a\u7b97\u6cd5\uff0c\u8ba1\u7b97\u77e9\u9635\u4e2d\u6700\u591a\u53ef\u4ee5\u6709\u591a\u5c11\u4e2a 1\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1awidth = 3, height = 3, sideLength = 2, maxOnes = 1\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\n\u9898\u76ee\u8981\u6c42\uff1a\u5728\u4e00\u4e2a 3*3 \u7684\u77e9\u9635\u4e2d\uff0c\u6bcf\u4e00\u4e2a 2*2 \u7684\u5b50\u9635\u4e2d\u7684 1 \u7684\u6570\u76ee\u4e0d\u8d85\u8fc7 1 \u4e2a\u3002\n\u6700\u597d\u7684\u89e3\u51b3\u65b9\u6848\u4e2d\uff0c\u77e9\u9635 M \u91cc\u6700\u591a\u53ef\u4ee5\u6709 4 \u4e2a 1\uff0c\u5982\u4e0b\u6240\u793a\uff1a\n[1,0,1]\n[0,0,0]\n[1,0,1]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1awidth = 3, height = 3, sideLength = 2, maxOnes = 2\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\n[1,0,1]\n[1,0,1]\n[1,0,1]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= width, height <= 100
    • \n\t
    • 1 <= sideLength <= width, height
    • \n\t
    • 0 <= maxOnes <= sideLength * sideLength
    • \n
    \n", "tags_en": ["Sort", "Math"], "tags_cn": ["\u6392\u5e8f", "\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maximumNumberOfOnes(int width, int height, int sideLength, int maxOnes) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maximumNumberOfOnes(int width, int height, int sideLength, int maxOnes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximumNumberOfOnes(self, width, height, sideLength, maxOnes):\n \"\"\"\n :type width: int\n :type height: int\n :type sideLength: int\n :type maxOnes: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximumNumberOfOnes(self, width: int, height: int, sideLength: int, maxOnes: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maximumNumberOfOnes(int width, int height, int sideLength, int maxOnes){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaximumNumberOfOnes(int width, int height, int sideLength, int maxOnes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} width\n * @param {number} height\n * @param {number} sideLength\n * @param {number} maxOnes\n * @return {number}\n */\nvar maximumNumberOfOnes = function(width, height, sideLength, maxOnes) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} width\n# @param {Integer} height\n# @param {Integer} side_length\n# @param {Integer} max_ones\n# @return {Integer}\ndef maximum_number_of_ones(width, height, side_length, max_ones)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximumNumberOfOnes(_ width: Int, _ height: Int, _ sideLength: Int, _ maxOnes: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximumNumberOfOnes(width int, height int, sideLength int, maxOnes int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximumNumberOfOnes(width: Int, height: Int, sideLength: Int, maxOnes: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximumNumberOfOnes(width: Int, height: Int, sideLength: Int, maxOnes: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximum_number_of_ones(width: i32, height: i32, side_length: i32, max_ones: i32) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $width\n * @param Integer $height\n * @param Integer $sideLength\n * @param Integer $maxOnes\n * @return Integer\n */\n function maximumNumberOfOnes($width, $height, $sideLength, $maxOnes) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximumNumberOfOnes(width: number, height: number, sideLength: number, maxOnes: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximum-number-of-ones width height sideLength maxOnes)\n (-> exact-integer? exact-integer? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1183](https://leetcode-cn.com/problems/maximum-number-of-ones)", "[\u77e9\u9635\u4e2d 1 \u7684\u6700\u5927\u6570\u91cf](/solution/1100-1199/1183.Maximum%20Number%20of%20Ones/README.md)", "`\u6392\u5e8f`,`\u6570\u5b66`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1183](https://leetcode.com/problems/maximum-number-of-ones)", "[Maximum Number of Ones](/solution/1100-1199/1183.Maximum%20Number%20of%20Ones/README_EN.md)", "`Sort`,`Math`", "Hard", "\ud83d\udd12"]}, {"question_id": "1151", "frontend_question_id": "1215", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/stepping-numbers", "url_en": "https://leetcode.com/problems/stepping-numbers", "relative_path_cn": "/solution/1200-1299/1215.Stepping%20Numbers/README.md", "relative_path_en": "/solution/1200-1299/1215.Stepping%20Numbers/README_EN.md", "title_cn": "\u6b65\u8fdb\u6570", "title_en": "Stepping Numbers", "question_title_slug": "stepping-numbers", "content_en": "

    A Stepping Number is an integer such that all of its adjacent digits have an absolute difference of exactly 1. For example, 321 is a Stepping Number while 421 is not.

    \n\n

    Given two integers low and high, find and return a sorted list of all the Stepping Numbers in the range [low, high] inclusive.

    \n\n

     

    \n

    Example 1:

    \n
    Input: low = 0, high = 21\nOutput: [0,1,2,3,4,5,6,7,8,9,10,12,21]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= low <= high <= 2 * 10^9
    • \n
    \n", "content_cn": "

    \u5982\u679c\u4e00\u4e2a\u6574\u6570\u4e0a\u7684\u6bcf\u4e00\u4f4d\u6570\u5b57\u4e0e\u5176\u76f8\u90bb\u4f4d\u4e0a\u7684\u6570\u5b57\u7684\u7edd\u5bf9\u5dee\u90fd\u662f 1\uff0c\u90a3\u4e48\u8fd9\u4e2a\u6570\u5c31\u662f\u4e00\u4e2a\u300c\u6b65\u8fdb\u6570\u300d\u3002

    \n\n

    \u4f8b\u5982\uff0c321 \u662f\u4e00\u4e2a\u6b65\u8fdb\u6570\uff0c\u800c 421 \u4e0d\u662f\u3002

    \n\n

    \u7ed9\u4f60\u4e24\u4e2a\u6574\u6570\uff0clow \u548c high\uff0c\u8bf7\u4f60\u627e\u51fa\u5728 [low, high] \u8303\u56f4\u5185\u7684\u6240\u6709\u6b65\u8fdb\u6570\uff0c\u5e76\u8fd4\u56de \u6392\u5e8f\u540e \u7684\u7ed3\u679c\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1alow = 0, high = 21\n\u8f93\u51fa\uff1a[0,1,2,3,4,5,6,7,8,9,10,12,21]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= low <= high <= 2 * 10^9
    • \n
    \n", "tags_en": ["Backtracking"], "tags_cn": ["\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector countSteppingNumbers(int low, int high) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List countSteppingNumbers(int low, int high) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countSteppingNumbers(self, low, high):\n \"\"\"\n :type low: int\n :type high: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countSteppingNumbers(self, low: int, high: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* countSteppingNumbers(int low, int high, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList CountSteppingNumbers(int low, int high) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} low\n * @param {number} high\n * @return {number[]}\n */\nvar countSteppingNumbers = function(low, high) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} low\n# @param {Integer} high\n# @return {Integer[]}\ndef count_stepping_numbers(low, high)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countSteppingNumbers(_ low: Int, _ high: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countSteppingNumbers(low int, high int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countSteppingNumbers(low: Int, high: Int): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countSteppingNumbers(low: Int, high: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_stepping_numbers(low: i32, high: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $low\n * @param Integer $high\n * @return Integer[]\n */\n function countSteppingNumbers($low, $high) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countSteppingNumbers(low: number, high: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-stepping-numbers low high)\n (-> exact-integer? exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1215](https://leetcode-cn.com/problems/stepping-numbers)", "[\u6b65\u8fdb\u6570](/solution/1200-1299/1215.Stepping%20Numbers/README.md)", "`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1215](https://leetcode.com/problems/stepping-numbers)", "[Stepping Numbers](/solution/1200-1299/1215.Stepping%20Numbers/README_EN.md)", "`Backtracking`", "Medium", "\ud83d\udd12"]}, {"question_id": "1150", "frontend_question_id": "1214", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/two-sum-bsts", "url_en": "https://leetcode.com/problems/two-sum-bsts", "relative_path_cn": "/solution/1200-1299/1214.Two%20Sum%20BSTs/README.md", "relative_path_en": "/solution/1200-1299/1214.Two%20Sum%20BSTs/README_EN.md", "title_cn": "\u67e5\u627e\u4e24\u68f5\u4e8c\u53c9\u641c\u7d22\u6811\u4e4b\u548c", "title_en": "Two Sum BSTs", "question_title_slug": "two-sum-bsts", "content_en": "

    Given the roots of two binary search trees, root1 and root2, return true if and only if there is a node in the first tree and a node in the second tree whose values sum up to a given integer target.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root1 = [2,1,4], root2 = [1,0,3], target = 5\nOutput: true\nExplanation: 2 and 3 sum up to 5.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root1 = [0,-10,10], root2 = [5,1,7,0,2], target = 18\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in each tree is in the range [1, 5000].
    • \n\t
    • -109 <= Node.val, target <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u51fa\u4e24\u68f5\u4e8c\u53c9\u641c\u7d22\u6811\uff0c\u8bf7\u4f60\u4ece\u4e24\u68f5\u6811\u4e2d\u5404\u627e\u51fa\u4e00\u4e2a\u8282\u70b9\uff0c\u4f7f\u5f97\u8fd9\u4e24\u4e2a\u8282\u70b9\u7684\u503c\u4e4b\u548c\u7b49\u4e8e\u76ee\u6807\u503c Target\u3002

    \n\n

    \u5982\u679c\u53ef\u4ee5\u627e\u5230\u8fd4\u56de True\uff0c\u5426\u5219\u8fd4\u56de False\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"\"\"

    \n\n
    \u8f93\u5165\uff1aroot1 = [2,1,4], root2 = [1,0,3], target = 5\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a2 \u52a0 3 \u548c\u4e3a 5 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"\"\"

    \n\n
    \u8f93\u5165\uff1aroot1 = [0,-10,10], root2 = [5,1,7,0,2], target = 18\n\u8f93\u51fa\uff1afalse
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. \u6bcf\u68f5\u6811\u4e0a\u6700\u591a\u6709 5000 \u4e2a\u8282\u70b9\u3002
    2. \n\t
    3. -10^9 <= target, node.val <= 10^9
    4. \n
    \n", "tags_en": ["Binary Search Tree"], "tags_cn": ["\u4e8c\u53c9\u641c\u7d22\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n bool twoSumBSTs(TreeNode* root1, TreeNode* root2, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public boolean twoSumBSTs(TreeNode root1, TreeNode root2, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def twoSumBSTs(self, root1, root2, target):\n \"\"\"\n :type root1: TreeNode\n :type root2: TreeNode\n :type target: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def twoSumBSTs(self, root1: TreeNode, root2: TreeNode, target: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nbool twoSumBSTs(struct TreeNode* root1, struct TreeNode* root2, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public bool TwoSumBSTs(TreeNode root1, TreeNode root2, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root1\n * @param {TreeNode} root2\n * @param {number} target\n * @return {boolean}\n */\nvar twoSumBSTs = function(root1, root2, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root1\n# @param {TreeNode} root2\n# @param {Integer} target\n# @return {Boolean}\ndef two_sum_bs_ts(root1, root2, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func twoSumBSTs(_ root1: TreeNode?, _ root2: TreeNode?, _ target: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc twoSumBSTs(root1 *TreeNode, root2 *TreeNode, target int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def twoSumBSTs(root1: TreeNode, root2: TreeNode, target: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun twoSumBSTs(root1: TreeNode?, root2: TreeNode?, target: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn two_sum_bs_ts(root1: Option>>, root2: Option>>, target: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root1\n * @param TreeNode $root2\n * @param Integer $target\n * @return Boolean\n */\n function twoSumBSTs($root1, $root2, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction twoSumBSTs(root1: TreeNode | null, root2: TreeNode | null, target: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (two-sum-bs-ts root1 root2 target)\n (-> (or/c tree-node? #f) (or/c tree-node? #f) exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1214](https://leetcode-cn.com/problems/two-sum-bsts)", "[\u67e5\u627e\u4e24\u68f5\u4e8c\u53c9\u641c\u7d22\u6811\u4e4b\u548c](/solution/1200-1299/1214.Two%20Sum%20BSTs/README.md)", "`\u4e8c\u53c9\u641c\u7d22\u6811`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1214](https://leetcode.com/problems/two-sum-bsts)", "[Two Sum BSTs](/solution/1200-1299/1214.Two%20Sum%20BSTs/README_EN.md)", "`Binary Search Tree`", "Medium", "\ud83d\udd12"]}, {"question_id": "1149", "frontend_question_id": "1213", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/intersection-of-three-sorted-arrays", "url_en": "https://leetcode.com/problems/intersection-of-three-sorted-arrays", "relative_path_cn": "/solution/1200-1299/1213.Intersection%20of%20Three%20Sorted%20Arrays/README.md", "relative_path_en": "/solution/1200-1299/1213.Intersection%20of%20Three%20Sorted%20Arrays/README_EN.md", "title_cn": "\u4e09\u4e2a\u6709\u5e8f\u6570\u7ec4\u7684\u4ea4\u96c6", "title_en": "Intersection of Three Sorted Arrays", "question_title_slug": "intersection-of-three-sorted-arrays", "content_en": "

    Given three integer arrays arr1, arr2 and arr3 sorted in strictly increasing order, return a sorted array of only the integers that appeared in all three arrays.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr1 = [1,2,3,4,5], arr2 = [1,2,5,7,9], arr3 = [1,3,4,5,8]\nOutput: [1,5]\nExplanation: Only 1 and 5 appeared in the three arrays.\n
    \n\n

    Example 2:

    \n\n
    \nInput: arr1 = [197,418,523,876,1356], arr2 = [501,880,1593,1710,1870], arr3 = [521,682,1337,1395,1764]\nOutput: []\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= arr1.length, arr2.length, arr3.length <= 1000
    • \n\t
    • 1 <= arr1[i], arr2[i], arr3[i] <= 2000
    • \n
    \n", "content_cn": "

    \u7ed9\u51fa\u4e09\u4e2a\u5747\u4e3a \u4e25\u683c\u9012\u589e\u6392\u5217 \u7684\u6574\u6570\u6570\u7ec4 arr1\uff0carr2 \u548c arr3\u3002

    \n\n

    \u8fd4\u56de\u4e00\u4e2a\u7531 \u4ec5 \u5728\u8fd9\u4e09\u4e2a\u6570\u7ec4\u4e2d \u540c\u65f6\u51fa\u73b0 \u7684\u6574\u6570\u6240\u6784\u6210\u7684\u6709\u5e8f\u6570\u7ec4\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165: arr1 = [1,2,3,4,5], arr2 = [1,2,5,7,9], arr3 = [1,3,4,5,8]\n\u8f93\u51fa: [1,5]\n\u89e3\u91ca: \u53ea\u6709 1 \u548c 5 \u540c\u65f6\u5728\u8fd9\u4e09\u4e2a\u6570\u7ec4\u4e2d\u51fa\u73b0.\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= arr1.length, arr2.length, arr3.length <= 1000
    2. \n\t
    3. 1 <= arr1[i], arr2[i], arr3[i] <= 2000
    4. \n
    \n", "tags_en": ["Hash Table", "Two Pointers"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u53cc\u6307\u9488"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector arraysIntersection(vector& arr1, vector& arr2, vector& arr3) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List arraysIntersection(int[] arr1, int[] arr2, int[] arr3) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def arraysIntersection(self, arr1, arr2, arr3):\n \"\"\"\n :type arr1: List[int]\n :type arr2: List[int]\n :type arr3: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def arraysIntersection(self, arr1: List[int], arr2: List[int], arr3: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* arraysIntersection(int* arr1, int arr1Size, int* arr2, int arr2Size, int* arr3, int arr3Size, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList ArraysIntersection(int[] arr1, int[] arr2, int[] arr3) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr1\n * @param {number[]} arr2\n * @param {number[]} arr3\n * @return {number[]}\n */\nvar arraysIntersection = function(arr1, arr2, arr3) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr1\n# @param {Integer[]} arr2\n# @param {Integer[]} arr3\n# @return {Integer[]}\ndef arrays_intersection(arr1, arr2, arr3)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func arraysIntersection(_ arr1: [Int], _ arr2: [Int], _ arr3: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func arraysIntersection(arr1 []int, arr2 []int, arr3 []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def arraysIntersection(arr1: Array[Int], arr2: Array[Int], arr3: Array[Int]): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun arraysIntersection(arr1: IntArray, arr2: IntArray, arr3: IntArray): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn arrays_intersection(arr1: Vec, arr2: Vec, arr3: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr1\n * @param Integer[] $arr2\n * @param Integer[] $arr3\n * @return Integer[]\n */\n function arraysIntersection($arr1, $arr2, $arr3) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function arraysIntersection(arr1: number[], arr2: number[], arr3: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (arrays-intersection arr1 arr2 arr3)\n (-> (listof exact-integer?) (listof exact-integer?) (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1213](https://leetcode-cn.com/problems/intersection-of-three-sorted-arrays)", "[\u4e09\u4e2a\u6709\u5e8f\u6570\u7ec4\u7684\u4ea4\u96c6](/solution/1200-1299/1213.Intersection%20of%20Three%20Sorted%20Arrays/README.md)", "`\u54c8\u5e0c\u8868`,`\u53cc\u6307\u9488`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1213](https://leetcode.com/problems/intersection-of-three-sorted-arrays)", "[Intersection of Three Sorted Arrays](/solution/1200-1299/1213.Intersection%20of%20Three%20Sorted%20Arrays/README_EN.md)", "`Hash Table`,`Two Pointers`", "Easy", "\ud83d\udd12"]}, {"question_id": "1148", "frontend_question_id": "1073", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/adding-two-negabinary-numbers", "url_en": "https://leetcode.com/problems/adding-two-negabinary-numbers", "relative_path_cn": "/solution/1000-1099/1073.Adding%20Two%20Negabinary%20Numbers/README.md", "relative_path_en": "/solution/1000-1099/1073.Adding%20Two%20Negabinary%20Numbers/README_EN.md", "title_cn": "\u8d1f\u4e8c\u8fdb\u5236\u6570\u76f8\u52a0", "title_en": "Adding Two Negabinary Numbers", "question_title_slug": "adding-two-negabinary-numbers", "content_en": "

    Given two numbers arr1 and arr2 in base -2, return the result of adding them together.

    \n\n

    Each number is given in array format:  as an array of 0s and 1s, from most significant bit to least significant bit.  For example, arr = [1,1,0,1] represents the number (-2)^3 + (-2)^2 + (-2)^0 = -3.  A number arr in array, format is also guaranteed to have no leading zeros: either arr == [0] or arr[0] == 1.

    \n\n

    Return the result of adding arr1 and arr2 in the same format: as an array of 0s and 1s with no leading zeros.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr1 = [1,1,1,1,1], arr2 = [1,0,1]\nOutput: [1,0,0,0,0]\nExplanation: arr1 represents 11, arr2 represents 5, the output represents 16.\n
    \n\n

    Example 2:

    \n\n
    \nInput: arr1 = [0], arr2 = [0]\nOutput: [0]\n
    \n\n

    Example 3:

    \n\n
    \nInput: arr1 = [0], arr2 = [1]\nOutput: [1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= arr1.length, arr2.length <= 1000
    • \n\t
    • arr1[i] and arr2[i] are 0 or 1
    • \n\t
    • arr1 and arr2 have no leading zeros
    • \n
    \n", "content_cn": "

    \u7ed9\u51fa\u57fa\u6570\u4e3a -2 \u7684\u4e24\u4e2a\u6570 arr1 \u548c arr2\uff0c\u8fd4\u56de\u4e24\u6570\u76f8\u52a0\u7684\u7ed3\u679c\u3002

    \n\n

    \u6570\u5b57\u4ee5 \u6570\u7ec4\u5f62\u5f0f \u7ed9\u51fa\uff1a\u6570\u7ec4\u7531\u82e5\u5e72 0 \u548c 1 \u7ec4\u6210\uff0c\u6309\u6700\u9ad8\u6709\u6548\u4f4d\u5230\u6700\u4f4e\u6709\u6548\u4f4d\u7684\u987a\u5e8f\u6392\u5217\u3002\u4f8b\u5982\uff0carr = [1,1,0,1] \u8868\u793a\u6570\u5b57 (-2)^3 + (-2)^2 + (-2)^0 = -3\u3002\u6570\u7ec4\u5f62\u5f0f \u7684\u6570\u5b57\u4e5f\u540c\u6837\u4e0d\u542b\u524d\u5bfc\u96f6\uff1a\u4ee5 arr \u4e3a\u4f8b\uff0c\u8fd9\u610f\u5473\u7740\u8981\u4e48 arr == [0]\uff0c\u8981\u4e48 arr[0] == 1\u3002

    \n\n

    \u8fd4\u56de\u76f8\u540c\u8868\u793a\u5f62\u5f0f\u7684 arr1 \u548c arr2 \u76f8\u52a0\u7684\u7ed3\u679c\u3002\u4e24\u6570\u7684\u8868\u793a\u5f62\u5f0f\u4e3a\uff1a\u4e0d\u542b\u524d\u5bfc\u96f6\u3001\u7531\u82e5\u5e72 0 \u548c 1 \u7ec4\u6210\u7684\u6570\u7ec4\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1aarr1 = [1,1,1,1,1], arr2 = [1,0,1]\n\u8f93\u51fa\uff1a[1,0,0,0,0]\n\u89e3\u91ca\uff1aarr1 \u8868\u793a 11\uff0carr2 \u8868\u793a 5\uff0c\u8f93\u51fa\u8868\u793a 16 \u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= arr1.length <= 1000
    2. \n\t
    3. 1 <= arr2.length <= 1000
    4. \n\t
    5. arr1 \u548c arr2 \u90fd\u4e0d\u542b\u524d\u5bfc\u96f6
    6. \n\t
    7. arr1[i] \u4e3a 0 \u6216 1
    8. \n\t
    9. arr2[i] \u4e3a 0 \u6216 1
    10. \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector addNegabinary(vector& arr1, vector& arr2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] addNegabinary(int[] arr1, int[] arr2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def addNegabinary(self, arr1, arr2):\n \"\"\"\n :type arr1: List[int]\n :type arr2: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def addNegabinary(self, arr1: List[int], arr2: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* addNegabinary(int* arr1, int arr1Size, int* arr2, int arr2Size, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] AddNegabinary(int[] arr1, int[] arr2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr1\n * @param {number[]} arr2\n * @return {number[]}\n */\nvar addNegabinary = function(arr1, arr2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr1\n# @param {Integer[]} arr2\n# @return {Integer[]}\ndef add_negabinary(arr1, arr2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func addNegabinary(_ arr1: [Int], _ arr2: [Int]) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func addNegabinary(arr1 []int, arr2 []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def addNegabinary(arr1: Array[Int], arr2: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun addNegabinary(arr1: IntArray, arr2: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn add_negabinary(arr1: Vec, arr2: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr1\n * @param Integer[] $arr2\n * @return Integer[]\n */\n function addNegabinary($arr1, $arr2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function addNegabinary(arr1: number[], arr2: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (add-negabinary arr1 arr2)\n (-> (listof exact-integer?) (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1073](https://leetcode-cn.com/problems/adding-two-negabinary-numbers)", "[\u8d1f\u4e8c\u8fdb\u5236\u6570\u76f8\u52a0](/solution/1000-1099/1073.Adding%20Two%20Negabinary%20Numbers/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1073](https://leetcode.com/problems/adding-two-negabinary-numbers)", "[Adding Two Negabinary Numbers](/solution/1000-1099/1073.Adding%20Two%20Negabinary%20Numbers/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "1147", "frontend_question_id": "1072", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/flip-columns-for-maximum-number-of-equal-rows", "url_en": "https://leetcode.com/problems/flip-columns-for-maximum-number-of-equal-rows", "relative_path_cn": "/solution/1000-1099/1072.Flip%20Columns%20For%20Maximum%20Number%20of%20Equal%20Rows/README.md", "relative_path_en": "/solution/1000-1099/1072.Flip%20Columns%20For%20Maximum%20Number%20of%20Equal%20Rows/README_EN.md", "title_cn": "\u6309\u5217\u7ffb\u8f6c\u5f97\u5230\u6700\u5927\u503c\u7b49\u884c\u6570", "title_en": "Flip Columns For Maximum Number of Equal Rows", "question_title_slug": "flip-columns-for-maximum-number-of-equal-rows", "content_en": "

    You are given an m x n binary matrix matrix.

    \n\n

    You can choose any number of columns in the matrix and flip every cell in that column (i.e., Change the value of the cell from 0 to 1 or vice versa).

    \n\n

    Return the maximum number of rows that have all values equal after some number of flips.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: matrix = [[0,1],[1,1]]\nOutput: 1\nExplanation: After flipping no values, 1 row has all values equal.\n
    \n\n

    Example 2:

    \n\n
    \nInput: matrix = [[0,1],[1,0]]\nOutput: 2\nExplanation: After flipping values in the first column, both rows have equal values.\n
    \n\n

    Example 3:

    \n\n
    \nInput: matrix = [[0,0,0],[0,0,1],[1,1,0]]\nOutput: 2\nExplanation: After flipping values in the first two columns, the last two rows have equal values.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == matrix.length
    • \n\t
    • n == matrix[i].length
    • \n\t
    • 1 <= m, n <= 300
    • \n\t
    • matrix[i][j] is either 0 or 1.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u7531\u82e5\u5e72 0 \u548c 1 \u7ec4\u6210\u7684\u77e9\u9635\u00a0matrix\uff0c\u4ece\u4e2d\u9009\u51fa\u4efb\u610f\u6570\u91cf\u7684\u5217\u5e76\u7ffb\u8f6c\u5176\u4e0a\u7684\u00a0\u6bcf\u4e2a\u00a0\u5355\u5143\u683c\u3002\u7ffb\u8f6c\u540e\uff0c\u5355\u5143\u683c\u7684\u503c\u4ece 0 \u53d8\u6210 1\uff0c\u6216\u8005\u4ece 1 \u53d8\u4e3a 0 \u3002

    \n\n

    \u56de\u7ecf\u8fc7\u4e00\u4e9b\u7ffb\u8f6c\u540e\uff0c\u884c\u4e0e\u884c\u4e4b\u95f4\u6240\u6709\u503c\u90fd\u76f8\u7b49\u7684\u6700\u5927\u884c\u6570\u3002

    \n\n

    \u00a0

    \n\n
      \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[[0,1],[1,1]]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u4e0d\u8fdb\u884c\u7ffb\u8f6c\uff0c\u6709 1 \u884c\u6240\u6709\u503c\u90fd\u76f8\u7b49\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[[0,1],[1,0]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u7ffb\u8f6c\u7b2c\u4e00\u5217\u7684\u503c\u4e4b\u540e\uff0c\u8fd9\u4e24\u884c\u90fd\u7531\u76f8\u7b49\u7684\u503c\u7ec4\u6210\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[[0,0,0],[0,0,1],[1,1,0]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u7ffb\u8f6c\u524d\u4e24\u5217\u7684\u503c\u4e4b\u540e\uff0c\u540e\u4e24\u884c\u7531\u76f8\u7b49\u7684\u503c\u7ec4\u6210\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= matrix.length <= 300
    2. \n\t
    3. 1 <= matrix[i].length <= 300
    4. \n\t
    5. \u6240\u6709 matrix[i].length\u00a0\u90fd\u76f8\u7b49
    6. \n\t
    7. matrix[i][j] \u4e3a\u00a00 \u6216\u00a01
    8. \n
    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxEqualRowsAfterFlips(vector>& matrix) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxEqualRowsAfterFlips(int[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxEqualRowsAfterFlips(self, matrix):\n \"\"\"\n :type matrix: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxEqualRowsAfterFlips(self, matrix: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxEqualRowsAfterFlips(int** matrix, int matrixSize, int* matrixColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxEqualRowsAfterFlips(int[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} matrix\n * @return {number}\n */\nvar maxEqualRowsAfterFlips = function(matrix) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} matrix\n# @return {Integer}\ndef max_equal_rows_after_flips(matrix)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxEqualRowsAfterFlips(_ matrix: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxEqualRowsAfterFlips(matrix [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxEqualRowsAfterFlips(matrix: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxEqualRowsAfterFlips(matrix: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_equal_rows_after_flips(matrix: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $matrix\n * @return Integer\n */\n function maxEqualRowsAfterFlips($matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxEqualRowsAfterFlips(matrix: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-equal-rows-after-flips matrix)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1072](https://leetcode-cn.com/problems/flip-columns-for-maximum-number-of-equal-rows)", "[\u6309\u5217\u7ffb\u8f6c\u5f97\u5230\u6700\u5927\u503c\u7b49\u884c\u6570](/solution/1000-1099/1072.Flip%20Columns%20For%20Maximum%20Number%20of%20Equal%20Rows/README.md)", "`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1072](https://leetcode.com/problems/flip-columns-for-maximum-number-of-equal-rows)", "[Flip Columns For Maximum Number of Equal Rows](/solution/1000-1099/1072.Flip%20Columns%20For%20Maximum%20Number%20of%20Equal%20Rows/README_EN.md)", "`Hash Table`", "Medium", ""]}, {"question_id": "1146", "frontend_question_id": "1071", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/greatest-common-divisor-of-strings", "url_en": "https://leetcode.com/problems/greatest-common-divisor-of-strings", "relative_path_cn": "/solution/1000-1099/1071.Greatest%20Common%20Divisor%20of%20Strings/README.md", "relative_path_en": "/solution/1000-1099/1071.Greatest%20Common%20Divisor%20of%20Strings/README_EN.md", "title_cn": "\u5b57\u7b26\u4e32\u7684\u6700\u5927\u516c\u56e0\u5b50", "title_en": "Greatest Common Divisor of Strings", "question_title_slug": "greatest-common-divisor-of-strings", "content_en": "

    For two strings s and t, we say "t divides s" if and only if s = t + ... + t  (t concatenated with itself 1 or more times)

    \n\n

    Given two strings str1 and str2, return the largest string x such that x divides both str1 and str2.

    \n\n

     

    \n

    Example 1:

    \n
    Input: str1 = \"ABCABC\", str2 = \"ABC\"\nOutput: \"ABC\"\n

    Example 2:

    \n
    Input: str1 = \"ABABAB\", str2 = \"ABAB\"\nOutput: \"AB\"\n

    Example 3:

    \n
    Input: str1 = \"LEET\", str2 = \"CODE\"\nOutput: \"\"\n

    Example 4:

    \n
    Input: str1 = \"ABCDEF\", str2 = \"ABC\"\nOutput: \"\"\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= str1.length <= 1000
    • \n\t
    • 1 <= str2.length <= 1000
    • \n\t
    • str1 and str2 consist of English uppercase letters.
    • \n
    \n", "content_cn": "

    \u5bf9\u4e8e\u5b57\u7b26\u4e32\u00a0S \u548c\u00a0T\uff0c\u53ea\u6709\u5728 S = T + ... + T\uff08T \u81ea\u8eab\u8fde\u63a5 1 \u6b21\u6216\u591a\u6b21\uff09\u65f6\uff0c\u6211\u4eec\u624d\u8ba4\u5b9a\u00a0\u201cT \u80fd\u9664\u5c3d S\u201d\u3002

    \n\n

    \u8fd4\u56de\u6700\u957f\u5b57\u7b26\u4e32\u00a0X\uff0c\u8981\u6c42\u6ee1\u8db3\u00a0X \u80fd\u9664\u5c3d str1 \u4e14\u00a0X \u80fd\u9664\u5c3d str2\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1astr1 = \"ABCABC\", str2 = \"ABC\"\n\u8f93\u51fa\uff1a\"ABC\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1astr1 = \"ABABAB\", str2 = \"ABAB\"\n\u8f93\u51fa\uff1a\"AB\"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1astr1 = \"LEET\", str2 = \"CODE\"\n\u8f93\u51fa\uff1a\"\"\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= str1.length <= 1000
    2. \n\t
    3. 1 <= str2.length <= 1000
    4. \n\t
    5. str1[i] \u548c\u00a0str2[i] \u4e3a\u5927\u5199\u82f1\u6587\u5b57\u6bcd
    6. \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string gcdOfStrings(string str1, string str2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String gcdOfStrings(String str1, String str2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def gcdOfStrings(self, str1, str2):\n \"\"\"\n :type str1: str\n :type str2: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def gcdOfStrings(self, str1: str, str2: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * gcdOfStrings(char * str1, char * str2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string GcdOfStrings(string str1, string str2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} str1\n * @param {string} str2\n * @return {string}\n */\nvar gcdOfStrings = function(str1, str2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} str1\n# @param {String} str2\n# @return {String}\ndef gcd_of_strings(str1, str2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func gcdOfStrings(_ str1: String, _ str2: String) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func gcdOfStrings(str1 string, str2 string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def gcdOfStrings(str1: String, str2: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun gcdOfStrings(str1: String, str2: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn gcd_of_strings(str1: String, str2: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $str1\n * @param String $str2\n * @return String\n */\n function gcdOfStrings($str1, $str2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function gcdOfStrings(str1: string, str2: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (gcd-of-strings str1 str2)\n (-> string? string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1071](https://leetcode-cn.com/problems/greatest-common-divisor-of-strings)", "[\u5b57\u7b26\u4e32\u7684\u6700\u5927\u516c\u56e0\u5b50](/solution/1000-1099/1071.Greatest%20Common%20Divisor%20of%20Strings/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[1071](https://leetcode.com/problems/greatest-common-divisor-of-strings)", "[Greatest Common Divisor of Strings](/solution/1000-1099/1071.Greatest%20Common%20Divisor%20of%20Strings/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "1145", "frontend_question_id": "1074", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-submatrices-that-sum-to-target", "url_en": "https://leetcode.com/problems/number-of-submatrices-that-sum-to-target", "relative_path_cn": "/solution/1000-1099/1074.Number%20of%20Submatrices%20That%20Sum%20to%20Target/README.md", "relative_path_en": "/solution/1000-1099/1074.Number%20of%20Submatrices%20That%20Sum%20to%20Target/README_EN.md", "title_cn": "\u5143\u7d20\u548c\u4e3a\u76ee\u6807\u503c\u7684\u5b50\u77e9\u9635\u6570\u91cf", "title_en": "Number of Submatrices That Sum to Target", "question_title_slug": "number-of-submatrices-that-sum-to-target", "content_en": "

    Given a matrix and a target, return the number of non-empty submatrices that sum to target.

    \n\n

    A submatrix x1, y1, x2, y2 is the set of all cells matrix[x][y] with x1 <= x <= x2 and y1 <= y <= y2.

    \n\n

    Two submatrices (x1, y1, x2, y2) and (x1', y1', x2', y2') are different if they have some coordinate that is different: for example, if x1 != x1'.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: matrix = [[0,1,0],[1,1,1],[0,1,0]], target = 0\nOutput: 4\nExplanation: The four 1x1 submatrices that only contain 0.\n
    \n\n

    Example 2:

    \n\n
    \nInput: matrix = [[1,-1],[-1,1]], target = 0\nOutput: 5\nExplanation: The two 1x2 submatrices, plus the two 2x1 submatrices, plus the 2x2 submatrix.\n
    \n\n

    Example 3:

    \n\n
    \nInput: matrix = [[904]], target = 0\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= matrix.length <= 100
    • \n\t
    • 1 <= matrix[0].length <= 100
    • \n\t
    • -1000 <= matrix[i] <= 1000
    • \n\t
    • -10^8 <= target <= 10^8
    • \n
    \n", "content_cn": "

    \u7ed9\u51fa\u77e9\u9635\u00a0matrix\u00a0\u548c\u76ee\u6807\u503c\u00a0target\uff0c\u8fd4\u56de\u5143\u7d20\u603b\u548c\u7b49\u4e8e\u76ee\u6807\u503c\u7684\u975e\u7a7a\u5b50\u77e9\u9635\u7684\u6570\u91cf\u3002

    \n\n

    \u5b50\u77e9\u9635\u00a0x1, y1, x2, y2\u00a0\u662f\u6ee1\u8db3 x1 <= x <= x2\u00a0\u4e14\u00a0y1 <= y <= y2\u00a0\u7684\u6240\u6709\u5355\u5143\u00a0matrix[x][y]\u00a0\u7684\u96c6\u5408\u3002

    \n\n

    \u5982\u679c\u00a0(x1, y1, x2, y2) \u548c\u00a0(x1', y1', x2', y2')\u00a0\u4e24\u4e2a\u5b50\u77e9\u9635\u4e2d\u90e8\u5206\u5750\u6807\u4e0d\u540c\uff08\u5982\uff1ax1 != x1'\uff09\uff0c\u90a3\u4e48\u8fd9\u4e24\u4e2a\u5b50\u77e9\u9635\u4e5f\u4e0d\u540c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1amatrix = [[0,1,0],[1,1,1],[0,1,0]], target = 0\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u56db\u4e2a\u53ea\u542b 0 \u7684 1x1 \u5b50\u77e9\u9635\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1amatrix = [[1,-1],[-1,1]], target = 0\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u4e24\u4e2a 1x2 \u5b50\u77e9\u9635\uff0c\u52a0\u4e0a\u4e24\u4e2a 2x1 \u5b50\u77e9\u9635\uff0c\u518d\u52a0\u4e0a\u4e00\u4e2a 2x2 \u5b50\u77e9\u9635\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1amatrix = [[904]], target = 0\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= matrix.length <= 100
    • \n\t
    • 1 <= matrix[0].length <= 100
    • \n\t
    • -1000 <= matrix[i] <= 1000
    • \n\t
    • -10^8 <= target <= 10^8
    • \n
    \n", "tags_en": ["Array", "Dynamic Programming", "Sliding Window"], "tags_cn": ["\u6570\u7ec4", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numSubmatrixSumTarget(vector>& matrix, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numSubmatrixSumTarget(int[][] matrix, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numSubmatrixSumTarget(self, matrix, target):\n \"\"\"\n :type matrix: List[List[int]]\n :type target: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numSubmatrixSumTarget(self, matrix: List[List[int]], target: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numSubmatrixSumTarget(int** matrix, int matrixSize, int* matrixColSize, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumSubmatrixSumTarget(int[][] matrix, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} matrix\n * @param {number} target\n * @return {number}\n */\nvar numSubmatrixSumTarget = function(matrix, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} matrix\n# @param {Integer} target\n# @return {Integer}\ndef num_submatrix_sum_target(matrix, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numSubmatrixSumTarget(_ matrix: [[Int]], _ target: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numSubmatrixSumTarget(matrix [][]int, target int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numSubmatrixSumTarget(matrix: Array[Array[Int]], target: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numSubmatrixSumTarget(matrix: Array, target: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_submatrix_sum_target(matrix: Vec>, target: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $matrix\n * @param Integer $target\n * @return Integer\n */\n function numSubmatrixSumTarget($matrix, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numSubmatrixSumTarget(matrix: number[][], target: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-submatrix-sum-target matrix target)\n (-> (listof (listof exact-integer?)) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1074](https://leetcode-cn.com/problems/number-of-submatrices-that-sum-to-target)", "[\u5143\u7d20\u548c\u4e3a\u76ee\u6807\u503c\u7684\u5b50\u77e9\u9635\u6570\u91cf](/solution/1000-1099/1074.Number%20of%20Submatrices%20That%20Sum%20to%20Target/README.md)", "`\u6570\u7ec4`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1074](https://leetcode.com/problems/number-of-submatrices-that-sum-to-target)", "[Number of Submatrices That Sum to Target](/solution/1000-1099/1074.Number%20of%20Submatrices%20That%20Sum%20to%20Target/README_EN.md)", "`Array`,`Dynamic Programming`,`Sliding Window`", "Hard", ""]}, {"question_id": "1144", "frontend_question_id": "1168", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/optimize-water-distribution-in-a-village", "url_en": "https://leetcode.com/problems/optimize-water-distribution-in-a-village", "relative_path_cn": "/solution/1100-1199/1168.Optimize%20Water%20Distribution%20in%20a%20Village/README.md", "relative_path_en": "/solution/1100-1199/1168.Optimize%20Water%20Distribution%20in%20a%20Village/README_EN.md", "title_cn": "\u6c34\u8d44\u6e90\u5206\u914d\u4f18\u5316", "title_en": "Optimize Water Distribution in a Village", "question_title_slug": "optimize-water-distribution-in-a-village", "content_en": "

    There are n houses in a village. We want to supply water for all the houses by building wells and laying pipes.

    \n\n

    For each house i, we can either build a well inside it directly with cost wells[i - 1] (note the -1 due to 0-indexing), or pipe in water from another well to it. The costs to lay pipes between houses are given by the array pipes, where each pipes[j] = [house1j, house2j, costj] represents the cost to connect house1j and house2j together using a pipe. Connections are bidirectional.

    \n\n

    Return the minimum total cost to supply water to all houses.

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: n = 3, wells = [1,2,2], pipes = [[1,2,1],[2,3,1]]\nOutput: 3\nExplanation: \nThe image shows the costs of connecting houses using pipes.\nThe best strategy is to build a well in the first house with cost 1 and connect the other houses to it with cost 2 so the total cost is 3.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 104
    • \n\t
    • wells.length == n
    • \n\t
    • 0 <= wells[i] <= 105
    • \n\t
    • 1 <= pipes.length <= 104
    • \n\t
    • pipes[j].length == 3
    • \n\t
    • 1 <= house1j, house2j <= n
    • \n\t
    • 0 <= costj <= 105
    • \n\t
    • house1j != house2j
    • \n
    \n", "content_cn": "

    \u6751\u91cc\u9762\u4e00\u5171\u6709 n \u680b\u623f\u5b50\u3002\u6211\u4eec\u5e0c\u671b\u901a\u8fc7\u5efa\u9020\u6c34\u4e95\u548c\u94fa\u8bbe\u7ba1\u9053\u6765\u4e3a\u6240\u6709\u623f\u5b50\u4f9b\u6c34\u3002

    \n\n

    \u5bf9\u4e8e\u6bcf\u4e2a\u623f\u5b50 i\uff0c\u6211\u4eec\u6709\u4e24\u79cd\u53ef\u9009\u7684\u4f9b\u6c34\u65b9\u6848\uff1a

    \n\n
      \n\t
    • \u4e00\u79cd\u662f\u76f4\u63a5\u5728\u623f\u5b50\u5185\u5efa\u9020\u6c34\u4e95\uff0c\u6210\u672c\u4e3a wells[i]\uff1b
    • \n\t
    • \u53e6\u4e00\u79cd\u662f\u4ece\u53e6\u4e00\u53e3\u4e95\u94fa\u8bbe\u7ba1\u9053\u5f15\u6c34\uff0c\u6570\u7ec4 pipes \u7ed9\u51fa\u4e86\u5728\u623f\u5b50\u95f4\u94fa\u8bbe\u7ba1\u9053\u7684\u6210\u672c\uff0c\u5176\u4e2d\u6bcf\u4e2a pipes[i] = [house1, house2, cost] \u4ee3\u8868\u7528\u7ba1\u9053\u5c06 house1 \u548c house2 \u8fde\u63a5\u5728\u4e00\u8d77\u7684\u6210\u672c\u3002\u5f53\u7136\uff0c\u8fde\u63a5\u662f\u53cc\u5411\u7684\u3002
    • \n
    \n\n

    \u8bf7\u4f60\u5e2e\u5fd9\u8ba1\u7b97\u4e3a\u6240\u6709\u623f\u5b50\u90fd\u4f9b\u6c34\u7684\u6700\u4f4e\u603b\u6210\u672c\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 3, wells = [1,2,2], pipes = [[1,2,1],[2,3,1]]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a \n\u4e0a\u56fe\u5c55\u793a\u4e86\u94fa\u8bbe\u7ba1\u9053\u8fde\u63a5\u623f\u5c4b\u7684\u6210\u672c\u3002\n\u6700\u597d\u7684\u7b56\u7565\u662f\u5728\u7b2c\u4e00\u4e2a\u623f\u5b50\u91cc\u5efa\u9020\u6c34\u4e95\uff08\u6210\u672c\u4e3a 1\uff09\uff0c\u7136\u540e\u5c06\u5176\u4ed6\u623f\u5b50\u94fa\u8bbe\u7ba1\u9053\u8fde\u8d77\u6765\uff08\u6210\u672c\u4e3a 2\uff09\uff0c\u6240\u4ee5\u603b\u6210\u672c\u4e3a 3\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 10000
    • \n\t
    • wells.length == n
    • \n\t
    • 0 <= wells[i] <= 10^5
    • \n\t
    • 1 <= pipes.length <= 10000
    • \n\t
    • 1 <= pipes[i][0], pipes[i][1] <= n
    • \n\t
    • 0 <= pipes[i][2] <= 10^5
    • \n\t
    • pipes[i][0] != pipes[i][1]
    • \n
    \n", "tags_en": ["Union Find", "Graph"], "tags_cn": ["\u5e76\u67e5\u96c6", "\u56fe"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minCostToSupplyWater(int n, vector& wells, vector>& pipes) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minCostToSupplyWater(int n, int[] wells, int[][] pipes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minCostToSupplyWater(self, n, wells, pipes):\n \"\"\"\n :type n: int\n :type wells: List[int]\n :type pipes: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minCostToSupplyWater(self, n: int, wells: List[int], pipes: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minCostToSupplyWater(int n, int* wells, int wellsSize, int** pipes, int pipesSize, int* pipesColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinCostToSupplyWater(int n, int[] wells, int[][] pipes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[]} wells\n * @param {number[][]} pipes\n * @return {number}\n */\nvar minCostToSupplyWater = function(n, wells, pipes) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[]} wells\n# @param {Integer[][]} pipes\n# @return {Integer}\ndef min_cost_to_supply_water(n, wells, pipes)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minCostToSupplyWater(_ n: Int, _ wells: [Int], _ pipes: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minCostToSupplyWater(n int, wells []int, pipes [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minCostToSupplyWater(n: Int, wells: Array[Int], pipes: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minCostToSupplyWater(n: Int, wells: IntArray, pipes: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_cost_to_supply_water(n: i32, wells: Vec, pipes: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[] $wells\n * @param Integer[][] $pipes\n * @return Integer\n */\n function minCostToSupplyWater($n, $wells, $pipes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minCostToSupplyWater(n: number, wells: number[], pipes: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-cost-to-supply-water n wells pipes)\n (-> exact-integer? (listof exact-integer?) (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1168](https://leetcode-cn.com/problems/optimize-water-distribution-in-a-village)", "[\u6c34\u8d44\u6e90\u5206\u914d\u4f18\u5316](/solution/1100-1199/1168.Optimize%20Water%20Distribution%20in%20a%20Village/README.md)", "`\u5e76\u67e5\u96c6`,`\u56fe`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1168](https://leetcode.com/problems/optimize-water-distribution-in-a-village)", "[Optimize Water Distribution in a Village](/solution/1100-1199/1168.Optimize%20Water%20Distribution%20in%20a%20Village/README_EN.md)", "`Union Find`,`Graph`", "Hard", "\ud83d\udd12"]}, {"question_id": "1143", "frontend_question_id": "1198", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/find-smallest-common-element-in-all-rows", "url_en": "https://leetcode.com/problems/find-smallest-common-element-in-all-rows", "relative_path_cn": "/solution/1100-1199/1198.Find%20Smallest%20Common%20Element%20in%20All%20Rows/README.md", "relative_path_en": "/solution/1100-1199/1198.Find%20Smallest%20Common%20Element%20in%20All%20Rows/README_EN.md", "title_cn": "\u627e\u51fa\u6240\u6709\u884c\u4e2d\u6700\u5c0f\u516c\u5171\u5143\u7d20", "title_en": "Find Smallest Common Element in All Rows", "question_title_slug": "find-smallest-common-element-in-all-rows", "content_en": "

    Given an m x n matrix mat where every row is sorted in strictly increasing order, return the smallest common element in all rows.

    \n\n

    If there is no common element, return -1.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: mat = [[1,2,3,4,5],[2,4,5,8,10],[3,5,7,9,11],[1,3,5,7,9]]\nOutput: 5\n
    \n\n

    Example 2:

    \n\n
    \nInput: mat = [[1,2,3],[2,3,4],[2,3,5]]\nOutput: 2\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == mat.length
    • \n\t
    • n == mat[i].length
    • \n\t
    • 1 <= m, n <= 500
    • \n\t
    • 1 <= mat[i][j] <= 104
    • \n\t
    • mat[i] is sorted in strictly increasing order.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u77e9\u9635\u00a0mat\uff0c\u5176\u4e2d\u6bcf\u4e00\u884c\u7684\u5143\u7d20\u90fd\u5df2\u7ecf\u6309 \u4e25\u683c\u9012\u589e \u987a\u5e8f\u6392\u597d\u4e86\u3002\u8bf7\u4f60\u5e2e\u5fd9\u627e\u51fa\u5728\u6240\u6709\u8fd9\u4e9b\u884c\u4e2d \u6700\u5c0f\u7684\u516c\u5171\u5143\u7d20\u3002

    \n\n

    \u5982\u679c\u77e9\u9635\u4e2d\u6ca1\u6709\u8fd9\u6837\u7684\u516c\u5171\u5143\u7d20\uff0c\u5c31\u8bf7\u8fd4\u56de\u00a0-1\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1amat = [[1,2,3,4,5],[2,4,5,8,10],[3,5,7,9,11],[1,3,5,7,9]]\n\u8f93\u51fa\uff1a5\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= mat.length, mat[i].length <= 500
    • \n\t
    • 1 <= mat[i][j] <= 10^4
    • \n\t
    • mat[i]\u00a0\u5df2\u6309\u4e25\u683c\u9012\u589e\u987a\u5e8f\u6392\u5217\u3002
    • \n
    \n", "tags_en": ["Hash Table", "Binary Search"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int smallestCommonElement(vector>& mat) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int smallestCommonElement(int[][] mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def smallestCommonElement(self, mat):\n \"\"\"\n :type mat: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def smallestCommonElement(self, mat: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint smallestCommonElement(int** mat, int matSize, int* matColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SmallestCommonElement(int[][] mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} mat\n * @return {number}\n */\nvar smallestCommonElement = function(mat) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} mat\n# @return {Integer}\ndef smallest_common_element(mat)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func smallestCommonElement(_ mat: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func smallestCommonElement(mat [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def smallestCommonElement(mat: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun smallestCommonElement(mat: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn smallest_common_element(mat: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $mat\n * @return Integer\n */\n function smallestCommonElement($mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function smallestCommonElement(mat: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (smallest-common-element mat)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1198](https://leetcode-cn.com/problems/find-smallest-common-element-in-all-rows)", "[\u627e\u51fa\u6240\u6709\u884c\u4e2d\u6700\u5c0f\u516c\u5171\u5143\u7d20](/solution/1100-1199/1198.Find%20Smallest%20Common%20Element%20in%20All%20Rows/README.md)", "`\u54c8\u5e0c\u8868`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1198](https://leetcode.com/problems/find-smallest-common-element-in-all-rows)", "[Find Smallest Common Element in All Rows](/solution/1100-1199/1198.Find%20Smallest%20Common%20Element%20in%20All%20Rows/README_EN.md)", "`Hash Table`,`Binary Search`", "Medium", "\ud83d\udd12"]}, {"question_id": "1142", "frontend_question_id": "1197", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/minimum-knight-moves", "url_en": "https://leetcode.com/problems/minimum-knight-moves", "relative_path_cn": "/solution/1100-1199/1197.Minimum%20Knight%20Moves/README.md", "relative_path_en": "/solution/1100-1199/1197.Minimum%20Knight%20Moves/README_EN.md", "title_cn": "\u8fdb\u51fb\u7684\u9a91\u58eb", "title_en": "Minimum Knight Moves", "question_title_slug": "minimum-knight-moves", "content_en": "

    In an infinite chess board with coordinates from -infinity to +infinity, you have a knight at square [0, 0].

    \n\n

    A knight has 8 possible moves it can make, as illustrated below. Each move is two squares in a cardinal direction, then one square in an orthogonal direction.

    \n\n

    \n\n

    Return the minimum number of steps needed to move the knight to the square [x, y].  It is guaranteed the answer exists.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: x = 2, y = 1\nOutput: 1\nExplanation: [0, 0] → [2, 1]\n
    \n\n

    Example 2:

    \n\n
    \nInput: x = 5, y = 5\nOutput: 4\nExplanation: [0, 0] → [2, 1] → [4, 2] → [3, 4] → [5, 5]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • |x| + |y| <= 300
    • \n
    \n", "content_cn": "

    \u4e00\u4e2a\u5750\u6807\u53ef\u4ee5\u4ece -infinity \u5ef6\u4f38\u5230 +infinity \u7684 \u65e0\u9650\u5927\u7684 \u68cb\u76d8\u4e0a\uff0c\u4f60\u7684 \u9a91\u58eb \u9a7b\u624e\u5728\u5750\u6807\u4e3a [0, 0] \u7684\u65b9\u683c\u91cc\u3002

    \n\n

    \u9a91\u58eb\u7684\u8d70\u6cd5\u548c\u4e2d\u56fd\u8c61\u68cb\u4e2d\u7684\u9a6c\u76f8\u4f3c\uff0c\u8d70 “\u65e5” \u5b57\uff1a\u5373\u5148\u5411\u5de6\uff08\u6216\u53f3\uff09\u8d70 1 \u683c\uff0c\u518d\u5411\u4e0a\uff08\u6216\u4e0b\uff09\u8d70 2 \u683c\uff1b\u6216\u5148\u5411\u5de6\uff08\u6216\u53f3\uff09\u8d70 2 \u683c\uff0c\u518d\u5411\u4e0a\uff08\u6216\u4e0b\uff09\u8d70 1 \u683c\u3002

    \n\n

    \u6bcf\u6b21\u79fb\u52a8\uff0c\u4ed6\u90fd\u53ef\u4ee5\u6309\u56fe\u793a\u516b\u4e2a\u65b9\u5411\u4e4b\u4e00\u524d\u8fdb\u3002

    \n\n

    \n\n

    \u73b0\u5728\uff0c\u9a91\u58eb\u9700\u8981\u524d\u53bb\u5f81\u670d\u5750\u6807\u4e3a [x, y] \u7684\u90e8\u843d\uff0c\u8bf7\u4f60\u4e3a\u4ed6\u89c4\u5212\u8def\u7ebf\u3002

    \n\n

    \u6700\u540e\u8fd4\u56de\u6240\u9700\u7684\u6700\u5c0f\u79fb\u52a8\u6b21\u6570\u5373\u53ef\u3002\u672c\u9898\u786e\u4fdd\u7b54\u6848\u662f\u4e00\u5b9a\u5b58\u5728\u7684\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1ax = 2, y = 1\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a[0, 0] → [2, 1]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1ax = 5, y = 5\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a[0, 0] → [2, 1] → [4, 2] → [3, 4] → [5, 5]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • |x| + |y| <= 300
    • \n
    \n", "tags_en": ["Breadth-first Search"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minKnightMoves(int x, int y) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minKnightMoves(int x, int y) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minKnightMoves(self, x, y):\n \"\"\"\n :type x: int\n :type y: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minKnightMoves(self, x: int, y: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minKnightMoves(int x, int y){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinKnightMoves(int x, int y) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} x\n * @param {number} y\n * @return {number}\n */\nvar minKnightMoves = function(x, y) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} x\n# @param {Integer} y\n# @return {Integer}\ndef min_knight_moves(x, y)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minKnightMoves(_ x: Int, _ y: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minKnightMoves(x int, y int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minKnightMoves(x: Int, y: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minKnightMoves(x: Int, y: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_knight_moves(x: i32, y: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $x\n * @param Integer $y\n * @return Integer\n */\n function minKnightMoves($x, $y) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minKnightMoves(x: number, y: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-knight-moves x y)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1197](https://leetcode-cn.com/problems/minimum-knight-moves)", "[\u8fdb\u51fb\u7684\u9a91\u58eb](/solution/1100-1199/1197.Minimum%20Knight%20Moves/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1197](https://leetcode.com/problems/minimum-knight-moves)", "[Minimum Knight Moves](/solution/1100-1199/1197.Minimum%20Knight%20Moves/README_EN.md)", "`Breadth-first Search`", "Medium", "\ud83d\udd12"]}, {"question_id": "1141", "frontend_question_id": "1196", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/how-many-apples-can-you-put-into-the-basket", "url_en": "https://leetcode.com/problems/how-many-apples-can-you-put-into-the-basket", "relative_path_cn": "/solution/1100-1199/1196.How%20Many%20Apples%20Can%20You%20Put%20into%20the%20Basket/README.md", "relative_path_en": "/solution/1100-1199/1196.How%20Many%20Apples%20Can%20You%20Put%20into%20the%20Basket/README_EN.md", "title_cn": "\u6700\u591a\u53ef\u4ee5\u4e70\u5230\u7684\u82f9\u679c\u6570\u91cf", "title_en": "How Many Apples Can You Put into the Basket", "question_title_slug": "how-many-apples-can-you-put-into-the-basket", "content_en": "

    You have some apples, where arr[i] is the weight of the i-th apple.  You also have a basket that can carry up to 5000 units of weight.

    \n\n

    Return the maximum number of apples you can put in the basket.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr = [100,200,150,1000]\nOutput: 4\nExplanation: All 4 apples can be carried by the basket since their sum of weights is 1450.\n
    \n\n

    Example 2:

    \n\n
    \nInput: arr = [900,950,800,1000,700,800]\nOutput: 5\nExplanation: The sum of weights of the 6 apples exceeds 5000 so we choose any 5 of them.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= arr.length <= 10^3
    • \n\t
    • 1 <= arr[i] <= 10^3
    • \n
    \n", "content_cn": "

    \u697c\u4e0b\u6c34\u679c\u5e97\u6b63\u5728\u4fc3\u9500\uff0c\u4f60\u6253\u7b97\u4e70\u4e9b\u82f9\u679c\uff0carr[i] \u8868\u793a\u7b2c i \u4e2a\u82f9\u679c\u7684\u5355\u4f4d\u91cd\u91cf\u3002

    \n\n

    \u4f60\u6709\u4e00\u4e2a\u8d2d\u7269\u888b\uff0c\u6700\u591a\u53ef\u4ee5\u88c5 5000 \u5355\u4f4d\u91cd\u91cf\u7684\u4e1c\u897f\uff0c\u7b97\u4e00\u7b97\uff0c\u6700\u591a\u53ef\u4ee5\u5f80\u8d2d\u7269\u888b\u91cc\u88c5\u5165\u591a\u5c11\u82f9\u679c\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [100,200,150,1000]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u6240\u6709 4 \u4e2a\u82f9\u679c\u90fd\u53ef\u4ee5\u88c5\u8fdb\u53bb\uff0c\u56e0\u4e3a\u5b83\u4eec\u7684\u91cd\u91cf\u4e4b\u548c\u4e3a 1450\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aarr = [900,950,800,1000,700,800]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a6 \u4e2a\u82f9\u679c\u7684\u603b\u91cd\u91cf\u8d85\u8fc7\u4e86 5000\uff0c\u6240\u4ee5\u6211\u4eec\u53ea\u80fd\u4ece\u4e2d\u4efb\u9009 5 \u4e2a\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= arr.length <= 10^3
    • \n\t
    • 1 <= arr[i] <= 10^3
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxNumberOfApples(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxNumberOfApples(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxNumberOfApples(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxNumberOfApples(self, arr: List[int]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxNumberOfApples(int* arr, int arrSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxNumberOfApples(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar maxNumberOfApples = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef max_number_of_apples(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxNumberOfApples(_ arr: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxNumberOfApples(arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxNumberOfApples(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxNumberOfApples(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_number_of_apples(arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function maxNumberOfApples($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxNumberOfApples(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-number-of-apples arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1196](https://leetcode-cn.com/problems/how-many-apples-can-you-put-into-the-basket)", "[\u6700\u591a\u53ef\u4ee5\u4e70\u5230\u7684\u82f9\u679c\u6570\u91cf](/solution/1100-1199/1196.How%20Many%20Apples%20Can%20You%20Put%20into%20the%20Basket/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1196](https://leetcode.com/problems/how-many-apples-can-you-put-into-the-basket)", "[How Many Apples Can You Put into the Basket](/solution/1100-1199/1196.How%20Many%20Apples%20Can%20You%20Put%20into%20the%20Basket/README_EN.md)", "`Greedy`", "Easy", "\ud83d\udd12"]}, {"question_id": "1140", "frontend_question_id": "1054", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/distant-barcodes", "url_en": "https://leetcode.com/problems/distant-barcodes", "relative_path_cn": "/solution/1000-1099/1054.Distant%20Barcodes/README.md", "relative_path_en": "/solution/1000-1099/1054.Distant%20Barcodes/README_EN.md", "title_cn": "\u8ddd\u79bb\u76f8\u7b49\u7684\u6761\u5f62\u7801", "title_en": "Distant Barcodes", "question_title_slug": "distant-barcodes", "content_en": "

    In a warehouse, there is a row of barcodes, where the ith barcode is barcodes[i].

    \n\n

    Rearrange the barcodes so that no two adjacent barcodes are equal. You may return any answer, and it is guaranteed an answer exists.

    \n\n

     

    \n

    Example 1:

    \n
    Input: barcodes = [1,1,1,2,2,2]\nOutput: [2,1,2,1,2,1]\n

    Example 2:

    \n
    Input: barcodes = [1,1,1,1,2,2,3,3]\nOutput: [1,3,1,3,1,2,1,2]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= barcodes.length <= 10000
    • \n\t
    • 1 <= barcodes[i] <= 10000
    • \n
    \n", "content_cn": "

    \u5728\u4e00\u4e2a\u4ed3\u5e93\u91cc\uff0c\u6709\u4e00\u6392\u6761\u5f62\u7801\uff0c\u5176\u4e2d\u7b2c i \u4e2a\u6761\u5f62\u7801\u4e3a barcodes[i]\u3002

    \n\n

    \u8bf7\u4f60\u91cd\u65b0\u6392\u5217\u8fd9\u4e9b\u6761\u5f62\u7801\uff0c\u4f7f\u5176\u4e2d\u4e24\u4e2a\u76f8\u90bb\u7684\u6761\u5f62\u7801 \u4e0d\u80fd \u76f8\u7b49\u3002 \u4f60\u53ef\u4ee5\u8fd4\u56de\u4efb\u4f55\u6ee1\u8db3\u8be5\u8981\u6c42\u7684\u7b54\u6848\uff0c\u6b64\u9898\u4fdd\u8bc1\u5b58\u5728\u7b54\u6848\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a[1,1,1,2,2,2]\n\u8f93\u51fa\uff1a[2,1,2,1,2,1]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a[1,1,1,1,2,2,3,3]\n\u8f93\u51fa\uff1a[1,3,1,3,2,1,2,1]
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= barcodes.length <= 10000
    2. \n\t
    3. 1 <= barcodes[i] <= 10000
    4. \n
    \n\n

     

    \n", "tags_en": ["Heap", "Sort"], "tags_cn": ["\u5806", "\u6392\u5e8f"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector rearrangeBarcodes(vector& barcodes) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] rearrangeBarcodes(int[] barcodes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def rearrangeBarcodes(self, barcodes):\n \"\"\"\n :type barcodes: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def rearrangeBarcodes(self, barcodes: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* rearrangeBarcodes(int* barcodes, int barcodesSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] RearrangeBarcodes(int[] barcodes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} barcodes\n * @return {number[]}\n */\nvar rearrangeBarcodes = function(barcodes) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} barcodes\n# @return {Integer[]}\ndef rearrange_barcodes(barcodes)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func rearrangeBarcodes(_ barcodes: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func rearrangeBarcodes(barcodes []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def rearrangeBarcodes(barcodes: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun rearrangeBarcodes(barcodes: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn rearrange_barcodes(barcodes: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $barcodes\n * @return Integer[]\n */\n function rearrangeBarcodes($barcodes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function rearrangeBarcodes(barcodes: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (rearrange-barcodes barcodes)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1054](https://leetcode-cn.com/problems/distant-barcodes)", "[\u8ddd\u79bb\u76f8\u7b49\u7684\u6761\u5f62\u7801](/solution/1000-1099/1054.Distant%20Barcodes/README.md)", "`\u5806`,`\u6392\u5e8f`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1054](https://leetcode.com/problems/distant-barcodes)", "[Distant Barcodes](/solution/1000-1099/1054.Distant%20Barcodes/README_EN.md)", "`Heap`,`Sort`", "Medium", ""]}, {"question_id": "1139", "frontend_question_id": "1053", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/previous-permutation-with-one-swap", "url_en": "https://leetcode.com/problems/previous-permutation-with-one-swap", "relative_path_cn": "/solution/1000-1099/1053.Previous%20Permutation%20With%20One%20Swap/README.md", "relative_path_en": "/solution/1000-1099/1053.Previous%20Permutation%20With%20One%20Swap/README_EN.md", "title_cn": "\u4ea4\u6362\u4e00\u6b21\u7684\u5148\u524d\u6392\u5217", "title_en": "Previous Permutation With One Swap", "question_title_slug": "previous-permutation-with-one-swap", "content_en": "

    Given an array of positive integers arr (not necessarily distinct), return the lexicographically largest permutation that is smaller than arr, that can be made with exactly one swap (A swap exchanges the positions of two numbers arr[i] and arr[j]). If it cannot be done, then return the same array.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr = [3,2,1]\nOutput: [3,1,2]\nExplanation: Swapping 2 and 1.\n
    \n\n

    Example 2:

    \n\n
    \nInput: arr = [1,1,5]\nOutput: [1,1,5]\nExplanation: This is already the smallest permutation.\n
    \n\n

    Example 3:

    \n\n
    \nInput: arr = [1,9,4,6,7]\nOutput: [1,7,4,6,9]\nExplanation: Swapping 9 and 7.\n
    \n\n

    Example 4:

    \n\n
    \nInput: arr = [3,1,1,3]\nOutput: [1,3,1,3]\nExplanation: Swapping 1 and 3.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= arr.length <= 104
    • \n\t
    • 1 <= arr[i] <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6b63\u6574\u6570\u7684\u6570\u7ec4 A\uff08\u5176\u4e2d\u7684\u5143\u7d20\u4e0d\u4e00\u5b9a\u5b8c\u5168\u4e0d\u540c\uff09\uff0c\u8bf7\u4f60\u8fd4\u56de\u53ef\u5728\u00a0\u4e00\u6b21\u4ea4\u6362\uff08\u4ea4\u6362\u4e24\u6570\u5b57 A[i] \u548c A[j] \u7684\u4f4d\u7f6e\uff09\u540e\u5f97\u5230\u7684\u3001\u6309\u5b57\u5178\u5e8f\u6392\u5217\u5c0f\u4e8e A \u7684\u6700\u5927\u53ef\u80fd\u6392\u5217\u3002

    \n\n

    \u5982\u679c\u65e0\u6cd5\u8fd9\u4e48\u64cd\u4f5c\uff0c\u5c31\u8bf7\u8fd4\u56de\u539f\u6570\u7ec4\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [3,2,1]\n\u8f93\u51fa\uff1a[3,1,2]\n\u89e3\u91ca\uff1a\u4ea4\u6362 2 \u548c 1\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [1,1,5]\n\u8f93\u51fa\uff1a[1,1,5]\n\u89e3\u91ca\uff1a\u5df2\u7ecf\u662f\u6700\u5c0f\u6392\u5217\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [1,9,4,6,7]\n\u8f93\u51fa\uff1a[1,7,4,6,9]\n\u89e3\u91ca\uff1a\u4ea4\u6362 9 \u548c 7\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [3,1,1,3]\n\u8f93\u51fa\uff1a[1,3,1,3]\n\u89e3\u91ca\uff1a\u4ea4\u6362 1 \u548c 3\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= arr.length <= 104
    • \n\t
    • 1 <= arr[i] <= 104
    • \n
    \n", "tags_en": ["Greedy", "Array"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector prevPermOpt1(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] prevPermOpt1(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def prevPermOpt1(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def prevPermOpt1(self, arr: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* prevPermOpt1(int* arr, int arrSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] PrevPermOpt1(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number[]}\n */\nvar prevPermOpt1 = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer[]}\ndef prev_perm_opt1(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func prevPermOpt1(_ arr: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func prevPermOpt1(arr []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def prevPermOpt1(arr: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun prevPermOpt1(arr: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn prev_perm_opt1(arr: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer[]\n */\n function prevPermOpt1($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function prevPermOpt1(arr: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (prev-perm-opt1 arr)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1053](https://leetcode-cn.com/problems/previous-permutation-with-one-swap)", "[\u4ea4\u6362\u4e00\u6b21\u7684\u5148\u524d\u6392\u5217](/solution/1000-1099/1053.Previous%20Permutation%20With%20One%20Swap/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1053](https://leetcode.com/problems/previous-permutation-with-one-swap)", "[Previous Permutation With One Swap](/solution/1000-1099/1053.Previous%20Permutation%20With%20One%20Swap/README_EN.md)", "`Greedy`,`Array`", "Medium", ""]}, {"question_id": "1138", "frontend_question_id": "1052", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/grumpy-bookstore-owner", "url_en": "https://leetcode.com/problems/grumpy-bookstore-owner", "relative_path_cn": "/solution/1000-1099/1052.Grumpy%20Bookstore%20Owner/README.md", "relative_path_en": "/solution/1000-1099/1052.Grumpy%20Bookstore%20Owner/README_EN.md", "title_cn": "\u7231\u751f\u6c14\u7684\u4e66\u5e97\u8001\u677f", "title_en": "Grumpy Bookstore Owner", "question_title_slug": "grumpy-bookstore-owner", "content_en": "

    Today, the bookstore owner has a store open for customers.length minutes.  Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.

    \n\n

    On some minutes, the bookstore owner is grumpy.  If the bookstore owner is grumpy on the i-th minute, grumpy[i] = 1, otherwise grumpy[i] = 0.  When the bookstore owner is grumpy, the customers of that minute are not satisfied, otherwise they are satisfied.

    \n\n

    The bookstore owner knows a secret technique to keep themselves not grumpy for minutes minutes straight, but can only use it once.

    \n\n

    Return the maximum number of customers that can be satisfied throughout the day.

    \n\n

     

    \n\n

    Example 1:

    \n\n
    \nInput: customers = [1,0,1,2,1,1,7,5], grumpy = [0,1,0,1,0,1,0,1], minutes = 3\nOutput: 16\nExplanation: The bookstore owner keeps themselves not grumpy for the last 3 minutes. \nThe maximum number of customers that can be satisfied = 1 + 1 + 1 + 1 + 7 + 5 = 16.\n
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    • 1 <= minutes <= customers.length == grumpy.length <= 20000
    • \n\t
    • 0 <= customers[i] <= 1000
    • \n\t
    • 0 <= grumpy[i] <= 1
    • \n
    \n", "content_cn": "

    \u4eca\u5929\uff0c\u4e66\u5e97\u8001\u677f\u6709\u4e00\u5bb6\u5e97\u6253\u7b97\u8bd5\u8425\u4e1a\u00a0customers.length\u00a0\u5206\u949f\u3002\u6bcf\u5206\u949f\u90fd\u6709\u4e00\u4e9b\u987e\u5ba2\uff08customers[i]\uff09\u4f1a\u8fdb\u5165\u4e66\u5e97\uff0c\u6240\u6709\u8fd9\u4e9b\u987e\u5ba2\u90fd\u4f1a\u5728\u90a3\u4e00\u5206\u949f\u7ed3\u675f\u540e\u79bb\u5f00\u3002

    \n\n

    \u5728\u67d0\u4e9b\u65f6\u5019\uff0c\u4e66\u5e97\u8001\u677f\u4f1a\u751f\u6c14\u3002 \u5982\u679c\u4e66\u5e97\u8001\u677f\u5728\u7b2c i \u5206\u949f\u751f\u6c14\uff0c\u90a3\u4e48 grumpy[i] = 1\uff0c\u5426\u5219 grumpy[i] = 0\u3002 \u5f53\u4e66\u5e97\u8001\u677f\u751f\u6c14\u65f6\uff0c\u90a3\u4e00\u5206\u949f\u7684\u987e\u5ba2\u5c31\u4f1a\u4e0d\u6ee1\u610f\uff0c\u4e0d\u751f\u6c14\u5219\u4ed6\u4eec\u662f\u6ee1\u610f\u7684\u3002

    \n\n

    \u4e66\u5e97\u8001\u677f\u77e5\u9053\u4e00\u4e2a\u79d8\u5bc6\u6280\u5de7\uff0c\u80fd\u6291\u5236\u81ea\u5df1\u7684\u60c5\u7eea\uff0c\u53ef\u4ee5\u8ba9\u81ea\u5df1\u8fde\u7eed\u00a0X \u5206\u949f\u4e0d\u751f\u6c14\uff0c\u4f46\u5374\u53ea\u80fd\u4f7f\u7528\u4e00\u6b21\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u8fd9\u4e00\u5929\u8425\u4e1a\u4e0b\u6765\uff0c\u6700\u591a\u6709\u591a\u5c11\u5ba2\u6237\u80fd\u591f\u611f\u5230\u6ee1\u610f\u3002
    \n\u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1acustomers = [1,0,1,2,1,1,7,5], grumpy = [0,1,0,1,0,1,0,1], X = 3\n\u8f93\u51fa\uff1a16\n\u89e3\u91ca\uff1a\n\u4e66\u5e97\u8001\u677f\u5728\u6700\u540e 3 \u5206\u949f\u4fdd\u6301\u51b7\u9759\u3002\n\u611f\u5230\u6ee1\u610f\u7684\u6700\u5927\u5ba2\u6237\u6570\u91cf = 1 + 1 + 1 + 1 + 7 + 5 = 16.\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= X <=\u00a0customers.length ==\u00a0grumpy.length <= 20000
    • \n\t
    • 0 <=\u00a0customers[i] <= 1000
    • \n\t
    • 0 <=\u00a0grumpy[i] <= 1
    • \n
    \n", "tags_en": ["Array", "Sliding Window"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxSatisfied(vector& customers, vector& grumpy, int minutes) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxSatisfied(int[] customers, int[] grumpy, int minutes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxSatisfied(self, customers, grumpy, minutes):\n \"\"\"\n :type customers: List[int]\n :type grumpy: List[int]\n :type minutes: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxSatisfied(self, customers: List[int], grumpy: List[int], minutes: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxSatisfied(int* customers, int customersSize, int* grumpy, int grumpySize, int minutes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxSatisfied(int[] customers, int[] grumpy, int minutes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} customers\n * @param {number[]} grumpy\n * @param {number} minutes\n * @return {number}\n */\nvar maxSatisfied = function(customers, grumpy, minutes) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} customers\n# @param {Integer[]} grumpy\n# @param {Integer} minutes\n# @return {Integer}\ndef max_satisfied(customers, grumpy, minutes)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxSatisfied(_ customers: [Int], _ grumpy: [Int], _ minutes: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxSatisfied(customers []int, grumpy []int, minutes int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxSatisfied(customers: Array[Int], grumpy: Array[Int], minutes: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxSatisfied(customers: IntArray, grumpy: IntArray, minutes: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_satisfied(customers: Vec, grumpy: Vec, minutes: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $customers\n * @param Integer[] $grumpy\n * @param Integer $minutes\n * @return Integer\n */\n function maxSatisfied($customers, $grumpy, $minutes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxSatisfied(customers: number[], grumpy: number[], minutes: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-satisfied customers grumpy minutes)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1052](https://leetcode-cn.com/problems/grumpy-bookstore-owner)", "[\u7231\u751f\u6c14\u7684\u4e66\u5e97\u8001\u677f](/solution/1000-1099/1052.Grumpy%20Bookstore%20Owner/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1052](https://leetcode.com/problems/grumpy-bookstore-owner)", "[Grumpy Bookstore Owner](/solution/1000-1099/1052.Grumpy%20Bookstore%20Owner/README_EN.md)", "`Array`,`Sliding Window`", "Medium", ""]}, {"question_id": "1137", "frontend_question_id": "1051", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/height-checker", "url_en": "https://leetcode.com/problems/height-checker", "relative_path_cn": "/solution/1000-1099/1051.Height%20Checker/README.md", "relative_path_en": "/solution/1000-1099/1051.Height%20Checker/README_EN.md", "title_cn": "\u9ad8\u5ea6\u68c0\u67e5\u5668", "title_en": "Height Checker", "question_title_slug": "height-checker", "content_en": "

    A school is trying to take an annual photo of all the students. The students are asked to stand in a single file line in non-decreasing order by height. Let this ordering be represented by the integer array expected where expected[i] is the expected height of the ith student in line.

    \n\n

    You are given an integer array heights representing the current order that the students are standing in. Each heights[i] is the height of the ith student in line (0-indexed).

    \n\n

    Return the number of indices where heights[i] != expected[i].

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: heights = [1,1,4,2,1,3]\nOutput: 3\nExplanation: \nheights:  [1,1,4,2,1,3]\nexpected: [1,1,1,2,3,4]\nIndices 2, 4, and 5 do not match.\n
    \n\n

    Example 2:

    \n\n
    \nInput: heights = [5,1,2,3,4]\nOutput: 5\nExplanation:\nheights:  [5,1,2,3,4]\nexpected: [1,2,3,4,5]\nAll indices do not match.\n
    \n\n

    Example 3:

    \n\n
    \nInput: heights = [1,2,3,4,5]\nOutput: 0\nExplanation:\nheights:  [1,2,3,4,5]\nexpected: [1,2,3,4,5]\nAll indices match.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= heights.length <= 100
    • \n\t
    • 1 <= heights[i] <= 100
    • \n
    \n", "content_cn": "

    \u5b66\u6821\u5728\u62cd\u5e74\u5ea6\u7eaa\u5ff5\u7167\u65f6\uff0c\u4e00\u822c\u8981\u6c42\u5b66\u751f\u6309\u7167 \u975e\u9012\u51cf \u7684\u9ad8\u5ea6\u987a\u5e8f\u6392\u5217\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u80fd\u8ba9\u6240\u6709\u5b66\u751f\u4ee5 \u975e\u9012\u51cf \u9ad8\u5ea6\u6392\u5217\u7684\u6700\u5c0f\u5fc5\u8981\u79fb\u52a8\u4eba\u6570\u3002

    \n\n

    \u6ce8\u610f\uff0c\u5f53\u4e00\u7ec4\u5b66\u751f\u88ab\u9009\u4e2d\u65f6\uff0c\u4ed6\u4eec\u4e4b\u95f4\u53ef\u4ee5\u4ee5\u4efb\u4f55\u53ef\u80fd\u7684\u65b9\u5f0f\u91cd\u65b0\u6392\u5e8f\uff0c\u800c\u672a\u88ab\u9009\u4e2d\u7684\u5b66\u751f\u5e94\u8be5\u4fdd\u6301\u4e0d\u52a8\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1aheights =\u00a0[1,1,4,2,1,3]\n\u8f93\u51fa\uff1a3 \n\u89e3\u91ca\uff1a\n\u5f53\u524d\u6570\u7ec4\uff1a[1,1,4,2,1,3]\n\u76ee\u6807\u6570\u7ec4\uff1a[1,1,1,2,3,4]\n\u5728\u4e0b\u6807 2 \u5904\uff08\u4ece 0 \u5f00\u59cb\u8ba1\u6570\uff09\u51fa\u73b0 4 vs 1 \uff0c\u6240\u4ee5\u6211\u4eec\u5fc5\u987b\u79fb\u52a8\u8fd9\u540d\u5b66\u751f\u3002\n\u5728\u4e0b\u6807 4 \u5904\uff08\u4ece 0 \u5f00\u59cb\u8ba1\u6570\uff09\u51fa\u73b0 1 vs 3 \uff0c\u6240\u4ee5\u6211\u4eec\u5fc5\u987b\u79fb\u52a8\u8fd9\u540d\u5b66\u751f\u3002\n\u5728\u4e0b\u6807 5 \u5904\uff08\u4ece 0 \u5f00\u59cb\u8ba1\u6570\uff09\u51fa\u73b0 3 vs 4 \uff0c\u6240\u4ee5\u6211\u4eec\u5fc5\u987b\u79fb\u52a8\u8fd9\u540d\u5b66\u751f\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aheights = [5,1,2,3,4]\n\u8f93\u51fa\uff1a5\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aheights = [1,2,3,4,5]\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= heights.length <= 100
    • \n\t
    • 1 <= heights[i] <= 100
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int heightChecker(vector& heights) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int heightChecker(int[] heights) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def heightChecker(self, heights):\n \"\"\"\n :type heights: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def heightChecker(self, heights: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint heightChecker(int* heights, int heightsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int HeightChecker(int[] heights) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} heights\n * @return {number}\n */\nvar heightChecker = function(heights) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} heights\n# @return {Integer}\ndef height_checker(heights)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func heightChecker(_ heights: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func heightChecker(heights []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def heightChecker(heights: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun heightChecker(heights: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn height_checker(heights: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $heights\n * @return Integer\n */\n function heightChecker($heights) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function heightChecker(heights: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (height-checker heights)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1051](https://leetcode-cn.com/problems/height-checker)", "[\u9ad8\u5ea6\u68c0\u67e5\u5668](/solution/1000-1099/1051.Height%20Checker/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1051](https://leetcode.com/problems/height-checker)", "[Height Checker](/solution/1000-1099/1051.Height%20Checker/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1136", "frontend_question_id": "1050", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/actors-and-directors-who-cooperated-at-least-three-times", "url_en": "https://leetcode.com/problems/actors-and-directors-who-cooperated-at-least-three-times", "relative_path_cn": "/solution/1000-1099/1050.Actors%20and%20Directors%20Who%20Cooperated%20At%20Least%20Three%20Times/README.md", "relative_path_en": "/solution/1000-1099/1050.Actors%20and%20Directors%20Who%20Cooperated%20At%20Least%20Three%20Times/README_EN.md", "title_cn": "\u5408\u4f5c\u8fc7\u81f3\u5c11\u4e09\u6b21\u7684\u6f14\u5458\u548c\u5bfc\u6f14", "title_en": "Actors and Directors Who Cooperated At Least Three Times", "question_title_slug": "actors-and-directors-who-cooperated-at-least-three-times", "content_en": "

    Table: ActorDirector

    \r\n\r\n
    \r\n+-------------+---------+\r\n| Column Name | Type    |\r\n+-------------+---------+\r\n| actor_id    | int     |\r\n| director_id | int     |\r\n| timestamp   | int     |\r\n+-------------+---------+\r\ntimestamp is the primary key column for this table.\r\n
    \r\n\r\n

     

    \r\n\r\n

    Write a SQL query for a report that provides the pairs (actor_id, director_id) where the actor have cooperated with the director at least 3 times.

    \r\n\r\n

    Example:

    \r\n\r\n
    \r\nActorDirector table:\r\n+-------------+-------------+-------------+\r\n| actor_id    | director_id | timestamp   |\r\n+-------------+-------------+-------------+\r\n| 1           | 1           | 0           |\r\n| 1           | 1           | 1           |\r\n| 1           | 1           | 2           |\r\n| 1           | 2           | 3           |\r\n| 1           | 2           | 4           |\r\n| 2           | 1           | 5           |\r\n| 2           | 1           | 6           |\r\n+-------------+-------------+-------------+\r\n\r\nResult table:\r\n+-------------+-------------+\r\n| actor_id    | director_id |\r\n+-------------+-------------+\r\n| 1           | 1           |\r\n+-------------+-------------+\r\nThe only pair is (1, 1) where they cooperated exactly 3 times.\r\n
    \r\n", "content_cn": "

    ActorDirector \u8868\uff1a

    \n\n
    \n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| actor_id    | int     |\n| director_id | int     |\n| timestamp   | int     |\n+-------------+---------+\ntimestamp \u662f\u8fd9\u5f20\u8868\u7684\u4e3b\u952e.\n
    \n\n

     

    \n\n

    \u5199\u4e00\u6761SQL\u67e5\u8be2\u8bed\u53e5\u83b7\u53d6\u5408\u4f5c\u8fc7\u81f3\u5c11\u4e09\u6b21\u7684\u6f14\u5458\u548c\u5bfc\u6f14\u7684 id \u5bf9 (actor_id, director_id)

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \nActorDirector \u8868\uff1a\n+-------------+-------------+-------------+\n| actor_id    | director_id | timestamp   |\n+-------------+-------------+-------------+\n| 1           | 1           | 0           |\n| 1           | 1           | 1           |\n| 1           | 1           | 2           |\n| 1           | 2           | 3           |\n| 1           | 2           | 4           |\n| 2           | 1           | 5           |\n| 2           | 1           | 6           |\n+-------------+-------------+-------------+\n\nResult \u8868\uff1a\n+-------------+-------------+\n| actor_id    | director_id |\n+-------------+-------------+\n| 1           | 1           |\n+-------------+-------------+\n\u552f\u4e00\u7684 id \u5bf9\u662f (1, 1)\uff0c\u4ed6\u4eec\u6070\u597d\u5408\u4f5c\u4e86 3 \u6b21\u3002
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1050](https://leetcode-cn.com/problems/actors-and-directors-who-cooperated-at-least-three-times)", "[\u5408\u4f5c\u8fc7\u81f3\u5c11\u4e09\u6b21\u7684\u6f14\u5458\u548c\u5bfc\u6f14](/solution/1000-1099/1050.Actors%20and%20Directors%20Who%20Cooperated%20At%20Least%20Three%20Times/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1050](https://leetcode.com/problems/actors-and-directors-who-cooperated-at-least-three-times)", "[Actors and Directors Who Cooperated At Least Three Times](/solution/1000-1099/1050.Actors%20and%20Directors%20Who%20Cooperated%20At%20Least%20Three%20Times/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1135", "frontend_question_id": "1045", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/customers-who-bought-all-products", "url_en": "https://leetcode.com/problems/customers-who-bought-all-products", "relative_path_cn": "/solution/1000-1099/1045.Customers%20Who%20Bought%20All%20Products/README.md", "relative_path_en": "/solution/1000-1099/1045.Customers%20Who%20Bought%20All%20Products/README_EN.md", "title_cn": "\u4e70\u4e0b\u6240\u6709\u4ea7\u54c1\u7684\u5ba2\u6237", "title_en": "Customers Who Bought All Products", "question_title_slug": "customers-who-bought-all-products", "content_en": "

    Table: Customer

    \n\n
    \n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| customer_id | int     |\n| product_key | int     |\n+-------------+---------+\nproduct_key is a foreign key to Product table.\n
    \n\n

     

    \n\n

    Table: Product

    \n\n
    \n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| product_key | int     |\n+-------------+---------+\nproduct_key is the primary key column for this table.\n
    \n\n

     

    \n\n

    Write an SQL query for a report that provides the customer ids from the Customer table that bought all the products in the Product table.

    \n\n

    Return the result table in any order.

    \n\n

    The query result format is in the following example:

    \n\n

     

    \n\n
    \nCustomer table:\n+-------------+-------------+\n| customer_id | product_key |\n+-------------+-------------+\n| 1           | 5           |\n| 2           | 6           |\n| 3           | 5           |\n| 3           | 6           |\n| 1           | 6           |\n+-------------+-------------+\n\nProduct table:\n+-------------+\n| product_key |\n+-------------+\n| 5           |\n| 6           |\n+-------------+\n\nResult table:\n+-------------+\n| customer_id |\n+-------------+\n| 1           |\n| 3           |\n+-------------+\nThe customers who bought all the products (5 and 6) are customers with id 1 and 3.\n
    \n", "content_cn": "

    Customer \u8868\uff1a

    \n\n
    +-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| customer_id | int     |\n| product_key | int     |\n+-------------+---------+\nproduct_key \u662f Customer \u8868\u7684\u5916\u952e\u3002\n
    \n\n

    Product \u8868\uff1a

    \n\n
    +-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| product_key | int     |\n+-------------+---------+\nproduct_key \u662f\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\u3002\n
    \n\n

     

    \n\n

    \u5199\u4e00\u6761 SQL \u67e5\u8be2\u8bed\u53e5\uff0c\u4ece Customer \u8868\u4e2d\u67e5\u8be2\u8d2d\u4e70\u4e86 Product \u8868\u4e2d\u6240\u6709\u4ea7\u54c1\u7684\u5ba2\u6237\u7684 id\u3002

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    Customer \u8868\uff1a\n+-------------+-------------+\n| customer_id | product_key |\n+-------------+-------------+\n| 1           | 5           |\n| 2           | 6           |\n| 3           | 5           |\n| 3           | 6           |\n| 1           | 6           |\n+-------------+-------------+\n\nProduct \u8868\uff1a\n+-------------+\n| product_key |\n+-------------+\n| 5           |\n| 6           |\n+-------------+\n\nResult \u8868\uff1a\n+-------------+\n| customer_id |\n+-------------+\n| 1           |\n| 3           |\n+-------------+\n\u8d2d\u4e70\u4e86\u6240\u6709\u4ea7\u54c1\uff085 \u548c 6\uff09\u7684\u5ba2\u6237\u7684 id \u662f 1 \u548c 3 \u3002\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1045](https://leetcode-cn.com/problems/customers-who-bought-all-products)", "[\u4e70\u4e0b\u6240\u6709\u4ea7\u54c1\u7684\u5ba2\u6237](/solution/1000-1099/1045.Customers%20Who%20Bought%20All%20Products/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1045](https://leetcode.com/problems/customers-who-bought-all-products)", "[Customers Who Bought All Products](/solution/1000-1099/1045.Customers%20Who%20Bought%20All%20Products/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "1134", "frontend_question_id": "1182", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/shortest-distance-to-target-color", "url_en": "https://leetcode.com/problems/shortest-distance-to-target-color", "relative_path_cn": "/solution/1100-1199/1182.Shortest%20Distance%20to%20Target%20Color/README.md", "relative_path_en": "/solution/1100-1199/1182.Shortest%20Distance%20to%20Target%20Color/README_EN.md", "title_cn": "\u4e0e\u76ee\u6807\u989c\u8272\u95f4\u7684\u6700\u77ed\u8ddd\u79bb", "title_en": "Shortest Distance to Target Color", "question_title_slug": "shortest-distance-to-target-color", "content_en": "

    You are given an array colors, in which there are three colors: 1, 2 and 3.

    \n\n

    You are also given some queries. Each query consists of two integers i and c, return the shortest distance between the given index i and the target color c. If there is no solution return -1.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: colors = [1,1,2,1,3,2,2,3,3], queries = [[1,3],[2,2],[6,1]]\nOutput: [3,0,3]\nExplanation: \nThe nearest 3 from index 1 is at index 4 (3 steps away).\nThe nearest 2 from index 2 is at index 2 itself (0 steps away).\nThe nearest 1 from index 6 is at index 3 (3 steps away).\n
    \n\n

    Example 2:

    \n\n
    \nInput: colors = [1,2], queries = [[0,3]]\nOutput: [-1]\nExplanation: There is no 3 in the array.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= colors.length <= 5*10^4
    • \n\t
    • 1 <= colors[i] <= 3
    • \n\t
    • 1 <= queries.length <= 5*10^4
    • \n\t
    • queries[i].length == 2
    • \n\t
    • 0 <= queries[i][0] < colors.length
    • \n\t
    • 1 <= queries[i][1] <= 3
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 colors\uff0c\u91cc\u9762\u6709  1\u30012\u3001 3 \u4e09\u79cd\u989c\u8272\u3002

    \n\n

    \u6211\u4eec\u9700\u8981\u5728 colors \u4e0a\u8fdb\u884c\u4e00\u4e9b\u67e5\u8be2\u64cd\u4f5c queries\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5f85\u67e5\u9879\u90fd\u7531\u4e24\u4e2a\u6574\u6570 i \u548c c \u7ec4\u6210\u3002

    \n\n

    \u73b0\u5728\u8bf7\u4f60\u5e2e\u5fd9\u8bbe\u8ba1\u4e00\u4e2a\u7b97\u6cd5\uff0c\u67e5\u627e\u4ece\u7d22\u5f15 i \u5230\u5177\u6709\u76ee\u6807\u989c\u8272 c \u7684\u5143\u7d20\u4e4b\u95f4\u7684\u6700\u77ed\u8ddd\u79bb\u3002

    \n\n

    \u5982\u679c\u4e0d\u5b58\u5728\u89e3\u51b3\u65b9\u6848\uff0c\u8bf7\u8fd4\u56de -1\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1acolors = [1,1,2,1,3,2,2,3,3], queries = [[1,3],[2,2],[6,1]]\n\u8f93\u51fa\uff1a[3,0,3]\n\u89e3\u91ca\uff1a \n\u8ddd\u79bb\u7d22\u5f15 1 \u6700\u8fd1\u7684\u989c\u8272 3 \u4f4d\u4e8e\u7d22\u5f15 4\uff08\u8ddd\u79bb\u4e3a 3\uff09\u3002\n\u8ddd\u79bb\u7d22\u5f15 2 \u6700\u8fd1\u7684\u989c\u8272 2 \u5c31\u662f\u5b83\u81ea\u5df1\uff08\u8ddd\u79bb\u4e3a 0\uff09\u3002\n\u8ddd\u79bb\u7d22\u5f15 6 \u6700\u8fd1\u7684\u989c\u8272 1 \u4f4d\u4e8e\u7d22\u5f15 3\uff08\u8ddd\u79bb\u4e3a 3\uff09\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1acolors = [1,2], queries = [[0,3]]\n\u8f93\u51fa\uff1a[-1]\n\u89e3\u91ca\uff1acolors \u4e2d\u6ca1\u6709\u989c\u8272 3\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= colors.length <= 5*10^4
    • \n\t
    • 1 <= colors[i] <= 3
    • \n\t
    • 1 <= queries.length <= 5*10^4
    • \n\t
    • queries[i].length == 2
    • \n\t
    • 0 <= queries[i][0] < colors.length
    • \n\t
    • 1 <= queries[i][1] <= 3
    • \n
    \n", "tags_en": ["Binary Search"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector shortestDistanceColor(vector& colors, vector>& queries) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List shortestDistanceColor(int[] colors, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def shortestDistanceColor(self, colors, queries):\n \"\"\"\n :type colors: List[int]\n :type queries: List[List[int]]\n :rtype: List[int]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def shortestDistanceColor(self, colors: List[int], queries: List[List[int]]) -> List[int]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* shortestDistanceColor(int* colors, int colorsSize, int** queries, int queriesSize, int* queriesColSize, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList ShortestDistanceColor(int[] colors, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} colors\n * @param {number[][]} queries\n * @return {number[]}\n */\nvar shortestDistanceColor = function(colors, queries) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} colors\n# @param {Integer[][]} queries\n# @return {Integer[]}\ndef shortest_distance_color(colors, queries)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func shortestDistanceColor(_ colors: [Int], _ queries: [[Int]]) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func shortestDistanceColor(colors []int, queries [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def shortestDistanceColor(colors: Array[Int], queries: Array[Array[Int]]): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun shortestDistanceColor(colors: IntArray, queries: Array): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn shortest_distance_color(colors: Vec, queries: Vec>) -> Vec {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $colors\n * @param Integer[][] $queries\n * @return Integer[]\n */\n function shortestDistanceColor($colors, $queries) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function shortestDistanceColor(colors: number[], queries: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (shortest-distance-color colors queries)\n (-> (listof exact-integer?) (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1182](https://leetcode-cn.com/problems/shortest-distance-to-target-color)", "[\u4e0e\u76ee\u6807\u989c\u8272\u95f4\u7684\u6700\u77ed\u8ddd\u79bb](/solution/1100-1199/1182.Shortest%20Distance%20to%20Target%20Color/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1182](https://leetcode.com/problems/shortest-distance-to-target-color)", "[Shortest Distance to Target Color](/solution/1100-1199/1182.Shortest%20Distance%20to%20Target%20Color/README_EN.md)", "`Binary Search`", "Medium", "\ud83d\udd12"]}, {"question_id": "1133", "frontend_question_id": "1163", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/last-substring-in-lexicographical-order", "url_en": "https://leetcode.com/problems/last-substring-in-lexicographical-order", "relative_path_cn": "/solution/1100-1199/1163.Last%20Substring%20in%20Lexicographical%20Order/README.md", "relative_path_en": "/solution/1100-1199/1163.Last%20Substring%20in%20Lexicographical%20Order/README_EN.md", "title_cn": "\u6309\u5b57\u5178\u5e8f\u6392\u5728\u6700\u540e\u7684\u5b50\u4e32", "title_en": "Last Substring in Lexicographical Order", "question_title_slug": "last-substring-in-lexicographical-order", "content_en": "

    Given a string s, return the last substring of s in lexicographical order.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "abab"\nOutput: "bab"\nExplanation: The substrings are ["a", "ab", "aba", "abab", "b", "ba", "bab"]. The lexicographically maximum substring is "bab".\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "leetcode"\nOutput: "tcode"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 4 * 105
    • \n\t
    • s contains only lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s\uff0c\u627e\u51fa\u5b83\u7684\u6240\u6709\u5b50\u4e32\u5e76\u6309\u5b57\u5178\u5e8f\u6392\u5217\uff0c\u8fd4\u56de\u6392\u5728\u6700\u540e\u7684\u90a3\u4e2a\u5b50\u4e32\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a"abab"\n\u8f93\u51fa\uff1a"bab"\n\u89e3\u91ca\uff1a\u6211\u4eec\u53ef\u4ee5\u627e\u51fa 7 \u4e2a\u5b50\u4e32 ["a", "ab", "aba", "abab", "b", "ba", "bab"]\u3002\u6309\u5b57\u5178\u5e8f\u6392\u5728\u6700\u540e\u7684\u5b50\u4e32\u662f "bab"\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a"leetcode"\n\u8f93\u51fa\uff1a"tcode"\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= s.length <= 4 * 10^5
    2. \n\t
    3. s \u4ec5\u542b\u6709\u5c0f\u5199\u82f1\u6587\u5b57\u7b26\u3002
    4. \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string lastSubstring(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String lastSubstring(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def lastSubstring(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def lastSubstring(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * lastSubstring(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string LastSubstring(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar lastSubstring = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef last_substring(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func lastSubstring(_ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func lastSubstring(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def lastSubstring(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun lastSubstring(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn last_substring(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function lastSubstring($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function lastSubstring(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (last-substring s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1163](https://leetcode-cn.com/problems/last-substring-in-lexicographical-order)", "[\u6309\u5b57\u5178\u5e8f\u6392\u5728\u6700\u540e\u7684\u5b50\u4e32](/solution/1100-1199/1163.Last%20Substring%20in%20Lexicographical%20Order/README.md)", "`\u5b57\u7b26\u4e32`", "\u56f0\u96be", ""], "md_table_row_en": ["[1163](https://leetcode.com/problems/last-substring-in-lexicographical-order)", "[Last Substring in Lexicographical Order](/solution/1100-1199/1163.Last%20Substring%20in%20Lexicographical%20Order/README_EN.md)", "`String`", "Hard", ""]}, {"question_id": "1132", "frontend_question_id": "1181", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/before-and-after-puzzle", "url_en": "https://leetcode.com/problems/before-and-after-puzzle", "relative_path_cn": "/solution/1100-1199/1181.Before%20and%20After%20Puzzle/README.md", "relative_path_en": "/solution/1100-1199/1181.Before%20and%20After%20Puzzle/README_EN.md", "title_cn": "\u524d\u540e\u62fc\u63a5", "title_en": "Before and After Puzzle", "question_title_slug": "before-and-after-puzzle", "content_en": "

    Given a list of phrases, generate a list of Before and After puzzles.

    \n\n

    A phrase is a string that consists of lowercase English letters and spaces only. No space appears in the start or the end of a phrase. There are no consecutive spaces in a phrase.

    \n\n

    Before and After puzzles are phrases that are formed by merging two phrases where the last word of the first phrase is the same as the first word of the second phrase.

    \n\n

    Return the Before and After puzzles that can be formed by every two phrases phrases[i] and phrases[j] where i != j. Note that the order of matching two phrases matters, we want to consider both orders.

    \n\n

    You should return a list of distinct strings sorted lexicographically.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: phrases = ["writing code","code rocks"]\nOutput: ["writing code rocks"]\n
    \n\n

    Example 2:

    \n\n
    \nInput: phrases = ["mission statement",\n                  "a quick bite to eat",\n                  "a chip off the old block",\n                  "chocolate bar",\n                  "mission impossible",\n                  "a man on a mission",\n                  "block party",\n                  "eat my words",\n                  "bar of soap"]\nOutput: ["a chip off the old block party",\n         "a man on a mission impossible",\n         "a man on a mission statement",\n         "a quick bite to eat my words",\n         "chocolate bar of soap"]\n
    \n\n

    Example 3:

    \n\n
    \nInput: phrases = ["a","b","a"]\nOutput: ["a"]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= phrases.length <= 100
    • \n\t
    • 1 <= phrases[i].length <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u300c\u77ed\u8bed\u300d\u5217\u8868 phrases\uff0c\u8bf7\u4f60\u5e2e\u5fd9\u6309\u89c4\u5219\u751f\u6210\u62fc\u63a5\u540e\u7684\u300c\u65b0\u77ed\u8bed\u300d\u5217\u8868\u3002

    \n\n

    \u300c\u77ed\u8bed\u300d\uff08phrase\uff09\u662f\u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u548c\u7a7a\u683c\u7ec4\u6210\u7684\u5b57\u7b26\u4e32\u3002\u300c\u77ed\u8bed\u300d\u7684\u5f00\u5934\u548c\u7ed3\u5c3e\u90fd\u4e0d\u4f1a\u51fa\u73b0\u7a7a\u683c\uff0c\u300c\u77ed\u8bed\u300d\u4e2d\u7684\u7a7a\u683c\u4e0d\u4f1a\u8fde\u7eed\u51fa\u73b0\u3002

    \n\n

    \u300c\u524d\u540e\u62fc\u63a5\u300d\uff08Before and After puzzles\uff09\u662f\u5408\u5e76\u4e24\u4e2a\u300c\u77ed\u8bed\u300d\u5f62\u6210\u300c\u65b0\u77ed\u8bed\u300d\u7684\u65b9\u6cd5\u3002\u6211\u4eec\u89c4\u5b9a\u62fc\u63a5\u65f6\uff0c\u7b2c\u4e00\u4e2a\u77ed\u8bed\u7684\u6700\u540e\u4e00\u4e2a\u5355\u8bcd \u548c \u7b2c\u4e8c\u4e2a\u77ed\u8bed\u7684\u7b2c\u4e00\u4e2a\u5355\u8bcd \u5fc5\u987b\u76f8\u540c\u3002

    \n\n

    \u8fd4\u56de\u6bcf\u4e24\u4e2a\u300c\u77ed\u8bed\u300d phrases[i] \u548c phrases[j]\uff08i != j\uff09\u8fdb\u884c\u300c\u524d\u540e\u62fc\u63a5\u300d\u5f97\u5230\u7684\u300c\u65b0\u77ed\u8bed\u300d\u3002

    \n\n

    \u6ce8\u610f\uff0c\u4e24\u4e2a\u300c\u77ed\u8bed\u300d\u62fc\u63a5\u65f6\u7684\u987a\u5e8f\u4e5f\u5f88\u91cd\u8981\uff0c\u6211\u4eec\u9700\u8981\u540c\u65f6\u8003\u8651\u8fd9\u4e24\u4e2a\u300c\u77ed\u8bed\u300d\u3002\u53e6\u5916\uff0c\u540c\u4e00\u4e2a\u300c\u77ed\u8bed\u300d\u53ef\u4ee5\u591a\u6b21\u53c2\u4e0e\u62fc\u63a5\uff0c\u4f46\u300c\u65b0\u77ed\u8bed\u300d\u4e0d\u80fd\u518d\u53c2\u4e0e\u62fc\u63a5\u3002

    \n\n

    \u8bf7\u4f60\u6309\u5b57\u5178\u5e8f\u6392\u5217\u5e76\u8fd4\u56de\u300c\u65b0\u77ed\u8bed\u300d\u5217\u8868\uff0c\u5217\u8868\u4e2d\u7684\u5b57\u7b26\u4e32\u5e94\u8be5\u662f \u4e0d\u91cd\u590d\u7684 \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aphrases = ["writing code","code rocks"]\n\u8f93\u51fa\uff1a["writing code rocks"]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aphrases = ["mission statement",\n                "a quick bite to eat",\n                "a chip off the old block",\n                "chocolate bar",\n                "mission impossible",\n                "a man on a mission",\n                "block party",\n                "eat my words",\n                "bar of soap"]\n\u8f93\u51fa\uff1a["a chip off the old block party",\n      "a man on a mission impossible",\n      "a man on a mission statement",\n      "a quick bite to eat my words",\n      "chocolate bar of soap"]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aphrases = ["a","b","a"]\n\u8f93\u51fa\uff1a["a"]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= phrases.length <= 100
    • \n\t
    • 1 <= phrases[i].length <= 100
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector beforeAndAfterPuzzles(vector& phrases) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List beforeAndAfterPuzzles(String[] phrases) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def beforeAndAfterPuzzles(self, phrases):\n \"\"\"\n :type phrases: List[str]\n :rtype: List[str]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def beforeAndAfterPuzzles(self, phrases: List[str]) -> List[str]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** beforeAndAfterPuzzles(char ** phrases, int phrasesSize, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList BeforeAndAfterPuzzles(string[] phrases) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} phrases\n * @return {string[]}\n */\nvar beforeAndAfterPuzzles = function(phrases) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} phrases\n# @return {String[]}\ndef before_and_after_puzzles(phrases)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func beforeAndAfterPuzzles(_ phrases: [String]) -> [String] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func beforeAndAfterPuzzles(phrases []string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def beforeAndAfterPuzzles(phrases: Array[String]): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun beforeAndAfterPuzzles(phrases: Array): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn before_and_after_puzzles(phrases: Vec) -> Vec {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $phrases\n * @return String[]\n */\n function beforeAndAfterPuzzles($phrases) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function beforeAndAfterPuzzles(phrases: string[]): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (before-and-after-puzzles phrases)\n (-> (listof string?) (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1181](https://leetcode-cn.com/problems/before-and-after-puzzle)", "[\u524d\u540e\u62fc\u63a5](/solution/1100-1199/1181.Before%20and%20After%20Puzzle/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1181](https://leetcode.com/problems/before-and-after-puzzle)", "[Before and After Puzzle](/solution/1100-1199/1181.Before%20and%20After%20Puzzle/README_EN.md)", "`String`", "Medium", "\ud83d\udd12"]}, {"question_id": "1131", "frontend_question_id": "1180", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/count-substrings-with-only-one-distinct-letter", "url_en": "https://leetcode.com/problems/count-substrings-with-only-one-distinct-letter", "relative_path_cn": "/solution/1100-1199/1180.Count%20Substrings%20with%20Only%20One%20Distinct%20Letter/README.md", "relative_path_en": "/solution/1100-1199/1180.Count%20Substrings%20with%20Only%20One%20Distinct%20Letter/README_EN.md", "title_cn": "\u7edf\u8ba1\u53ea\u542b\u5355\u4e00\u5b57\u6bcd\u7684\u5b50\u4e32", "title_en": "Count Substrings with Only One Distinct Letter", "question_title_slug": "count-substrings-with-only-one-distinct-letter", "content_en": "

    Given a string s, return the number of substrings that have only one distinct letter.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "aaaba"\nOutput: 8\nExplanation: The substrings with one distinct letter are "aaa", "aa", "a", "b".\n"aaa" occurs 1 time.\n"aa" occurs 2 times.\n"a" occurs 4 times.\n"b" occurs 1 time.\nSo the answer is 1 + 2 + 4 + 1 = 8.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "aaaaaaaaaa"\nOutput: 55\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 1000
    • \n\t
    • s[i] consists of only lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 S\uff0c\u8fd4\u56de\u53ea\u542b \u5355\u4e00\u5b57\u6bcd \u7684\u5b50\u4e32\u4e2a\u6570\u3002

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a "aaaba"\n\u8f93\u51fa\uff1a 8\n\u89e3\u91ca\uff1a \n\u53ea\u542b\u5355\u4e00\u5b57\u6bcd\u7684\u5b50\u4e32\u5206\u522b\u662f "aaa"\uff0c "aa"\uff0c "a"\uff0c "b"\u3002\n"aaa" \u51fa\u73b0 1 \u6b21\u3002\n"aa" \u51fa\u73b0 2 \u6b21\u3002\n"a" \u51fa\u73b0 4 \u6b21\u3002\n"b" \u51fa\u73b0 1 \u6b21\u3002\n\u6240\u4ee5\u7b54\u6848\u662f 1 + 2 + 4 + 1 = 8\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165\uff1a "aaaaaaaaaa"\n\u8f93\u51fa\uff1a 55\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= S.length <= 1000
    2. \n\t
    3. S[i] \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\u3002
    4. \n
    \n", "tags_en": ["Math", "String"], "tags_cn": ["\u6570\u5b66", "\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countLetters(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countLetters(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countLetters(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countLetters(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countLetters(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountLetters(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar countLetters = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef count_letters(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countLetters(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countLetters(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countLetters(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countLetters(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_letters(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function countLetters($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countLetters(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-letters s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1180](https://leetcode-cn.com/problems/count-substrings-with-only-one-distinct-letter)", "[\u7edf\u8ba1\u53ea\u542b\u5355\u4e00\u5b57\u6bcd\u7684\u5b50\u4e32](/solution/1100-1199/1180.Count%20Substrings%20with%20Only%20One%20Distinct%20Letter/README.md)", "`\u6570\u5b66`,`\u5b57\u7b26\u4e32`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1180](https://leetcode.com/problems/count-substrings-with-only-one-distinct-letter)", "[Count Substrings with Only One Distinct Letter](/solution/1100-1199/1180.Count%20Substrings%20with%20Only%20One%20Distinct%20Letter/README_EN.md)", "`Math`,`String`", "Easy", "\ud83d\udd12"]}, {"question_id": "1130", "frontend_question_id": "1049", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/last-stone-weight-ii", "url_en": "https://leetcode.com/problems/last-stone-weight-ii", "relative_path_cn": "/solution/1000-1099/1049.Last%20Stone%20Weight%20II/README.md", "relative_path_en": "/solution/1000-1099/1049.Last%20Stone%20Weight%20II/README_EN.md", "title_cn": "\u6700\u540e\u4e00\u5757\u77f3\u5934\u7684\u91cd\u91cf II", "title_en": "Last Stone Weight II", "question_title_slug": "last-stone-weight-ii", "content_en": "

    You are given an array of integers stones where stones[i] is the weight of the ith stone.

    \n\n

    We are playing a game with the stones. On each turn, we choose any two stones and smash them together. Suppose the stones have weights x and y with x <= y. The result of this smash is:

    \n\n
      \n\t
    • If x == y, both stones are destroyed, and
    • \n\t
    • If x != y, the stone of weight x is destroyed, and the stone of weight y has new weight y - x.
    • \n
    \n\n

    At the end of the game, there is at most one stone left.

    \n\n

    Return the smallest possible weight of the left stone. If there are no stones left, return 0.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: stones = [2,7,4,1,8,1]\nOutput: 1\nExplanation:\nWe can combine 2 and 4 to get 2, so the array converts to [2,7,1,8,1] then,\nwe can combine 7 and 8 to get 1, so the array converts to [2,1,1,1] then,\nwe can combine 2 and 1 to get 1, so the array converts to [1,1,1] then,\nwe can combine 1 and 1 to get 0, so the array converts to [1], then that's the optimal value.\n
    \n\n

    Example 2:

    \n\n
    \nInput: stones = [31,26,33,21,40]\nOutput: 5\n
    \n\n

    Example 3:

    \n\n
    \nInput: stones = [1,2]\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= stones.length <= 30
    • \n\t
    • 1 <= stones[i] <= 100
    • \n
    \n", "content_cn": "

    \u6709\u4e00\u5806\u77f3\u5934\uff0c\u6bcf\u5757\u77f3\u5934\u7684\u91cd\u91cf\u90fd\u662f\u6b63\u6574\u6570\u3002

    \n\n

    \u6bcf\u4e00\u56de\u5408\uff0c\u4ece\u4e2d\u9009\u51fa\u4efb\u610f\u4e24\u5757\u77f3\u5934\uff0c\u7136\u540e\u5c06\u5b83\u4eec\u4e00\u8d77\u7c89\u788e\u3002\u5047\u8bbe\u77f3\u5934\u7684\u91cd\u91cf\u5206\u522b\u4e3a x \u548c y\uff0c\u4e14 x <= y\u3002\u90a3\u4e48\u7c89\u788e\u7684\u53ef\u80fd\u7ed3\u679c\u5982\u4e0b\uff1a

    \n\n
      \n\t
    • \u5982\u679c x == y\uff0c\u90a3\u4e48\u4e24\u5757\u77f3\u5934\u90fd\u4f1a\u88ab\u5b8c\u5168\u7c89\u788e\uff1b
    • \n\t
    • \u5982\u679c x != y\uff0c\u90a3\u4e48\u91cd\u91cf\u4e3a x \u7684\u77f3\u5934\u5c06\u4f1a\u5b8c\u5168\u7c89\u788e\uff0c\u800c\u91cd\u91cf\u4e3a y \u7684\u77f3\u5934\u65b0\u91cd\u91cf\u4e3a y-x\u3002
    • \n
    \n\n

    \u6700\u540e\uff0c\u6700\u591a\u53ea\u4f1a\u5269\u4e0b\u4e00\u5757\u77f3\u5934\u3002\u8fd4\u56de\u6b64\u77f3\u5934\u6700\u5c0f\u7684\u53ef\u80fd\u91cd\u91cf\u3002\u5982\u679c\u6ca1\u6709\u77f3\u5934\u5269\u4e0b\uff0c\u5c31\u8fd4\u56de 0\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1a[2,7,4,1,8,1]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\n\u7ec4\u5408 2 \u548c 4\uff0c\u5f97\u5230 2\uff0c\u6240\u4ee5\u6570\u7ec4\u8f6c\u5316\u4e3a [2,7,1,8,1]\uff0c\n\u7ec4\u5408 7 \u548c 8\uff0c\u5f97\u5230 1\uff0c\u6240\u4ee5\u6570\u7ec4\u8f6c\u5316\u4e3a [2,1,1,1]\uff0c\n\u7ec4\u5408 2 \u548c 1\uff0c\u5f97\u5230 1\uff0c\u6240\u4ee5\u6570\u7ec4\u8f6c\u5316\u4e3a [1,1,1]\uff0c\n\u7ec4\u5408 1 \u548c 1\uff0c\u5f97\u5230 0\uff0c\u6240\u4ee5\u6570\u7ec4\u8f6c\u5316\u4e3a [1]\uff0c\u8fd9\u5c31\u662f\u6700\u4f18\u503c\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= stones.length <= 30
    2. \n\t
    3. 1 <= stones[i] <= 1000
    4. \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int lastStoneWeightII(vector& stones) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int lastStoneWeightII(int[] stones) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def lastStoneWeightII(self, stones):\n \"\"\"\n :type stones: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def lastStoneWeightII(self, stones: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint lastStoneWeightII(int* stones, int stonesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LastStoneWeightII(int[] stones) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} stones\n * @return {number}\n */\nvar lastStoneWeightII = function(stones) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} stones\n# @return {Integer}\ndef last_stone_weight_ii(stones)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func lastStoneWeightII(_ stones: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func lastStoneWeightII(stones []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def lastStoneWeightII(stones: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun lastStoneWeightII(stones: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn last_stone_weight_ii(stones: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $stones\n * @return Integer\n */\n function lastStoneWeightII($stones) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function lastStoneWeightII(stones: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (last-stone-weight-ii stones)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1049](https://leetcode-cn.com/problems/last-stone-weight-ii)", "[\u6700\u540e\u4e00\u5757\u77f3\u5934\u7684\u91cd\u91cf II](/solution/1000-1099/1049.Last%20Stone%20Weight%20II/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1049](https://leetcode.com/problems/last-stone-weight-ii)", "[Last Stone Weight II](/solution/1000-1099/1049.Last%20Stone%20Weight%20II/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "1129", "frontend_question_id": "1048", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-string-chain", "url_en": "https://leetcode.com/problems/longest-string-chain", "relative_path_cn": "/solution/1000-1099/1048.Longest%20String%20Chain/README.md", "relative_path_en": "/solution/1000-1099/1048.Longest%20String%20Chain/README_EN.md", "title_cn": "\u6700\u957f\u5b57\u7b26\u4e32\u94fe", "title_en": "Longest String Chain", "question_title_slug": "longest-string-chain", "content_en": "

    You are given an array of words where each word consists of lowercase English letters.

    \n\n

    wordA is a predecessor of wordB if and only if we can insert exactly one letter anywhere in wordA without changing the order of the other characters to make it equal to wordB.

    \n\n
      \n\t
    • For example, "abc" is a predecessor of "abac", while "cba" is not a predecessor of "bcad".
    • \n
    \n\n

    A word chain is a sequence of words [word1, word2, ..., wordk] with k >= 1, where word1 is a predecessor of word2, word2 is a predecessor of word3, and so on. A single word is trivially a word chain with k == 1.

    \n\n

    Return the length of the longest possible word chain with words chosen from the given list of words.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: words = ["a","b","ba","bca","bda","bdca"]\nOutput: 4\nExplanation: One of the longest word chains is ["a","ba","bda","bdca"].\n
    \n\n

    Example 2:

    \n\n
    \nInput: words = ["xbc","pcxbcf","xb","cxbc","pcxbc"]\nOutput: 5\nExplanation: All the words can be put in a word chain ["xb", "xbc", "cxbc", "pcxbc", "pcxbcf"].\n
    \n\n

    Example 3:

    \n\n
    \nInput: words = ["abcd","dbqca"]\nOutput: 1\nExplanation: The trivial word chain ["abcd"] is one of the longest word chains.\n["abcd","dbqca"] is not a valid word chain because the ordering of the letters is changed.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= words.length <= 1000
    • \n\t
    • 1 <= words[i].length <= 16
    • \n\t
    • words[i] only consists of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u51fa\u4e00\u4e2a\u5355\u8bcd\u5217\u8868\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5355\u8bcd\u90fd\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\u3002

    \n\n

    \u5982\u679c\u6211\u4eec\u53ef\u4ee5\u5728 word1 \u7684\u4efb\u4f55\u5730\u65b9\u6dfb\u52a0\u4e00\u4e2a\u5b57\u6bcd\u4f7f\u5176\u53d8\u6210 word2\uff0c\u90a3\u4e48\u6211\u4eec\u8ba4\u4e3a word1 \u662f word2 \u7684\u524d\u8eab\u3002\u4f8b\u5982\uff0c"abc" \u662f "abac" \u7684\u524d\u8eab\u3002

    \n\n

    \u8bcd\u94fe\u662f\u5355\u8bcd [word_1, word_2, ..., word_k] \u7ec4\u6210\u7684\u5e8f\u5217\uff0ck >= 1\uff0c\u5176\u4e2d word_1 \u662f word_2 \u7684\u524d\u8eab\uff0cword_2 \u662f word_3 \u7684\u524d\u8eab\uff0c\u4f9d\u6b64\u7c7b\u63a8\u3002

    \n\n

    \u4ece\u7ed9\u5b9a\u5355\u8bcd\u5217\u8868 words \u4e2d\u9009\u62e9\u5355\u8bcd\u7ec4\u6210\u8bcd\u94fe\uff0c\u8fd4\u56de\u8bcd\u94fe\u7684\u6700\u957f\u53ef\u80fd\u957f\u5ea6\u3002
    \n 

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1a["a","b","ba","bca","bda","bdca"]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u6700\u957f\u5355\u8bcd\u94fe\u4e4b\u4e00\u4e3a "a","ba","bda","bdca"\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= words.length <= 1000
    2. \n\t
    3. 1 <= words[i].length <= 16
    4. \n\t
    5. words[i] \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\u3002
    6. \n
    \n\n

     

    \n", "tags_en": ["Hash Table", "Dynamic Programming"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int longestStrChain(vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int longestStrChain(String[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestStrChain(self, words):\n \"\"\"\n :type words: List[str]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestStrChain(self, words: List[str]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint longestStrChain(char ** words, int wordsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LongestStrChain(string[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @return {number}\n */\nvar longestStrChain = function(words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @return {Integer}\ndef longest_str_chain(words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestStrChain(_ words: [String]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestStrChain(words []string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestStrChain(words: Array[String]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestStrChain(words: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_str_chain(words: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @return Integer\n */\n function longestStrChain($words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestStrChain(words: string[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-str-chain words)\n (-> (listof string?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1048](https://leetcode-cn.com/problems/longest-string-chain)", "[\u6700\u957f\u5b57\u7b26\u4e32\u94fe](/solution/1000-1099/1048.Longest%20String%20Chain/README.md)", "`\u54c8\u5e0c\u8868`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1048](https://leetcode.com/problems/longest-string-chain)", "[Longest String Chain](/solution/1000-1099/1048.Longest%20String%20Chain/README_EN.md)", "`Hash Table`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "1128", "frontend_question_id": "1047", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string", "url_en": "https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string", "relative_path_cn": "/solution/1000-1099/1047.Remove%20All%20Adjacent%20Duplicates%20In%20String/README.md", "relative_path_en": "/solution/1000-1099/1047.Remove%20All%20Adjacent%20Duplicates%20In%20String/README_EN.md", "title_cn": "\u5220\u9664\u5b57\u7b26\u4e32\u4e2d\u7684\u6240\u6709\u76f8\u90bb\u91cd\u590d\u9879", "title_en": "Remove All Adjacent Duplicates In String", "question_title_slug": "remove-all-adjacent-duplicates-in-string", "content_en": "

    You are given a string s consisting of lowercase English letters. A duplicate removal consists of choosing two adjacent and equal letters and removing them.

    \n\n

    We repeatedly make duplicate removals on s until we no longer can.

    \n\n

    Return the final string after all such duplicate removals have been made. It can be proven that the answer is unique.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "abbaca"\nOutput: "ca"\nExplanation: \nFor example, in "abbaca" we could remove "bb" since the letters are adjacent and equal, and this is the only possible move.  The result of this move is that the string is "aaca", of which only "aa" is possible, so the final string is "ca".\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "azxxzy"\nOutput: "ay"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 105
    • \n\t
    • s consists of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u51fa\u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210\u7684\u5b57\u7b26\u4e32 S\uff0c\u91cd\u590d\u9879\u5220\u9664\u64cd\u4f5c\u4f1a\u9009\u62e9\u4e24\u4e2a\u76f8\u90bb\u4e14\u76f8\u540c\u7684\u5b57\u6bcd\uff0c\u5e76\u5220\u9664\u5b83\u4eec\u3002

    \n\n

    \u5728 S \u4e0a\u53cd\u590d\u6267\u884c\u91cd\u590d\u9879\u5220\u9664\u64cd\u4f5c\uff0c\u76f4\u5230\u65e0\u6cd5\u7ee7\u7eed\u5220\u9664\u3002

    \n\n

    \u5728\u5b8c\u6210\u6240\u6709\u91cd\u590d\u9879\u5220\u9664\u64cd\u4f5c\u540e\u8fd4\u56de\u6700\u7ec8\u7684\u5b57\u7b26\u4e32\u3002\u7b54\u6848\u4fdd\u8bc1\u552f\u4e00\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1a"abbaca"\n\u8f93\u51fa\uff1a"ca"\n\u89e3\u91ca\uff1a\n\u4f8b\u5982\uff0c\u5728 "abbaca" \u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u5220\u9664 "bb" \u7531\u4e8e\u4e24\u5b57\u6bcd\u76f8\u90bb\u4e14\u76f8\u540c\uff0c\u8fd9\u662f\u6b64\u65f6\u552f\u4e00\u53ef\u4ee5\u6267\u884c\u5220\u9664\u64cd\u4f5c\u7684\u91cd\u590d\u9879\u3002\u4e4b\u540e\u6211\u4eec\u5f97\u5230\u5b57\u7b26\u4e32 "aaca"\uff0c\u5176\u4e2d\u53c8\u53ea\u6709 "aa" \u53ef\u4ee5\u6267\u884c\u91cd\u590d\u9879\u5220\u9664\u64cd\u4f5c\uff0c\u6240\u4ee5\u6700\u540e\u7684\u5b57\u7b26\u4e32\u4e3a "ca"\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= S.length <= 20000
    2. \n\t
    3. S \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\u3002
    4. \n
    \n", "tags_en": ["Stack"], "tags_cn": ["\u6808"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string removeDuplicates(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String removeDuplicates(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def removeDuplicates(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def removeDuplicates(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * removeDuplicates(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string RemoveDuplicates(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar removeDuplicates = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef remove_duplicates(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func removeDuplicates(_ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func removeDuplicates(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def removeDuplicates(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun removeDuplicates(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn remove_duplicates(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function removeDuplicates($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function removeDuplicates(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (remove-duplicates s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1047](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string)", "[\u5220\u9664\u5b57\u7b26\u4e32\u4e2d\u7684\u6240\u6709\u76f8\u90bb\u91cd\u590d\u9879](/solution/1000-1099/1047.Remove%20All%20Adjacent%20Duplicates%20In%20String/README.md)", "`\u6808`", "\u7b80\u5355", ""], "md_table_row_en": ["[1047](https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string)", "[Remove All Adjacent Duplicates In String](/solution/1000-1099/1047.Remove%20All%20Adjacent%20Duplicates%20In%20String/README_EN.md)", "`Stack`", "Easy", ""]}, {"question_id": "1127", "frontend_question_id": "1046", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/last-stone-weight", "url_en": "https://leetcode.com/problems/last-stone-weight", "relative_path_cn": "/solution/1000-1099/1046.Last%20Stone%20Weight/README.md", "relative_path_en": "/solution/1000-1099/1046.Last%20Stone%20Weight/README_EN.md", "title_cn": "\u6700\u540e\u4e00\u5757\u77f3\u5934\u7684\u91cd\u91cf", "title_en": "Last Stone Weight", "question_title_slug": "last-stone-weight", "content_en": "

    We have a collection of stones, each stone has a positive integer weight.

    \n\n

    Each turn, we choose the two heaviest stones and smash them together.  Suppose the stones have weights x and y with x <= y.  The result of this smash is:

    \n\n
      \n\t
    • If x == y, both stones are totally destroyed;
    • \n\t
    • If x != y, the stone of weight x is totally destroyed, and the stone of weight y has new weight y-x.
    • \n
    \n\n

    At the end, there is at most 1 stone left.  Return the weight of this stone (or 0 if there are no stones left.)

    \n\n

     

    \n\n

    Example 1:

    \n\n
    \nInput: [2,7,4,1,8,1]\nOutput: 1\nExplanation: \nWe combine 7 and 8 to get 1 so the array converts to [2,4,1,1,1] then,\nwe combine 2 and 4 to get 2 so the array converts to [2,1,1,1] then,\nwe combine 2 and 1 to get 1 so the array converts to [1,1,1] then,\nwe combine 1 and 1 to get 0 so the array converts to [1] then that's the value of last stone.
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    1. 1 <= stones.length <= 30
    2. \n\t
    3. 1 <= stones[i] <= 1000
    4. \n
    \n", "content_cn": "

    \u6709\u4e00\u5806\u77f3\u5934\uff0c\u6bcf\u5757\u77f3\u5934\u7684\u91cd\u91cf\u90fd\u662f\u6b63\u6574\u6570\u3002

    \n\n

    \u6bcf\u4e00\u56de\u5408\uff0c\u4ece\u4e2d\u9009\u51fa\u4e24\u5757 \u6700\u91cd\u7684 \u77f3\u5934\uff0c\u7136\u540e\u5c06\u5b83\u4eec\u4e00\u8d77\u7c89\u788e\u3002\u5047\u8bbe\u77f3\u5934\u7684\u91cd\u91cf\u5206\u522b\u4e3a\u00a0x \u548c\u00a0y\uff0c\u4e14\u00a0x <= y\u3002\u90a3\u4e48\u7c89\u788e\u7684\u53ef\u80fd\u7ed3\u679c\u5982\u4e0b\uff1a

    \n\n
      \n\t
    • \u5982\u679c\u00a0x == y\uff0c\u90a3\u4e48\u4e24\u5757\u77f3\u5934\u90fd\u4f1a\u88ab\u5b8c\u5168\u7c89\u788e\uff1b
    • \n\t
    • \u5982\u679c\u00a0x != y\uff0c\u90a3\u4e48\u91cd\u91cf\u4e3a\u00a0x\u00a0\u7684\u77f3\u5934\u5c06\u4f1a\u5b8c\u5168\u7c89\u788e\uff0c\u800c\u91cd\u91cf\u4e3a\u00a0y\u00a0\u7684\u77f3\u5934\u65b0\u91cd\u91cf\u4e3a\u00a0y-x\u3002
    • \n
    \n\n

    \u6700\u540e\uff0c\u6700\u591a\u53ea\u4f1a\u5269\u4e0b\u4e00\u5757\u77f3\u5934\u3002\u8fd4\u56de\u6b64\u77f3\u5934\u7684\u91cd\u91cf\u3002\u5982\u679c\u6ca1\u6709\u77f3\u5934\u5269\u4e0b\uff0c\u5c31\u8fd4\u56de 0\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[2,7,4,1,8,1]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\n\u5148\u9009\u51fa 7 \u548c 8\uff0c\u5f97\u5230 1\uff0c\u6240\u4ee5\u6570\u7ec4\u8f6c\u6362\u4e3a [2,4,1,1,1]\uff0c\n\u518d\u9009\u51fa 2 \u548c 4\uff0c\u5f97\u5230 2\uff0c\u6240\u4ee5\u6570\u7ec4\u8f6c\u6362\u4e3a [2,1,1,1]\uff0c\n\u63a5\u7740\u662f 2 \u548c 1\uff0c\u5f97\u5230 1\uff0c\u6240\u4ee5\u6570\u7ec4\u8f6c\u6362\u4e3a [1,1,1]\uff0c\n\u6700\u540e\u9009\u51fa 1 \u548c 1\uff0c\u5f97\u5230 0\uff0c\u6700\u7ec8\u6570\u7ec4\u8f6c\u6362\u4e3a [1]\uff0c\u8fd9\u5c31\u662f\u6700\u540e\u5269\u4e0b\u90a3\u5757\u77f3\u5934\u7684\u91cd\u91cf\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= stones.length <= 30
    • \n\t
    • 1 <= stones[i] <= 1000
    • \n
    \n", "tags_en": ["Heap", "Greedy"], "tags_cn": ["\u5806", "\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int lastStoneWeight(vector& stones) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int lastStoneWeight(int[] stones) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def lastStoneWeight(self, stones):\n \"\"\"\n :type stones: List[int]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def lastStoneWeight(self, stones: List[int]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint lastStoneWeight(int* stones, int stonesSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LastStoneWeight(int[] stones) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} stones\n * @return {number}\n */\nvar lastStoneWeight = function(stones) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} stones\n# @return {Integer}\ndef last_stone_weight(stones)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func lastStoneWeight(_ stones: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func lastStoneWeight(stones []int) int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def lastStoneWeight(stones: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun lastStoneWeight(stones: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn last_stone_weight(stones: Vec) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $stones\n * @return Integer\n */\n function lastStoneWeight($stones) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function lastStoneWeight(stones: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (last-stone-weight stones)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1046](https://leetcode-cn.com/problems/last-stone-weight)", "[\u6700\u540e\u4e00\u5757\u77f3\u5934\u7684\u91cd\u91cf](/solution/1000-1099/1046.Last%20Stone%20Weight/README.md)", "`\u5806`,`\u8d2a\u5fc3\u7b97\u6cd5`", "\u7b80\u5355", ""], "md_table_row_en": ["[1046](https://leetcode.com/problems/last-stone-weight)", "[Last Stone Weight](/solution/1000-1099/1046.Last%20Stone%20Weight/README_EN.md)", "`Heap`,`Greedy`", "Easy", ""]}, {"question_id": "1126", "frontend_question_id": "1167", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/minimum-cost-to-connect-sticks", "url_en": "https://leetcode.com/problems/minimum-cost-to-connect-sticks", "relative_path_cn": "/solution/1100-1199/1167.Minimum%20Cost%20to%20Connect%20Sticks/README.md", "relative_path_en": "/solution/1100-1199/1167.Minimum%20Cost%20to%20Connect%20Sticks/README_EN.md", "title_cn": "\u8fde\u63a5\u68d2\u6750\u7684\u6700\u4f4e\u8d39\u7528", "title_en": "Minimum Cost to Connect Sticks", "question_title_slug": "minimum-cost-to-connect-sticks", "content_en": "

    You have some number of sticks with positive integer lengths. These lengths are given as an array sticks, where sticks[i] is the length of the ith stick.

    \n\n

    You can connect any two sticks of lengths x and y into one stick by paying a cost of x + y. You must connect all the sticks until there is only one stick remaining.

    \n\n

    Return the minimum cost of connecting all the given sticks into one stick in this way.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: sticks = [2,4,3]\nOutput: 14\nExplanation: You start with sticks = [2,4,3].\n1. Combine sticks 2 and 3 for a cost of 2 + 3 = 5. Now you have sticks = [5,4].\n2. Combine sticks 5 and 4 for a cost of 5 + 4 = 9. Now you have sticks = [9].\nThere is only one stick left, so you are done. The total cost is 5 + 9 = 14.\n
    \n\n

    Example 2:

    \n\n
    \nInput: sticks = [1,8,3,5]\nOutput: 30\nExplanation: You start with sticks = [1,8,3,5].\n1. Combine sticks 1 and 3 for a cost of 1 + 3 = 4. Now you have sticks = [4,8,5].\n2. Combine sticks 4 and 5 for a cost of 4 + 5 = 9. Now you have sticks = [9,8].\n3. Combine sticks 9 and 8 for a cost of 9 + 8 = 17. Now you have sticks = [17].\nThere is only one stick left, so you are done. The total cost is 4 + 9 + 17 = 30.\n
    \n\n

    Example 3:

    \n\n
    \nInput: sticks = [5]\nOutput: 0\nExplanation: There is only one stick, so you don't need to do anything. The total cost is 0.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= sticks.length <= 104
    • \n\t
    • 1 <= sticks[i] <= 104
    • \n
    \n", "content_cn": "

    \u4e3a\u4e86\u88c5\u4fee\u65b0\u623f\uff0c\u4f60\u9700\u8981\u52a0\u5de5\u4e00\u4e9b\u957f\u5ea6\u4e3a\u6b63\u6574\u6570\u7684\u68d2\u6750 \u3002\u68d2\u6750\u4ee5\u6570\u7ec4 sticks \u7684\u5f62\u5f0f\u7ed9\u51fa\uff0c\u5176\u4e2d sticks[i] \u662f\u7b2c i \u6839\u68d2\u6750\u7684\u957f\u5ea6\u3002

    \n\n

    \u5982\u679c\u8981\u5c06\u957f\u5ea6\u5206\u522b\u4e3a x \u548c y \u7684\u4e24\u6839\u68d2\u6750\u8fde\u63a5\u5728\u4e00\u8d77\uff0c\u4f60\u9700\u8981\u652f\u4ed8 x + y \u7684\u8d39\u7528\u3002 \u7531\u4e8e\u65bd\u5de5\u9700\u8981\uff0c\u4f60\u5fc5\u987b\u5c06\u6240\u6709\u68d2\u6750\u8fde\u63a5\u6210\u4e00\u6839\u3002

    \n\n

    \u8fd4\u56de\u4f60\u628a\u6240\u6709\u68d2\u6750\u00a0sticks\u00a0\u8fde\u6210\u4e00\u6839\u6240\u9700\u8981\u7684\u6700\u4f4e\u8d39\u7528\u3002\u6ce8\u610f\u4f60\u53ef\u4ee5\u4efb\u610f\u9009\u62e9\u68d2\u6750\u8fde\u63a5\u7684\u987a\u5e8f\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1asticks = [2,4,3]\n\u8f93\u51fa\uff1a14\n\u89e3\u91ca\uff1a\u4ece sticks = [2,4,3] \u5f00\u59cb\u3002\n1. \u8fde\u63a5 2 \u548c 3 \uff0c\u8d39\u7528\u4e3a 2 + 3 = 5 \u3002\u73b0\u5728 sticks = [5,4]\n2. \u8fde\u63a5 5 \u548c 4 \uff0c\u8d39\u7528\u4e3a 5 + 4 = 9 \u3002\u73b0\u5728 sticks = [9]\n\u6240\u6709\u68d2\u6750\u5df2\u7ecf\u8fde\u6210\u4e00\u6839\uff0c\u603b\u8d39\u7528 5 + 9 = 14\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1asticks = [1,8,3,5]\n\u8f93\u51fa\uff1a30\n\u89e3\u91ca\uff1a\u4ece sticks = [1,8,3,5] \u5f00\u59cb\u3002\n1. \u8fde\u63a5 1 \u548c 3 \uff0c\u8d39\u7528\u4e3a 1 + 3 = 4 \u3002\u73b0\u5728 sticks = [4,8,5]\n2. \u8fde\u63a5 4 \u548c 5 \uff0c\u8d39\u7528\u4e3a 4 + 5 = 9 \u3002\u73b0\u5728 sticks = [9,8]\n3. \u8fde\u63a5 9 \u548c 8 \uff0c\u8d39\u7528\u4e3a 9 + 8 = 17 \u3002\u73b0\u5728 sticks = [17]\n\u6240\u6709\u68d2\u6750\u5df2\u7ecf\u8fde\u6210\u4e00\u6839\uff0c\u603b\u8d39\u7528 4 + 9 + 17 = 30\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1asticks = [5]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u53ea\u6709\u4e00\u6839\u68d2\u6750\uff0c\u4e0d\u5fc5\u518d\u8fde\u63a5\u3002\u603b\u8d39\u7528 0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= sticks.length <= 104
    • \n\t
    • 1 <= sticks[i] <= 104
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int connectSticks(vector& sticks) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int connectSticks(int[] sticks) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def connectSticks(self, sticks):\n \"\"\"\n :type sticks: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def connectSticks(self, sticks: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint connectSticks(int* sticks, int sticksSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ConnectSticks(int[] sticks) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} sticks\n * @return {number}\n */\nvar connectSticks = function(sticks) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} sticks\n# @return {Integer}\ndef connect_sticks(sticks)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func connectSticks(_ sticks: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func connectSticks(sticks []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def connectSticks(sticks: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun connectSticks(sticks: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn connect_sticks(sticks: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $sticks\n * @return Integer\n */\n function connectSticks($sticks) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function connectSticks(sticks: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (connect-sticks sticks)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1167](https://leetcode-cn.com/problems/minimum-cost-to-connect-sticks)", "[\u8fde\u63a5\u68d2\u6750\u7684\u6700\u4f4e\u8d39\u7528](/solution/1100-1199/1167.Minimum%20Cost%20to%20Connect%20Sticks/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1167](https://leetcode.com/problems/minimum-cost-to-connect-sticks)", "[Minimum Cost to Connect Sticks](/solution/1100-1199/1167.Minimum%20Cost%20to%20Connect%20Sticks/README_EN.md)", "`Greedy`", "Medium", "\ud83d\udd12"]}, {"question_id": "1125", "frontend_question_id": "1166", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/design-file-system", "url_en": "https://leetcode.com/problems/design-file-system", "relative_path_cn": "/solution/1100-1199/1166.Design%20File%20System/README.md", "relative_path_en": "/solution/1100-1199/1166.Design%20File%20System/README_EN.md", "title_cn": "\u8bbe\u8ba1\u6587\u4ef6\u7cfb\u7edf", "title_en": "Design File System", "question_title_slug": "design-file-system", "content_en": "

    You are asked to design a file system that allows you to create new paths and associate them with different values.

    \n\n

    The format of a path is one or more concatenated strings of the form: / followed by one or more lowercase English letters. For example, "/leetcode" and "/leetcode/problems" are valid paths while an empty string "" and "/" are not.

    \n\n

    Implement the FileSystem class:

    \n\n
      \n\t
    • bool createPath(string path, int value) Creates a new path and associates a value to it if possible and returns true. Returns false if the path already exists or its parent path doesn't exist.
    • \n\t
    • int get(string path) Returns the value associated with path or returns -1 if the path doesn't exist.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: \n["FileSystem","createPath","get"]\n[[],["/a",1],["/a"]]\nOutput: \n[null,true,1]\nExplanation: \nFileSystem fileSystem = new FileSystem();\n\nfileSystem.createPath("/a", 1); // return true\nfileSystem.get("/a"); // return 1\n
    \n\n

    Example 2:

    \n\n
    \nInput: \n["FileSystem","createPath","createPath","get","createPath","get"]\n[[],["/leet",1],["/leet/code",2],["/leet/code"],["/c/d",1],["/c"]]\nOutput: \n[null,true,true,2,false,-1]\nExplanation: \nFileSystem fileSystem = new FileSystem();\n\nfileSystem.createPath("/leet", 1); // return true\nfileSystem.createPath("/leet/code", 2); // return true\nfileSystem.get("/leet/code"); // return 2\nfileSystem.createPath("/c/d", 1); // return false because the parent path "/c" doesn't exist.\nfileSystem.get("/c"); // return -1 because this path doesn't exist.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of calls to the two functions is less than or equal to 104 in total.
    • \n\t
    • 2 <= path.length <= 100
    • \n\t
    • 1 <= value <= 109
    • \n
    \n", "content_cn": "

    \u4f60\u9700\u8981\u8bbe\u8ba1\u4e00\u4e2a\u80fd\u63d0\u4f9b\u4e0b\u9762\u4e24\u4e2a\u51fd\u6570\u7684\u6587\u4ef6\u7cfb\u7edf\uff1a

    \n\n
      \n\t
    • create(path, value): \u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u8def\u5f84\uff0c\u5e76\u5c3d\u53ef\u80fd\u5c06\u503c value \u4e0e\u8def\u5f84 path \u5173\u8054\uff0c\u7136\u540e\u8fd4\u56de True\u3002\u5982\u679c\u8def\u5f84\u5df2\u7ecf\u5b58\u5728\u6216\u8005\u8def\u5f84\u7684\u7236\u8def\u5f84\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de False\u3002
    • \n\t
    • get(path): \u8fd4\u56de\u4e0e\u8def\u5f84\u5173\u8054\u7684\u503c\u3002\u5982\u679c\u8def\u5f84\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de -1\u3002
    • \n
    \n\n

    “\u8def\u5f84” \u662f\u7531\u4e00\u4e2a\u6216\u591a\u4e2a\u7b26\u5408\u4e0b\u8ff0\u683c\u5f0f\u7684\u5b57\u7b26\u4e32\u8fde\u63a5\u8d77\u6765\u5f62\u6210\u7684\uff1a\u5728 / \u540e\u8ddf\u7740\u4e00\u4e2a\u6216\u591a\u4e2a\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002

    \n\n

    \u4f8b\u5982 /leetcode \u548c /leetcode/problems \u90fd\u662f\u6709\u6548\u7684\u8def\u5f84\uff0c\u4f46\u7a7a\u5b57\u7b26\u4e32\u548c / \u4e0d\u662f\u6709\u6548\u7684\u8def\u5f84\u3002

    \n\n

    \u597d\u4e86\uff0c\u63a5\u4e0b\u6765\u5c31\u8bf7\u4f60\u6765\u5b9e\u73b0\u8fd9\u4e24\u4e2a\u51fd\u6570\u5427\uff01\uff08\u8bf7\u53c2\u8003\u793a\u4f8b\u4ee5\u83b7\u5f97\u66f4\u591a\u4fe1\u606f\uff09

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a \n["FileSystem","create","get"]\n[[],["/a",1],["/a"]]\n\u8f93\u51fa\uff1a \n[null,true,1]\n\u89e3\u91ca\uff1a \nFileSystem fileSystem = new FileSystem();\n\nfileSystem.create("/a", 1); // \u8fd4\u56de true\nfileSystem.get("/a"); // \u8fd4\u56de 1\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a \n["FileSystem","create","create","get","create","get"]\n[[],["/leet",1],["/leet/code",2],["/leet/code"],["/c/d",1],["/c"]]\n\u8f93\u51fa\uff1a \n[null,true,true,2,false,-1]\n\u89e3\u91ca\uff1a\nFileSystem fileSystem = new FileSystem();\n\nfileSystem.create("/leet", 1); // \u8fd4\u56de true\nfileSystem.create("/leet/code", 2); // \u8fd4\u56de true\nfileSystem.get("/leet/code"); // \u8fd4\u56de 2\nfileSystem.create("/c/d", 1); // \u8fd4\u56de false \u56e0\u4e3a\u7236\u8def\u5f84 "/c" \u4e0d\u5b58\u5728\u3002\nfileSystem.get("/c"); // \u8fd4\u56de -1 \u56e0\u4e3a\u8be5\u8def\u5f84\u4e0d\u5b58\u5728\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u5bf9\u4e24\u4e2a\u51fd\u6570\u7684\u8c03\u7528\u6b21\u6570\u52a0\u8d77\u6765\u5c0f\u4e8e\u7b49\u4e8e 10^4
    • \n\t
    • 2 <= path.length <= 100
    • \n\t
    • 1 <= value <= 10^9
    • \n
    \n", "tags_en": ["Design", "Hash Table"], "tags_cn": ["\u8bbe\u8ba1", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class FileSystem {\npublic:\n FileSystem() {\n\n }\n \n bool createPath(string path, int value) {\n\n }\n \n int get(string path) {\n\n }\n};\n\n/**\n * Your FileSystem object will be instantiated and called as such:\n * FileSystem* obj = new FileSystem();\n * bool param_1 = obj->createPath(path,value);\n * int param_2 = obj->get(path);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class FileSystem {\n\n public FileSystem() {\n\n }\n \n public boolean createPath(String path, int value) {\n\n }\n \n public int get(String path) {\n\n }\n}\n\n/**\n * Your FileSystem object will be instantiated and called as such:\n * FileSystem obj = new FileSystem();\n * boolean param_1 = obj.createPath(path,value);\n * int param_2 = obj.get(path);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class FileSystem(object):\n\n def __init__(self):\n\n\n def createPath(self, path, value):\n \"\"\"\n :type path: str\n :type value: int\n :rtype: bool\n \"\"\"\n\n\n def get(self, path):\n \"\"\"\n :type path: str\n :rtype: int\n \"\"\"\n\n\n\n# Your FileSystem object will be instantiated and called as such:\n# obj = FileSystem()\n# param_1 = obj.createPath(path,value)\n# param_2 = obj.get(path)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class FileSystem:\n\n def __init__(self):\n\n\n def createPath(self, path: str, value: int) -> bool:\n\n\n def get(self, path: str) -> int:\n\n\n\n# Your FileSystem object will be instantiated and called as such:\n# obj = FileSystem()\n# param_1 = obj.createPath(path,value)\n# param_2 = obj.get(path)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} FileSystem;\n\n\nFileSystem* fileSystemCreate() {\n \n}\n\nbool fileSystemCreatePath(FileSystem* obj, char * path, int value) {\n \n}\n\nint fileSystemGet(FileSystem* obj, char * path) {\n \n}\n\nvoid fileSystemFree(FileSystem* obj) {\n \n}\n\n/**\n * Your FileSystem struct will be instantiated and called as such:\n * FileSystem* obj = fileSystemCreate();\n * bool param_1 = fileSystemCreatePath(obj, path, value);\n \n * int param_2 = fileSystemGet(obj, path);\n \n * fileSystemFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class FileSystem {\n\n public FileSystem() {\n\n }\n \n public bool CreatePath(string path, int value) {\n\n }\n \n public int Get(string path) {\n\n }\n}\n\n/**\n * Your FileSystem object will be instantiated and called as such:\n * FileSystem obj = new FileSystem();\n * bool param_1 = obj.CreatePath(path,value);\n * int param_2 = obj.Get(path);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "\nvar FileSystem = function() {\n\n};\n\n/** \n * @param {string} path \n * @param {number} value\n * @return {boolean}\n */\nFileSystem.prototype.createPath = function(path, value) {\n\n};\n\n/** \n * @param {string} path\n * @return {number}\n */\nFileSystem.prototype.get = function(path) {\n\n};\n\n/**\n * Your FileSystem object will be instantiated and called as such:\n * var obj = new FileSystem()\n * var param_1 = obj.createPath(path,value)\n * var param_2 = obj.get(path)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class FileSystem\n def initialize()\n\n end\n\n\n=begin\n :type path: String\n :type value: Integer\n :rtype: Boolean\n=end\n def create_path(path, value)\n\n end\n\n\n=begin\n :type path: String\n :rtype: Integer\n=end\n def get(path)\n\n end\n\n\nend\n\n# Your FileSystem object will be instantiated and called as such:\n# obj = FileSystem.new()\n# param_1 = obj.create_path(path, value)\n# param_2 = obj.get(path)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass FileSystem {\n\n init() {\n \n }\n \n func createPath(_ path: String, _ value: Int) -> Bool {\n \n }\n \n func get(_ path: String) -> Int {\n \n }\n}\n\n/**\n * Your FileSystem object will be instantiated and called as such:\n * let obj = FileSystem()\n * let ret_1: Bool = obj.createPath(path, value)\n * let ret_2: Int = obj.get(path)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type FileSystem struct {\n\n}\n\n\nfunc Constructor() FileSystem {\n\n}\n\n\nfunc (this *FileSystem) CreatePath(path string, value int) bool {\n\n}\n\n\nfunc (this *FileSystem) Get(path string) int {\n\n}\n\n\n/**\n * Your FileSystem object will be instantiated and called as such:\n * obj := Constructor();\n * param_1 := obj.CreatePath(path,value);\n * param_2 := obj.Get(path);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class FileSystem() {\n\n def createPath(path: String, value: Int): Boolean = {\n\n }\n\n def get(path: String): Int = {\n\n }\n\n}\n\n/**\n * Your FileSystem object will be instantiated and called as such:\n * var obj = new FileSystem()\n * var param_1 = obj.createPath(path,value)\n * var param_2 = obj.get(path)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class FileSystem() {\n\n fun createPath(path: String, value: Int): Boolean {\n\n }\n\n fun get(path: String): Int {\n\n }\n\n}\n\n/**\n * Your FileSystem object will be instantiated and called as such:\n * var obj = FileSystem()\n * var param_1 = obj.createPath(path,value)\n * var param_2 = obj.get(path)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct FileSystem {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl FileSystem {\n\n fn new() -> Self {\n\n }\n \n fn create_path(&self, path: String, value: i32) -> bool {\n\n }\n \n fn get(&self, path: String) -> i32 {\n\n }\n}\n\n/**\n * Your FileSystem object will be instantiated and called as such:\n * let obj = FileSystem::new();\n * let ret_1: bool = obj.create_path(path, value);\n * let ret_2: i32 = obj.get(path);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class FileSystem {\n /**\n */\n function __construct() {\n\n }\n\n /**\n * @param String $path\n * @param Integer $value\n * @return Boolean\n */\n function createPath($path, $value) {\n\n }\n\n /**\n * @param String $path\n * @return Integer\n */\n function get($path) {\n\n }\n}\n\n/**\n * Your FileSystem object will be instantiated and called as such:\n * $obj = FileSystem();\n * $ret_1 = $obj->createPath($path, $value);\n * $ret_2 = $obj->get($path);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class FileSystem {\n constructor() {\n\n }\n\n createPath(path: string, value: number): boolean {\n\n }\n\n get(path: string): number {\n\n }\n}\n\n/**\n * Your FileSystem object will be instantiated and called as such:\n * var obj = new FileSystem()\n * var param_1 = obj.createPath(path,value)\n * var param_2 = obj.get(path)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define file-system%\n (class object%\n (super-new)\n (init-field)\n \n ; create-path : string? exact-integer? -> boolean?\n (define/public (create-path path value)\n\n )\n ; get : string? -> exact-integer?\n (define/public (get path)\n\n )))\n\n;; Your file-system% object will be instantiated and called as such:\n;; (define obj (new file-system%))\n;; (define param_1 (send obj create-path path value))\n;; (define param_2 (send obj get path))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1166](https://leetcode-cn.com/problems/design-file-system)", "[\u8bbe\u8ba1\u6587\u4ef6\u7cfb\u7edf](/solution/1100-1199/1166.Design%20File%20System/README.md)", "`\u8bbe\u8ba1`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1166](https://leetcode.com/problems/design-file-system)", "[Design File System](/solution/1100-1199/1166.Design%20File%20System/README_EN.md)", "`Design`,`Hash Table`", "Medium", "\ud83d\udd12"]}, {"question_id": "1124", "frontend_question_id": "1153", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/string-transforms-into-another-string", "url_en": "https://leetcode.com/problems/string-transforms-into-another-string", "relative_path_cn": "/solution/1100-1199/1153.String%20Transforms%20Into%20Another%20String/README.md", "relative_path_en": "/solution/1100-1199/1153.String%20Transforms%20Into%20Another%20String/README_EN.md", "title_cn": "\u5b57\u7b26\u4e32\u8f6c\u5316", "title_en": "String Transforms Into Another String", "question_title_slug": "string-transforms-into-another-string", "content_en": "

    Given two strings str1 and str2 of the same length, determine whether you can transform str1 into str2 by doing zero or more conversions.

    \n\n

    In one conversion you can convert all occurrences of one character in str1 to any other lowercase English character.

    \n\n

    Return true if and only if you can transform str1 into str2.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: str1 = "aabcc", str2 = "ccdee"\nOutput: true\nExplanation: Convert 'c' to 'e' then 'b' to 'd' then 'a' to 'c'. Note that the order of conversions matter.\n
    \n\n

    Example 2:

    \n\n
    \nInput: str1 = "leetcode", str2 = "codeleet"\nOutput: false\nExplanation: There is no way to transform str1 to str2.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= str1.length == str2.length <= 104
    • \n\t
    • str1 and str2 contain only lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u51fa\u4e24\u4e2a\u957f\u5ea6\u76f8\u540c\u7684\u5b57\u7b26\u4e32\uff0c\u5206\u522b\u662f str1 \u548c str2\u3002\u8bf7\u4f60\u5e2e\u5fd9\u5224\u65ad\u5b57\u7b26\u4e32 str1 \u80fd\u4e0d\u80fd\u5728 \u96f6\u6b21 \u6216 \u591a\u6b21 \u8f6c\u5316\u540e\u53d8\u6210\u5b57\u7b26\u4e32 str2\u3002

    \n\n

    \u6bcf\u4e00\u6b21\u8f6c\u5316\u65f6\uff0c\u5c06\u4f1a\u4e00\u6b21\u6027\u5c06 str1 \u4e2d\u51fa\u73b0\u7684 \u6240\u6709 \u76f8\u540c\u5b57\u6bcd\u53d8\u6210\u5176\u4ed6 \u4efb\u4f55 \u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\uff08\u89c1\u793a\u4f8b\uff09\u3002

    \n\n

    \u53ea\u6709\u5728\u5b57\u7b26\u4e32 str1 \u80fd\u591f\u901a\u8fc7\u4e0a\u8ff0\u65b9\u5f0f\u987a\u5229\u8f6c\u5316\u4e3a\u5b57\u7b26\u4e32 str2 \u65f6\u624d\u80fd\u8fd4\u56de True\uff0c\u5426\u5219\u8fd4\u56de False\u3002\u200b\u200b

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1astr1 = "aabcc", str2 = "ccdee"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u5c06 'c' \u53d8\u6210 'e'\uff0c\u7136\u540e\u628a 'b' \u53d8\u6210 'd'\uff0c\u63a5\u7740\u518d\u628a 'a' \u53d8\u6210 'c'\u3002\u6ce8\u610f\uff0c\u8f6c\u5316\u7684\u987a\u5e8f\u4e5f\u5f88\u91cd\u8981\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1astr1 = "leetcode", str2 = "codeleet"\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u6211\u4eec\u6ca1\u6709\u529e\u6cd5\u80fd\u591f\u628a str1 \u8f6c\u5316\u4e3a str2\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= str1.length == str2.length <= 10^4
    2. \n\t
    3. str1 \u548c str2 \u4e2d\u90fd\u53ea\u4f1a\u51fa\u73b0 \u5c0f\u5199\u82f1\u6587\u5b57\u6bcd
    4. \n
    \n", "tags_en": ["Graph"], "tags_cn": ["\u56fe"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canConvert(string str1, string str2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canConvert(String str1, String str2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canConvert(self, str1, str2):\n \"\"\"\n :type str1: str\n :type str2: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canConvert(self, str1: str, str2: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canConvert(char * str1, char * str2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanConvert(string str1, string str2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} str1\n * @param {string} str2\n * @return {boolean}\n */\nvar canConvert = function(str1, str2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} str1\n# @param {String} str2\n# @return {Boolean}\ndef can_convert(str1, str2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canConvert(_ str1: String, _ str2: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canConvert(str1 string, str2 string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canConvert(str1: String, str2: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canConvert(str1: String, str2: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_convert(str1: String, str2: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $str1\n * @param String $str2\n * @return Boolean\n */\n function canConvert($str1, $str2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canConvert(str1: string, str2: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-convert str1 str2)\n (-> string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1153](https://leetcode-cn.com/problems/string-transforms-into-another-string)", "[\u5b57\u7b26\u4e32\u8f6c\u5316](/solution/1100-1199/1153.String%20Transforms%20Into%20Another%20String/README.md)", "`\u56fe`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1153](https://leetcode.com/problems/string-transforms-into-another-string)", "[String Transforms Into Another String](/solution/1100-1199/1153.String%20Transforms%20Into%20Another%20String/README_EN.md)", "`Graph`", "Hard", "\ud83d\udd12"]}, {"question_id": "1123", "frontend_question_id": "1165", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/single-row-keyboard", "url_en": "https://leetcode.com/problems/single-row-keyboard", "relative_path_cn": "/solution/1100-1199/1165.Single-Row%20Keyboard/README.md", "relative_path_en": "/solution/1100-1199/1165.Single-Row%20Keyboard/README_EN.md", "title_cn": "\u5355\u884c\u952e\u76d8", "title_en": "Single-Row Keyboard", "question_title_slug": "single-row-keyboard", "content_en": "

    There is a special keyboard with all keys in a single row.

    \n\n

    Given a string keyboard of length 26 indicating the layout of the keyboard (indexed from 0 to 25). Initially, your finger is at index 0. To type a character, you have to move your finger to the index of the desired character. The time taken to move your finger from index i to index j is |i - j|.

    \n\n

    You want to type a string word. Write a function to calculate how much time it takes to type it with one finger.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: keyboard = "abcdefghijklmnopqrstuvwxyz", word = "cba"\nOutput: 4\nExplanation: The index moves from 0 to 2 to write 'c' then to 1 to write 'b' then to 0 again to write 'a'.\nTotal time = 2 + 1 + 1 = 4. \n
    \n\n

    Example 2:

    \n\n
    \nInput: keyboard = "pqrstuvwxyzabcdefghijklmno", word = "leetcode"\nOutput: 73\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • keyboard.length == 26
    • \n\t
    • keyboard contains each English lowercase letter exactly once in some order.
    • \n\t
    • 1 <= word.length <= 104
    • \n\t
    • word[i] is an English lowercase letter.
    • \n
    \n", "content_cn": "

    \u6211\u4eec\u5b9a\u5236\u4e86\u4e00\u6b3e\u7279\u6b8a\u7684\u529b\u6263\u952e\u76d8\uff0c\u6240\u6709\u7684\u952e\u90fd\u6392\u5217\u5728\u4e00\u884c\u4e0a\u3002

    \n\n

    \u6211\u4eec\u53ef\u4ee5\u6309\u4ece\u5de6\u5230\u53f3\u7684\u987a\u5e8f\uff0c\u7528\u4e00\u4e2a\u957f\u5ea6\u4e3a 26 \u7684\u5b57\u7b26\u4e32 keyboard \uff08\u7d22\u5f15\u4ece 0 \u5f00\u59cb\uff0c\u5230 25 \u7ed3\u675f\uff09\u6765\u8868\u793a\u8be5\u952e\u76d8\u7684\u952e\u4f4d\u5e03\u5c40\u3002

    \n\n

    \u73b0\u5728\u9700\u8981\u6d4b\u8bd5\u8fd9\u4e2a\u952e\u76d8\u662f\u5426\u80fd\u591f\u6709\u6548\u5de5\u4f5c\uff0c\u90a3\u4e48\u6211\u4eec\u5c31\u9700\u8981\u4e2a\u673a\u68b0\u624b\u6765\u6d4b\u8bd5\u8fd9\u4e2a\u952e\u76d8\u3002

    \n\n

    \u6700\u521d\u7684\u65f6\u5019\uff0c\u673a\u68b0\u624b\u4f4d\u4e8e\u5de6\u8fb9\u8d77\u7b2c\u4e00\u4e2a\u952e\uff08\u4e5f\u5c31\u662f\u7d22\u5f15\u4e3a 0 \u7684\u952e\uff09\u7684\u4e0a\u65b9\u3002\u5f53\u673a\u68b0\u624b\u79fb\u52a8\u5230\u67d0\u4e00\u5b57\u7b26\u6240\u5728\u7684\u952e\u4f4d\u65f6\uff0c\u5c31\u4f1a\u5728\u7ec8\u7aef\u4e0a\u8f93\u51fa\u8be5\u5b57\u7b26\u3002

    \n\n

    \u673a\u68b0\u624b\u4ece\u7d22\u5f15 i \u79fb\u52a8\u5230\u7d22\u5f15 j \u6240\u9700\u8981\u7684\u65f6\u95f4\u662f |i - j|\u3002

    \n\n

    \u5f53\u524d\u6d4b\u8bd5\u9700\u8981\u4f60\u4f7f\u7528\u673a\u68b0\u624b\u8f93\u51fa\u6307\u5b9a\u7684\u5355\u8bcd word\uff0c\u8bf7\u4f60\u7f16\u5199\u4e00\u4e2a\u51fd\u6570\u6765\u8ba1\u7b97\u673a\u68b0\u624b\u8f93\u51fa\u8be5\u5355\u8bcd\u6240\u9700\u7684\u65f6\u95f4\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1akeyboard = "abcdefghijklmnopqrstuvwxyz", word = "cba"\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\n\u673a\u68b0\u624b\u4ece 0 \u53f7\u952e\u79fb\u52a8\u5230 2 \u53f7\u952e\u6765\u8f93\u51fa 'c'\uff0c\u53c8\u79fb\u52a8\u5230 1 \u53f7\u952e\u6765\u8f93\u51fa 'b'\uff0c\u63a5\u7740\u79fb\u52a8\u5230 0 \u53f7\u952e\u6765\u8f93\u51fa 'a'\u3002\n\u603b\u7528\u65f6 = 2 + 1 + 1 = 4. \n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1akeyboard = "pqrstuvwxyzabcdefghijklmno", word = "leetcode"\n\u8f93\u51fa\uff1a73\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • keyboard.length == 26
    • \n\t
    • keyboard \u6309\u67d0\u79cd\u7279\u5b9a\u987a\u5e8f\u6392\u5217\uff0c\u5e76\u5305\u542b\u6bcf\u4e2a\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u4e00\u6b21\u3002
    • \n\t
    • 1 <= word.length <= 10^4
    • \n\t
    • word[i] \u662f\u4e00\u4e2a\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int calculateTime(string keyboard, string word) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int calculateTime(String keyboard, String word) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def calculateTime(self, keyboard, word):\n \"\"\"\n :type keyboard: str\n :type word: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def calculateTime(self, keyboard: str, word: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint calculateTime(char * keyboard, char * word){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CalculateTime(string keyboard, string word) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} keyboard\n * @param {string} word\n * @return {number}\n */\nvar calculateTime = function(keyboard, word) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} keyboard\n# @param {String} word\n# @return {Integer}\ndef calculate_time(keyboard, word)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func calculateTime(_ keyboard: String, _ word: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func calculateTime(keyboard string, word string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def calculateTime(keyboard: String, word: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun calculateTime(keyboard: String, word: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn calculate_time(keyboard: String, word: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $keyboard\n * @param String $word\n * @return Integer\n */\n function calculateTime($keyboard, $word) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function calculateTime(keyboard: string, word: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (calculate-time keyboard word)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1165](https://leetcode-cn.com/problems/single-row-keyboard)", "[\u5355\u884c\u952e\u76d8](/solution/1100-1199/1165.Single-Row%20Keyboard/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1165](https://leetcode.com/problems/single-row-keyboard)", "[Single-Row Keyboard](/solution/1100-1199/1165.Single-Row%20Keyboard/README_EN.md)", "`String`", "Easy", "\ud83d\udd12"]}, {"question_id": "1122", "frontend_question_id": "1044", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-duplicate-substring", "url_en": "https://leetcode.com/problems/longest-duplicate-substring", "relative_path_cn": "/solution/1000-1099/1044.Longest%20Duplicate%20Substring/README.md", "relative_path_en": "/solution/1000-1099/1044.Longest%20Duplicate%20Substring/README_EN.md", "title_cn": "\u6700\u957f\u91cd\u590d\u5b50\u4e32", "title_en": "Longest Duplicate Substring", "question_title_slug": "longest-duplicate-substring", "content_en": "

    Given a string s, consider all duplicated substrings: (contiguous) substrings of s that occur 2 or more times. The occurrences may overlap.

    \n\n

    Return any duplicated substring that has the longest possible length. If s does not have a duplicated substring, the answer is "".

    \n\n

     

    \n

    Example 1:

    \n
    Input: s = \"banana\"\nOutput: \"ana\"\n

    Example 2:

    \n
    Input: s = \"abcd\"\nOutput: \"\"\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= s.length <= 3 * 104
    • \n\t
    • s consists of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u51fa\u4e00\u4e2a\u5b57\u7b26\u4e32 S\uff0c\u8003\u8651\u5176\u6240\u6709\u91cd\u590d\u5b50\u4e32\uff08S \u7684\u8fde\u7eed\u5b50\u4e32\uff0c\u51fa\u73b0\u4e24\u6b21\u6216\u591a\u6b21\uff0c\u53ef\u80fd\u4f1a\u6709\u91cd\u53e0\uff09\u3002

    \n\n

    \u8fd4\u56de\u4efb\u4f55\u5177\u6709\u6700\u957f\u53ef\u80fd\u957f\u5ea6\u7684\u91cd\u590d\u5b50\u4e32\u3002\uff08\u5982\u679c S \u4e0d\u542b\u91cd\u590d\u5b50\u4e32\uff0c\u90a3\u4e48\u7b54\u6848\u4e3a ""\u3002\uff09

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a"banana"\n\u8f93\u51fa\uff1a"ana"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a"abcd"\n\u8f93\u51fa\uff1a""\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 2 <= S.length <= 10^5
    2. \n\t
    3. S \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\u3002
    4. \n
    \n", "tags_en": ["Hash Table", "Binary Search"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string longestDupSubstring(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String longestDupSubstring(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestDupSubstring(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestDupSubstring(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * longestDupSubstring(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string LongestDupSubstring(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar longestDupSubstring = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef longest_dup_substring(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestDupSubstring(_ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestDupSubstring(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestDupSubstring(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestDupSubstring(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_dup_substring(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function longestDupSubstring($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestDupSubstring(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-dup-substring s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1044](https://leetcode-cn.com/problems/longest-duplicate-substring)", "[\u6700\u957f\u91cd\u590d\u5b50\u4e32](/solution/1000-1099/1044.Longest%20Duplicate%20Substring/README.md)", "`\u54c8\u5e0c\u8868`,`\u4e8c\u5206\u67e5\u627e`", "\u56f0\u96be", ""], "md_table_row_en": ["[1044](https://leetcode.com/problems/longest-duplicate-substring)", "[Longest Duplicate Substring](/solution/1000-1099/1044.Longest%20Duplicate%20Substring/README_EN.md)", "`Hash Table`,`Binary Search`", "Hard", ""]}, {"question_id": "1121", "frontend_question_id": "1043", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/partition-array-for-maximum-sum", "url_en": "https://leetcode.com/problems/partition-array-for-maximum-sum", "relative_path_cn": "/solution/1000-1099/1043.Partition%20Array%20for%20Maximum%20Sum/README.md", "relative_path_en": "/solution/1000-1099/1043.Partition%20Array%20for%20Maximum%20Sum/README_EN.md", "title_cn": "\u5206\u9694\u6570\u7ec4\u4ee5\u5f97\u5230\u6700\u5927\u548c", "title_en": "Partition Array for Maximum Sum", "question_title_slug": "partition-array-for-maximum-sum", "content_en": "

    Given an integer array arr, partition the array into (contiguous) subarrays of length at most k. After partitioning, each subarray has their values changed to become the maximum value of that subarray.

    \n\n

    Return the largest sum of the given array after partitioning. Test cases are generated so that the answer fits in a 32-bit integer.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr = [1,15,7,9,2,5,10], k = 3\nOutput: 84\nExplanation: arr becomes [15,15,15,9,10,10,10]\n
    \n\n

    Example 2:

    \n\n
    \nInput: arr = [1,4,1,5,7,3,6,1,9,9,3], k = 4\nOutput: 83\n
    \n\n

    Example 3:

    \n\n
    \nInput: arr = [1], k = 1\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= arr.length <= 500
    • \n\t
    • 0 <= arr[i] <= 109
    • \n\t
    • 1 <= k <= arr.length
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr\uff0c\u8bf7\u4f60\u5c06\u8be5\u6570\u7ec4\u5206\u9694\u4e3a\u957f\u5ea6\u6700\u591a\u4e3a k \u7684\u4e00\u4e9b\uff08\u8fde\u7eed\uff09\u5b50\u6570\u7ec4\u3002\u5206\u9694\u5b8c\u6210\u540e\uff0c\u6bcf\u4e2a\u5b50\u6570\u7ec4\u7684\u4e2d\u7684\u6240\u6709\u503c\u90fd\u4f1a\u53d8\u4e3a\u8be5\u5b50\u6570\u7ec4\u4e2d\u7684\u6700\u5927\u503c\u3002

    \n\n

    \u8fd4\u56de\u5c06\u6570\u7ec4\u5206\u9694\u53d8\u6362\u540e\u80fd\u591f\u5f97\u5230\u7684\u5143\u7d20\u6700\u5927\u548c\u3002

    \n\n

    \u00a0

    \n\n

    \u6ce8\u610f\uff0c\u539f\u6570\u7ec4\u548c\u5206\u9694\u540e\u7684\u6570\u7ec4\u5bf9\u5e94\u987a\u5e8f\u5e94\u5f53\u4e00\u81f4\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u4f60\u53ea\u80fd\u9009\u62e9\u5206\u9694\u6570\u7ec4\u7684\u4f4d\u7f6e\u800c\u4e0d\u80fd\u8c03\u6574\u6570\u7ec4\u4e2d\u7684\u987a\u5e8f\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [1,15,7,9,2,5,10], k = 3\n\u8f93\u51fa\uff1a84\n\u89e3\u91ca\uff1a\n\u56e0\u4e3a k=3 \u53ef\u4ee5\u5206\u9694\u6210 [1,15,7] [9] [2,5,10]\uff0c\u7ed3\u679c\u4e3a [15,15,15,9,10,10,10]\uff0c\u548c\u4e3a 84\uff0c\u662f\u8be5\u6570\u7ec4\u6240\u6709\u5206\u9694\u53d8\u6362\u540e\u5143\u7d20\u603b\u548c\u6700\u5927\u7684\u3002\n\u82e5\u662f\u5206\u9694\u6210 [1] [15,7,9] [2,5,10]\uff0c\u7ed3\u679c\u5c31\u662f [1, 15, 15, 15, 10, 10, 10] \u4f46\u8fd9\u79cd\u5206\u9694\u65b9\u5f0f\u7684\u5143\u7d20\u603b\u548c\uff0876\uff09\u5c0f\u4e8e\u4e0a\u4e00\u79cd\u3002 
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [1,4,1,5,7,3,6,1,9,9,3], k = 4\n\u8f93\u51fa\uff1a83\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [1], k = 1\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= arr.length <= 500
    • \n\t
    • 0 <= arr[i] <= 109
    • \n\t
    • 1 <= k <= arr.length
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxSumAfterPartitioning(vector& arr, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxSumAfterPartitioning(int[] arr, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxSumAfterPartitioning(self, arr, k):\n \"\"\"\n :type arr: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxSumAfterPartitioning(self, arr: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxSumAfterPartitioning(int* arr, int arrSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxSumAfterPartitioning(int[] arr, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @param {number} k\n * @return {number}\n */\nvar maxSumAfterPartitioning = function(arr, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @param {Integer} k\n# @return {Integer}\ndef max_sum_after_partitioning(arr, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxSumAfterPartitioning(_ arr: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxSumAfterPartitioning(arr []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxSumAfterPartitioning(arr: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxSumAfterPartitioning(arr: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_sum_after_partitioning(arr: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @param Integer $k\n * @return Integer\n */\n function maxSumAfterPartitioning($arr, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxSumAfterPartitioning(arr: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-sum-after-partitioning arr k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1043](https://leetcode-cn.com/problems/partition-array-for-maximum-sum)", "[\u5206\u9694\u6570\u7ec4\u4ee5\u5f97\u5230\u6700\u5927\u548c](/solution/1000-1099/1043.Partition%20Array%20for%20Maximum%20Sum/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1043](https://leetcode.com/problems/partition-array-for-maximum-sum)", "[Partition Array for Maximum Sum](/solution/1000-1099/1043.Partition%20Array%20for%20Maximum%20Sum/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "1120", "frontend_question_id": "1042", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/flower-planting-with-no-adjacent", "url_en": "https://leetcode.com/problems/flower-planting-with-no-adjacent", "relative_path_cn": "/solution/1000-1099/1042.Flower%20Planting%20With%20No%20Adjacent/README.md", "relative_path_en": "/solution/1000-1099/1042.Flower%20Planting%20With%20No%20Adjacent/README_EN.md", "title_cn": "\u4e0d\u90bb\u63a5\u690d\u82b1", "title_en": "Flower Planting With No Adjacent", "question_title_slug": "flower-planting-with-no-adjacent", "content_en": "

    You have n gardens, labeled from 1 to n, and an array paths where paths[i] = [xi, yi] describes a bidirectional path between garden xi to garden yi. In each garden, you want to plant one of 4 types of flowers.

    \n\n

    All gardens have at most 3 paths coming into or leaving it.

    \n\n

    Your task is to choose a flower type for each garden such that, for any two gardens connected by a path, they have different types of flowers.

    \n\n

    Return any such a choice as an array answer, where answer[i] is the type of flower planted in the (i+1)th garden. The flower types are denoted 1, 2, 3, or 4. It is guaranteed an answer exists.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 3, paths = [[1,2],[2,3],[3,1]]\nOutput: [1,2,3]\nExplanation:\nGardens 1 and 2 have different types.\nGardens 2 and 3 have different types.\nGardens 3 and 1 have different types.\nHence, [1,2,3] is a valid answer. Other valid answers include [1,2,4], [1,4,2], and [3,2,1].\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 4, paths = [[1,2],[3,4]]\nOutput: [1,2,1,2]\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 4, paths = [[1,2],[2,3],[3,4],[4,1],[1,3],[2,4]]\nOutput: [1,2,3,4]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 104
    • \n\t
    • 0 <= paths.length <= 2 * 104
    • \n\t
    • paths[i].length == 2
    • \n\t
    • 1 <= xi, yi <= n
    • \n\t
    • xi != yi
    • \n\t
    • Every garden has at most 3 paths coming into or leaving it.
    • \n
    \n", "content_cn": "

    \u6709 n \u4e2a\u82b1\u56ed\uff0c\u6309\u4ece\u00a01\u00a0\u5230 n \u6807\u8bb0\u3002\u53e6\u6709\u6570\u7ec4 paths \uff0c\u5176\u4e2d paths[i] = [xi, yi]\u00a0\u63cf\u8ff0\u4e86\u82b1\u56ed\u00a0xi \u5230\u82b1\u56ed\u00a0yi \u7684\u53cc\u5411\u8def\u5f84\u3002\u5728\u6bcf\u4e2a\u82b1\u56ed\u4e2d\uff0c\u4f60\u6253\u7b97\u79cd\u4e0b\u56db\u79cd\u82b1\u4e4b\u4e00\u3002

    \n\n

    \u53e6\u5916\uff0c\u6240\u6709\u82b1\u56ed \u6700\u591a \u6709 3 \u6761\u8def\u5f84\u53ef\u4ee5\u8fdb\u5165\u6216\u79bb\u5f00.

    \n\n

    \u4f60\u9700\u8981\u4e3a\u6bcf\u4e2a\u82b1\u56ed\u9009\u62e9\u4e00\u79cd\u82b1\uff0c\u4f7f\u5f97\u901a\u8fc7\u8def\u5f84\u76f8\u8fde\u7684\u4efb\u4f55\u4e24\u4e2a\u82b1\u56ed\u4e2d\u7684\u82b1\u7684\u79cd\u7c7b\u4e92\u4e0d\u76f8\u540c\u3002

    \n\n

    \u4ee5\u6570\u7ec4\u5f62\u5f0f\u8fd4\u56de \u4efb\u4e00 \u53ef\u884c\u7684\u65b9\u6848\u4f5c\u4e3a\u7b54\u6848\u00a0answer\uff0c\u5176\u4e2d\u00a0answer[i]\u00a0\u4e3a\u5728\u7b2c\u00a0(i+1)\u00a0\u4e2a\u82b1\u56ed\u4e2d\u79cd\u690d\u7684\u82b1\u7684\u79cd\u7c7b\u3002\u82b1\u7684\u79cd\u7c7b\u7528 \u00a01\u30012\u30013\u30014 \u8868\u793a\u3002\u4fdd\u8bc1\u5b58\u5728\u7b54\u6848\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 3, paths = [[1,2],[2,3],[3,1]]\n\u8f93\u51fa\uff1a[1,2,3]\n\u89e3\u91ca\uff1a\n\u82b1\u56ed 1 \u548c 2 \u82b1\u7684\u79cd\u7c7b\u4e0d\u540c\u3002\n\u82b1\u56ed 2 \u548c 3 \u82b1\u7684\u79cd\u7c7b\u4e0d\u540c\u3002\n\u82b1\u56ed 3 \u548c 1 \u82b1\u7684\u79cd\u7c7b\u4e0d\u540c\u3002\n\u56e0\u6b64\uff0c[1,2,3] \u662f\u4e00\u4e2a\u6ee1\u8db3\u9898\u610f\u7684\u7b54\u6848\u3002\u5176\u4ed6\u6ee1\u8db3\u9898\u610f\u7684\u7b54\u6848\u6709 [1,2,4]\u3001[1,4,2] \u548c [3,2,1]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 4, paths = [[1,2],[3,4]]\n\u8f93\u51fa\uff1a[1,2,1,2]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 4, paths = [[1,2],[2,3],[3,4],[4,1],[1,3],[2,4]]\n\u8f93\u51fa\uff1a[1,2,3,4]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 104
    • \n\t
    • 0 <= paths.length <= 2 * 104
    • \n\t
    • paths[i].length == 2
    • \n\t
    • 1 <= xi, yi <= n
    • \n\t
    • xi != yi
    • \n\t
    • \u6bcf\u4e2a\u82b1\u56ed \u6700\u591a \u6709 3 \u6761\u8def\u5f84\u53ef\u4ee5\u8fdb\u5165\u6216\u79bb\u5f00
    • \n
    \n", "tags_en": ["Graph"], "tags_cn": ["\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector gardenNoAdj(int n, vector>& paths) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] gardenNoAdj(int n, int[][] paths) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def gardenNoAdj(self, n, paths):\n \"\"\"\n :type n: int\n :type paths: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def gardenNoAdj(self, n: int, paths: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* gardenNoAdj(int n, int** paths, int pathsSize, int* pathsColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] GardenNoAdj(int n, int[][] paths) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} paths\n * @return {number[]}\n */\nvar gardenNoAdj = function(n, paths) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} paths\n# @return {Integer[]}\ndef garden_no_adj(n, paths)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func gardenNoAdj(_ n: Int, _ paths: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func gardenNoAdj(n int, paths [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def gardenNoAdj(n: Int, paths: Array[Array[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun gardenNoAdj(n: Int, paths: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn garden_no_adj(n: i32, paths: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $paths\n * @return Integer[]\n */\n function gardenNoAdj($n, $paths) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function gardenNoAdj(n: number, paths: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (garden-no-adj n paths)\n (-> exact-integer? (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1042](https://leetcode-cn.com/problems/flower-planting-with-no-adjacent)", "[\u4e0d\u90bb\u63a5\u690d\u82b1](/solution/1000-1099/1042.Flower%20Planting%20With%20No%20Adjacent/README.md)", "`\u56fe`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1042](https://leetcode.com/problems/flower-planting-with-no-adjacent)", "[Flower Planting With No Adjacent](/solution/1000-1099/1042.Flower%20Planting%20With%20No%20Adjacent/README_EN.md)", "`Graph`", "Medium", ""]}, {"question_id": "1119", "frontend_question_id": "1041", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/robot-bounded-in-circle", "url_en": "https://leetcode.com/problems/robot-bounded-in-circle", "relative_path_cn": "/solution/1000-1099/1041.Robot%20Bounded%20In%20Circle/README.md", "relative_path_en": "/solution/1000-1099/1041.Robot%20Bounded%20In%20Circle/README_EN.md", "title_cn": "\u56f0\u4e8e\u73af\u4e2d\u7684\u673a\u5668\u4eba", "title_en": "Robot Bounded In Circle", "question_title_slug": "robot-bounded-in-circle", "content_en": "

    On an infinite plane, a robot initially stands at (0, 0) and faces north. The robot can receive one of three instructions:

    \n\n
      \n\t
    • "G": go straight 1 unit;
    • \n\t
    • "L": turn 90 degrees to the left;
    • \n\t
    • "R": turn 90 degrees to the right.
    • \n
    \n\n

    The robot performs the instructions given in order, and repeats them forever.

    \n\n

    Return true if and only if there exists a circle in the plane such that the robot never leaves the circle.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: instructions = "GGLLGG"\nOutput: true\nExplanation: The robot moves from (0,0) to (0,2), turns 180 degrees, and then returns to (0,0).\nWhen repeating these instructions, the robot remains in the circle of radius 2 centered at the origin.
    \n\n

    Example 2:

    \n\n
    \nInput: instructions = "GG"\nOutput: false\nExplanation: The robot moves north indefinitely.
    \n\n

    Example 3:

    \n\n
    \nInput: instructions = "GL"\nOutput: true\nExplanation: The robot moves from (0, 0) -> (0, 1) -> (-1, 1) -> (-1, 0) -> (0, 0) -> ...
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= instructions.length <= 100
    • \n\t
    • instructions[i] is 'G', 'L' or, 'R'.
    • \n
    \n", "content_cn": "

    \u5728\u65e0\u9650\u7684\u5e73\u9762\u4e0a\uff0c\u673a\u5668\u4eba\u6700\u521d\u4f4d\u4e8e (0, 0) \u5904\uff0c\u9762\u671d\u5317\u65b9\u3002\u673a\u5668\u4eba\u53ef\u4ee5\u63a5\u53d7\u4e0b\u5217\u4e09\u6761\u6307\u4ee4\u4e4b\u4e00\uff1a

    \n\n
      \n\t
    • "G"\uff1a\u76f4\u8d70 1 \u4e2a\u5355\u4f4d
    • \n\t
    • "L"\uff1a\u5de6\u8f6c 90 \u5ea6
    • \n\t
    • "R"\uff1a\u53f3\u8f6c 90 \u5ea6
    • \n
    \n\n

    \u673a\u5668\u4eba\u6309\u987a\u5e8f\u6267\u884c\u6307\u4ee4 instructions\uff0c\u5e76\u4e00\u76f4\u91cd\u590d\u5b83\u4eec\u3002

    \n\n

    \u53ea\u6709\u5728\u5e73\u9762\u4e2d\u5b58\u5728\u73af\u4f7f\u5f97\u673a\u5668\u4eba\u6c38\u8fdc\u65e0\u6cd5\u79bb\u5f00\u65f6\uff0c\u8fd4\u56de true\u3002\u5426\u5219\uff0c\u8fd4\u56de false\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a"GGLLGG"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\n\u673a\u5668\u4eba\u4ece (0,0) \u79fb\u52a8\u5230 (0,2)\uff0c\u8f6c 180 \u5ea6\uff0c\u7136\u540e\u56de\u5230 (0,0)\u3002\n\u91cd\u590d\u8fd9\u4e9b\u6307\u4ee4\uff0c\u673a\u5668\u4eba\u5c06\u4fdd\u6301\u5728\u4ee5\u539f\u70b9\u4e3a\u4e2d\u5fc3\uff0c2 \u4e3a\u534a\u5f84\u7684\u73af\u4e2d\u8fdb\u884c\u79fb\u52a8\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a"GG"\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\n\u673a\u5668\u4eba\u65e0\u9650\u5411\u5317\u79fb\u52a8\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1a"GL"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\n\u673a\u5668\u4eba\u6309 (0, 0) -> (0, 1) -> (-1, 1) -> (-1, 0) -> (0, 0) -> ... \u8fdb\u884c\u79fb\u52a8\u3002
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= instructions.length <= 100
    2. \n\t
    3. instructions[i] \u5728 {'G', 'L', 'R'} \u4e2d
    4. \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isRobotBounded(string instructions) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isRobotBounded(String instructions) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isRobotBounded(self, instructions):\n \"\"\"\n :type instructions: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isRobotBounded(self, instructions: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isRobotBounded(char * instructions){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsRobotBounded(string instructions) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} instructions\n * @return {boolean}\n */\nvar isRobotBounded = function(instructions) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} instructions\n# @return {Boolean}\ndef is_robot_bounded(instructions)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isRobotBounded(_ instructions: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isRobotBounded(instructions string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isRobotBounded(instructions: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isRobotBounded(instructions: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_robot_bounded(instructions: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $instructions\n * @return Boolean\n */\n function isRobotBounded($instructions) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isRobotBounded(instructions: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-robot-bounded instructions)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1041](https://leetcode-cn.com/problems/robot-bounded-in-circle)", "[\u56f0\u4e8e\u73af\u4e2d\u7684\u673a\u5668\u4eba](/solution/1000-1099/1041.Robot%20Bounded%20In%20Circle/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1041](https://leetcode.com/problems/robot-bounded-in-circle)", "[Robot Bounded In Circle](/solution/1000-1099/1041.Robot%20Bounded%20In%20Circle/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "1118", "frontend_question_id": "1121", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/divide-array-into-increasing-sequences", "url_en": "https://leetcode.com/problems/divide-array-into-increasing-sequences", "relative_path_cn": "/solution/1100-1199/1121.Divide%20Array%20Into%20Increasing%20Sequences/README.md", "relative_path_en": "/solution/1100-1199/1121.Divide%20Array%20Into%20Increasing%20Sequences/README_EN.md", "title_cn": "\u5c06\u6570\u7ec4\u5206\u6210\u51e0\u4e2a\u9012\u589e\u5e8f\u5217", "title_en": "Divide Array Into Increasing Sequences", "question_title_slug": "divide-array-into-increasing-sequences", "content_en": "

    Given a non-decreasing array of positive integers nums and an integer k, find out if this array can be divided into one or more disjoint increasing subsequences of length at least k.

    \n\n

     

    \n\n

    Example 1:

    \n\n
    \nInput: nums = [1,2,2,3,3,4,4], k = 3\nOutput: true\nExplanation: \nThe array can be divided into the two subsequences [1,2,3,4] and [2,3,4] with lengths at least 3 each.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [5,6,6,7,8], k = 3\nOutput: false\nExplanation: \nThere is no way to divide the array using the conditions required.\n
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    1. 1 <= nums.length <= 105
    2. \n\t
    3. 1 <= k <= nums.length
    4. \n\t
    5. 1 <= nums[i] <= 105
    6. \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a \u975e\u9012\u51cf \u7684\u6b63\u6574\u6570\u6570\u7ec4 nums \u548c\u6574\u6570 K\uff0c\u5224\u65ad\u8be5\u6570\u7ec4\u662f\u5426\u53ef\u4ee5\u88ab\u5206\u6210\u4e00\u4e2a\u6216\u51e0\u4e2a \u957f\u5ea6\u81f3\u5c11 \u4e3a K \u7684 \u4e0d\u76f8\u4ea4\u7684\u9012\u589e\u5b50\u5e8f\u5217\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [1,2,2,3,3,4,4], K = 3\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\n\u8be5\u6570\u7ec4\u53ef\u4ee5\u5206\u6210\u4e24\u4e2a\u5b50\u5e8f\u5217 [1,2,3,4] \u548c [2,3,4]\uff0c\u6bcf\u4e2a\u5b50\u5e8f\u5217\u7684\u957f\u5ea6\u90fd\u81f3\u5c11\u662f 3\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [5,6,6,7,8], K = 3\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\n\u6ca1\u6709\u529e\u6cd5\u6839\u636e\u6761\u4ef6\u6765\u5212\u5206\u6570\u7ec4\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= nums.length <= 10^5
    2. \n\t
    3. 1 <= K <= nums.length
    4. \n\t
    5. 1 <= nums[i] <= 10^5
    6. \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canDivideIntoSubsequences(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canDivideIntoSubsequences(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canDivideIntoSubsequences(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canDivideIntoSubsequences(self, nums: List[int], k: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canDivideIntoSubsequences(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanDivideIntoSubsequences(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {boolean}\n */\nvar canDivideIntoSubsequences = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Boolean}\ndef can_divide_into_subsequences(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canDivideIntoSubsequences(_ nums: [Int], _ k: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canDivideIntoSubsequences(nums []int, k int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canDivideIntoSubsequences(nums: Array[Int], k: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canDivideIntoSubsequences(nums: IntArray, k: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_divide_into_subsequences(nums: Vec, k: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Boolean\n */\n function canDivideIntoSubsequences($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canDivideIntoSubsequences(nums: number[], k: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-divide-into-subsequences nums k)\n (-> (listof exact-integer?) exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1121](https://leetcode-cn.com/problems/divide-array-into-increasing-sequences)", "[\u5c06\u6570\u7ec4\u5206\u6210\u51e0\u4e2a\u9012\u589e\u5e8f\u5217](/solution/1100-1199/1121.Divide%20Array%20Into%20Increasing%20Sequences/README.md)", "`\u6570\u5b66`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1121](https://leetcode.com/problems/divide-array-into-increasing-sequences)", "[Divide Array Into Increasing Sequences](/solution/1100-1199/1121.Divide%20Array%20Into%20Increasing%20Sequences/README_EN.md)", "`Math`", "Hard", "\ud83d\udd12"]}, {"question_id": "1117", "frontend_question_id": "1162", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/as-far-from-land-as-possible", "url_en": "https://leetcode.com/problems/as-far-from-land-as-possible", "relative_path_cn": "/solution/1100-1199/1162.As%20Far%20from%20Land%20as%20Possible/README.md", "relative_path_en": "/solution/1100-1199/1162.As%20Far%20from%20Land%20as%20Possible/README_EN.md", "title_cn": "\u5730\u56fe\u5206\u6790", "title_en": "As Far from Land as Possible", "question_title_slug": "as-far-from-land-as-possible", "content_en": "

    Given an n x n grid containing only values 0 and 1, where 0 represents water and 1 represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or water exists in the grid, return -1.

    \n\n

    The distance used in this problem is the Manhattan distance: the distance between two cells (x0, y0) and (x1, y1) is |x0 - x1| + |y0 - y1|.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: grid = [[1,0,1],[0,0,0],[1,0,1]]\nOutput: 2\nExplanation: The cell (1, 1) is as far as possible from all the land with distance 2.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: grid = [[1,0,0],[0,0,0],[0,0,0]]\nOutput: 4\nExplanation: The cell (2, 2) is as far as possible from all the land with distance 4.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= n <= 100
    • \n\t
    • grid[i][j] is 0 or 1
    • \n
    \n", "content_cn": "

    \u4f60\u73b0\u5728\u624b\u91cc\u6709\u4e00\u4efd\u5927\u5c0f\u4e3a N x N \u7684 \u7f51\u683c grid\uff0c\u4e0a\u9762\u7684\u6bcf\u4e2a \u5355\u5143\u683c \u90fd\u7528 0 \u548c 1 \u6807\u8bb0\u597d\u4e86\u3002\u5176\u4e2d 0 \u4ee3\u8868\u6d77\u6d0b\uff0c1 \u4ee3\u8868\u9646\u5730\uff0c\u8bf7\u4f60\u627e\u51fa\u4e00\u4e2a\u6d77\u6d0b\u5355\u5143\u683c\uff0c\u8fd9\u4e2a\u6d77\u6d0b\u5355\u5143\u683c\u5230\u79bb\u5b83\u6700\u8fd1\u7684\u9646\u5730\u5355\u5143\u683c\u7684\u8ddd\u79bb\u662f\u6700\u5927\u7684\u3002

    \n\n

    \u6211\u4eec\u8fd9\u91cc\u8bf4\u7684\u8ddd\u79bb\u662f\u300c\u66fc\u54c8\u987f\u8ddd\u79bb\u300d\uff08 Manhattan Distance\uff09\uff1a(x0, y0) \u548c (x1, y1) \u8fd9\u4e24\u4e2a\u5355\u5143\u683c\u4e4b\u95f4\u7684\u8ddd\u79bb\u662f |x0 - x1| + |y0 - y1| \u3002

    \n\n

    \u5982\u679c\u7f51\u683c\u4e0a\u53ea\u6709\u9646\u5730\u6216\u8005\u6d77\u6d0b\uff0c\u8bf7\u8fd4\u56de -1\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1a[[1,0,1],[0,0,0],[1,0,1]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a \n\u6d77\u6d0b\u5355\u5143\u683c (1, 1) \u548c\u6240\u6709\u9646\u5730\u5355\u5143\u683c\u4e4b\u95f4\u7684\u8ddd\u79bb\u90fd\u8fbe\u5230\u6700\u5927\uff0c\u6700\u5927\u8ddd\u79bb\u4e3a 2\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1a[[1,0,0],[0,0,0],[0,0,0]]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a \n\u6d77\u6d0b\u5355\u5143\u683c (2, 2) \u548c\u6240\u6709\u9646\u5730\u5355\u5143\u683c\u4e4b\u95f4\u7684\u8ddd\u79bb\u90fd\u8fbe\u5230\u6700\u5927\uff0c\u6700\u5927\u8ddd\u79bb\u4e3a 4\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= grid.length == grid[0].length <= 100
    2. \n\t
    3. grid[i][j] \u4e0d\u662f 0 \u5c31\u662f 1
    4. \n
    \n", "tags_en": ["Breadth-first Search", "Graph"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxDistance(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxDistance(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxDistance(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxDistance(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxDistance(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxDistance(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar maxDistance = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef max_distance(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxDistance(_ grid: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxDistance(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxDistance(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxDistance(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_distance(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function maxDistance($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxDistance(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-distance grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1162](https://leetcode-cn.com/problems/as-far-from-land-as-possible)", "[\u5730\u56fe\u5206\u6790](/solution/1100-1199/1162.As%20Far%20from%20Land%20as%20Possible/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u56fe`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1162](https://leetcode.com/problems/as-far-from-land-as-possible)", "[As Far from Land as Possible](/solution/1100-1199/1162.As%20Far%20from%20Land%20as%20Possible/README_EN.md)", "`Breadth-first Search`,`Graph`", "Medium", ""]}, {"question_id": "1116", "frontend_question_id": "1161", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-level-sum-of-a-binary-tree", "url_en": "https://leetcode.com/problems/maximum-level-sum-of-a-binary-tree", "relative_path_cn": "/solution/1100-1199/1161.Maximum%20Level%20Sum%20of%20a%20Binary%20Tree/README.md", "relative_path_en": "/solution/1100-1199/1161.Maximum%20Level%20Sum%20of%20a%20Binary%20Tree/README_EN.md", "title_cn": "\u6700\u5927\u5c42\u5185\u5143\u7d20\u548c", "title_en": "Maximum Level Sum of a Binary Tree", "question_title_slug": "maximum-level-sum-of-a-binary-tree", "content_en": "

    Given the root of a binary tree, the level of its root is 1, the level of its children is 2, and so on.

    \n\n

    Return the smallest level x such that the sum of all the values of nodes at level x is maximal.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,7,0,7,-8,null,null]\nOutput: 2\nExplanation: \nLevel 1 sum = 1.\nLevel 2 sum = 7 + 0 = 7.\nLevel 3 sum = 7 + -8 = -1.\nSo we return the level with the maximum sum which is level 2.\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = [989,null,10250,98693,-89388,null,null,null,-32127]\nOutput: 2\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 104].
    • \n\t
    • -105 <= Node.val <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9 root\u3002\u8bbe\u6839\u8282\u70b9\u4f4d\u4e8e\u4e8c\u53c9\u6811\u7684\u7b2c 1 \u5c42\uff0c\u800c\u6839\u8282\u70b9\u7684\u5b50\u8282\u70b9\u4f4d\u4e8e\u7b2c 2 \u5c42\uff0c\u4f9d\u6b64\u7c7b\u63a8\u3002

    \n\n

    \u8bf7\u4f60\u627e\u51fa\u5c42\u5185\u5143\u7d20\u4e4b\u548c \u6700\u5927 \u7684\u90a3\u51e0\u5c42\uff08\u53ef\u80fd\u53ea\u6709\u4e00\u5c42\uff09\u7684\u5c42\u53f7\uff0c\u5e76\u8fd4\u56de\u5176\u4e2d \u6700\u5c0f \u7684\u90a3\u4e2a\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1aroot = [1,7,0,7,-8,null,null]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n\u7b2c 1 \u5c42\u5404\u5143\u7d20\u4e4b\u548c\u4e3a 1\uff0c\n\u7b2c 2 \u5c42\u5404\u5143\u7d20\u4e4b\u548c\u4e3a 7 + 0 = 7\uff0c\n\u7b2c 3 \u5c42\u5404\u5143\u7d20\u4e4b\u548c\u4e3a 7 + -8 = -1\uff0c\n\u6240\u4ee5\u6211\u4eec\u8fd4\u56de\u7b2c 2 \u5c42\u7684\u5c42\u53f7\uff0c\u5b83\u7684\u5c42\u5185\u5143\u7d20\u4e4b\u548c\u6700\u5927\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aroot = [989,null,10250,98693,-89388,null,null,null,-32127]\n\u8f93\u51fa\uff1a2\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u7684\u8282\u70b9\u6570\u4ecb\u4e8e 1 \u548c 10^4 \u4e4b\u95f4
    • \n\t
    • -10^5 <= node.val <= 10^5
    • \n
    \n", "tags_en": ["Tree", "Breadth-first Search"], "tags_cn": ["\u6811", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int maxLevelSum(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int maxLevelSum(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def maxLevelSum(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def maxLevelSum(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint maxLevelSum(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int MaxLevelSum(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar maxLevelSum = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef max_level_sum(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func maxLevelSum(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc maxLevelSum(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def maxLevelSum(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun maxLevelSum(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn max_level_sum(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function maxLevelSum($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction maxLevelSum(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (max-level-sum root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1161](https://leetcode-cn.com/problems/maximum-level-sum-of-a-binary-tree)", "[\u6700\u5927\u5c42\u5185\u5143\u7d20\u548c](/solution/1100-1199/1161.Maximum%20Level%20Sum%20of%20a%20Binary%20Tree/README.md)", "`\u6811`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1161](https://leetcode.com/problems/maximum-level-sum-of-a-binary-tree)", "[Maximum Level Sum of a Binary Tree](/solution/1100-1199/1161.Maximum%20Level%20Sum%20of%20a%20Binary%20Tree/README_EN.md)", "`Tree`,`Breadth-first Search`", "Medium", ""]}, {"question_id": "1115", "frontend_question_id": "1037", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/valid-boomerang", "url_en": "https://leetcode.com/problems/valid-boomerang", "relative_path_cn": "/solution/1000-1099/1037.Valid%20Boomerang/README.md", "relative_path_en": "/solution/1000-1099/1037.Valid%20Boomerang/README_EN.md", "title_cn": "\u6709\u6548\u7684\u56de\u65cb\u9556", "title_en": "Valid Boomerang", "question_title_slug": "valid-boomerang", "content_en": "

    Given an array points where points[i] = [xi, yi] represents a point on the X-Y plane, return true if these points are a boomerang.

    \n\n

    A boomerang is a set of three points that are all distinct and not in a straight line.

    \n\n

     

    \n

    Example 1:

    \n
    Input: points = [[1,1],[2,3],[3,2]]\nOutput: true\n

    Example 2:

    \n
    Input: points = [[1,1],[2,2],[3,3]]\nOutput: false\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • points.length == 3
    • \n\t
    • points[i].length == 2
    • \n\t
    • 0 <= xi, yi <= 100
    • \n
    \n", "content_cn": "

    \u56de\u65cb\u9556\u5b9a\u4e49\u4e3a\u4e00\u7ec4\u4e09\u4e2a\u70b9\uff0c\u8fd9\u4e9b\u70b9\u5404\u4e0d\u76f8\u540c\u4e14\u4e0d\u5728\u4e00\u6761\u76f4\u7ebf\u4e0a\u3002

    \n\n

    \u7ed9\u51fa\u5e73\u9762\u4e0a\u4e09\u4e2a\u70b9\u7ec4\u6210\u7684\u5217\u8868\uff0c\u5224\u65ad\u8fd9\u4e9b\u70b9\u662f\u5426\u53ef\u4ee5\u6784\u6210\u56de\u65cb\u9556\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a[[1,1],[2,3],[3,2]]\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a[[1,1],[2,2],[3,3]]\n\u8f93\u51fa\uff1afalse
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. points.length == 3
    2. \n\t
    3. points[i].length == 2
    4. \n\t
    5. 0 <= points[i][j] <= 100
    6. \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isBoomerang(vector>& points) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isBoomerang(int[][] points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isBoomerang(self, points):\n \"\"\"\n :type points: List[List[int]]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isBoomerang(self, points: List[List[int]]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isBoomerang(int** points, int pointsSize, int* pointsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsBoomerang(int[][] points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} points\n * @return {boolean}\n */\nvar isBoomerang = function(points) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} points\n# @return {Boolean}\ndef is_boomerang(points)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isBoomerang(_ points: [[Int]]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isBoomerang(points [][]int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isBoomerang(points: Array[Array[Int]]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isBoomerang(points: Array): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_boomerang(points: Vec>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $points\n * @return Boolean\n */\n function isBoomerang($points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isBoomerang(points: number[][]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-boomerang points)\n (-> (listof (listof exact-integer?)) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1037](https://leetcode-cn.com/problems/valid-boomerang)", "[\u6709\u6548\u7684\u56de\u65cb\u9556](/solution/1000-1099/1037.Valid%20Boomerang/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[1037](https://leetcode.com/problems/valid-boomerang)", "[Valid Boomerang](/solution/1000-1099/1037.Valid%20Boomerang/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "1114", "frontend_question_id": "1038", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/binary-search-tree-to-greater-sum-tree", "url_en": "https://leetcode.com/problems/binary-search-tree-to-greater-sum-tree", "relative_path_cn": "/solution/1000-1099/1038.Binary%20Search%20Tree%20to%20Greater%20Sum%20Tree/README.md", "relative_path_en": "/solution/1000-1099/1038.Binary%20Search%20Tree%20to%20Greater%20Sum%20Tree/README_EN.md", "title_cn": "\u628a\u4e8c\u53c9\u641c\u7d22\u6811\u8f6c\u6362\u4e3a\u7d2f\u52a0\u6811", "title_en": "Binary Search Tree to Greater Sum Tree", "question_title_slug": "binary-search-tree-to-greater-sum-tree", "content_en": "

    Given the root of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus sum of all keys greater than the original key in BST.

    \r\n\r\n

    As a reminder, a binary search tree is a tree that satisfies these constraints:

    \r\n\r\n
      \r\n\t
    • The left subtree of a node contains only nodes with keys less than the node's key.
    • \r\n\t
    • The right subtree of a node contains only nodes with keys greater than the node's key.
    • \r\n\t
    • Both the left and right subtrees must also be binary search trees.
    • \r\n
    \r\n\r\n

    Note: This question is the same as 538: https://leetcode.com/problems/convert-bst-to-greater-tree/

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\"\"\r\n
    \r\nInput: root = [4,1,6,0,2,5,7,null,null,null,3,null,null,null,8]\r\nOutput: [30,36,21,36,35,26,15,null,null,null,33,null,null,null,8]\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: root = [0,null,1]\r\nOutput: [1,null,1]\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: root = [1,0,2]\r\nOutput: [3,3,2]\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: root = [3,2,4,1]\r\nOutput: [7,9,4,10]\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • The number of nodes in the tree is in the range [1, 100].
    • \r\n\t
    • 0 <= Node.val <= 100
    • \r\n\t
    • All the values in the tree are unique.
    • \r\n\t
    • root is guaranteed to be a valid binary search tree.
    • \r\n
    ", "content_cn": "

    \u7ed9\u51fa\u4e8c\u53c9 \u641c\u7d22 \u6811\u7684\u6839\u8282\u70b9\uff0c\u8be5\u6811\u7684\u8282\u70b9\u503c\u5404\u4e0d\u76f8\u540c\uff0c\u8bf7\u4f60\u5c06\u5176\u8f6c\u6362\u4e3a\u7d2f\u52a0\u6811\uff08Greater Sum Tree\uff09\uff0c\u4f7f\u6bcf\u4e2a\u8282\u70b9 node \u7684\u65b0\u503c\u7b49\u4e8e\u539f\u6811\u4e2d\u5927\u4e8e\u6216\u7b49\u4e8e node.val \u7684\u503c\u4e4b\u548c\u3002

    \n\n

    \u63d0\u9192\u4e00\u4e0b\uff0c\u4e8c\u53c9\u641c\u7d22\u6811\u6ee1\u8db3\u4e0b\u5217\u7ea6\u675f\u6761\u4ef6\uff1a

    \n\n
      \n\t
    • \u8282\u70b9\u7684\u5de6\u5b50\u6811\u4ec5\u5305\u542b\u952e \u5c0f\u4e8e \u8282\u70b9\u952e\u7684\u8282\u70b9\u3002
    • \n\t
    • \u8282\u70b9\u7684\u53f3\u5b50\u6811\u4ec5\u5305\u542b\u952e \u5927\u4e8e \u8282\u70b9\u952e\u7684\u8282\u70b9\u3002
    • \n\t
    • \u5de6\u53f3\u5b50\u6811\u4e5f\u5fc5\u987b\u662f\u4e8c\u53c9\u641c\u7d22\u6811\u3002
    • \n
    \n\n

    \u6ce8\u610f\uff1a\u8be5\u9898\u76ee\u4e0e 538: https://leetcode-cn.com/problems/convert-bst-to-greater-tree/  \u76f8\u540c

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1a[4,1,6,0,2,5,7,null,null,null,3,null,null,null,8]\n\u8f93\u51fa\uff1a[30,36,21,36,35,26,15,null,null,null,33,null,null,null,8]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aroot = [0,null,1]\n\u8f93\u51fa\uff1a[1,null,1]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aroot = [1,0,2]\n\u8f93\u51fa\uff1a[3,3,2]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1aroot = [3,2,4,1]\n\u8f93\u51fa\uff1a[7,9,4,10]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u7684\u8282\u70b9\u6570\u4ecb\u4e8e 1 \u548c 100 \u4e4b\u95f4\u3002
    • \n\t
    • \u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u4ecb\u4e8e 0 \u548c 100 \u4e4b\u95f4\u3002
    • \n\t
    • \u6811\u4e2d\u7684\u6240\u6709\u503c \u4e92\u4e0d\u76f8\u540c \u3002
    • \n\t
    • \u7ed9\u5b9a\u7684\u6811\u4e3a\u4e8c\u53c9\u641c\u7d22\u6811\u3002
    • \n
    \n", "tags_en": ["Tree", "Depth-first Search", "Binary Search Tree", "Recursion"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u4e8c\u53c9\u641c\u7d22\u6811", "\u9012\u5f52"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* bstToGst(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode bstToGst(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def bstToGst(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: TreeNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def bstToGst(self, root: TreeNode) -> TreeNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* bstToGst(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode BstToGst(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {TreeNode}\n */\nvar bstToGst = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {TreeNode}\ndef bst_to_gst(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func bstToGst(_ root: TreeNode?) -> TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc bstToGst(root *TreeNode) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def bstToGst(root: TreeNode): TreeNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun bstToGst(root: TreeNode?): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn bst_to_gst(root: Option>>) -> Option>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return TreeNode\n */\n function bstToGst($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction bstToGst(root: TreeNode | null): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (bst-to-gst root)\n (-> (or/c tree-node? #f) (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1038](https://leetcode-cn.com/problems/binary-search-tree-to-greater-sum-tree)", "[\u628a\u4e8c\u53c9\u641c\u7d22\u6811\u8f6c\u6362\u4e3a\u7d2f\u52a0\u6811](/solution/1000-1099/1038.Binary%20Search%20Tree%20to%20Greater%20Sum%20Tree/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u4e8c\u53c9\u641c\u7d22\u6811`,`\u9012\u5f52`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1038](https://leetcode.com/problems/binary-search-tree-to-greater-sum-tree)", "[Binary Search Tree to Greater Sum Tree](/solution/1000-1099/1038.Binary%20Search%20Tree%20to%20Greater%20Sum%20Tree/README_EN.md)", "`Tree`,`Depth-first Search`,`Binary Search Tree`,`Recursion`", "Medium", ""]}, {"question_id": "1113", "frontend_question_id": "1040", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/moving-stones-until-consecutive-ii", "url_en": "https://leetcode.com/problems/moving-stones-until-consecutive-ii", "relative_path_cn": "/solution/1000-1099/1040.Moving%20Stones%20Until%20Consecutive%20II/README.md", "relative_path_en": "/solution/1000-1099/1040.Moving%20Stones%20Until%20Consecutive%20II/README_EN.md", "title_cn": "\u79fb\u52a8\u77f3\u5b50\u76f4\u5230\u8fde\u7eed II", "title_en": "Moving Stones Until Consecutive II", "question_title_slug": "moving-stones-until-consecutive-ii", "content_en": "

    On an infinite number line, the position of the i-th stone is given by stones[i].  Call a stone an endpoint stone if it has the smallest or largest position.

    \r\n\r\n

    Each turn, you pick up an endpoint stone and move it to an unoccupied position so that it is no longer an endpoint stone.

    \r\n\r\n

    In particular, if the stones are at say, stones = [1,2,5], you cannot move the endpoint stone at position 5, since moving it to any position (such as 0, or 3) will still keep that stone as an endpoint stone.

    \r\n\r\n

    The game ends when you cannot make any more moves, ie. the stones are in consecutive positions.

    \r\n\r\n

    When the game ends, what is the minimum and maximum number of moves that you could have made?  Return the answer as an length 2 array: answer = [minimum_moves, maximum_moves]

    \r\n\r\n

     

    \r\n\r\n

    Example 1:

    \r\n\r\n
    \r\nInput: [7,4,9]\r\nOutput: [1,2]\r\nExplanation: \r\nWe can move 4 -> 8 for one move to finish the game.\r\nOr, we can move 9 -> 5, 4 -> 6 for two moves to finish the game.\r\n
    \r\n\r\n
    \r\n

    Example 2:

    \r\n\r\n
    \r\nInput: [6,5,4,3,10]\r\nOutput: [2,3]\r\nWe can move 3 -> 8 then 10 -> 7 to finish the game.\r\nOr, we can move 3 -> 7, 4 -> 8, 5 -> 9 to finish the game.\r\nNotice we cannot move 10 -> 2 to finish the game, because that would be an illegal move.\r\n
    \r\n\r\n
    \r\n

    Example 3:

    \r\n\r\n
    \r\nInput: [100,101,104,102,103]\r\nOutput: [0,0]
    \r\n\r\n

     

    \r\n
    \r\n
    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    1. 3 <= stones.length <= 10^4
    2. \r\n\t
    3. 1 <= stones[i] <= 10^9
    4. \r\n\t
    5. stones[i] have distinct values.
    6. \r\n
    \r\n\r\n
    \r\n
    \r\n
     
    \r\n
    \r\n
    \r\n", "content_cn": "

    \u5728\u4e00\u4e2a\u957f\u5ea6 \u65e0\u9650 \u7684\u6570\u8f74\u4e0a\uff0c\u7b2c i \u9897\u77f3\u5b50\u7684\u4f4d\u7f6e\u4e3a\u00a0stones[i]\u3002\u5982\u679c\u4e00\u9897\u77f3\u5b50\u7684\u4f4d\u7f6e\u6700\u5c0f/\u6700\u5927\uff0c\u90a3\u4e48\u8be5\u77f3\u5b50\u88ab\u79f0\u4f5c \u7aef\u70b9\u77f3\u5b50 \u3002

    \n\n

    \u6bcf\u4e2a\u56de\u5408\uff0c\u4f60\u53ef\u4ee5\u5c06\u4e00\u9897\u7aef\u70b9\u77f3\u5b50\u62ff\u8d77\u5e76\u79fb\u52a8\u5230\u4e00\u4e2a\u672a\u5360\u7528\u7684\u4f4d\u7f6e\uff0c\u4f7f\u5f97\u8be5\u77f3\u5b50\u4e0d\u518d\u662f\u4e00\u9897\u7aef\u70b9\u77f3\u5b50\u3002

    \n\n

    \u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0c\u5982\u679c\u77f3\u5b50\u50cf\u00a0stones = [1,2,5]\u00a0\u8fd9\u6837\uff0c\u4f60\u5c06 \u65e0\u6cd5 \u79fb\u52a8\u4f4d\u4e8e\u4f4d\u7f6e 5 \u7684\u7aef\u70b9\u77f3\u5b50\uff0c\u56e0\u4e3a\u65e0\u8bba\u5c06\u5b83\u79fb\u52a8\u5230\u4efb\u4f55\u4f4d\u7f6e\uff08\u4f8b\u5982 0 \u6216 3\uff09\uff0c\u8be5\u77f3\u5b50\u90fd\u4ecd\u7136\u4f1a\u662f\u7aef\u70b9\u77f3\u5b50\u3002

    \n\n

    \u5f53\u4f60\u65e0\u6cd5\u8fdb\u884c\u4efb\u4f55\u79fb\u52a8\u65f6\uff0c\u5373\uff0c\u8fd9\u4e9b\u77f3\u5b50\u7684\u4f4d\u7f6e\u8fde\u7eed\u65f6\uff0c\u6e38\u620f\u7ed3\u675f\u3002

    \n\n

    \u8981\u4f7f\u6e38\u620f\u7ed3\u675f\uff0c\u4f60\u53ef\u4ee5\u6267\u884c\u7684\u6700\u5c0f\u548c\u6700\u5927\u79fb\u52a8\u6b21\u6570\u5206\u522b\u662f\u591a\u5c11\uff1f \u4ee5\u957f\u5ea6\u4e3a 2 \u7684\u6570\u7ec4\u5f62\u5f0f\u8fd4\u56de\u7b54\u6848\uff1aanswer = [minimum_moves, maximum_moves] \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[7,4,9]\n\u8f93\u51fa\uff1a[1,2]\n\u89e3\u91ca\uff1a\n\u6211\u4eec\u53ef\u4ee5\u79fb\u52a8\u4e00\u6b21\uff0c4 -> 8\uff0c\u6e38\u620f\u7ed3\u675f\u3002\n\u6216\u8005\uff0c\u6211\u4eec\u53ef\u4ee5\u79fb\u52a8\u4e24\u6b21 9 -> 5\uff0c4 -> 6\uff0c\u6e38\u620f\u7ed3\u675f\u3002\n
    \n\n

    \u793a\u4f8b\u00a02\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[6,5,4,3,10]\n\u8f93\u51fa\uff1a[2,3]\n\u89e3\u91ca\uff1a\n\u6211\u4eec\u53ef\u4ee5\u79fb\u52a8 3 -> 8\uff0c\u63a5\u7740\u662f 10 -> 7\uff0c\u6e38\u620f\u7ed3\u675f\u3002\n\u6216\u8005\uff0c\u6211\u4eec\u53ef\u4ee5\u79fb\u52a8 3 -> 7, 4 -> 8, 5 -> 9\uff0c\u6e38\u620f\u7ed3\u675f\u3002\n\u6ce8\u610f\uff0c\u6211\u4eec\u65e0\u6cd5\u8fdb\u884c 10 -> 2 \u8fd9\u6837\u7684\u79fb\u52a8\u6765\u7ed3\u675f\u6e38\u620f\uff0c\u56e0\u4e3a\u8fd9\u662f\u4e0d\u5408\u8981\u6c42\u7684\u79fb\u52a8\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[100,101,104,102,103]\n\u8f93\u51fa\uff1a[0,0]
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 3 <= stones.length <= 10^4
    • \n\t
    • 1 <= stones[i] <= 10^9
    • \n\t
    • stones[i]\u00a0\u7684\u503c\u5404\u4e0d\u76f8\u540c\u3002
    • \n
    \n\n

    \u00a0

    \n", "tags_en": ["Array", "Sliding Window"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector numMovesStonesII(vector& stones) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] numMovesStonesII(int[] stones) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numMovesStonesII(self, stones):\n \"\"\"\n :type stones: List[int]\n :rtype: List[int]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numMovesStonesII(self, stones: List[int]) -> List[int]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* numMovesStonesII(int* stones, int stonesSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] NumMovesStonesII(int[] stones) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} stones\n * @return {number[]}\n */\nvar numMovesStonesII = function(stones) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} stones\n# @return {Integer[]}\ndef num_moves_stones_ii(stones)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numMovesStonesII(_ stones: [Int]) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numMovesStonesII(stones []int) []int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numMovesStonesII(stones: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numMovesStonesII(stones: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_moves_stones_ii(stones: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $stones\n * @return Integer[]\n */\n function numMovesStonesII($stones) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numMovesStonesII(stones: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-moves-stones-ii stones)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1040](https://leetcode-cn.com/problems/moving-stones-until-consecutive-ii)", "[\u79fb\u52a8\u77f3\u5b50\u76f4\u5230\u8fde\u7eed II](/solution/1000-1099/1040.Moving%20Stones%20Until%20Consecutive%20II/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1040](https://leetcode.com/problems/moving-stones-until-consecutive-ii)", "[Moving Stones Until Consecutive II](/solution/1000-1099/1040.Moving%20Stones%20Until%20Consecutive%20II/README_EN.md)", "`Array`,`Sliding Window`", "Medium", ""]}, {"question_id": "1112", "frontend_question_id": "1160", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-words-that-can-be-formed-by-characters", "url_en": "https://leetcode.com/problems/find-words-that-can-be-formed-by-characters", "relative_path_cn": "/solution/1100-1199/1160.Find%20Words%20That%20Can%20Be%20Formed%20by%20Characters/README.md", "relative_path_en": "/solution/1100-1199/1160.Find%20Words%20That%20Can%20Be%20Formed%20by%20Characters/README_EN.md", "title_cn": "\u62fc\u5199\u5355\u8bcd", "title_en": "Find Words That Can Be Formed by Characters", "question_title_slug": "find-words-that-can-be-formed-by-characters", "content_en": "

    You are given an array of strings words and a string chars.

    \r\n\r\n

    A string is good if it can be formed by characters from chars (each character can only be used once).

    \r\n\r\n

    Return the sum of lengths of all good strings in words.

    \r\n\r\n

     

    \r\n\r\n

    Example 1:

    \r\n\r\n
    \r\nInput: words = ["cat","bt","hat","tree"], chars = "atach"\r\nOutput: 6\r\nExplanation: \r\nThe strings that can be formed are "cat" and "hat" so the answer is 3 + 3 = 6.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: words = ["hello","world","leetcode"], chars = "welldonehoneyr"\r\nOutput: 10\r\nExplanation: \r\nThe strings that can be formed are "hello" and "world" so the answer is 5 + 5 = 10.\r\n
    \r\n\r\n

     

    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    1. 1 <= words.length <= 1000
    2. \r\n\t
    3. 1 <= words[i].length, chars.length <= 100
    4. \r\n\t
    5. All strings contain lowercase English letters only.
    6. \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4efd\u300e\u8bcd\u6c47\u8868\u300f\uff08\u5b57\u7b26\u4e32\u6570\u7ec4\uff09 words \u548c\u4e00\u5f20\u300e\u5b57\u6bcd\u8868\u300f\uff08\u5b57\u7b26\u4e32\uff09 chars\u3002

    \n\n

    \u5047\u5982\u4f60\u53ef\u4ee5\u7528 chars \u4e2d\u7684\u300e\u5b57\u6bcd\u300f\uff08\u5b57\u7b26\uff09\u62fc\u5199\u51fa words \u4e2d\u7684\u67d0\u4e2a\u300e\u5355\u8bcd\u300f\uff08\u5b57\u7b26\u4e32\uff09\uff0c\u90a3\u4e48\u6211\u4eec\u5c31\u8ba4\u4e3a\u4f60\u638c\u63e1\u4e86\u8fd9\u4e2a\u5355\u8bcd\u3002

    \n\n

    \u6ce8\u610f\uff1a\u6bcf\u6b21\u62fc\u5199\uff08\u6307\u62fc\u5199\u8bcd\u6c47\u8868\u4e2d\u7684\u4e00\u4e2a\u5355\u8bcd\uff09\u65f6\uff0cchars \u4e2d\u7684\u6bcf\u4e2a\u5b57\u6bcd\u90fd\u53ea\u80fd\u7528\u4e00\u6b21\u3002

    \n\n

    \u8fd4\u56de\u8bcd\u6c47\u8868 words \u4e2d\u4f60\u638c\u63e1\u7684\u6240\u6709\u5355\u8bcd\u7684 \u957f\u5ea6\u4e4b\u548c\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1awords = ["cat","bt","hat","tree"], chars = "atach"\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a \n\u53ef\u4ee5\u5f62\u6210\u5b57\u7b26\u4e32 "cat" \u548c "hat"\uff0c\u6240\u4ee5\u7b54\u6848\u662f 3 + 3 = 6\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1awords = ["hello","world","leetcode"], chars = "welldonehoneyr"\n\u8f93\u51fa\uff1a10\n\u89e3\u91ca\uff1a\n\u53ef\u4ee5\u5f62\u6210\u5b57\u7b26\u4e32 "hello" \u548c "world"\uff0c\u6240\u4ee5\u7b54\u6848\u662f 5 + 5 = 10\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= words.length <= 1000
    2. \n\t
    3. 1 <= words[i].length, chars.length <= 100
    4. \n\t
    5. \u6240\u6709\u5b57\u7b26\u4e32\u4e2d\u90fd\u4ec5\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd
    6. \n
    \n", "tags_en": ["Array", "Hash Table"], "tags_cn": ["\u6570\u7ec4", "\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countCharacters(vector& words, string chars) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countCharacters(String[] words, String chars) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countCharacters(self, words, chars):\n \"\"\"\n :type words: List[str]\n :type chars: str\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countCharacters(self, words: List[str], chars: str) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countCharacters(char ** words, int wordsSize, char * chars){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountCharacters(string[] words, string chars) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @param {string} chars\n * @return {number}\n */\nvar countCharacters = function(words, chars) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @param {String} chars\n# @return {Integer}\ndef count_characters(words, chars)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countCharacters(_ words: [String], _ chars: String) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countCharacters(words []string, chars string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countCharacters(words: Array[String], chars: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countCharacters(words: Array, chars: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_characters(words: Vec, chars: String) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @param String $chars\n * @return Integer\n */\n function countCharacters($words, $chars) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countCharacters(words: string[], chars: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-characters words chars)\n (-> (listof string?) string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1160](https://leetcode-cn.com/problems/find-words-that-can-be-formed-by-characters)", "[\u62fc\u5199\u5355\u8bcd](/solution/1100-1199/1160.Find%20Words%20That%20Can%20Be%20Formed%20by%20Characters/README.md)", "`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[1160](https://leetcode.com/problems/find-words-that-can-be-formed-by-characters)", "[Find Words That Can Be Formed by Characters](/solution/1100-1199/1160.Find%20Words%20That%20Can%20Be%20Formed%20by%20Characters/README_EN.md)", "`Array`,`Hash Table`", "Easy", ""]}, {"question_id": "1111", "frontend_question_id": "1039", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-score-triangulation-of-polygon", "url_en": "https://leetcode.com/problems/minimum-score-triangulation-of-polygon", "relative_path_cn": "/solution/1000-1099/1039.Minimum%20Score%20Triangulation%20of%20Polygon/README.md", "relative_path_en": "/solution/1000-1099/1039.Minimum%20Score%20Triangulation%20of%20Polygon/README_EN.md", "title_cn": "\u591a\u8fb9\u5f62\u4e09\u89d2\u5256\u5206\u7684\u6700\u4f4e\u5f97\u5206", "title_en": "Minimum Score Triangulation of Polygon", "question_title_slug": "minimum-score-triangulation-of-polygon", "content_en": "

    You have a convex n-sided polygon where each vertex has an integer value. You are given an integer array values where values[i] is the value of the ith vertex (i.e., clockwise order).

    \n\n

    You will triangulate the polygon into n - 2 triangles. For each triangle, the value of that triangle is the product of the values of its vertices, and the total score of the triangulation is the sum of these values over all n - 2 triangles in the triangulation.

    \n\n

    Return the smallest possible total score that you can achieve with some triangulation of the polygon.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: values = [1,2,3]\nOutput: 6\nExplanation: The polygon is already triangulated, and the score of the only triangle is 6.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: values = [3,7,4,5]\nOutput: 144\nExplanation: There are two triangulations, with possible scores: 3*7*5 + 4*5*7 = 245, or 3*4*5 + 3*4*7 = 144.\nThe minimum score is 144.\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: values = [1,3,1,4,1,5]\nOutput: 13\nExplanation: The minimum score triangulation has score 1*1*3 + 1*1*4 + 1*1*5 + 1*1*1 = 13.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == values.length
    • \n\t
    • 3 <= n <= 50
    • \n\t
    • 1 <= values[i] <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a N\uff0c\u60f3\u8c61\u4e00\u4e2a\u51f8 N \u8fb9\u591a\u8fb9\u5f62\uff0c\u5176\u9876\u70b9\u6309\u987a\u65f6\u9488\u987a\u5e8f\u4f9d\u6b21\u6807\u8bb0\u4e3a A[0], A[i], ..., A[N-1]\u3002

    \n\n

    \u5047\u8bbe\u60a8\u5c06\u591a\u8fb9\u5f62\u5256\u5206\u4e3a N-2 \u4e2a\u4e09\u89d2\u5f62\u3002\u5bf9\u4e8e\u6bcf\u4e2a\u4e09\u89d2\u5f62\uff0c\u8be5\u4e09\u89d2\u5f62\u7684\u503c\u662f\u9876\u70b9\u6807\u8bb0\u7684\u4e58\u79ef\uff0c\u4e09\u89d2\u5256\u5206\u7684\u5206\u6570\u662f\u8fdb\u884c\u4e09\u89d2\u5256\u5206\u540e\u6240\u6709 N-2 \u4e2a\u4e09\u89d2\u5f62\u7684\u503c\u4e4b\u548c\u3002

    \n\n

    \u8fd4\u56de\u591a\u8fb9\u5f62\u8fdb\u884c\u4e09\u89d2\u5256\u5206\u540e\u53ef\u4ee5\u5f97\u5230\u7684\u6700\u4f4e\u5206\u3002
    \n 

    \n\n
      \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a[1,2,3]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u591a\u8fb9\u5f62\u5df2\u7ecf\u4e09\u89d2\u5316\uff0c\u552f\u4e00\u4e09\u89d2\u5f62\u7684\u5206\u6570\u4e3a 6\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1a[3,7,4,5]\n\u8f93\u51fa\uff1a144\n\u89e3\u91ca\uff1a\u6709\u4e24\u79cd\u4e09\u89d2\u5256\u5206\uff0c\u53ef\u80fd\u5f97\u5206\u5206\u522b\u4e3a\uff1a3*7*5 + 4*5*7 = 245\uff0c\u6216 3*4*5 + 3*4*7 = 144\u3002\u6700\u4f4e\u5206\u6570\u4e3a 144\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1a[1,3,1,4,1,5]\n\u8f93\u51fa\uff1a13\n\u89e3\u91ca\uff1a\u6700\u4f4e\u5206\u6570\u4e09\u89d2\u5256\u5206\u7684\u5f97\u5206\u60c5\u51b5\u4e3a 1*1*3 + 1*1*4 + 1*1*5 + 1*1*1 = 13\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 3 <= A.length <= 50
    2. \n\t
    3. 1 <= A[i] <= 100
    4. \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minScoreTriangulation(vector& values) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minScoreTriangulation(int[] values) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minScoreTriangulation(self, values):\n \"\"\"\n :type values: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minScoreTriangulation(self, values: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minScoreTriangulation(int* values, int valuesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinScoreTriangulation(int[] values) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} values\n * @return {number}\n */\nvar minScoreTriangulation = function(values) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} values\n# @return {Integer}\ndef min_score_triangulation(values)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minScoreTriangulation(_ values: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minScoreTriangulation(values []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minScoreTriangulation(values: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minScoreTriangulation(values: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_score_triangulation(values: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $values\n * @return Integer\n */\n function minScoreTriangulation($values) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minScoreTriangulation(values: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-score-triangulation values)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1039](https://leetcode-cn.com/problems/minimum-score-triangulation-of-polygon)", "[\u591a\u8fb9\u5f62\u4e09\u89d2\u5256\u5206\u7684\u6700\u4f4e\u5f97\u5206](/solution/1000-1099/1039.Minimum%20Score%20Triangulation%20of%20Polygon/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1039](https://leetcode.com/problems/minimum-score-triangulation-of-polygon)", "[Minimum Score Triangulation of Polygon](/solution/1000-1099/1039.Minimum%20Score%20Triangulation%20of%20Polygon/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "1108", "frontend_question_id": "1152", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/analyze-user-website-visit-pattern", "url_en": "https://leetcode.com/problems/analyze-user-website-visit-pattern", "relative_path_cn": "/solution/1100-1199/1152.Analyze%20User%20Website%20Visit%20Pattern/README.md", "relative_path_en": "/solution/1100-1199/1152.Analyze%20User%20Website%20Visit%20Pattern/README_EN.md", "title_cn": "\u7528\u6237\u7f51\u7ad9\u8bbf\u95ee\u884c\u4e3a\u5206\u6790", "title_en": "Analyze User Website Visit Pattern", "question_title_slug": "analyze-user-website-visit-pattern", "content_en": "

    We are given some website visits: the user with name username[i] visited the website website[i] at time timestamp[i].

    \n\n

    A 3-sequence is a list of websites of length 3 sorted in ascending order by the time of their visits.  (The websites in a 3-sequence are not necessarily distinct.)

    \n\n

    Find the 3-sequence visited by the largest number of users. If there is more than one solution, return the lexicographically smallest such 3-sequence.

    \n\n

     

    \n\n

    Example 1:

    \n\n
    \nInput: username = ["joe","joe","joe","james","james","james","james","mary","mary","mary"], timestamp = [1,2,3,4,5,6,7,8,9,10], website = ["home","about","career","home","cart","maps","home","home","about","career"]\nOutput: ["home","about","career"]\nExplanation: \nThe tuples in this example are:\n["joe", 1, "home"]\n["joe", 2, "about"]\n["joe", 3, "career"]\n["james", 4, "home"]\n["james", 5, "cart"]\n["james", 6, "maps"]\n["james", 7, "home"]\n["mary", 8, "home"]\n["mary", 9, "about"]\n["mary", 10, "career"]\nThe 3-sequence ("home", "about", "career") was visited at least once by 2 users.\nThe 3-sequence ("home", "cart", "maps") was visited at least once by 1 user.\nThe 3-sequence ("home", "cart", "home") was visited at least once by 1 user.\nThe 3-sequence ("home", "maps", "home") was visited at least once by 1 user.\nThe 3-sequence ("cart", "maps", "home") was visited at least once by 1 user.\n
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    1. 3 <= N = username.length = timestamp.length = website.length <= 50
    2. \n\t
    3. 1 <= username[i].length <= 10
    4. \n\t
    5. 0 <= timestamp[i] <= 10^9
    6. \n\t
    7. 1 <= website[i].length <= 10
    8. \n\t
    9. Both username[i] and website[i] contain only lowercase characters.
    10. \n\t
    11. It is guaranteed that there is at least one user who visited at least 3 websites.
    12. \n\t
    13. No user visits two websites at the same time.
    14. \n
    \n", "content_cn": "

    \u4e3a\u4e86\u8bc4\u4f30\u67d0\u7f51\u7ad9\u7684\u7528\u6237\u8f6c\u5316\u7387\uff0c\u6211\u4eec\u9700\u8981\u5bf9\u7528\u6237\u7684\u8bbf\u95ee\u884c\u4e3a\u8fdb\u884c\u5206\u6790\uff0c\u5e76\u5efa\u7acb\u7528\u6237\u884c\u4e3a\u6a21\u578b\u3002\u65e5\u5fd7\u6587\u4ef6\u4e2d\u5df2\u7ecf\u8bb0\u5f55\u4e86\u7528\u6237\u540d\u3001\u8bbf\u95ee\u65f6\u95f4 \u4ee5\u53ca \u9875\u9762\u8def\u5f84\u3002

    \n\n

    \u4e3a\u4e86\u65b9\u4fbf\u5206\u6790\uff0c\u65e5\u5fd7\u6587\u4ef6\u4e2d\u7684 N \u6761\u8bb0\u5f55\u5df2\u7ecf\u88ab\u89e3\u6790\u6210\u4e09\u4e2a\u957f\u5ea6\u76f8\u540c\u4e14\u957f\u5ea6\u90fd\u4e3a N \u7684\u6570\u7ec4\uff0c\u5206\u522b\u662f\uff1a\u7528\u6237\u540d username\uff0c\u8bbf\u95ee\u65f6\u95f4 timestamp \u548c \u9875\u9762\u8def\u5f84 website\u3002\u7b2c i \u6761\u8bb0\u5f55\u610f\u5473\u7740\u7528\u6237\u540d\u662f username[i] \u7684\u7528\u6237\u5728 timestamp[i] \u7684\u65f6\u5019\u8bbf\u95ee\u4e86\u8def\u5f84\u4e3a website[i] \u7684\u9875\u9762\u3002

    \n\n

    \u6211\u4eec\u9700\u8981\u627e\u5230\u7528\u6237\u8bbf\u95ee\u7f51\u7ad9\u65f6\u7684 \u300e\u5171\u6027\u884c\u4e3a\u8def\u5f84\u300f\uff0c\u4e5f\u5c31\u662f\u6709\u6700\u591a\u7684\u7528\u6237\u90fd \u81f3\u5c11\u6309\u67d0\u79cd\u6b21\u5e8f\u8bbf\u95ee\u8fc7\u4e00\u6b21 \u7684\u4e09\u4e2a\u9875\u9762\u8def\u5f84\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u7528\u6237 \u53ef\u80fd\u4e0d\u662f\u8fde\u7eed\u8bbf\u95ee \u8fd9\u4e09\u4e2a\u8def\u5f84\u7684\u3002

    \n\n

    \u300e\u5171\u6027\u884c\u4e3a\u8def\u5f84\u300f\u662f\u4e00\u4e2a \u957f\u5ea6\u4e3a 3 \u7684\u9875\u9762\u8def\u5f84\u5217\u8868\uff0c\u5217\u8868\u4e2d\u7684\u8def\u5f84 \u4e0d\u5fc5\u4e0d\u540c\uff0c\u5e76\u4e14\u6309\u7167\u8bbf\u95ee\u65f6\u95f4\u7684\u5148\u540e\u5347\u5e8f\u6392\u5217\u3002

    \n\n

    \u5982\u679c\u6709\u591a\u4e2a\u6ee1\u8db3\u8981\u6c42\u7684\u7b54\u6848\uff0c\u90a3\u4e48\u5c31\u8bf7\u8fd4\u56de\u6309\u5b57\u5178\u5e8f\u6392\u5217\u6700\u5c0f\u7684\u90a3\u4e2a\u3002\uff08\u9875\u9762\u8def\u5f84\u5217\u8868 X \u6309\u5b57\u5178\u5e8f\u5c0f\u4e8e Y \u7684\u524d\u63d0\u6761\u4ef6\u662f\uff1aX[0] < Y[0] \u6216 X[0] == Y[0] \u4e14 (X[1] < Y[1] \u6216 X[1] == Y[1] \u4e14 X[2] < Y[2])\uff09

    \n\n

    \u9898\u76ee\u4fdd\u8bc1\u4e00\u4e2a\u7528\u6237\u4f1a\u81f3\u5c11\u8bbf\u95ee 3 \u4e2a\u8def\u5f84\u4e00\u81f4\u7684\u9875\u9762\uff0c\u5e76\u4e14\u4e00\u4e2a\u7528\u6237\u4e0d\u4f1a\u5728\u540c\u4e00\u65f6\u95f4\u8bbf\u95ee\u4e24\u4e2a\u8def\u5f84\u4e0d\u540c\u7684\u9875\u9762\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1ausername = ["joe","joe","joe","james","james","james","james","mary","mary","mary"], timestamp = [1,2,3,4,5,6,7,8,9,10], website = ["home","about","career","home","cart","maps","home","home","about","career"]\n\u8f93\u51fa\uff1a["home","about","career"]\n\u89e3\u91ca\uff1a\n\u7531\u793a\u4f8b\u8f93\u5165\u5f97\u5230\u7684\u8bb0\u5f55\u5982\u4e0b\uff1a\n["joe", 1, "home"]\n["joe", 2, "about"]\n["joe", 3, "career"]\n["james", 4, "home"]\n["james", 5, "cart"]\n["james", 6, "maps"]\n["james", 7, "home"]\n["mary", 8, "home"]\n["mary", 9, "about"]\n["mary", 10, "career"]\n\u6709 2 \u4e2a\u7528\u6237\u81f3\u5c11\u8bbf\u95ee\u8fc7\u4e00\u6b21 ("home", "about", "career")\u3002\n\u6709 1 \u4e2a\u7528\u6237\u81f3\u5c11\u8bbf\u95ee\u8fc7\u4e00\u6b21 ("home", "cart", "maps")\u3002\n\u6709 1 \u4e2a\u7528\u6237\u81f3\u5c11\u8bbf\u95ee\u8fc7\u4e00\u6b21 ("home", "cart", "home")\u3002\n\u6709 1 \u4e2a\u7528\u6237\u81f3\u5c11\u8bbf\u95ee\u8fc7\u4e00\u6b21 ("home", "maps", "home")\u3002\n\u6709 1 \u4e2a\u7528\u6237\u81f3\u5c11\u8bbf\u95ee\u8fc7\u4e00\u6b21 ("cart", "maps", "home")\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 3 <= N = username.length = timestamp.length = website.length <= 50
    2. \n\t
    3. 1 <= username[i].length <= 10
    4. \n\t
    5. 0 <= timestamp[i] <= 10^9
    6. \n\t
    7. 1 <= website[i].length <= 10
    8. \n\t
    9. username[i] \u548c website[i] \u90fd\u53ea\u542b\u5c0f\u5199\u5b57\u7b26
    10. \n
    \n", "tags_en": ["Sort", "Array", "Hash Table"], "tags_cn": ["\u6392\u5e8f", "\u6570\u7ec4", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector mostVisitedPattern(vector& username, vector& timestamp, vector& website) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List mostVisitedPattern(String[] username, int[] timestamp, String[] website) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def mostVisitedPattern(self, username, timestamp, website):\n \"\"\"\n :type username: List[str]\n :type timestamp: List[int]\n :type website: List[str]\n :rtype: List[str]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def mostVisitedPattern(self, username: List[str], timestamp: List[int], website: List[str]) -> List[str]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** mostVisitedPattern(char ** username, int usernameSize, int* timestamp, int timestampSize, char ** website, int websiteSize, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList MostVisitedPattern(string[] username, int[] timestamp, string[] website) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} username\n * @param {number[]} timestamp\n * @param {string[]} website\n * @return {string[]}\n */\nvar mostVisitedPattern = function(username, timestamp, website) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} username\n# @param {Integer[]} timestamp\n# @param {String[]} website\n# @return {String[]}\ndef most_visited_pattern(username, timestamp, website)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func mostVisitedPattern(_ username: [String], _ timestamp: [Int], _ website: [String]) -> [String] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func mostVisitedPattern(username []string, timestamp []int, website []string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def mostVisitedPattern(username: Array[String], timestamp: Array[Int], website: Array[String]): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun mostVisitedPattern(username: Array, timestamp: IntArray, website: Array): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn most_visited_pattern(username: Vec, timestamp: Vec, website: Vec) -> Vec {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $username\n * @param Integer[] $timestamp\n * @param String[] $website\n * @return String[]\n */\n function mostVisitedPattern($username, $timestamp, $website) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function mostVisitedPattern(username: string[], timestamp: number[], website: string[]): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (most-visited-pattern username timestamp website)\n (-> (listof string?) (listof exact-integer?) (listof string?) (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1152](https://leetcode-cn.com/problems/analyze-user-website-visit-pattern)", "[\u7528\u6237\u7f51\u7ad9\u8bbf\u95ee\u884c\u4e3a\u5206\u6790](/solution/1100-1199/1152.Analyze%20User%20Website%20Visit%20Pattern/README.md)", "`\u6392\u5e8f`,`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1152](https://leetcode.com/problems/analyze-user-website-visit-pattern)", "[Analyze User Website Visit Pattern](/solution/1100-1199/1152.Analyze%20User%20Website%20Visit%20Pattern/README_EN.md)", "`Sort`,`Array`,`Hash Table`", "Medium", "\ud83d\udd12"]}, {"question_id": "1107", "frontend_question_id": "1151", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/minimum-swaps-to-group-all-1s-together", "url_en": "https://leetcode.com/problems/minimum-swaps-to-group-all-1s-together", "relative_path_cn": "/solution/1100-1199/1151.Minimum%20Swaps%20to%20Group%20All%201%27s%20Together/README.md", "relative_path_en": "/solution/1100-1199/1151.Minimum%20Swaps%20to%20Group%20All%201%27s%20Together/README_EN.md", "title_cn": "\u6700\u5c11\u4ea4\u6362\u6b21\u6570\u6765\u7ec4\u5408\u6240\u6709\u7684 1", "title_en": "Minimum Swaps to Group All 1's Together", "question_title_slug": "minimum-swaps-to-group-all-1s-together", "content_en": "

    Given a binary array data, return the minimum number of swaps required to group all 1’s present in the array together in any place in the array.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: data = [1,0,1,0,1]\nOutput: 1\nExplanation: \nThere are 3 ways to group all 1's together:\n[1,1,1,0,0] using 1 swap.\n[0,1,1,1,0] using 2 swaps.\n[0,0,1,1,1] using 1 swap.\nThe minimum is 1.\n
    \n\n

    Example 2:

    \n\n
    \nInput: data = [0,0,0,1,0]\nOutput: 0\nExplanation: \nSince there is only one 1 in the array, no swaps needed.\n
    \n\n

    Example 3:

    \n\n
    \nInput: data = [1,0,1,0,1,0,0,1,1,0,1]\nOutput: 3\nExplanation: \nOne possible solution that uses 3 swaps is [0,0,0,0,0,1,1,1,1,1,1].\n
    \n\n

    Example 4:

    \n\n
    \nInput: data = [1,0,1,0,1,0,1,1,1,0,1,0,0,1,1,1,0,0,1,1,1,0,1,0,1,1,0,0,0,1,1,1,1,0,0,1]\nOutput: 8\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= data.length <= 105
    • \n\t
    • data[i] is 0 or 1.
    • \n
    \n", "content_cn": "

    \u7ed9\u51fa\u4e00\u4e2a\u4e8c\u8fdb\u5236\u6570\u7ec4 data\uff0c\u4f60\u9700\u8981\u901a\u8fc7\u4ea4\u6362\u4f4d\u7f6e\uff0c\u5c06\u6570\u7ec4\u4e2d \u4efb\u4f55\u4f4d\u7f6e \u4e0a\u7684 1 \u7ec4\u5408\u5230\u4e00\u8d77\uff0c\u5e76\u8fd4\u56de\u6240\u6709\u53ef\u80fd\u4e2d\u6240\u9700 \u6700\u5c11\u7684\u4ea4\u6362\u6b21\u6570\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a[1,0,1,0,1]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a \n\u6709\u4e09\u79cd\u53ef\u80fd\u7684\u65b9\u6cd5\u53ef\u4ee5\u628a\u6240\u6709\u7684 1 \u7ec4\u5408\u5728\u4e00\u8d77\uff1a\n[1,1,1,0,0]\uff0c\u4ea4\u6362 1 \u6b21\uff1b\n[0,1,1,1,0]\uff0c\u4ea4\u6362 2 \u6b21\uff1b\n[0,0,1,1,1]\uff0c\u4ea4\u6362 1 \u6b21\u3002\n\u6240\u4ee5\u6700\u5c11\u7684\u4ea4\u6362\u6b21\u6570\u4e3a 1\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a[0,0,0,1,0]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a \n\u7531\u4e8e\u6570\u7ec4\u4e2d\u53ea\u6709\u4e00\u4e2a 1\uff0c\u6240\u4ee5\u4e0d\u9700\u8981\u4ea4\u6362\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1a[1,0,1,0,1,0,0,1,1,0,1]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\n\u4ea4\u6362 3 \u6b21\uff0c\u4e00\u79cd\u53ef\u884c\u7684\u53ea\u7528 3 \u6b21\u4ea4\u6362\u7684\u89e3\u51b3\u65b9\u6848\u662f [0,0,0,0,0,1,1,1,1,1,1]\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= data.length <= 10^5
    2. \n\t
    3. 0 <= data[i] <= 1
    4. \n
    \n", "tags_en": ["Array", "Sliding Window"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minSwaps(vector& data) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minSwaps(int[] data) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minSwaps(self, data):\n \"\"\"\n :type data: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minSwaps(self, data: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minSwaps(int* data, int dataSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinSwaps(int[] data) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} data\n * @return {number}\n */\nvar minSwaps = function(data) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} data\n# @return {Integer}\ndef min_swaps(data)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minSwaps(_ data: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minSwaps(data []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minSwaps(data: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minSwaps(data: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_swaps(data: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $data\n * @return Integer\n */\n function minSwaps($data) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minSwaps(data: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-swaps data)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1151](https://leetcode-cn.com/problems/minimum-swaps-to-group-all-1s-together)", "[\u6700\u5c11\u4ea4\u6362\u6b21\u6570\u6765\u7ec4\u5408\u6240\u6709\u7684 1](/solution/1100-1199/1151.Minimum%20Swaps%20to%20Group%20All%201%27s%20Together/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1151](https://leetcode.com/problems/minimum-swaps-to-group-all-1s-together)", "[Minimum Swaps to Group All 1's Together](/solution/1100-1199/1151.Minimum%20Swaps%20to%20Group%20All%201%27s%20Together/README_EN.md)", "`Array`,`Sliding Window`", "Medium", "\ud83d\udd12"]}, {"question_id": "1106", "frontend_question_id": "1036", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/escape-a-large-maze", "url_en": "https://leetcode.com/problems/escape-a-large-maze", "relative_path_cn": "/solution/1000-1099/1036.Escape%20a%20Large%20Maze/README.md", "relative_path_en": "/solution/1000-1099/1036.Escape%20a%20Large%20Maze/README_EN.md", "title_cn": "\u9003\u79bb\u5927\u8ff7\u5bab", "title_en": "Escape a Large Maze", "question_title_slug": "escape-a-large-maze", "content_en": "

    There is a 1 million by 1 million grid on an XY-plane, and the coordinates of each grid square are (x, y).

    \n\n

    We start at the source = [sx, sy] square and want to reach the target = [tx, ty] square. There is also an array of blocked squares, where each blocked[i] = [xi, yi] represents a blocked square with coordinates (xi, yi).

    \n\n

    Each move, we can walk one square north, east, south, or west if the square is not in the array of blocked squares. We are also not allowed to walk outside of the grid.

    \n\n

    Return true if and only if it is possible to reach the target square from the source square through a sequence of valid moves.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: blocked = [[0,1],[1,0]], source = [0,0], target = [0,2]\nOutput: false\nExplanation: The target square is inaccessible starting from the source square because we cannot move.\nWe cannot move north or east because those squares are blocked.\nWe cannot move south or west because we cannot go outside of the grid.\n
    \n\n

    Example 2:

    \n\n
    \nInput: blocked = [], source = [0,0], target = [999999,999999]\nOutput: true\nExplanation: Because there are no blocked cells, it is possible to reach the target square.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= blocked.length <= 200
    • \n\t
    • blocked[i].length == 2
    • \n\t
    • 0 <= xi, yi < 106
    • \n\t
    • source.length == target.length == 2
    • \n\t
    • 0 <= sx, sy, tx, ty < 106
    • \n\t
    • source != target
    • \n\t
    • It is guaranteed that source and target are not blocked.
    • \n
    \n", "content_cn": "

    \u5728\u4e00\u4e2a 106 x 106 \u7684\u7f51\u683c\u4e2d\uff0c\u6bcf\u4e2a\u7f51\u683c\u4e0a\u65b9\u683c\u7684\u5750\u6807\u4e3a\u00a0(x, y) \u3002

    \n\n

    \u73b0\u5728\u4ece\u6e90\u65b9\u683c\u00a0source = [sx, sy]\u00a0\u5f00\u59cb\u51fa\u53d1\uff0c\u610f\u56fe\u8d76\u5f80\u76ee\u6807\u65b9\u683c\u00a0target = [tx, ty] \u3002\u6570\u7ec4 blocked \u662f\u5c01\u9501\u7684\u65b9\u683c\u5217\u8868\uff0c\u5176\u4e2d\u6bcf\u4e2a blocked[i] = [xi, yi] \u8868\u793a\u5750\u6807\u4e3a (xi, yi) \u7684\u65b9\u683c\u662f\u7981\u6b62\u901a\u884c\u7684\u3002

    \n\n

    \u6bcf\u6b21\u79fb\u52a8\uff0c\u90fd\u53ef\u4ee5\u8d70\u5230\u7f51\u683c\u4e2d\u5728\u56db\u4e2a\u65b9\u5411\u4e0a\u76f8\u90bb\u7684\u65b9\u683c\uff0c\u53ea\u8981\u8be5\u65b9\u683c \u4e0d \u5728\u7ed9\u51fa\u7684\u5c01\u9501\u5217\u8868\u00a0blocked\u00a0\u4e0a\u3002\u540c\u65f6\uff0c\u4e0d\u5141\u8bb8\u8d70\u51fa\u7f51\u683c\u3002

    \n\n

    \u53ea\u6709\u5728\u53ef\u4ee5\u901a\u8fc7\u4e00\u7cfb\u5217\u7684\u79fb\u52a8\u4ece\u6e90\u65b9\u683c\u00a0source \u5230\u8fbe\u76ee\u6807\u65b9\u683c\u00a0target \u65f6\u624d\u8fd4\u56de\u00a0true\u3002\u5426\u5219\uff0c\u8fd4\u56de false\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1ablocked = [[0,1],[1,0]], source = [0,0], target = [0,2]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\n\u4ece\u6e90\u65b9\u683c\u65e0\u6cd5\u5230\u8fbe\u76ee\u6807\u65b9\u683c\uff0c\u56e0\u4e3a\u6211\u4eec\u65e0\u6cd5\u5728\u7f51\u683c\u4e2d\u79fb\u52a8\u3002\n\u65e0\u6cd5\u5411\u5317\u6216\u8005\u5411\u4e1c\u79fb\u52a8\u662f\u56e0\u4e3a\u65b9\u683c\u7981\u6b62\u901a\u884c\u3002\n\u65e0\u6cd5\u5411\u5357\u6216\u8005\u5411\u897f\u79fb\u52a8\u662f\u56e0\u4e3a\u4e0d\u80fd\u8d70\u51fa\u7f51\u683c\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1ablocked = [], source = [0,0], target = [999999,999999]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\n\u56e0\u4e3a\u6ca1\u6709\u65b9\u683c\u88ab\u5c01\u9501\uff0c\u6240\u4ee5\u4e00\u5b9a\u53ef\u4ee5\u5230\u8fbe\u76ee\u6807\u65b9\u683c\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= blocked.length <= 200
    • \n\t
    • blocked[i].length == 2
    • \n\t
    • 0 <= xi, yi < 106
    • \n\t
    • source.length == target.length == 2
    • \n\t
    • 0 <= sx, sy, tx, ty < 106
    • \n\t
    • source != target
    • \n\t
    • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1 source \u548c target \u4e0d\u5728\u5c01\u9501\u5217\u8868\u5185
    • \n
    \n", "tags_en": ["Breadth-first Search"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isEscapePossible(vector>& blocked, vector& source, vector& target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isEscapePossible(int[][] blocked, int[] source, int[] target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isEscapePossible(self, blocked, source, target):\n \"\"\"\n :type blocked: List[List[int]]\n :type source: List[int]\n :type target: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isEscapePossible(self, blocked: List[List[int]], source: List[int], target: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isEscapePossible(int** blocked, int blockedSize, int* blockedColSize, int* source, int sourceSize, int* target, int targetSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsEscapePossible(int[][] blocked, int[] source, int[] target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} blocked\n * @param {number[]} source\n * @param {number[]} target\n * @return {boolean}\n */\nvar isEscapePossible = function(blocked, source, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} blocked\n# @param {Integer[]} source\n# @param {Integer[]} target\n# @return {Boolean}\ndef is_escape_possible(blocked, source, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isEscapePossible(_ blocked: [[Int]], _ source: [Int], _ target: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isEscapePossible(blocked [][]int, source []int, target []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isEscapePossible(blocked: Array[Array[Int]], source: Array[Int], target: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isEscapePossible(blocked: Array, source: IntArray, target: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_escape_possible(blocked: Vec>, source: Vec, target: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $blocked\n * @param Integer[] $source\n * @param Integer[] $target\n * @return Boolean\n */\n function isEscapePossible($blocked, $source, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isEscapePossible(blocked: number[][], source: number[], target: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-escape-possible blocked source target)\n (-> (listof (listof exact-integer?)) (listof exact-integer?) (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1036](https://leetcode-cn.com/problems/escape-a-large-maze)", "[\u9003\u79bb\u5927\u8ff7\u5bab](/solution/1000-1099/1036.Escape%20a%20Large%20Maze/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[1036](https://leetcode.com/problems/escape-a-large-maze)", "[Escape a Large Maze](/solution/1000-1099/1036.Escape%20a%20Large%20Maze/README_EN.md)", "`Breadth-first Search`", "Hard", ""]}, {"question_id": "1105", "frontend_question_id": "1035", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/uncrossed-lines", "url_en": "https://leetcode.com/problems/uncrossed-lines", "relative_path_cn": "/solution/1000-1099/1035.Uncrossed%20Lines/README.md", "relative_path_en": "/solution/1000-1099/1035.Uncrossed%20Lines/README_EN.md", "title_cn": "\u4e0d\u76f8\u4ea4\u7684\u7ebf", "title_en": "Uncrossed Lines", "question_title_slug": "uncrossed-lines", "content_en": "

    We write the integers of nums1 and nums2 (in the order they are given) on two separate horizontal lines.

    \n\n

    Now, we may draw connecting lines: a straight line connecting two numbers nums1[i] and nums2[j] such that:

    \n\n
      \n\t
    • nums1[i] == nums2[j];
    • \n\t
    • The line we draw does not intersect any other connecting (non-horizontal) line.
    • \n
    \n\n

    Note that a connecting lines cannot intersect even at the endpoints: each number can only belong to one connecting line.

    \n\n

    Return the maximum number of connecting lines we can draw in this way.

    \n\n

     

    \n\n

    Example 1:

    \n\"\"\n
    \nInput: nums1 = [1,4,2], nums2 = [1,2,4]\nOutput: 2\nExplanation: We can draw 2 uncrossed lines as in the diagram.\nWe cannot draw 3 uncrossed lines, because the line from nums1[1]=4 to nums2[2]=4 will intersect the line from nums1[2]=2 to nums2[1]=2.\n
    \n\n
    \n

    Example 2:

    \n\n
    \nInput: nums1 = [2,5,1,2,5], nums2 = [10,5,2,1,5,2]\nOutput: 3\n
    \n\n
    \n

    Example 3:

    \n\n
    \nInput: nums1 = [1,3,7,1,7,5], nums2 = [1,9,2,5,1]\nOutput: 2
    \n\n

     

    \n
    \n
    \n\n

    Note:

    \n\n
      \n\t
    1. 1 <= nums1.length <= 500
    2. \n\t
    3. 1 <= nums2.length <= 500
    4. \n\t
    5. 1 <= nums1[i], nums2[i] <= 2000
    6. \n
    \n", "content_cn": "

    \u5728\u4e24\u6761\u72ec\u7acb\u7684\u6c34\u5e73\u7ebf\u4e0a\u6309\u7ed9\u5b9a\u7684\u987a\u5e8f\u5199\u4e0b nums1 \u548c nums2 \u4e2d\u7684\u6574\u6570\u3002

    \n\n

    \u73b0\u5728\uff0c\u53ef\u4ee5\u7ed8\u5236\u4e00\u4e9b\u8fde\u63a5\u4e24\u4e2a\u6570\u5b57 nums1[i]\u00a0\u548c nums2[j]\u00a0\u7684\u76f4\u7ebf\uff0c\u8fd9\u4e9b\u76f4\u7ebf\u9700\u8981\u540c\u65f6\u6ee1\u8db3\u6ee1\u8db3\uff1a

    \n\n
      \n\t
    • \u00a0nums1[i] == nums2[j]
    • \n\t
    • \u4e14\u7ed8\u5236\u7684\u76f4\u7ebf\u4e0d\u4e0e\u4efb\u4f55\u5176\u4ed6\u8fde\u7ebf\uff08\u975e\u6c34\u5e73\u7ebf\uff09\u76f8\u4ea4\u3002
    • \n
    \n\n

    \u8bf7\u6ce8\u610f\uff0c\u8fde\u7ebf\u5373\u4f7f\u5728\u7aef\u70b9\u4e5f\u4e0d\u80fd\u76f8\u4ea4\uff1a\u6bcf\u4e2a\u6570\u5b57\u53ea\u80fd\u5c5e\u4e8e\u4e00\u6761\u8fde\u7ebf\u3002

    \n\n

    \u4ee5\u8fd9\u79cd\u65b9\u6cd5\u7ed8\u5236\u7ebf\u6761\uff0c\u5e76\u8fd4\u56de\u53ef\u4ee5\u7ed8\u5236\u7684\u6700\u5927\u8fde\u7ebf\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n\n
    \n\u8f93\u5165\uff1anums1 = [1,4,2], nums2 = [1,2,4]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u53ef\u4ee5\u753b\u51fa\u4e24\u6761\u4e0d\u4ea4\u53c9\u7684\u7ebf\uff0c\u5982\u4e0a\u56fe\u6240\u793a\u3002 \n\u4f46\u65e0\u6cd5\u753b\u51fa\u7b2c\u4e09\u6761\u4e0d\u76f8\u4ea4\u7684\u76f4\u7ebf\uff0c\u56e0\u4e3a\u4ece nums1[1]=4 \u5230 nums2[2]=4 \u7684\u76f4\u7ebf\u5c06\u4e0e\u4ece nums1[2]=2 \u5230 nums2[1]=2 \u7684\u76f4\u7ebf\u76f8\u4ea4\u3002\n
    \n\n
    \n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums1 = [2,5,1,2,5], nums2 = [10,5,2,1,5,2]\n\u8f93\u51fa\uff1a3\n
    \n\n
    \n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums1 = [1,3,7,1,7,5], nums2 = [1,9,2,5,1]\n\u8f93\u51fa\uff1a2
    \n\n

    \u00a0

    \n
    \n
    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums1.length <= 500
    • \n\t
    • 1 <= nums2.length <= 500
    • \n\t
    • 1 <= nums1[i], nums2[i] <= 2000
    • \n
    \n\n

    \u00a0

    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxUncrossedLines(vector& nums1, vector& nums2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxUncrossedLines(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxUncrossedLines(self, nums1, nums2):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxUncrossedLines(self, nums1: List[int], nums2: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxUncrossedLines(int* nums1, int nums1Size, int* nums2, int nums2Size){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxUncrossedLines(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums1\n * @param {number[]} nums2\n * @return {number}\n */\nvar maxUncrossedLines = function(nums1, nums2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums1\n# @param {Integer[]} nums2\n# @return {Integer}\ndef max_uncrossed_lines(nums1, nums2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxUncrossedLines(_ nums1: [Int], _ nums2: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxUncrossedLines(nums1 []int, nums2 []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxUncrossedLines(nums1: Array[Int], nums2: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxUncrossedLines(nums1: IntArray, nums2: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_uncrossed_lines(nums1: Vec, nums2: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums1\n * @param Integer[] $nums2\n * @return Integer\n */\n function maxUncrossedLines($nums1, $nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxUncrossedLines(nums1: number[], nums2: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-uncrossed-lines nums1 nums2)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1035](https://leetcode-cn.com/problems/uncrossed-lines)", "[\u4e0d\u76f8\u4ea4\u7684\u7ebf](/solution/1000-1099/1035.Uncrossed%20Lines/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1035](https://leetcode.com/problems/uncrossed-lines)", "[Uncrossed Lines](/solution/1000-1099/1035.Uncrossed%20Lines/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "1104", "frontend_question_id": "1034", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/coloring-a-border", "url_en": "https://leetcode.com/problems/coloring-a-border", "relative_path_cn": "/solution/1000-1099/1034.Coloring%20A%20Border/README.md", "relative_path_en": "/solution/1000-1099/1034.Coloring%20A%20Border/README_EN.md", "title_cn": "\u8fb9\u6846\u7740\u8272", "title_en": "Coloring A Border", "question_title_slug": "coloring-a-border", "content_en": "

    Given a 2-dimensional grid of integers, each value in the grid represents the color of the grid square at that location.

    \r\n\r\n

    Two squares belong to the same connected component if and only if they have the same color and are next to each other in any of the 4 directions.

    \r\n\r\n

    The border of a connected component is all the squares in the connected component that are either 4-directionally adjacent to a square not in the component, or on the boundary of the grid (the first or last row or column).

    \r\n\r\n

    Given a square at location (r0, c0) in the grid and a color, color the border of the connected component of that square with the given color, and return the final grid.

    \r\n\r\n

     

    \r\n\r\n

    Example 1:

    \r\n\r\n
    \r\nInput: grid = [[1,1],[1,2]], r0 = 0, c0 = 0, color = 3\r\nOutput: [[3, 3], [3, 2]]\r\n
    \r\n\r\n
    \r\n

    Example 2:

    \r\n\r\n
    \r\nInput: grid = [[1,2,2],[2,3,2]], r0 = 0, c0 = 1, color = 3\r\nOutput: [[1, 3, 3], [2, 3, 3]]\r\n
    \r\n\r\n
    \r\n

    Example 3:

    \r\n\r\n
    \r\nInput: grid = [[1,1,1],[1,1,1],[1,1,1]], r0 = 1, c0 = 1, color = 2\r\nOutput: [[2, 2, 2], [2, 1, 2], [2, 2, 2]]
    \r\n
    \r\n
    \r\n\r\n

     

    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    1. 1 <= grid.length <= 50
    2. \r\n\t
    3. 1 <= grid[0].length <= 50
    4. \r\n\t
    5. 1 <= grid[i][j] <= 1000
    6. \r\n\t
    7. 0 <= r0 < grid.length
    8. \r\n\t
    9. 0 <= c0 < grid[0].length
    10. \r\n\t
    11. 1 <= color <= 1000
    12. \r\n
    ", "content_cn": "

    \u7ed9\u51fa\u4e00\u4e2a\u4e8c\u7ef4\u6574\u6570\u7f51\u683c grid\uff0c\u7f51\u683c\u4e2d\u7684\u6bcf\u4e2a\u503c\u8868\u793a\u8be5\u4f4d\u7f6e\u5904\u7684\u7f51\u683c\u5757\u7684\u989c\u8272\u3002

    \n\n

    \u53ea\u6709\u5f53\u4e24\u4e2a\u7f51\u683c\u5757\u7684\u989c\u8272\u76f8\u540c\uff0c\u800c\u4e14\u5728\u56db\u4e2a\u65b9\u5411\u4e2d\u4efb\u610f\u4e00\u4e2a\u65b9\u5411\u4e0a\u76f8\u90bb\u65f6\uff0c\u5b83\u4eec\u5c5e\u4e8e\u540c\u4e00\u8fde\u901a\u5206\u91cf\u3002

    \n\n

    \u8fde\u901a\u5206\u91cf\u7684\u8fb9\u754c\u662f\u6307\u8fde\u901a\u5206\u91cf\u4e2d\u7684\u6240\u6709\u4e0e\u4e0d\u5728\u5206\u91cf\u4e2d\u7684\u6b63\u65b9\u5f62\u76f8\u90bb\uff08\u56db\u4e2a\u65b9\u5411\u4e0a\uff09\u7684\u6240\u6709\u6b63\u65b9\u5f62\uff0c\u6216\u8005\u5728\u7f51\u683c\u7684\u8fb9\u754c\u4e0a\uff08\u7b2c\u4e00\u884c/\u5217\u6216\u6700\u540e\u4e00\u884c/\u5217\uff09\u7684\u6240\u6709\u6b63\u65b9\u5f62\u3002

    \n\n

    \u7ed9\u51fa\u4f4d\u4e8e (r0, c0) \u7684\u7f51\u683c\u5757\u548c\u989c\u8272 color\uff0c\u4f7f\u7528\u6307\u5b9a\u989c\u8272 color \u4e3a\u6240\u7ed9\u7f51\u683c\u5757\u7684\u8fde\u901a\u5206\u91cf\u7684\u8fb9\u754c\u8fdb\u884c\u7740\u8272\uff0c\u5e76\u8fd4\u56de\u6700\u7ec8\u7684\u7f51\u683c grid \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1agrid = [[1,1],[1,2]], r0 = 0, c0 = 0, color = 3\n\u8f93\u51fa\uff1a[[3, 3], [3, 2]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1agrid = [[1,2,2],[2,3,2]], r0 = 0, c0 = 1, color = 3\n\u8f93\u51fa\uff1a[[1, 3, 3], [2, 3, 3]]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1agrid = [[1,1,1],[1,1,1],[1,1,1]], r0 = 1, c0 = 1, color = 2\n\u8f93\u51fa\uff1a[[2, 2, 2], [2, 1, 2], [2, 2, 2]]
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= grid.length <= 50
    2. \n\t
    3. 1 <= grid[0].length <= 50
    4. \n\t
    5. 1 <= grid[i][j] <= 1000
    6. \n\t
    7. 0 <= r0 < grid.length
    8. \n\t
    9. 0 <= c0 < grid[0].length
    10. \n\t
    11. 1 <= color <= 1000
    12. \n
    \n\n

     

    \n", "tags_en": ["Depth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> colorBorder(vector>& grid, int r0, int c0, int color) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[][] colorBorder(int[][] grid, int r0, int c0, int color) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def colorBorder(self, grid, r0, c0, color):\n \"\"\"\n :type grid: List[List[int]]\n :type r0: int\n :type c0: int\n :type color: int\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def colorBorder(self, grid: List[List[int]], r0: int, c0: int, color: int) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** colorBorder(int** grid, int gridSize, int* gridColSize, int r0, int c0, int color, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[][] ColorBorder(int[][] grid, int r0, int c0, int color) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @param {number} r0\n * @param {number} c0\n * @param {number} color\n * @return {number[][]}\n */\nvar colorBorder = function(grid, r0, c0, color) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @param {Integer} r0\n# @param {Integer} c0\n# @param {Integer} color\n# @return {Integer[][]}\ndef color_border(grid, r0, c0, color)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func colorBorder(_ grid: [[Int]], _ r0: Int, _ c0: Int, _ color: Int) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func colorBorder(grid [][]int, r0 int, c0 int, color int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def colorBorder(grid: Array[Array[Int]], r0: Int, c0: Int, color: Int): Array[Array[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun colorBorder(grid: Array, r0: Int, c0: Int, color: Int): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn color_border(grid: Vec>, r0: i32, c0: i32, color: i32) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @param Integer $r0\n * @param Integer $c0\n * @param Integer $color\n * @return Integer[][]\n */\n function colorBorder($grid, $r0, $c0, $color) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function colorBorder(grid: number[][], r0: number, c0: number, color: number): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (color-border grid r0 c0 color)\n (-> (listof (listof exact-integer?)) exact-integer? exact-integer? exact-integer? (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1034](https://leetcode-cn.com/problems/coloring-a-border)", "[\u8fb9\u6846\u7740\u8272](/solution/1000-1099/1034.Coloring%20A%20Border/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1034](https://leetcode.com/problems/coloring-a-border)", "[Coloring A Border](/solution/1000-1099/1034.Coloring%20A%20Border/README_EN.md)", "`Depth-first Search`", "Medium", ""]}, {"question_id": "1103", "frontend_question_id": "1033", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/moving-stones-until-consecutive", "url_en": "https://leetcode.com/problems/moving-stones-until-consecutive", "relative_path_cn": "/solution/1000-1099/1033.Moving%20Stones%20Until%20Consecutive/README.md", "relative_path_en": "/solution/1000-1099/1033.Moving%20Stones%20Until%20Consecutive/README_EN.md", "title_cn": "\u79fb\u52a8\u77f3\u5b50\u76f4\u5230\u8fde\u7eed", "title_en": "Moving Stones Until Consecutive", "question_title_slug": "moving-stones-until-consecutive", "content_en": "

    Three stones are on a number line at positions a, b, and c.

    \r\n\r\n

    Each turn, you pick up a stone at an endpoint (ie., either the lowest or highest position stone), and move it to an unoccupied position between those endpoints.  Formally, let's say the stones are currently at positions x, y, z with x < y < z.  You pick up the stone at either position x or position z, and move that stone to an integer position k, with x < k < z and k != y.

    \r\n\r\n

    The game ends when you cannot make any more moves, ie. the stones are in consecutive positions.

    \r\n\r\n

    When the game ends, what is the minimum and maximum number of moves that you could have made?  Return the answer as an length 2 array: answer = [minimum_moves, maximum_moves]

    \r\n\r\n

     

    \r\n\r\n

    Example 1:

    \r\n\r\n
    \r\nInput: a = 1, b = 2, c = 5\r\nOutput: [1,2]\r\nExplanation: Move the stone from 5 to 3, or move the stone from 5 to 4 to 3.\r\n
    \r\n\r\n
    \r\n

    Example 2:

    \r\n\r\n
    \r\nInput: a = 4, b = 3, c = 2\r\nOutput: [0,0]\r\nExplanation: We cannot make any moves.\r\n
    \r\n\r\n
    \r\n

    Example 3:

    \r\n\r\n
    \r\nInput: a = 3, b = 5, c = 1\r\nOutput: [1,2]\r\nExplanation: Move the stone from 1 to 4; or move the stone from 1 to 2 to 4.\r\n
    \r\n\r\n

     

    \r\n
    \r\n
    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    1. 1 <= a <= 100
    2. \r\n\t
    3. 1 <= b <= 100
    4. \r\n\t
    5. 1 <= c <= 100
    6. \r\n\t
    7. a != b, b != c, c != a
    8. \r\n
    \r\n\r\n
    \r\n

     

    \r\n\r\n
    \r\n
     
    \r\n
    \r\n
    \r\n", "content_cn": "

    \u4e09\u679a\u77f3\u5b50\u653e\u7f6e\u5728\u6570\u8f74\u4e0a\uff0c\u4f4d\u7f6e\u5206\u522b\u4e3a a\uff0cb\uff0cc\u3002

    \n\n

    \u6bcf\u4e00\u56de\u5408\uff0c\u4f60\u53ef\u4ee5\u4ece\u4e24\u7aef\u4e4b\u4e00\u62ff\u8d77\u4e00\u679a\u77f3\u5b50\uff08\u4f4d\u7f6e\u6700\u5927\u6216\u6700\u5c0f\uff09\uff0c\u5e76\u5c06\u5176\u653e\u5165\u4e24\u7aef\u4e4b\u95f4\u7684\u4efb\u4e00\u7a7a\u95f2\u4f4d\u7f6e\u3002\u5f62\u5f0f\u4e0a\uff0c\u5047\u8bbe\u8fd9\u4e09\u679a\u77f3\u5b50\u5f53\u524d\u5206\u522b\u4f4d\u4e8e\u4f4d\u7f6e x, y, z \u4e14 x < y < z\u3002\u90a3\u4e48\u5c31\u53ef\u4ee5\u4ece\u4f4d\u7f6e x \u6216\u8005\u662f\u4f4d\u7f6e z \u62ff\u8d77\u4e00\u679a\u77f3\u5b50\uff0c\u5e76\u5c06\u8be5\u77f3\u5b50\u79fb\u52a8\u5230\u67d0\u4e00\u6574\u6570\u4f4d\u7f6e k \u5904\uff0c\u5176\u4e2d x < k < z \u4e14 k != y\u3002

    \n\n

    \u5f53\u4f60\u65e0\u6cd5\u8fdb\u884c\u4efb\u4f55\u79fb\u52a8\u65f6\uff0c\u5373\uff0c\u8fd9\u4e9b\u77f3\u5b50\u7684\u4f4d\u7f6e\u8fde\u7eed\u65f6\uff0c\u6e38\u620f\u7ed3\u675f\u3002

    \n\n

    \u8981\u4f7f\u6e38\u620f\u7ed3\u675f\uff0c\u4f60\u53ef\u4ee5\u6267\u884c\u7684\u6700\u5c0f\u548c\u6700\u5927\u79fb\u52a8\u6b21\u6570\u5206\u522b\u662f\u591a\u5c11\uff1f \u4ee5\u957f\u5ea6\u4e3a 2 \u7684\u6570\u7ec4\u5f62\u5f0f\u8fd4\u56de\u7b54\u6848\uff1aanswer = [minimum_moves, maximum_moves]

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aa = 1, b = 2, c = 5\n\u8f93\u51fa\uff1a[1, 2]\n\u89e3\u91ca\uff1a\u5c06\u77f3\u5b50\u4ece 5 \u79fb\u52a8\u5230 4 \u518d\u79fb\u52a8\u5230 3\uff0c\u6216\u8005\u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u5c06\u77f3\u5b50\u79fb\u52a8\u5230 3\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aa = 4, b = 3, c = 2\n\u8f93\u51fa\uff1a[0, 0]\n\u89e3\u91ca\uff1a\u6211\u4eec\u65e0\u6cd5\u8fdb\u884c\u4efb\u4f55\u79fb\u52a8\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= a <= 100
    2. \n\t
    3. 1 <= b <= 100
    4. \n\t
    5. 1 <= c <= 100
    6. \n\t
    7. a != b, b != c, c != a
    8. \n
    \n", "tags_en": ["Brainteaser"], "tags_cn": ["\u8111\u7b4b\u6025\u8f6c\u5f2f"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector numMovesStones(int a, int b, int c) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] numMovesStones(int a, int b, int c) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numMovesStones(self, a, b, c):\n \"\"\"\n :type a: int\n :type b: int\n :type c: int\n :rtype: List[int]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numMovesStones(self, a: int, b: int, c: int) -> List[int]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* numMovesStones(int a, int b, int c, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] NumMovesStones(int a, int b, int c) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} a\n * @param {number} b\n * @param {number} c\n * @return {number[]}\n */\nvar numMovesStones = function(a, b, c) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} a\n# @param {Integer} b\n# @param {Integer} c\n# @return {Integer[]}\ndef num_moves_stones(a, b, c)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numMovesStones(_ a: Int, _ b: Int, _ c: Int) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numMovesStones(a int, b int, c int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numMovesStones(a: Int, b: Int, c: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numMovesStones(a: Int, b: Int, c: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_moves_stones(a: i32, b: i32, c: i32) -> Vec {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $a\n * @param Integer $b\n * @param Integer $c\n * @return Integer[]\n */\n function numMovesStones($a, $b, $c) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numMovesStones(a: number, b: number, c: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-moves-stones a b c)\n (-> exact-integer? exact-integer? exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1033](https://leetcode-cn.com/problems/moving-stones-until-consecutive)", "[\u79fb\u52a8\u77f3\u5b50\u76f4\u5230\u8fde\u7eed](/solution/1000-1099/1033.Moving%20Stones%20Until%20Consecutive/README.md)", "`\u8111\u7b4b\u6025\u8f6c\u5f2f`", "\u7b80\u5355", ""], "md_table_row_en": ["[1033](https://leetcode.com/problems/moving-stones-until-consecutive)", "[Moving Stones Until Consecutive](/solution/1000-1099/1033.Moving%20Stones%20Until%20Consecutive/README_EN.md)", "`Brainteaser`", "Easy", ""]}, {"question_id": "1102", "frontend_question_id": "1150", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/check-if-a-number-is-majority-element-in-a-sorted-array", "url_en": "https://leetcode.com/problems/check-if-a-number-is-majority-element-in-a-sorted-array", "relative_path_cn": "/solution/1100-1199/1150.Check%20If%20a%20Number%20Is%20Majority%20Element%20in%20a%20Sorted%20Array/README.md", "relative_path_en": "/solution/1100-1199/1150.Check%20If%20a%20Number%20Is%20Majority%20Element%20in%20a%20Sorted%20Array/README_EN.md", "title_cn": "\u68c0\u67e5\u4e00\u4e2a\u6570\u662f\u5426\u5728\u6570\u7ec4\u4e2d\u5360\u7edd\u5927\u591a\u6570", "title_en": "Check If a Number Is Majority Element in a Sorted Array", "question_title_slug": "check-if-a-number-is-majority-element-in-a-sorted-array", "content_en": "

    Given an array nums sorted in non-decreasing order, and a number target, return True if and only if target is a majority element.

    \n\n

    A majority element is an element that appears more than N/2 times in an array of length N.

    \n\n

     

    \n\n

    Example 1:

    \n\n
    \nInput: nums = [2,4,5,5,5,5,5,6,6], target = 5\nOutput: true\nExplanation: \nThe value 5 appears 5 times and the length of the array is 9.\nThus, 5 is a majority element because 5 > 9/2 is true.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [10,100,101,101], target = 101\nOutput: false\nExplanation: \nThe value 101 appears 2 times and the length of the array is 4.\nThus, 101 is not a majority element because 2 > 4/2 is false.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 1000
    • \n\t
    • 1 <= nums[i] <= 10^9
    • \n\t
    • 1 <= target <= 10^9
    • \n
    \n", "content_cn": "

    \u7ed9\u51fa\u4e00\u4e2a\u6309 \u975e\u9012\u51cf\u00a0\u987a\u5e8f\u6392\u5217\u7684\u6570\u7ec4\u00a0nums\uff0c\u548c\u4e00\u4e2a\u76ee\u6807\u6570\u503c\u00a0target\u3002\u5047\u5982\u6570\u7ec4\u00a0nums \u4e2d\u7edd\u5927\u591a\u6570\u5143\u7d20\u7684\u6570\u503c\u90fd\u7b49\u4e8e\u00a0target\uff0c\u5219\u8fd4\u56de\u00a0True\uff0c\u5426\u5219\u8bf7\u8fd4\u56de\u00a0False\u3002

    \n\n

    \u6240\u8c13\u5360\u7edd\u5927\u591a\u6570\uff0c\u662f\u6307\u5728\u957f\u5ea6\u4e3a N\u00a0\u7684\u6570\u7ec4\u4e2d\u51fa\u73b0\u5fc5\u987b\u00a0\u8d85\u8fc7\u00a0N/2\u00a0\u6b21\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [2,4,5,5,5,5,5,6,6], target = 5\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\n\u6570\u5b57 5 \u51fa\u73b0\u4e86 5 \u6b21\uff0c\u800c\u6570\u7ec4\u7684\u957f\u5ea6\u4e3a 9\u3002\n\u6240\u4ee5\uff0c5 \u5728\u6570\u7ec4\u4e2d\u5360\u7edd\u5927\u591a\u6570\uff0c\u56e0\u4e3a 5 \u6b21 > 9/2\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [10,100,101,101], target = 101\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\n\u6570\u5b57 101 \u51fa\u73b0\u4e86 2 \u6b21\uff0c\u800c\u6570\u7ec4\u7684\u957f\u5ea6\u662f 4\u3002\n\u6240\u4ee5\uff0c101 \u4e0d\u662f \u6570\u7ec4\u5360\u7edd\u5927\u591a\u6570\u7684\u5143\u7d20\uff0c\u56e0\u4e3a 2 \u6b21 = 4/2\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 1000
    • \n\t
    • 1 <= nums[i] <= 10^9
    • \n\t
    • 1 <= target <= 10^9
    • \n
    \n", "tags_en": ["Array", "Binary Search"], "tags_cn": ["\u6570\u7ec4", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isMajorityElement(vector& nums, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isMajorityElement(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isMajorityElement(self, nums, target):\n \"\"\"\n :type nums: List[int]\n :type target: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isMajorityElement(self, nums: List[int], target: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isMajorityElement(int* nums, int numsSize, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsMajorityElement(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} target\n * @return {boolean}\n */\nvar isMajorityElement = function(nums, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} target\n# @return {Boolean}\ndef is_majority_element(nums, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isMajorityElement(_ nums: [Int], _ target: Int) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isMajorityElement(nums []int, target int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isMajorityElement(nums: Array[Int], target: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isMajorityElement(nums: IntArray, target: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_majority_element(nums: Vec, target: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $target\n * @return Boolean\n */\n function isMajorityElement($nums, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isMajorityElement(nums: number[], target: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-majority-element nums target)\n (-> (listof exact-integer?) exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1150](https://leetcode-cn.com/problems/check-if-a-number-is-majority-element-in-a-sorted-array)", "[\u68c0\u67e5\u4e00\u4e2a\u6570\u662f\u5426\u5728\u6570\u7ec4\u4e2d\u5360\u7edd\u5927\u591a\u6570](/solution/1100-1199/1150.Check%20If%20a%20Number%20Is%20Majority%20Element%20in%20a%20Sorted%20Array/README.md)", "`\u6570\u7ec4`,`\u4e8c\u5206\u67e5\u627e`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1150](https://leetcode.com/problems/check-if-a-number-is-majority-element-in-a-sorted-array)", "[Check If a Number Is Majority Element in a Sorted Array](/solution/1100-1199/1150.Check%20If%20a%20Number%20Is%20Majority%20Element%20in%20a%20Sorted%20Array/README_EN.md)", "`Array`,`Binary Search`", "Easy", "\ud83d\udd12"]}, {"question_id": "1101", "frontend_question_id": "1136", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/parallel-courses", "url_en": "https://leetcode.com/problems/parallel-courses", "relative_path_cn": "/solution/1100-1199/1136.Parallel%20Courses/README.md", "relative_path_en": "/solution/1100-1199/1136.Parallel%20Courses/README_EN.md", "title_cn": "\u5e73\u884c\u8bfe\u7a0b", "title_en": "Parallel Courses", "question_title_slug": "parallel-courses", "content_en": "

    You are given an integer n, which indicates that there are n courses labeled from 1 to n. You are also given an array relations where relations[i] = [prevCoursei, nextCoursei], representing a prerequisite relationship between course prevCoursei and course nextCoursei: course prevCoursei has to be taken before course nextCoursei.

    \n\n

    In one semester, you can take any number of courses as long as you have taken all the prerequisites in the previous semester for the courses you are taking.

    \n\n

    Return the minimum number of semesters needed to take all courses. If there is no way to take all the courses, return -1.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: n = 3, relations = [[1,3],[2,3]]\nOutput: 2\nExplanation: The figure above represents the given graph.\nIn the first semester, you can take courses 1 and 2.\nIn the second semester, you can take course 3.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: n = 3, relations = [[1,2],[2,3],[3,1]]\nOutput: -1\nExplanation: No course can be studied because they are prerequisites of each other.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 5000
    • \n\t
    • 1 <= relations.length <= 5000
    • \n\t
    • relations[i].length == 2
    • \n\t
    • 1 <= prevCoursei, nextCoursei <= n
    • \n\t
    • prevCoursei != nextCoursei
    • \n\t
    • All the pairs [prevCoursei, nextCoursei] are unique.
    • \n
    \n", "content_cn": "

    \u5df2\u77e5\u6709 N \u95e8\u8bfe\u7a0b\uff0c\u5b83\u4eec\u4ee5 1 \u5230 N \u8fdb\u884c\u7f16\u53f7\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4efd\u8bfe\u7a0b\u5173\u7cfb\u8868 relations[i] = [X, Y]\uff0c\u7528\u4ee5\u8868\u793a\u8bfe\u7a0b X \u548c\u8bfe\u7a0b Y \u4e4b\u95f4\u7684\u5148\u4fee\u5173\u7cfb\uff1a\u8bfe\u7a0b X \u5fc5\u987b\u5728\u8bfe\u7a0b Y \u4e4b\u524d\u4fee\u5b8c\u3002

    \n\n

    \u5047\u8bbe\u5728\u4e00\u4e2a\u5b66\u671f\u91cc\uff0c\u4f60\u53ef\u4ee5\u5b66\u4e60\u4efb\u4f55\u6570\u91cf\u7684\u8bfe\u7a0b\uff0c\u4f46\u524d\u63d0\u662f\u4f60\u5df2\u7ecf\u5b66\u4e60\u4e86\u5c06\u8981\u5b66\u4e60\u7684\u8fd9\u4e9b\u8bfe\u7a0b\u7684\u6240\u6709\u5148\u4fee\u8bfe\u7a0b\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u5b66\u5b8c\u5168\u90e8\u8bfe\u7a0b\u6240\u9700\u7684\u6700\u5c11\u5b66\u671f\u6570\u3002

    \n\n

    \u5982\u679c\u6ca1\u6709\u529e\u6cd5\u505a\u5230\u5b66\u5b8c\u5168\u90e8\u8fd9\u4e9b\u8bfe\u7a0b\u7684\u8bdd\uff0c\u5c31\u8fd4\u56de -1\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1aN = 3, relations = [[1,3],[2,3]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n\u5728\u7b2c\u4e00\u4e2a\u5b66\u671f\u5b66\u4e60\u8bfe\u7a0b 1 \u548c 2\uff0c\u5728\u7b2c\u4e8c\u4e2a\u5b66\u671f\u5b66\u4e60\u8bfe\u7a0b 3\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1aN = 3, relations = [[1,2],[2,3],[3,1]]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\n\u6ca1\u6709\u8bfe\u7a0b\u53ef\u4ee5\u5b66\u4e60\uff0c\u56e0\u4e3a\u5b83\u4eec\u76f8\u4e92\u4f9d\u8d56\u3002
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= N <= 5000
    2. \n\t
    3. 1 <= relations.length <= 5000
    4. \n\t
    5. relations[i][0] != relations[i][1]
    6. \n\t
    7. \u8f93\u5165\u4e2d\u6ca1\u6709\u91cd\u590d\u7684\u5173\u7cfb
    8. \n
    \n", "tags_en": ["Depth-first Search", "Graph", "Dynamic Programming"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u56fe", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minimumSemesters(int n, vector>& relations) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minimumSemesters(int n, int[][] relations) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimumSemesters(self, n, relations):\n \"\"\"\n :type n: int\n :type relations: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimumSemesters(self, n: int, relations: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minimumSemesters(int n, int** relations, int relationsSize, int* relationsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinimumSemesters(int n, int[][] relations) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} relations\n * @return {number}\n */\nvar minimumSemesters = function(n, relations) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} relations\n# @return {Integer}\ndef minimum_semesters(n, relations)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimumSemesters(_ n: Int, _ relations: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimumSemesters(n int, relations [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimumSemesters(n: Int, relations: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimumSemesters(n: Int, relations: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimum_semesters(n: i32, relations: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $relations\n * @return Integer\n */\n function minimumSemesters($n, $relations) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimumSemesters(n: number, relations: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimum-semesters n relations)\n (-> exact-integer? (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1136](https://leetcode-cn.com/problems/parallel-courses)", "[\u5e73\u884c\u8bfe\u7a0b](/solution/1100-1199/1136.Parallel%20Courses/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u56fe`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1136](https://leetcode.com/problems/parallel-courses)", "[Parallel Courses](/solution/1100-1199/1136.Parallel%20Courses/README_EN.md)", "`Depth-first Search`,`Graph`,`Dynamic Programming`", "Medium", "\ud83d\udd12"]}, {"question_id": "1100", "frontend_question_id": "1135", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/connecting-cities-with-minimum-cost", "url_en": "https://leetcode.com/problems/connecting-cities-with-minimum-cost", "relative_path_cn": "/solution/1100-1199/1135.Connecting%20Cities%20With%20Minimum%20Cost/README.md", "relative_path_en": "/solution/1100-1199/1135.Connecting%20Cities%20With%20Minimum%20Cost/README_EN.md", "title_cn": "\u6700\u4f4e\u6210\u672c\u8054\u901a\u6240\u6709\u57ce\u5e02", "title_en": "Connecting Cities With Minimum Cost", "question_title_slug": "connecting-cities-with-minimum-cost", "content_en": "

    There are n cities numbered from 1 to n.

    \n\n

    You are given connections, where each connections[i] = [city1, city2, cost] represents the cost to connect city1 and city2 together.  (A connection is bidirectional: connecting city1 and city2 is the same as connecting city2 and city1.)

    \n\n

    Return the minimum cost so that for every pair of cities, there exists a path of connections (possibly of length 1) that connects those two cities together.  The cost is the sum of the connection costs used. If the task is impossible, return -1.

    \n\n

     

    \n\n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: n = 3, connections = [[1,2,5],[1,3,6],[2,3,1]]\nOutput: 6\nExplanation: \nChoosing any 2 edges will connect all cities so we choose the minimum 2.\n
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: n = 4, connections = [[1,2,3],[3,4,4]]\nOutput: -1\nExplanation: \nThere is no way to connect all cities even if all edges are used.\n
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    1. 1 <= n <= 10000
    2. \n\t
    3. 1 <= connections.length <= 10000
    4. \n\t
    5. 1 <= connections[i][0], connections[i][1] <= n
    6. \n\t
    7. 0 <= connections[i][2] <= 105
    8. \n\t
    9. connections[i][0] != connections[i][1]
    10. \n
    \n", "content_cn": "

    \u60f3\u8c61\u4e00\u4e0b\u4f60\u662f\u4e2a\u57ce\u5e02\u57fa\u5efa\u89c4\u5212\u8005\uff0c\u5730\u56fe\u4e0a\u6709 N \u5ea7\u57ce\u5e02\uff0c\u5b83\u4eec\u6309\u4ee5 1 \u5230 N \u7684\u6b21\u5e8f\u7f16\u53f7\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e9b\u53ef\u8fde\u63a5\u7684\u9009\u9879 conections\uff0c\u5176\u4e2d\u6bcf\u4e2a\u9009\u9879 conections[i] = [city1, city2, cost] \u8868\u793a\u5c06\u57ce\u5e02 city1 \u548c\u57ce\u5e02 city2 \u8fde\u63a5\u6240\u8981\u7684\u6210\u672c\u3002\uff08\u8fde\u63a5\u662f\u53cc\u5411\u7684\uff0c\u4e5f\u5c31\u662f\u8bf4\u57ce\u5e02 city1 \u548c\u57ce\u5e02 city2 \u76f8\u8fde\u4e5f\u540c\u6837\u610f\u5473\u7740\u57ce\u5e02 city2 \u548c\u57ce\u5e02 city1 \u76f8\u8fde\uff09\u3002

    \n\n

    \u8fd4\u56de\u4f7f\u5f97\u6bcf\u5bf9\u57ce\u5e02\u95f4\u90fd\u5b58\u5728\u5c06\u5b83\u4eec\u8fde\u63a5\u5728\u4e00\u8d77\u7684\u8fde\u901a\u8def\u5f84\uff08\u53ef\u80fd\u957f\u5ea6\u4e3a 1 \u7684\uff09\u6700\u5c0f\u6210\u672c\u3002\u8be5\u6700\u5c0f\u6210\u672c\u5e94\u8be5\u662f\u6240\u7528\u5168\u90e8\u8fde\u63a5\u4ee3\u4ef7\u7684\u7efc\u5408\u3002\u5982\u679c\u6839\u636e\u5df2\u77e5\u6761\u4ef6\u65e0\u6cd5\u5b8c\u6210\u8be5\u9879\u4efb\u52a1\uff0c\u5219\u8bf7\u4f60\u8fd4\u56de -1\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1aN = 3, conections = [[1,2,5],[1,3,6],[2,3,1]]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\n\u9009\u51fa\u4efb\u610f 2 \u6761\u8fb9\u90fd\u53ef\u4ee5\u8fde\u63a5\u6240\u6709\u57ce\u5e02\uff0c\u6211\u4eec\u4ece\u4e2d\u9009\u53d6\u6210\u672c\u6700\u5c0f\u7684 2 \u6761\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1aN = 4, conections = [[1,2,3],[3,4,4]]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a \n\u5373\u4f7f\u8fde\u901a\u6240\u6709\u7684\u8fb9\uff0c\u4e5f\u65e0\u6cd5\u8fde\u63a5\u6240\u6709\u57ce\u5e02\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= N <= 10000
    2. \n\t
    3. 1 <= conections.length <= 10000
    4. \n\t
    5. 1 <= conections[i][0], conections[i][1] <= N
    6. \n\t
    7. 0 <= conections[i][2] <= 10^5
    8. \n\t
    9. conections[i][0] != conections[i][1]
    10. \n
    \n", "tags_en": ["Union Find", "Graph"], "tags_cn": ["\u5e76\u67e5\u96c6", "\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minimumCost(int n, vector>& connections) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minimumCost(int n, int[][] connections) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimumCost(self, n, connections):\n \"\"\"\n :type n: int\n :type connections: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimumCost(self, n: int, connections: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minimumCost(int n, int** connections, int connectionsSize, int* connectionsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinimumCost(int n, int[][] connections) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} connections\n * @return {number}\n */\nvar minimumCost = function(n, connections) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} connections\n# @return {Integer}\ndef minimum_cost(n, connections)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimumCost(_ n: Int, _ connections: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimumCost(n int, connections [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimumCost(n: Int, connections: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimumCost(n: Int, connections: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimum_cost(n: i32, connections: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $connections\n * @return Integer\n */\n function minimumCost($n, $connections) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimumCost(n: number, connections: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimum-cost n connections)\n (-> exact-integer? (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1135](https://leetcode-cn.com/problems/connecting-cities-with-minimum-cost)", "[\u6700\u4f4e\u6210\u672c\u8054\u901a\u6240\u6709\u57ce\u5e02](/solution/1100-1199/1135.Connecting%20Cities%20With%20Minimum%20Cost/README.md)", "`\u5e76\u67e5\u96c6`,`\u56fe`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1135](https://leetcode.com/problems/connecting-cities-with-minimum-cost)", "[Connecting Cities With Minimum Cost](/solution/1100-1199/1135.Connecting%20Cities%20With%20Minimum%20Cost/README_EN.md)", "`Union Find`,`Graph`", "Medium", "\ud83d\udd12"]}, {"question_id": "1099", "frontend_question_id": "1102", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/path-with-maximum-minimum-value", "url_en": "https://leetcode.com/problems/path-with-maximum-minimum-value", "relative_path_cn": "/solution/1100-1199/1102.Path%20With%20Maximum%20Minimum%20Value/README.md", "relative_path_en": "/solution/1100-1199/1102.Path%20With%20Maximum%20Minimum%20Value/README_EN.md", "title_cn": "\u5f97\u5206\u6700\u9ad8\u7684\u8def\u5f84", "title_en": "Path With Maximum Minimum Value", "question_title_slug": "path-with-maximum-minimum-value", "content_en": "

    Given a matrix of integers grid with m rows and n columns, find the maximum score of a path starting at [0,0] and ending at [m-1,n-1].

    \n\n

    The score of a path is the minimum value in that path.  For example, the value of the path 8 →  4 →  5 →  9 is 4.

    \n\n

    A path moves some number of times from one visited cell to any neighbouring unvisited cell in one of the 4 cardinal directions (north, east, west, south).

    \n\n

     

    \n\n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: [[5,4,5],[1,2,6],[7,4,6]]\nOutput: 4\nExplanation: \nThe path with the maximum score is highlighted in yellow. \n
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: [[2,2,1,2,2,2],[1,2,2,2,1,2]]\nOutput: 2
    \n\n

    Example 3:

    \n\n

    \"\"

    \n\n
    \nInput: [[3,4,6,3,4],[0,2,1,1,7],[8,8,3,2,7],[3,2,4,9,8],[4,1,2,0,0],[4,6,5,4,3]]\nOutput: 3
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    1. 1 <= m, n <= 100
    2. \n\t
    3. 0 <= grid[i][j] <= 109
    4. \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a R \u884c C \u5217\u7684\u6574\u6570\u77e9\u9635 A\u3002\u77e9\u9635\u4e0a\u7684\u8def\u5f84\u4ece [0,0] \u5f00\u59cb\uff0c\u5728 [R-1,C-1] \u7ed3\u675f\u3002

    \n\n

    \u8def\u5f84\u6cbf\u56db\u4e2a\u57fa\u672c\u65b9\u5411\uff08\u4e0a\u3001\u4e0b\u3001\u5de6\u3001\u53f3\uff09\u5c55\u5f00\uff0c\u4ece\u4e00\u4e2a\u5df2\u8bbf\u95ee\u5355\u5143\u683c\u79fb\u52a8\u5230\u4efb\u4e00\u76f8\u90bb\u7684\u672a\u8bbf\u95ee\u5355\u5143\u683c\u3002

    \n\n

    \u8def\u5f84\u7684\u5f97\u5206\u662f\u8be5\u8def\u5f84\u4e0a\u7684 \u6700\u5c0f \u503c\u3002\u4f8b\u5982\uff0c\u8def\u5f84 8 →  4 →  5 →  9 \u7684\u503c\u4e3a 4 \u3002

    \n\n

    \u627e\u51fa\u6240\u6709\u8def\u5f84\u4e2d\u5f97\u5206 \u6700\u9ad8 \u7684\u90a3\u6761\u8def\u5f84\uff0c\u8fd4\u56de\u5176 \u5f97\u5206\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1a[[5,4,5],[1,2,6],[7,4,6]]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a \n\u5f97\u5206\u6700\u9ad8\u7684\u8def\u5f84\u7528\u9ec4\u8272\u7a81\u51fa\u663e\u793a\u3002 \n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1a[[2,2,1,2,2,2],[1,2,2,2,1,2]]\n\u8f93\u51fa\uff1a2
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1a[[3,4,6,3,4],[0,2,1,1,7],[8,8,3,2,7],[3,2,4,9,8],[4,1,2,0,0],[4,6,5,4,3]]\n\u8f93\u51fa\uff1a3
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= R, C <= 100
    2. \n\t
    3. 0 <= A[i][j] <= 10^9
    4. \n
    \n", "tags_en": ["Depth-first Search", "Union Find", "Graph"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e76\u67e5\u96c6", "\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maximumMinimumPath(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maximumMinimumPath(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximumMinimumPath(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximumMinimumPath(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maximumMinimumPath(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaximumMinimumPath(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar maximumMinimumPath = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef maximum_minimum_path(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximumMinimumPath(_ grid: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximumMinimumPath(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximumMinimumPath(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximumMinimumPath(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximum_minimum_path(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function maximumMinimumPath($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximumMinimumPath(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximum-minimum-path grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1102](https://leetcode-cn.com/problems/path-with-maximum-minimum-value)", "[\u5f97\u5206\u6700\u9ad8\u7684\u8def\u5f84](/solution/1100-1199/1102.Path%20With%20Maximum%20Minimum%20Value/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e76\u67e5\u96c6`,`\u56fe`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1102](https://leetcode.com/problems/path-with-maximum-minimum-value)", "[Path With Maximum Minimum Value](/solution/1100-1199/1102.Path%20With%20Maximum%20Minimum%20Value/README_EN.md)", "`Depth-first Search`,`Union Find`,`Graph`", "Medium", "\ud83d\udd12"]}, {"question_id": "1098", "frontend_question_id": "1133", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/largest-unique-number", "url_en": "https://leetcode.com/problems/largest-unique-number", "relative_path_cn": "/solution/1100-1199/1133.Largest%20Unique%20Number/README.md", "relative_path_en": "/solution/1100-1199/1133.Largest%20Unique%20Number/README_EN.md", "title_cn": "\u6700\u5927\u552f\u4e00\u6570", "title_en": "Largest Unique Number", "question_title_slug": "largest-unique-number", "content_en": "

    Given an array of integers A, return the largest integer that only occurs once.

    \r\n\r\n

    If no integer occurs once, return -1.

    \r\n\r\n

     

    \r\n\r\n

    Example 1:

    \r\n\r\n
    \r\nInput: [5,7,3,9,4,9,8,3,1]\r\nOutput: 8\r\nExplanation: \r\nThe maximum integer in the array is 9 but it is repeated. The number 8 occurs only once, so it's the answer.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: [9,9,8,8]\r\nOutput: -1\r\nExplanation: \r\nThere is no number that occurs only once.\r\n
    \r\n\r\n

     

    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    1. 1 <= A.length <= 2000
    2. \r\n\t
    3. 0 <= A[i] <= 1000
    4. \r\n
    \r\n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 A\uff0c\u8bf7\u627e\u51fa\u5e76\u8fd4\u56de\u5728\u8be5\u6570\u7ec4\u4e2d\u4ec5\u51fa\u73b0\u4e00\u6b21\u7684\u6700\u5927\u6574\u6570\u3002

    \n\n

    \u5982\u679c\u4e0d\u5b58\u5728\u8fd9\u4e2a\u53ea\u51fa\u73b0\u4e00\u6b21\u7684\u6574\u6570\uff0c\u5219\u8fd4\u56de -1\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a[5,7,3,9,4,9,8,3,1]\n\u8f93\u51fa\uff1a8\n\u89e3\u91ca\uff1a \n\u6570\u7ec4\u4e2d\u6700\u5927\u7684\u6574\u6570\u662f 9\uff0c\u4f46\u5b83\u5728\u6570\u7ec4\u4e2d\u91cd\u590d\u51fa\u73b0\u4e86\u3002\u800c\u7b2c\u4e8c\u5927\u7684\u6574\u6570\u662f 8\uff0c\u5b83\u53ea\u51fa\u73b0\u4e86\u4e00\u6b21\uff0c\u6240\u4ee5\u7b54\u6848\u662f 8\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a[9,9,8,8]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a \n\u6570\u7ec4\u4e2d\u4e0d\u5b58\u5728\u4ec5\u51fa\u73b0\u4e00\u6b21\u7684\u6574\u6570\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= A.length <= 2000
    2. \n\t
    3. 0 <= A[i] <= 1000
    4. \n
    \n", "tags_en": ["Array", "Hash Table"], "tags_cn": ["\u6570\u7ec4", "\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int largestUniqueNumber(vector& A) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int largestUniqueNumber(int[] A) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def largestUniqueNumber(self, A):\n \"\"\"\n :type A: List[int]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def largestUniqueNumber(self, A: List[int]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint largestUniqueNumber(int* A, int ASize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LargestUniqueNumber(int[] A) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} A\n * @return {number}\n */\nvar largestUniqueNumber = function(A) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} a\n# @return {Integer}\ndef largest_unique_number(a)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func largestUniqueNumber(_ A: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func largestUniqueNumber(A []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def largestUniqueNumber(A: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun largestUniqueNumber(A: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn largest_unique_number(a: Vec) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $A\n * @return Integer\n */\n function largestUniqueNumber($A) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function largestUniqueNumber(A: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (largest-unique-number A)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1133](https://leetcode-cn.com/problems/largest-unique-number)", "[\u6700\u5927\u552f\u4e00\u6570](/solution/1100-1199/1133.Largest%20Unique%20Number/README.md)", "`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1133](https://leetcode.com/problems/largest-unique-number)", "[Largest Unique Number](/solution/1100-1199/1133.Largest%20Unique%20Number/README_EN.md)", "`Array`,`Hash Table`", "Easy", "\ud83d\udd12"]}, {"question_id": "1097", "frontend_question_id": "1032", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/stream-of-characters", "url_en": "https://leetcode.com/problems/stream-of-characters", "relative_path_cn": "/solution/1000-1099/1032.Stream%20of%20Characters/README.md", "relative_path_en": "/solution/1000-1099/1032.Stream%20of%20Characters/README_EN.md", "title_cn": "\u5b57\u7b26\u6d41", "title_en": "Stream of Characters", "question_title_slug": "stream-of-characters", "content_en": "

    Implement the StreamChecker class as follows:

    \r\n\r\n
      \r\n\t
    • StreamChecker(words): Constructor, init the data structure with the given words.
    • \r\n\t
    • query(letter): returns true if and only if for some k >= 1, the last k characters queried (in order from oldest to newest, including this letter just queried) spell one of the words in the given list.
    • \r\n
    \r\n\r\n

     

    \r\n\r\n

    Example:

    \r\n\r\n
    \r\nStreamChecker streamChecker = new StreamChecker(["cd","f","kl"]); // init the dictionary.\r\nstreamChecker.query('a');          // return false\r\nstreamChecker.query('b');          // return false\r\nstreamChecker.query('c');          // return false\r\nstreamChecker.query('d');          // return true, because 'cd' is in the wordlist\r\nstreamChecker.query('e');          // return false\r\nstreamChecker.query('f');          // return true, because 'f' is in the wordlist\r\nstreamChecker.query('g');          // return false\r\nstreamChecker.query('h');          // return false\r\nstreamChecker.query('i');          // return false\r\nstreamChecker.query('j');          // return false\r\nstreamChecker.query('k');          // return false\r\nstreamChecker.query('l');          // return true, because 'kl' is in the wordlist\r\n
    \r\n\r\n

     

    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    • 1 <= words.length <= 2000
    • \r\n\t
    • 1 <= words[i].length <= 2000
    • \r\n\t
    • Words will only consist of lowercase English letters.
    • \r\n\t
    • Queries will only consist of lowercase English letters.
    • \r\n\t
    • The number of queries is at most 40000.
    • \r\n
    \r\n", "content_cn": "

    \u6309\u4e0b\u8ff0\u8981\u6c42\u5b9e\u73b0 StreamChecker \u7c7b\uff1a

    \n\n
      \n\t
    • StreamChecker(words)\uff1a\u6784\u9020\u51fd\u6570\uff0c\u7528\u7ed9\u5b9a\u7684\u5b57\u8bcd\u521d\u59cb\u5316\u6570\u636e\u7ed3\u6784\u3002
    • \n\t
    • query(letter)\uff1a\u5982\u679c\u5b58\u5728\u67d0\u4e9b k >= 1\uff0c\u53ef\u4ee5\u7528\u67e5\u8be2\u7684\u6700\u540e k\u4e2a\u5b57\u7b26\uff08\u6309\u4ece\u65e7\u5230\u65b0\u987a\u5e8f\uff0c\u5305\u62ec\u521a\u521a\u67e5\u8be2\u7684\u5b57\u6bcd\uff09\u62fc\u5199\u51fa\u7ed9\u5b9a\u5b57\u8bcd\u8868\u4e2d\u7684\u67d0\u4e00\u5b57\u8bcd\u65f6\uff0c\u8fd4\u56de true\u3002\u5426\u5219\uff0c\u8fd4\u56de false\u3002
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    StreamChecker streamChecker = new StreamChecker(["cd","f","kl"]); // \u521d\u59cb\u5316\u5b57\u5178\nstreamChecker.query('a');          // \u8fd4\u56de false\nstreamChecker.query('b');          // \u8fd4\u56de false\nstreamChecker.query('c');          // \u8fd4\u56de false\nstreamChecker.query('d');          // \u8fd4\u56de true\uff0c\u56e0\u4e3a 'cd' \u5728\u5b57\u8bcd\u8868\u4e2d\nstreamChecker.query('e');          // \u8fd4\u56de false\nstreamChecker.query('f');          // \u8fd4\u56de true\uff0c\u56e0\u4e3a 'f' \u5728\u5b57\u8bcd\u8868\u4e2d\nstreamChecker.query('g');          // \u8fd4\u56de false\nstreamChecker.query('h');          // \u8fd4\u56de false\nstreamChecker.query('i');          // \u8fd4\u56de false\nstreamChecker.query('j');          // \u8fd4\u56de false\nstreamChecker.query('k');          // \u8fd4\u56de false\nstreamChecker.query('l');          // \u8fd4\u56de true\uff0c\u56e0\u4e3a 'kl' \u5728\u5b57\u8bcd\u8868\u4e2d\u3002
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= words.length <= 2000
    • \n\t
    • 1 <= words[i].length <= 2000
    • \n\t
    • \u5b57\u8bcd\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    • \n\t
    • \u5f85\u67e5\u9879\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    • \n\t
    • \u5f85\u67e5\u9879\u6700\u591a 40000 \u4e2a\u3002
    • \n
    \n", "tags_en": ["Trie"], "tags_cn": ["\u5b57\u5178\u6811"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class StreamChecker {\npublic:\n StreamChecker(vector& words) {\n\n }\n \n bool query(char letter) {\n\n }\n};\n\n/**\n * Your StreamChecker object will be instantiated and called as such:\n * StreamChecker* obj = new StreamChecker(words);\n * bool param_1 = obj->query(letter);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class StreamChecker {\n\n public StreamChecker(String[] words) {\n\n }\n \n public boolean query(char letter) {\n\n }\n}\n\n/**\n * Your StreamChecker object will be instantiated and called as such:\n * StreamChecker obj = new StreamChecker(words);\n * boolean param_1 = obj.query(letter);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class StreamChecker(object):\n\n def __init__(self, words):\n \"\"\"\n :type words: List[str]\n \"\"\"\n\n\n def query(self, letter):\n \"\"\"\n :type letter: str\n :rtype: bool\n \"\"\"\n\n\n\n# Your StreamChecker object will be instantiated and called as such:\n# obj = StreamChecker(words)\n# param_1 = obj.query(letter)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class StreamChecker:\n\n def __init__(self, words: List[str]):\n\n\n def query(self, letter: str) -> bool:\n\n\n\n# Your StreamChecker object will be instantiated and called as such:\n# obj = StreamChecker(words)\n# param_1 = obj.query(letter)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} StreamChecker;\n\n\nStreamChecker* streamCheckerCreate(char ** words, int wordsSize) {\n \n}\n\nbool streamCheckerQuery(StreamChecker* obj, char letter) {\n \n}\n\nvoid streamCheckerFree(StreamChecker* obj) {\n \n}\n\n/**\n * Your StreamChecker struct will be instantiated and called as such:\n * StreamChecker* obj = streamCheckerCreate(words, wordsSize);\n * bool param_1 = streamCheckerQuery(obj, letter);\n \n * streamCheckerFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class StreamChecker {\n\n public StreamChecker(string[] words) {\n\n }\n \n public bool Query(char letter) {\n\n }\n}\n\n/**\n * Your StreamChecker object will be instantiated and called as such:\n * StreamChecker obj = new StreamChecker(words);\n * bool param_1 = obj.Query(letter);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n */\nvar StreamChecker = function(words) {\n\n};\n\n/** \n * @param {character} letter\n * @return {boolean}\n */\nStreamChecker.prototype.query = function(letter) {\n\n};\n\n/**\n * Your StreamChecker object will be instantiated and called as such:\n * var obj = new StreamChecker(words)\n * var param_1 = obj.query(letter)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class StreamChecker\n\n=begin\n :type words: String[]\n=end\n def initialize(words)\n\n end\n\n\n=begin\n :type letter: Character\n :rtype: Boolean\n=end\n def query(letter)\n\n end\n\n\nend\n\n# Your StreamChecker object will be instantiated and called as such:\n# obj = StreamChecker.new(words)\n# param_1 = obj.query(letter)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass StreamChecker {\n\n init(_ words: [String]) {\n \n }\n \n func query(_ letter: Character) -> Bool {\n \n }\n}\n\n/**\n * Your StreamChecker object will be instantiated and called as such:\n * let obj = StreamChecker(words)\n * let ret_1: Bool = obj.query(letter)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type StreamChecker struct {\n\n}\n\n\nfunc Constructor(words []string) StreamChecker {\n\n}\n\n\nfunc (this *StreamChecker) Query(letter byte) bool {\n\n}\n\n\n/**\n * Your StreamChecker object will be instantiated and called as such:\n * obj := Constructor(words);\n * param_1 := obj.Query(letter);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class StreamChecker(_words: Array[String]) {\n\n def query(letter: Char): Boolean = {\n\n }\n\n}\n\n/**\n * Your StreamChecker object will be instantiated and called as such:\n * var obj = new StreamChecker(words)\n * var param_1 = obj.query(letter)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class StreamChecker(words: Array) {\n\n fun query(letter: Char): Boolean {\n\n }\n\n}\n\n/**\n * Your StreamChecker object will be instantiated and called as such:\n * var obj = StreamChecker(words)\n * var param_1 = obj.query(letter)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct StreamChecker {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl StreamChecker {\n\n fn new(words: Vec) -> Self {\n\n }\n \n fn query(&self, letter: char) -> bool {\n\n }\n}\n\n/**\n * Your StreamChecker object will be instantiated and called as such:\n * let obj = StreamChecker::new(words);\n * let ret_1: bool = obj.query(letter);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class StreamChecker {\n /**\n * @param String[] $words\n */\n function __construct($words) {\n \n }\n \n /**\n * @param String $letter\n * @return Boolean\n */\n function query($letter) {\n \n }\n}\n\n/**\n * Your StreamChecker object will be instantiated and called as such:\n * $obj = StreamChecker($words);\n * $ret_1 = $obj->query($letter);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class StreamChecker {\n constructor(words: string[]) {\n\n }\n\n query(letter: string): boolean {\n\n }\n}\n\n/**\n * Your StreamChecker object will be instantiated and called as such:\n * var obj = new StreamChecker(words)\n * var param_1 = obj.query(letter)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define stream-checker%\n (class object%\n (super-new)\n\n ; words : (listof string?)\n (init-field\n words)\n \n ; query : char? -> boolean?\n (define/public (query letter)\n\n )))\n\n;; Your stream-checker% object will be instantiated and called as such:\n;; (define obj (new stream-checker% [words words]))\n;; (define param_1 (send obj query letter))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1032](https://leetcode-cn.com/problems/stream-of-characters)", "[\u5b57\u7b26\u6d41](/solution/1000-1099/1032.Stream%20of%20Characters/README.md)", "`\u5b57\u5178\u6811`", "\u56f0\u96be", ""], "md_table_row_en": ["[1032](https://leetcode.com/problems/stream-of-characters)", "[Stream of Characters](/solution/1000-1099/1032.Stream%20of%20Characters/README_EN.md)", "`Trie`", "Hard", ""]}, {"question_id": "1096", "frontend_question_id": "1031", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-sum-of-two-non-overlapping-subarrays", "url_en": "https://leetcode.com/problems/maximum-sum-of-two-non-overlapping-subarrays", "relative_path_cn": "/solution/1000-1099/1031.Maximum%20Sum%20of%20Two%20Non-Overlapping%20Subarrays/README.md", "relative_path_en": "/solution/1000-1099/1031.Maximum%20Sum%20of%20Two%20Non-Overlapping%20Subarrays/README_EN.md", "title_cn": "\u4e24\u4e2a\u975e\u91cd\u53e0\u5b50\u6570\u7ec4\u7684\u6700\u5927\u548c", "title_en": "Maximum Sum of Two Non-Overlapping Subarrays", "question_title_slug": "maximum-sum-of-two-non-overlapping-subarrays", "content_en": "

    Given an array nums of non-negative integers, return the maximum sum of elements in two non-overlapping (contiguous) subarrays, which have lengths firstLen and secondLen.  (For clarification, the firstLen-length subarray could occur before or after the secondLen-length subarray.)

    \n\n

    Formally, return the largest V for which V = (nums[i] + nums[i+1] + ... + nums[i+firstLen-1]) + (nums[j] + nums[j+1] + ... + nums[j+secondLen-1]) and either:

    \n\n
      \n\t
    • 0 <= i < i + firstLen - 1 < j < j + secondLen - 1 < nums.length, or
    • \n\t
    • 0 <= j < j + secondLen - 1 < i < i + firstLen - 1 < nums.length.
    • \n
    \n\n

     

    \n\n
      \n
    \n\n
    \n

    Example 1:

    \n\n
    \nInput: nums = [0,6,5,2,2,5,1,9,4], firstLen = 1, secondLen = 2\nOutput: 20\nExplanation: One choice of subarrays is [9] with length 1, and [6,5] with length 2.\n
    \n\n
    \n

    Example 2:

    \n\n
    \nInput: nums = [3,8,1,3,2,1,8,9,0], firstLen = 3, secondLen = 2\nOutput: 29\nExplanation: One choice of subarrays is [3,8,1] with length 3, and [8,9] with length 2.\n
    \n\n
    \n

    Example 3:

    \n\n
    \nInput: nums = [2,1,5,6,0,9,5,0,3,8], firstLen = 4, secondLen = 3\nOutput: 31\nExplanation: One choice of subarrays is [5,6,0,9] with length 4, and [3,8] with length 3.\n
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    1. firstLen >= 1
    2. \n\t
    3. secondLen >= 1
    4. \n\t
    5. firstLen + secondLen <= nums.length <= 1000
    6. \n\t
    7. 0 <= nums[i] <= 1000
    8. \n
    \n
    \n
    \n
    \n", "content_cn": "

    \u7ed9\u51fa\u975e\u8d1f\u6574\u6570\u6570\u7ec4 A \uff0c\u8fd4\u56de\u4e24\u4e2a\u975e\u91cd\u53e0\uff08\u8fde\u7eed\uff09\u5b50\u6570\u7ec4\u4e2d\u5143\u7d20\u7684\u6700\u5927\u548c\uff0c\u5b50\u6570\u7ec4\u7684\u957f\u5ea6\u5206\u522b\u4e3a L \u548c M\u3002\uff08\u8fd9\u91cc\u9700\u8981\u6f84\u6e05\u7684\u662f\uff0c\u957f\u4e3a L \u7684\u5b50\u6570\u7ec4\u53ef\u4ee5\u51fa\u73b0\u5728\u957f\u4e3a M \u7684\u5b50\u6570\u7ec4\u4e4b\u524d\u6216\u4e4b\u540e\u3002\uff09

    \n\n

    \u4ece\u5f62\u5f0f\u4e0a\u770b\uff0c\u8fd4\u56de\u6700\u5927\u7684 V\uff0c\u800c V = (A[i] + A[i+1] + ... + A[i+L-1]) + (A[j] + A[j+1] + ... + A[j+M-1]) \u5e76\u6ee1\u8db3\u4e0b\u5217\u6761\u4ef6\u4e4b\u4e00\uff1a

    \n\n

     

    \n\n
      \n\t
    • 0 <= i < i + L - 1 < j < j + M - 1 < A.length, \u6216
    • \n\t
    • 0 <= j < j + M - 1 < i < i + L - 1 < A.length.
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aA = [0,6,5,2,2,5,1,9,4], L = 1, M = 2\n\u8f93\u51fa\uff1a20\n\u89e3\u91ca\uff1a\u5b50\u6570\u7ec4\u7684\u4e00\u79cd\u9009\u62e9\u4e2d\uff0c[9] \u957f\u5ea6\u4e3a 1\uff0c[6,5] \u957f\u5ea6\u4e3a 2\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aA = [3,8,1,3,2,1,8,9,0], L = 3, M = 2\n\u8f93\u51fa\uff1a29\n\u89e3\u91ca\uff1a\u5b50\u6570\u7ec4\u7684\u4e00\u79cd\u9009\u62e9\u4e2d\uff0c[3,8,1] \u957f\u5ea6\u4e3a 3\uff0c[8,9] \u957f\u5ea6\u4e3a 2\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aA = [2,1,5,6,0,9,5,0,3,8], L = 4, M = 3\n\u8f93\u51fa\uff1a31\n\u89e3\u91ca\uff1a\u5b50\u6570\u7ec4\u7684\u4e00\u79cd\u9009\u62e9\u4e2d\uff0c[5,6,0,9] \u957f\u5ea6\u4e3a 4\uff0c[0,3,8] \u957f\u5ea6\u4e3a 3\u3002
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. L >= 1
    2. \n\t
    3. M >= 1
    4. \n\t
    5. L + M <= A.length <= 1000
    6. \n\t
    7. 0 <= A[i] <= 1000
    8. \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxSumTwoNoOverlap(vector& nums, int firstLen, int secondLen) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxSumTwoNoOverlap(int[] nums, int firstLen, int secondLen) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxSumTwoNoOverlap(self, nums, firstLen, secondLen):\n \"\"\"\n :type nums: List[int]\n :type firstLen: int\n :type secondLen: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxSumTwoNoOverlap(self, nums: List[int], firstLen: int, secondLen: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxSumTwoNoOverlap(int* nums, int numsSize, int firstLen, int secondLen){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxSumTwoNoOverlap(int[] nums, int firstLen, int secondLen) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} firstLen\n * @param {number} secondLen\n * @return {number}\n */\nvar maxSumTwoNoOverlap = function(nums, firstLen, secondLen) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} first_len\n# @param {Integer} second_len\n# @return {Integer}\ndef max_sum_two_no_overlap(nums, first_len, second_len)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxSumTwoNoOverlap(_ nums: [Int], _ firstLen: Int, _ secondLen: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxSumTwoNoOverlap(nums []int, firstLen int, secondLen int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxSumTwoNoOverlap(nums: Array[Int], firstLen: Int, secondLen: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxSumTwoNoOverlap(nums: IntArray, firstLen: Int, secondLen: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_sum_two_no_overlap(nums: Vec, first_len: i32, second_len: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $firstLen\n * @param Integer $secondLen\n * @return Integer\n */\n function maxSumTwoNoOverlap($nums, $firstLen, $secondLen) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxSumTwoNoOverlap(nums: number[], firstLen: number, secondLen: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-sum-two-no-overlap nums firstLen secondLen)\n (-> (listof exact-integer?) exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1031](https://leetcode-cn.com/problems/maximum-sum-of-two-non-overlapping-subarrays)", "[\u4e24\u4e2a\u975e\u91cd\u53e0\u5b50\u6570\u7ec4\u7684\u6700\u5927\u548c](/solution/1000-1099/1031.Maximum%20Sum%20of%20Two%20Non-Overlapping%20Subarrays/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1031](https://leetcode.com/problems/maximum-sum-of-two-non-overlapping-subarrays)", "[Maximum Sum of Two Non-Overlapping Subarrays](/solution/1000-1099/1031.Maximum%20Sum%20of%20Two%20Non-Overlapping%20Subarrays/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "1095", "frontend_question_id": "1029", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/two-city-scheduling", "url_en": "https://leetcode.com/problems/two-city-scheduling", "relative_path_cn": "/solution/1000-1099/1029.Two%20City%20Scheduling/README.md", "relative_path_en": "/solution/1000-1099/1029.Two%20City%20Scheduling/README_EN.md", "title_cn": "\u4e24\u5730\u8c03\u5ea6", "title_en": "Two City Scheduling", "question_title_slug": "two-city-scheduling", "content_en": "

    A company is planning to interview 2n people. Given the array costs where costs[i] = [aCosti, bCosti], the cost of flying the ith person to city a is aCosti, and the cost of flying the ith person to city b is bCosti.

    \n\n

    Return the minimum cost to fly every person to a city such that exactly n people arrive in each city.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: costs = [[10,20],[30,200],[400,50],[30,20]]\nOutput: 110\nExplanation: \nThe first person goes to city A for a cost of 10.\nThe second person goes to city A for a cost of 30.\nThe third person goes to city B for a cost of 50.\nThe fourth person goes to city B for a cost of 20.\n\nThe total minimum cost is 10 + 30 + 50 + 20 = 110 to have half the people interviewing in each city.\n
    \n\n

    Example 2:

    \n\n
    \nInput: costs = [[259,770],[448,54],[926,667],[184,139],[840,118],[577,469]]\nOutput: 1859\n
    \n\n

    Example 3:

    \n\n
    \nInput: costs = [[515,563],[451,713],[537,709],[343,819],[855,779],[457,60],[650,359],[631,42]]\nOutput: 3086\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 * n == costs.length
    • \n\t
    • 2 <= costs.length <= 100
    • \n\t
    • costs.length is even.
    • \n\t
    • 1 <= aCosti, bCosti <= 1000
    • \n
    \n", "content_cn": "

    \u516c\u53f8\u8ba1\u5212\u9762\u8bd5 2n \u4eba\u3002\u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 costs \uff0c\u5176\u4e2d costs[i] = [aCosti, bCosti] \u3002\u7b2c i \u4eba\u98de\u5f80 a \u5e02\u7684\u8d39\u7528\u4e3a aCosti \uff0c\u98de\u5f80 b \u5e02\u7684\u8d39\u7528\u4e3a bCosti \u3002

    \n\n

    \u8fd4\u56de\u5c06\u6bcf\u4e2a\u4eba\u90fd\u98de\u5230 a \u3001b \u4e2d\u67d0\u5ea7\u57ce\u5e02\u7684\u6700\u4f4e\u8d39\u7528\uff0c\u8981\u6c42\u6bcf\u4e2a\u57ce\u5e02\u90fd\u6709 n \u4eba\u62b5\u8fbe\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1acosts = [[10,20],[30,200],[400,50],[30,20]]\n\u8f93\u51fa\uff1a110\n\u89e3\u91ca\uff1a\n\u7b2c\u4e00\u4e2a\u4eba\u53bb a \u5e02\uff0c\u8d39\u7528\u4e3a 10\u3002\n\u7b2c\u4e8c\u4e2a\u4eba\u53bb a \u5e02\uff0c\u8d39\u7528\u4e3a 30\u3002\n\u7b2c\u4e09\u4e2a\u4eba\u53bb b \u5e02\uff0c\u8d39\u7528\u4e3a 50\u3002\n\u7b2c\u56db\u4e2a\u4eba\u53bb b \u5e02\uff0c\u8d39\u7528\u4e3a 20\u3002\n\n\u6700\u4f4e\u603b\u8d39\u7528\u4e3a 10 + 30 + 50 + 20 = 110\uff0c\u6bcf\u4e2a\u57ce\u5e02\u90fd\u6709\u4e00\u534a\u7684\u4eba\u5728\u9762\u8bd5\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1acosts = [[259,770],[448,54],[926,667],[184,139],[840,118],[577,469]]\n\u8f93\u51fa\uff1a1859\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1acosts = [[515,563],[451,713],[537,709],[343,819],[855,779],[457,60],[650,359],[631,42]]\n\u8f93\u51fa\uff1a3086\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 * n == costs.length
    • \n\t
    • 2 <= costs.length <= 100
    • \n\t
    • costs.length \u4e3a\u5076\u6570
    • \n\t
    • 1 <= aCosti, bCosti <= 1000
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int twoCitySchedCost(vector>& costs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int twoCitySchedCost(int[][] costs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def twoCitySchedCost(self, costs):\n \"\"\"\n :type costs: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def twoCitySchedCost(self, costs: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint twoCitySchedCost(int** costs, int costsSize, int* costsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int TwoCitySchedCost(int[][] costs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} costs\n * @return {number}\n */\nvar twoCitySchedCost = function(costs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} costs\n# @return {Integer}\ndef two_city_sched_cost(costs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func twoCitySchedCost(_ costs: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func twoCitySchedCost(costs [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def twoCitySchedCost(costs: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun twoCitySchedCost(costs: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn two_city_sched_cost(costs: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $costs\n * @return Integer\n */\n function twoCitySchedCost($costs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function twoCitySchedCost(costs: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (two-city-sched-cost costs)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1029](https://leetcode-cn.com/problems/two-city-scheduling)", "[\u4e24\u5730\u8c03\u5ea6](/solution/1000-1099/1029.Two%20City%20Scheduling/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1029](https://leetcode.com/problems/two-city-scheduling)", "[Two City Scheduling](/solution/1000-1099/1029.Two%20City%20Scheduling/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1094", "frontend_question_id": "1030", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/matrix-cells-in-distance-order", "url_en": "https://leetcode.com/problems/matrix-cells-in-distance-order", "relative_path_cn": "/solution/1000-1099/1030.Matrix%20Cells%20in%20Distance%20Order/README.md", "relative_path_en": "/solution/1000-1099/1030.Matrix%20Cells%20in%20Distance%20Order/README_EN.md", "title_cn": "\u8ddd\u79bb\u987a\u5e8f\u6392\u5217\u77e9\u9635\u5355\u5143\u683c", "title_en": "Matrix Cells in Distance Order", "question_title_slug": "matrix-cells-in-distance-order", "content_en": "

    We are given a matrix with rows rows and cols columns has cells with integer coordinates (r, c), where 0 <= r < rows and 0 <= c < cols.

    \n\n

    Additionally, we are given a cell in that matrix with coordinates (rCenter, cCenter).

    \n\n

    Return the coordinates of all cells in the matrix, sorted by their distance from (rCenter, cCenter) from smallest distance to largest distance.  Here, the distance between two cells (r1, c1) and (r2, c2) is the Manhattan distance, |r1 - r2| + |c1 - c2|.  (You may return the answer in any order that satisfies this condition.)

    \n\n

     

    \n\n
    \n

    Example 1:

    \n\n
    \nInput: rows = 1, cols = 2, rCenter = 0, cCenter = 0\nOutput: [[0,0],[0,1]]\nExplanation: The distances from (0, 0) to other cells are: [0,1]\n
    \n\n
    \n

    Example 2:

    \n\n
    \nInput: rows = 2, cols = 2, rCenter = 0, cCenter = 1\nOutput: [[0,1],[0,0],[1,1],[1,0]]\nExplanation: The distances from (0, 1) to other cells are: [0,1,1,2]\nThe answer [[0,1],[1,1],[0,0],[1,0]] would also be accepted as correct.\n
    \n\n
    \n

    Example 3:

    \n\n
    \nInput: rows = 2, cols = 3, rCenter = 1, cCenter = 2\nOutput: [[1,2],[0,2],[1,1],[0,1],[1,0],[0,0]]\nExplanation: The distances from (1, 2) to other cells are: [0,1,1,2,2,3]\nThere are other answers that would also be accepted as correct, such as [[1,2],[1,1],[0,2],[1,0],[0,1],[0,0]].\n
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    1. 1 <= rows <= 100
    2. \n\t
    3. 1 <= cols <= 100
    4. \n\t
    5. 0 <= rCenter < rows
    6. \n\t
    7. 0 <= cCenter < cols
    8. \n
    \n
    \n
    \n
    \n", "content_cn": "

    \u7ed9\u51fa R \u884c C \u5217\u7684\u77e9\u9635\uff0c\u5176\u4e2d\u7684\u5355\u5143\u683c\u7684\u6574\u6570\u5750\u6807\u4e3a (r, c)\uff0c\u6ee1\u8db3 0 <= r < R \u4e14 0 <= c < C\u3002

    \n\n

    \u53e6\u5916\uff0c\u6211\u4eec\u5728\u8be5\u77e9\u9635\u4e2d\u7ed9\u51fa\u4e86\u4e00\u4e2a\u5750\u6807\u4e3a (r0, c0) \u7684\u5355\u5143\u683c\u3002

    \n\n

    \u8fd4\u56de\u77e9\u9635\u4e2d\u7684\u6240\u6709\u5355\u5143\u683c\u7684\u5750\u6807\uff0c\u5e76\u6309\u5230 (r0, c0) \u7684\u8ddd\u79bb\u4ece\u6700\u5c0f\u5230\u6700\u5927\u7684\u987a\u5e8f\u6392\uff0c\u5176\u4e2d\uff0c\u4e24\u5355\u5143\u683c(r1, c1) \u548c (r2, c2) \u4e4b\u95f4\u7684\u8ddd\u79bb\u662f\u66fc\u54c8\u987f\u8ddd\u79bb\uff0c|r1 - r2| + |c1 - c2|\u3002\uff08\u4f60\u53ef\u4ee5\u6309\u4efb\u4f55\u6ee1\u8db3\u6b64\u6761\u4ef6\u7684\u987a\u5e8f\u8fd4\u56de\u7b54\u6848\u3002\uff09

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aR = 1, C = 2, r0 = 0, c0 = 0\n\u8f93\u51fa\uff1a[[0,0],[0,1]]\n\u89e3\u91ca\uff1a\u4ece (r0, c0) \u5230\u5176\u4ed6\u5355\u5143\u683c\u7684\u8ddd\u79bb\u4e3a\uff1a[0,1]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aR = 2, C = 2, r0 = 0, c0 = 1\n\u8f93\u51fa\uff1a[[0,1],[0,0],[1,1],[1,0]]\n\u89e3\u91ca\uff1a\u4ece (r0, c0) \u5230\u5176\u4ed6\u5355\u5143\u683c\u7684\u8ddd\u79bb\u4e3a\uff1a[0,1,1,2]\n[[0,1],[1,1],[0,0],[1,0]] \u4e5f\u4f1a\u88ab\u89c6\u4f5c\u6b63\u786e\u7b54\u6848\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aR = 2, C = 3, r0 = 1, c0 = 2\n\u8f93\u51fa\uff1a[[1,2],[0,2],[1,1],[0,1],[1,0],[0,0]]\n\u89e3\u91ca\uff1a\u4ece (r0, c0) \u5230\u5176\u4ed6\u5355\u5143\u683c\u7684\u8ddd\u79bb\u4e3a\uff1a[0,1,1,2,2,3]\n\u5176\u4ed6\u6ee1\u8db3\u9898\u76ee\u8981\u6c42\u7684\u7b54\u6848\u4e5f\u4f1a\u88ab\u89c6\u4e3a\u6b63\u786e\uff0c\u4f8b\u5982 [[1,2],[1,1],[0,2],[1,0],[0,1],[0,0]]\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= R <= 100
    2. \n\t
    3. 1 <= C <= 100
    4. \n\t
    5. 0 <= r0 < R
    6. \n\t
    7. 0 <= c0 < C
    8. \n
    \n", "tags_en": ["Sort"], "tags_cn": ["\u6392\u5e8f"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> allCellsDistOrder(int rows, int cols, int rCenter, int cCenter) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[][] allCellsDistOrder(int rows, int cols, int rCenter, int cCenter) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def allCellsDistOrder(self, rows, cols, rCenter, cCenter):\n \"\"\"\n :type rows: int\n :type cols: int\n :type rCenter: int\n :type cCenter: int\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def allCellsDistOrder(self, rows: int, cols: int, rCenter: int, cCenter: int) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** allCellsDistOrder(int rows, int cols, int rCenter, int cCenter, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[][] AllCellsDistOrder(int rows, int cols, int rCenter, int cCenter) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} rows\n * @param {number} cols\n * @param {number} rCenter\n * @param {number} cCenter\n * @return {number[][]}\n */\nvar allCellsDistOrder = function(rows, cols, rCenter, cCenter) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} rows\n# @param {Integer} cols\n# @param {Integer} r_center\n# @param {Integer} c_center\n# @return {Integer[][]}\ndef all_cells_dist_order(rows, cols, r_center, c_center)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func allCellsDistOrder(_ rows: Int, _ cols: Int, _ rCenter: Int, _ cCenter: Int) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func allCellsDistOrder(rows int, cols int, rCenter int, cCenter int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def allCellsDistOrder(rows: Int, cols: Int, rCenter: Int, cCenter: Int): Array[Array[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun allCellsDistOrder(rows: Int, cols: Int, rCenter: Int, cCenter: Int): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn all_cells_dist_order(rows: i32, cols: i32, r_center: i32, c_center: i32) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $rows\n * @param Integer $cols\n * @param Integer $rCenter\n * @param Integer $cCenter\n * @return Integer[][]\n */\n function allCellsDistOrder($rows, $cols, $rCenter, $cCenter) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function allCellsDistOrder(rows: number, cols: number, rCenter: number, cCenter: number): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (all-cells-dist-order rows cols rCenter cCenter)\n (-> exact-integer? exact-integer? exact-integer? exact-integer? (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1030](https://leetcode-cn.com/problems/matrix-cells-in-distance-order)", "[\u8ddd\u79bb\u987a\u5e8f\u6392\u5217\u77e9\u9635\u5355\u5143\u683c](/solution/1000-1099/1030.Matrix%20Cells%20in%20Distance%20Order/README.md)", "`\u6392\u5e8f`", "\u7b80\u5355", ""], "md_table_row_en": ["[1030](https://leetcode.com/problems/matrix-cells-in-distance-order)", "[Matrix Cells in Distance Order](/solution/1000-1099/1030.Matrix%20Cells%20in%20Distance%20Order/README_EN.md)", "`Sort`", "Easy", ""]}, {"question_id": "1093", "frontend_question_id": "1028", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/recover-a-tree-from-preorder-traversal", "url_en": "https://leetcode.com/problems/recover-a-tree-from-preorder-traversal", "relative_path_cn": "/solution/1000-1099/1028.Recover%20a%20Tree%20From%20Preorder%20Traversal/README.md", "relative_path_en": "/solution/1000-1099/1028.Recover%20a%20Tree%20From%20Preorder%20Traversal/README_EN.md", "title_cn": "\u4ece\u5148\u5e8f\u904d\u5386\u8fd8\u539f\u4e8c\u53c9\u6811", "title_en": "Recover a Tree From Preorder Traversal", "question_title_slug": "recover-a-tree-from-preorder-traversal", "content_en": "

    We run a preorder depth-first search (DFS) on the root of a binary tree.

    \n\n

    At each node in this traversal, we output D dashes (where D is the depth of this node), then we output the value of this node.  If the depth of a node is D, the depth of its immediate child is D + 1.  The depth of the root node is 0.

    \n\n

    If a node has only one child, that child is guaranteed to be the left child.

    \n\n

    Given the output traversal of this traversal, recover the tree and return its root.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: traversal = "1-2--3--4-5--6--7"\nOutput: [1,2,5,3,4,6,7]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: traversal = "1-2--3---4-5--6---7"\nOutput: [1,2,5,3,null,6,null,4,null,7]\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: traversal = "1-401--349---90--88"\nOutput: [1,401,null,349,88,90]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the original tree is in the range [1, 1000].
    • \n\t
    • 1 <= Node.val <= 109
    • \n
    \n", "content_cn": "

    \u6211\u4eec\u4ece\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9 root \u5f00\u59cb\u8fdb\u884c\u6df1\u5ea6\u4f18\u5148\u641c\u7d22\u3002

    \n\n

    \u5728\u904d\u5386\u4e2d\u7684\u6bcf\u4e2a\u8282\u70b9\u5904\uff0c\u6211\u4eec\u8f93\u51fa D \u6761\u77ed\u5212\u7ebf\uff08\u5176\u4e2d D \u662f\u8be5\u8282\u70b9\u7684\u6df1\u5ea6\uff09\uff0c\u7136\u540e\u8f93\u51fa\u8be5\u8282\u70b9\u7684\u503c\u3002\uff08\u5982\u679c\u8282\u70b9\u7684\u6df1\u5ea6\u4e3a D\uff0c\u5219\u5176\u76f4\u63a5\u5b50\u8282\u70b9\u7684\u6df1\u5ea6\u4e3a D + 1\u3002\u6839\u8282\u70b9\u7684\u6df1\u5ea6\u4e3a 0\uff09\u3002

    \n\n

    \u5982\u679c\u8282\u70b9\u53ea\u6709\u4e00\u4e2a\u5b50\u8282\u70b9\uff0c\u90a3\u4e48\u4fdd\u8bc1\u8be5\u5b50\u8282\u70b9\u4e3a\u5de6\u5b50\u8282\u70b9\u3002

    \n\n

    \u7ed9\u51fa\u904d\u5386\u8f93\u51fa S\uff0c\u8fd8\u539f\u6811\u5e76\u8fd4\u56de\u5176\u6839\u8282\u70b9 root\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1a"1-2--3--4-5--6--7"\n\u8f93\u51fa\uff1a[1,2,5,3,4,6,7]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1a"1-2--3---4-5--6---7"\n\u8f93\u51fa\uff1a[1,2,5,3,null,6,null,4,null,7]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1a"1-401--349---90--88"\n\u8f93\u51fa\uff1a[1,401,null,349,88,90]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u539f\u59cb\u6811\u4e2d\u7684\u8282\u70b9\u6570\u4ecb\u4e8e 1 \u548c 1000 \u4e4b\u95f4\u3002
    • \n\t
    • \u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u4ecb\u4e8e 1 \u548c 10 ^ 9 \u4e4b\u95f4\u3002
    • \n
    \n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* recoverFromPreorder(string traversal) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode recoverFromPreorder(String traversal) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def recoverFromPreorder(self, traversal):\n \"\"\"\n :type traversal: str\n :rtype: TreeNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def recoverFromPreorder(self, traversal: str) -> TreeNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* recoverFromPreorder(char * traversal){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode RecoverFromPreorder(string traversal) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {string} traversal\n * @return {TreeNode}\n */\nvar recoverFromPreorder = function(traversal) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {String} traversal\n# @return {TreeNode}\ndef recover_from_preorder(traversal)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func recoverFromPreorder(_ traversal: String) -> TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc recoverFromPreorder(traversal string) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def recoverFromPreorder(traversal: String): TreeNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun recoverFromPreorder(traversal: String): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn recover_from_preorder(traversal: String) -> Option>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param String $traversal\n * @return TreeNode\n */\n function recoverFromPreorder($traversal) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction recoverFromPreorder(traversal: string): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (recover-from-preorder traversal)\n (-> string? (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1028](https://leetcode-cn.com/problems/recover-a-tree-from-preorder-traversal)", "[\u4ece\u5148\u5e8f\u904d\u5386\u8fd8\u539f\u4e8c\u53c9\u6811](/solution/1000-1099/1028.Recover%20a%20Tree%20From%20Preorder%20Traversal/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[1028](https://leetcode.com/problems/recover-a-tree-from-preorder-traversal)", "[Recover a Tree From Preorder Traversal](/solution/1000-1099/1028.Recover%20a%20Tree%20From%20Preorder%20Traversal/README_EN.md)", "`Tree`,`Depth-first Search`", "Hard", ""]}, {"question_id": "1092", "frontend_question_id": "1026", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-difference-between-node-and-ancestor", "url_en": "https://leetcode.com/problems/maximum-difference-between-node-and-ancestor", "relative_path_cn": "/solution/1000-1099/1026.Maximum%20Difference%20Between%20Node%20and%20Ancestor/README.md", "relative_path_en": "/solution/1000-1099/1026.Maximum%20Difference%20Between%20Node%20and%20Ancestor/README_EN.md", "title_cn": "\u8282\u70b9\u4e0e\u5176\u7956\u5148\u4e4b\u95f4\u7684\u6700\u5927\u5dee\u503c", "title_en": "Maximum Difference Between Node and Ancestor", "question_title_slug": "maximum-difference-between-node-and-ancestor", "content_en": "

    Given the root of a binary tree, find the maximum value V for which there exist different nodes A and B where V = |A.val - B.val| and A is an ancestor of B.

    \n\n

    A node A is an ancestor of B if either: any child of A is equal to B, or any child of A is an ancestor of B.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [8,3,10,1,6,null,14,null,null,4,7,13]\nOutput: 7\nExplanation: We have various ancestor-node differences, some of which are given below :\n|8 - 3| = 5\n|3 - 7| = 4\n|8 - 1| = 7\n|10 - 13| = 3\nAmong all possible differences, the maximum value of 7 is obtained by |8 - 1| = 7.
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [1,null,2,null,0,3]\nOutput: 3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [2, 5000].
    • \n\t
    • 0 <= Node.val <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9\u00a0root\uff0c\u627e\u51fa\u5b58\u5728\u4e8e \u4e0d\u540c \u8282\u70b9\u00a0A \u548c\u00a0B\u00a0\u4e4b\u95f4\u7684\u6700\u5927\u503c V\uff0c\u5176\u4e2d\u00a0V = |A.val - B.val|\uff0c\u4e14\u00a0A\u00a0\u662f\u00a0B\u00a0\u7684\u7956\u5148\u3002

    \n\n

    \uff08\u5982\u679c A \u7684\u4efb\u4f55\u5b50\u8282\u70b9\u4e4b\u4e00\u4e3a B\uff0c\u6216\u8005 A \u7684\u4efb\u4f55\u5b50\u8282\u70b9\u662f B \u7684\u7956\u5148\uff0c\u90a3\u4e48\u6211\u4eec\u8ba4\u4e3a A \u662f B \u7684\u7956\u5148\uff09

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aroot = [8,3,10,1,6,null,14,null,null,4,7,13]\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a \n\u6211\u4eec\u6709\u5927\u91cf\u7684\u8282\u70b9\u4e0e\u5176\u7956\u5148\u7684\u5dee\u503c\uff0c\u5176\u4e2d\u4e00\u4e9b\u5982\u4e0b\uff1a\n|8 - 3| = 5\n|3 - 7| = 4\n|8 - 1| = 7\n|10 - 13| = 3\n\u5728\u6240\u6709\u53ef\u80fd\u7684\u5dee\u503c\u4e2d\uff0c\u6700\u5927\u503c 7 \u7531 |8 - 1| = 7 \u5f97\u51fa\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [1,null,2,null,0,3]\n\u8f93\u51fa\uff1a3\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u7684\u8282\u70b9\u6570\u5728\u00a02\u00a0\u5230\u00a05000\u00a0\u4e4b\u95f4\u3002
    • \n\t
    • 0 <= Node.val <= 105
    • \n
    \n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int maxAncestorDiff(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int maxAncestorDiff(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def maxAncestorDiff(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def maxAncestorDiff(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint maxAncestorDiff(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int MaxAncestorDiff(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar maxAncestorDiff = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef max_ancestor_diff(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func maxAncestorDiff(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc maxAncestorDiff(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def maxAncestorDiff(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun maxAncestorDiff(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn max_ancestor_diff(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function maxAncestorDiff($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction maxAncestorDiff(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (max-ancestor-diff root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1026](https://leetcode-cn.com/problems/maximum-difference-between-node-and-ancestor)", "[\u8282\u70b9\u4e0e\u5176\u7956\u5148\u4e4b\u95f4\u7684\u6700\u5927\u5dee\u503c](/solution/1000-1099/1026.Maximum%20Difference%20Between%20Node%20and%20Ancestor/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1026](https://leetcode.com/problems/maximum-difference-between-node-and-ancestor)", "[Maximum Difference Between Node and Ancestor](/solution/1000-1099/1026.Maximum%20Difference%20Between%20Node%20and%20Ancestor/README_EN.md)", "`Tree`,`Depth-first Search`", "Medium", ""]}, {"question_id": "1091", "frontend_question_id": "1120", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/maximum-average-subtree", "url_en": "https://leetcode.com/problems/maximum-average-subtree", "relative_path_cn": "/solution/1100-1199/1120.Maximum%20Average%20Subtree/README.md", "relative_path_en": "/solution/1100-1199/1120.Maximum%20Average%20Subtree/README_EN.md", "title_cn": "\u5b50\u6811\u7684\u6700\u5927\u5e73\u5747\u503c", "title_en": "Maximum Average Subtree", "question_title_slug": "maximum-average-subtree", "content_en": "

    Given the root of a binary tree, find the maximum average value of any subtree of that tree.

    \n\n

    (A subtree of a tree is any node of that tree plus all its descendants. The average value of a tree is the sum of its values, divided by the number of nodes.)

    \n\n

     

    \n\n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: [5,6,1]\nOutput: 6.00000\nExplanation: \nFor the node with value = 5 we have an average of (5 + 6 + 1) / 3 = 4.\nFor the node with value = 6 we have an average of 6 / 1 = 6.\nFor the node with value = 1 we have an average of 1 / 1 = 1.\nSo the answer is 6 which is the maximum.\n
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    1. The number of nodes in the tree is between 1 and 5000.
    2. \n\t
    3. Each node will have a value between 0 and 100000.
    4. \n\t
    5. Answers will be accepted as correct if they are within 10^-5 of the correct answer.
    6. \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u68f5\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9 root\uff0c\u627e\u51fa\u8fd9\u68f5\u6811\u7684 \u6bcf\u4e00\u68f5 \u5b50\u6811\u7684 \u5e73\u5747\u503c \u4e2d\u7684 \u6700\u5927 \u503c\u3002

    \n\n

    \u5b50\u6811\u662f\u6811\u4e2d\u7684\u4efb\u610f\u8282\u70b9\u548c\u5b83\u7684\u6240\u6709\u540e\u4ee3\u6784\u6210\u7684\u96c6\u5408\u3002

    \n\n

    \u6811\u7684\u5e73\u5747\u503c\u662f\u6811\u4e2d\u8282\u70b9\u503c\u7684\u603b\u548c\u9664\u4ee5\u8282\u70b9\u6570\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1a[5,6,1]\n\u8f93\u51fa\uff1a6.00000\n\u89e3\u91ca\uff1a \n\u4ee5 value = 5 \u7684\u8282\u70b9\u4f5c\u4e3a\u5b50\u6811\u7684\u6839\u8282\u70b9\uff0c\u5f97\u5230\u7684\u5e73\u5747\u503c\u4e3a (5 + 6 + 1) / 3 = 4\u3002\n\u4ee5 value = 6 \u7684\u8282\u70b9\u4f5c\u4e3a\u5b50\u6811\u7684\u6839\u8282\u70b9\uff0c\u5f97\u5230\u7684\u5e73\u5747\u503c\u4e3a 6 / 1 = 6\u3002\n\u4ee5 value = 1 \u7684\u8282\u70b9\u4f5c\u4e3a\u5b50\u6811\u7684\u6839\u8282\u70b9\uff0c\u5f97\u5230\u7684\u5e73\u5747\u503c\u4e3a 1 / 1 = 1\u3002\n\u6240\u4ee5\u7b54\u6848\u53d6\u6700\u5927\u503c 6\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. \u6811\u4e2d\u7684\u8282\u70b9\u6570\u4ecb\u4e8e 1 \u5230 5000\u4e4b\u95f4\u3002
    2. \n\t
    3. \u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u4ecb\u4e8e 0 \u5230 100000 \u4e4b\u95f4\u3002
    4. \n\t
    5. \u5982\u679c\u7ed3\u679c\u4e0e\u6807\u51c6\u7b54\u6848\u7684\u8bef\u5dee\u4e0d\u8d85\u8fc7 10^-5\uff0c\u90a3\u4e48\u8be5\u7ed3\u679c\u5c06\u88ab\u89c6\u4e3a\u6b63\u786e\u7b54\u6848\u3002
    6. \n
    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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 */\nclass Solution {\npublic:\n double maximumAverageSubtree(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode(int x) { val = x; }\n * }\n */\nclass Solution {\n public double maximumAverageSubtree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution(object):\n def maximumAverageSubtree(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: float\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution:\n def maximumAverageSubtree(self, root: TreeNode) -> float:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\ndouble maximumAverageSubtree(struct TreeNode* root){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int x) { val = x; }\n * }\n */\npublic class Solution {\n public double MaximumAverageSubtree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val) {\n * this.val = val;\n * this.left = this.right = null;\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar maximumAverageSubtree = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val)\n# @val = val\n# @left, @right = nil, nil\n# end\n# end\n\n# @param {TreeNode} root\n# @return {Float}\ndef maximum_average_subtree(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.left = nil\n * self.right = nil\n * }\n * }\n */\nclass Solution {\n func maximumAverageSubtree(_ root: TreeNode?) -> Double {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc maximumAverageSubtree(root *TreeNode) float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(var _value: Int) {\n * var value: Int = _value\n * var left: TreeNode = null\n * var right: TreeNode = null\n * }\n */\nobject Solution {\n def maximumAverageSubtree(root: TreeNode): Double = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun maximumAverageSubtree(root: TreeNode?): Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n// \n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn maximum_average_subtree(root: Option>>) -> f64 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($value) { $this->val = $value; }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Float\n */\n function maximumAverageSubtree($root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction maximumAverageSubtree(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (maximum-average-subtree root)\n (-> (or/c tree-node? #f) flonum?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1120](https://leetcode-cn.com/problems/maximum-average-subtree)", "[\u5b50\u6811\u7684\u6700\u5927\u5e73\u5747\u503c](/solution/1100-1199/1120.Maximum%20Average%20Subtree/README.md)", "`\u6811`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1120](https://leetcode.com/problems/maximum-average-subtree)", "[Maximum Average Subtree](/solution/1100-1199/1120.Maximum%20Average%20Subtree/README_EN.md)", "`Tree`", "Medium", "\ud83d\udd12"]}, {"question_id": "1090", "frontend_question_id": "1134", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/armstrong-number", "url_en": "https://leetcode.com/problems/armstrong-number", "relative_path_cn": "/solution/1100-1199/1134.Armstrong%20Number/README.md", "relative_path_en": "/solution/1100-1199/1134.Armstrong%20Number/README_EN.md", "title_cn": "\u963f\u59c6\u65af\u7279\u6717\u6570", "title_en": "Armstrong Number", "question_title_slug": "armstrong-number", "content_en": "

    Given an integer n, return true if and only if it is an Armstrong number.

    \n\n

    The k-digit number n is an Armstrong number if and only if the kth power of each digit sums to n.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 153\nOutput: true\nExplanation: 153 is a 3-digit number, and 153 = 13 + 53 + 33.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 123\nOutput: false\nExplanation: 123 is a 3-digit number, and 123 != 13 + 23 + 33 = 36.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 108
    • \n
    \n", "content_cn": "

    \u5047\u8bbe\u5b58\u5728\u4e00\u4e2a k \u4f4d\u6570 N\uff0c\u5176\u6bcf\u4e00\u4f4d\u4e0a\u7684\u6570\u5b57\u7684 k \u6b21\u5e42\u7684\u603b\u548c\u4e5f\u662f N\uff0c\u90a3\u4e48\u8fd9\u4e2a\u6570\u662f\u963f\u59c6\u65af\u7279\u6717\u6570\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6b63\u6574\u6570 N\uff0c\u8ba9\u4f60\u6765\u5224\u5b9a\u4ed6\u662f\u5426\u662f\u963f\u59c6\u65af\u7279\u6717\u6570\uff0c\u662f\u5219\u8fd4\u56de true\uff0c\u4e0d\u662f\u5219\u8fd4\u56de false\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a153\n\u8f93\u51fa\uff1atrue\n\u793a\u4f8b\uff1a \n153 \u662f\u4e00\u4e2a 3 \u4f4d\u6570\uff0c\u4e14 153 = 1^3 + 5^3 + 3^3\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a123\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a \n123 \u662f\u4e00\u4e2a 3 \u4f4d\u6570\uff0c\u4e14 123 != 1^3 + 2^3 + 3^3 = 36\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= N <= 10^8
    2. \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isArmstrong(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isArmstrong(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isArmstrong(self, n):\n \"\"\"\n :type n: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isArmstrong(self, n: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isArmstrong(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsArmstrong(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {boolean}\n */\nvar isArmstrong = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Boolean}\ndef is_armstrong(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isArmstrong(_ n: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isArmstrong(n int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isArmstrong(n: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isArmstrong(n: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_armstrong(n: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Boolean\n */\n function isArmstrong($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isArmstrong(n: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-armstrong n)\n (-> exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1134](https://leetcode-cn.com/problems/armstrong-number)", "[\u963f\u59c6\u65af\u7279\u6717\u6570](/solution/1100-1199/1134.Armstrong%20Number/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1134](https://leetcode.com/problems/armstrong-number)", "[Armstrong Number](/solution/1100-1199/1134.Armstrong%20Number/README_EN.md)", "`Math`", "Easy", "\ud83d\udd12"]}, {"question_id": "1089", "frontend_question_id": "1119", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/remove-vowels-from-a-string", "url_en": "https://leetcode.com/problems/remove-vowels-from-a-string", "relative_path_cn": "/solution/1100-1199/1119.Remove%20Vowels%20from%20a%20String/README.md", "relative_path_en": "/solution/1100-1199/1119.Remove%20Vowels%20from%20a%20String/README_EN.md", "title_cn": "\u5220\u53bb\u5b57\u7b26\u4e32\u4e2d\u7684\u5143\u97f3", "title_en": "Remove Vowels from a String", "question_title_slug": "remove-vowels-from-a-string", "content_en": "

    Given a string s, remove the vowels 'a', 'e', 'i', 'o', and 'u' from it, and return the new string.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "leetcodeisacommunityforcoders"\nOutput: "ltcdscmmntyfrcdrs"\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "aeiou"\nOutput: ""\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 1000
    • \n\t
    • s consists of only lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 S\uff0c\u8bf7\u4f60\u5220\u53bb\u5176\u4e2d\u7684\u6240\u6709\u5143\u97f3\u5b57\u6bcd\uff08 'a'\uff0c'e'\uff0c'i'\uff0c'o'\uff0c'u'\uff09\uff0c\u5e76\u8fd4\u56de\u8fd9\u4e2a\u65b0\u5b57\u7b26\u4e32\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a"leetcodeisacommunityforcoders"\n\u8f93\u51fa\uff1a"ltcdscmmntyfrcdrs"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a"aeiou"\n\u8f93\u51fa\uff1a""\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. S \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\u3002
    2. \n\t
    3. 1 <= S.length <= 1000
    4. \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string removeVowels(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String removeVowels(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def removeVowels(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def removeVowels(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * removeVowels(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string RemoveVowels(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar removeVowels = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef remove_vowels(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func removeVowels(_ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func removeVowels(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def removeVowels(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun removeVowels(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn remove_vowels(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function removeVowels($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function removeVowels(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (remove-vowels s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1119](https://leetcode-cn.com/problems/remove-vowels-from-a-string)", "[\u5220\u53bb\u5b57\u7b26\u4e32\u4e2d\u7684\u5143\u97f3](/solution/1100-1199/1119.Remove%20Vowels%20from%20a%20String/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1119](https://leetcode.com/problems/remove-vowels-from-a-string)", "[Remove Vowels from a String](/solution/1100-1199/1119.Remove%20Vowels%20from%20a%20String/README_EN.md)", "`String`", "Easy", "\ud83d\udd12"]}, {"question_id": "1088", "frontend_question_id": "1118", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/number-of-days-in-a-month", "url_en": "https://leetcode.com/problems/number-of-days-in-a-month", "relative_path_cn": "/solution/1100-1199/1118.Number%20of%20Days%20in%20a%20Month/README.md", "relative_path_en": "/solution/1100-1199/1118.Number%20of%20Days%20in%20a%20Month/README_EN.md", "title_cn": "\u4e00\u6708\u6709\u591a\u5c11\u5929", "title_en": "Number of Days in a Month", "question_title_slug": "number-of-days-in-a-month", "content_en": "

    Given a year Y and a month M, return how many days there are in that month.

    \r\n\r\n

     

    \r\n\r\n

    Example 1:

    \r\n\r\n
    \r\nInput: Y = 1992, M = 7\r\nOutput: 31\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: Y = 2000, M = 2\r\nOutput: 29\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: Y = 1900, M = 2\r\nOutput: 28\r\n
    \r\n\r\n

     

    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    1. 1583 <= Y <= 2100
    2. \r\n\t
    3. 1 <= M <= 12
    4. \r\n
    \r\n", "content_cn": "

    \u6307\u5b9a\u5e74\u4efd Y \u548c\u6708\u4efd M\uff0c\u8bf7\u4f60\u5e2e\u5fd9\u8ba1\u7b97\u51fa\u8be5\u6708\u4e00\u5171\u6709\u591a\u5c11\u5929\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aY = 1992, M = 7\n\u8f93\u51fa\uff1a31\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aY = 2000, M = 2\n\u8f93\u51fa\uff1a29\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aY = 1900, M = 2\n\u8f93\u51fa\uff1a28\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1583 <= Y <= 2100
    2. \n\t
    3. 1 <= M <= 12
    4. \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numberOfDays(int Y, int M) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numberOfDays(int Y, int M) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numberOfDays(self, Y, M):\n \"\"\"\n :type Y: int\n :type M: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numberOfDays(self, Y: int, M: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numberOfDays(int Y, int M){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumberOfDays(int Y, int M) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} Y\n * @param {number} M\n * @return {number}\n */\nvar numberOfDays = function(Y, M) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} y\n# @param {Integer} m\n# @return {Integer}\ndef number_of_days(y, m)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numberOfDays(_ Y: Int, _ M: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numberOfDays(Y int, M int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numberOfDays(Y: Int, M: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numberOfDays(Y: Int, M: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn number_of_days(y: i32, m: i32) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $Y\n * @param Integer $M\n * @return Integer\n */\n function numberOfDays($Y, $M) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numberOfDays(Y: number, M: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (number-of-days Y M)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1118](https://leetcode-cn.com/problems/number-of-days-in-a-month)", "[\u4e00\u6708\u6709\u591a\u5c11\u5929](/solution/1100-1199/1118.Number%20of%20Days%20in%20a%20Month/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1118](https://leetcode.com/problems/number-of-days-in-a-month)", "[Number of Days in a Month](/solution/1100-1199/1118.Number%20of%20Days%20in%20a%20Month/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "1087", "frontend_question_id": "1027", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-arithmetic-subsequence", "url_en": "https://leetcode.com/problems/longest-arithmetic-subsequence", "relative_path_cn": "/solution/1000-1099/1027.Longest%20Arithmetic%20Subsequence/README.md", "relative_path_en": "/solution/1000-1099/1027.Longest%20Arithmetic%20Subsequence/README_EN.md", "title_cn": "\u6700\u957f\u7b49\u5dee\u6570\u5217", "title_en": "Longest Arithmetic Subsequence", "question_title_slug": "longest-arithmetic-subsequence", "content_en": "

    Given an array nums of integers, return the length of the longest arithmetic subsequence in nums.

    \n\n

    Recall that a subsequence of an array nums is a list nums[i1], nums[i2], ..., nums[ik] with 0 <= i1 < i2 < ... < ik <= nums.length - 1, and that a sequence seq is arithmetic if seq[i+1] - seq[i] are all the same value (for 0 <= i < seq.length - 1).

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [3,6,9,12]\nOutput: 4\nExplanation: \nThe whole array is an arithmetic sequence with steps of length = 3.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [9,4,7,2,10]\nOutput: 3\nExplanation: \nThe longest arithmetic subsequence is [4,7,10].\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [20,1,15,3,10,5,8]\nOutput: 4\nExplanation: \nThe longest arithmetic subsequence is [20,15,10,5].\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= nums.length <= 1000
    • \n\t
    • 0 <= nums[i] <= 500
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 A\uff0c\u8fd4\u56de A \u4e2d\u6700\u957f\u7b49\u5dee\u5b50\u5e8f\u5217\u7684\u957f\u5ea6\u3002

    \n\n

    \u56de\u60f3\u4e00\u4e0b\uff0cA \u7684\u5b50\u5e8f\u5217\u662f\u5217\u8868 A[i_1], A[i_2], ..., A[i_k] \u5176\u4e2d 0 <= i_1 < i_2 < ... < i_k <= A.length - 1\u3002\u5e76\u4e14\u5982\u679c B[i+1] - B[i]0 <= i < B.length - 1) \u7684\u503c\u90fd\u76f8\u540c\uff0c\u90a3\u4e48\u5e8f\u5217 B \u662f\u7b49\u5dee\u7684\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a[3,6,9,12]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a \n\u6574\u4e2a\u6570\u7ec4\u662f\u516c\u5dee\u4e3a 3 \u7684\u7b49\u5dee\u6570\u5217\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a[9,4,7,2,10]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\n\u6700\u957f\u7684\u7b49\u5dee\u5b50\u5e8f\u5217\u662f [4,7,10]\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1a[20,1,15,3,10,5,8]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\n\u6700\u957f\u7684\u7b49\u5dee\u5b50\u5e8f\u5217\u662f [20,15,10,5]\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 2 <= A.length <= 2000
    2. \n\t
    3. 0 <= A[i] <= 10000
    4. \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int longestArithSeqLength(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int longestArithSeqLength(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestArithSeqLength(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestArithSeqLength(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint longestArithSeqLength(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LongestArithSeqLength(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar longestArithSeqLength = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef longest_arith_seq_length(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestArithSeqLength(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestArithSeqLength(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestArithSeqLength(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestArithSeqLength(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_arith_seq_length(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function longestArithSeqLength($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestArithSeqLength(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-arith-seq-length nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1027](https://leetcode-cn.com/problems/longest-arithmetic-subsequence)", "[\u6700\u957f\u7b49\u5dee\u6570\u5217](/solution/1000-1099/1027.Longest%20Arithmetic%20Subsequence/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1027](https://leetcode.com/problems/longest-arithmetic-subsequence)", "[Longest Arithmetic Subsequence](/solution/1000-1099/1027.Longest%20Arithmetic%20Subsequence/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "1086", "frontend_question_id": "1025", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/divisor-game", "url_en": "https://leetcode.com/problems/divisor-game", "relative_path_cn": "/solution/1000-1099/1025.Divisor%20Game/README.md", "relative_path_en": "/solution/1000-1099/1025.Divisor%20Game/README_EN.md", "title_cn": "\u9664\u6570\u535a\u5f08", "title_en": "Divisor Game", "question_title_slug": "divisor-game", "content_en": "

    Alice and Bob take turns playing a game, with Alice starting first.

    \n\n

    Initially, there is a number n on the chalkboard. On each player's turn, that player makes a move consisting of:

    \n\n
      \n\t
    • Choosing any x with 0 < x < n and n % x == 0.
    • \n\t
    • Replacing the number n on the chalkboard with n - x.
    • \n
    \n\n

    Also, if a player cannot make a move, they lose the game.

    \n\n

    Return true if and only if Alice wins the game, assuming both players play optimally.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 2\nOutput: true\nExplanation: Alice chooses 1, and Bob has no more moves.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 3\nOutput: false\nExplanation: Alice chooses 1, Bob chooses 1, and Alice has no more moves.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 1000
    • \n
    \n", "content_cn": "

    \u7231\u4e3d\u4e1d\u548c\u9c8d\u52c3\u4e00\u8d77\u73a9\u6e38\u620f\uff0c\u4ed6\u4eec\u8f6e\u6d41\u884c\u52a8\u3002\u7231\u4e3d\u4e1d\u5148\u624b\u5f00\u5c40\u3002

    \n\n

    \u6700\u521d\uff0c\u9ed1\u677f\u4e0a\u6709\u4e00\u4e2a\u6570\u5b57 N \u3002\u5728\u6bcf\u4e2a\u73a9\u5bb6\u7684\u56de\u5408\uff0c\u73a9\u5bb6\u9700\u8981\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\uff1a

    \n\n
      \n\t
    • \u9009\u51fa\u4efb\u4e00 x\uff0c\u6ee1\u8db3 0 < x < N \u4e14 N % x == 0 \u3002
    • \n\t
    • \u7528 N - x \u66ff\u6362\u9ed1\u677f\u4e0a\u7684\u6570\u5b57 N \u3002
    • \n
    \n\n

    \u5982\u679c\u73a9\u5bb6\u65e0\u6cd5\u6267\u884c\u8fd9\u4e9b\u64cd\u4f5c\uff0c\u5c31\u4f1a\u8f93\u6389\u6e38\u620f\u3002

    \n\n

    \u53ea\u6709\u5728\u7231\u4e3d\u4e1d\u5728\u6e38\u620f\u4e2d\u53d6\u5f97\u80dc\u5229\u65f6\u624d\u8fd4\u56de True\uff0c\u5426\u5219\u8fd4\u56de False\u3002\u5047\u8bbe\u4e24\u4e2a\u73a9\u5bb6\u90fd\u4ee5\u6700\u4f73\u72b6\u6001\u53c2\u4e0e\u6e38\u620f\u3002

    \n\n

     

    \n\n
      \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a2\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u7231\u4e3d\u4e1d\u9009\u62e9 1\uff0c\u9c8d\u52c3\u65e0\u6cd5\u8fdb\u884c\u64cd\u4f5c\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a3\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u7231\u4e3d\u4e1d\u9009\u62e9 1\uff0c\u9c8d\u52c3\u4e5f\u9009\u62e9 1\uff0c\u7136\u540e\u7231\u4e3d\u4e1d\u65e0\u6cd5\u8fdb\u884c\u64cd\u4f5c\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= N <= 1000
    2. \n
    \n", "tags_en": ["Math", "Dynamic Programming"], "tags_cn": ["\u6570\u5b66", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool divisorGame(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean divisorGame(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def divisorGame(self, n):\n \"\"\"\n :type n: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def divisorGame(self, n: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool divisorGame(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool DivisorGame(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {boolean}\n */\nvar divisorGame = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Boolean}\ndef divisor_game(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func divisorGame(_ n: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func divisorGame(n int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def divisorGame(n: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun divisorGame(n: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn divisor_game(n: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Boolean\n */\n function divisorGame($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function divisorGame(n: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (divisor-game n)\n (-> exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1025](https://leetcode-cn.com/problems/divisor-game)", "[\u9664\u6570\u535a\u5f08](/solution/1000-1099/1025.Divisor%20Game/README.md)", "`\u6570\u5b66`,`\u52a8\u6001\u89c4\u5212`", "\u7b80\u5355", ""], "md_table_row_en": ["[1025](https://leetcode.com/problems/divisor-game)", "[Divisor Game](/solution/1000-1099/1025.Divisor%20Game/README_EN.md)", "`Math`,`Dynamic Programming`", "Easy", ""]}, {"question_id": "1085", "frontend_question_id": "1101", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/the-earliest-moment-when-everyone-become-friends", "url_en": "https://leetcode.com/problems/the-earliest-moment-when-everyone-become-friends", "relative_path_cn": "/solution/1100-1199/1101.The%20Earliest%20Moment%20When%20Everyone%20Become%20Friends/README.md", "relative_path_en": "/solution/1100-1199/1101.The%20Earliest%20Moment%20When%20Everyone%20Become%20Friends/README_EN.md", "title_cn": "\u5f7c\u6b64\u719f\u8bc6\u7684\u6700\u65e9\u65f6\u95f4", "title_en": "The Earliest Moment When Everyone Become Friends", "question_title_slug": "the-earliest-moment-when-everyone-become-friends", "content_en": "

    In a social group, there are n people, with unique integer ids from 0 to n-1.

    \n\n

    We have a list of logs, where each logs[i] = [timestamp, id_A, id_B] contains a non-negative integer timestamp, and the ids of two different people.

    \n\n

    Each log represents the time in which two different people became friends.  Friendship is symmetric: if A is friends with B, then B is friends with A.

    \n\n

    Let's say that person A is acquainted with person B if A is friends with B, or A is a friend of someone acquainted with B.

    \n\n

    Return the earliest time for which every person became acquainted with every other person. Return -1 if there is no such earliest time.

    \n\n

     

    \n\n

    Example 1:

    \n\n
    \nInput: logs = [[20190101,0,1],[20190104,3,4],[20190107,2,3],[20190211,1,5],[20190224,2,4],[20190301,0,3],[20190312,1,2],[20190322,4,5]], n = 6\nOutput: 20190301\nExplanation: \nThe first event occurs at timestamp = 20190101 and after 0 and 1 become friends we have the following friendship groups [0,1], [2], [3], [4], [5].\nThe second event occurs at timestamp = 20190104 and after 3 and 4 become friends we have the following friendship groups [0,1], [2], [3,4], [5].\nThe third event occurs at timestamp = 20190107 and after 2 and 3 become friends we have the following friendship groups [0,1], [2,3,4], [5].\nThe fourth event occurs at timestamp = 20190211 and after 1 and 5 become friends we have the following friendship groups [0,1,5], [2,3,4].\nThe fifth event occurs at timestamp = 20190224 and as 2 and 4 are already friend anything happens.\nThe sixth event occurs at timestamp = 20190301 and after 0 and 3 become friends we have that all become friends.\n
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    1. 2 <= n <= 100
    2. \n\t
    3. 1 <= logs.length <= 104
    4. \n\t
    5. 0 <= logs[i][0] <= 109
    6. \n\t
    7. 0 <= logs[i][1], logs[i][2] <= n - 1
    8. \n\t
    9. It's guaranteed that all timestamps in logs[i][0] are different.
    10. \n\t
    11. logs are not necessarily ordered by some criteria.
    12. \n\t
    13. logs[i][1] != logs[i][2]
    14. \n
    \n", "content_cn": "

    \u5728\u4e00\u4e2a\u793e\u4ea4\u5708\u5b50\u5f53\u4e2d\uff0c\u6709 N \u4e2a\u4eba\u3002\u6bcf\u4e2a\u4eba\u90fd\u6709\u4e00\u4e2a\u4ece 0 \u5230 N-1 \u552f\u4e00\u7684 id \u7f16\u53f7\u3002

    \n\n

    \u6211\u4eec\u6709\u4e00\u4efd\u65e5\u5fd7\u5217\u8868 logs\uff0c\u5176\u4e2d\u6bcf\u6761\u8bb0\u5f55\u90fd\u5305\u542b\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\u7684\u65f6\u95f4\u6233\uff0c\u4ee5\u53ca\u5206\u5c5e\u4e24\u4e2a\u4eba\u7684\u4e0d\u540c id\uff0clogs[i] = [timestamp, id_A, id_B]\u3002

    \n\n

    \u6bcf\u6761\u65e5\u5fd7\u6807\u8bc6\u51fa\u4e24\u4e2a\u4eba\u6210\u4e3a\u597d\u53cb\u7684\u65f6\u95f4\uff0c\u53cb\u8c0a\u662f\u76f8\u4e92\u7684\uff1a\u5982\u679c A \u548c B \u662f\u597d\u53cb\uff0c\u90a3\u4e48 B \u548c A \u4e5f\u662f\u597d\u53cb\u3002

    \n\n

    \u5982\u679c A \u662f B \u7684\u597d\u53cb\uff0c\u6216\u8005 A \u662f B \u7684\u597d\u53cb\u7684\u597d\u53cb\uff0c\u90a3\u4e48\u5c31\u53ef\u4ee5\u8ba4\u4e3a A \u4e5f\u4e0e B \u719f\u8bc6\u3002

    \n\n

    \u8fd4\u56de\u5708\u5b50\u91cc\u6240\u6709\u4eba\u4e4b\u95f4\u90fd\u719f\u8bc6\u7684\u6700\u65e9\u65f6\u95f4\u3002\u5982\u679c\u627e\u4e0d\u5230\u6700\u65e9\u65f6\u95f4\uff0c\u5c31\u8fd4\u56de -1 \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1alogs = [[20190101,0,1],[20190104,3,4],[20190107,2,3],[20190211,1,5],[20190224,2,4],[20190301,0,3],[20190312,1,2],[20190322,4,5]], N = 6\n\u8f93\u51fa\uff1a20190301\n\u89e3\u91ca\uff1a\n\u7b2c\u4e00\u6b21\u7ed3\u4ea4\u53d1\u751f\u5728 timestamp = 20190101\uff0c0 \u548c 1 \u6210\u4e3a\u597d\u53cb\uff0c\u793e\u4ea4\u670b\u53cb\u5708\u5982\u4e0b [0,1], [2], [3], [4], [5]\u3002\n\u7b2c\u4e8c\u6b21\u7ed3\u4ea4\u53d1\u751f\u5728 timestamp = 20190104\uff0c3 \u548c 4 \u6210\u4e3a\u597d\u53cb\uff0c\u793e\u4ea4\u670b\u53cb\u5708\u5982\u4e0b [0,1], [2], [3,4], [5].\n\u7b2c\u4e09\u6b21\u7ed3\u4ea4\u53d1\u751f\u5728 timestamp = 20190107\uff0c2 \u548c 3 \u6210\u4e3a\u597d\u53cb\uff0c\u793e\u4ea4\u670b\u53cb\u5708\u5982\u4e0b [0,1], [2,3,4], [5].\n\u7b2c\u56db\u6b21\u7ed3\u4ea4\u53d1\u751f\u5728 timestamp = 20190211\uff0c1 \u548c 5 \u6210\u4e3a\u597d\u53cb\uff0c\u793e\u4ea4\u670b\u53cb\u5708\u5982\u4e0b [0,1,5], [2,3,4].\n\u7b2c\u4e94\u6b21\u7ed3\u4ea4\u53d1\u751f\u5728 timestamp = 20190224\uff0c2 \u548c 4 \u5df2\u7ecf\u662f\u597d\u53cb\u4e86\u3002\n\u7b2c\u516d\u6b21\u7ed3\u4ea4\u53d1\u751f\u5728 timestamp = 20190301\uff0c0 \u548c 3 \u6210\u4e3a\u597d\u53cb\uff0c\u5927\u5bb6\u90fd\u4e92\u76f8\u719f\u8bc6\u4e86\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= N <= 100
    2. \n\t
    3. 1 <= logs.length <= 10^4
    4. \n\t
    5. 0 <= logs[i][0] <= 10^9
    6. \n\t
    7. 0 <= logs[i][1], logs[i][2] <= N - 1
    8. \n\t
    9. \u4fdd\u8bc1 logs[i][0] \u4e2d\u7684\u6240\u6709\u65f6\u95f4\u6233\u90fd\u4e0d\u540c
    10. \n\t
    11. Logs \u4e0d\u4e00\u5b9a\u6309\u67d0\u4e00\u6807\u51c6\u6392\u5e8f
    12. \n\t
    13. logs[i][1] != logs[i][2]
    14. \n
    \n", "tags_en": ["Union Find"], "tags_cn": ["\u5e76\u67e5\u96c6"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int earliestAcq(vector>& logs, int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int earliestAcq(int[][] logs, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def earliestAcq(self, logs, n):\n \"\"\"\n :type logs: List[List[int]]\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def earliestAcq(self, logs: List[List[int]], n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint earliestAcq(int** logs, int logsSize, int* logsColSize, int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int EarliestAcq(int[][] logs, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} logs\n * @param {number} n\n * @return {number}\n */\nvar earliestAcq = function(logs, n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} logs\n# @param {Integer} n\n# @return {Integer}\ndef earliest_acq(logs, n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func earliestAcq(_ logs: [[Int]], _ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func earliestAcq(logs [][]int, n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def earliestAcq(logs: Array[Array[Int]], n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun earliestAcq(logs: Array, n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn earliest_acq(logs: Vec>, n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $logs\n * @param Integer $n\n * @return Integer\n */\n function earliestAcq($logs, $n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function earliestAcq(logs: number[][], n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (earliest-acq logs n)\n (-> (listof (listof exact-integer?)) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1101](https://leetcode-cn.com/problems/the-earliest-moment-when-everyone-become-friends)", "[\u5f7c\u6b64\u719f\u8bc6\u7684\u6700\u65e9\u65f6\u95f4](/solution/1100-1199/1101.The%20Earliest%20Moment%20When%20Everyone%20Become%20Friends/README.md)", "`\u5e76\u67e5\u96c6`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1101](https://leetcode.com/problems/the-earliest-moment-when-everyone-become-friends)", "[The Earliest Moment When Everyone Become Friends](/solution/1100-1199/1101.The%20Earliest%20Moment%20When%20Everyone%20Become%20Friends/README_EN.md)", "`Union Find`", "Medium", "\ud83d\udd12"]}, {"question_id": "1084", "frontend_question_id": "1100", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/find-k-length-substrings-with-no-repeated-characters", "url_en": "https://leetcode.com/problems/find-k-length-substrings-with-no-repeated-characters", "relative_path_cn": "/solution/1100-1199/1100.Find%20K-Length%20Substrings%20With%20No%20Repeated%20Characters/README.md", "relative_path_en": "/solution/1100-1199/1100.Find%20K-Length%20Substrings%20With%20No%20Repeated%20Characters/README_EN.md", "title_cn": "\u957f\u5ea6\u4e3a K \u7684\u65e0\u91cd\u590d\u5b57\u7b26\u5b50\u4e32", "title_en": "Find K-Length Substrings With No Repeated Characters", "question_title_slug": "find-k-length-substrings-with-no-repeated-characters", "content_en": "

    Given a string s, return the number of substrings of length k with no repeated characters.

    \n\n

     

    \n\n

    Example 1:

    \n\n
    \nInput: s = "havefunonleetcode", k = 5\nOutput: 6\nExplanation: \nThere are 6 substrings they are : 'havef','avefu','vefun','efuno','etcod','tcode'.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "home", k = 5\nOutput: 0\nExplanation: \nNotice k can be larger than the length of s. In this case is not possible to find any substring.\n
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    1. 1 <= s.length <= 104
    2. \n\t
    3. All characters of s are lowercase English letters.
    4. \n\t
    5. 1 <= k <= 104
    6. \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 S\uff0c\u627e\u51fa\u6240\u6709\u957f\u5ea6\u4e3a K \u4e14\u4e0d\u542b\u91cd\u590d\u5b57\u7b26\u7684\u5b50\u4e32\uff0c\u8bf7\u4f60\u8fd4\u56de\u5168\u90e8\u6ee1\u8db3\u8981\u6c42\u7684\u5b50\u4e32\u7684 \u6570\u76ee\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aS = "havefunonleetcode", K = 5\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\n\u8fd9\u91cc\u6709 6 \u4e2a\u6ee1\u8db3\u9898\u610f\u7684\u5b50\u4e32\uff0c\u5206\u522b\u662f\uff1a'havef','avefu','vefun','efuno','etcod','tcode'\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aS = "home", K = 5\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\n\u6ce8\u610f\uff1aK \u53ef\u80fd\u4f1a\u5927\u4e8e S \u7684\u957f\u5ea6\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u5c31\u65e0\u6cd5\u627e\u5230\u4efb\u4f55\u957f\u5ea6\u4e3a K \u7684\u5b50\u4e32\u3002
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= S.length <= 10^4
    2. \n\t
    3. S \u4e2d\u7684\u6240\u6709\u5b57\u7b26\u5747\u4e3a\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd
    4. \n\t
    5. 1 <= K <= 10^4
    6. \n
    \n", "tags_en": ["String", "Sliding Window"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numKLenSubstrNoRepeats(string s, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numKLenSubstrNoRepeats(String s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numKLenSubstrNoRepeats(self, s, k):\n \"\"\"\n :type s: str\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numKLenSubstrNoRepeats(self, s: str, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numKLenSubstrNoRepeats(char * s, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumKLenSubstrNoRepeats(string s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number} k\n * @return {number}\n */\nvar numKLenSubstrNoRepeats = function(s, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer} k\n# @return {Integer}\ndef num_k_len_substr_no_repeats(s, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numKLenSubstrNoRepeats(_ s: String, _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numKLenSubstrNoRepeats(s string, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numKLenSubstrNoRepeats(s: String, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numKLenSubstrNoRepeats(s: String, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_k_len_substr_no_repeats(s: String, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer $k\n * @return Integer\n */\n function numKLenSubstrNoRepeats($s, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numKLenSubstrNoRepeats(s: string, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-k-len-substr-no-repeats s k)\n (-> string? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1100](https://leetcode-cn.com/problems/find-k-length-substrings-with-no-repeated-characters)", "[\u957f\u5ea6\u4e3a K \u7684\u65e0\u91cd\u590d\u5b57\u7b26\u5b50\u4e32](/solution/1100-1199/1100.Find%20K-Length%20Substrings%20With%20No%20Repeated%20Characters/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1100](https://leetcode.com/problems/find-k-length-substrings-with-no-repeated-characters)", "[Find K-Length Substrings With No Repeated Characters](/solution/1100-1199/1100.Find%20K-Length%20Substrings%20With%20No%20Repeated%20Characters/README_EN.md)", "`String`,`Sliding Window`", "Medium", "\ud83d\udd12"]}, {"question_id": "1083", "frontend_question_id": "1099", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/two-sum-less-than-k", "url_en": "https://leetcode.com/problems/two-sum-less-than-k", "relative_path_cn": "/solution/1000-1099/1099.Two%20Sum%20Less%20Than%20K/README.md", "relative_path_en": "/solution/1000-1099/1099.Two%20Sum%20Less%20Than%20K/README_EN.md", "title_cn": "\u5c0f\u4e8e K \u7684\u4e24\u6570\u4e4b\u548c", "title_en": "Two Sum Less Than K", "question_title_slug": "two-sum-less-than-k", "content_en": "

    Given an array nums of integers and integer k, return the maximum sum such that there exists i < j with nums[i] + nums[j] = sum and sum < k. If no i, j exist satisfying this equation, return -1.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [34,23,1,24,75,33,54,8], k = 60\nOutput: 58\nExplanation: We can use 34 and 24 to sum 58 which is less than 60.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [10,20,30], k = 15\nOutput: -1\nExplanation: In this case it is not possible to get a pair sum less that 15.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 100
    • \n\t
    • 1 <= nums[i] <= 1000
    • \n\t
    • 1 <= k <= 2000
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \u548c\u6574\u6570 k \uff0c\u8fd4\u56de\u6700\u5927\u548c sum \uff0c\u6ee1\u8db3\u5b58\u5728 i < j \u4f7f\u5f97 nums[i] + nums[j] = sum \u4e14 sum < k \u3002\u5982\u679c\u6ca1\u6709\u6ee1\u8db3\u6b64\u7b49\u5f0f\u7684 i,j \u5b58\u5728\uff0c\u5219\u8fd4\u56de -1 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [34,23,1,24,75,33,54,8], k = 60\n\u8f93\u51fa\uff1a58\n\u89e3\u91ca\uff1a\n34 \u548c 24 \u76f8\u52a0\u5f97\u5230 58\uff0c58 \u5c0f\u4e8e 60\uff0c\u6ee1\u8db3\u9898\u610f\u3002\n
    \n\n

    \u793a\u4f8b\u00a02\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [10,20,30], k = 15\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\n\u6211\u4eec\u65e0\u6cd5\u627e\u5230\u548c\u5c0f\u4e8e 15 \u7684\u4e24\u4e2a\u5143\u7d20\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 100
    • \n\t
    • 1 <= nums[i] <= 1000
    • \n\t
    • 1 <= k <= 2000
    • \n
    \n", "tags_en": ["Sort", "Array", "Two Pointers"], "tags_cn": ["\u6392\u5e8f", "\u6570\u7ec4", "\u53cc\u6307\u9488"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int twoSumLessThanK(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int twoSumLessThanK(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def twoSumLessThanK(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def twoSumLessThanK(self, nums: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint twoSumLessThanK(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int TwoSumLessThanK(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar twoSumLessThanK = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef two_sum_less_than_k(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func twoSumLessThanK(_ nums: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func twoSumLessThanK(nums []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def twoSumLessThanK(nums: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun twoSumLessThanK(nums: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn two_sum_less_than_k(nums: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer\n */\n function twoSumLessThanK($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function twoSumLessThanK(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (two-sum-less-than-k nums k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1099](https://leetcode-cn.com/problems/two-sum-less-than-k)", "[\u5c0f\u4e8e K \u7684\u4e24\u6570\u4e4b\u548c](/solution/1000-1099/1099.Two%20Sum%20Less%20Than%20K/README.md)", "`\u6392\u5e8f`,`\u6570\u7ec4`,`\u53cc\u6307\u9488`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1099](https://leetcode.com/problems/two-sum-less-than-k)", "[Two Sum Less Than K](/solution/1000-1099/1099.Two%20Sum%20Less%20Than%20K/README_EN.md)", "`Sort`,`Array`,`Two Pointers`", "Easy", "\ud83d\udd12"]}, {"question_id": "1082", "frontend_question_id": "1085", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/sum-of-digits-in-the-minimum-number", "url_en": "https://leetcode.com/problems/sum-of-digits-in-the-minimum-number", "relative_path_cn": "/solution/1000-1099/1085.Sum%20of%20Digits%20in%20the%20Minimum%20Number/README.md", "relative_path_en": "/solution/1000-1099/1085.Sum%20of%20Digits%20in%20the%20Minimum%20Number/README_EN.md", "title_cn": "\u6700\u5c0f\u5143\u7d20\u5404\u6570\u4f4d\u4e4b\u548c", "title_en": "Sum of Digits in the Minimum Number", "question_title_slug": "sum-of-digits-in-the-minimum-number", "content_en": "

    Given an array nums of positive integers, let minDigitSum be the sum of the digits of the minimal element of nums.

    \n\n

    Return 0 if minDigitSum is odd, otherwise return 1.

    \n\n

     

    \n\n

    Example 1:

    \n\n
    \nInput: nums = [34,23,1,24,75,33,54,8]\nOutput: 0\nExplanation: \nThe minimal element is 1, and the sum of those digits is minDigitSum = 1 which is odd, so the answer is 0.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [99,77,33,66,55]\nOutput: 1\nExplanation: \nThe minimal element is 33, and the sum of those digits is minDigitSum = 3 + 3 = 6 which is even, so the answer is 1.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 100
    • \n\t
    • 1 <= nums[i] <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6b63\u6574\u6570\u7684\u6570\u7ec4\u00a0A\u3002

    \n\n

    \u7136\u540e\u8ba1\u7b97\u00a0S\uff0c\u4f7f\u5176\u7b49\u4e8e\u6570\u7ec4\u00a0A\u00a0\u5f53\u4e2d\u6700\u5c0f\u7684\u90a3\u4e2a\u5143\u7d20\u5404\u4e2a\u6570\u4f4d\u4e0a\u6570\u5b57\u4e4b\u548c\u3002

    \n\n

    \u6700\u540e\uff0c\u5047\u5982\u00a0S\u00a0\u6240\u5f97\u8ba1\u7b97\u7ed3\u679c\u662f\u00a0\u5947\u6570 \uff0c\u8fd4\u56de 0 \uff1b\u5426\u5219\u8bf7\u8fd4\u56de 1\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165\uff1a[34,23,1,24,75,33,54,8]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\n\u6700\u5c0f\u5143\u7d20\u4e3a 1 \uff0c\u8be5\u5143\u7d20\u5404\u4e2a\u6570\u4f4d\u4e0a\u7684\u6570\u5b57\u4e4b\u548c S = 1 \uff0c\u662f\u5947\u6570\u6240\u4ee5\u7b54\u6848\u4e3a 0 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[99,77,33,66,55]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\n\u6700\u5c0f\u5143\u7d20\u4e3a 33 \uff0c\u8be5\u5143\u7d20\u5404\u4e2a\u6570\u4f4d\u4e0a\u7684\u6570\u5b57\u4e4b\u548c S = 3 + 3 = 6 \uff0c\u662f\u5076\u6570\u6240\u4ee5\u7b54\u6848\u4e3a 1 \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= A.length <= 100
    • \n\t
    • 1 <= A[i] <= 100
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int sumOfDigits(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int sumOfDigits(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def sumOfDigits(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def sumOfDigits(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint sumOfDigits(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SumOfDigits(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar sumOfDigits = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef sum_of_digits(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func sumOfDigits(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func sumOfDigits(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def sumOfDigits(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun sumOfDigits(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sum_of_digits(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function sumOfDigits($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function sumOfDigits(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (sum-of-digits nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1085](https://leetcode-cn.com/problems/sum-of-digits-in-the-minimum-number)", "[\u6700\u5c0f\u5143\u7d20\u5404\u6570\u4f4d\u4e4b\u548c](/solution/1000-1099/1085.Sum%20of%20Digits%20in%20the%20Minimum%20Number/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1085](https://leetcode.com/problems/sum-of-digits-in-the-minimum-number)", "[Sum of Digits in the Minimum Number](/solution/1000-1099/1085.Sum%20of%20Digits%20in%20the%20Minimum%20Number/README_EN.md)", "`Array`", "Easy", "\ud83d\udd12"]}, {"question_id": "1081", "frontend_question_id": "1024", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/video-stitching", "url_en": "https://leetcode.com/problems/video-stitching", "relative_path_cn": "/solution/1000-1099/1024.Video%20Stitching/README.md", "relative_path_en": "/solution/1000-1099/1024.Video%20Stitching/README_EN.md", "title_cn": "\u89c6\u9891\u62fc\u63a5", "title_en": "Video Stitching", "question_title_slug": "video-stitching", "content_en": "

    You are given a series of video clips from a sporting event that lasted time seconds. These video clips can be overlapping with each other and have varying lengths.

    \n\n

    Each video clip is described by an array clips where clips[i] = [starti, endi] indicates that the ith clip started at starti and ended at endi.

    \n\n

    We can cut these clips into segments freely.

    \n\n
      \n\t
    • For example, a clip [0, 7] can be cut into segments [0, 1] + [1, 3] + [3, 7].
    • \n
    \n\n

    Return the minimum number of clips needed so that we can cut the clips into segments that cover the entire sporting event [0, time]. If the task is impossible, return -1.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: clips = [[0,2],[4,6],[8,10],[1,9],[1,5],[5,9]], time = 10\nOutput: 3\nExplanation: \nWe take the clips [0,2], [8,10], [1,9]; a total of 3 clips.\nThen, we can reconstruct the sporting event as follows:\nWe cut [1,9] into segments [1,2] + [2,8] + [8,9].\nNow we have segments [0,2] + [2,8] + [8,10] which cover the sporting event [0, 10].\n
    \n\n

    Example 2:

    \n\n
    \nInput: clips = [[0,1],[1,2]], time = 5\nOutput: -1\nExplanation: We can't cover [0,5] with only [0,1] and [1,2].\n
    \n\n

    Example 3:

    \n\n
    \nInput: clips = [[0,1],[6,8],[0,2],[5,6],[0,4],[0,3],[6,7],[1,3],[4,7],[1,4],[2,5],[2,6],[3,4],[4,5],[5,7],[6,9]], time = 9\nOutput: 3\nExplanation: We can take clips [0,4], [4,7], and [6,9].\n
    \n\n

    Example 4:

    \n\n
    \nInput: clips = [[0,4],[2,8]], time = 5\nOutput: 2\nExplanation: Notice you can have extra video after the event ends.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= clips.length <= 100
    • \n\t
    • 0 <= clips[i][0] <= clips[i][1] <= 100
    • \n\t
    • 1 <= time <= 100
    • \n
    \n", "content_cn": "

    \u4f60\u5c06\u4f1a\u83b7\u5f97\u4e00\u7cfb\u5217\u89c6\u9891\u7247\u6bb5\uff0c\u8fd9\u4e9b\u7247\u6bb5\u6765\u81ea\u4e8e\u4e00\u9879\u6301\u7eed\u65f6\u957f\u4e3a\u00a0T\u00a0\u79d2\u7684\u4f53\u80b2\u8d5b\u4e8b\u3002\u8fd9\u4e9b\u7247\u6bb5\u53ef\u80fd\u6709\u6240\u91cd\u53e0\uff0c\u4e5f\u53ef\u80fd\u957f\u5ea6\u4e0d\u4e00\u3002

    \n\n

    \u89c6\u9891\u7247\u6bb5\u00a0clips[i]\u00a0\u90fd\u7528\u533a\u95f4\u8fdb\u884c\u8868\u793a\uff1a\u5f00\u59cb\u4e8e\u00a0clips[i][0]\u00a0\u5e76\u4e8e\u00a0clips[i][1]\u00a0\u7ed3\u675f\u3002\u6211\u4eec\u751a\u81f3\u53ef\u4ee5\u5bf9\u8fd9\u4e9b\u7247\u6bb5\u81ea\u7531\u5730\u518d\u526a\u8f91\uff0c\u4f8b\u5982\u7247\u6bb5\u00a0[0, 7]\u00a0\u53ef\u4ee5\u526a\u5207\u6210\u00a0[0, 1] +\u00a0[1, 3] + [3, 7]\u00a0\u4e09\u90e8\u5206\u3002

    \n\n

    \u6211\u4eec\u9700\u8981\u5c06\u8fd9\u4e9b\u7247\u6bb5\u8fdb\u884c\u518d\u526a\u8f91\uff0c\u5e76\u5c06\u526a\u8f91\u540e\u7684\u5185\u5bb9\u62fc\u63a5\u6210\u8986\u76d6\u6574\u4e2a\u8fd0\u52a8\u8fc7\u7a0b\u7684\u7247\u6bb5\uff08[0, T]\uff09\u3002\u8fd4\u56de\u6240\u9700\u7247\u6bb5\u7684\u6700\u5c0f\u6570\u76ee\uff0c\u5982\u679c\u65e0\u6cd5\u5b8c\u6210\u8be5\u4efb\u52a1\uff0c\u5219\u8fd4\u56de\u00a0-1 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aclips = [[0,2],[4,6],[8,10],[1,9],[1,5],[5,9]], T = 10\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\n\u6211\u4eec\u9009\u4e2d [0,2], [8,10], [1,9] \u8fd9\u4e09\u4e2a\u7247\u6bb5\u3002\n\u7136\u540e\uff0c\u6309\u4e0b\u9762\u7684\u65b9\u6848\u91cd\u5236\u6bd4\u8d5b\u7247\u6bb5\uff1a\n\u5c06 [1,9] \u518d\u526a\u8f91\u4e3a [1,2] + [2,8] + [8,9] \u3002\n\u73b0\u5728\u6211\u4eec\u624b\u4e0a\u6709 [0,2] + [2,8] + [8,10]\uff0c\u800c\u8fd9\u4e9b\u6db5\u76d6\u4e86\u6574\u573a\u6bd4\u8d5b [0, 10]\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aclips = [[0,1],[1,2]], T = 5\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\n\u6211\u4eec\u65e0\u6cd5\u53ea\u7528 [0,1] \u548c [1,2] \u8986\u76d6 [0,5] \u7684\u6574\u4e2a\u8fc7\u7a0b\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aclips = [[0,1],[6,8],[0,2],[5,6],[0,4],[0,3],[6,7],[1,3],[4,7],[1,4],[2,5],[2,6],[3,4],[4,5],[5,7],[6,9]], T = 9\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a \n\u6211\u4eec\u9009\u53d6\u7247\u6bb5 [0,4], [4,7] \u548c [6,9] \u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1aclips = [[0,4],[2,8]], T = 5\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n\u6ce8\u610f\uff0c\u4f60\u53ef\u80fd\u5f55\u5236\u8d85\u8fc7\u6bd4\u8d5b\u7ed3\u675f\u65f6\u95f4\u7684\u89c6\u9891\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= clips.length <= 100
    • \n\t
    • 0 <= clips[i][0] <=\u00a0clips[i][1] <= 100
    • \n\t
    • 0 <= T <= 100
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int videoStitching(vector>& clips, int time) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int videoStitching(int[][] clips, int time) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def videoStitching(self, clips, time):\n \"\"\"\n :type clips: List[List[int]]\n :type time: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def videoStitching(self, clips: List[List[int]], time: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint videoStitching(int** clips, int clipsSize, int* clipsColSize, int time){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int VideoStitching(int[][] clips, int time) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} clips\n * @param {number} time\n * @return {number}\n */\nvar videoStitching = function(clips, time) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} clips\n# @param {Integer} time\n# @return {Integer}\ndef video_stitching(clips, time)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func videoStitching(_ clips: [[Int]], _ time: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func videoStitching(clips [][]int, time int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def videoStitching(clips: Array[Array[Int]], time: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun videoStitching(clips: Array, time: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn video_stitching(clips: Vec>, time: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $clips\n * @param Integer $time\n * @return Integer\n */\n function videoStitching($clips, $time) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function videoStitching(clips: number[][], time: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (video-stitching clips time)\n (-> (listof (listof exact-integer?)) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1024](https://leetcode-cn.com/problems/video-stitching)", "[\u89c6\u9891\u62fc\u63a5](/solution/1000-1099/1024.Video%20Stitching/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1024](https://leetcode.com/problems/video-stitching)", "[Video Stitching](/solution/1000-1099/1024.Video%20Stitching/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "1080", "frontend_question_id": "1023", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/camelcase-matching", "url_en": "https://leetcode.com/problems/camelcase-matching", "relative_path_cn": "/solution/1000-1099/1023.Camelcase%20Matching/README.md", "relative_path_en": "/solution/1000-1099/1023.Camelcase%20Matching/README_EN.md", "title_cn": "\u9a7c\u5cf0\u5f0f\u5339\u914d", "title_en": "Camelcase Matching", "question_title_slug": "camelcase-matching", "content_en": "

    A query word matches a given pattern if we can insert lowercase letters to the pattern word so that it equals the query. (We may insert each character at any position, and may insert 0 characters.)

    \r\n\r\n

    Given a list of queries, and a pattern, return an answer list of booleans, where answer[i] is true if and only if queries[i] matches the pattern.

    \r\n\r\n

     

    \r\n\r\n

    Example 1:

    \r\n\r\n
    \r\nInput: queries = ["FooBar","FooBarTest","FootBall","FrameBuffer","ForceFeedBack"], pattern = "FB"\r\nOutput: [true,false,true,true,false]\r\nExplanation: \r\n"FooBar" can be generated like this "F" + "oo" + "B" + "ar".\r\n"FootBall" can be generated like this "F" + "oot" + "B" + "all".\r\n"FrameBuffer" can be generated like this "F" + "rame" + "B" + "uffer".
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: queries = ["FooBar","FooBarTest","FootBall","FrameBuffer","ForceFeedBack"], pattern = "FoBa"\r\nOutput: [true,false,true,false,false]\r\nExplanation: \r\n"FooBar" can be generated like this "Fo" + "o" + "Ba" + "r".\r\n"FootBall" can be generated like this "Fo" + "ot" + "Ba" + "ll".\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: queries = ["FooBar","FooBarTest","FootBall","FrameBuffer","ForceFeedBack"], pattern = "FoBaT"\r\nOutput: [false,true,false,false,false]\r\nExplanation: \r\n"FooBarTest" can be generated like this "Fo" + "o" + "Ba" + "r" + "T" + "est".\r\n
    \r\n\r\n

     

    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    1. 1 <= queries.length <= 100
    2. \r\n\t
    3. 1 <= queries[i].length <= 100
    4. \r\n\t
    5. 1 <= pattern.length <= 100
    6. \r\n\t
    7. All strings consists only of lower and upper case English letters.
    8. \r\n
    \r\n", "content_cn": "

    \u5982\u679c\u6211\u4eec\u53ef\u4ee5\u5c06\u5c0f\u5199\u5b57\u6bcd\u63d2\u5165\u6a21\u5f0f\u4e32 pattern \u5f97\u5230\u5f85\u67e5\u8be2\u9879 query\uff0c\u90a3\u4e48\u5f85\u67e5\u8be2\u9879\u4e0e\u7ed9\u5b9a\u6a21\u5f0f\u4e32\u5339\u914d\u3002\uff08\u6211\u4eec\u53ef\u4ee5\u5728\u4efb\u4f55\u4f4d\u7f6e\u63d2\u5165\u6bcf\u4e2a\u5b57\u7b26\uff0c\u4e5f\u53ef\u4ee5\u63d2\u5165 0 \u4e2a\u5b57\u7b26\u3002\uff09

    \n\n

    \u7ed9\u5b9a\u5f85\u67e5\u8be2\u5217\u8868 queries\uff0c\u548c\u6a21\u5f0f\u4e32 pattern\uff0c\u8fd4\u56de\u7531\u5e03\u5c14\u503c\u7ec4\u6210\u7684\u7b54\u6848\u5217\u8868 answer\u3002\u53ea\u6709\u5728\u5f85\u67e5\u9879 queries[i] \u4e0e\u6a21\u5f0f\u4e32 pattern \u5339\u914d\u65f6\uff0c answer[i] \u624d\u4e3a true\uff0c\u5426\u5219\u4e3a false\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aqueries = ["FooBar","FooBarTest","FootBall","FrameBuffer","ForceFeedBack"], pattern = "FB"\n\u8f93\u51fa\uff1a[true,false,true,true,false]\n\u793a\u4f8b\uff1a\n"FooBar" \u53ef\u4ee5\u8fd9\u6837\u751f\u6210\uff1a"F" + "oo" + "B" + "ar"\u3002\n"FootBall" \u53ef\u4ee5\u8fd9\u6837\u751f\u6210\uff1a"F" + "oot" + "B" + "all".\n"FrameBuffer" \u53ef\u4ee5\u8fd9\u6837\u751f\u6210\uff1a"F" + "rame" + "B" + "uffer".
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aqueries = ["FooBar","FooBarTest","FootBall","FrameBuffer","ForceFeedBack"], pattern = "FoBa"\n\u8f93\u51fa\uff1a[true,false,true,false,false]\n\u89e3\u91ca\uff1a\n"FooBar" \u53ef\u4ee5\u8fd9\u6837\u751f\u6210\uff1a"Fo" + "o" + "Ba" + "r".\n"FootBall" \u53ef\u4ee5\u8fd9\u6837\u751f\u6210\uff1a"Fo" + "ot" + "Ba" + "ll".\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u51fa\uff1aqueries = ["FooBar","FooBarTest","FootBall","FrameBuffer","ForceFeedBack"], pattern = "FoBaT"\n\u8f93\u5165\uff1a[false,true,false,false,false]\n\u89e3\u91ca\uff1a \n"FooBarTest" \u53ef\u4ee5\u8fd9\u6837\u751f\u6210\uff1a"Fo" + "o" + "Ba" + "r" + "T" + "est".\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= queries.length <= 100
    2. \n\t
    3. 1 <= queries[i].length <= 100
    4. \n\t
    5. 1 <= pattern.length <= 100
    6. \n\t
    7. \u6240\u6709\u5b57\u7b26\u4e32\u90fd\u4ec5\u7531\u5927\u5199\u548c\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\u3002
    8. \n
    \n", "tags_en": ["Trie", "String"], "tags_cn": ["\u5b57\u5178\u6811", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector camelMatch(vector& queries, string pattern) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List camelMatch(String[] queries, String pattern) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def camelMatch(self, queries, pattern):\n \"\"\"\n :type queries: List[str]\n :type pattern: str\n :rtype: List[bool]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def camelMatch(self, queries: List[str], pattern: str) -> List[bool]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nbool* camelMatch(char ** queries, int queriesSize, char * pattern, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList CamelMatch(string[] queries, string pattern) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} queries\n * @param {string} pattern\n * @return {boolean[]}\n */\nvar camelMatch = function(queries, pattern) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} queries\n# @param {String} pattern\n# @return {Boolean[]}\ndef camel_match(queries, pattern)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func camelMatch(_ queries: [String], _ pattern: String) -> [Bool] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func camelMatch(queries []string, pattern string) []bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def camelMatch(queries: Array[String], pattern: String): Array[Boolean] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun camelMatch(queries: Array, pattern: String): BooleanArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn camel_match(queries: Vec, pattern: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $queries\n * @param String $pattern\n * @return Boolean[]\n */\n function camelMatch($queries, $pattern) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function camelMatch(queries: string[], pattern: string): boolean[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (camel-match queries pattern)\n (-> (listof string?) string? (listof boolean?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1023](https://leetcode-cn.com/problems/camelcase-matching)", "[\u9a7c\u5cf0\u5f0f\u5339\u914d](/solution/1000-1099/1023.Camelcase%20Matching/README.md)", "`\u5b57\u5178\u6811`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1023](https://leetcode.com/problems/camelcase-matching)", "[Camelcase Matching](/solution/1000-1099/1023.Camelcase%20Matching/README_EN.md)", "`Trie`,`String`", "Medium", ""]}, {"question_id": "1079", "frontend_question_id": "1022", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sum-of-root-to-leaf-binary-numbers", "url_en": "https://leetcode.com/problems/sum-of-root-to-leaf-binary-numbers", "relative_path_cn": "/solution/1000-1099/1022.Sum%20of%20Root%20To%20Leaf%20Binary%20Numbers/README.md", "relative_path_en": "/solution/1000-1099/1022.Sum%20of%20Root%20To%20Leaf%20Binary%20Numbers/README_EN.md", "title_cn": "\u4ece\u6839\u5230\u53f6\u7684\u4e8c\u8fdb\u5236\u6570\u4e4b\u548c", "title_en": "Sum of Root To Leaf Binary Numbers", "question_title_slug": "sum-of-root-to-leaf-binary-numbers", "content_en": "

    You are given the root of a binary tree where each node has a value 0 or 1.  Each root-to-leaf path represents a binary number starting with the most significant bit.  For example, if the path is 0 -> 1 -> 1 -> 0 -> 1, then this could represent 01101 in binary, which is 13.

    \n\n

    For all leaves in the tree, consider the numbers represented by the path from the root to that leaf.

    \n\n

    Return the sum of these numbers. The answer is guaranteed to fit in a 32-bits integer.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,0,1,0,1,0,1]\nOutput: 22\nExplanation: (100) + (101) + (110) + (111) = 4 + 5 + 6 + 7 = 22\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = [0]\nOutput: 0\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = [1]\nOutput: 1\n
    \n\n

    Example 4:

    \n\n
    \nInput: root = [1,1]\nOutput: 3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 1000].
    • \n\t
    • Node.val is 0 or 1.
    • \n
    \n", "content_cn": "

    \u7ed9\u51fa\u4e00\u68f5\u4e8c\u53c9\u6811\uff0c\u5176\u4e0a\u6bcf\u4e2a\u7ed3\u70b9\u7684\u503c\u90fd\u662f\u00a00\u00a0\u6216\u00a01\u00a0\u3002\u6bcf\u4e00\u6761\u4ece\u6839\u5230\u53f6\u7684\u8def\u5f84\u90fd\u4ee3\u8868\u4e00\u4e2a\u4ece\u6700\u9ad8\u6709\u6548\u4f4d\u5f00\u59cb\u7684\u4e8c\u8fdb\u5236\u6570\u3002\u4f8b\u5982\uff0c\u5982\u679c\u8def\u5f84\u4e3a\u00a00 -> 1 -> 1 -> 0 -> 1\uff0c\u90a3\u4e48\u5b83\u8868\u793a\u4e8c\u8fdb\u5236\u6570\u00a001101\uff0c\u4e5f\u5c31\u662f\u00a013\u00a0\u3002

    \n\n

    \u5bf9\u6811\u4e0a\u7684\u6bcf\u4e00\u7247\u53f6\u5b50\uff0c\u6211\u4eec\u90fd\u8981\u627e\u51fa\u4ece\u6839\u5230\u8be5\u53f6\u5b50\u7684\u8def\u5f84\u6240\u8868\u793a\u7684\u6570\u5b57\u3002

    \n\n

    \u8fd4\u56de\u8fd9\u4e9b\u6570\u5b57\u4e4b\u548c\u3002\u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u7b54\u6848\u662f\u4e00\u4e2a 32 \u4f4d \u6574\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [1,0,1,0,1,0,1]\n\u8f93\u51fa\uff1a22\n\u89e3\u91ca\uff1a(100) + (101) + (110) + (111) = 4 + 5 + 6 + 7 = 22\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [0]\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [1]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [1,1]\n\u8f93\u51fa\uff1a3\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u7684\u7ed3\u70b9\u6570\u4ecb\u4e8e 1 \u548c 1000 \u4e4b\u95f4\u3002
    • \n\t
    • Node.val \u4e3a 0 \u6216 1 \u3002
    • \n
    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int sumRootToLeaf(TreeNode* root) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int sumRootToLeaf(TreeNode root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def sumRootToLeaf(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def sumRootToLeaf(self, root: TreeNode) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint sumRootToLeaf(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int SumRootToLeaf(TreeNode root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar sumRootToLeaf = function(root) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef sum_root_to_leaf(root)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func sumRootToLeaf(_ root: TreeNode?) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc sumRootToLeaf(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def sumRootToLeaf(root: TreeNode): Int = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun sumRootToLeaf(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn sum_root_to_leaf(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function sumRootToLeaf($root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction sumRootToLeaf(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (sum-root-to-leaf root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1022](https://leetcode-cn.com/problems/sum-of-root-to-leaf-binary-numbers)", "[\u4ece\u6839\u5230\u53f6\u7684\u4e8c\u8fdb\u5236\u6570\u4e4b\u548c](/solution/1000-1099/1022.Sum%20of%20Root%20To%20Leaf%20Binary%20Numbers/README.md)", "`\u6811`", "\u7b80\u5355", ""], "md_table_row_en": ["[1022](https://leetcode.com/problems/sum-of-root-to-leaf-binary-numbers)", "[Sum of Root To Leaf Binary Numbers](/solution/1000-1099/1022.Sum%20of%20Root%20To%20Leaf%20Binary%20Numbers/README_EN.md)", "`Tree`", "Easy", ""]}, {"question_id": "1078", "frontend_question_id": "1021", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/remove-outermost-parentheses", "url_en": "https://leetcode.com/problems/remove-outermost-parentheses", "relative_path_cn": "/solution/1000-1099/1021.Remove%20Outermost%20Parentheses/README.md", "relative_path_en": "/solution/1000-1099/1021.Remove%20Outermost%20Parentheses/README_EN.md", "title_cn": "\u5220\u9664\u6700\u5916\u5c42\u7684\u62ec\u53f7", "title_en": "Remove Outermost Parentheses", "question_title_slug": "remove-outermost-parentheses", "content_en": "

    A valid parentheses string is either empty (""), "(" + A + ")", or A + B, where A and B are valid parentheses strings, and + represents string concatenation.  For example, "", "()", "(())()", and "(()(()))" are all valid parentheses strings.

    \n\n

    A valid parentheses string s is primitive if it is nonempty, and there does not exist a way to split it into s = A+B, with A and B nonempty valid parentheses strings.

    \n\n

    Given a valid parentheses string s, consider its primitive decomposition: s = P_1 + P_2 + ... + P_k, where P_i are primitive valid parentheses strings.

    \n\n

    Return s after removing the outermost parentheses of every primitive string in the primitive decomposition of S.

    \n\n

     

    \n\n

    Example 1:

    \n\n
    \nInput: s = "(()())(())"\nOutput: "()()()"\nExplanation: \nThe input string is "(()())(())", with primitive decomposition "(()())" + "(())".\nAfter removing outer parentheses of each part, this is "()()" + "()" = "()()()".\n
    \n\n
    \n

    Example 2:

    \n\n
    \nInput: s = "(()())(())(()(()))"\nOutput: "()()()()(())"\nExplanation: \nThe input string is "(()())(())(()(()))", with primitive decomposition "(()())" + "(())" + "(()(()))".\nAfter removing outer parentheses of each part, this is "()()" + "()" + "()(())" = "()()()()(())".\n
    \n\n
    \n

    Example 3:

    \n\n
    \nInput: s = "()()"\nOutput: ""\nExplanation: \nThe input string is "()()", with primitive decomposition "()" + "()".\nAfter removing outer parentheses of each part, this is "" + "" = "".\n
    \n\n

     

    \n
    \n
    \n\n

    Note:

    \n\n
      \n\t
    1. s.length <= 10000
    2. \n\t
    3. s[i] is "(" or ")"
    4. \n\t
    5. s is a valid parentheses string
    6. \n
    \n\n
    \n
    \n
     
    \n
    \n
    \n", "content_cn": "

    \u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32\u4e3a\u7a7a ("")\u3001"(" + A + ")" \u6216 A + B\uff0c\u5176\u4e2d A \u548c B \u90fd\u662f\u6709\u6548\u7684\u62ec\u53f7\u5b57\u7b26\u4e32\uff0c+ \u4ee3\u8868\u5b57\u7b26\u4e32\u7684\u8fde\u63a5\u3002\u4f8b\u5982\uff0c""\uff0c"()"\uff0c"(())()" \u548c "(()(()))" \u90fd\u662f\u6709\u6548\u7684\u62ec\u53f7\u5b57\u7b26\u4e32\u3002

    \n\n

    \u5982\u679c\u6709\u6548\u5b57\u7b26\u4e32 S \u975e\u7a7a\uff0c\u4e14\u4e0d\u5b58\u5728\u5c06\u5176\u62c6\u5206\u4e3a S = A+B \u7684\u65b9\u6cd5\uff0c\u6211\u4eec\u79f0\u5176\u4e3a\u539f\u8bed\uff08primitive\uff09\uff0c\u5176\u4e2d A \u548c B \u90fd\u662f\u975e\u7a7a\u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32\u3002

    \n\n

    \u7ed9\u51fa\u4e00\u4e2a\u975e\u7a7a\u6709\u6548\u5b57\u7b26\u4e32 S\uff0c\u8003\u8651\u5c06\u5176\u8fdb\u884c\u539f\u8bed\u5316\u5206\u89e3\uff0c\u4f7f\u5f97\uff1aS = P_1 + P_2 + ... + P_k\uff0c\u5176\u4e2d P_i \u662f\u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32\u539f\u8bed\u3002

    \n\n

    \u5bf9 S \u8fdb\u884c\u539f\u8bed\u5316\u5206\u89e3\uff0c\u5220\u9664\u5206\u89e3\u4e2d\u6bcf\u4e2a\u539f\u8bed\u5b57\u7b26\u4e32\u7684\u6700\u5916\u5c42\u62ec\u53f7\uff0c\u8fd4\u56de S \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a"(()())(())"\n\u8f93\u51fa\uff1a"()()()"\n\u89e3\u91ca\uff1a\n\u8f93\u5165\u5b57\u7b26\u4e32\u4e3a "(()())(())"\uff0c\u539f\u8bed\u5316\u5206\u89e3\u5f97\u5230 "(()())" + "(())"\uff0c\n\u5220\u9664\u6bcf\u4e2a\u90e8\u5206\u4e2d\u7684\u6700\u5916\u5c42\u62ec\u53f7\u540e\u5f97\u5230 "()()" + "()" = "()()()"\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a"(()())(())(()(()))"\n\u8f93\u51fa\uff1a"()()()()(())"\n\u89e3\u91ca\uff1a\n\u8f93\u5165\u5b57\u7b26\u4e32\u4e3a "(()())(())(()(()))"\uff0c\u539f\u8bed\u5316\u5206\u89e3\u5f97\u5230 "(()())" + "(())" + "(()(()))"\uff0c\n\u5220\u9664\u6bcf\u4e2a\u90e8\u5206\u4e2d\u7684\u6700\u5916\u5c42\u62ec\u53f7\u540e\u5f97\u5230 "()()" + "()" + "()(())" = "()()()()(())"\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1a"()()"\n\u8f93\u51fa\uff1a""\n\u89e3\u91ca\uff1a\n\u8f93\u5165\u5b57\u7b26\u4e32\u4e3a "()()"\uff0c\u539f\u8bed\u5316\u5206\u89e3\u5f97\u5230 "()" + "()"\uff0c\n\u5220\u9664\u6bcf\u4e2a\u90e8\u5206\u4e2d\u7684\u6700\u5916\u5c42\u62ec\u53f7\u540e\u5f97\u5230 "" + "" = ""\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. S.length <= 10000
    2. \n\t
    3. S[i] \u4e3a "(" \u6216 ")"
    4. \n\t
    5. S \u662f\u4e00\u4e2a\u6709\u6548\u62ec\u53f7\u5b57\u7b26\u4e32
    6. \n
    \n", "tags_en": ["Stack"], "tags_cn": ["\u6808"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string removeOuterParentheses(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String removeOuterParentheses(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def removeOuterParentheses(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def removeOuterParentheses(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * removeOuterParentheses(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string RemoveOuterParentheses(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar removeOuterParentheses = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef remove_outer_parentheses(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func removeOuterParentheses(_ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func removeOuterParentheses(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def removeOuterParentheses(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun removeOuterParentheses(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn remove_outer_parentheses(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function removeOuterParentheses($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function removeOuterParentheses(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (remove-outer-parentheses s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1021](https://leetcode-cn.com/problems/remove-outermost-parentheses)", "[\u5220\u9664\u6700\u5916\u5c42\u7684\u62ec\u53f7](/solution/1000-1099/1021.Remove%20Outermost%20Parentheses/README.md)", "`\u6808`", "\u7b80\u5355", ""], "md_table_row_en": ["[1021](https://leetcode.com/problems/remove-outermost-parentheses)", "[Remove Outermost Parentheses](/solution/1000-1099/1021.Remove%20Outermost%20Parentheses/README_EN.md)", "`Stack`", "Easy", ""]}, {"question_id": "1077", "frontend_question_id": "1088", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/confusing-number-ii", "url_en": "https://leetcode.com/problems/confusing-number-ii", "relative_path_cn": "/solution/1000-1099/1088.Confusing%20Number%20II/README.md", "relative_path_en": "/solution/1000-1099/1088.Confusing%20Number%20II/README_EN.md", "title_cn": "\u6613\u6df7\u6dc6\u6570 II", "title_en": "Confusing Number II", "question_title_slug": "confusing-number-ii", "content_en": "

    We can rotate digits by 180 degrees to form new digits. When 0, 1, 6, 8, 9 are rotated 180 degrees, they become 0, 1, 9, 8, 6 respectively. When 2, 3, 4, 5 and 7 are rotated 180 degrees, they become invalid.

    \n\n

    A confusing number is a number that when rotated 180 degrees becomes a different number with each digit valid.(Note that the rotated number can be greater than the original number.)

    \n\n

    Given a positive integer n, return the number of confusing numbers between 1 and n inclusive.

    \n\n

     

    \n\n

    Example 1:

    \n\n
    \nInput: n = 20\nOutput: 6\nExplanation: \nThe confusing numbers are [6,9,10,16,18,19].\n6 converts to 9.\n9 converts to 6.\n10 converts to 01 which is just 1.\n16 converts to 91.\n18 converts to 81.\n19 converts to 61.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 100\nOutput: 19\nExplanation: \nThe confusing numbers are [6,9,10,16,18,19,60,61,66,68,80,81,86,89,90,91,98,99,100].\n
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    1. 1 <= n <= 109
    2. \n
    \n", "content_cn": "

    \u672c\u9898\u6211\u4eec\u4f1a\u5c06\u6570\u5b57\u65cb\u8f6c 180° \u6765\u751f\u6210\u4e00\u4e2a\u65b0\u7684\u6570\u5b57\u3002

    \n\n

    \u6bd4\u5982 0\u30011\u30016\u30018\u30019 \u65cb\u8f6c 180° \u4ee5\u540e\uff0c\u6211\u4eec\u5f97\u5230\u7684\u65b0\u6570\u5b57\u5206\u522b\u4e3a 0\u30011\u30019\u30018\u30016\u3002

    \n\n

    2\u30013\u30014\u30015\u30017 \u65cb\u8f6c 180° \u540e\uff0c\u662f \u65e0\u6cd5 \u5f97\u5230\u4efb\u4f55\u6570\u5b57\u7684\u3002

    \n\n

    \u6613\u6df7\u6dc6\u6570\uff08Confusing Number\uff09\u6307\u7684\u662f\u4e00\u4e2a\u6570\u5b57\u5728\u6574\u4f53\u65cb\u8f6c 180° \u4ee5\u540e\uff0c\u80fd\u591f\u5f97\u5230\u4e00\u4e2a\u548c\u539f\u6765 \u4e0d\u540c \u7684\u6570\uff0c\u4e14\u65b0\u6570\u5b57\u7684\u6bcf\u4e00\u4f4d\u90fd\u5e94\u8be5\u662f\u6709\u6548\u7684\u3002\uff08\u8bf7\u6ce8\u610f\uff0c\u65cb\u8f6c\u540e\u5f97\u5230\u7684\u65b0\u6570\u5b57\u53ef\u80fd\u5927\u4e8e\u539f\u6570\u5b57\uff09

    \n\n

    \u7ed9\u51fa\u6b63\u6574\u6570 N\uff0c\u8bf7\u4f60\u8fd4\u56de 1 \u5230 N \u4e4b\u95f4\u6613\u6df7\u6dc6\u6570\u5b57\u7684\u6570\u91cf\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a20\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\n\u6613\u6df7\u6dc6\u6570\u4e3a [6,9,10,16,18,19]\u3002\n6 \u8f6c\u6362\u4e3a 9\n9 \u8f6c\u6362\u4e3a 6\n10 \u8f6c\u6362\u4e3a 01 \u4e5f\u5c31\u662f 1\n16 \u8f6c\u6362\u4e3a 91\n18 \u8f6c\u6362\u4e3a 81\n19 \u8f6c\u6362\u4e3a 61\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a100\n\u8f93\u51fa\uff1a19\n\u89e3\u91ca\uff1a\n\u6613\u6df7\u6dc6\u6570\u4e3a [6,9,10,16,18,19,60,61,66,68,80,81,86,89,90,91,98,99,100]\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= N <= 10^9
    2. \n
    \n", "tags_en": ["Math", "Backtracking"], "tags_cn": ["\u6570\u5b66", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int confusingNumberII(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int confusingNumberII(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def confusingNumberII(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def confusingNumberII(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint confusingNumberII(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ConfusingNumberII(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar confusingNumberII = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef confusing_number_ii(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func confusingNumberII(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func confusingNumberII(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def confusingNumberII(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun confusingNumberII(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn confusing_number_ii(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function confusingNumberII($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function confusingNumberII(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (confusing-number-ii n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1088](https://leetcode-cn.com/problems/confusing-number-ii)", "[\u6613\u6df7\u6dc6\u6570 II](/solution/1000-1099/1088.Confusing%20Number%20II/README.md)", "`\u6570\u5b66`,`\u56de\u6eaf\u7b97\u6cd5`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1088](https://leetcode.com/problems/confusing-number-ii)", "[Confusing Number II](/solution/1000-1099/1088.Confusing%20Number%20II/README_EN.md)", "`Math`,`Backtracking`", "Hard", "\ud83d\udd12"]}, {"question_id": "1076", "frontend_question_id": "1087", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/brace-expansion", "url_en": "https://leetcode.com/problems/brace-expansion", "relative_path_cn": "/solution/1000-1099/1087.Brace%20Expansion/README.md", "relative_path_en": "/solution/1000-1099/1087.Brace%20Expansion/README_EN.md", "title_cn": "\u82b1\u62ec\u53f7\u5c55\u5f00", "title_en": "Brace Expansion", "question_title_slug": "brace-expansion", "content_en": "

    You are given a string s representing a list of words. Each letter in the word has one or more options.

    \n\n
      \n\t
    • If there is one option, the letter is represented as is.
    • \n\t
    • If there is more than one option, then curly braces delimit the options. For example, "{a,b,c}" represents options ["a", "b", "c"].
    • \n
    \n\n

    For example, if s = "a{b,c}", the first character is always 'a', but the second character can be 'b' or 'c'. The original list is ["ab", "ac"].

    \n\n

    Return all words that can be formed in this manner, sorted in lexicographical order.

    \n\n

     

    \n

    Example 1:

    \n
    Input: s = \"{a,b}c{d,e}f\"\nOutput: [\"acdf\",\"acef\",\"bcdf\",\"bcef\"]\n

    Example 2:

    \n
    Input: s = \"abcd\"\nOutput: [\"abcd\"]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 50
    • \n\t
    • s consists of curly brackets '{}', commas ',', and lowercase English letters.
    • \n\t
    • s is guaranteed to be a valid input.
    • \n\t
    • There are no nested curly brackets.
    • \n\t
    • All characters inside a pair of consecutive opening and ending curly brackets are different.
    • \n
    \n", "content_cn": "

    \u6211\u4eec\u7528\u4e00\u4e2a\u7279\u6b8a\u7684\u5b57\u7b26\u4e32 S \u6765\u8868\u793a\u4e00\u4efd\u5355\u8bcd\u5217\u8868\uff0c\u4e4b\u6240\u4ee5\u80fd\u5c55\u5f00\u6210\u4e3a\u4e00\u4e2a\u5217\u8868\uff0c\u662f\u56e0\u4e3a\u8fd9\u4e2a\u5b57\u7b26\u4e32 S \u4e2d\u5b58\u5728\u4e00\u4e2a\u53eb\u505a\u300c\u9009\u9879\u300d\u7684\u6982\u5ff5\uff1a

    \n\n

    \u5355\u8bcd\u4e2d\u7684\u6bcf\u4e2a\u5b57\u6bcd\u53ef\u80fd\u53ea\u6709\u4e00\u4e2a\u9009\u9879\u6216\u5b58\u5728\u591a\u4e2a\u5907\u9009\u9879\u3002\u5982\u679c\u53ea\u6709\u4e00\u4e2a\u9009\u9879\uff0c\u90a3\u4e48\u8be5\u5b57\u6bcd\u6309\u539f\u6837\u8868\u793a\u3002

    \n\n

    \u5982\u679c\u5b58\u5728\u591a\u4e2a\u9009\u9879\uff0c\u5c31\u4f1a\u4ee5\u82b1\u62ec\u53f7\u5305\u88f9\u6765\u8868\u793a\u8fd9\u4e9b\u9009\u9879\uff08\u4f7f\u5b83\u4eec\u4e0e\u5176\u4ed6\u5b57\u6bcd\u5206\u9694\u5f00\uff09\uff0c\u4f8b\u5982 "{a,b,c}" \u8868\u793a ["a", "b", "c"]\u3002

    \n\n

    \u4f8b\u5b50\uff1a"{a,b,c}d{e,f}" \u53ef\u4ee5\u8868\u793a\u5355\u8bcd\u5217\u8868 ["ade", "adf", "bde", "bdf", "cde", "cdf"]\u3002

    \n\n

    \u8bf7\u4f60\u6309\u5b57\u5178\u987a\u5e8f\uff0c\u8fd4\u56de\u6240\u6709\u4ee5\u8fd9\u79cd\u65b9\u5f0f\u5f62\u6210\u7684\u5355\u8bcd\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a"{a,b}c{d,e}f"\n\u8f93\u51fa\uff1a["acdf","acef","bcdf","bcef"]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a"abcd"\n\u8f93\u51fa\uff1a["abcd"]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= S.length <= 50
    2. \n\t
    3. \u4f60\u53ef\u4ee5\u5047\u8bbe\u9898\u76ee\u4e2d\u4e0d\u5b58\u5728\u5d4c\u5957\u7684\u82b1\u62ec\u53f7
    4. \n\t
    5. \u5728\u4e00\u5bf9\u8fde\u7eed\u7684\u82b1\u62ec\u53f7\uff08\u5f00\u82b1\u62ec\u53f7\u4e0e\u95ed\u82b1\u62ec\u53f7\uff09\u4e4b\u95f4\u7684\u6240\u6709\u5b57\u6bcd\u90fd\u4e0d\u4f1a\u76f8\u540c
    6. \n
    \n", "tags_en": ["Backtracking"], "tags_cn": ["\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector expand(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String[] expand(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def expand(self, s):\n \"\"\"\n :type s: str\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def expand(self, s: str) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** expand(char * s, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string[] Expand(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string[]}\n */\nvar expand = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String[]}\ndef expand(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func expand(_ s: String) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func expand(s string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def expand(s: String): Array[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun expand(s: String): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn expand(s: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String[]\n */\n function expand($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function expand(s: string): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (expand s)\n (-> string? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1087](https://leetcode-cn.com/problems/brace-expansion)", "[\u82b1\u62ec\u53f7\u5c55\u5f00](/solution/1000-1099/1087.Brace%20Expansion/README.md)", "`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1087](https://leetcode.com/problems/brace-expansion)", "[Brace Expansion](/solution/1000-1099/1087.Brace%20Expansion/README_EN.md)", "`Backtracking`", "Medium", "\ud83d\udd12"]}, {"question_id": "1075", "frontend_question_id": "1065", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/index-pairs-of-a-string", "url_en": "https://leetcode.com/problems/index-pairs-of-a-string", "relative_path_cn": "/solution/1000-1099/1065.Index%20Pairs%20of%20a%20String/README.md", "relative_path_en": "/solution/1000-1099/1065.Index%20Pairs%20of%20a%20String/README_EN.md", "title_cn": "\u5b57\u7b26\u4e32\u7684\u7d22\u5f15\u5bf9", "title_en": "Index Pairs of a String", "question_title_slug": "index-pairs-of-a-string", "content_en": "

    Given a text string and words (a list of strings), return all index pairs [i, j] so that the substring text[i]...text[j] is in the list of words.

    \r\n\r\n

     

    \r\n\r\n

    Example 1:

    \r\n\r\n
    \r\nInput: text = "thestoryofleetcodeandme", words = ["story","fleet","leetcode"]\r\nOutput: [[3,7],[9,13],[10,17]]\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: text = "ababa", words = ["aba","ab"]\r\nOutput: [[0,1],[0,2],[2,3],[2,4]]\r\nExplanation: \r\nNotice that matches can overlap, see "aba" is found in [0,2] and [2,4].\r\n
    \r\n\r\n

     

    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    1. All strings contains only lowercase English letters.
    2. \r\n\t
    3. It's guaranteed that all strings in words are different.
    4. \r\n\t
    5. 1 <= text.length <= 100
    6. \r\n\t
    7. 1 <= words.length <= 20
    8. \r\n\t
    9. 1 <= words[i].length <= 50
    10. \r\n\t
    11. Return the pairs [i,j] in sorted order (i.e. sort them by their first coordinate in case of ties sort them by their second coordinate).
    12. \r\n
    ", "content_cn": "

    \u7ed9\u51fa \u5b57\u7b26\u4e32 text \u548c \u5b57\u7b26\u4e32\u5217\u8868 words, \u8fd4\u56de\u6240\u6709\u7684\u7d22\u5f15\u5bf9 [i, j] \u4f7f\u5f97\u5728\u7d22\u5f15\u5bf9\u8303\u56f4\u5185\u7684\u5b50\u5b57\u7b26\u4e32 text[i]...text[j]\uff08\u5305\u62ec i \u548c j\uff09\u5c5e\u4e8e\u5b57\u7b26\u4e32\u5217\u8868 words\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: text = "thestoryofleetcodeandme", words = ["story","fleet","leetcode"]\n\u8f93\u51fa: [[3,7],[9,13],[10,17]]\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: text = "ababa", words = ["aba","ab"]\n\u8f93\u51fa: [[0,1],[0,2],[2,3],[2,4]]\n\u89e3\u91ca: \n\u6ce8\u610f\uff0c\u8fd4\u56de\u7684\u914d\u5bf9\u53ef\u4ee5\u6709\u4ea4\u53c9\uff0c\u6bd4\u5982\uff0c"aba" \u65e2\u5728 [0,2] \u4e2d\u4e5f\u5728 [2,4] \u4e2d\n
    \n\n

     

    \n\n

    \u63d0\u793a:

    \n\n
      \n\t
    1. \u6240\u6709\u5b57\u7b26\u4e32\u90fd\u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd\u3002
    2. \n\t
    3. \u4fdd\u8bc1 words \u4e2d\u7684\u5b57\u7b26\u4e32\u65e0\u91cd\u590d\u3002
    4. \n\t
    5. 1 <= text.length <= 100
    6. \n\t
    7. 1 <= words.length <= 20
    8. \n\t
    9. 1 <= words[i].length <= 50
    10. \n\t
    11. \u6309\u5e8f\u8fd4\u56de\u7d22\u5f15\u5bf9 [i,j]\uff08\u5373\uff0c\u6309\u7167\u7d22\u5f15\u5bf9\u7684\u7b2c\u4e00\u4e2a\u7d22\u5f15\u8fdb\u884c\u6392\u5e8f\uff0c\u5f53\u7b2c\u4e00\u4e2a\u7d22\u5f15\u5bf9\u76f8\u540c\u65f6\u6309\u7167\u7b2c\u4e8c\u4e2a\u7d22\u5f15\u5bf9\u6392\u5e8f\uff09\u3002
    12. \n
    \n", "tags_en": ["Trie", "String"], "tags_cn": ["\u5b57\u5178\u6811", "\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> indexPairs(string text, vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[][] indexPairs(String text, String[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def indexPairs(self, text, words):\n \"\"\"\n :type text: str\n :type words: List[str]\n :rtype: List[List[int]]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def indexPairs(self, text: str, words: List[str]) -> List[List[int]]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** indexPairs(char * text, char ** words, int wordsSize, int* returnSize, int** returnColumnSizes){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[][] IndexPairs(string text, string[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} text\n * @param {string[]} words\n * @return {number[][]}\n */\nvar indexPairs = function(text, words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} text\n# @param {String[]} words\n# @return {Integer[][]}\ndef index_pairs(text, words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func indexPairs(_ text: String, _ words: [String]) -> [[Int]] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func indexPairs(text string, words []string) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def indexPairs(text: String, words: Array[String]): Array[Array[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun indexPairs(text: String, words: Array): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn index_pairs(text: String, words: Vec) -> Vec> {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $text\n * @param String[] $words\n * @return Integer[][]\n */\n function indexPairs($text, $words) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function indexPairs(text: string, words: string[]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (index-pairs text words)\n (-> string? (listof string?) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1065](https://leetcode-cn.com/problems/index-pairs-of-a-string)", "[\u5b57\u7b26\u4e32\u7684\u7d22\u5f15\u5bf9](/solution/1000-1099/1065.Index%20Pairs%20of%20a%20String/README.md)", "`\u5b57\u5178\u6811`,`\u5b57\u7b26\u4e32`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1065](https://leetcode.com/problems/index-pairs-of-a-string)", "[Index Pairs of a String](/solution/1000-1099/1065.Index%20Pairs%20of%20a%20String/README_EN.md)", "`Trie`,`String`", "Easy", "\ud83d\udd12"]}, {"question_id": "1074", "frontend_question_id": "1086", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/high-five", "url_en": "https://leetcode.com/problems/high-five", "relative_path_cn": "/solution/1000-1099/1086.High%20Five/README.md", "relative_path_en": "/solution/1000-1099/1086.High%20Five/README_EN.md", "title_cn": "\u524d\u4e94\u79d1\u7684\u5747\u5206", "title_en": "High Five", "question_title_slug": "high-five", "content_en": "

    Given a list of the scores of different students, items, where items[i] = [IDi, scorei] represents one score from a student with IDi, calculate each student's top five average.

    \n\n

    Return the answer as an array of pairs result, where result[j] = [IDj, topFiveAveragej] represents the student with IDj and their top five average. Sort result by IDj in increasing order.

    \n\n

    A student's top five average is calculated by taking the sum of their top five scores and dividing it by 5 using integer division.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: items = [[1,91],[1,92],[2,93],[2,97],[1,60],[2,77],[1,65],[1,87],[1,100],[2,100],[2,76]]\nOutput: [[1,87],[2,88]]\nExplanation: \nThe student with ID = 1 got scores 91, 92, 60, 65, 87, and 100. Their top five average is (100 + 92 + 91 + 87 + 65) / 5 = 87.\nThe student with ID = 2 got scores 93, 97, 77, 100, and 76. Their top five average is (100 + 97 + 93 + 77 + 76) / 5 = 88.6, but with integer division their average converts to 88.\n
    \n\n

    Example 2:

    \n\n
    \nInput: items = [[1,100],[7,100],[1,100],[7,100],[1,100],[7,100],[1,100],[7,100],[1,100],[7,100]]\nOutput: [[1,100],[7,100]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= items.length <= 1000
    • \n\t
    • items[i].length == 2
    • \n\t
    • 1 <= IDi <= 1000
    • \n\t
    • 0 <= scorei <= 100
    • \n\t
    • For each IDi, there will be at least five scores.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u4e0d\u540c\u5b66\u751f\u7684\u5206\u6570\u5217\u8868 items\uff0c\u5176\u4e2d items[i] = [IDi, scorei] \u8868\u793a IDi \u7684\u5b66\u751f\u7684\u4e00\u79d1\u5206\u6570\uff0c\u4f60\u9700\u8981\u8ba1\u7b97\u6bcf\u4e2a\u5b66\u751f\u00a0\u6700\u9ad8\u7684\u4e94\u79d1\u00a0\u6210\u7ee9\u7684\u00a0\u5e73\u5747\u5206\u3002

    \n\n

    \u8fd4\u56de\u7b54\u6848\u00a0result \u4ee5\u6570\u5bf9\u6570\u7ec4\u5f62\u5f0f\u7ed9\u51fa\uff0c\u5176\u4e2d result[j] = [IDj, topFiveAveragej] \u8868\u793a IDj \u7684\u5b66\u751f\u548c\u4ed6 \u6700\u9ad8\u7684\u4e94\u79d1\u00a0\u6210\u7ee9\u7684\u00a0\u5e73\u5747\u5206\u3002result \u9700\u8981\u6309 IDj\u00a0 \u9012\u589e\u7684 \u987a\u5e8f\u6392\u5217 \u3002

    \n\n

    \u5b66\u751f \u6700\u9ad8\u7684\u4e94\u79d1\u00a0\u6210\u7ee9\u7684\u00a0\u5e73\u5747\u5206 \u7684\u8ba1\u7b97\u65b9\u6cd5\u662f\u5c06\u6700\u9ad8\u7684\u4e94\u79d1\u5206\u6570\u76f8\u52a0\uff0c\u7136\u540e\u7528 \u6574\u6570\u9664\u6cd5 \u9664\u4ee5 5 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aitems = [[1,91],[1,92],[2,93],[2,97],[1,60],[2,77],[1,65],[1,87],[1,100],[2,100],[2,76]]\n\u8f93\u51fa\uff1a[[1,87],[2,88]]\n\u89e3\u91ca\uff1a\nID = 1 \u7684\u5b66\u751f\u5206\u6570\u4e3a 91\u300192\u300160\u300165\u300187 \u548c 100 \u3002\u524d\u4e94\u79d1\u7684\u5e73\u5747\u5206 (100 + 92 + 91 + 87 + 65) / 5 = 87\nID = 2 \u7684\u5b66\u751f\u5206\u6570\u4e3a 93\u300197\u300177\u3001100 \u548c 76 \u3002\u524d\u4e94\u79d1\u7684\u5e73\u5747\u5206 (100 + 97 + 93 + 77 + 76) / 5 = 88.6\uff0c\u4f46\u662f\u7531\u4e8e\u4f7f\u7528\u6574\u6570\u9664\u6cd5\uff0c\u7ed3\u679c\u8f6c\u6362\u4e3a 88\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aitems = [[1,100],[7,100],[1,100],[7,100],[1,100],[7,100],[1,100],[7,100],[1,100],[7,100]]\n\u8f93\u51fa\uff1a[[1,100],[7,100]]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= items.length <= 1000
    • \n\t
    • items[i].length == 2
    • \n\t
    • 1 <= IDi <= 1000
    • \n\t
    • 0 <= scorei <= 100
    • \n\t
    • \u5bf9\u4e8e\u6bcf\u4e2a IDi\uff0c\u81f3\u5c11 \u5b58\u5728\u4e94\u4e2a\u5206\u6570
    • \n
    \n", "tags_en": ["Sort", "Array", "Hash Table"], "tags_cn": ["\u6392\u5e8f", "\u6570\u7ec4", "\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> highFive(vector>& items) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[][] highFive(int[][] items) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def highFive(self, items):\n \"\"\"\n :type items: List[List[int]]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def highFive(self, items: List[List[int]]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** highFive(int** items, int itemsSize, int* itemsColSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[][] HighFive(int[][] items) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} items\n * @return {number[][]}\n */\nvar highFive = function(items) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} items\n# @return {Integer[][]}\ndef high_five(items)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func highFive(_ items: [[Int]]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func highFive(items [][]int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def highFive(items: Array[Array[Int]]): Array[Array[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun highFive(items: Array): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn high_five(items: Vec>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $items\n * @return Integer[][]\n */\n function highFive($items) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function highFive(items: number[][]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (high-five items)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1086](https://leetcode-cn.com/problems/high-five)", "[\u524d\u4e94\u79d1\u7684\u5747\u5206](/solution/1000-1099/1086.High%20Five/README.md)", "`\u6392\u5e8f`,`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1086](https://leetcode.com/problems/high-five)", "[High Five](/solution/1000-1099/1086.High%20Five/README_EN.md)", "`Sort`,`Array`,`Hash Table`", "Easy", "\ud83d\udd12"]}, {"question_id": "1073", "frontend_question_id": "1020", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-enclaves", "url_en": "https://leetcode.com/problems/number-of-enclaves", "relative_path_cn": "/solution/1000-1099/1020.Number%20of%20Enclaves/README.md", "relative_path_en": "/solution/1000-1099/1020.Number%20of%20Enclaves/README_EN.md", "title_cn": "\u98de\u5730\u7684\u6570\u91cf", "title_en": "Number of Enclaves", "question_title_slug": "number-of-enclaves", "content_en": "

    You are given an m x n binary matrix grid, where 0 represents a sea cell and 1 represents a land cell.

    \n\n

    A move consists of walking from one land cell to another adjacent (4-directionally) land cell or walking off the boundary of the grid.

    \n\n

    Return the number of land cells in grid for which we cannot walk off the boundary of the grid in any number of moves.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: grid = [[0,0,0,0],[1,0,1,0],[0,1,1,0],[0,0,0,0]]\nOutput: 3\nExplanation: There are three 1s that are enclosed by 0s, and one 1 that is not enclosed because its on the boundary.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: grid = [[0,1,1,0],[0,0,1,0],[0,0,1,0],[0,0,0,0]]\nOutput: 0\nExplanation: All 1s are either on the boundary or can reach the boundary.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= m, n <= 500
    • \n\t
    • grid[i][j] is either 0 or 1.
    • \n
    \n", "content_cn": "

    \u7ed9\u51fa\u4e00\u4e2a\u4e8c\u7ef4\u6570\u7ec4 A\uff0c\u6bcf\u4e2a\u5355\u5143\u683c\u4e3a 0\uff08\u4ee3\u8868\u6d77\uff09\u6216 1\uff08\u4ee3\u8868\u9646\u5730\uff09\u3002

    \n\n

    \u79fb\u52a8\u662f\u6307\u5728\u9646\u5730\u4e0a\u4ece\u4e00\u4e2a\u5730\u65b9\u8d70\u5230\u53e6\u4e00\u4e2a\u5730\u65b9\uff08\u671d\u56db\u4e2a\u65b9\u5411\u4e4b\u4e00\uff09\u6216\u79bb\u5f00\u7f51\u683c\u7684\u8fb9\u754c\u3002

    \n\n

    \u8fd4\u56de\u7f51\u683c\u4e2d\u65e0\u6cd5\u5728\u4efb\u610f\u6b21\u6570\u7684\u79fb\u52a8\u4e2d\u79bb\u5f00\u7f51\u683c\u8fb9\u754c\u7684\u9646\u5730\u5355\u5143\u683c\u7684\u6570\u91cf\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a[[0,0,0,0],[1,0,1,0],[0,1,1,0],[0,0,0,0]]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a \n\u6709\u4e09\u4e2a 1 \u88ab 0 \u5305\u56f4\u3002\u4e00\u4e2a 1 \u6ca1\u6709\u88ab\u5305\u56f4\uff0c\u56e0\u4e3a\u5b83\u5728\u8fb9\u754c\u4e0a\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a[[0,1,1,0],[0,0,1,0],[0,0,1,0],[0,0,0,0]]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\n\u6240\u6709 1 \u90fd\u5728\u8fb9\u754c\u4e0a\u6216\u53ef\u4ee5\u5230\u8fbe\u8fb9\u754c\u3002
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= A.length <= 500
    2. \n\t
    3. 1 <= A[i].length <= 500
    4. \n\t
    5. 0 <= A[i][j] <= 1
    6. \n\t
    7. \u6240\u6709\u884c\u7684\u5927\u5c0f\u90fd\u76f8\u540c
    8. \n
    \n", "tags_en": ["Depth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numEnclaves(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numEnclaves(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numEnclaves(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numEnclaves(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numEnclaves(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumEnclaves(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar numEnclaves = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef num_enclaves(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numEnclaves(_ grid: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numEnclaves(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numEnclaves(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numEnclaves(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_enclaves(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function numEnclaves($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numEnclaves(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-enclaves grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1020](https://leetcode-cn.com/problems/number-of-enclaves)", "[\u98de\u5730\u7684\u6570\u91cf](/solution/1000-1099/1020.Number%20of%20Enclaves/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1020](https://leetcode.com/problems/number-of-enclaves)", "[Number of Enclaves](/solution/1000-1099/1020.Number%20of%20Enclaves/README_EN.md)", "`Depth-first Search`", "Medium", ""]}, {"question_id": "1072", "frontend_question_id": "1019", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/next-greater-node-in-linked-list", "url_en": "https://leetcode.com/problems/next-greater-node-in-linked-list", "relative_path_cn": "/solution/1000-1099/1019.Next%20Greater%20Node%20In%20Linked%20List/README.md", "relative_path_en": "/solution/1000-1099/1019.Next%20Greater%20Node%20In%20Linked%20List/README_EN.md", "title_cn": "\u94fe\u8868\u4e2d\u7684\u4e0b\u4e00\u4e2a\u66f4\u5927\u8282\u70b9", "title_en": "Next Greater Node In Linked List", "question_title_slug": "next-greater-node-in-linked-list", "content_en": "

    We are given a linked list with head as the first node.  Let's number the nodes in the list: node_1, node_2, node_3, ... etc.

    \r\n\r\n

    Each node may have a next larger value: for node_inext_larger(node_i) is the node_j.val such that j > i, node_j.val > node_i.val, and j is the smallest possible choice.  If such a j does not exist, the next larger value is 0.

    \r\n\r\n

    Return an array of integers answer, where answer[i] = next_larger(node_{i+1}).

    \r\n\r\n

    Note that in the example inputs (not outputs) below, arrays such as [2,1,5] represent the serialization of a linked list with a head node value of 2, second node value of 1, and third node value of 5.

    \r\n\r\n

     

    \r\n\r\n
    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: [2,1,5]\r\nOutput: [5,5,0]\r\n
    \r\n\r\n
    \r\n

    Example 2:

    \r\n\r\n
    \r\nInput: [2,7,4,3,5]\r\nOutput: [7,0,5,5,0]\r\n
    \r\n\r\n
    \r\n

    Example 3:

    \r\n\r\n
    \r\nInput: [1,7,5,1,9,2,5,1]\r\nOutput: [7,9,9,9,0,5,0,0]\r\n
    \r\n\r\n

     

    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    1. 1 <= node.val <= 10^9 for each node in the linked list.
    2. \r\n\t
    3. The given list has length in the range [0, 10000].
    4. \r\n
    \r\n
    \r\n
    \r\n
    ", "content_cn": "

    \u7ed9\u51fa\u4e00\u4e2a\u4ee5\u5934\u8282\u70b9 head \u4f5c\u4e3a\u7b2c\u4e00\u4e2a\u8282\u70b9\u7684\u94fe\u8868\u3002\u94fe\u8868\u4e2d\u7684\u8282\u70b9\u5206\u522b\u7f16\u53f7\u4e3a\uff1anode_1, node_2, node_3, ... \u3002

    \n\n

    \u6bcf\u4e2a\u8282\u70b9\u90fd\u53ef\u80fd\u6709\u4e0b\u4e00\u4e2a\u66f4\u5927\u503c\uff08next larger value\uff09\uff1a\u5bf9\u4e8e node_i\uff0c\u5982\u679c\u5176 next_larger(node_i) \u662f node_j.val\uff0c\u90a3\u4e48\u5c31\u6709 j > i \u4e14  node_j.val > node_i.val\uff0c\u800c j \u662f\u53ef\u80fd\u7684\u9009\u9879\u4e2d\u6700\u5c0f\u7684\u90a3\u4e2a\u3002\u5982\u679c\u4e0d\u5b58\u5728\u8fd9\u6837\u7684 j\uff0c\u90a3\u4e48\u4e0b\u4e00\u4e2a\u66f4\u5927\u503c\u4e3a 0 \u3002

    \n\n

    \u8fd4\u56de\u6574\u6570\u7b54\u6848\u6570\u7ec4 answer\uff0c\u5176\u4e2d answer[i] = next_larger(node_{i+1}) \u3002

    \n\n

    \u6ce8\u610f\uff1a\u5728\u4e0b\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u8bf8\u5982 [2,1,5] \u8fd9\u6837\u7684\u8f93\u5165\uff08\u4e0d\u662f\u8f93\u51fa\uff09\u662f\u94fe\u8868\u7684\u5e8f\u5217\u5316\u8868\u793a\uff0c\u5176\u5934\u8282\u70b9\u7684\u503c\u4e3a 2\uff0c\u7b2c\u4e8c\u4e2a\u8282\u70b9\u503c\u4e3a 1\uff0c\u7b2c\u4e09\u4e2a\u8282\u70b9\u503c\u4e3a 5 \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a[2,1,5]\n\u8f93\u51fa\uff1a[5,5,0]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a[2,7,4,3,5]\n\u8f93\u51fa\uff1a[7,0,5,5,0]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1a[1,7,5,1,9,2,5,1]\n\u8f93\u51fa\uff1a[7,9,9,9,0,5,0,0]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. \u5bf9\u4e8e\u94fe\u8868\u4e2d\u7684\u6bcf\u4e2a\u8282\u70b9\uff0c1 <= node.val <= 10^9
    2. \n\t
    3. \u7ed9\u5b9a\u5217\u8868\u7684\u957f\u5ea6\u5728 [0, 10000] \u8303\u56f4\u5185
    4. \n
    \n", "tags_en": ["Stack", "Linked List"], "tags_cn": ["\u6808", "\u94fe\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\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 nextLargerNodes(ListNode* head) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode(int x) { val = x; }\n * }\n */\nclass Solution {\n public int[] nextLargerNodes(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.next = None\n\nclass Solution(object):\n def nextLargerNodes(self, head):\n \"\"\"\n :type head: ListNode\n :rtype: List[int]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, x):\n# self.val = x\n# self.next = None\n\nclass Solution:\n def nextLargerNodes(self, head: ListNode) -> List[int]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* nextLargerNodes(struct ListNode* head, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int x) { val = x; }\n * }\n */\npublic class Solution {\n public int[] NextLargerNodes(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val) {\n * this.val = val;\n * this.next = null;\n * }\n */\n/**\n * @param {ListNode} head\n * @return {number[]}\n */\nvar nextLargerNodes = function(head) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val)\n# @val = val\n# @next = nil\n# end\n# end\n\n# @param {ListNode} head\n# @return {Integer[]}\ndef next_larger_nodes(head)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.next = nil\n * }\n * }\n */\nclass Solution {\n func nextLargerNodes(_ head: ListNode?) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc nextLargerNodes(head *ListNode) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(var _x: Int = 0) {\n * var next: ListNode = null\n * var x: Int = _x\n * }\n */\nobject Solution {\n def nextLargerNodes(head: ListNode): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun nextLargerNodes(head: ListNode?): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n// \n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn next_larger_nodes(head: Option>) -> Vec {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val) { $this->val = $val; }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @return Integer[]\n */\n function nextLargerNodes($head) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction nextLargerNodes(head: ListNode | null): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (next-larger-nodes head)\n (-> (or/c list-node? #f) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1019](https://leetcode-cn.com/problems/next-greater-node-in-linked-list)", "[\u94fe\u8868\u4e2d\u7684\u4e0b\u4e00\u4e2a\u66f4\u5927\u8282\u70b9](/solution/1000-1099/1019.Next%20Greater%20Node%20In%20Linked%20List/README.md)", "`\u6808`,`\u94fe\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1019](https://leetcode.com/problems/next-greater-node-in-linked-list)", "[Next Greater Node In Linked List](/solution/1000-1099/1019.Next%20Greater%20Node%20In%20Linked%20List/README_EN.md)", "`Stack`,`Linked List`", "Medium", ""]}, {"question_id": "1071", "frontend_question_id": "1018", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/binary-prefix-divisible-by-5", "url_en": "https://leetcode.com/problems/binary-prefix-divisible-by-5", "relative_path_cn": "/solution/1000-1099/1018.Binary%20Prefix%20Divisible%20By%205/README.md", "relative_path_en": "/solution/1000-1099/1018.Binary%20Prefix%20Divisible%20By%205/README_EN.md", "title_cn": "\u53ef\u88ab 5 \u6574\u9664\u7684\u4e8c\u8fdb\u5236\u524d\u7f00", "title_en": "Binary Prefix Divisible By 5", "question_title_slug": "binary-prefix-divisible-by-5", "content_en": "

    You are given a binary array nums (0-indexed).

    \n\n

    We define xi as the number whose binary representation is the subarray nums[0..i] (from most-significant-bit to least-significant-bit).

    \n\n
      \n\t
    • For example, if nums = [1,0,1], then x0 = 1, x1 = 2, and x2 = 5.
    • \n
    \n\n

    Return an array of booleans answer where answer[i] is true if xi is divisible by 5.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [0,1,1]\nOutput: [true,false,false]\nExplanation: The input numbers in binary are 0, 01, 011; which are 0, 1, and 3 in base-10.\nOnly the first number is divisible by 5, so answer[0] is true.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,1,1]\nOutput: [false,false,false]\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [0,1,1,1,1,1]\nOutput: [true,false,false,false,true,false]\n
    \n\n

    Example 4:

    \n\n
    \nInput: nums = [1,1,1,0,1]\nOutput: [false,false,false,false,false]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • nums[i] is 0 or 1.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u7531\u82e5\u5e72 0 \u548c 1 \u7ec4\u6210\u7684\u6570\u7ec4 A\u3002\u6211\u4eec\u5b9a\u4e49 N_i\uff1a\u4ece A[0] \u5230 A[i] \u7684\u7b2c i \u4e2a\u5b50\u6570\u7ec4\u88ab\u89e3\u91ca\u4e3a\u4e00\u4e2a\u4e8c\u8fdb\u5236\u6570\uff08\u4ece\u6700\u9ad8\u6709\u6548\u4f4d\u5230\u6700\u4f4e\u6709\u6548\u4f4d\uff09\u3002

    \n\n

    \u8fd4\u56de\u5e03\u5c14\u503c\u5217\u8868 answer\uff0c\u53ea\u6709\u5f53 N_i \u53ef\u4ee5\u88ab 5 \u6574\u9664\u65f6\uff0c\u7b54\u6848 answer[i] \u4e3a true\uff0c\u5426\u5219\u4e3a false\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a[0,1,1]\n\u8f93\u51fa\uff1a[true,false,false]\n\u89e3\u91ca\uff1a\n\u8f93\u5165\u6570\u5b57\u4e3a 0, 01, 011\uff1b\u4e5f\u5c31\u662f\u5341\u8fdb\u5236\u4e2d\u7684 0, 1, 3 \u3002\u53ea\u6709\u7b2c\u4e00\u4e2a\u6570\u53ef\u4ee5\u88ab 5 \u6574\u9664\uff0c\u56e0\u6b64 answer[0] \u4e3a\u771f\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a[1,1,1]\n\u8f93\u51fa\uff1a[false,false,false]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1a[0,1,1,1,1,1]\n\u8f93\u51fa\uff1a[true,false,false,false,true,false]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1a[1,1,1,0,1]\n\u8f93\u51fa\uff1a[false,false,false,false,false]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= A.length <= 30000
    2. \n\t
    3. A[i] \u4e3a 0 \u6216 1
    4. \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector prefixesDivBy5(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List prefixesDivBy5(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def prefixesDivBy5(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[bool]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def prefixesDivBy5(self, nums: List[int]) -> List[bool]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nbool* prefixesDivBy5(int* nums, int numsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList PrefixesDivBy5(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {boolean[]}\n */\nvar prefixesDivBy5 = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Boolean[]}\ndef prefixes_div_by5(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func prefixesDivBy5(_ nums: [Int]) -> [Bool] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func prefixesDivBy5(nums []int) []bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def prefixesDivBy5(nums: Array[Int]): List[Boolean] = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun prefixesDivBy5(nums: IntArray): List {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn prefixes_div_by5(nums: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Boolean[]\n */\n function prefixesDivBy5($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function prefixesDivBy5(nums: number[]): boolean[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (prefixes-div-by5 nums)\n (-> (listof exact-integer?) (listof boolean?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1018](https://leetcode-cn.com/problems/binary-prefix-divisible-by-5)", "[\u53ef\u88ab 5 \u6574\u9664\u7684\u4e8c\u8fdb\u5236\u524d\u7f00](/solution/1000-1099/1018.Binary%20Prefix%20Divisible%20By%205/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1018](https://leetcode.com/problems/binary-prefix-divisible-by-5)", "[Binary Prefix Divisible By 5](/solution/1000-1099/1018.Binary%20Prefix%20Divisible%20By%205/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1070", "frontend_question_id": "1017", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/convert-to-base-2", "url_en": "https://leetcode.com/problems/convert-to-base-2", "relative_path_cn": "/solution/1000-1099/1017.Convert%20to%20Base%20-2/README.md", "relative_path_en": "/solution/1000-1099/1017.Convert%20to%20Base%20-2/README_EN.md", "title_cn": "\u8d1f\u4e8c\u8fdb\u5236\u8f6c\u6362", "title_en": "Convert to Base -2", "question_title_slug": "convert-to-base-2", "content_en": "

    Given a number n, return a string consisting of "0"s and "1"s that represents its value in base -2 (negative two).

    \n\n

    The returned string must have no leading zeroes, unless the string is "0".

    \n\n

     

    \n\n
    \n

    Example 1:

    \n\n
    \nInput: n = 2\nOutput: "110"\nExplantion: (-2) ^ 2 + (-2) ^ 1 = 2\n
    \n\n
    \n

    Example 2:

    \n\n
    \nInput: n = 3\nOutput: "111"\nExplantion: (-2) ^ 2 + (-2) ^ 1 + (-2) ^ 0 = 3\n
    \n\n
    \n

    Example 3:

    \n\n
    \nInput: n = 4\nOutput: "100"\nExplantion: (-2) ^ 2 = 4\n
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    1. 0 <= n <= 109
    2. \n
    \n
    \n
    \n
    \n", "content_cn": "

    \u7ed9\u51fa\u6570\u5b57 N\uff0c\u8fd4\u56de\u7531\u82e5\u5e72 "0" \u548c "1"\u7ec4\u6210\u7684\u5b57\u7b26\u4e32\uff0c\u8be5\u5b57\u7b26\u4e32\u4e3a N \u7684\u8d1f\u4e8c\u8fdb\u5236\uff08base -2\uff09\u8868\u793a\u3002

    \n\n

    \u9664\u975e\u5b57\u7b26\u4e32\u5c31\u662f "0"\uff0c\u5426\u5219\u8fd4\u56de\u7684\u5b57\u7b26\u4e32\u4e2d\u4e0d\u80fd\u542b\u6709\u524d\u5bfc\u96f6\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a2\n\u8f93\u51fa\uff1a"110"\n\u89e3\u91ca\uff1a(-2) ^ 2 + (-2) ^ 1 = 2\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a3\n\u8f93\u51fa\uff1a"111"\n\u89e3\u91ca\uff1a(-2) ^ 2 + (-2) ^ 1 + (-2) ^ 0 = 3\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1a4\n\u8f93\u51fa\uff1a"100"\n\u89e3\u91ca\uff1a(-2) ^ 2 = 4\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 0 <= N <= 10^9
    2. \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string baseNeg2(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String baseNeg2(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def baseNeg2(self, n):\n \"\"\"\n :type n: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def baseNeg2(self, n: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * baseNeg2(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string BaseNeg2(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {string}\n */\nvar baseNeg2 = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {String}\ndef base_neg2(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func baseNeg2(_ n: Int) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func baseNeg2(n int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def baseNeg2(n: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun baseNeg2(n: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn base_neg2(n: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return String\n */\n function baseNeg2($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function baseNeg2(n: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (base-neg2 n)\n (-> exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1017](https://leetcode-cn.com/problems/convert-to-base-2)", "[\u8d1f\u4e8c\u8fdb\u5236\u8f6c\u6362](/solution/1000-1099/1017.Convert%20to%20Base%20-2/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1017](https://leetcode.com/problems/convert-to-base-2)", "[Convert to Base -2](/solution/1000-1099/1017.Convert%20to%20Base%20-2/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "1069", "frontend_question_id": "1056", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/confusing-number", "url_en": "https://leetcode.com/problems/confusing-number", "relative_path_cn": "/solution/1000-1099/1056.Confusing%20Number/README.md", "relative_path_en": "/solution/1000-1099/1056.Confusing%20Number/README_EN.md", "title_cn": "\u6613\u6df7\u6dc6\u6570", "title_en": "Confusing Number", "question_title_slug": "confusing-number", "content_en": "

    Given a number n, return true if and only if it is a confusing number, which satisfies the following condition:

    \n\n

    We can rotate digits by 180 degrees to form new digits. When 0, 1, 6, 8, 9 are rotated 180 degrees, they become 0, 1, 9, 8, 6 respectively. When 2, 3, 4, 5 and 7 are rotated 180 degrees, they become invalid. A confusing number is a number that when rotated 180 degrees becomes a different number with each digit valid.

    \n\n

     

    \n\n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: n = 6\nOutput: true\nExplanation: \nWe get 9 after rotating 6, 9 is a valid number and 9!=6.\n
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: n = 89\nOutput: true\nExplanation: \nWe get 68 after rotating 89, 86 is a valid number and 86!=89.\n
    \n\n

    Example 3:

    \n\n

    \"\"

    \n\n
    \nInput: n = 11\nOutput: false\nExplanation: \nWe get 11 after rotating 11, 11 is a valid number but the value remains the same, thus 11 is not a confusing number.\n
    \n\n

    Example 4:

    \n\n

    \"\"

    \n\n
    \nInput: n = 25\nOutput: false\nExplanation: \nWe get an invalid number after rotating 25.\n
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    1. 0 <= n <= 109
    2. \n\t
    3. After the rotation we can ignore leading zeros, for example if after rotation we have 0008 then this number is considered as just 8.
    4. \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6570\u5b57 N\uff0c\u5f53\u5b83\u6ee1\u8db3\u4ee5\u4e0b\u6761\u4ef6\u7684\u65f6\u5019\u8fd4\u56de true\uff1a

    \n\n

    \u539f\u6570\u5b57\u65cb\u8f6c 180° \u4ee5\u540e\u53ef\u4ee5\u5f97\u5230\u65b0\u7684\u6570\u5b57\u3002

    \n\n

    \u5982 0, 1, 6, 8, 9 \u65cb\u8f6c 180° \u4ee5\u540e\uff0c\u5f97\u5230\u4e86\u65b0\u7684\u6570\u5b57 0, 1, 9, 8, 6 \u3002

    \n\n

    2, 3, 4, 5, 7 \u65cb\u8f6c 180° \u540e\uff0c\u5f97\u5230\u7684\u4e0d\u662f\u6570\u5b57\u3002

    \n\n

    \u6613\u6df7\u6dc6\u6570 (confusing number) \u5728\u65cb\u8f6c180°\u4ee5\u540e\uff0c\u53ef\u4ee5\u5f97\u5230\u548c\u539f\u6765\u4e0d\u540c\u7684\u6570\uff0c\u4e14\u65b0\u6570\u5b57\u7684\u6bcf\u4e00\u4f4d\u90fd\u662f\u6709\u6548\u7684\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1a6\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a \n\u628a 6 \u65cb\u8f6c 180° \u4ee5\u540e\u5f97\u5230 9\uff0c9 \u662f\u6709\u6548\u6570\u5b57\u4e14 9!=6 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1a89\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca: \n\u628a 89 \u65cb\u8f6c 180° \u4ee5\u540e\u5f97\u5230 68\uff0c86 \u662f\u6709\u6548\u6570\u5b57\u4e14 86!=89 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1a11\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\n\u628a 11 \u65cb\u8f6c 180° \u4ee5\u540e\u5f97\u5230 11\uff0c11 \u662f\u6709\u6548\u6570\u5b57\u4f46\u662f\u503c\u4fdd\u6301\u4e0d\u53d8\uff0c\u6240\u4ee5 11 \u4e0d\u662f\u6613\u6df7\u6dc6\u6570\u5b57\u3002 \n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1a25\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\n\u628a 25 \u65cb\u8f6c 180° \u4ee5\u540e\u5f97\u5230\u7684\u4e0d\u662f\u6570\u5b57\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 0 <= N <= 10^9
    2. \n\t
    3. \u53ef\u4ee5\u5ffd\u7565\u6389\u65cb\u8f6c\u540e\u5f97\u5230\u7684\u524d\u5bfc\u96f6\uff0c\u4f8b\u5982\uff0c\u5982\u679c\u6211\u4eec\u65cb\u8f6c\u540e\u5f97\u5230 0008 \u90a3\u4e48\u8be5\u6570\u5b57\u5c31\u662f 8 \u3002
    4. \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool confusingNumber(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean confusingNumber(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def confusingNumber(self, n):\n \"\"\"\n :type n: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def confusingNumber(self, n: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool confusingNumber(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool ConfusingNumber(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {boolean}\n */\nvar confusingNumber = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Boolean}\ndef confusing_number(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func confusingNumber(_ n: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func confusingNumber(n int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def confusingNumber(n: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun confusingNumber(n: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn confusing_number(n: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Boolean\n */\n function confusingNumber($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function confusingNumber(n: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (confusing-number n)\n (-> exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1056](https://leetcode-cn.com/problems/confusing-number)", "[\u6613\u6df7\u6dc6\u6570](/solution/1000-1099/1056.Confusing%20Number/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1056](https://leetcode.com/problems/confusing-number)", "[Confusing Number](/solution/1000-1099/1056.Confusing%20Number/README_EN.md)", "`Math`", "Easy", "\ud83d\udd12"]}, {"question_id": "1068", "frontend_question_id": "1067", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/digit-count-in-range", "url_en": "https://leetcode.com/problems/digit-count-in-range", "relative_path_cn": "/solution/1000-1099/1067.Digit%20Count%20in%20Range/README.md", "relative_path_en": "/solution/1000-1099/1067.Digit%20Count%20in%20Range/README_EN.md", "title_cn": "\u8303\u56f4\u5185\u7684\u6570\u5b57\u8ba1\u6570", "title_en": "Digit Count in Range", "question_title_slug": "digit-count-in-range", "content_en": "Given an integer d between 0 and 9, and two positive integers low and high as lower and upper bounds, respectively. Return the number of times that d occurs as a digit in all integers between low and high, including the bounds low and high.\r\n

     

    \r\n\r\n

    Example 1:

    \r\n\r\n
    \r\nInput: d = 1, low = 1, high = 13\r\nOutput: 6\r\nExplanation: \r\nThe digit d=1 occurs 6 times in 1,10,11,12,13. Note that the digit d=1 occurs twice in the number 11.\r\n
    \r\n\r\n
    \r\n

    Example 2:

    \r\n\r\n
    \r\nInput: d = 3, low = 100, high = 250\r\nOutput: 35\r\nExplanation: \r\nThe digit d=3 occurs 35 times in 103,113,123,130,131,...,238,239,243.\r\n
    \r\n\r\n

     

    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    1. 0 <= d <= 9
    2. \r\n\t
    3. 1 <= low <= high <= 2×10^8
    4. \r\n
    \r\n
    ", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5728 0 \u5230 9 \u4e4b\u95f4\u7684\u6574\u6570 d\uff0c\u548c\u4e24\u4e2a\u6b63\u6574\u6570 low \u548c high \u5206\u522b\u4f5c\u4e3a\u4e0a\u4e0b\u754c\u3002\u8fd4\u56de d \u5728 low \u548c high \u4e4b\u95f4\u7684\u6574\u6570\u4e2d\u51fa\u73b0\u7684\u6b21\u6570\uff0c\u5305\u62ec\u8fb9\u754c low \u548c high\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1ad = 1, low = 1, high = 13\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a \n\u6570\u5b57 d=1 \u5728 1,10,11,12,13 \u4e2d\u51fa\u73b0 6 \u6b21\u3002\u6ce8\u610f d=1 \u5728\u6570\u5b57 11 \u4e2d\u51fa\u73b0\u4e24\u6b21\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1ad = 3, low = 100, high = 250\n\u8f93\u51fa\uff1a35\n\u89e3\u91ca\uff1a\n\u6570\u5b57 d=3 \u5728 103,113,123,130,131,...,238,239,243 \u51fa\u73b0 35 \u6b21\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 0 <= d <= 9
    2. \n\t
    3. 1 <= low <= high <= 2×10^8
    4. \n
    \n", "tags_en": ["Math", "Dynamic Programming"], "tags_cn": ["\u6570\u5b66", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int digitsCount(int d, int low, int high) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int digitsCount(int d, int low, int high) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def digitsCount(self, d, low, high):\n \"\"\"\n :type d: int\n :type low: int\n :type high: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def digitsCount(self, d: int, low: int, high: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint digitsCount(int d, int low, int high){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int DigitsCount(int d, int low, int high) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} d\n * @param {number} low\n * @param {number} high\n * @return {number}\n */\nvar digitsCount = function(d, low, high) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} d\n# @param {Integer} low\n# @param {Integer} high\n# @return {Integer}\ndef digits_count(d, low, high)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func digitsCount(_ d: Int, _ low: Int, _ high: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func digitsCount(d int, low int, high int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def digitsCount(d: Int, low: Int, high: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun digitsCount(d: Int, low: Int, high: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn digits_count(d: i32, low: i32, high: i32) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $d\n * @param Integer $low\n * @param Integer $high\n * @return Integer\n */\n function digitsCount($d, $low, $high) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function digitsCount(d: number, low: number, high: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (digits-count d low high)\n (-> exact-integer? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1067](https://leetcode-cn.com/problems/digit-count-in-range)", "[\u8303\u56f4\u5185\u7684\u6570\u5b57\u8ba1\u6570](/solution/1000-1099/1067.Digit%20Count%20in%20Range/README.md)", "`\u6570\u5b66`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1067](https://leetcode.com/problems/digit-count-in-range)", "[Digit Count in Range](/solution/1000-1099/1067.Digit%20Count%20in%20Range/README_EN.md)", "`Math`,`Dynamic Programming`", "Hard", "\ud83d\udd12"]}, {"question_id": "1067", "frontend_question_id": "1066", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/campus-bikes-ii", "url_en": "https://leetcode.com/problems/campus-bikes-ii", "relative_path_cn": "/solution/1000-1099/1066.Campus%20Bikes%20II/README.md", "relative_path_en": "/solution/1000-1099/1066.Campus%20Bikes%20II/README_EN.md", "title_cn": "\u6821\u56ed\u81ea\u884c\u8f66\u5206\u914d II", "title_en": "Campus Bikes II", "question_title_slug": "campus-bikes-ii", "content_en": "

    On a campus represented as a 2D grid, there are N workers and M bikes, with N <= M. Each worker and bike is a 2D coordinate on this grid.

    \n\n

    We assign one unique bike to each worker so that the sum of the Manhattan distances between each worker and their assigned bike is minimized.

    \n\n

    The Manhattan distance between two points p1 and p2 is Manhattan(p1, p2) = |p1.x - p2.x| + |p1.y - p2.y|.

    \n\n

    Return the minimum possible sum of Manhattan distances between each worker and their assigned bike.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: workers = [[0,0],[2,1]], bikes = [[1,2],[3,3]]\nOutput: 6\nExplanation: \nWe assign bike 0 to worker 0, bike 1 to worker 1. The Manhattan distance of both assignments is 3, so the output is 6.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: workers = [[0,0],[1,1],[2,0]], bikes = [[1,0],[2,2],[2,1]]\nOutput: 4\nExplanation: \nWe first assign bike 0 to worker 0, then assign bike 1 to worker 1 or worker 2, bike 2 to worker 2 or worker 1. Both assignments lead to sum of the Manhattan distances as 4.\n
    \n\n

    Example 3:

    \n\n
    \nInput: workers = [[0,0],[1,0],[2,0],[3,0],[4,0]], bikes = [[0,999],[1,999],[2,999],[3,999],[4,999]]\nOutput: 4995\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • N == workers.length
    • \n\t
    • M == bikes.length
    • \n\t
    • 1 <= N <= M <= 10
    • \n\t
    • workers[i].length == 2
    • \n\t
    • bikes[i].length == 2
    • \n\t
    • 0 <= workers[i][0], workers[i][1], bikes[i][0], bikes[i][1] < 1000
    • \n\t
    • All the workers and the bikes locations are unique.
    • \n
    \n", "content_cn": "

    \u5728\u7531 2D \u7f51\u683c\u8868\u793a\u7684\u6821\u56ed\u91cc\u6709 n \u4f4d\u5de5\u4eba\uff08worker\uff09\u548c m \u8f86\u81ea\u884c\u8f66\uff08bike\uff09\uff0cn <= m\u3002\u6240\u6709\u5de5\u4eba\u548c\u81ea\u884c\u8f66\u7684\u4f4d\u7f6e\u90fd\u7528\u7f51\u683c\u4e0a\u7684 2D \u5750\u6807\u8868\u793a\u3002

    \n\n

    \u6211\u4eec\u4e3a\u6bcf\u4e00\u4f4d\u5de5\u4eba\u5206\u914d\u4e00\u8f86\u4e13\u5c5e\u81ea\u884c\u8f66\uff0c\u4f7f\u6bcf\u4e2a\u5de5\u4eba\u4e0e\u5176\u5206\u914d\u5230\u7684\u81ea\u884c\u8f66\u4e4b\u95f4\u7684\u66fc\u54c8\u987f\u8ddd\u79bb\u6700\u5c0f\u5316\u3002

    \n\n

    p1 \u548c p2 \u4e4b\u95f4\u7684\u66fc\u54c8\u987f\u8ddd\u79bb\u4e3a Manhattan(p1, p2) = |p1.x - p2.x| + |p1.y - p2.y|\u3002

    \n\n

    \u8fd4\u56de\u6bcf\u4e2a\u5de5\u4eba\u4e0e\u5206\u914d\u5230\u7684\u81ea\u884c\u8f66\u4e4b\u95f4\u7684\u66fc\u54c8\u987f\u8ddd\u79bb\u7684\u6700\u5c0f\u53ef\u80fd\u603b\u548c\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1aworkers = [[0,0],[2,1]], bikes = [[1,2],[3,3]]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\n\u81ea\u884c\u8f66 0 \u5206\u914d\u7ed9\u5de5\u4eba 0\uff0c\u81ea\u884c\u8f66 1 \u5206\u914d\u7ed9\u5de5\u4eba 1 \u3002\u5206\u914d\u5f97\u5230\u7684\u66fc\u54c8\u987f\u8ddd\u79bb\u90fd\u662f 3, \u6240\u4ee5\u8f93\u51fa\u4e3a 6 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1aworkers = [[0,0],[1,1],[2,0]], bikes = [[1,0],[2,2],[2,1]]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\n\u5148\u5c06\u81ea\u884c\u8f66 0 \u5206\u914d\u7ed9\u5de5\u4eba 0\uff0c\u518d\u5c06\u81ea\u884c\u8f66 1 \u5206\u914d\u7ed9\u5de5\u4eba 1\uff08\u6216\u5de5\u4eba 2\uff09\uff0c\u81ea\u884c\u8f66 2 \u7ed9\u5de5\u4eba 2\uff08\u6216\u5de5\u4eba 1\uff09\u3002\u5982\u6b64\u5206\u914d\u4f7f\u5f97\u66fc\u54c8\u987f\u8ddd\u79bb\u7684\u603b\u548c\u4e3a 4\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 0 <= workers[i][0], workers[i][1], bikes[i][0], bikes[i][1] < 1000
    2. \n\t
    3. \u6240\u6709\u5de5\u4eba\u548c\u81ea\u884c\u8f66\u7684\u4f4d\u7f6e\u90fd\u4e0d\u76f8\u540c\u3002
    4. \n\t
    5. 1 <= workers.length <= bikes.length <= 10
    6. \n
    \n", "tags_en": ["Dynamic Programming", "Backtracking"], "tags_cn": ["\u52a8\u6001\u89c4\u5212", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int assignBikes(vector>& workers, vector>& bikes) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int assignBikes(int[][] workers, int[][] bikes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def assignBikes(self, workers, bikes):\n \"\"\"\n :type workers: List[List[int]]\n :type bikes: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def assignBikes(self, workers: List[List[int]], bikes: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint assignBikes(int** workers, int workersSize, int* workersColSize, int** bikes, int bikesSize, int* bikesColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int AssignBikes(int[][] workers, int[][] bikes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} workers\n * @param {number[][]} bikes\n * @return {number}\n */\nvar assignBikes = function(workers, bikes) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} workers\n# @param {Integer[][]} bikes\n# @return {Integer}\ndef assign_bikes(workers, bikes)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func assignBikes(_ workers: [[Int]], _ bikes: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func assignBikes(workers [][]int, bikes [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def assignBikes(workers: Array[Array[Int]], bikes: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun assignBikes(workers: Array, bikes: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn assign_bikes(workers: Vec>, bikes: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $workers\n * @param Integer[][] $bikes\n * @return Integer\n */\n function assignBikes($workers, $bikes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function assignBikes(workers: number[][], bikes: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (assign-bikes workers bikes)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1066](https://leetcode-cn.com/problems/campus-bikes-ii)", "[\u6821\u56ed\u81ea\u884c\u8f66\u5206\u914d II](/solution/1000-1099/1066.Campus%20Bikes%20II/README.md)", "`\u52a8\u6001\u89c4\u5212`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1066](https://leetcode.com/problems/campus-bikes-ii)", "[Campus Bikes II](/solution/1000-1099/1066.Campus%20Bikes%20II/README_EN.md)", "`Dynamic Programming`,`Backtracking`", "Medium", "\ud83d\udd12"]}, {"question_id": "1066", "frontend_question_id": "1064", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/fixed-point", "url_en": "https://leetcode.com/problems/fixed-point", "relative_path_cn": "/solution/1000-1099/1064.Fixed%20Point/README.md", "relative_path_en": "/solution/1000-1099/1064.Fixed%20Point/README_EN.md", "title_cn": "\u4e0d\u52a8\u70b9", "title_en": "Fixed Point", "question_title_slug": "fixed-point", "content_en": "

    Given an array of distinct integers arr, where arr is sorted in ascending order, return the smallest index i that satisfies arr[i] == i. If there is no such index, return -1.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr = [-10,-5,0,3,7]\nOutput: 3\nExplanation: For the given array, arr[0] = -10, arr[1] = -5, arr[2] = 0, arr[3] = 3, thus the output is 3.
    \n\n

    Example 2:

    \n\n
    \nInput: arr = [0,2,5,8,17]\nOutput: 0\nExplanation: arr[0] = 0, thus the output is 0.
    \n\n

    Example 3:

    \n\n
    \nInput: arr = [-10,-5,3,4,7,9]\nOutput: -1\nExplanation: There is no such i that arr[i] == i, thus the output is -1.
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= arr.length < 104
    • \n\t
    • -109 <= arr[i] <= 109
    • \n
    \n\n

     

    \nFollow up: The O(n) solution is very straightforward. Can we do better?", "content_cn": "

    \u7ed9\u5b9a\u5df2\u7ecf\u6309 \u5347\u5e8f \u6392\u5217\u3001\u7531\u4e0d\u540c\u6574\u6570\u7ec4\u6210\u7684\u6570\u7ec4 arr\uff0c\u8fd4\u56de\u6ee1\u8db3 arr[i] == i \u7684\u6700\u5c0f\u7d22\u5f15\u00a0i\u3002\u5982\u679c\u4e0d\u5b58\u5728\u8fd9\u6837\u7684\u00a0i\uff0c\u8fd4\u56de -1\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [-10,-5,0,3,7]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u5bf9\u4e8e\u7ed9\u5b9a\u7684\u6570\u7ec4\uff0carr[0] = -10\uff0carr[1] = -5\uff0carr[2] = 0\uff0carr[3] = 3\uff0c\u56e0\u6b64\u8f93\u51fa\u4e3a 3 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [0,2,5,8,17]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1aarr[0] = 0\uff0c\u56e0\u6b64\u8f93\u51fa\u4e3a 0 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [-10,-5,3,4,7,9]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u4e0d\u5b58\u5728\u8fd9\u6837\u7684 i \u6ee1\u8db3 arr[i] = i\uff0c\u56e0\u6b64\u8f93\u51fa\u4e3a -1 \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= arr.length < 104
    • \n\t
    • -109 <= arr[i] <= 109
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n) \u7684\u89e3\u51b3\u65b9\u6848\u5f88\u76f4\u89c2\u4e5f\u5f88\u7b80\u5355\u3002\u4f60\u53ef\u4ee5\u8bbe\u8ba1\u66f4\u4f18\u7684\u89e3\u51b3\u65b9\u6848\u5417\uff1f

    \n", "tags_en": ["Array", "Binary Search"], "tags_cn": ["\u6570\u7ec4", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int fixedPoint(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int fixedPoint(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def fixedPoint(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def fixedPoint(self, arr: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint fixedPoint(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FixedPoint(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar fixedPoint = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef fixed_point(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func fixedPoint(_ arr: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func fixedPoint(arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def fixedPoint(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun fixedPoint(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn fixed_point(arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function fixedPoint($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function fixedPoint(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (fixed-point arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1064](https://leetcode-cn.com/problems/fixed-point)", "[\u4e0d\u52a8\u70b9](/solution/1000-1099/1064.Fixed%20Point/README.md)", "`\u6570\u7ec4`,`\u4e8c\u5206\u67e5\u627e`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[1064](https://leetcode.com/problems/fixed-point)", "[Fixed Point](/solution/1000-1099/1064.Fixed%20Point/README_EN.md)", "`Array`,`Binary Search`", "Easy", "\ud83d\udd12"]}, {"question_id": "1065", "frontend_question_id": "1016", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/binary-string-with-substrings-representing-1-to-n", "url_en": "https://leetcode.com/problems/binary-string-with-substrings-representing-1-to-n", "relative_path_cn": "/solution/1000-1099/1016.Binary%20String%20With%20Substrings%20Representing%201%20To%20N/README.md", "relative_path_en": "/solution/1000-1099/1016.Binary%20String%20With%20Substrings%20Representing%201%20To%20N/README_EN.md", "title_cn": "\u5b50\u4e32\u80fd\u8868\u793a\u4ece 1 \u5230 N \u6570\u5b57\u7684\u4e8c\u8fdb\u5236\u4e32", "title_en": "Binary String With Substrings Representing 1 To N", "question_title_slug": "binary-string-with-substrings-representing-1-to-n", "content_en": "

    Given a binary string s (a string consisting only of '0' and '1's) and a positive integer n, return true if and only if for every integer x from 1 to n, the binary representation of x is a substring of s.

    \n\n

     

    \n\n

    Example 1:

    \n\n
    \nInput: s = "0110", n = 3\nOutput: true\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "0110", n = 4\nOutput: false\n
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    1. 1 <= s.length <= 1000
    2. \n\t
    3. 1 <= n <= 109
    4. \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32 S\uff08\u4e00\u4e2a\u4ec5\u7531\u82e5\u5e72 '0' \u548c '1' \u6784\u6210\u7684\u5b57\u7b26\u4e32\uff09\u548c\u4e00\u4e2a\u6b63\u6574\u6570 N\uff0c\u5982\u679c\u5bf9\u4e8e\u4ece 1 \u5230 N \u7684\u6bcf\u4e2a\u6574\u6570 X\uff0c\u5176\u4e8c\u8fdb\u5236\u8868\u793a\u90fd\u662f S \u7684\u5b50\u4e32\uff0c\u5c31\u8fd4\u56de true\uff0c\u5426\u5219\u8fd4\u56de false\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aS = "0110", N = 3\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aS = "0110", N = 4\n\u8f93\u51fa\uff1afalse\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= S.length <= 1000
    2. \n\t
    3. 1 <= N <= 10^9
    4. \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool queryString(string s, int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean queryString(String s, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def queryString(self, s, n):\n \"\"\"\n :type s: str\n :type n: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def queryString(self, s: str, n: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool queryString(char * s, int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool QueryString(string s, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number} n\n * @return {boolean}\n */\nvar queryString = function(s, n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer} n\n# @return {Boolean}\ndef query_string(s, n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func queryString(_ s: String, _ n: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func queryString(s string, n int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def queryString(s: String, n: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun queryString(s: String, n: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn query_string(s: String, n: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer $n\n * @return Boolean\n */\n function queryString($s, $n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function queryString(s: string, n: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (query-string s n)\n (-> string? exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1016](https://leetcode-cn.com/problems/binary-string-with-substrings-representing-1-to-n)", "[\u5b50\u4e32\u80fd\u8868\u793a\u4ece 1 \u5230 N \u6570\u5b57\u7684\u4e8c\u8fdb\u5236\u4e32](/solution/1000-1099/1016.Binary%20String%20With%20Substrings%20Representing%201%20To%20N/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1016](https://leetcode.com/problems/binary-string-with-substrings-representing-1-to-n)", "[Binary String With Substrings Representing 1 To N](/solution/1000-1099/1016.Binary%20String%20With%20Substrings%20Representing%201%20To%20N/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "1064", "frontend_question_id": "1015", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/smallest-integer-divisible-by-k", "url_en": "https://leetcode.com/problems/smallest-integer-divisible-by-k", "relative_path_cn": "/solution/1000-1099/1015.Smallest%20Integer%20Divisible%20by%20K/README.md", "relative_path_en": "/solution/1000-1099/1015.Smallest%20Integer%20Divisible%20by%20K/README_EN.md", "title_cn": "\u53ef\u88ab K \u6574\u9664\u7684\u6700\u5c0f\u6574\u6570", "title_en": "Smallest Integer Divisible by K", "question_title_slug": "smallest-integer-divisible-by-k", "content_en": "

    Given a positive integer k, you need to find the length of the smallest positive integer n such that n is divisible by k, and n only contains the digit 1.

    \n\n

    Return the length of n. If there is no such n, return -1.

    \n\n

    Note: n may not fit in a 64-bit signed integer.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: k = 1\nOutput: 1\nExplanation: The smallest answer is n = 1, which has length 1.\n
    \n\n

    Example 2:

    \n\n
    \nInput: k = 2\nOutput: -1\nExplanation: There is no such positive integer n divisible by 2.\n
    \n\n

    Example 3:

    \n\n
    \nInput: k = 3\nOutput: 3\nExplanation: The smallest answer is n = 111, which has length 3.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= k <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u6b63\u6574\u6570 K\uff0c\u4f60\u9700\u8981\u627e\u51fa\u53ef\u4ee5\u88ab K \u6574\u9664\u7684\u3001\u4ec5\u5305\u542b\u6570\u5b57 1 \u7684\u6700\u5c0f\u6b63\u6574\u6570 N\u3002

    \n\n

    \u8fd4\u56de N \u7684\u957f\u5ea6\u3002\u5982\u679c\u4e0d\u5b58\u5728\u8fd9\u6837\u7684 N\uff0c\u5c31\u8fd4\u56de -1\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a1\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u6700\u5c0f\u7684\u7b54\u6848\u662f N = 1\uff0c\u5176\u957f\u5ea6\u4e3a 1\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a2\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u4e0d\u5b58\u5728\u53ef\u88ab 2 \u6574\u9664\u7684\u6b63\u6574\u6570 N \u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1a3\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6700\u5c0f\u7684\u7b54\u6848\u662f N = 111\uff0c\u5176\u957f\u5ea6\u4e3a 3\u3002
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= K <= 10^5
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int smallestRepunitDivByK(int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int smallestRepunitDivByK(int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def smallestRepunitDivByK(self, k):\n \"\"\"\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def smallestRepunitDivByK(self, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint smallestRepunitDivByK(int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SmallestRepunitDivByK(int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} k\n * @return {number}\n */\nvar smallestRepunitDivByK = function(k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} k\n# @return {Integer}\ndef smallest_repunit_div_by_k(k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func smallestRepunitDivByK(_ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func smallestRepunitDivByK(k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def smallestRepunitDivByK(k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun smallestRepunitDivByK(k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn smallest_repunit_div_by_k(k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $k\n * @return Integer\n */\n function smallestRepunitDivByK($k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function smallestRepunitDivByK(k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (smallest-repunit-div-by-k k)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1015](https://leetcode-cn.com/problems/smallest-integer-divisible-by-k)", "[\u53ef\u88ab K \u6574\u9664\u7684\u6700\u5c0f\u6574\u6570](/solution/1000-1099/1015.Smallest%20Integer%20Divisible%20by%20K/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1015](https://leetcode.com/problems/smallest-integer-divisible-by-k)", "[Smallest Integer Divisible by K](/solution/1000-1099/1015.Smallest%20Integer%20Divisible%20by%20K/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "1063", "frontend_question_id": "1014", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/best-sightseeing-pair", "url_en": "https://leetcode.com/problems/best-sightseeing-pair", "relative_path_cn": "/solution/1000-1099/1014.Best%20Sightseeing%20Pair/README.md", "relative_path_en": "/solution/1000-1099/1014.Best%20Sightseeing%20Pair/README_EN.md", "title_cn": "\u6700\u4f73\u89c2\u5149\u7ec4\u5408", "title_en": "Best Sightseeing Pair", "question_title_slug": "best-sightseeing-pair", "content_en": "

    You are given an integer array values where values[i] represents the value of the ith sightseeing spot. Two sightseeing spots i and j have a distance j - i between them.

    \n\n

    The score of a pair (i < j) of sightseeing spots is values[i] + values[j] + i - j: the sum of the values of the sightseeing spots, minus the distance between them.

    \n\n

    Return the maximum score of a pair of sightseeing spots.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: values = [8,1,5,2,6]\nOutput: 11\nExplanation: i = 0, j = 2, values[i] + values[j] + i - j = 8 + 5 + 0 - 2 = 11\n
    \n\n

    Example 2:

    \n\n
    \nInput: values = [1,2]\nOutput: 2\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= values.length <= 5 * 104
    • \n\t
    • 1 <= values[i] <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6b63\u6574\u6570\u6570\u7ec4 values\uff0c\u5176\u4e2d values[i]\u00a0\u8868\u793a\u7b2c i \u4e2a\u89c2\u5149\u666f\u70b9\u7684\u8bc4\u5206\uff0c\u5e76\u4e14\u4e24\u4e2a\u666f\u70b9\u00a0i \u548c\u00a0j\u00a0\u4e4b\u95f4\u7684 \u8ddd\u79bb \u4e3a\u00a0j - i\u3002

    \n\n

    \u4e00\u5bf9\u666f\u70b9\uff08i < j\uff09\u7ec4\u6210\u7684\u89c2\u5149\u7ec4\u5408\u7684\u5f97\u5206\u4e3a values[i] + values[j] + i - j \uff0c\u4e5f\u5c31\u662f\u666f\u70b9\u7684\u8bc4\u5206\u4e4b\u548c \u51cf\u53bb \u5b83\u4eec\u4e24\u8005\u4e4b\u95f4\u7684\u8ddd\u79bb\u3002

    \n\n

    \u8fd4\u56de\u4e00\u5bf9\u89c2\u5149\u666f\u70b9\u80fd\u53d6\u5f97\u7684\u6700\u9ad8\u5206\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1avalues = [8,1,5,2,6]\n\u8f93\u51fa\uff1a11\n\u89e3\u91ca\uff1ai = 0, j = 2, values[i] + values[j] + i - j = 8 + 5 + 0 - 2 = 11\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1avalues = [1,2]\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= values.length <= 5 * 104
    • \n\t
    • 1 <= values[i] <= 1000
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxScoreSightseeingPair(vector& values) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxScoreSightseeingPair(int[] values) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxScoreSightseeingPair(self, values):\n \"\"\"\n :type values: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxScoreSightseeingPair(self, values: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxScoreSightseeingPair(int* values, int valuesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxScoreSightseeingPair(int[] values) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} values\n * @return {number}\n */\nvar maxScoreSightseeingPair = function(values) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} values\n# @return {Integer}\ndef max_score_sightseeing_pair(values)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxScoreSightseeingPair(_ values: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxScoreSightseeingPair(values []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxScoreSightseeingPair(values: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxScoreSightseeingPair(values: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_score_sightseeing_pair(values: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $values\n * @return Integer\n */\n function maxScoreSightseeingPair($values) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxScoreSightseeingPair(values: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-score-sightseeing-pair values)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1014](https://leetcode-cn.com/problems/best-sightseeing-pair)", "[\u6700\u4f73\u89c2\u5149\u7ec4\u5408](/solution/1000-1099/1014.Best%20Sightseeing%20Pair/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1014](https://leetcode.com/problems/best-sightseeing-pair)", "[Best Sightseeing Pair](/solution/1000-1099/1014.Best%20Sightseeing%20Pair/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "1062", "frontend_question_id": "1013", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/partition-array-into-three-parts-with-equal-sum", "url_en": "https://leetcode.com/problems/partition-array-into-three-parts-with-equal-sum", "relative_path_cn": "/solution/1000-1099/1013.Partition%20Array%20Into%20Three%20Parts%20With%20Equal%20Sum/README.md", "relative_path_en": "/solution/1000-1099/1013.Partition%20Array%20Into%20Three%20Parts%20With%20Equal%20Sum/README_EN.md", "title_cn": "\u5c06\u6570\u7ec4\u5206\u6210\u548c\u76f8\u7b49\u7684\u4e09\u4e2a\u90e8\u5206", "title_en": "Partition Array Into Three Parts With Equal Sum", "question_title_slug": "partition-array-into-three-parts-with-equal-sum", "content_en": "

    Given an array of integers arr, return true if we can partition the array into three non-empty parts with equal sums.

    \n\n

    Formally, we can partition the array if we can find indexes i + 1 < j with (arr[0] + arr[1] + ... + arr[i] == arr[i + 1] + arr[i + 2] + ... + arr[j - 1] == arr[j] + arr[j + 1] + ... + arr[arr.length - 1])

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr = [0,2,1,-6,6,-7,9,1,2,0,1]\nOutput: true\nExplanation: 0 + 2 + 1 = -6 + 6 - 7 + 9 + 1 = 2 + 0 + 1\n
    \n\n

    Example 2:

    \n\n
    \nInput: arr = [0,2,1,-6,6,7,9,-1,2,0,1]\nOutput: false\n
    \n\n

    Example 3:

    \n\n
    \nInput: arr = [3,3,6,5,-2,2,5,1,-9,4]\nOutput: true\nExplanation: 3 + 3 = 6 = 5 - 2 + 2 + 5 + 1 - 9 + 4\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 3 <= arr.length <= 5 * 104
    • \n\t
    • -104 <= arr[i] <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 A\uff0c\u53ea\u6709\u53ef\u4ee5\u5c06\u5176\u5212\u5206\u4e3a\u4e09\u4e2a\u548c\u76f8\u7b49\u7684\u975e\u7a7a\u90e8\u5206\u65f6\u624d\u8fd4\u56de true\uff0c\u5426\u5219\u8fd4\u56de false\u3002

    \n\n

    \u5f62\u5f0f\u4e0a\uff0c\u5982\u679c\u53ef\u4ee5\u627e\u51fa\u7d22\u5f15 i+1 < j \u4e14\u6ee1\u8db3 A[0] + A[1] + ... + A[i] == A[i+1] + A[i+2] + ... + A[j-1] == A[j] + A[j-1] + ... + A[A.length - 1] \u5c31\u53ef\u4ee5\u5c06\u6570\u7ec4\u4e09\u7b49\u5206\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a[0,2,1,-6,6,-7,9,1,2,0,1]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a0 + 2 + 1 = -6 + 6 - 7 + 9 + 1 = 2 + 0 + 1\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a[0,2,1,-6,6,7,9,-1,2,0,1]\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1a[3,3,6,5,-2,2,5,1,-9,4]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a3 + 3 = 6 = 5 - 2 + 2 + 5 + 1 - 9 + 4\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 3 <= A.length <= 50000
    2. \n\t
    3. -10^4 <= A[i] <= 10^4
    4. \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canThreePartsEqualSum(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canThreePartsEqualSum(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canThreePartsEqualSum(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canThreePartsEqualSum(self, arr: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canThreePartsEqualSum(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanThreePartsEqualSum(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {boolean}\n */\nvar canThreePartsEqualSum = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Boolean}\ndef can_three_parts_equal_sum(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canThreePartsEqualSum(_ arr: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canThreePartsEqualSum(arr []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canThreePartsEqualSum(arr: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canThreePartsEqualSum(arr: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_three_parts_equal_sum(arr: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Boolean\n */\n function canThreePartsEqualSum($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canThreePartsEqualSum(arr: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-three-parts-equal-sum arr)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1013](https://leetcode-cn.com/problems/partition-array-into-three-parts-with-equal-sum)", "[\u5c06\u6570\u7ec4\u5206\u6210\u548c\u76f8\u7b49\u7684\u4e09\u4e2a\u90e8\u5206](/solution/1000-1099/1013.Partition%20Array%20Into%20Three%20Parts%20With%20Equal%20Sum/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[1013](https://leetcode.com/problems/partition-array-into-three-parts-with-equal-sum)", "[Partition Array Into Three Parts With Equal Sum](/solution/1000-1099/1013.Partition%20Array%20Into%20Three%20Parts%20With%20Equal%20Sum/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1061", "frontend_question_id": "1063", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/number-of-valid-subarrays", "url_en": "https://leetcode.com/problems/number-of-valid-subarrays", "relative_path_cn": "/solution/1000-1099/1063.Number%20of%20Valid%20Subarrays/README.md", "relative_path_en": "/solution/1000-1099/1063.Number%20of%20Valid%20Subarrays/README_EN.md", "title_cn": "\u6709\u6548\u5b50\u6570\u7ec4\u7684\u6570\u76ee", "title_en": "Number of Valid Subarrays", "question_title_slug": "number-of-valid-subarrays", "content_en": "

    Given an array nums of integers, return the number of non-empty continuous subarrays that satisfy the following condition:

    \n\n

    The leftmost element of the subarray is not larger than other elements in the subarray.

    \n\n

     

    \n\n

    Example 1:

    \n\n
    \nInput: nums = [1,4,2,5,3]\nOutput: 11\nExplanation: There are 11 valid subarrays: [1],[4],[2],[5],[3],[1,4],[2,5],[1,4,2],[2,5,3],[1,4,2,5],[1,4,2,5,3].\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [3,2,1]\nOutput: 3\nExplanation: The 3 valid subarrays are: [3],[2],[1].\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [2,2,2]\nOutput: 6\nExplanation: There are 6 valid subarrays: [2],[2],[2],[2,2],[2,2],[2,2,2].\n
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    1. 1 <= nums.length <= 50000
    2. \n\t
    3. 0 <= nums[i] <= 100000
    4. \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 A\uff0c\u8fd4\u56de\u6ee1\u8db3\u4e0b\u9762\u6761\u4ef6\u7684 \u975e\u7a7a\u3001\u8fde\u7eed \u5b50\u6570\u7ec4\u7684\u6570\u76ee\uff1a

    \n\n

    \u5b50\u6570\u7ec4\u4e2d\uff0c\u6700\u5de6\u4fa7\u7684\u5143\u7d20\u4e0d\u5927\u4e8e\u5176\u4ed6\u5143\u7d20\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a[1,4,2,5,3]\n\u8f93\u51fa\uff1a11\n\u89e3\u91ca\uff1a\u6709 11 \u4e2a\u6709\u6548\u5b50\u6570\u7ec4\uff0c\u5206\u522b\u662f\uff1a[1],[4],[2],[5],[3],[1,4],[2,5],[1,4,2],[2,5,3],[1,4,2,5],[1,4,2,5,3] \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a[3,2,1]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6709 3 \u4e2a\u6709\u6548\u5b50\u6570\u7ec4\uff0c\u5206\u522b\u662f\uff1a[3],[2],[1] \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1a[2,2,2]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u6709 6 \u4e2a\u6709\u6548\u5b50\u6570\u7ec4\uff0c\u5206\u522b\u4e3a\u662f\uff1a[2],[2],[2],[2,2],[2,2],[2,2,2] \u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= A.length <= 50000
    2. \n\t
    3. 0 <= A[i] <= 100000
    4. \n
    \n", "tags_en": ["Stack"], "tags_cn": ["\u6808"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int validSubarrays(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int validSubarrays(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def validSubarrays(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def validSubarrays(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint validSubarrays(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ValidSubarrays(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar validSubarrays = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef valid_subarrays(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func validSubarrays(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func validSubarrays(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def validSubarrays(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun validSubarrays(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn valid_subarrays(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function validSubarrays($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function validSubarrays(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (valid-subarrays nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1063](https://leetcode-cn.com/problems/number-of-valid-subarrays)", "[\u6709\u6548\u5b50\u6570\u7ec4\u7684\u6570\u76ee](/solution/1000-1099/1063.Number%20of%20Valid%20Subarrays/README.md)", "`\u6808`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[1063](https://leetcode.com/problems/number-of-valid-subarrays)", "[Number of Valid Subarrays](/solution/1000-1099/1063.Number%20of%20Valid%20Subarrays/README_EN.md)", "`Stack`", "Hard", "\ud83d\udd12"]}, {"question_id": "1060", "frontend_question_id": "1062", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/longest-repeating-substring", "url_en": "https://leetcode.com/problems/longest-repeating-substring", "relative_path_cn": "/solution/1000-1099/1062.Longest%20Repeating%20Substring/README.md", "relative_path_en": "/solution/1000-1099/1062.Longest%20Repeating%20Substring/README_EN.md", "title_cn": "\u6700\u957f\u91cd\u590d\u5b50\u4e32", "title_en": "Longest Repeating Substring", "question_title_slug": "longest-repeating-substring", "content_en": "

    Given a string s, find out the length of the longest repeating substring(s). Return 0 if no repeating substring exists.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "abcd"\nOutput: 0\nExplanation: There is no repeating substring.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "abbaba"\nOutput: 2\nExplanation: The longest repeating substrings are "ab" and "ba", each of which occurs twice.\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "aabcaabdaab"\nOutput: 3\nExplanation: The longest repeating substring is "aab", which occurs 3 times.\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "aaaaa"\nOutput: 4\nExplanation: The longest repeating substring is "aaaa", which occurs twice.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The string s consists of only lowercase English letters from 'a' - 'z'.
    • \n\t
    • 1 <= s.length <= 1500
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u5b57\u7b26\u4e32 S\uff0c\u627e\u51fa\u6700\u957f\u91cd\u590d\u5b50\u4e32\u7684\u957f\u5ea6\u3002\u5982\u679c\u4e0d\u5b58\u5728\u91cd\u590d\u5b50\u4e32\u5c31\u8fd4\u56de 0\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a"abcd"\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6ca1\u6709\u91cd\u590d\u5b50\u4e32\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a"abbaba"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6700\u957f\u7684\u91cd\u590d\u5b50\u4e32\u4e3a "ab" \u548c "ba"\uff0c\u6bcf\u4e2a\u51fa\u73b0 2 \u6b21\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1a"aabcaabdaab"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6700\u957f\u7684\u91cd\u590d\u5b50\u4e32\u4e3a "aab"\uff0c\u51fa\u73b0 3 \u6b21\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1a"aaaaa"\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u6700\u957f\u7684\u91cd\u590d\u5b50\u4e32\u4e3a "aaaa"\uff0c\u51fa\u73b0 2 \u6b21\u3002
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. \u5b57\u7b26\u4e32 S \u4ec5\u5305\u542b\u4ece 'a' \u5230 'z' \u7684\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    2. \n\t
    3. 1 <= S.length <= 1500
    4. \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int longestRepeatingSubstring(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int longestRepeatingSubstring(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestRepeatingSubstring(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestRepeatingSubstring(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint longestRepeatingSubstring(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LongestRepeatingSubstring(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar longestRepeatingSubstring = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef longest_repeating_substring(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestRepeatingSubstring(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestRepeatingSubstring(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestRepeatingSubstring(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestRepeatingSubstring(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_repeating_substring(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function longestRepeatingSubstring($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestRepeatingSubstring(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-repeating-substring s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1062](https://leetcode-cn.com/problems/longest-repeating-substring)", "[\u6700\u957f\u91cd\u590d\u5b50\u4e32](/solution/1000-1099/1062.Longest%20Repeating%20Substring/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1062](https://leetcode.com/problems/longest-repeating-substring)", "[Longest Repeating Substring](/solution/1000-1099/1062.Longest%20Repeating%20Substring/README_EN.md)", "`String`", "Medium", "\ud83d\udd12"]}, {"question_id": "1059", "frontend_question_id": "1060", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/missing-element-in-sorted-array", "url_en": "https://leetcode.com/problems/missing-element-in-sorted-array", "relative_path_cn": "/solution/1000-1099/1060.Missing%20Element%20in%20Sorted%20Array/README.md", "relative_path_en": "/solution/1000-1099/1060.Missing%20Element%20in%20Sorted%20Array/README_EN.md", "title_cn": "\u6709\u5e8f\u6570\u7ec4\u4e2d\u7684\u7f3a\u5931\u5143\u7d20", "title_en": "Missing Element in Sorted Array", "question_title_slug": "missing-element-in-sorted-array", "content_en": "

    Given an integer array nums which is sorted in ascending order and all of its elements are unique and given also an integer k, return the kth missing number starting from the leftmost number of the array.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [4,7,9,10], k = 1\nOutput: 5\nExplanation: The first missing number is 5.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [4,7,9,10], k = 3\nOutput: 8\nExplanation: The missing numbers are [5,6,8,...], hence the third missing number is 8.\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [1,2,4], k = 3\nOutput: 6\nExplanation: The missing numbers are [3,5,6,7,...], hence the third missing number is 6.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 5 * 104
    • \n\t
    • 1 <= nums[i] <= 107
    • \n\t
    • nums is sorted in ascending order, and all the elements are unique.
    • \n\t
    • 1 <= k <= 108
    • \n
    \n\n

     

    \nFollow up: Can you find a logarithmic time complexity (i.e., O(log(n))) solution?", "content_cn": "

    \u73b0\u6709\u4e00\u4e2a\u6309 \u5347\u5e8f \u6392\u5217\u7684\u6574\u6570\u6570\u7ec4 nums \uff0c\u5176\u4e2d\u6bcf\u4e2a\u6570\u5b57\u90fd \u4e92\u4e0d\u76f8\u540c \u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 k \uff0c\u8bf7\u4f60\u627e\u51fa\u5e76\u8fd4\u56de\u4ece\u6570\u7ec4\u6700\u5de6\u8fb9\u5f00\u59cb\u7684\u7b2c k \u4e2a\u7f3a\u5931\u6570\u5b57\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [4,7,9,10], k = 1\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u7b2c\u4e00\u4e2a\u7f3a\u5931\u6570\u5b57\u4e3a 5 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [4,7,9,10], k = 3\n\u8f93\u51fa\uff1a8\n\u89e3\u91ca\uff1a\u7f3a\u5931\u6570\u5b57\u6709 [5,6,8,...]\uff0c\u56e0\u6b64\u7b2c\u4e09\u4e2a\u7f3a\u5931\u6570\u5b57\u4e3a 8 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,4], k = 3\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u7f3a\u5931\u6570\u5b57\u6709 [3,5,6,7,...]\uff0c\u56e0\u6b64\u7b2c\u4e09\u4e2a\u7f3a\u5931\u6570\u5b57\u4e3a 6 \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 5 * 104
    • \n\t
    • 1 <= nums[i] <= 107
    • \n\t
    • nums \u6309 \u5347\u5e8f \u6392\u5217\uff0c\u5176\u4e2d\u6240\u6709\u5143\u7d20 \u4e92\u4e0d\u76f8\u540c \u3002
    • \n\t
    • 1 <= k <= 108
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u53ef\u4ee5\u8bbe\u8ba1\u4e00\u4e2a\u5bf9\u6570\u65f6\u95f4\u590d\u6742\u5ea6\uff08\u5373\uff0cO(log(n))\uff09\u7684\u89e3\u51b3\u65b9\u6848\u5417\uff1f

    \n", "tags_en": ["Binary Search"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int missingElement(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int missingElement(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def missingElement(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def missingElement(self, nums: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint missingElement(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MissingElement(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar missingElement = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef missing_element(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func missingElement(_ nums: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func missingElement(nums []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def missingElement(nums: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun missingElement(nums: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn missing_element(nums: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer\n */\n function missingElement($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function missingElement(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (missing-element nums k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1060](https://leetcode-cn.com/problems/missing-element-in-sorted-array)", "[\u6709\u5e8f\u6570\u7ec4\u4e2d\u7684\u7f3a\u5931\u5143\u7d20](/solution/1000-1099/1060.Missing%20Element%20in%20Sorted%20Array/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1060](https://leetcode.com/problems/missing-element-in-sorted-array)", "[Missing Element in Sorted Array](/solution/1000-1099/1060.Missing%20Element%20in%20Sorted%20Array/README_EN.md)", "`Binary Search`", "Medium", "\ud83d\udd12"]}, {"question_id": "1058", "frontend_question_id": "1061", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/lexicographically-smallest-equivalent-string", "url_en": "https://leetcode.com/problems/lexicographically-smallest-equivalent-string", "relative_path_cn": "/solution/1000-1099/1061.Lexicographically%20Smallest%20Equivalent%20String/README.md", "relative_path_en": "/solution/1000-1099/1061.Lexicographically%20Smallest%20Equivalent%20String/README_EN.md", "title_cn": "\u6309\u5b57\u5178\u5e8f\u6392\u5217\u6700\u5c0f\u7684\u7b49\u6548\u5b57\u7b26\u4e32", "title_en": "Lexicographically Smallest Equivalent String", "question_title_slug": "lexicographically-smallest-equivalent-string", "content_en": "

    Given strings s1 and s2 of the same length, we say s1[i] and s2[i] are equivalent characters. For example, if s1 = "abc" and s2 = "cde", then we have 'a' == 'c', 'b' == 'd', 'c' == 'e'.

    \n\n

    Equivalent characters follow the usual rules of any equivalence relation:

    \n\n
      \n\t
    • Reflexivity: 'a' == 'a'
    • \n\t
    • Symmetry: 'a' == 'b' implies 'b' == 'a'
    • \n\t
    • Transitivity: 'a' == 'b' and 'b' == 'c' implies 'a' == 'c'
    • \n
    \n\n

    For example, given the equivalency information from s1 and s2 above and baseStr = "eed", "acd" and "aab" are equivalent strings of baseStr, and "aab" is the lexicographically smallest equivalent string of baseStr.

    \n\n

    Return the lexicographically smallest equivalent string of baseStr by using the equivalency information from s1 and s2.

    \n\n

     

    \n\n

    Example 1:

    \n\n
    \nInput: s1 = "parker", s2 = "morris", baseStr = "parser"\nOutput: "makkek"\nExplanation: Based on the equivalency information in s1 and s2, we can group their characters as [m,p], [a,o], [k,r,s], [e,i]. The characters in each group are equivalent and sorted in lexicographical order. So the answer is "makkek".\n
    \n\n

    Example 2:

    \n\n
    \nInput: s1 = "hello", s2 = "world", baseStr = "hold"\nOutput: "hdld"\nExplanation:  Based on the equivalency information in s1 and s2, we can group their characters as [h,w], [d,e,o], [l,r]. So only the second letter 'o' in baseStr is changed to 'd', the answer is "hdld".\n
    \n\n

    Example 3:

    \n\n
    \nInput: s1 = "leetcode", s2 = "programs", baseStr = "sourcecode"\nOutput: "aauaaaaada"\nExplanation:  We group the equivalent characters in s1 and s2 as [a,o,e,r,s,c], [l,p], [g,t] and [d,m], thus all letters in baseStr except 'u' and 'd' are transformed to 'a', the answer is "aauaaaaada".\n
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    1. Strings s1, s2, and baseStr consist of only lowercase English letters from 'a' - 'z'.
    2. \n\t
    3. The lengths of string s1, s2, and baseStr are between 1 and 1000.
    4. \n\t
    5. Strings s1 and s2 are of the same length.
    6. \n
    \n", "content_cn": "

    \u7ed9\u51fa\u957f\u5ea6\u76f8\u540c\u7684\u4e24\u4e2a\u5b57\u7b26\u4e32\uff1aA \u548c B\uff0c\u5176\u4e2d A[i] \u548c B[i] \u662f\u4e00\u7ec4\u7b49\u4ef7\u5b57\u7b26\u3002\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u5982\u679c A = "abc" \u4e14 B = "cde"\uff0c\u90a3\u4e48\u5c31\u6709 'a' == 'c', 'b' == 'd', 'c' == 'e'\u3002

    \n\n

    \u7b49\u4ef7\u5b57\u7b26\u9075\u5faa\u4efb\u4f55\u7b49\u4ef7\u5173\u7cfb\u7684\u4e00\u822c\u89c4\u5219\uff1a

    \n\n
      \n\t
    • \u81ea\u53cd\u6027\uff1a'a' == 'a'
    • \n\t
    • \u5bf9\u79f0\u6027\uff1a'a' == 'b' \u5219\u5fc5\u5b9a\u6709 'b' == 'a'
    • \n\t
    • \u4f20\u9012\u6027\uff1a'a' == 'b' \u4e14 'b' == 'c' \u5c31\u8868\u660e 'a' == 'c'
    • \n
    \n\n

    \u4f8b\u5982\uff0cA \u548c B \u7684\u7b49\u4ef7\u4fe1\u606f\u548c\u4e4b\u524d\u7684\u4f8b\u5b50\u4e00\u6837\uff0c\u90a3\u4e48 S = "eed", "acd" \u6216 "aab"\uff0c\u8fd9\u4e09\u4e2a\u5b57\u7b26\u4e32\u90fd\u662f\u7b49\u4ef7\u7684\uff0c\u800c "aab" \u662f S \u7684\u6309\u5b57\u5178\u5e8f\u6700\u5c0f\u7684\u7b49\u4ef7\u5b57\u7b26\u4e32

    \n\n

    \u5229\u7528 A \u548c B \u7684\u7b49\u4ef7\u4fe1\u606f\uff0c\u627e\u51fa\u5e76\u8fd4\u56de S \u7684\u6309\u5b57\u5178\u5e8f\u6392\u5217\u6700\u5c0f\u7684\u7b49\u4ef7\u5b57\u7b26\u4e32\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aA = "parker", B = "morris", S = "parser"\n\u8f93\u51fa\uff1a"makkek"\n\u89e3\u91ca\uff1a\u6839\u636e A \u548c B \u4e2d\u7684\u7b49\u4ef7\u4fe1\u606f\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u8fd9\u4e9b\u5b57\u7b26\u5206\u4e3a [m,p], [a,o], [k,r,s], [e,i] \u5171 4 \u7ec4\u3002\u6bcf\u7ec4\u4e2d\u7684\u5b57\u7b26\u90fd\u662f\u7b49\u4ef7\u7684\uff0c\u5e76\u6309\u5b57\u5178\u5e8f\u6392\u5217\u3002\u6240\u4ee5\u7b54\u6848\u662f "makkek"\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aA = "hello", B = "world", S = "hold"\n\u8f93\u51fa\uff1a"hdld"\n\u89e3\u91ca\uff1a\u6839\u636e A \u548c B \u4e2d\u7684\u7b49\u4ef7\u4fe1\u606f\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u8fd9\u4e9b\u5b57\u7b26\u5206\u4e3a [h,w], [d,e,o], [l,r] \u5171 3 \u7ec4\u3002\u6240\u4ee5\u53ea\u6709 S \u4e2d\u7684\u7b2c\u4e8c\u4e2a\u5b57\u7b26 'o' \u53d8\u6210 'd'\uff0c\u6700\u540e\u7b54\u6848\u4e3a "hdld"\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aA = "leetcode", B = "programs", S = "sourcecode"\n\u8f93\u51fa\uff1a"aauaaaaada"\n\u89e3\u91ca\uff1a\u6211\u4eec\u53ef\u4ee5\u628a A \u548c B \u4e2d\u7684\u7b49\u4ef7\u5b57\u7b26\u5206\u4e3a [a,o,e,r,s,c], [l,p], [g,t] \u548c [d,m] \u5171 4 \u7ec4\uff0c\u56e0\u6b64 S \u4e2d\u9664\u4e86 'u' \u548c 'd' \u4e4b\u5916\u7684\u6240\u6709\u5b57\u6bcd\u90fd\u8f6c\u5316\u6210\u4e86 'a'\uff0c\u6700\u540e\u7b54\u6848\u4e3a "aauaaaaada"\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. \u5b57\u7b26\u4e32 A\uff0cB \u548c S \u4ec5\u6709\u4ece 'a' \u5230 'z' \u7684\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\u3002
    2. \n\t
    3. \u5b57\u7b26\u4e32 A\uff0cB \u548c S \u7684\u957f\u5ea6\u5728 1 \u5230 1000 \u4e4b\u95f4\u3002
    4. \n\t
    5. \u5b57\u7b26\u4e32 A \u548c B \u957f\u5ea6\u76f8\u540c\u3002
    6. \n
    \n", "tags_en": ["Depth-first Search", "Union Find"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e76\u67e5\u96c6"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string smallestEquivalentString(string s1, string s2, string baseStr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String smallestEquivalentString(String s1, String s2, String baseStr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def smallestEquivalentString(self, s1, s2, baseStr):\n \"\"\"\n :type s1: str\n :type s2: str\n :type baseStr: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def smallestEquivalentString(self, s1: str, s2: str, baseStr: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * smallestEquivalentString(char * s1, char * s2, char * baseStr){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string SmallestEquivalentString(string s1, string s2, string baseStr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s1\n * @param {string} s2\n * @param {string} baseStr\n * @return {string}\n */\nvar smallestEquivalentString = function(s1, s2, baseStr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s1\n# @param {String} s2\n# @param {String} base_str\n# @return {String}\ndef smallest_equivalent_string(s1, s2, base_str)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func smallestEquivalentString(_ s1: String, _ s2: String, _ baseStr: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func smallestEquivalentString(s1 string, s2 string, baseStr string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def smallestEquivalentString(s1: String, s2: String, baseStr: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun smallestEquivalentString(s1: String, s2: String, baseStr: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn smallest_equivalent_string(s1: String, s2: String, base_str: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s1\n * @param String $s2\n * @param String $baseStr\n * @return String\n */\n function smallestEquivalentString($s1, $s2, $baseStr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function smallestEquivalentString(s1: string, s2: string, baseStr: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (smallest-equivalent-string s1 s2 baseStr)\n (-> string? string? string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1061](https://leetcode-cn.com/problems/lexicographically-smallest-equivalent-string)", "[\u6309\u5b57\u5178\u5e8f\u6392\u5217\u6700\u5c0f\u7684\u7b49\u6548\u5b57\u7b26\u4e32](/solution/1000-1099/1061.Lexicographically%20Smallest%20Equivalent%20String/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e76\u67e5\u96c6`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1061](https://leetcode.com/problems/lexicographically-smallest-equivalent-string)", "[Lexicographically Smallest Equivalent String](/solution/1000-1099/1061.Lexicographically%20Smallest%20Equivalent%20String/README_EN.md)", "`Depth-first Search`,`Union Find`", "Medium", "\ud83d\udd12"]}, {"question_id": "1057", "frontend_question_id": "1012", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/numbers-with-repeated-digits", "url_en": "https://leetcode.com/problems/numbers-with-repeated-digits", "relative_path_cn": "/solution/1000-1099/1012.Numbers%20With%20Repeated%20Digits/README.md", "relative_path_en": "/solution/1000-1099/1012.Numbers%20With%20Repeated%20Digits/README_EN.md", "title_cn": "\u81f3\u5c11\u6709 1 \u4f4d\u91cd\u590d\u7684\u6570\u5b57", "title_en": "Numbers With Repeated Digits", "question_title_slug": "numbers-with-repeated-digits", "content_en": "

    Given a positive integer n, return the number of positive integers less than or equal to n that have at least 1 repeated digit.

    \n\n

     

    \n\n
    \n

    Example 1:

    \n\n
    \nInput: n = 20\nOutput: 1\nExplanation: The only positive number (<= 20) with at least 1 repeated digit is 11.\n
    \n\n
    \n

    Example 2:

    \n\n
    \nInput: n = 100\nOutput: 10\nExplanation: The positive numbers (<= 100) with atleast 1 repeated digit are 11, 22, 33, 44, 55, 66, 77, 88, 99, and 100.\n
    \n\n
    \n

    Example 3:

    \n\n
    \nInput: n = 1000\nOutput: 262\n
    \n
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    1. 1 <= n <= 109
    2. \n
    \n
    \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u6b63\u6574\u6570 N\uff0c\u8fd4\u56de\u5c0f\u4e8e\u7b49\u4e8e N \u4e14\u5177\u6709\u81f3\u5c11 1 \u4f4d\u91cd\u590d\u6570\u5b57\u7684\u6b63\u6574\u6570\u7684\u4e2a\u6570\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a20\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u5177\u6709\u81f3\u5c11 1 \u4f4d\u91cd\u590d\u6570\u5b57\u7684\u6b63\u6570\uff08<= 20\uff09\u53ea\u6709 11 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a100\n\u8f93\u51fa\uff1a10\n\u89e3\u91ca\uff1a\u5177\u6709\u81f3\u5c11 1 \u4f4d\u91cd\u590d\u6570\u5b57\u7684\u6b63\u6570\uff08<= 100\uff09\u6709 11\uff0c22\uff0c33\uff0c44\uff0c55\uff0c66\uff0c77\uff0c88\uff0c99 \u548c 100 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1a1000\n\u8f93\u51fa\uff1a262\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= N <= 10^9
    2. \n
    \n", "tags_en": ["Math", "Dynamic Programming"], "tags_cn": ["\u6570\u5b66", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numDupDigitsAtMostN(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numDupDigitsAtMostN(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numDupDigitsAtMostN(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numDupDigitsAtMostN(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numDupDigitsAtMostN(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumDupDigitsAtMostN(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar numDupDigitsAtMostN = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef num_dup_digits_at_most_n(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numDupDigitsAtMostN(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numDupDigitsAtMostN(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numDupDigitsAtMostN(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numDupDigitsAtMostN(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_dup_digits_at_most_n(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function numDupDigitsAtMostN($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numDupDigitsAtMostN(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-dup-digits-at-most-n n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1012](https://leetcode-cn.com/problems/numbers-with-repeated-digits)", "[\u81f3\u5c11\u6709 1 \u4f4d\u91cd\u590d\u7684\u6570\u5b57](/solution/1000-1099/1012.Numbers%20With%20Repeated%20Digits/README.md)", "`\u6570\u5b66`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1012](https://leetcode.com/problems/numbers-with-repeated-digits)", "[Numbers With Repeated Digits](/solution/1000-1099/1012.Numbers%20With%20Repeated%20Digits/README_EN.md)", "`Math`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "1056", "frontend_question_id": "1011", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/capacity-to-ship-packages-within-d-days", "url_en": "https://leetcode.com/problems/capacity-to-ship-packages-within-d-days", "relative_path_cn": "/solution/1000-1099/1011.Capacity%20To%20Ship%20Packages%20Within%20D%20Days/README.md", "relative_path_en": "/solution/1000-1099/1011.Capacity%20To%20Ship%20Packages%20Within%20D%20Days/README_EN.md", "title_cn": "\u5728 D \u5929\u5185\u9001\u8fbe\u5305\u88f9\u7684\u80fd\u529b", "title_en": "Capacity To Ship Packages Within D Days", "question_title_slug": "capacity-to-ship-packages-within-d-days", "content_en": "

    A conveyor belt has packages that must be shipped from one port to another within days days.

    \n\n

    The ith package on the conveyor belt has a weight of weights[i]. Each day, we load the ship with packages on the conveyor belt (in the order given by weights). We may not load more weight than the maximum weight capacity of the ship.

    \n\n

    Return the least weight capacity of the ship that will result in all the packages on the conveyor belt being shipped within days days.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: weights = [1,2,3,4,5,6,7,8,9,10], days = 5\nOutput: 15\nExplanation: A ship capacity of 15 is the minimum to ship all the packages in 5 days like this:\n1st day: 1, 2, 3, 4, 5\n2nd day: 6, 7\n3rd day: 8\n4th day: 9\n5th day: 10\n\nNote that the cargo must be shipped in the order given, so using a ship of capacity 14 and splitting the packages into parts like (2, 3, 4, 5), (1, 6, 7), (8), (9), (10) is not allowed.\n
    \n\n

    Example 2:

    \n\n
    \nInput: weights = [3,2,2,4,1,4], days = 3\nOutput: 6\nExplanation: A ship capacity of 6 is the minimum to ship all the packages in 3 days like this:\n1st day: 3, 2\n2nd day: 2, 4\n3rd day: 1, 4\n
    \n\n

    Example 3:

    \n\n
    \nInput: weights = [1,2,3,1,1], days = 4\nOutput: 3\nExplanation:\n1st day: 1\n2nd day: 2\n3rd day: 3\n4th day: 1, 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= days <= weights.length <= 5 * 104
    • \n\t
    • 1 <= weights[i] <= 500
    • \n
    \n", "content_cn": "

    \u4f20\u9001\u5e26\u4e0a\u7684\u5305\u88f9\u5fc5\u987b\u5728 D \u5929\u5185\u4ece\u4e00\u4e2a\u6e2f\u53e3\u8fd0\u9001\u5230\u53e6\u4e00\u4e2a\u6e2f\u53e3\u3002

    \n\n

    \u4f20\u9001\u5e26\u4e0a\u7684\u7b2c i\u00a0\u4e2a\u5305\u88f9\u7684\u91cd\u91cf\u4e3a\u00a0weights[i]\u3002\u6bcf\u4e00\u5929\uff0c\u6211\u4eec\u90fd\u4f1a\u6309\u7ed9\u51fa\u91cd\u91cf\u7684\u987a\u5e8f\u5f80\u4f20\u9001\u5e26\u4e0a\u88c5\u8f7d\u5305\u88f9\u3002\u6211\u4eec\u88c5\u8f7d\u7684\u91cd\u91cf\u4e0d\u4f1a\u8d85\u8fc7\u8239\u7684\u6700\u5927\u8fd0\u8f7d\u91cd\u91cf\u3002

    \n\n

    \u8fd4\u56de\u80fd\u5728 D \u5929\u5185\u5c06\u4f20\u9001\u5e26\u4e0a\u7684\u6240\u6709\u5305\u88f9\u9001\u8fbe\u7684\u8239\u7684\u6700\u4f4e\u8fd0\u8f7d\u80fd\u529b\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aweights = [1,2,3,4,5,6,7,8,9,10], D = 5\n\u8f93\u51fa\uff1a15\n\u89e3\u91ca\uff1a\n\u8239\u8236\u6700\u4f4e\u8f7d\u91cd 15 \u5c31\u80fd\u591f\u5728 5 \u5929\u5185\u9001\u8fbe\u6240\u6709\u5305\u88f9\uff0c\u5982\u4e0b\u6240\u793a\uff1a\n\u7b2c 1 \u5929\uff1a1, 2, 3, 4, 5\n\u7b2c 2 \u5929\uff1a6, 7\n\u7b2c 3 \u5929\uff1a8\n\u7b2c 4 \u5929\uff1a9\n\u7b2c 5 \u5929\uff1a10\n\n\u8bf7\u6ce8\u610f\uff0c\u8d27\u7269\u5fc5\u987b\u6309\u7167\u7ed9\u5b9a\u7684\u987a\u5e8f\u88c5\u8fd0\uff0c\u56e0\u6b64\u4f7f\u7528\u8f7d\u91cd\u80fd\u529b\u4e3a 14 \u7684\u8239\u8236\u5e76\u5c06\u5305\u88c5\u5206\u6210 (2, 3, 4, 5), (1, 6, 7), (8), (9), (10) \u662f\u4e0d\u5141\u8bb8\u7684\u3002 \n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aweights = [3,2,2,4,1,4], D = 3\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\n\u8239\u8236\u6700\u4f4e\u8f7d\u91cd 6 \u5c31\u80fd\u591f\u5728 3 \u5929\u5185\u9001\u8fbe\u6240\u6709\u5305\u88f9\uff0c\u5982\u4e0b\u6240\u793a\uff1a\n\u7b2c 1 \u5929\uff1a3, 2\n\u7b2c 2 \u5929\uff1a2, 4\n\u7b2c 3 \u5929\uff1a1, 4\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aweights = [1,2,3,1,1], D = 4\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\n\u7b2c 1 \u5929\uff1a1\n\u7b2c 2 \u5929\uff1a2\n\u7b2c 3 \u5929\uff1a3\n\u7b2c 4 \u5929\uff1a1, 1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= D <= weights.length <= 5 * 104
    • \n\t
    • 1 <= weights[i] <= 500
    • \n
    \n", "tags_en": ["Array", "Binary Search"], "tags_cn": ["\u6570\u7ec4", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int shipWithinDays(vector& weights, int days) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int shipWithinDays(int[] weights, int days) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def shipWithinDays(self, weights, days):\n \"\"\"\n :type weights: List[int]\n :type days: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def shipWithinDays(self, weights: List[int], days: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint shipWithinDays(int* weights, int weightsSize, int days){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ShipWithinDays(int[] weights, int days) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} weights\n * @param {number} days\n * @return {number}\n */\nvar shipWithinDays = function(weights, days) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} weights\n# @param {Integer} days\n# @return {Integer}\ndef ship_within_days(weights, days)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func shipWithinDays(_ weights: [Int], _ days: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func shipWithinDays(weights []int, days int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def shipWithinDays(weights: Array[Int], days: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun shipWithinDays(weights: IntArray, days: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn ship_within_days(weights: Vec, days: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $weights\n * @param Integer $days\n * @return Integer\n */\n function shipWithinDays($weights, $days) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function shipWithinDays(weights: number[], days: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (ship-within-days weights days)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1011](https://leetcode-cn.com/problems/capacity-to-ship-packages-within-d-days)", "[\u5728 D \u5929\u5185\u9001\u8fbe\u5305\u88f9\u7684\u80fd\u529b](/solution/1000-1099/1011.Capacity%20To%20Ship%20Packages%20Within%20D%20Days/README.md)", "`\u6570\u7ec4`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1011](https://leetcode.com/problems/capacity-to-ship-packages-within-d-days)", "[Capacity To Ship Packages Within D Days](/solution/1000-1099/1011.Capacity%20To%20Ship%20Packages%20Within%20D%20Days/README_EN.md)", "`Array`,`Binary Search`", "Medium", ""]}, {"question_id": "1055", "frontend_question_id": "1010", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/pairs-of-songs-with-total-durations-divisible-by-60", "url_en": "https://leetcode.com/problems/pairs-of-songs-with-total-durations-divisible-by-60", "relative_path_cn": "/solution/1000-1099/1010.Pairs%20of%20Songs%20With%20Total%20Durations%20Divisible%20by%2060/README.md", "relative_path_en": "/solution/1000-1099/1010.Pairs%20of%20Songs%20With%20Total%20Durations%20Divisible%20by%2060/README_EN.md", "title_cn": "\u603b\u6301\u7eed\u65f6\u95f4\u53ef\u88ab 60 \u6574\u9664\u7684\u6b4c\u66f2", "title_en": "Pairs of Songs With Total Durations Divisible by 60", "question_title_slug": "pairs-of-songs-with-total-durations-divisible-by-60", "content_en": "

    You are given a list of songs where the ith song has a duration of time[i] seconds.

    \n\n

    Return the number of pairs of songs for which their total duration in seconds is divisible by 60. Formally, we want the number of indices i, j such that i < j with (time[i] + time[j]) % 60 == 0.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: time = [30,20,150,100,40]\nOutput: 3\nExplanation: Three pairs have a total duration divisible by 60:\n(time[0] = 30, time[2] = 150): total duration 180\n(time[1] = 20, time[3] = 100): total duration 120\n(time[1] = 20, time[4] = 40): total duration 60\n
    \n\n

    Example 2:

    \n\n
    \nInput: time = [60,60,60]\nOutput: 3\nExplanation: All three pairs have a total duration of 120, which is divisible by 60.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= time.length <= 6 * 104
    • \n\t
    • 1 <= time[i] <= 500
    • \n
    \n", "content_cn": "

    \u5728\u6b4c\u66f2\u5217\u8868\u4e2d\uff0c\u7b2c i \u9996\u6b4c\u66f2\u7684\u6301\u7eed\u65f6\u95f4\u4e3a time[i] \u79d2\u3002

    \n\n

    \u8fd4\u56de\u5176\u603b\u6301\u7eed\u65f6\u95f4\uff08\u4ee5\u79d2\u4e3a\u5355\u4f4d\uff09\u53ef\u88ab 60 \u6574\u9664\u7684\u6b4c\u66f2\u5bf9\u7684\u6570\u91cf\u3002\u5f62\u5f0f\u4e0a\uff0c\u6211\u4eec\u5e0c\u671b\u7d22\u5f15\u7684\u6570\u5b57 i \u548c j \u6ee1\u8db3  i < j \u4e14\u6709 (time[i] + time[j]) % 60 == 0\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a[30,20,150,100,40]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u8fd9\u4e09\u5bf9\u7684\u603b\u6301\u7eed\u65f6\u95f4\u53ef\u88ab 60 \u6574\u6570\uff1a\n(time[0] = 30, time[2] = 150): \u603b\u6301\u7eed\u65f6\u95f4 180\n(time[1] = 20, time[3] = 100): \u603b\u6301\u7eed\u65f6\u95f4 120\n(time[1] = 20, time[4] = 40): \u603b\u6301\u7eed\u65f6\u95f4 60\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a[60,60,60]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6240\u6709\u4e09\u5bf9\u7684\u603b\u6301\u7eed\u65f6\u95f4\u90fd\u662f 120\uff0c\u53ef\u4ee5\u88ab 60 \u6574\u6570\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= time.length <= 60000
    2. \n\t
    3. 1 <= time[i] <= 500
    4. \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numPairsDivisibleBy60(vector& time) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numPairsDivisibleBy60(int[] time) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numPairsDivisibleBy60(self, time):\n \"\"\"\n :type time: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numPairsDivisibleBy60(self, time: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numPairsDivisibleBy60(int* time, int timeSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumPairsDivisibleBy60(int[] time) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} time\n * @return {number}\n */\nvar numPairsDivisibleBy60 = function(time) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} time\n# @return {Integer}\ndef num_pairs_divisible_by60(time)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numPairsDivisibleBy60(_ time: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numPairsDivisibleBy60(time []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numPairsDivisibleBy60(time: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numPairsDivisibleBy60(time: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_pairs_divisible_by60(time: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $time\n * @return Integer\n */\n function numPairsDivisibleBy60($time) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numPairsDivisibleBy60(time: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-pairs-divisible-by60 time)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1010](https://leetcode-cn.com/problems/pairs-of-songs-with-total-durations-divisible-by-60)", "[\u603b\u6301\u7eed\u65f6\u95f4\u53ef\u88ab 60 \u6574\u9664\u7684\u6b4c\u66f2](/solution/1000-1099/1010.Pairs%20of%20Songs%20With%20Total%20Durations%20Divisible%20by%2060/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1010](https://leetcode.com/problems/pairs-of-songs-with-total-durations-divisible-by-60)", "[Pairs of Songs With Total Durations Divisible by 60](/solution/1000-1099/1010.Pairs%20of%20Songs%20With%20Total%20Durations%20Divisible%20by%2060/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "1054", "frontend_question_id": "1009", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/complement-of-base-10-integer", "url_en": "https://leetcode.com/problems/complement-of-base-10-integer", "relative_path_cn": "/solution/1000-1099/1009.Complement%20of%20Base%2010%20Integer/README.md", "relative_path_en": "/solution/1000-1099/1009.Complement%20of%20Base%2010%20Integer/README_EN.md", "title_cn": "\u5341\u8fdb\u5236\u6574\u6570\u7684\u53cd\u7801", "title_en": "Complement of Base 10 Integer", "question_title_slug": "complement-of-base-10-integer", "content_en": "

    Every non-negative integer n has a binary representation.  For example, 5 can be represented as "101" in binary, 11 as "1011" in binary, and so on.  Note that except for n = 0, there are no leading zeroes in any binary representation.

    \n\n

    The complement of a binary representation is the number in binary you get when changing every 1 to a 0 and 0 to a 1.  For example, the complement of "101" in binary is "010" in binary.

    \n\n

    For a given number n in base-10, return the complement of it's binary representation as a base-10 integer.

    \n\n

     

    \n\n
      \n
    \n\n
    \n

    Example 1:

    \n\n
    \nInput: n = 5\nOutput: 2\nExplanation: 5 is "101" in binary, with complement "010" in binary, which is 2 in base-10.\n
    \n\n
    \n

    Example 2:

    \n\n
    \nInput: n = 7\nOutput: 0\nExplanation: 7 is "111" in binary, with complement "000" in binary, which is 0 in base-10.\n
    \n\n
    \n

    Example 3:

    \n\n
    \nInput: n = 10\nOutput: 5\nExplanation: 10 is "1010" in binary, with complement "0101" in binary, which is 5 in base-10.\n
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    1. 0 <= n < 109
    2. \n\t
    3. This question is the same as 476: https://leetcode.com/problems/number-complement/
    4. \n
    \n
    \n
    \n
    \n", "content_cn": "

    \u6bcf\u4e2a\u975e\u8d1f\u6574\u6570 N \u90fd\u6709\u5176\u4e8c\u8fdb\u5236\u8868\u793a\u3002\u4f8b\u5982\uff0c 5 \u53ef\u4ee5\u88ab\u8868\u793a\u4e3a\u4e8c\u8fdb\u5236 "101"\uff0c11 \u53ef\u4ee5\u7528\u4e8c\u8fdb\u5236 "1011" \u8868\u793a\uff0c\u4f9d\u6b64\u7c7b\u63a8\u3002\u6ce8\u610f\uff0c\u9664 N = 0 \u5916\uff0c\u4efb\u4f55\u4e8c\u8fdb\u5236\u8868\u793a\u4e2d\u90fd\u4e0d\u542b\u524d\u5bfc\u96f6\u3002

    \n\n

    \u4e8c\u8fdb\u5236\u7684\u53cd\u7801\u8868\u793a\u662f\u5c06\u6bcf\u4e2a 1 \u6539\u4e3a 0 \u4e14\u6bcf\u4e2a 0 \u53d8\u4e3a 1\u3002\u4f8b\u5982\uff0c\u4e8c\u8fdb\u5236\u6570 "101" \u7684\u4e8c\u8fdb\u5236\u53cd\u7801\u4e3a "010"\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u5341\u8fdb\u5236\u6570 N\uff0c\u8bf7\u4f60\u8fd4\u56de\u5176\u4e8c\u8fdb\u5236\u8868\u793a\u7684\u53cd\u7801\u6240\u5bf9\u5e94\u7684\u5341\u8fdb\u5236\u6574\u6570\u3002

    \n\n

     

    \n\n
      \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a5\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a5 \u7684\u4e8c\u8fdb\u5236\u8868\u793a\u4e3a "101"\uff0c\u5176\u4e8c\u8fdb\u5236\u53cd\u7801\u4e3a "010"\uff0c\u4e5f\u5c31\u662f\u5341\u8fdb\u5236\u4e2d\u7684 2 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a7\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a7 \u7684\u4e8c\u8fdb\u5236\u8868\u793a\u4e3a "111"\uff0c\u5176\u4e8c\u8fdb\u5236\u53cd\u7801\u4e3a "000"\uff0c\u4e5f\u5c31\u662f\u5341\u8fdb\u5236\u4e2d\u7684 0 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1a10\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a10 \u7684\u4e8c\u8fdb\u5236\u8868\u793a\u4e3a "1010"\uff0c\u5176\u4e8c\u8fdb\u5236\u53cd\u7801\u4e3a "0101"\uff0c\u4e5f\u5c31\u662f\u5341\u8fdb\u5236\u4e2d\u7684 5 \u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 0 <= N < 10^9
    2. \n\t
    3. \u672c\u9898\u4e0e 476\uff1ahttps://leetcode-cn.com/problems/number-complement/ \u76f8\u540c
    4. \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int bitwiseComplement(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int bitwiseComplement(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def bitwiseComplement(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def bitwiseComplement(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint bitwiseComplement(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int BitwiseComplement(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar bitwiseComplement = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef bitwise_complement(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func bitwiseComplement(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func bitwiseComplement(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def bitwiseComplement(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun bitwiseComplement(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn bitwise_complement(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function bitwiseComplement($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function bitwiseComplement(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (bitwise-complement n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1009](https://leetcode-cn.com/problems/complement-of-base-10-integer)", "[\u5341\u8fdb\u5236\u6574\u6570\u7684\u53cd\u7801](/solution/1000-1099/1009.Complement%20of%20Base%2010%20Integer/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[1009](https://leetcode.com/problems/complement-of-base-10-integer)", "[Complement of Base 10 Integer](/solution/1000-1099/1009.Complement%20of%20Base%2010%20Integer/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "1053", "frontend_question_id": "1058", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/minimize-rounding-error-to-meet-target", "url_en": "https://leetcode.com/problems/minimize-rounding-error-to-meet-target", "relative_path_cn": "/solution/1000-1099/1058.Minimize%20Rounding%20Error%20to%20Meet%20Target/README.md", "relative_path_en": "/solution/1000-1099/1058.Minimize%20Rounding%20Error%20to%20Meet%20Target/README_EN.md", "title_cn": "\u6700\u5c0f\u5316\u820d\u5165\u8bef\u5dee\u4ee5\u6ee1\u8db3\u76ee\u6807", "title_en": "Minimize Rounding Error to Meet Target", "question_title_slug": "minimize-rounding-error-to-meet-target", "content_en": "

    Given an array of prices [p1,p2...,pn] and a target, round each price pi to Roundi(pi) so that the rounded array [Round1(p1),Round2(p2)...,Roundn(pn)] sums to the given target. Each operation Roundi(pi) could be either Floor(pi) or Ceil(pi).

    \n\n

    Return the string "-1" if the rounded array is impossible to sum to target. Otherwise, return the smallest rounding error, which is defined as Σ |Roundi(pi) - (pi)| for i from 1 to n, as a string with three places after the decimal.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: prices = ["0.700","2.800","4.900"], target = 8\nOutput: "1.000"\nExplanation:\nUse Floor, Ceil and Ceil operations to get (0.7 - 0) + (3 - 2.8) + (5 - 4.9) = 0.7 + 0.2 + 0.1 = 1.0 .\n
    \n\n

    Example 2:

    \n\n
    \nInput: prices = ["1.500","2.500","3.500"], target = 10\nOutput: "-1"\nExplanation: It is impossible to meet the target.\n
    \n\n

    Example 3:

    \n\n
    \nInput: prices = ["1.500","2.500","3.500"], target = 9\nOutput: "1.500"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= prices.length <= 500
    • \n\t
    • Each string prices[i] represents a real number in the range [0.0, 1000.0] and has exactly 3 decimal places.
    • \n\t
    • 0 <= target <= 106
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u7cfb\u5217\u4ef7\u683c [p1,p2...,pn] \u548c\u4e00\u4e2a\u76ee\u6807 target\uff0c\u5c06\u6bcf\u4e2a\u4ef7\u683c pi \u820d\u5165\u4e3a Roundi(pi) \u4ee5\u4f7f\u5f97\u820d\u5165\u6570\u7ec4 [Round1(p1),Round2(p2)...,Roundn(pn)] \u4e4b\u548c\u8fbe\u5230\u7ed9\u5b9a\u7684\u76ee\u6807\u503c target\u3002\u6bcf\u6b21\u820d\u5165\u64cd\u4f5c Roundi(pi) \u53ef\u4ee5\u662f\u5411\u4e0b\u820d Floor(pi) \u4e5f\u53ef\u4ee5\u662f\u5411\u4e0a\u5165 Ceil(pi)\u3002

    \n\n

    \u5982\u679c\u820d\u5165\u6570\u7ec4\u4e4b\u548c\u65e0\u8bba\u5982\u4f55\u90fd\u65e0\u6cd5\u8fbe\u5230\u76ee\u6807\u503c target\uff0c\u5c31\u8fd4\u56de -1\u3002\u5426\u5219\uff0c\u4ee5\u4fdd\u7559\u5230\u5c0f\u6570\u70b9\u540e\u4e09\u4f4d\u7684\u5b57\u7b26\u4e32\u683c\u5f0f\u8fd4\u56de\u6700\u5c0f\u7684\u820d\u5165\u8bef\u5dee\uff0c\u5176\u5b9a\u4e49\u4e3a Σ |Roundi(pi) - (pi)|\uff08 i \u4ece 1 \u5230 n \uff09\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aprices = ["0.700","2.800","4.900"], target = 8\n\u8f93\u51fa\uff1a"1.000"\n\u89e3\u91ca\uff1a \n\u4f7f\u7528 Floor\uff0cCeil \u548c Ceil \u64cd\u4f5c\u5f97\u5230 (0.7 - 0) + (3 - 2.8) + (5 - 4.9) = 0.7 + 0.2 + 0.1 = 1.0 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aprices = ["1.500","2.500","3.500"], target = 10\n\u8f93\u51fa\uff1a"-1"\n\u89e3\u91ca\uff1a\n\u8fbe\u5230\u76ee\u6807\u662f\u4e0d\u53ef\u80fd\u7684\u3002
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= prices.length <= 500
    2. \n\t
    3. \u8868\u793a\u4ef7\u683c\u7684\u6bcf\u4e2a\u5b57\u7b26\u4e32 prices[i] \u90fd\u4ee3\u8868\u4e00\u4e2a\u4ecb\u4e8e 0 \u548c 1000 \u4e4b\u95f4\u7684\u5b9e\u6570\uff0c\u5e76\u4e14\u6b63\u597d\u6709 3 \u4e2a\u5c0f\u6570\u4f4d\u3002
    4. \n\t
    5. target \u4ecb\u4e8e 0 \u548c 1000000 \u4e4b\u95f4\u3002
    6. \n
    \n", "tags_en": ["Greedy", "Math", "Dynamic Programming"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u5b66", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string minimizeError(vector& prices, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String minimizeError(String[] prices, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimizeError(self, prices, target):\n \"\"\"\n :type prices: List[str]\n :type target: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimizeError(self, prices: List[str], target: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * minimizeError(char ** prices, int pricesSize, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string MinimizeError(string[] prices, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} prices\n * @param {number} target\n * @return {string}\n */\nvar minimizeError = function(prices, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} prices\n# @param {Integer} target\n# @return {String}\ndef minimize_error(prices, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimizeError(_ prices: [String], _ target: Int) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimizeError(prices []string, target int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimizeError(prices: Array[String], target: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimizeError(prices: Array, target: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimize_error(prices: Vec, target: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $prices\n * @param Integer $target\n * @return String\n */\n function minimizeError($prices, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimizeError(prices: string[], target: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimize-error prices target)\n (-> (listof string?) exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1058](https://leetcode-cn.com/problems/minimize-rounding-error-to-meet-target)", "[\u6700\u5c0f\u5316\u820d\u5165\u8bef\u5dee\u4ee5\u6ee1\u8db3\u76ee\u6807](/solution/1000-1099/1058.Minimize%20Rounding%20Error%20to%20Meet%20Target/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u5b66`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1058](https://leetcode.com/problems/minimize-rounding-error-to-meet-target)", "[Minimize Rounding Error to Meet Target](/solution/1000-1099/1058.Minimize%20Rounding%20Error%20to%20Meet%20Target/README_EN.md)", "`Greedy`,`Math`,`Dynamic Programming`", "Medium", "\ud83d\udd12"]}, {"question_id": "1052", "frontend_question_id": "1057", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/campus-bikes", "url_en": "https://leetcode.com/problems/campus-bikes", "relative_path_cn": "/solution/1000-1099/1057.Campus%20Bikes/README.md", "relative_path_en": "/solution/1000-1099/1057.Campus%20Bikes/README_EN.md", "title_cn": "\u6821\u56ed\u81ea\u884c\u8f66\u5206\u914d", "title_en": "Campus Bikes", "question_title_slug": "campus-bikes", "content_en": "

    On a campus represented as a 2D grid, there are N workers and M bikes, with N <= M. Each worker and bike is a 2D coordinate on this grid.

    \r\n\r\n

    Our goal is to assign a bike to each worker. Among the available bikes and workers, we choose the (worker, bike) pair with the shortest Manhattan distance between each other, and assign the bike to that worker. (If there are multiple (worker, bike) pairs with the same shortest Manhattan distance, we choose the pair with the smallest worker index; if there are multiple ways to do that, we choose the pair with the smallest bike index). We repeat this process until there are no available workers.

    \r\n\r\n

    The Manhattan distance between two points p1 and p2 is Manhattan(p1, p2) = |p1.x - p2.x| + |p1.y - p2.y|.

    \r\n\r\n

    Return a vector ans of length N, where ans[i] is the index (0-indexed) of the bike that the i-th worker is assigned to.

    \r\n\r\n

     

    \r\n\r\n

    Example 1:

    \r\n\r\n

    \"\"

    \r\n\r\n
    \r\nInput: workers = [[0,0],[2,1]], bikes = [[1,2],[3,3]]\r\nOutput: [1,0]\r\nExplanation: \r\nWorker 1 grabs Bike 0 as they are closest (without ties), and Worker 0 is assigned Bike 1. So the output is [1, 0].\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n

    \"\"

    \r\n\r\n
    \r\nInput: workers = [[0,0],[1,1],[2,0]], bikes = [[1,0],[2,2],[2,1]]\r\nOutput: [0,2,1]\r\nExplanation: \r\nWorker 0 grabs Bike 0 at first. Worker 1 and Worker 2 share the same distance to Bike 2, thus Worker 1 is assigned to Bike 2, and Worker 2 will take Bike 1. So the output is [0,2,1].\r\n
    \r\n\r\n

     

    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    1. 0 <= workers[i][j], bikes[i][j] < 1000
    2. \r\n\t
    3. All worker and bike locations are distinct.
    4. \r\n\t
    5. 1 <= workers.length <= bikes.length <= 1000
    6. \r\n
    \r\n", "content_cn": "

    \u5728\u7531 2D \u7f51\u683c\u8868\u793a\u7684\u6821\u56ed\u91cc\u6709 n \u4f4d\u5de5\u4eba\uff08worker\uff09\u548c m \u8f86\u81ea\u884c\u8f66\uff08bike\uff09\uff0cn <= m\u3002\u6240\u6709\u5de5\u4eba\u548c\u81ea\u884c\u8f66\u7684\u4f4d\u7f6e\u90fd\u7528\u7f51\u683c\u4e0a\u7684 2D \u5750\u6807\u8868\u793a\u3002

    \n\n

    \u6211\u4eec\u9700\u8981\u4e3a\u6bcf\u4f4d\u5de5\u4eba\u5206\u914d\u4e00\u8f86\u81ea\u884c\u8f66\u3002\u5728\u6240\u6709\u53ef\u7528\u7684\u81ea\u884c\u8f66\u548c\u5de5\u4eba\u4e2d\uff0c\u6211\u4eec\u9009\u53d6\u5f7c\u6b64\u4e4b\u95f4\u66fc\u54c8\u987f\u8ddd\u79bb\u6700\u77ed\u7684\u5de5\u4eba\u81ea\u884c\u8f66\u5bf9  (worker, bike) \uff0c\u5e76\u5c06\u5176\u4e2d\u7684\u81ea\u884c\u8f66\u5206\u914d\u7d66\u5de5\u4eba\u3002\u5982\u679c\u6709\u591a\u4e2a (worker, bike) \u5bf9\u4e4b\u95f4\u7684\u66fc\u54c8\u987f\u8ddd\u79bb\u76f8\u540c\uff0c\u90a3\u4e48\u6211\u4eec\u9009\u62e9\u5de5\u4eba\u7d22\u5f15\u6700\u5c0f\u7684\u90a3\u5bf9\u3002\u7c7b\u4f3c\u5730\uff0c\u5982\u679c\u6709\u591a\u79cd\u4e0d\u540c\u7684\u5206\u914d\u65b9\u6cd5\uff0c\u5219\u9009\u62e9\u81ea\u884c\u8f66\u7d22\u5f15\u6700\u5c0f\u7684\u4e00\u5bf9\u3002\u4e0d\u65ad\u91cd\u590d\u8fd9\u4e00\u8fc7\u7a0b\uff0c\u76f4\u5230\u6240\u6709\u5de5\u4eba\u90fd\u5206\u914d\u5230\u81ea\u884c\u8f66\u4e3a\u6b62\u3002

    \n\n

    \u7ed9\u5b9a\u4e24\u70b9 p1 \u548c p2 \u4e4b\u95f4\u7684\u66fc\u54c8\u987f\u8ddd\u79bb\u4e3a Manhattan(p1, p2) = |p1.x - p2.x| + |p1.y - p2.y|\u3002

    \n\n

    \u8fd4\u56de\u957f\u5ea6\u4e3a n \u7684\u5411\u91cf ans\uff0c\u5176\u4e2d a[i] \u662f\u7b2c i \u4f4d\u5de5\u4eba\u5206\u914d\u5230\u7684\u81ea\u884c\u8f66\u7684\u7d22\u5f15\uff08\u4ece 0 \u5f00\u59cb\uff09\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1aworkers = [[0,0],[2,1]], bikes = [[1,2],[3,3]]\n\u8f93\u51fa\uff1a[1,0]\n\u89e3\u91ca\uff1a\n\u5de5\u4eba 1 \u5206\u914d\u5230\u81ea\u884c\u8f66 0\uff0c\u56e0\u4e3a\u4ed6\u4eec\u6700\u63a5\u8fd1\u4e14\u4e0d\u5b58\u5728\u51b2\u7a81\uff0c\u5de5\u4eba 0 \u5206\u914d\u5230\u81ea\u884c\u8f66 1 \u3002\u6240\u4ee5\u8f93\u51fa\u662f [1,0]\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1aworkers = [[0,0],[1,1],[2,0]], bikes = [[1,0],[2,2],[2,1]]\n\u8f93\u51fa\uff1a[0,2,1]\n\u89e3\u91ca\uff1a\n\u5de5\u4eba 0 \u9996\u5148\u5206\u914d\u5230\u81ea\u884c\u8f66 0 \u3002\u5de5\u4eba 1 \u548c\u5de5\u4eba 2 \u4e0e\u81ea\u884c\u8f66 2 \u8ddd\u79bb\u76f8\u540c\uff0c\u56e0\u6b64\u5de5\u4eba 1 \u5206\u914d\u5230\u81ea\u884c\u8f66 2\uff0c\u5de5\u4eba 2 \u5c06\u5206\u914d\u5230\u81ea\u884c\u8f66 1 \u3002\u56e0\u6b64\u8f93\u51fa\u4e3a [0,2,1]\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 0 <= workers[i][j], bikes[i][j] < 1000
    2. \n\t
    3. \u6240\u6709\u5de5\u4eba\u548c\u81ea\u884c\u8f66\u7684\u4f4d\u7f6e\u90fd\u4e0d\u76f8\u540c\u3002
    4. \n\t
    5. 1 <= workers.length <= bikes.length <= 1000
    6. \n
    \n", "tags_en": ["Greedy", "Sort"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6392\u5e8f"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector assignBikes(vector>& workers, vector>& bikes) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] assignBikes(int[][] workers, int[][] bikes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def assignBikes(self, workers, bikes):\n \"\"\"\n :type workers: List[List[int]]\n :type bikes: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def assignBikes(self, workers: List[List[int]], bikes: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* assignBikes(int** workers, int workersSize, int* workersColSize, int** bikes, int bikesSize, int* bikesColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] AssignBikes(int[][] workers, int[][] bikes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} workers\n * @param {number[][]} bikes\n * @return {number[]}\n */\nvar assignBikes = function(workers, bikes) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} workers\n# @param {Integer[][]} bikes\n# @return {Integer[]}\ndef assign_bikes(workers, bikes)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func assignBikes(_ workers: [[Int]], _ bikes: [[Int]]) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func assignBikes(workers [][]int, bikes [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def assignBikes(workers: Array[Array[Int]], bikes: Array[Array[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun assignBikes(workers: Array, bikes: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn assign_bikes(workers: Vec>, bikes: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $workers\n * @param Integer[][] $bikes\n * @return Integer[]\n */\n function assignBikes($workers, $bikes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function assignBikes(workers: number[][], bikes: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (assign-bikes workers bikes)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1057](https://leetcode-cn.com/problems/campus-bikes)", "[\u6821\u56ed\u81ea\u884c\u8f66\u5206\u914d](/solution/1000-1099/1057.Campus%20Bikes/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6392\u5e8f`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1057](https://leetcode.com/problems/campus-bikes)", "[Campus Bikes](/solution/1000-1099/1057.Campus%20Bikes/README_EN.md)", "`Greedy`,`Sort`", "Medium", "\ud83d\udd12"]}, {"question_id": "1051", "frontend_question_id": "1055", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/shortest-way-to-form-string", "url_en": "https://leetcode.com/problems/shortest-way-to-form-string", "relative_path_cn": "/solution/1000-1099/1055.Shortest%20Way%20to%20Form%20String/README.md", "relative_path_en": "/solution/1000-1099/1055.Shortest%20Way%20to%20Form%20String/README_EN.md", "title_cn": "\u5f62\u6210\u5b57\u7b26\u4e32\u7684\u6700\u77ed\u8def\u5f84", "title_en": "Shortest Way to Form String", "question_title_slug": "shortest-way-to-form-string", "content_en": "

    From any string, we can form a subsequence of that string by deleting some number of characters (possibly no deletions).

    \r\n\r\n

    Given two strings source and target, return the minimum number of subsequences of source such that their concatenation equals target. If the task is impossible, return -1.

    \r\n\r\n

     

    \r\n\r\n

    Example 1:

    \r\n\r\n
    \r\nInput: source = "abc", target = "abcbc"\r\nOutput: 2\r\nExplanation: The target "abcbc" can be formed by "abc" and "bc", which are subsequences of source "abc".\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: source = "abc", target = "acdbc"\r\nOutput: -1\r\nExplanation: The target string cannot be constructed from the subsequences of source string due to the character "d" in target string.\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: source = "xyz", target = "xzyxz"\r\nOutput: 3\r\nExplanation: The target string can be constructed as follows "xz" + "y" + "xz".\r\n
    \r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • Both the source and target strings consist of only lowercase English letters from "a"-"z".
    • \r\n\t
    • The lengths of source and target string are between 1 and 1000.
    • \r\n
    ", "content_cn": "

    \u5bf9\u4e8e\u4efb\u4f55\u5b57\u7b26\u4e32\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u5220\u9664\u5176\u4e2d\u4e00\u4e9b\u5b57\u7b26\uff08\u4e5f\u53ef\u80fd\u4e0d\u5220\u9664\uff09\u6765\u6784\u9020\u8be5\u5b57\u7b26\u4e32\u7684\u5b50\u5e8f\u5217\u3002

    \n\n

    \u7ed9\u5b9a\u6e90\u5b57\u7b26\u4e32 source \u548c\u76ee\u6807\u5b57\u7b26\u4e32 target\uff0c\u627e\u51fa\u6e90\u5b57\u7b26\u4e32\u4e2d\u80fd\u901a\u8fc7\u4e32\u8054\u5f62\u6210\u76ee\u6807\u5b57\u7b26\u4e32\u7684\u5b50\u5e8f\u5217\u7684\u6700\u5c0f\u6570\u91cf\u3002\u5982\u679c\u65e0\u6cd5\u901a\u8fc7\u4e32\u8054\u6e90\u5b57\u7b26\u4e32\u4e2d\u7684\u5b50\u5e8f\u5217\u6765\u6784\u9020\u76ee\u6807\u5b57\u7b26\u4e32\uff0c\u5219\u8fd4\u56de -1\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1asource = "abc", target = "abcbc"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u76ee\u6807\u5b57\u7b26\u4e32 "abcbc" \u53ef\u4ee5\u7531 "abc" \u548c "bc" \u5f62\u6210\uff0c\u5b83\u4eec\u90fd\u662f\u6e90\u5b57\u7b26\u4e32 "abc" \u7684\u5b50\u5e8f\u5217\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1asource = "abc", target = "acdbc"\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u7531\u4e8e\u76ee\u6807\u5b57\u7b26\u4e32\u4e2d\u5305\u542b\u5b57\u7b26 "d"\uff0c\u6240\u4ee5\u65e0\u6cd5\u7531\u6e90\u5b57\u7b26\u4e32\u7684\u5b50\u5e8f\u5217\u6784\u5efa\u76ee\u6807\u5b57\u7b26\u4e32\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1asource = "xyz", target = "xzyxz"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u76ee\u6807\u5b57\u7b26\u4e32\u53ef\u4ee5\u6309\u5982\u4e0b\u65b9\u5f0f\u6784\u5efa\uff1a "xz" + "y" + "xz"\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. source \u548c target \u4e24\u4e2a\u5b57\u7b26\u4e32\u90fd\u53ea\u5305\u542b "a"-"z" \u7684\u82f1\u6587\u5c0f\u5199\u5b57\u6bcd\u3002
    2. \n\t
    3. source \u548c target \u4e24\u4e2a\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u4ecb\u4e8e 1 \u548c 1000 \u4e4b\u95f4\u3002
    4. \n
    \n", "tags_en": ["Greedy", "Dynamic Programming"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int shortestWay(string source, string target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int shortestWay(String source, String target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def shortestWay(self, source, target):\n \"\"\"\n :type source: str\n :type target: str\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def shortestWay(self, source: str, target: str) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint shortestWay(char * source, char * target){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ShortestWay(string source, string target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} source\n * @param {string} target\n * @return {number}\n */\nvar shortestWay = function(source, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} source\n# @param {String} target\n# @return {Integer}\ndef shortest_way(source, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func shortestWay(_ source: String, _ target: String) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func shortestWay(source string, target string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def shortestWay(source: String, target: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun shortestWay(source: String, target: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn shortest_way(source: String, target: String) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $source\n * @param String $target\n * @return Integer\n */\n function shortestWay($source, $target) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function shortestWay(source: string, target: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (shortest-way source target)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1055](https://leetcode-cn.com/problems/shortest-way-to-form-string)", "[\u5f62\u6210\u5b57\u7b26\u4e32\u7684\u6700\u77ed\u8def\u5f84](/solution/1000-1099/1055.Shortest%20Way%20to%20Form%20String/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1055](https://leetcode.com/problems/shortest-way-to-form-string)", "[Shortest Way to Form String](/solution/1000-1099/1055.Shortest%20Way%20to%20Form%20String/README_EN.md)", "`Greedy`,`Dynamic Programming`", "Medium", "\ud83d\udd12"]}, {"question_id": "1050", "frontend_question_id": "1008", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/construct-binary-search-tree-from-preorder-traversal", "url_en": "https://leetcode.com/problems/construct-binary-search-tree-from-preorder-traversal", "relative_path_cn": "/solution/1000-1099/1008.Construct%20Binary%20Search%20Tree%20from%20Preorder%20Traversal/README.md", "relative_path_en": "/solution/1000-1099/1008.Construct%20Binary%20Search%20Tree%20from%20Preorder%20Traversal/README_EN.md", "title_cn": "\u524d\u5e8f\u904d\u5386\u6784\u9020\u4e8c\u53c9\u641c\u7d22\u6811", "title_en": "Construct Binary Search Tree from Preorder Traversal", "question_title_slug": "construct-binary-search-tree-from-preorder-traversal", "content_en": "

    Given an array of integers preorder, which represents the preorder traversal of a BST (i.e., binary search tree), construct the tree and return its root.

    \n\n

    It is guaranteed that there is always possible to find a binary search tree with the given requirements for the given test cases.

    \n\n

    A binary search tree is a binary tree where for every node, any descendant of Node.left has a value strictly less than Node.val, and any descendant of Node.right has a value strictly greater than Node.val.

    \n\n

    A preorder traversal of a binary tree displays the value of the node first, then traverses Node.left, then traverses Node.right.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: preorder = [8,5,1,7,10,12]\nOutput: [8,5,10,1,7,null,12]\n
    \n\n

    Example 2:

    \n\n
    \nInput: preorder = [1,3]\nOutput: [1,null,3]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= preorder.length <= 100
    • \n\t
    • 1 <= preorder[i] <= 108
    • \n\t
    • All the values of preorder are unique.
    • \n
    \n", "content_cn": "

    \u8fd4\u56de\u4e0e\u7ed9\u5b9a\u524d\u5e8f\u904d\u5386 preorder \u76f8\u5339\u914d\u7684\u4e8c\u53c9\u641c\u7d22\u6811\uff08binary search tree\uff09\u7684\u6839\u7ed3\u70b9\u3002

    \n\n

    (\u56de\u60f3\u4e00\u4e0b\uff0c\u4e8c\u53c9\u641c\u7d22\u6811\u662f\u4e8c\u53c9\u6811\u7684\u4e00\u79cd\uff0c\u5176\u6bcf\u4e2a\u8282\u70b9\u90fd\u6ee1\u8db3\u4ee5\u4e0b\u89c4\u5219\uff0c\u5bf9\u4e8e node.left \u7684\u4efb\u4f55\u540e\u4ee3\uff0c\u503c\u603b < node.val\uff0c\u800c node.right \u7684\u4efb\u4f55\u540e\u4ee3\uff0c\u503c\u603b > node.val\u3002\u6b64\u5916\uff0c\u524d\u5e8f\u904d\u5386\u9996\u5148\u663e\u793a\u8282\u70b9 node \u7684\u503c\uff0c\u7136\u540e\u904d\u5386 node.left\uff0c\u63a5\u7740\u904d\u5386 node.right\u3002\uff09

    \n\n

    \u9898\u76ee\u4fdd\u8bc1\uff0c\u5bf9\u4e8e\u7ed9\u5b9a\u7684\u6d4b\u8bd5\u7528\u4f8b\uff0c\u603b\u80fd\u627e\u5230\u6ee1\u8db3\u8981\u6c42\u7684\u4e8c\u53c9\u641c\u7d22\u6811\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1a[8,5,1,7,10,12]\n\u8f93\u51fa\uff1a[8,5,10,1,7,null,12]\n\"\"\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= preorder.length <= 100
    • \n\t
    • 1 <= preorder[i] <= 10^8
    • \n\t
    • preorder \u4e2d\u7684\u503c\u4e92\u4e0d\u76f8\u540c
    • \n
    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* bstFromPreorder(vector& preorder) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode bstFromPreorder(int[] preorder) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def bstFromPreorder(self, preorder):\n \"\"\"\n :type preorder: List[int]\n :rtype: TreeNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def bstFromPreorder(self, preorder: List[int]) -> TreeNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* bstFromPreorder(int* preorder, int preorderSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode BstFromPreorder(int[] preorder) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {number[]} preorder\n * @return {TreeNode}\n */\nvar bstFromPreorder = function(preorder) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {Integer[]} preorder\n# @return {TreeNode}\ndef bst_from_preorder(preorder)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func bstFromPreorder(_ preorder: [Int]) -> TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc bstFromPreorder(preorder []int) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def bstFromPreorder(preorder: Array[Int]): TreeNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun bstFromPreorder(preorder: IntArray): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn bst_from_preorder(preorder: Vec) -> Option>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param Integer[] $preorder\n * @return TreeNode\n */\n function bstFromPreorder($preorder) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction bstFromPreorder(preorder: number[]): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (bst-from-preorder preorder)\n (-> (listof exact-integer?) (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1008](https://leetcode-cn.com/problems/construct-binary-search-tree-from-preorder-traversal)", "[\u524d\u5e8f\u904d\u5386\u6784\u9020\u4e8c\u53c9\u641c\u7d22\u6811](/solution/1000-1099/1008.Construct%20Binary%20Search%20Tree%20from%20Preorder%20Traversal/README.md)", "`\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1008](https://leetcode.com/problems/construct-binary-search-tree-from-preorder-traversal)", "[Construct Binary Search Tree from Preorder Traversal](/solution/1000-1099/1008.Construct%20Binary%20Search%20Tree%20from%20Preorder%20Traversal/README_EN.md)", "`Tree`", "Medium", ""]}, {"question_id": "1049", "frontend_question_id": "1007", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-domino-rotations-for-equal-row", "url_en": "https://leetcode.com/problems/minimum-domino-rotations-for-equal-row", "relative_path_cn": "/solution/1000-1099/1007.Minimum%20Domino%20Rotations%20For%20Equal%20Row/README.md", "relative_path_en": "/solution/1000-1099/1007.Minimum%20Domino%20Rotations%20For%20Equal%20Row/README_EN.md", "title_cn": "\u884c\u76f8\u7b49\u7684\u6700\u5c11\u591a\u7c73\u8bfa\u65cb\u8f6c", "title_en": "Minimum Domino Rotations For Equal Row", "question_title_slug": "minimum-domino-rotations-for-equal-row", "content_en": "

    In a row of dominoes, tops[i] and bottoms[i] represent the top and bottom halves of the ith domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)

    \n\n

    We may rotate the ith domino, so that tops[i] and bottoms[i] swap values.

    \n\n

    Return the minimum number of rotations so that all the values in tops are the same, or all the values in bottoms are the same.

    \n\n

    If it cannot be done, return -1.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: tops = [2,1,2,4,2,2], bottoms = [5,2,6,2,3,2]\nOutput: 2\nExplanation: \nThe first figure represents the dominoes as given by tops and bottoms: before we do any rotations.\nIf we rotate the second and fourth dominoes, we can make every value in the top row equal to 2, as indicated by the second figure.\n
    \n\n

    Example 2:

    \n\n
    \nInput: tops = [3,5,1,2,3], bottoms = [3,6,3,3,4]\nOutput: -1\nExplanation: \nIn this case, it is not possible to rotate the dominoes to make one row of values equal.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= tops.length == bottoms.length <= 2 * 104
    • \n\t
    • 1 <= tops[i], bottoms[i] <= 6
    • \n
    \n", "content_cn": "

    \u5728\u4e00\u6392\u591a\u7c73\u8bfa\u9aa8\u724c\u4e2d\uff0cA[i] \u548c B[i] \u5206\u522b\u4ee3\u8868\u7b2c i \u4e2a\u591a\u7c73\u8bfa\u9aa8\u724c\u7684\u4e0a\u534a\u90e8\u5206\u548c\u4e0b\u534a\u90e8\u5206\u3002\uff08\u4e00\u4e2a\u591a\u7c73\u8bfa\u662f\u4e24\u4e2a\u4ece 1 \u5230 6 \u7684\u6570\u5b57\u540c\u5217\u5e73\u94fa\u5f62\u6210\u7684 —— \u8be5\u5e73\u94fa\u7684\u6bcf\u4e00\u534a\u4e0a\u90fd\u6709\u4e00\u4e2a\u6570\u5b57\u3002\uff09

    \n\n

    \u6211\u4eec\u53ef\u4ee5\u65cb\u8f6c\u7b2c i \u5f20\u591a\u7c73\u8bfa\uff0c\u4f7f\u5f97 A[i] \u548c B[i] \u7684\u503c\u4ea4\u6362\u3002

    \n\n

    \u8fd4\u56de\u80fd\u4f7f A \u4e2d\u6240\u6709\u503c\u6216\u8005 B \u4e2d\u6240\u6709\u503c\u90fd\u76f8\u540c\u7684\u6700\u5c0f\u65cb\u8f6c\u6b21\u6570\u3002

    \n\n

    \u5982\u679c\u65e0\u6cd5\u505a\u5230\uff0c\u8fd4\u56de -1.

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1aA = [2,1,2,4,2,2], B = [5,2,6,2,3,2]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n\u56fe\u4e00\u8868\u793a\uff1a\u5728\u6211\u4eec\u65cb\u8f6c\u4e4b\u524d\uff0c A \u548c B \u7ed9\u51fa\u7684\u591a\u7c73\u8bfa\u724c\u3002\n\u5982\u679c\u6211\u4eec\u65cb\u8f6c\u7b2c\u4e8c\u4e2a\u548c\u7b2c\u56db\u4e2a\u591a\u7c73\u8bfa\u9aa8\u724c\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u4e0a\u9762\u4e00\u884c\u4e2d\u7684\u6bcf\u4e2a\u503c\u90fd\u7b49\u4e8e 2\uff0c\u5982\u56fe\u4e8c\u6240\u793a\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aA = [3,5,1,2,3], B = [3,6,3,3,4]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\n\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u4e0d\u53ef\u80fd\u65cb\u8f6c\u591a\u7c73\u8bfa\u724c\u4f7f\u4e00\u884c\u7684\u503c\u76f8\u7b49\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= A[i], B[i] <= 6
    2. \n\t
    3. 2 <= A.length == B.length <= 20000
    4. \n
    \n", "tags_en": ["Greedy", "Array"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minDominoRotations(vector& tops, vector& bottoms) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minDominoRotations(int[] tops, int[] bottoms) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minDominoRotations(self, tops, bottoms):\n \"\"\"\n :type tops: List[int]\n :type bottoms: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minDominoRotations(self, tops: List[int], bottoms: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minDominoRotations(int* tops, int topsSize, int* bottoms, int bottomsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinDominoRotations(int[] tops, int[] bottoms) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} tops\n * @param {number[]} bottoms\n * @return {number}\n */\nvar minDominoRotations = function(tops, bottoms) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} tops\n# @param {Integer[]} bottoms\n# @return {Integer}\ndef min_domino_rotations(tops, bottoms)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minDominoRotations(_ tops: [Int], _ bottoms: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minDominoRotations(tops []int, bottoms []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minDominoRotations(tops: Array[Int], bottoms: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minDominoRotations(tops: IntArray, bottoms: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_domino_rotations(tops: Vec, bottoms: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $tops\n * @param Integer[] $bottoms\n * @return Integer\n */\n function minDominoRotations($tops, $bottoms) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minDominoRotations(tops: number[], bottoms: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-domino-rotations tops bottoms)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1007](https://leetcode-cn.com/problems/minimum-domino-rotations-for-equal-row)", "[\u884c\u76f8\u7b49\u7684\u6700\u5c11\u591a\u7c73\u8bfa\u65cb\u8f6c](/solution/1000-1099/1007.Minimum%20Domino%20Rotations%20For%20Equal%20Row/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1007](https://leetcode.com/problems/minimum-domino-rotations-for-equal-row)", "[Minimum Domino Rotations For Equal Row](/solution/1000-1099/1007.Minimum%20Domino%20Rotations%20For%20Equal%20Row/README_EN.md)", "`Greedy`,`Array`", "Medium", ""]}, {"question_id": "1048", "frontend_question_id": "1006", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/clumsy-factorial", "url_en": "https://leetcode.com/problems/clumsy-factorial", "relative_path_cn": "/solution/1000-1099/1006.Clumsy%20Factorial/README.md", "relative_path_en": "/solution/1000-1099/1006.Clumsy%20Factorial/README_EN.md", "title_cn": "\u7b28\u9636\u4e58", "title_en": "Clumsy Factorial", "question_title_slug": "clumsy-factorial", "content_en": "

    Normally, the factorial of a positive integer n is the product of all positive integers less than or equal to n.  For example, factorial(10) = 10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1.

    \n\n

    We instead make a clumsy factorial: using the integers in decreasing order, we swap out the multiply operations for a fixed rotation of operations: multiply (*), divide (/), add (+) and subtract (-) in this order.

    \n\n

    For example, clumsy(10) = 10 * 9 / 8 + 7 - 6 * 5 / 4 + 3 - 2 * 1.  However, these operations are still applied using the usual order of operations of arithmetic: we do all multiplication and division steps before any addition or subtraction steps, and multiplication and division steps are processed left to right.

    \n\n

    Additionally, the division that we use is floor division such that 10 * 9 / 8 equals 11.  This guarantees the result is an integer.

    \n\n

    Implement the clumsy function as defined above: given an integer n, it returns the clumsy factorial of n.

    \n\n

     

    \n\n

    Example 1:

    \n\n
    \nInput: n = 4\nOutput: 7\nExplanation: 7 = 4 * 3 / 2 + 1\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 10\nOutput: 12\nExplanation: 12 = 10 * 9 / 8 + 7 - 6 * 5 / 4 + 3 - 2 * 1\n
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    1. 1 <= n <= 10000
    2. \n\t
    3. -231 <= answer <= 231 - 1  (The answer is guaranteed to fit within a 32-bit integer.)
    4. \n
    \n", "content_cn": "

    \u901a\u5e38\uff0c\u6b63\u6574\u6570 n \u7684\u9636\u4e58\u662f\u6240\u6709\u5c0f\u4e8e\u6216\u7b49\u4e8e n \u7684\u6b63\u6574\u6570\u7684\u4e58\u79ef\u3002\u4f8b\u5982\uff0cfactorial(10) = 10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1\u3002

    \n\n

    \u76f8\u53cd\uff0c\u6211\u4eec\u8bbe\u8ba1\u4e86\u4e00\u4e2a\u7b28\u9636\u4e58 clumsy\uff1a\u5728\u6574\u6570\u7684\u9012\u51cf\u5e8f\u5217\u4e2d\uff0c\u6211\u4eec\u4ee5\u4e00\u4e2a\u56fa\u5b9a\u987a\u5e8f\u7684\u64cd\u4f5c\u7b26\u5e8f\u5217\u6765\u4f9d\u6b21\u66ff\u6362\u539f\u6709\u7684\u4e58\u6cd5\u64cd\u4f5c\u7b26\uff1a\u4e58\u6cd5(*)\uff0c\u9664\u6cd5(/)\uff0c\u52a0\u6cd5(+)\u548c\u51cf\u6cd5(-)\u3002

    \n\n

    \u4f8b\u5982\uff0cclumsy(10) = 10 * 9 / 8 + 7 - 6 * 5 / 4 + 3 - 2 * 1\u3002\u7136\u800c\uff0c\u8fd9\u4e9b\u8fd0\u7b97\u4ecd\u7136\u4f7f\u7528\u901a\u5e38\u7684\u7b97\u672f\u8fd0\u7b97\u987a\u5e8f\uff1a\u6211\u4eec\u5728\u4efb\u4f55\u52a0\u3001\u51cf\u6b65\u9aa4\u4e4b\u524d\u6267\u884c\u6240\u6709\u7684\u4e58\u6cd5\u548c\u9664\u6cd5\u6b65\u9aa4\uff0c\u5e76\u4e14\u6309\u4ece\u5de6\u5230\u53f3\u5904\u7406\u4e58\u6cd5\u548c\u9664\u6cd5\u6b65\u9aa4\u3002

    \n\n

    \u53e6\u5916\uff0c\u6211\u4eec\u4f7f\u7528\u7684\u9664\u6cd5\u662f\u5730\u677f\u9664\u6cd5\uff08floor division\uff09\uff0c\u6240\u4ee5 10 * 9 / 8 \u7b49\u4e8e 11\u3002\u8fd9\u4fdd\u8bc1\u7ed3\u679c\u662f\u4e00\u4e2a\u6574\u6570\u3002

    \n\n

    \u5b9e\u73b0\u4e0a\u9762\u5b9a\u4e49\u7684\u7b28\u51fd\u6570\uff1a\u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570 N\uff0c\u5b83\u8fd4\u56de N \u7684\u7b28\u9636\u4e58\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a4\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a7 = 4 * 3 / 2 + 1\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a10\n\u8f93\u51fa\uff1a12\n\u89e3\u91ca\uff1a12 = 10 * 9 / 8 + 7 - 6 * 5 / 4 + 3 - 2 * 1\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= N <= 10000
    2. \n\t
    3. -2^31 <= answer <= 2^31 - 1  \uff08\u7b54\u6848\u4fdd\u8bc1\u7b26\u5408 32 \u4f4d\u6574\u6570\u3002\uff09
    4. \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int clumsy(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int clumsy(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def clumsy(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def clumsy(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint clumsy(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int Clumsy(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar clumsy = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef clumsy(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func clumsy(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func clumsy(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def clumsy(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun clumsy(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn clumsy(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function clumsy($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function clumsy(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (clumsy n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1006](https://leetcode-cn.com/problems/clumsy-factorial)", "[\u7b28\u9636\u4e58](/solution/1000-1099/1006.Clumsy%20Factorial/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1006](https://leetcode.com/problems/clumsy-factorial)", "[Clumsy Factorial](/solution/1000-1099/1006.Clumsy%20Factorial/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "1047", "frontend_question_id": "1005", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximize-sum-of-array-after-k-negations", "url_en": "https://leetcode.com/problems/maximize-sum-of-array-after-k-negations", "relative_path_cn": "/solution/1000-1099/1005.Maximize%20Sum%20Of%20Array%20After%20K%20Negations/README.md", "relative_path_en": "/solution/1000-1099/1005.Maximize%20Sum%20Of%20Array%20After%20K%20Negations/README_EN.md", "title_cn": "K \u6b21\u53d6\u53cd\u540e\u6700\u5927\u5316\u7684\u6570\u7ec4\u548c", "title_en": "Maximize Sum Of Array After K Negations", "question_title_slug": "maximize-sum-of-array-after-k-negations", "content_en": "

    Given an array nums of integers, we must modify the array in the following way: we choose an i and replace nums[i] with -nums[i], and we repeat this process k times in total.  (We may choose the same index i multiple times.)

    \n\n

    Return the largest possible sum of the array after modifying it in this way.

    \n\n

     

    \n\n

    Example 1:

    \n\n
    \nInput: nums = [4,2,3], k = 1\nOutput: 5\nExplanation: Choose indices (1,) and nums becomes [4,-2,3].\n
    \n\n
    \n

    Example 2:

    \n\n
    \nInput: nums = [3,-1,0,2], k = 3\nOutput: 6\nExplanation: Choose indices (1, 2, 2) and nums becomes [3,1,0,2].\n
    \n\n
    \n

    Example 3:

    \n\n
    \nInput: nums = [2,-3,-1,5,-4], k = 2\nOutput: 13\nExplanation: Choose indices (1, 4) and nums becomes [2,3,-1,5,4].\n
    \n
    \n
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    1. 1 <= nums.length <= 10000
    2. \n\t
    3. 1 <= k <= 10000
    4. \n\t
    5. -100 <= nums[i] <= 100
    6. \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 A\uff0c\u6211\u4eec\u53ea\u80fd\u7528\u4ee5\u4e0b\u65b9\u6cd5\u4fee\u6539\u8be5\u6570\u7ec4\uff1a\u6211\u4eec\u9009\u62e9\u67d0\u4e2a\u7d22\u5f15 i \u5e76\u5c06 A[i] \u66ff\u6362\u4e3a -A[i]\uff0c\u7136\u540e\u603b\u5171\u91cd\u590d\u8fd9\u4e2a\u8fc7\u7a0b K \u6b21\u3002\uff08\u6211\u4eec\u53ef\u4ee5\u591a\u6b21\u9009\u62e9\u540c\u4e00\u4e2a\u7d22\u5f15 i\u3002\uff09

    \n\n

    \u4ee5\u8fd9\u79cd\u65b9\u5f0f\u4fee\u6539\u6570\u7ec4\u540e\uff0c\u8fd4\u56de\u6570\u7ec4\u53ef\u80fd\u7684\u6700\u5927\u548c\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aA = [4,2,3], K = 1\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u9009\u62e9\u7d22\u5f15 (1,) \uff0c\u7136\u540e A \u53d8\u4e3a [4,-2,3]\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aA = [3,-1,0,2], K = 3\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u9009\u62e9\u7d22\u5f15 (1, 2, 2) \uff0c\u7136\u540e A \u53d8\u4e3a [3,1,0,2]\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aA = [2,-3,-1,5,-4], K = 2\n\u8f93\u51fa\uff1a13\n\u89e3\u91ca\uff1a\u9009\u62e9\u7d22\u5f15 (1, 4) \uff0c\u7136\u540e A \u53d8\u4e3a [2,3,-1,5,4]\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= A.length <= 10000
    2. \n\t
    3. 1 <= K <= 10000
    4. \n\t
    5. -100 <= A[i] <= 100
    6. \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int largestSumAfterKNegations(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int largestSumAfterKNegations(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def largestSumAfterKNegations(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def largestSumAfterKNegations(self, nums: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint largestSumAfterKNegations(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LargestSumAfterKNegations(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar largestSumAfterKNegations = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef largest_sum_after_k_negations(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func largestSumAfterKNegations(_ nums: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func largestSumAfterKNegations(nums []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def largestSumAfterKNegations(nums: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun largestSumAfterKNegations(nums: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn largest_sum_after_k_negations(nums: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer\n */\n function largestSumAfterKNegations($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function largestSumAfterKNegations(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (largest-sum-after-k-negations nums k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1005](https://leetcode-cn.com/problems/maximize-sum-of-array-after-k-negations)", "[K \u6b21\u53d6\u53cd\u540e\u6700\u5927\u5316\u7684\u6570\u7ec4\u548c](/solution/1000-1099/1005.Maximize%20Sum%20Of%20Array%20After%20K%20Negations/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u7b80\u5355", ""], "md_table_row_en": ["[1005](https://leetcode.com/problems/maximize-sum-of-array-after-k-negations)", "[Maximize Sum Of Array After K Negations](/solution/1000-1099/1005.Maximize%20Sum%20Of%20Array%20After%20K%20Negations/README_EN.md)", "`Greedy`", "Easy", ""]}, {"question_id": "1046", "frontend_question_id": "1004", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/max-consecutive-ones-iii", "url_en": "https://leetcode.com/problems/max-consecutive-ones-iii", "relative_path_cn": "/solution/1000-1099/1004.Max%20Consecutive%20Ones%20III/README.md", "relative_path_en": "/solution/1000-1099/1004.Max%20Consecutive%20Ones%20III/README_EN.md", "title_cn": "\u6700\u5927\u8fde\u7eed1\u7684\u4e2a\u6570 III", "title_en": "Max Consecutive Ones III", "question_title_slug": "max-consecutive-ones-iii", "content_en": "

    Given a binary array nums and an integer k, return the maximum number of consecutive 1's in the array if you can flip at most k 0's.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,1,1,0,0,0,1,1,1,1,0], k = 2\nOutput: 6\nExplanation: [1,1,1,0,0,1,1,1,1,1,1]\nBolded numbers were flipped from 0 to 1. The longest subarray is underlined.
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [0,0,1,1,0,0,1,1,1,0,1,1,0,0,0,1,1,1,1], k = 3\nOutput: 10\nExplanation: [0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1]\nBolded numbers were flipped from 0 to 1. The longest subarray is underlined.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • nums[i] is either 0 or 1.
    • \n\t
    • 0 <= k <= nums.length
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u7531\u82e5\u5e72 0 \u548c 1 \u7ec4\u6210\u7684\u6570\u7ec4 A\uff0c\u6211\u4eec\u6700\u591a\u53ef\u4ee5\u5c06 K \u4e2a\u503c\u4ece 0 \u53d8\u6210 1 \u3002

    \n\n

    \u8fd4\u56de\u4ec5\u5305\u542b 1 \u7684\u6700\u957f\uff08\u8fde\u7eed\uff09\u5b50\u6570\u7ec4\u7684\u957f\u5ea6\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aA = [1,1,1,0,0,0,1,1,1,1,0], K = 2\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a \n[1,1,1,0,0,1,1,1,1,1,1]\n\u7c97\u4f53\u6570\u5b57\u4ece 0 \u7ffb\u8f6c\u5230 1\uff0c\u6700\u957f\u7684\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 6\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aA = [0,0,1,1,0,0,1,1,1,0,1,1,0,0,0,1,1,1,1], K = 3\n\u8f93\u51fa\uff1a10\n\u89e3\u91ca\uff1a\n[0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1]\n\u7c97\u4f53\u6570\u5b57\u4ece 0 \u7ffb\u8f6c\u5230 1\uff0c\u6700\u957f\u7684\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 10\u3002
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= A.length <= 20000
    2. \n\t
    3. 0 <= K <= A.length
    4. \n\t
    5. A[i] \u4e3a 0 \u6216 1 
    6. \n
    \n", "tags_en": ["Two Pointers", "Sliding Window"], "tags_cn": ["\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int longestOnes(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int longestOnes(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestOnes(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestOnes(self, nums: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint longestOnes(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LongestOnes(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar longestOnes = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef longest_ones(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestOnes(_ nums: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestOnes(nums []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestOnes(nums: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestOnes(nums: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_ones(nums: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer\n */\n function longestOnes($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestOnes(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-ones nums k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1004](https://leetcode-cn.com/problems/max-consecutive-ones-iii)", "[\u6700\u5927\u8fde\u7eed1\u7684\u4e2a\u6570 III](/solution/1000-1099/1004.Max%20Consecutive%20Ones%20III/README.md)", "`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1004](https://leetcode.com/problems/max-consecutive-ones-iii)", "[Max Consecutive Ones III](/solution/1000-1099/1004.Max%20Consecutive%20Ones%20III/README_EN.md)", "`Two Pointers`,`Sliding Window`", "Medium", ""]}, {"question_id": "1045", "frontend_question_id": "1003", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/check-if-word-is-valid-after-substitutions", "url_en": "https://leetcode.com/problems/check-if-word-is-valid-after-substitutions", "relative_path_cn": "/solution/1000-1099/1003.Check%20If%20Word%20Is%20Valid%20After%20Substitutions/README.md", "relative_path_en": "/solution/1000-1099/1003.Check%20If%20Word%20Is%20Valid%20After%20Substitutions/README_EN.md", "title_cn": "\u68c0\u67e5\u66ff\u6362\u540e\u7684\u8bcd\u662f\u5426\u6709\u6548", "title_en": "Check If Word Is Valid After Substitutions", "question_title_slug": "check-if-word-is-valid-after-substitutions", "content_en": "

    Given a string s, determine if it is valid.

    \n\n

    A string s is valid if, starting with an empty string t = "", you can transform t into s after performing the following operation any number of times:

    \n\n
      \n\t
    • Insert string "abc" into any position in t. More formally, t becomes tleft + "abc" + tright, where t == tleft + tright. Note that tleft and tright may be empty.
    • \n
    \n\n

    Return true if s is a valid string, otherwise, return false.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "aabcbc"\nOutput: true\nExplanation:\n"" -> "abc" -> "aabcbc"\nThus, "aabcbc" is valid.
    \n\n

    Example 2:

    \n\n
    \nInput: s = "abcabcababcc"\nOutput: true\nExplanation:\n"" -> "abc" -> "abcabc" -> "abcabcabc" -> "abcabcababcc"\nThus, "abcabcababcc" is valid.\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "abccba"\nOutput: false\nExplanation: It is impossible to get "abccba" using the operation.\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "cababc"\nOutput: false\nExplanation: It is impossible to get "cababc" using the operation.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 2 * 104
    • \n\t
    • s consists of letters 'a', 'b', and 'c'
    • \n
    \n", "content_cn": "\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \uff0c\u8bf7\u4f60\u5224\u65ad\u5b83\u662f\u5426 \u6709\u6548 \u3002\n

    \u5b57\u7b26\u4e32 s \u6709\u6548 \u9700\u8981\u6ee1\u8db3\uff1a\u5047\u8bbe\u5f00\u59cb\u6709\u4e00\u4e2a\u7a7a\u5b57\u7b26\u4e32 t = \"\" \uff0c\u4f60\u53ef\u4ee5\u6267\u884c \u4efb\u610f\u6b21 \u4e0b\u8ff0\u64cd\u4f5c\u5c06 t \u8f6c\u6362\u4e3a s \uff1a

    \n\n
      \n\t
    • \u5c06\u5b57\u7b26\u4e32 \"abc\" \u63d2\u5165\u5230 t \u4e2d\u7684\u4efb\u610f\u4f4d\u7f6e\u3002\u5f62\u5f0f\u4e0a\uff0ct \u53d8\u4e3a tleft + \"abc\" + tright\uff0c\u5176\u4e2d t == tleft + tright \u3002\u6ce8\u610f\uff0ctleft \u548c tright \u53ef\u80fd\u4e3a \u7a7a \u3002
    • \n
    \n\n

    \u5982\u679c\u5b57\u7b26\u4e32 s \u6709\u6548\uff0c\u5219\u8fd4\u56de true\uff1b\u5426\u5219\uff0c\u8fd4\u56de false\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"aabcbc\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\n\"\" -> \"abc\" -> \"aabcbc\"\n\u56e0\u6b64\uff0c\"aabcbc\" \u6709\u6548\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"abcabcababcc\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\n\"\" -> \"abc\" -> \"abcabc\" -> \"abcabcabc\" -> \"abcabcababcc\"\n\u56e0\u6b64\uff0c\"abcabcababcc\" \u6709\u6548\u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"abccba\"\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u6267\u884c\u64cd\u4f5c\u65e0\u6cd5\u5f97\u5230 \"abccba\" \u3002
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"cababc\"\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u6267\u884c\u64cd\u4f5c\u65e0\u6cd5\u5f97\u5230 \"cababc\" \u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 2 * 104
    • \n\t
    • s \u7531\u5b57\u6bcd 'a'\u3001'b' \u548c 'c' \u7ec4\u6210
    • \n
    \n", "tags_en": ["Stack", "String"], "tags_cn": ["\u6808", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isValid(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isValid(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isValid(self, s):\n \"\"\"\n :type s: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isValid(self, s: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isValid(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsValid(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {boolean}\n */\nvar isValid = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Boolean}\ndef is_valid(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isValid(_ s: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isValid(s string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isValid(s: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isValid(s: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_valid(s: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Boolean\n */\n function isValid($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isValid(s: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-valid s)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1003](https://leetcode-cn.com/problems/check-if-word-is-valid-after-substitutions)", "[\u68c0\u67e5\u66ff\u6362\u540e\u7684\u8bcd\u662f\u5426\u6709\u6548](/solution/1000-1099/1003.Check%20If%20Word%20Is%20Valid%20After%20Substitutions/README.md)", "`\u6808`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1003](https://leetcode.com/problems/check-if-word-is-valid-after-substitutions)", "[Check If Word Is Valid After Substitutions](/solution/1000-1099/1003.Check%20If%20Word%20Is%20Valid%20After%20Substitutions/README_EN.md)", "`Stack`,`String`", "Medium", ""]}, {"question_id": "1044", "frontend_question_id": "1002", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-common-characters", "url_en": "https://leetcode.com/problems/find-common-characters", "relative_path_cn": "/solution/1000-1099/1002.Find%20Common%20Characters/README.md", "relative_path_en": "/solution/1000-1099/1002.Find%20Common%20Characters/README_EN.md", "title_cn": "\u67e5\u627e\u5e38\u7528\u5b57\u7b26", "title_en": "Find Common Characters", "question_title_slug": "find-common-characters", "content_en": "

    Given an array words of strings made only from lowercase letters, return a list of all characters that show up in all strings within the list (including duplicates).  For example, if a character occurs 3 times in all strings but not 4 times, you need to include that character three times in the final answer.

    \n\n

    You may return the answer in any order.

    \n\n

     

    \n\n
    \n

    Example 1:

    \n\n
    \nInput: ["bella","label","roller"]\nOutput: ["e","l","l"]\n
    \n\n
    \n

    Example 2:

    \n\n
    \nInput: ["cool","lock","cook"]\nOutput: ["c","o"]\n
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    1. 1 <= words.length <= 100
    2. \n\t
    3. 1 <= words[i].length <= 100
    4. \n\t
    5. words[i] consists of lowercase English letters.
    6. \n
    \n
    \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4ec5\u6709\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210\u7684\u5b57\u7b26\u4e32\u6570\u7ec4 A\uff0c\u8fd4\u56de\u5217\u8868\u4e2d\u7684\u6bcf\u4e2a\u5b57\u7b26\u4e32\u4e2d\u90fd\u663e\u793a\u7684\u5168\u90e8\u5b57\u7b26\uff08\u5305\u62ec\u91cd\u590d\u5b57\u7b26\uff09\u7ec4\u6210\u7684\u5217\u8868\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4e00\u4e2a\u5b57\u7b26\u5728\u6bcf\u4e2a\u5b57\u7b26\u4e32\u4e2d\u51fa\u73b0 3 \u6b21\uff0c\u4f46\u4e0d\u662f 4 \u6b21\uff0c\u5219\u9700\u8981\u5728\u6700\u7ec8\u7b54\u6848\u4e2d\u5305\u542b\u8be5\u5b57\u7b26 3 \u6b21\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u6309\u4efb\u610f\u987a\u5e8f\u8fd4\u56de\u7b54\u6848\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a["bella","label","roller"]\n\u8f93\u51fa\uff1a["e","l","l"]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a["cool","lock","cook"]\n\u8f93\u51fa\uff1a["c","o"]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= A.length <= 100
    2. \n\t
    3. 1 <= A[i].length <= 100
    4. \n\t
    5. A[i][j] \u662f\u5c0f\u5199\u5b57\u6bcd
    6. \n
    \n", "tags_en": ["Array", "Hash Table"], "tags_cn": ["\u6570\u7ec4", "\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector commonChars(vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List commonChars(String[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def commonChars(self, words):\n \"\"\"\n :type words: List[str]\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def commonChars(self, words: List[str]) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** commonChars(char ** words, int wordsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList CommonChars(string[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @return {string[]}\n */\nvar commonChars = function(words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @return {String[]}\ndef common_chars(words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func commonChars(_ words: [String]) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func commonChars(words []string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def commonChars(words: Array[String]): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun commonChars(words: Array): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn common_chars(words: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @return String[]\n */\n function commonChars($words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function commonChars(words: string[]): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (common-chars words)\n (-> (listof string?) (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1002](https://leetcode-cn.com/problems/find-common-characters)", "[\u67e5\u627e\u5e38\u7528\u5b57\u7b26](/solution/1000-1099/1002.Find%20Common%20Characters/README.md)", "`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[1002](https://leetcode.com/problems/find-common-characters)", "[Find Common Characters](/solution/1000-1099/1002.Find%20Common%20Characters/README_EN.md)", "`Array`,`Hash Table`", "Easy", ""]}, {"question_id": "1043", "frontend_question_id": "1001", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/grid-illumination", "url_en": "https://leetcode.com/problems/grid-illumination", "relative_path_cn": "/solution/1000-1099/1001.Grid%20Illumination/README.md", "relative_path_en": "/solution/1000-1099/1001.Grid%20Illumination/README_EN.md", "title_cn": "\u7f51\u683c\u7167\u660e", "title_en": "Grid Illumination", "question_title_slug": "grid-illumination", "content_en": "

    There is a 2D grid of size n x n where each cell of this grid has a lamp that is initially turned off.

    \n\n

    You are given a 2D array of lamp positions lamps, where lamps[i] = [rowi, coli] indicates that the lamp at grid[rowi][coli] is turned on. Even if the same lamp is listed more than once, it is turned on.

    \n\n

    When a lamp is turned on, it illuminates its cell and all other cells in the same row, column, or diagonal.

    \n\n

    You are also given another 2D array queries, where queries[j] = [rowj, colj]. For the jth query, determine whether grid[rowj][colj] is illuminated or not. After answering the jth query, turn off the lamp at grid[rowj][colj] and its 8 adjacent lamps if they exist. A lamp is adjacent if its cell shares either a side or corner with grid[rowj][colj].

    \n\n

    Return an array of integers ans, where ans[j] should be 1 if the cell in the jth query was illuminated, or 0 if the lamp was not.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: n = 5, lamps = [[0,0],[4,4]], queries = [[1,1],[1,0]]\nOutput: [1,0]\nExplanation: We have the initial grid with all lamps turned off. In the above picture we see the grid after turning on the lamp at grid[0][0] then turning on the lamp at grid[4][4].\nThe 0th query asks if the lamp at grid[1][1] is illuminated or not (the blue square). It is illuminated, so set ans[0] = 1. Then, we turn off all lamps in the red square.\n\"\"\nThe 1st query asks if the lamp at grid[1][0] is illuminated or not (the blue square). It is not illuminated, so set ans[1] = 0. Then, we turn off all lamps in the red rectangle.\n\"\"\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 5, lamps = [[0,0],[4,4]], queries = [[1,1],[1,1]]\nOutput: [1,1]\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 5, lamps = [[0,0],[0,4]], queries = [[0,4],[0,1],[1,4]]\nOutput: [1,1,0]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 109
    • \n\t
    • 0 <= lamps.length <= 20000
    • \n\t
    • 0 <= queries.length <= 20000
    • \n\t
    • lamps[i].length == 2
    • \n\t
    • 0 <= rowi, coli < n
    • \n\t
    • queries[j].length == 2
    • \n\t
    • 0 <= rowj, colj < n
    • \n
    \n", "content_cn": "

    \u5728\u00a0N x N\u00a0\u7684\u7f51\u683c grid \u4e0a\uff0c\u6bcf\u4e2a\u5355\u5143\u683c\u90fd\u6709\u4e00\u76cf\u706f\uff0c\u6700\u521d\u706f\u90fd\u5904\u4e8e \u5173\u95ed \u72b6\u6001\u3002

    \n\n

    \u6570\u7ec4\u00a0lamps \u8868\u793a\u6253\u5f00\u7684\u706f\u7684\u4f4d\u7f6e\u3002lamps[i] = [rowi, coli] \u8868\u793a \u6253\u5f00 \u4f4d\u4e8e grid[rowi][coli] \u7684\u7b2c i \u76cf\u706f \u3002\u6bcf\u76cf\u706f\u90fd\u7167\u4eae\u81ea\u8eab\u5355\u5143\u683c\u4ee5\u53ca\u540c\u4e00\u884c\u3001\u540c\u4e00\u5217\u548c\u4e24\u6761\u5bf9\u89d2\u7ebf\u4e0a\u7684\u6240\u6709\u5176\u4ed6\u5355\u5143\u683c\u3002

    \n\n

    \u67e5\u8be2\u6570\u7ec4 queries \u4e2d\uff0c\u7b2c i \u6b21\u67e5\u8be2\u00a0queries[i] = [rowi, coli]\uff0c\u5982\u679c\u5355\u5143\u683c [rowi, coli] \u662f\u88ab\u7167\u4eae\u7684\uff0c\u5219\u67e5\u8be2\u7ed3\u679c\u4e3a 1 \uff0c\u5426\u5219\u4e3a 0 \u3002\u5728\u7b2c i \u6b21\u67e5\u8be2\u4e4b\u540e [\u6309\u7167\u67e5\u8be2\u7684\u987a\u5e8f] \uff0c\u5173\u95ed \u4f4d\u4e8e\u5355\u5143\u683c grid[rowi][coli] \u4e0a\u6216\u5176\u76f8\u90bb 8 \u4e2a\u65b9\u5411\u4e0a\uff08\u4e0e\u5355\u5143\u683c grid[rowi][coli] \u5171\u4eab\u89d2\u6216\u8fb9\uff09\u7684\u4efb\u4f55\u706f\u3002

    \n\n

    \u8fd4\u56de\u7b54\u6848\u6570\u7ec4 ans \uff0c answer[i] \u5e94\u7b49\u4e8e\u7b2c i\u00a0\u6b21\u67e5\u8be2\u00a0queries[i]\u00a0\u7684\u7ed3\u679c\uff0c1 \u8868\u793a\u7167\u4eae\uff0c0 \u8868\u793a\u672a\u7167\u4eae\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aN = 5, lamps = [[0,0],[4,4]], queries = [[1,1],[1,0]]\n\u8f93\u51fa\uff1a[1,0]\n\u89e3\u91ca\uff1a\u6700\u521d\u6240\u6709\u706f\u90fd\u662f\u5173\u95ed\u7684\u3002\u5728\u6267\u884c\u67e5\u8be2\u4e4b\u524d\uff0c\u6253\u5f00\u4f4d\u4e8e [0, 0] \u548c [4, 4] \u7684\u706f\u3002\u7b2c 0\u00a0\u6b21\u67e5\u8be2\u68c0\u67e5 grid[1][1] \u662f\u5426\u88ab\u7167\u4eae\uff08\u84dd\u8272\u65b9\u6846\uff09\u3002\u8be5\u5355\u5143\u683c\u88ab\u7167\u4eae\uff0c\u6240\u4ee5 ans[0] = 1 \u3002\u7136\u540e\uff0c\u5173\u95ed\u7ea2\u8272\u65b9\u6846\u4e2d\u7684\u6240\u6709\u706f\u3002\n\"\"\n\u7b2c 1\u00a0\u6b21\u67e5\u8be2\u68c0\u67e5 grid[1][0] \u662f\u5426\u88ab\u7167\u4eae\uff08\u84dd\u8272\u65b9\u6846\uff09\u3002\u8be5\u5355\u5143\u683c\u6ca1\u6709\u88ab\u7167\u4eae\uff0c\u6240\u4ee5 ans[1] = 0 \u3002\u7136\u540e\uff0c\u5173\u95ed\u7ea2\u8272\u77e9\u5f62\u4e2d\u7684\u6240\u6709\u706f\u3002\n\"\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aN = 5, lamps = [[0,0],[4,4]], queries = [[1,1],[1,1]]\n\u8f93\u51fa\uff1a[1,1]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aN = 5, lamps = [[0,0],[0,4]], queries = [[0,4],[0,1],[1,4]]\n\u8f93\u51fa\uff1a[1,1,0]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= N <= 109
    • \n\t
    • 0 <= lamps.length <= 20000
    • \n\t
    • lamps[i].length == 2
    • \n\t
    • 0 <= lamps[i][j] < N
    • \n\t
    • 0 <= queries.length <= 20000
    • \n\t
    • queries[i].length == 2
    • \n\t
    • 0 <= queries[i][j] < N
    • \n
    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector gridIllumination(int n, vector>& lamps, vector>& queries) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] gridIllumination(int n, int[][] lamps, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def gridIllumination(self, n, lamps, queries):\n \"\"\"\n :type n: int\n :type lamps: List[List[int]]\n :type queries: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def gridIllumination(self, n: int, lamps: List[List[int]], queries: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* gridIllumination(int n, int** lamps, int lampsSize, int* lampsColSize, int** queries, int queriesSize, int* queriesColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] GridIllumination(int n, int[][] lamps, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} lamps\n * @param {number[][]} queries\n * @return {number[]}\n */\nvar gridIllumination = function(n, lamps, queries) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} lamps\n# @param {Integer[][]} queries\n# @return {Integer[]}\ndef grid_illumination(n, lamps, queries)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func gridIllumination(_ n: Int, _ lamps: [[Int]], _ queries: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func gridIllumination(n int, lamps [][]int, queries [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def gridIllumination(n: Int, lamps: Array[Array[Int]], queries: Array[Array[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun gridIllumination(n: Int, lamps: Array, queries: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn grid_illumination(n: i32, lamps: Vec>, queries: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $lamps\n * @param Integer[][] $queries\n * @return Integer[]\n */\n function gridIllumination($n, $lamps, $queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function gridIllumination(n: number, lamps: number[][], queries: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (grid-illumination n lamps queries)\n (-> exact-integer? (listof (listof exact-integer?)) (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1001](https://leetcode-cn.com/problems/grid-illumination)", "[\u7f51\u683c\u7167\u660e](/solution/1000-1099/1001.Grid%20Illumination/README.md)", "`\u54c8\u5e0c\u8868`", "\u56f0\u96be", ""], "md_table_row_en": ["[1001](https://leetcode.com/problems/grid-illumination)", "[Grid Illumination](/solution/1000-1099/1001.Grid%20Illumination/README_EN.md)", "`Hash Table`", "Hard", ""]}, {"question_id": "1042", "frontend_question_id": "1000", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-cost-to-merge-stones", "url_en": "https://leetcode.com/problems/minimum-cost-to-merge-stones", "relative_path_cn": "/solution/1000-1099/1000.Minimum%20Cost%20to%20Merge%20Stones/README.md", "relative_path_en": "/solution/1000-1099/1000.Minimum%20Cost%20to%20Merge%20Stones/README_EN.md", "title_cn": "\u5408\u5e76\u77f3\u5934\u7684\u6700\u4f4e\u6210\u672c", "title_en": "Minimum Cost to Merge Stones", "question_title_slug": "minimum-cost-to-merge-stones", "content_en": "

    There are n piles of stones arranged in a row. The ith pile has stones[i] stones.

    \n\n

    A move consists of merging exactly k consecutive piles into one pile, and the cost of this move is equal to the total number of stones in these k piles.

    \n\n

    Return the minimum cost to merge all piles of stones into one pile. If it is impossible, return -1.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: stones = [3,2,4,1], k = 2\nOutput: 20\nExplanation: We start with [3, 2, 4, 1].\nWe merge [3, 2] for a cost of 5, and we are left with [5, 4, 1].\nWe merge [4, 1] for a cost of 5, and we are left with [5, 5].\nWe merge [5, 5] for a cost of 10, and we are left with [10].\nThe total cost was 20, and this is the minimum possible.\n
    \n\n

    Example 2:

    \n\n
    \nInput: stones = [3,2,4,1], k = 3\nOutput: -1\nExplanation: After any merge operation, there are 2 piles left, and we can't merge anymore.  So the task is impossible.\n
    \n\n

    Example 3:

    \n\n
    \nInput: stones = [3,5,1,2,6], k = 3\nOutput: 25\nExplanation: We start with [3, 5, 1, 2, 6].\nWe merge [5, 1, 2] for a cost of 8, and we are left with [3, 8, 6].\nWe merge [3, 8, 6] for a cost of 17, and we are left with [17].\nThe total cost was 25, and this is the minimum possible.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == stones.length
    • \n\t
    • 1 <= n <= 30
    • \n\t
    • 1 <= stones[i] <= 100
    • \n\t
    • 2 <= k <= 30
    • \n
    \n", "content_cn": "

    \u6709 N \u5806\u77f3\u5934\u6392\u6210\u4e00\u6392\uff0c\u7b2c i \u5806\u4e2d\u6709 stones[i] \u5757\u77f3\u5934\u3002

    \n\n

    \u6bcf\u6b21\u79fb\u52a8\uff08move\uff09\u9700\u8981\u5c06\u8fde\u7eed\u7684 K \u5806\u77f3\u5934\u5408\u5e76\u4e3a\u4e00\u5806\uff0c\u800c\u8fd9\u4e2a\u79fb\u52a8\u7684\u6210\u672c\u4e3a\u8fd9 K \u5806\u77f3\u5934\u7684\u603b\u6570\u3002

    \n\n

    \u627e\u51fa\u628a\u6240\u6709\u77f3\u5934\u5408\u5e76\u6210\u4e00\u5806\u7684\u6700\u4f4e\u6210\u672c\u3002\u5982\u679c\u4e0d\u53ef\u80fd\uff0c\u8fd4\u56de -1 \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1astones = [3,2,4,1], K = 2\n\u8f93\u51fa\uff1a20\n\u89e3\u91ca\uff1a\n\u4ece [3, 2, 4, 1] \u5f00\u59cb\u3002\n\u5408\u5e76 [3, 2]\uff0c\u6210\u672c\u4e3a 5\uff0c\u5269\u4e0b [5, 4, 1]\u3002\n\u5408\u5e76 [4, 1]\uff0c\u6210\u672c\u4e3a 5\uff0c\u5269\u4e0b [5, 5]\u3002\n\u5408\u5e76 [5, 5]\uff0c\u6210\u672c\u4e3a 10\uff0c\u5269\u4e0b [10]\u3002\n\u603b\u6210\u672c 20\uff0c\u8fd9\u662f\u53ef\u80fd\u7684\u6700\u5c0f\u503c\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1astones = [3,2,4,1], K = 3\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u4efb\u4f55\u5408\u5e76\u64cd\u4f5c\u540e\uff0c\u90fd\u4f1a\u5269\u4e0b 2 \u5806\uff0c\u6211\u4eec\u65e0\u6cd5\u518d\u8fdb\u884c\u5408\u5e76\u3002\u6240\u4ee5\u8fd9\u9879\u4efb\u52a1\u662f\u4e0d\u53ef\u80fd\u5b8c\u6210\u7684\u3002.\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1astones = [3,5,1,2,6], K = 3\n\u8f93\u51fa\uff1a25\n\u89e3\u91ca\uff1a\n\u4ece [3, 5, 1, 2, 6] \u5f00\u59cb\u3002\n\u5408\u5e76 [5, 1, 2]\uff0c\u6210\u672c\u4e3a 8\uff0c\u5269\u4e0b [3, 8, 6]\u3002\n\u5408\u5e76 [3, 8, 6]\uff0c\u6210\u672c\u4e3a 17\uff0c\u5269\u4e0b [17]\u3002\n\u603b\u6210\u672c 25\uff0c\u8fd9\u662f\u53ef\u80fd\u7684\u6700\u5c0f\u503c\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= stones.length <= 30
    • \n\t
    • 2 <= K <= 30
    • \n\t
    • 1 <= stones[i] <= 100
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int mergeStones(vector& stones, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int mergeStones(int[] stones, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def mergeStones(self, stones, k):\n \"\"\"\n :type stones: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def mergeStones(self, stones: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint mergeStones(int* stones, int stonesSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MergeStones(int[] stones, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} stones\n * @param {number} k\n * @return {number}\n */\nvar mergeStones = function(stones, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} stones\n# @param {Integer} k\n# @return {Integer}\ndef merge_stones(stones, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func mergeStones(_ stones: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func mergeStones(stones []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def mergeStones(stones: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun mergeStones(stones: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn merge_stones(stones: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $stones\n * @param Integer $k\n * @return Integer\n */\n function mergeStones($stones, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function mergeStones(stones: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (merge-stones stones k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1000](https://leetcode-cn.com/problems/minimum-cost-to-merge-stones)", "[\u5408\u5e76\u77f3\u5934\u7684\u6700\u4f4e\u6210\u672c](/solution/1000-1099/1000.Minimum%20Cost%20to%20Merge%20Stones/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1000](https://leetcode.com/problems/minimum-cost-to-merge-stones)", "[Minimum Cost to Merge Stones](/solution/1000-1099/1000.Minimum%20Cost%20to%20Merge%20Stones/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1041", "frontend_question_id": "0999", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/available-captures-for-rook", "url_en": "https://leetcode.com/problems/available-captures-for-rook", "relative_path_cn": "/solution/0900-0999/0999.Available%20Captures%20for%20Rook/README.md", "relative_path_en": "/solution/0900-0999/0999.Available%20Captures%20for%20Rook/README_EN.md", "title_cn": "\u53ef\u4ee5\u88ab\u4e00\u6b65\u6355\u83b7\u7684\u68cb\u5b50\u6570", "title_en": "Available Captures for Rook", "question_title_slug": "available-captures-for-rook", "content_en": "

    On an 8 x 8 chessboard, there is exactly one white rook 'R' and some number of white bishops 'B', black pawns 'p', and empty squares '.'.

    \n\n

    When the rook moves, it chooses one of four cardinal directions (north, east, south, or west), then moves in that direction until it chooses to stop, reaches the edge of the board, captures a black pawn, or is blocked by a white bishop. A rook is considered attacking a pawn if the rook can capture the pawn on the rook's turn. The number of available captures for the white rook is the number of pawns that the rook is attacking.

    \n\n

    Return the number of available captures for the white rook.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: board = [[".",".",".",".",".",".",".","."],[".",".",".","p",".",".",".","."],[".",".",".","R",".",".",".","p"],[".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".","."],[".",".",".","p",".",".",".","."],[".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".","."]]\nOutput: 3\nExplanation: In this example, the rook is attacking all the pawns.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: board = [[".",".",".",".",".",".",".","."],[".","p","p","p","p","p",".","."],[".","p","p","B","p","p",".","."],[".","p","B","R","B","p",".","."],[".","p","p","B","p","p",".","."],[".","p","p","p","p","p",".","."],[".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".","."]]\nOutput: 0\nExplanation: The bishops are blocking the rook from attacking any of the pawns.\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: board = [[".",".",".",".",".",".",".","."],[".",".",".","p",".",".",".","."],[".",".",".","p",".",".",".","."],["p","p",".","R",".","p","B","."],[".",".",".",".",".",".",".","."],[".",".",".","B",".",".",".","."],[".",".",".","p",".",".",".","."],[".",".",".",".",".",".",".","."]]\nOutput: 3\nExplanation: The rook is attacking the pawns at positions b5, d6, and f5.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • board.length == 8
    • \n\t
    • board[i].length == 8
    • \n\t
    • board[i][j] is either 'R', '.', 'B', or 'p'
    • \n\t
    • There is exactly one cell with board[i][j] == 'R'
    • \n
    \n", "content_cn": "

    \u5728\u4e00\u4e2a 8 x 8 \u7684\u68cb\u76d8\u4e0a\uff0c\u6709\u4e00\u4e2a\u767d\u8272\u7684\u8f66\uff08Rook\uff09\uff0c\u7528\u5b57\u7b26 'R' \u8868\u793a\u3002\u68cb\u76d8\u4e0a\u8fd8\u53ef\u80fd\u5b58\u5728\u7a7a\u65b9\u5757\uff0c\u767d\u8272\u7684\u8c61\uff08Bishop\uff09\u4ee5\u53ca\u9ed1\u8272\u7684\u5352\uff08pawn\uff09\uff0c\u5206\u522b\u7528\u5b57\u7b26 '.'\uff0c'B' \u548c 'p' \u8868\u793a\u3002\u4e0d\u96be\u770b\u51fa\uff0c\u5927\u5199\u5b57\u7b26\u8868\u793a\u7684\u662f\u767d\u68cb\uff0c\u5c0f\u5199\u5b57\u7b26\u8868\u793a\u7684\u662f\u9ed1\u68cb\u3002

    \n\n

    \u8f66\u6309\u56fd\u9645\u8c61\u68cb\u4e2d\u7684\u89c4\u5219\u79fb\u52a8\u3002\u4e1c\uff0c\u897f\uff0c\u5357\uff0c\u5317\u56db\u4e2a\u57fa\u672c\u65b9\u5411\u4efb\u9009\u5176\u4e00\uff0c\u7136\u540e\u4e00\u76f4\u5411\u9009\u5b9a\u7684\u65b9\u5411\u79fb\u52a8\uff0c\u76f4\u5230\u6ee1\u8db3\u4e0b\u5217\u56db\u4e2a\u6761\u4ef6\u4e4b\u4e00\uff1a

    \n\n
      \n\t
    • \u68cb\u624b\u9009\u62e9\u4e3b\u52a8\u505c\u4e0b\u6765\u3002
    • \n\t
    • \u68cb\u5b50\u56e0\u5230\u8fbe\u68cb\u76d8\u7684\u8fb9\u7f18\u800c\u505c\u4e0b\u3002
    • \n\t
    • \u68cb\u5b50\u79fb\u52a8\u5230\u67d0\u4e00\u65b9\u683c\u6765\u6355\u83b7\u4f4d\u4e8e\u8be5\u65b9\u683c\u4e0a\u654c\u65b9\uff08\u9ed1\u8272\uff09\u7684\u5352\uff0c\u505c\u5728\u8be5\u65b9\u683c\u5185\u3002
    • \n\t
    • \u8f66\u4e0d\u80fd\u8fdb\u5165/\u8d8a\u8fc7\u5df2\u7ecf\u653e\u6709\u5176\u4ed6\u53cb\u65b9\u68cb\u5b50\uff08\u767d\u8272\u7684\u8c61\uff09\u7684\u65b9\u683c\uff0c\u505c\u5728\u53cb\u65b9\u68cb\u5b50\u524d\u3002
    • \n
    \n\n

    \u4f60\u73b0\u5728\u53ef\u4ee5\u63a7\u5236\u8f66\u79fb\u52a8\u4e00\u6b21\uff0c\u8bf7\u4f60\u7edf\u8ba1\u6709\u591a\u5c11\u654c\u65b9\u7684\u5352\u5904\u4e8e\u4f60\u7684\u6355\u83b7\u8303\u56f4\u5185\uff08\u5373\uff0c\u53ef\u4ee5\u88ab\u4e00\u6b65\u6355\u83b7\u7684\u68cb\u5b50\u6570\uff09\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1a[[".",".",".",".",".",".",".","."],[".",".",".","p",".",".",".","."],[".",".",".","R",".",".",".","p"],[".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".","."],[".",".",".","p",".",".",".","."],[".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".","."]]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\n\u5728\u672c\u4f8b\u4e2d\uff0c\u8f66\u80fd\u591f\u6355\u83b7\u6240\u6709\u7684\u5352\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1a[[".",".",".",".",".",".",".","."],[".","p","p","p","p","p",".","."],[".","p","p","B","p","p",".","."],[".","p","B","R","B","p",".","."],[".","p","p","B","p","p",".","."],[".","p","p","p","p","p",".","."],[".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".","."]]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\n\u8c61\u963b\u6b62\u4e86\u8f66\u6355\u83b7\u4efb\u4f55\u5352\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1a[[".",".",".",".",".",".",".","."],[".",".",".","p",".",".",".","."],[".",".",".","p",".",".",".","."],["p","p",".","R",".","p","B","."],[".",".",".",".",".",".",".","."],[".",".",".","B",".",".",".","."],[".",".",".","p",".",".",".","."],[".",".",".",".",".",".",".","."]]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a \n\u8f66\u53ef\u4ee5\u6355\u83b7\u4f4d\u7f6e b5\uff0cd6 \u548c f5 \u7684\u5352\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. board.length == board[i].length == 8
    2. \n\t
    3. board[i][j] \u53ef\u4ee5\u662f 'R'\uff0c'.'\uff0c'B' \u6216 'p'
    4. \n\t
    5. \u53ea\u6709\u4e00\u4e2a\u683c\u5b50\u4e0a\u5b58\u5728 board[i][j] == 'R'
    6. \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numRookCaptures(vector>& board) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numRookCaptures(char[][] board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numRookCaptures(self, board):\n \"\"\"\n :type board: List[List[str]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numRookCaptures(self, board: List[List[str]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numRookCaptures(char** board, int boardSize, int* boardColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumRookCaptures(char[][] board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {character[][]} board\n * @return {number}\n */\nvar numRookCaptures = function(board) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Character[][]} board\n# @return {Integer}\ndef num_rook_captures(board)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numRookCaptures(_ board: [[Character]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numRookCaptures(board [][]byte) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numRookCaptures(board: Array[Array[Char]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numRookCaptures(board: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_rook_captures(board: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $board\n * @return Integer\n */\n function numRookCaptures($board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numRookCaptures(board: string[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-rook-captures board)\n (-> (listof (listof char?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0999](https://leetcode-cn.com/problems/available-captures-for-rook)", "[\u53ef\u4ee5\u88ab\u4e00\u6b65\u6355\u83b7\u7684\u68cb\u5b50\u6570](/solution/0900-0999/0999.Available%20Captures%20for%20Rook/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0999](https://leetcode.com/problems/available-captures-for-rook)", "[Available Captures for Rook](/solution/0900-0999/0999.Available%20Captures%20for%20Rook/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1040", "frontend_question_id": "0998", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-binary-tree-ii", "url_en": "https://leetcode.com/problems/maximum-binary-tree-ii", "relative_path_cn": "/solution/0900-0999/0998.Maximum%20Binary%20Tree%20II/README.md", "relative_path_en": "/solution/0900-0999/0998.Maximum%20Binary%20Tree%20II/README_EN.md", "title_cn": "\u6700\u5927\u4e8c\u53c9\u6811 II", "title_en": "Maximum Binary Tree II", "question_title_slug": "maximum-binary-tree-ii", "content_en": "

    We are given the root node of a maximum tree: a tree where every node has a value greater than any other value in its subtree.

    \n\n

    Just as in the previous problem, the given tree was constructed from an list A (root = Construct(A)) recursively with the following Construct(A) routine:

    \n\n
      \n\t
    • If A is empty, return null.
    • \n\t
    • Otherwise, let A[i] be the largest element of A.  Create a root node with value A[i].
    • \n\t
    • The left child of root will be Construct([A[0], A[1], ..., A[i-1]])
    • \n\t
    • The right child of root will be Construct([A[i+1], A[i+2], ..., A[A.length - 1]])
    • \n\t
    • Return root.
    • \n
    \n\n

    Note that we were not given A directly, only a root node root = Construct(A).

    \n\n

    Suppose B is a copy of A with the value val appended to it.  It is guaranteed that B has unique values.

    \n\n

    Return Construct(B).

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"\"\"

    \n\n
    \nInput: root = [4,1,3,null,null,2], val = 5\nOutput: [5,4,null,1,3,null,null,2]\nExplanation: A = [1,4,2,3], B = [1,4,2,3,5]\n
    \n\n

    Example 2:

    \n\n

    \"\"\"\"

    \n\n
    \nInput: root = [5,2,4,null,1], val = 3\nOutput: [5,2,4,null,1,null,3]\nExplanation: A = [2,1,5,4], B = [2,1,5,4,3]\n
    \n\n

    Example 3:

    \n\n

    \"\"\"\"

    \n\n
    \nInput: root = [5,2,3,null,1], val = 4\nOutput: [5,2,4,null,1,3]\nExplanation: A = [2,1,5,3], B = [2,1,5,3,4]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= B.length <= 100
    • \n
    \n", "content_cn": "

    \u6700\u5927\u6811\u5b9a\u4e49\uff1a\u4e00\u4e2a\u6811\uff0c\u5176\u4e2d\u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u90fd\u5927\u4e8e\u5176\u5b50\u6811\u4e2d\u7684\u4efb\u4f55\u5176\u4ed6\u503c\u3002

    \n\n

    \u7ed9\u51fa\u6700\u5927\u6811\u7684\u6839\u8282\u70b9 root\u3002

    \n\n

    \u5c31\u50cf\u4e4b\u524d\u7684\u95ee\u9898\u90a3\u6837\uff0c\u7ed9\u5b9a\u7684\u6811\u662f\u4ece\u5217\u8868\u00a0A\uff08root = Construct(A)\uff09\u9012\u5f52\u5730\u4f7f\u7528\u4e0b\u8ff0\u00a0Construct(A)\u00a0\u4f8b\u7a0b\u6784\u9020\u7684\uff1a

    \n\n
      \n\t
    • \u5982\u679c\u00a0A\u00a0\u4e3a\u7a7a\uff0c\u8fd4\u56de\u00a0null
    • \n\t
    • \u5426\u5219\uff0c\u4ee4\u00a0A[i]\u00a0\u4f5c\u4e3a A \u7684\u6700\u5927\u5143\u7d20\u3002\u521b\u5efa\u4e00\u4e2a\u503c\u4e3a\u00a0A[i]\u00a0\u7684\u6839\u8282\u70b9 root
    • \n\t
    • root\u00a0\u7684\u5de6\u5b50\u6811\u5c06\u88ab\u6784\u5efa\u4e3a\u00a0Construct([A[0], A[1], ..., A[i-1]])
    • \n\t
    • root\u00a0\u7684\u53f3\u5b50\u6811\u5c06\u88ab\u6784\u5efa\u4e3a Construct([A[i+1], A[i+2], ..., A[A.length - 1]])
    • \n\t
    • \u8fd4\u56de\u00a0root
    • \n
    \n\n

    \u8bf7\u6ce8\u610f\uff0c\u6211\u4eec\u6ca1\u6709\u76f4\u63a5\u7ed9\u5b9a\u00a0A\uff0c\u53ea\u6709\u4e00\u4e2a\u6839\u8282\u70b9\u00a0root = Construct(A).

    \n\n

    \u5047\u8bbe B \u662f A \u7684\u526f\u672c\uff0c\u5e76\u5728\u672b\u5c3e\u9644\u52a0\u503c val\u3002\u9898\u76ee\u6570\u636e\u4fdd\u8bc1 B\u00a0\u4e2d\u7684\u503c\u662f\u4e0d\u540c\u7684\u3002

    \n\n

    \u8fd4\u56de\u00a0Construct(B)\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"\"\"

    \n\n
    \n\u8f93\u5165\uff1aroot = [4,1,3,null,null,2], val = 5\n\u8f93\u51fa\uff1a[5,4,null,1,3,null,null,2]\n\u89e3\u91ca\uff1aA = [1,4,2,3], B = [1,4,2,3,5]\n
    \n\n

    \u793a\u4f8b 2\uff1a
    \n\"\"\"\"

    \n\n
    \n\u8f93\u5165\uff1aroot = [5,2,4,null,1], val = 3\n\u8f93\u51fa\uff1a[5,2,4,null,1,null,3]\n\u89e3\u91ca\uff1aA = [2,1,5,4], B = [2,1,5,4,3]\n
    \n\n

    \u793a\u4f8b 3\uff1a
    \n\"\"\"\"

    \n\n
    \n\u8f93\u5165\uff1aroot = [5,2,3,null,1], val = 4\n\u8f93\u51fa\uff1a[5,2,4,null,1,3]\n\u89e3\u91ca\uff1aA = [2,1,5,3], B = [2,1,5,3,4]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= B.length <= 100
    • \n
    \n\n

    \u00a0

    \n\n

    \u00a0

    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* insertIntoMaxTree(TreeNode* root, int val) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode insertIntoMaxTree(TreeNode root, int val) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def insertIntoMaxTree(self, root, val):\n \"\"\"\n :type root: TreeNode\n :type val: int\n :rtype: TreeNode\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def insertIntoMaxTree(self, root: TreeNode, val: int) -> TreeNode:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* insertIntoMaxTree(struct TreeNode* root, int val){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode InsertIntoMaxTree(TreeNode root, int val) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number} val\n * @return {TreeNode}\n */\nvar insertIntoMaxTree = function(root, val) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @param {Integer} val\n# @return {TreeNode}\ndef insert_into_max_tree(root, val)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func insertIntoMaxTree(_ root: TreeNode?, _ val: Int) -> TreeNode? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc insertIntoMaxTree(root *TreeNode, val int) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def insertIntoMaxTree(root: TreeNode, `val`: Int): TreeNode = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun insertIntoMaxTree(root: TreeNode?, `val`: Int): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn insert_into_max_tree(root: Option>>, val: i32) -> Option>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param Integer $val\n * @return TreeNode\n */\n function insertIntoMaxTree($root, $val) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction insertIntoMaxTree(root: TreeNode | null, val: number): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (insert-into-max-tree root val)\n (-> (or/c tree-node? #f) exact-integer? (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0998](https://leetcode-cn.com/problems/maximum-binary-tree-ii)", "[\u6700\u5927\u4e8c\u53c9\u6811 II](/solution/0900-0999/0998.Maximum%20Binary%20Tree%20II/README.md)", "`\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0998](https://leetcode.com/problems/maximum-binary-tree-ii)", "[Maximum Binary Tree II](/solution/0900-0999/0998.Maximum%20Binary%20Tree%20II/README_EN.md)", "`Tree`", "Medium", ""]}, {"question_id": "1039", "frontend_question_id": "0997", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-the-town-judge", "url_en": "https://leetcode.com/problems/find-the-town-judge", "relative_path_cn": "/solution/0900-0999/0997.Find%20the%20Town%20Judge/README.md", "relative_path_en": "/solution/0900-0999/0997.Find%20the%20Town%20Judge/README_EN.md", "title_cn": "\u627e\u5230\u5c0f\u9547\u7684\u6cd5\u5b98", "title_en": "Find the Town Judge", "question_title_slug": "find-the-town-judge", "content_en": "

    In a town, there are n people labelled from 1 to n.  There is a rumor that one of these people is secretly the town judge.

    \n\n

    If the town judge exists, then:

    \n\n
      \n\t
    1. The town judge trusts nobody.
    2. \n\t
    3. Everybody (except for the town judge) trusts the town judge.
    4. \n\t
    5. There is exactly one person that satisfies properties 1 and 2.
    6. \n
    \n\n

    You are given trust, an array of pairs trust[i] = [a, b] representing that the person labelled a trusts the person labelled b.

    \n\n

    If the town judge exists and can be identified, return the label of the town judge.  Otherwise, return -1.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 2, trust = [[1,2]]\nOutput: 2\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 3, trust = [[1,3],[2,3]]\nOutput: 3\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 3, trust = [[1,3],[2,3],[3,1]]\nOutput: -1\n
    \n\n

    Example 4:

    \n\n
    \nInput: n = 3, trust = [[1,2],[2,3]]\nOutput: -1\n
    \n\n

    Example 5:

    \n\n
    \nInput: n = 4, trust = [[1,3],[1,4],[2,3],[2,4],[4,3]]\nOutput: 3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 1000
    • \n\t
    • 0 <= trust.length <= 104
    • \n\t
    • trust[i].length == 2
    • \n\t
    • trust[i] are all different
    • \n\t
    • trust[i][0] != trust[i][1]
    • \n\t
    • 1 <= trust[i][0], trust[i][1] <= n
    • \n
    \n", "content_cn": "

    \u5728\u4e00\u4e2a\u5c0f\u9547\u91cc\uff0c\u6309\u4ece 1 \u5230 N \u6807\u8bb0\u4e86 N \u4e2a\u4eba\u3002\u4f20\u8a00\u79f0\uff0c\u8fd9\u4e9b\u4eba\u4e2d\u6709\u4e00\u4e2a\u662f\u5c0f\u9547\u4e0a\u7684\u79d8\u5bc6\u6cd5\u5b98\u3002

    \n\n

    \u5982\u679c\u5c0f\u9547\u7684\u6cd5\u5b98\u771f\u7684\u5b58\u5728\uff0c\u90a3\u4e48\uff1a

    \n\n
      \n\t
    1. \u5c0f\u9547\u7684\u6cd5\u5b98\u4e0d\u76f8\u4fe1\u4efb\u4f55\u4eba\u3002
    2. \n\t
    3. \u6bcf\u4e2a\u4eba\uff08\u9664\u4e86\u5c0f\u9547\u6cd5\u5b98\u5916\uff09\u90fd\u4fe1\u4efb\u5c0f\u9547\u7684\u6cd5\u5b98\u3002
    4. \n\t
    5. \u53ea\u6709\u4e00\u4e2a\u4eba\u540c\u65f6\u6ee1\u8db3\u5c5e\u6027 1 \u548c\u5c5e\u6027 2 \u3002
    6. \n
    \n\n

    \u7ed9\u5b9a\u6570\u7ec4 trust\uff0c\u8be5\u6570\u7ec4\u7531\u4fe1\u4efb\u5bf9 trust[i] = [a, b] \u7ec4\u6210\uff0c\u8868\u793a\u6807\u8bb0\u4e3a a \u7684\u4eba\u4fe1\u4efb\u6807\u8bb0\u4e3a b \u7684\u4eba\u3002

    \n\n

    \u5982\u679c\u5c0f\u9547\u5b58\u5728\u79d8\u5bc6\u6cd5\u5b98\u5e76\u4e14\u53ef\u4ee5\u786e\u5b9a\u4ed6\u7684\u8eab\u4efd\uff0c\u8bf7\u8fd4\u56de\u8be5\u6cd5\u5b98\u7684\u6807\u8bb0\u3002\u5426\u5219\uff0c\u8fd4\u56de -1\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aN = 2, trust = [[1,2]]\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aN = 3, trust = [[1,3],[2,3]]\n\u8f93\u51fa\uff1a3\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aN = 3, trust = [[1,3],[2,3],[3,1]]\n\u8f93\u51fa\uff1a-1\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1aN = 3, trust = [[1,2],[2,3]]\n\u8f93\u51fa\uff1a-1\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1aN = 4, trust = [[1,3],[1,4],[2,3],[2,4],[4,3]]\n\u8f93\u51fa\uff1a3
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= N <= 1000
    2. \n\t
    3. trust.length <= 10000
    4. \n\t
    5. trust[i] \u662f\u5b8c\u5168\u4e0d\u540c\u7684
    6. \n\t
    7. trust[i][0] != trust[i][1]
    8. \n\t
    9. 1 <= trust[i][0], trust[i][1] <= N
    10. \n
    \n", "tags_en": ["Graph"], "tags_cn": ["\u56fe"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findJudge(int n, vector>& trust) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findJudge(int n, int[][] trust) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findJudge(self, n, trust):\n \"\"\"\n :type n: int\n :type trust: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findJudge(self, n: int, trust: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findJudge(int n, int** trust, int trustSize, int* trustColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindJudge(int n, int[][] trust) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} trust\n * @return {number}\n */\nvar findJudge = function(n, trust) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} trust\n# @return {Integer}\ndef find_judge(n, trust)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findJudge(_ n: Int, _ trust: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findJudge(n int, trust [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findJudge(n: Int, trust: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findJudge(n: Int, trust: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_judge(n: i32, trust: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $trust\n * @return Integer\n */\n function findJudge($n, $trust) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findJudge(n: number, trust: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-judge n trust)\n (-> exact-integer? (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0997](https://leetcode-cn.com/problems/find-the-town-judge)", "[\u627e\u5230\u5c0f\u9547\u7684\u6cd5\u5b98](/solution/0900-0999/0997.Find%20the%20Town%20Judge/README.md)", "`\u56fe`", "\u7b80\u5355", ""], "md_table_row_en": ["[0997](https://leetcode.com/problems/find-the-town-judge)", "[Find the Town Judge](/solution/0900-0999/0997.Find%20the%20Town%20Judge/README_EN.md)", "`Graph`", "Easy", ""]}, {"question_id": "1038", "frontend_question_id": "0996", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-squareful-arrays", "url_en": "https://leetcode.com/problems/number-of-squareful-arrays", "relative_path_cn": "/solution/0900-0999/0996.Number%20of%20Squareful%20Arrays/README.md", "relative_path_en": "/solution/0900-0999/0996.Number%20of%20Squareful%20Arrays/README_EN.md", "title_cn": "\u6b63\u65b9\u5f62\u6570\u7ec4\u7684\u6570\u76ee", "title_en": "Number of Squareful Arrays", "question_title_slug": "number-of-squareful-arrays", "content_en": "

    Given an array nums of non-negative integers, the array is squareful if for every pair of adjacent elements, their sum is a perfect square.

    \n\n

    Return the number of permutations of nums that are squareful.  Two permutations perm1 and perm2 differ if and only if there is some index i such that perm1[i] != perm2[i].

    \n\n

     

    \n\n

    Example 1:

    \n\n
    \nInput: nums = [1,17,8]\nOutput: 2\nExplanation: \n[1,8,17] and [17,8,1] are the valid permutations.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [2,2,2]\nOutput: 1\n
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    1. 1 <= nums.length <= 12
    2. \n\t
    3. 0 <= nums[i] <= 109
    4. \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\u6570\u7ec4 A\uff0c\u5982\u679c\u8be5\u6570\u7ec4\u6bcf\u5bf9\u76f8\u90bb\u5143\u7d20\u4e4b\u548c\u662f\u4e00\u4e2a\u5b8c\u5168\u5e73\u65b9\u6570\uff0c\u5219\u79f0\u8fd9\u4e00\u6570\u7ec4\u4e3a\u6b63\u65b9\u5f62\u6570\u7ec4\u3002

    \n\n

    \u8fd4\u56de A \u7684\u6b63\u65b9\u5f62\u6392\u5217\u7684\u6570\u76ee\u3002\u4e24\u4e2a\u6392\u5217 A1 \u548c A2 \u4e0d\u540c\u7684\u5145\u8981\u6761\u4ef6\u662f\u5b58\u5728\u67d0\u4e2a\u7d22\u5f15 i\uff0c\u4f7f\u5f97 A1[i] != A2[i]\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a[1,17,8]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n[1,8,17] \u548c [17,8,1] \u90fd\u662f\u6709\u6548\u7684\u6392\u5217\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a[2,2,2]\n\u8f93\u51fa\uff1a1\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= A.length <= 12
    2. \n\t
    3. 0 <= A[i] <= 1e9
    4. \n
    \n", "tags_en": ["Graph", "Math", "Backtracking"], "tags_cn": ["\u56fe", "\u6570\u5b66", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numSquarefulPerms(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numSquarefulPerms(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numSquarefulPerms(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numSquarefulPerms(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numSquarefulPerms(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumSquarefulPerms(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar numSquarefulPerms = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef num_squareful_perms(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numSquarefulPerms(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numSquarefulPerms(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numSquarefulPerms(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numSquarefulPerms(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_squareful_perms(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function numSquarefulPerms($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numSquarefulPerms(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-squareful-perms nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0996](https://leetcode-cn.com/problems/number-of-squareful-arrays)", "[\u6b63\u65b9\u5f62\u6570\u7ec4\u7684\u6570\u76ee](/solution/0900-0999/0996.Number%20of%20Squareful%20Arrays/README.md)", "`\u56fe`,`\u6570\u5b66`,`\u56de\u6eaf\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[0996](https://leetcode.com/problems/number-of-squareful-arrays)", "[Number of Squareful Arrays](/solution/0900-0999/0996.Number%20of%20Squareful%20Arrays/README_EN.md)", "`Graph`,`Math`,`Backtracking`", "Hard", ""]}, {"question_id": "1037", "frontend_question_id": "0995", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-number-of-k-consecutive-bit-flips", "url_en": "https://leetcode.com/problems/minimum-number-of-k-consecutive-bit-flips", "relative_path_cn": "/solution/0900-0999/0995.Minimum%20Number%20of%20K%20Consecutive%20Bit%20Flips/README.md", "relative_path_en": "/solution/0900-0999/0995.Minimum%20Number%20of%20K%20Consecutive%20Bit%20Flips/README_EN.md", "title_cn": "K \u8fde\u7eed\u4f4d\u7684\u6700\u5c0f\u7ffb\u8f6c\u6b21\u6570", "title_en": "Minimum Number of K Consecutive Bit Flips", "question_title_slug": "minimum-number-of-k-consecutive-bit-flips", "content_en": "

    In an array nums containing only 0s and 1s, a k-bit flip consists of choosing a (contiguous) subarray of length k and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0.

    \n\n

    Return the minimum number of k-bit flips required so that there is no 0 in the array.  If it is not possible, return -1.

    \n\n

     

    \n\n

    Example 1:

    \n\n
    \nInput: nums = [0,1,0], k = 1\nOutput: 2\nExplanation: Flip nums[0], then flip nums[2].\n
    \n\n
    \n

    Example 2:

    \n\n
    \nInput: nums = [1,1,0], k = 2\nOutput: -1\nExplanation: No matter how we flip subarrays of size 2, we can't make the array become [1,1,1].\n
    \n\n
    \n

    Example 3:

    \n\n
    \nInput: nums = [0,0,0,1,0,1,1,0], k = 3\nOutput: 3\nExplanation:\nFlip nums[0],nums[1],nums[2]: nums becomes [1,1,1,1,0,1,1,0]\nFlip nums[4],nums[5],nums[6]: nums becomes [1,1,1,1,1,0,0,0]\nFlip nums[5],nums[6],nums[7]: nums becomes [1,1,1,1,1,1,1,1]\n
    \n\n

     

    \n
    \n
    \n\n

    Note:

    \n\n
      \n\t
    1. 1 <= nums.length <= 30000
    2. \n\t
    3. 1 <= k <= nums.length
    4. \n
    \n", "content_cn": "

    \u5728\u4ec5\u5305\u542b 0 \u548c 1 \u7684\u6570\u7ec4 A \u4e2d\uff0c\u4e00\u6b21 K \u4f4d\u7ffb\u8f6c\u5305\u62ec\u9009\u62e9\u4e00\u4e2a\u957f\u5ea6\u4e3a K \u7684\uff08\u8fde\u7eed\uff09\u5b50\u6570\u7ec4\uff0c\u540c\u65f6\u5c06\u5b50\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a 0 \u66f4\u6539\u4e3a 1\uff0c\u800c\u6bcf\u4e2a 1 \u66f4\u6539\u4e3a 0\u3002

    \n\n

    \u8fd4\u56de\u6240\u9700\u7684 K \u4f4d\u7ffb\u8f6c\u7684\u6700\u5c0f\u6b21\u6570\uff0c\u4ee5\u4fbf\u6570\u7ec4\u6ca1\u6709\u503c\u4e3a 0 \u7684\u5143\u7d20\u3002\u5982\u679c\u4e0d\u53ef\u80fd\uff0c\u8fd4\u56de -1\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aA = [0,1,0], K = 1\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5148\u7ffb\u8f6c A[0]\uff0c\u7136\u540e\u7ffb\u8f6c A[2]\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aA = [1,1,0], K = 2\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u65e0\u8bba\u6211\u4eec\u600e\u6837\u7ffb\u8f6c\u5927\u5c0f\u4e3a 2 \u7684\u5b50\u6570\u7ec4\uff0c\u6211\u4eec\u90fd\u4e0d\u80fd\u4f7f\u6570\u7ec4\u53d8\u4e3a [1,1,1]\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aA = [0,0,0,1,0,1,1,0], K = 3\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\n\u7ffb\u8f6c A[0],A[1],A[2]:\u00a0A\u53d8\u6210 [1,1,1,1,0,1,1,0]\n\u7ffb\u8f6c A[4],A[5],A[6]:\u00a0A\u53d8\u6210 [1,1,1,1,1,0,0,0]\n\u7ffb\u8f6c A[5],A[6],A[7]:\u00a0A\u53d8\u6210 [1,1,1,1,1,1,1,1]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= A.length <=\u00a030000
    2. \n\t
    3. 1 <= K <= A.length
    4. \n
    \n", "tags_en": ["Greedy", "Sliding Window"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minKBitFlips(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minKBitFlips(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minKBitFlips(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minKBitFlips(self, nums: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minKBitFlips(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinKBitFlips(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar minKBitFlips = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef min_k_bit_flips(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minKBitFlips(_ nums: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minKBitFlips(nums []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minKBitFlips(nums: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minKBitFlips(nums: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_k_bit_flips(nums: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer\n */\n function minKBitFlips($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minKBitFlips(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-k-bit-flips nums k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0995](https://leetcode-cn.com/problems/minimum-number-of-k-consecutive-bit-flips)", "[K \u8fde\u7eed\u4f4d\u7684\u6700\u5c0f\u7ffb\u8f6c\u6b21\u6570](/solution/0900-0999/0995.Minimum%20Number%20of%20K%20Consecutive%20Bit%20Flips/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[0995](https://leetcode.com/problems/minimum-number-of-k-consecutive-bit-flips)", "[Minimum Number of K Consecutive Bit Flips](/solution/0900-0999/0995.Minimum%20Number%20of%20K%20Consecutive%20Bit%20Flips/README_EN.md)", "`Greedy`,`Sliding Window`", "Hard", ""]}, {"question_id": "1036", "frontend_question_id": "0994", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/rotting-oranges", "url_en": "https://leetcode.com/problems/rotting-oranges", "relative_path_cn": "/solution/0900-0999/0994.Rotting%20Oranges/README.md", "relative_path_en": "/solution/0900-0999/0994.Rotting%20Oranges/README_EN.md", "title_cn": "\u8150\u70c2\u7684\u6a58\u5b50", "title_en": "Rotting Oranges", "question_title_slug": "rotting-oranges", "content_en": "

    You are given an m x n grid where each cell can have one of three values:

    \n\n
      \n\t
    • 0 representing an empty cell,
    • \n\t
    • 1 representing a fresh orange, or
    • \n\t
    • 2 representing a rotten orange.
    • \n
    \n\n

    Every minute, any fresh orange that is 4-directionally adjacent to a rotten orange becomes rotten.

    \n\n

    Return the minimum number of minutes that must elapse until no cell has a fresh orange. If this is impossible, return -1.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: grid = [[2,1,1],[1,1,0],[0,1,1]]\nOutput: 4\n
    \n\n

    Example 2:

    \n\n
    \nInput: grid = [[2,1,1],[0,1,1],[1,0,1]]\nOutput: -1\nExplanation: The orange in the bottom left corner (row 2, column 0) is never rotten, because rotting only happens 4-directionally.\n
    \n\n

    Example 3:

    \n\n
    \nInput: grid = [[0,2]]\nOutput: 0\nExplanation: Since there are already no fresh oranges at minute 0, the answer is just 0.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= m, n <= 10
    • \n\t
    • grid[i][j] is 0, 1, or 2.
    • \n
    \n", "content_cn": "

    \u5728\u7ed9\u5b9a\u7684\u7f51\u683c\u4e2d\uff0c\u6bcf\u4e2a\u5355\u5143\u683c\u53ef\u4ee5\u6709\u4ee5\u4e0b\u4e09\u4e2a\u503c\u4e4b\u4e00\uff1a

    \n\n
      \n\t
    • \u503c 0 \u4ee3\u8868\u7a7a\u5355\u5143\u683c\uff1b
    • \n\t
    • \u503c 1 \u4ee3\u8868\u65b0\u9c9c\u6a58\u5b50\uff1b
    • \n\t
    • \u503c 2 \u4ee3\u8868\u8150\u70c2\u7684\u6a58\u5b50\u3002
    • \n
    \n\n

    \u6bcf\u5206\u949f\uff0c\u4efb\u4f55\u4e0e\u8150\u70c2\u7684\u6a58\u5b50\uff08\u5728 4 \u4e2a\u6b63\u65b9\u5411\u4e0a\uff09\u76f8\u90bb\u7684\u65b0\u9c9c\u6a58\u5b50\u90fd\u4f1a\u8150\u70c2\u3002

    \n\n

    \u8fd4\u56de\u76f4\u5230\u5355\u5143\u683c\u4e2d\u6ca1\u6709\u65b0\u9c9c\u6a58\u5b50\u4e3a\u6b62\u6240\u5fc5\u987b\u7ecf\u8fc7\u7684\u6700\u5c0f\u5206\u949f\u6570\u3002\u5982\u679c\u4e0d\u53ef\u80fd\uff0c\u8fd4\u56de -1\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1a[[2,1,1],[1,1,0],[0,1,1]]\n\u8f93\u51fa\uff1a4\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a[[2,1,1],[0,1,1],[1,0,1]]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u5de6\u4e0b\u89d2\u7684\u6a58\u5b50\uff08\u7b2c 2 \u884c\uff0c \u7b2c 0 \u5217\uff09\u6c38\u8fdc\u4e0d\u4f1a\u8150\u70c2\uff0c\u56e0\u4e3a\u8150\u70c2\u53ea\u4f1a\u53d1\u751f\u5728 4 \u4e2a\u6b63\u5411\u4e0a\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1a[[0,2]]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u56e0\u4e3a 0 \u5206\u949f\u65f6\u5df2\u7ecf\u6ca1\u6709\u65b0\u9c9c\u6a58\u5b50\u4e86\uff0c\u6240\u4ee5\u7b54\u6848\u5c31\u662f 0 \u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= grid.length <= 10
    2. \n\t
    3. 1 <= grid[0].length <= 10
    4. \n\t
    5. grid[i][j] \u4ec5\u4e3a 0\u30011 \u6216 2
    6. \n
    \n", "tags_en": ["Breadth-first Search"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int orangesRotting(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int orangesRotting(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def orangesRotting(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def orangesRotting(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint orangesRotting(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int OrangesRotting(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar orangesRotting = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef oranges_rotting(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func orangesRotting(_ grid: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func orangesRotting(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def orangesRotting(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun orangesRotting(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn oranges_rotting(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function orangesRotting($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function orangesRotting(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (oranges-rotting grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0994](https://leetcode-cn.com/problems/rotting-oranges)", "[\u8150\u70c2\u7684\u6a58\u5b50](/solution/0900-0999/0994.Rotting%20Oranges/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0994](https://leetcode.com/problems/rotting-oranges)", "[Rotting Oranges](/solution/0900-0999/0994.Rotting%20Oranges/README_EN.md)", "`Breadth-first Search`", "Medium", ""]}, {"question_id": "1035", "frontend_question_id": "0993", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/cousins-in-binary-tree", "url_en": "https://leetcode.com/problems/cousins-in-binary-tree", "relative_path_cn": "/solution/0900-0999/0993.Cousins%20in%20Binary%20Tree/README.md", "relative_path_en": "/solution/0900-0999/0993.Cousins%20in%20Binary%20Tree/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u7684\u5802\u5144\u5f1f\u8282\u70b9", "title_en": "Cousins in Binary Tree", "question_title_slug": "cousins-in-binary-tree", "content_en": "

    In a binary tree, the root node is at depth 0, and children of each depth k node are at depth k+1.

    \n\n

    Two nodes of a binary tree are cousins if they have the same depth, but have different parents.

    \n\n

    We are given the root of a binary tree with unique values, and the values x and y of two different nodes in the tree.

    \n\n

    Return true if and only if the nodes corresponding to the values x and y are cousins.

    \n\n

     

    \n\n

    Example 1:
    \n\"\"

    \n\n
    \nInput: root = [1,2,3,4], x = 4, y = 3\nOutput: false\n
    \n\n
    \n

    Example 2:
    \n\"\"

    \n\n
    \nInput: root = [1,2,3,null,4,null,5], x = 5, y = 4\nOutput: true\n
    \n\n
    \n

    Example 3:

    \n\n

    \"\"

    \n\n
    \nInput: root = [1,2,3,null,4], x = 2, y = 3\nOutput: false\n
    \n
    \n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree will be between 2 and 100.
    • \n\t
    • Each node has a unique integer value from 1 to 100.
    • \n
    \n", "content_cn": "

    \u5728\u4e8c\u53c9\u6811\u4e2d\uff0c\u6839\u8282\u70b9\u4f4d\u4e8e\u6df1\u5ea6 0 \u5904\uff0c\u6bcf\u4e2a\u6df1\u5ea6\u4e3a k \u7684\u8282\u70b9\u7684\u5b50\u8282\u70b9\u4f4d\u4e8e\u6df1\u5ea6 k+1 \u5904\u3002

    \n\n

    \u5982\u679c\u4e8c\u53c9\u6811\u7684\u4e24\u4e2a\u8282\u70b9\u6df1\u5ea6\u76f8\u540c\uff0c\u4f46 \u7236\u8282\u70b9\u4e0d\u540c \uff0c\u5219\u5b83\u4eec\u662f\u4e00\u5bf9\u5802\u5144\u5f1f\u8282\u70b9\u3002

    \n\n

    \u6211\u4eec\u7ed9\u51fa\u4e86\u5177\u6709\u552f\u4e00\u503c\u7684\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9 root \uff0c\u4ee5\u53ca\u6811\u4e2d\u4e24\u4e2a\u4e0d\u540c\u8282\u70b9\u7684\u503c x \u548c y \u3002

    \n\n

    \u53ea\u6709\u4e0e\u503c x \u548c y \u5bf9\u5e94\u7684\u8282\u70b9\u662f\u5802\u5144\u5f1f\u8282\u70b9\u65f6\uff0c\u624d\u8fd4\u56de true \u3002\u5426\u5219\uff0c\u8fd4\u56de false\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a
    \n\"\"

    \n\n
    \n\u8f93\u5165\uff1aroot = [1,2,3,4], x = 4, y = 3\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 2\uff1a
    \n\"\"

    \n\n
    \n\u8f93\u5165\uff1aroot = [1,2,3,null,4,null,5], x = 5, y = 4\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aroot = [1,2,3,null,4], x = 2, y = 3\n\u8f93\u51fa\uff1afalse
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u4e8c\u53c9\u6811\u7684\u8282\u70b9\u6570\u4ecb\u4e8e\u00a02 \u5230\u00a0100\u00a0\u4e4b\u95f4\u3002
    • \n\t
    • \u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u90fd\u662f\u552f\u4e00\u7684\u3001\u8303\u56f4\u4e3a\u00a01 \u5230\u00a0100\u00a0\u7684\u6574\u6570\u3002
    • \n
    \n\n

    \u00a0

    \n", "tags_en": ["Tree", "Breadth-first Search"], "tags_cn": ["\u6811", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n bool isCousins(TreeNode* root, int x, int y) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public boolean isCousins(TreeNode root, int x, int y) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def isCousins(self, root, x, y):\n \"\"\"\n :type root: TreeNode\n :type x: int\n :type y: int\n :rtype: bool\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def isCousins(self, root: TreeNode, x: int, y: int) -> bool:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nbool isCousins(struct TreeNode* root, int x, int y){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public bool IsCousins(TreeNode root, int x, int y) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number} x\n * @param {number} y\n * @return {boolean}\n */\nvar isCousins = function(root, x, y) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @param {Integer} x\n# @param {Integer} y\n# @return {Boolean}\ndef is_cousins(root, x, y)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func isCousins(_ root: TreeNode?, _ x: Int, _ y: Int) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc isCousins(root *TreeNode, x int, y int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def isCousins(root: TreeNode, x: Int, y: Int): Boolean = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun isCousins(root: TreeNode?, x: Int, y: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn is_cousins(root: Option>>, x: i32, y: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param Integer $x\n * @param Integer $y\n * @return Boolean\n */\n function isCousins($root, $x, $y) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction isCousins(root: TreeNode | null, x: number, y: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (is-cousins root x y)\n (-> (or/c tree-node? #f) exact-integer? exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0993](https://leetcode-cn.com/problems/cousins-in-binary-tree)", "[\u4e8c\u53c9\u6811\u7684\u5802\u5144\u5f1f\u8282\u70b9](/solution/0900-0999/0993.Cousins%20in%20Binary%20Tree/README.md)", "`\u6811`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u7b80\u5355", ""], "md_table_row_en": ["[0993](https://leetcode.com/problems/cousins-in-binary-tree)", "[Cousins in Binary Tree](/solution/0900-0999/0993.Cousins%20in%20Binary%20Tree/README_EN.md)", "`Tree`,`Breadth-first Search`", "Easy", ""]}, {"question_id": "1034", "frontend_question_id": "0992", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/subarrays-with-k-different-integers", "url_en": "https://leetcode.com/problems/subarrays-with-k-different-integers", "relative_path_cn": "/solution/0900-0999/0992.Subarrays%20with%20K%20Different%20Integers/README.md", "relative_path_en": "/solution/0900-0999/0992.Subarrays%20with%20K%20Different%20Integers/README_EN.md", "title_cn": "K \u4e2a\u4e0d\u540c\u6574\u6570\u7684\u5b50\u6570\u7ec4", "title_en": "Subarrays with K Different Integers", "question_title_slug": "subarrays-with-k-different-integers", "content_en": "

    Given an array nums of positive integers, call a (contiguous, not necessarily distinct) subarray of nums good if the number of different integers in that subarray is exactly k.

    \n\n

    (For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.)

    \n\n

    Return the number of good subarrays of nums.

    \n\n

     

    \n\n

    Example 1:

    \n\n
    \nInput: nums = [1,2,1,2,3], k = 2\nOutput: 7\nExplanation: Subarrays formed with exactly 2 different integers: [1,2], [2,1], [1,2], [2,3], [1,2,1], [2,1,2], [1,2,1,2].\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,2,1,3,4], k = 3\nOutput: 3\nExplanation: Subarrays formed with exactly 3 different integers: [1,2,1,3], [2,1,3], [1,3,4].\n
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    1. 1 <= nums.length <= 20000
    2. \n\t
    3. 1 <= nums[i] <= nums.length
    4. \n\t
    5. 1 <= k <= nums.length
    6. \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6b63\u6574\u6570\u6570\u7ec4 A\uff0c\u5982\u679c A\u00a0\u7684\u67d0\u4e2a\u5b50\u6570\u7ec4\u4e2d\u4e0d\u540c\u6574\u6570\u7684\u4e2a\u6570\u6070\u597d\u4e3a K\uff0c\u5219\u79f0 A \u7684\u8fd9\u4e2a\u8fde\u7eed\u3001\u4e0d\u4e00\u5b9a\u4e0d\u540c\u7684\u5b50\u6570\u7ec4\u4e3a\u597d\u5b50\u6570\u7ec4\u3002

    \n\n

    \uff08\u4f8b\u5982\uff0c[1,2,3,1,2] \u4e2d\u6709\u00a03\u00a0\u4e2a\u4e0d\u540c\u7684\u6574\u6570\uff1a1\uff0c2\uff0c\u4ee5\u53ca\u00a03\u3002\uff09

    \n\n

    \u8fd4\u56de\u00a0A\u00a0\u4e2d\u597d\u5b50\u6570\u7ec4\u7684\u6570\u76ee\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aA = [1,2,1,2,3], K = 2\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\u6070\u597d\u7531 2 \u4e2a\u4e0d\u540c\u6574\u6570\u7ec4\u6210\u7684\u5b50\u6570\u7ec4\uff1a[1,2], [2,1], [1,2], [2,3], [1,2,1], [2,1,2], [1,2,1,2].\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aA = [1,2,1,3,4], K = 3\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6070\u597d\u7531 3 \u4e2a\u4e0d\u540c\u6574\u6570\u7ec4\u6210\u7684\u5b50\u6570\u7ec4\uff1a[1,2,1,3], [2,1,3], [1,3,4].\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= A.length <= 20000
    2. \n\t
    3. 1 <= A[i] <= A.length
    4. \n\t
    5. 1 <= K <= A.length
    6. \n
    \n", "tags_en": ["Hash Table", "Two Pointers", "Sliding Window"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u53cc\u6307\u9488"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int subarraysWithKDistinct(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int subarraysWithKDistinct(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def subarraysWithKDistinct(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def subarraysWithKDistinct(self, nums: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint subarraysWithKDistinct(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SubarraysWithKDistinct(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar subarraysWithKDistinct = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef subarrays_with_k_distinct(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func subarraysWithKDistinct(_ nums: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func subarraysWithKDistinct(nums []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def subarraysWithKDistinct(nums: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun subarraysWithKDistinct(nums: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn subarrays_with_k_distinct(nums: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer\n */\n function subarraysWithKDistinct($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function subarraysWithKDistinct(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (subarrays-with-k-distinct nums k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0992](https://leetcode-cn.com/problems/subarrays-with-k-different-integers)", "[K \u4e2a\u4e0d\u540c\u6574\u6570\u7684\u5b50\u6570\u7ec4](/solution/0900-0999/0992.Subarrays%20with%20K%20Different%20Integers/README.md)", "`\u54c8\u5e0c\u8868`,`\u53cc\u6307\u9488`", "\u56f0\u96be", ""], "md_table_row_en": ["[0992](https://leetcode.com/problems/subarrays-with-k-different-integers)", "[Subarrays with K Different Integers](/solution/0900-0999/0992.Subarrays%20with%20K%20Different%20Integers/README_EN.md)", "`Hash Table`,`Two Pointers`,`Sliding Window`", "Hard", ""]}, {"question_id": "1033", "frontend_question_id": "0991", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/broken-calculator", "url_en": "https://leetcode.com/problems/broken-calculator", "relative_path_cn": "/solution/0900-0999/0991.Broken%20Calculator/README.md", "relative_path_en": "/solution/0900-0999/0991.Broken%20Calculator/README_EN.md", "title_cn": "\u574f\u4e86\u7684\u8ba1\u7b97\u5668", "title_en": "Broken Calculator", "question_title_slug": "broken-calculator", "content_en": "

    On a broken calculator that has a number showing on its display, we can perform two operations:

    \n\n
      \n\t
    • Double: Multiply the number on the display by 2, or;
    • \n\t
    • Decrement: Subtract 1 from the number on the display.
    • \n
    \n\n

    Initially, the calculator is displaying the number x.

    \n\n

    Return the minimum number of operations needed to display the number y.

    \n\n

     

    \n\n

    Example 1:

    \n\n
    \nInput: x = 2, y = 3\nOutput: 2\nExplanation: Use double operation and then decrement operation {2 -> 4 -> 3}.\n
    \n\n

    Example 2:

    \n\n
    \nInput: x = 5, y = 8\nOutput: 2\nExplanation: Use decrement and then double {5 -> 4 -> 8}.\n
    \n\n

    Example 3:

    \n\n
    \nInput: x = 3, y = 10\nOutput: 3\nExplanation:  Use double, decrement and double {3 -> 6 -> 5 -> 10}.\n
    \n\n

    Example 4:

    \n\n
    \nInput: x = 1024, y = 1\nOutput: 1023\nExplanation: Use decrement operations 1023 times.\n
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    1. 1 <= x <= 109
    2. \n\t
    3. 1 <= y <= 109
    4. \n
    \n", "content_cn": "

    \u5728\u663e\u793a\u7740\u6570\u5b57\u7684\u574f\u8ba1\u7b97\u5668\u4e0a\uff0c\u6211\u4eec\u53ef\u4ee5\u6267\u884c\u4ee5\u4e0b\u4e24\u79cd\u64cd\u4f5c\uff1a

    \n\n
      \n\t
    • \u53cc\u500d\uff08Double\uff09\uff1a\u5c06\u663e\u793a\u5c4f\u4e0a\u7684\u6570\u5b57\u4e58 2\uff1b
    • \n\t
    • \u9012\u51cf\uff08Decrement\uff09\uff1a\u5c06\u663e\u793a\u5c4f\u4e0a\u7684\u6570\u5b57\u51cf 1 \u3002
    • \n
    \n\n

    \u6700\u521d\uff0c\u8ba1\u7b97\u5668\u663e\u793a\u6570\u5b57 X\u3002

    \n\n

    \u8fd4\u56de\u663e\u793a\u6570\u5b57 Y \u6240\u9700\u7684\u6700\u5c0f\u64cd\u4f5c\u6570\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aX = 2, Y = 3\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5148\u8fdb\u884c\u53cc\u500d\u8fd0\u7b97\uff0c\u7136\u540e\u518d\u8fdb\u884c\u9012\u51cf\u8fd0\u7b97 {2 -> 4 -> 3}.\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aX = 5, Y = 8\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5148\u9012\u51cf\uff0c\u518d\u53cc\u500d {5 -> 4 -> 8}.\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aX = 3, Y = 10\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u5148\u53cc\u500d\uff0c\u7136\u540e\u9012\u51cf\uff0c\u518d\u53cc\u500d {3 -> 6 -> 5 -> 10}.\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1aX = 1024, Y = 1\n\u8f93\u51fa\uff1a1023\n\u89e3\u91ca\uff1a\u6267\u884c\u9012\u51cf\u8fd0\u7b97 1023 \u6b21\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= X <= 10^9
    2. \n\t
    3. 1 <= Y <= 10^9
    4. \n
    \n", "tags_en": ["Greedy", "Math"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int brokenCalc(int x, int y) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int brokenCalc(int x, int y) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def brokenCalc(self, x, y):\n \"\"\"\n :type x: int\n :type y: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def brokenCalc(self, x: int, y: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint brokenCalc(int x, int y){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int BrokenCalc(int x, int y) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} x\n * @param {number} y\n * @return {number}\n */\nvar brokenCalc = function(x, y) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} x\n# @param {Integer} y\n# @return {Integer}\ndef broken_calc(x, y)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func brokenCalc(_ x: Int, _ y: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func brokenCalc(x int, y int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def brokenCalc(x: Int, y: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun brokenCalc(x: Int, y: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn broken_calc(x: i32, y: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $x\n * @param Integer $y\n * @return Integer\n */\n function brokenCalc($x, $y) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function brokenCalc(x: number, y: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (broken-calc x y)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0991](https://leetcode-cn.com/problems/broken-calculator)", "[\u574f\u4e86\u7684\u8ba1\u7b97\u5668](/solution/0900-0999/0991.Broken%20Calculator/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0991](https://leetcode.com/problems/broken-calculator)", "[Broken Calculator](/solution/0900-0999/0991.Broken%20Calculator/README_EN.md)", "`Greedy`,`Math`", "Medium", ""]}, {"question_id": "1032", "frontend_question_id": "0990", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/satisfiability-of-equality-equations", "url_en": "https://leetcode.com/problems/satisfiability-of-equality-equations", "relative_path_cn": "/solution/0900-0999/0990.Satisfiability%20of%20Equality%20Equations/README.md", "relative_path_en": "/solution/0900-0999/0990.Satisfiability%20of%20Equality%20Equations/README_EN.md", "title_cn": "\u7b49\u5f0f\u65b9\u7a0b\u7684\u53ef\u6ee1\u8db3\u6027", "title_en": "Satisfiability of Equality Equations", "question_title_slug": "satisfiability-of-equality-equations", "content_en": "

    Given an array equations of strings that represent relationships between variables, each string equations[i] has length 4 and takes one of two different forms: "a==b" or "a!=b".  Here, a and b are lowercase letters (not necessarily different) that represent one-letter variable names.

    \r\n\r\n

    Return true if and only if it is possible to assign integers to variable names so as to satisfy all the given equations.

    \r\n\r\n

     

    \r\n\r\n
      \r\n
    \r\n\r\n
    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: ["a==b","b!=a"]\r\nOutput: false\r\nExplanation: If we assign say, a = 1 and b = 1, then the first equation is satisfied, but not the second.  There is no way to assign the variables to satisfy both equations.\r\n
    \r\n\r\n
    \r\n

    Example 2:

    \r\n\r\n
    \r\nInput: ["b==a","a==b"]\r\nOutput: true\r\nExplanation: We could assign a = 1 and b = 1 to satisfy both equations.\r\n
    \r\n\r\n
    \r\n

    Example 3:

    \r\n\r\n
    \r\nInput: ["a==b","b==c","a==c"]\r\nOutput: true\r\n
    \r\n\r\n
    \r\n

    Example 4:

    \r\n\r\n
    \r\nInput: ["a==b","b!=c","c==a"]\r\nOutput: false\r\n
    \r\n\r\n
    \r\n

    Example 5:

    \r\n\r\n
    \r\nInput: ["c==c","b==d","x!=z"]\r\nOutput: true\r\n
    \r\n\r\n

     

    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    1. 1 <= equations.length <= 500
    2. \r\n\t
    3. equations[i].length == 4
    4. \r\n\t
    5. equations[i][0] and equations[i][3] are lowercase letters
    6. \r\n\t
    7. equations[i][1] is either '=' or '!'
    8. \r\n\t
    9. equations[i][2] is '='
    10. \r\n
    \r\n
    \r\n
    \r\n
    \r\n
    \r\n
    \r\n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u7531\u8868\u793a\u53d8\u91cf\u4e4b\u95f4\u5173\u7cfb\u7684\u5b57\u7b26\u4e32\u65b9\u7a0b\u7ec4\u6210\u7684\u6570\u7ec4\uff0c\u6bcf\u4e2a\u5b57\u7b26\u4e32\u65b9\u7a0b equations[i] \u7684\u957f\u5ea6\u4e3a 4\uff0c\u5e76\u91c7\u7528\u4e24\u79cd\u4e0d\u540c\u7684\u5f62\u5f0f\u4e4b\u4e00\uff1a"a==b" \u6216 "a!=b"\u3002\u5728\u8fd9\u91cc\uff0ca \u548c b \u662f\u5c0f\u5199\u5b57\u6bcd\uff08\u4e0d\u4e00\u5b9a\u4e0d\u540c\uff09\uff0c\u8868\u793a\u5355\u5b57\u6bcd\u53d8\u91cf\u540d\u3002

    \n\n

    \u53ea\u6709\u5f53\u53ef\u4ee5\u5c06\u6574\u6570\u5206\u914d\u7ed9\u53d8\u91cf\u540d\uff0c\u4ee5\u4fbf\u6ee1\u8db3\u6240\u6709\u7ed9\u5b9a\u7684\u65b9\u7a0b\u65f6\u624d\u8fd4\u56de true\uff0c\u5426\u5219\u8fd4\u56de false\u3002 

    \n\n

     

    \n\n
      \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a["a==b","b!=a"]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u5982\u679c\u6211\u4eec\u6307\u5b9a\uff0ca = 1 \u4e14 b = 1\uff0c\u90a3\u4e48\u53ef\u4ee5\u6ee1\u8db3\u7b2c\u4e00\u4e2a\u65b9\u7a0b\uff0c\u4f46\u65e0\u6cd5\u6ee1\u8db3\u7b2c\u4e8c\u4e2a\u65b9\u7a0b\u3002\u6ca1\u6709\u529e\u6cd5\u5206\u914d\u53d8\u91cf\u540c\u65f6\u6ee1\u8db3\u8fd9\u4e24\u4e2a\u65b9\u7a0b\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a["b==a","a==b"]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u6211\u4eec\u53ef\u4ee5\u6307\u5b9a a = 1 \u4e14 b = 1 \u4ee5\u6ee1\u8db3\u6ee1\u8db3\u8fd9\u4e24\u4e2a\u65b9\u7a0b\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1a["a==b","b==c","a==c"]\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1a["a==b","b!=c","c==a"]\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1a["c==c","b==d","x!=z"]\n\u8f93\u51fa\uff1atrue\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= equations.length <= 500
    2. \n\t
    3. equations[i].length == 4
    4. \n\t
    5. equations[i][0] \u548c equations[i][3] \u662f\u5c0f\u5199\u5b57\u6bcd
    6. \n\t
    7. equations[i][1] \u8981\u4e48\u662f '='\uff0c\u8981\u4e48\u662f '!'
    8. \n\t
    9. equations[i][2] \u662f '='
    10. \n
    \n", "tags_en": ["Union Find", "Graph"], "tags_cn": ["\u5e76\u67e5\u96c6", "\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool equationsPossible(vector& equations) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean equationsPossible(String[] equations) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def equationsPossible(self, equations):\n \"\"\"\n :type equations: List[str]\n :rtype: bool\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def equationsPossible(self, equations: List[str]) -> bool:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool equationsPossible(char ** equations, int equationsSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool EquationsPossible(string[] equations) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} equations\n * @return {boolean}\n */\nvar equationsPossible = function(equations) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} equations\n# @return {Boolean}\ndef equations_possible(equations)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func equationsPossible(_ equations: [String]) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func equationsPossible(equations []string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def equationsPossible(equations: Array[String]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun equationsPossible(equations: Array): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn equations_possible(equations: Vec) -> bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $equations\n * @return Boolean\n */\n function equationsPossible($equations) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function equationsPossible(equations: string[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (equations-possible equations)\n (-> (listof string?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0990](https://leetcode-cn.com/problems/satisfiability-of-equality-equations)", "[\u7b49\u5f0f\u65b9\u7a0b\u7684\u53ef\u6ee1\u8db3\u6027](/solution/0900-0999/0990.Satisfiability%20of%20Equality%20Equations/README.md)", "`\u5e76\u67e5\u96c6`,`\u56fe`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0990](https://leetcode.com/problems/satisfiability-of-equality-equations)", "[Satisfiability of Equality Equations](/solution/0900-0999/0990.Satisfiability%20of%20Equality%20Equations/README_EN.md)", "`Union Find`,`Graph`", "Medium", ""]}, {"question_id": "1031", "frontend_question_id": "0989", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/add-to-array-form-of-integer", "url_en": "https://leetcode.com/problems/add-to-array-form-of-integer", "relative_path_cn": "/solution/0900-0999/0989.Add%20to%20Array-Form%20of%20Integer/README.md", "relative_path_en": "/solution/0900-0999/0989.Add%20to%20Array-Form%20of%20Integer/README_EN.md", "title_cn": "\u6570\u7ec4\u5f62\u5f0f\u7684\u6574\u6570\u52a0\u6cd5", "title_en": "Add to Array-Form of Integer", "question_title_slug": "add-to-array-form-of-integer", "content_en": "

    The array-form of an integer num is an array representing its digits in left to right order.

    \n\n
      \n\t
    • For example, for num = 1321, the array form is [1,3,2,1].
    • \n
    \n\n

    Given num, the array-form of an integer, and an integer k, return the array-form of the integer num + k.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: num = [1,2,0,0], k = 34\nOutput: [1,2,3,4]\nExplanation: 1200 + 34 = 1234\n
    \n\n

    Example 2:

    \n\n
    \nInput: num = [2,7,4], k = 181\nOutput: [4,5,5]\nExplanation: 274 + 181 = 455\n
    \n\n

    Example 3:

    \n\n
    \nInput: num = [2,1,5], k = 806\nOutput: [1,0,2,1]\nExplanation: 215 + 806 = 1021\n
    \n\n

    Example 4:

    \n\n
    \nInput: num = [9,9,9,9,9,9,9,9,9,9], k = 1\nOutput: [1,0,0,0,0,0,0,0,0,0,0]\nExplanation: 9999999999 + 1 = 10000000000\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= num.length <= 104
    • \n\t
    • 0 <= num[i] <= 9
    • \n\t
    • num does not contain any leading zeros except for the zero itself.
    • \n\t
    • 1 <= k <= 104
    • \n
    \n", "content_cn": "

    \u5bf9\u4e8e\u975e\u8d1f\u6574\u6570 X \u800c\u8a00\uff0cX \u7684\u6570\u7ec4\u5f62\u5f0f\u662f\u6bcf\u4f4d\u6570\u5b57\u6309\u4ece\u5de6\u5230\u53f3\u7684\u987a\u5e8f\u5f62\u6210\u7684\u6570\u7ec4\u3002\u4f8b\u5982\uff0c\u5982\u679c X = 1231\uff0c\u90a3\u4e48\u5176\u6570\u7ec4\u5f62\u5f0f\u4e3a [1,2,3,1]\u3002

    \n\n

    \u7ed9\u5b9a\u975e\u8d1f\u6574\u6570 X \u7684\u6570\u7ec4\u5f62\u5f0f A\uff0c\u8fd4\u56de\u6574\u6570 X+K \u7684\u6570\u7ec4\u5f62\u5f0f\u3002

    \n\n

     

    \n\n
      \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aA = [1,2,0,0], K = 34\n\u8f93\u51fa\uff1a[1,2,3,4]\n\u89e3\u91ca\uff1a1200 + 34 = 1234\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aA = [2,7,4], K = 181\n\u8f93\u51fa\uff1a[4,5,5]\n\u89e3\u91ca\uff1a274 + 181 = 455\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aA = [2,1,5], K = 806\n\u8f93\u51fa\uff1a[1,0,2,1]\n\u89e3\u91ca\uff1a215 + 806 = 1021\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1aA = [9,9,9,9,9,9,9,9,9,9], K = 1\n\u8f93\u51fa\uff1a[1,0,0,0,0,0,0,0,0,0,0]\n\u89e3\u91ca\uff1a9999999999 + 1 = 10000000000\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= A.length <= 10000
    2. \n\t
    3. 0 <= A[i] <= 9
    4. \n\t
    5. 0 <= K <= 10000
    6. \n\t
    7. \u5982\u679c A.length > 1\uff0c\u90a3\u4e48 A[0] != 0
    8. \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector addToArrayForm(vector& num, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List addToArrayForm(int[] num, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def addToArrayForm(self, num, k):\n \"\"\"\n :type num: List[int]\n :type k: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def addToArrayForm(self, num: List[int], k: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* addToArrayForm(int* num, int numSize, int k, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList AddToArrayForm(int[] num, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} num\n * @param {number} k\n * @return {number[]}\n */\nvar addToArrayForm = function(num, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} num\n# @param {Integer} k\n# @return {Integer[]}\ndef add_to_array_form(num, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func addToArrayForm(_ num: [Int], _ k: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func addToArrayForm(num []int, k int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def addToArrayForm(num: Array[Int], k: Int): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun addToArrayForm(num: IntArray, k: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn add_to_array_form(num: Vec, k: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $num\n * @param Integer $k\n * @return Integer[]\n */\n function addToArrayForm($num, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function addToArrayForm(num: number[], k: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (add-to-array-form num k)\n (-> (listof exact-integer?) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0989](https://leetcode-cn.com/problems/add-to-array-form-of-integer)", "[\u6570\u7ec4\u5f62\u5f0f\u7684\u6574\u6570\u52a0\u6cd5](/solution/0900-0999/0989.Add%20to%20Array-Form%20of%20Integer/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0989](https://leetcode.com/problems/add-to-array-form-of-integer)", "[Add to Array-Form of Integer](/solution/0900-0999/0989.Add%20to%20Array-Form%20of%20Integer/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1030", "frontend_question_id": "0988", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/smallest-string-starting-from-leaf", "url_en": "https://leetcode.com/problems/smallest-string-starting-from-leaf", "relative_path_cn": "/solution/0900-0999/0988.Smallest%20String%20Starting%20From%20Leaf/README.md", "relative_path_en": "/solution/0900-0999/0988.Smallest%20String%20Starting%20From%20Leaf/README_EN.md", "title_cn": "\u4ece\u53f6\u7ed3\u70b9\u5f00\u59cb\u7684\u6700\u5c0f\u5b57\u7b26\u4e32", "title_en": "Smallest String Starting From Leaf", "question_title_slug": "smallest-string-starting-from-leaf", "content_en": "

    Given the root of a binary tree, each node has a value from 0 to 25 representing the letters 'a' to 'z': a value of 0 represents 'a', a value of 1 represents 'b', and so on.

    \r\n\r\n

    Find the lexicographically smallest string that starts at a leaf of this tree and ends at the root.

    \r\n\r\n

    (As a reminder, any shorter prefix of a string is lexicographically smaller: for example, "ab" is lexicographically smaller than "aba".  A leaf of a node is a node that has no children.)

    \r\n\r\n
    \r\n
    \r\n

     

    \r\n\r\n
      \r\n
    \r\n
    \r\n
    \r\n\r\n
    \r\n

    Example 1:

    \r\n\r\n

    \"\"

    \r\n\r\n
    \r\nInput: [0,1,2,3,4,3,4]\r\nOutput: "dba"\r\n
    \r\n\r\n
    \r\n

    Example 2:

    \r\n\r\n

    \"\"

    \r\n\r\n
    \r\nInput: [25,1,3,1,3,0,2]\r\nOutput: "adz"\r\n
    \r\n\r\n
    \r\n

    Example 3:

    \r\n\r\n

    \"\"

    \r\n\r\n
    \r\nInput: [2,2,1,null,1,0,null,0]\r\nOutput: "abc"\r\n
    \r\n\r\n

     

    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    1. The number of nodes in the given tree will be between 1 and 8500.
    2. \r\n\t
    3. Each node in the tree will have a value between 0 and 25.
    4. \r\n
    \r\n
    \r\n
    \r\n
    ", "content_cn": "

    \u7ed9\u5b9a\u4e00\u9897\u6839\u7ed3\u70b9\u4e3a root \u7684\u4e8c\u53c9\u6811\uff0c\u6811\u4e2d\u7684\u6bcf\u4e00\u4e2a\u7ed3\u70b9\u90fd\u6709\u4e00\u4e2a\u4ece 0 \u5230 25 \u7684\u503c\uff0c\u5206\u522b\u4ee3\u8868\u5b57\u6bcd 'a' \u5230 'z'\uff1a\u503c 0 \u4ee3\u8868 'a'\uff0c\u503c 1 \u4ee3\u8868 'b'\uff0c\u4f9d\u6b64\u7c7b\u63a8\u3002

    \n\n

    \u627e\u51fa\u6309\u5b57\u5178\u5e8f\u6700\u5c0f\u7684\u5b57\u7b26\u4e32\uff0c\u8be5\u5b57\u7b26\u4e32\u4ece\u8fd9\u68f5\u6811\u7684\u4e00\u4e2a\u53f6\u7ed3\u70b9\u5f00\u59cb\uff0c\u5230\u6839\u7ed3\u70b9\u7ed3\u675f\u3002

    \n\n

    \uff08\u5c0f\u8d34\u58eb\uff1a\u5b57\u7b26\u4e32\u4e2d\u4efb\u4f55\u8f83\u77ed\u7684\u524d\u7f00\u5728\u5b57\u5178\u5e8f\u4e0a\u90fd\u662f\u8f83\u5c0f\u7684\uff1a\u4f8b\u5982\uff0c\u5728\u5b57\u5178\u5e8f\u4e0a "ab" \u6bd4 "aba" \u8981\u5c0f\u3002\u53f6\u7ed3\u70b9\u662f\u6307\u6ca1\u6709\u5b50\u7ed3\u70b9\u7684\u7ed3\u70b9\u3002\uff09

    \n\n

     

    \n\n
      \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1a[0,1,2,3,4,3,4]\n\u8f93\u51fa\uff1a"dba"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1a[25,1,3,1,3,0,2]\n\u8f93\u51fa\uff1a"adz"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1a[2,2,1,null,1,0,null,0]\n\u8f93\u51fa\uff1a"abc"\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. \u7ed9\u5b9a\u6811\u7684\u7ed3\u70b9\u6570\u4ecb\u4e8e 1 \u548c 8500 \u4e4b\u95f4\u3002
    2. \n\t
    3. \u6811\u4e2d\u7684\u6bcf\u4e2a\u7ed3\u70b9\u90fd\u6709\u4e00\u4e2a\u4ecb\u4e8e 0 \u548c 25 \u4e4b\u95f4\u7684\u503c\u3002
    4. \n
    \n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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 */\nclass Solution {\npublic:\n string smallestFromLeaf(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode(int x) { val = x; }\n * }\n */\nclass Solution {\n public String smallestFromLeaf(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution(object):\n def smallestFromLeaf(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: str\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution:\n def smallestFromLeaf(self, root: TreeNode) -> str:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nchar * smallestFromLeaf(struct TreeNode* root){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int x) { val = x; }\n * }\n */\npublic class Solution {\n public string SmallestFromLeaf(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val) {\n * this.val = val;\n * this.left = this.right = null;\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {string}\n */\nvar smallestFromLeaf = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val)\n# @val = val\n# @left, @right = nil, nil\n# end\n# end\n\n# @param {TreeNode} root\n# @return {String}\ndef smallest_from_leaf(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.left = nil\n * self.right = nil\n * }\n * }\n */\nclass Solution {\n func smallestFromLeaf(_ root: TreeNode?) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc smallestFromLeaf(root *TreeNode) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(var _value: Int) {\n * var value: Int = _value\n * var left: TreeNode = null\n * var right: TreeNode = null\n * }\n */\nobject Solution {\n def smallestFromLeaf(root: TreeNode): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun smallestFromLeaf(root: TreeNode?): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n// \n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn smallest_from_leaf(root: Option>>) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($value) { $this->val = $value; }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return String\n */\n function smallestFromLeaf($root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction smallestFromLeaf(root: TreeNode | null): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (smallest-from-leaf root)\n (-> (or/c tree-node? #f) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0988](https://leetcode-cn.com/problems/smallest-string-starting-from-leaf)", "[\u4ece\u53f6\u7ed3\u70b9\u5f00\u59cb\u7684\u6700\u5c0f\u5b57\u7b26\u4e32](/solution/0900-0999/0988.Smallest%20String%20Starting%20From%20Leaf/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0988](https://leetcode.com/problems/smallest-string-starting-from-leaf)", "[Smallest String Starting From Leaf](/solution/0900-0999/0988.Smallest%20String%20Starting%20From%20Leaf/README_EN.md)", "`Tree`,`Depth-first Search`", "Medium", ""]}, {"question_id": "1029", "frontend_question_id": "0987", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/vertical-order-traversal-of-a-binary-tree", "url_en": "https://leetcode.com/problems/vertical-order-traversal-of-a-binary-tree", "relative_path_cn": "/solution/0900-0999/0987.Vertical%20Order%20Traversal%20of%20a%20Binary%20Tree/README.md", "relative_path_en": "/solution/0900-0999/0987.Vertical%20Order%20Traversal%20of%20a%20Binary%20Tree/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u7684\u5782\u5e8f\u904d\u5386", "title_en": "Vertical Order Traversal of a Binary Tree", "question_title_slug": "vertical-order-traversal-of-a-binary-tree", "content_en": "

    Given the root of a binary tree, calculate the vertical order traversal of the binary tree.

    \n\n

    For each node at position (row, col), its left and right children will be at positions (row + 1, col - 1) and (row + 1, col + 1) respectively. The root of the tree is at (0, 0).

    \n\n

    The vertical order traversal of a binary tree is a list of top-to-bottom orderings for each column index starting from the leftmost column and ending on the rightmost column. There may be multiple nodes in the same row and same column. In such a case, sort these nodes by their values.

    \n\n

    Return the vertical order traversal of the binary tree.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [3,9,20,null,null,15,7]\nOutput: [[9],[3,15],[20],[7]]\nExplanation:\nColumn -1: Only node 9 is in this column.\nColumn 0: Nodes 3 and 15 are in this column in that order from top to bottom.\nColumn 1: Only node 20 is in this column.\nColumn 2: Only node 7 is in this column.
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [1,2,3,4,5,6,7]\nOutput: [[4],[2],[1,5,6],[3],[7]]\nExplanation:\nColumn -2: Only node 4 is in this column.\nColumn -1: Only node 2 is in this column.\nColumn 0: Nodes 1, 5, and 6 are in this column.\n          1 is at the top, so it comes first.\n          5 and 6 are at the same position (2, 0), so we order them by their value, 5 before 6.\nColumn 1: Only node 3 is in this column.\nColumn 2: Only node 7 is in this column.\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: root = [1,2,3,4,6,5,7]\nOutput: [[4],[2],[1,5,6],[3],[7]]\nExplanation:\nThis case is the exact same as example 2, but with nodes 5 and 6 swapped.\nNote that the solution remains the same since 5 and 6 are in the same location and should be ordered by their values.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 1000].
    • \n\t
    • 0 <= Node.val <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e8c\u53c9\u6811\u7684\u6839\u7ed3\u70b9 root \uff0c\u8bf7\u4f60\u8bbe\u8ba1\u7b97\u6cd5\u8ba1\u7b97\u4e8c\u53c9\u6811\u7684 \u5782\u5e8f\u904d\u5386 \u5e8f\u5217\u3002

    \n\n

    \u5bf9\u4f4d\u4e8e\u00a0(row, col)\u00a0\u7684\u6bcf\u4e2a\u7ed3\u70b9\u800c\u8a00\uff0c\u5176\u5de6\u53f3\u5b50\u7ed3\u70b9\u5206\u522b\u4f4d\u4e8e\u00a0(row + 1, col - 1)\u00a0\u548c\u00a0(row + 1, col + 1) \u3002\u6811\u7684\u6839\u7ed3\u70b9\u4f4d\u4e8e (0, 0) \u3002

    \n\n

    \u4e8c\u53c9\u6811\u7684 \u5782\u5e8f\u904d\u5386 \u4ece\u6700\u5de6\u8fb9\u7684\u5217\u5f00\u59cb\u76f4\u5230\u6700\u53f3\u8fb9\u7684\u5217\u7ed3\u675f\uff0c\u6309\u5217\u7d22\u5f15\u6bcf\u4e00\u5217\u4e0a\u7684\u6240\u6709\u7ed3\u70b9\uff0c\u5f62\u6210\u4e00\u4e2a\u6309\u51fa\u73b0\u4f4d\u7f6e\u4ece\u4e0a\u5230\u4e0b\u6392\u5e8f\u7684\u6709\u5e8f\u5217\u8868\u3002\u5982\u679c\u540c\u884c\u540c\u5217\u4e0a\u6709\u591a\u4e2a\u7ed3\u70b9\uff0c\u5219\u6309\u7ed3\u70b9\u7684\u503c\u4ece\u5c0f\u5230\u5927\u8fdb\u884c\u6392\u5e8f\u3002

    \n\n

    \u8fd4\u56de\u4e8c\u53c9\u6811\u7684 \u5782\u5e8f\u904d\u5386 \u5e8f\u5217\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [3,9,20,null,null,15,7]\n\u8f93\u51fa\uff1a[[9],[3,15],[20],[7]]\n\u89e3\u91ca\uff1a\n\u5217 -1 \uff1a\u53ea\u6709\u7ed3\u70b9 9 \u5728\u6b64\u5217\u4e2d\u3002\n\u5217  0 \uff1a\u53ea\u6709\u7ed3\u70b9 3 \u548c 15 \u5728\u6b64\u5217\u4e2d\uff0c\u6309\u4ece\u4e0a\u5230\u4e0b\u987a\u5e8f\u3002\n\u5217  1 \uff1a\u53ea\u6709\u7ed3\u70b9 20 \u5728\u6b64\u5217\u4e2d\u3002\n\u5217  2 \uff1a\u53ea\u6709\u7ed3\u70b9 7 \u5728\u6b64\u5217\u4e2d\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [1,2,3,4,5,6,7]\n\u8f93\u51fa\uff1a[[4],[2],[1,5,6],[3],[7]]\n\u89e3\u91ca\uff1a\n\u5217 -2 \uff1a\u53ea\u6709\u7ed3\u70b9 4 \u5728\u6b64\u5217\u4e2d\u3002\n\u5217 -1 \uff1a\u53ea\u6709\u7ed3\u70b9 2 \u5728\u6b64\u5217\u4e2d\u3002\n\u5217  0 \uff1a\u7ed3\u70b9 1 \u30015 \u548c 6 \u90fd\u5728\u6b64\u5217\u4e2d\u3002\n          1 \u5728\u4e0a\u9762\uff0c\u6240\u4ee5\u5b83\u51fa\u73b0\u5728\u524d\u9762\u3002\n          5 \u548c 6 \u4f4d\u7f6e\u90fd\u662f (2, 0) \uff0c\u6240\u4ee5\u6309\u503c\u4ece\u5c0f\u5230\u5927\u6392\u5e8f\uff0c5 \u5728 6 \u7684\u524d\u9762\u3002\n\u5217  1 \uff1a\u53ea\u6709\u7ed3\u70b9 3 \u5728\u6b64\u5217\u4e2d\u3002\n\u5217  2 \uff1a\u53ea\u6709\u7ed3\u70b9 7 \u5728\u6b64\u5217\u4e2d\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [1,2,3,4,6,5,7]\n\u8f93\u51fa\uff1a[[4],[2],[1,5,6],[3],[7]]\n\u89e3\u91ca\uff1a\n\u8fd9\u4e2a\u793a\u4f8b\u5b9e\u9645\u4e0a\u4e0e\u793a\u4f8b 2 \u5b8c\u5168\u76f8\u540c\uff0c\u53ea\u662f\u7ed3\u70b9 5 \u548c 6 \u5728\u6811\u4e2d\u7684\u4f4d\u7f6e\u53d1\u751f\u4e86\u4ea4\u6362\u3002\n\u56e0\u4e3a 5 \u548c 6 \u7684\u4f4d\u7f6e\u4ecd\u7136\u76f8\u540c\uff0c\u6240\u4ee5\u7b54\u6848\u4fdd\u6301\u4e0d\u53d8\uff0c\u4ecd\u7136\u6309\u503c\u4ece\u5c0f\u5230\u5927\u6392\u5e8f\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u7ed3\u70b9\u6570\u76ee\u603b\u6570\u5728\u8303\u56f4 [1, 1000] \u5185
    • \n\t
    • 0 <= Node.val <= 1000
    • \n
    \n", "tags_en": ["Tree", "Depth-first Search", "Breadth-first Search", "Hash Table"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u54c8\u5e0c\u8868"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector> verticalTraversal(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public List> verticalTraversal(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def verticalTraversal(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def verticalTraversal(self, root: TreeNode) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** verticalTraversal(struct TreeNode* root, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public IList> VerticalTraversal(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number[][]}\n */\nvar verticalTraversal = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer[][]}\ndef vertical_traversal(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func verticalTraversal(_ root: TreeNode?) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc verticalTraversal(root *TreeNode) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def verticalTraversal(root: TreeNode): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun verticalTraversal(root: TreeNode?): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn vertical_traversal(root: Option>>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer[][]\n */\n function verticalTraversal($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction verticalTraversal(root: TreeNode | null): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (vertical-traversal root)\n (-> (or/c tree-node? #f) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0987](https://leetcode-cn.com/problems/vertical-order-traversal-of-a-binary-tree)", "[\u4e8c\u53c9\u6811\u7684\u5782\u5e8f\u904d\u5386](/solution/0900-0999/0987.Vertical%20Order%20Traversal%20of%20a%20Binary%20Tree/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u54c8\u5e0c\u8868`", "\u56f0\u96be", ""], "md_table_row_en": ["[0987](https://leetcode.com/problems/vertical-order-traversal-of-a-binary-tree)", "[Vertical Order Traversal of a Binary Tree](/solution/0900-0999/0987.Vertical%20Order%20Traversal%20of%20a%20Binary%20Tree/README_EN.md)", "`Tree`,`Depth-first Search`,`Breadth-first Search`,`Hash Table`", "Hard", ""]}, {"question_id": "1028", "frontend_question_id": "0986", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/interval-list-intersections", "url_en": "https://leetcode.com/problems/interval-list-intersections", "relative_path_cn": "/solution/0900-0999/0986.Interval%20List%20Intersections/README.md", "relative_path_en": "/solution/0900-0999/0986.Interval%20List%20Intersections/README_EN.md", "title_cn": "\u533a\u95f4\u5217\u8868\u7684\u4ea4\u96c6", "title_en": "Interval List Intersections", "question_title_slug": "interval-list-intersections", "content_en": "

    You are given two lists of closed intervals, firstList and secondList, where firstList[i] = [starti, endi] and secondList[j] = [startj, endj]. Each list of intervals is pairwise disjoint and in sorted order.

    \n\n

    Return the intersection of these two interval lists.

    \n\n

    A closed interval [a, b] (with a < b) denotes the set of real numbers x with a <= x <= b.

    \n\n

    The intersection of two closed intervals is a set of real numbers that are either empty or represented as a closed interval. For example, the intersection of [1, 3] and [2, 4] is [2, 3].

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: firstList = [[0,2],[5,10],[13,23],[24,25]], secondList = [[1,5],[8,12],[15,24],[25,26]]\nOutput: [[1,2],[5,5],[8,10],[15,23],[24,24],[25,25]]\n
    \n\n

    Example 2:

    \n\n
    \nInput: firstList = [[1,3],[5,9]], secondList = []\nOutput: []\n
    \n\n

    Example 3:

    \n\n
    \nInput: firstList = [], secondList = [[4,8],[10,12]]\nOutput: []\n
    \n\n

    Example 4:

    \n\n
    \nInput: firstList = [[1,7]], secondList = [[3,10]]\nOutput: [[3,7]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= firstList.length, secondList.length <= 1000
    • \n\t
    • firstList.length + secondList.length >= 1
    • \n\t
    • 0 <= starti < endi <= 109
    • \n\t
    • endi < starti+1
    • \n\t
    • 0 <= startj < endj <= 109
    • \n\t
    • endj < startj+1
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u7531\u4e00\u4e9b \u95ed\u533a\u95f4 \u7ec4\u6210\u7684\u5217\u8868\uff0cfirstList \u548c secondList \uff0c\u5176\u4e2d firstList[i] = [starti, endi] \u800c\u00a0secondList[j] = [startj, endj] \u3002\u6bcf\u4e2a\u533a\u95f4\u5217\u8868\u90fd\u662f\u6210\u5bf9 \u4e0d\u76f8\u4ea4 \u7684\uff0c\u5e76\u4e14 \u5df2\u7ecf\u6392\u5e8f \u3002

    \n\n

    \u8fd4\u56de\u8fd9 \u4e24\u4e2a\u533a\u95f4\u5217\u8868\u7684\u4ea4\u96c6 \u3002

    \n\n

    \u5f62\u5f0f\u4e0a\uff0c\u95ed\u533a\u95f4\u00a0[a, b]\uff08\u5176\u4e2d\u00a0a <= b\uff09\u8868\u793a\u5b9e\u6570\u00a0x\u00a0\u7684\u96c6\u5408\uff0c\u800c\u00a0a <= x <= b \u3002

    \n\n

    \u4e24\u4e2a\u95ed\u533a\u95f4\u7684 \u4ea4\u96c6 \u662f\u4e00\u7ec4\u5b9e\u6570\uff0c\u8981\u4e48\u4e3a\u7a7a\u96c6\uff0c\u8981\u4e48\u4e3a\u95ed\u533a\u95f4\u3002\u4f8b\u5982\uff0c[1, 3] \u548c [2, 4] \u7684\u4ea4\u96c6\u4e3a [2, 3] \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1afirstList = [[0,2],[5,10],[13,23],[24,25]], secondList = [[1,5],[8,12],[15,24],[25,26]]\n\u8f93\u51fa\uff1a[[1,2],[5,5],[8,10],[15,23],[24,24],[25,25]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1afirstList = [[1,3],[5,9]], secondList = []\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1afirstList = [], secondList = [[4,8],[10,12]]\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1afirstList = [[1,7]], secondList = [[3,10]]\n\u8f93\u51fa\uff1a[[3,7]]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= firstList.length, secondList.length <= 1000
    • \n\t
    • firstList.length + secondList.length >= 1
    • \n\t
    • 0 <= starti < endi <= 109
    • \n\t
    • endi < starti+1
    • \n\t
    • 0 <= startj < endj <= 109
    • \n\t
    • endj < startj+1
    • \n
    \n", "tags_en": ["Two Pointers"], "tags_cn": ["\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> intervalIntersection(vector>& firstList, vector>& secondList) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[][] intervalIntersection(int[][] firstList, int[][] secondList) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def intervalIntersection(self, firstList, secondList):\n \"\"\"\n :type firstList: List[List[int]]\n :type secondList: List[List[int]]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def intervalIntersection(self, firstList: List[List[int]], secondList: List[List[int]]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** intervalIntersection(int** firstList, int firstListSize, int* firstListColSize, int** secondList, int secondListSize, int* secondListColSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[][] IntervalIntersection(int[][] firstList, int[][] secondList) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} firstList\n * @param {number[][]} secondList\n * @return {number[][]}\n */\nvar intervalIntersection = function(firstList, secondList) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} first_list\n# @param {Integer[][]} second_list\n# @return {Integer[][]}\ndef interval_intersection(first_list, second_list)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func intervalIntersection(_ firstList: [[Int]], _ secondList: [[Int]]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func intervalIntersection(firstList [][]int, secondList [][]int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def intervalIntersection(firstList: Array[Array[Int]], secondList: Array[Array[Int]]): Array[Array[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun intervalIntersection(firstList: Array, secondList: Array): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn interval_intersection(first_list: Vec>, second_list: Vec>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $firstList\n * @param Integer[][] $secondList\n * @return Integer[][]\n */\n function intervalIntersection($firstList, $secondList) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function intervalIntersection(firstList: number[][], secondList: number[][]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (interval-intersection firstList secondList)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0986](https://leetcode-cn.com/problems/interval-list-intersections)", "[\u533a\u95f4\u5217\u8868\u7684\u4ea4\u96c6](/solution/0900-0999/0986.Interval%20List%20Intersections/README.md)", "`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0986](https://leetcode.com/problems/interval-list-intersections)", "[Interval List Intersections](/solution/0900-0999/0986.Interval%20List%20Intersections/README_EN.md)", "`Two Pointers`", "Medium", ""]}, {"question_id": "1027", "frontend_question_id": "0985", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sum-of-even-numbers-after-queries", "url_en": "https://leetcode.com/problems/sum-of-even-numbers-after-queries", "relative_path_cn": "/solution/0900-0999/0985.Sum%20of%20Even%20Numbers%20After%20Queries/README.md", "relative_path_en": "/solution/0900-0999/0985.Sum%20of%20Even%20Numbers%20After%20Queries/README_EN.md", "title_cn": "\u67e5\u8be2\u540e\u7684\u5076\u6570\u548c", "title_en": "Sum of Even Numbers After Queries", "question_title_slug": "sum-of-even-numbers-after-queries", "content_en": "

    We have an array nums of integers, and an array queries of queries.

    \n\n

    For the i-th query val = queries[i][0], index = queries[i][1], we add val to nums[index].  Then, the answer to the i-th query is the sum of the even values of A.

    \n\n

    (Here, the given index = queries[i][1] is a 0-based index, and each query permanently modifies the array nums.)

    \n\n

    Return the answer to all queries.  Your answer array should have answer[i] as the answer to the i-th query.

    \n\n

     

    \n\n

    Example 1:

    \n\n
    \nInput: nums = [1,2,3,4], queries = [[1,0],[-3,1],[-4,0],[2,3]]\nOutput: [8,6,2,4]\nExplanation: \nAt the beginning, the array is [1,2,3,4].\nAfter adding 1 to nums[0], the array is [2,2,3,4], and the sum of even values is 2 + 2 + 4 = 8.\nAfter adding -3 to nums[1], the array is [2,-1,3,4], and the sum of even values is 2 + 4 = 6.\nAfter adding -4 to nums[0], the array is [-2,-1,3,4], and the sum of even values is -2 + 4 = 2.\nAfter adding 2 to nums[3], the array is [-2,-1,3,6], and the sum of even values is -2 + 6 = 4.\n
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    1. 1 <= nums.length <= 10000
    2. \n\t
    3. -10000 <= nums[i] <= 10000
    4. \n\t
    5. 1 <= queries.length <= 10000
    6. \n\t
    7. -10000 <= queries[i][0] <= 10000
    8. \n\t
    9. 0 <= queries[i][1] < nums.length
    10. \n
    \n", "content_cn": "

    \u7ed9\u51fa\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 A \u548c\u4e00\u4e2a\u67e5\u8be2\u6570\u7ec4 queries\u3002

    \n\n

    \u5bf9\u4e8e\u7b2c i \u6b21\u67e5\u8be2\uff0c\u6709 val = queries[i][0], index = queries[i][1]\uff0c\u6211\u4eec\u4f1a\u628a val \u52a0\u5230 A[index] \u4e0a\u3002\u7136\u540e\uff0c\u7b2c i \u6b21\u67e5\u8be2\u7684\u7b54\u6848\u662f A \u4e2d\u5076\u6570\u503c\u7684\u548c\u3002

    \n\n

    \uff08\u6b64\u5904\u7ed9\u5b9a\u7684 index = queries[i][1] \u662f\u4ece 0 \u5f00\u59cb\u7684\u7d22\u5f15\uff0c\u6bcf\u6b21\u67e5\u8be2\u90fd\u4f1a\u6c38\u4e45\u4fee\u6539\u6570\u7ec4 A\u3002\uff09

    \n\n

    \u8fd4\u56de\u6240\u6709\u67e5\u8be2\u7684\u7b54\u6848\u3002\u4f60\u7684\u7b54\u6848\u5e94\u5f53\u4ee5\u6570\u7ec4 answer \u7ed9\u51fa\uff0canswer[i] \u4e3a\u7b2c i \u6b21\u67e5\u8be2\u7684\u7b54\u6848\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1aA = [1,2,3,4], queries = [[1,0],[-3,1],[-4,0],[2,3]]\n\u8f93\u51fa\uff1a[8,6,2,4]\n\u89e3\u91ca\uff1a\n\u5f00\u59cb\u65f6\uff0c\u6570\u7ec4\u4e3a [1,2,3,4]\u3002\n\u5c06 1 \u52a0\u5230 A[0] \u4e0a\u4e4b\u540e\uff0c\u6570\u7ec4\u4e3a [2,2,3,4]\uff0c\u5076\u6570\u503c\u4e4b\u548c\u4e3a 2 + 2 + 4 = 8\u3002\n\u5c06 -3 \u52a0\u5230 A[1] \u4e0a\u4e4b\u540e\uff0c\u6570\u7ec4\u4e3a [2,-1,3,4]\uff0c\u5076\u6570\u503c\u4e4b\u548c\u4e3a 2 + 4 = 6\u3002\n\u5c06 -4 \u52a0\u5230 A[0] \u4e0a\u4e4b\u540e\uff0c\u6570\u7ec4\u4e3a [-2,-1,3,4]\uff0c\u5076\u6570\u503c\u4e4b\u548c\u4e3a -2 + 4 = 2\u3002\n\u5c06 2 \u52a0\u5230 A[3] \u4e0a\u4e4b\u540e\uff0c\u6570\u7ec4\u4e3a [-2,-1,3,6]\uff0c\u5076\u6570\u503c\u4e4b\u548c\u4e3a -2 + 6 = 4\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= A.length <= 10000
    2. \n\t
    3. -10000 <= A[i] <= 10000
    4. \n\t
    5. 1 <= queries.length <= 10000
    6. \n\t
    7. -10000 <= queries[i][0] <= 10000
    8. \n\t
    9. 0 <= queries[i][1] < A.length
    10. \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector sumEvenAfterQueries(vector& nums, vector>& queries) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] sumEvenAfterQueries(int[] nums, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def sumEvenAfterQueries(self, nums, queries):\n \"\"\"\n :type nums: List[int]\n :type queries: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def sumEvenAfterQueries(self, nums: List[int], queries: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* sumEvenAfterQueries(int* nums, int numsSize, int** queries, int queriesSize, int* queriesColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] SumEvenAfterQueries(int[] nums, int[][] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number[][]} queries\n * @return {number[]}\n */\nvar sumEvenAfterQueries = function(nums, queries) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer[][]} queries\n# @return {Integer[]}\ndef sum_even_after_queries(nums, queries)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func sumEvenAfterQueries(_ nums: [Int], _ queries: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func sumEvenAfterQueries(nums []int, queries [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def sumEvenAfterQueries(nums: Array[Int], queries: Array[Array[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun sumEvenAfterQueries(nums: IntArray, queries: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sum_even_after_queries(nums: Vec, queries: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer[][] $queries\n * @return Integer[]\n */\n function sumEvenAfterQueries($nums, $queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function sumEvenAfterQueries(nums: number[], queries: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (sum-even-after-queries nums queries)\n (-> (listof exact-integer?) (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0985](https://leetcode-cn.com/problems/sum-of-even-numbers-after-queries)", "[\u67e5\u8be2\u540e\u7684\u5076\u6570\u548c](/solution/0900-0999/0985.Sum%20of%20Even%20Numbers%20After%20Queries/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0985](https://leetcode.com/problems/sum-of-even-numbers-after-queries)", "[Sum of Even Numbers After Queries](/solution/0900-0999/0985.Sum%20of%20Even%20Numbers%20After%20Queries/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1026", "frontend_question_id": "0984", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/string-without-aaa-or-bbb", "url_en": "https://leetcode.com/problems/string-without-aaa-or-bbb", "relative_path_cn": "/solution/0900-0999/0984.String%20Without%20AAA%20or%20BBB/README.md", "relative_path_en": "/solution/0900-0999/0984.String%20Without%20AAA%20or%20BBB/README_EN.md", "title_cn": "\u4e0d\u542b AAA \u6216 BBB \u7684\u5b57\u7b26\u4e32", "title_en": "String Without AAA or BBB", "question_title_slug": "string-without-aaa-or-bbb", "content_en": "

    Given two integers a and b, return any string s such that:

    \n\n
      \n\t
    • s has length a + b and contains exactly a 'a' letters, and exactly b 'b' letters,
    • \n\t
    • The substring 'aaa' does not occur in s, and
    • \n\t
    • The substring 'bbb' does not occur in s.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: a = 1, b = 2\nOutput: "abb"\nExplanation: "abb", "bab" and "bba" are all correct answers.\n
    \n\n

    Example 2:

    \n\n
    \nInput: a = 4, b = 1\nOutput: "aabaa"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= a, b <= 100
    • \n\t
    • It is guaranteed such an s exists for the given a and b.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u6574\u6570 A \u548c B\uff0c\u8fd4\u56de\u4efb\u610f\u5b57\u7b26\u4e32 S\uff0c\u8981\u6c42\u6ee1\u8db3\uff1a

    \n\n
      \n\t
    • S \u7684\u957f\u5ea6\u4e3a A + B\uff0c\u4e14\u6b63\u597d\u5305\u542b A \u4e2a 'a' \u5b57\u6bcd\u4e0e B \u4e2a 'b' \u5b57\u6bcd\uff1b
    • \n\t
    • \u5b50\u4e32 'aaa' \u6ca1\u6709\u51fa\u73b0\u5728 S \u4e2d\uff1b
    • \n\t
    • \u5b50\u4e32 'bbb' \u6ca1\u6709\u51fa\u73b0\u5728 S \u4e2d\u3002
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aA = 1, B = 2\n\u8f93\u51fa\uff1a"abb"\n\u89e3\u91ca\uff1a"abb", "bab" \u548c "bba" \u90fd\u662f\u6b63\u786e\u7b54\u6848\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aA = 4, B = 1\n\u8f93\u51fa\uff1a"aabaa"
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 0 <= A <= 100
    2. \n\t
    3. 0 <= B <= 100
    4. \n\t
    5. \u5bf9\u4e8e\u7ed9\u5b9a\u7684 A \u548c B\uff0c\u4fdd\u8bc1\u5b58\u5728\u6ee1\u8db3\u8981\u6c42\u7684 S\u3002
    6. \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string strWithout3a3b(int a, int b) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String strWithout3a3b(int a, int b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def strWithout3a3b(self, a, b):\n \"\"\"\n :type a: int\n :type b: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def strWithout3a3b(self, a: int, b: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * strWithout3a3b(int a, int b){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string StrWithout3a3b(int a, int b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} a\n * @param {number} b\n * @return {string}\n */\nvar strWithout3a3b = function(a, b) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} a\n# @param {Integer} b\n# @return {String}\ndef str_without3a3b(a, b)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func strWithout3a3b(_ a: Int, _ b: Int) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func strWithout3a3b(a int, b int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def strWithout3a3b(a: Int, b: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun strWithout3a3b(a: Int, b: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn str_without3a3b(a: i32, b: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $a\n * @param Integer $b\n * @return String\n */\n function strWithout3a3b($a, $b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function strWithout3a3b(a: number, b: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (str-without3a3b a b)\n (-> exact-integer? exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0984](https://leetcode-cn.com/problems/string-without-aaa-or-bbb)", "[\u4e0d\u542b AAA \u6216 BBB \u7684\u5b57\u7b26\u4e32](/solution/0900-0999/0984.String%20Without%20AAA%20or%20BBB/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0984](https://leetcode.com/problems/string-without-aaa-or-bbb)", "[String Without AAA or BBB](/solution/0900-0999/0984.String%20Without%20AAA%20or%20BBB/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "1025", "frontend_question_id": "0983", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-cost-for-tickets", "url_en": "https://leetcode.com/problems/minimum-cost-for-tickets", "relative_path_cn": "/solution/0900-0999/0983.Minimum%20Cost%20For%20Tickets/README.md", "relative_path_en": "/solution/0900-0999/0983.Minimum%20Cost%20For%20Tickets/README_EN.md", "title_cn": "\u6700\u4f4e\u7968\u4ef7", "title_en": "Minimum Cost For Tickets", "question_title_slug": "minimum-cost-for-tickets", "content_en": "

    You have planned some train traveling one year in advance. The days of the year in which you will travel are given as an integer array days. Each day is an integer from 1 to 365.

    \n\n

    Train tickets are sold in three different ways:

    \n\n
      \n\t
    • a 1-day pass is sold for costs[0] dollars,
    • \n\t
    • a 7-day pass is sold for costs[1] dollars, and
    • \n\t
    • a 30-day pass is sold for costs[2] dollars.
    • \n
    \n\n

    The passes allow that many days of consecutive travel.

    \n\n
      \n\t
    • For example, if we get a 7-day pass on day 2, then we can travel for 7 days: 2, 3, 4, 5, 6, 7, and 8.
    • \n
    \n\n

    Return the minimum number of dollars you need to travel every day in the given list of days.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: days = [1,4,6,7,8,20], costs = [2,7,15]\nOutput: 11\nExplanation: For example, here is one way to buy passes that lets you travel your travel plan:\nOn day 1, you bought a 1-day pass for costs[0] = $2, which covered day 1.\nOn day 3, you bought a 7-day pass for costs[1] = $7, which covered days 3, 4, ..., 9.\nOn day 20, you bought a 1-day pass for costs[0] = $2, which covered day 20.\nIn total, you spent $11 and covered all the days of your travel.\n
    \n\n

    Example 2:

    \n\n
    \nInput: days = [1,2,3,4,5,6,7,8,9,10,30,31], costs = [2,7,15]\nOutput: 17\nExplanation: For example, here is one way to buy passes that lets you travel your travel plan:\nOn day 1, you bought a 30-day pass for costs[2] = $15 which covered days 1, 2, ..., 30.\nOn day 31, you bought a 1-day pass for costs[0] = $2 which covered day 31.\nIn total, you spent $17 and covered all the days of your travel.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= days.length <= 365
    • \n\t
    • 1 <= days[i] <= 365
    • \n\t
    • days is in strictly increasing order.
    • \n\t
    • costs.length == 3
    • \n\t
    • 1 <= costs[i] <= 1000
    • \n
    \n", "content_cn": "

    \u5728\u4e00\u4e2a\u706b\u8f66\u65c5\u884c\u5f88\u53d7\u6b22\u8fce\u7684\u56fd\u5ea6\uff0c\u4f60\u63d0\u524d\u4e00\u5e74\u8ba1\u5212\u4e86\u4e00\u4e9b\u706b\u8f66\u65c5\u884c\u3002\u5728\u63a5\u4e0b\u6765\u7684\u4e00\u5e74\u91cc\uff0c\u4f60\u8981\u65c5\u884c\u7684\u65e5\u5b50\u5c06\u4ee5\u4e00\u4e2a\u540d\u4e3a days \u7684\u6570\u7ec4\u7ed9\u51fa\u3002\u6bcf\u4e00\u9879\u662f\u4e00\u4e2a\u4ece 1 \u5230 365 \u7684\u6574\u6570\u3002

    \n\n

    \u706b\u8f66\u7968\u6709\u4e09\u79cd\u4e0d\u540c\u7684\u9500\u552e\u65b9\u5f0f\uff1a

    \n\n
      \n\t
    • \u4e00\u5f20\u4e3a\u671f\u4e00\u5929\u7684\u901a\u884c\u8bc1\u552e\u4ef7\u4e3a costs[0] \u7f8e\u5143\uff1b
    • \n\t
    • \u4e00\u5f20\u4e3a\u671f\u4e03\u5929\u7684\u901a\u884c\u8bc1\u552e\u4ef7\u4e3a costs[1] \u7f8e\u5143\uff1b
    • \n\t
    • \u4e00\u5f20\u4e3a\u671f\u4e09\u5341\u5929\u7684\u901a\u884c\u8bc1\u552e\u4ef7\u4e3a costs[2] \u7f8e\u5143\u3002
    • \n
    \n\n

    \u901a\u884c\u8bc1\u5141\u8bb8\u6570\u5929\u65e0\u9650\u5236\u7684\u65c5\u884c\u3002 \u4f8b\u5982\uff0c\u5982\u679c\u6211\u4eec\u5728\u7b2c 2 \u5929\u83b7\u5f97\u4e00\u5f20\u4e3a\u671f 7 \u5929\u7684\u901a\u884c\u8bc1\uff0c\u90a3\u4e48\u6211\u4eec\u53ef\u4ee5\u8fde\u7740\u65c5\u884c 7 \u5929\uff1a\u7b2c 2 \u5929\u3001\u7b2c 3 \u5929\u3001\u7b2c 4 \u5929\u3001\u7b2c 5 \u5929\u3001\u7b2c 6 \u5929\u3001\u7b2c 7 \u5929\u548c\u7b2c 8 \u5929\u3002

    \n\n

    \u8fd4\u56de\u4f60\u60f3\u8981\u5b8c\u6210\u5728\u7ed9\u5b9a\u7684\u5217\u8868 days \u4e2d\u5217\u51fa\u7684\u6bcf\u4e00\u5929\u7684\u65c5\u884c\u6240\u9700\u8981\u7684\u6700\u4f4e\u6d88\u8d39\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1adays = [1,4,6,7,8,20], costs = [2,7,15]\n\u8f93\u51fa\uff1a11\n\u89e3\u91ca\uff1a \n\u4f8b\u5982\uff0c\u8fd9\u91cc\u6709\u4e00\u79cd\u8d2d\u4e70\u901a\u884c\u8bc1\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u8ba9\u4f60\u5b8c\u6210\u4f60\u7684\u65c5\u884c\u8ba1\u5212\uff1a\n\u5728\u7b2c 1 \u5929\uff0c\u4f60\u82b1\u4e86 costs[0] = $2 \u4e70\u4e86\u4e00\u5f20\u4e3a\u671f 1 \u5929\u7684\u901a\u884c\u8bc1\uff0c\u5b83\u5c06\u5728\u7b2c 1 \u5929\u751f\u6548\u3002\n\u5728\u7b2c 3 \u5929\uff0c\u4f60\u82b1\u4e86 costs[1] = $7 \u4e70\u4e86\u4e00\u5f20\u4e3a\u671f 7 \u5929\u7684\u901a\u884c\u8bc1\uff0c\u5b83\u5c06\u5728\u7b2c 3, 4, ..., 9 \u5929\u751f\u6548\u3002\n\u5728\u7b2c 20 \u5929\uff0c\u4f60\u82b1\u4e86 costs[0] = $2 \u4e70\u4e86\u4e00\u5f20\u4e3a\u671f 1 \u5929\u7684\u901a\u884c\u8bc1\uff0c\u5b83\u5c06\u5728\u7b2c 20 \u5929\u751f\u6548\u3002\n\u4f60\u603b\u5171\u82b1\u4e86 $11\uff0c\u5e76\u5b8c\u6210\u4e86\u4f60\u8ba1\u5212\u7684\u6bcf\u4e00\u5929\u65c5\u884c\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1adays = [1,2,3,4,5,6,7,8,9,10,30,31], costs = [2,7,15]\n\u8f93\u51fa\uff1a17\n\u89e3\u91ca\uff1a\n\u4f8b\u5982\uff0c\u8fd9\u91cc\u6709\u4e00\u79cd\u8d2d\u4e70\u901a\u884c\u8bc1\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u8ba9\u4f60\u5b8c\u6210\u4f60\u7684\u65c5\u884c\u8ba1\u5212\uff1a \n\u5728\u7b2c 1 \u5929\uff0c\u4f60\u82b1\u4e86 costs[2] = $15 \u4e70\u4e86\u4e00\u5f20\u4e3a\u671f 30 \u5929\u7684\u901a\u884c\u8bc1\uff0c\u5b83\u5c06\u5728\u7b2c 1, 2, ..., 30 \u5929\u751f\u6548\u3002\n\u5728\u7b2c 31 \u5929\uff0c\u4f60\u82b1\u4e86 costs[0] = $2 \u4e70\u4e86\u4e00\u5f20\u4e3a\u671f 1 \u5929\u7684\u901a\u884c\u8bc1\uff0c\u5b83\u5c06\u5728\u7b2c 31 \u5929\u751f\u6548\u3002 \n\u4f60\u603b\u5171\u82b1\u4e86 $17\uff0c\u5e76\u5b8c\u6210\u4e86\u4f60\u8ba1\u5212\u7684\u6bcf\u4e00\u5929\u65c5\u884c\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= days.length <= 365
    2. \n\t
    3. 1 <= days[i] <= 365
    4. \n\t
    5. days \u6309\u987a\u5e8f\u4e25\u683c\u9012\u589e
    6. \n\t
    7. costs.length == 3
    8. \n\t
    9. 1 <= costs[i] <= 1000
    10. \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int mincostTickets(vector& days, vector& costs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int mincostTickets(int[] days, int[] costs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def mincostTickets(self, days, costs):\n \"\"\"\n :type days: List[int]\n :type costs: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def mincostTickets(self, days: List[int], costs: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint mincostTickets(int* days, int daysSize, int* costs, int costsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MincostTickets(int[] days, int[] costs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} days\n * @param {number[]} costs\n * @return {number}\n */\nvar mincostTickets = function(days, costs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} days\n# @param {Integer[]} costs\n# @return {Integer}\ndef mincost_tickets(days, costs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func mincostTickets(_ days: [Int], _ costs: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func mincostTickets(days []int, costs []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def mincostTickets(days: Array[Int], costs: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun mincostTickets(days: IntArray, costs: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn mincost_tickets(days: Vec, costs: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $days\n * @param Integer[] $costs\n * @return Integer\n */\n function mincostTickets($days, $costs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function mincostTickets(days: number[], costs: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (mincost-tickets days costs)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0983](https://leetcode-cn.com/problems/minimum-cost-for-tickets)", "[\u6700\u4f4e\u7968\u4ef7](/solution/0900-0999/0983.Minimum%20Cost%20For%20Tickets/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0983](https://leetcode.com/problems/minimum-cost-for-tickets)", "[Minimum Cost For Tickets](/solution/0900-0999/0983.Minimum%20Cost%20For%20Tickets/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "1024", "frontend_question_id": "0982", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/triples-with-bitwise-and-equal-to-zero", "url_en": "https://leetcode.com/problems/triples-with-bitwise-and-equal-to-zero", "relative_path_cn": "/solution/0900-0999/0982.Triples%20with%20Bitwise%20AND%20Equal%20To%20Zero/README.md", "relative_path_en": "/solution/0900-0999/0982.Triples%20with%20Bitwise%20AND%20Equal%20To%20Zero/README_EN.md", "title_cn": "\u6309\u4f4d\u4e0e\u4e3a\u96f6\u7684\u4e09\u5143\u7ec4", "title_en": "Triples with Bitwise AND Equal To Zero", "question_title_slug": "triples-with-bitwise-and-equal-to-zero", "content_en": "

    Given an array of integers nums, find the number of triples of indices (i, j, k) such that:

    \n\n
      \n\t
    • 0 <= i < nums.length
    • \n\t
    • 0 <= j < nums.length
    • \n\t
    • 0 <= k < nums.length
    • \n\t
    • nums[i] & nums[j] & nums[k] == 0, where & represents the bitwise-AND operator.
    • \n
    \n\n

     

    \n\n

    Example 1:

    \n\n
    \nInput: nums = [2,1,3]\nOutput: 12\nExplanation: We could choose the following i, j, k triples:\n(i=0, j=0, k=1) : 2 & 2 & 1\n(i=0, j=1, k=0) : 2 & 1 & 2\n(i=0, j=1, k=1) : 2 & 1 & 1\n(i=0, j=1, k=2) : 2 & 1 & 3\n(i=0, j=2, k=1) : 2 & 3 & 1\n(i=1, j=0, k=0) : 1 & 2 & 2\n(i=1, j=0, k=1) : 1 & 2 & 1\n(i=1, j=0, k=2) : 1 & 2 & 3\n(i=1, j=1, k=0) : 1 & 1 & 2\n(i=1, j=2, k=0) : 1 & 3 & 2\n(i=2, j=0, k=1) : 3 & 2 & 1\n(i=2, j=1, k=0) : 3 & 1 & 2\n
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    1. 1 <= nums.length <= 1000
    2. \n\t
    3. 0 <= nums[i] < 216
    4. \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 A\uff0c\u627e\u51fa\u7d22\u5f15\u4e3a (i, j, k) \u7684\u4e09\u5143\u7ec4\uff0c\u4f7f\u5f97\uff1a

    \n\n
      \n\t
    • 0 <= i < A.length
    • \n\t
    • 0 <= j < A.length
    • \n\t
    • 0 <= k < A.length
    • \n\t
    • A[i] & A[j] & A[k] == 0\uff0c\u5176\u4e2d & \u8868\u793a\u6309\u4f4d\u4e0e\uff08AND\uff09\u64cd\u4f5c\u7b26\u3002
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1a[2,1,3]\n\u8f93\u51fa\uff1a12\n\u89e3\u91ca\uff1a\u6211\u4eec\u53ef\u4ee5\u9009\u51fa\u5982\u4e0b i, j, k \u4e09\u5143\u7ec4\uff1a\n(i=0, j=0, k=1) : 2 & 2 & 1\n(i=0, j=1, k=0) : 2 & 1 & 2\n(i=0, j=1, k=1) : 2 & 1 & 1\n(i=0, j=1, k=2) : 2 & 1 & 3\n(i=0, j=2, k=1) : 2 & 3 & 1\n(i=1, j=0, k=0) : 1 & 2 & 2\n(i=1, j=0, k=1) : 1 & 2 & 1\n(i=1, j=0, k=2) : 1 & 2 & 3\n(i=1, j=1, k=0) : 1 & 1 & 2\n(i=1, j=2, k=0) : 1 & 3 & 2\n(i=2, j=0, k=1) : 3 & 2 & 1\n(i=2, j=1, k=0) : 3 & 1 & 2\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= A.length <= 1000
    2. \n\t
    3. 0 <= A[i] < 2^16
    4. \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countTriplets(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countTriplets(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countTriplets(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countTriplets(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countTriplets(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountTriplets(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar countTriplets = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef count_triplets(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countTriplets(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countTriplets(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countTriplets(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countTriplets(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_triplets(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function countTriplets($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countTriplets(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-triplets nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0982](https://leetcode-cn.com/problems/triples-with-bitwise-and-equal-to-zero)", "[\u6309\u4f4d\u4e0e\u4e3a\u96f6\u7684\u4e09\u5143\u7ec4](/solution/0900-0999/0982.Triples%20with%20Bitwise%20AND%20Equal%20To%20Zero/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0982](https://leetcode.com/problems/triples-with-bitwise-and-equal-to-zero)", "[Triples with Bitwise AND Equal To Zero](/solution/0900-0999/0982.Triples%20with%20Bitwise%20AND%20Equal%20To%20Zero/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "1023", "frontend_question_id": "0981", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/time-based-key-value-store", "url_en": "https://leetcode.com/problems/time-based-key-value-store", "relative_path_cn": "/solution/0900-0999/0981.Time%20Based%20Key-Value%20Store/README.md", "relative_path_en": "/solution/0900-0999/0981.Time%20Based%20Key-Value%20Store/README_EN.md", "title_cn": "\u57fa\u4e8e\u65f6\u95f4\u7684\u952e\u503c\u5b58\u50a8", "title_en": "Time Based Key-Value Store", "question_title_slug": "time-based-key-value-store", "content_en": "

    Create a timebased key-value store class TimeMap, that supports two operations.

    \r\n\r\n

    1. set(string key, string value, int timestamp)

    \r\n\r\n
      \r\n\t
    • Stores the key and value, along with the given timestamp.
    • \r\n
    \r\n\r\n

    2. get(string key, int timestamp)

    \r\n\r\n
      \r\n\t
    • Returns a value such that set(key, value, timestamp_prev) was called previously, with timestamp_prev <= timestamp.
    • \r\n\t
    • If there are multiple such values, it returns the one with the largest timestamp_prev.
    • \r\n\t
    • If there are no values, it returns the empty string ("").
    • \r\n
    \r\n\r\n

     

    \r\n\r\n
    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: inputs = ["TimeMap","set","get","get","set","get","get"], inputs = [[],["foo","bar",1],["foo",1],["foo",3],["foo","bar2",4],["foo",4],["foo",5]]\r\nOutput: [null,null,"bar","bar",null,"bar2","bar2"]\r\nExplanation:   \r\nTimeMap kv;   \r\nkv.set("foo", "bar", 1); // store the key "foo" and value "bar" along with timestamp = 1   \r\nkv.get("foo", 1);  // output "bar"   \r\nkv.get("foo", 3); // output "bar" since there is no value corresponding to foo at timestamp 3 and timestamp 2, then the only value is at timestamp 1 ie "bar"   \r\nkv.set("foo", "bar2", 4);   \r\nkv.get("foo", 4); // output "bar2"   \r\nkv.get("foo", 5); //output "bar2"   \r\n\r\n
    \r\n\r\n
    \r\n

    Example 2:

    \r\n\r\n
    \r\nInput: inputs = ["TimeMap","set","set","get","get","get","get","get"], inputs = [[],["love","high",10],["love","low",20],["love",5],["love",10],["love",15],["love",20],["love",25]]\r\nOutput: [null,null,null,"","high","high","low","low"]\r\n
    \r\n
    \r\n
    \r\n\r\n

     

    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    1. All key/value strings are lowercase.
    2. \r\n\t
    3. All key/value strings have length in the range [1, 100]
    4. \r\n\t
    5. The timestamps for all TimeMap.set operations are strictly increasing.
    6. \r\n\t
    7. 1 <= timestamp <= 10^7
    8. \r\n\t
    9. TimeMap.set and TimeMap.get functions will be called a total of 120000 times (combined) per test case.
    10. \r\n
    \r\n", "content_cn": "

    \u521b\u5efa\u4e00\u4e2a\u57fa\u4e8e\u65f6\u95f4\u7684\u952e\u503c\u5b58\u50a8\u7c7b TimeMap\uff0c\u5b83\u652f\u6301\u4e0b\u9762\u4e24\u4e2a\u64cd\u4f5c\uff1a

    \n\n

    1. set(string key, string value, int timestamp)

    \n\n
      \n\t
    • \u5b58\u50a8\u952e key\u3001\u503c value\uff0c\u4ee5\u53ca\u7ed9\u5b9a\u7684\u65f6\u95f4\u6233 timestamp\u3002
    • \n
    \n\n

    2. get(string key, int timestamp)

    \n\n
      \n\t
    • \u8fd4\u56de\u5148\u524d\u8c03\u7528 set(key, value, timestamp_prev) \u6240\u5b58\u50a8\u7684\u503c\uff0c\u5176\u4e2d timestamp_prev <= timestamp\u3002
    • \n\t
    • \u5982\u679c\u6709\u591a\u4e2a\u8fd9\u6837\u7684\u503c\uff0c\u5219\u8fd4\u56de\u5bf9\u5e94\u6700\u5927\u7684  timestamp_prev \u7684\u90a3\u4e2a\u503c\u3002
    • \n\t
    • \u5982\u679c\u6ca1\u6709\u503c\uff0c\u5219\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32\uff08""\uff09\u3002
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1ainputs = ["TimeMap","set","get","get","set","get","get"], inputs = [[],["foo","bar",1],["foo",1],["foo",3],["foo","bar2",4],["foo",4],["foo",5]]\n\u8f93\u51fa\uff1a[null,null,"bar","bar",null,"bar2","bar2"]\n\u89e3\u91ca\uff1a  \nTimeMap kv;   \nkv.set("foo", "bar", 1); // \u5b58\u50a8\u952e "foo" \u548c\u503c "bar" \u4ee5\u53ca\u65f6\u95f4\u6233 timestamp = 1   \nkv.get("foo", 1);  // \u8f93\u51fa "bar"   \nkv.get("foo", 3); // \u8f93\u51fa "bar" \u56e0\u4e3a\u5728\u65f6\u95f4\u6233 3 \u548c\u65f6\u95f4\u6233 2 \u5904\u6ca1\u6709\u5bf9\u5e94 "foo" \u7684\u503c\uff0c\u6240\u4ee5\u552f\u4e00\u7684\u503c\u4f4d\u4e8e\u65f6\u95f4\u6233 1 \u5904\uff08\u5373 "bar"\uff09   \nkv.set("foo", "bar2", 4);   \nkv.get("foo", 4); // \u8f93\u51fa "bar2"   \nkv.get("foo", 5); // \u8f93\u51fa "bar2"   \n\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1ainputs = ["TimeMap","set","set","get","get","get","get","get"], inputs = [[],["love","high",10],["love","low",20],["love",5],["love",10],["love",15],["love",20],["love",25]]\n\u8f93\u51fa\uff1a[null,null,null,"","high","high","low","low"]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. \u6240\u6709\u7684\u952e/\u503c\u5b57\u7b26\u4e32\u90fd\u662f\u5c0f\u5199\u7684\u3002
    2. \n\t
    3. \u6240\u6709\u7684\u952e/\u503c\u5b57\u7b26\u4e32\u957f\u5ea6\u90fd\u5728 [1, 100] \u8303\u56f4\u5185\u3002
    4. \n\t
    5. \u6240\u6709 TimeMap.set \u64cd\u4f5c\u4e2d\u7684\u65f6\u95f4\u6233 timestamps \u90fd\u662f\u4e25\u683c\u9012\u589e\u7684\u3002
    6. \n\t
    7. 1 <= timestamp <= 10^7
    8. \n\t
    9. TimeMap.set \u548c TimeMap.get \u51fd\u6570\u5728\u6bcf\u4e2a\u6d4b\u8bd5\u7528\u4f8b\u4e2d\u5c06\uff08\u7ec4\u5408\uff09\u8c03\u7528\u603b\u8ba1 120000 \u6b21\u3002
    10. \n
    \n", "tags_en": ["Hash Table", "Binary Search"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class TimeMap {\npublic:\n /** Initialize your data structure here. */\n TimeMap() {\n\n }\n \n void set(string key, string value, int timestamp) {\n\n }\n \n string get(string key, int timestamp) {\n\n }\n};\n\n/**\n * Your TimeMap object will be instantiated and called as such:\n * TimeMap* obj = new TimeMap();\n * obj->set(key,value,timestamp);\n * string param_2 = obj->get(key,timestamp);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class TimeMap {\n\n /** Initialize your data structure here. */\n public TimeMap() {\n\n }\n \n public void set(String key, String value, int timestamp) {\n\n }\n \n public String get(String key, int timestamp) {\n\n }\n}\n\n/**\n * Your TimeMap object will be instantiated and called as such:\n * TimeMap obj = new TimeMap();\n * obj.set(key,value,timestamp);\n * String param_2 = obj.get(key,timestamp);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class TimeMap(object):\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n \n\n def set(self, key, value, timestamp):\n \"\"\"\n :type key: str\n :type value: str\n :type timestamp: int\n :rtype: None\n \"\"\"\n \n\n def get(self, key, timestamp):\n \"\"\"\n :type key: str\n :type timestamp: int\n :rtype: str\n \"\"\"\n \n\n\n# Your TimeMap object will be instantiated and called as such:\n# obj = TimeMap()\n# obj.set(key,value,timestamp)\n# param_2 = obj.get(key,timestamp)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class TimeMap:\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n \n\n def set(self, key: str, value: str, timestamp: int) -> None:\n \n\n def get(self, key: str, timestamp: int) -> str:\n \n\n\n# Your TimeMap object will be instantiated and called as such:\n# obj = TimeMap()\n# obj.set(key,value,timestamp)\n# param_2 = obj.get(key,timestamp)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} TimeMap;\n\n/** Initialize your data structure here. */\n\nTimeMap* timeMapCreate() {\n \n}\n\nvoid timeMapSet(TimeMap* obj, char * key, char * value, int timestamp) {\n \n}\n\nchar * timeMapGet(TimeMap* obj, char * key, int timestamp) {\n \n}\n\nvoid timeMapFree(TimeMap* obj) {\n \n}\n\n/**\n * Your TimeMap struct will be instantiated and called as such:\n * TimeMap* obj = timeMapCreate();\n * timeMapSet(obj, key, value, timestamp);\n \n * char * param_2 = timeMapGet(obj, key, timestamp);\n \n * timeMapFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class TimeMap {\n\n /** Initialize your data structure here. */\n public TimeMap() {\n\n }\n \n public void Set(string key, string value, int timestamp) {\n\n }\n \n public string Get(string key, int timestamp) {\n\n }\n}\n\n/**\n * Your TimeMap object will be instantiated and called as such:\n * TimeMap obj = new TimeMap();\n * obj.Set(key,value,timestamp);\n * string param_2 = obj.Get(key,timestamp);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Initialize your data structure here.\n */\nvar TimeMap = function() {\n\n};\n\n/** \n * @param {string} key \n * @param {string} value \n * @param {number} timestamp\n * @return {void}\n */\nTimeMap.prototype.set = function(key, value, timestamp) {\n\n};\n\n/** \n * @param {string} key \n * @param {number} timestamp\n * @return {string}\n */\nTimeMap.prototype.get = function(key, timestamp) {\n\n};\n\n/**\n * Your TimeMap object will be instantiated and called as such:\n * var obj = new TimeMap()\n * obj.set(key,value,timestamp)\n * var param_2 = obj.get(key,timestamp)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class TimeMap\n\n=begin\n Initialize your data structure here.\n=end\n def initialize()\n\n end\n\n\n=begin\n :type key: String\n :type value: String\n :type timestamp: Integer\n :rtype: Void\n=end\n def set(key, value, timestamp)\n\n end\n\n\n=begin\n :type key: String\n :type timestamp: Integer\n :rtype: String\n=end\n def get(key, timestamp)\n\n end\n\n\nend\n\n# Your TimeMap object will be instantiated and called as such:\n# obj = TimeMap.new()\n# obj.set(key, value, timestamp)\n# param_2 = obj.get(key, timestamp)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass TimeMap {\n\n /** Initialize your data structure here. */\n init() {\n \n }\n \n func set(_ key: String, _ value: String, _ timestamp: Int) {\n \n }\n \n func get(_ key: String, _ timestamp: Int) -> String {\n \n }\n}\n\n/**\n * Your TimeMap object will be instantiated and called as such:\n * let obj = TimeMap()\n * obj.set(key, value, timestamp)\n * let ret_2: String = obj.get(key, timestamp)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type TimeMap struct {\n\n}\n\n\n/** Initialize your data structure here. */\nfunc Constructor() TimeMap {\n\n}\n\n\nfunc (this *TimeMap) Set(key string, value string, timestamp int) {\n\n}\n\n\nfunc (this *TimeMap) Get(key string, timestamp int) string {\n\n}\n\n\n/**\n * Your TimeMap object will be instantiated and called as such:\n * obj := Constructor();\n * obj.Set(key,value,timestamp);\n * param_2 := obj.Get(key,timestamp);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class TimeMap() {\n\n /** Initialize your data structure here. */\n\n\n def set(key: String, value: String, timestamp: Int) {\n\n }\n\n def get(key: String, timestamp: Int): String = {\n\n }\n\n}\n\n/**\n * Your TimeMap object will be instantiated and called as such:\n * var obj = new TimeMap()\n * obj.set(key,value,timestamp)\n * var param_2 = obj.get(key,timestamp)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class TimeMap() {\n\n /** Initialize your data structure here. */\n\n\n fun set(key: String, value: String, timestamp: Int) {\n\n }\n\n fun get(key: String, timestamp: Int): String {\n\n }\n\n}\n\n/**\n * Your TimeMap object will be instantiated and called as such:\n * var obj = TimeMap()\n * obj.set(key,value,timestamp)\n * var param_2 = obj.get(key,timestamp)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct TimeMap {\n\n}\n\n\n/** \n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl TimeMap {\n\n /** Initialize your data structure here. */\n fn new() -> Self {\n \n }\n \n fn set(&self, key: String, value: String, timestamp: i32) {\n \n }\n \n fn get(&self, key: String, timestamp: i32) -> String {\n \n }\n}\n\n/**\n * Your TimeMap object will be instantiated and called as such:\n * let obj = TimeMap::new();\n * obj.set(key, value, timestamp);\n * let ret_2: String = obj.get(key, timestamp);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class TimeMap {\n /**\n * Initialize your data structure here.\n */\n function __construct() {\n \n }\n \n /**\n * @param String $key\n * @param String $value\n * @param Integer $timestamp\n * @return NULL\n */\n function set($key, $value, $timestamp) {\n \n }\n \n /**\n * @param String $key\n * @param Integer $timestamp\n * @return String\n */\n function get($key, $timestamp) {\n \n }\n}\n\n/**\n * Your TimeMap object will be instantiated and called as such:\n * $obj = TimeMap();\n * $obj->set($key, $value, $timestamp);\n * $ret_2 = $obj->get($key, $timestamp);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class TimeMap {\n constructor() {\n\n }\n\n set(key: string, value: string, timestamp: number): void {\n\n }\n\n get(key: string, timestamp: number): string {\n\n }\n}\n\n/**\n * Your TimeMap object will be instantiated and called as such:\n * var obj = new TimeMap()\n * obj.set(key,value,timestamp)\n * var param_2 = obj.get(key,timestamp)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define time-map%\n (class object%\n (super-new)\n (init-field)\n \n ; set : string? string? exact-integer? -> void?\n (define/public (set key value timestamp)\n\n )\n ; get : string? exact-integer? -> string?\n (define/public (get key timestamp)\n\n )))\n\n;; Your time-map% object will be instantiated and called as such:\n;; (define obj (new time-map%))\n;; (send obj set key value timestamp)\n;; (define param_2 (send obj get key timestamp))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0981](https://leetcode-cn.com/problems/time-based-key-value-store)", "[\u57fa\u4e8e\u65f6\u95f4\u7684\u952e\u503c\u5b58\u50a8](/solution/0900-0999/0981.Time%20Based%20Key-Value%20Store/README.md)", "`\u54c8\u5e0c\u8868`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0981](https://leetcode.com/problems/time-based-key-value-store)", "[Time Based Key-Value Store](/solution/0900-0999/0981.Time%20Based%20Key-Value%20Store/README_EN.md)", "`Hash Table`,`Binary Search`", "Medium", ""]}, {"question_id": "1022", "frontend_question_id": "0980", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/unique-paths-iii", "url_en": "https://leetcode.com/problems/unique-paths-iii", "relative_path_cn": "/solution/0900-0999/0980.Unique%20Paths%20III/README.md", "relative_path_en": "/solution/0900-0999/0980.Unique%20Paths%20III/README_EN.md", "title_cn": "\u4e0d\u540c\u8def\u5f84 III", "title_en": "Unique Paths III", "question_title_slug": "unique-paths-iii", "content_en": "

    On a 2-dimensional grid, there are 4 types of squares:

    \r\n\r\n
      \r\n\t
    • 1 represents the starting square.  There is exactly one starting square.
    • \r\n\t
    • 2 represents the ending square.  There is exactly one ending square.
    • \r\n\t
    • 0 represents empty squares we can walk over.
    • \r\n\t
    • -1 represents obstacles that we cannot walk over.
    • \r\n
    \r\n\r\n

    Return the number of 4-directional walks from the starting square to the ending square, that walk over every non-obstacle square exactly once.

    \r\n\r\n

     

    \r\n\r\n
    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: [[1,0,0,0],[0,0,0,0],[0,0,2,-1]]\r\nOutput: 2\r\nExplanation: We have the following two paths: \r\n1. (0,0),(0,1),(0,2),(0,3),(1,3),(1,2),(1,1),(1,0),(2,0),(2,1),(2,2)\r\n2. (0,0),(1,0),(2,0),(2,1),(1,1),(0,1),(0,2),(0,3),(1,3),(1,2),(2,2)
    \r\n\r\n
    \r\n

    Example 2:

    \r\n\r\n
    \r\nInput: [[1,0,0,0],[0,0,0,0],[0,0,0,2]]\r\nOutput: 4\r\nExplanation: We have the following four paths: \r\n1. (0,0),(0,1),(0,2),(0,3),(1,3),(1,2),(1,1),(1,0),(2,0),(2,1),(2,2),(2,3)\r\n2. (0,0),(0,1),(1,1),(1,0),(2,0),(2,1),(2,2),(1,2),(0,2),(0,3),(1,3),(2,3)\r\n3. (0,0),(1,0),(2,0),(2,1),(2,2),(1,2),(1,1),(0,1),(0,2),(0,3),(1,3),(2,3)\r\n4. (0,0),(1,0),(2,0),(2,1),(1,1),(0,1),(0,2),(0,3),(1,3),(1,2),(2,2),(2,3)
    \r\n\r\n
    \r\n

    Example 3:

    \r\n\r\n
    \r\nInput: [[0,1],[2,0]]\r\nOutput: 0\r\nExplanation: \r\nThere is no path that walks over every empty square exactly once.\r\nNote that the starting and ending square can be anywhere in the grid.\r\n
    \r\n
    \r\n
    \r\n
    \r\n\r\n

     

    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    1. 1 <= grid.length * grid[0].length <= 20
    2. \r\n
    ", "content_cn": "

    \u5728\u4e8c\u7ef4\u7f51\u683c grid \u4e0a\uff0c\u6709 4 \u79cd\u7c7b\u578b\u7684\u65b9\u683c\uff1a

    \n\n
      \n\t
    • 1 \u8868\u793a\u8d77\u59cb\u65b9\u683c\u3002\u4e14\u53ea\u6709\u4e00\u4e2a\u8d77\u59cb\u65b9\u683c\u3002
    • \n\t
    • 2 \u8868\u793a\u7ed3\u675f\u65b9\u683c\uff0c\u4e14\u53ea\u6709\u4e00\u4e2a\u7ed3\u675f\u65b9\u683c\u3002
    • \n\t
    • 0 \u8868\u793a\u6211\u4eec\u53ef\u4ee5\u8d70\u8fc7\u7684\u7a7a\u65b9\u683c\u3002
    • \n\t
    • -1 \u8868\u793a\u6211\u4eec\u65e0\u6cd5\u8de8\u8d8a\u7684\u969c\u788d\u3002
    • \n
    \n\n

    \u8fd4\u56de\u5728\u56db\u4e2a\u65b9\u5411\uff08\u4e0a\u3001\u4e0b\u3001\u5de6\u3001\u53f3\uff09\u4e0a\u884c\u8d70\u65f6\uff0c\u4ece\u8d77\u59cb\u65b9\u683c\u5230\u7ed3\u675f\u65b9\u683c\u7684\u4e0d\u540c\u8def\u5f84\u7684\u6570\u76ee\u3002

    \n\n

    \u6bcf\u4e00\u4e2a\u65e0\u969c\u788d\u65b9\u683c\u90fd\u8981\u901a\u8fc7\u4e00\u6b21\uff0c\u4f46\u662f\u4e00\u6761\u8def\u5f84\u4e2d\u4e0d\u80fd\u91cd\u590d\u901a\u8fc7\u540c\u4e00\u4e2a\u65b9\u683c\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a[[1,0,0,0],[0,0,0,0],[0,0,2,-1]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6211\u4eec\u6709\u4ee5\u4e0b\u4e24\u6761\u8def\u5f84\uff1a\n1. (0,0),(0,1),(0,2),(0,3),(1,3),(1,2),(1,1),(1,0),(2,0),(2,1),(2,2)\n2. (0,0),(1,0),(2,0),(2,1),(1,1),(0,1),(0,2),(0,3),(1,3),(1,2),(2,2)
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a[[1,0,0,0],[0,0,0,0],[0,0,0,2]]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u6211\u4eec\u6709\u4ee5\u4e0b\u56db\u6761\u8def\u5f84\uff1a \n1. (0,0),(0,1),(0,2),(0,3),(1,3),(1,2),(1,1),(1,0),(2,0),(2,1),(2,2),(2,3)\n2. (0,0),(0,1),(1,1),(1,0),(2,0),(2,1),(2,2),(1,2),(0,2),(0,3),(1,3),(2,3)\n3. (0,0),(1,0),(2,0),(2,1),(2,2),(1,2),(1,1),(0,1),(0,2),(0,3),(1,3),(2,3)\n4. (0,0),(1,0),(2,0),(2,1),(1,1),(0,1),(0,2),(0,3),(1,3),(1,2),(2,2),(2,3)
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1a[[0,1],[2,0]]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\n\u6ca1\u6709\u4e00\u6761\u8def\u80fd\u5b8c\u5168\u7a7f\u8fc7\u6bcf\u4e00\u4e2a\u7a7a\u7684\u65b9\u683c\u4e00\u6b21\u3002\n\u8bf7\u6ce8\u610f\uff0c\u8d77\u59cb\u548c\u7ed3\u675f\u65b9\u683c\u53ef\u4ee5\u4f4d\u4e8e\u7f51\u683c\u4e2d\u7684\u4efb\u610f\u4f4d\u7f6e\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= grid.length * grid[0].length <= 20
    • \n
    \n", "tags_en": ["Depth-first Search", "Backtracking"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int uniquePathsIII(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int uniquePathsIII(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def uniquePathsIII(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def uniquePathsIII(self, grid: List[List[int]]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint uniquePathsIII(int** grid, int gridSize, int* gridColSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int UniquePathsIII(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar uniquePathsIII = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef unique_paths_iii(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func uniquePathsIII(_ grid: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func uniquePathsIII(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def uniquePathsIII(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun uniquePathsIII(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn unique_paths_iii(grid: Vec>) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function uniquePathsIII($grid) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function uniquePathsIII(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (unique-paths-iii grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0980](https://leetcode-cn.com/problems/unique-paths-iii)", "[\u4e0d\u540c\u8def\u5f84 III](/solution/0900-0999/0980.Unique%20Paths%20III/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u56de\u6eaf\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[0980](https://leetcode.com/problems/unique-paths-iii)", "[Unique Paths III](/solution/0900-0999/0980.Unique%20Paths%20III/README_EN.md)", "`Depth-first Search`,`Backtracking`", "Hard", ""]}, {"question_id": "1021", "frontend_question_id": "0979", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/distribute-coins-in-binary-tree", "url_en": "https://leetcode.com/problems/distribute-coins-in-binary-tree", "relative_path_cn": "/solution/0900-0999/0979.Distribute%20Coins%20in%20Binary%20Tree/README.md", "relative_path_en": "/solution/0900-0999/0979.Distribute%20Coins%20in%20Binary%20Tree/README_EN.md", "title_cn": "\u5728\u4e8c\u53c9\u6811\u4e2d\u5206\u914d\u786c\u5e01", "title_en": "Distribute Coins in Binary Tree", "question_title_slug": "distribute-coins-in-binary-tree", "content_en": "

    You are given the root of a binary tree with n nodes where each node in the tree has node.val coins. There are n coins in total throughout the whole tree.

    \n\n

    In one move, we may choose two adjacent nodes and move one coin from one node to another. A move may be from parent to child, or from child to parent.

    \n\n

    Return the minimum number of moves required to make every node have exactly one coin.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [3,0,0]\nOutput: 2\nExplanation: From the root of the tree, we move one coin to its left child, and one coin to its right child.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [0,3,0]\nOutput: 3\nExplanation: From the left child of the root, we move two coins to the root [taking two moves]. Then, we move one coin from the root of the tree to the right child.\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: root = [1,0,2]\nOutput: 2\n
    \n\n

    Example 4:

    \n\"\"\n
    \nInput: root = [1,0,0,null,3]\nOutput: 4\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is n.
    • \n\t
    • 1 <= n <= 100
    • \n\t
    • 0 <= Node.val <= n
    • \n\t
    • The sum of all Node.val is n.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6709 N \u4e2a\u7ed3\u70b9\u7684\u4e8c\u53c9\u6811\u7684\u6839\u7ed3\u70b9 root\uff0c\u6811\u4e2d\u7684\u6bcf\u4e2a\u7ed3\u70b9\u4e0a\u90fd\u5bf9\u5e94\u6709 node.val \u679a\u786c\u5e01\uff0c\u5e76\u4e14\u603b\u5171\u6709 N \u679a\u786c\u5e01\u3002

    \n\n

    \u5728\u4e00\u6b21\u79fb\u52a8\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u9009\u62e9\u4e24\u4e2a\u76f8\u90bb\u7684\u7ed3\u70b9\uff0c\u7136\u540e\u5c06\u4e00\u679a\u786c\u5e01\u4ece\u5176\u4e2d\u4e00\u4e2a\u7ed3\u70b9\u79fb\u52a8\u5230\u53e6\u4e00\u4e2a\u7ed3\u70b9\u3002(\u79fb\u52a8\u53ef\u4ee5\u662f\u4ece\u7236\u7ed3\u70b9\u5230\u5b50\u7ed3\u70b9\uff0c\u6216\u8005\u4ece\u5b50\u7ed3\u70b9\u79fb\u52a8\u5230\u7236\u7ed3\u70b9\u3002)\u3002

    \n\n

    \u8fd4\u56de\u4f7f\u6bcf\u4e2a\u7ed3\u70b9\u4e0a\u53ea\u6709\u4e00\u679a\u786c\u5e01\u6240\u9700\u7684\u79fb\u52a8\u6b21\u6570\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1a[3,0,0]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u4ece\u6811\u7684\u6839\u7ed3\u70b9\u5f00\u59cb\uff0c\u6211\u4eec\u5c06\u4e00\u679a\u786c\u5e01\u79fb\u5230\u5b83\u7684\u5de6\u5b50\u7ed3\u70b9\u4e0a\uff0c\u4e00\u679a\u786c\u5e01\u79fb\u5230\u5b83\u7684\u53f3\u5b50\u7ed3\u70b9\u4e0a\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1a[0,3,0]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u4ece\u6839\u7ed3\u70b9\u7684\u5de6\u5b50\u7ed3\u70b9\u5f00\u59cb\uff0c\u6211\u4eec\u5c06\u4e24\u679a\u786c\u5e01\u79fb\u5230\u6839\u7ed3\u70b9\u4e0a [\u79fb\u52a8\u4e24\u6b21]\u3002\u7136\u540e\uff0c\u6211\u4eec\u628a\u4e00\u679a\u786c\u5e01\u4ece\u6839\u7ed3\u70b9\u79fb\u5230\u53f3\u5b50\u7ed3\u70b9\u4e0a\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1a[1,0,2]\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1a[1,0,0,null,3]\n\u8f93\u51fa\uff1a4\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1<= N <= 100
    2. \n\t
    3. 0 <= node.val <= N
    4. \n
    \n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int distributeCoins(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int distributeCoins(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def distributeCoins(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def distributeCoins(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint distributeCoins(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int DistributeCoins(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar distributeCoins = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef distribute_coins(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func distributeCoins(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc distributeCoins(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def distributeCoins(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun distributeCoins(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn distribute_coins(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function distributeCoins($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction distributeCoins(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (distribute-coins root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0979](https://leetcode-cn.com/problems/distribute-coins-in-binary-tree)", "[\u5728\u4e8c\u53c9\u6811\u4e2d\u5206\u914d\u786c\u5e01](/solution/0900-0999/0979.Distribute%20Coins%20in%20Binary%20Tree/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0979](https://leetcode.com/problems/distribute-coins-in-binary-tree)", "[Distribute Coins in Binary Tree](/solution/0900-0999/0979.Distribute%20Coins%20in%20Binary%20Tree/README_EN.md)", "`Tree`,`Depth-first Search`", "Medium", ""]}, {"question_id": "1020", "frontend_question_id": "0978", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-turbulent-subarray", "url_en": "https://leetcode.com/problems/longest-turbulent-subarray", "relative_path_cn": "/solution/0900-0999/0978.Longest%20Turbulent%20Subarray/README.md", "relative_path_en": "/solution/0900-0999/0978.Longest%20Turbulent%20Subarray/README_EN.md", "title_cn": "\u6700\u957f\u6e4d\u6d41\u5b50\u6570\u7ec4", "title_en": "Longest Turbulent Subarray", "question_title_slug": "longest-turbulent-subarray", "content_en": "

    Given an integer array arr, return the length of a maximum size turbulent subarray of arr.

    \n\n

    A subarray is turbulent if the comparison sign flips between each adjacent pair of elements in the subarray.

    \n\n

    More formally, a subarray [arr[i], arr[i + 1], ..., arr[j]] of arr is said to be turbulent if and only if:

    \n\n
      \n\t
    • For i <= k < j:\n\n\t
        \n\t\t
      • arr[k] > arr[k + 1] when k is odd, and
      • \n\t\t
      • arr[k] < arr[k + 1] when k is even.
      • \n\t
      \n\t
    • \n\t
    • Or, for i <= k < j:\n\t
        \n\t\t
      • arr[k] > arr[k + 1] when k is even, and
      • \n\t\t
      • arr[k] < arr[k + 1] when k is odd.
      • \n\t
      \n\t
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr = [9,4,2,10,7,8,8,1,9]\nOutput: 5\nExplanation: arr[1] > arr[2] < arr[3] > arr[4] < arr[5]\n
    \n\n

    Example 2:

    \n\n
    \nInput: arr = [4,8,12,16]\nOutput: 2\n
    \n\n

    Example 3:

    \n\n
    \nInput: arr = [100]\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= arr.length <= 4 * 104
    • \n\t
    • 0 <= arr[i] <= 109
    • \n
    \n", "content_cn": "

    \u5f53 A \u7684\u5b50\u6570\u7ec4 A[i], A[i+1], ..., A[j] \u6ee1\u8db3\u4e0b\u5217\u6761\u4ef6\u65f6\uff0c\u6211\u4eec\u79f0\u5176\u4e3a\u6e4d\u6d41\u5b50\u6570\u7ec4\uff1a

    \n\n
      \n\t
    • \u82e5 i <= k < j\uff0c\u5f53 k \u4e3a\u5947\u6570\u65f6\uff0c A[k] > A[k+1]\uff0c\u4e14\u5f53 k \u4e3a\u5076\u6570\u65f6\uff0cA[k] < A[k+1]\uff1b
    • \n\t
    • \u6216 \u82e5 i <= k < j\uff0c\u5f53 k \u4e3a\u5076\u6570\u65f6\uff0cA[k] > A[k+1] \uff0c\u4e14\u5f53 k \u4e3a\u5947\u6570\u65f6\uff0c A[k] < A[k+1]\u3002
    • \n
    \n\n

    \u4e5f\u5c31\u662f\u8bf4\uff0c\u5982\u679c\u6bd4\u8f83\u7b26\u53f7\u5728\u5b50\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u76f8\u90bb\u5143\u7d20\u5bf9\u4e4b\u95f4\u7ffb\u8f6c\uff0c\u5219\u8be5\u5b50\u6570\u7ec4\u662f\u6e4d\u6d41\u5b50\u6570\u7ec4\u3002

    \n\n

    \u8fd4\u56de A \u7684\u6700\u5927\u6e4d\u6d41\u5b50\u6570\u7ec4\u7684\u957f\u5ea6\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a[9,4,2,10,7,8,8,1,9]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a(A[1] > A[2] < A[3] > A[4] < A[5])\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a[4,8,12,16]\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1a[100]\n\u8f93\u51fa\uff1a1\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= A.length <= 40000
    2. \n\t
    3. 0 <= A[i] <= 10^9
    4. \n
    \n", "tags_en": ["Array", "Dynamic Programming", "Sliding Window"], "tags_cn": ["\u6570\u7ec4", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxTurbulenceSize(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxTurbulenceSize(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxTurbulenceSize(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxTurbulenceSize(self, arr: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxTurbulenceSize(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxTurbulenceSize(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar maxTurbulenceSize = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef max_turbulence_size(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxTurbulenceSize(_ arr: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxTurbulenceSize(arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxTurbulenceSize(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxTurbulenceSize(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_turbulence_size(arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function maxTurbulenceSize($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxTurbulenceSize(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-turbulence-size arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0978](https://leetcode-cn.com/problems/longest-turbulent-subarray)", "[\u6700\u957f\u6e4d\u6d41\u5b50\u6570\u7ec4](/solution/0900-0999/0978.Longest%20Turbulent%20Subarray/README.md)", "`\u6570\u7ec4`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0978](https://leetcode.com/problems/longest-turbulent-subarray)", "[Longest Turbulent Subarray](/solution/0900-0999/0978.Longest%20Turbulent%20Subarray/README_EN.md)", "`Array`,`Dynamic Programming`,`Sliding Window`", "Medium", ""]}, {"question_id": "1019", "frontend_question_id": "0977", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/squares-of-a-sorted-array", "url_en": "https://leetcode.com/problems/squares-of-a-sorted-array", "relative_path_cn": "/solution/0900-0999/0977.Squares%20of%20a%20Sorted%20Array/README.md", "relative_path_en": "/solution/0900-0999/0977.Squares%20of%20a%20Sorted%20Array/README_EN.md", "title_cn": "\u6709\u5e8f\u6570\u7ec4\u7684\u5e73\u65b9", "title_en": "Squares of a Sorted Array", "question_title_slug": "squares-of-a-sorted-array", "content_en": "

    Given an integer array nums sorted in non-decreasing order, return an array of the squares of each number sorted in non-decreasing order.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [-4,-1,0,3,10]\nOutput: [0,1,9,16,100]\nExplanation: After squaring, the array becomes [16,1,0,9,100].\nAfter sorting, it becomes [0,1,9,16,100].\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [-7,-3,2,3,11]\nOutput: [4,9,9,49,121]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 104
    • \n\t
    • -104 <= nums[i] <= 104
    • \n\t
    • nums is sorted in non-decreasing order.
    • \n
    \n\n

     

    \nFollow up: Squaring each element and sorting the new array is very trivial, could you find an O(n) solution using a different approach?", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6309 \u975e\u9012\u51cf\u987a\u5e8f \u6392\u5e8f\u7684\u6574\u6570\u6570\u7ec4 nums\uff0c\u8fd4\u56de \u6bcf\u4e2a\u6570\u5b57\u7684\u5e73\u65b9 \u7ec4\u6210\u7684\u65b0\u6570\u7ec4\uff0c\u8981\u6c42\u4e5f\u6309 \u975e\u9012\u51cf\u987a\u5e8f \u6392\u5e8f\u3002

    \n\n
      \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [-4,-1,0,3,10]\n\u8f93\u51fa\uff1a[0,1,9,16,100]\n\u89e3\u91ca\uff1a\u5e73\u65b9\u540e\uff0c\u6570\u7ec4\u53d8\u4e3a [16,1,0,9,100]\n\u6392\u5e8f\u540e\uff0c\u6570\u7ec4\u53d8\u4e3a [0,1,9,16,100]
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [-7,-3,2,3,11]\n\u8f93\u51fa\uff1a[4,9,9,49,121]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 104
    • \n\t
    • -104 <= nums[i] <= 104
    • \n\t
    • nums \u5df2\u6309 \u975e\u9012\u51cf\u987a\u5e8f \u6392\u5e8f
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u8bf7\u4f60\u8bbe\u8ba1\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n) \u7684\u7b97\u6cd5\u89e3\u51b3\u672c\u95ee\u9898
    • \n
    \n", "tags_en": ["Array", "Two Pointers"], "tags_cn": ["\u6570\u7ec4", "\u53cc\u6307\u9488"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector sortedSquares(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] sortedSquares(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def sortedSquares(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def sortedSquares(self, nums: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* sortedSquares(int* nums, int numsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] SortedSquares(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar sortedSquares = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer[]}\ndef sorted_squares(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func sortedSquares(_ nums: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func sortedSquares(nums []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def sortedSquares(nums: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun sortedSquares(nums: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sorted_squares(nums: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer[]\n */\n function sortedSquares($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function sortedSquares(nums: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (sorted-squares nums)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0977](https://leetcode-cn.com/problems/squares-of-a-sorted-array)", "[\u6709\u5e8f\u6570\u7ec4\u7684\u5e73\u65b9](/solution/0900-0999/0977.Squares%20of%20a%20Sorted%20Array/README.md)", "`\u6570\u7ec4`,`\u53cc\u6307\u9488`", "\u7b80\u5355", ""], "md_table_row_en": ["[0977](https://leetcode.com/problems/squares-of-a-sorted-array)", "[Squares of a Sorted Array](/solution/0900-0999/0977.Squares%20of%20a%20Sorted%20Array/README_EN.md)", "`Array`,`Two Pointers`", "Easy", ""]}, {"question_id": "1018", "frontend_question_id": "0976", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/largest-perimeter-triangle", "url_en": "https://leetcode.com/problems/largest-perimeter-triangle", "relative_path_cn": "/solution/0900-0999/0976.Largest%20Perimeter%20Triangle/README.md", "relative_path_en": "/solution/0900-0999/0976.Largest%20Perimeter%20Triangle/README_EN.md", "title_cn": "\u4e09\u89d2\u5f62\u7684\u6700\u5927\u5468\u957f", "title_en": "Largest Perimeter Triangle", "question_title_slug": "largest-perimeter-triangle", "content_en": "

    Given an integer array nums, return the largest perimeter of a triangle with a non-zero area, formed from three of these lengths. If it is impossible to form any triangle of a non-zero area, return 0.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [2,1,2]\nOutput: 5\n

    Example 2:

    \n
    Input: nums = [1,2,1]\nOutput: 0\n

    Example 3:

    \n
    Input: nums = [3,2,3,4]\nOutput: 10\n

    Example 4:

    \n
    Input: nums = [3,6,2,3]\nOutput: 8\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 3 <= nums.length <= 104
    • \n\t
    • 1 <= nums[i] <= 106
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u7531\u4e00\u4e9b\u6b63\u6570\uff08\u4ee3\u8868\u957f\u5ea6\uff09\u7ec4\u6210\u7684\u6570\u7ec4 A\uff0c\u8fd4\u56de\u7531\u5176\u4e2d\u4e09\u4e2a\u957f\u5ea6\u7ec4\u6210\u7684\u3001\u9762\u79ef\u4e0d\u4e3a\u96f6\u7684\u4e09\u89d2\u5f62\u7684\u6700\u5927\u5468\u957f\u3002

    \n\n

    \u5982\u679c\u4e0d\u80fd\u5f62\u6210\u4efb\u4f55\u9762\u79ef\u4e0d\u4e3a\u96f6\u7684\u4e09\u89d2\u5f62\uff0c\u8fd4\u56de 0\u3002

    \n\n

     

    \n\n
      \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a[2,1,2]\n\u8f93\u51fa\uff1a5\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a[1,2,1]\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1a[3,2,3,4]\n\u8f93\u51fa\uff1a10\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1a[3,6,2,3]\n\u8f93\u51fa\uff1a8\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 3 <= A.length <= 10000
    2. \n\t
    3. 1 <= A[i] <= 10^6
    4. \n
    \n", "tags_en": ["Sort", "Math"], "tags_cn": ["\u6392\u5e8f", "\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int largestPerimeter(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int largestPerimeter(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def largestPerimeter(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def largestPerimeter(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint largestPerimeter(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LargestPerimeter(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar largestPerimeter = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef largest_perimeter(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func largestPerimeter(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func largestPerimeter(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def largestPerimeter(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun largestPerimeter(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn largest_perimeter(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function largestPerimeter($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function largestPerimeter(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (largest-perimeter nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0976](https://leetcode-cn.com/problems/largest-perimeter-triangle)", "[\u4e09\u89d2\u5f62\u7684\u6700\u5927\u5468\u957f](/solution/0900-0999/0976.Largest%20Perimeter%20Triangle/README.md)", "`\u6392\u5e8f`,`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0976](https://leetcode.com/problems/largest-perimeter-triangle)", "[Largest Perimeter Triangle](/solution/0900-0999/0976.Largest%20Perimeter%20Triangle/README_EN.md)", "`Sort`,`Math`", "Easy", ""]}, {"question_id": "1017", "frontend_question_id": "0975", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/odd-even-jump", "url_en": "https://leetcode.com/problems/odd-even-jump", "relative_path_cn": "/solution/0900-0999/0975.Odd%20Even%20Jump/README.md", "relative_path_en": "/solution/0900-0999/0975.Odd%20Even%20Jump/README_EN.md", "title_cn": "\u5947\u5076\u8df3", "title_en": "Odd Even Jump", "question_title_slug": "odd-even-jump", "content_en": "

    You are given an integer array arr. From some starting index, you can make a series of jumps. The (1st, 3rd, 5th, ...) jumps in the series are called odd-numbered jumps, and the (2nd, 4th, 6th, ...) jumps in the series are called even-numbered jumps. Note that the jumps are numbered, not the indices.

    \n\n

    You may jump forward from index i to index j (with i < j) in the following way:

    \n\n
      \n\t
    • During odd-numbered jumps (i.e., jumps 1, 3, 5, ...), you jump to the index j such that arr[i] <= arr[j] and arr[j] is the smallest possible value. If there are multiple such indices j, you can only jump to the smallest such index j.
    • \n\t
    • During even-numbered jumps (i.e., jumps 2, 4, 6, ...), you jump to the index j such that arr[i] >= arr[j] and arr[j] is the largest possible value. If there are multiple such indices j, you can only jump to the smallest such index j.
    • \n\t
    • It may be the case that for some index i, there are no legal jumps.
    • \n
    \n\n

    A starting index is good if, starting from that index, you can reach the end of the array (index arr.length - 1) by jumping some number of times (possibly 0 or more than once).

    \n\n

    Return the number of good starting indices.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr = [10,13,12,14,15]\nOutput: 2\nExplanation: \nFrom starting index i = 0, we can make our 1st jump to i = 2 (since arr[2] is the smallest among arr[1], arr[2], arr[3], arr[4] that is greater or equal to arr[0]), then we cannot jump any more.\nFrom starting index i = 1 and i = 2, we can make our 1st jump to i = 3, then we cannot jump any more.\nFrom starting index i = 3, we can make our 1st jump to i = 4, so we have reached the end.\nFrom starting index i = 4, we have reached the end already.\nIn total, there are 2 different starting indices i = 3 and i = 4, where we can reach the end with some number of\njumps.\n
    \n\n

    Example 2:

    \n\n
    \nInput: arr = [2,3,1,1,4]\nOutput: 3\nExplanation: \nFrom starting index i = 0, we make jumps to i = 1, i = 2, i = 3:\nDuring our 1st jump (odd-numbered), we first jump to i = 1 because arr[1] is the smallest value in [arr[1], arr[2], arr[3], arr[4]] that is greater than or equal to arr[0].\nDuring our 2nd jump (even-numbered), we jump from i = 1 to i = 2 because arr[2] is the largest value in [arr[2], arr[3], arr[4]] that is less than or equal to arr[1]. arr[3] is also the largest value, but 2 is a smaller index, so we can only jump to i = 2 and not i = 3\nDuring our 3rd jump (odd-numbered), we jump from i = 2 to i = 3 because arr[3] is the smallest value in [arr[3], arr[4]] that is greater than or equal to arr[2].\nWe can't jump from i = 3 to i = 4, so the starting index i = 0 is not good.\nIn a similar manner, we can deduce that:\nFrom starting index i = 1, we jump to i = 4, so we reach the end.\nFrom starting index i = 2, we jump to i = 3, and then we can't jump anymore.\nFrom starting index i = 3, we jump to i = 4, so we reach the end.\nFrom starting index i = 4, we are already at the end.\nIn total, there are 3 different starting indices i = 1, i = 3, and i = 4, where we can reach the end with some\nnumber of jumps.\n
    \n\n

    Example 3:

    \n\n
    \nInput: arr = [5,1,3,4,2]\nOutput: 3\nExplanation: We can reach the end from starting indices 1, 2, and 4.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= arr.length <= 2 * 104
    • \n\t
    • 0 <= arr[i] < 105
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 A\uff0c\u4f60\u53ef\u4ee5\u4ece\u67d0\u4e00\u8d77\u59cb\u7d22\u5f15\u51fa\u53d1\uff0c\u8df3\u8dc3\u4e00\u5b9a\u6b21\u6570\u3002\u5728\u4f60\u8df3\u8dc3\u7684\u8fc7\u7a0b\u4e2d\uff0c\u7b2c 1\u30013\u30015... \u6b21\u8df3\u8dc3\u79f0\u4e3a\u5947\u6570\u8df3\u8dc3\uff0c\u800c\u7b2c 2\u30014\u30016... \u6b21\u8df3\u8dc3\u79f0\u4e3a\u5076\u6570\u8df3\u8dc3\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u6309\u4ee5\u4e0b\u65b9\u5f0f\u4ece\u7d22\u5f15 i \u5411\u540e\u8df3\u8f6c\u5230\u7d22\u5f15 j\uff08\u5176\u4e2d i < j\uff09\uff1a

    \n\n
      \n\t
    • \u5728\u8fdb\u884c\u5947\u6570\u8df3\u8dc3\u65f6\uff08\u5982\uff0c\u7b2c 1\uff0c3\uff0c5... \u6b21\u8df3\u8dc3\uff09\uff0c\u4f60\u5c06\u4f1a\u8df3\u5230\u7d22\u5f15 j\uff0c\u4f7f\u5f97 A[i] <= A[j]\uff0cA[j] \u662f\u53ef\u80fd\u7684\u6700\u5c0f\u503c\u3002\u5982\u679c\u5b58\u5728\u591a\u4e2a\u8fd9\u6837\u7684\u7d22\u5f15 j\uff0c\u4f60\u53ea\u80fd\u8df3\u5230\u6ee1\u8db3\u8981\u6c42\u7684\u6700\u5c0f\u7d22\u5f15 j \u4e0a\u3002
    • \n\t
    • \u5728\u8fdb\u884c\u5076\u6570\u8df3\u8dc3\u65f6\uff08\u5982\uff0c\u7b2c 2\uff0c4\uff0c6... \u6b21\u8df3\u8dc3\uff09\uff0c\u4f60\u5c06\u4f1a\u8df3\u5230\u7d22\u5f15 j\uff0c\u4f7f\u5f97 A[i] >= A[j]\uff0cA[j] \u662f\u53ef\u80fd\u7684\u6700\u5927\u503c\u3002\u5982\u679c\u5b58\u5728\u591a\u4e2a\u8fd9\u6837\u7684\u7d22\u5f15 j\uff0c\u4f60\u53ea\u80fd\u8df3\u5230\u6ee1\u8db3\u8981\u6c42\u7684\u6700\u5c0f\u7d22\u5f15 j \u4e0a\u3002
    • \n\t
    • \uff08\u5bf9\u4e8e\u67d0\u4e9b\u7d22\u5f15 i\uff0c\u53ef\u80fd\u65e0\u6cd5\u8fdb\u884c\u5408\u4e4e\u8981\u6c42\u7684\u8df3\u8dc3\u3002\uff09
    • \n
    \n\n

    \u5982\u679c\u4ece\u67d0\u4e00\u7d22\u5f15\u5f00\u59cb\u8df3\u8dc3\u4e00\u5b9a\u6b21\u6570\uff08\u53ef\u80fd\u662f 0 \u6b21\u6216\u591a\u6b21\uff09\uff0c\u5c31\u53ef\u4ee5\u5230\u8fbe\u6570\u7ec4\u7684\u672b\u5c3e\uff08\u7d22\u5f15 A.length - 1\uff09\uff0c\u90a3\u4e48\u8be5\u7d22\u5f15\u5c31\u4f1a\u88ab\u8ba4\u4e3a\u662f\u597d\u7684\u8d77\u59cb\u7d22\u5f15\u3002

    \n\n

    \u8fd4\u56de\u597d\u7684\u8d77\u59cb\u7d22\u5f15\u7684\u6570\u91cf\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a[10,13,12,14,15]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a \n\u4ece\u8d77\u59cb\u7d22\u5f15 i = 0 \u51fa\u53d1\uff0c\u6211\u4eec\u53ef\u4ee5\u8df3\u5230 i = 2\uff0c\uff08\u56e0\u4e3a A[2] \u662f A[1]\uff0cA[2]\uff0cA[3]\uff0cA[4] \u4e2d\u5927\u4e8e\u6216\u7b49\u4e8e A[0] \u7684\u6700\u5c0f\u503c\uff09\uff0c\u7136\u540e\u6211\u4eec\u5c31\u65e0\u6cd5\u7ee7\u7eed\u8df3\u4e0b\u53bb\u4e86\u3002\n\u4ece\u8d77\u59cb\u7d22\u5f15 i = 1 \u548c i = 2 \u51fa\u53d1\uff0c\u6211\u4eec\u53ef\u4ee5\u8df3\u5230 i = 3\uff0c\u7136\u540e\u6211\u4eec\u5c31\u65e0\u6cd5\u7ee7\u7eed\u8df3\u4e0b\u53bb\u4e86\u3002\n\u4ece\u8d77\u59cb\u7d22\u5f15 i = 3 \u51fa\u53d1\uff0c\u6211\u4eec\u53ef\u4ee5\u8df3\u5230 i = 4\uff0c\u5230\u8fbe\u6570\u7ec4\u672b\u5c3e\u3002\n\u4ece\u8d77\u59cb\u7d22\u5f15 i = 4 \u51fa\u53d1\uff0c\u6211\u4eec\u5df2\u7ecf\u5230\u8fbe\u6570\u7ec4\u672b\u5c3e\u3002\n\u603b\u4e4b\uff0c\u6211\u4eec\u53ef\u4ee5\u4ece 2 \u4e2a\u4e0d\u540c\u7684\u8d77\u59cb\u7d22\u5f15\uff08i = 3, i = 4\uff09\u51fa\u53d1\uff0c\u901a\u8fc7\u4e00\u5b9a\u6570\u91cf\u7684\u8df3\u8dc3\u5230\u8fbe\u6570\u7ec4\u672b\u5c3e\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a[2,3,1,1,4]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\n\u4ece\u8d77\u59cb\u7d22\u5f15 i=0 \u51fa\u53d1\uff0c\u6211\u4eec\u4f9d\u6b21\u53ef\u4ee5\u8df3\u5230 i = 1\uff0ci = 2\uff0ci = 3\uff1a\n\n\u5728\u6211\u4eec\u7684\u7b2c\u4e00\u6b21\u8df3\u8dc3\uff08\u5947\u6570\uff09\u4e2d\uff0c\u6211\u4eec\u5148\u8df3\u5230 i = 1\uff0c\u56e0\u4e3a A[1] \u662f\uff08A[1]\uff0cA[2]\uff0cA[3]\uff0cA[4]\uff09\u4e2d\u5927\u4e8e\u6216\u7b49\u4e8e A[0] \u7684\u6700\u5c0f\u503c\u3002\n\n\u5728\u6211\u4eec\u7684\u7b2c\u4e8c\u6b21\u8df3\u8dc3\uff08\u5076\u6570\uff09\u4e2d\uff0c\u6211\u4eec\u4ece i = 1 \u8df3\u5230 i = 2\uff0c\u56e0\u4e3a A[2] \u662f\uff08A[2]\uff0cA[3]\uff0cA[4]\uff09\u4e2d\u5c0f\u4e8e\u6216\u7b49\u4e8e A[1] \u7684\u6700\u5927\u503c\u3002A[3] \u4e5f\u662f\u6700\u5927\u7684\u503c\uff0c\u4f46 2 \u662f\u4e00\u4e2a\u8f83\u5c0f\u7684\u7d22\u5f15\uff0c\u6240\u4ee5\u6211\u4eec\u53ea\u80fd\u8df3\u5230 i = 2\uff0c\u800c\u4e0d\u80fd\u8df3\u5230 i = 3\u3002\n\n\u5728\u6211\u4eec\u7684\u7b2c\u4e09\u6b21\u8df3\u8dc3\uff08\u5947\u6570\uff09\u4e2d\uff0c\u6211\u4eec\u4ece i = 2 \u8df3\u5230 i = 3\uff0c\u56e0\u4e3a A[3] \u662f\uff08A[3]\uff0cA[4]\uff09\u4e2d\u5927\u4e8e\u6216\u7b49\u4e8e A[2] \u7684\u6700\u5c0f\u503c\u3002\n\n\u6211\u4eec\u4e0d\u80fd\u4ece i = 3 \u8df3\u5230 i = 4\uff0c\u6240\u4ee5\u8d77\u59cb\u7d22\u5f15 i = 0 \u4e0d\u662f\u597d\u7684\u8d77\u59cb\u7d22\u5f15\u3002\n\n\u7c7b\u4f3c\u5730\uff0c\u6211\u4eec\u53ef\u4ee5\u63a8\u65ad\uff1a\n\u4ece\u8d77\u59cb\u7d22\u5f15 i = 1 \u51fa\u53d1\uff0c \u6211\u4eec\u8df3\u5230 i = 4\uff0c\u8fd9\u6837\u6211\u4eec\u5c31\u5230\u8fbe\u6570\u7ec4\u672b\u5c3e\u3002\n\u4ece\u8d77\u59cb\u7d22\u5f15 i = 2 \u51fa\u53d1\uff0c \u6211\u4eec\u8df3\u5230 i = 3\uff0c\u7136\u540e\u6211\u4eec\u5c31\u4e0d\u80fd\u518d\u8df3\u4e86\u3002\n\u4ece\u8d77\u59cb\u7d22\u5f15 i = 3 \u51fa\u53d1\uff0c \u6211\u4eec\u8df3\u5230 i = 4\uff0c\u8fd9\u6837\u6211\u4eec\u5c31\u5230\u8fbe\u6570\u7ec4\u672b\u5c3e\u3002\n\u4ece\u8d77\u59cb\u7d22\u5f15 i = 4 \u51fa\u53d1\uff0c\u6211\u4eec\u5df2\u7ecf\u5230\u8fbe\u6570\u7ec4\u672b\u5c3e\u3002\n\u603b\u4e4b\uff0c\u6211\u4eec\u53ef\u4ee5\u4ece 3 \u4e2a\u4e0d\u540c\u7684\u8d77\u59cb\u7d22\u5f15\uff08i = 1, i = 3, i = 4\uff09\u51fa\u53d1\uff0c\u901a\u8fc7\u4e00\u5b9a\u6570\u91cf\u7684\u8df3\u8dc3\u5230\u8fbe\u6570\u7ec4\u672b\u5c3e\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1a[5,1,3,4,2]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a \n\u6211\u4eec\u53ef\u4ee5\u4ece\u8d77\u59cb\u7d22\u5f15 1\uff0c2\uff0c4 \u51fa\u53d1\u5230\u8fbe\u6570\u7ec4\u672b\u5c3e\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= A.length <= 20000
    2. \n\t
    3. 0 <= A[i] < 100000
    4. \n
    \n", "tags_en": ["Stack", "Dynamic Programming", "Ordered Map"], "tags_cn": ["\u6808", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int oddEvenJumps(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int oddEvenJumps(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def oddEvenJumps(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def oddEvenJumps(self, arr: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint oddEvenJumps(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int OddEvenJumps(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar oddEvenJumps = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef odd_even_jumps(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func oddEvenJumps(_ arr: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func oddEvenJumps(arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def oddEvenJumps(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun oddEvenJumps(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn odd_even_jumps(arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function oddEvenJumps($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function oddEvenJumps(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (odd-even-jumps arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0975](https://leetcode-cn.com/problems/odd-even-jump)", "[\u5947\u5076\u8df3](/solution/0900-0999/0975.Odd%20Even%20Jump/README.md)", "`\u6808`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0975](https://leetcode.com/problems/odd-even-jump)", "[Odd Even Jump](/solution/0900-0999/0975.Odd%20Even%20Jump/README_EN.md)", "`Stack`,`Dynamic Programming`,`Ordered Map`", "Hard", ""]}, {"question_id": "1016", "frontend_question_id": "0974", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/subarray-sums-divisible-by-k", "url_en": "https://leetcode.com/problems/subarray-sums-divisible-by-k", "relative_path_cn": "/solution/0900-0999/0974.Subarray%20Sums%20Divisible%20by%20K/README.md", "relative_path_en": "/solution/0900-0999/0974.Subarray%20Sums%20Divisible%20by%20K/README_EN.md", "title_cn": "\u548c\u53ef\u88ab K \u6574\u9664\u7684\u5b50\u6570\u7ec4", "title_en": "Subarray Sums Divisible by K", "question_title_slug": "subarray-sums-divisible-by-k", "content_en": "

    Given an array nums of integers, return the number of (contiguous, non-empty) subarrays that have a sum divisible by k.

    \n\n

     

    \n\n
    \n

    Example 1:

    \n\n
    \nInput: nums = [4,5,0,-2,-3,1], k = 5\nOutput: 7\nExplanation: There are 7 subarrays with a sum divisible by k = 5:\n[4, 5, 0, -2, -3, 1], [5], [5, 0], [5, 0, -2, -3], [0], [0, -2, -3], [-2, -3]\n
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    1. 1 <= nums.length <= 30000
    2. \n\t
    3. -10000 <= nums[i] <= 10000
    4. \n\t
    5. 2 <= k <= 10000
    6. \n
    \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 A\uff0c\u8fd4\u56de\u5176\u4e2d\u5143\u7d20\u4e4b\u548c\u53ef\u88ab K \u6574\u9664\u7684\uff08\u8fde\u7eed\u3001\u975e\u7a7a\uff09\u5b50\u6570\u7ec4\u7684\u6570\u76ee\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1aA = [4,5,0,-2,-3,1], K = 5\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\n\u6709 7 \u4e2a\u5b50\u6570\u7ec4\u6ee1\u8db3\u5176\u5143\u7d20\u4e4b\u548c\u53ef\u88ab K = 5 \u6574\u9664\uff1a\n[4, 5, 0, -2, -3, 1], [5], [5, 0], [5, 0, -2, -3], [0], [0, -2, -3], [-2, -3]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= A.length <= 30000
    2. \n\t
    3. -10000 <= A[i] <= 10000
    4. \n\t
    5. 2 <= K <= 10000
    6. \n
    \n", "tags_en": ["Array", "Hash Table"], "tags_cn": ["\u6570\u7ec4", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int subarraysDivByK(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int subarraysDivByK(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def subarraysDivByK(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def subarraysDivByK(self, nums: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint subarraysDivByK(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SubarraysDivByK(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar subarraysDivByK = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef subarrays_div_by_k(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func subarraysDivByK(_ nums: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func subarraysDivByK(nums []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def subarraysDivByK(nums: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun subarraysDivByK(nums: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn subarrays_div_by_k(nums: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer\n */\n function subarraysDivByK($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function subarraysDivByK(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (subarrays-div-by-k nums k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0974](https://leetcode-cn.com/problems/subarray-sums-divisible-by-k)", "[\u548c\u53ef\u88ab K \u6574\u9664\u7684\u5b50\u6570\u7ec4](/solution/0900-0999/0974.Subarray%20Sums%20Divisible%20by%20K/README.md)", "`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0974](https://leetcode.com/problems/subarray-sums-divisible-by-k)", "[Subarray Sums Divisible by K](/solution/0900-0999/0974.Subarray%20Sums%20Divisible%20by%20K/README_EN.md)", "`Array`,`Hash Table`", "Medium", ""]}, {"question_id": "1014", "frontend_question_id": "0973", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/k-closest-points-to-origin", "url_en": "https://leetcode.com/problems/k-closest-points-to-origin", "relative_path_cn": "/solution/0900-0999/0973.K%20Closest%20Points%20to%20Origin/README.md", "relative_path_en": "/solution/0900-0999/0973.K%20Closest%20Points%20to%20Origin/README_EN.md", "title_cn": "\u6700\u63a5\u8fd1\u539f\u70b9\u7684 K \u4e2a\u70b9", "title_en": "K Closest Points to Origin", "question_title_slug": "k-closest-points-to-origin", "content_en": "

    Given an array of points where points[i] = [xi, yi] represents a point on the X-Y plane and an integer k, return the k closest points to the origin (0, 0).

    \n\n

    The distance between two points on the X-Y plane is the Euclidean distance (i.e., √(x1 - x2)2 + (y1 - y2)2).

    \n\n

    You may return the answer in any order. The answer is guaranteed to be unique (except for the order that it is in).

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: points = [[1,3],[-2,2]], k = 1\nOutput: [[-2,2]]\nExplanation:\nThe distance between (1, 3) and the origin is sqrt(10).\nThe distance between (-2, 2) and the origin is sqrt(8).\nSince sqrt(8) < sqrt(10), (-2, 2) is closer to the origin.\nWe only want the closest k = 1 points from the origin, so the answer is just [[-2,2]].\n
    \n\n

    Example 2:

    \n\n
    \nInput: points = [[3,3],[5,-1],[-2,4]], k = 2\nOutput: [[3,3],[-2,4]]\nExplanation: The answer [[-2,4],[3,3]] would also be accepted.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= k <= points.length <= 104
    • \n\t
    • -104 < xi, yi < 104
    • \n
    \n", "content_cn": "

    \u6211\u4eec\u6709\u4e00\u4e2a\u7531\u5e73\u9762\u4e0a\u7684\u70b9\u7ec4\u6210\u7684\u5217\u8868 points\u3002\u9700\u8981\u4ece\u4e2d\u627e\u51fa K \u4e2a\u8ddd\u79bb\u539f\u70b9 (0, 0) \u6700\u8fd1\u7684\u70b9\u3002

    \n\n

    \uff08\u8fd9\u91cc\uff0c\u5e73\u9762\u4e0a\u4e24\u70b9\u4e4b\u95f4\u7684\u8ddd\u79bb\u662f\u6b27\u51e0\u91cc\u5fb7\u8ddd\u79bb\u3002\uff09

    \n\n

    \u4f60\u53ef\u4ee5\u6309\u4efb\u4f55\u987a\u5e8f\u8fd4\u56de\u7b54\u6848\u3002\u9664\u4e86\u70b9\u5750\u6807\u7684\u987a\u5e8f\u4e4b\u5916\uff0c\u7b54\u6848\u786e\u4fdd\u662f\u552f\u4e00\u7684\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1apoints = [[1,3],[-2,2]], K = 1\n\u8f93\u51fa\uff1a[[-2,2]]\n\u89e3\u91ca\uff1a \n(1, 3) \u548c\u539f\u70b9\u4e4b\u95f4\u7684\u8ddd\u79bb\u4e3a sqrt(10)\uff0c\n(-2, 2) \u548c\u539f\u70b9\u4e4b\u95f4\u7684\u8ddd\u79bb\u4e3a sqrt(8)\uff0c\n\u7531\u4e8e sqrt(8) < sqrt(10)\uff0c(-2, 2) \u79bb\u539f\u70b9\u66f4\u8fd1\u3002\n\u6211\u4eec\u53ea\u9700\u8981\u8ddd\u79bb\u539f\u70b9\u6700\u8fd1\u7684 K = 1 \u4e2a\u70b9\uff0c\u6240\u4ee5\u7b54\u6848\u5c31\u662f [[-2,2]]\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1apoints = [[3,3],[5,-1],[-2,4]], K = 2\n\u8f93\u51fa\uff1a[[3,3],[-2,4]]\n\uff08\u7b54\u6848 [[-2,4],[3,3]] \u4e5f\u4f1a\u88ab\u63a5\u53d7\u3002\uff09\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= K <= points.length <= 10000
    2. \n\t
    3. -10000 < points[i][0] < 10000
    4. \n\t
    5. -10000 < points[i][1] < 10000
    6. \n
    \n", "tags_en": ["Heap", "Sort", "Divide and Conquer"], "tags_cn": ["\u5806", "\u6392\u5e8f", "\u5206\u6cbb\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> kClosest(vector>& points, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[][] kClosest(int[][] points, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def kClosest(self, points, k):\n \"\"\"\n :type points: List[List[int]]\n :type k: int\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def kClosest(self, points: List[List[int]], k: int) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** kClosest(int** points, int pointsSize, int* pointsColSize, int k, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[][] KClosest(int[][] points, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} points\n * @param {number} k\n * @return {number[][]}\n */\nvar kClosest = function(points, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} points\n# @param {Integer} k\n# @return {Integer[][]}\ndef k_closest(points, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func kClosest(_ points: [[Int]], _ k: Int) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func kClosest(points [][]int, k int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def kClosest(points: Array[Array[Int]], k: Int): Array[Array[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun kClosest(points: Array, k: Int): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn k_closest(points: Vec>, k: i32) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $points\n * @param Integer $k\n * @return Integer[][]\n */\n function kClosest($points, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function kClosest(points: number[][], k: number): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (k-closest points k)\n (-> (listof (listof exact-integer?)) exact-integer? (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0973](https://leetcode-cn.com/problems/k-closest-points-to-origin)", "[\u6700\u63a5\u8fd1\u539f\u70b9\u7684 K \u4e2a\u70b9](/solution/0900-0999/0973.K%20Closest%20Points%20to%20Origin/README.md)", "`\u5806`,`\u6392\u5e8f`,`\u5206\u6cbb\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0973](https://leetcode.com/problems/k-closest-points-to-origin)", "[K Closest Points to Origin](/solution/0900-0999/0973.K%20Closest%20Points%20to%20Origin/README_EN.md)", "`Heap`,`Sort`,`Divide and Conquer`", "Medium", ""]}, {"question_id": "1013", "frontend_question_id": "0509", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/fibonacci-number", "url_en": "https://leetcode.com/problems/fibonacci-number", "relative_path_cn": "/solution/0500-0599/0509.Fibonacci%20Number/README.md", "relative_path_en": "/solution/0500-0599/0509.Fibonacci%20Number/README_EN.md", "title_cn": "\u6590\u6ce2\u90a3\u5951\u6570", "title_en": "Fibonacci Number", "question_title_slug": "fibonacci-number", "content_en": "

    The Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1. That is,

    \n\n
    \nF(0) = 0, F(1) = 1\nF(n) = F(n - 1) + F(n - 2), for n > 1.\n
    \n\n

    Given n, calculate F(n).

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 2\nOutput: 1\nExplanation: F(2) = F(1) + F(0) = 1 + 0 = 1.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 3\nOutput: 2\nExplanation: F(3) = F(2) + F(1) = 1 + 1 = 2.\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 4\nOutput: 3\nExplanation: F(4) = F(3) + F(2) = 2 + 1 = 3.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= n <= 30
    • \n
    \n", "content_cn": "

    \u6590\u6ce2\u90a3\u5951\u6570\uff0c\u901a\u5e38\u7528\u00a0F(n) \u8868\u793a\uff0c\u5f62\u6210\u7684\u5e8f\u5217\u79f0\u4e3a \u6590\u6ce2\u90a3\u5951\u6570\u5217 \u3002\u8be5\u6570\u5217\u7531\u00a00 \u548c 1 \u5f00\u59cb\uff0c\u540e\u9762\u7684\u6bcf\u4e00\u9879\u6570\u5b57\u90fd\u662f\u524d\u9762\u4e24\u9879\u6570\u5b57\u7684\u548c\u3002\u4e5f\u5c31\u662f\uff1a

    \n\n
    \nF(0) = 0\uff0cF(1)\u00a0= 1\nF(n) = F(n - 1) + F(n - 2)\uff0c\u5176\u4e2d n > 1\n
    \n\n

    \u7ed9\u4f60 n \uff0c\u8bf7\u8ba1\u7b97 F(n) \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1a2\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1aF(2) = F(1) + F(0) = 1 + 0 = 1\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1a3\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1aF(3) = F(2) + F(1) = 1 + 1 = 2\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1a4\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1aF(4) = F(3) + F(2) = 2 + 1 = 3\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= n <= 30
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int fib(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int fib(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def fib(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def fib(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint fib(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int Fib(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar fib = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef fib(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func fib(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func fib(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def fib(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun fib(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn fib(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function fib($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function fib(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (fib n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0509](https://leetcode-cn.com/problems/fibonacci-number)", "[\u6590\u6ce2\u90a3\u5951\u6570](/solution/0500-0599/0509.Fibonacci%20Number/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0509](https://leetcode.com/problems/fibonacci-number)", "[Fibonacci Number](/solution/0500-0599/0509.Fibonacci%20Number/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "1012", "frontend_question_id": "0972", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/equal-rational-numbers", "url_en": "https://leetcode.com/problems/equal-rational-numbers", "relative_path_cn": "/solution/0900-0999/0972.Equal%20Rational%20Numbers/README.md", "relative_path_en": "/solution/0900-0999/0972.Equal%20Rational%20Numbers/README_EN.md", "title_cn": "\u76f8\u7b49\u7684\u6709\u7406\u6570", "title_en": "Equal Rational Numbers", "question_title_slug": "equal-rational-numbers", "content_en": "

    Given two strings s and t, each of which represents a non-negative rational number, return true if and only if they represent the same number. The strings may use parentheses to denote the repeating part of the rational number.

    \n\n

    A rational number can be represented using up to three parts: <IntegerPart>, <NonRepeatingPart>, and a <RepeatingPart>. The number will be represented in one of the following three ways:

    \n\n
      \n\t
    • <IntegerPart>\n\n\t
        \n\t\t
      • For example, 12, 0, and 123.
      • \n\t
      \n\t
    • \n\t
    • <IntegerPart><.><NonRepeatingPart>\n\t
        \n\t\t
      • For example, 0.5, 1., 2.12, and 123.0001.
      • \n\t
      \n\t
    • \n\t
    • <IntegerPart><.><NonRepeatingPart><(><RepeatingPart><)>\n\t
        \n\t\t
      • For example, 0.1(6), 1.(9), 123.00(1212).
      • \n\t
      \n\t
    • \n
    \n\n

    The repeating portion of a decimal expansion is conventionally denoted within a pair of round brackets. For example:

    \n\n
      \n\t
    • 1/6 = 0.16666666... = 0.1(6) = 0.1666(6) = 0.166(66).
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "0.(52)", t = "0.5(25)"\nOutput: true\nExplanation: Because "0.(52)" represents 0.52525252..., and "0.5(25)" represents 0.52525252525..... , the strings represent the same number.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "0.1666(6)", t = "0.166(66)"\nOutput: true\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "0.9(9)", t = "1."\nOutput: true\nExplanation: "0.9(9)" represents 0.999999999... repeated forever, which equals 1.  [See this link for an explanation.]\n"1." represents the number 1, which is formed correctly: (IntegerPart) = "1" and (NonRepeatingPart) = "".\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • Each part consists only of digits.
    • \n\t
    • The <IntegerPart> does not have leading zeros (except for the zero itself).
    • \n\t
    • 1 <= <IntegerPart>.length <= 4
    • \n\t
    • 0 <= <NonRepeatingPart>.length <= 4
    • \n\t
    • 1 <= <RepeatingPart>.length <= 4
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u5b57\u7b26\u4e32 S \u548c T\uff0c\u6bcf\u4e2a\u5b57\u7b26\u4e32\u4ee3\u8868\u4e00\u4e2a\u975e\u8d1f\u6709\u7406\u6570\uff0c\u53ea\u6709\u5f53\u5b83\u4eec\u8868\u793a\u76f8\u540c\u7684\u6570\u5b57\u65f6\u624d\u8fd4\u56de true\uff1b\u5426\u5219\uff0c\u8fd4\u56de false\u3002\u5b57\u7b26\u4e32\u4e2d\u53ef\u4ee5\u4f7f\u7528\u62ec\u53f7\u6765\u8868\u793a\u6709\u7406\u6570\u7684\u91cd\u590d\u90e8\u5206\u3002

    \n\n

    \u901a\u5e38\uff0c\u6709\u7406\u6570\u6700\u591a\u53ef\u4ee5\u7528\u4e09\u4e2a\u90e8\u5206\u6765\u8868\u793a\uff1a\u6574\u6570\u90e8\u5206 <IntegerPart>\u3001\u5c0f\u6570\u975e\u91cd\u590d\u90e8\u5206 <NonRepeatingPart> \u548c\u5c0f\u6570\u91cd\u590d\u90e8\u5206 <(><RepeatingPart><)>\u3002\u6570\u5b57\u53ef\u4ee5\u7528\u4ee5\u4e0b\u4e09\u79cd\u65b9\u6cd5\u4e4b\u4e00\u6765\u8868\u793a\uff1a

    \n\n
      \n\t
    • <IntegerPart>\uff08\u4f8b\uff1a0\uff0c12\uff0c123\uff09
    • \n\t
    • <IntegerPart><.><NonRepeatingPart> \uff08\u4f8b\uff1a0.5\uff0c2.12\uff0c2.0001\uff09
    • \n\t
    • <IntegerPart><.><NonRepeatingPart><(><RepeatingPart><)>\uff08\u4f8b\uff1a0.1(6)\uff0c0.9(9)\uff0c0.00(1212)\uff09
    • \n
    \n\n

    \u5341\u8fdb\u5236\u5c55\u5f00\u7684\u91cd\u590d\u90e8\u5206\u901a\u5e38\u5728\u4e00\u5bf9\u5706\u62ec\u53f7\u5185\u8868\u793a\u3002\u4f8b\u5982\uff1a

    \n\n

    1 / 6 = 0.16666666... = 0.1(6) = 0.1666(6) = 0.166(66)

    \n\n

    0.1(6) \u6216 0.1666(6) \u6216 0.166(66) \u90fd\u662f 1 / 6 \u7684\u6b63\u786e\u8868\u793a\u5f62\u5f0f\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aS = "0.(52)", T = "0.5(25)"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u56e0\u4e3a "0.(52)" \u4ee3\u8868 0.52525252...\uff0c\u800c "0.5(25)" \u4ee3\u8868 0.52525252525.....\uff0c\u5219\u8fd9\u4e24\u4e2a\u5b57\u7b26\u4e32\u8868\u793a\u76f8\u540c\u7684\u6570\u5b57\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aS = "0.1666(6)", T = "0.166(66)"\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aS = "0.9(9)", T = "1."\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\n"0.9(9)" \u4ee3\u8868 0.999999999... \u6c38\u8fdc\u91cd\u590d\uff0c\u7b49\u4e8e 1 \u3002[\u6709\u5173\u8bf4\u660e\uff0c\u8bf7\u53c2\u9605\u6b64\u94fe\u63a5]\n"1." \u8868\u793a\u6570\u5b57 1\uff0c\u5176\u683c\u5f0f\u6b63\u786e\uff1a(IntegerPart) = "1" \u4e14 (NonRepeatingPart) = "" \u3002
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. \u6bcf\u4e2a\u90e8\u5206\u4ec5\u7531\u6570\u5b57\u7ec4\u6210\u3002
    2. \n\t
    3. \u6574\u6570\u90e8\u5206 <IntegerPart> \u4e0d\u4f1a\u4ee5 2 \u4e2a\u6216\u66f4\u591a\u7684\u96f6\u5f00\u5934\u3002\uff08\u5bf9\u6bcf\u4e2a\u90e8\u5206\u7684\u6570\u5b57\u6ca1\u6709\u5176\u4ed6\u9650\u5236\uff09\u3002
    4. \n\t
    5. 1 <= <IntegerPart>.length <= 4
    6. \n\t
    7. 0 <= <NonRepeatingPart>.length <= 4
    8. \n\t
    9. 1 <= <RepeatingPart>.length <= 4
    10. \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isRationalEqual(string s, string t) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isRationalEqual(String s, String t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isRationalEqual(self, s, t):\n \"\"\"\n :type s: str\n :type t: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isRationalEqual(self, s: str, t: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isRationalEqual(char * s, char * t){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsRationalEqual(string s, string t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string} t\n * @return {boolean}\n */\nvar isRationalEqual = function(s, t) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String} t\n# @return {Boolean}\ndef is_rational_equal(s, t)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isRationalEqual(_ s: String, _ t: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isRationalEqual(s string, t string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isRationalEqual(s: String, t: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isRationalEqual(s: String, t: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_rational_equal(s: String, t: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String $t\n * @return Boolean\n */\n function isRationalEqual($s, $t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isRationalEqual(s: string, t: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-rational-equal s t)\n (-> string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0972](https://leetcode-cn.com/problems/equal-rational-numbers)", "[\u76f8\u7b49\u7684\u6709\u7406\u6570](/solution/0900-0999/0972.Equal%20Rational%20Numbers/README.md)", "`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[0972](https://leetcode.com/problems/equal-rational-numbers)", "[Equal Rational Numbers](/solution/0900-0999/0972.Equal%20Rational%20Numbers/README_EN.md)", "`Math`", "Hard", ""]}, {"question_id": "1011", "frontend_question_id": "0971", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/flip-binary-tree-to-match-preorder-traversal", "url_en": "https://leetcode.com/problems/flip-binary-tree-to-match-preorder-traversal", "relative_path_cn": "/solution/0900-0999/0971.Flip%20Binary%20Tree%20To%20Match%20Preorder%20Traversal/README.md", "relative_path_en": "/solution/0900-0999/0971.Flip%20Binary%20Tree%20To%20Match%20Preorder%20Traversal/README_EN.md", "title_cn": "\u7ffb\u8f6c\u4e8c\u53c9\u6811\u4ee5\u5339\u914d\u5148\u5e8f\u904d\u5386", "title_en": "Flip Binary Tree To Match Preorder Traversal", "question_title_slug": "flip-binary-tree-to-match-preorder-traversal", "content_en": "

    You are given the root of a binary tree with n nodes, where each node is uniquely assigned a value from 1 to n. You are also given a sequence of n values voyage, which is the desired pre-order traversal of the binary tree.

    \n\n

    Any node in the binary tree can be flipped by swapping its left and right subtrees. For example, flipping node 1 will have the following effect:

    \n\"\"\n

    Flip the smallest number of nodes so that the pre-order traversal of the tree matches voyage.

    \n\n

    Return a list of the values of all flipped nodes. You may return the answer in any order. If it is impossible to flip the nodes in the tree to make the pre-order traversal match voyage, return the list [-1].

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,2], voyage = [2,1]\nOutput: [-1]\nExplanation: It is impossible to flip the nodes such that the pre-order traversal matches voyage.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [1,2,3], voyage = [1,3,2]\nOutput: [1]\nExplanation: Flipping node 1 swaps nodes 2 and 3, so the pre-order traversal matches voyage.
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: root = [1,2,3], voyage = [1,2,3]\nOutput: []\nExplanation: The tree's pre-order traversal already matches voyage, so no nodes need to be flipped.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is n.
    • \n\t
    • n == voyage.length
    • \n\t
    • 1 <= n <= 100
    • \n\t
    • 1 <= Node.val, voyage[i] <= n
    • \n\t
    • All the values in the tree are unique.
    • \n\t
    • All the values in voyage are unique.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u68f5\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9 root \uff0c\u6811\u4e2d\u6709 n \u4e2a\u8282\u70b9\uff0c\u6bcf\u4e2a\u8282\u70b9\u90fd\u6709\u4e00\u4e2a\u4e0d\u540c\u4e8e\u5176\u4ed6\u8282\u70b9\u4e14\u5904\u4e8e 1 \u5230 n \u4e4b\u95f4\u7684\u503c\u3002

    \n\n

    \u53e6\u7ed9\u4f60\u4e00\u4e2a\u7531 n \u4e2a\u503c\u7ec4\u6210\u7684\u884c\u7a0b\u5e8f\u5217 voyage \uff0c\u8868\u793a \u9884\u671f \u7684\u4e8c\u53c9\u6811 \u5148\u5e8f\u904d\u5386 \u7ed3\u679c\u3002

    \n\n

    \u901a\u8fc7\u4ea4\u6362\u8282\u70b9\u7684\u5de6\u53f3\u5b50\u6811\uff0c\u53ef\u4ee5 \u7ffb\u8f6c \u8be5\u4e8c\u53c9\u6811\u4e2d\u7684\u4efb\u610f\u8282\u70b9\u3002\u4f8b\uff0c\u7ffb\u8f6c\u8282\u70b9 1 \u7684\u6548\u679c\u5982\u4e0b\uff1a

    \n\"\"\n

    \u8bf7\u7ffb\u8f6c \u6700\u5c11 \u7684\u6811\u4e2d\u8282\u70b9\uff0c\u4f7f\u4e8c\u53c9\u6811\u7684 \u5148\u5e8f\u904d\u5386 \u4e0e\u9884\u671f\u7684\u904d\u5386\u884c\u7a0b\u00a0voyage\u00a0\u76f8\u5339\u914d \u3002\u00a0

    \n\n

    \u5982\u679c\u53ef\u4ee5\uff0c\u5219\u8fd4\u56de \u7ffb\u8f6c\u7684 \u6240\u6709\u8282\u70b9\u7684\u503c\u7684\u5217\u8868\u3002\u4f60\u53ef\u4ee5\u6309\u4efb\u4f55\u987a\u5e8f\u8fd4\u56de\u7b54\u6848\u3002\u5982\u679c\u4e0d\u80fd\uff0c\u5219\u8fd4\u56de\u5217\u8868 [-1]\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [1,2], voyage = [2,1]\n\u8f93\u51fa\uff1a[-1]\n\u89e3\u91ca\uff1a\u7ffb\u8f6c\u8282\u70b9\u65e0\u6cd5\u4ee4\u5148\u5e8f\u904d\u5386\u5339\u914d\u9884\u671f\u884c\u7a0b\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [1,2,3], voyage = [1,3,2]\n\u8f93\u51fa\uff1a[1]\n\u89e3\u91ca\uff1a\u4ea4\u6362\u8282\u70b9 2 \u548c 3 \u6765\u7ffb\u8f6c\u8282\u70b9 1 \uff0c\u5148\u5e8f\u904d\u5386\u53ef\u4ee5\u5339\u914d\u9884\u671f\u884c\u7a0b\u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [1,2,3], voyage = [1,2,3]\n\u8f93\u51fa\uff1a[]\n\u89e3\u91ca\uff1a\u5148\u5e8f\u904d\u5386\u5df2\u7ecf\u5339\u914d\u9884\u671f\u884c\u7a0b\uff0c\u6240\u4ee5\u4e0d\u9700\u8981\u7ffb\u8f6c\u8282\u70b9\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u7684\u8282\u70b9\u6570\u76ee\u4e3a n
    • \n\t
    • n == voyage.length
    • \n\t
    • 1 <= n <= 100
    • \n\t
    • 1 <= Node.val, voyage[i] <= n
    • \n\t
    • \u6811\u4e2d\u7684\u6240\u6709\u503c \u4e92\u4e0d\u76f8\u540c
    • \n\t
    • voyage \u4e2d\u7684\u6240\u6709\u503c \u4e92\u4e0d\u76f8\u540c
    • \n
    \n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector flipMatchVoyage(TreeNode* root, vector& voyage) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public List flipMatchVoyage(TreeNode root, int[] voyage) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def flipMatchVoyage(self, root, voyage):\n \"\"\"\n :type root: TreeNode\n :type voyage: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def flipMatchVoyage(self, root: TreeNode, voyage: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* flipMatchVoyage(struct TreeNode* root, int* voyage, int voyageSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public IList FlipMatchVoyage(TreeNode root, int[] voyage) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number[]} voyage\n * @return {number[]}\n */\nvar flipMatchVoyage = function(root, voyage) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @param {Integer[]} voyage\n# @return {Integer[]}\ndef flip_match_voyage(root, voyage)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func flipMatchVoyage(_ root: TreeNode?, _ voyage: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc flipMatchVoyage(root *TreeNode, voyage []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def flipMatchVoyage(root: TreeNode, voyage: Array[Int]): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun flipMatchVoyage(root: TreeNode?, voyage: IntArray): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn flip_match_voyage(root: Option>>, voyage: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param Integer[] $voyage\n * @return Integer[]\n */\n function flipMatchVoyage($root, $voyage) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction flipMatchVoyage(root: TreeNode | null, voyage: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (flip-match-voyage root voyage)\n (-> (or/c tree-node? #f) (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0971](https://leetcode-cn.com/problems/flip-binary-tree-to-match-preorder-traversal)", "[\u7ffb\u8f6c\u4e8c\u53c9\u6811\u4ee5\u5339\u914d\u5148\u5e8f\u904d\u5386](/solution/0900-0999/0971.Flip%20Binary%20Tree%20To%20Match%20Preorder%20Traversal/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0971](https://leetcode.com/problems/flip-binary-tree-to-match-preorder-traversal)", "[Flip Binary Tree To Match Preorder Traversal](/solution/0900-0999/0971.Flip%20Binary%20Tree%20To%20Match%20Preorder%20Traversal/README_EN.md)", "`Tree`,`Depth-first Search`", "Medium", ""]}, {"question_id": "1010", "frontend_question_id": "0970", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/powerful-integers", "url_en": "https://leetcode.com/problems/powerful-integers", "relative_path_cn": "/solution/0900-0999/0970.Powerful%20Integers/README.md", "relative_path_en": "/solution/0900-0999/0970.Powerful%20Integers/README_EN.md", "title_cn": "\u5f3a\u6574\u6570", "title_en": "Powerful Integers", "question_title_slug": "powerful-integers", "content_en": "

    Given three integers x, y, and bound, return a list of all the powerful integers that have a value less than or equal to bound.

    \n\n

    An integer is powerful if it can be represented as xi + yj for some integers i >= 0 and j >= 0.

    \n\n

    You may return the answer in any order. In your answer, each value should occur at most once.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: x = 2, y = 3, bound = 10\nOutput: [2,3,4,5,7,9,10]\nExplanation:\n2 = 20 + 30\n3 = 21 + 30\n4 = 20 + 31\n5 = 21 + 31\n7 = 22 + 31\n9 = 23 + 30\n10 = 20 + 32\n
    \n\n

    Example 2:

    \n\n
    \nInput: x = 3, y = 5, bound = 15\nOutput: [2,4,6,8,10,14]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= x, y <= 100
    • \n\t
    • 0 <= bound <= 106
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u6b63\u6574\u6570 x \u548c y\uff0c\u5982\u679c\u67d0\u4e00\u6574\u6570\u7b49\u4e8e x^i + y^j\uff0c\u5176\u4e2d\u6574\u6570 i >= 0 \u4e14 j >= 0\uff0c\u90a3\u4e48\u6211\u4eec\u8ba4\u4e3a\u8be5\u6574\u6570\u662f\u4e00\u4e2a\u5f3a\u6574\u6570\u3002

    \n\n

    \u8fd4\u56de\u503c\u5c0f\u4e8e\u6216\u7b49\u4e8e bound \u7684\u6240\u6709\u5f3a\u6574\u6570\u7ec4\u6210\u7684\u5217\u8868\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u6309\u4efb\u4f55\u987a\u5e8f\u8fd4\u56de\u7b54\u6848\u3002\u5728\u4f60\u7684\u56de\u7b54\u4e2d\uff0c\u6bcf\u4e2a\u503c\u6700\u591a\u51fa\u73b0\u4e00\u6b21\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1ax = 2, y = 3, bound = 10\n\u8f93\u51fa\uff1a[2,3,4,5,7,9,10]\n\u89e3\u91ca\uff1a \n2 = 2^0 + 3^0\n3 = 2^1 + 3^0\n4 = 2^0 + 3^1\n5 = 2^1 + 3^1\n7 = 2^2 + 3^1\n9 = 2^3 + 3^0\n10 = 2^0 + 3^2\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1ax = 3, y = 5, bound = 15\n\u8f93\u51fa\uff1a[2,4,6,8,10,14]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= x <= 100
    • \n\t
    • 1 <= y <= 100
    • \n\t
    • 0 <= bound <= 10^6
    • \n
    \n", "tags_en": ["Hash Table", "Math"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector powerfulIntegers(int x, int y, int bound) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List powerfulIntegers(int x, int y, int bound) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def powerfulIntegers(self, x, y, bound):\n \"\"\"\n :type x: int\n :type y: int\n :type bound: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def powerfulIntegers(self, x: int, y: int, bound: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* powerfulIntegers(int x, int y, int bound, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList PowerfulIntegers(int x, int y, int bound) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} x\n * @param {number} y\n * @param {number} bound\n * @return {number[]}\n */\nvar powerfulIntegers = function(x, y, bound) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} x\n# @param {Integer} y\n# @param {Integer} bound\n# @return {Integer[]}\ndef powerful_integers(x, y, bound)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func powerfulIntegers(_ x: Int, _ y: Int, _ bound: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func powerfulIntegers(x int, y int, bound int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def powerfulIntegers(x: Int, y: Int, bound: Int): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun powerfulIntegers(x: Int, y: Int, bound: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn powerful_integers(x: i32, y: i32, bound: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $x\n * @param Integer $y\n * @param Integer $bound\n * @return Integer[]\n */\n function powerfulIntegers($x, $y, $bound) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function powerfulIntegers(x: number, y: number, bound: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (powerful-integers x y bound)\n (-> exact-integer? exact-integer? exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0970](https://leetcode-cn.com/problems/powerful-integers)", "[\u5f3a\u6574\u6570](/solution/0900-0999/0970.Powerful%20Integers/README.md)", "`\u54c8\u5e0c\u8868`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0970](https://leetcode.com/problems/powerful-integers)", "[Powerful Integers](/solution/0900-0999/0970.Powerful%20Integers/README_EN.md)", "`Hash Table`,`Math`", "Medium", ""]}, {"question_id": "1009", "frontend_question_id": "0969", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/pancake-sorting", "url_en": "https://leetcode.com/problems/pancake-sorting", "relative_path_cn": "/solution/0900-0999/0969.Pancake%20Sorting/README.md", "relative_path_en": "/solution/0900-0999/0969.Pancake%20Sorting/README_EN.md", "title_cn": "\u714e\u997c\u6392\u5e8f", "title_en": "Pancake Sorting", "question_title_slug": "pancake-sorting", "content_en": "

    Given an array of integers arr, sort the array by performing a series of pancake flips.

    \n\n

    In one pancake flip we do the following steps:

    \n\n
      \n\t
    • Choose an integer k where 1 <= k <= arr.length.
    • \n\t
    • Reverse the sub-array arr[0...k-1] (0-indexed).
    • \n
    \n\n

    For example, if arr = [3,2,1,4] and we performed a pancake flip choosing k = 3, we reverse the sub-array [3,2,1], so arr = [1,2,3,4] after the pancake flip at k = 3.

    \n\n

    Return an array of the k-values corresponding to a sequence of pancake flips that sort arr. Any valid answer that sorts the array within 10 * arr.length flips will be judged as correct.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr = [3,2,4,1]\nOutput: [4,2,4,3]\nExplanation: \nWe perform 4 pancake flips, with k values 4, 2, 4, and 3.\nStarting state: arr = [3, 2, 4, 1]\nAfter 1st flip (k = 4): arr = [1, 4, 2, 3]\nAfter 2nd flip (k = 2): arr = [4, 1, 2, 3]\nAfter 3rd flip (k = 4): arr = [3, 2, 1, 4]\nAfter 4th flip (k = 3): arr = [1, 2, 3, 4], which is sorted.\n
    \n\n

    Example 2:

    \n\n
    \nInput: arr = [1,2,3]\nOutput: []\nExplanation: The input is already sorted, so there is no need to flip anything.\nNote that other answers, such as [3, 3], would also be accepted.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= arr.length <= 100
    • \n\t
    • 1 <= arr[i] <= arr.length
    • \n\t
    • All integers in arr are unique (i.e. arr is a permutation of the integers from 1 to arr.length).
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr \uff0c\u8bf7\u4f7f\u7528 \u714e\u997c\u7ffb\u8f6c \u5b8c\u6210\u5bf9\u6570\u7ec4\u7684\u6392\u5e8f\u3002

    \n\n

    \u4e00\u6b21\u714e\u997c\u7ffb\u8f6c\u7684\u6267\u884c\u8fc7\u7a0b\u5982\u4e0b\uff1a

    \n\n
      \n\t
    • \u9009\u62e9\u4e00\u4e2a\u6574\u6570 k \uff0c1 <= k <= arr.length
    • \n\t
    • \u53cd\u8f6c\u5b50\u6570\u7ec4 arr[0...k-1]\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09
    • \n
    \n\n

    \u4f8b\u5982\uff0carr = [3,2,1,4] \uff0c\u9009\u62e9 k = 3 \u8fdb\u884c\u4e00\u6b21\u714e\u997c\u7ffb\u8f6c\uff0c\u53cd\u8f6c\u5b50\u6570\u7ec4 [3,2,1] \uff0c\u5f97\u5230 arr = [1,2,3,4] \u3002

    \n\n

    \u4ee5\u6570\u7ec4\u5f62\u5f0f\u8fd4\u56de\u80fd\u4f7f arr \u6709\u5e8f\u7684\u714e\u997c\u7ffb\u8f6c\u64cd\u4f5c\u6240\u5bf9\u5e94\u7684 k \u503c\u5e8f\u5217\u3002\u4efb\u4f55\u5c06\u6570\u7ec4\u6392\u5e8f\u4e14\u7ffb\u8f6c\u6b21\u6570\u5728\u00a010 * arr.length \u8303\u56f4\u5185\u7684\u6709\u6548\u7b54\u6848\u90fd\u5c06\u88ab\u5224\u65ad\u4e3a\u6b63\u786e\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[3,2,4,1]\n\u8f93\u51fa\uff1a[4,2,4,3]\n\u89e3\u91ca\uff1a\n\u6211\u4eec\u6267\u884c 4 \u6b21\u714e\u997c\u7ffb\u8f6c\uff0ck \u503c\u5206\u522b\u4e3a 4\uff0c2\uff0c4\uff0c\u548c 3\u3002\n\u521d\u59cb\u72b6\u6001 arr = [3, 2, 4, 1]\n\u7b2c\u4e00\u6b21\u7ffb\u8f6c\u540e\uff08k = 4\uff09\uff1aarr = [1, 4, 2, 3]\n\u7b2c\u4e8c\u6b21\u7ffb\u8f6c\u540e\uff08k = 2\uff09\uff1aarr = [4, 1, 2, 3]\n\u7b2c\u4e09\u6b21\u7ffb\u8f6c\u540e\uff08k = 4\uff09\uff1aarr = [3, 2, 1, 4]\n\u7b2c\u56db\u6b21\u7ffb\u8f6c\u540e\uff08k = 3\uff09\uff1aarr = [1, 2, 3, 4]\uff0c\u6b64\u65f6\u5df2\u5b8c\u6210\u6392\u5e8f\u3002 \n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[1,2,3]\n\u8f93\u51fa\uff1a[]\n\u89e3\u91ca\uff1a\n\u8f93\u5165\u5df2\u7ecf\u6392\u5e8f\uff0c\u56e0\u6b64\u4e0d\u9700\u8981\u7ffb\u8f6c\u4efb\u4f55\u5185\u5bb9\u3002\n\u8bf7\u6ce8\u610f\uff0c\u5176\u4ed6\u53ef\u80fd\u7684\u7b54\u6848\uff0c\u5982 [3\uff0c3] \uff0c\u4e5f\u5c06\u88ab\u5224\u65ad\u4e3a\u6b63\u786e\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= arr.length <= 100
    • \n\t
    • 1 <= arr[i] <= arr.length
    • \n\t
    • arr \u4e2d\u7684\u6240\u6709\u6574\u6570\u4e92\u4e0d\u76f8\u540c\uff08\u5373\uff0carr \u662f\u4ece 1 \u5230 arr.length \u6574\u6570\u7684\u4e00\u4e2a\u6392\u5217\uff09
    • \n
    \n", "tags_en": ["Sort", "Array"], "tags_cn": ["\u6392\u5e8f", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector pancakeSort(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List pancakeSort(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def pancakeSort(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def pancakeSort(self, arr: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* pancakeSort(int* arr, int arrSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList PancakeSort(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number[]}\n */\nvar pancakeSort = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer[]}\ndef pancake_sort(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func pancakeSort(_ arr: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func pancakeSort(arr []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def pancakeSort(arr: Array[Int]): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun pancakeSort(arr: IntArray): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn pancake_sort(arr: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer[]\n */\n function pancakeSort($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function pancakeSort(arr: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (pancake-sort arr)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0969](https://leetcode-cn.com/problems/pancake-sorting)", "[\u714e\u997c\u6392\u5e8f](/solution/0900-0999/0969.Pancake%20Sorting/README.md)", "`\u6392\u5e8f`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0969](https://leetcode.com/problems/pancake-sorting)", "[Pancake Sorting](/solution/0900-0999/0969.Pancake%20Sorting/README_EN.md)", "`Sort`,`Array`", "Medium", ""]}, {"question_id": "1008", "frontend_question_id": "0968", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/binary-tree-cameras", "url_en": "https://leetcode.com/problems/binary-tree-cameras", "relative_path_cn": "/solution/0900-0999/0968.Binary%20Tree%20Cameras/README.md", "relative_path_en": "/solution/0900-0999/0968.Binary%20Tree%20Cameras/README_EN.md", "title_cn": "\u76d1\u63a7\u4e8c\u53c9\u6811", "title_en": "Binary Tree Cameras", "question_title_slug": "binary-tree-cameras", "content_en": "

    You are given the root of a binary tree. We install cameras on the tree nodes where each camera at a node can monitor its parent, itself, and its immediate children.

    \n\n

    Return the minimum number of cameras needed to monitor all nodes of the tree.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [0,0,null,0,0]\nOutput: 1\nExplanation: One camera is enough to monitor all nodes if placed as shown.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [0,0,null,0,null,0,null,null,0]\nOutput: 2\nExplanation: At least two cameras are needed to monitor all nodes of the tree. The above image shows one of the valid configurations of camera placement.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 1000].
    • \n\t
    • Node.val == 0
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811\uff0c\u6211\u4eec\u5728\u6811\u7684\u8282\u70b9\u4e0a\u5b89\u88c5\u6444\u50cf\u5934\u3002

    \n\n

    \u8282\u70b9\u4e0a\u7684\u6bcf\u4e2a\u6444\u5f71\u5934\u90fd\u53ef\u4ee5\u76d1\u89c6\u5176\u7236\u5bf9\u8c61\u3001\u81ea\u8eab\u53ca\u5176\u76f4\u63a5\u5b50\u5bf9\u8c61\u3002

    \n\n

    \u8ba1\u7b97\u76d1\u63a7\u6811\u7684\u6240\u6709\u8282\u70b9\u6240\u9700\u7684\u6700\u5c0f\u6444\u50cf\u5934\u6570\u91cf\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1a[0,0,null,0,0]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u5982\u56fe\u6240\u793a\uff0c\u4e00\u53f0\u6444\u50cf\u5934\u8db3\u4ee5\u76d1\u63a7\u6240\u6709\u8282\u70b9\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1a[0,0,null,0,null,0,null,null,0]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u9700\u8981\u81f3\u5c11\u4e24\u4e2a\u6444\u50cf\u5934\u6765\u76d1\u89c6\u6811\u7684\u6240\u6709\u8282\u70b9\u3002 \u4e0a\u56fe\u663e\u793a\u4e86\u6444\u50cf\u5934\u653e\u7f6e\u7684\u6709\u6548\u4f4d\u7f6e\u4e4b\u4e00\u3002\n
    \n\n


    \n\u63d0\u793a\uff1a

    \n\n
      \n\t
    1. \u7ed9\u5b9a\u6811\u7684\u8282\u70b9\u6570\u7684\u8303\u56f4\u662f [1, 1000]\u3002
    2. \n\t
    3. \u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u90fd\u662f 0\u3002
    4. \n
    \n", "tags_en": ["Tree", "Depth-first Search", "Dynamic Programming"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int minCameraCover(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int minCameraCover(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def minCameraCover(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def minCameraCover(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint minCameraCover(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int MinCameraCover(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar minCameraCover = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef min_camera_cover(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func minCameraCover(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc minCameraCover(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def minCameraCover(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun minCameraCover(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn min_camera_cover(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function minCameraCover($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction minCameraCover(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (min-camera-cover root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0968](https://leetcode-cn.com/problems/binary-tree-cameras)", "[\u76d1\u63a7\u4e8c\u53c9\u6811](/solution/0900-0999/0968.Binary%20Tree%20Cameras/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0968](https://leetcode.com/problems/binary-tree-cameras)", "[Binary Tree Cameras](/solution/0900-0999/0968.Binary%20Tree%20Cameras/README_EN.md)", "`Tree`,`Depth-first Search`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "1007", "frontend_question_id": "0967", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/numbers-with-same-consecutive-differences", "url_en": "https://leetcode.com/problems/numbers-with-same-consecutive-differences", "relative_path_cn": "/solution/0900-0999/0967.Numbers%20With%20Same%20Consecutive%20Differences/README.md", "relative_path_en": "/solution/0900-0999/0967.Numbers%20With%20Same%20Consecutive%20Differences/README_EN.md", "title_cn": "\u8fde\u7eed\u5dee\u76f8\u540c\u7684\u6570\u5b57", "title_en": "Numbers With Same Consecutive Differences", "question_title_slug": "numbers-with-same-consecutive-differences", "content_en": "

    Return all non-negative integers of length n such that the absolute difference between every two consecutive digits is k.

    \n\n

    Note that every number in the answer must not have leading zeros. For example, 01 has one leading zero and is invalid.

    \n\n

    You may return the answer in any order.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 3, k = 7\nOutput: [181,292,707,818,929]\nExplanation: Note that 070 is not a valid number, because it has leading zeroes.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 2, k = 1\nOutput: [10,12,21,23,32,34,43,45,54,56,65,67,76,78,87,89,98]\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 2, k = 0\nOutput: [11,22,33,44,55,66,77,88,99]\n
    \n\n

    Example 4:

    \n\n
    \nInput: n = 2, k = 2\nOutput: [13,20,24,31,35,42,46,53,57,64,68,75,79,86,97]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= n <= 9
    • \n\t
    • 0 <= k <= 9
    • \n
    \n", "content_cn": "

    \u8fd4\u56de\u6240\u6709\u957f\u5ea6\u4e3a n \u4e14\u6ee1\u8db3\u5176\u6bcf\u4e24\u4e2a\u8fde\u7eed\u4f4d\u4e0a\u7684\u6570\u5b57\u4e4b\u95f4\u7684\u5dee\u7684\u7edd\u5bf9\u503c\u4e3a k \u7684 \u975e\u8d1f\u6574\u6570 \u3002

    \n\n

    \u8bf7\u6ce8\u610f\uff0c\u9664\u4e86 \u6570\u5b57 0 \u672c\u8eab\u4e4b\u5916\uff0c\u7b54\u6848\u4e2d\u7684\u6bcf\u4e2a\u6570\u5b57\u90fd \u4e0d\u80fd \u6709\u524d\u5bfc\u96f6\u3002\u4f8b\u5982\uff0c01 \u6709\u4e00\u4e2a\u524d\u5bfc\u96f6\uff0c\u6240\u4ee5\u662f\u65e0\u6548\u7684\uff1b\u4f46 0\u00a0\u662f\u6709\u6548\u7684\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u6309 \u4efb\u4f55\u987a\u5e8f \u8fd4\u56de\u7b54\u6848\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 3, k = 7\n\u8f93\u51fa\uff1a[181,292,707,818,929]\n\u89e3\u91ca\uff1a\u6ce8\u610f\uff0c070 \u4e0d\u662f\u4e00\u4e2a\u6709\u6548\u7684\u6570\u5b57\uff0c\u56e0\u4e3a\u5b83\u6709\u524d\u5bfc\u96f6\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 2, k = 1\n\u8f93\u51fa\uff1a[10,12,21,23,32,34,43,45,54,56,65,67,76,78,87,89,98]
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 2, k = 0\n\u8f93\u51fa\uff1a[11,22,33,44,55,66,77,88,99]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 2, k = 2\n\u8f93\u51fa\uff1a[13,20,24,31,35,42,46,53,57,64,68,75,79,86,97]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= n <= 9
    • \n\t
    • 0 <= k <= 9
    • \n
    \n", "tags_en": ["Depth-first Search", "Breadth-first Search", "Recursion", "Backtracking"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u9012\u5f52", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector numsSameConsecDiff(int n, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] numsSameConsecDiff(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numsSameConsecDiff(self, n, k):\n \"\"\"\n :type n: int\n :type k: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numsSameConsecDiff(self, n: int, k: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* numsSameConsecDiff(int n, int k, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] NumsSameConsecDiff(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} k\n * @return {number[]}\n */\nvar numsSameConsecDiff = function(n, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} k\n# @return {Integer[]}\ndef nums_same_consec_diff(n, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numsSameConsecDiff(_ n: Int, _ k: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numsSameConsecDiff(n int, k int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numsSameConsecDiff(n: Int, k: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numsSameConsecDiff(n: Int, k: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn nums_same_consec_diff(n: i32, k: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $k\n * @return Integer[]\n */\n function numsSameConsecDiff($n, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numsSameConsecDiff(n: number, k: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (nums-same-consec-diff n k)\n (-> exact-integer? exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0967](https://leetcode-cn.com/problems/numbers-with-same-consecutive-differences)", "[\u8fde\u7eed\u5dee\u76f8\u540c\u7684\u6570\u5b57](/solution/0900-0999/0967.Numbers%20With%20Same%20Consecutive%20Differences/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u9012\u5f52`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0967](https://leetcode.com/problems/numbers-with-same-consecutive-differences)", "[Numbers With Same Consecutive Differences](/solution/0900-0999/0967.Numbers%20With%20Same%20Consecutive%20Differences/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`,`Recursion`,`Backtracking`", "Medium", ""]}, {"question_id": "1006", "frontend_question_id": "0966", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/vowel-spellchecker", "url_en": "https://leetcode.com/problems/vowel-spellchecker", "relative_path_cn": "/solution/0900-0999/0966.Vowel%20Spellchecker/README.md", "relative_path_en": "/solution/0900-0999/0966.Vowel%20Spellchecker/README_EN.md", "title_cn": "\u5143\u97f3\u62fc\u5199\u68c0\u67e5\u5668", "title_en": "Vowel Spellchecker", "question_title_slug": "vowel-spellchecker", "content_en": "

    Given a wordlist, we want to implement a spellchecker that converts a query word into a correct word.

    \n\n

    For a given query word, the spell checker handles two categories of spelling mistakes:

    \n\n
      \n\t
    • Capitalization: If the query matches a word in the wordlist (case-insensitive), then the query word is returned with the same case as the case in the wordlist.\n\n\t
        \n\t\t
      • Example: wordlist = ["yellow"], query = "YellOw": correct = "yellow"
      • \n\t\t
      • Example: wordlist = ["Yellow"], query = "yellow": correct = "Yellow"
      • \n\t\t
      • Example: wordlist = ["yellow"], query = "yellow": correct = "yellow"
      • \n\t
      \n\t
    • \n\t
    • Vowel Errors: If after replacing the vowels ('a', 'e', 'i', 'o', 'u') of the query word with any vowel individually, it matches a word in the wordlist (case-insensitive), then the query word is returned with the same case as the match in the wordlist.\n\t
        \n\t\t
      • Example: wordlist = ["YellOw"], query = "yollow": correct = "YellOw"
      • \n\t\t
      • Example: wordlist = ["YellOw"], query = "yeellow": correct = "" (no match)
      • \n\t\t
      • Example: wordlist = ["YellOw"], query = "yllw": correct = "" (no match)
      • \n\t
      \n\t
    • \n
    \n\n

    In addition, the spell checker operates under the following precedence rules:

    \n\n
      \n\t
    • When the query exactly matches a word in the wordlist (case-sensitive), you should return the same word back.
    • \n\t
    • When the query matches a word up to capitlization, you should return the first such match in the wordlist.
    • \n\t
    • When the query matches a word up to vowel errors, you should return the first such match in the wordlist.
    • \n\t
    • If the query has no matches in the wordlist, you should return the empty string.
    • \n
    \n\n

    Given some queries, return a list of words answer, where answer[i] is the correct word for query = queries[i].

    \n\n

     

    \n

    Example 1:

    \n
    Input: wordlist = [\"KiTe\",\"kite\",\"hare\",\"Hare\"], queries = [\"kite\",\"Kite\",\"KiTe\",\"Hare\",\"HARE\",\"Hear\",\"hear\",\"keti\",\"keet\",\"keto\"]\nOutput: [\"kite\",\"KiTe\",\"KiTe\",\"Hare\",\"hare\",\"\",\"\",\"KiTe\",\"\",\"KiTe\"]\n

    Example 2:

    \n
    Input: wordlist = [\"yellow\"], queries = [\"YellOw\"]\nOutput: [\"yellow\"]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= wordlist.length, queries.length <= 5000
    • \n\t
    • 1 <= wordlist[i].length, queries[i].length <= 7
    • \n\t
    • wordlist[i] and queries[i] consist only of only English letters.
    • \n
    \n", "content_cn": "

    \u5728\u7ed9\u5b9a\u5355\u8bcd\u5217\u8868 wordlist \u7684\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u5e0c\u671b\u5b9e\u73b0\u4e00\u4e2a\u62fc\u5199\u68c0\u67e5\u5668\uff0c\u5c06\u67e5\u8be2\u5355\u8bcd\u8f6c\u6362\u4e3a\u6b63\u786e\u7684\u5355\u8bcd\u3002

    \n\n

    \u5bf9\u4e8e\u7ed9\u5b9a\u7684\u67e5\u8be2\u5355\u8bcd query\uff0c\u62fc\u5199\u68c0\u67e5\u5668\u5c06\u4f1a\u5904\u7406\u4e24\u7c7b\u62fc\u5199\u9519\u8bef\uff1a

    \n\n
      \n\t
    • \u5927\u5c0f\u5199\uff1a\u5982\u679c\u67e5\u8be2\u5339\u914d\u5355\u8bcd\u5217\u8868\u4e2d\u7684\u67d0\u4e2a\u5355\u8bcd\uff08\u4e0d\u533a\u5206\u5927\u5c0f\u5199\uff09\uff0c\u5219\u8fd4\u56de\u7684\u6b63\u786e\u5355\u8bcd\u4e0e\u5355\u8bcd\u5217\u8868\u4e2d\u7684\u5927\u5c0f\u5199\u76f8\u540c\u3002\n\n\t
        \n\t\t
      • \u4f8b\u5982\uff1awordlist = ["yellow"], query = "YellOw": correct = "yellow"
      • \n\t\t
      • \u4f8b\u5982\uff1awordlist = ["Yellow"], query = "yellow": correct = "Yellow"
      • \n\t\t
      • \u4f8b\u5982\uff1awordlist = ["yellow"], query = "yellow": correct = "yellow"
      • \n\t
      \n\t
    • \n\t
    • \u5143\u97f3\u9519\u8bef\uff1a\u5982\u679c\u5728\u5c06\u67e5\u8be2\u5355\u8bcd\u4e2d\u7684\u5143\u97f3\uff08‘a’\u3001‘e’\u3001‘i’\u3001‘o’\u3001‘u’\uff09\u5206\u522b\u66ff\u6362\u4e3a\u4efb\u4f55\u5143\u97f3\u540e\uff0c\u80fd\u4e0e\u5355\u8bcd\u5217\u8868\u4e2d\u7684\u5355\u8bcd\u5339\u914d\uff08\u4e0d\u533a\u5206\u5927\u5c0f\u5199\uff09\uff0c\u5219\u8fd4\u56de\u7684\u6b63\u786e\u5355\u8bcd\u4e0e\u5355\u8bcd\u5217\u8868\u4e2d\u7684\u5339\u914d\u9879\u5927\u5c0f\u5199\u76f8\u540c\u3002\n\t
        \n\t\t
      • \u4f8b\u5982\uff1awordlist = ["YellOw"], query = "yollow": correct = "YellOw"
      • \n\t\t
      • \u4f8b\u5982\uff1awordlist = ["YellOw"], query = "yeellow": correct = "" \uff08\u65e0\u5339\u914d\u9879\uff09
      • \n\t\t
      • \u4f8b\u5982\uff1awordlist = ["YellOw"], query = "yllw": correct = "" \uff08\u65e0\u5339\u914d\u9879\uff09
      • \n\t
      \n\t
    • \n
    \n\n

    \u6b64\u5916\uff0c\u62fc\u5199\u68c0\u67e5\u5668\u8fd8\u6309\u7167\u4ee5\u4e0b\u4f18\u5148\u7ea7\u89c4\u5219\u64cd\u4f5c\uff1a

    \n\n
      \n\t
    • \u5f53\u67e5\u8be2\u5b8c\u5168\u5339\u914d\u5355\u8bcd\u5217\u8868\u4e2d\u7684\u67d0\u4e2a\u5355\u8bcd\uff08\u533a\u5206\u5927\u5c0f\u5199\uff09\u65f6\uff0c\u5e94\u8fd4\u56de\u76f8\u540c\u7684\u5355\u8bcd\u3002
    • \n\t
    • \u5f53\u67e5\u8be2\u5339\u914d\u5230\u5927\u5c0f\u5199\u95ee\u9898\u7684\u5355\u8bcd\u65f6\uff0c\u60a8\u5e94\u8be5\u8fd4\u56de\u5355\u8bcd\u5217\u8868\u4e2d\u7684\u7b2c\u4e00\u4e2a\u8fd9\u6837\u7684\u5339\u914d\u9879\u3002
    • \n\t
    • \u5f53\u67e5\u8be2\u5339\u914d\u5230\u5143\u97f3\u9519\u8bef\u7684\u5355\u8bcd\u65f6\uff0c\u60a8\u5e94\u8be5\u8fd4\u56de\u5355\u8bcd\u5217\u8868\u4e2d\u7684\u7b2c\u4e00\u4e2a\u8fd9\u6837\u7684\u5339\u914d\u9879\u3002
    • \n\t
    • \u5982\u679c\u8be5\u67e5\u8be2\u5728\u5355\u8bcd\u5217\u8868\u4e2d\u6ca1\u6709\u5339\u914d\u9879\uff0c\u5219\u5e94\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32\u3002
    • \n
    \n\n

    \u7ed9\u51fa\u4e00\u4e9b\u67e5\u8be2 queries\uff0c\u8fd4\u56de\u4e00\u4e2a\u5355\u8bcd\u5217\u8868 answer\uff0c\u5176\u4e2d answer[i] \u662f\u7531\u67e5\u8be2 query = queries[i] \u5f97\u5230\u7684\u6b63\u786e\u5355\u8bcd\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1awordlist = ["KiTe","kite","hare","Hare"], queries = ["kite","Kite","KiTe","Hare","HARE","Hear","hear","keti","keet","keto"]\n\u8f93\u51fa\uff1a["kite","KiTe","KiTe","Hare","hare","","","KiTe","","KiTe"]
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= wordlist.length <= 5000
    2. \n\t
    3. 1 <= queries.length <= 5000
    4. \n\t
    5. 1 <= wordlist[i].length <= 7
    6. \n\t
    7. 1 <= queries[i].length <= 7
    8. \n\t
    9. wordlist \u548c queries \u4e2d\u7684\u6240\u6709\u5b57\u7b26\u4e32\u4ec5\u7531\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\u3002
    10. \n
    \n", "tags_en": ["Hash Table", "String"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector spellchecker(vector& wordlist, vector& queries) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String[] spellchecker(String[] wordlist, String[] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def spellchecker(self, wordlist, queries):\n \"\"\"\n :type wordlist: List[str]\n :type queries: List[str]\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def spellchecker(self, wordlist: List[str], queries: List[str]) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** spellchecker(char ** wordlist, int wordlistSize, char ** queries, int queriesSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string[] Spellchecker(string[] wordlist, string[] queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} wordlist\n * @param {string[]} queries\n * @return {string[]}\n */\nvar spellchecker = function(wordlist, queries) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} wordlist\n# @param {String[]} queries\n# @return {String[]}\ndef spellchecker(wordlist, queries)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func spellchecker(_ wordlist: [String], _ queries: [String]) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func spellchecker(wordlist []string, queries []string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def spellchecker(wordlist: Array[String], queries: Array[String]): Array[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun spellchecker(wordlist: Array, queries: Array): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn spellchecker(wordlist: Vec, queries: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $wordlist\n * @param String[] $queries\n * @return String[]\n */\n function spellchecker($wordlist, $queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function spellchecker(wordlist: string[], queries: string[]): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (spellchecker wordlist queries)\n (-> (listof string?) (listof string?) (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0966](https://leetcode-cn.com/problems/vowel-spellchecker)", "[\u5143\u97f3\u62fc\u5199\u68c0\u67e5\u5668](/solution/0900-0999/0966.Vowel%20Spellchecker/README.md)", "`\u54c8\u5e0c\u8868`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0966](https://leetcode.com/problems/vowel-spellchecker)", "[Vowel Spellchecker](/solution/0900-0999/0966.Vowel%20Spellchecker/README_EN.md)", "`Hash Table`,`String`", "Medium", ""]}, {"question_id": "1005", "frontend_question_id": "0965", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/univalued-binary-tree", "url_en": "https://leetcode.com/problems/univalued-binary-tree", "relative_path_cn": "/solution/0900-0999/0965.Univalued%20Binary%20Tree/README.md", "relative_path_en": "/solution/0900-0999/0965.Univalued%20Binary%20Tree/README_EN.md", "title_cn": "\u5355\u503c\u4e8c\u53c9\u6811", "title_en": "Univalued Binary Tree", "question_title_slug": "univalued-binary-tree", "content_en": "

    A binary tree is univalued if every node in the tree has the same value.

    \r\n\r\n

    Return true if and only if the given tree is univalued.

    \r\n\r\n

     

    \r\n\r\n

    Example 1:

    \r\n\"\"\r\n
    \r\nInput: [1,1,1,1,1,null,1]\r\nOutput: true\r\n
    \r\n\r\n
    \r\n

    Example 2:

    \r\n\"\"\r\n
    \r\nInput: [2,2,2,5,2]\r\nOutput: false\r\n
    \r\n
    \r\n\r\n

     

    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    1. The number of nodes in the given tree will be in the range [1, 100].
    2. \r\n\t
    3. Each node's value will be an integer in the range [0, 99].
    4. \r\n
    \r\n", "content_cn": "

    \u5982\u679c\u4e8c\u53c9\u6811\u6bcf\u4e2a\u8282\u70b9\u90fd\u5177\u6709\u76f8\u540c\u7684\u503c\uff0c\u90a3\u4e48\u8be5\u4e8c\u53c9\u6811\u5c31\u662f\u5355\u503c\u4e8c\u53c9\u6811\u3002

    \n\n

    \u53ea\u6709\u7ed9\u5b9a\u7684\u6811\u662f\u5355\u503c\u4e8c\u53c9\u6811\u65f6\uff0c\u624d\u8fd4\u56de true\uff1b\u5426\u5219\u8fd4\u56de false\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1a[1,1,1,1,1,null,1]\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1a[2,2,2,5,2]\n\u8f93\u51fa\uff1afalse\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. \u7ed9\u5b9a\u6811\u7684\u8282\u70b9\u6570\u8303\u56f4\u662f [1, 100]\u3002
    2. \n\t
    3. \u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u90fd\u662f\u6574\u6570\uff0c\u8303\u56f4\u4e3a [0, 99] \u3002
    4. \n
    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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 */\nclass Solution {\npublic:\n bool isUnivalTree(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode(int x) { val = x; }\n * }\n */\nclass Solution {\n public boolean isUnivalTree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution(object):\n def isUnivalTree(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: bool\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution:\n def isUnivalTree(self, root: TreeNode) -> bool:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nbool isUnivalTree(struct TreeNode* root){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int x) { val = x; }\n * }\n */\npublic class Solution {\n public bool IsUnivalTree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val) {\n * this.val = val;\n * this.left = this.right = null;\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {boolean}\n */\nvar isUnivalTree = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val)\n# @val = val\n# @left, @right = nil, nil\n# end\n# end\n\n# @param {TreeNode} root\n# @return {Boolean}\ndef is_unival_tree(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.left = nil\n * self.right = nil\n * }\n * }\n */\nclass Solution {\n func isUnivalTree(_ root: TreeNode?) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc isUnivalTree(root *TreeNode) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(var _value: Int) {\n * var value: Int = _value\n * var left: TreeNode = null\n * var right: TreeNode = null\n * }\n */\nobject Solution {\n def isUnivalTree(root: TreeNode): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun isUnivalTree(root: TreeNode?): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n// \n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn is_unival_tree(root: Option>>) -> bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($value) { $this->val = $value; }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Boolean\n */\n function isUnivalTree($root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction isUnivalTree(root: TreeNode | null): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (is-unival-tree root)\n (-> (or/c tree-node? #f) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0965](https://leetcode-cn.com/problems/univalued-binary-tree)", "[\u5355\u503c\u4e8c\u53c9\u6811](/solution/0900-0999/0965.Univalued%20Binary%20Tree/README.md)", "`\u6811`", "\u7b80\u5355", ""], "md_table_row_en": ["[0965](https://leetcode.com/problems/univalued-binary-tree)", "[Univalued Binary Tree](/solution/0900-0999/0965.Univalued%20Binary%20Tree/README_EN.md)", "`Tree`", "Easy", ""]}, {"question_id": "1004", "frontend_question_id": "0964", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/least-operators-to-express-number", "url_en": "https://leetcode.com/problems/least-operators-to-express-number", "relative_path_cn": "/solution/0900-0999/0964.Least%20Operators%20to%20Express%20Number/README.md", "relative_path_en": "/solution/0900-0999/0964.Least%20Operators%20to%20Express%20Number/README_EN.md", "title_cn": "\u8868\u793a\u6570\u5b57\u7684\u6700\u5c11\u8fd0\u7b97\u7b26", "title_en": "Least Operators to Express Number", "question_title_slug": "least-operators-to-express-number", "content_en": "

    Given a single positive integer x, we will write an expression of the form x (op1) x (op2) x (op3) x ... where each operator op1, op2, etc. is either addition, subtraction, multiplication, or division (+, -, *, or /). For example, with x = 3, we might write 3 * 3 / 3 + 3 - 3 which is a value of 3.

    \n\n

    When writing such an expression, we adhere to the following conventions:

    \n\n
      \n\t
    • The division operator (/) returns rational numbers.
    • \n\t
    • There are no parentheses placed anywhere.
    • \n\t
    • We use the usual order of operations: multiplication and division happen before addition and subtraction.
    • \n\t
    • It is not allowed to use the unary negation operator (-). For example, "x - x" is a valid expression as it only uses subtraction, but "-x + x" is not because it uses negation.
    • \n
    \n\n

    We would like to write an expression with the least number of operators such that the expression equals the given target. Return the least number of operators used.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: x = 3, target = 19\nOutput: 5\nExplanation: 3 * 3 + 3 * 3 + 3 / 3.\nThe expression contains 5 operations.\n
    \n\n

    Example 2:

    \n\n
    \nInput: x = 5, target = 501\nOutput: 8\nExplanation: 5 * 5 * 5 * 5 - 5 * 5 * 5 + 5 / 5.\nThe expression contains 8 operations.\n
    \n\n

    Example 3:

    \n\n
    \nInput: x = 100, target = 100000000\nOutput: 3\nExplanation: 100 * 100 * 100 * 100.\nThe expression contains 3 operations.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= x <= 100
    • \n\t
    • 1 <= target <= 2 * 108
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6b63\u6574\u6570 x\uff0c\u6211\u4eec\u5c06\u4f1a\u5199\u51fa\u4e00\u4e2a\u5f62\u5982 x (op1) x (op2) x (op3) x ... \u7684\u8868\u8fbe\u5f0f\uff0c\u5176\u4e2d\u6bcf\u4e2a\u8fd0\u7b97\u7b26 op1\uff0cop2\uff0c… \u53ef\u4ee5\u662f\u52a0\u3001\u51cf\u3001\u4e58\u3001\u9664\uff08+\uff0c-\uff0c*\uff0c\u6216\u662f /\uff09\u4e4b\u4e00\u3002\u4f8b\u5982\uff0c\u5bf9\u4e8e x = 3\uff0c\u6211\u4eec\u53ef\u4ee5\u5199\u51fa\u8868\u8fbe\u5f0f 3 * 3 / 3 + 3 - 3\uff0c\u8be5\u5f0f\u7684\u503c\u4e3a 3 \u3002

    \n\n

    \u5728\u5199\u8fd9\u6837\u7684\u8868\u8fbe\u5f0f\u65f6\uff0c\u6211\u4eec\u9700\u8981\u9075\u5b88\u4e0b\u9762\u7684\u60ef\u4f8b\uff1a

    \n\n
      \n\t
    1. \u9664\u8fd0\u7b97\u7b26\uff08/\uff09\u8fd4\u56de\u6709\u7406\u6570\u3002
    2. \n\t
    3. \u4efb\u4f55\u5730\u65b9\u90fd\u6ca1\u6709\u62ec\u53f7\u3002
    4. \n\t
    5. \u6211\u4eec\u4f7f\u7528\u901a\u5e38\u7684\u64cd\u4f5c\u987a\u5e8f\uff1a\u4e58\u6cd5\u548c\u9664\u6cd5\u53d1\u751f\u5728\u52a0\u6cd5\u548c\u51cf\u6cd5\u4e4b\u524d\u3002
    6. \n\t
    7. \u4e0d\u5141\u8bb8\u4f7f\u7528\u4e00\u5143\u5426\u5b9a\u8fd0\u7b97\u7b26\uff08-\uff09\u3002\u4f8b\u5982\uff0c“x - x” \u662f\u4e00\u4e2a\u6709\u6548\u7684\u8868\u8fbe\u5f0f\uff0c\u56e0\u4e3a\u5b83\u53ea\u4f7f\u7528\u51cf\u6cd5\uff0c\u4f46\u662f “-x + x” \u4e0d\u662f\uff0c\u56e0\u4e3a\u5b83\u4f7f\u7528\u4e86\u5426\u5b9a\u8fd0\u7b97\u7b26\u3002 
    8. \n
    \n\n

    \u6211\u4eec\u5e0c\u671b\u7f16\u5199\u4e00\u4e2a\u80fd\u4f7f\u8868\u8fbe\u5f0f\u7b49\u4e8e\u7ed9\u5b9a\u7684\u76ee\u6807\u503c target \u4e14\u8fd0\u7b97\u7b26\u6700\u5c11\u7684\u8868\u8fbe\u5f0f\u3002\u8fd4\u56de\u6240\u7528\u8fd0\u7b97\u7b26\u7684\u6700\u5c11\u6570\u91cf\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1ax = 3, target = 19\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a3 * 3 + 3 * 3 + 3 / 3 \u3002\u8868\u8fbe\u5f0f\u5305\u542b 5 \u4e2a\u8fd0\u7b97\u7b26\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1ax = 5, target = 501\n\u8f93\u51fa\uff1a8\n\u89e3\u91ca\uff1a5 * 5 * 5 * 5 - 5 * 5 * 5 + 5 / 5 \u3002\u8868\u8fbe\u5f0f\u5305\u542b 8 \u4e2a\u8fd0\u7b97\u7b26\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1ax = 100, target = 100000000\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a100 * 100 * 100 * 100 \u3002\u8868\u8fbe\u5f0f\u5305\u542b 3 \u4e2a\u8fd0\u7b97\u7b26\u3002
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= x <= 100
    • \n\t
    • 1 <= target <= 2 * 10^8
    • \n
    \n\n

     

    \n", "tags_en": ["Math", "Dynamic Programming"], "tags_cn": ["\u6570\u5b66", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int leastOpsExpressTarget(int x, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int leastOpsExpressTarget(int x, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def leastOpsExpressTarget(self, x, target):\n \"\"\"\n :type x: int\n :type target: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def leastOpsExpressTarget(self, x: int, target: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint leastOpsExpressTarget(int x, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LeastOpsExpressTarget(int x, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} x\n * @param {number} target\n * @return {number}\n */\nvar leastOpsExpressTarget = function(x, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} x\n# @param {Integer} target\n# @return {Integer}\ndef least_ops_express_target(x, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func leastOpsExpressTarget(_ x: Int, _ target: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func leastOpsExpressTarget(x int, target int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def leastOpsExpressTarget(x: Int, target: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun leastOpsExpressTarget(x: Int, target: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn least_ops_express_target(x: i32, target: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $x\n * @param Integer $target\n * @return Integer\n */\n function leastOpsExpressTarget($x, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function leastOpsExpressTarget(x: number, target: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (least-ops-express-target x target)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0964](https://leetcode-cn.com/problems/least-operators-to-express-number)", "[\u8868\u793a\u6570\u5b57\u7684\u6700\u5c11\u8fd0\u7b97\u7b26](/solution/0900-0999/0964.Least%20Operators%20to%20Express%20Number/README.md)", "`\u6570\u5b66`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0964](https://leetcode.com/problems/least-operators-to-express-number)", "[Least Operators to Express Number](/solution/0900-0999/0964.Least%20Operators%20to%20Express%20Number/README_EN.md)", "`Math`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "1003", "frontend_question_id": "0963", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-area-rectangle-ii", "url_en": "https://leetcode.com/problems/minimum-area-rectangle-ii", "relative_path_cn": "/solution/0900-0999/0963.Minimum%20Area%20Rectangle%20II/README.md", "relative_path_en": "/solution/0900-0999/0963.Minimum%20Area%20Rectangle%20II/README_EN.md", "title_cn": "\u6700\u5c0f\u9762\u79ef\u77e9\u5f62 II", "title_en": "Minimum Area Rectangle II", "question_title_slug": "minimum-area-rectangle-ii", "content_en": "

    Given a set of points in the xy-plane, determine the minimum area of any rectangle formed from these points, with sides not necessarily parallel to the x and y axes.

    \r\n\r\n

    If there isn't any rectangle, return 0.

    \r\n\r\n

     

    \r\n\r\n

    Example 1:

    \r\n\r\n

    \"\"

    \r\n\r\n
    \r\nInput: [[1,2],[2,1],[1,0],[0,1]]\r\nOutput: 2.00000\r\nExplanation: The minimum area rectangle occurs at [1,2],[2,1],[1,0],[0,1], with an area of 2.\r\n
    \r\n\r\n
    \r\n

    Example 2:

    \r\n\r\n

    \"\"

    \r\n\r\n
    \r\nInput: [[0,1],[2,1],[1,1],[1,0],[2,0]]\r\nOutput: 1.00000\r\nExplanation: The minimum area rectangle occurs at [1,0],[1,1],[2,1],[2,0], with an area of 1.\r\n
    \r\n\r\n
    \r\n

    Example 3:

    \r\n\r\n

    \"\"

    \r\n\r\n
    \r\nInput: [[0,3],[1,2],[3,1],[1,3],[2,1]]\r\nOutput: 0\r\nExplanation: There is no possible rectangle to form from these points.\r\n
    \r\n\r\n
    \r\n

    Example 4:

    \r\n\r\n

    \"\"

    \r\n\r\n
    \r\nInput: [[3,1],[1,1],[0,1],[2,1],[3,3],[3,2],[0,2],[2,3]]\r\nOutput: 2.00000\r\nExplanation: The minimum area rectangle occurs at [2,1],[2,3],[3,3],[3,1], with an area of 2.\r\n
    \r\n
    \r\n\r\n

     

    \r\n
    \r\n
    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    1. 1 <= points.length <= 50
    2. \r\n\t
    3. 0 <= points[i][0] <= 40000
    4. \r\n\t
    5. 0 <= points[i][1] <= 40000
    6. \r\n\t
    7. All points are distinct.
    8. \r\n\t
    9. Answers within 10^-5 of the actual value will be accepted as correct.
    10. \r\n
    \r\n", "content_cn": "

    \u7ed9\u5b9a\u5728 xy \u5e73\u9762\u4e0a\u7684\u4e00\u7ec4\u70b9\uff0c\u786e\u5b9a\u7531\u8fd9\u4e9b\u70b9\u7ec4\u6210\u7684\u4efb\u4f55\u77e9\u5f62\u7684\u6700\u5c0f\u9762\u79ef\uff0c\u5176\u4e2d\u77e9\u5f62\u7684\u8fb9\u4e0d\u4e00\u5b9a\u5e73\u884c\u4e8e x \u8f74\u548c y \u8f74\u3002

    \n\n

    \u5982\u679c\u6ca1\u6709\u4efb\u4f55\u77e9\u5f62\uff0c\u5c31\u8fd4\u56de 0\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1a[[1,2],[2,1],[1,0],[0,1]]\n\u8f93\u51fa\uff1a2.00000\n\u89e3\u91ca\uff1a\u6700\u5c0f\u9762\u79ef\u7684\u77e9\u5f62\u51fa\u73b0\u5728 [1,2],[2,1],[1,0],[0,1] \u5904\uff0c\u9762\u79ef\u4e3a 2\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1a[[0,1],[2,1],[1,1],[1,0],[2,0]]\n\u8f93\u51fa\uff1a1.00000\n\u89e3\u91ca\uff1a\u6700\u5c0f\u9762\u79ef\u7684\u77e9\u5f62\u51fa\u73b0\u5728 [1,0],[1,1],[2,1],[2,0] \u5904\uff0c\u9762\u79ef\u4e3a 1\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1a[[0,3],[1,2],[3,1],[1,3],[2,1]]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6ca1\u6cd5\u4ece\u8fd9\u4e9b\u70b9\u4e2d\u7ec4\u6210\u4efb\u4f55\u77e9\u5f62\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1a[[3,1],[1,1],[0,1],[2,1],[3,3],[3,2],[0,2],[2,3]]\n\u8f93\u51fa\uff1a2.00000\n\u89e3\u91ca\uff1a\u6700\u5c0f\u9762\u79ef\u7684\u77e9\u5f62\u51fa\u73b0\u5728 [2,1],[2,3],[3,3],[3,1] \u5904\uff0c\u9762\u79ef\u4e3a 2\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= points.length <= 50
    2. \n\t
    3. 0 <= points[i][0] <= 40000
    4. \n\t
    5. 0 <= points[i][1] <= 40000
    6. \n\t
    7. \u6240\u6709\u7684\u70b9\u90fd\u662f\u4e0d\u540c\u7684\u3002
    8. \n\t
    9. \u4e0e\u771f\u5b9e\u503c\u8bef\u5dee\u4e0d\u8d85\u8fc7 10^-5 \u7684\u7b54\u6848\u5c06\u89c6\u4e3a\u6b63\u786e\u7ed3\u679c\u3002
    10. \n
    \n", "tags_en": ["Geometry", "Math"], "tags_cn": ["\u51e0\u4f55", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n double minAreaFreeRect(vector>& points) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double minAreaFreeRect(int[][] points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minAreaFreeRect(self, points):\n \"\"\"\n :type points: List[List[int]]\n :rtype: float\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minAreaFreeRect(self, points: List[List[int]]) -> float:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\ndouble minAreaFreeRect(int** points, int pointsSize, int* pointsColSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double MinAreaFreeRect(int[][] points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} points\n * @return {number}\n */\nvar minAreaFreeRect = function(points) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} points\n# @return {Float}\ndef min_area_free_rect(points)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minAreaFreeRect(_ points: [[Int]]) -> Double {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minAreaFreeRect(points [][]int) float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minAreaFreeRect(points: Array[Array[Int]]): Double = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minAreaFreeRect(points: Array): Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_area_free_rect(points: Vec>) -> f64 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $points\n * @return Float\n */\n function minAreaFreeRect($points) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minAreaFreeRect(points: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-area-free-rect points)\n (-> (listof (listof exact-integer?)) flonum?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0963](https://leetcode-cn.com/problems/minimum-area-rectangle-ii)", "[\u6700\u5c0f\u9762\u79ef\u77e9\u5f62 II](/solution/0900-0999/0963.Minimum%20Area%20Rectangle%20II/README.md)", "`\u51e0\u4f55`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0963](https://leetcode.com/problems/minimum-area-rectangle-ii)", "[Minimum Area Rectangle II](/solution/0900-0999/0963.Minimum%20Area%20Rectangle%20II/README_EN.md)", "`Geometry`,`Math`", "Medium", ""]}, {"question_id": "1002", "frontend_question_id": "0962", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-width-ramp", "url_en": "https://leetcode.com/problems/maximum-width-ramp", "relative_path_cn": "/solution/0900-0999/0962.Maximum%20Width%20Ramp/README.md", "relative_path_en": "/solution/0900-0999/0962.Maximum%20Width%20Ramp/README_EN.md", "title_cn": "\u6700\u5927\u5bbd\u5ea6\u5761", "title_en": "Maximum Width Ramp", "question_title_slug": "maximum-width-ramp", "content_en": "

    Given an array nums of integers, a ramp is a tuple (i, j) for which i < j and nums[i] <= nums[j].  The width of such a ramp is j - i.

    \n\n

    Find the maximum width of a ramp in nums.  If one doesn't exist, return 0.

    \n\n

     

    \n\n

    Example 1:

    \n\n
    \nInput: nums = [6,0,8,2,1,5]\nOutput: 4\nExplanation: \nThe maximum width ramp is achieved at (i, j) = (1, 5): nums[1] = 0 and nums[5] = 5.\n
    \n\n
    \n

    Example 2:

    \n\n
    \nInput: nums = [9,8,1,0,1,9,4,0,4,1]\nOutput: 7\nExplanation: \nThe maximum width ramp is achieved at (i, j) = (2, 9): nums[2] = 1 and nums[9] = 1.\n
    \n
    \n\n
    \n
    \n

     

    \n\n

    Note:

    \n\n
      \n\t
    1. 2 <= nums.length <= 50000
    2. \n\t
    3. 0 <= nums[i] <= 50000
    4. \n
    \n
    \n
    \n\n
    \n
     
    \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 A\uff0c\u5761\u662f\u5143\u7ec4 (i, j)\uff0c\u5176\u4e2d  i < j \u4e14 A[i] <= A[j]\u3002\u8fd9\u6837\u7684\u5761\u7684\u5bbd\u5ea6\u4e3a j - i\u3002

    \n\n

    \u627e\u51fa A \u4e2d\u7684\u5761\u7684\u6700\u5927\u5bbd\u5ea6\uff0c\u5982\u679c\u4e0d\u5b58\u5728\uff0c\u8fd4\u56de 0 \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a[6,0,8,2,1,5]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\n\u6700\u5927\u5bbd\u5ea6\u7684\u5761\u4e3a (i, j) = (1, 5): A[1] = 0 \u4e14 A[5] = 5.\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a[9,8,1,0,1,9,4,0,4,1]\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\n\u6700\u5927\u5bbd\u5ea6\u7684\u5761\u4e3a (i, j) = (2, 9): A[2] = 1 \u4e14 A[9] = 1.\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 2 <= A.length <= 50000
    2. \n\t
    3. 0 <= A[i] <= 50000
    4. \n
    \n\n

     

    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxWidthRamp(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxWidthRamp(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxWidthRamp(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxWidthRamp(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxWidthRamp(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxWidthRamp(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar maxWidthRamp = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef max_width_ramp(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxWidthRamp(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxWidthRamp(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxWidthRamp(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxWidthRamp(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_width_ramp(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function maxWidthRamp($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxWidthRamp(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-width-ramp nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0962](https://leetcode-cn.com/problems/maximum-width-ramp)", "[\u6700\u5927\u5bbd\u5ea6\u5761](/solution/0900-0999/0962.Maximum%20Width%20Ramp/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0962](https://leetcode.com/problems/maximum-width-ramp)", "[Maximum Width Ramp](/solution/0900-0999/0962.Maximum%20Width%20Ramp/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "1001", "frontend_question_id": "0961", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/n-repeated-element-in-size-2n-array", "url_en": "https://leetcode.com/problems/n-repeated-element-in-size-2n-array", "relative_path_cn": "/solution/0900-0999/0961.N-Repeated%20Element%20in%20Size%202N%20Array/README.md", "relative_path_en": "/solution/0900-0999/0961.N-Repeated%20Element%20in%20Size%202N%20Array/README_EN.md", "title_cn": "\u91cd\u590d N \u6b21\u7684\u5143\u7d20", "title_en": "N-Repeated Element in Size 2N Array", "question_title_slug": "n-repeated-element-in-size-2n-array", "content_en": "

    In a array nums of size 2 * n, there are n + 1 unique elements, and exactly one of these elements is repeated n times.

    \n\n

    Return the element repeated n times.

    \n\n

     

    \n\n
      \n
    \n\n
    \n

    Example 1:

    \n\n
    \nInput: nums[1,2,3,3]\nOutput: 3\n
    \n\n
    \n

    Example 2:

    \n\n
    \nInput: nums[2,1,2,5,3,2]\nOutput: 2\n
    \n\n
    \n

    Example 3:

    \n\n
    \nInput: nums[5,1,5,2,5,3,5,4]\nOutput: 5\n
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    • 4 <= nums.length <= 10000
    • \n\t
    • 0 <= nums[i] < 10000
    • \n\t
    • nums.length is even
    • \n
    \n
    \n
    \n
    \n", "content_cn": "

    \u5728\u5927\u5c0f\u4e3a 2N\u00a0\u7684\u6570\u7ec4 A\u00a0\u4e2d\u6709 N+1 \u4e2a\u4e0d\u540c\u7684\u5143\u7d20\uff0c\u5176\u4e2d\u6709\u4e00\u4e2a\u5143\u7d20\u91cd\u590d\u4e86 N \u6b21\u3002

    \n\n

    \u8fd4\u56de\u91cd\u590d\u4e86 N\u00a0\u6b21\u7684\u90a3\u4e2a\u5143\u7d20\u3002

    \n\n

    \u00a0

    \n\n
      \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[1,2,3,3]\n\u8f93\u51fa\uff1a3\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[2,1,2,5,3,2]\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b\u00a03\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[5,1,5,2,5,3,5,4]\n\u8f93\u51fa\uff1a5\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 4 <= A.length <= 10000
    • \n\t
    • 0 <= A[i] < 10000
    • \n\t
    • A.length\u00a0\u4e3a\u5076\u6570
    • \n
    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int repeatedNTimes(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int repeatedNTimes(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def repeatedNTimes(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def repeatedNTimes(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint repeatedNTimes(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int RepeatedNTimes(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar repeatedNTimes = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef repeated_n_times(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func repeatedNTimes(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func repeatedNTimes(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def repeatedNTimes(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun repeatedNTimes(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn repeated_n_times(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function repeatedNTimes($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function repeatedNTimes(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (repeated-n-times nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0961](https://leetcode-cn.com/problems/n-repeated-element-in-size-2n-array)", "[\u91cd\u590d N \u6b21\u7684\u5143\u7d20](/solution/0900-0999/0961.N-Repeated%20Element%20in%20Size%202N%20Array/README.md)", "`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0961](https://leetcode.com/problems/n-repeated-element-in-size-2n-array)", "[N-Repeated Element in Size 2N Array](/solution/0900-0999/0961.N-Repeated%20Element%20in%20Size%202N%20Array/README_EN.md)", "`Hash Table`", "Easy", ""]}, {"question_id": "1000", "frontend_question_id": "0960", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/delete-columns-to-make-sorted-iii", "url_en": "https://leetcode.com/problems/delete-columns-to-make-sorted-iii", "relative_path_cn": "/solution/0900-0999/0960.Delete%20Columns%20to%20Make%20Sorted%20III/README.md", "relative_path_en": "/solution/0900-0999/0960.Delete%20Columns%20to%20Make%20Sorted%20III/README_EN.md", "title_cn": "\u5220\u5217\u9020\u5e8f III", "title_en": "Delete Columns to Make Sorted III", "question_title_slug": "delete-columns-to-make-sorted-iii", "content_en": "

    You are given an array of n strings strs, all of the same length.

    \n\n

    We may choose any deletion indices, and we delete all the characters in those indices for each string.

    \n\n

    For example, if we have strs = ["abcdef","uvwxyz"] and deletion indices {0, 2, 3}, then the final array after deletions is ["bef", "vyz"].

    \n\n

    Suppose we chose a set of deletion indices answer such that after deletions, the final array has every string (row) in lexicographic order. (i.e., (strs[0][0] <= strs[0][1] <= ... <= strs[0][strs[0].length - 1]), and (strs[1][0] <= strs[1][1] <= ... <= strs[1][strs[1].length - 1]), and so on). Return the minimum possible value of answer.length.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: strs = ["babca","bbazb"]\nOutput: 3\nExplanation: After deleting columns 0, 1, and 4, the final array is strs = ["bc", "az"].\nBoth these rows are individually in lexicographic order (ie. strs[0][0] <= strs[0][1] and strs[1][0] <= strs[1][1]).\nNote that strs[0] > strs[1] - the array strs is not necessarily in lexicographic order.
    \n\n

    Example 2:

    \n\n
    \nInput: strs = ["edcba"]\nOutput: 4\nExplanation: If we delete less than 4 columns, the only row will not be lexicographically sorted.\n
    \n\n

    Example 3:

    \n\n
    \nInput: strs = ["ghi","def","abc"]\nOutput: 0\nExplanation: All rows are already lexicographically sorted.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == strs.length
    • \n\t
    • 1 <= n <= 100
    • \n\t
    • 1 <= strs[i].length <= 100
    • \n\t
    • strs[i] consists of lowercase English letters.
    • \n
    \n\n
      \n\t
    •  
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u7531 N \u4e2a\u5c0f\u5199\u5b57\u6bcd\u5b57\u7b26\u4e32\u7ec4\u6210\u7684\u6570\u7ec4 A\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5b57\u7b26\u4e32\u957f\u5ea6\u76f8\u7b49\u3002

    \n\n

    \u9009\u53d6\u4e00\u4e2a\u5220\u9664\u7d22\u5f15\u5e8f\u5217\uff0c\u5bf9\u4e8e A \u4e2d\u7684\u6bcf\u4e2a\u5b57\u7b26\u4e32\uff0c\u5220\u9664\u5bf9\u5e94\u6bcf\u4e2a\u7d22\u5f15\u5904\u7684\u5b57\u7b26\u3002

    \n\n

    \u6bd4\u5982\uff0c\u6709 A = ["babca","bbazb"]\uff0c\u5220\u9664\u7d22\u5f15\u5e8f\u5217 {0, 1, 4}\uff0c\u5220\u9664\u540e A \u4e3a["bc","az"]\u3002

    \n\n

    \u5047\u8bbe\uff0c\u6211\u4eec\u9009\u62e9\u4e86\u4e00\u7ec4\u5220\u9664\u7d22\u5f15 D\uff0c\u90a3\u4e48\u5728\u6267\u884c\u5220\u9664\u64cd\u4f5c\u4e4b\u540e\uff0c\u6700\u7ec8\u5f97\u5230\u7684\u6570\u7ec4\u7684\u884c\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u90fd\u662f\u6309\u5b57\u5178\u5e8f\u6392\u5217\u7684\u3002

    \n\n

    \u6e05\u695a\u8d77\u89c1\uff0cA[0] \u662f\u6309\u5b57\u5178\u5e8f\u6392\u5217\u7684\uff08\u5373\uff0cA[0][0] <= A[0][1] <= ... <= A[0][A[0].length - 1]\uff09\uff0cA[1] \u662f\u6309\u5b57\u5178\u5e8f\u6392\u5217\u7684\uff08\u5373\uff0cA[1][0] <= A[1][1] <= ... <= A[1][A[1].length - 1]\uff09\uff0c\u4f9d\u6b64\u7c7b\u63a8\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de D.length \u7684\u6700\u5c0f\u53ef\u80fd\u503c\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a["babca","bbazb"]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\n\u5220\u9664 0\u30011 \u548c 4 \u8fd9\u4e09\u5217\u540e\uff0c\u6700\u7ec8\u5f97\u5230\u7684\u6570\u7ec4\u662f A = ["bc", "az"]\u3002\n\u8fd9\u4e24\u884c\u662f\u5206\u522b\u6309\u5b57\u5178\u5e8f\u6392\u5217\u7684\uff08\u5373\uff0cA[0][0] <= A[0][1] \u4e14 A[1][0] <= A[1][1]\uff09\u3002\n\u6ce8\u610f\uff0cA[0] > A[1] —— \u6570\u7ec4 A \u4e0d\u4e00\u5b9a\u662f\u6309\u5b57\u5178\u5e8f\u6392\u5217\u7684\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a["edcba"]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u5982\u679c\u5220\u9664\u7684\u5217\u5c11\u4e8e 4 \u5217\uff0c\u5219\u5269\u4e0b\u7684\u884c\u90fd\u4e0d\u4f1a\u6309\u5b57\u5178\u5e8f\u6392\u5217\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1a["ghi","def","abc"]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6240\u6709\u884c\u90fd\u5df2\u6309\u5b57\u5178\u5e8f\u6392\u5217\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= A.length <= 100
    2. \n\t
    3. 1 <= A[i].length <= 100
    4. \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minDeletionSize(vector& strs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minDeletionSize(String[] strs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minDeletionSize(self, strs):\n \"\"\"\n :type strs: List[str]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minDeletionSize(self, strs: List[str]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minDeletionSize(char ** strs, int strsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinDeletionSize(string[] strs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} strs\n * @return {number}\n */\nvar minDeletionSize = function(strs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} strs\n# @return {Integer}\ndef min_deletion_size(strs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minDeletionSize(_ strs: [String]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minDeletionSize(strs []string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minDeletionSize(strs: Array[String]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minDeletionSize(strs: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_deletion_size(strs: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $strs\n * @return Integer\n */\n function minDeletionSize($strs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minDeletionSize(strs: string[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-deletion-size strs)\n (-> (listof string?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0960](https://leetcode-cn.com/problems/delete-columns-to-make-sorted-iii)", "[\u5220\u5217\u9020\u5e8f III](/solution/0900-0999/0960.Delete%20Columns%20to%20Make%20Sorted%20III/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0960](https://leetcode.com/problems/delete-columns-to-make-sorted-iii)", "[Delete Columns to Make Sorted III](/solution/0900-0999/0960.Delete%20Columns%20to%20Make%20Sorted%20III/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "0999", "frontend_question_id": "0959", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/regions-cut-by-slashes", "url_en": "https://leetcode.com/problems/regions-cut-by-slashes", "relative_path_cn": "/solution/0900-0999/0959.Regions%20Cut%20By%20Slashes/README.md", "relative_path_en": "/solution/0900-0999/0959.Regions%20Cut%20By%20Slashes/README_EN.md", "title_cn": "\u7531\u659c\u6760\u5212\u5206\u533a\u57df", "title_en": "Regions Cut By Slashes", "question_title_slug": "regions-cut-by-slashes", "content_en": "

    An n x n grid is composed of 1 x 1 squares where each 1 x 1 square consists of a '/', '\\', or blank space ' '. These characters divide the square into contiguous regions.

    \n\n

    Given the grid grid represented as a string array, return the number of regions.

    \n\n

    Note that backslash characters are escaped, so a '\\' is represented as '\\\\'.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: grid = [" /","/ "]\nOutput: 2\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: grid = [" /","  "]\nOutput: 1\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: grid = ["\\\\/","/\\\\"]\nOutput: 4\nExplanation: (Recall that because \\ characters are escaped, "\\\\/" refers to \\/, and "/\\\\" refers to /\\.)\n
    \n\n

    Example 4:

    \n\"\"\n
    \nInput: grid = ["/\\\\","\\\\/"]\nOutput: 5\nExplanation: (Recall that because \\ characters are escaped, "\\\\/" refers to \\/, and "/\\\\" refers to /\\.)\n
    \n\n

    Example 5:

    \n\"\"\n
    \nInput: grid = ["//","/ "]\nOutput: 3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= n <= 30
    • \n\t
    • grid[i][j] is either '/', '\\', or ' '.
    • \n
    \n", "content_cn": "

    \u5728\u7531 1 x 1 \u65b9\u683c\u7ec4\u6210\u7684 N x N \u7f51\u683c grid \u4e2d\uff0c\u6bcf\u4e2a 1 x 1 \u65b9\u5757\u7531 /\u3001\\ \u6216\u7a7a\u683c\u6784\u6210\u3002\u8fd9\u4e9b\u5b57\u7b26\u4f1a\u5c06\u65b9\u5757\u5212\u5206\u4e3a\u4e00\u4e9b\u5171\u8fb9\u7684\u533a\u57df\u3002

    \n\n

    \uff08\u8bf7\u6ce8\u610f\uff0c\u53cd\u659c\u6760\u5b57\u7b26\u662f\u8f6c\u4e49\u7684\uff0c\u56e0\u6b64 \\ \u7528 "\\\\" \u8868\u793a\u3002\uff09\u3002

    \n\n

    \u8fd4\u56de\u533a\u57df\u7684\u6570\u76ee\u3002

    \n\n

     

    \n\n
      \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a\n[\n  " /",\n  "/ "\n]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a2x2 \u7f51\u683c\u5982\u4e0b\uff1a\n\"\"
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a\n[\n  " /",\n  "  "\n]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a2x2 \u7f51\u683c\u5982\u4e0b\uff1a\n\"\"
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1a\n[\n  "\\\\/",\n  "/\\\\"\n]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\uff08\u56de\u60f3\u4e00\u4e0b\uff0c\u56e0\u4e3a \\ \u5b57\u7b26\u662f\u8f6c\u4e49\u7684\uff0c\u6240\u4ee5 "\\\\/" \u8868\u793a \\/\uff0c\u800c "/\\\\" \u8868\u793a /\\\u3002\uff09\n2x2 \u7f51\u683c\u5982\u4e0b\uff1a\n\"\"
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1a\n[\n  "/\\\\",\n  "\\\\/"\n]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\uff08\u56de\u60f3\u4e00\u4e0b\uff0c\u56e0\u4e3a \\ \u5b57\u7b26\u662f\u8f6c\u4e49\u7684\uff0c\u6240\u4ee5 "/\\\\" \u8868\u793a /\\\uff0c\u800c "\\\\/" \u8868\u793a \\/\u3002\uff09\n2x2 \u7f51\u683c\u5982\u4e0b\uff1a\n\"\"
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1a\n[\n  "//",\n  "/ "\n]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a2x2 \u7f51\u683c\u5982\u4e0b\uff1a\n\"\"\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= grid.length == grid[0].length <= 30
    2. \n\t
    3. grid[i][j] \u662f '/'\u3001'\\'\u3001\u6216 ' '\u3002
    4. \n
    \n", "tags_en": ["Depth-first Search", "Union Find", "Graph"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e76\u67e5\u96c6", "\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int regionsBySlashes(vector& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int regionsBySlashes(String[] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def regionsBySlashes(self, grid):\n \"\"\"\n :type grid: List[str]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def regionsBySlashes(self, grid: List[str]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint regionsBySlashes(char ** grid, int gridSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int RegionsBySlashes(string[] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} grid\n * @return {number}\n */\nvar regionsBySlashes = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} grid\n# @return {Integer}\ndef regions_by_slashes(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func regionsBySlashes(_ grid: [String]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func regionsBySlashes(grid []string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def regionsBySlashes(grid: Array[String]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun regionsBySlashes(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn regions_by_slashes(grid: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $grid\n * @return Integer\n */\n function regionsBySlashes($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function regionsBySlashes(grid: string[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (regions-by-slashes grid)\n (-> (listof string?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0959](https://leetcode-cn.com/problems/regions-cut-by-slashes)", "[\u7531\u659c\u6760\u5212\u5206\u533a\u57df](/solution/0900-0999/0959.Regions%20Cut%20By%20Slashes/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e76\u67e5\u96c6`,`\u56fe`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0959](https://leetcode.com/problems/regions-cut-by-slashes)", "[Regions Cut By Slashes](/solution/0900-0999/0959.Regions%20Cut%20By%20Slashes/README_EN.md)", "`Depth-first Search`,`Union Find`,`Graph`", "Medium", ""]}, {"question_id": "0998", "frontend_question_id": "0958", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/check-completeness-of-a-binary-tree", "url_en": "https://leetcode.com/problems/check-completeness-of-a-binary-tree", "relative_path_cn": "/solution/0900-0999/0958.Check%20Completeness%20of%20a%20Binary%20Tree/README.md", "relative_path_en": "/solution/0900-0999/0958.Check%20Completeness%20of%20a%20Binary%20Tree/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u7684\u5b8c\u5168\u6027\u68c0\u9a8c", "title_en": "Check Completeness of a Binary Tree", "question_title_slug": "check-completeness-of-a-binary-tree", "content_en": "

    Given the root of a binary tree, determine if it is a complete binary tree.

    \n\n

    In a complete binary tree, every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as possible. It can have between 1 and 2h nodes inclusive at the last level h.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,2,3,4,5,6]\nOutput: true\nExplanation: Every level before the last is full (ie. levels with node-values {1} and {2, 3}), and all nodes in the last level ({4, 5, 6}) are as far left as possible.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [1,2,3,4,5,null,7]\nOutput: false\nExplanation: The node with value 7 isn't as far left as possible.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 100].
    • \n\t
    • 1 <= Node.val <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811\uff0c\u786e\u5b9a\u5b83\u662f\u5426\u662f\u4e00\u4e2a\u5b8c\u5168\u4e8c\u53c9\u6811\u3002

    \n\n

    \u767e\u5ea6\u767e\u79d1\u4e2d\u5bf9\u5b8c\u5168\u4e8c\u53c9\u6811\u7684\u5b9a\u4e49\u5982\u4e0b\uff1a

    \n\n

    \u82e5\u8bbe\u4e8c\u53c9\u6811\u7684\u6df1\u5ea6\u4e3a h\uff0c\u9664\u7b2c h \u5c42\u5916\uff0c\u5176\u5b83\u5404\u5c42 (1\uff5eh-1) \u7684\u7ed3\u70b9\u6570\u90fd\u8fbe\u5230\u6700\u5927\u4e2a\u6570\uff0c\u7b2c h \u5c42\u6240\u6709\u7684\u7ed3\u70b9\u90fd\u8fde\u7eed\u96c6\u4e2d\u5728\u6700\u5de6\u8fb9\uff0c\u8fd9\u5c31\u662f\u5b8c\u5168\u4e8c\u53c9\u6811\u3002\uff08\u6ce8\uff1a\u7b2c h \u5c42\u53ef\u80fd\u5305\u542b 1~ 2h \u4e2a\u8282\u70b9\u3002\uff09

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1a[1,2,3,4,5,6]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u6700\u540e\u4e00\u5c42\u524d\u7684\u6bcf\u4e00\u5c42\u90fd\u662f\u6ee1\u7684\uff08\u5373\uff0c\u7ed3\u70b9\u503c\u4e3a {1} \u548c {2,3} \u7684\u4e24\u5c42\uff09\uff0c\u4e14\u6700\u540e\u4e00\u5c42\u4e2d\u7684\u6240\u6709\u7ed3\u70b9\uff08{4,5,6}\uff09\u90fd\u5c3d\u53ef\u80fd\u5730\u5411\u5de6\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1a[1,2,3,4,5,null,7]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u503c\u4e3a 7 \u7684\u7ed3\u70b9\u6ca1\u6709\u5c3d\u53ef\u80fd\u9760\u5411\u5de6\u4fa7\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. \u6811\u4e2d\u5c06\u4f1a\u6709 1 \u5230 100 \u4e2a\u7ed3\u70b9\u3002
    2. \n
    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n bool isCompleteTree(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public boolean isCompleteTree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def isCompleteTree(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def isCompleteTree(self, root: TreeNode) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nbool isCompleteTree(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public bool IsCompleteTree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {boolean}\n */\nvar isCompleteTree = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Boolean}\ndef is_complete_tree(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func isCompleteTree(_ root: TreeNode?) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc isCompleteTree(root *TreeNode) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def isCompleteTree(root: TreeNode): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun isCompleteTree(root: TreeNode?): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn is_complete_tree(root: Option>>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Boolean\n */\n function isCompleteTree($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction isCompleteTree(root: TreeNode | null): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (is-complete-tree root)\n (-> (or/c tree-node? #f) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0958](https://leetcode-cn.com/problems/check-completeness-of-a-binary-tree)", "[\u4e8c\u53c9\u6811\u7684\u5b8c\u5168\u6027\u68c0\u9a8c](/solution/0900-0999/0958.Check%20Completeness%20of%20a%20Binary%20Tree/README.md)", "`\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0958](https://leetcode.com/problems/check-completeness-of-a-binary-tree)", "[Check Completeness of a Binary Tree](/solution/0900-0999/0958.Check%20Completeness%20of%20a%20Binary%20Tree/README_EN.md)", "`Tree`", "Medium", ""]}, {"question_id": "0994", "frontend_question_id": "0957", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/prison-cells-after-n-days", "url_en": "https://leetcode.com/problems/prison-cells-after-n-days", "relative_path_cn": "/solution/0900-0999/0957.Prison%20Cells%20After%20N%20Days/README.md", "relative_path_en": "/solution/0900-0999/0957.Prison%20Cells%20After%20N%20Days/README_EN.md", "title_cn": "N \u5929\u540e\u7684\u7262\u623f", "title_en": "Prison Cells After N Days", "question_title_slug": "prison-cells-after-n-days", "content_en": "

    There are 8 prison cells in a row and each cell is either occupied or vacant.

    \n\n

    Each day, whether the cell is occupied or vacant changes according to the following rules:

    \n\n
      \n\t
    • If a cell has two adjacent neighbors that are both occupied or both vacant, then the cell becomes occupied.
    • \n\t
    • Otherwise, it becomes vacant.
    • \n
    \n\n

    Note that because the prison is a row, the first and the last cells in the row can't have two adjacent neighbors.

    \n\n

    You are given an integer array cells where cells[i] == 1 if the ith cell is occupied and cells[i] == 0 if the ith cell is vacant, and you are given an integer n.

    \n\n

    Return the state of the prison after n days (i.e., n such changes described above).

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: cells = [0,1,0,1,1,0,0,1], n = 7\nOutput: [0,0,1,1,0,0,0,0]\nExplanation: The following table summarizes the state of the prison on each day:\nDay 0: [0, 1, 0, 1, 1, 0, 0, 1]\nDay 1: [0, 1, 1, 0, 0, 0, 0, 0]\nDay 2: [0, 0, 0, 0, 1, 1, 1, 0]\nDay 3: [0, 1, 1, 0, 0, 1, 0, 0]\nDay 4: [0, 0, 0, 0, 0, 1, 0, 0]\nDay 5: [0, 1, 1, 1, 0, 1, 0, 0]\nDay 6: [0, 0, 1, 0, 1, 1, 0, 0]\nDay 7: [0, 0, 1, 1, 0, 0, 0, 0]\n
    \n\n

    Example 2:

    \n\n
    \nInput: cells = [1,0,0,1,0,0,1,0], n = 1000000000\nOutput: [0,0,1,1,1,1,1,0]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • cells.length == 8
    • \n\t
    • cells[i] is either 0 or 1.
    • \n\t
    • 1 <= n <= 109
    • \n
    \n", "content_cn": "

    8 \u95f4\u7262\u623f\u6392\u6210\u4e00\u6392\uff0c\u6bcf\u95f4\u7262\u623f\u4e0d\u662f\u6709\u4eba\u4f4f\u5c31\u662f\u7a7a\u7740\u3002

    \n\n

    \u6bcf\u5929\uff0c\u65e0\u8bba\u7262\u623f\u662f\u88ab\u5360\u7528\u6216\u7a7a\u7f6e\uff0c\u90fd\u4f1a\u6839\u636e\u4ee5\u4e0b\u89c4\u5219\u8fdb\u884c\u66f4\u6539\uff1a

    \n\n
      \n\t
    • \u5982\u679c\u4e00\u95f4\u7262\u623f\u7684\u4e24\u4e2a\u76f8\u90bb\u7684\u623f\u95f4\u90fd\u88ab\u5360\u7528\u6216\u90fd\u662f\u7a7a\u7684\uff0c\u90a3\u4e48\u8be5\u7262\u623f\u5c31\u4f1a\u88ab\u5360\u7528\u3002
    • \n\t
    • \u5426\u5219\uff0c\u5b83\u5c31\u4f1a\u88ab\u7a7a\u7f6e\u3002
    • \n
    \n\n

    \uff08\u8bf7\u6ce8\u610f\uff0c\u7531\u4e8e\u76d1\u72f1\u4e2d\u7684\u7262\u623f\u6392\u6210\u4e00\u884c\uff0c\u6240\u4ee5\u884c\u4e2d\u7684\u7b2c\u4e00\u4e2a\u548c\u6700\u540e\u4e00\u4e2a\u623f\u95f4\u65e0\u6cd5\u6709\u4e24\u4e2a\u76f8\u90bb\u7684\u623f\u95f4\u3002\uff09

    \n\n

    \u6211\u4eec\u7528\u4ee5\u4e0b\u65b9\u5f0f\u63cf\u8ff0\u76d1\u72f1\u7684\u5f53\u524d\u72b6\u6001\uff1a\u5982\u679c\u7b2c i \u95f4\u7262\u623f\u88ab\u5360\u7528\uff0c\u5219 cell[i]==1\uff0c\u5426\u5219 cell[i]==0\u3002

    \n\n

    \u6839\u636e\u76d1\u72f1\u7684\u521d\u59cb\u72b6\u6001\uff0c\u5728 N \u5929\u540e\u8fd4\u56de\u76d1\u72f1\u7684\u72b6\u51b5\uff08\u548c\u4e0a\u8ff0 N \u79cd\u53d8\u5316\uff09\u3002

    \n\n

     

    \n\n
      \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1acells = [0,1,0,1,1,0,0,1], N = 7\n\u8f93\u51fa\uff1a[0,0,1,1,0,0,0,0]\n\u89e3\u91ca\uff1a\n\u4e0b\u8868\u6982\u8ff0\u4e86\u76d1\u72f1\u6bcf\u5929\u7684\u72b6\u51b5\uff1a\nDay 0: [0, 1, 0, 1, 1, 0, 0, 1]\nDay 1: [0, 1, 1, 0, 0, 0, 0, 0]\nDay 2: [0, 0, 0, 0, 1, 1, 1, 0]\nDay 3: [0, 1, 1, 0, 0, 1, 0, 0]\nDay 4: [0, 0, 0, 0, 0, 1, 0, 0]\nDay 5: [0, 1, 1, 1, 0, 1, 0, 0]\nDay 6: [0, 0, 1, 0, 1, 1, 0, 0]\nDay 7: [0, 0, 1, 1, 0, 0, 0, 0]\n\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1acells = [1,0,0,1,0,0,1,0], N = 1000000000\n\u8f93\u51fa\uff1a[0,0,1,1,1,1,1,0]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. cells.length == 8
    2. \n\t
    3. cells[i] \u7684\u503c\u4e3a 0 \u6216 1 
    4. \n\t
    5. 1 <= N <= 10^9
    6. \n
    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector prisonAfterNDays(vector& cells, int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] prisonAfterNDays(int[] cells, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def prisonAfterNDays(self, cells, n):\n \"\"\"\n :type cells: List[int]\n :type n: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def prisonAfterNDays(self, cells: List[int], n: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* prisonAfterNDays(int* cells, int cellsSize, int n, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] PrisonAfterNDays(int[] cells, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} cells\n * @param {number} n\n * @return {number[]}\n */\nvar prisonAfterNDays = function(cells, n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} cells\n# @param {Integer} n\n# @return {Integer[]}\ndef prison_after_n_days(cells, n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func prisonAfterNDays(_ cells: [Int], _ n: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func prisonAfterNDays(cells []int, n int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def prisonAfterNDays(cells: Array[Int], n: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun prisonAfterNDays(cells: IntArray, n: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn prison_after_n_days(cells: Vec, n: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $cells\n * @param Integer $n\n * @return Integer[]\n */\n function prisonAfterNDays($cells, $n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function prisonAfterNDays(cells: number[], n: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (prison-after-n-days cells n)\n (-> (listof exact-integer?) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0957](https://leetcode-cn.com/problems/prison-cells-after-n-days)", "[N \u5929\u540e\u7684\u7262\u623f](/solution/0900-0999/0957.Prison%20Cells%20After%20N%20Days/README.md)", "`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0957](https://leetcode.com/problems/prison-cells-after-n-days)", "[Prison Cells After N Days](/solution/0900-0999/0957.Prison%20Cells%20After%20N%20Days/README_EN.md)", "`Hash Table`", "Medium", ""]}, {"question_id": "0993", "frontend_question_id": "0956", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/tallest-billboard", "url_en": "https://leetcode.com/problems/tallest-billboard", "relative_path_cn": "/solution/0900-0999/0956.Tallest%20Billboard/README.md", "relative_path_en": "/solution/0900-0999/0956.Tallest%20Billboard/README_EN.md", "title_cn": "\u6700\u9ad8\u7684\u5e7f\u544a\u724c", "title_en": "Tallest Billboard", "question_title_slug": "tallest-billboard", "content_en": "

    You are installing a billboard and want it to have the largest height. The billboard will have two steel supports, one on each side. Each steel support must be an equal height.

    \n\n

    You are given a collection of rods that can be welded together. For example, if you have rods of lengths 1, 2, and 3, you can weld them together to make a support of length 6.

    \n\n

    Return the largest possible height of your billboard installation. If you cannot support the billboard, return 0.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: rods = [1,2,3,6]\nOutput: 6\nExplanation: We have two disjoint subsets {1,2,3} and {6}, which have the same sum = 6.\n
    \n\n

    Example 2:

    \n\n
    \nInput: rods = [1,2,3,4,5,6]\nOutput: 10\nExplanation: We have two disjoint subsets {2,3,5} and {4,6}, which have the same sum = 10.\n
    \n\n

    Example 3:

    \n\n
    \nInput: rods = [1,2]\nOutput: 0\nExplanation: The billboard cannot be supported, so we return 0.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= rods.length <= 20
    • \n\t
    • 1 <= rods[i] <= 1000
    • \n\t
    • sum(rods[i]) <= 5000
    • \n
    \n", "content_cn": "

    \u4f60\u6b63\u5728\u5b89\u88c5\u4e00\u4e2a\u5e7f\u544a\u724c\uff0c\u5e76\u5e0c\u671b\u5b83\u9ad8\u5ea6\u6700\u5927\u3002\u8fd9\u5757\u5e7f\u544a\u724c\u5c06\u6709\u4e24\u4e2a\u94a2\u5236\u652f\u67b6\uff0c\u4e24\u8fb9\u5404\u4e00\u4e2a\u3002\u6bcf\u4e2a\u94a2\u652f\u67b6\u7684\u9ad8\u5ea6\u5fc5\u987b\u76f8\u7b49\u3002

    \n\n

    \u4f60\u6709\u4e00\u5806\u53ef\u4ee5\u710a\u63a5\u5728\u4e00\u8d77\u7684\u94a2\u7b4b rods\u3002\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u5982\u679c\u94a2\u7b4b\u7684\u957f\u5ea6\u4e3a 1\u30012 \u548c 3\uff0c\u5219\u53ef\u4ee5\u5c06\u5b83\u4eec\u710a\u63a5\u5728\u4e00\u8d77\u5f62\u6210\u957f\u5ea6\u4e3a 6 \u7684\u652f\u67b6\u3002

    \n\n

    \u8fd4\u56de\u5e7f\u544a\u724c\u7684\u6700\u5927\u53ef\u80fd\u5b89\u88c5\u9ad8\u5ea6\u3002\u5982\u679c\u6ca1\u6cd5\u5b89\u88c5\u5e7f\u544a\u724c\uff0c\u8bf7\u8fd4\u56de 0\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a[1,2,3,6]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u6211\u4eec\u6709\u4e24\u4e2a\u4e0d\u76f8\u4ea4\u7684\u5b50\u96c6 {1,2,3} \u548c {6}\uff0c\u5b83\u4eec\u5177\u6709\u76f8\u540c\u7684\u548c sum = 6\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a[1,2,3,4,5,6]\n\u8f93\u51fa\uff1a10\n\u89e3\u91ca\uff1a\u6211\u4eec\u6709\u4e24\u4e2a\u4e0d\u76f8\u4ea4\u7684\u5b50\u96c6 {2,3,5} \u548c {4,6}\uff0c\u5b83\u4eec\u5177\u6709\u76f8\u540c\u7684\u548c sum = 10\u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1a[1,2]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6ca1\u6cd5\u5b89\u88c5\u5e7f\u544a\u724c\uff0c\u6240\u4ee5\u8fd4\u56de 0\u3002
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 0 <= rods.length <= 20
    2. \n\t
    3. 1 <= rods[i] <= 1000
    4. \n\t
    5. \u94a2\u7b4b\u7684\u957f\u5ea6\u603b\u548c\u6700\u591a\u4e3a 5000
    6. \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int tallestBillboard(vector& rods) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int tallestBillboard(int[] rods) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def tallestBillboard(self, rods):\n \"\"\"\n :type rods: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def tallestBillboard(self, rods: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint tallestBillboard(int* rods, int rodsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int TallestBillboard(int[] rods) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} rods\n * @return {number}\n */\nvar tallestBillboard = function(rods) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} rods\n# @return {Integer}\ndef tallest_billboard(rods)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func tallestBillboard(_ rods: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func tallestBillboard(rods []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def tallestBillboard(rods: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun tallestBillboard(rods: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn tallest_billboard(rods: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $rods\n * @return Integer\n */\n function tallestBillboard($rods) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function tallestBillboard(rods: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (tallest-billboard rods)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0956](https://leetcode-cn.com/problems/tallest-billboard)", "[\u6700\u9ad8\u7684\u5e7f\u544a\u724c](/solution/0900-0999/0956.Tallest%20Billboard/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0956](https://leetcode.com/problems/tallest-billboard)", "[Tallest Billboard](/solution/0900-0999/0956.Tallest%20Billboard/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "0992", "frontend_question_id": "0955", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/delete-columns-to-make-sorted-ii", "url_en": "https://leetcode.com/problems/delete-columns-to-make-sorted-ii", "relative_path_cn": "/solution/0900-0999/0955.Delete%20Columns%20to%20Make%20Sorted%20II/README.md", "relative_path_en": "/solution/0900-0999/0955.Delete%20Columns%20to%20Make%20Sorted%20II/README_EN.md", "title_cn": "\u5220\u5217\u9020\u5e8f II", "title_en": "Delete Columns to Make Sorted II", "question_title_slug": "delete-columns-to-make-sorted-ii", "content_en": "

    You are given an array of n strings strs, all of the same length.

    \n\n

    We may choose any deletion indices, and we delete all the characters in those indices for each string.

    \n\n

    For example, if we have strs = ["abcdef","uvwxyz"] and deletion indices {0, 2, 3}, then the final array after deletions is ["bef", "vyz"].

    \n\n

    Suppose we chose a set of deletion indices answer such that after deletions, the final array has its elements in lexicographic order (i.e., strs[0] <= strs[1] <= strs[2] <= ... <= strs[n - 1]). Return the minimum possible value of answer.length.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: strs = ["ca","bb","ac"]\nOutput: 1\nExplanation: \nAfter deleting the first column, strs = ["a", "b", "c"].\nNow strs is in lexicographic order (ie. strs[0] <= strs[1] <= strs[2]).\nWe require at least 1 deletion since initially strs was not in lexicographic order, so the answer is 1.\n
    \n\n

    Example 2:

    \n\n
    \nInput: strs = ["xc","yb","za"]\nOutput: 0\nExplanation: \nstrs is already in lexicographic order, so we do not need to delete anything.\nNote that the rows of strs are not necessarily in lexicographic order:\ni.e., it is NOT necessarily true that (strs[0][0] <= strs[0][1] <= ...)\n
    \n\n

    Example 3:

    \n\n
    \nInput: strs = ["zyx","wvu","tsr"]\nOutput: 3\nExplanation: We have to delete every column.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == strs.length
    • \n\t
    • 1 <= n <= 100
    • \n\t
    • 1 <= strs[i].length <= 100
    • \n\t
    • strs[i] consists of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u7531 n \u4e2a\u5b57\u7b26\u4e32\u7ec4\u6210\u7684\u6570\u7ec4 strs\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5b57\u7b26\u4e32\u957f\u5ea6\u76f8\u7b49\u3002

    \n\n

    \u9009\u53d6\u4e00\u4e2a\u5220\u9664\u7d22\u5f15\u5e8f\u5217\uff0c\u5bf9\u4e8e strs \u4e2d\u7684\u6bcf\u4e2a\u5b57\u7b26\u4e32\uff0c\u5220\u9664\u5bf9\u5e94\u6bcf\u4e2a\u7d22\u5f15\u5904\u7684\u5b57\u7b26\u3002

    \n\n

    \u6bd4\u5982\uff0c\u6709 strs = [\"abcdef\", \"uvwxyz\"]\uff0c\u5220\u9664\u7d22\u5f15\u5e8f\u5217\u00a0{0, 2, 3}\uff0c\u5220\u9664\u540e strs \u4e3a[\"bef\", \"vyz\"]\u3002

    \n\n

    \u5047\u8bbe\uff0c\u6211\u4eec\u9009\u62e9\u4e86\u4e00\u7ec4\u5220\u9664\u7d22\u5f15 answer\uff0c\u90a3\u4e48\u5728\u6267\u884c\u5220\u9664\u64cd\u4f5c\u4e4b\u540e\uff0c\u6700\u7ec8\u5f97\u5230\u7684\u6570\u7ec4\u7684\u5143\u7d20\u662f\u6309 \u5b57\u5178\u5e8f\uff08strs[0] <= strs[1] <= strs[2] ... <= strs[n - 1]\uff09\u6392\u5217\u7684\uff0c\u7136\u540e\u8bf7\u4f60\u8fd4\u56de answer.length\u00a0\u7684\u6700\u5c0f\u53ef\u80fd\u503c\u3002

    \n\n

    \u00a0

    \n\n
      \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1astrs = [\"ca\",\"bb\",\"ac\"]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a \n\u5220\u9664\u7b2c\u4e00\u5217\u540e\uff0cstrs = [\"a\", \"b\", \"c\"]\u3002\n\u73b0\u5728 strs \u4e2d\u5143\u7d20\u662f\u6309\u5b57\u5178\u6392\u5217\u7684 (\u5373\uff0cstrs[0] <= strs[1] <= strs[2])\u3002\n\u6211\u4eec\u81f3\u5c11\u9700\u8981\u8fdb\u884c 1 \u6b21\u5220\u9664\uff0c\u56e0\u4e3a\u6700\u521d strs \u4e0d\u662f\u6309\u5b57\u5178\u5e8f\u6392\u5217\u7684\uff0c\u6240\u4ee5\u7b54\u6848\u662f 1\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1astrs = [\"xc\",\"yb\",\"za\"]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\nstrs \u7684\u5217\u5df2\u7ecf\u662f\u6309\u5b57\u5178\u5e8f\u6392\u5217\u4e86\uff0c\u6240\u4ee5\u6211\u4eec\u4e0d\u9700\u8981\u5220\u9664\u4efb\u4f55\u4e1c\u897f\u3002\n\u6ce8\u610f strs \u7684\u884c\u4e0d\u9700\u8981\u6309\u5b57\u5178\u5e8f\u6392\u5217\u3002\n\u4e5f\u5c31\u662f\u8bf4\uff0cstrs[0][0] <= strs[0][1] <= ... \u4e0d\u4e00\u5b9a\u6210\u7acb\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1astrs = [\"zyx\",\"wvu\",\"tsr\"]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\n\u6211\u4eec\u5fc5\u987b\u5220\u6389\u6bcf\u4e00\u5217\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == strs.length
    • \n\t
    • 1 <= n <= 100
    • \n\t
    • 1 <= strs[i].length <= 100
    • \n\t
    • strs[i] \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minDeletionSize(vector& strs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minDeletionSize(String[] strs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minDeletionSize(self, strs):\n \"\"\"\n :type strs: List[str]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minDeletionSize(self, strs: List[str]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minDeletionSize(char ** strs, int strsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinDeletionSize(string[] strs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} strs\n * @return {number}\n */\nvar minDeletionSize = function(strs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} strs\n# @return {Integer}\ndef min_deletion_size(strs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minDeletionSize(_ strs: [String]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minDeletionSize(strs []string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minDeletionSize(strs: Array[String]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minDeletionSize(strs: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_deletion_size(strs: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $strs\n * @return Integer\n */\n function minDeletionSize($strs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minDeletionSize(strs: string[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-deletion-size strs)\n (-> (listof string?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0955](https://leetcode-cn.com/problems/delete-columns-to-make-sorted-ii)", "[\u5220\u5217\u9020\u5e8f II](/solution/0900-0999/0955.Delete%20Columns%20to%20Make%20Sorted%20II/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0955](https://leetcode.com/problems/delete-columns-to-make-sorted-ii)", "[Delete Columns to Make Sorted II](/solution/0900-0999/0955.Delete%20Columns%20to%20Make%20Sorted%20II/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "0991", "frontend_question_id": "0954", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/array-of-doubled-pairs", "url_en": "https://leetcode.com/problems/array-of-doubled-pairs", "relative_path_cn": "/solution/0900-0999/0954.Array%20of%20Doubled%20Pairs/README.md", "relative_path_en": "/solution/0900-0999/0954.Array%20of%20Doubled%20Pairs/README_EN.md", "title_cn": "\u4e8c\u500d\u6570\u5bf9\u6570\u7ec4", "title_en": "Array of Doubled Pairs", "question_title_slug": "array-of-doubled-pairs", "content_en": "

    Given an array of integers arr of even length, return true if and only if it is possible to reorder it such that arr[2 * i + 1] = 2 * arr[2 * i] for every 0 <= i < len(arr) / 2.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr = [3,1,3,6]\nOutput: false\n
    \n\n

    Example 2:

    \n\n
    \nInput: arr = [2,1,2,6]\nOutput: false\n
    \n\n

    Example 3:

    \n\n
    \nInput: arr = [4,-2,2,-4]\nOutput: true\nExplanation: We can take two groups, [-2,-4] and [2,4] to form [-2,-4,2,4] or [2,4,-2,-4].\n
    \n\n

    Example 4:

    \n\n
    \nInput: arr = [1,2,4,16,8,4]\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= arr.length <= 3 * 104
    • \n\t
    • arr.length is even.
    • \n\t
    • -105 <= arr[i] <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u957f\u5ea6\u4e3a\u5076\u6570\u7684\u6574\u6570\u6570\u7ec4 arr\uff0c\u53ea\u6709\u5bf9 arr \u8fdb\u884c\u91cd\u7ec4\u540e\u53ef\u4ee5\u6ee1\u8db3 \u201c\u5bf9\u4e8e\u6bcf\u4e2a 0 <=\u00a0i < len(arr) / 2\uff0c\u90fd\u6709 arr[2 * i + 1] = 2 * arr[2 * i]\u201d\u00a0\u65f6\uff0c\u8fd4\u56de true\uff1b\u5426\u5219\uff0c\u8fd4\u56de false\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [3,1,3,6]\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [2,1,2,6]\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [4,-2,2,-4]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u53ef\u4ee5\u7528 [-2,-4] \u548c [2,4] \u8fd9\u4e24\u7ec4\u7ec4\u6210 [-2,-4,2,4] \u6216\u662f [2,4,-2,-4]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [1,2,4,16,8,4]\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= arr.length <= 3 * 104
    • \n\t
    • arr.length \u662f\u5076\u6570
    • \n\t
    • -105 <= arr[i] <= 105
    • \n
    \n", "tags_en": ["Array", "Hash Table"], "tags_cn": ["\u6570\u7ec4", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canReorderDoubled(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canReorderDoubled(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canReorderDoubled(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canReorderDoubled(self, arr: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canReorderDoubled(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanReorderDoubled(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {boolean}\n */\nvar canReorderDoubled = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Boolean}\ndef can_reorder_doubled(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canReorderDoubled(_ arr: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canReorderDoubled(arr []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canReorderDoubled(arr: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canReorderDoubled(arr: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_reorder_doubled(arr: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Boolean\n */\n function canReorderDoubled($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canReorderDoubled(arr: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-reorder-doubled arr)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0954](https://leetcode-cn.com/problems/array-of-doubled-pairs)", "[\u4e8c\u500d\u6570\u5bf9\u6570\u7ec4](/solution/0900-0999/0954.Array%20of%20Doubled%20Pairs/README.md)", "`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0954](https://leetcode.com/problems/array-of-doubled-pairs)", "[Array of Doubled Pairs](/solution/0900-0999/0954.Array%20of%20Doubled%20Pairs/README_EN.md)", "`Array`,`Hash Table`", "Medium", ""]}, {"question_id": "0990", "frontend_question_id": "0953", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/verifying-an-alien-dictionary", "url_en": "https://leetcode.com/problems/verifying-an-alien-dictionary", "relative_path_cn": "/solution/0900-0999/0953.Verifying%20an%20Alien%20Dictionary/README.md", "relative_path_en": "/solution/0900-0999/0953.Verifying%20an%20Alien%20Dictionary/README_EN.md", "title_cn": "\u9a8c\u8bc1\u5916\u661f\u8bed\u8bcd\u5178", "title_en": "Verifying an Alien Dictionary", "question_title_slug": "verifying-an-alien-dictionary", "content_en": "

    In an alien language, surprisingly they also use english lowercase letters, but possibly in a different order. The order of the alphabet is some permutation of lowercase letters.

    \n\n

    Given a sequence of words written in the alien language, and the order of the alphabet, return true if and only if the given words are sorted lexicographicaly in this alien language.

    \n

     

    \n

    Example 1:

    \n\n
    \nInput: words = ["hello","leetcode"], order = "hlabcdefgijkmnopqrstuvwxyz"\nOutput: true\nExplanation: As 'h' comes before 'l' in this language, then the sequence is sorted.\n
    \n\n

    Example 2:

    \n\n
    \nInput: words = ["word","world","row"], order = "worldabcefghijkmnpqstuvxyz"\nOutput: false\nExplanation: As 'd' comes after 'l' in this language, then words[0] > words[1], hence the sequence is unsorted.\n
    \n\n

    Example 3:

    \n\n
    \nInput: words = ["apple","app"], order = "abcdefghijklmnopqrstuvwxyz"\nOutput: false\nExplanation: The first three characters "app" match, and the second string is shorter (in size.) According to lexicographical rules "apple" > "app", because 'l' > '∅', where '∅' is defined as the blank character which is less than any other character (More info).\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= words.length <= 100
    • \n\t
    • 1 <= words[i].length <= 20
    • \n\t
    • order.length == 26
    • \n\t
    • All characters in words[i] and order are English lowercase letters.
    • \n
    \n", "content_cn": "

    \u67d0\u79cd\u5916\u661f\u8bed\u4e5f\u4f7f\u7528\u82f1\u6587\u5c0f\u5199\u5b57\u6bcd\uff0c\u4f46\u53ef\u80fd\u987a\u5e8f order \u4e0d\u540c\u3002\u5b57\u6bcd\u8868\u7684\u987a\u5e8f\uff08order\uff09\u662f\u4e00\u4e9b\u5c0f\u5199\u5b57\u6bcd\u7684\u6392\u5217\u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u7ec4\u7528\u5916\u661f\u8bed\u4e66\u5199\u7684\u5355\u8bcd words\uff0c\u4ee5\u53ca\u5176\u5b57\u6bcd\u8868\u7684\u987a\u5e8f order\uff0c\u53ea\u6709\u5f53\u7ed9\u5b9a\u7684\u5355\u8bcd\u5728\u8fd9\u79cd\u5916\u661f\u8bed\u4e2d\u6309\u5b57\u5178\u5e8f\u6392\u5217\u65f6\uff0c\u8fd4\u56de true\uff1b\u5426\u5219\uff0c\u8fd4\u56de false\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1awords = ["hello","leetcode"], order = "hlabcdefgijkmnopqrstuvwxyz"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u5728\u8be5\u8bed\u8a00\u7684\u5b57\u6bcd\u8868\u4e2d\uff0c'h' \u4f4d\u4e8e 'l' \u4e4b\u524d\uff0c\u6240\u4ee5\u5355\u8bcd\u5e8f\u5217\u662f\u6309\u5b57\u5178\u5e8f\u6392\u5217\u7684\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1awords = ["word","world","row"], order = "worldabcefghijkmnpqstuvxyz"\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u5728\u8be5\u8bed\u8a00\u7684\u5b57\u6bcd\u8868\u4e2d\uff0c'd' \u4f4d\u4e8e 'l' \u4e4b\u540e\uff0c\u90a3\u4e48 words[0] > words[1]\uff0c\u56e0\u6b64\u5355\u8bcd\u5e8f\u5217\u4e0d\u662f\u6309\u5b57\u5178\u5e8f\u6392\u5217\u7684\u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1awords = ["apple","app"], order = "abcdefghijklmnopqrstuvwxyz"\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u5f53\u524d\u4e09\u4e2a\u5b57\u7b26 "app" \u5339\u914d\u65f6\uff0c\u7b2c\u4e8c\u4e2a\u5b57\u7b26\u4e32\u76f8\u5bf9\u77ed\u4e00\u4e9b\uff0c\u7136\u540e\u6839\u636e\u8bcd\u5178\u7f16\u7e82\u89c4\u5219 "apple" > "app"\uff0c\u56e0\u4e3a 'l' > '∅'\uff0c\u5176\u4e2d '∅' \u662f\u7a7a\u767d\u5b57\u7b26\uff0c\u5b9a\u4e49\u4e3a\u6bd4\u4efb\u4f55\u5176\u4ed6\u5b57\u7b26\u90fd\u5c0f\uff08\u66f4\u591a\u4fe1\u606f\uff09\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= words.length <= 100
    2. \n\t
    3. 1 <= words[i].length <= 20
    4. \n\t
    5. order.length == 26
    6. \n\t
    7. \u5728 words[i] \u548c order \u4e2d\u7684\u6240\u6709\u5b57\u7b26\u90fd\u662f\u82f1\u6587\u5c0f\u5199\u5b57\u6bcd\u3002
    8. \n
    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isAlienSorted(vector& words, string order) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isAlienSorted(String[] words, String order) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isAlienSorted(self, words, order):\n \"\"\"\n :type words: List[str]\n :type order: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isAlienSorted(self, words: List[str], order: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isAlienSorted(char ** words, int wordsSize, char * order){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsAlienSorted(string[] words, string order) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @param {string} order\n * @return {boolean}\n */\nvar isAlienSorted = function(words, order) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @param {String} order\n# @return {Boolean}\ndef is_alien_sorted(words, order)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isAlienSorted(_ words: [String], _ order: String) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isAlienSorted(words []string, order string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isAlienSorted(words: Array[String], order: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isAlienSorted(words: Array, order: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_alien_sorted(words: Vec, order: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @param String $order\n * @return Boolean\n */\n function isAlienSorted($words, $order) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isAlienSorted(words: string[], order: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-alien-sorted words order)\n (-> (listof string?) string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0953](https://leetcode-cn.com/problems/verifying-an-alien-dictionary)", "[\u9a8c\u8bc1\u5916\u661f\u8bed\u8bcd\u5178](/solution/0900-0999/0953.Verifying%20an%20Alien%20Dictionary/README.md)", "`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0953](https://leetcode.com/problems/verifying-an-alien-dictionary)", "[Verifying an Alien Dictionary](/solution/0900-0999/0953.Verifying%20an%20Alien%20Dictionary/README_EN.md)", "`Hash Table`", "Easy", ""]}, {"question_id": "0989", "frontend_question_id": "0952", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/largest-component-size-by-common-factor", "url_en": "https://leetcode.com/problems/largest-component-size-by-common-factor", "relative_path_cn": "/solution/0900-0999/0952.Largest%20Component%20Size%20by%20Common%20Factor/README.md", "relative_path_en": "/solution/0900-0999/0952.Largest%20Component%20Size%20by%20Common%20Factor/README_EN.md", "title_cn": "\u6309\u516c\u56e0\u6570\u8ba1\u7b97\u6700\u5927\u7ec4\u4ef6\u5927\u5c0f", "title_en": "Largest Component Size by Common Factor", "question_title_slug": "largest-component-size-by-common-factor", "content_en": "

    Given a non-empty array of unique positive integers nums, consider the following graph:

    \n\n
      \n\t
    • There are nums.length nodes, labelled nums[0] to nums[nums.length - 1];
    • \n\t
    • There is an edge between nums[i] and nums[j] if and only if nums[i] and nums[j] share a common factor greater than 1.
    • \n
    \n\n

    Return the size of the largest connected component in the graph.

    \n\n

     

    \n\n
      \n
    \n\n
    \n

    Example 1:

    \n\n
    \nInput: nums = [4,6,15,35]\nOutput: 4\n\"\"\n
    \n\n
    \n

    Example 2:

    \n\n
    \nInput: nums = [20,50,9,63]\nOutput: 2\n\"\"\n
    \n\n
    \n

    Example 3:

    \n\n
    \nInput: nums = [2,3,6,7,4,12,21,39]\nOutput: 8\n\"\"\n
    \n\n

    Note:

    \n\n
      \n\t
    1. 1 <= nums.length <= 20000
    2. \n\t
    3. 1 <= nums[i] <= 100000
    4. \n
    \n
    \n
    \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u7531\u4e0d\u540c\u6b63\u6574\u6570\u7684\u7ec4\u6210\u7684\u975e\u7a7a\u6570\u7ec4 A\uff0c\u8003\u8651\u4e0b\u9762\u7684\u56fe\uff1a

    \n\n
      \n\t
    • \u6709\u00a0A.length\u00a0\u4e2a\u8282\u70b9\uff0c\u6309\u4ece\u00a0A[0]\u00a0\u5230\u00a0A[A.length - 1]\u00a0\u6807\u8bb0\uff1b
    • \n\t
    • \u53ea\u6709\u5f53 A[i] \u548c A[j] \u5171\u7528\u4e00\u4e2a\u5927\u4e8e 1 \u7684\u516c\u56e0\u6570\u65f6\uff0cA[i]\u00a0\u548c A[j] \u4e4b\u95f4\u624d\u6709\u4e00\u6761\u8fb9\u3002
    • \n
    \n\n

    \u8fd4\u56de\u56fe\u4e2d\u6700\u5927\u8fde\u901a\u7ec4\u4ef6\u7684\u5927\u5c0f\u3002

    \n\n

    \u00a0

    \n\n
      \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[4,6,15,35]\n\u8f93\u51fa\uff1a4\n\"\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[20,50,9,63]\n\u8f93\u51fa\uff1a2\n\"\"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[2,3,6,7,4,12,21,39]\n\u8f93\u51fa\uff1a8\n\"\"\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= A.length <= 20000
    2. \n\t
    3. 1 <= A[i] <= 100000
    4. \n
    \n", "tags_en": ["Union Find", "Math"], "tags_cn": ["\u5e76\u67e5\u96c6", "\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int largestComponentSize(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int largestComponentSize(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def largestComponentSize(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def largestComponentSize(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint largestComponentSize(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LargestComponentSize(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar largestComponentSize = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef largest_component_size(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func largestComponentSize(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func largestComponentSize(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def largestComponentSize(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun largestComponentSize(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn largest_component_size(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function largestComponentSize($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function largestComponentSize(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (largest-component-size nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0952](https://leetcode-cn.com/problems/largest-component-size-by-common-factor)", "[\u6309\u516c\u56e0\u6570\u8ba1\u7b97\u6700\u5927\u7ec4\u4ef6\u5927\u5c0f](/solution/0900-0999/0952.Largest%20Component%20Size%20by%20Common%20Factor/README.md)", "`\u5e76\u67e5\u96c6`,`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[0952](https://leetcode.com/problems/largest-component-size-by-common-factor)", "[Largest Component Size by Common Factor](/solution/0900-0999/0952.Largest%20Component%20Size%20by%20Common%20Factor/README_EN.md)", "`Union Find`,`Math`", "Hard", ""]}, {"question_id": "0988", "frontend_question_id": "0951", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/flip-equivalent-binary-trees", "url_en": "https://leetcode.com/problems/flip-equivalent-binary-trees", "relative_path_cn": "/solution/0900-0999/0951.Flip%20Equivalent%20Binary%20Trees/README.md", "relative_path_en": "/solution/0900-0999/0951.Flip%20Equivalent%20Binary%20Trees/README_EN.md", "title_cn": "\u7ffb\u8f6c\u7b49\u4ef7\u4e8c\u53c9\u6811", "title_en": "Flip Equivalent Binary Trees", "question_title_slug": "flip-equivalent-binary-trees", "content_en": "

    For a binary tree T, we can define a flip operation as follows: choose any node, and swap the left and right child subtrees.

    \n\n

    A binary tree X is flip equivalent to a binary tree Y if and only if we can make X equal to Y after some number of flip operations.

    \n\n

    Given the roots of two binary trees root1 and root2, return true if the two trees are flip equivelent or false otherwise.

    \n\n

     

    \n

    Example 1:

    \n\"Flipped\n
    \nInput: root1 = [1,2,3,4,5,6,null,null,null,7,8], root2 = [1,3,2,null,6,4,5,null,null,null,null,8,7]\nOutput: true\nExplanation: We flipped at nodes with values 1, 3, and 5.\n
    \n\n

    Example 2:

    \n\n
    \nInput: root1 = [], root2 = []\nOutput: true\n
    \n\n

    Example 3:

    \n\n
    \nInput: root1 = [], root2 = [1]\nOutput: false\n
    \n\n

    Example 4:

    \n\n
    \nInput: root1 = [0,null,1], root2 = []\nOutput: false\n
    \n\n

    Example 5:

    \n\n
    \nInput: root1 = [0,null,1], root2 = [0,1]\nOutput: true\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in each tree is in the range [0, 100].
    • \n\t
    • Each tree will have unique node values in the range [0, 99].
    • \n
    \n", "content_cn": "

    \u6211\u4eec\u53ef\u4ee5\u4e3a\u4e8c\u53c9\u6811 T \u5b9a\u4e49\u4e00\u4e2a\u7ffb\u8f6c\u64cd\u4f5c\uff0c\u5982\u4e0b\u6240\u793a\uff1a\u9009\u62e9\u4efb\u610f\u8282\u70b9\uff0c\u7136\u540e\u4ea4\u6362\u5b83\u7684\u5de6\u5b50\u6811\u548c\u53f3\u5b50\u6811\u3002

    \n\n

    \u53ea\u8981\u7ecf\u8fc7\u4e00\u5b9a\u6b21\u6570\u7684\u7ffb\u8f6c\u64cd\u4f5c\u540e\uff0c\u80fd\u4f7f X \u7b49\u4e8e Y\uff0c\u6211\u4eec\u5c31\u79f0\u4e8c\u53c9\u6811 X \u7ffb\u8f6c\u7b49\u4ef7\u4e8e\u4e8c\u53c9\u6811 Y\u3002

    \n\n

    \u7f16\u5199\u4e00\u4e2a\u5224\u65ad\u4e24\u4e2a\u4e8c\u53c9\u6811\u662f\u5426\u662f\u7ffb\u8f6c\u7b49\u4ef7\u7684\u51fd\u6570\u3002\u8fd9\u4e9b\u6811\u7531\u6839\u8282\u70b9 root1 \u548c root2 \u7ed9\u51fa\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1aroot1 = [1,2,3,4,5,6,null,null,null,7,8], root2 = [1,3,2,null,6,4,5,null,null,null,null,8,7]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u6211\u4eec\u7ffb\u8f6c\u503c\u4e3a 1\uff0c3 \u4ee5\u53ca 5 \u7684\u4e09\u4e2a\u8282\u70b9\u3002\n\"Flipped\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. \u6bcf\u68f5\u6811\u6700\u591a\u6709 100 \u4e2a\u8282\u70b9\u3002
    2. \n\t
    3. \u6bcf\u68f5\u6811\u4e2d\u7684\u6bcf\u4e2a\u503c\u90fd\u662f\u552f\u4e00\u7684\u3001\u5728 [0, 99] \u8303\u56f4\u5185\u7684\u6574\u6570\u3002
    4. \n
    \n\n

     

    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n bool flipEquiv(TreeNode* root1, TreeNode* root2) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public boolean flipEquiv(TreeNode root1, TreeNode root2) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def flipEquiv(self, root1, root2):\n \"\"\"\n :type root1: TreeNode\n :type root2: TreeNode\n :rtype: bool\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def flipEquiv(self, root1: TreeNode, root2: TreeNode) -> bool:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nbool flipEquiv(struct TreeNode* root1, struct TreeNode* root2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public bool FlipEquiv(TreeNode root1, TreeNode root2) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root1\n * @param {TreeNode} root2\n * @return {boolean}\n */\nvar flipEquiv = function(root1, root2) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root1\n# @param {TreeNode} root2\n# @return {Boolean}\ndef flip_equiv(root1, root2)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func flipEquiv(_ root1: TreeNode?, _ root2: TreeNode?) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc flipEquiv(root1 *TreeNode, root2 *TreeNode) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def flipEquiv(root1: TreeNode, root2: TreeNode): Boolean = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun flipEquiv(root1: TreeNode?, root2: TreeNode?): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn flip_equiv(root1: Option>>, root2: Option>>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root1\n * @param TreeNode $root2\n * @return Boolean\n */\n function flipEquiv($root1, $root2) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction flipEquiv(root1: TreeNode | null, root2: TreeNode | null): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (flip-equiv root1 root2)\n (-> (or/c tree-node? #f) (or/c tree-node? #f) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0951](https://leetcode-cn.com/problems/flip-equivalent-binary-trees)", "[\u7ffb\u8f6c\u7b49\u4ef7\u4e8c\u53c9\u6811](/solution/0900-0999/0951.Flip%20Equivalent%20Binary%20Trees/README.md)", "`\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0951](https://leetcode.com/problems/flip-equivalent-binary-trees)", "[Flip Equivalent Binary Trees](/solution/0900-0999/0951.Flip%20Equivalent%20Binary%20Trees/README_EN.md)", "`Tree`", "Medium", ""]}, {"question_id": "0987", "frontend_question_id": "0950", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reveal-cards-in-increasing-order", "url_en": "https://leetcode.com/problems/reveal-cards-in-increasing-order", "relative_path_cn": "/solution/0900-0999/0950.Reveal%20Cards%20In%20Increasing%20Order/README.md", "relative_path_en": "/solution/0900-0999/0950.Reveal%20Cards%20In%20Increasing%20Order/README_EN.md", "title_cn": "\u6309\u9012\u589e\u987a\u5e8f\u663e\u793a\u5361\u724c", "title_en": "Reveal Cards In Increasing Order", "question_title_slug": "reveal-cards-in-increasing-order", "content_en": "

    In a deck of cards, every card has a unique integer.  You can order the deck in any order you want.

    \n\n

    Initially, all the cards start face down (unrevealed) in one deck.

    \n\n

    Now, you do the following steps repeatedly, until all cards are revealed:

    \n\n
      \n\t
    1. Take the top card of the deck, reveal it, and take it out of the deck.
    2. \n\t
    3. If there are still cards in the deck, put the next top card of the deck at the bottom of the deck.
    4. \n\t
    5. If there are still unrevealed cards, go back to step 1.  Otherwise, stop.
    6. \n
    \n\n

    Return an ordering of the deck that would reveal the cards in increasing order.

    \n\n

    The first entry in the answer is considered to be the top of the deck.

    \n\n

     

    \n\n
    \n

    Example 1:

    \n\n
    \nInput: [17,13,11,2,3,5,7]\nOutput: [2,13,3,11,5,17,7]\nExplanation: \nWe get the deck in the order [17,13,11,2,3,5,7] (this order doesn't matter), and reorder it.\nAfter reordering, the deck starts as [2,13,3,11,5,17,7], where 2 is the top of the deck.\nWe reveal 2, and move 13 to the bottom.  The deck is now [3,11,5,17,7,13].\nWe reveal 3, and move 11 to the bottom.  The deck is now [5,17,7,13,11].\nWe reveal 5, and move 17 to the bottom.  The deck is now [7,13,11,17].\nWe reveal 7, and move 13 to the bottom.  The deck is now [11,17,13].\nWe reveal 11, and move 17 to the bottom.  The deck is now [13,17].\nWe reveal 13, and move 17 to the bottom.  The deck is now [17].\nWe reveal 17.\nSince all the cards revealed are in increasing order, the answer is correct.\n
    \n\n
    \n

     

    \n\n

    Note:

    \n\n
      \n\t
    1. 1 <= deck.length <= 1000
    2. \n\t
    3. 1 <= deck[i] <= 10^6
    4. \n\t
    5. deck[i] != deck[j] for all i != j
    6. \n
    \n
    \n
    \n", "content_cn": "

    \u724c\u7ec4\u4e2d\u7684\u6bcf\u5f20\u5361\u724c\u90fd\u5bf9\u5e94\u6709\u4e00\u4e2a\u552f\u4e00\u7684\u6574\u6570\u3002\u4f60\u53ef\u4ee5\u6309\u4f60\u60f3\u8981\u7684\u987a\u5e8f\u5bf9\u8fd9\u5957\u5361\u7247\u8fdb\u884c\u6392\u5e8f\u3002

    \n\n

    \u6700\u521d\uff0c\u8fd9\u4e9b\u5361\u724c\u5728\u724c\u7ec4\u91cc\u662f\u6b63\u9762\u671d\u4e0b\u7684\uff08\u5373\uff0c\u672a\u663e\u793a\u72b6\u6001\uff09\u3002

    \n\n

    \u73b0\u5728\uff0c\u91cd\u590d\u6267\u884c\u4ee5\u4e0b\u6b65\u9aa4\uff0c\u76f4\u5230\u663e\u793a\u6240\u6709\u5361\u724c\u4e3a\u6b62\uff1a

    \n\n
      \n\t
    1. \u4ece\u724c\u7ec4\u9876\u90e8\u62bd\u4e00\u5f20\u724c\uff0c\u663e\u793a\u5b83\uff0c\u7136\u540e\u5c06\u5176\u4ece\u724c\u7ec4\u4e2d\u79fb\u51fa\u3002
    2. \n\t
    3. \u5982\u679c\u724c\u7ec4\u4e2d\u4ecd\u6709\u724c\uff0c\u5219\u5c06\u4e0b\u4e00\u5f20\u5904\u4e8e\u724c\u7ec4\u9876\u90e8\u7684\u724c\u653e\u5728\u724c\u7ec4\u7684\u5e95\u90e8\u3002
    4. \n\t
    5. \u5982\u679c\u4ecd\u6709\u672a\u663e\u793a\u7684\u724c\uff0c\u90a3\u4e48\u8fd4\u56de\u6b65\u9aa4 1\u3002\u5426\u5219\uff0c\u505c\u6b62\u884c\u52a8\u3002
    6. \n
    \n\n

    \u8fd4\u56de\u80fd\u4ee5\u9012\u589e\u987a\u5e8f\u663e\u793a\u5361\u724c\u7684\u724c\u7ec4\u987a\u5e8f\u3002

    \n\n

    \u7b54\u6848\u4e2d\u7684\u7b2c\u4e00\u5f20\u724c\u88ab\u8ba4\u4e3a\u5904\u4e8e\u724c\u5806\u9876\u90e8\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1a[17,13,11,2,3,5,7]\n\u8f93\u51fa\uff1a[2,13,3,11,5,17,7]\n\u89e3\u91ca\uff1a\n\u6211\u4eec\u5f97\u5230\u7684\u724c\u7ec4\u987a\u5e8f\u4e3a [17,13,11,2,3,5,7]\uff08\u8fd9\u4e2a\u987a\u5e8f\u4e0d\u91cd\u8981\uff09\uff0c\u7136\u540e\u5c06\u5176\u91cd\u65b0\u6392\u5e8f\u3002\n\u91cd\u65b0\u6392\u5e8f\u540e\uff0c\u724c\u7ec4\u4ee5 [2,13,3,11,5,17,7] \u5f00\u59cb\uff0c\u5176\u4e2d 2 \u4f4d\u4e8e\u724c\u7ec4\u7684\u9876\u90e8\u3002\n\u6211\u4eec\u663e\u793a 2\uff0c\u7136\u540e\u5c06 13 \u79fb\u5230\u5e95\u90e8\u3002\u724c\u7ec4\u73b0\u5728\u662f [3,11,5,17,7,13]\u3002\n\u6211\u4eec\u663e\u793a 3\uff0c\u5e76\u5c06 11 \u79fb\u5230\u5e95\u90e8\u3002\u724c\u7ec4\u73b0\u5728\u662f [5,17,7,13,11]\u3002\n\u6211\u4eec\u663e\u793a 5\uff0c\u7136\u540e\u5c06 17 \u79fb\u5230\u5e95\u90e8\u3002\u724c\u7ec4\u73b0\u5728\u662f [7,13,11,17]\u3002\n\u6211\u4eec\u663e\u793a 7\uff0c\u5e76\u5c06 13 \u79fb\u5230\u5e95\u90e8\u3002\u724c\u7ec4\u73b0\u5728\u662f [11,17,13]\u3002\n\u6211\u4eec\u663e\u793a 11\uff0c\u7136\u540e\u5c06 17 \u79fb\u5230\u5e95\u90e8\u3002\u724c\u7ec4\u73b0\u5728\u662f [13,17]\u3002\n\u6211\u4eec\u5c55\u793a 13\uff0c\u7136\u540e\u5c06 17 \u79fb\u5230\u5e95\u90e8\u3002\u724c\u7ec4\u73b0\u5728\u662f [17]\u3002\n\u6211\u4eec\u663e\u793a 17\u3002\n\u7531\u4e8e\u6240\u6709\u5361\u7247\u90fd\u662f\u6309\u9012\u589e\u987a\u5e8f\u6392\u5217\u663e\u793a\u7684\uff0c\u6240\u4ee5\u7b54\u6848\u662f\u6b63\u786e\u7684\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= A.length <= 1000
    2. \n\t
    3. 1 <= A[i] <= 10^6
    4. \n\t
    5. \u5bf9\u4e8e\u6240\u6709\u7684 i != j\uff0cA[i] != A[j]
    6. \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector deckRevealedIncreasing(vector& deck) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] deckRevealedIncreasing(int[] deck) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def deckRevealedIncreasing(self, deck):\n \"\"\"\n :type deck: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def deckRevealedIncreasing(self, deck: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* deckRevealedIncreasing(int* deck, int deckSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] DeckRevealedIncreasing(int[] deck) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} deck\n * @return {number[]}\n */\nvar deckRevealedIncreasing = function(deck) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} deck\n# @return {Integer[]}\ndef deck_revealed_increasing(deck)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func deckRevealedIncreasing(_ deck: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func deckRevealedIncreasing(deck []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def deckRevealedIncreasing(deck: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun deckRevealedIncreasing(deck: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn deck_revealed_increasing(deck: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $deck\n * @return Integer[]\n */\n function deckRevealedIncreasing($deck) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function deckRevealedIncreasing(deck: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (deck-revealed-increasing deck)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0950](https://leetcode-cn.com/problems/reveal-cards-in-increasing-order)", "[\u6309\u9012\u589e\u987a\u5e8f\u663e\u793a\u5361\u724c](/solution/0900-0999/0950.Reveal%20Cards%20In%20Increasing%20Order/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0950](https://leetcode.com/problems/reveal-cards-in-increasing-order)", "[Reveal Cards In Increasing Order](/solution/0900-0999/0950.Reveal%20Cards%20In%20Increasing%20Order/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0986", "frontend_question_id": "0949", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/largest-time-for-given-digits", "url_en": "https://leetcode.com/problems/largest-time-for-given-digits", "relative_path_cn": "/solution/0900-0999/0949.Largest%20Time%20for%20Given%20Digits/README.md", "relative_path_en": "/solution/0900-0999/0949.Largest%20Time%20for%20Given%20Digits/README_EN.md", "title_cn": "\u7ed9\u5b9a\u6570\u5b57\u80fd\u7ec4\u6210\u7684\u6700\u5927\u65f6\u95f4", "title_en": "Largest Time for Given Digits", "question_title_slug": "largest-time-for-given-digits", "content_en": "

    Given an array arr of 4 digits, find the latest 24-hour time that can be made using each digit exactly once.

    \n\n

    24-hour times are formatted as "HH:MM", where HH is between 00 and 23, and MM is between 00 and 59. The earliest 24-hour time is 00:00, and the latest is 23:59.

    \n\n

    Return the latest 24-hour time in "HH:MM" format.  If no valid time can be made, return an empty string.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr = [1,2,3,4]\nOutput: "23:41"\nExplanation: The valid 24-hour times are "12:34", "12:43", "13:24", "13:42", "14:23", "14:32", "21:34", "21:43", "23:14", and "23:41". Of these times, "23:41" is the latest.\n
    \n\n

    Example 2:

    \n\n
    \nInput: arr = [5,5,5,5]\nOutput: ""\nExplanation: There are no valid 24-hour times as "55:55" is not valid.\n
    \n\n

    Example 3:

    \n\n
    \nInput: arr = [0,0,0,0]\nOutput: "00:00"\n
    \n\n

    Example 4:

    \n\n
    \nInput: arr = [0,0,1,0]\nOutput: "10:00"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • arr.length == 4
    • \n\t
    • 0 <= arr[i] <= 9
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u7531 4 \u4f4d\u6570\u5b57\u7ec4\u6210\u7684\u6570\u7ec4\uff0c\u8fd4\u56de\u53ef\u4ee5\u8bbe\u7f6e\u7684\u7b26\u5408 24 \u5c0f\u65f6\u5236\u7684\u6700\u5927\u65f6\u95f4\u3002

    \n\n

    24 \u5c0f\u65f6\u683c\u5f0f\u4e3a \"HH:MM\" \uff0c\u5176\u4e2d HH \u5728 00 \u5230 23 \u4e4b\u95f4\uff0cMM \u5728 00 \u5230 59 \u4e4b\u95f4\u3002\u6700\u5c0f\u7684 24 \u5c0f\u65f6\u5236\u65f6\u95f4\u662f\u00a000:00 \uff0c\u800c\u6700\u5927\u7684\u662f\u00a023:59 \u3002\u4ece 00:00 \uff08\u5348\u591c\uff09\u5f00\u59cb\u7b97\u8d77\uff0c\u8fc7\u5f97\u8d8a\u4e45\uff0c\u65f6\u95f4\u8d8a\u5927\u3002

    \n\n

    \u4ee5\u957f\u5ea6\u4e3a 5 \u7684\u5b57\u7b26\u4e32\uff0c\u6309 \"HH:MM\" \u683c\u5f0f\u8fd4\u56de\u7b54\u6848\u3002\u5982\u679c\u4e0d\u80fd\u786e\u5b9a\u6709\u6548\u65f6\u95f4\uff0c\u5219\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [1,2,3,4]\n\u8f93\u51fa\uff1a\"23:41\"\n\u89e3\u91ca\uff1a\u6709\u6548\u7684 24 \u5c0f\u65f6\u5236\u65f6\u95f4\u662f \"12:34\"\uff0c\"12:43\"\uff0c\"13:24\"\uff0c\"13:42\"\uff0c\"14:23\"\uff0c\"14:32\"\uff0c\"21:34\"\uff0c\"21:43\"\uff0c\"23:14\" \u548c \"23:41\" \u3002\u8fd9\u4e9b\u65f6\u95f4\u4e2d\uff0c\"23:41\" \u662f\u6700\u5927\u65f6\u95f4\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [5,5,5,5]\n\u8f93\u51fa\uff1a\"\"\n\u89e3\u91ca\uff1a\u4e0d\u5b58\u5728\u6709\u6548\u7684 24 \u5c0f\u65f6\u5236\u65f6\u95f4\uff0c\u56e0\u4e3a \"55:55\" \u65e0\u6548\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [0,0,0,0]\n\u8f93\u51fa\uff1a\"00:00\"\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [0,0,1,0]\n\u8f93\u51fa\uff1a\"10:00\"\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • arr.length == 4
    • \n\t
    • 0 <= arr[i] <= 9
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string largestTimeFromDigits(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String largestTimeFromDigits(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def largestTimeFromDigits(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def largestTimeFromDigits(self, arr: List[int]) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * largestTimeFromDigits(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string LargestTimeFromDigits(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {string}\n */\nvar largestTimeFromDigits = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {String}\ndef largest_time_from_digits(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func largestTimeFromDigits(_ arr: [Int]) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func largestTimeFromDigits(arr []int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def largestTimeFromDigits(arr: Array[Int]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun largestTimeFromDigits(arr: IntArray): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn largest_time_from_digits(arr: Vec) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return String\n */\n function largestTimeFromDigits($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function largestTimeFromDigits(arr: number[]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (largest-time-from-digits arr)\n (-> (listof exact-integer?) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0949](https://leetcode-cn.com/problems/largest-time-for-given-digits)", "[\u7ed9\u5b9a\u6570\u5b57\u80fd\u7ec4\u6210\u7684\u6700\u5927\u65f6\u95f4](/solution/0900-0999/0949.Largest%20Time%20for%20Given%20Digits/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0949](https://leetcode.com/problems/largest-time-for-given-digits)", "[Largest Time for Given Digits](/solution/0900-0999/0949.Largest%20Time%20for%20Given%20Digits/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "0985", "frontend_question_id": "0948", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/bag-of-tokens", "url_en": "https://leetcode.com/problems/bag-of-tokens", "relative_path_cn": "/solution/0900-0999/0948.Bag%20of%20Tokens/README.md", "relative_path_en": "/solution/0900-0999/0948.Bag%20of%20Tokens/README_EN.md", "title_cn": "\u4ee4\u724c\u653e\u7f6e", "title_en": "Bag of Tokens", "question_title_slug": "bag-of-tokens", "content_en": "

    You have an initial power of power, an initial score of 0, and a bag of tokens where tokens[i] is the value of the ith token (0-indexed).

    \n\n

    Your goal is to maximize your total score by potentially playing each token in one of two ways:

    \n\n
      \n\t
    • If your current power is at least tokens[i], you may play the ith token face up, losing tokens[i] power and gaining 1 score.
    • \n\t
    • If your current score is at least 1, you may play the ith token face down, gaining tokens[i] power and losing 1 score.
    • \n
    \n\n

    Each token may be played at most once and in any order. You do not have to play all the tokens.

    \n\n

    Return the largest possible score you can achieve after playing any number of tokens.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: tokens = [100], power = 50\nOutput: 0\nExplanation: Playing the only token in the bag is impossible because you either have too little power or too little score.\n
    \n\n

    Example 2:

    \n\n
    \nInput: tokens = [100,200], power = 150\nOutput: 1\nExplanation: Play the 0th token (100) face up, your power becomes 50 and score becomes 1.\nThere is no need to play the 1st token since you cannot play it face up to add to your score.\n
    \n\n

    Example 3:

    \n\n
    \nInput: tokens = [100,200,300,400], power = 200\nOutput: 2\nExplanation: Play the tokens in this order to get a score of 2:\n1. Play the 0th token (100) face up, your power becomes 100 and score becomes 1.\n2. Play the 3rd token (400) face down, your power becomes 500 and score becomes 0.\n3. Play the 1st token (200) face up, your power becomes 300 and score becomes 1.\n4. Play the 2nd token (300) face up, your power becomes 0 and score becomes 2.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= tokens.length <= 1000
    • \n\t
    • 0 <= tokens[i], power < 104
    • \n
    \n", "content_cn": "

    \u4f60\u7684\u521d\u59cb \u80fd\u91cf \u4e3a\u00a0P\uff0c\u521d\u59cb \u5206\u6570 \u4e3a\u00a00\uff0c\u53ea\u6709\u4e00\u5305\u4ee4\u724c tokens \u3002\u5176\u4e2d tokens[i] \u662f\u7b2c i \u4e2a\u4ee4\u724c\u7684\u503c\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\u3002

    \n\n

    \u4ee4\u724c\u53ef\u80fd\u7684\u4e24\u79cd\u4f7f\u7528\u65b9\u6cd5\u5982\u4e0b\uff1a

    \n\n
      \n\t
    • \u5982\u679c\u4f60\u81f3\u5c11\u6709\u00a0token[i]\u00a0\u70b9 \u80fd\u91cf \uff0c\u53ef\u4ee5\u5c06\u4ee4\u724c i \u7f6e\u4e3a\u6b63\u9762\u671d\u4e0a\uff0c\u5931\u53bb\u00a0token[i]\u00a0\u70b9 \u80fd\u91cf \uff0c\u5e76\u5f97\u5230\u00a01\u00a0\u5206 \u3002
    • \n\t
    • \u5982\u679c\u6211\u4eec\u81f3\u5c11\u6709\u00a01\u00a0\u5206 \uff0c\u53ef\u4ee5\u5c06\u4ee4\u724c i \u7f6e\u4e3a\u53cd\u9762\u671d\u4e0a\uff0c\u83b7\u5f97\u00a0token[i] \u70b9 \u80fd\u91cf \uff0c\u5e76\u5931\u53bb\u00a01\u00a0\u5206 \u3002
    • \n
    \n\n

    \u6bcf\u4e2a\u4ee4\u724c \u6700\u591a \u53ea\u80fd\u4f7f\u7528\u4e00\u6b21\uff0c\u4f7f\u7528 \u987a\u5e8f\u4e0d\u9650 \uff0c\u4e0d\u9700 \u4f7f\u7528\u6240\u6709\u4ee4\u724c\u3002

    \n\n

    \u5728\u4f7f\u7528\u4efb\u610f\u6570\u91cf\u7684\u4ee4\u724c\u540e\uff0c\u8fd4\u56de\u6211\u4eec\u53ef\u4ee5\u5f97\u5230\u7684\u6700\u5927 \u5206\u6570 \u3002

    \n\n

    \u00a0

    \n\n
      \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1atokens = [100], P = 50\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u65e0\u6cd5\u4f7f\u7528\u552f\u4e00\u7684\u4ee4\u724c\uff0c\u56e0\u4e3a\u80fd\u91cf\u548c\u5206\u6570\u90fd\u592a\u5c11\u4e86\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1atokens = [100,200], P = 150\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u4ee4\u724c 0 \u6b63\u9762\u671d\u4e0a\uff0c\u80fd\u91cf\u53d8\u4e3a 50\uff0c\u5206\u6570\u53d8\u4e3a 1 \u3002\u4e0d\u5fc5\u4f7f\u7528\u4ee4\u724c 1 \uff0c\u56e0\u4e3a\u4f60\u65e0\u6cd5\u4f7f\u7528\u5b83\u6765\u63d0\u9ad8\u5206\u6570\u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1atokens = [100,200,300,400], P = 200\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6309\u4e0b\u9762\u987a\u5e8f\u4f7f\u7528\u4ee4\u724c\u53ef\u4ee5\u5f97\u5230 2 \u5206\uff1a\n1. \u4ee4\u724c 0 \u6b63\u9762\u671d\u4e0a\uff0c\u80fd\u91cf\u53d8\u4e3a 100 \uff0c\u5206\u6570\u53d8\u4e3a 1\n2. \u4ee4\u724c 3 \u6b63\u9762\u671d\u4e0b\uff0c\u80fd\u91cf\u53d8\u4e3a 500 \uff0c\u5206\u6570\u53d8\u4e3a 0\n3. \u4ee4\u724c 1 \u6b63\u9762\u671d\u4e0a\uff0c\u80fd\u91cf\u53d8\u4e3a 300 \uff0c\u5206\u6570\u53d8\u4e3a 1\n4. \u4ee4\u724c 2 \u6b63\u9762\u671d\u4e0a\uff0c\u80fd\u91cf\u53d8\u4e3a 0 \uff0c\u5206\u6570\u53d8\u4e3a 2
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= tokens.length <= 1000
    • \n\t
    • 0 <= tokens[i],\u00a0P < 104
    • \n
    \n", "tags_en": ["Greedy", "Sort", "Two Pointers"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6392\u5e8f", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int bagOfTokensScore(vector& tokens, int power) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int bagOfTokensScore(int[] tokens, int power) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def bagOfTokensScore(self, tokens, power):\n \"\"\"\n :type tokens: List[int]\n :type power: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def bagOfTokensScore(self, tokens: List[int], power: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint bagOfTokensScore(int* tokens, int tokensSize, int power){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int BagOfTokensScore(int[] tokens, int power) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} tokens\n * @param {number} power\n * @return {number}\n */\nvar bagOfTokensScore = function(tokens, power) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} tokens\n# @param {Integer} power\n# @return {Integer}\ndef bag_of_tokens_score(tokens, power)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func bagOfTokensScore(_ tokens: [Int], _ power: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func bagOfTokensScore(tokens []int, power int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def bagOfTokensScore(tokens: Array[Int], power: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun bagOfTokensScore(tokens: IntArray, power: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn bag_of_tokens_score(tokens: Vec, power: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $tokens\n * @param Integer $power\n * @return Integer\n */\n function bagOfTokensScore($tokens, $power) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function bagOfTokensScore(tokens: number[], power: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (bag-of-tokens-score tokens power)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0948](https://leetcode-cn.com/problems/bag-of-tokens)", "[\u4ee4\u724c\u653e\u7f6e](/solution/0900-0999/0948.Bag%20of%20Tokens/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6392\u5e8f`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0948](https://leetcode.com/problems/bag-of-tokens)", "[Bag of Tokens](/solution/0900-0999/0948.Bag%20of%20Tokens/README_EN.md)", "`Greedy`,`Sort`,`Two Pointers`", "Medium", ""]}, {"question_id": "0984", "frontend_question_id": "0947", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/most-stones-removed-with-same-row-or-column", "url_en": "https://leetcode.com/problems/most-stones-removed-with-same-row-or-column", "relative_path_cn": "/solution/0900-0999/0947.Most%20Stones%20Removed%20with%20Same%20Row%20or%20Column/README.md", "relative_path_en": "/solution/0900-0999/0947.Most%20Stones%20Removed%20with%20Same%20Row%20or%20Column/README_EN.md", "title_cn": "\u79fb\u9664\u6700\u591a\u7684\u540c\u884c\u6216\u540c\u5217\u77f3\u5934", "title_en": "Most Stones Removed with Same Row or Column", "question_title_slug": "most-stones-removed-with-same-row-or-column", "content_en": "

    On a 2D plane, we place n stones at some integer coordinate points. Each coordinate point may have at most one stone.

    \n\n

    A stone can be removed if it shares either the same row or the same column as another stone that has not been removed.

    \n\n

    Given an array stones of length n where stones[i] = [xi, yi] represents the location of the ith stone, return the largest possible number of stones that can be removed.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: stones = [[0,0],[0,1],[1,0],[1,2],[2,1],[2,2]]\nOutput: 5\nExplanation: One way to remove 5 stones is as follows:\n1. Remove stone [2,2] because it shares the same row as [2,1].\n2. Remove stone [2,1] because it shares the same column as [0,1].\n3. Remove stone [1,2] because it shares the same row as [1,0].\n4. Remove stone [1,0] because it shares the same column as [0,0].\n5. Remove stone [0,1] because it shares the same row as [0,0].\nStone [0,0] cannot be removed since it does not share a row/column with another stone still on the plane.\n
    \n\n

    Example 2:

    \n\n
    \nInput: stones = [[0,0],[0,2],[1,1],[2,0],[2,2]]\nOutput: 3\nExplanation: One way to make 3 moves is as follows:\n1. Remove stone [2,2] because it shares the same row as [2,0].\n2. Remove stone [2,0] because it shares the same column as [0,0].\n3. Remove stone [0,2] because it shares the same row as [0,0].\nStones [0,0] and [1,1] cannot be removed since they do not share a row/column with another stone still on the plane.\n
    \n\n

    Example 3:

    \n\n
    \nInput: stones = [[0,0]]\nOutput: 0\nExplanation: [0,0] is the only stone on the plane, so you cannot remove it.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= stones.length <= 1000
    • \n\t
    • 0 <= xi, yi <= 104
    • \n\t
    • No two stones are at the same coordinate point.
    • \n
    \n", "content_cn": "

    n \u5757\u77f3\u5934\u653e\u7f6e\u5728\u4e8c\u7ef4\u5e73\u9762\u4e2d\u7684\u4e00\u4e9b\u6574\u6570\u5750\u6807\u70b9\u4e0a\u3002\u6bcf\u4e2a\u5750\u6807\u70b9\u4e0a\u6700\u591a\u53ea\u80fd\u6709\u4e00\u5757\u77f3\u5934\u3002

    \n\n

    \u5982\u679c\u4e00\u5757\u77f3\u5934\u7684 \u540c\u884c\u6216\u8005\u540c\u5217 \u4e0a\u6709\u5176\u4ed6\u77f3\u5934\u5b58\u5728\uff0c\u90a3\u4e48\u5c31\u53ef\u4ee5\u79fb\u9664\u8fd9\u5757\u77f3\u5934\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u6570\u7ec4 stones \uff0c\u5176\u4e2d stones[i] = [xi, yi] \u8868\u793a\u7b2c i \u5757\u77f3\u5934\u7684\u4f4d\u7f6e\uff0c\u8fd4\u56de \u53ef\u4ee5\u79fb\u9664\u7684\u77f3\u5b50 \u7684\u6700\u5927\u6570\u91cf\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1astones = [[0,0],[0,1],[1,0],[1,2],[2,1],[2,2]]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u4e00\u79cd\u79fb\u9664 5 \u5757\u77f3\u5934\u7684\u65b9\u6cd5\u5982\u4e0b\u6240\u793a\uff1a\n1. \u79fb\u9664\u77f3\u5934 [2,2] \uff0c\u56e0\u4e3a\u5b83\u548c [2,1] \u540c\u884c\u3002\n2. \u79fb\u9664\u77f3\u5934 [2,1] \uff0c\u56e0\u4e3a\u5b83\u548c [0,1] \u540c\u5217\u3002\n3. \u79fb\u9664\u77f3\u5934 [1,2] \uff0c\u56e0\u4e3a\u5b83\u548c [1,0] \u540c\u884c\u3002\n4. \u79fb\u9664\u77f3\u5934 [1,0] \uff0c\u56e0\u4e3a\u5b83\u548c [0,0] \u540c\u5217\u3002\n5. \u79fb\u9664\u77f3\u5934 [0,1] \uff0c\u56e0\u4e3a\u5b83\u548c [0,0] \u540c\u884c\u3002\n\u77f3\u5934 [0,0] \u4e0d\u80fd\u79fb\u9664\uff0c\u56e0\u4e3a\u5b83\u6ca1\u6709\u4e0e\u53e6\u4e00\u5757\u77f3\u5934\u540c\u884c/\u5217\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1astones = [[0,0],[0,2],[1,1],[2,0],[2,2]]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u4e00\u79cd\u79fb\u9664 3 \u5757\u77f3\u5934\u7684\u65b9\u6cd5\u5982\u4e0b\u6240\u793a\uff1a\n1. \u79fb\u9664\u77f3\u5934 [2,2] \uff0c\u56e0\u4e3a\u5b83\u548c [2,0] \u540c\u884c\u3002\n2. \u79fb\u9664\u77f3\u5934 [2,0] \uff0c\u56e0\u4e3a\u5b83\u548c [0,0] \u540c\u5217\u3002\n3. \u79fb\u9664\u77f3\u5934 [0,2] \uff0c\u56e0\u4e3a\u5b83\u548c [0,0] \u540c\u884c\u3002\n\u77f3\u5934 [0,0] \u548c [1,1] \u4e0d\u80fd\u79fb\u9664\uff0c\u56e0\u4e3a\u5b83\u4eec\u6ca1\u6709\u4e0e\u53e6\u4e00\u5757\u77f3\u5934\u540c\u884c/\u5217\u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1astones = [[0,0]]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a[0,0] \u662f\u5e73\u9762\u4e0a\u552f\u4e00\u4e00\u5757\u77f3\u5934\uff0c\u6240\u4ee5\u4e0d\u53ef\u4ee5\u79fb\u9664\u5b83\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= stones.length <= 1000
    • \n\t
    • 0 <= xi, yi <= 104
    • \n\t
    • \u4e0d\u4f1a\u6709\u4e24\u5757\u77f3\u5934\u653e\u5728\u540c\u4e00\u4e2a\u5750\u6807\u70b9\u4e0a
    • \n
    \n", "tags_en": ["Depth-first Search", "Union Find"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e76\u67e5\u96c6"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int removeStones(vector>& stones) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int removeStones(int[][] stones) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def removeStones(self, stones):\n \"\"\"\n :type stones: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def removeStones(self, stones: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint removeStones(int** stones, int stonesSize, int* stonesColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int RemoveStones(int[][] stones) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} stones\n * @return {number}\n */\nvar removeStones = function(stones) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} stones\n# @return {Integer}\ndef remove_stones(stones)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func removeStones(_ stones: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func removeStones(stones [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def removeStones(stones: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun removeStones(stones: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn remove_stones(stones: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $stones\n * @return Integer\n */\n function removeStones($stones) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function removeStones(stones: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (remove-stones stones)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0947](https://leetcode-cn.com/problems/most-stones-removed-with-same-row-or-column)", "[\u79fb\u9664\u6700\u591a\u7684\u540c\u884c\u6216\u540c\u5217\u77f3\u5934](/solution/0900-0999/0947.Most%20Stones%20Removed%20with%20Same%20Row%20or%20Column/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e76\u67e5\u96c6`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0947](https://leetcode.com/problems/most-stones-removed-with-same-row-or-column)", "[Most Stones Removed with Same Row or Column](/solution/0900-0999/0947.Most%20Stones%20Removed%20with%20Same%20Row%20or%20Column/README_EN.md)", "`Depth-first Search`,`Union Find`", "Medium", ""]}, {"question_id": "0983", "frontend_question_id": "0946", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/validate-stack-sequences", "url_en": "https://leetcode.com/problems/validate-stack-sequences", "relative_path_cn": "/solution/0900-0999/0946.Validate%20Stack%20Sequences/README.md", "relative_path_en": "/solution/0900-0999/0946.Validate%20Stack%20Sequences/README_EN.md", "title_cn": "\u9a8c\u8bc1\u6808\u5e8f\u5217", "title_en": "Validate Stack Sequences", "question_title_slug": "validate-stack-sequences", "content_en": "

    Given two sequences pushed and popped with distinct values, return true if and only if this could have been the result of a sequence of push and pop operations on an initially empty stack.

    \n\n

     

    \n\n
    \n

    Example 1:

    \n\n
    \nInput: pushed = [1,2,3,4,5], popped = [4,5,3,2,1]\nOutput: true\nExplanation: We might do the following sequence:\npush(1), push(2), push(3), push(4), pop() -> 4,\npush(5), pop() -> 5, pop() -> 3, pop() -> 2, pop() -> 1\n
    \n\n
    \n

    Example 2:

    \n\n
    \nInput: pushed = [1,2,3,4,5], popped = [4,3,5,1,2]\nOutput: false\nExplanation: 1 cannot be popped before 2.\n
    \n
    \n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= pushed.length == popped.length <= 1000
    • \n\t
    • 0 <= pushed[i], popped[i] < 1000
    • \n\t
    • pushed is a permutation of popped.
    • \n\t
    • pushed and popped have distinct values.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a pushed \u548c popped \u4e24\u4e2a\u5e8f\u5217\uff0c\u6bcf\u4e2a\u5e8f\u5217\u4e2d\u7684 \u503c\u90fd\u4e0d\u91cd\u590d\uff0c\u53ea\u6709\u5f53\u5b83\u4eec\u53ef\u80fd\u662f\u5728\u6700\u521d\u7a7a\u6808\u4e0a\u8fdb\u884c\u7684\u63a8\u5165 push \u548c\u5f39\u51fa pop \u64cd\u4f5c\u5e8f\u5217\u7684\u7ed3\u679c\u65f6\uff0c\u8fd4\u56de true\uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1apushed = [1,2,3,4,5], popped = [4,5,3,2,1]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u6211\u4eec\u53ef\u4ee5\u6309\u4ee5\u4e0b\u987a\u5e8f\u6267\u884c\uff1a\npush(1), push(2), push(3), push(4), pop() -> 4,\npush(5), pop() -> 5, pop() -> 3, pop() -> 2, pop() -> 1\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1apushed = [1,2,3,4,5], popped = [4,3,5,1,2]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a1 \u4e0d\u80fd\u5728 2 \u4e4b\u524d\u5f39\u51fa\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 0 <= pushed.length == popped.length <= 1000
    2. \n\t
    3. 0 <= pushed[i], popped[i] < 1000
    4. \n\t
    5. pushed \u662f popped \u7684\u6392\u5217\u3002
    6. \n
    \n", "tags_en": ["Stack"], "tags_cn": ["\u6808"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool validateStackSequences(vector& pushed, vector& popped) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean validateStackSequences(int[] pushed, int[] popped) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def validateStackSequences(self, pushed, popped):\n \"\"\"\n :type pushed: List[int]\n :type popped: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def validateStackSequences(self, pushed: List[int], popped: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool validateStackSequences(int* pushed, int pushedSize, int* popped, int poppedSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool ValidateStackSequences(int[] pushed, int[] popped) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} pushed\n * @param {number[]} popped\n * @return {boolean}\n */\nvar validateStackSequences = function(pushed, popped) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} pushed\n# @param {Integer[]} popped\n# @return {Boolean}\ndef validate_stack_sequences(pushed, popped)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func validateStackSequences(_ pushed: [Int], _ popped: [Int]) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func validateStackSequences(pushed []int, popped []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def validateStackSequences(pushed: Array[Int], popped: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun validateStackSequences(pushed: IntArray, popped: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn validate_stack_sequences(pushed: Vec, popped: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $pushed\n * @param Integer[] $popped\n * @return Boolean\n */\n function validateStackSequences($pushed, $popped) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function validateStackSequences(pushed: number[], popped: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (validate-stack-sequences pushed popped)\n (-> (listof exact-integer?) (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0946](https://leetcode-cn.com/problems/validate-stack-sequences)", "[\u9a8c\u8bc1\u6808\u5e8f\u5217](/solution/0900-0999/0946.Validate%20Stack%20Sequences/README.md)", "`\u6808`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0946](https://leetcode.com/problems/validate-stack-sequences)", "[Validate Stack Sequences](/solution/0900-0999/0946.Validate%20Stack%20Sequences/README_EN.md)", "`Stack`", "Medium", ""]}, {"question_id": "0982", "frontend_question_id": "0945", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-increment-to-make-array-unique", "url_en": "https://leetcode.com/problems/minimum-increment-to-make-array-unique", "relative_path_cn": "/solution/0900-0999/0945.Minimum%20Increment%20to%20Make%20Array%20Unique/README.md", "relative_path_en": "/solution/0900-0999/0945.Minimum%20Increment%20to%20Make%20Array%20Unique/README_EN.md", "title_cn": "\u4f7f\u6570\u7ec4\u552f\u4e00\u7684\u6700\u5c0f\u589e\u91cf", "title_en": "Minimum Increment to Make Array Unique", "question_title_slug": "minimum-increment-to-make-array-unique", "content_en": "

    Given an array of integers nums, a move consists of choosing any nums[i], and incrementing it by 1.

    \n\n

    Return the least number of moves to make every value in nums unique.

    \n\n

     

    \n\n

    Example 1:

    \n\n
    \nInput: nums = [1,2,2]\nOutput: 1\nExplanation:  After 1 move, the array could be [1, 2, 3].\n
    \n\n
    \n

    Example 2:

    \n\n
    \nInput: nums = [3,2,1,2,1,7]\nOutput: 6\nExplanation:  After 6 moves, the array could be [3, 4, 1, 2, 5, 7].\nIt can be shown with 5 or less moves that it is impossible for the array to have all unique values.\n
    \n\n

     

    \n
    \n\n

    Note:

    \n\n
      \n\t
    1. 0 <= nums.length <= 40000
    2. \n\t
    3. 0 <= nums[i] < 40000
    4. \n
    \n\n
    \n
     
    \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u6574\u6570\u6570\u7ec4 A\uff0c\u6bcf\u6b21 move \u64cd\u4f5c\u5c06\u4f1a\u9009\u62e9\u4efb\u610f A[i]\uff0c\u5e76\u5c06\u5176\u9012\u589e 1\u3002

    \n\n

    \u8fd4\u56de\u4f7f A \u4e2d\u7684\u6bcf\u4e2a\u503c\u90fd\u662f\u552f\u4e00\u7684\u6700\u5c11\u64cd\u4f5c\u6b21\u6570\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165\uff1a[1,2,2]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u7ecf\u8fc7\u4e00\u6b21 move \u64cd\u4f5c\uff0c\u6570\u7ec4\u5c06\u53d8\u4e3a [1, 2, 3]\u3002
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165\uff1a[3,2,1,2,1,7]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u7ecf\u8fc7 6 \u6b21 move \u64cd\u4f5c\uff0c\u6570\u7ec4\u5c06\u53d8\u4e3a [3, 4, 1, 2, 5, 7]\u3002\n\u53ef\u4ee5\u770b\u51fa 5 \u6b21\u6216 5 \u6b21\u4ee5\u4e0b\u7684 move \u64cd\u4f5c\u662f\u4e0d\u80fd\u8ba9\u6570\u7ec4\u7684\u6bcf\u4e2a\u503c\u552f\u4e00\u7684\u3002\n
    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 0 <= A.length <= 40000
    2. \n\t
    3. 0 <= A[i] < 40000
    4. \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minIncrementForUnique(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minIncrementForUnique(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minIncrementForUnique(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minIncrementForUnique(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minIncrementForUnique(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinIncrementForUnique(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar minIncrementForUnique = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef min_increment_for_unique(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minIncrementForUnique(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minIncrementForUnique(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minIncrementForUnique(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minIncrementForUnique(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_increment_for_unique(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function minIncrementForUnique($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minIncrementForUnique(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-increment-for-unique nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0945](https://leetcode-cn.com/problems/minimum-increment-to-make-array-unique)", "[\u4f7f\u6570\u7ec4\u552f\u4e00\u7684\u6700\u5c0f\u589e\u91cf](/solution/0900-0999/0945.Minimum%20Increment%20to%20Make%20Array%20Unique/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0945](https://leetcode.com/problems/minimum-increment-to-make-array-unique)", "[Minimum Increment to Make Array Unique](/solution/0900-0999/0945.Minimum%20Increment%20to%20Make%20Array%20Unique/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0981", "frontend_question_id": "0944", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/delete-columns-to-make-sorted", "url_en": "https://leetcode.com/problems/delete-columns-to-make-sorted", "relative_path_cn": "/solution/0900-0999/0944.Delete%20Columns%20to%20Make%20Sorted/README.md", "relative_path_en": "/solution/0900-0999/0944.Delete%20Columns%20to%20Make%20Sorted/README_EN.md", "title_cn": "\u5220\u5217\u9020\u5e8f", "title_en": "Delete Columns to Make Sorted", "question_title_slug": "delete-columns-to-make-sorted", "content_en": "

    You are given an array of n strings strs, all of the same length.

    \n\n

    The strings can be arranged such that there is one on each line, making a grid. For example, strs = ["abc", "bce", "cae"] can be arranged as:

    \n\n
    \nabc\nbce\ncae\n
    \n\n

    You want to delete the columns that are not sorted lexicographically. In the above example (0-indexed), columns 0 ('a', 'b', 'c') and 2 ('c', 'e', 'e') are sorted while column 1 ('b', 'c', 'a') is not, so you would delete column 1.

    \n\n

    Return the number of columns that you will delete.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: strs = ["cba","daf","ghi"]\nOutput: 1\nExplanation: The grid looks as follows:\n  cba\n  daf\n  ghi\nColumns 0 and 2 are sorted, but column 1 is not, so you only need to delete 1 column.\n
    \n\n

    Example 2:

    \n\n
    \nInput: strs = ["a","b"]\nOutput: 0\nExplanation: The grid looks as follows:\n  a\n  b\nColumn 0 is the only column and is sorted, so you will not delete any columns.\n
    \n\n

    Example 3:

    \n\n
    \nInput: strs = ["zyx","wvu","tsr"]\nOutput: 3\nExplanation: The grid looks as follows:\n  zyx\n  wvu\n  tsr\nAll 3 columns are not sorted, so you will delete all 3.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == strs.length
    • \n\t
    • 1 <= n <= 100
    • \n\t
    • 1 <= strs[i].length <= 1000
    • \n\t
    • strs[i] consists of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u7531 n \u4e2a\u5c0f\u5199\u5b57\u6bcd\u5b57\u7b26\u4e32\u7ec4\u6210\u7684\u6570\u7ec4 strs\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5b57\u7b26\u4e32\u957f\u5ea6\u76f8\u7b49\u3002

    \n\n

    \u8fd9\u4e9b\u5b57\u7b26\u4e32\u53ef\u4ee5\u6bcf\u4e2a\u4e00\u884c\uff0c\u6392\u6210\u4e00\u4e2a\u7f51\u683c\u3002\u4f8b\u5982\uff0cstrs = [\"abc\", \"bce\", \"cae\"] \u53ef\u4ee5\u6392\u5217\u4e3a\uff1a

    \n\n
    \nabc\nbce\ncae
    \n\n

    \u4f60\u9700\u8981\u627e\u51fa\u5e76\u5220\u9664 \u4e0d\u662f\u6309\u5b57\u5178\u5e8f\u5347\u5e8f\u6392\u5217\u7684 \u5217\u3002\u5728\u4e0a\u9762\u7684\u4f8b\u5b50\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\u4e2d\uff0c\u5217 0\uff08'a', 'b', 'c'\uff09\u548c\u5217 2\uff08'c', 'e', 'e'\uff09\u90fd\u662f\u6309\u5347\u5e8f\u6392\u5217\u7684\uff0c\u800c\u5217 1\uff08'b', 'c', 'a'\uff09\u4e0d\u662f\uff0c\u6240\u4ee5\u8981\u5220\u9664\u5217 1 \u3002

    \n\n

    \u8fd4\u56de\u4f60\u9700\u8981\u5220\u9664\u7684\u5217\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1astrs = [\"cba\",\"daf\",\"ghi\"]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u7f51\u683c\u793a\u610f\u5982\u4e0b\uff1a\n  cba\n  daf\n  ghi\n\u5217 0 \u548c\u5217 2 \u6309\u5347\u5e8f\u6392\u5217\uff0c\u4f46\u5217 1 \u4e0d\u662f\uff0c\u6240\u4ee5\u53ea\u9700\u8981\u5220\u9664\u5217 1 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1astrs = [\"a\",\"b\"]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u7f51\u683c\u793a\u610f\u5982\u4e0b\uff1a\n  a\n  b\n\u53ea\u6709\u5217 0 \u8fd9\u4e00\u5217\uff0c\u4e14\u5df2\u7ecf\u6309\u5347\u5e8f\u6392\u5217\uff0c\u6240\u4ee5\u4e0d\u7528\u5220\u9664\u4efb\u4f55\u5217\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1astrs = [\"zyx\",\"wvu\",\"tsr\"]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u7f51\u683c\u793a\u610f\u5982\u4e0b\uff1a\n  zyx\n  wvu\n  tsr\n\u6240\u6709 3 \u5217\u90fd\u662f\u975e\u5347\u5e8f\u6392\u5217\u7684\uff0c\u6240\u4ee5\u90fd\u8981\u5220\u9664\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == strs.length
    • \n\t
    • 1 <= n <= 100
    • \n\t
    • 1 <= strs[i].length <= 1000
    • \n\t
    • strs[i] \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minDeletionSize(vector& strs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minDeletionSize(String[] strs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minDeletionSize(self, strs):\n \"\"\"\n :type strs: List[str]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minDeletionSize(self, strs: List[str]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minDeletionSize(char ** strs, int strsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinDeletionSize(string[] strs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} strs\n * @return {number}\n */\nvar minDeletionSize = function(strs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} strs\n# @return {Integer}\ndef min_deletion_size(strs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minDeletionSize(_ strs: [String]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minDeletionSize(strs []string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minDeletionSize(strs: Array[String]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minDeletionSize(strs: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_deletion_size(strs: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $strs\n * @return Integer\n */\n function minDeletionSize($strs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minDeletionSize(strs: string[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-deletion-size strs)\n (-> (listof string?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0944](https://leetcode-cn.com/problems/delete-columns-to-make-sorted)", "[\u5220\u5217\u9020\u5e8f](/solution/0900-0999/0944.Delete%20Columns%20to%20Make%20Sorted/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u7b80\u5355", ""], "md_table_row_en": ["[0944](https://leetcode.com/problems/delete-columns-to-make-sorted)", "[Delete Columns to Make Sorted](/solution/0900-0999/0944.Delete%20Columns%20to%20Make%20Sorted/README_EN.md)", "`Greedy`", "Easy", ""]}, {"question_id": "0980", "frontend_question_id": "0943", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-the-shortest-superstring", "url_en": "https://leetcode.com/problems/find-the-shortest-superstring", "relative_path_cn": "/solution/0900-0999/0943.Find%20the%20Shortest%20Superstring/README.md", "relative_path_en": "/solution/0900-0999/0943.Find%20the%20Shortest%20Superstring/README_EN.md", "title_cn": "\u6700\u77ed\u8d85\u7ea7\u4e32", "title_en": "Find the Shortest Superstring", "question_title_slug": "find-the-shortest-superstring", "content_en": "

    Given an array of strings words, return the smallest string that contains each string in words as a substring. If there are multiple valid strings of the smallest length, return any of them.

    \n\n

    You may assume that no string in words is a substring of another string in words.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: words = ["alex","loves","leetcode"]\nOutput: "alexlovesleetcode"\nExplanation: All permutations of "alex","loves","leetcode" would also be accepted.\n
    \n\n

    Example 2:

    \n\n
    \nInput: words = ["catg","ctaagt","gcta","ttca","atgcatc"]\nOutput: "gctaagttcatgcatc"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= words.length <= 12
    • \n\t
    • 1 <= words[i].length <= 20
    • \n\t
    • words[i] consists of lowercase English letters.
    • \n\t
    • All the strings of words are unique.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4 words\uff0c\u627e\u5230\u4ee5 words \u4e2d\u6bcf\u4e2a\u5b57\u7b26\u4e32\u4f5c\u4e3a\u5b50\u5b57\u7b26\u4e32\u7684\u6700\u77ed\u5b57\u7b26\u4e32\u3002\u5982\u679c\u6709\u591a\u4e2a\u6709\u6548\u6700\u77ed\u5b57\u7b26\u4e32\u6ee1\u8db3\u9898\u76ee\u6761\u4ef6\uff0c\u8fd4\u56de\u5176\u4e2d \u4efb\u610f\u4e00\u4e2a \u5373\u53ef\u3002

    \n\n

    \u6211\u4eec\u53ef\u4ee5\u5047\u8bbe words \u4e2d\u6ca1\u6709\u5b57\u7b26\u4e32\u662f words \u4e2d\u53e6\u4e00\u4e2a\u5b57\u7b26\u4e32\u7684\u5b50\u5b57\u7b26\u4e32\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1awords = [\"alex\",\"loves\",\"leetcode\"]\n\u8f93\u51fa\uff1a\"alexlovesleetcode\"\n\u89e3\u91ca\uff1a\"alex\"\uff0c\"loves\"\uff0c\"leetcode\" \u7684\u6240\u6709\u6392\u5217\u90fd\u4f1a\u88ab\u63a5\u53d7\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1awords = [\"catg\",\"ctaagt\",\"gcta\",\"ttca\",\"atgcatc\"]\n\u8f93\u51fa\uff1a\"gctaagttcatgcatc\"
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= words.length <= 12
    • \n\t
    • 1 <= words[i].length <= 20
    • \n\t
    • words[i] \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n\t
    • words \u4e2d\u7684\u6240\u6709\u5b57\u7b26\u4e32 \u4e92\u4e0d\u76f8\u540c
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string shortestSuperstring(vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String shortestSuperstring(String[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def shortestSuperstring(self, words):\n \"\"\"\n :type words: List[str]\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def shortestSuperstring(self, words: List[str]) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * shortestSuperstring(char ** words, int wordsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ShortestSuperstring(string[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @return {string}\n */\nvar shortestSuperstring = function(words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @return {String}\ndef shortest_superstring(words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func shortestSuperstring(_ words: [String]) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func shortestSuperstring(words []string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def shortestSuperstring(words: Array[String]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun shortestSuperstring(words: Array): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn shortest_superstring(words: Vec) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @return String\n */\n function shortestSuperstring($words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function shortestSuperstring(words: string[]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (shortest-superstring words)\n (-> (listof string?) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0943](https://leetcode-cn.com/problems/find-the-shortest-superstring)", "[\u6700\u77ed\u8d85\u7ea7\u4e32](/solution/0900-0999/0943.Find%20the%20Shortest%20Superstring/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0943](https://leetcode.com/problems/find-the-shortest-superstring)", "[Find the Shortest Superstring](/solution/0900-0999/0943.Find%20the%20Shortest%20Superstring/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "0979", "frontend_question_id": "0942", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/di-string-match", "url_en": "https://leetcode.com/problems/di-string-match", "relative_path_cn": "/solution/0900-0999/0942.DI%20String%20Match/README.md", "relative_path_en": "/solution/0900-0999/0942.DI%20String%20Match/README_EN.md", "title_cn": "\u589e\u51cf\u5b57\u7b26\u4e32\u5339\u914d", "title_en": "DI String Match", "question_title_slug": "di-string-match", "content_en": "

    A permutation perm of n + 1 integers of all the integers in the range [0, n] can be represented as a string s of length n where:

    \n\n
      \n\t
    • s[i] == 'I' if perm[i] < perm[i + 1], and
    • \n\t
    • s[i] == 'D' if perm[i] > perm[i + 1].
    • \n
    \n\n

    Given a string s, reconstruct the permutation perm and return it. If there are multiple valid permutations perm, return any of them.

    \n\n

     

    \n

    Example 1:

    \n
    Input: s = \"IDID\"\nOutput: [0,4,1,3,2]\n

    Example 2:

    \n
    Input: s = \"III\"\nOutput: [0,1,2,3]\n

    Example 3:

    \n
    Input: s = \"DDI\"\nOutput: [3,2,0,1]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 105
    • \n\t
    • s[i] is either 'I' or 'D'.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u53ea\u542b "I"\uff08\u589e\u5927\uff09\u6216 "D"\uff08\u51cf\u5c0f\uff09\u7684\u5b57\u7b26\u4e32 S \uff0c\u4ee4 N = S.length\u3002

    \n\n

    \u8fd4\u56de [0, 1, ..., N] \u7684\u4efb\u610f\u6392\u5217 A \u4f7f\u5f97\u5bf9\u4e8e\u6240\u6709 i = 0, ..., N-1\uff0c\u90fd\u6709\uff1a

    \n\n
      \n\t
    • \u5982\u679c S[i] == "I"\uff0c\u90a3\u4e48 A[i] < A[i+1]
    • \n\t
    • \u5982\u679c S[i] == "D"\uff0c\u90a3\u4e48 A[i] > A[i+1]
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a"IDID"\n\u8f93\u51fa\uff1a[0,4,1,3,2]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a"III"\n\u8f93\u51fa\uff1a[0,1,2,3]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1a"DDI"\n\u8f93\u51fa\uff1a[3,2,0,1]
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= S.length <= 10000
    • \n\t
    • S \u53ea\u5305\u542b\u5b57\u7b26 "I" \u6216 "D"\u3002
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector diStringMatch(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] diStringMatch(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def diStringMatch(self, s):\n \"\"\"\n :type s: str\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def diStringMatch(self, s: str) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* diStringMatch(char * s, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] DiStringMatch(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number[]}\n */\nvar diStringMatch = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer[]}\ndef di_string_match(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func diStringMatch(_ s: String) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func diStringMatch(s string) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def diStringMatch(s: String): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun diStringMatch(s: String): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn di_string_match(s: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer[]\n */\n function diStringMatch($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function diStringMatch(s: string): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (di-string-match s)\n (-> string? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0942](https://leetcode-cn.com/problems/di-string-match)", "[\u589e\u51cf\u5b57\u7b26\u4e32\u5339\u914d](/solution/0900-0999/0942.DI%20String%20Match/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0942](https://leetcode.com/problems/di-string-match)", "[DI String Match](/solution/0900-0999/0942.DI%20String%20Match/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "0978", "frontend_question_id": "0941", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/valid-mountain-array", "url_en": "https://leetcode.com/problems/valid-mountain-array", "relative_path_cn": "/solution/0900-0999/0941.Valid%20Mountain%20Array/README.md", "relative_path_en": "/solution/0900-0999/0941.Valid%20Mountain%20Array/README_EN.md", "title_cn": "\u6709\u6548\u7684\u5c71\u8109\u6570\u7ec4", "title_en": "Valid Mountain Array", "question_title_slug": "valid-mountain-array", "content_en": "

    Given an array of integers arr, return true if and only if it is a valid mountain array.

    \n\n

    Recall that arr is a mountain array if and only if:

    \n\n
      \n\t
    • arr.length >= 3
    • \n\t
    • There exists some i with 0 < i < arr.length - 1 such that:\n\t
        \n\t\t
      • arr[0] < arr[1] < ... < arr[i - 1] < arr[i]
      • \n\t\t
      • arr[i] > arr[i + 1] > ... > arr[arr.length - 1]
      • \n\t
      \n\t
    • \n
    \n\n

     

    \n

    Example 1:

    \n
    Input: arr = [2,1]\nOutput: false\n

    Example 2:

    \n
    Input: arr = [3,5,5]\nOutput: false\n

    Example 3:

    \n
    Input: arr = [0,3,2,1]\nOutput: true\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= arr.length <= 104
    • \n\t
    • 0 <= arr[i] <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr\uff0c\u5982\u679c\u5b83\u662f\u6709\u6548\u7684\u5c71\u8109\u6570\u7ec4\u5c31\u8fd4\u56de\u00a0true\uff0c\u5426\u5219\u8fd4\u56de false\u3002

    \n\n

    \u8ba9\u6211\u4eec\u56de\u987e\u4e00\u4e0b\uff0c\u5982\u679c A \u6ee1\u8db3\u4e0b\u8ff0\u6761\u4ef6\uff0c\u90a3\u4e48\u5b83\u662f\u4e00\u4e2a\u5c71\u8109\u6570\u7ec4\uff1a

    \n\n
      \n\t
    • arr.length >= 3
    • \n\t
    • \u5728\u00a00 < i\u00a0< arr.length - 1\u00a0\u6761\u4ef6\u4e0b\uff0c\u5b58\u5728\u00a0i\u00a0\u4f7f\u5f97\uff1a\n\t
        \n\t\t
      • arr[0] < arr[1] < ... arr[i-1] < arr[i]
      • \n\t\t
      • arr[i] > arr[i+1] > ... > arr[arr.length - 1]
      • \n\t
      \n\t
    • \n
    \n\n

    \u00a0

    \n\n

    \"\"

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [2,1]\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [3,5,5]\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [0,3,2,1]\n\u8f93\u51fa\uff1atrue
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= arr.length <= 104
    • \n\t
    • 0 <= arr[i] <= 104
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool validMountainArray(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean validMountainArray(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def validMountainArray(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def validMountainArray(self, arr: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool validMountainArray(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool ValidMountainArray(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {boolean}\n */\nvar validMountainArray = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Boolean}\ndef valid_mountain_array(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func validMountainArray(_ arr: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func validMountainArray(arr []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def validMountainArray(arr: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun validMountainArray(arr: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn valid_mountain_array(arr: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Boolean\n */\n function validMountainArray($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function validMountainArray(arr: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (valid-mountain-array arr)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0941](https://leetcode-cn.com/problems/valid-mountain-array)", "[\u6709\u6548\u7684\u5c71\u8109\u6570\u7ec4](/solution/0900-0999/0941.Valid%20Mountain%20Array/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0941](https://leetcode.com/problems/valid-mountain-array)", "[Valid Mountain Array](/solution/0900-0999/0941.Valid%20Mountain%20Array/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0977", "frontend_question_id": "0940", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/distinct-subsequences-ii", "url_en": "https://leetcode.com/problems/distinct-subsequences-ii", "relative_path_cn": "/solution/0900-0999/0940.Distinct%20Subsequences%20II/README.md", "relative_path_en": "/solution/0900-0999/0940.Distinct%20Subsequences%20II/README_EN.md", "title_cn": "\u4e0d\u540c\u7684\u5b50\u5e8f\u5217 II", "title_en": "Distinct Subsequences II", "question_title_slug": "distinct-subsequences-ii", "content_en": "

    Given a string s, count the number of distinct, non-empty subsequences of s .

    \n\n

    Since the result may be large, return the answer modulo 109 + 7.

    \n\n

     

    \n\n

    Example 1:

    \n\n
    \nInput: s = "abc"\nOutput: 7\nExplanation: The 7 distinct subsequences are "a", "b", "c", "ab", "ac", "bc", and "abc".\n
    \n\n
    \n

    Example 2:

    \n\n
    \nInput: s = "aba"\nOutput: 6\nExplanation: The 6 distinct subsequences are "a", "b", "ab", "ba", "aa" and "aba".\n
    \n\n
    \n

    Example 3:

    \n\n
    \nInput: s = "aaa"\nOutput: 3\nExplanation: The 3 distinct subsequences are "a", "aa" and "aaa".\n
    \n
    \n
    \n\n

     

    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    1. s contains only lowercase letters.
    2. \n\t
    3. 1 <= s.length <= 2000
    4. \n
    \n\n
    \n

     

    \n\n
    \n
     
    \n
    \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32 S\uff0c\u8ba1\u7b97 S \u7684\u4e0d\u540c\u975e\u7a7a\u5b50\u5e8f\u5217\u7684\u4e2a\u6570\u3002

    \n\n

    \u56e0\u4e3a\u7ed3\u679c\u53ef\u80fd\u5f88\u5927\uff0c\u6240\u4ee5\u8fd4\u56de\u7b54\u6848\u6a21 10^9 + 7.

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a"abc"\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a7 \u4e2a\u4e0d\u540c\u7684\u5b50\u5e8f\u5217\u5206\u522b\u662f "a", "b", "c", "ab", "ac", "bc", \u4ee5\u53ca "abc"\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a"aba"\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a6 \u4e2a\u4e0d\u540c\u7684\u5b50\u5e8f\u5217\u5206\u522b\u662f "a", "b", "ab", "ba", "aa" \u4ee5\u53ca "aba"\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1a"aaa"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a3 \u4e2a\u4e0d\u540c\u7684\u5b50\u5e8f\u5217\u5206\u522b\u662f "a", "aa" \u4ee5\u53ca "aaa"\u3002\n
    \n\n

     

    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. S \u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd\u3002
    2. \n\t
    3. 1 <= S.length <= 2000
    4. \n
    \n\n

     

    \n\n

     

    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int distinctSubseqII(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int distinctSubseqII(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def distinctSubseqII(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def distinctSubseqII(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint distinctSubseqII(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int DistinctSubseqII(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar distinctSubseqII = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef distinct_subseq_ii(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func distinctSubseqII(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func distinctSubseqII(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def distinctSubseqII(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun distinctSubseqII(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn distinct_subseq_ii(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function distinctSubseqII($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function distinctSubseqII(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (distinct-subseq-ii s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0940](https://leetcode-cn.com/problems/distinct-subsequences-ii)", "[\u4e0d\u540c\u7684\u5b50\u5e8f\u5217 II](/solution/0900-0999/0940.Distinct%20Subsequences%20II/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0940](https://leetcode.com/problems/distinct-subsequences-ii)", "[Distinct Subsequences II](/solution/0900-0999/0940.Distinct%20Subsequences%20II/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "0976", "frontend_question_id": "0939", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-area-rectangle", "url_en": "https://leetcode.com/problems/minimum-area-rectangle", "relative_path_cn": "/solution/0900-0999/0939.Minimum%20Area%20Rectangle/README.md", "relative_path_en": "/solution/0900-0999/0939.Minimum%20Area%20Rectangle/README_EN.md", "title_cn": "\u6700\u5c0f\u9762\u79ef\u77e9\u5f62", "title_en": "Minimum Area Rectangle", "question_title_slug": "minimum-area-rectangle", "content_en": "

    Given a set of points in the xy-plane, determine the minimum area of a rectangle formed from these points, with sides parallel to the x and y axes.

    \r\n\r\n

    If there isn't any rectangle, return 0.

    \r\n\r\n

     

    \r\n\r\n
    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: [[1,1],[1,3],[3,1],[3,3],[2,2]]\r\nOutput: 4\r\n
    \r\n\r\n
    \r\n

    Example 2:

    \r\n\r\n
    \r\nInput: [[1,1],[1,3],[3,1],[3,3],[4,1],[4,3]]\r\nOutput: 2\r\n
    \r\n\r\n

     

    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    1. 1 <= points.length <= 500
    2. \r\n\t
    3. 0 <= points[i][0] <= 40000
    4. \r\n\t
    5. 0 <= points[i][1] <= 40000
    6. \r\n\t
    7. All points are distinct.
    8. \r\n
    \r\n
    \r\n
    ", "content_cn": "

    \u7ed9\u5b9a\u5728 xy \u5e73\u9762\u4e0a\u7684\u4e00\u7ec4\u70b9\uff0c\u786e\u5b9a\u7531\u8fd9\u4e9b\u70b9\u7ec4\u6210\u7684\u77e9\u5f62\u7684\u6700\u5c0f\u9762\u79ef\uff0c\u5176\u4e2d\u77e9\u5f62\u7684\u8fb9\u5e73\u884c\u4e8e x \u8f74\u548c y \u8f74\u3002

    \n\n

    \u5982\u679c\u6ca1\u6709\u4efb\u4f55\u77e9\u5f62\uff0c\u5c31\u8fd4\u56de 0\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a[[1,1],[1,3],[3,1],[3,3],[2,2]]\n\u8f93\u51fa\uff1a4\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a[[1,1],[1,3],[3,1],[3,3],[4,1],[4,3]]\n\u8f93\u51fa\uff1a2\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= points.length <= 500
    2. \n\t
    3. 0 <= points[i][0] <= 40000
    4. \n\t
    5. 0 <= points[i][1] <= 40000
    6. \n\t
    7. \u6240\u6709\u7684\u70b9\u90fd\u662f\u4e0d\u540c\u7684\u3002
    8. \n
    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minAreaRect(vector>& points) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minAreaRect(int[][] points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minAreaRect(self, points):\n \"\"\"\n :type points: List[List[int]]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minAreaRect(self, points: List[List[int]]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minAreaRect(int** points, int pointsSize, int* pointsColSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinAreaRect(int[][] points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} points\n * @return {number}\n */\nvar minAreaRect = function(points) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} points\n# @return {Integer}\ndef min_area_rect(points)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minAreaRect(_ points: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minAreaRect(points [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minAreaRect(points: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minAreaRect(points: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_area_rect(points: Vec>) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $points\n * @return Integer\n */\n function minAreaRect($points) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minAreaRect(points: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-area-rect points)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0939](https://leetcode-cn.com/problems/minimum-area-rectangle)", "[\u6700\u5c0f\u9762\u79ef\u77e9\u5f62](/solution/0900-0999/0939.Minimum%20Area%20Rectangle/README.md)", "`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0939](https://leetcode.com/problems/minimum-area-rectangle)", "[Minimum Area Rectangle](/solution/0900-0999/0939.Minimum%20Area%20Rectangle/README_EN.md)", "`Hash Table`", "Medium", ""]}, {"question_id": "0975", "frontend_question_id": "0938", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/range-sum-of-bst", "url_en": "https://leetcode.com/problems/range-sum-of-bst", "relative_path_cn": "/solution/0900-0999/0938.Range%20Sum%20of%20BST/README.md", "relative_path_en": "/solution/0900-0999/0938.Range%20Sum%20of%20BST/README_EN.md", "title_cn": "\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u8303\u56f4\u548c", "title_en": "Range Sum of BST", "question_title_slug": "range-sum-of-bst", "content_en": "

    Given the root node of a binary search tree and two integers low and high, return the sum of values of all nodes with a value in the inclusive range [low, high].

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [10,5,15,3,7,null,18], low = 7, high = 15\nOutput: 32\nExplanation: Nodes 7, 10, and 15 are in the range [7, 15]. 7 + 10 + 15 = 32.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [10,5,15,3,7,13,18,1,null,6], low = 6, high = 10\nOutput: 23\nExplanation: Nodes 6, 7, and 10 are in the range [6, 10]. 6 + 7 + 10 = 23.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 2 * 104].
    • \n\t
    • 1 <= Node.val <= 105
    • \n\t
    • 1 <= low <= high <= 105
    • \n\t
    • All Node.val are unique.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6839\u7ed3\u70b9\u00a0root\uff0c\u8fd4\u56de\u503c\u4f4d\u4e8e\u8303\u56f4 [low, high] \u4e4b\u95f4\u7684\u6240\u6709\u7ed3\u70b9\u7684\u503c\u7684\u548c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [10,5,15,3,7,null,18], low = 7, high = 15\n\u8f93\u51fa\uff1a32\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [10,5,15,3,7,13,18,1,null,6], low = 6, high = 10\n\u8f93\u51fa\uff1a23\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u6570\u76ee\u5728\u8303\u56f4 [1, 2 * 104] \u5185
    • \n\t
    • 1 <= Node.val <= 105
    • \n\t
    • 1 <= low <= high <= 105
    • \n\t
    • \u6240\u6709 Node.val \u4e92\u4e0d\u76f8\u540c
    • \n
    \n", "tags_en": ["Tree", "Depth-first Search", "Recursion"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u9012\u5f52"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int rangeSumBST(TreeNode* root, int low, int high) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int rangeSumBST(TreeNode root, int low, int high) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def rangeSumBST(self, root, low, high):\n \"\"\"\n :type root: TreeNode\n :type low: int\n :type high: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def rangeSumBST(self, root: TreeNode, low: int, high: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint rangeSumBST(struct TreeNode* root, int low, int high){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int RangeSumBST(TreeNode root, int low, int high) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number} low\n * @param {number} high\n * @return {number}\n */\nvar rangeSumBST = function(root, low, high) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @param {Integer} low\n# @param {Integer} high\n# @return {Integer}\ndef range_sum_bst(root, low, high)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func rangeSumBST(_ root: TreeNode?, _ low: Int, _ high: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc rangeSumBST(root *TreeNode, low int, high int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def rangeSumBST(root: TreeNode, low: Int, high: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun rangeSumBST(root: TreeNode?, low: Int, high: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn range_sum_bst(root: Option>>, low: i32, high: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param Integer $low\n * @param Integer $high\n * @return Integer\n */\n function rangeSumBST($root, $low, $high) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction rangeSumBST(root: TreeNode | null, low: number, high: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (range-sum-bst root low high)\n (-> (or/c tree-node? #f) exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0938](https://leetcode-cn.com/problems/range-sum-of-bst)", "[\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u8303\u56f4\u548c](/solution/0900-0999/0938.Range%20Sum%20of%20BST/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u9012\u5f52`", "\u7b80\u5355", ""], "md_table_row_en": ["[0938](https://leetcode.com/problems/range-sum-of-bst)", "[Range Sum of BST](/solution/0900-0999/0938.Range%20Sum%20of%20BST/README_EN.md)", "`Tree`,`Depth-first Search`,`Recursion`", "Easy", ""]}, {"question_id": "0974", "frontend_question_id": "0937", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reorder-data-in-log-files", "url_en": "https://leetcode.com/problems/reorder-data-in-log-files", "relative_path_cn": "/solution/0900-0999/0937.Reorder%20Data%20in%20Log%20Files/README.md", "relative_path_en": "/solution/0900-0999/0937.Reorder%20Data%20in%20Log%20Files/README_EN.md", "title_cn": "\u91cd\u65b0\u6392\u5217\u65e5\u5fd7\u6587\u4ef6", "title_en": "Reorder Data in Log Files", "question_title_slug": "reorder-data-in-log-files", "content_en": "

    You are given an array of logs. Each log is a space-delimited string of words, where the first word is the identifier.

    \n\n

    There are two types of logs:

    \n\n
      \n\t
    • Letter-logs: All words (except the identifier) consist of lowercase English letters.
    • \n\t
    • Digit-logs: All words (except the identifier) consist of digits.
    • \n
    \n\n

    Reorder these logs so that:

    \n\n
      \n\t
    1. The letter-logs come before all digit-logs.
    2. \n\t
    3. The letter-logs are sorted lexicographically by their contents. If their contents are the same, then sort them lexicographically by their identifiers.
    4. \n\t
    5. The digit-logs maintain their relative ordering.
    6. \n
    \n\n

    Return the final order of the logs.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: logs = ["dig1 8 1 5 1","let1 art can","dig2 3 6","let2 own kit dig","let3 art zero"]\nOutput: ["let1 art can","let3 art zero","let2 own kit dig","dig1 8 1 5 1","dig2 3 6"]\nExplanation:\nThe letter-log contents are all different, so their ordering is "art can", "art zero", "own kit dig".\nThe digit-logs have a relative order of "dig1 8 1 5 1", "dig2 3 6".\n
    \n\n

    Example 2:

    \n\n
    \nInput: logs = ["a1 9 2 3 1","g1 act car","zo4 4 7","ab1 off key dog","a8 act zoo"]\nOutput: ["g1 act car","a8 act zoo","ab1 off key dog","a1 9 2 3 1","zo4 4 7"]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= logs.length <= 100
    • \n\t
    • 3 <= logs[i].length <= 100
    • \n\t
    • All the tokens of logs[i] are separated by a single space.
    • \n\t
    • logs[i] is guaranteed to have an identifier and at least one word after the identifier.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u65e5\u5fd7\u6570\u7ec4 logs\u3002\u6bcf\u6761\u65e5\u5fd7\u90fd\u662f\u4ee5\u7a7a\u683c\u5206\u9694\u7684\u5b57\u4e32\uff0c\u5176\u7b2c\u4e00\u4e2a\u5b57\u4e3a\u5b57\u6bcd\u4e0e\u6570\u5b57\u6df7\u5408\u7684 \u6807\u8bc6\u7b26 \u3002

    \n\n

    \u6709\u4e24\u79cd\u4e0d\u540c\u7c7b\u578b\u7684\u65e5\u5fd7\uff1a

    \n\n
      \n\t
    • \u5b57\u6bcd\u65e5\u5fd7\uff1a\u9664\u6807\u8bc6\u7b26\u4e4b\u5916\uff0c\u6240\u6709\u5b57\u5747\u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210
    • \n\t
    • \u6570\u5b57\u65e5\u5fd7\uff1a\u9664\u6807\u8bc6\u7b26\u4e4b\u5916\uff0c\u6240\u6709\u5b57\u5747\u7531\u6570\u5b57\u7ec4\u6210
    • \n
    \n\n

    \u8bf7\u6309\u4e0b\u8ff0\u89c4\u5219\u5c06\u65e5\u5fd7\u91cd\u65b0\u6392\u5e8f\uff1a

    \n\n
      \n\t
    • \u6240\u6709 \u5b57\u6bcd\u65e5\u5fd7 \u90fd\u6392\u5728 \u6570\u5b57\u65e5\u5fd7 \u4e4b\u524d\u3002
    • \n\t
    • \u5b57\u6bcd\u65e5\u5fd7 \u5728\u5185\u5bb9\u4e0d\u540c\u65f6\uff0c\u5ffd\u7565\u6807\u8bc6\u7b26\u540e\uff0c\u6309\u5185\u5bb9\u5b57\u6bcd\u987a\u5e8f\u6392\u5e8f\uff1b\u5728\u5185\u5bb9\u76f8\u540c\u65f6\uff0c\u6309\u6807\u8bc6\u7b26\u6392\u5e8f\u3002
    • \n\t
    • \u6570\u5b57\u65e5\u5fd7 \u5e94\u8be5\u4fdd\u7559\u539f\u6765\u7684\u76f8\u5bf9\u987a\u5e8f\u3002
    • \n
    \n\n

    \u8fd4\u56de\u65e5\u5fd7\u7684\u6700\u7ec8\u987a\u5e8f\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1alogs = [\"dig1 8 1 5 1\",\"let1 art can\",\"dig2 3 6\",\"let2 own kit dig\",\"let3 art zero\"]\n\u8f93\u51fa\uff1a[\"let1 art can\",\"let3 art zero\",\"let2 own kit dig\",\"dig1 8 1 5 1\",\"dig2 3 6\"]\n\u89e3\u91ca\uff1a\n\u5b57\u6bcd\u65e5\u5fd7\u7684\u5185\u5bb9\u90fd\u4e0d\u540c\uff0c\u6240\u4ee5\u987a\u5e8f\u4e3a \"art can\", \"art zero\", \"own kit dig\" \u3002\n\u6570\u5b57\u65e5\u5fd7\u4fdd\u7559\u539f\u6765\u7684\u76f8\u5bf9\u987a\u5e8f \"dig1 8 1 5 1\", \"dig2 3 6\" \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1alogs = [\"a1 9 2 3 1\",\"g1 act car\",\"zo4 4 7\",\"ab1 off key dog\",\"a8 act zoo\"]\n\u8f93\u51fa\uff1a[\"g1 act car\",\"a8 act zoo\",\"ab1 off key dog\",\"a1 9 2 3 1\",\"zo4 4 7\"]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= logs.length <= 100
    • \n\t
    • 3 <= logs[i].length <= 100
    • \n\t
    • logs[i] \u4e2d\uff0c\u5b57\u4e0e\u5b57\u4e4b\u95f4\u90fd\u7528 \u5355\u4e2a \u7a7a\u683c\u5206\u9694
    • \n\t
    • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1 logs[i] \u90fd\u6709\u4e00\u4e2a\u6807\u8bc6\u7b26\uff0c\u5e76\u4e14\u5728\u6807\u8bc6\u7b26\u4e4b\u540e\u81f3\u5c11\u5b58\u5728\u4e00\u4e2a\u5b57
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector reorderLogFiles(vector& logs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String[] reorderLogFiles(String[] logs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def reorderLogFiles(self, logs):\n \"\"\"\n :type logs: List[str]\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def reorderLogFiles(self, logs: List[str]) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** reorderLogFiles(char ** logs, int logsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string[] ReorderLogFiles(string[] logs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} logs\n * @return {string[]}\n */\nvar reorderLogFiles = function(logs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} logs\n# @return {String[]}\ndef reorder_log_files(logs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func reorderLogFiles(_ logs: [String]) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func reorderLogFiles(logs []string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def reorderLogFiles(logs: Array[String]): Array[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun reorderLogFiles(logs: Array): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn reorder_log_files(logs: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $logs\n * @return String[]\n */\n function reorderLogFiles($logs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function reorderLogFiles(logs: string[]): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (reorder-log-files logs)\n (-> (listof string?) (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0937](https://leetcode-cn.com/problems/reorder-data-in-log-files)", "[\u91cd\u65b0\u6392\u5217\u65e5\u5fd7\u6587\u4ef6](/solution/0900-0999/0937.Reorder%20Data%20in%20Log%20Files/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0937](https://leetcode.com/problems/reorder-data-in-log-files)", "[Reorder Data in Log Files](/solution/0900-0999/0937.Reorder%20Data%20in%20Log%20Files/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "0973", "frontend_question_id": "0936", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/stamping-the-sequence", "url_en": "https://leetcode.com/problems/stamping-the-sequence", "relative_path_cn": "/solution/0900-0999/0936.Stamping%20The%20Sequence/README.md", "relative_path_en": "/solution/0900-0999/0936.Stamping%20The%20Sequence/README_EN.md", "title_cn": "\u6233\u5370\u5e8f\u5217", "title_en": "Stamping The Sequence", "question_title_slug": "stamping-the-sequence", "content_en": "

    You want to form a target string of lowercase letters.

    \r\n\r\n

    At the beginning, your sequence is target.length '?' marks.  You also have a stamp of lowercase letters.

    \r\n\r\n

    On each turn, you may place the stamp over the sequence, and replace every letter in the sequence with the corresponding letter from the stamp.  You can make up to 10 * target.length turns.

    \r\n\r\n

    For example, if the initial sequence is "?????", and your stamp is "abc",  then you may make "abc??", "?abc?", "??abc" in the first turn.  (Note that the stamp must be fully contained in the boundaries of the sequence in order to stamp.)

    \r\n\r\n

    If the sequence is possible to stamp, then return an array of the index of the left-most letter being stamped at each turn.  If the sequence is not possible to stamp, return an empty array.

    \r\n\r\n

    For example, if the sequence is "ababc", and the stamp is "abc", then we could return the answer [0, 2], corresponding to the moves "?????" -> "abc??" -> "ababc".

    \r\n\r\n

    Also, if the sequence is possible to stamp, it is guaranteed it is possible to stamp within 10 * target.length moves.  Any answers specifying more than this number of moves will not be accepted.

    \r\n\r\n

     

    \r\n\r\n

    Example 1:

    \r\n\r\n
    \r\nInput: stamp = "abc", target = "ababc"\r\nOutput: [0,2]\r\n([1,0,2] would also be accepted as an answer, as well as some other answers.)\r\n
    \r\n\r\n
    \r\n

    Example 2:

    \r\n\r\n
    \r\nInput: stamp = "abca", target = "aabcaca"\r\nOutput: [3,0,1]\r\n
    \r\n\r\n
    \r\n

     

    \r\n\r\n

    Note:

    \r\n
    \r\n
    \r\n\r\n
      \r\n\t
    1. 1 <= stamp.length <= target.length <= 1000
    2. \r\n\t
    3. stamp and target only contain lowercase letters.
    4. \r\n
    ", "content_cn": "

    \u4f60\u60f3\u8981\u7528\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210\u4e00\u4e2a\u76ee\u6807\u5b57\u7b26\u4e32 target\u3002 

    \n\n

    \u5f00\u59cb\u7684\u65f6\u5019\uff0c\u5e8f\u5217\u7531 target.length \u4e2a '?' \u8bb0\u53f7\u7ec4\u6210\u3002\u800c\u4f60\u6709\u4e00\u4e2a\u5c0f\u5199\u5b57\u6bcd\u5370\u7ae0 stamp\u3002

    \n\n

    \u5728\u6bcf\u4e2a\u56de\u5408\uff0c\u4f60\u53ef\u4ee5\u5c06\u5370\u7ae0\u653e\u5728\u5e8f\u5217\u4e0a\uff0c\u5e76\u5c06\u5e8f\u5217\u4e2d\u7684\u6bcf\u4e2a\u5b57\u6bcd\u66ff\u6362\u4e3a\u5370\u7ae0\u4e0a\u7684\u76f8\u5e94\u5b57\u6bcd\u3002\u4f60\u6700\u591a\u53ef\u4ee5\u8fdb\u884c 10 * target.length  \u4e2a\u56de\u5408\u3002

    \n\n

    \u4e3e\u4e2a\u4f8b\u5b50\uff0c\u5982\u679c\u521d\u59cb\u5e8f\u5217\u4e3a "?????"\uff0c\u800c\u4f60\u7684\u5370\u7ae0 stamp \u662f "abc"\uff0c\u90a3\u4e48\u5728\u7b2c\u4e00\u56de\u5408\uff0c\u4f60\u53ef\u4ee5\u5f97\u5230 "abc??"\u3001"?abc?"\u3001"??abc"\u3002\uff08\u8bf7\u6ce8\u610f\uff0c\u5370\u7ae0\u5fc5\u987b\u5b8c\u5168\u5305\u542b\u5728\u5e8f\u5217\u7684\u8fb9\u754c\u5185\u624d\u80fd\u76d6\u4e0b\u53bb\u3002\uff09

    \n\n

    \u5982\u679c\u53ef\u4ee5\u5370\u51fa\u5e8f\u5217\uff0c\u90a3\u4e48\u8fd4\u56de\u4e00\u4e2a\u6570\u7ec4\uff0c\u8be5\u6570\u7ec4\u7531\u6bcf\u4e2a\u56de\u5408\u4e2d\u88ab\u5370\u4e0b\u7684\u6700\u5de6\u8fb9\u5b57\u6bcd\u7684\u7d22\u5f15\u7ec4\u6210\u3002\u5982\u679c\u4e0d\u80fd\u5370\u51fa\u5e8f\u5217\uff0c\u5c31\u8fd4\u56de\u4e00\u4e2a\u7a7a\u6570\u7ec4\u3002

    \n\n

    \u4f8b\u5982\uff0c\u5982\u679c\u5e8f\u5217\u662f "ababc"\uff0c\u5370\u7ae0\u662f "abc"\uff0c\u90a3\u4e48\u6211\u4eec\u5c31\u53ef\u4ee5\u8fd4\u56de\u4e0e\u64cd\u4f5c "?????" -> "abc??" -> "ababc" \u76f8\u5bf9\u5e94\u7684\u7b54\u6848 [0, 2]\uff1b

    \n\n

    \u53e6\u5916\uff0c\u5982\u679c\u53ef\u4ee5\u5370\u51fa\u5e8f\u5217\uff0c\u90a3\u4e48\u9700\u8981\u4fdd\u8bc1\u53ef\u4ee5\u5728 10 * target.length \u4e2a\u56de\u5408\u5185\u5b8c\u6210\u3002\u4efb\u4f55\u8d85\u8fc7\u6b64\u6570\u5b57\u7684\u7b54\u6848\u5c06\u4e0d\u88ab\u63a5\u53d7\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1astamp = "abc", target = "ababc"\n\u8f93\u51fa\uff1a[0,2]\n\uff08[1,0,2] \u4ee5\u53ca\u5176\u4ed6\u4e00\u4e9b\u53ef\u80fd\u7684\u7ed3\u679c\u4e5f\u5c06\u4f5c\u4e3a\u7b54\u6848\u88ab\u63a5\u53d7\uff09\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1astamp = "abca", target = "aabcaca"\n\u8f93\u51fa\uff1a[3,0,1]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= stamp.length <= target.length <= 1000
    2. \n\t
    3. stamp \u548c target \u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd\u3002
    4. \n
    \n", "tags_en": ["Greedy", "String"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector movesToStamp(string stamp, string target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] movesToStamp(String stamp, String target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def movesToStamp(self, stamp, target):\n \"\"\"\n :type stamp: str\n :type target: str\n :rtype: List[int]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def movesToStamp(self, stamp: str, target: str) -> List[int]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* movesToStamp(char * stamp, char * target, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] MovesToStamp(string stamp, string target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} stamp\n * @param {string} target\n * @return {number[]}\n */\nvar movesToStamp = function(stamp, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} stamp\n# @param {String} target\n# @return {Integer[]}\ndef moves_to_stamp(stamp, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func movesToStamp(_ stamp: String, _ target: String) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func movesToStamp(stamp string, target string) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def movesToStamp(stamp: String, target: String): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun movesToStamp(stamp: String, target: String): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn moves_to_stamp(stamp: String, target: String) -> Vec {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $stamp\n * @param String $target\n * @return Integer[]\n */\n function movesToStamp($stamp, $target) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function movesToStamp(stamp: string, target: string): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (moves-to-stamp stamp target)\n (-> string? string? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0936](https://leetcode-cn.com/problems/stamping-the-sequence)", "[\u6233\u5370\u5e8f\u5217](/solution/0900-0999/0936.Stamping%20The%20Sequence/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u5b57\u7b26\u4e32`", "\u56f0\u96be", ""], "md_table_row_en": ["[0936](https://leetcode.com/problems/stamping-the-sequence)", "[Stamping The Sequence](/solution/0900-0999/0936.Stamping%20The%20Sequence/README_EN.md)", "`Greedy`,`String`", "Hard", ""]}, {"question_id": "0972", "frontend_question_id": "0935", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/knight-dialer", "url_en": "https://leetcode.com/problems/knight-dialer", "relative_path_cn": "/solution/0900-0999/0935.Knight%20Dialer/README.md", "relative_path_en": "/solution/0900-0999/0935.Knight%20Dialer/README_EN.md", "title_cn": "\u9a91\u58eb\u62e8\u53f7\u5668", "title_en": "Knight Dialer", "question_title_slug": "knight-dialer", "content_en": "

    The chess knight has a unique movement, it may move two squares vertically and one square horizontally, or two squares horizontally and one square vertically (with both forming the shape of an L). The possible movements of chess knight are shown in this diagaram:

    \n\n

    A chess knight can move as indicated in the chess diagram below:

    \n\"\"\n

    We have a chess knight and a phone pad as shown below, the knight can only stand on a numeric cell (i.e. blue cell).

    \n\"\"\n

    Given an integer n, return how many distinct phone numbers of length n we can dial.

    \n\n

    You are allowed to place the knight on any numeric cell initially and then you should perform n - 1 jumps to dial a number of length n. All jumps should be valid knight jumps.

    \n\n

    As the answer may be very large, return the answer modulo 109 + 7.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 1\nOutput: 10\nExplanation: We need to dial a number of length 1, so placing the knight over any numeric cell of the 10 cells is sufficient.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 2\nOutput: 20\nExplanation: All the valid number we can dial are [04, 06, 16, 18, 27, 29, 34, 38, 40, 43, 49, 60, 61, 67, 72, 76, 81, 83, 92, 94]\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 3\nOutput: 46\n
    \n\n

    Example 4:

    \n\n
    \nInput: n = 4\nOutput: 104\n
    \n\n

    Example 5:

    \n\n
    \nInput: n = 3131\nOutput: 136006598\nExplanation: Please take care of the mod.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 5000
    • \n
    \n", "content_cn": "

    \u56fd\u9645\u8c61\u68cb\u4e2d\u7684\u9a91\u58eb\u53ef\u4ee5\u6309\u4e0b\u56fe\u6240\u793a\u8fdb\u884c\u79fb\u52a8\uff1a

    \n\n

    \"\" .           \"\"

    \n\n


    \n\u8fd9\u4e00\u6b21\uff0c\u6211\u4eec\u5c06 “\u9a91\u58eb” \u653e\u5728\u7535\u8bdd\u62e8\u53f7\u76d8\u7684\u4efb\u610f\u6570\u5b57\u952e\uff08\u5982\u4e0a\u56fe\u6240\u793a\uff09\u4e0a\uff0c\u63a5\u4e0b\u6765\uff0c\u9a91\u58eb\u5c06\u4f1a\u8df3 N-1 \u6b65\u3002\u6bcf\u4e00\u6b65\u5fc5\u987b\u662f\u4ece\u4e00\u4e2a\u6570\u5b57\u952e\u8df3\u5230\u53e6\u4e00\u4e2a\u6570\u5b57\u952e\u3002

    \n\n

    \u6bcf\u5f53\u5b83\u843d\u5728\u4e00\u4e2a\u952e\u4e0a\uff08\u5305\u62ec\u9a91\u58eb\u7684\u521d\u59cb\u4f4d\u7f6e\uff09\uff0c\u90fd\u4f1a\u62e8\u51fa\u952e\u6240\u5bf9\u5e94\u7684\u6570\u5b57\uff0c\u603b\u5171\u6309\u4e0b N \u4f4d\u6570\u5b57\u3002

    \n\n

    \u4f60\u80fd\u7528\u8fd9\u79cd\u65b9\u5f0f\u62e8\u51fa\u591a\u5c11\u4e2a\u4e0d\u540c\u7684\u53f7\u7801\uff1f

    \n\n

    \u56e0\u4e3a\u7b54\u6848\u53ef\u80fd\u5f88\u5927\uff0c\u6240\u4ee5\u8f93\u51fa\u7b54\u6848\u6a21 10^9 + 7\u3002

    \n\n

     

    \n\n
      \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a1\n\u8f93\u51fa\uff1a10\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a2\n\u8f93\u51fa\uff1a20\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1a3\n\u8f93\u51fa\uff1a46\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= N <= 5000
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int knightDialer(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int knightDialer(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def knightDialer(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def knightDialer(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint knightDialer(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int KnightDialer(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar knightDialer = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef knight_dialer(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func knightDialer(_ n: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func knightDialer(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def knightDialer(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun knightDialer(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn knight_dialer(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function knightDialer($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function knightDialer(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (knight-dialer n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0935](https://leetcode-cn.com/problems/knight-dialer)", "[\u9a91\u58eb\u62e8\u53f7\u5668](/solution/0900-0999/0935.Knight%20Dialer/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0935](https://leetcode.com/problems/knight-dialer)", "[Knight Dialer](/solution/0900-0999/0935.Knight%20Dialer/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0971", "frontend_question_id": "0934", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/shortest-bridge", "url_en": "https://leetcode.com/problems/shortest-bridge", "relative_path_cn": "/solution/0900-0999/0934.Shortest%20Bridge/README.md", "relative_path_en": "/solution/0900-0999/0934.Shortest%20Bridge/README_EN.md", "title_cn": "\u6700\u77ed\u7684\u6865", "title_en": "Shortest Bridge", "question_title_slug": "shortest-bridge", "content_en": "

    In a given 2D binary array grid, there are two islands.  (An island is a 4-directionally connected group of 1s not connected to any other 1s.)

    \n\n

    Now, we may change 0s to 1s so as to connect the two islands together to form 1 island.

    \n\n

    Return the smallest number of 0s that must be flipped.  (It is guaranteed that the answer is at least 1.)

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: grid = [[0,1],[1,0]]\nOutput: 1\n
    \n\n

    Example 2:

    \n\n
    \nInput: grid = [[0,1,0],[0,0,0],[0,0,1]]\nOutput: 2\n
    \n\n

    Example 3:

    \n\n
    \nInput: grid = [[1,1,1,1,1],[1,0,0,0,1],[1,0,1,0,1],[1,0,0,0,1],[1,1,1,1,1]]\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= grid.length == grid[0].length <= 100
    • \n\t
    • grid[i][j] == 0 or grid[i][j] == 1
    • \n
    \n", "content_cn": "

    \u5728\u7ed9\u5b9a\u7684\u4e8c\u7ef4\u4e8c\u8fdb\u5236\u6570\u7ec4\u00a0A\u00a0\u4e2d\uff0c\u5b58\u5728\u4e24\u5ea7\u5c9b\u3002\uff08\u5c9b\u662f\u7531\u56db\u9762\u76f8\u8fde\u7684 1 \u5f62\u6210\u7684\u4e00\u4e2a\u6700\u5927\u7ec4\u3002\uff09

    \n\n

    \u73b0\u5728\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u00a00\u00a0\u53d8\u4e3a\u00a01\uff0c\u4ee5\u4f7f\u4e24\u5ea7\u5c9b\u8fde\u63a5\u8d77\u6765\uff0c\u53d8\u6210\u4e00\u5ea7\u5c9b\u3002

    \n\n

    \u8fd4\u56de\u5fc5\u987b\u7ffb\u8f6c\u7684\u00a00 \u7684\u6700\u5c0f\u6570\u76ee\u3002\uff08\u53ef\u4ee5\u4fdd\u8bc1\u7b54\u6848\u81f3\u5c11\u662f 1 \u3002\uff09

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aA = [[0,1],[1,0]]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aA = [[0,1,0],[0,0,0],[0,0,1]]\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aA = [[1,1,1,1,1],[1,0,0,0,1],[1,0,1,0,1],[1,0,0,0,1],[1,1,1,1,1]]\n\u8f93\u51fa\uff1a1
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= A.length == A[0].length <= 100
    • \n\t
    • A[i][j] == 0 \u6216 A[i][j] == 1
    • \n
    \n", "tags_en": ["Depth-first Search", "Breadth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int shortestBridge(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int shortestBridge(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def shortestBridge(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def shortestBridge(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint shortestBridge(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ShortestBridge(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar shortestBridge = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef shortest_bridge(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func shortestBridge(_ grid: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func shortestBridge(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def shortestBridge(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun shortestBridge(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn shortest_bridge(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function shortestBridge($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function shortestBridge(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (shortest-bridge grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0934](https://leetcode-cn.com/problems/shortest-bridge)", "[\u6700\u77ed\u7684\u6865](/solution/0900-0999/0934.Shortest%20Bridge/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0934](https://leetcode.com/problems/shortest-bridge)", "[Shortest Bridge](/solution/0900-0999/0934.Shortest%20Bridge/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`", "Medium", ""]}, {"question_id": "0969", "frontend_question_id": "0933", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-recent-calls", "url_en": "https://leetcode.com/problems/number-of-recent-calls", "relative_path_cn": "/solution/0900-0999/0933.Number%20of%20Recent%20Calls/README.md", "relative_path_en": "/solution/0900-0999/0933.Number%20of%20Recent%20Calls/README_EN.md", "title_cn": "\u6700\u8fd1\u7684\u8bf7\u6c42\u6b21\u6570", "title_en": "Number of Recent Calls", "question_title_slug": "number-of-recent-calls", "content_en": "

    You have a RecentCounter class which counts the number of recent requests within a certain time frame.

    \n\n

    Implement the RecentCounter class:

    \n\n
      \n\t
    • RecentCounter() Initializes the counter with zero recent requests.
    • \n\t
    • int ping(int t) Adds a new request at time t, where t represents some time in milliseconds, and returns the number of requests that has happened in the past 3000 milliseconds (including the new request). Specifically, return the number of requests that have happened in the inclusive range [t - 3000, t].
    • \n
    \n\n

    It is guaranteed that every call to ping uses a strictly larger value of t than the previous call.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["RecentCounter", "ping", "ping", "ping", "ping"]\n[[], [1], [100], [3001], [3002]]\nOutput\n[null, 1, 2, 3, 3]\n\nExplanation\nRecentCounter recentCounter = new RecentCounter();\nrecentCounter.ping(1);     // requests = [1], range is [-2999,1], return 1\nrecentCounter.ping(100);   // requests = [1, 100], range is [-2900,100], return 2\nrecentCounter.ping(3001);  // requests = [1, 100, 3001], range is [1,3001], return 3\nrecentCounter.ping(3002);  // requests = [1, 100, 3001, 3002], range is [2,3002], return 3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= t <= 109
    • \n\t
    • Each test case will call ping with strictly increasing values of t.
    • \n\t
    • At most 104 calls will be made to ping.
    • \n
    \n", "content_cn": "

    \u5199\u4e00\u4e2a\u00a0RecentCounter\u00a0\u7c7b\u6765\u8ba1\u7b97\u7279\u5b9a\u65f6\u95f4\u8303\u56f4\u5185\u6700\u8fd1\u7684\u8bf7\u6c42\u3002

    \n\n

    \u8bf7\u4f60\u5b9e\u73b0 RecentCounter \u7c7b\uff1a

    \n\n
      \n\t
    • RecentCounter() \u521d\u59cb\u5316\u8ba1\u6570\u5668\uff0c\u8bf7\u6c42\u6570\u4e3a 0 \u3002
    • \n\t
    • int ping(int t) \u5728\u65f6\u95f4 t \u6dfb\u52a0\u4e00\u4e2a\u65b0\u8bf7\u6c42\uff0c\u5176\u4e2d t \u8868\u793a\u4ee5\u6beb\u79d2\u4e3a\u5355\u4f4d\u7684\u67d0\u4e2a\u65f6\u95f4\uff0c\u5e76\u8fd4\u56de\u8fc7\u53bb 3000 \u6beb\u79d2\u5185\u53d1\u751f\u7684\u6240\u6709\u8bf7\u6c42\u6570\uff08\u5305\u62ec\u65b0\u8bf7\u6c42\uff09\u3002\u786e\u5207\u5730\u8bf4\uff0c\u8fd4\u56de\u5728 [t-3000, t] \u5185\u53d1\u751f\u7684\u8bf7\u6c42\u6570\u3002
    • \n
    \n\n

    \u4fdd\u8bc1 \u6bcf\u6b21\u5bf9 ping \u7684\u8c03\u7528\u90fd\u4f7f\u7528\u6bd4\u4e4b\u524d\u66f4\u5927\u7684 t \u503c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\n[\"RecentCounter\", \"ping\", \"ping\", \"ping\", \"ping\"]\n[[], [1], [100], [3001], [3002]]\n\u8f93\u51fa\uff1a\n[null, 1, 2, 3, 3]\n\n\u89e3\u91ca\uff1a\nRecentCounter recentCounter = new RecentCounter();\nrecentCounter.ping(1);     // requests = [1]\uff0c\u8303\u56f4\u662f [-2999,1]\uff0c\u8fd4\u56de 1\nrecentCounter.ping(100);   // requests = [1, 100]\uff0c\u8303\u56f4\u662f [-2900,100]\uff0c\u8fd4\u56de 2\nrecentCounter.ping(3001);  // requests = [1, 100, 3001]\uff0c\u8303\u56f4\u662f [1,3001]\uff0c\u8fd4\u56de 3\nrecentCounter.ping(3002);  // requests = [1, 100, 3001, 3002]\uff0c\u8303\u56f4\u662f [2,3002]\uff0c\u8fd4\u56de 3\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= t <= 109
    • \n\t
    • \u4fdd\u8bc1\u6bcf\u6b21\u5bf9 ping \u8c03\u7528\u6240\u4f7f\u7528\u7684 t \u503c\u90fd \u4e25\u683c\u9012\u589e
    • \n\t
    • \u81f3\u591a\u8c03\u7528 ping \u65b9\u6cd5 104 \u6b21
    • \n
    \n", "tags_en": ["Queue"], "tags_cn": ["\u961f\u5217"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class RecentCounter {\npublic:\n RecentCounter() {\n\n }\n \n int ping(int t) {\n\n }\n};\n\n/**\n * Your RecentCounter object will be instantiated and called as such:\n * RecentCounter* obj = new RecentCounter();\n * int param_1 = obj->ping(t);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class RecentCounter {\n\n public RecentCounter() {\n\n }\n \n public int ping(int t) {\n\n }\n}\n\n/**\n * Your RecentCounter object will be instantiated and called as such:\n * RecentCounter obj = new RecentCounter();\n * int param_1 = obj.ping(t);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class RecentCounter(object):\n\n def __init__(self):\n\n\n def ping(self, t):\n \"\"\"\n :type t: int\n :rtype: int\n \"\"\"\n\n\n\n# Your RecentCounter object will be instantiated and called as such:\n# obj = RecentCounter()\n# param_1 = obj.ping(t)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class RecentCounter:\n\n def __init__(self):\n\n\n def ping(self, t: int) -> int:\n\n\n\n# Your RecentCounter object will be instantiated and called as such:\n# obj = RecentCounter()\n# param_1 = obj.ping(t)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} RecentCounter;\n\n\nRecentCounter* recentCounterCreate() {\n\n}\n\nint recentCounterPing(RecentCounter* obj, int t) {\n\n}\n\nvoid recentCounterFree(RecentCounter* obj) {\n\n}\n\n/**\n * Your RecentCounter struct will be instantiated and called as such:\n * RecentCounter* obj = recentCounterCreate();\n * int param_1 = recentCounterPing(obj, t);\n \n * recentCounterFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class RecentCounter {\n\n public RecentCounter() {\n\n }\n \n public int Ping(int t) {\n\n }\n}\n\n/**\n * Your RecentCounter object will be instantiated and called as such:\n * RecentCounter obj = new RecentCounter();\n * int param_1 = obj.Ping(t);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "\nvar RecentCounter = function() {\n\n};\n\n/** \n * @param {number} t\n * @return {number}\n */\nRecentCounter.prototype.ping = function(t) {\n\n};\n\n/**\n * Your RecentCounter object will be instantiated and called as such:\n * var obj = new RecentCounter()\n * var param_1 = obj.ping(t)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class RecentCounter\n def initialize()\n\n end\n\n\n=begin\n :type t: Integer\n :rtype: Integer\n=end\n def ping(t)\n\n end\n\n\nend\n\n# Your RecentCounter object will be instantiated and called as such:\n# obj = RecentCounter.new()\n# param_1 = obj.ping(t)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass RecentCounter {\n\n init() {\n \n }\n \n func ping(_ t: Int) -> Int {\n \n }\n}\n\n/**\n * Your RecentCounter object will be instantiated and called as such:\n * let obj = RecentCounter()\n * let ret_1: Int = obj.ping(t)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type RecentCounter struct {\n\n}\n\n\nfunc Constructor() RecentCounter {\n\n}\n\n\nfunc (this *RecentCounter) Ping(t int) int {\n\n}\n\n\n/**\n * Your RecentCounter object will be instantiated and called as such:\n * obj := Constructor();\n * param_1 := obj.Ping(t);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class RecentCounter() {\n\n def ping(t: Int): Int = {\n\n }\n\n}\n\n/**\n * Your RecentCounter object will be instantiated and called as such:\n * var obj = new RecentCounter()\n * var param_1 = obj.ping(t)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class RecentCounter() {\n\n fun ping(t: Int): Int {\n\n }\n\n}\n\n/**\n * Your RecentCounter object will be instantiated and called as such:\n * var obj = RecentCounter()\n * var param_1 = obj.ping(t)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct RecentCounter {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl RecentCounter {\n\n fn new() -> Self {\n\n }\n \n fn ping(&self, t: i32) -> i32 {\n\n }\n}\n\n/**\n * Your RecentCounter object will be instantiated and called as such:\n * let obj = RecentCounter::new();\n * let ret_1: i32 = obj.ping(t);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class RecentCounter {\n /**\n */\n function __construct() {\n\n }\n\n /**\n * @param Integer $t\n * @return Integer\n */\n function ping($t) {\n\n }\n}\n\n/**\n * Your RecentCounter object will be instantiated and called as such:\n * $obj = RecentCounter();\n * $ret_1 = $obj->ping($t);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class RecentCounter {\n constructor() {\n\n }\n\n ping(t: number): number {\n\n }\n}\n\n/**\n * Your RecentCounter object will be instantiated and called as such:\n * var obj = new RecentCounter()\n * var param_1 = obj.ping(t)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define recent-counter%\n (class object%\n (super-new)\n (init-field)\n \n ; ping : exact-integer? -> exact-integer?\n (define/public (ping t)\n\n )))\n\n;; Your recent-counter% object will be instantiated and called as such:\n;; (define obj (new recent-counter%))\n;; (define param_1 (send obj ping t))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0933](https://leetcode-cn.com/problems/number-of-recent-calls)", "[\u6700\u8fd1\u7684\u8bf7\u6c42\u6b21\u6570](/solution/0900-0999/0933.Number%20of%20Recent%20Calls/README.md)", "`\u961f\u5217`", "\u7b80\u5355", ""], "md_table_row_en": ["[0933](https://leetcode.com/problems/number-of-recent-calls)", "[Number of Recent Calls](/solution/0900-0999/0933.Number%20of%20Recent%20Calls/README_EN.md)", "`Queue`", "Easy", ""]}, {"question_id": "0968", "frontend_question_id": "0932", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/beautiful-array", "url_en": "https://leetcode.com/problems/beautiful-array", "relative_path_cn": "/solution/0900-0999/0932.Beautiful%20Array/README.md", "relative_path_en": "/solution/0900-0999/0932.Beautiful%20Array/README_EN.md", "title_cn": "\u6f02\u4eae\u6570\u7ec4", "title_en": "Beautiful Array", "question_title_slug": "beautiful-array", "content_en": "

    For some fixed n, an array nums is beautiful if it is a permutation of the integers 1, 2, ..., n, such that:

    \n\n

    For every i < j, there is no k with i < k < j such that nums[k] * 2 = nums[i] + nums[j].

    \n\n

    Given n, return any beautiful array nums.  (It is guaranteed that one exists.)

    \n\n

     

    \n\n

    Example 1:

    \n\n
    \nInput: n = 4\nOutput: [2,1,4,3]\n
    \n\n
    \n

    Example 2:

    \n\n
    \nInput: n = 5\nOutput: [3,1,2,5,4]
    \n\n

     

    \n
    \n\n

    Note:

    \n\n
      \n\t
    • 1 <= n <= 1000
    • \n
    \n\n
    \n
     
    \n
    \n", "content_cn": "

    \u5bf9\u4e8e\u67d0\u4e9b\u56fa\u5b9a\u7684 N\uff0c\u5982\u679c\u6570\u7ec4 A \u662f\u6574\u6570 1, 2, ..., N \u7ec4\u6210\u7684\u6392\u5217\uff0c\u4f7f\u5f97\uff1a

    \n\n

    \u5bf9\u4e8e\u6bcf\u4e2a i < j\uff0c\u90fd\u4e0d\u5b58\u5728 k \u6ee1\u8db3 i < k < j \u4f7f\u5f97 A[k] * 2 = A[i] + A[j]\u3002

    \n\n

    \u90a3\u4e48\u6570\u7ec4 A \u662f\u6f02\u4eae\u6570\u7ec4\u3002

    \n\n

     

    \n\n

    \u7ed9\u5b9a N\uff0c\u8fd4\u56de\u4efb\u610f\u6f02\u4eae\u6570\u7ec4 A\uff08\u4fdd\u8bc1\u5b58\u5728\u4e00\u4e2a\uff09\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a4\n\u8f93\u51fa\uff1a[2,1,4,3]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a5\n\u8f93\u51fa\uff1a[3,1,2,5,4]
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= N <= 1000
    • \n
    \n\n

     

    \n", "tags_en": ["Divide and Conquer"], "tags_cn": ["\u5206\u6cbb\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector beautifulArray(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] beautifulArray(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def beautifulArray(self, n):\n \"\"\"\n :type n: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def beautifulArray(self, n: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* beautifulArray(int n, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] BeautifulArray(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number[]}\n */\nvar beautifulArray = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer[]}\ndef beautiful_array(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func beautifulArray(_ n: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func beautifulArray(n int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def beautifulArray(n: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun beautifulArray(n: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn beautiful_array(n: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer[]\n */\n function beautifulArray($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function beautifulArray(n: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (beautiful-array n)\n (-> exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0932](https://leetcode-cn.com/problems/beautiful-array)", "[\u6f02\u4eae\u6570\u7ec4](/solution/0900-0999/0932.Beautiful%20Array/README.md)", "`\u5206\u6cbb\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0932](https://leetcode.com/problems/beautiful-array)", "[Beautiful Array](/solution/0900-0999/0932.Beautiful%20Array/README_EN.md)", "`Divide and Conquer`", "Medium", ""]}, {"question_id": "0967", "frontend_question_id": "0931", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-falling-path-sum", "url_en": "https://leetcode.com/problems/minimum-falling-path-sum", "relative_path_cn": "/solution/0900-0999/0931.Minimum%20Falling%20Path%20Sum/README.md", "relative_path_en": "/solution/0900-0999/0931.Minimum%20Falling%20Path%20Sum/README_EN.md", "title_cn": "\u4e0b\u964d\u8def\u5f84\u6700\u5c0f\u548c", "title_en": "Minimum Falling Path Sum", "question_title_slug": "minimum-falling-path-sum", "content_en": "

    Given an n x n array of integers matrix, return the minimum sum of any falling path through matrix.

    \n\n

    A falling path starts at any element in the first row and chooses the element in the next row that is either directly below or diagonally left/right. Specifically, the next element from position (row, col) will be (row + 1, col - 1), (row + 1, col), or (row + 1, col + 1).

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: matrix = [[2,1,3],[6,5,4],[7,8,9]]\nOutput: 13\nExplanation: There are two falling paths with a minimum sum underlined below:\n[[2,1,3],      [[2,1,3],\n [6,5,4],       [6,5,4],\n [7,8,9]]       [7,8,9]]\n
    \n\n

    Example 2:

    \n\n
    \nInput: matrix = [[-19,57],[-40,-5]]\nOutput: -59\nExplanation: The falling path with a minimum sum is underlined below:\n[[-19,57],\n [-40,-5]]\n
    \n\n

    Example 3:

    \n\n
    \nInput: matrix = [[-48]]\nOutput: -48\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == matrix.length
    • \n\t
    • n == matrix[i].length
    • \n\t
    • 1 <= n <= 100
    • \n\t
    • -100 <= matrix[i][j] <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a n x n \u7684 \u65b9\u5f62 \u6574\u6570\u6570\u7ec4\u00a0matrix \uff0c\u8bf7\u4f60\u627e\u51fa\u5e76\u8fd4\u56de\u901a\u8fc7 matrix \u7684\u4e0b\u964d\u8def\u5f84 \u7684 \u6700\u5c0f\u548c \u3002

    \n\n

    \u4e0b\u964d\u8def\u5f84 \u53ef\u4ee5\u4ece\u7b2c\u4e00\u884c\u4e2d\u7684\u4efb\u4f55\u5143\u7d20\u5f00\u59cb\uff0c\u5e76\u4ece\u6bcf\u4e00\u884c\u4e2d\u9009\u62e9\u4e00\u4e2a\u5143\u7d20\u3002\u5728\u4e0b\u4e00\u884c\u9009\u62e9\u7684\u5143\u7d20\u548c\u5f53\u524d\u884c\u6240\u9009\u5143\u7d20\u6700\u591a\u76f8\u9694\u4e00\u5217\uff08\u5373\u4f4d\u4e8e\u6b63\u4e0b\u65b9\u6216\u8005\u6cbf\u5bf9\u89d2\u7ebf\u5411\u5de6\u6216\u8005\u5411\u53f3\u7684\u7b2c\u4e00\u4e2a\u5143\u7d20\uff09\u3002\u5177\u4f53\u6765\u8bf4\uff0c\u4f4d\u7f6e (row, col) \u7684\u4e0b\u4e00\u4e2a\u5143\u7d20\u5e94\u5f53\u662f (row + 1, col - 1)\u3001(row + 1, col) \u6216\u8005 (row + 1, col + 1) \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1amatrix = [[2,1,3],[6,5,4],[7,8,9]]\n\u8f93\u51fa\uff1a13\n\u89e3\u91ca\uff1a\u4e0b\u9762\u662f\u4e24\u6761\u548c\u6700\u5c0f\u7684\u4e0b\u964d\u8def\u5f84\uff0c\u7528\u52a0\u7c97\u6807\u6ce8\uff1a\n[[2,1,3],      [[2,1,3],\n [6,5,4],       [6,5,4],\n [7,8,9]]       [7,8,9]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1amatrix = [[-19,57],[-40,-5]]\n\u8f93\u51fa\uff1a-59\n\u89e3\u91ca\uff1a\u4e0b\u9762\u662f\u4e00\u6761\u548c\u6700\u5c0f\u7684\u4e0b\u964d\u8def\u5f84\uff0c\u7528\u52a0\u7c97\u6807\u6ce8\uff1a\n[[-19,57],\n [-40,-5]]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1amatrix = [[-48]]\n\u8f93\u51fa\uff1a-48\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == matrix.length
    • \n\t
    • n == matrix[i].length
    • \n\t
    • 1 <= n <= 100
    • \n\t
    • -100 <= matrix[i][j] <= 100
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minFallingPathSum(vector>& matrix) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minFallingPathSum(int[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minFallingPathSum(self, matrix):\n \"\"\"\n :type matrix: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minFallingPathSum(self, matrix: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minFallingPathSum(int** matrix, int matrixSize, int* matrixColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinFallingPathSum(int[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} matrix\n * @return {number}\n */\nvar minFallingPathSum = function(matrix) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} matrix\n# @return {Integer}\ndef min_falling_path_sum(matrix)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minFallingPathSum(_ matrix: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minFallingPathSum(matrix [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minFallingPathSum(matrix: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minFallingPathSum(matrix: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_falling_path_sum(matrix: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $matrix\n * @return Integer\n */\n function minFallingPathSum($matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minFallingPathSum(matrix: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-falling-path-sum matrix)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0931](https://leetcode-cn.com/problems/minimum-falling-path-sum)", "[\u4e0b\u964d\u8def\u5f84\u6700\u5c0f\u548c](/solution/0900-0999/0931.Minimum%20Falling%20Path%20Sum/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0931](https://leetcode.com/problems/minimum-falling-path-sum)", "[Minimum Falling Path Sum](/solution/0900-0999/0931.Minimum%20Falling%20Path%20Sum/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0966", "frontend_question_id": "0930", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/binary-subarrays-with-sum", "url_en": "https://leetcode.com/problems/binary-subarrays-with-sum", "relative_path_cn": "/solution/0900-0999/0930.Binary%20Subarrays%20With%20Sum/README.md", "relative_path_en": "/solution/0900-0999/0930.Binary%20Subarrays%20With%20Sum/README_EN.md", "title_cn": "\u548c\u76f8\u540c\u7684\u4e8c\u5143\u5b50\u6570\u7ec4", "title_en": "Binary Subarrays With Sum", "question_title_slug": "binary-subarrays-with-sum", "content_en": "

    Given a binary array nums and an integer goal, return the number of non-empty subarrays with a sum goal.

    \n\n

    A subarray is a contiguous part of the array.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,0,1,0,1], goal = 2\nOutput: 4\nExplanation: The 4 subarrays are bolded and underlined below:\n[1,0,1,0,1]\n[1,0,1,0,1]\n[1,0,1,0,1]\n[1,0,1,0,1]\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [0,0,0,0,0], goal = 0\nOutput: 15\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 3 * 104
    • \n\t
    • nums[i] is either 0 or 1.
    • \n\t
    • 0 <= goal <= nums.length
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u4e8c\u5143\u6570\u7ec4 nums \uff0c\u548c\u4e00\u4e2a\u6574\u6570 goal \uff0c\u8bf7\u4f60\u7edf\u8ba1\u5e76\u6709\u591a\u5c11\u4e2a\u548c\u4e3a goal \u7684 \u975e\u7a7a \u5b50\u6570\u7ec4\u3002

    \n\n

    \u5b50\u6570\u7ec4 \u662f\u6570\u7ec4\u7684\u4e00\u6bb5\u8fde\u7eed\u90e8\u5206\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,0,1,0,1], goal = 2\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\n\u5982\u4e0b\u9762\u9ed1\u4f53\u6240\u793a\uff0c\u6709 4 \u4e2a\u6ee1\u8db3\u9898\u76ee\u8981\u6c42\u7684\u5b50\u6570\u7ec4\uff1a\n[1,0,1,0,1]\n[1,0,1,0,1]\n[1,0,1,0,1]\n[1,0,1,0,1]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [0,0,0,0,0], goal = 0\n\u8f93\u51fa\uff1a15\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 3 * 104
    • \n\t
    • nums[i] \u4e0d\u662f 0 \u5c31\u662f 1
    • \n\t
    • 0 <= goal <= nums.length
    • \n
    \n", "tags_en": ["Hash Table", "Two Pointers"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numSubarraysWithSum(vector& nums, int goal) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numSubarraysWithSum(int[] nums, int goal) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numSubarraysWithSum(self, nums, goal):\n \"\"\"\n :type nums: List[int]\n :type goal: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numSubarraysWithSum(self, nums: List[int], goal: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numSubarraysWithSum(int* nums, int numsSize, int goal){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumSubarraysWithSum(int[] nums, int goal) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} goal\n * @return {number}\n */\nvar numSubarraysWithSum = function(nums, goal) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} goal\n# @return {Integer}\ndef num_subarrays_with_sum(nums, goal)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numSubarraysWithSum(_ nums: [Int], _ goal: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numSubarraysWithSum(nums []int, goal int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numSubarraysWithSum(nums: Array[Int], goal: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numSubarraysWithSum(nums: IntArray, goal: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_subarrays_with_sum(nums: Vec, goal: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $goal\n * @return Integer\n */\n function numSubarraysWithSum($nums, $goal) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numSubarraysWithSum(nums: number[], goal: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-subarrays-with-sum nums goal)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0930](https://leetcode-cn.com/problems/binary-subarrays-with-sum)", "[\u548c\u76f8\u540c\u7684\u4e8c\u5143\u5b50\u6570\u7ec4](/solution/0900-0999/0930.Binary%20Subarrays%20With%20Sum/README.md)", "`\u54c8\u5e0c\u8868`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0930](https://leetcode.com/problems/binary-subarrays-with-sum)", "[Binary Subarrays With Sum](/solution/0900-0999/0930.Binary%20Subarrays%20With%20Sum/README_EN.md)", "`Hash Table`,`Two Pointers`", "Medium", ""]}, {"question_id": "0965", "frontend_question_id": "0929", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/unique-email-addresses", "url_en": "https://leetcode.com/problems/unique-email-addresses", "relative_path_cn": "/solution/0900-0999/0929.Unique%20Email%20Addresses/README.md", "relative_path_en": "/solution/0900-0999/0929.Unique%20Email%20Addresses/README_EN.md", "title_cn": "\u72ec\u7279\u7684\u7535\u5b50\u90ae\u4ef6\u5730\u5740", "title_en": "Unique Email Addresses", "question_title_slug": "unique-email-addresses", "content_en": "

    Every valid email consists of a local name and a domain name, separated by the '@' sign. Besides lowercase letters, the email may contain one or more '.' or '+'.

    \n\n
      \n\t
    • For example, in "alice@leetcode.com", "alice" is the local name, and "leetcode.com" is the domain name.
    • \n
    \n\n

    If you add periods '.' between some characters in the local name part of an email address, mail sent there will be forwarded to the same address without dots in the local name. Note that this rule does not apply to domain names.

    \n\n
      \n\t
    • For example, "alice.z@leetcode.com" and "alicez@leetcode.com" forward to the same email address.
    • \n
    \n\n

    If you add a plus '+' in the local name, everything after the first plus sign will be ignored. This allows certain emails to be filtered. Note that this rule does not apply to domain names.

    \n\n
      \n\t
    • For example, "m.y+name@email.com" will be forwarded to "my@email.com".
    • \n
    \n\n

    It is possible to use both of these rules at the same time.

    \n\n

    Given an array of strings emails where we send one email to each email[i], return the number of different addresses that actually receive mails.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: emails = ["test.email+alex@leetcode.com","test.e.mail+bob.cathy@leetcode.com","testemail+david@lee.tcode.com"]\nOutput: 2\nExplanation: "testemail@leetcode.com" and "testemail@lee.tcode.com" actually receive mails.\n
    \n\n

    Example 2:

    \n\n
    \nInput: emails = ["a@leetcode.com","b@leetcode.com","c@leetcode.com"]\nOutput: 3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= emails.length <= 100
    • \n\t
    • 1 <= emails[i].length <= 100
    • \n\t
    • email[i] consist of lowercase English letters, '+', '.' and '@'.
    • \n\t
    • Each emails[i] contains exactly one '@' character.
    • \n\t
    • All local and domain names are non-empty.
    • \n\t
    • Local names do not start with a '+' character.
    • \n
    \n", "content_cn": "

    \u6bcf\u5c01\u7535\u5b50\u90ae\u4ef6\u90fd\u7531\u4e00\u4e2a\u672c\u5730\u540d\u79f0\u548c\u4e00\u4e2a\u57df\u540d\u7ec4\u6210\uff0c\u4ee5 @ \u7b26\u53f7\u5206\u9694\u3002

    \n\n

    \u4f8b\u5982\uff0c\u5728 alice@leetcode.com\u4e2d\uff0c alice \u662f\u672c\u5730\u540d\u79f0\uff0c\u800c leetcode.com \u662f\u57df\u540d\u3002

    \n\n

    \u9664\u4e86\u5c0f\u5199\u5b57\u6bcd\uff0c\u8fd9\u4e9b\u7535\u5b50\u90ae\u4ef6\u8fd8\u53ef\u80fd\u5305\u542b '.' \u6216 '+'\u3002

    \n\n

    \u5982\u679c\u5728\u7535\u5b50\u90ae\u4ef6\u5730\u5740\u7684\u672c\u5730\u540d\u79f0\u90e8\u5206\u4e2d\u7684\u67d0\u4e9b\u5b57\u7b26\u4e4b\u95f4\u6dfb\u52a0\u53e5\u70b9\uff08'.'\uff09\uff0c\u5219\u53d1\u5f80\u90a3\u91cc\u7684\u90ae\u4ef6\u5c06\u4f1a\u8f6c\u53d1\u5230\u672c\u5730\u540d\u79f0\u4e2d\u6ca1\u6709\u70b9\u7684\u540c\u4e00\u5730\u5740\u3002\u4f8b\u5982\uff0c"alice.z@leetcode.com” \u548c “alicez@leetcode.com” \u4f1a\u8f6c\u53d1\u5230\u540c\u4e00\u7535\u5b50\u90ae\u4ef6\u5730\u5740\u3002 \uff08\u8bf7\u6ce8\u610f\uff0c\u6b64\u89c4\u5219\u4e0d\u9002\u7528\u4e8e\u57df\u540d\u3002\uff09

    \n\n

    \u5982\u679c\u5728\u672c\u5730\u540d\u79f0\u4e2d\u6dfb\u52a0\u52a0\u53f7\uff08'+'\uff09\uff0c\u5219\u4f1a\u5ffd\u7565\u7b2c\u4e00\u4e2a\u52a0\u53f7\u540e\u9762\u7684\u6240\u6709\u5185\u5bb9\u3002\u8fd9\u5141\u8bb8\u8fc7\u6ee4\u67d0\u4e9b\u7535\u5b50\u90ae\u4ef6\uff0c\u4f8b\u5982 m.y+name@email.com \u5c06\u8f6c\u53d1\u5230 my@email.com\u3002 \uff08\u540c\u6837\uff0c\u6b64\u89c4\u5219\u4e0d\u9002\u7528\u4e8e\u57df\u540d\u3002\uff09

    \n\n

    \u53ef\u4ee5\u540c\u65f6\u4f7f\u7528\u8fd9\u4e24\u4e2a\u89c4\u5219\u3002

    \n\n

    \u7ed9\u5b9a\u7535\u5b50\u90ae\u4ef6\u5217\u8868 emails\uff0c\u6211\u4eec\u4f1a\u5411\u5217\u8868\u4e2d\u7684\u6bcf\u4e2a\u5730\u5740\u53d1\u9001\u4e00\u5c01\u7535\u5b50\u90ae\u4ef6\u3002\u5b9e\u9645\u6536\u5230\u90ae\u4ef6\u7684\u4e0d\u540c\u5730\u5740\u6709\u591a\u5c11\uff1f

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1a["test.email+alex@leetcode.com","test.e.mail+bob.cathy@leetcode.com","testemail+david@lee.tcode.com"]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5b9e\u9645\u6536\u5230\u90ae\u4ef6\u7684\u662f "testemail@leetcode.com" \u548c "testemail@lee.tcode.com"\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= emails[i].length <= 100
    • \n\t
    • 1 <= emails.length <= 100
    • \n\t
    • \u6bcf\u5c01 emails[i] \u90fd\u5305\u542b\u6709\u4e14\u4ec5\u6709\u4e00\u4e2a '@' \u5b57\u7b26\u3002
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numUniqueEmails(vector& emails) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numUniqueEmails(String[] emails) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numUniqueEmails(self, emails):\n \"\"\"\n :type emails: List[str]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numUniqueEmails(self, emails: List[str]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numUniqueEmails(char ** emails, int emailsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumUniqueEmails(string[] emails) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} emails\n * @return {number}\n */\nvar numUniqueEmails = function(emails) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} emails\n# @return {Integer}\ndef num_unique_emails(emails)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numUniqueEmails(_ emails: [String]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numUniqueEmails(emails []string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numUniqueEmails(emails: Array[String]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numUniqueEmails(emails: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_unique_emails(emails: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $emails\n * @return Integer\n */\n function numUniqueEmails($emails) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numUniqueEmails(emails: string[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-unique-emails emails)\n (-> (listof string?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0929](https://leetcode-cn.com/problems/unique-email-addresses)", "[\u72ec\u7279\u7684\u7535\u5b50\u90ae\u4ef6\u5730\u5740](/solution/0900-0999/0929.Unique%20Email%20Addresses/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0929](https://leetcode.com/problems/unique-email-addresses)", "[Unique Email Addresses](/solution/0900-0999/0929.Unique%20Email%20Addresses/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "0964", "frontend_question_id": "0928", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimize-malware-spread-ii", "url_en": "https://leetcode.com/problems/minimize-malware-spread-ii", "relative_path_cn": "/solution/0900-0999/0928.Minimize%20Malware%20Spread%20II/README.md", "relative_path_en": "/solution/0900-0999/0928.Minimize%20Malware%20Spread%20II/README_EN.md", "title_cn": "\u5c3d\u91cf\u51cf\u5c11\u6076\u610f\u8f6f\u4ef6\u7684\u4f20\u64ad II", "title_en": "Minimize Malware Spread II", "question_title_slug": "minimize-malware-spread-ii", "content_en": "

    You are given a network of n nodes represented as an n x n adjacency matrix graph, where the ith node is directly connected to the jth node if graph[i][j] == 1.

    \n\n

    Some nodes initial are initially infected by malware. Whenever two nodes are directly connected, and at least one of those two nodes is infected by malware, both nodes will be infected by malware. This spread of malware will continue until no more nodes can be infected in this manner.

    \n\n

    Suppose M(initial) is the final number of nodes infected with malware in the entire network after the spread of malware stops.

    \n\n

    We will remove exactly one node from initial, completely removing it and any connections from this node to any other node.

    \n\n

    Return the node that, if removed, would minimize M(initial). If multiple nodes could be removed to minimize M(initial), return such a node with the smallest index.

    \n\n

     

    \n

    Example 1:

    \n
    Input: graph = [[1,1,0],[1,1,0],[0,0,1]], initial = [0,1]\nOutput: 0\n

    Example 2:

    \n
    Input: graph = [[1,1,0],[1,1,1],[0,1,1]], initial = [0,1]\nOutput: 1\n

    Example 3:

    \n
    Input: graph = [[1,1,0,0],[1,1,1,0],[0,1,1,1],[0,0,1,1]], initial = [0,1]\nOutput: 1\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == graph.length
    • \n\t
    • n == graph[i].length
    • \n\t
    • 2 <= n <= 300
    • \n\t
    • graph[i][j] is 0 or 1.
    • \n\t
    • graph[i][j] == graph[j][i]
    • \n\t
    • graph[i][i] == 1
    • \n\t
    • 1 <= initial.length < n
    • \n\t
    • 0 <= initial[i] <= n - 1
    • \n\t
    • All the integers in initial are unique.
    • \n
    \n", "content_cn": "

    (\u8fd9\u4e2a\u95ee\u9898\u4e0e \u5c3d\u91cf\u51cf\u5c11\u6076\u610f\u8f6f\u4ef6\u7684\u4f20\u64ad \u662f\u4e00\u6837\u7684\uff0c\u4e0d\u540c\u4e4b\u5904\u7528\u7c97\u4f53\u8868\u793a\u3002)

    \n\n

    \u5728\u8282\u70b9\u7f51\u7edc\u4e2d\uff0c\u53ea\u6709\u5f53 graph[i][j] = 1 \u65f6\uff0c\u6bcf\u4e2a\u8282\u70b9 i \u80fd\u591f\u76f4\u63a5\u8fde\u63a5\u5230\u53e6\u4e00\u4e2a\u8282\u70b9 j\u3002

    \n\n

    \u4e00\u4e9b\u8282\u70b9 initial \u6700\u521d\u88ab\u6076\u610f\u8f6f\u4ef6\u611f\u67d3\u3002\u53ea\u8981\u4e24\u4e2a\u8282\u70b9\u76f4\u63a5\u8fde\u63a5\uff0c\u4e14\u5176\u4e2d\u81f3\u5c11\u4e00\u4e2a\u8282\u70b9\u53d7\u5230\u6076\u610f\u8f6f\u4ef6\u7684\u611f\u67d3\uff0c\u90a3\u4e48\u4e24\u4e2a\u8282\u70b9\u90fd\u5c06\u88ab\u6076\u610f\u8f6f\u4ef6\u611f\u67d3\u3002\u8fd9\u79cd\u6076\u610f\u8f6f\u4ef6\u7684\u4f20\u64ad\u5c06\u7ee7\u7eed\uff0c\u76f4\u5230\u6ca1\u6709\u66f4\u591a\u7684\u8282\u70b9\u53ef\u4ee5\u88ab\u8fd9\u79cd\u65b9\u5f0f\u611f\u67d3\u3002

    \n\n

    \u5047\u8bbe M(initial) \u662f\u5728\u6076\u610f\u8f6f\u4ef6\u505c\u6b62\u4f20\u64ad\u4e4b\u540e\uff0c\u6574\u4e2a\u7f51\u7edc\u4e2d\u611f\u67d3\u6076\u610f\u8f6f\u4ef6\u7684\u6700\u7ec8\u8282\u70b9\u6570\u3002

    \n\n

    \u6211\u4eec\u53ef\u4ee5\u4ece\u521d\u59cb\u5217\u8868\u4e2d\u5220\u9664\u4e00\u4e2a\u8282\u70b9\uff0c\u5e76\u5b8c\u5168\u79fb\u9664\u8be5\u8282\u70b9\u4ee5\u53ca\u4ece\u8be5\u8282\u70b9\u5230\u4efb\u4f55\u5176\u4ed6\u8282\u70b9\u7684\u4efb\u4f55\u8fde\u63a5\u3002\u5982\u679c\u79fb\u9664\u8fd9\u4e00\u8282\u70b9\u5c06\u6700\u5c0f\u5316 M(initial)\uff0c \u5219\u8fd4\u56de\u8be5\u8282\u70b9\u3002\u5982\u679c\u6709\u591a\u4e2a\u8282\u70b9\u6ee1\u8db3\u6761\u4ef6\uff0c\u5c31\u8fd4\u56de\u7d22\u5f15\u6700\u5c0f\u7684\u8282\u70b9\u3002

    \n\n

     

    \n\n
      \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u51fa\uff1agraph = [[1,1,0],[1,1,0],[0,0,1]], initial = [0,1]\n\u8f93\u5165\uff1a0\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1agraph = [[1,1,0],[1,1,1],[0,1,1]], initial = [0,1]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1agraph = [[1,1,0,0],[1,1,1,0],[0,1,1,1],[0,0,1,1]], initial = [0,1]\n\u8f93\u51fa\uff1a1\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 < graph.length = graph[0].length <= 300
    2. \n\t
    3. 0 <= graph[i][j] == graph[j][i] <= 1
    4. \n\t
    5. graph[i][i] = 1
    6. \n\t
    7. 1 <= initial.length < graph.length
    8. \n\t
    9. 0 <= initial[i] < graph.length
    10. \n
    \n", "tags_en": ["Depth-first Search", "Union Find", "Graph"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e76\u67e5\u96c6", "\u56fe"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minMalwareSpread(vector>& graph, vector& initial) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minMalwareSpread(int[][] graph, int[] initial) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minMalwareSpread(self, graph, initial):\n \"\"\"\n :type graph: List[List[int]]\n :type initial: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minMalwareSpread(self, graph: List[List[int]], initial: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minMalwareSpread(int** graph, int graphSize, int* graphColSize, int* initial, int initialSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinMalwareSpread(int[][] graph, int[] initial) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} graph\n * @param {number[]} initial\n * @return {number}\n */\nvar minMalwareSpread = function(graph, initial) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} graph\n# @param {Integer[]} initial\n# @return {Integer}\ndef min_malware_spread(graph, initial)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minMalwareSpread(_ graph: [[Int]], _ initial: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minMalwareSpread(graph [][]int, initial []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minMalwareSpread(graph: Array[Array[Int]], initial: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minMalwareSpread(graph: Array, initial: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_malware_spread(graph: Vec>, initial: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $graph\n * @param Integer[] $initial\n * @return Integer\n */\n function minMalwareSpread($graph, $initial) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minMalwareSpread(graph: number[][], initial: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-malware-spread graph initial)\n (-> (listof (listof exact-integer?)) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0928](https://leetcode-cn.com/problems/minimize-malware-spread-ii)", "[\u5c3d\u91cf\u51cf\u5c11\u6076\u610f\u8f6f\u4ef6\u7684\u4f20\u64ad II](/solution/0900-0999/0928.Minimize%20Malware%20Spread%20II/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e76\u67e5\u96c6`,`\u56fe`", "\u56f0\u96be", ""], "md_table_row_en": ["[0928](https://leetcode.com/problems/minimize-malware-spread-ii)", "[Minimize Malware Spread II](/solution/0900-0999/0928.Minimize%20Malware%20Spread%20II/README_EN.md)", "`Depth-first Search`,`Union Find`,`Graph`", "Hard", ""]}, {"question_id": "0963", "frontend_question_id": "0927", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/three-equal-parts", "url_en": "https://leetcode.com/problems/three-equal-parts", "relative_path_cn": "/solution/0900-0999/0927.Three%20Equal%20Parts/README.md", "relative_path_en": "/solution/0900-0999/0927.Three%20Equal%20Parts/README_EN.md", "title_cn": "\u4e09\u7b49\u5206", "title_en": "Three Equal Parts", "question_title_slug": "three-equal-parts", "content_en": "

    You are given an array arr which consists of only zeros and ones, divide the array into three non-empty parts such that all of these parts represent the same binary value.

    \n\n

    If it is possible, return any [i, j] with i + 1 < j, such that:

    \n\n
      \n\t
    • arr[0], arr[1], ..., arr[i] is the first part,
    • \n\t
    • arr[i + 1], arr[i + 2], ..., arr[j - 1] is the second part, and
    • \n\t
    • arr[j], arr[j + 1], ..., arr[arr.length - 1] is the third part.
    • \n\t
    • All three parts have equal binary values.
    • \n
    \n\n

    If it is not possible, return [-1, -1].

    \n\n

    Note that the entire part is used when considering what binary value it represents. For example, [1,1,0] represents 6 in decimal, not 3. Also, leading zeros are allowed, so [0,1,1] and [1,1] represent the same value.

    \n\n

     

    \n

    Example 1:

    \n
    Input: arr = [1,0,1,0,1]\nOutput: [0,3]\n

    Example 2:

    \n
    Input: arr = [1,1,0,1,1]\nOutput: [-1,-1]\n

    Example 3:

    \n
    Input: arr = [1,1,0,0,1]\nOutput: [0,2]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 3 <= arr.length <= 3 * 104
    • \n\t
    • arr[i] is 0 or 1
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u7531 0 \u548c 1 \u7ec4\u6210\u7684\u6570\u7ec4 A\uff0c\u5c06\u6570\u7ec4\u5206\u6210 3 \u4e2a\u975e\u7a7a\u7684\u90e8\u5206\uff0c\u4f7f\u5f97\u6240\u6709\u8fd9\u4e9b\u90e8\u5206\u8868\u793a\u76f8\u540c\u7684\u4e8c\u8fdb\u5236\u503c\u3002

    \n\n

    \u5982\u679c\u53ef\u4ee5\u505a\u5230\uff0c\u8bf7\u8fd4\u56de\u4efb\u4f55 [i, j]\uff0c\u5176\u4e2d i+1 < j\uff0c\u8fd9\u6837\u4e00\u6765\uff1a

    \n\n
      \n\t
    • A[0], A[1], ..., A[i] \u7ec4\u6210\u7b2c\u4e00\u90e8\u5206\uff1b
    • \n\t
    • A[i+1], A[i+2], ..., A[j-1] \u4f5c\u4e3a\u7b2c\u4e8c\u90e8\u5206\uff1b
    • \n\t
    • A[j], A[j+1], ..., A[A.length - 1] \u662f\u7b2c\u4e09\u90e8\u5206\u3002
    • \n\t
    • \u8fd9\u4e09\u4e2a\u90e8\u5206\u6240\u8868\u793a\u7684\u4e8c\u8fdb\u5236\u503c\u76f8\u7b49\u3002
    • \n
    \n\n

    \u5982\u679c\u65e0\u6cd5\u505a\u5230\uff0c\u5c31\u8fd4\u56de [-1, -1]\u3002

    \n\n

    \u6ce8\u610f\uff0c\u5728\u8003\u8651\u6bcf\u4e2a\u90e8\u5206\u6240\u8868\u793a\u7684\u4e8c\u8fdb\u5236\u65f6\uff0c\u5e94\u5f53\u5c06\u5176\u770b\u4f5c\u4e00\u4e2a\u6574\u4f53\u3002\u4f8b\u5982\uff0c[1,1,0] \u8868\u793a\u5341\u8fdb\u5236\u4e2d\u7684 6\uff0c\u800c\u4e0d\u4f1a\u662f 3\u3002\u6b64\u5916\uff0c\u524d\u5bfc\u96f6\u4e5f\u662f\u88ab\u5141\u8bb8\u7684\uff0c\u6240\u4ee5 [0,1,1] \u548c [1,1] \u8868\u793a\u76f8\u540c\u7684\u503c\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a[1,0,1,0,1]\n\u8f93\u51fa\uff1a[0,3]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u51fa\uff1a[1,1,0,1,1]\n\u8f93\u51fa\uff1a[-1,-1]
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 3 <= A.length <= 30000
    2. \n\t
    3. A[i] == 0 \u6216 A[i] == 1
    4. \n
    \n\n

     

    \n", "tags_en": ["Greedy", "Math", "Binary Search"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u5b66", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector threeEqualParts(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] threeEqualParts(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def threeEqualParts(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def threeEqualParts(self, arr: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* threeEqualParts(int* arr, int arrSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] ThreeEqualParts(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number[]}\n */\nvar threeEqualParts = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer[]}\ndef three_equal_parts(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func threeEqualParts(_ arr: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func threeEqualParts(arr []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def threeEqualParts(arr: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun threeEqualParts(arr: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn three_equal_parts(arr: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer[]\n */\n function threeEqualParts($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function threeEqualParts(arr: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (three-equal-parts arr)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0927](https://leetcode-cn.com/problems/three-equal-parts)", "[\u4e09\u7b49\u5206](/solution/0900-0999/0927.Three%20Equal%20Parts/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u5b66`,`\u4e8c\u5206\u67e5\u627e`", "\u56f0\u96be", ""], "md_table_row_en": ["[0927](https://leetcode.com/problems/three-equal-parts)", "[Three Equal Parts](/solution/0900-0999/0927.Three%20Equal%20Parts/README_EN.md)", "`Greedy`,`Math`,`Binary Search`", "Hard", ""]}, {"question_id": "0962", "frontend_question_id": "0926", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/flip-string-to-monotone-increasing", "url_en": "https://leetcode.com/problems/flip-string-to-monotone-increasing", "relative_path_cn": "/solution/0900-0999/0926.Flip%20String%20to%20Monotone%20Increasing/README.md", "relative_path_en": "/solution/0900-0999/0926.Flip%20String%20to%20Monotone%20Increasing/README_EN.md", "title_cn": "\u5c06\u5b57\u7b26\u4e32\u7ffb\u8f6c\u5230\u5355\u8c03\u9012\u589e", "title_en": "Flip String to Monotone Increasing", "question_title_slug": "flip-string-to-monotone-increasing", "content_en": "

    A string of '0's and '1's is monotone increasing if it consists of some number of '0's (possibly 0), followed by some number of '1's (also possibly 0.)

    \n\n

    We are given a string s of '0's and '1's, and we may flip any '0' to a '1' or a '1' to a '0'.

    \n\n

    Return the minimum number of flips to make s monotone increasing.

    \n\n

     

    \n\n
    \n

    Example 1:

    \n\n
    \nInput: s = "00110"\nOutput: 1\nExplanation: We flip the last digit to get 00111.\n
    \n\n
    \n

    Example 2:

    \n\n
    \nInput: s = "010110"\nOutput: 2\nExplanation: We flip to get 011111, or alternatively 000111.\n
    \n\n
    \n

    Example 3:

    \n\n
    \nInput: s = "00011000"\nOutput: 2\nExplanation: We flip to get 00000000.\n
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    1. 1 <= s.length <= 20000
    2. \n\t
    3. s only consists of '0' and '1' characters.
    4. \n
    \n
    \n
    \n
    \n", "content_cn": "

    \u5982\u679c\u4e00\u4e2a\u7531 '0' \u548c '1' \u7ec4\u6210\u7684\u5b57\u7b26\u4e32\uff0c\u662f\u4ee5\u4e00\u4e9b '0'\uff08\u53ef\u80fd\u6ca1\u6709 '0'\uff09\u540e\u9762\u8ddf\u7740\u4e00\u4e9b '1'\uff08\u4e5f\u53ef\u80fd\u6ca1\u6709 '1'\uff09\u7684\u5f62\u5f0f\u7ec4\u6210\u7684\uff0c\u90a3\u4e48\u8be5\u5b57\u7b26\u4e32\u662f\u5355\u8c03\u9012\u589e\u7684\u3002

    \n\n

    \u6211\u4eec\u7ed9\u51fa\u4e00\u4e2a\u7531\u5b57\u7b26 '0' \u548c '1' \u7ec4\u6210\u7684\u5b57\u7b26\u4e32 S\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u4efb\u4f55 '0' \u7ffb\u8f6c\u4e3a '1' \u6216\u8005\u5c06 '1' \u7ffb\u8f6c\u4e3a '0'\u3002

    \n\n

    \u8fd4\u56de\u4f7f S \u5355\u8c03\u9012\u589e\u7684\u6700\u5c0f\u7ffb\u8f6c\u6b21\u6570\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a"00110"\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u6211\u4eec\u7ffb\u8f6c\u6700\u540e\u4e00\u4f4d\u5f97\u5230 00111.\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a"010110"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6211\u4eec\u7ffb\u8f6c\u5f97\u5230 011111\uff0c\u6216\u8005\u662f 000111\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1a"00011000"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6211\u4eec\u7ffb\u8f6c\u5f97\u5230 00000000\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= S.length <= 20000
    2. \n\t
    3. S \u4e2d\u53ea\u5305\u542b\u5b57\u7b26 '0' \u548c '1'
    4. \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minFlipsMonoIncr(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minFlipsMonoIncr(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minFlipsMonoIncr(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minFlipsMonoIncr(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minFlipsMonoIncr(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinFlipsMonoIncr(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar minFlipsMonoIncr = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef min_flips_mono_incr(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minFlipsMonoIncr(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minFlipsMonoIncr(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minFlipsMonoIncr(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minFlipsMonoIncr(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_flips_mono_incr(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function minFlipsMonoIncr($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minFlipsMonoIncr(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-flips-mono-incr s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0926](https://leetcode-cn.com/problems/flip-string-to-monotone-increasing)", "[\u5c06\u5b57\u7b26\u4e32\u7ffb\u8f6c\u5230\u5355\u8c03\u9012\u589e](/solution/0900-0999/0926.Flip%20String%20to%20Monotone%20Increasing/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0926](https://leetcode.com/problems/flip-string-to-monotone-increasing)", "[Flip String to Monotone Increasing](/solution/0900-0999/0926.Flip%20String%20to%20Monotone%20Increasing/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0961", "frontend_question_id": "0925", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/long-pressed-name", "url_en": "https://leetcode.com/problems/long-pressed-name", "relative_path_cn": "/solution/0900-0999/0925.Long%20Pressed%20Name/README.md", "relative_path_en": "/solution/0900-0999/0925.Long%20Pressed%20Name/README_EN.md", "title_cn": "\u957f\u6309\u952e\u5165", "title_en": "Long Pressed Name", "question_title_slug": "long-pressed-name", "content_en": "

    Your friend is typing his name into a keyboard. Sometimes, when typing a character c, the key might get long pressed, and the character will be typed 1 or more times.

    \n\n

    You examine the typed characters of the keyboard. Return True if it is possible that it was your friends name, with some characters (possibly none) being long pressed.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: name = "alex", typed = "aaleex"\nOutput: true\nExplanation: 'a' and 'e' in 'alex' were long pressed.\n
    \n\n

    Example 2:

    \n\n
    \nInput: name = "saeed", typed = "ssaaedd"\nOutput: false\nExplanation: 'e' must have been pressed twice, but it wasn't in the typed output.\n
    \n\n

    Example 3:

    \n\n
    \nInput: name = "leelee", typed = "lleeelee"\nOutput: true\n
    \n\n

    Example 4:

    \n\n
    \nInput: name = "laiden", typed = "laiden"\nOutput: true\nExplanation: It's not necessary to long press any character.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= name.length <= 1000
    • \n\t
    • 1 <= typed.length <= 1000
    • \n\t
    • name and typed contain only lowercase English letters.
    • \n
    \n", "content_cn": "

    \u4f60\u7684\u670b\u53cb\u6b63\u5728\u4f7f\u7528\u952e\u76d8\u8f93\u5165\u4ed6\u7684\u540d\u5b57 name\u3002\u5076\u5c14\uff0c\u5728\u952e\u5165\u5b57\u7b26 c \u65f6\uff0c\u6309\u952e\u53ef\u80fd\u4f1a\u88ab\u957f\u6309\uff0c\u800c\u5b57\u7b26\u53ef\u80fd\u88ab\u8f93\u5165 1 \u6b21\u6216\u591a\u6b21\u3002

    \n\n

    \u4f60\u5c06\u4f1a\u68c0\u67e5\u952e\u76d8\u8f93\u5165\u7684\u5b57\u7b26 typed\u3002\u5982\u679c\u5b83\u5bf9\u5e94\u7684\u53ef\u80fd\u662f\u4f60\u7684\u670b\u53cb\u7684\u540d\u5b57\uff08\u5176\u4e2d\u4e00\u4e9b\u5b57\u7b26\u53ef\u80fd\u88ab\u957f\u6309\uff09\uff0c\u90a3\u4e48\u5c31\u8fd4\u56de True\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aname = "alex", typed = "aaleex"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a'alex' \u4e2d\u7684 'a' \u548c 'e' \u88ab\u957f\u6309\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aname = "saeed", typed = "ssaaedd"\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a'e' \u4e00\u5b9a\u9700\u8981\u88ab\u952e\u5165\u4e24\u6b21\uff0c\u4f46\u5728 typed \u7684\u8f93\u51fa\u4e2d\u4e0d\u662f\u8fd9\u6837\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aname = "leelee", typed = "lleeelee"\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1aname = "laiden", typed = "laiden"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u957f\u6309\u540d\u5b57\u4e2d\u7684\u5b57\u7b26\u5e76\u4e0d\u662f\u5fc5\u8981\u7684\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. name.length <= 1000
    2. \n\t
    3. typed.length <= 1000
    4. \n\t
    5. name \u548c typed \u7684\u5b57\u7b26\u90fd\u662f\u5c0f\u5199\u5b57\u6bcd\u3002
    6. \n
    \n\n

     

    \n\n

     

    \n", "tags_en": ["Two Pointers", "String"], "tags_cn": ["\u53cc\u6307\u9488", "\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isLongPressedName(string name, string typed) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isLongPressedName(String name, String typed) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isLongPressedName(self, name, typed):\n \"\"\"\n :type name: str\n :type typed: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isLongPressedName(self, name: str, typed: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isLongPressedName(char * name, char * typed){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsLongPressedName(string name, string typed) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} name\n * @param {string} typed\n * @return {boolean}\n */\nvar isLongPressedName = function(name, typed) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} name\n# @param {String} typed\n# @return {Boolean}\ndef is_long_pressed_name(name, typed)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isLongPressedName(_ name: String, _ typed: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isLongPressedName(name string, typed string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isLongPressedName(name: String, typed: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isLongPressedName(name: String, typed: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_long_pressed_name(name: String, typed: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $name\n * @param String $typed\n * @return Boolean\n */\n function isLongPressedName($name, $typed) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isLongPressedName(name: string, typed: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-long-pressed-name name typed)\n (-> string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0925](https://leetcode-cn.com/problems/long-pressed-name)", "[\u957f\u6309\u952e\u5165](/solution/0900-0999/0925.Long%20Pressed%20Name/README.md)", "`\u53cc\u6307\u9488`,`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0925](https://leetcode.com/problems/long-pressed-name)", "[Long Pressed Name](/solution/0900-0999/0925.Long%20Pressed%20Name/README_EN.md)", "`Two Pointers`,`String`", "Easy", ""]}, {"question_id": "0960", "frontend_question_id": "0924", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimize-malware-spread", "url_en": "https://leetcode.com/problems/minimize-malware-spread", "relative_path_cn": "/solution/0900-0999/0924.Minimize%20Malware%20Spread/README.md", "relative_path_en": "/solution/0900-0999/0924.Minimize%20Malware%20Spread/README_EN.md", "title_cn": "\u5c3d\u91cf\u51cf\u5c11\u6076\u610f\u8f6f\u4ef6\u7684\u4f20\u64ad", "title_en": "Minimize Malware Spread", "question_title_slug": "minimize-malware-spread", "content_en": "

    You are given a network of n nodes represented as an n x n adjacency matrix graph, where the ith node is directly connected to the jth node if graph[i][j] == 1.

    \n\n

    Some nodes initial are initially infected by malware. Whenever two nodes are directly connected, and at least one of those two nodes is infected by malware, both nodes will be infected by malware. This spread of malware will continue until no more nodes can be infected in this manner.

    \n\n

    Suppose M(initial) is the final number of nodes infected with malware in the entire network after the spread of malware stops. We will remove exactly one node from initial.

    \n\n

    Return the node that, if removed, would minimize M(initial). If multiple nodes could be removed to minimize M(initial), return such a node with the smallest index.

    \n\n

    Note that if a node was removed from the initial list of infected nodes, it might still be infected later due to the malware spread.

    \n\n

     

    \n

    Example 1:

    \n
    Input: graph = [[1,1,0],[1,1,0],[0,0,1]], initial = [0,1]\nOutput: 0\n

    Example 2:

    \n
    Input: graph = [[1,0,0],[0,1,0],[0,0,1]], initial = [0,2]\nOutput: 0\n

    Example 3:

    \n
    Input: graph = [[1,1,1],[1,1,1],[1,1,1]], initial = [1,2]\nOutput: 1\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == graph.length
    • \n\t
    • n == graph[i].length
    • \n\t
    • 2 <= n <= 300
    • \n\t
    • graph[i][j] is 0 or 1.
    • \n\t
    • graph[i][j] == graph[j][i]
    • \n\t
    • graph[i][i] == 1
    • \n\t
    • 1 <= initial.length <= n
    • \n\t
    • 0 <= initial[i] <= n - 1
    • \n\t
    • All the integers in initial are unique.
    • \n
    \n", "content_cn": "

    \u5728\u8282\u70b9\u7f51\u7edc\u4e2d\uff0c\u53ea\u6709\u5f53 graph[i][j] = 1 \u65f6\uff0c\u6bcf\u4e2a\u8282\u70b9 i \u80fd\u591f\u76f4\u63a5\u8fde\u63a5\u5230\u53e6\u4e00\u4e2a\u8282\u70b9 j\u3002

    \n\n

    \u4e00\u4e9b\u8282\u70b9 initial \u6700\u521d\u88ab\u6076\u610f\u8f6f\u4ef6\u611f\u67d3\u3002\u53ea\u8981\u4e24\u4e2a\u8282\u70b9\u76f4\u63a5\u8fde\u63a5\uff0c\u4e14\u5176\u4e2d\u81f3\u5c11\u4e00\u4e2a\u8282\u70b9\u53d7\u5230\u6076\u610f\u8f6f\u4ef6\u7684\u611f\u67d3\uff0c\u90a3\u4e48\u4e24\u4e2a\u8282\u70b9\u90fd\u5c06\u88ab\u6076\u610f\u8f6f\u4ef6\u611f\u67d3\u3002\u8fd9\u79cd\u6076\u610f\u8f6f\u4ef6\u7684\u4f20\u64ad\u5c06\u7ee7\u7eed\uff0c\u76f4\u5230\u6ca1\u6709\u66f4\u591a\u7684\u8282\u70b9\u53ef\u4ee5\u88ab\u8fd9\u79cd\u65b9\u5f0f\u611f\u67d3\u3002

    \n\n

    \u5047\u8bbe M(initial) \u662f\u5728\u6076\u610f\u8f6f\u4ef6\u505c\u6b62\u4f20\u64ad\u4e4b\u540e\uff0c\u6574\u4e2a\u7f51\u7edc\u4e2d\u611f\u67d3\u6076\u610f\u8f6f\u4ef6\u7684\u6700\u7ec8\u8282\u70b9\u6570\u3002

    \n\n

    \u6211\u4eec\u53ef\u4ee5\u4ece\u521d\u59cb\u5217\u8868\u4e2d\u5220\u9664\u4e00\u4e2a\u8282\u70b9\u3002\u5982\u679c\u79fb\u9664\u8fd9\u4e00\u8282\u70b9\u5c06\u6700\u5c0f\u5316 M(initial)\uff0c \u5219\u8fd4\u56de\u8be5\u8282\u70b9\u3002\u5982\u679c\u6709\u591a\u4e2a\u8282\u70b9\u6ee1\u8db3\u6761\u4ef6\uff0c\u5c31\u8fd4\u56de\u7d22\u5f15\u6700\u5c0f\u7684\u8282\u70b9\u3002

    \n\n

    \u8bf7\u6ce8\u610f\uff0c\u5982\u679c\u67d0\u4e2a\u8282\u70b9\u5df2\u4ece\u53d7\u611f\u67d3\u8282\u70b9\u7684\u5217\u8868 initial \u4e2d\u5220\u9664\uff0c\u5b83\u4ee5\u540e\u53ef\u80fd\u4ecd\u7136\u56e0\u6076\u610f\u8f6f\u4ef6\u4f20\u64ad\u800c\u53d7\u5230\u611f\u67d3\u3002

    \n\n

     

    \n\n
      \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1agraph = [[1,1,0],[1,1,0],[0,0,1]], initial = [0,1]\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1agraph = [[1,0,0],[0,1,0],[0,0,1]], initial = [0,2]\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1agraph = [[1,1,1],[1,1,1],[1,1,1]], initial = [1,2]\n\u8f93\u51fa\uff1a1\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 < graph.length = graph[0].length <= 300
    • \n\t
    • 0 <= graph[i][j] == graph[j][i] <= 1
    • \n\t
    • graph[i][i] == 1
    • \n\t
    • 1 <= initial.length < graph.length
    • \n\t
    • 0 <= initial[i] < graph.length
    • \n
    \n", "tags_en": ["Depth-first Search", "Union Find"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e76\u67e5\u96c6"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minMalwareSpread(vector>& graph, vector& initial) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minMalwareSpread(int[][] graph, int[] initial) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minMalwareSpread(self, graph, initial):\n \"\"\"\n :type graph: List[List[int]]\n :type initial: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minMalwareSpread(self, graph: List[List[int]], initial: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minMalwareSpread(int** graph, int graphSize, int* graphColSize, int* initial, int initialSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinMalwareSpread(int[][] graph, int[] initial) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} graph\n * @param {number[]} initial\n * @return {number}\n */\nvar minMalwareSpread = function(graph, initial) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} graph\n# @param {Integer[]} initial\n# @return {Integer}\ndef min_malware_spread(graph, initial)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minMalwareSpread(_ graph: [[Int]], _ initial: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minMalwareSpread(graph [][]int, initial []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minMalwareSpread(graph: Array[Array[Int]], initial: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minMalwareSpread(graph: Array, initial: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_malware_spread(graph: Vec>, initial: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $graph\n * @param Integer[] $initial\n * @return Integer\n */\n function minMalwareSpread($graph, $initial) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minMalwareSpread(graph: number[][], initial: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-malware-spread graph initial)\n (-> (listof (listof exact-integer?)) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0924](https://leetcode-cn.com/problems/minimize-malware-spread)", "[\u5c3d\u91cf\u51cf\u5c11\u6076\u610f\u8f6f\u4ef6\u7684\u4f20\u64ad](/solution/0900-0999/0924.Minimize%20Malware%20Spread/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e76\u67e5\u96c6`", "\u56f0\u96be", ""], "md_table_row_en": ["[0924](https://leetcode.com/problems/minimize-malware-spread)", "[Minimize Malware Spread](/solution/0900-0999/0924.Minimize%20Malware%20Spread/README_EN.md)", "`Depth-first Search`,`Union Find`", "Hard", ""]}, {"question_id": "0959", "frontend_question_id": "0923", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/3sum-with-multiplicity", "url_en": "https://leetcode.com/problems/3sum-with-multiplicity", "relative_path_cn": "/solution/0900-0999/0923.3Sum%20With%20Multiplicity/README.md", "relative_path_en": "/solution/0900-0999/0923.3Sum%20With%20Multiplicity/README_EN.md", "title_cn": "\u4e09\u6570\u4e4b\u548c\u7684\u591a\u79cd\u53ef\u80fd", "title_en": "3Sum With Multiplicity", "question_title_slug": "3sum-with-multiplicity", "content_en": "

    Given an integer array arr, and an integer target, return the number of tuples i, j, k such that i < j < k and arr[i] + arr[j] + arr[k] == target.

    \n\n

    As the answer can be very large, return it modulo 109 + 7.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr = [1,1,2,2,3,3,4,4,5,5], target = 8\nOutput: 20\nExplanation: \nEnumerating by the values (arr[i], arr[j], arr[k]):\n(1, 2, 5) occurs 8 times;\n(1, 3, 4) occurs 8 times;\n(2, 2, 4) occurs 2 times;\n(2, 3, 3) occurs 2 times.\n
    \n\n

    Example 2:

    \n\n
    \nInput: arr = [1,1,2,2,2,2], target = 5\nOutput: 12\nExplanation: \narr[i] = 1, arr[j] = arr[k] = 2 occurs 12 times:\nWe choose one 1 from [1,1] in 2 ways,\nand two 2s from [2,2,2,2] in 6 ways.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 3 <= arr.length <= 3000
    • \n\t
    • 0 <= arr[i] <= 100
    • \n\t
    • 0 <= target <= 300
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 A\uff0c\u4ee5\u53ca\u4e00\u4e2a\u6574\u6570 target \u4f5c\u4e3a\u76ee\u6807\u503c\uff0c\u8fd4\u56de\u6ee1\u8db3 i < j < k \u4e14 A[i] + A[j] + A[k] == target \u7684\u5143\u7ec4 i, j, k \u7684\u6570\u91cf\u3002

    \n\n

    \u7531\u4e8e\u7ed3\u679c\u4f1a\u975e\u5e38\u5927\uff0c\u8bf7\u8fd4\u56de \u7ed3\u679c\u9664\u4ee5 10^9 + 7 \u7684\u4f59\u6570\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aA = [1,1,2,2,3,3,4,4,5,5], target = 8\n\u8f93\u51fa\uff1a20\n\u89e3\u91ca\uff1a\n\u6309\u503c\u679a\u4e3e\uff08A[i]\uff0cA[j]\uff0cA[k]\uff09\uff1a\n(1, 2, 5) \u51fa\u73b0 8 \u6b21\uff1b\n(1, 3, 4) \u51fa\u73b0 8 \u6b21\uff1b\n(2, 2, 4) \u51fa\u73b0 2 \u6b21\uff1b\n(2, 3, 3) \u51fa\u73b0 2 \u6b21\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aA = [1,1,2,2,2,2], target = 5\n\u8f93\u51fa\uff1a12\n\u89e3\u91ca\uff1a\nA[i] = 1\uff0cA[j] = A[k] = 2 \u51fa\u73b0 12 \u6b21\uff1a\n\u6211\u4eec\u4ece [1,1] \u4e2d\u9009\u62e9\u4e00\u4e2a 1\uff0c\u6709 2 \u79cd\u60c5\u51b5\uff0c\n\u4ece [2,2,2,2] \u4e2d\u9009\u51fa\u4e24\u4e2a 2\uff0c\u6709 6 \u79cd\u60c5\u51b5\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 3 <= A.length <= 3000
    2. \n\t
    3. 0 <= A[i] <= 100
    4. \n\t
    5. 0 <= target <= 300
    6. \n
    \n", "tags_en": ["Two Pointers"], "tags_cn": ["\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int threeSumMulti(vector& arr, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int threeSumMulti(int[] arr, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def threeSumMulti(self, arr, target):\n \"\"\"\n :type arr: List[int]\n :type target: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def threeSumMulti(self, arr: List[int], target: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint threeSumMulti(int* arr, int arrSize, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ThreeSumMulti(int[] arr, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @param {number} target\n * @return {number}\n */\nvar threeSumMulti = function(arr, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @param {Integer} target\n# @return {Integer}\ndef three_sum_multi(arr, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func threeSumMulti(_ arr: [Int], _ target: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func threeSumMulti(arr []int, target int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def threeSumMulti(arr: Array[Int], target: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun threeSumMulti(arr: IntArray, target: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn three_sum_multi(arr: Vec, target: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @param Integer $target\n * @return Integer\n */\n function threeSumMulti($arr, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function threeSumMulti(arr: number[], target: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (three-sum-multi arr target)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0923](https://leetcode-cn.com/problems/3sum-with-multiplicity)", "[\u4e09\u6570\u4e4b\u548c\u7684\u591a\u79cd\u53ef\u80fd](/solution/0900-0999/0923.3Sum%20With%20Multiplicity/README.md)", "`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0923](https://leetcode.com/problems/3sum-with-multiplicity)", "[3Sum With Multiplicity](/solution/0900-0999/0923.3Sum%20With%20Multiplicity/README_EN.md)", "`Two Pointers`", "Medium", ""]}, {"question_id": "0958", "frontend_question_id": "0922", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sort-array-by-parity-ii", "url_en": "https://leetcode.com/problems/sort-array-by-parity-ii", "relative_path_cn": "/solution/0900-0999/0922.Sort%20Array%20By%20Parity%20II/README.md", "relative_path_en": "/solution/0900-0999/0922.Sort%20Array%20By%20Parity%20II/README_EN.md", "title_cn": "\u6309\u5947\u5076\u6392\u5e8f\u6570\u7ec4 II", "title_en": "Sort Array By Parity II", "question_title_slug": "sort-array-by-parity-ii", "content_en": "

    Given an array of integers nums, half of the integers in nums are odd, and the other half are even.

    \n\n

    Sort the array so that whenever nums[i] is odd, i is odd, and whenever nums[i] is even, i is even.

    \n\n

    Return any answer array that satisfies this condition.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [4,2,5,7]\nOutput: [4,5,2,7]\nExplanation: [4,7,2,5], [2,5,4,7], [2,7,4,5] would also have been accepted.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [2,3]\nOutput: [2,3]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= nums.length <= 2 * 104
    • \n\t
    • nums.length is even.
    • \n\t
    • Half of the integers in nums are even.
    • \n\t
    • 0 <= nums[i] <= 1000
    • \n
    \n\n

     

    \n

    Follow Up: Could you solve it in-place?

    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\u6570\u7ec4 A\uff0c A \u4e2d\u4e00\u534a\u6574\u6570\u662f\u5947\u6570\uff0c\u4e00\u534a\u6574\u6570\u662f\u5076\u6570\u3002

    \n\n

    \u5bf9\u6570\u7ec4\u8fdb\u884c\u6392\u5e8f\uff0c\u4ee5\u4fbf\u5f53 A[i] \u4e3a\u5947\u6570\u65f6\uff0ci \u4e5f\u662f\u5947\u6570\uff1b\u5f53 A[i] \u4e3a\u5076\u6570\u65f6\uff0c i \u4e5f\u662f\u5076\u6570\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u8fd4\u56de\u4efb\u4f55\u6ee1\u8db3\u4e0a\u8ff0\u6761\u4ef6\u7684\u6570\u7ec4\u4f5c\u4e3a\u7b54\u6848\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1a[4,2,5,7]\n\u8f93\u51fa\uff1a[4,5,2,7]\n\u89e3\u91ca\uff1a[4,7,2,5]\uff0c[2,5,4,7]\uff0c[2,7,4,5] \u4e5f\u4f1a\u88ab\u63a5\u53d7\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 2 <= A.length <= 20000
    2. \n\t
    3. A.length % 2 == 0
    4. \n\t
    5. 0 <= A[i] <= 1000
    6. \n
    \n\n

     

    \n", "tags_en": ["Sort", "Array"], "tags_cn": ["\u6392\u5e8f", "\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector sortArrayByParityII(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] sortArrayByParityII(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def sortArrayByParityII(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def sortArrayByParityII(self, nums: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* sortArrayByParityII(int* nums, int numsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] SortArrayByParityII(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar sortArrayByParityII = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer[]}\ndef sort_array_by_parity_ii(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func sortArrayByParityII(_ nums: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func sortArrayByParityII(nums []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def sortArrayByParityII(nums: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun sortArrayByParityII(nums: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sort_array_by_parity_ii(nums: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer[]\n */\n function sortArrayByParityII($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function sortArrayByParityII(nums: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (sort-array-by-parity-ii nums)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0922](https://leetcode-cn.com/problems/sort-array-by-parity-ii)", "[\u6309\u5947\u5076\u6392\u5e8f\u6570\u7ec4 II](/solution/0900-0999/0922.Sort%20Array%20By%20Parity%20II/README.md)", "`\u6392\u5e8f`,`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0922](https://leetcode.com/problems/sort-array-by-parity-ii)", "[Sort Array By Parity II](/solution/0900-0999/0922.Sort%20Array%20By%20Parity%20II/README_EN.md)", "`Sort`,`Array`", "Easy", ""]}, {"question_id": "0957", "frontend_question_id": "0921", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-add-to-make-parentheses-valid", "url_en": "https://leetcode.com/problems/minimum-add-to-make-parentheses-valid", "relative_path_cn": "/solution/0900-0999/0921.Minimum%20Add%20to%20Make%20Parentheses%20Valid/README.md", "relative_path_en": "/solution/0900-0999/0921.Minimum%20Add%20to%20Make%20Parentheses%20Valid/README_EN.md", "title_cn": "\u4f7f\u62ec\u53f7\u6709\u6548\u7684\u6700\u5c11\u6dfb\u52a0", "title_en": "Minimum Add to Make Parentheses Valid", "question_title_slug": "minimum-add-to-make-parentheses-valid", "content_en": "

    Given a string s of '(' and ')' parentheses, we add the minimum number of parentheses ( '(' or ')', and in any positions ) so that the resulting parentheses string is valid.

    \n\n

    Formally, a parentheses string is valid if and only if:

    \n\n
      \n\t
    • It is the empty string, or
    • \n\t
    • It can be written as AB (A concatenated with B), where A and B are valid strings, or
    • \n\t
    • It can be written as (A), where A is a valid string.
    • \n
    \n\n

    Given a parentheses string, return the minimum number of parentheses we must add to make the resulting string valid.

    \n\n

     

    \n\n

    Example 1:

    \n\n
    \nInput: s = "())"\nOutput: 1\n
    \n\n
    \n

    Example 2:

    \n\n
    \nInput: s = "((("\nOutput: 3\n
    \n\n
    \n

    Example 3:

    \n\n
    \nInput: s = "()"\nOutput: 0\n
    \n\n
    \n

    Example 4:

    \n\n
    \nInput: s = "()))(("\nOutput: 4
    \n\n

     

    \n
    \n
    \n
    \n\n

    Note:

    \n\n
      \n\t
    1. s.length <= 1000
    2. \n\t
    3. s only consists of '(' and ')' characters.
    4. \n
    \n\n
    \n
    \n
    \n
     
    \n
    \n
    \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u7531 '(' \u548c ')' \u62ec\u53f7\u7ec4\u6210\u7684\u5b57\u7b26\u4e32 S\uff0c\u6211\u4eec\u9700\u8981\u6dfb\u52a0\u6700\u5c11\u7684\u62ec\u53f7\uff08 '(' \u6216\u662f ')'\uff0c\u53ef\u4ee5\u5728\u4efb\u4f55\u4f4d\u7f6e\uff09\uff0c\u4ee5\u4f7f\u5f97\u5230\u7684\u62ec\u53f7\u5b57\u7b26\u4e32\u6709\u6548\u3002

    \n\n

    \u4ece\u5f62\u5f0f\u4e0a\u8bb2\uff0c\u53ea\u6709\u6ee1\u8db3\u4e0b\u9762\u51e0\u70b9\u4e4b\u4e00\uff0c\u62ec\u53f7\u5b57\u7b26\u4e32\u624d\u662f\u6709\u6548\u7684\uff1a

    \n\n
      \n\t
    • \u5b83\u662f\u4e00\u4e2a\u7a7a\u5b57\u7b26\u4e32\uff0c\u6216\u8005
    • \n\t
    • \u5b83\u53ef\u4ee5\u88ab\u5199\u6210 AB \uff08A \u4e0e B \u8fde\u63a5\uff09, \u5176\u4e2d A \u548c B \u90fd\u662f\u6709\u6548\u5b57\u7b26\u4e32\uff0c\u6216\u8005
    • \n\t
    • \u5b83\u53ef\u4ee5\u88ab\u5199\u4f5c (A)\uff0c\u5176\u4e2d A \u662f\u6709\u6548\u5b57\u7b26\u4e32\u3002
    • \n
    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u62ec\u53f7\u5b57\u7b26\u4e32\uff0c\u8fd4\u56de\u4e3a\u4f7f\u7ed3\u679c\u5b57\u7b26\u4e32\u6709\u6548\u800c\u5fc5\u987b\u6dfb\u52a0\u7684\u6700\u5c11\u62ec\u53f7\u6570\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a"())"\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a"((("\n\u8f93\u51fa\uff1a3\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1a"()"\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1a"()))(("\n\u8f93\u51fa\uff1a4
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. S.length <= 1000
    2. \n\t
    3. S \u53ea\u5305\u542b '(' \u548c ')' \u5b57\u7b26\u3002
    4. \n
    \n\n

     

    \n", "tags_en": ["Stack", "Greedy"], "tags_cn": ["\u6808", "\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minAddToMakeValid(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minAddToMakeValid(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minAddToMakeValid(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minAddToMakeValid(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minAddToMakeValid(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinAddToMakeValid(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar minAddToMakeValid = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef min_add_to_make_valid(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minAddToMakeValid(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minAddToMakeValid(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minAddToMakeValid(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minAddToMakeValid(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_add_to_make_valid(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function minAddToMakeValid($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minAddToMakeValid(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-add-to-make-valid s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0921](https://leetcode-cn.com/problems/minimum-add-to-make-parentheses-valid)", "[\u4f7f\u62ec\u53f7\u6709\u6548\u7684\u6700\u5c11\u6dfb\u52a0](/solution/0900-0999/0921.Minimum%20Add%20to%20Make%20Parentheses%20Valid/README.md)", "`\u6808`,`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0921](https://leetcode.com/problems/minimum-add-to-make-parentheses-valid)", "[Minimum Add to Make Parentheses Valid](/solution/0900-0999/0921.Minimum%20Add%20to%20Make%20Parentheses%20Valid/README_EN.md)", "`Stack`,`Greedy`", "Medium", ""]}, {"question_id": "0956", "frontend_question_id": "0920", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-music-playlists", "url_en": "https://leetcode.com/problems/number-of-music-playlists", "relative_path_cn": "/solution/0900-0999/0920.Number%20of%20Music%20Playlists/README.md", "relative_path_en": "/solution/0900-0999/0920.Number%20of%20Music%20Playlists/README_EN.md", "title_cn": "\u64ad\u653e\u5217\u8868\u7684\u6570\u91cf", "title_en": "Number of Music Playlists", "question_title_slug": "number-of-music-playlists", "content_en": "

    Your music player contains n different songs and she wants to listen to goal (not necessarily different) songs during your trip.  You create a playlist so that:

    \n\n
      \n\t
    • Every song is played at least once
    • \n\t
    • A song can only be played again only if k other songs have been played
    • \n
    \n\n

    Return the number of possible playlists.  As the answer can be very large, return it modulo 109 + 7.

    \n\n

     

    \n\n
    \n
    \n
    \n

    Example 1:

    \n\n
    \nInput: n = 3, goal = 3, k = 1\nOutput: 6\nExplanation: There are 6 possible playlists. [1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1].\n
    \n\n
    \n

    Example 2:

    \n\n
    \nInput: n = 2, goal = 3, k = 0\nOutput: 6\nExplanation: There are 6 possible playlists. [1, 1, 2], [1, 2, 1], [2, 1, 1], [2, 2, 1], [2, 1, 2], [1, 2, 2]\n
    \n\n
    \n

    Example 3:

    \n\n
    \nInput: n = 2, goal = 3, k = 1\nOutput: 2\nExplanation: There are 2 possible playlists. [1, 2, 1], [2, 1, 2]\n
    \n
    \n
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    1. 0 <= k < n <= goal <= 100
    2. \n
    \n
    \n
    \n
    \n", "content_cn": "

    \u4f60\u7684\u97f3\u4e50\u64ad\u653e\u5668\u91cc\u6709 N \u9996\u4e0d\u540c\u7684\u6b4c\uff0c\u5728\u65c5\u9014\u4e2d\uff0c\u4f60\u7684\u65c5\u4f34\u60f3\u8981\u542c L \u9996\u6b4c\uff08\u4e0d\u4e00\u5b9a\u4e0d\u540c\uff0c\u5373\uff0c\u5141\u8bb8\u6b4c\u66f2\u91cd\u590d\uff09\u3002\u8bf7\u4f60\u4e3a\u5979\u6309\u5982\u4e0b\u89c4\u5219\u521b\u5efa\u4e00\u4e2a\u64ad\u653e\u5217\u8868\uff1a

    \n\n
      \n\t
    • \u6bcf\u9996\u6b4c\u81f3\u5c11\u64ad\u653e\u4e00\u6b21\u3002
    • \n\t
    • \u4e00\u9996\u6b4c\u53ea\u6709\u5728\u5176\u4ed6 K \u9996\u6b4c\u64ad\u653e\u5b8c\u4e4b\u540e\u624d\u80fd\u518d\u6b21\u64ad\u653e\u3002
    • \n
    \n\n

    \u8fd4\u56de\u53ef\u4ee5\u6ee1\u8db3\u8981\u6c42\u7684\u64ad\u653e\u5217\u8868\u7684\u6570\u91cf\u3002\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u975e\u5e38\u5927\uff0c\u8bf7\u8fd4\u56de\u5b83\u6a21 10^9 + 7 \u7684\u7ed3\u679c\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aN = 3, L = 3, K = 1\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u6709 6 \u79cd\u53ef\u80fd\u7684\u64ad\u653e\u5217\u8868\u3002[1, 2, 3]\uff0c[1, 3, 2]\uff0c[2, 1, 3]\uff0c[2, 3, 1]\uff0c[3, 1, 2]\uff0c[3, 2, 1].\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aN = 2, L = 3, K = 0\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u6709 6 \u79cd\u53ef\u80fd\u7684\u64ad\u653e\u5217\u8868\u3002[1, 1, 2]\uff0c[1, 2, 1]\uff0c[2, 1, 1]\uff0c[2, 2, 1]\uff0c[2, 1, 2]\uff0c[1, 2, 2]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aN = 2, L = 3, K = 1\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6709 2 \u79cd\u53ef\u80fd\u7684\u64ad\u653e\u5217\u8868\u3002[1, 2, 1]\uff0c[2, 1, 2]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 0 <= K < N <= L <= 100
    2. \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numMusicPlaylists(int n, int goal, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numMusicPlaylists(int n, int goal, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numMusicPlaylists(self, n, goal, k):\n \"\"\"\n :type n: int\n :type goal: int\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numMusicPlaylists(self, n: int, goal: int, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numMusicPlaylists(int n, int goal, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumMusicPlaylists(int n, int goal, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} goal\n * @param {number} k\n * @return {number}\n */\nvar numMusicPlaylists = function(n, goal, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} goal\n# @param {Integer} k\n# @return {Integer}\ndef num_music_playlists(n, goal, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numMusicPlaylists(_ n: Int, _ goal: Int, _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numMusicPlaylists(n int, goal int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numMusicPlaylists(n: Int, goal: Int, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numMusicPlaylists(n: Int, goal: Int, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_music_playlists(n: i32, goal: i32, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $goal\n * @param Integer $k\n * @return Integer\n */\n function numMusicPlaylists($n, $goal, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numMusicPlaylists(n: number, goal: number, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-music-playlists n goal k)\n (-> exact-integer? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0920](https://leetcode-cn.com/problems/number-of-music-playlists)", "[\u64ad\u653e\u5217\u8868\u7684\u6570\u91cf](/solution/0900-0999/0920.Number%20of%20Music%20Playlists/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0920](https://leetcode.com/problems/number-of-music-playlists)", "[Number of Music Playlists](/solution/0900-0999/0920.Number%20of%20Music%20Playlists/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "0955", "frontend_question_id": "0919", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/complete-binary-tree-inserter", "url_en": "https://leetcode.com/problems/complete-binary-tree-inserter", "relative_path_cn": "/solution/0900-0999/0919.Complete%20Binary%20Tree%20Inserter/README.md", "relative_path_en": "/solution/0900-0999/0919.Complete%20Binary%20Tree%20Inserter/README_EN.md", "title_cn": "\u5b8c\u5168\u4e8c\u53c9\u6811\u63d2\u5165\u5668", "title_en": "Complete Binary Tree Inserter", "question_title_slug": "complete-binary-tree-inserter", "content_en": "

    A complete binary tree is a binary tree in which every level, except possibly the last, is completely filled, and all nodes are as far left as possible.

    \r\n\r\n

    Write a data structure CBTInserter that is initialized with a complete binary tree and supports the following operations:

    \r\n\r\n
      \r\n\t
    • CBTInserter(TreeNode root) initializes the data structure on a given tree with head node root;
    • \r\n\t
    • CBTInserter.insert(int v) will insert a TreeNode into the tree with value node.val = v so that the tree remains complete, and returns the value of the parent of the inserted TreeNode;
    • \r\n\t
    • CBTInserter.get_root() will return the head node of the tree.
    • \r\n
    \r\n\r\n
      \r\n
    \r\n\r\n
    \r\n

     

    \r\n\r\n

    Example 1:

    \r\n\r\n
    \r\nInput: inputs = ["CBTInserter","insert","get_root"], inputs = [[[1]],[2],[]]\r\nOutput: [null,1,[1,2]]\r\n
    \r\n\r\n
    \r\n

    Example 2:

    \r\n\r\n
    \r\nInput: inputs = ["CBTInserter","insert","insert","get_root"], inputs = [[[1,2,3,4,5,6]],[7],[8],[]]\r\nOutput: [null,3,4,[1,2,3,4,5,6,7,8]]
    \r\n
    \r\n\r\n
    \r\n

     

    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    1. The initial given tree is complete and contains between 1 and 1000 nodes.
    2. \r\n\t
    3. CBTInserter.insert is called at most 10000 times per test case.
    4. \r\n\t
    5. Every value of a given or inserted node is between 0 and 5000.
    6. \r\n
    \r\n
    \r\n
    \r\n\r\n
    \r\n

     

    \r\n\r\n
     
    \r\n
    \r\n", "content_cn": "

    \u5b8c\u5168\u4e8c\u53c9\u6811\u662f\u6bcf\u4e00\u5c42\uff08\u9664\u6700\u540e\u4e00\u5c42\u5916\uff09\u90fd\u662f\u5b8c\u5168\u586b\u5145\uff08\u5373\uff0c\u8282\u70b9\u6570\u8fbe\u5230\u6700\u5927\uff09\u7684\uff0c\u5e76\u4e14\u6240\u6709\u7684\u8282\u70b9\u90fd\u5c3d\u53ef\u80fd\u5730\u96c6\u4e2d\u5728\u5de6\u4fa7\u3002

    \n\n

    \u8bbe\u8ba1\u4e00\u4e2a\u7528\u5b8c\u5168\u4e8c\u53c9\u6811\u521d\u59cb\u5316\u7684\u6570\u636e\u7ed3\u6784 CBTInserter\uff0c\u5b83\u652f\u6301\u4ee5\u4e0b\u51e0\u79cd\u64cd\u4f5c\uff1a

    \n\n
      \n\t
    • CBTInserter(TreeNode root) \u4f7f\u7528\u5934\u8282\u70b9\u4e3a root \u7684\u7ed9\u5b9a\u6811\u521d\u59cb\u5316\u8be5\u6570\u636e\u7ed3\u6784\uff1b
    • \n\t
    • CBTInserter.insert(int v)  \u5411\u6811\u4e2d\u63d2\u5165\u4e00\u4e2a\u65b0\u8282\u70b9\uff0c\u8282\u70b9\u7c7b\u578b\u4e3a TreeNode\uff0c\u503c\u4e3a v \u3002\u4f7f\u6811\u4fdd\u6301\u5b8c\u5168\u4e8c\u53c9\u6811\u7684\u72b6\u6001\uff0c\u5e76\u8fd4\u56de\u63d2\u5165\u7684\u65b0\u8282\u70b9\u7684\u7236\u8282\u70b9\u7684\u503c\uff1b
    • \n\t
    • CBTInserter.get_root() \u5c06\u8fd4\u56de\u6811\u7684\u5934\u8282\u70b9\u3002
    • \n
    \n\n

     

    \n\n
      \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1ainputs = ["CBTInserter","insert","get_root"], inputs = [[[1]],[2],[]]\n\u8f93\u51fa\uff1a[null,1,[1,2]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1ainputs = ["CBTInserter","insert","insert","get_root"], inputs = [[[1,2,3,4,5,6]],[7],[8],[]]\n\u8f93\u51fa\uff1a[null,3,4,[1,2,3,4,5,6,7,8]]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. \u6700\u521d\u7ed9\u5b9a\u7684\u6811\u662f\u5b8c\u5168\u4e8c\u53c9\u6811\uff0c\u4e14\u5305\u542b 1 \u5230 1000 \u4e2a\u8282\u70b9\u3002
    2. \n\t
    3. \u6bcf\u4e2a\u6d4b\u8bd5\u7528\u4f8b\u6700\u591a\u8c03\u7528 CBTInserter.insert  \u64cd\u4f5c 10000 \u6b21\u3002
    4. \n\t
    5. \u7ed9\u5b9a\u8282\u70b9\u6216\u63d2\u5165\u8282\u70b9\u7684\u6bcf\u4e2a\u503c\u90fd\u5728 0 \u5230 5000 \u4e4b\u95f4\u3002
    6. \n
    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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 */\nclass CBTInserter {\npublic:\n CBTInserter(TreeNode* root) {\n\n }\n \n int insert(int v) {\n\n }\n \n TreeNode* get_root() {\n\n }\n};\n\n/**\n * Your CBTInserter object will be instantiated and called as such:\n * CBTInserter* obj = new CBTInserter(root);\n * int param_1 = obj->insert(v);\n * TreeNode* param_2 = obj->get_root();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode(int x) { val = x; }\n * }\n */\nclass CBTInserter {\n\n public CBTInserter(TreeNode root) {\n\n }\n \n public int insert(int v) {\n\n }\n \n public TreeNode get_root() {\n\n }\n}\n\n/**\n * Your CBTInserter object will be instantiated and called as such:\n * CBTInserter obj = new CBTInserter(root);\n * int param_1 = obj.insert(v);\n * TreeNode param_2 = obj.get_root();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass CBTInserter(object):\n\n def __init__(self, root):\n \"\"\"\n :type root: TreeNode\n \"\"\"\n \n\n def insert(self, v):\n \"\"\"\n :type v: int\n :rtype: int\n \"\"\"\n \n\n def get_root(self):\n \"\"\"\n :rtype: TreeNode\n \"\"\"\n \n\n\n# Your CBTInserter object will be instantiated and called as such:\n# obj = CBTInserter(root)\n# param_1 = obj.insert(v)\n# param_2 = obj.get_root()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass CBTInserter:\n\n def __init__(self, root: TreeNode):\n \n\n def insert(self, v: int) -> int:\n \n\n def get_root(self) -> TreeNode:\n \n\n\n# Your CBTInserter object will be instantiated and called as such:\n# obj = CBTInserter(root)\n# param_1 = obj.insert(v)\n# param_2 = obj.get_root()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n\ntypedef struct {\n \n} CBTInserter;\n\n\nCBTInserter* cBTInserterCreate(struct TreeNode* root) {\n \n}\n\nint cBTInserterInsert(CBTInserter* obj, int v) {\n \n}\n\nstruct TreeNode* cBTInserterGet_root(CBTInserter* obj) {\n \n}\n\nvoid cBTInserterFree(CBTInserter* obj) {\n \n}\n\n/**\n * Your CBTInserter struct will be instantiated and called as such:\n * CBTInserter* obj = cBTInserterCreate(root);\n * int param_1 = cBTInserterInsert(obj, v);\n \n * struct TreeNode* param_2 = cBTInserterGet_root(obj);\n \n * cBTInserterFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int x) { val = x; }\n * }\n */\npublic class CBTInserter {\n\n public CBTInserter(TreeNode root) {\n\n }\n \n public int Insert(int v) {\n\n }\n \n public TreeNode Get_root() {\n\n }\n}\n\n/**\n * Your CBTInserter object will be instantiated and called as such:\n * CBTInserter obj = new CBTInserter(root);\n * int param_1 = obj.Insert(v);\n * TreeNode param_2 = obj.Get_root();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val) {\n * this.val = val;\n * this.left = this.right = null;\n * }\n */\n/**\n * @param {TreeNode} root\n */\nvar CBTInserter = function(root) {\n\n};\n\n/** \n * @param {number} v\n * @return {number}\n */\nCBTInserter.prototype.insert = function(v) {\n\n};\n\n/**\n * @return {TreeNode}\n */\nCBTInserter.prototype.get_root = function() {\n\n};\n\n/**\n * Your CBTInserter object will be instantiated and called as such:\n * var obj = new CBTInserter(root)\n * var param_1 = obj.insert(v)\n * var param_2 = obj.get_root()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val)\n# @val = val\n# @left, @right = nil, nil\n# end\n# end\n\nclass CBTInserter\n\n=begin\n :type root: TreeNode\n=end\n def initialize(root)\n\n end\n\n\n=begin\n :type v: Integer\n :rtype: Integer\n=end\n def insert(v)\n\n end\n\n\n=begin\n :rtype: TreeNode\n=end\n def get_root()\n\n end\n\n\nend\n\n# Your CBTInserter object will be instantiated and called as such:\n# obj = CBTInserter.new(root)\n# param_1 = obj.insert(v)\n# param_2 = obj.get_root()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.left = nil\n * self.right = nil\n * }\n * }\n */\n\nclass CBTInserter {\n\n init(_ root: TreeNode?) {\n \n }\n \n func insert(_ v: Int) -> Int {\n \n }\n \n func get_root() -> TreeNode? {\n \n }\n}\n\n/**\n * Your CBTInserter object will be instantiated and called as such:\n * let obj = CBTInserter(root)\n * let ret_1: Int = obj.insert(v)\n * let ret_2: TreeNode? = obj.get_root()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\ntype CBTInserter struct {\n\n}\n\n\nfunc Constructor(root *TreeNode) CBTInserter {\n\n}\n\n\nfunc (this *CBTInserter) Insert(v int) int {\n\n}\n\n\nfunc (this *CBTInserter) Get_root() *TreeNode {\n\n}\n\n\n/**\n * Your CBTInserter object will be instantiated and called as such:\n * obj := Constructor(root);\n * param_1 := obj.Insert(v);\n * param_2 := obj.Get_root();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(var _value: Int) {\n * var value: Int = _value\n * var left: TreeNode = null\n * var right: TreeNode = null\n * }\n */\nclass CBTInserter(_root: TreeNode) {\n\n def insert(v: Int): Int = {\n\n }\n\n def get_root(): TreeNode = {\n\n }\n\n}\n\n/**\n * Your CBTInserter object will be instantiated and called as such:\n * var obj = new CBTInserter(root)\n * var param_1 = obj.insert(v)\n * var param_2 = obj.get_root()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass CBTInserter(root: TreeNode?) {\n\n fun insert(v: Int): Int {\n\n }\n\n fun get_root(): TreeNode? {\n\n }\n\n}\n\n/**\n * Your CBTInserter object will be instantiated and called as such:\n * var obj = CBTInserter(root)\n * var param_1 = obj.insert(v)\n * var param_2 = obj.get_root()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n// \n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nstruct CBTInserter {\n\n}\n\n\n/** \n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl CBTInserter {\n\n fn new(root: Option>>) -> Self {\n \n }\n \n fn insert(&self, v: i32) -> i32 {\n \n }\n \n fn get_root(&self) -> Option>> {\n \n }\n}\n\n/**\n * Your CBTInserter object will be instantiated and called as such:\n * let obj = CBTInserter::new(root);\n * let ret_1: i32 = obj.insert(v);\n * let ret_2: Option>> = obj.get_root();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($value) { $this->val = $value; }\n * }\n */\nclass CBTInserter {\n /**\n * @param TreeNode $root\n */\n function __construct($root) {\n \n }\n \n /**\n * @param Integer $v\n * @return Integer\n */\n function insert($v) {\n \n }\n \n /**\n * @return TreeNode\n */\n function get_root() {\n \n }\n}\n\n/**\n * Your CBTInserter object will be instantiated and called as such:\n * $obj = CBTInserter($root);\n * $ret_1 = $obj->insert($v);\n * $ret_2 = $obj->get_root();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nclass CBTInserter {\n constructor(root: TreeNode | null) {\n\n }\n\n insert(v: number): number {\n\n }\n\n get_root(): TreeNode | null {\n\n }\n}\n\n/**\n * Your CBTInserter object will be instantiated and called as such:\n * var obj = new CBTInserter(root)\n * var param_1 = obj.insert(v)\n * var param_2 = obj.get_root()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define cbt-inserter%\n (class object%\n (super-new)\n\n ; root : (or/c tree-node? #f)\n (init-field\n root)\n \n ; insert : exact-integer? -> exact-integer?\n (define/public (insert v)\n\n )\n ; get_root : -> (or/c tree-node? #f)\n (define/public (get_root)\n\n )))\n\n;; Your cbt-inserter% object will be instantiated and called as such:\n;; (define obj (new cbt-inserter% [root root]))\n;; (define param_1 (send obj insert v))\n;; (define param_2 (send obj get_root))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0919](https://leetcode-cn.com/problems/complete-binary-tree-inserter)", "[\u5b8c\u5168\u4e8c\u53c9\u6811\u63d2\u5165\u5668](/solution/0900-0999/0919.Complete%20Binary%20Tree%20Inserter/README.md)", "`\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0919](https://leetcode.com/problems/complete-binary-tree-inserter)", "[Complete Binary Tree Inserter](/solution/0900-0999/0919.Complete%20Binary%20Tree%20Inserter/README_EN.md)", "`Tree`", "Medium", ""]}, {"question_id": "0954", "frontend_question_id": "0918", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-sum-circular-subarray", "url_en": "https://leetcode.com/problems/maximum-sum-circular-subarray", "relative_path_cn": "/solution/0900-0999/0918.Maximum%20Sum%20Circular%20Subarray/README.md", "relative_path_en": "/solution/0900-0999/0918.Maximum%20Sum%20Circular%20Subarray/README_EN.md", "title_cn": "\u73af\u5f62\u5b50\u6570\u7ec4\u7684\u6700\u5927\u548c", "title_en": "Maximum Sum Circular Subarray", "question_title_slug": "maximum-sum-circular-subarray", "content_en": "

    Given a circular integer array nums of length n, return the maximum possible sum of a non-empty subarray of nums.

    \n\n

    A circular array means the end of the array connects to the beginning of the array. Formally, the next element of nums[i] is nums[(i + 1) % n] and the previous element of nums[i] is nums[(i - 1 + n) % n].

    \n\n

    A subarray may only include each element of the fixed buffer nums at most once. Formally, for a subarray nums[i], nums[i + 1], ..., nums[j], there does not exist i <= k1, k2 <= j with k1 % n == k2 % n.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,-2,3,-2]\nOutput: 3\nExplanation: Subarray [3] has maximum sum 3\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [5,-3,5]\nOutput: 10\nExplanation: Subarray [5,5] has maximum sum 5 + 5 = 10\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [3,-1,2,-1]\nOutput: 4\nExplanation: Subarray [2,-1,3] has maximum sum 2 + (-1) + 3 = 4\n
    \n\n

    Example 4:

    \n\n
    \nInput: nums = [3,-2,2,-3]\nOutput: 3\nExplanation: Subarray [3] and [3,-2,2] both have maximum sum 3\n
    \n\n

    Example 5:

    \n\n
    \nInput: nums = [-2,-3,-1]\nOutput: -1\nExplanation: Subarray [-1] has maximum sum -1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= n <= 3 * 104
    • \n\t
    • -3 * 104 <= nums[i] <= 3 * 104
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u7531\u6574\u6570\u6570\u7ec4 A \u8868\u793a\u7684\u73af\u5f62\u6570\u7ec4 C\uff0c\u6c42 C \u7684\u975e\u7a7a\u5b50\u6570\u7ec4\u7684\u6700\u5927\u53ef\u80fd\u548c\u3002

    \n\n

    \u5728\u6b64\u5904\uff0c\u73af\u5f62\u6570\u7ec4\u610f\u5473\u7740\u6570\u7ec4\u7684\u672b\u7aef\u5c06\u4f1a\u4e0e\u5f00\u5934\u76f8\u8fde\u5448\u73af\u72b6\u3002\uff08\u5f62\u5f0f\u4e0a\uff0c\u5f530 <= i < A.length \u65f6 C[i] = A[i]\uff0c\u4e14\u5f53 i >= 0 \u65f6 C[i+A.length] = C[i]\uff09

    \n\n

    \u6b64\u5916\uff0c\u5b50\u6570\u7ec4\u6700\u591a\u53ea\u80fd\u5305\u542b\u56fa\u5b9a\u7f13\u51b2\u533a A \u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u4e00\u6b21\u3002\uff08\u5f62\u5f0f\u4e0a\uff0c\u5bf9\u4e8e\u5b50\u6570\u7ec4 C[i], C[i+1], ..., C[j]\uff0c\u4e0d\u5b58\u5728 i <= k1, k2 <= j \u5176\u4e2d k1 % A.length = k2 % A.length\uff09

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a[1,-2,3,-2]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u4ece\u5b50\u6570\u7ec4 [3] \u5f97\u5230\u6700\u5927\u548c 3\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a[5,-3,5]\n\u8f93\u51fa\uff1a10\n\u89e3\u91ca\uff1a\u4ece\u5b50\u6570\u7ec4 [5,5] \u5f97\u5230\u6700\u5927\u548c 5 + 5 = 10\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1a[3,-1,2,-1]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u4ece\u5b50\u6570\u7ec4 [2,-1,3] \u5f97\u5230\u6700\u5927\u548c 2 + (-1) + 3 = 4\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1a[3,-2,2,-3]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u4ece\u5b50\u6570\u7ec4 [3] \u548c [3,-2,2] \u90fd\u53ef\u4ee5\u5f97\u5230\u6700\u5927\u548c 3\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1a[-2,-3,-1]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u4ece\u5b50\u6570\u7ec4 [-1] \u5f97\u5230\u6700\u5927\u548c -1\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. -30000 <= A[i] <= 30000
    2. \n\t
    3. 1 <= A.length <= 30000
    4. \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxSubarraySumCircular(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxSubarraySumCircular(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxSubarraySumCircular(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxSubarraySumCircular(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxSubarraySumCircular(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxSubarraySumCircular(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar maxSubarraySumCircular = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef max_subarray_sum_circular(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxSubarraySumCircular(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxSubarraySumCircular(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxSubarraySumCircular(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxSubarraySumCircular(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_subarray_sum_circular(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function maxSubarraySumCircular($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxSubarraySumCircular(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-subarray-sum-circular nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0918](https://leetcode-cn.com/problems/maximum-sum-circular-subarray)", "[\u73af\u5f62\u5b50\u6570\u7ec4\u7684\u6700\u5927\u548c](/solution/0900-0999/0918.Maximum%20Sum%20Circular%20Subarray/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0918](https://leetcode.com/problems/maximum-sum-circular-subarray)", "[Maximum Sum Circular Subarray](/solution/0900-0999/0918.Maximum%20Sum%20Circular%20Subarray/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0953", "frontend_question_id": "0917", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reverse-only-letters", "url_en": "https://leetcode.com/problems/reverse-only-letters", "relative_path_cn": "/solution/0900-0999/0917.Reverse%20Only%20Letters/README.md", "relative_path_en": "/solution/0900-0999/0917.Reverse%20Only%20Letters/README_EN.md", "title_cn": "\u4ec5\u4ec5\u53cd\u8f6c\u5b57\u6bcd", "title_en": "Reverse Only Letters", "question_title_slug": "reverse-only-letters", "content_en": "

    Given a string s, return the "reversed" string where all characters that are not a letter stay in the same place, and all letters reverse their positions.

    \n\n

     

    \n\n
    \n
    \n
    \n
      \n
    \n
    \n
    \n
    \n\n
    \n

    Example 1:

    \n\n
    \nInput: s = "ab-cd"\nOutput: "dc-ba"\n
    \n\n
    \n

    Example 2:

    \n\n
    \nInput: s = "a-bC-dEf-ghIj"\nOutput: "j-Ih-gfE-dCba"\n
    \n\n
    \n

    Example 3:

    \n\n
    \nInput: s = "Test1ng-Leet=code-Q!"\nOutput: "Qedo1ct-eeLg=ntse-T!"\n
    \n\n

     

    \n\n
    \n

    Note:

    \n\n
      \n\t
    1. s.length <= 100
    2. \n\t
    3. 33 <= s[i].ASCIIcode <= 122 
    4. \n\t
    5. s doesn't contain \\ or "
    6. \n
    \n
    \n
    \n
    \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32 S\uff0c\u8fd4\u56de “\u53cd\u8f6c\u540e\u7684” \u5b57\u7b26\u4e32\uff0c\u5176\u4e2d\u4e0d\u662f\u5b57\u6bcd\u7684\u5b57\u7b26\u90fd\u4fdd\u7559\u5728\u539f\u5730\uff0c\u800c\u6240\u6709\u5b57\u6bcd\u7684\u4f4d\u7f6e\u53d1\u751f\u53cd\u8f6c\u3002

    \n\n

     

    \n\n
      \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a"ab-cd"\n\u8f93\u51fa\uff1a"dc-ba"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a"a-bC-dEf-ghIj"\n\u8f93\u51fa\uff1a"j-Ih-gfE-dCba"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1a"Test1ng-Leet=code-Q!"\n\u8f93\u51fa\uff1a"Qedo1ct-eeLg=ntse-T!"\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. S.length <= 100
    2. \n\t
    3. 33 <= S[i].ASCIIcode <= 122 
    4. \n\t
    5. S \u4e2d\u4e0d\u5305\u542b \\ or "
    6. \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string reverseOnlyLetters(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String reverseOnlyLetters(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def reverseOnlyLetters(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def reverseOnlyLetters(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * reverseOnlyLetters(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ReverseOnlyLetters(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar reverseOnlyLetters = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef reverse_only_letters(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func reverseOnlyLetters(_ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func reverseOnlyLetters(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def reverseOnlyLetters(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun reverseOnlyLetters(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn reverse_only_letters(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function reverseOnlyLetters($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function reverseOnlyLetters(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (reverse-only-letters s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0917](https://leetcode-cn.com/problems/reverse-only-letters)", "[\u4ec5\u4ec5\u53cd\u8f6c\u5b57\u6bcd](/solution/0900-0999/0917.Reverse%20Only%20Letters/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0917](https://leetcode.com/problems/reverse-only-letters)", "[Reverse Only Letters](/solution/0900-0999/0917.Reverse%20Only%20Letters/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "0952", "frontend_question_id": "0916", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/word-subsets", "url_en": "https://leetcode.com/problems/word-subsets", "relative_path_cn": "/solution/0900-0999/0916.Word%20Subsets/README.md", "relative_path_en": "/solution/0900-0999/0916.Word%20Subsets/README_EN.md", "title_cn": "\u5355\u8bcd\u5b50\u96c6", "title_en": "Word Subsets", "question_title_slug": "word-subsets", "content_en": "

    We are given two arrays words1 and words2 of words.  Each word is a string of lowercase letters.

    \n\n

    Now, say that word b is a subset of word a if every letter in b occurs in a, including multiplicity.  For example, "wrr" is a subset of "warrior", but is not a subset of "world".

    \n\n

    Now say a word a from words1 is universal if for every b in words2, b is a subset of a

    \n\n

    Return a list of all universal words in words1.  You can return the words in any order.

    \n\n

     

    \n\n
      \n
    \n\n
    \n

    Example 1:

    \n\n
    \nInput: words1 = ["amazon","apple","facebook","google","leetcode"], words2 = ["e","o"]\nOutput: ["facebook","google","leetcode"]\n
    \n\n
    \n

    Example 2:

    \n\n
    \nInput: words1 = ["amazon","apple","facebook","google","leetcode"], words2 = ["l","e"]\nOutput: ["apple","google","leetcode"]\n
    \n\n
    \n

    Example 3:

    \n\n
    \nInput: words1 = ["amazon","apple","facebook","google","leetcode"], words2 = ["e","oo"]\nOutput: ["facebook","google"]\n
    \n\n
    \n

    Example 4:

    \n\n
    \nInput: words1 = ["amazon","apple","facebook","google","leetcode"], words2 = ["lo","eo"]\nOutput: ["google","leetcode"]\n
    \n\n
    \n

    Example 5:

    \n\n
    \nInput: words1 = ["amazon","apple","facebook","google","leetcode"], words2 = ["ec","oc","ceo"]\nOutput: ["facebook","leetcode"]\n
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    1. 1 <= words1.length, words2.length <= 10000
    2. \n\t
    3. 1 <= words1[i].length, words2[i].length <= 10
    4. \n\t
    5. words1[i] and words2[i] consist only of lowercase letters.
    6. \n\t
    7. All words in words1[i] are unique: there isn't i != j with words1[i] == words1[j].
    8. \n
    \n
    \n
    \n
    \n
    \n
    \n", "content_cn": "

    \u6211\u4eec\u7ed9\u51fa\u4e24\u4e2a\u5355\u8bcd\u6570\u7ec4 A \u548c B\u3002\u6bcf\u4e2a\u5355\u8bcd\u90fd\u662f\u4e00\u4e32\u5c0f\u5199\u5b57\u6bcd\u3002

    \n\n

    \u73b0\u5728\uff0c\u5982\u679c b \u4e2d\u7684\u6bcf\u4e2a\u5b57\u6bcd\u90fd\u51fa\u73b0\u5728 a \u4e2d\uff0c\u5305\u62ec\u91cd\u590d\u51fa\u73b0\u7684\u5b57\u6bcd\uff0c\u90a3\u4e48\u79f0\u5355\u8bcd b \u662f\u5355\u8bcd a \u7684\u5b50\u96c6\u3002 \u4f8b\u5982\uff0c“wrr” \u662f “warrior” \u7684\u5b50\u96c6\uff0c\u4f46\u4e0d\u662f “world” \u7684\u5b50\u96c6\u3002

    \n\n

    \u5982\u679c\u5bf9 B \u4e2d\u7684\u6bcf\u4e00\u4e2a\u5355\u8bcd b\uff0cb \u90fd\u662f a \u7684\u5b50\u96c6\uff0c\u90a3\u4e48\u6211\u4eec\u79f0 A \u4e2d\u7684\u5355\u8bcd a \u662f\u901a\u7528\u7684\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u6309\u4efb\u610f\u987a\u5e8f\u4ee5\u5217\u8868\u5f62\u5f0f\u8fd4\u56de A \u4e2d\u6240\u6709\u7684\u901a\u7528\u5355\u8bcd\u3002

    \n\n

     

    \n\n
      \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aA = ["amazon","apple","facebook","google","leetcode"], B = ["e","o"]\n\u8f93\u51fa\uff1a["facebook","google","leetcode"]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aA = ["amazon","apple","facebook","google","leetcode"], B = ["l","e"]\n\u8f93\u51fa\uff1a["apple","google","leetcode"]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aA = ["amazon","apple","facebook","google","leetcode"], B = ["e","oo"]\n\u8f93\u51fa\uff1a["facebook","google"]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1aA = ["amazon","apple","facebook","google","leetcode"], B = ["lo","eo"]\n\u8f93\u51fa\uff1a["google","leetcode"]\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1aA = ["amazon","apple","facebook","google","leetcode"], B = ["ec","oc","ceo"]\n\u8f93\u51fa\uff1a["facebook","leetcode"]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= A.length, B.length <= 10000
    2. \n\t
    3. 1 <= A[i].length, B[i].length <= 10
    4. \n\t
    5. A[i] \u548c B[i] \u53ea\u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210\u3002
    6. \n\t
    7. A[i] \u4e2d\u6240\u6709\u7684\u5355\u8bcd\u90fd\u662f\u72ec\u4e00\u65e0\u4e8c\u7684\uff0c\u4e5f\u5c31\u662f\u8bf4\u4e0d\u5b58\u5728 i != j \u4f7f\u5f97 A[i] == A[j]\u3002
    8. \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector wordSubsets(vector& words1, vector& words2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List wordSubsets(String[] words1, String[] words2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def wordSubsets(self, words1, words2):\n \"\"\"\n :type words1: List[str]\n :type words2: List[str]\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def wordSubsets(self, words1: List[str], words2: List[str]) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** wordSubsets(char ** words1, int words1Size, char ** words2, int words2Size, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList WordSubsets(string[] words1, string[] words2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words1\n * @param {string[]} words2\n * @return {string[]}\n */\nvar wordSubsets = function(words1, words2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words1\n# @param {String[]} words2\n# @return {String[]}\ndef word_subsets(words1, words2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func wordSubsets(_ words1: [String], _ words2: [String]) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func wordSubsets(words1 []string, words2 []string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def wordSubsets(words1: Array[String], words2: Array[String]): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun wordSubsets(words1: Array, words2: Array): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn word_subsets(words1: Vec, words2: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words1\n * @param String[] $words2\n * @return String[]\n */\n function wordSubsets($words1, $words2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function wordSubsets(words1: string[], words2: string[]): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (word-subsets words1 words2)\n (-> (listof string?) (listof string?) (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0916](https://leetcode-cn.com/problems/word-subsets)", "[\u5355\u8bcd\u5b50\u96c6](/solution/0900-0999/0916.Word%20Subsets/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0916](https://leetcode.com/problems/word-subsets)", "[Word Subsets](/solution/0900-0999/0916.Word%20Subsets/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "0951", "frontend_question_id": "0915", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/partition-array-into-disjoint-intervals", "url_en": "https://leetcode.com/problems/partition-array-into-disjoint-intervals", "relative_path_cn": "/solution/0900-0999/0915.Partition%20Array%20into%20Disjoint%20Intervals/README.md", "relative_path_en": "/solution/0900-0999/0915.Partition%20Array%20into%20Disjoint%20Intervals/README_EN.md", "title_cn": "\u5206\u5272\u6570\u7ec4", "title_en": "Partition Array into Disjoint Intervals", "question_title_slug": "partition-array-into-disjoint-intervals", "content_en": "

    Given an array nums, partition it into two (contiguous) subarrays left and right so that:

    \n\n
      \n\t
    • Every element in left is less than or equal to every element in right.
    • \n\t
    • left and right are non-empty.
    • \n\t
    • left has the smallest possible size.
    • \n
    \n\n

    Return the length of left after such a partitioning.  It is guaranteed that such a partitioning exists.

    \n\n

     

    \n\n

    Example 1:

    \n\n
    \nInput: nums = [5,0,3,8,6]\nOutput: 3\nExplanation: left = [5,0,3], right = [8,6]\n
    \n\n
    \n

    Example 2:

    \n\n
    \nInput: nums = [1,1,1,0,6,12]\nOutput: 4\nExplanation: left = [1,1,1,0], right = [6,12]\n
    \n\n

     

    \n
    \n\n

    Note:

    \n\n
      \n\t
    1. 2 <= nums.length <= 30000
    2. \n\t
    3. 0 <= nums[i] <= 106
    4. \n\t
    5. It is guaranteed there is at least one way to partition nums as described.
    6. \n
    \n\n
    \n
     
    \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6570\u7ec4\u00a0A\uff0c\u5c06\u5176\u5212\u5206\u4e3a\u4e24\u4e2a\u8fde\u7eed\u5b50\u6570\u7ec4\u00a0left\u00a0\u548c\u00a0right\uff0c\u00a0\u4f7f\u5f97\uff1a

    \n\n
      \n\t
    • left\u00a0\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u90fd\u5c0f\u4e8e\u6216\u7b49\u4e8e\u00a0right\u00a0\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u3002
    • \n\t
    • left \u548c\u00a0right\u00a0\u90fd\u662f\u975e\u7a7a\u7684\u3002
    • \n\t
    • left \u7684\u957f\u5ea6\u8981\u5c3d\u53ef\u80fd\u5c0f\u3002
    • \n
    \n\n

    \u5728\u5b8c\u6210\u8fd9\u6837\u7684\u5206\u7ec4\u540e\u8fd4\u56de\u00a0left\u00a0\u7684\u957f\u5ea6\u3002\u53ef\u4ee5\u4fdd\u8bc1\u5b58\u5728\u8fd9\u6837\u7684\u5212\u5206\u65b9\u6cd5\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[5,0,3,8,6]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1aleft = [5,0,3]\uff0cright = [8,6]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[1,1,1,0,6,12]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1aleft = [1,1,1,0]\uff0cright = [6,12]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 2 <= A.length\u00a0<= 30000
    2. \n\t
    3. 0 <= A[i] <= 10^6
    4. \n\t
    5. \u53ef\u4ee5\u4fdd\u8bc1\u81f3\u5c11\u6709\u4e00\u79cd\u65b9\u6cd5\u80fd\u591f\u6309\u9898\u76ee\u6240\u63cf\u8ff0\u7684\u90a3\u6837\u5bf9 A \u8fdb\u884c\u5212\u5206\u3002
    6. \n
    \n\n

    \u00a0

    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int partitionDisjoint(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int partitionDisjoint(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def partitionDisjoint(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def partitionDisjoint(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint partitionDisjoint(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int PartitionDisjoint(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar partitionDisjoint = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef partition_disjoint(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func partitionDisjoint(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func partitionDisjoint(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def partitionDisjoint(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun partitionDisjoint(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn partition_disjoint(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function partitionDisjoint($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function partitionDisjoint(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (partition-disjoint nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0915](https://leetcode-cn.com/problems/partition-array-into-disjoint-intervals)", "[\u5206\u5272\u6570\u7ec4](/solution/0900-0999/0915.Partition%20Array%20into%20Disjoint%20Intervals/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0915](https://leetcode.com/problems/partition-array-into-disjoint-intervals)", "[Partition Array into Disjoint Intervals](/solution/0900-0999/0915.Partition%20Array%20into%20Disjoint%20Intervals/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0950", "frontend_question_id": "0914", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/x-of-a-kind-in-a-deck-of-cards", "url_en": "https://leetcode.com/problems/x-of-a-kind-in-a-deck-of-cards", "relative_path_cn": "/solution/0900-0999/0914.X%20of%20a%20Kind%20in%20a%20Deck%20of%20Cards/README.md", "relative_path_en": "/solution/0900-0999/0914.X%20of%20a%20Kind%20in%20a%20Deck%20of%20Cards/README_EN.md", "title_cn": "\u5361\u724c\u5206\u7ec4", "title_en": "X of a Kind in a Deck of Cards", "question_title_slug": "x-of-a-kind-in-a-deck-of-cards", "content_en": "

    In a deck of cards, each card has an integer written on it.

    \n\n

    Return true if and only if you can choose X >= 2 such that it is possible to split the entire deck into 1 or more groups of cards, where:

    \n\n
      \n\t
    • Each group has exactly X cards.
    • \n\t
    • All the cards in each group have the same integer.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: deck = [1,2,3,4,4,3,2,1]\nOutput: true\nExplanation: Possible partition [1,1],[2,2],[3,3],[4,4].\n
    \n\n

    Example 2:

    \n\n
    \nInput: deck = [1,1,1,2,2,2,3,3]\nOutput: false\nExplanation: No possible partition.\n
    \n\n

    Example 3:

    \n\n
    \nInput: deck = [1]\nOutput: false\nExplanation: No possible partition.\n
    \n\n

    Example 4:

    \n\n
    \nInput: deck = [1,1]\nOutput: true\nExplanation: Possible partition [1,1].\n
    \n\n

    Example 5:

    \n\n
    \nInput: deck = [1,1,2,2,2,2]\nOutput: true\nExplanation: Possible partition [1,1],[2,2],[2,2].\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= deck.length <= 104
    • \n\t
    • 0 <= deck[i] < 104
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u526f\u724c\uff0c\u6bcf\u5f20\u724c\u4e0a\u90fd\u5199\u7740\u4e00\u4e2a\u6574\u6570\u3002

    \n\n

    \u6b64\u65f6\uff0c\u4f60\u9700\u8981\u9009\u5b9a\u4e00\u4e2a\u6570\u5b57 X\uff0c\u4f7f\u6211\u4eec\u53ef\u4ee5\u5c06\u6574\u526f\u724c\u6309\u4e0b\u8ff0\u89c4\u5219\u5206\u6210 1 \u7ec4\u6216\u66f4\u591a\u7ec4\uff1a

    \n\n
      \n\t
    • \u6bcf\u7ec4\u90fd\u6709 X \u5f20\u724c\u3002
    • \n\t
    • \u7ec4\u5185\u6240\u6709\u7684\u724c\u4e0a\u90fd\u5199\u7740\u76f8\u540c\u7684\u6574\u6570\u3002
    • \n
    \n\n

    \u4ec5\u5f53\u4f60\u53ef\u9009\u7684 X >= 2 \u65f6\u8fd4\u56de true\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a[1,2,3,4,4,3,2,1]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u53ef\u884c\u7684\u5206\u7ec4\u662f [1,1]\uff0c[2,2]\uff0c[3,3]\uff0c[4,4]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a[1,1,1,2,2,2,3,3]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u6ca1\u6709\u6ee1\u8db3\u8981\u6c42\u7684\u5206\u7ec4\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1a[1]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u6ca1\u6709\u6ee1\u8db3\u8981\u6c42\u7684\u5206\u7ec4\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1a[1,1]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u53ef\u884c\u7684\u5206\u7ec4\u662f [1,1]\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1a[1,1,2,2,2,2]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u53ef\u884c\u7684\u5206\u7ec4\u662f [1,1]\uff0c[2,2]\uff0c[2,2]\n
    \n\n


    \n\u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= deck.length <= 10000
    2. \n\t
    3. 0 <= deck[i] < 10000
    4. \n
    \n\n

     

    \n", "tags_en": ["Array", "Math"], "tags_cn": ["\u6570\u7ec4", "\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool hasGroupsSizeX(vector& deck) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean hasGroupsSizeX(int[] deck) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def hasGroupsSizeX(self, deck):\n \"\"\"\n :type deck: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def hasGroupsSizeX(self, deck: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool hasGroupsSizeX(int* deck, int deckSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool HasGroupsSizeX(int[] deck) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} deck\n * @return {boolean}\n */\nvar hasGroupsSizeX = function(deck) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} deck\n# @return {Boolean}\ndef has_groups_size_x(deck)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func hasGroupsSizeX(_ deck: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func hasGroupsSizeX(deck []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def hasGroupsSizeX(deck: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun hasGroupsSizeX(deck: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn has_groups_size_x(deck: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $deck\n * @return Boolean\n */\n function hasGroupsSizeX($deck) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function hasGroupsSizeX(deck: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (has-groups-size-x deck)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0914](https://leetcode-cn.com/problems/x-of-a-kind-in-a-deck-of-cards)", "[\u5361\u724c\u5206\u7ec4](/solution/0900-0999/0914.X%20of%20a%20Kind%20in%20a%20Deck%20of%20Cards/README.md)", "`\u6570\u7ec4`,`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0914](https://leetcode.com/problems/x-of-a-kind-in-a-deck-of-cards)", "[X of a Kind in a Deck of Cards](/solution/0900-0999/0914.X%20of%20a%20Kind%20in%20a%20Deck%20of%20Cards/README_EN.md)", "`Array`,`Math`", "Easy", ""]}, {"question_id": "0949", "frontend_question_id": "0913", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/cat-and-mouse", "url_en": "https://leetcode.com/problems/cat-and-mouse", "relative_path_cn": "/solution/0900-0999/0913.Cat%20and%20Mouse/README.md", "relative_path_en": "/solution/0900-0999/0913.Cat%20and%20Mouse/README_EN.md", "title_cn": "\u732b\u548c\u8001\u9f20", "title_en": "Cat and Mouse", "question_title_slug": "cat-and-mouse", "content_en": "

    A game on an undirected graph is played by two players, Mouse and Cat, who alternate turns.

    \n\n

    The graph is given as follows: graph[a] is a list of all nodes b such that ab is an edge of the graph.

    \n\n

    The mouse starts at node 1 and goes first, the cat starts at node 2 and goes second, and there is a hole at node 0.

    \n\n

    During each player's turn, they must travel along one edge of the graph that meets where they are.  For example, if the Mouse is at node 1, it must travel to any node in graph[1].

    \n\n

    Additionally, it is not allowed for the Cat to travel to the Hole (node 0.)

    \n\n

    Then, the game can end in three ways:

    \n\n
      \n\t
    • If ever the Cat occupies the same node as the Mouse, the Cat wins.
    • \n\t
    • If ever the Mouse reaches the Hole, the Mouse wins.
    • \n\t
    • If ever a position is repeated (i.e., the players are in the same position as a previous turn, and it is the same player's turn to move), the game is a draw.
    • \n
    \n\n

    Given a graph, and assuming both players play optimally, return

    \n\n
      \n\t
    • 1 if the mouse wins the game,
    • \n\t
    • 2 if the cat wins the game, or
    • \n\t
    • 0 if the game is a draw.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: graph = [[2,5],[3],[0,4,5],[1,4,5],[2,3],[0,2,3]]\nOutput: 0\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: graph = [[1,3],[0],[3],[0,2]]\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 3 <= graph.length <= 50
    • \n\t
    • 1 <= graph[i].length < graph.length
    • \n\t
    • 0 <= graph[i][j] < graph.length
    • \n\t
    • graph[i][j] != i
    • \n\t
    • graph[i] is unique.
    • \n\t
    • The mouse and the cat can always move. 
    • \n
    \n", "content_cn": "

    \u4e24\u4e2a\u73a9\u5bb6\u5206\u522b\u626e\u6f14\u732b\uff08Cat\uff09\u548c\u8001\u9f20\uff08Mouse\uff09\u5728\u65e0\u5411\u56fe\u4e0a\u8fdb\u884c\u6e38\u620f\uff0c\u4ed6\u4eec\u8f6e\u6d41\u884c\u52a8\u3002

    \n\n

    \u8be5\u56fe\u6309\u4e0b\u8ff0\u89c4\u5219\u7ed9\u51fa\uff1agraph[a] \u662f\u6240\u6709\u7ed3\u70b9 b \u7684\u5217\u8868\uff0c\u4f7f\u5f97 ab \u662f\u56fe\u7684\u4e00\u6761\u8fb9\u3002

    \n\n

    \u8001\u9f20\u4ece\u7ed3\u70b9 1 \u5f00\u59cb\u5e76\u7387\u5148\u51fa\u53d1\uff0c\u732b\u4ece\u7ed3\u70b9 2 \u5f00\u59cb\u4e14\u968f\u540e\u51fa\u53d1\uff0c\u5728\u7ed3\u70b9 0 \u5904\u6709\u4e00\u4e2a\u6d1e\u3002

    \n\n

    \u5728\u6bcf\u4e2a\u73a9\u5bb6\u7684\u56de\u5408\u4e2d\uff0c\u4ed6\u4eec\u5fc5\u987b\u6cbf\u7740\u4e0e\u4ed6\u4eec\u6240\u5728\u4f4d\u7f6e\u76f8\u543b\u5408\u7684\u56fe\u7684\u4e00\u6761\u8fb9\u79fb\u52a8\u3002\u4f8b\u5982\uff0c\u5982\u679c\u8001\u9f20\u4f4d\u4e8e\u7ed3\u70b9 1\uff0c\u90a3\u4e48\u5b83\u53ea\u80fd\u79fb\u52a8\u5230 graph[1] \u4e2d\u7684\uff08\u4efb\u4f55\uff09\u7ed3\u70b9\u53bb\u3002

    \n\n

    \u6b64\u5916\uff0c\u732b\u65e0\u6cd5\u79fb\u52a8\u5230\u6d1e\uff08\u7ed3\u70b9 0\uff09\u91cc\u3002

    \n\n

    \u7136\u540e\uff0c\u6e38\u620f\u5728\u51fa\u73b0\u4ee5\u4e0b\u4e09\u79cd\u60c5\u5f62\u4e4b\u4e00\u65f6\u7ed3\u675f\uff1a

    \n\n
      \n\t
    • \u5982\u679c\u732b\u548c\u8001\u9f20\u5360\u636e\u76f8\u540c\u7684\u7ed3\u70b9\uff0c\u732b\u83b7\u80dc\u3002
    • \n\t
    • \u5982\u679c\u8001\u9f20\u8eb2\u5165\u6d1e\u91cc\uff0c\u8001\u9f20\u83b7\u80dc\u3002
    • \n\t
    • \u5982\u679c\u67d0\u4e00\u4f4d\u7f6e\u91cd\u590d\u51fa\u73b0\uff08\u5373\uff0c\u73a9\u5bb6\u4eec\u7684\u4f4d\u7f6e\u548c\u79fb\u52a8\u987a\u5e8f\u90fd\u4e0e\u4e0a\u4e00\u4e2a\u56de\u5408\u76f8\u540c\uff09\uff0c\u6e38\u620f\u5e73\u5c40\u3002
    • \n
    \n\n

    \u7ed9\u5b9a graph\uff0c\u5e76\u5047\u8bbe\u4e24\u4e2a\u73a9\u5bb6\u90fd\u4ee5\u6700\u4f73\u72b6\u6001\u53c2\u4e0e\u6e38\u620f\uff0c\u5982\u679c\u8001\u9f20\u83b7\u80dc\uff0c\u5219\u8fd4\u56de 1\uff1b\u5982\u679c\u732b\u83b7\u80dc\uff0c\u5219\u8fd4\u56de 2\uff1b\u5982\u679c\u5e73\u5c40\uff0c\u5219\u8fd4\u56de 0\u3002

    \n\n

     

    \n\n
      \n
    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1a[[2,5],[3],[0,4,5],[1,4,5],[2,3],[0,2,3]]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\n4---3---1\n|   |\n2---5\n \\ /\n  0\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 3 <= graph.length <= 200
    2. \n\t
    3. \u4fdd\u8bc1 graph[1] \u975e\u7a7a\u3002
    4. \n\t
    5. \u4fdd\u8bc1 graph[2] \u5305\u542b\u975e\u96f6\u5143\u7d20\u3002
    6. \n
    \n", "tags_en": ["Breadth-first Search", "Minimax"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u6781\u5c0f\u5316\u6781\u5927"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int catMouseGame(vector>& graph) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int catMouseGame(int[][] graph) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def catMouseGame(self, graph):\n \"\"\"\n :type graph: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def catMouseGame(self, graph: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint catMouseGame(int** graph, int graphSize, int* graphColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CatMouseGame(int[][] graph) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} graph\n * @return {number}\n */\nvar catMouseGame = function(graph) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} graph\n# @return {Integer}\ndef cat_mouse_game(graph)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func catMouseGame(_ graph: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func catMouseGame(graph [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def catMouseGame(graph: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun catMouseGame(graph: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn cat_mouse_game(graph: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $graph\n * @return Integer\n */\n function catMouseGame($graph) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function catMouseGame(graph: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (cat-mouse-game graph)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0913](https://leetcode-cn.com/problems/cat-and-mouse)", "[\u732b\u548c\u8001\u9f20](/solution/0900-0999/0913.Cat%20and%20Mouse/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u6781\u5c0f\u5316\u6781\u5927`", "\u56f0\u96be", ""], "md_table_row_en": ["[0913](https://leetcode.com/problems/cat-and-mouse)", "[Cat and Mouse](/solution/0900-0999/0913.Cat%20and%20Mouse/README_EN.md)", "`Breadth-first Search`,`Minimax`", "Hard", ""]}, {"question_id": "0948", "frontend_question_id": "0912", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sort-an-array", "url_en": "https://leetcode.com/problems/sort-an-array", "relative_path_cn": "/solution/0900-0999/0912.Sort%20an%20Array/README.md", "relative_path_en": "/solution/0900-0999/0912.Sort%20an%20Array/README_EN.md", "title_cn": "\u6392\u5e8f\u6570\u7ec4", "title_en": "Sort an Array", "question_title_slug": "sort-an-array", "content_en": "

    Given an array of integers nums, sort the array in ascending order.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [5,2,3,1]\nOutput: [1,2,3,5]\n

    Example 2:

    \n
    Input: nums = [5,1,1,2,0,0]\nOutput: [0,0,1,1,2,5]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 5 * 104
    • \n\t
    • -5 * 104 <= nums[i] <= 5 * 104
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums\uff0c\u8bf7\u4f60\u5c06\u8be5\u6570\u7ec4\u5347\u5e8f\u6392\u5217\u3002

    \n\n

     

    \n\n
      \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [5,2,3,1]\n\u8f93\u51fa\uff1a[1,2,3,5]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [5,1,1,2,0,0]\n\u8f93\u51fa\uff1a[0,0,1,1,2,5]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= nums.length <= 50000
    2. \n\t
    3. -50000 <= nums[i] <= 50000
    4. \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector sortArray(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] sortArray(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def sortArray(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def sortArray(self, nums: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* sortArray(int* nums, int numsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] SortArray(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar sortArray = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer[]}\ndef sort_array(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func sortArray(_ nums: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func sortArray(nums []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def sortArray(nums: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun sortArray(nums: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sort_array(nums: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer[]\n */\n function sortArray($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function sortArray(nums: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (sort-array nums)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0912](https://leetcode-cn.com/problems/sort-an-array)", "[\u6392\u5e8f\u6570\u7ec4](/solution/0900-0999/0912.Sort%20an%20Array/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0912](https://leetcode.com/problems/sort-an-array)", "[Sort an Array](/solution/0900-0999/0912.Sort%20an%20Array/README_EN.md)", "", "Medium", ""]}, {"question_id": "0947", "frontend_question_id": "0911", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/online-election", "url_en": "https://leetcode.com/problems/online-election", "relative_path_cn": "/solution/0900-0999/0911.Online%20Election/README.md", "relative_path_en": "/solution/0900-0999/0911.Online%20Election/README_EN.md", "title_cn": "\u5728\u7ebf\u9009\u4e3e", "title_en": "Online Election", "question_title_slug": "online-election", "content_en": "

    In an election, the i-th vote was cast for persons[i] at time times[i].

    \r\n\r\n

    Now, we would like to implement the following query function: TopVotedCandidate.q(int t) will return the number of the person that was leading the election at time t.  

    \r\n\r\n

    Votes cast at time t will count towards our query.  In the case of a tie, the most recent vote (among tied candidates) wins.

    \r\n\r\n

     

    \r\n\r\n
    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: ["TopVotedCandidate","q","q","q","q","q","q"], [[[0,1,1,0,0,1,0],[0,5,10,15,20,25,30]],[3],[12],[25],[15],[24],[8]]\r\nOutput: [null,0,1,1,0,0,1]\r\nExplanation: \r\nAt time 3, the votes are [0], and 0 is leading.\r\nAt time 12, the votes are [0,1,1], and 1 is leading.\r\nAt time 25, the votes are [0,1,1,0,0,1], and 1 is leading (as ties go to the most recent vote.)\r\nThis continues for 3 more queries at time 15, 24, and 8.\r\n
    \r\n\r\n

     

    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    1. 1 <= persons.length = times.length <= 5000
    2. \r\n\t
    3. 0 <= persons[i] <= persons.length
    4. \r\n\t
    5. times is a strictly increasing array with all elements in [0, 10^9].
    6. \r\n\t
    7. TopVotedCandidate.q is called at most 10000 times per test case.
    8. \r\n\t
    9. TopVotedCandidate.q(int t) is always called with t >= times[0].
    10. \r\n
    \r\n
    \r\n", "content_cn": "

    \u5728\u9009\u4e3e\u4e2d\uff0c\u7b2c i \u5f20\u7968\u662f\u5728\u65f6\u95f4\u4e3a times[i] \u65f6\u6295\u7ed9 persons[i] \u7684\u3002

    \n\n

    \u73b0\u5728\uff0c\u6211\u4eec\u60f3\u8981\u5b9e\u73b0\u4e0b\u9762\u7684\u67e5\u8be2\u51fd\u6570\uff1a TopVotedCandidate.q(int t) \u5c06\u8fd4\u56de\u5728 t \u65f6\u523b\u4e3b\u5bfc\u9009\u4e3e\u7684\u5019\u9009\u4eba\u7684\u7f16\u53f7\u3002

    \n\n

    \u5728 t \u65f6\u523b\u6295\u51fa\u7684\u9009\u7968\u4e5f\u5c06\u88ab\u8ba1\u5165\u6211\u4eec\u7684\u67e5\u8be2\u4e4b\u4e2d\u3002\u5728\u5e73\u5c40\u7684\u60c5\u51b5\u4e0b\uff0c\u6700\u8fd1\u83b7\u5f97\u6295\u7968\u7684\u5019\u9009\u4eba\u5c06\u4f1a\u83b7\u80dc\u3002

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1a["TopVotedCandidate","q","q","q","q","q","q"], [[[0,1,1,0,0,1,0],[0,5,10,15,20,25,30]],[3],[12],[25],[15],[24],[8]]\n\u8f93\u51fa\uff1a[null,0,1,1,0,0,1]\n\u89e3\u91ca\uff1a\n\u65f6\u95f4\u4e3a 3\uff0c\u7968\u6570\u5206\u5e03\u60c5\u51b5\u662f [0]\uff0c\u7f16\u53f7\u4e3a 0 \u7684\u5019\u9009\u4eba\u9886\u5148\u3002\n\u65f6\u95f4\u4e3a 12\uff0c\u7968\u6570\u5206\u5e03\u60c5\u51b5\u662f [0,1,1]\uff0c\u7f16\u53f7\u4e3a 1 \u7684\u5019\u9009\u4eba\u9886\u5148\u3002\n\u65f6\u95f4\u4e3a 25\uff0c\u7968\u6570\u5206\u5e03\u60c5\u51b5\u662f [0,1,1,0,0,1]\uff0c\u7f16\u53f7\u4e3a 1 \u7684\u5019\u9009\u4eba\u9886\u5148\uff08\u56e0\u4e3a\u6700\u8fd1\u7684\u6295\u7968\u7ed3\u679c\u662f\u5e73\u5c40\uff09\u3002\n\u5728\u65f6\u95f4 15\u300124 \u548c 8 \u5904\u7ee7\u7eed\u6267\u884c 3 \u4e2a\u67e5\u8be2\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= persons.length = times.length <= 5000
    2. \n\t
    3. 0 <= persons[i] <= persons.length
    4. \n\t
    5. times \u662f\u4e25\u683c\u9012\u589e\u7684\u6570\u7ec4\uff0c\u6240\u6709\u5143\u7d20\u90fd\u5728 [0, 10^9] \u8303\u56f4\u4e2d\u3002
    6. \n\t
    7. \u6bcf\u4e2a\u6d4b\u8bd5\u7528\u4f8b\u6700\u591a\u8c03\u7528 10000 \u6b21 TopVotedCandidate.q\u3002
    8. \n\t
    9. TopVotedCandidate.q(int t) \u88ab\u8c03\u7528\u65f6\u603b\u662f\u6ee1\u8db3 t >= times[0]\u3002
    10. \n
    \n", "tags_en": ["Binary Search"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class TopVotedCandidate {\npublic:\n TopVotedCandidate(vector& persons, vector& times) {\n\n }\n \n int q(int t) {\n\n }\n};\n\n/**\n * Your TopVotedCandidate object will be instantiated and called as such:\n * TopVotedCandidate* obj = new TopVotedCandidate(persons, times);\n * int param_1 = obj->q(t);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class TopVotedCandidate {\n\n public TopVotedCandidate(int[] persons, int[] times) {\n\n }\n \n public int q(int t) {\n\n }\n}\n\n/**\n * Your TopVotedCandidate object will be instantiated and called as such:\n * TopVotedCandidate obj = new TopVotedCandidate(persons, times);\n * int param_1 = obj.q(t);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class TopVotedCandidate(object):\n\n def __init__(self, persons, times):\n \"\"\"\n :type persons: List[int]\n :type times: List[int]\n \"\"\"\n \n\n def q(self, t):\n \"\"\"\n :type t: int\n :rtype: int\n \"\"\"\n \n\n\n# Your TopVotedCandidate object will be instantiated and called as such:\n# obj = TopVotedCandidate(persons, times)\n# param_1 = obj.q(t)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class TopVotedCandidate:\n\n def __init__(self, persons: List[int], times: List[int]):\n \n\n def q(self, t: int) -> int:\n \n\n\n# Your TopVotedCandidate object will be instantiated and called as such:\n# obj = TopVotedCandidate(persons, times)\n# param_1 = obj.q(t)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} TopVotedCandidate;\n\n\nTopVotedCandidate* topVotedCandidateCreate(int* persons, int personsSize, int* times, int timesSize) {\n \n}\n\nint topVotedCandidateQ(TopVotedCandidate* obj, int t) {\n \n}\n\nvoid topVotedCandidateFree(TopVotedCandidate* obj) {\n \n}\n\n/**\n * Your TopVotedCandidate struct will be instantiated and called as such:\n * TopVotedCandidate* obj = topVotedCandidateCreate(persons, personsSize, times, timesSize);\n * int param_1 = topVotedCandidateQ(obj, t);\n \n * topVotedCandidateFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class TopVotedCandidate {\n\n public TopVotedCandidate(int[] persons, int[] times) {\n\n }\n \n public int Q(int t) {\n\n }\n}\n\n/**\n * Your TopVotedCandidate object will be instantiated and called as such:\n * TopVotedCandidate obj = new TopVotedCandidate(persons, times);\n * int param_1 = obj.Q(t);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} persons\n * @param {number[]} times\n */\nvar TopVotedCandidate = function(persons, times) {\n\n};\n\n/** \n * @param {number} t\n * @return {number}\n */\nTopVotedCandidate.prototype.q = function(t) {\n\n};\n\n/**\n * Your TopVotedCandidate object will be instantiated and called as such:\n * var obj = new TopVotedCandidate(persons, times)\n * var param_1 = obj.q(t)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class TopVotedCandidate\n\n=begin\n :type persons: Integer[]\n :type times: Integer[]\n=end\n def initialize(persons, times)\n\n end\n\n\n=begin\n :type t: Integer\n :rtype: Integer\n=end\n def q(t)\n\n end\n\n\nend\n\n# Your TopVotedCandidate object will be instantiated and called as such:\n# obj = TopVotedCandidate.new(persons, times)\n# param_1 = obj.q(t)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass TopVotedCandidate {\n\n init(_ persons: [Int], _ times: [Int]) {\n \n }\n \n func q(_ t: Int) -> Int {\n \n }\n}\n\n/**\n * Your TopVotedCandidate object will be instantiated and called as such:\n * let obj = TopVotedCandidate(persons, times)\n * let ret_1: Int = obj.q(t)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type TopVotedCandidate struct {\n\n}\n\n\nfunc Constructor(persons []int, times []int) TopVotedCandidate {\n\n}\n\n\nfunc (this *TopVotedCandidate) Q(t int) int {\n\n}\n\n\n/**\n * Your TopVotedCandidate object will be instantiated and called as such:\n * obj := Constructor(persons, times);\n * param_1 := obj.Q(t);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class TopVotedCandidate(_persons: Array[Int], _times: Array[Int]) {\n\n def q(t: Int): Int = {\n\n }\n\n}\n\n/**\n * Your TopVotedCandidate object will be instantiated and called as such:\n * var obj = new TopVotedCandidate(persons, times)\n * var param_1 = obj.q(t)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class TopVotedCandidate(persons: IntArray, times: IntArray) {\n\n fun q(t: Int): Int {\n\n }\n\n}\n\n/**\n * Your TopVotedCandidate object will be instantiated and called as such:\n * var obj = TopVotedCandidate(persons, times)\n * var param_1 = obj.q(t)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct TopVotedCandidate {\n\n}\n\n\n/** \n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl TopVotedCandidate {\n\n fn new(persons: Vec, times: Vec) -> Self {\n \n }\n \n fn q(&self, t: i32) -> i32 {\n \n }\n}\n\n/**\n * Your TopVotedCandidate object will be instantiated and called as such:\n * let obj = TopVotedCandidate::new(persons, times);\n * let ret_1: i32 = obj.q(t);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class TopVotedCandidate {\n /**\n * @param Integer[] $persons\n * @param Integer[] $times\n */\n function __construct($persons, $times) {\n \n }\n \n /**\n * @param Integer $t\n * @return Integer\n */\n function q($t) {\n \n }\n}\n\n/**\n * Your TopVotedCandidate object will be instantiated and called as such:\n * $obj = TopVotedCandidate($persons, $times);\n * $ret_1 = $obj->q($t);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class TopVotedCandidate {\n constructor(persons: number[], times: number[]) {\n\n }\n\n q(t: number): number {\n\n }\n}\n\n/**\n * Your TopVotedCandidate object will be instantiated and called as such:\n * var obj = new TopVotedCandidate(persons, times)\n * var param_1 = obj.q(t)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define top-voted-candidate%\n (class object%\n (super-new)\n\n ; persons : (listof exact-integer?)\n\n ; times : (listof exact-integer?)\n (init-field\n persons\n times)\n \n ; q : exact-integer? -> exact-integer?\n (define/public (q t)\n\n )))\n\n;; Your top-voted-candidate% object will be instantiated and called as such:\n;; (define obj (new top-voted-candidate% [persons persons] [times times]))\n;; (define param_1 (send obj q t))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0911](https://leetcode-cn.com/problems/online-election)", "[\u5728\u7ebf\u9009\u4e3e](/solution/0900-0999/0911.Online%20Election/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0911](https://leetcode.com/problems/online-election)", "[Online Election](/solution/0900-0999/0911.Online%20Election/README_EN.md)", "`Binary Search`", "Medium", ""]}, {"question_id": "0946", "frontend_question_id": "0910", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/smallest-range-ii", "url_en": "https://leetcode.com/problems/smallest-range-ii", "relative_path_cn": "/solution/0900-0999/0910.Smallest%20Range%20II/README.md", "relative_path_en": "/solution/0900-0999/0910.Smallest%20Range%20II/README_EN.md", "title_cn": "\u6700\u5c0f\u5dee\u503c II", "title_en": "Smallest Range II", "question_title_slug": "smallest-range-ii", "content_en": "

    Given an array nums of integers, for each integer nums[i] we need to choose either x = -k or x = k, and add x to nums[i] (only once).

    \n\n

    After this process, we have some array result.

    \n\n

    Return the smallest possible difference between the maximum value of result and the minimum value of result.

    \n\n

     

    \n\n
      \n
    \n\n
    \n

    Example 1:

    \n\n
    \nInput: nums = [1], k = 0\nOutput: 0\nExplanation: result = [1]\n
    \n\n
    \n

    Example 2:

    \n\n
    \nInput: nums = [0,10], k = 2\nOutput: 6\nExplanation: result = [2,8]\n
    \n\n
    \n

    Example 3:

    \n\n
    \nInput: nums = [1,3,6], k = 3\nOutput: 3\nExplanation: result = [4,6,3]\n
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    1. 1 <= nums.length <= 10000
    2. \n\t
    3. 0 <= nums[i] <= 10000
    4. \n\t
    5. 0 <= k <= 10000
    6. \n
    \n
    \n
    \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 A\uff0c\u5bf9\u4e8e\u6bcf\u4e2a\u6574\u6570 A[i]\uff0c\u53ef\u4ee5\u9009\u62e9\u00a0x = -K\u00a0\u6216\u662f\u00a0x = K \uff08K \u603b\u662f\u975e\u8d1f\u6574\u6570\uff09\uff0c\u5e76\u5c06\u00a0x\u00a0\u52a0\u5230\u00a0A[i]\u00a0\u4e2d\u3002

    \n\n

    \u5728\u6b64\u8fc7\u7a0b\u4e4b\u540e\uff0c\u5f97\u5230\u6570\u7ec4\u00a0B\u3002

    \n\n

    \u8fd4\u56de B\u00a0\u7684\u6700\u5927\u503c\u548c B\u00a0\u7684\u6700\u5c0f\u503c\u4e4b\u95f4\u53ef\u80fd\u5b58\u5728\u7684\u6700\u5c0f\u5dee\u503c\u3002

    \n\n

    \u00a0

    \n\n
      \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aA = [1], K = 0\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1aB = [1]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aA = [0,10], K = 2\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1aB = [2,8]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aA = [1,3,6], K = 3\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1aB = [4,6,3]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= A.length <= 10000
    • \n\t
    • 0 <= A[i] <= 10000
    • \n\t
    • 0 <= K <= 10000
    • \n
    \n", "tags_en": ["Greedy", "Math"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int smallestRangeII(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int smallestRangeII(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def smallestRangeII(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def smallestRangeII(self, nums: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint smallestRangeII(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SmallestRangeII(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar smallestRangeII = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef smallest_range_ii(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func smallestRangeII(_ nums: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func smallestRangeII(nums []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def smallestRangeII(nums: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun smallestRangeII(nums: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn smallest_range_ii(nums: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer\n */\n function smallestRangeII($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function smallestRangeII(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (smallest-range-ii nums k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0910](https://leetcode-cn.com/problems/smallest-range-ii)", "[\u6700\u5c0f\u5dee\u503c II](/solution/0900-0999/0910.Smallest%20Range%20II/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0910](https://leetcode.com/problems/smallest-range-ii)", "[Smallest Range II](/solution/0900-0999/0910.Smallest%20Range%20II/README_EN.md)", "`Greedy`,`Math`", "Medium", ""]}, {"question_id": "0945", "frontend_question_id": "0909", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/snakes-and-ladders", "url_en": "https://leetcode.com/problems/snakes-and-ladders", "relative_path_cn": "/solution/0900-0999/0909.Snakes%20and%20Ladders/README.md", "relative_path_en": "/solution/0900-0999/0909.Snakes%20and%20Ladders/README_EN.md", "title_cn": "\u86c7\u68af\u68cb", "title_en": "Snakes and Ladders", "question_title_slug": "snakes-and-ladders", "content_en": "

    On an N x N board, the numbers from 1 to N*N are written boustrophedonically starting from the bottom left of the board, and alternating direction each row.  For example, for a 6 x 6 board, the numbers are written as follows:

    \r\n\r\n
    \r\n\"\"\r\n
    \r\n\r\n

    You start on square 1 of the board (which is always in the last row and first column).  Each move, starting from square x, consists of the following:

    \r\n\r\n
      \r\n\t
    • You choose a destination square S with number x+1, x+2, x+3, x+4, x+5, or x+6, provided this number is <= N*N.\r\n\r\n\t
        \r\n\t\t
      • (This choice simulates the result of a standard 6-sided die roll: ie., there are always at most 6 destinations, regardless of the size of the board.)
      • \r\n\t
      \r\n\t
    • \r\n\t
    • If S has a snake or ladder, you move to the destination of that snake or ladder.  Otherwise, you move to S.
    • \r\n
    \r\n\r\n

    A board square on row r and column c has a "snake or ladder" if board[r][c] != -1.  The destination of that snake or ladder is board[r][c].

    \r\n\r\n

    Note that you only take a snake or ladder at most once per move: if the destination to a snake or ladder is the start of another snake or ladder, you do not continue moving.  (For example, if the board is `[[4,-1],[-1,3]]`, and on the first move your destination square is `2`, then you finish your first move at `3`, because you do not continue moving to `4`.)

    \r\n\r\n

    Return the least number of moves required to reach square N*N.  If it is not possible, return -1.

    \r\n\r\n

    Example 1:

    \r\n\r\n
    \r\nInput: [\r\n[-1,-1,-1,-1,-1,-1],\r\n[-1,-1,-1,-1,-1,-1],\r\n[-1,-1,-1,-1,-1,-1],\r\n[-1,35,-1,-1,13,-1],\r\n[-1,-1,-1,-1,-1,-1],\r\n[-1,15,-1,-1,-1,-1]]\r\nOutput: 4\r\nExplanation: \r\nAt the beginning, you start at square 1 [at row 5, column 0].\r\nYou decide to move to square 2, and must take the ladder to square 15.\r\nYou then decide to move to square 17 (row 3, column 5), and must take the snake to square 13.\r\nYou then decide to move to square 14, and must take the ladder to square 35.\r\nYou then decide to move to square 36, ending the game.\r\nIt can be shown that you need at least 4 moves to reach the N*N-th square, so the answer is 4.\r\n
    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    1. 2 <= board.length = board[0].length <= 20
    2. \r\n\t
    3. board[i][j] is between 1 and N*N or is equal to -1.
    4. \r\n\t
    5. The board square with number 1 has no snake or ladder.
    6. \r\n\t
    7. The board square with number N*N has no snake or ladder.
    8. \r\n
    \r\n", "content_cn": "

    N x N \u7684\u68cb\u76d8 board \u4e0a\uff0c\u6309\u4ece 1 \u5230 N*N \u7684\u6570\u5b57\u7ed9\u65b9\u683c\u7f16\u53f7\uff0c\u7f16\u53f7 \u4ece\u5de6\u4e0b\u89d2\u5f00\u59cb\uff0c\u6bcf\u4e00\u884c\u4ea4\u66ff\u65b9\u5411\u3002

    \n\n

    \u4f8b\u5982\uff0c\u4e00\u5757 6 x 6 \u5927\u5c0f\u7684\u68cb\u76d8\uff0c\u7f16\u53f7\u5982\u4e0b\uff1a

    \n\n
    \"\"\n
    \n\n

    r \u884c c \u5217\u7684\u68cb\u76d8\uff0c\u6309\u524d\u8ff0\u65b9\u6cd5\u7f16\u53f7\uff0c\u68cb\u76d8\u683c\u4e2d\u53ef\u80fd\u5b58\u5728 “\u86c7” \u6216 “\u68af\u5b50”\uff1b\u5982\u679c board[r][c] != -1\uff0c\u90a3\u4e2a\u86c7\u6216\u68af\u5b50\u7684\u76ee\u7684\u5730\u5c06\u4f1a\u662f board[r][c]\u3002

    \n\n

    \u73a9\u5bb6\u4ece\u68cb\u76d8\u4e0a\u7684\u65b9\u683c 1 \uff08\u603b\u662f\u5728\u6700\u540e\u4e00\u884c\u3001\u7b2c\u4e00\u5217\uff09\u5f00\u59cb\u51fa\u53d1\u3002

    \n\n

    \u6bcf\u4e00\u56de\u5408\uff0c\u73a9\u5bb6\u9700\u8981\u4ece\u5f53\u524d\u65b9\u683c x \u5f00\u59cb\u51fa\u53d1\uff0c\u6309\u4e0b\u8ff0\u8981\u6c42\u524d\u8fdb\uff1a

    \n\n
      \n\t
    • \u9009\u5b9a\u76ee\u6807\u65b9\u683c\uff1a\u9009\u62e9\u4ece\u7f16\u53f7 x+1\uff0cx+2\uff0cx+3\uff0cx+4\uff0cx+5\uff0c\u6216\u8005 x+6 \u7684\u65b9\u683c\u4e2d\u9009\u51fa\u4e00\u4e2a\u76ee\u6807\u65b9\u683c s \uff0c\u76ee\u6807\u65b9\u683c\u7684\u7f16\u53f7 <= N*N\u3002\n\n\t
        \n\t\t
      • \u8be5\u9009\u62e9\u6a21\u62df\u4e86\u63b7\u9ab0\u5b50\u7684\u60c5\u666f\uff0c\u65e0\u8bba\u68cb\u76d8\u5927\u5c0f\u5982\u4f55\uff0c\u4f60\u7684\u76ee\u7684\u5730\u8303\u56f4\u4e5f\u53ea\u80fd\u5904\u4e8e\u533a\u95f4 [x+1, x+6] \u4e4b\u95f4\u3002
      • \n\t
      \n\t
    • \n\t
    • \u4f20\u9001\u73a9\u5bb6\uff1a\u5982\u679c\u76ee\u6807\u65b9\u683c S \u5904\u5b58\u5728\u86c7\u6216\u68af\u5b50\uff0c\u90a3\u4e48\u73a9\u5bb6\u4f1a\u4f20\u9001\u5230\u86c7\u6216\u68af\u5b50\u7684\u76ee\u7684\u5730\u3002\u5426\u5219\uff0c\u73a9\u5bb6\u4f20\u9001\u5230\u76ee\u6807\u65b9\u683c S\u3002 
    • \n
    \n\n

    \u6ce8\u610f\uff0c\u73a9\u5bb6\u5728\u6bcf\u56de\u5408\u7684\u524d\u8fdb\u8fc7\u7a0b\u4e2d\u6700\u591a\u53ea\u80fd\u722c\u8fc7\u86c7\u6216\u68af\u5b50\u4e00\u6b21\uff1a\u5c31\u7b97\u76ee\u7684\u5730\u662f\u53e6\u4e00\u6761\u86c7\u6216\u68af\u5b50\u7684\u8d77\u70b9\uff0c\u4f60\u4e5f\u4e0d\u4f1a\u7ee7\u7eed\u79fb\u52a8\u3002

    \n\n

    \u8fd4\u56de\u8fbe\u5230\u65b9\u683c N*N \u6240\u9700\u7684\u6700\u5c11\u79fb\u52a8\u6b21\u6570\uff0c\u5982\u679c\u4e0d\u53ef\u80fd\uff0c\u5219\u8fd4\u56de -1\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1a[\n[-1,-1,-1,-1,-1,-1],\n[-1,-1,-1,-1,-1,-1],\n[-1,-1,-1,-1,-1,-1],\n[-1,35,-1,-1,13,-1],\n[-1,-1,-1,-1,-1,-1],\n[-1,15,-1,-1,-1,-1]]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\n\u9996\u5148\uff0c\u4ece\u65b9\u683c 1 [\u7b2c 5 \u884c\uff0c\u7b2c 0 \u5217] \u5f00\u59cb\u3002\n\u4f60\u51b3\u5b9a\u79fb\u52a8\u5230\u65b9\u683c 2\uff0c\u5e76\u5fc5\u987b\u722c\u8fc7\u68af\u5b50\u79fb\u52a8\u5230\u5230\u65b9\u683c 15\u3002\n\u7136\u540e\u4f60\u51b3\u5b9a\u79fb\u52a8\u5230\u65b9\u683c 17 [\u7b2c 3 \u884c\uff0c\u7b2c 5 \u5217]\uff0c\u5fc5\u987b\u722c\u8fc7\u86c7\u5230\u65b9\u683c 13\u3002\n\u7136\u540e\u4f60\u51b3\u5b9a\u79fb\u52a8\u5230\u65b9\u683c 14\uff0c\u4e14\u5fc5\u987b\u901a\u8fc7\u68af\u5b50\u79fb\u52a8\u5230\u65b9\u683c 35\u3002\n\u7136\u540e\u4f60\u51b3\u5b9a\u79fb\u52a8\u5230\u65b9\u683c 36, \u6e38\u620f\u7ed3\u675f\u3002\n\u53ef\u4ee5\u8bc1\u660e\u4f60\u9700\u8981\u81f3\u5c11 4 \u6b21\u79fb\u52a8\u624d\u80fd\u5230\u8fbe\u7b2c N*N \u4e2a\u65b9\u683c\uff0c\u6240\u4ee5\u7b54\u6848\u662f 4\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= board.length = board[0].length <= 20
    • \n\t
    • board[i][j] \u4ecb\u4e8e 1 \u548c N*N \u4e4b\u95f4\u6216\u8005\u7b49\u4e8e -1\u3002
    • \n\t
    • \u7f16\u53f7\u4e3a 1 \u7684\u65b9\u683c\u4e0a\u6ca1\u6709\u86c7\u6216\u68af\u5b50\u3002
    • \n\t
    • \u7f16\u53f7\u4e3a N*N \u7684\u65b9\u683c\u4e0a\u6ca1\u6709\u86c7\u6216\u68af\u5b50\u3002
    • \n
    \n", "tags_en": ["Breadth-first Search"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int snakesAndLadders(vector>& board) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int snakesAndLadders(int[][] board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def snakesAndLadders(self, board):\n \"\"\"\n :type board: List[List[int]]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def snakesAndLadders(self, board: List[List[int]]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint snakesAndLadders(int** board, int boardSize, int* boardColSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SnakesAndLadders(int[][] board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} board\n * @return {number}\n */\nvar snakesAndLadders = function(board) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} board\n# @return {Integer}\ndef snakes_and_ladders(board)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func snakesAndLadders(_ board: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func snakesAndLadders(board [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def snakesAndLadders(board: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun snakesAndLadders(board: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn snakes_and_ladders(board: Vec>) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $board\n * @return Integer\n */\n function snakesAndLadders($board) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function snakesAndLadders(board: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (snakes-and-ladders board)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0909](https://leetcode-cn.com/problems/snakes-and-ladders)", "[\u86c7\u68af\u68cb](/solution/0900-0999/0909.Snakes%20and%20Ladders/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0909](https://leetcode.com/problems/snakes-and-ladders)", "[Snakes and Ladders](/solution/0900-0999/0909.Snakes%20and%20Ladders/README_EN.md)", "`Breadth-first Search`", "Medium", ""]}, {"question_id": "0944", "frontend_question_id": "0908", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/smallest-range-i", "url_en": "https://leetcode.com/problems/smallest-range-i", "relative_path_cn": "/solution/0900-0999/0908.Smallest%20Range%20I/README.md", "relative_path_en": "/solution/0900-0999/0908.Smallest%20Range%20I/README_EN.md", "title_cn": "\u6700\u5c0f\u5dee\u503c I", "title_en": "Smallest Range I", "question_title_slug": "smallest-range-i", "content_en": "

    Given an array nums of integers, for each integer nums[i] we may choose any x with -k <= x <= k, and add x to nums[i].

    \n\n

    After this process, we have some array result.

    \n\n

    Return the smallest possible difference between the maximum value of result and the minimum value of result.

    \n\n

     

    \n\n
      \n
    \n\n
    \n

    Example 1:

    \n\n
    \nInput: nums = [1], k = 0\nOutput: 0\nExplanation: result = [1]\n
    \n\n
    \n

    Example 2:

    \n\n
    \nInput: nums = [0,10], k = 2\nOutput: 6\nExplanation: result = [2,8]\n
    \n\n
    \n

    Example 3:

    \n\n
    \nInput: nums = [1,3,6], k = 3\nOutput: 0\nExplanation: result = [3,3,3] or result = [4,4,4]\n
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    1. 1 <= nums.length <= 10000
    2. \n\t
    3. 0 <= nums[i] <= 10000
    4. \n\t
    5. 0 <= k <= 10000
    6. \n
    \n
    \n
    \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 A\uff0c\u8bf7\u4f60\u7ed9\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20 A[i] \u90fd\u52a0\u4e0a\u4e00\u4e2a\u4efb\u610f\u6570\u5b57 x \uff08-K <= x <= K\uff09\uff0c\u4ece\u800c\u5f97\u5230\u4e00\u4e2a\u65b0\u6570\u7ec4 B \u3002

    \n\n

    \u8fd4\u56de\u6570\u7ec4 B \u7684\u6700\u5927\u503c\u548c\u6700\u5c0f\u503c\u4e4b\u95f4\u53ef\u80fd\u5b58\u5728\u7684\u6700\u5c0f\u5dee\u503c\u3002

    \n\n

     

    \n\n
      \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aA = [1], K = 0\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1aB = [1]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aA = [0,10], K = 2\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1aB = [2,8]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aA = [1,3,6], K = 3\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1aB = [3,3,3] \u6216 B = [4,4,4]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= A.length <= 10000
    2. \n\t
    3. 0 <= A[i] <= 10000
    4. \n\t
    5. 0 <= K <= 10000
    6. \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int smallestRangeI(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int smallestRangeI(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def smallestRangeI(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def smallestRangeI(self, nums: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint smallestRangeI(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SmallestRangeI(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar smallestRangeI = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef smallest_range_i(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func smallestRangeI(_ nums: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func smallestRangeI(nums []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def smallestRangeI(nums: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun smallestRangeI(nums: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn smallest_range_i(nums: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer\n */\n function smallestRangeI($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function smallestRangeI(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (smallest-range-i nums k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0908](https://leetcode-cn.com/problems/smallest-range-i)", "[\u6700\u5c0f\u5dee\u503c I](/solution/0900-0999/0908.Smallest%20Range%20I/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0908](https://leetcode.com/problems/smallest-range-i)", "[Smallest Range I](/solution/0900-0999/0908.Smallest%20Range%20I/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "0943", "frontend_question_id": "0907", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sum-of-subarray-minimums", "url_en": "https://leetcode.com/problems/sum-of-subarray-minimums", "relative_path_cn": "/solution/0900-0999/0907.Sum%20of%20Subarray%20Minimums/README.md", "relative_path_en": "/solution/0900-0999/0907.Sum%20of%20Subarray%20Minimums/README_EN.md", "title_cn": "\u5b50\u6570\u7ec4\u7684\u6700\u5c0f\u503c\u4e4b\u548c", "title_en": "Sum of Subarray Minimums", "question_title_slug": "sum-of-subarray-minimums", "content_en": "

    Given an array of integers arr, find the sum of min(b), where b ranges over every (contiguous) subarray of arr. Since the answer may be large, return the answer modulo 109 + 7.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr = [3,1,2,4]\nOutput: 17\nExplanation: \nSubarrays are [3], [1], [2], [4], [3,1], [1,2], [2,4], [3,1,2], [1,2,4], [3,1,2,4]. \nMinimums are 3, 1, 2, 4, 1, 1, 2, 1, 1, 1.\nSum is 17.\n
    \n\n

    Example 2:

    \n\n
    \nInput: arr = [11,81,94,43,3]\nOutput: 444\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= arr.length <= 3 * 104
    • \n\t
    • 1 <= arr[i] <= 3 * 104
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 arr\uff0c\u627e\u5230 min(b)\u00a0\u7684\u603b\u548c\uff0c\u5176\u4e2d b \u7684\u8303\u56f4\u4e3a arr \u7684\u6bcf\u4e2a\uff08\u8fde\u7eed\uff09\u5b50\u6570\u7ec4\u3002

    \n\n

    \u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u5f88\u5927\uff0c\u56e0\u6b64 \u8fd4\u56de\u7b54\u6848\u6a21 10^9 + 7 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [3,1,2,4]\n\u8f93\u51fa\uff1a17\n\u89e3\u91ca\uff1a\n\u5b50\u6570\u7ec4\u4e3a [3]\uff0c[1]\uff0c[2]\uff0c[4]\uff0c[3,1]\uff0c[1,2]\uff0c[2,4]\uff0c[3,1,2]\uff0c[1,2,4]\uff0c[3,1,2,4]\u3002 \n\u6700\u5c0f\u503c\u4e3a 3\uff0c1\uff0c2\uff0c4\uff0c1\uff0c1\uff0c2\uff0c1\uff0c1\uff0c1\uff0c\u548c\u4e3a 17\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [11,81,94,43,3]\n\u8f93\u51fa\uff1a444\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= arr.length <= 3 * 104
    • \n\t
    • 1 <= arr[i] <= 3 * 104
    • \n
    \n\n

    \u00a0

    \n", "tags_en": ["Stack", "Array"], "tags_cn": ["\u6808", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int sumSubarrayMins(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int sumSubarrayMins(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def sumSubarrayMins(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def sumSubarrayMins(self, arr: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint sumSubarrayMins(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SumSubarrayMins(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar sumSubarrayMins = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef sum_subarray_mins(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func sumSubarrayMins(_ arr: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func sumSubarrayMins(arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def sumSubarrayMins(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun sumSubarrayMins(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sum_subarray_mins(arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function sumSubarrayMins($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function sumSubarrayMins(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (sum-subarray-mins arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0907](https://leetcode-cn.com/problems/sum-of-subarray-minimums)", "[\u5b50\u6570\u7ec4\u7684\u6700\u5c0f\u503c\u4e4b\u548c](/solution/0900-0999/0907.Sum%20of%20Subarray%20Minimums/README.md)", "`\u6808`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0907](https://leetcode.com/problems/sum-of-subarray-minimums)", "[Sum of Subarray Minimums](/solution/0900-0999/0907.Sum%20of%20Subarray%20Minimums/README_EN.md)", "`Stack`,`Array`", "Medium", ""]}, {"question_id": "0942", "frontend_question_id": "0906", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/super-palindromes", "url_en": "https://leetcode.com/problems/super-palindromes", "relative_path_cn": "/solution/0900-0999/0906.Super%20Palindromes/README.md", "relative_path_en": "/solution/0900-0999/0906.Super%20Palindromes/README_EN.md", "title_cn": "\u8d85\u7ea7\u56de\u6587\u6570", "title_en": "Super Palindromes", "question_title_slug": "super-palindromes", "content_en": "

    Let's say a positive integer is a super-palindrome if it is a palindrome, and it is also the square of a palindrome.

    \n\n

    Given two positive integers left and right represented as strings, return the number of super-palindromes integers in the inclusive range [left, right].

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: left = "4", right = "1000"\nOutput: 4\nExplanation: 4, 9, 121, and 484 are superpalindromes.\nNote that 676 is not a superpalindrome: 26 * 26 = 676, but 26 is not a palindrome.\n
    \n\n

    Example 2:

    \n\n
    \nInput: left = "1", right = "2"\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= left.length, right.length <= 18
    • \n\t
    • left and right consist of only digits.
    • \n\t
    • left and right cannot have leading zeros.
    • \n\t
    • left and right represent integers in the range [1, 1018 - 1].
    • \n\t
    • left is less than or equal to right.
    • \n
    \n", "content_cn": "

    \u5982\u679c\u4e00\u4e2a\u6b63\u6574\u6570\u81ea\u8eab\u662f\u56de\u6587\u6570\uff0c\u800c\u4e14\u5b83\u4e5f\u662f\u4e00\u4e2a\u56de\u6587\u6570\u7684\u5e73\u65b9\uff0c\u90a3\u4e48\u6211\u4eec\u79f0\u8fd9\u4e2a\u6570\u4e3a\u8d85\u7ea7\u56de\u6587\u6570\u3002

    \n\n

    \u73b0\u5728\uff0c\u7ed9\u5b9a\u4e24\u4e2a\u6b63\u6574\u6570 L \u548c R \uff08\u4ee5\u5b57\u7b26\u4e32\u5f62\u5f0f\u8868\u793a\uff09\uff0c\u8fd4\u56de\u5305\u542b\u5728\u8303\u56f4 [L, R] \u4e2d\u7684\u8d85\u7ea7\u56de\u6587\u6570\u7684\u6570\u76ee\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1aL = "4", R = "1000"\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\n4\uff0c9\uff0c121\uff0c\u4ee5\u53ca 484 \u662f\u8d85\u7ea7\u56de\u6587\u6570\u3002\n\u6ce8\u610f 676 \u4e0d\u662f\u4e00\u4e2a\u8d85\u7ea7\u56de\u6587\u6570\uff1a 26 * 26 = 676\uff0c\u4f46\u662f 26 \u4e0d\u662f\u56de\u6587\u6570\u3002
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= len(L) <= 18
    2. \n\t
    3. 1 <= len(R) <= 18
    4. \n\t
    5. L \u548c R \u662f\u8868\u793a [1, 10^18) \u8303\u56f4\u7684\u6574\u6570\u7684\u5b57\u7b26\u4e32\u3002
    6. \n\t
    7. int(L) <= int(R)
    8. \n
    \n\n

     

    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int superpalindromesInRange(string left, string right) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int superpalindromesInRange(String left, String right) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def superpalindromesInRange(self, left, right):\n \"\"\"\n :type left: str\n :type right: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def superpalindromesInRange(self, left: str, right: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint superpalindromesInRange(char * left, char * right){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SuperpalindromesInRange(string left, string right) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} left\n * @param {string} right\n * @return {number}\n */\nvar superpalindromesInRange = function(left, right) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} left\n# @param {String} right\n# @return {Integer}\ndef superpalindromes_in_range(left, right)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func superpalindromesInRange(_ left: String, _ right: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func superpalindromesInRange(left string, right string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def superpalindromesInRange(left: String, right: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun superpalindromesInRange(left: String, right: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn superpalindromes_in_range(left: String, right: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $left\n * @param String $right\n * @return Integer\n */\n function superpalindromesInRange($left, $right) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function superpalindromesInRange(left: string, right: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (superpalindromes-in-range left right)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0906](https://leetcode-cn.com/problems/super-palindromes)", "[\u8d85\u7ea7\u56de\u6587\u6570](/solution/0900-0999/0906.Super%20Palindromes/README.md)", "`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[0906](https://leetcode.com/problems/super-palindromes)", "[Super Palindromes](/solution/0900-0999/0906.Super%20Palindromes/README_EN.md)", "`Math`", "Hard", ""]}, {"question_id": "0941", "frontend_question_id": "0905", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sort-array-by-parity", "url_en": "https://leetcode.com/problems/sort-array-by-parity", "relative_path_cn": "/solution/0900-0999/0905.Sort%20Array%20By%20Parity/README.md", "relative_path_en": "/solution/0900-0999/0905.Sort%20Array%20By%20Parity/README_EN.md", "title_cn": "\u6309\u5947\u5076\u6392\u5e8f\u6570\u7ec4", "title_en": "Sort Array By Parity", "question_title_slug": "sort-array-by-parity", "content_en": "

    Given an array nums of non-negative integers, return an array consisting of all the even elements of nums, followed by all the odd elements of nums.

    \n\n

    You may return any answer array that satisfies this condition.

    \n\n

     

    \n\n
    \n

    Example 1:

    \n\n
    \nInput: nums = [3,1,2,4]\nOutput: [2,4,3,1]\nThe outputs [4,2,3,1], [2,4,1,3], and [4,2,1,3] would also be accepted.\n
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    1. 1 <= nums.length <= 5000
    2. \n\t
    3. 0 <= nums[i] <= 5000
    4. \n
    \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\u6570\u7ec4 A\uff0c\u8fd4\u56de\u4e00\u4e2a\u6570\u7ec4\uff0c\u5728\u8be5\u6570\u7ec4\u4e2d\uff0c A \u7684\u6240\u6709\u5076\u6570\u5143\u7d20\u4e4b\u540e\u8ddf\u7740\u6240\u6709\u5947\u6570\u5143\u7d20\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u8fd4\u56de\u6ee1\u8db3\u6b64\u6761\u4ef6\u7684\u4efb\u4f55\u6570\u7ec4\u4f5c\u4e3a\u7b54\u6848\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1a[3,1,2,4]\n\u8f93\u51fa\uff1a[2,4,3,1]\n\u8f93\u51fa [4,2,3,1]\uff0c[2,4,1,3] \u548c [4,2,1,3] \u4e5f\u4f1a\u88ab\u63a5\u53d7\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= A.length <= 5000
    2. \n\t
    3. 0 <= A[i] <= 5000
    4. \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector sortArrayByParity(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] sortArrayByParity(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def sortArrayByParity(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def sortArrayByParity(self, nums: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* sortArrayByParity(int* nums, int numsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] SortArrayByParity(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar sortArrayByParity = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer[]}\ndef sort_array_by_parity(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func sortArrayByParity(_ nums: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func sortArrayByParity(nums []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def sortArrayByParity(nums: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun sortArrayByParity(nums: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sort_array_by_parity(nums: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer[]\n */\n function sortArrayByParity($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function sortArrayByParity(nums: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (sort-array-by-parity nums)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0905](https://leetcode-cn.com/problems/sort-array-by-parity)", "[\u6309\u5947\u5076\u6392\u5e8f\u6570\u7ec4](/solution/0900-0999/0905.Sort%20Array%20By%20Parity/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0905](https://leetcode.com/problems/sort-array-by-parity)", "[Sort Array By Parity](/solution/0900-0999/0905.Sort%20Array%20By%20Parity/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0940", "frontend_question_id": "0904", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/fruit-into-baskets", "url_en": "https://leetcode.com/problems/fruit-into-baskets", "relative_path_cn": "/solution/0900-0999/0904.Fruit%20Into%20Baskets/README.md", "relative_path_en": "/solution/0900-0999/0904.Fruit%20Into%20Baskets/README_EN.md", "title_cn": "\u6c34\u679c\u6210\u7bee", "title_en": "Fruit Into Baskets", "question_title_slug": "fruit-into-baskets", "content_en": "

    In a row of trees, the i-th tree produces fruit with type tree[i].

    \r\n\r\n

    You start at any tree of your choice, then repeatedly perform the following steps:

    \r\n\r\n
      \r\n\t
    1. Add one piece of fruit from this tree to your baskets.  If you cannot, stop.
    2. \r\n\t
    3. Move to the next tree to the right of the current tree.  If there is no tree to the right, stop.
    4. \r\n
    \r\n\r\n

    Note that you do not have any choice after the initial choice of starting tree: you must perform step 1, then step 2, then back to step 1, then step 2, and so on until you stop.

    \r\n\r\n

    You have two baskets, and each basket can carry any quantity of fruit, but you want each basket to only carry one type of fruit each.

    \r\n\r\n

    What is the total amount of fruit you can collect with this procedure?

    \r\n\r\n

     

    \r\n\r\n

    Example 1:

    \r\n\r\n
    \r\nInput: [1,2,1]\r\nOutput: 3\r\nExplanation: We can collect [1,2,1].\r\n
    \r\n\r\n
    \r\n

    Example 2:

    \r\n\r\n
    \r\nInput: [0,1,2,2]\r\nOutput: 3\r\nExplanation: We can collect [1,2,2].\r\nIf we started at the first tree, we would only collect [0, 1].\r\n
    \r\n\r\n
    \r\n

    Example 3:

    \r\n\r\n
    \r\nInput: [1,2,3,2,2]\r\nOutput: 4\r\nExplanation: We can collect [2,3,2,2].\r\nIf we started at the first tree, we would only collect [1, 2].\r\n
    \r\n\r\n
    \r\n

    Example 4:

    \r\n\r\n
    \r\nInput: [3,3,3,1,2,1,1,2,3,3,4]\r\nOutput: 5\r\nExplanation: We can collect [1,2,1,1,2].\r\nIf we started at the first tree or the eighth tree, we would only collect 4 fruits.\r\n
    \r\n\r\n

     

    \r\n
    \r\n
    \r\n
    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    1. 1 <= tree.length <= 40000
    2. \r\n\t
    3. 0 <= tree[i] < tree.length
    4. \r\n
    \r\n", "content_cn": "

    \u5728\u4e00\u6392\u6811\u4e2d\uff0c\u7b2c i \u68f5\u6811\u4ea7\u751f tree[i] \u578b\u7684\u6c34\u679c\u3002
    \n\u4f60\u53ef\u4ee5\u4ece\u4f60\u9009\u62e9\u7684\u4efb\u4f55\u6811\u5f00\u59cb\uff0c\u7136\u540e\u91cd\u590d\u6267\u884c\u4ee5\u4e0b\u6b65\u9aa4\uff1a

    \n\n
      \n\t
    1. \u628a\u8fd9\u68f5\u6811\u4e0a\u7684\u6c34\u679c\u653e\u8fdb\u4f60\u7684\u7bee\u5b50\u91cc\u3002\u5982\u679c\u4f60\u505a\u4e0d\u5230\uff0c\u5c31\u505c\u4e0b\u6765\u3002
    2. \n\t
    3. \u79fb\u52a8\u5230\u5f53\u524d\u6811\u53f3\u4fa7\u7684\u4e0b\u4e00\u68f5\u6811\u3002\u5982\u679c\u53f3\u8fb9\u6ca1\u6709\u6811\uff0c\u5c31\u505c\u4e0b\u6765\u3002
    4. \n
    \n\n

    \u8bf7\u6ce8\u610f\uff0c\u5728\u9009\u62e9\u4e00\u9897\u6811\u540e\uff0c\u4f60\u6ca1\u6709\u4efb\u4f55\u9009\u62e9\uff1a\u4f60\u5fc5\u987b\u6267\u884c\u6b65\u9aa4 1\uff0c\u7136\u540e\u6267\u884c\u6b65\u9aa4 2\uff0c\u7136\u540e\u8fd4\u56de\u6b65\u9aa4 1\uff0c\u7136\u540e\u6267\u884c\u6b65\u9aa4 2\uff0c\u4f9d\u6b64\u7c7b\u63a8\uff0c\u76f4\u81f3\u505c\u6b62\u3002

    \n\n

    \u4f60\u6709\u4e24\u4e2a\u7bee\u5b50\uff0c\u6bcf\u4e2a\u7bee\u5b50\u53ef\u4ee5\u643a\u5e26\u4efb\u4f55\u6570\u91cf\u7684\u6c34\u679c\uff0c\u4f46\u4f60\u5e0c\u671b\u6bcf\u4e2a\u7bee\u5b50\u53ea\u643a\u5e26\u4e00\u79cd\u7c7b\u578b\u7684\u6c34\u679c\u3002

    \n\n

    \u7528\u8fd9\u4e2a\u7a0b\u5e8f\u4f60\u80fd\u6536\u96c6\u7684\u6c34\u679c\u6811\u7684\u6700\u5927\u603b\u91cf\u662f\u591a\u5c11\uff1f

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a[1,2,1]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6211\u4eec\u53ef\u4ee5\u6536\u96c6 [1,2,1]\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a[0,1,2,2]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6211\u4eec\u53ef\u4ee5\u6536\u96c6 [1,2,2]\n\u5982\u679c\u6211\u4eec\u4ece\u7b2c\u4e00\u68f5\u6811\u5f00\u59cb\uff0c\u6211\u4eec\u5c06\u53ea\u80fd\u6536\u96c6\u5230 [0, 1]\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1a[1,2,3,2,2]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u6211\u4eec\u53ef\u4ee5\u6536\u96c6 [2,3,2,2]\n\u5982\u679c\u6211\u4eec\u4ece\u7b2c\u4e00\u68f5\u6811\u5f00\u59cb\uff0c\u6211\u4eec\u5c06\u53ea\u80fd\u6536\u96c6\u5230 [1, 2]\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1a[3,3,3,1,2,1,1,2,3,3,4]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u6211\u4eec\u53ef\u4ee5\u6536\u96c6 [1,2,1,1,2]\n\u5982\u679c\u6211\u4eec\u4ece\u7b2c\u4e00\u68f5\u6811\u6216\u7b2c\u516b\u68f5\u6811\u5f00\u59cb\uff0c\u6211\u4eec\u5c06\u53ea\u80fd\u6536\u96c6\u5230 4 \u68f5\u6c34\u679c\u6811\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= tree.length <= 40000
    • \n\t
    • 0 <= tree[i] < tree.length
    • \n
    \n", "tags_en": ["Two Pointers"], "tags_cn": ["\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int totalFruit(vector& tree) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int totalFruit(int[] tree) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def totalFruit(self, tree):\n \"\"\"\n :type tree: List[int]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def totalFruit(self, tree: List[int]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint totalFruit(int* tree, int treeSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int TotalFruit(int[] tree) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} tree\n * @return {number}\n */\nvar totalFruit = function(tree) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} tree\n# @return {Integer}\ndef total_fruit(tree)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func totalFruit(_ tree: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func totalFruit(tree []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def totalFruit(tree: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun totalFruit(tree: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn total_fruit(tree: Vec) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $tree\n * @return Integer\n */\n function totalFruit($tree) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function totalFruit(tree: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (total-fruit tree)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0904](https://leetcode-cn.com/problems/fruit-into-baskets)", "[\u6c34\u679c\u6210\u7bee](/solution/0900-0999/0904.Fruit%20Into%20Baskets/README.md)", "`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0904](https://leetcode.com/problems/fruit-into-baskets)", "[Fruit Into Baskets](/solution/0900-0999/0904.Fruit%20Into%20Baskets/README_EN.md)", "`Two Pointers`", "Medium", ""]}, {"question_id": "0939", "frontend_question_id": "0903", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/valid-permutations-for-di-sequence", "url_en": "https://leetcode.com/problems/valid-permutations-for-di-sequence", "relative_path_cn": "/solution/0900-0999/0903.Valid%20Permutations%20for%20DI%20Sequence/README.md", "relative_path_en": "/solution/0900-0999/0903.Valid%20Permutations%20for%20DI%20Sequence/README_EN.md", "title_cn": "DI \u5e8f\u5217\u7684\u6709\u6548\u6392\u5217", "title_en": "Valid Permutations for DI Sequence", "question_title_slug": "valid-permutations-for-di-sequence", "content_en": "

    We are given s, a length n string of characters from the set {'D', 'I'}. (These letters stand for "decreasing" and "increasing".)

    \n\n

    valid permutation is a permutation p[0], p[1], ..., p[n] of integers {0, 1, ..., n}, such that for all i:

    \n\n
      \n\t
    • If s[i] == 'D', then p[i] > p[i+1], and;
    • \n\t
    • If s[i] == 'I', then p[i] < p[i+1].
    • \n
    \n\n

    How many valid permutations are there?  Since the answer may be large, return your answer modulo 109 + 7.

    \n\n

     

    \n\n

    Example 1:

    \n\n
    \nInput: s = "DID"\nOutput: 5\nExplanation: \nThe 5 valid permutations of (0, 1, 2, 3) are:\n(1, 0, 3, 2)\n(2, 0, 3, 1)\n(2, 1, 3, 0)\n(3, 0, 2, 1)\n(3, 1, 2, 0)\n
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    1. 1 <= s.length <= 200
    2. \n\t
    3. s consists only of characters from the set {'D', 'I'}.
    4. \n
    \n\n
    \n

     

    \n
    \n", "content_cn": "

    \u6211\u4eec\u7ed9\u51fa S\uff0c\u4e00\u4e2a\u6e90\u4e8e {'D', 'I'} \u7684\u957f\u5ea6\u4e3a n \u7684\u5b57\u7b26\u4e32 \u3002\uff08\u8fd9\u4e9b\u5b57\u6bcd\u4ee3\u8868 “\u51cf\u5c11” \u548c “\u589e\u52a0”\u3002\uff09
    \n\u6709\u6548\u6392\u5217 \u662f\u5bf9\u6574\u6570 {0, 1, ..., n} \u7684\u4e00\u4e2a\u6392\u5217 P[0], P[1], ..., P[n]\uff0c\u4f7f\u5f97\u5bf9\u6240\u6709\u7684 i\uff1a

    \n\n
      \n\t
    • \u5982\u679c S[i] == 'D'\uff0c\u90a3\u4e48 P[i] > P[i+1]\uff0c\u4ee5\u53ca\uff1b
    • \n\t
    • \u5982\u679c S[i] == 'I'\uff0c\u90a3\u4e48 P[i] < P[i+1]\u3002
    • \n
    \n\n

    \u6709\u591a\u5c11\u4e2a\u6709\u6548\u6392\u5217\uff1f\u56e0\u4e3a\u7b54\u6848\u53ef\u80fd\u5f88\u5927\uff0c\u6240\u4ee5\u8bf7\u8fd4\u56de\u4f60\u7684\u7b54\u6848\u6a21 10^9 + 7.

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1a"DID"\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\n(0, 1, 2, 3) \u7684\u4e94\u4e2a\u6709\u6548\u6392\u5217\u662f\uff1a\n(1, 0, 3, 2)\n(2, 0, 3, 1)\n(2, 1, 3, 0)\n(3, 0, 2, 1)\n(3, 1, 2, 0)\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= S.length <= 200
    2. \n\t
    3. S \u4ec5\u7531\u96c6\u5408 {'D', 'I'} \u4e2d\u7684\u5b57\u7b26\u7ec4\u6210\u3002
    4. \n
    \n\n

     

    \n", "tags_en": ["Divide and Conquer", "Dynamic Programming"], "tags_cn": ["\u5206\u6cbb\u7b97\u6cd5", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numPermsDISequence(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numPermsDISequence(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numPermsDISequence(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numPermsDISequence(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numPermsDISequence(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumPermsDISequence(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar numPermsDISequence = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef num_perms_di_sequence(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numPermsDISequence(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numPermsDISequence(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numPermsDISequence(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numPermsDISequence(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_perms_di_sequence(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function numPermsDISequence($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numPermsDISequence(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-perms-di-sequence s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0903](https://leetcode-cn.com/problems/valid-permutations-for-di-sequence)", "[DI \u5e8f\u5217\u7684\u6709\u6548\u6392\u5217](/solution/0900-0999/0903.Valid%20Permutations%20for%20DI%20Sequence/README.md)", "`\u5206\u6cbb\u7b97\u6cd5`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0903](https://leetcode.com/problems/valid-permutations-for-di-sequence)", "[Valid Permutations for DI Sequence](/solution/0900-0999/0903.Valid%20Permutations%20for%20DI%20Sequence/README_EN.md)", "`Divide and Conquer`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0938", "frontend_question_id": "0902", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/numbers-at-most-n-given-digit-set", "url_en": "https://leetcode.com/problems/numbers-at-most-n-given-digit-set", "relative_path_cn": "/solution/0900-0999/0902.Numbers%20At%20Most%20N%20Given%20Digit%20Set/README.md", "relative_path_en": "/solution/0900-0999/0902.Numbers%20At%20Most%20N%20Given%20Digit%20Set/README_EN.md", "title_cn": "\u6700\u5927\u4e3a N \u7684\u6570\u5b57\u7ec4\u5408", "title_en": "Numbers At Most N Given Digit Set", "question_title_slug": "numbers-at-most-n-given-digit-set", "content_en": "

    Given an array of digits which is sorted in non-decreasing order. You can write numbers using each digits[i] as many times as we want. For example, if digits = ['1','3','5'], we may write numbers such as '13', '551', and '1351315'.

    \n\n

    Return the number of positive integers that can be generated that are less than or equal to a given integer n.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: digits = ["1","3","5","7"], n = 100\nOutput: 20\nExplanation: \nThe 20 numbers that can be written are:\n1, 3, 5, 7, 11, 13, 15, 17, 31, 33, 35, 37, 51, 53, 55, 57, 71, 73, 75, 77.\n
    \n\n

    Example 2:

    \n\n
    \nInput: digits = ["1","4","9"], n = 1000000000\nOutput: 29523\nExplanation: \nWe can write 3 one digit numbers, 9 two digit numbers, 27 three digit numbers,\n81 four digit numbers, 243 five digit numbers, 729 six digit numbers,\n2187 seven digit numbers, 6561 eight digit numbers, and 19683 nine digit numbers.\nIn total, this is 29523 integers that can be written using the digits array.\n
    \n\n

    Example 3:

    \n\n
    \nInput: digits = ["7"], n = 8\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= digits.length <= 9
    • \n\t
    • digits[i].length == 1
    • \n\t
    • digits[i] is a digit from '1' to '9'.
    • \n\t
    • All the values in digits are unique.
    • \n\t
    • digits is sorted in non-decreasing order.
    • \n\t
    • 1 <= n <= 109
    • \n
    \n", "content_cn": "

    \u6211\u4eec\u6709\u4e00\u7ec4\u6392\u5e8f\u7684\u6570\u5b57 D\uff0c\u5b83\u662f  {'1','2','3','4','5','6','7','8','9'} \u7684\u975e\u7a7a\u5b50\u96c6\u3002\uff08\u8bf7\u6ce8\u610f\uff0c'0' \u4e0d\u5305\u62ec\u5728\u5185\u3002\uff09

    \n\n

    \u73b0\u5728\uff0c\u6211\u4eec\u7528\u8fd9\u4e9b\u6570\u5b57\u8fdb\u884c\u7ec4\u5408\u5199\u6570\u5b57\uff0c\u60f3\u7528\u591a\u5c11\u6b21\u5c31\u7528\u591a\u5c11\u6b21\u3002\u4f8b\u5982 D = {'1','3','5'}\uff0c\u6211\u4eec\u53ef\u4ee5\u5199\u51fa\u50cf '13', '551', '1351315' \u8fd9\u6837\u7684\u6570\u5b57\u3002

    \n\n

    \u8fd4\u56de\u53ef\u4ee5\u7528 D \u4e2d\u7684\u6570\u5b57\u5199\u51fa\u7684\u5c0f\u4e8e\u6216\u7b49\u4e8e N \u7684\u6b63\u6574\u6570\u7684\u6570\u76ee\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aD = ["1","3","5","7"], N = 100\n\u8f93\u51fa\uff1a20\n\u89e3\u91ca\uff1a\n\u53ef\u5199\u51fa\u7684 20 \u4e2a\u6570\u5b57\u662f\uff1a\n1, 3, 5, 7, 11, 13, 15, 17, 31, 33, 35, 37, 51, 53, 55, 57, 71, 73, 75, 77.\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aD = ["1","4","9"], N = 1000000000\n\u8f93\u51fa\uff1a29523\n\u89e3\u91ca\uff1a\n\u6211\u4eec\u53ef\u4ee5\u5199 3 \u4e2a\u4e00\u4f4d\u6570\u5b57\uff0c9 \u4e2a\u4e24\u4f4d\u6570\u5b57\uff0c27 \u4e2a\u4e09\u4f4d\u6570\u5b57\uff0c\n81 \u4e2a\u56db\u4f4d\u6570\u5b57\uff0c243 \u4e2a\u4e94\u4f4d\u6570\u5b57\uff0c729 \u4e2a\u516d\u4f4d\u6570\u5b57\uff0c\n2187 \u4e2a\u4e03\u4f4d\u6570\u5b57\uff0c6561 \u4e2a\u516b\u4f4d\u6570\u5b57\u548c 19683 \u4e2a\u4e5d\u4f4d\u6570\u5b57\u3002\n\u603b\u5171\uff0c\u53ef\u4ee5\u4f7f\u7528D\u4e2d\u7684\u6570\u5b57\u5199\u51fa 29523 \u4e2a\u6574\u6570\u3002
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. D \u662f\u6309\u6392\u5e8f\u987a\u5e8f\u7684\u6570\u5b57 '1'-'9' \u7684\u5b50\u96c6\u3002
    2. \n\t
    3. 1 <= N <= 10^9
    4. \n
    \n", "tags_en": ["Math", "Dynamic Programming"], "tags_cn": ["\u6570\u5b66", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int atMostNGivenDigitSet(vector& digits, int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int atMostNGivenDigitSet(String[] digits, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def atMostNGivenDigitSet(self, digits, n):\n \"\"\"\n :type digits: List[str]\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def atMostNGivenDigitSet(self, digits: List[str], n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint atMostNGivenDigitSet(char ** digits, int digitsSize, int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int AtMostNGivenDigitSet(string[] digits, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} digits\n * @param {number} n\n * @return {number}\n */\nvar atMostNGivenDigitSet = function(digits, n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} digits\n# @param {Integer} n\n# @return {Integer}\ndef at_most_n_given_digit_set(digits, n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func atMostNGivenDigitSet(_ digits: [String], _ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func atMostNGivenDigitSet(digits []string, n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def atMostNGivenDigitSet(digits: Array[String], n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun atMostNGivenDigitSet(digits: Array, n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn at_most_n_given_digit_set(digits: Vec, n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $digits\n * @param Integer $n\n * @return Integer\n */\n function atMostNGivenDigitSet($digits, $n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function atMostNGivenDigitSet(digits: string[], n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (at-most-n-given-digit-set digits n)\n (-> (listof string?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0902](https://leetcode-cn.com/problems/numbers-at-most-n-given-digit-set)", "[\u6700\u5927\u4e3a N \u7684\u6570\u5b57\u7ec4\u5408](/solution/0900-0999/0902.Numbers%20At%20Most%20N%20Given%20Digit%20Set/README.md)", "`\u6570\u5b66`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0902](https://leetcode.com/problems/numbers-at-most-n-given-digit-set)", "[Numbers At Most N Given Digit Set](/solution/0900-0999/0902.Numbers%20At%20Most%20N%20Given%20Digit%20Set/README_EN.md)", "`Math`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0937", "frontend_question_id": "0901", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/online-stock-span", "url_en": "https://leetcode.com/problems/online-stock-span", "relative_path_cn": "/solution/0900-0999/0901.Online%20Stock%20Span/README.md", "relative_path_en": "/solution/0900-0999/0901.Online%20Stock%20Span/README_EN.md", "title_cn": "\u80a1\u7968\u4ef7\u683c\u8de8\u5ea6", "title_en": "Online Stock Span", "question_title_slug": "online-stock-span", "content_en": "

    Write a class StockSpanner which collects daily price quotes for some stock, and returns the span of that stock's price for the current day.

    \r\n\r\n

    The span of the stock's price today is defined as the maximum number of consecutive days (starting from today and going backwards) for which the price of the stock was less than or equal to today's price.

    \r\n\r\n

    For example, if the price of a stock over the next 7 days were [100, 80, 60, 70, 60, 75, 85], then the stock spans would be [1, 1, 1, 2, 1, 4, 6].

    \r\n\r\n

     

    \r\n\r\n
    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: ["StockSpanner","next","next","next","next","next","next","next"], [[],[100],[80],[60],[70],[60],[75],[85]]\r\nOutput: [null,1,1,1,2,1,4,6]\r\nExplanation: \r\nFirst, S = StockSpanner() is initialized.  Then:\r\nS.next(100) is called and returns 1,\r\nS.next(80) is called and returns 1,\r\nS.next(60) is called and returns 1,\r\nS.next(70) is called and returns 2,\r\nS.next(60) is called and returns 1,\r\nS.next(75) is called and returns 4,\r\nS.next(85) is called and returns 6.\r\n\r\nNote that (for example) S.next(75) returned 4, because the last 4 prices\r\n(including today's price of 75) were less than or equal to today's price.\r\n
    \r\n\r\n

     

    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    1. Calls to StockSpanner.next(int price) will have 1 <= price <= 10^5.
    2. \r\n\t
    3. There will be at most 10000 calls to StockSpanner.next per test case.
    4. \r\n\t
    5. There will be at most 150000 calls to StockSpanner.next across all test cases.
    6. \r\n\t
    7. The total time limit for this problem has been reduced by 75% for C++, and 50% for all other languages.
    8. \r\n
    \r\n
    \r\n", "content_cn": "

    \u7f16\u5199\u4e00\u4e2a StockSpanner \u7c7b\uff0c\u5b83\u6536\u96c6\u67d0\u4e9b\u80a1\u7968\u7684\u6bcf\u65e5\u62a5\u4ef7\uff0c\u5e76\u8fd4\u56de\u8be5\u80a1\u7968\u5f53\u65e5\u4ef7\u683c\u7684\u8de8\u5ea6\u3002

    \n\n

    \u4eca\u5929\u80a1\u7968\u4ef7\u683c\u7684\u8de8\u5ea6\u88ab\u5b9a\u4e49\u4e3a\u80a1\u7968\u4ef7\u683c\u5c0f\u4e8e\u6216\u7b49\u4e8e\u4eca\u5929\u4ef7\u683c\u7684\u6700\u5927\u8fde\u7eed\u65e5\u6570\uff08\u4ece\u4eca\u5929\u5f00\u59cb\u5f80\u56de\u6570\uff0c\u5305\u62ec\u4eca\u5929\uff09\u3002

    \n\n

    \u4f8b\u5982\uff0c\u5982\u679c\u672a\u67657\u5929\u80a1\u7968\u7684\u4ef7\u683c\u662f [100, 80, 60, 70, 60, 75, 85]\uff0c\u90a3\u4e48\u80a1\u7968\u8de8\u5ea6\u5c06\u662f [1, 1, 1, 2, 1, 4, 6]\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1a["StockSpanner","next","next","next","next","next","next","next"], [[],[100],[80],[60],[70],[60],[75],[85]]\n\u8f93\u51fa\uff1a[null,1,1,1,2,1,4,6]\n\u89e3\u91ca\uff1a\n\u9996\u5148\uff0c\u521d\u59cb\u5316 S = StockSpanner()\uff0c\u7136\u540e\uff1a\nS.next(100) \u88ab\u8c03\u7528\u5e76\u8fd4\u56de 1\uff0c\nS.next(80) \u88ab\u8c03\u7528\u5e76\u8fd4\u56de 1\uff0c\nS.next(60) \u88ab\u8c03\u7528\u5e76\u8fd4\u56de 1\uff0c\nS.next(70) \u88ab\u8c03\u7528\u5e76\u8fd4\u56de 2\uff0c\nS.next(60) \u88ab\u8c03\u7528\u5e76\u8fd4\u56de 1\uff0c\nS.next(75) \u88ab\u8c03\u7528\u5e76\u8fd4\u56de 4\uff0c\nS.next(85) \u88ab\u8c03\u7528\u5e76\u8fd4\u56de 6\u3002\n\n\u6ce8\u610f (\u4f8b\u5982) S.next(75) \u8fd4\u56de 4\uff0c\u56e0\u4e3a\u622a\u81f3\u4eca\u5929\u7684\u6700\u540e 4 \u4e2a\u4ef7\u683c\n(\u5305\u62ec\u4eca\u5929\u7684\u4ef7\u683c 75) \u5c0f\u4e8e\u6216\u7b49\u4e8e\u4eca\u5929\u7684\u4ef7\u683c\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. \u8c03\u7528 StockSpanner.next(int price) \u65f6\uff0c\u5c06\u6709 1 <= price <= 10^5\u3002
    2. \n\t
    3. \u6bcf\u4e2a\u6d4b\u8bd5\u7528\u4f8b\u6700\u591a\u53ef\u4ee5\u8c03\u7528  10000 \u6b21 StockSpanner.next\u3002
    4. \n\t
    5. \u5728\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u4e2d\uff0c\u6700\u591a\u8c03\u7528 150000 \u6b21 StockSpanner.next\u3002
    6. \n\t
    7. \u6b64\u95ee\u9898\u7684\u603b\u65f6\u95f4\u9650\u5236\u51cf\u5c11\u4e86 50%\u3002
    8. \n
    \n", "tags_en": ["Stack"], "tags_cn": ["\u6808"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class StockSpanner {\npublic:\n StockSpanner() {\n\n }\n \n int next(int price) {\n\n }\n};\n\n/**\n * Your StockSpanner object will be instantiated and called as such:\n * StockSpanner* obj = new StockSpanner();\n * int param_1 = obj->next(price);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class StockSpanner {\n\n public StockSpanner() {\n\n }\n \n public int next(int price) {\n\n }\n}\n\n/**\n * Your StockSpanner object will be instantiated and called as such:\n * StockSpanner obj = new StockSpanner();\n * int param_1 = obj.next(price);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class StockSpanner(object):\n\n def __init__(self):\n\n\n def next(self, price):\n \"\"\"\n :type price: int\n :rtype: int\n \"\"\"\n\n\n\n# Your StockSpanner object will be instantiated and called as such:\n# obj = StockSpanner()\n# param_1 = obj.next(price)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class StockSpanner:\n\n def __init__(self):\n\n\n def next(self, price: int) -> int:\n\n\n\n# Your StockSpanner object will be instantiated and called as such:\n# obj = StockSpanner()\n# param_1 = obj.next(price)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} StockSpanner;\n\n\nStockSpanner* stockSpannerCreate() {\n\n}\n\nint stockSpannerNext(StockSpanner* obj, int price) {\n\n}\n\nvoid stockSpannerFree(StockSpanner* obj) {\n\n}\n\n/**\n * Your StockSpanner struct will be instantiated and called as such:\n * StockSpanner* obj = stockSpannerCreate();\n * int param_1 = stockSpannerNext(obj, price);\n \n * stockSpannerFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class StockSpanner {\n\n public StockSpanner() {\n\n }\n \n public int Next(int price) {\n\n }\n}\n\n/**\n * Your StockSpanner object will be instantiated and called as such:\n * StockSpanner obj = new StockSpanner();\n * int param_1 = obj.Next(price);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "\nvar StockSpanner = function() {\n\n};\n\n/** \n * @param {number} price\n * @return {number}\n */\nStockSpanner.prototype.next = function(price) {\n\n};\n\n/**\n * Your StockSpanner object will be instantiated and called as such:\n * var obj = new StockSpanner()\n * var param_1 = obj.next(price)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class StockSpanner\n def initialize()\n\n end\n\n\n=begin\n :type price: Integer\n :rtype: Integer\n=end\n def next(price)\n\n end\n\n\nend\n\n# Your StockSpanner object will be instantiated and called as such:\n# obj = StockSpanner.new()\n# param_1 = obj.next(price)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass StockSpanner {\n\n init() {\n\n }\n \n func next(_ price: Int) -> Int {\n\n }\n}\n\n/**\n * Your StockSpanner object will be instantiated and called as such:\n * let obj = StockSpanner()\n * let ret_1: Int = obj.next(price)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type StockSpanner struct {\n\n}\n\n\nfunc Constructor() StockSpanner {\n\n}\n\n\nfunc (this *StockSpanner) Next(price int) int {\n\n}\n\n\n/**\n * Your StockSpanner object will be instantiated and called as such:\n * obj := Constructor();\n * param_1 := obj.Next(price);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class StockSpanner() {\n\n def next(price: Int): Int = {\n\n }\n\n}\n\n/**\n * Your StockSpanner object will be instantiated and called as such:\n * var obj = new StockSpanner()\n * var param_1 = obj.next(price)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class StockSpanner() {\n\n fun next(price: Int): Int {\n\n }\n\n}\n\n/**\n * Your StockSpanner object will be instantiated and called as such:\n * var obj = StockSpanner()\n * var param_1 = obj.next(price)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct StockSpanner {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl StockSpanner {\n\n fn new() -> Self {\n\n }\n \n fn next(&self, price: i32) -> i32 {\n\n }\n}\n\n/**\n * Your StockSpanner object will be instantiated and called as such:\n * let obj = StockSpanner::new();\n * let ret_1: i32 = obj.next(price);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class StockSpanner {\n /**\n */\n function __construct() {\n\n }\n\n /**\n * @param Integer $price\n * @return Integer\n */\n function next($price) {\n\n }\n}\n\n/**\n * Your StockSpanner object will be instantiated and called as such:\n * $obj = StockSpanner();\n * $ret_1 = $obj->next($price);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class StockSpanner {\n constructor() {\n\n }\n\n next(price: number): number {\n\n }\n}\n\n/**\n * Your StockSpanner object will be instantiated and called as such:\n * var obj = new StockSpanner()\n * var param_1 = obj.next(price)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define stock-spanner%\n (class object%\n (super-new)\n (init-field)\n \n ; next : exact-integer? -> exact-integer?\n (define/public (next price)\n\n )))\n\n;; Your stock-spanner% object will be instantiated and called as such:\n;; (define obj (new stock-spanner%))\n;; (define param_1 (send obj next price))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0901](https://leetcode-cn.com/problems/online-stock-span)", "[\u80a1\u7968\u4ef7\u683c\u8de8\u5ea6](/solution/0900-0999/0901.Online%20Stock%20Span/README.md)", "`\u6808`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0901](https://leetcode.com/problems/online-stock-span)", "[Online Stock Span](/solution/0900-0999/0901.Online%20Stock%20Span/README_EN.md)", "`Stack`", "Medium", ""]}, {"question_id": "0936", "frontend_question_id": "0900", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/rle-iterator", "url_en": "https://leetcode.com/problems/rle-iterator", "relative_path_cn": "/solution/0900-0999/0900.RLE%20Iterator/README.md", "relative_path_en": "/solution/0900-0999/0900.RLE%20Iterator/README_EN.md", "title_cn": "RLE \u8fed\u4ee3\u5668", "title_en": "RLE Iterator", "question_title_slug": "rle-iterator", "content_en": "

    We can use run-length encoding (i.e., RLE) to encode a sequence of integers. In a run-length encoded array of even length encoding (0-indexed), for all even i, encoding[i] tells us the number of times that the non-negative integer value encoding[i + 1] is repeated in the sequence.

    \n\n
      \n\t
    • For example, the sequence arr = [8,8,8,5,5] can be encoded to be encoding = [3,8,2,5]. encoding = [3,8,0,9,2,5] and encoding = [2,8,1,8,2,5] are also valid RLE of arr.
    • \n
    \n\n

    Given a run-length encoded array, design an iterator that iterates through it.

    \n\n

    Implement the RLEIterator class:

    \n\n
      \n\t
    • RLEIterator(int[] encoded) Initializes the object with the encoded array encoded.
    • \n\t
    • int next(int n) Exhausts the next n elements and returns the last element exhausted in this way. If there is no element left to exhaust, return -1 instead.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["RLEIterator", "next", "next", "next", "next"]\n[[[3, 8, 0, 9, 2, 5]], [2], [1], [1], [2]]\nOutput\n[null, 8, 8, 5, -1]\n\nExplanation\nRLEIterator rLEIterator = new RLEIterator([3, 8, 0, 9, 2, 5]); // This maps to the sequence [8,8,8,5,5].\nrLEIterator.next(2); // exhausts 2 terms of the sequence, returning 8. The remaining sequence is now [8, 5, 5].\nrLEIterator.next(1); // exhausts 1 term of the sequence, returning 8. The remaining sequence is now [5, 5].\nrLEIterator.next(1); // exhausts 1 term of the sequence, returning 5. The remaining sequence is now [5].\nrLEIterator.next(2); // exhausts 2 terms, returning -1. This is because the first term exhausted was 5,\nbut the second term did not exist. Since the last term exhausted does not exist, we return -1.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= encoding.length <= 1000
    • \n\t
    • encoding.length is even.
    • \n\t
    • 0 <= encoding[i] <= 109
    • \n\t
    • 1 <= n <= 109
    • \n\t
    • At most 1000 calls will be made to next.
    • \n
    \n", "content_cn": "

    \u7f16\u5199\u4e00\u4e2a\u904d\u5386\u6e38\u7a0b\u7f16\u7801\u5e8f\u5217\u7684\u8fed\u4ee3\u5668\u3002

    \n\n

    \u8fed\u4ee3\u5668\u7531 RLEIterator(int[] A) \u521d\u59cb\u5316\uff0c\u5176\u4e2d A \u662f\u67d0\u4e2a\u5e8f\u5217\u7684\u6e38\u7a0b\u7f16\u7801\u3002\u66f4\u5177\u4f53\u5730\uff0c\u5bf9\u4e8e\u6240\u6709\u5076\u6570 i\uff0cA[i] \u544a\u8bc9\u6211\u4eec\u5728\u5e8f\u5217\u4e2d\u91cd\u590d\u975e\u8d1f\u6574\u6570\u503c A[i + 1] \u7684\u6b21\u6570\u3002

    \n\n

    \u8fed\u4ee3\u5668\u652f\u6301\u4e00\u4e2a\u51fd\u6570\uff1anext(int n)\uff0c\u5b83\u8017\u5c3d\u63a5\u4e0b\u6765\u7684  n \u4e2a\u5143\u7d20\uff08n >= 1\uff09\u5e76\u8fd4\u56de\u4ee5\u8fd9\u79cd\u65b9\u5f0f\u8017\u53bb\u7684\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u3002\u5982\u679c\u6ca1\u6709\u5269\u4f59\u7684\u5143\u7d20\u53ef\u4f9b\u8017\u5c3d\uff0c\u5219  next \u8fd4\u56de -1 \u3002

    \n\n

    \u4f8b\u5982\uff0c\u6211\u4eec\u4ee5 A = [3,8,0,9,2,5] \u5f00\u59cb\uff0c\u8fd9\u662f\u5e8f\u5217 [8,8,8,5,5] \u7684\u6e38\u7a0b\u7f16\u7801\u3002\u8fd9\u662f\u56e0\u4e3a\u8be5\u5e8f\u5217\u53ef\u4ee5\u8bfb\u4f5c “\u4e09\u4e2a\u516b\uff0c\u96f6\u4e2a\u4e5d\uff0c\u4e24\u4e2a\u4e94”\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1a["RLEIterator","next","next","next","next"], [[[3,8,0,9,2,5]],[2],[1],[1],[2]]\n\u8f93\u51fa\uff1a[null,8,8,5,-1]\n\u89e3\u91ca\uff1a\nRLEIterator \u7531 RLEIterator([3,8,0,9,2,5]) \u521d\u59cb\u5316\u3002\n\u8fd9\u6620\u5c04\u5230\u5e8f\u5217 [8,8,8,5,5]\u3002\n\u7136\u540e\u8c03\u7528 RLEIterator.next 4\u6b21\u3002\n\n.next(2) \u8017\u53bb\u5e8f\u5217\u7684 2 \u4e2a\u9879\uff0c\u8fd4\u56de 8\u3002\u73b0\u5728\u5269\u4e0b\u7684\u5e8f\u5217\u662f [8, 5, 5]\u3002\n\n.next(1) \u8017\u53bb\u5e8f\u5217\u7684 1 \u4e2a\u9879\uff0c\u8fd4\u56de 8\u3002\u73b0\u5728\u5269\u4e0b\u7684\u5e8f\u5217\u662f [5, 5]\u3002\n\n.next(1) \u8017\u53bb\u5e8f\u5217\u7684 1 \u4e2a\u9879\uff0c\u8fd4\u56de 5\u3002\u73b0\u5728\u5269\u4e0b\u7684\u5e8f\u5217\u662f [5]\u3002\n\n.next(2) \u8017\u53bb\u5e8f\u5217\u7684 2 \u4e2a\u9879\uff0c\u8fd4\u56de -1\u3002 \u8fd9\u662f\u7531\u4e8e\u7b2c\u4e00\u4e2a\u88ab\u8017\u53bb\u7684\u9879\u662f 5\uff0c\n\u4f46\u7b2c\u4e8c\u4e2a\u9879\u5e76\u4e0d\u5b58\u5728\u3002\u7531\u4e8e\u6700\u540e\u4e00\u4e2a\u8981\u8017\u53bb\u7684\u9879\u4e0d\u5b58\u5728\uff0c\u6211\u4eec\u8fd4\u56de -1\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 0 <= A.length <= 1000
    2. \n\t
    3. A.length \u662f\u5076\u6570\u3002
    4. \n\t
    5. 0 <= A[i] <= 10^9
    6. \n\t
    7. \u6bcf\u4e2a\u6d4b\u8bd5\u7528\u4f8b\u6700\u591a\u8c03\u7528 1000 \u6b21 RLEIterator.next(int n)\u3002
    8. \n\t
    9. \u6bcf\u6b21\u8c03\u7528 RLEIterator.next(int n) \u90fd\u6709 1 <= n <= 10^9 \u3002
    10. \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class RLEIterator {\npublic:\n RLEIterator(vector& encoding) {\n\n }\n \n int next(int n) {\n\n }\n};\n\n/**\n * Your RLEIterator object will be instantiated and called as such:\n * RLEIterator* obj = new RLEIterator(encoding);\n * int param_1 = obj->next(n);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class RLEIterator {\n\n public RLEIterator(int[] encoding) {\n\n }\n \n public int next(int n) {\n\n }\n}\n\n/**\n * Your RLEIterator object will be instantiated and called as such:\n * RLEIterator obj = new RLEIterator(encoding);\n * int param_1 = obj.next(n);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class RLEIterator(object):\n\n def __init__(self, encoding):\n \"\"\"\n :type encoding: List[int]\n \"\"\"\n\n\n def next(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"\n\n\n\n# Your RLEIterator object will be instantiated and called as such:\n# obj = RLEIterator(encoding)\n# param_1 = obj.next(n)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class RLEIterator:\n\n def __init__(self, encoding: List[int]):\n\n\n def next(self, n: int) -> int:\n\n\n\n# Your RLEIterator object will be instantiated and called as such:\n# obj = RLEIterator(encoding)\n# param_1 = obj.next(n)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} RLEIterator;\n\n\nRLEIterator* rLEIteratorCreate(int* encoding, int encodingSize) {\n\n}\n\nint rLEIteratorNext(RLEIterator* obj, int n) {\n\n}\n\nvoid rLEIteratorFree(RLEIterator* obj) {\n\n}\n\n/**\n * Your RLEIterator struct will be instantiated and called as such:\n * RLEIterator* obj = rLEIteratorCreate(encoding, encodingSize);\n * int param_1 = rLEIteratorNext(obj, n);\n \n * rLEIteratorFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class RLEIterator {\n\n public RLEIterator(int[] encoding) {\n\n }\n \n public int Next(int n) {\n\n }\n}\n\n/**\n * Your RLEIterator object will be instantiated and called as such:\n * RLEIterator obj = new RLEIterator(encoding);\n * int param_1 = obj.Next(n);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} encoding\n */\nvar RLEIterator = function(encoding) {\n\n};\n\n/** \n * @param {number} n\n * @return {number}\n */\nRLEIterator.prototype.next = function(n) {\n\n};\n\n/**\n * Your RLEIterator object will be instantiated and called as such:\n * var obj = new RLEIterator(encoding)\n * var param_1 = obj.next(n)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class RLEIterator\n\n=begin\n :type encoding: Integer[]\n=end\n def initialize(encoding)\n\n end\n\n\n=begin\n :type n: Integer\n :rtype: Integer\n=end\n def next(n)\n\n end\n\n\nend\n\n# Your RLEIterator object will be instantiated and called as such:\n# obj = RLEIterator.new(encoding)\n# param_1 = obj.next(n)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass RLEIterator {\n\n init(_ encoding: [Int]) {\n\n }\n \n func next(_ n: Int) -> Int {\n\n }\n}\n\n/**\n * Your RLEIterator object will be instantiated and called as such:\n * let obj = RLEIterator(encoding)\n * let ret_1: Int = obj.next(n)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type RLEIterator struct {\n\n}\n\n\nfunc Constructor(encoding []int) RLEIterator {\n\n}\n\n\nfunc (this *RLEIterator) Next(n int) int {\n\n}\n\n\n/**\n * Your RLEIterator object will be instantiated and called as such:\n * obj := Constructor(encoding);\n * param_1 := obj.Next(n);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class RLEIterator(_encoding: Array[Int]) {\n\n def next(n: Int): Int = {\n\n }\n\n}\n\n/**\n * Your RLEIterator object will be instantiated and called as such:\n * var obj = new RLEIterator(encoding)\n * var param_1 = obj.next(n)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class RLEIterator(encoding: IntArray) {\n\n fun next(n: Int): Int {\n\n }\n\n}\n\n/**\n * Your RLEIterator object will be instantiated and called as such:\n * var obj = RLEIterator(encoding)\n * var param_1 = obj.next(n)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct RLEIterator {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl RLEIterator {\n\n fn new(encoding: Vec) -> Self {\n\n }\n \n fn next(&self, n: i32) -> i32 {\n\n }\n}\n\n/**\n * Your RLEIterator object will be instantiated and called as such:\n * let obj = RLEIterator::new(encoding);\n * let ret_1: i32 = obj.next(n);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class RLEIterator {\n /**\n * @param Integer[] $encoding\n */\n function __construct($encoding) {\n\n }\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function next($n) {\n\n }\n}\n\n/**\n * Your RLEIterator object will be instantiated and called as such:\n * $obj = RLEIterator($encoding);\n * $ret_1 = $obj->next($n);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class RLEIterator {\n constructor(encoding: number[]) {\n\n }\n\n next(n: number): number {\n\n }\n}\n\n/**\n * Your RLEIterator object will be instantiated and called as such:\n * var obj = new RLEIterator(encoding)\n * var param_1 = obj.next(n)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define rle-iterator%\n (class object%\n (super-new)\n\n ; encoding : (listof exact-integer?)\n (init-field\n encoding)\n \n ; next : exact-integer? -> exact-integer?\n (define/public (next n)\n\n )))\n\n;; Your rle-iterator% object will be instantiated and called as such:\n;; (define obj (new rle-iterator% [encoding encoding]))\n;; (define param_1 (send obj next n))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0900](https://leetcode-cn.com/problems/rle-iterator)", "[RLE \u8fed\u4ee3\u5668](/solution/0900-0999/0900.RLE%20Iterator/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0900](https://leetcode.com/problems/rle-iterator)", "[RLE Iterator](/solution/0900-0999/0900.RLE%20Iterator/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0935", "frontend_question_id": "0899", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/orderly-queue", "url_en": "https://leetcode.com/problems/orderly-queue", "relative_path_cn": "/solution/0800-0899/0899.Orderly%20Queue/README.md", "relative_path_en": "/solution/0800-0899/0899.Orderly%20Queue/README_EN.md", "title_cn": "\u6709\u5e8f\u961f\u5217", "title_en": "Orderly Queue", "question_title_slug": "orderly-queue", "content_en": "

    A string s of lowercase letters is given.  Then, we may make any number of moves.

    \n\n

    In each move, we choose one of the first k letters (starting from the left), remove it, and place it at the end of the string.

    \n\n

    Return the lexicographically smallest string we could have after any number of moves.

    \n\n

     

    \n\n
    \n

    Example 1:

    \n\n
    \nInput: s = "cba", k = 1\nOutput: "acb"\nExplanation: \nIn the first move, we move the 1st character ("c") to the end, obtaining the string "bac".\nIn the second move, we move the 1st character ("b") to the end, obtaining the final result "acb".\n
    \n\n
    \n

    Example 2:

    \n\n
    \nInput: s = "baaca", k = 3\nOutput: "aaabc"\nExplanation: \nIn the first move, we move the 1st character ("b") to the end, obtaining the string "aacab".\nIn the second move, we move the 3rd character ("c") to the end, obtaining the final result "aaabc".\n
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    1. 1 <= k <= s.length <= 1000
    2. \n\t
    3. s consists of lowercase letters only.
    4. \n
    \n
    \n
    \n", "content_cn": "

    \u7ed9\u51fa\u4e86\u4e00\u4e2a\u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210\u7684\u5b57\u7b26\u4e32 S\u3002\u7136\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u8fdb\u884c\u4efb\u610f\u6b21\u6570\u7684\u79fb\u52a8\u3002

    \n\n

    \u5728\u6bcf\u6b21\u79fb\u52a8\u4e2d\uff0c\u6211\u4eec\u9009\u62e9\u524d K \u4e2a\u5b57\u6bcd\u4e2d\u7684\u4e00\u4e2a\uff08\u4ece\u5de6\u4fa7\u5f00\u59cb\uff09\uff0c\u5c06\u5176\u4ece\u539f\u4f4d\u7f6e\u79fb\u9664\uff0c\u5e76\u653e\u7f6e\u5728\u5b57\u7b26\u4e32\u7684\u672b\u5c3e\u3002

    \n\n

    \u8fd4\u56de\u6211\u4eec\u5728\u4efb\u610f\u6b21\u6570\u7684\u79fb\u52a8\u4e4b\u540e\u53ef\u4ee5\u62e5\u6709\u7684\u6309\u5b57\u5178\u987a\u5e8f\u6392\u5217\u7684\u6700\u5c0f\u5b57\u7b26\u4e32\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aS = "cba", K = 1\n\u8f93\u51fa\uff1a"acb"\n\u89e3\u91ca\uff1a\n\u5728\u7b2c\u4e00\u6b65\u4e2d\uff0c\u6211\u4eec\u5c06\u7b2c\u4e00\u4e2a\u5b57\u7b26\uff08“c”\uff09\u79fb\u52a8\u5230\u6700\u540e\uff0c\u83b7\u5f97\u5b57\u7b26\u4e32 “bac”\u3002\n\u5728\u7b2c\u4e8c\u6b65\u4e2d\uff0c\u6211\u4eec\u5c06\u7b2c\u4e00\u4e2a\u5b57\u7b26\uff08“b”\uff09\u79fb\u52a8\u5230\u6700\u540e\uff0c\u83b7\u5f97\u6700\u7ec8\u7ed3\u679c “acb”\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aS = "baaca", K = 3\n\u8f93\u51fa\uff1a"aaabc"\n\u89e3\u91ca\uff1a\n\u5728\u7b2c\u4e00\u6b65\u4e2d\uff0c\u6211\u4eec\u5c06\u7b2c\u4e00\u4e2a\u5b57\u7b26\uff08“b”\uff09\u79fb\u52a8\u5230\u6700\u540e\uff0c\u83b7\u5f97\u5b57\u7b26\u4e32 “aacab”\u3002\n\u5728\u7b2c\u4e8c\u6b65\u4e2d\uff0c\u6211\u4eec\u5c06\u7b2c\u4e09\u4e2a\u5b57\u7b26\uff08“c”\uff09\u79fb\u52a8\u5230\u6700\u540e\uff0c\u83b7\u5f97\u6700\u7ec8\u7ed3\u679c “aaabc”\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= K <= S.length <= 1000
    2. \n\t
    3. S \u53ea\u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210\u3002
    4. \n
    \n", "tags_en": ["Math", "String"], "tags_cn": ["\u6570\u5b66", "\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string orderlyQueue(string s, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String orderlyQueue(String s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def orderlyQueue(self, s, k):\n \"\"\"\n :type s: str\n :type k: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def orderlyQueue(self, s: str, k: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * orderlyQueue(char * s, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string OrderlyQueue(string s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number} k\n * @return {string}\n */\nvar orderlyQueue = function(s, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer} k\n# @return {String}\ndef orderly_queue(s, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func orderlyQueue(_ s: String, _ k: Int) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func orderlyQueue(s string, k int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def orderlyQueue(s: String, k: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun orderlyQueue(s: String, k: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn orderly_queue(s: String, k: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer $k\n * @return String\n */\n function orderlyQueue($s, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function orderlyQueue(s: string, k: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (orderly-queue s k)\n (-> string? exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0899](https://leetcode-cn.com/problems/orderly-queue)", "[\u6709\u5e8f\u961f\u5217](/solution/0800-0899/0899.Orderly%20Queue/README.md)", "`\u6570\u5b66`,`\u5b57\u7b26\u4e32`", "\u56f0\u96be", ""], "md_table_row_en": ["[0899](https://leetcode.com/problems/orderly-queue)", "[Orderly Queue](/solution/0800-0899/0899.Orderly%20Queue/README_EN.md)", "`Math`,`String`", "Hard", ""]}, {"question_id": "0934", "frontend_question_id": "0898", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/bitwise-ors-of-subarrays", "url_en": "https://leetcode.com/problems/bitwise-ors-of-subarrays", "relative_path_cn": "/solution/0800-0899/0898.Bitwise%20ORs%20of%20Subarrays/README.md", "relative_path_en": "/solution/0800-0899/0898.Bitwise%20ORs%20of%20Subarrays/README_EN.md", "title_cn": "\u5b50\u6570\u7ec4\u6309\u4f4d\u6216\u64cd\u4f5c", "title_en": "Bitwise ORs of Subarrays", "question_title_slug": "bitwise-ors-of-subarrays", "content_en": "

    We have an array arr of non-negative integers.

    \n\n

    For every (contiguous) subarray sub = [arr[i], arr[i + 1], ..., arr[j]] (with i <= j), we take the bitwise OR of all the elements in sub, obtaining a result arr[i] | arr[i + 1] | ... | arr[j].

    \n\n

    Return the number of possible results. Results that occur more than once are only counted once in the final answer

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr = [0]\nOutput: 1\nExplanation: There is only one possible result: 0.\n
    \n\n

    Example 2:

    \n\n
    \nInput: arr = [1,1,2]\nOutput: 3\nExplanation: The possible subarrays are [1], [1], [2], [1, 1], [1, 2], [1, 1, 2].\nThese yield the results 1, 1, 2, 1, 3, 3.\nThere are 3 unique values, so the answer is 3.\n
    \n\n

    Example 3:

    \n\n
    \nInput: arr = [1,2,4]\nOutput: 6\nExplanation: The possible results are 1, 2, 3, 4, 6, and 7.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 5 * 104
    • \n\t
    • 0 <= nums[i] <= 109
    • \n
    \n", "content_cn": "

    \u6211\u4eec\u6709\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\u6570\u7ec4 A\u3002

    \n\n

    \u5bf9\u4e8e\u6bcf\u4e2a\uff08\u8fde\u7eed\u7684\uff09\u5b50\u6570\u7ec4 B = [A[i], A[i+1], ..., A[j]] \uff08 i <= j\uff09\uff0c\u6211\u4eec\u5bf9 B \u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u8fdb\u884c\u6309\u4f4d\u6216\u64cd\u4f5c\uff0c\u83b7\u5f97\u7ed3\u679c A[i] | A[i+1] | ... | A[j]\u3002

    \n\n

    \u8fd4\u56de\u53ef\u80fd\u7ed3\u679c\u7684\u6570\u91cf\u3002 \uff08\u591a\u6b21\u51fa\u73b0\u7684\u7ed3\u679c\u5728\u6700\u7ec8\u7b54\u6848\u4e2d\u4ec5\u8ba1\u7b97\u4e00\u6b21\u3002\uff09

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a[0]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\n\u53ea\u6709\u4e00\u4e2a\u53ef\u80fd\u7684\u7ed3\u679c 0 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a[1,1,2]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\n\u53ef\u80fd\u7684\u5b50\u6570\u7ec4\u4e3a [1]\uff0c[1]\uff0c[2]\uff0c[1, 1]\uff0c[1, 2]\uff0c[1, 1, 2]\u3002\n\u4ea7\u751f\u7684\u7ed3\u679c\u4e3a 1\uff0c1\uff0c2\uff0c1\uff0c3\uff0c3 \u3002\n\u6709\u4e09\u4e2a\u552f\u4e00\u503c\uff0c\u6240\u4ee5\u7b54\u6848\u662f 3 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1a[1,2,4]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\n\u53ef\u80fd\u7684\u7ed3\u679c\u662f 1\uff0c2\uff0c3\uff0c4\uff0c6\uff0c\u4ee5\u53ca 7 \u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= A.length <= 50000
    2. \n\t
    3. 0 <= A[i] <= 10^9
    4. \n
    \n", "tags_en": ["Bit Manipulation", "Dynamic Programming"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int subarrayBitwiseORs(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int subarrayBitwiseORs(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def subarrayBitwiseORs(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def subarrayBitwiseORs(self, arr: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint subarrayBitwiseORs(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SubarrayBitwiseORs(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar subarrayBitwiseORs = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef subarray_bitwise_o_rs(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func subarrayBitwiseORs(_ arr: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func subarrayBitwiseORs(arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def subarrayBitwiseORs(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun subarrayBitwiseORs(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn subarray_bitwise_o_rs(arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function subarrayBitwiseORs($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function subarrayBitwiseORs(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (subarray-bitwise-o-rs arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0898](https://leetcode-cn.com/problems/bitwise-ors-of-subarrays)", "[\u5b50\u6570\u7ec4\u6309\u4f4d\u6216\u64cd\u4f5c](/solution/0800-0899/0898.Bitwise%20ORs%20of%20Subarrays/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0898](https://leetcode.com/problems/bitwise-ors-of-subarrays)", "[Bitwise ORs of Subarrays](/solution/0800-0899/0898.Bitwise%20ORs%20of%20Subarrays/README_EN.md)", "`Bit Manipulation`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0933", "frontend_question_id": "0897", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/increasing-order-search-tree", "url_en": "https://leetcode.com/problems/increasing-order-search-tree", "relative_path_cn": "/solution/0800-0899/0897.Increasing%20Order%20Search%20Tree/README.md", "relative_path_en": "/solution/0800-0899/0897.Increasing%20Order%20Search%20Tree/README_EN.md", "title_cn": "\u9012\u589e\u987a\u5e8f\u641c\u7d22\u6811", "title_en": "Increasing Order Search Tree", "question_title_slug": "increasing-order-search-tree", "content_en": "

    Given the root of a binary search tree, rearrange the tree in in-order so that the leftmost node in the tree is now the root of the tree, and every node has no left child and only one right child.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\"\"\r\n
    \r\nInput: root = [5,3,6,2,4,null,8,1,null,null,null,7,9]\r\nOutput: [1,null,2,null,3,null,4,null,5,null,6,null,7,null,8,null,9]\r\n
    \r\n\r\n

    Example 2:

    \r\n\"\"\r\n
    \r\nInput: root = [5,1,7]\r\nOutput: [1,null,5,null,7]\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • The number of nodes in the given tree will be in the range [1, 100].
    • \r\n\t
    • 0 <= Node.val <= 1000
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u68f5\u4e8c\u53c9\u641c\u7d22\u6811\uff0c\u8bf7\u4f60 \u6309\u4e2d\u5e8f\u904d\u5386 \u5c06\u5176\u91cd\u65b0\u6392\u5217\u4e3a\u4e00\u68f5\u9012\u589e\u987a\u5e8f\u641c\u7d22\u6811\uff0c\u4f7f\u6811\u4e2d\u6700\u5de6\u8fb9\u7684\u8282\u70b9\u6210\u4e3a\u6811\u7684\u6839\u8282\u70b9\uff0c\u5e76\u4e14\u6bcf\u4e2a\u8282\u70b9\u6ca1\u6709\u5de6\u5b50\u8282\u70b9\uff0c\u53ea\u6709\u4e00\u4e2a\u53f3\u5b50\u8282\u70b9\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [5,3,6,2,4,null,8,1,null,null,null,7,9]\n\u8f93\u51fa\uff1a[1,null,2,null,3,null,4,null,5,null,6,null,7,null,8,null,9]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [5,1,7]\n\u8f93\u51fa\uff1a[1,null,5,null,7]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u6570\u7684\u53d6\u503c\u8303\u56f4\u662f [1, 100]
    • \n\t
    • 0 <= Node.val <= 1000
    • \n
    \n", "tags_en": ["Tree", "Depth-first Search", "Recursion"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u9012\u5f52"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* increasingBST(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode increasingBST(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def increasingBST(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: TreeNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def increasingBST(self, root: TreeNode) -> TreeNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* increasingBST(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode IncreasingBST(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {TreeNode}\n */\nvar increasingBST = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {TreeNode}\ndef increasing_bst(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func increasingBST(_ root: TreeNode?) -> TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc increasingBST(root *TreeNode) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def increasingBST(root: TreeNode): TreeNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun increasingBST(root: TreeNode?): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn increasing_bst(root: Option>>) -> Option>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return TreeNode\n */\n function increasingBST($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction increasingBST(root: TreeNode | null): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (increasing-bst root)\n (-> (or/c tree-node? #f) (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0897](https://leetcode-cn.com/problems/increasing-order-search-tree)", "[\u9012\u589e\u987a\u5e8f\u641c\u7d22\u6811](/solution/0800-0899/0897.Increasing%20Order%20Search%20Tree/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u9012\u5f52`", "\u7b80\u5355", ""], "md_table_row_en": ["[0897](https://leetcode.com/problems/increasing-order-search-tree)", "[Increasing Order Search Tree](/solution/0800-0899/0897.Increasing%20Order%20Search%20Tree/README_EN.md)", "`Tree`,`Depth-first Search`,`Recursion`", "Easy", ""]}, {"question_id": "0932", "frontend_question_id": "0896", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/monotonic-array", "url_en": "https://leetcode.com/problems/monotonic-array", "relative_path_cn": "/solution/0800-0899/0896.Monotonic%20Array/README.md", "relative_path_en": "/solution/0800-0899/0896.Monotonic%20Array/README_EN.md", "title_cn": "\u5355\u8c03\u6570\u5217", "title_en": "Monotonic Array", "question_title_slug": "monotonic-array", "content_en": "

    An array is monotonic if it is either monotone increasing or monotone decreasing.

    \n\n

    An array nums is monotone increasing if for all i <= j, nums[i] <= nums[j].  An array nums is monotone decreasing if for all i <= j, nums[i] >= nums[j].

    \n\n

    Return true if and only if the given array nums is monotonic.

    \n\n

     

    \n\n
      \n
    \n\n
    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,2,3]\nOutput: true\n
    \n\n
    \n

    Example 2:

    \n\n
    \nInput: nums = [6,5,4,4]\nOutput: true\n
    \n\n
    \n

    Example 3:

    \n\n
    \nInput: nums = [1,3,2]\nOutput: false\n
    \n\n
    \n

    Example 4:

    \n\n
    \nInput: nums = [1,2,4,5]\nOutput: true\n
    \n\n
    \n

    Example 5:

    \n\n
    \nInput: nums = [1,1,1]\nOutput: true\n
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    1. 1 <= nums.length <= 50000
    2. \n\t
    3. -100000 <= nums[i] <= 100000
    4. \n
    \n
    \n
    \n
    \n
    \n
    \n", "content_cn": "

    \u5982\u679c\u6570\u7ec4\u662f\u5355\u8c03\u9012\u589e\u6216\u5355\u8c03\u9012\u51cf\u7684\uff0c\u90a3\u4e48\u5b83\u662f\u5355\u8c03\u7684\u3002

    \n\n

    \u5982\u679c\u5bf9\u4e8e\u6240\u6709 i <= j\uff0cA[i] <= A[j]\uff0c\u90a3\u4e48\u6570\u7ec4 A \u662f\u5355\u8c03\u9012\u589e\u7684\u3002 \u5982\u679c\u5bf9\u4e8e\u6240\u6709 i <= j\uff0cA[i]> = A[j]\uff0c\u90a3\u4e48\u6570\u7ec4 A \u662f\u5355\u8c03\u9012\u51cf\u7684\u3002

    \n\n

    \u5f53\u7ed9\u5b9a\u7684\u6570\u7ec4 A \u662f\u5355\u8c03\u6570\u7ec4\u65f6\u8fd4\u56de true\uff0c\u5426\u5219\u8fd4\u56de false\u3002

    \n\n

     

    \n\n
      \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a[1,2,2,3]\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a[6,5,4,4]\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1a[1,3,2]\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1a[1,2,4,5]\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1a[1,1,1]\n\u8f93\u51fa\uff1atrue\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= A.length <= 50000
    2. \n\t
    3. -100000 <= A[i] <= 100000
    4. \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isMonotonic(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isMonotonic(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isMonotonic(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isMonotonic(self, nums: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isMonotonic(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsMonotonic(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {boolean}\n */\nvar isMonotonic = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Boolean}\ndef is_monotonic(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isMonotonic(_ nums: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isMonotonic(nums []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isMonotonic(nums: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isMonotonic(nums: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_monotonic(nums: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Boolean\n */\n function isMonotonic($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isMonotonic(nums: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-monotonic nums)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0896](https://leetcode-cn.com/problems/monotonic-array)", "[\u5355\u8c03\u6570\u5217](/solution/0800-0899/0896.Monotonic%20Array/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0896](https://leetcode.com/problems/monotonic-array)", "[Monotonic Array](/solution/0800-0899/0896.Monotonic%20Array/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0931", "frontend_question_id": "0895", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-frequency-stack", "url_en": "https://leetcode.com/problems/maximum-frequency-stack", "relative_path_cn": "/solution/0800-0899/0895.Maximum%20Frequency%20Stack/README.md", "relative_path_en": "/solution/0800-0899/0895.Maximum%20Frequency%20Stack/README_EN.md", "title_cn": "\u6700\u5927\u9891\u7387\u6808", "title_en": "Maximum Frequency Stack", "question_title_slug": "maximum-frequency-stack", "content_en": "

    Design a stack-like data structure to push elements to the stack and pop the most frequent element from the stack.

    \n\n

    Implement the FreqStack class:

    \n\n
      \n\t
    • FreqStack() constructs an empty frequency stack.
    • \n\t
    • void push(int val) pushes an integer val onto the top of the stack.
    • \n\t
    • int pop() removes and returns the most frequent element in the stack.\n\t
        \n\t\t
      • If there is a tie for the most frequent element, the element closest to the stack's top is removed and returned.
      • \n\t
      \n\t
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["FreqStack", "push", "push", "push", "push", "push", "push", "pop", "pop", "pop", "pop"]\n[[], [5], [7], [5], [7], [4], [5], [], [], [], []]\nOutput\n[null, null, null, null, null, null, null, 5, 7, 5, 4]\n\nExplanation\nFreqStack freqStack = new FreqStack();\nfreqStack.push(5); // The stack is [5]\nfreqStack.push(7); // The stack is [5,7]\nfreqStack.push(5); // The stack is [5,7,5]\nfreqStack.push(7); // The stack is [5,7,5,7]\nfreqStack.push(4); // The stack is [5,7,5,7,4]\nfreqStack.push(5); // The stack is [5,7,5,7,4,5]\nfreqStack.pop();   // return 5, as 5 is the most frequent. The stack becomes [5,7,5,7,4].\nfreqStack.pop();   // return 7, as 5 and 7 is the most frequent, but 7 is closest to the top. The stack becomes [5,7,5,4].\nfreqStack.pop();   // return 5, as 5 is the most frequent. The stack becomes [5,7,4].\nfreqStack.pop();   // return 4, as 4, 5 and 7 is the most frequent, but 4 is closest to the top. The stack becomes [5,7].\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= val <= 109
    • \n\t
    • At most 2 * 104 calls will be made to push and pop.
    • \n\t
    • It is guaranteed that there will be at least one element in the stack before calling pop.
    • \n
    \n", "content_cn": "

    \u5b9e\u73b0 FreqStack\uff0c\u6a21\u62df\u7c7b\u4f3c\u6808\u7684\u6570\u636e\u7ed3\u6784\u7684\u64cd\u4f5c\u7684\u4e00\u4e2a\u7c7b\u3002

    \n\n

    FreqStack \u6709\u4e24\u4e2a\u51fd\u6570\uff1a

    \n\n
      \n\t
    • push(int x)\uff0c\u5c06\u6574\u6570 x \u63a8\u5165\u6808\u4e2d\u3002
    • \n\t
    • pop()\uff0c\u5b83\u79fb\u9664\u5e76\u8fd4\u56de\u6808\u4e2d\u51fa\u73b0\u6700\u9891\u7e41\u7684\u5143\u7d20\u3002\n\t
        \n\t\t
      • \u5982\u679c\u6700\u9891\u7e41\u7684\u5143\u7d20\u4e0d\u53ea\u4e00\u4e2a\uff0c\u5219\u79fb\u9664\u5e76\u8fd4\u56de\u6700\u63a5\u8fd1\u6808\u9876\u7684\u5143\u7d20\u3002
      • \n\t
      \n\t
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1a\n["FreqStack","push","push","push","push","push","push","pop","pop","pop","pop"],\n[[],[5],[7],[5],[7],[4],[5],[],[],[],[]]\n\u8f93\u51fa\uff1a[null,null,null,null,null,null,null,5,7,5,4]\n\u89e3\u91ca\uff1a\n\u6267\u884c\u516d\u6b21 .push \u64cd\u4f5c\u540e\uff0c\u6808\u81ea\u5e95\u5411\u4e0a\u4e3a [5,7,5,7,4,5]\u3002\u7136\u540e\uff1a\n\npop() -> \u8fd4\u56de 5\uff0c\u56e0\u4e3a 5 \u662f\u51fa\u73b0\u9891\u7387\u6700\u9ad8\u7684\u3002\n\u6808\u53d8\u6210 [5,7,5,7,4]\u3002\n\npop() -> \u8fd4\u56de 7\uff0c\u56e0\u4e3a 5 \u548c 7 \u90fd\u662f\u9891\u7387\u6700\u9ad8\u7684\uff0c\u4f46 7 \u6700\u63a5\u8fd1\u6808\u9876\u3002\n\u6808\u53d8\u6210 [5,7,5,4]\u3002\n\npop() -> \u8fd4\u56de 5 \u3002\n\u6808\u53d8\u6210 [5,7,4]\u3002\n\npop() -> \u8fd4\u56de 4 \u3002\n\u6808\u53d8\u6210 [5,7]\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u5bf9 FreqStack.push(int x) \u7684\u8c03\u7528\u4e2d 0 <= x <= 10^9\u3002
    • \n\t
    • \u5982\u679c\u6808\u7684\u5143\u7d20\u6570\u76ee\u4e3a\u96f6\uff0c\u5219\u4fdd\u8bc1\u4e0d\u4f1a\u8c03\u7528  FreqStack.pop()\u3002
    • \n\t
    • \u5355\u4e2a\u6d4b\u8bd5\u6837\u4f8b\u4e2d\uff0c\u5bf9 FreqStack.push \u7684\u603b\u8c03\u7528\u6b21\u6570\u4e0d\u4f1a\u8d85\u8fc7 10000\u3002
    • \n\t
    • \u5355\u4e2a\u6d4b\u8bd5\u6837\u4f8b\u4e2d\uff0c\u5bf9 FreqStack.pop \u7684\u603b\u8c03\u7528\u6b21\u6570\u4e0d\u4f1a\u8d85\u8fc7 10000\u3002
    • \n\t
    • \u6240\u6709\u6d4b\u8bd5\u6837\u4f8b\u4e2d\uff0c\u5bf9 FreqStack.push \u548c FreqStack.pop \u7684\u603b\u8c03\u7528\u6b21\u6570\u4e0d\u4f1a\u8d85\u8fc7 150000\u3002
    • \n
    \n\n

     

    \n", "tags_en": ["Stack", "Hash Table"], "tags_cn": ["\u6808", "\u54c8\u5e0c\u8868"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class FreqStack {\npublic:\n FreqStack() {\n\n }\n \n void push(int val) {\n\n }\n \n int pop() {\n\n }\n};\n\n/**\n * Your FreqStack object will be instantiated and called as such:\n * FreqStack* obj = new FreqStack();\n * obj->push(val);\n * int param_2 = obj->pop();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class FreqStack {\n\n public FreqStack() {\n\n }\n \n public void push(int val) {\n\n }\n \n public int pop() {\n\n }\n}\n\n/**\n * Your FreqStack object will be instantiated and called as such:\n * FreqStack obj = new FreqStack();\n * obj.push(val);\n * int param_2 = obj.pop();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class FreqStack(object):\n\n def __init__(self):\n\n\n def push(self, val):\n \"\"\"\n :type val: int\n :rtype: None\n \"\"\"\n\n\n def pop(self):\n \"\"\"\n :rtype: int\n \"\"\"\n\n\n\n# Your FreqStack object will be instantiated and called as such:\n# obj = FreqStack()\n# obj.push(val)\n# param_2 = obj.pop()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class FreqStack:\n\n def __init__(self):\n\n\n def push(self, val: int) -> None:\n\n\n def pop(self) -> int:\n\n\n\n# Your FreqStack object will be instantiated and called as such:\n# obj = FreqStack()\n# obj.push(val)\n# param_2 = obj.pop()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} FreqStack;\n\n\nFreqStack* freqStackCreate() {\n\n}\n\nvoid freqStackPush(FreqStack* obj, int val) {\n\n}\n\nint freqStackPop(FreqStack* obj) {\n\n}\n\nvoid freqStackFree(FreqStack* obj) {\n\n}\n\n/**\n * Your FreqStack struct will be instantiated and called as such:\n * FreqStack* obj = freqStackCreate();\n * freqStackPush(obj, val);\n \n * int param_2 = freqStackPop(obj);\n \n * freqStackFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class FreqStack {\n\n public FreqStack() {\n\n }\n \n public void Push(int val) {\n\n }\n \n public int Pop() {\n\n }\n}\n\n/**\n * Your FreqStack object will be instantiated and called as such:\n * FreqStack obj = new FreqStack();\n * obj.Push(val);\n * int param_2 = obj.Pop();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "\nvar FreqStack = function() {\n\n};\n\n/** \n * @param {number} val\n * @return {void}\n */\nFreqStack.prototype.push = function(val) {\n\n};\n\n/**\n * @return {number}\n */\nFreqStack.prototype.pop = function() {\n\n};\n\n/**\n * Your FreqStack object will be instantiated and called as such:\n * var obj = new FreqStack()\n * obj.push(val)\n * var param_2 = obj.pop()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class FreqStack\n def initialize()\n\n end\n\n\n=begin\n :type val: Integer\n :rtype: Void\n=end\n def push(val)\n\n end\n\n\n=begin\n :rtype: Integer\n=end\n def pop()\n\n end\n\n\nend\n\n# Your FreqStack object will be instantiated and called as such:\n# obj = FreqStack.new()\n# obj.push(val)\n# param_2 = obj.pop()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass FreqStack {\n\n init() {\n\n }\n \n func push(_ val: Int) {\n\n }\n \n func pop() -> Int {\n\n }\n}\n\n/**\n * Your FreqStack object will be instantiated and called as such:\n * let obj = FreqStack()\n * obj.push(val)\n * let ret_2: Int = obj.pop()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type FreqStack struct {\n\n}\n\n\nfunc Constructor() FreqStack {\n\n}\n\n\nfunc (this *FreqStack) Push(val int) {\n\n}\n\n\nfunc (this *FreqStack) Pop() int {\n\n}\n\n\n/**\n * Your FreqStack object will be instantiated and called as such:\n * obj := Constructor();\n * obj.Push(val);\n * param_2 := obj.Pop();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class FreqStack() {\n\n def push(`val`: Int) {\n\n }\n\n def pop(): Int = {\n\n }\n\n}\n\n/**\n * Your FreqStack object will be instantiated and called as such:\n * var obj = new FreqStack()\n * obj.push(`val`)\n * var param_2 = obj.pop()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class FreqStack() {\n\n fun push(`val`: Int) {\n\n }\n\n fun pop(): Int {\n\n }\n\n}\n\n/**\n * Your FreqStack object will be instantiated and called as such:\n * var obj = FreqStack()\n * obj.push(`val`)\n * var param_2 = obj.pop()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct FreqStack {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl FreqStack {\n\n fn new() -> Self {\n\n }\n \n fn push(&self, val: i32) {\n\n }\n \n fn pop(&self) -> i32 {\n\n }\n}\n\n/**\n * Your FreqStack object will be instantiated and called as such:\n * let obj = FreqStack::new();\n * obj.push(val);\n * let ret_2: i32 = obj.pop();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class FreqStack {\n /**\n */\n function __construct() {\n\n }\n\n /**\n * @param Integer $val\n * @return NULL\n */\n function push($val) {\n\n }\n\n /**\n * @return Integer\n */\n function pop() {\n\n }\n}\n\n/**\n * Your FreqStack object will be instantiated and called as such:\n * $obj = FreqStack();\n * $obj->push($val);\n * $ret_2 = $obj->pop();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class FreqStack {\n constructor() {\n\n }\n\n push(val: number): void {\n\n }\n\n pop(): number {\n\n }\n}\n\n/**\n * Your FreqStack object will be instantiated and called as such:\n * var obj = new FreqStack()\n * obj.push(val)\n * var param_2 = obj.pop()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define freq-stack%\n (class object%\n (super-new)\n (init-field)\n \n ; push : exact-integer? -> void?\n (define/public (push val)\n\n )\n ; pop : -> exact-integer?\n (define/public (pop)\n\n )))\n\n;; Your freq-stack% object will be instantiated and called as such:\n;; (define obj (new freq-stack%))\n;; (send obj push val)\n;; (define param_2 (send obj pop))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0895](https://leetcode-cn.com/problems/maximum-frequency-stack)", "[\u6700\u5927\u9891\u7387\u6808](/solution/0800-0899/0895.Maximum%20Frequency%20Stack/README.md)", "`\u6808`,`\u54c8\u5e0c\u8868`", "\u56f0\u96be", ""], "md_table_row_en": ["[0895](https://leetcode.com/problems/maximum-frequency-stack)", "[Maximum Frequency Stack](/solution/0800-0899/0895.Maximum%20Frequency%20Stack/README_EN.md)", "`Stack`,`Hash Table`", "Hard", ""]}, {"question_id": "0930", "frontend_question_id": "0894", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/all-possible-full-binary-trees", "url_en": "https://leetcode.com/problems/all-possible-full-binary-trees", "relative_path_cn": "/solution/0800-0899/0894.All%20Possible%20Full%20Binary%20Trees/README.md", "relative_path_en": "/solution/0800-0899/0894.All%20Possible%20Full%20Binary%20Trees/README_EN.md", "title_cn": "\u6240\u6709\u53ef\u80fd\u7684\u6ee1\u4e8c\u53c9\u6811", "title_en": "All Possible Full Binary Trees", "question_title_slug": "all-possible-full-binary-trees", "content_en": "

    Given an integer n, return a list of all possible full binary trees with n nodes. Each node of each tree in the answer must have Node.val == 0.

    \n\n

    Each element of the answer is the root node of one possible tree. You may return the final list of trees in any order.

    \n\n

    A full binary tree is a binary tree where each node has exactly 0 or 2 children.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: n = 7\nOutput: [[0,0,0,null,null,0,0,null,null,0,0],[0,0,0,null,null,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,null,null,null,null,0,0],[0,0,0,0,0,null,null,0,0]]\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 3\nOutput: [[0,0,0]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 20
    • \n
    \n", "content_cn": "

    \u6ee1\u4e8c\u53c9\u6811\u662f\u4e00\u7c7b\u4e8c\u53c9\u6811\uff0c\u5176\u4e2d\u6bcf\u4e2a\u7ed3\u70b9\u6070\u597d\u6709 0 \u6216 2 \u4e2a\u5b50\u7ed3\u70b9\u3002

    \n\n

    \u8fd4\u56de\u5305\u542b N \u4e2a\u7ed3\u70b9\u7684\u6240\u6709\u53ef\u80fd\u6ee1\u4e8c\u53c9\u6811\u7684\u5217\u8868\u3002 \u7b54\u6848\u7684\u6bcf\u4e2a\u5143\u7d20\u90fd\u662f\u4e00\u4e2a\u53ef\u80fd\u6811\u7684\u6839\u7ed3\u70b9\u3002

    \n\n

    \u7b54\u6848\u4e2d\u6bcf\u4e2a\u6811\u7684\u6bcf\u4e2a\u7ed3\u70b9\u90fd\u5fc5\u987b\u6709 node.val=0\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u6309\u4efb\u4f55\u987a\u5e8f\u8fd4\u56de\u6811\u7684\u6700\u7ec8\u5217\u8868\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1a7\n\u8f93\u51fa\uff1a[[0,0,0,null,null,0,0,null,null,0,0],[0,0,0,null,null,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,null,null,null,null,0,0],[0,0,0,0,0,null,null,0,0]]\n\u89e3\u91ca\uff1a\n\"\"\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= N <= 20
    • \n
    \n", "tags_en": ["Tree", "Recursion"], "tags_cn": ["\u6811", "\u9012\u5f52"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector allPossibleFBT(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public List allPossibleFBT(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def allPossibleFBT(self, n):\n \"\"\"\n :type n: int\n :rtype: List[TreeNode]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def allPossibleFBT(self, n: int) -> List[TreeNode]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nstruct TreeNode** allPossibleFBT(int n, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public IList AllPossibleFBT(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {number} n\n * @return {TreeNode[]}\n */\nvar allPossibleFBT = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {Integer} n\n# @return {TreeNode[]}\ndef all_possible_fbt(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func allPossibleFBT(_ n: Int) -> [TreeNode?] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc allPossibleFBT(n int) []*TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def allPossibleFBT(n: Int): List[TreeNode] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun allPossibleFBT(n: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn all_possible_fbt(n: i32) -> Vec>>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param Integer $n\n * @return TreeNode[]\n */\n function allPossibleFBT($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction allPossibleFBT(n: number): Array {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (all-possible-fbt n)\n (-> exact-integer? (listof (or/c tree-node? #f)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0894](https://leetcode-cn.com/problems/all-possible-full-binary-trees)", "[\u6240\u6709\u53ef\u80fd\u7684\u6ee1\u4e8c\u53c9\u6811](/solution/0800-0899/0894.All%20Possible%20Full%20Binary%20Trees/README.md)", "`\u6811`,`\u9012\u5f52`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0894](https://leetcode.com/problems/all-possible-full-binary-trees)", "[All Possible Full Binary Trees](/solution/0800-0899/0894.All%20Possible%20Full%20Binary%20Trees/README_EN.md)", "`Tree`,`Recursion`", "Medium", ""]}, {"question_id": "0929", "frontend_question_id": "0893", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/groups-of-special-equivalent-strings", "url_en": "https://leetcode.com/problems/groups-of-special-equivalent-strings", "relative_path_cn": "/solution/0800-0899/0893.Groups%20of%20Special-Equivalent%20Strings/README.md", "relative_path_en": "/solution/0800-0899/0893.Groups%20of%20Special-Equivalent%20Strings/README_EN.md", "title_cn": "\u7279\u6b8a\u7b49\u4ef7\u5b57\u7b26\u4e32\u7ec4", "title_en": "Groups of Special-Equivalent Strings", "question_title_slug": "groups-of-special-equivalent-strings", "content_en": "

    You are given an array words of strings.

    \n\n

    A move onto s consists of swapping any two even indexed characters of s, or any two odd indexed characters of s.

    \n\n

    Two strings s and t are special-equivalent if after any number of moves onto s, s == t.

    \n\n

    For example, s = "zzxy" and t = "xyzz" are special-equivalent because we may make the moves "zzxy" -> "xzzy" -> "xyzz" that swap s[0] and s[2], then s[1] and s[3].

    \n\n

    Now, a group of special-equivalent strings from words is a non-empty subset of words such that:

    \n\n
      \n\t
    1. Every pair of strings in the group are special equivalent, and;
    2. \n\t
    3. The group is the largest size possible (ie., there isn't a string s not in the group such that s is special equivalent to every string in the group)
    4. \n
    \n\n

    Return the number of groups of special-equivalent strings from words.

    \n\n
     
    \n\n
    \n

    Example 1:

    \n\n
    \nInput: words = ["abcd","cdab","cbad","xyzz","zzxy","zzyx"]\nOutput: 3\nExplanation: \nOne group is ["abcd", "cdab", "cbad"], since they are all pairwise special equivalent, and none of the other strings are all pairwise special equivalent to these.\n\nThe other two groups are ["xyzz", "zzxy"] and ["zzyx"].  Note that in particular, "zzxy" is not special equivalent to "zzyx".\n
    \n\n
    \n

    Example 2:

    \n\n
    \nInput: words = ["abc","acb","bac","bca","cab","cba"]\nOutput: 3
    \n\n

     

    \n
    \n
    \n\n
    \n
    \n
    \n
    \n

    Note:

    \n\n
      \n\t
    • 1 <= words.length <= 1000
    • \n\t
    • 1 <= words[i].length <= 20
    • \n\t
    • All words[i] have the same length.
    • \n\t
    • All words[i] consist of only lowercase letters.
    • \n
    \n
    \n
    \n
    \n
    \n", "content_cn": "

    \u4f60\u5c06\u5f97\u5230\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4 A\u3002

    \n\n

    \u6bcf\u6b21\u79fb\u52a8\u90fd\u53ef\u4ee5\u4ea4\u6362 S \u7684\u4efb\u610f\u4e24\u4e2a\u5076\u6570\u4e0b\u6807\u7684\u5b57\u7b26\u6216\u4efb\u610f\u4e24\u4e2a\u5947\u6570\u4e0b\u6807\u7684\u5b57\u7b26\u3002

    \n\n

    \u5982\u679c\u7ecf\u8fc7\u4efb\u610f\u6b21\u6570\u7684\u79fb\u52a8\uff0cS == T\uff0c\u90a3\u4e48\u4e24\u4e2a\u5b57\u7b26\u4e32 S \u548c T \u662f \u7279\u6b8a\u7b49\u4ef7 \u7684\u3002

    \n\n

    \u4f8b\u5982\uff0cS = "zzxy" \u548c T = "xyzz" \u662f\u4e00\u5bf9\u7279\u6b8a\u7b49\u4ef7\u5b57\u7b26\u4e32\uff0c\u56e0\u4e3a\u53ef\u4ee5\u5148\u4ea4\u6362 S[0] \u548c S[2]\uff0c\u7136\u540e\u4ea4\u6362 S[1] \u548c S[3]\uff0c\u4f7f\u5f97 "zzxy" -> "xzzy" -> "xyzz" \u3002

    \n\n

    \u73b0\u5728\u89c4\u5b9a\uff0cA \u7684 \u4e00\u7ec4\u7279\u6b8a\u7b49\u4ef7\u5b57\u7b26\u4e32 \u5c31\u662f A \u7684\u4e00\u4e2a\u540c\u65f6\u6ee1\u8db3\u4e0b\u8ff0\u6761\u4ef6\u7684\u975e\u7a7a\u5b50\u96c6\uff1a

    \n\n
      \n\t
    1. \u8be5\u7ec4\u4e2d\u7684\u6bcf\u4e00\u5bf9\u5b57\u7b26\u4e32\u90fd\u662f \u7279\u6b8a\u7b49\u4ef7 \u7684
    2. \n\t
    3. \u8be5\u7ec4\u5b57\u7b26\u4e32\u5df2\u7ecf\u6db5\u76d6\u4e86\u8be5\u7c7b\u522b\u4e2d\u7684\u6240\u6709\u7279\u6b8a\u7b49\u4ef7\u5b57\u7b26\u4e32\uff0c\u5bb9\u91cf\u8fbe\u5230\u7406\u8bba\u4e0a\u7684\u6700\u5927\u503c\uff08\u4e5f\u5c31\u662f\u8bf4\uff0c\u5982\u679c\u4e00\u4e2a\u5b57\u7b26\u4e32\u4e0d\u5728\u8be5\u7ec4\u4e2d\uff0c\u90a3\u4e48\u8fd9\u4e2a\u5b57\u7b26\u4e32\u5c31 \u4e0d\u4f1a \u4e0e\u8be5\u7ec4\u5185\u4efb\u4f55\u5b57\u7b26\u4e32\u7279\u6b8a\u7b49\u4ef7\uff09
    4. \n
    \n\n

    \u8fd4\u56de A \u4e2d\u7279\u6b8a\u7b49\u4ef7\u5b57\u7b26\u4e32\u7ec4\u7684\u6570\u91cf\u3002

    \n\n

     

    \n\n
      \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a["abcd","cdab","cbad","xyzz","zzxy","zzyx"]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\n\u5176\u4e2d\u4e00\u7ec4\u4e3a ["abcd", "cdab", "cbad"]\uff0c\u56e0\u4e3a\u5b83\u4eec\u662f\u6210\u5bf9\u7684\u7279\u6b8a\u7b49\u4ef7\u5b57\u7b26\u4e32\uff0c\u4e14\u6ca1\u6709\u5176\u4ed6\u5b57\u7b26\u4e32\u4e0e\u8fd9\u4e9b\u5b57\u7b26\u4e32\u7279\u6b8a\u7b49\u4ef7\u3002\n\u53e6\u5916\u4e24\u7ec4\u5206\u522b\u662f ["xyzz", "zzxy"] \u548c ["zzyx"]\u3002\u7279\u522b\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c"zzxy" \u4e0d\u4e0e "zzyx" \u7279\u6b8a\u7b49\u4ef7\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a["abc","acb","bac","bca","cab","cba"]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a3 \u7ec4 ["abc","cba"]\uff0c["acb","bca"]\uff0c["bac","cab"]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= A.length <= 1000
    • \n\t
    • 1 <= A[i].length <= 20
    • \n\t
    • \u6240\u6709 A[i] \u90fd\u5177\u6709\u76f8\u540c\u7684\u957f\u5ea6\u3002
    • \n\t
    • \u6240\u6709 A[i] \u90fd\u53ea\u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210\u3002
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numSpecialEquivGroups(vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numSpecialEquivGroups(String[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numSpecialEquivGroups(self, words):\n \"\"\"\n :type words: List[str]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numSpecialEquivGroups(self, words: List[str]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numSpecialEquivGroups(char ** words, int wordsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumSpecialEquivGroups(string[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @return {number}\n */\nvar numSpecialEquivGroups = function(words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @return {Integer}\ndef num_special_equiv_groups(words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numSpecialEquivGroups(_ words: [String]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numSpecialEquivGroups(words []string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numSpecialEquivGroups(words: Array[String]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numSpecialEquivGroups(words: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_special_equiv_groups(words: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @return Integer\n */\n function numSpecialEquivGroups($words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numSpecialEquivGroups(words: string[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-special-equiv-groups words)\n (-> (listof string?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0893](https://leetcode-cn.com/problems/groups-of-special-equivalent-strings)", "[\u7279\u6b8a\u7b49\u4ef7\u5b57\u7b26\u4e32\u7ec4](/solution/0800-0899/0893.Groups%20of%20Special-Equivalent%20Strings/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0893](https://leetcode.com/problems/groups-of-special-equivalent-strings)", "[Groups of Special-Equivalent Strings](/solution/0800-0899/0893.Groups%20of%20Special-Equivalent%20Strings/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "0928", "frontend_question_id": "0892", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/surface-area-of-3d-shapes", "url_en": "https://leetcode.com/problems/surface-area-of-3d-shapes", "relative_path_cn": "/solution/0800-0899/0892.Surface%20Area%20of%203D%20Shapes/README.md", "relative_path_en": "/solution/0800-0899/0892.Surface%20Area%20of%203D%20Shapes/README_EN.md", "title_cn": "\u4e09\u7ef4\u5f62\u4f53\u7684\u8868\u9762\u79ef", "title_en": "Surface Area of 3D Shapes", "question_title_slug": "surface-area-of-3d-shapes", "content_en": "

    You are given an n x n grid where you have placed some 1 x 1 x 1 cubes. Each value v = grid[i][j] represents a tower of v cubes placed on top of cell (i, j).

    \n\n

    After placing these cubes, you have decided to glue any directly adjacent cubes to each other, forming several irregular 3D shapes.

    \n\n

    Return the total surface area of the resulting shapes.

    \n\n

    Note: The bottom face of each shape counts toward its surface area.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: grid = [[2]]\nOutput: 10\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: grid = [[1,2],[3,4]]\nOutput: 34\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: grid = [[1,0],[0,2]]\nOutput: 16\n
    \n\n

    Example 4:

    \n\"\"\n
    \nInput: grid = [[1,1,1],[1,0,1],[1,1,1]]\nOutput: 32\n
    \n\n

    Example 5:

    \n\"\"\n
    \nInput: grid = [[2,2,2],[2,1,2],[2,2,2]]\nOutput: 46\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= n <= 50
    • \n\t
    • 0 <= grid[i][j] <= 50
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a n * n \u7684\u7f51\u683c\u00a0grid \uff0c\u4e0a\u9762\u653e\u7f6e\u7740\u4e00\u4e9b\u00a01 x 1 x 1\u00a0\u7684\u6b63\u65b9\u4f53\u3002

    \n\n

    \u6bcf\u4e2a\u503c\u00a0v = grid[i][j]\u00a0\u8868\u793a\u00a0v\u00a0\u4e2a\u6b63\u65b9\u4f53\u53e0\u653e\u5728\u5bf9\u5e94\u5355\u5143\u683c\u00a0(i, j)\u00a0\u4e0a\u3002

    \n\n

    \u653e\u7f6e\u597d\u6b63\u65b9\u4f53\u540e\uff0c\u4efb\u4f55\u76f4\u63a5\u76f8\u90bb\u7684\u6b63\u65b9\u4f53\u90fd\u4f1a\u4e92\u76f8\u7c98\u5728\u4e00\u8d77\uff0c\u5f62\u6210\u4e00\u4e9b\u4e0d\u89c4\u5219\u7684\u4e09\u7ef4\u5f62\u4f53\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u6700\u7ec8\u8fd9\u4e9b\u5f62\u4f53\u7684\u603b\u8868\u9762\u79ef\u3002

    \n\n

    \u6ce8\u610f\uff1a\u6bcf\u4e2a\u5f62\u4f53\u7684\u5e95\u9762\u4e5f\u9700\u8981\u8ba1\u5165\u8868\u9762\u79ef\u4e2d\u3002

    \n\n

    \u00a0

    \n\n
      \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1agrid = [[2]]\n\u8f93\u51fa\uff1a10\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1agrid = [[1,2],[3,4]]\n\u8f93\u51fa\uff1a34\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1agrid = [[1,0],[0,2]]\n\u8f93\u51fa\uff1a16\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1agrid = [[1,1,1],[1,0,1],[1,1,1]]\n\u8f93\u51fa\uff1a32\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1agrid = [[2,2,2],[2,1,2],[2,2,2]]\n\u8f93\u51fa\uff1a46\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= n <= 50
    • \n\t
    • 0 <= grid[i][j] <= 50
    • \n
    \n", "tags_en": ["Geometry", "Math"], "tags_cn": ["\u51e0\u4f55", "\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int surfaceArea(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int surfaceArea(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def surfaceArea(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def surfaceArea(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint surfaceArea(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SurfaceArea(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar surfaceArea = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef surface_area(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func surfaceArea(_ grid: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func surfaceArea(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def surfaceArea(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun surfaceArea(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn surface_area(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function surfaceArea($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function surfaceArea(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (surface-area grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0892](https://leetcode-cn.com/problems/surface-area-of-3d-shapes)", "[\u4e09\u7ef4\u5f62\u4f53\u7684\u8868\u9762\u79ef](/solution/0800-0899/0892.Surface%20Area%20of%203D%20Shapes/README.md)", "`\u51e0\u4f55`,`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0892](https://leetcode.com/problems/surface-area-of-3d-shapes)", "[Surface Area of 3D Shapes](/solution/0800-0899/0892.Surface%20Area%20of%203D%20Shapes/README_EN.md)", "`Geometry`,`Math`", "Easy", ""]}, {"question_id": "0927", "frontend_question_id": "0891", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sum-of-subsequence-widths", "url_en": "https://leetcode.com/problems/sum-of-subsequence-widths", "relative_path_cn": "/solution/0800-0899/0891.Sum%20of%20Subsequence%20Widths/README.md", "relative_path_en": "/solution/0800-0899/0891.Sum%20of%20Subsequence%20Widths/README_EN.md", "title_cn": "\u5b50\u5e8f\u5217\u5bbd\u5ea6\u4e4b\u548c", "title_en": "Sum of Subsequence Widths", "question_title_slug": "sum-of-subsequence-widths", "content_en": "

    Given an array of integers nums, consider all non-empty subsequences of nums.

    \n\n

    For any sequence seq, let the width of seq be the difference between the maximum and minimum element of seq.

    \n\n

    Return the sum of the widths of all subsequences of nums

    \n\n

    As the answer may be very large, return the answer modulo 109 + 7.

    \n\n
    \n

     

    \n\n

    Example 1:

    \n\n
    \nInput: nums = [2,1,3]\nOutput: 6\nExplanation:\nSubsequences are [1], [2], [3], [2,1], [2,3], [1,3], [2,1,3].\nThe corresponding widths are 0, 0, 0, 1, 1, 2, 2.\nThe sum of these widths is 6.\n
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    • 1 <= nums.length <= 20000
    • \n\t
    • 1 <= nums[i] <= 20000
    • \n
    \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 A \uff0c\u8003\u8651 A \u7684\u6240\u6709\u975e\u7a7a\u5b50\u5e8f\u5217\u3002

    \n\n

    \u5bf9\u4e8e\u4efb\u610f\u5e8f\u5217 S \uff0c\u8bbe S \u7684\u5bbd\u5ea6\u662f S \u7684\u6700\u5927\u5143\u7d20\u548c\u6700\u5c0f\u5143\u7d20\u7684\u5dee\u3002

    \n\n

    \u8fd4\u56de A \u7684\u6240\u6709\u5b50\u5e8f\u5217\u7684\u5bbd\u5ea6\u4e4b\u548c\u3002

    \n\n

    \u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u975e\u5e38\u5927\uff0c\u8bf7\u8fd4\u56de\u7b54\u6848\u6a21 10^9+7\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1a[2,1,3]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\n\u5b50\u5e8f\u5217\u4e3a [1]\uff0c[2]\uff0c[3]\uff0c[2,1]\uff0c[2,3]\uff0c[1,3]\uff0c[2,1,3] \u3002\n\u76f8\u5e94\u7684\u5bbd\u5ea6\u662f 0\uff0c0\uff0c0\uff0c1\uff0c1\uff0c2\uff0c2 \u3002\n\u8fd9\u4e9b\u5bbd\u5ea6\u4e4b\u548c\u662f 6 \u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= A.length <= 20000
    • \n\t
    • 1 <= A[i] <= 20000
    • \n
    \n", "tags_en": ["Array", "Math"], "tags_cn": ["\u6570\u7ec4", "\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int sumSubseqWidths(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int sumSubseqWidths(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def sumSubseqWidths(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def sumSubseqWidths(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint sumSubseqWidths(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SumSubseqWidths(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar sumSubseqWidths = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef sum_subseq_widths(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func sumSubseqWidths(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func sumSubseqWidths(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def sumSubseqWidths(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun sumSubseqWidths(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sum_subseq_widths(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function sumSubseqWidths($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function sumSubseqWidths(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (sum-subseq-widths nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0891](https://leetcode-cn.com/problems/sum-of-subsequence-widths)", "[\u5b50\u5e8f\u5217\u5bbd\u5ea6\u4e4b\u548c](/solution/0800-0899/0891.Sum%20of%20Subsequence%20Widths/README.md)", "`\u6570\u7ec4`,`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[0891](https://leetcode.com/problems/sum-of-subsequence-widths)", "[Sum of Subsequence Widths](/solution/0800-0899/0891.Sum%20of%20Subsequence%20Widths/README_EN.md)", "`Array`,`Math`", "Hard", ""]}, {"question_id": "0926", "frontend_question_id": "0890", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-and-replace-pattern", "url_en": "https://leetcode.com/problems/find-and-replace-pattern", "relative_path_cn": "/solution/0800-0899/0890.Find%20and%20Replace%20Pattern/README.md", "relative_path_en": "/solution/0800-0899/0890.Find%20and%20Replace%20Pattern/README_EN.md", "title_cn": "\u67e5\u627e\u548c\u66ff\u6362\u6a21\u5f0f", "title_en": "Find and Replace Pattern", "question_title_slug": "find-and-replace-pattern", "content_en": "

    Given a list of strings words and a string pattern, return a list of words[i] that match pattern. You may return the answer in any order.

    \n\n

    A word matches the pattern if there exists a permutation of letters p so that after replacing every letter x in the pattern with p(x), we get the desired word.

    \n\n

    Recall that a permutation of letters is a bijection from letters to letters: every letter maps to another letter, and no two letters map to the same letter.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: words = ["abc","deq","mee","aqq","dkd","ccc"], pattern = "abb"\nOutput: ["mee","aqq"]\nExplanation: "mee" matches the pattern because there is a permutation {a -> m, b -> e, ...}. \n"ccc" does not match the pattern because {a -> c, b -> c, ...} is not a permutation, since a and b map to the same letter.\n
    \n\n

    Example 2:

    \n\n
    \nInput: words = ["a","b","c"], pattern = "a"\nOutput: ["a","b","c"]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= pattern.length <= 20
    • \n\t
    • 1 <= words.length <= 50
    • \n\t
    • words[i].length == pattern.length
    • \n\t
    • pattern and words[i] are lowercase English letters.
    • \n
    \n", "content_cn": "

    \u4f60\u6709\u4e00\u4e2a\u5355\u8bcd\u5217\u8868 words \u548c\u4e00\u4e2a\u6a21\u5f0f  pattern\uff0c\u4f60\u60f3\u77e5\u9053 words \u4e2d\u7684\u54ea\u4e9b\u5355\u8bcd\u4e0e\u6a21\u5f0f\u5339\u914d\u3002

    \n\n

    \u5982\u679c\u5b58\u5728\u5b57\u6bcd\u7684\u6392\u5217 p \uff0c\u4f7f\u5f97\u5c06\u6a21\u5f0f\u4e2d\u7684\u6bcf\u4e2a\u5b57\u6bcd x \u66ff\u6362\u4e3a p(x) \u4e4b\u540e\uff0c\u6211\u4eec\u5c31\u5f97\u5230\u4e86\u6240\u9700\u7684\u5355\u8bcd\uff0c\u90a3\u4e48\u5355\u8bcd\u4e0e\u6a21\u5f0f\u662f\u5339\u914d\u7684\u3002

    \n\n

    \uff08\u56de\u60f3\u4e00\u4e0b\uff0c\u5b57\u6bcd\u7684\u6392\u5217\u662f\u4ece\u5b57\u6bcd\u5230\u5b57\u6bcd\u7684\u53cc\u5c04\uff1a\u6bcf\u4e2a\u5b57\u6bcd\u6620\u5c04\u5230\u53e6\u4e00\u4e2a\u5b57\u6bcd\uff0c\u6ca1\u6709\u4e24\u4e2a\u5b57\u6bcd\u6620\u5c04\u5230\u540c\u4e00\u4e2a\u5b57\u6bcd\u3002\uff09

    \n\n

    \u8fd4\u56de words \u4e2d\u4e0e\u7ed9\u5b9a\u6a21\u5f0f\u5339\u914d\u7684\u5355\u8bcd\u5217\u8868\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u6309\u4efb\u4f55\u987a\u5e8f\u8fd4\u56de\u7b54\u6848\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1awords = ["abc","deq","mee","aqq","dkd","ccc"], pattern = "abb"\n\u8f93\u51fa\uff1a["mee","aqq"]\n\u89e3\u91ca\uff1a\n"mee" \u4e0e\u6a21\u5f0f\u5339\u914d\uff0c\u56e0\u4e3a\u5b58\u5728\u6392\u5217 {a -> m, b -> e, ...}\u3002\n"ccc" \u4e0e\u6a21\u5f0f\u4e0d\u5339\u914d\uff0c\u56e0\u4e3a {a -> c, b -> c, ...} \u4e0d\u662f\u6392\u5217\u3002\n\u56e0\u4e3a a \u548c b \u6620\u5c04\u5230\u540c\u4e00\u4e2a\u5b57\u6bcd\u3002
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= words.length <= 50
    • \n\t
    • 1 <= pattern.length = words[i].length <= 20
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findAndReplacePattern(vector& words, string pattern) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List findAndReplacePattern(String[] words, String pattern) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findAndReplacePattern(self, words, pattern):\n \"\"\"\n :type words: List[str]\n :type pattern: str\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findAndReplacePattern(self, words: List[str], pattern: str) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** findAndReplacePattern(char ** words, int wordsSize, char * pattern, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList FindAndReplacePattern(string[] words, string pattern) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @param {string} pattern\n * @return {string[]}\n */\nvar findAndReplacePattern = function(words, pattern) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @param {String} pattern\n# @return {String[]}\ndef find_and_replace_pattern(words, pattern)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findAndReplacePattern(_ words: [String], _ pattern: String) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findAndReplacePattern(words []string, pattern string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findAndReplacePattern(words: Array[String], pattern: String): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findAndReplacePattern(words: Array, pattern: String): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_and_replace_pattern(words: Vec, pattern: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @param String $pattern\n * @return String[]\n */\n function findAndReplacePattern($words, $pattern) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findAndReplacePattern(words: string[], pattern: string): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-and-replace-pattern words pattern)\n (-> (listof string?) string? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0890](https://leetcode-cn.com/problems/find-and-replace-pattern)", "[\u67e5\u627e\u548c\u66ff\u6362\u6a21\u5f0f](/solution/0800-0899/0890.Find%20and%20Replace%20Pattern/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0890](https://leetcode.com/problems/find-and-replace-pattern)", "[Find and Replace Pattern](/solution/0800-0899/0890.Find%20and%20Replace%20Pattern/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "0925", "frontend_question_id": "0889", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-postorder-traversal", "url_en": "https://leetcode.com/problems/construct-binary-tree-from-preorder-and-postorder-traversal", "relative_path_cn": "/solution/0800-0899/0889.Construct%20Binary%20Tree%20from%20Preorder%20and%20Postorder%20Traversal/README.md", "relative_path_en": "/solution/0800-0899/0889.Construct%20Binary%20Tree%20from%20Preorder%20and%20Postorder%20Traversal/README_EN.md", "title_cn": "\u6839\u636e\u524d\u5e8f\u548c\u540e\u5e8f\u904d\u5386\u6784\u9020\u4e8c\u53c9\u6811", "title_en": "Construct Binary Tree from Preorder and Postorder Traversal", "question_title_slug": "construct-binary-tree-from-preorder-and-postorder-traversal", "content_en": "

    Return any binary tree that matches the given preorder and postorder traversals.

    \r\n\r\n

    Values in the traversals pre and post are distinct positive integers.

    \r\n\r\n

     

    \r\n\r\n
    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: pre = [1,2,4,5,3,6,7], post = [4,5,2,6,7,3,1]\r\nOutput: [1,2,3,4,5,6,7]\r\n
    \r\n\r\n

     

    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    • 1 <= pre.length == post.length <= 30
    • \r\n\t
    • pre[] and post[] are both permutations of 1, 2, ..., pre.length.
    • \r\n\t
    • It is guaranteed an answer exists. If there exists multiple answers, you can return any of them.
    • \r\n
    \r\n
    \r\n", "content_cn": "

    \u8fd4\u56de\u4e0e\u7ed9\u5b9a\u7684\u524d\u5e8f\u548c\u540e\u5e8f\u904d\u5386\u5339\u914d\u7684\u4efb\u4f55\u4e8c\u53c9\u6811\u3002

    \n\n

     pre \u548c post \u904d\u5386\u4e2d\u7684\u503c\u662f\u4e0d\u540c\u7684\u6b63\u6574\u6570\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1apre = [1,2,4,5,3,6,7], post = [4,5,2,6,7,3,1]\n\u8f93\u51fa\uff1a[1,2,3,4,5,6,7]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= pre.length == post.length <= 30
    • \n\t
    • pre[] \u548c post[] \u90fd\u662f 1, 2, ..., pre.length \u7684\u6392\u5217
    • \n\t
    • \u6bcf\u4e2a\u8f93\u5165\u4fdd\u8bc1\u81f3\u5c11\u6709\u4e00\u4e2a\u7b54\u6848\u3002\u5982\u679c\u6709\u591a\u4e2a\u7b54\u6848\uff0c\u53ef\u4ee5\u8fd4\u56de\u5176\u4e2d\u4e00\u4e2a\u3002
    • \n
    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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 */\nclass Solution {\npublic:\n TreeNode* constructFromPrePost(vector& pre, vector& post) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode(int x) { val = x; }\n * }\n */\nclass Solution {\n public TreeNode constructFromPrePost(int[] pre, int[] post) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution(object):\n def constructFromPrePost(self, pre, post):\n \"\"\"\n :type pre: List[int]\n :type post: List[int]\n :rtype: TreeNode\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution:\n def constructFromPrePost(self, pre: List[int], post: List[int]) -> TreeNode:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* constructFromPrePost(int* pre, int preSize, int* post, int postSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int x) { val = x; }\n * }\n */\npublic class Solution {\n public TreeNode ConstructFromPrePost(int[] pre, int[] post) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val) {\n * this.val = val;\n * this.left = this.right = null;\n * }\n */\n/**\n * @param {number[]} pre\n * @param {number[]} post\n * @return {TreeNode}\n */\nvar constructFromPrePost = function(pre, post) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val)\n# @val = val\n# @left, @right = nil, nil\n# end\n# end\n\n# @param {Integer[]} pre\n# @param {Integer[]} post\n# @return {TreeNode}\ndef construct_from_pre_post(pre, post)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.left = nil\n * self.right = nil\n * }\n * }\n */\nclass Solution {\n func constructFromPrePost(_ pre: [Int], _ post: [Int]) -> TreeNode? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc constructFromPrePost(pre []int, post []int) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(var _value: Int) {\n * var value: Int = _value\n * var left: TreeNode = null\n * var right: TreeNode = null\n * }\n */\nobject Solution {\n def constructFromPrePost(pre: Array[Int], post: Array[Int]): TreeNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun constructFromPrePost(pre: IntArray, post: IntArray): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n// \n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn construct_from_pre_post(pre: Vec, post: Vec) -> Option>> {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($value) { $this->val = $value; }\n * }\n */\nclass Solution {\n\n /**\n * @param Integer[] $pre\n * @param Integer[] $post\n * @return TreeNode\n */\n function constructFromPrePost($pre, $post) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction constructFromPrePost(pre: number[], post: number[]): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (construct-from-pre-post pre post)\n (-> (listof exact-integer?) (listof exact-integer?) (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0889](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-postorder-traversal)", "[\u6839\u636e\u524d\u5e8f\u548c\u540e\u5e8f\u904d\u5386\u6784\u9020\u4e8c\u53c9\u6811](/solution/0800-0899/0889.Construct%20Binary%20Tree%20from%20Preorder%20and%20Postorder%20Traversal/README.md)", "`\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0889](https://leetcode.com/problems/construct-binary-tree-from-preorder-and-postorder-traversal)", "[Construct Binary Tree from Preorder and Postorder Traversal](/solution/0800-0899/0889.Construct%20Binary%20Tree%20from%20Preorder%20and%20Postorder%20Traversal/README_EN.md)", "`Tree`", "Medium", ""]}, {"question_id": "0924", "frontend_question_id": "0888", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/fair-candy-swap", "url_en": "https://leetcode.com/problems/fair-candy-swap", "relative_path_cn": "/solution/0800-0899/0888.Fair%20Candy%20Swap/README.md", "relative_path_en": "/solution/0800-0899/0888.Fair%20Candy%20Swap/README_EN.md", "title_cn": "\u516c\u5e73\u7684\u7cd6\u679c\u68d2\u4ea4\u6362", "title_en": "Fair Candy Swap", "question_title_slug": "fair-candy-swap", "content_en": "

    Alice and Bob have candy bars of different sizes: aliceSizes[i] is the size of the i-th bar of candy that Alice has, and bobSizes[j] is the size of the j-th bar of candy that Bob has.

    \n\n

    Since they are friends, they would like to exchange one candy bar each so that after the exchange, they both have the same total amount of candy.  (The total amount of candy a person has is the sum of the sizes of candy bars they have.)

    \n\n

    Return an integer array ans where ans[0] is the size of the candy bar that Alice must exchange, and ans[1] is the size of the candy bar that Bob must exchange.

    \n\n

    If there are multiple answers, you may return any one of them.  It is guaranteed an answer exists.

    \n\n

     

    \n\n
    \n

    Example 1:

    \n\n
    \nInput: aliceSizes = [1,1], bobSizes = [2,2]\nOutput: [1,2]\n
    \n\n
    \n

    Example 2:

    \n\n
    \nInput: aliceSizes = [1,2], bobSizes = [2,3]\nOutput: [1,2]\n
    \n\n
    \n

    Example 3:

    \n\n
    \nInput: aliceSizes = [2], bobSizes = [1,3]\nOutput: [2,3]\n
    \n\n
    \n

    Example 4:

    \n\n
    \nInput: aliceSizes = [1,2,5], bobSizes = [2,4]\nOutput: [5,4]\n
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    • 1 <= aliceSizes.length <= 10000
    • \n\t
    • 1 <= bobSizes.length <= 10000
    • \n\t
    • 1 <= aliceSizes[i] <= 100000
    • \n\t
    • 1 <= bobSizes[i] <= 100000
    • \n\t
    • It is guaranteed that Alice and Bob have different total amounts of candy.
    • \n\t
    • It is guaranteed there exists an answer.
    • \n
    \n
    \n
    \n
    \n
    \n", "content_cn": "

    \u7231\u4e3d\u4e1d\u548c\u9c8d\u52c3\u6709\u4e0d\u540c\u5927\u5c0f\u7684\u7cd6\u679c\u68d2\uff1aA[i] \u662f\u7231\u4e3d\u4e1d\u62e5\u6709\u7684\u7b2c i \u6839\u7cd6\u679c\u68d2\u7684\u5927\u5c0f\uff0cB[j] \u662f\u9c8d\u52c3\u62e5\u6709\u7684\u7b2c j \u6839\u7cd6\u679c\u68d2\u7684\u5927\u5c0f\u3002

    \n\n

    \u56e0\u4e3a\u4ed6\u4eec\u662f\u670b\u53cb\uff0c\u6240\u4ee5\u4ed6\u4eec\u60f3\u4ea4\u6362\u4e00\u6839\u7cd6\u679c\u68d2\uff0c\u8fd9\u6837\u4ea4\u6362\u540e\uff0c\u4ed6\u4eec\u90fd\u6709\u76f8\u540c\u7684\u7cd6\u679c\u603b\u91cf\u3002\uff08\u4e00\u4e2a\u4eba\u62e5\u6709\u7684\u7cd6\u679c\u603b\u91cf\u662f\u4ed6\u4eec\u62e5\u6709\u7684\u7cd6\u679c\u68d2\u5927\u5c0f\u7684\u603b\u548c\u3002\uff09

    \n\n

    \u8fd4\u56de\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 ans\uff0c\u5176\u4e2d ans[0] \u662f\u7231\u4e3d\u4e1d\u5fc5\u987b\u4ea4\u6362\u7684\u7cd6\u679c\u68d2\u7684\u5927\u5c0f\uff0cans[1]\u00a0\u662f Bob \u5fc5\u987b\u4ea4\u6362\u7684\u7cd6\u679c\u68d2\u7684\u5927\u5c0f\u3002

    \n\n

    \u5982\u679c\u6709\u591a\u4e2a\u7b54\u6848\uff0c\u4f60\u53ef\u4ee5\u8fd4\u56de\u5176\u4e2d\u4efb\u4f55\u4e00\u4e2a\u3002\u4fdd\u8bc1\u7b54\u6848\u5b58\u5728\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aA = [1,1], B = [2,2]\n\u8f93\u51fa\uff1a[1,2]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aA = [1,2], B = [2,3]\n\u8f93\u51fa\uff1a[1,2]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aA = [2], B = [1,3]\n\u8f93\u51fa\uff1a[2,3]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1aA = [1,2,5], B = [2,4]\n\u8f93\u51fa\uff1a[5,4]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= A.length <= 10000
    • \n\t
    • 1 <= B.length <= 10000
    • \n\t
    • 1 <= A[i] <= 100000
    • \n\t
    • 1 <= B[i] <= 100000
    • \n\t
    • \u4fdd\u8bc1\u7231\u4e3d\u4e1d\u4e0e\u9c8d\u52c3\u7684\u7cd6\u679c\u603b\u91cf\u4e0d\u540c\u3002
    • \n\t
    • \u7b54\u6848\u80af\u5b9a\u5b58\u5728\u3002
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector fairCandySwap(vector& aliceSizes, vector& bobSizes) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] fairCandySwap(int[] aliceSizes, int[] bobSizes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def fairCandySwap(self, aliceSizes, bobSizes):\n \"\"\"\n :type aliceSizes: List[int]\n :type bobSizes: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def fairCandySwap(self, aliceSizes: List[int], bobSizes: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* fairCandySwap(int* aliceSizes, int aliceSizesSize, int* bobSizes, int bobSizesSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] FairCandySwap(int[] aliceSizes, int[] bobSizes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} aliceSizes\n * @param {number[]} bobSizes\n * @return {number[]}\n */\nvar fairCandySwap = function(aliceSizes, bobSizes) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} alice_sizes\n# @param {Integer[]} bob_sizes\n# @return {Integer[]}\ndef fair_candy_swap(alice_sizes, bob_sizes)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func fairCandySwap(_ aliceSizes: [Int], _ bobSizes: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func fairCandySwap(aliceSizes []int, bobSizes []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def fairCandySwap(aliceSizes: Array[Int], bobSizes: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun fairCandySwap(aliceSizes: IntArray, bobSizes: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn fair_candy_swap(alice_sizes: Vec, bob_sizes: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $aliceSizes\n * @param Integer[] $bobSizes\n * @return Integer[]\n */\n function fairCandySwap($aliceSizes, $bobSizes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function fairCandySwap(aliceSizes: number[], bobSizes: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (fair-candy-swap aliceSizes bobSizes)\n (-> (listof exact-integer?) (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0888](https://leetcode-cn.com/problems/fair-candy-swap)", "[\u516c\u5e73\u7684\u7cd6\u679c\u68d2\u4ea4\u6362](/solution/0800-0899/0888.Fair%20Candy%20Swap/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0888](https://leetcode.com/problems/fair-candy-swap)", "[Fair Candy Swap](/solution/0800-0899/0888.Fair%20Candy%20Swap/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0923", "frontend_question_id": "0887", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/super-egg-drop", "url_en": "https://leetcode.com/problems/super-egg-drop", "relative_path_cn": "/solution/0800-0899/0887.Super%20Egg%20Drop/README.md", "relative_path_en": "/solution/0800-0899/0887.Super%20Egg%20Drop/README_EN.md", "title_cn": "\u9e21\u86cb\u6389\u843d", "title_en": "Super Egg Drop", "question_title_slug": "super-egg-drop", "content_en": "

    You are given k identical eggs and you have access to a building with n floors labeled from 1 to n.

    \n\n

    You know that there exists a floor f where 0 <= f <= n such that any egg dropped at a floor higher than f will break, and any egg dropped at or below floor f will not break.

    \n\n

    Each move, you may take an unbroken egg and drop it from any floor x (where 1 <= x <= n). If the egg breaks, you can no longer use it. However, if the egg does not break, you may reuse it in future moves.

    \n\n

    Return the minimum number of moves that you need to determine with certainty what the value of f is.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: k = 1, n = 2\nOutput: 2\nExplanation: \nDrop the egg from floor 1. If it breaks, we know that f = 0.\nOtherwise, drop the egg from floor 2. If it breaks, we know that f = 1.\nIf it does not break, then we know f = 2.\nHence, we need at minimum 2 moves to determine with certainty what the value of f is.\n
    \n\n

    Example 2:

    \n\n
    \nInput: k = 2, n = 6\nOutput: 3\n
    \n\n

    Example 3:

    \n\n
    \nInput: k = 3, n = 14\nOutput: 4\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= k <= 100
    • \n\t
    • 1 <= n <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60 k \u679a\u76f8\u540c\u7684\u9e21\u86cb\uff0c\u5e76\u53ef\u4ee5\u4f7f\u7528\u4e00\u680b\u4ece\u7b2c 1 \u5c42\u5230\u7b2c n \u5c42\u5171\u6709 n \u5c42\u697c\u7684\u5efa\u7b51\u3002

    \n\n

    \u5df2\u77e5\u5b58\u5728\u697c\u5c42 f \uff0c\u6ee1\u8db3\u00a00 <= f <= n \uff0c\u4efb\u4f55\u4ece \u9ad8\u4e8e f \u7684\u697c\u5c42\u843d\u4e0b\u7684\u9e21\u86cb\u90fd\u4f1a\u788e\uff0c\u4ece f \u697c\u5c42\u6216\u6bd4\u5b83\u4f4e\u7684\u697c\u5c42\u843d\u4e0b\u7684\u9e21\u86cb\u90fd\u4e0d\u4f1a\u7834\u3002

    \n\n

    \u6bcf\u6b21\u64cd\u4f5c\uff0c\u4f60\u53ef\u4ee5\u53d6\u4e00\u679a\u6ca1\u6709\u788e\u7684\u9e21\u86cb\u5e76\u628a\u5b83\u4ece\u4efb\u4e00\u697c\u5c42 x \u6254\u4e0b\uff08\u6ee1\u8db3\u00a01 <= x <= n\uff09\u3002\u5982\u679c\u9e21\u86cb\u788e\u4e86\uff0c\u4f60\u5c31\u4e0d\u80fd\u518d\u6b21\u4f7f\u7528\u5b83\u3002\u5982\u679c\u67d0\u679a\u9e21\u86cb\u6254\u4e0b\u540e\u6ca1\u6709\u6454\u788e\uff0c\u5219\u53ef\u4ee5\u5728\u4e4b\u540e\u7684\u64cd\u4f5c\u4e2d \u91cd\u590d\u4f7f\u7528 \u8fd9\u679a\u9e21\u86cb\u3002

    \n\n

    \u8bf7\u4f60\u8ba1\u7b97\u5e76\u8fd4\u56de\u8981\u786e\u5b9a f \u786e\u5207\u7684\u503c \u7684 \u6700\u5c0f\u64cd\u4f5c\u6b21\u6570 \u662f\u591a\u5c11\uff1f

    \n\u00a0\n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1ak = 1, n = 2\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n\u9e21\u86cb\u4ece 1 \u697c\u6389\u843d\u3002\u5982\u679c\u5b83\u788e\u4e86\uff0c\u80af\u5b9a\u80fd\u5f97\u51fa f = 0 \u3002 \n\u5426\u5219\uff0c\u9e21\u86cb\u4ece 2 \u697c\u6389\u843d\u3002\u5982\u679c\u5b83\u788e\u4e86\uff0c\u80af\u5b9a\u80fd\u5f97\u51fa f = 1 \u3002 \n\u5982\u679c\u5b83\u6ca1\u788e\uff0c\u90a3\u4e48\u80af\u5b9a\u80fd\u5f97\u51fa f = 2 \u3002 \n\u56e0\u6b64\uff0c\u5728\u6700\u574f\u7684\u60c5\u51b5\u4e0b\u6211\u4eec\u9700\u8981\u79fb\u52a8 2 \u6b21\u4ee5\u786e\u5b9a f \u662f\u591a\u5c11\u3002 \n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1ak = 2, n = 6\n\u8f93\u51fa\uff1a3\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1ak = 3, n = 14\n\u8f93\u51fa\uff1a4\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= k <= 100
    • \n\t
    • 1 <= n <= 104
    • \n
    \n", "tags_en": ["Math", "Binary Search", "Dynamic Programming"], "tags_cn": ["\u6570\u5b66", "\u4e8c\u5206\u67e5\u627e", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int superEggDrop(int k, int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int superEggDrop(int k, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def superEggDrop(self, k, n):\n \"\"\"\n :type k: int\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def superEggDrop(self, k: int, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint superEggDrop(int k, int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SuperEggDrop(int k, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} k\n * @param {number} n\n * @return {number}\n */\nvar superEggDrop = function(k, n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} k\n# @param {Integer} n\n# @return {Integer}\ndef super_egg_drop(k, n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func superEggDrop(_ k: Int, _ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func superEggDrop(k int, n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def superEggDrop(k: Int, n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun superEggDrop(k: Int, n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn super_egg_drop(k: i32, n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $k\n * @param Integer $n\n * @return Integer\n */\n function superEggDrop($k, $n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function superEggDrop(k: number, n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (super-egg-drop k n)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0887](https://leetcode-cn.com/problems/super-egg-drop)", "[\u9e21\u86cb\u6389\u843d](/solution/0800-0899/0887.Super%20Egg%20Drop/README.md)", "`\u6570\u5b66`,`\u4e8c\u5206\u67e5\u627e`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0887](https://leetcode.com/problems/super-egg-drop)", "[Super Egg Drop](/solution/0800-0899/0887.Super%20Egg%20Drop/README_EN.md)", "`Math`,`Binary Search`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0922", "frontend_question_id": "0886", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/possible-bipartition", "url_en": "https://leetcode.com/problems/possible-bipartition", "relative_path_cn": "/solution/0800-0899/0886.Possible%20Bipartition/README.md", "relative_path_en": "/solution/0800-0899/0886.Possible%20Bipartition/README_EN.md", "title_cn": "\u53ef\u80fd\u7684\u4e8c\u5206\u6cd5", "title_en": "Possible Bipartition", "question_title_slug": "possible-bipartition", "content_en": "

    Given a set of n people (numbered 1, 2, ..., n), we would like to split everyone into two groups of any size.

    \n\n

    Each person may dislike some other people, and they should not go into the same group. 

    \n\n

    Formally, if dislikes[i] = [a, b], it means it is not allowed to put the people numbered a and b into the same group.

    \n\n

    Return true if and only if it is possible to split everyone into two groups in this way.

    \n\n

     

    \n\n
    \n
    \n
      \n
    \n
    \n
    \n\n
    \n

    Example 1:

    \n\n
    \nInput: n = 4, dislikes = [[1,2],[1,3],[2,4]]\nOutput: true\nExplanation: group1 [1,4], group2 [2,3]\n
    \n\n
    \n

    Example 2:

    \n\n
    \nInput: n = 3, dislikes = [[1,2],[1,3],[2,3]]\nOutput: false\n
    \n\n
    \n

    Example 3:

    \n\n
    \nInput: n = 5, dislikes = [[1,2],[2,3],[3,4],[4,5],[1,5]]\nOutput: false\n
    \n
    \n
    \n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 2000
    • \n\t
    • 0 <= dislikes.length <= 10000
    • \n\t
    • dislikes[i].length == 2
    • \n\t
    • 1 <= dislikes[i][j] <= n
    • \n\t
    • dislikes[i][0] < dislikes[i][1]
    • \n\t
    • There does not exist i != j for which dislikes[i] == dislikes[j].
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u7ec4\u00a0N\u00a0\u4eba\uff08\u7f16\u53f7\u4e3a\u00a01, 2, ..., N\uff09\uff0c\u00a0\u6211\u4eec\u60f3\u628a\u6bcf\u4e2a\u4eba\u5206\u8fdb\u4efb\u610f\u5927\u5c0f\u7684\u4e24\u7ec4\u3002

    \n\n

    \u6bcf\u4e2a\u4eba\u90fd\u53ef\u80fd\u4e0d\u559c\u6b22\u5176\u4ed6\u4eba\uff0c\u90a3\u4e48\u4ed6\u4eec\u4e0d\u5e94\u8be5\u5c5e\u4e8e\u540c\u4e00\u7ec4\u3002

    \n\n

    \u5f62\u5f0f\u4e0a\uff0c\u5982\u679c dislikes[i] = [a, b]\uff0c\u8868\u793a\u4e0d\u5141\u8bb8\u5c06\u7f16\u53f7\u4e3a a \u548c b \u7684\u4eba\u5f52\u5165\u540c\u4e00\u7ec4\u3002

    \n\n

    \u5f53\u53ef\u4ee5\u7528\u8fd9\u79cd\u65b9\u6cd5\u5c06\u6240\u6709\u4eba\u5206\u8fdb\u4e24\u7ec4\u65f6\uff0c\u8fd4\u56de true\uff1b\u5426\u5219\u8fd4\u56de false\u3002

    \n\n

    \u00a0

    \n\n
      \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aN = 4, dislikes = [[1,2],[1,3],[2,4]]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1agroup1 [1,4], group2 [2,3]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aN = 3, dislikes = [[1,2],[1,3],[2,3]]\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aN = 5, dislikes = [[1,2],[2,3],[3,4],[4,5],[1,5]]\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= N <= 2000
    • \n\t
    • 0 <= dislikes.length <= 10000
    • \n\t
    • dislikes[i].length == 2
    • \n\t
    • 1 <= dislikes[i][j] <= N
    • \n\t
    • dislikes[i][0] < dislikes[i][1]
    • \n\t
    • \u5bf9\u4e8e dislikes[i] == dislikes[j] \u4e0d\u5b58\u5728 i != j
    • \n
    \n", "tags_en": ["Depth-first Search", "Graph"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool possibleBipartition(int n, vector>& dislikes) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean possibleBipartition(int n, int[][] dislikes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def possibleBipartition(self, n, dislikes):\n \"\"\"\n :type n: int\n :type dislikes: List[List[int]]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def possibleBipartition(self, n: int, dislikes: List[List[int]]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool possibleBipartition(int n, int** dislikes, int dislikesSize, int* dislikesColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool PossibleBipartition(int n, int[][] dislikes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} dislikes\n * @return {boolean}\n */\nvar possibleBipartition = function(n, dislikes) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} dislikes\n# @return {Boolean}\ndef possible_bipartition(n, dislikes)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func possibleBipartition(_ n: Int, _ dislikes: [[Int]]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func possibleBipartition(n int, dislikes [][]int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def possibleBipartition(n: Int, dislikes: Array[Array[Int]]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun possibleBipartition(n: Int, dislikes: Array): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn possible_bipartition(n: i32, dislikes: Vec>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $dislikes\n * @return Boolean\n */\n function possibleBipartition($n, $dislikes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function possibleBipartition(n: number, dislikes: number[][]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (possible-bipartition n dislikes)\n (-> exact-integer? (listof (listof exact-integer?)) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0886](https://leetcode-cn.com/problems/possible-bipartition)", "[\u53ef\u80fd\u7684\u4e8c\u5206\u6cd5](/solution/0800-0899/0886.Possible%20Bipartition/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u56fe`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0886](https://leetcode.com/problems/possible-bipartition)", "[Possible Bipartition](/solution/0800-0899/0886.Possible%20Bipartition/README_EN.md)", "`Depth-first Search`,`Graph`", "Medium", ""]}, {"question_id": "0921", "frontend_question_id": "0885", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/spiral-matrix-iii", "url_en": "https://leetcode.com/problems/spiral-matrix-iii", "relative_path_cn": "/solution/0800-0899/0885.Spiral%20Matrix%20III/README.md", "relative_path_en": "/solution/0800-0899/0885.Spiral%20Matrix%20III/README_EN.md", "title_cn": "\u87ba\u65cb\u77e9\u9635 III", "title_en": "Spiral Matrix III", "question_title_slug": "spiral-matrix-iii", "content_en": "

    On a 2 dimensional grid with rows rows and cols columns, we start at (rStart, cStart) facing east.

    \n\n

    Here, the north-west corner of the grid is at the first row and column, and the south-east corner of the grid is at the last row and column.

    \n\n

    Now, we walk in a clockwise spiral shape to visit every position in this grid. 

    \n\n

    Whenever we would move outside the boundary of the grid, we continue our walk outside the grid (but may return to the grid boundary later.) 

    \n\n

    Eventually, we reach all rows * cols spaces of the grid.

    \n\n

    Return a list of coordinates representing the positions of the grid in the order they were visited.

    \n\n

     

    \n\n

    Example 1:

    \n\n
    \nInput: rows = 1, cols = 4, rStart = 0, cStart = 0\nOutput: [[0,0],[0,1],[0,2],[0,3]]\n\n\"\"\n
    \n\n

     

    \n\n

    Example 2:

    \n\n
    \nInput: rows = 5, cols = 6, rStart = 1, cStart = 4\nOutput: [[1,4],[1,5],[2,5],[2,4],[2,3],[1,3],[0,3],[0,4],[0,5],[3,5],[3,4],[3,3],[3,2],[2,2],[1,2],[0,2],[4,5],[4,4],[4,3],[4,2],[4,1],[3,1],[2,1],[1,1],[0,1],[4,0],[3,0],[2,0],[1,0],[0,0]]\n\n\"\"\n
    \n\n
    \n
    \n

     

    \n\n

    Note:

    \n\n
      \n\t
    1. 1 <= rows <= 100
    2. \n\t
    3. 1 <= cols <= 100
    4. \n\t
    5. 0 <= rStart < rows
    6. \n\t
    7. 0 <= cStart < cols
    8. \n
    \n
    \n
    \n", "content_cn": "

    \u5728 R \u884c C \u5217\u7684\u77e9\u9635\u4e0a\uff0c\u6211\u4eec\u4ece (r0, c0) \u9762\u671d\u4e1c\u9762\u5f00\u59cb

    \n\n

    \u8fd9\u91cc\uff0c\u7f51\u683c\u7684\u897f\u5317\u89d2\u4f4d\u4e8e\u7b2c\u4e00\u884c\u7b2c\u4e00\u5217\uff0c\u7f51\u683c\u7684\u4e1c\u5357\u89d2\u4f4d\u4e8e\u6700\u540e\u4e00\u884c\u6700\u540e\u4e00\u5217\u3002

    \n\n

    \u73b0\u5728\uff0c\u6211\u4eec\u4ee5\u987a\u65f6\u9488\u6309\u87ba\u65cb\u72b6\u884c\u8d70\uff0c\u8bbf\u95ee\u6b64\u7f51\u683c\u4e2d\u7684\u6bcf\u4e2a\u4f4d\u7f6e\u3002

    \n\n

    \u6bcf\u5f53\u6211\u4eec\u79fb\u52a8\u5230\u7f51\u683c\u7684\u8fb9\u754c\u4e4b\u5916\u65f6\uff0c\u6211\u4eec\u4f1a\u7ee7\u7eed\u5728\u7f51\u683c\u4e4b\u5916\u884c\u8d70\uff08\u4f46\u7a0d\u540e\u53ef\u80fd\u4f1a\u8fd4\u56de\u5230\u7f51\u683c\u8fb9\u754c\uff09\u3002

    \n\n

    \u6700\u7ec8\uff0c\u6211\u4eec\u5230\u8fc7\u7f51\u683c\u7684\u6240\u6709 R * C \u4e2a\u7a7a\u95f4\u3002

    \n\n

    \u6309\u7167\u8bbf\u95ee\u987a\u5e8f\u8fd4\u56de\u8868\u793a\u7f51\u683c\u4f4d\u7f6e\u7684\u5750\u6807\u5217\u8868\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aR = 1, C = 4, r0 = 0, c0 = 0\n\u8f93\u51fa\uff1a[[0,0],[0,1],[0,2],[0,3]]\n\n\"\"\n
    \n\n

     

    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aR = 5, C = 6, r0 = 1, c0 = 4\n\u8f93\u51fa\uff1a[[1,4],[1,5],[2,5],[2,4],[2,3],[1,3],[0,3],[0,4],[0,5],[3,5],[3,4],[3,3],[3,2],[2,2],[1,2],[0,2],[4,5],[4,4],[4,3],[4,2],[4,1],[3,1],[2,1],[1,1],[0,1],[4,0],[3,0],[2,0],[1,0],[0,0]]\n\n\"\"\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= R <= 100
    2. \n\t
    3. 1 <= C <= 100
    4. \n\t
    5. 0 <= r0 < R
    6. \n\t
    7. 0 <= c0 < C
    8. \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> spiralMatrixIII(int rows, int cols, int rStart, int cStart) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[][] spiralMatrixIII(int rows, int cols, int rStart, int cStart) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def spiralMatrixIII(self, rows, cols, rStart, cStart):\n \"\"\"\n :type rows: int\n :type cols: int\n :type rStart: int\n :type cStart: int\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def spiralMatrixIII(self, rows: int, cols: int, rStart: int, cStart: int) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** spiralMatrixIII(int rows, int cols, int rStart, int cStart, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[][] SpiralMatrixIII(int rows, int cols, int rStart, int cStart) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} rows\n * @param {number} cols\n * @param {number} rStart\n * @param {number} cStart\n * @return {number[][]}\n */\nvar spiralMatrixIII = function(rows, cols, rStart, cStart) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} rows\n# @param {Integer} cols\n# @param {Integer} r_start\n# @param {Integer} c_start\n# @return {Integer[][]}\ndef spiral_matrix_iii(rows, cols, r_start, c_start)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func spiralMatrixIII(_ rows: Int, _ cols: Int, _ rStart: Int, _ cStart: Int) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func spiralMatrixIII(rows int, cols int, rStart int, cStart int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def spiralMatrixIII(rows: Int, cols: Int, rStart: Int, cStart: Int): Array[Array[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun spiralMatrixIII(rows: Int, cols: Int, rStart: Int, cStart: Int): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn spiral_matrix_iii(rows: i32, cols: i32, r_start: i32, c_start: i32) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $rows\n * @param Integer $cols\n * @param Integer $rStart\n * @param Integer $cStart\n * @return Integer[][]\n */\n function spiralMatrixIII($rows, $cols, $rStart, $cStart) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function spiralMatrixIII(rows: number, cols: number, rStart: number, cStart: number): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (spiral-matrix-iii rows cols rStart cStart)\n (-> exact-integer? exact-integer? exact-integer? exact-integer? (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0885](https://leetcode-cn.com/problems/spiral-matrix-iii)", "[\u87ba\u65cb\u77e9\u9635 III](/solution/0800-0899/0885.Spiral%20Matrix%20III/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0885](https://leetcode.com/problems/spiral-matrix-iii)", "[Spiral Matrix III](/solution/0800-0899/0885.Spiral%20Matrix%20III/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "0920", "frontend_question_id": "0884", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/uncommon-words-from-two-sentences", "url_en": "https://leetcode.com/problems/uncommon-words-from-two-sentences", "relative_path_cn": "/solution/0800-0899/0884.Uncommon%20Words%20from%20Two%20Sentences/README.md", "relative_path_en": "/solution/0800-0899/0884.Uncommon%20Words%20from%20Two%20Sentences/README_EN.md", "title_cn": "\u4e24\u53e5\u8bdd\u4e2d\u7684\u4e0d\u5e38\u89c1\u5355\u8bcd", "title_en": "Uncommon Words from Two Sentences", "question_title_slug": "uncommon-words-from-two-sentences", "content_en": "

    A sentence is a string of single-space separated words where each word consists only of lowercase letters.

    \n\n

    A word is uncommon if it appears exactly once in one of the sentences, and does not appear in the other sentence.

    \n\n

    Given two sentences s1 and s2, return a list of all the uncommon words. You may return the answer in any order.

    \n\n

     

    \n

    Example 1:

    \n
    Input: s1 = \"this apple is sweet\", s2 = \"this apple is sour\"\nOutput: [\"sweet\",\"sour\"]\n

    Example 2:

    \n
    Input: s1 = \"apple apple\", s2 = \"banana\"\nOutput: [\"banana\"]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s1.length, s2.length <= 200
    • \n\t
    • s1 and s2 consist of lowercase English letters and spaces.
    • \n\t
    • s1 and s2 do not have leading or trailing spaces.
    • \n\t
    • All the words in s1 and s2 are separated by a single space.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u53e5\u5b50 A \u548c B \u3002 \uff08\u53e5\u5b50\u662f\u4e00\u4e32\u7531\u7a7a\u683c\u5206\u9694\u7684\u5355\u8bcd\u3002\u6bcf\u4e2a\u5355\u8bcd\u4ec5\u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210\u3002\uff09

    \n\n

    \u5982\u679c\u4e00\u4e2a\u5355\u8bcd\u5728\u5176\u4e2d\u4e00\u4e2a\u53e5\u5b50\u4e2d\u53ea\u51fa\u73b0\u4e00\u6b21\uff0c\u5728\u53e6\u4e00\u4e2a\u53e5\u5b50\u4e2d\u5374\u6ca1\u6709\u51fa\u73b0\uff0c\u90a3\u4e48\u8fd9\u4e2a\u5355\u8bcd\u5c31\u662f\u4e0d\u5e38\u89c1\u7684\u3002

    \n\n

    \u8fd4\u56de\u6240\u6709\u4e0d\u5e38\u7528\u5355\u8bcd\u7684\u5217\u8868\u3002

    \n\n

    \u60a8\u53ef\u4ee5\u6309\u4efb\u4f55\u987a\u5e8f\u8fd4\u56de\u5217\u8868\u3002

    \n\n

     

    \n\n
      \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aA = "this apple is sweet", B = "this apple is sour"\n\u8f93\u51fa\uff1a["sweet","sour"]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aA = "apple apple", B = "banana"\n\u8f93\u51fa\uff1a["banana"]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 0 <= A.length <= 200
    2. \n\t
    3. 0 <= B.length <= 200
    4. \n\t
    5. A \u548c B \u90fd\u53ea\u5305\u542b\u7a7a\u683c\u548c\u5c0f\u5199\u5b57\u6bcd\u3002
    6. \n
    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector uncommonFromSentences(string s1, string s2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String[] uncommonFromSentences(String s1, String s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def uncommonFromSentences(self, s1, s2):\n \"\"\"\n :type s1: str\n :type s2: str\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** uncommonFromSentences(char * s1, char * s2, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string[] UncommonFromSentences(string s1, string s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s1\n * @param {string} s2\n * @return {string[]}\n */\nvar uncommonFromSentences = function(s1, s2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s1\n# @param {String} s2\n# @return {String[]}\ndef uncommon_from_sentences(s1, s2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func uncommonFromSentences(_ s1: String, _ s2: String) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func uncommonFromSentences(s1 string, s2 string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def uncommonFromSentences(s1: String, s2: String): Array[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun uncommonFromSentences(s1: String, s2: String): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn uncommon_from_sentences(s1: String, s2: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s1\n * @param String $s2\n * @return String[]\n */\n function uncommonFromSentences($s1, $s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function uncommonFromSentences(s1: string, s2: string): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (uncommon-from-sentences s1 s2)\n (-> string? string? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0884](https://leetcode-cn.com/problems/uncommon-words-from-two-sentences)", "[\u4e24\u53e5\u8bdd\u4e2d\u7684\u4e0d\u5e38\u89c1\u5355\u8bcd](/solution/0800-0899/0884.Uncommon%20Words%20from%20Two%20Sentences/README.md)", "`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0884](https://leetcode.com/problems/uncommon-words-from-two-sentences)", "[Uncommon Words from Two Sentences](/solution/0800-0899/0884.Uncommon%20Words%20from%20Two%20Sentences/README_EN.md)", "`Hash Table`", "Easy", ""]}, {"question_id": "0919", "frontend_question_id": "0883", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/projection-area-of-3d-shapes", "url_en": "https://leetcode.com/problems/projection-area-of-3d-shapes", "relative_path_cn": "/solution/0800-0899/0883.Projection%20Area%20of%203D%20Shapes/README.md", "relative_path_en": "/solution/0800-0899/0883.Projection%20Area%20of%203D%20Shapes/README_EN.md", "title_cn": "\u4e09\u7ef4\u5f62\u4f53\u6295\u5f71\u9762\u79ef", "title_en": "Projection Area of 3D Shapes", "question_title_slug": "projection-area-of-3d-shapes", "content_en": "

    You are given an n x n grid where we place some 1 x 1 x 1 cubes that are axis-aligned with the x, y, and z axes.

    \n\n

    Each value v = grid[i][j] represents a tower of v cubes placed on top of the cell (i, j).

    \n\n

    We view the projection of these cubes onto the xy, yz, and zx planes.

    \n\n

    A projection is like a shadow, that maps our 3-dimensional figure to a 2-dimensional plane. We are viewing the "shadow" when looking at the cubes from the top, the front, and the side.

    \n\n

    Return the total area of all three projections.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: grid = [[1,2],[3,4]]\nOutput: 17\nExplanation: Here are the three projections ("shadows") of the shape made with each axis-aligned plane.\n
    \n\n

    Example 2:

    \n\n
    \nInput: grid = [[2]]\nOutput: 5\n
    \n\n

    Example 3:

    \n\n
    \nInput: grid = [[1,0],[0,2]]\nOutput: 8\n
    \n\n

    Example 4:

    \n\n
    \nInput: grid = [[1,1,1],[1,0,1],[1,1,1]]\nOutput: 14\n
    \n\n

    Example 5:

    \n\n
    \nInput: grid = [[2,2,2],[2,1,2],[2,2,2]]\nOutput: 21\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= n <= 50
    • \n\t
    • 0 <= grid[i][j] <= 50
    • \n
    \n", "content_cn": "

    \u5728 N * N \u7684\u7f51\u683c\u4e2d\uff0c\u6211\u4eec\u653e\u7f6e\u4e86\u4e00\u4e9b\u4e0e x\uff0cy\uff0cz \u4e09\u8f74\u5bf9\u9f50\u7684 1 * 1 * 1 \u7acb\u65b9\u4f53\u3002

    \n\n

    \u6bcf\u4e2a\u503c v = grid[i][j] \u8868\u793a v \u4e2a\u6b63\u65b9\u4f53\u53e0\u653e\u5728\u5355\u5143\u683c (i, j) \u4e0a\u3002

    \n\n

    \u73b0\u5728\uff0c\u6211\u4eec\u67e5\u770b\u8fd9\u4e9b\u7acb\u65b9\u4f53\u5728 xy\u3001yz \u548c zx \u5e73\u9762\u4e0a\u7684\u6295\u5f71\u3002

    \n\n

    \u6295\u5f71\u5c31\u50cf\u5f71\u5b50\uff0c\u5c06\u4e09\u7ef4\u5f62\u4f53\u6620\u5c04\u5230\u4e00\u4e2a\u4e8c\u7ef4\u5e73\u9762\u4e0a\u3002

    \n\n

    \u5728\u8fd9\u91cc\uff0c\u4ece\u9876\u90e8\u3001\u524d\u9762\u548c\u4fa7\u9762\u770b\u7acb\u65b9\u4f53\u65f6\uff0c\u6211\u4eec\u4f1a\u770b\u5230“\u5f71\u5b50”\u3002

    \n\n

    \u8fd4\u56de\u6240\u6709\u4e09\u4e2a\u6295\u5f71\u7684\u603b\u9762\u79ef\u3002

    \n\n

     

    \n\n
      \n
    \n\n
      \n
    \n\n
      \n
    \n\n
      \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a[[2]]\n\u8f93\u51fa\uff1a5\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a[[1,2],[3,4]]\n\u8f93\u51fa\uff1a17\n\u89e3\u91ca\uff1a\n\u8fd9\u91cc\u6709\u8be5\u5f62\u4f53\u5728\u4e09\u4e2a\u8f74\u5bf9\u9f50\u5e73\u9762\u4e0a\u7684\u4e09\u4e2a\u6295\u5f71(“\u9634\u5f71\u90e8\u5206”)\u3002\n\"\"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1a[[1,0],[0,2]]\n\u8f93\u51fa\uff1a8\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1a[[1,1,1],[1,0,1],[1,1,1]]\n\u8f93\u51fa\uff1a14\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1a[[2,2,2],[2,1,2],[2,2,2]]\n\u8f93\u51fa\uff1a21\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= grid.length = grid[0].length <= 50
    • \n\t
    • 0 <= grid[i][j] <= 50
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int projectionArea(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int projectionArea(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def projectionArea(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def projectionArea(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint projectionArea(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ProjectionArea(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar projectionArea = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef projection_area(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func projectionArea(_ grid: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func projectionArea(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def projectionArea(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun projectionArea(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn projection_area(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function projectionArea($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function projectionArea(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (projection-area grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0883](https://leetcode-cn.com/problems/projection-area-of-3d-shapes)", "[\u4e09\u7ef4\u5f62\u4f53\u6295\u5f71\u9762\u79ef](/solution/0800-0899/0883.Projection%20Area%20of%203D%20Shapes/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0883](https://leetcode.com/problems/projection-area-of-3d-shapes)", "[Projection Area of 3D Shapes](/solution/0800-0899/0883.Projection%20Area%20of%203D%20Shapes/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "0918", "frontend_question_id": "0882", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reachable-nodes-in-subdivided-graph", "url_en": "https://leetcode.com/problems/reachable-nodes-in-subdivided-graph", "relative_path_cn": "/solution/0800-0899/0882.Reachable%20Nodes%20In%20Subdivided%20Graph/README.md", "relative_path_en": "/solution/0800-0899/0882.Reachable%20Nodes%20In%20Subdivided%20Graph/README_EN.md", "title_cn": "\u7ec6\u5206\u56fe\u4e2d\u7684\u53ef\u5230\u8fbe\u7ed3\u70b9", "title_en": "Reachable Nodes In Subdivided Graph", "question_title_slug": "reachable-nodes-in-subdivided-graph", "content_en": "

    You are given an undirected graph (the "original graph") with n nodes labeled from 0 to n - 1. You decide to subdivide each edge in the graph into a chain of nodes, with the number of new nodes varying between each edge.

    \n\n

    The graph is given as a 2D array of edges where edges[i] = [ui, vi, cnti] indicates that there is an edge between nodes ui and vi in the original graph, and cnti is the total number of new nodes that you will subdivide the edge into. Note that cnti == 0 means you will not subdivide the edge.

    \n\n

    To subdivide the edge [ui, vi], replace it with (cnti + 1) new edges and cnti new nodes. The new nodes are x1, x2, ..., xcnti, and the new edges are [ui, x1], [x1, x2], [x2, x3], ..., [xcnti+1, xcnti], [xcnti, vi].

    \n\n

    In this new graph, you want to know how many nodes are reachable from the node 0, where a node is reachable if the distance is maxMoves or less.

    \n\n

    Given the original graph and maxMoves, return the number of nodes that are reachable from node 0 in the new graph.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: edges = [[0,1,10],[0,2,1],[1,2,2]], maxMoves = 6, n = 3\nOutput: 13\nExplanation: The edge subdivisions are shown in the image above.\nThe nodes that are reachable are highlighted in yellow.\n
    \n\n

    Example 2:

    \n\n
    \nInput: edges = [[0,1,4],[1,2,6],[0,2,8],[1,3,1]], maxMoves = 10, n = 4\nOutput: 23\n
    \n\n

    Example 3:

    \n\n
    \nInput: edges = [[1,2,4],[1,4,5],[1,3,1],[2,3,4],[3,4,5]], maxMoves = 17, n = 5\nOutput: 1\nExplanation: Node 0 is disconnected from the rest of the graph, so only node 0 is reachable.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= edges.length <= min(n * (n - 1) / 2, 104)
    • \n\t
    • edges[i].length == 3
    • \n\t
    • 0 <= ui < vi < n
    • \n\t
    • There are no multiple edges in the graph.
    • \n\t
    • 0 <= cnti <= 104
    • \n\t
    • 0 <= maxMoves <= 109
    • \n\t
    • 1 <= n <= 3000
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u65e0\u5411\u56fe\uff08\u539f\u59cb\u56fe\uff09\uff0c\u56fe\u4e2d\u6709 n \u4e2a\u8282\u70b9\uff0c\u7f16\u53f7\u4ece 0 \u5230 n - 1 \u3002\u4f60\u51b3\u5b9a\u5c06\u56fe\u4e2d\u7684\u6bcf\u6761\u8fb9\u7ec6\u5206\u4e3a\u4e00\u6761\u8282\u70b9\u94fe\uff0c\u6bcf\u6761\u8fb9\u4e4b\u95f4\u7684\u65b0\u8282\u70b9\u6570\u5404\u4e0d\u76f8\u540c\u3002

    \n\n

    \u56fe\u7528\u7531\u8fb9\u7ec4\u6210\u7684\u4e8c\u7ef4\u6570\u7ec4 edges \u8868\u793a\uff0c\u5176\u4e2d\u00a0edges[i] = [ui, vi, cnti] \u8868\u793a\u539f\u59cb\u56fe\u4e2d\u8282\u70b9\u00a0ui \u548c\u00a0vi \u4e4b\u95f4\u5b58\u5728\u4e00\u6761\u8fb9\uff0ccnti \u662f\u5c06\u8fb9\u7ec6\u5206\u540e\u7684\u65b0\u8282\u70b9\u603b\u6570\u3002\u6ce8\u610f\uff0ccnti == 0 \u8868\u793a\u8fb9\u4e0d\u53ef\u7ec6\u5206\u3002

    \n\n

    \u8981\u7ec6\u5206\u8fb9 [ui, vi] \uff0c\u9700\u8981\u5c06\u5176\u66ff\u6362\u4e3a (cnti + 1) \u6761\u65b0\u8fb9\uff0c\u548c\u00a0cnti \u4e2a\u65b0\u8282\u70b9\u3002\u65b0\u8282\u70b9\u4e3a x1, x2, ..., xcnti \uff0c\u65b0\u8fb9\u4e3a [ui, x1], [x1, x2], [x2, x3], ..., [xcnti+1, xcnti], [xcnti, vi] \u3002

    \n\n

    \u73b0\u5728\u5f97\u5230\u4e00\u4e2a\u65b0\u7684 \u7ec6\u5206\u56fe \uff0c\u8bf7\u4f60\u8ba1\u7b97\u4ece\u8282\u70b9 0 \u51fa\u53d1\uff0c\u53ef\u4ee5\u5230\u8fbe\u591a\u5c11\u4e2a\u8282\u70b9\uff1f\u8282\u70b9 \u662f\u5426\u53ef\u4ee5\u5230\u8fbe\u7684\u5224\u65ad\u6761\u4ef6 \u4e3a\uff1a\u5982\u679c\u8282\u70b9\u95f4\u8ddd\u79bb\u662f maxMoves \u6216\u66f4\u5c11\uff0c\u5219\u89c6\u4e3a\u53ef\u4ee5\u5230\u8fbe\uff1b\u5426\u5219\uff0c\u4e0d\u53ef\u5230\u8fbe\u3002

    \n\n

    \u7ed9\u4f60\u539f\u59cb\u56fe\u548c maxMoves \uff0c\u8fd4\u56de\u65b0\u7684\u7ec6\u5206\u56fe\u4e2d\u4ece\u8282\u70b9 0 \u51fa\u53d1 \u53ef\u5230\u8fbe\u7684\u8282\u70b9\u6570 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aedges = [[0,1,10],[0,2,1],[1,2,2]], maxMoves = 6, n = 3\n\u8f93\u51fa\uff1a13\n\u89e3\u91ca\uff1a\u8fb9\u7684\u7ec6\u5206\u60c5\u51b5\u5982\u4e0a\u56fe\u6240\u793a\u3002\n\u53ef\u4ee5\u5230\u8fbe\u7684\u8282\u70b9\u5df2\u7ecf\u7528\u9ec4\u8272\u6807\u6ce8\u51fa\u6765\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aedges = [[0,1,4],[1,2,6],[0,2,8],[1,3,1]], maxMoves = 10, n = 4\n\u8f93\u51fa\uff1a23\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aedges = [[1,2,4],[1,4,5],[1,3,1],[2,3,4],[3,4,5]], maxMoves = 17, n = 5\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u8282\u70b9 0 \u4e0e\u56fe\u7684\u5176\u4f59\u90e8\u5206\u6ca1\u6709\u8fde\u901a\uff0c\u6240\u4ee5\u53ea\u6709\u8282\u70b9 0 \u53ef\u4ee5\u5230\u8fbe\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= edges.length <= min(n * (n - 1) / 2, 104)
    • \n\t
    • edges[i].length == 3
    • \n\t
    • 0 <= ui < vi < n
    • \n\t
    • \u56fe\u4e2d \u4e0d\u5b58\u5728\u5e73\u884c\u8fb9
    • \n\t
    • 0 <= cnti <= 104
    • \n\t
    • 0 <= maxMoves <= 109
    • \n\t
    • 1 <= n <= 3000
    • \n
    \n", "tags_en": ["Heap", "Breadth-first Search"], "tags_cn": ["\u5806", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int reachableNodes(vector>& edges, int maxMoves, int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int reachableNodes(int[][] edges, int maxMoves, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def reachableNodes(self, edges, maxMoves, n):\n \"\"\"\n :type edges: List[List[int]]\n :type maxMoves: int\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def reachableNodes(self, edges: List[List[int]], maxMoves: int, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint reachableNodes(int** edges, int edgesSize, int* edgesColSize, int maxMoves, int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ReachableNodes(int[][] edges, int maxMoves, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} edges\n * @param {number} maxMoves\n * @param {number} n\n * @return {number}\n */\nvar reachableNodes = function(edges, maxMoves, n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} edges\n# @param {Integer} max_moves\n# @param {Integer} n\n# @return {Integer}\ndef reachable_nodes(edges, max_moves, n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func reachableNodes(_ edges: [[Int]], _ maxMoves: Int, _ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func reachableNodes(edges [][]int, maxMoves int, n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def reachableNodes(edges: Array[Array[Int]], maxMoves: Int, n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun reachableNodes(edges: Array, maxMoves: Int, n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn reachable_nodes(edges: Vec>, max_moves: i32, n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $edges\n * @param Integer $maxMoves\n * @param Integer $n\n * @return Integer\n */\n function reachableNodes($edges, $maxMoves, $n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function reachableNodes(edges: number[][], maxMoves: number, n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (reachable-nodes edges maxMoves n)\n (-> (listof (listof exact-integer?)) exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0882](https://leetcode-cn.com/problems/reachable-nodes-in-subdivided-graph)", "[\u7ec6\u5206\u56fe\u4e2d\u7684\u53ef\u5230\u8fbe\u7ed3\u70b9](/solution/0800-0899/0882.Reachable%20Nodes%20In%20Subdivided%20Graph/README.md)", "`\u5806`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[0882](https://leetcode.com/problems/reachable-nodes-in-subdivided-graph)", "[Reachable Nodes In Subdivided Graph](/solution/0800-0899/0882.Reachable%20Nodes%20In%20Subdivided%20Graph/README_EN.md)", "`Heap`,`Breadth-first Search`", "Hard", ""]}, {"question_id": "0917", "frontend_question_id": "0881", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/boats-to-save-people", "url_en": "https://leetcode.com/problems/boats-to-save-people", "relative_path_cn": "/solution/0800-0899/0881.Boats%20to%20Save%20People/README.md", "relative_path_en": "/solution/0800-0899/0881.Boats%20to%20Save%20People/README_EN.md", "title_cn": "\u6551\u751f\u8247", "title_en": "Boats to Save People", "question_title_slug": "boats-to-save-people", "content_en": "

    You are given an array people where people[i] is the weight of the ith person, and an infinite number of boats where each boat can carry a maximum weight of limit. Each boat carries at most two people at the same time, provided the sum of the weight of those people is at most limit.

    \n\n

    Return the minimum number of boats to carry every given person.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: people = [1,2], limit = 3\nOutput: 1\nExplanation: 1 boat (1, 2)\n
    \n\n

    Example 2:

    \n\n
    \nInput: people = [3,2,2,1], limit = 3\nOutput: 3\nExplanation: 3 boats (1, 2), (2) and (3)\n
    \n\n

    Example 3:

    \n\n
    \nInput: people = [3,5,3,4], limit = 5\nOutput: 4\nExplanation: 4 boats (3), (3), (4), (5)\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= people.length <= 5 * 104
    • \n\t
    • 1 <= people[i] <= limit <= 3 * 104
    • \n
    \n", "content_cn": "

    \u7b2c i \u4e2a\u4eba\u7684\u4f53\u91cd\u4e3a people[i]\uff0c\u6bcf\u8258\u8239\u53ef\u4ee5\u627f\u8f7d\u7684\u6700\u5927\u91cd\u91cf\u4e3a limit\u3002

    \n\n

    \u6bcf\u8258\u8239\u6700\u591a\u53ef\u540c\u65f6\u8f7d\u4e24\u4eba\uff0c\u4f46\u6761\u4ef6\u662f\u8fd9\u4e9b\u4eba\u7684\u91cd\u91cf\u4e4b\u548c\u6700\u591a\u4e3a limit\u3002

    \n\n

    \u8fd4\u56de\u8f7d\u5230\u6bcf\u4e00\u4e2a\u4eba\u6240\u9700\u7684\u6700\u5c0f\u8239\u6570\u3002(\u4fdd\u8bc1\u6bcf\u4e2a\u4eba\u90fd\u80fd\u88ab\u8239\u8f7d)\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1apeople = [1,2], limit = 3\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a1 \u8258\u8239\u8f7d (1, 2)\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1apeople = [3,2,2,1], limit = 3\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a3 \u8258\u8239\u5206\u522b\u8f7d (1, 2), (2) \u548c (3)\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1apeople = [3,5,3,4], limit = 5\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a4 \u8258\u8239\u5206\u522b\u8f7d (3), (3), (4), (5)
    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= people.length <= 50000
    • \n\t
    • 1 <= people[i] <= limit <= 30000
    • \n
    \n", "tags_en": ["Greedy", "Two Pointers"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numRescueBoats(vector& people, int limit) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numRescueBoats(int[] people, int limit) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numRescueBoats(self, people, limit):\n \"\"\"\n :type people: List[int]\n :type limit: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numRescueBoats(self, people: List[int], limit: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numRescueBoats(int* people, int peopleSize, int limit){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumRescueBoats(int[] people, int limit) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} people\n * @param {number} limit\n * @return {number}\n */\nvar numRescueBoats = function(people, limit) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} people\n# @param {Integer} limit\n# @return {Integer}\ndef num_rescue_boats(people, limit)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numRescueBoats(_ people: [Int], _ limit: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numRescueBoats(people []int, limit int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numRescueBoats(people: Array[Int], limit: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numRescueBoats(people: IntArray, limit: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_rescue_boats(people: Vec, limit: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $people\n * @param Integer $limit\n * @return Integer\n */\n function numRescueBoats($people, $limit) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numRescueBoats(people: number[], limit: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-rescue-boats people limit)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0881](https://leetcode-cn.com/problems/boats-to-save-people)", "[\u6551\u751f\u8247](/solution/0800-0899/0881.Boats%20to%20Save%20People/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0881](https://leetcode.com/problems/boats-to-save-people)", "[Boats to Save People](/solution/0800-0899/0881.Boats%20to%20Save%20People/README_EN.md)", "`Greedy`,`Two Pointers`", "Medium", ""]}, {"question_id": "0916", "frontend_question_id": "0880", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/decoded-string-at-index", "url_en": "https://leetcode.com/problems/decoded-string-at-index", "relative_path_cn": "/solution/0800-0899/0880.Decoded%20String%20at%20Index/README.md", "relative_path_en": "/solution/0800-0899/0880.Decoded%20String%20at%20Index/README_EN.md", "title_cn": "\u7d22\u5f15\u5904\u7684\u89e3\u7801\u5b57\u7b26\u4e32", "title_en": "Decoded String at Index", "question_title_slug": "decoded-string-at-index", "content_en": "

    An encoded string s is given.  To find and write the decoded string to a tape, the encoded string is read one character at a time and the following steps are taken:

    \n\n
      \n\t
    • If the character read is a letter, that letter is written onto the tape.
    • \n\t
    • If the character read is a digit (say d), the entire current tape is repeatedly written d-1 more times in total.
    • \n
    \n\n

    Now for some encoded string s, and an index k, find and return the k-th letter (1 indexed) in the decoded string.

    \n\n

     

    \n\n
    \n

    Example 1:

    \n\n
    \nInput: s = "leet2code3", k = 10\nOutput: "o"\nExplanation: \nThe decoded string is "leetleetcodeleetleetcodeleetleetcode".\nThe 10th letter in the string is "o".\n
    \n\n
    \n

    Example 2:

    \n\n
    \nInput: s = "ha22", k = 5\nOutput: "h"\nExplanation: \nThe decoded string is "hahahaha".  The 5th letter is "h".\n
    \n\n
    \n

    Example 3:

    \n\n
    \nInput: s = "a2345678999999999999999", k = 1\nOutput: "a"\nExplanation: \nThe decoded string is "a" repeated 8301530446056247680 times.  The 1st letter is "a".\n
    \n
    \n
    \n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= s.length <= 100
    • \n\t
    • s will only contain lowercase letters and digits 2 through 9.
    • \n\t
    • s starts with a letter.
    • \n\t
    • 1 <= k <= 109
    • \n\t
    • It's guaranteed that k is less than or equal to the length of the decoded string.
    • \n\t
    • The decoded string is guaranteed to have less than 263 letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u7f16\u7801\u5b57\u7b26\u4e32 S\u3002\u8bf7\u4f60\u627e\u51fa \u89e3\u7801\u5b57\u7b26\u4e32 \u5e76\u5c06\u5176\u5199\u5165\u78c1\u5e26\u3002\u89e3\u7801\u65f6\uff0c\u4ece\u7f16\u7801\u5b57\u7b26\u4e32\u4e2d \u6bcf\u6b21\u8bfb\u53d6\u4e00\u4e2a\u5b57\u7b26 \uff0c\u5e76\u91c7\u53d6\u4ee5\u4e0b\u6b65\u9aa4\uff1a

    \n\n
      \n\t
    • \u5982\u679c\u6240\u8bfb\u7684\u5b57\u7b26\u662f\u5b57\u6bcd\uff0c\u5219\u5c06\u8be5\u5b57\u6bcd\u5199\u5728\u78c1\u5e26\u4e0a\u3002
    • \n\t
    • \u5982\u679c\u6240\u8bfb\u7684\u5b57\u7b26\u662f\u6570\u5b57\uff08\u4f8b\u5982 d\uff09\uff0c\u5219\u6574\u4e2a\u5f53\u524d\u78c1\u5e26\u603b\u5171\u4f1a\u88ab\u91cd\u590d\u5199 d-1 \u6b21\u3002
    • \n
    \n\n

    \u73b0\u5728\uff0c\u5bf9\u4e8e\u7ed9\u5b9a\u7684\u7f16\u7801\u5b57\u7b26\u4e32 S \u548c\u7d22\u5f15 K\uff0c\u67e5\u627e\u5e76\u8fd4\u56de\u89e3\u7801\u5b57\u7b26\u4e32\u4e2d\u7684\u7b2c K \u4e2a\u5b57\u6bcd\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aS = "leet2code3", K = 10\n\u8f93\u51fa\uff1a"o"\n\u89e3\u91ca\uff1a\n\u89e3\u7801\u540e\u7684\u5b57\u7b26\u4e32\u4e3a "leetleetcodeleetleetcodeleetleetcode"\u3002\n\u5b57\u7b26\u4e32\u4e2d\u7684\u7b2c 10 \u4e2a\u5b57\u6bcd\u662f "o"\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aS = "ha22", K = 5\n\u8f93\u51fa\uff1a"h"\n\u89e3\u91ca\uff1a\n\u89e3\u7801\u540e\u7684\u5b57\u7b26\u4e32\u4e3a "hahahaha"\u3002\u7b2c 5 \u4e2a\u5b57\u6bcd\u662f "h"\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aS = "a2345678999999999999999", K = 1\n\u8f93\u51fa\uff1a"a"\n\u89e3\u91ca\uff1a\n\u89e3\u7801\u540e\u7684\u5b57\u7b26\u4e32\u4e3a "a" \u91cd\u590d 8301530446056247680 \u6b21\u3002\u7b2c 1 \u4e2a\u5b57\u6bcd\u662f "a"\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= S.length <= 100
    • \n\t
    • S \u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd\u4e0e\u6570\u5b57 2 \u5230 9 \u3002
    • \n\t
    • S \u4ee5\u5b57\u6bcd\u5f00\u5934\u3002
    • \n\t
    • 1 <= K <= 10^9
    • \n\t
    • \u9898\u76ee\u4fdd\u8bc1 K \u5c0f\u4e8e\u6216\u7b49\u4e8e\u89e3\u7801\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u3002
    • \n\t
    • \u89e3\u7801\u540e\u7684\u5b57\u7b26\u4e32\u4fdd\u8bc1\u5c11\u4e8e 2^63 \u4e2a\u5b57\u6bcd\u3002
    • \n
    \n", "tags_en": ["Stack"], "tags_cn": ["\u6808"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string decodeAtIndex(string s, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String decodeAtIndex(String s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def decodeAtIndex(self, s, k):\n \"\"\"\n :type s: str\n :type k: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def decodeAtIndex(self, s: str, k: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * decodeAtIndex(char * s, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string DecodeAtIndex(string s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number} k\n * @return {string}\n */\nvar decodeAtIndex = function(s, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer} k\n# @return {String}\ndef decode_at_index(s, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func decodeAtIndex(_ s: String, _ k: Int) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func decodeAtIndex(s string, k int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def decodeAtIndex(s: String, k: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun decodeAtIndex(s: String, k: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn decode_at_index(s: String, k: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer $k\n * @return String\n */\n function decodeAtIndex($s, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function decodeAtIndex(s: string, k: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (decode-at-index s k)\n (-> string? exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0880](https://leetcode-cn.com/problems/decoded-string-at-index)", "[\u7d22\u5f15\u5904\u7684\u89e3\u7801\u5b57\u7b26\u4e32](/solution/0800-0899/0880.Decoded%20String%20at%20Index/README.md)", "`\u6808`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0880](https://leetcode.com/problems/decoded-string-at-index)", "[Decoded String at Index](/solution/0800-0899/0880.Decoded%20String%20at%20Index/README_EN.md)", "`Stack`", "Medium", ""]}, {"question_id": "0915", "frontend_question_id": "0478", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/generate-random-point-in-a-circle", "url_en": "https://leetcode.com/problems/generate-random-point-in-a-circle", "relative_path_cn": "/solution/0400-0499/0478.Generate%20Random%20Point%20in%20a%20Circle/README.md", "relative_path_en": "/solution/0400-0499/0478.Generate%20Random%20Point%20in%20a%20Circle/README_EN.md", "title_cn": "\u5728\u5706\u5185\u968f\u673a\u751f\u6210\u70b9", "title_en": "Generate Random Point in a Circle", "question_title_slug": "generate-random-point-in-a-circle", "content_en": "

    Given the radius and the position of the center of a circle, implement the function randPoint which generates a uniform random point inside the circle.

    \n\n

    Implement the Solution class:

    \n\n
      \n\t
    • Solution(double radius, double x_center, double y_center) initializes the object with the radius of the circle radius and the position of the center (x_center, y_center).
    • \n\t
    • randPoint() returns a random point inside the circle. A point on the circumference of the circle is considered to be in the circle. The answer is returned as an array [x, y].
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["Solution", "randPoint", "randPoint", "randPoint"]\n[[1.0, 0.0, 0.0], [], [], []]\nOutput\n[null, [-0.02493, -0.38077], [0.82314, 0.38945], [0.36572, 0.17248]]\n\nExplanation\nSolution solution = new Solution(1.0, 0.0, 0.0);\nsolution.randPoint(); // return [-0.02493, -0.38077]\nsolution.randPoint(); // return [0.82314, 0.38945]\nsolution.randPoint(); // return [0.36572, 0.17248]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 < radius <= 108
    • \n\t
    • -107 <= x_center, y_center <= 107
    • \n\t
    • At most 3 * 104 calls will be made to randPoint.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u5706\u7684\u534a\u5f84\u548c\u5706\u5fc3\u7684 x\u3001y \u5750\u6807\uff0c\u5199\u4e00\u4e2a\u5728\u5706\u4e2d\u4ea7\u751f\u5747\u5300\u968f\u673a\u70b9\u7684\u51fd\u6570 randPoint \u3002

    \n\n

    \u8bf4\u660e:

    \n\n
      \n\t
    1. \u8f93\u5165\u503c\u548c\u8f93\u51fa\u503c\u90fd\u5c06\u662f\u6d6e\u70b9\u6570\u3002
    2. \n\t
    3. \u5706\u7684\u534a\u5f84\u548c\u5706\u5fc3\u7684 x\u3001y \u5750\u6807\u5c06\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u7ed9\u7c7b\u7684\u6784\u9020\u51fd\u6570\u3002
    4. \n\t
    5. \u5706\u5468\u4e0a\u7684\u70b9\u4e5f\u8ba4\u4e3a\u662f\u5728\u5706\u4e2d\u3002
    6. \n\t
    7. randPoint \u8fd4\u56de\u4e00\u4e2a\u5305\u542b\u968f\u673a\u70b9\u7684x\u5750\u6807\u548cy\u5750\u6807\u7684\u5927\u5c0f\u4e3a2\u7684\u6570\u7ec4\u3002
    8. \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165: \n["Solution","randPoint","randPoint","randPoint"]\n[[1,0,0],[],[],[]]\n\u8f93\u51fa: [null,[-0.72939,-0.65505],[-0.78502,-0.28626],[-0.83119,-0.19803]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165: \n["Solution","randPoint","randPoint","randPoint"]\n[[10,5,-7.5],[],[],[]]\n\u8f93\u51fa: [null,[11.52438,-8.33273],[2.46992,-16.21705],[11.13430,-12.42337]]
    \n\n

    \u8f93\u5165\u8bed\u6cd5\u8bf4\u660e\uff1a

    \n\n

    \u8f93\u5165\u662f\u4e24\u4e2a\u5217\u8868\uff1a\u8c03\u7528\u6210\u5458\u51fd\u6570\u540d\u548c\u8c03\u7528\u7684\u53c2\u6570\u3002Solution \u7684\u6784\u9020\u51fd\u6570\u6709\u4e09\u4e2a\u53c2\u6570\uff0c\u5706\u7684\u534a\u5f84\u3001\u5706\u5fc3\u7684 x \u5750\u6807\u3001\u5706\u5fc3\u7684 y \u5750\u6807\u3002randPoint \u6ca1\u6709\u53c2\u6570\u3002\u8f93\u5165\u53c2\u6570\u662f\u4e00\u4e2a\u5217\u8868\uff0c\u5373\u4f7f\u53c2\u6570\u4e3a\u7a7a\uff0c\u4e5f\u4f1a\u8f93\u5165\u4e00\u4e2a [] \u7a7a\u5217\u8868\u3002

    \n", "tags_en": ["Math", "Random", "Rejection Sampling"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n Solution(double radius, double x_center, double y_center) {\n\n }\n \n vector randPoint() {\n\n }\n};\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution* obj = new Solution(radius, x_center, y_center);\n * vector param_1 = obj->randPoint();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n\n public Solution(double radius, double x_center, double y_center) {\n\n }\n \n public double[] randPoint() {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution obj = new Solution(radius, x_center, y_center);\n * double[] param_1 = obj.randPoint();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n\n def __init__(self, radius, x_center, y_center):\n \"\"\"\n :type radius: float\n :type x_center: float\n :type y_center: float\n \"\"\"\n\n\n def randPoint(self):\n \"\"\"\n :rtype: List[float]\n \"\"\"\n\n\n\n# Your Solution object will be instantiated and called as such:\n# obj = Solution(radius, x_center, y_center)\n# param_1 = obj.randPoint()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n\n def __init__(self, radius: float, x_center: float, y_center: float):\n\n\n def randPoint(self) -> List[float]:\n\n\n\n# Your Solution object will be instantiated and called as such:\n# obj = Solution(radius, x_center, y_center)\n# param_1 = obj.randPoint()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} Solution;\n\n\nSolution* solutionCreate(double radius, double x_center, double y_center) {\n\n}\n\ndouble* solutionRandPoint(Solution* obj, int* retSize) {\n\n}\n\nvoid solutionFree(Solution* obj) {\n\n}\n\n/**\n * Your Solution struct will be instantiated and called as such:\n * Solution* obj = solutionCreate(radius, x_center, y_center);\n * double* param_1 = solutionRandPoint(obj, retSize);\n \n * solutionFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n\n public Solution(double radius, double x_center, double y_center) {\n\n }\n \n public double[] RandPoint() {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution obj = new Solution(radius, x_center, y_center);\n * double[] param_1 = obj.RandPoint();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} radius\n * @param {number} x_center\n * @param {number} y_center\n */\nvar Solution = function(radius, x_center, y_center) {\n\n};\n\n/**\n * @return {number[]}\n */\nSolution.prototype.randPoint = function() {\n\n};\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = new Solution(radius, x_center, y_center)\n * var param_1 = obj.randPoint()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class Solution\n\n=begin\n :type radius: Float\n :type x_center: Float\n :type y_center: Float\n=end\n def initialize(radius, x_center, y_center)\n\n end\n\n\n=begin\n :rtype: Float[]\n=end\n def rand_point()\n\n end\n\n\nend\n\n# Your Solution object will be instantiated and called as such:\n# obj = Solution.new(radius, x_center, y_center)\n# param_1 = obj.rand_point()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass Solution {\n\n init(_ radius: Double, _ x_center: Double, _ y_center: Double) {\n\n }\n \n func randPoint() -> [Double] {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * let obj = Solution(radius, x_center, y_center)\n * let ret_1: [Double] = obj.randPoint()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type Solution struct {\n\n}\n\n\nfunc Constructor(radius float64, x_center float64, y_center float64) Solution {\n\n}\n\n\nfunc (this *Solution) RandPoint() []float64 {\n\n}\n\n\n/**\n * Your Solution object will be instantiated and called as such:\n * obj := Constructor(radius, x_center, y_center);\n * param_1 := obj.RandPoint();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class Solution(_radius: Double, _x_center: Double, _y_center: Double) {\n\n def randPoint(): Array[Double] = {\n\n }\n\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = new Solution(radius, x_center, y_center)\n * var param_1 = obj.randPoint()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution(radius: Double, x_center: Double, y_center: Double) {\n\n fun randPoint(): DoubleArray {\n\n }\n\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = Solution(radius, x_center, y_center)\n * var param_1 = obj.randPoint()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct Solution {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl Solution {\n\n fn new(radius: f64, x_center: f64, y_center: f64) -> Self {\n\n }\n \n fn rand_point(&self) -> Vec {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * let obj = Solution::new(radius, x_center, y_center);\n * let ret_1: Vec = obj.rand_point();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n /**\n * @param Float $radius\n * @param Float $x_center\n * @param Float $y_center\n */\n function __construct($radius, $x_center, $y_center) {\n\n }\n\n /**\n * @return Float[]\n */\n function randPoint() {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * $obj = Solution($radius, $x_center, $y_center);\n * $ret_1 = $obj->randPoint();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class Solution {\n constructor(radius: number, x_center: number, y_center: number) {\n\n }\n\n randPoint(): number[] {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = new Solution(radius, x_center, y_center)\n * var param_1 = obj.randPoint()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define solution%\n (class object%\n (super-new)\n\n ; radius : flonum?\n\n ; x_center : flonum?\n\n ; y_center : flonum?\n (init-field\n radius\n x_center\n y_center)\n \n ; rand-point : -> (listof flonum?)\n (define/public (rand-point)\n\n )))\n\n;; Your solution% object will be instantiated and called as such:\n;; (define obj (new solution% [radius radius] [x_center x_center] [y_center y_center]))\n;; (define param_1 (send obj rand-point))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0478](https://leetcode-cn.com/problems/generate-random-point-in-a-circle)", "[\u5728\u5706\u5185\u968f\u673a\u751f\u6210\u70b9](/solution/0400-0499/0478.Generate%20Random%20Point%20in%20a%20Circle/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0478](https://leetcode.com/problems/generate-random-point-in-a-circle)", "[Generate Random Point in a Circle](/solution/0400-0499/0478.Generate%20Random%20Point%20in%20a%20Circle/README_EN.md)", "`Math`,`Random`,`Rejection Sampling`", "Medium", ""]}, {"question_id": "0914", "frontend_question_id": "0497", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/random-point-in-non-overlapping-rectangles", "url_en": "https://leetcode.com/problems/random-point-in-non-overlapping-rectangles", "relative_path_cn": "/solution/0400-0499/0497.Random%20Point%20in%20Non-overlapping%20Rectangles/README.md", "relative_path_en": "/solution/0400-0499/0497.Random%20Point%20in%20Non-overlapping%20Rectangles/README_EN.md", "title_cn": "\u975e\u91cd\u53e0\u77e9\u5f62\u4e2d\u7684\u968f\u673a\u70b9", "title_en": "Random Point in Non-overlapping Rectangles", "question_title_slug": "random-point-in-non-overlapping-rectangles", "content_en": "

    Given a list of non-overlapping axis-aligned rectangles rects, write a function pick which randomly and uniformily picks an integer point in the space covered by the rectangles.

    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    1. An integer point is a point that has integer coordinates. 
    2. \r\n\t
    3. A point on the perimeter of a rectangle is included in the space covered by the rectangles. 
    4. \r\n\t
    5. ith rectangle = rects[i][x1,y1,x2,y2], where [x1, y1] are the integer coordinates of the bottom-left corner, and [x2, y2] are the integer coordinates of the top-right corner.
    6. \r\n\t
    7. length and width of each rectangle does not exceed 2000.
    8. \r\n\t
    9. 1 <= rects.length <= 100
    10. \r\n\t
    11. pick return a point as an array of integer coordinates [p_x, p_y]
    12. \r\n\t
    13. pick is called at most 10000 times.
    14. \r\n
    \r\n\r\n
    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: \r\n["Solution","pick","pick","pick"]\r\n[[[[1,1,5,5]]],[],[],[]]\r\nOutput: \r\n[null,[4,1],[4,1],[3,3]]\r\n
    \r\n\r\n
    \r\n

    Example 2:

    \r\n\r\n
    \r\nInput: \r\n["Solution","pick","pick","pick","pick","pick"]\r\n[[[[-2,-2,-1,-1],[1,0,3,0]]],[],[],[],[],[]]\r\nOutput: \r\n[null,[-1,-2],[2,0],[-2,-1],[3,0],[-2,-2]]
    \r\n
    \r\n\r\n
    \r\n

    Explanation of Input Syntax:

    \r\n\r\n

    The input is two lists: the subroutines called and their arguments. Solution's constructor has one argument, the array of rectangles rects. pick has no arguments. Arguments are always wrapped with a list, even if there aren't any.

    \r\n
    \r\n
    \r\n\r\n
    \r\n
     
    \r\n
    \r\n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u91cd\u53e0\u8f74\u5bf9\u9f50\u77e9\u5f62\u7684\u5217\u8868 rects\uff0c\u5199\u4e00\u4e2a\u51fd\u6570 pick \u968f\u673a\u5747\u5300\u5730\u9009\u53d6\u77e9\u5f62\u8986\u76d6\u7684\u7a7a\u95f4\u4e2d\u7684\u6574\u6570\u70b9\u3002

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. \u6574\u6570\u70b9\u662f\u5177\u6709\u6574\u6570\u5750\u6807\u7684\u70b9\u3002
    2. \n\t
    3. \u77e9\u5f62\u5468\u8fb9\u4e0a\u7684\u70b9\u5305\u542b\u5728\u77e9\u5f62\u8986\u76d6\u7684\u7a7a\u95f4\u4e2d\u3002
    4. \n\t
    5. \u7b2c i \u4e2a\u77e9\u5f62 rects [i] = [x1\uff0cy1\uff0cx2\uff0cy2]\uff0c\u5176\u4e2d [x1\uff0cy1] \u662f\u5de6\u4e0b\u89d2\u7684\u6574\u6570\u5750\u6807\uff0c[x2\uff0cy2] \u662f\u53f3\u4e0a\u89d2\u7684\u6574\u6570\u5750\u6807\u3002
    6. \n\t
    7. \u6bcf\u4e2a\u77e9\u5f62\u7684\u957f\u5ea6\u548c\u5bbd\u5ea6\u4e0d\u8d85\u8fc7 2000\u3002
    8. \n\t
    9. 1 <= rects.length <= 100
    10. \n\t
    11. pick \u4ee5\u6574\u6570\u5750\u6807\u6570\u7ec4 [p_x, p_y] \u7684\u5f62\u5f0f\u8fd4\u56de\u4e00\u4e2a\u70b9\u3002
    12. \n\t
    13. pick \u6700\u591a\u88ab\u8c03\u752810000\u6b21\u3002
    14. \n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165: \n["Solution","pick","pick","pick"]\n[[[[1,1,5,5]]],[],[],[]]\n\u8f93\u51fa: \n[null,[4,1],[4,1],[3,3]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165: \n["Solution","pick","pick","pick","pick","pick"]\n[[[[-2,-2,-1,-1],[1,0,3,0]]],[],[],[],[],[]]\n\u8f93\u51fa: \n[null,[-1,-2],[2,0],[-2,-1],[3,0],[-2,-2]]
    \n\n

     

    \n\n

    \u8f93\u5165\u8bed\u6cd5\u7684\u8bf4\u660e\uff1a

    \n\n

    \u8f93\u5165\u662f\u4e24\u4e2a\u5217\u8868\uff1a\u8c03\u7528\u7684\u5b50\u4f8b\u7a0b\u53ca\u5176\u53c2\u6570\u3002Solution \u7684\u6784\u9020\u51fd\u6570\u6709\u4e00\u4e2a\u53c2\u6570\uff0c\u5373\u77e9\u5f62\u6570\u7ec4 rects\u3002pick \u6ca1\u6709\u53c2\u6570\u3002\u53c2\u6570\u603b\u662f\u7528\u5217\u8868\u5305\u88c5\u7684\uff0c\u5373\u4f7f\u6ca1\u6709\u4e5f\u662f\u5982\u6b64\u3002

    \n\n

     

    \n", "tags_en": ["Binary Search", "Random"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n Solution(vector>& rects) {\n\n }\n \n vector pick() {\n\n }\n};\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution* obj = new Solution(rects);\n * vector param_1 = obj->pick();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n\n public Solution(int[][] rects) {\n\n }\n \n public int[] pick() {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution obj = new Solution(rects);\n * int[] param_1 = obj.pick();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n\n def __init__(self, rects):\n \"\"\"\n :type rects: List[List[int]]\n \"\"\"\n \n\n def pick(self):\n \"\"\"\n :rtype: List[int]\n \"\"\"\n \n\n\n# Your Solution object will be instantiated and called as such:\n# obj = Solution(rects)\n# param_1 = obj.pick()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n\n def __init__(self, rects: List[List[int]]):\n \n\n def pick(self) -> List[int]:\n \n\n\n# Your Solution object will be instantiated and called as such:\n# obj = Solution(rects)\n# param_1 = obj.pick()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} Solution;\n\n\nSolution* solutionCreate(int** rects, int rectsSize, int* rectsColSize) {\n \n}\n\nint* solutionPick(Solution* obj, int* retSize) {\n \n}\n\nvoid solutionFree(Solution* obj) {\n \n}\n\n/**\n * Your Solution struct will be instantiated and called as such:\n * Solution* obj = solutionCreate(rects, rectsSize, rectsColSize);\n * int* param_1 = solutionPick(obj, retSize);\n \n * solutionFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n\n public Solution(int[][] rects) {\n\n }\n \n public int[] Pick() {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution obj = new Solution(rects);\n * int[] param_1 = obj.Pick();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} rects\n */\nvar Solution = function(rects) {\n\n};\n\n/**\n * @return {number[]}\n */\nSolution.prototype.pick = function() {\n\n};\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = new Solution(rects)\n * var param_1 = obj.pick()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class Solution\n\n=begin\n :type rects: Integer[][]\n=end\n def initialize(rects)\n\n end\n\n\n=begin\n :rtype: Integer[]\n=end\n def pick()\n\n end\n\n\nend\n\n# Your Solution object will be instantiated and called as such:\n# obj = Solution.new(rects)\n# param_1 = obj.pick()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass Solution {\n\n init(_ rects: [[Int]]) {\n \n }\n \n func pick() -> [Int] {\n \n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * let obj = Solution(rects)\n * let ret_1: [Int] = obj.pick()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type Solution struct {\n\n}\n\n\nfunc Constructor(rects [][]int) Solution {\n\n}\n\n\nfunc (this *Solution) Pick() []int {\n\n}\n\n\n/**\n * Your Solution object will be instantiated and called as such:\n * obj := Constructor(rects);\n * param_1 := obj.Pick();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class Solution(_rects: Array[Array[Int]]) {\n\n def pick(): Array[Int] = {\n\n }\n\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = new Solution(rects)\n * var param_1 = obj.pick()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution(rects: Array) {\n\n fun pick(): IntArray {\n\n }\n\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = Solution(rects)\n * var param_1 = obj.pick()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct Solution {\n\n}\n\n\n/** \n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl Solution {\n\n fn new(rects: Vec>) -> Self {\n \n }\n \n fn pick(&self) -> Vec {\n \n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * let obj = Solution::new(rects);\n * let ret_1: Vec = obj.pick();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n /**\n * @param Integer[][] $rects\n */\n function __construct($rects) {\n \n }\n \n /**\n * @return Integer[]\n */\n function pick() {\n \n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * $obj = Solution($rects);\n * $ret_1 = $obj->pick();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class Solution {\n constructor(rects: number[][]) {\n\n }\n\n pick(): number[] {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = new Solution(rects)\n * var param_1 = obj.pick()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define solution%\n (class object%\n (super-new)\n\n ; rects : (listof (listof exact-integer?))\n (init-field\n rects)\n \n ; pick : -> (listof exact-integer?)\n (define/public (pick)\n\n )))\n\n;; Your solution% object will be instantiated and called as such:\n;; (define obj (new solution% [rects rects]))\n;; (define param_1 (send obj pick))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0497](https://leetcode-cn.com/problems/random-point-in-non-overlapping-rectangles)", "[\u975e\u91cd\u53e0\u77e9\u5f62\u4e2d\u7684\u968f\u673a\u70b9](/solution/0400-0499/0497.Random%20Point%20in%20Non-overlapping%20Rectangles/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0497](https://leetcode.com/problems/random-point-in-non-overlapping-rectangles)", "[Random Point in Non-overlapping Rectangles](/solution/0400-0499/0497.Random%20Point%20in%20Non-overlapping%20Rectangles/README_EN.md)", "`Binary Search`,`Random`", "Medium", ""]}, {"question_id": "0913", "frontend_question_id": "0519", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/random-flip-matrix", "url_en": "https://leetcode.com/problems/random-flip-matrix", "relative_path_cn": "/solution/0500-0599/0519.Random%20Flip%20Matrix/README.md", "relative_path_en": "/solution/0500-0599/0519.Random%20Flip%20Matrix/README_EN.md", "title_cn": "\u968f\u673a\u7ffb\u8f6c\u77e9\u9635", "title_en": "Random Flip Matrix", "question_title_slug": "random-flip-matrix", "content_en": "

    You are given the number of rows n_rows and number of columns n_cols of a 2D binary matrix where all values are initially 0. Write a function flip which chooses a 0 value uniformly at random, changes it to 1, and then returns the position [row.id, col.id] of that value. Also, write a function reset which sets all values back to 0. Try to minimize the number of calls to system's Math.random() and optimize the time and space complexity.

    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    1. 1 <= n_rows, n_cols <= 10000
    2. \r\n\t
    3. 0 <= row.id < n_rows and 0 <= col.id < n_cols
    4. \r\n\t
    5. flip will not be called when the matrix has no 0 values left.
    6. \r\n\t
    7. the total number of calls to flip and reset will not exceed 1000.
    8. \r\n
    \r\n\r\n

    Example 1:

    \r\n\r\n
    \r\nInput: \r\n["Solution","flip","flip","flip","flip"]\r\n[[2,3],[],[],[],[]]\r\nOutput: [null,[0,1],[1,2],[1,0],[1,1]]\r\n
    \r\n\r\n
    \r\n

    Example 2:

    \r\n\r\n
    \r\nInput: \r\n["Solution","flip","flip","reset","flip"]\r\n[[1,2],[],[],[],[]]\r\nOutput: [null,[0,0],[0,1],null,[0,0]]
    \r\n
    \r\n\r\n

    Explanation of Input Syntax:

    \r\n\r\n

    The input is two lists: the subroutines called and their arguments. Solution's constructor has two arguments, n_rows and n_colsflip and reset have no arguments. Arguments are always wrapped with a list, even if there aren't any.

    \r\n", "content_cn": "

    \u9898\u4e2d\u7ed9\u51fa\u4e00\u4e2a n_rows \u884c n_cols \u5217\u7684\u4e8c\u7ef4\u77e9\u9635\uff0c\u4e14\u6240\u6709\u503c\u88ab\u521d\u59cb\u5316\u4e3a 0\u3002\u8981\u6c42\u7f16\u5199\u4e00\u4e2a flip \u51fd\u6570\uff0c\u5747\u5300\u968f\u673a\u7684\u5c06\u77e9\u9635\u4e2d\u7684 0 \u53d8\u4e3a 1\uff0c\u5e76\u8fd4\u56de\u8be5\u503c\u7684\u4f4d\u7f6e\u4e0b\u6807 [row_id,col_id]\uff1b\u540c\u6837\u7f16\u5199\u4e00\u4e2a reset \u51fd\u6570\uff0c\u5c06\u6240\u6709\u7684\u503c\u90fd\u91cd\u65b0\u7f6e\u4e3a 0\u3002\u5c3d\u91cf\u6700\u5c11\u8c03\u7528\u968f\u673a\u51fd\u6570 Math.random()\uff0c\u5e76\u4e14\u4f18\u5316\u65f6\u95f4\u548c\u7a7a\u95f4\u590d\u6742\u5ea6\u3002

    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. 1 <= n_rows, n_cols <= 10000
    2. \n\t
    3. 0 <= row.id < n_rows \u5e76\u4e14 0 <= col.id < n_cols
    4. \n\t
    5. \u5f53\u77e9\u9635\u4e2d\u6ca1\u6709\u503c\u4e3a 0 \u65f6\uff0c\u4e0d\u53ef\u4ee5\u8c03\u7528 flip \u51fd\u6570
    6. \n\t
    7. \u8c03\u7528 flip \u548c reset \u51fd\u6570\u7684\u6b21\u6570\u52a0\u8d77\u6765\u4e0d\u4f1a\u8d85\u8fc7 1000 \u6b21
    8. \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165: \n["Solution","flip","flip","flip","flip"]\n[[2,3],[],[],[],[]]\n\u8f93\u51fa: [null,[0,1],[1,2],[1,0],[1,1]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165: \n["Solution","flip","flip","reset","flip"]\n[[1,2],[],[],[],[]]\n\u8f93\u51fa: [null,[0,0],[0,1],null,[0,0]]
    \n\n

    \u8f93\u5165\u8bed\u6cd5\u89e3\u91ca\uff1a

    \n\n

    \u8f93\u5165\u5305\u542b\u4e24\u4e2a\u5217\u8868\uff1a\u88ab\u8c03\u7528\u7684\u5b50\u7a0b\u5e8f\u548c\u4ed6\u4eec\u7684\u53c2\u6570\u3002Solution \u7684\u6784\u9020\u51fd\u6570\u6709\u4e24\u4e2a\u53c2\u6570\uff0c\u5206\u522b\u4e3a n_rows \u548c n_cols\u3002flip \u548c reset \u6ca1\u6709\u53c2\u6570\uff0c\u53c2\u6570\u603b\u4f1a\u4ee5\u5217\u8868\u5f62\u5f0f\u7ed9\u51fa\uff0c\u54ea\u6015\u8be5\u5217\u8868\u4e3a\u7a7a

    \n", "tags_en": ["Random"], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n Solution(int n_rows, int n_cols) {\n\n }\n \n vector flip() {\n\n }\n \n void reset() {\n\n }\n};\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution* obj = new Solution(n_rows, n_cols);\n * vector param_1 = obj->flip();\n * obj->reset();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n\n public Solution(int n_rows, int n_cols) {\n\n }\n \n public int[] flip() {\n\n }\n \n public void reset() {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution obj = new Solution(n_rows, n_cols);\n * int[] param_1 = obj.flip();\n * obj.reset();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n\n def __init__(self, n_rows, n_cols):\n \"\"\"\n :type n_rows: int\n :type n_cols: int\n \"\"\"\n\n\n def flip(self):\n \"\"\"\n :rtype: List[int]\n \"\"\"\n\n\n def reset(self):\n \"\"\"\n :rtype: None\n \"\"\"\n\n\n\n# Your Solution object will be instantiated and called as such:\n# obj = Solution(n_rows, n_cols)\n# param_1 = obj.flip()\n# obj.reset()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n\n def __init__(self, n_rows: int, n_cols: int):\n\n\n def flip(self) -> List[int]:\n\n\n def reset(self) -> None:\n\n\n\n# Your Solution object will be instantiated and called as such:\n# obj = Solution(n_rows, n_cols)\n# param_1 = obj.flip()\n# obj.reset()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} Solution;\n\n\nSolution* solutionCreate(int n_rows, int n_cols) {\n\n}\n\nint* solutionFlip(Solution* obj, int* retSize) {\n\n}\n\nvoid solutionReset(Solution* obj) {\n\n}\n\nvoid solutionFree(Solution* obj) {\n\n}\n\n/**\n * Your Solution struct will be instantiated and called as such:\n * Solution* obj = solutionCreate(n_rows, n_cols);\n * int* param_1 = solutionFlip(obj, retSize);\n \n * solutionReset(obj);\n \n * solutionFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n\n public Solution(int n_rows, int n_cols) {\n\n }\n \n public int[] Flip() {\n\n }\n \n public void Reset() {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution obj = new Solution(n_rows, n_cols);\n * int[] param_1 = obj.Flip();\n * obj.Reset();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n_rows\n * @param {number} n_cols\n */\nvar Solution = function(n_rows, n_cols) {\n\n};\n\n/**\n * @return {number[]}\n */\nSolution.prototype.flip = function() {\n\n};\n\n/**\n * @return {void}\n */\nSolution.prototype.reset = function() {\n\n};\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = new Solution(n_rows, n_cols)\n * var param_1 = obj.flip()\n * obj.reset()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class Solution\n\n=begin\n :type n_rows: Integer\n :type n_cols: Integer\n=end\n def initialize(n_rows, n_cols)\n\n end\n\n\n=begin\n :rtype: Integer[]\n=end\n def flip()\n\n end\n\n\n=begin\n :rtype: Void\n=end\n def reset()\n\n end\n\n\nend\n\n# Your Solution object will be instantiated and called as such:\n# obj = Solution.new(n_rows, n_cols)\n# param_1 = obj.flip()\n# obj.reset()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass Solution {\n\n init(_ n_rows: Int, _ n_cols: Int) {\n\n }\n \n func flip() -> [Int] {\n\n }\n \n func reset() {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * let obj = Solution(n_rows, n_cols)\n * let ret_1: [Int] = obj.flip()\n * obj.reset()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type Solution struct {\n\n}\n\n\nfunc Constructor(n_rows int, n_cols int) Solution {\n\n}\n\n\nfunc (this *Solution) Flip() []int {\n\n}\n\n\nfunc (this *Solution) Reset() {\n\n}\n\n\n/**\n * Your Solution object will be instantiated and called as such:\n * obj := Constructor(n_rows, n_cols);\n * param_1 := obj.Flip();\n * obj.Reset();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class Solution(_n_rows: Int, _n_cols: Int) {\n\n def flip(): Array[Int] = {\n\n }\n\n def reset() {\n\n }\n\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = new Solution(n_rows, n_cols)\n * var param_1 = obj.flip()\n * obj.reset()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution(n_rows: Int, n_cols: Int) {\n\n fun flip(): IntArray {\n\n }\n\n fun reset() {\n\n }\n\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = Solution(n_rows, n_cols)\n * var param_1 = obj.flip()\n * obj.reset()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct Solution {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl Solution {\n\n fn new(n_rows: i32, n_cols: i32) -> Self {\n\n }\n \n fn flip(&self) -> Vec {\n\n }\n \n fn reset(&self) {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * let obj = Solution::new(n_rows, n_cols);\n * let ret_1: Vec = obj.flip();\n * obj.reset();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n /**\n * @param Integer $n_rows\n * @param Integer $n_cols\n */\n function __construct($n_rows, $n_cols) {\n\n }\n\n /**\n * @return Integer[]\n */\n function flip() {\n\n }\n\n /**\n * @return NULL\n */\n function reset() {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * $obj = Solution($n_rows, $n_cols);\n * $ret_1 = $obj->flip();\n * $obj->reset();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class Solution {\n constructor(n_rows: number, n_cols: number) {\n\n }\n\n flip(): number[] {\n\n }\n\n reset(): void {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = new Solution(n_rows, n_cols)\n * var param_1 = obj.flip()\n * obj.reset()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define solution%\n (class object%\n (super-new)\n\n ; n_rows : exact-integer?\n\n ; n_cols : exact-integer?\n (init-field\n n_rows\n n_cols)\n \n ; flip : -> (listof exact-integer?)\n (define/public (flip)\n\n )\n ; reset : -> void?\n (define/public (reset)\n\n )))\n\n;; Your solution% object will be instantiated and called as such:\n;; (define obj (new solution% [n_rows n_rows] [n_cols n_cols]))\n;; (define param_1 (send obj flip))\n;; (send obj reset)", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0519](https://leetcode-cn.com/problems/random-flip-matrix)", "[\u968f\u673a\u7ffb\u8f6c\u77e9\u9635](/solution/0500-0599/0519.Random%20Flip%20Matrix/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0519](https://leetcode.com/problems/random-flip-matrix)", "[Random Flip Matrix](/solution/0500-0599/0519.Random%20Flip%20Matrix/README_EN.md)", "`Random`", "Medium", ""]}, {"question_id": "0912", "frontend_question_id": "0528", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/random-pick-with-weight", "url_en": "https://leetcode.com/problems/random-pick-with-weight", "relative_path_cn": "/solution/0500-0599/0528.Random%20Pick%20with%20Weight/README.md", "relative_path_en": "/solution/0500-0599/0528.Random%20Pick%20with%20Weight/README_EN.md", "title_cn": "\u6309\u6743\u91cd\u968f\u673a\u9009\u62e9", "title_en": "Random Pick with Weight", "question_title_slug": "random-pick-with-weight", "content_en": "

    You are given an array of positive integers w where w[i] describes the weight of ith index (0-indexed).

    \n\n

    We need to call the function pickIndex() which randomly returns an integer in the range [0, w.length - 1]pickIndex() should return the integer proportional to its weight in the w array. For example, for w = [1, 3], the probability of picking the index 0 is 1 / (1 + 3) = 0.25 (i.e 25%) while the probability of picking the index 1 is 3 / (1 + 3) = 0.75 (i.e 75%).

    \n\n

    More formally, the probability of picking index i is w[i] / sum(w).

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["Solution","pickIndex"]\n[[[1]],[]]\nOutput\n[null,0]\n\nExplanation\nSolution solution = new Solution([1]);\nsolution.pickIndex(); // return 0. Since there is only one single element on the array the only option is to return the first element.\n
    \n\n

    Example 2:

    \n\n
    \nInput\n["Solution","pickIndex","pickIndex","pickIndex","pickIndex","pickIndex"]\n[[[1,3]],[],[],[],[],[]]\nOutput\n[null,1,1,1,1,0]\n\nExplanation\nSolution solution = new Solution([1, 3]);\nsolution.pickIndex(); // return 1. It's returning the second element (index = 1) that has probability of 3/4.\nsolution.pickIndex(); // return 1\nsolution.pickIndex(); // return 1\nsolution.pickIndex(); // return 1\nsolution.pickIndex(); // return 0. It's returning the first element (index = 0) that has probability of 1/4.\n\nSince this is a randomization problem, multiple answers are allowed so the following outputs can be considered correct :\n[null,1,1,1,1,0]\n[null,1,1,1,1,1]\n[null,1,1,1,0,0]\n[null,1,1,1,0,1]\n[null,1,0,1,0,0]\n......\nand so on.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= w.length <= 10000
    • \n\t
    • 1 <= w[i] <= 10^5
    • \n\t
    • pickIndex will be called at most 10000 times.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6b63\u6574\u6570\u6570\u7ec4 w \uff0c\u5176\u4e2d w[i] \u4ee3\u8868\u4e0b\u6807 i \u7684\u6743\u91cd\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\uff0c\u8bf7\u5199\u4e00\u4e2a\u51fd\u6570 pickIndex \uff0c\u5b83\u53ef\u4ee5\u968f\u673a\u5730\u83b7\u53d6\u4e0b\u6807 i\uff0c\u9009\u53d6\u4e0b\u6807 i \u7684\u6982\u7387\u4e0e w[i] \u6210\u6b63\u6bd4\u3002

    \n\n
      \n
    \n\n

    \u4f8b\u5982\uff0c\u5bf9\u4e8e w = [1, 3]\uff0c\u6311\u9009\u4e0b\u6807 0 \u7684\u6982\u7387\u4e3a 1 / (1 + 3) = 0.25 \uff08\u5373\uff0c25%\uff09\uff0c\u800c\u9009\u53d6\u4e0b\u6807 1 \u7684\u6982\u7387\u4e3a 3 / (1 + 3) = 0.75\uff08\u5373\uff0c75%\uff09\u3002

    \n\n

    \u4e5f\u5c31\u662f\u8bf4\uff0c\u9009\u53d6\u4e0b\u6807 i \u7684\u6982\u7387\u4e3a w[i] / sum(w) \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a\n["Solution","pickIndex"]\n[[[1]],[]]\n\u8f93\u51fa\uff1a\n[null,0]\n\u89e3\u91ca\uff1a\nSolution solution = new Solution([1]);\nsolution.pickIndex(); // \u8fd4\u56de 0\uff0c\u56e0\u4e3a\u6570\u7ec4\u4e2d\u53ea\u6709\u4e00\u4e2a\u5143\u7d20\uff0c\u6240\u4ee5\u552f\u4e00\u7684\u9009\u62e9\u662f\u8fd4\u56de\u4e0b\u6807 0\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a\n["Solution","pickIndex","pickIndex","pickIndex","pickIndex","pickIndex"]\n[[[1,3]],[],[],[],[],[]]\n\u8f93\u51fa\uff1a\n[null,1,1,1,1,0]\n\u89e3\u91ca\uff1a\nSolution solution = new Solution([1, 3]);\nsolution.pickIndex(); // \u8fd4\u56de 1\uff0c\u8fd4\u56de\u4e0b\u6807 1\uff0c\u8fd4\u56de\u8be5\u4e0b\u6807\u6982\u7387\u4e3a 3/4 \u3002\nsolution.pickIndex(); // \u8fd4\u56de 1\nsolution.pickIndex(); // \u8fd4\u56de 1\nsolution.pickIndex(); // \u8fd4\u56de 1\nsolution.pickIndex(); // \u8fd4\u56de 0\uff0c\u8fd4\u56de\u4e0b\u6807 0\uff0c\u8fd4\u56de\u8be5\u4e0b\u6807\u6982\u7387\u4e3a 1/4 \u3002\n\n\u7531\u4e8e\u8fd9\u662f\u4e00\u4e2a\u968f\u673a\u95ee\u9898\uff0c\u5141\u8bb8\u591a\u4e2a\u7b54\u6848\uff0c\u56e0\u6b64\u4e0b\u5217\u8f93\u51fa\u90fd\u53ef\u4ee5\u88ab\u8ba4\u4e3a\u662f\u6b63\u786e\u7684:\n[null,1,1,1,1,0]\n[null,1,1,1,1,1]\n[null,1,1,1,0,0]\n[null,1,1,1,0,1]\n[null,1,0,1,0,0]\n......\n\u8bf8\u82e5\u6b64\u7c7b\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= w.length <= 10000
    • \n\t
    • 1 <= w[i] <= 10^5
    • \n\t
    • pickIndex \u5c06\u88ab\u8c03\u7528\u4e0d\u8d85\u8fc7 10000 \u6b21
    • \n
    \n", "tags_en": ["Binary Search", "Random"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n Solution(vector& w) {\n\n }\n \n int pickIndex() {\n\n }\n};\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution* obj = new Solution(w);\n * int param_1 = obj->pickIndex();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n\n public Solution(int[] w) {\n\n }\n \n public int pickIndex() {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution obj = new Solution(w);\n * int param_1 = obj.pickIndex();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n\n def __init__(self, w):\n \"\"\"\n :type w: List[int]\n \"\"\"\n\n\n def pickIndex(self):\n \"\"\"\n :rtype: int\n \"\"\"\n\n\n\n# Your Solution object will be instantiated and called as such:\n# obj = Solution(w)\n# param_1 = obj.pickIndex()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n\n def __init__(self, w: List[int]):\n\n\n def pickIndex(self) -> int:\n\n\n\n# Your Solution object will be instantiated and called as such:\n# obj = Solution(w)\n# param_1 = obj.pickIndex()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} Solution;\n\n\nSolution* solutionCreate(int* w, int wSize) {\n\n}\n\nint solutionPickIndex(Solution* obj) {\n\n}\n\nvoid solutionFree(Solution* obj) {\n\n}\n\n/**\n * Your Solution struct will be instantiated and called as such:\n * Solution* obj = solutionCreate(w, wSize);\n * int param_1 = solutionPickIndex(obj);\n \n * solutionFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n\n public Solution(int[] w) {\n\n }\n \n public int PickIndex() {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution obj = new Solution(w);\n * int param_1 = obj.PickIndex();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} w\n */\nvar Solution = function(w) {\n\n};\n\n/**\n * @return {number}\n */\nSolution.prototype.pickIndex = function() {\n\n};\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = new Solution(w)\n * var param_1 = obj.pickIndex()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class Solution\n\n=begin\n :type w: Integer[]\n=end\n def initialize(w)\n\n end\n\n\n=begin\n :rtype: Integer\n=end\n def pick_index()\n\n end\n\n\nend\n\n# Your Solution object will be instantiated and called as such:\n# obj = Solution.new(w)\n# param_1 = obj.pick_index()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass Solution {\n\n init(_ w: [Int]) {\n \n }\n \n func pickIndex() -> Int {\n \n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * let obj = Solution(w)\n * let ret_1: Int = obj.pickIndex()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type Solution struct {\n\n}\n\n\nfunc Constructor(w []int) Solution {\n\n}\n\n\nfunc (this *Solution) PickIndex() int {\n\n}\n\n\n/**\n * Your Solution object will be instantiated and called as such:\n * obj := Constructor(w);\n * param_1 := obj.PickIndex();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class Solution(_w: Array[Int]) {\n\n def pickIndex(): Int = {\n\n }\n\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = new Solution(w)\n * var param_1 = obj.pickIndex()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution(w: IntArray) {\n\n fun pickIndex(): Int {\n\n }\n\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = Solution(w)\n * var param_1 = obj.pickIndex()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct Solution {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl Solution {\n\n fn new(w: Vec) -> Self {\n\n }\n \n fn pick_index(&self) -> i32 {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * let obj = Solution::new(w);\n * let ret_1: i32 = obj.pick_index();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n /**\n * @param Integer[] $w\n */\n function __construct($w) {\n \n }\n \n /**\n * @return Integer\n */\n function pickIndex() {\n \n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * $obj = Solution($w);\n * $ret_1 = $obj->pickIndex();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class Solution {\n constructor(w: number[]) {\n\n }\n\n pickIndex(): number {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = new Solution(w)\n * var param_1 = obj.pickIndex()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define solution%\n (class object%\n (super-new)\n\n ; w : (listof exact-integer?)\n (init-field\n w)\n \n ; pick-index : -> exact-integer?\n (define/public (pick-index)\n\n )))\n\n;; Your solution% object will be instantiated and called as such:\n;; (define obj (new solution% [w w]))\n;; (define param_1 (send obj pick-index))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0528](https://leetcode-cn.com/problems/random-pick-with-weight)", "[\u6309\u6743\u91cd\u968f\u673a\u9009\u62e9](/solution/0500-0599/0528.Random%20Pick%20with%20Weight/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0528](https://leetcode.com/problems/random-pick-with-weight)", "[Random Pick with Weight](/solution/0500-0599/0528.Random%20Pick%20with%20Weight/README_EN.md)", "`Binary Search`,`Random`", "Medium", ""]}, {"question_id": "0911", "frontend_question_id": "0879", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/profitable-schemes", "url_en": "https://leetcode.com/problems/profitable-schemes", "relative_path_cn": "/solution/0800-0899/0879.Profitable%20Schemes/README.md", "relative_path_en": "/solution/0800-0899/0879.Profitable%20Schemes/README_EN.md", "title_cn": "\u76c8\u5229\u8ba1\u5212", "title_en": "Profitable Schemes", "question_title_slug": "profitable-schemes", "content_en": "

    There is a group of n members, and a list of various crimes they could commit. The ith crime generates a profit[i] and requires group[i] members to participate in it. If a member participates in one crime, that member can't participate in another crime.

    \n\n

    Let's call a profitable scheme any subset of these crimes that generates at least minProfit profit, and the total number of members participating in that subset of crimes is at most n.

    \n\n

    Return the number of schemes that can be chosen. Since the answer may be very large, return it modulo 109 + 7.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 5, minProfit = 3, group = [2,2], profit = [2,3]\nOutput: 2\nExplanation: To make a profit of at least 3, the group could either commit crimes 0 and 1, or just crime 1.\nIn total, there are 2 schemes.
    \n\n

    Example 2:

    \n\n
    \nInput: n = 10, minProfit = 5, group = [2,3,5], profit = [6,7,8]\nOutput: 7\nExplanation: To make a profit of at least 5, the group could commit any crimes, as long as they commit one.\nThere are 7 possible schemes: (0), (1), (2), (0,1), (0,2), (1,2), and (0,1,2).
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 100
    • \n\t
    • 0 <= minProfit <= 100
    • \n\t
    • 1 <= group.length <= 100
    • \n\t
    • 1 <= group[i] <= 100
    • \n\t
    • profit.length == group.length
    • \n\t
    • 0 <= profit[i] <= 100
    • \n
    \n", "content_cn": "

    \u96c6\u56e2\u91cc\u6709 n \u540d\u5458\u5de5\uff0c\u4ed6\u4eec\u53ef\u4ee5\u5b8c\u6210\u5404\u79cd\u5404\u6837\u7684\u5de5\u4f5c\u521b\u9020\u5229\u6da6\u3002

    \n\n

    \u7b2c\u00a0i\u00a0\u79cd\u5de5\u4f5c\u4f1a\u4ea7\u751f\u00a0profit[i]\u00a0\u7684\u5229\u6da6\uff0c\u5b83\u8981\u6c42\u00a0group[i]\u00a0\u540d\u6210\u5458\u5171\u540c\u53c2\u4e0e\u3002\u5982\u679c\u6210\u5458\u53c2\u4e0e\u4e86\u5176\u4e2d\u4e00\u9879\u5de5\u4f5c\uff0c\u5c31\u4e0d\u80fd\u53c2\u4e0e\u53e6\u4e00\u9879\u5de5\u4f5c\u3002

    \n\n

    \u5de5\u4f5c\u7684\u4efb\u4f55\u81f3\u5c11\u4ea7\u751f\u00a0minProfit \u5229\u6da6\u7684\u5b50\u96c6\u79f0\u4e3a\u76c8\u5229\u8ba1\u5212\u3002\u5e76\u4e14\u5de5\u4f5c\u7684\u6210\u5458\u603b\u6570\u6700\u591a\u4e3a n \u3002

    \n\n

    \u6709\u591a\u5c11\u79cd\u8ba1\u5212\u53ef\u4ee5\u9009\u62e9\uff1f\u56e0\u4e3a\u7b54\u6848\u5f88\u5927\uff0c\u6240\u4ee5 \u8fd4\u56de\u7ed3\u679c\u6a21\u00a010^9 + 7\u00a0\u7684\u503c\u3002

    \n\n
    \n
    \n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 5, minProfit = 3, group = [2,2], profit = [2,3]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u81f3\u5c11\u4ea7\u751f 3 \u7684\u5229\u6da6\uff0c\u8be5\u96c6\u56e2\u53ef\u4ee5\u5b8c\u6210\u5de5\u4f5c 0 \u548c\u5de5\u4f5c 1 \uff0c\u6216\u4ec5\u5b8c\u6210\u5de5\u4f5c 1 \u3002\n\u603b\u7684\u6765\u8bf4\uff0c\u6709\u4e24\u79cd\u8ba1\u5212\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 10, minProfit = 5, group = [2,3,5], profit = [6,7,8]\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\u81f3\u5c11\u4ea7\u751f 5 \u7684\u5229\u6da6\uff0c\u53ea\u8981\u5b8c\u6210\u5176\u4e2d\u4e00\u79cd\u5de5\u4f5c\u5c31\u884c\uff0c\u6240\u4ee5\u8be5\u96c6\u56e2\u53ef\u4ee5\u5b8c\u6210\u4efb\u4f55\u5de5\u4f5c\u3002\n\u6709 7 \u79cd\u53ef\u80fd\u7684\u8ba1\u5212\uff1a(0)\uff0c(1)\uff0c(2)\uff0c(0,1)\uff0c(0,2)\uff0c(1,2)\uff0c\u4ee5\u53ca (0,1,2) \u3002
    \n
    \n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 100
    • \n\t
    • 0 <= minProfit <= 100
    • \n\t
    • 1 <= group.length <= 100
    • \n\t
    • 1 <= group[i] <= 100
    • \n\t
    • profit.length == group.length
    • \n\t
    • 0 <= profit[i] <= 100
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int profitableSchemes(int n, int minProfit, vector& group, vector& profit) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int profitableSchemes(int n, int minProfit, int[] group, int[] profit) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def profitableSchemes(self, n, minProfit, group, profit):\n \"\"\"\n :type n: int\n :type minProfit: int\n :type group: List[int]\n :type profit: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def profitableSchemes(self, n: int, minProfit: int, group: List[int], profit: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint profitableSchemes(int n, int minProfit, int* group, int groupSize, int* profit, int profitSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ProfitableSchemes(int n, int minProfit, int[] group, int[] profit) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} minProfit\n * @param {number[]} group\n * @param {number[]} profit\n * @return {number}\n */\nvar profitableSchemes = function(n, minProfit, group, profit) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} min_profit\n# @param {Integer[]} group\n# @param {Integer[]} profit\n# @return {Integer}\ndef profitable_schemes(n, min_profit, group, profit)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func profitableSchemes(_ n: Int, _ minProfit: Int, _ group: [Int], _ profit: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func profitableSchemes(n int, minProfit int, group []int, profit []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def profitableSchemes(n: Int, minProfit: Int, group: Array[Int], profit: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun profitableSchemes(n: Int, minProfit: Int, group: IntArray, profit: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn profitable_schemes(n: i32, min_profit: i32, group: Vec, profit: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $minProfit\n * @param Integer[] $group\n * @param Integer[] $profit\n * @return Integer\n */\n function profitableSchemes($n, $minProfit, $group, $profit) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function profitableSchemes(n: number, minProfit: number, group: number[], profit: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (profitable-schemes n minProfit group profit)\n (-> exact-integer? exact-integer? (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0879](https://leetcode-cn.com/problems/profitable-schemes)", "[\u76c8\u5229\u8ba1\u5212](/solution/0800-0899/0879.Profitable%20Schemes/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0879](https://leetcode.com/problems/profitable-schemes)", "[Profitable Schemes](/solution/0800-0899/0879.Profitable%20Schemes/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "0910", "frontend_question_id": "0878", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/nth-magical-number", "url_en": "https://leetcode.com/problems/nth-magical-number", "relative_path_cn": "/solution/0800-0899/0878.Nth%20Magical%20Number/README.md", "relative_path_en": "/solution/0800-0899/0878.Nth%20Magical%20Number/README_EN.md", "title_cn": "\u7b2c N \u4e2a\u795e\u5947\u6570\u5b57", "title_en": "Nth Magical Number", "question_title_slug": "nth-magical-number", "content_en": "

    A positive integer is magical if it is divisible by either a or b.

    \n\n

    Given the three integers n, a, and b, return the nth magical number. Since the answer may be very large, return it modulo 109 + 7.

    \n\n

     

    \n

    Example 1:

    \n
    Input: n = 1, a = 2, b = 3\nOutput: 2\n

    Example 2:

    \n
    Input: n = 4, a = 2, b = 3\nOutput: 6\n

    Example 3:

    \n
    Input: n = 5, a = 2, b = 4\nOutput: 10\n

    Example 4:

    \n
    Input: n = 3, a = 6, b = 4\nOutput: 8\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 109
    • \n\t
    • 2 <= a, b <= 4 * 104
    • \n
    \n", "content_cn": "

    \u5982\u679c\u6b63\u6574\u6570\u53ef\u4ee5\u88ab A \u6216 B \u6574\u9664\uff0c\u90a3\u4e48\u5b83\u662f\u795e\u5947\u7684\u3002

    \n\n

    \u8fd4\u56de\u7b2c N \u4e2a\u795e\u5947\u6570\u5b57\u3002\u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u975e\u5e38\u5927\uff0c\u8fd4\u56de\u5b83\u6a21 10^9 + 7 \u7684\u7ed3\u679c\u3002

    \n\n

     

    \n\n
      \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aN = 1, A = 2, B = 3\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aN = 4, A = 2, B = 3\n\u8f93\u51fa\uff1a6\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aN = 5, A = 2, B = 4\n\u8f93\u51fa\uff1a10\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1aN = 3, A = 6, B = 4\n\u8f93\u51fa\uff1a8\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= N <= 10^9
    2. \n\t
    3. 2 <= A <= 40000
    4. \n\t
    5. 2 <= B <= 40000
    6. \n
    \n", "tags_en": ["Math", "Binary Search"], "tags_cn": ["\u6570\u5b66", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int nthMagicalNumber(int n, int a, int b) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int nthMagicalNumber(int n, int a, int b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def nthMagicalNumber(self, n, a, b):\n \"\"\"\n :type n: int\n :type a: int\n :type b: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def nthMagicalNumber(self, n: int, a: int, b: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint nthMagicalNumber(int n, int a, int b){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NthMagicalNumber(int n, int a, int b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} a\n * @param {number} b\n * @return {number}\n */\nvar nthMagicalNumber = function(n, a, b) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} a\n# @param {Integer} b\n# @return {Integer}\ndef nth_magical_number(n, a, b)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func nthMagicalNumber(_ n: Int, _ a: Int, _ b: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func nthMagicalNumber(n int, a int, b int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def nthMagicalNumber(n: Int, a: Int, b: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun nthMagicalNumber(n: Int, a: Int, b: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn nth_magical_number(n: i32, a: i32, b: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $a\n * @param Integer $b\n * @return Integer\n */\n function nthMagicalNumber($n, $a, $b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function nthMagicalNumber(n: number, a: number, b: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (nth-magical-number n a b)\n (-> exact-integer? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0878](https://leetcode-cn.com/problems/nth-magical-number)", "[\u7b2c N \u4e2a\u795e\u5947\u6570\u5b57](/solution/0800-0899/0878.Nth%20Magical%20Number/README.md)", "`\u6570\u5b66`,`\u4e8c\u5206\u67e5\u627e`", "\u56f0\u96be", ""], "md_table_row_en": ["[0878](https://leetcode.com/problems/nth-magical-number)", "[Nth Magical Number](/solution/0800-0899/0878.Nth%20Magical%20Number/README_EN.md)", "`Math`,`Binary Search`", "Hard", ""]}, {"question_id": "0909", "frontend_question_id": "0877", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/stone-game", "url_en": "https://leetcode.com/problems/stone-game", "relative_path_cn": "/solution/0800-0899/0877.Stone%20Game/README.md", "relative_path_en": "/solution/0800-0899/0877.Stone%20Game/README_EN.md", "title_cn": "\u77f3\u5b50\u6e38\u620f", "title_en": "Stone Game", "question_title_slug": "stone-game", "content_en": "

    Alex and Lee play a game with piles of stones.  There are an even number of piles arranged in a row, and each pile has a positive integer number of stones piles[i].

    \n\n

    The objective of the game is to end with the most stones.  The total number of stones is odd, so there are no ties.

    \n\n

    Alex and Lee take turns, with Alex starting first.  Each turn, a player takes the entire pile of stones from either the beginning or the end of the row.  This continues until there are no more piles left, at which point the person with the most stones wins.

    \n\n

    Assuming Alex and Lee play optimally, return True if and only if Alex wins the game.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: piles = [5,3,4,5]\nOutput: true\nExplanation: \nAlex starts first, and can only take the first 5 or the last 5.\nSay he takes the first 5, so that the row becomes [3, 4, 5].\nIf Lee takes 3, then the board is [4, 5], and Alex takes 5 to win with 10 points.\nIf Lee takes the last 5, then the board is [3, 4], and Alex takes 4 to win with 9 points.\nThis demonstrated that taking the first 5 was a winning move for Alex, so we return true.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= piles.length <= 500
    • \n\t
    • piles.length is even.
    • \n\t
    • 1 <= piles[i] <= 500
    • \n\t
    • sum(piles) is odd.
    • \n
    \n", "content_cn": "

    \u4e9a\u5386\u514b\u65af\u548c\u674e\u7528\u51e0\u5806\u77f3\u5b50\u5728\u505a\u6e38\u620f\u3002\u5076\u6570\u5806\u77f3\u5b50\u6392\u6210\u4e00\u884c\uff0c\u6bcf\u5806\u90fd\u6709\u6b63\u6574\u6570\u9897\u77f3\u5b50 piles[i] \u3002

    \n\n

    \u6e38\u620f\u4ee5\u8c01\u624b\u4e2d\u7684\u77f3\u5b50\u6700\u591a\u6765\u51b3\u51fa\u80dc\u8d1f\u3002\u77f3\u5b50\u7684\u603b\u6570\u662f\u5947\u6570\uff0c\u6240\u4ee5\u6ca1\u6709\u5e73\u5c40\u3002

    \n\n

    \u4e9a\u5386\u514b\u65af\u548c\u674e\u8f6e\u6d41\u8fdb\u884c\uff0c\u4e9a\u5386\u514b\u65af\u5148\u5f00\u59cb\u3002 \u6bcf\u56de\u5408\uff0c\u73a9\u5bb6\u4ece\u884c\u7684\u5f00\u59cb\u6216\u7ed3\u675f\u5904\u53d6\u8d70\u6574\u5806\u77f3\u5934\u3002 \u8fd9\u79cd\u60c5\u51b5\u4e00\u76f4\u6301\u7eed\u5230\u6ca1\u6709\u66f4\u591a\u7684\u77f3\u5b50\u5806\u4e3a\u6b62\uff0c\u6b64\u65f6\u624b\u4e2d\u77f3\u5b50\u6700\u591a\u7684\u73a9\u5bb6\u83b7\u80dc\u3002

    \n\n

    \u5047\u8bbe\u4e9a\u5386\u514b\u65af\u548c\u674e\u90fd\u53d1\u6325\u51fa\u6700\u4f73\u6c34\u5e73\uff0c\u5f53\u4e9a\u5386\u514b\u65af\u8d62\u5f97\u6bd4\u8d5b\u65f6\u8fd4\u56de true \uff0c\u5f53\u674e\u8d62\u5f97\u6bd4\u8d5b\u65f6\u8fd4\u56de false \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1a[5,3,4,5]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\n\u4e9a\u5386\u514b\u65af\u5148\u5f00\u59cb\uff0c\u53ea\u80fd\u62ff\u524d 5 \u9897\u6216\u540e 5 \u9897\u77f3\u5b50 \u3002\n\u5047\u8bbe\u4ed6\u53d6\u4e86\u524d 5 \u9897\uff0c\u8fd9\u4e00\u884c\u5c31\u53d8\u6210\u4e86 [3,4,5] \u3002\n\u5982\u679c\u674e\u62ff\u8d70\u524d 3 \u9897\uff0c\u90a3\u4e48\u5269\u4e0b\u7684\u662f [4,5]\uff0c\u4e9a\u5386\u514b\u65af\u62ff\u8d70\u540e 5 \u9897\u8d62\u5f97 10 \u5206\u3002\n\u5982\u679c\u674e\u62ff\u8d70\u540e 5 \u9897\uff0c\u90a3\u4e48\u5269\u4e0b\u7684\u662f [3,4]\uff0c\u4e9a\u5386\u514b\u65af\u62ff\u8d70\u540e 4 \u9897\u8d62\u5f97 9 \u5206\u3002\n\u8fd9\u8868\u660e\uff0c\u53d6\u524d 5 \u9897\u77f3\u5b50\u5bf9\u4e9a\u5386\u514b\u65af\u6765\u8bf4\u662f\u4e00\u4e2a\u80dc\u5229\u7684\u4e3e\u52a8\uff0c\u6240\u4ee5\u6211\u4eec\u8fd4\u56de true \u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 2 <= piles.length <= 500
    2. \n\t
    3. piles.length \u662f\u5076\u6570\u3002
    4. \n\t
    5. 1 <= piles[i] <= 500
    6. \n\t
    7. sum(piles) \u662f\u5947\u6570\u3002
    8. \n
    \n", "tags_en": ["Minimax", "Math", "Dynamic Programming"], "tags_cn": ["\u6781\u5c0f\u5316\u6781\u5927", "\u6570\u5b66", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool stoneGame(vector& piles) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean stoneGame(int[] piles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def stoneGame(self, piles):\n \"\"\"\n :type piles: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def stoneGame(self, piles: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool stoneGame(int* piles, int pilesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool StoneGame(int[] piles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} piles\n * @return {boolean}\n */\nvar stoneGame = function(piles) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} piles\n# @return {Boolean}\ndef stone_game(piles)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func stoneGame(_ piles: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func stoneGame(piles []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def stoneGame(piles: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun stoneGame(piles: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn stone_game(piles: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $piles\n * @return Boolean\n */\n function stoneGame($piles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function stoneGame(piles: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (stone-game piles)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0877](https://leetcode-cn.com/problems/stone-game)", "[\u77f3\u5b50\u6e38\u620f](/solution/0800-0899/0877.Stone%20Game/README.md)", "`\u6781\u5c0f\u5316\u6781\u5927`,`\u6570\u5b66`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0877](https://leetcode.com/problems/stone-game)", "[Stone Game](/solution/0800-0899/0877.Stone%20Game/README_EN.md)", "`Minimax`,`Math`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0908", "frontend_question_id": "0876", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/middle-of-the-linked-list", "url_en": "https://leetcode.com/problems/middle-of-the-linked-list", "relative_path_cn": "/solution/0800-0899/0876.Middle%20of%20the%20Linked%20List/README.md", "relative_path_en": "/solution/0800-0899/0876.Middle%20of%20the%20Linked%20List/README_EN.md", "title_cn": "\u94fe\u8868\u7684\u4e2d\u95f4\u7ed3\u70b9", "title_en": "Middle of the Linked List", "question_title_slug": "middle-of-the-linked-list", "content_en": "

    Given a non-empty, singly linked list with head node head, return a middle node of linked list.

    \r\n\r\n

    If there are two middle nodes, return the second middle node.

    \r\n\r\n

     

    \r\n\r\n
    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: [1,2,3,4,5]\r\nOutput: Node 3 from this list (Serialization: [3,4,5])\r\nThe returned node has value 3.  (The judge's serialization of this node is [3,4,5]).\r\nNote that we returned a ListNode object ans, such that:\r\nans.val = 3, ans.next.val = 4, ans.next.next.val = 5, and ans.next.next.next = NULL.\r\n
    \r\n\r\n
    \r\n

    Example 2:

    \r\n\r\n
    \r\nInput: [1,2,3,4,5,6]\r\nOutput: Node 4 from this list (Serialization: [4,5,6])\r\nSince the list has two middle nodes with values 3 and 4, we return the second one.\r\n
    \r\n\r\n

     

    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    • The number of nodes in the given list will be between 1 and 100.
    • \r\n
    \r\n
    \r\n
    \r\n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5934\u7ed3\u70b9\u4e3a head\u00a0\u7684\u975e\u7a7a\u5355\u94fe\u8868\uff0c\u8fd4\u56de\u94fe\u8868\u7684\u4e2d\u95f4\u7ed3\u70b9\u3002

    \n\n

    \u5982\u679c\u6709\u4e24\u4e2a\u4e2d\u95f4\u7ed3\u70b9\uff0c\u5219\u8fd4\u56de\u7b2c\u4e8c\u4e2a\u4e2d\u95f4\u7ed3\u70b9\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[1,2,3,4,5]\n\u8f93\u51fa\uff1a\u6b64\u5217\u8868\u4e2d\u7684\u7ed3\u70b9 3 (\u5e8f\u5217\u5316\u5f62\u5f0f\uff1a[3,4,5])\n\u8fd4\u56de\u7684\u7ed3\u70b9\u503c\u4e3a 3 \u3002 (\u6d4b\u8bc4\u7cfb\u7edf\u5bf9\u8be5\u7ed3\u70b9\u5e8f\u5217\u5316\u8868\u8ff0\u662f [3,4,5])\u3002\n\u6ce8\u610f\uff0c\u6211\u4eec\u8fd4\u56de\u4e86\u4e00\u4e2a ListNode \u7c7b\u578b\u7684\u5bf9\u8c61 ans\uff0c\u8fd9\u6837\uff1a\nans.val = 3, ans.next.val = 4, ans.next.next.val = 5, \u4ee5\u53ca ans.next.next.next = NULL.\n
    \n\n

    \u793a\u4f8b\u00a02\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[1,2,3,4,5,6]\n\u8f93\u51fa\uff1a\u6b64\u5217\u8868\u4e2d\u7684\u7ed3\u70b9 4 (\u5e8f\u5217\u5316\u5f62\u5f0f\uff1a[4,5,6])\n\u7531\u4e8e\u8be5\u5217\u8868\u6709\u4e24\u4e2a\u4e2d\u95f4\u7ed3\u70b9\uff0c\u503c\u5206\u522b\u4e3a 3 \u548c 4\uff0c\u6211\u4eec\u8fd4\u56de\u7b2c\u4e8c\u4e2a\u7ed3\u70b9\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u7ed9\u5b9a\u94fe\u8868\u7684\u7ed3\u70b9\u6570\u4ecb\u4e8e\u00a01\u00a0\u548c\u00a0100\u00a0\u4e4b\u95f4\u3002
    • \n
    \n", "tags_en": ["Linked List"], "tags_cn": ["\u94fe\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n ListNode* middleNode(ListNode* head) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public ListNode middleNode(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def middleNode(self, head):\n \"\"\"\n :type head: ListNode\n :rtype: ListNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def middleNode(self, head: ListNode) -> ListNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nstruct ListNode* middleNode(struct ListNode* head){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public ListNode MiddleNode(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} head\n * @return {ListNode}\n */\nvar middleNode = function(head) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode} head\n# @return {ListNode}\ndef middle_node(head)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func middleNode(_ head: ListNode?) -> ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc middleNode(head *ListNode) *ListNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def middleNode(head: ListNode): ListNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun middleNode(head: ListNode?): ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn middle_node(head: Option>) -> Option> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @return ListNode\n */\n function middleNode($head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction middleNode(head: ListNode | null): ListNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (middle-node head)\n (-> (or/c list-node? #f) (or/c list-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0876](https://leetcode-cn.com/problems/middle-of-the-linked-list)", "[\u94fe\u8868\u7684\u4e2d\u95f4\u7ed3\u70b9](/solution/0800-0899/0876.Middle%20of%20the%20Linked%20List/README.md)", "`\u94fe\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0876](https://leetcode.com/problems/middle-of-the-linked-list)", "[Middle of the Linked List](/solution/0800-0899/0876.Middle%20of%20the%20Linked%20List/README_EN.md)", "`Linked List`", "Easy", ""]}, {"question_id": "0907", "frontend_question_id": "0875", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/koko-eating-bananas", "url_en": "https://leetcode.com/problems/koko-eating-bananas", "relative_path_cn": "/solution/0800-0899/0875.Koko%20Eating%20Bananas/README.md", "relative_path_en": "/solution/0800-0899/0875.Koko%20Eating%20Bananas/README_EN.md", "title_cn": "\u7231\u5403\u9999\u8549\u7684\u73c2\u73c2", "title_en": "Koko Eating Bananas", "question_title_slug": "koko-eating-bananas", "content_en": "

    Koko loves to eat bananas. There are n piles of bananas, the ith pile has piles[i] bananas. The guards have gone and will come back in h hours.

    \n\n

    Koko can decide her bananas-per-hour eating speed of k. Each hour, she chooses some pile of bananas and eats k bananas from that pile. If the pile has less than k bananas, she eats all of them instead and will not eat any more bananas during this hour.

    \n\n

    Koko likes to eat slowly but still wants to finish eating all the bananas before the guards return.

    \n\n

    Return the minimum integer k such that she can eat all the bananas within h hours.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: piles = [3,6,7,11], h = 8\nOutput: 4\n
    \n\n

    Example 2:

    \n\n
    \nInput: piles = [30,11,23,4,20], h = 5\nOutput: 30\n
    \n\n

    Example 3:

    \n\n
    \nInput: piles = [30,11,23,4,20], h = 6\nOutput: 23\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= piles.length <= 104
    • \n\t
    • piles.length <= h <= 109
    • \n\t
    • 1 <= piles[i] <= 109
    • \n
    \n", "content_cn": "

    \u73c2\u73c2\u559c\u6b22\u5403\u9999\u8549\u3002\u8fd9\u91cc\u6709 N \u5806\u9999\u8549\uff0c\u7b2c i \u5806\u4e2d\u6709 piles[i] \u6839\u9999\u8549\u3002\u8b66\u536b\u5df2\u7ecf\u79bb\u5f00\u4e86\uff0c\u5c06\u5728 H \u5c0f\u65f6\u540e\u56de\u6765\u3002

    \n\n

    \u73c2\u73c2\u53ef\u4ee5\u51b3\u5b9a\u5979\u5403\u9999\u8549\u7684\u901f\u5ea6 K \uff08\u5355\u4f4d\uff1a\u6839/\u5c0f\u65f6\uff09\u3002\u6bcf\u4e2a\u5c0f\u65f6\uff0c\u5979\u5c06\u4f1a\u9009\u62e9\u4e00\u5806\u9999\u8549\uff0c\u4ece\u4e2d\u5403\u6389 K \u6839\u3002\u5982\u679c\u8fd9\u5806\u9999\u8549\u5c11\u4e8e K \u6839\uff0c\u5979\u5c06\u5403\u6389\u8fd9\u5806\u7684\u6240\u6709\u9999\u8549\uff0c\u7136\u540e\u8fd9\u4e00\u5c0f\u65f6\u5185\u4e0d\u4f1a\u518d\u5403\u66f4\u591a\u7684\u9999\u8549\u3002  

    \n\n

    \u73c2\u73c2\u559c\u6b22\u6162\u6162\u5403\uff0c\u4f46\u4ecd\u7136\u60f3\u5728\u8b66\u536b\u56de\u6765\u524d\u5403\u6389\u6240\u6709\u7684\u9999\u8549\u3002

    \n\n

    \u8fd4\u56de\u5979\u53ef\u4ee5\u5728 H \u5c0f\u65f6\u5185\u5403\u6389\u6240\u6709\u9999\u8549\u7684\u6700\u5c0f\u901f\u5ea6 K\uff08K \u4e3a\u6574\u6570\uff09\u3002

    \n\n

     

    \n\n
      \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165: piles = [3,6,7,11], H = 8\n\u8f93\u51fa: 4\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165: piles = [30,11,23,4,20], H = 5\n\u8f93\u51fa: 30\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165: piles = [30,11,23,4,20], H = 6\n\u8f93\u51fa: 23\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= piles.length <= 10^4
    • \n\t
    • piles.length <= H <= 10^9
    • \n\t
    • 1 <= piles[i] <= 10^9
    • \n
    \n", "tags_en": ["Binary Search"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minEatingSpeed(vector& piles, int h) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minEatingSpeed(int[] piles, int h) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minEatingSpeed(self, piles, h):\n \"\"\"\n :type piles: List[int]\n :type h: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minEatingSpeed(self, piles: List[int], h: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minEatingSpeed(int* piles, int pilesSize, int h){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinEatingSpeed(int[] piles, int h) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} piles\n * @param {number} h\n * @return {number}\n */\nvar minEatingSpeed = function(piles, h) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} piles\n# @param {Integer} h\n# @return {Integer}\ndef min_eating_speed(piles, h)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minEatingSpeed(_ piles: [Int], _ h: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minEatingSpeed(piles []int, h int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minEatingSpeed(piles: Array[Int], h: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minEatingSpeed(piles: IntArray, h: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_eating_speed(piles: Vec, h: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $piles\n * @param Integer $h\n * @return Integer\n */\n function minEatingSpeed($piles, $h) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minEatingSpeed(piles: number[], h: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-eating-speed piles h)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0875](https://leetcode-cn.com/problems/koko-eating-bananas)", "[\u7231\u5403\u9999\u8549\u7684\u73c2\u73c2](/solution/0800-0899/0875.Koko%20Eating%20Bananas/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0875](https://leetcode.com/problems/koko-eating-bananas)", "[Koko Eating Bananas](/solution/0800-0899/0875.Koko%20Eating%20Bananas/README_EN.md)", "`Binary Search`", "Medium", ""]}, {"question_id": "0906", "frontend_question_id": "0874", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/walking-robot-simulation", "url_en": "https://leetcode.com/problems/walking-robot-simulation", "relative_path_cn": "/solution/0800-0899/0874.Walking%20Robot%20Simulation/README.md", "relative_path_en": "/solution/0800-0899/0874.Walking%20Robot%20Simulation/README_EN.md", "title_cn": "\u6a21\u62df\u884c\u8d70\u673a\u5668\u4eba", "title_en": "Walking Robot Simulation", "question_title_slug": "walking-robot-simulation", "content_en": "

    A robot on an infinite XY-plane starts at point (0, 0) and faces north. The robot can receive one of three possible types of commands:

    \n\n
      \n\t
    • -2: turn left 90 degrees,
    • \n\t
    • -1: turn right 90 degrees, or
    • \n\t
    • 1 <= k <= 9: move forward k units.
    • \n
    \n\n

    Some of the grid squares are obstacles. The ith obstacle is at grid point obstacles[i] = (xi, yi).

    \n\n

    If the robot would try to move onto them, the robot stays on the previous grid square instead (but still continues following the rest of the route.)

    \n\n

    Return the maximum Euclidean distance that the robot will be from the origin squared (i.e. if the distance is 5, return 25).

    \n\n

    Note:

    \n\n
      \n\t
    • North means +Y direction.
    • \n\t
    • East means +X direction.
    • \n\t
    • South means -Y direction.
    • \n\t
    • West means -X direction.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: commands = [4,-1,3], obstacles = []\nOutput: 25\nExplanation: The robot starts at (0, 0):\n1. Move north 4 units to (0, 4).\n2. Turn right.\n3. Move east 3 units to (3, 4).\nThe furthest point away from the origin is (3, 4), which is 32 + 42 = 25 units away.\n
    \n\n

    Example 2:

    \n\n
    \nInput: commands = [4,-1,4,-2,4], obstacles = [[2,4]]\nOutput: 65\nExplanation: The robot starts at (0, 0):\n1. Move north 4 units to (0, 4).\n2. Turn right.\n3. Move east 1 unit and get blocked by the obstacle at (2, 4), robot is at (1, 4).\n4. Turn left.\n5. Move north 4 units to (1, 8).\nThe furthest point away from the origin is (1, 8), which is 12 + 82 = 65 units away.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= commands.length <= 104
    • \n\t
    • commands[i] is one of the values in the list [-2,-1,1,2,3,4,5,6,7,8,9].
    • \n\t
    • 0 <= obstacles.length <= 104
    • \n\t
    • -3 * 104 <= xi, yi <= 3 * 104
    • \n\t
    • The answer is guaranteed to be less than 231.
    • \n
    \n", "content_cn": "

    \u673a\u5668\u4eba\u5728\u4e00\u4e2a\u65e0\u9650\u5927\u5c0f\u7684 XY \u7f51\u683c\u5e73\u9762\u4e0a\u884c\u8d70\uff0c\u4ece\u70b9\u00a0(0, 0) \u5904\u5f00\u59cb\u51fa\u53d1\uff0c\u9762\u5411\u5317\u65b9\u3002\u8be5\u673a\u5668\u4eba\u53ef\u4ee5\u63a5\u6536\u4ee5\u4e0b\u4e09\u79cd\u7c7b\u578b\u7684\u547d\u4ee4 commands \uff1a

    \n\n
      \n\t
    • -2 \uff1a\u5411\u5de6\u8f6c\u00a090 \u5ea6
    • \n\t
    • -1 \uff1a\u5411\u53f3\u8f6c 90 \u5ea6
    • \n\t
    • 1 <= x <= 9 \uff1a\u5411\u524d\u79fb\u52a8\u00a0x\u00a0\u4e2a\u5355\u4f4d\u957f\u5ea6
    • \n
    \n\n

    \u5728\u7f51\u683c\u4e0a\u6709\u4e00\u4e9b\u683c\u5b50\u88ab\u89c6\u4e3a\u969c\u788d\u7269\u00a0obstacles \u3002\u7b2c i\u00a0\u4e2a\u969c\u788d\u7269\u4f4d\u4e8e\u7f51\u683c\u70b9 \u00a0obstacles[i] = (xi, yi) \u3002

    \n\n

    \u673a\u5668\u4eba\u65e0\u6cd5\u8d70\u5230\u969c\u788d\u7269\u4e0a\uff0c\u5b83\u5c06\u4f1a\u505c\u7559\u5728\u969c\u788d\u7269\u7684\u524d\u4e00\u4e2a\u7f51\u683c\u65b9\u5757\u4e0a\uff0c\u4f46\u4ecd\u7136\u53ef\u4ee5\u7ee7\u7eed\u5c1d\u8bd5\u8fdb\u884c\u8be5\u8def\u7ebf\u7684\u5176\u4f59\u90e8\u5206\u3002

    \n\n

    \u8fd4\u56de\u4ece\u539f\u70b9\u5230\u673a\u5668\u4eba\u6240\u6709\u7ecf\u8fc7\u7684\u8def\u5f84\u70b9\uff08\u5750\u6807\u4e3a\u6574\u6570\uff09\u7684\u6700\u5927\u6b27\u5f0f\u8ddd\u79bb\u7684\u5e73\u65b9\u3002\uff08\u5373\uff0c\u5982\u679c\u8ddd\u79bb\u4e3a 5 \uff0c\u5219\u8fd4\u56de 25 \uff09

    \n\n
    \n
    \n
    \n
    \n
    \u00a0
    \n
    \n\n
    \n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    • \u5317\u8868\u793a +Y \u65b9\u5411\u3002
    • \n\t
    • \u4e1c\u8868\u793a +X \u65b9\u5411\u3002
    • \n\t
    • \u5357\u8868\u793a -Y \u65b9\u5411\u3002
    • \n\t
    • \u897f\u8868\u793a -X \u65b9\u5411\u3002
    • \n
    \n
    \n
    \n
    \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1acommands = [4,-1,3], obstacles = []\n\u8f93\u51fa\uff1a25\n\u89e3\u91ca\uff1a\n\u673a\u5668\u4eba\u5f00\u59cb\u4f4d\u4e8e (0, 0)\uff1a\n1. \u5411\u5317\u79fb\u52a8 4 \u4e2a\u5355\u4f4d\uff0c\u5230\u8fbe (0, 4)\n2. \u53f3\u8f6c\n3. \u5411\u4e1c\u79fb\u52a8 3 \u4e2a\u5355\u4f4d\uff0c\u5230\u8fbe (3, 4)\n\u8ddd\u79bb\u539f\u70b9\u6700\u8fdc\u7684\u662f (3, 4) \uff0c\u8ddd\u79bb\u4e3a 32 + 42 = 25
    \n\n

    \u793a\u4f8b\u00a02\uff1a

    \n\n
    \n\u8f93\u5165\uff1acommands = [4,-1,4,-2,4], obstacles = [[2,4]]\n\u8f93\u51fa\uff1a65\n\u89e3\u91ca\uff1a\u673a\u5668\u4eba\u5f00\u59cb\u4f4d\u4e8e (0, 0)\uff1a\n1. \u5411\u5317\u79fb\u52a8 4 \u4e2a\u5355\u4f4d\uff0c\u5230\u8fbe (0, 4)\n2. \u53f3\u8f6c\n3. \u5411\u4e1c\u79fb\u52a8 1 \u4e2a\u5355\u4f4d\uff0c\u7136\u540e\u88ab\u4f4d\u4e8e (2, 4) \u7684\u969c\u788d\u7269\u963b\u6321\uff0c\u673a\u5668\u4eba\u505c\u5728 (1, 4)\n4. \u5de6\u8f6c\n5. \u5411\u5317\u8d70 4 \u4e2a\u5355\u4f4d\uff0c\u5230\u8fbe (1, 8)\n\u8ddd\u79bb\u539f\u70b9\u6700\u8fdc\u7684\u662f (1, 8) \uff0c\u8ddd\u79bb\u4e3a 12 + 82 = 65
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= commands.length <= 104
    • \n\t
    • commands[i] is one of the values in the list [-2,-1,1,2,3,4,5,6,7,8,9].
    • \n\t
    • 0 <= obstacles.length <= 104
    • \n\t
    • -3 * 104 <= xi, yi <= 3 * 104
    • \n\t
    • \u7b54\u6848\u4fdd\u8bc1\u5c0f\u4e8e 231
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int robotSim(vector& commands, vector>& obstacles) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int robotSim(int[] commands, int[][] obstacles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def robotSim(self, commands, obstacles):\n \"\"\"\n :type commands: List[int]\n :type obstacles: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def robotSim(self, commands: List[int], obstacles: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint robotSim(int* commands, int commandsSize, int** obstacles, int obstaclesSize, int* obstaclesColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int RobotSim(int[] commands, int[][] obstacles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} commands\n * @param {number[][]} obstacles\n * @return {number}\n */\nvar robotSim = function(commands, obstacles) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} commands\n# @param {Integer[][]} obstacles\n# @return {Integer}\ndef robot_sim(commands, obstacles)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func robotSim(_ commands: [Int], _ obstacles: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func robotSim(commands []int, obstacles [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def robotSim(commands: Array[Int], obstacles: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun robotSim(commands: IntArray, obstacles: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn robot_sim(commands: Vec, obstacles: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $commands\n * @param Integer[][] $obstacles\n * @return Integer\n */\n function robotSim($commands, $obstacles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function robotSim(commands: number[], obstacles: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (robot-sim commands obstacles)\n (-> (listof exact-integer?) (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0874](https://leetcode-cn.com/problems/walking-robot-simulation)", "[\u6a21\u62df\u884c\u8d70\u673a\u5668\u4eba](/solution/0800-0899/0874.Walking%20Robot%20Simulation/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u7b80\u5355", ""], "md_table_row_en": ["[0874](https://leetcode.com/problems/walking-robot-simulation)", "[Walking Robot Simulation](/solution/0800-0899/0874.Walking%20Robot%20Simulation/README_EN.md)", "`Greedy`", "Easy", ""]}, {"question_id": "0905", "frontend_question_id": "0873", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/length-of-longest-fibonacci-subsequence", "url_en": "https://leetcode.com/problems/length-of-longest-fibonacci-subsequence", "relative_path_cn": "/solution/0800-0899/0873.Length%20of%20Longest%20Fibonacci%20Subsequence/README.md", "relative_path_en": "/solution/0800-0899/0873.Length%20of%20Longest%20Fibonacci%20Subsequence/README_EN.md", "title_cn": "\u6700\u957f\u7684\u6590\u6ce2\u90a3\u5951\u5b50\u5e8f\u5217\u7684\u957f\u5ea6", "title_en": "Length of Longest Fibonacci Subsequence", "question_title_slug": "length-of-longest-fibonacci-subsequence", "content_en": "

    A sequence x1, x2, ..., xn is Fibonacci-like if:

    \n\n
      \n\t
    • n >= 3
    • \n\t
    • xi + xi+1 == xi+2 for all i + 2 <= n
    • \n
    \n\n

    Given a strictly increasing array arr of positive integers forming a sequence, return the length of the longest Fibonacci-like subsequence of arr. If one does not exist, return 0.

    \n\n

    A subsequence is derived from another sequence arr by deleting any number of elements (including none) from arr, without changing the order of the remaining elements. For example, [3, 5, 8] is a subsequence of [3, 4, 5, 6, 7, 8].

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr = [1,2,3,4,5,6,7,8]\nOutput: 5\nExplanation: The longest subsequence that is fibonacci-like: [1,2,3,5,8].
    \n\n

    Example 2:

    \n\n
    \nInput: arr = [1,3,7,11,12,14,18]\nOutput: 3\nExplanation: The longest subsequence that is fibonacci-like: [1,11,12], [3,11,14] or [7,11,18].
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 3 <= arr.length <= 1000
    • \n\t
    • 1 <= arr[i] < arr[i + 1] <= 109
    • \n
    \n", "content_cn": "

    \u5982\u679c\u5e8f\u5217 X_1, X_2, ..., X_n \u6ee1\u8db3\u4e0b\u5217\u6761\u4ef6\uff0c\u5c31\u8bf4\u5b83\u662f \u6590\u6ce2\u90a3\u5951\u5f0f \u7684\uff1a

    \n\n
      \n\t
    • n >= 3
    • \n\t
    • \u5bf9\u4e8e\u6240\u6709 i + 2 <= n\uff0c\u90fd\u6709 X_i + X_{i+1} = X_{i+2}
    • \n
    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u4e25\u683c\u9012\u589e\u7684\u6b63\u6574\u6570\u6570\u7ec4\u5f62\u6210\u5e8f\u5217\uff0c\u627e\u5230 A \u4e2d\u6700\u957f\u7684\u6590\u6ce2\u90a3\u5951\u5f0f\u7684\u5b50\u5e8f\u5217\u7684\u957f\u5ea6\u3002\u5982\u679c\u4e00\u4e2a\u4e0d\u5b58\u5728\uff0c\u8fd4\u56de  0 \u3002

    \n\n

    \uff08\u56de\u60f3\u4e00\u4e0b\uff0c\u5b50\u5e8f\u5217\u662f\u4ece\u539f\u5e8f\u5217 A \u4e2d\u6d3e\u751f\u51fa\u6765\u7684\uff0c\u5b83\u4ece A \u4e2d\u5220\u6389\u4efb\u610f\u6570\u91cf\u7684\u5143\u7d20\uff08\u4e5f\u53ef\u4ee5\u4e0d\u5220\uff09\uff0c\u800c\u4e0d\u6539\u53d8\u5176\u4f59\u5143\u7d20\u7684\u987a\u5e8f\u3002\u4f8b\u5982\uff0c [3, 5, 8] \u662f [3, 4, 5, 6, 7, 8] \u7684\u4e00\u4e2a\u5b50\u5e8f\u5217\uff09

    \n\n

     

    \n\n
      \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165: [1,2,3,4,5,6,7,8]\n\u8f93\u51fa: 5\n\u89e3\u91ca:\n\u6700\u957f\u7684\u6590\u6ce2\u90a3\u5951\u5f0f\u5b50\u5e8f\u5217\u4e3a\uff1a[1,2,3,5,8] \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165: [1,3,7,11,12,14,18]\n\u8f93\u51fa: 3\n\u89e3\u91ca:\n\u6700\u957f\u7684\u6590\u6ce2\u90a3\u5951\u5f0f\u5b50\u5e8f\u5217\u6709\uff1a\n[1,11,12]\uff0c[3,11,14] \u4ee5\u53ca [7,11,18] \u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 3 <= A.length <= 1000
    • \n\t
    • 1 <= A[0] < A[1] < ... < A[A.length - 1] <= 10^9
    • \n\t
    • \uff08\u5bf9\u4e8e\u4ee5 Java\uff0cC\uff0cC++\uff0c\u4ee5\u53ca C# \u7684\u63d0\u4ea4\uff0c\u65f6\u95f4\u9650\u5236\u88ab\u51cf\u5c11\u4e86 50%\uff09
    • \n
    \n", "tags_en": ["Array", "Dynamic Programming"], "tags_cn": ["\u6570\u7ec4", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int lenLongestFibSubseq(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int lenLongestFibSubseq(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def lenLongestFibSubseq(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def lenLongestFibSubseq(self, arr: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint lenLongestFibSubseq(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LenLongestFibSubseq(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar lenLongestFibSubseq = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef len_longest_fib_subseq(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func lenLongestFibSubseq(_ arr: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func lenLongestFibSubseq(arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def lenLongestFibSubseq(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun lenLongestFibSubseq(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn len_longest_fib_subseq(arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function lenLongestFibSubseq($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function lenLongestFibSubseq(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (len-longest-fib-subseq arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0873](https://leetcode-cn.com/problems/length-of-longest-fibonacci-subsequence)", "[\u6700\u957f\u7684\u6590\u6ce2\u90a3\u5951\u5b50\u5e8f\u5217\u7684\u957f\u5ea6](/solution/0800-0899/0873.Length%20of%20Longest%20Fibonacci%20Subsequence/README.md)", "`\u6570\u7ec4`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0873](https://leetcode.com/problems/length-of-longest-fibonacci-subsequence)", "[Length of Longest Fibonacci Subsequence](/solution/0800-0899/0873.Length%20of%20Longest%20Fibonacci%20Subsequence/README_EN.md)", "`Array`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0904", "frontend_question_id": "0872", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/leaf-similar-trees", "url_en": "https://leetcode.com/problems/leaf-similar-trees", "relative_path_cn": "/solution/0800-0899/0872.Leaf-Similar%20Trees/README.md", "relative_path_en": "/solution/0800-0899/0872.Leaf-Similar%20Trees/README_EN.md", "title_cn": "\u53f6\u5b50\u76f8\u4f3c\u7684\u6811", "title_en": "Leaf-Similar Trees", "question_title_slug": "leaf-similar-trees", "content_en": "

    Consider all the leaves of a binary tree, from left to right order, the values of those leaves form a leaf value sequence.

    \n\n

    \"\"

    \n\n

    For example, in the given tree above, the leaf value sequence is (6, 7, 4, 9, 8).

    \n\n

    Two binary trees are considered leaf-similar if their leaf value sequence is the same.

    \n\n

    Return true if and only if the two given trees with head nodes root1 and root2 are leaf-similar.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root1 = [3,5,1,6,2,9,8,null,null,7,4], root2 = [3,5,1,6,7,4,2,null,null,null,null,null,null,9,8]\nOutput: true\n
    \n\n

    Example 2:

    \n\n
    \nInput: root1 = [1], root2 = [1]\nOutput: true\n
    \n\n

    Example 3:

    \n\n
    \nInput: root1 = [1], root2 = [2]\nOutput: false\n
    \n\n

    Example 4:

    \n\n
    \nInput: root1 = [1,2], root2 = [2,2]\nOutput: true\n
    \n\n

    Example 5:

    \n\"\"\n
    \nInput: root1 = [1,2,3], root2 = [1,3,2]\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in each tree will be in the range [1, 200].
    • \n\t
    • Both of the given trees will have values in the range [0, 200].
    • \n
    \n", "content_cn": "

    \u8bf7\u8003\u8651\u4e00\u68f5\u4e8c\u53c9\u6811\u4e0a\u6240\u6709\u7684\u53f6\u5b50\uff0c\u8fd9\u4e9b\u53f6\u5b50\u7684\u503c\u6309\u4ece\u5de6\u5230\u53f3\u7684\u987a\u5e8f\u6392\u5217\u5f62\u6210\u4e00\u4e2a\u00a0\u53f6\u503c\u5e8f\u5217 \u3002

    \n\n

    \"\"

    \n\n

    \u4e3e\u4e2a\u4f8b\u5b50\uff0c\u5982\u4e0a\u56fe\u6240\u793a\uff0c\u7ed9\u5b9a\u4e00\u68f5\u53f6\u503c\u5e8f\u5217\u4e3a\u00a0(6, 7, 4, 9, 8)\u00a0\u7684\u6811\u3002

    \n\n

    \u5982\u679c\u6709\u4e24\u68f5\u4e8c\u53c9\u6811\u7684\u53f6\u503c\u5e8f\u5217\u662f\u76f8\u540c\uff0c\u90a3\u4e48\u6211\u4eec\u5c31\u8ba4\u4e3a\u5b83\u4eec\u662f\u00a0\u53f6\u76f8\u4f3c\u00a0\u7684\u3002

    \n\n

    \u5982\u679c\u7ed9\u5b9a\u7684\u4e24\u4e2a\u6839\u7ed3\u70b9\u5206\u522b\u4e3a\u00a0root1 \u548c\u00a0root2\u00a0\u7684\u6811\u662f\u53f6\u76f8\u4f3c\u7684\uff0c\u5219\u8fd4\u56de\u00a0true\uff1b\u5426\u5219\u8fd4\u56de false \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aroot1 = [3,5,1,6,2,9,8,null,null,7,4], root2 = [3,5,1,6,7,4,2,null,null,null,null,null,null,9,8]\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot1 = [1], root2 = [1]\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot1 = [1], root2 = [2]\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot1 = [1,2], root2 = [2,2]\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aroot1 = [1,2,3], root2 = [1,3,2]\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u7ed9\u5b9a\u7684\u4e24\u68f5\u6811\u53ef\u80fd\u4f1a\u6709\u00a01\u00a0\u5230 200\u00a0\u4e2a\u7ed3\u70b9\u3002
    • \n\t
    • \u7ed9\u5b9a\u7684\u4e24\u68f5\u6811\u4e0a\u7684\u503c\u4ecb\u4e8e 0 \u5230 200 \u4e4b\u95f4\u3002
    • \n
    \n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n bool leafSimilar(TreeNode* root1, TreeNode* root2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public boolean leafSimilar(TreeNode root1, TreeNode root2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def leafSimilar(self, root1, root2):\n \"\"\"\n :type root1: TreeNode\n :type root2: TreeNode\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def leafSimilar(self, root1: TreeNode, root2: TreeNode) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nbool leafSimilar(struct TreeNode* root1, struct TreeNode* root2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public bool LeafSimilar(TreeNode root1, TreeNode root2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root1\n * @param {TreeNode} root2\n * @return {boolean}\n */\nvar leafSimilar = function(root1, root2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root1\n# @param {TreeNode} root2\n# @return {Boolean}\ndef leaf_similar(root1, root2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func leafSimilar(_ root1: TreeNode?, _ root2: TreeNode?) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc leafSimilar(root1 *TreeNode, root2 *TreeNode) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def leafSimilar(root1: TreeNode, root2: TreeNode): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun leafSimilar(root1: TreeNode?, root2: TreeNode?): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn leaf_similar(root1: Option>>, root2: Option>>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root1\n * @param TreeNode $root2\n * @return Boolean\n */\n function leafSimilar($root1, $root2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction leafSimilar(root1: TreeNode | null, root2: TreeNode | null): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (leaf-similar root1 root2)\n (-> (or/c tree-node? #f) (or/c tree-node? #f) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0872](https://leetcode-cn.com/problems/leaf-similar-trees)", "[\u53f6\u5b50\u76f8\u4f3c\u7684\u6811](/solution/0800-0899/0872.Leaf-Similar%20Trees/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u7b80\u5355", ""], "md_table_row_en": ["[0872](https://leetcode.com/problems/leaf-similar-trees)", "[Leaf-Similar Trees](/solution/0800-0899/0872.Leaf-Similar%20Trees/README_EN.md)", "`Tree`,`Depth-first Search`", "Easy", ""]}, {"question_id": "0903", "frontend_question_id": "0470", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/implement-rand10-using-rand7", "url_en": "https://leetcode.com/problems/implement-rand10-using-rand7", "relative_path_cn": "/solution/0400-0499/0470.Implement%20Rand10%28%29%20Using%20Rand7%28%29/README.md", "relative_path_en": "/solution/0400-0499/0470.Implement%20Rand10%28%29%20Using%20Rand7%28%29/README_EN.md", "title_cn": "\u7528 Rand7() \u5b9e\u73b0 Rand10()", "title_en": "Implement Rand10() Using Rand7()", "question_title_slug": "implement-rand10-using-rand7", "content_en": "

    Given the API rand7() that generates a uniform random integer in the range [1, 7], write a function rand10() that generates a uniform random integer in the range [1, 10]. You can only call the API rand7(), and you shouldn't call any other API. Please do not use a language's built-in random API.

    \n\n

    Each test case will have one internal argument n, the number of times that your implemented function rand10() will be called while testing. Note that this is not an argument passed to rand10().

    \n\n

    Follow up:

    \n\n
      \n\t
    • What is the expected value for the number of calls to rand7() function?
    • \n\t
    • Could you minimize the number of calls to rand7()?
    • \n
    \n\n

     

    \n

    Example 1:

    \n
    Input: n = 1\nOutput: [2]\n

    Example 2:

    \n
    Input: n = 2\nOutput: [2,8]\n

    Example 3:

    \n
    Input: n = 3\nOutput: [3,8,10]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 105
    • \n
    \n", "content_cn": "

    \u5df2\u6709\u65b9\u6cd5 rand7 \u53ef\u751f\u6210 1 \u5230 7 \u8303\u56f4\u5185\u7684\u5747\u5300\u968f\u673a\u6574\u6570\uff0c\u8bd5\u5199\u4e00\u4e2a\u65b9\u6cd5 rand10 \u751f\u6210 1 \u5230 10 \u8303\u56f4\u5185\u7684\u5747\u5300\u968f\u673a\u6574\u6570\u3002

    \n\n

    \u4e0d\u8981\u4f7f\u7528\u7cfb\u7edf\u7684 Math.random() \u65b9\u6cd5\u3002

    \n\n
      \n
    \n\n

     

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: 1\n\u8f93\u51fa: [7]\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: 2\n\u8f93\u51fa: [8,4]\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \n\u8f93\u5165: 3\n\u8f93\u51fa: [8,1,10]\n
    \n\n

     

    \n\n

    \u63d0\u793a:

    \n\n
      \n\t
    1. rand7 \u5df2\u5b9a\u4e49\u3002
    2. \n\t
    3. \u4f20\u5165\u53c2\u6570: n \u8868\u793a rand10 \u7684\u8c03\u7528\u6b21\u6570\u3002
    4. \n
    \n\n

     

    \n\n

    \u8fdb\u9636:

    \n\n
      \n\t
    1. rand7()\u8c03\u7528\u6b21\u6570\u7684 \u671f\u671b\u503c \u662f\u591a\u5c11 ?
    2. \n\t
    3. \u4f60\u80fd\u5426\u5c3d\u91cf\u5c11\u8c03\u7528 rand7() ?
    4. \n
    \n", "tags_en": ["Random", "Rejection Sampling"], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "// The rand7() API is already defined for you.\n// int rand7();\n// @return a random integer in the range 1 to 7\n\nclass Solution {\npublic:\n int rand10() {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * The rand7() API is already defined in the parent class SolBase.\n * public int rand7();\n * @return a random integer in the range 1 to 7\n */\nclass Solution extends SolBase {\n public int rand10() {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# The rand7() API is already defined for you.\n# def rand7():\n# @return a random integer in the range 1 to 7\n\nclass Solution(object):\n def rand10(self):\n \"\"\"\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# The rand7() API is already defined for you.\n# def rand7():\n# @return a random integer in the range 1 to 7\n\nclass Solution:\n def rand10(self):\n \"\"\"\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "// The rand7() API is already defined for you.\n// int rand7();\n// @return a random integer in the range 1 to 7\n\nint rand10() {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * The Rand7() API is already defined in the parent class SolBase.\n * public int Rand7();\n * @return a random integer in the range 1 to 7\n */\npublic class Solution : SolBase {\n public int Rand10() {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * The rand7() API is already defined for you.\n * var rand7 = function() {}\n * @return {number} a random integer in the range 1 to 7\n */\nvar rand10 = function() {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# The rand7() API is already defined for you.\n# def rand7()\n# @return {Integer} a random integer in the range 1 to 7\n\ndef rand10()\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * The rand7() API is already defined in the parent class SolBase.\n * func rand7() -> Int = {}\n * @return a random integer in the range 1 to 7\n */\nclass Solution : SolBase {\n func rand10() -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func rand10() int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * The rand7() API is already defined in the parent class SolBase.\n * def rand7(): Int = {}\n * @return a random integer in the range 1 to 7\n */\nobject Solution extends SolBase {\n def rand10(): Int = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * The rand7() API is already defined in the parent class SolBase.\n * fun rand7(): Int {}\n * @return a random integer in the range 1 to 7\n */\nclass Solution : SolBase() {\n fun rand10(): Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "/** \n * The rand7() API is already defined for you.\n * @return a random integer in the range 1 to 7\n * fn rand7() -> i32;\n */\n\nimpl Solution {\n pub fn rand10() -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/*\n * The rand7() API is already defined for you.\n * @return a random integer in the range 1 to 7\n * function rand7();\n*/\n\nclass Solution {\n /**\n * @param \n * @return Integer\n */\n function rand10() {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * The rand7() API is already defined for you.\n * function rand7(): number {}\n * @return a random integer in the range 1 to 7\n */\n\nfunction rand10(): number {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0470](https://leetcode-cn.com/problems/implement-rand10-using-rand7)", "[\u7528 Rand7() \u5b9e\u73b0 Rand10()](/solution/0400-0499/0470.Implement%20Rand10%28%29%20Using%20Rand7%28%29/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0470](https://leetcode.com/problems/implement-rand10-using-rand7)", "[Implement Rand10() Using Rand7()](/solution/0400-0499/0470.Implement%20Rand10%28%29%20Using%20Rand7%28%29/README_EN.md)", "`Random`,`Rejection Sampling`", "Medium", ""]}, {"question_id": "0902", "frontend_question_id": "0871", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-number-of-refueling-stops", "url_en": "https://leetcode.com/problems/minimum-number-of-refueling-stops", "relative_path_cn": "/solution/0800-0899/0871.Minimum%20Number%20of%20Refueling%20Stops/README.md", "relative_path_en": "/solution/0800-0899/0871.Minimum%20Number%20of%20Refueling%20Stops/README_EN.md", "title_cn": "\u6700\u4f4e\u52a0\u6cb9\u6b21\u6570", "title_en": "Minimum Number of Refueling Stops", "question_title_slug": "minimum-number-of-refueling-stops", "content_en": "

    A car travels from a starting position to a destination which is target miles east of the starting position.

    \r\n\r\n

    Along the way, there are gas stations.  Each station[i] represents a gas station that is station[i][0] miles east of the starting position, and has station[i][1] liters of gas.

    \r\n\r\n

    The car starts with an infinite tank of gas, which initially has startFuel liters of fuel in it.  It uses 1 liter of gas per 1 mile that it drives.

    \r\n\r\n

    When the car reaches a gas station, it may stop and refuel, transferring all the gas from the station into the car.

    \r\n\r\n

    What is the least number of refueling stops the car must make in order to reach its destination?  If it cannot reach the destination, return -1.

    \r\n\r\n

    Note that if the car reaches a gas station with 0 fuel left, the car can still refuel there.  If the car reaches the destination with 0 fuel left, it is still considered to have arrived.

    \r\n\r\n

     

    \r\n\r\n
    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: target = 1, startFuel = 1, stations = []\r\nOutput: 0\r\nExplanation: We can reach the target without refueling.\r\n
    \r\n\r\n
    \r\n

    Example 2:

    \r\n\r\n
    \r\nInput: target = 100, startFuel = 1, stations = [[10,100]]\r\nOutput: -1\r\nExplanation: We can't reach the target (or even the first gas station).\r\n
    \r\n\r\n
    \r\n

    Example 3:

    \r\n\r\n
    \r\nInput: target = 100, startFuel = 10, stations = [[10,60],[20,30],[30,30],[60,40]]\r\nOutput: 2\r\nExplanation: \r\nWe start with 10 liters of fuel.\r\nWe drive to position 10, expending 10 liters of fuel.  We refuel from 0 liters to 60 liters of gas.\r\nThen, we drive from position 10 to position 60 (expending 50 liters of fuel),\r\nand refuel from 10 liters to 50 liters of gas.  We then drive to and reach the target.\r\nWe made 2 refueling stops along the way, so we return 2.\r\n
    \r\n\r\n

     

    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    1. 1 <= target, startFuel, stations[i][1] <= 10^9
    2. \r\n\t
    3. 0 <= stations.length <= 500
    4. \r\n\t
    5. 0 < stations[0][0] < stations[1][0] < ... < stations[stations.length-1][0] < target
    6. \r\n
    \r\n
    \r\n
    \r\n
    \r\n", "content_cn": "

    \u6c7d\u8f66\u4ece\u8d77\u70b9\u51fa\u53d1\u9a76\u5411\u76ee\u7684\u5730\uff0c\u8be5\u76ee\u7684\u5730\u4f4d\u4e8e\u51fa\u53d1\u4f4d\u7f6e\u4e1c\u9762 target \u82f1\u91cc\u5904\u3002

    \n\n

    \u6cbf\u9014\u6709\u52a0\u6cb9\u7ad9\uff0c\u6bcf\u4e2a station[i] \u4ee3\u8868\u4e00\u4e2a\u52a0\u6cb9\u7ad9\uff0c\u5b83\u4f4d\u4e8e\u51fa\u53d1\u4f4d\u7f6e\u4e1c\u9762 station[i][0] \u82f1\u91cc\u5904\uff0c\u5e76\u4e14\u6709 station[i][1] \u5347\u6c7d\u6cb9\u3002

    \n\n

    \u5047\u8bbe\u6c7d\u8f66\u6cb9\u7bb1\u7684\u5bb9\u91cf\u662f\u65e0\u9650\u7684\uff0c\u5176\u4e2d\u6700\u521d\u6709 startFuel \u5347\u71c3\u6599\u3002\u5b83\u6bcf\u884c\u9a76 1 \u82f1\u91cc\u5c31\u4f1a\u7528\u6389 1 \u5347\u6c7d\u6cb9\u3002

    \n\n

    \u5f53\u6c7d\u8f66\u5230\u8fbe\u52a0\u6cb9\u7ad9\u65f6\uff0c\u5b83\u53ef\u80fd\u505c\u4e0b\u6765\u52a0\u6cb9\uff0c\u5c06\u6240\u6709\u6c7d\u6cb9\u4ece\u52a0\u6cb9\u7ad9\u8f6c\u79fb\u5230\u6c7d\u8f66\u4e2d\u3002

    \n\n

    \u4e3a\u4e86\u5230\u8fbe\u76ee\u7684\u5730\uff0c\u6c7d\u8f66\u6240\u5fc5\u8981\u7684\u6700\u4f4e\u52a0\u6cb9\u6b21\u6570\u662f\u591a\u5c11\uff1f\u5982\u679c\u65e0\u6cd5\u5230\u8fbe\u76ee\u7684\u5730\uff0c\u5219\u8fd4\u56de -1 \u3002

    \n\n

    \u6ce8\u610f\uff1a\u5982\u679c\u6c7d\u8f66\u5230\u8fbe\u52a0\u6cb9\u7ad9\u65f6\u5269\u4f59\u71c3\u6599\u4e3a 0\uff0c\u5b83\u4ecd\u7136\u53ef\u4ee5\u5728\u90a3\u91cc\u52a0\u6cb9\u3002\u5982\u679c\u6c7d\u8f66\u5230\u8fbe\u76ee\u7684\u5730\u65f6\u5269\u4f59\u71c3\u6599\u4e3a 0\uff0c\u4ecd\u7136\u8ba4\u4e3a\u5b83\u5df2\u7ecf\u5230\u8fbe\u76ee\u7684\u5730\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1atarget = 1, startFuel = 1, stations = []\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6211\u4eec\u53ef\u4ee5\u5728\u4e0d\u52a0\u6cb9\u7684\u60c5\u51b5\u4e0b\u5230\u8fbe\u76ee\u7684\u5730\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1atarget = 100, startFuel = 1, stations = [[10,100]]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u6211\u4eec\u65e0\u6cd5\u62b5\u8fbe\u76ee\u7684\u5730\uff0c\u751a\u81f3\u65e0\u6cd5\u5230\u8fbe\u7b2c\u4e00\u4e2a\u52a0\u6cb9\u7ad9\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1atarget = 100, startFuel = 10, stations = [[10,60],[20,30],[30,30],[60,40]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n\u6211\u4eec\u51fa\u53d1\u65f6\u6709 10 \u5347\u71c3\u6599\u3002\n\u6211\u4eec\u5f00\u8f66\u6765\u5230\u8ddd\u8d77\u70b9 10 \u82f1\u91cc\u5904\u7684\u52a0\u6cb9\u7ad9\uff0c\u6d88\u8017 10 \u5347\u71c3\u6599\u3002\u5c06\u6c7d\u6cb9\u4ece 0 \u5347\u52a0\u5230 60 \u5347\u3002\n\u7136\u540e\uff0c\u6211\u4eec\u4ece 10 \u82f1\u91cc\u5904\u7684\u52a0\u6cb9\u7ad9\u5f00\u5230 60 \u82f1\u91cc\u5904\u7684\u52a0\u6cb9\u7ad9\uff08\u6d88\u8017 50 \u5347\u71c3\u6599\uff09\uff0c\n\u5e76\u5c06\u6c7d\u6cb9\u4ece 10 \u5347\u52a0\u5230 50 \u5347\u3002\u7136\u540e\u6211\u4eec\u5f00\u8f66\u62b5\u8fbe\u76ee\u7684\u5730\u3002\n\u6211\u4eec\u6cbf\u9014\u57281\u4e24\u4e2a\u52a0\u6cb9\u7ad9\u505c\u9760\uff0c\u6240\u4ee5\u8fd4\u56de 2 \u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= target, startFuel, stations[i][1] <= 10^9
    2. \n\t
    3. 0 <= stations.length <= 500
    4. \n\t
    5. 0 < stations[0][0] < stations[1][0] < ... < stations[stations.length-1][0] < target
    6. \n
    \n", "tags_en": ["Heap", "Dynamic Programming"], "tags_cn": ["\u5806", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minRefuelStops(int target, int startFuel, vector>& stations) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minRefuelStops(int target, int startFuel, int[][] stations) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minRefuelStops(self, target, startFuel, stations):\n \"\"\"\n :type target: int\n :type startFuel: int\n :type stations: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minRefuelStops(self, target: int, startFuel: int, stations: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minRefuelStops(int target, int startFuel, int** stations, int stationsSize, int* stationsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinRefuelStops(int target, int startFuel, int[][] stations) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} target\n * @param {number} startFuel\n * @param {number[][]} stations\n * @return {number}\n */\nvar minRefuelStops = function(target, startFuel, stations) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} target\n# @param {Integer} start_fuel\n# @param {Integer[][]} stations\n# @return {Integer}\ndef min_refuel_stops(target, start_fuel, stations)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minRefuelStops(_ target: Int, _ startFuel: Int, _ stations: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minRefuelStops(target int, startFuel int, stations [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minRefuelStops(target: Int, startFuel: Int, stations: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minRefuelStops(target: Int, startFuel: Int, stations: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_refuel_stops(target: i32, start_fuel: i32, stations: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $target\n * @param Integer $startFuel\n * @param Integer[][] $stations\n * @return Integer\n */\n function minRefuelStops($target, $startFuel, $stations) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minRefuelStops(target: number, startFuel: number, stations: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-refuel-stops target startFuel stations)\n (-> exact-integer? exact-integer? (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0871](https://leetcode-cn.com/problems/minimum-number-of-refueling-stops)", "[\u6700\u4f4e\u52a0\u6cb9\u6b21\u6570](/solution/0800-0899/0871.Minimum%20Number%20of%20Refueling%20Stops/README.md)", "`\u5806`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0871](https://leetcode.com/problems/minimum-number-of-refueling-stops)", "[Minimum Number of Refueling Stops](/solution/0800-0899/0871.Minimum%20Number%20of%20Refueling%20Stops/README_EN.md)", "`Heap`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0901", "frontend_question_id": "0870", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/advantage-shuffle", "url_en": "https://leetcode.com/problems/advantage-shuffle", "relative_path_cn": "/solution/0800-0899/0870.Advantage%20Shuffle/README.md", "relative_path_en": "/solution/0800-0899/0870.Advantage%20Shuffle/README_EN.md", "title_cn": "\u4f18\u52bf\u6d17\u724c", "title_en": "Advantage Shuffle", "question_title_slug": "advantage-shuffle", "content_en": "

    Given two arrays nums1 and nums2 of equal size, the advantage of nums1 with respect to nums2 is the number of indices i for which nums1[i] > nums2[i].

    \n\n

    Return any permutation of nums1 that maximizes its advantage with respect to nums2.

    \n\n

     

    \n\n
    \n

    Example 1:

    \n\n
    \nInput: nums1 = [2,7,11,15], nums2 = [1,10,4,11]\nOutput: [2,11,7,15]\n
    \n\n
    \n

    Example 2:

    \n\n
    \nInput: nums1 = [12,24,8,32], nums2 = [13,25,32,11]\nOutput: [24,32,8,12]\n
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    1. 1 <= nums1.length = nums2.length <= 10000
    2. \n\t
    3. 0 <= nums1[i] <= 109
    4. \n\t
    5. 0 <= nums2[i] <= 109
    6. \n
    \n
    \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u5927\u5c0f\u76f8\u7b49\u7684\u6570\u7ec4 A \u548c B\uff0cA \u76f8\u5bf9\u4e8e B \u7684\u4f18\u52bf\u53ef\u4ee5\u7528\u6ee1\u8db3 A[i] > B[i] \u7684\u7d22\u5f15 i \u7684\u6570\u76ee\u6765\u63cf\u8ff0\u3002

    \n\n

    \u8fd4\u56de A \u7684\u4efb\u610f\u6392\u5217\uff0c\u4f7f\u5176\u76f8\u5bf9\u4e8e B \u7684\u4f18\u52bf\u6700\u5927\u5316\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aA = [2,7,11,15], B = [1,10,4,11]\n\u8f93\u51fa\uff1a[2,11,7,15]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aA = [12,24,8,32], B = [13,25,32,11]\n\u8f93\u51fa\uff1a[24,32,8,12]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= A.length = B.length <= 10000
    2. \n\t
    3. 0 <= A[i] <= 10^9
    4. \n\t
    5. 0 <= B[i] <= 10^9
    6. \n
    \n", "tags_en": ["Greedy", "Array"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector advantageCount(vector& nums1, vector& nums2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] advantageCount(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def advantageCount(self, nums1, nums2):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def advantageCount(self, nums1: List[int], nums2: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* advantageCount(int* nums1, int nums1Size, int* nums2, int nums2Size, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] AdvantageCount(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums1\n * @param {number[]} nums2\n * @return {number[]}\n */\nvar advantageCount = function(nums1, nums2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums1\n# @param {Integer[]} nums2\n# @return {Integer[]}\ndef advantage_count(nums1, nums2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func advantageCount(_ nums1: [Int], _ nums2: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func advantageCount(nums1 []int, nums2 []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def advantageCount(nums1: Array[Int], nums2: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun advantageCount(nums1: IntArray, nums2: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn advantage_count(nums1: Vec, nums2: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums1\n * @param Integer[] $nums2\n * @return Integer[]\n */\n function advantageCount($nums1, $nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function advantageCount(nums1: number[], nums2: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (advantage-count nums1 nums2)\n (-> (listof exact-integer?) (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0870](https://leetcode-cn.com/problems/advantage-shuffle)", "[\u4f18\u52bf\u6d17\u724c](/solution/0800-0899/0870.Advantage%20Shuffle/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0870](https://leetcode.com/problems/advantage-shuffle)", "[Advantage Shuffle](/solution/0800-0899/0870.Advantage%20Shuffle/README_EN.md)", "`Greedy`,`Array`", "Medium", ""]}, {"question_id": "0900", "frontend_question_id": "0869", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reordered-power-of-2", "url_en": "https://leetcode.com/problems/reordered-power-of-2", "relative_path_cn": "/solution/0800-0899/0869.Reordered%20Power%20of%202/README.md", "relative_path_en": "/solution/0800-0899/0869.Reordered%20Power%20of%202/README_EN.md", "title_cn": "\u91cd\u65b0\u6392\u5e8f\u5f97\u5230 2 \u7684\u5e42", "title_en": "Reordered Power of 2", "question_title_slug": "reordered-power-of-2", "content_en": "

    You are given an integer n. We reorder the digits in any order (including the original order) such that the leading digit is not zero.

    \n\n

    Return true if and only if we can do this so that the resulting number is a power of two.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 1\nOutput: true\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 10\nOutput: false\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 16\nOutput: true\n
    \n\n

    Example 4:

    \n\n
    \nInput: n = 24\nOutput: false\n
    \n\n

    Example 5:

    \n\n
    \nInput: n = 46\nOutput: true\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u6b63\u6574\u6570 N \uff0c\u6211\u4eec\u6309\u4efb\u4f55\u987a\u5e8f\uff08\u5305\u62ec\u539f\u59cb\u987a\u5e8f\uff09\u5c06\u6570\u5b57\u91cd\u65b0\u6392\u5e8f\uff0c\u6ce8\u610f\u5176\u524d\u5bfc\u6570\u5b57\u4e0d\u80fd\u4e3a\u96f6\u3002

    \n\n

    \u5982\u679c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4e0a\u8ff0\u65b9\u5f0f\u5f97\u5230 2 \u7684\u5e42\uff0c\u8fd4\u56de true\uff1b\u5426\u5219\uff0c\u8fd4\u56de false\u3002

    \n\n

     

    \n\n
      \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a1\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a10\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1a16\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1a24\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1a46\n\u8f93\u51fa\uff1atrue\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= N <= 10^9
    2. \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool reorderedPowerOf2(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean reorderedPowerOf2(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def reorderedPowerOf2(self, n):\n \"\"\"\n :type n: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def reorderedPowerOf2(self, n: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool reorderedPowerOf2(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool ReorderedPowerOf2(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {boolean}\n */\nvar reorderedPowerOf2 = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Boolean}\ndef reordered_power_of2(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func reorderedPowerOf2(_ n: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func reorderedPowerOf2(n int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def reorderedPowerOf2(n: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun reorderedPowerOf2(n: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn reordered_power_of2(n: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Boolean\n */\n function reorderedPowerOf2($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function reorderedPowerOf2(n: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (reordered-power-of2 n)\n (-> exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0869](https://leetcode-cn.com/problems/reordered-power-of-2)", "[\u91cd\u65b0\u6392\u5e8f\u5f97\u5230 2 \u7684\u5e42](/solution/0800-0899/0869.Reordered%20Power%20of%202/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0869](https://leetcode.com/problems/reordered-power-of-2)", "[Reordered Power of 2](/solution/0800-0899/0869.Reordered%20Power%20of%202/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "0899", "frontend_question_id": "0868", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/binary-gap", "url_en": "https://leetcode.com/problems/binary-gap", "relative_path_cn": "/solution/0800-0899/0868.Binary%20Gap/README.md", "relative_path_en": "/solution/0800-0899/0868.Binary%20Gap/README_EN.md", "title_cn": "\u4e8c\u8fdb\u5236\u95f4\u8ddd", "title_en": "Binary Gap", "question_title_slug": "binary-gap", "content_en": "

    Given a positive integer n, find and return the longest distance between any two adjacent 1's in the binary representation of n. If there are no two adjacent 1's, return 0.

    \n\n

    Two 1's are adjacent if there are only 0's separating them (possibly no 0's). The distance between two 1's is the absolute difference between their bit positions. For example, the two 1's in "1001" have a distance of 3.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 22\nOutput: 2\nExplanation: 22 in binary is "10110".\nThe first adjacent pair of 1's is "10110" with a distance of 2.\nThe second adjacent pair of 1's is "10110" with a distance of 1.\nThe answer is the largest of these two distances, which is 2.\nNote that "10110" is not a valid pair since there is a 1 separating the two 1's underlined.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 5\nOutput: 2\nExplanation: 5 in binary is "101".\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 6\nOutput: 1\nExplanation: 6 in binary is "110".\n
    \n\n

    Example 4:

    \n\n
    \nInput: n = 8\nOutput: 0\nExplanation: 8 in binary is "1000".\nThere aren't any adjacent pairs of 1's in the binary representation of 8, so we return 0.\n
    \n\n

    Example 5:

    \n\n
    \nInput: n = 1\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6b63\u6574\u6570 n\uff0c\u627e\u5230\u5e76\u8fd4\u56de n \u7684\u4e8c\u8fdb\u5236\u8868\u793a\u4e2d\u4e24\u4e2a \u76f8\u90bb 1 \u4e4b\u95f4\u7684 \u6700\u957f\u8ddd\u79bb \u3002\u5982\u679c\u4e0d\u5b58\u5728\u4e24\u4e2a\u76f8\u90bb\u7684 1\uff0c\u8fd4\u56de 0 \u3002

    \n\n

    \u5982\u679c\u53ea\u6709 0 \u5c06\u4e24\u4e2a 1 \u5206\u9694\u5f00\uff08\u53ef\u80fd\u4e0d\u5b58\u5728 0 \uff09\uff0c\u5219\u8ba4\u4e3a\u8fd9\u4e24\u4e2a 1 \u5f7c\u6b64 \u76f8\u90bb \u3002\u4e24\u4e2a 1 \u4e4b\u95f4\u7684\u8ddd\u79bb\u662f\u5b83\u4eec\u7684\u4e8c\u8fdb\u5236\u8868\u793a\u4e2d\u4f4d\u7f6e\u7684\u7edd\u5bf9\u5dee\u3002\u4f8b\u5982\uff0c\"1001\" \u4e2d\u7684\u4e24\u4e2a 1 \u7684\u8ddd\u79bb\u4e3a 3 \u3002

    \n\n

    \u00a0

    \n\n
      \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 22\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n22 \u7684\u4e8c\u8fdb\u5236\u662f \"10110\" \u3002\n\u5728 22 \u7684\u4e8c\u8fdb\u5236\u8868\u793a\u4e2d\uff0c\u6709\u4e09\u4e2a 1\uff0c\u7ec4\u6210\u4e24\u5bf9\u76f8\u90bb\u7684 1 \u3002\n\u7b2c\u4e00\u5bf9\u76f8\u90bb\u7684 1 \u4e2d\uff0c\u4e24\u4e2a 1 \u4e4b\u95f4\u7684\u8ddd\u79bb\u4e3a 2 \u3002\n\u7b2c\u4e8c\u5bf9\u76f8\u90bb\u7684 1 \u4e2d\uff0c\u4e24\u4e2a 1 \u4e4b\u95f4\u7684\u8ddd\u79bb\u4e3a 1 \u3002\n\u7b54\u6848\u53d6\u4e24\u4e2a\u8ddd\u79bb\u4e4b\u4e2d\u6700\u5927\u7684\uff0c\u4e5f\u5c31\u662f 2 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 5\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n5 \u7684\u4e8c\u8fdb\u5236\u662f \"101\" \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 6\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\n6 \u7684\u4e8c\u8fdb\u5236\u662f \"110\" \u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 8\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\n8 \u7684\u4e8c\u8fdb\u5236\u662f \"1000\" \u3002\n\u5728 8 \u7684\u4e8c\u8fdb\u5236\u8868\u793a\u4e2d\u6ca1\u6709\u76f8\u90bb\u7684\u4e24\u4e2a 1\uff0c\u6240\u4ee5\u8fd4\u56de 0 \u3002\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= N <= 10^9
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int binaryGap(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int binaryGap(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def binaryGap(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def binaryGap(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint binaryGap(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int BinaryGap(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar binaryGap = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef binary_gap(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func binaryGap(_ n: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func binaryGap(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def binaryGap(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun binaryGap(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn binary_gap(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function binaryGap($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function binaryGap(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (binary-gap n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0868](https://leetcode-cn.com/problems/binary-gap)", "[\u4e8c\u8fdb\u5236\u95f4\u8ddd](/solution/0800-0899/0868.Binary%20Gap/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0868](https://leetcode.com/problems/binary-gap)", "[Binary Gap](/solution/0800-0899/0868.Binary%20Gap/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "0898", "frontend_question_id": "0867", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/transpose-matrix", "url_en": "https://leetcode.com/problems/transpose-matrix", "relative_path_cn": "/solution/0800-0899/0867.Transpose%20Matrix/README.md", "relative_path_en": "/solution/0800-0899/0867.Transpose%20Matrix/README_EN.md", "title_cn": "\u8f6c\u7f6e\u77e9\u9635", "title_en": "Transpose Matrix", "question_title_slug": "transpose-matrix", "content_en": "

    Given a 2D integer array matrix, return the transpose of matrix.

    \n\n

    The transpose of a matrix is the matrix flipped over its main diagonal, switching the matrix's row and column indices.

    \n\n

    \"\"

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: matrix = [[1,2,3],[4,5,6],[7,8,9]]\nOutput: [[1,4,7],[2,5,8],[3,6,9]]\n
    \n\n

    Example 2:

    \n\n
    \nInput: matrix = [[1,2,3],[4,5,6]]\nOutput: [[1,4],[2,5],[3,6]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == matrix.length
    • \n\t
    • n == matrix[i].length
    • \n\t
    • 1 <= m, n <= 1000
    • \n\t
    • 1 <= m * n <= 105
    • \n\t
    • -109 <= matrix[i][j] <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u4e8c\u7ef4\u6574\u6570\u6570\u7ec4 matrix\uff0c\u00a0\u8fd4\u56de matrix \u7684 \u8f6c\u7f6e\u77e9\u9635 \u3002

    \n\n

    \u77e9\u9635\u7684 \u8f6c\u7f6e \u662f\u6307\u5c06\u77e9\u9635\u7684\u4e3b\u5bf9\u89d2\u7ebf\u7ffb\u8f6c\uff0c\u4ea4\u6362\u77e9\u9635\u7684\u884c\u7d22\u5f15\u4e0e\u5217\u7d22\u5f15\u3002

    \n\n

    \"\"

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1amatrix = [[1,2,3],[4,5,6],[7,8,9]]\n\u8f93\u51fa\uff1a[[1,4,7],[2,5,8],[3,6,9]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1amatrix = [[1,2,3],[4,5,6]]\n\u8f93\u51fa\uff1a[[1,4],[2,5],[3,6]]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == matrix.length
    • \n\t
    • n == matrix[i].length
    • \n\t
    • 1 <= m, n <= 1000
    • \n\t
    • 1 <= m * n <= 105
    • \n\t
    • -109 <= matrix[i][j] <= 109
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> transpose(vector>& matrix) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[][] transpose(int[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def transpose(self, matrix):\n \"\"\"\n :type matrix: List[List[int]]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def transpose(self, matrix: List[List[int]]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** transpose(int** matrix, int matrixSize, int* matrixColSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[][] Transpose(int[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} matrix\n * @return {number[][]}\n */\nvar transpose = function(matrix) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} matrix\n# @return {Integer[][]}\ndef transpose(matrix)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func transpose(_ matrix: [[Int]]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func transpose(matrix [][]int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def transpose(matrix: Array[Array[Int]]): Array[Array[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun transpose(matrix: Array): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn transpose(matrix: Vec>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $matrix\n * @return Integer[][]\n */\n function transpose($matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function transpose(matrix: number[][]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (transpose matrix)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0867](https://leetcode-cn.com/problems/transpose-matrix)", "[\u8f6c\u7f6e\u77e9\u9635](/solution/0800-0899/0867.Transpose%20Matrix/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0867](https://leetcode.com/problems/transpose-matrix)", "[Transpose Matrix](/solution/0800-0899/0867.Transpose%20Matrix/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0897", "frontend_question_id": "0866", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/prime-palindrome", "url_en": "https://leetcode.com/problems/prime-palindrome", "relative_path_cn": "/solution/0800-0899/0866.Prime%20Palindrome/README.md", "relative_path_en": "/solution/0800-0899/0866.Prime%20Palindrome/README_EN.md", "title_cn": "\u56de\u6587\u7d20\u6570", "title_en": "Prime Palindrome", "question_title_slug": "prime-palindrome", "content_en": "

    Find the smallest prime palindrome greater than or equal to n.

    \n\n

    Recall that a number is prime if it's only divisors are 1 and itself, and it is greater than 1. 

    \n\n

    For example, 2,3,5,7,11 and 13 are primes.

    \n\n

    Recall that a number is a palindrome if it reads the same from left to right as it does from right to left. 

    \n\n

    For example, 12321 is a palindrome.

    \n\n

     

    \n\n
    \n

    Example 1:

    \n\n
    \nInput: n = 6\nOutput: 7\n
    \n\n
    \n

    Example 2:

    \n\n
    \nInput: n = 8\nOutput: 11\n
    \n\n
    \n

    Example 3:

    \n\n
    \nInput: n = 13\nOutput: 101
    \n
    \n
    \n
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    • 1 <= n <= 108
    • \n\t
    • The answer is guaranteed to exist and be less than 2 * 108.
    • \n
    \n", "content_cn": "

    \u6c42\u51fa\u5927\u4e8e\u6216\u7b49\u4e8e N \u7684\u6700\u5c0f\u56de\u6587\u7d20\u6570\u3002

    \n\n

    \u56de\u987e\u4e00\u4e0b\uff0c\u5982\u679c\u4e00\u4e2a\u6570\u5927\u4e8e 1\uff0c\u4e14\u5176\u56e0\u6570\u53ea\u6709 1 \u548c\u5b83\u81ea\u8eab\uff0c\u90a3\u4e48\u8fd9\u4e2a\u6570\u662f\u7d20\u6570\u3002

    \n\n

    \u4f8b\u5982\uff0c2\uff0c3\uff0c5\uff0c7\uff0c11 \u4ee5\u53ca 13 \u662f\u7d20\u6570\u3002

    \n\n

    \u56de\u987e\u4e00\u4e0b\uff0c\u5982\u679c\u4e00\u4e2a\u6570\u4ece\u5de6\u5f80\u53f3\u8bfb\u4e0e\u4ece\u53f3\u5f80\u5de6\u8bfb\u662f\u4e00\u6837\u7684\uff0c\u90a3\u4e48\u8fd9\u4e2a\u6570\u662f\u56de\u6587\u6570\u3002

    \n\n

    \u4f8b\u5982\uff0c12321 \u662f\u56de\u6587\u6570\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a6\n\u8f93\u51fa\uff1a7\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a8\n\u8f93\u51fa\uff1a11\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1a13\n\u8f93\u51fa\uff1a101
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= N <= 10^8
    • \n\t
    • \u7b54\u6848\u80af\u5b9a\u5b58\u5728\uff0c\u4e14\u5c0f\u4e8e 2 * 10^8\u3002
    • \n
    \n\n

     

    \n\n

     

    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int primePalindrome(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int primePalindrome(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def primePalindrome(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def primePalindrome(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint primePalindrome(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int PrimePalindrome(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar primePalindrome = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef prime_palindrome(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func primePalindrome(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func primePalindrome(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def primePalindrome(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun primePalindrome(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn prime_palindrome(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function primePalindrome($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function primePalindrome(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (prime-palindrome n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0866](https://leetcode-cn.com/problems/prime-palindrome)", "[\u56de\u6587\u7d20\u6570](/solution/0800-0899/0866.Prime%20Palindrome/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0866](https://leetcode.com/problems/prime-palindrome)", "[Prime Palindrome](/solution/0800-0899/0866.Prime%20Palindrome/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "0896", "frontend_question_id": "0865", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/smallest-subtree-with-all-the-deepest-nodes", "url_en": "https://leetcode.com/problems/smallest-subtree-with-all-the-deepest-nodes", "relative_path_cn": "/solution/0800-0899/0865.Smallest%20Subtree%20with%20all%20the%20Deepest%20Nodes/README.md", "relative_path_en": "/solution/0800-0899/0865.Smallest%20Subtree%20with%20all%20the%20Deepest%20Nodes/README_EN.md", "title_cn": "\u5177\u6709\u6240\u6709\u6700\u6df1\u8282\u70b9\u7684\u6700\u5c0f\u5b50\u6811", "title_en": "Smallest Subtree with all the Deepest Nodes", "question_title_slug": "smallest-subtree-with-all-the-deepest-nodes", "content_en": "

    Given the root of a binary tree, the depth of each node is the shortest distance to the root.

    \r\n\r\n

    Return the smallest subtree such that it contains all the deepest nodes in the original tree.

    \r\n\r\n

    A node is called the deepest if it has the largest depth possible among any node in the entire tree.

    \r\n\r\n

    The subtree of a node is tree consisting of that node, plus the set of all descendants of that node.

    \r\n\r\n

    Note: This question is the same as 1123: https://leetcode.com/problems/lowest-common-ancestor-of-deepest-leaves/

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\"\"\r\n
    \r\nInput: root = [3,5,1,6,2,0,8,null,null,7,4]\r\nOutput: [2,7,4]\r\nExplanation: We return the node with value 2, colored in yellow in the diagram.\r\nThe nodes coloured in blue are the deepest nodes of the tree.\r\nNotice that nodes 5, 3 and 2 contain the deepest nodes in the tree but node 2 is the smallest subtree among them, so we return it.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: root = [1]\r\nOutput: [1]\r\nExplanation: The root is the deepest node in the tree.\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: root = [0,1,3,null,2]\r\nOutput: [2]\r\nExplanation: The deepest node in the tree is 2, the valid subtrees are the subtrees of nodes 2, 1 and 0 but the subtree of node 2 is the smallest.\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • The number of nodes in the tree will be in the range [1, 500].
    • \r\n\t
    • 0 <= Node.val <= 500
    • \r\n\t
    • The values of the nodes in the tree are unique.
    • \r\n
    ", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6839\u4e3a\u00a0root\u00a0\u7684\u4e8c\u53c9\u6811\uff0c\u6bcf\u4e2a\u8282\u70b9\u7684\u6df1\u5ea6\u662f \u8be5\u8282\u70b9\u5230\u6839\u7684\u6700\u77ed\u8ddd\u79bb \u3002

    \n\n

    \u5982\u679c\u4e00\u4e2a\u8282\u70b9\u5728 \u6574\u4e2a\u6811 \u7684\u4efb\u610f\u8282\u70b9\u4e4b\u95f4\u5177\u6709\u6700\u5927\u7684\u6df1\u5ea6\uff0c\u5219\u8be5\u8282\u70b9\u662f \u6700\u6df1\u7684 \u3002

    \n\n

    \u4e00\u4e2a\u8282\u70b9\u7684 \u5b50\u6811 \u662f\u8be5\u8282\u70b9\u52a0\u4e0a\u5b83\u7684\u6240\u6709\u540e\u4ee3\u7684\u96c6\u5408\u3002

    \n\n

    \u8fd4\u56de\u80fd\u6ee1\u8db3 \u4ee5\u8be5\u8282\u70b9\u4e3a\u6839\u7684\u5b50\u6811\u4e2d\u5305\u542b\u6240\u6709\u6700\u6df1\u7684\u8282\u70b9 \u8fd9\u4e00\u6761\u4ef6\u7684\u5177\u6709\u6700\u5927\u6df1\u5ea6\u7684\u8282\u70b9\u3002

    \n\n

    \u00a0

    \n\n

    \u6ce8\u610f\uff1a\u672c\u9898\u4e0e\u529b\u6263 1123 \u91cd\u590d\uff1ahttps://leetcode-cn.com/problems/lowest-common-ancestor-of-deepest-leaves/

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aroot = [3,5,1,6,2,0,8,null,null,7,4]\n\u8f93\u51fa\uff1a[2,7,4]\n\u89e3\u91ca\uff1a\n\u6211\u4eec\u8fd4\u56de\u503c\u4e3a 2 \u7684\u8282\u70b9\uff0c\u5728\u56fe\u4e2d\u7528\u9ec4\u8272\u6807\u8bb0\u3002\n\u5728\u56fe\u4e2d\u7528\u84dd\u8272\u6807\u8bb0\u7684\u662f\u6811\u7684\u6700\u6df1\u7684\u8282\u70b9\u3002\n\u6ce8\u610f\uff0c\u8282\u70b9 5\u30013 \u548c 2 \u5305\u542b\u6811\u4e2d\u6700\u6df1\u7684\u8282\u70b9\uff0c\u4f46\u8282\u70b9 2 \u7684\u5b50\u6811\u6700\u5c0f\uff0c\u56e0\u6b64\u6211\u4eec\u8fd4\u56de\u5b83\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [1]\n\u8f93\u51fa\uff1a[1]\n\u89e3\u91ca\uff1a\u6839\u8282\u70b9\u662f\u6811\u4e2d\u6700\u6df1\u7684\u8282\u70b9\u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [0,1,3,null,2]\n\u8f93\u51fa\uff1a[2]\n\u89e3\u91ca\uff1a\u6811\u4e2d\u6700\u6df1\u7684\u8282\u70b9\u4e3a 2 \uff0c\u6709\u6548\u5b50\u6811\u4e3a\u8282\u70b9 2\u30011 \u548c 0 \u7684\u5b50\u6811\uff0c\u4f46\u8282\u70b9 2 \u7684\u5b50\u6811\u6700\u5c0f\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u7684\u6570\u91cf\u4ecb\u4e8e\u00a01 \u548c\u00a0500 \u4e4b\u95f4\u3002
    • \n\t
    • 0 <= Node.val <= 500
    • \n\t
    • \u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u90fd\u662f\u72ec\u4e00\u65e0\u4e8c\u7684\u3002
    • \n
    \n", "tags_en": ["Tree", "Depth-first Search", "Breadth-first Search", "Recursion"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u9012\u5f52"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* subtreeWithAllDeepest(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode subtreeWithAllDeepest(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def subtreeWithAllDeepest(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: TreeNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def subtreeWithAllDeepest(self, root: TreeNode) -> TreeNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* subtreeWithAllDeepest(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode SubtreeWithAllDeepest(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {TreeNode}\n */\nvar subtreeWithAllDeepest = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {TreeNode}\ndef subtree_with_all_deepest(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func subtreeWithAllDeepest(_ root: TreeNode?) -> TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc subtreeWithAllDeepest(root *TreeNode) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def subtreeWithAllDeepest(root: TreeNode): TreeNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun subtreeWithAllDeepest(root: TreeNode?): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn subtree_with_all_deepest(root: Option>>) -> Option>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return TreeNode\n */\n function subtreeWithAllDeepest($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction subtreeWithAllDeepest(root: TreeNode | null): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (subtree-with-all-deepest root)\n (-> (or/c tree-node? #f) (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0865](https://leetcode-cn.com/problems/smallest-subtree-with-all-the-deepest-nodes)", "[\u5177\u6709\u6240\u6709\u6700\u6df1\u8282\u70b9\u7684\u6700\u5c0f\u5b50\u6811](/solution/0800-0899/0865.Smallest%20Subtree%20with%20all%20the%20Deepest%20Nodes/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u9012\u5f52`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0865](https://leetcode.com/problems/smallest-subtree-with-all-the-deepest-nodes)", "[Smallest Subtree with all the Deepest Nodes](/solution/0800-0899/0865.Smallest%20Subtree%20with%20all%20the%20Deepest%20Nodes/README_EN.md)", "`Tree`,`Depth-first Search`,`Breadth-first Search`,`Recursion`", "Medium", ""]}, {"question_id": "0895", "frontend_question_id": "0864", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/shortest-path-to-get-all-keys", "url_en": "https://leetcode.com/problems/shortest-path-to-get-all-keys", "relative_path_cn": "/solution/0800-0899/0864.Shortest%20Path%20to%20Get%20All%20Keys/README.md", "relative_path_en": "/solution/0800-0899/0864.Shortest%20Path%20to%20Get%20All%20Keys/README_EN.md", "title_cn": "\u83b7\u53d6\u6240\u6709\u94a5\u5319\u7684\u6700\u77ed\u8def\u5f84", "title_en": "Shortest Path to Get All Keys", "question_title_slug": "shortest-path-to-get-all-keys", "content_en": "

    We are given a 2-dimensional grid"." is an empty cell, "#" is a wall, "@" is the starting point, ("a", "b", ...) are keys, and ("A""B", ...) are locks.

    \r\n\r\n

    We start at the starting point, and one move consists of walking one space in one of the 4 cardinal directions.  We cannot walk outside the grid, or walk into a wall.  If we walk over a key, we pick it up.  We can't walk over a lock unless we have the corresponding key.

    \r\n\r\n

    For some 1 <= K <= 6, there is exactly one lowercase and one uppercase letter of the first K letters of the English alphabet in the grid.  This means that there is exactly one key for each lock, and one lock for each key; and also that the letters used to represent the keys and locks were chosen in the same order as the English alphabet.

    \r\n\r\n

    Return the lowest number of moves to acquire all keys.  If it's impossible, return -1.

    \r\n\r\n

     

    \r\n\r\n
    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: ["@.a.#","###.#","b.A.B"]\r\nOutput: 8\r\n
    \r\n\r\n
    \r\n

    Example 2:

    \r\n\r\n
    \r\nInput: ["@..aA","..B#.","....b"]\r\nOutput: 6\r\n
    \r\n
    \r\n\r\n

     

    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    1. 1 <= grid.length <= 30
    2. \r\n\t
    3. 1 <= grid[0].length <= 30
    4. \r\n\t
    5. grid[i][j] contains only '.', '#', '@''a'-'f' and 'A'-'F'
    6. \r\n\t
    7. The number of keys is in [1, 6].  Each key has a different letter and opens exactly one lock.
    8. \r\n
    \r\n
    \r\n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u7ef4\u7f51\u683c grid\u3002 "." \u4ee3\u8868\u4e00\u4e2a\u7a7a\u623f\u95f4\uff0c "#" \u4ee3\u8868\u4e00\u5835\u5899\uff0c "@" \u662f\u8d77\u70b9\uff0c\uff08"a""b", ...\uff09\u4ee3\u8868\u94a5\u5319\uff0c\uff08"A""B", ...\uff09\u4ee3\u8868\u9501\u3002

    \n\n

    \u6211\u4eec\u4ece\u8d77\u70b9\u5f00\u59cb\u51fa\u53d1\uff0c\u4e00\u6b21\u79fb\u52a8\u662f\u6307\u5411\u56db\u4e2a\u57fa\u672c\u65b9\u5411\u4e4b\u4e00\u884c\u8d70\u4e00\u4e2a\u5355\u4f4d\u7a7a\u95f4\u3002\u6211\u4eec\u4e0d\u80fd\u5728\u7f51\u683c\u5916\u9762\u884c\u8d70\uff0c\u4e5f\u65e0\u6cd5\u7a7f\u8fc7\u4e00\u5835\u5899\u3002\u5982\u679c\u9014\u7ecf\u4e00\u4e2a\u94a5\u5319\uff0c\u6211\u4eec\u5c31\u628a\u5b83\u6361\u8d77\u6765\u3002\u9664\u975e\u6211\u4eec\u624b\u91cc\u6709\u5bf9\u5e94\u7684\u94a5\u5319\uff0c\u5426\u5219\u65e0\u6cd5\u901a\u8fc7\u9501\u3002

    \n\n

    \u5047\u8bbe K \u4e3a\u94a5\u5319/\u9501\u7684\u4e2a\u6570\uff0c\u4e14\u6ee1\u8db3 1 <= K <= 6\uff0c\u5b57\u6bcd\u8868\u4e2d\u7684\u524d K \u4e2a\u5b57\u6bcd\u5728\u7f51\u683c\u4e2d\u90fd\u6709\u81ea\u5df1\u5bf9\u5e94\u7684\u4e00\u4e2a\u5c0f\u5199\u548c\u4e00\u4e2a\u5927\u5199\u5b57\u6bcd\u3002\u6362\u8a00\u4e4b\uff0c\u6bcf\u4e2a\u9501\u6709\u552f\u4e00\u5bf9\u5e94\u7684\u94a5\u5319\uff0c\u6bcf\u4e2a\u94a5\u5319\u4e5f\u6709\u552f\u4e00\u5bf9\u5e94\u7684\u9501\u3002\u53e6\u5916\uff0c\u4ee3\u8868\u94a5\u5319\u548c\u9501\u7684\u5b57\u6bcd\u4e92\u4e3a\u5927\u5c0f\u5199\u5e76\u6309\u5b57\u6bcd\u987a\u5e8f\u6392\u5217\u3002

    \n\n

    \u8fd4\u56de\u83b7\u53d6\u6240\u6709\u94a5\u5319\u6240\u9700\u8981\u7684\u79fb\u52a8\u7684\u6700\u5c11\u6b21\u6570\u3002\u5982\u679c\u65e0\u6cd5\u83b7\u53d6\u6240\u6709\u94a5\u5319\uff0c\u8fd4\u56de -1 \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a["@.a.#","###.#","b.A.B"]\n\u8f93\u51fa\uff1a8\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a["@..aA","..B#.","....b"]\n\u8f93\u51fa\uff1a6\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= grid.length <= 30
    2. \n\t
    3. 1 <= grid[0].length <= 30
    4. \n\t
    5. grid[i][j] \u53ea\u542b\u6709 '.''#''@''a'-'f' \u4ee5\u53ca 'A'-'F'
    6. \n\t
    7. \u94a5\u5319\u7684\u6570\u76ee\u8303\u56f4\u662f [1, 6]\uff0c\u6bcf\u4e2a\u94a5\u5319\u90fd\u5bf9\u5e94\u4e00\u4e2a\u4e0d\u540c\u7684\u5b57\u6bcd\uff0c\u6b63\u597d\u6253\u5f00\u4e00\u4e2a\u5bf9\u5e94\u7684\u9501\u3002
    8. \n
    \n", "tags_en": ["Heap", "Breadth-first Search"], "tags_cn": ["\u5806", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int shortestPathAllKeys(vector& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int shortestPathAllKeys(String[] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def shortestPathAllKeys(self, grid):\n \"\"\"\n :type grid: List[str]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def shortestPathAllKeys(self, grid: List[str]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint shortestPathAllKeys(char ** grid, int gridSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ShortestPathAllKeys(string[] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} grid\n * @return {number}\n */\nvar shortestPathAllKeys = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} grid\n# @return {Integer}\ndef shortest_path_all_keys(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func shortestPathAllKeys(_ grid: [String]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func shortestPathAllKeys(grid []string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def shortestPathAllKeys(grid: Array[String]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun shortestPathAllKeys(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn shortest_path_all_keys(grid: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $grid\n * @return Integer\n */\n function shortestPathAllKeys($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function shortestPathAllKeys(grid: string[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (shortest-path-all-keys grid)\n (-> (listof string?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0864](https://leetcode-cn.com/problems/shortest-path-to-get-all-keys)", "[\u83b7\u53d6\u6240\u6709\u94a5\u5319\u7684\u6700\u77ed\u8def\u5f84](/solution/0800-0899/0864.Shortest%20Path%20to%20Get%20All%20Keys/README.md)", "`\u5806`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[0864](https://leetcode.com/problems/shortest-path-to-get-all-keys)", "[Shortest Path to Get All Keys](/solution/0800-0899/0864.Shortest%20Path%20to%20Get%20All%20Keys/README_EN.md)", "`Heap`,`Breadth-first Search`", "Hard", ""]}, {"question_id": "0894", "frontend_question_id": "0710", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/random-pick-with-blacklist", "url_en": "https://leetcode.com/problems/random-pick-with-blacklist", "relative_path_cn": "/solution/0700-0799/0710.Random%20Pick%20with%20Blacklist/README.md", "relative_path_en": "/solution/0700-0799/0710.Random%20Pick%20with%20Blacklist/README_EN.md", "title_cn": "\u9ed1\u540d\u5355\u4e2d\u7684\u968f\u673a\u6570", "title_en": "Random Pick with Blacklist", "question_title_slug": "random-pick-with-blacklist", "content_en": "

    Given a blacklist blacklist containing unique integers from [0, n), write a function to return a uniform random integer from [0, n) which is NOT in blacklist.

    \n\n

    Optimize it such that it minimizes the call to system’s Math.random().

    \n\n

    Note:

    \n\n
      \n\t
    1. 1 <= n <= 1000000000
    2. \n\t
    3. 0 <= blacklist.length < min(100000, n)
    4. \n\t
    5. [0, n) does NOT include n. See interval notation.
    6. \n
    \n\n

    Example 1:

    \n\n
    \nInput: \n["Solution","pick","pick","pick"]\n[[1,[]],[],[],[]]\nOutput: [null,0,0,0]\n
    \n\n

    Example 2:

    \n\n
    \nInput: \n["Solution","pick","pick","pick"]\n[[2,[]],[],[],[]]\nOutput: [null,1,1,1]\n
    \n\n

    Example 3:

    \n\n
    \nInput: \n["Solution","pick","pick","pick"]\n[[3,[1]],[],[],[]]\nOutput: [null,0,0,2]\n
    \n\n

    Example 4:

    \n\n
    \nInput: \n["Solution","pick","pick","pick"]\n[[4,[2]],[],[],[]]\nOutput: [null,1,3,1]\n
    \n\n

    Explanation of Input Syntax:

    \n\n

    The input is two lists: the subroutines called and their arguments. Solution's constructor has two arguments, n and the blacklist blacklist. pick has no arguments. Arguments are always wrapped with a list, even if there aren't any.

    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5305\u542b [0\uff0cn) \u4e2d\u4e0d\u91cd\u590d\u6574\u6570\u7684\u9ed1\u540d\u5355 blacklist \uff0c\u5199\u4e00\u4e2a\u51fd\u6570\u4ece [0, n) \u4e2d\u8fd4\u56de\u4e00\u4e2a\u4e0d\u5728 blacklist \u4e2d\u7684\u968f\u673a\u6574\u6570\u3002

    \n\n

    \u5bf9\u5b83\u8fdb\u884c\u4f18\u5316\u4f7f\u5176\u5c3d\u91cf\u5c11\u8c03\u7528\u7cfb\u7edf\u65b9\u6cd5 Math.random() \u3002

    \n\n

    \u63d0\u793a:

    \n\n
      \n\t
    1. 1 <= n <= 1000000000
    2. \n\t
    3. 0 <= blacklist.length < min(100000, N)
    4. \n\t
    5. [0, n)\u00a0\u4e0d\u5305\u542b n \uff0c\u8be6\u7ec6\u53c2\u89c1\u00a0interval notation\u00a0\u3002
    6. \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\n[\"Solution\",\"pick\",\"pick\",\"pick\"]\n[[1,[]],[],[],[]]\n\u8f93\u51fa\uff1a[null,0,0,0]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\n[\"Solution\",\"pick\",\"pick\",\"pick\"]\n[[2,[]],[],[],[]]\n\u8f93\u51fa\uff1a[null,1,1,1]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\n[\"Solution\",\"pick\",\"pick\",\"pick\"]\n[[3,[1]],[],[],[]]\n\u8f93\u51fa\uff1a[null,0,0,2]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1a \n[\"Solution\",\"pick\",\"pick\",\"pick\"]\n[[4,[2]],[],[],[]]\n\u8f93\u51fa\uff1a[null,1,3,1]\n
    \n\n

    \u8f93\u5165\u8bed\u6cd5\u8bf4\u660e\uff1a

    \n\n

    \u8f93\u5165\u662f\u4e24\u4e2a\u5217\u8868\uff1a\u8c03\u7528\u6210\u5458\u51fd\u6570\u540d\u548c\u8c03\u7528\u7684\u53c2\u6570\u3002Solution\u7684\u6784\u9020\u51fd\u6570\u6709\u4e24\u4e2a\u53c2\u6570\uff0cn \u548c\u9ed1\u540d\u5355\u00a0blacklist\u3002pick\u00a0\u6ca1\u6709\u53c2\u6570\uff0c\u8f93\u5165\u53c2\u6570\u662f\u4e00\u4e2a\u5217\u8868\uff0c\u5373\u4f7f\u53c2\u6570\u4e3a\u7a7a\uff0c\u4e5f\u4f1a\u8f93\u5165\u4e00\u4e2a [] \u7a7a\u5217\u8868\u3002

    \n", "tags_en": ["Sort", "Hash Table", "Binary Search", "Random"], "tags_cn": ["\u6392\u5e8f", "\u54c8\u5e0c\u8868", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n Solution(int n, vector& blacklist) {\n\n }\n \n int pick() {\n\n }\n};\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution* obj = new Solution(n, blacklist);\n * int param_1 = obj->pick();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n\n public Solution(int n, int[] blacklist) {\n\n }\n \n public int pick() {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution obj = new Solution(n, blacklist);\n * int param_1 = obj.pick();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n\n def __init__(self, n, blacklist):\n \"\"\"\n :type n: int\n :type blacklist: List[int]\n \"\"\"\n\n\n def pick(self):\n \"\"\"\n :rtype: int\n \"\"\"\n\n\n\n# Your Solution object will be instantiated and called as such:\n# obj = Solution(n, blacklist)\n# param_1 = obj.pick()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n\n def __init__(self, n: int, blacklist: List[int]):\n\n\n def pick(self) -> int:\n\n\n\n# Your Solution object will be instantiated and called as such:\n# obj = Solution(n, blacklist)\n# param_1 = obj.pick()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} Solution;\n\n\nSolution* solutionCreate(int n, int* blacklist, int blacklistSize) {\n\n}\n\nint solutionPick(Solution* obj) {\n\n}\n\nvoid solutionFree(Solution* obj) {\n\n}\n\n/**\n * Your Solution struct will be instantiated and called as such:\n * Solution* obj = solutionCreate(n, blacklist, blacklistSize);\n * int param_1 = solutionPick(obj);\n \n * solutionFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n\n public Solution(int n, int[] blacklist) {\n\n }\n \n public int Pick() {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution obj = new Solution(n, blacklist);\n * int param_1 = obj.Pick();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[]} blacklist\n */\nvar Solution = function(n, blacklist) {\n\n};\n\n/**\n * @return {number}\n */\nSolution.prototype.pick = function() {\n\n};\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = new Solution(n, blacklist)\n * var param_1 = obj.pick()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class Solution\n\n=begin\n :type n: Integer\n :type blacklist: Integer[]\n=end\n def initialize(n, blacklist)\n\n end\n\n\n=begin\n :rtype: Integer\n=end\n def pick()\n\n end\n\n\nend\n\n# Your Solution object will be instantiated and called as such:\n# obj = Solution.new(n, blacklist)\n# param_1 = obj.pick()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass Solution {\n\n init(_ n: Int, _ blacklist: [Int]) {\n\n }\n \n func pick() -> Int {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * let obj = Solution(n, blacklist)\n * let ret_1: Int = obj.pick()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type Solution struct {\n\n}\n\n\nfunc Constructor(n int, blacklist []int) Solution {\n\n}\n\n\nfunc (this *Solution) Pick() int {\n\n}\n\n\n/**\n * Your Solution object will be instantiated and called as such:\n * obj := Constructor(n, blacklist);\n * param_1 := obj.Pick();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class Solution(_n: Int, _blacklist: Array[Int]) {\n\n def pick(): Int = {\n\n }\n\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = new Solution(n, blacklist)\n * var param_1 = obj.pick()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution(n: Int, blacklist: IntArray) {\n\n fun pick(): Int {\n\n }\n\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = Solution(n, blacklist)\n * var param_1 = obj.pick()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct Solution {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl Solution {\n\n fn new(n: i32, blacklist: Vec) -> Self {\n\n }\n \n fn pick(&self) -> i32 {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * let obj = Solution::new(n, blacklist);\n * let ret_1: i32 = obj.pick();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n /**\n * @param Integer $n\n * @param Integer[] $blacklist\n */\n function __construct($n, $blacklist) {\n\n }\n\n /**\n * @return Integer\n */\n function pick() {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * $obj = Solution($n, $blacklist);\n * $ret_1 = $obj->pick();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class Solution {\n constructor(n: number, blacklist: number[]) {\n\n }\n\n pick(): number {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = new Solution(n, blacklist)\n * var param_1 = obj.pick()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define solution%\n (class object%\n (super-new)\n\n ; n : exact-integer?\n\n ; blacklist : (listof exact-integer?)\n (init-field\n n\n blacklist)\n \n ; pick : -> exact-integer?\n (define/public (pick)\n\n )))\n\n;; Your solution% object will be instantiated and called as such:\n;; (define obj (new solution% [n n] [blacklist blacklist]))\n;; (define param_1 (send obj pick))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0710](https://leetcode-cn.com/problems/random-pick-with-blacklist)", "[\u9ed1\u540d\u5355\u4e2d\u7684\u968f\u673a\u6570](/solution/0700-0799/0710.Random%20Pick%20with%20Blacklist/README.md)", "`\u6392\u5e8f`,`\u54c8\u5e0c\u8868`,`\u4e8c\u5206\u67e5\u627e`", "\u56f0\u96be", ""], "md_table_row_en": ["[0710](https://leetcode.com/problems/random-pick-with-blacklist)", "[Random Pick with Blacklist](/solution/0700-0799/0710.Random%20Pick%20with%20Blacklist/README_EN.md)", "`Sort`,`Hash Table`,`Binary Search`,`Random`", "Hard", ""]}, {"question_id": "0893", "frontend_question_id": "0863", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/all-nodes-distance-k-in-binary-tree", "url_en": "https://leetcode.com/problems/all-nodes-distance-k-in-binary-tree", "relative_path_cn": "/solution/0800-0899/0863.All%20Nodes%20Distance%20K%20in%20Binary%20Tree/README.md", "relative_path_en": "/solution/0800-0899/0863.All%20Nodes%20Distance%20K%20in%20Binary%20Tree/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u4e2d\u6240\u6709\u8ddd\u79bb\u4e3a K \u7684\u7ed3\u70b9", "title_en": "All Nodes Distance K in Binary Tree", "question_title_slug": "all-nodes-distance-k-in-binary-tree", "content_en": "

    We are given a binary tree (with root node root), a target node, and an integer value k.

    \n\n

    Return a list of the values of all nodes that have a distance k from the target node.  The answer can be returned in any order.

    \n\n

     

    \n\n
      \n
    \n\n
    \n

    Example 1:

    \n\n
    \nInput: root = [3,5,1,6,2,0,8,null,null,7,4], target = 5, k = 2\n\nOutput: [7,4,1]\n\nExplanation: \nThe nodes that are a distance 2 from the target node (with value 5)\nhave values 7, 4, and 1.\n\n\"\"\n\nNote that the inputs "root" and "target" are actually TreeNodes.\nThe descriptions of the inputs above are just serializations of these objects.\n
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    1. The given tree is non-empty.
    2. \n\t
    3. Each node in the tree has unique values 0 <= node.val <= 500.
    4. \n\t
    5. The target node is a node in the tree.
    6. \n\t
    7. 0 <= k <= 1000.
    8. \n
    \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811\uff08\u5177\u6709\u6839\u7ed3\u70b9 root\uff09\uff0c \u4e00\u4e2a\u76ee\u6807\u7ed3\u70b9 target \uff0c\u548c\u4e00\u4e2a\u6574\u6570\u503c K \u3002

    \n\n

    \u8fd4\u56de\u5230\u76ee\u6807\u7ed3\u70b9 target \u8ddd\u79bb\u4e3a K \u7684\u6240\u6709\u7ed3\u70b9\u7684\u503c\u7684\u5217\u8868\u3002 \u7b54\u6848\u53ef\u4ee5\u4ee5\u4efb\u4f55\u987a\u5e8f\u8fd4\u56de\u3002

    \n\n

     

    \n\n
      \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aroot = [3,5,1,6,2,0,8,null,null,7,4], target = 5, K = 2\n\u8f93\u51fa\uff1a[7,4,1]\n\u89e3\u91ca\uff1a\n\u6240\u6c42\u7ed3\u70b9\u4e3a\u4e0e\u76ee\u6807\u7ed3\u70b9\uff08\u503c\u4e3a 5\uff09\u8ddd\u79bb\u4e3a 2 \u7684\u7ed3\u70b9\uff0c\n\u503c\u5206\u522b\u4e3a 7\uff0c4\uff0c\u4ee5\u53ca 1\n\n\"\"\n\n\u6ce8\u610f\uff0c\u8f93\u5165\u7684 "root" \u548c "target" \u5b9e\u9645\u4e0a\u662f\u6811\u4e0a\u7684\u7ed3\u70b9\u3002\n\u4e0a\u9762\u7684\u8f93\u5165\u4ec5\u4ec5\u662f\u5bf9\u8fd9\u4e9b\u5bf9\u8c61\u8fdb\u884c\u4e86\u5e8f\u5217\u5316\u63cf\u8ff0\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. \u7ed9\u5b9a\u7684\u6811\u662f\u975e\u7a7a\u7684\u3002
    2. \n\t
    3. \u6811\u4e0a\u7684\u6bcf\u4e2a\u7ed3\u70b9\u90fd\u5177\u6709\u552f\u4e00\u7684\u503c 0 <= node.val <= 500 \u3002
    4. \n\t
    5. \u76ee\u6807\u7ed3\u70b9 target \u662f\u6811\u4e0a\u7684\u7ed3\u70b9\u3002
    6. \n\t
    7. 0 <= K <= 1000.
    8. \n
    \n", "tags_en": ["Tree", "Depth-first Search", "Breadth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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 */\nclass Solution {\npublic:\n vector distanceK(TreeNode* root, TreeNode* target, int k) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode(int x) { val = x; }\n * }\n */\nclass Solution {\n public List distanceK(TreeNode root, TreeNode target, int k) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution(object):\n def distanceK(self, root, target, k):\n \"\"\"\n :type root: TreeNode\n :type target: TreeNode\n :type k: int\n :rtype: List[int]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution:\n def distanceK(self, root: TreeNode, target: TreeNode, k: int) -> List[int]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* distanceK(struct TreeNode* root, struct TreeNode* target, int k, int* returnSize) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int x) { val = x; }\n * }\n */\npublic class Solution {\n public IList DistanceK(TreeNode root, TreeNode target, int k) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val) {\n * this.val = val;\n * this.left = this.right = null;\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {TreeNode} target\n * @param {number} k\n * @return {number[]}\n */\nvar distanceK = function(root, target, k) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val)\n# @val = val\n# @left, @right = nil, nil\n# end\n# end\n# @param {TreeNode} root\n# @param {TreeNode} target\n# @param {Integer} k\n# @return {Integer[]}\ndef distance_k(root, target, k)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.left = nil\n * self.right = nil\n * }\n * }\n */\nclass Solution {\n func distanceK(_ root: TreeNode?, _ target: TreeNode?, _ k: Int) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc distanceK(root *TreeNode, target *TreeNode, k int) []int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(var _value: Int) {\n * var value: Int = _value\n * var left: TreeNode = null\n * var right: TreeNode = null\n * }\n */\nobject Solution {\n def distanceK(root: TreeNode, target: TreeNode, k: Int): List[Int] = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int = 0) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun distanceK(root: TreeNode?, target: TreeNode?, k: Int): List {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n// \n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn distance_k(root: Option>>, target: Option>>, k: i32) -> Vec {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($value) { $this->val = $value; }\n * }\n */\nclass Solution {\n /**\n * @param TreeNode $root\n * @param TreeNode $target\n * @param Integer $k\n * @return Integer[]\n */\n function distanceK($root, $target, $k) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction distanceK(root: TreeNode | null, target: TreeNode | null, k: number): number[] {\n \n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0863](https://leetcode-cn.com/problems/all-nodes-distance-k-in-binary-tree)", "[\u4e8c\u53c9\u6811\u4e2d\u6240\u6709\u8ddd\u79bb\u4e3a K \u7684\u7ed3\u70b9](/solution/0800-0899/0863.All%20Nodes%20Distance%20K%20in%20Binary%20Tree/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0863](https://leetcode.com/problems/all-nodes-distance-k-in-binary-tree)", "[All Nodes Distance K in Binary Tree](/solution/0800-0899/0863.All%20Nodes%20Distance%20K%20in%20Binary%20Tree/README_EN.md)", "`Tree`,`Depth-first Search`,`Breadth-first Search`", "Medium", ""]}, {"question_id": "0892", "frontend_question_id": "0862", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/shortest-subarray-with-sum-at-least-k", "url_en": "https://leetcode.com/problems/shortest-subarray-with-sum-at-least-k", "relative_path_cn": "/solution/0800-0899/0862.Shortest%20Subarray%20with%20Sum%20at%20Least%20K/README.md", "relative_path_en": "/solution/0800-0899/0862.Shortest%20Subarray%20with%20Sum%20at%20Least%20K/README_EN.md", "title_cn": "\u548c\u81f3\u5c11\u4e3a K \u7684\u6700\u77ed\u5b50\u6570\u7ec4", "title_en": "Shortest Subarray with Sum at Least K", "question_title_slug": "shortest-subarray-with-sum-at-least-k", "content_en": "

    Return the length of the shortest, non-empty, contiguous subarray of nums with sum at least k.

    \n\n

    If there is no non-empty subarray with sum at least k, return -1.

    \n\n

     

    \n\n
      \n
    \n\n
    \n

    Example 1:

    \n\n
    \nInput: nums = [1], k = 1\nOutput: 1\n
    \n\n
    \n

    Example 2:

    \n\n
    \nInput: nums = [1,2], k = 4\nOutput: -1\n
    \n\n
    \n

    Example 3:

    \n\n
    \nInput: nums = [2,-1,2], k = 3\nOutput: 3\n
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    1. 1 <= nums.length <= 50000
    2. \n\t
    3. -105 <= nums[i] <= 105
    4. \n\t
    5. 1 <= k <= 109
    6. \n
    \n
    \n
    \n
    \n", "content_cn": "

    \u8fd4\u56de A \u7684\u6700\u77ed\u7684\u975e\u7a7a\u8fde\u7eed\u5b50\u6570\u7ec4\u7684\u957f\u5ea6\uff0c\u8be5\u5b50\u6570\u7ec4\u7684\u548c\u81f3\u5c11\u4e3a K \u3002

    \n\n

    \u5982\u679c\u6ca1\u6709\u548c\u81f3\u5c11\u4e3a K \u7684\u975e\u7a7a\u5b50\u6570\u7ec4\uff0c\u8fd4\u56de -1 \u3002

    \n\n

     

    \n\n
      \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aA = [1], K = 1\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aA = [1,2], K = 4\n\u8f93\u51fa\uff1a-1\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aA = [2,-1,2], K = 3\n\u8f93\u51fa\uff1a3\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= A.length <= 50000
    2. \n\t
    3. -10 ^ 5 <= A[i] <= 10 ^ 5
    4. \n\t
    5. 1 <= K <= 10 ^ 9
    6. \n
    \n", "tags_en": ["Queue", "Binary Search"], "tags_cn": ["\u961f\u5217", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int shortestSubarray(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int shortestSubarray(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def shortestSubarray(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def shortestSubarray(self, nums: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint shortestSubarray(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ShortestSubarray(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar shortestSubarray = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef shortest_subarray(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func shortestSubarray(_ nums: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func shortestSubarray(nums []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def shortestSubarray(nums: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun shortestSubarray(nums: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn shortest_subarray(nums: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer\n */\n function shortestSubarray($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function shortestSubarray(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (shortest-subarray nums k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0862](https://leetcode-cn.com/problems/shortest-subarray-with-sum-at-least-k)", "[\u548c\u81f3\u5c11\u4e3a K \u7684\u6700\u77ed\u5b50\u6570\u7ec4](/solution/0800-0899/0862.Shortest%20Subarray%20with%20Sum%20at%20Least%20K/README.md)", "`\u961f\u5217`,`\u4e8c\u5206\u67e5\u627e`", "\u56f0\u96be", ""], "md_table_row_en": ["[0862](https://leetcode.com/problems/shortest-subarray-with-sum-at-least-k)", "[Shortest Subarray with Sum at Least K](/solution/0800-0899/0862.Shortest%20Subarray%20with%20Sum%20at%20Least%20K/README_EN.md)", "`Queue`,`Binary Search`", "Hard", ""]}, {"question_id": "0891", "frontend_question_id": "0861", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/score-after-flipping-matrix", "url_en": "https://leetcode.com/problems/score-after-flipping-matrix", "relative_path_cn": "/solution/0800-0899/0861.Score%20After%20Flipping%20Matrix/README.md", "relative_path_en": "/solution/0800-0899/0861.Score%20After%20Flipping%20Matrix/README_EN.md", "title_cn": "\u7ffb\u8f6c\u77e9\u9635\u540e\u7684\u5f97\u5206", "title_en": "Score After Flipping Matrix", "question_title_slug": "score-after-flipping-matrix", "content_en": "

    We have a two dimensional matrix grid where each value is 0 or 1.

    \n\n

    A move consists of choosing any row or column, and toggling each value in that row or column: changing all 0s to 1s, and all 1s to 0s.

    \n\n

    After making any number of moves, every row of this matrix is interpreted as a binary number, and the score of the matrix is the sum of these numbers.

    \n\n

    Return the highest possible score.

    \n\n

     

    \n\n
      \n
    \n\n
    \n

    Example 1:

    \n\n
    \nInput: grid = [[0,0,1,1],[1,0,1,0],[1,1,0,0]]\nOutput: 39\nExplanation:\nToggled to [[1,1,1,1],[1,0,0,1],[1,1,1,1]].\n0b1111 + 0b1001 + 0b1111 = 15 + 9 + 15 = 39
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    1. 1 <= grid.length <= 20
    2. \n\t
    3. 1 <= grid[0].length <= 20
    4. \n\t
    5. grid[i][j] is 0 or 1.
    6. \n
    \n
    \n", "content_cn": "

    \u6709\u4e00\u4e2a\u4e8c\u7ef4\u77e9\u9635 A \u5176\u4e2d\u6bcf\u4e2a\u5143\u7d20\u7684\u503c\u4e3a 0 \u6216 1 \u3002

    \n\n

    \u79fb\u52a8\u662f\u6307\u9009\u62e9\u4efb\u4e00\u884c\u6216\u5217\uff0c\u5e76\u8f6c\u6362\u8be5\u884c\u6216\u5217\u4e2d\u7684\u6bcf\u4e00\u4e2a\u503c\uff1a\u5c06\u6240\u6709 0 \u90fd\u66f4\u6539\u4e3a 1\uff0c\u5c06\u6240\u6709 1 \u90fd\u66f4\u6539\u4e3a 0\u3002

    \n\n

    \u5728\u505a\u51fa\u4efb\u610f\u6b21\u6570\u7684\u79fb\u52a8\u540e\uff0c\u5c06\u8be5\u77e9\u9635\u7684\u6bcf\u4e00\u884c\u90fd\u6309\u7167\u4e8c\u8fdb\u5236\u6570\u6765\u89e3\u91ca\uff0c\u77e9\u9635\u7684\u5f97\u5206\u5c31\u662f\u8fd9\u4e9b\u6570\u5b57\u7684\u603b\u548c\u3002

    \n\n

    \u8fd4\u56de\u5c3d\u53ef\u80fd\u9ad8\u7684\u5206\u6570\u3002

    \n\n

     

    \n\n
      \n
    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1a[[0,0,1,1],[1,0,1,0],[1,1,0,0]]\n\u8f93\u51fa\uff1a39\n\u89e3\u91ca\uff1a\n\u8f6c\u6362\u4e3a [[1,1,1,1],[1,0,0,1],[1,1,1,1]]\n0b1111 + 0b1001 + 0b1111 = 15 + 9 + 15 = 39
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= A.length <= 20
    2. \n\t
    3. 1 <= A[0].length <= 20
    4. \n\t
    5. A[i][j] \u662f 0 \u6216 1
    6. \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int matrixScore(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int matrixScore(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def matrixScore(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def matrixScore(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint matrixScore(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MatrixScore(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar matrixScore = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef matrix_score(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func matrixScore(_ grid: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func matrixScore(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def matrixScore(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun matrixScore(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn matrix_score(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function matrixScore($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function matrixScore(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (matrix-score grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0861](https://leetcode-cn.com/problems/score-after-flipping-matrix)", "[\u7ffb\u8f6c\u77e9\u9635\u540e\u7684\u5f97\u5206](/solution/0800-0899/0861.Score%20After%20Flipping%20Matrix/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0861](https://leetcode.com/problems/score-after-flipping-matrix)", "[Score After Flipping Matrix](/solution/0800-0899/0861.Score%20After%20Flipping%20Matrix/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "0890", "frontend_question_id": "0860", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/lemonade-change", "url_en": "https://leetcode.com/problems/lemonade-change", "relative_path_cn": "/solution/0800-0899/0860.Lemonade%20Change/README.md", "relative_path_en": "/solution/0800-0899/0860.Lemonade%20Change/README_EN.md", "title_cn": "\u67e0\u6aac\u6c34\u627e\u96f6", "title_en": "Lemonade Change", "question_title_slug": "lemonade-change", "content_en": "

    At a lemonade stand, each lemonade costs $5

    \r\n\r\n

    Customers are standing in a queue to buy from you, and order one at a time (in the order specified by bills).

    \r\n\r\n

    Each customer will only buy one lemonade and pay with either a $5, $10, or $20 bill.  You must provide the correct change to each customer, so that the net transaction is that the customer pays $5.

    \r\n\r\n

    Note that you don't have any change in hand at first.

    \r\n\r\n

    Return true if and only if you can provide every customer with correct change.

    \r\n\r\n

     

    \r\n\r\n
    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: [5,5,5,10,20]\r\nOutput: true\r\nExplanation: \r\nFrom the first 3 customers, we collect three $5 bills in order.\r\nFrom the fourth customer, we collect a $10 bill and give back a $5.\r\nFrom the fifth customer, we give a $10 bill and a $5 bill.\r\nSince all customers got correct change, we output true.\r\n
    \r\n\r\n
    \r\n

    Example 2:

    \r\n\r\n
    \r\nInput: [5,5,10]\r\nOutput: true\r\n
    \r\n\r\n
    \r\n

    Example 3:

    \r\n\r\n
    \r\nInput: [10,10]\r\nOutput: false\r\n
    \r\n\r\n
    \r\n

    Example 4:

    \r\n\r\n
    \r\nInput: [5,5,10,10,20]\r\nOutput: false\r\nExplanation: \r\nFrom the first two customers in order, we collect two $5 bills.\r\nFor the next two customers in order, we collect a $10 bill and give back a $5 bill.\r\nFor the last customer, we can't give change of $15 back because we only have two $10 bills.\r\nSince not every customer received correct change, the answer is false.\r\n
    \r\n\r\n

     

    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    • 0 <= bills.length <= 10000
    • \r\n\t
    • bills[i] will be either 5, 10, or 20.
    • \r\n
    \r\n
    \r\n
    \r\n
    \r\n
    \r\n", "content_cn": "

    \u5728\u67e0\u6aac\u6c34\u644a\u4e0a\uff0c\u6bcf\u4e00\u676f\u67e0\u6aac\u6c34\u7684\u552e\u4ef7\u4e3a 5 \u7f8e\u5143\u3002

    \n\n

    \u987e\u5ba2\u6392\u961f\u8d2d\u4e70\u4f60\u7684\u4ea7\u54c1\uff0c\uff08\u6309\u8d26\u5355 bills \u652f\u4ed8\u7684\u987a\u5e8f\uff09\u4e00\u6b21\u8d2d\u4e70\u4e00\u676f\u3002

    \n\n

    \u6bcf\u4f4d\u987e\u5ba2\u53ea\u4e70\u4e00\u676f\u67e0\u6aac\u6c34\uff0c\u7136\u540e\u5411\u4f60\u4ed8 5 \u7f8e\u5143\u300110 \u7f8e\u5143\u6216 20 \u7f8e\u5143\u3002\u4f60\u5fc5\u987b\u7ed9\u6bcf\u4e2a\u987e\u5ba2\u6b63\u786e\u627e\u96f6\uff0c\u4e5f\u5c31\u662f\u8bf4\u51c0\u4ea4\u6613\u662f\u6bcf\u4f4d\u987e\u5ba2\u5411\u4f60\u652f\u4ed8 5 \u7f8e\u5143\u3002

    \n\n

    \u6ce8\u610f\uff0c\u4e00\u5f00\u59cb\u4f60\u624b\u5934\u6ca1\u6709\u4efb\u4f55\u96f6\u94b1\u3002

    \n\n

    \u5982\u679c\u4f60\u80fd\u7ed9\u6bcf\u4f4d\u987e\u5ba2\u6b63\u786e\u627e\u96f6\uff0c\u8fd4\u56de true \uff0c\u5426\u5219\u8fd4\u56de false \u3002

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a[5,5,5,10,20]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\n\u524d 3 \u4f4d\u987e\u5ba2\u90a3\u91cc\uff0c\u6211\u4eec\u6309\u987a\u5e8f\u6536\u53d6 3 \u5f20 5 \u7f8e\u5143\u7684\u949e\u7968\u3002\n\u7b2c 4 \u4f4d\u987e\u5ba2\u90a3\u91cc\uff0c\u6211\u4eec\u6536\u53d6\u4e00\u5f20 10 \u7f8e\u5143\u7684\u949e\u7968\uff0c\u5e76\u8fd4\u8fd8 5 \u7f8e\u5143\u3002\n\u7b2c 5 \u4f4d\u987e\u5ba2\u90a3\u91cc\uff0c\u6211\u4eec\u627e\u8fd8\u4e00\u5f20 10 \u7f8e\u5143\u7684\u949e\u7968\u548c\u4e00\u5f20 5 \u7f8e\u5143\u7684\u949e\u7968\u3002\n\u7531\u4e8e\u6240\u6709\u5ba2\u6237\u90fd\u5f97\u5230\u4e86\u6b63\u786e\u7684\u627e\u96f6\uff0c\u6240\u4ee5\u6211\u4eec\u8f93\u51fa true\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a[5,5,10]\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1a[10,10]\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1a[5,5,10,10,20]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\n\u524d 2 \u4f4d\u987e\u5ba2\u90a3\u91cc\uff0c\u6211\u4eec\u6309\u987a\u5e8f\u6536\u53d6 2 \u5f20 5 \u7f8e\u5143\u7684\u949e\u7968\u3002\n\u5bf9\u4e8e\u63a5\u4e0b\u6765\u7684 2 \u4f4d\u987e\u5ba2\uff0c\u6211\u4eec\u6536\u53d6\u4e00\u5f20 10 \u7f8e\u5143\u7684\u949e\u7968\uff0c\u7136\u540e\u8fd4\u8fd8 5 \u7f8e\u5143\u3002\n\u5bf9\u4e8e\u6700\u540e\u4e00\u4f4d\u987e\u5ba2\uff0c\u6211\u4eec\u65e0\u6cd5\u9000\u56de 15 \u7f8e\u5143\uff0c\u56e0\u4e3a\u6211\u4eec\u73b0\u5728\u53ea\u6709\u4e24\u5f20 10 \u7f8e\u5143\u7684\u949e\u7968\u3002\n\u7531\u4e8e\u4e0d\u662f\u6bcf\u4f4d\u987e\u5ba2\u90fd\u5f97\u5230\u4e86\u6b63\u786e\u7684\u627e\u96f6\uff0c\u6240\u4ee5\u7b54\u6848\u662f false\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= bills.length <= 10000
    • \n\t
    • bills[i] \u4e0d\u662f 5 \u5c31\u662f 10 \u6216\u662f 20 
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool lemonadeChange(vector& bills) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean lemonadeChange(int[] bills) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def lemonadeChange(self, bills):\n \"\"\"\n :type bills: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def lemonadeChange(self, bills: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool lemonadeChange(int* bills, int billsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool LemonadeChange(int[] bills) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} bills\n * @return {boolean}\n */\nvar lemonadeChange = function(bills) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} bills\n# @return {Boolean}\ndef lemonade_change(bills)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func lemonadeChange(_ bills: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func lemonadeChange(bills []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def lemonadeChange(bills: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun lemonadeChange(bills: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn lemonade_change(bills: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $bills\n * @return Boolean\n */\n function lemonadeChange($bills) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function lemonadeChange(bills: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (lemonade-change bills)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0860](https://leetcode-cn.com/problems/lemonade-change)", "[\u67e0\u6aac\u6c34\u627e\u96f6](/solution/0800-0899/0860.Lemonade%20Change/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u7b80\u5355", ""], "md_table_row_en": ["[0860](https://leetcode.com/problems/lemonade-change)", "[Lemonade Change](/solution/0800-0899/0860.Lemonade%20Change/README_EN.md)", "`Greedy`", "Easy", ""]}, {"question_id": "0889", "frontend_question_id": "0859", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/buddy-strings", "url_en": "https://leetcode.com/problems/buddy-strings", "relative_path_cn": "/solution/0800-0899/0859.Buddy%20Strings/README.md", "relative_path_en": "/solution/0800-0899/0859.Buddy%20Strings/README_EN.md", "title_cn": "\u4eb2\u5bc6\u5b57\u7b26\u4e32", "title_en": "Buddy Strings", "question_title_slug": "buddy-strings", "content_en": "

    Given two strings s and goal, return true if you can swap two letters in s so the result is equal to goal, otherwise, return false.

    \n\n

    Swapping letters is defined as taking two indices i and j (0-indexed) such that i != j and swapping the characters at s[i] and s[j].

    \n\n
      \n\t
    • For example, swapping at indices 0 and 2 in "abcd" results in "cbad".
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "ab", goal = "ba"\nOutput: true\nExplanation: You can swap s[0] = 'a' and s[1] = 'b' to get "ba", which is equal to goal.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "ab", goal = "ab"\nOutput: false\nExplanation: The only letters you can swap are s[0] = 'a' and s[1] = 'b', which results in "ba" != goal.\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "aa", goal = "aa"\nOutput: true\nExplanation: You can swap s[0] = 'a' and s[1] = 'a' to get "aa", which is equal to goal.\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "aaaaaaabc", goal = "aaaaaaacb"\nOutput: true\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length, goal.length <= 2 * 104
    • \n\t
    • s and goal consist of lowercase letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u7531\u5c0f\u5199\u5b57\u6bcd\u6784\u6210\u7684\u5b57\u7b26\u4e32\u00a0A\u00a0\u548c\u00a0B\u00a0\uff0c\u53ea\u8981\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4ea4\u6362 A \u4e2d\u7684\u4e24\u4e2a\u5b57\u6bcd\u5f97\u5230\u4e0e B \u76f8\u7b49\u7684\u7ed3\u679c\uff0c\u5c31\u8fd4\u56de\u00a0true\u00a0\uff1b\u5426\u5219\u8fd4\u56de false \u3002

    \n\n

    \u4ea4\u6362\u5b57\u6bcd\u7684\u5b9a\u4e49\u662f\u53d6\u4e24\u4e2a\u4e0b\u6807 i \u548c j \uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\uff0c\u53ea\u8981 i!=j \u5c31\u4ea4\u6362 A[i] \u548c A[j] \u5904\u7684\u5b57\u7b26\u3002\u4f8b\u5982\uff0c\u5728 \"abcd\" \u4e2d\u4ea4\u6362\u4e0b\u6807 0 \u548c\u4e0b\u6807 2 \u7684\u5143\u7d20\u53ef\u4ee5\u751f\u6210 \"cbad\" \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1a A = \"ab\", B = \"ba\"\n\u8f93\u51fa\uff1a true\n\u89e3\u91ca\uff1a \u4f60\u53ef\u4ee5\u4ea4\u6362 A[0] = 'a' \u548c A[1] = 'b' \u751f\u6210 \"ba\"\uff0c\u6b64\u65f6 A \u548c B \u76f8\u7b49\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1a A = \"ab\", B = \"ab\"\n\u8f93\u51fa\uff1a false\n\u89e3\u91ca\uff1a \u4f60\u53ea\u80fd\u4ea4\u6362 A[0] = 'a' \u548c A[1] = 'b' \u751f\u6210 \"ba\"\uff0c\u6b64\u65f6 A \u548c B \u4e0d\u76f8\u7b49\u3002\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \n\u8f93\u5165\uff1a A = \"aa\", B = \"aa\"\n\u8f93\u51fa\uff1a true\n\u89e3\u91ca\uff1a \u4f60\u53ef\u4ee5\u4ea4\u6362 A[0] = 'a' \u548c A[1] = 'a' \u751f\u6210 \"aa\"\uff0c\u6b64\u65f6 A \u548c B \u76f8\u7b49\u3002
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1a A = \"aaaaaaabc\", B = \"aaaaaaacb\"\n\u8f93\u51fa\uff1a true\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1a A = \"\", B = \"aa\"\n\u8f93\u51fa\uff1a false\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 0 <= A.length <= 20000
    2. \n\t
    3. 0 <= B.length <= 20000
    4. \n\t
    5. A\u00a0\u548c\u00a0B\u00a0\u4ec5\u7531\u5c0f\u5199\u5b57\u6bcd\u6784\u6210\u3002
    6. \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool buddyStrings(string s, string goal) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean buddyStrings(String s, String goal) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def buddyStrings(self, s, goal):\n \"\"\"\n :type s: str\n :type goal: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def buddyStrings(self, s: str, goal: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool buddyStrings(char * s, char * goal){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool BuddyStrings(string s, string goal) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string} goal\n * @return {boolean}\n */\nvar buddyStrings = function(s, goal) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String} goal\n# @return {Boolean}\ndef buddy_strings(s, goal)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func buddyStrings(_ s: String, _ goal: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func buddyStrings(s string, goal string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def buddyStrings(s: String, goal: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun buddyStrings(s: String, goal: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn buddy_strings(s: String, goal: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String $goal\n * @return Boolean\n */\n function buddyStrings($s, $goal) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function buddyStrings(s: string, goal: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (buddy-strings s goal)\n (-> string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0859](https://leetcode-cn.com/problems/buddy-strings)", "[\u4eb2\u5bc6\u5b57\u7b26\u4e32](/solution/0800-0899/0859.Buddy%20Strings/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0859](https://leetcode.com/problems/buddy-strings)", "[Buddy Strings](/solution/0800-0899/0859.Buddy%20Strings/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "0888", "frontend_question_id": "0858", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/mirror-reflection", "url_en": "https://leetcode.com/problems/mirror-reflection", "relative_path_cn": "/solution/0800-0899/0858.Mirror%20Reflection/README.md", "relative_path_en": "/solution/0800-0899/0858.Mirror%20Reflection/README_EN.md", "title_cn": "\u955c\u9762\u53cd\u5c04", "title_en": "Mirror Reflection", "question_title_slug": "mirror-reflection", "content_en": "

    There is a special square room with mirrors on each of the four walls.  Except for the southwest corner, there are receptors on each of the remaining corners, numbered 0, 1, and 2.

    \n\n

    The square room has walls of length p, and a laser ray from the southwest corner first meets the east wall at a distance q from the 0th receptor.

    \n\n

    Return the number of the receptor that the ray meets first.  (It is guaranteed that the ray will meet a receptor eventually.)

    \n\n

     

    \n\n
    \n

    Example 1:

    \n\n
    \nInput: p = 2, q = 1\nOutput: 2\nExplanation: The ray meets receptor 2 the first time it gets reflected back to the left wall.\n\"\"\n
    \n\n

    Note:

    \n\n
      \n\t
    1. 1 <= p <= 1000
    2. \n\t
    3. 0 <= q <= p
    4. \n
    \n
    \n", "content_cn": "

    \u6709\u4e00\u4e2a\u7279\u6b8a\u7684\u6b63\u65b9\u5f62\u623f\u95f4\uff0c\u6bcf\u9762\u5899\u4e0a\u90fd\u6709\u4e00\u9762\u955c\u5b50\u3002\u9664\u897f\u5357\u89d2\u4ee5\u5916\uff0c\u6bcf\u4e2a\u89d2\u843d\u90fd\u653e\u6709\u4e00\u4e2a\u63a5\u53d7\u5668\uff0c\u7f16\u53f7\u4e3a\u00a00\uff0c\u00a01\uff0c\u4ee5\u53ca\u00a02\u3002

    \n\n

    \u6b63\u65b9\u5f62\u623f\u95f4\u7684\u5899\u58c1\u957f\u5ea6\u4e3a\u00a0p\uff0c\u4e00\u675f\u6fc0\u5149\u4ece\u897f\u5357\u89d2\u5c04\u51fa\uff0c\u9996\u5148\u4f1a\u4e0e\u4e1c\u5899\u76f8\u9047\uff0c\u5165\u5c04\u70b9\u5230\u63a5\u6536\u5668 0 \u7684\u8ddd\u79bb\u4e3a q \u3002

    \n\n

    \u8fd4\u56de\u5149\u7ebf\u6700\u5148\u9047\u5230\u7684\u63a5\u6536\u5668\u7684\u7f16\u53f7\uff08\u4fdd\u8bc1\u5149\u7ebf\u6700\u7ec8\u4f1a\u9047\u5230\u4e00\u4e2a\u63a5\u6536\u5668\uff09\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1a p = 2, q = 1\n\u8f93\u51fa\uff1a 2\n\u89e3\u91ca\uff1a \u8fd9\u6761\u5149\u7ebf\u5728\u7b2c\u4e00\u6b21\u88ab\u53cd\u5c04\u56de\u5de6\u8fb9\u7684\u5899\u65f6\u5c31\u9047\u5230\u4e86\u63a5\u6536\u5668 2 \u3002\n\"\"
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= p <= 1000
    • \n\t
    • 0 <= q <= p
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int mirrorReflection(int p, int q) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int mirrorReflection(int p, int q) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def mirrorReflection(self, p, q):\n \"\"\"\n :type p: int\n :type q: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def mirrorReflection(self, p: int, q: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint mirrorReflection(int p, int q){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MirrorReflection(int p, int q) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} p\n * @param {number} q\n * @return {number}\n */\nvar mirrorReflection = function(p, q) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} p\n# @param {Integer} q\n# @return {Integer}\ndef mirror_reflection(p, q)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func mirrorReflection(_ p: Int, _ q: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func mirrorReflection(p int, q int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def mirrorReflection(p: Int, q: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun mirrorReflection(p: Int, q: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn mirror_reflection(p: i32, q: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $p\n * @param Integer $q\n * @return Integer\n */\n function mirrorReflection($p, $q) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function mirrorReflection(p: number, q: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (mirror-reflection p q)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0858](https://leetcode-cn.com/problems/mirror-reflection)", "[\u955c\u9762\u53cd\u5c04](/solution/0800-0899/0858.Mirror%20Reflection/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0858](https://leetcode.com/problems/mirror-reflection)", "[Mirror Reflection](/solution/0800-0899/0858.Mirror%20Reflection/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "0887", "frontend_question_id": "0857", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-cost-to-hire-k-workers", "url_en": "https://leetcode.com/problems/minimum-cost-to-hire-k-workers", "relative_path_cn": "/solution/0800-0899/0857.Minimum%20Cost%20to%20Hire%20K%20Workers/README.md", "relative_path_en": "/solution/0800-0899/0857.Minimum%20Cost%20to%20Hire%20K%20Workers/README_EN.md", "title_cn": "\u96c7\u4f63 K \u540d\u5de5\u4eba\u7684\u6700\u4f4e\u6210\u672c", "title_en": "Minimum Cost to Hire K Workers", "question_title_slug": "minimum-cost-to-hire-k-workers", "content_en": "

    There are n workers.  The i-th worker has a quality[i] and a minimum wage expectation wage[i].

    \n\n

    Now we want to hire exactly k workers to form a paid group.  When hiring a group of k workers, we must pay them according to the following rules:

    \n\n
      \n\t
    1. Every worker in the paid group should be paid in the ratio of their quality compared to other workers in the paid group.
    2. \n\t
    3. Every worker in the paid group must be paid at least their minimum wage expectation.
    4. \n
    \n\n

    Return the least amount of money needed to form a paid group satisfying the above conditions.

    \n\n

     

    \n\n
      \n
    \n\n
    \n

    Example 1:

    \n\n
    \nInput: quality = [10,20,5], wage = [70,50,30], k = 2\nOutput: 105.00000\nExplanation: We pay 70 to 0-th worker and 35 to 2-th worker.\n
    \n\n
    \n

    Example 2:

    \n\n
    \nInput: quality = [3,1,10,10,1], wage = [4,8,2,2,7], k = 3\nOutput: 30.66667\nExplanation: We pay 4 to 0-th worker, 13.33333 to 2-th and 3-th workers seperately. \n
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    1. 1 <= k <= n <= 10000, where n = quality.length = wage.length
    2. \n\t
    3. 1 <= quality[i] <= 10000
    4. \n\t
    5. 1 <= wage[i] <= 10000
    6. \n\t
    7. Answers within 10-5 of the correct answer will be considered correct.
    8. \n
    \n
    \n
    \n", "content_cn": "

    \u6709 N \u540d\u5de5\u4eba\u3002 \u7b2c i \u540d\u5de5\u4eba\u7684\u5de5\u4f5c\u8d28\u91cf\u4e3a quality[i] \uff0c\u5176\u6700\u4f4e\u671f\u671b\u5de5\u8d44\u4e3a wage[i] \u3002

    \n\n

    \u73b0\u5728\u6211\u4eec\u60f3\u96c7\u4f63 K \u540d\u5de5\u4eba\u7ec4\u6210\u4e00\u4e2a\u5de5\u8d44\u7ec4\u3002\u5728\u96c7\u4f63 \u4e00\u7ec4 K \u540d\u5de5\u4eba\u65f6\uff0c\u6211\u4eec\u5fc5\u987b\u6309\u7167\u4e0b\u8ff0\u89c4\u5219\u5411\u4ed6\u4eec\u652f\u4ed8\u5de5\u8d44\uff1a

    \n\n
      \n\t
    1. \u5bf9\u5de5\u8d44\u7ec4\u4e2d\u7684\u6bcf\u540d\u5de5\u4eba\uff0c\u5e94\u5f53\u6309\u5176\u5de5\u4f5c\u8d28\u91cf\u4e0e\u540c\u7ec4\u5176\u4ed6\u5de5\u4eba\u7684\u5de5\u4f5c\u8d28\u91cf\u7684\u6bd4\u4f8b\u6765\u652f\u4ed8\u5de5\u8d44\u3002
    2. \n\t
    3. \u5de5\u8d44\u7ec4\u4e2d\u7684\u6bcf\u540d\u5de5\u4eba\u81f3\u5c11\u5e94\u5f53\u5f97\u5230\u4ed6\u4eec\u7684\u6700\u4f4e\u671f\u671b\u5de5\u8d44\u3002
    4. \n
    \n\n

    \u8fd4\u56de\u7ec4\u6210\u4e00\u4e2a\u6ee1\u8db3\u4e0a\u8ff0\u6761\u4ef6\u7684\u5de5\u8d44\u7ec4\u81f3\u5c11\u9700\u8981\u591a\u5c11\u94b1\u3002

    \n\n

     

    \n\n
      \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a quality = [10,20,5], wage = [70,50,30], K = 2\n\u8f93\u51fa\uff1a 105.00000\n\u89e3\u91ca\uff1a \u6211\u4eec\u5411 0 \u53f7\u5de5\u4eba\u652f\u4ed8 70\uff0c\u5411 2 \u53f7\u5de5\u4eba\u652f\u4ed8 35\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a quality = [3,1,10,10,1], wage = [4,8,2,2,7], K = 3\n\u8f93\u51fa\uff1a 30.66667\n\u89e3\u91ca\uff1a \u6211\u4eec\u5411 0 \u53f7\u5de5\u4eba\u652f\u4ed8 4\uff0c\u5411 2 \u53f7\u548c 3 \u53f7\u5206\u522b\u652f\u4ed8 13.33333\u3002
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= K <= N <= 10000\uff0c\u5176\u4e2d N = quality.length = wage.length
    2. \n\t
    3. 1 <= quality[i] <= 10000
    4. \n\t
    5. 1 <= wage[i] <= 10000
    6. \n\t
    7. \u4e0e\u6b63\u786e\u7b54\u6848\u8bef\u5dee\u5728 10^-5 \u4e4b\u5185\u7684\u7b54\u6848\u5c06\u88ab\u89c6\u4e3a\u6b63\u786e\u7684\u3002
    8. \n
    \n", "tags_en": ["Heap"], "tags_cn": ["\u5806"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n double mincostToHireWorkers(vector& quality, vector& wage, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double mincostToHireWorkers(int[] quality, int[] wage, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def mincostToHireWorkers(self, quality, wage, k):\n \"\"\"\n :type quality: List[int]\n :type wage: List[int]\n :type k: int\n :rtype: float\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def mincostToHireWorkers(self, quality: List[int], wage: List[int], k: int) -> float:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\ndouble mincostToHireWorkers(int* quality, int qualitySize, int* wage, int wageSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double MincostToHireWorkers(int[] quality, int[] wage, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} quality\n * @param {number[]} wage\n * @param {number} k\n * @return {number}\n */\nvar mincostToHireWorkers = function(quality, wage, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} quality\n# @param {Integer[]} wage\n# @param {Integer} k\n# @return {Float}\ndef mincost_to_hire_workers(quality, wage, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func mincostToHireWorkers(_ quality: [Int], _ wage: [Int], _ k: Int) -> Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func mincostToHireWorkers(quality []int, wage []int, k int) float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def mincostToHireWorkers(quality: Array[Int], wage: Array[Int], k: Int): Double = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun mincostToHireWorkers(quality: IntArray, wage: IntArray, k: Int): Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn mincost_to_hire_workers(quality: Vec, wage: Vec, k: i32) -> f64 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $quality\n * @param Integer[] $wage\n * @param Integer $k\n * @return Float\n */\n function mincostToHireWorkers($quality, $wage, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function mincostToHireWorkers(quality: number[], wage: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (mincost-to-hire-workers quality wage k)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer? flonum?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0857](https://leetcode-cn.com/problems/minimum-cost-to-hire-k-workers)", "[\u96c7\u4f63 K \u540d\u5de5\u4eba\u7684\u6700\u4f4e\u6210\u672c](/solution/0800-0899/0857.Minimum%20Cost%20to%20Hire%20K%20Workers/README.md)", "`\u5806`", "\u56f0\u96be", ""], "md_table_row_en": ["[0857](https://leetcode.com/problems/minimum-cost-to-hire-k-workers)", "[Minimum Cost to Hire K Workers](/solution/0800-0899/0857.Minimum%20Cost%20to%20Hire%20K%20Workers/README_EN.md)", "`Heap`", "Hard", ""]}, {"question_id": "0886", "frontend_question_id": "0856", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/score-of-parentheses", "url_en": "https://leetcode.com/problems/score-of-parentheses", "relative_path_cn": "/solution/0800-0899/0856.Score%20of%20Parentheses/README.md", "relative_path_en": "/solution/0800-0899/0856.Score%20of%20Parentheses/README_EN.md", "title_cn": "\u62ec\u53f7\u7684\u5206\u6570", "title_en": "Score of Parentheses", "question_title_slug": "score-of-parentheses", "content_en": "

    Given a balanced parentheses string s, compute the score of the string based on the following rule:

    \n\n
      \n\t
    • () has score 1
    • \n\t
    • AB has score A + B, where A and B are balanced parentheses strings.
    • \n\t
    • (A) has score 2 * A, where A is a balanced parentheses string.
    • \n
    \n\n

     

    \n\n

    Example 1:

    \n\n
    \nInput: s = "()"\nOutput: 1\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "(())"\nOutput: 2\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "()()"\nOutput: 2\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "(()(()))"\nOutput: 6\n
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    1. s is a balanced parentheses string, containing only ( and ).
    2. \n\t
    3. 2 <= s.length <= 50
    4. \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5e73\u8861\u62ec\u53f7\u5b57\u7b26\u4e32 S\uff0c\u6309\u4e0b\u8ff0\u89c4\u5219\u8ba1\u7b97\u8be5\u5b57\u7b26\u4e32\u7684\u5206\u6570\uff1a

    \n\n
      \n\t
    • () \u5f97 1 \u5206\u3002
    • \n\t
    • AB \u5f97 A + B \u5206\uff0c\u5176\u4e2d A \u548c B \u662f\u5e73\u8861\u62ec\u53f7\u5b57\u7b26\u4e32\u3002
    • \n\t
    • (A) \u5f97 2 * A \u5206\uff0c\u5176\u4e2d A \u662f\u5e73\u8861\u62ec\u53f7\u5b57\u7b26\u4e32\u3002
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a "()"\n\u8f93\u51fa\uff1a 1\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a "(())"\n\u8f93\u51fa\uff1a 2\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1a "()()"\n\u8f93\u51fa\uff1a 2\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1a "(()(()))"\n\u8f93\u51fa\uff1a 6\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. S \u662f\u5e73\u8861\u62ec\u53f7\u5b57\u7b26\u4e32\uff0c\u4e14\u53ea\u542b\u6709 ( \u548c ) \u3002
    2. \n\t
    3. 2 <= S.length <= 50
    4. \n
    \n", "tags_en": ["Stack", "String"], "tags_cn": ["\u6808", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int scoreOfParentheses(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int scoreOfParentheses(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def scoreOfParentheses(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def scoreOfParentheses(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint scoreOfParentheses(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ScoreOfParentheses(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar scoreOfParentheses = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef score_of_parentheses(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func scoreOfParentheses(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func scoreOfParentheses(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def scoreOfParentheses(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun scoreOfParentheses(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn score_of_parentheses(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function scoreOfParentheses($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function scoreOfParentheses(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (score-of-parentheses s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0856](https://leetcode-cn.com/problems/score-of-parentheses)", "[\u62ec\u53f7\u7684\u5206\u6570](/solution/0800-0899/0856.Score%20of%20Parentheses/README.md)", "`\u6808`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0856](https://leetcode.com/problems/score-of-parentheses)", "[Score of Parentheses](/solution/0800-0899/0856.Score%20of%20Parentheses/README_EN.md)", "`Stack`,`String`", "Medium", ""]}, {"question_id": "0885", "frontend_question_id": "0855", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/exam-room", "url_en": "https://leetcode.com/problems/exam-room", "relative_path_cn": "/solution/0800-0899/0855.Exam%20Room/README.md", "relative_path_en": "/solution/0800-0899/0855.Exam%20Room/README_EN.md", "title_cn": "\u8003\u573a\u5c31\u5ea7", "title_en": "Exam Room", "question_title_slug": "exam-room", "content_en": "

    In an exam room, there are n seats in a single row, numbered 0, 1, 2, ..., n-1.

    \n\n

    When a student enters the room, they must sit in the seat that maximizes the distance to the closest person.  If there are multiple such seats, they sit in the seat with the lowest number.  (Also, if no one is in the room, then the student sits at seat number 0.)

    \n\n

    Return a class ExamRoom(int n) that exposes two functions: ExamRoom.seat() returning an int representing what seat the student sat in, and ExamRoom.leave(int p) representing that the student in seat number p now leaves the room.  It is guaranteed that any calls to ExamRoom.leave(p) have a student sitting in seat p.

    \n\n

     

    \n\n

    Example 1:

    \n\n
    \nInput: ["ExamRoom","seat","seat","seat","seat","leave","seat"], [[10],[],[],[],[],[4],[]]\nOutput: [null,0,9,4,2,null,5]\nExplanation:\nExamRoom(10) -> null\nseat() -> 0, no one is in the room, then the student sits at seat number 0.\nseat() -> 9, the student sits at the last seat number 9.\nseat() -> 4, the student sits at the last seat number 4.\nseat() -> 2, the student sits at the last seat number 2.\nleave(4) -> null\nseat() -> 5, the student sits at the last seat number 5.\n
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    1. 1 <= n <= 109
    2. \n\t
    3. ExamRoom.seat() and ExamRoom.leave() will be called at most 104 times across all test cases.
    4. \n\t
    5. Calls to ExamRoom.leave(p) are guaranteed to have a student currently sitting in seat number p.
    6. \n
    \n", "content_cn": "

    \u5728\u8003\u573a\u91cc\uff0c\u4e00\u6392\u6709 N \u4e2a\u5ea7\u4f4d\uff0c\u5206\u522b\u7f16\u53f7\u4e3a 0, 1, 2, ..., N-1 \u3002

    \n\n

    \u5f53\u5b66\u751f\u8fdb\u5165\u8003\u573a\u540e\uff0c\u4ed6\u5fc5\u987b\u5750\u5728\u80fd\u591f\u4f7f\u4ed6\u4e0e\u79bb\u4ed6\u6700\u8fd1\u7684\u4eba\u4e4b\u95f4\u7684\u8ddd\u79bb\u8fbe\u5230\u6700\u5927\u5316\u7684\u5ea7\u4f4d\u4e0a\u3002\u5982\u679c\u6709\u591a\u4e2a\u8fd9\u6837\u7684\u5ea7\u4f4d\uff0c\u4ed6\u4f1a\u5750\u5728\u7f16\u53f7\u6700\u5c0f\u7684\u5ea7\u4f4d\u4e0a\u3002(\u53e6\u5916\uff0c\u5982\u679c\u8003\u573a\u91cc\u6ca1\u6709\u4eba\uff0c\u90a3\u4e48\u5b66\u751f\u5c31\u5750\u5728 0 \u53f7\u5ea7\u4f4d\u4e0a\u3002)

    \n\n

    \u8fd4\u56de ExamRoom(int N) \u7c7b\uff0c\u5b83\u6709\u4e24\u4e2a\u516c\u5f00\u7684\u51fd\u6570\uff1a\u5176\u4e2d\uff0c\u51fd\u6570 ExamRoom.seat() \u4f1a\u8fd4\u56de\u4e00\u4e2a int \uff08\u6574\u578b\u6570\u636e\uff09\uff0c\u4ee3\u8868\u5b66\u751f\u5750\u7684\u4f4d\u7f6e\uff1b\u51fd\u6570 ExamRoom.leave(int p) \u4ee3\u8868\u5750\u5728\u5ea7\u4f4d p \u4e0a\u7684\u5b66\u751f\u73b0\u5728\u79bb\u5f00\u4e86\u8003\u573a\u3002\u6bcf\u6b21\u8c03\u7528 ExamRoom.leave(p) \u65f6\u90fd\u4fdd\u8bc1\u6709\u5b66\u751f\u5750\u5728\u5ea7\u4f4d p \u4e0a\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1a["ExamRoom","seat","seat","seat","seat","leave","seat"], [[10],[],[],[],[],[4],[]]\n\u8f93\u51fa\uff1a[null,0,9,4,2,null,5]\n\u89e3\u91ca\uff1a\nExamRoom(10) -> null\nseat() -> 0\uff0c\u6ca1\u6709\u4eba\u5728\u8003\u573a\u91cc\uff0c\u90a3\u4e48\u5b66\u751f\u5750\u5728 0 \u53f7\u5ea7\u4f4d\u4e0a\u3002\nseat() -> 9\uff0c\u5b66\u751f\u6700\u540e\u5750\u5728 9 \u53f7\u5ea7\u4f4d\u4e0a\u3002\nseat() -> 4\uff0c\u5b66\u751f\u6700\u540e\u5750\u5728 4 \u53f7\u5ea7\u4f4d\u4e0a\u3002\nseat() -> 2\uff0c\u5b66\u751f\u6700\u540e\u5750\u5728 2 \u53f7\u5ea7\u4f4d\u4e0a\u3002\nleave(4) -> null\nseat() -> 5\uff0c\u5b66\u751f\u6700\u540e\u5750\u5728 5 \u53f7\u5ea7\u4f4d\u4e0a\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= N <= 10^9
    2. \n\t
    3. \u5728\u6240\u6709\u7684\u6d4b\u8bd5\u6837\u4f8b\u4e2d ExamRoom.seat() \u548c ExamRoom.leave() \u6700\u591a\u88ab\u8c03\u7528 10^4 \u6b21\u3002
    4. \n\t
    5. \u4fdd\u8bc1\u5728\u8c03\u7528 ExamRoom.leave(p) \u65f6\u6709\u5b66\u751f\u6b63\u5750\u5728\u5ea7\u4f4d p \u4e0a\u3002
    6. \n
    \n", "tags_en": ["Ordered Map"], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class ExamRoom {\npublic:\n ExamRoom(int n) {\n\n }\n \n int seat() {\n\n }\n \n void leave(int p) {\n\n }\n};\n\n/**\n * Your ExamRoom object will be instantiated and called as such:\n * ExamRoom* obj = new ExamRoom(n);\n * int param_1 = obj->seat();\n * obj->leave(p);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class ExamRoom {\n\n public ExamRoom(int n) {\n\n }\n \n public int seat() {\n\n }\n \n public void leave(int p) {\n\n }\n}\n\n/**\n * Your ExamRoom object will be instantiated and called as such:\n * ExamRoom obj = new ExamRoom(n);\n * int param_1 = obj.seat();\n * obj.leave(p);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class ExamRoom(object):\n\n def __init__(self, n):\n \"\"\"\n :type n: int\n \"\"\"\n\n\n def seat(self):\n \"\"\"\n :rtype: int\n \"\"\"\n\n\n def leave(self, p):\n \"\"\"\n :type p: int\n :rtype: None\n \"\"\"\n\n\n\n# Your ExamRoom object will be instantiated and called as such:\n# obj = ExamRoom(n)\n# param_1 = obj.seat()\n# obj.leave(p)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class ExamRoom:\n\n def __init__(self, n: int):\n\n\n def seat(self) -> int:\n\n\n def leave(self, p: int) -> None:\n\n\n\n# Your ExamRoom object will be instantiated and called as such:\n# obj = ExamRoom(n)\n# param_1 = obj.seat()\n# obj.leave(p)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} ExamRoom;\n\n\nExamRoom* examRoomCreate(int n) {\n\n}\n\nint examRoomSeat(ExamRoom* obj) {\n\n}\n\nvoid examRoomLeave(ExamRoom* obj, int p) {\n\n}\n\nvoid examRoomFree(ExamRoom* obj) {\n\n}\n\n/**\n * Your ExamRoom struct will be instantiated and called as such:\n * ExamRoom* obj = examRoomCreate(n);\n * int param_1 = examRoomSeat(obj);\n \n * examRoomLeave(obj, p);\n \n * examRoomFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class ExamRoom {\n\n public ExamRoom(int n) {\n\n }\n \n public int Seat() {\n\n }\n \n public void Leave(int p) {\n\n }\n}\n\n/**\n * Your ExamRoom object will be instantiated and called as such:\n * ExamRoom obj = new ExamRoom(n);\n * int param_1 = obj.Seat();\n * obj.Leave(p);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n */\nvar ExamRoom = function(n) {\n\n};\n\n/**\n * @return {number}\n */\nExamRoom.prototype.seat = function() {\n\n};\n\n/** \n * @param {number} p\n * @return {void}\n */\nExamRoom.prototype.leave = function(p) {\n\n};\n\n/**\n * Your ExamRoom object will be instantiated and called as such:\n * var obj = new ExamRoom(n)\n * var param_1 = obj.seat()\n * obj.leave(p)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class ExamRoom\n\n=begin\n :type n: Integer\n=end\n def initialize(n)\n\n end\n\n\n=begin\n :rtype: Integer\n=end\n def seat()\n\n end\n\n\n=begin\n :type p: Integer\n :rtype: Void\n=end\n def leave(p)\n\n end\n\n\nend\n\n# Your ExamRoom object will be instantiated and called as such:\n# obj = ExamRoom.new(n)\n# param_1 = obj.seat()\n# obj.leave(p)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass ExamRoom {\n\n init(_ n: Int) {\n\n }\n \n func seat() -> Int {\n\n }\n \n func leave(_ p: Int) {\n\n }\n}\n\n/**\n * Your ExamRoom object will be instantiated and called as such:\n * let obj = ExamRoom(n)\n * let ret_1: Int = obj.seat()\n * obj.leave(p)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type ExamRoom struct {\n\n}\n\n\nfunc Constructor(n int) ExamRoom {\n\n}\n\n\nfunc (this *ExamRoom) Seat() int {\n\n}\n\n\nfunc (this *ExamRoom) Leave(p int) {\n\n}\n\n\n/**\n * Your ExamRoom object will be instantiated and called as such:\n * obj := Constructor(n);\n * param_1 := obj.Seat();\n * obj.Leave(p);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class ExamRoom(_n: Int) {\n\n def seat(): Int = {\n\n }\n\n def leave(p: Int) {\n\n }\n\n}\n\n/**\n * Your ExamRoom object will be instantiated and called as such:\n * var obj = new ExamRoom(n)\n * var param_1 = obj.seat()\n * obj.leave(p)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class ExamRoom(n: Int) {\n\n fun seat(): Int {\n\n }\n\n fun leave(p: Int) {\n\n }\n\n}\n\n/**\n * Your ExamRoom object will be instantiated and called as such:\n * var obj = ExamRoom(n)\n * var param_1 = obj.seat()\n * obj.leave(p)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct ExamRoom {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl ExamRoom {\n\n fn new(n: i32) -> Self {\n\n }\n \n fn seat(&self) -> i32 {\n\n }\n \n fn leave(&self, p: i32) {\n\n }\n}\n\n/**\n * Your ExamRoom object will be instantiated and called as such:\n * let obj = ExamRoom::new(n);\n * let ret_1: i32 = obj.seat();\n * obj.leave(p);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class ExamRoom {\n /**\n * @param Integer $n\n */\n function __construct($n) {\n\n }\n\n /**\n * @return Integer\n */\n function seat() {\n\n }\n\n /**\n * @param Integer $p\n * @return NULL\n */\n function leave($p) {\n\n }\n}\n\n/**\n * Your ExamRoom object will be instantiated and called as such:\n * $obj = ExamRoom($n);\n * $ret_1 = $obj->seat();\n * $obj->leave($p);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class ExamRoom {\n constructor(n: number) {\n\n }\n\n seat(): number {\n\n }\n\n leave(p: number): void {\n\n }\n}\n\n/**\n * Your ExamRoom object will be instantiated and called as such:\n * var obj = new ExamRoom(n)\n * var param_1 = obj.seat()\n * obj.leave(p)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define exam-room%\n (class object%\n (super-new)\n\n ; n : exact-integer?\n (init-field\n n)\n \n ; seat : -> exact-integer?\n (define/public (seat)\n\n )\n ; leave : exact-integer? -> void?\n (define/public (leave p)\n\n )))\n\n;; Your exam-room% object will be instantiated and called as such:\n;; (define obj (new exam-room% [n n]))\n;; (define param_1 (send obj seat))\n;; (send obj leave p)", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0855](https://leetcode-cn.com/problems/exam-room)", "[\u8003\u573a\u5c31\u5ea7](/solution/0800-0899/0855.Exam%20Room/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0855](https://leetcode.com/problems/exam-room)", "[Exam Room](/solution/0800-0899/0855.Exam%20Room/README_EN.md)", "`Ordered Map`", "Medium", ""]}, {"question_id": "0884", "frontend_question_id": "0854", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/k-similar-strings", "url_en": "https://leetcode.com/problems/k-similar-strings", "relative_path_cn": "/solution/0800-0899/0854.K-Similar%20Strings/README.md", "relative_path_en": "/solution/0800-0899/0854.K-Similar%20Strings/README_EN.md", "title_cn": "\u76f8\u4f3c\u5ea6\u4e3a K \u7684\u5b57\u7b26\u4e32", "title_en": "K-Similar Strings", "question_title_slug": "k-similar-strings", "content_en": "

    Strings s1 and s2 are k-similar (for some non-negative integer k) if we can swap the positions of two letters in s1 exactly k times so that the resulting string equals s2.

    \n\n

    Given two anagrams s1 and s2, return the smallest k for which s1 and s2 are k-similar.

    \n\n

     

    \n

    Example 1:

    \n
    Input: s1 = \"ab\", s2 = \"ba\"\nOutput: 1\n

    Example 2:

    \n
    Input: s1 = \"abc\", s2 = \"bca\"\nOutput: 2\n

    Example 3:

    \n
    Input: s1 = \"abac\", s2 = \"baca\"\nOutput: 2\n

    Example 4:

    \n
    Input: s1 = \"aabc\", s2 = \"abca\"\nOutput: 2\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s1.length <= 20
    • \n\t
    • s2.length == s1.length
    • \n\t
    • s1 and s2 contain only lowercase letters from the set {'a', 'b', 'c', 'd', 'e', 'f'}.
    • \n\t
    • s2 is an anagram of s1.
    • \n
    \n", "content_cn": "

    \u5982\u679c\u53ef\u4ee5\u901a\u8fc7\u5c06 A \u4e2d\u7684\u4e24\u4e2a\u5c0f\u5199\u5b57\u6bcd\u7cbe\u786e\u5730\u4ea4\u6362\u4f4d\u7f6e K \u6b21\u5f97\u5230\u4e0e B \u76f8\u7b49\u7684\u5b57\u7b26\u4e32\uff0c\u6211\u4eec\u79f0\u5b57\u7b26\u4e32 A \u548c B \u7684\u76f8\u4f3c\u5ea6\u4e3a K\uff08K \u4e3a\u975e\u8d1f\u6574\u6570\uff09\u3002

    \n\n

    \u7ed9\u5b9a\u4e24\u4e2a\u5b57\u6bcd\u5f02\u4f4d\u8bcd A \u548c B \uff0c\u8fd4\u56de A \u548c B \u7684\u76f8\u4f3c\u5ea6 K \u7684\u6700\u5c0f\u503c\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aA = "ab", B = "ba"\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aA = "abc", B = "bca"\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aA = "abac", B = "baca"\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1aA = "aabc", B = "abca"\n\u8f93\u51fa\uff1a2
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= A.length == B.length <= 20
    2. \n\t
    3. A \u548c B \u53ea\u5305\u542b\u96c6\u5408 {'a', 'b', 'c', 'd', 'e', 'f'} \u4e2d\u7684\u5c0f\u5199\u5b57\u6bcd\u3002
    4. \n
    \n", "tags_en": ["Breadth-first Search", "Graph"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u56fe"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int kSimilarity(string s1, string s2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int kSimilarity(String s1, String s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def kSimilarity(self, s1, s2):\n \"\"\"\n :type s1: str\n :type s2: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def kSimilarity(self, s1: str, s2: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint kSimilarity(char * s1, char * s2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int KSimilarity(string s1, string s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s1\n * @param {string} s2\n * @return {number}\n */\nvar kSimilarity = function(s1, s2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s1\n# @param {String} s2\n# @return {Integer}\ndef k_similarity(s1, s2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func kSimilarity(_ s1: String, _ s2: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func kSimilarity(s1 string, s2 string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def kSimilarity(s1: String, s2: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun kSimilarity(s1: String, s2: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn k_similarity(s1: String, s2: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s1\n * @param String $s2\n * @return Integer\n */\n function kSimilarity($s1, $s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function kSimilarity(s1: string, s2: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (k-similarity s1 s2)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0854](https://leetcode-cn.com/problems/k-similar-strings)", "[\u76f8\u4f3c\u5ea6\u4e3a K \u7684\u5b57\u7b26\u4e32](/solution/0800-0899/0854.K-Similar%20Strings/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u56fe`", "\u56f0\u96be", ""], "md_table_row_en": ["[0854](https://leetcode.com/problems/k-similar-strings)", "[K-Similar Strings](/solution/0800-0899/0854.K-Similar%20Strings/README_EN.md)", "`Breadth-first Search`,`Graph`", "Hard", ""]}, {"question_id": "0883", "frontend_question_id": "0853", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/car-fleet", "url_en": "https://leetcode.com/problems/car-fleet", "relative_path_cn": "/solution/0800-0899/0853.Car%20Fleet/README.md", "relative_path_en": "/solution/0800-0899/0853.Car%20Fleet/README_EN.md", "title_cn": "\u8f66\u961f", "title_en": "Car Fleet", "question_title_slug": "car-fleet", "content_en": "

    N cars are going to the same destination along a one lane road.  The destination is target miles away.

    \r\n\r\n

    Each car i has a constant speed speed[i] (in miles per hour), and initial position position[i] miles towards the target along the road.

    \r\n\r\n

    A car can never pass another car ahead of it, but it can catch up to it, and drive bumper to bumper at the same speed.

    \r\n\r\n

    The distance between these two cars is ignored - they are assumed to have the same position.

    \r\n\r\n

    A car fleet is some non-empty set of cars driving at the same position and same speed.  Note that a single car is also a car fleet.

    \r\n\r\n

    If a car catches up to a car fleet right at the destination point, it will still be considered as one car fleet.

    \r\n\r\n


    \r\nHow many car fleets will arrive at the destination?

    \r\n\r\n

     

    \r\n\r\n

    Example 1:

    \r\n\r\n
    \r\nInput: target = 12, position = [10,8,0,5,3], speed = [2,4,1,1,3]\r\nOutput: 3\r\nExplanation:\r\nThe cars starting at 10 and 8 become a fleet, meeting each other at 12.\r\nThe car starting at 0 doesn't catch up to any other car, so it is a fleet by itself.\r\nThe cars starting at 5 and 3 become a fleet, meeting each other at 6.\r\nNote that no other cars meet these fleets before the destination, so the answer is 3.\r\n
    \r\n\r\n


    \r\nNote:

    \r\n\r\n
      \r\n\t
    1. 0 <= N <= 10 ^ 4
    2. \r\n\t
    3. 0 < target <= 10 ^ 6
    4. \r\n\t
    5. 0 < speed[i] <= 10 ^ 6
    6. \r\n\t
    7. 0 <= position[i] < target
    8. \r\n\t
    9. All initial positions are different.
    10. \r\n
    ", "content_cn": "

    N  \u8f86\u8f66\u6cbf\u7740\u4e00\u6761\u8f66\u9053\u9a76\u5411\u4f4d\u4e8e target \u82f1\u91cc\u4e4b\u5916\u7684\u5171\u540c\u76ee\u7684\u5730\u3002

    \n\n

    \u6bcf\u8f86\u8f66 i \u4ee5\u6052\u5b9a\u7684\u901f\u5ea6 speed[i] \uff08\u82f1\u91cc/\u5c0f\u65f6\uff09\uff0c\u4ece\u521d\u59cb\u4f4d\u7f6e position[i] \uff08\u82f1\u91cc\uff09 \u6cbf\u8f66\u9053\u9a76\u5411\u76ee\u7684\u5730\u3002

    \n\n

    \u4e00\u8f86\u8f66\u6c38\u8fdc\u4e0d\u4f1a\u8d85\u8fc7\u524d\u9762\u7684\u53e6\u4e00\u8f86\u8f66\uff0c\u4f46\u5b83\u53ef\u4ee5\u8ffd\u4e0a\u53bb\uff0c\u5e76\u4e0e\u524d\u8f66\u4ee5\u76f8\u540c\u7684\u901f\u5ea6\u7d27\u63a5\u7740\u884c\u9a76\u3002

    \n\n

    \u6b64\u65f6\uff0c\u6211\u4eec\u4f1a\u5ffd\u7565\u8fd9\u4e24\u8f86\u8f66\u4e4b\u95f4\u7684\u8ddd\u79bb\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u5b83\u4eec\u88ab\u5047\u5b9a\u5904\u4e8e\u76f8\u540c\u7684\u4f4d\u7f6e\u3002

    \n\n

    \u8f66\u961f \u662f\u4e00\u4e9b\u7531\u884c\u9a76\u5728\u76f8\u540c\u4f4d\u7f6e\u3001\u5177\u6709\u76f8\u540c\u901f\u5ea6\u7684\u8f66\u7ec4\u6210\u7684\u975e\u7a7a\u96c6\u5408\u3002\u6ce8\u610f\uff0c\u4e00\u8f86\u8f66\u4e5f\u53ef\u4ee5\u662f\u4e00\u4e2a\u8f66\u961f\u3002

    \n\n

    \u5373\u4fbf\u4e00\u8f86\u8f66\u5728\u76ee\u7684\u5730\u624d\u8d76\u4e0a\u4e86\u4e00\u4e2a\u8f66\u961f\uff0c\u5b83\u4eec\u4ecd\u7136\u4f1a\u88ab\u89c6\u4f5c\u662f\u540c\u4e00\u4e2a\u8f66\u961f\u3002

    \n\n

     

    \n\n

    \u4f1a\u6709\u591a\u5c11\u8f66\u961f\u5230\u8fbe\u76ee\u7684\u5730?

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1atarget = 12, position = [10,8,0,5,3], speed = [2,4,1,1,3]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\n\u4ece 10 \u548c 8 \u5f00\u59cb\u7684\u8f66\u4f1a\u7ec4\u6210\u4e00\u4e2a\u8f66\u961f\uff0c\u5b83\u4eec\u5728 12 \u5904\u76f8\u9047\u3002\n\u4ece 0 \u5904\u5f00\u59cb\u7684\u8f66\u65e0\u6cd5\u8ffd\u4e0a\u5176\u5b83\u8f66\uff0c\u6240\u4ee5\u5b83\u81ea\u5df1\u5c31\u662f\u4e00\u4e2a\u8f66\u961f\u3002\n\u4ece 5 \u548c 3 \u5f00\u59cb\u7684\u8f66\u4f1a\u7ec4\u6210\u4e00\u4e2a\u8f66\u961f\uff0c\u5b83\u4eec\u5728 6 \u5904\u76f8\u9047\u3002\n\u8bf7\u6ce8\u610f\uff0c\u5728\u5230\u8fbe\u76ee\u7684\u5730\u4e4b\u524d\u6ca1\u6709\u5176\u5b83\u8f66\u4f1a\u9047\u5230\u8fd9\u4e9b\u8f66\u961f\uff0c\u6240\u4ee5\u7b54\u6848\u662f 3\u3002\n
    \n\n


    \n\u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 0 <= N <= 10 ^ 4
    2. \n\t
    3. 0 < target <= 10 ^ 6
    4. \n\t
    5. 0 < speed[i] <= 10 ^ 6
    6. \n\t
    7. 0 <= position[i] < target
    8. \n\t
    9. \u6240\u6709\u8f66\u7684\u521d\u59cb\u4f4d\u7f6e\u5404\u4e0d\u76f8\u540c\u3002
    10. \n
    \n", "tags_en": ["Sort"], "tags_cn": ["\u6392\u5e8f"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int carFleet(int target, vector& position, vector& speed) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int carFleet(int target, int[] position, int[] speed) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def carFleet(self, target, position, speed):\n \"\"\"\n :type target: int\n :type position: List[int]\n :type speed: List[int]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def carFleet(self, target: int, position: List[int], speed: List[int]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint carFleet(int target, int* position, int positionSize, int* speed, int speedSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CarFleet(int target, int[] position, int[] speed) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} target\n * @param {number[]} position\n * @param {number[]} speed\n * @return {number}\n */\nvar carFleet = function(target, position, speed) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} target\n# @param {Integer[]} position\n# @param {Integer[]} speed\n# @return {Integer}\ndef car_fleet(target, position, speed)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func carFleet(_ target: Int, _ position: [Int], _ speed: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func carFleet(target int, position []int, speed []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def carFleet(target: Int, position: Array[Int], speed: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun carFleet(target: Int, position: IntArray, speed: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn car_fleet(target: i32, position: Vec, speed: Vec) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $target\n * @param Integer[] $position\n * @param Integer[] $speed\n * @return Integer\n */\n function carFleet($target, $position, $speed) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function carFleet(target: number, position: number[], speed: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (car-fleet target position speed)\n (-> exact-integer? (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0853](https://leetcode-cn.com/problems/car-fleet)", "[\u8f66\u961f](/solution/0800-0899/0853.Car%20Fleet/README.md)", "`\u6392\u5e8f`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0853](https://leetcode.com/problems/car-fleet)", "[Car Fleet](/solution/0800-0899/0853.Car%20Fleet/README_EN.md)", "`Sort`", "Medium", ""]}, {"question_id": "0882", "frontend_question_id": "0852", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/peak-index-in-a-mountain-array", "url_en": "https://leetcode.com/problems/peak-index-in-a-mountain-array", "relative_path_cn": "/solution/0800-0899/0852.Peak%20Index%20in%20a%20Mountain%20Array/README.md", "relative_path_en": "/solution/0800-0899/0852.Peak%20Index%20in%20a%20Mountain%20Array/README_EN.md", "title_cn": "\u5c71\u8109\u6570\u7ec4\u7684\u5cf0\u9876\u7d22\u5f15", "title_en": "Peak Index in a Mountain Array", "question_title_slug": "peak-index-in-a-mountain-array", "content_en": "

    Let's call an array arr a mountain if the following properties hold:

    \n\n
      \n\t
    • arr.length >= 3
    • \n\t
    • There exists some i with 0 < i < arr.length - 1 such that:\n\t
        \n\t\t
      • arr[0] < arr[1] < ... arr[i-1] < arr[i]
      • \n\t\t
      • arr[i] > arr[i+1] > ... > arr[arr.length - 1]
      • \n\t
      \n\t
    • \n
    \n\n

    Given an integer array arr that is guaranteed to be a mountain, return any i such that arr[0] < arr[1] < ... arr[i - 1] < arr[i] > arr[i + 1] > ... > arr[arr.length - 1].

    \n\n

     

    \n

    Example 1:

    \n
    Input: arr = [0,1,0]\nOutput: 1\n

    Example 2:

    \n
    Input: arr = [0,2,1,0]\nOutput: 1\n

    Example 3:

    \n
    Input: arr = [0,10,5,2]\nOutput: 1\n

    Example 4:

    \n
    Input: arr = [3,4,5,1]\nOutput: 2\n

    Example 5:

    \n
    Input: arr = [24,69,100,99,79,78,67,36,26,19]\nOutput: 2\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 3 <= arr.length <= 104
    • \n\t
    • 0 <= arr[i] <= 106
    • \n\t
    • arr is guaranteed to be a mountain array.
    • \n
    \n\n

     

    \nFollow up: Finding the O(n) is straightforward, could you find an O(log(n)) solution?", "content_cn": "\u7b26\u5408\u4e0b\u5217\u5c5e\u6027\u7684\u6570\u7ec4 arr \u79f0\u4e3a \u5c71\u8109\u6570\u7ec4 \uff1a\n
      \n\t
    • arr.length >= 3
    • \n\t
    • \u5b58\u5728 i\uff080 < i\u00a0< arr.length - 1\uff09\u4f7f\u5f97\uff1a\n\t
        \n\t\t
      • arr[0] < arr[1] < ... arr[i-1] < arr[i]
      • \n\t\t
      • arr[i] > arr[i+1] > ... > arr[arr.length - 1]
      • \n\t
      \n\t
    • \n
    \n\n

    \u7ed9\u4f60\u7531\u6574\u6570\u7ec4\u6210\u7684\u5c71\u8109\u6570\u7ec4 arr \uff0c\u8fd4\u56de\u4efb\u4f55\u6ee1\u8db3 arr[0] < arr[1] < ... arr[i - 1] < arr[i] > arr[i + 1] > ... > arr[arr.length - 1] \u7684\u4e0b\u6807 i \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [0,1,0]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [0,2,1,0]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [0,10,5,2]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [3,4,5,1]\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [24,69,100,99,79,78,67,36,26,19]\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 3 <= arr.length <= 104
    • \n\t
    • 0 <= arr[i] <= 106
    • \n\t
    • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1 arr \u662f\u4e00\u4e2a\u5c71\u8109\u6570\u7ec4
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u5f88\u5bb9\u6613\u60f3\u5230\u65f6\u95f4\u590d\u6742\u5ea6 O(n) \u7684\u89e3\u51b3\u65b9\u6848\uff0c\u4f60\u53ef\u4ee5\u8bbe\u8ba1\u4e00\u4e2a O(log(n)) \u7684\u89e3\u51b3\u65b9\u6848\u5417\uff1f

    \n", "tags_en": ["Binary Search"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int peakIndexInMountainArray(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int peakIndexInMountainArray(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def peakIndexInMountainArray(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def peakIndexInMountainArray(self, arr: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint peakIndexInMountainArray(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int PeakIndexInMountainArray(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar peakIndexInMountainArray = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef peak_index_in_mountain_array(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func peakIndexInMountainArray(_ arr: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func peakIndexInMountainArray(arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def peakIndexInMountainArray(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun peakIndexInMountainArray(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn peak_index_in_mountain_array(arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function peakIndexInMountainArray($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function peakIndexInMountainArray(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (peak-index-in-mountain-array arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0852](https://leetcode-cn.com/problems/peak-index-in-a-mountain-array)", "[\u5c71\u8109\u6570\u7ec4\u7684\u5cf0\u9876\u7d22\u5f15](/solution/0800-0899/0852.Peak%20Index%20in%20a%20Mountain%20Array/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u7b80\u5355", ""], "md_table_row_en": ["[0852](https://leetcode.com/problems/peak-index-in-a-mountain-array)", "[Peak Index in a Mountain Array](/solution/0800-0899/0852.Peak%20Index%20in%20a%20Mountain%20Array/README_EN.md)", "`Binary Search`", "Easy", ""]}, {"question_id": "0881", "frontend_question_id": "0851", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/loud-and-rich", "url_en": "https://leetcode.com/problems/loud-and-rich", "relative_path_cn": "/solution/0800-0899/0851.Loud%20and%20Rich/README.md", "relative_path_en": "/solution/0800-0899/0851.Loud%20and%20Rich/README_EN.md", "title_cn": "\u55a7\u95f9\u548c\u5bcc\u6709", "title_en": "Loud and Rich", "question_title_slug": "loud-and-rich", "content_en": "

    In a group of N people (labelled 0, 1, 2, ..., N-1), each person has different amounts of money, and different levels of quietness.

    \r\n\r\n

    For convenience, we'll call the person with label x, simply "person x".

    \r\n\r\n

    We'll say that richer[i] = [x, y] if person x definitely has more money than person y.  Note that richer may only be a subset of valid observations.

    \r\n\r\n

    Also, we'll say quiet[x] = q if person x has quietness q.

    \r\n\r\n

    Now, return answer, where answer[x] = y if y is the least quiet person (that is, the person y with the smallest value of quiet[y]), among all people who definitely have equal to or more money than person x.

    \r\n\r\n

     

    \r\n\r\n
    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: richer = [[1,0],[2,1],[3,1],[3,7],[4,3],[5,3],[6,3]], quiet = [3,2,5,4,6,1,7,0]\r\nOutput: [5,5,2,5,4,5,6,7]\r\nExplanation: \r\nanswer[0] = 5.\r\nPerson 5 has more money than 3, which has more money than 1, which has more money than 0.\r\nThe only person who is quieter (has lower quiet[x]) is person 7, but\r\nit isn't clear if they have more money than person 0.\r\n\r\nanswer[7] = 7.\r\nAmong all people that definitely have equal to or more money than person 7\r\n(which could be persons 3, 4, 5, 6, or 7), the person who is the quietest (has lower quiet[x])\r\nis person 7.\r\n\r\nThe other answers can be filled out with similar reasoning.\r\n
    \r\n
    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    1. 1 <= quiet.length = N <= 500
    2. \r\n\t
    3. 0 <= quiet[i] < N, all quiet[i] are different.
    4. \r\n\t
    5. 0 <= richer.length <= N * (N-1) / 2
    6. \r\n\t
    7. 0 <= richer[i][j] < N
    8. \r\n\t
    9. richer[i][0] != richer[i][1]
    10. \r\n\t
    11. richer[i]'s are all different.
    12. \r\n\t
    13. The observations in richer are all logically consistent.
    14. \r\n
    \r\n", "content_cn": "

    \u5728\u4e00\u7ec4 N \u4e2a\u4eba\uff08\u7f16\u53f7\u4e3a 0, 1, 2, ..., N-1\uff09\u4e2d\uff0c\u6bcf\u4e2a\u4eba\u90fd\u6709\u4e0d\u540c\u6570\u76ee\u7684\u94b1\uff0c\u4ee5\u53ca\u4e0d\u540c\u7a0b\u5ea6\u7684\u5b89\u9759\uff08quietness\uff09\u3002

    \n\n

    \u4e3a\u4e86\u65b9\u4fbf\u8d77\u89c1\uff0c\u6211\u4eec\u5c06\u7f16\u53f7\u4e3a x \u7684\u4eba\u7b80\u79f0\u4e3a "person x "\u3002

    \n\n

    \u5982\u679c\u80fd\u591f\u80af\u5b9a person x \u6bd4 person y \u66f4\u6709\u94b1\u7684\u8bdd\uff0c\u6211\u4eec\u4f1a\u8bf4 richer[i] = [x, y] \u3002\u6ce8\u610f richer \u53ef\u80fd\u53ea\u662f\u6709\u6548\u89c2\u5bdf\u7684\u4e00\u4e2a\u5b50\u96c6\u3002

    \n\n

    \u53e6\u5916\uff0c\u5982\u679c person x \u7684\u5b89\u9759\u7a0b\u5ea6\u4e3a q \uff0c\u6211\u4eec\u4f1a\u8bf4 quiet[x] = q \u3002

    \n\n

    \u73b0\u5728\uff0c\u8fd4\u56de\u7b54\u6848 answer \uff0c\u5176\u4e2d answer[x] = y \u7684\u524d\u63d0\u662f\uff0c\u5728\u6240\u6709\u62e5\u6709\u7684\u94b1\u4e0d\u5c11\u4e8e person x \u7684\u4eba\u4e2d\uff0cperson y \u662f\u6700\u5b89\u9759\u7684\u4eba\uff08\u4e5f\u5c31\u662f\u5b89\u9759\u503c quiet[y] \u6700\u5c0f\u7684\u4eba\uff09\u3002

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1aricher = [[1,0],[2,1],[3,1],[3,7],[4,3],[5,3],[6,3]], quiet = [3,2,5,4,6,1,7,0]\n\u8f93\u51fa\uff1a[5,5,2,5,4,5,6,7]\n\u89e3\u91ca\uff1a \nanswer[0] = 5\uff0c\nperson 5 \u6bd4 person 3 \u6709\u66f4\u591a\u7684\u94b1\uff0cperson 3 \u6bd4 person 1 \u6709\u66f4\u591a\u7684\u94b1\uff0cperson 1 \u6bd4 person 0 \u6709\u66f4\u591a\u7684\u94b1\u3002\n\u552f\u4e00\u8f83\u4e3a\u5b89\u9759\uff08\u6709\u8f83\u4f4e\u7684\u5b89\u9759\u503c quiet[x]\uff09\u7684\u4eba\u662f person 7\uff0c\n\u4f46\u662f\u76ee\u524d\u8fd8\u4e0d\u6e05\u695a\u4ed6\u662f\u5426\u6bd4 person 0 \u66f4\u6709\u94b1\u3002\n\nanswer[7] = 7\uff0c\n\u5728\u6240\u6709\u62e5\u6709\u7684\u94b1\u80af\u5b9a\u4e0d\u5c11\u4e8e person 7 \u7684\u4eba\u4e2d(\u8fd9\u53ef\u80fd\u5305\u62ec person 3\uff0c4\uff0c5\uff0c6 \u4ee5\u53ca 7)\uff0c\n\u6700\u5b89\u9759(\u6709\u8f83\u4f4e\u5b89\u9759\u503c quiet[x])\u7684\u4eba\u662f person 7\u3002\n\n\u5176\u4ed6\u7684\u7b54\u6848\u4e5f\u53ef\u4ee5\u7528\u7c7b\u4f3c\u7684\u63a8\u7406\u6765\u89e3\u91ca\u3002\n
    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= quiet.length = N <= 500
    2. \n\t
    3. 0 <= quiet[i] < N\uff0c\u6240\u6709 quiet[i] \u90fd\u4e0d\u76f8\u540c\u3002
    4. \n\t
    5. 0 <= richer.length <= N * (N-1) / 2
    6. \n\t
    7. 0 <= richer[i][j] < N
    8. \n\t
    9. richer[i][0] != richer[i][1]
    10. \n\t
    11. richer[i] \u90fd\u662f\u4e0d\u540c\u7684\u3002
    12. \n\t
    13. \u5bf9 richer \u7684\u89c2\u5bdf\u5728\u903b\u8f91\u4e0a\u662f\u4e00\u81f4\u7684\u3002
    14. \n
    \n", "tags_en": ["Depth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector loudAndRich(vector>& richer, vector& quiet) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] loudAndRich(int[][] richer, int[] quiet) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def loudAndRich(self, richer, quiet):\n \"\"\"\n :type richer: List[List[int]]\n :type quiet: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def loudAndRich(self, richer: List[List[int]], quiet: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* loudAndRich(int** richer, int richerSize, int* richerColSize, int* quiet, int quietSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] LoudAndRich(int[][] richer, int[] quiet) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} richer\n * @param {number[]} quiet\n * @return {number[]}\n */\nvar loudAndRich = function(richer, quiet) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} richer\n# @param {Integer[]} quiet\n# @return {Integer[]}\ndef loud_and_rich(richer, quiet)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func loudAndRich(_ richer: [[Int]], _ quiet: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func loudAndRich(richer [][]int, quiet []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def loudAndRich(richer: Array[Array[Int]], quiet: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun loudAndRich(richer: Array, quiet: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn loud_and_rich(richer: Vec>, quiet: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $richer\n * @param Integer[] $quiet\n * @return Integer[]\n */\n function loudAndRich($richer, $quiet) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function loudAndRich(richer: number[][], quiet: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (loud-and-rich richer quiet)\n (-> (listof (listof exact-integer?)) (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0851](https://leetcode-cn.com/problems/loud-and-rich)", "[\u55a7\u95f9\u548c\u5bcc\u6709](/solution/0800-0899/0851.Loud%20and%20Rich/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0851](https://leetcode.com/problems/loud-and-rich)", "[Loud and Rich](/solution/0800-0899/0851.Loud%20and%20Rich/README_EN.md)", "`Depth-first Search`", "Medium", ""]}, {"question_id": "0880", "frontend_question_id": "0850", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/rectangle-area-ii", "url_en": "https://leetcode.com/problems/rectangle-area-ii", "relative_path_cn": "/solution/0800-0899/0850.Rectangle%20Area%20II/README.md", "relative_path_en": "/solution/0800-0899/0850.Rectangle%20Area%20II/README_EN.md", "title_cn": "\u77e9\u5f62\u9762\u79ef II", "title_en": "Rectangle Area II", "question_title_slug": "rectangle-area-ii", "content_en": "

    We are given a list of (axis-aligned) rectangles. Each rectangle[i] = [xi1, yi1, xi2, yi2] , where (xi1, yi1) are the coordinates of the bottom-left corner, and (xi2, yi2) are the coordinates of the top-right corner of the ith rectangle.

    \n\n

    Find the total area covered by all rectangles in the plane. Since the answer may be too large, return it modulo 109 + 7.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: rectangles = [[0,0,2,2],[1,0,2,3],[1,0,3,1]]\nOutput: 6\nExplanation: As illustrated in the picture.\n
    \n\n

    Example 2:

    \n\n
    \nInput: rectangles = [[0,0,1000000000,1000000000]]\nOutput: 49\nExplanation: The answer is 1018 modulo (109 + 7), which is (109)2 = (-7)2 = 49.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= rectangles.length <= 200
    • \n\t
    • rectanges[i].length = 4
    • \n\t
    • 0 <= rectangles[i][j] <= 109
    • \n\t
    • The total area covered by all rectangles will never exceed 263 - 1 and thus will fit in a 64-bit signed integer.
    • \n
    \n", "content_cn": "

    \u6211\u4eec\u7ed9\u51fa\u4e86\u4e00\u4e2a\uff08\u8f74\u5bf9\u9f50\u7684\uff09\u77e9\u5f62\u5217\u8868 rectangles \u3002 \u5bf9\u4e8e rectangle[i] = [x1, y1, x2, y2]\uff0c\u5176\u4e2d\uff08x1\uff0cy1\uff09\u662f\u77e9\u5f62 i \u5de6\u4e0b\u89d2\u7684\u5750\u6807\uff0c\uff08x2\uff0cy2\uff09\u662f\u8be5\u77e9\u5f62\u53f3\u4e0a\u89d2\u7684\u5750\u6807\u3002

    \n\n

    \u627e\u51fa\u5e73\u9762\u4e2d\u6240\u6709\u77e9\u5f62\u53e0\u52a0\u8986\u76d6\u540e\u7684\u603b\u9762\u79ef\u3002 \u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u592a\u5927\uff0c\u8bf7\u8fd4\u56de\u5b83\u5bf9 10 ^ 9 + 7 \u53d6\u6a21\u7684\u7ed3\u679c\u3002

    \n\n

    \"\"

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a[[0,0,2,2],[1,0,2,3],[1,0,3,1]]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u5982\u56fe\u6240\u793a\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a[[0,0,1000000000,1000000000]]\n\u8f93\u51fa\uff1a49\n\u89e3\u91ca\uff1a\u7b54\u6848\u662f 10^18 \u5bf9 (10^9 + 7) \u53d6\u6a21\u7684\u7ed3\u679c\uff0c \u5373 (10^9)^2 → (-7)^2 = 49 \u3002\n
    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= rectangles.length <= 200
    • \n\t
    • rectanges[i].length = 4
    • \n\t
    • 0 <= rectangles[i][j] <= 10^9
    • \n\t
    • \u77e9\u5f62\u53e0\u52a0\u8986\u76d6\u540e\u7684\u603b\u9762\u79ef\u4e0d\u4f1a\u8d85\u8d8a 2^63 - 1 \uff0c\u8fd9\u610f\u5473\u7740\u53ef\u4ee5\u7528\u4e00\u4e2a 64 \u4f4d\u6709\u7b26\u53f7\u6574\u6570\u6765\u4fdd\u5b58\u9762\u79ef\u7ed3\u679c\u3002
    • \n
    \n", "tags_en": ["Segment Tree", "Line Sweep"], "tags_cn": ["\u7ebf\u6bb5\u6811"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int rectangleArea(vector>& rectangles) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int rectangleArea(int[][] rectangles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def rectangleArea(self, rectangles):\n \"\"\"\n :type rectangles: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def rectangleArea(self, rectangles: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint rectangleArea(int** rectangles, int rectanglesSize, int* rectanglesColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int RectangleArea(int[][] rectangles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} rectangles\n * @return {number}\n */\nvar rectangleArea = function(rectangles) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} rectangles\n# @return {Integer}\ndef rectangle_area(rectangles)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func rectangleArea(_ rectangles: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func rectangleArea(rectangles [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def rectangleArea(rectangles: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun rectangleArea(rectangles: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn rectangle_area(rectangles: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $rectangles\n * @return Integer\n */\n function rectangleArea($rectangles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function rectangleArea(rectangles: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (rectangle-area rectangles)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0850](https://leetcode-cn.com/problems/rectangle-area-ii)", "[\u77e9\u5f62\u9762\u79ef II](/solution/0800-0899/0850.Rectangle%20Area%20II/README.md)", "`\u7ebf\u6bb5\u6811`", "\u56f0\u96be", ""], "md_table_row_en": ["[0850](https://leetcode.com/problems/rectangle-area-ii)", "[Rectangle Area II](/solution/0800-0899/0850.Rectangle%20Area%20II/README_EN.md)", "`Segment Tree`,`Line Sweep`", "Hard", ""]}, {"question_id": "0879", "frontend_question_id": "0849", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximize-distance-to-closest-person", "url_en": "https://leetcode.com/problems/maximize-distance-to-closest-person", "relative_path_cn": "/solution/0800-0899/0849.Maximize%20Distance%20to%20Closest%20Person/README.md", "relative_path_en": "/solution/0800-0899/0849.Maximize%20Distance%20to%20Closest%20Person/README_EN.md", "title_cn": "\u5230\u6700\u8fd1\u7684\u4eba\u7684\u6700\u5927\u8ddd\u79bb", "title_en": "Maximize Distance to Closest Person", "question_title_slug": "maximize-distance-to-closest-person", "content_en": "

    You are given an array representing a row of seats where seats[i] = 1 represents a person sitting in the ith seat, and seats[i] = 0 represents that the ith seat is empty (0-indexed).

    \n\n

    There is at least one empty seat, and at least one person sitting.

    \n\n

    Alex wants to sit in the seat such that the distance between him and the closest person to him is maximized. 

    \n\n

    Return that maximum distance to the closest person.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: seats = [1,0,0,0,1,0,1]\nOutput: 2\nExplanation: \nIf Alex sits in the second open seat (i.e. seats[2]), then the closest person has distance 2.\nIf Alex sits in any other open seat, the closest person has distance 1.\nThus, the maximum distance to the closest person is 2.\n
    \n\n

    Example 2:

    \n\n
    \nInput: seats = [1,0,0,0]\nOutput: 3\nExplanation: \nIf Alex sits in the last seat (i.e. seats[3]), the closest person is 3 seats away.\nThis is the maximum distance possible, so the answer is 3.\n
    \n\n

    Example 3:

    \n\n
    \nInput: seats = [0,1]\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= seats.length <= 2 * 104
    • \n\t
    • seats[i] is 0 or 1.
    • \n\t
    • At least one seat is empty.
    • \n\t
    • At least one seat is occupied.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4\u00a0seats \u8868\u793a\u4e00\u6392\u5ea7\u4f4d\uff0c\u5176\u4e2d seats[i] = 1 \u4ee3\u8868\u6709\u4eba\u5750\u5728\u7b2c i \u4e2a\u5ea7\u4f4d\u4e0a\uff0cseats[i] = 0 \u4ee3\u8868\u5ea7\u4f4d i \u4e0a\u662f\u7a7a\u7684\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\u3002

    \n\n

    \u81f3\u5c11\u6709\u4e00\u4e2a\u7a7a\u5ea7\u4f4d\uff0c\u4e14\u81f3\u5c11\u6709\u4e00\u4eba\u5df2\u7ecf\u5750\u5728\u5ea7\u4f4d\u4e0a\u3002

    \n\n

    \u4e9a\u5386\u514b\u65af\u5e0c\u671b\u5750\u5728\u4e00\u4e2a\u80fd\u591f\u4f7f\u4ed6\u4e0e\u79bb\u4ed6\u6700\u8fd1\u7684\u4eba\u4e4b\u95f4\u7684\u8ddd\u79bb\u8fbe\u5230\u6700\u5927\u5316\u7684\u5ea7\u4f4d\u4e0a\u3002

    \n\n

    \u8fd4\u56de\u4ed6\u5230\u79bb\u4ed6\u6700\u8fd1\u7684\u4eba\u7684\u6700\u5927\u8ddd\u79bb\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aseats = [1,0,0,0,1,0,1]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n\u5982\u679c\u4e9a\u5386\u514b\u65af\u5750\u5728\u7b2c\u4e8c\u4e2a\u7a7a\u4f4d\uff08seats[2]\uff09\u4e0a\uff0c\u4ed6\u5230\u79bb\u4ed6\u6700\u8fd1\u7684\u4eba\u7684\u8ddd\u79bb\u4e3a 2 \u3002\n\u5982\u679c\u4e9a\u5386\u514b\u65af\u5750\u5728\u5176\u5b83\u4efb\u4f55\u4e00\u4e2a\u7a7a\u4f4d\u4e0a\uff0c\u4ed6\u5230\u79bb\u4ed6\u6700\u8fd1\u7684\u4eba\u7684\u8ddd\u79bb\u4e3a 1 \u3002\n\u56e0\u6b64\uff0c\u4ed6\u5230\u79bb\u4ed6\u6700\u8fd1\u7684\u4eba\u7684\u6700\u5927\u8ddd\u79bb\u662f 2 \u3002 \n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aseats = [1,0,0,0]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\n\u5982\u679c\u4e9a\u5386\u514b\u65af\u5750\u5728\u6700\u540e\u4e00\u4e2a\u5ea7\u4f4d\u4e0a\uff0c\u4ed6\u79bb\u6700\u8fd1\u7684\u4eba\u6709 3 \u4e2a\u5ea7\u4f4d\u8fdc\u3002\n\u8fd9\u662f\u53ef\u80fd\u7684\u6700\u5927\u8ddd\u79bb\uff0c\u6240\u4ee5\u7b54\u6848\u662f 3 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aseats = [0,1]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= seats.length <= 2 * 104
    • \n\t
    • seats[i] \u4e3a 0 \u6216 1
    • \n\t
    • \u81f3\u5c11\u6709\u4e00\u4e2a \u7a7a\u5ea7\u4f4d
    • \n\t
    • \u81f3\u5c11\u6709\u4e00\u4e2a \u5ea7\u4f4d\u4e0a\u6709\u4eba
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxDistToClosest(vector& seats) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxDistToClosest(int[] seats) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxDistToClosest(self, seats):\n \"\"\"\n :type seats: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxDistToClosest(self, seats: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxDistToClosest(int* seats, int seatsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxDistToClosest(int[] seats) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} seats\n * @return {number}\n */\nvar maxDistToClosest = function(seats) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} seats\n# @return {Integer}\ndef max_dist_to_closest(seats)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxDistToClosest(_ seats: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxDistToClosest(seats []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxDistToClosest(seats: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxDistToClosest(seats: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_dist_to_closest(seats: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $seats\n * @return Integer\n */\n function maxDistToClosest($seats) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxDistToClosest(seats: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-dist-to-closest seats)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0849](https://leetcode-cn.com/problems/maximize-distance-to-closest-person)", "[\u5230\u6700\u8fd1\u7684\u4eba\u7684\u6700\u5927\u8ddd\u79bb](/solution/0800-0899/0849.Maximize%20Distance%20to%20Closest%20Person/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0849](https://leetcode.com/problems/maximize-distance-to-closest-person)", "[Maximize Distance to Closest Person](/solution/0800-0899/0849.Maximize%20Distance%20to%20Closest%20Person/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0878", "frontend_question_id": "0848", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/shifting-letters", "url_en": "https://leetcode.com/problems/shifting-letters", "relative_path_cn": "/solution/0800-0899/0848.Shifting%20Letters/README.md", "relative_path_en": "/solution/0800-0899/0848.Shifting%20Letters/README_EN.md", "title_cn": "\u5b57\u6bcd\u79fb\u4f4d", "title_en": "Shifting Letters", "question_title_slug": "shifting-letters", "content_en": "

    We have a string s of lowercase letters, and an integer array shifts.

    \n\n

    Call the shift of a letter, the next letter in the alphabet, (wrapping around so that 'z' becomes 'a'). 

    \n\n

    For example, shift('a') = 'b', shift('t') = 'u', and shift('z') = 'a'.

    \n\n

    Now for each shifts[i] = x, we want to shift the first i+1 letters of S, x times.

    \n\n

    Return the final string after all such shifts to s are applied.

    \n\n

    Example 1:

    \n\n
    \nInput: s = "abc", shifts = [3,5,9]\nOutput: "rpl"\nExplanation: \nWe start with "abc".\nAfter shifting the first 1 letters of S by 3, we have "dbc".\nAfter shifting the first 2 letters of S by 5, we have "igc".\nAfter shifting the first 3 letters of S by 9, we have "rpl", the answer.\n
    \n\n

    Note:

    \n\n
      \n\t
    1. 1 <= s.length = shifts.length <= 20000
    2. \n\t
    3. 0 <= shifts[i] <= 109
    4. \n
    \n", "content_cn": "

    \u6709\u4e00\u4e2a\u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210\u7684\u5b57\u7b26\u4e32 S\uff0c\u548c\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 shifts\u3002

    \n\n

    \u6211\u4eec\u5c06\u5b57\u6bcd\u8868\u4e2d\u7684\u4e0b\u4e00\u4e2a\u5b57\u6bcd\u79f0\u4e3a\u539f\u5b57\u6bcd\u7684 \u79fb\u4f4d\uff08\u7531\u4e8e\u5b57\u6bcd\u8868\u662f\u73af\u7ed5\u7684\uff0c 'z' \u5c06\u4f1a\u53d8\u6210 'a'\uff09\u3002

    \n\n

    \u4f8b\u5982·\uff0cshift('a') = 'b'\uff0c shift('t') = 'u',\uff0c \u4ee5\u53ca shift('z') = 'a'\u3002

    \n\n

    \u5bf9\u4e8e\u6bcf\u4e2a shifts[i] = x \uff0c \u6211\u4eec\u4f1a\u5c06 S \u4e2d\u7684\u524d i+1 \u4e2a\u5b57\u6bcd\u79fb\u4f4d x \u6b21\u3002

    \n\n

    \u8fd4\u56de\u5c06\u6240\u6709\u8fd9\u4e9b\u79fb\u4f4d\u90fd\u5e94\u7528\u5230 S \u540e\u6700\u7ec8\u5f97\u5230\u7684\u5b57\u7b26\u4e32\u3002

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1aS = "abc", shifts = [3,5,9]\n\u8f93\u51fa\uff1a"rpl"\n\u89e3\u91ca\uff1a \n\u6211\u4eec\u4ee5 "abc" \u5f00\u59cb\u3002\n\u5c06 S \u4e2d\u7684\u7b2c 1 \u4e2a\u5b57\u6bcd\u79fb\u4f4d 3 \u6b21\u540e\uff0c\u6211\u4eec\u5f97\u5230 "dbc"\u3002\n\u518d\u5c06 S \u4e2d\u7684\u524d 2 \u4e2a\u5b57\u6bcd\u79fb\u4f4d 5 \u6b21\u540e\uff0c\u6211\u4eec\u5f97\u5230 "igc"\u3002\n\u6700\u540e\u5c06 S \u4e2d\u7684\u8fd9 3 \u4e2a\u5b57\u6bcd\u79fb\u4f4d 9 \u6b21\u540e\uff0c\u6211\u4eec\u5f97\u5230\u7b54\u6848 "rpl"\u3002\n
    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= S.length = shifts.length <= 20000
    2. \n\t
    3. 0 <= shifts[i] <= 10 ^ 9
    4. \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string shiftingLetters(string s, vector& shifts) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String shiftingLetters(String s, int[] shifts) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def shiftingLetters(self, s, shifts):\n \"\"\"\n :type s: str\n :type shifts: List[int]\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def shiftingLetters(self, s: str, shifts: List[int]) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * shiftingLetters(char * s, int* shifts, int shiftsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ShiftingLetters(string s, int[] shifts) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number[]} shifts\n * @return {string}\n */\nvar shiftingLetters = function(s, shifts) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer[]} shifts\n# @return {String}\ndef shifting_letters(s, shifts)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func shiftingLetters(_ s: String, _ shifts: [Int]) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func shiftingLetters(s string, shifts []int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def shiftingLetters(s: String, shifts: Array[Int]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun shiftingLetters(s: String, shifts: IntArray): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn shifting_letters(s: String, shifts: Vec) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer[] $shifts\n * @return String\n */\n function shiftingLetters($s, $shifts) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function shiftingLetters(s: string, shifts: number[]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (shifting-letters s shifts)\n (-> string? (listof exact-integer?) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0848](https://leetcode-cn.com/problems/shifting-letters)", "[\u5b57\u6bcd\u79fb\u4f4d](/solution/0800-0899/0848.Shifting%20Letters/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0848](https://leetcode.com/problems/shifting-letters)", "[Shifting Letters](/solution/0800-0899/0848.Shifting%20Letters/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "0877", "frontend_question_id": "0847", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/shortest-path-visiting-all-nodes", "url_en": "https://leetcode.com/problems/shortest-path-visiting-all-nodes", "relative_path_cn": "/solution/0800-0899/0847.Shortest%20Path%20Visiting%20All%20Nodes/README.md", "relative_path_en": "/solution/0800-0899/0847.Shortest%20Path%20Visiting%20All%20Nodes/README_EN.md", "title_cn": "\u8bbf\u95ee\u6240\u6709\u8282\u70b9\u7684\u6700\u77ed\u8def\u5f84", "title_en": "Shortest Path Visiting All Nodes", "question_title_slug": "shortest-path-visiting-all-nodes", "content_en": "

    You have an undirected, connected graph of n nodes labeled from 0 to n - 1. You are given an array graph where graph[i] is a list of all the nodes connected with node i by an edge.

    \n\n

    Return the length of the shortest path that visits every node. You may start and stop at any node, you may revisit nodes multiple times, and you may reuse edges.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: graph = [[1,2,3],[0],[0],[0]]\nOutput: 4\nExplanation: One possible path is [1,0,2,0,3]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: graph = [[1],[0,2,4],[1,3,4],[2],[1,2]]\nOutput: 4\nExplanation: One possible path is [0,1,4,2,3]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == graph.length
    • \n\t
    • 1 <= n <= 12
    • \n\t
    • 0 <= graph[i].length < n
    • \n\t
    • graph[i] does not contain i.
    • \n\t
    • If graph[a] contains b, then graph[b] contains a.
    • \n\t
    • The input graph is always connected.
    • \n
    \n", "content_cn": "

    \u7ed9\u51fa graph \u4e3a\u6709 N \u4e2a\u8282\u70b9\uff08\u7f16\u53f7\u4e3a 0, 1, 2, ..., N-1\uff09\u7684\u65e0\u5411\u8fde\u901a\u56fe\u3002 

    \n\n

    graph.length = N\uff0c\u4e14\u53ea\u6709\u8282\u70b9 i \u548c j \u8fde\u901a\u65f6\uff0cj != i \u5728\u5217\u8868 graph[i] \u4e2d\u6070\u597d\u51fa\u73b0\u4e00\u6b21\u3002

    \n\n

    \u8fd4\u56de\u80fd\u591f\u8bbf\u95ee\u6240\u6709\u8282\u70b9\u7684\u6700\u77ed\u8def\u5f84\u7684\u957f\u5ea6\u3002\u4f60\u53ef\u4ee5\u5728\u4efb\u4e00\u8282\u70b9\u5f00\u59cb\u548c\u505c\u6b62\uff0c\u4e5f\u53ef\u4ee5\u591a\u6b21\u91cd\u8bbf\u8282\u70b9\uff0c\u5e76\u4e14\u53ef\u4ee5\u91cd\u7528\u8fb9\u3002

    \n\n

     

    \n\n
      \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a[[1,2,3],[0],[0],[0]]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u4e00\u4e2a\u53ef\u80fd\u7684\u8def\u5f84\u4e3a [1,0,2,0,3]
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a[[1],[0,2,4],[1,3,4],[2],[1,2]]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u4e00\u4e2a\u53ef\u80fd\u7684\u8def\u5f84\u4e3a [0,1,4,2,3]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= graph.length <= 12
    2. \n\t
    3. 0 <= graph[i].length < graph.length
    4. \n
    \n", "tags_en": ["Breadth-first Search", "Dynamic Programming"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int shortestPathLength(vector>& graph) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int shortestPathLength(int[][] graph) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def shortestPathLength(self, graph):\n \"\"\"\n :type graph: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def shortestPathLength(self, graph: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint shortestPathLength(int** graph, int graphSize, int* graphColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ShortestPathLength(int[][] graph) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} graph\n * @return {number}\n */\nvar shortestPathLength = function(graph) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} graph\n# @return {Integer}\ndef shortest_path_length(graph)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func shortestPathLength(_ graph: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func shortestPathLength(graph [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def shortestPathLength(graph: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun shortestPathLength(graph: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn shortest_path_length(graph: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $graph\n * @return Integer\n */\n function shortestPathLength($graph) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function shortestPathLength(graph: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (shortest-path-length graph)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0847](https://leetcode-cn.com/problems/shortest-path-visiting-all-nodes)", "[\u8bbf\u95ee\u6240\u6709\u8282\u70b9\u7684\u6700\u77ed\u8def\u5f84](/solution/0800-0899/0847.Shortest%20Path%20Visiting%20All%20Nodes/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0847](https://leetcode.com/problems/shortest-path-visiting-all-nodes)", "[Shortest Path Visiting All Nodes](/solution/0800-0899/0847.Shortest%20Path%20Visiting%20All%20Nodes/README_EN.md)", "`Breadth-first Search`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0876", "frontend_question_id": "0846", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/hand-of-straights", "url_en": "https://leetcode.com/problems/hand-of-straights", "relative_path_cn": "/solution/0800-0899/0846.Hand%20of%20Straights/README.md", "relative_path_en": "/solution/0800-0899/0846.Hand%20of%20Straights/README_EN.md", "title_cn": "\u4e00\u624b\u987a\u5b50", "title_en": "Hand of Straights", "question_title_slug": "hand-of-straights", "content_en": "

    Alice has a hand of cards, given as an array of integers.

    \n\n

    Now she wants to rearrange the cards into groups so that each group is size groupSize, and consists of groupSize consecutive cards.

    \n\n

    Return true if and only if she can.

    \n\n

    Note: This question is the same as 1296: https://leetcode.com/problems/divide-array-in-sets-of-k-consecutive-numbers/

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: hand = [1,2,3,6,2,3,4,7,8], groupSize = 3\nOutput: true\nExplanation: Alice's hand can be rearranged as [1,2,3],[2,3,4],[6,7,8]\n
    \n\n

    Example 2:

    \n\n
    \nInput: hand = [1,2,3,4,5], groupSize = 4\nOutput: false\nExplanation: Alice's hand can't be rearranged into groups of 4.\n\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= hand.length <= 10000
    • \n\t
    • 0 <= hand[i] <= 109
    • \n\t
    • 1 <= groupSize <= hand.length
    • \n
    \n", "content_cn": "

    \u7231\u4e3d\u4e1d\u6709\u4e00\u624b\uff08hand\uff09\u7531\u6574\u6570\u6570\u7ec4\u7ed9\u5b9a\u7684\u724c\u3002\u00a0

    \n\n

    \u73b0\u5728\u5979\u60f3\u628a\u724c\u91cd\u65b0\u6392\u5217\u6210\u7ec4\uff0c\u4f7f\u5f97\u6bcf\u4e2a\u7ec4\u7684\u5927\u5c0f\u90fd\u662f W\uff0c\u4e14\u7531 W \u5f20\u8fde\u7eed\u7684\u724c\u7ec4\u6210\u3002

    \n\n

    \u5982\u679c\u5979\u53ef\u4ee5\u5b8c\u6210\u5206\u7ec4\u5c31\u8fd4\u56de true\uff0c\u5426\u5219\u8fd4\u56de false\u3002

    \n\n

    \u00a0

    \n\n

    \u6ce8\u610f\uff1a\u6b64\u9898\u76ee\u4e0e 1296 \u91cd\u590d\uff1ahttps://leetcode-cn.com/problems/divide-array-in-sets-of-k-consecutive-numbers/

    \n\n

    \u00a0

    \n\n
      \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahand = [1,2,3,6,2,3,4,7,8], W = 3\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u7231\u4e3d\u4e1d\u7684\u624b\u724c\u53ef\u4ee5\u88ab\u91cd\u65b0\u6392\u5217\u4e3a [1,2,3]\uff0c[2,3,4]\uff0c[6,7,8]\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahand = [1,2,3,4,5], W = 4\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u7231\u4e3d\u4e1d\u7684\u624b\u724c\u65e0\u6cd5\u88ab\u91cd\u65b0\u6392\u5217\u6210\u51e0\u4e2a\u5927\u5c0f\u4e3a 4 \u7684\u7ec4\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= hand.length <= 10000
    • \n\t
    • 0 <= hand[i]\u00a0<= 10^9
    • \n\t
    • 1 <= W <= hand.length
    • \n
    \n", "tags_en": ["Ordered Map"], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isNStraightHand(vector& hand, int groupSize) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isNStraightHand(int[] hand, int groupSize) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isNStraightHand(self, hand, groupSize):\n \"\"\"\n :type hand: List[int]\n :type groupSize: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isNStraightHand(self, hand: List[int], groupSize: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isNStraightHand(int* hand, int handSize, int groupSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsNStraightHand(int[] hand, int groupSize) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} hand\n * @param {number} groupSize\n * @return {boolean}\n */\nvar isNStraightHand = function(hand, groupSize) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} hand\n# @param {Integer} group_size\n# @return {Boolean}\ndef is_n_straight_hand(hand, group_size)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isNStraightHand(_ hand: [Int], _ groupSize: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isNStraightHand(hand []int, groupSize int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isNStraightHand(hand: Array[Int], groupSize: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isNStraightHand(hand: IntArray, groupSize: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_n_straight_hand(hand: Vec, group_size: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $hand\n * @param Integer $groupSize\n * @return Boolean\n */\n function isNStraightHand($hand, $groupSize) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isNStraightHand(hand: number[], groupSize: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-n-straight-hand hand groupSize)\n (-> (listof exact-integer?) exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0846](https://leetcode-cn.com/problems/hand-of-straights)", "[\u4e00\u624b\u987a\u5b50](/solution/0800-0899/0846.Hand%20of%20Straights/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0846](https://leetcode.com/problems/hand-of-straights)", "[Hand of Straights](/solution/0800-0899/0846.Hand%20of%20Straights/README_EN.md)", "`Ordered Map`", "Medium", ""]}, {"question_id": "0875", "frontend_question_id": "0845", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-mountain-in-array", "url_en": "https://leetcode.com/problems/longest-mountain-in-array", "relative_path_cn": "/solution/0800-0899/0845.Longest%20Mountain%20in%20Array/README.md", "relative_path_en": "/solution/0800-0899/0845.Longest%20Mountain%20in%20Array/README_EN.md", "title_cn": "\u6570\u7ec4\u4e2d\u7684\u6700\u957f\u5c71\u8109", "title_en": "Longest Mountain in Array", "question_title_slug": "longest-mountain-in-array", "content_en": "

    You may recall that an array arr is a mountain array if and only if:

    \n\n
      \n\t
    • arr.length >= 3
    • \n\t
    • There exists some index i (0-indexed) with 0 < i < arr.length - 1 such that:\n\t
        \n\t\t
      • arr[0] < arr[1] < ... < arr[i - 1] < arr[i]
      • \n\t\t
      • arr[i] > arr[i + 1] > ... > arr[arr.length - 1]
      • \n\t
      \n\t
    • \n
    \n\n

    Given an integer array arr, return the length of the longest subarray, which is a mountain. Return 0 if there is no mountain subarray.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr = [2,1,4,7,3,2,5]\nOutput: 5\nExplanation: The largest mountain is [1,4,7,3,2] which has length 5.\n
    \n\n

    Example 2:

    \n\n
    \nInput: arr = [2,2,2]\nOutput: 0\nExplanation: There is no mountain.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= arr.length <= 104
    • \n\t
    • 0 <= arr[i] <= 104
    • \n
    \n\n

     

    \n

    Follow up:

    \n\n
      \n\t
    • Can you solve it using only one pass?
    • \n\t
    • Can you solve it in O(1) space?
    • \n
    \n", "content_cn": "

    \u6211\u4eec\u628a\u6570\u7ec4 A \u4e2d\u7b26\u5408\u4e0b\u5217\u5c5e\u6027\u7684\u4efb\u610f\u8fde\u7eed\u5b50\u6570\u7ec4 B \u79f0\u4e3a “\u5c71\u8109”\uff1a

    \n\n
      \n\t
    • B.length >= 3
    • \n\t
    • \u5b58\u5728 0 < i < B.length - 1 \u4f7f\u5f97 B[0] < B[1] < ... B[i-1] < B[i] > B[i+1] > ... > B[B.length - 1]
    • \n
    \n\n

    \uff08\u6ce8\u610f\uff1aB \u53ef\u4ee5\u662f A \u7684\u4efb\u610f\u5b50\u6570\u7ec4\uff0c\u5305\u62ec\u6574\u4e2a\u6570\u7ec4 A\u3002\uff09

    \n\n

    \u7ed9\u51fa\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 A\uff0c\u8fd4\u56de\u6700\u957f “\u5c71\u8109” \u7684\u957f\u5ea6\u3002

    \n\n

    \u5982\u679c\u4e0d\u542b\u6709 “\u5c71\u8109” \u5219\u8fd4\u56de 0\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a[2,1,4,7,3,2,5]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u6700\u957f\u7684 “\u5c71\u8109” \u662f [1,4,7,3,2]\uff0c\u957f\u5ea6\u4e3a 5\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a[2,2,2]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u4e0d\u542b “\u5c71\u8109”\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 0 <= A.length <= 10000
    2. \n\t
    3. 0 <= A[i] <= 10000
    4. \n
    \n", "tags_en": ["Two Pointers"], "tags_cn": ["\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int longestMountain(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int longestMountain(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestMountain(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestMountain(self, arr: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint longestMountain(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LongestMountain(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar longestMountain = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef longest_mountain(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestMountain(_ arr: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestMountain(arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestMountain(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestMountain(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_mountain(arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function longestMountain($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestMountain(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-mountain arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0845](https://leetcode-cn.com/problems/longest-mountain-in-array)", "[\u6570\u7ec4\u4e2d\u7684\u6700\u957f\u5c71\u8109](/solution/0800-0899/0845.Longest%20Mountain%20in%20Array/README.md)", "`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0845](https://leetcode.com/problems/longest-mountain-in-array)", "[Longest Mountain in Array](/solution/0800-0899/0845.Longest%20Mountain%20in%20Array/README_EN.md)", "`Two Pointers`", "Medium", ""]}, {"question_id": "0874", "frontend_question_id": "0844", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/backspace-string-compare", "url_en": "https://leetcode.com/problems/backspace-string-compare", "relative_path_cn": "/solution/0800-0899/0844.Backspace%20String%20Compare/README.md", "relative_path_en": "/solution/0800-0899/0844.Backspace%20String%20Compare/README_EN.md", "title_cn": "\u6bd4\u8f83\u542b\u9000\u683c\u7684\u5b57\u7b26\u4e32", "title_en": "Backspace String Compare", "question_title_slug": "backspace-string-compare", "content_en": "

    Given two strings s and t, return true if they are equal when both are typed into empty text editors. '#' means a backspace character.

    \n\n

    Note that after backspacing an empty text, the text will continue empty.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "ab#c", t = "ad#c"\nOutput: true\nExplanation: Both s and t become "ac".\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "ab##", t = "c#d#"\nOutput: true\nExplanation: Both s and t become "".\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "a##c", t = "#a#c"\nOutput: true\nExplanation: Both s and t become "c".\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "a#c", t = "b"\nOutput: false\nExplanation: s becomes "c" while t becomes "b".\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length, t.length <= 200
    • \n\t
    • s and t only contain lowercase letters and '#' characters.
    • \n
    \n\n

     

    \n

    Follow up: Can you solve it in O(n) time and O(1) space?

    \n", "content_cn": "

    \u7ed9\u5b9a S \u548c T \u4e24\u4e2a\u5b57\u7b26\u4e32\uff0c\u5f53\u5b83\u4eec\u5206\u522b\u88ab\u8f93\u5165\u5230\u7a7a\u767d\u7684\u6587\u672c\u7f16\u8f91\u5668\u540e\uff0c\u5224\u65ad\u4e8c\u8005\u662f\u5426\u76f8\u7b49\uff0c\u5e76\u8fd4\u56de\u7ed3\u679c\u3002 # \u4ee3\u8868\u9000\u683c\u5b57\u7b26\u3002

    \n\n

    \u6ce8\u610f\uff1a\u5982\u679c\u5bf9\u7a7a\u6587\u672c\u8f93\u5165\u9000\u683c\u5b57\u7b26\uff0c\u6587\u672c\u7ee7\u7eed\u4e3a\u7a7a\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aS = \"ab#c\", T = \"ad#c\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1aS \u548c T \u90fd\u4f1a\u53d8\u6210 \u201cac\u201d\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aS = \"ab##\", T = \"c#d#\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1aS \u548c T \u90fd\u4f1a\u53d8\u6210 \u201c\u201d\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aS = \"a##c\", T = \"#a#c\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1aS \u548c T \u90fd\u4f1a\u53d8\u6210 \u201cc\u201d\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1aS = \"a#c\", T = \"b\"\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1aS \u4f1a\u53d8\u6210 \u201cc\u201d\uff0c\u4f46 T \u4ecd\u7136\u662f \u201cb\u201d\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= S.length <= 200
    • \n\t
    • 1 <= T.length <= 200
    • \n\t
    • S \u548c T \u53ea\u542b\u6709\u5c0f\u5199\u5b57\u6bcd\u4ee5\u53ca\u5b57\u7b26 '#'\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u4f60\u53ef\u4ee5\u7528 O(N) \u7684\u65f6\u95f4\u590d\u6742\u5ea6\u548c O(1) \u7684\u7a7a\u95f4\u590d\u6742\u5ea6\u89e3\u51b3\u8be5\u95ee\u9898\u5417\uff1f
    • \n
    \n\n

    \u00a0

    \n", "tags_en": ["Stack", "Two Pointers"], "tags_cn": ["\u6808", "\u53cc\u6307\u9488"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool backspaceCompare(string s, string t) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean backspaceCompare(String s, String t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def backspaceCompare(self, s, t):\n \"\"\"\n :type s: str\n :type t: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def backspaceCompare(self, s: str, t: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool backspaceCompare(char * s, char * t){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool BackspaceCompare(string s, string t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string} t\n * @return {boolean}\n */\nvar backspaceCompare = function(s, t) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String} t\n# @return {Boolean}\ndef backspace_compare(s, t)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func backspaceCompare(_ s: String, _ t: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func backspaceCompare(s string, t string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def backspaceCompare(s: String, t: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun backspaceCompare(s: String, t: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn backspace_compare(s: String, t: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String $t\n * @return Boolean\n */\n function backspaceCompare($s, $t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function backspaceCompare(s: string, t: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (backspace-compare s t)\n (-> string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0844](https://leetcode-cn.com/problems/backspace-string-compare)", "[\u6bd4\u8f83\u542b\u9000\u683c\u7684\u5b57\u7b26\u4e32](/solution/0800-0899/0844.Backspace%20String%20Compare/README.md)", "`\u6808`,`\u53cc\u6307\u9488`", "\u7b80\u5355", ""], "md_table_row_en": ["[0844](https://leetcode.com/problems/backspace-string-compare)", "[Backspace String Compare](/solution/0800-0899/0844.Backspace%20String%20Compare/README_EN.md)", "`Stack`,`Two Pointers`", "Easy", ""]}, {"question_id": "0873", "frontend_question_id": "0843", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/guess-the-word", "url_en": "https://leetcode.com/problems/guess-the-word", "relative_path_cn": "/solution/0800-0899/0843.Guess%20the%20Word/README.md", "relative_path_en": "/solution/0800-0899/0843.Guess%20the%20Word/README_EN.md", "title_cn": "\u731c\u731c\u8fd9\u4e2a\u5355\u8bcd", "title_en": "Guess the Word", "question_title_slug": "guess-the-word", "content_en": "

    This is an interactive problem.

    \n\n

    You are given an array of unique strings wordlist where wordlist[i] is 6 letters long, and one word in this list is chosen as secret.

    \n\n

    You may call Master.guess(word) to guess a word. The guessed word should have type string and must be from the original list with 6 lowercase letters.

    \n\n

    This function returns an integer type, representing the number of exact matches (value and position) of your guess to the secret word. Also, if your guess is not in the given wordlist, it will return -1 instead.

    \n\n

    For each test case, you have exactly 10 guesses to guess the word. At the end of any number of calls, if you have made 10 or fewer calls to Master.guess and at least one of these guesses was secret, then you pass the test case.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: secret = "acckzz", wordlist = ["acckzz","ccbazz","eiowzz","abcczz"], numguesses = 10\nOutput: You guessed the secret word correctly.\nExplanation:\nmaster.guess("aaaaaa") returns -1, because "aaaaaa" is not in wordlist.\nmaster.guess("acckzz") returns 6, because "acckzz" is secret and has all 6 matches.\nmaster.guess("ccbazz") returns 3, because "ccbazz" has 3 matches.\nmaster.guess("eiowzz") returns 2, because "eiowzz" has 2 matches.\nmaster.guess("abcczz") returns 4, because "abcczz" has 4 matches.\nWe made 5 calls to master.guess and one of them was the secret, so we pass the test case.\n
    \n\n

    Example 2:

    \n\n
    \nInput: secret = "hamada", wordlist = ["hamada","khaled"], numguesses = 10\nOutput: You guessed the secret word correctly.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= wordlist.length <= 100
    • \n\t
    • wordlist[i].length == 6
    • \n\t
    • wordlist[i] consist of lowercase English letters.
    • \n\t
    • All the strings of wordlist are unique.
    • \n\t
    • secret exists in wordlist.
    • \n\t
    • numguesses == 10
    • \n
    \n", "content_cn": "

    \u8fd9\u4e2a\u95ee\u9898\u662f LeetCode \u5e73\u53f0\u65b0\u589e\u7684\u4ea4\u4e92\u5f0f\u95ee\u9898 \u3002

    \n\n

    \u6211\u4eec\u7ed9\u51fa\u4e86\u4e00\u4e2a\u7531\u4e00\u4e9b\u72ec\u7279\u7684\u5355\u8bcd\u7ec4\u6210\u7684\u5355\u8bcd\u5217\u8868\uff0c\u6bcf\u4e2a\u5355\u8bcd\u90fd\u662f 6 \u4e2a\u5b57\u6bcd\u957f\uff0c\u5e76\u4e14\u8fd9\u4e2a\u5217\u8868\u4e2d\u7684\u4e00\u4e2a\u5355\u8bcd\u5c06\u88ab\u9009\u4f5c\u79d8\u5bc6\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u8c03\u7528 master.guess(word) \u6765\u731c\u5355\u8bcd\u3002\u4f60\u6240\u731c\u7684\u5355\u8bcd\u5e94\u5f53\u662f\u5b58\u5728\u4e8e\u539f\u5217\u8868\u5e76\u4e14\u7531 6 \u4e2a\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210\u7684\u7c7b\u578b\u5b57\u7b26\u4e32\u3002

    \n\n

    \u6b64\u51fd\u6570\u5c06\u4f1a\u8fd4\u56de\u4e00\u4e2a\u6574\u578b\u6570\u5b57\uff0c\u8868\u793a\u4f60\u7684\u731c\u6d4b\u4e0e\u79d8\u5bc6\u5355\u8bcd\u7684\u51c6\u786e\u5339\u914d\uff08\u503c\u548c\u4f4d\u7f6e\u540c\u65f6\u5339\u914d\uff09\u7684\u6570\u76ee\u3002\u6b64\u5916\uff0c\u5982\u679c\u4f60\u7684\u731c\u6d4b\u4e0d\u5728\u7ed9\u5b9a\u7684\u5355\u8bcd\u5217\u8868\u4e2d\uff0c\u5b83\u5c06\u8fd4\u56de -1\u3002

    \n\n

    \u5bf9\u4e8e\u6bcf\u4e2a\u6d4b\u8bd5\u7528\u4f8b\uff0c\u4f60\u6709 10 \u6b21\u673a\u4f1a\u6765\u731c\u51fa\u8fd9\u4e2a\u5355\u8bcd\u3002\u5f53\u6240\u6709\u8c03\u7528\u90fd\u7ed3\u675f\u65f6\uff0c\u5982\u679c\u60a8\u5bf9 master.guess \u7684\u8c03\u7528\u4e0d\u8d85\u8fc7 10 \u6b21\uff0c\u5e76\u4e14\u81f3\u5c11\u6709\u4e00\u6b21\u731c\u5230\u79d8\u5bc6\uff0c\u90a3\u4e48\u60a8\u5c06\u901a\u8fc7\u8be5\u6d4b\u8bd5\u7528\u4f8b\u3002

    \n\n

    \u9664\u4e86\u4e0b\u9762\u793a\u4f8b\u7ed9\u51fa\u7684\u6d4b\u8bd5\u7528\u4f8b\u5916\uff0c\u8fd8\u4f1a\u6709 5 \u4e2a\u989d\u5916\u7684\u6d4b\u8bd5\u7528\u4f8b\uff0c\u6bcf\u4e2a\u5355\u8bcd\u5217\u8868\u4e2d\u5c06\u4f1a\u6709 100 \u4e2a\u5355\u8bcd\u3002\u8fd9\u4e9b\u6d4b\u8bd5\u7528\u4f8b\u4e2d\u7684\u6bcf\u4e2a\u5355\u8bcd\u7684\u5b57\u6bcd\u90fd\u662f\u4ece 'a' \u5230 'z' \u4e2d\u968f\u673a\u9009\u53d6\u7684\uff0c\u5e76\u4e14\u4fdd\u8bc1\u7ed9\u5b9a\u5355\u8bcd\u5217\u8868\u4e2d\u7684\u6bcf\u4e2a\u5355\u8bcd\u90fd\u662f\u552f\u4e00\u7684\u3002

    \n\n
    \u793a\u4f8b 1:\n\u8f93\u5165: secret = "acckzz", wordlist = ["acckzz","ccbazz","eiowzz","abcczz"]\n\n\u89e3\u91ca:\n\nmaster.guess("aaaaaa") \u8fd4\u56de -1, \u56e0\u4e3a "aaaaaa" \u4e0d\u5728 wordlist \u4e2d.\nmaster.guess("acckzz") \u8fd4\u56de 6, \u56e0\u4e3a "acckzz" \u5c31\u662f\u79d8\u5bc6\uff0c6\u4e2a\u5b57\u6bcd\u5b8c\u5168\u5339\u914d\u3002\nmaster.guess("ccbazz") \u8fd4\u56de 3, \u56e0\u4e3a "ccbazz" \u6709 3 \u4e2a\u5339\u914d\u9879\u3002\nmaster.guess("eiowzz") \u8fd4\u56de 2, \u56e0\u4e3a "eiowzz" \u6709 2 \u4e2a\u5339\u914d\u9879\u3002\nmaster.guess("abcczz") \u8fd4\u56de 4, \u56e0\u4e3a "abcczz" \u6709 4 \u4e2a\u5339\u914d\u9879\u3002\n\n\u6211\u4eec\u8c03\u7528\u4e86 5 \u6b21master.guess\uff0c\u5176\u4e2d\u4e00\u6b21\u731c\u5230\u4e86\u79d8\u5bc6\uff0c\u6240\u4ee5\u6211\u4eec\u901a\u8fc7\u4e86\u8fd9\u4e2a\u6d4b\u8bd5\u7528\u4f8b\u3002\n
    \n\n

    \u63d0\u793a\uff1a\u4efb\u4f55\u8bd5\u56fe\u7ed5\u8fc7\u8bc4\u5224\u7684\u89e3\u51b3\u65b9\u6848\u90fd\u5c06\u5bfc\u81f4\u6bd4\u8d5b\u8d44\u683c\u88ab\u53d6\u6d88\u3002

    \n", "tags_en": ["Minimax"], "tags_cn": ["\u6781\u5c0f\u5316\u6781\u5927"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * // This is the Master's API interface.\n * // You should not implement it, or speculate about its implementation\n * class Master {\n * public:\n * int guess(string word);\n * };\n */\nclass Solution {\npublic:\n void findSecretWord(vector& wordlist, Master& master) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * // This is the Master's API interface.\n * // You should not implement it, or speculate about its implementation\n * interface Master {\n * public int guess(String word) {}\n * }\n */\nclass Solution {\n public void findSecretWord(String[] wordlist, Master master) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# \"\"\"\n# This is Master's API interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class Master(object):\n# def guess(self, word):\n# \"\"\"\n# :type word: str\n# :rtype int\n# \"\"\"\n\nclass Solution(object):\n def findSecretWord(self, wordlist, master):\n \"\"\"\n :type wordlist: List[Str]\n :type master: Master\n :rtype: None\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# \"\"\"\n# This is Master's API interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n# class Master:\n# def guess(self, word: str) -> int:\n\nclass Solution:\n def findSecretWord(self, wordlist: List[str], master: 'Master') -> None:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * *********************************************************************\n * // This is the Master's API interface.\n * // You should not implement it, or speculate about its implementation\n * *********************************************************************\n *\n * int guess(Master *, char *word);\n */\nvoid findSecretWord(char** wordlist, int wordlistSize, Master* master) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * // This is the Master's API interface.\n * // You should not implement it, or speculate about its implementation\n * class Master {\n * public int Guess(string word);\n * }\n */\nclass Solution {\n public void FindSecretWord(string[] wordlist, Master master) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // This is the master's API interface.\n * // You should not implement it, or speculate about its implementation\n * function Master() {\n *\n * @param {string[]} wordlist\n * @param {Master} master\n * @return {integer}\n * this.guess = function(word) {\n * ...\n * };\n * };\n */\n/**\n * @param {string[]} wordlist\n * @param {Master} master\n * @return {void}\n */\nvar findSecretWord = function(wordlist, master) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# This is Master's API interface.\n# You should not implement it, or speculate about its implementation\n#\n# class Master\n# =begin\n# :type word: String\n# :rtype: Integer\n# =end\n# def guess(word)\n# ...\n# end\n# end\n#\n\n# @param {String[]} wordlist\n# @param {Master} master\n# @return {Void}\ndef find_secret_word(wordlist, master)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * // This is the Master's API interface.\n * // You should not implement it, or speculate about its implementation\n * class Master {\n * public func guess(word: String) -> Int {}\n * }\n */\nclass Solution {\n func findSecretWord(_ wordlist: [String], _ master: Master) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * // This is the Master's API interface.\n * // You should not implement it, or speculate about its implementation\n * type Master struct {\n * }\n *\n * func (this *Master) Guess(word string) int {}\n */\nfunc findSecretWord(wordlist []string, master *Master) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * // This is the Master's API interface.\n * // You should not implement it, or speculate about its implementation\n * class Master {\n *\n * def guess(word: String): Int = {}\n *\n * }\n */\nobject Solution {\n def findSecretWord(wordlist: Array[String], master: Master): Unit = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * // This is the Master's API interface.\n * // You should not implement it, or speculate about its implementation\n * interface Master {\n * fun guess(word: String): Int {}\n * }\n */\nclass Solution {\n fun findSecretWord(wordlist: Array, master: Master) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "/**\n * // This is the Master's API interface.\n * // You should not implement it, or speculate about its implementation\n * struct Master;\n * impl Master {\n * fn guess(word:String)->int;\n * };\n */\n\nimpl Solution {\n pub fn find_secret_word(words: Vec, master: &Master) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * // This is the Master's API interface.\n * // You should not implement it, or speculate about its implementation\n * interface Master {\n * function guess($word) {}\n * }\n */\n\nclass Solution {\n /**\n * @param String[] $wordlist\n * @param Master $master\n * @return \n */\n function findSecretWord($wordlist, $master) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * // This is the Master's API interface.\n * // You should not implement it, or speculate about its implementation\n * class Master {\n * guess(word: string): number {}\n * }\n */\n\nfunction findSecretWord(wordlist: string[], master: Master) {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0843](https://leetcode-cn.com/problems/guess-the-word)", "[\u731c\u731c\u8fd9\u4e2a\u5355\u8bcd](/solution/0800-0899/0843.Guess%20the%20Word/README.md)", "`\u6781\u5c0f\u5316\u6781\u5927`", "\u56f0\u96be", ""], "md_table_row_en": ["[0843](https://leetcode.com/problems/guess-the-word)", "[Guess the Word](/solution/0800-0899/0843.Guess%20the%20Word/README_EN.md)", "`Minimax`", "Hard", ""]}, {"question_id": "0872", "frontend_question_id": "0842", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/split-array-into-fibonacci-sequence", "url_en": "https://leetcode.com/problems/split-array-into-fibonacci-sequence", "relative_path_cn": "/solution/0800-0899/0842.Split%20Array%20into%20Fibonacci%20Sequence/README.md", "relative_path_en": "/solution/0800-0899/0842.Split%20Array%20into%20Fibonacci%20Sequence/README_EN.md", "title_cn": "\u5c06\u6570\u7ec4\u62c6\u5206\u6210\u6590\u6ce2\u90a3\u5951\u5e8f\u5217", "title_en": "Split Array into Fibonacci Sequence", "question_title_slug": "split-array-into-fibonacci-sequence", "content_en": "

    You are given a string of digits num, such as "123456579". We can split it into a Fibonacci-like sequence [123, 456, 579].

    \n\n

    Formally, a Fibonacci-like sequence is a list f of non-negative integers such that:

    \n\n
      \n\t
    • 0 <= f[i] < 231, (that is, each integer fits in a 32-bit signed integer type),
    • \n\t
    • f.length >= 3, and
    • \n\t
    • f[i] + f[i + 1] == f[i + 2] for all 0 <= i < f.length - 2.
    • \n
    \n\n

    Note that when splitting the string into pieces, each piece must not have extra leading zeroes, except if the piece is the number 0 itself.

    \n\n

    Return any Fibonacci-like sequence split from num, or return [] if it cannot be done.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: num = "123456579"\nOutput: [123,456,579]\n
    \n\n

    Example 2:

    \n\n
    \nInput: num = "11235813"\nOutput: [1,1,2,3,5,8,13]\n
    \n\n

    Example 3:

    \n\n
    \nInput: num = "112358130"\nOutput: []\nExplanation: The task is impossible.\n
    \n\n

    Example 4:

    \n\n
    \nInput: num = "0123"\nOutput: []\nExplanation: Leading zeroes are not allowed, so "01", "2", "3" is not valid.\n
    \n\n

    Example 5:

    \n\n
    \nInput: num = "1101111"\nOutput: [11,0,11,11]\nExplanation: The output [11, 0, 11, 11] would also be accepted.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= num.length <= 200
    • \n\t
    • num contains only digits.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6570\u5b57\u5b57\u7b26\u4e32 S\uff0c\u6bd4\u5982 S = "123456579"\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u5b83\u5206\u6210\u6590\u6ce2\u90a3\u5951\u5f0f\u7684\u5e8f\u5217 [123, 456, 579]\u3002

    \n\n

    \u5f62\u5f0f\u4e0a\uff0c\u6590\u6ce2\u90a3\u5951\u5f0f\u5e8f\u5217\u662f\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\u5217\u8868 F\uff0c\u4e14\u6ee1\u8db3\uff1a

    \n\n
      \n\t
    • 0 <= F[i] <= 2^31 - 1\uff0c\uff08\u4e5f\u5c31\u662f\u8bf4\uff0c\u6bcf\u4e2a\u6574\u6570\u90fd\u7b26\u5408 32 \u4f4d\u6709\u7b26\u53f7\u6574\u6570\u7c7b\u578b\uff09\uff1b
    • \n\t
    • F.length >= 3\uff1b
    • \n\t
    • \u5bf9\u4e8e\u6240\u6709\u76840 <= i < F.length - 2\uff0c\u90fd\u6709 F[i] + F[i+1] = F[i+2] \u6210\u7acb\u3002
    • \n
    \n\n

    \u53e6\u5916\uff0c\u8bf7\u6ce8\u610f\uff0c\u5c06\u5b57\u7b26\u4e32\u62c6\u5206\u6210\u5c0f\u5757\u65f6\uff0c\u6bcf\u4e2a\u5757\u7684\u6570\u5b57\u4e00\u5b9a\u4e0d\u8981\u4ee5\u96f6\u5f00\u5934\uff0c\u9664\u975e\u8fd9\u4e2a\u5757\u662f\u6570\u5b57 0 \u672c\u8eab\u3002

    \n\n

    \u8fd4\u56de\u4ece S \u62c6\u5206\u51fa\u6765\u7684\u4efb\u610f\u4e00\u7ec4\u6590\u6ce2\u90a3\u5951\u5f0f\u7684\u5e8f\u5217\u5757\uff0c\u5982\u679c\u4e0d\u80fd\u62c6\u5206\u5219\u8fd4\u56de []\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a"123456579"\n\u8f93\u51fa\uff1a[123,456,579]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165: "11235813"\n\u8f93\u51fa: [1,1,2,3,5,8,13]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165: "112358130"\n\u8f93\u51fa: []\n\u89e3\u91ca: \u8fd9\u9879\u4efb\u52a1\u65e0\u6cd5\u5b8c\u6210\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1a"0123"\n\u8f93\u51fa\uff1a[]\n\u89e3\u91ca\uff1a\u6bcf\u4e2a\u5757\u7684\u6570\u5b57\u4e0d\u80fd\u4ee5\u96f6\u5f00\u5934\uff0c\u56e0\u6b64 "01"\uff0c"2"\uff0c"3" \u4e0d\u662f\u6709\u6548\u7b54\u6848\u3002\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165: "1101111"\n\u8f93\u51fa: [110, 1, 111]\n\u89e3\u91ca: \u8f93\u51fa [11,0,11,11] \u4e5f\u540c\u6837\u88ab\u63a5\u53d7\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= S.length <= 200
    2. \n\t
    3. \u5b57\u7b26\u4e32 S \u4e2d\u53ea\u542b\u6709\u6570\u5b57\u3002
    4. \n
    \n", "tags_en": ["Greedy", "String", "Backtracking"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u5b57\u7b26\u4e32", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector splitIntoFibonacci(string num) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List splitIntoFibonacci(String num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def splitIntoFibonacci(self, num):\n \"\"\"\n :type num: str\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def splitIntoFibonacci(self, num: str) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* splitIntoFibonacci(char * num, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList SplitIntoFibonacci(string num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} num\n * @return {number[]}\n */\nvar splitIntoFibonacci = function(num) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} num\n# @return {Integer[]}\ndef split_into_fibonacci(num)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func splitIntoFibonacci(_ num: String) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func splitIntoFibonacci(num string) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def splitIntoFibonacci(num: String): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun splitIntoFibonacci(num: String): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn split_into_fibonacci(num: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $num\n * @return Integer[]\n */\n function splitIntoFibonacci($num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function splitIntoFibonacci(num: string): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (split-into-fibonacci num)\n (-> string? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0842](https://leetcode-cn.com/problems/split-array-into-fibonacci-sequence)", "[\u5c06\u6570\u7ec4\u62c6\u5206\u6210\u6590\u6ce2\u90a3\u5951\u5e8f\u5217](/solution/0800-0899/0842.Split%20Array%20into%20Fibonacci%20Sequence/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u5b57\u7b26\u4e32`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0842](https://leetcode.com/problems/split-array-into-fibonacci-sequence)", "[Split Array into Fibonacci Sequence](/solution/0800-0899/0842.Split%20Array%20into%20Fibonacci%20Sequence/README_EN.md)", "`Greedy`,`String`,`Backtracking`", "Medium", ""]}, {"question_id": "0871", "frontend_question_id": "0841", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/keys-and-rooms", "url_en": "https://leetcode.com/problems/keys-and-rooms", "relative_path_cn": "/solution/0800-0899/0841.Keys%20and%20Rooms/README.md", "relative_path_en": "/solution/0800-0899/0841.Keys%20and%20Rooms/README_EN.md", "title_cn": "\u94a5\u5319\u548c\u623f\u95f4", "title_en": "Keys and Rooms", "question_title_slug": "keys-and-rooms", "content_en": "

    There are N rooms and you start in room 0.  Each room has a distinct number in 0, 1, 2, ..., N-1, and each room may have some keys to access the next room. 

    \r\n\r\n

    Formally, each room i has a list of keys rooms[i], and each key rooms[i][j] is an integer in [0, 1, ..., N-1] where N = rooms.length.  A key rooms[i][j] = v opens the room with number v.

    \r\n\r\n

    Initially, all the rooms start locked (except for room 0). 

    \r\n\r\n

    You can walk back and forth between rooms freely.

    \r\n\r\n

    Return true if and only if you can enter every room.

    \r\n\r\n
      \r\n
    \r\n\r\n

    Example 1:

    \r\n\r\n
    \r\nInput: [[1],[2],[3],[]]\r\nOutput: true\r\nExplanation:  \r\nWe start in room 0, and pick up key 1.\r\nWe then go to room 1, and pick up key 2.\r\nWe then go to room 2, and pick up key 3.\r\nWe then go to room 3.  Since we were able to go to every room, we return true.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: [[1,3],[3,0,1],[2],[0]]\r\nOutput: false\r\nExplanation: We can't enter the room with number 2.\r\n
    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    1. 1 <= rooms.length <= 1000
    2. \r\n\t
    3. 0 <= rooms[i].length <= 1000
    4. \r\n\t
    5. The number of keys in all rooms combined is at most 3000.
    6. \r\n
    \r\n", "content_cn": "

    \u6709 N \u4e2a\u623f\u95f4\uff0c\u5f00\u59cb\u65f6\u4f60\u4f4d\u4e8e 0 \u53f7\u623f\u95f4\u3002\u6bcf\u4e2a\u623f\u95f4\u6709\u4e0d\u540c\u7684\u53f7\u7801\uff1a0\uff0c1\uff0c2\uff0c...\uff0cN-1\uff0c\u5e76\u4e14\u623f\u95f4\u91cc\u53ef\u80fd\u6709\u4e00\u4e9b\u94a5\u5319\u80fd\u4f7f\u4f60\u8fdb\u5165\u4e0b\u4e00\u4e2a\u623f\u95f4\u3002

    \n\n

    \u5728\u5f62\u5f0f\u4e0a\uff0c\u5bf9\u4e8e\u6bcf\u4e2a\u623f\u95f4 i \u90fd\u6709\u4e00\u4e2a\u94a5\u5319\u5217\u8868 rooms[i]\uff0c\u6bcf\u4e2a\u94a5\u5319 rooms[i][j] \u7531 [0,1\uff0c...\uff0cN-1] \u4e2d\u7684\u4e00\u4e2a\u6574\u6570\u8868\u793a\uff0c\u5176\u4e2d N = rooms.length\u3002 \u94a5\u5319 rooms[i][j] = v \u53ef\u4ee5\u6253\u5f00\u7f16\u53f7\u4e3a v \u7684\u623f\u95f4\u3002

    \n\n

    \u6700\u521d\uff0c\u9664 0 \u53f7\u623f\u95f4\u5916\u7684\u5176\u4f59\u6240\u6709\u623f\u95f4\u90fd\u88ab\u9501\u4f4f\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u81ea\u7531\u5730\u5728\u623f\u95f4\u4e4b\u95f4\u6765\u56de\u8d70\u52a8\u3002

    \n\n

    \u5982\u679c\u80fd\u8fdb\u5165\u6bcf\u4e2a\u623f\u95f4\u8fd4\u56de true\uff0c\u5426\u5219\u8fd4\u56de false\u3002

    \n\n
      \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165: [[1],[2],[3],[]]\n\u8f93\u51fa: true\n\u89e3\u91ca:  \n\u6211\u4eec\u4ece 0 \u53f7\u623f\u95f4\u5f00\u59cb\uff0c\u62ff\u5230\u94a5\u5319 1\u3002\n\u4e4b\u540e\u6211\u4eec\u53bb 1 \u53f7\u623f\u95f4\uff0c\u62ff\u5230\u94a5\u5319 2\u3002\n\u7136\u540e\u6211\u4eec\u53bb 2 \u53f7\u623f\u95f4\uff0c\u62ff\u5230\u94a5\u5319 3\u3002\n\u6700\u540e\u6211\u4eec\u53bb\u4e86 3 \u53f7\u623f\u95f4\u3002\n\u7531\u4e8e\u6211\u4eec\u80fd\u591f\u8fdb\u5165\u6bcf\u4e2a\u623f\u95f4\uff0c\u6211\u4eec\u8fd4\u56de true\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a[[1,3],[3,0,1],[2],[0]]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u6211\u4eec\u4e0d\u80fd\u8fdb\u5165 2 \u53f7\u623f\u95f4\u3002\n
    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= rooms.length <= 1000
    2. \n\t
    3. 0 <= rooms[i].length <= 1000
    4. \n\t
    5. \u6240\u6709\u623f\u95f4\u4e2d\u7684\u94a5\u5319\u6570\u91cf\u603b\u8ba1\u4e0d\u8d85\u8fc7 3000\u3002
    6. \n
    \n", "tags_en": ["Depth-first Search", "Graph"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canVisitAllRooms(vector>& rooms) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canVisitAllRooms(List> rooms) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canVisitAllRooms(self, rooms):\n \"\"\"\n :type rooms: List[List[int]]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canVisitAllRooms(self, rooms: List[List[int]]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canVisitAllRooms(int** rooms, int roomsSize, int* roomsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanVisitAllRooms(IList> rooms) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} rooms\n * @return {boolean}\n */\nvar canVisitAllRooms = function(rooms) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} rooms\n# @return {Boolean}\ndef can_visit_all_rooms(rooms)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canVisitAllRooms(_ rooms: [[Int]]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canVisitAllRooms(rooms [][]int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canVisitAllRooms(rooms: List[List[Int]]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canVisitAllRooms(rooms: List>): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_visit_all_rooms(rooms: Vec>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $rooms\n * @return Boolean\n */\n function canVisitAllRooms($rooms) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canVisitAllRooms(rooms: number[][]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-visit-all-rooms rooms)\n (-> (listof (listof exact-integer?)) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0841](https://leetcode-cn.com/problems/keys-and-rooms)", "[\u94a5\u5319\u548c\u623f\u95f4](/solution/0800-0899/0841.Keys%20and%20Rooms/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u56fe`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0841](https://leetcode.com/problems/keys-and-rooms)", "[Keys and Rooms](/solution/0800-0899/0841.Keys%20and%20Rooms/README_EN.md)", "`Depth-first Search`,`Graph`", "Medium", ""]}, {"question_id": "0870", "frontend_question_id": "0840", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/magic-squares-in-grid", "url_en": "https://leetcode.com/problems/magic-squares-in-grid", "relative_path_cn": "/solution/0800-0899/0840.Magic%20Squares%20In%20Grid/README.md", "relative_path_en": "/solution/0800-0899/0840.Magic%20Squares%20In%20Grid/README_EN.md", "title_cn": "\u77e9\u9635\u4e2d\u7684\u5e7b\u65b9", "title_en": "Magic Squares In Grid", "question_title_slug": "magic-squares-in-grid", "content_en": "

    A 3 x 3 magic square is a 3 x 3 grid filled with distinct numbers from 1 to 9 such that each row, column, and both diagonals all have the same sum.

    \n\n

    Given a row x col grid of integers, how many 3 x 3 "magic square" subgrids are there?  (Each subgrid is contiguous).

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: grid = [[4,3,8,4],[9,5,1,9],[2,7,6,2]]\nOutput: 1\nExplanation: \nThe following subgrid is a 3 x 3 magic square:\n\"\"\nwhile this one is not:\n\"\"\nIn total, there is only one magic square inside the given grid.\n
    \n\n

    Example 2:

    \n\n
    \nInput: grid = [[8]]\nOutput: 0\n
    \n\n

    Example 3:

    \n\n
    \nInput: grid = [[4,4],[3,3]]\nOutput: 0\n
    \n\n

    Example 4:

    \n\n
    \nInput: grid = [[4,7,8],[9,5,1],[2,3,6]]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • row == grid.length
    • \n\t
    • col == grid[i].length
    • \n\t
    • 1 <= row, col <= 10
    • \n\t
    • 0 <= grid[i][j] <= 15
    • \n
    \n", "content_cn": "

    3 x 3 \u7684\u5e7b\u65b9\u662f\u4e00\u4e2a\u586b\u5145\u6709\u4ece 1 \u5230 9 \u7684\u4e0d\u540c\u6570\u5b57\u7684 3 x 3 \u77e9\u9635\uff0c\u5176\u4e2d\u6bcf\u884c\uff0c\u6bcf\u5217\u4ee5\u53ca\u4e24\u6761\u5bf9\u89d2\u7ebf\u4e0a\u7684\u5404\u6570\u4e4b\u548c\u90fd\u76f8\u7b49\u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u7531\u6574\u6570\u7ec4\u6210\u7684 grid\uff0c\u5176\u4e2d\u6709\u591a\u5c11\u4e2a 3 × 3 \u7684 “\u5e7b\u65b9” \u5b50\u77e9\u9635\uff1f\uff08\u6bcf\u4e2a\u5b50\u77e9\u9635\u90fd\u662f\u8fde\u7eed\u7684\uff09\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165: [[4,3,8,4],\n      [9,5,1,9],\n      [2,7,6,2]]\n\u8f93\u51fa: 1\n\u89e3\u91ca: \n\u4e0b\u9762\u7684\u5b50\u77e9\u9635\u662f\u4e00\u4e2a 3 x 3 \u7684\u5e7b\u65b9\uff1a\n438\n951\n276\n\n\u800c\u8fd9\u4e00\u4e2a\u4e0d\u662f\uff1a\n384\n519\n762\n\n\u603b\u7684\u6765\u8bf4\uff0c\u5728\u672c\u793a\u4f8b\u6240\u7ed9\u5b9a\u7684\u77e9\u9635\u4e2d\u53ea\u6709\u4e00\u4e2a 3 x 3 \u7684\u5e7b\u65b9\u5b50\u77e9\u9635\u3002\n
    \n\n

    \u63d0\u793a:

    \n\n
      \n\t
    1. 1 <= grid.length <= 10
    2. \n\t
    3. 1 <= grid[0].length <= 10
    4. \n\t
    5. 0 <= grid[i][j] <= 15
    6. \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numMagicSquaresInside(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numMagicSquaresInside(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numMagicSquaresInside(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numMagicSquaresInside(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numMagicSquaresInside(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumMagicSquaresInside(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar numMagicSquaresInside = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef num_magic_squares_inside(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numMagicSquaresInside(_ grid: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numMagicSquaresInside(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numMagicSquaresInside(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numMagicSquaresInside(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_magic_squares_inside(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function numMagicSquaresInside($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numMagicSquaresInside(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-magic-squares-inside grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0840](https://leetcode-cn.com/problems/magic-squares-in-grid)", "[\u77e9\u9635\u4e2d\u7684\u5e7b\u65b9](/solution/0800-0899/0840.Magic%20Squares%20In%20Grid/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0840](https://leetcode.com/problems/magic-squares-in-grid)", "[Magic Squares In Grid](/solution/0800-0899/0840.Magic%20Squares%20In%20Grid/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0869", "frontend_question_id": "0839", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/similar-string-groups", "url_en": "https://leetcode.com/problems/similar-string-groups", "relative_path_cn": "/solution/0800-0899/0839.Similar%20String%20Groups/README.md", "relative_path_en": "/solution/0800-0899/0839.Similar%20String%20Groups/README_EN.md", "title_cn": "\u76f8\u4f3c\u5b57\u7b26\u4e32\u7ec4", "title_en": "Similar String Groups", "question_title_slug": "similar-string-groups", "content_en": "

    Two strings X and Y are similar if we can swap two letters (in different positions) of X, so that it equals Y. Also two strings X and Y are similar if they are equal.

    \n\n

    For example, "tars" and "rats" are similar (swapping at positions 0 and 2), and "rats" and "arts" are similar, but "star" is not similar to "tars", "rats", or "arts".

    \n\n

    Together, these form two connected groups by similarity: {"tars", "rats", "arts"} and {"star"}.  Notice that "tars" and "arts" are in the same group even though they are not similar.  Formally, each group is such that a word is in the group if and only if it is similar to at least one other word in the group.

    \n\n

    We are given a list strs of strings where every string in strs is an anagram of every other string in strs. How many groups are there?

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: strs = ["tars","rats","arts","star"]\nOutput: 2\n
    \n\n

    Example 2:

    \n\n
    \nInput: strs = ["omv","ovm"]\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= strs.length <= 300
    • \n\t
    • 1 <= strs[i].length <= 300
    • \n\t
    • strs[i] consists of lowercase letters only.
    • \n\t
    • All words in strs have the same length and are anagrams of each other.
    • \n
    \n", "content_cn": "

    \u5982\u679c\u4ea4\u6362\u5b57\u7b26\u4e32\u00a0X \u4e2d\u7684\u4e24\u4e2a\u4e0d\u540c\u4f4d\u7f6e\u7684\u5b57\u6bcd\uff0c\u4f7f\u5f97\u5b83\u548c\u5b57\u7b26\u4e32\u00a0Y \u76f8\u7b49\uff0c\u90a3\u4e48\u79f0 X \u548c Y \u4e24\u4e2a\u5b57\u7b26\u4e32\u76f8\u4f3c\u3002\u5982\u679c\u8fd9\u4e24\u4e2a\u5b57\u7b26\u4e32\u672c\u8eab\u662f\u76f8\u7b49\u7684\uff0c\u90a3\u5b83\u4eec\u4e5f\u662f\u76f8\u4f3c\u7684\u3002

    \n\n

    \u4f8b\u5982\uff0c\"tars\" \u548c \"rats\" \u662f\u76f8\u4f3c\u7684 (\u4ea4\u6362 0 \u4e0e 2 \u7684\u4f4d\u7f6e)\uff1b\u00a0\"rats\" \u548c \"arts\" \u4e5f\u662f\u76f8\u4f3c\u7684\uff0c\u4f46\u662f \"star\" \u4e0d\u4e0e \"tars\"\uff0c\"rats\"\uff0c\u6216 \"arts\" \u76f8\u4f3c\u3002

    \n\n

    \u603b\u4e4b\uff0c\u5b83\u4eec\u901a\u8fc7\u76f8\u4f3c\u6027\u5f62\u6210\u4e86\u4e24\u4e2a\u5173\u8054\u7ec4\uff1a{\"tars\", \"rats\", \"arts\"} \u548c {\"star\"}\u3002\u6ce8\u610f\uff0c\"tars\" \u548c \"arts\" \u662f\u5728\u540c\u4e00\u7ec4\u4e2d\uff0c\u5373\u4f7f\u5b83\u4eec\u5e76\u4e0d\u76f8\u4f3c\u3002\u5f62\u5f0f\u4e0a\uff0c\u5bf9\u6bcf\u4e2a\u7ec4\u800c\u8a00\uff0c\u8981\u786e\u5b9a\u4e00\u4e2a\u5355\u8bcd\u5728\u7ec4\u4e2d\uff0c\u53ea\u9700\u8981\u8fd9\u4e2a\u8bcd\u548c\u8be5\u7ec4\u4e2d\u81f3\u5c11\u4e00\u4e2a\u5355\u8bcd\u76f8\u4f3c\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32\u5217\u8868 strs\u3002\u5217\u8868\u4e2d\u7684\u6bcf\u4e2a\u5b57\u7b26\u4e32\u90fd\u662f strs \u4e2d\u5176\u5b83\u6240\u6709\u5b57\u7b26\u4e32\u7684\u4e00\u4e2a\u5b57\u6bcd\u5f02\u4f4d\u8bcd\u3002\u8bf7\u95ee strs \u4e2d\u6709\u591a\u5c11\u4e2a\u76f8\u4f3c\u5b57\u7b26\u4e32\u7ec4\uff1f

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1astrs = [\"tars\",\"rats\",\"arts\",\"star\"]\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1astrs = [\"omv\",\"ovm\"]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= strs.length <= 300
    • \n\t
    • 1 <= strs[i].length <= 300
    • \n\t
    • strs[i] \u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd\u3002
    • \n\t
    • strs \u4e2d\u7684\u6240\u6709\u5355\u8bcd\u90fd\u5177\u6709\u76f8\u540c\u7684\u957f\u5ea6\uff0c\u4e14\u662f\u5f7c\u6b64\u7684\u5b57\u6bcd\u5f02\u4f4d\u8bcd\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u5907\u6ce8\uff1a

    \n\n

    \u00a0\u00a0\u00a0\u00a0\u00a0 \u5b57\u6bcd\u5f02\u4f4d\u8bcd\uff08anagram\uff09\uff0c\u4e00\u79cd\u628a\u67d0\u4e2a\u5b57\u7b26\u4e32\u7684\u5b57\u6bcd\u7684\u4f4d\u7f6e\uff08\u987a\u5e8f\uff09\u52a0\u4ee5\u6539\u6362\u6240\u5f62\u6210\u7684\u65b0\u8bcd\u3002

    \n", "tags_en": ["Depth-first Search", "Union Find", "Graph"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e76\u67e5\u96c6", "\u56fe"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numSimilarGroups(vector& strs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numSimilarGroups(String[] strs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numSimilarGroups(self, strs):\n \"\"\"\n :type strs: List[str]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numSimilarGroups(self, strs: List[str]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numSimilarGroups(char ** strs, int strsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumSimilarGroups(string[] strs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} strs\n * @return {number}\n */\nvar numSimilarGroups = function(strs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} strs\n# @return {Integer}\ndef num_similar_groups(strs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numSimilarGroups(_ strs: [String]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numSimilarGroups(strs []string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numSimilarGroups(strs: Array[String]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numSimilarGroups(strs: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_similar_groups(strs: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $strs\n * @return Integer\n */\n function numSimilarGroups($strs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numSimilarGroups(strs: string[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-similar-groups strs)\n (-> (listof string?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0839](https://leetcode-cn.com/problems/similar-string-groups)", "[\u76f8\u4f3c\u5b57\u7b26\u4e32\u7ec4](/solution/0800-0899/0839.Similar%20String%20Groups/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e76\u67e5\u96c6`,`\u56fe`", "\u56f0\u96be", ""], "md_table_row_en": ["[0839](https://leetcode.com/problems/similar-string-groups)", "[Similar String Groups](/solution/0800-0899/0839.Similar%20String%20Groups/README_EN.md)", "`Depth-first Search`,`Union Find`,`Graph`", "Hard", ""]}, {"question_id": "0868", "frontend_question_id": "0838", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/push-dominoes", "url_en": "https://leetcode.com/problems/push-dominoes", "relative_path_cn": "/solution/0800-0899/0838.Push%20Dominoes/README.md", "relative_path_en": "/solution/0800-0899/0838.Push%20Dominoes/README_EN.md", "title_cn": "\u63a8\u591a\u7c73\u8bfa", "title_en": "Push Dominoes", "question_title_slug": "push-dominoes", "content_en": "

    There are N dominoes in a line, and we place each domino vertically upright.

    \r\n\r\n

    In the beginning, we simultaneously push some of the dominoes either to the left or to the right.

    \r\n\r\n

    \"\"

    \r\n\r\n

    After each second, each domino that is falling to the left pushes the adjacent domino on the left.

    \r\n\r\n

    Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right.

    \r\n\r\n

    When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces.

    \r\n\r\n

    For the purposes of this question, we will consider that a falling domino expends no additional force to a falling or already fallen domino.

    \r\n\r\n

    Given a string "S" representing the initial state. S[i] = 'L', if the i-th domino has been pushed to the left; S[i] = 'R', if the i-th domino has been pushed to the right; S[i] = '.', if the i-th domino has not been pushed.

    \r\n\r\n

    Return a string representing the final state. 

    \r\n\r\n

    Example 1:

    \r\n\r\n
    \r\nInput: ".L.R...LR..L.."\r\nOutput: "LL.RR.LLRRLL.."\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: "RR.L"\r\nOutput: "RR.L"\r\nExplanation: The first domino expends no additional force on the second domino.\r\n
    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    1. 0 <= N <= 10^5
    2. \r\n\t
    3. String dominoes contains only 'L', 'R' and '.'
    4. \r\n
    \r\n", "content_cn": "

    \u4e00\u884c\u4e2d\u6709 N \u5f20\u591a\u7c73\u8bfa\u9aa8\u724c\uff0c\u6211\u4eec\u5c06\u6bcf\u5f20\u591a\u7c73\u8bfa\u9aa8\u724c\u5782\u76f4\u7ad6\u7acb\u3002

    \n\n

    \u5728\u5f00\u59cb\u65f6\uff0c\u6211\u4eec\u540c\u65f6\u628a\u4e00\u4e9b\u591a\u7c73\u8bfa\u9aa8\u724c\u5411\u5de6\u6216\u5411\u53f3\u63a8\u3002

    \n\n

    \"\"

    \n\n

    \u6bcf\u8fc7\u4e00\u79d2\uff0c\u5012\u5411\u5de6\u8fb9\u7684\u591a\u7c73\u8bfa\u9aa8\u724c\u4f1a\u63a8\u52a8\u5176\u5de6\u4fa7\u76f8\u90bb\u7684\u591a\u7c73\u8bfa\u9aa8\u724c\u3002

    \n\n

    \u540c\u6837\u5730\uff0c\u5012\u5411\u53f3\u8fb9\u7684\u591a\u7c73\u8bfa\u9aa8\u724c\u4e5f\u4f1a\u63a8\u52a8\u7ad6\u7acb\u5728\u5176\u53f3\u4fa7\u7684\u76f8\u90bb\u591a\u7c73\u8bfa\u9aa8\u724c\u3002

    \n\n

    \u5982\u679c\u540c\u65f6\u6709\u591a\u7c73\u8bfa\u9aa8\u724c\u843d\u5728\u4e00\u5f20\u5782\u76f4\u7ad6\u7acb\u7684\u591a\u7c73\u8bfa\u9aa8\u724c\u7684\u4e24\u8fb9\uff0c\u7531\u4e8e\u53d7\u529b\u5e73\u8861\uff0c \u8be5\u9aa8\u724c\u4ecd\u7136\u4fdd\u6301\u4e0d\u53d8\u3002

    \n\n

    \u5c31\u8fd9\u4e2a\u95ee\u9898\u800c\u8a00\uff0c\u6211\u4eec\u4f1a\u8ba4\u4e3a\u6b63\u5728\u4e0b\u964d\u7684\u591a\u7c73\u8bfa\u9aa8\u724c\u4e0d\u4f1a\u5bf9\u5176\u5b83\u6b63\u5728\u4e0b\u964d\u6216\u5df2\u7ecf\u4e0b\u964d\u7684\u591a\u7c73\u8bfa\u9aa8\u724c\u65bd\u52a0\u989d\u5916\u7684\u529b\u3002

    \n\n

    \u7ed9\u5b9a\u8868\u793a\u521d\u59cb\u72b6\u6001\u7684\u5b57\u7b26\u4e32 "S" \u3002\u5982\u679c\u7b2c i \u5f20\u591a\u7c73\u8bfa\u9aa8\u724c\u88ab\u63a8\u5411\u5de6\u8fb9\uff0c\u5219 S[i] = 'L'\uff1b\u5982\u679c\u7b2c i \u5f20\u591a\u7c73\u8bfa\u9aa8\u724c\u88ab\u63a8\u5411\u53f3\u8fb9\uff0c\u5219 S[i] = 'R'\uff1b\u5982\u679c\u7b2c i \u5f20\u591a\u7c73\u8bfa\u9aa8\u724c\u6ca1\u6709\u88ab\u63a8\u52a8\uff0c\u5219 S[i] = '.'\u3002

    \n\n

    \u8fd4\u56de\u8868\u793a\u6700\u7ec8\u72b6\u6001\u7684\u5b57\u7b26\u4e32\u3002

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a".L.R...LR..L.."\n\u8f93\u51fa\uff1a"LL.RR.LLRRLL.."
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a"RR.L"\n\u8f93\u51fa\uff1a"RR.L"\n\u8bf4\u660e\uff1a\u7b2c\u4e00\u5f20\u591a\u7c73\u8bfa\u9aa8\u724c\u6ca1\u6709\u7ed9\u7b2c\u4e8c\u5f20\u65bd\u52a0\u989d\u5916\u7684\u529b\u3002
    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 0 <= N <= 10^5
    2. \n\t
    3. \u8868\u793a\u591a\u7c73\u8bfa\u9aa8\u724c\u72b6\u6001\u7684\u5b57\u7b26\u4e32\u53ea\u542b\u6709 'L'\uff0c'R'; \u4ee5\u53ca '.';
    4. \n
    \n", "tags_en": ["Two Pointers", "Dynamic Programming"], "tags_cn": ["\u53cc\u6307\u9488", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string pushDominoes(string dominoes) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String pushDominoes(String dominoes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def pushDominoes(self, dominoes):\n \"\"\"\n :type dominoes: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def pushDominoes(self, dominoes: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * pushDominoes(char * dominoes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string PushDominoes(string dominoes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} dominoes\n * @return {string}\n */\nvar pushDominoes = function(dominoes) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} dominoes\n# @return {String}\ndef push_dominoes(dominoes)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func pushDominoes(_ dominoes: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func pushDominoes(dominoes string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def pushDominoes(dominoes: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun pushDominoes(dominoes: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn push_dominoes(dominoes: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $dominoes\n * @return String\n */\n function pushDominoes($dominoes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function pushDominoes(dominoes: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (push-dominoes dominoes)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0838](https://leetcode-cn.com/problems/push-dominoes)", "[\u63a8\u591a\u7c73\u8bfa](/solution/0800-0899/0838.Push%20Dominoes/README.md)", "`\u53cc\u6307\u9488`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0838](https://leetcode.com/problems/push-dominoes)", "[Push Dominoes](/solution/0800-0899/0838.Push%20Dominoes/README_EN.md)", "`Two Pointers`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0867", "frontend_question_id": "0837", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/new-21-game", "url_en": "https://leetcode.com/problems/new-21-game", "relative_path_cn": "/solution/0800-0899/0837.New%2021%20Game/README.md", "relative_path_en": "/solution/0800-0899/0837.New%2021%20Game/README_EN.md", "title_cn": "\u65b021\u70b9", "title_en": "New 21 Game", "question_title_slug": "new-21-game", "content_en": "

    Alice plays the following game, loosely based on the card game "21".

    \n\n

    Alice starts with 0 points and draws numbers while she has less than k points. During each draw, she gains an integer number of points randomly from the range [1, maxPts], where maxPts is an integer. Each draw is independent and the outcomes have equal probabilities.

    \n\n

    Alice stops drawing numbers when she gets k or more points.

    \n\n

    Return the probability that Alice has n or fewer points.

    \n\n

    Answers within 10-5 of the actual answer are considered accepted.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 10, k = 1, maxPts = 10\nOutput: 1.00000\nExplanation: Alice gets a single card, then stops.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 6, k = 1, maxPts = 10\nOutput: 0.60000\nExplanation: Alice gets a single card, then stops.\nIn 6 out of 10 possibilities, she is at or below 6 points.\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 21, k = 17, maxPts = 10\nOutput: 0.73278\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= k <= n <= 104
    • \n\t
    • 1 <= maxPts <= 104
    • \n
    \n", "content_cn": "

    \u7231\u4e3d\u4e1d\u53c2\u4e0e\u4e00\u4e2a\u5927\u81f4\u57fa\u4e8e\u7eb8\u724c\u6e38\u620f “21\u70b9” \u89c4\u5219\u7684\u6e38\u620f\uff0c\u63cf\u8ff0\u5982\u4e0b\uff1a

    \n\n

    \u7231\u4e3d\u4e1d\u4ee5 0 \u5206\u5f00\u59cb\uff0c\u5e76\u5728\u5979\u7684\u5f97\u5206\u5c11\u4e8e K \u5206\u65f6\u62bd\u53d6\u6570\u5b57\u3002 \u62bd\u53d6\u65f6\uff0c\u5979\u4ece [1, W] \u7684\u8303\u56f4\u4e2d\u968f\u673a\u83b7\u5f97\u4e00\u4e2a\u6574\u6570\u4f5c\u4e3a\u5206\u6570\u8fdb\u884c\u7d2f\u8ba1\uff0c\u5176\u4e2d W \u662f\u6574\u6570\u3002 \u6bcf\u6b21\u62bd\u53d6\u90fd\u662f\u72ec\u7acb\u7684\uff0c\u5176\u7ed3\u679c\u5177\u6709\u76f8\u540c\u7684\u6982\u7387\u3002

    \n\n

    \u5f53\u7231\u4e3d\u4e1d\u83b7\u5f97\u4e0d\u5c11\u4e8e K \u5206\u65f6\uff0c\u5979\u5c31\u505c\u6b62\u62bd\u53d6\u6570\u5b57\u3002 \u7231\u4e3d\u4e1d\u7684\u5206\u6570\u4e0d\u8d85\u8fc7 N \u7684\u6982\u7387\u662f\u591a\u5c11\uff1f

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aN = 10, K = 1, W = 10\n\u8f93\u51fa\uff1a1.00000\n\u8bf4\u660e\uff1a\u7231\u4e3d\u4e1d\u5f97\u5230\u4e00\u5f20\u5361\uff0c\u7136\u540e\u505c\u6b62\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aN = 6, K = 1, W = 10\n\u8f93\u51fa\uff1a0.60000\n\u8bf4\u660e\uff1a\u7231\u4e3d\u4e1d\u5f97\u5230\u4e00\u5f20\u5361\uff0c\u7136\u540e\u505c\u6b62\u3002\n\u5728 W = 10 \u7684 6 \u79cd\u53ef\u80fd\u4e0b\uff0c\u5979\u7684\u5f97\u5206\u4e0d\u8d85\u8fc7 N = 6 \u5206\u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aN = 21, K = 17, W = 10\n\u8f93\u51fa\uff1a0.73278
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 0 <= K <= N <= 10000
    2. \n\t
    3. 1 <= W <= 10000
    4. \n\t
    5. \u5982\u679c\u7b54\u6848\u4e0e\u6b63\u786e\u7b54\u6848\u7684\u8bef\u5dee\u4e0d\u8d85\u8fc7 10^-5\uff0c\u5219\u8be5\u7b54\u6848\u5c06\u88ab\u89c6\u4e3a\u6b63\u786e\u7b54\u6848\u901a\u8fc7\u3002
    6. \n\t
    7. \u6b64\u95ee\u9898\u7684\u5224\u65ad\u9650\u5236\u65f6\u95f4\u5df2\u7ecf\u51cf\u5c11\u3002
    8. \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n double new21Game(int n, int k, int maxPts) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double new21Game(int n, int k, int maxPts) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def new21Game(self, n, k, maxPts):\n \"\"\"\n :type n: int\n :type k: int\n :type maxPts: int\n :rtype: float\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def new21Game(self, n: int, k: int, maxPts: int) -> float:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\ndouble new21Game(int n, int k, int maxPts){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double New21Game(int n, int k, int maxPts) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} k\n * @param {number} maxPts\n * @return {number}\n */\nvar new21Game = function(n, k, maxPts) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} k\n# @param {Integer} max_pts\n# @return {Float}\ndef new21_game(n, k, max_pts)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func new21Game(_ n: Int, _ k: Int, _ maxPts: Int) -> Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func new21Game(n int, k int, maxPts int) float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def new21Game(n: Int, k: Int, maxPts: Int): Double = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun new21Game(n: Int, k: Int, maxPts: Int): Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn new21_game(n: i32, k: i32, max_pts: i32) -> f64 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $k\n * @param Integer $maxPts\n * @return Float\n */\n function new21Game($n, $k, $maxPts) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function new21Game(n: number, k: number, maxPts: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (new21-game n k maxPts)\n (-> exact-integer? exact-integer? exact-integer? flonum?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0837](https://leetcode-cn.com/problems/new-21-game)", "[\u65b021\u70b9](/solution/0800-0899/0837.New%2021%20Game/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0837](https://leetcode.com/problems/new-21-game)", "[New 21 Game](/solution/0800-0899/0837.New%2021%20Game/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0866", "frontend_question_id": "0836", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/rectangle-overlap", "url_en": "https://leetcode.com/problems/rectangle-overlap", "relative_path_cn": "/solution/0800-0899/0836.Rectangle%20Overlap/README.md", "relative_path_en": "/solution/0800-0899/0836.Rectangle%20Overlap/README_EN.md", "title_cn": "\u77e9\u5f62\u91cd\u53e0", "title_en": "Rectangle Overlap", "question_title_slug": "rectangle-overlap", "content_en": "

    An axis-aligned rectangle is represented as a list [x1, y1, x2, y2], where (x1, y1) is the coordinate of its bottom-left corner, and (x2, y2) is the coordinate of its top-right corner. Its top and bottom edges are parallel to the X-axis, and its left and right edges are parallel to the Y-axis.

    \n\n

    Two rectangles overlap if the area of their intersection is positive. To be clear, two rectangles that only touch at the corner or edges do not overlap.

    \n\n

    Given two axis-aligned rectangles rec1 and rec2, return true if they overlap, otherwise return false.

    \n\n

     

    \n

    Example 1:

    \n
    Input: rec1 = [0,0,2,2], rec2 = [1,1,3,3]\nOutput: true\n

    Example 2:

    \n
    Input: rec1 = [0,0,1,1], rec2 = [1,0,2,1]\nOutput: false\n

    Example 3:

    \n
    Input: rec1 = [0,0,1,1], rec2 = [2,2,3,3]\nOutput: false\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • rect1.length == 4
    • \n\t
    • rect2.length == 4
    • \n\t
    • -109 <= rec1[i], rec2[i] <= 109
    • \n\t
    • rec1[0] <= rec1[2] and rec1[1] <= rec1[3]
    • \n\t
    • rec2[0] <= rec2[2] and rec2[1] <= rec2[3]
    • \n
    \n", "content_cn": "

    \u77e9\u5f62\u4ee5\u5217\u8868 [x1, y1, x2, y2] \u7684\u5f62\u5f0f\u8868\u793a\uff0c\u5176\u4e2d (x1, y1) \u4e3a\u5de6\u4e0b\u89d2\u7684\u5750\u6807\uff0c(x2, y2) \u662f\u53f3\u4e0a\u89d2\u7684\u5750\u6807\u3002\u77e9\u5f62\u7684\u4e0a\u4e0b\u8fb9\u5e73\u884c\u4e8e x \u8f74\uff0c\u5de6\u53f3\u8fb9\u5e73\u884c\u4e8e y \u8f74\u3002

    \n\n

    \u5982\u679c\u76f8\u4ea4\u7684\u9762\u79ef\u4e3a \u6b63 \uff0c\u5219\u79f0\u4e24\u77e9\u5f62\u91cd\u53e0\u3002\u9700\u8981\u660e\u786e\u7684\u662f\uff0c\u53ea\u5728\u89d2\u6216\u8fb9\u63a5\u89e6\u7684\u4e24\u4e2a\u77e9\u5f62\u4e0d\u6784\u6210\u91cd\u53e0\u3002

    \n\n

    \u7ed9\u51fa\u4e24\u4e2a\u77e9\u5f62 rec1 \u548c rec2 \u3002\u5982\u679c\u5b83\u4eec\u91cd\u53e0\uff0c\u8fd4\u56de true\uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1arec1 = [0,0,2,2], rec2 = [1,1,3,3]\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1arec1 = [0,0,1,1], rec2 = [1,0,2,1]\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1arec1 = [0,0,1,1], rec2 = [2,2,3,3]\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • rect1.length == 4
    • \n\t
    • rect2.length == 4
    • \n\t
    • -109 <= rec1[i], rec2[i] <= 109
    • \n\t
    • rec1[0] <= rec1[2] \u4e14 rec1[1] <= rec1[3]
    • \n\t
    • rec2[0] <= rec2[2] \u4e14 rec2[1] <= rec2[3]
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isRectangleOverlap(vector& rec1, vector& rec2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isRectangleOverlap(int[] rec1, int[] rec2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isRectangleOverlap(self, rec1, rec2):\n \"\"\"\n :type rec1: List[int]\n :type rec2: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isRectangleOverlap(int* rec1, int rec1Size, int* rec2, int rec2Size){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsRectangleOverlap(int[] rec1, int[] rec2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} rec1\n * @param {number[]} rec2\n * @return {boolean}\n */\nvar isRectangleOverlap = function(rec1, rec2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} rec1\n# @param {Integer[]} rec2\n# @return {Boolean}\ndef is_rectangle_overlap(rec1, rec2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isRectangleOverlap(_ rec1: [Int], _ rec2: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isRectangleOverlap(rec1 []int, rec2 []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isRectangleOverlap(rec1: Array[Int], rec2: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isRectangleOverlap(rec1: IntArray, rec2: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_rectangle_overlap(rec1: Vec, rec2: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $rec1\n * @param Integer[] $rec2\n * @return Boolean\n */\n function isRectangleOverlap($rec1, $rec2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isRectangleOverlap(rec1: number[], rec2: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-rectangle-overlap rec1 rec2)\n (-> (listof exact-integer?) (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0836](https://leetcode-cn.com/problems/rectangle-overlap)", "[\u77e9\u5f62\u91cd\u53e0](/solution/0800-0899/0836.Rectangle%20Overlap/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0836](https://leetcode.com/problems/rectangle-overlap)", "[Rectangle Overlap](/solution/0800-0899/0836.Rectangle%20Overlap/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "0865", "frontend_question_id": "0489", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/robot-room-cleaner", "url_en": "https://leetcode.com/problems/robot-room-cleaner", "relative_path_cn": "/solution/0400-0499/0489.Robot%20Room%20Cleaner/README.md", "relative_path_en": "/solution/0400-0499/0489.Robot%20Room%20Cleaner/README_EN.md", "title_cn": "\u626b\u5730\u673a\u5668\u4eba", "title_en": "Robot Room Cleaner", "question_title_slug": "robot-room-cleaner", "content_en": "

    Given a robot cleaner in a room modeled as a grid.

    \r\n\r\n

    Each cell in the grid can be empty or blocked.

    \r\n\r\n

    The robot cleaner with 4 given APIs can move forward, turn left or turn right. Each turn it made is 90 degrees.

    \r\n\r\n

    When it tries to move into a blocked cell, its bumper sensor detects the obstacle and it stays on the current cell.

    \r\n\r\n

    Design an algorithm to clean the entire room using only the 4 given APIs shown below.

    \r\n\r\n
    \r\ninterface Robot {\r\n  // returns true if next cell is open and robot moves into the cell.\r\n  // returns false if next cell is obstacle and robot stays on the current cell.\r\n  boolean move();\r\n\r\n  // Robot will stay on the same cell after calling turnLeft/turnRight.\r\n  // Each turn will be 90 degrees.\r\n  void turnLeft();\r\n  void turnRight();\r\n\r\n  // Clean the current cell.\r\n  void clean();\r\n}\r\n
    \r\n\r\n

    Example:

    \r\n\r\n
    \r\nInput:\r\nroom = [\r\n  [1,1,1,1,1,0,1,1],\r\n  [1,1,1,1,1,0,1,1],\r\n  [1,0,1,1,1,1,1,1],\r\n  [0,0,0,1,0,0,0,0],\r\n  [1,1,1,1,1,1,1,1]\r\n],\r\nrow = 1,\r\ncol = 3\r\n\r\nExplanation:\r\nAll grids in the room are marked by either 0 or 1.\r\n0 means the cell is blocked, while 1 means the cell is accessible.\r\nThe robot initially starts at the position of row=1, col=3.\r\nFrom the top left corner, its position is one row below and three columns right.\r\n
    \r\n\r\n

    Notes:

    \r\n\r\n
      \r\n\t
    1. The input is only given to initialize the room and the robot's position internally. You must solve this problem "blindfolded". In other words, you must control the robot using only the mentioned 4 APIs, without knowing the room layout and the initial robot's position.
    2. \r\n\t
    3. The robot's initial position will always be in an accessible cell.
    4. \r\n\t
    5. The initial direction of the robot will be facing up.
    6. \r\n\t
    7. All accessible cells are connected, which means the all cells marked as 1 will be accessible by the robot.
    8. \r\n\t
    9. Assume all four edges of the grid are all surrounded by wall.
    10. \r\n
    \r\n", "content_cn": "

    \u623f\u95f4\uff08\u7528\u683c\u6805\u8868\u793a\uff09\u4e2d\u6709\u4e00\u4e2a\u626b\u5730\u673a\u5668\u4eba\u3002\u683c\u6805\u4e2d\u7684\u6bcf\u4e00\u4e2a\u683c\u5b50\u6709\u7a7a\u548c\u969c\u788d\u7269\u4e24\u79cd\u53ef\u80fd\u3002

    \n\n

    \u626b\u5730\u673a\u5668\u4eba\u63d0\u4f9b4\u4e2aAPI\uff0c\u53ef\u4ee5\u5411\u524d\u8fdb\uff0c\u5411\u5de6\u8f6c\u6216\u8005\u5411\u53f3\u8f6c\u3002\u6bcf\u6b21\u8f6c\u5f2f90\u5ea6\u3002

    \n\n

    \u5f53\u626b\u5730\u673a\u5668\u4eba\u8bd5\u56fe\u8fdb\u5165\u969c\u788d\u7269\u683c\u5b50\u65f6\uff0c\u5b83\u7684\u78b0\u649e\u4f20\u611f\u5668\u4f1a\u63a2\u6d4b\u51fa\u969c\u788d\u7269\uff0c\u4f7f\u5b83\u505c\u7559\u5728\u539f\u5730\u3002

    \n\n

    \u8bf7\u5229\u7528\u63d0\u4f9b\u76844\u4e2aAPI\u7f16\u5199\u8ba9\u673a\u5668\u4eba\u6e05\u7406\u6574\u4e2a\u623f\u95f4\u7684\u7b97\u6cd5\u3002

    \n\n
    interface Robot {\n  // \u82e5\u4e0b\u4e00\u4e2a\u65b9\u683c\u4e3a\u7a7a\uff0c\u5219\u8fd4\u56detrue\uff0c\u5e76\u79fb\u52a8\u81f3\u8be5\u65b9\u683c\n  // \u82e5\u4e0b\u4e00\u4e2a\u65b9\u683c\u4e3a\u969c\u788d\u7269\uff0c\u5219\u8fd4\u56defalse\uff0c\u5e76\u505c\u7559\u5728\u539f\u5730\n  boolean move();\n\n  // \u5728\u8c03\u7528turnLeft/turnRight\u540e\u673a\u5668\u4eba\u4f1a\u505c\u7559\u5728\u539f\u4f4d\u7f6e\n  // \u6bcf\u6b21\u8f6c\u5f2f90\u5ea6\n  void turnLeft();\n  void turnRight();\n\n  // \u6e05\u7406\u6240\u5728\u65b9\u683c\n  void clean();\n}\n
    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165:\nroom = [\n  [1,1,1,1,1,0,1,1],\n  [1,1,1,1,1,0,1,1],\n  [1,0,1,1,1,1,1,1],\n  [0,0,0,1,0,0,0,0],\n  [1,1,1,1,1,1,1,1]\n],\nrow = 1,\ncol = 3\n\n\u89e3\u6790:\n\u623f\u95f4\u683c\u6805\u75280\u62161\u586b\u5145\u30020\u8868\u793a\u969c\u788d\u7269\uff0c1\u8868\u793a\u53ef\u4ee5\u901a\u8fc7\u3002\n\u673a\u5668\u4eba\u4ecerow=1\uff0ccol=3\u7684\u521d\u59cb\u4f4d\u7f6e\u51fa\u53d1\u3002\u5728\u5de6\u4e0a\u89d2\u7684\u4e00\u884c\u4ee5\u4e0b\uff0c\u4e09\u5217\u4ee5\u53f3\u3002\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u8f93\u5165\u53ea\u7528\u4e8e\u521d\u59cb\u5316\u623f\u95f4\u548c\u673a\u5668\u4eba\u7684\u4f4d\u7f6e\u3002\u4f60\u9700\u8981“\u76f2\u89e3”\u8fd9\u4e2a\u95ee\u9898\u3002\u6362\u800c\u8a00\u4e4b\uff0c\u4f60\u5fc5\u987b\u5728\u5bf9\u623f\u95f4\u548c\u673a\u5668\u4eba\u4f4d\u7f6e\u4e00\u65e0\u6240\u77e5\u7684\u60c5\u51b5\u4e0b\uff0c\u53ea\u4f7f\u75284\u4e2a\u7ed9\u51fa\u7684API\u89e3\u51b3\u95ee\u9898\u3002 
    2. \n\t
    3. \u626b\u5730\u673a\u5668\u4eba\u7684\u521d\u59cb\u4f4d\u7f6e\u4e00\u5b9a\u662f\u7a7a\u5730\u3002
    4. \n\t
    5. \u626b\u5730\u673a\u5668\u4eba\u7684\u521d\u59cb\u65b9\u5411\u5411\u4e0a\u3002
    6. \n\t
    7. \u6240\u6709\u53ef\u62b5\u8fbe\u7684\u683c\u5b50\u90fd\u662f\u76f8\u8fde\u7684\uff0c\u4ea6\u5373\u6240\u6709\u6807\u8bb0\u4e3a1\u7684\u683c\u5b50\u673a\u5668\u4eba\u90fd\u53ef\u4ee5\u62b5\u8fbe\u3002
    8. \n\t
    9. \u53ef\u4ee5\u5047\u5b9a\u683c\u6805\u7684\u56db\u5468\u90fd\u88ab\u5899\u5305\u56f4\u3002
    10. \n
    \n", "tags_en": ["Depth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * // This is the robot's control interface.\n * // You should not implement it, or speculate about its implementation\n * class Robot {\n * public:\n * // Returns true if the cell in front is open and robot moves into the cell.\n * // Returns false if the cell in front is blocked and robot stays in the current cell.\n * bool move();\n *\n * // Robot will stay in the same cell after calling turnLeft/turnRight.\n * // Each turn will be 90 degrees.\n * void turnLeft();\n * void turnRight();\n *\n * // Clean the current cell.\n * void clean();\n * };\n */\n\nclass Solution {\npublic:\n void cleanRoom(Robot& robot) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * // This is the robot's control interface.\n * // You should not implement it, or speculate about its implementation\n * interface Robot {\n * // Returns true if the cell in front is open and robot moves into the cell.\n * // Returns false if the cell in front is blocked and robot stays in the current cell.\n * public boolean move();\n *\n * // Robot will stay in the same cell after calling turnLeft/turnRight.\n * // Each turn will be 90 degrees.\n * public void turnLeft();\n * public void turnRight();\n *\n * // Clean the current cell.\n * public void clean();\n * }\n */\n\nclass Solution {\n public void cleanRoom(Robot robot) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# \"\"\"\n# This is the robot's control interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class Robot(object):\n# def move(self):\n# \"\"\"\n# Returns true if the cell in front is open and robot moves into the cell.\n# Returns false if the cell in front is blocked and robot stays in the current cell.\n# :rtype bool\n# \"\"\"\n#\n# def turnLeft(self):\n# \"\"\"\n# Robot will stay in the same cell after calling turnLeft/turnRight.\n# Each turn will be 90 degrees.\n# :rtype void\n# \"\"\"\n#\n# def turnRight(self):\n# \"\"\"\n# Robot will stay in the same cell after calling turnLeft/turnRight.\n# Each turn will be 90 degrees.\n# :rtype void\n# \"\"\"\n#\n# def clean(self):\n# \"\"\"\n# Clean the current cell.\n# :rtype void\n# \"\"\"\n\nclass Solution(object):\n def cleanRoom(self, robot):\n \"\"\"\n :type robot: Robot\n :rtype: None\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# \"\"\"\n# This is the robot's control interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class Robot:\n# def move(self):\n# \"\"\"\n# Returns true if the cell in front is open and robot moves into the cell.\n# Returns false if the cell in front is blocked and robot stays in the current cell.\n# :rtype bool\n# \"\"\"\n#\n# def turnLeft(self):\n# \"\"\"\n# Robot will stay in the same cell after calling turnLeft/turnRight.\n# Each turn will be 90 degrees.\n# :rtype void\n# \"\"\"\n#\n# def turnRight(self):\n# \"\"\"\n# Robot will stay in the same cell after calling turnLeft/turnRight.\n# Each turn will be 90 degrees.\n# :rtype void\n# \"\"\"\n#\n# def clean(self):\n# \"\"\"\n# Clean the current cell.\n# :rtype void\n# \"\"\"\n\nclass Solution:\n def cleanRoom(self, robot):\n \"\"\"\n :type robot: Robot\n :rtype: None\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * // This is the robot's control interface.\n * // You should not implement it, or speculate about its implementation\n * interface Robot {\n * // Returns true if the cell in front is open and robot moves into the cell.\n * // Returns false if the cell in front is blocked and robot stays in the current cell.\n * public bool Move();\n *\n * // Robot will stay in the same cell after calling turnLeft/turnRight.\n * // Each turn will be 90 degrees.\n * public void TurnLeft();\n * public void TurnRight();\n *\n * // Clean the current cell.\n * public void Clean();\n * }\n */\n\nclass Solution {\n public void CleanRoom(Robot robot) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // This is the robot's control interface.\n * // You should not implement it, or speculate about its implementation\n * function Robot() {\n * // Returns true if the cell in front is open and robot moves into the cell.\n * // Returns false if the cell in front is blocked and robot stays in the current cell.\n * @return {boolean}\n * this.move = function() {\n * ...\n * };\n *\n * // Robot will stay in the same cell after calling turnLeft/turnRight.\n * // Each turn will be 90 degrees.\n * @return {void}\n * this.turnLeft = function() {\n * ...\n * };\n * \n * // Robot will stay in the same cell after calling turnLeft/turnRight.\n * // Each turn will be 90 degrees.\n * @return {void} \n * this.turnRight = function() {\n * ...\n * };\n *\n * // Clean the current cell.\n * @return {void}\n * this.clean = function() {\n * ...\n * };\n * };\n */\n\n/**\n * @param {Robot} robot\n * @return {void}\n */\nvar cleanRoom = function(robot) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# This is the robot's control interface.\n# You should not implement it, or speculate about its implementation\n# class Robot\n# def move():\n# Returns true if the cell in front is open and robot moves into the cell.\n# Returns false if the cell in front is blocked and robot stays in the current cell.\n# end\n#\n# def turnLeft():\n# Robot will stay in the same cell after calling turnLeft/turnRight.\n# Each turn will be 90 degrees.\n# end\n#\n# def turnRight():\n# Robot will stay in the same cell after calling turnLeft/turnRight.\n# Each turn will be 90 degrees.\n# end\n#\n# def clean():\n# Clean the current cell.\n# end\n# end\n\n# @param {Robot} robot\n# @return {}\ndef cleanRoom(robot)\n\t\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * // This is the robot's control interface.\n * // You should not implement it, or speculate about its implementation\n * public class Robot {\n * // Returns true if the cell in front is open and robot moves into the cell.\n * // Returns false if the cell in front is blocked and robot stays in the current cell.\n * public func move() -> Bool {}\n *\n * // Robot will stay in the same cell after calling turnLeft/turnRight.\n * // Each turn will be 90 degrees.\n * public func turnLeft() {}\n * public func turnRight() {}\n *\n * // Clean the current cell.\n * public func clean() {}\n * }\n */\n\nclass Solution {\n func cleanRoom(_ robot: Robot) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * // This is the robot's control interface.\n * // You should not implement it, or speculate about its implementation\n * type Robot struct {\n * }\n * \n * // Returns true if the cell in front is open and robot moves into the cell.\n * // Returns false if the cell in front is blocked and robot stays in the current cell.\n * func (robot *Robot) Move() bool {}\n *\n * // Robot will stay in the same cell after calling TurnLeft/TurnRight.\n * // Each turn will be 90 degrees.\n * func (robot *Robot) TurnLeft() {}\n * func (robot *Robot) TurnRight() {}\n *\n * // Clean the current cell.\n * func (robot *Robot) Clean() {}\n */\n\nfunc cleanRoom(robot *Robot) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * // This is the robot's control interface.\n * // You should not implement it, or speculate about its implementation\n * class Robot {\n * // Returns true if the cell in front is open and robot moves into the cell.\n * // Returns false if the cell in front is blocked and robot stays in the current cell.\n * def move(): Boolean = {}\n *\n * // Robot will stay in the same cell after calling turnLeft/turnRight.\n * // Each turn will be 90 degrees.\n * def turnLeft(): Unit = {}\n * def turnRight(): Unit = {}\n *\n * // Clean the current cell.\n * def clean(): Unit = {}\n * }\n */\n\nobject Solution {\n def cleanRoom(robot: Robot): Unit = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * // This is the Robot's API interface.\n * // You should not implement it, or speculate about its implementation\n * class Robot {\n * // Returns true if the cell in front is open and robot moves into the cell.\n * // Returns false if the cell in front is blocked and robot stays in the current cell.\n * fun move(): Boolean {}\n *\n * // Robot will stay in the same cell after calling turnLeft/turnRight.\n * // Each turn will be 90 degrees.\n * fun turnLeft() {}\n * fun turnRight() {}\n *\n * // Clean the current cell.\n * fun clean() {}\n * }\n */\n\nclass Solution {\n fun cleanRoom(robot: Robot) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * // This is the Robot's control interface.\n * // You should not implement it, or speculate about its implementation\n * class Robot {\n * // Returns true if the cell in front is open and robot moves into the cell.\n * // Returns false if the cell in front is blocked and robot stays in the current cell.\n * function move() {}\n *\n * // Robot will stay in the same cell after calling turnLeft/turnRight.\n * // Each turn will be 90 degrees.\n * function turnLeft() {}\n * function turnRight() {}\n *\n * // Clean the current cell.\n * function clean() {}\n * }\n */\n\nclass Solution {\n /**\n * @param Robot $robot\n * @return \n */\n function cleanRoom($robot) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * class Robot {\n * // Returns true if the cell in front is open and robot moves into the cell.\n * // Returns false if the cell in front is blocked and robot stays in the current cell.\n * \t\tmove(): boolean {}\n * \t\t\n * // Robot will stay in the same cell after calling turnLeft/turnRight.\n * // Each turn will be 90 degrees.\n * \t\tturnRight() {}\n * \t\t\n * // Robot will stay in the same cell after calling turnLeft/turnRight.\n * // Each turn will be 90 degrees.\n * \t\tturnLeft() {}\n * \t\t\n * \t\t// Clean the current cell.\n * \t\tclean(): {}\n * }\n */\n\nfunction cleanRoom(robot: Robot) {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0489](https://leetcode-cn.com/problems/robot-room-cleaner)", "[\u626b\u5730\u673a\u5668\u4eba](/solution/0400-0499/0489.Robot%20Room%20Cleaner/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0489](https://leetcode.com/problems/robot-room-cleaner)", "[Robot Room Cleaner](/solution/0400-0499/0489.Robot%20Room%20Cleaner/README_EN.md)", "`Depth-first Search`", "Hard", "\ud83d\udd12"]}, {"question_id": "0864", "frontend_question_id": "0835", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/image-overlap", "url_en": "https://leetcode.com/problems/image-overlap", "relative_path_cn": "/solution/0800-0899/0835.Image%20Overlap/README.md", "relative_path_en": "/solution/0800-0899/0835.Image%20Overlap/README_EN.md", "title_cn": "\u56fe\u50cf\u91cd\u53e0", "title_en": "Image Overlap", "question_title_slug": "image-overlap", "content_en": "

    You are given two images img1 and img2 both of size n x n, represented as binary, square matrices of the same size. (A binary matrix has only 0s and 1s as values.)

    \n\n

    We translate one image however we choose (sliding it left, right, up, or down any number of units), and place it on top of the other image.  After, the overlap of this translation is the number of positions that have a 1 in both images.

    \n\n

    (Note also that a translation does not include any kind of rotation.)

    \n\n

    What is the largest possible overlap?

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: img1 = [[1,1,0],[0,1,0],[0,1,0]], img2 = [[0,0,0],[0,1,1],[0,0,1]]\nOutput: 3\nExplanation: We slide img1 to right by 1 unit and down by 1 unit.\n\"\"\nThe number of positions that have a 1 in both images is 3. (Shown in red)\n\"\"\n
    \n\n

    Example 2:

    \n\n
    \nInput: img1 = [[1]], img2 = [[1]]\nOutput: 1\n
    \n\n

    Example 3:

    \n\n
    \nInput: img1 = [[0]], img2 = [[0]]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == img1.length
    • \n\t
    • n == img1[i].length
    • \n\t
    • n == img2.length
    • \n\t
    • n == img2[i].length
    • \n\t
    • 1 <= n <= 30
    • \n\t
    • img1[i][j] is 0 or 1.
    • \n\t
    • img2[i][j] is 0 or 1.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u56fe\u50cf img1 \u548c img2 \uff0c\u4e24\u4e2a\u56fe\u50cf\u7684\u5927\u5c0f\u90fd\u662f n x n \uff0c\u7528\u5927\u5c0f\u76f8\u540c\u7684\u4e8c\u7ef4\u6b63\u65b9\u5f62\u77e9\u9635\u8868\u793a\u3002\uff08\u5e76\u4e14\u4e3a\u4e8c\u8fdb\u5236\u77e9\u9635\uff0c\u53ea\u5305\u542b\u82e5\u5e72 0 \u548c\u82e5\u5e72 1 \uff09

    \n\n

    \u8f6c\u6362\u5176\u4e2d\u4e00\u4e2a\u56fe\u50cf\uff0c\u5411\u5de6\uff0c\u53f3\uff0c\u4e0a\uff0c\u6216\u4e0b\u6ed1\u52a8\u4efb\u4f55\u6570\u91cf\u7684\u5355\u4f4d\uff0c\u5e76\u628a\u5b83\u653e\u5728\u53e6\u4e00\u4e2a\u56fe\u50cf\u7684\u4e0a\u9762\u3002\u4e4b\u540e\uff0c\u8be5\u8f6c\u6362\u7684 \u91cd\u53e0 \u662f\u6307\u4e24\u4e2a\u56fe\u50cf\u90fd\u5177\u6709 1 \u7684\u4f4d\u7f6e\u7684\u6570\u76ee\u3002

    \n\n
    \n
    \n

    \uff08\u8bf7\u6ce8\u610f\uff0c\u8f6c\u6362 \u4e0d\u5305\u62ec \u5411\u4efb\u4f55\u65b9\u5411\u65cb\u8f6c\u3002\uff09

    \n\n

    \u6700\u5927\u53ef\u80fd\u7684\u91cd\u53e0\u662f\u591a\u5c11\uff1f

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aimg1 = [[1,1,0],[0,1,0],[0,1,0]], img2 = [[0,0,0],[0,1,1],[0,0,1]]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u5c06 img1 \u5411\u53f3\u79fb\u52a8 1 \u4e2a\u5355\u4f4d\uff0c\u518d\u5411\u4e0b\u79fb\u52a8 1 \u4e2a\u5355\u4f4d\u3002\n\"\"\n\u4e24\u4e2a\u56fe\u50cf\u90fd\u5177\u6709 1 \u7684\u4f4d\u7f6e\u7684\u6570\u76ee\u662f 3\uff08\u7528\u7ea2\u8272\u6807\u8bc6\uff09\u3002\n\"\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aimg1 = [[1]], img2 = [[1]]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aimg1 = [[0]], img2 = [[0]]\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == img1.length
    • \n\t
    • n == img1[i].length
    • \n\t
    • n == img2.length
    • \n\t
    • n == img2[i].length
    • \n\t
    • 1 <= n <= 30
    • \n\t
    • img1[i][j] \u4e3a 0 \u6216 1
    • \n\t
    • img2[i][j] \u4e3a 0 \u6216 1
    • \n
    \n
    \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int largestOverlap(vector>& img1, vector>& img2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int largestOverlap(int[][] img1, int[][] img2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def largestOverlap(self, img1, img2):\n \"\"\"\n :type img1: List[List[int]]\n :type img2: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def largestOverlap(self, img1: List[List[int]], img2: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint largestOverlap(int** img1, int img1Size, int* img1ColSize, int** img2, int img2Size, int* img2ColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LargestOverlap(int[][] img1, int[][] img2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} img1\n * @param {number[][]} img2\n * @return {number}\n */\nvar largestOverlap = function(img1, img2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} img1\n# @param {Integer[][]} img2\n# @return {Integer}\ndef largest_overlap(img1, img2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func largestOverlap(_ img1: [[Int]], _ img2: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func largestOverlap(img1 [][]int, img2 [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def largestOverlap(img1: Array[Array[Int]], img2: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun largestOverlap(img1: Array, img2: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn largest_overlap(img1: Vec>, img2: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $img1\n * @param Integer[][] $img2\n * @return Integer\n */\n function largestOverlap($img1, $img2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function largestOverlap(img1: number[][], img2: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (largest-overlap img1 img2)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0835](https://leetcode-cn.com/problems/image-overlap)", "[\u56fe\u50cf\u91cd\u53e0](/solution/0800-0899/0835.Image%20Overlap/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0835](https://leetcode.com/problems/image-overlap)", "[Image Overlap](/solution/0800-0899/0835.Image%20Overlap/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0863", "frontend_question_id": "0834", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sum-of-distances-in-tree", "url_en": "https://leetcode.com/problems/sum-of-distances-in-tree", "relative_path_cn": "/solution/0800-0899/0834.Sum%20of%20Distances%20in%20Tree/README.md", "relative_path_en": "/solution/0800-0899/0834.Sum%20of%20Distances%20in%20Tree/README_EN.md", "title_cn": "\u6811\u4e2d\u8ddd\u79bb\u4e4b\u548c", "title_en": "Sum of Distances in Tree", "question_title_slug": "sum-of-distances-in-tree", "content_en": "

    An undirected, connected tree with n nodes labelled 0...n-1 and n-1 edges are given.

    \n\n

    The ith edge connects nodes edges[i][0] and edges[i][1] together.

    \n\n

    Return a list ans, where ans[i] is the sum of the distances between node i and all other nodes.

    \n\n

    Example 1:

    \n\n
    \nInput: n = 6, edges = [[0,1],[0,2],[2,3],[2,4],[2,5]]\nOutput: [8,12,6,10,10,10]\nExplanation: \nHere is a diagram of the given tree:\n  0\n / \\\n1   2\n   /|\\\n  3 4 5\nWe can see that dist(0,1) + dist(0,2) + dist(0,3) + dist(0,4) + dist(0,5)\nequals 1 + 1 + 2 + 2 + 2 = 8.  Hence, answer[0] = 8, and so on.\n
    \n\n

    Note: 1 <= n <= 10000

    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u65e0\u5411\u3001\u8fde\u901a\u7684\u6811\u3002\u6811\u4e2d\u6709 N \u4e2a\u6807\u8bb0\u4e3a 0...N-1 \u7684\u8282\u70b9\u4ee5\u53ca N-1 \u6761\u8fb9 \u3002

    \n\n

    \u7b2c i \u6761\u8fb9\u8fde\u63a5\u8282\u70b9 edges[i][0] \u548c edges[i][1] \u3002

    \n\n

    \u8fd4\u56de\u4e00\u4e2a\u8868\u793a\u8282\u70b9 i \u4e0e\u5176\u4ed6\u6240\u6709\u8282\u70b9\u8ddd\u79bb\u4e4b\u548c\u7684\u5217\u8868 ans\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: N = 6, edges = [[0,1],[0,2],[2,3],[2,4],[2,5]]\n\u8f93\u51fa: [8,12,6,10,10,10]\n\u89e3\u91ca: \n\u5982\u4e0b\u4e3a\u7ed9\u5b9a\u7684\u6811\u7684\u793a\u610f\u56fe\uff1a\n  0\n / \\\n1   2\n   /|\\\n  3 4 5\n\n\u6211\u4eec\u53ef\u4ee5\u8ba1\u7b97\u51fa dist(0,1) + dist(0,2) + dist(0,3) + dist(0,4) + dist(0,5) \n\u4e5f\u5c31\u662f 1 + 1 + 2 + 2 + 2 = 8\u3002 \u56e0\u6b64\uff0canswer[0] = 8\uff0c\u4ee5\u6b64\u7c7b\u63a8\u3002\n
    \n\n

    \u8bf4\u660e: 1 <= N <= 10000

    \n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector sumOfDistancesInTree(int n, vector>& edges) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] sumOfDistancesInTree(int n, int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def sumOfDistancesInTree(self, n, edges):\n \"\"\"\n :type n: int\n :type edges: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def sumOfDistancesInTree(self, n: int, edges: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* sumOfDistancesInTree(int n, int** edges, int edgesSize, int* edgesColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] SumOfDistancesInTree(int n, int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} edges\n * @return {number[]}\n */\nvar sumOfDistancesInTree = function(n, edges) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} edges\n# @return {Integer[]}\ndef sum_of_distances_in_tree(n, edges)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func sumOfDistancesInTree(_ n: Int, _ edges: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func sumOfDistancesInTree(n int, edges [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def sumOfDistancesInTree(n: Int, edges: Array[Array[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun sumOfDistancesInTree(n: Int, edges: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sum_of_distances_in_tree(n: i32, edges: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $edges\n * @return Integer[]\n */\n function sumOfDistancesInTree($n, $edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function sumOfDistancesInTree(n: number, edges: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (sum-of-distances-in-tree n edges)\n (-> exact-integer? (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0834](https://leetcode-cn.com/problems/sum-of-distances-in-tree)", "[\u6811\u4e2d\u8ddd\u79bb\u4e4b\u548c](/solution/0800-0899/0834.Sum%20of%20Distances%20in%20Tree/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[0834](https://leetcode.com/problems/sum-of-distances-in-tree)", "[Sum of Distances in Tree](/solution/0800-0899/0834.Sum%20of%20Distances%20in%20Tree/README_EN.md)", "`Tree`,`Depth-first Search`", "Hard", ""]}, {"question_id": "0862", "frontend_question_id": "0833", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-and-replace-in-string", "url_en": "https://leetcode.com/problems/find-and-replace-in-string", "relative_path_cn": "/solution/0800-0899/0833.Find%20And%20Replace%20in%20String/README.md", "relative_path_en": "/solution/0800-0899/0833.Find%20And%20Replace%20in%20String/README_EN.md", "title_cn": "\u5b57\u7b26\u4e32\u4e2d\u7684\u67e5\u627e\u4e0e\u66ff\u6362", "title_en": "Find And Replace in String", "question_title_slug": "find-and-replace-in-string", "content_en": "

    To some string s, we will perform some replacement operations that replace groups of letters with new ones (not necessarily the same size).

    \n\n

    Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.

    \n\n

    For example, if we have s = "abcd" and we have some replacement operation i = 2, x = "cd", y = "ffff", then because "cd" starts at position 2 in the original string s, we will replace it with "ffff".

    \n\n

    Using another example on s = "abcd", if we have both the replacement operation i = 0, x = "ab", y = "eee", as well as another replacement operation i = 2, x = "ec", y = "ffff", this second operation does nothing because in the original string s[2] = 'c', which doesn't match x[0] = 'e'.

    \n\n

    All these operations occur simultaneously. It's guaranteed that there won't be any overlap in replacement: for example, s = "abc", indexes = [0, 1], sources = ["ab","bc"] is not a valid test case.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "abcd", indexes = [0, 2], sources = ["a", "cd"], targets = ["eee", "ffff"]\nOutput: "eeebffff"\nExplanation:\n"a" starts at index 0 in s, so it's replaced by "eee".\n"cd" starts at index 2 in s, so it's replaced by "ffff".\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "abcd", indexes = [0, 2], sources = ["ab","ec"], targets = ["eee","ffff"]\nOutput: "eeecd"\nExplanation:\n"ab" starts at index 0 in s, so it's replaced by "eee".\n"ec" doesn't starts at index 2 in the original s, so we do nothing.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= s.length <= 1000
    • \n\t
    • s consists of only lowercase English letters.
    • \n\t
    • 0 <= indexes.length <= 100
    • \n\t
    • 0 <= indexes[i] < s.length
    • \n\t
    • sources.length == indexes.length
    • \n\t
    • targets.length == indexes.length
    • \n\t
    • 1 <= sources[i].length, targets[i].length <= 50
    • \n\t
    • sources[i] and targets[i] consist of only lowercase English letters.
    • \n
    \n", "content_cn": "

    \u67d0\u4e2a\u5b57\u7b26\u4e32 S \u9700\u8981\u6267\u884c\u4e00\u4e9b\u66ff\u6362\u64cd\u4f5c\uff0c\u7528\u65b0\u7684\u5b57\u6bcd\u7ec4\u66ff\u6362\u539f\u6709\u7684\u5b57\u6bcd\u7ec4\uff08\u4e0d\u4e00\u5b9a\u5927\u5c0f\u76f8\u540c\uff09\u3002

    \n\n

    \u6bcf\u4e2a\u66ff\u6362\u64cd\u4f5c\u5177\u6709 3 \u4e2a\u53c2\u6570\uff1a\u8d77\u59cb\u7d22\u5f15 i\uff0c\u6e90\u5b57 x \u548c\u76ee\u6807\u5b57 y\u3002\u89c4\u5219\u662f\uff1a\u5982\u679c x \u4ece\u539f\u59cb\u5b57\u7b26\u4e32 S \u4e2d\u7684\u4f4d\u7f6e i \u5f00\u59cb\uff0c\u90a3\u4e48\u5c31\u7528 y \u66ff\u6362\u51fa\u73b0\u7684 x\u3002\u5982\u679c\u6ca1\u6709\uff0c\u5219\u4ec0\u4e48\u90fd\u4e0d\u505a\u3002

    \n\n

    \u4e3e\u4e2a\u4f8b\u5b50\uff0c\u5982\u679c S\u00a0= \u201cabcd\u201d \u5e76\u4e14\u66ff\u6362\u64cd\u4f5c i = 2\uff0cx = \u201ccd\u201d\uff0cy = \u201cffff\u201d\uff0c\u90a3\u4e48\u56e0\u4e3a \u201ccd\u201d \u4ece\u539f\u59cb\u5b57\u7b26\u4e32 S \u4e2d\u7684\u4f4d\u7f6e 2 \u5f00\u59cb\uff0c\u6240\u4ee5\u7528\u00a0\u201cffff\u201d \u66ff\u6362\u5b83\u3002

    \n\n

    \u518d\u6765\u770b S = \u201cabcd\u201d \u4e0a\u7684\u53e6\u4e00\u4e2a\u4f8b\u5b50\uff0c\u5982\u679c\u4e00\u4e2a\u66ff\u6362\u64cd\u4f5c i = 0\uff0cx = \u201cab\u201d\uff0cy = \u201ceee\u201d\uff0c\u4ee5\u53ca\u53e6\u4e00\u4e2a\u66ff\u6362\u64cd\u4f5c i = 2\uff0cx = \u201cec\u201d\uff0cy = \u201cffff\u201d\uff0c\u90a3\u4e48\u7b2c\u4e8c\u4e2a\u64cd\u4f5c\u5c06\u4e0d\u4f1a\u6267\u884c\uff0c\u56e0\u4e3a\u539f\u59cb\u5b57\u7b26\u4e32\u4e2d\u00a0S[2] = 'c'\uff0c\u4e0e x[0] = 'e' \u4e0d\u5339\u914d\u3002

    \n\n

    \u6240\u6709\u8fd9\u4e9b\u64cd\u4f5c\u540c\u65f6\u53d1\u751f\u3002\u4fdd\u8bc1\u5728\u66ff\u6362\u65f6\u4e0d\u4f1a\u6709\u4efb\u4f55\u91cd\u53e0\uff1a\u00a0S = \"abc\", indexes = [0, 1],\u00a0sources = [\"ab\",\"bc\"] \u4e0d\u662f\u6709\u6548\u7684\u6d4b\u8bd5\u7528\u4f8b\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aS = \"abcd\", indexes = [0,2], sources = [\"a\",\"cd\"], targets = [\"eee\",\"ffff\"]\n\u8f93\u51fa\uff1a\"eeebffff\"\n\u89e3\u91ca\uff1a\n\"a\" \u4ece S \u4e2d\u7684\u7d22\u5f15 0 \u5f00\u59cb\uff0c\u6240\u4ee5\u5b83\u88ab\u66ff\u6362\u4e3a \"eee\"\u3002\n\"cd\" \u4ece S \u4e2d\u7684\u7d22\u5f15 2 \u5f00\u59cb\uff0c\u6240\u4ee5\u5b83\u88ab\u66ff\u6362\u4e3a \"ffff\"\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aS = \"abcd\", indexes = [0,2], sources = [\"ab\",\"ec\"], targets = [\"eee\",\"ffff\"]\n\u8f93\u51fa\uff1a\"eeecd\"\n\u89e3\u91ca\uff1a\n\"ab\" \u4ece S \u4e2d\u7684\u7d22\u5f15 0 \u5f00\u59cb\uff0c\u6240\u4ee5\u5b83\u88ab\u66ff\u6362\u4e3a \"eee\"\u3002\n\"ec\" \u6ca1\u6709\u4ece\u539f\u59cb\u7684 S \u4e2d\u7684\u7d22\u5f15 2 \u5f00\u59cb\uff0c\u6240\u4ee5\u5b83\u6ca1\u6709\u88ab\u66ff\u6362\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= S.length <= 1000
    • \n\t
    • S \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n\t
    • 0 <= indexes.length <= 100
    • \n\t
    • 0 <= indexes[i] < S.length
    • \n\t
    • sources.length == indexes.length
    • \n\t
    • targets.length == indexes.length
    • \n\t
    • 1 <= sources[i].length, targets[i].length <= 50
    • \n\t
    • sources[i] \u548c targets[i] \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n\n

    \u00a0

    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string findReplaceString(string s, vector& indexes, vector& sources, vector& targets) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String findReplaceString(String s, int[] indexes, String[] sources, String[] targets) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findReplaceString(self, s, indexes, sources, targets):\n \"\"\"\n :type s: str\n :type indexes: List[int]\n :type sources: List[str]\n :type targets: List[str]\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findReplaceString(self, s: str, indexes: List[int], sources: List[str], targets: List[str]) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * findReplaceString(char * s, int* indexes, int indexesSize, char ** sources, int sourcesSize, char ** targets, int targetsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string FindReplaceString(string s, int[] indexes, string[] sources, string[] targets) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number[]} indexes\n * @param {string[]} sources\n * @param {string[]} targets\n * @return {string}\n */\nvar findReplaceString = function(s, indexes, sources, targets) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer[]} indexes\n# @param {String[]} sources\n# @param {String[]} targets\n# @return {String}\ndef find_replace_string(s, indexes, sources, targets)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findReplaceString(_ s: String, _ indexes: [Int], _ sources: [String], _ targets: [String]) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findReplaceString(s string, indexes []int, sources []string, targets []string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findReplaceString(s: String, indexes: Array[Int], sources: Array[String], targets: Array[String]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findReplaceString(s: String, indexes: IntArray, sources: Array, targets: Array): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_replace_string(s: String, indexes: Vec, sources: Vec, targets: Vec) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer[] $indexes\n * @param String[] $sources\n * @param String[] $targets\n * @return String\n */\n function findReplaceString($s, $indexes, $sources, $targets) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findReplaceString(s: string, indexes: number[], sources: string[], targets: string[]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-replace-string s indexes sources targets)\n (-> string? (listof exact-integer?) (listof string?) (listof string?) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0833](https://leetcode-cn.com/problems/find-and-replace-in-string)", "[\u5b57\u7b26\u4e32\u4e2d\u7684\u67e5\u627e\u4e0e\u66ff\u6362](/solution/0800-0899/0833.Find%20And%20Replace%20in%20String/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0833](https://leetcode.com/problems/find-and-replace-in-string)", "[Find And Replace in String](/solution/0800-0899/0833.Find%20And%20Replace%20in%20String/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "0861", "frontend_question_id": "0832", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/flipping-an-image", "url_en": "https://leetcode.com/problems/flipping-an-image", "relative_path_cn": "/solution/0800-0899/0832.Flipping%20an%20Image/README.md", "relative_path_en": "/solution/0800-0899/0832.Flipping%20an%20Image/README_EN.md", "title_cn": "\u7ffb\u8f6c\u56fe\u50cf", "title_en": "Flipping an Image", "question_title_slug": "flipping-an-image", "content_en": "

    Given an n x n binary matrix image, flip the image horizontally, then invert it, and return the resulting image.

    \n\n

    To flip an image horizontally means that each row of the image is reversed.

    \n\n
      \n\t
    • For example, flipping [1,1,0] horizontally results in [0,1,1].
    • \n
    \n\n

    To invert an image means that each 0 is replaced by 1, and each 1 is replaced by 0.

    \n\n
      \n\t
    • For example, inverting [0,1,1] results in [1,0,0].
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: image = [[1,1,0],[1,0,1],[0,0,0]]\nOutput: [[1,0,0],[0,1,0],[1,1,1]]\nExplanation: First reverse each row: [[0,1,1],[1,0,1],[0,0,0]].\nThen, invert the image: [[1,0,0],[0,1,0],[1,1,1]]\n
    \n\n

    Example 2:

    \n\n
    \nInput: image = [[1,1,0,0],[1,0,0,1],[0,1,1,1],[1,0,1,0]]\nOutput: [[1,1,0,0],[0,1,1,0],[0,0,0,1],[1,0,1,0]]\nExplanation: First reverse each row: [[0,0,1,1],[1,0,0,1],[1,1,1,0],[0,1,0,1]].\nThen invert the image: [[1,1,0,0],[0,1,1,0],[0,0,0,1],[1,0,1,0]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == image.length
    • \n\t
    • n == image[i].length
    • \n\t
    • 1 <= n <= 20
    • \n\t
    • images[i][j] is either 0 or 1.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u8fdb\u5236\u77e9\u9635\u00a0A\uff0c\u6211\u4eec\u60f3\u5148\u6c34\u5e73\u7ffb\u8f6c\u56fe\u50cf\uff0c\u7136\u540e\u53cd\u8f6c\u56fe\u50cf\u5e76\u8fd4\u56de\u7ed3\u679c\u3002

    \n\n

    \u6c34\u5e73\u7ffb\u8f6c\u56fe\u7247\u5c31\u662f\u5c06\u56fe\u7247\u7684\u6bcf\u4e00\u884c\u90fd\u8fdb\u884c\u7ffb\u8f6c\uff0c\u5373\u9006\u5e8f\u3002\u4f8b\u5982\uff0c\u6c34\u5e73\u7ffb\u8f6c\u00a0[1, 1, 0]\u00a0\u7684\u7ed3\u679c\u662f\u00a0[0, 1, 1]\u3002

    \n\n

    \u53cd\u8f6c\u56fe\u7247\u7684\u610f\u601d\u662f\u56fe\u7247\u4e2d\u7684\u00a00\u00a0\u5168\u90e8\u88ab\u00a01\u00a0\u66ff\u6362\uff0c\u00a01\u00a0\u5168\u90e8\u88ab\u00a00\u00a0\u66ff\u6362\u3002\u4f8b\u5982\uff0c\u53cd\u8f6c\u00a0[0, 1, 1]\u00a0\u7684\u7ed3\u679c\u662f\u00a0[1, 0, 0]\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[[1,1,0],[1,0,1],[0,0,0]]\n\u8f93\u51fa\uff1a[[1,0,0],[0,1,0],[1,1,1]]\n\u89e3\u91ca\uff1a\u9996\u5148\u7ffb\u8f6c\u6bcf\u4e00\u884c: [[0,1,1],[1,0,1],[0,0,0]]\uff1b\n     \u7136\u540e\u53cd\u8f6c\u56fe\u7247: [[1,0,0],[0,1,0],[1,1,1]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[[1,1,0,0],[1,0,0,1],[0,1,1,1],[1,0,1,0]]\n\u8f93\u51fa\uff1a[[1,1,0,0],[0,1,1,0],[0,0,0,1],[1,0,1,0]]\n\u89e3\u91ca\uff1a\u9996\u5148\u7ffb\u8f6c\u6bcf\u4e00\u884c: [[0,0,1,1],[1,0,0,1],[1,1,1,0],[0,1,0,1]]\uff1b\n     \u7136\u540e\u53cd\u8f6c\u56fe\u7247: [[1,1,0,0],[0,1,1,0],[0,0,0,1],[1,0,1,0]]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= A.length = A[0].length <= 20
    • \n\t
    • 0 <= A[i][j]\u00a0<=\u00a01
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> flipAndInvertImage(vector>& image) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[][] flipAndInvertImage(int[][] image) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def flipAndInvertImage(self, image):\n \"\"\"\n :type image: List[List[int]]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def flipAndInvertImage(self, image: List[List[int]]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** flipAndInvertImage(int** image, int imageSize, int* imageColSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[][] FlipAndInvertImage(int[][] image) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} image\n * @return {number[][]}\n */\nvar flipAndInvertImage = function(image) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} image\n# @return {Integer[][]}\ndef flip_and_invert_image(image)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func flipAndInvertImage(_ image: [[Int]]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func flipAndInvertImage(image [][]int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def flipAndInvertImage(image: Array[Array[Int]]): Array[Array[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun flipAndInvertImage(image: Array): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn flip_and_invert_image(image: Vec>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $image\n * @return Integer[][]\n */\n function flipAndInvertImage($image) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function flipAndInvertImage(image: number[][]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (flip-and-invert-image image)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0832](https://leetcode-cn.com/problems/flipping-an-image)", "[\u7ffb\u8f6c\u56fe\u50cf](/solution/0800-0899/0832.Flipping%20an%20Image/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0832](https://leetcode.com/problems/flipping-an-image)", "[Flipping an Image](/solution/0800-0899/0832.Flipping%20an%20Image/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0860", "frontend_question_id": "0622", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/design-circular-queue", "url_en": "https://leetcode.com/problems/design-circular-queue", "relative_path_cn": "/solution/0600-0699/0622.Design%20Circular%20Queue/README.md", "relative_path_en": "/solution/0600-0699/0622.Design%20Circular%20Queue/README_EN.md", "title_cn": "\u8bbe\u8ba1\u5faa\u73af\u961f\u5217", "title_en": "Design Circular Queue", "question_title_slug": "design-circular-queue", "content_en": "

    Design your implementation of the circular queue. The circular queue is a linear data structure in which the operations are performed based on FIFO (First In First Out) principle and the last position is connected back to the first position to make a circle. It is also called "Ring Buffer".

    \n\n

    One of the benefits of the circular queue is that we can make use of the spaces in front of the queue. In a normal queue, once the queue becomes full, we cannot insert the next element even if there is a space in front of the queue. But using the circular queue, we can use the space to store new values.

    \n\n

    Implementation the MyCircularQueue class:

    \n\n
      \n\t
    • MyCircularQueue(k) Initializes the object with the size of the queue to be k.
    • \n\t
    • int Front() Gets the front item from the queue. If the queue is empty, return -1.
    • \n\t
    • int Rear() Gets the last item from the queue. If the queue is empty, return -1.
    • \n\t
    • boolean enQueue(int value) Inserts an element into the circular queue. Return true if the operation is successful.
    • \n\t
    • boolean deQueue() Deletes an element from the circular queue. Return true if the operation is successful.
    • \n\t
    • boolean isEmpty() Checks whether the circular queue is empty or not.
    • \n\t
    • boolean isFull() Checks whether the circular queue is full or not.
    • \n
    \n\n

    You must solve the problem without using the built-in queue data structure in your programming language. 

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["MyCircularQueue", "enQueue", "enQueue", "enQueue", "enQueue", "Rear", "isFull", "deQueue", "enQueue", "Rear"]\n[[3], [1], [2], [3], [4], [], [], [], [4], []]\nOutput\n[null, true, true, true, false, 3, true, true, true, 4]\n\nExplanation\nMyCircularQueue myCircularQueue = new MyCircularQueue(3);\nmyCircularQueue.enQueue(1); // return True\nmyCircularQueue.enQueue(2); // return True\nmyCircularQueue.enQueue(3); // return True\nmyCircularQueue.enQueue(4); // return False\nmyCircularQueue.Rear();     // return 3\nmyCircularQueue.isFull();   // return True\nmyCircularQueue.deQueue();  // return True\nmyCircularQueue.enQueue(4); // return True\nmyCircularQueue.Rear();     // return 4\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= k <= 1000
    • \n\t
    • 0 <= value <= 1000
    • \n\t
    • At most 3000 calls will be made to enQueue, deQueueFrontRearisEmpty, and isFull.
    • \n
    \n", "content_cn": "

    \u8bbe\u8ba1\u4f60\u7684\u5faa\u73af\u961f\u5217\u5b9e\u73b0\u3002 \u5faa\u73af\u961f\u5217\u662f\u4e00\u79cd\u7ebf\u6027\u6570\u636e\u7ed3\u6784\uff0c\u5176\u64cd\u4f5c\u8868\u73b0\u57fa\u4e8e FIFO\uff08\u5148\u8fdb\u5148\u51fa\uff09\u539f\u5219\u5e76\u4e14\u961f\u5c3e\u88ab\u8fde\u63a5\u5728\u961f\u9996\u4e4b\u540e\u4ee5\u5f62\u6210\u4e00\u4e2a\u5faa\u73af\u3002\u5b83\u4e5f\u88ab\u79f0\u4e3a“\u73af\u5f62\u7f13\u51b2\u5668”\u3002

    \n\n

    \u5faa\u73af\u961f\u5217\u7684\u4e00\u4e2a\u597d\u5904\u662f\u6211\u4eec\u53ef\u4ee5\u5229\u7528\u8fd9\u4e2a\u961f\u5217\u4e4b\u524d\u7528\u8fc7\u7684\u7a7a\u95f4\u3002\u5728\u4e00\u4e2a\u666e\u901a\u961f\u5217\u91cc\uff0c\u4e00\u65e6\u4e00\u4e2a\u961f\u5217\u6ee1\u4e86\uff0c\u6211\u4eec\u5c31\u4e0d\u80fd\u63d2\u5165\u4e0b\u4e00\u4e2a\u5143\u7d20\uff0c\u5373\u4f7f\u5728\u961f\u5217\u524d\u9762\u4ecd\u6709\u7a7a\u95f4\u3002\u4f46\u662f\u4f7f\u7528\u5faa\u73af\u961f\u5217\uff0c\u6211\u4eec\u80fd\u4f7f\u7528\u8fd9\u4e9b\u7a7a\u95f4\u53bb\u5b58\u50a8\u65b0\u7684\u503c\u3002

    \n\n

    \u4f60\u7684\u5b9e\u73b0\u5e94\u8be5\u652f\u6301\u5982\u4e0b\u64cd\u4f5c\uff1a

    \n\n
      \n\t
    • MyCircularQueue(k): \u6784\u9020\u5668\uff0c\u8bbe\u7f6e\u961f\u5217\u957f\u5ea6\u4e3a k \u3002
    • \n\t
    • Front: \u4ece\u961f\u9996\u83b7\u53d6\u5143\u7d20\u3002\u5982\u679c\u961f\u5217\u4e3a\u7a7a\uff0c\u8fd4\u56de -1 \u3002
    • \n\t
    • Rear: \u83b7\u53d6\u961f\u5c3e\u5143\u7d20\u3002\u5982\u679c\u961f\u5217\u4e3a\u7a7a\uff0c\u8fd4\u56de -1 \u3002
    • \n\t
    • enQueue(value): \u5411\u5faa\u73af\u961f\u5217\u63d2\u5165\u4e00\u4e2a\u5143\u7d20\u3002\u5982\u679c\u6210\u529f\u63d2\u5165\u5219\u8fd4\u56de\u771f\u3002
    • \n\t
    • deQueue(): \u4ece\u5faa\u73af\u961f\u5217\u4e2d\u5220\u9664\u4e00\u4e2a\u5143\u7d20\u3002\u5982\u679c\u6210\u529f\u5220\u9664\u5219\u8fd4\u56de\u771f\u3002
    • \n\t
    • isEmpty(): \u68c0\u67e5\u5faa\u73af\u961f\u5217\u662f\u5426\u4e3a\u7a7a\u3002
    • \n\t
    • isFull(): \u68c0\u67e5\u5faa\u73af\u961f\u5217\u662f\u5426\u5df2\u6ee1\u3002
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    MyCircularQueue circularQueue = new MyCircularQueue(3); // \u8bbe\u7f6e\u957f\u5ea6\u4e3a 3\ncircularQueue.enQueue(1);  // \u8fd4\u56de true\ncircularQueue.enQueue(2);  // \u8fd4\u56de true\ncircularQueue.enQueue(3);  // \u8fd4\u56de true\ncircularQueue.enQueue(4);  // \u8fd4\u56de false\uff0c\u961f\u5217\u5df2\u6ee1\ncircularQueue.Rear();  // \u8fd4\u56de 3\ncircularQueue.isFull();  // \u8fd4\u56de true\ncircularQueue.deQueue();  // \u8fd4\u56de true\ncircularQueue.enQueue(4);  // \u8fd4\u56de true\ncircularQueue.Rear();  // \u8fd4\u56de 4
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6240\u6709\u7684\u503c\u90fd\u5728 0 \u81f3 1000 \u7684\u8303\u56f4\u5185\uff1b
    • \n\t
    • \u64cd\u4f5c\u6570\u5c06\u5728 1 \u81f3 1000 \u7684\u8303\u56f4\u5185\uff1b
    • \n\t
    • \u8bf7\u4e0d\u8981\u4f7f\u7528\u5185\u7f6e\u7684\u961f\u5217\u5e93\u3002
    • \n
    \n", "tags_en": ["Design", "Queue"], "tags_cn": ["\u8bbe\u8ba1", "\u961f\u5217"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class MyCircularQueue {\npublic:\n MyCircularQueue(int k) {\n\n }\n \n bool enQueue(int value) {\n\n }\n \n bool deQueue() {\n\n }\n \n int Front() {\n\n }\n \n int Rear() {\n\n }\n \n bool isEmpty() {\n\n }\n \n bool isFull() {\n\n }\n};\n\n/**\n * Your MyCircularQueue object will be instantiated and called as such:\n * MyCircularQueue* obj = new MyCircularQueue(k);\n * bool param_1 = obj->enQueue(value);\n * bool param_2 = obj->deQueue();\n * int param_3 = obj->Front();\n * int param_4 = obj->Rear();\n * bool param_5 = obj->isEmpty();\n * bool param_6 = obj->isFull();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class MyCircularQueue {\n\n public MyCircularQueue(int k) {\n\n }\n \n public boolean enQueue(int value) {\n\n }\n \n public boolean deQueue() {\n\n }\n \n public int Front() {\n\n }\n \n public int Rear() {\n\n }\n \n public boolean isEmpty() {\n\n }\n \n public boolean isFull() {\n\n }\n}\n\n/**\n * Your MyCircularQueue object will be instantiated and called as such:\n * MyCircularQueue obj = new MyCircularQueue(k);\n * boolean param_1 = obj.enQueue(value);\n * boolean param_2 = obj.deQueue();\n * int param_3 = obj.Front();\n * int param_4 = obj.Rear();\n * boolean param_5 = obj.isEmpty();\n * boolean param_6 = obj.isFull();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class MyCircularQueue(object):\n\n def __init__(self, k):\n \"\"\"\n :type k: int\n \"\"\"\n\n\n def enQueue(self, value):\n \"\"\"\n :type value: int\n :rtype: bool\n \"\"\"\n\n\n def deQueue(self):\n \"\"\"\n :rtype: bool\n \"\"\"\n\n\n def Front(self):\n \"\"\"\n :rtype: int\n \"\"\"\n\n\n def Rear(self):\n \"\"\"\n :rtype: int\n \"\"\"\n\n\n def isEmpty(self):\n \"\"\"\n :rtype: bool\n \"\"\"\n\n\n def isFull(self):\n \"\"\"\n :rtype: bool\n \"\"\"\n\n\n\n# Your MyCircularQueue object will be instantiated and called as such:\n# obj = MyCircularQueue(k)\n# param_1 = obj.enQueue(value)\n# param_2 = obj.deQueue()\n# param_3 = obj.Front()\n# param_4 = obj.Rear()\n# param_5 = obj.isEmpty()\n# param_6 = obj.isFull()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class MyCircularQueue:\n\n def __init__(self, k: int):\n\n\n def enQueue(self, value: int) -> bool:\n\n\n def deQueue(self) -> bool:\n\n\n def Front(self) -> int:\n\n\n def Rear(self) -> int:\n\n\n def isEmpty(self) -> bool:\n\n\n def isFull(self) -> bool:\n\n\n\n# Your MyCircularQueue object will be instantiated and called as such:\n# obj = MyCircularQueue(k)\n# param_1 = obj.enQueue(value)\n# param_2 = obj.deQueue()\n# param_3 = obj.Front()\n# param_4 = obj.Rear()\n# param_5 = obj.isEmpty()\n# param_6 = obj.isFull()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} MyCircularQueue;\n\n\nMyCircularQueue* myCircularQueueCreate(int k) {\n\n}\n\nbool myCircularQueueEnQueue(MyCircularQueue* obj, int value) {\n\n}\n\nbool myCircularQueueDeQueue(MyCircularQueue* obj) {\n\n}\n\nint myCircularQueueFront(MyCircularQueue* obj) {\n\n}\n\nint myCircularQueueRear(MyCircularQueue* obj) {\n\n}\n\nbool myCircularQueueIsEmpty(MyCircularQueue* obj) {\n\n}\n\nbool myCircularQueueIsFull(MyCircularQueue* obj) {\n\n}\n\nvoid myCircularQueueFree(MyCircularQueue* obj) {\n\n}\n\n/**\n * Your MyCircularQueue struct will be instantiated and called as such:\n * MyCircularQueue* obj = myCircularQueueCreate(k);\n * bool param_1 = myCircularQueueEnQueue(obj, value);\n \n * bool param_2 = myCircularQueueDeQueue(obj);\n \n * int param_3 = myCircularQueueFront(obj);\n \n * int param_4 = myCircularQueueRear(obj);\n \n * bool param_5 = myCircularQueueIsEmpty(obj);\n \n * bool param_6 = myCircularQueueIsFull(obj);\n \n * myCircularQueueFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class MyCircularQueue {\n\n public MyCircularQueue(int k) {\n\n }\n \n public bool EnQueue(int value) {\n\n }\n \n public bool DeQueue() {\n\n }\n \n public int Front() {\n\n }\n \n public int Rear() {\n\n }\n \n public bool IsEmpty() {\n\n }\n \n public bool IsFull() {\n\n }\n}\n\n/**\n * Your MyCircularQueue object will be instantiated and called as such:\n * MyCircularQueue obj = new MyCircularQueue(k);\n * bool param_1 = obj.EnQueue(value);\n * bool param_2 = obj.DeQueue();\n * int param_3 = obj.Front();\n * int param_4 = obj.Rear();\n * bool param_5 = obj.IsEmpty();\n * bool param_6 = obj.IsFull();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} k\n */\nvar MyCircularQueue = function(k) {\n\n};\n\n/** \n * @param {number} value\n * @return {boolean}\n */\nMyCircularQueue.prototype.enQueue = function(value) {\n\n};\n\n/**\n * @return {boolean}\n */\nMyCircularQueue.prototype.deQueue = function() {\n\n};\n\n/**\n * @return {number}\n */\nMyCircularQueue.prototype.Front = function() {\n\n};\n\n/**\n * @return {number}\n */\nMyCircularQueue.prototype.Rear = function() {\n\n};\n\n/**\n * @return {boolean}\n */\nMyCircularQueue.prototype.isEmpty = function() {\n\n};\n\n/**\n * @return {boolean}\n */\nMyCircularQueue.prototype.isFull = function() {\n\n};\n\n/**\n * Your MyCircularQueue object will be instantiated and called as such:\n * var obj = new MyCircularQueue(k)\n * var param_1 = obj.enQueue(value)\n * var param_2 = obj.deQueue()\n * var param_3 = obj.Front()\n * var param_4 = obj.Rear()\n * var param_5 = obj.isEmpty()\n * var param_6 = obj.isFull()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class MyCircularQueue\n\n=begin\n :type k: Integer\n=end\n def initialize(k)\n\n end\n\n\n=begin\n :type value: Integer\n :rtype: Boolean\n=end\n def en_queue(value)\n\n end\n\n\n=begin\n :rtype: Boolean\n=end\n def de_queue()\n\n end\n\n\n=begin\n :rtype: Integer\n=end\n def front()\n\n end\n\n\n=begin\n :rtype: Integer\n=end\n def rear()\n\n end\n\n\n=begin\n :rtype: Boolean\n=end\n def is_empty()\n\n end\n\n\n=begin\n :rtype: Boolean\n=end\n def is_full()\n\n end\n\n\nend\n\n# Your MyCircularQueue object will be instantiated and called as such:\n# obj = MyCircularQueue.new(k)\n# param_1 = obj.en_queue(value)\n# param_2 = obj.de_queue()\n# param_3 = obj.front()\n# param_4 = obj.rear()\n# param_5 = obj.is_empty()\n# param_6 = obj.is_full()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass MyCircularQueue {\n\n init(_ k: Int) {\n\n }\n \n func enQueue(_ value: Int) -> Bool {\n\n }\n \n func deQueue() -> Bool {\n\n }\n \n func Front() -> Int {\n\n }\n \n func Rear() -> Int {\n\n }\n \n func isEmpty() -> Bool {\n\n }\n \n func isFull() -> Bool {\n\n }\n}\n\n/**\n * Your MyCircularQueue object will be instantiated and called as such:\n * let obj = MyCircularQueue(k)\n * let ret_1: Bool = obj.enQueue(value)\n * let ret_2: Bool = obj.deQueue()\n * let ret_3: Int = obj.Front()\n * let ret_4: Int = obj.Rear()\n * let ret_5: Bool = obj.isEmpty()\n * let ret_6: Bool = obj.isFull()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type MyCircularQueue struct {\n\n}\n\n\nfunc Constructor(k int) MyCircularQueue {\n\n}\n\n\nfunc (this *MyCircularQueue) EnQueue(value int) bool {\n\n}\n\n\nfunc (this *MyCircularQueue) DeQueue() bool {\n\n}\n\n\nfunc (this *MyCircularQueue) Front() int {\n\n}\n\n\nfunc (this *MyCircularQueue) Rear() int {\n\n}\n\n\nfunc (this *MyCircularQueue) IsEmpty() bool {\n\n}\n\n\nfunc (this *MyCircularQueue) IsFull() bool {\n\n}\n\n\n/**\n * Your MyCircularQueue object will be instantiated and called as such:\n * obj := Constructor(k);\n * param_1 := obj.EnQueue(value);\n * param_2 := obj.DeQueue();\n * param_3 := obj.Front();\n * param_4 := obj.Rear();\n * param_5 := obj.IsEmpty();\n * param_6 := obj.IsFull();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class MyCircularQueue(_k: Int) {\n\n def enQueue(value: Int): Boolean = {\n\n }\n\n def deQueue(): Boolean = {\n\n }\n\n def Front(): Int = {\n\n }\n\n def Rear(): Int = {\n\n }\n\n def isEmpty(): Boolean = {\n\n }\n\n def isFull(): Boolean = {\n\n }\n\n}\n\n/**\n * Your MyCircularQueue object will be instantiated and called as such:\n * var obj = new MyCircularQueue(k)\n * var param_1 = obj.enQueue(value)\n * var param_2 = obj.deQueue()\n * var param_3 = obj.Front()\n * var param_4 = obj.Rear()\n * var param_5 = obj.isEmpty()\n * var param_6 = obj.isFull()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class MyCircularQueue(k: Int) {\n\n fun enQueue(value: Int): Boolean {\n\n }\n\n fun deQueue(): Boolean {\n\n }\n\n fun Front(): Int {\n\n }\n\n fun Rear(): Int {\n\n }\n\n fun isEmpty(): Boolean {\n\n }\n\n fun isFull(): Boolean {\n\n }\n\n}\n\n/**\n * Your MyCircularQueue object will be instantiated and called as such:\n * var obj = MyCircularQueue(k)\n * var param_1 = obj.enQueue(value)\n * var param_2 = obj.deQueue()\n * var param_3 = obj.Front()\n * var param_4 = obj.Rear()\n * var param_5 = obj.isEmpty()\n * var param_6 = obj.isFull()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct MyCircularQueue {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl MyCircularQueue {\n\n fn new(k: i32) -> Self {\n\n }\n \n fn en_queue(&self, value: i32) -> bool {\n\n }\n \n fn de_queue(&self) -> bool {\n\n }\n \n fn front(&self) -> i32 {\n\n }\n \n fn rear(&self) -> i32 {\n\n }\n \n fn is_empty(&self) -> bool {\n\n }\n \n fn is_full(&self) -> bool {\n\n }\n}\n\n/**\n * Your MyCircularQueue object will be instantiated and called as such:\n * let obj = MyCircularQueue::new(k);\n * let ret_1: bool = obj.en_queue(value);\n * let ret_2: bool = obj.de_queue();\n * let ret_3: i32 = obj.front();\n * let ret_4: i32 = obj.rear();\n * let ret_5: bool = obj.is_empty();\n * let ret_6: bool = obj.is_full();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class MyCircularQueue {\n /**\n * @param Integer $k\n */\n function __construct($k) {\n\n }\n\n /**\n * @param Integer $value\n * @return Boolean\n */\n function enQueue($value) {\n\n }\n\n /**\n * @return Boolean\n */\n function deQueue() {\n\n }\n\n /**\n * @return Integer\n */\n function Front() {\n\n }\n\n /**\n * @return Integer\n */\n function Rear() {\n\n }\n\n /**\n * @return Boolean\n */\n function isEmpty() {\n\n }\n\n /**\n * @return Boolean\n */\n function isFull() {\n\n }\n}\n\n/**\n * Your MyCircularQueue object will be instantiated and called as such:\n * $obj = MyCircularQueue($k);\n * $ret_1 = $obj->enQueue($value);\n * $ret_2 = $obj->deQueue();\n * $ret_3 = $obj->Front();\n * $ret_4 = $obj->Rear();\n * $ret_5 = $obj->isEmpty();\n * $ret_6 = $obj->isFull();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class MyCircularQueue {\n constructor(k: number) {\n\n }\n\n enQueue(value: number): boolean {\n\n }\n\n deQueue(): boolean {\n\n }\n\n Front(): number {\n\n }\n\n Rear(): number {\n\n }\n\n isEmpty(): boolean {\n\n }\n\n isFull(): boolean {\n\n }\n}\n\n/**\n * Your MyCircularQueue object will be instantiated and called as such:\n * var obj = new MyCircularQueue(k)\n * var param_1 = obj.enQueue(value)\n * var param_2 = obj.deQueue()\n * var param_3 = obj.Front()\n * var param_4 = obj.Rear()\n * var param_5 = obj.isEmpty()\n * var param_6 = obj.isFull()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define my-circular-queue%\n (class object%\n (super-new)\n\n ; k : exact-integer?\n (init-field\n k)\n \n ; en-queue : exact-integer? -> boolean?\n (define/public (en-queue value)\n\n )\n ; de-queue : -> boolean?\n (define/public (de-queue)\n\n )\n ; front : -> exact-integer?\n (define/public (front)\n\n )\n ; rear : -> exact-integer?\n (define/public (rear)\n\n )\n ; is-empty : -> boolean?\n (define/public (is-empty)\n\n )\n ; is-full : -> boolean?\n (define/public (is-full)\n\n )))\n\n;; Your my-circular-queue% object will be instantiated and called as such:\n;; (define obj (new my-circular-queue% [k k]))\n;; (define param_1 (send obj en-queue value))\n;; (define param_2 (send obj de-queue))\n;; (define param_3 (send obj front))\n;; (define param_4 (send obj rear))\n;; (define param_5 (send obj is-empty))\n;; (define param_6 (send obj is-full))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0622](https://leetcode-cn.com/problems/design-circular-queue)", "[\u8bbe\u8ba1\u5faa\u73af\u961f\u5217](/solution/0600-0699/0622.Design%20Circular%20Queue/README.md)", "`\u8bbe\u8ba1`,`\u961f\u5217`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0622](https://leetcode.com/problems/design-circular-queue)", "[Design Circular Queue](/solution/0600-0699/0622.Design%20Circular%20Queue/README_EN.md)", "`Design`,`Queue`", "Medium", ""]}, {"question_id": "0859", "frontend_question_id": "0641", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/design-circular-deque", "url_en": "https://leetcode.com/problems/design-circular-deque", "relative_path_cn": "/solution/0600-0699/0641.Design%20Circular%20Deque/README.md", "relative_path_en": "/solution/0600-0699/0641.Design%20Circular%20Deque/README_EN.md", "title_cn": "\u8bbe\u8ba1\u5faa\u73af\u53cc\u7aef\u961f\u5217", "title_en": "Design Circular Deque", "question_title_slug": "design-circular-deque", "content_en": "

    Design your implementation of the circular double-ended queue (deque).

    \r\n\r\n

    Your implementation should support following operations:

    \r\n\r\n
      \r\n\t
    • MyCircularDeque(k): Constructor, set the size of the deque to be k.
    • \r\n\t
    • insertFront(): Adds an item at the front of Deque. Return true if the operation is successful.
    • \r\n\t
    • insertLast(): Adds an item at the rear of Deque. Return true if the operation is successful.
    • \r\n\t
    • deleteFront(): Deletes an item from the front of Deque. Return true if the operation is successful.
    • \r\n\t
    • deleteLast(): Deletes an item from the rear of Deque. Return true if the operation is successful.
    • \r\n\t
    • getFront(): Gets the front item from the Deque. If the deque is empty, return -1.
    • \r\n\t
    • getRear(): Gets the last item from Deque. If the deque is empty, return -1.
    • \r\n\t
    • isEmpty(): Checks whether Deque is empty or not. 
    • \r\n\t
    • isFull(): Checks whether Deque is full or not.
    • \r\n
    \r\n\r\n

     

    \r\n\r\n

    Example:

    \r\n\r\n
    \r\nMyCircularDeque circularDeque = new MycircularDeque(3); // set the size to be 3\r\ncircularDeque.insertLast(1);\t\t\t// return true\r\ncircularDeque.insertLast(2);\t\t\t// return true\r\ncircularDeque.insertFront(3);\t\t\t// return true\r\ncircularDeque.insertFront(4);\t\t\t// return false, the queue is full\r\ncircularDeque.getRear();  \t\t\t// return 2\r\ncircularDeque.isFull();\t\t\t\t// return true\r\ncircularDeque.deleteLast();\t\t\t// return true\r\ncircularDeque.insertFront(4);\t\t\t// return true\r\ncircularDeque.getFront();\t\t\t// return 4\r\n
    \r\n\r\n

     

    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    • All values will be in the range of [0, 1000].
    • \r\n\t
    • The number of operations will be in the range of [1, 1000].
    • \r\n\t
    • Please do not use the built-in Deque library.
    • \r\n
    \r\n", "content_cn": "

    \u8bbe\u8ba1\u5b9e\u73b0\u53cc\u7aef\u961f\u5217\u3002
    \n\u4f60\u7684\u5b9e\u73b0\u9700\u8981\u652f\u6301\u4ee5\u4e0b\u64cd\u4f5c\uff1a

    \n\n
      \n\t
    • MyCircularDeque(k)\uff1a\u6784\u9020\u51fd\u6570,\u53cc\u7aef\u961f\u5217\u7684\u5927\u5c0f\u4e3ak\u3002
    • \n\t
    • insertFront()\uff1a\u5c06\u4e00\u4e2a\u5143\u7d20\u6dfb\u52a0\u5230\u53cc\u7aef\u961f\u5217\u5934\u90e8\u3002 \u5982\u679c\u64cd\u4f5c\u6210\u529f\u8fd4\u56de true\u3002
    • \n\t
    • insertLast()\uff1a\u5c06\u4e00\u4e2a\u5143\u7d20\u6dfb\u52a0\u5230\u53cc\u7aef\u961f\u5217\u5c3e\u90e8\u3002\u5982\u679c\u64cd\u4f5c\u6210\u529f\u8fd4\u56de true\u3002
    • \n\t
    • deleteFront()\uff1a\u4ece\u53cc\u7aef\u961f\u5217\u5934\u90e8\u5220\u9664\u4e00\u4e2a\u5143\u7d20\u3002 \u5982\u679c\u64cd\u4f5c\u6210\u529f\u8fd4\u56de true\u3002
    • \n\t
    • deleteLast()\uff1a\u4ece\u53cc\u7aef\u961f\u5217\u5c3e\u90e8\u5220\u9664\u4e00\u4e2a\u5143\u7d20\u3002\u5982\u679c\u64cd\u4f5c\u6210\u529f\u8fd4\u56de true\u3002
    • \n\t
    • getFront()\uff1a\u4ece\u53cc\u7aef\u961f\u5217\u5934\u90e8\u83b7\u5f97\u4e00\u4e2a\u5143\u7d20\u3002\u5982\u679c\u53cc\u7aef\u961f\u5217\u4e3a\u7a7a\uff0c\u8fd4\u56de -1\u3002
    • \n\t
    • getRear()\uff1a\u83b7\u5f97\u53cc\u7aef\u961f\u5217\u7684\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u3002 \u5982\u679c\u53cc\u7aef\u961f\u5217\u4e3a\u7a7a\uff0c\u8fd4\u56de -1\u3002
    • \n\t
    • isEmpty()\uff1a\u68c0\u67e5\u53cc\u7aef\u961f\u5217\u662f\u5426\u4e3a\u7a7a\u3002
    • \n\t
    • isFull()\uff1a\u68c0\u67e5\u53cc\u7aef\u961f\u5217\u662f\u5426\u6ee1\u4e86\u3002
    • \n
    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    MyCircularDeque circularDeque = new MycircularDeque(3); // \u8bbe\u7f6e\u5bb9\u91cf\u5927\u5c0f\u4e3a3\ncircularDeque.insertLast(1);\t\t\t        // \u8fd4\u56de true\ncircularDeque.insertLast(2);\t\t\t        // \u8fd4\u56de true\ncircularDeque.insertFront(3);\t\t\t        // \u8fd4\u56de true\ncircularDeque.insertFront(4);\t\t\t        // \u5df2\u7ecf\u6ee1\u4e86\uff0c\u8fd4\u56de false\ncircularDeque.getRear();  \t\t\t\t// \u8fd4\u56de 2\ncircularDeque.isFull();\t\t\t\t        // \u8fd4\u56de true\ncircularDeque.deleteLast();\t\t\t        // \u8fd4\u56de true\ncircularDeque.insertFront(4);\t\t\t        // \u8fd4\u56de true\ncircularDeque.getFront();\t\t\t\t// \u8fd4\u56de 4\n 
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6240\u6709\u503c\u7684\u8303\u56f4\u4e3a [1, 1000]
    • \n\t
    • \u64cd\u4f5c\u6b21\u6570\u7684\u8303\u56f4\u4e3a [1, 1000]
    • \n\t
    • \u8bf7\u4e0d\u8981\u4f7f\u7528\u5185\u7f6e\u7684\u53cc\u7aef\u961f\u5217\u5e93\u3002
    • \n
    \n", "tags_en": ["Design", "Queue"], "tags_cn": ["\u8bbe\u8ba1", "\u961f\u5217"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class MyCircularDeque {\npublic:\n /** Initialize your data structure here. Set the size of the deque to be k. */\n MyCircularDeque(int k) {\n\n }\n \n /** Adds an item at the front of Deque. Return true if the operation is successful. */\n bool insertFront(int value) {\n\n }\n \n /** Adds an item at the rear of Deque. Return true if the operation is successful. */\n bool insertLast(int value) {\n\n }\n \n /** Deletes an item from the front of Deque. Return true if the operation is successful. */\n bool deleteFront() {\n\n }\n \n /** Deletes an item from the rear of Deque. Return true if the operation is successful. */\n bool deleteLast() {\n\n }\n \n /** Get the front item from the deque. */\n int getFront() {\n\n }\n \n /** Get the last item from the deque. */\n int getRear() {\n\n }\n \n /** Checks whether the circular deque is empty or not. */\n bool isEmpty() {\n\n }\n \n /** Checks whether the circular deque is full or not. */\n bool isFull() {\n\n }\n};\n\n/**\n * Your MyCircularDeque object will be instantiated and called as such:\n * MyCircularDeque* obj = new MyCircularDeque(k);\n * bool param_1 = obj->insertFront(value);\n * bool param_2 = obj->insertLast(value);\n * bool param_3 = obj->deleteFront();\n * bool param_4 = obj->deleteLast();\n * int param_5 = obj->getFront();\n * int param_6 = obj->getRear();\n * bool param_7 = obj->isEmpty();\n * bool param_8 = obj->isFull();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class MyCircularDeque {\n\n /** Initialize your data structure here. Set the size of the deque to be k. */\n public MyCircularDeque(int k) {\n\n }\n \n /** Adds an item at the front of Deque. Return true if the operation is successful. */\n public boolean insertFront(int value) {\n\n }\n \n /** Adds an item at the rear of Deque. Return true if the operation is successful. */\n public boolean insertLast(int value) {\n\n }\n \n /** Deletes an item from the front of Deque. Return true if the operation is successful. */\n public boolean deleteFront() {\n\n }\n \n /** Deletes an item from the rear of Deque. Return true if the operation is successful. */\n public boolean deleteLast() {\n\n }\n \n /** Get the front item from the deque. */\n public int getFront() {\n\n }\n \n /** Get the last item from the deque. */\n public int getRear() {\n\n }\n \n /** Checks whether the circular deque is empty or not. */\n public boolean isEmpty() {\n\n }\n \n /** Checks whether the circular deque is full or not. */\n public boolean isFull() {\n\n }\n}\n\n/**\n * Your MyCircularDeque object will be instantiated and called as such:\n * MyCircularDeque obj = new MyCircularDeque(k);\n * boolean param_1 = obj.insertFront(value);\n * boolean param_2 = obj.insertLast(value);\n * boolean param_3 = obj.deleteFront();\n * boolean param_4 = obj.deleteLast();\n * int param_5 = obj.getFront();\n * int param_6 = obj.getRear();\n * boolean param_7 = obj.isEmpty();\n * boolean param_8 = obj.isFull();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class MyCircularDeque(object):\n\n def __init__(self, k):\n \"\"\"\n Initialize your data structure here. Set the size of the deque to be k.\n :type k: int\n \"\"\"\n \n\n def insertFront(self, value):\n \"\"\"\n Adds an item at the front of Deque. Return true if the operation is successful.\n :type value: int\n :rtype: bool\n \"\"\"\n \n\n def insertLast(self, value):\n \"\"\"\n Adds an item at the rear of Deque. Return true if the operation is successful.\n :type value: int\n :rtype: bool\n \"\"\"\n \n\n def deleteFront(self):\n \"\"\"\n Deletes an item from the front of Deque. Return true if the operation is successful.\n :rtype: bool\n \"\"\"\n \n\n def deleteLast(self):\n \"\"\"\n Deletes an item from the rear of Deque. Return true if the operation is successful.\n :rtype: bool\n \"\"\"\n \n\n def getFront(self):\n \"\"\"\n Get the front item from the deque.\n :rtype: int\n \"\"\"\n \n\n def getRear(self):\n \"\"\"\n Get the last item from the deque.\n :rtype: int\n \"\"\"\n \n\n def isEmpty(self):\n \"\"\"\n Checks whether the circular deque is empty or not.\n :rtype: bool\n \"\"\"\n \n\n def isFull(self):\n \"\"\"\n Checks whether the circular deque is full or not.\n :rtype: bool\n \"\"\"\n \n\n\n# Your MyCircularDeque object will be instantiated and called as such:\n# obj = MyCircularDeque(k)\n# param_1 = obj.insertFront(value)\n# param_2 = obj.insertLast(value)\n# param_3 = obj.deleteFront()\n# param_4 = obj.deleteLast()\n# param_5 = obj.getFront()\n# param_6 = obj.getRear()\n# param_7 = obj.isEmpty()\n# param_8 = obj.isFull()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class MyCircularDeque:\n\n def __init__(self, k: int):\n \"\"\"\n Initialize your data structure here. Set the size of the deque to be k.\n \"\"\"\n \n\n def insertFront(self, value: int) -> bool:\n \"\"\"\n Adds an item at the front of Deque. Return true if the operation is successful.\n \"\"\"\n \n\n def insertLast(self, value: int) -> bool:\n \"\"\"\n Adds an item at the rear of Deque. Return true if the operation is successful.\n \"\"\"\n \n\n def deleteFront(self) -> bool:\n \"\"\"\n Deletes an item from the front of Deque. Return true if the operation is successful.\n \"\"\"\n \n\n def deleteLast(self) -> bool:\n \"\"\"\n Deletes an item from the rear of Deque. Return true if the operation is successful.\n \"\"\"\n \n\n def getFront(self) -> int:\n \"\"\"\n Get the front item from the deque.\n \"\"\"\n \n\n def getRear(self) -> int:\n \"\"\"\n Get the last item from the deque.\n \"\"\"\n \n\n def isEmpty(self) -> bool:\n \"\"\"\n Checks whether the circular deque is empty or not.\n \"\"\"\n \n\n def isFull(self) -> bool:\n \"\"\"\n Checks whether the circular deque is full or not.\n \"\"\"\n \n\n\n# Your MyCircularDeque object will be instantiated and called as such:\n# obj = MyCircularDeque(k)\n# param_1 = obj.insertFront(value)\n# param_2 = obj.insertLast(value)\n# param_3 = obj.deleteFront()\n# param_4 = obj.deleteLast()\n# param_5 = obj.getFront()\n# param_6 = obj.getRear()\n# param_7 = obj.isEmpty()\n# param_8 = obj.isFull()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} MyCircularDeque;\n\n/** Initialize your data structure here. Set the size of the deque to be k. */\n\nMyCircularDeque* myCircularDequeCreate(int k) {\n \n}\n\n/** Adds an item at the front of Deque. Return true if the operation is successful. */\nbool myCircularDequeInsertFront(MyCircularDeque* obj, int value) {\n \n}\n\n/** Adds an item at the rear of Deque. Return true if the operation is successful. */\nbool myCircularDequeInsertLast(MyCircularDeque* obj, int value) {\n \n}\n\n/** Deletes an item from the front of Deque. Return true if the operation is successful. */\nbool myCircularDequeDeleteFront(MyCircularDeque* obj) {\n \n}\n\n/** Deletes an item from the rear of Deque. Return true if the operation is successful. */\nbool myCircularDequeDeleteLast(MyCircularDeque* obj) {\n \n}\n\n/** Get the front item from the deque. */\nint myCircularDequeGetFront(MyCircularDeque* obj) {\n \n}\n\n/** Get the last item from the deque. */\nint myCircularDequeGetRear(MyCircularDeque* obj) {\n \n}\n\n/** Checks whether the circular deque is empty or not. */\nbool myCircularDequeIsEmpty(MyCircularDeque* obj) {\n \n}\n\n/** Checks whether the circular deque is full or not. */\nbool myCircularDequeIsFull(MyCircularDeque* obj) {\n \n}\n\nvoid myCircularDequeFree(MyCircularDeque* obj) {\n \n}\n\n/**\n * Your MyCircularDeque struct will be instantiated and called as such:\n * MyCircularDeque* obj = myCircularDequeCreate(k);\n * bool param_1 = myCircularDequeInsertFront(obj, value);\n \n * bool param_2 = myCircularDequeInsertLast(obj, value);\n \n * bool param_3 = myCircularDequeDeleteFront(obj);\n \n * bool param_4 = myCircularDequeDeleteLast(obj);\n \n * int param_5 = myCircularDequeGetFront(obj);\n \n * int param_6 = myCircularDequeGetRear(obj);\n \n * bool param_7 = myCircularDequeIsEmpty(obj);\n \n * bool param_8 = myCircularDequeIsFull(obj);\n \n * myCircularDequeFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class MyCircularDeque {\n\n /** Initialize your data structure here. Set the size of the deque to be k. */\n public MyCircularDeque(int k) {\n\n }\n \n /** Adds an item at the front of Deque. Return true if the operation is successful. */\n public bool InsertFront(int value) {\n\n }\n \n /** Adds an item at the rear of Deque. Return true if the operation is successful. */\n public bool InsertLast(int value) {\n\n }\n \n /** Deletes an item from the front of Deque. Return true if the operation is successful. */\n public bool DeleteFront() {\n\n }\n \n /** Deletes an item from the rear of Deque. Return true if the operation is successful. */\n public bool DeleteLast() {\n\n }\n \n /** Get the front item from the deque. */\n public int GetFront() {\n\n }\n \n /** Get the last item from the deque. */\n public int GetRear() {\n\n }\n \n /** Checks whether the circular deque is empty or not. */\n public bool IsEmpty() {\n\n }\n \n /** Checks whether the circular deque is full or not. */\n public bool IsFull() {\n\n }\n}\n\n/**\n * Your MyCircularDeque object will be instantiated and called as such:\n * MyCircularDeque obj = new MyCircularDeque(k);\n * bool param_1 = obj.InsertFront(value);\n * bool param_2 = obj.InsertLast(value);\n * bool param_3 = obj.DeleteFront();\n * bool param_4 = obj.DeleteLast();\n * int param_5 = obj.GetFront();\n * int param_6 = obj.GetRear();\n * bool param_7 = obj.IsEmpty();\n * bool param_8 = obj.IsFull();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Initialize your data structure here. Set the size of the deque to be k.\n * @param {number} k\n */\nvar MyCircularDeque = function(k) {\n\n};\n\n/**\n * Adds an item at the front of Deque. Return true if the operation is successful. \n * @param {number} value\n * @return {boolean}\n */\nMyCircularDeque.prototype.insertFront = function(value) {\n\n};\n\n/**\n * Adds an item at the rear of Deque. Return true if the operation is successful. \n * @param {number} value\n * @return {boolean}\n */\nMyCircularDeque.prototype.insertLast = function(value) {\n\n};\n\n/**\n * Deletes an item from the front of Deque. Return true if the operation is successful.\n * @return {boolean}\n */\nMyCircularDeque.prototype.deleteFront = function() {\n\n};\n\n/**\n * Deletes an item from the rear of Deque. Return true if the operation is successful.\n * @return {boolean}\n */\nMyCircularDeque.prototype.deleteLast = function() {\n\n};\n\n/**\n * Get the front item from the deque.\n * @return {number}\n */\nMyCircularDeque.prototype.getFront = function() {\n\n};\n\n/**\n * Get the last item from the deque.\n * @return {number}\n */\nMyCircularDeque.prototype.getRear = function() {\n\n};\n\n/**\n * Checks whether the circular deque is empty or not.\n * @return {boolean}\n */\nMyCircularDeque.prototype.isEmpty = function() {\n\n};\n\n/**\n * Checks whether the circular deque is full or not.\n * @return {boolean}\n */\nMyCircularDeque.prototype.isFull = function() {\n\n};\n\n/**\n * Your MyCircularDeque object will be instantiated and called as such:\n * var obj = new MyCircularDeque(k)\n * var param_1 = obj.insertFront(value)\n * var param_2 = obj.insertLast(value)\n * var param_3 = obj.deleteFront()\n * var param_4 = obj.deleteLast()\n * var param_5 = obj.getFront()\n * var param_6 = obj.getRear()\n * var param_7 = obj.isEmpty()\n * var param_8 = obj.isFull()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class MyCircularDeque\n\n=begin\n Initialize your data structure here. Set the size of the deque to be k.\n :type k: Integer\n=end\n def initialize(k)\n\n end\n\n\n=begin\n Adds an item at the front of Deque. Return true if the operation is successful.\n :type value: Integer\n :rtype: Boolean\n=end\n def insert_front(value)\n\n end\n\n\n=begin\n Adds an item at the rear of Deque. Return true if the operation is successful.\n :type value: Integer\n :rtype: Boolean\n=end\n def insert_last(value)\n\n end\n\n\n=begin\n Deletes an item from the front of Deque. Return true if the operation is successful.\n :rtype: Boolean\n=end\n def delete_front()\n\n end\n\n\n=begin\n Deletes an item from the rear of Deque. Return true if the operation is successful.\n :rtype: Boolean\n=end\n def delete_last()\n\n end\n\n\n=begin\n Get the front item from the deque.\n :rtype: Integer\n=end\n def get_front()\n\n end\n\n\n=begin\n Get the last item from the deque.\n :rtype: Integer\n=end\n def get_rear()\n\n end\n\n\n=begin\n Checks whether the circular deque is empty or not.\n :rtype: Boolean\n=end\n def is_empty()\n\n end\n\n\n=begin\n Checks whether the circular deque is full or not.\n :rtype: Boolean\n=end\n def is_full()\n\n end\n\n\nend\n\n# Your MyCircularDeque object will be instantiated and called as such:\n# obj = MyCircularDeque.new(k)\n# param_1 = obj.insert_front(value)\n# param_2 = obj.insert_last(value)\n# param_3 = obj.delete_front()\n# param_4 = obj.delete_last()\n# param_5 = obj.get_front()\n# param_6 = obj.get_rear()\n# param_7 = obj.is_empty()\n# param_8 = obj.is_full()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass MyCircularDeque {\n\n /** Initialize your data structure here. Set the size of the deque to be k. */\n init(_ k: Int) {\n \n }\n \n /** Adds an item at the front of Deque. Return true if the operation is successful. */\n func insertFront(_ value: Int) -> Bool {\n \n }\n \n /** Adds an item at the rear of Deque. Return true if the operation is successful. */\n func insertLast(_ value: Int) -> Bool {\n \n }\n \n /** Deletes an item from the front of Deque. Return true if the operation is successful. */\n func deleteFront() -> Bool {\n \n }\n \n /** Deletes an item from the rear of Deque. Return true if the operation is successful. */\n func deleteLast() -> Bool {\n \n }\n \n /** Get the front item from the deque. */\n func getFront() -> Int {\n \n }\n \n /** Get the last item from the deque. */\n func getRear() -> Int {\n \n }\n \n /** Checks whether the circular deque is empty or not. */\n func isEmpty() -> Bool {\n \n }\n \n /** Checks whether the circular deque is full or not. */\n func isFull() -> Bool {\n \n }\n}\n\n/**\n * Your MyCircularDeque object will be instantiated and called as such:\n * let obj = MyCircularDeque(k)\n * let ret_1: Bool = obj.insertFront(value)\n * let ret_2: Bool = obj.insertLast(value)\n * let ret_3: Bool = obj.deleteFront()\n * let ret_4: Bool = obj.deleteLast()\n * let ret_5: Int = obj.getFront()\n * let ret_6: Int = obj.getRear()\n * let ret_7: Bool = obj.isEmpty()\n * let ret_8: Bool = obj.isFull()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type MyCircularDeque struct {\n\n}\n\n\n/** Initialize your data structure here. Set the size of the deque to be k. */\nfunc Constructor(k int) MyCircularDeque {\n\n}\n\n\n/** Adds an item at the front of Deque. Return true if the operation is successful. */\nfunc (this *MyCircularDeque) InsertFront(value int) bool {\n\n}\n\n\n/** Adds an item at the rear of Deque. Return true if the operation is successful. */\nfunc (this *MyCircularDeque) InsertLast(value int) bool {\n\n}\n\n\n/** Deletes an item from the front of Deque. Return true if the operation is successful. */\nfunc (this *MyCircularDeque) DeleteFront() bool {\n\n}\n\n\n/** Deletes an item from the rear of Deque. Return true if the operation is successful. */\nfunc (this *MyCircularDeque) DeleteLast() bool {\n\n}\n\n\n/** Get the front item from the deque. */\nfunc (this *MyCircularDeque) GetFront() int {\n\n}\n\n\n/** Get the last item from the deque. */\nfunc (this *MyCircularDeque) GetRear() int {\n\n}\n\n\n/** Checks whether the circular deque is empty or not. */\nfunc (this *MyCircularDeque) IsEmpty() bool {\n\n}\n\n\n/** Checks whether the circular deque is full or not. */\nfunc (this *MyCircularDeque) IsFull() bool {\n\n}\n\n\n/**\n * Your MyCircularDeque object will be instantiated and called as such:\n * obj := Constructor(k);\n * param_1 := obj.InsertFront(value);\n * param_2 := obj.InsertLast(value);\n * param_3 := obj.DeleteFront();\n * param_4 := obj.DeleteLast();\n * param_5 := obj.GetFront();\n * param_6 := obj.GetRear();\n * param_7 := obj.IsEmpty();\n * param_8 := obj.IsFull();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class MyCircularDeque(_k: Int) {\n\n /** Initialize your data structure here. Set the size of the deque to be k. */\n\n\n /** Adds an item at the front of Deque. Return true if the operation is successful. */\n def insertFront(value: Int): Boolean = {\n\n }\n\n /** Adds an item at the rear of Deque. Return true if the operation is successful. */\n def insertLast(value: Int): Boolean = {\n\n }\n\n /** Deletes an item from the front of Deque. Return true if the operation is successful. */\n def deleteFront(): Boolean = {\n\n }\n\n /** Deletes an item from the rear of Deque. Return true if the operation is successful. */\n def deleteLast(): Boolean = {\n\n }\n\n /** Get the front item from the deque. */\n def getFront(): Int = {\n\n }\n\n /** Get the last item from the deque. */\n def getRear(): Int = {\n\n }\n\n /** Checks whether the circular deque is empty or not. */\n def isEmpty(): Boolean = {\n\n }\n\n /** Checks whether the circular deque is full or not. */\n def isFull(): Boolean = {\n\n }\n\n}\n\n/**\n * Your MyCircularDeque object will be instantiated and called as such:\n * var obj = new MyCircularDeque(k)\n * var param_1 = obj.insertFront(value)\n * var param_2 = obj.insertLast(value)\n * var param_3 = obj.deleteFront()\n * var param_4 = obj.deleteLast()\n * var param_5 = obj.getFront()\n * var param_6 = obj.getRear()\n * var param_7 = obj.isEmpty()\n * var param_8 = obj.isFull()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class MyCircularDeque(k: Int) {\n\n /** Initialize your data structure here. Set the size of the deque to be k. */\n\n\n /** Adds an item at the front of Deque. Return true if the operation is successful. */\n fun insertFront(value: Int): Boolean {\n\n }\n\n /** Adds an item at the rear of Deque. Return true if the operation is successful. */\n fun insertLast(value: Int): Boolean {\n\n }\n\n /** Deletes an item from the front of Deque. Return true if the operation is successful. */\n fun deleteFront(): Boolean {\n\n }\n\n /** Deletes an item from the rear of Deque. Return true if the operation is successful. */\n fun deleteLast(): Boolean {\n\n }\n\n /** Get the front item from the deque. */\n fun getFront(): Int {\n\n }\n\n /** Get the last item from the deque. */\n fun getRear(): Int {\n\n }\n\n /** Checks whether the circular deque is empty or not. */\n fun isEmpty(): Boolean {\n\n }\n\n /** Checks whether the circular deque is full or not. */\n fun isFull(): Boolean {\n\n }\n\n}\n\n/**\n * Your MyCircularDeque object will be instantiated and called as such:\n * var obj = MyCircularDeque(k)\n * var param_1 = obj.insertFront(value)\n * var param_2 = obj.insertLast(value)\n * var param_3 = obj.deleteFront()\n * var param_4 = obj.deleteLast()\n * var param_5 = obj.getFront()\n * var param_6 = obj.getRear()\n * var param_7 = obj.isEmpty()\n * var param_8 = obj.isFull()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct MyCircularDeque {\n\n}\n\n\n/** \n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl MyCircularDeque {\n\n /** Initialize your data structure here. Set the size of the deque to be k. */\n fn new(k: i32) -> Self {\n \n }\n \n /** Adds an item at the front of Deque. Return true if the operation is successful. */\n fn insert_front(&self, value: i32) -> bool {\n \n }\n \n /** Adds an item at the rear of Deque. Return true if the operation is successful. */\n fn insert_last(&self, value: i32) -> bool {\n \n }\n \n /** Deletes an item from the front of Deque. Return true if the operation is successful. */\n fn delete_front(&self) -> bool {\n \n }\n \n /** Deletes an item from the rear of Deque. Return true if the operation is successful. */\n fn delete_last(&self) -> bool {\n \n }\n \n /** Get the front item from the deque. */\n fn get_front(&self) -> i32 {\n \n }\n \n /** Get the last item from the deque. */\n fn get_rear(&self) -> i32 {\n \n }\n \n /** Checks whether the circular deque is empty or not. */\n fn is_empty(&self) -> bool {\n \n }\n \n /** Checks whether the circular deque is full or not. */\n fn is_full(&self) -> bool {\n \n }\n}\n\n/**\n * Your MyCircularDeque object will be instantiated and called as such:\n * let obj = MyCircularDeque::new(k);\n * let ret_1: bool = obj.insert_front(value);\n * let ret_2: bool = obj.insert_last(value);\n * let ret_3: bool = obj.delete_front();\n * let ret_4: bool = obj.delete_last();\n * let ret_5: i32 = obj.get_front();\n * let ret_6: i32 = obj.get_rear();\n * let ret_7: bool = obj.is_empty();\n * let ret_8: bool = obj.is_full();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class MyCircularDeque {\n /**\n * Initialize your data structure here. Set the size of the deque to be k.\n * @param Integer $k\n */\n function __construct($k) {\n \n }\n \n /**\n * Adds an item at the front of Deque. Return true if the operation is successful.\n * @param Integer $value\n * @return Boolean\n */\n function insertFront($value) {\n \n }\n \n /**\n * Adds an item at the rear of Deque. Return true if the operation is successful.\n * @param Integer $value\n * @return Boolean\n */\n function insertLast($value) {\n \n }\n \n /**\n * Deletes an item from the front of Deque. Return true if the operation is successful.\n * @return Boolean\n */\n function deleteFront() {\n \n }\n \n /**\n * Deletes an item from the rear of Deque. Return true if the operation is successful.\n * @return Boolean\n */\n function deleteLast() {\n \n }\n \n /**\n * Get the front item from the deque.\n * @return Integer\n */\n function getFront() {\n \n }\n \n /**\n * Get the last item from the deque.\n * @return Integer\n */\n function getRear() {\n \n }\n \n /**\n * Checks whether the circular deque is empty or not.\n * @return Boolean\n */\n function isEmpty() {\n \n }\n \n /**\n * Checks whether the circular deque is full or not.\n * @return Boolean\n */\n function isFull() {\n \n }\n}\n\n/**\n * Your MyCircularDeque object will be instantiated and called as such:\n * $obj = MyCircularDeque($k);\n * $ret_1 = $obj->insertFront($value);\n * $ret_2 = $obj->insertLast($value);\n * $ret_3 = $obj->deleteFront();\n * $ret_4 = $obj->deleteLast();\n * $ret_5 = $obj->getFront();\n * $ret_6 = $obj->getRear();\n * $ret_7 = $obj->isEmpty();\n * $ret_8 = $obj->isFull();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class MyCircularDeque {\n constructor(k: number) {\n\n }\n\n insertFront(value: number): boolean {\n\n }\n\n insertLast(value: number): boolean {\n\n }\n\n deleteFront(): boolean {\n\n }\n\n deleteLast(): boolean {\n\n }\n\n getFront(): number {\n\n }\n\n getRear(): number {\n\n }\n\n isEmpty(): boolean {\n\n }\n\n isFull(): boolean {\n\n }\n}\n\n/**\n * Your MyCircularDeque object will be instantiated and called as such:\n * var obj = new MyCircularDeque(k)\n * var param_1 = obj.insertFront(value)\n * var param_2 = obj.insertLast(value)\n * var param_3 = obj.deleteFront()\n * var param_4 = obj.deleteLast()\n * var param_5 = obj.getFront()\n * var param_6 = obj.getRear()\n * var param_7 = obj.isEmpty()\n * var param_8 = obj.isFull()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define my-circular-deque%\n (class object%\n (super-new)\n\n ; k : exact-integer?\n (init-field\n k)\n \n ; insert-front : exact-integer? -> boolean?\n (define/public (insert-front value)\n\n )\n ; insert-last : exact-integer? -> boolean?\n (define/public (insert-last value)\n\n )\n ; delete-front : -> boolean?\n (define/public (delete-front)\n\n )\n ; delete-last : -> boolean?\n (define/public (delete-last)\n\n )\n ; get-front : -> exact-integer?\n (define/public (get-front)\n\n )\n ; get-rear : -> exact-integer?\n (define/public (get-rear)\n\n )\n ; is-empty : -> boolean?\n (define/public (is-empty)\n\n )\n ; is-full : -> boolean?\n (define/public (is-full)\n\n )))\n\n;; Your my-circular-deque% object will be instantiated and called as such:\n;; (define obj (new my-circular-deque% [k k]))\n;; (define param_1 (send obj insert-front value))\n;; (define param_2 (send obj insert-last value))\n;; (define param_3 (send obj delete-front))\n;; (define param_4 (send obj delete-last))\n;; (define param_5 (send obj get-front))\n;; (define param_6 (send obj get-rear))\n;; (define param_7 (send obj is-empty))\n;; (define param_8 (send obj is-full))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0641](https://leetcode-cn.com/problems/design-circular-deque)", "[\u8bbe\u8ba1\u5faa\u73af\u53cc\u7aef\u961f\u5217](/solution/0600-0699/0641.Design%20Circular%20Deque/README.md)", "`\u8bbe\u8ba1`,`\u961f\u5217`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0641](https://leetcode.com/problems/design-circular-deque)", "[Design Circular Deque](/solution/0600-0699/0641.Design%20Circular%20Deque/README_EN.md)", "`Design`,`Queue`", "Medium", ""]}, {"question_id": "0858", "frontend_question_id": "0831", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/masking-personal-information", "url_en": "https://leetcode.com/problems/masking-personal-information", "relative_path_cn": "/solution/0800-0899/0831.Masking%20Personal%20Information/README.md", "relative_path_en": "/solution/0800-0899/0831.Masking%20Personal%20Information/README_EN.md", "title_cn": "\u9690\u85cf\u4e2a\u4eba\u4fe1\u606f", "title_en": "Masking Personal Information", "question_title_slug": "masking-personal-information", "content_en": "

    We are given a personal information string s, which may represent either an email address or a phone number.

    \n\n

    We would like to mask this personal information according to the following rules:

    \n\n


    \n1. Email address:

    \n\n

    We define a name to be a string of length ≥ 2 consisting of only lowercase letters a-z or uppercase letters A-Z.

    \n\n

    An email address starts with a name, followed by the symbol '@', followed by a name, followed by the dot '.' and followed by a name. 

    \n\n

    All email addresses are guaranteed to be valid and in the format of "name1@name2.name3".

    \n\n

    To mask an email, all names must be converted to lowercase and all letters between the first and last letter of the first name must be replaced by 5 asterisks '*'.

    \n\n


    \n2. Phone number:

    \n\n

    A phone number is a string consisting of only the digits 0-9 or the characters from the set {'+', '-', '(', ')', ' '}. You may assume a phone number contains 10 to 13 digits.

    \n\n

    The last 10 digits make up the local number, while the digits before those make up the country code. Note that the country code is optional. We want to expose only the last 4 digits and mask all other digits.

    \n\n

    The local number should be formatted and masked as "***-***-1111", where 1 represents the exposed digits.

    \n\n

    To mask a phone number with country code like "+111 111 111 1111", we write it in the form "+***-***-***-1111".  The '+' sign and the first '-' sign before the local number should only exist if there is a country code.  For example, a 12 digit phone number mask should start with "+**-".

    \n\n

    Note that extraneous characters like "(", ")", " ", as well as extra dashes or plus signs not part of the above formatting scheme should be removed.

    \n\n

     

    \n\n

    Return the correct "mask" of the information provided.

    \n\n

     

    \n\n

    Example 1:

    \n\n
    \nInput: s = "LeetCode@LeetCode.com"\nOutput: "l*****e@leetcode.com"\nExplanation: All names are converted to lowercase, and the letters between the\n             first and last letter of the first name is replaced by 5 asterisks.\n             Therefore, "leetcode" -> "l*****e".\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "AB@qq.com"\nOutput: "a*****b@qq.com"\nExplanation: There must be 5 asterisks between the first and last letter \n             of the first name "ab". Therefore, "ab" -> "a*****b".\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "1(234)567-890"\nOutput: "***-***-7890"\nExplanation: 10 digits in the phone number, which means all digits make up the local number.\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "86-(10)12345678"\nOutput: "+**-***-***-5678"\nExplanation: 12 digits, 2 digits for country code and 10 digits for local number. \n
    \n\n

    Notes:

    \n\n
      \n\t
    1. s.length <= 40.
    2. \n\t
    3. Emails have length at least 8.
    4. \n\t
    5. Phone numbers have length at least 10.
    6. \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u6761\u4e2a\u4eba\u4fe1\u606f\u5b57\u7b26\u4e32 S\uff0c\u5b83\u53ef\u80fd\u662f\u4e00\u4e2a \u90ae\u7bb1\u5730\u5740 \uff0c\u4e5f\u53ef\u80fd\u662f\u4e00\u4e32 \u7535\u8bdd\u53f7\u7801 \u3002

    \n\n

    \u6211\u4eec\u5c06\u9690\u85cf\u5b83\u7684\u9690\u79c1\u4fe1\u606f\uff0c\u901a\u8fc7\u5982\u4e0b\u89c4\u5219:

    \n\n

     

    \n\n

    1. \u7535\u5b50\u90ae\u7bb1

    \n\n

    \u5b9a\u4e49\u540d\u79f0 name \u662f\u957f\u5ea6\u5927\u4e8e\u7b49\u4e8e 2 \uff08length ≥ 2\uff09\uff0c\u5e76\u4e14\u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd a-z \u548c\u5927\u5199\u5b57\u6bcd A-Z \u7684\u5b57\u7b26\u4e32\u3002

    \n\n

    \u7535\u5b50\u90ae\u7bb1\u5730\u5740\u7531\u540d\u79f0 name \u5f00\u5934\uff0c\u7d27\u63a5\u7740\u662f\u7b26\u53f7 '@'\uff0c\u540e\u9762\u63a5\u7740\u4e00\u4e2a\u540d\u79f0 name\uff0c\u518d\u63a5\u7740\u4e00\u4e2a\u70b9\u53f7 '.'\uff0c\u7136\u540e\u662f\u4e00\u4e2a\u540d\u79f0 name\u3002

    \n\n

    \u7535\u5b50\u90ae\u7bb1\u5730\u5740\u786e\u5b9a\u4e3a\u6709\u6548\u7684\uff0c\u5e76\u4e14\u683c\u5f0f\u662f "name1@name2.name3"\u3002

    \n\n

    \u4e3a\u4e86\u9690\u85cf\u7535\u5b50\u90ae\u7bb1\uff0c\u6240\u6709\u7684\u540d\u79f0 name \u5fc5\u987b\u88ab\u8f6c\u6362\u6210\u5c0f\u5199\u7684\uff0c\u5e76\u4e14\u7b2c\u4e00\u4e2a\u540d\u79f0 name \u7684\u7b2c\u4e00\u4e2a\u5b57\u6bcd\u548c\u6700\u540e\u4e00\u4e2a\u5b57\u6bcd\u7684\u4e2d\u95f4\u7684\u6240\u6709\u5b57\u6bcd\u7531 5 \u4e2a '*' \u4ee3\u66ff\u3002

    \n\n

     

    \n\n

    2. \u7535\u8bdd\u53f7\u7801

    \n\n

    \u7535\u8bdd\u53f7\u7801\u662f\u4e00\u4e32\u5305\u62ec\u6570\u5b57 0-9\uff0c\u4ee5\u53ca {'+', '-', '(', ')', ' '} \u8fd9\u51e0\u4e2a\u5b57\u7b26\u7684\u5b57\u7b26\u4e32\u3002\u4f60\u53ef\u4ee5\u5047\u8bbe\u7535\u8bdd\u53f7\u7801\u5305\u542b 10 \u5230 13 \u4e2a\u6570\u5b57\u3002

    \n\n

    \u7535\u8bdd\u53f7\u7801\u7684\u6700\u540e 10 \u4e2a\u6570\u5b57\u7ec4\u6210\u672c\u5730\u53f7\u7801\uff0c\u5728\u8fd9\u4e4b\u524d\u7684\u6570\u5b57\u7ec4\u6210\u56fd\u9645\u53f7\u7801\u3002\u6ce8\u610f\uff0c\u56fd\u9645\u53f7\u7801\u662f\u53ef\u9009\u7684\u3002\u6211\u4eec\u53ea\u66b4\u9732\u6700\u540e 4 \u4e2a\u6570\u5b57\u5e76\u9690\u85cf\u6240\u6709\u5176\u4ed6\u6570\u5b57\u3002

    \n\n

    \u672c\u5730\u53f7\u7801\u662f\u6709\u683c\u5f0f\u7684\uff0c\u5e76\u4e14\u5982 "***-***-1111" \u8fd9\u6837\u663e\u793a\uff0c\u8fd9\u91cc\u7684 1 \u8868\u793a\u66b4\u9732\u7684\u6570\u5b57\u3002

    \n\n

    \u4e3a\u4e86\u9690\u85cf\u6709\u56fd\u9645\u53f7\u7801\u7684\u7535\u8bdd\u53f7\u7801\uff0c\u50cf "+111 111 111 1111"\uff0c\u6211\u4eec\u4ee5 "+***-***-***-1111" \u7684\u683c\u5f0f\u6765\u663e\u793a\u3002\u5728\u672c\u5730\u53f7\u7801\u524d\u9762\u7684 '+' \u53f7\u548c\u7b2c\u4e00\u4e2a '-' \u53f7\u4ec5\u5f53\u7535\u8bdd\u53f7\u7801\u4e2d\u5305\u542b\u56fd\u9645\u53f7\u7801\u65f6\u5b58\u5728\u3002\u4f8b\u5982\uff0c\u4e00\u4e2a 12 \u4f4d\u7684\u7535\u8bdd\u53f7\u7801\u5e94\u5f53\u4ee5 "+**-" \u5f00\u5934\u8fdb\u884c\u663e\u793a\u3002

    \n\n

    \u6ce8\u610f\uff1a\u50cf "("\uff0c")"\uff0c" " \u8fd9\u6837\u7684\u4e0d\u76f8\u5e72\u7684\u5b57\u7b26\u4ee5\u53ca\u4e0d\u7b26\u5408\u4e0a\u8ff0\u683c\u5f0f\u7684\u989d\u5916\u7684\u51cf\u53f7\u6216\u8005\u52a0\u53f7\u90fd\u5e94\u5f53\u88ab\u5220\u9664\u3002

    \n\n

     

    \n\n

    \u6700\u540e\uff0c\u5c06\u63d0\u4f9b\u7684\u4fe1\u606f\u6b63\u786e\u9690\u85cf\u540e\u8fd4\u56de\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165: "LeetCode@LeetCode.com"\n\u8f93\u51fa: "l*****e@leetcode.com"\n\u89e3\u91ca\uff1a \n\u6240\u6709\u7684\u540d\u79f0\u8f6c\u6362\u6210\u5c0f\u5199, \u7b2c\u4e00\u4e2a\u540d\u79f0\u7684\u7b2c\u4e00\u4e2a\u5b57\u7b26\u548c\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\u4e2d\u95f4\u7531 5 \u4e2a\u661f\u53f7\u4ee3\u66ff\u3002\n\u56e0\u6b64\uff0c"leetcode" -> "l*****e"\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165: "AB@qq.com"\n\u8f93\u51fa: "a*****b@qq.com"\n\u89e3\u91ca: \n\u7b2c\u4e00\u4e2a\u540d\u79f0"ab"\u7684\u7b2c\u4e00\u4e2a\u5b57\u7b26\u548c\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\u7684\u4e2d\u95f4\u5fc5\u987b\u6709 5 \u4e2a\u661f\u53f7\n\u56e0\u6b64\uff0c"ab" -> "a*****b"\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165: "1(234)567-890"\n\u8f93\u51fa: "***-***-7890"\n\u89e3\u91ca: \n10 \u4e2a\u6570\u5b57\u7684\u7535\u8bdd\u53f7\u7801\uff0c\u90a3\u610f\u5473\u7740\u6240\u6709\u7684\u6570\u5b57\u90fd\u662f\u672c\u5730\u53f7\u7801\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165: "86-(10)12345678"\n\u8f93\u51fa: "+**-***-***-5678"\n\u89e3\u91ca: \n12 \u4f4d\u6570\u5b57\uff0c2 \u4e2a\u6570\u5b57\u662f\u56fd\u9645\u53f7\u7801\u53e6\u5916 10 \u4e2a\u6570\u5b57\u662f\u672c\u5730\u53f7\u7801 \u3002\n
    \n\n

     

    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. S.length <= 40\u3002
    2. \n\t
    3. \u90ae\u7bb1\u7684\u957f\u5ea6\u81f3\u5c11\u662f 8\u3002
    4. \n\t
    5. \u7535\u8bdd\u53f7\u7801\u7684\u957f\u5ea6\u81f3\u5c11\u662f 10\u3002
    6. \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string maskPII(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String maskPII(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maskPII(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maskPII(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * maskPII(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string MaskPII(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar maskPII = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef mask_pii(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maskPII(_ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maskPII(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maskPII(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maskPII(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn mask_pii(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function maskPII($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maskPII(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (mask-pii s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0831](https://leetcode-cn.com/problems/masking-personal-information)", "[\u9690\u85cf\u4e2a\u4eba\u4fe1\u606f](/solution/0800-0899/0831.Masking%20Personal%20Information/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0831](https://leetcode.com/problems/masking-personal-information)", "[Masking Personal Information](/solution/0800-0899/0831.Masking%20Personal%20Information/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "0857", "frontend_question_id": "0830", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/positions-of-large-groups", "url_en": "https://leetcode.com/problems/positions-of-large-groups", "relative_path_cn": "/solution/0800-0899/0830.Positions%20of%20Large%20Groups/README.md", "relative_path_en": "/solution/0800-0899/0830.Positions%20of%20Large%20Groups/README_EN.md", "title_cn": "\u8f83\u5927\u5206\u7ec4\u7684\u4f4d\u7f6e", "title_en": "Positions of Large Groups", "question_title_slug": "positions-of-large-groups", "content_en": "

    In a string s of lowercase letters, these letters form consecutive groups of the same character.

    \n\n

    For example, a string like s = "abbxxxxzyy" has the groups "a", "bb", "xxxx", "z", and "yy".

    \n\n

    A group is identified by an interval [start, end], where start and end denote the start and end indices (inclusive) of the group. In the above example, "xxxx" has the interval [3,6].

    \n\n

    A group is considered large if it has 3 or more characters.

    \n\n

    Return the intervals of every large group sorted in increasing order by start index.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "abbxxxxzzy"\nOutput: [[3,6]]\nExplanation: "xxxx" is the only large group with start index 3 and end index 6.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "abc"\nOutput: []\nExplanation: We have groups "a", "b", and "c", none of which are large groups.\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "abcdddeeeeaabbbcd"\nOutput: [[3,5],[6,9],[12,14]]\nExplanation: The large groups are "ddd", "eeee", and "bbb".\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "aba"\nOutput: []\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 1000
    • \n\t
    • s contains lower-case English letters only.
    • \n
    \n", "content_cn": "

    \u5728\u4e00\u4e2a\u7531\u5c0f\u5199\u5b57\u6bcd\u6784\u6210\u7684\u5b57\u7b26\u4e32 s \u4e2d\uff0c\u5305\u542b\u7531\u4e00\u4e9b\u8fde\u7eed\u7684\u76f8\u540c\u5b57\u7b26\u6240\u6784\u6210\u7684\u5206\u7ec4\u3002

    \n\n

    \u4f8b\u5982\uff0c\u5728\u5b57\u7b26\u4e32 s = \"abbxxxxzyy\"\u00a0\u4e2d\uff0c\u5c31\u542b\u6709 \"a\", \"bb\", \"xxxx\", \"z\" \u548c \"yy\" \u8fd9\u6837\u7684\u4e00\u4e9b\u5206\u7ec4\u3002

    \n\n

    \u5206\u7ec4\u53ef\u4ee5\u7528\u533a\u95f4 [start, end] \u8868\u793a\uff0c\u5176\u4e2d start \u548c end \u5206\u522b\u8868\u793a\u8be5\u5206\u7ec4\u7684\u8d77\u59cb\u548c\u7ec8\u6b62\u4f4d\u7f6e\u7684\u4e0b\u6807\u3002\u4e0a\u4f8b\u4e2d\u7684 \"xxxx\" \u5206\u7ec4\u7528\u533a\u95f4\u8868\u793a\u4e3a [3,6] \u3002

    \n\n

    \u6211\u4eec\u79f0\u6240\u6709\u5305\u542b\u5927\u4e8e\u6216\u7b49\u4e8e\u4e09\u4e2a\u8fde\u7eed\u5b57\u7b26\u7684\u5206\u7ec4\u4e3a \u8f83\u5927\u5206\u7ec4 \u3002

    \n\n

    \u627e\u5230\u6bcf\u4e00\u4e2a \u8f83\u5927\u5206\u7ec4 \u7684\u533a\u95f4\uff0c\u6309\u8d77\u59cb\u4f4d\u7f6e\u4e0b\u6807\u9012\u589e\u987a\u5e8f\u6392\u5e8f\u540e\uff0c\u8fd4\u56de\u7ed3\u679c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\u00a01\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"abbxxxxzzy\"\n\u8f93\u51fa\uff1a[[3,6]]\n\u89e3\u91ca\uff1a\"xxxx\" \u662f\u4e00\u4e2a\u8d77\u59cb\u4e8e 3 \u4e14\u7ec8\u6b62\u4e8e 6 \u7684\u8f83\u5927\u5206\u7ec4\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"abc\"\n\u8f93\u51fa\uff1a[]\n\u89e3\u91ca\uff1a\"a\",\"b\" \u548c \"c\" \u5747\u4e0d\u662f\u7b26\u5408\u8981\u6c42\u7684\u8f83\u5927\u5206\u7ec4\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"abcdddeeeeaabbbcd\"\n\u8f93\u51fa\uff1a[[3,5],[6,9],[12,14]]\n\u89e3\u91ca\uff1a\u8f83\u5927\u5206\u7ec4\u4e3a \"ddd\", \"eeee\" \u548c \"bbb\"
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"aba\"\n\u8f93\u51fa\uff1a[]\n
    \n\u00a0\n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 1000
    • \n\t
    • s \u4ec5\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> largeGroupPositions(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> largeGroupPositions(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def largeGroupPositions(self, s):\n \"\"\"\n :type s: str\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def largeGroupPositions(self, s: str) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** largeGroupPositions(char * s, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> LargeGroupPositions(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number[][]}\n */\nvar largeGroupPositions = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer[][]}\ndef large_group_positions(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func largeGroupPositions(_ s: String) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func largeGroupPositions(s string) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def largeGroupPositions(s: String): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun largeGroupPositions(s: String): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn large_group_positions(s: String) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer[][]\n */\n function largeGroupPositions($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function largeGroupPositions(s: string): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (large-group-positions s)\n (-> string? (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0830](https://leetcode-cn.com/problems/positions-of-large-groups)", "[\u8f83\u5927\u5206\u7ec4\u7684\u4f4d\u7f6e](/solution/0800-0899/0830.Positions%20of%20Large%20Groups/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0830](https://leetcode.com/problems/positions-of-large-groups)", "[Positions of Large Groups](/solution/0800-0899/0830.Positions%20of%20Large%20Groups/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0856", "frontend_question_id": "0829", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/consecutive-numbers-sum", "url_en": "https://leetcode.com/problems/consecutive-numbers-sum", "relative_path_cn": "/solution/0800-0899/0829.Consecutive%20Numbers%20Sum/README.md", "relative_path_en": "/solution/0800-0899/0829.Consecutive%20Numbers%20Sum/README_EN.md", "title_cn": "\u8fde\u7eed\u6574\u6570\u6c42\u548c", "title_en": "Consecutive Numbers Sum", "question_title_slug": "consecutive-numbers-sum", "content_en": "

    Given a positive integer n, how many ways can we write it as a sum of consecutive positive integers?

    \n\n

    Example 1:

    \n\n
    \nInput: n = 5\nOutput: 2\nExplanation: 5 = 5 = 2 + 3
    \n\n

    Example 2:

    \n\n
    \nInput: n = 9\nOutput: 3\nExplanation: 9 = 9 = 4 + 5 = 2 + 3 + 4
    \n\n

    Example 3:

    \n\n
    \nInput: n = 15\nOutput: 4\nExplanation: 15 = 15 = 8 + 7 = 4 + 5 + 6 = 1 + 2 + 3 + 4 + 5
    \n\n

    Note: 1 <= n <= 10 ^ 9.

    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6b63\u6574\u6570 N\uff0c\u8bd5\u6c42\u6709\u591a\u5c11\u7ec4\u8fde\u7eed\u6b63\u6574\u6570\u6ee1\u8db3\u6240\u6709\u6570\u5b57\u4e4b\u548c\u4e3a N?

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: 5\n\u8f93\u51fa: 2\n\u89e3\u91ca: 5 = 5 = 2 + 3\uff0c\u5171\u6709\u4e24\u7ec4\u8fde\u7eed\u6574\u6570([5],[2,3])\u6c42\u548c\u540e\u4e3a 5\u3002
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: 9\n\u8f93\u51fa: 3\n\u89e3\u91ca: 9 = 9 = 4 + 5 = 2 + 3 + 4
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \n\u8f93\u5165: 15\n\u8f93\u51fa: 4\n\u89e3\u91ca: 15 = 15 = 8 + 7 = 4 + 5 + 6 = 1 + 2 + 3 + 4 + 5
    \n\n

    \u8bf4\u660e: 1 <= N <= 10 ^ 9

    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int consecutiveNumbersSum(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int consecutiveNumbersSum(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def consecutiveNumbersSum(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def consecutiveNumbersSum(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint consecutiveNumbersSum(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ConsecutiveNumbersSum(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar consecutiveNumbersSum = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef consecutive_numbers_sum(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func consecutiveNumbersSum(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func consecutiveNumbersSum(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def consecutiveNumbersSum(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun consecutiveNumbersSum(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn consecutive_numbers_sum(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function consecutiveNumbersSum($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function consecutiveNumbersSum(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (consecutive-numbers-sum n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0829](https://leetcode-cn.com/problems/consecutive-numbers-sum)", "[\u8fde\u7eed\u6574\u6570\u6c42\u548c](/solution/0800-0899/0829.Consecutive%20Numbers%20Sum/README.md)", "`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[0829](https://leetcode.com/problems/consecutive-numbers-sum)", "[Consecutive Numbers Sum](/solution/0800-0899/0829.Consecutive%20Numbers%20Sum/README_EN.md)", "`Math`", "Hard", ""]}, {"question_id": "0855", "frontend_question_id": "0828", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-unique-characters-of-all-substrings-of-a-given-string", "url_en": "https://leetcode.com/problems/count-unique-characters-of-all-substrings-of-a-given-string", "relative_path_cn": "/solution/0800-0899/0828.Count%20Unique%20Characters%20of%20All%20Substrings%20of%20a%20Given%20String/README.md", "relative_path_en": "/solution/0800-0899/0828.Count%20Unique%20Characters%20of%20All%20Substrings%20of%20a%20Given%20String/README_EN.md", "title_cn": "\u7edf\u8ba1\u5b50\u4e32\u4e2d\u7684\u552f\u4e00\u5b57\u7b26", "title_en": "Count Unique Characters of All Substrings of a Given String", "question_title_slug": "count-unique-characters-of-all-substrings-of-a-given-string", "content_en": "

    Let's define a function countUniqueChars(s) that returns the number of unique characters on s, for example if s = "LEETCODE" then "L", "T","C","O","D" are the unique characters since they appear only once in s, therefore countUniqueChars(s) = 5.
    \n
    \nOn this problem given a string s we need to return the sum of countUniqueChars(t) where t is a substring of s. Notice that some substrings can be repeated so on this case you have to count the repeated ones too.

    \n\n

    Since the answer can be very large, return the answer modulo 10 ^ 9 + 7.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "ABC"\nOutput: 10\nExplanation: All possible substrings are: "A","B","C","AB","BC" and "ABC".\nEvey substring is composed with only unique letters.\nSum of lengths of all substring is 1 + 1 + 1 + 2 + 2 + 3 = 10\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "ABA"\nOutput: 8\nExplanation: The same as example 1, except countUniqueChars("ABA") = 1.\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "LEETCODE"\nOutput: 92\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= s.length <= 10^4
    • \n\t
    • s contain upper-case English letters only.
    • \n
    \n", "content_cn": "

    \u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a\u51fd\u6570 countUniqueChars(s) \u6765\u7edf\u8ba1\u5b57\u7b26\u4e32 s \u4e2d\u7684\u552f\u4e00\u5b57\u7b26\uff0c\u5e76\u8fd4\u56de\u552f\u4e00\u5b57\u7b26\u7684\u4e2a\u6570\u3002

    \n\n

    \u4f8b\u5982\uff1as = \"LEETCODE\" \uff0c\u5219\u5176\u4e2d \"L\", \"T\",\"C\",\"O\",\"D\" \u90fd\u662f\u552f\u4e00\u5b57\u7b26\uff0c\u56e0\u4e3a\u5b83\u4eec\u53ea\u51fa\u73b0\u4e00\u6b21\uff0c\u6240\u4ee5 countUniqueChars(s) = 5 \u3002

    \n\n

    \u672c\u9898\u5c06\u4f1a\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \uff0c\u6211\u4eec\u9700\u8981\u8fd4\u56de countUniqueChars(t) \u7684\u603b\u548c\uff0c\u5176\u4e2d t \u662f s \u7684\u5b50\u5b57\u7b26\u4e32\u3002\u6ce8\u610f\uff0c\u67d0\u4e9b\u5b50\u5b57\u7b26\u4e32\u53ef\u80fd\u662f\u91cd\u590d\u7684\uff0c\u4f46\u4f60\u7edf\u8ba1\u65f6\u4e5f\u5fc5\u987b\u7b97\u4e0a\u8fd9\u4e9b\u91cd\u590d\u7684\u5b50\u5b57\u7b26\u4e32\uff08\u4e5f\u5c31\u662f\u8bf4\uff0c\u4f60\u5fc5\u987b\u7edf\u8ba1 s \u7684\u6240\u6709\u5b50\u5b57\u7b26\u4e32\u4e2d\u7684\u552f\u4e00\u5b57\u7b26\uff09\u3002

    \n\n

    \u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u975e\u5e38\u5927\uff0c\u8bf7\u5c06\u7ed3\u679c mod 10 ^ 9 + 7 \u540e\u518d\u8fd4\u56de\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165: s = \"ABC\"\n\u8f93\u51fa: 10\n\u89e3\u91ca: \u6240\u6709\u53ef\u80fd\u7684\u5b50\u4e32\u4e3a\uff1a\"A\",\"B\",\"C\",\"AB\",\"BC\" \u548c \"ABC\"\u3002\n     \u5176\u4e2d\uff0c\u6bcf\u4e00\u4e2a\u5b50\u4e32\u90fd\u7531\u72ec\u7279\u5b57\u7b26\u6784\u6210\u3002\n     \u6240\u4ee5\u5176\u957f\u5ea6\u603b\u548c\u4e3a\uff1a1 + 1 + 1 + 2 + 2 + 3 = 10\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165: s = \"ABA\"\n\u8f93\u51fa: 8\n\u89e3\u91ca: \u9664\u4e86 countUniqueChars(\"ABA\") = 1 \u4e4b\u5916\uff0c\u5176\u4f59\u4e0e\u793a\u4f8b 1 \u76f8\u540c\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"LEETCODE\"\n\u8f93\u51fa\uff1a92\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= s.length <= 10^4
    • \n\t
    • s \u53ea\u5305\u542b\u5927\u5199\u82f1\u6587\u5b57\u7b26
    • \n
    \n", "tags_en": ["Two Pointers"], "tags_cn": ["\u53cc\u6307\u9488"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int uniqueLetterString(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int uniqueLetterString(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def uniqueLetterString(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def uniqueLetterString(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint uniqueLetterString(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int UniqueLetterString(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar uniqueLetterString = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef unique_letter_string(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func uniqueLetterString(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func uniqueLetterString(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def uniqueLetterString(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun uniqueLetterString(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn unique_letter_string(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function uniqueLetterString($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function uniqueLetterString(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (unique-letter-string s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0828](https://leetcode-cn.com/problems/count-unique-characters-of-all-substrings-of-a-given-string)", "[\u7edf\u8ba1\u5b50\u4e32\u4e2d\u7684\u552f\u4e00\u5b57\u7b26](/solution/0800-0899/0828.Count%20Unique%20Characters%20of%20All%20Substrings%20of%20a%20Given%20String/README.md)", "`\u53cc\u6307\u9488`", "\u56f0\u96be", ""], "md_table_row_en": ["[0828](https://leetcode.com/problems/count-unique-characters-of-all-substrings-of-a-given-string)", "[Count Unique Characters of All Substrings of a Given String](/solution/0800-0899/0828.Count%20Unique%20Characters%20of%20All%20Substrings%20of%20a%20Given%20String/README_EN.md)", "`Two Pointers`", "Hard", ""]}, {"question_id": "0854", "frontend_question_id": "0827", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/making-a-large-island", "url_en": "https://leetcode.com/problems/making-a-large-island", "relative_path_cn": "/solution/0800-0899/0827.Making%20A%20Large%20Island/README.md", "relative_path_en": "/solution/0800-0899/0827.Making%20A%20Large%20Island/README_EN.md", "title_cn": "\u6700\u5927\u4eba\u5de5\u5c9b", "title_en": "Making A Large Island", "question_title_slug": "making-a-large-island", "content_en": "

    You are given an n x n binary matrix grid. You are allowed to change at most one 0 to be 1.

    \r\n\r\n

    Return the size of the largest island in grid after applying this operation.

    \r\n\r\n

    An island is a 4-directionally connected group of 1s.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: grid = [[1,0],[0,1]]\r\nOutput: 3\r\nExplanation: Change one 0 to 1 and connect two 1s, then we get an island with area = 3.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: grid = [[1,1],[1,0]]\r\nOutput: 4\r\nExplanation: Change the 0 to 1 and make the island bigger, only one island with area = 4.
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: grid = [[1,1],[1,1]]\r\nOutput: 4\r\nExplanation: Can't change any 0 to 1, only one island with area = 4.\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • n == grid.length
    • \r\n\t
    • n == grid[i].length
    • \r\n\t
    • 1 <= n <= 500
    • \r\n\t
    • grid[i][j] is either 0 or 1.
    • \r\n
    ", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5927\u5c0f\u4e3a n x n \u4e8c\u8fdb\u5236\u77e9\u9635 grid \u3002\u6700\u591a \u53ea\u80fd\u5c06\u4e00\u683c\u00a00 \u53d8\u6210\u00a01 \u3002

    \n\n

    \u8fd4\u56de\u6267\u884c\u6b64\u64cd\u4f5c\u540e\uff0cgrid \u4e2d\u6700\u5927\u7684\u5c9b\u5c7f\u9762\u79ef\u662f\u591a\u5c11\uff1f

    \n\n

    \u5c9b\u5c7f \u7531\u4e00\u7ec4\u4e0a\u3001\u4e0b\u3001\u5de6\u3001\u53f3\u56db\u4e2a\u65b9\u5411\u76f8\u8fde\u7684\u00a01 \u5f62\u6210\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: grid = [[1, 0], [0, 1]]\n\u8f93\u51fa: 3\n\u89e3\u91ca: \u5c06\u4e00\u683c0\u53d8\u62101\uff0c\u6700\u7ec8\u8fde\u901a\u4e24\u4e2a\u5c0f\u5c9b\u5f97\u5230\u9762\u79ef\u4e3a 3 \u7684\u5c9b\u5c7f\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: grid = [[1, 1], [1, 0]]\n\u8f93\u51fa: 4\n\u89e3\u91ca: \u5c06\u4e00\u683c0\u53d8\u62101\uff0c\u5c9b\u5c7f\u7684\u9762\u79ef\u6269\u5927\u4e3a 4\u3002
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \n\u8f93\u5165: grid = [[1, 1], [1, 1]]\n\u8f93\u51fa: 4\n\u89e3\u91ca: \u6ca1\u67090\u53ef\u4ee5\u8ba9\u6211\u4eec\u53d8\u62101\uff0c\u9762\u79ef\u4f9d\u7136\u4e3a 4\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= n <= 500
    • \n\t
    • grid[i][j] \u4e3a 0 \u6216 1
    • \n
    \n", "tags_en": ["Depth-first Search", "Breadth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int largestIsland(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int largestIsland(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def largestIsland(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def largestIsland(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint largestIsland(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LargestIsland(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar largestIsland = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef largest_island(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func largestIsland(_ grid: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func largestIsland(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def largestIsland(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun largestIsland(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn largest_island(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function largestIsland($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function largestIsland(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (largest-island grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0827](https://leetcode-cn.com/problems/making-a-large-island)", "[\u6700\u5927\u4eba\u5de5\u5c9b](/solution/0800-0899/0827.Making%20A%20Large%20Island/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[0827](https://leetcode.com/problems/making-a-large-island)", "[Making A Large Island](/solution/0800-0899/0827.Making%20A%20Large%20Island/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`", "Hard", ""]}, {"question_id": "0853", "frontend_question_id": "0826", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/most-profit-assigning-work", "url_en": "https://leetcode.com/problems/most-profit-assigning-work", "relative_path_cn": "/solution/0800-0899/0826.Most%20Profit%20Assigning%20Work/README.md", "relative_path_en": "/solution/0800-0899/0826.Most%20Profit%20Assigning%20Work/README_EN.md", "title_cn": "\u5b89\u6392\u5de5\u4f5c\u4ee5\u8fbe\u5230\u6700\u5927\u6536\u76ca", "title_en": "Most Profit Assigning Work", "question_title_slug": "most-profit-assigning-work", "content_en": "

    We have jobs: difficulty[i] is the difficulty of the ith job, and profit[i] is the profit of the ith job. 

    \r\n\r\n

    Now we have some workers. worker[i] is the ability of the ith worker, which means that this worker can only complete a job with difficulty at most worker[i]

    \r\n\r\n

    Every worker can be assigned at most one job, but one job can be completed multiple times.

    \r\n\r\n

    For example, if 3 people attempt the same job that pays $1, then the total profit will be $3.  If a worker cannot complete any job, his profit is $0.

    \r\n\r\n

    What is the most profit we can make?

    \r\n\r\n

    Example 1:

    \r\n\r\n
    \r\nInput: difficulty = [2,4,6,8,10], profit = [10,20,30,40,50], worker = [4,5,6,7]\r\nOutput: 100 \r\nExplanation: Workers are assigned jobs of difficulty [4,4,6,6] and they get profit of [20,20,30,30] seperately.
    \r\n\r\n

    Notes:

    \r\n\r\n
      \r\n\t
    • 1 <= difficulty.length = profit.length <= 10000
    • \r\n\t
    • 1 <= worker.length <= 10000
    • \r\n\t
    • difficulty[i], profit[i], worker[i]  are in range [1, 10^5]
    • \r\n
    \r\n", "content_cn": "

    \u6709\u4e00\u4e9b\u5de5\u4f5c\uff1adifficulty[i] \u8868\u793a\u7b2c i \u4e2a\u5de5\u4f5c\u7684\u96be\u5ea6\uff0cprofit[i] \u8868\u793a\u7b2c i \u4e2a\u5de5\u4f5c\u7684\u6536\u76ca\u3002

    \n\n

    \u73b0\u5728\u6211\u4eec\u6709\u4e00\u4e9b\u5de5\u4eba\u3002worker[i] \u662f\u7b2c i \u4e2a\u5de5\u4eba\u7684\u80fd\u529b\uff0c\u5373\u8be5\u5de5\u4eba\u53ea\u80fd\u5b8c\u6210\u96be\u5ea6\u5c0f\u4e8e\u7b49\u4e8e worker[i] \u7684\u5de5\u4f5c\u3002

    \n\n

    \u6bcf\u4e00\u4e2a\u5de5\u4eba\u90fd\u6700\u591a\u53ea\u80fd\u5b89\u6392\u4e00\u4e2a\u5de5\u4f5c\uff0c\u4f46\u662f\u4e00\u4e2a\u5de5\u4f5c\u53ef\u4ee5\u5b8c\u6210\u591a\u6b21\u3002

    \n\n

    \u4e3e\u4e2a\u4f8b\u5b50\uff0c\u5982\u679c 3 \u4e2a\u5de5\u4eba\u90fd\u5c1d\u8bd5\u5b8c\u6210\u4e00\u4efd\u62a5\u916c\u4e3a 1 \u7684\u540c\u6837\u5de5\u4f5c\uff0c\u90a3\u4e48\u603b\u6536\u76ca\u4e3a $3\u3002\u5982\u679c\u4e00\u4e2a\u5de5\u4eba\u4e0d\u80fd\u5b8c\u6210\u4efb\u4f55\u5de5\u4f5c\uff0c\u4ed6\u7684\u6536\u76ca\u4e3a $0 \u3002

    \n\n

    \u6211\u4eec\u80fd\u5f97\u5230\u7684\u6700\u5927\u6536\u76ca\u662f\u591a\u5c11\uff1f

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165: difficulty = [2,4,6,8,10], profit = [10,20,30,40,50], worker = [4,5,6,7]\n\u8f93\u51fa: 100 \n\u89e3\u91ca: \u5de5\u4eba\u88ab\u5206\u914d\u7684\u5de5\u4f5c\u96be\u5ea6\u662f [4,4,6,6] \uff0c\u5206\u522b\u83b7\u5f97 [20,20,30,30] \u7684\u6536\u76ca\u3002
    \n\n

     

    \n\n

    \u63d0\u793a:

    \n\n
      \n\t
    • 1 <= difficulty.length = profit.length <= 10000
    • \n\t
    • 1 <= worker.length <= 10000
    • \n\t
    • difficulty[i], profit[i], worker[i]  \u7684\u8303\u56f4\u662f [1, 10^5]
    • \n
    \n", "tags_en": ["Two Pointers"], "tags_cn": ["\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxProfitAssignment(vector& difficulty, vector& profit, vector& worker) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxProfitAssignment(int[] difficulty, int[] profit, int[] worker) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxProfitAssignment(self, difficulty, profit, worker):\n \"\"\"\n :type difficulty: List[int]\n :type profit: List[int]\n :type worker: List[int]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxProfitAssignment(self, difficulty: List[int], profit: List[int], worker: List[int]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxProfitAssignment(int* difficulty, int difficultySize, int* profit, int profitSize, int* worker, int workerSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxProfitAssignment(int[] difficulty, int[] profit, int[] worker) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} difficulty\n * @param {number[]} profit\n * @param {number[]} worker\n * @return {number}\n */\nvar maxProfitAssignment = function(difficulty, profit, worker) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} difficulty\n# @param {Integer[]} profit\n# @param {Integer[]} worker\n# @return {Integer}\ndef max_profit_assignment(difficulty, profit, worker)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxProfitAssignment(_ difficulty: [Int], _ profit: [Int], _ worker: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxProfitAssignment(difficulty []int, profit []int, worker []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxProfitAssignment(difficulty: Array[Int], profit: Array[Int], worker: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxProfitAssignment(difficulty: IntArray, profit: IntArray, worker: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_profit_assignment(difficulty: Vec, profit: Vec, worker: Vec) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $difficulty\n * @param Integer[] $profit\n * @param Integer[] $worker\n * @return Integer\n */\n function maxProfitAssignment($difficulty, $profit, $worker) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxProfitAssignment(difficulty: number[], profit: number[], worker: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-profit-assignment difficulty profit worker)\n (-> (listof exact-integer?) (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0826](https://leetcode-cn.com/problems/most-profit-assigning-work)", "[\u5b89\u6392\u5de5\u4f5c\u4ee5\u8fbe\u5230\u6700\u5927\u6536\u76ca](/solution/0800-0899/0826.Most%20Profit%20Assigning%20Work/README.md)", "`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0826](https://leetcode.com/problems/most-profit-assigning-work)", "[Most Profit Assigning Work](/solution/0800-0899/0826.Most%20Profit%20Assigning%20Work/README_EN.md)", "`Two Pointers`", "Medium", ""]}, {"question_id": "0852", "frontend_question_id": "0825", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/friends-of-appropriate-ages", "url_en": "https://leetcode.com/problems/friends-of-appropriate-ages", "relative_path_cn": "/solution/0800-0899/0825.Friends%20Of%20Appropriate%20Ages/README.md", "relative_path_en": "/solution/0800-0899/0825.Friends%20Of%20Appropriate%20Ages/README_EN.md", "title_cn": "\u9002\u9f84\u7684\u670b\u53cb", "title_en": "Friends Of Appropriate Ages", "question_title_slug": "friends-of-appropriate-ages", "content_en": "

    Some people will make friend requests. The list of their ages is given and ages[i] is the age of the ith person. 

    \n\n

    Person A will NOT friend request person B (B != A) if any of the following conditions are true:

    \n\n
      \n\t
    • age[B] <= 0.5 * age[A] + 7
    • \n\t
    • age[B] > age[A]
    • \n\t
    • age[B] > 100 && age[A] < 100
    • \n
    \n\n

    Otherwise, A will friend request B.

    \n\n

    Note that if A requests B, B does not necessarily request A.  Also, people will not friend request themselves.

    \n\n

    How many total friend requests are made?

    \n\n

    Example 1:

    \n\n
    \nInput: [16,16]\nOutput: 2\nExplanation: 2 people friend request each other.\n
    \n\n

    Example 2:

    \n\n
    \nInput: [16,17,18]\nOutput: 2\nExplanation: Friend requests are made 17 -> 16, 18 -> 17.
    \n\n

    Example 3:

    \n\n
    \nInput: [20,30,100,110,120]\nOutput: 3\nExplanation: Friend requests are made 110 -> 100, 120 -> 110, 120 -> 100.\n
    \n\n

     

    \n\n

    Notes:

    \n\n
      \n\t
    • 1 <= ages.length <= 20000.
    • \n\t
    • 1 <= ages[i] <= 120.
    • \n
    \n", "content_cn": "

    \u4eba\u4eec\u4f1a\u4e92\u76f8\u53d1\u9001\u597d\u53cb\u8bf7\u6c42\uff0c\u73b0\u5728\u7ed9\u5b9a\u4e00\u4e2a\u5305\u542b\u6709\u4ed6\u4eec\u5e74\u9f84\u7684\u6570\u7ec4\uff0cages[i]\u00a0\u8868\u793a\u7b2c i \u4e2a\u4eba\u7684\u5e74\u9f84\u3002

    \n\n

    \u5f53\u6ee1\u8db3\u4ee5\u4e0b\u4efb\u4e00\u6761\u4ef6\u65f6\uff0cA \u4e0d\u80fd\u7ed9 B\uff08A\u3001B\u4e0d\u4e3a\u540c\u4e00\u4eba\uff09\u53d1\u9001\u597d\u53cb\u8bf7\u6c42\uff1a

    \n\n
      \n\t
    • age[B]\u00a0<= 0.5 * age[A]\u00a0+ 7
    • \n\t
    • age[B]\u00a0> age[A]
    • \n\t
    • age[B]\u00a0> 100 &&\u00a0age[A]\u00a0< 100
    • \n
    \n\n

    \u5426\u5219\uff0cA \u53ef\u4ee5\u7ed9 B \u53d1\u9001\u597d\u53cb\u8bf7\u6c42\u3002

    \n\n

    \u6ce8\u610f\u5982\u679c A \u5411 B \u53d1\u51fa\u4e86\u8bf7\u6c42\uff0c\u4e0d\u7b49\u4e8e B \u4e5f\u4e00\u5b9a\u4f1a\u5411\u00a0A \u53d1\u51fa\u8bf7\u6c42\u3002\u800c\u4e14\uff0c\u4eba\u4eec\u4e0d\u4f1a\u7ed9\u81ea\u5df1\u53d1\u9001\u597d\u53cb\u8bf7\u6c42\u3002\u00a0

    \n\n

    \u6c42\u603b\u5171\u4f1a\u53d1\u51fa\u591a\u5c11\u4efd\u597d\u53cb\u8bf7\u6c42?

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[16,16]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u4e8c\u4eba\u53ef\u4ee5\u4e92\u53d1\u597d\u53cb\u7533\u8bf7\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[16,17,18]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u597d\u53cb\u8bf7\u6c42\u53ef\u4ea7\u751f\u4e8e 17 -> 16, 18 -> 17.
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[20,30,100,110,120]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u597d\u53cb\u8bf7\u6c42\u53ef\u4ea7\u751f\u4e8e 110 -> 100, 120 -> 110, 120 -> 100.\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= ages.length\u00a0<= 20000
    • \n\t
    • 1 <= ages[i] <= 120
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numFriendRequests(vector& ages) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numFriendRequests(int[] ages) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numFriendRequests(self, ages):\n \"\"\"\n :type ages: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numFriendRequests(self, ages: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numFriendRequests(int* ages, int agesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumFriendRequests(int[] ages) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} ages\n * @return {number}\n */\nvar numFriendRequests = function(ages) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} ages\n# @return {Integer}\ndef num_friend_requests(ages)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numFriendRequests(_ ages: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numFriendRequests(ages []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numFriendRequests(ages: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numFriendRequests(ages: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_friend_requests(ages: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $ages\n * @return Integer\n */\n function numFriendRequests($ages) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numFriendRequests(ages: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-friend-requests ages)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0825](https://leetcode-cn.com/problems/friends-of-appropriate-ages)", "[\u9002\u9f84\u7684\u670b\u53cb](/solution/0800-0899/0825.Friends%20Of%20Appropriate%20Ages/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0825](https://leetcode.com/problems/friends-of-appropriate-ages)", "[Friends Of Appropriate Ages](/solution/0800-0899/0825.Friends%20Of%20Appropriate%20Ages/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0851", "frontend_question_id": "0824", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/goat-latin", "url_en": "https://leetcode.com/problems/goat-latin", "relative_path_cn": "/solution/0800-0899/0824.Goat%20Latin/README.md", "relative_path_en": "/solution/0800-0899/0824.Goat%20Latin/README_EN.md", "title_cn": "\u5c71\u7f8a\u62c9\u4e01\u6587", "title_en": "Goat Latin", "question_title_slug": "goat-latin", "content_en": "

    A sentence sentence is given, composed of words separated by spaces. Each word consists of lowercase and uppercase letters only.

    \n\n

    We would like to convert the sentence to "Goat Latin" (a made-up language similar to Pig Latin.)

    \n\n

    The rules of Goat Latin are as follows:

    \n\n
      \n\t
    • If a word begins with a vowel (a, e, i, o, or u), append "ma" to the end of the word.
      \n\tFor example, the word 'apple' becomes 'applema'.
      \n\t 
    • \n\t
    • If a word begins with a consonant (i.e. not a vowel), remove the first letter and append it to the end, then add "ma".
      \n\tFor example, the word "goat" becomes "oatgma".
      \n\t 
    • \n\t
    • Add one letter 'a' to the end of each word per its word index in the sentence, starting with 1.
      \n\tFor example, the first word gets "a" added to the end, the second word gets "aa" added to the end and so on.
    • \n
    \n\n

    Return the final sentence representing the conversion from sentence to Goat Latin. 

    \n\n

     

    \n\n

    Example 1:

    \n\n
    \nInput: sentence = "I speak Goat Latin"\nOutput: "Imaa peaksmaaa oatGmaaaa atinLmaaaaa"\n
    \n\n

    Example 2:

    \n\n
    \nInput: sentence = "The quick brown fox jumped over the lazy dog"\nOutput: "heTmaa uickqmaaa rownbmaaaa oxfmaaaaa umpedjmaaaaaa overmaaaaaaa hetmaaaaaaaa azylmaaaaaaaaa ogdmaaaaaaaaaa"\n
    \n\n

     

    \n\n

    Notes:

    \n\n
      \n\t
    • sentence contains only uppercase, lowercase and spaces. Exactly one space between each word.
    • \n\t
    • 1 <= sentence.length <= 150.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u7531\u7a7a\u683c\u5206\u5272\u5355\u8bcd\u7684\u53e5\u5b50 S\u3002\u6bcf\u4e2a\u5355\u8bcd\u53ea\u5305\u542b\u5927\u5199\u6216\u5c0f\u5199\u5b57\u6bcd\u3002

    \n\n

    \u6211\u4eec\u8981\u5c06\u53e5\u5b50\u8f6c\u6362\u4e3a “Goat Latin”\uff08\u4e00\u79cd\u7c7b\u4f3c\u4e8e \u732a\u62c9\u4e01\u6587 - Pig Latin \u7684\u865a\u6784\u8bed\u8a00\uff09\u3002

    \n\n

    \u5c71\u7f8a\u62c9\u4e01\u6587\u7684\u89c4\u5219\u5982\u4e0b\uff1a

    \n\n
      \n\t
    • \u5982\u679c\u5355\u8bcd\u4ee5\u5143\u97f3\u5f00\u5934\uff08a, e, i, o, u\uff09\uff0c\u5728\u5355\u8bcd\u540e\u6dfb\u52a0"ma"\u3002
      \n\t\u4f8b\u5982\uff0c\u5355\u8bcd"apple"\u53d8\u4e3a"applema"\u3002
    • \n\t
      \n\t
    • \u5982\u679c\u5355\u8bcd\u4ee5\u8f85\u97f3\u5b57\u6bcd\u5f00\u5934\uff08\u5373\u975e\u5143\u97f3\u5b57\u6bcd\uff09\uff0c\u79fb\u9664\u7b2c\u4e00\u4e2a\u5b57\u7b26\u5e76\u5c06\u5b83\u653e\u5230\u672b\u5c3e\uff0c\u4e4b\u540e\u518d\u6dfb\u52a0"ma"\u3002
      \n\t\u4f8b\u5982\uff0c\u5355\u8bcd"goat"\u53d8\u4e3a"oatgma"\u3002
    • \n\t
      \n\t
    • \u6839\u636e\u5355\u8bcd\u5728\u53e5\u5b50\u4e2d\u7684\u7d22\u5f15\uff0c\u5728\u5355\u8bcd\u6700\u540e\u6dfb\u52a0\u4e0e\u7d22\u5f15\u76f8\u540c\u6570\u91cf\u7684\u5b57\u6bcd'a'\uff0c\u7d22\u5f15\u4ece1\u5f00\u59cb\u3002
      \n\t\u4f8b\u5982\uff0c\u5728\u7b2c\u4e00\u4e2a\u5355\u8bcd\u540e\u6dfb\u52a0"a"\uff0c\u5728\u7b2c\u4e8c\u4e2a\u5355\u8bcd\u540e\u6dfb\u52a0"aa"\uff0c\u4ee5\u6b64\u7c7b\u63a8\u3002
    • \n
    \n\n

    \u8fd4\u56de\u5c06 S \u8f6c\u6362\u4e3a\u5c71\u7f8a\u62c9\u4e01\u6587\u540e\u7684\u53e5\u5b50\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: "I speak Goat Latin"\n\u8f93\u51fa: "Imaa peaksmaaa oatGmaaaa atinLmaaaaa"\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: "The quick brown fox jumped over the lazy dog"\n\u8f93\u51fa: "heTmaa uickqmaaa rownbmaaaa oxfmaaaaa umpedjmaaaaaa overmaaaaaaa hetmaaaaaaaa azylmaaaaaaaaa ogdmaaaaaaaaaa"\n
    \n\n

    \u8bf4\u660e:

    \n\n
      \n\t
    • S \u4e2d\u4ec5\u5305\u542b\u5927\u5c0f\u5199\u5b57\u6bcd\u548c\u7a7a\u683c\u3002\u5355\u8bcd\u95f4\u6709\u4e14\u4ec5\u6709\u4e00\u4e2a\u7a7a\u683c\u3002
    • \n\t
    • 1 <= S.length <= 150\u3002
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string toGoatLatin(string sentence) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String toGoatLatin(String sentence) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def toGoatLatin(self, sentence):\n \"\"\"\n :type sentence: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def toGoatLatin(self, sentence: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * toGoatLatin(char * sentence){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ToGoatLatin(string sentence) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} sentence\n * @return {string}\n */\nvar toGoatLatin = function(sentence) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} sentence\n# @return {String}\ndef to_goat_latin(sentence)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func toGoatLatin(_ sentence: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func toGoatLatin(sentence string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def toGoatLatin(sentence: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun toGoatLatin(sentence: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn to_goat_latin(sentence: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $sentence\n * @return String\n */\n function toGoatLatin($sentence) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function toGoatLatin(sentence: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (to-goat-latin sentence)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0824](https://leetcode-cn.com/problems/goat-latin)", "[\u5c71\u7f8a\u62c9\u4e01\u6587](/solution/0800-0899/0824.Goat%20Latin/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0824](https://leetcode.com/problems/goat-latin)", "[Goat Latin](/solution/0800-0899/0824.Goat%20Latin/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "0850", "frontend_question_id": "0708", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/insert-into-a-sorted-circular-linked-list", "url_en": "https://leetcode.com/problems/insert-into-a-sorted-circular-linked-list", "relative_path_cn": "/solution/0700-0799/0708.Insert%20into%20a%20Sorted%20Circular%20Linked%20List/README.md", "relative_path_en": "/solution/0700-0799/0708.Insert%20into%20a%20Sorted%20Circular%20Linked%20List/README_EN.md", "title_cn": "\u5faa\u73af\u6709\u5e8f\u5217\u8868\u7684\u63d2\u5165", "title_en": "Insert into a Sorted Circular Linked List", "question_title_slug": "insert-into-a-sorted-circular-linked-list", "content_en": "

    Given a Circular Linked List node, which is sorted in ascending order, write a function to insert a value insertVal into the list such that it remains a sorted circular list. The given node can be a reference to any single node in the list and may not necessarily be the smallest value in the circular list.

    \n\n

    If there are multiple suitable places for insertion, you may choose any place to insert the new value. After the insertion, the circular list should remain sorted.

    \n\n

    If the list is empty (i.e., the given node is null), you should create a new single circular list and return the reference to that single node. Otherwise, you should return the originally given node.

    \n\n

     

    \n

    Example 1:

    \n\"\"
    \n \n
    \nInput: head = [3,4,1], insertVal = 2\nOutput: [3,4,1,2]\nExplanation: In the figure above, there is a sorted circular list of three elements. You are given a reference to the node with value 3, and we need to insert 2 into the list. The new node should be inserted between node 1 and node 3. After the insertion, the list should look like this, and we should still return node 3.\n\n\"\"\n\n
    \n\n

    Example 2:

    \n\n
    \nInput: head = [], insertVal = 1\nOutput: [1]\nExplanation: The list is empty (given head is null). We create a new single circular list and return the reference to that single node.\n
    \n\n

    Example 3:

    \n\n
    \nInput: head = [1], insertVal = 0\nOutput: [1,0]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= Number of Nodes <= 5 * 104
    • \n\t
    • -106 <= Node.val, insertVal <= 106
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u5faa\u73af\u5347\u5e8f\u5217\u8868\u4e2d\u7684\u4e00\u4e2a\u70b9\uff0c\u5199\u4e00\u4e2a\u51fd\u6570\u5411\u8fd9\u4e2a\u5217\u8868\u4e2d\u63d2\u5165\u4e00\u4e2a\u65b0\u5143\u7d20\u00a0insertVal \uff0c\u4f7f\u8fd9\u4e2a\u5217\u8868\u4ecd\u7136\u662f\u5faa\u73af\u5347\u5e8f\u7684\u3002

    \n\n

    \u7ed9\u5b9a\u7684\u53ef\u4ee5\u662f\u8fd9\u4e2a\u5217\u8868\u4e2d\u4efb\u610f\u4e00\u4e2a\u9876\u70b9\u7684\u6307\u9488\uff0c\u5e76\u4e0d\u4e00\u5b9a\u662f\u8fd9\u4e2a\u5217\u8868\u4e2d\u6700\u5c0f\u5143\u7d20\u7684\u6307\u9488\u3002

    \n\n

    \u5982\u679c\u6709\u591a\u4e2a\u6ee1\u8db3\u6761\u4ef6\u7684\u63d2\u5165\u4f4d\u7f6e\uff0c\u4f60\u53ef\u4ee5\u9009\u62e9\u4efb\u610f\u4e00\u4e2a\u4f4d\u7f6e\u63d2\u5165\u65b0\u7684\u503c\uff0c\u63d2\u5165\u540e\u6574\u4e2a\u5217\u8868\u4ecd\u7136\u4fdd\u6301\u6709\u5e8f\u3002

    \n\n

    \u5982\u679c\u5217\u8868\u4e3a\u7a7a\uff08\u7ed9\u5b9a\u7684\u8282\u70b9\u662f null\uff09\uff0c\u4f60\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u5faa\u73af\u6709\u5e8f\u5217\u8868\u5e76\u8fd4\u56de\u8fd9\u4e2a\u8282\u70b9\u3002\u5426\u5219\u3002\u8bf7\u8fd4\u56de\u539f\u5148\u7ed9\u5b9a\u7684\u8282\u70b9\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"
    \n\u00a0\n
    \n\u8f93\u5165\uff1ahead = [3,4,1], insertVal = 2\n\u8f93\u51fa\uff1a[3,4,1,2]\n\u89e3\u91ca\uff1a\u5728\u4e0a\u56fe\u4e2d\uff0c\u6709\u4e00\u4e2a\u5305\u542b\u4e09\u4e2a\u5143\u7d20\u7684\u5faa\u73af\u6709\u5e8f\u5217\u8868\uff0c\u4f60\u83b7\u5f97\u503c\u4e3a 3 \u7684\u8282\u70b9\u7684\u6307\u9488\uff0c\u6211\u4eec\u9700\u8981\u5411\u8868\u4e2d\u63d2\u5165\u5143\u7d20 2 \u3002\u65b0\u63d2\u5165\u7684\u8282\u70b9\u5e94\u8be5\u5728 1 \u548c 3 \u4e4b\u95f4\uff0c\u63d2\u5165\u4e4b\u540e\uff0c\u6574\u4e2a\u5217\u8868\u5982\u4e0a\u56fe\u6240\u793a\uff0c\u6700\u540e\u8fd4\u56de\u8282\u70b9 3 \u3002\n\n\"\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahead = [], insertVal = 1\n\u8f93\u51fa\uff1a[1]\n\u89e3\u91ca\uff1a\u5217\u8868\u4e3a\u7a7a\uff08\u7ed9\u5b9a\u7684\u8282\u70b9\u662f null\uff09\uff0c\u521b\u5efa\u4e00\u4e2a\u5faa\u73af\u6709\u5e8f\u5217\u8868\u5e76\u8fd4\u56de\u8fd9\u4e2a\u8282\u70b9\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahead = [1], insertVal = 0\n\u8f93\u51fa\uff1a[1,0]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= Number of Nodes <= 5 * 10^4
    • \n\t
    • -10^6 <= Node.val <= 10^6
    • \n\t
    • -10^6 <=\u00a0insertVal <= 10^6
    • \n
    \n", "tags_en": ["Linked List"], "tags_cn": ["\u94fe\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* next;\n\n Node() {}\n\n Node(int _val) {\n val = _val;\n next = NULL;\n }\n\n Node(int _val, Node* _next) {\n val = _val;\n next = _next;\n }\n};\n*/\n\nclass Solution {\npublic:\n Node* insert(Node* head, int insertVal) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/*\n// Definition for a Node.\nclass Node {\n public int val;\n public Node next;\n\n public Node() {}\n\n public Node(int _val) {\n val = _val;\n }\n\n public Node(int _val, Node _next) {\n val = _val;\n next = _next;\n }\n};\n*/\n\nclass Solution {\n public Node insert(Node head, int insertVal) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "\"\"\"\n# Definition for a Node.\nclass Node(object):\n def __init__(self, val=None, next=None):\n self.val = val\n self.next = next\n\"\"\"\n\nclass Solution(object):\n def insert(self, head, insertVal):\n \"\"\"\n :type head: Node\n :type insertVal: int\n :rtype: Node\n \"\"\"\n\t\t", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "\"\"\"\n# Definition for a Node.\nclass Node:\n def __init__(self, val=None, next=None):\n self.val = val\n self.next = next\n\"\"\"\n\nclass Solution:\n def insert(self, head: 'Node', insertVal: int) -> 'Node':\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a Node.\n * struct Node {\n * int val;\n * struct TreeNode *next;\n * };\n */\n\nstruct Node* insert(struct Node* head, int insertVal) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/*\n// Definition for a Node.\npublic class Node {\n public int val;\n public Node next;\n\n public Node() {}\n\n public Node(int _val) {\n val = _val;\n next = null;\n }\n\n public Node(int _val, Node _next) {\n val = _val;\n next = _next;\n }\n}\n*/\n\npublic class Solution {\n public Node Insert(Node head, int insertVal) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // Definition for a Node.\n * function Node(val, next) {\n * this.val = val;\n * this.next = next;\n * };\n */\n\n/**\n * @param {Node} head\n * @param {number} insertVal\n * @return {Node}\n */\nvar insert = function(head, insertVal) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a Node.\n# class Node\n# attr_accessor :val, :next\n# def initialize(val=nil, next_=nil)\n# @val = val\n# @next = next_\n# end\n# end\n\n# @param {Node} head\n# @param {Integer} insertVal\n# @return {Node}\ndef insert(head, insertVal)\n\t\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a Node.\n * public class Node {\n * public var val: Int\n * public var next: Node?\n * public init(_ val: Int) {\n * self.val = val\n * self.next = nil\n * }\n * }\n */\n\nclass Solution {\n func insert(_ head: Node?, _ insertVal: Int) -> Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a Node.\n * type Node struct {\n * Val int\n * Next *Node\n * }\n */\n\nfunc insert(aNode *Node, x int) *Node {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a Node.\n * class Node(var _value: Int) {\n * var value: Int = _value\n * var next: Node = null\n * }\n */\n\nobject Solution {\n def insert(head: Node, insertVal: Int): Node = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a Node.\n * class Node(var `val`: Int) {\n * var next: Node? = null\n * }\n */\n\nclass Solution {\n fun insert(head: Node?, insertVal: Int): Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a Node.\n * class Node {\n * public $val = null;\n * public $next = null;\n * function __construct($val = 0) {\n * $this->val = $val;\n * $this->next = null;\n * }\n * }\n */\n\nclass Solution {\n /**\n * @param Node $root\n * @param Integer $insertVal\n * @return Node\n */\n function insert($head, $insertVal) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for node.\n * class Node {\n * val: number\n * next: Node | null\n * constructor(val?: number, next?: Node) {\n * this.val = (val===undefined ? 0 : val);\n * this.next = (next===undefined ? null : next);\n * }\n * }\n */\n\nfunction insert(head: Node | null, insertVal: number): Node | null {\n\t\n}", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0708](https://leetcode-cn.com/problems/insert-into-a-sorted-circular-linked-list)", "[\u5faa\u73af\u6709\u5e8f\u5217\u8868\u7684\u63d2\u5165](/solution/0700-0799/0708.Insert%20into%20a%20Sorted%20Circular%20Linked%20List/README.md)", "`\u94fe\u8868`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0708](https://leetcode.com/problems/insert-into-a-sorted-circular-linked-list)", "[Insert into a Sorted Circular Linked List](/solution/0700-0799/0708.Insert%20into%20a%20Sorted%20Circular%20Linked%20List/README_EN.md)", "`Linked List`", "Medium", "\ud83d\udd12"]}, {"question_id": "0843", "frontend_question_id": "0823", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/binary-trees-with-factors", "url_en": "https://leetcode.com/problems/binary-trees-with-factors", "relative_path_cn": "/solution/0800-0899/0823.Binary%20Trees%20With%20Factors/README.md", "relative_path_en": "/solution/0800-0899/0823.Binary%20Trees%20With%20Factors/README_EN.md", "title_cn": "\u5e26\u56e0\u5b50\u7684\u4e8c\u53c9\u6811", "title_en": "Binary Trees With Factors", "question_title_slug": "binary-trees-with-factors", "content_en": "

    Given an array of unique integers, arr, where each integer arr[i] is strictly greater than 1.

    \n\n

    We make a binary tree using these integers, and each number may be used for any number of times. Each non-leaf node's value should be equal to the product of the values of its children.

    \n\n

    Return the number of binary trees we can make. The answer may be too large so return the answer modulo 109 + 7.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr = [2,4]\nOutput: 3\nExplanation: We can make these trees: [2], [4], [4, 2, 2]
    \n\n

    Example 2:

    \n\n
    \nInput: arr = [2,4,5,10]\nOutput: 7\nExplanation: We can make these trees: [2], [4], [5], [10], [4, 2, 2], [10, 2, 5], [10, 5, 2].
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= arr.length <= 1000
    • \n\t
    • 2 <= arr[i] <= 109
    • \n\t
    • All the values of arr are unique.
    • \n
    \n", "content_cn": "

    \u7ed9\u51fa\u4e00\u4e2a\u542b\u6709\u4e0d\u91cd\u590d\u6574\u6570\u5143\u7d20\u7684\u6570\u7ec4\uff0c\u6bcf\u4e2a\u6574\u6570\u5747\u5927\u4e8e 1\u3002

    \n\n

    \u6211\u4eec\u7528\u8fd9\u4e9b\u6574\u6570\u6765\u6784\u5efa\u4e8c\u53c9\u6811\uff0c\u6bcf\u4e2a\u6574\u6570\u53ef\u4ee5\u4f7f\u7528\u4efb\u610f\u6b21\u6570\u3002

    \n\n

    \u5176\u4e2d\uff1a\u6bcf\u4e2a\u975e\u53f6\u7ed3\u70b9\u7684\u503c\u5e94\u7b49\u4e8e\u5b83\u7684\u4e24\u4e2a\u5b50\u7ed3\u70b9\u7684\u503c\u7684\u4e58\u79ef\u3002

    \n\n

    \u6ee1\u8db3\u6761\u4ef6\u7684\u4e8c\u53c9\u6811\u4e00\u5171\u6709\u591a\u5c11\u4e2a\uff1f\u8fd4\u56de\u7684\u7ed3\u679c\u5e94\u6a21\u9664 10 ** 9 + 7\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: A = [2, 4]\n\u8f93\u51fa: 3\n\u89e3\u91ca: \u6211\u4eec\u53ef\u4ee5\u5f97\u5230\u8fd9\u4e9b\u4e8c\u53c9\u6811: [2], [4], [4, 2, 2]
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: A = [2, 4, 5, 10]\n\u8f93\u51fa: 7\n\u89e3\u91ca: \u6211\u4eec\u53ef\u4ee5\u5f97\u5230\u8fd9\u4e9b\u4e8c\u53c9\u6811: [2], [4], [5], [10], [4, 2, 2], [10, 2, 5], [10, 5, 2].
    \n\n

     

    \n\n

    \u63d0\u793a:

    \n\n
      \n\t
    1. 1 <= A.length <= 1000.
    2. \n\t
    3. 2 <= A[i] <= 10 ^ 9.
    4. \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numFactoredBinaryTrees(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numFactoredBinaryTrees(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numFactoredBinaryTrees(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numFactoredBinaryTrees(self, arr: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numFactoredBinaryTrees(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumFactoredBinaryTrees(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar numFactoredBinaryTrees = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef num_factored_binary_trees(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numFactoredBinaryTrees(_ arr: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numFactoredBinaryTrees(arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numFactoredBinaryTrees(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numFactoredBinaryTrees(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_factored_binary_trees(arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function numFactoredBinaryTrees($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numFactoredBinaryTrees(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-factored-binary-trees arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0823](https://leetcode-cn.com/problems/binary-trees-with-factors)", "[\u5e26\u56e0\u5b50\u7684\u4e8c\u53c9\u6811](/solution/0800-0899/0823.Binary%20Trees%20With%20Factors/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0823](https://leetcode.com/problems/binary-trees-with-factors)", "[Binary Trees With Factors](/solution/0800-0899/0823.Binary%20Trees%20With%20Factors/README_EN.md)", "", "Medium", ""]}, {"question_id": "0842", "frontend_question_id": "0822", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/card-flipping-game", "url_en": "https://leetcode.com/problems/card-flipping-game", "relative_path_cn": "/solution/0800-0899/0822.Card%20Flipping%20Game/README.md", "relative_path_en": "/solution/0800-0899/0822.Card%20Flipping%20Game/README_EN.md", "title_cn": "\u7ffb\u8f6c\u5361\u7247\u6e38\u620f", "title_en": "Card Flipping Game", "question_title_slug": "card-flipping-game", "content_en": "

    On a table are N cards, with a positive integer printed on the front and back of each card (possibly different).

    \r\n\r\n

    We flip any number of cards, and after we choose one card. 

    \r\n\r\n

    If the number X on the back of the chosen card is not on the front of any card, then this number X is good.

    \r\n\r\n

    What is the smallest number that is good?  If no number is good, output 0.

    \r\n\r\n

    Here, fronts[i] and backs[i] represent the number on the front and back of card i

    \r\n\r\n

    A flip swaps the front and back numbers, so the value on the front is now on the back and vice versa.

    \r\n\r\n

    Example:

    \r\n\r\n
    \r\nInput: fronts = [1,2,4,4,7], backs = [1,3,4,1,3]\r\nOutput: 2\r\nExplanation: If we flip the second card, the fronts are [1,3,4,4,7] and the backs are [1,2,4,1,3].\r\nWe choose the second card, which has number 2 on the back, and it isn't on the front of any card, so 2 is good.
    \r\n\r\n

     

    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    1. 1 <= fronts.length == backs.length <= 1000.
    2. \r\n\t
    3. 1 <= fronts[i] <= 2000.
    4. \r\n\t
    5. 1 <= backs[i] <= 2000.
    6. \r\n
    \r\n", "content_cn": "

    \u5728\u684c\u5b50\u4e0a\u6709 N \u5f20\u5361\u7247\uff0c\u6bcf\u5f20\u5361\u7247\u7684\u6b63\u9762\u548c\u80cc\u9762\u90fd\u5199\u7740\u4e00\u4e2a\u6b63\u6570\uff08\u6b63\u9762\u4e0e\u80cc\u9762\u4e0a\u7684\u6570\u6709\u53ef\u80fd\u4e0d\u4e00\u6837\uff09\u3002

    \n\n

    \u6211\u4eec\u53ef\u4ee5\u5148\u7ffb\u8f6c\u4efb\u610f\u5f20\u5361\u7247\uff0c\u7136\u540e\u9009\u62e9\u5176\u4e2d\u4e00\u5f20\u5361\u7247\u3002

    \n\n

    \u5982\u679c\u9009\u4e2d\u7684\u90a3\u5f20\u5361\u7247\u80cc\u9762\u7684\u6570\u5b57 X \u4e0e\u4efb\u610f\u4e00\u5f20\u5361\u7247\u7684\u6b63\u9762\u7684\u6570\u5b57\u90fd\u4e0d\u540c\uff0c\u90a3\u4e48\u8fd9\u4e2a\u6570\u5b57\u662f\u6211\u4eec\u60f3\u8981\u7684\u6570\u5b57\u3002

    \n\n

    \u54ea\u4e2a\u6570\u662f\u8fd9\u4e9b\u60f3\u8981\u7684\u6570\u5b57\u4e2d\u6700\u5c0f\u7684\u6570\uff08\u627e\u5230\u8fd9\u4e9b\u6570\u4e2d\u7684\u6700\u5c0f\u503c\uff09\u5462\uff1f\u5982\u679c\u6ca1\u6709\u4e00\u4e2a\u6570\u5b57\u7b26\u5408\u8981\u6c42\u7684\uff0c\u8f93\u51fa 0\u3002

    \n\n

    \u5176\u4e2d, fronts[i] \u548c backs[i] \u5206\u522b\u4ee3\u8868\u7b2c i \u5f20\u5361\u7247\u7684\u6b63\u9762\u548c\u80cc\u9762\u7684\u6570\u5b57\u3002

    \n\n

    \u5982\u679c\u6211\u4eec\u901a\u8fc7\u7ffb\u8f6c\u5361\u7247\u6765\u4ea4\u6362\u6b63\u9762\u4e0e\u80cc\u9762\u4e0a\u7684\u6570\uff0c\u90a3\u4e48\u5f53\u521d\u5728\u6b63\u9762\u7684\u6570\u5c31\u53d8\u6210\u80cc\u9762\u7684\u6570\uff0c\u80cc\u9762\u7684\u6570\u5c31\u53d8\u6210\u6b63\u9762\u7684\u6570\u3002

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1afronts = [1,2,4,4,7], backs = [1,3,4,1,3]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5047\u8bbe\u6211\u4eec\u7ffb\u8f6c\u7b2c\u4e8c\u5f20\u5361\u7247\uff0c\u90a3\u4e48\u5728\u6b63\u9762\u7684\u6570\u53d8\u6210\u4e86 [1,3,4,4,7] \uff0c \u80cc\u9762\u7684\u6570\u53d8\u6210\u4e86 [1,2,4,1,3]\u3002\n\u63a5\u7740\u6211\u4eec\u9009\u62e9\u7b2c\u4e8c\u5f20\u5361\u7247\uff0c\u56e0\u4e3a\u73b0\u5728\u8be5\u5361\u7247\u7684\u80cc\u9762\u7684\u6570\u662f 2\uff0c2 \u4e0e\u4efb\u610f\u5361\u7247\u4e0a\u6b63\u9762\u7684\u6570\u90fd\u4e0d\u540c\uff0c\u6240\u4ee5 2 \u5c31\u662f\u6211\u4eec\u60f3\u8981\u7684\u6570\u5b57\u3002
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. 1 <= fronts.length == backs.length <= 1000
    2. \n\t
    3. 1 <= fronts[i] <= 2000
    4. \n\t
    5. 1 <= backs[i] <= 2000
    6. \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int flipgame(vector& fronts, vector& backs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int flipgame(int[] fronts, int[] backs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def flipgame(self, fronts, backs):\n \"\"\"\n :type fronts: List[int]\n :type backs: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def flipgame(self, fronts: List[int], backs: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint flipgame(int* fronts, int frontsSize, int* backs, int backsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int Flipgame(int[] fronts, int[] backs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} fronts\n * @param {number[]} backs\n * @return {number}\n */\nvar flipgame = function(fronts, backs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} fronts\n# @param {Integer[]} backs\n# @return {Integer}\ndef flipgame(fronts, backs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func flipgame(_ fronts: [Int], _ backs: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func flipgame(fronts []int, backs []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def flipgame(fronts: Array[Int], backs: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun flipgame(fronts: IntArray, backs: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn flipgame(fronts: Vec, backs: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $fronts\n * @param Integer[] $backs\n * @return Integer\n */\n function flipgame($fronts, $backs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function flipgame(fronts: number[], backs: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (flipgame fronts backs)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0822](https://leetcode-cn.com/problems/card-flipping-game)", "[\u7ffb\u8f6c\u5361\u7247\u6e38\u620f](/solution/0800-0899/0822.Card%20Flipping%20Game/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0822](https://leetcode.com/problems/card-flipping-game)", "[Card Flipping Game](/solution/0800-0899/0822.Card%20Flipping%20Game/README_EN.md)", "", "Medium", ""]}, {"question_id": "0841", "frontend_question_id": "0821", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/shortest-distance-to-a-character", "url_en": "https://leetcode.com/problems/shortest-distance-to-a-character", "relative_path_cn": "/solution/0800-0899/0821.Shortest%20Distance%20to%20a%20Character/README.md", "relative_path_en": "/solution/0800-0899/0821.Shortest%20Distance%20to%20a%20Character/README_EN.md", "title_cn": "\u5b57\u7b26\u7684\u6700\u77ed\u8ddd\u79bb", "title_en": "Shortest Distance to a Character", "question_title_slug": "shortest-distance-to-a-character", "content_en": "

    Given a string s and a character c that occurs in s, return an array of integers answer where answer.length == s.length and answer[i] is the distance from index i to the closest occurrence of character c in s.

    \n\n

    The distance between two indices i and j is abs(i - j), where abs is the absolute value function.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "loveleetcode", c = "e"\nOutput: [3,2,1,0,1,0,0,1,2,2,1,0]\nExplanation: The character 'e' appears at indices 3, 5, 6, and 11 (0-indexed).\nThe closest occurrence of 'e' for index 0 is at index 3, so the distance is abs(0 - 3) = 3.\nThe closest occurrence of 'e' for index 1 is at index 3, so the distance is abs(1 - 3) = 3.\nFor index 4, there is a tie between the 'e' at index 3 and the 'e' at index 5, but the distance is still the same: abs(4 - 3) == abs(4 - 5) = 1.\nThe closest occurrence of 'e' for index 8 is at index 6, so the distance is abs(8 - 6) = 2.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "aaab", c = "b"\nOutput: [3,2,1,0]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 104
    • \n\t
    • s[i] and c are lowercase English letters.
    • \n\t
    • It is guaranteed that c occurs at least once in s.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \u548c\u4e00\u4e2a\u5b57\u7b26 c \uff0c\u4e14 c \u662f s \u4e2d\u51fa\u73b0\u8fc7\u7684\u5b57\u7b26\u3002

    \n\n

    \u8fd4\u56de\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 answer \uff0c\u5176\u4e2d answer.length == s.length \u4e14 answer[i] \u662f s \u4e2d\u4ece\u4e0b\u6807 i \u5230\u79bb\u5b83 \u6700\u8fd1 \u7684\u5b57\u7b26 c \u7684 \u8ddd\u79bb \u3002

    \n\n

    \u4e24\u4e2a\u4e0b\u6807\u00a0i \u548c j \u4e4b\u95f4\u7684 \u8ddd\u79bb \u4e3a abs(i - j) \uff0c\u5176\u4e2d abs \u662f\u7edd\u5bf9\u503c\u51fd\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"loveleetcode\", c = \"e\"\n\u8f93\u51fa\uff1a[3,2,1,0,1,0,0,1,2,2,1,0]\n\u89e3\u91ca\uff1a\u5b57\u7b26 'e' \u51fa\u73b0\u5728\u4e0b\u6807 3\u30015\u30016 \u548c 11 \u5904\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\u8ba1\u6570\uff09\u3002\n\u8ddd\u4e0b\u6807 0 \u6700\u8fd1\u7684 'e' \u51fa\u73b0\u5728\u4e0b\u6807 3 \uff0c\u6240\u4ee5\u8ddd\u79bb\u4e3a abs(0 - 3) = 3 \u3002\n\u8ddd\u4e0b\u6807 1 \u6700\u8fd1\u7684 'e' \u51fa\u73b0\u5728\u4e0b\u6807 3 \uff0c\u6240\u4ee5\u8ddd\u79bb\u4e3a abs(1 - 3) = 3 \u3002\n\u5bf9\u4e8e\u4e0b\u6807 4 \uff0c\u51fa\u73b0\u5728\u4e0b\u6807 3 \u548c\u4e0b\u6807 5 \u5904\u7684 'e' \u90fd\u79bb\u5b83\u6700\u8fd1\uff0c\u4f46\u8ddd\u79bb\u662f\u4e00\u6837\u7684 abs(4 - 3) == abs(4 - 5) = 1 \u3002\n\u8ddd\u4e0b\u6807 8 \u6700\u8fd1\u7684 'e' \u51fa\u73b0\u5728\u4e0b\u6807 6 \uff0c\u6240\u4ee5\u8ddd\u79bb\u4e3a abs(8 - 6) = 2 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"aaab\", c = \"b\"\n\u8f93\u51fa\uff1a[3,2,1,0]\n
    \n\n

    \u00a0

    \n\u63d0\u793a\uff1a\n\n
      \n\t
    • 1 <= s.length <= 104
    • \n\t
    • s[i] \u548c c \u5747\u4e3a\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd
    • \n\t
    • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1 c \u5728 s \u4e2d\u81f3\u5c11\u51fa\u73b0\u4e00\u6b21
    • \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector shortestToChar(string s, char c) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] shortestToChar(String s, char c) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def shortestToChar(self, s, c):\n \"\"\"\n :type s: str\n :type c: str\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def shortestToChar(self, s: str, c: str) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* shortestToChar(char * s, char c, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] ShortestToChar(string s, char c) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {character} c\n * @return {number[]}\n */\nvar shortestToChar = function(s, c) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Character} c\n# @return {Integer[]}\ndef shortest_to_char(s, c)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func shortestToChar(_ s: String, _ c: Character) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func shortestToChar(s string, c byte) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def shortestToChar(s: String, c: Char): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun shortestToChar(s: String, c: Char): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn shortest_to_char(s: String, c: char) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String $c\n * @return Integer[]\n */\n function shortestToChar($s, $c) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function shortestToChar(s: string, c: string): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (shortest-to-char s c)\n (-> string? char? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0821](https://leetcode-cn.com/problems/shortest-distance-to-a-character)", "[\u5b57\u7b26\u7684\u6700\u77ed\u8ddd\u79bb](/solution/0800-0899/0821.Shortest%20Distance%20to%20a%20Character/README.md)", "", "\u7b80\u5355", ""], "md_table_row_en": ["[0821](https://leetcode.com/problems/shortest-distance-to-a-character)", "[Shortest Distance to a Character](/solution/0800-0899/0821.Shortest%20Distance%20to%20a%20Character/README_EN.md)", "", "Easy", ""]}, {"question_id": "0839", "frontend_question_id": "0820", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/short-encoding-of-words", "url_en": "https://leetcode.com/problems/short-encoding-of-words", "relative_path_cn": "/solution/0800-0899/0820.Short%20Encoding%20of%20Words/README.md", "relative_path_en": "/solution/0800-0899/0820.Short%20Encoding%20of%20Words/README_EN.md", "title_cn": "\u5355\u8bcd\u7684\u538b\u7f29\u7f16\u7801", "title_en": "Short Encoding of Words", "question_title_slug": "short-encoding-of-words", "content_en": "

    A valid encoding of an array of words is any reference string s and array of indices indices such that:

    \n\n
      \n\t
    • words.length == indices.length
    • \n\t
    • The reference string s ends with the '#' character.
    • \n\t
    • For each index indices[i], the substring of s starting from indices[i] and up to (but not including) the next '#' character is equal to words[i].
    • \n
    \n\n

    Given an array of words, return the length of the shortest reference string s possible of any valid encoding of words.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: words = ["time", "me", "bell"]\nOutput: 10\nExplanation: A valid encoding would be s = "time#bell#" and indices = [0, 2, 5].\nwords[0] = "time", the substring of s starting from indices[0] = 0 to the next '#' is underlined in "time#bell#"\nwords[1] = "me", the substring of s starting from indices[1] = 2 to the next '#' is underlined in "time#bell#"\nwords[2] = "bell", the substring of s starting from indices[2] = 5 to the next '#' is underlined in "time#bell#"\n
    \n\n

    Example 2:

    \n\n
    \nInput: words = ["t"]\nOutput: 2\nExplanation: A valid encoding would be s = "t#" and indices = [0].\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= words.length <= 2000
    • \n\t
    • 1 <= words[i].length <= 7
    • \n\t
    • words[i] consists of only lowercase letters.
    • \n
    \n", "content_cn": "

    \u5355\u8bcd\u6570\u7ec4\u00a0words \u7684 \u6709\u6548\u7f16\u7801 \u7531\u4efb\u610f\u52a9\u8bb0\u5b57\u7b26\u4e32 s \u548c\u4e0b\u6807\u6570\u7ec4 indices \u7ec4\u6210\uff0c\u4e14\u6ee1\u8db3\uff1a

    \n\n
      \n\t
    • words.length == indices.length
    • \n\t
    • \u52a9\u8bb0\u5b57\u7b26\u4e32 s \u4ee5 '#' \u5b57\u7b26\u7ed3\u5c3e
    • \n\t
    • \u5bf9\u4e8e\u6bcf\u4e2a\u4e0b\u6807 indices[i] \uff0cs \u7684\u4e00\u4e2a\u4ece indices[i] \u5f00\u59cb\u3001\u5230\u4e0b\u4e00\u4e2a '#' \u5b57\u7b26\u7ed3\u675f\uff08\u4f46\u4e0d\u5305\u62ec '#'\uff09\u7684 \u5b50\u5b57\u7b26\u4e32 \u6070\u597d\u4e0e words[i] \u76f8\u7b49
    • \n
    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u5355\u8bcd\u6570\u7ec4\u00a0words \uff0c\u8fd4\u56de\u6210\u529f\u5bf9 words \u8fdb\u884c\u7f16\u7801\u7684\u6700\u5c0f\u52a9\u8bb0\u5b57\u7b26\u4e32 s \u7684\u957f\u5ea6 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1awords = [\"time\", \"me\", \"bell\"]\n\u8f93\u51fa\uff1a10\n\u89e3\u91ca\uff1a\u4e00\u7ec4\u6709\u6548\u7f16\u7801\u4e3a s = \"time#bell#\" \u548c indices = [0, 2, 5] \u3002\nwords[0] = \"time\" \uff0cs \u5f00\u59cb\u4e8e indices[0] = 0 \u5230\u4e0b\u4e00\u4e2a '#' \u7ed3\u675f\u7684\u5b50\u5b57\u7b26\u4e32\uff0c\u5982\u52a0\u7c97\u90e8\u5206\u6240\u793a \"time#bell#\"\nwords[1] = \"me\" \uff0cs \u5f00\u59cb\u4e8e indices[1] = 2 \u5230\u4e0b\u4e00\u4e2a '#' \u7ed3\u675f\u7684\u5b50\u5b57\u7b26\u4e32\uff0c\u5982\u52a0\u7c97\u90e8\u5206\u6240\u793a \"time#bell#\"\nwords[2] = \"bell\" \uff0cs \u5f00\u59cb\u4e8e indices[2] = 5 \u5230\u4e0b\u4e00\u4e2a '#' \u7ed3\u675f\u7684\u5b50\u5b57\u7b26\u4e32\uff0c\u5982\u52a0\u7c97\u90e8\u5206\u6240\u793a \"time#bell#\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1awords = [\"t\"]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u4e00\u7ec4\u6709\u6548\u7f16\u7801\u4e3a s = \"t#\" \u548c indices = [0] \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= words.length <= 2000
    • \n\t
    • 1 <= words[i].length <= 7
    • \n\t
    • words[i] \u4ec5\u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minimumLengthEncoding(vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minimumLengthEncoding(String[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimumLengthEncoding(self, words):\n \"\"\"\n :type words: List[str]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimumLengthEncoding(self, words: List[str]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minimumLengthEncoding(char ** words, int wordsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinimumLengthEncoding(string[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @return {number}\n */\nvar minimumLengthEncoding = function(words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @return {Integer}\ndef minimum_length_encoding(words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimumLengthEncoding(_ words: [String]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimumLengthEncoding(words []string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimumLengthEncoding(words: Array[String]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimumLengthEncoding(words: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimum_length_encoding(words: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @return Integer\n */\n function minimumLengthEncoding($words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimumLengthEncoding(words: string[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimum-length-encoding words)\n (-> (listof string?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0820](https://leetcode-cn.com/problems/short-encoding-of-words)", "[\u5355\u8bcd\u7684\u538b\u7f29\u7f16\u7801](/solution/0800-0899/0820.Short%20Encoding%20of%20Words/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0820](https://leetcode.com/problems/short-encoding-of-words)", "[Short Encoding of Words](/solution/0800-0899/0820.Short%20Encoding%20of%20Words/README_EN.md)", "", "Medium", ""]}, {"question_id": "0838", "frontend_question_id": "0707", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/design-linked-list", "url_en": "https://leetcode.com/problems/design-linked-list", "relative_path_cn": "/solution/0700-0799/0707.Design%20Linked%20List/README.md", "relative_path_en": "/solution/0700-0799/0707.Design%20Linked%20List/README_EN.md", "title_cn": "\u8bbe\u8ba1\u94fe\u8868", "title_en": "Design Linked List", "question_title_slug": "design-linked-list", "content_en": "

    Design your implementation of the linked list. You can choose to use a singly or doubly linked list.
    \nA node in a singly linked list should have two attributes: val and next. val is the value of the current node, and next is a pointer/reference to the next node.
    \nIf you want to use the doubly linked list, you will need one more attribute prev to indicate the previous node in the linked list. Assume all nodes in the linked list are 0-indexed.

    \n\n

    Implement the MyLinkedList class:

    \n\n
      \n\t
    • MyLinkedList() Initializes the MyLinkedList object.
    • \n\t
    • int get(int index) Get the value of the indexth node in the linked list. If the index is invalid, return -1.
    • \n\t
    • void addAtHead(int val) Add a node of value val before the first element of the linked list. After the insertion, the new node will be the first node of the linked list.
    • \n\t
    • void addAtTail(int val) Append a node of value val as the last element of the linked list.
    • \n\t
    • void addAtIndex(int index, int val) Add a node of value val before the indexth node in the linked list. If index equals the length of the linked list, the node will be appended to the end of the linked list. If index is greater than the length, the node will not be inserted.
    • \n\t
    • void deleteAtIndex(int index) Delete the indexth node in the linked list, if the index is valid.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["MyLinkedList", "addAtHead", "addAtTail", "addAtIndex", "get", "deleteAtIndex", "get"]\n[[], [1], [3], [1, 2], [1], [1], [1]]\nOutput\n[null, null, null, null, 2, null, 3]\n\nExplanation\nMyLinkedList myLinkedList = new MyLinkedList();\nmyLinkedList.addAtHead(1);\nmyLinkedList.addAtTail(3);\nmyLinkedList.addAtIndex(1, 2);    // linked list becomes 1->2->3\nmyLinkedList.get(1);              // return 2\nmyLinkedList.deleteAtIndex(1);    // now the linked list is 1->3\nmyLinkedList.get(1);              // return 3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= index, val <= 1000
    • \n\t
    • Please do not use the built-in LinkedList library.
    • \n\t
    • At most 2000 calls will be made to get, addAtHead, addAtTail, addAtIndex and deleteAtIndex.
    • \n
    \n", "content_cn": "

    \u8bbe\u8ba1\u94fe\u8868\u7684\u5b9e\u73b0\u3002\u60a8\u53ef\u4ee5\u9009\u62e9\u4f7f\u7528\u5355\u94fe\u8868\u6216\u53cc\u94fe\u8868\u3002\u5355\u94fe\u8868\u4e2d\u7684\u8282\u70b9\u5e94\u8be5\u5177\u6709\u4e24\u4e2a\u5c5e\u6027\uff1aval \u548c next\u3002val \u662f\u5f53\u524d\u8282\u70b9\u7684\u503c\uff0cnext \u662f\u6307\u5411\u4e0b\u4e00\u4e2a\u8282\u70b9\u7684\u6307\u9488/\u5f15\u7528\u3002\u5982\u679c\u8981\u4f7f\u7528\u53cc\u5411\u94fe\u8868\uff0c\u5219\u8fd8\u9700\u8981\u4e00\u4e2a\u5c5e\u6027 prev \u4ee5\u6307\u793a\u94fe\u8868\u4e2d\u7684\u4e0a\u4e00\u4e2a\u8282\u70b9\u3002\u5047\u8bbe\u94fe\u8868\u4e2d\u7684\u6240\u6709\u8282\u70b9\u90fd\u662f 0-index \u7684\u3002

    \n\n

    \u5728\u94fe\u8868\u7c7b\u4e2d\u5b9e\u73b0\u8fd9\u4e9b\u529f\u80fd\uff1a

    \n\n
      \n\t
    • get(index)\uff1a\u83b7\u53d6\u94fe\u8868\u4e2d\u7b2c index \u4e2a\u8282\u70b9\u7684\u503c\u3002\u5982\u679c\u7d22\u5f15\u65e0\u6548\uff0c\u5219\u8fd4\u56de-1\u3002
    • \n\t
    • addAtHead(val)\uff1a\u5728\u94fe\u8868\u7684\u7b2c\u4e00\u4e2a\u5143\u7d20\u4e4b\u524d\u6dfb\u52a0\u4e00\u4e2a\u503c\u4e3a val \u7684\u8282\u70b9\u3002\u63d2\u5165\u540e\uff0c\u65b0\u8282\u70b9\u5c06\u6210\u4e3a\u94fe\u8868\u7684\u7b2c\u4e00\u4e2a\u8282\u70b9\u3002
    • \n\t
    • addAtTail(val)\uff1a\u5c06\u503c\u4e3a val \u7684\u8282\u70b9\u8ffd\u52a0\u5230\u94fe\u8868\u7684\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u3002
    • \n\t
    • addAtIndex(index,val)\uff1a\u5728\u94fe\u8868\u4e2d\u7684\u7b2c index \u4e2a\u8282\u70b9\u4e4b\u524d\u6dfb\u52a0\u503c\u4e3a val  \u7684\u8282\u70b9\u3002\u5982\u679c index \u7b49\u4e8e\u94fe\u8868\u7684\u957f\u5ea6\uff0c\u5219\u8be5\u8282\u70b9\u5c06\u9644\u52a0\u5230\u94fe\u8868\u7684\u672b\u5c3e\u3002\u5982\u679c index \u5927\u4e8e\u94fe\u8868\u957f\u5ea6\uff0c\u5219\u4e0d\u4f1a\u63d2\u5165\u8282\u70b9\u3002\u5982\u679cindex\u5c0f\u4e8e0\uff0c\u5219\u5728\u5934\u90e8\u63d2\u5165\u8282\u70b9\u3002
    • \n\t
    • deleteAtIndex(index)\uff1a\u5982\u679c\u7d22\u5f15 index \u6709\u6548\uff0c\u5219\u5220\u9664\u94fe\u8868\u4e2d\u7684\u7b2c index \u4e2a\u8282\u70b9\u3002
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    MyLinkedList linkedList = new MyLinkedList();\nlinkedList.addAtHead(1);\nlinkedList.addAtTail(3);\nlinkedList.addAtIndex(1,2);   //\u94fe\u8868\u53d8\u4e3a1-> 2-> 3\nlinkedList.get(1);            //\u8fd4\u56de2\nlinkedList.deleteAtIndex(1);  //\u73b0\u5728\u94fe\u8868\u662f1-> 3\nlinkedList.get(1);            //\u8fd4\u56de3\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6240\u6709val\u503c\u90fd\u5728 [1, 1000] \u4e4b\u5185\u3002
    • \n\t
    • \u64cd\u4f5c\u6b21\u6570\u5c06\u5728  [1, 1000] \u4e4b\u5185\u3002
    • \n\t
    • \u8bf7\u4e0d\u8981\u4f7f\u7528\u5185\u7f6e\u7684 LinkedList \u5e93\u3002
    • \n
    \n", "tags_en": ["Design", "Linked List"], "tags_cn": ["\u8bbe\u8ba1", "\u94fe\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class MyLinkedList {\npublic:\n /** Initialize your data structure here. */\n MyLinkedList() {\n\n }\n \n /** Get the value of the index-th node in the linked list. If the index is invalid, return -1. */\n int get(int index) {\n\n }\n \n /** Add a node of value val before the first element of the linked list. After the insertion, the new node will be the first node of the linked list. */\n void addAtHead(int val) {\n\n }\n \n /** Append a node of value val to the last element of the linked list. */\n void addAtTail(int val) {\n\n }\n \n /** Add a node of value val before the index-th node in the linked list. If index equals to the length of linked list, the node will be appended to the end of linked list. If index is greater than the length, the node will not be inserted. */\n void addAtIndex(int index, int val) {\n\n }\n \n /** Delete the index-th node in the linked list, if the index is valid. */\n void deleteAtIndex(int index) {\n\n }\n};\n\n/**\n * Your MyLinkedList object will be instantiated and called as such:\n * MyLinkedList* obj = new MyLinkedList();\n * int param_1 = obj->get(index);\n * obj->addAtHead(val);\n * obj->addAtTail(val);\n * obj->addAtIndex(index,val);\n * obj->deleteAtIndex(index);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class MyLinkedList {\n\n /** Initialize your data structure here. */\n public MyLinkedList() {\n\n }\n \n /** Get the value of the index-th node in the linked list. If the index is invalid, return -1. */\n public int get(int index) {\n\n }\n \n /** Add a node of value val before the first element of the linked list. After the insertion, the new node will be the first node of the linked list. */\n public void addAtHead(int val) {\n\n }\n \n /** Append a node of value val to the last element of the linked list. */\n public void addAtTail(int val) {\n\n }\n \n /** Add a node of value val before the index-th node in the linked list. If index equals to the length of linked list, the node will be appended to the end of linked list. If index is greater than the length, the node will not be inserted. */\n public void addAtIndex(int index, int val) {\n\n }\n \n /** Delete the index-th node in the linked list, if the index is valid. */\n public void deleteAtIndex(int index) {\n\n }\n}\n\n/**\n * Your MyLinkedList object will be instantiated and called as such:\n * MyLinkedList obj = new MyLinkedList();\n * int param_1 = obj.get(index);\n * obj.addAtHead(val);\n * obj.addAtTail(val);\n * obj.addAtIndex(index,val);\n * obj.deleteAtIndex(index);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class MyLinkedList(object):\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def get(self, index):\n \"\"\"\n Get the value of the index-th node in the linked list. If the index is invalid, return -1.\n :type index: int\n :rtype: int\n \"\"\"\n\n\n def addAtHead(self, val):\n \"\"\"\n Add a node of value val before the first element of the linked list. After the insertion, the new node will be the first node of the linked list.\n :type val: int\n :rtype: None\n \"\"\"\n\n\n def addAtTail(self, val):\n \"\"\"\n Append a node of value val to the last element of the linked list.\n :type val: int\n :rtype: None\n \"\"\"\n\n\n def addAtIndex(self, index, val):\n \"\"\"\n Add a node of value val before the index-th node in the linked list. If index equals to the length of linked list, the node will be appended to the end of linked list. If index is greater than the length, the node will not be inserted.\n :type index: int\n :type val: int\n :rtype: None\n \"\"\"\n\n\n def deleteAtIndex(self, index):\n \"\"\"\n Delete the index-th node in the linked list, if the index is valid.\n :type index: int\n :rtype: None\n \"\"\"\n\n\n\n# Your MyLinkedList object will be instantiated and called as such:\n# obj = MyLinkedList()\n# param_1 = obj.get(index)\n# obj.addAtHead(val)\n# obj.addAtTail(val)\n# obj.addAtIndex(index,val)\n# obj.deleteAtIndex(index)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class MyLinkedList:\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def get(self, index: int) -> int:\n \"\"\"\n Get the value of the index-th node in the linked list. If the index is invalid, return -1.\n \"\"\"\n\n\n def addAtHead(self, val: int) -> None:\n \"\"\"\n Add a node of value val before the first element of the linked list. After the insertion, the new node will be the first node of the linked list.\n \"\"\"\n\n\n def addAtTail(self, val: int) -> None:\n \"\"\"\n Append a node of value val to the last element of the linked list.\n \"\"\"\n\n\n def addAtIndex(self, index: int, val: int) -> None:\n \"\"\"\n Add a node of value val before the index-th node in the linked list. If index equals to the length of linked list, the node will be appended to the end of linked list. If index is greater than the length, the node will not be inserted.\n \"\"\"\n\n\n def deleteAtIndex(self, index: int) -> None:\n \"\"\"\n Delete the index-th node in the linked list, if the index is valid.\n \"\"\"\n\n\n\n# Your MyLinkedList object will be instantiated and called as such:\n# obj = MyLinkedList()\n# param_1 = obj.get(index)\n# obj.addAtHead(val)\n# obj.addAtTail(val)\n# obj.addAtIndex(index,val)\n# obj.deleteAtIndex(index)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} MyLinkedList;\n\n/** Initialize your data structure here. */\n\nMyLinkedList* myLinkedListCreate() {\n\n}\n\n/** Get the value of the index-th node in the linked list. If the index is invalid, return -1. */\nint myLinkedListGet(MyLinkedList* obj, int index) {\n\n}\n\n/** Add a node of value val before the first element of the linked list. After the insertion, the new node will be the first node of the linked list. */\nvoid myLinkedListAddAtHead(MyLinkedList* obj, int val) {\n\n}\n\n/** Append a node of value val to the last element of the linked list. */\nvoid myLinkedListAddAtTail(MyLinkedList* obj, int val) {\n\n}\n\n/** Add a node of value val before the index-th node in the linked list. If index equals to the length of linked list, the node will be appended to the end of linked list. If index is greater than the length, the node will not be inserted. */\nvoid myLinkedListAddAtIndex(MyLinkedList* obj, int index, int val) {\n\n}\n\n/** Delete the index-th node in the linked list, if the index is valid. */\nvoid myLinkedListDeleteAtIndex(MyLinkedList* obj, int index) {\n\n}\n\nvoid myLinkedListFree(MyLinkedList* obj) {\n\n}\n\n/**\n * Your MyLinkedList struct will be instantiated and called as such:\n * MyLinkedList* obj = myLinkedListCreate();\n * int param_1 = myLinkedListGet(obj, index);\n \n * myLinkedListAddAtHead(obj, val);\n \n * myLinkedListAddAtTail(obj, val);\n \n * myLinkedListAddAtIndex(obj, index, val);\n \n * myLinkedListDeleteAtIndex(obj, index);\n \n * myLinkedListFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class MyLinkedList {\n\n /** Initialize your data structure here. */\n public MyLinkedList() {\n\n }\n \n /** Get the value of the index-th node in the linked list. If the index is invalid, return -1. */\n public int Get(int index) {\n\n }\n \n /** Add a node of value val before the first element of the linked list. After the insertion, the new node will be the first node of the linked list. */\n public void AddAtHead(int val) {\n\n }\n \n /** Append a node of value val to the last element of the linked list. */\n public void AddAtTail(int val) {\n\n }\n \n /** Add a node of value val before the index-th node in the linked list. If index equals to the length of linked list, the node will be appended to the end of linked list. If index is greater than the length, the node will not be inserted. */\n public void AddAtIndex(int index, int val) {\n\n }\n \n /** Delete the index-th node in the linked list, if the index is valid. */\n public void DeleteAtIndex(int index) {\n\n }\n}\n\n/**\n * Your MyLinkedList object will be instantiated and called as such:\n * MyLinkedList obj = new MyLinkedList();\n * int param_1 = obj.Get(index);\n * obj.AddAtHead(val);\n * obj.AddAtTail(val);\n * obj.AddAtIndex(index,val);\n * obj.DeleteAtIndex(index);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Initialize your data structure here.\n */\nvar MyLinkedList = function() {\n\n};\n\n/**\n * Get the value of the index-th node in the linked list. If the index is invalid, return -1. \n * @param {number} index\n * @return {number}\n */\nMyLinkedList.prototype.get = function(index) {\n\n};\n\n/**\n * Add a node of value val before the first element of the linked list. After the insertion, the new node will be the first node of the linked list. \n * @param {number} val\n * @return {void}\n */\nMyLinkedList.prototype.addAtHead = function(val) {\n\n};\n\n/**\n * Append a node of value val to the last element of the linked list. \n * @param {number} val\n * @return {void}\n */\nMyLinkedList.prototype.addAtTail = function(val) {\n\n};\n\n/**\n * Add a node of value val before the index-th node in the linked list. If index equals to the length of linked list, the node will be appended to the end of linked list. If index is greater than the length, the node will not be inserted. \n * @param {number} index \n * @param {number} val\n * @return {void}\n */\nMyLinkedList.prototype.addAtIndex = function(index, val) {\n\n};\n\n/**\n * Delete the index-th node in the linked list, if the index is valid. \n * @param {number} index\n * @return {void}\n */\nMyLinkedList.prototype.deleteAtIndex = function(index) {\n\n};\n\n/**\n * Your MyLinkedList object will be instantiated and called as such:\n * var obj = new MyLinkedList()\n * var param_1 = obj.get(index)\n * obj.addAtHead(val)\n * obj.addAtTail(val)\n * obj.addAtIndex(index,val)\n * obj.deleteAtIndex(index)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class MyLinkedList\n\n=begin\n Initialize your data structure here.\n=end\n def initialize()\n\n end\n\n\n=begin\n Get the value of the index-th node in the linked list. If the index is invalid, return -1.\n :type index: Integer\n :rtype: Integer\n=end\n def get(index)\n\n end\n\n\n=begin\n Add a node of value val before the first element of the linked list. After the insertion, the new node will be the first node of the linked list.\n :type val: Integer\n :rtype: Void\n=end\n def add_at_head(val)\n\n end\n\n\n=begin\n Append a node of value val to the last element of the linked list.\n :type val: Integer\n :rtype: Void\n=end\n def add_at_tail(val)\n\n end\n\n\n=begin\n Add a node of value val before the index-th node in the linked list. If index equals to the length of linked list, the node will be appended to the end of linked list. If index is greater than the length, the node will not be inserted.\n :type index: Integer\n :type val: Integer\n :rtype: Void\n=end\n def add_at_index(index, val)\n\n end\n\n\n=begin\n Delete the index-th node in the linked list, if the index is valid.\n :type index: Integer\n :rtype: Void\n=end\n def delete_at_index(index)\n\n end\n\n\nend\n\n# Your MyLinkedList object will be instantiated and called as such:\n# obj = MyLinkedList.new()\n# param_1 = obj.get(index)\n# obj.add_at_head(val)\n# obj.add_at_tail(val)\n# obj.add_at_index(index, val)\n# obj.delete_at_index(index)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass MyLinkedList {\n\n /** Initialize your data structure here. */\n init() {\n\n }\n \n /** Get the value of the index-th node in the linked list. If the index is invalid, return -1. */\n func get(_ index: Int) -> Int {\n\n }\n \n /** Add a node of value val before the first element of the linked list. After the insertion, the new node will be the first node of the linked list. */\n func addAtHead(_ val: Int) {\n\n }\n \n /** Append a node of value val to the last element of the linked list. */\n func addAtTail(_ val: Int) {\n\n }\n \n /** Add a node of value val before the index-th node in the linked list. If index equals to the length of linked list, the node will be appended to the end of linked list. If index is greater than the length, the node will not be inserted. */\n func addAtIndex(_ index: Int, _ val: Int) {\n\n }\n \n /** Delete the index-th node in the linked list, if the index is valid. */\n func deleteAtIndex(_ index: Int) {\n\n }\n}\n\n/**\n * Your MyLinkedList object will be instantiated and called as such:\n * let obj = MyLinkedList()\n * let ret_1: Int = obj.get(index)\n * obj.addAtHead(val)\n * obj.addAtTail(val)\n * obj.addAtIndex(index, val)\n * obj.deleteAtIndex(index)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type MyLinkedList struct {\n\n}\n\n\n/** Initialize your data structure here. */\nfunc Constructor() MyLinkedList {\n\n}\n\n\n/** Get the value of the index-th node in the linked list. If the index is invalid, return -1. */\nfunc (this *MyLinkedList) Get(index int) int {\n\n}\n\n\n/** Add a node of value val before the first element of the linked list. After the insertion, the new node will be the first node of the linked list. */\nfunc (this *MyLinkedList) AddAtHead(val int) {\n\n}\n\n\n/** Append a node of value val to the last element of the linked list. */\nfunc (this *MyLinkedList) AddAtTail(val int) {\n\n}\n\n\n/** Add a node of value val before the index-th node in the linked list. If index equals to the length of linked list, the node will be appended to the end of linked list. If index is greater than the length, the node will not be inserted. */\nfunc (this *MyLinkedList) AddAtIndex(index int, val int) {\n\n}\n\n\n/** Delete the index-th node in the linked list, if the index is valid. */\nfunc (this *MyLinkedList) DeleteAtIndex(index int) {\n\n}\n\n\n/**\n * Your MyLinkedList object will be instantiated and called as such:\n * obj := Constructor();\n * param_1 := obj.Get(index);\n * obj.AddAtHead(val);\n * obj.AddAtTail(val);\n * obj.AddAtIndex(index,val);\n * obj.DeleteAtIndex(index);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class MyLinkedList() {\n\n /** Initialize your data structure here. */\n\n\n /** Get the value of the index-th node in the linked list. If the index is invalid, return -1. */\n def get(index: Int): Int = {\n\n }\n\n /** Add a node of value val before the first element of the linked list. After the insertion, the new node will be the first node of the linked list. */\n def addAtHead(`val`: Int) {\n\n }\n\n /** Append a node of value val to the last element of the linked list. */\n def addAtTail(`val`: Int) {\n\n }\n\n /** Add a node of value val before the index-th node in the linked list. If index equals to the length of linked list, the node will be appended to the end of linked list. If index is greater than the length, the node will not be inserted. */\n def addAtIndex(index: Int, `val`: Int) {\n\n }\n\n /** Delete the index-th node in the linked list, if the index is valid. */\n def deleteAtIndex(index: Int) {\n\n }\n\n}\n\n/**\n * Your MyLinkedList object will be instantiated and called as such:\n * var obj = new MyLinkedList()\n * var param_1 = obj.get(index)\n * obj.addAtHead(`val`)\n * obj.addAtTail(`val`)\n * obj.addAtIndex(index,`val`)\n * obj.deleteAtIndex(index)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class MyLinkedList() {\n\n /** Initialize your data structure here. */\n\n\n /** Get the value of the index-th node in the linked list. If the index is invalid, return -1. */\n fun get(index: Int): Int {\n\n }\n\n /** Add a node of value val before the first element of the linked list. After the insertion, the new node will be the first node of the linked list. */\n fun addAtHead(`val`: Int) {\n\n }\n\n /** Append a node of value val to the last element of the linked list. */\n fun addAtTail(`val`: Int) {\n\n }\n\n /** Add a node of value val before the index-th node in the linked list. If index equals to the length of linked list, the node will be appended to the end of linked list. If index is greater than the length, the node will not be inserted. */\n fun addAtIndex(index: Int, `val`: Int) {\n\n }\n\n /** Delete the index-th node in the linked list, if the index is valid. */\n fun deleteAtIndex(index: Int) {\n\n }\n\n}\n\n/**\n * Your MyLinkedList object will be instantiated and called as such:\n * var obj = MyLinkedList()\n * var param_1 = obj.get(index)\n * obj.addAtHead(`val`)\n * obj.addAtTail(`val`)\n * obj.addAtIndex(index,`val`)\n * obj.deleteAtIndex(index)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct MyLinkedList {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl MyLinkedList {\n\n /** Initialize your data structure here. */\n fn new() -> Self {\n\n }\n \n /** Get the value of the index-th node in the linked list. If the index is invalid, return -1. */\n fn get(&self, index: i32) -> i32 {\n\n }\n \n /** Add a node of value val before the first element of the linked list. After the insertion, the new node will be the first node of the linked list. */\n fn add_at_head(&self, val: i32) {\n\n }\n \n /** Append a node of value val to the last element of the linked list. */\n fn add_at_tail(&self, val: i32) {\n\n }\n \n /** Add a node of value val before the index-th node in the linked list. If index equals to the length of linked list, the node will be appended to the end of linked list. If index is greater than the length, the node will not be inserted. */\n fn add_at_index(&self, index: i32, val: i32) {\n\n }\n \n /** Delete the index-th node in the linked list, if the index is valid. */\n fn delete_at_index(&self, index: i32) {\n\n }\n}\n\n/**\n * Your MyLinkedList object will be instantiated and called as such:\n * let obj = MyLinkedList::new();\n * let ret_1: i32 = obj.get(index);\n * obj.add_at_head(val);\n * obj.add_at_tail(val);\n * obj.add_at_index(index, val);\n * obj.delete_at_index(index);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class MyLinkedList {\n /**\n * Initialize your data structure here.\n */\n function __construct() {\n\n }\n\n /**\n * Get the value of the index-th node in the linked list. If the index is invalid, return -1.\n * @param Integer $index\n * @return Integer\n */\n function get($index) {\n\n }\n\n /**\n * Add a node of value val before the first element of the linked list. After the insertion, the new node will be the first node of the linked list.\n * @param Integer $val\n * @return NULL\n */\n function addAtHead($val) {\n\n }\n\n /**\n * Append a node of value val to the last element of the linked list.\n * @param Integer $val\n * @return NULL\n */\n function addAtTail($val) {\n\n }\n\n /**\n * Add a node of value val before the index-th node in the linked list. If index equals to the length of linked list, the node will be appended to the end of linked list. If index is greater than the length, the node will not be inserted.\n * @param Integer $index\n * @param Integer $val\n * @return NULL\n */\n function addAtIndex($index, $val) {\n\n }\n\n /**\n * Delete the index-th node in the linked list, if the index is valid.\n * @param Integer $index\n * @return NULL\n */\n function deleteAtIndex($index) {\n\n }\n}\n\n/**\n * Your MyLinkedList object will be instantiated and called as such:\n * $obj = MyLinkedList();\n * $ret_1 = $obj->get($index);\n * $obj->addAtHead($val);\n * $obj->addAtTail($val);\n * $obj->addAtIndex($index, $val);\n * $obj->deleteAtIndex($index);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class MyLinkedList {\n constructor() {\n\n }\n\n get(index: number): number {\n\n }\n\n addAtHead(val: number): void {\n\n }\n\n addAtTail(val: number): void {\n\n }\n\n addAtIndex(index: number, val: number): void {\n\n }\n\n deleteAtIndex(index: number): void {\n\n }\n}\n\n/**\n * Your MyLinkedList object will be instantiated and called as such:\n * var obj = new MyLinkedList()\n * var param_1 = obj.get(index)\n * obj.addAtHead(val)\n * obj.addAtTail(val)\n * obj.addAtIndex(index,val)\n * obj.deleteAtIndex(index)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define my-linked-list%\n (class object%\n (super-new)\n (init-field)\n \n ; get : exact-integer? -> exact-integer?\n (define/public (get index)\n\n )\n ; add-at-head : exact-integer? -> void?\n (define/public (add-at-head val)\n\n )\n ; add-at-tail : exact-integer? -> void?\n (define/public (add-at-tail val)\n\n )\n ; add-at-index : exact-integer? exact-integer? -> void?\n (define/public (add-at-index index val)\n\n )\n ; delete-at-index : exact-integer? -> void?\n (define/public (delete-at-index index)\n\n )))\n\n;; Your my-linked-list% object will be instantiated and called as such:\n;; (define obj (new my-linked-list%))\n;; (define param_1 (send obj get index))\n;; (send obj add-at-head val)\n;; (send obj add-at-tail val)\n;; (send obj add-at-index index val)\n;; (send obj delete-at-index index)", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0707](https://leetcode-cn.com/problems/design-linked-list)", "[\u8bbe\u8ba1\u94fe\u8868](/solution/0700-0799/0707.Design%20Linked%20List/README.md)", "`\u8bbe\u8ba1`,`\u94fe\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0707](https://leetcode.com/problems/design-linked-list)", "[Design Linked List](/solution/0700-0799/0707.Design%20Linked%20List/README_EN.md)", "`Design`,`Linked List`", "Medium", ""]}, {"question_id": "0837", "frontend_question_id": "0819", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/most-common-word", "url_en": "https://leetcode.com/problems/most-common-word", "relative_path_cn": "/solution/0800-0899/0819.Most%20Common%20Word/README.md", "relative_path_en": "/solution/0800-0899/0819.Most%20Common%20Word/README_EN.md", "title_cn": "\u6700\u5e38\u89c1\u7684\u5355\u8bcd", "title_en": "Most Common Word", "question_title_slug": "most-common-word", "content_en": "

    Given a string paragraph and a string array of the banned words banned, return the most frequent word that is not banned. It is guaranteed there is at least one word that is not banned, and that the answer is unique.

    \n\n

    The words in paragraph are case-insensitive and the answer should be returned in lowercase.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: paragraph = "Bob hit a ball, the hit BALL flew far after it was hit.", banned = ["hit"]\nOutput: "ball"\nExplanation: \n"hit" occurs 3 times, but it is a banned word.\n"ball" occurs twice (and no other word does), so it is the most frequent non-banned word in the paragraph. \nNote that words in the paragraph are not case sensitive,\nthat punctuation is ignored (even if adjacent to words, such as "ball,"), \nand that "hit" isn't the answer even though it occurs more because it is banned.\n
    \n\n

    Example 2:

    \n\n
    \nInput: paragraph = "a.", banned = []\nOutput: "a"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= paragraph.length <= 1000
    • \n\t
    • paragraph consists of English letters, space ' ', or one of the symbols: "!?',;.".
    • \n\t
    • 0 <= banned.length <= 100
    • \n\t
    • 1 <= banned[i].length <= 10
    • \n\t
    • banned[i] consists of only lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6bb5\u843d (paragraph) \u548c\u4e00\u4e2a\u7981\u7528\u5355\u8bcd\u5217\u8868 (banned)\u3002\u8fd4\u56de\u51fa\u73b0\u6b21\u6570\u6700\u591a\uff0c\u540c\u65f6\u4e0d\u5728\u7981\u7528\u5217\u8868\u4e2d\u7684\u5355\u8bcd\u3002

    \n\n

    \u9898\u76ee\u4fdd\u8bc1\u81f3\u5c11\u6709\u4e00\u4e2a\u8bcd\u4e0d\u5728\u7981\u7528\u5217\u8868\u4e2d\uff0c\u800c\u4e14\u7b54\u6848\u552f\u4e00\u3002

    \n\n

    \u7981\u7528\u5217\u8868\u4e2d\u7684\u5355\u8bcd\u7528\u5c0f\u5199\u5b57\u6bcd\u8868\u793a\uff0c\u4e0d\u542b\u6807\u70b9\u7b26\u53f7\u3002\u6bb5\u843d\u4e2d\u7684\u5355\u8bcd\u4e0d\u533a\u5206\u5927\u5c0f\u5199\u3002\u7b54\u6848\u90fd\u662f\u5c0f\u5199\u5b57\u6bcd\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165: \nparagraph = "Bob hit a ball, the hit BALL flew far after it was hit."\nbanned = ["hit"]\n\u8f93\u51fa: "ball"\n\u89e3\u91ca: \n"hit" \u51fa\u73b0\u4e863\u6b21\uff0c\u4f46\u5b83\u662f\u4e00\u4e2a\u7981\u7528\u7684\u5355\u8bcd\u3002\n"ball" \u51fa\u73b0\u4e862\u6b21 (\u540c\u65f6\u6ca1\u6709\u5176\u4ed6\u5355\u8bcd\u51fa\u73b02\u6b21)\uff0c\u6240\u4ee5\u5b83\u662f\u6bb5\u843d\u91cc\u51fa\u73b0\u6b21\u6570\u6700\u591a\u7684\uff0c\u4e14\u4e0d\u5728\u7981\u7528\u5217\u8868\u4e2d\u7684\u5355\u8bcd\u3002 \n\u6ce8\u610f\uff0c\u6240\u6709\u8fd9\u4e9b\u5355\u8bcd\u5728\u6bb5\u843d\u91cc\u4e0d\u533a\u5206\u5927\u5c0f\u5199\uff0c\u6807\u70b9\u7b26\u53f7\u9700\u8981\u5ffd\u7565\uff08\u5373\u4f7f\u662f\u7d27\u6328\u7740\u5355\u8bcd\u4e5f\u5ffd\u7565\uff0c \u6bd4\u5982 "ball,"\uff09\uff0c \n"hit"\u4e0d\u662f\u6700\u7ec8\u7684\u7b54\u6848\uff0c\u867d\u7136\u5b83\u51fa\u73b0\u6b21\u6570\u66f4\u591a\uff0c\u4f46\u5b83\u5728\u7981\u7528\u5355\u8bcd\u5217\u8868\u4e2d\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= \u6bb5\u843d\u957f\u5ea6 <= 1000
    • \n\t
    • 0 <= \u7981\u7528\u5355\u8bcd\u4e2a\u6570 <= 100
    • \n\t
    • 1 <= \u7981\u7528\u5355\u8bcd\u957f\u5ea6 <= 10
    • \n\t
    • \u7b54\u6848\u662f\u552f\u4e00\u7684, \u4e14\u90fd\u662f\u5c0f\u5199\u5b57\u6bcd (\u5373\u4f7f\u5728 paragraph \u91cc\u662f\u5927\u5199\u7684\uff0c\u5373\u4f7f\u662f\u4e00\u4e9b\u7279\u5b9a\u7684\u540d\u8bcd\uff0c\u7b54\u6848\u90fd\u662f\u5c0f\u5199\u7684\u3002)
    • \n\t
    • paragraph \u53ea\u5305\u542b\u5b57\u6bcd\u3001\u7a7a\u683c\u548c\u4e0b\u5217\u6807\u70b9\u7b26\u53f7!?',;.
    • \n\t
    • \u4e0d\u5b58\u5728\u6ca1\u6709\u8fde\u5b57\u7b26\u6216\u8005\u5e26\u6709\u8fde\u5b57\u7b26\u7684\u5355\u8bcd\u3002
    • \n\t
    • \u5355\u8bcd\u91cc\u53ea\u5305\u542b\u5b57\u6bcd\uff0c\u4e0d\u4f1a\u51fa\u73b0\u7701\u7565\u53f7\u6216\u8005\u5176\u4ed6\u6807\u70b9\u7b26\u53f7\u3002
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string mostCommonWord(string paragraph, vector& banned) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String mostCommonWord(String paragraph, String[] banned) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def mostCommonWord(self, paragraph, banned):\n \"\"\"\n :type paragraph: str\n :type banned: List[str]\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def mostCommonWord(self, paragraph: str, banned: List[str]) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * mostCommonWord(char * paragraph, char ** banned, int bannedSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string MostCommonWord(string paragraph, string[] banned) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} paragraph\n * @param {string[]} banned\n * @return {string}\n */\nvar mostCommonWord = function(paragraph, banned) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} paragraph\n# @param {String[]} banned\n# @return {String}\ndef most_common_word(paragraph, banned)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func mostCommonWord(_ paragraph: String, _ banned: [String]) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func mostCommonWord(paragraph string, banned []string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def mostCommonWord(paragraph: String, banned: Array[String]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun mostCommonWord(paragraph: String, banned: Array): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn most_common_word(paragraph: String, banned: Vec) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $paragraph\n * @param String[] $banned\n * @return String\n */\n function mostCommonWord($paragraph, $banned) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function mostCommonWord(paragraph: string, banned: string[]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (most-common-word paragraph banned)\n (-> string? (listof string?) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0819](https://leetcode-cn.com/problems/most-common-word)", "[\u6700\u5e38\u89c1\u7684\u5355\u8bcd](/solution/0800-0899/0819.Most%20Common%20Word/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0819](https://leetcode.com/problems/most-common-word)", "[Most Common Word](/solution/0800-0899/0819.Most%20Common%20Word/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "0836", "frontend_question_id": "0818", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/race-car", "url_en": "https://leetcode.com/problems/race-car", "relative_path_cn": "/solution/0800-0899/0818.Race%20Car/README.md", "relative_path_en": "/solution/0800-0899/0818.Race%20Car/README_EN.md", "title_cn": "\u8d5b\u8f66", "title_en": "Race Car", "question_title_slug": "race-car", "content_en": "

    Your car starts at position 0 and speed +1 on an infinite number line. Your car can go into negative positions. Your car drives automatically according to a sequence of instructions 'A' (accelerate) and 'R' (reverse):

    \n\n
      \n\t
    • When you get an instruction 'A', your car does the following:\n\n\t
        \n\t\t
      • position += speed
      • \n\t\t
      • speed *= 2
      • \n\t
      \n\t
    • \n\t
    • When you get an instruction 'R', your car does the following:\n\t
        \n\t\t
      • If your speed is positive then speed = -1
      • \n\t\t
      • otherwise speed = 1
      • \n\t
      \n\tYour position stays the same.
    • \n
    \n\n

    For example, after commands "AAR", your car goes to positions 0 --> 1 --> 3 --> 3, and your speed goes to 1 --> 2 --> 4 --> -1.

    \n\n

    Given a target position target, return the length of the shortest sequence of instructions to get there.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: target = 3\nOutput: 2\nExplanation: \nThe shortest instruction sequence is "AA".\nYour position goes from 0 --> 1 --> 3.\n
    \n\n

    Example 2:

    \n\n
    \nInput: target = 6\nOutput: 5\nExplanation: \nThe shortest instruction sequence is "AAARA".\nYour position goes from 0 --> 1 --> 3 --> 7 --> 7 --> 6.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= target <= 104
    • \n
    \n", "content_cn": "

    \u4f60\u7684\u8d5b\u8f66\u8d77\u59cb\u505c\u7559\u5728\u4f4d\u7f6e 0\uff0c\u901f\u5ea6\u4e3a +1\uff0c\u6b63\u884c\u9a76\u5728\u4e00\u4e2a\u65e0\u9650\u957f\u7684\u6570\u8f74\u4e0a\u3002\uff08\u8f66\u4e5f\u53ef\u4ee5\u5411\u8d1f\u6570\u65b9\u5411\u884c\u9a76\u3002\uff09

    \n\n

    \u4f60\u7684\u8f66\u4f1a\u6839\u636e\u4e00\u7cfb\u5217\u7531 A\uff08\u52a0\u901f\uff09\u548c R\uff08\u5012\u8f66\uff09\u7ec4\u6210\u7684\u6307\u4ee4\u8fdb\u884c\u81ea\u52a8\u9a7e\u9a76 \u3002

    \n\n

    \u5f53\u8f66\u5f97\u5230\u6307\u4ee4 "A" \u65f6, \u5c06\u4f1a\u505a\u51fa\u4ee5\u4e0b\u64cd\u4f5c\uff1a position += speed, speed *= 2\u3002

    \n\n

    \u5f53\u8f66\u5f97\u5230\u6307\u4ee4 "R" \u65f6, \u5c06\u4f1a\u505a\u51fa\u4ee5\u4e0b\u64cd\u4f5c\uff1a\u5982\u679c\u5f53\u524d\u901f\u5ea6\u662f\u6b63\u6570\uff0c\u5219\u5c06\u8f66\u901f\u8c03\u6574\u4e3a speed = -1 \uff1b\u5426\u5219\u5c06\u8f66\u901f\u8c03\u6574\u4e3a speed = 1\u3002  (\u5f53\u524d\u6240\u5904\u4f4d\u7f6e\u4e0d\u53d8\u3002)

    \n\n

    \u4f8b\u5982\uff0c\u5f53\u5f97\u5230\u4e00\u7cfb\u5217\u6307\u4ee4 "AAR" \u540e, \u4f60\u7684\u8f66\u5c06\u4f1a\u8d70\u8fc7\u4f4d\u7f6e 0->1->3->3\uff0c\u5e76\u4e14\u901f\u5ea6\u53d8\u5316\u4e3a 1->2->4->-1\u3002

    \n\n

    \u73b0\u5728\u7ed9\u5b9a\u4e00\u4e2a\u76ee\u6807\u4f4d\u7f6e\uff0c\u8bf7\u7ed9\u51fa\u80fd\u591f\u5230\u8fbe\u76ee\u6807\u4f4d\u7f6e\u7684\u6700\u77ed\u6307\u4ee4\u5217\u8868\u7684\u957f\u5ea6\u3002

    \n\n
    \u793a\u4f8b 1:\n\u8f93\u5165: \ntarget = 3\n\u8f93\u51fa: 2\n\u89e3\u91ca: \n\u6700\u77ed\u6307\u4ee4\u5217\u8868\u4e3a "AA"\n\u4f4d\u7f6e\u53d8\u5316\u4e3a 0->1->3\n
    \n\n
    \u793a\u4f8b 2:\n\u8f93\u5165: \ntarget = 6\n\u8f93\u51fa: 5\n\u89e3\u91ca: \n\u6700\u77ed\u6307\u4ee4\u5217\u8868\u4e3a "AAARA"\n\u4f4d\u7f6e\u53d8\u5316\u4e3a 0->1->3->7->7->6\n
    \n\n

    \u8bf4\u660e:

    \n\n
      \n\t
    • 1 <= target\uff08\u76ee\u6807\u4f4d\u7f6e\uff09 <= 10000\u3002
    • \n
    \n", "tags_en": ["Heap", "Dynamic Programming"], "tags_cn": ["\u5806", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int racecar(int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int racecar(int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def racecar(self, target):\n \"\"\"\n :type target: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def racecar(self, target: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint racecar(int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int Racecar(int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} target\n * @return {number}\n */\nvar racecar = function(target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} target\n# @return {Integer}\ndef racecar(target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func racecar(_ target: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func racecar(target int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def racecar(target: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun racecar(target: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn racecar(target: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $target\n * @return Integer\n */\n function racecar($target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function racecar(target: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (racecar target)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0818](https://leetcode-cn.com/problems/race-car)", "[\u8d5b\u8f66](/solution/0800-0899/0818.Race%20Car/README.md)", "`\u5806`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0818](https://leetcode.com/problems/race-car)", "[Race Car](/solution/0800-0899/0818.Race%20Car/README_EN.md)", "`Heap`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0835", "frontend_question_id": "0817", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/linked-list-components", "url_en": "https://leetcode.com/problems/linked-list-components", "relative_path_cn": "/solution/0800-0899/0817.Linked%20List%20Components/README.md", "relative_path_en": "/solution/0800-0899/0817.Linked%20List%20Components/README_EN.md", "title_cn": "\u94fe\u8868\u7ec4\u4ef6", "title_en": "Linked List Components", "question_title_slug": "linked-list-components", "content_en": "

    We are given head, the head node of a linked list containing unique integer values.

    \n\n

    We are also given the list nums, a subset of the values in the linked list.

    \n\n

    Return the number of connected components in nums, where two values are connected if they appear consecutively in the linked list.

    \n\n

    Example 1:

    \n\n
    \nInput: \nhead: 0->1->2->3\nnums = [0, 1, 3]\nOutput: 2\nExplanation: \n0 and 1 are connected, so [0, 1] and [3] are the two connected components.\n
    \n\n

    Example 2:

    \n\n
    \nInput: \nhead: 0->1->2->3->4\nnums = [0, 3, 1, 4]\nOutput: 2\nExplanation: \n0 and 1 are connected, 3 and 4 are connected, so [0, 1] and [3, 4] are the two connected components.\n
    \n\n

    Note:

    \n\n
      \n\t
    • If n is the length of the linked list given by head1 <= n <= 10000.
    • \n\t
    • The value of each node in the linked list will be in the range [0, n - 1].
    • \n\t
    • 1 <= nums.length <= 10000.
    • \n\t
    • nums is a subset of all values in the linked list.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u94fe\u8868\u5934\u7ed3\u70b9 head\uff0c\u8be5\u94fe\u8868\u4e0a\u7684\u6bcf\u4e2a\u7ed3\u70b9\u90fd\u6709\u4e00\u4e2a \u552f\u4e00\u7684\u6574\u578b\u503c \u3002

    \n\n

    \u540c\u65f6\u7ed9\u5b9a\u5217\u8868 G\uff0c\u8be5\u5217\u8868\u662f\u4e0a\u8ff0\u94fe\u8868\u4e2d\u6574\u578b\u503c\u7684\u4e00\u4e2a\u5b50\u96c6\u3002

    \n\n

    \u8fd4\u56de\u5217\u8868 G \u4e2d\u7ec4\u4ef6\u7684\u4e2a\u6570\uff0c\u8fd9\u91cc\u5bf9\u7ec4\u4ef6\u7684\u5b9a\u4e49\u4e3a\uff1a\u94fe\u8868\u4e2d\u4e00\u6bb5\u6700\u957f\u8fde\u7eed\u7ed3\u70b9\u7684\u503c\uff08\u8be5\u503c\u5fc5\u987b\u5728\u5217\u8868 G \u4e2d\uff09\u6784\u6210\u7684\u96c6\u5408\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165: \nhead: 0->1->2->3\nG = [0, 1, 3]\n\u8f93\u51fa: 2\n\u89e3\u91ca: \n\u94fe\u8868\u4e2d,0 \u548c 1 \u662f\u76f8\u8fde\u63a5\u7684\uff0c\u4e14 G \u4e2d\u4e0d\u5305\u542b 2\uff0c\u6240\u4ee5 [0, 1] \u662f G \u7684\u4e00\u4e2a\u7ec4\u4ef6\uff0c\u540c\u7406 [3] \u4e5f\u662f\u4e00\u4e2a\u7ec4\u4ef6\uff0c\u6545\u8fd4\u56de 2\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165: \nhead: 0->1->2->3->4\nG = [0, 3, 1, 4]\n\u8f93\u51fa: 2\n\u89e3\u91ca: \n\u94fe\u8868\u4e2d\uff0c0 \u548c 1 \u662f\u76f8\u8fde\u63a5\u7684\uff0c3 \u548c 4 \u662f\u76f8\u8fde\u63a5\u7684\uff0c\u6240\u4ee5 [0, 1] \u548c [3, 4] \u662f\u4e24\u4e2a\u7ec4\u4ef6\uff0c\u6545\u8fd4\u56de 2\u3002
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u5982\u679c N \u662f\u7ed9\u5b9a\u94fe\u8868 head \u7684\u957f\u5ea6\uff0c1 <= N <= 10000\u3002
    • \n\t
    • \u94fe\u8868\u4e2d\u6bcf\u4e2a\u7ed3\u70b9\u7684\u503c\u6240\u5728\u8303\u56f4\u4e3a [0, N - 1]\u3002
    • \n\t
    • 1 <= G.length <= 10000
    • \n\t
    • G \u662f\u94fe\u8868\u4e2d\u6240\u6709\u7ed3\u70b9\u7684\u503c\u7684\u4e00\u4e2a\u5b50\u96c6.
    • \n
    \n", "tags_en": ["Linked List"], "tags_cn": ["\u94fe\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n int numComponents(ListNode* head, vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public int numComponents(ListNode head, int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def numComponents(self, head, nums):\n \"\"\"\n :type head: ListNode\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def numComponents(self, head: ListNode, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nint numComponents(struct ListNode* head, int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public int NumComponents(ListNode head, int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} head\n * @param {number[]} nums\n * @return {number}\n */\nvar numComponents = function(head, nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode} head\n# @param {Integer[]} nums\n# @return {Integer}\ndef num_components(head, nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func numComponents(_ head: ListNode?, _ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc numComponents(head *ListNode, nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def numComponents(head: ListNode, nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun numComponents(head: ListNode?, nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn num_components(head: Option>, nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @param Integer[] $nums\n * @return Integer\n */\n function numComponents($head, $nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction numComponents(head: ListNode | null, nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (num-components head nums)\n (-> (or/c list-node? #f) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0817](https://leetcode-cn.com/problems/linked-list-components)", "[\u94fe\u8868\u7ec4\u4ef6](/solution/0800-0899/0817.Linked%20List%20Components/README.md)", "`\u94fe\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0817](https://leetcode.com/problems/linked-list-components)", "[Linked List Components](/solution/0800-0899/0817.Linked%20List%20Components/README_EN.md)", "`Linked List`", "Medium", ""]}, {"question_id": "0834", "frontend_question_id": "0816", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/ambiguous-coordinates", "url_en": "https://leetcode.com/problems/ambiguous-coordinates", "relative_path_cn": "/solution/0800-0899/0816.Ambiguous%20Coordinates/README.md", "relative_path_en": "/solution/0800-0899/0816.Ambiguous%20Coordinates/README_EN.md", "title_cn": "\u6a21\u7cca\u5750\u6807", "title_en": "Ambiguous Coordinates", "question_title_slug": "ambiguous-coordinates", "content_en": "

    We had some 2-dimensional coordinates, like "(1, 3)" or "(2, 0.5)". Then, we removed all commas, decimal points, and spaces and ended up with the string s.

    \n\n
      \n\t
    • For example, "(1, 3)" becomes s = "(13)" and "(2, 0.5)" becomes s = "(205)".
    • \n
    \n\n

    Return a list of strings representing all possibilities for what our original coordinates could have been.

    \n\n

    Our original representation never had extraneous zeroes, so we never started with numbers like "00", "0.0", "0.00", "1.0", "001", "00.01", or any other number that can be represented with fewer digits. Also, a decimal point within a number never occurs without at least one digit occurring before it, so we never started with numbers like ".1".

    \n\n

    The final answer list can be returned in any order. All coordinates in the final answer have exactly one space between them (occurring after the comma.)

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "(123)"\nOutput: ["(1, 2.3)","(1, 23)","(1.2, 3)","(12, 3)"]\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "(0123)"\nOutput: ["(0, 1.23)","(0, 12.3)","(0, 123)","(0.1, 2.3)","(0.1, 23)","(0.12, 3)"]\nExplanation: 0.0, 00, 0001 or 00.01 are not allowed.\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "(00011)"\nOutput: ["(0, 0.011)","(0.001, 1)"]\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "(100)"\nOutput: ["(10, 0)"]\nExplanation: 1.0 is not allowed.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 4 <= s.length <= 12
    • \n\t
    • s[0] == '(' and s[s.length - 1] == ')'.
    • \n\t
    • The rest of s are digits.
    • \n
    \n", "content_cn": "

    \u6211\u4eec\u6709\u4e00\u4e9b\u4e8c\u7ef4\u5750\u6807\uff0c\u5982 "(1, 3)" \u6216 "(2, 0.5)"\uff0c\u7136\u540e\u6211\u4eec\u79fb\u9664\u6240\u6709\u9017\u53f7\uff0c\u5c0f\u6570\u70b9\u548c\u7a7a\u683c\uff0c\u5f97\u5230\u4e00\u4e2a\u5b57\u7b26\u4e32S\u3002\u8fd4\u56de\u6240\u6709\u53ef\u80fd\u7684\u539f\u59cb\u5b57\u7b26\u4e32\u5230\u4e00\u4e2a\u5217\u8868\u4e2d\u3002

    \n\n

    \u539f\u59cb\u7684\u5750\u6807\u8868\u793a\u6cd5\u4e0d\u4f1a\u5b58\u5728\u591a\u4f59\u7684\u96f6\uff0c\u6240\u4ee5\u4e0d\u4f1a\u51fa\u73b0\u7c7b\u4f3c\u4e8e"00", "0.0", "0.00", "1.0", "001", "00.01"\u6216\u4e00\u4e9b\u5176\u4ed6\u66f4\u5c0f\u7684\u6570\u6765\u8868\u793a\u5750\u6807\u3002\u6b64\u5916\uff0c\u4e00\u4e2a\u5c0f\u6570\u70b9\u524d\u81f3\u5c11\u5b58\u5728\u4e00\u4e2a\u6570\uff0c\u6240\u4ee5\u4e5f\u4e0d\u4f1a\u51fa\u73b0“.1”\u5f62\u5f0f\u7684\u6570\u5b57\u3002

    \n\n

    \u6700\u540e\u8fd4\u56de\u7684\u5217\u8868\u53ef\u4ee5\u662f\u4efb\u610f\u987a\u5e8f\u7684\u3002\u800c\u4e14\u6ce8\u610f\u8fd4\u56de\u7684\u4e24\u4e2a\u6570\u5b57\u4e2d\u95f4\uff08\u9017\u53f7\u4e4b\u540e\uff09\u90fd\u6709\u4e00\u4e2a\u7a7a\u683c\u3002

    \n\n

     

    \n\n
    \n\u793a\u4f8b 1:\n\u8f93\u5165: "(123)"\n\u8f93\u51fa: ["(1, 23)", "(12, 3)", "(1.2, 3)", "(1, 2.3)"]\n
    \n\n
    \n\u793a\u4f8b 2:\n\u8f93\u5165: "(00011)"\n\u8f93\u51fa:  ["(0.001, 1)", "(0, 0.011)"]\n\u89e3\u91ca: \n0.0, 00, 0001 \u6216 00.01 \u662f\u4e0d\u88ab\u5141\u8bb8\u7684\u3002\n
    \n\n
    \n\u793a\u4f8b 3:\n\u8f93\u5165: "(0123)"\n\u8f93\u51fa: ["(0, 123)", "(0, 12.3)", "(0, 1.23)", "(0.1, 23)", "(0.1, 2.3)", "(0.12, 3)"]\n
    \n\n
    \n\u793a\u4f8b 4:\n\u8f93\u5165: "(100)"\n\u8f93\u51fa: [(10, 0)]\n\u89e3\u91ca: \n1.0 \u662f\u4e0d\u88ab\u5141\u8bb8\u7684\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a:

    \n\n
      \n\t
    • 4 <= S.length <= 12.
    • \n\t
    • S[0] = "(", S[S.length - 1] = ")", \u4e14\u5b57\u7b26\u4e32 S \u4e2d\u7684\u5176\u4ed6\u5143\u7d20\u90fd\u662f\u6570\u5b57\u3002
    • \n
    \n\n

     

    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector ambiguousCoordinates(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List ambiguousCoordinates(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def ambiguousCoordinates(self, s):\n \"\"\"\n :type s: str\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def ambiguousCoordinates(self, s: str) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** ambiguousCoordinates(char * s, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList AmbiguousCoordinates(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string[]}\n */\nvar ambiguousCoordinates = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String[]}\ndef ambiguous_coordinates(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func ambiguousCoordinates(_ s: String) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func ambiguousCoordinates(s string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def ambiguousCoordinates(s: String): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun ambiguousCoordinates(s: String): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn ambiguous_coordinates(s: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String[]\n */\n function ambiguousCoordinates($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function ambiguousCoordinates(s: string): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (ambiguous-coordinates s)\n (-> string? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0816](https://leetcode-cn.com/problems/ambiguous-coordinates)", "[\u6a21\u7cca\u5750\u6807](/solution/0800-0899/0816.Ambiguous%20Coordinates/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0816](https://leetcode.com/problems/ambiguous-coordinates)", "[Ambiguous Coordinates](/solution/0800-0899/0816.Ambiguous%20Coordinates/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "0833", "frontend_question_id": "0815", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/bus-routes", "url_en": "https://leetcode.com/problems/bus-routes", "relative_path_cn": "/solution/0800-0899/0815.Bus%20Routes/README.md", "relative_path_en": "/solution/0800-0899/0815.Bus%20Routes/README_EN.md", "title_cn": "\u516c\u4ea4\u8def\u7ebf", "title_en": "Bus Routes", "question_title_slug": "bus-routes", "content_en": "

    You are given an array routes representing bus routes where routes[i] is a bus route that the ith bus repeats forever.

    \n\n
      \n\t
    • For example, if routes[0] = [1, 5, 7], this means that the 0th bus travels in the sequence 1 -> 5 -> 7 -> 1 -> 5 -> 7 -> 1 -> ... forever.
    • \n
    \n\n

    You will start at the bus stop source (You are not on any bus initially), and you want to go to the bus stop target. You can travel between bus stops by buses only.

    \n\n

    Return the least number of buses you must take to travel from source to target. Return -1 if it is not possible.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: routes = [[1,2,7],[3,6,7]], source = 1, target = 6\nOutput: 2\nExplanation: The best strategy is take the first bus to the bus stop 7, then take the second bus to the bus stop 6.\n
    \n\n

    Example 2:

    \n\n
    \nInput: routes = [[7,12],[4,5,15],[6],[15,19],[9,12,13]], source = 15, target = 12\nOutput: -1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= routes.length <= 500.
    • \n\t
    • 1 <= routes[i].length <= 105
    • \n\t
    • All the values of routes[i] are unique.
    • \n\t
    • sum(routes[i].length) <= 105
    • \n\t
    • 0 <= routes[i][j] < 106
    • \n\t
    • 0 <= source, target < 106
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 routes \uff0c\u8868\u793a\u4e00\u7cfb\u5217\u516c\u4ea4\u7ebf\u8def\uff0c\u5176\u4e2d\u6bcf\u4e2a routes[i] \u8868\u793a\u4e00\u6761\u516c\u4ea4\u7ebf\u8def\uff0c\u7b2c i \u8f86\u516c\u4ea4\u8f66\u5c06\u4f1a\u5728\u4e0a\u9762\u5faa\u73af\u884c\u9a76\u3002

    \n\n
      \n\t
    • \u4f8b\u5982\uff0c\u8def\u7ebf routes[0] = [1, 5, 7] \u8868\u793a\u7b2c 0 \u8f86\u516c\u4ea4\u8f66\u4f1a\u4e00\u76f4\u6309\u5e8f\u5217 1 -> 5 -> 7 -> 1 -> 5 -> 7 -> 1 -> ... \u8fd9\u6837\u7684\u8f66\u7ad9\u8def\u7ebf\u884c\u9a76\u3002
    • \n
    \n\n

    \u73b0\u5728\u4ece source \u8f66\u7ad9\u51fa\u53d1\uff08\u521d\u59cb\u65f6\u4e0d\u5728\u516c\u4ea4\u8f66\u4e0a\uff09\uff0c\u8981\u524d\u5f80 target \u8f66\u7ad9\u3002 \u671f\u95f4\u4ec5\u53ef\u4e58\u5750\u516c\u4ea4\u8f66\u3002

    \n\n

    \u6c42\u51fa \u6700\u5c11\u4e58\u5750\u7684\u516c\u4ea4\u8f66\u6570\u91cf \u3002\u5982\u679c\u4e0d\u53ef\u80fd\u5230\u8fbe\u7ec8\u70b9\u8f66\u7ad9\uff0c\u8fd4\u56de -1 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroutes = [[1,2,7],[3,6,7]], source = 1, target = 6\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6700\u4f18\u7b56\u7565\u662f\u5148\u4e58\u5750\u7b2c\u4e00\u8f86\u516c\u4ea4\u8f66\u5230\u8fbe\u8f66\u7ad9 7 , \u7136\u540e\u6362\u4e58\u7b2c\u4e8c\u8f86\u516c\u4ea4\u8f66\u5230\u8f66\u7ad9 6 \u3002 \n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroutes = [[7,12],[4,5,15],[6],[15,19],[9,12,13]], source = 15, target = 12\n\u8f93\u51fa\uff1a-1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= routes.length <= 500.
    • \n\t
    • 1 <= routes[i].length <= 105
    • \n\t
    • routes[i] \u4e2d\u7684\u6240\u6709\u503c \u4e92\u4e0d\u76f8\u540c
    • \n\t
    • sum(routes[i].length) <= 105
    • \n\t
    • 0 <= routes[i][j] < 106
    • \n\t
    • 0 <= source, target < 106
    • \n
    \n", "tags_en": ["Breadth-first Search"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numBusesToDestination(vector>& routes, int source, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numBusesToDestination(int[][] routes, int source, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numBusesToDestination(self, routes, source, target):\n \"\"\"\n :type routes: List[List[int]]\n :type source: int\n :type target: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numBusesToDestination(self, routes: List[List[int]], source: int, target: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numBusesToDestination(int** routes, int routesSize, int* routesColSize, int source, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumBusesToDestination(int[][] routes, int source, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} routes\n * @param {number} source\n * @param {number} target\n * @return {number}\n */\nvar numBusesToDestination = function(routes, source, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} routes\n# @param {Integer} source\n# @param {Integer} target\n# @return {Integer}\ndef num_buses_to_destination(routes, source, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numBusesToDestination(_ routes: [[Int]], _ source: Int, _ target: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numBusesToDestination(routes [][]int, source int, target int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numBusesToDestination(routes: Array[Array[Int]], source: Int, target: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numBusesToDestination(routes: Array, source: Int, target: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_buses_to_destination(routes: Vec>, source: i32, target: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $routes\n * @param Integer $source\n * @param Integer $target\n * @return Integer\n */\n function numBusesToDestination($routes, $source, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numBusesToDestination(routes: number[][], source: number, target: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-buses-to-destination routes source target)\n (-> (listof (listof exact-integer?)) exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0815](https://leetcode-cn.com/problems/bus-routes)", "[\u516c\u4ea4\u8def\u7ebf](/solution/0800-0899/0815.Bus%20Routes/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[0815](https://leetcode.com/problems/bus-routes)", "[Bus Routes](/solution/0800-0899/0815.Bus%20Routes/README_EN.md)", "`Breadth-first Search`", "Hard", ""]}, {"question_id": "0832", "frontend_question_id": "0814", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/binary-tree-pruning", "url_en": "https://leetcode.com/problems/binary-tree-pruning", "relative_path_cn": "/solution/0800-0899/0814.Binary%20Tree%20Pruning/README.md", "relative_path_en": "/solution/0800-0899/0814.Binary%20Tree%20Pruning/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u526a\u679d", "title_en": "Binary Tree Pruning", "question_title_slug": "binary-tree-pruning", "content_en": "

    Given the root of a binary tree, return the same tree where every subtree (of the given tree) not containing a 1 has been removed.

    \n\n

    A subtree of a node node is node plus every node that is a descendant of node.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,null,0,0,1]\nOutput: [1,null,0,null,1]\nExplanation: \nOnly the red nodes satisfy the property "every subtree not containing a 1".\nThe diagram on the right represents the answer.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [1,0,1,0,0,0,1]\nOutput: [1,null,1,null,1]\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: root = [1,1,0,1,1,0,1,0]\nOutput: [1,1,0,1,1,null,1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 200].
    • \n\t
    • Node.val is either 0 or 1.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e8c\u53c9\u6811\u6839\u7ed3\u70b9 root \uff0c\u6b64\u5916\u6811\u7684\u6bcf\u4e2a\u7ed3\u70b9\u7684\u503c\u8981\u4e48\u662f 0\uff0c\u8981\u4e48\u662f 1\u3002

    \n\n

    \u8fd4\u56de\u79fb\u9664\u4e86\u6240\u6709\u4e0d\u5305\u542b 1 \u7684\u5b50\u6811\u7684\u539f\u4e8c\u53c9\u6811\u3002

    \n\n

    ( \u8282\u70b9 X \u7684\u5b50\u6811\u4e3a X \u672c\u8eab\uff0c\u4ee5\u53ca\u6240\u6709 X \u7684\u540e\u4ee3\u3002)

    \n\n
    \n\u793a\u4f8b1:\n\u8f93\u5165: [1,null,0,0,1]\n\u8f93\u51fa: [1,null,0,null,1]\n \n\u89e3\u91ca: \n\u53ea\u6709\u7ea2\u8272\u8282\u70b9\u6ee1\u8db3\u6761\u4ef6“\u6240\u6709\u4e0d\u5305\u542b 1 \u7684\u5b50\u6811”\u3002\n\u53f3\u56fe\u4e3a\u8fd4\u56de\u7684\u7b54\u6848\u3002\n\n\"\"\n
    \n\n
    \n\u793a\u4f8b2:\n\u8f93\u5165: [1,0,1,0,0,0,1]\n\u8f93\u51fa: [1,null,1,null,1]\n\n\n\"\"\n
    \n\n
    \n\u793a\u4f8b3:\n\u8f93\u5165: [1,1,0,1,1,0,1,0]\n\u8f93\u51fa: [1,1,0,1,1,null,1]\n\n\n\"\"\n
    \n\n

    \u8bf4\u660e:

    \n\n
      \n\t
    • \u7ed9\u5b9a\u7684\u4e8c\u53c9\u6811\u6700\u591a\u6709 100 \u4e2a\u8282\u70b9\u3002
    • \n\t
    • \u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u53ea\u4f1a\u4e3a 0 \u6216 1 \u3002
    • \n
    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* pruneTree(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode pruneTree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def pruneTree(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: TreeNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def pruneTree(self, root: TreeNode) -> TreeNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* pruneTree(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode PruneTree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {TreeNode}\n */\nvar pruneTree = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {TreeNode}\ndef prune_tree(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func pruneTree(_ root: TreeNode?) -> TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc pruneTree(root *TreeNode) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def pruneTree(root: TreeNode): TreeNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun pruneTree(root: TreeNode?): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn prune_tree(root: Option>>) -> Option>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return TreeNode\n */\n function pruneTree($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction pruneTree(root: TreeNode | null): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (prune-tree root)\n (-> (or/c tree-node? #f) (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0814](https://leetcode-cn.com/problems/binary-tree-pruning)", "[\u4e8c\u53c9\u6811\u526a\u679d](/solution/0800-0899/0814.Binary%20Tree%20Pruning/README.md)", "`\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0814](https://leetcode.com/problems/binary-tree-pruning)", "[Binary Tree Pruning](/solution/0800-0899/0814.Binary%20Tree%20Pruning/README_EN.md)", "`Tree`", "Medium", ""]}, {"question_id": "0831", "frontend_question_id": "0813", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/largest-sum-of-averages", "url_en": "https://leetcode.com/problems/largest-sum-of-averages", "relative_path_cn": "/solution/0800-0899/0813.Largest%20Sum%20of%20Averages/README.md", "relative_path_en": "/solution/0800-0899/0813.Largest%20Sum%20of%20Averages/README_EN.md", "title_cn": "\u6700\u5927\u5e73\u5747\u503c\u548c\u7684\u5206\u7ec4", "title_en": "Largest Sum of Averages", "question_title_slug": "largest-sum-of-averages", "content_en": "

    We partition a row of numbers nums into at most k adjacent (non-empty) groups, then our score is the sum of the average of each group. What is the largest score we can achieve?

    \n\n

    Note that our partition must use every number in nums, and that scores are not necessarily integers.

    \n\n
    \nExample:\nInput: \nnums = [9,1,2,3,9]\nk = 3\nOutput: 20\nExplanation: \nThe best choice is to partition nums into [9], [1, 2, 3], [9]. The answer is 9 + (1 + 2 + 3) / 3 + 9 = 20.\nWe could have also partitioned nums into [9, 1], [2], [3, 9], for example.\nThat partition would lead to a score of 5 + 2 + 6 = 13, which is worse.\n
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    • 1 <= nums.length <= 100.
    • \n\t
    • 1 <= nums[i] <= 10000.
    • \n\t
    • 1 <= k <= nums.length.
    • \n\t
    • Answers within 10-6 of the correct answer will be accepted as correct.
    • \n
    \n", "content_cn": "

    \u6211\u4eec\u5c06\u7ed9\u5b9a\u7684\u6570\u7ec4 A \u5206\u6210 K \u4e2a\u76f8\u90bb\u7684\u975e\u7a7a\u5b50\u6570\u7ec4 \uff0c\u6211\u4eec\u7684\u5206\u6570\u7531\u6bcf\u4e2a\u5b50\u6570\u7ec4\u5185\u7684\u5e73\u5747\u503c\u7684\u603b\u548c\u6784\u6210\u3002\u8ba1\u7b97\u6211\u4eec\u6240\u80fd\u5f97\u5230\u7684\u6700\u5927\u5206\u6570\u662f\u591a\u5c11\u3002

    \n\n

    \u6ce8\u610f\u6211\u4eec\u5fc5\u987b\u4f7f\u7528 A \u6570\u7ec4\u4e2d\u7684\u6bcf\u4e00\u4e2a\u6570\u8fdb\u884c\u5206\u7ec4\uff0c\u5e76\u4e14\u5206\u6570\u4e0d\u4e00\u5b9a\u9700\u8981\u662f\u6574\u6570\u3002

    \n\n
    \n\u793a\u4f8b:\n\u8f93\u5165: \nA = [9,1,2,3,9]\nK = 3\n\u8f93\u51fa: 20\n\u89e3\u91ca: \nA \u7684\u6700\u4f18\u5206\u7ec4\u662f[9], [1, 2, 3], [9]. \u5f97\u5230\u7684\u5206\u6570\u662f 9 + (1 + 2 + 3) / 3 + 9 = 20.\n\u6211\u4eec\u4e5f\u53ef\u4ee5\u628a A \u5206\u6210[9, 1], [2], [3, 9].\n\u8fd9\u6837\u7684\u5206\u7ec4\u5f97\u5230\u7684\u5206\u6570\u4e3a 5 + 2 + 6 = 13, \u4f46\u4e0d\u662f\u6700\u5927\u503c.\n
    \n\n

    \u8bf4\u660e:

    \n\n
      \n\t
    • 1 <= A.length <= 100.
    • \n\t
    • 1 <= A[i] <= 10000.
    • \n\t
    • 1 <= K <= A.length.
    • \n\t
    • \u7b54\u6848\u8bef\u5dee\u5728 10^-6 \u5185\u88ab\u89c6\u4e3a\u662f\u6b63\u786e\u7684\u3002
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n double largestSumOfAverages(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double largestSumOfAverages(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def largestSumOfAverages(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: float\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def largestSumOfAverages(self, nums: List[int], k: int) -> float:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\ndouble largestSumOfAverages(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double LargestSumOfAverages(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar largestSumOfAverages = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Float}\ndef largest_sum_of_averages(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func largestSumOfAverages(_ nums: [Int], _ k: Int) -> Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func largestSumOfAverages(nums []int, k int) float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def largestSumOfAverages(nums: Array[Int], k: Int): Double = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun largestSumOfAverages(nums: IntArray, k: Int): Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn largest_sum_of_averages(nums: Vec, k: i32) -> f64 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Float\n */\n function largestSumOfAverages($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function largestSumOfAverages(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (largest-sum-of-averages nums k)\n (-> (listof exact-integer?) exact-integer? flonum?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0813](https://leetcode-cn.com/problems/largest-sum-of-averages)", "[\u6700\u5927\u5e73\u5747\u503c\u548c\u7684\u5206\u7ec4](/solution/0800-0899/0813.Largest%20Sum%20of%20Averages/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0813](https://leetcode.com/problems/largest-sum-of-averages)", "[Largest Sum of Averages](/solution/0800-0899/0813.Largest%20Sum%20of%20Averages/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0830", "frontend_question_id": "0812", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/largest-triangle-area", "url_en": "https://leetcode.com/problems/largest-triangle-area", "relative_path_cn": "/solution/0800-0899/0812.Largest%20Triangle%20Area/README.md", "relative_path_en": "/solution/0800-0899/0812.Largest%20Triangle%20Area/README_EN.md", "title_cn": "\u6700\u5927\u4e09\u89d2\u5f62\u9762\u79ef", "title_en": "Largest Triangle Area", "question_title_slug": "largest-triangle-area", "content_en": "

    You have a list of points in the plane. Return the area of the largest triangle that can be formed by any 3 of the points.

    \r\n\r\n
    \r\nExample:\r\nInput: points = [[0,0],[0,1],[1,0],[0,2],[2,0]]\r\nOutput: 2\r\nExplanation: \r\nThe five points are show in the figure below. The red triangle is the largest.\r\n
    \r\n\r\n

    \"\"

    \r\n\r\n

    Notes:

    \r\n\r\n
      \r\n\t
    • 3 <= points.length <= 50.
    • \r\n\t
    • No points will be duplicated.
    • \r\n\t
    •  -50 <= points[i][j] <= 50.
    • \r\n\t
    • Answers within 10^-6 of the true value will be accepted as correct.
    • \r\n
    \r\n\r\n

     

    \r\n", "content_cn": "

    \u7ed9\u5b9a\u5305\u542b\u591a\u4e2a\u70b9\u7684\u96c6\u5408\uff0c\u4ece\u5176\u4e2d\u53d6\u4e09\u4e2a\u70b9\u7ec4\u6210\u4e09\u89d2\u5f62\uff0c\u8fd4\u56de\u80fd\u7ec4\u6210\u7684\u6700\u5927\u4e09\u89d2\u5f62\u7684\u9762\u79ef\u3002

    \n\n
    \n\u793a\u4f8b:\n\u8f93\u5165: points = [[0,0],[0,1],[1,0],[0,2],[2,0]]\n\u8f93\u51fa: 2\n\u89e3\u91ca: \n\u8fd9\u4e94\u4e2a\u70b9\u5982\u4e0b\u56fe\u6240\u793a\u3002\u7ec4\u6210\u7684\u6a59\u8272\u4e09\u89d2\u5f62\u662f\u6700\u5927\u7684\uff0c\u9762\u79ef\u4e3a2\u3002\n
    \n\n

    \"\"

    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    • 3 <= points.length <= 50.
    • \n\t
    • \u4e0d\u5b58\u5728\u91cd\u590d\u7684\u70b9\u3002
    • \n\t
    •  -50 <= points[i][j] <= 50.
    • \n\t
    • \u7ed3\u679c\u8bef\u5dee\u503c\u5728 10^-6 \u4ee5\u5185\u90fd\u8ba4\u4e3a\u662f\u6b63\u786e\u7b54\u6848\u3002
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n double largestTriangleArea(vector>& points) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double largestTriangleArea(int[][] points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def largestTriangleArea(self, points):\n \"\"\"\n :type points: List[List[int]]\n :rtype: float\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def largestTriangleArea(self, points: List[List[int]]) -> float:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\ndouble largestTriangleArea(int** points, int pointsSize, int* pointsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double LargestTriangleArea(int[][] points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} points\n * @return {number}\n */\nvar largestTriangleArea = function(points) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} points\n# @return {Float}\ndef largest_triangle_area(points)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func largestTriangleArea(_ points: [[Int]]) -> Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func largestTriangleArea(points [][]int) float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def largestTriangleArea(points: Array[Array[Int]]): Double = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun largestTriangleArea(points: Array): Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn largest_triangle_area(points: Vec>) -> f64 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $points\n * @return Float\n */\n function largestTriangleArea($points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function largestTriangleArea(points: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (largest-triangle-area points)\n (-> (listof (listof exact-integer?)) flonum?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0812](https://leetcode-cn.com/problems/largest-triangle-area)", "[\u6700\u5927\u4e09\u89d2\u5f62\u9762\u79ef](/solution/0800-0899/0812.Largest%20Triangle%20Area/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0812](https://leetcode.com/problems/largest-triangle-area)", "[Largest Triangle Area](/solution/0800-0899/0812.Largest%20Triangle%20Area/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "0829", "frontend_question_id": "0811", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/subdomain-visit-count", "url_en": "https://leetcode.com/problems/subdomain-visit-count", "relative_path_cn": "/solution/0800-0899/0811.Subdomain%20Visit%20Count/README.md", "relative_path_en": "/solution/0800-0899/0811.Subdomain%20Visit%20Count/README_EN.md", "title_cn": "\u5b50\u57df\u540d\u8bbf\u95ee\u8ba1\u6570", "title_en": "Subdomain Visit Count", "question_title_slug": "subdomain-visit-count", "content_en": "

    A website domain like "discuss.leetcode.com" consists of various subdomains. At the top level, we have "com", at the next level, we have "leetcode.com", and at the lowest level, "discuss.leetcode.com". When we visit a domain like "discuss.leetcode.com", we will also visit the parent domains "leetcode.com" and "com" implicitly.

    \r\n\r\n

    Now, call a "count-paired domain" to be a count (representing the number of visits this domain received), followed by a space, followed by the address. An example of a count-paired domain might be "9001 discuss.leetcode.com".

    \r\n\r\n

    We are given a list cpdomains of count-paired domains. We would like a list of count-paired domains, (in the same format as the input, and in any order), that explicitly counts the number of visits to each subdomain.

    \r\n\r\n
    \r\nExample 1:\r\nInput: \r\n["9001 discuss.leetcode.com"]\r\nOutput: \r\n["9001 discuss.leetcode.com", "9001 leetcode.com", "9001 com"]\r\nExplanation: \r\nWe only have one website domain: "discuss.leetcode.com". As discussed above, the subdomain "leetcode.com" and "com" will also be visited. So they will all be visited 9001 times.\r\n\r\n
    \r\n\r\n
    \r\nExample 2:\r\nInput: \r\n["900 google.mail.com", "50 yahoo.com", "1 intel.mail.com", "5 wiki.org"]\r\nOutput: \r\n["901 mail.com","50 yahoo.com","900 google.mail.com","5 wiki.org","5 org","1 intel.mail.com","951 com"]\r\nExplanation: \r\nWe will visit "google.mail.com" 900 times, "yahoo.com" 50 times, "intel.mail.com" once and "wiki.org" 5 times. For the subdomains, we will visit "mail.com" 900 + 1 = 901 times, "com" 900 + 50 + 1 = 951 times, and "org" 5 times.\r\n\r\n
    \r\n\r\n

    Notes:

    \r\n\r\n
      \r\n\t
    • The length of cpdomains will not exceed 100
    • \r\n\t
    • The length of each domain name will not exceed 100.
    • \r\n\t
    • Each address will have either 1 or 2 "." characters.
    • \r\n\t
    • The input count in any count-paired domain will not exceed 10000.
    • \r\n\t
    • The answer output can be returned in any order.
    • \r\n
    \r\n", "content_cn": "

    \u4e00\u4e2a\u7f51\u7ad9\u57df\u540d\uff0c\u5982"discuss.leetcode.com"\uff0c\u5305\u542b\u4e86\u591a\u4e2a\u5b50\u57df\u540d\u3002\u4f5c\u4e3a\u9876\u7ea7\u57df\u540d\uff0c\u5e38\u7528\u7684\u6709"com"\uff0c\u4e0b\u4e00\u7ea7\u5219\u6709"leetcode.com"\uff0c\u6700\u4f4e\u7684\u4e00\u7ea7\u4e3a"discuss.leetcode.com"\u3002\u5f53\u6211\u4eec\u8bbf\u95ee\u57df\u540d"discuss.leetcode.com"\u65f6\uff0c\u4e5f\u540c\u65f6\u8bbf\u95ee\u4e86\u5176\u7236\u57df\u540d"leetcode.com"\u4ee5\u53ca\u9876\u7ea7\u57df\u540d "com"\u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u5e26\u8bbf\u95ee\u6b21\u6570\u548c\u57df\u540d\u7684\u7ec4\u5408\uff0c\u8981\u6c42\u5206\u522b\u8ba1\u7b97\u6bcf\u4e2a\u57df\u540d\u88ab\u8bbf\u95ee\u7684\u6b21\u6570\u3002\u5176\u683c\u5f0f\u4e3a\u8bbf\u95ee\u6b21\u6570+\u7a7a\u683c+\u5730\u5740\uff0c\u4f8b\u5982\uff1a"9001 discuss.leetcode.com"\u3002

    \n\n

    \u63a5\u4e0b\u6765\u4f1a\u7ed9\u51fa\u4e00\u7ec4\u8bbf\u95ee\u6b21\u6570\u548c\u57df\u540d\u7ec4\u5408\u7684\u5217\u8868cpdomains \u3002\u8981\u6c42\u89e3\u6790\u51fa\u6240\u6709\u57df\u540d\u7684\u8bbf\u95ee\u6b21\u6570\uff0c\u8f93\u51fa\u683c\u5f0f\u548c\u8f93\u5165\u683c\u5f0f\u76f8\u540c\uff0c\u4e0d\u9650\u5b9a\u5148\u540e\u987a\u5e8f\u3002

    \n\n
    \n\u793a\u4f8b 1:\n\u8f93\u5165: \n["9001 discuss.leetcode.com"]\n\u8f93\u51fa: \n["9001 discuss.leetcode.com", "9001 leetcode.com", "9001 com"]\n\u8bf4\u660e: \n\u4f8b\u5b50\u4e2d\u4ec5\u5305\u542b\u4e00\u4e2a\u7f51\u7ad9\u57df\u540d\uff1a"discuss.leetcode.com"\u3002\u6309\u7167\u524d\u6587\u5047\u8bbe\uff0c\u5b50\u57df\u540d"leetcode.com"\u548c"com"\u90fd\u4f1a\u88ab\u8bbf\u95ee\uff0c\u6240\u4ee5\u5b83\u4eec\u90fd\u88ab\u8bbf\u95ee\u4e869001\u6b21\u3002\n
    \n\n
    \n\u793a\u4f8b 2\n\u8f93\u5165: \n["900 google.mail.com", "50 yahoo.com", "1 intel.mail.com", "5 wiki.org"]\n\u8f93\u51fa: \n["901 mail.com","50 yahoo.com","900 google.mail.com","5 wiki.org","5 org","1 intel.mail.com","951 com"]\n\u8bf4\u660e: \n\u6309\u7167\u5047\u8bbe\uff0c\u4f1a\u8bbf\u95ee"google.mail.com" 900\u6b21\uff0c"yahoo.com" 50\u6b21\uff0c"intel.mail.com" 1\u6b21\uff0c"wiki.org" 5\u6b21\u3002\n\u800c\u5bf9\u4e8e\u7236\u57df\u540d\uff0c\u4f1a\u8bbf\u95ee"mail.com" 900+1 = 901\u6b21\uff0c"com" 900 + 50 + 1 = 951\u6b21\uff0c\u548c "org" 5 \u6b21\u3002\n
    \n\n

    \u6ce8\u610f\u4e8b\u9879\uff1a

    \n\n
      \n\t
    •  cpdomains \u7684\u957f\u5ea6\u5c0f\u4e8e 100\u3002
    • \n\t
    • \u6bcf\u4e2a\u57df\u540d\u7684\u957f\u5ea6\u5c0f\u4e8e100\u3002
    • \n\t
    • \u6bcf\u4e2a\u57df\u540d\u5730\u5740\u5305\u542b\u4e00\u4e2a\u6216\u4e24\u4e2a"."\u7b26\u53f7\u3002
    • \n\t
    • \u8f93\u5165\u4e2d\u4efb\u610f\u4e00\u4e2a\u57df\u540d\u7684\u8bbf\u95ee\u6b21\u6570\u90fd\u5c0f\u4e8e10000\u3002
    • \n
    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector subdomainVisits(vector& cpdomains) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List subdomainVisits(String[] cpdomains) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def subdomainVisits(self, cpdomains):\n \"\"\"\n :type cpdomains: List[str]\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def subdomainVisits(self, cpdomains: List[str]) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** subdomainVisits(char ** cpdomains, int cpdomainsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList SubdomainVisits(string[] cpdomains) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} cpdomains\n * @return {string[]}\n */\nvar subdomainVisits = function(cpdomains) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} cpdomains\n# @return {String[]}\ndef subdomain_visits(cpdomains)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func subdomainVisits(_ cpdomains: [String]) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func subdomainVisits(cpdomains []string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def subdomainVisits(cpdomains: Array[String]): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun subdomainVisits(cpdomains: Array): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn subdomain_visits(cpdomains: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $cpdomains\n * @return String[]\n */\n function subdomainVisits($cpdomains) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function subdomainVisits(cpdomains: string[]): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (subdomain-visits cpdomains)\n (-> (listof string?) (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0811](https://leetcode-cn.com/problems/subdomain-visit-count)", "[\u5b50\u57df\u540d\u8bbf\u95ee\u8ba1\u6570](/solution/0800-0899/0811.Subdomain%20Visit%20Count/README.md)", "`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0811](https://leetcode.com/problems/subdomain-visit-count)", "[Subdomain Visit Count](/solution/0800-0899/0811.Subdomain%20Visit%20Count/README_EN.md)", "`Hash Table`", "Easy", ""]}, {"question_id": "0828", "frontend_question_id": "0810", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/chalkboard-xor-game", "url_en": "https://leetcode.com/problems/chalkboard-xor-game", "relative_path_cn": "/solution/0800-0899/0810.Chalkboard%20XOR%20Game/README.md", "relative_path_en": "/solution/0800-0899/0810.Chalkboard%20XOR%20Game/README_EN.md", "title_cn": "\u9ed1\u677f\u5f02\u6216\u6e38\u620f", "title_en": "Chalkboard XOR Game", "question_title_slug": "chalkboard-xor-game", "content_en": "

    We are given non-negative integers nums[i] which are written on a chalkboard.  Alice and Bob take turns erasing exactly one number from the chalkboard, with Alice starting first.  If erasing a number causes the bitwise XOR of all the elements of the chalkboard to become 0, then that player loses.  (Also, we'll say the bitwise XOR of one element is that element itself, and the bitwise XOR of no elements is 0.)

    \r\n\r\n

    Also, if any player starts their turn with the bitwise XOR of all the elements of the chalkboard equal to 0, then that player wins.

    \r\n\r\n

    Return True if and only if Alice wins the game, assuming both players play optimally.

    \r\n\r\n
    \r\nExample:\r\nInput: nums = [1, 1, 2]\r\nOutput: false\r\nExplanation: \r\nAlice has two choices: erase 1 or erase 2. \r\nIf she erases 1, the nums array becomes [1, 2]. The bitwise XOR of all the elements of the chalkboard is 1 XOR 2 = 3. Now Bob can remove any element he wants, because Alice will be the one to erase the last element and she will lose. \r\nIf Alice erases 2 first, now nums becomes [1, 1]. The bitwise XOR of all the elements of the chalkboard is 1 XOR 1 = 0. Alice will lose.\r\n\r\n
    \r\n\r\n

    Notes:

    \r\n\r\n
      \r\n\t
    • 1 <= N <= 1000
    • \r\n\t
    • 0 <= nums[i] <= 2^16.
    • \r\n
    \r\n\r\n

     

    \r\n", "content_cn": "

    \u9ed1\u677f\u4e0a\u5199\u7740\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\u6570\u7ec4 nums[i] \u3002Alice \u548c Bob \u8f6e\u6d41\u4ece\u9ed1\u677f\u4e0a\u64e6\u6389\u4e00\u4e2a\u6570\u5b57\uff0cAlice \u5148\u624b\u3002\u5982\u679c\u64e6\u9664\u4e00\u4e2a\u6570\u5b57\u540e\uff0c\u5269\u4f59\u7684\u6240\u6709\u6570\u5b57\u6309\u4f4d\u5f02\u6216\u8fd0\u7b97\u5f97\u51fa\u7684\u7ed3\u679c\u7b49\u4e8e 0 \u7684\u8bdd\uff0c\u5f53\u524d\u73a9\u5bb6\u6e38\u620f\u5931\u8d25\u3002\u00a0(\u53e6\u5916\uff0c\u5982\u679c\u53ea\u5269\u4e00\u4e2a\u6570\u5b57\uff0c\u6309\u4f4d\u5f02\u6216\u8fd0\u7b97\u5f97\u5230\u5b83\u672c\u8eab\uff1b\u5982\u679c\u65e0\u6570\u5b57\u5269\u4f59\uff0c\u6309\u4f4d\u5f02\u6216\u8fd0\u7b97\u7ed3\u679c\u4e3a\u00a00\u3002\uff09

    \n\n

    \u5e76\u4e14\uff0c\u8f6e\u5230\u67d0\u4e2a\u73a9\u5bb6\u65f6\uff0c\u5982\u679c\u5f53\u524d\u9ed1\u677f\u4e0a\u6240\u6709\u6570\u5b57\u6309\u4f4d\u5f02\u6216\u8fd0\u7b97\u7ed3\u679c\u7b49\u4e8e 0\uff0c\u8fd9\u4e2a\u73a9\u5bb6\u83b7\u80dc\u3002

    \n\n

    \u5047\u8bbe\u4e24\u4e2a\u73a9\u5bb6\u6bcf\u6b65\u90fd\u4f7f\u7528\u6700\u4f18\u89e3\uff0c\u5f53\u4e14\u4ec5\u5f53 Alice \u83b7\u80dc\u65f6\u8fd4\u56de true\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165: nums = [1, 1, 2]\n\u8f93\u51fa: false\n\u89e3\u91ca: \nAlice \u6709\u4e24\u4e2a\u9009\u62e9: \u64e6\u6389\u6570\u5b57 1 \u6216 2\u3002\n\u5982\u679c\u64e6\u6389 1, \u6570\u7ec4\u53d8\u6210 [1, 2]\u3002\u5269\u4f59\u6570\u5b57\u6309\u4f4d\u5f02\u6216\u5f97\u5230 1 XOR 2 = 3\u3002\u90a3\u4e48 Bob \u53ef\u4ee5\u64e6\u6389\u4efb\u610f\u6570\u5b57\uff0c\u56e0\u4e3a Alice \u4f1a\u6210\u4e3a\u64e6\u6389\u6700\u540e\u4e00\u4e2a\u6570\u5b57\u7684\u4eba\uff0c\u5979\u603b\u662f\u4f1a\u8f93\u3002\n\u5982\u679c Alice \u64e6\u6389 2\uff0c\u90a3\u4e48\u6570\u7ec4\u53d8\u6210[1, 1]\u3002\u5269\u4f59\u6570\u5b57\u6309\u4f4d\u5f02\u6216\u5f97\u5230 1 XOR 1 = 0\u3002Alice \u4ecd\u7136\u4f1a\u8f93\u6389\u6e38\u620f\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= N <= 1000
    • \n\t
    • 0 <= nums[i] <= 2^16
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool xorGame(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean xorGame(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def xorGame(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: bool\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def xorGame(self, nums: List[int]) -> bool:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool xorGame(int* nums, int numsSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool XorGame(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {boolean}\n */\nvar xorGame = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Boolean}\ndef xor_game(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func xorGame(_ nums: [Int]) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func xorGame(nums []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def xorGame(nums: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun xorGame(nums: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn xor_game(nums: Vec) -> bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Boolean\n */\n function xorGame($nums) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function xorGame(nums: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (xor-game nums)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0810](https://leetcode-cn.com/problems/chalkboard-xor-game)", "[\u9ed1\u677f\u5f02\u6216\u6e38\u620f](/solution/0800-0899/0810.Chalkboard%20XOR%20Game/README.md)", "`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[0810](https://leetcode.com/problems/chalkboard-xor-game)", "[Chalkboard XOR Game](/solution/0800-0899/0810.Chalkboard%20XOR%20Game/README_EN.md)", "`Math`", "Hard", ""]}, {"question_id": "0827", "frontend_question_id": "0809", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/expressive-words", "url_en": "https://leetcode.com/problems/expressive-words", "relative_path_cn": "/solution/0800-0899/0809.Expressive%20Words/README.md", "relative_path_en": "/solution/0800-0899/0809.Expressive%20Words/README_EN.md", "title_cn": "\u60c5\u611f\u4e30\u5bcc\u7684\u6587\u5b57", "title_en": "Expressive Words", "question_title_slug": "expressive-words", "content_en": "

    Sometimes people repeat letters to represent extra feeling, such as "hello" -> "heeellooo", "hi" -> "hiiii".  In these strings like "heeellooo", we have groups of adjacent letters that are all the same:  "h", "eee", "ll", "ooo".

    \n\n

    For some given string s, a query word is stretchy if it can be made to be equal to s by any number of applications of the following extension operation: choose a group consisting of characters c, and add some number of characters c to the group so that the size of the group is 3 or more.

    \n\n

    For example, starting with "hello", we could do an extension on the group "o" to get "hellooo", but we cannot get "helloo" since the group "oo" has size less than 3.  Also, we could do another extension like "ll" -> "lllll" to get "helllllooo".  If s = "helllllooo", then the query word "hello" would be stretchy because of these two extension operations: query = "hello" -> "hellooo" -> "helllllooo" = s.

    \n\n

    Given a list of query words, return the number of words that are stretchy. 

    \n\n

     

    \n\n
    \nExample:\nInput: \ns = "heeellooo"\nwords = ["hello", "hi", "helo"]\nOutput: 1\nExplanation: \nWe can extend "e" and "o" in the word "hello" to get "heeellooo".\nWe can't extend "helo" to get "heeellooo" because the group "ll" is not size 3 or more.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= len(s) <= 100.
    • \n\t
    • 0 <= len(words) <= 100.
    • \n\t
    • 0 <= len(words[i]) <= 100.
    • \n\t
    • s and all words in words consist only of lowercase letters
    • \n
    \n", "content_cn": "

    \u6709\u65f6\u5019\u4eba\u4eec\u4f1a\u7528\u91cd\u590d\u5199\u4e00\u4e9b\u5b57\u6bcd\u6765\u8868\u793a\u989d\u5916\u7684\u611f\u53d7\uff0c\u6bd4\u5982 \"hello\" -> \"heeellooo\", \"hi\" -> \"hiii\"\u3002\u6211\u4eec\u5c06\u76f8\u90bb\u5b57\u6bcd\u90fd\u76f8\u540c\u7684\u4e00\u4e32\u5b57\u7b26\u5b9a\u4e49\u4e3a\u76f8\u540c\u5b57\u6bcd\u7ec4\uff0c\u4f8b\u5982\uff1a\"h\", \"eee\", \"ll\", \"ooo\"\u3002

    \n\n

    \u5bf9\u4e8e\u4e00\u4e2a\u7ed9\u5b9a\u7684\u5b57\u7b26\u4e32 S \uff0c\u5982\u679c\u53e6\u4e00\u4e2a\u5355\u8bcd\u80fd\u591f\u901a\u8fc7\u5c06\u4e00\u4e9b\u5b57\u6bcd\u7ec4\u6269\u5f20\u4ece\u800c\u4f7f\u5176\u548c S \u76f8\u540c\uff0c\u6211\u4eec\u5c06\u8fd9\u4e2a\u5355\u8bcd\u5b9a\u4e49\u4e3a\u53ef\u6269\u5f20\u7684\uff08stretchy\uff09\u3002\u6269\u5f20\u64cd\u4f5c\u5b9a\u4e49\u5982\u4e0b\uff1a\u9009\u62e9\u4e00\u4e2a\u5b57\u6bcd\u7ec4\uff08\u5305\u542b\u5b57\u6bcd\u00a0c\u00a0\uff09\uff0c\u7136\u540e\u5f80\u5176\u4e2d\u6dfb\u52a0\u76f8\u540c\u7684\u5b57\u6bcd\u00a0c\u00a0\u4f7f\u5176\u957f\u5ea6\u8fbe\u5230 3 \u6216\u4ee5\u4e0a\u3002

    \n\n

    \u4f8b\u5982\uff0c\u4ee5\u00a0\"hello\" \u4e3a\u4f8b\uff0c\u6211\u4eec\u53ef\u4ee5\u5bf9\u5b57\u6bcd\u7ec4\u00a0\"o\" \u6269\u5f20\u5f97\u5230 \"hellooo\"\uff0c\u4f46\u662f\u65e0\u6cd5\u4ee5\u540c\u6837\u7684\u65b9\u6cd5\u5f97\u5230 \"helloo\" \u56e0\u4e3a\u5b57\u6bcd\u7ec4 \"oo\" \u957f\u5ea6\u5c0f\u4e8e\u00a03\u3002\u6b64\u5916\uff0c\u6211\u4eec\u53ef\u4ee5\u8fdb\u884c\u53e6\u4e00\u79cd\u6269\u5f20 \"ll\" -> \"lllll\" \u4ee5\u83b7\u5f97\u00a0\"helllllooo\"\u3002\u5982\u679c\u00a0S = \"helllllooo\"\uff0c\u90a3\u4e48\u67e5\u8be2\u8bcd\u00a0\"hello\" \u662f\u53ef\u6269\u5f20\u7684\uff0c\u56e0\u4e3a\u53ef\u4ee5\u5bf9\u5b83\u6267\u884c\u8fd9\u4e24\u79cd\u6269\u5f20\u64cd\u4f5c\u4f7f\u5f97\u00a0query = \"hello\" -> \"hellooo\" ->\u00a0\"helllllooo\" = S\u3002

    \n\n

    \u8f93\u5165\u4e00\u7ec4\u67e5\u8be2\u5355\u8bcd\uff0c\u8f93\u51fa\u5176\u4e2d\u53ef\u6269\u5f20\u7684\u5355\u8bcd\u6570\u91cf\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1a \nS = \"heeellooo\"\nwords = [\"hello\", \"hi\", \"helo\"]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\n\u6211\u4eec\u80fd\u901a\u8fc7\u6269\u5f20 \"hello\" \u7684 \"e\" \u548c \"o\" \u6765\u5f97\u5230 \"heeellooo\"\u3002\n\u6211\u4eec\u4e0d\u80fd\u901a\u8fc7\u6269\u5f20 \"helo\" \u6765\u5f97\u5230 \"heeellooo\" \u56e0\u4e3a \"ll\" \u7684\u957f\u5ea6\u5c0f\u4e8e 3 \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= len(S) <= 100\u3002
    • \n\t
    • 0 <= len(words) <= 100\u3002
    • \n\t
    • 0 <= len(words[i]) <= 100\u3002
    • \n\t
    • S\u00a0\u548c\u6240\u6709\u5728\u00a0words\u00a0\u4e2d\u7684\u5355\u8bcd\u90fd\u53ea\u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210\u3002
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int expressiveWords(string s, vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int expressiveWords(String s, String[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def expressiveWords(self, s, words):\n \"\"\"\n :type s: str\n :type words: List[str]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def expressiveWords(self, s: str, words: List[str]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint expressiveWords(char * s, char ** words, int wordsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ExpressiveWords(string s, string[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string[]} words\n * @return {number}\n */\nvar expressiveWords = function(s, words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String[]} words\n# @return {Integer}\ndef expressive_words(s, words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func expressiveWords(_ s: String, _ words: [String]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func expressiveWords(s string, words []string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def expressiveWords(s: String, words: Array[String]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun expressiveWords(s: String, words: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn expressive_words(s: String, words: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String[] $words\n * @return Integer\n */\n function expressiveWords($s, $words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function expressiveWords(s: string, words: string[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (expressive-words s words)\n (-> string? (listof string?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0809](https://leetcode-cn.com/problems/expressive-words)", "[\u60c5\u611f\u4e30\u5bcc\u7684\u6587\u5b57](/solution/0800-0899/0809.Expressive%20Words/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0809](https://leetcode.com/problems/expressive-words)", "[Expressive Words](/solution/0800-0899/0809.Expressive%20Words/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "0826", "frontend_question_id": "0808", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/soup-servings", "url_en": "https://leetcode.com/problems/soup-servings", "relative_path_cn": "/solution/0800-0899/0808.Soup%20Servings/README.md", "relative_path_en": "/solution/0800-0899/0808.Soup%20Servings/README_EN.md", "title_cn": "\u5206\u6c64", "title_en": "Soup Servings", "question_title_slug": "soup-servings", "content_en": "

    There are two types of soup: type A and type B. Initially we have n ml of each type of soup. There are four kinds of operations:

    \n\n
      \n\t
    1. Serve 100 ml of soup A and 0 ml of soup B
    2. \n\t
    3. Serve 75 ml of soup A and 25 ml of soup B
    4. \n\t
    5. Serve 50 ml of soup A and 50 ml of soup B
    6. \n\t
    7. Serve 25 ml of soup A and 75 ml of soup B
    8. \n
    \n\n

    When we serve some soup, we give it to someone and we no longer have it. Each turn, we will choose from the four operations with equal probability 0.25. If the remaining volume of soup is not enough to complete the operation, we will serve as much as we can. We stop once we no longer have some quantity of both types of soup.

    \n\n

    Note that we do not have the operation where all 100 ml's of soup B are used first.

    \n\n

    Return the probability that soup A will be empty first, plus half the probability that A and B become empty at the same time.

    \n\n

     

    \n\n
    \nExample:\nInput: n = 50\nOutput: 0.625\nExplanation: \nIf we choose the first two operations, A will become empty first. For the third operation, A and B will become empty at the same time. For the fourth operation, B will become empty first. So the total probability of A becoming empty first plus half the probability that A and B become empty at the same time, is 0.25 * (1 + 1 + 0.5 + 0) = 0.625.\n\n
    \n\n

    Notes:

    \n\n
      \n\t
    • 0 <= n <= 109.
    • \n\t
    • Answers within 10-6 of the true value will be accepted as correct.
    • \n
    \n", "content_cn": "

    \u6709 A \u548c B \u4e24\u79cd\u7c7b\u578b\u7684\u6c64\u3002\u4e00\u5f00\u59cb\u6bcf\u79cd\u7c7b\u578b\u7684\u6c64\u6709 N \u6beb\u5347\u3002\u6709\u56db\u79cd\u5206\u914d\u64cd\u4f5c\uff1a

    \n\n
      \n\t
    1. \u63d0\u4f9b 100ml \u7684\u6c64A \u548c 0ml \u7684\u6c64B\u3002
    2. \n\t
    3. \u63d0\u4f9b 75ml \u7684\u6c64A \u548c 25ml \u7684\u6c64B\u3002
    4. \n\t
    5. \u63d0\u4f9b 50ml \u7684\u6c64A \u548c 50ml \u7684\u6c64B\u3002
    6. \n\t
    7. \u63d0\u4f9b 25ml \u7684\u6c64A \u548c 75ml \u7684\u6c64B\u3002
    8. \n
    \n\n

    \u5f53\u6211\u4eec\u628a\u6c64\u5206\u914d\u7ed9\u67d0\u4eba\u4e4b\u540e\uff0c\u6c64\u5c31\u6ca1\u6709\u4e86\u3002\u6bcf\u4e2a\u56de\u5408\uff0c\u6211\u4eec\u5c06\u4ece\u56db\u79cd\u6982\u7387\u540c\u4e3a0.25\u7684\u64cd\u4f5c\u4e2d\u8fdb\u884c\u5206\u914d\u9009\u62e9\u3002\u5982\u679c\u6c64\u7684\u5269\u4f59\u91cf\u4e0d\u8db3\u4ee5\u5b8c\u6210\u67d0\u6b21\u64cd\u4f5c\uff0c\u6211\u4eec\u5c06\u5c3d\u53ef\u80fd\u5206\u914d\u3002\u5f53\u4e24\u79cd\u7c7b\u578b\u7684\u6c64\u90fd\u5206\u914d\u5b8c\u65f6\uff0c\u505c\u6b62\u64cd\u4f5c\u3002

    \n\n

    \u6ce8\u610f\u4e0d\u5b58\u5728\u5148\u5206\u914d100 ml\u6c64B\u7684\u64cd\u4f5c\u3002

    \n\n

    \u9700\u8981\u8fd4\u56de\u7684\u503c\uff1a \u6c64A\u5148\u5206\u914d\u5b8c\u7684\u6982\u7387 + \u6c64A\u548c\u6c64B\u540c\u65f6\u5206\u914d\u5b8c\u7684\u6982\u7387 / 2\u3002

    \n\n
    \n\u793a\u4f8b:\n\u8f93\u5165: N = 50\n\u8f93\u51fa: 0.625\n\u89e3\u91ca:\n\u5982\u679c\u6211\u4eec\u9009\u62e9\u524d\u4e24\u4e2a\u64cd\u4f5c\uff0cA\u5c06\u9996\u5148\u53d8\u4e3a\u7a7a\u3002\u5bf9\u4e8e\u7b2c\u4e09\u4e2a\u64cd\u4f5c\uff0cA\u548cB\u4f1a\u540c\u65f6\u53d8\u4e3a\u7a7a\u3002\u5bf9\u4e8e\u7b2c\u56db\u4e2a\u64cd\u4f5c\uff0cB\u5c06\u9996\u5148\u53d8\u4e3a\u7a7a\u3002\n\u6240\u4ee5A\u53d8\u4e3a\u7a7a\u7684\u603b\u6982\u7387\u52a0\u4e0aA\u548cB\u540c\u65f6\u53d8\u4e3a\u7a7a\u7684\u6982\u7387\u7684\u4e00\u534a\u662f 0.25 *(1 + 1 + 0.5 + 0)= 0.625\u3002\n
    \n\n

    \u6ce8\u91ca:

    \n\n
      \n\t
    • 0 <= N <= 10^9\u3002
    • \n\t
    • \n\t

      \u8fd4\u56de\u503c\u5728 10^-6 \u7684\u8303\u56f4\u5c06\u88ab\u8ba4\u4e3a\u662f\u6b63\u786e\u7684\u3002

      \n\t
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n double soupServings(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double soupServings(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def soupServings(self, n):\n \"\"\"\n :type n: int\n :rtype: float\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def soupServings(self, n: int) -> float:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\ndouble soupServings(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double SoupServings(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar soupServings = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Float}\ndef soup_servings(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func soupServings(_ n: Int) -> Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func soupServings(n int) float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def soupServings(n: Int): Double = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun soupServings(n: Int): Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn soup_servings(n: i32) -> f64 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Float\n */\n function soupServings($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function soupServings(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (soup-servings n)\n (-> exact-integer? flonum?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0808](https://leetcode-cn.com/problems/soup-servings)", "[\u5206\u6c64](/solution/0800-0899/0808.Soup%20Servings/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0808](https://leetcode.com/problems/soup-servings)", "[Soup Servings](/solution/0800-0899/0808.Soup%20Servings/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0825", "frontend_question_id": "0807", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/max-increase-to-keep-city-skyline", "url_en": "https://leetcode.com/problems/max-increase-to-keep-city-skyline", "relative_path_cn": "/solution/0800-0899/0807.Max%20Increase%20to%20Keep%20City%20Skyline/README.md", "relative_path_en": "/solution/0800-0899/0807.Max%20Increase%20to%20Keep%20City%20Skyline/README_EN.md", "title_cn": "\u4fdd\u6301\u57ce\u5e02\u5929\u9645\u7ebf", "title_en": "Max Increase to Keep City Skyline", "question_title_slug": "max-increase-to-keep-city-skyline", "content_en": "

    In a 2 dimensional array grid, each value grid[i][j] represents the height of a building located there. We are allowed to increase the height of any number of buildings, by any amount (the amounts can be different for different buildings). Height 0 is considered to be a building as well. 

    \r\n\r\n

    At the end, the "skyline" when viewed from all four directions of the grid, i.e. top, bottom, left, and right, must be the same as the skyline of the original grid. A city's skyline is the outer contour of the rectangles formed by all the buildings when viewed from a distance. See the following example.

    \r\n\r\n

    What is the maximum total sum that the height of the buildings can be increased?

    \r\n\r\n
    \r\nExample:\r\nInput: grid = [[3,0,8,4],[2,4,5,7],[9,2,6,3],[0,3,1,0]]\r\nOutput: 35\r\nExplanation: \r\nThe grid is:\r\n[ [3, 0, 8, 4], \r\n  [2, 4, 5, 7],\r\n  [9, 2, 6, 3],\r\n  [0, 3, 1, 0] ]\r\n\r\nThe skyline viewed from top or bottom is: [9, 4, 8, 7]\r\nThe skyline viewed from left or right is: [8, 7, 9, 3]\r\n\r\nThe grid after increasing the height of buildings without affecting skylines is:\r\n\r\ngridNew = [ [8, 4, 8, 7],\r\n            [7, 4, 7, 7],\r\n            [9, 4, 8, 7],\r\n            [3, 3, 3, 3] ]\r\n\r\n
    \r\n\r\n

    Notes:

    \r\n\r\n
      \r\n\t
    • 1 < grid.length = grid[0].length <= 50.
    • \r\n\t
    • All heights grid[i][j] are in the range [0, 100].
    • \r\n\t
    • All buildings in grid[i][j] occupy the entire grid cell: that is, they are a 1 x 1 x grid[i][j] rectangular prism.
    • \r\n
    \r\n", "content_cn": "

    \u5728\u4e8c\u7ef4\u6570\u7ec4grid\u4e2d\uff0cgrid[i][j]\u4ee3\u8868\u4f4d\u4e8e\u67d0\u5904\u7684\u5efa\u7b51\u7269\u7684\u9ad8\u5ea6\u3002 \u6211\u4eec\u88ab\u5141\u8bb8\u589e\u52a0\u4efb\u4f55\u6570\u91cf\uff08\u4e0d\u540c\u5efa\u7b51\u7269\u7684\u6570\u91cf\u53ef\u80fd\u4e0d\u540c\uff09\u7684\u5efa\u7b51\u7269\u7684\u9ad8\u5ea6\u3002 \u9ad8\u5ea6 0 \u4e5f\u88ab\u8ba4\u4e3a\u662f\u5efa\u7b51\u7269\u3002

    \n\n

    \u6700\u540e\uff0c\u4ece\u65b0\u6570\u7ec4\u7684\u6240\u6709\u56db\u4e2a\u65b9\u5411\uff08\u5373\u9876\u90e8\uff0c\u5e95\u90e8\uff0c\u5de6\u4fa7\u548c\u53f3\u4fa7\uff09\u89c2\u770b\u7684“\u5929\u9645\u7ebf”\u5fc5\u987b\u4e0e\u539f\u59cb\u6570\u7ec4\u7684\u5929\u9645\u7ebf\u76f8\u540c\u3002 \u57ce\u5e02\u7684\u5929\u9645\u7ebf\u662f\u4ece\u8fdc\u5904\u89c2\u770b\u65f6\uff0c\u7531\u6240\u6709\u5efa\u7b51\u7269\u5f62\u6210\u7684\u77e9\u5f62\u7684\u5916\u90e8\u8f6e\u5ed3\u3002 \u8bf7\u770b\u4e0b\u9762\u7684\u4f8b\u5b50\u3002

    \n\n

    \u5efa\u7b51\u7269\u9ad8\u5ea6\u53ef\u4ee5\u589e\u52a0\u7684\u6700\u5927\u603b\u548c\u662f\u591a\u5c11\uff1f

    \n\n
    \n\u4f8b\u5b50\uff1a\n\u8f93\u5165\uff1a grid = [[3,0,8,4],[2,4,5,7],[9,2,6,3],[0,3,1,0]]\n\u8f93\u51fa\uff1a 35\n\u89e3\u91ca\uff1a \nThe grid is:\n[ [3, 0, 8, 4], \n  [2, 4, 5, 7],\n  [9, 2, 6, 3],\n  [0, 3, 1, 0] ]\n\n\u4ece\u6570\u7ec4\u7ad6\u76f4\u65b9\u5411\uff08\u5373\u9876\u90e8\uff0c\u5e95\u90e8\uff09\u770b“\u5929\u9645\u7ebf”\u662f\uff1a[9, 4, 8, 7]\n\u4ece\u6c34\u5e73\u6c34\u5e73\u65b9\u5411\uff08\u5373\u5de6\u4fa7\uff0c\u53f3\u4fa7\uff09\u770b“\u5929\u9645\u7ebf”\u662f\uff1a[8, 7, 9, 3]\n\n\u5728\u4e0d\u5f71\u54cd\u5929\u9645\u7ebf\u7684\u60c5\u51b5\u4e0b\u5bf9\u5efa\u7b51\u7269\u8fdb\u884c\u589e\u9ad8\u540e\uff0c\u65b0\u6570\u7ec4\u5982\u4e0b\uff1a\n\ngridNew = [ [8, 4, 8, 7],\n            [7, 4, 7, 7],\n            [9, 4, 8, 7],\n            [3, 3, 3, 3] ]\n
    \n\n

    \u8bf4\u660e:

    \n\n
      \n\t
    • 1 < grid.length = grid[0].length <= 50\u3002
    • \n\t
    •  grid[i][j] \u7684\u9ad8\u5ea6\u8303\u56f4\u662f\uff1a [0, 100]\u3002
    • \n\t
    • \u4e00\u5ea7\u5efa\u7b51\u7269\u5360\u636e\u4e00\u4e2agrid[i][j]\uff1a\u6362\u8a00\u4e4b\uff0c\u5b83\u4eec\u662f 1 x 1 x grid[i][j] \u7684\u957f\u65b9\u4f53\u3002
    • \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxIncreaseKeepingSkyline(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxIncreaseKeepingSkyline(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxIncreaseKeepingSkyline(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxIncreaseKeepingSkyline(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxIncreaseKeepingSkyline(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxIncreaseKeepingSkyline(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar maxIncreaseKeepingSkyline = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef max_increase_keeping_skyline(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxIncreaseKeepingSkyline(_ grid: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxIncreaseKeepingSkyline(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxIncreaseKeepingSkyline(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxIncreaseKeepingSkyline(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_increase_keeping_skyline(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function maxIncreaseKeepingSkyline($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxIncreaseKeepingSkyline(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-increase-keeping-skyline grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0807](https://leetcode-cn.com/problems/max-increase-to-keep-city-skyline)", "[\u4fdd\u6301\u57ce\u5e02\u5929\u9645\u7ebf](/solution/0800-0899/0807.Max%20Increase%20to%20Keep%20City%20Skyline/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0807](https://leetcode.com/problems/max-increase-to-keep-city-skyline)", "[Max Increase to Keep City Skyline](/solution/0800-0899/0807.Max%20Increase%20to%20Keep%20City%20Skyline/README_EN.md)", "", "Medium", ""]}, {"question_id": "0824", "frontend_question_id": "0806", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-lines-to-write-string", "url_en": "https://leetcode.com/problems/number-of-lines-to-write-string", "relative_path_cn": "/solution/0800-0899/0806.Number%20of%20Lines%20To%20Write%20String/README.md", "relative_path_en": "/solution/0800-0899/0806.Number%20of%20Lines%20To%20Write%20String/README_EN.md", "title_cn": "\u5199\u5b57\u7b26\u4e32\u9700\u8981\u7684\u884c\u6570", "title_en": "Number of Lines To Write String", "question_title_slug": "number-of-lines-to-write-string", "content_en": "

    You are given a string s of lowercase English letters and an array widths denoting how many pixels wide each lowercase English letter is. Specifically, widths[0] is the width of 'a', widths[1] is the width of 'b', and so on.

    \n\n

    You are trying to write s across several lines, where each line is no longer than 100 pixels. Starting at the beginning of s, write as many letters on the first line such that the total width does not exceed 100 pixels. Then, from where you stopped in s, continue writing as many letters as you can on the second line. Continue this process until you have written all of s.

    \n\n

    Return an array result of length 2 where:

    \n\n
      \n\t
    • result[0] is the total number of lines.
    • \n\t
    • result[1] is the width of the last line in pixels.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: widths = [10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10], s = "abcdefghijklmnopqrstuvwxyz"\nOutput: [3,60]\nExplanation: You can write s as follows:\nabcdefghij  // 100 pixels wide\nklmnopqrst  // 100 pixels wide\nuvwxyz      // 60 pixels wide\nThere are a total of 3 lines, and the last line is 60 pixels wide.
    \n\n

    Example 2:

    \n\n
    \nInput: widths = [4,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10], s = "bbbcccdddaaa"\nOutput: [2,4]\nExplanation: You can write s as follows:\nbbbcccdddaa  // 98 pixels wide\na            // 4 pixels wide\nThere are a total of 2 lines, and the last line is 4 pixels wide.
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • widths.length == 26
    • \n\t
    • 2 <= widths[i] <= 10
    • \n\t
    • 1 <= s.length <= 1000
    • \n\t
    • s contains only lowercase English letters.
    • \n
    \n", "content_cn": "

    \u6211\u4eec\u8981\u628a\u7ed9\u5b9a\u7684\u5b57\u7b26\u4e32 S \u4ece\u5de6\u5230\u53f3\u5199\u5230\u6bcf\u4e00\u884c\u4e0a\uff0c\u6bcf\u4e00\u884c\u7684\u6700\u5927\u5bbd\u5ea6\u4e3a100\u4e2a\u5355\u4f4d\uff0c\u5982\u679c\u6211\u4eec\u5728\u5199\u67d0\u4e2a\u5b57\u6bcd\u7684\u65f6\u5019\u4f1a\u4f7f\u8fd9\u884c\u8d85\u8fc7\u4e86100 \u4e2a\u5355\u4f4d\uff0c\u90a3\u4e48\u6211\u4eec\u5e94\u8be5\u628a\u8fd9\u4e2a\u5b57\u6bcd\u5199\u5230\u4e0b\u4e00\u884c\u3002\u6211\u4eec\u7ed9\u5b9a\u4e86\u4e00\u4e2a\u6570\u7ec4 widths \uff0c\u8fd9\u4e2a\u6570\u7ec4 widths[0] \u4ee3\u8868 'a' \u9700\u8981\u7684\u5355\u4f4d\uff0c widths[1] \u4ee3\u8868 'b' \u9700\u8981\u7684\u5355\u4f4d\uff0c...\uff0c widths[25] \u4ee3\u8868 'z' \u9700\u8981\u7684\u5355\u4f4d\u3002

    \n\n

    \u73b0\u5728\u56de\u7b54\u4e24\u4e2a\u95ee\u9898\uff1a\u81f3\u5c11\u591a\u5c11\u884c\u80fd\u653e\u4e0bS\uff0c\u4ee5\u53ca\u6700\u540e\u4e00\u884c\u4f7f\u7528\u7684\u5bbd\u5ea6\u662f\u591a\u5c11\u4e2a\u5355\u4f4d\uff1f\u5c06\u4f60\u7684\u7b54\u6848\u4f5c\u4e3a\u957f\u5ea6\u4e3a2\u7684\u6574\u6570\u5217\u8868\u8fd4\u56de\u3002

    \n\n
    \n\u793a\u4f8b 1:\n\u8f93\u5165: \nwidths = [10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10]\nS = "abcdefghijklmnopqrstuvwxyz"\n\u8f93\u51fa: [3, 60]\n\u89e3\u91ca: \n\u6240\u6709\u7684\u5b57\u7b26\u62e5\u6709\u76f8\u540c\u7684\u5360\u7528\u5355\u4f4d10\u3002\u6240\u4ee5\u4e66\u5199\u6240\u6709\u768426\u4e2a\u5b57\u6bcd\uff0c\n\u6211\u4eec\u9700\u89812\u4e2a\u6574\u884c\u548c\u5360\u752860\u4e2a\u5355\u4f4d\u7684\u4e00\u884c\u3002\n
    \n\n
    \n\u793a\u4f8b 2:\n\u8f93\u5165: \nwidths = [4,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10]\nS = "bbbcccdddaaa"\n\u8f93\u51fa: [2, 4]\n\u89e3\u91ca: \n\u9664\u53bb\u5b57\u6bcd'a'\u6240\u6709\u7684\u5b57\u7b26\u90fd\u662f\u76f8\u540c\u7684\u5355\u4f4d10\uff0c\u5e76\u4e14\u5b57\u7b26\u4e32 "bbbcccdddaa" \u5c06\u4f1a\u8986\u76d6 9 * 10 + 2 * 4 = 98 \u4e2a\u5355\u4f4d.\n\u6700\u540e\u4e00\u4e2a\u5b57\u6bcd 'a' \u5c06\u4f1a\u88ab\u5199\u5230\u7b2c\u4e8c\u884c\uff0c\u56e0\u4e3a\u7b2c\u4e00\u884c\u53ea\u5269\u4e0b2\u4e2a\u5355\u4f4d\u4e86\u3002\n\u6240\u4ee5\uff0c\u8fd9\u4e2a\u7b54\u6848\u662f2\u884c\uff0c\u7b2c\u4e8c\u884c\u67094\u4e2a\u5355\u4f4d\u5bbd\u5ea6\u3002\n
    \n\n

     

    \n\n

    \u6ce8:

    \n\n
      \n\t
    • \u5b57\u7b26\u4e32 S \u7684\u957f\u5ea6\u5728 [1, 1000] \u7684\u8303\u56f4\u3002
    • \n\t
    • S \u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd\u3002
    • \n\t
    • widths \u662f\u957f\u5ea6\u4e3a 26\u7684\u6570\u7ec4\u3002
    • \n\t
    • widths[i] \u503c\u7684\u8303\u56f4\u5728 [2, 10]\u3002
    • \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector numberOfLines(vector& widths, string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] numberOfLines(int[] widths, String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numberOfLines(self, widths, s):\n \"\"\"\n :type widths: List[int]\n :type s: str\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numberOfLines(self, widths: List[int], s: str) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* numberOfLines(int* widths, int widthsSize, char * s, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] NumberOfLines(int[] widths, string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} widths\n * @param {string} s\n * @return {number[]}\n */\nvar numberOfLines = function(widths, s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} widths\n# @param {String} s\n# @return {Integer[]}\ndef number_of_lines(widths, s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numberOfLines(_ widths: [Int], _ s: String) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numberOfLines(widths []int, s string) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numberOfLines(widths: Array[Int], s: String): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numberOfLines(widths: IntArray, s: String): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn number_of_lines(widths: Vec, s: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $widths\n * @param String $s\n * @return Integer[]\n */\n function numberOfLines($widths, $s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numberOfLines(widths: number[], s: string): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (number-of-lines widths s)\n (-> (listof exact-integer?) string? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0806](https://leetcode-cn.com/problems/number-of-lines-to-write-string)", "[\u5199\u5b57\u7b26\u4e32\u9700\u8981\u7684\u884c\u6570](/solution/0800-0899/0806.Number%20of%20Lines%20To%20Write%20String/README.md)", "", "\u7b80\u5355", ""], "md_table_row_en": ["[0806](https://leetcode.com/problems/number-of-lines-to-write-string)", "[Number of Lines To Write String](/solution/0800-0899/0806.Number%20of%20Lines%20To%20Write%20String/README_EN.md)", "", "Easy", ""]}, {"question_id": "0823", "frontend_question_id": "0805", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/split-array-with-same-average", "url_en": "https://leetcode.com/problems/split-array-with-same-average", "relative_path_cn": "/solution/0800-0899/0805.Split%20Array%20With%20Same%20Average/README.md", "relative_path_en": "/solution/0800-0899/0805.Split%20Array%20With%20Same%20Average/README_EN.md", "title_cn": "\u6570\u7ec4\u7684\u5747\u503c\u5206\u5272", "title_en": "Split Array With Same Average", "question_title_slug": "split-array-with-same-average", "content_en": "

    You are given an integer array nums.

    \n\n

    You should move each element of nums into one of the two arrays A and B such that A and B are non-empty, and average(A) == average(B).

    \n\n

    Return true if it is possible to achieve that and false otherwise.

    \n\n

    Note that for an array arr, average(arr) is the sum of all the elements of arr over the length of arr.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,3,4,5,6,7,8]\nOutput: true\nExplanation: We can split the array into [1,4,5,8] and [2,3,6,7], and both of them have an average of 4.5.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [3,1]\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 30
    • \n\t
    • 0 <= nums[i] <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u7684\u6574\u6570\u6570\u7ec4 A \uff0c\u6211\u4eec\u8981\u5c06 A\u6570\u7ec4 \u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u79fb\u52a8\u5230 B\u6570\u7ec4 \u6216\u8005 C\u6570\u7ec4\u4e2d\u3002\uff08B\u6570\u7ec4\u548cC\u6570\u7ec4\u5728\u5f00\u59cb\u7684\u65f6\u5019\u90fd\u4e3a\u7a7a\uff09

    \n\n

    \u8fd4\u56detrue \uff0c\u5f53\u4e14\u4ec5\u5f53\u5728\u6211\u4eec\u7684\u5b8c\u6210\u8fd9\u6837\u7684\u79fb\u52a8\u540e\uff0c\u53ef\u4f7f\u5f97B\u6570\u7ec4\u7684\u5e73\u5747\u503c\u548cC\u6570\u7ec4\u7684\u5e73\u5747\u503c\u76f8\u7b49\uff0c\u5e76\u4e14B\u6570\u7ec4\u548cC\u6570\u7ec4\u90fd\u4e0d\u4e3a\u7a7a\u3002

    \n\n
    \n\u793a\u4f8b:\n\u8f93\u5165: \n[1,2,3,4,5,6,7,8]\n\u8f93\u51fa: true\n\u89e3\u91ca: \u6211\u4eec\u53ef\u4ee5\u5c06\u6570\u7ec4\u5206\u5272\u4e3a [1,4,5,8] \u548c [2,3,6,7], \u4ed6\u4eec\u7684\u5e73\u5747\u503c\u90fd\u662f4.5\u3002\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    • A \u6570\u7ec4\u7684\u957f\u5ea6\u8303\u56f4\u4e3a [1, 30].
    • \n\t
    • A[i] \u7684\u6570\u636e\u8303\u56f4\u4e3a [0, 10000].
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool splitArraySameAverage(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean splitArraySameAverage(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def splitArraySameAverage(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def splitArraySameAverage(self, nums: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool splitArraySameAverage(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool SplitArraySameAverage(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {boolean}\n */\nvar splitArraySameAverage = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Boolean}\ndef split_array_same_average(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func splitArraySameAverage(_ nums: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func splitArraySameAverage(nums []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def splitArraySameAverage(nums: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun splitArraySameAverage(nums: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn split_array_same_average(nums: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Boolean\n */\n function splitArraySameAverage($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function splitArraySameAverage(nums: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (split-array-same-average nums)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0805](https://leetcode-cn.com/problems/split-array-with-same-average)", "[\u6570\u7ec4\u7684\u5747\u503c\u5206\u5272](/solution/0800-0899/0805.Split%20Array%20With%20Same%20Average/README.md)", "`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[0805](https://leetcode.com/problems/split-array-with-same-average)", "[Split Array With Same Average](/solution/0800-0899/0805.Split%20Array%20With%20Same%20Average/README_EN.md)", "`Math`", "Hard", ""]}, {"question_id": "0822", "frontend_question_id": "0804", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/unique-morse-code-words", "url_en": "https://leetcode.com/problems/unique-morse-code-words", "relative_path_cn": "/solution/0800-0899/0804.Unique%20Morse%20Code%20Words/README.md", "relative_path_en": "/solution/0800-0899/0804.Unique%20Morse%20Code%20Words/README_EN.md", "title_cn": "\u552f\u4e00\u6469\u5c14\u65af\u5bc6\u7801\u8bcd", "title_en": "Unique Morse Code Words", "question_title_slug": "unique-morse-code-words", "content_en": "

    International Morse Code defines a standard encoding where each letter is mapped to a series of dots and dashes, as follows: "a" maps to ".-", "b" maps to "-...", "c" maps to "-.-.", and so on.

    \n\n

    For convenience, the full table for the 26 letters of the English alphabet is given below:

    \n\n
    \n[".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."]
    \n\n

    Now, given a list of words, each word can be written as a concatenation of the Morse code of each letter. For example, "cab" can be written as "-.-..--...", (which is the concatenation "-.-." + ".-" + "-..."). We'll call such a concatenation, the transformation of a word.

    \n\n

    Return the number of different transformations among all words we have.

    \n\n
    \nExample:\nInput: words = ["gin", "zen", "gig", "msg"]\nOutput: 2\nExplanation: \nThe transformation of each word is:\n"gin" -> "--...-."\n"zen" -> "--...-."\n"gig" -> "--...--."\n"msg" -> "--...--."\n\nThere are 2 different transformations, "--...-." and "--...--.".\n
    \n\n

    Note:

    \n\n
      \n\t
    • The length of words will be at most 100.
    • \n\t
    • Each words[i] will have length in range [1, 12].
    • \n\t
    • words[i] will only consist of lowercase letters.
    • \n
    \n", "content_cn": "

    \u56fd\u9645\u6469\u5c14\u65af\u5bc6\u7801\u5b9a\u4e49\u4e00\u79cd\u6807\u51c6\u7f16\u7801\u65b9\u5f0f\uff0c\u5c06\u6bcf\u4e2a\u5b57\u6bcd\u5bf9\u5e94\u4e8e\u4e00\u4e2a\u7531\u4e00\u7cfb\u5217\u70b9\u548c\u77ed\u7ebf\u7ec4\u6210\u7684\u5b57\u7b26\u4e32\uff0c \u6bd4\u5982: "a" \u5bf9\u5e94 ".-", "b" \u5bf9\u5e94 "-...", "c" \u5bf9\u5e94 "-.-.", \u7b49\u7b49\u3002

    \n\n

    \u4e3a\u4e86\u65b9\u4fbf\uff0c\u6240\u670926\u4e2a\u82f1\u6587\u5b57\u6bcd\u5bf9\u5e94\u6469\u5c14\u65af\u5bc6\u7801\u8868\u5982\u4e0b\uff1a

    \n\n
    [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."]
    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u5355\u8bcd\u5217\u8868\uff0c\u6bcf\u4e2a\u5355\u8bcd\u53ef\u4ee5\u5199\u6210\u6bcf\u4e2a\u5b57\u6bcd\u5bf9\u5e94\u6469\u5c14\u65af\u5bc6\u7801\u7684\u7ec4\u5408\u3002\u4f8b\u5982\uff0c"cab" \u53ef\u4ee5\u5199\u6210 "-.-..--..."\uff0c(\u5373 "-.-." + ".-" + "-..." \u5b57\u7b26\u4e32\u7684\u7ed3\u5408)\u3002\u6211\u4eec\u5c06\u8fd9\u6837\u4e00\u4e2a\u8fde\u63a5\u8fc7\u7a0b\u79f0\u4f5c\u5355\u8bcd\u7ffb\u8bd1\u3002

    \n\n

    \u8fd4\u56de\u6211\u4eec\u53ef\u4ee5\u83b7\u5f97\u6240\u6709\u8bcd\u4e0d\u540c\u5355\u8bcd\u7ffb\u8bd1\u7684\u6570\u91cf\u3002

    \n\n
    \u4f8b\u5982:\n\u8f93\u5165: words = ["gin", "zen", "gig", "msg"]\n\u8f93\u51fa: 2\n\u89e3\u91ca: \n\u5404\u5355\u8bcd\u7ffb\u8bd1\u5982\u4e0b:\n"gin" -> "--...-."\n"zen" -> "--...-."\n"gig" -> "--...--."\n"msg" -> "--...--."\n\n\u5171\u6709 2 \u79cd\u4e0d\u540c\u7ffb\u8bd1, "--...-." \u548c "--...--.".\n
    \n\n

     

    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    • \u5355\u8bcd\u5217\u8868words \u7684\u957f\u5ea6\u4e0d\u4f1a\u8d85\u8fc7 100\u3002
    • \n\t
    • \u6bcf\u4e2a\u5355\u8bcd words[i]\u7684\u957f\u5ea6\u8303\u56f4\u4e3a [1, 12]\u3002
    • \n\t
    • \u6bcf\u4e2a\u5355\u8bcd words[i]\u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd\u3002
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int uniqueMorseRepresentations(vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int uniqueMorseRepresentations(String[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def uniqueMorseRepresentations(self, words):\n \"\"\"\n :type words: List[str]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def uniqueMorseRepresentations(self, words: List[str]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint uniqueMorseRepresentations(char ** words, int wordsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int UniqueMorseRepresentations(string[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @return {number}\n */\nvar uniqueMorseRepresentations = function(words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @return {Integer}\ndef unique_morse_representations(words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func uniqueMorseRepresentations(_ words: [String]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func uniqueMorseRepresentations(words []string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def uniqueMorseRepresentations(words: Array[String]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun uniqueMorseRepresentations(words: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn unique_morse_representations(words: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @return Integer\n */\n function uniqueMorseRepresentations($words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function uniqueMorseRepresentations(words: string[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (unique-morse-representations words)\n (-> (listof string?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0804](https://leetcode-cn.com/problems/unique-morse-code-words)", "[\u552f\u4e00\u6469\u5c14\u65af\u5bc6\u7801\u8bcd](/solution/0800-0899/0804.Unique%20Morse%20Code%20Words/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0804](https://leetcode.com/problems/unique-morse-code-words)", "[Unique Morse Code Words](/solution/0800-0899/0804.Unique%20Morse%20Code%20Words/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "0821", "frontend_question_id": "0803", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/bricks-falling-when-hit", "url_en": "https://leetcode.com/problems/bricks-falling-when-hit", "relative_path_cn": "/solution/0800-0899/0803.Bricks%20Falling%20When%20Hit/README.md", "relative_path_en": "/solution/0800-0899/0803.Bricks%20Falling%20When%20Hit/README_EN.md", "title_cn": "\u6253\u7816\u5757", "title_en": "Bricks Falling When Hit", "question_title_slug": "bricks-falling-when-hit", "content_en": "

    You are given an m x n binary grid, where each 1 represents a brick and 0 represents an empty space. A brick is stable if:

    \n\n
      \n\t
    • It is directly connected to the top of the grid, or
    • \n\t
    • At least one other brick in its four adjacent cells is stable.
    • \n
    \n\n

    You are also given an array hits, which is a sequence of erasures we want to apply. Each time we want to erase the brick at the location hits[i] = (rowi, coli). The brick on that location (if it exists) will disappear. Some other bricks may no longer be stable because of that erasure and will fall. Once a brick falls, it is immediately erased from the grid (i.e., it does not land on other stable bricks).

    \n\n

    Return an array result, where each result[i] is the number of bricks that will fall after the ith erasure is applied.

    \n\n

    Note that an erasure may refer to a location with no brick, and if it does, no bricks drop.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: grid = [[1,0,0,0],[1,1,1,0]], hits = [[1,0]]\nOutput: [2]\nExplanation: Starting with the grid:\n[[1,0,0,0],\n [1,1,1,0]]\nWe erase the underlined brick at (1,0), resulting in the grid:\n[[1,0,0,0],\n [0,1,1,0]]\nThe two underlined bricks are no longer stable as they are no longer connected to the top nor adjacent to another stable brick, so they will fall. The resulting grid is:\n[[1,0,0,0],\n [0,0,0,0]]\nHence the result is [2].\n
    \n\n

    Example 2:

    \n\n
    \nInput: grid = [[1,0,0,0],[1,1,0,0]], hits = [[1,1],[1,0]]\nOutput: [0,0]\nExplanation: Starting with the grid:\n[[1,0,0,0],\n [1,1,0,0]]\nWe erase the underlined brick at (1,1), resulting in the grid:\n[[1,0,0,0],\n [1,0,0,0]]\nAll remaining bricks are still stable, so no bricks fall. The grid remains the same:\n[[1,0,0,0],\n [1,0,0,0]]\nNext, we erase the underlined brick at (1,0), resulting in the grid:\n[[1,0,0,0],\n [0,0,0,0]]\nOnce again, all remaining bricks are still stable, so no bricks fall.\nHence the result is [0,0].\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= m, n <= 200
    • \n\t
    • grid[i][j] is 0 or 1.
    • \n\t
    • 1 <= hits.length <= 4 * 104
    • \n\t
    • hits[i].length == 2
    • \n\t
    • 0 <= x<= m - 1
    • \n\t
    • 0 <= yi <= n - 1
    • \n\t
    • All (xi, yi) are unique.
    • \n
    \n", "content_cn": "

    \u6709\u4e00\u4e2a m x n \u7684\u4e8c\u5143\u7f51\u683c\uff0c\u5176\u4e2d 1 \u8868\u793a\u7816\u5757\uff0c0 \u8868\u793a\u7a7a\u767d\u3002\u7816\u5757 \u7a33\u5b9a\uff08\u4e0d\u4f1a\u6389\u843d\uff09\u7684\u524d\u63d0\u662f\uff1a

    \n\n
      \n\t
    • \u4e00\u5757\u7816\u76f4\u63a5\u8fde\u63a5\u5230\u7f51\u683c\u7684\u9876\u90e8\uff0c\u6216\u8005
    • \n\t
    • \u81f3\u5c11\u6709\u4e00\u5757\u76f8\u90bb\uff084\u00a0\u4e2a\u65b9\u5411\u4e4b\u4e00\uff09\u7816\u5757 \u7a33\u5b9a \u4e0d\u4f1a\u6389\u843d\u65f6
    • \n
    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 hits \uff0c\u8fd9\u662f\u9700\u8981\u4f9d\u6b21\u6d88\u9664\u7816\u5757\u7684\u4f4d\u7f6e\u3002\u6bcf\u5f53\u6d88\u9664\u00a0hits[i] = (rowi, coli) \u4f4d\u7f6e\u4e0a\u7684\u7816\u5757\u65f6\uff0c\u5bf9\u5e94\u4f4d\u7f6e\u7684\u7816\u5757\uff08\u82e5\u5b58\u5728\uff09\u4f1a\u6d88\u5931\uff0c\u7136\u540e\u5176\u4ed6\u7684\u7816\u5757\u53ef\u80fd\u56e0\u4e3a\u8fd9\u4e00\u6d88\u9664\u64cd\u4f5c\u800c\u6389\u843d\u3002\u4e00\u65e6\u7816\u5757\u6389\u843d\uff0c\u5b83\u4f1a\u7acb\u5373\u4ece\u7f51\u683c\u4e2d\u6d88\u5931\uff08\u5373\uff0c\u5b83\u4e0d\u4f1a\u843d\u5728\u5176\u4ed6\u7a33\u5b9a\u7684\u7816\u5757\u4e0a\uff09\u3002

    \n\n

    \u8fd4\u56de\u4e00\u4e2a\u6570\u7ec4 result \uff0c\u5176\u4e2d result[i] \u8868\u793a\u7b2c i \u6b21\u6d88\u9664\u64cd\u4f5c\u5bf9\u5e94\u6389\u843d\u7684\u7816\u5757\u6570\u76ee\u3002

    \n\n

    \u6ce8\u610f\uff0c\u6d88\u9664\u53ef\u80fd\u6307\u5411\u662f\u6ca1\u6709\u7816\u5757\u7684\u7a7a\u767d\u4f4d\u7f6e\uff0c\u5982\u679c\u53d1\u751f\u8fd9\u79cd\u60c5\u51b5\uff0c\u5219\u6ca1\u6709\u7816\u5757\u6389\u843d\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1agrid = [[1,0,0,0],[1,1,1,0]], hits = [[1,0]]\n\u8f93\u51fa\uff1a[2]\n\u89e3\u91ca\uff1a\n\u7f51\u683c\u5f00\u59cb\u4e3a\uff1a\n[[1,0,0,0]\uff0c\n [1,1,1,0]]\n\u6d88\u9664 (1,0) \u5904\u52a0\u7c97\u7684\u7816\u5757\uff0c\u5f97\u5230\u7f51\u683c\uff1a\n[[1,0,0,0]\n [0,1,1,0]]\n\u4e24\u4e2a\u52a0\u7c97\u7684\u7816\u4e0d\u518d\u7a33\u5b9a\uff0c\u56e0\u4e3a\u5b83\u4eec\u4e0d\u518d\u4e0e\u9876\u90e8\u76f8\u8fde\uff0c\u4e5f\u4e0d\u518d\u4e0e\u53e6\u4e00\u4e2a\u7a33\u5b9a\u7684\u7816\u76f8\u90bb\uff0c\u56e0\u6b64\u5b83\u4eec\u5c06\u6389\u843d\u3002\u5f97\u5230\u7f51\u683c\uff1a\n[[1,0,0,0],\n [0,0,0,0]]\n\u56e0\u6b64\uff0c\u7ed3\u679c\u4e3a [2] \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1agrid = [[1,0,0,0],[1,1,0,0]], hits = [[1,1],[1,0]]\n\u8f93\u51fa\uff1a[0,0]\n\u89e3\u91ca\uff1a\n\u7f51\u683c\u5f00\u59cb\u4e3a\uff1a\n[[1,0,0,0],\n [1,1,0,0]]\n\u6d88\u9664 (1,1) \u5904\u52a0\u7c97\u7684\u7816\u5757\uff0c\u5f97\u5230\u7f51\u683c\uff1a\n[[1,0,0,0],\n [1,0,0,0]]\n\u5269\u4e0b\u7684\u7816\u90fd\u5f88\u7a33\u5b9a\uff0c\u6240\u4ee5\u4e0d\u4f1a\u6389\u843d\u3002\u7f51\u683c\u4fdd\u6301\u4e0d\u53d8\uff1a\n[[1,0,0,0], \n [1,0,0,0]]\n\u63a5\u4e0b\u6765\u6d88\u9664 (1,0) \u5904\u52a0\u7c97\u7684\u7816\u5757\uff0c\u5f97\u5230\u7f51\u683c\uff1a\n[[1,0,0,0],\n [0,0,0,0]]\n\u5269\u4e0b\u7684\u7816\u5757\u4ecd\u7136\u662f\u7a33\u5b9a\u7684\uff0c\u6240\u4ee5\u4e0d\u4f1a\u6709\u7816\u5757\u6389\u843d\u3002\n\u56e0\u6b64\uff0c\u7ed3\u679c\u4e3a [0,0] \u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= m, n <= 200
    • \n\t
    • grid[i][j] \u4e3a 0 \u6216 1
    • \n\t
    • 1 <= hits.length <= 4 * 104
    • \n\t
    • hits[i].length == 2
    • \n\t
    • 0 <= xi\u00a0<= m - 1
    • \n\t
    • 0 <=\u00a0yi <= n - 1
    • \n\t
    • \u6240\u6709 (xi, yi) \u4e92\u4e0d\u76f8\u540c
    • \n
    \n", "tags_en": ["Union Find"], "tags_cn": ["\u5e76\u67e5\u96c6"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector hitBricks(vector>& grid, vector>& hits) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] hitBricks(int[][] grid, int[][] hits) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def hitBricks(self, grid, hits):\n \"\"\"\n :type grid: List[List[int]]\n :type hits: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def hitBricks(self, grid: List[List[int]], hits: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* hitBricks(int** grid, int gridSize, int* gridColSize, int** hits, int hitsSize, int* hitsColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] HitBricks(int[][] grid, int[][] hits) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @param {number[][]} hits\n * @return {number[]}\n */\nvar hitBricks = function(grid, hits) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @param {Integer[][]} hits\n# @return {Integer[]}\ndef hit_bricks(grid, hits)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func hitBricks(_ grid: [[Int]], _ hits: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func hitBricks(grid [][]int, hits [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def hitBricks(grid: Array[Array[Int]], hits: Array[Array[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun hitBricks(grid: Array, hits: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn hit_bricks(grid: Vec>, hits: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @param Integer[][] $hits\n * @return Integer[]\n */\n function hitBricks($grid, $hits) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function hitBricks(grid: number[][], hits: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (hit-bricks grid hits)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0803](https://leetcode-cn.com/problems/bricks-falling-when-hit)", "[\u6253\u7816\u5757](/solution/0800-0899/0803.Bricks%20Falling%20When%20Hit/README.md)", "`\u5e76\u67e5\u96c6`", "\u56f0\u96be", ""], "md_table_row_en": ["[0803](https://leetcode.com/problems/bricks-falling-when-hit)", "[Bricks Falling When Hit](/solution/0800-0899/0803.Bricks%20Falling%20When%20Hit/README_EN.md)", "`Union Find`", "Hard", ""]}, {"question_id": "0820", "frontend_question_id": "0802", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-eventual-safe-states", "url_en": "https://leetcode.com/problems/find-eventual-safe-states", "relative_path_cn": "/solution/0800-0899/0802.Find%20Eventual%20Safe%20States/README.md", "relative_path_en": "/solution/0800-0899/0802.Find%20Eventual%20Safe%20States/README_EN.md", "title_cn": "\u627e\u5230\u6700\u7ec8\u7684\u5b89\u5168\u72b6\u6001", "title_en": "Find Eventual Safe States", "question_title_slug": "find-eventual-safe-states", "content_en": "

    We start at some node in a directed graph, and every turn, we walk along a directed edge of the graph. If we reach a terminal node (that is, it has no outgoing directed edges), we stop.

    \n\n

    We define a starting node to be safe if we must eventually walk to a terminal node. More specifically, there is a natural number k, so that we must have stopped at a terminal node in less than k steps for any choice of where to walk.

    \n\n

    Return an array containing all the safe nodes of the graph. The answer should be sorted in ascending order.

    \n\n

    The directed graph has n nodes with labels from 0 to n - 1, where n is the length of graph. The graph is given in the following form: graph[i] is a list of labels j such that (i, j) is a directed edge of the graph, going from node i to node j.

    \n\n

     

    \n

    Example 1:

    \n\"Illustration\n
    \nInput: graph = [[1,2],[2,3],[5],[0],[5],[],[]]\nOutput: [2,4,5,6]\nExplanation: The given graph is shown above.\n
    \n\n

    Example 2:

    \n\n
    \nInput: graph = [[1,2,3,4],[1,2],[3,4],[0,4],[]]\nOutput: [4]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == graph.length
    • \n\t
    • 1 <= n <= 104
    • \n\t
    • 0 <= graph[i].legnth <= n
    • \n\t
    • graph[i] is sorted in a strictly increasing order.
    • \n\t
    • The graph may contain self-loops.
    • \n\t
    • The number of edges in the graph will be in the range [1, 4 * 104].
    • \n
    \n", "content_cn": "

    \u5728\u6709\u5411\u56fe\u4e2d\uff0c\u4ece\u67d0\u4e2a\u8282\u70b9\u548c\u6bcf\u4e2a\u8f6c\u5411\u5904\u5f00\u59cb\u51fa\u53d1\uff0c\u6cbf\u7740\u56fe\u7684\u6709\u5411\u8fb9\u8d70\u3002\u5982\u679c\u5230\u8fbe\u7684\u8282\u70b9\u662f\u7ec8\u70b9\uff08\u5373\u5b83\u6ca1\u6709\u8fde\u51fa\u7684\u6709\u5411\u8fb9\uff09\uff0c\u5219\u505c\u6b62\u3002

    \n\n

    \u5982\u679c\u4ece\u8d77\u59cb\u8282\u70b9\u51fa\u53d1\uff0c\u6700\u540e\u5fc5\u7136\u80fd\u8d70\u5230\u7ec8\u70b9\uff0c\u5c31\u8ba4\u4e3a\u8d77\u59cb\u8282\u70b9\u662f \u6700\u7ec8\u5b89\u5168 \u7684\u3002\u66f4\u5177\u4f53\u5730\u8bf4\uff0c\u5bf9\u4e8e\u6700\u7ec8\u5b89\u5168\u7684\u8d77\u59cb\u8282\u70b9\u800c\u8a00\uff0c\u5b58\u5728\u4e00\u4e2a\u81ea\u7136\u6570 k \uff0c\u65e0\u8bba\u9009\u62e9\u6cbf\u54ea\u6761\u6709\u5411\u8fb9\u884c\u8d70 \uff0c\u8d70\u4e86\u4e0d\u5230 k \u6b65\u540e\u5fc5\u80fd\u505c\u6b62\u5728\u4e00\u4e2a\u7ec8\u70b9\u4e0a\u3002

    \n\n

    \u8fd4\u56de\u4e00\u4e2a\u7531\u56fe\u4e2d\u6240\u6709\u6700\u7ec8\u5b89\u5168\u7684\u8d77\u59cb\u8282\u70b9\u7ec4\u6210\u7684\u6570\u7ec4\u4f5c\u4e3a\u7b54\u6848\u3002\u7b54\u6848\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u5e94\u5f53\u6309 \u5347\u5e8f \u6392\u5217\u3002

    \n\n

    \u8be5\u6709\u5411\u56fe\u6709 n \u4e2a\u8282\u70b9\uff0c\u6309 0 \u5230 n - 1 \u7f16\u53f7\uff0c\u5176\u4e2d n \u662f\u00a0graph\u00a0\u7684\u8282\u70b9\u6570\u3002\u56fe\u4ee5\u4e0b\u8ff0\u5f62\u5f0f\u7ed9\u51fa\uff1agraph[i] \u662f\u7f16\u53f7 j \u8282\u70b9\u7684\u4e00\u4e2a\u5217\u8868\uff0c\u6ee1\u8db3 (i, j) \u662f\u56fe\u7684\u4e00\u6761\u6709\u5411\u8fb9\u3002

    \n\n

    \u00a0

    \n\n
    \n
    \n

    \u793a\u4f8b 1\uff1a

    \n\"Illustration\n
    \n\u8f93\u5165\uff1agraph = [[1,2],[2,3],[5],[0],[5],[],[]]\n\u8f93\u51fa\uff1a[2,4,5,6]\n\u89e3\u91ca\uff1a\u793a\u610f\u56fe\u5982\u4e0a\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1agraph = [[1,2,3,4],[1,2],[3,4],[0,4],[]]\n\u8f93\u51fa\uff1a[4]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == graph.length
    • \n\t
    • 1 <= n <= 104
    • \n\t
    • 0 <= graph[i].legnth <= n
    • \n\t
    • graph[i] \u6309\u4e25\u683c\u9012\u589e\u987a\u5e8f\u6392\u5217\u3002
    • \n\t
    • \u56fe\u4e2d\u53ef\u80fd\u5305\u542b\u81ea\u73af\u3002
    • \n\t
    • \u56fe\u4e2d\u8fb9\u7684\u6570\u76ee\u5728\u8303\u56f4 [1, 4 * 104] \u5185\u3002
    • \n
    \n
    \n
    \n", "tags_en": ["Depth-first Search", "Graph"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector eventualSafeNodes(vector>& graph) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List eventualSafeNodes(int[][] graph) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def eventualSafeNodes(self, graph):\n \"\"\"\n :type graph: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def eventualSafeNodes(self, graph: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* eventualSafeNodes(int** graph, int graphSize, int* graphColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList EventualSafeNodes(int[][] graph) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} graph\n * @return {number[]}\n */\nvar eventualSafeNodes = function(graph) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} graph\n# @return {Integer[]}\ndef eventual_safe_nodes(graph)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func eventualSafeNodes(_ graph: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func eventualSafeNodes(graph [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def eventualSafeNodes(graph: Array[Array[Int]]): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun eventualSafeNodes(graph: Array): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn eventual_safe_nodes(graph: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $graph\n * @return Integer[]\n */\n function eventualSafeNodes($graph) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function eventualSafeNodes(graph: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (eventual-safe-nodes graph)\n (-> (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0802](https://leetcode-cn.com/problems/find-eventual-safe-states)", "[\u627e\u5230\u6700\u7ec8\u7684\u5b89\u5168\u72b6\u6001](/solution/0800-0899/0802.Find%20Eventual%20Safe%20States/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u56fe`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0802](https://leetcode.com/problems/find-eventual-safe-states)", "[Find Eventual Safe States](/solution/0800-0899/0802.Find%20Eventual%20Safe%20States/README_EN.md)", "`Depth-first Search`,`Graph`", "Medium", ""]}, {"question_id": "0819", "frontend_question_id": "0801", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-swaps-to-make-sequences-increasing", "url_en": "https://leetcode.com/problems/minimum-swaps-to-make-sequences-increasing", "relative_path_cn": "/solution/0800-0899/0801.Minimum%20Swaps%20To%20Make%20Sequences%20Increasing/README.md", "relative_path_en": "/solution/0800-0899/0801.Minimum%20Swaps%20To%20Make%20Sequences%20Increasing/README_EN.md", "title_cn": "\u4f7f\u5e8f\u5217\u9012\u589e\u7684\u6700\u5c0f\u4ea4\u6362\u6b21\u6570", "title_en": "Minimum Swaps To Make Sequences Increasing", "question_title_slug": "minimum-swaps-to-make-sequences-increasing", "content_en": "

    We have two integer sequences nums1 and nums2 of the same non-zero length.

    \n\n

    We are allowed to swap elements nums1[i] and nums2[i]. Note that both elements are in the same index position in their respective sequences.

    \n\n

    At the end of some number of swaps, nums1 and nums2 are both strictly increasing. (An array A is strictly increasing if and only if A[0] < A[1] < A[2] < ... < A[A.length - 1].)

    \n\n

    Given nums1 and nums2, return the minimum number of swaps to make both sequences strictly increasing. It is guaranteed that the given input always makes it possible.

    \n\n
    \nExample:\nInput: nums1 = [1,3,5,4], nums2 = [1,2,3,7]\nOutput: 1\nExplanation: \nSwap nums1[3] and nums2[3].  Then the sequences are:\nnums1 = [1, 3, 5, 7] and nums2 = [1, 2, 3, 4]\nwhich are both strictly increasing.\n
    \n\n

    Note:

    \n\n
      \n\t
    • nums1, nums2 are arrays with the same length, and that length will be in the range [1, 1000].
    • \n\t
    • nums1[i], nums2[i] are integer values in the range [0, 2000].
    • \n
    \n", "content_cn": "

    \u6211\u4eec\u6709\u4e24\u4e2a\u957f\u5ea6\u76f8\u7b49\u4e14\u4e0d\u4e3a\u7a7a\u7684\u6574\u578b\u6570\u7ec4 A \u548c B \u3002

    \n\n

    \u6211\u4eec\u53ef\u4ee5\u4ea4\u6362 A[i] \u548c B[i] \u7684\u5143\u7d20\u3002\u6ce8\u610f\u8fd9\u4e24\u4e2a\u5143\u7d20\u5728\u5404\u81ea\u7684\u5e8f\u5217\u4e2d\u5e94\u8be5\u5904\u4e8e\u76f8\u540c\u7684\u4f4d\u7f6e\u3002

    \n\n

    \u5728\u4ea4\u6362\u8fc7\u4e00\u4e9b\u5143\u7d20\u4e4b\u540e\uff0c\u6570\u7ec4 A \u548c B \u90fd\u5e94\u8be5\u662f\u4e25\u683c\u9012\u589e\u7684\uff08\u6570\u7ec4\u4e25\u683c\u9012\u589e\u7684\u6761\u4ef6\u4ec5\u4e3aA[0] < A[1] < A[2] < ... < A[A.length - 1]\uff09\u3002

    \n\n

    \u7ed9\u5b9a\u6570\u7ec4 A \u548c B \uff0c\u8bf7\u8fd4\u56de\u4f7f\u5f97\u4e24\u4e2a\u6570\u7ec4\u5747\u4fdd\u6301\u4e25\u683c\u9012\u589e\u72b6\u6001\u7684\u6700\u5c0f\u4ea4\u6362\u6b21\u6570\u3002\u5047\u8bbe\u7ed9\u5b9a\u7684\u8f93\u5165\u603b\u662f\u6709\u6548\u7684\u3002

    \n\n
    \n\u793a\u4f8b:\n\u8f93\u5165: A = [1,3,5,4], B = [1,2,3,7]\n\u8f93\u51fa: 1\n\u89e3\u91ca: \n\u4ea4\u6362 A[3] \u548c B[3] \u540e\uff0c\u4e24\u4e2a\u6570\u7ec4\u5982\u4e0b:\nA = [1, 3, 5, 7] \uff0c B = [1, 2, 3, 4]\n\u4e24\u4e2a\u6570\u7ec4\u5747\u4e3a\u4e25\u683c\u9012\u589e\u7684\u3002
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    • A, B \u4e24\u4e2a\u6570\u7ec4\u7684\u957f\u5ea6\u603b\u662f\u76f8\u7b49\u7684\uff0c\u4e14\u957f\u5ea6\u7684\u8303\u56f4\u4e3a [1, 1000]\u3002
    • \n\t
    • A[i], B[i] \u5747\u4e3a [0, 2000]\u533a\u95f4\u5185\u7684\u6574\u6570\u3002
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minSwap(vector& nums1, vector& nums2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minSwap(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minSwap(self, nums1, nums2):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minSwap(self, nums1: List[int], nums2: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minSwap(int* nums1, int nums1Size, int* nums2, int nums2Size){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinSwap(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums1\n * @param {number[]} nums2\n * @return {number}\n */\nvar minSwap = function(nums1, nums2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums1\n# @param {Integer[]} nums2\n# @return {Integer}\ndef min_swap(nums1, nums2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minSwap(_ nums1: [Int], _ nums2: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minSwap(nums1 []int, nums2 []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minSwap(nums1: Array[Int], nums2: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minSwap(nums1: IntArray, nums2: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_swap(nums1: Vec, nums2: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums1\n * @param Integer[] $nums2\n * @return Integer\n */\n function minSwap($nums1, $nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minSwap(nums1: number[], nums2: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-swap nums1 nums2)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0801](https://leetcode-cn.com/problems/minimum-swaps-to-make-sequences-increasing)", "[\u4f7f\u5e8f\u5217\u9012\u589e\u7684\u6700\u5c0f\u4ea4\u6362\u6b21\u6570](/solution/0800-0899/0801.Minimum%20Swaps%20To%20Make%20Sequences%20Increasing/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0801](https://leetcode.com/problems/minimum-swaps-to-make-sequences-increasing)", "[Minimum Swaps To Make Sequences Increasing](/solution/0800-0899/0801.Minimum%20Swaps%20To%20Make%20Sequences%20Increasing/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0818", "frontend_question_id": "0800", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/similar-rgb-color", "url_en": "https://leetcode.com/problems/similar-rgb-color", "relative_path_cn": "/solution/0800-0899/0800.Similar%20RGB%20Color/README.md", "relative_path_en": "/solution/0800-0899/0800.Similar%20RGB%20Color/README_EN.md", "title_cn": "\u76f8\u4f3c RGB \u989c\u8272", "title_en": "Similar RGB Color", "question_title_slug": "similar-rgb-color", "content_en": "

    In the following, every capital letter represents some hexadecimal digit from 0 to f.

    \r\n\r\n

    The red-green-blue color "#AABBCC" can be written as "#ABC" in shorthand.  For example, "#15c" is shorthand for the color "#1155cc".

    \r\n\r\n

    Now, say the similarity between two colors "#ABCDEF" and "#UVWXYZ" is -(AB - UV)^2 - (CD - WX)^2 - (EF - YZ)^2.

    \r\n\r\n

    Given the color "#ABCDEF", return a 7 character color that is most similar to #ABCDEF, and has a shorthand (that is, it can be represented as some "#XYZ"

    \r\n\r\n
    \r\nExample 1:\r\nInput: color = "#09f166"\r\nOutput: "#11ee66"\r\nExplanation:  \r\nThe similarity is -(0x09 - 0x11)^2 -(0xf1 - 0xee)^2 - (0x66 - 0x66)^2 = -64 -9 -0 = -73.\r\nThis is the highest among any shorthand color.\r\n
    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    • color is a string of length 7.
    • \r\n\t
    • color is a valid RGB color: for i > 0, color[i] is a hexadecimal digit from 0 to f
    • \r\n\t
    • Any answer which has the same (highest) similarity as the best answer will be accepted.
    • \r\n\t
    • All inputs and outputs should use lowercase letters, and the output is 7 characters.
    • \r\n
    \r\n", "content_cn": "

    RGB \u989c\u8272\u7528\u5341\u516d\u8fdb\u5236\u6765\u8868\u793a\u7684\u8bdd\uff0c\u6bcf\u4e2a\u5927\u5199\u5b57\u6bcd\u90fd\u4ee3\u8868\u4e86\u67d0\u4e2a\u4ece 0 \u5230 f \u7684 16 \u8fdb\u5236\u6570\u3002

    \n\n

    RGB \u989c\u8272 "#AABBCC" \u53ef\u4ee5\u7b80\u5199\u6210 "#ABC" \u3002\u4f8b\u5982\uff0c"#15c" \u5176\u5b9e\u662f "#1155cc" \u7684\u7b80\u5199\u3002

    \n\n

    \u73b0\u5728\uff0c\u5047\u5982\u6211\u4eec\u5206\u522b\u5b9a\u4e49\u4e24\u4e2a\u989c\u8272 "#ABCDEF" \u548c "#UVWXYZ"\uff0c\u5219\u4ed6\u4eec\u7684\u76f8\u4f3c\u5ea6\u53ef\u4ee5\u901a\u8fc7\u8fd9\u4e2a\u8868\u8fbe\u5f0f -(AB - UV)^2 - (CD - WX)^2 - (EF - YZ)^2 \u6765\u8ba1\u7b97\u3002

    \n\n

    \u90a3\u4e48\u7ed9\u5b9a\u989c\u8272 "#ABCDEF"\uff0c\u8bf7\u4f60\u8fd4\u56de\u4e00\u4e2a\u4e0e #ABCDEF \u6700\u76f8\u4f3c\u7684 7 \u4e2a\u5b57\u7b26\u4ee3\u8868\u7684\u989c\u8272\uff0c\u5e76\u4e14\u5b83\u662f\u53ef\u4ee5\u88ab\u7b80\u5199\u5f62\u5f0f\u8868\u8fbe\u7684\u3002\uff08\u6bd4\u5982\uff0c\u53ef\u4ee5\u8868\u793a\u6210\u7c7b\u4f3c "#XYZ" \u7684\u5f62\u5f0f\uff09

    \n\n
    \u793a\u4f8b 1\uff1a\n\u8f93\u5165\uff1acolor = "#09f166"\n\u8f93\u51fa\uff1a"#11ee66"\n\u89e3\u91ca\uff1a \n\u56e0\u4e3a\u76f8\u4f3c\u5ea6\u8ba1\u7b97\u5f97\u51fa -(0x09 - 0x11)^2 -(0xf1 - 0xee)^2 - (0x66 - 0x66)^2 = -64 -9 -0 = -73\n\u8fd9\u5df2\u7ecf\u662f\u6240\u6709\u53ef\u4ee5\u7b80\u5199\u7684\u989c\u8272\u4e2d\u6700\u76f8\u4f3c\u7684\u4e86\n
    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    • color \u662f\u4e00\u4e2a\u957f\u5ea6\u4e3a 7 \u7684\u5b57\u7b26\u4e32
    • \n\t
    • color \u662f\u4e00\u4e2a\u6709\u6548\u7684 RGB \u989c\u8272\uff1a\u5bf9\u4e8e\u4ecd\u548c i > 0\uff0ccolor[i] \u90fd\u662f\u4e00\u4e2a\u5728 0 \u5230 f \u8303\u56f4\u7684 16 \u8fdb\u5236\u6570
    • \n\t
    • \u5047\u5982\u7b54\u6848\u5177\u6709\u76f8\u540c\u7684\uff08\u6700\u5927\uff09\u76f8\u4f3c\u5ea6\u7684\u8bdd\uff0c\u90fd\u662f\u53ef\u4ee5\u88ab\u63a5\u53d7\u7684
    • \n\t
    • \u6240\u6709\u8f93\u5165\u3001\u8f93\u51fa\u90fd\u5fc5\u987b\u4f7f\u7528\u5c0f\u5199\u5b57\u6bcd\uff0c\u5e76\u4e14\u8f93\u51fa\u4e3a 7 \u4e2a\u5b57\u7b26
    • \n
    \n", "tags_en": ["Math", "String"], "tags_cn": ["\u6570\u5b66", "\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string similarRGB(string color) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String similarRGB(String color) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def similarRGB(self, color):\n \"\"\"\n :type color: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def similarRGB(self, color: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * similarRGB(char * color){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string SimilarRGB(string color) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} color\n * @return {string}\n */\nvar similarRGB = function(color) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} color\n# @return {String}\ndef similar_rgb(color)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func similarRGB(_ color: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func similarRGB(color string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def similarRGB(color: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun similarRGB(color: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn similar_rgb(color: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $color\n * @return String\n */\n function similarRGB($color) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function similarRGB(color: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (similar-rgb color)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0800](https://leetcode-cn.com/problems/similar-rgb-color)", "[\u76f8\u4f3c RGB \u989c\u8272](/solution/0800-0899/0800.Similar%20RGB%20Color/README.md)", "`\u6570\u5b66`,`\u5b57\u7b26\u4e32`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0800](https://leetcode.com/problems/similar-rgb-color)", "[Similar RGB Color](/solution/0800-0899/0800.Similar%20RGB%20Color/README_EN.md)", "`Math`,`String`", "Easy", "\ud83d\udd12"]}, {"question_id": "0817", "frontend_question_id": "0706", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/design-hashmap", "url_en": "https://leetcode.com/problems/design-hashmap", "relative_path_cn": "/solution/0700-0799/0706.Design%20HashMap/README.md", "relative_path_en": "/solution/0700-0799/0706.Design%20HashMap/README_EN.md", "title_cn": "\u8bbe\u8ba1\u54c8\u5e0c\u6620\u5c04", "title_en": "Design HashMap", "question_title_slug": "design-hashmap", "content_en": "

    Design a HashMap without using any built-in hash table libraries.

    \n\n

    Implement the MyHashMap class:

    \n\n
      \n\t
    • MyHashMap() initializes the object with an empty map.
    • \n\t
    • void put(int key, int value) inserts a (key, value) pair into the HashMap. If the key already exists in the map, update the corresponding value.
    • \n\t
    • int get(int key) returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key.
    • \n\t
    • void remove(key) removes the key and its corresponding value if the map contains the mapping for the key.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["MyHashMap", "put", "put", "get", "get", "put", "get", "remove", "get"]\n[[], [1, 1], [2, 2], [1], [3], [2, 1], [2], [2], [2]]\nOutput\n[null, null, null, 1, -1, null, 1, null, -1]\n\nExplanation\nMyHashMap myHashMap = new MyHashMap();\nmyHashMap.put(1, 1); // The map is now [[1,1]]\nmyHashMap.put(2, 2); // The map is now [[1,1], [2,2]]\nmyHashMap.get(1);    // return 1, The map is now [[1,1], [2,2]]\nmyHashMap.get(3);    // return -1 (i.e., not found), The map is now [[1,1], [2,2]]\nmyHashMap.put(2, 1); // The map is now [[1,1], [2,1]] (i.e., update the existing value)\nmyHashMap.get(2);    // return 1, The map is now [[1,1], [2,1]]\nmyHashMap.remove(2); // remove the mapping for 2, The map is now [[1,1]]\nmyHashMap.get(2);    // return -1 (i.e., not found), The map is now [[1,1]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= key, value <= 106
    • \n\t
    • At most 104 calls will be made to put, get, and remove.
    • \n
    \n", "content_cn": "

    \u4e0d\u4f7f\u7528\u4efb\u4f55\u5185\u5efa\u7684\u54c8\u5e0c\u8868\u5e93\u8bbe\u8ba1\u4e00\u4e2a\u54c8\u5e0c\u6620\u5c04\uff08HashMap\uff09\u3002

    \n\n

    \u5b9e\u73b0 MyHashMap \u7c7b\uff1a

    \n\n
      \n\t
    • MyHashMap() \u7528\u7a7a\u6620\u5c04\u521d\u59cb\u5316\u5bf9\u8c61
    • \n\t
    • void put(int key, int value) \u5411 HashMap \u63d2\u5165\u4e00\u4e2a\u952e\u503c\u5bf9 (key, value) \u3002\u5982\u679c key \u5df2\u7ecf\u5b58\u5728\u4e8e\u6620\u5c04\u4e2d\uff0c\u5219\u66f4\u65b0\u5176\u5bf9\u5e94\u7684\u503c value \u3002
    • \n\t
    • int get(int key) \u8fd4\u56de\u7279\u5b9a\u7684 key \u6240\u6620\u5c04\u7684 value \uff1b\u5982\u679c\u6620\u5c04\u4e2d\u4e0d\u5305\u542b key \u7684\u6620\u5c04\uff0c\u8fd4\u56de -1 \u3002
    • \n\t
    • void remove(key) \u5982\u679c\u6620\u5c04\u4e2d\u5b58\u5728 key \u7684\u6620\u5c04\uff0c\u5219\u79fb\u9664 key \u548c\u5b83\u6240\u5bf9\u5e94\u7684 value \u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\n[\"MyHashMap\", \"put\", \"put\", \"get\", \"get\", \"put\", \"get\", \"remove\", \"get\"]\n[[], [1, 1], [2, 2], [1], [3], [2, 1], [2], [2], [2]]\n\u8f93\u51fa\uff1a\n[null, null, null, 1, -1, null, 1, null, -1]\n\n\u89e3\u91ca\uff1a\nMyHashMap myHashMap = new MyHashMap();\nmyHashMap.put(1, 1); // myHashMap \u73b0\u5728\u4e3a [[1,1]]\nmyHashMap.put(2, 2); // myHashMap \u73b0\u5728\u4e3a [[1,1], [2,2]]\nmyHashMap.get(1);    // \u8fd4\u56de 1 \uff0cmyHashMap \u73b0\u5728\u4e3a [[1,1], [2,2]]\nmyHashMap.get(3);    // \u8fd4\u56de -1\uff08\u672a\u627e\u5230\uff09\uff0cmyHashMap \u73b0\u5728\u4e3a [[1,1], [2,2]]\nmyHashMap.put(2, 1); // myHashMap \u73b0\u5728\u4e3a [[1,1], [2,1]]\uff08\u66f4\u65b0\u5df2\u6709\u7684\u503c\uff09\nmyHashMap.get(2);    // \u8fd4\u56de 1 \uff0cmyHashMap \u73b0\u5728\u4e3a [[1,1], [2,1]]\nmyHashMap.remove(2); // \u5220\u9664\u952e\u4e3a 2 \u7684\u6570\u636e\uff0cmyHashMap \u73b0\u5728\u4e3a [[1,1]]\nmyHashMap.get(2);    // \u8fd4\u56de -1\uff08\u672a\u627e\u5230\uff09\uff0cmyHashMap \u73b0\u5728\u4e3a [[1,1]]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= key, value <= 106
    • \n\t
    • \u6700\u591a\u8c03\u7528 104 \u6b21 put\u3001get \u548c remove \u65b9\u6cd5
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u80fd\u5426\u4e0d\u4f7f\u7528\u5185\u7f6e\u7684 HashMap \u5e93\u89e3\u51b3\u6b64\u95ee\u9898\uff1f

    \n", "tags_en": ["Design", "Hash Table"], "tags_cn": ["\u8bbe\u8ba1", "\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class MyHashMap {\npublic:\n /** Initialize your data structure here. */\n MyHashMap() {\n\n }\n \n /** value will always be non-negative. */\n void put(int key, int value) {\n\n }\n \n /** Returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key */\n int get(int key) {\n\n }\n \n /** Removes the mapping of the specified value key if this map contains a mapping for the key */\n void remove(int key) {\n\n }\n};\n\n/**\n * Your MyHashMap object will be instantiated and called as such:\n * MyHashMap* obj = new MyHashMap();\n * obj->put(key,value);\n * int param_2 = obj->get(key);\n * obj->remove(key);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class MyHashMap {\n\n /** Initialize your data structure here. */\n public MyHashMap() {\n\n }\n \n /** value will always be non-negative. */\n public void put(int key, int value) {\n\n }\n \n /** Returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key */\n public int get(int key) {\n\n }\n \n /** Removes the mapping of the specified value key if this map contains a mapping for the key */\n public void remove(int key) {\n\n }\n}\n\n/**\n * Your MyHashMap object will be instantiated and called as such:\n * MyHashMap obj = new MyHashMap();\n * obj.put(key,value);\n * int param_2 = obj.get(key);\n * obj.remove(key);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class MyHashMap(object):\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def put(self, key, value):\n \"\"\"\n value will always be non-negative.\n :type key: int\n :type value: int\n :rtype: None\n \"\"\"\n\n\n def get(self, key):\n \"\"\"\n Returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key\n :type key: int\n :rtype: int\n \"\"\"\n\n\n def remove(self, key):\n \"\"\"\n Removes the mapping of the specified value key if this map contains a mapping for the key\n :type key: int\n :rtype: None\n \"\"\"\n\n\n\n# Your MyHashMap object will be instantiated and called as such:\n# obj = MyHashMap()\n# obj.put(key,value)\n# param_2 = obj.get(key)\n# obj.remove(key)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class MyHashMap:\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def put(self, key: int, value: int) -> None:\n \"\"\"\n value will always be non-negative.\n \"\"\"\n\n\n def get(self, key: int) -> int:\n \"\"\"\n Returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key\n \"\"\"\n\n\n def remove(self, key: int) -> None:\n \"\"\"\n Removes the mapping of the specified value key if this map contains a mapping for the key\n \"\"\"\n\n\n\n# Your MyHashMap object will be instantiated and called as such:\n# obj = MyHashMap()\n# obj.put(key,value)\n# param_2 = obj.get(key)\n# obj.remove(key)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} MyHashMap;\n\n/** Initialize your data structure here. */\n\nMyHashMap* myHashMapCreate() {\n\n}\n\n/** value will always be non-negative. */\nvoid myHashMapPut(MyHashMap* obj, int key, int value) {\n\n}\n\n/** Returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key */\nint myHashMapGet(MyHashMap* obj, int key) {\n\n}\n\n/** Removes the mapping of the specified value key if this map contains a mapping for the key */\nvoid myHashMapRemove(MyHashMap* obj, int key) {\n\n}\n\nvoid myHashMapFree(MyHashMap* obj) {\n\n}\n\n/**\n * Your MyHashMap struct will be instantiated and called as such:\n * MyHashMap* obj = myHashMapCreate();\n * myHashMapPut(obj, key, value);\n \n * int param_2 = myHashMapGet(obj, key);\n \n * myHashMapRemove(obj, key);\n \n * myHashMapFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class MyHashMap {\n\n /** Initialize your data structure here. */\n public MyHashMap() {\n\n }\n \n /** value will always be non-negative. */\n public void Put(int key, int value) {\n\n }\n \n /** Returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key */\n public int Get(int key) {\n\n }\n \n /** Removes the mapping of the specified value key if this map contains a mapping for the key */\n public void Remove(int key) {\n\n }\n}\n\n/**\n * Your MyHashMap object will be instantiated and called as such:\n * MyHashMap obj = new MyHashMap();\n * obj.Put(key,value);\n * int param_2 = obj.Get(key);\n * obj.Remove(key);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Initialize your data structure here.\n */\nvar MyHashMap = function() {\n\n};\n\n/**\n * value will always be non-negative. \n * @param {number} key \n * @param {number} value\n * @return {void}\n */\nMyHashMap.prototype.put = function(key, value) {\n\n};\n\n/**\n * Returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key \n * @param {number} key\n * @return {number}\n */\nMyHashMap.prototype.get = function(key) {\n\n};\n\n/**\n * Removes the mapping of the specified value key if this map contains a mapping for the key \n * @param {number} key\n * @return {void}\n */\nMyHashMap.prototype.remove = function(key) {\n\n};\n\n/**\n * Your MyHashMap object will be instantiated and called as such:\n * var obj = new MyHashMap()\n * obj.put(key,value)\n * var param_2 = obj.get(key)\n * obj.remove(key)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class MyHashMap\n\n=begin\n Initialize your data structure here.\n=end\n def initialize()\n\n end\n\n\n=begin\n value will always be non-negative.\n :type key: Integer\n :type value: Integer\n :rtype: Void\n=end\n def put(key, value)\n\n end\n\n\n=begin\n Returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key\n :type key: Integer\n :rtype: Integer\n=end\n def get(key)\n\n end\n\n\n=begin\n Removes the mapping of the specified value key if this map contains a mapping for the key\n :type key: Integer\n :rtype: Void\n=end\n def remove(key)\n\n end\n\n\nend\n\n# Your MyHashMap object will be instantiated and called as such:\n# obj = MyHashMap.new()\n# obj.put(key, value)\n# param_2 = obj.get(key)\n# obj.remove(key)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass MyHashMap {\n\n /** Initialize your data structure here. */\n init() {\n\n }\n \n /** value will always be non-negative. */\n func put(_ key: Int, _ value: Int) {\n\n }\n \n /** Returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key */\n func get(_ key: Int) -> Int {\n\n }\n \n /** Removes the mapping of the specified value key if this map contains a mapping for the key */\n func remove(_ key: Int) {\n\n }\n}\n\n/**\n * Your MyHashMap object will be instantiated and called as such:\n * let obj = MyHashMap()\n * obj.put(key, value)\n * let ret_2: Int = obj.get(key)\n * obj.remove(key)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type MyHashMap struct {\n\n}\n\n\n/** Initialize your data structure here. */\nfunc Constructor() MyHashMap {\n\n}\n\n\n/** value will always be non-negative. */\nfunc (this *MyHashMap) Put(key int, value int) {\n\n}\n\n\n/** Returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key */\nfunc (this *MyHashMap) Get(key int) int {\n\n}\n\n\n/** Removes the mapping of the specified value key if this map contains a mapping for the key */\nfunc (this *MyHashMap) Remove(key int) {\n\n}\n\n\n/**\n * Your MyHashMap object will be instantiated and called as such:\n * obj := Constructor();\n * obj.Put(key,value);\n * param_2 := obj.Get(key);\n * obj.Remove(key);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class MyHashMap() {\n\n /** Initialize your data structure here. */\n\n\n /** value will always be non-negative. */\n def put(key: Int, value: Int) {\n\n }\n\n /** Returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key */\n def get(key: Int): Int = {\n\n }\n\n /** Removes the mapping of the specified value key if this map contains a mapping for the key */\n def remove(key: Int) {\n\n }\n\n}\n\n/**\n * Your MyHashMap object will be instantiated and called as such:\n * var obj = new MyHashMap()\n * obj.put(key,value)\n * var param_2 = obj.get(key)\n * obj.remove(key)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class MyHashMap() {\n\n /** Initialize your data structure here. */\n\n\n /** value will always be non-negative. */\n fun put(key: Int, value: Int) {\n\n }\n\n /** Returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key */\n fun get(key: Int): Int {\n\n }\n\n /** Removes the mapping of the specified value key if this map contains a mapping for the key */\n fun remove(key: Int) {\n\n }\n\n}\n\n/**\n * Your MyHashMap object will be instantiated and called as such:\n * var obj = MyHashMap()\n * obj.put(key,value)\n * var param_2 = obj.get(key)\n * obj.remove(key)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct MyHashMap {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl MyHashMap {\n\n /** Initialize your data structure here. */\n fn new() -> Self {\n\n }\n \n /** value will always be non-negative. */\n fn put(&self, key: i32, value: i32) {\n\n }\n \n /** Returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key */\n fn get(&self, key: i32) -> i32 {\n\n }\n \n /** Removes the mapping of the specified value key if this map contains a mapping for the key */\n fn remove(&self, key: i32) {\n\n }\n}\n\n/**\n * Your MyHashMap object will be instantiated and called as such:\n * let obj = MyHashMap::new();\n * obj.put(key, value);\n * let ret_2: i32 = obj.get(key);\n * obj.remove(key);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class MyHashMap {\n /**\n * Initialize your data structure here.\n */\n function __construct() {\n\n }\n\n /**\n * value will always be non-negative.\n * @param Integer $key\n * @param Integer $value\n * @return NULL\n */\n function put($key, $value) {\n\n }\n\n /**\n * Returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key\n * @param Integer $key\n * @return Integer\n */\n function get($key) {\n\n }\n\n /**\n * Removes the mapping of the specified value key if this map contains a mapping for the key\n * @param Integer $key\n * @return NULL\n */\n function remove($key) {\n\n }\n}\n\n/**\n * Your MyHashMap object will be instantiated and called as such:\n * $obj = MyHashMap();\n * $obj->put($key, $value);\n * $ret_2 = $obj->get($key);\n * $obj->remove($key);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class MyHashMap {\n constructor() {\n\n }\n\n put(key: number, value: number): void {\n\n }\n\n get(key: number): number {\n\n }\n\n remove(key: number): void {\n\n }\n}\n\n/**\n * Your MyHashMap object will be instantiated and called as such:\n * var obj = new MyHashMap()\n * obj.put(key,value)\n * var param_2 = obj.get(key)\n * obj.remove(key)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define my-hash-map%\n (class object%\n (super-new)\n (init-field)\n \n ; put : exact-integer? exact-integer? -> void?\n (define/public (put key value)\n\n )\n ; get : exact-integer? -> exact-integer?\n (define/public (get key)\n\n )\n ; remove : exact-integer? -> void?\n (define/public (remove key)\n\n )))\n\n;; Your my-hash-map% object will be instantiated and called as such:\n;; (define obj (new my-hash-map%))\n;; (send obj put key value)\n;; (define param_2 (send obj get key))\n;; (send obj remove key)", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0706](https://leetcode-cn.com/problems/design-hashmap)", "[\u8bbe\u8ba1\u54c8\u5e0c\u6620\u5c04](/solution/0700-0799/0706.Design%20HashMap/README.md)", "`\u8bbe\u8ba1`,`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0706](https://leetcode.com/problems/design-hashmap)", "[Design HashMap](/solution/0700-0799/0706.Design%20HashMap/README_EN.md)", "`Design`,`Hash Table`", "Easy", ""]}, {"question_id": "0816", "frontend_question_id": "0705", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/design-hashset", "url_en": "https://leetcode.com/problems/design-hashset", "relative_path_cn": "/solution/0700-0799/0705.Design%20HashSet/README.md", "relative_path_en": "/solution/0700-0799/0705.Design%20HashSet/README_EN.md", "title_cn": "\u8bbe\u8ba1\u54c8\u5e0c\u96c6\u5408", "title_en": "Design HashSet", "question_title_slug": "design-hashset", "content_en": "

    Design a HashSet without using any built-in hash table libraries.

    \n\n

    Implement MyHashSet class:

    \n\n
      \n\t
    • void add(key) Inserts the value key into the HashSet.
    • \n\t
    • bool contains(key) Returns whether the value key exists in the HashSet or not.
    • \n\t
    • void remove(key) Removes the value key in the HashSet. If key does not exist in the HashSet, do nothing.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["MyHashSet", "add", "add", "contains", "contains", "add", "contains", "remove", "contains"]\n[[], [1], [2], [1], [3], [2], [2], [2], [2]]\nOutput\n[null, null, null, true, false, null, true, null, false]\n\nExplanation\nMyHashSet myHashSet = new MyHashSet();\nmyHashSet.add(1);      // set = [1]\nmyHashSet.add(2);      // set = [1, 2]\nmyHashSet.contains(1); // return True\nmyHashSet.contains(3); // return False, (not found)\nmyHashSet.add(2);      // set = [1, 2]\nmyHashSet.contains(2); // return True\nmyHashSet.remove(2);   // set = [1]\nmyHashSet.contains(2); // return False, (already removed)
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= key <= 106
    • \n\t
    • At most 104 calls will be made to add, remove, and contains.
    • \n
    \n", "content_cn": "

    \u4e0d\u4f7f\u7528\u4efb\u4f55\u5185\u5efa\u7684\u54c8\u5e0c\u8868\u5e93\u8bbe\u8ba1\u4e00\u4e2a\u54c8\u5e0c\u96c6\u5408\uff08HashSet\uff09\u3002

    \n\n

    \u5b9e\u73b0 MyHashSet \u7c7b\uff1a

    \n\n
      \n\t
    • void add(key) \u5411\u54c8\u5e0c\u96c6\u5408\u4e2d\u63d2\u5165\u503c key \u3002
    • \n\t
    • bool contains(key) \u8fd4\u56de\u54c8\u5e0c\u96c6\u5408\u4e2d\u662f\u5426\u5b58\u5728\u8fd9\u4e2a\u503c key \u3002
    • \n\t
    • void remove(key) \u5c06\u7ed9\u5b9a\u503c key \u4ece\u54c8\u5e0c\u96c6\u5408\u4e2d\u5220\u9664\u3002\u5982\u679c\u54c8\u5e0c\u96c6\u5408\u4e2d\u6ca1\u6709\u8fd9\u4e2a\u503c\uff0c\u4ec0\u4e48\u4e5f\u4e0d\u505a\u3002
    • \n
    \n\u00a0\n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\n[\"MyHashSet\", \"add\", \"add\", \"contains\", \"contains\", \"add\", \"contains\", \"remove\", \"contains\"]\n[[], [1], [2], [1], [3], [2], [2], [2], [2]]\n\u8f93\u51fa\uff1a\n[null, null, null, true, false, null, true, null, false]\n\n\u89e3\u91ca\uff1a\nMyHashSet myHashSet = new MyHashSet();\nmyHashSet.add(1);      // set = [1]\nmyHashSet.add(2);      // set = [1, 2]\nmyHashSet.contains(1); // \u8fd4\u56de True\nmyHashSet.contains(3); // \u8fd4\u56de False \uff0c\uff08\u672a\u627e\u5230\uff09\nmyHashSet.add(2);      // set = [1, 2]\nmyHashSet.contains(2); // \u8fd4\u56de True\nmyHashSet.remove(2);   // set = [1]\nmyHashSet.contains(2); // \u8fd4\u56de False \uff0c\uff08\u5df2\u79fb\u9664\uff09
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= key <= 106
    • \n\t
    • \u6700\u591a\u8c03\u7528 104 \u6b21 add\u3001remove \u548c contains \u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u53ef\u4ee5\u4e0d\u4f7f\u7528\u5185\u5efa\u7684\u54c8\u5e0c\u96c6\u5408\u5e93\u89e3\u51b3\u6b64\u95ee\u9898\u5417\uff1f

    \n", "tags_en": ["Design", "Hash Table"], "tags_cn": ["\u8bbe\u8ba1", "\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class MyHashSet {\npublic:\n /** Initialize your data structure here. */\n MyHashSet() {\n\n }\n \n void add(int key) {\n\n }\n \n void remove(int key) {\n\n }\n \n /** Returns true if this set contains the specified element */\n bool contains(int key) {\n\n }\n};\n\n/**\n * Your MyHashSet object will be instantiated and called as such:\n * MyHashSet* obj = new MyHashSet();\n * obj->add(key);\n * obj->remove(key);\n * bool param_3 = obj->contains(key);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class MyHashSet {\n\n /** Initialize your data structure here. */\n public MyHashSet() {\n\n }\n \n public void add(int key) {\n\n }\n \n public void remove(int key) {\n\n }\n \n /** Returns true if this set contains the specified element */\n public boolean contains(int key) {\n\n }\n}\n\n/**\n * Your MyHashSet object will be instantiated and called as such:\n * MyHashSet obj = new MyHashSet();\n * obj.add(key);\n * obj.remove(key);\n * boolean param_3 = obj.contains(key);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class MyHashSet(object):\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def add(self, key):\n \"\"\"\n :type key: int\n :rtype: None\n \"\"\"\n\n\n def remove(self, key):\n \"\"\"\n :type key: int\n :rtype: None\n \"\"\"\n\n\n def contains(self, key):\n \"\"\"\n Returns true if this set contains the specified element\n :type key: int\n :rtype: bool\n \"\"\"\n\n\n\n# Your MyHashSet object will be instantiated and called as such:\n# obj = MyHashSet()\n# obj.add(key)\n# obj.remove(key)\n# param_3 = obj.contains(key)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class MyHashSet:\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def add(self, key: int) -> None:\n\n\n def remove(self, key: int) -> None:\n\n\n def contains(self, key: int) -> bool:\n \"\"\"\n Returns true if this set contains the specified element\n \"\"\"\n\n\n\n# Your MyHashSet object will be instantiated and called as such:\n# obj = MyHashSet()\n# obj.add(key)\n# obj.remove(key)\n# param_3 = obj.contains(key)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} MyHashSet;\n\n/** Initialize your data structure here. */\n\nMyHashSet* myHashSetCreate() {\n\n}\n\nvoid myHashSetAdd(MyHashSet* obj, int key) {\n\n}\n\nvoid myHashSetRemove(MyHashSet* obj, int key) {\n\n}\n\n/** Returns true if this set contains the specified element */\nbool myHashSetContains(MyHashSet* obj, int key) {\n\n}\n\nvoid myHashSetFree(MyHashSet* obj) {\n\n}\n\n/**\n * Your MyHashSet struct will be instantiated and called as such:\n * MyHashSet* obj = myHashSetCreate();\n * myHashSetAdd(obj, key);\n \n * myHashSetRemove(obj, key);\n \n * bool param_3 = myHashSetContains(obj, key);\n \n * myHashSetFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class MyHashSet {\n\n /** Initialize your data structure here. */\n public MyHashSet() {\n\n }\n \n public void Add(int key) {\n\n }\n \n public void Remove(int key) {\n\n }\n \n /** Returns true if this set contains the specified element */\n public bool Contains(int key) {\n\n }\n}\n\n/**\n * Your MyHashSet object will be instantiated and called as such:\n * MyHashSet obj = new MyHashSet();\n * obj.Add(key);\n * obj.Remove(key);\n * bool param_3 = obj.Contains(key);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Initialize your data structure here.\n */\nvar MyHashSet = function() {\n\n};\n\n/** \n * @param {number} key\n * @return {void}\n */\nMyHashSet.prototype.add = function(key) {\n\n};\n\n/** \n * @param {number} key\n * @return {void}\n */\nMyHashSet.prototype.remove = function(key) {\n\n};\n\n/**\n * Returns true if this set contains the specified element \n * @param {number} key\n * @return {boolean}\n */\nMyHashSet.prototype.contains = function(key) {\n\n};\n\n/**\n * Your MyHashSet object will be instantiated and called as such:\n * var obj = new MyHashSet()\n * obj.add(key)\n * obj.remove(key)\n * var param_3 = obj.contains(key)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class MyHashSet\n\n=begin\n Initialize your data structure here.\n=end\n def initialize()\n\n end\n\n\n=begin\n :type key: Integer\n :rtype: Void\n=end\n def add(key)\n\n end\n\n\n=begin\n :type key: Integer\n :rtype: Void\n=end\n def remove(key)\n\n end\n\n\n=begin\n Returns true if this set contains the specified element\n :type key: Integer\n :rtype: Boolean\n=end\n def contains(key)\n\n end\n\n\nend\n\n# Your MyHashSet object will be instantiated and called as such:\n# obj = MyHashSet.new()\n# obj.add(key)\n# obj.remove(key)\n# param_3 = obj.contains(key)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass MyHashSet {\n\n /** Initialize your data structure here. */\n init() {\n\n }\n \n func add(_ key: Int) {\n\n }\n \n func remove(_ key: Int) {\n\n }\n \n /** Returns true if this set contains the specified element */\n func contains(_ key: Int) -> Bool {\n\n }\n}\n\n/**\n * Your MyHashSet object will be instantiated and called as such:\n * let obj = MyHashSet()\n * obj.add(key)\n * obj.remove(key)\n * let ret_3: Bool = obj.contains(key)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type MyHashSet struct {\n\n}\n\n\n/** Initialize your data structure here. */\nfunc Constructor() MyHashSet {\n\n}\n\n\nfunc (this *MyHashSet) Add(key int) {\n\n}\n\n\nfunc (this *MyHashSet) Remove(key int) {\n\n}\n\n\n/** Returns true if this set contains the specified element */\nfunc (this *MyHashSet) Contains(key int) bool {\n\n}\n\n\n/**\n * Your MyHashSet object will be instantiated and called as such:\n * obj := Constructor();\n * obj.Add(key);\n * obj.Remove(key);\n * param_3 := obj.Contains(key);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class MyHashSet() {\n\n /** Initialize your data structure here. */\n\n\n def add(key: Int) {\n\n }\n\n def remove(key: Int) {\n\n }\n\n /** Returns true if this set contains the specified element */\n def contains(key: Int): Boolean = {\n\n }\n\n}\n\n/**\n * Your MyHashSet object will be instantiated and called as such:\n * var obj = new MyHashSet()\n * obj.add(key)\n * obj.remove(key)\n * var param_3 = obj.contains(key)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class MyHashSet() {\n\n /** Initialize your data structure here. */\n\n\n fun add(key: Int) {\n\n }\n\n fun remove(key: Int) {\n\n }\n\n /** Returns true if this set contains the specified element */\n fun contains(key: Int): Boolean {\n\n }\n\n}\n\n/**\n * Your MyHashSet object will be instantiated and called as such:\n * var obj = MyHashSet()\n * obj.add(key)\n * obj.remove(key)\n * var param_3 = obj.contains(key)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct MyHashSet {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl MyHashSet {\n\n /** Initialize your data structure here. */\n fn new() -> Self {\n\n }\n \n fn add(&self, key: i32) {\n\n }\n \n fn remove(&self, key: i32) {\n\n }\n \n /** Returns true if this set contains the specified element */\n fn contains(&self, key: i32) -> bool {\n\n }\n}\n\n/**\n * Your MyHashSet object will be instantiated and called as such:\n * let obj = MyHashSet::new();\n * obj.add(key);\n * obj.remove(key);\n * let ret_3: bool = obj.contains(key);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class MyHashSet {\n /**\n * Initialize your data structure here.\n */\n function __construct() {\n\n }\n\n /**\n * @param Integer $key\n * @return NULL\n */\n function add($key) {\n\n }\n\n /**\n * @param Integer $key\n * @return NULL\n */\n function remove($key) {\n\n }\n\n /**\n * Returns true if this set contains the specified element\n * @param Integer $key\n * @return Boolean\n */\n function contains($key) {\n\n }\n}\n\n/**\n * Your MyHashSet object will be instantiated and called as such:\n * $obj = MyHashSet();\n * $obj->add($key);\n * $obj->remove($key);\n * $ret_3 = $obj->contains($key);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class MyHashSet {\n constructor() {\n\n }\n\n add(key: number): void {\n\n }\n\n remove(key: number): void {\n\n }\n\n contains(key: number): boolean {\n\n }\n}\n\n/**\n * Your MyHashSet object will be instantiated and called as such:\n * var obj = new MyHashSet()\n * obj.add(key)\n * obj.remove(key)\n * var param_3 = obj.contains(key)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define my-hash-set%\n (class object%\n (super-new)\n (init-field)\n \n ; add : exact-integer? -> void?\n (define/public (add key)\n\n )\n ; remove : exact-integer? -> void?\n (define/public (remove key)\n\n )\n ; contains : exact-integer? -> boolean?\n (define/public (contains key)\n\n )))\n\n;; Your my-hash-set% object will be instantiated and called as such:\n;; (define obj (new my-hash-set%))\n;; (send obj add key)\n;; (send obj remove key)\n;; (define param_3 (send obj contains key))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0705](https://leetcode-cn.com/problems/design-hashset)", "[\u8bbe\u8ba1\u54c8\u5e0c\u96c6\u5408](/solution/0700-0799/0705.Design%20HashSet/README.md)", "`\u8bbe\u8ba1`,`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0705](https://leetcode.com/problems/design-hashset)", "[Design HashSet](/solution/0700-0799/0705.Design%20HashSet/README_EN.md)", "`Design`,`Hash Table`", "Easy", ""]}, {"question_id": "0815", "frontend_question_id": "0799", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/champagne-tower", "url_en": "https://leetcode.com/problems/champagne-tower", "relative_path_cn": "/solution/0700-0799/0799.Champagne%20Tower/README.md", "relative_path_en": "/solution/0700-0799/0799.Champagne%20Tower/README_EN.md", "title_cn": "\u9999\u69df\u5854", "title_en": "Champagne Tower", "question_title_slug": "champagne-tower", "content_en": "

    We stack glasses in a pyramid, where the first row has 1 glass, the second row has 2 glasses, and so on until the 100th row.  Each glass holds one cup of champagne.

    \r\n\r\n

    Then, some champagne is poured into the first glass at the top.  When the topmost glass is full, any excess liquid poured will fall equally to the glass immediately to the left and right of it.  When those glasses become full, any excess champagne will fall equally to the left and right of those glasses, and so on.  (A glass at the bottom row has its excess champagne fall on the floor.)

    \r\n\r\n

    For example, after one cup of champagne is poured, the top most glass is full.  After two cups of champagne are poured, the two glasses on the second row are half full.  After three cups of champagne are poured, those two cups become full - there are 3 full glasses total now.  After four cups of champagne are poured, the third row has the middle glass half full, and the two outside glasses are a quarter full, as pictured below.

    \r\n\r\n

    \"\"

    \r\n\r\n

    Now after pouring some non-negative integer cups of champagne, return how full the jth glass in the ith row is (both i and j are 0-indexed.)

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n
    \r\nInput: poured = 1, query_row = 1, query_glass = 1\r\nOutput: 0.00000\r\nExplanation: We poured 1 cup of champange to the top glass of the tower (which is indexed as (0, 0)). There will be no excess liquid so all the glasses under the top glass will remain empty.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: poured = 2, query_row = 1, query_glass = 1\r\nOutput: 0.50000\r\nExplanation: We poured 2 cups of champange to the top glass of the tower (which is indexed as (0, 0)). There is one cup of excess liquid. The glass indexed as (1, 0) and the glass indexed as (1, 1) will share the excess liquid equally, and each will get half cup of champange.\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: poured = 100000009, query_row = 33, query_glass = 17\r\nOutput: 1.00000\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 0 <= poured <= 109
    • \r\n\t
    • 0 <= query_glass <= query_row < 100
    • \r\n
    ", "content_cn": "

    \u6211\u4eec\u628a\u73bb\u7483\u676f\u6446\u6210\u91d1\u5b57\u5854\u7684\u5f62\u72b6\uff0c\u5176\u4e2d\u7b2c\u4e00\u5c42\u67091\u4e2a\u73bb\u7483\u676f\uff0c\u7b2c\u4e8c\u5c42\u67092\u4e2a\uff0c\u4f9d\u6b21\u7c7b\u63a8\u5230\u7b2c100\u5c42\uff0c\u6bcf\u4e2a\u73bb\u7483\u676f(250ml)\u5c06\u76db\u6709\u9999\u69df\u3002

    \n\n

    \u4ece\u9876\u5c42\u7684\u7b2c\u4e00\u4e2a\u73bb\u7483\u676f\u5f00\u59cb\u503e\u5012\u4e00\u4e9b\u9999\u69df\uff0c\u5f53\u9876\u5c42\u7684\u676f\u5b50\u6ee1\u4e86\uff0c\u4efb\u4f55\u6ea2\u51fa\u7684\u9999\u69df\u90fd\u4f1a\u7acb\u523b\u7b49\u6d41\u91cf\u7684\u6d41\u5411\u5de6\u53f3\u4e24\u4fa7\u7684\u73bb\u7483\u676f\u3002\u5f53\u5de6\u53f3\u4e24\u8fb9\u7684\u676f\u5b50\u4e5f\u6ee1\u4e86\uff0c\u5c31\u4f1a\u7b49\u6d41\u91cf\u7684\u6d41\u5411\u5b83\u4eec\u5de6\u53f3\u4e24\u8fb9\u7684\u676f\u5b50\uff0c\u4f9d\u6b21\u7c7b\u63a8\u3002\uff08\u5f53\u6700\u5e95\u5c42\u7684\u73bb\u7483\u676f\u6ee1\u4e86\uff0c\u9999\u69df\u4f1a\u6d41\u5230\u5730\u677f\u4e0a\uff09

    \n\n

    \u4f8b\u5982\uff0c\u5728\u503e\u5012\u4e00\u676f\u9999\u69df\u540e\uff0c\u6700\u9876\u5c42\u7684\u73bb\u7483\u676f\u6ee1\u4e86\u3002\u503e\u5012\u4e86\u4e24\u676f\u9999\u69df\u540e\uff0c\u7b2c\u4e8c\u5c42\u7684\u4e24\u4e2a\u73bb\u7483\u676f\u5404\u81ea\u76db\u653e\u4e00\u534a\u7684\u9999\u69df\u3002\u5728\u5012\u4e09\u676f\u9999\u69df\u540e\uff0c\u7b2c\u4e8c\u5c42\u7684\u9999\u69df\u6ee1\u4e86 - \u6b64\u65f6\u603b\u5171\u6709\u4e09\u4e2a\u6ee1\u7684\u73bb\u7483\u676f\u3002\u5728\u5012\u7b2c\u56db\u676f\u540e\uff0c\u7b2c\u4e09\u5c42\u4e2d\u95f4\u7684\u73bb\u7483\u676f\u76db\u653e\u4e86\u4e00\u534a\u7684\u9999\u69df\uff0c\u4ed6\u4e24\u8fb9\u7684\u73bb\u7483\u676f\u5404\u81ea\u76db\u653e\u4e86\u56db\u5206\u4e4b\u4e00\u7684\u9999\u69df\uff0c\u5982\u4e0b\u56fe\u6240\u793a\u3002

    \n\n

    \"\"

    \n\n

    \u73b0\u5728\u5f53\u503e\u5012\u4e86\u975e\u8d1f\u6574\u6570\u676f\u9999\u69df\u540e\uff0c\u8fd4\u56de\u7b2c i \u884c j \u4e2a\u73bb\u7483\u676f\u6240\u76db\u653e\u7684\u9999\u69df\u5360\u73bb\u7483\u676f\u5bb9\u79ef\u7684\u6bd4\u4f8b\uff08i \u548c j\u90fd\u4ece0\u5f00\u59cb\uff09\u3002

    \n\n

     

    \n\n
    \n\u793a\u4f8b 1:\n\u8f93\u5165: poured(\u503e\u5012\u9999\u69df\u603b\u676f\u6570) = 1, query_glass(\u676f\u5b50\u7684\u4f4d\u7f6e\u6570) = 1, query_row(\u884c\u6570) = 1\n\u8f93\u51fa: 0.0\n\u89e3\u91ca: \u6211\u4eec\u5728\u9876\u5c42\uff08\u4e0b\u6807\u662f\uff080\uff0c0\uff09\uff09\u5012\u4e86\u4e00\u676f\u9999\u69df\u540e\uff0c\u6ca1\u6709\u6ea2\u51fa\uff0c\u56e0\u6b64\u6240\u6709\u5728\u9876\u5c42\u4ee5\u4e0b\u7684\u73bb\u7483\u676f\u90fd\u662f\u7a7a\u7684\u3002\n\n\u793a\u4f8b 2:\n\u8f93\u5165: poured(\u503e\u5012\u9999\u69df\u603b\u676f\u6570) = 2, query_glass(\u676f\u5b50\u7684\u4f4d\u7f6e\u6570) = 1, query_row(\u884c\u6570) = 1\n\u8f93\u51fa: 0.5\n\u89e3\u91ca: \u6211\u4eec\u5728\u9876\u5c42\uff08\u4e0b\u6807\u662f\uff080\uff0c0\uff09\u5012\u4e86\u4e24\u676f\u9999\u69df\u540e\uff0c\u6709\u4e00\u676f\u91cf\u7684\u9999\u69df\u5c06\u4ece\u9876\u5c42\u6ea2\u51fa\uff0c\u4f4d\u4e8e\uff081\uff0c0\uff09\u7684\u73bb\u7483\u676f\u548c\uff081\uff0c1\uff09\u7684\u73bb\u7483\u676f\u5e73\u5206\u4e86\u8fd9\u4e00\u676f\u9999\u69df\uff0c\u6240\u4ee5\u6bcf\u4e2a\u73bb\u7483\u676f\u6709\u4e00\u534a\u7684\u9999\u69df\u3002\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    • poured \u7684\u8303\u56f4[0, 10 ^ 9]\u3002
    • \n\t
    • query_glass \u548cquery_row \u7684\u8303\u56f4 [0, 99]\u3002
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n double champagneTower(int poured, int query_row, int query_glass) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double champagneTower(int poured, int query_row, int query_glass) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def champagneTower(self, poured, query_row, query_glass):\n \"\"\"\n :type poured: int\n :type query_row: int\n :type query_glass: int\n :rtype: float\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def champagneTower(self, poured: int, query_row: int, query_glass: int) -> float:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\ndouble champagneTower(int poured, int query_row, int query_glass){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double ChampagneTower(int poured, int query_row, int query_glass) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} poured\n * @param {number} query_row\n * @param {number} query_glass\n * @return {number}\n */\nvar champagneTower = function(poured, query_row, query_glass) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} poured\n# @param {Integer} query_row\n# @param {Integer} query_glass\n# @return {Float}\ndef champagne_tower(poured, query_row, query_glass)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func champagneTower(_ poured: Int, _ query_row: Int, _ query_glass: Int) -> Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func champagneTower(poured int, query_row int, query_glass int) float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def champagneTower(poured: Int, query_row: Int, query_glass: Int): Double = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun champagneTower(poured: Int, query_row: Int, query_glass: Int): Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn champagne_tower(poured: i32, query_row: i32, query_glass: i32) -> f64 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $poured\n * @param Integer $query_row\n * @param Integer $query_glass\n * @return Float\n */\n function champagneTower($poured, $query_row, $query_glass) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function champagneTower(poured: number, query_row: number, query_glass: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (champagne-tower poured query_row query_glass)\n (-> exact-integer? exact-integer? exact-integer? flonum?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0799](https://leetcode-cn.com/problems/champagne-tower)", "[\u9999\u69df\u5854](/solution/0700-0799/0799.Champagne%20Tower/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0799](https://leetcode.com/problems/champagne-tower)", "[Champagne Tower](/solution/0700-0799/0799.Champagne%20Tower/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0814", "frontend_question_id": "0798", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/smallest-rotation-with-highest-score", "url_en": "https://leetcode.com/problems/smallest-rotation-with-highest-score", "relative_path_cn": "/solution/0700-0799/0798.Smallest%20Rotation%20with%20Highest%20Score/README.md", "relative_path_en": "/solution/0700-0799/0798.Smallest%20Rotation%20with%20Highest%20Score/README_EN.md", "title_cn": "\u5f97\u5206\u6700\u9ad8\u7684\u6700\u5c0f\u8f6e\u8c03", "title_en": "Smallest Rotation with Highest Score", "question_title_slug": "smallest-rotation-with-highest-score", "content_en": "

    Given an array nums, we may rotate it by a non-negative integer k so that the array becomes nums[k], nums[k+1], nums[k+2], ... nums[nums.length - 1], nums[0], nums[1], ..., nums[k-1].  Afterward, any entries that are less than or equal to their index are worth 1 point.

    \n\n

    For example, if we have [2, 4, 1, 3, 0], and we rotate by k = 2, it becomes [1, 3, 0, 2, 4]. This is worth 3 points because 1 > 0 [no points], 3 > 1 [no points], 0 <= 2 [one point], 2 <= 3 [one point], 4 <= 4 [one point].

    \n\n

    Over all possible rotations, return the rotation index k that corresponds to the highest score we could receive. If there are multiple answers, return the smallest such index k.

    \n\n
    \nExample 1:\nInput: [2, 3, 1, 4, 0]\nOutput: 3\nExplanation:  \nScores for each k are listed below: \nk = 0,  nums = [2,3,1,4,0],    score 2\nk = 1,  nums = [3,1,4,0,2],    score 3\nk = 2,  nums = [1,4,0,2,3],    score 3\nk = 3,  nums = [4,0,2,3,1],    score 4\nk = 4,  nums = [0,2,3,1,4],    score 3\n
    \n\n

    So we should choose k = 3, which has the highest score.

    \n\n

     

    \n\n
    \nExample 2:\nInput: [1, 3, 0, 2, 4]\nOutput: 0\nExplanation: nums will always have 3 points no matter how it shifts.\nSo we will choose the smallest k, which is 0.\n
    \n\n

    Note:

    \n\n
      \n\t
    • nums will have length at most 20000.
    • \n\t
    • nums[i] will be in the range [0, nums.length].
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6570\u7ec4 A\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u5b83\u6309\u4e00\u4e2a\u975e\u8d1f\u6574\u6570 K \u8fdb\u884c\u8f6e\u8c03\uff0c\u8fd9\u6837\u53ef\u4ee5\u4f7f\u6570\u7ec4\u53d8\u4e3a A[K], A[K+1], A{K+2], ... A[A.length - 1], A[0], A[1], ..., A[K-1] \u7684\u5f62\u5f0f\u3002\u6b64\u540e\uff0c\u4efb\u4f55\u503c\u5c0f\u4e8e\u6216\u7b49\u4e8e\u5176\u7d22\u5f15\u7684\u9879\u90fd\u53ef\u4ee5\u8bb0\u4f5c\u4e00\u5206\u3002

    \n\n

    \u4f8b\u5982\uff0c\u5982\u679c\u6570\u7ec4\u4e3a [2, 4, 1, 3, 0]\uff0c\u6211\u4eec\u6309 K = 2 \u8fdb\u884c\u8f6e\u8c03\u540e\uff0c\u5b83\u5c06\u53d8\u6210 [1, 3, 0, 2, 4]\u3002\u8fd9\u5c06\u8bb0\u4f5c 3 \u5206\uff0c\u56e0\u4e3a 1 > 0 [no points], 3 > 1 [no points], 0 <= 2 [one point], 2 <= 3 [one point], 4 <= 4 [one point]\u3002

    \n\n

    \u5728\u6240\u6709\u53ef\u80fd\u7684\u8f6e\u8c03\u4e2d\uff0c\u8fd4\u56de\u6211\u4eec\u6240\u80fd\u5f97\u5230\u7684\u6700\u9ad8\u5206\u6570\u5bf9\u5e94\u7684\u8f6e\u8c03\u7d22\u5f15 K\u3002\u5982\u679c\u6709\u591a\u4e2a\u7b54\u6848\uff0c\u8fd4\u56de\u6ee1\u8db3\u6761\u4ef6\u7684\u6700\u5c0f\u7684\u7d22\u5f15 K\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a[2, 3, 1, 4, 0]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\n\u4e0b\u9762\u5217\u51fa\u4e86\u6bcf\u4e2a K \u7684\u5f97\u5206\uff1a\nK = 0,  A = [2,3,1,4,0],    score 2\nK = 1,  A = [3,1,4,0,2],    score 3\nK = 2,  A = [1,4,0,2,3],    score 3\nK = 3,  A = [4,0,2,3,1],    score 4\nK = 4,  A = [0,2,3,1,4],    score 3\n\u6240\u4ee5\u6211\u4eec\u5e94\u5f53\u9009\u62e9 K = 3\uff0c\u5f97\u5206\u6700\u9ad8\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a[1, 3, 0, 2, 4]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\nA \u65e0\u8bba\u600e\u4e48\u53d8\u5316\u603b\u662f\u6709 3 \u5206\u3002\n\u6240\u4ee5\u6211\u4eec\u5c06\u9009\u62e9\u6700\u5c0f\u7684 K\uff0c\u5373 0\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • A \u7684\u957f\u5ea6\u6700\u5927\u4e3a 20000\u3002
    • \n\t
    • A[i] \u7684\u53d6\u503c\u8303\u56f4\u662f [0, A.length]\u3002
    • \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int bestRotation(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int bestRotation(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def bestRotation(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def bestRotation(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint bestRotation(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int BestRotation(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar bestRotation = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef best_rotation(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func bestRotation(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func bestRotation(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def bestRotation(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun bestRotation(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn best_rotation(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function bestRotation($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function bestRotation(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (best-rotation nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0798](https://leetcode-cn.com/problems/smallest-rotation-with-highest-score)", "[\u5f97\u5206\u6700\u9ad8\u7684\u6700\u5c0f\u8f6e\u8c03](/solution/0700-0799/0798.Smallest%20Rotation%20with%20Highest%20Score/README.md)", "", "\u56f0\u96be", ""], "md_table_row_en": ["[0798](https://leetcode.com/problems/smallest-rotation-with-highest-score)", "[Smallest Rotation with Highest Score](/solution/0700-0799/0798.Smallest%20Rotation%20with%20Highest%20Score/README_EN.md)", "", "Hard", ""]}, {"question_id": "0813", "frontend_question_id": "0797", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/all-paths-from-source-to-target", "url_en": "https://leetcode.com/problems/all-paths-from-source-to-target", "relative_path_cn": "/solution/0700-0799/0797.All%20Paths%20From%20Source%20to%20Target/README.md", "relative_path_en": "/solution/0700-0799/0797.All%20Paths%20From%20Source%20to%20Target/README_EN.md", "title_cn": "\u6240\u6709\u53ef\u80fd\u7684\u8def\u5f84", "title_en": "All Paths From Source to Target", "question_title_slug": "all-paths-from-source-to-target", "content_en": "

    Given a directed acyclic graph (DAG) of n nodes labeled from 0 to n - 1, find all possible paths from node 0 to node n - 1, and return them in any order.

    \n\n

    The graph is given as follows: graph[i] is a list of all nodes you can visit from node i (i.e., there is a directed edge from node i to node graph[i][j]).

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: graph = [[1,2],[3],[3],[]]\nOutput: [[0,1,3],[0,2,3]]\nExplanation: There are two paths: 0 -> 1 -> 3 and 0 -> 2 -> 3.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: graph = [[4,3,1],[3,2,4],[3],[4],[]]\nOutput: [[0,4],[0,3,4],[0,1,3,4],[0,1,2,3,4],[0,1,4]]\n
    \n\n

    Example 3:

    \n\n
    \nInput: graph = [[1],[]]\nOutput: [[0,1]]\n
    \n\n

    Example 4:

    \n\n
    \nInput: graph = [[1,2,3],[2],[3],[]]\nOutput: [[0,1,2,3],[0,2,3],[0,3]]\n
    \n\n

    Example 5:

    \n\n
    \nInput: graph = [[1,3],[2],[3],[]]\nOutput: [[0,1,2,3],[0,3]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == graph.length
    • \n\t
    • 2 <= n <= 15
    • \n\t
    • 0 <= graph[i][j] < n
    • \n\t
    • graph[i][j] != i (i.e., there will be no self-loops).
    • \n\t
    • The input graph is guaranteed to be a DAG.
    • \n
    \n", "content_cn": "

    \u7ed9\u4e00\u4e2a\u6709 n \u4e2a\u7ed3\u70b9\u7684\u6709\u5411\u65e0\u73af\u56fe\uff0c\u627e\u5230\u6240\u6709\u4ece 0 \u5230 n-1 \u7684\u8def\u5f84\u5e76\u8f93\u51fa\uff08\u4e0d\u8981\u6c42\u6309\u987a\u5e8f\uff09

    \n\n

    \u4e8c\u7ef4\u6570\u7ec4\u7684\u7b2c i \u4e2a\u6570\u7ec4\u4e2d\u7684\u5355\u5143\u90fd\u8868\u793a\u6709\u5411\u56fe\u4e2d i \u53f7\u7ed3\u70b9\u6240\u80fd\u5230\u8fbe\u7684\u4e0b\u4e00\u4e9b\u7ed3\u70b9\uff08\u8bd1\u8005\u6ce8\uff1a\u6709\u5411\u56fe\u662f\u6709\u65b9\u5411\u7684\uff0c\u5373\u89c4\u5b9a\u4e86 a→b \u4f60\u5c31\u4e0d\u80fd\u4ece b→a \uff09\u7a7a\u5c31\u662f\u6ca1\u6709\u4e0b\u4e00\u4e2a\u7ed3\u70b9\u4e86\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1agraph = [[1,2],[3],[3],[]]\n\u8f93\u51fa\uff1a[[0,1,3],[0,2,3]]\n\u89e3\u91ca\uff1a\u6709\u4e24\u6761\u8def\u5f84 0 -> 1 -> 3 \u548c 0 -> 2 -> 3\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1agraph = [[4,3,1],[3,2,4],[3],[4],[]]\n\u8f93\u51fa\uff1a[[0,4],[0,3,4],[0,1,3,4],[0,1,2,3,4],[0,1,4]]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1agraph = [[1],[]]\n\u8f93\u51fa\uff1a[[0,1]]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1agraph = [[1,2,3],[2],[3],[]]\n\u8f93\u51fa\uff1a[[0,1,2,3],[0,2,3],[0,3]]\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1agraph = [[1,3],[2],[3],[]]\n\u8f93\u51fa\uff1a[[0,1,2,3],[0,3]]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u7ed3\u70b9\u7684\u6570\u91cf\u4f1a\u5728\u8303\u56f4 [2, 15] \u5185\u3002
    • \n\t
    • \u4f60\u53ef\u4ee5\u628a\u8def\u5f84\u4ee5\u4efb\u610f\u987a\u5e8f\u8f93\u51fa\uff0c\u4f46\u5728\u8def\u5f84\u5185\u7684\u7ed3\u70b9\u7684\u987a\u5e8f\u5fc5\u987b\u4fdd\u8bc1\u3002
    • \n
    \n", "tags_en": ["Depth-first Search", "Graph", "Backtracking"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u56fe", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> allPathsSourceTarget(vector>& graph) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> allPathsSourceTarget(int[][] graph) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def allPathsSourceTarget(self, graph):\n \"\"\"\n :type graph: List[List[int]]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def allPathsSourceTarget(self, graph: List[List[int]]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** allPathsSourceTarget(int** graph, int graphSize, int* graphColSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> AllPathsSourceTarget(int[][] graph) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} graph\n * @return {number[][]}\n */\nvar allPathsSourceTarget = function(graph) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} graph\n# @return {Integer[][]}\ndef all_paths_source_target(graph)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func allPathsSourceTarget(_ graph: [[Int]]) -> [[Int]] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func allPathsSourceTarget(graph [][]int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def allPathsSourceTarget(graph: Array[Array[Int]]): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun allPathsSourceTarget(graph: Array): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn all_paths_source_target(graph: Vec>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $graph\n * @return Integer[][]\n */\n function allPathsSourceTarget($graph) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function allPathsSourceTarget(graph: number[][]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (all-paths-source-target graph)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0797](https://leetcode-cn.com/problems/all-paths-from-source-to-target)", "[\u6240\u6709\u53ef\u80fd\u7684\u8def\u5f84](/solution/0700-0799/0797.All%20Paths%20From%20Source%20to%20Target/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u56fe`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0797](https://leetcode.com/problems/all-paths-from-source-to-target)", "[All Paths From Source to Target](/solution/0700-0799/0797.All%20Paths%20From%20Source%20to%20Target/README_EN.md)", "`Depth-first Search`,`Graph`,`Backtracking`", "Medium", ""]}, {"question_id": "0812", "frontend_question_id": "0796", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/rotate-string", "url_en": "https://leetcode.com/problems/rotate-string", "relative_path_cn": "/solution/0700-0799/0796.Rotate%20String/README.md", "relative_path_en": "/solution/0700-0799/0796.Rotate%20String/README_EN.md", "title_cn": "\u65cb\u8f6c\u5b57\u7b26\u4e32", "title_en": "Rotate String", "question_title_slug": "rotate-string", "content_en": "

    We are given two strings, s and goal.

    \n\n

    A shift on s consists of taking string s and moving the leftmost character to the rightmost position. For example, if s = 'abcde', then it will be 'bcdea' after one shift on s. Return true if and only if s can become goal after some number of shifts on s.

    \n\n
    \nExample 1:\nInput: s = 'abcde', goal = 'cdeab'\nOutput: true\n\nExample 2:\nInput: s = 'abcde', goal = 'abced'\nOutput: false\n
    \n\n

    Note:

    \n\n
      \n\t
    • s and goal will have length at most 100.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u5b57\u7b26\u4e32, A \u548c B\u3002

    \n\n

    A \u7684\u65cb\u8f6c\u64cd\u4f5c\u5c31\u662f\u5c06 A \u6700\u5de6\u8fb9\u7684\u5b57\u7b26\u79fb\u52a8\u5230\u6700\u53f3\u8fb9\u3002 \u4f8b\u5982, \u82e5 A = 'abcde'\uff0c\u5728\u79fb\u52a8\u4e00\u6b21\u4e4b\u540e\u7ed3\u679c\u5c31\u662f'bcdea' \u3002\u5982\u679c\u5728\u82e5\u5e72\u6b21\u65cb\u8f6c\u64cd\u4f5c\u4e4b\u540e\uff0cA \u80fd\u53d8\u6210B\uff0c\u90a3\u4e48\u8fd4\u56deTrue\u3002

    \n\n
    \n\u793a\u4f8b 1:\n\u8f93\u5165: A = 'abcde', B = 'cdeab'\n\u8f93\u51fa: true\n\n\u793a\u4f8b 2:\n\u8f93\u5165: A = 'abcde', B = 'abced'\n\u8f93\u51fa: false
    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    • A \u548c B \u957f\u5ea6\u4e0d\u8d85\u8fc7 100\u3002
    • \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool rotateString(string s, string goal) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean rotateString(String s, String goal) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def rotateString(self, s, goal):\n \"\"\"\n :type s: str\n :type goal: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def rotateString(self, s: str, goal: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool rotateString(char * s, char * goal){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool RotateString(string s, string goal) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string} goal\n * @return {boolean}\n */\nvar rotateString = function(s, goal) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String} goal\n# @return {Boolean}\ndef rotate_string(s, goal)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func rotateString(_ s: String, _ goal: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func rotateString(s string, goal string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def rotateString(s: String, goal: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun rotateString(s: String, goal: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn rotate_string(s: String, goal: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String $goal\n * @return Boolean\n */\n function rotateString($s, $goal) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function rotateString(s: string, goal: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (rotate-string s goal)\n (-> string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0796](https://leetcode-cn.com/problems/rotate-string)", "[\u65cb\u8f6c\u5b57\u7b26\u4e32](/solution/0700-0799/0796.Rotate%20String/README.md)", "", "\u7b80\u5355", ""], "md_table_row_en": ["[0796](https://leetcode.com/problems/rotate-string)", "[Rotate String](/solution/0700-0799/0796.Rotate%20String/README_EN.md)", "", "Easy", ""]}, {"question_id": "0811", "frontend_question_id": "0795", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-subarrays-with-bounded-maximum", "url_en": "https://leetcode.com/problems/number-of-subarrays-with-bounded-maximum", "relative_path_cn": "/solution/0700-0799/0795.Number%20of%20Subarrays%20with%20Bounded%20Maximum/README.md", "relative_path_en": "/solution/0700-0799/0795.Number%20of%20Subarrays%20with%20Bounded%20Maximum/README_EN.md", "title_cn": "\u533a\u95f4\u5b50\u6570\u7ec4\u4e2a\u6570", "title_en": "Number of Subarrays with Bounded Maximum", "question_title_slug": "number-of-subarrays-with-bounded-maximum", "content_en": "

    We are given an array nums of positive integers, and two positive integers left and right (left <= right).

    \n\n

    Return the number of (contiguous, non-empty) subarrays such that the value of the maximum array element in that subarray is at least left and at most right.

    \n\n
    \nExample:\nInput: \nnums = [2, 1, 4, 3]\nleft = 2\nright = 3\nOutput: 3\nExplanation: There are three subarrays that meet the requirements: [2], [2, 1], [3].\n
    \n\n

    Note:

    \n\n
      \n\t
    • left, right, and nums[i] will be an integer in the range [0, 109].
    • \n\t
    • The length of nums will be in the range of [1, 50000].
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5143\u7d20\u90fd\u662f\u6b63\u6574\u6570\u7684\u6570\u7ec4A \uff0c\u6b63\u6574\u6570 L \u4ee5\u53ca R (L <= R)\u3002

    \n\n

    \u6c42\u8fde\u7eed\u3001\u975e\u7a7a\u4e14\u5176\u4e2d\u6700\u5927\u5143\u7d20\u6ee1\u8db3\u5927\u4e8e\u7b49\u4e8eL \u5c0f\u4e8e\u7b49\u4e8eR\u7684\u5b50\u6570\u7ec4\u4e2a\u6570\u3002

    \n\n
    \u4f8b\u5982 :\n\u8f93\u5165: \nA = [2, 1, 4, 3]\nL = 2\nR = 3\n\u8f93\u51fa: 3\n\u89e3\u91ca: \u6ee1\u8db3\u6761\u4ef6\u7684\u5b50\u6570\u7ec4: [2], [2, 1], [3].\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    • L, R  \u548c A[i] \u90fd\u662f\u6574\u6570\uff0c\u8303\u56f4\u5728 [0, 10^9]\u3002
    • \n\t
    • \u6570\u7ec4 A \u7684\u957f\u5ea6\u8303\u56f4\u5728[1, 50000]\u3002
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numSubarrayBoundedMax(vector& nums, int left, int right) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numSubarrayBoundedMax(int[] nums, int left, int right) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numSubarrayBoundedMax(self, nums, left, right):\n \"\"\"\n :type nums: List[int]\n :type left: int\n :type right: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numSubarrayBoundedMax(self, nums: List[int], left: int, right: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numSubarrayBoundedMax(int* nums, int numsSize, int left, int right){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumSubarrayBoundedMax(int[] nums, int left, int right) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} left\n * @param {number} right\n * @return {number}\n */\nvar numSubarrayBoundedMax = function(nums, left, right) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} left\n# @param {Integer} right\n# @return {Integer}\ndef num_subarray_bounded_max(nums, left, right)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numSubarrayBoundedMax(_ nums: [Int], _ left: Int, _ right: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numSubarrayBoundedMax(nums []int, left int, right int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numSubarrayBoundedMax(nums: Array[Int], left: Int, right: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numSubarrayBoundedMax(nums: IntArray, left: Int, right: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_subarray_bounded_max(nums: Vec, left: i32, right: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $left\n * @param Integer $right\n * @return Integer\n */\n function numSubarrayBoundedMax($nums, $left, $right) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numSubarrayBoundedMax(nums: number[], left: number, right: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-subarray-bounded-max nums left right)\n (-> (listof exact-integer?) exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0795](https://leetcode-cn.com/problems/number-of-subarrays-with-bounded-maximum)", "[\u533a\u95f4\u5b50\u6570\u7ec4\u4e2a\u6570](/solution/0700-0799/0795.Number%20of%20Subarrays%20with%20Bounded%20Maximum/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0795](https://leetcode.com/problems/number-of-subarrays-with-bounded-maximum)", "[Number of Subarrays with Bounded Maximum](/solution/0700-0799/0795.Number%20of%20Subarrays%20with%20Bounded%20Maximum/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0810", "frontend_question_id": "0794", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/valid-tic-tac-toe-state", "url_en": "https://leetcode.com/problems/valid-tic-tac-toe-state", "relative_path_cn": "/solution/0700-0799/0794.Valid%20Tic-Tac-Toe%20State/README.md", "relative_path_en": "/solution/0700-0799/0794.Valid%20Tic-Tac-Toe%20State/README_EN.md", "title_cn": "\u6709\u6548\u7684\u4e95\u5b57\u6e38\u620f", "title_en": "Valid Tic-Tac-Toe State", "question_title_slug": "valid-tic-tac-toe-state", "content_en": "

    Given a Tic-Tac-Toe board as a string array board, return true if and only if it is possible to reach this board position during the course of a valid tic-tac-toe game.

    \n\n

    The board is a 3 x 3 array that consists of characters ' ', 'X', and 'O'. The ' ' character represents an empty square.

    \n\n

    Here are the rules of Tic-Tac-Toe:

    \n\n
      \n\t
    • Players take turns placing characters into empty squares ' '.
    • \n\t
    • The first player always places 'X' characters, while the second player always places 'O' characters.
    • \n\t
    • 'X' and 'O' characters are always placed into empty squares, never filled ones.
    • \n\t
    • The game ends when there are three of the same (non-empty) character filling any row, column, or diagonal.
    • \n\t
    • The game also ends if all squares are non-empty.
    • \n\t
    • No more moves can be played if the game is over.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: board = ["O  ","   ","   "]\nOutput: false\nExplanation: The first player always plays "X".\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: board = ["XOX"," X ","   "]\nOutput: false\nExplanation: Players take turns making moves.\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: board = ["XXX","   ","OOO"]\nOutput: false\n
    \n\n

    Example 4:

    \n\"\"\n
    \nInput: board = ["XOX","O O","XOX"]\nOutput: true\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • board.length == 3
    • \n\t
    • board[i].length == 3
    • \n\t
    • board[i][j] is either 'X', 'O', or ' '.
    • \n
    \n", "content_cn": "

    \u7528\u5b57\u7b26\u4e32\u6570\u7ec4\u4f5c\u4e3a\u4e95\u5b57\u6e38\u620f\u7684\u6e38\u620f\u677f board\u3002\u5f53\u4e14\u4ec5\u5f53\u5728\u4e95\u5b57\u6e38\u620f\u8fc7\u7a0b\u4e2d\uff0c\u73a9\u5bb6\u6709\u53ef\u80fd\u5c06\u5b57\u7b26\u653e\u7f6e\u6210\u6e38\u620f\u677f\u6240\u663e\u793a\u7684\u72b6\u6001\u65f6\uff0c\u624d\u8fd4\u56de true\u3002

    \n\n

    \u8be5\u6e38\u620f\u677f\u662f\u4e00\u4e2a 3 x 3 \u6570\u7ec4\uff0c\u7531\u5b57\u7b26 " "\uff0c"X" \u548c "O" \u7ec4\u6210\u3002\u5b57\u7b26 " " \u4ee3\u8868\u4e00\u4e2a\u7a7a\u4f4d\u3002

    \n\n

    \u4ee5\u4e0b\u662f\u4e95\u5b57\u6e38\u620f\u7684\u89c4\u5219\uff1a

    \n\n
      \n\t
    • \u73a9\u5bb6\u8f6e\u6d41\u5c06\u5b57\u7b26\u653e\u5165\u7a7a\u4f4d\uff08" "\uff09\u4e2d\u3002
    • \n\t
    • \u7b2c\u4e00\u4e2a\u73a9\u5bb6\u603b\u662f\u653e\u5b57\u7b26 “X”\uff0c\u4e14\u7b2c\u4e8c\u4e2a\u73a9\u5bb6\u603b\u662f\u653e\u5b57\u7b26 “O”\u3002
    • \n\t
    • “X” \u548c “O” \u53ea\u5141\u8bb8\u653e\u7f6e\u5728\u7a7a\u4f4d\u4e2d\uff0c\u4e0d\u5141\u8bb8\u5bf9\u5df2\u653e\u6709\u5b57\u7b26\u7684\u4f4d\u7f6e\u8fdb\u884c\u586b\u5145\u3002
    • \n\t
    • \u5f53\u6709 3 \u4e2a\u76f8\u540c\uff08\u4e14\u975e\u7a7a\uff09\u7684\u5b57\u7b26\u586b\u5145\u4efb\u4f55\u884c\u3001\u5217\u6216\u5bf9\u89d2\u7ebf\u65f6\uff0c\u6e38\u620f\u7ed3\u675f\u3002
    • \n\t
    • \u5f53\u6240\u6709\u4f4d\u7f6e\u975e\u7a7a\u65f6\uff0c\u4e5f\u7b97\u4e3a\u6e38\u620f\u7ed3\u675f\u3002
    • \n\t
    • \u5982\u679c\u6e38\u620f\u7ed3\u675f\uff0c\u73a9\u5bb6\u4e0d\u5141\u8bb8\u518d\u653e\u7f6e\u5b57\u7b26\u3002
    • \n
    \n\n
    \n\u793a\u4f8b 1:\n\u8f93\u5165: board = ["O  ", "   ", "   "]\n\u8f93\u51fa: false\n\u89e3\u91ca: \u7b2c\u4e00\u4e2a\u73a9\u5bb6\u603b\u662f\u653e\u7f6e“X”\u3002\n\n\u793a\u4f8b 2:\n\u8f93\u5165: board = ["XOX", " X ", "   "]\n\u8f93\u51fa: false\n\u89e3\u91ca: \u73a9\u5bb6\u5e94\u8be5\u662f\u8f6e\u6d41\u653e\u7f6e\u7684\u3002\n\n\u793a\u4f8b 3:\n\u8f93\u5165: board = ["XXX", "   ", "OOO"]\n\u8f93\u51fa: false\n\n\u793a\u4f8b 4:\n\u8f93\u5165: board = ["XOX", "O O", "XOX"]\n\u8f93\u51fa: true\n
    \n\n

    \u8bf4\u660e:

    \n\n
      \n\t
    • \u6e38\u620f\u677f board \u662f\u957f\u5ea6\u4e3a 3 \u7684\u5b57\u7b26\u4e32\u6570\u7ec4\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5b57\u7b26\u4e32 board[i] \u7684\u957f\u5ea6\u4e3a 3\u3002
    • \n\t
    •  board[i][j] \u662f\u96c6\u5408 {" ", "X", "O"} \u4e2d\u7684\u4e00\u4e2a\u5b57\u7b26\u3002
    • \n
    \n", "tags_en": ["Recursion", "Math"], "tags_cn": ["\u9012\u5f52", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool validTicTacToe(vector& board) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean validTicTacToe(String[] board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def validTicTacToe(self, board):\n \"\"\"\n :type board: List[str]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def validTicTacToe(self, board: List[str]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool validTicTacToe(char ** board, int boardSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool ValidTicTacToe(string[] board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} board\n * @return {boolean}\n */\nvar validTicTacToe = function(board) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} board\n# @return {Boolean}\ndef valid_tic_tac_toe(board)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func validTicTacToe(_ board: [String]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func validTicTacToe(board []string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def validTicTacToe(board: Array[String]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun validTicTacToe(board: Array): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn valid_tic_tac_toe(board: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $board\n * @return Boolean\n */\n function validTicTacToe($board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function validTicTacToe(board: string[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (valid-tic-tac-toe board)\n (-> (listof string?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0794](https://leetcode-cn.com/problems/valid-tic-tac-toe-state)", "[\u6709\u6548\u7684\u4e95\u5b57\u6e38\u620f](/solution/0700-0799/0794.Valid%20Tic-Tac-Toe%20State/README.md)", "`\u9012\u5f52`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0794](https://leetcode.com/problems/valid-tic-tac-toe-state)", "[Valid Tic-Tac-Toe State](/solution/0700-0799/0794.Valid%20Tic-Tac-Toe%20State/README_EN.md)", "`Recursion`,`Math`", "Medium", ""]}, {"question_id": "0809", "frontend_question_id": "0793", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/preimage-size-of-factorial-zeroes-function", "url_en": "https://leetcode.com/problems/preimage-size-of-factorial-zeroes-function", "relative_path_cn": "/solution/0700-0799/0793.Preimage%20Size%20of%20Factorial%20Zeroes%20Function/README.md", "relative_path_en": "/solution/0700-0799/0793.Preimage%20Size%20of%20Factorial%20Zeroes%20Function/README_EN.md", "title_cn": "\u9636\u4e58\u51fd\u6570\u540e K \u4e2a\u96f6", "title_en": "Preimage Size of Factorial Zeroes Function", "question_title_slug": "preimage-size-of-factorial-zeroes-function", "content_en": "

    Let f(x) be the number of zeroes at the end of x!. (Recall that x! = 1 * 2 * 3 * ... * x, and by convention, 0! = 1.)

    \n\n

    For example, f(3) = 0 because 3! = 6 has no zeroes at the end, while f(11) = 2 because 11! = 39916800 has 2 zeroes at the end. Given k, find how many non-negative integers x have the property that f(x) = k.

    \n\n
    \nExample 1:\nInput: k = 0\nOutput: 5\nExplanation: 0!, 1!, 2!, 3!, and 4! end with k = 0 zeroes.\n\nExample 2:\nInput: k = 5\nOutput: 0\nExplanation: There is no x such that x! ends in k = 5 zeroes.\n
    \n\n

    Note:

    \n\n
      \n\t
    • k will be an integer in the range [0, 109].
    • \n
    \n", "content_cn": "

    \u00a0f(x)\u00a0\u662f\u00a0x!\u00a0\u672b\u5c3e\u662f 0 \u7684\u6570\u91cf\u3002\uff08\u56de\u60f3\u4e00\u4e0b\u00a0x! = 1 * 2 * 3 * ... * x\uff0c\u4e14 0! = 1 \uff09

    \n\n

    \u4f8b\u5982\uff0c\u00a0f(3) = 0\u00a0\uff0c\u56e0\u4e3a 3! = 6 \u7684\u672b\u5c3e\u6ca1\u6709 0 \uff1b\u800c f(11) = 2\u00a0\uff0c\u56e0\u4e3a 11!= 39916800 \u672b\u7aef\u6709 2 \u4e2a 0 \u3002\u7ed9\u5b9a\u00a0K\uff0c\u627e\u51fa\u591a\u5c11\u4e2a\u975e\u8d1f\u6574\u6570 x\u00a0\uff0c\u80fd\u6ee1\u8db3 f(x) = K \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aK = 0\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a0!, 1!, 2!, 3!, and 4!\u00a0\u5747\u7b26\u5408 K = 0 \u7684\u6761\u4ef6\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aK = 5\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6ca1\u6709\u5339\u914d\u5230\u8fd9\u6837\u7684 x!\uff0c\u7b26\u5408 K = 5 \u7684\u6761\u4ef6\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \n\t

      K \u662f\u8303\u56f4\u5728\u00a0[0, 10^9]\u00a0\u7684\u6574\u6570\u3002

      \n\t
    • \n
    \n", "tags_en": ["Binary Search"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int preimageSizeFZF(int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int preimageSizeFZF(int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def preimageSizeFZF(self, k):\n \"\"\"\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def preimageSizeFZF(self, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint preimageSizeFZF(int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int PreimageSizeFZF(int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} k\n * @return {number}\n */\nvar preimageSizeFZF = function(k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} k\n# @return {Integer}\ndef preimage_size_fzf(k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func preimageSizeFZF(_ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func preimageSizeFZF(k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def preimageSizeFZF(k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun preimageSizeFZF(k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn preimage_size_fzf(k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $k\n * @return Integer\n */\n function preimageSizeFZF($k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function preimageSizeFZF(k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (preimage-size-fzf k)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0793](https://leetcode-cn.com/problems/preimage-size-of-factorial-zeroes-function)", "[\u9636\u4e58\u51fd\u6570\u540e K \u4e2a\u96f6](/solution/0700-0799/0793.Preimage%20Size%20of%20Factorial%20Zeroes%20Function/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u56f0\u96be", ""], "md_table_row_en": ["[0793](https://leetcode.com/problems/preimage-size-of-factorial-zeroes-function)", "[Preimage Size of Factorial Zeroes Function](/solution/0700-0799/0793.Preimage%20Size%20of%20Factorial%20Zeroes%20Function/README_EN.md)", "`Binary Search`", "Hard", ""]}, {"question_id": "0808", "frontend_question_id": "0792", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-matching-subsequences", "url_en": "https://leetcode.com/problems/number-of-matching-subsequences", "relative_path_cn": "/solution/0700-0799/0792.Number%20of%20Matching%20Subsequences/README.md", "relative_path_en": "/solution/0700-0799/0792.Number%20of%20Matching%20Subsequences/README_EN.md", "title_cn": "\u5339\u914d\u5b50\u5e8f\u5217\u7684\u5355\u8bcd\u6570", "title_en": "Number of Matching Subsequences", "question_title_slug": "number-of-matching-subsequences", "content_en": "

    Given a string s and an array of strings words, return the number of words[i] that is a subsequence of s.

    \n\n

    A subsequence of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters.

    \n\n
      \n\t
    • For example, "ace" is a subsequence of "abcde".
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "abcde", words = ["a","bb","acd","ace"]\nOutput: 3\nExplanation: There are three strings in words that are a subsequence of s: "a", "acd", "ace".\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "dsahjpjauf", words = ["ahjpjau","ja","ahbwzgqnuk","tnmlanowax"]\nOutput: 2\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 5 * 104
    • \n\t
    • 1 <= words.length <= 5000
    • \n\t
    • 1 <= words[i].length <= 50
    • \n\t
    • s and words[i] consist of only lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u5b57\u7b26\u4e32 S \u548c\u5355\u8bcd\u5b57\u5178 words, \u6c42 words[i] \u4e2d\u662f S \u7684\u5b50\u5e8f\u5217\u7684\u5355\u8bcd\u4e2a\u6570\u3002

    \n\n
    \n\u793a\u4f8b:\n\u8f93\u5165: \nS = "abcde"\nwords = ["a", "bb", "acd", "ace"]\n\u8f93\u51fa: 3\n\u89e3\u91ca: \u6709\u4e09\u4e2a\u662f S \u7684\u5b50\u5e8f\u5217\u7684\u5355\u8bcd: "a", "acd", "ace"\u3002\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    • \u6240\u6709\u5728words\u548c S \u91cc\u7684\u5355\u8bcd\u90fd\u53ea\u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210\u3002
    • \n\t
    • S \u7684\u957f\u5ea6\u5728 [1, 50000]\u3002
    • \n\t
    • words \u7684\u957f\u5ea6\u5728 [1, 5000]\u3002
    • \n\t
    • words[i]\u7684\u957f\u5ea6\u5728[1, 50]\u3002
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numMatchingSubseq(string s, vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numMatchingSubseq(String s, String[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numMatchingSubseq(self, s, words):\n \"\"\"\n :type s: str\n :type words: List[str]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numMatchingSubseq(self, s: str, words: List[str]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numMatchingSubseq(char * s, char ** words, int wordsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumMatchingSubseq(string s, string[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string[]} words\n * @return {number}\n */\nvar numMatchingSubseq = function(s, words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String[]} words\n# @return {Integer}\ndef num_matching_subseq(s, words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numMatchingSubseq(_ s: String, _ words: [String]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numMatchingSubseq(s string, words []string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numMatchingSubseq(s: String, words: Array[String]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numMatchingSubseq(s: String, words: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_matching_subseq(s: String, words: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String[] $words\n * @return Integer\n */\n function numMatchingSubseq($s, $words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numMatchingSubseq(s: string, words: string[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-matching-subseq s words)\n (-> string? (listof string?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0792](https://leetcode-cn.com/problems/number-of-matching-subsequences)", "[\u5339\u914d\u5b50\u5e8f\u5217\u7684\u5355\u8bcd\u6570](/solution/0700-0799/0792.Number%20of%20Matching%20Subsequences/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0792](https://leetcode.com/problems/number-of-matching-subsequences)", "[Number of Matching Subsequences](/solution/0700-0799/0792.Number%20of%20Matching%20Subsequences/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0807", "frontend_question_id": "0791", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/custom-sort-string", "url_en": "https://leetcode.com/problems/custom-sort-string", "relative_path_cn": "/solution/0700-0799/0791.Custom%20Sort%20String/README.md", "relative_path_en": "/solution/0700-0799/0791.Custom%20Sort%20String/README_EN.md", "title_cn": "\u81ea\u5b9a\u4e49\u5b57\u7b26\u4e32\u6392\u5e8f", "title_en": "Custom Sort String", "question_title_slug": "custom-sort-string", "content_en": "

    order and str are strings composed of lowercase letters. In order, no letter occurs more than once.

    \n\n

    order was sorted in some custom order previously. We want to permute the characters of str so that they match the order that order was sorted. More specifically, if x occurs before y in order, then x should occur before y in the returned string.

    \n\n

    Return any permutation of str (as a string) that satisfies this property.

    \n\n
    \nExample:\nInput: \norder = "cba"\nstr = "abcd"\nOutput: "cbad"\nExplanation: \n"a", "b", "c" appear in order, so the order of "a", "b", "c" should be "c", "b", and "a". \nSince "d" does not appear in order, it can be at any position in the returned string. "dcba", "cdba", "cbda" are also valid outputs.\n
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    • order has length at most 26, and no character is repeated in order.
    • \n\t
    • str has length at most 200.
    • \n\t
    • order and str consist of lowercase letters only.
    • \n
    \n", "content_cn": "

    \u5b57\u7b26\u4e32S\u548c T \u53ea\u5305\u542b\u5c0f\u5199\u5b57\u7b26\u3002\u5728S\u4e2d\uff0c\u6240\u6709\u5b57\u7b26\u53ea\u4f1a\u51fa\u73b0\u4e00\u6b21\u3002

    \n\n

    S \u5df2\u7ecf\u6839\u636e\u67d0\u79cd\u89c4\u5219\u8fdb\u884c\u4e86\u6392\u5e8f\u3002\u6211\u4eec\u8981\u6839\u636eS\u4e2d\u7684\u5b57\u7b26\u987a\u5e8f\u5bf9T\u8fdb\u884c\u6392\u5e8f\u3002\u66f4\u5177\u4f53\u5730\u8bf4\uff0c\u5982\u679cS\u4e2dx\u5728y\u4e4b\u524d\u51fa\u73b0\uff0c\u90a3\u4e48\u8fd4\u56de\u7684\u5b57\u7b26\u4e32\u4e2dx\u4e5f\u5e94\u51fa\u73b0\u5728y\u4e4b\u524d\u3002

    \n\n

    \u8fd4\u56de\u4efb\u610f\u4e00\u79cd\u7b26\u5408\u6761\u4ef6\u7684\u5b57\u7b26\u4e32T\u3002

    \n\n
    \n\u793a\u4f8b:\n\u8f93\u5165:\nS = "cba"\nT = "abcd"\n\u8f93\u51fa: "cbad"\n\u89e3\u91ca: \nS\u4e2d\u51fa\u73b0\u4e86\u5b57\u7b26 "a", "b", "c", \u6240\u4ee5 "a", "b", "c" \u7684\u987a\u5e8f\u5e94\u8be5\u662f "c", "b", "a". \n\u7531\u4e8e "d" \u6ca1\u6709\u5728S\u4e2d\u51fa\u73b0, \u5b83\u53ef\u4ee5\u653e\u5728T\u7684\u4efb\u610f\u4f4d\u7f6e. "dcba", "cdba", "cbda" \u90fd\u662f\u5408\u6cd5\u7684\u8f93\u51fa\u3002\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    • S\u7684\u6700\u5927\u957f\u5ea6\u4e3a26\uff0c\u5176\u4e2d\u6ca1\u6709\u91cd\u590d\u7684\u5b57\u7b26\u3002
    • \n\t
    • T\u7684\u6700\u5927\u957f\u5ea6\u4e3a200\u3002
    • \n\t
    • S\u548cT\u53ea\u5305\u542b\u5c0f\u5199\u5b57\u7b26\u3002
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string customSortString(string order, string str) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String customSortString(String order, String str) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def customSortString(self, order, str):\n \"\"\"\n :type order: str\n :type str: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def customSortString(self, order: str, str: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * customSortString(char * order, char * str){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string CustomSortString(string order, string str) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} order\n * @param {string} str\n * @return {string}\n */\nvar customSortString = function(order, str) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} order\n# @param {String} str\n# @return {String}\ndef custom_sort_string(order, str)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func customSortString(_ order: String, _ str: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func customSortString(order string, str string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def customSortString(order: String, str: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun customSortString(order: String, str: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn custom_sort_string(order: String, str: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $order\n * @param String $str\n * @return String\n */\n function customSortString($order, $str) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function customSortString(order: string, str: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (custom-sort-string order str)\n (-> string? string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0791](https://leetcode-cn.com/problems/custom-sort-string)", "[\u81ea\u5b9a\u4e49\u5b57\u7b26\u4e32\u6392\u5e8f](/solution/0700-0799/0791.Custom%20Sort%20String/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0791](https://leetcode.com/problems/custom-sort-string)", "[Custom Sort String](/solution/0700-0799/0791.Custom%20Sort%20String/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "0806", "frontend_question_id": "0790", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/domino-and-tromino-tiling", "url_en": "https://leetcode.com/problems/domino-and-tromino-tiling", "relative_path_cn": "/solution/0700-0799/0790.Domino%20and%20Tromino%20Tiling/README.md", "relative_path_en": "/solution/0700-0799/0790.Domino%20and%20Tromino%20Tiling/README_EN.md", "title_cn": "\u591a\u7c73\u8bfa\u548c\u6258\u7c73\u8bfa\u5e73\u94fa", "title_en": "Domino and Tromino Tiling", "question_title_slug": "domino-and-tromino-tiling", "content_en": "

    We have two types of tiles: a 2x1 domino shape, and an "L" tromino shape. These shapes may be rotated.

    \n\n
    \nXX  <- domino\n\nXX  <- "L" tromino\nX\n
    \n\n

    Given n, how many ways are there to tile a 2 x n board? Return your answer modulo 109 + 7.

    \n\n

    (In a tiling, every square must be covered by a tile. Two tilings are different if and only if there are two 4-directionally adjacent cells on the board such that exactly one of the tilings has both squares occupied by a tile.)

    \n\n
    \nExample:\nInput: n = 3\nOutput: 5\nExplanation: \nThe five different ways are listed below, different letters indicates different tiles:\nXYZ XXZ XYY XXY XYY\nXYZ YYZ XZZ XYY XXY
    \n\n

    Note:

    \n\n
      \n\t
    • n will be in range [1, 1000].
    • \n
    \n\n

     

    \n", "content_cn": "

    \u6709\u4e24\u79cd\u5f62\u72b6\u7684\u74f7\u7816\uff1a\u4e00\u79cd\u662f 2x1 \u7684\u591a\u7c73\u8bfa\u5f62\uff0c\u53e6\u4e00\u79cd\u662f\u5f62\u5982 "L" \u7684\u6258\u7c73\u8bfa\u5f62\u3002\u4e24\u79cd\u5f62\u72b6\u90fd\u53ef\u4ee5\u65cb\u8f6c\u3002

    \n\n
    \nXX  <- \u591a\u7c73\u8bfa\n\nXX  <- "L" \u6258\u7c73\u8bfa\nX\n
    \n\n

    \u7ed9\u5b9a N \u7684\u503c\uff0c\u6709\u591a\u5c11\u79cd\u65b9\u6cd5\u53ef\u4ee5\u5e73\u94fa 2 x N \u7684\u9762\u677f\uff1f\u8fd4\u56de\u503c mod 10^9 + 7\u3002

    \n\n

    \uff08\u5e73\u94fa\u6307\u7684\u662f\u6bcf\u4e2a\u6b63\u65b9\u5f62\u90fd\u5fc5\u987b\u6709\u74f7\u7816\u8986\u76d6\u3002\u4e24\u4e2a\u5e73\u94fa\u4e0d\u540c\uff0c\u5f53\u4e14\u4ec5\u5f53\u9762\u677f\u4e0a\u6709\u56db\u4e2a\u65b9\u5411\u4e0a\u7684\u76f8\u90bb\u5355\u5143\u4e2d\u7684\u4e24\u4e2a\uff0c\u4f7f\u5f97\u6070\u597d\u6709\u4e00\u4e2a\u5e73\u94fa\u6709\u4e00\u4e2a\u74f7\u7816\u5360\u636e\u4e24\u4e2a\u6b63\u65b9\u5f62\u3002\uff09

    \n\n
    \n\u793a\u4f8b:\n\u8f93\u5165: 3\n\u8f93\u51fa: 5\n\u89e3\u91ca: \n\u4e0b\u9762\u5217\u51fa\u4e86\u4e94\u79cd\u4e0d\u540c\u7684\u65b9\u6cd5\uff0c\u4e0d\u540c\u5b57\u6bcd\u4ee3\u8868\u4e0d\u540c\u74f7\u7816\uff1a\nXYZ XXZ XYY XXY XYY\nXYZ YYZ XZZ XYY XXY
    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • N  \u7684\u8303\u56f4\u662f [1, 1000]
    • \n
    \n\n

     

    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numTilings(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numTilings(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numTilings(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numTilings(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numTilings(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumTilings(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar numTilings = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef num_tilings(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numTilings(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numTilings(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numTilings(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numTilings(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_tilings(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function numTilings($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numTilings(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-tilings n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0790](https://leetcode-cn.com/problems/domino-and-tromino-tiling)", "[\u591a\u7c73\u8bfa\u548c\u6258\u7c73\u8bfa\u5e73\u94fa](/solution/0700-0799/0790.Domino%20and%20Tromino%20Tiling/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0790](https://leetcode.com/problems/domino-and-tromino-tiling)", "[Domino and Tromino Tiling](/solution/0700-0799/0790.Domino%20and%20Tromino%20Tiling/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0805", "frontend_question_id": "0789", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/escape-the-ghosts", "url_en": "https://leetcode.com/problems/escape-the-ghosts", "relative_path_cn": "/solution/0700-0799/0789.Escape%20The%20Ghosts/README.md", "relative_path_en": "/solution/0700-0799/0789.Escape%20The%20Ghosts/README_EN.md", "title_cn": "\u9003\u8131\u963b\u788d\u8005", "title_en": "Escape The Ghosts", "question_title_slug": "escape-the-ghosts", "content_en": "

    You are playing a simplified PAC-MAN game on an infinite 2-D grid. You start at the point [0, 0], and you are given a destination point target = [xtarget, ytarget], which you are trying to get to. There are several ghosts on the map with their starting positions given as an array ghosts, where ghosts[i] = [xi, yi] represents the starting position of the ith ghost. All inputs are integral coordinates.

    \n\n

    Each turn, you and all the ghosts may independently choose to either move 1 unit in any of the four cardinal directions: north, east, south, or west or stay still. All actions happen simultaneously.

    \n\n

    You escape if and only if you can reach the target before any ghost reaches you. If you reach any square (including the target) at the same time as a ghost, it does not count as an escape.

    \n\n

    Return true if it is possible to escape, otherwise return false.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: ghosts = [[1,0],[0,3]], target = [0,1]\nOutput: true\nExplanation: You can reach the destination (0, 1) after 1 turn, while the ghosts located at (1, 0) and (0, 3) cannot catch up with you.\n
    \n\n

    Example 2:

    \n\n
    \nInput: ghosts = [[1,0]], target = [2,0]\nOutput: false\nExplanation: You need to reach the destination (2, 0), but the ghost at (1, 0) lies between you and the destination.\n
    \n\n

    Example 3:

    \n\n
    \nInput: ghosts = [[2,0]], target = [1,0]\nOutput: false\nExplanation: The ghost can reach the target at the same time as you.\n
    \n\n

    Example 4:

    \n\n
    \nInput: ghosts = [[5,0],[-10,-2],[0,-5],[-2,-2],[-7,1]], target = [7,7]\nOutput: false\n
    \n\n

    Example 5:

    \n\n
    \nInput: ghosts = [[-1,0],[0,1],[-1,0],[0,1],[-1,0]], target = [0,0]\nOutput: true\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= ghosts.length <= 100
    • \n\t
    • ghosts[i].length == 2
    • \n\t
    • -104 <= xi, yi <= 104
    • \n\t
    • There can be multiple ghosts in the same location.
    • \n\t
    • target.length == 2
    • \n\t
    • -104 <= xtarget, ytarget <= 104
    • \n
    \n", "content_cn": "

    \u4f60\u5728\u8fdb\u884c\u4e00\u4e2a\u7b80\u5316\u7248\u7684\u5403\u8c46\u4eba\u6e38\u620f\u3002\u4f60\u4ece [0, 0] \u70b9\u5f00\u59cb\u51fa\u53d1\uff0c\u4f60\u7684\u76ee\u7684\u5730\u662f\u00a0target = [xtarget, ytarget] \u3002\u5730\u56fe\u4e0a\u6709\u4e00\u4e9b\u963b\u788d\u8005\uff0c\u4ee5\u6570\u7ec4 ghosts \u7ed9\u51fa\uff0c\u7b2c i \u4e2a\u963b\u788d\u8005\u4ece\u00a0ghosts[i] = [xi, yi]\u00a0\u51fa\u53d1\u3002\u6240\u6709\u8f93\u5165\u5747\u4e3a \u6574\u6570\u5750\u6807 \u3002

    \n\n

    \u6bcf\u4e00\u56de\u5408\uff0c\u4f60\u548c\u963b\u788d\u8005\u4eec\u53ef\u4ee5\u540c\u65f6\u5411\u4e1c\uff0c\u897f\uff0c\u5357\uff0c\u5317\u56db\u4e2a\u65b9\u5411\u79fb\u52a8\uff0c\u6bcf\u6b21\u53ef\u4ee5\u79fb\u52a8\u5230\u8ddd\u79bb\u539f\u4f4d\u7f6e 1 \u4e2a\u5355\u4f4d \u7684\u65b0\u4f4d\u7f6e\u3002\u5f53\u7136\uff0c\u4e5f\u53ef\u4ee5\u9009\u62e9 \u4e0d\u52a8 \u3002\u6240\u6709\u52a8\u4f5c \u540c\u65f6 \u53d1\u751f\u3002

    \n\n

    \u5982\u679c\u4f60\u53ef\u4ee5\u5728\u4efb\u4f55\u963b\u788d\u8005\u6293\u4f4f\u4f60 \u4e4b\u524d \u5230\u8fbe\u76ee\u7684\u5730\uff08\u963b\u788d\u8005\u53ef\u4ee5\u91c7\u53d6\u4efb\u610f\u884c\u52a8\u65b9\u5f0f\uff09\uff0c\u5219\u88ab\u89c6\u4e3a\u9003\u8131\u6210\u529f\u3002\u5982\u679c\u4f60\u548c\u963b\u788d\u8005\u540c\u65f6\u5230\u8fbe\u4e86\u4e00\u4e2a\u4f4d\u7f6e\uff08\u5305\u62ec\u76ee\u7684\u5730\uff09\u90fd\u4e0d\u7b97\u662f\u9003\u8131\u6210\u529f\u3002

    \n\n

    \u53ea\u6709\u5728\u4f60\u6709\u53ef\u80fd\u6210\u529f\u9003\u8131\u65f6\uff0c\u8f93\u51fa true \uff1b\u5426\u5219\uff0c\u8f93\u51fa false \u3002

    \n\u00a0\n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aghosts = [[1,0],[0,3]], target = [0,1]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u76f4\u63a5\u4e00\u6b65\u5230\u8fbe\u76ee\u7684\u5730 (0,1) \uff0c\u5728 (1, 0) \u6216\u8005 (0, 3) \u4f4d\u7f6e\u7684\u963b\u788d\u8005\u90fd\u4e0d\u53ef\u80fd\u6293\u4f4f\u4f60\u3002 \n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aghosts = [[1,0]], target = [2,0]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u4f60\u9700\u8981\u8d70\u5230\u4f4d\u4e8e (2, 0) \u7684\u76ee\u7684\u5730\uff0c\u4f46\u662f\u5728 (1, 0) \u7684\u963b\u788d\u8005\u4f4d\u4e8e\u4f60\u548c\u76ee\u7684\u5730\u4e4b\u95f4\u3002 \n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aghosts = [[2,0]], target = [1,0]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u963b\u788d\u8005\u53ef\u4ee5\u548c\u4f60\u540c\u65f6\u8fbe\u5230\u76ee\u7684\u5730\u3002 \n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1aghosts = [[5,0],[-10,-2],[0,-5],[-2,-2],[-7,1]], target = [7,7]\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1aghosts = [[-1,0],[0,1],[-1,0],[0,1],[-1,0]], target = [0,0]\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= ghosts.length <= 100
    • \n\t
    • ghosts[i].length == 2
    • \n\t
    • -104 <= xi, yi <= 104
    • \n\t
    • \u540c\u4e00\u4f4d\u7f6e\u53ef\u80fd\u6709 \u591a\u4e2a\u963b\u788d\u8005 \u3002
    • \n\t
    • target.length == 2
    • \n\t
    • -104 <= xtarget, ytarget <= 104
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool escapeGhosts(vector>& ghosts, vector& target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean escapeGhosts(int[][] ghosts, int[] target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def escapeGhosts(self, ghosts, target):\n \"\"\"\n :type ghosts: List[List[int]]\n :type target: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def escapeGhosts(self, ghosts: List[List[int]], target: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool escapeGhosts(int** ghosts, int ghostsSize, int* ghostsColSize, int* target, int targetSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool EscapeGhosts(int[][] ghosts, int[] target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} ghosts\n * @param {number[]} target\n * @return {boolean}\n */\nvar escapeGhosts = function(ghosts, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} ghosts\n# @param {Integer[]} target\n# @return {Boolean}\ndef escape_ghosts(ghosts, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func escapeGhosts(_ ghosts: [[Int]], _ target: [Int]) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func escapeGhosts(ghosts [][]int, target []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def escapeGhosts(ghosts: Array[Array[Int]], target: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun escapeGhosts(ghosts: Array, target: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn escape_ghosts(ghosts: Vec>, target: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $ghosts\n * @param Integer[] $target\n * @return Boolean\n */\n function escapeGhosts($ghosts, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function escapeGhosts(ghosts: number[][], target: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (escape-ghosts ghosts target)\n (-> (listof (listof exact-integer?)) (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0789](https://leetcode-cn.com/problems/escape-the-ghosts)", "[\u9003\u8131\u963b\u788d\u8005](/solution/0700-0799/0789.Escape%20The%20Ghosts/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0789](https://leetcode.com/problems/escape-the-ghosts)", "[Escape The Ghosts](/solution/0700-0799/0789.Escape%20The%20Ghosts/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "0804", "frontend_question_id": "0788", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/rotated-digits", "url_en": "https://leetcode.com/problems/rotated-digits", "relative_path_cn": "/solution/0700-0799/0788.Rotated%20Digits/README.md", "relative_path_en": "/solution/0700-0799/0788.Rotated%20Digits/README_EN.md", "title_cn": "\u65cb\u8f6c\u6570\u5b57", "title_en": "Rotated Digits", "question_title_slug": "rotated-digits", "content_en": "

    x is a good number if after rotating each digit individually by 180 degrees, we get a valid number that is different from x. Each digit must be rotated - we cannot choose to leave it alone.

    \n\n

    A number is valid if each digit remains a digit after rotation. 0, 1, and 8 rotate to themselves; 2 and 5 rotate to each other (on this case they are rotated in a different direction, in other words 2 or 5 gets mirrored); 6 and 9 rotate to each other, and the rest of the numbers do not rotate to any other number and become invalid.

    \n\n

    Now given a positive number n, how many numbers x from 1 to n are good?

    \n\n
    \nExample:\nInput: 10\nOutput: 4\nExplanation: \nThere are four good numbers in the range [1, 10] : 2, 5, 6, 9.\nNote that 1 and 10 are not good numbers, since they remain unchanged after rotating.\n
    \n\n

    Note:

    \n\n
      \n\t
    • n will be in range [1, 10000].
    • \n
    \n", "content_cn": "

    \u6211\u4eec\u79f0\u4e00\u4e2a\u6570 X \u4e3a\u597d\u6570, \u5982\u679c\u5b83\u7684\u6bcf\u4f4d\u6570\u5b57\u9010\u4e2a\u5730\u88ab\u65cb\u8f6c 180 \u5ea6\u540e\uff0c\u6211\u4eec\u4ecd\u53ef\u4ee5\u5f97\u5230\u4e00\u4e2a\u6709\u6548\u7684\uff0c\u4e14\u548c X \u4e0d\u540c\u7684\u6570\u3002\u8981\u6c42\u6bcf\u4f4d\u6570\u5b57\u90fd\u8981\u88ab\u65cb\u8f6c\u3002

    \n\n

    \u5982\u679c\u4e00\u4e2a\u6570\u7684\u6bcf\u4f4d\u6570\u5b57\u88ab\u65cb\u8f6c\u4ee5\u540e\u4ecd\u7136\u8fd8\u662f\u4e00\u4e2a\u6570\u5b57\uff0c \u5219\u8fd9\u4e2a\u6570\u662f\u6709\u6548\u7684\u30020, 1, \u548c 8 \u88ab\u65cb\u8f6c\u540e\u4ecd\u7136\u662f\u5b83\u4eec\u81ea\u5df1\uff1b2 \u548c 5 \u53ef\u4ee5\u4e92\u76f8\u65cb\u8f6c\u6210\u5bf9\u65b9\uff08\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u5b83\u4eec\u4ee5\u4e0d\u540c\u7684\u65b9\u5411\u65cb\u8f6c\uff0c\u6362\u53e5\u8bdd\u8bf4\uff0c2 \u548c 5 \u4e92\u4e3a\u955c\u50cf\uff09\uff1b6 \u548c 9 \u540c\u7406\uff0c\u9664\u4e86\u8fd9\u4e9b\u4ee5\u5916\u5176\u4ed6\u7684\u6570\u5b57\u65cb\u8f6c\u4ee5\u540e\u90fd\u4e0d\u518d\u662f\u6709\u6548\u7684\u6570\u5b57\u3002

    \n\n

    \u73b0\u5728\u6211\u4eec\u6709\u4e00\u4e2a\u6b63\u6574\u6570 N, \u8ba1\u7b97\u4ece 1 \u5230 N \u4e2d\u6709\u591a\u5c11\u4e2a\u6570 X \u662f\u597d\u6570\uff1f

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165: 10\n\u8f93\u51fa: 4\n\u89e3\u91ca: \n\u5728[1, 10]\u4e2d\u6709\u56db\u4e2a\u597d\u6570\uff1a 2, 5, 6, 9\u3002\n\u6ce8\u610f 1 \u548c 10 \u4e0d\u662f\u597d\u6570, \u56e0\u4e3a\u4ed6\u4eec\u5728\u65cb\u8f6c\u4e4b\u540e\u4e0d\u53d8\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • N \u7684\u53d6\u503c\u8303\u56f4\u662f [1, 10000]\u3002
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int rotatedDigits(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int rotatedDigits(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def rotatedDigits(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def rotatedDigits(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint rotatedDigits(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int RotatedDigits(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar rotatedDigits = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef rotated_digits(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func rotatedDigits(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func rotatedDigits(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def rotatedDigits(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun rotatedDigits(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn rotated_digits(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function rotatedDigits($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function rotatedDigits(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (rotated-digits n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0788](https://leetcode-cn.com/problems/rotated-digits)", "[\u65cb\u8f6c\u6570\u5b57](/solution/0700-0799/0788.Rotated%20Digits/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0788](https://leetcode.com/problems/rotated-digits)", "[Rotated Digits](/solution/0700-0799/0788.Rotated%20Digits/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "0803", "frontend_question_id": "0787", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/cheapest-flights-within-k-stops", "url_en": "https://leetcode.com/problems/cheapest-flights-within-k-stops", "relative_path_cn": "/solution/0700-0799/0787.Cheapest%20Flights%20Within%20K%20Stops/README.md", "relative_path_en": "/solution/0700-0799/0787.Cheapest%20Flights%20Within%20K%20Stops/README_EN.md", "title_cn": "K \u7ad9\u4e2d\u8f6c\u5185\u6700\u4fbf\u5b9c\u7684\u822a\u73ed", "title_en": "Cheapest Flights Within K Stops", "question_title_slug": "cheapest-flights-within-k-stops", "content_en": "

    There are n cities connected by some number of flights. You are given an array flights where flights[i] = [fromi, toi, pricei] indicates that there is a flight from city fromi to city toi with cost pricei.

    \n\n

    You are also given three integers src, dst, and k, return the cheapest price from src to dst with at most k stops. If there is no such route, return -1.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: n = 3, flights = [[0,1,100],[1,2,100],[0,2,500]], src = 0, dst = 2, k = 1\nOutput: 200\nExplanation: The graph is shown.\nThe cheapest price from city 0 to city 2 with at most 1 stop costs 200, as marked red in the picture.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: n = 3, flights = [[0,1,100],[1,2,100],[0,2,500]], src = 0, dst = 2, k = 0\nOutput: 500\nExplanation: The graph is shown.\nThe cheapest price from city 0 to city 2 with at most 0 stop costs 500, as marked blue in the picture.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 100
    • \n\t
    • 0 <= flights.length <= (n * (n - 1) / 2)
    • \n\t
    • flights[i].length == 3
    • \n\t
    • 0 <= fromi, toi < n
    • \n\t
    • fromi != toi
    • \n\t
    • 1 <= pricei <= 104
    • \n\t
    • There will not be any multiple flights between two cities.
    • \n\t
    • 0 <= src, dst, k < n
    • \n\t
    • src != dst
    • \n
    \n", "content_cn": "

    \u6709 n \u4e2a\u57ce\u5e02\u901a\u8fc7 m \u4e2a\u822a\u73ed\u8fde\u63a5\u3002\u6bcf\u4e2a\u822a\u73ed\u90fd\u4ece\u57ce\u5e02 u \u5f00\u59cb\uff0c\u4ee5\u4ef7\u683c w \u62b5\u8fbe v\u3002

    \n\n

    \u73b0\u5728\u7ed9\u5b9a\u6240\u6709\u7684\u57ce\u5e02\u548c\u822a\u73ed\uff0c\u4ee5\u53ca\u51fa\u53d1\u57ce\u5e02 src \u548c\u76ee\u7684\u5730 dst\uff0c\u4f60\u7684\u4efb\u52a1\u662f\u627e\u5230\u4ece src \u5230 dst \u6700\u591a\u7ecf\u8fc7 k\u00a0\u7ad9\u4e2d\u8f6c\u7684\u6700\u4fbf\u5b9c\u7684\u4ef7\u683c\u3002 \u5982\u679c\u6ca1\u6709\u8fd9\u6837\u7684\u8def\u7ebf\uff0c\u5219\u8f93\u51fa -1\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165: \nn = 3, edges = [[0,1,100],[1,2,100],[0,2,500]]\nsrc = 0, dst = 2, k = 1\n\u8f93\u51fa: 200\n\u89e3\u91ca: \n\u57ce\u5e02\u822a\u73ed\u56fe\u5982\u4e0b\n\"\"\n\n\u4ece\u57ce\u5e02 0 \u5230\u57ce\u5e02 2 \u5728 1 \u7ad9\u4e2d\u8f6c\u4ee5\u5185\u7684\u6700\u4fbf\u5b9c\u4ef7\u683c\u662f 200\uff0c\u5982\u56fe\u4e2d\u7ea2\u8272\u6240\u793a\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165: \nn = 3, edges = [[0,1,100],[1,2,100],[0,2,500]]\nsrc = 0, dst = 2, k = 0\n\u8f93\u51fa: 500\n\u89e3\u91ca: \n\u57ce\u5e02\u822a\u73ed\u56fe\u5982\u4e0b\n\"\"\n\n\u4ece\u57ce\u5e02 0 \u5230\u57ce\u5e02 2 \u5728 0 \u7ad9\u4e2d\u8f6c\u4ee5\u5185\u7684\u6700\u4fbf\u5b9c\u4ef7\u683c\u662f 500\uff0c\u5982\u56fe\u4e2d\u84dd\u8272\u6240\u793a\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n \u8303\u56f4\u662f [1, 100]\uff0c\u57ce\u5e02\u6807\u7b7e\u4ece 0 \u5230 n - 1
    • \n\t
    • \u822a\u73ed\u6570\u91cf\u8303\u56f4\u662f [0, n * (n - 1) / 2]
    • \n\t
    • \u6bcf\u4e2a\u822a\u73ed\u7684\u683c\u5f0f (src, dst, price)
    • \n\t
    • \u6bcf\u4e2a\u822a\u73ed\u7684\u4ef7\u683c\u8303\u56f4\u662f [1, 10000]
    • \n\t
    • k \u8303\u56f4\u662f [0, n - 1]
    • \n\t
    • \u822a\u73ed\u6ca1\u6709\u91cd\u590d\uff0c\u4e14\u4e0d\u5b58\u5728\u81ea\u73af
    • \n
    \n", "tags_en": ["Heap", "Breadth-first Search", "Dynamic Programming"], "tags_cn": ["\u5806", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findCheapestPrice(int n, vector>& flights, int src, int dst, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findCheapestPrice(int n, int[][] flights, int src, int dst, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findCheapestPrice(self, n, flights, src, dst, k):\n \"\"\"\n :type n: int\n :type flights: List[List[int]]\n :type src: int\n :type dst: int\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findCheapestPrice(self, n: int, flights: List[List[int]], src: int, dst: int, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findCheapestPrice(int n, int** flights, int flightsSize, int* flightsColSize, int src, int dst, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindCheapestPrice(int n, int[][] flights, int src, int dst, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} flights\n * @param {number} src\n * @param {number} dst\n * @param {number} k\n * @return {number}\n */\nvar findCheapestPrice = function(n, flights, src, dst, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} flights\n# @param {Integer} src\n# @param {Integer} dst\n# @param {Integer} k\n# @return {Integer}\ndef find_cheapest_price(n, flights, src, dst, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findCheapestPrice(_ n: Int, _ flights: [[Int]], _ src: Int, _ dst: Int, _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findCheapestPrice(n int, flights [][]int, src int, dst int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findCheapestPrice(n: Int, flights: Array[Array[Int]], src: Int, dst: Int, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findCheapestPrice(n: Int, flights: Array, src: Int, dst: Int, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_cheapest_price(n: i32, flights: Vec>, src: i32, dst: i32, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $flights\n * @param Integer $src\n * @param Integer $dst\n * @param Integer $k\n * @return Integer\n */\n function findCheapestPrice($n, $flights, $src, $dst, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findCheapestPrice(n: number, flights: number[][], src: number, dst: number, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-cheapest-price n flights src dst k)\n (-> exact-integer? (listof (listof exact-integer?)) exact-integer? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0787](https://leetcode-cn.com/problems/cheapest-flights-within-k-stops)", "[K \u7ad9\u4e2d\u8f6c\u5185\u6700\u4fbf\u5b9c\u7684\u822a\u73ed](/solution/0700-0799/0787.Cheapest%20Flights%20Within%20K%20Stops/README.md)", "`\u5806`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0787](https://leetcode.com/problems/cheapest-flights-within-k-stops)", "[Cheapest Flights Within K Stops](/solution/0700-0799/0787.Cheapest%20Flights%20Within%20K%20Stops/README_EN.md)", "`Heap`,`Breadth-first Search`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0802", "frontend_question_id": "0786", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/k-th-smallest-prime-fraction", "url_en": "https://leetcode.com/problems/k-th-smallest-prime-fraction", "relative_path_cn": "/solution/0700-0799/0786.K-th%20Smallest%20Prime%20Fraction/README.md", "relative_path_en": "/solution/0700-0799/0786.K-th%20Smallest%20Prime%20Fraction/README_EN.md", "title_cn": "\u7b2c K \u4e2a\u6700\u5c0f\u7684\u7d20\u6570\u5206\u6570", "title_en": "K-th Smallest Prime Fraction", "question_title_slug": "k-th-smallest-prime-fraction", "content_en": "

    You are given a sorted integer array arr containing 1 and prime numbers, where all the integers of arr are unique. You are also given an integer k.

    \n\n

    For every i and j where 0 <= i < j < arr.length, we consider the fraction arr[i] / arr[j].

    \n\n

    Return the kth smallest fraction considered. Return your answer as an array of integers of size 2, where answer[0] == arr[i] and answer[1] == arr[j].

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arr = [1,2,3,5], k = 3\nOutput: [2,5]\nExplanation: The fractions to be considered in sorted order are:\n1/5, 1/3, 2/5, 1/2, 3/5, and 2/3.\nThe third fraction is 2/5.\n
    \n\n

    Example 2:

    \n\n
    \nInput: arr = [1,7], k = 1\nOutput: [1,7]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= arr.length <= 1000
    • \n\t
    • 1 <= arr[i] <= 3 * 104
    • \n\t
    • arr[0] == 1
    • \n\t
    • arr[i] is a prime number for i > 0.
    • \n\t
    • All the numbers of arr are unique and sorted in strictly increasing order.
    • \n\t
    • 1 <= k <= arr.length * (arr.length - 1) / 2
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6309\u9012\u589e\u987a\u5e8f\u6392\u5e8f\u7684\u6570\u7ec4 arr \u548c\u4e00\u4e2a\u6574\u6570 k \u3002\u6570\u7ec4 arr \u7531 1 \u548c\u82e5\u5e72 \u7d20\u6570\u00a0 \u7ec4\u6210\uff0c\u4e14\u5176\u4e2d\u6240\u6709\u6574\u6570\u4e92\u4e0d\u76f8\u540c\u3002

    \n\n

    \u5bf9\u4e8e\u6bcf\u5bf9\u6ee1\u8db3 0 < i < j < arr.length \u7684 i \u548c j \uff0c\u53ef\u4ee5\u5f97\u5230\u5206\u6570 arr[i] / arr[j] \u3002

    \n\n

    \u90a3\u4e48\u7b2c\u00a0k\u00a0\u4e2a\u6700\u5c0f\u7684\u5206\u6570\u662f\u591a\u5c11\u5462?\u00a0 \u4ee5\u957f\u5ea6\u4e3a 2 \u7684\u6574\u6570\u6570\u7ec4\u8fd4\u56de\u4f60\u7684\u7b54\u6848, \u8fd9\u91cc\u00a0answer[0] == arr[i]\u00a0\u4e14\u00a0answer[1] == arr[j] \u3002

    \n\u00a0\n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [1,2,3,5], k = 3\n\u8f93\u51fa\uff1a[2,5]\n\u89e3\u91ca\uff1a\u5df2\u6784\u9020\u597d\u7684\u5206\u6570,\u6392\u5e8f\u540e\u5982\u4e0b\u6240\u793a: \n1/5, 1/3, 2/5, 1/2, 3/5, 2/3\n\u5f88\u660e\u663e\u7b2c\u4e09\u4e2a\u6700\u5c0f\u7684\u5206\u6570\u662f 2/5\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [1,7], k = 1\n\u8f93\u51fa\uff1a[1,7]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= arr.length <= 1000
    • \n\t
    • 1 <= arr[i] <= 3 * 104
    • \n\t
    • arr[0] == 1
    • \n\t
    • arr[i] \u662f\u4e00\u4e2a \u7d20\u6570 \uff0ci > 0
    • \n\t
    • arr \u4e2d\u7684\u6240\u6709\u6570\u5b57 \u4e92\u4e0d\u76f8\u540c \uff0c\u4e14\u6309 \u4e25\u683c\u9012\u589e \u6392\u5e8f
    • \n\t
    • 1 <= k <= arr.length * (arr.length - 1) / 2
    • \n
    \n", "tags_en": ["Heap", "Binary Search"], "tags_cn": ["\u5806", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector kthSmallestPrimeFraction(vector& arr, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] kthSmallestPrimeFraction(int[] arr, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def kthSmallestPrimeFraction(self, arr, k):\n \"\"\"\n :type arr: List[int]\n :type k: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def kthSmallestPrimeFraction(self, arr: List[int], k: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* kthSmallestPrimeFraction(int* arr, int arrSize, int k, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] KthSmallestPrimeFraction(int[] arr, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @param {number} k\n * @return {number[]}\n */\nvar kthSmallestPrimeFraction = function(arr, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @param {Integer} k\n# @return {Integer[]}\ndef kth_smallest_prime_fraction(arr, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func kthSmallestPrimeFraction(_ arr: [Int], _ k: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func kthSmallestPrimeFraction(arr []int, k int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def kthSmallestPrimeFraction(arr: Array[Int], k: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun kthSmallestPrimeFraction(arr: IntArray, k: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn kth_smallest_prime_fraction(arr: Vec, k: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @param Integer $k\n * @return Integer[]\n */\n function kthSmallestPrimeFraction($arr, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function kthSmallestPrimeFraction(arr: number[], k: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (kth-smallest-prime-fraction arr k)\n (-> (listof exact-integer?) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0786](https://leetcode-cn.com/problems/k-th-smallest-prime-fraction)", "[\u7b2c K \u4e2a\u6700\u5c0f\u7684\u7d20\u6570\u5206\u6570](/solution/0700-0799/0786.K-th%20Smallest%20Prime%20Fraction/README.md)", "`\u5806`,`\u4e8c\u5206\u67e5\u627e`", "\u56f0\u96be", ""], "md_table_row_en": ["[0786](https://leetcode.com/problems/k-th-smallest-prime-fraction)", "[K-th Smallest Prime Fraction](/solution/0700-0799/0786.K-th%20Smallest%20Prime%20Fraction/README_EN.md)", "`Heap`,`Binary Search`", "Hard", ""]}, {"question_id": "0801", "frontend_question_id": "0785", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/is-graph-bipartite", "url_en": "https://leetcode.com/problems/is-graph-bipartite", "relative_path_cn": "/solution/0700-0799/0785.Is%20Graph%20Bipartite/README.md", "relative_path_en": "/solution/0700-0799/0785.Is%20Graph%20Bipartite/README_EN.md", "title_cn": "\u5224\u65ad\u4e8c\u5206\u56fe", "title_en": "Is Graph Bipartite", "question_title_slug": "is-graph-bipartite", "content_en": "

    There is an undirected graph with n nodes, where each node is numbered between 0 and n - 1. You are given a 2D array graph, where graph[u] is an array of nodes that node u is adjacent to. More formally, for each v in graph[u], there is an undirected edge between node u and node v. The graph has the following properties:

    \n\n
      \n\t
    • There are no self-edges (graph[u] does not contain u).
    • \n\t
    • There are no parallel edges (graph[u] does not contain duplicate values).
    • \n\t
    • If v is in graph[u], then u is in graph[v] (the graph is undirected).
    • \n\t
    • The graph may not be connected, meaning there may be two nodes u and v such that there is no path between them.
    • \n
    \n\n

    A graph is bipartite if the nodes can be partitioned into two independent sets A and B such that every edge in the graph connects a node in set A and a node in set B.

    \n\n

    Return true if and only if it is bipartite.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: graph = [[1,2,3],[0,2],[0,1,3],[0,2]]\nOutput: false\nExplanation: There is no way to partition the nodes into two independent sets such that every edge connects a node in one and a node in the other.
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: graph = [[1,3],[0,2],[1,3],[0,2]]\nOutput: true\nExplanation: We can partition the nodes into two sets: {0, 2} and {1, 3}.
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • graph.length == n
    • \n\t
    • 1 <= n <= 100
    • \n\t
    • 0 <= graph[u].length < n
    • \n\t
    • 0 <= graph[u][i] <= n - 1
    • \n\t
    • graph[u] does not contain u.
    • \n\t
    • All the values of graph[u] are unique.
    • \n\t
    • If graph[u] contains v, then graph[v] contains u.
    • \n
    \n", "content_cn": "\u5b58\u5728\u4e00\u4e2a \u65e0\u5411\u56fe \uff0c\u56fe\u4e2d\u6709 n \u4e2a\u8282\u70b9\u3002\u5176\u4e2d\u6bcf\u4e2a\u8282\u70b9\u90fd\u6709\u4e00\u4e2a\u4ecb\u4e8e 0 \u5230 n - 1 \u4e4b\u95f4\u7684\u552f\u4e00\u7f16\u53f7\u3002\u7ed9\u4f60\u4e00\u4e2a\u4e8c\u7ef4\u6570\u7ec4 graph \uff0c\u5176\u4e2d graph[u] \u662f\u4e00\u4e2a\u8282\u70b9\u6570\u7ec4\uff0c\u7531\u8282\u70b9 u \u7684\u90bb\u63a5\u8282\u70b9\u7ec4\u6210\u3002\u5f62\u5f0f\u4e0a\uff0c\u5bf9\u4e8e\u00a0graph[u] \u4e2d\u7684\u6bcf\u4e2a v \uff0c\u90fd\u5b58\u5728\u4e00\u6761\u4f4d\u4e8e\u8282\u70b9 u \u548c\u8282\u70b9 v \u4e4b\u95f4\u7684\u65e0\u5411\u8fb9\u3002\u8be5\u65e0\u5411\u56fe\u540c\u65f6\u5177\u6709\u4ee5\u4e0b\u5c5e\u6027\uff1a\n
      \n\t
    • \u4e0d\u5b58\u5728\u81ea\u73af\uff08graph[u] \u4e0d\u5305\u542b u\uff09\u3002
    • \n\t
    • \u4e0d\u5b58\u5728\u5e73\u884c\u8fb9\uff08graph[u] \u4e0d\u5305\u542b\u91cd\u590d\u503c\uff09\u3002
    • \n\t
    • \u5982\u679c v \u5728 graph[u] \u5185\uff0c\u90a3\u4e48 u \u4e5f\u5e94\u8be5\u5728 graph[v] \u5185\uff08\u8be5\u56fe\u662f\u65e0\u5411\u56fe\uff09
    • \n\t
    • \u8fd9\u4e2a\u56fe\u53ef\u80fd\u4e0d\u662f\u8fde\u901a\u56fe\uff0c\u4e5f\u5c31\u662f\u8bf4\u4e24\u4e2a\u8282\u70b9 u \u548c v \u4e4b\u95f4\u53ef\u80fd\u4e0d\u5b58\u5728\u4e00\u6761\u8fde\u901a\u5f7c\u6b64\u7684\u8def\u5f84\u3002
    • \n
    \n\n

    \u4e8c\u5206\u56fe \u5b9a\u4e49\uff1a\u5982\u679c\u80fd\u5c06\u4e00\u4e2a\u56fe\u7684\u8282\u70b9\u96c6\u5408\u5206\u5272\u6210\u4e24\u4e2a\u72ec\u7acb\u7684\u5b50\u96c6 A \u548c B \uff0c\u5e76\u4f7f\u56fe\u4e2d\u7684\u6bcf\u4e00\u6761\u8fb9\u7684\u4e24\u4e2a\u8282\u70b9\u4e00\u4e2a\u6765\u81ea A \u96c6\u5408\uff0c\u4e00\u4e2a\u6765\u81ea B \u96c6\u5408\uff0c\u5c31\u5c06\u8fd9\u4e2a\u56fe\u79f0\u4e3a \u4e8c\u5206\u56fe \u3002

    \n\n

    \u5982\u679c\u56fe\u662f\u4e8c\u5206\u56fe\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1agraph = [[1,2,3],[0,2],[0,1,3],[0,2]]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u4e0d\u80fd\u5c06\u8282\u70b9\u5206\u5272\u6210\u4e24\u4e2a\u72ec\u7acb\u7684\u5b50\u96c6\uff0c\u4ee5\u4f7f\u6bcf\u6761\u8fb9\u90fd\u8fde\u901a\u4e00\u4e2a\u5b50\u96c6\u4e2d\u7684\u4e00\u4e2a\u8282\u70b9\u4e0e\u53e6\u4e00\u4e2a\u5b50\u96c6\u4e2d\u7684\u4e00\u4e2a\u8282\u70b9\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1agraph = [[1,3],[0,2],[1,3],[0,2]]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u53ef\u4ee5\u5c06\u8282\u70b9\u5206\u6210\u4e24\u7ec4: {0, 2} \u548c {1, 3} \u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • graph.length == n
    • \n\t
    • 1 <= n <= 100
    • \n\t
    • 0 <= graph[u].length < n
    • \n\t
    • 0 <= graph[u][i] <= n - 1
    • \n\t
    • graph[u] \u4e0d\u4f1a\u5305\u542b u
    • \n\t
    • graph[u] \u7684\u6240\u6709\u503c \u4e92\u4e0d\u76f8\u540c
    • \n\t
    • \u5982\u679c graph[u] \u5305\u542b v\uff0c\u90a3\u4e48 graph[v] \u4e5f\u4f1a\u5305\u542b u
    • \n
    \n", "tags_en": ["Depth-first Search", "Breadth-first Search", "Graph"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isBipartite(vector>& graph) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isBipartite(int[][] graph) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isBipartite(self, graph):\n \"\"\"\n :type graph: List[List[int]]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isBipartite(self, graph: List[List[int]]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isBipartite(int** graph, int graphSize, int* graphColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsBipartite(int[][] graph) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} graph\n * @return {boolean}\n */\nvar isBipartite = function(graph) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} graph\n# @return {Boolean}\ndef is_bipartite(graph)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isBipartite(_ graph: [[Int]]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isBipartite(graph [][]int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isBipartite(graph: Array[Array[Int]]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isBipartite(graph: Array): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_bipartite(graph: Vec>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $graph\n * @return Boolean\n */\n function isBipartite($graph) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isBipartite(graph: number[][]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-bipartite graph)\n (-> (listof (listof exact-integer?)) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0785](https://leetcode-cn.com/problems/is-graph-bipartite)", "[\u5224\u65ad\u4e8c\u5206\u56fe](/solution/0700-0799/0785.Is%20Graph%20Bipartite/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u56fe`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0785](https://leetcode.com/problems/is-graph-bipartite)", "[Is Graph Bipartite](/solution/0700-0799/0785.Is%20Graph%20Bipartite/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`,`Graph`", "Medium", ""]}, {"question_id": "0800", "frontend_question_id": "0784", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/letter-case-permutation", "url_en": "https://leetcode.com/problems/letter-case-permutation", "relative_path_cn": "/solution/0700-0799/0784.Letter%20Case%20Permutation/README.md", "relative_path_en": "/solution/0700-0799/0784.Letter%20Case%20Permutation/README_EN.md", "title_cn": "\u5b57\u6bcd\u5927\u5c0f\u5199\u5168\u6392\u5217", "title_en": "Letter Case Permutation", "question_title_slug": "letter-case-permutation", "content_en": "

    Given a string s, we can transform every letter individually to be lowercase or uppercase to create another string.

    \n\n

    Return a list of all possible strings we could create. You can return the output in any order.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "a1b2"\nOutput: ["a1b2","a1B2","A1b2","A1B2"]\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "3z4"\nOutput: ["3z4","3Z4"]\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "12345"\nOutput: ["12345"]\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "0"\nOutput: ["0"]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • s will be a string with length between 1 and 12.
    • \n\t
    • s will consist only of letters or digits.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32S\uff0c\u901a\u8fc7\u5c06\u5b57\u7b26\u4e32S\u4e2d\u7684\u6bcf\u4e2a\u5b57\u6bcd\u8f6c\u53d8\u5927\u5c0f\u5199\uff0c\u6211\u4eec\u53ef\u4ee5\u83b7\u5f97\u4e00\u4e2a\u65b0\u7684\u5b57\u7b26\u4e32\u3002\u8fd4\u56de\u6240\u6709\u53ef\u80fd\u5f97\u5230\u7684\u5b57\u7b26\u4e32\u96c6\u5408\u3002

    \n\n

     

    \n\n
    \u793a\u4f8b\uff1a\n\u8f93\u5165\uff1aS = "a1b2"\n\u8f93\u51fa\uff1a["a1b2", "a1B2", "A1b2", "A1B2"]\n\n\u8f93\u5165\uff1aS = "3z4"\n\u8f93\u51fa\uff1a["3z4", "3Z4"]\n\n\u8f93\u5165\uff1aS = "12345"\n\u8f93\u51fa\uff1a["12345"]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • S \u7684\u957f\u5ea6\u4e0d\u8d85\u8fc712\u3002
    • \n\t
    • S \u4ec5\u7531\u6570\u5b57\u548c\u5b57\u6bcd\u7ec4\u6210\u3002
    • \n
    \n", "tags_en": ["Bit Manipulation", "Backtracking"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector letterCasePermutation(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List letterCasePermutation(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def letterCasePermutation(self, s):\n \"\"\"\n :type s: str\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def letterCasePermutation(self, s: str) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** letterCasePermutation(char * s, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList LetterCasePermutation(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string[]}\n */\nvar letterCasePermutation = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String[]}\ndef letter_case_permutation(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func letterCasePermutation(_ s: String) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func letterCasePermutation(s string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def letterCasePermutation(s: String): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun letterCasePermutation(s: String): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn letter_case_permutation(s: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String[]\n */\n function letterCasePermutation($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function letterCasePermutation(s: string): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (letter-case-permutation s)\n (-> string? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0784](https://leetcode-cn.com/problems/letter-case-permutation)", "[\u5b57\u6bcd\u5927\u5c0f\u5199\u5168\u6392\u5217](/solution/0700-0799/0784.Letter%20Case%20Permutation/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0784](https://leetcode.com/problems/letter-case-permutation)", "[Letter Case Permutation](/solution/0700-0799/0784.Letter%20Case%20Permutation/README_EN.md)", "`Bit Manipulation`,`Backtracking`", "Medium", ""]}, {"question_id": "0799", "frontend_question_id": "0783", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-distance-between-bst-nodes", "url_en": "https://leetcode.com/problems/minimum-distance-between-bst-nodes", "relative_path_cn": "/solution/0700-0799/0783.Minimum%20Distance%20Between%20BST%20Nodes/README.md", "relative_path_en": "/solution/0700-0799/0783.Minimum%20Distance%20Between%20BST%20Nodes/README_EN.md", "title_cn": "\u4e8c\u53c9\u641c\u7d22\u6811\u8282\u70b9\u6700\u5c0f\u8ddd\u79bb", "title_en": "Minimum Distance Between BST Nodes", "question_title_slug": "minimum-distance-between-bst-nodes", "content_en": "

    Given the root of a Binary Search Tree (BST), return the minimum difference between the values of any two different nodes in the tree.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [4,2,6,1,3]\nOutput: 1\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [1,0,48,null,null,12,49]\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [2, 100].
    • \n\t
    • 0 <= Node.val <= 105
    • \n
    \n\n

     

    \n

    Note: This question is the same as 530: https://leetcode.com/problems/minimum-absolute-difference-in-bst/

    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6839\u8282\u70b9 root \uff0c\u8fd4\u56de \u6811\u4e2d\u4efb\u610f\u4e24\u4e0d\u540c\u8282\u70b9\u503c\u4e4b\u95f4\u7684\u6700\u5c0f\u5dee\u503c \u3002

    \n\n

    \u6ce8\u610f\uff1a\u672c\u9898\u4e0e 530\uff1ahttps://leetcode-cn.com/problems/minimum-absolute-difference-in-bst/ \u76f8\u540c

    \n\n

    \u00a0

    \n\n
    \n
    \n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [4,2,6,1,3]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [1,0,48,null,null,12,49]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u6570\u76ee\u5728\u8303\u56f4 [2, 100] \u5185
    • \n\t
    • 0 <= Node.val <= 105
    • \n\t
    • \u5dee\u503c\u662f\u4e00\u4e2a\u6b63\u6570\uff0c\u5176\u6570\u503c\u7b49\u4e8e\u4e24\u503c\u4e4b\u5dee\u7684\u7edd\u5bf9\u503c
    • \n
    \n
    \n
    \n", "tags_en": ["Tree", "Depth-first Search", "Recursion"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u9012\u5f52"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int minDiffInBST(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int minDiffInBST(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def minDiffInBST(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def minDiffInBST(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint minDiffInBST(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int MinDiffInBST(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar minDiffInBST = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef min_diff_in_bst(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func minDiffInBST(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc minDiffInBST(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def minDiffInBST(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun minDiffInBST(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn min_diff_in_bst(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function minDiffInBST($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction minDiffInBST(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (min-diff-in-bst root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0783](https://leetcode-cn.com/problems/minimum-distance-between-bst-nodes)", "[\u4e8c\u53c9\u641c\u7d22\u6811\u8282\u70b9\u6700\u5c0f\u8ddd\u79bb](/solution/0700-0799/0783.Minimum%20Distance%20Between%20BST%20Nodes/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u9012\u5f52`", "\u7b80\u5355", ""], "md_table_row_en": ["[0783](https://leetcode.com/problems/minimum-distance-between-bst-nodes)", "[Minimum Distance Between BST Nodes](/solution/0700-0799/0783.Minimum%20Distance%20Between%20BST%20Nodes/README_EN.md)", "`Tree`,`Depth-first Search`,`Recursion`", "Easy", ""]}, {"question_id": "0798", "frontend_question_id": "0782", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/transform-to-chessboard", "url_en": "https://leetcode.com/problems/transform-to-chessboard", "relative_path_cn": "/solution/0700-0799/0782.Transform%20to%20Chessboard/README.md", "relative_path_en": "/solution/0700-0799/0782.Transform%20to%20Chessboard/README_EN.md", "title_cn": "\u53d8\u4e3a\u68cb\u76d8", "title_en": "Transform to Chessboard", "question_title_slug": "transform-to-chessboard", "content_en": "

    An N x N board contains only 0s and 1s. In each move, you can swap any 2 rows with each other, or any 2 columns with each other.

    \r\n\r\n

    What is the minimum number of moves to transform the board into a "chessboard" - a board where no 0s and no 1s are 4-directionally adjacent? If the task is impossible, return -1.

    \r\n\r\n
    \r\nExamples:\r\nInput: board = [[0,1,1,0],[0,1,1,0],[1,0,0,1],[1,0,0,1]]\r\nOutput: 2\r\nExplanation:\r\nOne potential sequence of moves is shown below, from left to right:\r\n\r\n0110     1010     1010\r\n0110 --> 1010 --> 0101\r\n1001     0101     1010\r\n1001     0101     0101\r\n\r\nThe first move swaps the first and second column.\r\nThe second move swaps the second and third row.\r\n\r\n\r\nInput: board = [[0, 1], [1, 0]]\r\nOutput: 0\r\nExplanation:\r\nAlso note that the board with 0 in the top left corner,\r\n01\r\n10\r\n\r\nis also a valid chessboard.\r\n\r\nInput: board = [[1, 0], [1, 0]]\r\nOutput: -1\r\nExplanation:\r\nNo matter what sequence of moves you make, you cannot end with a valid chessboard.\r\n
    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    • board will have the same number of rows and columns, a number in the range [2, 30].
    • \r\n\t
    • board[i][j] will be only 0s or 1s.
    • \r\n
    \r\n", "content_cn": "

    \u4e00\u4e2a N x N\u7684 board \u4ec5\u7531 0 \u548c 1 \u7ec4\u6210 \u3002\u6bcf\u6b21\u79fb\u52a8\uff0c\u4f60\u80fd\u4efb\u610f\u4ea4\u6362\u4e24\u5217\u6216\u662f\u4e24\u884c\u7684\u4f4d\u7f6e\u3002

    \n\n

    \u8f93\u51fa\u5c06\u8fd9\u4e2a\u77e9\u9635\u53d8\u4e3a “\u68cb\u76d8” \u6240\u9700\u7684\u6700\u5c0f\u79fb\u52a8\u6b21\u6570\u3002“\u68cb\u76d8” \u662f\u6307\u4efb\u610f\u4e00\u683c\u7684\u4e0a\u4e0b\u5de6\u53f3\u56db\u4e2a\u65b9\u5411\u7684\u503c\u5747\u4e0e\u672c\u8eab\u4e0d\u540c\u7684\u77e9\u9635\u3002\u5982\u679c\u4e0d\u5b58\u5728\u53ef\u884c\u7684\u53d8\u6362\uff0c\u8f93\u51fa -1\u3002

    \n\n
    \u793a\u4f8b:\n\u8f93\u5165: board = [[0,1,1,0],[0,1,1,0],[1,0,0,1],[1,0,0,1]]\n\u8f93\u51fa: 2\n\u89e3\u91ca:\n\u4e00\u79cd\u53ef\u884c\u7684\u53d8\u6362\u65b9\u5f0f\u5982\u4e0b\uff0c\u4ece\u5de6\u5230\u53f3\uff1a\n\n0110     1010     1010\n0110 --> 1010 --> 0101\n1001     0101     1010\n1001     0101     0101\n\n\u7b2c\u4e00\u6b21\u79fb\u52a8\u4ea4\u6362\u4e86\u7b2c\u4e00\u5217\u548c\u7b2c\u4e8c\u5217\u3002\n\u7b2c\u4e8c\u6b21\u79fb\u52a8\u4ea4\u6362\u4e86\u7b2c\u4e8c\u884c\u548c\u7b2c\u4e09\u884c\u3002\n\n\n\u8f93\u5165: board = [[0, 1], [1, 0]]\n\u8f93\u51fa: 0\n\u89e3\u91ca:\n\u6ce8\u610f\u5de6\u4e0a\u89d2\u7684\u683c\u503c\u4e3a0\u65f6\u4e5f\u662f\u5408\u6cd5\u7684\u68cb\u76d8\uff0c\u5982\uff1a\n\n01\n10\n\n\u4e5f\u662f\u5408\u6cd5\u7684\u68cb\u76d8.\n\n\u8f93\u5165: board = [[1, 0], [1, 0]]\n\u8f93\u51fa: -1\n\u89e3\u91ca:\n\u4efb\u610f\u7684\u53d8\u6362\u90fd\u4e0d\u80fd\u4f7f\u8fd9\u4e2a\u8f93\u5165\u53d8\u4e3a\u5408\u6cd5\u7684\u68cb\u76d8\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • board \u662f\u65b9\u9635\uff0c\u4e14\u884c\u5217\u6570\u7684\u8303\u56f4\u662f[2, 30]\u3002
    • \n\t
    • board[i][j] \u5c06\u53ea\u5305\u542b 0\u6216 1\u3002
    • \n
    \n", "tags_en": ["Array", "Math"], "tags_cn": ["\u6570\u7ec4", "\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int movesToChessboard(vector>& board) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int movesToChessboard(int[][] board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def movesToChessboard(self, board):\n \"\"\"\n :type board: List[List[int]]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def movesToChessboard(self, board: List[List[int]]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint movesToChessboard(int** board, int boardSize, int* boardColSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MovesToChessboard(int[][] board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} board\n * @return {number}\n */\nvar movesToChessboard = function(board) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} board\n# @return {Integer}\ndef moves_to_chessboard(board)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func movesToChessboard(_ board: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func movesToChessboard(board [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def movesToChessboard(board: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun movesToChessboard(board: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn moves_to_chessboard(board: Vec>) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $board\n * @return Integer\n */\n function movesToChessboard($board) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function movesToChessboard(board: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (moves-to-chessboard board)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0782](https://leetcode-cn.com/problems/transform-to-chessboard)", "[\u53d8\u4e3a\u68cb\u76d8](/solution/0700-0799/0782.Transform%20to%20Chessboard/README.md)", "`\u6570\u7ec4`,`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[0782](https://leetcode.com/problems/transform-to-chessboard)", "[Transform to Chessboard](/solution/0700-0799/0782.Transform%20to%20Chessboard/README_EN.md)", "`Array`,`Math`", "Hard", ""]}, {"question_id": "0797", "frontend_question_id": "0781", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/rabbits-in-forest", "url_en": "https://leetcode.com/problems/rabbits-in-forest", "relative_path_cn": "/solution/0700-0799/0781.Rabbits%20in%20Forest/README.md", "relative_path_en": "/solution/0700-0799/0781.Rabbits%20in%20Forest/README_EN.md", "title_cn": "\u68ee\u6797\u4e2d\u7684\u5154\u5b50", "title_en": "Rabbits in Forest", "question_title_slug": "rabbits-in-forest", "content_en": "

    In a forest, each rabbit has some color. Some subset of rabbits (possibly all of them) tell you how many other rabbits have the same color as them. Those answers are placed in an array.

    \r\n\r\n

    Return the minimum number of rabbits that could be in the forest.

    \r\n\r\n
    \r\nExamples:\r\nInput: answers = [1, 1, 2]\r\nOutput: 5\r\nExplanation:\r\nThe two rabbits that answered "1" could both be the same color, say red.\r\nThe rabbit than answered "2" can't be red or the answers would be inconsistent.\r\nSay the rabbit that answered "2" was blue.\r\nThen there should be 2 other blue rabbits in the forest that didn't answer into the array.\r\nThe smallest possible number of rabbits in the forest is therefore 5: 3 that answered plus 2 that didn't.\r\n\r\nInput: answers = [10, 10, 10]\r\nOutput: 11\r\n\r\nInput: answers = []\r\nOutput: 0\r\n
    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    1. answers will have length at most 1000.
    2. \r\n\t
    3. Each answers[i] will be an integer in the range [0, 999].
    4. \r\n
    \r\n", "content_cn": "

    \u68ee\u6797\u4e2d\uff0c\u6bcf\u4e2a\u5154\u5b50\u90fd\u6709\u989c\u8272\u3002\u5176\u4e2d\u4e00\u4e9b\u5154\u5b50\uff08\u53ef\u80fd\u662f\u5168\u90e8\uff09\u544a\u8bc9\u4f60\u8fd8\u6709\u591a\u5c11\u5176\u4ed6\u7684\u5154\u5b50\u548c\u81ea\u5df1\u6709\u76f8\u540c\u7684\u989c\u8272\u3002\u6211\u4eec\u5c06\u8fd9\u4e9b\u56de\u7b54\u653e\u5728 answers \u6570\u7ec4\u91cc\u3002

    \n\n

    \u8fd4\u56de\u68ee\u6797\u4e2d\u5154\u5b50\u7684\u6700\u5c11\u6570\u91cf\u3002

    \n\n
    \n\u793a\u4f8b:\n\u8f93\u5165: answers = [1, 1, 2]\n\u8f93\u51fa: 5\n\u89e3\u91ca:\n\u4e24\u53ea\u56de\u7b54\u4e86 "1" \u7684\u5154\u5b50\u53ef\u80fd\u6709\u76f8\u540c\u7684\u989c\u8272\uff0c\u8bbe\u4e3a\u7ea2\u8272\u3002\n\u4e4b\u540e\u56de\u7b54\u4e86 "2" \u7684\u5154\u5b50\u4e0d\u4f1a\u662f\u7ea2\u8272\uff0c\u5426\u5219\u4ed6\u4eec\u7684\u56de\u7b54\u4f1a\u76f8\u4e92\u77db\u76fe\u3002\n\u8bbe\u56de\u7b54\u4e86 "2" \u7684\u5154\u5b50\u4e3a\u84dd\u8272\u3002\n\u6b64\u5916\uff0c\u68ee\u6797\u4e2d\u8fd8\u5e94\u6709\u53e6\u5916 2 \u53ea\u84dd\u8272\u5154\u5b50\u7684\u56de\u7b54\u6ca1\u6709\u5305\u542b\u5728\u6570\u7ec4\u4e2d\u3002\n\u56e0\u6b64\u68ee\u6797\u4e2d\u5154\u5b50\u7684\u6700\u5c11\u6570\u91cf\u662f 5: 3 \u53ea\u56de\u7b54\u7684\u548c 2 \u53ea\u6ca1\u6709\u56de\u7b54\u7684\u3002\n\n\u8f93\u5165: answers = [10, 10, 10]\n\u8f93\u51fa: 11\n\n\u8f93\u5165: answers = []\n\u8f93\u51fa: 0\n
    \n\n

    \u8bf4\u660e:

    \n\n
      \n\t
    1. answers \u7684\u957f\u5ea6\u6700\u5927\u4e3a1000\u3002
    2. \n\t
    3. answers[i] \u662f\u5728 [0, 999] \u8303\u56f4\u5185\u7684\u6574\u6570\u3002
    4. \n
    \n", "tags_en": ["Hash Table", "Math"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numRabbits(vector& answers) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numRabbits(int[] answers) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numRabbits(self, answers):\n \"\"\"\n :type answers: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numRabbits(self, answers: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numRabbits(int* answers, int answersSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumRabbits(int[] answers) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} answers\n * @return {number}\n */\nvar numRabbits = function(answers) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} answers\n# @return {Integer}\ndef num_rabbits(answers)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numRabbits(_ answers: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numRabbits(answers []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numRabbits(answers: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numRabbits(answers: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_rabbits(answers: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $answers\n * @return Integer\n */\n function numRabbits($answers) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numRabbits(answers: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-rabbits answers)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0781](https://leetcode-cn.com/problems/rabbits-in-forest)", "[\u68ee\u6797\u4e2d\u7684\u5154\u5b50](/solution/0700-0799/0781.Rabbits%20in%20Forest/README.md)", "`\u54c8\u5e0c\u8868`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0781](https://leetcode.com/problems/rabbits-in-forest)", "[Rabbits in Forest](/solution/0700-0799/0781.Rabbits%20in%20Forest/README_EN.md)", "`Hash Table`,`Math`", "Medium", ""]}, {"question_id": "0796", "frontend_question_id": "0780", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reaching-points", "url_en": "https://leetcode.com/problems/reaching-points", "relative_path_cn": "/solution/0700-0799/0780.Reaching%20Points/README.md", "relative_path_en": "/solution/0700-0799/0780.Reaching%20Points/README_EN.md", "title_cn": "\u5230\u8fbe\u7ec8\u70b9", "title_en": "Reaching Points", "question_title_slug": "reaching-points", "content_en": "

    A move consists of taking a point (x, y) and transforming it to either (x, x+y) or (x+y, y).

    \r\n\r\n

    Given a starting point (sx, sy) and a target point (tx, ty), return True if and only if a sequence of moves exists to transform the point (sx, sy) to (tx, ty). Otherwise, return False.

    \r\n\r\n
    \r\nExamples:\r\nInput: sx = 1, sy = 1, tx = 3, ty = 5\r\nOutput: True\r\nExplanation:\r\nOne series of moves that transforms the starting point to the target is:\r\n(1, 1) -> (1, 2)\r\n(1, 2) -> (3, 2)\r\n(3, 2) -> (3, 5)\r\n\r\nInput: sx = 1, sy = 1, tx = 2, ty = 2\r\nOutput: False\r\n\r\nInput: sx = 1, sy = 1, tx = 1, ty = 1\r\nOutput: True\r\n\r\n
    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    • sx, sy, tx, ty will all be integers in the range [1, 10^9].
    • \r\n
    \r\n", "content_cn": "

    \u4ece\u70b9 (x, y) \u53ef\u4ee5\u8f6c\u6362\u5230 (x, x+y)  \u6216\u8005 (x+y, y)\u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u8d77\u70b9 (sx, sy) \u548c\u4e00\u4e2a\u7ec8\u70b9 (tx, ty)\uff0c\u5982\u679c\u901a\u8fc7\u4e00\u7cfb\u5217\u7684\u8f6c\u6362\u53ef\u4ee5\u4ece\u8d77\u70b9\u5230\u8fbe\u7ec8\u70b9\uff0c\u5219\u8fd4\u56de True \uff0c\u5426\u5219\u8fd4\u56de False\u3002

    \n\n
    \n\u793a\u4f8b:\n\u8f93\u5165: sx = 1, sy = 1, tx = 3, ty = 5\n\u8f93\u51fa: True\n\u89e3\u91ca:\n\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u4e00\u7cfb\u5217\u8f6c\u6362\u4ece\u8d77\u70b9\u8f6c\u6362\u5230\u7ec8\u70b9\uff1a\n(1, 1) -> (1, 2)\n(1, 2) -> (3, 2)\n(3, 2) -> (3, 5)\n\n\u8f93\u5165: sx = 1, sy = 1, tx = 2, ty = 2\n\u8f93\u51fa: False\n\n\u8f93\u5165: sx = 1, sy = 1, tx = 1, ty = 1\n\u8f93\u51fa: True\n\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    • sx, sy, tx, ty \u662f\u8303\u56f4\u5728 [1, 10^9] \u7684\u6574\u6570\u3002
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool reachingPoints(int sx, int sy, int tx, int ty) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean reachingPoints(int sx, int sy, int tx, int ty) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def reachingPoints(self, sx, sy, tx, ty):\n \"\"\"\n :type sx: int\n :type sy: int\n :type tx: int\n :type ty: int\n :rtype: bool\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def reachingPoints(self, sx: int, sy: int, tx: int, ty: int) -> bool:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool reachingPoints(int sx, int sy, int tx, int ty){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool ReachingPoints(int sx, int sy, int tx, int ty) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} sx\n * @param {number} sy\n * @param {number} tx\n * @param {number} ty\n * @return {boolean}\n */\nvar reachingPoints = function(sx, sy, tx, ty) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} sx\n# @param {Integer} sy\n# @param {Integer} tx\n# @param {Integer} ty\n# @return {Boolean}\ndef reaching_points(sx, sy, tx, ty)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func reachingPoints(_ sx: Int, _ sy: Int, _ tx: Int, _ ty: Int) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func reachingPoints(sx int, sy int, tx int, ty int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def reachingPoints(sx: Int, sy: Int, tx: Int, ty: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun reachingPoints(sx: Int, sy: Int, tx: Int, ty: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn reaching_points(sx: i32, sy: i32, tx: i32, ty: i32) -> bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $sx\n * @param Integer $sy\n * @param Integer $tx\n * @param Integer $ty\n * @return Boolean\n */\n function reachingPoints($sx, $sy, $tx, $ty) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function reachingPoints(sx: number, sy: number, tx: number, ty: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (reaching-points sx sy tx ty)\n (-> exact-integer? exact-integer? exact-integer? exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0780](https://leetcode-cn.com/problems/reaching-points)", "[\u5230\u8fbe\u7ec8\u70b9](/solution/0700-0799/0780.Reaching%20Points/README.md)", "`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[0780](https://leetcode.com/problems/reaching-points)", "[Reaching Points](/solution/0700-0799/0780.Reaching%20Points/README_EN.md)", "`Math`", "Hard", ""]}, {"question_id": "0795", "frontend_question_id": "0779", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/k-th-symbol-in-grammar", "url_en": "https://leetcode.com/problems/k-th-symbol-in-grammar", "relative_path_cn": "/solution/0700-0799/0779.K-th%20Symbol%20in%20Grammar/README.md", "relative_path_en": "/solution/0700-0799/0779.K-th%20Symbol%20in%20Grammar/README_EN.md", "title_cn": "\u7b2cK\u4e2a\u8bed\u6cd5\u7b26\u53f7", "title_en": "K-th Symbol in Grammar", "question_title_slug": "k-th-symbol-in-grammar", "content_en": "

    We build a table of n rows (1-indexed). We start by writing 0 in the 1st row. Now in every subsequent row, we look at the previous row and replace each occurrence of 0 with 01, and each occurrence of 1 with 10.

    \n\n
      \n\t
    • For example, for n = 3, the 1st row is 0, the 2nd row is 01, and the 3rd row is 0110.
    • \n
    \n\n

    Given two integer n and k, return the kth (1-indexed) symbol in the nth row of a table of n rows.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 1, k = 1\nOutput: 0\nExplanation: row 1: 0\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 2, k = 1\nOutput: 0\nExplanation:\nrow 1: 0\nrow 2: 01\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 2, k = 2\nOutput: 1\nExplanation:\nrow 1: 0\nrow 2: 01\n
    \n\n

    Example 4:

    \n\n
    \nInput: n = 3, k = 1\nOutput: 0\nExplanation:\nrow 1: 0\nrow 2: 01\nrow 3: 0110\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 30
    • \n\t
    • 1 <= k <= 2n - 1
    • \n
    \n", "content_cn": "

    \u5728\u7b2c\u4e00\u884c\u6211\u4eec\u5199\u4e0a\u4e00\u4e2a 0\u3002\u63a5\u4e0b\u6765\u7684\u6bcf\u4e00\u884c\uff0c\u5c06\u524d\u4e00\u884c\u4e2d\u76840\u66ff\u6362\u4e3a01\uff0c1\u66ff\u6362\u4e3a10\u3002

    \n\n

    \u7ed9\u5b9a\u884c\u6570 N \u548c\u5e8f\u6570 K\uff0c\u8fd4\u56de\u7b2c N \u884c\u4e2d\u7b2c K\u4e2a\u5b57\u7b26\u3002\uff08K\u4ece1\u5f00\u59cb\uff09

    \n\n


    \n\u4f8b\u5b50:

    \n\n
    \u8f93\u5165: N = 1, K = 1\n\u8f93\u51fa: 0\n\n\u8f93\u5165: N = 2, K = 1\n\u8f93\u51fa: 0\n\n\u8f93\u5165: N = 2, K = 2\n\u8f93\u51fa: 1\n\n\u8f93\u5165: N = 4, K = 5\n\u8f93\u51fa: 1\n\n\u89e3\u91ca:\n\u7b2c\u4e00\u884c: 0\n\u7b2c\u4e8c\u884c: 01\n\u7b2c\u4e09\u884c: 0110\n\u7b2c\u56db\u884c: 01101001\n
    \n\n


    \n\u6ce8\u610f\uff1a

    \n\n
      \n\t
    1. N \u7684\u8303\u56f4 [1, 30].
    2. \n\t
    3. K \u7684\u8303\u56f4 [1, 2^(N-1)].
    4. \n
    \n", "tags_en": ["Recursion"], "tags_cn": ["\u9012\u5f52"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int kthGrammar(int n, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int kthGrammar(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def kthGrammar(self, n, k):\n \"\"\"\n :type n: int\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def kthGrammar(self, n: int, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint kthGrammar(int n, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int KthGrammar(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} k\n * @return {number}\n */\nvar kthGrammar = function(n, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} k\n# @return {Integer}\ndef kth_grammar(n, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func kthGrammar(_ n: Int, _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func kthGrammar(n int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def kthGrammar(n: Int, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun kthGrammar(n: Int, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn kth_grammar(n: i32, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $k\n * @return Integer\n */\n function kthGrammar($n, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function kthGrammar(n: number, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (kth-grammar n k)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0779](https://leetcode-cn.com/problems/k-th-symbol-in-grammar)", "[\u7b2cK\u4e2a\u8bed\u6cd5\u7b26\u53f7](/solution/0700-0799/0779.K-th%20Symbol%20in%20Grammar/README.md)", "`\u9012\u5f52`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0779](https://leetcode.com/problems/k-th-symbol-in-grammar)", "[K-th Symbol in Grammar](/solution/0700-0799/0779.K-th%20Symbol%20in%20Grammar/README_EN.md)", "`Recursion`", "Medium", ""]}, {"question_id": "0794", "frontend_question_id": "0778", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/swim-in-rising-water", "url_en": "https://leetcode.com/problems/swim-in-rising-water", "relative_path_cn": "/solution/0700-0799/0778.Swim%20in%20Rising%20Water/README.md", "relative_path_en": "/solution/0700-0799/0778.Swim%20in%20Rising%20Water/README_EN.md", "title_cn": "\u6c34\u4f4d\u4e0a\u5347\u7684\u6cf3\u6c60\u4e2d\u6e38\u6cf3", "title_en": "Swim in Rising Water", "question_title_slug": "swim-in-rising-water", "content_en": "

    On an N x N grid, each square grid[i][j] represents the elevation at that point (i,j).

    \r\n\r\n

    Now rain starts to fall. At time t, the depth of the water everywhere is t. You can swim from a square to another 4-directionally adjacent square if and only if the elevation of both squares individually are at most t. You can swim infinite distance in zero time. Of course, you must stay within the boundaries of the grid during your swim.

    \r\n\r\n

    You start at the top left square (0, 0). What is the least time until you can reach the bottom right square (N-1, N-1)?

    \r\n\r\n

    Example 1:

    \r\n\r\n
    \r\nInput: [[0,2],[1,3]]\r\nOutput: 3\r\nExplanation:\r\nAt time 0, you are in grid location (0, 0).\r\nYou cannot go anywhere else because 4-directionally adjacent neighbors have a higher elevation than t = 0.\r\n\r\nYou cannot reach point (1, 1) until time 3.\r\nWhen the depth of water is 3, we can swim anywhere inside the grid.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: [[0,1,2,3,4],[24,23,22,21,5],[12,13,14,15,16],[11,17,18,19,20],[10,9,8,7,6]]\r\nOutput: 16\r\nExplanation:\r\n 0  1  2  3  4\r\n24 23 22 21  5\r\n12 13 14 15 16\r\n11 17 18 19 20\r\n10  9  8  7  6\r\n\r\nThe final route is marked in bold.\r\nWe need to wait until time 16 so that (0, 0) and (4, 4) are connected.\r\n
    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    1. 2 <= N <= 50.
    2. \r\n\t
    3. grid[i][j] is a permutation of [0, ..., N*N - 1].
    4. \r\n
    \r\n", "content_cn": "

    \u5728\u4e00\u4e2a N x N \u7684\u5750\u6807\u65b9\u683c\u00a0grid \u4e2d\uff0c\u6bcf\u4e00\u4e2a\u65b9\u683c\u7684\u503c grid[i][j] \u8868\u793a\u5728\u4f4d\u7f6e (i,j) \u7684\u5e73\u53f0\u9ad8\u5ea6\u3002

    \n\n

    \u73b0\u5728\u5f00\u59cb\u4e0b\u96e8\u4e86\u3002\u5f53\u65f6\u95f4\u4e3a\u00a0t\u00a0\u65f6\uff0c\u6b64\u65f6\u96e8\u6c34\u5bfc\u81f4\u6c34\u6c60\u4e2d\u4efb\u610f\u4f4d\u7f6e\u7684\u6c34\u4f4d\u4e3a\u00a0t\u00a0\u3002\u4f60\u53ef\u4ee5\u4ece\u4e00\u4e2a\u5e73\u53f0\u6e38\u5411\u56db\u5468\u76f8\u90bb\u7684\u4efb\u610f\u4e00\u4e2a\u5e73\u53f0\uff0c\u4f46\u662f\u524d\u63d0\u662f\u6b64\u65f6\u6c34\u4f4d\u5fc5\u987b\u540c\u65f6\u6df9\u6ca1\u8fd9\u4e24\u4e2a\u5e73\u53f0\u3002\u5047\u5b9a\u4f60\u53ef\u4ee5\u77ac\u95f4\u79fb\u52a8\u65e0\u9650\u8ddd\u79bb\uff0c\u4e5f\u5c31\u662f\u9ed8\u8ba4\u5728\u65b9\u683c\u5185\u90e8\u6e38\u52a8\u662f\u4e0d\u8017\u65f6\u7684\u3002\u5f53\u7136\uff0c\u5728\u4f60\u6e38\u6cf3\u7684\u65f6\u5019\u4f60\u5fc5\u987b\u5f85\u5728\u5750\u6807\u65b9\u683c\u91cc\u9762\u3002

    \n\n

    \u4f60\u4ece\u5750\u6807\u65b9\u683c\u7684\u5de6\u4e0a\u5e73\u53f0 (0\uff0c0) \u51fa\u53d1\u3002\u6700\u5c11\u8017\u65f6\u591a\u4e45\u4f60\u624d\u80fd\u5230\u8fbe\u5750\u6807\u65b9\u683c\u7684\u53f3\u4e0b\u5e73\u53f0\u00a0(N-1, N-1)\uff1f

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: [[0,2],[1,3]]\n\u8f93\u51fa: 3\n\u89e3\u91ca:\n\u65f6\u95f4\u4e3a0\u65f6\uff0c\u4f60\u4f4d\u4e8e\u5750\u6807\u65b9\u683c\u7684\u4f4d\u7f6e\u4e3a (0, 0)\u3002\n\u6b64\u65f6\u4f60\u4e0d\u80fd\u6e38\u5411\u4efb\u610f\u65b9\u5411\uff0c\u56e0\u4e3a\u56db\u4e2a\u76f8\u90bb\u65b9\u5411\u5e73\u53f0\u7684\u9ad8\u5ea6\u90fd\u5927\u4e8e\u5f53\u524d\u65f6\u95f4\u4e3a 0 \u65f6\u7684\u6c34\u4f4d\u3002\n\n\u7b49\u65f6\u95f4\u5230\u8fbe 3 \u65f6\uff0c\u4f60\u624d\u53ef\u4ee5\u6e38\u5411\u5e73\u53f0 (1, 1). \u56e0\u4e3a\u6b64\u65f6\u7684\u6c34\u4f4d\u662f 3\uff0c\u5750\u6807\u65b9\u683c\u4e2d\u7684\u5e73\u53f0\u6ca1\u6709\u6bd4\u6c34\u4f4d 3 \u66f4\u9ad8\u7684\uff0c\u6240\u4ee5\u4f60\u53ef\u4ee5\u6e38\u5411\u5750\u6807\u65b9\u683c\u4e2d\u7684\u4efb\u610f\u4f4d\u7f6e\n
    \n\n

    \u793a\u4f8b2:

    \n\n
    \n\u8f93\u5165: [[0,1,2,3,4],[24,23,22,21,5],[12,13,14,15,16],[11,17,18,19,20],[10,9,8,7,6]]\n\u8f93\u51fa: 16\n\u89e3\u91ca:\n 0  1  2  3  4\n24 23 22 21  5\n12 13 14 15 16\n11 17 18 19 20\n10  9  8  7  6\n\n\u6700\u7ec8\u7684\u8def\u7ebf\u7528\u52a0\u7c97\u8fdb\u884c\u4e86\u6807\u8bb0\u3002\n\u6211\u4eec\u5fc5\u987b\u7b49\u5230\u65f6\u95f4\u4e3a 16\uff0c\u6b64\u65f6\u624d\u80fd\u4fdd\u8bc1\u5e73\u53f0 (0, 0) \u548c (4, 4) \u662f\u8fde\u901a\u7684\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a:

    \n\n
      \n\t
    1. 2 <= N <= 50.
    2. \n\t
    3. grid[i][j] \u662f [0, ..., N*N - 1] \u7684\u6392\u5217\u3002
    4. \n
    \n", "tags_en": ["Heap", "Depth-first Search", "Union Find", "Binary Search"], "tags_cn": ["\u5806", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e76\u67e5\u96c6", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int swimInWater(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int swimInWater(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def swimInWater(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def swimInWater(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint swimInWater(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SwimInWater(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar swimInWater = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef swim_in_water(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func swimInWater(_ grid: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func swimInWater(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def swimInWater(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun swimInWater(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn swim_in_water(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function swimInWater($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function swimInWater(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (swim-in-water grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0778](https://leetcode-cn.com/problems/swim-in-rising-water)", "[\u6c34\u4f4d\u4e0a\u5347\u7684\u6cf3\u6c60\u4e2d\u6e38\u6cf3](/solution/0700-0799/0778.Swim%20in%20Rising%20Water/README.md)", "`\u5806`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e76\u67e5\u96c6`,`\u4e8c\u5206\u67e5\u627e`", "\u56f0\u96be", ""], "md_table_row_en": ["[0778](https://leetcode.com/problems/swim-in-rising-water)", "[Swim in Rising Water](/solution/0700-0799/0778.Swim%20in%20Rising%20Water/README_EN.md)", "`Heap`,`Depth-first Search`,`Union Find`,`Binary Search`", "Hard", ""]}, {"question_id": "0793", "frontend_question_id": "0777", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/swap-adjacent-in-lr-string", "url_en": "https://leetcode.com/problems/swap-adjacent-in-lr-string", "relative_path_cn": "/solution/0700-0799/0777.Swap%20Adjacent%20in%20LR%20String/README.md", "relative_path_en": "/solution/0700-0799/0777.Swap%20Adjacent%20in%20LR%20String/README_EN.md", "title_cn": "\u5728LR\u5b57\u7b26\u4e32\u4e2d\u4ea4\u6362\u76f8\u90bb\u5b57\u7b26", "title_en": "Swap Adjacent in LR String", "question_title_slug": "swap-adjacent-in-lr-string", "content_en": "

    In a string composed of 'L', 'R', and 'X' characters, like "RXXLRXRXL", a move consists of either replacing one occurrence of "XL" with "LX", or replacing one occurrence of "RX" with "XR". Given the starting string start and the ending string end, return True if and only if there exists a sequence of moves to transform one string to the other.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: start = "RXXLRXRXL", end = "XRLXXRRLX"\nOutput: true\nExplanation: We can transform start to end following these steps:\nRXXLRXRXL ->\nXRXLRXRXL ->\nXRLXRXRXL ->\nXRLXXRRXL ->\nXRLXXRRLX\n
    \n\n

    Example 2:

    \n\n
    \nInput: start = "X", end = "L"\nOutput: false\n
    \n\n

    Example 3:

    \n\n
    \nInput: start = "LLR", end = "RRL"\nOutput: false\n
    \n\n

    Example 4:

    \n\n
    \nInput: start = "XL", end = "LX"\nOutput: true\n
    \n\n

    Example 5:

    \n\n
    \nInput: start = "XLLR", end = "LXLX"\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= start.length <= 104
    • \n\t
    • start.length == end.length
    • \n\t
    • Both start and end will only consist of characters in 'L', 'R', and 'X'.
    • \n
    \n", "content_cn": "

    \u5728\u4e00\u4e2a\u7531 'L' , 'R' \u548c 'X' \u4e09\u4e2a\u5b57\u7b26\u7ec4\u6210\u7684\u5b57\u7b26\u4e32\uff08\u4f8b\u5982"RXXLRXRXL"\uff09\u4e2d\u8fdb\u884c\u79fb\u52a8\u64cd\u4f5c\u3002\u4e00\u6b21\u79fb\u52a8\u64cd\u4f5c\u6307\u7528\u4e00\u4e2a"LX"\u66ff\u6362\u4e00\u4e2a"XL"\uff0c\u6216\u8005\u7528\u4e00\u4e2a"XR"\u66ff\u6362\u4e00\u4e2a"RX"\u3002\u73b0\u7ed9\u5b9a\u8d77\u59cb\u5b57\u7b26\u4e32start\u548c\u7ed3\u675f\u5b57\u7b26\u4e32end\uff0c\u8bf7\u7f16\u5199\u4ee3\u7801\uff0c\u5f53\u4e14\u4ec5\u5f53\u5b58\u5728\u4e00\u7cfb\u5217\u79fb\u52a8\u64cd\u4f5c\u4f7f\u5f97start\u53ef\u4ee5\u8f6c\u6362\u6210end\u65f6\uff0c \u8fd4\u56deTrue\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b :

    \n\n
    \u8f93\u5165: start = "RXXLRXRXL", end = "XRLXXRRLX"\n\u8f93\u51fa: True\n\u89e3\u91ca:\n\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u51e0\u6b65\u5c06start\u8f6c\u6362\u6210end:\nRXXLRXRXL ->\nXRXLRXRXL ->\nXRLXRXRXL ->\nXRLXXRRXL ->\nXRLXXRRLX\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= len(start) = len(end) <= 10000\u3002
    • \n\t
    • start\u548cend\u4e2d\u7684\u5b57\u7b26\u4e32\u4ec5\u9650\u4e8e'L', 'R'\u548c'X'\u3002
    • \n
    \n", "tags_en": ["Brainteaser"], "tags_cn": ["\u8111\u7b4b\u6025\u8f6c\u5f2f"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canTransform(string start, string end) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canTransform(String start, String end) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canTransform(self, start, end):\n \"\"\"\n :type start: str\n :type end: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canTransform(self, start: str, end: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canTransform(char * start, char * end){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanTransform(string start, string end) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} start\n * @param {string} end\n * @return {boolean}\n */\nvar canTransform = function(start, end) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} start\n# @param {String} end\n# @return {Boolean}\ndef can_transform(start, end)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canTransform(_ start: String, _ end: String) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canTransform(start string, end string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canTransform(start: String, end: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canTransform(start: String, end: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_transform(start: String, end: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $start\n * @param String $end\n * @return Boolean\n */\n function canTransform($start, $end) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canTransform(start: string, end: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-transform start end)\n (-> string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0777](https://leetcode-cn.com/problems/swap-adjacent-in-lr-string)", "[\u5728LR\u5b57\u7b26\u4e32\u4e2d\u4ea4\u6362\u76f8\u90bb\u5b57\u7b26](/solution/0700-0799/0777.Swap%20Adjacent%20in%20LR%20String/README.md)", "`\u8111\u7b4b\u6025\u8f6c\u5f2f`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0777](https://leetcode.com/problems/swap-adjacent-in-lr-string)", "[Swap Adjacent in LR String](/solution/0700-0799/0777.Swap%20Adjacent%20in%20LR%20String/README_EN.md)", "`Brainteaser`", "Medium", ""]}, {"question_id": "0792", "frontend_question_id": "0704", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/binary-search", "url_en": "https://leetcode.com/problems/binary-search", "relative_path_cn": "/solution/0700-0799/0704.Binary%20Search/README.md", "relative_path_en": "/solution/0700-0799/0704.Binary%20Search/README_EN.md", "title_cn": "\u4e8c\u5206\u67e5\u627e", "title_en": "Binary Search", "question_title_slug": "binary-search", "content_en": "

    Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists, then return its index. Otherwise, return -1.

    \n\n

    You must write an algorithm with O(log n) runtime complexity.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [-1,0,3,5,9,12], target = 9\nOutput: 4\nExplanation: 9 exists in nums and its index is 4\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [-1,0,3,5,9,12], target = 2\nOutput: -1\nExplanation: 2 does not exist in nums so return -1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 104
    • \n\t
    • -9999 <= nums[i], target <= 9999
    • \n\t
    • All the integers in nums are unique.
    • \n\t
    • nums is sorted in an ascending order.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a n \u4e2a\u5143\u7d20\u6709\u5e8f\u7684\uff08\u5347\u5e8f\uff09\u6574\u578b\u6570\u7ec4 nums \u548c\u4e00\u4e2a\u76ee\u6807\u503c target  \uff0c\u5199\u4e00\u4e2a\u51fd\u6570\u641c\u7d22 nums \u4e2d\u7684 target\uff0c\u5982\u679c\u76ee\u6807\u503c\u5b58\u5728\u8fd4\u56de\u4e0b\u6807\uff0c\u5426\u5219\u8fd4\u56de -1\u3002

    \n\n


    \n\u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: nums = [-1,0,3,5,9,12], target = 9\n\u8f93\u51fa: 4\n\u89e3\u91ca: 9 \u51fa\u73b0\u5728 nums \u4e2d\u5e76\u4e14\u4e0b\u6807\u4e3a 4\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: nums = [-1,0,3,5,9,12], target = 2\n\u8f93\u51fa: -1\n\u89e3\u91ca: 2 \u4e0d\u5b58\u5728 nums \u4e2d\u56e0\u6b64\u8fd4\u56de -1\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. \u4f60\u53ef\u4ee5\u5047\u8bbe nums \u4e2d\u7684\u6240\u6709\u5143\u7d20\u662f\u4e0d\u91cd\u590d\u7684\u3002
    2. \n\t
    3. n \u5c06\u5728 [1, 10000]\u4e4b\u95f4\u3002
    4. \n\t
    5. nums \u7684\u6bcf\u4e2a\u5143\u7d20\u90fd\u5c06\u5728 [-9999, 9999]\u4e4b\u95f4\u3002
    6. \n
    \n", "tags_en": ["Binary Search"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int search(vector& nums, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int search(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def search(self, nums, target):\n \"\"\"\n :type nums: List[int]\n :type target: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def search(self, nums: List[int], target: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint search(int* nums, int numsSize, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int Search(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} target\n * @return {number}\n */\nvar search = function(nums, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} target\n# @return {Integer}\ndef search(nums, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func search(_ nums: [Int], _ target: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func search(nums []int, target int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def search(nums: Array[Int], target: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun search(nums: IntArray, target: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn search(nums: Vec, target: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $target\n * @return Integer\n */\n function search($nums, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function search(nums: number[], target: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (search nums target)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0704](https://leetcode-cn.com/problems/binary-search)", "[\u4e8c\u5206\u67e5\u627e](/solution/0700-0799/0704.Binary%20Search/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u7b80\u5355", ""], "md_table_row_en": ["[0704](https://leetcode.com/problems/binary-search)", "[Binary Search](/solution/0700-0799/0704.Binary%20Search/README_EN.md)", "`Binary Search`", "Easy", ""]}, {"question_id": "0791", "frontend_question_id": "0776", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/split-bst", "url_en": "https://leetcode.com/problems/split-bst", "relative_path_cn": "/solution/0700-0799/0776.Split%20BST/README.md", "relative_path_en": "/solution/0700-0799/0776.Split%20BST/README_EN.md", "title_cn": "\u62c6\u5206\u4e8c\u53c9\u641c\u7d22\u6811", "title_en": "Split BST", "question_title_slug": "split-bst", "content_en": "

    Given a Binary Search Tree (BST) with root node root, and a target value target, split the tree into two subtrees where one subtree has nodes that are all smaller or equal to the target value, while the other subtree has all nodes that are greater than the target value. It's not necessarily the case that the tree contains a node with value target.

    \n\n

    Additionally, most of the structure of the original tree should remain. Formally, for any child c with parent p in the original tree, if they are both in the same subtree after the split, then node c should still have the parent p.

    \n\n

    You should output the root TreeNode of both subtrees after splitting, in any order.

    \n\n

    Example 1:

    \n\n
    \nInput: root = [4,2,6,1,3,5,7], target = 2\nOutput: [[2,1],[4,3,6,null,null,5,7]]\nExplanation:\nNote that root, output[0], and output[1] are TreeNode objects, not arrays.\n\nThe given tree [4,2,6,1,3,5,7] is represented by the following diagram:\n\n          4\n        /   \\\n      2      6\n     / \\    / \\\n    1   3  5   7\n\nwhile the diagrams for the outputs are:\n\n          4\n        /   \\\n      3      6      and    2\n            / \\           /\n           5   7         1\n
    \n\n

    Note:

    \n\n
      \n\t
    1. The size of the BST will not exceed 50.
    2. \n\t
    3. The BST is always valid and each node's value is different.
    4. \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u68f5\u4e8c\u53c9\u641c\u7d22\u6811\uff08BST\uff09\u3001\u5b83\u7684\u6839\u7ed3\u70b9 root\u00a0\u4ee5\u53ca\u76ee\u6807\u503c V\u3002

    \n\n

    \u8bf7\u5c06\u8be5\u6811\u6309\u8981\u6c42\u62c6\u5206\u4e3a\u4e24\u4e2a\u5b50\u6811\uff1a\u5176\u4e2d\u4e00\u4e2a\u5b50\u6811\u7ed3\u70b9\u7684\u503c\u90fd\u5fc5\u987b\u5c0f\u4e8e\u7b49\u4e8e\u7ed9\u5b9a\u7684\u76ee\u6807\u503c V\uff1b\u53e6\u4e00\u4e2a\u5b50\u6811\u7ed3\u70b9\u7684\u503c\u90fd\u5fc5\u987b\u5927\u4e8e\u76ee\u6807\u503c V\uff1b\u6811\u4e2d\u5e76\u975e\u4e00\u5b9a\u8981\u5b58\u5728\u503c\u4e3a V\u00a0\u7684\u7ed3\u70b9\u3002

    \n\n

    \u9664\u6b64\u4e4b\u5916\uff0c\u6811\u4e2d\u5927\u90e8\u5206\u7ed3\u6784\u90fd\u9700\u8981\u4fdd\u7559\uff0c\u4e5f\u5c31\u662f\u8bf4\u539f\u59cb\u6811\u4e2d\u7236\u8282\u70b9 P \u7684\u4efb\u610f\u5b50\u8282\u70b9 C\uff0c\u5047\u5982\u62c6\u5206\u540e\u5b83\u4eec\u4ecd\u5728\u540c\u4e00\u4e2a\u5b50\u6811\u4e2d\uff0c\u90a3\u4e48\u7ed3\u70b9 P \u5e94\u4ecd\u4e3a C \u7684\u7236\u7ed3\u70b9\u3002

    \n\n

    \u4f60\u9700\u8981\u8fd4\u56de\u62c6\u5206\u540e\u4e24\u4e2a\u5b50\u6811\u7684\u6839\u7ed3\u70b9 TreeNode\uff0c\u987a\u5e8f\u968f\u610f\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [4,2,6,1,3,5,7], V = 2\n\u8f93\u51fa\uff1a[[2,1],[4,3,6,null,null,5,7]]\n\u89e3\u91ca\uff1a\n\u6ce8\u610f\u6839\u7ed3\u70b9 output[0] \u548c output[1] \u90fd\u662f TreeNode\u00a0\u5bf9\u8c61\uff0c\u4e0d\u662f\u6570\u7ec4\u3002\n\n\u7ed9\u5b9a\u7684\u6811 [4,2,6,1,3,5,7] \u53ef\u5316\u4e3a\u5982\u4e0b\u793a\u610f\u56fe\uff1a\n\n          4\n        /   \\\n      2      6\n     / \\    / \\\n    1   3  5   7\n\n\u8f93\u51fa\u7684\u793a\u610f\u56fe\u5982\u4e0b\uff1a\n\n          4\n        /   \\\n      3      6       \u548c    2\n            / \\           /\n           5   7         1
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. \u4e8c\u53c9\u641c\u7d22\u6811\u8282\u70b9\u4e2a\u6570\u4e0d\u8d85\u8fc7\u00a050\u00a0
    2. \n\t
    3. \u4e8c\u53c9\u641c\u7d22\u6811\u59cb\u7ec8\u662f\u6709\u6548\u7684\uff0c\u5e76\u4e14\u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u90fd\u4e0d\u76f8\u540c
    4. \n
    \n", "tags_en": ["Tree", "Recursion"], "tags_cn": ["\u6811", "\u9012\u5f52"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector splitBST(TreeNode* root, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode[] splitBST(TreeNode root, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def splitBST(self, root, target):\n \"\"\"\n :type root: TreeNode\n :type target: int\n :rtype: List[TreeNode]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def splitBST(self, root: TreeNode, target: int) -> List[TreeNode]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nstruct TreeNode** splitBST(struct TreeNode* root, int target, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode[] SplitBST(TreeNode root, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number} target\n * @return {TreeNode[]}\n */\nvar splitBST = function(root, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @param {Integer} target\n# @return {TreeNode[]}\ndef split_bst(root, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func splitBST(_ root: TreeNode?, _ target: Int) -> [TreeNode?] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc splitBST(root *TreeNode, target int) []*TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def splitBST(root: TreeNode, target: Int): Array[TreeNode] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun splitBST(root: TreeNode?, target: Int): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn split_bst(root: Option>>, target: i32) -> Vec>>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param Integer $target\n * @return TreeNode[]\n */\n function splitBST($root, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction splitBST(root: TreeNode | null, target: number): Array {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (split-bst root target)\n (-> (or/c tree-node? #f) exact-integer? (listof (or/c tree-node? #f)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0776](https://leetcode-cn.com/problems/split-bst)", "[\u62c6\u5206\u4e8c\u53c9\u641c\u7d22\u6811](/solution/0700-0799/0776.Split%20BST/README.md)", "`\u6811`,`\u9012\u5f52`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0776](https://leetcode.com/problems/split-bst)", "[Split BST](/solution/0700-0799/0776.Split%20BST/README_EN.md)", "`Tree`,`Recursion`", "Medium", "\ud83d\udd12"]}, {"question_id": "0790", "frontend_question_id": "0775", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/global-and-local-inversions", "url_en": "https://leetcode.com/problems/global-and-local-inversions", "relative_path_cn": "/solution/0700-0799/0775.Global%20and%20Local%20Inversions/README.md", "relative_path_en": "/solution/0700-0799/0775.Global%20and%20Local%20Inversions/README_EN.md", "title_cn": "\u5168\u5c40\u5012\u7f6e\u4e0e\u5c40\u90e8\u5012\u7f6e", "title_en": "Global and Local Inversions", "question_title_slug": "global-and-local-inversions", "content_en": "

    You are given an integer array nums of length n which represents a permutation of all the integers in the range [0, n - 1].

    \n\n

    The number of global inversions is the number of the different pairs (i, j) where:

    \n\n
      \n\t
    • 0 <= i < j < n
    • \n\t
    • nums[i] > nums[j]
    • \n
    \n\n

    The number of local inversions is the number of indices i where:

    \n\n
      \n\t
    • 0 <= i < n - 1
    • \n\t
    • nums[i] > nums[i + 1]
    • \n
    \n\n

    Return true if the number of global inversions is equal to the number of local inversions.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,0,2]\nOutput: true\nExplanation: There is 1 global inversion and 1 local inversion.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,2,0]\nOutput: false\nExplanation: There are 2 global inversions and 1 local inversion.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= n <= 105
    • \n\t
    • 0 <= nums[i] < n
    • \n\t
    • All the integers of nums are unique.
    • \n\t
    • nums is a permutation of all the numbers in the range [0, n - 1].
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u6574\u6570\u6570\u7ec4 nums \uff0c\u8868\u793a\u7531\u8303\u56f4 [0, n - 1] \u5185\u6240\u6709\u6574\u6570\u7ec4\u6210\u7684\u4e00\u4e2a\u6392\u5217\u3002

    \n\n

    \u5168\u5c40\u5012\u7f6e \u7684\u6570\u76ee\u7b49\u4e8e\u6ee1\u8db3\u4e0b\u8ff0\u6761\u4ef6\u4e0d\u540c\u4e0b\u6807\u5bf9 (i, j) \u7684\u6570\u76ee\uff1a

    \n\n
      \n\t
    • 0 <= i < j < n
    • \n\t
    • nums[i] > nums[j]
    • \n
    \n\n

    \u5c40\u90e8\u5012\u7f6e \u7684\u6570\u76ee\u7b49\u4e8e\u6ee1\u8db3\u4e0b\u8ff0\u6761\u4ef6\u7684\u4e0b\u6807 i \u7684\u6570\u76ee\uff1a

    \n\n
      \n\t
    • 0 <= i < n - 1
    • \n\t
    • nums[i] > nums[i + 1]
    • \n
    \n\n

    \u5f53\u6570\u7ec4 nums \u4e2d \u5168\u5c40\u5012\u7f6e \u7684\u6570\u91cf\u7b49\u4e8e \u5c40\u90e8\u5012\u7f6e \u7684\u6570\u91cf\u65f6\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,0,2]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u6709 1 \u4e2a\u5168\u5c40\u5012\u7f6e\uff0c\u548c 1 \u4e2a\u5c40\u90e8\u5012\u7f6e\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,0]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u6709 2 \u4e2a\u5168\u5c40\u5012\u7f6e\uff0c\u548c 1 \u4e2a\u5c40\u90e8\u5012\u7f6e\u3002\n
    \n\u00a0\n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= n <= 5000
    • \n\t
    • 0 <= nums[i] < n
    • \n\t
    • nums \u4e2d\u7684\u6240\u6709\u6574\u6570 \u4e92\u4e0d\u76f8\u540c
    • \n\t
    • nums \u662f\u8303\u56f4 [0, n - 1] \u5185\u6240\u6709\u6570\u5b57\u7ec4\u6210\u7684\u4e00\u4e2a\u6392\u5217
    • \n
    \n", "tags_en": ["Array", "Math"], "tags_cn": ["\u6570\u7ec4", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isIdealPermutation(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isIdealPermutation(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isIdealPermutation(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isIdealPermutation(self, nums: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isIdealPermutation(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsIdealPermutation(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {boolean}\n */\nvar isIdealPermutation = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Boolean}\ndef is_ideal_permutation(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isIdealPermutation(_ nums: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isIdealPermutation(nums []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isIdealPermutation(nums: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isIdealPermutation(nums: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_ideal_permutation(nums: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Boolean\n */\n function isIdealPermutation($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isIdealPermutation(nums: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-ideal-permutation nums)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0775](https://leetcode-cn.com/problems/global-and-local-inversions)", "[\u5168\u5c40\u5012\u7f6e\u4e0e\u5c40\u90e8\u5012\u7f6e](/solution/0700-0799/0775.Global%20and%20Local%20Inversions/README.md)", "`\u6570\u7ec4`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0775](https://leetcode.com/problems/global-and-local-inversions)", "[Global and Local Inversions](/solution/0700-0799/0775.Global%20and%20Local%20Inversions/README_EN.md)", "`Array`,`Math`", "Medium", ""]}, {"question_id": "0789", "frontend_question_id": "0703", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/kth-largest-element-in-a-stream", "url_en": "https://leetcode.com/problems/kth-largest-element-in-a-stream", "relative_path_cn": "/solution/0700-0799/0703.Kth%20Largest%20Element%20in%20a%20Stream/README.md", "relative_path_en": "/solution/0700-0799/0703.Kth%20Largest%20Element%20in%20a%20Stream/README_EN.md", "title_cn": "\u6570\u636e\u6d41\u4e2d\u7684\u7b2c K \u5927\u5143\u7d20", "title_en": "Kth Largest Element in a Stream", "question_title_slug": "kth-largest-element-in-a-stream", "content_en": "

    Design a class to find the kth largest element in a stream. Note that it is the kth largest element in the sorted order, not the kth distinct element.

    \n\n

    Implement KthLargest class:

    \n\n
      \n\t
    • KthLargest(int k, int[] nums) Initializes the object with the integer k and the stream of integers nums.
    • \n\t
    • int add(int val) Returns the element representing the kth largest element in the stream.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["KthLargest", "add", "add", "add", "add", "add"]\n[[3, [4, 5, 8, 2]], [3], [5], [10], [9], [4]]\nOutput\n[null, 4, 5, 5, 8, 8]\n\nExplanation\nKthLargest kthLargest = new KthLargest(3, [4, 5, 8, 2]);\nkthLargest.add(3);   // return 4\nkthLargest.add(5);   // return 5\nkthLargest.add(10);  // return 5\nkthLargest.add(9);   // return 8\nkthLargest.add(4);   // return 8\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= k <= 104
    • \n\t
    • 0 <= nums.length <= 104
    • \n\t
    • -104 <= nums[i] <= 104
    • \n\t
    • -104 <= val <= 104
    • \n\t
    • At most 104 calls will be made to add.
    • \n\t
    • It is guaranteed that there will be at least k elements in the array when you search for the kth element.
    • \n
    \n", "content_cn": "

    \u8bbe\u8ba1\u4e00\u4e2a\u627e\u5230\u6570\u636e\u6d41\u4e2d\u7b2c k \u5927\u5143\u7d20\u7684\u7c7b\uff08class\uff09\u3002\u6ce8\u610f\u662f\u6392\u5e8f\u540e\u7684\u7b2c k \u5927\u5143\u7d20\uff0c\u4e0d\u662f\u7b2c k \u4e2a\u4e0d\u540c\u7684\u5143\u7d20\u3002

    \n\n

    \u8bf7\u5b9e\u73b0 KthLargest\u00a0\u7c7b\uff1a

    \n\n
      \n\t
    • KthLargest(int k, int[] nums) \u4f7f\u7528\u6574\u6570 k \u548c\u6574\u6570\u6d41 nums \u521d\u59cb\u5316\u5bf9\u8c61\u3002
    • \n\t
    • int add(int val) \u5c06 val \u63d2\u5165\u6570\u636e\u6d41 nums \u540e\uff0c\u8fd4\u56de\u5f53\u524d\u6570\u636e\u6d41\u4e2d\u7b2c k \u5927\u7684\u5143\u7d20\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\n[\"KthLargest\", \"add\", \"add\", \"add\", \"add\", \"add\"]\n[[3, [4, 5, 8, 2]], [3], [5], [10], [9], [4]]\n\u8f93\u51fa\uff1a\n[null, 4, 5, 5, 8, 8]\n\n\u89e3\u91ca\uff1a\nKthLargest kthLargest = new KthLargest(3, [4, 5, 8, 2]);\nkthLargest.add(3);   // return 4\nkthLargest.add(5);   // return 5\nkthLargest.add(10);  // return 5\nkthLargest.add(9);   // return 8\nkthLargest.add(4);   // return 8\n
    \n\n

    \u00a0

    \n\u63d0\u793a\uff1a\n\n
      \n\t
    • 1 <= k <= 104
    • \n\t
    • 0 <= nums.length <= 104
    • \n\t
    • -104 <= nums[i] <= 104
    • \n\t
    • -104 <= val <= 104
    • \n\t
    • \u6700\u591a\u8c03\u7528 add \u65b9\u6cd5 104 \u6b21
    • \n\t
    • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\uff0c\u5728\u67e5\u627e\u7b2c k \u5927\u5143\u7d20\u65f6\uff0c\u6570\u7ec4\u4e2d\u81f3\u5c11\u6709 k \u4e2a\u5143\u7d20
    • \n
    \n", "tags_en": ["Heap", "Design"], "tags_cn": ["\u5806", "\u8bbe\u8ba1"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class KthLargest {\npublic:\n KthLargest(int k, vector& nums) {\n\n }\n \n int add(int val) {\n\n }\n};\n\n/**\n * Your KthLargest object will be instantiated and called as such:\n * KthLargest* obj = new KthLargest(k, nums);\n * int param_1 = obj->add(val);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class KthLargest {\n\n public KthLargest(int k, int[] nums) {\n\n }\n \n public int add(int val) {\n\n }\n}\n\n/**\n * Your KthLargest object will be instantiated and called as such:\n * KthLargest obj = new KthLargest(k, nums);\n * int param_1 = obj.add(val);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class KthLargest(object):\n\n def __init__(self, k, nums):\n \"\"\"\n :type k: int\n :type nums: List[int]\n \"\"\"\n\n\n def add(self, val):\n \"\"\"\n :type val: int\n :rtype: int\n \"\"\"\n\n\n\n# Your KthLargest object will be instantiated and called as such:\n# obj = KthLargest(k, nums)\n# param_1 = obj.add(val)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class KthLargest:\n\n def __init__(self, k: int, nums: List[int]):\n\n\n def add(self, val: int) -> int:\n\n\n\n# Your KthLargest object will be instantiated and called as such:\n# obj = KthLargest(k, nums)\n# param_1 = obj.add(val)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} KthLargest;\n\n\nKthLargest* kthLargestCreate(int k, int* nums, int numsSize) {\n\n}\n\nint kthLargestAdd(KthLargest* obj, int val) {\n\n}\n\nvoid kthLargestFree(KthLargest* obj) {\n\n}\n\n/**\n * Your KthLargest struct will be instantiated and called as such:\n * KthLargest* obj = kthLargestCreate(k, nums, numsSize);\n * int param_1 = kthLargestAdd(obj, val);\n \n * kthLargestFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class KthLargest {\n\n public KthLargest(int k, int[] nums) {\n\n }\n \n public int Add(int val) {\n\n }\n}\n\n/**\n * Your KthLargest object will be instantiated and called as such:\n * KthLargest obj = new KthLargest(k, nums);\n * int param_1 = obj.Add(val);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} k\n * @param {number[]} nums\n */\nvar KthLargest = function(k, nums) {\n\n};\n\n/** \n * @param {number} val\n * @return {number}\n */\nKthLargest.prototype.add = function(val) {\n\n};\n\n/**\n * Your KthLargest object will be instantiated and called as such:\n * var obj = new KthLargest(k, nums)\n * var param_1 = obj.add(val)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class KthLargest\n\n=begin\n :type k: Integer\n :type nums: Integer[]\n=end\n def initialize(k, nums)\n\n end\n\n\n=begin\n :type val: Integer\n :rtype: Integer\n=end\n def add(val)\n\n end\n\n\nend\n\n# Your KthLargest object will be instantiated and called as such:\n# obj = KthLargest.new(k, nums)\n# param_1 = obj.add(val)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass KthLargest {\n\n init(_ k: Int, _ nums: [Int]) {\n\n }\n \n func add(_ val: Int) -> Int {\n\n }\n}\n\n/**\n * Your KthLargest object will be instantiated and called as such:\n * let obj = KthLargest(k, nums)\n * let ret_1: Int = obj.add(val)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type KthLargest struct {\n\n}\n\n\nfunc Constructor(k int, nums []int) KthLargest {\n\n}\n\n\nfunc (this *KthLargest) Add(val int) int {\n\n}\n\n\n/**\n * Your KthLargest object will be instantiated and called as such:\n * obj := Constructor(k, nums);\n * param_1 := obj.Add(val);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class KthLargest(_k: Int, _nums: Array[Int]) {\n\n def add(`val`: Int): Int = {\n\n }\n\n}\n\n/**\n * Your KthLargest object will be instantiated and called as such:\n * var obj = new KthLargest(k, nums)\n * var param_1 = obj.add(`val`)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class KthLargest(k: Int, nums: IntArray) {\n\n fun add(`val`: Int): Int {\n\n }\n\n}\n\n/**\n * Your KthLargest object will be instantiated and called as such:\n * var obj = KthLargest(k, nums)\n * var param_1 = obj.add(`val`)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct KthLargest {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl KthLargest {\n\n fn new(k: i32, nums: Vec) -> Self {\n\n }\n \n fn add(&self, val: i32) -> i32 {\n\n }\n}\n\n/**\n * Your KthLargest object will be instantiated and called as such:\n * let obj = KthLargest::new(k, nums);\n * let ret_1: i32 = obj.add(val);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class KthLargest {\n /**\n * @param Integer $k\n * @param Integer[] $nums\n */\n function __construct($k, $nums) {\n\n }\n\n /**\n * @param Integer $val\n * @return Integer\n */\n function add($val) {\n\n }\n}\n\n/**\n * Your KthLargest object will be instantiated and called as such:\n * $obj = KthLargest($k, $nums);\n * $ret_1 = $obj->add($val);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class KthLargest {\n constructor(k: number, nums: number[]) {\n\n }\n\n add(val: number): number {\n\n }\n}\n\n/**\n * Your KthLargest object will be instantiated and called as such:\n * var obj = new KthLargest(k, nums)\n * var param_1 = obj.add(val)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define kth-largest%\n (class object%\n (super-new)\n\n ; k : exact-integer?\n\n ; nums : (listof exact-integer?)\n (init-field\n k\n nums)\n \n ; add : exact-integer? -> exact-integer?\n (define/public (add val)\n\n )))\n\n;; Your kth-largest% object will be instantiated and called as such:\n;; (define obj (new kth-largest% [k k] [nums nums]))\n;; (define param_1 (send obj add val))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0703](https://leetcode-cn.com/problems/kth-largest-element-in-a-stream)", "[\u6570\u636e\u6d41\u4e2d\u7684\u7b2c K \u5927\u5143\u7d20](/solution/0700-0799/0703.Kth%20Largest%20Element%20in%20a%20Stream/README.md)", "`\u5806`,`\u8bbe\u8ba1`", "\u7b80\u5355", ""], "md_table_row_en": ["[0703](https://leetcode.com/problems/kth-largest-element-in-a-stream)", "[Kth Largest Element in a Stream](/solution/0700-0799/0703.Kth%20Largest%20Element%20in%20a%20Stream/README_EN.md)", "`Heap`,`Design`", "Easy", ""]}, {"question_id": "0788", "frontend_question_id": "0774", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/minimize-max-distance-to-gas-station", "url_en": "https://leetcode.com/problems/minimize-max-distance-to-gas-station", "relative_path_cn": "/solution/0700-0799/0774.Minimize%20Max%20Distance%20to%20Gas%20Station/README.md", "relative_path_en": "/solution/0700-0799/0774.Minimize%20Max%20Distance%20to%20Gas%20Station/README_EN.md", "title_cn": "\u6700\u5c0f\u5316\u53bb\u52a0\u6cb9\u7ad9\u7684\u6700\u5927\u8ddd\u79bb", "title_en": "Minimize Max Distance to Gas Station", "question_title_slug": "minimize-max-distance-to-gas-station", "content_en": "

    You are given an integer array stations that represents the positions of the gas stations on the x-axis. You are also given an integer k.

    \n\n

    You should add k new gas stations. You can add the stations anywhere on the x-axis, and not necessarily on an integer position.

    \n\n

    Let penalty() be the maximum distance between adjacent gas stations after adding the k new stations.

    \n\n

    Return the smallest possible value of penalty(). Answers within 10-6 of the actual answer will be accepted.

    \n\n

     

    \n

    Example 1:

    \n
    Input: stations = [1,2,3,4,5,6,7,8,9,10], k = 9\nOutput: 0.50000\n

    Example 2:

    \n
    Input: stations = [23,24,36,39,46,56,57,65,84,98], k = 1\nOutput: 14.00000\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 10 <= stations.length <= 2000
    • \n\t
    • 0 <= stations[i] <= 108
    • \n\t
    • stations is sorted in a strictly increasing order.
    • \n\t
    • 1 <= k <= 106
    • \n
    \n", "content_cn": "

    \u6574\u6570\u6570\u7ec4 stations \u8868\u793a \u6c34\u5e73\u6570\u8f74 \u4e0a\u5404\u4e2a\u52a0\u6cb9\u7ad9\u7684\u4f4d\u7f6e\u3002\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 k \u3002

    \n\n

    \u8bf7\u4f60\u5728\u6570\u8f74\u4e0a\u589e\u8bbe k \u4e2a\u52a0\u6cb9\u7ad9\uff0c\u65b0\u589e\u52a0\u6cb9\u7ad9\u53ef\u4ee5\u4f4d\u4e8e \u6c34\u5e73\u6570\u8f74 \u4e0a\u7684\u4efb\u610f\u4f4d\u7f6e\uff0c\u800c\u4e0d\u5fc5\u653e\u5728\u6574\u6570\u4f4d\u7f6e\u4e0a\u3002

    \n\n

    \u8bbe penalty() \u662f\uff1a\u589e\u8bbe k \u4e2a\u65b0\u52a0\u6cb9\u7ad9\u540e\uff0c\u76f8\u90bb \u4e24\u4e2a\u52a0\u6cb9\u7ad9\u95f4\u7684\u6700\u5927\u8ddd\u79bb\u3002

    \n\u8bf7\u4f60\u8fd4\u56de\u00a0penalty() \u53ef\u80fd\u7684\u6700\u5c0f\u503c\u3002\u4e0e\u5b9e\u9645\u7b54\u6848\u8bef\u5dee\u5728 10-6 \u8303\u56f4\u5185\u7684\u7b54\u6848\u5c06\u88ab\u89c6\u4f5c\u6b63\u786e\u7b54\u6848\u3002\n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1astations = [1,2,3,4,5,6,7,8,9,10], k = 9\n\u8f93\u51fa\uff1a0.50000\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1astations = [23,24,36,39,46,56,57,65,84,98], k = 1\n\u8f93\u51fa\uff1a14.00000\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 10 <= stations.length <= 2000
    • \n\t
    • 0 <= stations[i] <= 108
    • \n\t
    • stations \u6309 \u4e25\u683c\u9012\u589e \u987a\u5e8f\u6392\u5217
    • \n\t
    • 1 <= k <= 106
    • \n
    \n", "tags_en": ["Binary Search"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n double minmaxGasDist(vector& stations, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double minmaxGasDist(int[] stations, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minmaxGasDist(self, stations, k):\n \"\"\"\n :type stations: List[int]\n :type k: int\n :rtype: float\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minmaxGasDist(self, stations: List[int], k: int) -> float:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\ndouble minmaxGasDist(int* stations, int stationsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double MinmaxGasDist(int[] stations, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} stations\n * @param {number} k\n * @return {number}\n */\nvar minmaxGasDist = function(stations, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} stations\n# @param {Integer} k\n# @return {Float}\ndef minmax_gas_dist(stations, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minmaxGasDist(_ stations: [Int], _ k: Int) -> Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minmaxGasDist(stations []int, k int) float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minmaxGasDist(stations: Array[Int], k: Int): Double = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minmaxGasDist(stations: IntArray, k: Int): Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minmax_gas_dist(stations: Vec, k: i32) -> f64 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $stations\n * @param Integer $k\n * @return Float\n */\n function minmaxGasDist($stations, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minmaxGasDist(stations: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minmax-gas-dist stations k)\n (-> (listof exact-integer?) exact-integer? flonum?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0774](https://leetcode-cn.com/problems/minimize-max-distance-to-gas-station)", "[\u6700\u5c0f\u5316\u53bb\u52a0\u6cb9\u7ad9\u7684\u6700\u5927\u8ddd\u79bb](/solution/0700-0799/0774.Minimize%20Max%20Distance%20to%20Gas%20Station/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0774](https://leetcode.com/problems/minimize-max-distance-to-gas-station)", "[Minimize Max Distance to Gas Station](/solution/0700-0799/0774.Minimize%20Max%20Distance%20to%20Gas%20Station/README_EN.md)", "`Binary Search`", "Hard", "\ud83d\udd12"]}, {"question_id": "0787", "frontend_question_id": "0773", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sliding-puzzle", "url_en": "https://leetcode.com/problems/sliding-puzzle", "relative_path_cn": "/solution/0700-0799/0773.Sliding%20Puzzle/README.md", "relative_path_en": "/solution/0700-0799/0773.Sliding%20Puzzle/README_EN.md", "title_cn": "\u6ed1\u52a8\u8c1c\u9898", "title_en": "Sliding Puzzle", "question_title_slug": "sliding-puzzle", "content_en": "

    On a 2x3 board, there are 5 tiles represented by the integers 1 through 5, and an empty square represented by 0.

    \r\n\r\n

    A move consists of choosing 0 and a 4-directionally adjacent number and swapping it.

    \r\n\r\n

    The state of the board is solved if and only if the board is [[1,2,3],[4,5,0]].

    \r\n\r\n

    Given a puzzle board, return the least number of moves required so that the state of the board is solved. If it is impossible for the state of the board to be solved, return -1.

    \r\n\r\n

    Examples:

    \r\n\r\n
    \r\nInput: board = [[1,2,3],[4,0,5]]\r\nOutput: 1\r\nExplanation: Swap the 0 and the 5 in one move.\r\n
    \r\n\r\n
    \r\nInput: board = [[1,2,3],[5,4,0]]\r\nOutput: -1\r\nExplanation: No number of moves will make the board solved.\r\n
    \r\n\r\n
    \r\nInput: board = [[4,1,2],[5,0,3]]\r\nOutput: 5\r\nExplanation: 5 is the smallest number of moves that solves the board.\r\nAn example path:\r\nAfter move 0: [[4,1,2],[5,0,3]]\r\nAfter move 1: [[4,1,2],[0,5,3]]\r\nAfter move 2: [[0,1,2],[4,5,3]]\r\nAfter move 3: [[1,0,2],[4,5,3]]\r\nAfter move 4: [[1,2,0],[4,5,3]]\r\nAfter move 5: [[1,2,3],[4,5,0]]\r\n
    \r\n\r\n
    \r\nInput: board = [[3,2,4],[1,5,0]]\r\nOutput: 14\r\n
    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    • board will be a 2 x 3 array as described above.
    • \r\n\t
    • board[i][j] will be a permutation of [0, 1, 2, 3, 4, 5].
    • \r\n
    \r\n", "content_cn": "

    \u5728\u4e00\u4e2a 2 x 3 \u7684\u677f\u4e0a\uff08board\uff09\u6709 5 \u5757\u7816\u74e6\uff0c\u7528\u6570\u5b57 1~5 \u6765\u8868\u793a, \u4ee5\u53ca\u4e00\u5757\u7a7a\u7f3a\u7528 0 \u6765\u8868\u793a.

    \n\n

    \u4e00\u6b21\u79fb\u52a8\u5b9a\u4e49\u4e3a\u9009\u62e9 0 \u4e0e\u4e00\u4e2a\u76f8\u90bb\u7684\u6570\u5b57\uff08\u4e0a\u4e0b\u5de6\u53f3\uff09\u8fdb\u884c\u4ea4\u6362.

    \n\n

    \u6700\u7ec8\u5f53\u677f board \u7684\u7ed3\u679c\u662f [[1,2,3],[4,5,0]] \u8c1c\u677f\u88ab\u89e3\u5f00\u3002

    \n\n

    \u7ed9\u51fa\u4e00\u4e2a\u8c1c\u677f\u7684\u521d\u59cb\u72b6\u6001\uff0c\u8fd4\u56de\u6700\u5c11\u53ef\u4ee5\u901a\u8fc7\u591a\u5c11\u6b21\u79fb\u52a8\u89e3\u5f00\u8c1c\u677f\uff0c\u5982\u679c\u4e0d\u80fd\u89e3\u5f00\u8c1c\u677f\uff0c\u5219\u8fd4\u56de -1 \u3002

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1aboard = [[1,2,3],[4,0,5]]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u4ea4\u6362 0 \u548c 5 \uff0c1 \u6b65\u5b8c\u6210\n
    \n\n
    \n\u8f93\u5165\uff1aboard = [[1,2,3],[5,4,0]]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u6ca1\u6709\u529e\u6cd5\u5b8c\u6210\u8c1c\u677f\n
    \n\n
    \n\u8f93\u5165\uff1aboard = [[4,1,2],[5,0,3]]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\n\u6700\u5c11\u5b8c\u6210\u8c1c\u677f\u7684\u6700\u5c11\u79fb\u52a8\u6b21\u6570\u662f 5 \uff0c\n\u4e00\u79cd\u79fb\u52a8\u8def\u5f84:\n\u5c1a\u672a\u79fb\u52a8: [[4,1,2],[5,0,3]]\n\u79fb\u52a8 1 \u6b21: [[4,1,2],[0,5,3]]\n\u79fb\u52a8 2 \u6b21: [[0,1,2],[4,5,3]]\n\u79fb\u52a8 3 \u6b21: [[1,0,2],[4,5,3]]\n\u79fb\u52a8 4 \u6b21: [[1,2,0],[4,5,3]]\n\u79fb\u52a8 5 \u6b21: [[1,2,3],[4,5,0]]\n
    \n\n
    \n\u8f93\u5165\uff1aboard = [[3,2,4],[1,5,0]]\n\u8f93\u51fa\uff1a14\n
    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • board \u662f\u4e00\u4e2a\u5982\u4e0a\u6240\u8ff0\u7684 2 x 3 \u7684\u6570\u7ec4.
    • \n\t
    • board[i][j] \u662f\u4e00\u4e2a [0, 1, 2, 3, 4, 5] \u7684\u6392\u5217.
    • \n
    \n", "tags_en": ["Breadth-first Search"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int slidingPuzzle(vector>& board) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int slidingPuzzle(int[][] board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def slidingPuzzle(self, board):\n \"\"\"\n :type board: List[List[int]]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def slidingPuzzle(self, board: List[List[int]]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint slidingPuzzle(int** board, int boardSize, int* boardColSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SlidingPuzzle(int[][] board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} board\n * @return {number}\n */\nvar slidingPuzzle = function(board) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} board\n# @return {Integer}\ndef sliding_puzzle(board)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func slidingPuzzle(_ board: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func slidingPuzzle(board [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def slidingPuzzle(board: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun slidingPuzzle(board: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sliding_puzzle(board: Vec>) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $board\n * @return Integer\n */\n function slidingPuzzle($board) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function slidingPuzzle(board: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (sliding-puzzle board)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0773](https://leetcode-cn.com/problems/sliding-puzzle)", "[\u6ed1\u52a8\u8c1c\u9898](/solution/0700-0799/0773.Sliding%20Puzzle/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[0773](https://leetcode.com/problems/sliding-puzzle)", "[Sliding Puzzle](/solution/0700-0799/0773.Sliding%20Puzzle/README_EN.md)", "`Breadth-first Search`", "Hard", ""]}, {"question_id": "0786", "frontend_question_id": "0702", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/search-in-a-sorted-array-of-unknown-size", "url_en": "https://leetcode.com/problems/search-in-a-sorted-array-of-unknown-size", "relative_path_cn": "/solution/0700-0799/0702.Search%20in%20a%20Sorted%20Array%20of%20Unknown%20Size/README.md", "relative_path_en": "/solution/0700-0799/0702.Search%20in%20a%20Sorted%20Array%20of%20Unknown%20Size/README_EN.md", "title_cn": "\u641c\u7d22\u957f\u5ea6\u672a\u77e5\u7684\u6709\u5e8f\u6570\u7ec4", "title_en": "Search in a Sorted Array of Unknown Size", "question_title_slug": "search-in-a-sorted-array-of-unknown-size", "content_en": "

    Given an integer array sorted in ascending order, write a function to search target in nums.  If target exists, then return its index, otherwise return -1. However, the array size is unknown to you. You may only access the array using an ArrayReader interface, where ArrayReader.get(k) returns the element of the array at index k (0-indexed).

    \n\n

    You may assume all integers in the array are less than 10000, and if you access the array out of bounds, ArrayReader.get will return 2147483647.

    \n\n

    You must write an algorithm with O(log n) runtime complexity.

    \n\n

     

    \n\n

    Example 1:

    \n\n
    \nInput: array = [-1,0,3,5,9,12], target = 9\nOutput: 4\nExplanation: 9 exists in nums and its index is 4\n
    \n\n

    Example 2:

    \n\n
    \nInput: array = [-1,0,3,5,9,12], target = 2\nOutput: -1\nExplanation: 2 does not exist in nums so return -1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • You may assume that all elements in the array are unique.
    • \n\t
    • The value of each element in the array will be in the range [-9999, 9999].
    • \n\t
    • The length of the array will be in the range [1, 10^4].
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5347\u5e8f\u6574\u6570\u6570\u7ec4\uff0c\u5199\u4e00\u4e2a\u51fd\u6570\u641c\u7d22 nums \u4e2d\u6570\u5b57 target\u3002\u5982\u679c target \u5b58\u5728\uff0c\u8fd4\u56de\u5b83\u7684\u4e0b\u6807\uff0c\u5426\u5219\u8fd4\u56de -1\u3002\u6ce8\u610f\uff0c\u8fd9\u4e2a\u6570\u7ec4\u7684\u5927\u5c0f\u662f\u672a\u77e5\u7684\u3002\u4f60\u53ea\u53ef\u4ee5\u901a\u8fc7 ArrayReader \u63a5\u53e3\u8bbf\u95ee\u8fd9\u4e2a\u6570\u7ec4\uff0cArrayReader.get(k) \u8fd4\u56de\u6570\u7ec4\u4e2d\u7b2c k \u4e2a\u5143\u7d20\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u8ba4\u4e3a\u6570\u7ec4\u4e2d\u6240\u6709\u7684\u6574\u6570\u90fd\u5c0f\u4e8e 10000\u3002\u5982\u679c\u4f60\u8bbf\u95ee\u6570\u7ec4\u8d8a\u754c\uff0cArrayReader.get \u4f1a\u8fd4\u56de 2147483647\u3002

    \n\n

     

    \n\n

    \u6837\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165: array = [-1,0,3,5,9,12], target = 9\n\u8f93\u51fa: 4\n\u89e3\u91ca: 9 \u5b58\u5728\u5728 nums \u4e2d\uff0c\u4e0b\u6807\u4e3a 4\n
    \n\n

    \u6837\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165: array = [-1,0,3,5,9,12], target = 2\n\u8f93\u51fa: -1\n\u89e3\u91ca: 2 \u4e0d\u5728\u6570\u7ec4\u4e2d\u6240\u4ee5\u8fd4\u56de -1
    \n\n

     

    \n\n

    \u6ce8\u91ca \uff1a

    \n\n
      \n\t
    1. \u4f60\u53ef\u4ee5\u8ba4\u4e3a\u6570\u7ec4\u4e2d\u6240\u6709\u5143\u7d20\u7684\u503c\u4e92\u4e0d\u76f8\u540c\u3002
    2. \n\t
    3. \u6570\u7ec4\u5143\u7d20\u7684\u503c\u57df\u662f [-9999, 9999]\u3002
    4. \n
    \n", "tags_en": ["Binary Search"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * // This is the ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * class ArrayReader {\n * public:\n * int get(int index);\n * };\n */\n\nclass Solution {\npublic:\n int search(const ArrayReader& reader, int target) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * // This is ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * interface ArrayReader {\n * public int get(int index) {}\n * }\n */\n\nclass Solution {\n public int search(ArrayReader reader, int target) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# \"\"\"\n# This is ArrayReader's API interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class ArrayReader(object):\n# def get(self, index):\n# \"\"\"\n# :type index: int\n# :rtype int\n# \"\"\"\n\nclass Solution(object):\n def search(self, reader, target):\n \"\"\"\n :type reader: ArrayReader\n :type target: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# \"\"\"\n# This is ArrayReader's API interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class ArrayReader:\n# def get(self, index: int) -> int:\n\nclass Solution:\n def search(self, reader, target):\n \"\"\"\n :type reader: ArrayReader\n :type target: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * *********************************************************************\n * // This is the ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * *********************************************************************\n *\n * int getElement(ArrayReader *, int index);\n */\n\nint search(struct ArrayReader* reader, int target) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * // This is ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * class ArrayReader {\n * public int Get(int index) {}\n * }\n */\n\nclass Solution {\n public int Search(ArrayReader reader, int target) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // This is the ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * function ArrayReader() {\n *\n * @param {number} index\n * @return {number}\n * this.get = function(index) {\n * ...\n * };\n * };\n */\n\n/**\n * @param {ArrayReader} reader\n * @param {number} target\n * @return {number}\n */\nvar search = function (reader, target) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# This is ArrayReader's API interface.\n# You should not implement it, or speculate about its implementation\n# class ArrayReader\n# def get(index)\n#\t\t\n# end\n# end\n\n# @param {ArrayReader} reader\n# @param {int} target\n# @return {int}\ndef search(reader, target)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * // This is ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * public class ArrayReader {\n * public func get(_ index: Int) -> Int {}\n * }\n */\n\nclass Solution {\n func search(_ reader: ArrayReader, _ target: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * // This is the ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * type ArrayReader struct {\n * }\n *\n * func (this *ArrayReader) get(index int) int {}\n */\n\nfunc search(reader ArrayReader, target int) int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * // This is ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * class ArrayReader {\n * def get(index: Int): Int = {}\n * }\n */\n\nobject Solution {\n def search(reader: ArrayReader, target: Int): Int = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * // This is ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * class ArrayReader {\n * fun get(index: Int): Int {}\n * }\n */\n\nclass Solution {\n fun search(reader: ArrayReader, target: Int): Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * // This is ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * class ArrayReader {\n * function get($index) {}\n * }\n */\n\nclass Solution {\n /**\n * @param ArrayReader $reader\n * @param Integer $target\n * @return Integer\n */\n function search($reader, $target) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * class ArrayReader {\n *\t\t// This is the ArrayReader's API interface.\n *\t\t// You should not implement it, or speculate about its implementation\n *\t\tget(index: number): number {};\n * };\n */\n\nfunction search(reader: ArrayReader, target: number): number {\n\t\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0702](https://leetcode-cn.com/problems/search-in-a-sorted-array-of-unknown-size)", "[\u641c\u7d22\u957f\u5ea6\u672a\u77e5\u7684\u6709\u5e8f\u6570\u7ec4](/solution/0700-0799/0702.Search%20in%20a%20Sorted%20Array%20of%20Unknown%20Size/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0702](https://leetcode.com/problems/search-in-a-sorted-array-of-unknown-size)", "[Search in a Sorted Array of Unknown Size](/solution/0700-0799/0702.Search%20in%20a%20Sorted%20Array%20of%20Unknown%20Size/README_EN.md)", "`Binary Search`", "Medium", "\ud83d\udd12"]}, {"question_id": "0785", "frontend_question_id": "0772", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/basic-calculator-iii", "url_en": "https://leetcode.com/problems/basic-calculator-iii", "relative_path_cn": "/solution/0700-0799/0772.Basic%20Calculator%20III/README.md", "relative_path_en": "/solution/0700-0799/0772.Basic%20Calculator%20III/README_EN.md", "title_cn": "\u57fa\u672c\u8ba1\u7b97\u5668 III", "title_en": "Basic Calculator III", "question_title_slug": "basic-calculator-iii", "content_en": "

    Implement a basic calculator to evaluate a simple expression string.

    \n\n

    The expression string contains only non-negative integers, '+', '-', '*', '/' operators, and open '(' and closing parentheses ')'. The integer division should truncate toward zero.

    \n\n

    You may assume that the given expression is always valid. All intermediate results will be in the range of [-231, 231 - 1].

    \n\n

    Note: You are not allowed to use any built-in function which evaluates strings as mathematical expressions, such as eval().

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "1+1"\nOutput: 2\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "6-4/2"\nOutput: 4\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "2*(5+5*2)/3+(6/2+8)"\nOutput: 21\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "(2+6*3+5-(3*14/7+2)*5)+3"\nOutput: -12\n
    \n\n

    Example 5:

    \n\n
    \nInput: s = "0"\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s <= 104
    • \n\t
    • s consists of digits, '+', '-', '*', '/', '(', and ')'.
    • \n\t
    • s is a valid expression.
    • \n
    \n", "content_cn": "

    \u5b9e\u73b0\u4e00\u4e2a\u57fa\u672c\u7684\u8ba1\u7b97\u5668\u6765\u8ba1\u7b97\u7b80\u5355\u7684\u8868\u8fbe\u5f0f\u5b57\u7b26\u4e32\u3002

    \n\n

    \u8868\u8fbe\u5f0f\u5b57\u7b26\u4e32\u53ea\u5305\u542b\u975e\u8d1f\u6574\u6570\uff0c\u7b97\u7b26 +\u3001-\u3001*\u3001/ \uff0c\u5de6\u62ec\u53f7 ( \u548c\u53f3\u62ec\u53f7 ) \u3002\u6574\u6570\u9664\u6cd5\u9700\u8981 \u5411\u4e0b\u622a\u65ad \u3002

    \n\n

    \u4f60\u53ef\u4ee5\u5047\u5b9a\u7ed9\u5b9a\u7684\u8868\u8fbe\u5f0f\u603b\u662f\u6709\u6548\u7684\u3002\u6240\u6709\u7684\u4e2d\u95f4\u7ed3\u679c\u7684\u8303\u56f4\u4e3a [-231, 231 - 1] \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"1+1\"\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"6-4/2\"\n\u8f93\u51fa\uff1a4\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"2*(5+5*2)/3+(6/2+8)\"\n\u8f93\u51fa\uff1a21\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"(2+6*3+5-(3*14/7+2)*5)+3\"\n\u8f93\u51fa\uff1a-12\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"0\"\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s <= 104
    • \n\t
    • s \u7531\u6574\u6570\u3001'+'\u3001'-'\u3001'*'\u3001'/'\u3001'(' \u548c ')' \u7ec4\u6210
    • \n\t
    • s \u662f\u4e00\u4e2a \u6709\u6548\u7684 \u8868\u8fbe\u5f0f
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u53ef\u4ee5\u5728\u4e0d\u4f7f\u7528\u5185\u7f6e\u5e93\u51fd\u6570\u7684\u60c5\u51b5\u4e0b\u89e3\u51b3\u6b64\u95ee\u9898\u5417\uff1f

    \n", "tags_en": ["Stack", "String"], "tags_cn": ["\u6808", "\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int calculate(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int calculate(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def calculate(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def calculate(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint calculate(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int Calculate(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar calculate = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef calculate(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func calculate(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func calculate(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def calculate(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun calculate(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn calculate(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function calculate($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function calculate(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (calculate s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0772](https://leetcode-cn.com/problems/basic-calculator-iii)", "[\u57fa\u672c\u8ba1\u7b97\u5668 III](/solution/0700-0799/0772.Basic%20Calculator%20III/README.md)", "`\u6808`,`\u5b57\u7b26\u4e32`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0772](https://leetcode.com/problems/basic-calculator-iii)", "[Basic Calculator III](/solution/0700-0799/0772.Basic%20Calculator%20III/README_EN.md)", "`Stack`,`String`", "Hard", "\ud83d\udd12"]}, {"question_id": "0784", "frontend_question_id": "0701", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/insert-into-a-binary-search-tree", "url_en": "https://leetcode.com/problems/insert-into-a-binary-search-tree", "relative_path_cn": "/solution/0700-0799/0701.Insert%20into%20a%20Binary%20Search%20Tree/README.md", "relative_path_en": "/solution/0700-0799/0701.Insert%20into%20a%20Binary%20Search%20Tree/README_EN.md", "title_cn": "\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u7684\u63d2\u5165\u64cd\u4f5c", "title_en": "Insert into a Binary Search Tree", "question_title_slug": "insert-into-a-binary-search-tree", "content_en": "

    You are given the root node of a binary search tree (BST) and a value to insert into the tree. Return the root node of the BST after the insertion. It is guaranteed that the new value does not exist in the original BST.

    \n\n

    Notice that there may exist multiple valid ways for the insertion, as long as the tree remains a BST after insertion. You can return any of them.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [4,2,7,1,3], val = 5\nOutput: [4,2,7,1,3,5]\nExplanation: Another accepted tree is:\n\"\"\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = [40,20,60,10,30,50,70], val = 25\nOutput: [40,20,60,10,30,50,70,null,null,25]\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = [4,2,7,1,3,null,null,null,null,null,null], val = 5\nOutput: [4,2,7,1,3,5]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree will be in the range [0, 104].
    • \n\t
    • -108 <= Node.val <= 108
    • \n\t
    • All the values Node.val are unique.
    • \n\t
    • -108 <= val <= 108
    • \n\t
    • It's guaranteed that val does not exist in the original BST.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e8c\u53c9\u641c\u7d22\u6811\uff08BST\uff09\u7684\u6839\u8282\u70b9\u548c\u8981\u63d2\u5165\u6811\u4e2d\u7684\u503c\uff0c\u5c06\u503c\u63d2\u5165\u4e8c\u53c9\u641c\u7d22\u6811\u3002 \u8fd4\u56de\u63d2\u5165\u540e\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6839\u8282\u70b9\u3002 \u8f93\u5165\u6570\u636e \u4fdd\u8bc1 \uff0c\u65b0\u503c\u548c\u539f\u59cb\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u7684\u4efb\u610f\u8282\u70b9\u503c\u90fd\u4e0d\u540c\u3002

    \n\n

    \u6ce8\u610f\uff0c\u53ef\u80fd\u5b58\u5728\u591a\u79cd\u6709\u6548\u7684\u63d2\u5165\u65b9\u5f0f\uff0c\u53ea\u8981\u6811\u5728\u63d2\u5165\u540e\u4ecd\u4fdd\u6301\u4e3a\u4e8c\u53c9\u641c\u7d22\u6811\u5373\u53ef\u3002 \u4f60\u53ef\u4ee5\u8fd4\u56de \u4efb\u610f\u6709\u6548\u7684\u7ed3\u679c \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [4,2,7,1,3], val = 5\n\u8f93\u51fa\uff1a[4,2,7,1,3,5]\n\u89e3\u91ca\uff1a\u53e6\u4e00\u4e2a\u6ee1\u8db3\u9898\u76ee\u8981\u6c42\u53ef\u4ee5\u901a\u8fc7\u7684\u6811\u662f\uff1a\n\"\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [40,20,60,10,30,50,70], val = 25\n\u8f93\u51fa\uff1a[40,20,60,10,30,50,70,null,null,25]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [4,2,7,1,3,null,null,null,null,null,null], val = 5\n\u8f93\u51fa\uff1a[4,2,7,1,3,5]\n
    \n\n

    \u00a0

    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u7ed9\u5b9a\u7684\u6811\u4e0a\u7684\u8282\u70b9\u6570\u4ecb\u4e8e 0 \u548c 10^4 \u4e4b\u95f4
    • \n\t
    • \u6bcf\u4e2a\u8282\u70b9\u90fd\u6709\u4e00\u4e2a\u552f\u4e00\u6574\u6570\u503c\uff0c\u53d6\u503c\u8303\u56f4\u4ece 0 \u5230 10^8
    • \n\t
    • -10^8 <= val <= 10^8
    • \n\t
    • \u65b0\u503c\u548c\u539f\u59cb\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u7684\u4efb\u610f\u8282\u70b9\u503c\u90fd\u4e0d\u540c
    • \n
    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* insertIntoBST(TreeNode* root, int val) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode insertIntoBST(TreeNode root, int val) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def insertIntoBST(self, root, val):\n \"\"\"\n :type root: TreeNode\n :type val: int\n :rtype: TreeNode\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def insertIntoBST(self, root: TreeNode, val: int) -> TreeNode:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* insertIntoBST(struct TreeNode* root, int val){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode InsertIntoBST(TreeNode root, int val) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number} val\n * @return {TreeNode}\n */\nvar insertIntoBST = function(root, val) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @param {Integer} val\n# @return {TreeNode}\ndef insert_into_bst(root, val)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func insertIntoBST(_ root: TreeNode?, _ val: Int) -> TreeNode? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc insertIntoBST(root *TreeNode, val int) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def insertIntoBST(root: TreeNode, `val`: Int): TreeNode = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun insertIntoBST(root: TreeNode?, `val`: Int): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn insert_into_bst(root: Option>>, val: i32) -> Option>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param Integer $val\n * @return TreeNode\n */\n function insertIntoBST($root, $val) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction insertIntoBST(root: TreeNode | null, val: number): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (insert-into-bst root val)\n (-> (or/c tree-node? #f) exact-integer? (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0701](https://leetcode-cn.com/problems/insert-into-a-binary-search-tree)", "[\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u7684\u63d2\u5165\u64cd\u4f5c](/solution/0700-0799/0701.Insert%20into%20a%20Binary%20Search%20Tree/README.md)", "`\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0701](https://leetcode.com/problems/insert-into-a-binary-search-tree)", "[Insert into a Binary Search Tree](/solution/0700-0799/0701.Insert%20into%20a%20Binary%20Search%20Tree/README_EN.md)", "`Tree`", "Medium", ""]}, {"question_id": "0783", "frontend_question_id": "0700", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/search-in-a-binary-search-tree", "url_en": "https://leetcode.com/problems/search-in-a-binary-search-tree", "relative_path_cn": "/solution/0700-0799/0700.Search%20in%20a%20Binary%20Search%20Tree/README.md", "relative_path_en": "/solution/0700-0799/0700.Search%20in%20a%20Binary%20Search%20Tree/README_EN.md", "title_cn": "\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u7684\u641c\u7d22", "title_en": "Search in a Binary Search Tree", "question_title_slug": "search-in-a-binary-search-tree", "content_en": "

    You are given the root of a binary search tree (BST) and an integer val.

    \n\n

    Find the node in the BST that the node's value equals val and return the subtree rooted with that node. If such a node does not exist, return null.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [4,2,7,1,3], val = 2\nOutput: [2,1,3]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [4,2,7,1,3], val = 5\nOutput: []\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 5000].
    • \n\t
    • 1 <= Node.val <= 107
    • \n\t
    • root is a binary search tree.
    • \n\t
    • 1 <= val <= 107
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e8c\u53c9\u641c\u7d22\u6811\uff08BST\uff09\u7684\u6839\u8282\u70b9\u548c\u4e00\u4e2a\u503c\u3002 \u4f60\u9700\u8981\u5728BST\u4e2d\u627e\u5230\u8282\u70b9\u503c\u7b49\u4e8e\u7ed9\u5b9a\u503c\u7684\u8282\u70b9\u3002 \u8fd4\u56de\u4ee5\u8be5\u8282\u70b9\u4e3a\u6839\u7684\u5b50\u6811\u3002 \u5982\u679c\u8282\u70b9\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de NULL\u3002

    \n\n

    \u4f8b\u5982\uff0c

    \n\n
    \n\u7ed9\u5b9a\u4e8c\u53c9\u641c\u7d22\u6811:\n\n        4\n       / \\\n      2   7\n     / \\\n    1   3\n\n\u548c\u503c: 2\n
    \n\n

    \u4f60\u5e94\u8be5\u8fd4\u56de\u5982\u4e0b\u5b50\u6811:

    \n\n
    \n      2     \n     / \\   \n    1   3\n
    \n\n

    \u5728\u4e0a\u8ff0\u793a\u4f8b\u4e2d\uff0c\u5982\u679c\u8981\u627e\u7684\u503c\u662f 5\uff0c\u4f46\u56e0\u4e3a\u6ca1\u6709\u8282\u70b9\u503c\u4e3a 5\uff0c\u6211\u4eec\u5e94\u8be5\u8fd4\u56de NULL\u3002

    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* searchBST(TreeNode* root, int val) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode searchBST(TreeNode root, int val) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def searchBST(self, root, val):\n \"\"\"\n :type root: TreeNode\n :type val: int\n :rtype: TreeNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def searchBST(self, root: TreeNode, val: int) -> TreeNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* searchBST(struct TreeNode* root, int val){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode SearchBST(TreeNode root, int val) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number} val\n * @return {TreeNode}\n */\nvar searchBST = function(root, val) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @param {Integer} val\n# @return {TreeNode}\ndef search_bst(root, val)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func searchBST(_ root: TreeNode?, _ val: Int) -> TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc searchBST(root *TreeNode, val int) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def searchBST(root: TreeNode, `val`: Int): TreeNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun searchBST(root: TreeNode?, `val`: Int): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn search_bst(root: Option>>, val: i32) -> Option>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param Integer $val\n * @return TreeNode\n */\n function searchBST($root, $val) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction searchBST(root: TreeNode | null, val: number): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (search-bst root val)\n (-> (or/c tree-node? #f) exact-integer? (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0700](https://leetcode-cn.com/problems/search-in-a-binary-search-tree)", "[\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u7684\u641c\u7d22](/solution/0700-0799/0700.Search%20in%20a%20Binary%20Search%20Tree/README.md)", "`\u6811`", "\u7b80\u5355", ""], "md_table_row_en": ["[0700](https://leetcode.com/problems/search-in-a-binary-search-tree)", "[Search in a Binary Search Tree](/solution/0700-0799/0700.Search%20in%20a%20Binary%20Search%20Tree/README_EN.md)", "`Tree`", "Easy", ""]}, {"question_id": "0782", "frontend_question_id": "0771", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/jewels-and-stones", "url_en": "https://leetcode.com/problems/jewels-and-stones", "relative_path_cn": "/solution/0700-0799/0771.Jewels%20and%20Stones/README.md", "relative_path_en": "/solution/0700-0799/0771.Jewels%20and%20Stones/README_EN.md", "title_cn": "\u5b9d\u77f3\u4e0e\u77f3\u5934", "title_en": "Jewels and Stones", "question_title_slug": "jewels-and-stones", "content_en": "

    You're given strings jewels representing the types of stones that are jewels, and stones representing the stones you have. Each character in stones is a type of stone you have. You want to know how many of the stones you have are also jewels.

    \n\n

    Letters are case sensitive, so "a" is considered a different type of stone from "A".

    \n\n

     

    \n

    Example 1:

    \n
    Input: jewels = \"aA\", stones = \"aAAbbbb\"\nOutput: 3\n

    Example 2:

    \n
    Input: jewels = \"z\", stones = \"ZZ\"\nOutput: 0\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= jewels.length, stones.length <= 50
    • \n\t
    • jewels and stones consist of only English letters.
    • \n\t
    • All the characters of jewels are unique.
    • \n
    \n", "content_cn": "

     \u7ed9\u5b9a\u5b57\u7b26\u4e32J \u4ee3\u8868\u77f3\u5934\u4e2d\u5b9d\u77f3\u7684\u7c7b\u578b\uff0c\u548c\u5b57\u7b26\u4e32 S\u4ee3\u8868\u4f60\u62e5\u6709\u7684\u77f3\u5934\u3002 S \u4e2d\u6bcf\u4e2a\u5b57\u7b26\u4ee3\u8868\u4e86\u4e00\u79cd\u4f60\u62e5\u6709\u7684\u77f3\u5934\u7684\u7c7b\u578b\uff0c\u4f60\u60f3\u77e5\u9053\u4f60\u62e5\u6709\u7684\u77f3\u5934\u4e2d\u6709\u591a\u5c11\u662f\u5b9d\u77f3\u3002

    \n\n

    J \u4e2d\u7684\u5b57\u6bcd\u4e0d\u91cd\u590d\uff0cJ \u548c S\u4e2d\u7684\u6240\u6709\u5b57\u7b26\u90fd\u662f\u5b57\u6bcd\u3002\u5b57\u6bcd\u533a\u5206\u5927\u5c0f\u5199\uff0c\u56e0\u6b64"a"\u548c"A"\u662f\u4e0d\u540c\u7c7b\u578b\u7684\u77f3\u5934\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: J = "aA", S = "aAAbbbb"\n\u8f93\u51fa: 3\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: J = "z", S = "ZZ"\n\u8f93\u51fa: 0\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    • S \u548c J \u6700\u591a\u542b\u670950\u4e2a\u5b57\u6bcd\u3002
    • \n\t
    •  J \u4e2d\u7684\u5b57\u7b26\u4e0d\u91cd\u590d\u3002
    • \n
    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numJewelsInStones(string jewels, string stones) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numJewelsInStones(String jewels, String stones) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numJewelsInStones(self, jewels, stones):\n \"\"\"\n :type jewels: str\n :type stones: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numJewelsInStones(self, jewels: str, stones: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numJewelsInStones(char * jewels, char * stones){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumJewelsInStones(string jewels, string stones) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} jewels\n * @param {string} stones\n * @return {number}\n */\nvar numJewelsInStones = function(jewels, stones) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} jewels\n# @param {String} stones\n# @return {Integer}\ndef num_jewels_in_stones(jewels, stones)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numJewelsInStones(_ jewels: String, _ stones: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numJewelsInStones(jewels string, stones string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numJewelsInStones(jewels: String, stones: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numJewelsInStones(jewels: String, stones: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_jewels_in_stones(jewels: String, stones: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $jewels\n * @param String $stones\n * @return Integer\n */\n function numJewelsInStones($jewels, $stones) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numJewelsInStones(jewels: string, stones: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-jewels-in-stones jewels stones)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0771](https://leetcode-cn.com/problems/jewels-and-stones)", "[\u5b9d\u77f3\u4e0e\u77f3\u5934](/solution/0700-0799/0771.Jewels%20and%20Stones/README.md)", "`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0771](https://leetcode.com/problems/jewels-and-stones)", "[Jewels and Stones](/solution/0700-0799/0771.Jewels%20and%20Stones/README_EN.md)", "`Hash Table`", "Easy", ""]}, {"question_id": "0781", "frontend_question_id": "0770", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/basic-calculator-iv", "url_en": "https://leetcode.com/problems/basic-calculator-iv", "relative_path_cn": "/solution/0700-0799/0770.Basic%20Calculator%20IV/README.md", "relative_path_en": "/solution/0700-0799/0770.Basic%20Calculator%20IV/README_EN.md", "title_cn": "\u57fa\u672c\u8ba1\u7b97\u5668 IV", "title_en": "Basic Calculator IV", "question_title_slug": "basic-calculator-iv", "content_en": "

    Given an expression such as expression = "e + 8 - a + 5" and an evaluation map such as {"e": 1} (given in terms of evalvars = ["e"] and evalints = [1]), return a list of tokens representing the simplified expression, such as ["-1*a","14"]

    \r\n\r\n
      \r\n\t
    • An expression alternates chunks and symbols, with a space separating each chunk and symbol.
    • \r\n\t
    • A chunk is either an expression in parentheses, a variable, or a non-negative integer.
    • \r\n\t
    • A variable is a string of lowercase letters (not including digits.) Note that variables can be multiple letters, and note that variables never have a leading coefficient or unary operator like "2x" or "-x".
    • \r\n
    \r\n\r\n

    Expressions are evaluated in the usual order: brackets first, then multiplication, then addition and subtraction. For example, expression = "1 + 2 * 3" has an answer of ["7"].

    \r\n\r\n

    The format of the output is as follows:

    \r\n\r\n
      \r\n\t
    • For each term of free variables with non-zero coefficient, we write the free variables within a term in sorted order lexicographically. For example, we would never write a term like "b*a*c", only "a*b*c".
    • \r\n\t
    • Terms have degree equal to the number of free variables being multiplied, counting multiplicity. (For example, "a*a*b*c" has degree 4.) We write the largest degree terms of our answer first, breaking ties by lexicographic order ignoring the leading coefficient of the term.
    • \r\n\t
    • The leading coefficient of the term is placed directly to the left with an asterisk separating it from the variables (if they exist.)  A leading coefficient of 1 is still printed.
    • \r\n\t
    • An example of a well formatted answer is ["-2*a*a*a", "3*a*a*b", "3*b*b", "4*a", "5*c", "-6"] 
    • \r\n\t
    • Terms (including constant terms) with coefficient 0 are not included.  For example, an expression of "0" has an output of [].
    • \r\n
    \r\n\r\n

    Examples:

    \r\n\r\n
    \r\nInput: expression = "e + 8 - a + 5", evalvars = ["e"], evalints = [1]\r\nOutput: ["-1*a","14"]\r\n\r\nInput: expression = "e - 8 + temperature - pressure",\r\nevalvars = ["e", "temperature"], evalints = [1, 12]\r\nOutput: ["-1*pressure","5"]\r\n\r\nInput: expression = "(e + 8) * (e - 8)", evalvars = [], evalints = []\r\nOutput: ["1*e*e","-64"]\r\n\r\nInput: expression = "7 - 7", evalvars = [], evalints = []\r\nOutput: []\r\n\r\nInput: expression = "a * b * c + b * a * c * 4", evalvars = [], evalints = []\r\nOutput: ["5*a*b*c"]\r\n\r\nInput: expression = "((a - b) * (b - c) + (c - a)) * ((a - b) + (b - c) * (c - a))",\r\nevalvars = [], evalints = []\r\nOutput: ["-1*a*a*b*b","2*a*a*b*c","-1*a*a*c*c","1*a*b*b*b","-1*a*b*b*c","-1*a*b*c*c","1*a*c*c*c","-1*b*b*b*c","2*b*b*c*c","-1*b*c*c*c","2*a*a*b","-2*a*a*c","-2*a*b*b","2*a*c*c","1*b*b*b","-1*b*b*c","1*b*c*c","-1*c*c*c","-1*a*a","1*a*b","1*a*c","-1*b*c"]\r\n
    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    1. expression will have length in range [1, 250].
    2. \r\n\t
    3. evalvars, evalints will have equal lengths in range [0, 100].
    4. \r\n
    \r\n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u8868\u8fbe\u5f0f expression \u5982 expression = "e + 8 - a + 5" \u548c\u4e00\u4e2a\u6c42\u503c\u6620\u5c04\uff0c\u5982 {"e": 1}\uff08\u7ed9\u5b9a\u7684\u5f62\u5f0f\u4e3a evalvars = ["e"] \u548c evalints = [1]\uff09\uff0c\u8fd4\u56de\u8868\u793a\u7b80\u5316\u8868\u8fbe\u5f0f\u7684\u6807\u8bb0\u5217\u8868\uff0c\u4f8b\u5982 ["-1*a","14"]

    \n\n
      \n\t
    • \u8868\u8fbe\u5f0f\u4ea4\u66ff\u4f7f\u7528\u5757\u548c\u7b26\u53f7\uff0c\u6bcf\u4e2a\u5757\u548c\u7b26\u53f7\u4e4b\u95f4\u6709\u4e00\u4e2a\u7a7a\u683c\u3002
    • \n\t
    • \u5757\u8981\u4e48\u662f\u62ec\u53f7\u4e2d\u7684\u8868\u8fbe\u5f0f\uff0c\u8981\u4e48\u662f\u53d8\u91cf\uff0c\u8981\u4e48\u662f\u975e\u8d1f\u6574\u6570\u3002
    • \n\t
    • \u5757\u662f\u62ec\u53f7\u4e2d\u7684\u8868\u8fbe\u5f0f\uff0c\u53d8\u91cf\u6216\u975e\u8d1f\u6574\u6570\u3002
    • \n\t
    • \u53d8\u91cf\u662f\u4e00\u4e2a\u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210\u7684\u5b57\u7b26\u4e32\uff08\u4e0d\u5305\u62ec\u6570\u5b57\uff09\u3002\u8bf7\u6ce8\u610f\uff0c\u53d8\u91cf\u53ef\u4ee5\u662f\u591a\u4e2a\u5b57\u6bcd\uff0c\u5e76\u6ce8\u610f\u53d8\u91cf\u4ece\u4e0d\u5177\u6709\u50cf "2x" \u6216 "-x" \u8fd9\u6837\u7684\u524d\u5bfc\u7cfb\u6570\u6216\u4e00\u5143\u8fd0\u7b97\u7b26 \u3002
    • \n
    \n\n

    \u8868\u8fbe\u5f0f\u6309\u901a\u5e38\u987a\u5e8f\u8fdb\u884c\u6c42\u503c\uff1a\u5148\u662f\u62ec\u53f7\uff0c\u7136\u540e\u6c42\u4e58\u6cd5\uff0c\u518d\u8ba1\u7b97\u52a0\u6cd5\u548c\u51cf\u6cd5\u3002\u4f8b\u5982\uff0cexpression = "1 + 2 * 3" \u7684\u7b54\u6848\u662f ["7"]\u3002

    \n\n

    \u8f93\u51fa\u683c\u5f0f\u5982\u4e0b\uff1a

    \n\n
      \n\t
    • \u5bf9\u4e8e\u7cfb\u6570\u975e\u96f6\u7684\u6bcf\u4e2a\u81ea\u53d8\u91cf\u9879\uff0c\u6211\u4eec\u6309\u5b57\u5178\u6392\u5e8f\u7684\u987a\u5e8f\u5c06\u81ea\u53d8\u91cf\u5199\u5728\u4e00\u4e2a\u9879\u4e2d\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u6c38\u8fdc\u4e0d\u4f1a\u5199\u50cf “b*a*c” \u8fd9\u6837\u7684\u9879\uff0c\u53ea\u5199 “a*b*c”\u3002
    • \n\t
    • \u9879\u7684\u6b21\u6570\u7b49\u4e8e\u88ab\u4e58\u7684\u81ea\u53d8\u91cf\u7684\u6570\u76ee\uff0c\u5e76\u8ba1\u7b97\u91cd\u590d\u9879\u3002(\u4f8b\u5982\uff0c"a*a*b*c" \u7684\u6b21\u6570\u4e3a 4\u3002)\u3002\u6211\u4eec\u5148\u5199\u51fa\u7b54\u6848\u7684\u6700\u5927\u6b21\u6570\u9879\uff0c\u7528\u5b57\u5178\u987a\u5e8f\u6253\u7834\u5173\u7cfb\uff0c\u6b64\u65f6\u5ffd\u7565\u8bcd\u7684\u524d\u5bfc\u7cfb\u6570\u3002
    • \n\t
    • \u9879\u7684\u524d\u5bfc\u7cfb\u6570\u76f4\u63a5\u653e\u5728\u5de6\u8fb9\uff0c\u7528\u661f\u53f7\u5c06\u5b83\u4e0e\u53d8\u91cf\u5206\u9694\u5f00(\u5982\u679c\u5b58\u5728\u7684\u8bdd)\u3002\u524d\u5bfc\u7cfb\u6570 1 \u4ecd\u7136\u8981\u6253\u5370\u51fa\u6765\u3002
    • \n\t
    • \u683c\u5f0f\u826f\u597d\u7684\u4e00\u4e2a\u793a\u4f8b\u7b54\u6848\u662f ["-2*a*a*a", "3*a*a*b", "3*b*b", "4*a", "5*c", "-6"] \u3002
    • \n\t
    • \u7cfb\u6570\u4e3a 0 \u7684\u9879\uff08\u5305\u62ec\u5e38\u6570\u9879\uff09\u4e0d\u5305\u62ec\u5728\u5185\u3002\u4f8b\u5982\uff0c“0” \u7684\u8868\u8fbe\u5f0f\u8f93\u51fa\u4e3a []\u3002
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1aexpression = "e + 8 - a + 5", evalvars = ["e"], evalints = [1]\n\u8f93\u51fa\uff1a["-1*a","14"]\n\n\u8f93\u5165\uff1aexpression = "e - 8 + temperature - pressure",\nevalvars = ["e", "temperature"], evalints = [1, 12]\n\u8f93\u51fa\uff1a["-1*pressure","5"]\n\n\u8f93\u5165\uff1aexpression = "(e + 8) * (e - 8)", evalvars = [], evalints = []\n\u8f93\u51fa\uff1a["1*e*e","-64"]\n\n\u8f93\u5165\uff1aexpression = "7 - 7", evalvars = [], evalints = []\n\u8f93\u51fa\uff1a[]\n\n\u8f93\u5165\uff1aexpression = "a * b * c + b * a * c * 4", evalvars = [], evalints = []\n\u8f93\u51fa\uff1a["5*a*b*c"]\n\n\u8f93\u5165\uff1aexpression = "((a - b) * (b - c) + (c - a)) * ((a - b) + (b - c) * (c - a))",\nevalvars = [], evalints = []\n\u8f93\u51fa\uff1a["-1*a*a*b*b","2*a*a*b*c","-1*a*a*c*c","1*a*b*b*b","-1*a*b*b*c","-1*a*b*c*c","1*a*c*c*c","-1*b*b*b*c","2*b*b*c*c","-1*b*c*c*c","2*a*a*b","-2*a*a*c","-2*a*b*b","2*a*c*c","1*b*b*b","-1*b*b*c","1*b*c*c","-1*c*c*c","-1*a*a","1*a*b","1*a*c","-1*b*c"]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. expression \u7684\u957f\u5ea6\u5728 [1, 250] \u8303\u56f4\u5185\u3002
    2. \n\t
    3. evalvars, evalints \u5728\u8303\u56f4 [0, 100] \u5185\uff0c\u4e14\u957f\u5ea6\u76f8\u540c\u3002
    4. \n
    \n", "tags_en": ["Stack", "Hash Table", "String"], "tags_cn": ["\u6808", "\u54c8\u5e0c\u8868", "\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector basicCalculatorIV(string expression, vector& evalvars, vector& evalints) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List basicCalculatorIV(String expression, String[] evalvars, int[] evalints) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def basicCalculatorIV(self, expression, evalvars, evalints):\n \"\"\"\n :type expression: str\n :type evalvars: List[str]\n :type evalints: List[int]\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def basicCalculatorIV(self, expression: str, evalvars: List[str], evalints: List[int]) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** basicCalculatorIV(char * expression, char ** evalvars, int evalvarsSize, int* evalints, int evalintsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList BasicCalculatorIV(string expression, string[] evalvars, int[] evalints) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} expression\n * @param {string[]} evalvars\n * @param {number[]} evalints\n * @return {string[]}\n */\nvar basicCalculatorIV = function(expression, evalvars, evalints) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} expression\n# @param {String[]} evalvars\n# @param {Integer[]} evalints\n# @return {String[]}\ndef basic_calculator_iv(expression, evalvars, evalints)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func basicCalculatorIV(_ expression: String, _ evalvars: [String], _ evalints: [Int]) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func basicCalculatorIV(expression string, evalvars []string, evalints []int) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def basicCalculatorIV(expression: String, evalvars: Array[String], evalints: Array[Int]): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun basicCalculatorIV(expression: String, evalvars: Array, evalints: IntArray): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn basic_calculator_iv(expression: String, evalvars: Vec, evalints: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $expression\n * @param String[] $evalvars\n * @param Integer[] $evalints\n * @return String[]\n */\n function basicCalculatorIV($expression, $evalvars, $evalints) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function basicCalculatorIV(expression: string, evalvars: string[], evalints: number[]): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (basic-calculator-iv expression evalvars evalints)\n (-> string? (listof string?) (listof exact-integer?) (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0770](https://leetcode-cn.com/problems/basic-calculator-iv)", "[\u57fa\u672c\u8ba1\u7b97\u5668 IV](/solution/0700-0799/0770.Basic%20Calculator%20IV/README.md)", "`\u6808`,`\u54c8\u5e0c\u8868`,`\u5b57\u7b26\u4e32`", "\u56f0\u96be", ""], "md_table_row_en": ["[0770](https://leetcode.com/problems/basic-calculator-iv)", "[Basic Calculator IV](/solution/0700-0799/0770.Basic%20Calculator%20IV/README_EN.md)", "`Stack`,`Hash Table`,`String`", "Hard", ""]}, {"question_id": "0780", "frontend_question_id": "0769", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/max-chunks-to-make-sorted", "url_en": "https://leetcode.com/problems/max-chunks-to-make-sorted", "relative_path_cn": "/solution/0700-0799/0769.Max%20Chunks%20To%20Make%20Sorted/README.md", "relative_path_en": "/solution/0700-0799/0769.Max%20Chunks%20To%20Make%20Sorted/README_EN.md", "title_cn": "\u6700\u591a\u80fd\u5b8c\u6210\u6392\u5e8f\u7684\u5757", "title_en": "Max Chunks To Make Sorted", "question_title_slug": "max-chunks-to-make-sorted", "content_en": "

    Given an array arr that is a permutation of [0, 1, ..., arr.length - 1], we split the array into some number of "chunks" (partitions), and individually sort each chunk.  After concatenating them, the result equals the sorted array.

    \r\n\r\n

    What is the most number of chunks we could have made?

    \r\n\r\n

    Example 1:

    \r\n\r\n
    \r\nInput: arr = [4,3,2,1,0]\r\nOutput: 1\r\nExplanation:\r\nSplitting into two or more chunks will not return the required result.\r\nFor example, splitting into [4, 3], [2, 1, 0] will result in [3, 4, 0, 1, 2], which isn't sorted.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: arr = [1,0,2,3,4]\r\nOutput: 4\r\nExplanation:\r\nWe can split into two chunks, such as [1, 0], [2, 3, 4].\r\nHowever, splitting into [1, 0], [2], [3], [4] is the highest number of chunks possible.\r\n
    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    • arr will have length in range [1, 10].
    • \r\n\t
    • arr[i] will be a permutation of [0, 1, ..., arr.length - 1].
    • \r\n
    \r\n\r\n

     

    \r\n", "content_cn": "

    \u6570\u7ec4arr\u662f[0, 1, ..., arr.length - 1]\u7684\u4e00\u79cd\u6392\u5217\uff0c\u6211\u4eec\u5c06\u8fd9\u4e2a\u6570\u7ec4\u5206\u5272\u6210\u51e0\u4e2a“\u5757”\uff0c\u5e76\u5c06\u8fd9\u4e9b\u5757\u5206\u522b\u8fdb\u884c\u6392\u5e8f\u3002\u4e4b\u540e\u518d\u8fde\u63a5\u8d77\u6765\uff0c\u4f7f\u5f97\u8fde\u63a5\u7684\u7ed3\u679c\u548c\u6309\u5347\u5e8f\u6392\u5e8f\u540e\u7684\u539f\u6570\u7ec4\u76f8\u540c\u3002

    \n\n

    \u6211\u4eec\u6700\u591a\u80fd\u5c06\u6570\u7ec4\u5206\u6210\u591a\u5c11\u5757\uff1f

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: arr = [4,3,2,1,0]\n\u8f93\u51fa: 1\n\u89e3\u91ca:\n\u5c06\u6570\u7ec4\u5206\u62102\u5757\u6216\u8005\u66f4\u591a\u5757\uff0c\u90fd\u65e0\u6cd5\u5f97\u5230\u6240\u9700\u7684\u7ed3\u679c\u3002\n\u4f8b\u5982\uff0c\u5206\u6210 [4, 3], [2, 1, 0] \u7684\u7ed3\u679c\u662f [3, 4, 0, 1, 2]\uff0c\u8fd9\u4e0d\u662f\u6709\u5e8f\u7684\u6570\u7ec4\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: arr = [1,0,2,3,4]\n\u8f93\u51fa: 4\n\u89e3\u91ca:\n\u6211\u4eec\u53ef\u4ee5\u628a\u5b83\u5206\u6210\u4e24\u5757\uff0c\u4f8b\u5982 [1, 0], [2, 3, 4]\u3002\n\u7136\u800c\uff0c\u5206\u6210 [1, 0], [2], [3], [4] \u53ef\u4ee5\u5f97\u5230\u6700\u591a\u7684\u5757\u6570\u3002\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    • arr \u7684\u957f\u5ea6\u5728 [1, 10] \u4e4b\u95f4\u3002
    • \n\t
    • arr[i]\u662f [0, 1, ..., arr.length - 1]\u7684\u4e00\u79cd\u6392\u5217\u3002
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxChunksToSorted(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxChunksToSorted(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxChunksToSorted(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxChunksToSorted(self, arr: List[int]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxChunksToSorted(int* arr, int arrSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxChunksToSorted(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar maxChunksToSorted = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef max_chunks_to_sorted(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxChunksToSorted(_ arr: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxChunksToSorted(arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxChunksToSorted(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxChunksToSorted(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_chunks_to_sorted(arr: Vec) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function maxChunksToSorted($arr) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxChunksToSorted(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-chunks-to-sorted arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0769](https://leetcode-cn.com/problems/max-chunks-to-make-sorted)", "[\u6700\u591a\u80fd\u5b8c\u6210\u6392\u5e8f\u7684\u5757](/solution/0700-0799/0769.Max%20Chunks%20To%20Make%20Sorted/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0769](https://leetcode.com/problems/max-chunks-to-make-sorted)", "[Max Chunks To Make Sorted](/solution/0700-0799/0769.Max%20Chunks%20To%20Make%20Sorted/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0779", "frontend_question_id": "0768", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/max-chunks-to-make-sorted-ii", "url_en": "https://leetcode.com/problems/max-chunks-to-make-sorted-ii", "relative_path_cn": "/solution/0700-0799/0768.Max%20Chunks%20To%20Make%20Sorted%20II/README.md", "relative_path_en": "/solution/0700-0799/0768.Max%20Chunks%20To%20Make%20Sorted%20II/README_EN.md", "title_cn": "\u6700\u591a\u80fd\u5b8c\u6210\u6392\u5e8f\u7684\u5757 II", "title_en": "Max Chunks To Make Sorted II", "question_title_slug": "max-chunks-to-make-sorted-ii", "content_en": "

    This question is the same as "Max Chunks to Make Sorted" except the integers of the given array are not necessarily distinct, the input array could be up to length 2000, and the elements could be up to 10**8.

    \r\n\r\n
    \r\n\r\n

    Given an array arr of integers (not necessarily distinct), we split the array into some number of "chunks" (partitions), and individually sort each chunk.  After concatenating them, the result equals the sorted array.

    \r\n\r\n

    What is the most number of chunks we could have made?

    \r\n\r\n

    Example 1:

    \r\n\r\n
    \r\nInput: arr = [5,4,3,2,1]\r\nOutput: 1\r\nExplanation:\r\nSplitting into two or more chunks will not return the required result.\r\nFor example, splitting into [5, 4], [3, 2, 1] will result in [4, 5, 1, 2, 3], which isn't sorted.\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: arr = [2,1,3,4,4]\r\nOutput: 4\r\nExplanation:\r\nWe can split into two chunks, such as [2, 1], [3, 4, 4].\r\nHowever, splitting into [2, 1], [3], [4], [4] is the highest number of chunks possible.\r\n
    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    • arr will have length in range [1, 2000].
    • \r\n\t
    • arr[i] will be an integer in range [0, 10**8].
    • \r\n
    \r\n\r\n

     

    \r\n", "content_cn": "

    \u8fd9\u4e2a\u95ee\u9898\u548c“\u6700\u591a\u80fd\u5b8c\u6210\u6392\u5e8f\u7684\u5757”\u76f8\u4f3c\uff0c\u4f46\u7ed9\u5b9a\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u53ef\u4ee5\u91cd\u590d\uff0c\u8f93\u5165\u6570\u7ec4\u6700\u5927\u957f\u5ea6\u4e3a2000\uff0c\u5176\u4e2d\u7684\u5143\u7d20\u6700\u5927\u4e3a10**8\u3002

    \n\n

    arr\u662f\u4e00\u4e2a\u53ef\u80fd\u5305\u542b\u91cd\u590d\u5143\u7d20\u7684\u6574\u6570\u6570\u7ec4\uff0c\u6211\u4eec\u5c06\u8fd9\u4e2a\u6570\u7ec4\u5206\u5272\u6210\u51e0\u4e2a“\u5757”\uff0c\u5e76\u5c06\u8fd9\u4e9b\u5757\u5206\u522b\u8fdb\u884c\u6392\u5e8f\u3002\u4e4b\u540e\u518d\u8fde\u63a5\u8d77\u6765\uff0c\u4f7f\u5f97\u8fde\u63a5\u7684\u7ed3\u679c\u548c\u6309\u5347\u5e8f\u6392\u5e8f\u540e\u7684\u539f\u6570\u7ec4\u76f8\u540c\u3002

    \n\n

    \u6211\u4eec\u6700\u591a\u80fd\u5c06\u6570\u7ec4\u5206\u6210\u591a\u5c11\u5757\uff1f

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: arr = [5,4,3,2,1]\n\u8f93\u51fa: 1\n\u89e3\u91ca:\n\u5c06\u6570\u7ec4\u5206\u62102\u5757\u6216\u8005\u66f4\u591a\u5757\uff0c\u90fd\u65e0\u6cd5\u5f97\u5230\u6240\u9700\u7684\u7ed3\u679c\u3002\n\u4f8b\u5982\uff0c\u5206\u6210 [5, 4], [3, 2, 1] \u7684\u7ed3\u679c\u662f [4, 5, 1, 2, 3]\uff0c\u8fd9\u4e0d\u662f\u6709\u5e8f\u7684\u6570\u7ec4\u3002 \n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: arr = [2,1,3,4,4]\n\u8f93\u51fa: 4\n\u89e3\u91ca:\n\u6211\u4eec\u53ef\u4ee5\u628a\u5b83\u5206\u6210\u4e24\u5757\uff0c\u4f8b\u5982 [2, 1], [3, 4, 4]\u3002\n\u7136\u800c\uff0c\u5206\u6210 [2, 1], [3], [4], [4] \u53ef\u4ee5\u5f97\u5230\u6700\u591a\u7684\u5757\u6570\u3002 \n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    • arr\u7684\u957f\u5ea6\u5728[1, 2000]\u4e4b\u95f4\u3002
    • \n\t
    • arr[i]\u7684\u5927\u5c0f\u5728[0, 10**8]\u4e4b\u95f4\u3002
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxChunksToSorted(vector& arr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxChunksToSorted(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxChunksToSorted(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxChunksToSorted(self, arr: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxChunksToSorted(int* arr, int arrSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxChunksToSorted(int[] arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @return {number}\n */\nvar maxChunksToSorted = function(arr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @return {Integer}\ndef max_chunks_to_sorted(arr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxChunksToSorted(_ arr: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxChunksToSorted(arr []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxChunksToSorted(arr: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxChunksToSorted(arr: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_chunks_to_sorted(arr: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @return Integer\n */\n function maxChunksToSorted($arr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxChunksToSorted(arr: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-chunks-to-sorted arr)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0768](https://leetcode-cn.com/problems/max-chunks-to-make-sorted-ii)", "[\u6700\u591a\u80fd\u5b8c\u6210\u6392\u5e8f\u7684\u5757 II](/solution/0700-0799/0768.Max%20Chunks%20To%20Make%20Sorted%20II/README.md)", "`\u6570\u7ec4`", "\u56f0\u96be", ""], "md_table_row_en": ["[0768](https://leetcode.com/problems/max-chunks-to-make-sorted-ii)", "[Max Chunks To Make Sorted II](/solution/0700-0799/0768.Max%20Chunks%20To%20Make%20Sorted%20II/README_EN.md)", "`Array`", "Hard", ""]}, {"question_id": "0778", "frontend_question_id": "0767", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reorganize-string", "url_en": "https://leetcode.com/problems/reorganize-string", "relative_path_cn": "/solution/0700-0799/0767.Reorganize%20String/README.md", "relative_path_en": "/solution/0700-0799/0767.Reorganize%20String/README_EN.md", "title_cn": "\u91cd\u6784\u5b57\u7b26\u4e32", "title_en": "Reorganize String", "question_title_slug": "reorganize-string", "content_en": "

    Given a string s, check if the letters can be rearranged so that two characters that are adjacent to each other are not the same.

    \n\n

    If possible, output any possible result.  If not possible, return the empty string.

    \n\n

    Example 1:

    \n\n
    \nInput: s = "aab"\nOutput: "aba"\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "aaab"\nOutput: ""\n
    \n\n

    Note:

    \n\n
      \n\t
    • s will consist of lowercase letters and have length in range [1, 500].
    • \n
    \n\n

     

    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32S\uff0c\u68c0\u67e5\u662f\u5426\u80fd\u91cd\u65b0\u6392\u5e03\u5176\u4e2d\u7684\u5b57\u6bcd\uff0c\u4f7f\u5f97\u4e24\u76f8\u90bb\u7684\u5b57\u7b26\u4e0d\u540c\u3002

    \n\n

    \u82e5\u53ef\u884c\uff0c\u8f93\u51fa\u4efb\u610f\u53ef\u884c\u7684\u7ed3\u679c\u3002\u82e5\u4e0d\u53ef\u884c\uff0c\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: S = "aab"\n\u8f93\u51fa: "aba"\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: S = "aaab"\n\u8f93\u51fa: ""\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    • S \u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd\u5e76\u4e14\u957f\u5ea6\u5728[1, 500]\u533a\u95f4\u5185\u3002
    • \n
    \n", "tags_en": ["Heap", "Greedy", "Sort", "String"], "tags_cn": ["\u5806", "\u8d2a\u5fc3\u7b97\u6cd5", "\u6392\u5e8f", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string reorganizeString(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String reorganizeString(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def reorganizeString(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def reorganizeString(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * reorganizeString(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ReorganizeString(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar reorganizeString = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef reorganize_string(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func reorganizeString(_ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func reorganizeString(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def reorganizeString(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun reorganizeString(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn reorganize_string(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function reorganizeString($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function reorganizeString(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (reorganize-string s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0767](https://leetcode-cn.com/problems/reorganize-string)", "[\u91cd\u6784\u5b57\u7b26\u4e32](/solution/0700-0799/0767.Reorganize%20String/README.md)", "`\u5806`,`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6392\u5e8f`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0767](https://leetcode.com/problems/reorganize-string)", "[Reorganize String](/solution/0700-0799/0767.Reorganize%20String/README_EN.md)", "`Heap`,`Greedy`,`Sort`,`String`", "Medium", ""]}, {"question_id": "0777", "frontend_question_id": "0766", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/toeplitz-matrix", "url_en": "https://leetcode.com/problems/toeplitz-matrix", "relative_path_cn": "/solution/0700-0799/0766.Toeplitz%20Matrix/README.md", "relative_path_en": "/solution/0700-0799/0766.Toeplitz%20Matrix/README_EN.md", "title_cn": "\u6258\u666e\u5229\u8328\u77e9\u9635", "title_en": "Toeplitz Matrix", "question_title_slug": "toeplitz-matrix", "content_en": "

    Given an m x n matrix, return true if the matrix is Toeplitz. Otherwise, return false.

    \n\n

    A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same elements.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: matrix = [[1,2,3,4],[5,1,2,3],[9,5,1,2]]\nOutput: true\nExplanation:\nIn the above grid, the diagonals are:\n"[9]", "[5, 5]", "[1, 1, 1]", "[2, 2, 2]", "[3, 3]", "[4]".\nIn each diagonal all elements are the same, so the answer is True.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: matrix = [[1,2],[2,2]]\nOutput: false\nExplanation:\nThe diagonal "[1, 2]" has different elements.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == matrix.length
    • \n\t
    • n == matrix[i].length
    • \n\t
    • 1 <= m, n <= 20
    • \n\t
    • 0 <= matrix[i][j] <= 99
    • \n
    \n\n

     

    \n

    Follow up:

    \n\n
      \n\t
    • What if the matrix is stored on disk, and the memory is limited such that you can only load at most one row of the matrix into the memory at once?
    • \n\t
    • What if the matrix is so large that you can only load up a partial row into the memory at once?
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a m x n \u7684\u77e9\u9635 matrix \u3002\u5982\u679c\u8fd9\u4e2a\u77e9\u9635\u662f\u6258\u666e\u5229\u8328\u77e9\u9635\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n

    \u5982\u679c\u77e9\u9635\u4e0a\u6bcf\u4e00\u6761\u7531\u5de6\u4e0a\u5230\u53f3\u4e0b\u7684\u5bf9\u89d2\u7ebf\u4e0a\u7684\u5143\u7d20\u90fd\u76f8\u540c\uff0c\u90a3\u4e48\u8fd9\u4e2a\u77e9\u9635\u662f \u6258\u666e\u5229\u8328\u77e9\u9635 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1amatrix = [[1,2,3,4],[5,1,2,3],[9,5,1,2]]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\n\u5728\u4e0a\u8ff0\u77e9\u9635\u4e2d, \u5176\u5bf9\u89d2\u7ebf\u4e3a: \n\"[9]\", \"[5, 5]\", \"[1, 1, 1]\", \"[2, 2, 2]\", \"[3, 3]\", \"[4]\"\u3002 \n\u5404\u6761\u5bf9\u89d2\u7ebf\u4e0a\u7684\u6240\u6709\u5143\u7d20\u5747\u76f8\u540c, \u56e0\u6b64\u7b54\u6848\u662f True \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1amatrix = [[1,2],[2,2]]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\n\u5bf9\u89d2\u7ebf \"[1, 2]\" \u4e0a\u7684\u5143\u7d20\u4e0d\u540c\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == matrix.length
    • \n\t
    • n == matrix[i].length
    • \n\t
    • 1 <= m, n <= 20
    • \n\t
    • 0 <= matrix[i][j] <= 99
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u5982\u679c\u77e9\u9635\u5b58\u50a8\u5728\u78c1\u76d8\u4e0a\uff0c\u5e76\u4e14\u5185\u5b58\u6709\u9650\uff0c\u4ee5\u81f3\u4e8e\u4e00\u6b21\u6700\u591a\u53ea\u80fd\u5c06\u77e9\u9635\u7684\u4e00\u884c\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\uff0c\u8be5\u600e\u4e48\u529e\uff1f
    • \n\t
    • \u5982\u679c\u77e9\u9635\u592a\u5927\uff0c\u4ee5\u81f3\u4e8e\u4e00\u6b21\u53ea\u80fd\u5c06\u4e0d\u5b8c\u6574\u7684\u4e00\u884c\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\uff0c\u8be5\u600e\u4e48\u529e\uff1f
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isToeplitzMatrix(vector>& matrix) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isToeplitzMatrix(int[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isToeplitzMatrix(self, matrix):\n \"\"\"\n :type matrix: List[List[int]]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isToeplitzMatrix(self, matrix: List[List[int]]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isToeplitzMatrix(int** matrix, int matrixSize, int* matrixColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsToeplitzMatrix(int[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} matrix\n * @return {boolean}\n */\nvar isToeplitzMatrix = function(matrix) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} matrix\n# @return {Boolean}\ndef is_toeplitz_matrix(matrix)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isToeplitzMatrix(_ matrix: [[Int]]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isToeplitzMatrix(matrix [][]int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isToeplitzMatrix(matrix: Array[Array[Int]]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isToeplitzMatrix(matrix: Array): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_toeplitz_matrix(matrix: Vec>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $matrix\n * @return Boolean\n */\n function isToeplitzMatrix($matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isToeplitzMatrix(matrix: number[][]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-toeplitz-matrix matrix)\n (-> (listof (listof exact-integer?)) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0766](https://leetcode-cn.com/problems/toeplitz-matrix)", "[\u6258\u666e\u5229\u8328\u77e9\u9635](/solution/0700-0799/0766.Toeplitz%20Matrix/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0766](https://leetcode.com/problems/toeplitz-matrix)", "[Toeplitz Matrix](/solution/0700-0799/0766.Toeplitz%20Matrix/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0776", "frontend_question_id": "0590", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/n-ary-tree-postorder-traversal", "url_en": "https://leetcode.com/problems/n-ary-tree-postorder-traversal", "relative_path_cn": "/solution/0500-0599/0590.N-ary%20Tree%20Postorder%20Traversal/README.md", "relative_path_en": "/solution/0500-0599/0590.N-ary%20Tree%20Postorder%20Traversal/README_EN.md", "title_cn": "N \u53c9\u6811\u7684\u540e\u5e8f\u904d\u5386", "title_en": "N-ary Tree Postorder Traversal", "question_title_slug": "n-ary-tree-postorder-traversal", "content_en": "

    Given the root of an n-ary tree, return the postorder traversal of its nodes' values.

    \n\n

    Nary-Tree input serialization is represented in their level order traversal. Each group of children is separated by the null value (See examples)

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: root = [1,null,3,2,4,null,5,6]\nOutput: [5,6,3,2,4,1]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]\nOutput: [2,6,14,11,7,3,12,8,4,13,9,10,5,1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [0, 104].
    • \n\t
    • 0 <= Node.val <= 104
    • \n\t
    • The height of the n-ary tree is less than or equal to 1000.
    • \n
    \n\n

     

    \n

    Follow up: Recursive solution is trivial, could you do it iteratively?

    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a N \u53c9\u6811\uff0c\u8fd4\u56de\u5176\u8282\u70b9\u503c\u7684 \u540e\u5e8f\u904d\u5386 \u3002

    \n\n

    N \u53c9\u6811 \u5728\u8f93\u5165\u4e2d\u6309\u5c42\u5e8f\u904d\u5386\u8fdb\u884c\u5e8f\u5217\u5316\u8868\u793a\uff0c\u6bcf\u7ec4\u5b50\u8282\u70b9\u7531\u7a7a\u503c null \u5206\u9694\uff08\u8bf7\u53c2\u89c1\u793a\u4f8b\uff09\u3002

    \n\n
    \n
    \n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a

    \n\n

    \u9012\u5f52\u6cd5\u5f88\u7b80\u5355\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u8fed\u4ee3\u6cd5\u5b8c\u6210\u6b64\u9898\u5417?

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \n\n
    \n\u8f93\u5165\uff1aroot = [1,null,3,2,4,null,5,6]\n\u8f93\u51fa\uff1a[5,6,3,2,4,1]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aroot = [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]\n\u8f93\u51fa\uff1a[2,6,14,11,7,3,12,8,4,13,9,10,5,1]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • N \u53c9\u6811\u7684\u9ad8\u5ea6\u5c0f\u4e8e\u6216\u7b49\u4e8e 1000
    • \n\t
    • \u8282\u70b9\u603b\u6570\u5728\u8303\u56f4 [0,\u00a010^4] \u5185
    • \n
    \n
    \n
    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n vector children;\n\n Node() {}\n\n Node(int _val) {\n val = _val;\n }\n\n Node(int _val, vector _children) {\n val = _val;\n children = _children;\n }\n};\n*/\n\nclass Solution {\npublic:\n vector postorder(Node* root) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/*\n// Definition for a Node.\nclass Node {\n public int val;\n public List children;\n\n public Node() {}\n\n public Node(int _val) {\n val = _val;\n }\n\n public Node(int _val, List _children) {\n val = _val;\n children = _children;\n }\n};\n*/\n\nclass Solution {\n public List postorder(Node root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "\"\"\"\n# Definition for a Node.\nclass Node(object):\n def __init__(self, val=None, children=None):\n self.val = val\n self.children = children\n\"\"\"\n\nclass Solution(object):\n def postorder(self, root):\n \"\"\"\n :type root: Node\n :rtype: List[int]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "\"\"\"\n# Definition for a Node.\nclass Node:\n def __init__(self, val=None, children=None):\n self.val = val\n self.children = children\n\"\"\"\n\nclass Solution:\n def postorder(self, root: 'Node') -> List[int]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a Node.\n * struct Node {\n * int val;\n * int numChildren;\n * struct Node** children;\n * };\n */\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* postorder(struct Node* root, int* returnSize) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/*\n// Definition for a Node.\npublic class Node {\n public int val;\n public IList children;\n\n public Node() {}\n\n public Node(int _val) {\n val = _val;\n }\n\n public Node(int _val, IList _children) {\n val = _val;\n children = _children;\n }\n}\n*/\n\npublic class Solution {\n public IList Postorder(Node root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // Definition for a Node.\n * function Node(val,children) {\n * this.val = val;\n * this.children = children;\n * };\n */\n\n/**\n * @param {Node} root\n * @return {number[]}\n */\nvar postorder = function(root) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a Node.\n# class Node\n# attr_accessor :val, :children\n# def initialize(val)\n# @val = val\n# @children = []\n# end\n# end\n\n# @param {Node} root\n# @return {List[int]}\ndef postorder(root)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a Node.\n * public class Node {\n * public var val: Int\n * public var children: [Node]\n * public init(_ val: Int) {\n * self.val = val\n * self.children = []\n * }\n * }\n */\n\nclass Solution {\n func postorder(_ root: Node?) -> [Int] {\n \t\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a Node.\n * type Node struct {\n * Val int\n * Children []*Node\n * }\n */\n\nfunc postorder(root *Node) []int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a Node.\n * class Node(var _value: Int) {\n * var value: Int = _value\n * var children: List[Node] = List()\n * }\n */\n\nobject Solution {\n def postorder(root: Node): List[Int] = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a Node.\n * class Node(var `val`: Int) {\n * var children: List = listOf()\n * }\n */\n\nclass Solution {\n fun postorder(root: Node?): List {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a Node.\n * class Node {\n * public $val = null;\n * public $children = null;\n * function __construct($val = 0) {\n * $this->val = $val;\n * $this->children = array();\n * }\n * }\n */\n\nclass Solution {\n /**\n * @param Node $root\n * @return integer[]\n */\n function postorder($root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for node.\n * class Node {\n * val: number\n * children: Node[]\n * constructor(val?: number) {\n * this.val = (val===undefined ? 0 : val)\n * this.children = []\n * }\n * }\n */\n\nfunction postorder(root: Node | null): number[] {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0590](https://leetcode-cn.com/problems/n-ary-tree-postorder-traversal)", "[N \u53c9\u6811\u7684\u540e\u5e8f\u904d\u5386](/solution/0500-0599/0590.N-ary%20Tree%20Postorder%20Traversal/README.md)", "`\u6811`", "\u7b80\u5355", ""], "md_table_row_en": ["[0590](https://leetcode.com/problems/n-ary-tree-postorder-traversal)", "[N-ary Tree Postorder Traversal](/solution/0500-0599/0590.N-ary%20Tree%20Postorder%20Traversal/README_EN.md)", "`Tree`", "Easy", ""]}, {"question_id": "0775", "frontend_question_id": "0589", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/n-ary-tree-preorder-traversal", "url_en": "https://leetcode.com/problems/n-ary-tree-preorder-traversal", "relative_path_cn": "/solution/0500-0599/0589.N-ary%20Tree%20Preorder%20Traversal/README.md", "relative_path_en": "/solution/0500-0599/0589.N-ary%20Tree%20Preorder%20Traversal/README_EN.md", "title_cn": "N \u53c9\u6811\u7684\u524d\u5e8f\u904d\u5386", "title_en": "N-ary Tree Preorder Traversal", "question_title_slug": "n-ary-tree-preorder-traversal", "content_en": "

    Given the root of an n-ary tree, return the preorder traversal of its nodes' values.

    \n\n

    Nary-Tree input serialization is represented in their level order traversal. Each group of children is separated by the null value (See examples)

    \n\n

     

    \n

    Example 1:

    \n\n

    \n\n
    \nInput: root = [1,null,3,2,4,null,5,6]\nOutput: [1,3,5,6,2,4]\n
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: root = [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]\nOutput: [1,2,3,6,7,11,14,4,8,12,5,9,13,10]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [0, 104].
    • \n\t
    • 0 <= Node.val <= 104
    • \n\t
    • The height of the n-ary tree is less than or equal to 1000.
    • \n
    \n\n

     

    \n

    Follow up: Recursive solution is trivial, could you do it iteratively?

    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a N \u53c9\u6811\uff0c\u8fd4\u56de\u5176\u8282\u70b9\u503c\u7684 \u524d\u5e8f\u904d\u5386 \u3002

    \n\n

    N \u53c9\u6811 \u5728\u8f93\u5165\u4e2d\u6309\u5c42\u5e8f\u904d\u5386\u8fdb\u884c\u5e8f\u5217\u5316\u8868\u793a\uff0c\u6bcf\u7ec4\u5b50\u8282\u70b9\u7531\u7a7a\u503c null \u5206\u9694\uff08\u8bf7\u53c2\u89c1\u793a\u4f8b\uff09\u3002

    \n\n
    \n
    \n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a

    \n\n

    \u9012\u5f52\u6cd5\u5f88\u7b80\u5355\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u8fed\u4ee3\u6cd5\u5b8c\u6210\u6b64\u9898\u5417?

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \n\n
    \n\u8f93\u5165\uff1aroot = [1,null,3,2,4,null,5,6]\n\u8f93\u51fa\uff1a[1,3,5,6,2,4]\n
    \n\u793a\u4f8b 2\uff1a\n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aroot = [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]\n\u8f93\u51fa\uff1a[1,2,3,6,7,11,14,4,8,12,5,9,13,10]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • N \u53c9\u6811\u7684\u9ad8\u5ea6\u5c0f\u4e8e\u6216\u7b49\u4e8e 1000
    • \n\t
    • \u8282\u70b9\u603b\u6570\u5728\u8303\u56f4 [0,\u00a010^4] \u5185
    • \n
    \n
    \n
    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n vector children;\n\n Node() {}\n\n Node(int _val) {\n val = _val;\n }\n\n Node(int _val, vector _children) {\n val = _val;\n children = _children;\n }\n};\n*/\n\nclass Solution {\npublic:\n vector preorder(Node* root) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/*\n// Definition for a Node.\nclass Node {\n public int val;\n public List children;\n\n public Node() {}\n\n public Node(int _val) {\n val = _val;\n }\n\n public Node(int _val, List _children) {\n val = _val;\n children = _children;\n }\n};\n*/\n\nclass Solution {\n public List preorder(Node root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "\"\"\"\n# Definition for a Node.\nclass Node(object):\n def __init__(self, val=None, children=None):\n self.val = val\n self.children = children\n\"\"\"\n\nclass Solution(object):\n def preorder(self, root):\n \"\"\"\n :type root: Node\n :rtype: List[int]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "\"\"\"\n# Definition for a Node.\nclass Node:\n def __init__(self, val=None, children=None):\n self.val = val\n self.children = children\n\"\"\"\n\nclass Solution:\n def preorder(self, root: 'Node') -> List[int]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a Node.\n * struct Node {\n * int val;\n * int numChildren;\n * struct Node** children;\n * };\n */\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* preorder(struct Node* root, int* returnSize) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/*\n// Definition for a Node.\npublic class Node {\n public int val;\n public IList children;\n\n public Node() {}\n\n public Node(int _val) {\n val = _val;\n }\n\n public Node(int _val,IList _children) {\n val = _val;\n children = _children;\n }\n}\n*/\n\npublic class Solution {\n public IList Preorder(Node root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // Definition for a Node.\n * function Node(val, children) {\n * this.val = val;\n * this.children = children;\n * };\n */\n\n/**\n * @param {Node} root\n * @return {number[]}\n */\nvar preorder = function(root) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a Node.\n# class Node\n# attr_accessor :val, :children\n# def initialize(val)\n# @val = val\n# @children = []\n# end\n# end\n\n# @param {Node} root\n# @return {List[int]}\ndef preorder(root)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a Node.\n * public class Node {\n * public var val: Int\n * public var children: [Node]\n * public init(_ val: Int) {\n * self.val = val\n * self.children = []\n * }\n * }\n */\n\nclass Solution {\n func preorder(_ root: Node?) -> [Int] {\n \t\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a Node.\n * type Node struct {\n * Val int\n * Children []*Node\n * }\n */\n\nfunc preorder(root *Node) []int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a Node.\n * class Node(var _value: Int) {\n * var value: Int = _value\n * var children: List[Node] = List()\n * }\n */\n\nobject Solution {\n def preorder(root: Node): List[Int] = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a Node.\n * class Node(var `val`: Int) {\n * var children: List = listOf()\n * }\n */\n\nclass Solution {\n fun preorder(root: Node?): List {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a Node.\n * class Node {\n * public $val = null;\n * public $children = null;\n * function __construct($val = 0) {\n * $this->val = $val;\n * $this->children = array();\n * }\n * }\n */\n\nclass Solution {\n /**\n * @param Node $root\n * @return integer[]\n */\n function preorder($root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for node.\n * class Node {\n * val: number\n * children: Node[]\n * constructor(val?: number) {\n * this.val = (val===undefined ? 0 : val)\n * this.children = []\n * }\n * }\n */\n\nfunction preorder(root: Node | null): number[] {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0589](https://leetcode-cn.com/problems/n-ary-tree-preorder-traversal)", "[N \u53c9\u6811\u7684\u524d\u5e8f\u904d\u5386](/solution/0500-0599/0589.N-ary%20Tree%20Preorder%20Traversal/README.md)", "`\u6811`", "\u7b80\u5355", ""], "md_table_row_en": ["[0589](https://leetcode.com/problems/n-ary-tree-preorder-traversal)", "[N-ary Tree Preorder Traversal](/solution/0500-0599/0589.N-ary%20Tree%20Preorder%20Traversal/README_EN.md)", "`Tree`", "Easy", ""]}, {"question_id": "0774", "frontend_question_id": "0559", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-depth-of-n-ary-tree", "url_en": "https://leetcode.com/problems/maximum-depth-of-n-ary-tree", "relative_path_cn": "/solution/0500-0599/0559.Maximum%20Depth%20of%20N-ary%20Tree/README.md", "relative_path_en": "/solution/0500-0599/0559.Maximum%20Depth%20of%20N-ary%20Tree/README_EN.md", "title_cn": "N \u53c9\u6811\u7684\u6700\u5927\u6df1\u5ea6", "title_en": "Maximum Depth of N-ary Tree", "question_title_slug": "maximum-depth-of-n-ary-tree", "content_en": "

    Given a n-ary tree, find its maximum depth.

    \n\n

    The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.

    \n\n

    Nary-Tree input serialization is represented in their level order traversal, each group of children is separated by the null value (See examples).

    \n\n

     

    \n

    Example 1:

    \n\n

    \n\n
    \nInput: root = [1,null,3,2,4,null,5,6]\nOutput: 3\n
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: root = [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]\nOutput: 5\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The depth of the n-ary tree is less than or equal to 1000.
    • \n\t
    • The total number of nodes is between [0, 104].
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a N \u53c9\u6811\uff0c\u627e\u5230\u5176\u6700\u5927\u6df1\u5ea6\u3002

    \n\n

    \u6700\u5927\u6df1\u5ea6\u662f\u6307\u4ece\u6839\u8282\u70b9\u5230\u6700\u8fdc\u53f6\u5b50\u8282\u70b9\u7684\u6700\u957f\u8def\u5f84\u4e0a\u7684\u8282\u70b9\u603b\u6570\u3002

    \n\n

    N \u53c9\u6811\u8f93\u5165\u6309\u5c42\u5e8f\u904d\u5386\u5e8f\u5217\u5316\u8868\u793a\uff0c\u6bcf\u7ec4\u5b50\u8282\u70b9\u7531\u7a7a\u503c\u5206\u9694\uff08\u8bf7\u53c2\u89c1\u793a\u4f8b\uff09\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \n\n
    \n\u8f93\u5165\uff1aroot = [1,null,3,2,4,null,5,6]\n\u8f93\u51fa\uff1a3\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aroot = [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]\n\u8f93\u51fa\uff1a5\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u7684\u6df1\u5ea6\u4e0d\u4f1a\u8d85\u8fc7\u00a01000 \u3002
    • \n\t
    • \u6811\u7684\u8282\u70b9\u6570\u76ee\u4f4d\u4e8e [0,\u00a0104] \u4e4b\u95f4\u3002
    • \n
    \n", "tags_en": ["Tree", "Depth-first Search", "Breadth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n vector children;\n\n Node() {}\n\n Node(int _val) {\n val = _val;\n }\n\n Node(int _val, vector _children) {\n val = _val;\n children = _children;\n }\n};\n*/\n\nclass Solution {\npublic:\n int maxDepth(Node* root) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/*\n// Definition for a Node.\nclass Node {\n public int val;\n public List children;\n\n public Node() {}\n\n public Node(int _val) {\n val = _val;\n }\n\n public Node(int _val, List _children) {\n val = _val;\n children = _children;\n }\n};\n*/\n\nclass Solution {\n public int maxDepth(Node root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "\"\"\"\n# Definition for a Node.\nclass Node(object):\n def __init__(self, val=None, children=None):\n self.val = val\n self.children = children\n\"\"\"\n\nclass Solution(object):\n def maxDepth(self, root):\n \"\"\"\n :type root: Node\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "\"\"\"\n# Definition for a Node.\nclass Node:\n def __init__(self, val=None, children=None):\n self.val = val\n self.children = children\n\"\"\"\n\nclass Solution:\n def maxDepth(self, root: 'Node') -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a Node.\n * struct Node {\n * int val;\n * int numChildren;\n * struct Node** children;\n * };\n */\n\nint maxDepth(struct Node* root) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/*\n// Definition for a Node.\npublic class Node {\n public int val;\n public IList children;\n\n public Node() {}\n\n public Node(int _val) {\n val = _val;\n }\n\n public Node(int _val, IList _children) {\n val = _val;\n children = _children;\n }\n}\n*/\n\npublic class Solution {\n public int MaxDepth(Node root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // Definition for a Node.\n * function Node(val,children) {\n * this.val = val;\n * this.children = children;\n * };\n */\n\n/**\n * @param {Node|null} root\n * @return {number}\n */\nvar maxDepth = function(root) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a Node.\n# class Node\n# attr_accessor :val, :children\n# def initialize(val)\n# @val = val\n# @children = []\n# end\n# end\n\n# @param {Node} root\n# @return {int}\ndef maxDepth(root)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a Node.\n * public class Node {\n * public var val: Int\n * public var children: [Node]\n * public init(_ val: Int) {\n * self.val = val\n * self.children = []\n * }\n * }\n */\n\nclass Solution {\n func maxDepth(_ root: Node?) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a Node.\n * type Node struct {\n * Val int\n * Children []*Node\n * }\n */\n\nfunc maxDepth(root *Node) int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a Node.\n * class Node(var _value: Int) {\n * var value: Int = _value\n * var children: List[Node] = List()\n * }\n */\n\nobject Solution {\n def maxDepth(root: Node): Int = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a Node.\n * class Node(var `val`: Int) {\n * var children: List = listOf()\n * }\n */\n\nclass Solution {\n fun maxDepth(root: Node?): Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a Node.\n * class Node {\n * public $val = null;\n * public $children = null;\n * function __construct($val = 0) {\n * $this->val = $val;\n * $this->children = array();\n * }\n * }\n */\n\nclass Solution {\n /**\n * @param Node $root\n * @return integer\n */\n function maxDepth($root) {\n \t\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for Node.\n * class Node {\n * val: number\n * children: Node[]\n * constructor(val?: number, children?: Node[]) {\n * this.val = (val===undefined ? 0 : val)\n * this.children = (children===undefined ? [] : children)\n * }\n * }\n */\n\nfunction maxDepth(root: Node): number {\n \n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0559](https://leetcode-cn.com/problems/maximum-depth-of-n-ary-tree)", "[N \u53c9\u6811\u7684\u6700\u5927\u6df1\u5ea6](/solution/0500-0599/0559.Maximum%20Depth%20of%20N-ary%20Tree/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u7b80\u5355", ""], "md_table_row_en": ["[0559](https://leetcode.com/problems/maximum-depth-of-n-ary-tree)", "[Maximum Depth of N-ary Tree](/solution/0500-0599/0559.Maximum%20Depth%20of%20N-ary%20Tree/README_EN.md)", "`Tree`,`Depth-first Search`,`Breadth-first Search`", "Easy", ""]}, {"question_id": "0773", "frontend_question_id": "0558", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/logical-or-of-two-binary-grids-represented-as-quad-trees", "url_en": "https://leetcode.com/problems/logical-or-of-two-binary-grids-represented-as-quad-trees", "relative_path_cn": "/solution/0500-0599/0558.Logical%20OR%20of%20Two%20Binary%20Grids%20Represented%20as%20Quad-Trees/README.md", "relative_path_en": "/solution/0500-0599/0558.Logical%20OR%20of%20Two%20Binary%20Grids%20Represented%20as%20Quad-Trees/README_EN.md", "title_cn": "\u56db\u53c9\u6811\u4ea4\u96c6", "title_en": "Logical OR of Two Binary Grids Represented as Quad-Trees", "question_title_slug": "logical-or-of-two-binary-grids-represented-as-quad-trees", "content_en": "

    A Binary Matrix is a matrix in which all the elements are either 0 or 1.

    \r\n\r\n

    Given quadTree1 and quadTree2. quadTree1 represents a n * n binary matrix and quadTree2 represents another n * n binary matrix. 

    \r\n\r\n

    Return a Quad-Tree representing the n * n binary matrix which is the result of logical bitwise OR of the two binary matrixes represented by quadTree1 and quadTree2.

    \r\n\r\n

    Notice that you can assign the value of a node to True or False when isLeaf is False, and both are accepted in the answer.

    \r\n\r\n

    A Quad-Tree is a tree data structure in which each internal node has exactly four children. Besides, each node has two attributes:

    \r\n\r\n
      \r\n\t
    • val: True if the node represents a grid of 1's or False if the node represents a grid of 0's. 
    • \r\n\t
    • isLeaf: True if the node is leaf node on the tree or False if the node has the four children.
    • \r\n
    \r\n\r\n
    \r\nclass Node {\r\n    public boolean val;\r\n    public boolean isLeaf;\r\n    public Node topLeft;\r\n    public Node topRight;\r\n    public Node bottomLeft;\r\n    public Node bottomRight;\r\n}
    \r\n\r\n

    We can construct a Quad-Tree from a two-dimensional area using the following steps:

    \r\n\r\n
      \r\n\t
    1. If the current grid has the same value (i.e all 1's or all 0's) set isLeaf True and set val to the value of the grid and set the four children to Null and stop.
    2. \r\n\t
    3. If the current grid has different values, set isLeaf to False and set val to any value and divide the current grid into four sub-grids as shown in the photo.
    4. \r\n\t
    5. Recurse for each of the children with the proper sub-grid.
    6. \r\n
    \r\n\"\"\r\n

    If you want to know more about the Quad-Tree, you can refer to the wiki.

    \r\n\r\n

    Quad-Tree format:

    \r\n\r\n

    The input/output represents the serialized format of a Quad-Tree using level order traversal, where null signifies a path terminator where no node exists below.

    \r\n\r\n

    It is very similar to the serialization of the binary tree. The only difference is that the node is represented as a list [isLeaf, val].

    \r\n\r\n

    If the value of isLeaf or val is True we represent it as 1 in the list [isLeaf, val] and if the value of isLeaf or val is False we represent it as 0.

    \r\n\n

     

    \n

    Example 1:

    \n\"\" \"\"\n
    \nInput: quadTree1 = [[0,1],[1,1],[1,1],[1,0],[1,0]]\n, quadTree2 = [[0,1],[1,1],[0,1],[1,1],[1,0],null,null,null,null,[1,0],[1,0],[1,1],[1,1]]\nOutput: [[0,0],[1,1],[1,1],[1,1],[1,0]]\nExplanation: quadTree1 and quadTree2 are shown above. You can see the binary matrix which is represented by each Quad-Tree.\nIf we apply logical bitwise OR on the two binary matrices we get the binary matrix below which is represented by the result Quad-Tree.\nNotice that the binary matrices shown are only for illustration, you don't have to construct the binary matrix to get the result tree.\n\"\"\n
    \n\n

    Example 2:

    \n\n
    \nInput: quadTree1 = [[1,0]]\n, quadTree2 = [[1,0]]\nOutput: [[1,0]]\nExplanation: Each tree represents a binary matrix of size 1*1. Each matrix contains only zero.\nThe resulting matrix is of size 1*1 with also zero.\n
    \n\n

    Example 3:

    \n\n
    \nInput: quadTree1 = [[0,0],[1,0],[1,0],[1,1],[1,1]]\n, quadTree2 = [[0,0],[1,1],[1,1],[1,0],[1,1]]\nOutput: [[1,1]]\n
    \n\n

    Example 4:

    \n\n
    \nInput: quadTree1 = [[0,0],[1,1],[1,0],[1,1],[1,1]]\n, quadTree2 = [[0,0],[1,1],[0,1],[1,1],[1,1],null,null,null,null,[1,1],[1,0],[1,0],[1,1]]\nOutput: [[0,0],[1,1],[0,1],[1,1],[1,1],null,null,null,null,[1,1],[1,0],[1,0],[1,1]]\n
    \n\n

    Example 5:

    \n\n
    \nInput: quadTree1 = [[0,1],[1,0],[0,1],[1,1],[1,0],null,null,null,null,[1,0],[1,0],[1,1],[1,1]]\n, quadTree2 = [[0,1],[0,1],[1,0],[1,1],[1,0],[1,0],[1,0],[1,1],[1,1]]\nOutput: [[0,0],[0,1],[0,1],[1,1],[1,0],[1,0],[1,0],[1,1],[1,1],[1,0],[1,0],[1,1],[1,1]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • quadTree1 and quadTree2 are both valid Quad-Trees each representing a n * n grid.
    • \n\t
    • n == 2^x where 0 <= x <= 9.
    • \n
    \n", "content_cn": "

    \u4e8c\u8fdb\u5236\u77e9\u9635\u4e2d\u7684\u6240\u6709\u5143\u7d20\u4e0d\u662f 0 \u5c31\u662f 1 \u3002

    \n\n

    \u7ed9\u4f60\u4e24\u4e2a\u56db\u53c9\u6811\uff0cquadTree1 \u548c quadTree2\u3002\u5176\u4e2d quadTree1 \u8868\u793a\u4e00\u4e2a n * n \u4e8c\u8fdb\u5236\u77e9\u9635\uff0c\u800c quadTree2 \u8868\u793a\u53e6\u4e00\u4e2a n * n \u4e8c\u8fdb\u5236\u77e9\u9635\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u4e00\u4e2a\u8868\u793a n * n \u4e8c\u8fdb\u5236\u77e9\u9635\u7684\u56db\u53c9\u6811\uff0c\u5b83\u662f quadTree1 \u548c quadTree2 \u6240\u8868\u793a\u7684\u4e24\u4e2a\u4e8c\u8fdb\u5236\u77e9\u9635\u8fdb\u884c \u6309\u4f4d\u903b\u8f91\u6216\u8fd0\u7b97 \u7684\u7ed3\u679c\u3002

    \n\n

    \u6ce8\u610f\uff0c\u5f53 isLeaf \u4e3a False \u65f6\uff0c\u4f60\u53ef\u4ee5\u628a True \u6216\u8005 False \u8d4b\u503c\u7ed9\u8282\u70b9\uff0c\u4e24\u79cd\u503c\u90fd\u4f1a\u88ab\u5224\u9898\u673a\u5236 \u63a5\u53d7 \u3002

    \n\n

    \u56db\u53c9\u6811\u6570\u636e\u7ed3\u6784\u4e2d\uff0c\u6bcf\u4e2a\u5185\u90e8\u8282\u70b9\u53ea\u6709\u56db\u4e2a\u5b50\u8282\u70b9\u3002\u6b64\u5916\uff0c\u6bcf\u4e2a\u8282\u70b9\u90fd\u6709\u4e24\u4e2a\u5c5e\u6027\uff1a

    \n\n
      \n\t
    • val\uff1a\u50a8\u5b58\u53f6\u5b50\u7ed3\u70b9\u6240\u4ee3\u8868\u7684\u533a\u57df\u7684\u503c\u30021 \u5bf9\u5e94 True\uff0c0 \u5bf9\u5e94 False\uff1b
    • \n\t
    • isLeaf: \u5f53\u8fd9\u4e2a\u8282\u70b9\u662f\u4e00\u4e2a\u53f6\u5b50\u7ed3\u70b9\u65f6\u4e3a True\uff0c\u5982\u679c\u5b83\u6709 4 \u4e2a\u5b50\u8282\u70b9\u5219\u4e3a False \u3002
    • \n
    \n\n
    \nclass Node {\n    public boolean val;\n\u00a0 \u00a0 public boolean isLeaf;\n\u00a0 \u00a0 public Node topLeft;\n\u00a0 \u00a0 public Node topRight;\n\u00a0 \u00a0 public Node bottomLeft;\n\u00a0 \u00a0 public Node bottomRight;\n}
    \n\n

    \u6211\u4eec\u53ef\u4ee5\u6309\u4ee5\u4e0b\u6b65\u9aa4\u4e3a\u4e8c\u7ef4\u533a\u57df\u6784\u5efa\u56db\u53c9\u6811\uff1a

    \n\n
      \n\t
    1. \u5982\u679c\u5f53\u524d\u7f51\u683c\u7684\u503c\u76f8\u540c\uff08\u5373\uff0c\u5168\u4e3a 0 \u6216\u8005\u5168\u4e3a 1\uff09\uff0c\u5c06 isLeaf \u8bbe\u4e3a True \uff0c\u5c06 val \u8bbe\u4e3a\u7f51\u683c\u76f8\u5e94\u7684\u503c\uff0c\u5e76\u5c06\u56db\u4e2a\u5b50\u8282\u70b9\u90fd\u8bbe\u4e3a Null \u7136\u540e\u505c\u6b62\u3002
    2. \n\t
    3. \u5982\u679c\u5f53\u524d\u7f51\u683c\u7684\u503c\u4e0d\u540c\uff0c\u5c06 isLeaf \u8bbe\u4e3a False\uff0c \u5c06 val \u8bbe\u4e3a\u4efb\u610f\u503c\uff0c\u7136\u540e\u5982\u4e0b\u56fe\u6240\u793a\uff0c\u5c06\u5f53\u524d\u7f51\u683c\u5212\u5206\u4e3a\u56db\u4e2a\u5b50\u7f51\u683c\u3002
    4. \n\t
    5. \u4f7f\u7528\u9002\u5f53\u7684\u5b50\u7f51\u683c\u9012\u5f52\u6bcf\u4e2a\u5b50\u8282\u70b9\u3002
    6. \n
    \n\n

    \"\"

    \n\n

    \u5982\u679c\u4f60\u60f3\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u56db\u53c9\u6811\u7684\u5185\u5bb9\uff0c\u53ef\u4ee5\u53c2\u8003 wiki \u3002

    \n\n

    \u56db\u53c9\u6811\u683c\u5f0f\uff1a

    \n\n

    \u8f93\u51fa\u4e3a\u4f7f\u7528\u5c42\u5e8f\u904d\u5386\u540e\u56db\u53c9\u6811\u7684\u5e8f\u5217\u5316\u5f62\u5f0f\uff0c\u5176\u4e2d null \u8868\u793a\u8def\u5f84\u7ec8\u6b62\u7b26\uff0c\u5176\u4e0b\u9762\u4e0d\u5b58\u5728\u8282\u70b9\u3002

    \n\n

    \u5b83\u4e0e\u4e8c\u53c9\u6811\u7684\u5e8f\u5217\u5316\u975e\u5e38\u76f8\u4f3c\u3002\u552f\u4e00\u7684\u533a\u522b\u662f\u8282\u70b9\u4ee5\u5217\u8868\u5f62\u5f0f\u8868\u793a [isLeaf, val] \u3002

    \n\n

    \u5982\u679c isLeaf \u6216\u8005 val \u7684\u503c\u4e3a True \uff0c\u5219\u8868\u793a\u5b83\u5728\u5217\u8868\u00a0[isLeaf, val] \u4e2d\u7684\u503c\u4e3a 1 \uff1b\u5982\u679c isLeaf \u6216\u8005 val \u7684\u503c\u4e3a False \uff0c\u5219\u8868\u793a\u503c\u4e3a 0 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\" \"\"

    \n\n
    \n\u8f93\u5165\uff1aquadTree1 = [[0,1],[1,1],[1,1],[1,0],[1,0]]\n, quadTree2 = [[0,1],[1,1],[0,1],[1,1],[1,0],null,null,null,null,[1,0],[1,0],[1,1],[1,1]]\n\u8f93\u51fa\uff1a[[0,0],[1,1],[1,1],[1,1],[1,0]]\n\u89e3\u91ca\uff1aquadTree1 \u548c quadTree2 \u5982\u4e0a\u6240\u793a\u3002\u7531\u56db\u53c9\u6811\u6240\u8868\u793a\u7684\u4e8c\u8fdb\u5236\u77e9\u9635\u4e5f\u5df2\u7ecf\u7ed9\u51fa\u3002\n\u5982\u679c\u6211\u4eec\u5bf9\u8fd9\u4e24\u4e2a\u77e9\u9635\u8fdb\u884c\u6309\u4f4d\u903b\u8f91\u6216\u8fd0\u7b97\uff0c\u5219\u53ef\u4ee5\u5f97\u5230\u4e0b\u9762\u7684\u4e8c\u8fdb\u5236\u77e9\u9635\uff0c\u7531\u4e00\u4e2a\u4f5c\u4e3a\u7ed3\u679c\u7684\u56db\u53c9\u6811\u8868\u793a\u3002\n\u6ce8\u610f\uff0c\u6211\u4eec\u5c55\u793a\u7684\u4e8c\u8fdb\u5236\u77e9\u9635\u4ec5\u4ec5\u662f\u4e3a\u4e86\u66f4\u597d\u5730\u8bf4\u660e\u9898\u610f\uff0c\u4f60\u65e0\u9700\u6784\u9020\u4e8c\u8fdb\u5236\u77e9\u9635\u6765\u83b7\u5f97\u7ed3\u679c\u56db\u53c9\u6811\u3002\n\"\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aquadTree1 = [[1,0]]\n, quadTree2 = [[1,0]]\n\u8f93\u51fa\uff1a[[1,0]]\n\u89e3\u91ca\uff1a\u4e24\u4e2a\u6570\u6240\u8868\u793a\u7684\u77e9\u9635\u5927\u5c0f\u90fd\u4e3a 1*1\uff0c\u503c\u5168\u4e3a 0 \n\u7ed3\u679c\u77e9\u9635\u5927\u5c0f\u4e3a 1*1\uff0c\u503c\u5168\u4e3a 0 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aquadTree1 = [[0,0],[1,0],[1,0],[1,1],[1,1]]\n, quadTree2 = [[0,0],[1,1],[1,1],[1,0],[1,1]]\n\u8f93\u51fa\uff1a[[1,1]]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1aquadTree1 = [[0,0],[1,1],[1,0],[1,1],[1,1]]\n, quadTree2 = [[0,0],[1,1],[0,1],[1,1],[1,1],null,null,null,null,[1,1],[1,0],[1,0],[1,1]]\n\u8f93\u51fa\uff1a[[0,0],[1,1],[0,1],[1,1],[1,1],null,null,null,null,[1,1],[1,0],[1,0],[1,1]]\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1aquadTree1 = [[0,1],[1,0],[0,1],[1,1],[1,0],null,null,null,null,[1,0],[1,0],[1,1],[1,1]]\n, quadTree2 = [[0,1],[0,1],[1,0],[1,1],[1,0],[1,0],[1,0],[1,1],[1,1]]\n\u8f93\u51fa\uff1a[[0,0],[0,1],[0,1],[1,1],[1,0],[1,0],[1,0],[1,1],[1,1],[1,0],[1,0],[1,1],[1,1]]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • quadTree1 \u548c quadTree2 \u90fd\u662f\u7b26\u5408\u9898\u76ee\u8981\u6c42\u7684\u56db\u53c9\u6811\uff0c\u6bcf\u4e2a\u90fd\u4ee3\u8868\u4e00\u4e2a n * n \u7684\u77e9\u9635\u3002
    • \n\t
    • n == 2^x \uff0c\u5176\u4e2d 0 <= x <= 9.
    • \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n// Definition for a QuadTree node.\nclass Node {\npublic:\n bool val;\n bool isLeaf;\n Node* topLeft;\n Node* topRight;\n Node* bottomLeft;\n Node* bottomRight;\n \n Node() {\n val = false;\n isLeaf = false;\n topLeft = NULL;\n topRight = NULL;\n bottomLeft = NULL;\n bottomRight = NULL;\n }\n \n Node(bool _val, bool _isLeaf) {\n val = _val;\n isLeaf = _isLeaf;\n topLeft = NULL;\n topRight = NULL;\n bottomLeft = NULL;\n bottomRight = NULL;\n }\n \n Node(bool _val, bool _isLeaf, Node* _topLeft, Node* _topRight, Node* _bottomLeft, Node* _bottomRight) {\n val = _val;\n isLeaf = _isLeaf;\n topLeft = _topLeft;\n topRight = _topRight;\n bottomLeft = _bottomLeft;\n bottomRight = _bottomRight;\n }\n};\n*/\n\nclass Solution {\npublic:\n Node* intersect(Node* quadTree1, Node* quadTree2) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/*\n// Definition for a QuadTree node.\nclass Node {\n public boolean val;\n public boolean isLeaf;\n public Node topLeft;\n public Node topRight;\n public Node bottomLeft;\n public Node bottomRight;\n\n public Node() {}\n\n public Node(boolean _val,boolean _isLeaf,Node _topLeft,Node _topRight,Node _bottomLeft,Node _bottomRight) {\n val = _val;\n isLeaf = _isLeaf;\n topLeft = _topLeft;\n topRight = _topRight;\n bottomLeft = _bottomLeft;\n bottomRight = _bottomRight;\n }\n};\n*/\n\nclass Solution {\n public Node intersect(Node quadTree1, Node quadTree2) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "\"\"\"\n# Definition for a QuadTree node.\nclass Node(object):\n def __init__(self, val, isLeaf, topLeft, topRight, bottomLeft, bottomRight):\n self.val = val\n self.isLeaf = isLeaf\n self.topLeft = topLeft\n self.topRight = topRight\n self.bottomLeft = bottomLeft\n self.bottomRight = bottomRight\n\"\"\"\n\nclass Solution(object):\n def intersect(self, quadTree1, quadTree2):\n \"\"\"\n :type quadTree1: Node\n :type quadTree2: Node\n :rtype: Node\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "\"\"\"\n# Definition for a QuadTree node.\nclass Node:\n def __init__(self, val, isLeaf, topLeft, topRight, bottomLeft, bottomRight):\n self.val = val\n self.isLeaf = isLeaf\n self.topLeft = topLeft\n self.topRight = topRight\n self.bottomLeft = bottomLeft\n self.bottomRight = bottomRight\n\"\"\"\n\nclass Solution:\n def intersect(self, quadTree1: 'Node', quadTree2: 'Node') -> 'Node':\n ", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/*\n// Definition for a QuadTree node.\npublic class Node {\n public bool val;\n public bool isLeaf;\n public Node topLeft;\n public Node topRight;\n public Node bottomLeft;\n public Node bottomRight;\n\n public Node(){}\n public Node(bool _val,bool _isLeaf,Node _topLeft,Node _topRight,Node _bottomLeft,Node _bottomRight) {\n val = _val;\n isLeaf = _isLeaf;\n topLeft = _topLeft;\n topRight = _topRight;\n bottomLeft = _bottomLeft;\n bottomRight = _bottomRight;\n }\n}\n*/\n\npublic class Solution {\n public Node Intersect(Node quadTree1, Node quadTree2) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // Definition for a QuadTree node.\n * function Node(val,isLeaf,topLeft,topRight,bottomLeft,bottomRight) {\n * this.val = val;\n * this.isLeaf = isLeaf;\n * this.topLeft = topLeft;\n * this.topRight = topRight;\n * this.bottomLeft = bottomLeft;\n * this.bottomRight = bottomRight;\n * };\n */\n\n/**\n * @param {Node} quadTree1\n * @param {Node} quadTree2\n * @return {Node}\n */\nvar intersect = function(quadTree1, quadTree2) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a QuadTree node.\n# class Node\n# attr_accessor :val, :isLeaf, :topLeft, :topRight, :bottomLeft, :bottomRight\n# def initialize(val=false, isLeaf=false, topLeft=nil, topRight=nil, bottomLeft=nil, bottomRight=nil)\n# @val = val\n# @isLeaf = isLeaf\n# @topLeft = topLeft\n# @topRight = topRight\n# @bottomLeft = bottomLeft\n# @bottomRight = bottomRight\n# end\n# end\n\n# @param {Node} quadTree1\n# @param {Node} quadTree2\n# @return {Node}\ndef intersect(quadTree1, quadTree2)\n\t\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a Node.\n * public class Node {\n * public var val: Bool\n * public var isLeaf: Bool\n * public var topLeft: Node?\n * public var topRight: Node?\n * public var bottomLeft: Node?\n * public var bottomRight: Node?\n * public init(_ val: Bool, _ isLeaf: Bool) {\n * self.val = val\n * self.isLeaf = isLeaf\n * self.topLeft = nil\n * self.topRight = nil\n * self.bottomLeft = nil\n * self.bottomRight = nil\n * }\n * }\n */\n\nclass Solution {\n func intersect(_ quadTree1: Node?, _ quadTree2: Node?) -> Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a QuadTree node.\n * type Node struct {\n * Val bool\n * IsLeaf bool\n * TopLeft *Node\n * TopRight *Node\n * BottomLeft *Node\n * BottomRight *Node\n * }\n */\n\nfunc intersect(quadTree1 *Node, quadTree2 *Node) *Node {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a QuadTree node.\n * class Node(var _value: Boolean, var _isLeaf: Boolean) {\n * var value: Int = _value\n * var isLeaf: Boolean = _isLeaf\n * var topLeft: Node = null\n * var topRight: Node = null\n * var bottomLeft: Node = null\n * var bottomRight: Node = null\n * }\n */\n\nobject Solution {\n def intersect(quadTree1: Node, quadTree2: Node): Node = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a QuadTree node.\n * class Node(var `val`: Boolean, var isLeaf: Boolean) {\n * var topLeft: Node? = null\n * var topRight: Node? = null\n * var bottomLeft: Node? = null\n * var bottomRight: Node? = null\n * }\n */\n\nclass Solution {\n fun intersect(quadTree1: Node?, quadTree2: Node?): Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a QuadTree node.\n * class Node {\n * public $val = null;\n * public $isLeaf = null;\n * public $topLeft = null;\n * public $topRight = null;\n * public $bottomLeft = null;\n * public $bottomRight = null;\n * function __construct($val, $isLeaf) {\n * $this->val = $val;\n * $this->isLeaf = $isLeaf;\n * $this->topLeft = null;\n * $this->topRight = null;\n * $this->bottomLeft = null;\n * $this->bottomRight = null;\n * }\n * }\n */\n\nclass Solution {\n /**\n * @param Node $quadTree1\n * @param Node $quadTree2\n * @return Node\n */\n function intersect($quadTree1, $quadTree2) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for node.\n * class Node {\n * val: boolean\n * isLeaf: boolean\n * topLeft: Node | null\n * topRight: Node | null\n * bottomLeft: Node | null\n * bottomRight: Node | null\n * constructor(val?: boolean, isLeaf?: boolean, topLeft?: Node, topRight?: Node, bottomLeft?: Node, bottomRight?: Node) {\n * this.val = (val===undefined ? false : val)\n * this.isLeaf = (isLeaf===undefined ? false : isLeaf)\n * this.topLeft = (topLeft===undefined ? null : topLeft)\n * this.topRight = (topRight===undefined ? null : topRight)\n * this.bottomLeft = (bottomLeft===undefined ? null : bottomLeft)\n * this.bottomRight = (bottomRight===undefined ? null : bottomRight)\n * }\n * }\n */\n\nfunction intersect(quadTree1: Node | null, quadTree2: Node | null): Node | null {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0558](https://leetcode-cn.com/problems/logical-or-of-two-binary-grids-represented-as-quad-trees)", "[\u56db\u53c9\u6811\u4ea4\u96c6](/solution/0500-0599/0558.Logical%20OR%20of%20Two%20Binary%20Grids%20Represented%20as%20Quad-Trees/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0558](https://leetcode.com/problems/logical-or-of-two-binary-grids-represented-as-quad-trees)", "[Logical OR of Two Binary Grids Represented as Quad-Trees](/solution/0500-0599/0558.Logical%20OR%20of%20Two%20Binary%20Grids%20Represented%20as%20Quad-Trees/README_EN.md)", "", "Medium", ""]}, {"question_id": "0772", "frontend_question_id": "0427", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/construct-quad-tree", "url_en": "https://leetcode.com/problems/construct-quad-tree", "relative_path_cn": "/solution/0400-0499/0427.Construct%20Quad%20Tree/README.md", "relative_path_en": "/solution/0400-0499/0427.Construct%20Quad%20Tree/README_EN.md", "title_cn": "\u5efa\u7acb\u56db\u53c9\u6811", "title_en": "Construct Quad Tree", "question_title_slug": "construct-quad-tree", "content_en": "

    Given a n * n matrix grid of 0's and 1's only. We want to represent the grid with a Quad-Tree.

    \r\n\r\n

    Return the root of the Quad-Tree representing the grid.

    \r\n\r\n

    Notice that you can assign the value of a node to True or False when isLeaf is False, and both are accepted in the answer.

    \r\n\r\n

    A Quad-Tree is a tree data structure in which each internal node has exactly four children. Besides, each node has two attributes:

    \r\n\r\n
      \r\n\t
    • val: True if the node represents a grid of 1's or False if the node represents a grid of 0's. 
    • \r\n\t
    • isLeaf: True if the node is leaf node on the tree or False if the node has the four children.
    • \r\n
    \r\n\r\n
    \r\nclass Node {\r\n    public boolean val;\r\n    public boolean isLeaf;\r\n    public Node topLeft;\r\n    public Node topRight;\r\n    public Node bottomLeft;\r\n    public Node bottomRight;\r\n}
    \r\n\r\n

    We can construct a Quad-Tree from a two-dimensional area using the following steps:

    \r\n\r\n
      \r\n\t
    1. If the current grid has the same value (i.e all 1's or all 0's) set isLeaf True and set val to the value of the grid and set the four children to Null and stop.
    2. \r\n\t
    3. If the current grid has different values, set isLeaf to False and set val to any value and divide the current grid into four sub-grids as shown in the photo.
    4. \r\n\t
    5. Recurse for each of the children with the proper sub-grid.
    6. \r\n
    \r\n\"\"\r\n

    If you want to know more about the Quad-Tree, you can refer to the wiki.

    \r\n\r\n

    Quad-Tree format:

    \r\n\r\n

    The output represents the serialized format of a Quad-Tree using level order traversal, where null signifies a path terminator where no node exists below.

    \r\n\r\n

    It is very similar to the serialization of the binary tree. The only difference is that the node is represented as a list [isLeaf, val].

    \r\n\r\n

    If the value of isLeaf or val is True we represent it as 1 in the list [isLeaf, val] and if the value of isLeaf or val is False we represent it as 0.

    \r\n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: grid = [[0,1],[1,0]]\nOutput: [[0,1],[1,0],[1,1],[1,1],[1,0]]\nExplanation: The explanation of this example is shown below:\nNotice that 0 represnts False and 1 represents True in the photo representing the Quad-Tree.\n\"\"\n
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: grid = [[1,1,1,1,0,0,0,0],[1,1,1,1,0,0,0,0],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,0,0,0,0],[1,1,1,1,0,0,0,0],[1,1,1,1,0,0,0,0],[1,1,1,1,0,0,0,0]]\nOutput: [[0,1],[1,1],[0,1],[1,1],[1,0],null,null,null,null,[1,0],[1,0],[1,1],[1,1]]\nExplanation: All values in the grid are not the same. We divide the grid into four sub-grids.\nThe topLeft, bottomLeft and bottomRight each has the same value.\nThe topRight have different values so we divide it into 4 sub-grids where each has the same value.\nExplanation is shown in the photo below:\n\"\"\n
    \n\n

    Example 3:

    \n\n
    \nInput: grid = [[1,1],[1,1]]\nOutput: [[1,1]]\n
    \n\n

    Example 4:

    \n\n
    \nInput: grid = [[0]]\nOutput: [[1,0]]\n
    \n\n

    Example 5:

    \n\n
    \nInput: grid = [[1,1,0,0],[1,1,0,0],[0,0,1,1],[0,0,1,1]]\nOutput: [[0,1],[1,1],[1,0],[1,0],[1,1]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == grid.length == grid[i].length
    • \n\t
    • n == 2^x where 0 <= x <= 6
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a n * n \u77e9\u9635 grid \uff0c\u77e9\u9635\u7531\u82e5\u5e72 0 \u548c 1 \u7ec4\u6210\u3002\u8bf7\u4f60\u7528\u56db\u53c9\u6811\u8868\u793a\u8be5\u77e9\u9635 grid \u3002

    \n\n

    \u4f60\u9700\u8981\u8fd4\u56de\u80fd\u8868\u793a\u77e9\u9635\u7684 \u56db\u53c9\u6811 \u7684\u6839\u7ed3\u70b9\u3002

    \n\n

    \u6ce8\u610f\uff0c\u5f53 isLeaf \u4e3a False \u65f6\uff0c\u4f60\u53ef\u4ee5\u628a True \u6216\u8005 False \u8d4b\u503c\u7ed9\u8282\u70b9\uff0c\u4e24\u79cd\u503c\u90fd\u4f1a\u88ab\u5224\u9898\u673a\u5236 \u63a5\u53d7 \u3002

    \n\n

    \u56db\u53c9\u6811\u6570\u636e\u7ed3\u6784\u4e2d\uff0c\u6bcf\u4e2a\u5185\u90e8\u8282\u70b9\u53ea\u6709\u56db\u4e2a\u5b50\u8282\u70b9\u3002\u6b64\u5916\uff0c\u6bcf\u4e2a\u8282\u70b9\u90fd\u6709\u4e24\u4e2a\u5c5e\u6027\uff1a

    \n\n
      \n\t
    • val\uff1a\u50a8\u5b58\u53f6\u5b50\u7ed3\u70b9\u6240\u4ee3\u8868\u7684\u533a\u57df\u7684\u503c\u30021 \u5bf9\u5e94 True\uff0c0 \u5bf9\u5e94 False\uff1b
    • \n\t
    • isLeaf: \u5f53\u8fd9\u4e2a\u8282\u70b9\u662f\u4e00\u4e2a\u53f6\u5b50\u7ed3\u70b9\u65f6\u4e3a True\uff0c\u5982\u679c\u5b83\u6709 4 \u4e2a\u5b50\u8282\u70b9\u5219\u4e3a False \u3002
    • \n
    \n\n
    class Node {\n    public boolean val;\n    public boolean isLeaf;\n    public Node topLeft;\n    public Node topRight;\n    public Node bottomLeft;\n    public Node bottomRight;\n}
    \n\n

    \u6211\u4eec\u53ef\u4ee5\u6309\u4ee5\u4e0b\u6b65\u9aa4\u4e3a\u4e8c\u7ef4\u533a\u57df\u6784\u5efa\u56db\u53c9\u6811\uff1a

    \n\n
      \n\t
    1. \u5982\u679c\u5f53\u524d\u7f51\u683c\u7684\u503c\u76f8\u540c\uff08\u5373\uff0c\u5168\u4e3a 0 \u6216\u8005\u5168\u4e3a 1\uff09\uff0c\u5c06 isLeaf \u8bbe\u4e3a True \uff0c\u5c06 val \u8bbe\u4e3a\u7f51\u683c\u76f8\u5e94\u7684\u503c\uff0c\u5e76\u5c06\u56db\u4e2a\u5b50\u8282\u70b9\u90fd\u8bbe\u4e3a Null \u7136\u540e\u505c\u6b62\u3002
    2. \n\t
    3. \u5982\u679c\u5f53\u524d\u7f51\u683c\u7684\u503c\u4e0d\u540c\uff0c\u5c06 isLeaf \u8bbe\u4e3a False\uff0c \u5c06 val \u8bbe\u4e3a\u4efb\u610f\u503c\uff0c\u7136\u540e\u5982\u4e0b\u56fe\u6240\u793a\uff0c\u5c06\u5f53\u524d\u7f51\u683c\u5212\u5206\u4e3a\u56db\u4e2a\u5b50\u7f51\u683c\u3002
    4. \n\t
    5. \u4f7f\u7528\u9002\u5f53\u7684\u5b50\u7f51\u683c\u9012\u5f52\u6bcf\u4e2a\u5b50\u8282\u70b9\u3002
    6. \n
    \n\n

    \"\"

    \n\n

    \u5982\u679c\u4f60\u60f3\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u56db\u53c9\u6811\u7684\u5185\u5bb9\uff0c\u53ef\u4ee5\u53c2\u8003 wiki \u3002

    \n\n

    \u56db\u53c9\u6811\u683c\u5f0f\uff1a

    \n\n

    \u8f93\u51fa\u4e3a\u4f7f\u7528\u5c42\u5e8f\u904d\u5386\u540e\u56db\u53c9\u6811\u7684\u5e8f\u5217\u5316\u5f62\u5f0f\uff0c\u5176\u4e2d null \u8868\u793a\u8def\u5f84\u7ec8\u6b62\u7b26\uff0c\u5176\u4e0b\u9762\u4e0d\u5b58\u5728\u8282\u70b9\u3002

    \n\n

    \u5b83\u4e0e\u4e8c\u53c9\u6811\u7684\u5e8f\u5217\u5316\u975e\u5e38\u76f8\u4f3c\u3002\u552f\u4e00\u7684\u533a\u522b\u662f\u8282\u70b9\u4ee5\u5217\u8868\u5f62\u5f0f\u8868\u793a [isLeaf, val] \u3002

    \n\n

    \u5982\u679c isLeaf \u6216\u8005 val \u7684\u503c\u4e3a True \uff0c\u5219\u8868\u793a\u5b83\u5728\u5217\u8868 [isLeaf, val] \u4e2d\u7684\u503c\u4e3a 1 \uff1b\u5982\u679c isLeaf \u6216\u8005 val \u7684\u503c\u4e3a False \uff0c\u5219\u8868\u793a\u503c\u4e3a 0 \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1agrid = [[0,1],[1,0]]\n\u8f93\u51fa\uff1a[[0,1],[1,0],[1,1],[1,1],[1,0]]\n\u89e3\u91ca\uff1a\u6b64\u793a\u4f8b\u7684\u89e3\u91ca\u5982\u4e0b\uff1a\n\u8bf7\u6ce8\u610f\uff0c\u5728\u4e0b\u9762\u56db\u53c9\u6811\u7684\u56fe\u793a\u4e2d\uff0c0 \u8868\u793a false\uff0c1 \u8868\u793a True \u3002\n\"\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1agrid = [[1,1,1,1,0,0,0,0],[1,1,1,1,0,0,0,0],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,0,0,0,0],[1,1,1,1,0,0,0,0],[1,1,1,1,0,0,0,0],[1,1,1,1,0,0,0,0]]\n\u8f93\u51fa\uff1a[[0,1],[1,1],[0,1],[1,1],[1,0],null,null,null,null,[1,0],[1,0],[1,1],[1,1]]\n\u89e3\u91ca\uff1a\u7f51\u683c\u4e2d\u7684\u6240\u6709\u503c\u90fd\u4e0d\u76f8\u540c\u3002\u6211\u4eec\u5c06\u7f51\u683c\u5212\u5206\u4e3a\u56db\u4e2a\u5b50\u7f51\u683c\u3002\ntopLeft\uff0cbottomLeft \u548c bottomRight \u5747\u5177\u6709\u76f8\u540c\u7684\u503c\u3002\ntopRight \u5177\u6709\u4e0d\u540c\u7684\u503c\uff0c\u56e0\u6b64\u6211\u4eec\u5c06\u5176\u518d\u5206\u4e3a 4 \u4e2a\u5b50\u7f51\u683c\uff0c\u8fd9\u6837\u6bcf\u4e2a\u5b50\u7f51\u683c\u90fd\u5177\u6709\u76f8\u540c\u7684\u503c\u3002\n\u89e3\u91ca\u5982\u4e0b\u56fe\u6240\u793a\uff1a\n\"\"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1agrid = [[1,1],[1,1]]\n\u8f93\u51fa\uff1a[[1,1]]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1agrid = [[0]]\n\u8f93\u51fa\uff1a[[1,0]]\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1agrid = [[1,1,0,0],[1,1,0,0],[0,0,1,1],[0,0,1,1]]\n\u8f93\u51fa\uff1a[[0,1],[1,1],[1,0],[1,0],[1,1]]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. n == grid.length == grid[i].length
    2. \n\t
    3. n == 2^x \u5176\u4e2d 0 <= x <= 6
    4. \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n// Definition for a QuadTree node.\nclass Node {\npublic:\n bool val;\n bool isLeaf;\n Node* topLeft;\n Node* topRight;\n Node* bottomLeft;\n Node* bottomRight;\n \n Node() {\n val = false;\n isLeaf = false;\n topLeft = NULL;\n topRight = NULL;\n bottomLeft = NULL;\n bottomRight = NULL;\n }\n \n Node(bool _val, bool _isLeaf) {\n val = _val;\n isLeaf = _isLeaf;\n topLeft = NULL;\n topRight = NULL;\n bottomLeft = NULL;\n bottomRight = NULL;\n }\n \n Node(bool _val, bool _isLeaf, Node* _topLeft, Node* _topRight, Node* _bottomLeft, Node* _bottomRight) {\n val = _val;\n isLeaf = _isLeaf;\n topLeft = _topLeft;\n topRight = _topRight;\n bottomLeft = _bottomLeft;\n bottomRight = _bottomRight;\n }\n};\n*/\n\nclass Solution {\npublic:\n Node* construct(vector>& grid) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/*\n// Definition for a QuadTree node.\nclass Node {\n public boolean val;\n public boolean isLeaf;\n public Node topLeft;\n public Node topRight;\n public Node bottomLeft;\n public Node bottomRight;\n\n \n public Node() {\n this.val = false;\n this.isLeaf = false;\n this.topLeft = null;\n this.topRight = null;\n this.bottomLeft = null;\n this.bottomRight = null;\n }\n \n public Node(boolean val, boolean isLeaf) {\n this.val = val;\n this.isLeaf = isLeaf;\n this.topLeft = null;\n this.topRight = null;\n this.bottomLeft = null;\n this.bottomRight = null;\n }\n \n public Node(boolean val, boolean isLeaf, Node topLeft, Node topRight, Node bottomLeft, Node bottomRight) {\n this.val = val;\n this.isLeaf = isLeaf;\n this.topLeft = topLeft;\n this.topRight = topRight;\n this.bottomLeft = bottomLeft;\n this.bottomRight = bottomRight;\n }\n};\n*/\n\nclass Solution {\n public Node construct(int[][] grid) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "\"\"\"\n# Definition for a QuadTree node.\nclass Node(object):\n def __init__(self, val, isLeaf, topLeft, topRight, bottomLeft, bottomRight):\n self.val = val\n self.isLeaf = isLeaf\n self.topLeft = topLeft\n self.topRight = topRight\n self.bottomLeft = bottomLeft\n self.bottomRight = bottomRight\n\"\"\"\n\nclass Solution(object):\n def construct(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: Node\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "\"\"\"\n# Definition for a QuadTree node.\nclass Node:\n def __init__(self, val, isLeaf, topLeft, topRight, bottomLeft, bottomRight):\n self.val = val\n self.isLeaf = isLeaf\n self.topLeft = topLeft\n self.topRight = topRight\n self.bottomLeft = bottomLeft\n self.bottomRight = bottomRight\n\"\"\"\n\nclass Solution:\n def construct(self, grid: List[List[int]]) -> 'Node':\n ", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/*\n// Definition for a QuadTree node.\npublic class Node {\n public bool val;\n public bool isLeaf;\n public Node topLeft;\n public Node topRight;\n public Node bottomLeft;\n public Node bottomRight;\n\n public Node() {\n val = false;\n isLeaf = false;\n topLeft = null;\n topRight = null;\n bottomLeft = null;\n bottomRight = null;\n }\n \n public Node(bool _val, bool _isLeaf) {\n val = _val;\n isLeaf = _isLeaf;\n topLeft = null;\n topRight = null;\n bottomLeft = null;\n bottomRight = null;\n }\n \n public Node(bool _val,bool _isLeaf,Node _topLeft,Node _topRight,Node _bottomLeft,Node _bottomRight) {\n val = _val;\n isLeaf = _isLeaf;\n topLeft = _topLeft;\n topRight = _topRight;\n bottomLeft = _bottomLeft;\n bottomRight = _bottomRight;\n }\n}\n*/\n\npublic class Solution {\n public Node Construct(int[][] grid) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // Definition for a QuadTree node.\n * function Node(val,isLeaf,topLeft,topRight,bottomLeft,bottomRight) {\n * this.val = val;\n * this.isLeaf = isLeaf;\n * this.topLeft = topLeft;\n * this.topRight = topRight;\n * this.bottomLeft = bottomLeft;\n * this.bottomRight = bottomRight;\n * };\n */\n\n/**\n * @param {number[][]} grid\n * @return {Node}\n */\nvar construct = function(grid) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a QuadTree node.\n# class Node\n# attr_accessor :val, :isLeaf, :topLeft, :topRight, :bottomLeft, :bottomRight\n# def initialize(val=false, isLeaf=false, topLeft=nil, topRight=nil, bottomLeft=nil, bottomRight=nil)\n# @val = val\n# @isLeaf = isLeaf\n# @topLeft = topLeft\n# @topRight = topRight\n# @bottomLeft = bottomLeft\n# @bottomRight = bottomRight\n# end\n# end\n\n# @param {Integer[][]} grid\n# @return {Node}\ndef construct(grid)\n\t\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a QuadTree node.\n * public class Node {\n * public var val: Bool\n * public var isLeaf: Bool\n * public var topLeft: Node?\n * public var topRight: Node?\n * public var bottomLeft: Node?\n * public var bottomRight: Node?\n * public init(_ val: Bool, _ isLeaf: Bool) {\n * self.val = val\n * self.isLeaf = isLeaf\n * self.topLeft = nil\n * self.topRight = nil\n * self.bottomLeft = nil\n * self.bottomRight = nil\n * }\n * }\n */\n\nclass Solution {\n func construct(_ grid: [[Int]]) -> Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a QuadTree node.\n * type Node struct {\n * Val bool\n * IsLeaf bool\n * TopLeft *Node\n * TopRight *Node\n * BottomLeft *Node\n * BottomRight *Node\n * }\n */\n\nfunc construct(grid [][]int) *Node {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a QuadTree node.\n * class Node(var _value: Boolean, var _isLeaf: Boolean) {\n * var value: Int = _value\n * var isLeaf: Boolean = _isLeaf\n * var topLeft: Node = null\n * var topRight: Node = null\n * var bottomLeft: Node = null\n * var bottomRight: Node = null\n * }\n */\n\nobject Solution {\n def construct(grid: Array[Array[Int]]): Node = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a QuadTree node.\n * class Node(var `val`: Boolean, var isLeaf: Boolean) {\n * var topLeft: Node? = null\n * var topRight: Node? = null\n * var bottomLeft: Node? = null\n * var bottomRight: Node? = null\n * }\n */\n\nclass Solution {\n fun construct(grid: Array): Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a QuadTree node.\n * class Node {\n * public $val = null;\n * public $isLeaf = null;\n * public $topLeft = null;\n * public $topRight = null;\n * public $bottomLeft = null;\n * public $bottomRight = null;\n * function __construct($val, $isLeaf) {\n * $this->val = $val;\n * $this->isLeaf = $isLeaf;\n * $this->topLeft = null;\n * $this->topRight = null;\n * $this->bottomLeft = null;\n * $this->bottomRight = null;\n * }\n * }\n */\n\nclass Solution {\n /**\n * @param Integer[][] $grid\n * @return Node\n */\n function construct($grid) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for node.\n * class Node {\n * val: boolean\n * isLeaf: boolean\n * topLeft: Node | null\n * topRight: Node | null\n * bottomLeft: Node | null\n * bottomRight: Node | null\n * constructor(val?: boolean, isLeaf?: boolean, topLeft?: Node, topRight?: Node, bottomLeft?: Node, bottomRight?: Node) {\n * this.val = (val===undefined ? false : val)\n * this.isLeaf = (isLeaf===undefined ? false : isLeaf)\n * this.topLeft = (topLeft===undefined ? null : topLeft)\n * this.topRight = (topRight===undefined ? null : topRight)\n * this.bottomLeft = (bottomLeft===undefined ? null : bottomLeft)\n * this.bottomRight = (bottomRight===undefined ? null : bottomRight)\n * }\n * }\n */\n\nfunction construct(grid: number[][]): Node | null {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0427](https://leetcode-cn.com/problems/construct-quad-tree)", "[\u5efa\u7acb\u56db\u53c9\u6811](/solution/0400-0499/0427.Construct%20Quad%20Tree/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0427](https://leetcode.com/problems/construct-quad-tree)", "[Construct Quad Tree](/solution/0400-0499/0427.Construct%20Quad%20Tree/README_EN.md)", "", "Medium", ""]}, {"question_id": "0771", "frontend_question_id": "0431", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/encode-n-ary-tree-to-binary-tree", "url_en": "https://leetcode.com/problems/encode-n-ary-tree-to-binary-tree", "relative_path_cn": "/solution/0400-0499/0431.Encode%20N-ary%20Tree%20to%20Binary%20Tree/README.md", "relative_path_en": "/solution/0400-0499/0431.Encode%20N-ary%20Tree%20to%20Binary%20Tree/README_EN.md", "title_cn": "\u5c06 N \u53c9\u6811\u7f16\u7801\u4e3a\u4e8c\u53c9\u6811", "title_en": "Encode N-ary Tree to Binary Tree", "question_title_slug": "encode-n-ary-tree-to-binary-tree", "content_en": "

    Design an algorithm to encode an N-ary tree into a binary tree and decode the binary tree to get the original N-ary tree. An N-ary tree is a rooted tree in which each node has no more than N children. Similarly, a binary tree is a rooted tree in which each node has no more than 2 children. There is no restriction on how your encode/decode algorithm should work. You just need to ensure that an N-ary tree can be encoded to a binary tree and this binary tree can be decoded to the original N-nary tree structure.

    \n\n

    Nary-Tree input serialization is represented in their level order traversal, each group of children is separated by the null value (See following example).

    \n\n

    For example, you may encode the following 3-ary tree to a binary tree in this way:

    \n\n

    \n\n
    \nInput: root = [1,null,3,2,4,null,5,6]\n
    \n\n

    Note that the above is just an example which might or might not work. You do not necessarily need to follow this format, so please be creative and come up with different approaches yourself.

    \n\n
      \n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The height of the n-ary tree is less than or equal to 1000
    • \n\t
    • The total number of nodes is between [0, 104]
    • \n\t
    • Do not use class member/global/static variables to store states. Your encode and decode algorithms should be stateless.
    • \n
    \n", "content_cn": "

    \u8bbe\u8ba1\u4e00\u4e2a\u7b97\u6cd5\uff0c\u53ef\u4ee5\u5c06 N \u53c9\u6811\u7f16\u7801\u4e3a\u4e8c\u53c9\u6811\uff0c\u5e76\u80fd\u5c06\u8be5\u4e8c\u53c9\u6811\u89e3\u7801\u4e3a\u539f N \u53c9\u6811\u3002\u4e00\u4e2a N \u53c9\u6811\u662f\u6307\u6bcf\u4e2a\u8282\u70b9\u90fd\u6709\u4e0d\u8d85\u8fc7 N \u4e2a\u5b69\u5b50\u8282\u70b9\u7684\u6709\u6839\u6811\u3002\u7c7b\u4f3c\u5730\uff0c\u4e00\u4e2a\u4e8c\u53c9\u6811\u662f\u6307\u6bcf\u4e2a\u8282\u70b9\u90fd\u6709\u4e0d\u8d85\u8fc7 2 \u4e2a\u5b69\u5b50\u8282\u70b9\u7684\u6709\u6839\u6811\u3002\u4f60\u7684\u7f16\u7801 / \u89e3\u7801\u7684\u7b97\u6cd5\u7684\u5b9e\u73b0\u6ca1\u6709\u9650\u5236\uff0c\u4f60\u53ea\u9700\u8981\u4fdd\u8bc1\u4e00\u4e2a N \u53c9\u6811\u53ef\u4ee5\u7f16\u7801\u4e3a\u4e8c\u53c9\u6811\u4e14\u8be5\u4e8c\u53c9\u6811\u53ef\u4ee5\u89e3\u7801\u56de\u539f\u59cb N \u53c9\u6811\u5373\u53ef\u3002

    \n\n

    \u4f8b\u5982\uff0c\u4f60\u53ef\u4ee5\u5c06\u4e0b\u9762\u7684 3-\u53c9 \u6811\u4ee5\u8be5\u79cd\u65b9\u5f0f\u7f16\u7801\uff1a

    \n\n

     

    \n\n

    \n\n

     

    \n\n

    \u6ce8\u610f\uff0c\u4e0a\u9762\u7684\u65b9\u6cd5\u4ec5\u4ec5\u662f\u4e00\u4e2a\u4f8b\u5b50\uff0c\u53ef\u80fd\u53ef\u884c\u4e5f\u53ef\u80fd\u4e0d\u53ef\u884c\u3002\u4f60\u6ca1\u6709\u5fc5\u8981\u9075\u5faa\u8fd9\u79cd\u5f62\u5f0f\u8f6c\u5316\uff0c\u4f60\u53ef\u4ee5\u81ea\u5df1\u521b\u9020\u548c\u5b9e\u73b0\u4e0d\u540c\u7684\u65b9\u6cd5\u3002

    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    1. N \u7684\u8303\u56f4\u5728 [1, 1000]
    2. \n\t
    3. \u4e0d\u8981\u4f7f\u7528\u7c7b\u6210\u5458 / \u5168\u5c40\u53d8\u91cf / \u9759\u6001\u53d8\u91cf\u6765\u5b58\u50a8\u72b6\u6001\u3002\u4f60\u7684\u7f16\u7801\u548c\u89e3\u7801\u7b97\u6cd5\u5e94\u662f\u65e0\u72b6\u6001\u7684\u3002
    4. \n
    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n vector children;\n\n Node() {}\n\n Node(int _val) {\n val = _val;\n }\n\n Node(int _val, vector _children) {\n val = _val;\n children = _children;\n }\n};\n*/\n\n/**\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\nclass Codec {\npublic:\n // Encodes an n-ary tree to a binary tree.\n TreeNode* encode(Node* root) {\n \n }\n\t\n // Decodes your binary tree to an n-ary tree.\n Node* decode(TreeNode* root) {\n \n }\n};\n\n// Your Codec object will be instantiated and called as such:\n// Codec codec;\n// codec.decode(codec.encode(root));", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/*\n// Definition for a Node.\nclass Node {\n public int val;\n public List children;\n\n public Node() {}\n\n public Node(int _val) {\n val = _val;\n }\n\n public Node(int _val, List _children) {\n val = _val;\n children = _children;\n }\n};\n*/\n\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode(int x) { val = x; }\n * }\n */\n\nclass Codec {\n // Encodes an n-ary tree to a binary tree.\n public TreeNode encode(Node root) {\n \n }\n\t\n // Decodes your binary tree to an n-ary tree.\n public Node decode(TreeNode root) {\n \n }\n}\n\n// Your Codec object will be instantiated and called as such:\n// Codec codec = new Codec();\n// codec.decode(codec.encode(root));", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "\"\"\"\n# Definition for a Node.\nclass Node(object):\n def __init__(self, val=None, children=None):\n self.val = val\n self.children = children\n\"\"\"\n\n\"\"\"\n# Definition for a binary tree node.\nclass TreeNode(object):\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\"\"\"\n\nclass Codec:\n def encode(self, root):\n \"\"\"Encodes an n-ary tree to a binary tree.\n :type root: Node\n :rtype: TreeNode\n \"\"\"\n \n\t\n def decode(self, data):\n \"\"\"Decodes your binary tree to an n-ary tree.\n :type data: TreeNode\n :rtype: Node\n \"\"\"\n \n\n# Your Codec object will be instantiated and called as such:\n# codec = Codec()\n# codec.decode(codec.encode(root))", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "\"\"\"\n# Definition for a Node.\nclass Node:\n def __init__(self, val=None, children=None):\n self.val = val\n self.children = children\n\"\"\"\n\n\"\"\"\n# Definition for a binary tree node.\nclass TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\"\"\"\n\nclass Codec:\n # Encodes an n-ary tree to a binary tree.\n def encode(self, root: 'Node') -> TreeNode:\n \n\t\n\t# Decodes your binary tree to an n-ary tree.\n def decode(self, data: TreeNode) -> 'Node':\n \n\n# Your Codec object will be instantiated and called as such:\n# codec = Codec()\n# codec.decode(codec.encode(root))", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/*\n// Definition for a Node.\npublic class Node {\n public int val;\n public IList children;\n\n public Node() {}\n\n public Node(int _val) {\n val = _val;\n }\n\n public Node(int _val, IList _children) {\n val = _val;\n children = _children;\n }\n}\n*/\n\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int x) { val = x; }\n * }\n */\n\npublic class Codec {\n // Encodes an n-ary tree to a binary tree.\n public TreeNode encode(Node root) {\n \n }\n \n // Decodes your binary tree to an n-ary tree.\n public Node decode(TreeNode root) {\n \n }\n}\n\n// Your Codec object will be instantiated and called as such:\n// Codec codec = new Codec();\n// codec.decode(codec.encode(root));", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // Definition for a Node.\n * function Node(val, children) {\n * this.val = val;\n * this.children = children;\n * };\n */\n\n/**\n * Definition for a binary tree node.\n * function TreeNode(val) {\n * this.val = val;\n * this.left = this.right = null;\n * }\n */\n\nclass Codec {\n \tconstructor() {\n }\n \n /** \n * @param {Node|null} root\n * @return {TreeNode|null}\n */\n // Encodes an n-ary tree to a binary tree.\n encode = function(root) {\n\t\t\n };\n\t\n /** \n * @param {TreeNode|null} root \n * @return {Node|null}\n */\n // Decodes your binary tree to an n-ary tree.\n decode = function(root) {\n\t\t\n };\n}\n\n/*\n* Your Codec object will be instantiated and called as such:\n* codec = Codec()\n* codec.decode(codec.encode(root))\n*/", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a Node.\n# class Node\n# attr_accessor :val, :children\n# def initialize(val=0, children=[])\n# @val = val\n# @children = children\n# end\n# end\n\n# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val)\n# @val = val\n# @left, @right = nil, nil\n# end\n# end\n\nclass Codec\n # Encodes an n-ary tree to a binary tree.\n # @param {Node} root\n\t# @return {TreeNode}\n def encode(root)\n \t\n end\n \n # Decodes your binary tree to an n-ary tree.\n # @param {TreeNode} root\n\t# @return {Node}\n def decode(root)\n \n end\nend\n\n# Your Codec object will be instantiated and called as such:\n# obj = Codec.new()\n# data = obj.encode(root)\n# ans = obj.decode(data)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a Node.\n * public class Node {\n * public var val: Int\n * public var children: [Node]\n * public init(_ val: Int) {\n * self.val = val\n * self.children = []\n * }\n * }\n */\n\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.left = nil\n * self.right = nil\n * }\n * }\n */\n\nclass Codec {\n func encode(_ root: Node?) -> TreeNode? {\n \n }\n \n func decode(_ root: TreeNode?) -> Node? {\n \n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * let obj = Codec()\n * let ret_1: TreeNode? = obj.encode(root)\n * let ret_2: Node? = obj.decode(root)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a Node.\n * type Node struct {\n * Val int\n * Children []*Node\n * }\n */\n\n/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\n\ntype Codec struct {\n \n}\n\nfunc Constructor() *Codec {\n \n}\n\nfunc (this *Codec) encode(root *Node) *TreeNode {\n \n}\n\nfunc (this *Codec) decode(root *TreeNode) *Node {\n \n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * obj := Constructor();\n * bst := obj.encode(root);\n * ans := obj.decode(bst);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a Node.\n * class Node(var _value: Int) {\n * var value: Int = _value\n * var children: List[Node] = List()\n * }\n */\n\n/**\n * Definition for a binary tree node.\n * class TreeNode(var _value: Int) {\n * var value: Int = _value\n * var left: TreeNode = null\n * var right: TreeNode = null\n * }\n */\n\nclass Codec {\n // Encodes an n-ary tree to a binary tree.\n def encode(root: Node): TreeNode = {\n \n }\n \n // Decodes your binary tree to an n-ary tree.\n def decode(root: TreeNode): Node = {\n \n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * var obj = new Codec()\n * var data = obj.encode(root)\n * var ans = obj.decode(data)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a Node.\n * class Node(var `val`: Int) {\n * var children: List = listOf()\n * }\n */\n\n/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\n\nclass Codec {\n // Encodes a tree to a single string.\n fun encode(root: Node?): TreeNode? {\n \n }\n \n // Decodes your encoded data to tree.\n fun decode(root: TreeNode?): Node? {\n \n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * var obj = Codec()\n * var data = obj.encode(root)\n * var ans = obj.decode(data)\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a Node.\n * class Node {\n * public $val = null;\n * public $children = null;\n * function __construct($val = 0) {\n * $this->val = $val;\n * $this->children = array();\n * }\n * }\n */\n\n/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\n\nclass Codec {\n /**\n * @param Node $root\n * @return TreeNode\n */\n function encode($root) {\n \t\n }\n \n /**\n * @param TreeNode $root\n * @return Node\n */\n function decode($root) {\n \n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * $obj = Codec();\n * $ret_1 = $obj->encode($root);\n * $ret_2 = $obj->decode($root);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for node.\n * class Node {\n * val: number\n * children: Node[]\n * constructor(val?: number) {\n * this.val = (val===undefined ? 0 : val)\n * this.children = []\n * }\n * }\n */\n\n/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nclass Codec {\n \tconstructor() {\n \n }\n \n // Encodes a tree to a binary tree.\n serialize(root: Node | null): TreeNode | null {\n \n };\n\t\n // Decodes your encoded data to tree.\n deserialize(root: TreeNode | null): Node | null {\n \n };\n}\n\n// Your Codec object will be instantiated and called as such:\n// Codec codec = new Codec();\n// codec.deserialize(codec.serialize(root));", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0431](https://leetcode-cn.com/problems/encode-n-ary-tree-to-binary-tree)", "[\u5c06 N \u53c9\u6811\u7f16\u7801\u4e3a\u4e8c\u53c9\u6811](/solution/0400-0499/0431.Encode%20N-ary%20Tree%20to%20Binary%20Tree/README.md)", "`\u6811`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0431](https://leetcode.com/problems/encode-n-ary-tree-to-binary-tree)", "[Encode N-ary Tree to Binary Tree](/solution/0400-0499/0431.Encode%20N-ary%20Tree%20to%20Binary%20Tree/README_EN.md)", "`Tree`", "Hard", "\ud83d\udd12"]}, {"question_id": "0770", "frontend_question_id": "0765", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/couples-holding-hands", "url_en": "https://leetcode.com/problems/couples-holding-hands", "relative_path_cn": "/solution/0700-0799/0765.Couples%20Holding%20Hands/README.md", "relative_path_en": "/solution/0700-0799/0765.Couples%20Holding%20Hands/README_EN.md", "title_cn": "\u60c5\u4fa3\u7275\u624b", "title_en": "Couples Holding Hands", "question_title_slug": "couples-holding-hands", "content_en": "

    \r\nN couples sit in 2N seats arranged in a row and want to hold hands. We want to know the minimum number of swaps so that every couple is sitting side by side. A swap consists of choosing any two people, then they stand up and switch seats. \r\n

    \r\nThe people and seats are represented by an integer from 0 to 2N-1, the couples are numbered in order, the first couple being (0, 1), the second couple being (2, 3), and so on with the last couple being (2N-2, 2N-1).\r\n

    \r\nThe couples' initial seating is given by row[i] being the value of the person who is initially sitting in the i-th seat.\r\n\r\n

    Example 1:

    \r\nInput: row = [0, 2, 1, 3]\r\nOutput: 1\r\nExplanation: We only need to swap the second (row[1]) and third (row[2]) person.\r\n

    \r\n\r\n

    Example 2:

    \r\nInput: row = [3, 2, 0, 1]\r\nOutput: 0\r\nExplanation: All couples are already seated side by side.\r\n

    \r\n\r\n

    \r\nNote:\r\n

      \r\n
    1. len(row) is even and in the range of [4, 60].
    2. \r\n
    3. row is guaranteed to be a permutation of 0...len(row)-1.
    4. \r\n
    ", "content_cn": "

    N \u5bf9\u60c5\u4fa3\u5750\u5728\u8fde\u7eed\u6392\u5217\u7684 2N \u4e2a\u5ea7\u4f4d\u4e0a\uff0c\u60f3\u8981\u7275\u5230\u5bf9\u65b9\u7684\u624b\u3002 \u8ba1\u7b97\u6700\u5c11\u4ea4\u6362\u5ea7\u4f4d\u7684\u6b21\u6570\uff0c\u4ee5\u4fbf\u6bcf\u5bf9\u60c5\u4fa3\u53ef\u4ee5\u5e76\u80a9\u5750\u5728\u4e00\u8d77\u3002 \u4e00\u6b21\u4ea4\u6362\u53ef\u9009\u62e9\u4efb\u610f\u4e24\u4eba\uff0c\u8ba9\u4ed6\u4eec\u7ad9\u8d77\u6765\u4ea4\u6362\u5ea7\u4f4d\u3002

    \n\n

    \u4eba\u548c\u5ea7\u4f4d\u7528 0 \u5230 2N-1 \u7684\u6574\u6570\u8868\u793a\uff0c\u60c5\u4fa3\u4eec\u6309\u987a\u5e8f\u7f16\u53f7\uff0c\u7b2c\u4e00\u5bf9\u662f (0, 1)\uff0c\u7b2c\u4e8c\u5bf9\u662f (2, 3)\uff0c\u4ee5\u6b64\u7c7b\u63a8\uff0c\u6700\u540e\u4e00\u5bf9\u662f (2N-2, 2N-1)\u3002

    \n\n

    \u8fd9\u4e9b\u60c5\u4fa3\u7684\u521d\u59cb\u5ea7\u4f4d  row[i] \u662f\u7531\u6700\u521d\u59cb\u5750\u5728\u7b2c i \u4e2a\u5ea7\u4f4d\u4e0a\u7684\u4eba\u51b3\u5b9a\u7684\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: row = [0, 2, 1, 3]\n\u8f93\u51fa: 1\n\u89e3\u91ca: \u6211\u4eec\u53ea\u9700\u8981\u4ea4\u6362row[1]\u548crow[2]\u7684\u4f4d\u7f6e\u5373\u53ef\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: row = [3, 2, 0, 1]\n\u8f93\u51fa: 0\n\u89e3\u91ca: \u65e0\u9700\u4ea4\u6362\u5ea7\u4f4d\uff0c\u6240\u6709\u7684\u60c5\u4fa3\u90fd\u5df2\u7ecf\u53ef\u4ee5\u624b\u7275\u624b\u4e86\u3002\n
    \n\n

    \u8bf4\u660e:

    \n\n
      \n\t
    1. len(row) \u662f\u5076\u6570\u4e14\u6570\u503c\u5728 [4, 60]\u8303\u56f4\u5185\u3002
    2. \n\t
    3. \u53ef\u4ee5\u4fdd\u8bc1row \u662f\u5e8f\u5217 0...len(row)-1 \u7684\u4e00\u4e2a\u5168\u6392\u5217\u3002
    4. \n
    \n", "tags_en": ["Greedy", "Union Find", "Graph"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u5e76\u67e5\u96c6", "\u56fe"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minSwapsCouples(vector& row) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minSwapsCouples(int[] row) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minSwapsCouples(self, row):\n \"\"\"\n :type row: List[int]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minSwapsCouples(self, row: List[int]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minSwapsCouples(int* row, int rowSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinSwapsCouples(int[] row) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} row\n * @return {number}\n */\nvar minSwapsCouples = function(row) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} row\n# @return {Integer}\ndef min_swaps_couples(row)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minSwapsCouples(_ row: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minSwapsCouples(row []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minSwapsCouples(row: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minSwapsCouples(row: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_swaps_couples(row: Vec) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $row\n * @return Integer\n */\n function minSwapsCouples($row) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minSwapsCouples(row: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-swaps-couples row)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0765](https://leetcode-cn.com/problems/couples-holding-hands)", "[\u60c5\u4fa3\u7275\u624b](/solution/0700-0799/0765.Couples%20Holding%20Hands/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u5e76\u67e5\u96c6`,`\u56fe`", "\u56f0\u96be", ""], "md_table_row_en": ["[0765](https://leetcode.com/problems/couples-holding-hands)", "[Couples Holding Hands](/solution/0700-0799/0765.Couples%20Holding%20Hands/README_EN.md)", "`Greedy`,`Union Find`,`Graph`", "Hard", ""]}, {"question_id": "0769", "frontend_question_id": "0764", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/largest-plus-sign", "url_en": "https://leetcode.com/problems/largest-plus-sign", "relative_path_cn": "/solution/0700-0799/0764.Largest%20Plus%20Sign/README.md", "relative_path_en": "/solution/0700-0799/0764.Largest%20Plus%20Sign/README_EN.md", "title_cn": "\u6700\u5927\u52a0\u53f7\u6807\u5fd7", "title_en": "Largest Plus Sign", "question_title_slug": "largest-plus-sign", "content_en": "

    In a 2D grid from (0, 0) to (n-1, n-1), every cell contains a 1, except those cells in the given list mines which are 0. What is the largest axis-aligned plus sign of 1s contained in the grid? Return the order of the plus sign. If there is none, return 0.

    \n\n

    An "axis-aligned plus sign of 1s of order k" has some center grid[x][y] = 1 along with 4 arms of length k-1 going up, down, left, and right, and made of 1s. This is demonstrated in the diagrams below. Note that there could be 0s or 1s beyond the arms of the plus sign, only the relevant area of the plus sign is checked for 1s.

    \n\n

    Examples of Axis-Aligned Plus Signs of Order k:

    \n\n
    \nOrder 1:\n000\n010\n000\n\nOrder 2:\n00000\n00100\n01110\n00100\n00000\n\nOrder 3:\n0000000\n0001000\n0001000\n0111110\n0001000\n0001000\n0000000\n
    \n\n

    Example 1:

    \n\n
    \nInput: n = 5, mines = [[4, 2]]\nOutput: 2\nExplanation:\n11111\n11111\n11111\n11111\n11011\nIn the above grid, the largest plus sign can only be order 2.  One of them is marked in bold.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 2, mines = []\nOutput: 1\nExplanation:\nThere is no plus sign of order 2, but there is of order 1.\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 1, mines = [[0, 0]]\nOutput: 0\nExplanation:\nThere is no plus sign, so return 0.\n
    \n\n

    Note:

    \n\n
      \n\t
    1. n will be an integer in the range [1, 500].
    2. \n\t
    3. mines will have length at most 5000.
    4. \n\t
    5. mines[i] will be length 2 and consist of integers in the range [0, n-1].
    6. \n\t
    7. (Additionally, programs submitted in C, C++, or C# will be judged with a slightly smaller time limit.)
    8. \n
    \n\n

     

    \n", "content_cn": "

    \u5728\u4e00\u4e2a\u5927\u5c0f\u5728 (0, 0) \u5230 (N-1, N-1) \u76842D\u7f51\u683c grid \u4e2d\uff0c\u9664\u4e86\u5728 mines \u4e2d\u7ed9\u51fa\u7684\u5355\u5143\u4e3a 0\uff0c\u5176\u4ed6\u6bcf\u4e2a\u5355\u5143\u90fd\u662f 1\u3002\u7f51\u683c\u4e2d\u5305\u542b 1 \u7684\u6700\u5927\u7684\u8f74\u5bf9\u9f50\u52a0\u53f7\u6807\u5fd7\u662f\u591a\u5c11\u9636\uff1f\u8fd4\u56de\u52a0\u53f7\u6807\u5fd7\u7684\u9636\u6570\u3002\u5982\u679c\u672a\u627e\u5230\u52a0\u53f7\u6807\u5fd7\uff0c\u5219\u8fd4\u56de 0\u3002

    \n\n

    \u4e00\u4e2a k" \u9636\u7531 1 \u7ec4\u6210\u7684“\u8f74\u5bf9\u79f0”\u52a0\u53f7\u6807\u5fd7\u5177\u6709\u4e2d\u5fc3\u7f51\u683c  grid[x][y] = 1 \uff0c\u4ee5\u53ca4\u4e2a\u4ece\u4e2d\u5fc3\u5411\u4e0a\u3001\u5411\u4e0b\u3001\u5411\u5de6\u3001\u5411\u53f3\u5ef6\u4f38\uff0c\u957f\u5ea6\u4e3a k-1\uff0c\u7531 1 \u7ec4\u6210\u7684\u81c2\u3002\u4e0b\u9762\u7ed9\u51fa k" \u9636“\u8f74\u5bf9\u79f0”\u52a0\u53f7\u6807\u5fd7\u7684\u793a\u4f8b\u3002\u6ce8\u610f\uff0c\u53ea\u6709\u52a0\u53f7\u6807\u5fd7\u7684\u6240\u6709\u7f51\u683c\u8981\u6c42\u4e3a 1\uff0c\u522b\u7684\u7f51\u683c\u53ef\u80fd\u4e3a 0 \u4e5f\u53ef\u80fd\u4e3a 1\u3002

    \n\n

     

    \n\n

    k \u9636\u8f74\u5bf9\u79f0\u52a0\u53f7\u6807\u5fd7\u793a\u4f8b:

    \n\n
    \n\u9636 1:\n000\n010\n000\n\n\u9636 2:\n00000\n00100\n01110\n00100\n00000\n\n\u9636 3:\n0000000\n0001000\n0001000\n0111110\n0001000\n0001000\n0000000\n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165: N = 5, mines = [[4, 2]]\n\u8f93\u51fa: 2\n\u89e3\u91ca:\n\n11111\n11111\n11111\n11111\n11011\n\n\u5728\u4e0a\u9762\u7684\u7f51\u683c\u4e2d\uff0c\u6700\u5927\u52a0\u53f7\u6807\u5fd7\u7684\u9636\u53ea\u80fd\u662f2\u3002\u4e00\u4e2a\u6807\u5fd7\u5df2\u5728\u56fe\u4e2d\u6807\u51fa\u3002\n
    \n\n

     

    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165: N = 2, mines = []\n\u8f93\u51fa: 1\n\u89e3\u91ca:\n\n11\n11\n\n\u6ca1\u6709 2 \u9636\u52a0\u53f7\u6807\u5fd7\uff0c\u6709 1 \u9636\u52a0\u53f7\u6807\u5fd7\u3002\n
    \n\n

     

    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165: N = 1, mines = [[0, 0]]\n\u8f93\u51fa: 0\n\u89e3\u91ca:\n\n0\n\n\u6ca1\u6709\u52a0\u53f7\u6807\u5fd7\uff0c\u8fd4\u56de 0 \u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. \u6574\u6570N \u7684\u8303\u56f4\uff1a [1, 500].
    2. \n\t
    3. mines \u7684\u6700\u5927\u957f\u5ea6\u4e3a 5000.
    4. \n\t
    5. mines[i] \u662f\u957f\u5ea6\u4e3a2\u7684\u75312\u4e2a [0, N-1] \u4e2d\u7684\u6570\u7ec4\u6210.
    6. \n\t
    7. (\u53e6\u5916,\u4f7f\u7528 C, C++, \u6216\u8005 C# \u7f16\u7a0b\u5c06\u4ee5\u7a0d\u5c0f\u7684\u65f6\u95f4\u9650\u5236\u8fdb\u884c\u200b\u200b\u5224\u65ad.)
    8. \n
    \n\n

     

    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int orderOfLargestPlusSign(int n, vector>& mines) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int orderOfLargestPlusSign(int n, int[][] mines) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def orderOfLargestPlusSign(self, n, mines):\n \"\"\"\n :type n: int\n :type mines: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def orderOfLargestPlusSign(self, n: int, mines: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint orderOfLargestPlusSign(int n, int** mines, int minesSize, int* minesColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int OrderOfLargestPlusSign(int n, int[][] mines) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} mines\n * @return {number}\n */\nvar orderOfLargestPlusSign = function(n, mines) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} mines\n# @return {Integer}\ndef order_of_largest_plus_sign(n, mines)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func orderOfLargestPlusSign(_ n: Int, _ mines: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func orderOfLargestPlusSign(n int, mines [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def orderOfLargestPlusSign(n: Int, mines: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun orderOfLargestPlusSign(n: Int, mines: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn order_of_largest_plus_sign(n: i32, mines: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $mines\n * @return Integer\n */\n function orderOfLargestPlusSign($n, $mines) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function orderOfLargestPlusSign(n: number, mines: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (order-of-largest-plus-sign n mines)\n (-> exact-integer? (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0764](https://leetcode-cn.com/problems/largest-plus-sign)", "[\u6700\u5927\u52a0\u53f7\u6807\u5fd7](/solution/0700-0799/0764.Largest%20Plus%20Sign/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0764](https://leetcode.com/problems/largest-plus-sign)", "[Largest Plus Sign](/solution/0700-0799/0764.Largest%20Plus%20Sign/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0768", "frontend_question_id": "0763", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/partition-labels", "url_en": "https://leetcode.com/problems/partition-labels", "relative_path_cn": "/solution/0700-0799/0763.Partition%20Labels/README.md", "relative_path_en": "/solution/0700-0799/0763.Partition%20Labels/README_EN.md", "title_cn": "\u5212\u5206\u5b57\u6bcd\u533a\u95f4", "title_en": "Partition Labels", "question_title_slug": "partition-labels", "content_en": "

    A string s of lowercase English letters is given. We want to partition this string into as many parts as possible so that each letter appears in at most one part, and return a list of integers representing the size of these parts.

    \n\n

     

    \n\n

    Example 1:

    \n\n
    \nInput: s = "ababcbacadefegdehijhklij"\nOutput: [9,7,8]\nExplanation:\nThe partition is "ababcbaca", "defegde", "hijhklij".\nThis is a partition so that each letter appears in at most one part.\nA partition like "ababcbacadefegde", "hijhklij" is incorrect, because it splits s into less parts.\n
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    • s will have length in range [1, 500].
    • \n\t
    • s will consist of lowercase English letters ('a' to 'z') only.
    • \n
    \n\n

     

    \n", "content_cn": "

    \u5b57\u7b26\u4e32 S \u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210\u3002\u6211\u4eec\u8981\u628a\u8fd9\u4e2a\u5b57\u7b26\u4e32\u5212\u5206\u4e3a\u5c3d\u53ef\u80fd\u591a\u7684\u7247\u6bb5\uff0c\u540c\u4e00\u5b57\u6bcd\u6700\u591a\u51fa\u73b0\u5728\u4e00\u4e2a\u7247\u6bb5\u4e2d\u3002\u8fd4\u56de\u4e00\u4e2a\u8868\u793a\u6bcf\u4e2a\u5b57\u7b26\u4e32\u7247\u6bb5\u7684\u957f\u5ea6\u7684\u5217\u8868\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1aS = \"ababcbacadefegdehijhklij\"\n\u8f93\u51fa\uff1a[9,7,8]\n\u89e3\u91ca\uff1a\n\u5212\u5206\u7ed3\u679c\u4e3a \"ababcbaca\", \"defegde\", \"hijhklij\"\u3002\n\u6bcf\u4e2a\u5b57\u6bcd\u6700\u591a\u51fa\u73b0\u5728\u4e00\u4e2a\u7247\u6bb5\u4e2d\u3002\n\u50cf \"ababcbacadefegde\", \"hijhklij\" \u7684\u5212\u5206\u662f\u9519\u8bef\u7684\uff0c\u56e0\u4e3a\u5212\u5206\u7684\u7247\u6bb5\u6570\u8f83\u5c11\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • S\u7684\u957f\u5ea6\u5728[1, 500]\u4e4b\u95f4\u3002
    • \n\t
    • S\u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd 'a' \u5230 'z' \u3002
    • \n
    \n", "tags_en": ["Greedy", "Two Pointers"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector partitionLabels(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List partitionLabels(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def partitionLabels(self, s):\n \"\"\"\n :type s: str\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def partitionLabels(self, s: str) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* partitionLabels(char * s, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList PartitionLabels(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number[]}\n */\nvar partitionLabels = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer[]}\ndef partition_labels(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func partitionLabels(_ s: String) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func partitionLabels(s string) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def partitionLabels(s: String): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun partitionLabels(s: String): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn partition_labels(s: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer[]\n */\n function partitionLabels($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function partitionLabels(s: string): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (partition-labels s)\n (-> string? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0763](https://leetcode-cn.com/problems/partition-labels)", "[\u5212\u5206\u5b57\u6bcd\u533a\u95f4](/solution/0700-0799/0763.Partition%20Labels/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0763](https://leetcode.com/problems/partition-labels)", "[Partition Labels](/solution/0700-0799/0763.Partition%20Labels/README_EN.md)", "`Greedy`,`Two Pointers`", "Medium", ""]}, {"question_id": "0767", "frontend_question_id": "0762", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/prime-number-of-set-bits-in-binary-representation", "url_en": "https://leetcode.com/problems/prime-number-of-set-bits-in-binary-representation", "relative_path_cn": "/solution/0700-0799/0762.Prime%20Number%20of%20Set%20Bits%20in%20Binary%20Representation/README.md", "relative_path_en": "/solution/0700-0799/0762.Prime%20Number%20of%20Set%20Bits%20in%20Binary%20Representation/README_EN.md", "title_cn": "\u4e8c\u8fdb\u5236\u8868\u793a\u4e2d\u8d28\u6570\u4e2a\u8ba1\u7b97\u7f6e\u4f4d", "title_en": "Prime Number of Set Bits in Binary Representation", "question_title_slug": "prime-number-of-set-bits-in-binary-representation", "content_en": "

    Given two integers left and right, find the count of numbers in the range [left, right] (inclusive) having a prime number of set bits in their binary representation.

    \n\n

    (Recall that the number of set bits an integer has is the number of 1s present when written in binary. For example, 21 written in binary is 10101 which has 3 set bits. Also, 1 is not a prime.)

    \n\n

    Example 1:

    \n\n
    \nInput: left = 6, right = 10\nOutput: 4\nExplanation:\n6 -> 110 (2 set bits, 2 is prime)\n7 -> 111 (3 set bits, 3 is prime)\n9 -> 1001 (2 set bits , 2 is prime)\n10->1010 (2 set bits , 2 is prime)\n
    \n\n

    Example 2:

    \n\n
    \nInput: left = 10, right = 15\nOutput: 5\nExplanation:\n10 -> 1010 (2 set bits, 2 is prime)\n11 -> 1011 (3 set bits, 3 is prime)\n12 -> 1100 (2 set bits, 2 is prime)\n13 -> 1101 (3 set bits, 3 is prime)\n14 -> 1110 (3 set bits, 3 is prime)\n15 -> 1111 (4 set bits, 4 is not prime)\n
    \n\n

    Note:

    \n\n
      \n\t
    1. left, right will be integers left <= right in the range [1, 10^6].
    2. \n\t
    3. right - left will be at most 10000.
    4. \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u6574\u6570 L \u548c R \uff0c\u627e\u5230\u95ed\u533a\u95f4 [L, R] \u8303\u56f4\u5185\uff0c\u8ba1\u7b97\u7f6e\u4f4d\u4f4d\u6570\u4e3a\u8d28\u6570\u7684\u6574\u6570\u4e2a\u6570\u3002

    \n\n

    \uff08\u6ce8\u610f\uff0c\u8ba1\u7b97\u7f6e\u4f4d\u4ee3\u8868\u4e8c\u8fdb\u5236\u8868\u793a\u4e2d1\u7684\u4e2a\u6570\u3002\u4f8b\u5982 21 \u7684\u4e8c\u8fdb\u5236\u8868\u793a 10101 \u6709 3 \u4e2a\u8ba1\u7b97\u7f6e\u4f4d\u3002\u8fd8\u6709\uff0c1 \u4e0d\u662f\u8d28\u6570\u3002\uff09

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: L = 6, R = 10\n\u8f93\u51fa: 4\n\u89e3\u91ca:\n6 -> 110 (2 \u4e2a\u8ba1\u7b97\u7f6e\u4f4d\uff0c2 \u662f\u8d28\u6570)\n7 -> 111 (3 \u4e2a\u8ba1\u7b97\u7f6e\u4f4d\uff0c3 \u662f\u8d28\u6570)\n9 -> 1001 (2 \u4e2a\u8ba1\u7b97\u7f6e\u4f4d\uff0c2 \u662f\u8d28\u6570)\n10-> 1010 (2 \u4e2a\u8ba1\u7b97\u7f6e\u4f4d\uff0c2 \u662f\u8d28\u6570)\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: L = 10, R = 15\n\u8f93\u51fa: 5\n\u89e3\u91ca:\n10 -> 1010 (2 \u4e2a\u8ba1\u7b97\u7f6e\u4f4d, 2 \u662f\u8d28\u6570)\n11 -> 1011 (3 \u4e2a\u8ba1\u7b97\u7f6e\u4f4d, 3 \u662f\u8d28\u6570)\n12 -> 1100 (2 \u4e2a\u8ba1\u7b97\u7f6e\u4f4d, 2 \u662f\u8d28\u6570)\n13 -> 1101 (3 \u4e2a\u8ba1\u7b97\u7f6e\u4f4d, 3 \u662f\u8d28\u6570)\n14 -> 1110 (3 \u4e2a\u8ba1\u7b97\u7f6e\u4f4d, 3 \u662f\u8d28\u6570)\n15 -> 1111 (4 \u4e2a\u8ba1\u7b97\u7f6e\u4f4d, 4 \u4e0d\u662f\u8d28\u6570)\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. L, R \u662f L <= R \u4e14\u5728 [1, 10^6] \u4e2d\u7684\u6574\u6570\u3002
    2. \n\t
    3. R - L \u7684\u6700\u5927\u503c\u4e3a 10000\u3002
    4. \n
    \n", "tags_en": ["Bit Manipulation"], "tags_cn": ["\u4f4d\u8fd0\u7b97"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countPrimeSetBits(int left, int right) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countPrimeSetBits(int left, int right) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countPrimeSetBits(self, left, right):\n \"\"\"\n :type left: int\n :type right: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countPrimeSetBits(self, left: int, right: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countPrimeSetBits(int left, int right){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountPrimeSetBits(int left, int right) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} left\n * @param {number} right\n * @return {number}\n */\nvar countPrimeSetBits = function(left, right) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} left\n# @param {Integer} right\n# @return {Integer}\ndef count_prime_set_bits(left, right)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countPrimeSetBits(_ left: Int, _ right: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countPrimeSetBits(left int, right int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countPrimeSetBits(left: Int, right: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countPrimeSetBits(left: Int, right: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_prime_set_bits(left: i32, right: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $left\n * @param Integer $right\n * @return Integer\n */\n function countPrimeSetBits($left, $right) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countPrimeSetBits(left: number, right: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-prime-set-bits left right)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0762](https://leetcode-cn.com/problems/prime-number-of-set-bits-in-binary-representation)", "[\u4e8c\u8fdb\u5236\u8868\u793a\u4e2d\u8d28\u6570\u4e2a\u8ba1\u7b97\u7f6e\u4f4d](/solution/0700-0799/0762.Prime%20Number%20of%20Set%20Bits%20in%20Binary%20Representation/README.md)", "`\u4f4d\u8fd0\u7b97`", "\u7b80\u5355", ""], "md_table_row_en": ["[0762](https://leetcode.com/problems/prime-number-of-set-bits-in-binary-representation)", "[Prime Number of Set Bits in Binary Representation](/solution/0700-0799/0762.Prime%20Number%20of%20Set%20Bits%20in%20Binary%20Representation/README_EN.md)", "`Bit Manipulation`", "Easy", ""]}, {"question_id": "0766", "frontend_question_id": "0430", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/flatten-a-multilevel-doubly-linked-list", "url_en": "https://leetcode.com/problems/flatten-a-multilevel-doubly-linked-list", "relative_path_cn": "/solution/0400-0499/0430.Flatten%20a%20Multilevel%20Doubly%20Linked%20List/README.md", "relative_path_en": "/solution/0400-0499/0430.Flatten%20a%20Multilevel%20Doubly%20Linked%20List/README_EN.md", "title_cn": "\u6241\u5e73\u5316\u591a\u7ea7\u53cc\u5411\u94fe\u8868", "title_en": "Flatten a Multilevel Doubly Linked List", "question_title_slug": "flatten-a-multilevel-doubly-linked-list", "content_en": "

    You are given a doubly linked list which in addition to the next and previous pointers, it could have a child pointer, which may or may not point to a separate doubly linked list. These child lists may have one or more children of their own, and so on, to produce a multilevel data structure, as shown in the example below.

    \r\n\r\n

    Flatten the list so that all the nodes appear in a single-level, doubly linked list. You are given the head of the first level of the list.

    \r\n\n

     

    \n

    Example 1:

    \n\n
    \nInput: head = [1,2,3,4,5,6,null,null,null,7,8,9,10,null,null,11,12]\nOutput: [1,2,3,7,8,11,12,9,10,4,5,6]\nExplanation:\n\nThe multilevel linked list in the input is as follows:\n\n\n\nAfter flattening the multilevel linked list it becomes:\n\n\n
    \n\n

    Example 2:

    \n\n
    \nInput: head = [1,2,null,3]\nOutput: [1,3,2]\nExplanation:\n\nThe input multilevel linked list is as follows:\n\n  1---2---NULL\n  |\n  3---NULL\n
    \n\n

    Example 3:

    \n\n
    \nInput: head = []\nOutput: []\n
    \n\n

     

    \n\n

    How multilevel linked list is represented in test case:

    \n\n

    We use the multilevel linked list from Example 1 above:

    \n\n
    \n 1---2---3---4---5---6--NULL\n         |\n         7---8---9---10--NULL\n             |\n             11--12--NULL
    \n\n

    The serialization of each level is as follows:

    \n\n
    \n[1,2,3,4,5,6,null]\n[7,8,9,10,null]\n[11,12,null]\n
    \n\n

    To serialize all levels together we will add nulls in each level to signify no node connects to the upper node of the previous level. The serialization becomes:

    \n\n
    \n[1,2,3,4,5,6,null]\n[null,null,7,8,9,10,null]\n[null,11,12,null]\n
    \n\n

    Merging the serialization of each level and removing trailing nulls we obtain:

    \n\n
    \n[1,2,3,4,5,6,null,null,null,7,8,9,10,null,null,11,12]
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of Nodes will not exceed 1000.
    • \n\t
    • 1 <= Node.val <= 105
    • \n
    \n", "content_cn": "

    \u591a\u7ea7\u53cc\u5411\u94fe\u8868\u4e2d\uff0c\u9664\u4e86\u6307\u5411\u4e0b\u4e00\u4e2a\u8282\u70b9\u548c\u524d\u4e00\u4e2a\u8282\u70b9\u6307\u9488\u4e4b\u5916\uff0c\u5b83\u8fd8\u6709\u4e00\u4e2a\u5b50\u94fe\u8868\u6307\u9488\uff0c\u53ef\u80fd\u6307\u5411\u5355\u72ec\u7684\u53cc\u5411\u94fe\u8868\u3002\u8fd9\u4e9b\u5b50\u5217\u8868\u4e5f\u53ef\u80fd\u4f1a\u6709\u4e00\u4e2a\u6216\u591a\u4e2a\u81ea\u5df1\u7684\u5b50\u9879\uff0c\u4f9d\u6b64\u7c7b\u63a8\uff0c\u751f\u6210\u591a\u7ea7\u6570\u636e\u7ed3\u6784\uff0c\u5982\u4e0b\u9762\u7684\u793a\u4f8b\u6240\u793a\u3002

    \n\n

    \u7ed9\u4f60\u4f4d\u4e8e\u5217\u8868\u7b2c\u4e00\u7ea7\u7684\u5934\u8282\u70b9\uff0c\u8bf7\u4f60\u6241\u5e73\u5316\u5217\u8868\uff0c\u4f7f\u6240\u6709\u7ed3\u70b9\u51fa\u73b0\u5728\u5355\u7ea7\u53cc\u94fe\u8868\u4e2d\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1ahead = [1,2,3,4,5,6,null,null,null,7,8,9,10,null,null,11,12]\n\u8f93\u51fa\uff1a[1,2,3,7,8,11,12,9,10,4,5,6]\n\u89e3\u91ca\uff1a\n\n\u8f93\u5165\u7684\u591a\u7ea7\u5217\u8868\u5982\u4e0b\u56fe\u6240\u793a\uff1a\n\n\n\n\u6241\u5e73\u5316\u540e\u7684\u94fe\u8868\u5982\u4e0b\u56fe\uff1a\n\n\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1ahead = [1,2,null,3]\n\u8f93\u51fa\uff1a[1,3,2]\n\u89e3\u91ca\uff1a\n\n\u8f93\u5165\u7684\u591a\u7ea7\u5217\u8868\u5982\u4e0b\u56fe\u6240\u793a\uff1a\n\n  1---2---NULL\n  |\n  3---NULL\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1ahead = []\n\u8f93\u51fa\uff1a[]\n
    \n\n

     

    \n\n

    \u5982\u4f55\u8868\u793a\u6d4b\u8bd5\u7528\u4f8b\u4e2d\u7684\u591a\u7ea7\u94fe\u8868\uff1f

    \n\n

    \u4ee5 \u793a\u4f8b 1 \u4e3a\u4f8b\uff1a

    \n\n
     1---2---3---4---5---6--NULL\n         |\n         7---8---9---10--NULL\n             |\n             11--12--NULL
    \n\n

    \u5e8f\u5217\u5316\u5176\u4e2d\u7684\u6bcf\u4e00\u7ea7\u4e4b\u540e\uff1a

    \n\n
    [1,2,3,4,5,6,null]\n[7,8,9,10,null]\n[11,12,null]\n
    \n\n

    \u4e3a\u4e86\u5c06\u6bcf\u4e00\u7ea7\u90fd\u5e8f\u5217\u5316\u5230\u4e00\u8d77\uff0c\u6211\u4eec\u9700\u8981\u6bcf\u4e00\u7ea7\u4e2d\u6dfb\u52a0\u503c\u4e3a null \u7684\u5143\u7d20\uff0c\u4ee5\u8868\u793a\u6ca1\u6709\u8282\u70b9\u8fde\u63a5\u5230\u4e0a\u4e00\u7ea7\u7684\u4e0a\u7ea7\u8282\u70b9\u3002

    \n\n
    [1,2,3,4,5,6,null]\n[null,null,7,8,9,10,null]\n[null,11,12,null]\n
    \n\n

    \u5408\u5e76\u6240\u6709\u5e8f\u5217\u5316\u7ed3\u679c\uff0c\u5e76\u53bb\u9664\u672b\u5c3e\u7684 null \u3002

    \n\n
    [1,2,3,4,5,6,null,null,null,7,8,9,10,null,null,11,12]
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u8282\u70b9\u6570\u76ee\u4e0d\u8d85\u8fc7 1000
    • \n\t
    • 1 <= Node.val <= 10^5
    • \n
    \n", "tags_en": ["Depth-first Search", "Linked List"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u94fe\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* prev;\n Node* next;\n Node* child;\n};\n*/\n\nclass Solution {\npublic:\n Node* flatten(Node* head) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/*\n// Definition for a Node.\nclass Node {\n public int val;\n public Node prev;\n public Node next;\n public Node child;\n};\n*/\n\nclass Solution {\n public Node flatten(Node head) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "\"\"\"\n# Definition for a Node.\nclass Node(object):\n def __init__(self, val, prev, next, child):\n self.val = val\n self.prev = prev\n self.next = next\n self.child = child\n\"\"\"\n\nclass Solution(object):\n def flatten(self, head):\n \"\"\"\n :type head: Node\n :rtype: Node\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "\"\"\"\n# Definition for a Node.\nclass Node:\n def __init__(self, val, prev, next, child):\n self.val = val\n self.prev = prev\n self.next = next\n self.child = child\n\"\"\"\n\nclass Solution:\n def flatten(self, head: 'Node') -> 'Node':\n ", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/*\n// Definition for a Node.\npublic class Node {\n public int val;\n public Node prev;\n public Node next;\n public Node child;\n}\n*/\n\npublic class Solution {\n public Node Flatten(Node head) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // Definition for a Node.\n * function Node(val,prev,next,child) {\n * this.val = val;\n * this.prev = prev;\n * this.next = next;\n * this.child = child;\n * };\n */\n\n/**\n * @param {Node} head\n * @return {Node}\n */\nvar flatten = function(head) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a Node.\n# class Node\n# attr_accessor :val, :prev, :next, :child\n# def initialize(val=nil, prev=nil, next_=nil, child=nil)\n# @val = val\n# @prev = prev\n# @next = next_\n# @child = child\n# end\n# end\n\n# @param {Node} root\n# @return {Node}\ndef flatten(root)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a Node.\n * public class Node {\n * public var val: Int\n * public var prev: Node?\n * public var next: Node?\n * public var child: Node?\n * public init(_ val: Int) {\n * self.val = val\n * self.prev = nil\n * self.next = nil\n * self.child = nil\n * }\n * }\n */\n\nclass Solution {\n func flatten(_ head: Node?) -> Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a Node.\n * type Node struct {\n * Val int\n * Prev *Node\n * Next *Node\n * Child *Node\n * }\n */\n\nfunc flatten(root *Node) *Node {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a Node.\n * class Node(var _value: Int) {\n * var value: Int = _value\n * var prev: Node = null\n * var next: Node = null\n * var child: Node = null\n * }\n */\n\nobject Solution {\n def flatten(head: Node): Node = {\n \t\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a Node.\n * class Node(var `val`: Int) {\n * var prev: Node? = null\n * var next: Node? = null\n * var child: Node? = null\n * }\n */\n\nclass Solution {\n fun flatten(root: Node?): Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a Node.\n * class Node {\n * public $val = null;\n * public $prev = null;\n * public $next = null;\n * public $child = null;\n * function __construct($val = 0) {\n * $this->val = $val;\n * $this->prev = null;\n * $this->next = null;\n * $this->child = null;\n * }\n * }\n */\n\nclass Solution {\n /**\n * @param Node $head\n * @return Node\n */\n function flatten($head) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for node.\n * class Node {\n * val: number\n * prev: Node | null\n * next: Node | null\n * child: Node | null\n * constructor(val?: number, prev? : Node, next? : Node, child? : Node) {\n * this.val = (val===undefined ? 0 : val);\n * this.prev = (prev===undefined ? null : prev);\n * this.next = (next===undefined ? null : next);\n * this.child = (child===undefined ? null : child);\n * }\n * }\n */\n\nfunction flatten(head: Node | null): Node | null {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0430](https://leetcode-cn.com/problems/flatten-a-multilevel-doubly-linked-list)", "[\u6241\u5e73\u5316\u591a\u7ea7\u53cc\u5411\u94fe\u8868](/solution/0400-0499/0430.Flatten%20a%20Multilevel%20Doubly%20Linked%20List/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u94fe\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0430](https://leetcode.com/problems/flatten-a-multilevel-doubly-linked-list)", "[Flatten a Multilevel Doubly Linked List](/solution/0400-0499/0430.Flatten%20a%20Multilevel%20Doubly%20Linked%20List/README_EN.md)", "`Depth-first Search`,`Linked List`", "Medium", ""]}, {"question_id": "0765", "frontend_question_id": "0428", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/serialize-and-deserialize-n-ary-tree", "url_en": "https://leetcode.com/problems/serialize-and-deserialize-n-ary-tree", "relative_path_cn": "/solution/0400-0499/0428.Serialize%20and%20Deserialize%20N-ary%20Tree/README.md", "relative_path_en": "/solution/0400-0499/0428.Serialize%20and%20Deserialize%20N-ary%20Tree/README_EN.md", "title_cn": "\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316 N \u53c9\u6811", "title_en": "Serialize and Deserialize N-ary Tree", "question_title_slug": "serialize-and-deserialize-n-ary-tree", "content_en": "

    Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be reconstructed later in the same or another computer environment.

    \n\n

    Design an algorithm to serialize and deserialize an N-ary tree. An N-ary tree is a rooted tree in which each node has no more than N children. There is no restriction on how your serialization/deserialization algorithm should work. You just need to ensure that an N-ary tree can be serialized to a string and this string can be deserialized to the original tree structure.

    \n\n

    For example, you may serialize the following 3-ary tree

    \n\n

    \n\n

    as [1 [3[5 6] 2 4]]. Note that this is just an example, you do not necessarily need to follow this format.

    \n\n

    Or you can follow LeetCode's level order traversal serialization format, where each group of children is separated by the null value.

    \n\n

    \"\"

    \n\n

    For example, the above tree may be serialized as [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14].

    \n\n

    You do not necessarily need to follow the above suggested formats, there are many more different formats that work so please be creative and come up with different approaches yourself.

    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [0, 104].
    • \n\t
    • 0 <= Node.val <= 104
    • \n\t
    • The height of the n-ary tree is less than or equal to 1000
    • \n\t
    • Do not use class member/global/static variables to store states. Your encode and decode algorithms should be stateless.
    • \n
    \n", "content_cn": "

    \u5e8f\u5217\u5316\u662f\u6307\u5c06\u4e00\u4e2a\u6570\u636e\u7ed3\u6784\u8f6c\u5316\u4e3a\u4f4d\u5e8f\u5217\u7684\u8fc7\u7a0b\uff0c\u56e0\u6b64\u53ef\u4ee5\u5c06\u5176\u5b58\u50a8\u5728\u6587\u4ef6\u4e2d\u6216\u5185\u5b58\u7f13\u51b2\u533a\u4e2d\uff0c\u4ee5\u4fbf\u7a0d\u540e\u5728\u76f8\u540c\u6216\u4e0d\u540c\u7684\u8ba1\u7b97\u673a\u73af\u5883\u4e2d\u6062\u590d\u7ed3\u6784\u3002

    \n\n

    \u8bbe\u8ba1\u4e00\u4e2a\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316 N \u53c9\u6811\u7684\u7b97\u6cd5\u3002\u4e00\u4e2a N \u53c9\u6811\u662f\u6307\u6bcf\u4e2a\u8282\u70b9\u90fd\u6709\u4e0d\u8d85\u8fc7 N \u4e2a\u5b69\u5b50\u8282\u70b9\u7684\u6709\u6839\u6811\u3002\u5e8f\u5217\u5316 / \u53cd\u5e8f\u5217\u5316\u7b97\u6cd5\u7684\u7b97\u6cd5\u5b9e\u73b0\u6ca1\u6709\u9650\u5236\u3002\u4f60\u53ea\u9700\u8981\u4fdd\u8bc1 N \u53c9\u6811\u53ef\u4ee5\u88ab\u5e8f\u5217\u5316\u4e3a\u4e00\u4e2a\u5b57\u7b26\u4e32\u5e76\u4e14\u8be5\u5b57\u7b26\u4e32\u53ef\u4ee5\u88ab\u53cd\u5e8f\u5217\u5316\u6210\u539f\u6811\u7ed3\u6784\u5373\u53ef\u3002

    \n\n

    \u4f8b\u5982\uff0c\u4f60\u9700\u8981\u5e8f\u5217\u5316\u4e0b\u9762\u7684 3-\u53c9 \u6811\u3002

    \n\n

    \u00a0

    \n\n

    \n\n

    \u00a0

    \n\n

    \u4e3a\u00a0[1 [3[5 6] 2 4]]\u3002\u4f60\u4e0d\u9700\u8981\u4ee5\u8fd9\u79cd\u5f62\u5f0f\u5b8c\u6210\uff0c\u4f60\u53ef\u4ee5\u81ea\u5df1\u521b\u9020\u548c\u5b9e\u73b0\u4e0d\u540c\u7684\u65b9\u6cd5\u3002

    \n\n

    \u6216\u8005\uff0c\u60a8\u53ef\u4ee5\u9075\u5faa LeetCode \u7684\u5c42\u5e8f\u904d\u5386\u5e8f\u5217\u5316\u683c\u5f0f\uff0c\u5176\u4e2d\u6bcf\u7ec4\u5b69\u5b50\u8282\u70b9\u7531\u7a7a\u503c\u5206\u9694\u3002

    \n\n

    \"\"

    \n\n

    \u4f8b\u5982\uff0c\u4e0a\u9762\u7684\u6811\u53ef\u4ee5\u5e8f\u5217\u5316\u4e3a [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]

    \n\n

    \u4f60\u4e0d\u4e00\u5b9a\u8981\u9075\u5faa\u4ee5\u4e0a\u5efa\u8bae\u7684\u683c\u5f0f\uff0c\u6709\u5f88\u591a\u4e0d\u540c\u7684\u683c\u5f0f\uff0c\u6240\u4ee5\u8bf7\u53d1\u6325\u521b\u9020\u529b\uff0c\u60f3\u51fa\u4e0d\u540c\u7684\u65b9\u6cd5\u6765\u5b8c\u6210\u672c\u9898\u3002

    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u6570\u76ee\u7684\u8303\u56f4\u662f [0,\u00a0104].
    • \n\t
    • 0 <= Node.val <= 104
    • \n\t
    • N \u53c9\u6811\u7684\u9ad8\u5ea6\u5c0f\u4e8e\u7b49\u4e8e 1000
    • \n\t
    • \u4e0d\u8981\u4f7f\u7528\u7c7b\u6210\u5458 / \u5168\u5c40\u53d8\u91cf / \u9759\u6001\u53d8\u91cf\u6765\u5b58\u50a8\u72b6\u6001\u3002\u4f60\u7684\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316\u7b97\u6cd5\u5e94\u662f\u65e0\u72b6\u6001\u7684\u3002
    • \n
    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n vector children;\n\n Node() {}\n\n Node(int _val) {\n val = _val;\n }\n\n Node(int _val, vector _children) {\n val = _val;\n children = _children;\n }\n};\n*/\n\nclass Codec {\npublic:\n // Encodes a tree to a single string.\n string serialize(Node* root) {\n \n }\n\t\n // Decodes your encoded data to tree.\n Node* deserialize(string data) {\n \n }\n};\n\n// Your Codec object will be instantiated and called as such:\n// Codec codec;\n// codec.deserialize(codec.serialize(root));", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/*\n// Definition for a Node.\nclass Node {\n public int val;\n public List children;\n\n public Node() {}\n\n public Node(int _val) {\n val = _val;\n }\n\n public Node(int _val, List _children) {\n val = _val;\n children = _children;\n }\n};\n*/\n\nclass Codec {\n // Encodes a tree to a single string.\n public String serialize(Node root) {\n \n }\n\t\n // Decodes your encoded data to tree.\n public Node deserialize(String data) {\n \n }\n}\n\n// Your Codec object will be instantiated and called as such:\n// Codec codec = new Codec();\n// codec.deserialize(codec.serialize(root));", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "\"\"\"\n# Definition for a Node.\nclass Node(object):\n def __init__(self, val=None, children=None):\n self.val = val\n self.children = children\n\"\"\"\n\nclass Codec:\n def serialize(self, root):\n \"\"\"Encodes a tree to a single string.\n \n :type root: Node\n :rtype: str\n \"\"\"\n\t\t\n \n def deserialize(self, data):\n \"\"\"Decodes your encoded data to tree.\n \n :type data: str\n :rtype: Node\n \"\"\"\n \n\n# Your Codec object will be instantiated and called as such:\n# codec = Codec()\n# codec.deserialize(codec.serialize(root))", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "\"\"\"\n# Definition for a Node.\nclass Node(object):\n def __init__(self, val=None, children=None):\n self.val = val\n self.children = children\n\"\"\"\n\nclass Codec:\n def serialize(self, root: 'Node') -> str:\n \"\"\"Encodes a tree to a single string.\n \n :type root: Node\n :rtype: str\n \"\"\"\n \n\t\n def deserialize(self, data: str) -> 'Node':\n \"\"\"Decodes your encoded data to tree.\n \n :type data: str\n :rtype: Node\n \"\"\"\n \n\n# Your Codec object will be instantiated and called as such:\n# codec = Codec()\n# codec.deserialize(codec.serialize(root))", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/*\n// Definition for a Node.\npublic class Node {\n public int val;\n public IList children;\n\n public Node() {}\n\n public Node(int _val) {\n val = _val;\n }\n\n public Node(int _val, IList _children) {\n val = _val;\n children = _children;\n }\n}\n*/\n\npublic class Codec {\n // Encodes a tree to a single string.\n public string serialize(Node root) {\n \n }\n\t\n // Decodes your encoded data to tree.\n public Node deserialize(string data) {\n \n }\n}\n\n// Your Codec object will be instantiated and called as such:\n// Codec codec = new Codec();\n// codec.deserialize(codec.serialize(root));", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // Definition for a Node.\n * function Node(val, children) {\n * this.val = val;\n * this.children = children;\n * };\n */\n\nclass Codec {\n \tconstructor() {\n \n }\n \n /** \n * @param {Node|null} root\n * @return {string}\n */\n // Encodes a tree to a single string.\n serialize = function(root) {\n \n };\n\t\n /** \n * @param {string} data \n * @return {Node|null}\n */\n // Decodes your encoded data to tree.\n deserialize = function(data) {\n \n };\n}\n\n// Your Codec object will be instantiated and called as such:\n// Codec codec = new Codec();\n// codec.deserialize(codec.serialize(root));", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a Node.\n# class Node\n# attr_accessor :val, :children\n# def initialize(val=0, children=[])\n# @val = val\n# @children = children\n# end\n# end\n\nclass Codec\n # Encodes a tree to a single string.\n # @param {Node} root\n\t# @return {String}\n def serialize(root)\n \t\n end\n \n # Decodes your encoded data to tree.\n # @param {String} data\n\t# @return {Node}\n def deserialize(data)\n \n end\nend\n\n# Your Codec object will be instantiated and called as such:\n# obj = Codec.new()\n# data = obj.seralize(root)\n# ans = obj.desrialize(data)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a Node.\n * public class Node {\n * public var val: Int\n * public var children: [Node]\n * public init(_ val: Int) {\n * self.val = val\n * self.children = []\n * }\n * }\n */\n\nclass Codec {\n func serialize(_ root: Node?) -> String {\n \t\n }\n \n func deserialize(_ data: String) -> Node? {\n \t\n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * let obj = Codec()\n * let ret_1: TreeNode? = obj.serialize(root)\n * let ret_2: Node? = obj.decode(data)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a Node.\n * type Node struct {\n * Val int\n * Children []*Node\n * }\n */\n\ntype Codec struct {\n \n}\n\nfunc Constructor() *Codec {\n \n}\n\nfunc (this *Codec) serialize(root *Node) string {\n \n}\n\nfunc (this *Codec) deserialize(data string) *Node {\n \n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * obj := Constructor();\n * data := obj.serialize(root);\n * ans := obj.deserialize(data);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a Node.\n * class Node(var _value: Int) {\n * var value: Int = _value\n * var children: List[Node] = List()\n * }\n */\n\nclass Codec {\n // Encodes a tree to a single string.\n def serialize(root: Node): String = {\n \n }\n \n // Decodes your encoded data to tree.\n def deserialize(data: String): Node = {\n \n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * var obj = new Codec()\n * var data = obj.serialize(root)\n * var ans = obj.deserialize(data)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a Node.\n * class Node(var `val`: Int) {\n * var children: List = listOf()\n * }\n */\n\nclass Codec {\n // Encodes a tree to a single string.\n fun serialize(root: Node?): String {\n \n }\n \n // Decodes your encoded data to tree.\n fun deserialize(data: String): Node? {\n \n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * var obj = Codec()\n * var data = obj.serialize(root)\n * var ans = obj.deserialize(data)\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a Node.\n * class Node {\n * public $val = null;\n * public $children = null;\n * function __construct($val = 0) {\n * $this->val = $val;\n * $this->children = array();\n * }\n * }\n */\n\nclass Codec {\n /**\n * Encodes a tree to a single string.\n * @param Node $root\n * @return String\n */\n function serialize($root) {\n\t\t\n }\n \t\n /**\n * Decodes your encoded data to tree.\n * @param String $data\n * @return Node\n */\n function deserialize($data) {\n \t\n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * $obj = Codec();\n * $ret_1 = $obj->serialize($root);\n * $ret_2 = $obj->deserialize($data);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for node.\n * class Node {\n * val: number\n * children: Node[]\n * constructor(val?: number) {\n * this.val = (val===undefined ? 0 : val)\n * this.children = []\n * }\n * }\n */\n\nclass Codec {\n \tconstructor() {\n \n }\n \n // Encodes a tree to a single string.\n serialize(root: Node | null): string {\n \n };\n\t\n // Decodes your encoded data to tree.\n deserialize(data: string): Node | null {\n \n };\n}\n\n// Your Codec object will be instantiated and called as such:\n// Codec codec = new Codec();\n// codec.deserialize(codec.serialize(root));", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0428](https://leetcode-cn.com/problems/serialize-and-deserialize-n-ary-tree)", "[\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316 N \u53c9\u6811](/solution/0400-0499/0428.Serialize%20and%20Deserialize%20N-ary%20Tree/README.md)", "`\u6811`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0428](https://leetcode.com/problems/serialize-and-deserialize-n-ary-tree)", "[Serialize and Deserialize N-ary Tree](/solution/0400-0499/0428.Serialize%20and%20Deserialize%20N-ary%20Tree/README_EN.md)", "`Tree`", "Hard", "\ud83d\udd12"]}, {"question_id": "0764", "frontend_question_id": "0429", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/n-ary-tree-level-order-traversal", "url_en": "https://leetcode.com/problems/n-ary-tree-level-order-traversal", "relative_path_cn": "/solution/0400-0499/0429.N-ary%20Tree%20Level%20Order%20Traversal/README.md", "relative_path_en": "/solution/0400-0499/0429.N-ary%20Tree%20Level%20Order%20Traversal/README_EN.md", "title_cn": "N \u53c9\u6811\u7684\u5c42\u5e8f\u904d\u5386", "title_en": "N-ary Tree Level Order Traversal", "question_title_slug": "n-ary-tree-level-order-traversal", "content_en": "

    Given an n-ary tree, return the level order traversal of its nodes' values.

    \n\n

    Nary-Tree input serialization is represented in their level order traversal, each group of children is separated by the null value (See examples).

    \n\n

     

    \n

    Example 1:

    \n\n

    \n\n
    \nInput: root = [1,null,3,2,4,null,5,6]\nOutput: [[1],[3,2,4],[5,6]]\n
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: root = [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]\nOutput: [[1],[2,3,4,5],[6,7,8,9,10],[11,12,13],[14]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The height of the n-ary tree is less than or equal to 1000
    • \n\t
    • The total number of nodes is between [0, 104]
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a N \u53c9\u6811\uff0c\u8fd4\u56de\u5176\u8282\u70b9\u503c\u7684\u5c42\u5e8f\u904d\u5386\u3002\uff08\u5373\u4ece\u5de6\u5230\u53f3\uff0c\u9010\u5c42\u904d\u5386\uff09\u3002

    \n\n

    \u6811\u7684\u5e8f\u5217\u5316\u8f93\u5165\u662f\u7528\u5c42\u5e8f\u904d\u5386\uff0c\u6bcf\u7ec4\u5b50\u8282\u70b9\u90fd\u7531 null \u503c\u5206\u9694\uff08\u53c2\u89c1\u793a\u4f8b\uff09\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \n\n
    \n\u8f93\u5165\uff1aroot = [1,null,3,2,4,null,5,6]\n\u8f93\u51fa\uff1a[[1],[3,2,4],[5,6]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aroot = [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]\n\u8f93\u51fa\uff1a[[1],[2,3,4,5],[6,7,8,9,10],[11,12,13],[14]]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u7684\u9ad8\u5ea6\u4e0d\u4f1a\u8d85\u8fc7\u00a01000
    • \n\t
    • \u6811\u7684\u8282\u70b9\u603b\u6570\u5728 [0,\u00a010^4] \u4e4b\u95f4
    • \n
    \n", "tags_en": ["Tree", "Breadth-first Search"], "tags_cn": ["\u6811", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n vector children;\n\n Node() {}\n\n Node(int _val) {\n val = _val;\n }\n\n Node(int _val, vector _children) {\n val = _val;\n children = _children;\n }\n};\n*/\n\nclass Solution {\npublic:\n vector> levelOrder(Node* root) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/*\n// Definition for a Node.\nclass Node {\n public int val;\n public List children;\n\n public Node() {}\n\n public Node(int _val) {\n val = _val;\n }\n\n public Node(int _val, List _children) {\n val = _val;\n children = _children;\n }\n};\n*/\n\nclass Solution {\n public List> levelOrder(Node root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "\"\"\"\n# Definition for a Node.\nclass Node(object):\n def __init__(self, val=None, children=None):\n self.val = val\n self.children = children\n\"\"\"\n\nclass Solution(object):\n def levelOrder(self, root):\n \"\"\"\n :type root: Node\n :rtype: List[List[int]]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "\"\"\"\n# Definition for a Node.\nclass Node:\n def __init__(self, val=None, children=None):\n self.val = val\n self.children = children\n\"\"\"\n\nclass Solution:\n def levelOrder(self, root: 'Node') -> List[List[int]]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a Node.\n * struct Node {\n * int val;\n * int numChildren;\n * struct Node** children;\n * };\n */\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** levelOrder(struct Node* root, int* returnSize, int** returnColumnSizes) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/*\n// Definition for a Node.\npublic class Node {\n public int val;\n public IList children;\n\n public Node() {}\n\n public Node(int _val) {\n val = _val;\n }\n\n public Node(int _val, IList _children) {\n val = _val;\n children = _children;\n }\n}\n*/\n\npublic class Solution {\n public IList> LevelOrder(Node root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // Definition for a Node.\n * function Node(val,children) {\n * this.val = val;\n * this.children = children;\n * };\n */\n\n/**\n * @param {Node|null} root\n * @return {number[][]}\n */\nvar levelOrder = function(root) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a Node.\n# class Node\n# attr_accessor :val, :children\n# def initialize(val)\n# @val = val\n# @children = []\n# end\n# end\n\n# @param {Node} root\n# @return {List[List[int]]}\ndef level_order(root)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a Node.\n * public class Node {\n * public var val: Int\n * public var children: [Node]\n * public init(_ val: Int) {\n * self.val = val\n * self.children = []\n * }\n * }\n */\n\nclass Solution {\n func levelOrder(_ root: Node?) -> [[Int]] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a Node.\n * type Node struct {\n * Val int\n * Children []*Node\n * }\n */\n\nfunc levelOrder(root *Node) [][]int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a Node.\n * class Node(var _value: Int) {\n * var value: Int = _value\n * var children: List[Node] = List()\n * }\n */\n\nobject Solution {\n def levelOrder(root: Node): List[List[Int]] = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a Node.\n * class Node(var `val`: Int) {\n * var children: List = listOf()\n * }\n */\n\nclass Solution {\n fun levelOrder(root: Node?): List> {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a Node.\n * class Node {\n * public $val = null;\n * public $children = null;\n * function __construct($val = 0) {\n * $this->val = $val;\n * $this->children = array();\n * }\n * }\n */\n\nclass Solution {\n /**\n * @param Node $root\n * @return integer[][]\n */\n function levelOrder($root) {\n\t\t\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for node.\n * class Node {\n * val: number\n * children: Node[]\n * constructor(val?: number) {\n * this.val = (val===undefined ? 0 : val)\n * this.children = []\n * }\n * }\n */\n\nfunction levelOrder(root: Node | null): number[][] {\n\t\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0429](https://leetcode-cn.com/problems/n-ary-tree-level-order-traversal)", "[N \u53c9\u6811\u7684\u5c42\u5e8f\u904d\u5386](/solution/0400-0499/0429.N-ary%20Tree%20Level%20Order%20Traversal/README.md)", "`\u6811`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0429](https://leetcode.com/problems/n-ary-tree-level-order-traversal)", "[N-ary Tree Level Order Traversal](/solution/0400-0499/0429.N-ary%20Tree%20Level%20Order%20Traversal/README_EN.md)", "`Tree`,`Breadth-first Search`", "Medium", ""]}, {"question_id": "0763", "frontend_question_id": "0761", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/special-binary-string", "url_en": "https://leetcode.com/problems/special-binary-string", "relative_path_cn": "/solution/0700-0799/0761.Special%20Binary%20String/README.md", "relative_path_en": "/solution/0700-0799/0761.Special%20Binary%20String/README_EN.md", "title_cn": "\u7279\u6b8a\u7684\u4e8c\u8fdb\u5236\u5e8f\u5217", "title_en": "Special Binary String", "question_title_slug": "special-binary-string", "content_en": "

    Special binary strings are binary strings with the following two properties:

    \n\n
      \n\t
    • The number of 0's is equal to the number of 1's.
    • \n\t
    • Every prefix of the binary string has at least as many 1's as 0's.
    • \n
    \n\n

    Given a special string s, a move consists of choosing two consecutive, non-empty, special substrings of s, and swapping them. (Two strings are consecutive if the last character of the first string is exactly one index before the first character of the second string.)

    \n\n

    At the end of any number of moves, what is the lexicographically largest resulting string possible?

    \n\n

    Example 1:

    \n\n
    \nInput: s = "11011000"\nOutput: "11100100"\nExplanation:\nThe strings "10" [occuring at s[1]] and "1100" [at s[3]] are swapped.\nThis is the lexicographically largest string possible after some number of swaps.\n
    \n\n

    Note:

    \n\n
      \n\t
    1. s has length at most 50.
    2. \n\t
    3. s is guaranteed to be a special binary string as defined above.
    4. \n
    \n", "content_cn": "

    \u7279\u6b8a\u7684\u4e8c\u8fdb\u5236\u5e8f\u5217\u662f\u5177\u6709\u4ee5\u4e0b\u4e24\u4e2a\u6027\u8d28\u7684\u4e8c\u8fdb\u5236\u5e8f\u5217\uff1a

    \n\n
      \n\t
    • 0 \u7684\u6570\u91cf\u4e0e 1 \u7684\u6570\u91cf\u76f8\u7b49\u3002
    • \n\t
    • \u4e8c\u8fdb\u5236\u5e8f\u5217\u7684\u6bcf\u4e00\u4e2a\u524d\u7f00\u7801\u4e2d 1 \u7684\u6570\u91cf\u8981\u5927\u4e8e\u7b49\u4e8e 0 \u7684\u6570\u91cf\u3002
    • \n
    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u7279\u6b8a\u7684\u4e8c\u8fdb\u5236\u5e8f\u5217 S\uff0c\u4ee5\u5b57\u7b26\u4e32\u5f62\u5f0f\u8868\u793a\u3002\u5b9a\u4e49\u4e00\u4e2a\u64cd\u4f5c \u4e3a\u9996\u5148\u9009\u62e9 S \u7684\u4e24\u4e2a\u8fde\u7eed\u4e14\u975e\u7a7a\u7684\u7279\u6b8a\u7684\u5b50\u4e32\uff0c\u7136\u540e\u5c06\u5b83\u4eec\u4ea4\u6362\u3002\uff08\u4e24\u4e2a\u5b50\u4e32\u4e3a\u8fde\u7eed\u7684\u5f53\u4e14\u4ec5\u5f53\u7b2c\u4e00\u4e2a\u5b50\u4e32\u7684\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\u6070\u597d\u4e3a\u7b2c\u4e8c\u4e2a\u5b50\u4e32\u7684\u7b2c\u4e00\u4e2a\u5b57\u7b26\u7684\u524d\u4e00\u4e2a\u5b57\u7b26\u3002)

    \n\n

    \u5728\u4efb\u610f\u6b21\u6570\u7684\u64cd\u4f5c\u4e4b\u540e\uff0c\u4ea4\u6362\u540e\u7684\u5b57\u7b26\u4e32\u6309\u7167\u5b57\u5178\u5e8f\u6392\u5217\u7684\u6700\u5927\u7684\u7ed3\u679c\u662f\u4ec0\u4e48\uff1f

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: S = "11011000"\n\u8f93\u51fa: "11100100"\n\u89e3\u91ca:\n\u5c06\u5b50\u4e32 "10" \uff08\u5728S[1]\u51fa\u73b0\uff09 \u548c "1100" \uff08\u5728S[3]\u51fa\u73b0\uff09\u8fdb\u884c\u4ea4\u6362\u3002\n\u8fd9\u662f\u5728\u8fdb\u884c\u82e5\u5e72\u6b21\u64cd\u4f5c\u540e\u6309\u5b57\u5178\u5e8f\u6392\u5217\u6700\u5927\u7684\u7ed3\u679c\u3002\n
    \n\n

    \u8bf4\u660e:

    \n\n
      \n\t
    1. S \u7684\u957f\u5ea6\u4e0d\u8d85\u8fc7 50\u3002
    2. \n\t
    3. S \u4fdd\u8bc1\u4e3a\u4e00\u4e2a\u6ee1\u8db3\u4e0a\u8ff0\u5b9a\u4e49\u7684\u7279\u6b8a \u7684\u4e8c\u8fdb\u5236\u5e8f\u5217\u3002
    4. \n
    \n", "tags_en": ["Recursion", "String"], "tags_cn": ["\u9012\u5f52", "\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string makeLargestSpecial(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String makeLargestSpecial(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def makeLargestSpecial(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def makeLargestSpecial(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * makeLargestSpecial(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string MakeLargestSpecial(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar makeLargestSpecial = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef make_largest_special(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func makeLargestSpecial(_ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func makeLargestSpecial(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def makeLargestSpecial(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun makeLargestSpecial(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn make_largest_special(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function makeLargestSpecial($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function makeLargestSpecial(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (make-largest-special s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0761](https://leetcode-cn.com/problems/special-binary-string)", "[\u7279\u6b8a\u7684\u4e8c\u8fdb\u5236\u5e8f\u5217](/solution/0700-0799/0761.Special%20Binary%20String/README.md)", "`\u9012\u5f52`,`\u5b57\u7b26\u4e32`", "\u56f0\u96be", ""], "md_table_row_en": ["[0761](https://leetcode.com/problems/special-binary-string)", "[Special Binary String](/solution/0700-0799/0761.Special%20Binary%20String/README_EN.md)", "`Recursion`,`String`", "Hard", ""]}, {"question_id": "0762", "frontend_question_id": "0760", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/find-anagram-mappings", "url_en": "https://leetcode.com/problems/find-anagram-mappings", "relative_path_cn": "/solution/0700-0799/0760.Find%20Anagram%20Mappings/README.md", "relative_path_en": "/solution/0700-0799/0760.Find%20Anagram%20Mappings/README_EN.md", "title_cn": "\u627e\u51fa\u53d8\u4f4d\u6620\u5c04", "title_en": "Find Anagram Mappings", "question_title_slug": "find-anagram-mappings", "content_en": "

    Given two lists nums1 and nums2, and nums2 is an anagram of nums1. nums2 is an anagram of nums1 means nums2 is made by randomizing the order of the elements in nums1.

    \n\n

    We want to find an index mapping mapping, from nums1 to nums2. A mapping mapping[i] = j means the ith element in nums1 appears in nums2 at index j.

    \n\n

    These lists nums1 and nums2 may contain duplicates. If there are multiple answers, output any of them.

    \n\n

    For example, given

    \n\n
    \nnums1 = [12, 28, 46, 32, 50]\nnums2 = [50, 12, 32, 46, 28]\n
    \n\n

    We should return

    \n\n
    \n[1, 4, 3, 2, 0]\n
    \n\n

    as mapping[0] = 1 because the 0th element of nums1 appears at nums2[1], and mapping[1] = 4 because the 1st element of nums1 appears at nums2[4], and so on.

    \n\n

    Note:

    \n\n
      \n\t
    1. nums1, nums2 have equal lengths in range [1, 100].
    2. \n\t
    3. nums1[i], nums2[i] are integers in range [0, 10^5].
    4. \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u5217\u8868 Aand B\uff0c\u5e76\u4e14 B \u662f A \u7684\u53d8\u4f4d\uff08\u5373 B \u662f\u7531 A \u4e2d\u7684\u5143\u7d20\u968f\u673a\u6392\u5217\u540e\u7ec4\u6210\u7684\u65b0\u5217\u8868\uff09\u3002

    \n\n

    \u6211\u4eec\u5e0c\u671b\u627e\u51fa\u4e00\u4e2a\u4ece A \u5230 B \u7684\u7d22\u5f15\u6620\u5c04 P \u3002\u4e00\u4e2a\u6620\u5c04 P[i] = j \u6307\u7684\u662f\u5217\u8868 A \u4e2d\u7684\u7b2c i \u4e2a\u5143\u7d20\u51fa\u73b0\u4e8e\u5217\u8868 B \u4e2d\u7684\u7b2c j \u4e2a\u5143\u7d20\u4e0a\u3002

    \n\n

    \u5217\u8868 A \u548c B \u53ef\u80fd\u51fa\u73b0\u91cd\u590d\u5143\u7d20\u3002\u5982\u679c\u6709\u591a\u4e8e\u4e00\u79cd\u7b54\u6848\uff0c\u8f93\u51fa\u4efb\u610f\u4e00\u79cd\u3002

    \n\n

    \u4f8b\u5982\uff0c\u7ed9\u5b9a

    \n\n
    A = [12, 28, 46, 32, 50]\nB = [50, 12, 32, 46, 28]\n
    \n\n

     

    \n\n

    \u9700\u8981\u8fd4\u56de

    \n\n
    [1, 4, 3, 2, 0]\n
    \n\n

    P[0] = 1 \uff0c\u56e0\u4e3a A \u4e2d\u7684\u7b2c 0 \u4e2a\u5143\u7d20\u51fa\u73b0\u4e8e B[1]\uff0c\u800c\u4e14 P[1] = 4 \u56e0\u4e3a A \u4e2d\u7b2c 1 \u4e2a\u5143\u7d20\u51fa\u73b0\u4e8e B[4]\uff0c\u4ee5\u6b64\u7c7b\u63a8\u3002

    \n\n

     

    \n\n

    \u6ce8\uff1a

    \n\n
      \n\t
    1. A, B \u6709\u76f8\u540c\u7684\u957f\u5ea6\uff0c\u8303\u56f4\u4e3a [1, 100]\u3002
    2. \n\t
    3. A[i], B[i] \u90fd\u662f\u8303\u56f4\u5728 [0, 10^5] \u7684\u6574\u6570\u3002
    4. \n
    \n\n

     

    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector anagramMappings(vector& nums1, vector& nums2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] anagramMappings(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def anagramMappings(self, nums1, nums2):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def anagramMappings(self, nums1: List[int], nums2: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* anagramMappings(int* nums1, int nums1Size, int* nums2, int nums2Size, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] AnagramMappings(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums1\n * @param {number[]} nums2\n * @return {number[]}\n */\nvar anagramMappings = function(nums1, nums2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums1\n# @param {Integer[]} nums2\n# @return {Integer[]}\ndef anagram_mappings(nums1, nums2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func anagramMappings(_ nums1: [Int], _ nums2: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func anagramMappings(nums1 []int, nums2 []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def anagramMappings(nums1: Array[Int], nums2: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun anagramMappings(nums1: IntArray, nums2: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn anagram_mappings(nums1: Vec, nums2: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums1\n * @param Integer[] $nums2\n * @return Integer[]\n */\n function anagramMappings($nums1, $nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function anagramMappings(nums1: number[], nums2: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (anagram-mappings nums1 nums2)\n (-> (listof exact-integer?) (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0760](https://leetcode-cn.com/problems/find-anagram-mappings)", "[\u627e\u51fa\u53d8\u4f4d\u6620\u5c04](/solution/0700-0799/0760.Find%20Anagram%20Mappings/README.md)", "`\u54c8\u5e0c\u8868`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0760](https://leetcode.com/problems/find-anagram-mappings)", "[Find Anagram Mappings](/solution/0700-0799/0760.Find%20Anagram%20Mappings/README_EN.md)", "`Hash Table`", "Easy", "\ud83d\udd12"]}, {"question_id": "0761", "frontend_question_id": "0759", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/employee-free-time", "url_en": "https://leetcode.com/problems/employee-free-time", "relative_path_cn": "/solution/0700-0799/0759.Employee%20Free%20Time/README.md", "relative_path_en": "/solution/0700-0799/0759.Employee%20Free%20Time/README_EN.md", "title_cn": "\u5458\u5de5\u7a7a\u95f2\u65f6\u95f4", "title_en": "Employee Free Time", "question_title_slug": "employee-free-time", "content_en": "

    We are given a list schedule of employees, which represents the working time for each employee.

    \r\n\r\n

    Each employee has a list of non-overlapping Intervals, and these intervals are in sorted order.

    \r\n\r\n

    Return the list of finite intervals representing common, positive-length free time for all employees, also in sorted order.

    \r\n\r\n

    (Even though we are representing Intervals in the form [x, y], the objects inside are Intervals, not lists or arrays. For example, schedule[0][0].start = 1, schedule[0][0].end = 2, and schedule[0][0][0] is not defined).  Also, we wouldn't include intervals like [5, 5] in our answer, as they have zero length.

    \r\n\n

     

    \n

    Example 1:

    \n\n
    \nInput: schedule = [[[1,2],[5,6]],[[1,3]],[[4,10]]]\nOutput: [[3,4]]\nExplanation: There are a total of three employees, and all common\nfree time intervals would be [-inf, 1], [3, 4], [10, inf].\nWe discard any intervals that contain inf as they aren't finite.\n
    \n\n

    Example 2:

    \n\n
    \nInput: schedule = [[[1,3],[6,7]],[[2,4]],[[2,5],[9,12]]]\nOutput: [[5,6],[7,9]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= schedule.length , schedule[i].length <= 50
    • \n\t
    • 0 <= schedule[i].start < schedule[i].end <= 10^8
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u5458\u5de5\u7684 schedule \u5217\u8868\uff0c\u8868\u793a\u6bcf\u4e2a\u5458\u5de5\u7684\u5de5\u4f5c\u65f6\u95f4\u3002

    \n\n

    \u6bcf\u4e2a\u5458\u5de5\u90fd\u6709\u4e00\u4e2a\u975e\u91cd\u53e0\u7684\u65f6\u95f4\u6bb5  Intervals \u5217\u8868\uff0c\u8fd9\u4e9b\u65f6\u95f4\u6bb5\u5df2\u7ecf\u6392\u597d\u5e8f\u3002

    \n\n

    \u8fd4\u56de\u8868\u793a \u6240\u6709 \u5458\u5de5\u7684 \u5171\u540c\uff0c\u6b63\u6570\u957f\u5ea6\u7684\u7a7a\u95f2\u65f6\u95f4 \u7684\u6709\u9650\u65f6\u95f4\u6bb5\u7684\u5217\u8868\uff0c\u540c\u6837\u9700\u8981\u6392\u597d\u5e8f\u3002

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aschedule = [[[1,2],[5,6]],[[1,3]],[[4,10]]]\n\u8f93\u51fa\uff1a[[3,4]]\n\u89e3\u91ca\uff1a\n\u5171\u6709 3 \u4e2a\u5458\u5de5\uff0c\u5e76\u4e14\u6240\u6709\u5171\u540c\u7684\n\u7a7a\u95f4\u65f6\u95f4\u6bb5\u662f [-inf, 1], [3, 4], [10, inf]\u3002\n\u6211\u4eec\u53bb\u9664\u6240\u6709\u5305\u542b inf \u7684\u65f6\u95f4\u6bb5\uff0c\u56e0\u4e3a\u5b83\u4eec\u4e0d\u662f\u6709\u9650\u7684\u65f6\u95f4\u6bb5\u3002\n
    \n\n

     

    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aschedule = [[[1,3],[6,7]],[[2,4]],[[2,5],[9,12]]]\n\u8f93\u51fa\uff1a[[5,6],[7,9]]\n
    \n\n

     

    \n\n

    \uff08\u5c3d\u7ba1\u6211\u4eec\u7528 [x, y] \u7684\u5f62\u5f0f\u8868\u793a Intervals \uff0c\u5185\u90e8\u7684\u5bf9\u8c61\u662f Intervals \u800c\u4e0d\u662f\u5217\u8868\u6216\u6570\u7ec4\u3002\u4f8b\u5982\uff0cschedule[0][0].start = 1, schedule[0][0].end = 2\uff0c\u5e76\u4e14 schedule[0][0][0] \u662f\u672a\u5b9a\u4e49\u7684\uff09

    \n\n

    \u800c\u4e14\uff0c\u7b54\u6848\u4e2d\u4e0d\u5305\u542b [5, 5] \uff0c\u56e0\u4e3a\u957f\u5ea6\u4e3a 0\u3002

    \n\n

     

    \n\n

    \u6ce8\uff1a

    \n\n
      \n\t
    1. schedule \u548c schedule[i] \u4e3a\u957f\u5ea6\u8303\u56f4\u5728 [1, 50]\u7684\u5217\u8868\u3002
    2. \n\t
    3. 0 <= schedule[i].start < schedule[i].end <= 10^8\u3002
    4. \n
    \n\n

    \u6ce8\uff1a\u8f93\u5165\u7c7b\u578b\u4e8e 2019 \u5e74 4 \u6708 15 \u65e5 \u6539\u53d8\u3002\u8bf7\u91cd\u7f6e\u4e3a\u9ed8\u8ba4\u4ee3\u7801\u7684\u5b9a\u4e49\u4ee5\u83b7\u53d6\u65b0\u65b9\u6cd5\u3002

    \n\n

     

    \n", "tags_en": ["Heap", "Greedy"], "tags_cn": ["\u5806", "\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n// Definition for an Interval.\nclass Interval {\npublic:\n int start;\n int end;\n\n Interval() {}\n\n Interval(int _start, int _end) {\n start = _start;\n end = _end;\n }\n};\n*/\n\nclass Solution {\npublic:\n vector employeeFreeTime(vector> schedule) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/*\n// Definition for an Interval.\nclass Interval {\n public int start;\n public int end;\n\n public Interval() {}\n\n public Interval(int _start, int _end) {\n start = _start;\n end = _end;\n }\n};\n*/\n\nclass Solution {\n public List employeeFreeTime(List> schedule) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "\"\"\"\n# Definition for an Interval.\nclass Interval(object):\n def __init__(self, start=None, end=None):\n self.start = start\n self.end = end\n\"\"\"\n\nclass Solution(object):\n def employeeFreeTime(self, schedule):\n \"\"\"\n :type schedule: [[Interval]]\n :rtype: [Interval]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "\"\"\"\n# Definition for an Interval.\nclass Interval:\n def __init__(self, start: int = None, end: int = None):\n self.start = start\n self.end = end\n\"\"\"\n\nclass Solution:\n def employeeFreeTime(self, schedule: '[[Interval]]') -> '[Interval]':\n ", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/*\n// Definition for an Interval.\npublic class Interval {\n public int start;\n public int end;\n\n public Interval(){}\n public Interval(int _start, int _end) {\n start = _start;\n end = _end;\n }\n}\n*/\n\npublic class Solution {\n public IList EmployeeFreeTime(IList> schedule) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // Definition for an Interval.\n * function Interval(start, end) {\n * this.start = start;\n * this.end = end;\n * };\n */\n\n/**\n * @param {Interval[][]} schedule\n * @return {Interval[]}\n */\nvar employeeFreeTime = function(schedule) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for an Interval.\n# class Interval\n# def initialize(start_, end_)\n# @start = start_\n# @end = end_\n# end\n# end\n\n# @param {List[List[Interval]]} schedule\n# @return {List[List[Interval]]}\ndef employeeFreeTime(schedule)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for an Interval.\n * public class Interval {\n * public var start: Int\n * public var end: Int\n * public init(_ start: Int, _ end: Int) {\n * self.start = start\n * self.end = end\n * }\n * }\n */\n\nclass Solution {\n func employeeFreeTime(_ schedule: [[Interval]]) -> [Interval] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for an Interval.\n * type Interval struct {\n * Start int\n * End int\n * }\n */\n\nfunc employeeFreeTime(schedule [][]*Interval) []*Interval {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for an Interval.\n * class Interval(var _start: Int, var _end: Int) {\n * var start: Int = _start\n * var end: Int = _end\n * }\n */\n\nobject Solution {\n def employeeFreeTime(schedule: List[List[Interval]]): List[Interval] = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/*\n *\t// Definition for an Interval.\n *\tclass Interval {\n *\t\tvar start:Int = 0\n *\t\tvar end:Int = 0\n *\t\n *\t\tconstructor(_start:Int, _end:Int) {\n *\t\t\tstart = _start\n *\t\t\tend = _end\n *\t\t}\n *\t}\n */\n\nclass Solution {\n fun employeeFreeTime(schedule: ArrayList>): ArrayList {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "/*\n// Definition for an Interval.\n#[derive(PartialEq, Eq, Clone, Debug)]\nstruct Interval {\n pub start:i32,\n pub end:i32\n}\n\nimpl Interval {\n #[inline]\n fn new(start:i32, end:i32) -> Self{\n Interval {\n start,\n end\n }\n }\n}\n*/\n\nimpl Solution {\n pub fn employee_free_time(schedule: Vec>) -> Vec {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for an Interval.\n * class Interval {\n * public $start = null;\n * public $end = null;\n * function __construct($start, $end) {\n * $this->start = $start;\n * $this->end = $end;\n * }\n * }\n */\n\nclass Solution {\n /**\n * @param Interval[][] $schedule\n * @return Interval[]\n */\n function employeeFreeTime($schedule) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * // Definition for an Interval.\n * class Interval {\n * start: number;\n * end: number;\n * constructor(strat: number, end: number) {\n * this.start = start;\n * this.end = end;\n * }\n * }\n */\n\nfunction employeeFreeTime(schedule: Interval[][]): Interval[] {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0759](https://leetcode-cn.com/problems/employee-free-time)", "[\u5458\u5de5\u7a7a\u95f2\u65f6\u95f4](/solution/0700-0799/0759.Employee%20Free%20Time/README.md)", "`\u5806`,`\u8d2a\u5fc3\u7b97\u6cd5`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0759](https://leetcode.com/problems/employee-free-time)", "[Employee Free Time](/solution/0700-0799/0759.Employee%20Free%20Time/README_EN.md)", "`Heap`,`Greedy`", "Hard", "\ud83d\udd12"]}, {"question_id": "0760", "frontend_question_id": "0758", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/bold-words-in-string", "url_en": "https://leetcode.com/problems/bold-words-in-string", "relative_path_cn": "/solution/0700-0799/0758.Bold%20Words%20in%20String/README.md", "relative_path_en": "/solution/0700-0799/0758.Bold%20Words%20in%20String/README_EN.md", "title_cn": "\u5b57\u7b26\u4e32\u4e2d\u7684\u52a0\u7c97\u5355\u8bcd", "title_en": "Bold Words in String", "question_title_slug": "bold-words-in-string", "content_en": "

    Given an array of keywords words and a string s, make all appearances of all keywords words[i] in s bold. Any letters between <b> and </b> tags become bold.

    \n\n

    Return s after adding the bold tags. The returned string should use the least number of tags possible, and the tags should form a valid combination.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: words = ["ab","bc"], s = "aabcd"\nOutput: "a<b>abc</b>d"\nExplanation: Note that returning "a<b>a<b>b</b>c</b>d" would use more tags, so it is incorrect.\n
    \n\n

    Example 2:

    \n\n
    \nInput: words = ["ab","cb"], s = "aabcd"\nOutput: "a<b>ab</b>cd"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 500
    • \n\t
    • 0 <= words.length <= 50
    • \n\t
    • 1 <= words[i].length <= 10
    • \n\t
    • s and words[i] consist of lowercase English letters.
    • \n
    \n\n

     

    \n

    Note: This question is the same as 616: https://leetcode.com/problems/add-bold-tag-in-string/

    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5173\u952e\u8bcd\u96c6\u5408\u00a0words \u548c\u4e00\u4e2a\u5b57\u7b26\u4e32\u00a0S\uff0c\u5c06\u6240\u6709 S \u4e2d\u51fa\u73b0\u7684\u5173\u952e\u8bcd\u52a0\u7c97\u3002\u6240\u6709\u5728\u6807\u7b7e \u548c\u00a0\u00a0\u4e2d\u7684\u5b57\u6bcd\u90fd\u4f1a\u52a0\u7c97\u3002

    \n\n

    \u8fd4\u56de\u7684\u5b57\u7b26\u4e32\u9700\u8981\u4f7f\u7528\u5c3d\u53ef\u80fd\u5c11\u7684\u6807\u7b7e\uff0c\u5f53\u7136\u6807\u7b7e\u5e94\u5f62\u6210\u6709\u6548\u7684\u7ec4\u5408\u3002

    \n\n

    \u4f8b\u5982\uff0c\u7ed9\u5b9a\u00a0words = [\"ab\", \"bc\"] \u548c\u00a0S = \"aabcd\"\uff0c\u9700\u8981\u8fd4\u56de\u00a0\"aabcd\"\u3002\u6ce8\u610f\u8fd4\u56de\u00a0\"aabcd\"\u00a0\u4f1a\u4f7f\u7528\u66f4\u591a\u7684\u6807\u7b7e\uff0c\u56e0\u6b64\u662f\u9519\u8bef\u7684\u3002

    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • words \u957f\u5ea6\u7684\u8303\u56f4\u4e3a\u00a0[0, 50]\u3002
    • \n\t
    • words[i] \u957f\u5ea6\u7684\u8303\u56f4\u4e3a\u00a0[1, 10]\u3002
    • \n\t
    • S \u957f\u5ea6\u7684\u8303\u56f4\u4e3a\u00a0[0, 500]\u3002
    • \n\t
    • \u6240\u6709\u00a0words[i]\u00a0\u548c\u00a0S\u00a0\u4e2d\u7684\u5b57\u7b26\u90fd\u4e3a\u5c0f\u5199\u5b57\u6bcd\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u6ce8\uff1a\u6b64\u9898\u4e0e\u300c616 - \u7ed9\u5b57\u7b26\u4e32\u6dfb\u52a0\u52a0\u7c97\u6807\u7b7e\u300d\u76f8\u540c - https://leetcode-cn.com/problems/add-bold-tag-in-string/

    \n\n

    \u00a0

    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string boldWords(vector& words, string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String boldWords(String[] words, String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def boldWords(self, words, s):\n \"\"\"\n :type words: List[str]\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def boldWords(self, words: List[str], s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * boldWords(char ** words, int wordsSize, char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string BoldWords(string[] words, string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @param {string} s\n * @return {string}\n */\nvar boldWords = function(words, s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @param {String} s\n# @return {String}\ndef bold_words(words, s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func boldWords(_ words: [String], _ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func boldWords(words []string, s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def boldWords(words: Array[String], s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun boldWords(words: Array, s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn bold_words(words: Vec, s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @param String $s\n * @return String\n */\n function boldWords($words, $s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function boldWords(words: string[], s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (bold-words words s)\n (-> (listof string?) string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0758](https://leetcode-cn.com/problems/bold-words-in-string)", "[\u5b57\u7b26\u4e32\u4e2d\u7684\u52a0\u7c97\u5355\u8bcd](/solution/0700-0799/0758.Bold%20Words%20in%20String/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0758](https://leetcode.com/problems/bold-words-in-string)", "[Bold Words in String](/solution/0700-0799/0758.Bold%20Words%20in%20String/README_EN.md)", "`String`", "Medium", "\ud83d\udd12"]}, {"question_id": "0759", "frontend_question_id": "0757", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/set-intersection-size-at-least-two", "url_en": "https://leetcode.com/problems/set-intersection-size-at-least-two", "relative_path_cn": "/solution/0700-0799/0757.Set%20Intersection%20Size%20At%20Least%20Two/README.md", "relative_path_en": "/solution/0700-0799/0757.Set%20Intersection%20Size%20At%20Least%20Two/README_EN.md", "title_cn": "\u8bbe\u7f6e\u4ea4\u96c6\u5927\u5c0f\u81f3\u5c11\u4e3a2", "title_en": "Set Intersection Size At Least Two", "question_title_slug": "set-intersection-size-at-least-two", "content_en": "

    An integer interval [a, b] (for integers a < b) is a set of all consecutive integers from a to b, including a and b.

    \n\n

    Find the minimum size of a set S such that for every integer interval A in intervals, the intersection of S with A has a size of at least two.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: intervals = [[1,3],[1,4],[2,5],[3,5]]\nOutput: 3\nExplanation: Consider the set S = {2, 3, 4}.  For each interval, there are at least 2 elements from S in the interval.\nAlso, there isn't a smaller size set that fulfills the above condition.\nThus, we output the size of this set, which is 3.\n
    \n\n

    Example 2:

    \n\n
    \nInput: intervals = [[1,2],[2,3],[2,4],[4,5]]\nOutput: 5\nExplanation: An example of a minimum sized set is {1, 2, 3, 4, 5}.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= intervals.length <= 3000
    • \n\t
    • intervals[i].length == 2
    • \n\t
    • 0 <= ai < bi <= 108
    • \n
    \n", "content_cn": "

    \u4e00\u4e2a\u6574\u6570\u533a\u95f4 [a, b]  ( a < b ) \u4ee3\u8868\u7740\u4ece a \u5230 b \u7684\u6240\u6709\u8fde\u7eed\u6574\u6570\uff0c\u5305\u62ec a \u548c b\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u7ec4\u6574\u6570\u533a\u95f4intervals\uff0c\u8bf7\u627e\u5230\u4e00\u4e2a\u6700\u5c0f\u7684\u96c6\u5408 S\uff0c\u4f7f\u5f97 S \u91cc\u7684\u5143\u7d20\u4e0e\u533a\u95f4intervals\u4e2d\u7684\u6bcf\u4e00\u4e2a\u6574\u6570\u533a\u95f4\u90fd\u81f3\u5c11\u67092\u4e2a\u5143\u7d20\u76f8\u4ea4\u3002

    \n\n

    \u8f93\u51fa\u8fd9\u4e2a\u6700\u5c0f\u96c6\u5408S\u7684\u5927\u5c0f\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: intervals = [[1, 3], [1, 4], [2, 5], [3, 5]]\n\u8f93\u51fa: 3\n\u89e3\u91ca:\n\u8003\u8651\u96c6\u5408 S = {2, 3, 4}. S\u4e0eintervals\u4e2d\u7684\u56db\u4e2a\u533a\u95f4\u90fd\u6709\u81f3\u5c112\u4e2a\u76f8\u4ea4\u7684\u5143\u7d20\u3002\n\u4e14\u8fd9\u662fS\u6700\u5c0f\u7684\u60c5\u51b5\uff0c\u6545\u6211\u4eec\u8f93\u51fa3\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: intervals = [[1, 2], [2, 3], [2, 4], [4, 5]]\n\u8f93\u51fa: 5\n\u89e3\u91ca:\n\u6700\u5c0f\u7684\u96c6\u5408S = {1, 2, 3, 4, 5}.\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. intervals \u7684\u957f\u5ea6\u8303\u56f4\u4e3a[1, 3000]\u3002
    2. \n\t
    3. intervals[i] \u957f\u5ea6\u4e3a 2\uff0c\u5206\u522b\u4ee3\u8868\u5de6\u3001\u53f3\u8fb9\u754c\u3002
    4. \n\t
    5. intervals[i][j] \u7684\u503c\u662f [0, 10^8]\u8303\u56f4\u5185\u7684\u6574\u6570\u3002
    6. \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int intersectionSizeTwo(vector>& intervals) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int intersectionSizeTwo(int[][] intervals) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def intersectionSizeTwo(self, intervals):\n \"\"\"\n :type intervals: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def intersectionSizeTwo(self, intervals: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint intersectionSizeTwo(int** intervals, int intervalsSize, int* intervalsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int IntersectionSizeTwo(int[][] intervals) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} intervals\n * @return {number}\n */\nvar intersectionSizeTwo = function(intervals) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} intervals\n# @return {Integer}\ndef intersection_size_two(intervals)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func intersectionSizeTwo(_ intervals: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func intersectionSizeTwo(intervals [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def intersectionSizeTwo(intervals: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun intersectionSizeTwo(intervals: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn intersection_size_two(intervals: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $intervals\n * @return Integer\n */\n function intersectionSizeTwo($intervals) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function intersectionSizeTwo(intervals: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (intersection-size-two intervals)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0757](https://leetcode-cn.com/problems/set-intersection-size-at-least-two)", "[\u8bbe\u7f6e\u4ea4\u96c6\u5927\u5c0f\u81f3\u5c11\u4e3a2](/solution/0700-0799/0757.Set%20Intersection%20Size%20At%20Least%20Two/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[0757](https://leetcode.com/problems/set-intersection-size-at-least-two)", "[Set Intersection Size At Least Two](/solution/0700-0799/0757.Set%20Intersection%20Size%20At%20Least%20Two/README_EN.md)", "`Greedy`", "Hard", ""]}, {"question_id": "0758", "frontend_question_id": "0426", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/convert-binary-search-tree-to-sorted-doubly-linked-list", "url_en": "https://leetcode.com/problems/convert-binary-search-tree-to-sorted-doubly-linked-list", "relative_path_cn": "/solution/0400-0499/0426.Convert%20Binary%20Search%20Tree%20to%20Sorted%20Doubly%20Linked%20List/README.md", "relative_path_en": "/solution/0400-0499/0426.Convert%20Binary%20Search%20Tree%20to%20Sorted%20Doubly%20Linked%20List/README_EN.md", "title_cn": "\u5c06\u4e8c\u53c9\u641c\u7d22\u6811\u8f6c\u5316\u4e3a\u6392\u5e8f\u7684\u53cc\u5411\u94fe\u8868", "title_en": "Convert Binary Search Tree to Sorted Doubly Linked List", "question_title_slug": "convert-binary-search-tree-to-sorted-doubly-linked-list", "content_en": "

    Convert a Binary Search Tree to a sorted Circular Doubly-Linked List in place.

    \n\n

    You can think of the left and right pointers as synonymous to the predecessor and successor pointers in a doubly-linked list. For a circular doubly linked list, the predecessor of the first element is the last element, and the successor of the last element is the first element.

    \n\n

    We want to do the transformation in place. After the transformation, the left pointer of the tree node should point to its predecessor, and the right pointer should point to its successor. You should return the pointer to the smallest element of the linked list.

    \n\n

     

    \n

    Example 1:

    \n\n

    \n\n
    \nInput: root = [4,2,5,1,3]\n\n\nOutput: [1,2,3,4,5]\n\nExplanation: The figure below shows the transformed BST. The solid line indicates the successor relationship, while the dashed line means the predecessor relationship.\n\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = [2,1,3]\nOutput: [1,2,3]\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = []\nOutput: []\nExplanation: Input is an empty tree. Output is also an empty Linked List.\n
    \n\n

    Example 4:

    \n\n
    \nInput: root = [1]\nOutput: [1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [0, 2000].
    • \n\t
    • -1000 <= Node.val <= 1000
    • \n\t
    • All the values of the tree are unique.
    • \n
    \n", "content_cn": "

    \u5c06\u4e00\u4e2a \u4e8c\u53c9\u641c\u7d22\u6811 \u5c31\u5730\u8f6c\u5316\u4e3a\u4e00\u4e2a \u5df2\u6392\u5e8f\u7684\u53cc\u5411\u5faa\u73af\u94fe\u8868 \u3002

    \n\n

    \u5bf9\u4e8e\u53cc\u5411\u5faa\u73af\u5217\u8868\uff0c\u4f60\u53ef\u4ee5\u5c06\u5de6\u53f3\u5b69\u5b50\u6307\u9488\u4f5c\u4e3a\u53cc\u5411\u5faa\u73af\u94fe\u8868\u7684\u524d\u9a71\u548c\u540e\u7ee7\u6307\u9488\uff0c\u7b2c\u4e00\u4e2a\u8282\u70b9\u7684\u524d\u9a71\u662f\u6700\u540e\u4e00\u4e2a\u8282\u70b9\uff0c\u6700\u540e\u4e00\u4e2a\u8282\u70b9\u7684\u540e\u7ee7\u662f\u7b2c\u4e00\u4e2a\u8282\u70b9\u3002

    \n\n

    \u7279\u522b\u5730\uff0c\u6211\u4eec\u5e0c\u671b\u53ef\u4ee5 \u5c31\u5730 \u5b8c\u6210\u8f6c\u6362\u64cd\u4f5c\u3002\u5f53\u8f6c\u5316\u5b8c\u6210\u4ee5\u540e\uff0c\u6811\u4e2d\u8282\u70b9\u7684\u5de6\u6307\u9488\u9700\u8981\u6307\u5411\u524d\u9a71\uff0c\u6811\u4e2d\u8282\u70b9\u7684\u53f3\u6307\u9488\u9700\u8981\u6307\u5411\u540e\u7ee7\u3002\u8fd8\u9700\u8981\u8fd4\u56de\u94fe\u8868\u4e2d\u6700\u5c0f\u5143\u7d20\u7684\u6307\u9488\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [4,2,5,1,3] \n\n\n\u8f93\u51fa\uff1a[1,2,3,4,5]\n\n\u89e3\u91ca\uff1a\u4e0b\u56fe\u663e\u793a\u4e86\u8f6c\u5316\u540e\u7684\u4e8c\u53c9\u641c\u7d22\u6811\uff0c\u5b9e\u7ebf\u8868\u793a\u540e\u7ee7\u5173\u7cfb\uff0c\u865a\u7ebf\u8868\u793a\u524d\u9a71\u5173\u7cfb\u3002\n\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [2,1,3]\n\u8f93\u51fa\uff1a[1,2,3]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = []\n\u8f93\u51fa\uff1a[]\n\u89e3\u91ca\uff1a\u8f93\u5165\u662f\u7a7a\u6811\uff0c\u6240\u4ee5\u8f93\u51fa\u4e5f\u662f\u7a7a\u94fe\u8868\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [1]\n\u8f93\u51fa\uff1a[1]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • -1000 <= Node.val <= 1000
    • \n\t
    • Node.left.val < Node.val < Node.right.val
    • \n\t
    • Node.val \u7684\u6240\u6709\u503c\u90fd\u662f\u72ec\u4e00\u65e0\u4e8c\u7684
    • \n\t
    • 0 <= Number of Nodes <= 2000
    • \n
    \n", "tags_en": ["Tree", "Linked List", "Divide and Conquer"], "tags_cn": ["\u6811", "\u94fe\u8868", "\u5206\u6cbb\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n\n Node() {}\n\n Node(int _val) {\n val = _val;\n left = NULL;\n right = NULL;\n }\n\n Node(int _val, Node* _left, Node* _right) {\n val = _val;\n left = _left;\n right = _right;\n }\n};\n*/\n\nclass Solution {\npublic:\n Node* treeToDoublyList(Node* root) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/*\n// Definition for a Node.\nclass Node {\n public int val;\n public Node left;\n public Node right;\n\n public Node() {}\n\n public Node(int _val) {\n val = _val;\n }\n\n public Node(int _val,Node _left,Node _right) {\n val = _val;\n left = _left;\n right = _right;\n }\n};\n*/\n\nclass Solution {\n public Node treeToDoublyList(Node root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "\"\"\"\n# Definition for a Node.\nclass Node(object):\n def __init__(self, val, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\"\"\"\n\nclass Solution(object):\n def treeToDoublyList(self, root):\n \"\"\"\n :type root: Node\n :rtype: Node\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "\"\"\"\n# Definition for a Node.\nclass Node:\n def __init__(self, val, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\"\"\"\n\nclass Solution:\n def treeToDoublyList(self, root: 'Node') -> 'Node':\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/*\n// Definition for a Node.\nstruct Node {\n int val;\n struct Node* left;\n struct Node* right;\n};\n*/\n\nstruct Node* treeToDoublyList(struct Node *root) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/*\n// Definition for a Node.\npublic class Node {\n public int val;\n public Node left;\n public Node right;\n\n public Node() {}\n\n public Node(int _val) {\n val = _val;\n left = null;\n right = null;\n }\n\n public Node(int _val,Node _left,Node _right) {\n val = _val;\n left = _left;\n right = _right;\n }\n}\n*/\n\npublic class Solution {\n public Node TreeToDoublyList(Node root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // Definition for a Node.\n * function Node(val, left, right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * };\n */\n\n/**\n * @param {Node} root\n * @return {Node}\n */\nvar treeToDoublyList = function(root) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a Node.\n# class Node\n# attr_accessor :val, :left, :right\n# def initialize(val=0)\n# @val = val\n# @left, @right = nil, nil\n# end\n# end\n\n# @param {Node} root\n# @return {Node}\ndef treeToDoublyList(root)\n\t\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a Node.\n * public class Node {\n * public var val: Int\n * public var left: Node?\n * public var right: Node?\n * public init(_ val: Int) {\n * self.val = val\n * self.left = nil\n * self.right = nil\n * }\n * }\n */\n\nclass Solution {\n func treeToDoublyList(_ root: Node?) -> Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a Node.\n * type Node struct {\n * Val int\n * Left *Node\n * Right *Node\n * }\n */\n\nfunc treeToDoublyList(root *Node) *Node {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a Node.\n * class Node(var _value: Int) {\n * var value: Int = _value\n * var left: Node = null\n * var right: Node = null\n * }\n */\n\nobject Solution {\n def treeToDoublyList(root: Node): Node = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a Node.\n * class Node(var `val`: Int) {\n * var left: Node? = null\n * var right: Node? = null\n * }\n */\n\nclass Solution {\n fun treeToDoublyList(root:Node?): Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a Node.\n * class Node {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0) {\n * $this->val = $val;\n * $this->left = null;\n * $this->right = null;\n * }\n * }\n */\n\nclass Solution {\n /**\n * @param Node $root\n * @return Node\n */\n function treeToDoublyList($root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class Node {\n * val: number\n * left: Node | null\n * right: Node | null\n * constructor(val?: number, left?: Node | null, right?: Node | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction treeToDoublyList(root: Node | null): Node | null {\n\t\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0426](https://leetcode-cn.com/problems/convert-binary-search-tree-to-sorted-doubly-linked-list)", "[\u5c06\u4e8c\u53c9\u641c\u7d22\u6811\u8f6c\u5316\u4e3a\u6392\u5e8f\u7684\u53cc\u5411\u94fe\u8868](/solution/0400-0499/0426.Convert%20Binary%20Search%20Tree%20to%20Sorted%20Doubly%20Linked%20List/README.md)", "`\u6811`,`\u94fe\u8868`,`\u5206\u6cbb\u7b97\u6cd5`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0426](https://leetcode.com/problems/convert-binary-search-tree-to-sorted-doubly-linked-list)", "[Convert Binary Search Tree to Sorted Doubly Linked List](/solution/0400-0499/0426.Convert%20Binary%20Search%20Tree%20to%20Sorted%20Doubly%20Linked%20List/README_EN.md)", "`Tree`,`Linked List`,`Divide and Conquer`", "Medium", "\ud83d\udd12"]}, {"question_id": "0757", "frontend_question_id": "0756", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/pyramid-transition-matrix", "url_en": "https://leetcode.com/problems/pyramid-transition-matrix", "relative_path_cn": "/solution/0700-0799/0756.Pyramid%20Transition%20Matrix/README.md", "relative_path_en": "/solution/0700-0799/0756.Pyramid%20Transition%20Matrix/README_EN.md", "title_cn": "\u91d1\u5b57\u5854\u8f6c\u6362\u77e9\u9635", "title_en": "Pyramid Transition Matrix", "question_title_slug": "pyramid-transition-matrix", "content_en": "

    We are stacking blocks to form a pyramid. Each block has a color which is a one-letter string.

    \n\n

    We are allowed to place any color block C on top of two adjacent blocks of colors A and B, if and only if ABC is an allowed triple.

    \n\n

    We start with a bottom row of bottom, represented as a single string. We also start with a list of allowed triples allowed. Each allowed triple is represented as a string of length 3.

    \n\n

    Return true if we can build the pyramid all the way to the top, otherwise false.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: bottom = "BCD", allowed = ["BCG","CDE","GEA","FFF"]\nOutput: true\nExplanation:\nWe can stack the pyramid like this:\n    A\n   / \\\n  G   E\n / \\ / \\\nB   C   D\n\nWe are allowed to place G on top of B and C because BCG is an allowed triple.  Similarly, we can place E on top of C and D, then A on top of G and E.\n
    \n\n

    Example 2:

    \n\n
    \nInput: bottom = "AABA", allowed = ["AAA","AAB","ABA","ABB","BAC"]\nOutput: false\nExplanation:\nWe cannot stack the pyramid to the top.\nNote that there could be allowed triples (A, B, C) and (A, B, D) with C != D.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= bottom.length <= 8
    • \n\t
    • 0 <= allowed.length <= 200
    • \n\t
    • allowed[i].length == 3
    • \n\t
    • The letters in all input strings are from the set {'A', 'B', 'C', 'D', 'E', 'F', 'G'}.
    • \n
    \n", "content_cn": "

    \u73b0\u5728\uff0c\u6211\u4eec\u7528\u4e00\u4e9b\u65b9\u5757\u6765\u5806\u780c\u4e00\u4e2a\u91d1\u5b57\u5854\u3002 \u6bcf\u4e2a\u65b9\u5757\u7528\u4ec5\u5305\u542b\u4e00\u4e2a\u5b57\u6bcd\u7684\u5b57\u7b26\u4e32\u8868\u793a\u3002

    \n\n

    \u4f7f\u7528\u4e09\u5143\u7ec4\u8868\u793a\u91d1\u5b57\u5854\u7684\u5806\u780c\u89c4\u5219\u5982\u4e0b\uff1a

    \n\n

    \u5bf9\u4e8e\u4e09\u5143\u7ec4 ABC \uff0cC \u4e3a\u9876\u5c42\u65b9\u5757\uff0c\u65b9\u5757 A \u3001B \u5206\u522b\u4f5c\u4e3a\u65b9\u5757 C \u4e0b\u4e00\u5c42\u7684\u7684\u5de6\u3001\u53f3\u5b50\u5757\u3002\u5f53\u4e14\u4ec5\u5f53 ABC \u662f\u88ab\u5141\u8bb8\u7684\u4e09\u5143\u7ec4\uff0c\u6211\u4eec\u624d\u53ef\u4ee5\u5c06\u5176\u5806\u780c\u4e0a\u3002

    \n\n

    \u521d\u59cb\u65f6\uff0c\u7ed9\u5b9a\u91d1\u5b57\u5854\u7684\u57fa\u5c42\u00a0bottom\uff0c\u7528\u4e00\u4e2a\u5b57\u7b26\u4e32\u8868\u793a\u3002\u4e00\u4e2a\u5141\u8bb8\u7684\u4e09\u5143\u7ec4\u5217\u8868\u00a0allowed\uff0c\u6bcf\u4e2a\u4e09\u5143\u7ec4\u7528\u4e00\u4e2a\u957f\u5ea6\u4e3a 3 \u7684\u5b57\u7b26\u4e32\u8868\u793a\u3002

    \n\n

    \u5982\u679c\u53ef\u4ee5\u7531\u57fa\u5c42\u4e00\u76f4\u5806\u5230\u5854\u5c16\u5c31\u8fd4\u56de true \uff0c\u5426\u5219\u8fd4\u56de false \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1abottom = \"BCD\", allowed = [\"BCG\", \"CDE\", \"GEA\", \"FFF\"]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\n\u53ef\u4ee5\u5806\u780c\u6210\u8fd9\u6837\u7684\u91d1\u5b57\u5854:\n    A\n   / \\\n  G   E\n / \\ / \\\nB   C   D\n\n\u56e0\u4e3a\u7b26\u5408 BCG\u3001CDE \u548c GEA \u4e09\u79cd\u89c4\u5219\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1abottom = \"AABA\", allowed = [\"AAA\", \"AAB\", \"ABA\", \"ABB\", \"BAC\"]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\n\u65e0\u6cd5\u4e00\u76f4\u5806\u5230\u5854\u5c16\u3002\n\u6ce8\u610f, \u5141\u8bb8\u5b58\u5728\u50cf ABC \u548c ABD \u8fd9\u6837\u7684\u4e09\u5143\u7ec4\uff0c\u5176\u4e2d C != D\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • bottom \u7684\u957f\u5ea6\u8303\u56f4\u5728\u00a0[2, 8]\u3002
    • \n\t
    • allowed \u7684\u957f\u5ea6\u8303\u56f4\u5728[0, 200]\u3002
    • \n\t
    • \u65b9\u5757\u7684\u6807\u8bb0\u5b57\u6bcd\u8303\u56f4\u4e3a{'A', 'B', 'C', 'D', 'E', 'F', 'G'}\u3002
    • \n
    \n", "tags_en": ["Bit Manipulation", "Depth-first Search"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool pyramidTransition(string bottom, vector& allowed) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean pyramidTransition(String bottom, List allowed) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def pyramidTransition(self, bottom, allowed):\n \"\"\"\n :type bottom: str\n :type allowed: List[str]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def pyramidTransition(self, bottom: str, allowed: List[str]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool pyramidTransition(char * bottom, char ** allowed, int allowedSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool PyramidTransition(string bottom, IList allowed) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} bottom\n * @param {string[]} allowed\n * @return {boolean}\n */\nvar pyramidTransition = function(bottom, allowed) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} bottom\n# @param {String[]} allowed\n# @return {Boolean}\ndef pyramid_transition(bottom, allowed)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func pyramidTransition(_ bottom: String, _ allowed: [String]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func pyramidTransition(bottom string, allowed []string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def pyramidTransition(bottom: String, allowed: List[String]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun pyramidTransition(bottom: String, allowed: List): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn pyramid_transition(bottom: String, allowed: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $bottom\n * @param String[] $allowed\n * @return Boolean\n */\n function pyramidTransition($bottom, $allowed) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function pyramidTransition(bottom: string, allowed: string[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (pyramid-transition bottom allowed)\n (-> string? (listof string?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0756](https://leetcode-cn.com/problems/pyramid-transition-matrix)", "[\u91d1\u5b57\u5854\u8f6c\u6362\u77e9\u9635](/solution/0700-0799/0756.Pyramid%20Transition%20Matrix/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0756](https://leetcode.com/problems/pyramid-transition-matrix)", "[Pyramid Transition Matrix](/solution/0700-0799/0756.Pyramid%20Transition%20Matrix/README_EN.md)", "`Bit Manipulation`,`Depth-first Search`", "Medium", ""]}, {"question_id": "0756", "frontend_question_id": "0755", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/pour-water", "url_en": "https://leetcode.com/problems/pour-water", "relative_path_cn": "/solution/0700-0799/0755.Pour%20Water/README.md", "relative_path_en": "/solution/0700-0799/0755.Pour%20Water/README_EN.md", "title_cn": "\u5012\u6c34", "title_en": "Pour Water", "question_title_slug": "pour-water", "content_en": "

    We are given an elevation map, heights[i] representing the height of the terrain at that index. The width at each index is 1. After volume units of water fall at index k, how much water is at each index?

    \n\n

    Water first drops at index k and rests on top of the highest terrain or water at that index. Then, it flows according to the following rules:

    \n\n
      \n\t
    • If the droplet would eventually fall by moving left, then move left.
    • \n\t
    • Otherwise, if the droplet would eventually fall by moving right, then move right.
    • \n\t
    • Otherwise, rise at it's current position.
    • \n
    \n\n

    Here, "eventually fall" means that the droplet will eventually be at a lower level if it moves in that direction. Also, "level" means the height of the terrain plus any water in that column.

    \n\n

    We can assume there's infinitely high terrain on the two sides out of bounds of the array. Also, there could not be partial water being spread out evenly on more than 1 grid block - each unit of water has to be in exactly one block.

    \n\n

    Example 1:

    \n\n
    \nInput: heights = [2,1,1,2,1,2,2], volume = 4, k = 3\nOutput: [2,2,2,3,2,2,2]\nExplanation:\n#       #\n#       #\n##  # ###\n#########\n 0123456    <- index\n\nThe first drop of water lands at index k = 3:\n\n#       #\n#   w   #\n##  # ###\n#########\n 0123456    \n\nWhen moving left or right, the water can only move to the same level or a lower level.\n(By level, we mean the total height of the terrain plus any water in that column.)\nSince moving left will eventually make it fall, it moves left.\n(A droplet "made to fall" means go to a lower height than it was at previously.)\n\n#       #\n#       #\n## w# ###\n#########\n 0123456    \n\nSince moving left will not make it fall, it stays in place.  The next droplet falls:\n\n#       #\n#   w   #\n## w# ###\n#########\n 0123456  \n\nSince the new droplet moving left will eventually make it fall, it moves left.\nNotice that the droplet still preferred to move left,\neven though it could move right (and moving right makes it fall quicker.)\n\n#       #\n#  w    #\n## w# ###\n#########\n 0123456  \n\n#       #\n#       #\n##ww# ###\n#########\n 0123456  \n\nAfter those steps, the third droplet falls.\nSince moving left would not eventually make it fall, it tries to move right.\nSince moving right would eventually make it fall, it moves right.\n\n#       #\n#   w   #\n##ww# ###\n#########\n 0123456  \n\n#       #\n#       #\n##ww#w###\n#########\n 0123456  \n\nFinally, the fourth droplet falls.\nSince moving left would not eventually make it fall, it tries to move right.\nSince moving right would not eventually make it fall, it stays in place:\n\n#       #\n#   w   #\n##ww#w###\n#########\n 0123456  \n\nThe final answer is [2,2,2,3,2,2,2]:\n\n    #    \n ####### \n ####### \n 0123456 \n
    \n\n

    Example 2:

    \n\n
    \nInput: heights = [1,2,3,4], volume = 2, k = 2\nOutput: [2,3,3,4]\nExplanation:\nThe last droplet settles at index 1, since moving further left would not cause it to eventually fall to a lower height.\n
    \n\n

    Example 3:

    \n\n
    \nInput: heights = [3,1,3], volume = 5, k = 1\nOutput: [4,4,4]\n
    \n\n

    Note:

    \n\n
      \n\t
    1. heights will have length in [1, 100] and contain integers in [0, 99].
    2. \n\t
    3. volume will be in range [0, 2000].
    4. \n\t
    5. k will be in range [0, heights.length - 1].
    6. \n
    \n\n

     

    \n", "content_cn": "

    \u7ed9\u51fa\u4e00\u4e2a\u5730\u5f62\u9ad8\u5ea6\u56fe\uff0c heights[i] \u8868\u793a\u8be5\u7d22\u5f15\u5904\u7684\u9ad8\u5ea6\u3002\u6bcf\u4e2a\u7d22\u5f15\u7684\u5bbd\u5ea6\u4e3a 1\u3002\u5728 V \u4e2a\u5355\u4f4d\u7684\u6c34\u843d\u5728\u7d22\u5f15 K \u5904\u4ee5\u540e\uff0c\u6bcf\u4e2a\u7d22\u5f15\u4f4d\u7f6e\u6709\u591a\u5c11\u6c34\uff1f

    \n\n

    \u6c34\u6700\u5148\u4f1a\u5728\u7d22\u5f15 K \u5904\u4e0b\u964d\u5e76\u4e14\u843d\u5728\u8be5\u7d22\u5f15\u4f4d\u7f6e\u7684\u6700\u9ad8\u5730\u5f62\u6216\u6c34\u9762\u4e4b\u4e0a\u3002\u7136\u540e\u6309\u5982\u4e0b\u65b9\u5f0f\u6d41\u52a8\uff1a

    \n\n
      \n\t
    • \u5982\u679c\u6db2\u6ef4\u6700\u7ec8\u53ef\u4ee5\u901a\u8fc7\u5411\u5de6\u6d41\u52a8\u800c\u4e0b\u964d\uff0c\u5219\u5411\u5de6\u6d41\u52a8\u3002
    • \n\t
    • \u5426\u5219\uff0c\u5982\u679c\u6db2\u6ef4\u6700\u7ec8\u53ef\u4ee5\u901a\u8fc7\u5411\u53f3\u6d41\u52a8\u800c\u4e0b\u964d\uff0c\u5219\u5411\u53f3\u6d41\u52a8\u3002
    • \n\t
    • \u5426\u5219\uff0c\u5728\u5f53\u524d\u7684\u4f4d\u7f6e\u4e0a\u5347\u3002
    • \n\t
    • \u8fd9\u91cc\uff0c\u201c\u6700\u7ec8\u4e0b\u964d\u201d \u7684\u610f\u601d\u662f\u6db2\u6ef4\u5982\u679c\u6309\u6b64\u65b9\u5411\u79fb\u52a8\u7684\u8bdd\uff0c\u6700\u7ec8\u53ef\u4ee5\u4e0b\u964d\u5230\u4e00\u4e2a\u8f83\u4f4e\u7684\u6c34\u5e73\u3002\u800c\u4e14\uff0c\u201c\u6c34\u5e73\u201d\u7684\u610f\u601d\u662f\u5f53\u524d\u5217\u7684\u5730\u5f62\u7684\u9ad8\u5ea6\u52a0\u4e0a\u6c34\u7684\u9ad8\u5ea6\u3002
    • \n
    \n\n

    \u6211\u4eec\u53ef\u4ee5\u5047\u5b9a\u5728\u6570\u7ec4\u4e24\u4fa7\u7684\u8fb9\u754c\u5916\u6709\u65e0\u9650\u9ad8\u7684\u5730\u5f62\u3002\u800c\u4e14\uff0c\u4e0d\u80fd\u6709\u90e8\u5206\u6c34\u5728\u591a\u4e8e 1 \u4e2a\u7684\u7f51\u683c\u5757\u4e0a\u5747\u5300\u5206\u5e03 - \u6bcf\u4e2a\u5355\u4f4d\u7684\u6c34\u5fc5\u987b\u8981\u4f4d\u4e8e\u4e00\u4e2a\u5757\u4e2d\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aheights = [2,1,1,2,1,2,2], V = 4, K = 3\n\u8f93\u51fa\uff1a[2,2,2,3,2,2,2]\n\u89e3\u91ca\uff1a\n#       #\n#       #\n##  # ###\n#########\n 0123456    <- \u7d22\u5f15\n\n\u7b2c\u4e00\u4e2a\u6c34\u6ef4\u964d\u843d\u5728\u7d22\u5f15 K = 3 \u4e0a\uff1a\n\n#       #\n#   w   #\n##  # ###\n#########\n 0123456    \n\n\u5f53\u5411\u5de6\u6216\u5411\u53f3\u79fb\u52a8\u65f6\uff0c\u6c34\u53ef\u4ee5\u79fb\u52a8\u5230\u76f8\u540c\u6216\u66f4\u4f4e\u7684\u9ad8\u5ea6\u3002When moving left or right, the water can only move to the same level or a lower level.\n\uff08\u4ece\u6c34\u5e73\u4e0a\u770b\uff0c\u610f\u601d\u662f\u8be5\u5217\u7684\u5730\u5f62\u9ad8\u5ea6\u52a0\u4e0a\u6c34\u7684\u9ad8\u5ea6\uff09\n\u7531\u4e8e\u5411\u5de6\u79fb\u52a8\u53ef\u4ee5\u6700\u7ec8\u4e0b\u843d\uff0c\u56e0\u6b64\u5411\u5de6\u79fb\u52a8\u3002\n\uff08\u4e00\u4e2a\u6c34\u6ef4 \u201c\u4e0b\u843d\u201d \u7684\u610f\u601d\u662f\u53ef\u4ee5\u76f8\u6bd4\u4e4b\u524d\u53ef\u4ee5\u8fdb\u5165\u66f4\u4f4e\u7684\u9ad8\u5ea6\uff09\n\n#       #\n#       #\n## w# ###\n#########\n 0123456    \n\n\u7531\u4e8e\u5411\u5de6\u79fb\u52a8\u4e0d\u4f1a\u4f7f\u5176\u964d\u843d\uff0c\u6240\u4ee5\u505c\u5728\u8be5\u4f4d\u7f6e\u4e0a\u3002\u4e0b\u4e00\u4e2a\u6c34\u6ef4\u4e0b\u843d\uff1a\n\n#       #\n#   w   #\n## w# ###\n#########\n 0123456  \n\n\n\u7531\u4e8e\u65b0\u6c34\u6ef4\u5411\u5de6\u79fb\u52a8\u53ef\u4ee5\u6700\u7ec8\u4e0b\u843d\uff0c\u56e0\u6b64\u5411\u5de6\u79fb\u52a8\u3002\n\u6ce8\u610f\u6c34\u6ef4\u4ecd\u7136\u662f\u4f18\u5148\u9009\u62e9\u5411\u5de6\u79fb\u52a8\uff0c\n\u5c3d\u7ba1\u53ef\u4ee5\u5411\u53f3\u79fb\u52a8\uff08\u800c\u4e14\u5411\u53f3\u79fb\u52a8\u53ef\u4ee5\u4e0b\u843d\u66f4\u5feb\uff09\n\n\n#       #\n#  w    #\n## w# ###\n#########\n 0123456  \n\n#       #\n#       #\n##ww# ###\n#########\n 0123456  \n\n\u7ecf\u8fc7\u521a\u624d\u7684\u9636\u6bb5\u540e\uff0c\u7b2c\u4e09\u4e2a\u6c34\u6ef4\u4e0b\u843d\u3002\n\u7531\u4e8e\u5411\u5de6\u79fb\u52a8\u4e0d\u4f1a\u6700\u7ec8\u4e0b\u843d\uff0c\u56e0\u6b64\u5c1d\u8bd5\u5411\u53f3\u79fb\u52a8\u3002\n\u7531\u4e8e\u5411\u53f3\u79fb\u52a8\u53ef\u4ee5\u6700\u7ec8\u4e0b\u843d\uff0c\u56e0\u6b64\u5411\u53f3\u79fb\u52a8\u3002\n\n\n#       #\n#   w   #\n##ww# ###\n#########\n 0123456  \n\n#       #\n#       #\n##ww#w###\n#########\n 0123456  \n\n\u6700\u7ec8\uff0c\u7b2c\u56db\u4e2a\u6c34\u6ef4\u4e0b\u843d\u3002\n\u7531\u4e8e\u5411\u5de6\u79fb\u52a8\u4e0d\u4f1a\u6700\u7ec8\u4e0b\u843d\uff0c\u56e0\u6b64\u5c1d\u8bd5\u5411\u53f3\u79fb\u52a8\u3002\n\u7531\u4e8e\u5411\u53f3\u79fb\u52a8\u4e0d\u4f1a\u6700\u7ec8\u4e0b\u843d\uff0c\u56e0\u6b64\u505c\u5728\u5f53\u524d\u4f4d\u7f6e\uff1a\n\n#       #\n#   w   #\n##ww#w###\n#########\n 0123456  \n\n\u6700\u7ec8\u7684\u7b54\u6848\u4e3a [2,2,2,3,2,2,2]:\n\n    #    \n ####### \n ####### \n 0123456 \n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aheights = [1,2,3,4], V = 2, K = 2\n\u8f93\u51fa\uff1a[2,3,3,4]\n\u89e3\u91ca\uff1a\n\u6700\u540e\u7684\u6c34\u6ef4\u843d\u5728\u7d22\u5f15 1 \u4f4d\u7f6e\uff0c\u56e0\u4e3a\u7ee7\u7eed\u5411\u5de6\u79fb\u52a8\u4e0d\u4f1a\u4f7f\u5176\u4e0b\u964d\u5230\u66f4\u4f4e\u7684\u9ad8\u5ea6\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aheights = [3,1,3], V = 5, K = 1\n\u8f93\u51fa\uff1a[4,4,4]\n
    \n\n

    \u00a0

    \n\n

    \u6ce8\uff1a

    \n\n
      \n\t
    1. heights \u7684\u957f\u5ea6\u4e3a\u00a0[1, 100]\u00a0\uff0c\u5e76\u4e14\u6bcf\u4e2a\u6570\u7684\u8303\u56f4\u4e3a[0, 99]\u3002
    2. \n\t
    3. V \u7684\u8303\u56f4\u00a0[0, 2000]\u3002
    4. \n\t
    5. K\u00a0\u7684\u8303\u56f4\u00a0[0, heights.length - 1]\u3002
    6. \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector pourWater(vector& heights, int volume, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] pourWater(int[] heights, int volume, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def pourWater(self, heights, volume, k):\n \"\"\"\n :type heights: List[int]\n :type volume: int\n :type k: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def pourWater(self, heights: List[int], volume: int, k: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* pourWater(int* heights, int heightsSize, int volume, int k, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] PourWater(int[] heights, int volume, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} heights\n * @param {number} volume\n * @param {number} k\n * @return {number[]}\n */\nvar pourWater = function(heights, volume, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} heights\n# @param {Integer} volume\n# @param {Integer} k\n# @return {Integer[]}\ndef pour_water(heights, volume, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func pourWater(_ heights: [Int], _ volume: Int, _ k: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func pourWater(heights []int, volume int, k int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def pourWater(heights: Array[Int], volume: Int, k: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun pourWater(heights: IntArray, volume: Int, k: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn pour_water(heights: Vec, volume: i32, k: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $heights\n * @param Integer $volume\n * @param Integer $k\n * @return Integer[]\n */\n function pourWater($heights, $volume, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function pourWater(heights: number[], volume: number, k: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (pour-water heights volume k)\n (-> (listof exact-integer?) exact-integer? exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0755](https://leetcode-cn.com/problems/pour-water)", "[\u5012\u6c34](/solution/0700-0799/0755.Pour%20Water/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0755](https://leetcode.com/problems/pour-water)", "[Pour Water](/solution/0700-0799/0755.Pour%20Water/README_EN.md)", "`Array`", "Medium", "\ud83d\udd12"]}, {"question_id": "0755", "frontend_question_id": "0754", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reach-a-number", "url_en": "https://leetcode.com/problems/reach-a-number", "relative_path_cn": "/solution/0700-0799/0754.Reach%20a%20Number/README.md", "relative_path_en": "/solution/0700-0799/0754.Reach%20a%20Number/README_EN.md", "title_cn": "\u5230\u8fbe\u7ec8\u70b9\u6570\u5b57", "title_en": "Reach a Number", "question_title_slug": "reach-a-number", "content_en": "

    \r\nYou are standing at position 0 on an infinite number line. There is a goal at position target.\r\n

    \r\nOn each move, you can either go left or right. During the n-th move (starting from 1), you take n steps.\r\n

    \r\nReturn the minimum number of steps required to reach the destination.\r\n

    \r\n\r\n

    Example 1:
    \r\n

    \r\nInput: target = 3\r\nOutput: 2\r\nExplanation:\r\nOn the first move we step from 0 to 1.\r\nOn the second step we step from 1 to 3.\r\n
    \r\n

    \r\n\r\n

    Example 2:
    \r\n

    \r\nInput: target = 2\r\nOutput: 3\r\nExplanation:\r\nOn the first move we step from 0 to 1.\r\nOn the second move we step  from 1 to -1.\r\nOn the third move we step from -1 to 2.\r\n
    \r\n

    \r\n\r\n

    Note:
    \r\n

  • target will be a non-zero integer in the range [-10^9, 10^9].
  • \r\n

    ", "content_cn": "

    \u5728\u4e00\u6839\u65e0\u9650\u957f\u7684\u6570\u8f74\u4e0a\uff0c\u4f60\u7ad9\u57280\u7684\u4f4d\u7f6e\u3002\u7ec8\u70b9\u5728target\u7684\u4f4d\u7f6e\u3002

    \n\n

    \u6bcf\u6b21\u4f60\u53ef\u4ee5\u9009\u62e9\u5411\u5de6\u6216\u5411\u53f3\u79fb\u52a8\u3002\u7b2c n \u6b21\u79fb\u52a8\uff08\u4ece 1 \u5f00\u59cb\uff09\uff0c\u53ef\u4ee5\u8d70 n \u6b65\u3002

    \n\n

    \u8fd4\u56de\u5230\u8fbe\u7ec8\u70b9\u9700\u8981\u7684\u6700\u5c0f\u79fb\u52a8\u6b21\u6570\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: target = 3\n\u8f93\u51fa: 2\n\u89e3\u91ca:\n\u7b2c\u4e00\u6b21\u79fb\u52a8\uff0c\u4ece 0 \u5230 1 \u3002\n\u7b2c\u4e8c\u6b21\u79fb\u52a8\uff0c\u4ece 1 \u5230 3 \u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: target = 2\n\u8f93\u51fa: 3\n\u89e3\u91ca:\n\u7b2c\u4e00\u6b21\u79fb\u52a8\uff0c\u4ece 0 \u5230 1 \u3002\n\u7b2c\u4e8c\u6b21\u79fb\u52a8\uff0c\u4ece 1 \u5230 -1 \u3002\n\u7b2c\u4e09\u6b21\u79fb\u52a8\uff0c\u4ece -1 \u5230 2 \u3002\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    • target\u662f\u5728[-10^9, 10^9]\u8303\u56f4\u4e2d\u7684\u975e\u96f6\u6574\u6570\u3002
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int reachNumber(int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int reachNumber(int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def reachNumber(self, target):\n \"\"\"\n :type target: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def reachNumber(self, target: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint reachNumber(int target){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ReachNumber(int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} target\n * @return {number}\n */\nvar reachNumber = function(target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} target\n# @return {Integer}\ndef reach_number(target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func reachNumber(_ target: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func reachNumber(target int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def reachNumber(target: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun reachNumber(target: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn reach_number(target: i32) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $target\n * @return Integer\n */\n function reachNumber($target) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function reachNumber(target: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (reach-number target)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0754](https://leetcode-cn.com/problems/reach-a-number)", "[\u5230\u8fbe\u7ec8\u70b9\u6570\u5b57](/solution/0700-0799/0754.Reach%20a%20Number/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0754](https://leetcode.com/problems/reach-a-number)", "[Reach a Number](/solution/0700-0799/0754.Reach%20a%20Number/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "0754", "frontend_question_id": "0753", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/cracking-the-safe", "url_en": "https://leetcode.com/problems/cracking-the-safe", "relative_path_cn": "/solution/0700-0799/0753.Cracking%20the%20Safe/README.md", "relative_path_en": "/solution/0700-0799/0753.Cracking%20the%20Safe/README_EN.md", "title_cn": "\u7834\u89e3\u4fdd\u9669\u7bb1", "title_en": "Cracking the Safe", "question_title_slug": "cracking-the-safe", "content_en": "

    There is a box protected by a password. The password is a sequence of n digits where each digit can be one of the first k digits 0, 1, ..., k-1.

    \n\n

    While entering a password, the last n digits entered will automatically be matched against the correct password.

    \n\n

    For example, assuming the correct password is "345", if you type "012345", the box will open because the correct password matches the suffix of the entered password.

    \n\n

    Return any password of minimum length that is guaranteed to open the box at some point of entering it.

    \n\n

     

    \n\n

    Example 1:

    \n\n
    \nInput: n = 1, k = 2\nOutput: "01"\nNote: "10" will be accepted too.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 2, k = 2\nOutput: "00110"\nNote: "01100", "10011", "11001" will be accepted too.\n
    \n\n

     

    \n\n

    Note:

    \n\n
      \n\t
    1. n will be in the range [1, 4].
    2. \n\t
    3. k will be in the range [1, 10].
    4. \n\t
    5. k^n will be at most 4096.
    6. \n
    \n\n

     

    \n", "content_cn": "

    \u6709\u4e00\u4e2a\u9700\u8981\u5bc6\u7801\u624d\u80fd\u6253\u5f00\u7684\u4fdd\u9669\u7bb1\u3002\u5bc6\u7801\u662f n \u4f4d\u6570, \u5bc6\u7801\u7684\u6bcf\u4e00\u4f4d\u662f k \u4f4d\u5e8f\u5217 0, 1, ..., k-1 \u4e2d\u7684\u4e00\u4e2a \u3002

    \n\n

    \u4f60\u53ef\u4ee5\u968f\u610f\u8f93\u5165\u5bc6\u7801\uff0c\u4fdd\u9669\u7bb1\u4f1a\u81ea\u52a8\u8bb0\u4f4f\u6700\u540e n \u4f4d\u8f93\u5165\uff0c\u5982\u679c\u5339\u914d\uff0c\u5219\u80fd\u591f\u6253\u5f00\u4fdd\u9669\u7bb1\u3002

    \n\n

    \u4e3e\u4e2a\u4f8b\u5b50\uff0c\u5047\u8bbe\u5bc6\u7801\u662f "345"\uff0c\u4f60\u53ef\u4ee5\u8f93\u5165 "012345" \u6765\u6253\u5f00\u5b83\uff0c\u53ea\u662f\u4f60\u8f93\u5165\u4e86 6 \u4e2a\u5b57\u7b26.

    \n\n

    \u8bf7\u8fd4\u56de\u4e00\u4e2a\u80fd\u6253\u5f00\u4fdd\u9669\u7bb1\u7684\u6700\u77ed\u5b57\u7b26\u4e32\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b1:

    \n\n
    \u8f93\u5165: n = 1, k = 2\n\u8f93\u51fa: "01"\n\u8bf4\u660e: "10"\u4e5f\u53ef\u4ee5\u6253\u5f00\u4fdd\u9669\u7bb1\u3002\n
    \n\n

     

    \n\n

    \u793a\u4f8b2:

    \n\n
    \u8f93\u5165: n = 2, k = 2\n\u8f93\u51fa: "00110"\n\u8bf4\u660e: "01100", "10011", "11001" \u4e5f\u80fd\u6253\u5f00\u4fdd\u9669\u7bb1\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. n \u7684\u8303\u56f4\u662f [1, 4]\u3002
    2. \n\t
    3. k \u7684\u8303\u56f4\u662f [1, 10]\u3002
    4. \n\t
    5. k^n \u6700\u5927\u53ef\u80fd\u4e3a 4096\u3002
    6. \n
    \n\n

     

    \n", "tags_en": ["Depth-first Search", "Math"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string crackSafe(int n, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String crackSafe(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def crackSafe(self, n, k):\n \"\"\"\n :type n: int\n :type k: int\n :rtype: str\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def crackSafe(self, n: int, k: int) -> str:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * crackSafe(int n, int k){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string CrackSafe(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} k\n * @return {string}\n */\nvar crackSafe = function(n, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} k\n# @return {String}\ndef crack_safe(n, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func crackSafe(_ n: Int, _ k: Int) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func crackSafe(n int, k int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def crackSafe(n: Int, k: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun crackSafe(n: Int, k: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn crack_safe(n: i32, k: i32) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $k\n * @return String\n */\n function crackSafe($n, $k) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function crackSafe(n: number, k: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (crack-safe n k)\n (-> exact-integer? exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0753](https://leetcode-cn.com/problems/cracking-the-safe)", "[\u7834\u89e3\u4fdd\u9669\u7bb1](/solution/0700-0799/0753.Cracking%20the%20Safe/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[0753](https://leetcode.com/problems/cracking-the-safe)", "[Cracking the Safe](/solution/0700-0799/0753.Cracking%20the%20Safe/README_EN.md)", "`Depth-first Search`,`Math`", "Hard", ""]}, {"question_id": "0753", "frontend_question_id": "0752", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/open-the-lock", "url_en": "https://leetcode.com/problems/open-the-lock", "relative_path_cn": "/solution/0700-0799/0752.Open%20the%20Lock/README.md", "relative_path_en": "/solution/0700-0799/0752.Open%20the%20Lock/README_EN.md", "title_cn": "\u6253\u5f00\u8f6c\u76d8\u9501", "title_en": "Open the Lock", "question_title_slug": "open-the-lock", "content_en": "

    You have a lock in front of you with 4 circular wheels. Each wheel has 10 slots: '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'. The wheels can rotate freely and wrap around: for example we can turn '9' to be '0', or '0' to be '9'. Each move consists of turning one wheel one slot.

    \n\n

    The lock initially starts at '0000', a string representing the state of the 4 wheels.

    \n\n

    You are given a list of deadends dead ends, meaning if the lock displays any of these codes, the wheels of the lock will stop turning and you will be unable to open it.

    \n\n

    Given a target representing the value of the wheels that will unlock the lock, return the minimum total number of turns required to open the lock, or -1 if it is impossible.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: deadends = ["0201","0101","0102","1212","2002"], target = "0202"\nOutput: 6\nExplanation:\nA sequence of valid moves would be "0000" -> "1000" -> "1100" -> "1200" -> "1201" -> "1202" -> "0202".\nNote that a sequence like "0000" -> "0001" -> "0002" -> "0102" -> "0202" would be invalid,\nbecause the wheels of the lock become stuck after the display becomes the dead end "0102".\n
    \n\n

    Example 2:

    \n\n
    \nInput: deadends = ["8888"], target = "0009"\nOutput: 1\nExplanation:\nWe can turn the last wheel in reverse to move from "0000" -> "0009".\n
    \n\n

    Example 3:

    \n\n
    \nInput: deadends = ["8887","8889","8878","8898","8788","8988","7888","9888"], target = "8888"\nOutput: -1\nExplanation:\nWe can't reach the target without getting stuck.\n
    \n\n

    Example 4:

    \n\n
    \nInput: deadends = ["0000"], target = "8888"\nOutput: -1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= deadends.length <= 500
    • \n\t
    • deadends[i].length == 4
    • \n\t
    • target.length == 4
    • \n\t
    • target will not be in the list deadends.
    • \n\t
    • target and deadends[i] consist of digits only.
    • \n
    \n", "content_cn": "

    \u4f60\u6709\u4e00\u4e2a\u5e26\u6709\u56db\u4e2a\u5706\u5f62\u62e8\u8f6e\u7684\u8f6c\u76d8\u9501\u3002\u6bcf\u4e2a\u62e8\u8f6e\u90fd\u670910\u4e2a\u6570\u5b57\uff1a '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' \u3002\u6bcf\u4e2a\u62e8\u8f6e\u53ef\u4ee5\u81ea\u7531\u65cb\u8f6c\uff1a\u4f8b\u5982\u628a '9' \u53d8\u4e3a  '0'\uff0c'0' \u53d8\u4e3a '9' \u3002\u6bcf\u6b21\u65cb\u8f6c\u90fd\u53ea\u80fd\u65cb\u8f6c\u4e00\u4e2a\u62e8\u8f6e\u7684\u4e00\u4f4d\u6570\u5b57\u3002

    \n\n

    \u9501\u7684\u521d\u59cb\u6570\u5b57\u4e3a '0000' \uff0c\u4e00\u4e2a\u4ee3\u8868\u56db\u4e2a\u62e8\u8f6e\u7684\u6570\u5b57\u7684\u5b57\u7b26\u4e32\u3002

    \n\n

    \u5217\u8868 deadends \u5305\u542b\u4e86\u4e00\u7ec4\u6b7b\u4ea1\u6570\u5b57\uff0c\u4e00\u65e6\u62e8\u8f6e\u7684\u6570\u5b57\u548c\u5217\u8868\u91cc\u7684\u4efb\u4f55\u4e00\u4e2a\u5143\u7d20\u76f8\u540c\uff0c\u8fd9\u4e2a\u9501\u5c06\u4f1a\u88ab\u6c38\u4e45\u9501\u5b9a\uff0c\u65e0\u6cd5\u518d\u88ab\u65cb\u8f6c\u3002

    \n\n

    \u5b57\u7b26\u4e32 target \u4ee3\u8868\u53ef\u4ee5\u89e3\u9501\u7684\u6570\u5b57\uff0c\u4f60\u9700\u8981\u7ed9\u51fa\u6700\u5c0f\u7684\u65cb\u8f6c\u6b21\u6570\uff0c\u5982\u679c\u65e0\u8bba\u5982\u4f55\u4e0d\u80fd\u89e3\u9501\uff0c\u8fd4\u56de -1\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165\uff1adeadends = ["0201","0101","0102","1212","2002"], target = "0202"\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\n\u53ef\u80fd\u7684\u79fb\u52a8\u5e8f\u5217\u4e3a "0000" -> "1000" -> "1100" -> "1200" -> "1201" -> "1202" -> "0202"\u3002\n\u6ce8\u610f "0000" -> "0001" -> "0002" -> "0102" -> "0202" \u8fd9\u6837\u7684\u5e8f\u5217\u662f\u4e0d\u80fd\u89e3\u9501\u7684\uff0c\n\u56e0\u4e3a\u5f53\u62e8\u52a8\u5230 "0102" \u65f6\u8fd9\u4e2a\u9501\u5c31\u4f1a\u88ab\u9501\u5b9a\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: deadends = ["8888"], target = "0009"\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\n\u628a\u6700\u540e\u4e00\u4f4d\u53cd\u5411\u65cb\u8f6c\u4e00\u6b21\u5373\u53ef "0000" -> "0009"\u3002\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \n\u8f93\u5165: deadends = ["8887","8889","8878","8898","8788","8988","7888","9888"], target = "8888"\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\n\u65e0\u6cd5\u65cb\u8f6c\u5230\u76ee\u6807\u6570\u5b57\u4e14\u4e0d\u88ab\u9501\u5b9a\u3002\n
    \n\n

    \u793a\u4f8b 4:

    \n\n
    \n\u8f93\u5165: deadends = ["0000"], target = "8888"\n\u8f93\u51fa\uff1a-1\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. \u6b7b\u4ea1\u5217\u8868 deadends \u7684\u957f\u5ea6\u8303\u56f4\u4e3a [1, 500]\u3002
    2. \n\t
    3. \u76ee\u6807\u6570\u5b57 target \u4e0d\u4f1a\u5728 deadends \u4e4b\u4e2d\u3002
    4. \n\t
    5. \u6bcf\u4e2a deadends \u548c target \u4e2d\u7684\u5b57\u7b26\u4e32\u7684\u6570\u5b57\u4f1a\u5728 10,000 \u4e2a\u53ef\u80fd\u7684\u60c5\u51b5 '0000' \u5230 '9999' \u4e2d\u4ea7\u751f\u3002
    6. \n
    \n", "tags_en": ["Breadth-first Search"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int openLock(vector& deadends, string target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int openLock(String[] deadends, String target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def openLock(self, deadends, target):\n \"\"\"\n :type deadends: List[str]\n :type target: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def openLock(self, deadends: List[str], target: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint openLock(char ** deadends, int deadendsSize, char * target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int OpenLock(string[] deadends, string target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} deadends\n * @param {string} target\n * @return {number}\n */\nvar openLock = function(deadends, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} deadends\n# @param {String} target\n# @return {Integer}\ndef open_lock(deadends, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func openLock(_ deadends: [String], _ target: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func openLock(deadends []string, target string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def openLock(deadends: Array[String], target: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun openLock(deadends: Array, target: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn open_lock(deadends: Vec, target: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $deadends\n * @param String $target\n * @return Integer\n */\n function openLock($deadends, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function openLock(deadends: string[], target: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (open-lock deadends target)\n (-> (listof string?) string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0752](https://leetcode-cn.com/problems/open-the-lock)", "[\u6253\u5f00\u8f6c\u76d8\u9501](/solution/0700-0799/0752.Open%20the%20Lock/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0752](https://leetcode.com/problems/open-the-lock)", "[Open the Lock](/solution/0700-0799/0752.Open%20the%20Lock/README_EN.md)", "`Breadth-first Search`", "Medium", ""]}, {"question_id": "0752", "frontend_question_id": "0751", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/ip-to-cidr", "url_en": "https://leetcode.com/problems/ip-to-cidr", "relative_path_cn": "/solution/0700-0799/0751.IP%20to%20CIDR/README.md", "relative_path_en": "/solution/0700-0799/0751.IP%20to%20CIDR/README_EN.md", "title_cn": "IP \u5230 CIDR", "title_en": "IP to CIDR", "question_title_slug": "ip-to-cidr", "content_en": "

    An IP address is a formatted 32-bit unsigned integer where each group of 8 bits is printed as a decimal number and the dot character '.' splits the groups.

    \n\n
      \n\t
    • For example, the binary number 00001111 10001000 11111111 01101011 (spaces added for clarity) formatted as an IP address would be "15.136.255.107".
    • \n
    \n\n

    A CIDR block is a format used to denote a specific set of IP addresses. It is a string consisting of a base IP address, followed by a slash, followed by a prefix length k. The addresses it covers are all the IPs whose first k bits are the same as the base IP address.

    \n\n
      \n\t
    • For example, "123.45.67.89/20" is a CIDR block with a prefix length of 20. Any IP address whose binary representation matches 01111011 00101101 0100xxxx xxxxxxxx, where x can be either 0 or 1, is in the set covered by the CIDR block.
    • \n
    \n\n

    You are given a start IP address ip and the number of IP addresses we need to cover n. Your goal is to use as few CIDR blocks as possible to cover all the IP addresses in the inclusive range [ip, ip + n - 1] exactly. No other IP addresses outside of the range should be covered.

    \n\n

    Return the shortest list of CIDR blocks that covers the range of IP addresses. If there are multiple answers, return any of them.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: ip = "255.0.0.7", n = 10\nOutput: ["255.0.0.7/32","255.0.0.8/29","255.0.0.16/32"]\nExplanation:\nThe IP addresses that need to be covered are:\n- 255.0.0.7  -> 11111111 00000000 00000000 00000111\n- 255.0.0.8  -> 11111111 00000000 00000000 00001000\n- 255.0.0.9  -> 11111111 00000000 00000000 00001001\n- 255.0.0.10 -> 11111111 00000000 00000000 00001010\n- 255.0.0.11 -> 11111111 00000000 00000000 00001011\n- 255.0.0.12 -> 11111111 00000000 00000000 00001100\n- 255.0.0.13 -> 11111111 00000000 00000000 00001101\n- 255.0.0.14 -> 11111111 00000000 00000000 00001110\n- 255.0.0.15 -> 11111111 00000000 00000000 00001111\n- 255.0.0.16 -> 11111111 00000000 00000000 00010000\nThe CIDR block "255.0.0.7/32" covers the first address.\nThe CIDR block "255.0.0.8/29" covers the middle 8 addresses (binary format of 11111111 00000000 00000000 00001xxx).\nThe CIDR block "255.0.0.16/32" covers the last address.\nNote that while the CIDR block "255.0.0.0/28" does cover all the addresses, it also includes addresses outside of the range, so we cannot use it.\n
    \n\n

    Example 2:

    \n\n
    \nInput: ip = "117.145.102.62", n = 8\nOutput: ["117.145.102.62/31","117.145.102.64/30","117.145.102.68/31"]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 7 <= ip.length <= 15
    • \n\t
    • ip is a valid IPv4 on the form "a.b.c.d" where a, b, c, and d are integers in the range [0, 255].
    • \n\t
    • 1 <= n <= 1000
    • \n\t
    • Every implied address ip + x (for x < n) will be a valid IPv4 address.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u8d77\u59cb IP \u5730\u5740 ip \u548c\u4e00\u4e2a\u6211\u4eec\u9700\u8981\u5305\u542b\u7684 IP \u7684\u6570\u91cf n\uff0c\u8fd4\u56de\u7528\u5217\u8868\uff08\u6700\u5c0f\u53ef\u80fd\u7684\u957f\u5ea6\uff09\u8868\u793a\u7684 CIDR\u5757\u7684\u8303\u56f4\u3002 

    \n\n

    CIDR \u5757\u662f\u5305\u542b IP \u7684\u5b57\u7b26\u4e32\uff0c\u540e\u63a5\u659c\u6760\u548c\u56fa\u5b9a\u957f\u5ea6\u3002\u4f8b\u5982\uff1a“123.45.67.89/20”\u3002\u56fa\u5b9a\u957f\u5ea6 “20” \u8868\u793a\u5728\u7279\u5b9a\u7684\u8303\u56f4\u4e2d\u516c\u5171\u524d\u7f00\u4f4d\u7684\u957f\u5ea6\u3002

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aip = "255.0.0.7", n = 10\n\u8f93\u51fa\uff1a["255.0.0.7/32","255.0.0.8/29","255.0.0.16/32"]\n\u89e3\u91ca\uff1a\n\u8f6c\u6362\u4e3a\u4e8c\u8fdb\u5236\u65f6\uff0c\u521d\u59cbIP\u5730\u5740\u5982\u4e0b\u6240\u793a\uff08\u4e3a\u6e05\u6670\u8d77\u89c1\u6dfb\u52a0\u4e86\u7a7a\u683c\uff09\uff1a\n255.0.0.7 -> 11111111 00000000 00000000 00000111\n\u5730\u5740 "255.0.0.7/32" \u8868\u793a\u4e0e\u7ed9\u5b9a\u5730\u5740\u6709\u76f8\u540c\u7684 32 \u4f4d\u524d\u7f00\u7684\u6240\u6709\u5730\u5740\uff0c\n\u5728\u8fd9\u91cc\u53ea\u6709\u8fd9\u4e00\u4e2a\u5730\u5740\u3002\n\n\u5730\u5740 "255.0.0.8/29" \u8868\u793a\u4e0e\u7ed9\u5b9a\u5730\u5740\u6709\u76f8\u540c\u7684 29 \u4f4d\u524d\u7f00\u7684\u6240\u6709\u5730\u5740\uff1a\n255.0.0.8 -> 11111111 00000000 00000000 00001000\n\u6709\u76f8\u540c\u7684 29 \u4f4d\u524d\u7f00\u7684\u5730\u5740\u5982\u4e0b\uff1a\n11111111 00000000 00000000 00001000\n11111111 00000000 00000000 00001001\n11111111 00000000 00000000 00001010\n11111111 00000000 00000000 00001011\n11111111 00000000 00000000 00001100\n11111111 00000000 00000000 00001101\n11111111 00000000 00000000 00001110\n11111111 00000000 00000000 00001111\n\n\u5730\u5740 "255.0.0.16/32" \u8868\u793a\u4e0e\u7ed9\u5b9a\u5730\u5740\u6709\u76f8\u540c\u7684 32 \u4f4d\u524d\u7f00\u7684\u6240\u6709\u5730\u5740\uff0c\n\u8fd9\u91cc\u53ea\u6709 11111111 00000000 00000000 00010000\u3002\n\n\u603b\u4e4b\uff0c\u7b54\u6848\u6307\u5b9a\u4e86\u4ece 255.0.0.7 \u5f00\u59cb\u7684 10 \u4e2a IP \u7684\u8303\u56f4\u3002\n\n\u6709\u4e00\u4e9b\u5176\u4ed6\u7684\u8868\u793a\u65b9\u6cd5\uff0c\u4f8b\u5982\uff1a\n["255.0.0.7/32","255.0.0.8/30", "255.0.0.12/30", "255.0.0.16/32"],\n\u4f46\u662f\u6211\u4eec\u7684\u7b54\u6848\u662f\u6700\u77ed\u53ef\u80fd\u7684\u7b54\u6848\u3002\n\n\u53e6\u5916\u8bf7\u6ce8\u610f\u4ee5 "255.0.0.7/30" \u5f00\u59cb\u7684\u8868\u793a\u4e0d\u6b63\u786e\uff0c\n\u56e0\u4e3a\u5176\u5305\u62ec\u4e86 255.0.0.4 = 11111111 00000000 00000000 00000100 \u8fd9\u6837\u7684\u5730\u5740\uff0c\n\u8d85\u51fa\u4e86\u9700\u8981\u8868\u793a\u7684\u8303\u56f4\u3002\n
    \n\n

     

    \n\n

    \u6ce8\uff1a

    \n\n
      \n\t
    1. ip \u662f\u6709\u6548\u7684 IPv4 \u5730\u5740\u3002
    2. \n\t
    3. \u6bcf\u4e00\u4e2a\u9690\u542b\u5730\u5740 ip + x (\u5176\u4e2d x < n) \u90fd\u662f\u6709\u6548\u7684 IPv4 \u5730\u5740\u3002
    4. \n\t
    5. n \u4e3a\u6574\u6570\uff0c\u8303\u56f4\u4e3a [1, 1000]\u3002
    6. \n
    \n\n

     

    \n", "tags_en": ["Bit Manipulation"], "tags_cn": ["\u4f4d\u8fd0\u7b97"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector ipToCIDR(string ip, int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List ipToCIDR(String ip, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def ipToCIDR(self, ip, n):\n \"\"\"\n :type ip: str\n :type n: int\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def ipToCIDR(self, ip: str, n: int) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** ipToCIDR(char * ip, int n, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList IpToCIDR(string ip, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} ip\n * @param {number} n\n * @return {string[]}\n */\nvar ipToCIDR = function(ip, n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} ip\n# @param {Integer} n\n# @return {String[]}\ndef ip_to_cidr(ip, n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func ipToCIDR(_ ip: String, _ n: Int) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func ipToCIDR(ip string, n int) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def ipToCIDR(ip: String, n: Int): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun ipToCIDR(ip: String, n: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn ip_to_cidr(ip: String, n: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $ip\n * @param Integer $n\n * @return String[]\n */\n function ipToCIDR($ip, $n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function ipToCIDR(ip: string, n: number): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (ip-to-cidr ip n)\n (-> string? exact-integer? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0751](https://leetcode-cn.com/problems/ip-to-cidr)", "[IP \u5230 CIDR](/solution/0700-0799/0751.IP%20to%20CIDR/README.md)", "`\u4f4d\u8fd0\u7b97`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0751](https://leetcode.com/problems/ip-to-cidr)", "[IP to CIDR](/solution/0700-0799/0751.IP%20to%20CIDR/README_EN.md)", "`Bit Manipulation`", "Medium", "\ud83d\udd12"]}, {"question_id": "0751", "frontend_question_id": "0750", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/number-of-corner-rectangles", "url_en": "https://leetcode.com/problems/number-of-corner-rectangles", "relative_path_cn": "/solution/0700-0799/0750.Number%20Of%20Corner%20Rectangles/README.md", "relative_path_en": "/solution/0700-0799/0750.Number%20Of%20Corner%20Rectangles/README_EN.md", "title_cn": "\u89d2\u77e9\u5f62\u7684\u6570\u91cf", "title_en": "Number Of Corner Rectangles", "question_title_slug": "number-of-corner-rectangles", "content_en": "

    Given a grid where each entry is only 0 or 1, find the number of corner rectangles.

    \r\n\r\n

    A corner rectangle is 4 distinct 1s on the grid that form an axis-aligned rectangle. Note that only the corners need to have the value 1. Also, all four 1s used must be distinct.

    \r\n\r\n

     

    \r\n\r\n

    Example 1:

    \r\n\r\n
    \r\nInput: grid = \r\n[[1, 0, 0, 1, 0],\r\n [0, 0, 1, 0, 1],\r\n [0, 0, 0, 1, 0],\r\n [1, 0, 1, 0, 1]]\r\nOutput: 1\r\nExplanation: There is only one corner rectangle, with corners grid[1][2], grid[1][4], grid[3][2], grid[3][4].\r\n
    \r\n\r\n

     

    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: grid = \r\n[[1, 1, 1],\r\n [1, 1, 1],\r\n [1, 1, 1]]\r\nOutput: 9\r\nExplanation: There are four 2x2 rectangles, four 2x3 and 3x2 rectangles, and one 3x3 rectangle.\r\n
    \r\n\r\n

     

    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: grid = \r\n[[1, 1, 1, 1]]\r\nOutput: 0\r\nExplanation: Rectangles must have four distinct corners.\r\n
    \r\n\r\n

     

    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    1. The number of rows and columns of grid will each be in the range [1, 200].
    2. \r\n\t
    3. Each grid[i][j] will be either 0 or 1.
    4. \r\n\t
    5. The number of 1s in the grid will be at most 6000.
    6. \r\n
    \r\n\r\n

     

    \r\n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u53ea\u5305\u542b 0 \u548c 1 \u7684\u7f51\u683c\uff0c\u627e\u51fa\u5176\u4e2d\u89d2\u77e9\u5f62\u7684\u6570\u91cf\u3002

    \n\n

    \u4e00\u4e2a\u300c\u89d2\u77e9\u5f62\u300d\u662f\u7531\u56db\u4e2a\u4e0d\u540c\u7684\u5728\u7f51\u683c\u4e0a\u7684 1 \u5f62\u6210\u7684\u8f74\u5bf9\u79f0\u7684\u77e9\u5f62\u3002\u6ce8\u610f\u53ea\u6709\u89d2\u7684\u4f4d\u7f6e\u624d\u9700\u8981\u4e3a 1\u3002\u5e76\u4e14\uff0c4 \u4e2a 1 \u9700\u8981\u662f\u4e0d\u540c\u7684\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1agrid = \n[[1, 0, 0, 1, 0],\n [0, 0, 1, 0, 1],\n [0, 0, 0, 1, 0],\n [1, 0, 1, 0, 1]]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u53ea\u6709\u4e00\u4e2a\u89d2\u77e9\u5f62\uff0c\u89d2\u7684\u4f4d\u7f6e\u4e3a grid[1][2], grid[1][4], grid[3][2], grid[3][4]\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1agrid = \n[[1, 1, 1],\n [1, 1, 1],\n [1, 1, 1]]\n\u8f93\u51fa\uff1a9\n\u89e3\u91ca\uff1a\u8fd9\u91cc\u6709 4 \u4e2a 2x2 \u7684\u77e9\u5f62\uff0c4 \u4e2a 2x3 \u548c 3x2 \u7684\u77e9\u5f62\u548c 1 \u4e2a 3x3 \u7684\u77e9\u5f62\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1agrid = \n[[1, 1, 1, 1]]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u77e9\u5f62\u5fc5\u987b\u6709 4 \u4e2a\u4e0d\u540c\u7684\u89d2\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. \u7f51\u683c grid \u4e2d\u884c\u548c\u5217\u7684\u6570\u76ee\u8303\u56f4\u4e3a [1, 200]\u3002
    2. \n\t
    3. \u6bcf\u4e2a\u7f51\u683c grid[i][j] \u4e2d\u7684\u503c\u4e0d\u662f 0 \u5c31\u662f 1 \u3002
    4. \n\t
    5. \u7f51\u683c\u4e2d 1 \u7684\u4e2a\u6570\u4e0d\u4f1a\u8d85\u8fc7 6000\u3002
    6. \n
    \n\n

     

    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countCornerRectangles(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countCornerRectangles(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countCornerRectangles(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countCornerRectangles(self, grid: List[List[int]]) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countCornerRectangles(int** grid, int gridSize, int* gridColSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountCornerRectangles(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar countCornerRectangles = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef count_corner_rectangles(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countCornerRectangles(_ grid: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countCornerRectangles(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countCornerRectangles(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countCornerRectangles(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_corner_rectangles(grid: Vec>) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function countCornerRectangles($grid) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countCornerRectangles(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-corner-rectangles grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0750](https://leetcode-cn.com/problems/number-of-corner-rectangles)", "[\u89d2\u77e9\u5f62\u7684\u6570\u91cf](/solution/0700-0799/0750.Number%20Of%20Corner%20Rectangles/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0750](https://leetcode.com/problems/number-of-corner-rectangles)", "[Number Of Corner Rectangles](/solution/0700-0799/0750.Number%20Of%20Corner%20Rectangles/README_EN.md)", "`Dynamic Programming`", "Medium", "\ud83d\udd12"]}, {"question_id": "0750", "frontend_question_id": "0749", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/contain-virus", "url_en": "https://leetcode.com/problems/contain-virus", "relative_path_cn": "/solution/0700-0799/0749.Contain%20Virus/README.md", "relative_path_en": "/solution/0700-0799/0749.Contain%20Virus/README_EN.md", "title_cn": "\u9694\u79bb\u75c5\u6bd2", "title_en": "Contain Virus", "question_title_slug": "contain-virus", "content_en": "

    A virus is spreading rapidly, and your task is to quarantine the infected area by installing walls.

    \n\n

    The world is modeled as an m x n binary grid isInfected, where isInfected[i][j] == 0 represents uninfected cells, and isInfected[i][j] == 1 represents cells contaminated with the virus. A wall (and only one wall) can be installed between any two 4-directionally adjacent cells, on the shared boundary.

    \n\n

    Every night, the virus spreads to all neighboring cells in all four directions unless blocked by a wall. Resources are limited. Each day, you can install walls around only one region (i.e., the affected area (continuous block of infected cells) that threatens the most uninfected cells the following night). There will never be a tie.

    \n\n

    Return the number of walls used to quarantine all the infected regions. If the world will become fully infected, return the number of walls used.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: isInfected = [[0,1,0,0,0,0,0,1],[0,1,0,0,0,0,0,1],[0,0,0,0,0,0,0,1],[0,0,0,0,0,0,0,0]]\nOutput: 10\nExplanation: There are 2 contaminated regions.\nOn the first day, add 5 walls to quarantine the viral region on the left. The board after the virus spreads is:\n\"\"\nOn the second day, add 5 walls to quarantine the viral region on the right. The virus is fully contained.\n\"\"\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: isInfected = [[1,1,1],[1,0,1],[1,1,1]]\nOutput: 4\nExplanation: Even though there is only one cell saved, there are 4 walls built.\nNotice that walls are only built on the shared boundary of two different cells.\n
    \n\n

    Example 3:

    \n\n
    \nInput: isInfected = [[1,1,1,0,0,0,0,0,0],[1,0,1,0,1,1,1,1,1],[1,1,1,0,0,0,0,0,0]]\nOutput: 13\nExplanation: The region on the left only builds two new walls.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == isInfected.length
    • \n\t
    • n == isInfected[i].length
    • \n\t
    • 1 <= m, n <= 50
    • \n\t
    • isInfected[i][j] is either 0 or 1.
    • \n\t
    • There is always a contiguous viral region throughout the described process that will infect strictly more uncontaminated squares in the next round.
    • \n
    \n", "content_cn": "

    \u75c5\u6bd2\u6269\u6563\u5f97\u5f88\u5feb\uff0c\u73b0\u5728\u4f60\u7684\u4efb\u52a1\u662f\u5c3d\u53ef\u80fd\u5730\u901a\u8fc7\u5b89\u88c5\u9632\u706b\u5899\u6765\u9694\u79bb\u75c5\u6bd2\u3002

    \n\n

    \u5047\u8bbe\u4e16\u754c\u7531\u4e8c\u7ef4\u77e9\u9635\u7ec4\u6210\uff0c0 \u8868\u793a\u8be5\u533a\u57df\u672a\u611f\u67d3\u75c5\u6bd2\uff0c\u800c 1 \u8868\u793a\u8be5\u533a\u57df\u5df2\u611f\u67d3\u75c5\u6bd2\u3002\u53ef\u4ee5\u5728\u4efb\u610f 2 \u4e2a\u56db\u65b9\u5411\u76f8\u90bb\u5355\u5143\u4e4b\u95f4\u7684\u5171\u4eab\u8fb9\u754c\u4e0a\u5b89\u88c5\u4e00\u4e2a\u9632\u706b\u5899\uff08\u5e76\u4e14\u53ea\u6709\u4e00\u4e2a\u9632\u706b\u5899\uff09\u3002

    \n\n

    \u6bcf\u5929\u665a\u4e0a\uff0c\u75c5\u6bd2\u4f1a\u4ece\u88ab\u611f\u67d3\u533a\u57df\u5411\u76f8\u90bb\u672a\u611f\u67d3\u533a\u57df\u6269\u6563\uff0c\u9664\u975e\u88ab\u9632\u706b\u5899\u9694\u79bb\u3002\u73b0\u7531\u4e8e\u8d44\u6e90\u6709\u9650\uff0c\u6bcf\u5929\u4f60\u53ea\u80fd\u5b89\u88c5\u4e00\u7cfb\u5217\u9632\u706b\u5899\u6765\u9694\u79bb\u5176\u4e2d\u4e00\u4e2a\u88ab\u75c5\u6bd2\u611f\u67d3\u7684\u533a\u57df\uff08\u4e00\u4e2a\u533a\u57df\u6216\u8fde\u7eed\u7684\u4e00\u7247\u533a\u57df\uff09\uff0c\u4e14\u8be5\u611f\u67d3\u533a\u57df\u5bf9\u672a\u611f\u67d3\u533a\u57df\u7684\u5a01\u80c1\u6700\u5927\u4e14\u4fdd\u8bc1\u552f\u4e00\u3002

    \n\n

    \u4f60\u9700\u8981\u52aa\u529b\u4f7f\u5f97\u6700\u540e\u6709\u90e8\u5206\u533a\u57df\u4e0d\u88ab\u75c5\u6bd2\u611f\u67d3\uff0c\u5982\u679c\u53ef\u4ee5\u6210\u529f\uff0c\u90a3\u4e48\u8fd4\u56de\u9700\u8981\u4f7f\u7528\u7684\u9632\u706b\u5899\u4e2a\u6570; \u5982\u679c\u65e0\u6cd5\u5b9e\u73b0\uff0c\u5219\u8fd4\u56de\u5728\u4e16\u754c\u88ab\u75c5\u6bd2\u5168\u90e8\u611f\u67d3\u65f6\u5df2\u5b89\u88c5\u7684\u9632\u706b\u5899\u4e2a\u6570\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165: grid = \n[[0,1,0,0,0,0,0,1],\n [0,1,0,0,0,0,0,1],\n [0,0,0,0,0,0,0,1],\n [0,0,0,0,0,0,0,0]]\n\u8f93\u51fa: 10\n\u8bf4\u660e:\n\u4e00\u5171\u6709\u4e24\u5757\u88ab\u75c5\u6bd2\u611f\u67d3\u7684\u533a\u57df: \u4ece\u5de6\u5f80\u53f3\u7b2c\u4e00\u5757\u9700\u8981 5 \u4e2a\u9632\u706b\u5899\uff0c\u540c\u65f6\u82e5\u8be5\u533a\u57df\u4e0d\u9694\u79bb\uff0c\u665a\u4e0a\u5c06\u611f\u67d3 5 \u4e2a\u672a\u611f\u67d3\u533a\u57df\uff08\u5373\u88ab\u5a01\u80c1\u7684\u672a\u611f\u67d3\u533a\u57df\u4e2a\u6570\u4e3a 5\uff09;\n\u7b2c\u4e8c\u5757\u9700\u8981 4 \u4e2a\u9632\u706b\u5899\uff0c\u540c\u7406\u88ab\u5a01\u80c1\u7684\u672a\u611f\u67d3\u533a\u57df\u4e2a\u6570\u662f 4\u3002\u56e0\u6b64\uff0c\u7b2c\u4e00\u5929\u5148\u9694\u79bb\u5de6\u8fb9\u7684\u611f\u67d3\u533a\u57df\uff0c\u7ecf\u8fc7\u4e00\u665a\u540e\uff0c\u75c5\u6bd2\u4f20\u64ad\u540e\u4e16\u754c\u5982\u4e0b:\n[[0,1,0,0,0,0,1,1],\n [0,1,0,0,0,0,1,1],\n [0,0,0,0,0,0,1,1],\n [0,0,0,0,0,0,0,1]]\n\u7b2c\u4e8c\u9898\uff0c\u53ea\u5269\u4e0b\u4e00\u5757\u672a\u9694\u79bb\u7684\u88ab\u611f\u67d3\u7684\u8fde\u7eed\u533a\u57df\uff0c\u6b64\u65f6\u9700\u8981\u5b89\u88c5 5 \u4e2a\u9632\u706b\u5899\uff0c\u4e14\u5b89\u88c5\u5b8c\u6bd5\u540e\u75c5\u6bd2\u9694\u79bb\u4efb\u52a1\u5b8c\u6210\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165: grid = \n[[1,1,1],\n [1,0,1],\n [1,1,1]]\n\u8f93\u51fa: 4\n\u8bf4\u660e: \n\u6b64\u65f6\u53ea\u9700\u8981\u5b89\u88c5 4 \u9762\u9632\u706b\u5899\uff0c\u5c31\u6709\u4e00\u5c0f\u533a\u57df\u53ef\u4ee5\u5e78\u5b58\uff0c\u4e0d\u88ab\u75c5\u6bd2\u611f\u67d3\u3002\n\u6ce8\u610f\u4e0d\u9700\u8981\u5728\u4e16\u754c\u8fb9\u754c\u5efa\u7acb\u9632\u706b\u5899\u3002
    \n\n

     

    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u8f93\u5165: grid = \n[[1,1,1,0,0,0,0,0,0],\n [1,0,1,0,1,1,1,1,1],\n [1,1,1,0,0,0,0,0,0]]\n\u8f93\u51fa: 13\n\u8bf4\u660e: \n\u5728\u9694\u79bb\u53f3\u8fb9\u611f\u67d3\u533a\u57df\u540e\uff0c\u9694\u79bb\u5de6\u8fb9\u75c5\u6bd2\u533a\u57df\u53ea\u9700\u8981 2 \u4e2a\u9632\u706b\u5899\u4e86\u3002\n
    \n\n

     

    \n\n

    \u8bf4\u660e:

    \n\n
      \n\t
    1. grid \u7684\u884c\u6570\u548c\u5217\u6570\u8303\u56f4\u662f [1, 50]\u3002
    2. \n\t
    3.  grid[i][j] \u53ea\u5305\u542b 0 \u6216 1 \u3002
    4. \n\t
    5. \u9898\u76ee\u4fdd\u8bc1\u6bcf\u6b21\u9009\u53d6\u611f\u67d3\u533a\u57df\u8fdb\u884c\u9694\u79bb\u65f6\uff0c\u4e00\u5b9a\u5b58\u5728\u552f\u4e00\u4e00\u4e2a\u5bf9\u672a\u611f\u67d3\u533a\u57df\u7684\u5a01\u80c1\u6700\u5927\u7684\u533a\u57df\u3002
    6. \n
    \n\n

     

    \n", "tags_en": ["Depth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int containVirus(vector>& isInfected) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int containVirus(int[][] isInfected) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def containVirus(self, isInfected):\n \"\"\"\n :type isInfected: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def containVirus(self, isInfected: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint containVirus(int** isInfected, int isInfectedSize, int* isInfectedColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ContainVirus(int[][] isInfected) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} isInfected\n * @return {number}\n */\nvar containVirus = function(isInfected) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} is_infected\n# @return {Integer}\ndef contain_virus(is_infected)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func containVirus(_ isInfected: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func containVirus(isInfected [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def containVirus(isInfected: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun containVirus(isInfected: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn contain_virus(is_infected: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $isInfected\n * @return Integer\n */\n function containVirus($isInfected) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function containVirus(isInfected: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (contain-virus isInfected)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0749](https://leetcode-cn.com/problems/contain-virus)", "[\u9694\u79bb\u75c5\u6bd2](/solution/0700-0799/0749.Contain%20Virus/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[0749](https://leetcode.com/problems/contain-virus)", "[Contain Virus](/solution/0700-0799/0749.Contain%20Virus/README_EN.md)", "`Depth-first Search`", "Hard", ""]}, {"question_id": "0749", "frontend_question_id": "0748", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/shortest-completing-word", "url_en": "https://leetcode.com/problems/shortest-completing-word", "relative_path_cn": "/solution/0700-0799/0748.Shortest%20Completing%20Word/README.md", "relative_path_en": "/solution/0700-0799/0748.Shortest%20Completing%20Word/README_EN.md", "title_cn": "\u6700\u77ed\u8865\u5168\u8bcd", "title_en": "Shortest Completing Word", "question_title_slug": "shortest-completing-word", "content_en": "

    Given a string licensePlate and an array of strings words, find the shortest completing word in words.

    \n\n

    A completing word is a word that contains all the letters in licensePlate. Ignore numbers and spaces in licensePlate, and treat letters as case insensitive. If a letter appears more than once in licensePlate, then it must appear in the word the same number of times or more.

    \n\n

    For example, if licensePlate = "aBc 12c", then it contains letters 'a', 'b' (ignoring case), and 'c' twice. Possible completing words are "abccdef", "caaacab", and "cbca".

    \n\n

    Return the shortest completing word in words. It is guaranteed an answer exists. If there are multiple shortest completing words, return the first one that occurs in words.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: licensePlate = "1s3 PSt", words = ["step","steps","stripe","stepple"]\nOutput: "steps"\nExplanation: licensePlate contains letters 's', 'p', 's' (ignoring case), and 't'.\n"step" contains 't' and 'p', but only contains 1 's'.\n"steps" contains 't', 'p', and both 's' characters.\n"stripe" is missing an 's'.\n"stepple" is missing an 's'.\nSince "steps" is the only word containing all the letters, that is the answer.\n
    \n\n

    Example 2:

    \n\n
    \nInput: licensePlate = "1s3 456", words = ["looks","pest","stew","show"]\nOutput: "pest"\nExplanation: licensePlate only contains the letter 's'. All the words contain 's', but among these "pest", "stew", and "show" are shortest. The answer is "pest" because it is the word that appears earliest of the 3.\n
    \n\n

    Example 3:

    \n\n
    \nInput: licensePlate = "Ah71752", words = ["suggest","letter","of","husband","easy","education","drug","prevent","writer","old"]\nOutput: "husband"\n
    \n\n

    Example 4:

    \n\n
    \nInput: licensePlate = "OgEu755", words = ["enough","these","play","wide","wonder","box","arrive","money","tax","thus"]\nOutput: "enough"\n
    \n\n

    Example 5:

    \n\n
    \nInput: licensePlate = "iMSlpe4", words = ["claim","consumer","student","camera","public","never","wonder","simple","thought","use"]\nOutput: "simple"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= licensePlate.length <= 7
    • \n\t
    • licensePlate contains digits, letters (uppercase or lowercase), or space ' '.
    • \n\t
    • 1 <= words.length <= 1000
    • \n\t
    • 1 <= words[i].length <= 15
    • \n\t
    • words[i] consists of lower case English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\u724c\u7167 licensePlate \u548c\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4 words \uff0c\u8bf7\u4f60\u627e\u51fa\u5e76\u8fd4\u56de words \u4e2d\u7684 \u6700\u77ed\u8865\u5168\u8bcd \u3002

    \n\n

    \u5982\u679c\u5355\u8bcd\u5217\u8868\uff08words\uff09\u4e2d\u7684\u4e00\u4e2a\u5355\u8bcd\u5305\u542b\u724c\u7167\uff08licensePlate\uff09\u4e2d\u6240\u6709\u7684\u5b57\u6bcd\uff0c\u90a3\u4e48\u6211\u4eec\u79f0\u4e4b\u4e3a \u8865\u5168\u8bcd \u3002\u5728\u6240\u6709\u5b8c\u6574\u8bcd\u4e2d\uff0c\u6700\u77ed\u7684\u5355\u8bcd\u6211\u4eec\u79f0\u4e4b\u4e3a \u6700\u77ed\u8865\u5168\u8bcd \u3002

    \n\n

    \u5355\u8bcd\u5728\u5339\u914d\u724c\u7167\u4e2d\u7684\u5b57\u6bcd\u65f6\u8981\uff1a

    \n\n
      \n\t
    • \u5ffd\u7565\u724c\u7167\u4e2d\u7684\u6570\u5b57\u548c\u7a7a\u683c\u3002
    • \n\t
    • \u4e0d\u533a\u5206\u5927\u5c0f\u5199\uff0c\u6bd4\u5982\u724c\u7167\u4e2d\u7684 "P" \u4f9d\u7136\u53ef\u4ee5\u5339\u914d\u5355\u8bcd\u4e2d\u7684 "p" \u5b57\u6bcd\u3002
    • \n\t
    • \u5982\u679c\u67d0\u4e2a\u5b57\u6bcd\u5728\u724c\u7167\u4e2d\u51fa\u73b0\u4e0d\u6b62\u4e00\u6b21\uff0c\u90a3\u4e48\u8be5\u5b57\u6bcd\u5728\u8865\u5168\u8bcd\u4e2d\u7684\u51fa\u73b0\u6b21\u6570\u5e94\u5f53\u4e00\u81f4\u6216\u8005\u66f4\u591a\u3002
    • \n
    \n\n

    \u4f8b\u5982\uff1alicensePlate = "aBc 12c"\uff0c\u90a3\u4e48\u5b83\u7531\u5b57\u6bcd 'a'\u3001'b' \uff08\u5ffd\u7565\u5927\u5199\uff09\u548c\u4e24\u4e2a 'c' \u3002\u53ef\u80fd\u7684 \u8865\u5168\u8bcd \u662f "abccdef"\u3001"caaacab" \u4ee5\u53ca "cbca" \u3002

    \n\n

    \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u4e00\u5b9a\u5b58\u5728\u4e00\u4e2a\u6700\u77ed\u8865\u5168\u8bcd\u3002\u5f53\u6709\u591a\u4e2a\u5355\u8bcd\u90fd\u7b26\u5408\u6700\u77ed\u8865\u5168\u8bcd\u7684\u5339\u914d\u6761\u4ef6\u65f6\u53d6\u5355\u8bcd\u5217\u8868\u4e2d\u6700\u9760\u524d\u7684\u4e00\u4e2a\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1alicensePlate = "1s3 PSt", words = ["step", "steps", "stripe", "stepple"]\n\u8f93\u51fa\uff1a"steps"\n\u8bf4\u660e\uff1a\u6700\u77ed\u8865\u5168\u8bcd\u5e94\u8be5\u5305\u62ec "s"\u3001"p"\u3001"s" \u4ee5\u53ca "t"\u3002\u5728\u5339\u914d\u8fc7\u7a0b\u4e2d\u6211\u4eec\u5ffd\u7565\u724c\u7167\u4e2d\u7684\u5927\u5c0f\u5199\u3002\n"step" \u5305\u542b "t"\u3001"p"\uff0c\u4f46\u53ea\u5305\u542b\u4e00\u4e2a "s"\uff0c\u6240\u4ee5\u5b83\u4e0d\u7b26\u5408\u6761\u4ef6\u3002\n"steps" \u5305\u542b "t"\u3001"p" \u548c\u4e24\u4e2a "s"\u3002\n"stripe" \u7f3a\u4e00\u4e2a "s"\u3002\n"stepple" \u7f3a\u4e00\u4e2a "s"\u3002\n\u56e0\u6b64\uff0c"steps" \u662f\u552f\u4e00\u4e00\u4e2a\u5305\u542b\u6240\u6709\u5b57\u6bcd\u7684\u5355\u8bcd\uff0c\u4e5f\u662f\u672c\u6837\u4f8b\u7684\u7b54\u6848\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1alicensePlate = "1s3 456", words = ["looks", "pest", "stew", "show"]\n\u8f93\u51fa\uff1a"pest"\n\u8bf4\u660e\uff1a\u5b58\u5728 3 \u4e2a\u5305\u542b\u5b57\u6bcd "s" \u4e14\u6709\u7740\u6700\u77ed\u957f\u5ea6\u7684\u8865\u5168\u8bcd\uff0c"pest"\u3001"stew"\u3001\u548c "show" \u4e09\u8005\u957f\u5ea6\u76f8\u540c\uff0c\u4f46\u6211\u4eec\u8fd4\u56de\u6700\u5148\u51fa\u73b0\u7684\u8865\u5168\u8bcd "pest" \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1alicensePlate = "Ah71752", words = ["suggest","letter","of","husband","easy","education","drug","prevent","writer","old"]\n\u8f93\u51fa\uff1a"husband"\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1alicensePlate = "OgEu755", words = ["enough","these","play","wide","wonder","box","arrive","money","tax","thus"]\n\u8f93\u51fa\uff1a"enough"\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1alicensePlate = "iMSlpe4", words = ["claim","consumer","student","camera","public","never","wonder","simple","thought","use"]\n\u8f93\u51fa\uff1a"simple"\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= licensePlate.length <= 7
    • \n\t
    • licensePlate \u7531\u6570\u5b57\u3001\u5927\u5c0f\u5199\u5b57\u6bcd\u6216\u7a7a\u683c ' ' \u7ec4\u6210
    • \n\t
    • 1 <= words.length <= 1000
    • \n\t
    • 1 <= words[i].length <= 15
    • \n\t
    • words[i] \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string shortestCompletingWord(string licensePlate, vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String shortestCompletingWord(String licensePlate, String[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def shortestCompletingWord(self, licensePlate, words):\n \"\"\"\n :type licensePlate: str\n :type words: List[str]\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def shortestCompletingWord(self, licensePlate: str, words: List[str]) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * shortestCompletingWord(char * licensePlate, char ** words, int wordsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ShortestCompletingWord(string licensePlate, string[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} licensePlate\n * @param {string[]} words\n * @return {string}\n */\nvar shortestCompletingWord = function(licensePlate, words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} license_plate\n# @param {String[]} words\n# @return {String}\ndef shortest_completing_word(license_plate, words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func shortestCompletingWord(_ licensePlate: String, _ words: [String]) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func shortestCompletingWord(licensePlate string, words []string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def shortestCompletingWord(licensePlate: String, words: Array[String]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun shortestCompletingWord(licensePlate: String, words: Array): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn shortest_completing_word(license_plate: String, words: Vec) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $licensePlate\n * @param String[] $words\n * @return String\n */\n function shortestCompletingWord($licensePlate, $words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function shortestCompletingWord(licensePlate: string, words: string[]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (shortest-completing-word licensePlate words)\n (-> string? (listof string?) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0748](https://leetcode-cn.com/problems/shortest-completing-word)", "[\u6700\u77ed\u8865\u5168\u8bcd](/solution/0700-0799/0748.Shortest%20Completing%20Word/README.md)", "`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0748](https://leetcode.com/problems/shortest-completing-word)", "[Shortest Completing Word](/solution/0700-0799/0748.Shortest%20Completing%20Word/README_EN.md)", "`Hash Table`", "Easy", ""]}, {"question_id": "0748", "frontend_question_id": "0747", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/largest-number-at-least-twice-of-others", "url_en": "https://leetcode.com/problems/largest-number-at-least-twice-of-others", "relative_path_cn": "/solution/0700-0799/0747.Largest%20Number%20At%20Least%20Twice%20of%20Others/README.md", "relative_path_en": "/solution/0700-0799/0747.Largest%20Number%20At%20Least%20Twice%20of%20Others/README_EN.md", "title_cn": "\u81f3\u5c11\u662f\u5176\u4ed6\u6570\u5b57\u4e24\u500d\u7684\u6700\u5927\u6570", "title_en": "Largest Number At Least Twice of Others", "question_title_slug": "largest-number-at-least-twice-of-others", "content_en": "

    You are given an integer array nums where the largest integer is unique.

    \n\n

    Determine whether the largest element in the array is at least twice as much as every other number in the array. If it is, return the index of the largest element, or return -1 otherwise.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [3,6,1,0]\nOutput: 1\nExplanation: 6 is the largest integer.\nFor every other number in the array x, 6 is at least twice as big as x.\nThe index of value 6 is 1, so we return 1.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,2,3,4]\nOutput: -1\nExplanation: 4 is less than twice the value of 3, so we return -1.
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [1]\nOutput: 0\nExplanation: 1 is trivially at least twice the value as any other number because there are no other numbers.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 50
    • \n\t
    • 0 <= nums[i] <= 100
    • \n\t
    • The largest element in nums is unique.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \uff0c\u5176\u4e2d\u603b\u662f\u5b58\u5728 \u552f\u4e00\u7684 \u4e00\u4e2a\u6700\u5927\u6574\u6570 \u3002

    \n\n

    \u8bf7\u4f60\u627e\u51fa\u6570\u7ec4\u4e2d\u7684\u6700\u5927\u5143\u7d20\u5e76\u68c0\u67e5\u5b83\u662f\u5426 \u81f3\u5c11\u662f\u6570\u7ec4\u4e2d\u6bcf\u4e2a\u5176\u4ed6\u6570\u5b57\u7684\u4e24\u500d \u3002\u5982\u679c\u662f\uff0c\u5219\u8fd4\u56de \u6700\u5927\u5143\u7d20\u7684\u4e0b\u6807 \uff0c\u5426\u5219\u8fd4\u56de -1 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [3,6,1,0]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a6 \u662f\u6700\u5927\u7684\u6574\u6570\uff0c\u5bf9\u4e8e\u6570\u7ec4\u4e2d\u7684\u5176\u4ed6\u6574\u6570\uff0c6 \u5927\u4e8e\u6570\u7ec4\u4e2d\u5176\u4ed6\u5143\u7d20\u7684\u4e24\u500d\u30026 \u7684\u4e0b\u6807\u662f 1 \uff0c\u6240\u4ee5\u8fd4\u56de 1 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,3,4]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a4 \u6ca1\u6709\u8d85\u8fc7 3 \u7684\u4e24\u500d\u5927\uff0c\u6240\u4ee5\u8fd4\u56de -1 \u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u56e0\u4e3a\u4e0d\u5b58\u5728\u5176\u4ed6\u6570\u5b57\uff0c\u6240\u4ee5\u8ba4\u4e3a\u73b0\u6709\u6570\u5b57 1 \u81f3\u5c11\u662f\u5176\u4ed6\u6570\u5b57\u7684\u4e24\u500d\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 50
    • \n\t
    • 0 <= nums[i] <= 100
    • \n\t
    • nums \u4e2d\u7684\u6700\u5927\u5143\u7d20\u662f\u552f\u4e00\u7684
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int dominantIndex(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int dominantIndex(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def dominantIndex(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def dominantIndex(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint dominantIndex(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int DominantIndex(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar dominantIndex = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef dominant_index(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func dominantIndex(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func dominantIndex(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def dominantIndex(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun dominantIndex(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn dominant_index(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function dominantIndex($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function dominantIndex(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (dominant-index nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0747](https://leetcode-cn.com/problems/largest-number-at-least-twice-of-others)", "[\u81f3\u5c11\u662f\u5176\u4ed6\u6570\u5b57\u4e24\u500d\u7684\u6700\u5927\u6570](/solution/0700-0799/0747.Largest%20Number%20At%20Least%20Twice%20of%20Others/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0747](https://leetcode.com/problems/largest-number-at-least-twice-of-others)", "[Largest Number At Least Twice of Others](/solution/0700-0799/0747.Largest%20Number%20At%20Least%20Twice%20of%20Others/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0747", "frontend_question_id": "0746", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/min-cost-climbing-stairs", "url_en": "https://leetcode.com/problems/min-cost-climbing-stairs", "relative_path_cn": "/solution/0700-0799/0746.Min%20Cost%20Climbing%20Stairs/README.md", "relative_path_en": "/solution/0700-0799/0746.Min%20Cost%20Climbing%20Stairs/README_EN.md", "title_cn": "\u4f7f\u7528\u6700\u5c0f\u82b1\u8d39\u722c\u697c\u68af", "title_en": "Min Cost Climbing Stairs", "question_title_slug": "min-cost-climbing-stairs", "content_en": "

    You are given an integer array cost where cost[i] is the cost of ith step on a staircase. Once you pay the cost, you can either climb one or two steps.

    \n\n

    You can either start from the step with index 0, or the step with index 1.

    \n\n

    Return the minimum cost to reach the top of the floor.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: cost = [10,15,20]\nOutput: 15\nExplanation: Cheapest is: start on cost[1], pay that cost, and go to the top.\n
    \n\n

    Example 2:

    \n\n
    \nInput: cost = [1,100,1,1,1,100,1,1,100,1]\nOutput: 6\nExplanation: Cheapest is: start on cost[0], and only step on 1s, skipping cost[3].\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= cost.length <= 1000
    • \n\t
    • 0 <= cost[i] <= 999
    • \n
    \n", "content_cn": "

    \u6570\u7ec4\u7684\u6bcf\u4e2a\u4e0b\u6807\u4f5c\u4e3a\u4e00\u4e2a\u9636\u68af\uff0c\u7b2c i \u4e2a\u9636\u68af\u5bf9\u5e94\u7740\u4e00\u4e2a\u975e\u8d1f\u6570\u7684\u4f53\u529b\u82b1\u8d39\u503c\u00a0cost[i]\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\u3002

    \n\n

    \u6bcf\u5f53\u4f60\u722c\u4e0a\u4e00\u4e2a\u9636\u68af\u4f60\u90fd\u8981\u82b1\u8d39\u5bf9\u5e94\u7684\u4f53\u529b\u503c\uff0c\u4e00\u65e6\u652f\u4ed8\u4e86\u76f8\u5e94\u7684\u4f53\u529b\u503c\uff0c\u4f60\u5c31\u53ef\u4ee5\u9009\u62e9\u5411\u4e0a\u722c\u4e00\u4e2a\u9636\u68af\u6216\u8005\u722c\u4e24\u4e2a\u9636\u68af\u3002

    \n\n

    \u8bf7\u4f60\u627e\u51fa\u8fbe\u5230\u697c\u5c42\u9876\u90e8\u7684\u6700\u4f4e\u82b1\u8d39\u3002\u5728\u5f00\u59cb\u65f6\uff0c\u4f60\u53ef\u4ee5\u9009\u62e9\u4ece\u4e0b\u6807\u4e3a 0 \u6216 1 \u7684\u5143\u7d20\u4f5c\u4e3a\u521d\u59cb\u9636\u68af\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\u00a01\uff1a

    \n\n
    \n\u8f93\u5165\uff1acost = [10, 15, 20]\n\u8f93\u51fa\uff1a15\n\u89e3\u91ca\uff1a\u6700\u4f4e\u82b1\u8d39\u662f\u4ece cost[1] \u5f00\u59cb\uff0c\u7136\u540e\u8d70\u4e24\u6b65\u5373\u53ef\u5230\u9636\u68af\u9876\uff0c\u4e00\u5171\u82b1\u8d39 15 \u3002\n
    \n\n

    \u00a0\u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1acost = [1, 100, 1, 1, 1, 100, 1, 1, 100, 1]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u6700\u4f4e\u82b1\u8d39\u65b9\u5f0f\u662f\u4ece cost[0] \u5f00\u59cb\uff0c\u9010\u4e2a\u7ecf\u8fc7\u90a3\u4e9b 1 \uff0c\u8df3\u8fc7 cost[3] \uff0c\u4e00\u5171\u82b1\u8d39 6 \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • cost\u00a0\u7684\u957f\u5ea6\u8303\u56f4\u662f [2, 1000]\u3002
    • \n\t
    • cost[i] \u5c06\u4f1a\u662f\u4e00\u4e2a\u6574\u578b\u6570\u636e\uff0c\u8303\u56f4\u4e3a\u00a0[0, 999] \u3002
    • \n
    \n", "tags_en": ["Array", "Dynamic Programming"], "tags_cn": ["\u6570\u7ec4", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minCostClimbingStairs(vector& cost) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minCostClimbingStairs(int[] cost) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minCostClimbingStairs(self, cost):\n \"\"\"\n :type cost: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minCostClimbingStairs(self, cost: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minCostClimbingStairs(int* cost, int costSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinCostClimbingStairs(int[] cost) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} cost\n * @return {number}\n */\nvar minCostClimbingStairs = function(cost) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} cost\n# @return {Integer}\ndef min_cost_climbing_stairs(cost)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minCostClimbingStairs(_ cost: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minCostClimbingStairs(cost []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minCostClimbingStairs(cost: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minCostClimbingStairs(cost: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_cost_climbing_stairs(cost: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $cost\n * @return Integer\n */\n function minCostClimbingStairs($cost) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minCostClimbingStairs(cost: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-cost-climbing-stairs cost)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0746](https://leetcode-cn.com/problems/min-cost-climbing-stairs)", "[\u4f7f\u7528\u6700\u5c0f\u82b1\u8d39\u722c\u697c\u68af](/solution/0700-0799/0746.Min%20Cost%20Climbing%20Stairs/README.md)", "`\u6570\u7ec4`,`\u52a8\u6001\u89c4\u5212`", "\u7b80\u5355", ""], "md_table_row_en": ["[0746](https://leetcode.com/problems/min-cost-climbing-stairs)", "[Min Cost Climbing Stairs](/solution/0700-0799/0746.Min%20Cost%20Climbing%20Stairs/README_EN.md)", "`Array`,`Dynamic Programming`", "Easy", ""]}, {"question_id": "0746", "frontend_question_id": "0745", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/prefix-and-suffix-search", "url_en": "https://leetcode.com/problems/prefix-and-suffix-search", "relative_path_cn": "/solution/0700-0799/0745.Prefix%20and%20Suffix%20Search/README.md", "relative_path_en": "/solution/0700-0799/0745.Prefix%20and%20Suffix%20Search/README_EN.md", "title_cn": "\u524d\u7f00\u548c\u540e\u7f00\u641c\u7d22", "title_en": "Prefix and Suffix Search", "question_title_slug": "prefix-and-suffix-search", "content_en": "

    Design a special dictionary with some words that searchs the words in it by a prefix and a suffix.

    \n\n

    Implement the WordFilter class:

    \n\n
      \n\t
    • WordFilter(string[] words) Initializes the object with the words in the dictionary.
    • \n\t
    • f(string prefix, string suffix) Returns the index of the word in the dictionary, which has the prefix prefix and the suffix suffix. If there is more than one valid index, return the largest of them. If there is no such word in the dictionary, return -1.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["WordFilter", "f"]\n[[["apple"]], ["a", "e"]]\nOutput\n[null, 0]\n\nExplanation\nWordFilter wordFilter = new WordFilter(["apple"]);\nwordFilter.f("a", "e"); // return 0, because the word at index 0 has prefix = "a" and suffix = 'e".\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= words.length <= 15000
    • \n\t
    • 1 <= words[i].length <= 10
    • \n\t
    • 1 <= prefix.length, suffix.length <= 10
    • \n\t
    • words[i], prefix and suffix consist of lower-case English letters only.
    • \n\t
    • At most 15000 calls will be made to the function f.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u591a\u4e2a words\uff0cwords[i] \u7684\u6743\u91cd\u4e3a i \u3002

    \n\n

    \u8bbe\u8ba1\u4e00\u4e2a\u7c7b WordFilter \u5b9e\u73b0\u51fd\u6570WordFilter.f(String prefix, String suffix)\u3002\u8fd9\u4e2a\u51fd\u6570\u5c06\u8fd4\u56de\u5177\u6709\u524d\u7f00 prefix \u548c\u540e\u7f00suffix \u7684\u8bcd\u7684\u6700\u5927\u6743\u91cd\u3002\u5982\u679c\u6ca1\u6709\u8fd9\u6837\u7684\u8bcd\uff0c\u8fd4\u56de -1\u3002

    \n\n

    \u4f8b\u5b50:

    \n\n
    \n\u8f93\u5165:\nWordFilter(["apple"])\nWordFilter.f("a", "e") // \u8fd4\u56de 0\nWordFilter.f("b", "") // \u8fd4\u56de -1\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. words\u7684\u957f\u5ea6\u5728[1, 15000]\u4e4b\u95f4\u3002
    2. \n\t
    3. \u5bf9\u4e8e\u6bcf\u4e2a\u6d4b\u8bd5\u7528\u4f8b\uff0c\u6700\u591a\u4f1a\u6709words.length\u6b21\u5bf9WordFilter.f\u7684\u8c03\u7528\u3002
    4. \n\t
    5. words[i]\u7684\u957f\u5ea6\u5728[1, 10]\u4e4b\u95f4\u3002
    6. \n\t
    7. prefix, suffix\u7684\u957f\u5ea6\u5728[0, 10]\u4e4b\u524d\u3002
    8. \n\t
    9. words[i]\u548cprefix, suffix\u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd\u3002
    10. \n
    \n", "tags_en": ["Trie"], "tags_cn": ["\u5b57\u5178\u6811"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class WordFilter {\npublic:\n WordFilter(vector& words) {\n\n }\n \n int f(string prefix, string suffix) {\n\n }\n};\n\n/**\n * Your WordFilter object will be instantiated and called as such:\n * WordFilter* obj = new WordFilter(words);\n * int param_1 = obj->f(prefix,suffix);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class WordFilter {\n\n public WordFilter(String[] words) {\n\n }\n \n public int f(String prefix, String suffix) {\n\n }\n}\n\n/**\n * Your WordFilter object will be instantiated and called as such:\n * WordFilter obj = new WordFilter(words);\n * int param_1 = obj.f(prefix,suffix);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class WordFilter(object):\n\n def __init__(self, words):\n \"\"\"\n :type words: List[str]\n \"\"\"\n\n\n def f(self, prefix, suffix):\n \"\"\"\n :type prefix: str\n :type suffix: str\n :rtype: int\n \"\"\"\n\n\n\n# Your WordFilter object will be instantiated and called as such:\n# obj = WordFilter(words)\n# param_1 = obj.f(prefix,suffix)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class WordFilter:\n\n def __init__(self, words: List[str]):\n\n\n def f(self, prefix: str, suffix: str) -> int:\n\n\n\n# Your WordFilter object will be instantiated and called as such:\n# obj = WordFilter(words)\n# param_1 = obj.f(prefix,suffix)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} WordFilter;\n\n\nWordFilter* wordFilterCreate(char ** words, int wordsSize) {\n \n}\n\nint wordFilterF(WordFilter* obj, char * prefix, char * suffix) {\n \n}\n\nvoid wordFilterFree(WordFilter* obj) {\n \n}\n\n/**\n * Your WordFilter struct will be instantiated and called as such:\n * WordFilter* obj = wordFilterCreate(words, wordsSize);\n * int param_1 = wordFilterF(obj, prefix, suffix);\n \n * wordFilterFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class WordFilter {\n\n public WordFilter(string[] words) {\n\n }\n \n public int F(string prefix, string suffix) {\n\n }\n}\n\n/**\n * Your WordFilter object will be instantiated and called as such:\n * WordFilter obj = new WordFilter(words);\n * int param_1 = obj.F(prefix,suffix);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n */\nvar WordFilter = function(words) {\n\n};\n\n/** \n * @param {string} prefix \n * @param {string} suffix\n * @return {number}\n */\nWordFilter.prototype.f = function(prefix, suffix) {\n\n};\n\n/**\n * Your WordFilter object will be instantiated and called as such:\n * var obj = new WordFilter(words)\n * var param_1 = obj.f(prefix,suffix)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class WordFilter\n\n=begin\n :type words: String[]\n=end\n def initialize(words)\n\n end\n\n\n=begin\n :type prefix: String\n :type suffix: String\n :rtype: Integer\n=end\n def f(prefix, suffix)\n\n end\n\n\nend\n\n# Your WordFilter object will be instantiated and called as such:\n# obj = WordFilter.new(words)\n# param_1 = obj.f(prefix, suffix)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass WordFilter {\n\n init(_ words: [String]) {\n\n }\n \n func f(_ prefix: String, _ suffix: String) -> Int {\n\n }\n}\n\n/**\n * Your WordFilter object will be instantiated and called as such:\n * let obj = WordFilter(words)\n * let ret_1: Int = obj.f(prefix, suffix)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type WordFilter struct {\n\n}\n\n\nfunc Constructor(words []string) WordFilter {\n\n}\n\n\nfunc (this *WordFilter) F(prefix string, suffix string) int {\n\n}\n\n\n/**\n * Your WordFilter object will be instantiated and called as such:\n * obj := Constructor(words);\n * param_1 := obj.F(prefix,suffix);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class WordFilter(_words: Array[String]) {\n\n def f(prefix: String, suffix: String): Int = {\n\n }\n\n}\n\n/**\n * Your WordFilter object will be instantiated and called as such:\n * var obj = new WordFilter(words)\n * var param_1 = obj.f(prefix,suffix)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class WordFilter(words: Array) {\n\n fun f(prefix: String, suffix: String): Int {\n\n }\n\n}\n\n/**\n * Your WordFilter object will be instantiated and called as such:\n * var obj = WordFilter(words)\n * var param_1 = obj.f(prefix,suffix)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct WordFilter {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl WordFilter {\n\n fn new(words: Vec) -> Self {\n\n }\n \n fn f(&self, prefix: String, suffix: String) -> i32 {\n\n }\n}\n\n/**\n * Your WordFilter object will be instantiated and called as such:\n * let obj = WordFilter::new(words);\n * let ret_1: i32 = obj.f(prefix, suffix);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class WordFilter {\n /**\n * @param String[] $words\n */\n function __construct($words) {\n\n }\n\n /**\n * @param String $prefix\n * @param String $suffix\n * @return Integer\n */\n function f($prefix, $suffix) {\n\n }\n}\n\n/**\n * Your WordFilter object will be instantiated and called as such:\n * $obj = WordFilter($words);\n * $ret_1 = $obj->f($prefix, $suffix);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class WordFilter {\n constructor(words: string[]) {\n\n }\n\n f(prefix: string, suffix: string): number {\n\n }\n}\n\n/**\n * Your WordFilter object will be instantiated and called as such:\n * var obj = new WordFilter(words)\n * var param_1 = obj.f(prefix,suffix)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define word-filter%\n (class object%\n (super-new)\n\n ; words : (listof string?)\n (init-field\n words)\n \n ; f : string? string? -> exact-integer?\n (define/public (f prefix suffix)\n\n )))\n\n;; Your word-filter% object will be instantiated and called as such:\n;; (define obj (new word-filter% [words words]))\n;; (define param_1 (send obj f prefix suffix))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0745](https://leetcode-cn.com/problems/prefix-and-suffix-search)", "[\u524d\u7f00\u548c\u540e\u7f00\u641c\u7d22](/solution/0700-0799/0745.Prefix%20and%20Suffix%20Search/README.md)", "`\u5b57\u5178\u6811`", "\u56f0\u96be", ""], "md_table_row_en": ["[0745](https://leetcode.com/problems/prefix-and-suffix-search)", "[Prefix and Suffix Search](/solution/0700-0799/0745.Prefix%20and%20Suffix%20Search/README_EN.md)", "`Trie`", "Hard", ""]}, {"question_id": "0745", "frontend_question_id": "0744", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-smallest-letter-greater-than-target", "url_en": "https://leetcode.com/problems/find-smallest-letter-greater-than-target", "relative_path_cn": "/solution/0700-0799/0744.Find%20Smallest%20Letter%20Greater%20Than%20Target/README.md", "relative_path_en": "/solution/0700-0799/0744.Find%20Smallest%20Letter%20Greater%20Than%20Target/README_EN.md", "title_cn": "\u5bfb\u627e\u6bd4\u76ee\u6807\u5b57\u6bcd\u5927\u7684\u6700\u5c0f\u5b57\u6bcd", "title_en": "Find Smallest Letter Greater Than Target", "question_title_slug": "find-smallest-letter-greater-than-target", "content_en": "

    Given a characters array letters that is sorted in non-decreasing order and a character target, return the smallest character in the array that is larger than target.

    \n\n

    Note that the letters wrap around.

    \n\n
      \n\t
    • For example, if target == 'z' and letters == ['a', 'b'], the answer is 'a'.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: letters = ["c","f","j"], target = "a"\nOutput: "c"\n
    \n\n

    Example 2:

    \n\n
    \nInput: letters = ["c","f","j"], target = "c"\nOutput: "f"\n
    \n\n

    Example 3:

    \n\n
    \nInput: letters = ["c","f","j"], target = "d"\nOutput: "f"\n
    \n\n

    Example 4:

    \n\n
    \nInput: letters = ["c","f","j"], target = "g"\nOutput: "j"\n
    \n\n

    Example 5:

    \n\n
    \nInput: letters = ["c","f","j"], target = "j"\nOutput: "c"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= letters.length <= 104
    • \n\t
    • letters[i] is a lowercase English letter.
    • \n\t
    • letters is sorted in non-decreasing order.
    • \n\t
    • letters contains at least two different characters.
    • \n\t
    • target is a lowercase English letter.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6392\u5e8f\u540e\u7684\u5b57\u7b26\u5217\u8868 letters \uff0c\u5217\u8868\u4e2d\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002\u53e6\u7ed9\u51fa\u4e00\u4e2a\u76ee\u6807\u5b57\u6bcd target\uff0c\u8bf7\u4f60\u5bfb\u627e\u5728\u8fd9\u4e00\u6709\u5e8f\u5217\u8868\u91cc\u6bd4\u76ee\u6807\u5b57\u6bcd\u5927\u7684\u6700\u5c0f\u5b57\u6bcd\u3002

    \n\n

    \u5728\u6bd4\u8f83\u65f6\uff0c\u5b57\u6bcd\u662f\u4f9d\u5e8f\u5faa\u73af\u51fa\u73b0\u7684\u3002\u4e3e\u4e2a\u4f8b\u5b50\uff1a

    \n\n
      \n\t
    • \u5982\u679c\u76ee\u6807\u5b57\u6bcd target = 'z' \u5e76\u4e14\u5b57\u7b26\u5217\u8868\u4e3a letters = ['a', 'b']\uff0c\u5219\u7b54\u6848\u8fd4\u56de 'a'
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165:\nletters = ["c", "f", "j"]\ntarget = "a"\n\u8f93\u51fa: "c"\n\n\u8f93\u5165:\nletters = ["c", "f", "j"]\ntarget = "c"\n\u8f93\u51fa: "f"\n\n\u8f93\u5165:\nletters = ["c", "f", "j"]\ntarget = "d"\n\u8f93\u51fa: "f"\n\n\u8f93\u5165:\nletters = ["c", "f", "j"]\ntarget = "g"\n\u8f93\u51fa: "j"\n\n\u8f93\u5165:\nletters = ["c", "f", "j"]\ntarget = "j"\n\u8f93\u51fa: "c"\n\n\u8f93\u5165:\nletters = ["c", "f", "j"]\ntarget = "k"\n\u8f93\u51fa: "c"\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. letters\u957f\u5ea6\u8303\u56f4\u5728[2, 10000]\u533a\u95f4\u5185\u3002
    2. \n\t
    3. letters \u4ec5\u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210\uff0c\u6700\u5c11\u5305\u542b\u4e24\u4e2a\u4e0d\u540c\u7684\u5b57\u6bcd\u3002
    4. \n\t
    5. \u76ee\u6807\u5b57\u6bcdtarget \u662f\u4e00\u4e2a\u5c0f\u5199\u5b57\u6bcd\u3002
    6. \n
    \n", "tags_en": ["Binary Search"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n char nextGreatestLetter(vector& letters, char target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public char nextGreatestLetter(char[] letters, char target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def nextGreatestLetter(self, letters, target):\n \"\"\"\n :type letters: List[str]\n :type target: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def nextGreatestLetter(self, letters: List[str], target: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar nextGreatestLetter(char* letters, int lettersSize, char target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public char NextGreatestLetter(char[] letters, char target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {character[]} letters\n * @param {character} target\n * @return {character}\n */\nvar nextGreatestLetter = function(letters, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Character[]} letters\n# @param {Character} target\n# @return {Character}\ndef next_greatest_letter(letters, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func nextGreatestLetter(_ letters: [Character], _ target: Character) -> Character {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func nextGreatestLetter(letters []byte, target byte) byte {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def nextGreatestLetter(letters: Array[Char], target: Char): Char = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun nextGreatestLetter(letters: CharArray, target: Char): Char {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn next_greatest_letter(letters: Vec, target: char) -> char {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $letters\n * @param String $target\n * @return String\n */\n function nextGreatestLetter($letters, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function nextGreatestLetter(letters: string[], target: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (next-greatest-letter letters target)\n (-> (listof char?) char? char?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0744](https://leetcode-cn.com/problems/find-smallest-letter-greater-than-target)", "[\u5bfb\u627e\u6bd4\u76ee\u6807\u5b57\u6bcd\u5927\u7684\u6700\u5c0f\u5b57\u6bcd](/solution/0700-0799/0744.Find%20Smallest%20Letter%20Greater%20Than%20Target/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u7b80\u5355", ""], "md_table_row_en": ["[0744](https://leetcode.com/problems/find-smallest-letter-greater-than-target)", "[Find Smallest Letter Greater Than Target](/solution/0700-0799/0744.Find%20Smallest%20Letter%20Greater%20Than%20Target/README_EN.md)", "`Binary Search`", "Easy", ""]}, {"question_id": "0744", "frontend_question_id": "0743", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/network-delay-time", "url_en": "https://leetcode.com/problems/network-delay-time", "relative_path_cn": "/solution/0700-0799/0743.Network%20Delay%20Time/README.md", "relative_path_en": "/solution/0700-0799/0743.Network%20Delay%20Time/README_EN.md", "title_cn": "\u7f51\u7edc\u5ef6\u8fdf\u65f6\u95f4", "title_en": "Network Delay Time", "question_title_slug": "network-delay-time", "content_en": "

    You are given a network of n nodes, labeled from 1 to n. You are also given times, a list of travel times as directed edges times[i] = (ui, vi, wi), where ui is the source node, vi is the target node, and wi is the time it takes for a signal to travel from source to target.

    \n\n

    We will send a signal from a given node k. Return the time it takes for all the n nodes to receive the signal. If it is impossible for all the n nodes to receive the signal, return -1.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: times = [[2,1,1],[2,3,1],[3,4,1]], n = 4, k = 2\nOutput: 2\n
    \n\n

    Example 2:

    \n\n
    \nInput: times = [[1,2,1]], n = 2, k = 1\nOutput: 1\n
    \n\n

    Example 3:

    \n\n
    \nInput: times = [[1,2,1]], n = 2, k = 2\nOutput: -1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= k <= n <= 100
    • \n\t
    • 1 <= times.length <= 6000
    • \n\t
    • times[i].length == 3
    • \n\t
    • 1 <= ui, vi <= n
    • \n\t
    • ui != vi
    • \n\t
    • 0 <= wi <= 100
    • \n\t
    • All the pairs (ui, vi) are unique. (i.e., no multiple edges.)
    • \n
    \n", "content_cn": "

    \u6709 n \u4e2a\u7f51\u7edc\u8282\u70b9\uff0c\u6807\u8bb0\u4e3a\u00a01\u00a0\u5230 n\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u5217\u8868\u00a0times\uff0c\u8868\u793a\u4fe1\u53f7\u7ecf\u8fc7 \u6709\u5411 \u8fb9\u7684\u4f20\u9012\u65f6\u95f4\u3002\u00a0times[i] = (ui, vi, wi)\uff0c\u5176\u4e2d\u00a0ui\u00a0\u662f\u6e90\u8282\u70b9\uff0cvi\u00a0\u662f\u76ee\u6807\u8282\u70b9\uff0c wi\u00a0\u662f\u4e00\u4e2a\u4fe1\u53f7\u4ece\u6e90\u8282\u70b9\u4f20\u9012\u5230\u76ee\u6807\u8282\u70b9\u7684\u65f6\u95f4\u3002

    \n\n

    \u73b0\u5728\uff0c\u4ece\u67d0\u4e2a\u8282\u70b9\u00a0K\u00a0\u53d1\u51fa\u4e00\u4e2a\u4fe1\u53f7\u3002\u9700\u8981\u591a\u4e45\u624d\u80fd\u4f7f\u6240\u6709\u8282\u70b9\u90fd\u6536\u5230\u4fe1\u53f7\uff1f\u5982\u679c\u4e0d\u80fd\u4f7f\u6240\u6709\u8282\u70b9\u6536\u5230\u4fe1\u53f7\uff0c\u8fd4\u56de\u00a0-1 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1atimes = [[2,1,1],[2,3,1],[3,4,1]], n = 4, k = 2\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1atimes = [[1,2,1]], n = 2, k = 1\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1atimes = [[1,2,1]], n = 2, k = 2\n\u8f93\u51fa\uff1a-1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= k <= n <= 100
    • \n\t
    • 1 <= times.length <= 6000
    • \n\t
    • times[i].length == 3
    • \n\t
    • 1 <= ui, vi <= n
    • \n\t
    • ui != vi
    • \n\t
    • 0 <= wi <= 100
    • \n\t
    • \u6240\u6709 (ui, vi) \u5bf9\u90fd \u4e92\u4e0d\u76f8\u540c\uff08\u5373\uff0c\u4e0d\u542b\u91cd\u590d\u8fb9\uff09
    • \n
    \n", "tags_en": ["Heap", "Depth-first Search", "Breadth-first Search", "Graph"], "tags_cn": ["\u5806", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int networkDelayTime(vector>& times, int n, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int networkDelayTime(int[][] times, int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def networkDelayTime(self, times, n, k):\n \"\"\"\n :type times: List[List[int]]\n :type n: int\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def networkDelayTime(self, times: List[List[int]], n: int, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint networkDelayTime(int** times, int timesSize, int* timesColSize, int n, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NetworkDelayTime(int[][] times, int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} times\n * @param {number} n\n * @param {number} k\n * @return {number}\n */\nvar networkDelayTime = function(times, n, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} times\n# @param {Integer} n\n# @param {Integer} k\n# @return {Integer}\ndef network_delay_time(times, n, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func networkDelayTime(_ times: [[Int]], _ n: Int, _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func networkDelayTime(times [][]int, n int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def networkDelayTime(times: Array[Array[Int]], n: Int, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun networkDelayTime(times: Array, n: Int, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn network_delay_time(times: Vec>, n: i32, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $times\n * @param Integer $n\n * @param Integer $k\n * @return Integer\n */\n function networkDelayTime($times, $n, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function networkDelayTime(times: number[][], n: number, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (network-delay-time times n k)\n (-> (listof (listof exact-integer?)) exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0743](https://leetcode-cn.com/problems/network-delay-time)", "[\u7f51\u7edc\u5ef6\u8fdf\u65f6\u95f4](/solution/0700-0799/0743.Network%20Delay%20Time/README.md)", "`\u5806`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u56fe`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0743](https://leetcode.com/problems/network-delay-time)", "[Network Delay Time](/solution/0700-0799/0743.Network%20Delay%20Time/README_EN.md)", "`Heap`,`Depth-first Search`,`Breadth-first Search`,`Graph`", "Medium", ""]}, {"question_id": "0743", "frontend_question_id": "0742", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/closest-leaf-in-a-binary-tree", "url_en": "https://leetcode.com/problems/closest-leaf-in-a-binary-tree", "relative_path_cn": "/solution/0700-0799/0742.Closest%20Leaf%20in%20a%20Binary%20Tree/README.md", "relative_path_en": "/solution/0700-0799/0742.Closest%20Leaf%20in%20a%20Binary%20Tree/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u6700\u8fd1\u7684\u53f6\u8282\u70b9", "title_en": "Closest Leaf in a Binary Tree", "question_title_slug": "closest-leaf-in-a-binary-tree", "content_en": "

    Given a binary tree where every node has a unique value, and a target key k, find the value of the nearest leaf node to target k in the tree.\r\n

    \r\nHere, nearest to a leaf means the least number of edges travelled on the binary tree to reach any leaf of the tree. Also, a node is called a leaf if it has no children.\r\n

    \r\nIn the following examples, the input tree is represented in flattened form row by row.\r\nThe actual root tree given will be a TreeNode object.\r\n

    \r\nExample 1:\r\n

    \r\nInput:\r\nroot = [1, 3, 2], k = 1\r\nDiagram of binary tree:\r\n          1\r\n         / \\\r\n        3   2\r\n\r\nOutput: 2 (or 3)\r\n\r\nExplanation: Either 2 or 3 is the nearest leaf node to the target of 1.\r\n
    \r\n

    \r\nExample 2:\r\n

    \r\nInput:\r\nroot = [1], k = 1\r\nOutput: 1\r\n\r\nExplanation: The nearest leaf node is the root node itself.\r\n
    \r\n

    \r\n\r\n

    \r\nExample 3:\r\n

    \r\nInput:\r\nroot = [1,2,3,4,null,null,null,5,null,6], k = 2\r\nDiagram of binary tree:\r\n             1\r\n            / \\\r\n           2   3\r\n          /\r\n         4\r\n        /\r\n       5\r\n      /\r\n     6\r\n\r\nOutput: 3\r\nExplanation: The leaf node with value 3 (and not the leaf node with value 6) is nearest to the node with value 2.\r\n
    \r\n

    \r\n\r\n

    Note:
    \r\n

      \r\n
    1. root represents a binary tree with at least 1 node and at most 1000 nodes.
    2. \r\n
    3. Every node has a unique node.val in range [1, 1000].
    4. \r\n
    5. There exists some node in the given binary tree for which node.val == k.
    6. \r\n
    \r\n

    ", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a \u6bcf\u4e2a\u7ed3\u70b9\u7684\u503c\u4e92\u4e0d\u76f8\u540c \u7684\u4e8c\u53c9\u6811\uff0c\u548c\u4e00\u4e2a\u76ee\u6807\u503c k\uff0c\u627e\u51fa\u6811\u4e2d\u4e0e\u76ee\u6807\u503c k \u6700\u8fd1\u7684\u53f6\u7ed3\u70b9\u3002 

    \n\n

    \u8fd9\u91cc\uff0c\u4e0e\u53f6\u7ed3\u70b9 \u6700\u8fd1 \u8868\u793a\u5728\u4e8c\u53c9\u6811\u4e2d\u5230\u8fbe\u8be5\u53f6\u8282\u70b9\u9700\u8981\u884c\u8fdb\u7684\u8fb9\u6570\u4e0e\u5230\u8fbe\u5176\u5b83\u53f6\u7ed3\u70b9\u76f8\u6bd4\u6700\u5c11\u3002\u800c\u4e14\uff0c\u5f53\u4e00\u4e2a\u7ed3\u70b9\u6ca1\u6709\u5b69\u5b50\u7ed3\u70b9\u65f6\u79f0\u5176\u4e3a\u53f6\u7ed3\u70b9\u3002

    \n\n

    \u5728\u4e0b\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c\u8f93\u5165\u7684\u6811\u4ee5\u9010\u884c\u7684\u5e73\u94fa\u5f62\u5f0f\u8868\u793a\u3002\u5b9e\u9645\u4e0a\u7684\u6709\u6839\u6811 root \u5c06\u4ee5TreeNode\u5bf9\u8c61\u7684\u5f62\u5f0f\u7ed9\u51fa\u3002

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a\nroot = [1, 3, 2], k = 1\n\u4e8c\u53c9\u6811\u56fe\u793a\uff1a\n          1\n         / \\\n        3   2\n\n\u8f93\u51fa\uff1a 2 (\u6216 3)\n\n\u89e3\u91ca\uff1a 2 \u548c 3 \u90fd\u662f\u8ddd\u79bb\u76ee\u6807 1 \u6700\u8fd1\u7684\u53f6\u8282\u70b9\u3002\n
    \n\n

     

    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a\nroot = [1], k = 1\n\u8f93\u51fa\uff1a1\n\n\u89e3\u91ca\uff1a \u6700\u8fd1\u7684\u53f6\u8282\u70b9\u662f\u6839\u7ed3\u70b9\u81ea\u8eab\u3002\n
    \n\n

     

    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1a\nroot = [1,2,3,4,null,null,null,5,null,6], k = 2\n\u4e8c\u53c9\u6811\u56fe\u793a\uff1a\n             1\n            / \\\n           2   3\n          /\n         4\n        /\n       5\n      /\n     6\n\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a \u503c\u4e3a 3\uff08\u800c\u4e0d\u662f\u503c\u4e3a 6\uff09\u7684\u53f6\u8282\u70b9\u662f\u8ddd\u79bb\u7ed3\u70b9 2 \u7684\u6700\u8fd1\u7ed3\u70b9\u3002\n
    \n\n

     

    \n\n

    \u6ce8\uff1a

    \n\n
      \n\t
    1. root \u8868\u793a\u7684\u4e8c\u53c9\u6811\u6700\u5c11\u6709 1 \u4e2a\u7ed3\u70b9\u4e14\u6700\u591a\u6709 1000 \u4e2a\u7ed3\u70b9\u3002
    2. \n\t
    3. \u6bcf\u4e2a\u7ed3\u70b9\u90fd\u6709\u4e00\u4e2a\u552f\u4e00\u7684 node.val \uff0c\u8303\u56f4\u4e3a [1, 1000]\u3002
    4. \n\t
    5. \u7ed9\u5b9a\u7684\u4e8c\u53c9\u6811\u4e2d\u6709\u67d0\u4e2a\u7ed3\u70b9\u4f7f\u5f97 node.val == k\u3002
    6. \n
    \n\n

     

    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int findClosestLeaf(TreeNode* root, int k) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int findClosestLeaf(TreeNode root, int k) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def findClosestLeaf(self, root, k):\n \"\"\"\n :type root: TreeNode\n :type k: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def findClosestLeaf(self, root: TreeNode, k: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint findClosestLeaf(struct TreeNode* root, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int FindClosestLeaf(TreeNode root, int k) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number} k\n * @return {number}\n */\nvar findClosestLeaf = function(root, k) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @param {Integer} k\n# @return {Integer}\ndef find_closest_leaf(root, k)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func findClosestLeaf(_ root: TreeNode?, _ k: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc findClosestLeaf(root *TreeNode, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def findClosestLeaf(root: TreeNode, k: Int): Int = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun findClosestLeaf(root: TreeNode?, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn find_closest_leaf(root: Option>>, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param Integer $k\n * @return Integer\n */\n function findClosestLeaf($root, $k) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction findClosestLeaf(root: TreeNode | null, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (find-closest-leaf root k)\n (-> (or/c tree-node? #f) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0742](https://leetcode-cn.com/problems/closest-leaf-in-a-binary-tree)", "[\u4e8c\u53c9\u6811\u6700\u8fd1\u7684\u53f6\u8282\u70b9](/solution/0700-0799/0742.Closest%20Leaf%20in%20a%20Binary%20Tree/README.md)", "`\u6811`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0742](https://leetcode.com/problems/closest-leaf-in-a-binary-tree)", "[Closest Leaf in a Binary Tree](/solution/0700-0799/0742.Closest%20Leaf%20in%20a%20Binary%20Tree/README_EN.md)", "`Tree`", "Medium", "\ud83d\udd12"]}, {"question_id": "0742", "frontend_question_id": "0709", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/to-lower-case", "url_en": "https://leetcode.com/problems/to-lower-case", "relative_path_cn": "/solution/0700-0799/0709.To%20Lower%20Case/README.md", "relative_path_en": "/solution/0700-0799/0709.To%20Lower%20Case/README_EN.md", "title_cn": "\u8f6c\u6362\u6210\u5c0f\u5199\u5b57\u6bcd", "title_en": "To Lower Case", "question_title_slug": "to-lower-case", "content_en": "

    Given a string s, return the string after replacing every uppercase letter with the same lowercase letter.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "Hello"\nOutput: "hello"\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "here"\nOutput: "here"\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "LOVELY"\nOutput: "lovely"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 100
    • \n\t
    • s consists of printable ASCII characters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \uff0c\u5c06\u8be5\u5b57\u7b26\u4e32\u4e2d\u7684\u5927\u5199\u5b57\u6bcd\u8f6c\u6362\u6210\u76f8\u540c\u7684\u5c0f\u5199\u5b57\u6bcd\uff0c\u8fd4\u56de\u65b0\u7684\u5b57\u7b26\u4e32\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"Hello\"\n\u8f93\u51fa\uff1a\"hello\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"here\"\n\u8f93\u51fa\uff1a\"here\"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"LOVELY\"\n\u8f93\u51fa\uff1a\"lovely\"\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 100
    • \n\t
    • s \u7531 ASCII \u5b57\u7b26\u96c6\u4e2d\u7684\u53ef\u6253\u5370\u5b57\u7b26\u7ec4\u6210
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string toLowerCase(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String toLowerCase(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def toLowerCase(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def toLowerCase(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * toLowerCase(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ToLowerCase(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar toLowerCase = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef to_lower_case(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func toLowerCase(_ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func toLowerCase(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def toLowerCase(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun toLowerCase(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn to_lower_case(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function toLowerCase($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function toLowerCase(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (to-lower-case s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0709](https://leetcode-cn.com/problems/to-lower-case)", "[\u8f6c\u6362\u6210\u5c0f\u5199\u5b57\u6bcd](/solution/0700-0799/0709.To%20Lower%20Case/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0709](https://leetcode.com/problems/to-lower-case)", "[To Lower Case](/solution/0700-0799/0709.To%20Lower%20Case/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "0741", "frontend_question_id": "0741", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/cherry-pickup", "url_en": "https://leetcode.com/problems/cherry-pickup", "relative_path_cn": "/solution/0700-0799/0741.Cherry%20Pickup/README.md", "relative_path_en": "/solution/0700-0799/0741.Cherry%20Pickup/README_EN.md", "title_cn": "\u6458\u6a31\u6843", "title_en": "Cherry Pickup", "question_title_slug": "cherry-pickup", "content_en": "

    You are given an n x n grid representing a field of cherries, each cell is one of three possible integers.

    \n\n
      \n\t
    • 0 means the cell is empty, so you can pass through,
    • \n\t
    • 1 means the cell contains a cherry that you can pick up and pass through, or
    • \n\t
    • -1 means the cell contains a thorn that blocks your way.
    • \n
    \n\n

    Return the maximum number of cherries you can collect by following the rules below:

    \n\n
      \n\t
    • Starting at the position (0, 0) and reaching (n - 1, n - 1) by moving right or down through valid path cells (cells with value 0 or 1).
    • \n\t
    • After reaching (n - 1, n - 1), returning to (0, 0) by moving left or up through valid path cells.
    • \n\t
    • When passing through a path cell containing a cherry, you pick it up, and the cell becomes an empty cell 0.
    • \n\t
    • If there is no valid path between (0, 0) and (n - 1, n - 1), then no cherries can be collected.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: grid = [[0,1,-1],[1,0,-1],[1,1,1]]\nOutput: 5\nExplanation: The player started at (0, 0) and went down, down, right right to reach (2, 2).\n4 cherries were picked up during this single trip, and the matrix becomes [[0,1,-1],[0,0,-1],[0,0,0]].\nThen, the player went left, up, up, left to return home, picking up one more cherry.\nThe total number of cherries picked up is 5, and this is the maximum possible.\n
    \n\n

    Example 2:

    \n\n
    \nInput: grid = [[1,1,-1],[1,-1,1],[-1,1,1]]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= n <= 50
    • \n\t
    • grid[i][j] is -1, 0, or 1.
    • \n\t
    • grid[0][0] != -1
    • \n\t
    • grid[n - 1][n - 1] != -1
    • \n
    \n", "content_cn": "

    \u4e00\u4e2aN x N\u7684\u7f51\u683c(grid) \u4ee3\u8868\u4e86\u4e00\u5757\u6a31\u6843\u5730\uff0c\u6bcf\u4e2a\u683c\u5b50\u7531\u4ee5\u4e0b\u4e09\u79cd\u6570\u5b57\u7684\u4e00\u79cd\u6765\u8868\u793a\uff1a

    \n\n
      \n\t
    • 0 \u8868\u793a\u8fd9\u4e2a\u683c\u5b50\u662f\u7a7a\u7684\uff0c\u6240\u4ee5\u4f60\u53ef\u4ee5\u7a7f\u8fc7\u5b83\u3002
    • \n\t
    • 1 \u8868\u793a\u8fd9\u4e2a\u683c\u5b50\u91cc\u88c5\u7740\u4e00\u4e2a\u6a31\u6843\uff0c\u4f60\u53ef\u4ee5\u6458\u5230\u6a31\u6843\u7136\u540e\u7a7f\u8fc7\u5b83\u3002
    • \n\t
    • -1 \u8868\u793a\u8fd9\u4e2a\u683c\u5b50\u91cc\u6709\u8346\u68d8\uff0c\u6321\u7740\u4f60\u7684\u8def\u3002
    • \n
    \n\n

    \u4f60\u7684\u4efb\u52a1\u662f\u5728\u9075\u5b88\u4e0b\u5217\u89c4\u5219\u7684\u60c5\u51b5\u4e0b\uff0c\u5c3d\u53ef\u80fd\u7684\u6458\u5230\u6700\u591a\u6a31\u6843\uff1a

    \n\n
      \n\t
    • \u4ece\u4f4d\u7f6e (0, 0) \u51fa\u53d1\uff0c\u6700\u540e\u5230\u8fbe (N-1, N-1) \uff0c\u53ea\u80fd\u5411\u4e0b\u6216\u5411\u53f3\u8d70\uff0c\u5e76\u4e14\u53ea\u80fd\u7a7f\u8d8a\u6709\u6548\u7684\u683c\u5b50\uff08\u5373\u53ea\u53ef\u4ee5\u7a7f\u8fc7\u503c\u4e3a0\u6216\u80051\u7684\u683c\u5b50\uff09\uff1b
    • \n\t
    • \u5f53\u5230\u8fbe (N-1, N-1) \u540e\uff0c\u4f60\u8981\u7ee7\u7eed\u8d70\uff0c\u76f4\u5230\u8fd4\u56de\u5230 (0, 0) \uff0c\u53ea\u80fd\u5411\u4e0a\u6216\u5411\u5de6\u8d70\uff0c\u5e76\u4e14\u53ea\u80fd\u7a7f\u8d8a\u6709\u6548\u7684\u683c\u5b50\uff1b
    • \n\t
    • \u5f53\u4f60\u7ecf\u8fc7\u4e00\u4e2a\u683c\u5b50\u4e14\u8fd9\u4e2a\u683c\u5b50\u5305\u542b\u4e00\u4e2a\u6a31\u6843\u65f6\uff0c\u4f60\u5c06\u6458\u5230\u6a31\u6843\u5e76\u4e14\u8fd9\u4e2a\u683c\u5b50\u4f1a\u53d8\u6210\u7a7a\u7684\uff08\u503c\u53d8\u4e3a0\uff09\uff1b
    • \n\t
    • \u5982\u679c\u5728 (0, 0) \u548c (N-1, N-1) \u4e4b\u95f4\u4e0d\u5b58\u5728\u4e00\u6761\u53ef\u7ecf\u8fc7\u7684\u8def\u5f84\uff0c\u5219\u6ca1\u6709\u4efb\u4f55\u4e00\u4e2a\u6a31\u6843\u80fd\u88ab\u6458\u5230\u3002
    • \n
    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: grid =\n[[0, 1, -1],\n [1, 0, -1],\n [1, 1,  1]]\n\u8f93\u51fa: 5\n\u89e3\u91ca\uff1a \n\u73a9\u5bb6\u4ece\uff080,0\uff09\u70b9\u51fa\u53d1\uff0c\u7ecf\u8fc7\u4e86\u5411\u4e0b\u8d70\uff0c\u5411\u4e0b\u8d70\uff0c\u5411\u53f3\u8d70\uff0c\u5411\u53f3\u8d70\uff0c\u5230\u8fbe\u4e86\u70b9(2, 2)\u3002\n\u5728\u8fd9\u8d9f\u5355\u7a0b\u4e2d\uff0c\u603b\u5171\u6458\u5230\u4e864\u9897\u6a31\u6843\uff0c\u77e9\u9635\u53d8\u6210\u4e86[[0,1,-1],[0,0,-1],[0,0,0]]\u3002\n\u63a5\u7740\uff0c\u8fd9\u540d\u73a9\u5bb6\u5411\u5de6\u8d70\uff0c\u5411\u4e0a\u8d70\uff0c\u5411\u4e0a\u8d70\uff0c\u5411\u5de6\u8d70\uff0c\u8fd4\u56de\u4e86\u8d77\u59cb\u70b9\uff0c\u53c8\u6458\u5230\u4e861\u9897\u6a31\u6843\u3002\n\u5728\u65c5\u7a0b\u4e2d\uff0c\u603b\u5171\u6458\u5230\u4e865\u9897\u6a31\u6843\uff0c\u8fd9\u662f\u53ef\u4ee5\u6458\u5230\u7684\u6700\u5927\u503c\u4e86\u3002\n
    \n\n

    \u8bf4\u660e:

    \n\n
      \n\t
    • grid \u662f\u4e00\u4e2a N * N \u7684\u4e8c\u7ef4\u6570\u7ec4\uff0cN\u7684\u53d6\u503c\u8303\u56f4\u662f1 <= N <= 50\u3002
    • \n\t
    • \u6bcf\u4e00\u4e2a grid[i][j] \u90fd\u662f\u96c6\u5408 {-1, 0, 1}\u5176\u4e2d\u7684\u4e00\u4e2a\u6570\u3002
    • \n\t
    • \u53ef\u4ee5\u4fdd\u8bc1\u8d77\u70b9 grid[0][0] \u548c\u7ec8\u70b9 grid[N-1][N-1] \u7684\u503c\u90fd\u4e0d\u4f1a\u662f -1\u3002
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int cherryPickup(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int cherryPickup(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def cherryPickup(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def cherryPickup(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint cherryPickup(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CherryPickup(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar cherryPickup = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef cherry_pickup(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func cherryPickup(_ grid: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func cherryPickup(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def cherryPickup(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun cherryPickup(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn cherry_pickup(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function cherryPickup($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function cherryPickup(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (cherry-pickup grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0741](https://leetcode-cn.com/problems/cherry-pickup)", "[\u6458\u6a31\u6843](/solution/0700-0799/0741.Cherry%20Pickup/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0741](https://leetcode.com/problems/cherry-pickup)", "[Cherry Pickup](/solution/0700-0799/0741.Cherry%20Pickup/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "0740", "frontend_question_id": "0740", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/delete-and-earn", "url_en": "https://leetcode.com/problems/delete-and-earn", "relative_path_cn": "/solution/0700-0799/0740.Delete%20and%20Earn/README.md", "relative_path_en": "/solution/0700-0799/0740.Delete%20and%20Earn/README_EN.md", "title_cn": "\u5220\u9664\u5e76\u83b7\u5f97\u70b9\u6570", "title_en": "Delete and Earn", "question_title_slug": "delete-and-earn", "content_en": "

    Given an array nums of integers, you can perform operations on the array.

    \n\n

    In each operation, you pick any nums[i] and delete it to earn nums[i] points. After, you must delete every element equal to nums[i] - 1 or nums[i] + 1.

    \n\n

    You start with 0 points. Return the maximum number of points you can earn by applying such operations.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [3,4,2]\nOutput: 6\nExplanation: Delete 4 to earn 4 points, consequently 3 is also deleted.\nThen, delete 2 to earn 2 points.\n6 total points are earned.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [2,2,3,3,3,4]\nOutput: 9\nExplanation: Delete 3 to earn 3 points, deleting both 2's and the 4.\nThen, delete 3 again to earn 3 points, and 3 again to earn 3 points.\n9 total points are earned.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 2 * 104
    • \n\t
    • 1 <= nums[i] <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0nums\u00a0\uff0c\u4f60\u53ef\u4ee5\u5bf9\u5b83\u8fdb\u884c\u4e00\u4e9b\u64cd\u4f5c\u3002

    \n\n

    \u6bcf\u6b21\u64cd\u4f5c\u4e2d\uff0c\u9009\u62e9\u4efb\u610f\u4e00\u4e2a\u00a0nums[i]\u00a0\uff0c\u5220\u9664\u5b83\u5e76\u83b7\u5f97\u00a0nums[i]\u00a0\u7684\u70b9\u6570\u3002\u4e4b\u540e\uff0c\u4f60\u5fc5\u987b\u5220\u9664 \u6240\u6709 \u7b49\u4e8e\u00a0nums[i] - 1 \u548c nums[i] + 1\u00a0\u7684\u5143\u7d20\u3002

    \n\n

    \u5f00\u59cb\u4f60\u62e5\u6709 0 \u4e2a\u70b9\u6570\u3002\u8fd4\u56de\u4f60\u80fd\u901a\u8fc7\u8fd9\u4e9b\u64cd\u4f5c\u83b7\u5f97\u7684\u6700\u5927\u70b9\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [3,4,2]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\n\u5220\u9664 4 \u83b7\u5f97 4 \u4e2a\u70b9\u6570\uff0c\u56e0\u6b64 3 \u4e5f\u88ab\u5220\u9664\u3002\n\u4e4b\u540e\uff0c\u5220\u9664 2 \u83b7\u5f97 2 \u4e2a\u70b9\u6570\u3002\u603b\u5171\u83b7\u5f97 6 \u4e2a\u70b9\u6570\u3002\n
    \n\n

    \u793a\u4f8b\u00a02\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [2,2,3,3,3,4]\n\u8f93\u51fa\uff1a9\n\u89e3\u91ca\uff1a\n\u5220\u9664 3 \u83b7\u5f97 3 \u4e2a\u70b9\u6570\uff0c\u63a5\u7740\u8981\u5220\u9664\u4e24\u4e2a 2 \u548c 4 \u3002\n\u4e4b\u540e\uff0c\u518d\u6b21\u5220\u9664 3 \u83b7\u5f97 3 \u4e2a\u70b9\u6570\uff0c\u518d\u6b21\u5220\u9664 3 \u83b7\u5f97 3 \u4e2a\u70b9\u6570\u3002\n\u603b\u5171\u83b7\u5f97 9 \u4e2a\u70b9\u6570\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 2 * 104
    • \n\t
    • 1 <= nums[i] <= 104
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int deleteAndEarn(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int deleteAndEarn(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def deleteAndEarn(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def deleteAndEarn(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint deleteAndEarn(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int DeleteAndEarn(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar deleteAndEarn = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef delete_and_earn(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func deleteAndEarn(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func deleteAndEarn(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def deleteAndEarn(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun deleteAndEarn(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn delete_and_earn(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function deleteAndEarn($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function deleteAndEarn(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (delete-and-earn nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0740](https://leetcode-cn.com/problems/delete-and-earn)", "[\u5220\u9664\u5e76\u83b7\u5f97\u70b9\u6570](/solution/0700-0799/0740.Delete%20and%20Earn/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0740](https://leetcode.com/problems/delete-and-earn)", "[Delete and Earn](/solution/0700-0799/0740.Delete%20and%20Earn/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0739", "frontend_question_id": "0739", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/daily-temperatures", "url_en": "https://leetcode.com/problems/daily-temperatures", "relative_path_cn": "/solution/0700-0799/0739.Daily%20Temperatures/README.md", "relative_path_en": "/solution/0700-0799/0739.Daily%20Temperatures/README_EN.md", "title_cn": "\u6bcf\u65e5\u6e29\u5ea6", "title_en": "Daily Temperatures", "question_title_slug": "daily-temperatures", "content_en": "

    Given an array of integers temperatures represents the daily temperatures, return an array answer such that answer[i] is the number of days you have to wait after the ith day to get a warmer temperature. If there is no future day for which this is possible, keep answer[i] == 0 instead.

    \n\n

     

    \n

    Example 1:

    \n
    Input: temperatures = [73,74,75,71,69,72,76,73]\nOutput: [1,1,4,2,1,1,0,0]\n

    Example 2:

    \n
    Input: temperatures = [30,40,50,60]\nOutput: [1,1,1,0]\n

    Example 3:

    \n
    Input: temperatures = [30,60,90]\nOutput: [1,1,0]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= temperatures.length <= 105
    • \n\t
    • 30 <= temperatures[i] <= 100
    • \n
    \n", "content_cn": "

    \u8bf7\u6839\u636e\u6bcf\u65e5 \u6c14\u6e29 \u5217\u8868\uff0c\u91cd\u65b0\u751f\u6210\u4e00\u4e2a\u5217\u8868\u3002\u5bf9\u5e94\u4f4d\u7f6e\u7684\u8f93\u51fa\u4e3a\uff1a\u8981\u60f3\u89c2\u6d4b\u5230\u66f4\u9ad8\u7684\u6c14\u6e29\uff0c\u81f3\u5c11\u9700\u8981\u7b49\u5f85\u7684\u5929\u6570\u3002\u5982\u679c\u6c14\u6e29\u5728\u8fd9\u4e4b\u540e\u90fd\u4e0d\u4f1a\u5347\u9ad8\uff0c\u8bf7\u5728\u8be5\u4f4d\u7f6e\u7528 0 \u6765\u4ee3\u66ff\u3002

    \n\n

    \u4f8b\u5982\uff0c\u7ed9\u5b9a\u4e00\u4e2a\u5217\u8868 temperatures = [73, 74, 75, 71, 69, 72, 76, 73]\uff0c\u4f60\u7684\u8f93\u51fa\u5e94\u8be5\u662f [1, 1, 4, 2, 1, 1, 0, 0]\u3002

    \n\n

    \u63d0\u793a\uff1a\u6c14\u6e29 \u5217\u8868\u957f\u5ea6\u7684\u8303\u56f4\u662f [1, 30000]\u3002\u6bcf\u4e2a\u6c14\u6e29\u7684\u503c\u7684\u5747\u4e3a\u534e\u6c0f\u5ea6\uff0c\u90fd\u662f\u5728 [30, 100] \u8303\u56f4\u5185\u7684\u6574\u6570\u3002

    \n", "tags_en": ["Stack", "Hash Table"], "tags_cn": ["\u6808", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector dailyTemperatures(vector& temperatures) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] dailyTemperatures(int[] temperatures) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def dailyTemperatures(self, temperatures):\n \"\"\"\n :type temperatures: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def dailyTemperatures(self, temperatures: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* dailyTemperatures(int* temperatures, int temperaturesSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] DailyTemperatures(int[] temperatures) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} temperatures\n * @return {number[]}\n */\nvar dailyTemperatures = function(temperatures) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} temperatures\n# @return {Integer[]}\ndef daily_temperatures(temperatures)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func dailyTemperatures(_ temperatures: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func dailyTemperatures(temperatures []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def dailyTemperatures(temperatures: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun dailyTemperatures(temperatures: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn daily_temperatures(temperatures: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $temperatures\n * @return Integer[]\n */\n function dailyTemperatures($temperatures) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function dailyTemperatures(temperatures: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (daily-temperatures temperatures)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0739](https://leetcode-cn.com/problems/daily-temperatures)", "[\u6bcf\u65e5\u6e29\u5ea6](/solution/0700-0799/0739.Daily%20Temperatures/README.md)", "`\u6808`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0739](https://leetcode.com/problems/daily-temperatures)", "[Daily Temperatures](/solution/0700-0799/0739.Daily%20Temperatures/README_EN.md)", "`Stack`,`Hash Table`", "Medium", ""]}, {"question_id": "0738", "frontend_question_id": "0738", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/monotone-increasing-digits", "url_en": "https://leetcode.com/problems/monotone-increasing-digits", "relative_path_cn": "/solution/0700-0799/0738.Monotone%20Increasing%20Digits/README.md", "relative_path_en": "/solution/0700-0799/0738.Monotone%20Increasing%20Digits/README_EN.md", "title_cn": "\u5355\u8c03\u9012\u589e\u7684\u6570\u5b57", "title_en": "Monotone Increasing Digits", "question_title_slug": "monotone-increasing-digits", "content_en": "

    An integer has monotone increasing digits if and only if each pair of adjacent digits x and y satisfy x <= y.

    \n\n

    Given an integer n, return the largest number that is less than or equal to n with monotone increasing digits.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 10\nOutput: 9\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 1234\nOutput: 1234\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 332\nOutput: 299\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= n <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u8d1f\u6574\u6570 N\uff0c\u627e\u51fa\u5c0f\u4e8e\u6216\u7b49\u4e8e N \u7684\u6700\u5927\u7684\u6574\u6570\uff0c\u540c\u65f6\u8fd9\u4e2a\u6574\u6570\u9700\u8981\u6ee1\u8db3\u5176\u5404\u4e2a\u4f4d\u6570\u4e0a\u7684\u6570\u5b57\u662f\u5355\u8c03\u9012\u589e\u3002

    \n\n

    \uff08\u5f53\u4e14\u4ec5\u5f53\u6bcf\u4e2a\u76f8\u90bb\u4f4d\u6570\u4e0a\u7684\u6570\u5b57 x \u548c y \u6ee1\u8db3 x <= y \u65f6\uff0c\u6211\u4eec\u79f0\u8fd9\u4e2a\u6574\u6570\u662f\u5355\u8c03\u9012\u589e\u7684\u3002\uff09

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: N = 10\n\u8f93\u51fa: 9\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: N = 1234\n\u8f93\u51fa: 1234\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u8f93\u5165: N = 332\n\u8f93\u51fa: 299\n
    \n\n

    \u8bf4\u660e: N \u662f\u5728 [0, 10^9] \u8303\u56f4\u5185\u7684\u4e00\u4e2a\u6574\u6570\u3002

    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int monotoneIncreasingDigits(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int monotoneIncreasingDigits(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def monotoneIncreasingDigits(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def monotoneIncreasingDigits(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint monotoneIncreasingDigits(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MonotoneIncreasingDigits(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar monotoneIncreasingDigits = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef monotone_increasing_digits(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func monotoneIncreasingDigits(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func monotoneIncreasingDigits(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def monotoneIncreasingDigits(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun monotoneIncreasingDigits(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn monotone_increasing_digits(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function monotoneIncreasingDigits($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function monotoneIncreasingDigits(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (monotone-increasing-digits n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0738](https://leetcode-cn.com/problems/monotone-increasing-digits)", "[\u5355\u8c03\u9012\u589e\u7684\u6570\u5b57](/solution/0700-0799/0738.Monotone%20Increasing%20Digits/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0738](https://leetcode.com/problems/monotone-increasing-digits)", "[Monotone Increasing Digits](/solution/0700-0799/0738.Monotone%20Increasing%20Digits/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "0737", "frontend_question_id": "0737", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/sentence-similarity-ii", "url_en": "https://leetcode.com/problems/sentence-similarity-ii", "relative_path_cn": "/solution/0700-0799/0737.Sentence%20Similarity%20II/README.md", "relative_path_en": "/solution/0700-0799/0737.Sentence%20Similarity%20II/README_EN.md", "title_cn": "\u53e5\u5b50\u76f8\u4f3c\u6027 II", "title_en": "Sentence Similarity II", "question_title_slug": "sentence-similarity-ii", "content_en": "

    We can represent a sentence as an array of words, for example, the sentence "I am happy with leetcode" can be represented as arr = ["I","am",happy","with","leetcode"].

    \n\n

    Given two sentences sentence1 and sentence2 each represented as a string array and given an array of string pairs similarPairs where similarPairs[i] = [xi, yi] indicates that the two words xi and yi are similar.

    \n\n

    Return true if sentence1 and sentence2 are similar, or false if they are not similar.

    \n\n

    Two sentences are similar if:

    \n\n
      \n\t
    • They have the same length (i.e., the same number of words)
    • \n\t
    • sentence1[i] and sentence2[i] are similar.
    • \n
    \n\n

    Notice that a word is always similar to itself, also notice that the similarity relation is transitive. For example, if the words a and b are similar, and the words b and c are similar, then a and c are similar.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: sentence1 = ["great","acting","skills"], sentence2 = ["fine","drama","talent"], similarPairs = [["great","good"],["fine","good"],["drama","acting"],["skills","talent"]]\nOutput: true\nExplanation: The two sentences have the same length and each word i of sentence1 is also similar to the corresponding word in sentence2.\n
    \n\n

    Example 2:

    \n\n
    \nInput: sentence1 = ["I","love","leetcode"], sentence2 = ["I","love","onepiece"], similarPairs = [["manga","onepiece"],["platform","anime"],["leetcode","platform"],["anime","manga"]]\nOutput: true\nExplanation: "leetcode" --> "platform" --> "anime" --> "manga" --> "onepiece".\nSince "leetcode is similar to "onepiece" and the first two words are the same, the two sentences are similar.
    \n\n

    Example 3:

    \n\n
    \nInput: sentence1 = ["I","love","leetcode"], sentence2 = ["I","love","onepiece"], similarPairs = [["manga","hunterXhunter"],["platform","anime"],["leetcode","platform"],["anime","manga"]]\nOutput: false\nExplanation: "leetcode" is not similar to "onepiece".\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= sentence1.length, sentence2.length <= 1000
    • \n\t
    • 1 <= sentence1[i].length, sentence2[i].length <= 20
    • \n\t
    • sentence1[i] and sentence2[i] consist of lower-case and upper-case English letters.
    • \n\t
    • 0 <= similarPairs.length <= 2000
    • \n\t
    • similarPairs[i].length == 2
    • \n\t
    • 1 <= xi.length, yi.length <= 20
    • \n\t
    • xi and yi consist of English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u53e5\u5b50 words1, words2 \uff08\u6bcf\u4e2a\u7528\u5b57\u7b26\u4e32\u6570\u7ec4\u8868\u793a\uff09\uff0c\u548c\u4e00\u4e2a\u76f8\u4f3c\u5355\u8bcd\u5bf9\u7684\u5217\u8868 pairs \uff0c\u5224\u65ad\u662f\u5426\u4e24\u4e2a\u53e5\u5b50\u662f\u76f8\u4f3c\u7684\u3002

    \n\n

    \u4f8b\u5982\uff0c\u5f53\u76f8\u4f3c\u5355\u8bcd\u5bf9\u662f pairs = [["great", "fine"], ["acting","drama"], ["skills","talent"]]\u7684\u65f6\u5019\uff0cwords1 = ["great", "acting", "skills"] \u548c words2 = ["fine", "drama", "talent"] \u662f\u76f8\u4f3c\u7684\u3002

    \n\n

    \u6ce8\u610f\u76f8\u4f3c\u5173\u7cfb\u662f \u5177\u6709 \u4f20\u9012\u6027\u7684\u3002\u4f8b\u5982\uff0c\u5982\u679c "great" \u548c "fine" \u662f\u76f8\u4f3c\u7684\uff0c"fine" \u548c "good" \u662f\u76f8\u4f3c\u7684\uff0c\u5219 "great" \u548c "good" \u662f\u76f8\u4f3c\u7684\u3002

    \n\n

    \u800c\u4e14\uff0c\u76f8\u4f3c\u5173\u7cfb\u662f\u5177\u6709\u5bf9\u79f0\u6027\u7684\u3002\u4f8b\u5982\uff0c"great" \u548c "fine" \u662f\u76f8\u4f3c\u7684\u76f8\u5f53\u4e8e "fine" \u548c "great" \u662f\u76f8\u4f3c\u7684\u3002

    \n\n

    \u5e76\u4e14\uff0c\u4e00\u4e2a\u5355\u8bcd\u603b\u662f\u4e0e\u5176\u81ea\u8eab\u76f8\u4f3c\u3002\u4f8b\u5982\uff0c\u53e5\u5b50 words1 = ["great"], words2 = ["great"], pairs = [] \u662f\u76f8\u4f3c\u7684\uff0c\u5c3d\u7ba1\u6ca1\u6709\u8f93\u5165\u7279\u5b9a\u7684\u76f8\u4f3c\u5355\u8bcd\u5bf9\u3002

    \n\n

    \u6700\u540e\uff0c\u53e5\u5b50\u53ea\u4f1a\u5728\u5177\u6709\u76f8\u540c\u5355\u8bcd\u4e2a\u6570\u7684\u524d\u63d0\u4e0b\u624d\u4f1a\u76f8\u4f3c\u3002\u6240\u4ee5\u4e00\u4e2a\u53e5\u5b50 words1 = ["great"] \u6c38\u8fdc\u4e0d\u53ef\u80fd\u548c\u53e5\u5b50 words2 = ["doubleplus","good"] \u76f8\u4f3c\u3002

    \n\n

    \u6ce8\uff1a

    \n\n
      \n\t
    • words1 and words2 \u7684\u957f\u5ea6\u4e0d\u4f1a\u8d85\u8fc7 1000\u3002
    • \n\t
    • pairs \u7684\u957f\u5ea6\u4e0d\u4f1a\u8d85\u8fc7 2000\u3002
    • \n\t
    • \u6bcf\u4e2apairs[i] \u7684\u957f\u5ea6\u4e3a 2\u3002
    • \n\t
    • \u6bcf\u4e2a words[i] \u548c pairs[i][j] \u7684\u957f\u5ea6\u8303\u56f4\u4e3a [1, 20]\u3002
    • \n
    \n", "tags_en": ["Depth-first Search", "Union Find"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e76\u67e5\u96c6"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool areSentencesSimilarTwo(vector& sentence1, vector& sentence2, vector>& similarPairs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean areSentencesSimilarTwo(String[] sentence1, String[] sentence2, List> similarPairs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def areSentencesSimilarTwo(self, sentence1, sentence2, similarPairs):\n \"\"\"\n :type sentence1: List[str]\n :type sentence2: List[str]\n :type similarPairs: List[List[str]]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def areSentencesSimilarTwo(self, sentence1: List[str], sentence2: List[str], similarPairs: List[List[str]]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool areSentencesSimilarTwo(char ** sentence1, int sentence1Size, char ** sentence2, int sentence2Size, char *** similarPairs, int similarPairsSize, int* similarPairsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool AreSentencesSimilarTwo(string[] sentence1, string[] sentence2, IList> similarPairs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} sentence1\n * @param {string[]} sentence2\n * @param {string[][]} similarPairs\n * @return {boolean}\n */\nvar areSentencesSimilarTwo = function(sentence1, sentence2, similarPairs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} sentence1\n# @param {String[]} sentence2\n# @param {String[][]} similar_pairs\n# @return {Boolean}\ndef are_sentences_similar_two(sentence1, sentence2, similar_pairs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func areSentencesSimilarTwo(_ sentence1: [String], _ sentence2: [String], _ similarPairs: [[String]]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func areSentencesSimilarTwo(sentence1 []string, sentence2 []string, similarPairs [][]string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def areSentencesSimilarTwo(sentence1: Array[String], sentence2: Array[String], similarPairs: List[List[String]]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun areSentencesSimilarTwo(sentence1: Array, sentence2: Array, similarPairs: List>): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn are_sentences_similar_two(sentence1: Vec, sentence2: Vec, similar_pairs: Vec>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $sentence1\n * @param String[] $sentence2\n * @param String[][] $similarPairs\n * @return Boolean\n */\n function areSentencesSimilarTwo($sentence1, $sentence2, $similarPairs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function areSentencesSimilarTwo(sentence1: string[], sentence2: string[], similarPairs: string[][]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (are-sentences-similar-two sentence1 sentence2 similarPairs)\n (-> (listof string?) (listof string?) (listof (listof string?)) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0737](https://leetcode-cn.com/problems/sentence-similarity-ii)", "[\u53e5\u5b50\u76f8\u4f3c\u6027 II](/solution/0700-0799/0737.Sentence%20Similarity%20II/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e76\u67e5\u96c6`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0737](https://leetcode.com/problems/sentence-similarity-ii)", "[Sentence Similarity II](/solution/0700-0799/0737.Sentence%20Similarity%20II/README_EN.md)", "`Depth-first Search`,`Union Find`", "Medium", "\ud83d\udd12"]}, {"question_id": "0736", "frontend_question_id": "0736", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/parse-lisp-expression", "url_en": "https://leetcode.com/problems/parse-lisp-expression", "relative_path_cn": "/solution/0700-0799/0736.Parse%20Lisp%20Expression/README.md", "relative_path_en": "/solution/0700-0799/0736.Parse%20Lisp%20Expression/README_EN.md", "title_cn": "Lisp \u8bed\u6cd5\u89e3\u6790", "title_en": "Parse Lisp Expression", "question_title_slug": "parse-lisp-expression", "content_en": "

    \r\nYou are given a string expression representing a Lisp-like expression to return the integer value of.\r\n

    \r\nThe syntax for these expressions is given as follows.\r\n

    \r\n

  • An expression is either an integer, a let-expression, an add-expression, a mult-expression, or an assigned variable. Expressions always evaluate to a single integer.
  • \r\n

    \r\n

  • (An integer could be positive or negative.)
  • \r\n

    \r\n

  • A let-expression takes the form (let v1 e1 v2 e2 ... vn en expr), where let is always the string \"let\", then there are 1 or more pairs of alternating variables and expressions, meaning that the first variable v1 is assigned the value of the expression e1, the second variable v2 is assigned the value of the expression e2, and so on sequentially; and then the value of this let-expression is the value of the expression expr.
  • \r\n

    \r\n

  • An add-expression takes the form (add e1 e2) where add is always the string \"add\", there are always two expressions e1, e2, and this expression evaluates to the addition of the evaluation of e1 and the evaluation of e2.
  • \r\n

    \r\n

  • A mult-expression takes the form (mult e1 e2) where mult is always the string \"mult\", there are always two expressions e1, e2, and this expression evaluates to the multiplication of the evaluation of e1 and the evaluation of e2.
  • \r\n

    \r\n

  • For the purposes of this question, we will use a smaller subset of variable names. A variable starts with a lowercase letter, then zero or more lowercase letters or digits. Additionally for your convenience, the names \"add\", \"let\", or \"mult\" are protected and will never be used as variable names.
  • \r\n

    \r\n

  • Finally, there is the concept of scope. When an expression of a variable name is evaluated, within the context of that evaluation, the innermost scope (in terms of parentheses) is checked first for the value of that variable, and then outer scopes are checked sequentially. It is guaranteed that every expression is legal. Please see the examples for more details on scope.
  • \r\n

    \r\n\r\n

    Evaluation Examples:
    \r\n

    \r\nInput: (add 1 2)\r\nOutput: 3\r\n\r\nInput: (mult 3 (add 2 3))\r\nOutput: 15\r\n\r\nInput: (let x 2 (mult x 5))\r\nOutput: 10\r\n\r\nInput: (let x 2 (mult x (let x 3 y 4 (add x y))))\r\nOutput: 14\r\nExplanation: In the expression (add x y), when checking for the value of the variable x,\r\nwe check from the innermost scope to the outermost in the context of the variable we are trying to evaluate.\r\nSince x = 3 is found first, the value of x is 3.\r\n\r\nInput: (let x 3 x 2 x)\r\nOutput: 2\r\nExplanation: Assignment in let statements is processed sequentially.\r\n\r\nInput: (let x 1 y 2 x (add x y) (add x y))\r\nOutput: 5\r\nExplanation: The first (add x y) evaluates as 3, and is assigned to x.\r\nThe second (add x y) evaluates as 3+2 = 5.\r\n\r\nInput: (let x 2 (add (let x 3 (let x 4 x)) x))\r\nOutput: 6\r\nExplanation: Even though (let x 4 x) has a deeper scope, it is outside the context\r\nof the final x in the add-expression.  That final x will equal 2.\r\n\r\nInput: (let a1 3 b2 (add a1 1) b2) \r\nOutput 4\r\nExplanation: Variable names can contain digits after the first character.\r\n\r\n
    \r\n\r\n

    Note:\r\n

  • The given string expression is well formatted: There are no leading or trailing spaces, there is only a single space separating different components of the string, and no space between adjacent parentheses. The expression is guaranteed to be legal and evaluate to an integer.
  • \r\n
  • The length of expression is at most 2000. (It is also non-empty, as that would not be a legal expression.)
  • \r\n
  • The answer and all intermediate calculations of that answer are guaranteed to fit in a 32-bit integer.
  • \r\n

    ", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u7c7b\u4f3c Lisp \u8bed\u53e5\u7684\u8868\u8fbe\u5f0f expression\uff0c\u6c42\u51fa\u5176\u8ba1\u7b97\u7ed3\u679c\u3002

    \n\n

    \u8868\u8fbe\u5f0f\u8bed\u6cd5\u5982\u4e0b\u6240\u793a:

    \n\n
      \n\t
    • \u8868\u8fbe\u5f0f\u53ef\u4ee5\u4e3a\u6574\u6570\uff0clet \u8bed\u6cd5\uff0cadd \u8bed\u6cd5\uff0cmult \u8bed\u6cd5\uff0c\u6216\u8d4b\u503c\u7684\u53d8\u91cf\u3002\u8868\u8fbe\u5f0f\u7684\u7ed3\u679c\u603b\u662f\u4e00\u4e2a\u6574\u6570\u3002
    • \n\t
    • (\u6574\u6570\u53ef\u4ee5\u662f\u6b63\u6574\u6570\u3001\u8d1f\u6574\u6570\u30010)
    • \n\t
    • let \u8bed\u6cd5\u8868\u793a\u4e3a (let v1 e1 v2 e2 ... vn en expr), \u5176\u4e2d let\u8bed\u6cd5\u603b\u662f\u4ee5\u5b57\u7b26\u4e32 "let"\u6765\u8868\u793a\uff0c\u63a5\u4e0b\u6765\u4f1a\u8ddf\u968f\u4e00\u4e2a\u6216\u591a\u4e2a\u4ea4\u66ff\u53d8\u91cf\u6216\u8868\u8fbe\u5f0f\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u7b2c\u4e00\u4e2a\u53d8\u91cf v1\u88ab\u5206\u914d\u4e3a\u8868\u8fbe\u5f0f e1 \u7684\u503c\uff0c\u7b2c\u4e8c\u4e2a\u53d8\u91cf v2 \u88ab\u5206\u914d\u4e3a\u8868\u8fbe\u5f0f e2 \u7684\u503c\uff0c\u4ee5\u6b64\u7c7b\u63a8\uff1b\u6700\u7ec8 let \u8bed\u6cd5\u7684\u503c\u4e3a expr\u8868\u8fbe\u5f0f\u7684\u503c\u3002
    • \n\t
    • add \u8bed\u6cd5\u8868\u793a\u4e3a (add e1 e2)\uff0c\u5176\u4e2d add \u8bed\u6cd5\u603b\u662f\u4ee5\u5b57\u7b26\u4e32 "add"\u6765\u8868\u793a\uff0c\u8be5\u8bed\u6cd5\u603b\u662f\u6709\u4e24\u4e2a\u8868\u8fbe\u5f0fe1\u3001e2, \u8be5\u8bed\u6cd5\u7684\u6700\u7ec8\u7ed3\u679c\u662f e1 \u8868\u8fbe\u5f0f\u7684\u503c\u4e0e e2 \u8868\u8fbe\u5f0f\u7684\u503c\u4e4b\u548c\u3002
    • \n\t
    • mult \u8bed\u6cd5\u8868\u793a\u4e3a (mult e1 e2) \uff0c\u5176\u4e2d mult \u8bed\u6cd5\u603b\u662f\u4ee5\u5b57\u7b26\u4e32"mult"\u8868\u793a\uff0c \u8be5\u8bed\u6cd5\u603b\u662f\u6709\u4e24\u4e2a\u8868\u8fbe\u5f0f e1\u3001e2\uff0c\u8be5\u8bed\u6cd5\u7684\u6700\u7ec8\u7ed3\u679c\u662f e1 \u8868\u8fbe\u5f0f\u7684\u503c\u4e0e e2 \u8868\u8fbe\u5f0f\u7684\u503c\u4e4b\u79ef\u3002
    • \n\t
    • \u5728\u8be5\u9898\u76ee\u4e2d\uff0c\u53d8\u91cf\u7684\u547d\u540d\u4ee5\u5c0f\u5199\u5b57\u7b26\u5f00\u59cb\uff0c\u4e4b\u540e\u8ddf\u968f0\u4e2a\u6216\u591a\u4e2a\u5c0f\u5199\u5b57\u7b26\u6216\u6570\u5b57\u3002\u4e3a\u4e86\u65b9\u4fbf\uff0c"add"\uff0c"let"\uff0c"mult"\u4f1a\u88ab\u5b9a\u4e49\u4e3a"\u5173\u952e\u5b57"\uff0c\u4e0d\u4f1a\u5728\u8868\u8fbe\u5f0f\u7684\u53d8\u91cf\u547d\u540d\u4e2d\u51fa\u73b0\u3002
    • \n\t
    • \u6700\u540e\uff0c\u8981\u8bf4\u4e00\u4e0b\u4f5c\u7528\u57df\u7684\u6982\u5ff5\u3002\u8ba1\u7b97\u53d8\u91cf\u540d\u6240\u5bf9\u5e94\u7684\u8868\u8fbe\u5f0f\u65f6\uff0c\u5728\u8ba1\u7b97\u4e0a\u4e0b\u6587\u4e2d\uff0c\u9996\u5148\u68c0\u67e5\u6700\u5185\u5c42\u4f5c\u7528\u57df\uff08\u6309\u62ec\u53f7\u8ba1\uff09\uff0c\u7136\u540e\u6309\u987a\u5e8f\u4f9d\u6b21\u68c0\u67e5\u5916\u90e8\u4f5c\u7528\u57df\u3002\u6211\u4eec\u5c06\u4fdd\u8bc1\u6bcf\u4e00\u4e2a\u6d4b\u8bd5\u7684\u8868\u8fbe\u5f0f\u90fd\u662f\u5408\u6cd5\u7684\u3002\u6709\u5173\u4f5c\u7528\u57df\u7684\u66f4\u591a\u8be6\u7ec6\u4fe1\u606f\uff0c\u8bf7\u53c2\u9605\u793a\u4f8b\u3002
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165: (add 1 2)\n\u8f93\u51fa: 3\n\n\u8f93\u5165: (mult 3 (add 2 3))\n\u8f93\u51fa: 15\n\n\u8f93\u5165: (let x 2 (mult x 5))\n\u8f93\u51fa: 10\n\n\u8f93\u5165: (let x 2 (mult x (let x 3 y 4 (add x y))))\n\u8f93\u51fa: 14\n\u89e3\u91ca: \n\u8868\u8fbe\u5f0f (add x y), \u5728\u83b7\u53d6 x \u503c\u65f6, \u6211\u4eec\u5e94\u5f53\u7531\u6700\u5185\u5c42\u4f9d\u6b21\u5411\u5916\u8ba1\u7b97, \u9996\u5148\u9047\u5230\u4e86 x=3, \u6240\u4ee5\u6b64\u5904\u7684 x \u503c\u662f 3.\n\n\n\u8f93\u5165: (let x 3 x 2 x)\n\u8f93\u51fa: 2\n\u89e3\u91ca: let \u8bed\u53e5\u4e2d\u7684\u8d4b\u503c\u8fd0\u7b97\u6309\u987a\u5e8f\u5904\u7406\u5373\u53ef\n\n\u8f93\u5165: (let x 1 y 2 x (add x y) (add x y))\n\u8f93\u51fa: 5\n\u89e3\u91ca: \n\u7b2c\u4e00\u4e2a (add x y) \u8ba1\u7b97\u7ed3\u679c\u662f 3\uff0c\u5e76\u4e14\u5c06\u6b64\u503c\u8d4b\u7ed9\u4e86 x \u3002\n\u7b2c\u4e8c\u4e2a (add x y) \u8ba1\u7b97\u7ed3\u679c\u5c31\u662f 3+2 = 5 \u3002\n\n\u8f93\u5165: (let x 2 (add (let x 3 (let x 4 x)) x))\n\u8f93\u51fa: 6\n\u89e3\u91ca: \n(let x 4 x) \u4e2d\u7684 x \u7684\u4f5c\u7528\u57df\u4ec5\u5728()\u4e4b\u5185\u3002\u6240\u4ee5\u6700\u7ec8\u505a\u52a0\u6cd5\u64cd\u4f5c\u65f6\uff0cx \u7684\u503c\u662f 2 \u3002\n\n\u8f93\u5165: (let a1 3 b2 (add a1 1) b2) \n\u8f93\u51fa: 4\n\u89e3\u91ca: \n\u53d8\u91cf\u547d\u540d\u65f6\u53ef\u4ee5\u5728\u7b2c\u4e00\u4e2a\u5c0f\u5199\u5b57\u6bcd\u540e\u8ddf\u968f\u6570\u5b57.\n
    \n\n

     

    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    • \u6211\u4eec\u7ed9\u5b9a\u7684 expression \u8868\u8fbe\u5f0f\u90fd\u662f\u683c\u5f0f\u5316\u540e\u7684\uff1a\u8868\u8fbe\u5f0f\u524d\u540e\u6ca1\u6709\u591a\u4f59\u7684\u7a7a\u683c\uff0c\u8868\u8fbe\u5f0f\u7684\u4e0d\u540c\u90e8\u5206(\u5173\u952e\u5b57\u3001\u53d8\u91cf\u3001\u8868\u8fbe\u5f0f)\u4e4b\u95f4\u4ec5\u4f7f\u7528\u4e00\u4e2a\u7a7a\u683c\u5206\u5272\uff0c\u5e76\u4e14\u5728\u76f8\u90bb\u62ec\u53f7\u4e4b\u95f4\u4e5f\u6ca1\u6709\u7a7a\u683c\u3002\u6211\u4eec\u7ed9\u5b9a\u7684\u8868\u8fbe\u5f0f\u5747\u4e3a\u5408\u6cd5\u7684\u4e14\u6700\u7ec8\u7ed3\u679c\u4e3a\u6574\u6570\u3002
    • \n\t
    • \u6211\u4eec\u7ed9\u5b9a\u7684\u8868\u8fbe\u5f0f\u957f\u5ea6\u6700\u591a\u4e3a 2000 (\u8868\u8fbe\u5f0f\u4e5f\u4e0d\u4f1a\u4e3a\u7a7a\uff0c\u56e0\u4e3a\u90a3\u4e0d\u662f\u4e00\u4e2a\u5408\u6cd5\u7684\u8868\u8fbe\u5f0f)\u3002
    • \n\t
    • \u6700\u7ec8\u7684\u7ed3\u679c\u548c\u4e2d\u95f4\u7684\u8ba1\u7b97\u7ed3\u679c\u90fd\u5c06\u662f\u4e00\u4e2a 32 \u4f4d\u6574\u6570\u3002
    • \n
    \n\n

     

    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int evaluate(string expression) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int evaluate(String expression) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def evaluate(self, expression):\n \"\"\"\n :type expression: str\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def evaluate(self, expression: str) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint evaluate(char * expression){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int Evaluate(string expression) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} expression\n * @return {number}\n */\nvar evaluate = function(expression) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} expression\n# @return {Integer}\ndef evaluate(expression)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func evaluate(_ expression: String) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func evaluate(expression string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def evaluate(expression: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun evaluate(expression: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn evaluate(expression: String) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $expression\n * @return Integer\n */\n function evaluate($expression) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function evaluate(expression: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (evaluate expression)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0736](https://leetcode-cn.com/problems/parse-lisp-expression)", "[Lisp \u8bed\u6cd5\u89e3\u6790](/solution/0700-0799/0736.Parse%20Lisp%20Expression/README.md)", "`\u5b57\u7b26\u4e32`", "\u56f0\u96be", ""], "md_table_row_en": ["[0736](https://leetcode.com/problems/parse-lisp-expression)", "[Parse Lisp Expression](/solution/0700-0799/0736.Parse%20Lisp%20Expression/README_EN.md)", "`String`", "Hard", ""]}, {"question_id": "0735", "frontend_question_id": "0735", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/asteroid-collision", "url_en": "https://leetcode.com/problems/asteroid-collision", "relative_path_cn": "/solution/0700-0799/0735.Asteroid%20Collision/README.md", "relative_path_en": "/solution/0700-0799/0735.Asteroid%20Collision/README_EN.md", "title_cn": "\u884c\u661f\u78b0\u649e", "title_en": "Asteroid Collision", "question_title_slug": "asteroid-collision", "content_en": "

    We are given an array asteroids of integers representing asteroids in a row.

    \n\n

    For each asteroid, the absolute value represents its size, and the sign represents its direction (positive meaning right, negative meaning left). Each asteroid moves at the same speed.

    \n\n

    Find out the state of the asteroids after all collisions. If two asteroids meet, the smaller one will explode. If both are the same size, both will explode. Two asteroids moving in the same direction will never meet.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: asteroids = [5,10,-5]\nOutput: [5,10]\nExplanation: The 10 and -5 collide resulting in 10. The 5 and 10 never collide.\n
    \n\n

    Example 2:

    \n\n
    \nInput: asteroids = [8,-8]\nOutput: []\nExplanation: The 8 and -8 collide exploding each other.\n
    \n\n

    Example 3:

    \n\n
    \nInput: asteroids = [10,2,-5]\nOutput: [10]\nExplanation: The 2 and -5 collide resulting in -5. The 10 and -5 collide resulting in 10.\n
    \n\n

    Example 4:

    \n\n
    \nInput: asteroids = [-2,-1,1,2]\nOutput: [-2,-1,1,2]\nExplanation: The -2 and -1 are moving left, while the 1 and 2 are moving right. Asteroids moving the same direction never meet, so no asteroids will meet each other.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= asteroids.length <= 104
    • \n\t
    • -1000 <= asteroids[i] <= 1000
    • \n\t
    • asteroids[i] != 0
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 asteroids\uff0c\u8868\u793a\u5728\u540c\u4e00\u884c\u7684\u884c\u661f\u3002

    \n\n

    \u5bf9\u4e8e\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e00\u4e2a\u5143\u7d20\uff0c\u5176\u7edd\u5bf9\u503c\u8868\u793a\u884c\u661f\u7684\u5927\u5c0f\uff0c\u6b63\u8d1f\u8868\u793a\u884c\u661f\u7684\u79fb\u52a8\u65b9\u5411\uff08\u6b63\u8868\u793a\u5411\u53f3\u79fb\u52a8\uff0c\u8d1f\u8868\u793a\u5411\u5de6\u79fb\u52a8\uff09\u3002\u6bcf\u4e00\u9897\u884c\u661f\u4ee5\u76f8\u540c\u7684\u901f\u5ea6\u79fb\u52a8\u3002

    \n\n

    \u627e\u51fa\u78b0\u649e\u540e\u5269\u4e0b\u7684\u6240\u6709\u884c\u661f\u3002\u78b0\u649e\u89c4\u5219\uff1a\u4e24\u4e2a\u884c\u661f\u76f8\u4e92\u78b0\u649e\uff0c\u8f83\u5c0f\u7684\u884c\u661f\u4f1a\u7206\u70b8\u3002\u5982\u679c\u4e24\u9897\u884c\u661f\u5927\u5c0f\u76f8\u540c\uff0c\u5219\u4e24\u9897\u884c\u661f\u90fd\u4f1a\u7206\u70b8\u3002\u4e24\u9897\u79fb\u52a8\u65b9\u5411\u76f8\u540c\u7684\u884c\u661f\uff0c\u6c38\u8fdc\u4e0d\u4f1a\u53d1\u751f\u78b0\u649e\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aasteroids = [5,10,-5]\n\u8f93\u51fa\uff1a[5,10]\n\u89e3\u91ca\uff1a10 \u548c -5 \u78b0\u649e\u540e\u53ea\u5269\u4e0b 10 \u3002 5 \u548c 10 \u6c38\u8fdc\u4e0d\u4f1a\u53d1\u751f\u78b0\u649e\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aasteroids = [8,-8]\n\u8f93\u51fa\uff1a[]\n\u89e3\u91ca\uff1a8 \u548c -8 \u78b0\u649e\u540e\uff0c\u4e24\u8005\u90fd\u53d1\u751f\u7206\u70b8\u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aasteroids = [10,2,-5]\n\u8f93\u51fa\uff1a[10]\n\u89e3\u91ca\uff1a2 \u548c -5 \u53d1\u751f\u78b0\u649e\u540e\u5269\u4e0b -5 \u300210 \u548c -5 \u53d1\u751f\u78b0\u649e\u540e\u5269\u4e0b 10 \u3002
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1aasteroids = [-2,-1,1,2]\n\u8f93\u51fa\uff1a[-2,-1,1,2]\n\u89e3\u91ca\uff1a-2 \u548c -1 \u5411\u5de6\u79fb\u52a8\uff0c\u800c 1 \u548c 2 \u5411\u53f3\u79fb\u52a8\u3002 \u7531\u4e8e\u79fb\u52a8\u65b9\u5411\u76f8\u540c\u7684\u884c\u661f\u4e0d\u4f1a\u53d1\u751f\u78b0\u649e\uff0c\u6240\u4ee5\u6700\u7ec8\u6ca1\u6709\u884c\u661f\u53d1\u751f\u78b0\u649e\u3002 
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= asteroids.length\u00a0<= 104
    • \n\t
    • -1000 <= asteroids[i] <= 1000
    • \n\t
    • asteroids[i] != 0
    • \n
    \n", "tags_en": ["Stack"], "tags_cn": ["\u6808"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector asteroidCollision(vector& asteroids) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] asteroidCollision(int[] asteroids) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def asteroidCollision(self, asteroids):\n \"\"\"\n :type asteroids: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def asteroidCollision(self, asteroids: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* asteroidCollision(int* asteroids, int asteroidsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] AsteroidCollision(int[] asteroids) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} asteroids\n * @return {number[]}\n */\nvar asteroidCollision = function(asteroids) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} asteroids\n# @return {Integer[]}\ndef asteroid_collision(asteroids)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func asteroidCollision(_ asteroids: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func asteroidCollision(asteroids []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def asteroidCollision(asteroids: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun asteroidCollision(asteroids: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn asteroid_collision(asteroids: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $asteroids\n * @return Integer[]\n */\n function asteroidCollision($asteroids) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function asteroidCollision(asteroids: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (asteroid-collision asteroids)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0735](https://leetcode-cn.com/problems/asteroid-collision)", "[\u884c\u661f\u78b0\u649e](/solution/0700-0799/0735.Asteroid%20Collision/README.md)", "`\u6808`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0735](https://leetcode.com/problems/asteroid-collision)", "[Asteroid Collision](/solution/0700-0799/0735.Asteroid%20Collision/README_EN.md)", "`Stack`", "Medium", ""]}, {"question_id": "0734", "frontend_question_id": "0734", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/sentence-similarity", "url_en": "https://leetcode.com/problems/sentence-similarity", "relative_path_cn": "/solution/0700-0799/0734.Sentence%20Similarity/README.md", "relative_path_en": "/solution/0700-0799/0734.Sentence%20Similarity/README_EN.md", "title_cn": "\u53e5\u5b50\u76f8\u4f3c\u6027", "title_en": "Sentence Similarity", "question_title_slug": "sentence-similarity", "content_en": "

    We can represent a sentence as an array of words, for example, the sentence "I am happy with leetcode" can be represented as arr = ["I","am",happy","with","leetcode"].

    \n\n

    Given two sentences sentence1 and sentence2 each represented as a string array and given an array of string pairs similarPairs where similarPairs[i] = [xi, yi] indicates that the two words xi and yi are similar.

    \n\n

    Return true if sentence1 and sentence2 are similar, or false if they are not similar.

    \n\n

    Two sentences are similar if:

    \n\n
      \n\t
    • They have the same length (i.e., the same number of words)
    • \n\t
    • sentence1[i] and sentence2[i] are similar.
    • \n
    \n\n

    Notice that a word is always similar to itself, also notice that the similarity relation is not transitive. For example, if the words a and b are similar, and the words b and c are similar, a and c are not necessarily similar.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: sentence1 = ["great","acting","skills"], sentence2 = ["fine","drama","talent"], similarPairs = [["great","fine"],["drama","acting"],["skills","talent"]]\nOutput: true\nExplanation: The two sentences have the same length and each word i of sentence1 is also similar to the corresponding word in sentence2.\n
    \n\n

    Example 2:

    \n\n
    \nInput: sentence1 = ["great"], sentence2 = ["great"], similarPairs = []\nOutput: true\nExplanation: A word is similar to itself.\n
    \n\n

    Example 3:

    \n\n
    \nInput: sentence1 = ["great"], sentence2 = ["doubleplus","good"], similarPairs = [["great","doubleplus"]]\nOutput: false\nExplanation: As they don't have the same length, we return false.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= sentence1.length, sentence2.length <= 1000
    • \n\t
    • 1 <= sentence1[i].length, sentence2[i].length <= 20
    • \n\t
    • sentence1[i] and sentence2[i] consist of English letters.
    • \n\t
    • 0 <= similarPairs.length <= 1000
    • \n\t
    • similarPairs[i].length == 2
    • \n\t
    • 1 <= xi.length, yi.length <= 20
    • \n\t
    • xi and yi consist of lower-case and upper-case English letters.
    • \n\t
    • All the pairs (xi, yi) are distinct.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u53e5\u5b50 words1, words2 \uff08\u6bcf\u4e2a\u7528\u5b57\u7b26\u4e32\u6570\u7ec4\u8868\u793a\uff09\uff0c\u548c\u4e00\u4e2a\u76f8\u4f3c\u5355\u8bcd\u5bf9\u7684\u5217\u8868 pairs \uff0c\u5224\u65ad\u662f\u5426\u4e24\u4e2a\u53e5\u5b50\u662f\u76f8\u4f3c\u7684\u3002

    \n\n

    \u4f8b\u5982\uff0c\u5f53\u76f8\u4f3c\u5355\u8bcd\u5bf9\u662f pairs = [["great", "fine"], ["acting","drama"], ["skills","talent"]]\u7684\u65f6\u5019\uff0c"great acting skills" \u548c "fine drama talent" \u662f\u76f8\u4f3c\u7684\u3002

    \n\n

    \u6ce8\u610f\u76f8\u4f3c\u5173\u7cfb\u662f\u4e0d\u5177\u6709\u4f20\u9012\u6027\u7684\u3002\u4f8b\u5982\uff0c\u5982\u679c "great" \u548c "fine" \u662f\u76f8\u4f3c\u7684\uff0c"fine" \u548c "good" \u662f\u76f8\u4f3c\u7684\uff0c\u4f46\u662f "great" \u548c "good" \u672a\u5fc5\u662f\u76f8\u4f3c\u7684\u3002

    \n\n

    \u4f46\u662f\uff0c\u76f8\u4f3c\u5173\u7cfb\u662f\u5177\u6709\u5bf9\u79f0\u6027\u7684\u3002\u4f8b\u5982\uff0c"great" \u548c "fine" \u662f\u76f8\u4f3c\u7684\u76f8\u5f53\u4e8e "fine" \u548c "great" \u662f\u76f8\u4f3c\u7684\u3002

    \n\n

    \u800c\u4e14\uff0c\u4e00\u4e2a\u5355\u8bcd\u603b\u662f\u4e0e\u5176\u81ea\u8eab\u76f8\u4f3c\u3002\u4f8b\u5982\uff0c\u53e5\u5b50 words1 = ["great"], words2 = ["great"], pairs = [] \u662f\u76f8\u4f3c\u7684\uff0c\u5c3d\u7ba1\u6ca1\u6709\u8f93\u5165\u7279\u5b9a\u7684\u76f8\u4f3c\u5355\u8bcd\u5bf9\u3002

    \n\n

    \u6700\u540e\uff0c\u53e5\u5b50\u53ea\u4f1a\u5728\u5177\u6709\u76f8\u540c\u5355\u8bcd\u4e2a\u6570\u7684\u524d\u63d0\u4e0b\u624d\u4f1a\u76f8\u4f3c\u3002\u6240\u4ee5\u4e00\u4e2a\u53e5\u5b50 words1 = ["great"] \u6c38\u8fdc\u4e0d\u53ef\u80fd\u548c\u53e5\u5b50 words2 = ["doubleplus","good"] \u76f8\u4f3c\u3002

    \n\n

     

    \n\n

    \u6ce8\uff1a

    \n\n
      \n\t
    • words1 and words2 \u7684\u957f\u5ea6\u4e0d\u4f1a\u8d85\u8fc7 1000\u3002
    • \n\t
    • pairs \u7684\u957f\u5ea6\u4e0d\u4f1a\u8d85\u8fc7 2000\u3002
    • \n\t
    • \u6bcf\u4e2apairs[i] \u7684\u957f\u5ea6\u4e3a 2\u3002
    • \n\t
    • \u6bcf\u4e2a words[i] \u548c pairs[i][j] \u7684\u957f\u5ea6\u8303\u56f4\u4e3a [1, 20]\u3002
    • \n
    \n\n

     

    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool areSentencesSimilar(vector& sentence1, vector& sentence2, vector>& similarPairs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean areSentencesSimilar(String[] sentence1, String[] sentence2, List> similarPairs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def areSentencesSimilar(self, sentence1, sentence2, similarPairs):\n \"\"\"\n :type sentence1: List[str]\n :type sentence2: List[str]\n :type similarPairs: List[List[str]]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def areSentencesSimilar(self, sentence1: List[str], sentence2: List[str], similarPairs: List[List[str]]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool areSentencesSimilar(char ** sentence1, int sentence1Size, char ** sentence2, int sentence2Size, char *** similarPairs, int similarPairsSize, int* similarPairsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool AreSentencesSimilar(string[] sentence1, string[] sentence2, IList> similarPairs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} sentence1\n * @param {string[]} sentence2\n * @param {string[][]} similarPairs\n * @return {boolean}\n */\nvar areSentencesSimilar = function(sentence1, sentence2, similarPairs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} sentence1\n# @param {String[]} sentence2\n# @param {String[][]} similar_pairs\n# @return {Boolean}\ndef are_sentences_similar(sentence1, sentence2, similar_pairs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func areSentencesSimilar(_ sentence1: [String], _ sentence2: [String], _ similarPairs: [[String]]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func areSentencesSimilar(sentence1 []string, sentence2 []string, similarPairs [][]string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def areSentencesSimilar(sentence1: Array[String], sentence2: Array[String], similarPairs: List[List[String]]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun areSentencesSimilar(sentence1: Array, sentence2: Array, similarPairs: List>): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn are_sentences_similar(sentence1: Vec, sentence2: Vec, similar_pairs: Vec>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $sentence1\n * @param String[] $sentence2\n * @param String[][] $similarPairs\n * @return Boolean\n */\n function areSentencesSimilar($sentence1, $sentence2, $similarPairs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function areSentencesSimilar(sentence1: string[], sentence2: string[], similarPairs: string[][]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (are-sentences-similar sentence1 sentence2 similarPairs)\n (-> (listof string?) (listof string?) (listof (listof string?)) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0734](https://leetcode-cn.com/problems/sentence-similarity)", "[\u53e5\u5b50\u76f8\u4f3c\u6027](/solution/0700-0799/0734.Sentence%20Similarity/README.md)", "`\u54c8\u5e0c\u8868`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0734](https://leetcode.com/problems/sentence-similarity)", "[Sentence Similarity](/solution/0700-0799/0734.Sentence%20Similarity/README_EN.md)", "`Hash Table`", "Easy", "\ud83d\udd12"]}, {"question_id": "0733", "frontend_question_id": "0733", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/flood-fill", "url_en": "https://leetcode.com/problems/flood-fill", "relative_path_cn": "/solution/0700-0799/0733.Flood%20Fill/README.md", "relative_path_en": "/solution/0700-0799/0733.Flood%20Fill/README_EN.md", "title_cn": "\u56fe\u50cf\u6e32\u67d3", "title_en": "Flood Fill", "question_title_slug": "flood-fill", "content_en": "

    An image is represented by an m x n integer grid image where image[i][j] represents the pixel value of the image.

    \n\n

    You are also given three integers sr, sc, and newColor. You should perform a flood fill on the image starting from the pixel image[sr][sc].

    \n\n

    To perform a flood fill, consider the starting pixel, plus any pixels connected 4-directionally to the starting pixel of the same color as the starting pixel, plus any pixels connected 4-directionally to those pixels (also with the same color), and so on. Replace the color of all of the aforementioned pixels with newColor.

    \n\n

    Return the modified image after performing the flood fill.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: image = [[1,1,1],[1,1,0],[1,0,1]], sr = 1, sc = 1, newColor = 2\nOutput: [[2,2,2],[2,2,0],[2,0,1]]\nExplanation: From the center of the image with position (sr, sc) = (1, 1) (i.e., the red pixel), all pixels connected by a path of the same color as the starting pixel (i.e., the blue pixels) are colored with the new color.\nNote the bottom corner is not colored 2, because it is not 4-directionally connected to the starting pixel.\n
    \n\n

    Example 2:

    \n\n
    \nInput: image = [[0,0,0],[0,0,0]], sr = 0, sc = 0, newColor = 2\nOutput: [[2,2,2],[2,2,2]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == image.length
    • \n\t
    • n == image[i].length
    • \n\t
    • 1 <= m, n <= 50
    • \n\t
    • 0 <= image[i][j], newColor < 216
    • \n\t
    • 0 <= sr <= m
    • \n\t
    • 0 <= sc <= n
    • \n
    \n", "content_cn": "

    \u6709\u4e00\u5e45\u4ee5\u4e8c\u7ef4\u6574\u6570\u6570\u7ec4\u8868\u793a\u7684\u56fe\u753b\uff0c\u6bcf\u4e00\u4e2a\u6574\u6570\u8868\u793a\u8be5\u56fe\u753b\u7684\u50cf\u7d20\u503c\u5927\u5c0f\uff0c\u6570\u503c\u5728 0 \u5230 65535 \u4e4b\u95f4\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u5750\u6807 (sr, sc) \u8868\u793a\u56fe\u50cf\u6e32\u67d3\u5f00\u59cb\u7684\u50cf\u7d20\u503c\uff08\u884c \uff0c\u5217\uff09\u548c\u4e00\u4e2a\u65b0\u7684\u989c\u8272\u503c newColor\uff0c\u8ba9\u4f60\u91cd\u65b0\u4e0a\u8272\u8fd9\u5e45\u56fe\u50cf\u3002

    \n\n

    \u4e3a\u4e86\u5b8c\u6210\u4e0a\u8272\u5de5\u4f5c\uff0c\u4ece\u521d\u59cb\u5750\u6807\u5f00\u59cb\uff0c\u8bb0\u5f55\u521d\u59cb\u5750\u6807\u7684\u4e0a\u4e0b\u5de6\u53f3\u56db\u4e2a\u65b9\u5411\u4e0a\u50cf\u7d20\u503c\u4e0e\u521d\u59cb\u5750\u6807\u76f8\u540c\u7684\u76f8\u8fde\u50cf\u7d20\u70b9\uff0c\u63a5\u7740\u518d\u8bb0\u5f55\u8fd9\u56db\u4e2a\u65b9\u5411\u4e0a\u7b26\u5408\u6761\u4ef6\u7684\u50cf\u7d20\u70b9\u4e0e\u4ed6\u4eec\u5bf9\u5e94\u56db\u4e2a\u65b9\u5411\u4e0a\u50cf\u7d20\u503c\u4e0e\u521d\u59cb\u5750\u6807\u76f8\u540c\u7684\u76f8\u8fde\u50cf\u7d20\u70b9\uff0c……\uff0c\u91cd\u590d\u8be5\u8fc7\u7a0b\u3002\u5c06\u6240\u6709\u6709\u8bb0\u5f55\u7684\u50cf\u7d20\u70b9\u7684\u989c\u8272\u503c\u6539\u4e3a\u65b0\u7684\u989c\u8272\u503c\u3002

    \n\n

    \u6700\u540e\u8fd4\u56de\u7ecf\u8fc7\u4e0a\u8272\u6e32\u67d3\u540e\u7684\u56fe\u50cf\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: \nimage = [[1,1,1],[1,1,0],[1,0,1]]\nsr = 1, sc = 1, newColor = 2\n\u8f93\u51fa: [[2,2,2],[2,2,0],[2,0,1]]\n\u89e3\u6790: \n\u5728\u56fe\u50cf\u7684\u6b63\u4e2d\u95f4\uff0c(\u5750\u6807(sr,sc)=(1,1)),\n\u5728\u8def\u5f84\u4e0a\u6240\u6709\u7b26\u5408\u6761\u4ef6\u7684\u50cf\u7d20\u70b9\u7684\u989c\u8272\u90fd\u88ab\u66f4\u6539\u62102\u3002\n\u6ce8\u610f\uff0c\u53f3\u4e0b\u89d2\u7684\u50cf\u7d20\u6ca1\u6709\u66f4\u6539\u4e3a2\uff0c\n\u56e0\u4e3a\u5b83\u4e0d\u662f\u5728\u4e0a\u4e0b\u5de6\u53f3\u56db\u4e2a\u65b9\u5411\u4e0a\u4e0e\u521d\u59cb\u70b9\u76f8\u8fde\u7684\u50cf\u7d20\u70b9\u3002\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    • image \u548c image[0] \u7684\u957f\u5ea6\u5728\u8303\u56f4 [1, 50] \u5185\u3002
    • \n\t
    • \u7ed9\u51fa\u7684\u521d\u59cb\u70b9\u5c06\u6ee1\u8db3 0 <= sr < image.length \u548c 0 <= sc < image[0].length\u3002
    • \n\t
    • image[i][j] \u548c newColor \u8868\u793a\u7684\u989c\u8272\u503c\u5728\u8303\u56f4 [0, 65535]\u5185\u3002
    • \n
    \n", "tags_en": ["Depth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> floodFill(vector>& image, int sr, int sc, int newColor) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[][] floodFill(int[][] image, int sr, int sc, int newColor) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def floodFill(self, image, sr, sc, newColor):\n \"\"\"\n :type image: List[List[int]]\n :type sr: int\n :type sc: int\n :type newColor: int\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def floodFill(self, image: List[List[int]], sr: int, sc: int, newColor: int) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** floodFill(int** image, int imageSize, int* imageColSize, int sr, int sc, int newColor, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[][] FloodFill(int[][] image, int sr, int sc, int newColor) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} image\n * @param {number} sr\n * @param {number} sc\n * @param {number} newColor\n * @return {number[][]}\n */\nvar floodFill = function(image, sr, sc, newColor) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} image\n# @param {Integer} sr\n# @param {Integer} sc\n# @param {Integer} new_color\n# @return {Integer[][]}\ndef flood_fill(image, sr, sc, new_color)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func floodFill(_ image: [[Int]], _ sr: Int, _ sc: Int, _ newColor: Int) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func floodFill(image [][]int, sr int, sc int, newColor int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def floodFill(image: Array[Array[Int]], sr: Int, sc: Int, newColor: Int): Array[Array[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun floodFill(image: Array, sr: Int, sc: Int, newColor: Int): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn flood_fill(image: Vec>, sr: i32, sc: i32, new_color: i32) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $image\n * @param Integer $sr\n * @param Integer $sc\n * @param Integer $newColor\n * @return Integer[][]\n */\n function floodFill($image, $sr, $sc, $newColor) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function floodFill(image: number[][], sr: number, sc: number, newColor: number): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (flood-fill image sr sc newColor)\n (-> (listof (listof exact-integer?)) exact-integer? exact-integer? exact-integer? (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0733](https://leetcode-cn.com/problems/flood-fill)", "[\u56fe\u50cf\u6e32\u67d3](/solution/0700-0799/0733.Flood%20Fill/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u7b80\u5355", ""], "md_table_row_en": ["[0733](https://leetcode.com/problems/flood-fill)", "[Flood Fill](/solution/0700-0799/0733.Flood%20Fill/README_EN.md)", "`Depth-first Search`", "Easy", ""]}, {"question_id": "0732", "frontend_question_id": "0732", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/my-calendar-iii", "url_en": "https://leetcode.com/problems/my-calendar-iii", "relative_path_cn": "/solution/0700-0799/0732.My%20Calendar%20III/README.md", "relative_path_en": "/solution/0700-0799/0732.My%20Calendar%20III/README_EN.md", "title_cn": "\u6211\u7684\u65e5\u7a0b\u5b89\u6392\u8868 III", "title_en": "My Calendar III", "question_title_slug": "my-calendar-iii", "content_en": "

    A k-booking happens when k events have some non-empty intersection (i.e., there is some time that is common to all k events.)

    \n\n

    You are given some events [start, end), after each given event, return an integer k representing the maximum k-booking between all the previous events.

    \n\n

    Implement the MyCalendarThree class:

    \n\n
      \n\t
    • MyCalendarThree() Initializes the object.
    • \n\t
    • int book(int start, int end) Returns an integer k representing the largest integer such that there exists a k-booking in the calendar.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["MyCalendarThree", "book", "book", "book", "book", "book", "book"]\n[[], [10, 20], [50, 60], [10, 40], [5, 15], [5, 10], [25, 55]]\nOutput\n[null, 1, 1, 2, 3, 3, 3]\n\nExplanation\nMyCalendarThree myCalendarThree = new MyCalendarThree();\nmyCalendarThree.book(10, 20); // return 1, The first event can be booked and is disjoint, so the maximum k-booking is a 1-booking.\nmyCalendarThree.book(50, 60); // return 1, The second event can be booked and is disjoint, so the maximum k-booking is a 1-booking.\nmyCalendarThree.book(10, 40); // return 2, The third event [10, 40) intersects the first event, and the maximum k-booking is a 2-booking.\nmyCalendarThree.book(5, 15); // return 3, The remaining events cause the maximum K-booking to be only a 3-booking.\nmyCalendarThree.book(5, 10); // return 3\nmyCalendarThree.book(25, 55); // return 3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= start < end <= 109
    • \n\t
    • At most 400 calls will be made to book.
    • \n
    \n", "content_cn": "

    \u5f53 k \u4e2a\u65e5\u7a0b\u5b89\u6392\u6709\u4e00\u4e9b\u65f6\u95f4\u4e0a\u7684\u4ea4\u53c9\u65f6\uff08\u4f8b\u5982 k \u4e2a\u65e5\u7a0b\u5b89\u6392\u90fd\u5728\u540c\u4e00\u65f6\u95f4\u5185\uff09\uff0c\u5c31\u4f1a\u4ea7\u751f k \u6b21\u9884\u8ba2\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e9b\u65e5\u7a0b\u5b89\u6392 [start, end) \uff0c\u8bf7\u4f60\u5728\u6bcf\u4e2a\u65e5\u7a0b\u5b89\u6392\u6dfb\u52a0\u540e\uff0c\u8fd4\u56de\u4e00\u4e2a\u6574\u6570 k \uff0c\u8868\u793a\u6240\u6709\u5148\u524d\u65e5\u7a0b\u5b89\u6392\u4f1a\u4ea7\u751f\u7684\u6700\u5927 k \u6b21\u9884\u8ba2\u3002

    \n\n

    \u5b9e\u73b0\u4e00\u4e2a MyCalendarThree \u7c7b\u6765\u5b58\u653e\u4f60\u7684\u65e5\u7a0b\u5b89\u6392\uff0c\u4f60\u53ef\u4ee5\u4e00\u76f4\u6dfb\u52a0\u65b0\u7684\u65e5\u7a0b\u5b89\u6392\u3002

    \n\n
      \n\t
    • MyCalendarThree() \u521d\u59cb\u5316\u5bf9\u8c61\u3002
    • \n\t
    • int book(int start, int end) \u8fd4\u56de\u4e00\u4e2a\u6574\u6570 k \uff0c\u8868\u793a\u65e5\u5386\u4e2d\u5b58\u5728\u7684 k \u6b21\u9884\u8ba2\u7684\u6700\u5927\u503c\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\n[\"MyCalendarThree\", \"book\", \"book\", \"book\", \"book\", \"book\", \"book\"]\n[[], [10, 20], [50, 60], [10, 40], [5, 15], [5, 10], [25, 55]]\n\u8f93\u51fa\uff1a\n[null, 1, 1, 2, 3, 3, 3]\n\n\u89e3\u91ca\uff1a\nMyCalendarThree myCalendarThree = new MyCalendarThree();\nmyCalendarThree.book(10, 20); // \u8fd4\u56de 1 \uff0c\u7b2c\u4e00\u4e2a\u65e5\u7a0b\u5b89\u6392\u53ef\u4ee5\u9884\u8ba2\u5e76\u4e14\u4e0d\u5b58\u5728\u76f8\u4ea4\uff0c\u6240\u4ee5\u6700\u5927 k \u6b21\u9884\u8ba2\u662f 1 \u6b21\u9884\u8ba2\u3002\nmyCalendarThree.book(50, 60); // \u8fd4\u56de 1 \uff0c\u7b2c\u4e8c\u4e2a\u65e5\u7a0b\u5b89\u6392\u53ef\u4ee5\u9884\u8ba2\u5e76\u4e14\u4e0d\u5b58\u5728\u76f8\u4ea4\uff0c\u6240\u4ee5\u6700\u5927 k \u6b21\u9884\u8ba2\u662f 1 \u6b21\u9884\u8ba2\u3002\nmyCalendarThree.book(10, 40); // \u8fd4\u56de 2 \uff0c\u7b2c\u4e09\u4e2a\u65e5\u7a0b\u5b89\u6392 [10, 40) \u4e0e\u7b2c\u4e00\u4e2a\u65e5\u7a0b\u5b89\u6392\u76f8\u4ea4\uff0c\u6240\u4ee5\u6700\u5927 k \u6b21\u9884\u8ba2\u662f 2 \u6b21\u9884\u8ba2\u3002\nmyCalendarThree.book(5, 15); // \u8fd4\u56de 3 \uff0c\u5269\u4e0b\u7684\u65e5\u7a0b\u5b89\u6392\u7684\u6700\u5927 k \u6b21\u9884\u8ba2\u662f 3 \u6b21\u9884\u8ba2\u3002\nmyCalendarThree.book(5, 10); // \u8fd4\u56de 3\nmyCalendarThree.book(25, 55); // \u8fd4\u56de 3\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= start < end <= 109
    • \n\t
    • \u6bcf\u4e2a\u6d4b\u8bd5\u7528\u4f8b\uff0c\u8c03\u7528 book\u00a0\u51fd\u6570\u6700\u591a\u4e0d\u8d85\u8fc7\u00a0400\u6b21
    • \n
    \n", "tags_en": ["Segment Tree", "Ordered Map"], "tags_cn": ["\u7ebf\u6bb5\u6811"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class MyCalendarThree {\npublic:\n MyCalendarThree() {\n\n }\n \n int book(int start, int end) {\n\n }\n};\n\n/**\n * Your MyCalendarThree object will be instantiated and called as such:\n * MyCalendarThree* obj = new MyCalendarThree();\n * int param_1 = obj->book(start,end);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class MyCalendarThree {\n\n public MyCalendarThree() {\n\n }\n \n public int book(int start, int end) {\n\n }\n}\n\n/**\n * Your MyCalendarThree object will be instantiated and called as such:\n * MyCalendarThree obj = new MyCalendarThree();\n * int param_1 = obj.book(start,end);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class MyCalendarThree(object):\n\n def __init__(self):\n\n\n def book(self, start, end):\n \"\"\"\n :type start: int\n :type end: int\n :rtype: int\n \"\"\"\n\n\n\n# Your MyCalendarThree object will be instantiated and called as such:\n# obj = MyCalendarThree()\n# param_1 = obj.book(start,end)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class MyCalendarThree:\n\n def __init__(self):\n\n\n def book(self, start: int, end: int) -> int:\n\n\n\n# Your MyCalendarThree object will be instantiated and called as such:\n# obj = MyCalendarThree()\n# param_1 = obj.book(start,end)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} MyCalendarThree;\n\n\nMyCalendarThree* myCalendarThreeCreate() {\n\n}\n\nint myCalendarThreeBook(MyCalendarThree* obj, int start, int end) {\n\n}\n\nvoid myCalendarThreeFree(MyCalendarThree* obj) {\n\n}\n\n/**\n * Your MyCalendarThree struct will be instantiated and called as such:\n * MyCalendarThree* obj = myCalendarThreeCreate();\n * int param_1 = myCalendarThreeBook(obj, start, end);\n \n * myCalendarThreeFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class MyCalendarThree {\n\n public MyCalendarThree() {\n\n }\n \n public int Book(int start, int end) {\n\n }\n}\n\n/**\n * Your MyCalendarThree object will be instantiated and called as such:\n * MyCalendarThree obj = new MyCalendarThree();\n * int param_1 = obj.Book(start,end);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "\nvar MyCalendarThree = function() {\n\n};\n\n/** \n * @param {number} start \n * @param {number} end\n * @return {number}\n */\nMyCalendarThree.prototype.book = function(start, end) {\n\n};\n\n/**\n * Your MyCalendarThree object will be instantiated and called as such:\n * var obj = new MyCalendarThree()\n * var param_1 = obj.book(start,end)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class MyCalendarThree\n def initialize()\n\n end\n\n\n=begin\n :type start: Integer\n :type end: Integer\n :rtype: Integer\n=end\n def book(start, end)\n\n end\n\n\nend\n\n# Your MyCalendarThree object will be instantiated and called as such:\n# obj = MyCalendarThree.new()\n# param_1 = obj.book(start, end)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass MyCalendarThree {\n\n init() {\n\n }\n \n func book(_ start: Int, _ end: Int) -> Int {\n\n }\n}\n\n/**\n * Your MyCalendarThree object will be instantiated and called as such:\n * let obj = MyCalendarThree()\n * let ret_1: Int = obj.book(start, end)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type MyCalendarThree struct {\n\n}\n\n\nfunc Constructor() MyCalendarThree {\n\n}\n\n\nfunc (this *MyCalendarThree) Book(start int, end int) int {\n\n}\n\n\n/**\n * Your MyCalendarThree object will be instantiated and called as such:\n * obj := Constructor();\n * param_1 := obj.Book(start,end);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class MyCalendarThree() {\n\n def book(start: Int, end: Int): Int = {\n\n }\n\n}\n\n/**\n * Your MyCalendarThree object will be instantiated and called as such:\n * var obj = new MyCalendarThree()\n * var param_1 = obj.book(start,end)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class MyCalendarThree() {\n\n fun book(start: Int, end: Int): Int {\n\n }\n\n}\n\n/**\n * Your MyCalendarThree object will be instantiated and called as such:\n * var obj = MyCalendarThree()\n * var param_1 = obj.book(start,end)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct MyCalendarThree {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl MyCalendarThree {\n\n fn new() -> Self {\n\n }\n \n fn book(&self, start: i32, end: i32) -> i32 {\n\n }\n}\n\n/**\n * Your MyCalendarThree object will be instantiated and called as such:\n * let obj = MyCalendarThree::new();\n * let ret_1: i32 = obj.book(start, end);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class MyCalendarThree {\n /**\n */\n function __construct() {\n\n }\n\n /**\n * @param Integer $start\n * @param Integer $end\n * @return Integer\n */\n function book($start, $end) {\n\n }\n}\n\n/**\n * Your MyCalendarThree object will be instantiated and called as such:\n * $obj = MyCalendarThree();\n * $ret_1 = $obj->book($start, $end);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class MyCalendarThree {\n constructor() {\n\n }\n\n book(start: number, end: number): number {\n\n }\n}\n\n/**\n * Your MyCalendarThree object will be instantiated and called as such:\n * var obj = new MyCalendarThree()\n * var param_1 = obj.book(start,end)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define my-calendar-three%\n (class object%\n (super-new)\n (init-field)\n \n ; book : exact-integer? exact-integer? -> exact-integer?\n (define/public (book start end)\n\n )))\n\n;; Your my-calendar-three% object will be instantiated and called as such:\n;; (define obj (new my-calendar-three%))\n;; (define param_1 (send obj book start end))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0732](https://leetcode-cn.com/problems/my-calendar-iii)", "[\u6211\u7684\u65e5\u7a0b\u5b89\u6392\u8868 III](/solution/0700-0799/0732.My%20Calendar%20III/README.md)", "`\u7ebf\u6bb5\u6811`", "\u56f0\u96be", ""], "md_table_row_en": ["[0732](https://leetcode.com/problems/my-calendar-iii)", "[My Calendar III](/solution/0700-0799/0732.My%20Calendar%20III/README_EN.md)", "`Segment Tree`,`Ordered Map`", "Hard", ""]}, {"question_id": "0731", "frontend_question_id": "0731", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/my-calendar-ii", "url_en": "https://leetcode.com/problems/my-calendar-ii", "relative_path_cn": "/solution/0700-0799/0731.My%20Calendar%20II/README.md", "relative_path_en": "/solution/0700-0799/0731.My%20Calendar%20II/README_EN.md", "title_cn": "\u6211\u7684\u65e5\u7a0b\u5b89\u6392\u8868 II", "title_en": "My Calendar II", "question_title_slug": "my-calendar-ii", "content_en": "

    Implement a MyCalendarTwo class to store your events. A new event can be added if adding the event will not cause a triple booking.

    \r\n\r\n

    Your class will have one method, book(int start, int end). Formally, this represents a booking on the half open interval [start, end), the range of real numbers x such that start <= x < end.

    \r\n\r\n

    A triple booking happens when three events have some non-empty intersection (ie., there is some time that is common to all 3 events.)

    \r\n\r\n

    For each call to the method MyCalendar.book, return true if the event can be added to the calendar successfully without causing a triple booking. Otherwise, return false and do not add the event to the calendar.

    \r\nYour class will be called like this: MyCalendar cal = new MyCalendar(); MyCalendar.book(start, end)\r\n\r\n

    Example 1:

    \r\n\r\n
    \r\nMyCalendar();\r\nMyCalendar.book(10, 20); // returns true\r\nMyCalendar.book(50, 60); // returns true\r\nMyCalendar.book(10, 40); // returns true\r\nMyCalendar.book(5, 15); // returns false\r\nMyCalendar.book(5, 10); // returns true\r\nMyCalendar.book(25, 55); // returns true\r\nExplanation: \r\nThe first two events can be booked.  The third event can be double booked.\r\nThe fourth event (5, 15) can't be booked, because it would result in a triple booking.\r\nThe fifth event (5, 10) can be booked, as it does not use time 10 which is already double booked.\r\nThe sixth event (25, 55) can be booked, as the time in [25, 40) will be double booked with the third event;\r\nthe time [40, 50) will be single booked, and the time [50, 55) will be double booked with the second event.\r\n
    \r\n\r\n

     

    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    • The number of calls to MyCalendar.book per test case will be at most 1000.
    • \r\n\t
    • In calls to MyCalendar.book(start, end), start and end are integers in the range [0, 10^9].
    • \r\n
    \r\n\r\n

     

    ", "content_cn": "

    \u5b9e\u73b0\u4e00\u4e2a MyCalendar \u7c7b\u6765\u5b58\u653e\u4f60\u7684\u65e5\u7a0b\u5b89\u6392\u3002\u5982\u679c\u8981\u6dfb\u52a0\u7684\u65f6\u95f4\u5185\u4e0d\u4f1a\u5bfc\u81f4\u4e09\u91cd\u9884\u8ba2\u65f6\uff0c\u5219\u53ef\u4ee5\u5b58\u50a8\u8fd9\u4e2a\u65b0\u7684\u65e5\u7a0b\u5b89\u6392\u3002

    \n\n

    MyCalendar \u6709\u4e00\u4e2a book(int start, int end)\u65b9\u6cd5\u3002\u5b83\u610f\u5473\u7740\u5728 start \u5230 end \u65f6\u95f4\u5185\u589e\u52a0\u4e00\u4e2a\u65e5\u7a0b\u5b89\u6392\uff0c\u6ce8\u610f\uff0c\u8fd9\u91cc\u7684\u65f6\u95f4\u662f\u534a\u5f00\u533a\u95f4\uff0c\u5373 [start, end), \u5b9e\u6570 x \u7684\u8303\u56f4\u4e3a\uff0c  start <= x < end\u3002

    \n\n

    \u5f53\u4e09\u4e2a\u65e5\u7a0b\u5b89\u6392\u6709\u4e00\u4e9b\u65f6\u95f4\u4e0a\u7684\u4ea4\u53c9\u65f6\uff08\u4f8b\u5982\u4e09\u4e2a\u65e5\u7a0b\u5b89\u6392\u90fd\u5728\u540c\u4e00\u65f6\u95f4\u5185\uff09\uff0c\u5c31\u4f1a\u4ea7\u751f\u4e09\u91cd\u9884\u8ba2\u3002

    \n\n

    \u6bcf\u6b21\u8c03\u7528 MyCalendar.book\u65b9\u6cd5\u65f6\uff0c\u5982\u679c\u53ef\u4ee5\u5c06\u65e5\u7a0b\u5b89\u6392\u6210\u529f\u6dfb\u52a0\u5230\u65e5\u5386\u4e2d\u800c\u4e0d\u4f1a\u5bfc\u81f4\u4e09\u91cd\u9884\u8ba2\uff0c\u8fd4\u56de true\u3002\u5426\u5219\uff0c\u8fd4\u56de false \u5e76\u4e14\u4e0d\u8981\u5c06\u8be5\u65e5\u7a0b\u5b89\u6392\u6dfb\u52a0\u5230\u65e5\u5386\u4e2d\u3002

    \n\n

    \u8bf7\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u8c03\u7528MyCalendar \u7c7b: MyCalendar cal = new MyCalendar(); MyCalendar.book(start, end)

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    MyCalendar();\nMyCalendar.book(10, 20); // returns true\nMyCalendar.book(50, 60); // returns true\nMyCalendar.book(10, 40); // returns true\nMyCalendar.book(5, 15); // returns false\nMyCalendar.book(5, 10); // returns true\nMyCalendar.book(25, 55); // returns true\n\u89e3\u91ca\uff1a \n\u524d\u4e24\u4e2a\u65e5\u7a0b\u5b89\u6392\u53ef\u4ee5\u6dfb\u52a0\u81f3\u65e5\u5386\u4e2d\u3002 \u7b2c\u4e09\u4e2a\u65e5\u7a0b\u5b89\u6392\u4f1a\u5bfc\u81f4\u53cc\u91cd\u9884\u8ba2\uff0c\u4f46\u53ef\u4ee5\u6dfb\u52a0\u81f3\u65e5\u5386\u4e2d\u3002\n\u7b2c\u56db\u4e2a\u65e5\u7a0b\u5b89\u6392\u6d3b\u52a8\uff085,15\uff09\u4e0d\u80fd\u6dfb\u52a0\u81f3\u65e5\u5386\u4e2d\uff0c\u56e0\u4e3a\u5b83\u4f1a\u5bfc\u81f4\u4e09\u91cd\u9884\u8ba2\u3002\n\u7b2c\u4e94\u4e2a\u65e5\u7a0b\u5b89\u6392\uff085,10\uff09\u53ef\u4ee5\u6dfb\u52a0\u81f3\u65e5\u5386\u4e2d\uff0c\u56e0\u4e3a\u5b83\u672a\u4f7f\u7528\u5df2\u7ecf\u53cc\u91cd\u9884\u8ba2\u7684\u65f6\u95f410\u3002\n\u7b2c\u516d\u4e2a\u65e5\u7a0b\u5b89\u6392\uff0825,55\uff09\u53ef\u4ee5\u6dfb\u52a0\u81f3\u65e5\u5386\u4e2d\uff0c\u56e0\u4e3a\u65f6\u95f4 [25,40] \u5c06\u548c\u7b2c\u4e09\u4e2a\u65e5\u7a0b\u5b89\u6392\u53cc\u91cd\u9884\u8ba2\uff1b\n\u65f6\u95f4 [40,50] \u5c06\u5355\u72ec\u9884\u8ba2\uff0c\u65f6\u95f4 [50,55\uff09\u5c06\u548c\u7b2c\u4e8c\u4e2a\u65e5\u7a0b\u5b89\u6392\u53cc\u91cd\u9884\u8ba2\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6bcf\u4e2a\u6d4b\u8bd5\u7528\u4f8b\uff0c\u8c03\u7528 MyCalendar.book \u51fd\u6570\u6700\u591a\u4e0d\u8d85\u8fc7 1000\u6b21\u3002
    • \n\t
    • \u8c03\u7528\u51fd\u6570 MyCalendar.book(start, end)\u65f6\uff0c start \u548c end \u7684\u53d6\u503c\u8303\u56f4\u4e3a [0, 10^9]\u3002
    • \n
    \n", "tags_en": ["Ordered Map"], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class MyCalendarTwo {\npublic:\n MyCalendarTwo() {\n\n }\n \n bool book(int start, int end) {\n\n }\n};\n\n/**\n * Your MyCalendarTwo object will be instantiated and called as such:\n * MyCalendarTwo* obj = new MyCalendarTwo();\n * bool param_1 = obj->book(start,end);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class MyCalendarTwo {\n\n public MyCalendarTwo() {\n\n }\n \n public boolean book(int start, int end) {\n\n }\n}\n\n/**\n * Your MyCalendarTwo object will be instantiated and called as such:\n * MyCalendarTwo obj = new MyCalendarTwo();\n * boolean param_1 = obj.book(start,end);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class MyCalendarTwo(object):\n\n def __init__(self):\n \n\n def book(self, start, end):\n \"\"\"\n :type start: int\n :type end: int\n :rtype: bool\n \"\"\"\n \n\n\n# Your MyCalendarTwo object will be instantiated and called as such:\n# obj = MyCalendarTwo()\n# param_1 = obj.book(start,end)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class MyCalendarTwo:\n\n def __init__(self):\n \n\n def book(self, start: int, end: int) -> bool:\n \n\n\n# Your MyCalendarTwo object will be instantiated and called as such:\n# obj = MyCalendarTwo()\n# param_1 = obj.book(start,end)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} MyCalendarTwo;\n\n\nMyCalendarTwo* myCalendarTwoCreate() {\n \n}\n\nbool myCalendarTwoBook(MyCalendarTwo* obj, int start, int end) {\n \n}\n\nvoid myCalendarTwoFree(MyCalendarTwo* obj) {\n \n}\n\n/**\n * Your MyCalendarTwo struct will be instantiated and called as such:\n * MyCalendarTwo* obj = myCalendarTwoCreate();\n * bool param_1 = myCalendarTwoBook(obj, start, end);\n \n * myCalendarTwoFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class MyCalendarTwo {\n\n public MyCalendarTwo() {\n\n }\n \n public bool Book(int start, int end) {\n\n }\n}\n\n/**\n * Your MyCalendarTwo object will be instantiated and called as such:\n * MyCalendarTwo obj = new MyCalendarTwo();\n * bool param_1 = obj.Book(start,end);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "\nvar MyCalendarTwo = function() {\n\n};\n\n/** \n * @param {number} start \n * @param {number} end\n * @return {boolean}\n */\nMyCalendarTwo.prototype.book = function(start, end) {\n\n};\n\n/**\n * Your MyCalendarTwo object will be instantiated and called as such:\n * var obj = new MyCalendarTwo()\n * var param_1 = obj.book(start,end)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class MyCalendarTwo\n def initialize()\n\n end\n\n\n=begin\n :type start: Integer\n :type end: Integer\n :rtype: Boolean\n=end\n def book(start, end)\n\n end\n\n\nend\n\n# Your MyCalendarTwo object will be instantiated and called as such:\n# obj = MyCalendarTwo.new()\n# param_1 = obj.book(start, end)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass MyCalendarTwo {\n\n init() {\n \n }\n \n func book(_ start: Int, _ end: Int) -> Bool {\n \n }\n}\n\n/**\n * Your MyCalendarTwo object will be instantiated and called as such:\n * let obj = MyCalendarTwo()\n * let ret_1: Bool = obj.book(start, end)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type MyCalendarTwo struct {\n\n}\n\n\nfunc Constructor() MyCalendarTwo {\n\n}\n\n\nfunc (this *MyCalendarTwo) Book(start int, end int) bool {\n\n}\n\n\n/**\n * Your MyCalendarTwo object will be instantiated and called as such:\n * obj := Constructor();\n * param_1 := obj.Book(start,end);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class MyCalendarTwo() {\n\n def book(start: Int, end: Int): Boolean = {\n\n }\n\n}\n\n/**\n * Your MyCalendarTwo object will be instantiated and called as such:\n * var obj = new MyCalendarTwo()\n * var param_1 = obj.book(start,end)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class MyCalendarTwo() {\n\n fun book(start: Int, end: Int): Boolean {\n\n }\n\n}\n\n/**\n * Your MyCalendarTwo object will be instantiated and called as such:\n * var obj = MyCalendarTwo()\n * var param_1 = obj.book(start,end)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct MyCalendarTwo {\n\n}\n\n\n/** \n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl MyCalendarTwo {\n\n fn new() -> Self {\n \n }\n \n fn book(&self, start: i32, end: i32) -> bool {\n \n }\n}\n\n/**\n * Your MyCalendarTwo object will be instantiated and called as such:\n * let obj = MyCalendarTwo::new();\n * let ret_1: bool = obj.book(start, end);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class MyCalendarTwo {\n /**\n */\n function __construct() {\n \n }\n \n /**\n * @param Integer $start\n * @param Integer $end\n * @return Boolean\n */\n function book($start, $end) {\n \n }\n}\n\n/**\n * Your MyCalendarTwo object will be instantiated and called as such:\n * $obj = MyCalendarTwo();\n * $ret_1 = $obj->book($start, $end);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class MyCalendarTwo {\n constructor() {\n\n }\n\n book(start: number, end: number): boolean {\n\n }\n}\n\n/**\n * Your MyCalendarTwo object will be instantiated and called as such:\n * var obj = new MyCalendarTwo()\n * var param_1 = obj.book(start,end)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define my-calendar-two%\n (class object%\n (super-new)\n (init-field)\n \n ; book : exact-integer? exact-integer? -> boolean?\n (define/public (book start end)\n\n )))\n\n;; Your my-calendar-two% object will be instantiated and called as such:\n;; (define obj (new my-calendar-two%))\n;; (define param_1 (send obj book start end))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0731](https://leetcode-cn.com/problems/my-calendar-ii)", "[\u6211\u7684\u65e5\u7a0b\u5b89\u6392\u8868 II](/solution/0700-0799/0731.My%20Calendar%20II/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0731](https://leetcode.com/problems/my-calendar-ii)", "[My Calendar II](/solution/0700-0799/0731.My%20Calendar%20II/README_EN.md)", "`Ordered Map`", "Medium", ""]}, {"question_id": "0730", "frontend_question_id": "0730", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-different-palindromic-subsequences", "url_en": "https://leetcode.com/problems/count-different-palindromic-subsequences", "relative_path_cn": "/solution/0700-0799/0730.Count%20Different%20Palindromic%20Subsequences/README.md", "relative_path_en": "/solution/0700-0799/0730.Count%20Different%20Palindromic%20Subsequences/README_EN.md", "title_cn": "\u7edf\u8ba1\u4e0d\u540c\u56de\u6587\u5b50\u5e8f\u5217", "title_en": "Count Different Palindromic Subsequences", "question_title_slug": "count-different-palindromic-subsequences", "content_en": "

    Given a string s, return the number of different non-empty palindromic subsequences in s. Since the answer may be very large, return it modulo 109 + 7.

    \n\n

    A subsequence of a string is obtained by deleting zero or more characters from the string.

    \n\n

    A sequence is palindromic if it is equal to the sequence reversed.

    \n\n

    Two sequences a1, a2, ... and b1, b2, ... are different if there is some i for which ai != bi.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "bccb"\nOutput: 6\nExplanation: The 6 different non-empty palindromic subsequences are 'b', 'c', 'bb', 'cc', 'bcb', 'bccb'.\nNote that 'bcb' is counted only once, even though it occurs twice.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "abcdabcdabcdabcdabcdabcdabcdabcddcbadcbadcbadcbadcbadcbadcbadcba"\nOutput: 104860361\nExplanation: There are 3104860382 different non-empty palindromic subsequences, which is 104860361 modulo 109 + 7.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 1000
    • \n\t
    • s[i] is either 'a', 'b', 'c', or 'd'.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32 S\uff0c\u627e\u51fa S \u4e2d\u4e0d\u540c\u7684\u975e\u7a7a\u56de\u6587\u5b50\u5e8f\u5217\u4e2a\u6570\uff0c\u5e76\u8fd4\u56de\u8be5\u6570\u5b57\u4e0e 10^9 + 7 \u7684\u6a21\u3002

    \n\n

    \u901a\u8fc7\u4ece S \u4e2d\u5220\u9664 0 \u4e2a\u6216\u591a\u4e2a\u5b57\u7b26\u6765\u83b7\u5f97\u5b50\u5e8f\u5217\u3002

    \n\n

    \u5982\u679c\u4e00\u4e2a\u5b57\u7b26\u5e8f\u5217\u4e0e\u5b83\u53cd\u8f6c\u540e\u7684\u5b57\u7b26\u5e8f\u5217\u4e00\u81f4\uff0c\u90a3\u4e48\u5b83\u662f\u56de\u6587\u5b57\u7b26\u5e8f\u5217\u3002

    \n\n

    \u5982\u679c\u5bf9\u4e8e\u67d0\u4e2a  i\uff0cA_i != B_i\uff0c\u90a3\u4e48 A_1, A_2, ... \u548c B_1, B_2, ... \u8fd9\u4e24\u4e2a\u5b57\u7b26\u5e8f\u5217\u662f\u4e0d\u540c\u7684\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a\nS = 'bccb'\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\n6 \u4e2a\u4e0d\u540c\u7684\u975e\u7a7a\u56de\u6587\u5b50\u5b57\u7b26\u5e8f\u5217\u5206\u522b\u4e3a\uff1a'b', 'c', 'bb', 'cc', 'bcb', 'bccb'\u3002\n\u6ce8\u610f\uff1a'bcb' \u867d\u7136\u51fa\u73b0\u4e24\u6b21\u4f46\u4ec5\u8ba1\u6570\u4e00\u6b21\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a\nS = 'abcdabcdabcdabcdabcdabcdabcdabcddcbadcbadcbadcbadcbadcbadcbadcba'\n\u8f93\u51fa\uff1a104860361\n\u89e3\u91ca\uff1a\n\u5171\u6709 3104860382 \u4e2a\u4e0d\u540c\u7684\u975e\u7a7a\u56de\u6587\u5b50\u5e8f\u5217\uff0c\u5bf9 10^9 + 7 \u53d6\u6a21\u4e3a 104860361\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u5b57\u7b26\u4e32 S \u7684\u957f\u5ea6\u5c06\u5728[1, 1000]\u8303\u56f4\u5185\u3002
    • \n\t
    • \u6bcf\u4e2a\u5b57\u7b26 S[i] \u5c06\u4f1a\u662f\u96c6\u5408 {'a', 'b', 'c', 'd'} \u4e2d\u7684\u67d0\u4e00\u4e2a\u3002
    • \n
    \n\n

     

    \n", "tags_en": ["String", "Dynamic Programming"], "tags_cn": ["\u5b57\u7b26\u4e32", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countPalindromicSubsequences(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countPalindromicSubsequences(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countPalindromicSubsequences(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countPalindromicSubsequences(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countPalindromicSubsequences(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountPalindromicSubsequences(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar countPalindromicSubsequences = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef count_palindromic_subsequences(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countPalindromicSubsequences(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countPalindromicSubsequences(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countPalindromicSubsequences(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countPalindromicSubsequences(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_palindromic_subsequences(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function countPalindromicSubsequences($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countPalindromicSubsequences(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-palindromic-subsequences s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0730](https://leetcode-cn.com/problems/count-different-palindromic-subsequences)", "[\u7edf\u8ba1\u4e0d\u540c\u56de\u6587\u5b50\u5e8f\u5217](/solution/0700-0799/0730.Count%20Different%20Palindromic%20Subsequences/README.md)", "`\u5b57\u7b26\u4e32`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0730](https://leetcode.com/problems/count-different-palindromic-subsequences)", "[Count Different Palindromic Subsequences](/solution/0700-0799/0730.Count%20Different%20Palindromic%20Subsequences/README_EN.md)", "`String`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0729", "frontend_question_id": "0729", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/my-calendar-i", "url_en": "https://leetcode.com/problems/my-calendar-i", "relative_path_cn": "/solution/0700-0799/0729.My%20Calendar%20I/README.md", "relative_path_en": "/solution/0700-0799/0729.My%20Calendar%20I/README_EN.md", "title_cn": "\u6211\u7684\u65e5\u7a0b\u5b89\u6392\u8868 I", "title_en": "My Calendar I", "question_title_slug": "my-calendar-i", "content_en": "

    Implement a MyCalendar class to store your events. A new event can be added if adding the event will not cause a double booking.

    \r\n\r\n

    Your class will have the method, book(int start, int end). Formally, this represents a booking on the half open interval [start, end), the range of real numbers x such that start <= x < end.

    \r\n\r\n

    A double booking happens when two events have some non-empty intersection (ie., there is some time that is common to both events.)

    \r\n\r\n

    For each call to the method MyCalendar.book, return true if the event can be added to the calendar successfully without causing a double booking. Otherwise, return false and do not add the event to the calendar.

    \r\nYour class will be called like this: MyCalendar cal = new MyCalendar(); MyCalendar.book(start, end)\r\n\r\n

    Example 1:

    \r\n\r\n
    \r\nMyCalendar();\r\nMyCalendar.book(10, 20); // returns true\r\nMyCalendar.book(15, 25); // returns false\r\nMyCalendar.book(20, 30); // returns true\r\nExplanation: \r\nThe first event can be booked.  The second can't because time 15 is already booked by another event.\r\nThe third event can be booked, as the first event takes every time less than 20, but not including 20.\r\n
    \r\n\r\n

     

    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    • The number of calls to MyCalendar.book per test case will be at most 1000.
    • \r\n\t
    • In calls to MyCalendar.book(start, end), start and end are integers in the range [0, 10^9].
    • \r\n
    \r\n\r\n

     

    \r\n", "content_cn": "

    \u5b9e\u73b0\u4e00\u4e2a MyCalendar \u7c7b\u6765\u5b58\u653e\u4f60\u7684\u65e5\u7a0b\u5b89\u6392\u3002\u5982\u679c\u8981\u6dfb\u52a0\u7684\u65f6\u95f4\u5185\u6ca1\u6709\u5176\u4ed6\u5b89\u6392\uff0c\u5219\u53ef\u4ee5\u5b58\u50a8\u8fd9\u4e2a\u65b0\u7684\u65e5\u7a0b\u5b89\u6392\u3002

    \n\n

    MyCalendar \u6709\u4e00\u4e2a book(int start, int end)\u65b9\u6cd5\u3002\u5b83\u610f\u5473\u7740\u5728 start \u5230 end \u65f6\u95f4\u5185\u589e\u52a0\u4e00\u4e2a\u65e5\u7a0b\u5b89\u6392\uff0c\u6ce8\u610f\uff0c\u8fd9\u91cc\u7684\u65f6\u95f4\u662f\u534a\u5f00\u533a\u95f4\uff0c\u5373 [start, end), \u5b9e\u6570\u00a0x \u7684\u8303\u56f4\u4e3a\uff0c \u00a0start <= x < end\u3002

    \n\n

    \u5f53\u4e24\u4e2a\u65e5\u7a0b\u5b89\u6392\u6709\u4e00\u4e9b\u65f6\u95f4\u4e0a\u7684\u4ea4\u53c9\u65f6\uff08\u4f8b\u5982\u4e24\u4e2a\u65e5\u7a0b\u5b89\u6392\u90fd\u5728\u540c\u4e00\u65f6\u95f4\u5185\uff09\uff0c\u5c31\u4f1a\u4ea7\u751f\u91cd\u590d\u9884\u8ba2\u3002

    \n\n

    \u6bcf\u6b21\u8c03\u7528 MyCalendar.book\u65b9\u6cd5\u65f6\uff0c\u5982\u679c\u53ef\u4ee5\u5c06\u65e5\u7a0b\u5b89\u6392\u6210\u529f\u6dfb\u52a0\u5230\u65e5\u5386\u4e2d\u800c\u4e0d\u4f1a\u5bfc\u81f4\u91cd\u590d\u9884\u8ba2\uff0c\u8fd4\u56de true\u3002\u5426\u5219\uff0c\u8fd4\u56de false\u00a0\u5e76\u4e14\u4e0d\u8981\u5c06\u8be5\u65e5\u7a0b\u5b89\u6392\u6dfb\u52a0\u5230\u65e5\u5386\u4e2d\u3002

    \n\n

    \u8bf7\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u8c03\u7528 MyCalendar \u7c7b: MyCalendar cal = new MyCalendar(); MyCalendar.book(start, end)

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \nMyCalendar();\nMyCalendar.book(10, 20); // returns true\nMyCalendar.book(15, 25); // returns false\nMyCalendar.book(20, 30); // returns true\n\u89e3\u91ca: \n\u7b2c\u4e00\u4e2a\u65e5\u7a0b\u5b89\u6392\u53ef\u4ee5\u6dfb\u52a0\u5230\u65e5\u5386\u4e2d.  \u7b2c\u4e8c\u4e2a\u65e5\u7a0b\u5b89\u6392\u4e0d\u80fd\u6dfb\u52a0\u5230\u65e5\u5386\u4e2d\uff0c\u56e0\u4e3a\u65f6\u95f4 15 \u5df2\u7ecf\u88ab\u7b2c\u4e00\u4e2a\u65e5\u7a0b\u5b89\u6392\u9884\u5b9a\u4e86\u3002\n\u7b2c\u4e09\u4e2a\u65e5\u7a0b\u5b89\u6392\u53ef\u4ee5\u6dfb\u52a0\u5230\u65e5\u5386\u4e2d\uff0c\u56e0\u4e3a\u7b2c\u4e00\u4e2a\u65e5\u7a0b\u5b89\u6392\u5e76\u4e0d\u5305\u542b\u65f6\u95f4 20 \u3002\n
    \n\n

    \u8bf4\u660e:

    \n\n
      \n\t
    • \u6bcf\u4e2a\u6d4b\u8bd5\u7528\u4f8b\uff0c\u8c03\u7528\u00a0MyCalendar.book\u00a0\u51fd\u6570\u6700\u591a\u4e0d\u8d85\u8fc7\u00a01000\u6b21\u3002
    • \n\t
    • \u8c03\u7528\u51fd\u6570\u00a0MyCalendar.book(start, end)\u65f6\uff0c\u00a0start \u548c\u00a0end \u7684\u53d6\u503c\u8303\u56f4\u4e3a\u00a0[0, 10^9]\u3002
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class MyCalendar {\npublic:\n MyCalendar() {\n\n }\n \n bool book(int start, int end) {\n\n }\n};\n\n/**\n * Your MyCalendar object will be instantiated and called as such:\n * MyCalendar* obj = new MyCalendar();\n * bool param_1 = obj->book(start,end);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class MyCalendar {\n\n public MyCalendar() {\n\n }\n \n public boolean book(int start, int end) {\n\n }\n}\n\n/**\n * Your MyCalendar object will be instantiated and called as such:\n * MyCalendar obj = new MyCalendar();\n * boolean param_1 = obj.book(start,end);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class MyCalendar(object):\n\n def __init__(self):\n \n\n def book(self, start, end):\n \"\"\"\n :type start: int\n :type end: int\n :rtype: bool\n \"\"\"\n \n\n\n# Your MyCalendar object will be instantiated and called as such:\n# obj = MyCalendar()\n# param_1 = obj.book(start,end)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class MyCalendar:\n\n def __init__(self):\n \n\n def book(self, start: int, end: int) -> bool:\n \n\n\n# Your MyCalendar object will be instantiated and called as such:\n# obj = MyCalendar()\n# param_1 = obj.book(start,end)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} MyCalendar;\n\n\nMyCalendar* myCalendarCreate() {\n \n}\n\nbool myCalendarBook(MyCalendar* obj, int start, int end) {\n \n}\n\nvoid myCalendarFree(MyCalendar* obj) {\n \n}\n\n/**\n * Your MyCalendar struct will be instantiated and called as such:\n * MyCalendar* obj = myCalendarCreate();\n * bool param_1 = myCalendarBook(obj, start, end);\n \n * myCalendarFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class MyCalendar {\n\n public MyCalendar() {\n\n }\n \n public bool Book(int start, int end) {\n\n }\n}\n\n/**\n * Your MyCalendar object will be instantiated and called as such:\n * MyCalendar obj = new MyCalendar();\n * bool param_1 = obj.Book(start,end);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "\nvar MyCalendar = function() {\n\n};\n\n/** \n * @param {number} start \n * @param {number} end\n * @return {boolean}\n */\nMyCalendar.prototype.book = function(start, end) {\n\n};\n\n/**\n * Your MyCalendar object will be instantiated and called as such:\n * var obj = new MyCalendar()\n * var param_1 = obj.book(start,end)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class MyCalendar\n def initialize()\n\n end\n\n\n=begin\n :type start: Integer\n :type end: Integer\n :rtype: Boolean\n=end\n def book(start, end)\n\n end\n\n\nend\n\n# Your MyCalendar object will be instantiated and called as such:\n# obj = MyCalendar.new()\n# param_1 = obj.book(start, end)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass MyCalendar {\n\n init() {\n \n }\n \n func book(_ start: Int, _ end: Int) -> Bool {\n \n }\n}\n\n/**\n * Your MyCalendar object will be instantiated and called as such:\n * let obj = MyCalendar()\n * let ret_1: Bool = obj.book(start, end)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type MyCalendar struct {\n\n}\n\n\nfunc Constructor() MyCalendar {\n\n}\n\n\nfunc (this *MyCalendar) Book(start int, end int) bool {\n\n}\n\n\n/**\n * Your MyCalendar object will be instantiated and called as such:\n * obj := Constructor();\n * param_1 := obj.Book(start,end);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class MyCalendar() {\n\n def book(start: Int, end: Int): Boolean = {\n\n }\n\n}\n\n/**\n * Your MyCalendar object will be instantiated and called as such:\n * var obj = new MyCalendar()\n * var param_1 = obj.book(start,end)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class MyCalendar() {\n\n fun book(start: Int, end: Int): Boolean {\n\n }\n\n}\n\n/**\n * Your MyCalendar object will be instantiated and called as such:\n * var obj = MyCalendar()\n * var param_1 = obj.book(start,end)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct MyCalendar {\n\n}\n\n\n/** \n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl MyCalendar {\n\n fn new() -> Self {\n \n }\n \n fn book(&self, start: i32, end: i32) -> bool {\n \n }\n}\n\n/**\n * Your MyCalendar object will be instantiated and called as such:\n * let obj = MyCalendar::new();\n * let ret_1: bool = obj.book(start, end);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class MyCalendar {\n /**\n */\n function __construct() {\n \n }\n \n /**\n * @param Integer $start\n * @param Integer $end\n * @return Boolean\n */\n function book($start, $end) {\n \n }\n}\n\n/**\n * Your MyCalendar object will be instantiated and called as such:\n * $obj = MyCalendar();\n * $ret_1 = $obj->book($start, $end);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class MyCalendar {\n constructor() {\n\n }\n\n book(start: number, end: number): boolean {\n\n }\n}\n\n/**\n * Your MyCalendar object will be instantiated and called as such:\n * var obj = new MyCalendar()\n * var param_1 = obj.book(start,end)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define my-calendar%\n (class object%\n (super-new)\n (init-field)\n \n ; book : exact-integer? exact-integer? -> boolean?\n (define/public (book start end)\n\n )))\n\n;; Your my-calendar% object will be instantiated and called as such:\n;; (define obj (new my-calendar%))\n;; (define param_1 (send obj book start end))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0729](https://leetcode-cn.com/problems/my-calendar-i)", "[\u6211\u7684\u65e5\u7a0b\u5b89\u6392\u8868 I](/solution/0700-0799/0729.My%20Calendar%20I/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0729](https://leetcode.com/problems/my-calendar-i)", "[My Calendar I](/solution/0700-0799/0729.My%20Calendar%20I/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0728", "frontend_question_id": "0728", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/self-dividing-numbers", "url_en": "https://leetcode.com/problems/self-dividing-numbers", "relative_path_cn": "/solution/0700-0799/0728.Self%20Dividing%20Numbers/README.md", "relative_path_en": "/solution/0700-0799/0728.Self%20Dividing%20Numbers/README_EN.md", "title_cn": "\u81ea\u9664\u6570", "title_en": "Self Dividing Numbers", "question_title_slug": "self-dividing-numbers", "content_en": "

    A self-dividing number is a number that is divisible by every digit it contains.

    \n\n
      \n\t
    • For example, 128 is a self-dividing number because 128 % 1 == 0, 128 % 2 == 0, and 128 % 8 == 0.
    • \n
    \n\n

    A self-dividing number is not allowed to contain the digit zero.

    \n\n

    Given two integers left and right, return a list of all the self-dividing numbers in the range [left, right].

    \n\n

     

    \n

    Example 1:

    \n
    Input: left = 1, right = 22\nOutput: [1,2,3,4,5,6,7,8,9,11,12,15,22]\n

    Example 2:

    \n
    Input: left = 47, right = 85\nOutput: [48,55,66,77]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= left <= right <= 104
    • \n
    \n", "content_cn": "

    \u81ea\u9664\u6570 \u662f\u6307\u53ef\u4ee5\u88ab\u5b83\u5305\u542b\u7684\u6bcf\u4e00\u4f4d\u6570\u9664\u5c3d\u7684\u6570\u3002

    \n\n

    \u4f8b\u5982\uff0c128 \u662f\u4e00\u4e2a\u81ea\u9664\u6570\uff0c\u56e0\u4e3a 128 % 1 == 0\uff0c128 % 2 == 0\uff0c128 % 8 == 0\u3002

    \n\n

    \u8fd8\u6709\uff0c\u81ea\u9664\u6570\u4e0d\u5141\u8bb8\u5305\u542b 0 \u3002

    \n\n

    \u7ed9\u5b9a\u4e0a\u8fb9\u754c\u548c\u4e0b\u8fb9\u754c\u6570\u5b57\uff0c\u8f93\u51fa\u4e00\u4e2a\u5217\u8868\uff0c\u5217\u8868\u7684\u5143\u7d20\u662f\u8fb9\u754c\uff08\u542b\u8fb9\u754c\uff09\u5185\u6240\u6709\u7684\u81ea\u9664\u6570\u3002

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1a \n\u4e0a\u8fb9\u754cleft = 1, \u4e0b\u8fb9\u754cright = 22\n\u8f93\u51fa\uff1a [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 15, 22]\n
    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    • \u6bcf\u4e2a\u8f93\u5165\u53c2\u6570\u7684\u8fb9\u754c\u6ee1\u8db3 1 <= left <= right <= 10000\u3002
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector selfDividingNumbers(int left, int right) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List selfDividingNumbers(int left, int right) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def selfDividingNumbers(self, left, right):\n \"\"\"\n :type left: int\n :type right: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def selfDividingNumbers(self, left: int, right: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* selfDividingNumbers(int left, int right, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList SelfDividingNumbers(int left, int right) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} left\n * @param {number} right\n * @return {number[]}\n */\nvar selfDividingNumbers = function(left, right) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} left\n# @param {Integer} right\n# @return {Integer[]}\ndef self_dividing_numbers(left, right)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func selfDividingNumbers(_ left: Int, _ right: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func selfDividingNumbers(left int, right int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def selfDividingNumbers(left: Int, right: Int): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun selfDividingNumbers(left: Int, right: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn self_dividing_numbers(left: i32, right: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $left\n * @param Integer $right\n * @return Integer[]\n */\n function selfDividingNumbers($left, $right) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function selfDividingNumbers(left: number, right: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (self-dividing-numbers left right)\n (-> exact-integer? exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0728](https://leetcode-cn.com/problems/self-dividing-numbers)", "[\u81ea\u9664\u6570](/solution/0700-0799/0728.Self%20Dividing%20Numbers/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0728](https://leetcode.com/problems/self-dividing-numbers)", "[Self Dividing Numbers](/solution/0700-0799/0728.Self%20Dividing%20Numbers/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "0727", "frontend_question_id": "0727", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/minimum-window-subsequence", "url_en": "https://leetcode.com/problems/minimum-window-subsequence", "relative_path_cn": "/solution/0700-0799/0727.Minimum%20Window%20Subsequence/README.md", "relative_path_en": "/solution/0700-0799/0727.Minimum%20Window%20Subsequence/README_EN.md", "title_cn": "\u6700\u5c0f\u7a97\u53e3\u5b50\u5e8f\u5217", "title_en": "Minimum Window Subsequence", "question_title_slug": "minimum-window-subsequence", "content_en": "

    Given strings s1 and s2, return the minimum contiguous substring part of s1, so that s2 is a subsequence of the part.

    \n\n

    If there is no such window in s1 that covers all characters in s2, return the empty string "". If there are multiple such minimum-length windows, return the one with the left-most starting index.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s1 = "abcdebdde", s2 = "bde"\nOutput: "bcde"\nExplanation: \n"bcde" is the answer because it occurs before "bdde" which has the same length.\n"deb" is not a smaller window because the elements of s2 in the window must occur in order.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s1 = "jmeqksfrsdcmsiwvaovztaqenprpvnbstl", s2 = "u"\nOutput: ""\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s1.length <= 2 * 104
    • \n\t
    • 1 <= s2.length <= 100
    • \n\t
    • s1 and s2 consist of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u5b57\u7b26\u4e32 S and T\uff0c\u627e\u51fa S \u4e2d\u6700\u77ed\u7684\uff08\u8fde\u7eed\uff09\u5b50\u4e32 W \uff0c\u4f7f\u5f97 T \u662f W \u7684 \u5b50\u5e8f\u5217 \u3002

    \n\n

    \u5982\u679c S \u4e2d\u6ca1\u6709\u7a97\u53e3\u53ef\u4ee5\u5305\u542b T \u4e2d\u7684\u6240\u6709\u5b57\u7b26\uff0c\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32 ""\u3002\u5982\u679c\u6709\u4e0d\u6b62\u4e00\u4e2a\u6700\u77ed\u957f\u5ea6\u7684\u7a97\u53e3\uff0c\u8fd4\u56de\u5f00\u59cb\u4f4d\u7f6e\u6700\u9760\u5de6\u7684\u90a3\u4e2a\u3002

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a\nS = "abcdebdde", T = "bde"\n\u8f93\u51fa\uff1a"bcde"\n\u89e3\u91ca\uff1a\n"bcde" \u662f\u7b54\u6848\uff0c\u56e0\u4e3a\u5b83\u5728\u76f8\u540c\u957f\u5ea6\u7684\u5b57\u7b26\u4e32 "bdde" \u51fa\u73b0\u4e4b\u524d\u3002\n"deb" \u4e0d\u662f\u4e00\u4e2a\u66f4\u77ed\u7684\u7b54\u6848\uff0c\u56e0\u4e3a\u5728\u7a97\u53e3\u4e2d\u5fc5\u987b\u6309\u987a\u5e8f\u51fa\u73b0 T \u4e2d\u7684\u5143\u7d20\u3002
    \n\n

     

    \n\n

    \u6ce8\uff1a

    \n\n
      \n\t
    • \u6240\u6709\u8f93\u5165\u7684\u5b57\u7b26\u4e32\u90fd\u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd\u3002All the strings in the input will only contain lowercase letters.
    • \n\t
    • S \u957f\u5ea6\u7684\u8303\u56f4\u4e3a [1, 20000]\u3002
    • \n\t
    • T \u957f\u5ea6\u7684\u8303\u56f4\u4e3a [1, 100]\u3002
    • \n
    \n\n

     

    \n", "tags_en": ["Dynamic Programming", "Sliding Window"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string minWindow(string s1, string s2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String minWindow(String s1, String s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minWindow(self, s1, s2):\n \"\"\"\n :type s1: str\n :type s2: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minWindow(self, s1: str, s2: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * minWindow(char * s1, char * s2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string MinWindow(string s1, string s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s1\n * @param {string} s2\n * @return {string}\n */\nvar minWindow = function(s1, s2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s1\n# @param {String} s2\n# @return {String}\ndef min_window(s1, s2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minWindow(_ s1: String, _ s2: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minWindow(s1 string, s2 string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minWindow(s1: String, s2: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minWindow(s1: String, s2: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_window(s1: String, s2: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s1\n * @param String $s2\n * @return String\n */\n function minWindow($s1, $s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minWindow(s1: string, s2: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-window s1 s2)\n (-> string? string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0727](https://leetcode-cn.com/problems/minimum-window-subsequence)", "[\u6700\u5c0f\u7a97\u53e3\u5b50\u5e8f\u5217](/solution/0700-0799/0727.Minimum%20Window%20Subsequence/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0727](https://leetcode.com/problems/minimum-window-subsequence)", "[Minimum Window Subsequence](/solution/0700-0799/0727.Minimum%20Window%20Subsequence/README_EN.md)", "`Dynamic Programming`,`Sliding Window`", "Hard", "\ud83d\udd12"]}, {"question_id": "0726", "frontend_question_id": "0726", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-atoms", "url_en": "https://leetcode.com/problems/number-of-atoms", "relative_path_cn": "/solution/0700-0799/0726.Number%20of%20Atoms/README.md", "relative_path_en": "/solution/0700-0799/0726.Number%20of%20Atoms/README_EN.md", "title_cn": "\u539f\u5b50\u7684\u6570\u91cf", "title_en": "Number of Atoms", "question_title_slug": "number-of-atoms", "content_en": "

    Given a chemical formula (given as a string), return the count of each atom.

    \n\n

    The atomic element always starts with an uppercase character, then zero or more lowercase letters, representing the name.

    \n\n

    One or more digits representing that element's count may follow if the count is greater than 1. If the count is 1, no digits will follow. For example, H2O and H2O2 are possible, but H1O2 is impossible.

    \n\n

    Two formulas concatenated together to produce another formula. For example, H2O2He3Mg4 is also a formula.

    \n\n

    A formula placed in parentheses, and a count (optionally added) is also a formula. For example, (H2O2) and (H2O2)3 are formulas.

    \n\n

    Given a formula, return the count of all elements as a string in the following form: the first name (in sorted order), followed by its count (if that count is more than 1), followed by the second name (in sorted order), followed by its count (if that count is more than 1), and so on.

    \n\n

     

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: formula = "H2O"\nOutput: "H2O"\nExplanation: The count of elements are {'H': 2, 'O': 1}.\n
    \n\n

    Example 2:

    \n\n
    \nInput: formula = "Mg(OH)2"\nOutput: "H2MgO2"\nExplanation: The count of elements are {'H': 2, 'Mg': 1, 'O': 2}.\n
    \n\n

    Example 3:

    \n\n
    \nInput: formula = "K4(ON(SO3)2)2"\nOutput: "K4N2O14S4"\nExplanation: The count of elements are {'K': 4, 'N': 2, 'O': 14, 'S': 4}.\n
    \n\n

    Example 4:

    \n\n
    \nInput: formula = "Be32"\nOutput: "Be32"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= formula.length <= 1000
    • \n\t
    • formula consists of English letters, digits, '(', and ')'.
    • \n\t
    • formula is always valid.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5316\u5b66\u5f0fformula\uff08\u4f5c\u4e3a\u5b57\u7b26\u4e32\uff09\uff0c\u8fd4\u56de\u6bcf\u79cd\u539f\u5b50\u7684\u6570\u91cf\u3002

    \n\n

    \u539f\u5b50\u603b\u662f\u4ee5\u4e00\u4e2a\u5927\u5199\u5b57\u6bcd\u5f00\u59cb\uff0c\u63a5\u7740\u8ddf\u968f0\u4e2a\u6216\u4efb\u610f\u4e2a\u5c0f\u5199\u5b57\u6bcd\uff0c\u8868\u793a\u539f\u5b50\u7684\u540d\u5b57\u3002

    \n\n

    \u5982\u679c\u6570\u91cf\u5927\u4e8e 1\uff0c\u539f\u5b50\u540e\u4f1a\u8ddf\u7740\u6570\u5b57\u8868\u793a\u539f\u5b50\u7684\u6570\u91cf\u3002\u5982\u679c\u6570\u91cf\u7b49\u4e8e 1 \u5219\u4e0d\u4f1a\u8ddf\u6570\u5b57\u3002\u4f8b\u5982\uff0cH2O \u548c H2O2 \u662f\u53ef\u884c\u7684\uff0c\u4f46 H1O2 \u8fd9\u4e2a\u8868\u8fbe\u662f\u4e0d\u53ef\u884c\u7684\u3002

    \n\n

    \u4e24\u4e2a\u5316\u5b66\u5f0f\u8fde\u5728\u4e00\u8d77\u662f\u65b0\u7684\u5316\u5b66\u5f0f\u3002\u4f8b\u5982 H2O2He3Mg4 \u4e5f\u662f\u5316\u5b66\u5f0f\u3002

    \n\n

    \u4e00\u4e2a\u62ec\u53f7\u4e2d\u7684\u5316\u5b66\u5f0f\u548c\u6570\u5b57\uff08\u53ef\u9009\u62e9\u6027\u6dfb\u52a0\uff09\u4e5f\u662f\u5316\u5b66\u5f0f\u3002\u4f8b\u5982 (H2O2) \u548c (H2O2)3 \u662f\u5316\u5b66\u5f0f\u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u5316\u5b66\u5f0f\uff0c\u8f93\u51fa\u6240\u6709\u539f\u5b50\u7684\u6570\u91cf\u3002\u683c\u5f0f\u4e3a\uff1a\u7b2c\u4e00\u4e2a\uff08\u6309\u5b57\u5178\u5e8f\uff09\u539f\u5b50\u7684\u540d\u5b50\uff0c\u8ddf\u7740\u5b83\u7684\u6570\u91cf\uff08\u5982\u679c\u6570\u91cf\u5927\u4e8e 1\uff09\uff0c\u7136\u540e\u662f\u7b2c\u4e8c\u4e2a\u539f\u5b50\u7684\u540d\u5b57\uff08\u6309\u5b57\u5178\u5e8f\uff09\uff0c\u8ddf\u7740\u5b83\u7684\u6570\u91cf\uff08\u5982\u679c\u6570\u91cf\u5927\u4e8e 1\uff09\uff0c\u4ee5\u6b64\u7c7b\u63a8\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: \nformula = "H2O"\n\u8f93\u51fa: "H2O"\n\u89e3\u91ca: \n\u539f\u5b50\u7684\u6570\u91cf\u662f {'H': 2, 'O': 1}\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: \nformula = "Mg(OH)2"\n\u8f93\u51fa: "H2MgO2"\n\u89e3\u91ca: \n\u539f\u5b50\u7684\u6570\u91cf\u662f {'H': 2, 'Mg': 1, 'O': 2}\u3002\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \n\u8f93\u5165: \nformula = "K4(ON(SO3)2)2"\n\u8f93\u51fa: "K4N2O14S4"\n\u89e3\u91ca: \n\u539f\u5b50\u7684\u6570\u91cf\u662f {'K': 4, 'N': 2, 'O': 14, 'S': 4}\u3002\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    • \u6240\u6709\u539f\u5b50\u7684\u7b2c\u4e00\u4e2a\u5b57\u6bcd\u4e3a\u5927\u5199\uff0c\u5269\u4f59\u5b57\u6bcd\u90fd\u662f\u5c0f\u5199\u3002
    • \n\t
    • formula\u7684\u957f\u5ea6\u5728[1, 1000]\u4e4b\u95f4\u3002
    • \n\t
    • formula\u53ea\u5305\u542b\u5b57\u6bcd\u3001\u6570\u5b57\u548c\u5706\u62ec\u53f7\uff0c\u5e76\u4e14\u9898\u76ee\u4e2d\u7ed9\u5b9a\u7684\u662f\u5408\u6cd5\u7684\u5316\u5b66\u5f0f\u3002
    • \n
    \n", "tags_en": ["Stack", "Recursion", "Hash Table"], "tags_cn": ["\u6808", "\u9012\u5f52", "\u54c8\u5e0c\u8868"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string countOfAtoms(string formula) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String countOfAtoms(String formula) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countOfAtoms(self, formula):\n \"\"\"\n :type formula: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countOfAtoms(self, formula: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * countOfAtoms(char * formula){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string CountOfAtoms(string formula) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} formula\n * @return {string}\n */\nvar countOfAtoms = function(formula) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} formula\n# @return {String}\ndef count_of_atoms(formula)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countOfAtoms(_ formula: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countOfAtoms(formula string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countOfAtoms(formula: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countOfAtoms(formula: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_of_atoms(formula: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $formula\n * @return String\n */\n function countOfAtoms($formula) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countOfAtoms(formula: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-of-atoms formula)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0726](https://leetcode-cn.com/problems/number-of-atoms)", "[\u539f\u5b50\u7684\u6570\u91cf](/solution/0700-0799/0726.Number%20of%20Atoms/README.md)", "`\u6808`,`\u9012\u5f52`,`\u54c8\u5e0c\u8868`", "\u56f0\u96be", ""], "md_table_row_en": ["[0726](https://leetcode.com/problems/number-of-atoms)", "[Number of Atoms](/solution/0700-0799/0726.Number%20of%20Atoms/README_EN.md)", "`Stack`,`Recursion`,`Hash Table`", "Hard", ""]}, {"question_id": "0725", "frontend_question_id": "0725", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/split-linked-list-in-parts", "url_en": "https://leetcode.com/problems/split-linked-list-in-parts", "relative_path_cn": "/solution/0700-0799/0725.Split%20Linked%20List%20in%20Parts/README.md", "relative_path_en": "/solution/0700-0799/0725.Split%20Linked%20List%20in%20Parts/README_EN.md", "title_cn": "\u5206\u9694\u94fe\u8868", "title_en": "Split Linked List in Parts", "question_title_slug": "split-linked-list-in-parts", "content_en": "

    Given a (singly) linked list with head node root, write a function to split the linked list into k consecutive linked list \"parts\".\r\n

    \r\nThe length of each part should be as equal as possible: no two parts should have a size differing by more than 1. This may lead to some parts being null.\r\n

    \r\nThe parts should be in order of occurrence in the input list, and parts occurring earlier should always have a size greater than or equal parts occurring later.\r\n

    \r\nReturn a List of ListNode's representing the linked list parts that are formed.\r\n

    \r\n\r\nExamples\r\n1->2->3->4, k = 5 // 5 equal parts\r\n[ [1], \r\n[2],\r\n[3],\r\n[4],\r\nnull ]\r\n\r\n

    Example 1:
    \r\n

    \r\nInput: \r\nroot = [1, 2, 3], k = 5\r\nOutput: [[1],[2],[3],[],[]]\r\nExplanation:\r\nThe input and each element of the output are ListNodes, not arrays.\r\nFor example, the input root has root.val = 1, root.next.val = 2, \\root.next.next.val = 3, and root.next.next.next = null.\r\nThe first element output[0] has output[0].val = 1, output[0].next = null.\r\nThe last element output[4] is null, but it's string representation as a ListNode is [].\r\n
    \r\n

    \r\n\r\n

    Example 2:
    \r\n

    \r\nInput: \r\nroot = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], k = 3\r\nOutput: [[1, 2, 3, 4], [5, 6, 7], [8, 9, 10]]\r\nExplanation:\r\nThe input has been split into consecutive parts with size difference at most 1, and earlier parts are a larger size than the later parts.\r\n
    \r\n

    \r\n\r\n

    Note:\r\n

  • The length of root will be in the range [0, 1000].
  • \r\n
  • Each value of a node in the input will be an integer in the range [0, 999].
  • \r\n
  • k will be an integer in the range [1, 50].
  • \r\n

    ", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5934\u7ed3\u70b9\u4e3a root \u7684\u94fe\u8868, \u7f16\u5199\u4e00\u4e2a\u51fd\u6570\u4ee5\u5c06\u94fe\u8868\u5206\u9694\u4e3a k \u4e2a\u8fde\u7eed\u7684\u90e8\u5206\u3002

    \n\n

    \u6bcf\u90e8\u5206\u7684\u957f\u5ea6\u5e94\u8be5\u5c3d\u53ef\u80fd\u7684\u76f8\u7b49: \u4efb\u610f\u4e24\u90e8\u5206\u7684\u957f\u5ea6\u5dee\u8ddd\u4e0d\u80fd\u8d85\u8fc7 1\uff0c\u4e5f\u5c31\u662f\u8bf4\u53ef\u80fd\u6709\u4e9b\u90e8\u5206\u4e3a null\u3002

    \n\n

    \u8fd9k\u4e2a\u90e8\u5206\u5e94\u8be5\u6309\u7167\u5728\u94fe\u8868\u4e2d\u51fa\u73b0\u7684\u987a\u5e8f\u8fdb\u884c\u8f93\u51fa\uff0c\u5e76\u4e14\u6392\u5728\u524d\u9762\u7684\u90e8\u5206\u7684\u957f\u5ea6\u5e94\u8be5\u5927\u4e8e\u6216\u7b49\u4e8e\u540e\u9762\u7684\u957f\u5ea6\u3002

    \n\n

    \u8fd4\u56de\u4e00\u4e2a\u7b26\u5408\u4e0a\u8ff0\u89c4\u5219\u7684\u94fe\u8868\u7684\u5217\u8868\u3002

    \n\n

    \u4e3e\u4f8b\uff1a 1->2->3->4, k = 5 // 5 \u7ed3\u679c [ [1], [2], [3], [4], null ]

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165: \nroot = [1, 2, 3], k = 5\n\u8f93\u51fa: [[1],[2],[3],[],[]]\n\u89e3\u91ca:\n\u8f93\u5165\u8f93\u51fa\u5404\u90e8\u5206\u90fd\u5e94\u8be5\u662f\u94fe\u8868\uff0c\u800c\u4e0d\u662f\u6570\u7ec4\u3002\n\u4f8b\u5982, \u8f93\u5165\u7684\u7ed3\u70b9 root \u7684 val= 1, root.next.val = 2, \\root.next.next.val = 3, \u4e14 root.next.next.next = null\u3002\n\u7b2c\u4e00\u4e2a\u8f93\u51fa output[0] \u662f output[0].val = 1, output[0].next = null\u3002\n\u6700\u540e\u4e00\u4e2a\u5143\u7d20 output[4] \u4e3a null, \u5b83\u4ee3\u8868\u4e86\u6700\u540e\u4e00\u4e2a\u90e8\u5206\u4e3a\u7a7a\u94fe\u8868\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165: \nroot = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], k = 3\n\u8f93\u51fa: [[1, 2, 3, 4], [5, 6, 7], [8, 9, 10]]\n\u89e3\u91ca:\n\u8f93\u5165\u88ab\u5206\u6210\u4e86\u51e0\u4e2a\u8fde\u7eed\u7684\u90e8\u5206\uff0c\u5e76\u4e14\u6bcf\u90e8\u5206\u7684\u957f\u5ea6\u76f8\u5dee\u4e0d\u8d85\u8fc71.\u524d\u9762\u90e8\u5206\u7684\u957f\u5ea6\u5927\u4e8e\u7b49\u4e8e\u540e\u9762\u90e8\u5206\u7684\u957f\u5ea6\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a:

    \n\n
      \n\t
    • root \u7684\u957f\u5ea6\u8303\u56f4\uff1a [0, 1000].
    • \n\t
    • \u8f93\u5165\u7684\u6bcf\u4e2a\u8282\u70b9\u7684\u5927\u5c0f\u8303\u56f4\uff1a[0, 999].
    • \n\t
    • k \u7684\u53d6\u503c\u8303\u56f4\uff1a [1, 50].
    • \n
    \n\n

     

    \n", "tags_en": ["Linked List"], "tags_cn": ["\u94fe\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\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 splitListToParts(ListNode* root, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode(int x) { val = x; }\n * }\n */\nclass Solution {\n public ListNode[] splitListToParts(ListNode root, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.next = None\n\nclass Solution(object):\n def splitListToParts(self, root, k):\n \"\"\"\n :type root: ListNode\n :type k: int\n :rtype: List[ListNode]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, x):\n# self.val = x\n# self.next = None\n\nclass Solution:\n def splitListToParts(self, root: ListNode, k: int) -> List[ListNode]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nstruct ListNode** splitListToParts(struct ListNode* root, int k, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int x) { val = x; }\n * }\n */\npublic class Solution {\n public ListNode[] SplitListToParts(ListNode root, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val) {\n * this.val = val;\n * this.next = null;\n * }\n */\n/**\n * @param {ListNode} root\n * @param {number} k\n * @return {ListNode[]}\n */\nvar splitListToParts = function(root, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val)\n# @val = val\n# @next = nil\n# end\n# end\n\n# @param {ListNode} root\n# @param {Integer} k\n# @return {ListNode[]}\ndef split_list_to_parts(root, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.next = nil\n * }\n * }\n */\nclass Solution {\n func splitListToParts(_ root: ListNode?, _ k: Int) -> [ListNode?] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc splitListToParts(root *ListNode, k int) []*ListNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(var _x: Int = 0) {\n * var next: ListNode = null\n * var x: Int = _x\n * }\n */\nobject Solution {\n def splitListToParts(root: ListNode, k: Int): Array[ListNode] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun splitListToParts(root: ListNode?, k: Int): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n// \n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn split_list_to_parts(root: Option>, k: i32) -> Vec>> {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val) { $this->val = $val; }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $root\n * @param Integer $k\n * @return ListNode[]\n */\n function splitListToParts($root, $k) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction splitListToParts(root: ListNode | null, k: number): Array {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (split-list-to-parts root k)\n (-> (or/c list-node? #f) exact-integer? (listof (or/c list-node? #f)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0725](https://leetcode-cn.com/problems/split-linked-list-in-parts)", "[\u5206\u9694\u94fe\u8868](/solution/0700-0799/0725.Split%20Linked%20List%20in%20Parts/README.md)", "`\u94fe\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0725](https://leetcode.com/problems/split-linked-list-in-parts)", "[Split Linked List in Parts](/solution/0700-0799/0725.Split%20Linked%20List%20in%20Parts/README_EN.md)", "`Linked List`", "Medium", ""]}, {"question_id": "0724", "frontend_question_id": "0724", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-pivot-index", "url_en": "https://leetcode.com/problems/find-pivot-index", "relative_path_cn": "/solution/0700-0799/0724.Find%20Pivot%20Index/README.md", "relative_path_en": "/solution/0700-0799/0724.Find%20Pivot%20Index/README_EN.md", "title_cn": "\u5bfb\u627e\u6570\u7ec4\u7684\u4e2d\u5fc3\u4e0b\u6807", "title_en": "Find Pivot Index", "question_title_slug": "find-pivot-index", "content_en": "

    Given an array of integers nums, calculate the pivot index of this array.

    \n\n

    The pivot index is the index where the sum of all the numbers strictly to the left of the index is equal to the sum of all the numbers strictly to the index's right.

    \n\n

    If the index is on the left edge of the array, then the left sum is 0 because there are no elements to the left. This also applies to the right edge of the array.

    \n\n

    Return the leftmost pivot index. If no such index exists, return -1.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,7,3,6,5,6]\nOutput: 3\nExplanation:\nThe pivot index is 3.\nLeft sum = nums[0] + nums[1] + nums[2] = 1 + 7 + 3 = 11\nRight sum = nums[4] + nums[5] = 5 + 6 = 11\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,2,3]\nOutput: -1\nExplanation:\nThere is no index that satisfies the conditions in the problem statement.
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [2,1,-1]\nOutput: 0\nExplanation:\nThe pivot index is 0.\nLeft sum = 0 (no elements to the left of index 0)\nRight sum = nums[1] + nums[2] = 1 + -1 = 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 104
    • \n\t
    • -1000 <= nums[i] <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0nums\uff0c\u8bf7\u7f16\u5199\u4e00\u4e2a\u80fd\u591f\u8fd4\u56de\u6570\u7ec4 \u201c\u4e2d\u5fc3\u4e0b\u6807\u201d \u7684\u65b9\u6cd5\u3002

    \n\n

    \u6570\u7ec4 \u4e2d\u5fc3\u4e0b\u6807 \u662f\u6570\u7ec4\u7684\u4e00\u4e2a\u4e0b\u6807\uff0c\u5176\u5de6\u4fa7\u6240\u6709\u5143\u7d20\u76f8\u52a0\u7684\u548c\u7b49\u4e8e\u53f3\u4fa7\u6240\u6709\u5143\u7d20\u76f8\u52a0\u7684\u548c\u3002

    \n\n

    \u5982\u679c\u6570\u7ec4\u4e0d\u5b58\u5728\u4e2d\u5fc3\u4e0b\u6807\uff0c\u8fd4\u56de -1 \u3002\u5982\u679c\u6570\u7ec4\u6709\u591a\u4e2a\u4e2d\u5fc3\u4e0b\u6807\uff0c\u5e94\u8be5\u8fd4\u56de\u6700\u9760\u8fd1\u5de6\u8fb9\u7684\u90a3\u4e00\u4e2a\u3002

    \n\n

    \u6ce8\u610f\uff1a\u4e2d\u5fc3\u4e0b\u6807\u53ef\u80fd\u51fa\u73b0\u5728\u6570\u7ec4\u7684\u4e24\u7aef\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1, 7, 3, 6, 5, 6]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\n\u4e2d\u5fc3\u4e0b\u6807\u662f 3 \u3002\n\u5de6\u4fa7\u6570\u4e4b\u548c (1 + 7 + 3 = 11)\uff0c\n\u53f3\u4fa7\u6570\u4e4b\u548c (5 + 6 = 11) \uff0c\u4e8c\u8005\u76f8\u7b49\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1, 2, 3]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\n\u6570\u7ec4\u4e2d\u4e0d\u5b58\u5728\u6ee1\u8db3\u6b64\u6761\u4ef6\u7684\u4e2d\u5fc3\u4e0b\u6807\u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [2, 1, -1]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\n\u4e2d\u5fc3\u4e0b\u6807\u662f 0 \u3002\n\u4e0b\u6807 0 \u5de6\u4fa7\u4e0d\u5b58\u5728\u5143\u7d20\uff0c\u89c6\u4f5c\u548c\u4e3a 0 \uff1b\n\u53f3\u4fa7\u6570\u4e4b\u548c\u4e3a 1 + (-1) = 0 \uff0c\u4e8c\u8005\u76f8\u7b49\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • nums \u7684\u957f\u5ea6\u8303\u56f4\u4e3a\u00a0[0, 10000]\u3002
    • \n\t
    • \u4efb\u4f55\u4e00\u4e2a\u00a0nums[i] \u5c06\u4f1a\u662f\u4e00\u4e2a\u8303\u56f4\u5728\u00a0[-1000, 1000]\u7684\u6574\u6570\u3002
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int pivotIndex(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int pivotIndex(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def pivotIndex(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def pivotIndex(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint pivotIndex(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int PivotIndex(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar pivotIndex = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef pivot_index(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func pivotIndex(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func pivotIndex(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def pivotIndex(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun pivotIndex(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn pivot_index(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function pivotIndex($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function pivotIndex(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (pivot-index nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0724](https://leetcode-cn.com/problems/find-pivot-index)", "[\u5bfb\u627e\u6570\u7ec4\u7684\u4e2d\u5fc3\u4e0b\u6807](/solution/0700-0799/0724.Find%20Pivot%20Index/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0724](https://leetcode.com/problems/find-pivot-index)", "[Find Pivot Index](/solution/0700-0799/0724.Find%20Pivot%20Index/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0723", "frontend_question_id": "0723", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/candy-crush", "url_en": "https://leetcode.com/problems/candy-crush", "relative_path_cn": "/solution/0700-0799/0723.Candy%20Crush/README.md", "relative_path_en": "/solution/0700-0799/0723.Candy%20Crush/README_EN.md", "title_cn": "\u7c89\u788e\u7cd6\u679c", "title_en": "Candy Crush", "question_title_slug": "candy-crush", "content_en": "

    This question is about implementing a basic elimination algorithm for Candy Crush.

    \n\n

    Given an m x n integer array board representing the grid of candy where board[i][j] represents the type of candy. A value of board[i][j] == 0 represents that the cell is empty.

    \n\n

    The given board represents the state of the game following the player's move. Now, you need to restore the board to a stable state by crushing candies according to the following rules:

    \n\n
      \n\t
    • If three or more candies of the same type are adjacent vertically or horizontally, crush them all at the same time - these positions become empty.
    • \n\t
    • After crushing all candies simultaneously, if an empty space on the board has candies on top of itself, then these candies will drop until they hit a candy or bottom at the same time. No new candies will drop outside the top boundary.
    • \n\t
    • After the above steps, there may exist more candies that can be crushed. If so, you need to repeat the above steps.
    • \n\t
    • If there does not exist more candies that can be crushed (i.e., the board is stable), then return the current board.
    • \n
    \n\n

    You need to perform the above rules until the board becomes stable, then return the stable board.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: board = [[110,5,112,113,114],[210,211,5,213,214],[310,311,3,313,314],[410,411,412,5,414],[5,1,512,3,3],[610,4,1,613,614],[710,1,2,713,714],[810,1,2,1,1],[1,1,2,2,2],[4,1,4,4,1014]]\nOutput: [[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[110,0,0,0,114],[210,0,0,0,214],[310,0,0,113,314],[410,0,0,213,414],[610,211,112,313,614],[710,311,412,613,714],[810,411,512,713,1014]]\n
    \n\n

    Example 2:

    \n\n
    \nInput: board = [[1,3,5,5,2],[3,4,3,3,1],[3,2,4,5,2],[2,4,4,5,5],[1,4,4,1,1]]\nOutput: [[1,3,0,0,0],[3,4,0,5,2],[3,2,0,3,1],[2,4,0,5,2],[1,4,3,1,1]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == board.length
    • \n\t
    • n == board[i].length
    • \n\t
    • 3 <= m, n <= 50
    • \n\t
    • 1 <= board[i][j] <= 2000
    • \n
    \n", "content_cn": "

    \u8fd9\u4e2a\u95ee\u9898\u662f\u5b9e\u73b0\u4e00\u4e2a\u7b80\u5355\u7684\u6d88\u9664\u7b97\u6cd5\u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u7ef4\u6574\u6570\u6570\u7ec4 board \u4ee3\u8868\u7cd6\u679c\u6240\u5728\u7684\u65b9\u683c\uff0c\u4e0d\u540c\u7684\u6b63\u6574\u6570 board[i][j] \u4ee3\u8868\u4e0d\u540c\u79cd\u7c7b\u7684\u7cd6\u679c\uff0c\u5982\u679c board[i][j] = 0 \u4ee3\u8868 (i, j) \u8fd9\u4e2a\u4f4d\u7f6e\u662f\u7a7a\u7684\u3002\u7ed9\u5b9a\u7684\u65b9\u683c\u662f\u73a9\u5bb6\u79fb\u52a8\u540e\u7684\u6e38\u620f\u72b6\u6001\uff0c\u73b0\u5728\u9700\u8981\u4f60\u6839\u636e\u4ee5\u4e0b\u89c4\u5219\u7c89\u788e\u7cd6\u679c\uff0c\u4f7f\u5f97\u6574\u4e2a\u65b9\u683c\u5904\u4e8e\u7a33\u5b9a\u72b6\u6001\u5e76\u6700\u7ec8\u8f93\u51fa\u3002

    \n\n
      \n\t
    1. \u5982\u679c\u6709\u4e09\u4e2a\u53ca\u4ee5\u4e0a\u6c34\u5e73\u6216\u8005\u5782\u76f4\u76f8\u8fde\u7684\u540c\u79cd\u7cd6\u679c\uff0c\u540c\u4e00\u65f6\u95f4\u5c06\u5b83\u4eec\u7c89\u788e\uff0c\u5373\u5c06\u8fd9\u4e9b\u4f4d\u7f6e\u53d8\u6210\u7a7a\u7684\u3002
    2. \n\t
    3. \u5728\u540c\u65f6\u7c89\u788e\u6389\u8fd9\u4e9b\u7cd6\u679c\u4e4b\u540e\uff0c\u5982\u679c\u6709\u4e00\u4e2a\u7a7a\u7684\u4f4d\u7f6e\u4e0a\u65b9\u8fd8\u6709\u7cd6\u679c\uff0c\u90a3\u4e48\u4e0a\u65b9\u7684\u7cd6\u679c\u5c31\u4f1a\u4e0b\u843d\u76f4\u5230\u78b0\u5230\u4e0b\u65b9\u7684\u7cd6\u679c\u6216\u8005\u5e95\u90e8\uff0c\u8fd9\u4e9b\u7cd6\u679c\u90fd\u662f\u540c\u65f6\u4e0b\u843d\uff0c\u4e5f\u4e0d\u4f1a\u6709\u65b0\u7684\u7cd6\u679c\u4ece\u9876\u90e8\u51fa\u73b0\u5e76\u843d\u4e0b\u6765\u3002
    4. \n\t
    5. \u901a\u8fc7\u524d\u4e24\u6b65\u7684\u64cd\u4f5c\uff0c\u53ef\u80fd\u53c8\u4f1a\u51fa\u73b0\u53ef\u4ee5\u7c89\u788e\u7684\u7cd6\u679c\uff0c\u8bf7\u7ee7\u7eed\u91cd\u590d\u524d\u9762\u7684\u64cd\u4f5c\u3002
    6. \n\t
    7. \u5f53\u4e0d\u5b58\u5728\u53ef\u4ee5\u7c89\u788e\u7684\u7cd6\u679c\uff0c\u4e5f\u5c31\u662f\u72b6\u6001\u7a33\u5b9a\u4e4b\u540e\uff0c\u8bf7\u8f93\u51fa\u6700\u7ec8\u7684\u72b6\u6001\u3002
    8. \n
    \n\n

    \u4f60\u9700\u8981\u6a21\u62df\u4e0a\u8ff0\u89c4\u5219\u5e76\u4f7f\u6574\u4e2a\u65b9\u683c\u8fbe\u5230\u7a33\u5b9a\u72b6\u6001\uff0c\u5e76\u8f93\u51fa\u3002

    \n\n

     

    \n\n

    \u6837\u4f8b :

    \n\n
    \u8f93\u5165:\nboard = \n[[110,5,112,113,114],[210,211,5,213,214],[310,311,3,313,314],[410,411,412,5,414],[5,1,512,3,3],[610,4,1,613,614],[710,1,2,713,714],[810,1,2,1,1],[1,1,2,2,2],[4,1,4,4,1014]]\n\n\u8f93\u51fa:\n[[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[110,0,0,0,114],[210,0,0,0,214],[310,0,0,113,314],[410,0,0,213,414],[610,211,112,313,614],[710,311,412,613,714],[810,411,512,713,1014]]\n\n\u89e3\u91ca: \n\n
    \n\n

     

    \n\n

    \u6ce8\u91ca :

    \n\n
      \n\t
    1. board \u6570\u7ec4\u7684\u884c\u6570\u533a\u95f4\u662f [3, 50]\u3002
    2. \n\t
    3. board[i] \u6570\u7ec4\u7684\u957f\u5ea6\u533a\u95f4\uff08\u5373 board \u6570\u7ec4\u7684\u5217\u6570\u533a\u95f4\uff09\u662f [3, 50]\u3002
    4. \n\t
    5. \u6bcf\u4e2a board[i][j] \u521d\u59cb\u6574\u6570\u8303\u56f4\u662f [1, 2000]\u3002
    6. \n
    \n", "tags_en": ["Array", "Two Pointers"], "tags_cn": ["\u6570\u7ec4", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> candyCrush(vector>& board) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[][] candyCrush(int[][] board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def candyCrush(self, board):\n \"\"\"\n :type board: List[List[int]]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def candyCrush(self, board: List[List[int]]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** candyCrush(int** board, int boardSize, int* boardColSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[][] CandyCrush(int[][] board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} board\n * @return {number[][]}\n */\nvar candyCrush = function(board) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} board\n# @return {Integer[][]}\ndef candy_crush(board)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func candyCrush(_ board: [[Int]]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func candyCrush(board [][]int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def candyCrush(board: Array[Array[Int]]): Array[Array[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun candyCrush(board: Array): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn candy_crush(board: Vec>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $board\n * @return Integer[][]\n */\n function candyCrush($board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function candyCrush(board: number[][]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (candy-crush board)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0723](https://leetcode-cn.com/problems/candy-crush)", "[\u7c89\u788e\u7cd6\u679c](/solution/0700-0799/0723.Candy%20Crush/README.md)", "`\u6570\u7ec4`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0723](https://leetcode.com/problems/candy-crush)", "[Candy Crush](/solution/0700-0799/0723.Candy%20Crush/README_EN.md)", "`Array`,`Two Pointers`", "Medium", "\ud83d\udd12"]}, {"question_id": "0722", "frontend_question_id": "0722", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/remove-comments", "url_en": "https://leetcode.com/problems/remove-comments", "relative_path_cn": "/solution/0700-0799/0722.Remove%20Comments/README.md", "relative_path_en": "/solution/0700-0799/0722.Remove%20Comments/README_EN.md", "title_cn": "\u5220\u9664\u6ce8\u91ca", "title_en": "Remove Comments", "question_title_slug": "remove-comments", "content_en": "

    Given a C++ program, remove comments from it. The program source is an array where source[i] is the i-th line of the source code. This represents the result of splitting the original source code string by the newline character \\n.

    \r\n\r\n

    In C++, there are two types of comments, line comments, and block comments.

    \r\n

    \r\nThe string // denotes a line comment, which represents that it and rest of the characters to the right of it in the same line should be ignored.\r\n

    \r\nThe string /* denotes a block comment, which represents that all characters until the next (non-overlapping) occurrence of */ should be ignored. (Here, occurrences happen in reading order: line by line from left to right.) To be clear, the string /*/ does not yet end the block comment, as the ending would be overlapping the beginning.\r\n

    \r\nThe first effective comment takes precedence over others: if the string // occurs in a block comment, it is ignored. Similarly, if the string /* occurs in a line or block comment, it is also ignored.\r\n

    \r\nIf a certain line of code is empty after removing comments, you must not output that line: each string in the answer list will be non-empty.\r\n

    \r\nThere will be no control characters, single quote, or double quote characters. For example, source = \"string s = \"/* Not a comment. */\";\" will not be a test case. (Also, nothing else such as defines or macros will interfere with the comments.)\r\n

    \r\nIt is guaranteed that every open block comment will eventually be closed, so /* outside of a line or block comment always starts a new comment.\r\n

    \r\nFinally, implicit newline characters can be deleted by block comments. Please see the examples below for details.\r\n

    \r\n\r\n

    After removing the comments from the source code, return the source code in the same format.

    \r\n\r\n

    Example 1:
    \r\n

    \r\nInput: \r\nsource = [\"/*Test program */\", \"int main()\", \"{ \", \"  // variable declaration \", \"int a, b, c;\", \"/* This is a test\", \"   multiline  \", \"   comment for \", \"   testing */\", \"a = b + c;\", \"}\"]\r\n\r\nThe line by line code is visualized as below:\r\n/*Test program */\r\nint main()\r\n{ \r\n  // variable declaration \r\nint a, b, c;\r\n/* This is a test\r\n   multiline  \r\n   comment for \r\n   testing */\r\na = b + c;\r\n}\r\n\r\nOutput: [\"int main()\",\"{ \",\"  \",\"int a, b, c;\",\"a = b + c;\",\"}\"]\r\n\r\nThe line by line code is visualized as below:\r\nint main()\r\n{ \r\n  \r\nint a, b, c;\r\na = b + c;\r\n}\r\n\r\nExplanation: \r\nThe string /* denotes a block comment, including line 1 and lines 6-9. The string // denotes line 4 as comments.\r\n
    \r\n

    \r\n\r\n

    Example 2:
    \r\n

    \r\nInput: \r\nsource = [\"a/*comment\", \"line\", \"more_comment*/b\"]\r\nOutput: [\"ab\"]\r\nExplanation: The original source string is \"a/*comment\\nline\\nmore_comment*/b\", where we have bolded the newline characters.  After deletion, the implicit newline characters are deleted, leaving the string \"ab\", which when delimited by newline characters becomes [\"ab\"].\r\n
    \r\n

    \r\n\r\n

    Note:\r\n

  • The length of source is in the range [1, 100].
  • \r\n
  • The length of source[i] is in the range [0, 80].
  • \r\n
  • Every open block comment is eventually closed.
  • \r\n
  • There are no single-quote, double-quote, or control characters in the source code.
  • \r\n

    ", "content_cn": "

    \u7ed9\u4e00\u4e2a C++ \u7a0b\u5e8f\uff0c\u5220\u9664\u7a0b\u5e8f\u4e2d\u7684\u6ce8\u91ca\u3002\u8fd9\u4e2a\u7a0b\u5e8fsource\u662f\u4e00\u4e2a\u6570\u7ec4\uff0c\u5176\u4e2dsource[i]\u8868\u793a\u7b2ci\u884c\u6e90\u7801\u3002 \u8fd9\u8868\u793a\u6bcf\u884c\u6e90\u7801\u7531\\n\u5206\u9694\u3002

    \n\n

    \u5728 C++ \u4e2d\u6709\u4e24\u79cd\u6ce8\u91ca\u98ce\u683c\uff0c\u884c\u5185\u6ce8\u91ca\u548c\u5757\u6ce8\u91ca\u3002

    \n\n

    \u5b57\u7b26\u4e32// \u8868\u793a\u884c\u6ce8\u91ca\uff0c\u8868\u793a//\u548c\u5176\u53f3\u4fa7\u7684\u5176\u4f59\u5b57\u7b26\u5e94\u8be5\u88ab\u5ffd\u7565\u3002

    \n\n

    \u5b57\u7b26\u4e32/* \u8868\u793a\u4e00\u4e2a\u5757\u6ce8\u91ca\uff0c\u5b83\u8868\u793a\u76f4\u5230*/\u7684\u4e0b\u4e00\u4e2a\uff08\u975e\u91cd\u53e0\uff09\u51fa\u73b0\u7684\u6240\u6709\u5b57\u7b26\u90fd\u5e94\u8be5\u88ab\u5ffd\u7565\u3002\uff08\u9605\u8bfb\u987a\u5e8f\u4e3a\u4ece\u5de6\u5230\u53f3\uff09\u975e\u91cd\u53e0\u662f\u6307\uff0c\u5b57\u7b26\u4e32/*/\u5e76\u6ca1\u6709\u7ed3\u675f\u5757\u6ce8\u91ca\uff0c\u56e0\u4e3a\u6ce8\u91ca\u7684\u7ed3\u5c3e\u4e0e\u5f00\u5934\u76f8\u91cd\u53e0\u3002

    \n\n

    \u7b2c\u4e00\u4e2a\u6709\u6548\u6ce8\u91ca\u4f18\u5148\u4e8e\u5176\u4ed6\u6ce8\u91ca\uff1a\u5982\u679c\u5b57\u7b26\u4e32//\u51fa\u73b0\u5728\u5757\u6ce8\u91ca\u4e2d\u4f1a\u88ab\u5ffd\u7565\u3002 \u540c\u6837\uff0c\u5982\u679c\u5b57\u7b26\u4e32/*\u51fa\u73b0\u5728\u884c\u6216\u5757\u6ce8\u91ca\u4e2d\u4e5f\u4f1a\u88ab\u5ffd\u7565\u3002

    \n\n

    \u5982\u679c\u4e00\u884c\u5728\u5220\u9664\u6ce8\u91ca\u4e4b\u540e\u53d8\u4e3a\u7a7a\u5b57\u7b26\u4e32\uff0c\u90a3\u4e48\u4e0d\u8981\u8f93\u51fa\u8be5\u884c\u3002\u5373\uff0c\u7b54\u6848\u5217\u8868\u4e2d\u7684\u6bcf\u4e2a\u5b57\u7b26\u4e32\u90fd\u662f\u975e\u7a7a\u7684\u3002

    \n\n

    \u6837\u4f8b\u4e2d\u6ca1\u6709\u63a7\u5236\u5b57\u7b26\uff0c\u5355\u5f15\u53f7\u6216\u53cc\u5f15\u53f7\u5b57\u7b26\u3002\u6bd4\u5982\uff0csource = "string s = "/* Not a comment. */";" \u4e0d\u4f1a\u51fa\u73b0\u5728\u6d4b\u8bd5\u6837\u4f8b\u91cc\u3002\uff08\u6b64\u5916\uff0c\u6ca1\u6709\u5176\u4ed6\u5185\u5bb9\uff08\u5982\u5b9a\u4e49\u6216\u5b8f\uff09\u4f1a\u5e72\u6270\u6ce8\u91ca\u3002\uff09

    \n\n

    \u6211\u4eec\u4fdd\u8bc1\u6bcf\u4e00\u4e2a\u5757\u6ce8\u91ca\u6700\u7ec8\u90fd\u4f1a\u88ab\u95ed\u5408\uff0c \u6240\u4ee5\u5728\u884c\u6216\u5757\u6ce8\u91ca\u4e4b\u5916\u7684/*\u603b\u662f\u5f00\u59cb\u65b0\u7684\u6ce8\u91ca\u3002

    \n\n

    \u6700\u540e\uff0c\u9690\u5f0f\u6362\u884c\u7b26\u53ef\u4ee5\u901a\u8fc7\u5757\u6ce8\u91ca\u5220\u9664\u3002 \u6709\u5173\u8be6\u7ec6\u4fe1\u606f\uff0c\u8bf7\u53c2\u9605\u4e0b\u9762\u7684\u793a\u4f8b\u3002

    \n\n

    \u4ece\u6e90\u4ee3\u7801\u4e2d\u5220\u9664\u6ce8\u91ca\u540e\uff0c\u9700\u8981\u4ee5\u76f8\u540c\u7684\u683c\u5f0f\u8fd4\u56de\u6e90\u4ee3\u7801\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: \nsource = ["/*Test program */", "int main()", "{ ", "  // variable declaration ", "int a, b, c;", "/* This is a test", "   multiline  ", "   comment for ", "   testing */", "a = b + c;", "}"]\n\n\u793a\u4f8b\u4ee3\u7801\u53ef\u4ee5\u7f16\u6392\u6210\u8fd9\u6837:\n/*Test program */\nint main()\n{ \n  // variable declaration \nint a, b, c;\n/* This is a test\n   multiline  \n   comment for \n   testing */\na = b + c;\n}\n\n\u8f93\u51fa: ["int main()","{ ","  ","int a, b, c;","a = b + c;","}"]\n\n\u7f16\u6392\u540e:\nint main()\n{ \n  \nint a, b, c;\na = b + c;\n}\n\n\u89e3\u91ca: \n\u7b2c 1 \u884c\u548c\u7b2c 6-9 \u884c\u7684\u5b57\u7b26\u4e32 /* \u8868\u793a\u5757\u6ce8\u91ca\u3002\u7b2c 4 \u884c\u7684\u5b57\u7b26\u4e32 // \u8868\u793a\u884c\u6ce8\u91ca\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: \nsource = ["a/*comment", "line", "more_comment*/b"]\n\u8f93\u51fa: ["ab"]\n\u89e3\u91ca: \u539f\u59cb\u7684 source \u5b57\u7b26\u4e32\u662f "a/*comment\\nline\\nmore_comment*/b", \u5176\u4e2d\u6211\u4eec\u7528\u7c97\u4f53\u663e\u793a\u4e86\u6362\u884c\u7b26\u3002\u5220\u9664\u6ce8\u91ca\u540e\uff0c\u9690\u542b\u7684\u6362\u884c\u7b26\u88ab\u5220\u9664\uff0c\u7559\u4e0b\u5b57\u7b26\u4e32 "ab" \u7528\u6362\u884c\u7b26\u5206\u9694\u6210\u6570\u7ec4\u65f6\u5c31\u662f ["ab"].\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    • source\u7684\u957f\u5ea6\u8303\u56f4\u4e3a[1, 100].
    • \n\t
    • source[i]\u7684\u957f\u5ea6\u8303\u56f4\u4e3a[0, 80].
    • \n\t
    • \u6bcf\u4e2a\u5757\u6ce8\u91ca\u90fd\u4f1a\u88ab\u95ed\u5408\u3002
    • \n\t
    • \u7ed9\u5b9a\u7684\u6e90\u7801\u4e2d\u4e0d\u4f1a\u6709\u5355\u5f15\u53f7\u3001\u53cc\u5f15\u53f7\u6216\u5176\u4ed6\u63a7\u5236\u5b57\u7b26\u3002
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector removeComments(vector& source) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List removeComments(String[] source) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def removeComments(self, source):\n \"\"\"\n :type source: List[str]\n :rtype: List[str]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def removeComments(self, source: List[str]) -> List[str]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** removeComments(char ** source, int sourceSize, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList RemoveComments(string[] source) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} source\n * @return {string[]}\n */\nvar removeComments = function(source) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} source\n# @return {String[]}\ndef remove_comments(source)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func removeComments(_ source: [String]) -> [String] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func removeComments(source []string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def removeComments(source: Array[String]): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun removeComments(source: Array): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn remove_comments(source: Vec) -> Vec {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $source\n * @return String[]\n */\n function removeComments($source) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function removeComments(source: string[]): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (remove-comments source)\n (-> (listof string?) (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0722](https://leetcode-cn.com/problems/remove-comments)", "[\u5220\u9664\u6ce8\u91ca](/solution/0700-0799/0722.Remove%20Comments/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0722](https://leetcode.com/problems/remove-comments)", "[Remove Comments](/solution/0700-0799/0722.Remove%20Comments/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "0721", "frontend_question_id": "0721", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/accounts-merge", "url_en": "https://leetcode.com/problems/accounts-merge", "relative_path_cn": "/solution/0700-0799/0721.Accounts%20Merge/README.md", "relative_path_en": "/solution/0700-0799/0721.Accounts%20Merge/README_EN.md", "title_cn": "\u8d26\u6237\u5408\u5e76", "title_en": "Accounts Merge", "question_title_slug": "accounts-merge", "content_en": "

    Given a list of accounts where each element accounts[i] is a list of strings, where the first element accounts[i][0] is a name, and the rest of the elements are emails representing emails of the account.

    \n\n

    Now, we would like to merge these accounts. Two accounts definitely belong to the same person if there is some common email to both accounts. Note that even if two accounts have the same name, they may belong to different people as people could have the same name. A person can have any number of accounts initially, but all of their accounts definitely have the same name.

    \n\n

    After merging the accounts, return the accounts in the following format: the first element of each account is the name, and the rest of the elements are emails in sorted order. The accounts themselves can be returned in any order.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: accounts = [["John","johnsmith@mail.com","john_newyork@mail.com"],["John","johnsmith@mail.com","john00@mail.com"],["Mary","mary@mail.com"],["John","johnnybravo@mail.com"]]\nOutput: [["John","john00@mail.com","john_newyork@mail.com","johnsmith@mail.com"],["Mary","mary@mail.com"],["John","johnnybravo@mail.com"]]\nExplanation:\nThe first and third John's are the same person as they have the common email "johnsmith@mail.com".\nThe second John and Mary are different people as none of their email addresses are used by other accounts.\nWe could return these lists in any order, for example the answer [['Mary', 'mary@mail.com'], ['John', 'johnnybravo@mail.com'], \n['John', 'john00@mail.com', 'john_newyork@mail.com', 'johnsmith@mail.com']] would still be accepted.\n
    \n\n

    Example 2:

    \n\n
    \nInput: accounts = [["Gabe","Gabe0@m.co","Gabe3@m.co","Gabe1@m.co"],["Kevin","Kevin3@m.co","Kevin5@m.co","Kevin0@m.co"],["Ethan","Ethan5@m.co","Ethan4@m.co","Ethan0@m.co"],["Hanzo","Hanzo3@m.co","Hanzo1@m.co","Hanzo0@m.co"],["Fern","Fern5@m.co","Fern1@m.co","Fern0@m.co"]]\nOutput: [["Ethan","Ethan0@m.co","Ethan4@m.co","Ethan5@m.co"],["Gabe","Gabe0@m.co","Gabe1@m.co","Gabe3@m.co"],["Hanzo","Hanzo0@m.co","Hanzo1@m.co","Hanzo3@m.co"],["Kevin","Kevin0@m.co","Kevin3@m.co","Kevin5@m.co"],["Fern","Fern0@m.co","Fern1@m.co","Fern5@m.co"]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= accounts.length <= 1000
    • \n\t
    • 2 <= accounts[i].length <= 10
    • \n\t
    • 1 <= accounts[i][j] <= 30
    • \n\t
    • accounts[i][0] consists of English letters.
    • \n\t
    • accounts[i][j] (for j > 0) is a valid email.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5217\u8868 accounts\uff0c\u6bcf\u4e2a\u5143\u7d20 accounts[i]\u00a0\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\u5217\u8868\uff0c\u5176\u4e2d\u7b2c\u4e00\u4e2a\u5143\u7d20 accounts[i][0]\u00a0\u662f\u00a0\u540d\u79f0 (name)\uff0c\u5176\u4f59\u5143\u7d20\u662f emails \u8868\u793a\u8be5\u8d26\u6237\u7684\u90ae\u7bb1\u5730\u5740\u3002

    \n\n

    \u73b0\u5728\uff0c\u6211\u4eec\u60f3\u5408\u5e76\u8fd9\u4e9b\u8d26\u6237\u3002\u5982\u679c\u4e24\u4e2a\u8d26\u6237\u90fd\u6709\u4e00\u4e9b\u5171\u540c\u7684\u90ae\u7bb1\u5730\u5740\uff0c\u5219\u4e24\u4e2a\u8d26\u6237\u5fc5\u5b9a\u5c5e\u4e8e\u540c\u4e00\u4e2a\u4eba\u3002\u8bf7\u6ce8\u610f\uff0c\u5373\u4f7f\u4e24\u4e2a\u8d26\u6237\u5177\u6709\u76f8\u540c\u7684\u540d\u79f0\uff0c\u5b83\u4eec\u4e5f\u53ef\u80fd\u5c5e\u4e8e\u4e0d\u540c\u7684\u4eba\uff0c\u56e0\u4e3a\u4eba\u4eec\u53ef\u80fd\u5177\u6709\u76f8\u540c\u7684\u540d\u79f0\u3002\u4e00\u4e2a\u4eba\u6700\u521d\u53ef\u4ee5\u62e5\u6709\u4efb\u610f\u6570\u91cf\u7684\u8d26\u6237\uff0c\u4f46\u5176\u6240\u6709\u8d26\u6237\u90fd\u5177\u6709\u76f8\u540c\u7684\u540d\u79f0\u3002

    \n\n

    \u5408\u5e76\u8d26\u6237\u540e\uff0c\u6309\u4ee5\u4e0b\u683c\u5f0f\u8fd4\u56de\u8d26\u6237\uff1a\u6bcf\u4e2a\u8d26\u6237\u7684\u7b2c\u4e00\u4e2a\u5143\u7d20\u662f\u540d\u79f0\uff0c\u5176\u4f59\u5143\u7d20\u662f\u6309\u5b57\u7b26 ASCII \u987a\u5e8f\u6392\u5217\u7684\u90ae\u7bb1\u5730\u5740\u3002\u8d26\u6237\u672c\u8eab\u53ef\u4ee5\u4ee5\u4efb\u610f\u987a\u5e8f\u8fd4\u56de\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\naccounts = [[\"John\", \"johnsmith@mail.com\", \"john00@mail.com\"], [\"John\", \"johnnybravo@mail.com\"], [\"John\", \"johnsmith@mail.com\", \"john_newyork@mail.com\"], [\"Mary\", \"mary@mail.com\"]]\n\u8f93\u51fa\uff1a\n[[\"John\", 'john00@mail.com', 'john_newyork@mail.com', 'johnsmith@mail.com'],  [\"John\", \"johnnybravo@mail.com\"], [\"Mary\", \"mary@mail.com\"]]\n\u89e3\u91ca\uff1a\n\u7b2c\u4e00\u4e2a\u548c\u7b2c\u4e09\u4e2a John \u662f\u540c\u4e00\u4e2a\u4eba\uff0c\u56e0\u4e3a\u4ed6\u4eec\u6709\u5171\u540c\u7684\u90ae\u7bb1\u5730\u5740 \"johnsmith@mail.com\"\u3002 \n\u7b2c\u4e8c\u4e2a John \u548c Mary \u662f\u4e0d\u540c\u7684\u4eba\uff0c\u56e0\u4e3a\u4ed6\u4eec\u7684\u90ae\u7bb1\u5730\u5740\u6ca1\u6709\u88ab\u5176\u4ed6\u5e10\u6237\u4f7f\u7528\u3002\n\u53ef\u4ee5\u4ee5\u4efb\u4f55\u987a\u5e8f\u8fd4\u56de\u8fd9\u4e9b\u5217\u8868\uff0c\u4f8b\u5982\u7b54\u6848 [['Mary'\uff0c'mary@mail.com']\uff0c['John'\uff0c'johnnybravo@mail.com']\uff0c\n['John'\uff0c'john00@mail.com'\uff0c'john_newyork@mail.com'\uff0c'johnsmith@mail.com']] \u4e5f\u662f\u6b63\u786e\u7684\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • accounts\u7684\u957f\u5ea6\u5c06\u5728[1\uff0c1000]\u7684\u8303\u56f4\u5185\u3002
    • \n\t
    • accounts[i]\u7684\u957f\u5ea6\u5c06\u5728[1\uff0c10]\u7684\u8303\u56f4\u5185\u3002
    • \n\t
    • accounts[i][j]\u7684\u957f\u5ea6\u5c06\u5728[1\uff0c30]\u7684\u8303\u56f4\u5185\u3002
    • \n
    \n", "tags_en": ["Depth-first Search", "Union Find"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e76\u67e5\u96c6"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> accountsMerge(vector>& accounts) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> accountsMerge(List> accounts) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def accountsMerge(self, accounts):\n \"\"\"\n :type accounts: List[List[str]]\n :rtype: List[List[str]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def accountsMerge(self, accounts: List[List[str]]) -> List[List[str]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nchar *** accountsMerge(char *** accounts, int accountsSize, int* accountsColSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> AccountsMerge(IList> accounts) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[][]} accounts\n * @return {string[][]}\n */\nvar accountsMerge = function(accounts) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[][]} accounts\n# @return {String[][]}\ndef accounts_merge(accounts)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func accountsMerge(_ accounts: [[String]]) -> [[String]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func accountsMerge(accounts [][]string) [][]string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def accountsMerge(accounts: List[List[String]]): List[List[String]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun accountsMerge(accounts: List>): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn accounts_merge(accounts: Vec>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $accounts\n * @return String[][]\n */\n function accountsMerge($accounts) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function accountsMerge(accounts: string[][]): string[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (accounts-merge accounts)\n (-> (listof (listof string?)) (listof (listof string?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0721](https://leetcode-cn.com/problems/accounts-merge)", "[\u8d26\u6237\u5408\u5e76](/solution/0700-0799/0721.Accounts%20Merge/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e76\u67e5\u96c6`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0721](https://leetcode.com/problems/accounts-merge)", "[Accounts Merge](/solution/0700-0799/0721.Accounts%20Merge/README_EN.md)", "`Depth-first Search`,`Union Find`", "Medium", ""]}, {"question_id": "0720", "frontend_question_id": "0720", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-word-in-dictionary", "url_en": "https://leetcode.com/problems/longest-word-in-dictionary", "relative_path_cn": "/solution/0700-0799/0720.Longest%20Word%20in%20Dictionary/README.md", "relative_path_en": "/solution/0700-0799/0720.Longest%20Word%20in%20Dictionary/README_EN.md", "title_cn": "\u8bcd\u5178\u4e2d\u6700\u957f\u7684\u5355\u8bcd", "title_en": "Longest Word in Dictionary", "question_title_slug": "longest-word-in-dictionary", "content_en": "

    Given an array of strings words representing an English Dictionary, return the longest word in words that can be built one character at a time by other words in words.

    \n\n

    If there is more than one possible answer, return the longest word with the smallest lexicographical order. If there is no answer, return the empty string.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: words = ["w","wo","wor","worl","world"]\nOutput: "world"\nExplanation: The word "world" can be built one character at a time by "w", "wo", "wor", and "worl".\n
    \n\n

    Example 2:

    \n\n
    \nInput: words = ["a","banana","app","appl","ap","apply","apple"]\nOutput: "apple"\nExplanation: Both "apply" and "apple" can be built from other words in the dictionary. However, "apple" is lexicographically smaller than "apply".\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= words.length <= 1000
    • \n\t
    • 1 <= words[i].length <= 30
    • \n\t
    • words[i] consists of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u51fa\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4words\u7ec4\u6210\u7684\u4e00\u672c\u82f1\u8bed\u8bcd\u5178\u3002\u4ece\u4e2d\u627e\u51fa\u6700\u957f\u7684\u4e00\u4e2a\u5355\u8bcd\uff0c\u8be5\u5355\u8bcd\u662f\u7531words\u8bcd\u5178\u4e2d\u5176\u4ed6\u5355\u8bcd\u9010\u6b65\u6dfb\u52a0\u4e00\u4e2a\u5b57\u6bcd\u7ec4\u6210\u3002\u82e5\u5176\u4e2d\u6709\u591a\u4e2a\u53ef\u884c\u7684\u7b54\u6848\uff0c\u5219\u8fd4\u56de\u7b54\u6848\u4e2d\u5b57\u5178\u5e8f\u6700\u5c0f\u7684\u5355\u8bcd\u3002

    \n\n

    \u82e5\u65e0\u7b54\u6848\uff0c\u5219\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a\nwords = ["w","wo","wor","worl", "world"]\n\u8f93\u51fa\uff1a"world"\n\u89e3\u91ca\uff1a \n\u5355\u8bcd"world"\u53ef\u7531"w", "wo", "wor", \u548c "worl"\u6dfb\u52a0\u4e00\u4e2a\u5b57\u6bcd\u7ec4\u6210\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a\nwords = ["a", "banana", "app", "appl", "ap", "apply", "apple"]\n\u8f93\u51fa\uff1a"apple"\n\u89e3\u91ca\uff1a\n"apply"\u548c"apple"\u90fd\u80fd\u7531\u8bcd\u5178\u4e2d\u7684\u5355\u8bcd\u7ec4\u6210\u3002\u4f46\u662f"apple"\u7684\u5b57\u5178\u5e8f\u5c0f\u4e8e"apply"\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6240\u6709\u8f93\u5165\u7684\u5b57\u7b26\u4e32\u90fd\u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd\u3002
    • \n\t
    • words\u6570\u7ec4\u957f\u5ea6\u8303\u56f4\u4e3a[1,1000]\u3002
    • \n\t
    • words[i]\u7684\u957f\u5ea6\u8303\u56f4\u4e3a[1,30]\u3002
    • \n
    \n", "tags_en": ["Trie", "Hash Table"], "tags_cn": ["\u5b57\u5178\u6811", "\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string longestWord(vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String longestWord(String[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestWord(self, words):\n \"\"\"\n :type words: List[str]\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestWord(self, words: List[str]) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * longestWord(char ** words, int wordsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string LongestWord(string[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @return {string}\n */\nvar longestWord = function(words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @return {String}\ndef longest_word(words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestWord(_ words: [String]) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestWord(words []string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestWord(words: Array[String]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestWord(words: Array): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_word(words: Vec) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @return String\n */\n function longestWord($words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestWord(words: string[]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-word words)\n (-> (listof string?) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0720](https://leetcode-cn.com/problems/longest-word-in-dictionary)", "[\u8bcd\u5178\u4e2d\u6700\u957f\u7684\u5355\u8bcd](/solution/0700-0799/0720.Longest%20Word%20in%20Dictionary/README.md)", "`\u5b57\u5178\u6811`,`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0720](https://leetcode.com/problems/longest-word-in-dictionary)", "[Longest Word in Dictionary](/solution/0700-0799/0720.Longest%20Word%20in%20Dictionary/README_EN.md)", "`Trie`,`Hash Table`", "Easy", ""]}, {"question_id": "0719", "frontend_question_id": "0719", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-k-th-smallest-pair-distance", "url_en": "https://leetcode.com/problems/find-k-th-smallest-pair-distance", "relative_path_cn": "/solution/0700-0799/0719.Find%20K-th%20Smallest%20Pair%20Distance/README.md", "relative_path_en": "/solution/0700-0799/0719.Find%20K-th%20Smallest%20Pair%20Distance/README_EN.md", "title_cn": "\u627e\u51fa\u7b2c k \u5c0f\u7684\u8ddd\u79bb\u5bf9", "title_en": "Find K-th Smallest Pair Distance", "question_title_slug": "find-k-th-smallest-pair-distance", "content_en": "

    The distance of a pair of integers a and b is defined as the absolute difference between a and b.

    \n\n

    Given an integer array nums and an integer k, return the kth smallest distance among all the pairs nums[i] and nums[j] where 0 <= i < j < nums.length.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,3,1], k = 1\nOutput: 0\nExplanation: Here are all the pairs:\n(1,3) -> 2\n(1,1) -> 0\n(3,1) -> 2\nThen the 1st smallest distance pair is (1,1), and its distance is 0.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,1,1], k = 2\nOutput: 0\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [1,6,1], k = 3\nOutput: 5\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 2 <= n <= 104
    • \n\t
    • 0 <= nums[i] <= 106
    • \n\t
    • 1 <= k <= n * (n - 1) / 2
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\uff0c\u8fd4\u56de\u6240\u6709\u6570\u5bf9\u4e4b\u95f4\u7684\u7b2c k \u4e2a\u6700\u5c0f\u8ddd\u79bb\u3002\u4e00\u5bf9 (A, B) \u7684\u8ddd\u79bb\u88ab\u5b9a\u4e49\u4e3a A \u548c B \u4e4b\u95f4\u7684\u7edd\u5bf9\u5dee\u503c\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165\uff1a\nnums = [1,3,1]\nk = 1\n\u8f93\u51fa\uff1a0 \n\u89e3\u91ca\uff1a\n\u6240\u6709\u6570\u5bf9\u5982\u4e0b\uff1a\n(1,3) -> 2\n(1,1) -> 0\n(3,1) -> 2\n\u56e0\u6b64\u7b2c 1 \u4e2a\u6700\u5c0f\u8ddd\u79bb\u7684\u6570\u5bf9\u662f (1,1)\uff0c\u5b83\u4eec\u4e4b\u95f4\u7684\u8ddd\u79bb\u4e3a 0\u3002\n
    \n\n

    \u63d0\u793a:

    \n\n
      \n\t
    1. 2 <= len(nums) <= 10000.
    2. \n\t
    3. 0 <= nums[i] < 1000000.
    4. \n\t
    5. 1 <= k <= len(nums) * (len(nums) - 1) / 2.
    6. \n
    \n", "tags_en": ["Heap", "Array", "Binary Search"], "tags_cn": ["\u5806", "\u6570\u7ec4", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int smallestDistancePair(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int smallestDistancePair(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def smallestDistancePair(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def smallestDistancePair(self, nums: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint smallestDistancePair(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SmallestDistancePair(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar smallestDistancePair = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef smallest_distance_pair(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func smallestDistancePair(_ nums: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func smallestDistancePair(nums []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def smallestDistancePair(nums: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun smallestDistancePair(nums: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn smallest_distance_pair(nums: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer\n */\n function smallestDistancePair($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function smallestDistancePair(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (smallest-distance-pair nums k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0719](https://leetcode-cn.com/problems/find-k-th-smallest-pair-distance)", "[\u627e\u51fa\u7b2c k \u5c0f\u7684\u8ddd\u79bb\u5bf9](/solution/0700-0799/0719.Find%20K-th%20Smallest%20Pair%20Distance/README.md)", "`\u5806`,`\u6570\u7ec4`,`\u4e8c\u5206\u67e5\u627e`", "\u56f0\u96be", ""], "md_table_row_en": ["[0719](https://leetcode.com/problems/find-k-th-smallest-pair-distance)", "[Find K-th Smallest Pair Distance](/solution/0700-0799/0719.Find%20K-th%20Smallest%20Pair%20Distance/README_EN.md)", "`Heap`,`Array`,`Binary Search`", "Hard", ""]}, {"question_id": "0718", "frontend_question_id": "0718", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-length-of-repeated-subarray", "url_en": "https://leetcode.com/problems/maximum-length-of-repeated-subarray", "relative_path_cn": "/solution/0700-0799/0718.Maximum%20Length%20of%20Repeated%20Subarray/README.md", "relative_path_en": "/solution/0700-0799/0718.Maximum%20Length%20of%20Repeated%20Subarray/README_EN.md", "title_cn": "\u6700\u957f\u91cd\u590d\u5b50\u6570\u7ec4", "title_en": "Maximum Length of Repeated Subarray", "question_title_slug": "maximum-length-of-repeated-subarray", "content_en": "

    Given two integer arrays nums1 and nums2, return the maximum length of a subarray that appears in both arrays.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums1 = [1,2,3,2,1], nums2 = [3,2,1,4,7]\nOutput: 3\nExplanation: The repeated subarray with maximum length is [3,2,1].\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums1 = [0,0,0,0,0], nums2 = [0,0,0,0,0]\nOutput: 5\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums1.length, nums2.length <= 1000
    • \n\t
    • 0 <= nums1[i], nums2[i] <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u4e24\u4e2a\u6574\u6570\u6570\u7ec4 A \u548c B \uff0c\u8fd4\u56de\u4e24\u4e2a\u6570\u7ec4\u4e2d\u516c\u5171\u7684\u3001\u957f\u5ea6\u6700\u957f\u7684\u5b50\u6570\u7ec4\u7684\u957f\u5ea6\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1a\nA: [1,2,3,2,1]\nB: [3,2,1,4,7]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\n\u957f\u5ea6\u6700\u957f\u7684\u516c\u5171\u5b50\u6570\u7ec4\u662f [3, 2, 1] \u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= len(A), len(B) <= 1000
    • \n\t
    • 0 <= A[i], B[i] < 100
    • \n
    \n", "tags_en": ["Array", "Hash Table", "Binary Search", "Dynamic Programming"], "tags_cn": ["\u6570\u7ec4", "\u54c8\u5e0c\u8868", "\u4e8c\u5206\u67e5\u627e", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findLength(vector& nums1, vector& nums2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findLength(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findLength(self, nums1, nums2):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findLength(self, nums1: List[int], nums2: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findLength(int* nums1, int nums1Size, int* nums2, int nums2Size){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindLength(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums1\n * @param {number[]} nums2\n * @return {number}\n */\nvar findLength = function(nums1, nums2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums1\n# @param {Integer[]} nums2\n# @return {Integer}\ndef find_length(nums1, nums2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findLength(_ nums1: [Int], _ nums2: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findLength(nums1 []int, nums2 []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findLength(nums1: Array[Int], nums2: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findLength(nums1: IntArray, nums2: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_length(nums1: Vec, nums2: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums1\n * @param Integer[] $nums2\n * @return Integer\n */\n function findLength($nums1, $nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findLength(nums1: number[], nums2: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-length nums1 nums2)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0718](https://leetcode-cn.com/problems/maximum-length-of-repeated-subarray)", "[\u6700\u957f\u91cd\u590d\u5b50\u6570\u7ec4](/solution/0700-0799/0718.Maximum%20Length%20of%20Repeated%20Subarray/README.md)", "`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`,`\u4e8c\u5206\u67e5\u627e`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0718](https://leetcode.com/problems/maximum-length-of-repeated-subarray)", "[Maximum Length of Repeated Subarray](/solution/0700-0799/0718.Maximum%20Length%20of%20Repeated%20Subarray/README_EN.md)", "`Array`,`Hash Table`,`Binary Search`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0717", "frontend_question_id": "0717", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/1-bit-and-2-bit-characters", "url_en": "https://leetcode.com/problems/1-bit-and-2-bit-characters", "relative_path_cn": "/solution/0700-0799/0717.1-bit%20and%202-bit%20Characters/README.md", "relative_path_en": "/solution/0700-0799/0717.1-bit%20and%202-bit%20Characters/README_EN.md", "title_cn": "1\u6bd4\u7279\u4e0e2\u6bd4\u7279\u5b57\u7b26", "title_en": "1-bit and 2-bit Characters", "question_title_slug": "1-bit-and-2-bit-characters", "content_en": "

    We have two special characters:

    \n\n
      \n\t
    • The first character can be represented by one bit 0.
    • \n\t
    • The second character can be represented by two bits (10 or 11).
    • \n
    \n\n

    Given a binary array bits that ends with 0, return true if the last character must be a one-bit character.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: bits = [1,0,0]\nOutput: true\nExplanation: The only way to decode it is two-bit character and one-bit character.\nSo the last character is one-bit character.\n
    \n\n

    Example 2:

    \n\n
    \nInput: bits = [1,1,1,0]\nOutput: false\nExplanation: The only way to decode it is two-bit character and two-bit character.\nSo the last character is not one-bit character.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= bits.length <= 1000
    • \n\t
    • bits[i] is either 0 or 1.
    • \n
    \n", "content_cn": "

    \u6709\u4e24\u79cd\u7279\u6b8a\u5b57\u7b26\u3002\u7b2c\u4e00\u79cd\u5b57\u7b26\u53ef\u4ee5\u7528\u4e00\u6bd4\u72790\u6765\u8868\u793a\u3002\u7b2c\u4e8c\u79cd\u5b57\u7b26\u53ef\u4ee5\u7528\u4e24\u6bd4\u7279(10 \u6216 11)\u6765\u8868\u793a\u3002

    \n\n

    \u73b0\u7ed9\u4e00\u4e2a\u7531\u82e5\u5e72\u6bd4\u7279\u7ec4\u6210\u7684\u5b57\u7b26\u4e32\u3002\u95ee\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\u662f\u5426\u5fc5\u5b9a\u4e3a\u4e00\u4e2a\u4e00\u6bd4\u7279\u5b57\u7b26\u3002\u7ed9\u5b9a\u7684\u5b57\u7b26\u4e32\u603b\u662f\u75310\u7ed3\u675f\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: \nbits = [1, 0, 0]\n\u8f93\u51fa: True\n\u89e3\u91ca: \n\u552f\u4e00\u7684\u7f16\u7801\u65b9\u5f0f\u662f\u4e00\u4e2a\u4e24\u6bd4\u7279\u5b57\u7b26\u548c\u4e00\u4e2a\u4e00\u6bd4\u7279\u5b57\u7b26\u3002\u6240\u4ee5\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\u662f\u4e00\u6bd4\u7279\u5b57\u7b26\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: \nbits = [1, 1, 1, 0]\n\u8f93\u51fa: False\n\u89e3\u91ca: \n\u552f\u4e00\u7684\u7f16\u7801\u65b9\u5f0f\u662f\u4e24\u6bd4\u7279\u5b57\u7b26\u548c\u4e24\u6bd4\u7279\u5b57\u7b26\u3002\u6240\u4ee5\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\u4e0d\u662f\u4e00\u6bd4\u7279\u5b57\u7b26\u3002\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    • 1 <= len(bits) <= 1000.
    • \n\t
    • bits[i] \u603b\u662f0 \u6216 1.
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isOneBitCharacter(vector& bits) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isOneBitCharacter(int[] bits) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isOneBitCharacter(self, bits):\n \"\"\"\n :type bits: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isOneBitCharacter(self, bits: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isOneBitCharacter(int* bits, int bitsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsOneBitCharacter(int[] bits) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} bits\n * @return {boolean}\n */\nvar isOneBitCharacter = function(bits) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} bits\n# @return {Boolean}\ndef is_one_bit_character(bits)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isOneBitCharacter(_ bits: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isOneBitCharacter(bits []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isOneBitCharacter(bits: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isOneBitCharacter(bits: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_one_bit_character(bits: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $bits\n * @return Boolean\n */\n function isOneBitCharacter($bits) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isOneBitCharacter(bits: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-one-bit-character bits)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0717](https://leetcode-cn.com/problems/1-bit-and-2-bit-characters)", "[1\u6bd4\u7279\u4e0e2\u6bd4\u7279\u5b57\u7b26](/solution/0700-0799/0717.1-bit%20and%202-bit%20Characters/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0717](https://leetcode.com/problems/1-bit-and-2-bit-characters)", "[1-bit and 2-bit Characters](/solution/0700-0799/0717.1-bit%20and%202-bit%20Characters/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0716", "frontend_question_id": "0716", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/max-stack", "url_en": "https://leetcode.com/problems/max-stack", "relative_path_cn": "/solution/0700-0799/0716.Max%20Stack/README.md", "relative_path_en": "/solution/0700-0799/0716.Max%20Stack/README_EN.md", "title_cn": "\u6700\u5927\u6808", "title_en": "Max Stack", "question_title_slug": "max-stack", "content_en": "

    Design a max stack data structure that supports the stack operations and supports finding the stack's maximum element.

    \n\n

    Implement the MaxStack class:

    \n\n
      \n\t
    • MaxStack() Initializes the stack object.
    • \n\t
    • void push(int x) Pushes element x onto the stack.
    • \n\t
    • int pop() Removes the element on top of the stack and returns it.
    • \n\t
    • int top() Gets the element on the top of the stack without removing it.
    • \n\t
    • int peekMax() Retrieves the maximum element in the stack without removing it.
    • \n\t
    • int popMax() Retrieves the maximum element in the stack and removes it. If there is more than one maximum element, only remove the top-most one.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["MaxStack", "push", "push", "push", "top", "popMax", "top", "peekMax", "pop", "top"]\n[[], [5], [1], [5], [], [], [], [], [], []]\nOutput\n[null, null, null, null, 5, 5, 1, 5, 1, 5]\n\nExplanation\nMaxStack stk = new MaxStack();\nstk.push(5);   // [5] the top of the stack and the maximum number is 5.\nstk.push(1);   // [5, 1] the top of the stack is 1, but the maximum is 5.\nstk.push(5);   // [5, 1, 5] the top of the stack is 5, which is also the maximum, because it is the top most one.\nstk.top();     // return 5, [5, 1, 5] the stack did not change.\nstk.popMax();  // return 5, [5, 1] the stack is changed now, and the top is different from the max.\nstk.top();     // return 1, [5, 1] the stack did not change.\nstk.peekMax(); // return 5, [5, 1] the stack did not change.\nstk.pop();     // return 1, [5] the top of the stack and the max element is now 5.\nstk.top();     // return 5, [5] the stack did not change.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • -107 <= x <= 107
    • \n\t
    • At most 104 calls will be made to push, pop, top, peekMax, and popMax.
    • \n\t
    • There will be at least one element in the stack when pop, top, peekMax, or popMax is called.
    • \n
    \n\n

     

    \nFollow up: Could you come up with a solution that supports O(1) for each top call and O(logn) for each other call? ", "content_cn": "

    \u8bbe\u8ba1\u4e00\u4e2a\u6700\u5927\u6808\u6570\u636e\u7ed3\u6784\uff0c\u65e2\u652f\u6301\u6808\u64cd\u4f5c\uff0c\u53c8\u652f\u6301\u67e5\u627e\u6808\u4e2d\u6700\u5927\u5143\u7d20\u3002

    \n\n

    \u5b9e\u73b0\u00a0MaxStack\u00a0\u7c7b\uff1a

    \n\n
      \n\t
    • MaxStack()\u00a0\u521d\u59cb\u5316\u6808\u5bf9\u8c61
    • \n\t
    • void push(int x)\u00a0\u5c06\u5143\u7d20 x \u538b\u5165\u6808\u4e2d\u3002
    • \n\t
    • int pop()\u00a0\u79fb\u9664\u6808\u9876\u5143\u7d20\u5e76\u8fd4\u56de\u8fd9\u4e2a\u5143\u7d20\u3002
    • \n\t
    • int top()\u00a0\u8fd4\u56de\u6808\u9876\u5143\u7d20\uff0c\u65e0\u9700\u79fb\u9664\u3002
    • \n\t
    • int peekMax()\u00a0\u68c0\u7d22\u5e76\u8fd4\u56de\u6808\u4e2d\u6700\u5927\u5143\u7d20\uff0c\u65e0\u9700\u79fb\u9664\u3002
    • \n\t
    • int popMax()\u00a0\u68c0\u7d22\u5e76\u8fd4\u56de\u6808\u4e2d\u6700\u5927\u5143\u7d20\uff0c\u5e76\u5c06\u5176\u79fb\u9664\u3002\u5982\u679c\u6709\u591a\u4e2a\u6700\u5927\u5143\u7d20\uff0c\u53ea\u8981\u79fb\u9664 \u6700\u9760\u8fd1\u6808\u9876 \u7684\u90a3\u4e2a\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\n[\"MaxStack\", \"push\", \"push\", \"push\", \"top\", \"popMax\", \"top\", \"peekMax\", \"pop\", \"top\"]\n[[], [5], [1], [5], [], [], [], [], [], []]\n\u8f93\u51fa\n[null, null, null, null, 5, 5, 1, 5, 1, 5]\n\n\u89e3\u91ca\nMaxStack stk = new MaxStack();\nstk.push(5);   // [5] - 5 \u65e2\u662f\u6808\u9876\u5143\u7d20\uff0c\u4e5f\u662f\u6700\u5927\u5143\u7d20\nstk.push(1);   // [5, 1] - \u6808\u9876\u5143\u7d20\u662f 1\uff0c\u6700\u5927\u5143\u7d20\u662f 5\nstk.push(5);   // [5, 1, 5] - 5 \u65e2\u662f\u6808\u9876\u5143\u7d20\uff0c\u4e5f\u662f\u6700\u5927\u5143\u7d20\nstk.top();     // \u8fd4\u56de 5\uff0c[5, 1, 5] - \u6808\u6ca1\u6709\u6539\u53d8\nstk.popMax();  // \u8fd4\u56de 5\uff0c[5, 1] - \u6808\u53d1\u751f\u6539\u53d8\uff0c\u6808\u9876\u5143\u7d20\u4e0d\u518d\u662f\u6700\u5927\u5143\u7d20\nstk.top();     // \u8fd4\u56de 1\uff0c[5, 1] - \u6808\u6ca1\u6709\u6539\u53d8\nstk.peekMax(); // \u8fd4\u56de 5\uff0c[5, 1] - \u6808\u6ca1\u6709\u6539\u53d8\nstk.pop();     // \u8fd4\u56de 1\uff0c[5] - \u6b64\u64cd\u4f5c\u540e\uff0c5 \u65e2\u662f\u6808\u9876\u5143\u7d20\uff0c\u4e5f\u662f\u6700\u5927\u5143\u7d20\nstk.top();     // \u8fd4\u56de 5\uff0c[5] - \u6808\u6ca1\u6709\u6539\u53d8\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • -107\u00a0<= x <= 107
    • \n\t
    • \u6700\u591a\u8c03\u7528\u00a0104\u00a0\u6b21\u00a0push\u3001pop\u3001top\u3001peekMax\u00a0\u548c\u00a0popMax
    • \n\t
    • \u8c03\u7528\u00a0pop\u3001top\u3001peekMax\u00a0\u6216\u00a0popMax\u00a0\u65f6\uff0c\u6808\u4e2d \u81f3\u5c11\u5b58\u5728\u4e00\u4e2a\u5143\u7d20
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u00a0

    \n\n
      \n\t
    • \u8bd5\u7740\u8bbe\u8ba1\u89e3\u51b3\u65b9\u6848\uff1a\u8c03\u7528 top \u65b9\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a\u00a0O(1)\u00a0\uff0c\u8c03\u7528\u5176\u4ed6\u65b9\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a\u00a0O(logn)\u00a0\u3002\u00a0
    • \n
    \n", "tags_en": ["Design"], "tags_cn": ["\u8bbe\u8ba1"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class MaxStack {\npublic:\n /** initialize your data structure here. */\n MaxStack() {\n\n }\n \n void push(int x) {\n\n }\n \n int pop() {\n\n }\n \n int top() {\n\n }\n \n int peekMax() {\n\n }\n \n int popMax() {\n\n }\n};\n\n/**\n * Your MaxStack object will be instantiated and called as such:\n * MaxStack* obj = new MaxStack();\n * obj->push(x);\n * int param_2 = obj->pop();\n * int param_3 = obj->top();\n * int param_4 = obj->peekMax();\n * int param_5 = obj->popMax();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class MaxStack {\n\n /** initialize your data structure here. */\n public MaxStack() {\n\n }\n \n public void push(int x) {\n\n }\n \n public int pop() {\n\n }\n \n public int top() {\n\n }\n \n public int peekMax() {\n\n }\n \n public int popMax() {\n\n }\n}\n\n/**\n * Your MaxStack object will be instantiated and called as such:\n * MaxStack obj = new MaxStack();\n * obj.push(x);\n * int param_2 = obj.pop();\n * int param_3 = obj.top();\n * int param_4 = obj.peekMax();\n * int param_5 = obj.popMax();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class MaxStack(object):\n\n def __init__(self):\n \"\"\"\n initialize your data structure here.\n \"\"\"\n\n\n def push(self, x):\n \"\"\"\n :type x: int\n :rtype: None\n \"\"\"\n\n\n def pop(self):\n \"\"\"\n :rtype: int\n \"\"\"\n\n\n def top(self):\n \"\"\"\n :rtype: int\n \"\"\"\n\n\n def peekMax(self):\n \"\"\"\n :rtype: int\n \"\"\"\n\n\n def popMax(self):\n \"\"\"\n :rtype: int\n \"\"\"\n\n\n\n# Your MaxStack object will be instantiated and called as such:\n# obj = MaxStack()\n# obj.push(x)\n# param_2 = obj.pop()\n# param_3 = obj.top()\n# param_4 = obj.peekMax()\n# param_5 = obj.popMax()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class MaxStack:\n\n def __init__(self):\n \"\"\"\n initialize your data structure here.\n \"\"\"\n\n\n def push(self, x: int) -> None:\n\n\n def pop(self) -> int:\n\n\n def top(self) -> int:\n\n\n def peekMax(self) -> int:\n\n\n def popMax(self) -> int:\n\n\n\n# Your MaxStack object will be instantiated and called as such:\n# obj = MaxStack()\n# obj.push(x)\n# param_2 = obj.pop()\n# param_3 = obj.top()\n# param_4 = obj.peekMax()\n# param_5 = obj.popMax()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} MaxStack;\n\n/** initialize your data structure here. */\n\nMaxStack* maxStackCreate() {\n\n}\n\nvoid maxStackPush(MaxStack* obj, int x) {\n\n}\n\nint maxStackPop(MaxStack* obj) {\n\n}\n\nint maxStackTop(MaxStack* obj) {\n\n}\n\nint maxStackPeekMax(MaxStack* obj) {\n\n}\n\nint maxStackPopMax(MaxStack* obj) {\n\n}\n\nvoid maxStackFree(MaxStack* obj) {\n\n}\n\n/**\n * Your MaxStack struct will be instantiated and called as such:\n * MaxStack* obj = maxStackCreate();\n * maxStackPush(obj, x);\n \n * int param_2 = maxStackPop(obj);\n \n * int param_3 = maxStackTop(obj);\n \n * int param_4 = maxStackPeekMax(obj);\n \n * int param_5 = maxStackPopMax(obj);\n \n * maxStackFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class MaxStack {\n\n /** initialize your data structure here. */\n public MaxStack() {\n\n }\n \n public void Push(int x) {\n\n }\n \n public int Pop() {\n\n }\n \n public int Top() {\n\n }\n \n public int PeekMax() {\n\n }\n \n public int PopMax() {\n\n }\n}\n\n/**\n * Your MaxStack object will be instantiated and called as such:\n * MaxStack obj = new MaxStack();\n * obj.Push(x);\n * int param_2 = obj.Pop();\n * int param_3 = obj.Top();\n * int param_4 = obj.PeekMax();\n * int param_5 = obj.PopMax();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * initialize your data structure here.\n */\nvar MaxStack = function() {\n\n};\n\n/** \n * @param {number} x\n * @return {void}\n */\nMaxStack.prototype.push = function(x) {\n\n};\n\n/**\n * @return {number}\n */\nMaxStack.prototype.pop = function() {\n\n};\n\n/**\n * @return {number}\n */\nMaxStack.prototype.top = function() {\n\n};\n\n/**\n * @return {number}\n */\nMaxStack.prototype.peekMax = function() {\n\n};\n\n/**\n * @return {number}\n */\nMaxStack.prototype.popMax = function() {\n\n};\n\n/**\n * Your MaxStack object will be instantiated and called as such:\n * var obj = new MaxStack()\n * obj.push(x)\n * var param_2 = obj.pop()\n * var param_3 = obj.top()\n * var param_4 = obj.peekMax()\n * var param_5 = obj.popMax()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class MaxStack\n\n=begin\n initialize your data structure here.\n=end\n def initialize()\n\n end\n\n\n=begin\n :type x: Integer\n :rtype: Void\n=end\n def push(x)\n\n end\n\n\n=begin\n :rtype: Integer\n=end\n def pop()\n\n end\n\n\n=begin\n :rtype: Integer\n=end\n def top()\n\n end\n\n\n=begin\n :rtype: Integer\n=end\n def peek_max()\n\n end\n\n\n=begin\n :rtype: Integer\n=end\n def pop_max()\n\n end\n\n\nend\n\n# Your MaxStack object will be instantiated and called as such:\n# obj = MaxStack.new()\n# obj.push(x)\n# param_2 = obj.pop()\n# param_3 = obj.top()\n# param_4 = obj.peek_max()\n# param_5 = obj.pop_max()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass MaxStack {\n\n /** initialize your data structure here. */\n init() {\n\n }\n \n func push(_ x: Int) {\n\n }\n \n func pop() -> Int {\n\n }\n \n func top() -> Int {\n\n }\n \n func peekMax() -> Int {\n\n }\n \n func popMax() -> Int {\n\n }\n}\n\n/**\n * Your MaxStack object will be instantiated and called as such:\n * let obj = MaxStack()\n * obj.push(x)\n * let ret_2: Int = obj.pop()\n * let ret_3: Int = obj.top()\n * let ret_4: Int = obj.peekMax()\n * let ret_5: Int = obj.popMax()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type MaxStack struct {\n\n}\n\n\n/** initialize your data structure here. */\nfunc Constructor() MaxStack {\n\n}\n\n\nfunc (this *MaxStack) Push(x int) {\n\n}\n\n\nfunc (this *MaxStack) Pop() int {\n\n}\n\n\nfunc (this *MaxStack) Top() int {\n\n}\n\n\nfunc (this *MaxStack) PeekMax() int {\n\n}\n\n\nfunc (this *MaxStack) PopMax() int {\n\n}\n\n\n/**\n * Your MaxStack object will be instantiated and called as such:\n * obj := Constructor();\n * obj.Push(x);\n * param_2 := obj.Pop();\n * param_3 := obj.Top();\n * param_4 := obj.PeekMax();\n * param_5 := obj.PopMax();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class MaxStack() {\n\n /** initialize your data structure here. */\n\n\n def push(x: Int) {\n\n }\n\n def pop(): Int = {\n\n }\n\n def top(): Int = {\n\n }\n\n def peekMax(): Int = {\n\n }\n\n def popMax(): Int = {\n\n }\n\n}\n\n/**\n * Your MaxStack object will be instantiated and called as such:\n * var obj = new MaxStack()\n * obj.push(x)\n * var param_2 = obj.pop()\n * var param_3 = obj.top()\n * var param_4 = obj.peekMax()\n * var param_5 = obj.popMax()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class MaxStack() {\n\n /** initialize your data structure here. */\n\n\n fun push(x: Int) {\n\n }\n\n fun pop(): Int {\n\n }\n\n fun top(): Int {\n\n }\n\n fun peekMax(): Int {\n\n }\n\n fun popMax(): Int {\n\n }\n\n}\n\n/**\n * Your MaxStack object will be instantiated and called as such:\n * var obj = MaxStack()\n * obj.push(x)\n * var param_2 = obj.pop()\n * var param_3 = obj.top()\n * var param_4 = obj.peekMax()\n * var param_5 = obj.popMax()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct MaxStack {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl MaxStack {\n\n /** initialize your data structure here. */\n fn new() -> Self {\n\n }\n \n fn push(&self, x: i32) {\n\n }\n \n fn pop(&self) -> i32 {\n\n }\n \n fn top(&self) -> i32 {\n\n }\n \n fn peek_max(&self) -> i32 {\n\n }\n \n fn pop_max(&self) -> i32 {\n\n }\n}\n\n/**\n * Your MaxStack object will be instantiated and called as such:\n * let obj = MaxStack::new();\n * obj.push(x);\n * let ret_2: i32 = obj.pop();\n * let ret_3: i32 = obj.top();\n * let ret_4: i32 = obj.peek_max();\n * let ret_5: i32 = obj.pop_max();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class MaxStack {\n /**\n * initialize your data structure here.\n */\n function __construct() {\n\n }\n\n /**\n * @param Integer $x\n * @return NULL\n */\n function push($x) {\n\n }\n\n /**\n * @return Integer\n */\n function pop() {\n\n }\n\n /**\n * @return Integer\n */\n function top() {\n\n }\n\n /**\n * @return Integer\n */\n function peekMax() {\n\n }\n\n /**\n * @return Integer\n */\n function popMax() {\n\n }\n}\n\n/**\n * Your MaxStack object will be instantiated and called as such:\n * $obj = MaxStack();\n * $obj->push($x);\n * $ret_2 = $obj->pop();\n * $ret_3 = $obj->top();\n * $ret_4 = $obj->peekMax();\n * $ret_5 = $obj->popMax();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class MaxStack {\n constructor() {\n\n }\n\n push(x: number): void {\n\n }\n\n pop(): number {\n\n }\n\n top(): number {\n\n }\n\n peekMax(): number {\n\n }\n\n popMax(): number {\n\n }\n}\n\n/**\n * Your MaxStack object will be instantiated and called as such:\n * var obj = new MaxStack()\n * obj.push(x)\n * var param_2 = obj.pop()\n * var param_3 = obj.top()\n * var param_4 = obj.peekMax()\n * var param_5 = obj.popMax()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define max-stack%\n (class object%\n (super-new)\n (init-field)\n \n ; push : exact-integer? -> void?\n (define/public (push x)\n\n )\n ; pop : -> exact-integer?\n (define/public (pop)\n\n )\n ; top : -> exact-integer?\n (define/public (top)\n\n )\n ; peek-max : -> exact-integer?\n (define/public (peek-max)\n\n )\n ; pop-max : -> exact-integer?\n (define/public (pop-max)\n\n )))\n\n;; Your max-stack% object will be instantiated and called as such:\n;; (define obj (new max-stack%))\n;; (send obj push x)\n;; (define param_2 (send obj pop))\n;; (define param_3 (send obj top))\n;; (define param_4 (send obj peek-max))\n;; (define param_5 (send obj pop-max))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0716](https://leetcode-cn.com/problems/max-stack)", "[\u6700\u5927\u6808](/solution/0700-0799/0716.Max%20Stack/README.md)", "`\u8bbe\u8ba1`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0716](https://leetcode.com/problems/max-stack)", "[Max Stack](/solution/0700-0799/0716.Max%20Stack/README_EN.md)", "`Design`", "Easy", "\ud83d\udd12"]}, {"question_id": "0715", "frontend_question_id": "0715", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/range-module", "url_en": "https://leetcode.com/problems/range-module", "relative_path_cn": "/solution/0700-0799/0715.Range%20Module/README.md", "relative_path_en": "/solution/0700-0799/0715.Range%20Module/README_EN.md", "title_cn": "Range \u6a21\u5757", "title_en": "Range Module", "question_title_slug": "range-module", "content_en": "

    A Range Module is a module that tracks ranges of numbers. Your task is to design and implement the following interfaces in an efficient manner.

    \r\n\r\n

  • addRange(int left, int right) Adds the half-open interval [left, right), tracking every real number in that interval. Adding an interval that partially overlaps with currently tracked numbers should add any numbers in the interval [left, right) that are not already tracked.
  • \r\n\r\n

  • queryRange(int left, int right) Returns true if and only if every real number in the interval [left, right)\r\n is currently being tracked.
  • \r\n\r\n

  • removeRange(int left, int right) Stops tracking every real number currently being tracked in the interval [left, right).
  • \r\n\r\n

    Example 1:
    \r\n

    \r\naddRange(10, 20): null\r\nremoveRange(14, 16): null\r\nqueryRange(10, 14): true (Every number in [10, 14) is being tracked)\r\nqueryRange(13, 15): false (Numbers like 14, 14.03, 14.17 in [13, 15) are not being tracked)\r\nqueryRange(16, 17): true (The number 16 in [16, 17) is still being tracked, despite the remove operation)\r\n
    \r\n

    \r\n\r\n

    Note:\r\n

  • A half open interval [left, right) denotes all real numbers left <= x < right.
  • \r\n\r\n
  • 0 < left < right < 10^9 in all calls to addRange, queryRange, removeRange.
  • \r\n
  • The total number of calls to addRange in a single test case is at most 1000.
  • \r\n
  • The total number of calls to queryRange in a single test case is at most 5000.
  • \r\n
  • The total number of calls to removeRange in a single test case is at most 1000.
  • \r\n

    ", "content_cn": "

    Range \u6a21\u5757\u662f\u8ddf\u8e2a\u6570\u5b57\u8303\u56f4\u7684\u6a21\u5757\u3002\u4f60\u7684\u4efb\u52a1\u662f\u4ee5\u4e00\u79cd\u6709\u6548\u7684\u65b9\u5f0f\u8bbe\u8ba1\u548c\u5b9e\u73b0\u4ee5\u4e0b\u63a5\u53e3\u3002

    \n\n
      \n\t
    • addRange(int left, int right) \u6dfb\u52a0\u534a\u5f00\u533a\u95f4 [left, right)\uff0c\u8ddf\u8e2a\u8be5\u533a\u95f4\u4e2d\u7684\u6bcf\u4e2a\u5b9e\u6570\u3002\u6dfb\u52a0\u4e0e\u5f53\u524d\u8ddf\u8e2a\u7684\u6570\u5b57\u90e8\u5206\u91cd\u53e0\u7684\u533a\u95f4\u65f6\uff0c\u5e94\u5f53\u6dfb\u52a0\u5728\u533a\u95f4 [left, right) \u4e2d\u5c1a\u672a\u8ddf\u8e2a\u7684\u4efb\u4f55\u6570\u5b57\u5230\u8be5\u533a\u95f4\u4e2d\u3002
    • \n\t
    • queryRange(int left, int right) \u53ea\u6709\u5728\u5f53\u524d\u6b63\u5728\u8ddf\u8e2a\u533a\u95f4 [left, right) \u4e2d\u7684\u6bcf\u4e00\u4e2a\u5b9e\u6570\u65f6\uff0c\u624d\u8fd4\u56de true\u3002
    • \n\t
    • removeRange(int left, int right) \u505c\u6b62\u8ddf\u8e2a\u533a\u95f4 [left, right) \u4e2d\u5f53\u524d\u6b63\u5728\u8ddf\u8e2a\u7684\u6bcf\u4e2a\u5b9e\u6570\u3002
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    addRange(10, 20): null\nremoveRange(14, 16): null\nqueryRange(10, 14): true \uff08\u533a\u95f4 [10, 14) \u4e2d\u7684\u6bcf\u4e2a\u6570\u90fd\u6b63\u5728\u88ab\u8ddf\u8e2a\uff09\nqueryRange(13, 15): false \uff08\u672a\u8ddf\u8e2a\u533a\u95f4 [13, 15) \u4e2d\u50cf 14, 14.03, 14.17 \u8fd9\u6837\u7684\u6570\u5b57\uff09\nqueryRange(16, 17): true \uff08\u5c3d\u7ba1\u6267\u884c\u4e86\u5220\u9664\u64cd\u4f5c\uff0c\u533a\u95f4 [16, 17) \u4e2d\u7684\u6570\u5b57 16 \u4ecd\u7136\u4f1a\u88ab\u8ddf\u8e2a\uff09\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u534a\u5f00\u533a\u95f4 [left, right) \u8868\u793a\u6240\u6709\u6ee1\u8db3 left <= x < right \u7684\u5b9e\u6570\u3002
    • \n\t
    • \u5bf9 addRange, queryRange, removeRange \u7684\u6240\u6709\u8c03\u7528\u4e2d 0 < left < right < 10^9\u3002
    • \n\t
    • \u5728\u5355\u4e2a\u6d4b\u8bd5\u7528\u4f8b\u4e2d\uff0c\u5bf9 addRange \u7684\u8c03\u7528\u603b\u6570\u4e0d\u8d85\u8fc7 1000 \u6b21\u3002
    • \n\t
    • \u5728\u5355\u4e2a\u6d4b\u8bd5\u7528\u4f8b\u4e2d\uff0c\u5bf9  queryRange \u7684\u8c03\u7528\u603b\u6570\u4e0d\u8d85\u8fc7 5000 \u6b21\u3002
    • \n\t
    • \u5728\u5355\u4e2a\u6d4b\u8bd5\u7528\u4f8b\u4e2d\uff0c\u5bf9 removeRange \u7684\u8c03\u7528\u603b\u6570\u4e0d\u8d85\u8fc7 1000 \u6b21\u3002
    • \n
    \n\n

     

    \n", "tags_en": ["Segment Tree", "Ordered Map"], "tags_cn": ["\u7ebf\u6bb5\u6811"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class RangeModule {\npublic:\n RangeModule() {\n\n }\n \n void addRange(int left, int right) {\n\n }\n \n bool queryRange(int left, int right) {\n\n }\n \n void removeRange(int left, int right) {\n\n }\n};\n\n/**\n * Your RangeModule object will be instantiated and called as such:\n * RangeModule* obj = new RangeModule();\n * obj->addRange(left,right);\n * bool param_2 = obj->queryRange(left,right);\n * obj->removeRange(left,right);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class RangeModule {\n\n public RangeModule() {\n\n }\n \n public void addRange(int left, int right) {\n\n }\n \n public boolean queryRange(int left, int right) {\n\n }\n \n public void removeRange(int left, int right) {\n\n }\n}\n\n/**\n * Your RangeModule object will be instantiated and called as such:\n * RangeModule obj = new RangeModule();\n * obj.addRange(left,right);\n * boolean param_2 = obj.queryRange(left,right);\n * obj.removeRange(left,right);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class RangeModule(object):\n\n def __init__(self):\n \n\n def addRange(self, left, right):\n \"\"\"\n :type left: int\n :type right: int\n :rtype: None\n \"\"\"\n \n\n def queryRange(self, left, right):\n \"\"\"\n :type left: int\n :type right: int\n :rtype: bool\n \"\"\"\n \n\n def removeRange(self, left, right):\n \"\"\"\n :type left: int\n :type right: int\n :rtype: None\n \"\"\"\n \n\n\n# Your RangeModule object will be instantiated and called as such:\n# obj = RangeModule()\n# obj.addRange(left,right)\n# param_2 = obj.queryRange(left,right)\n# obj.removeRange(left,right)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class RangeModule:\n\n def __init__(self):\n \n\n def addRange(self, left: int, right: int) -> None:\n \n\n def queryRange(self, left: int, right: int) -> bool:\n \n\n def removeRange(self, left: int, right: int) -> None:\n \n\n\n# Your RangeModule object will be instantiated and called as such:\n# obj = RangeModule()\n# obj.addRange(left,right)\n# param_2 = obj.queryRange(left,right)\n# obj.removeRange(left,right)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} RangeModule;\n\n\nRangeModule* rangeModuleCreate() {\n \n}\n\nvoid rangeModuleAddRange(RangeModule* obj, int left, int right) {\n \n}\n\nbool rangeModuleQueryRange(RangeModule* obj, int left, int right) {\n \n}\n\nvoid rangeModuleRemoveRange(RangeModule* obj, int left, int right) {\n \n}\n\nvoid rangeModuleFree(RangeModule* obj) {\n \n}\n\n/**\n * Your RangeModule struct will be instantiated and called as such:\n * RangeModule* obj = rangeModuleCreate();\n * rangeModuleAddRange(obj, left, right);\n \n * bool param_2 = rangeModuleQueryRange(obj, left, right);\n \n * rangeModuleRemoveRange(obj, left, right);\n \n * rangeModuleFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class RangeModule {\n\n public RangeModule() {\n\n }\n \n public void AddRange(int left, int right) {\n\n }\n \n public bool QueryRange(int left, int right) {\n\n }\n \n public void RemoveRange(int left, int right) {\n\n }\n}\n\n/**\n * Your RangeModule object will be instantiated and called as such:\n * RangeModule obj = new RangeModule();\n * obj.AddRange(left,right);\n * bool param_2 = obj.QueryRange(left,right);\n * obj.RemoveRange(left,right);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "\nvar RangeModule = function() {\n\n};\n\n/** \n * @param {number} left \n * @param {number} right\n * @return {void}\n */\nRangeModule.prototype.addRange = function(left, right) {\n\n};\n\n/** \n * @param {number} left \n * @param {number} right\n * @return {boolean}\n */\nRangeModule.prototype.queryRange = function(left, right) {\n\n};\n\n/** \n * @param {number} left \n * @param {number} right\n * @return {void}\n */\nRangeModule.prototype.removeRange = function(left, right) {\n\n};\n\n/**\n * Your RangeModule object will be instantiated and called as such:\n * var obj = new RangeModule()\n * obj.addRange(left,right)\n * var param_2 = obj.queryRange(left,right)\n * obj.removeRange(left,right)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class RangeModule\n def initialize()\n\n end\n\n\n=begin\n :type left: Integer\n :type right: Integer\n :rtype: Void\n=end\n def add_range(left, right)\n\n end\n\n\n=begin\n :type left: Integer\n :type right: Integer\n :rtype: Boolean\n=end\n def query_range(left, right)\n\n end\n\n\n=begin\n :type left: Integer\n :type right: Integer\n :rtype: Void\n=end\n def remove_range(left, right)\n\n end\n\n\nend\n\n# Your RangeModule object will be instantiated and called as such:\n# obj = RangeModule.new()\n# obj.add_range(left, right)\n# param_2 = obj.query_range(left, right)\n# obj.remove_range(left, right)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass RangeModule {\n\n init() {\n \n }\n \n func addRange(_ left: Int, _ right: Int) {\n \n }\n \n func queryRange(_ left: Int, _ right: Int) -> Bool {\n \n }\n \n func removeRange(_ left: Int, _ right: Int) {\n \n }\n}\n\n/**\n * Your RangeModule object will be instantiated and called as such:\n * let obj = RangeModule()\n * obj.addRange(left, right)\n * let ret_2: Bool = obj.queryRange(left, right)\n * obj.removeRange(left, right)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type RangeModule struct {\n\n}\n\n\nfunc Constructor() RangeModule {\n\n}\n\n\nfunc (this *RangeModule) AddRange(left int, right int) {\n\n}\n\n\nfunc (this *RangeModule) QueryRange(left int, right int) bool {\n\n}\n\n\nfunc (this *RangeModule) RemoveRange(left int, right int) {\n\n}\n\n\n/**\n * Your RangeModule object will be instantiated and called as such:\n * obj := Constructor();\n * obj.AddRange(left,right);\n * param_2 := obj.QueryRange(left,right);\n * obj.RemoveRange(left,right);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class RangeModule() {\n\n def addRange(left: Int, right: Int) {\n\n }\n\n def queryRange(left: Int, right: Int): Boolean = {\n\n }\n\n def removeRange(left: Int, right: Int) {\n\n }\n\n}\n\n/**\n * Your RangeModule object will be instantiated and called as such:\n * var obj = new RangeModule()\n * obj.addRange(left,right)\n * var param_2 = obj.queryRange(left,right)\n * obj.removeRange(left,right)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class RangeModule() {\n\n fun addRange(left: Int, right: Int) {\n\n }\n\n fun queryRange(left: Int, right: Int): Boolean {\n\n }\n\n fun removeRange(left: Int, right: Int) {\n\n }\n\n}\n\n/**\n * Your RangeModule object will be instantiated and called as such:\n * var obj = RangeModule()\n * obj.addRange(left,right)\n * var param_2 = obj.queryRange(left,right)\n * obj.removeRange(left,right)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct RangeModule {\n\n}\n\n\n/** \n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl RangeModule {\n\n fn new() -> Self {\n \n }\n \n fn add_range(&self, left: i32, right: i32) {\n \n }\n \n fn query_range(&self, left: i32, right: i32) -> bool {\n \n }\n \n fn remove_range(&self, left: i32, right: i32) {\n \n }\n}\n\n/**\n * Your RangeModule object will be instantiated and called as such:\n * let obj = RangeModule::new();\n * obj.add_range(left, right);\n * let ret_2: bool = obj.query_range(left, right);\n * obj.remove_range(left, right);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class RangeModule {\n /**\n */\n function __construct() {\n \n }\n \n /**\n * @param Integer $left\n * @param Integer $right\n * @return NULL\n */\n function addRange($left, $right) {\n \n }\n \n /**\n * @param Integer $left\n * @param Integer $right\n * @return Boolean\n */\n function queryRange($left, $right) {\n \n }\n \n /**\n * @param Integer $left\n * @param Integer $right\n * @return NULL\n */\n function removeRange($left, $right) {\n \n }\n}\n\n/**\n * Your RangeModule object will be instantiated and called as such:\n * $obj = RangeModule();\n * $obj->addRange($left, $right);\n * $ret_2 = $obj->queryRange($left, $right);\n * $obj->removeRange($left, $right);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class RangeModule {\n constructor() {\n\n }\n\n addRange(left: number, right: number): void {\n\n }\n\n queryRange(left: number, right: number): boolean {\n\n }\n\n removeRange(left: number, right: number): void {\n\n }\n}\n\n/**\n * Your RangeModule object will be instantiated and called as such:\n * var obj = new RangeModule()\n * obj.addRange(left,right)\n * var param_2 = obj.queryRange(left,right)\n * obj.removeRange(left,right)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define range-module%\n (class object%\n (super-new)\n (init-field)\n \n ; add-range : exact-integer? exact-integer? -> void?\n (define/public (add-range left right)\n\n )\n ; query-range : exact-integer? exact-integer? -> boolean?\n (define/public (query-range left right)\n\n )\n ; remove-range : exact-integer? exact-integer? -> void?\n (define/public (remove-range left right)\n\n )))\n\n;; Your range-module% object will be instantiated and called as such:\n;; (define obj (new range-module%))\n;; (send obj add-range left right)\n;; (define param_2 (send obj query-range left right))\n;; (send obj remove-range left right)", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0715](https://leetcode-cn.com/problems/range-module)", "[Range \u6a21\u5757](/solution/0700-0799/0715.Range%20Module/README.md)", "`\u7ebf\u6bb5\u6811`", "\u56f0\u96be", ""], "md_table_row_en": ["[0715](https://leetcode.com/problems/range-module)", "[Range Module](/solution/0700-0799/0715.Range%20Module/README_EN.md)", "`Segment Tree`,`Ordered Map`", "Hard", ""]}, {"question_id": "0714", "frontend_question_id": "0714", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-with-transaction-fee", "url_en": "https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-transaction-fee", "relative_path_cn": "/solution/0700-0799/0714.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20with%20Transaction%20Fee/README.md", "relative_path_en": "/solution/0700-0799/0714.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20with%20Transaction%20Fee/README_EN.md", "title_cn": "\u4e70\u5356\u80a1\u7968\u7684\u6700\u4f73\u65f6\u673a\u542b\u624b\u7eed\u8d39", "title_en": "Best Time to Buy and Sell Stock with Transaction Fee", "question_title_slug": "best-time-to-buy-and-sell-stock-with-transaction-fee", "content_en": "

    You are given an array prices where prices[i] is the price of a given stock on the ith day, and an integer fee representing a transaction fee.

    \n\n

    Find the maximum profit you can achieve. You may complete as many transactions as you like, but you need to pay the transaction fee for each transaction.

    \n\n

    Note: You may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again).

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: prices = [1,3,2,8,4,9], fee = 2\nOutput: 8\nExplanation: The maximum profit can be achieved by:\n- Buying at prices[0] = 1\n- Selling at prices[3] = 8\n- Buying at prices[4] = 4\n- Selling at prices[5] = 9\nThe total profit is ((8 - 1) - 2) + ((9 - 4) - 2) = 8.\n
    \n\n

    Example 2:

    \n\n
    \nInput: prices = [1,3,7,5,10,3], fee = 3\nOutput: 6\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= prices.length <= 5 * 104
    • \n\t
    • 1 <= prices[i] < 5 * 104
    • \n\t
    • 0 <= fee < 5 * 104
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 prices\uff0c\u5176\u4e2d\u7b2c i \u4e2a\u5143\u7d20\u4ee3\u8868\u4e86\u7b2c i \u5929\u7684\u80a1\u7968\u4ef7\u683c \uff1b\u975e\u8d1f\u6574\u6570 fee \u4ee3\u8868\u4e86\u4ea4\u6613\u80a1\u7968\u7684\u624b\u7eed\u8d39\u7528\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u65e0\u9650\u6b21\u5730\u5b8c\u6210\u4ea4\u6613\uff0c\u4f46\u662f\u4f60\u6bcf\u7b14\u4ea4\u6613\u90fd\u9700\u8981\u4ed8\u624b\u7eed\u8d39\u3002\u5982\u679c\u4f60\u5df2\u7ecf\u8d2d\u4e70\u4e86\u4e00\u4e2a\u80a1\u7968\uff0c\u5728\u5356\u51fa\u5b83\u4e4b\u524d\u4f60\u5c31\u4e0d\u80fd\u518d\u7ee7\u7eed\u8d2d\u4e70\u80a1\u7968\u4e86\u3002

    \n\n

    \u8fd4\u56de\u83b7\u5f97\u5229\u6da6\u7684\u6700\u5927\u503c\u3002

    \n\n

    \u6ce8\u610f\uff1a\u8fd9\u91cc\u7684\u4e00\u7b14\u4ea4\u6613\u6307\u4e70\u5165\u6301\u6709\u5e76\u5356\u51fa\u80a1\u7968\u7684\u6574\u4e2a\u8fc7\u7a0b\uff0c\u6bcf\u7b14\u4ea4\u6613\u4f60\u53ea\u9700\u8981\u4e3a\u652f\u4ed8\u4e00\u6b21\u624b\u7eed\u8d39\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: prices = [1, 3, 2, 8, 4, 9], fee = 2\n\u8f93\u51fa: 8\n\u89e3\u91ca: \u80fd\u591f\u8fbe\u5230\u7684\u6700\u5927\u5229\u6da6:  \n\u5728\u6b64\u5904\u4e70\u5165 prices[0] = 1\n\u5728\u6b64\u5904\u5356\u51fa prices[3] = 8\n\u5728\u6b64\u5904\u4e70\u5165 prices[4] = 4\n\u5728\u6b64\u5904\u5356\u51fa prices[5] = 9\n\u603b\u5229\u6da6: ((8 - 1) - 2) + ((9 - 4) - 2) = 8.
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    • 0 < prices.length <= 50000.
    • \n\t
    • 0 < prices[i] < 50000.
    • \n\t
    • 0 <= fee < 50000.
    • \n
    \n", "tags_en": ["Greedy", "Array", "Dynamic Programming"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u7ec4", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxProfit(vector& prices, int fee) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxProfit(int[] prices, int fee) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxProfit(self, prices, fee):\n \"\"\"\n :type prices: List[int]\n :type fee: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxProfit(self, prices: List[int], fee: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxProfit(int* prices, int pricesSize, int fee){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxProfit(int[] prices, int fee) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} prices\n * @param {number} fee\n * @return {number}\n */\nvar maxProfit = function(prices, fee) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} prices\n# @param {Integer} fee\n# @return {Integer}\ndef max_profit(prices, fee)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxProfit(_ prices: [Int], _ fee: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxProfit(prices []int, fee int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxProfit(prices: Array[Int], fee: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxProfit(prices: IntArray, fee: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_profit(prices: Vec, fee: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $prices\n * @param Integer $fee\n * @return Integer\n */\n function maxProfit($prices, $fee) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxProfit(prices: number[], fee: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-profit prices fee)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0714](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-with-transaction-fee)", "[\u4e70\u5356\u80a1\u7968\u7684\u6700\u4f73\u65f6\u673a\u542b\u624b\u7eed\u8d39](/solution/0700-0799/0714.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20with%20Transaction%20Fee/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u7ec4`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0714](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-transaction-fee)", "[Best Time to Buy and Sell Stock with Transaction Fee](/solution/0700-0799/0714.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20with%20Transaction%20Fee/README_EN.md)", "`Greedy`,`Array`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0713", "frontend_question_id": "0713", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/subarray-product-less-than-k", "url_en": "https://leetcode.com/problems/subarray-product-less-than-k", "relative_path_cn": "/solution/0700-0799/0713.Subarray%20Product%20Less%20Than%20K/README.md", "relative_path_en": "/solution/0700-0799/0713.Subarray%20Product%20Less%20Than%20K/README_EN.md", "title_cn": "\u4e58\u79ef\u5c0f\u4e8eK\u7684\u5b50\u6570\u7ec4", "title_en": "Subarray Product Less Than K", "question_title_slug": "subarray-product-less-than-k", "content_en": "

    Given an array of integers nums and an integer k, return the number of contiguous subarrays where the product of all the elements in the subarray is strictly less than k.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [10,5,2,6], k = 100\nOutput: 8\nExplanation: The 8 subarrays that have product less than 100 are:\n[10], [5], [2], [6], [10, 5], [5, 2], [2, 6], [5, 2, 6]\nNote that [10, 5, 2] is not included as the product of 100 is not strictly less than k.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,2,3], k = 0\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • 0 <= nums[i] < 1000
    • \n\t
    • 0 <= k < 106
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6b63\u6574\u6570\u6570\u7ec4 nums\u3002

    \n\n

    \u627e\u51fa\u8be5\u6570\u7ec4\u5185\u4e58\u79ef\u5c0f\u4e8e k \u7684\u8fde\u7eed\u7684\u5b50\u6570\u7ec4\u7684\u4e2a\u6570\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: nums = [10,5,2,6], k = 100\n\u8f93\u51fa: 8\n\u89e3\u91ca: 8\u4e2a\u4e58\u79ef\u5c0f\u4e8e100\u7684\u5b50\u6570\u7ec4\u5206\u522b\u4e3a: [10], [5], [2], [6], [10,5], [5,2], [2,6], [5,2,6]\u3002\n\u9700\u8981\u6ce8\u610f\u7684\u662f [10,5,2] \u5e76\u4e0d\u662f\u4e58\u79ef\u5c0f\u4e8e100\u7684\u5b50\u6570\u7ec4\u3002\n
    \n\n

    \u8bf4\u660e:

    \n\n
      \n\t
    • 0 < nums.length <= 50000
    • \n\t
    • 0 < nums[i] < 1000
    • \n\t
    • 0 <= k < 10^6
    • \n
    \n", "tags_en": ["Array", "Two Pointers"], "tags_cn": ["\u6570\u7ec4", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numSubarrayProductLessThanK(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numSubarrayProductLessThanK(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numSubarrayProductLessThanK(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numSubarrayProductLessThanK(self, nums: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numSubarrayProductLessThanK(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumSubarrayProductLessThanK(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar numSubarrayProductLessThanK = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef num_subarray_product_less_than_k(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numSubarrayProductLessThanK(_ nums: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numSubarrayProductLessThanK(nums []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numSubarrayProductLessThanK(nums: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numSubarrayProductLessThanK(nums: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_subarray_product_less_than_k(nums: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer\n */\n function numSubarrayProductLessThanK($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numSubarrayProductLessThanK(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-subarray-product-less-than-k nums k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0713](https://leetcode-cn.com/problems/subarray-product-less-than-k)", "[\u4e58\u79ef\u5c0f\u4e8eK\u7684\u5b50\u6570\u7ec4](/solution/0700-0799/0713.Subarray%20Product%20Less%20Than%20K/README.md)", "`\u6570\u7ec4`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0713](https://leetcode.com/problems/subarray-product-less-than-k)", "[Subarray Product Less Than K](/solution/0700-0799/0713.Subarray%20Product%20Less%20Than%20K/README_EN.md)", "`Array`,`Two Pointers`", "Medium", ""]}, {"question_id": "0712", "frontend_question_id": "0712", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-ascii-delete-sum-for-two-strings", "url_en": "https://leetcode.com/problems/minimum-ascii-delete-sum-for-two-strings", "relative_path_cn": "/solution/0700-0799/0712.Minimum%20ASCII%20Delete%20Sum%20for%20Two%20Strings/README.md", "relative_path_en": "/solution/0700-0799/0712.Minimum%20ASCII%20Delete%20Sum%20for%20Two%20Strings/README_EN.md", "title_cn": "\u4e24\u4e2a\u5b57\u7b26\u4e32\u7684\u6700\u5c0fASCII\u5220\u9664\u548c", "title_en": "Minimum ASCII Delete Sum for Two Strings", "question_title_slug": "minimum-ascii-delete-sum-for-two-strings", "content_en": "

    Given two strings s1 and s2, return the lowest ASCII sum of deleted characters to make two strings equal.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s1 = "sea", s2 = "eat"\nOutput: 231\nExplanation: Deleting "s" from "sea" adds the ASCII value of "s" (115) to the sum.\nDeleting "t" from "eat" adds 116 to the sum.\nAt the end, both strings are equal, and 115 + 116 = 231 is the minimum sum possible to achieve this.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s1 = "delete", s2 = "leet"\nOutput: 403\nExplanation: Deleting "dee" from "delete" to turn the string into "let",\nadds 100[d] + 101[e] + 101[e] to the sum.\nDeleting "e" from "leet" adds 101[e] to the sum.\nAt the end, both strings are equal to "let", and the answer is 100+101+101+101 = 403.\nIf instead we turned both strings into "lee" or "eet", we would get answers of 433 or 417, which are higher.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s1.length, s2.length <= 1000
    • \n\t
    • s1 and s2 consist of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u5b57\u7b26\u4e32s1, s2\uff0c\u627e\u5230\u4f7f\u4e24\u4e2a\u5b57\u7b26\u4e32\u76f8\u7b49\u6240\u9700\u5220\u9664\u5b57\u7b26\u7684ASCII\u503c\u7684\u6700\u5c0f\u548c\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: s1 = "sea", s2 = "eat"\n\u8f93\u51fa: 231\n\u89e3\u91ca: \u5728 "sea" \u4e2d\u5220\u9664 "s" \u5e76\u5c06 "s" \u7684\u503c(115)\u52a0\u5165\u603b\u548c\u3002\n\u5728 "eat" \u4e2d\u5220\u9664 "t" \u5e76\u5c06 116 \u52a0\u5165\u603b\u548c\u3002\n\u7ed3\u675f\u65f6\uff0c\u4e24\u4e2a\u5b57\u7b26\u4e32\u76f8\u7b49\uff0c115 + 116 = 231 \u5c31\u662f\u7b26\u5408\u6761\u4ef6\u7684\u6700\u5c0f\u548c\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: s1 = "delete", s2 = "leet"\n\u8f93\u51fa: 403\n\u89e3\u91ca: \u5728 "delete" \u4e2d\u5220\u9664 "dee" \u5b57\u7b26\u4e32\u53d8\u6210 "let"\uff0c\n\u5c06 100[d]+101[e]+101[e] \u52a0\u5165\u603b\u548c\u3002\u5728 "leet" \u4e2d\u5220\u9664 "e" \u5c06 101[e] \u52a0\u5165\u603b\u548c\u3002\n\u7ed3\u675f\u65f6\uff0c\u4e24\u4e2a\u5b57\u7b26\u4e32\u90fd\u7b49\u4e8e "let"\uff0c\u7ed3\u679c\u5373\u4e3a 100+101+101+101 = 403 \u3002\n\u5982\u679c\u6539\u4e3a\u5c06\u4e24\u4e2a\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a "lee" \u6216 "eet"\uff0c\u6211\u4eec\u4f1a\u5f97\u5230 433 \u6216 417 \u7684\u7ed3\u679c\uff0c\u6bd4\u7b54\u6848\u66f4\u5927\u3002\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    • 0 < s1.length, s2.length <= 1000\u3002
    • \n\t
    • \u6240\u6709\u5b57\u7b26\u4e32\u4e2d\u7684\u5b57\u7b26ASCII\u503c\u5728[97, 122]\u4e4b\u95f4\u3002
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minimumDeleteSum(string s1, string s2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minimumDeleteSum(String s1, String s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimumDeleteSum(self, s1, s2):\n \"\"\"\n :type s1: str\n :type s2: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimumDeleteSum(self, s1: str, s2: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minimumDeleteSum(char * s1, char * s2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinimumDeleteSum(string s1, string s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s1\n * @param {string} s2\n * @return {number}\n */\nvar minimumDeleteSum = function(s1, s2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s1\n# @param {String} s2\n# @return {Integer}\ndef minimum_delete_sum(s1, s2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimumDeleteSum(_ s1: String, _ s2: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimumDeleteSum(s1 string, s2 string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimumDeleteSum(s1: String, s2: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimumDeleteSum(s1: String, s2: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimum_delete_sum(s1: String, s2: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s1\n * @param String $s2\n * @return Integer\n */\n function minimumDeleteSum($s1, $s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimumDeleteSum(s1: string, s2: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimum-delete-sum s1 s2)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0712](https://leetcode-cn.com/problems/minimum-ascii-delete-sum-for-two-strings)", "[\u4e24\u4e2a\u5b57\u7b26\u4e32\u7684\u6700\u5c0fASCII\u5220\u9664\u548c](/solution/0700-0799/0712.Minimum%20ASCII%20Delete%20Sum%20for%20Two%20Strings/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0712](https://leetcode.com/problems/minimum-ascii-delete-sum-for-two-strings)", "[Minimum ASCII Delete Sum for Two Strings](/solution/0700-0799/0712.Minimum%20ASCII%20Delete%20Sum%20for%20Two%20Strings/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0711", "frontend_question_id": "0711", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/number-of-distinct-islands-ii", "url_en": "https://leetcode.com/problems/number-of-distinct-islands-ii", "relative_path_cn": "/solution/0700-0799/0711.Number%20of%20Distinct%20Islands%20II/README.md", "relative_path_en": "/solution/0700-0799/0711.Number%20of%20Distinct%20Islands%20II/README_EN.md", "title_cn": "\u4e0d\u540c\u5c9b\u5c7f\u7684\u6570\u91cf II", "title_en": "Number of Distinct Islands II", "question_title_slug": "number-of-distinct-islands-ii", "content_en": "

    You are given an m x n binary matrix grid. An island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrounded by water.

    \n\n

    An island is considered to be the same as another if they have the same shape, or have the same shape after rotation (90, 180, or 270 degrees only) or reflection (left/right direction or up/down direction).

    \n\n

    Return the number of distinct islands.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: grid = [[1,1,0,0,0],[1,0,0,0,0],[0,0,0,0,1],[0,0,0,1,1]]\nOutput: 1\nExplanation: The two islands are considered the same because if we make a 180 degrees clockwise rotation on the first island, then two islands will have the same shapes.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: grid = [[1,1,0,0,0],[1,1,0,0,0],[0,0,0,1,1],[0,0,0,1,1]]\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= m, n <= 50
    • \n\t
    • grid[i][j] is either 0 or 1.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u7a7a01\u4e8c\u7ef4\u6570\u7ec4\u8868\u793a\u7684\u7f51\u683c\uff0c\u4e00\u4e2a\u5c9b\u5c7f\u7531\u56db\u8fde\u901a\uff08\u4e0a\u3001\u4e0b\u3001\u5de6\u3001\u53f3\u56db\u4e2a\u65b9\u5411\uff09\u7684 1 \u7ec4\u6210\uff0c\u4f60\u53ef\u4ee5\u8ba4\u4e3a\u7f51\u683c\u7684\u56db\u5468\u88ab\u6d77\u6c34\u5305\u56f4\u3002

    \n\n

    \u8bf7\u4f60\u8ba1\u7b97\u8fd9\u4e2a\u7f51\u683c\u4e2d\u5171\u6709\u591a\u5c11\u4e2a\u5f62\u72b6\u4e0d\u540c\u7684\u5c9b\u5c7f\u3002\u5982\u679c\u4e24\u4e2a\u5c9b\u5c7f\u7684\u5f62\u72b6\u76f8\u540c\uff0c\u6216\u8005\u901a\u8fc7\u65cb\u8f6c\uff08\u987a\u65f6\u9488\u65cb\u8f6c 90°\uff0c180°\uff0c270°\uff09\u3001\u7ffb\u8f6c\uff08\u5de6\u53f3\u7ffb\u8f6c\u3001\u4e0a\u4e0b\u7ffb\u8f6c\uff09\u540e\u5f62\u72b6\u76f8\u540c\uff0c\u90a3\u4e48\u5c31\u8ba4\u4e3a\u8fd9\u4e24\u4e2a\u5c9b\u5c7f\u662f\u76f8\u540c\u7684\u3002

    \n\n

     

    \n\n

    \u6837\u4f8b 1:

    \n\n
    11000\n10000\n00001\n00011\n
    \n\n

    \u7ed9\u5b9a\u4e0a\u56fe\uff0c\u8fd4\u56de\u7ed3\u679c 1\u3002
    \n
    \n\u6ce8\u610f \uff1a

    \n\n
    11\n1\n
    \n\n

    \u548c

    \n\n
     1\n11
    \n\n

    \u662f\u76f8\u540c\u7684\u5c9b\u5c7f\u3002\u56e0\u4e3a\u6211\u4eec\u901a\u8fc7 180° \u65cb\u8f6c\u7b2c\u4e00\u4e2a\u5c9b\u5c7f\uff0c\u4e24\u4e2a\u5c9b\u5c7f\u7684\u5f62\u72b6\u76f8\u540c\u3002

    \n\n

     

    \n\n

    \u6837\u4f8b 2:

    \n\n
    11100\n10001\n01001\n01110
    \n\n

    \u7ed9\u5b9a\u4e0a\u56fe\uff0c\u8fd4\u56de\u7ed3\u679c 2\u3002
    \n
    \n\u4e0b\u9762\u662f\u4e24\u4e2a\u4e0d\u540c\u7684\u5c9b\u5c7f\uff1a

    \n\n
    111\n1
    \n\n

    \u548c

    \n\n
    1\n1\n
    \n\n

     

    \n\n

    \u6ce8\u610f \uff1a

    \n\n
    111\n1
    \n\n

    \u548c

    \n\n
    1\n111\n
    \n\n

    \u76f8\u540c\u7684\u5c9b\u5c7f\u3002\u56e0\u4e3a\u6211\u4eec\u901a\u8fc7\u4e0a\u4e0b\u7ffb\u8f6c\u7b2c\u4e00\u4e2a\u5c9b\u5c7f\uff0c\u4e24\u4e2a\u5c9b\u5c7f\u7684\u5f62\u72b6\u76f8\u540c\u3002

    \n\n

     

    \n\n

    \u6ce8\u91ca :  \u4e8c\u7ef4\u6570\u7ec4\u6bcf\u7ef4\u7684\u5927\u5c0f\u90fd\u4e0d\u4f1a\u8d85\u8fc750\u3002

    \n", "tags_en": ["Depth-first Search", "Hash Table"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u54c8\u5e0c\u8868"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numDistinctIslands2(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numDistinctIslands2(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numDistinctIslands2(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numDistinctIslands2(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numDistinctIslands2(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumDistinctIslands2(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar numDistinctIslands2 = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef num_distinct_islands2(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numDistinctIslands2(_ grid: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numDistinctIslands2(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numDistinctIslands2(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numDistinctIslands2(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_distinct_islands2(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function numDistinctIslands2($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numDistinctIslands2(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-distinct-islands2 grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0711](https://leetcode-cn.com/problems/number-of-distinct-islands-ii)", "[\u4e0d\u540c\u5c9b\u5c7f\u7684\u6570\u91cf II](/solution/0700-0799/0711.Number%20of%20Distinct%20Islands%20II/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u54c8\u5e0c\u8868`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0711](https://leetcode.com/problems/number-of-distinct-islands-ii)", "[Number of Distinct Islands II](/solution/0700-0799/0711.Number%20of%20Distinct%20Islands%20II/README_EN.md)", "`Depth-first Search`,`Hash Table`", "Hard", "\ud83d\udd12"]}, {"question_id": "0699", "frontend_question_id": "0699", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/falling-squares", "url_en": "https://leetcode.com/problems/falling-squares", "relative_path_cn": "/solution/0600-0699/0699.Falling%20Squares/README.md", "relative_path_en": "/solution/0600-0699/0699.Falling%20Squares/README_EN.md", "title_cn": "\u6389\u843d\u7684\u65b9\u5757", "title_en": "Falling Squares", "question_title_slug": "falling-squares", "content_en": "

    There are several squares being dropped onto the X-axis of a 2D plane.

    \n\n

    You are given a 2D integer array positions where positions[i] = [lefti, sideLengthi] represents the ith square with a side length of sideLengthi that is dropped with its left edge aligned with X-coordinate lefti.

    \n\n

    Each square is dropped one at a time from a height above any landed squares. It then falls downward (negative Y direction) until it either lands on the top side of another square or on the X-axis. A square brushing the left/right side of another square does not count as landing on it. Once it lands, it freezes in place and cannot be moved.

    \n\n

    After each square is dropped, you must record the height of the current tallest stack of squares.

    \n\n

    Return an integer array ans where ans[i] represents the height described above after dropping the ith square.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: positions = [[1,2],[2,3],[6,1]]\nOutput: [2,5,5]\nExplanation:\nAfter the first drop, the tallest stack is square 1 with a height of 2.\nAfter the second drop, the tallest stack is squares 1 and 2 with a height of 5.\nAfter the third drop, the tallest stack is still squares 1 and 2 with a height of 5.\nThus, we return an answer of [2, 5, 5].\n
    \n\n

    Example 2:

    \n\n
    \nInput: positions = [[100,100],[200,100]]\nOutput: [100,100]\nExplanation:\nAfter the first drop, the tallest stack is square 1 with a height of 100.\nAfter the second drop, the tallest stack is either square 1 or square 2, both with heights of 100.\nThus, we return an answer of [100, 100].\nNote that square 2 only brushes the right side of square 1, which does not count as landing on it.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= positions.length <= 1000
    • \n\t
    • 1 <= lefti <= 108
    • \n\t
    • 1 <= sideLengthi <= 106
    • \n
    \n", "content_cn": "

    \u5728\u65e0\u9650\u957f\u7684\u6570\u8f74\uff08\u5373 x \u8f74\uff09\u4e0a\uff0c\u6211\u4eec\u6839\u636e\u7ed9\u5b9a\u7684\u987a\u5e8f\u653e\u7f6e\u5bf9\u5e94\u7684\u6b63\u65b9\u5f62\u65b9\u5757\u3002

    \n\n

    \u7b2c i \u4e2a\u6389\u843d\u7684\u65b9\u5757\uff08positions[i] = (left, side_length)\uff09\u662f\u6b63\u65b9\u5f62\uff0c\u5176\u4e2d left \u8868\u793a\u8be5\u65b9\u5757\u6700\u5de6\u8fb9\u7684\u70b9\u4f4d\u7f6e(positions[i][0])\uff0cside_length \u8868\u793a\u8be5\u65b9\u5757\u7684\u8fb9\u957f(positions[i][1])\u3002

    \n\n

    \u6bcf\u4e2a\u65b9\u5757\u7684\u5e95\u90e8\u8fb9\u7f18\u5e73\u884c\u4e8e\u6570\u8f74\uff08\u5373 x \u8f74\uff09\uff0c\u5e76\u4e14\u4ece\u4e00\u4e2a\u6bd4\u76ee\u524d\u6240\u6709\u7684\u843d\u5730\u65b9\u5757\u66f4\u9ad8\u7684\u9ad8\u5ea6\u6389\u843d\u800c\u4e0b\u3002\u5728\u4e0a\u4e00\u4e2a\u65b9\u5757\u7ed3\u675f\u6389\u843d\uff0c\u5e76\u4fdd\u6301\u9759\u6b62\u540e\uff0c\u624d\u5f00\u59cb\u6389\u843d\u65b0\u65b9\u5757\u3002

    \n\n

    \u65b9\u5757\u7684\u5e95\u8fb9\u5177\u6709\u975e\u5e38\u5927\u7684\u7c98\u6027\uff0c\u5e76\u5c06\u4fdd\u6301\u56fa\u5b9a\u5728\u5b83\u4eec\u6240\u63a5\u89e6\u7684\u4efb\u4f55\u957f\u5ea6\u8868\u9762\u4e0a\uff08\u65e0\u8bba\u662f\u6570\u8f74\u8fd8\u662f\u5176\u4ed6\u65b9\u5757\uff09\u3002\u90bb\u63a5\u6389\u843d\u7684\u8fb9\u4e0d\u4f1a\u8fc7\u65e9\u5730\u7c98\u5408\u5728\u4e00\u8d77\uff0c\u56e0\u4e3a\u53ea\u6709\u5e95\u8fb9\u624d\u5177\u6709\u7c98\u6027\u3002

    \n\n

     

    \n\n

    \u8fd4\u56de\u4e00\u4e2a\u5806\u53e0\u9ad8\u5ea6\u5217\u8868 ans \u3002\u6bcf\u4e00\u4e2a\u5806\u53e0\u9ad8\u5ea6 ans[i] \u8868\u793a\u5728\u901a\u8fc7 positions[0], positions[1], ..., positions[i] \u8868\u793a\u7684\u65b9\u5757\u6389\u843d\u7ed3\u675f\u540e\uff0c\u76ee\u524d\u6240\u6709\u5df2\u7ecf\u843d\u7a33\u7684\u65b9\u5757\u5806\u53e0\u7684\u6700\u9ad8\u9ad8\u5ea6\u3002

    \n\n

     

    \n\n

     

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: [[1, 2], [2, 3], [6, 1]]\n\u8f93\u51fa: [2, 5, 5]\n\u89e3\u91ca:\n\n\u7b2c\u4e00\u4e2a\u65b9\u5757 positions[0] = [1, 2] \u6389\u843d\uff1a\n_aa\n_aa\n-------\n\u65b9\u5757\u6700\u5927\u9ad8\u5ea6\u4e3a 2 \u3002\n\n\u7b2c\u4e8c\u4e2a\u65b9\u5757 positions[1] = [2, 3] \u6389\u843d\uff1a\n__aaa\n__aaa\n__aaa\n_aa__\n_aa__\n--------------\n\u65b9\u5757\u6700\u5927\u9ad8\u5ea6\u4e3a5\u3002\n\u5927\u7684\u65b9\u5757\u4fdd\u6301\u5728\u8f83\u5c0f\u7684\u65b9\u5757\u7684\u9876\u90e8\uff0c\u4e0d\u8bba\u5b83\u7684\u91cd\u5fc3\u5728\u54ea\u91cc\uff0c\u56e0\u4e3a\u65b9\u5757\u7684\u5e95\u90e8\u8fb9\u7f18\u6709\u975e\u5e38\u5927\u7684\u7c98\u6027\u3002\n\n\u7b2c\u4e09\u4e2a\u65b9\u5757 positions[1] = [6, 1] \u6389\u843d\uff1a\n__aaa\n__aaa\n__aaa\n_aa\n_aa___a\n-------------- \n\u65b9\u5757\u6700\u5927\u9ad8\u5ea6\u4e3a5\u3002\n\n\u56e0\u6b64\uff0c\u6211\u4eec\u8fd4\u56de\u7ed3\u679c[2, 5, 5]\u3002\n
    \n\n

     

    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: [[100, 100], [200, 100]]\n\u8f93\u51fa: [100, 100]\n\u89e3\u91ca: \u76f8\u90bb\u7684\u65b9\u5757\u4e0d\u4f1a\u8fc7\u65e9\u5730\u5361\u4f4f\uff0c\u53ea\u6709\u5b83\u4eec\u7684\u5e95\u90e8\u8fb9\u7f18\u624d\u80fd\u7c98\u5728\u8868\u9762\u4e0a\u3002\n
    \n\n

     

    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    • 1 <= positions.length <= 1000.
    • \n\t
    • 1 <= positions[i][0] <= 10^8.
    • \n\t
    • 1 <= positions[i][1] <= 10^6.
    • \n
    \n\n

     

    \n", "tags_en": ["Segment Tree", "Ordered Map"], "tags_cn": ["\u7ebf\u6bb5\u6811"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector fallingSquares(vector>& positions) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List fallingSquares(int[][] positions) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def fallingSquares(self, positions):\n \"\"\"\n :type positions: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def fallingSquares(self, positions: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* fallingSquares(int** positions, int positionsSize, int* positionsColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList FallingSquares(int[][] positions) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} positions\n * @return {number[]}\n */\nvar fallingSquares = function(positions) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} positions\n# @return {Integer[]}\ndef falling_squares(positions)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func fallingSquares(_ positions: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func fallingSquares(positions [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def fallingSquares(positions: Array[Array[Int]]): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun fallingSquares(positions: Array): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn falling_squares(positions: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $positions\n * @return Integer[]\n */\n function fallingSquares($positions) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function fallingSquares(positions: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (falling-squares positions)\n (-> (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0699](https://leetcode-cn.com/problems/falling-squares)", "[\u6389\u843d\u7684\u65b9\u5757](/solution/0600-0699/0699.Falling%20Squares/README.md)", "`\u7ebf\u6bb5\u6811`", "\u56f0\u96be", ""], "md_table_row_en": ["[0699](https://leetcode.com/problems/falling-squares)", "[Falling Squares](/solution/0600-0699/0699.Falling%20Squares/README_EN.md)", "`Segment Tree`,`Ordered Map`", "Hard", ""]}, {"question_id": "0698", "frontend_question_id": "0698", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/partition-to-k-equal-sum-subsets", "url_en": "https://leetcode.com/problems/partition-to-k-equal-sum-subsets", "relative_path_cn": "/solution/0600-0699/0698.Partition%20to%20K%20Equal%20Sum%20Subsets/README.md", "relative_path_en": "/solution/0600-0699/0698.Partition%20to%20K%20Equal%20Sum%20Subsets/README_EN.md", "title_cn": "\u5212\u5206\u4e3ak\u4e2a\u76f8\u7b49\u7684\u5b50\u96c6", "title_en": "Partition to K Equal Sum Subsets", "question_title_slug": "partition-to-k-equal-sum-subsets", "content_en": "

    Given an integer array nums and an integer k, return true if it is possible to divide this array into k non-empty subsets whose sums are all equal.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [4,3,2,3,5,2,1], k = 4\nOutput: true\nExplanation: It's possible to divide it into 4 subsets (5), (1, 4), (2,3), (2,3) with equal sums.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,2,3,4], k = 3\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= k <= nums.length <= 16
    • \n\t
    • 1 <= nums[i] <= 104
    • \n\t
    • The frequency of each element is in the range [1, 4].
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4  nums \u548c\u4e00\u4e2a\u6b63\u6574\u6570 k\uff0c\u627e\u51fa\u662f\u5426\u6709\u53ef\u80fd\u628a\u8fd9\u4e2a\u6570\u7ec4\u5206\u6210 k \u4e2a\u975e\u7a7a\u5b50\u96c6\uff0c\u5176\u603b\u548c\u90fd\u76f8\u7b49\u3002

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a nums = [4, 3, 2, 3, 5, 2, 1], k = 4\n\u8f93\u51fa\uff1a True\n\u8bf4\u660e\uff1a \u6709\u53ef\u80fd\u5c06\u5176\u5206\u6210 4 \u4e2a\u5b50\u96c6\uff085\uff09\uff0c\uff081,4\uff09\uff0c\uff082,3\uff09\uff0c\uff082,3\uff09\u7b49\u4e8e\u603b\u548c\u3002
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= k <= len(nums) <= 16
    • \n\t
    • 0 < nums[i] < 10000
    • \n
    \n", "tags_en": ["Recursion", "Dynamic Programming"], "tags_cn": ["\u9012\u5f52", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canPartitionKSubsets(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canPartitionKSubsets(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canPartitionKSubsets(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canPartitionKSubsets(self, nums: List[int], k: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canPartitionKSubsets(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanPartitionKSubsets(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {boolean}\n */\nvar canPartitionKSubsets = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Boolean}\ndef can_partition_k_subsets(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canPartitionKSubsets(_ nums: [Int], _ k: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canPartitionKSubsets(nums []int, k int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canPartitionKSubsets(nums: Array[Int], k: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canPartitionKSubsets(nums: IntArray, k: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_partition_k_subsets(nums: Vec, k: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Boolean\n */\n function canPartitionKSubsets($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canPartitionKSubsets(nums: number[], k: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-partition-k-subsets nums k)\n (-> (listof exact-integer?) exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0698](https://leetcode-cn.com/problems/partition-to-k-equal-sum-subsets)", "[\u5212\u5206\u4e3ak\u4e2a\u76f8\u7b49\u7684\u5b50\u96c6](/solution/0600-0699/0698.Partition%20to%20K%20Equal%20Sum%20Subsets/README.md)", "`\u9012\u5f52`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0698](https://leetcode.com/problems/partition-to-k-equal-sum-subsets)", "[Partition to K Equal Sum Subsets](/solution/0600-0699/0698.Partition%20to%20K%20Equal%20Sum%20Subsets/README_EN.md)", "`Recursion`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0697", "frontend_question_id": "0697", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/degree-of-an-array", "url_en": "https://leetcode.com/problems/degree-of-an-array", "relative_path_cn": "/solution/0600-0699/0697.Degree%20of%20an%20Array/README.md", "relative_path_en": "/solution/0600-0699/0697.Degree%20of%20an%20Array/README_EN.md", "title_cn": "\u6570\u7ec4\u7684\u5ea6", "title_en": "Degree of an Array", "question_title_slug": "degree-of-an-array", "content_en": "

    Given a non-empty array of non-negative integers nums, the degree of this array is defined as the maximum frequency of any one of its elements.

    \n\n

    Your task is to find the smallest possible length of a (contiguous) subarray of nums, that has the same degree as nums.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,2,3,1]\nOutput: 2\nExplanation: \nThe input array has a degree of 2 because both elements 1 and 2 appear twice.\nOf the subarrays that have the same degree:\n[1, 2, 2, 3, 1], [1, 2, 2, 3], [2, 2, 3, 1], [1, 2, 2], [2, 2, 3], [2, 2]\nThe shortest length is 2. So return 2.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,2,2,3,1,4,2]\nOutput: 6\nExplanation: \nThe degree is 3 because the element 2 is repeated 3 times.\nSo [2,2,3,1,4,2] is the shortest subarray, therefore returning 6.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • nums.length will be between 1 and 50,000.
    • \n\t
    • nums[i] will be an integer between 0 and 49,999.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u7a7a\u4e14\u53ea\u5305\u542b\u975e\u8d1f\u6570\u7684\u6574\u6570\u6570\u7ec4\u00a0nums\uff0c\u6570\u7ec4\u7684\u5ea6\u7684\u5b9a\u4e49\u662f\u6307\u6570\u7ec4\u91cc\u4efb\u4e00\u5143\u7d20\u51fa\u73b0\u9891\u6570\u7684\u6700\u5927\u503c\u3002

    \n\n

    \u4f60\u7684\u4efb\u52a1\u662f\u5728 nums \u4e2d\u627e\u5230\u4e0e\u00a0nums\u00a0\u62e5\u6709\u76f8\u540c\u5927\u5c0f\u7684\u5ea6\u7684\u6700\u77ed\u8fde\u7eed\u5b50\u6570\u7ec4\uff0c\u8fd4\u56de\u5176\u957f\u5ea6\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[1, 2, 2, 3, 1]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n\u8f93\u5165\u6570\u7ec4\u7684\u5ea6\u662f2\uff0c\u56e0\u4e3a\u5143\u7d201\u548c2\u7684\u51fa\u73b0\u9891\u6570\u6700\u5927\uff0c\u5747\u4e3a2.\n\u8fde\u7eed\u5b50\u6570\u7ec4\u91cc\u9762\u62e5\u6709\u76f8\u540c\u5ea6\u7684\u6709\u5982\u4e0b\u6240\u793a:\n[1, 2, 2, 3, 1], [1, 2, 2, 3], [2, 2, 3, 1], [1, 2, 2], [2, 2, 3], [2, 2]\n\u6700\u77ed\u8fde\u7eed\u5b50\u6570\u7ec4[2, 2]\u7684\u957f\u5ea6\u4e3a2\uff0c\u6240\u4ee5\u8fd4\u56de2.\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[1,2,2,3,1,4,2]\n\u8f93\u51fa\uff1a6\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • nums.length\u00a0\u57281\u5230 50,000 \u533a\u95f4\u8303\u56f4\u5185\u3002
    • \n\t
    • nums[i]\u00a0\u662f\u4e00\u4e2a\u5728 0 \u5230 49,999 \u8303\u56f4\u5185\u7684\u6574\u6570\u3002
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findShortestSubArray(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findShortestSubArray(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findShortestSubArray(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findShortestSubArray(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findShortestSubArray(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindShortestSubArray(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar findShortestSubArray = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef find_shortest_sub_array(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findShortestSubArray(_ nums: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findShortestSubArray(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findShortestSubArray(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findShortestSubArray(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_shortest_sub_array(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function findShortestSubArray($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findShortestSubArray(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-shortest-sub-array nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0697](https://leetcode-cn.com/problems/degree-of-an-array)", "[\u6570\u7ec4\u7684\u5ea6](/solution/0600-0699/0697.Degree%20of%20an%20Array/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0697](https://leetcode.com/problems/degree-of-an-array)", "[Degree of an Array](/solution/0600-0699/0697.Degree%20of%20an%20Array/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0696", "frontend_question_id": "0696", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-binary-substrings", "url_en": "https://leetcode.com/problems/count-binary-substrings", "relative_path_cn": "/solution/0600-0699/0696.Count%20Binary%20Substrings/README.md", "relative_path_en": "/solution/0600-0699/0696.Count%20Binary%20Substrings/README_EN.md", "title_cn": "\u8ba1\u6570\u4e8c\u8fdb\u5236\u5b50\u4e32", "title_en": "Count Binary Substrings", "question_title_slug": "count-binary-substrings", "content_en": "

    Give a binary string s, return the number of non-empty substrings that have the same number of 0's and 1's, and all the 0's and all the 1's in these substrings are grouped consecutively.

    \n\n

    Substrings that occur multiple times are counted the number of times they occur.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "00110011"\nOutput: 6\nExplanation: There are 6 substrings that have equal number of consecutive 1's and 0's: "0011", "01", "1100", "10", "0011", and "01".\nNotice that some of these substrings repeat and are counted the number of times they occur.\nAlso, "00110011" is not a valid substring because all the 0's (and 1's) are not grouped together.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "10101"\nOutput: 4\nExplanation: There are 4 substrings: "10", "01", "10", "01" that have equal number of consecutive 1's and 0's.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 105
    • \n\t
    • s[i] is either '0' or '1'.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\u00a0s\uff0c\u8ba1\u7b97\u5177\u6709\u76f8\u540c\u6570\u91cf 0 \u548c 1 \u7684\u975e\u7a7a\uff08\u8fde\u7eed\uff09\u5b50\u5b57\u7b26\u4e32\u7684\u6570\u91cf\uff0c\u5e76\u4e14\u8fd9\u4e9b\u5b50\u5b57\u7b26\u4e32\u4e2d\u7684\u6240\u6709 0 \u548c\u6240\u6709 1 \u90fd\u662f\u8fde\u7eed\u7684\u3002

    \n\n

    \u91cd\u590d\u51fa\u73b0\u7684\u5b50\u4e32\u8981\u8ba1\u7b97\u5b83\u4eec\u51fa\u73b0\u7684\u6b21\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1 :

    \n\n
    \n\u8f93\u5165: \"00110011\"\n\u8f93\u51fa: 6\n\u89e3\u91ca: \u67096\u4e2a\u5b50\u4e32\u5177\u6709\u76f8\u540c\u6570\u91cf\u7684\u8fde\u7eed1\u548c0\uff1a\u201c0011\u201d\uff0c\u201c01\u201d\uff0c\u201c1100\u201d\uff0c\u201c10\u201d\uff0c\u201c0011\u201d \u548c \u201c01\u201d\u3002\n\n\u8bf7\u6ce8\u610f\uff0c\u4e00\u4e9b\u91cd\u590d\u51fa\u73b0\u7684\u5b50\u4e32\u8981\u8ba1\u7b97\u5b83\u4eec\u51fa\u73b0\u7684\u6b21\u6570\u3002\n\n\u53e6\u5916\uff0c\u201c00110011\u201d\u4e0d\u662f\u6709\u6548\u7684\u5b50\u4e32\uff0c\u56e0\u4e3a\u6240\u6709\u76840\uff08\u548c1\uff09\u6ca1\u6709\u7ec4\u5408\u5728\u4e00\u8d77\u3002\n
    \n\n

    \u793a\u4f8b 2 :

    \n\n
    \n\u8f93\u5165: \"10101\"\n\u8f93\u51fa: 4\n\u89e3\u91ca: \u67094\u4e2a\u5b50\u4e32\uff1a\u201c10\u201d\uff0c\u201c01\u201d\uff0c\u201c10\u201d\uff0c\u201c01\u201d\uff0c\u5b83\u4eec\u5177\u6709\u76f8\u540c\u6570\u91cf\u7684\u8fde\u7eed1\u548c0\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • s.length\u00a0\u57281\u523050,000\u4e4b\u95f4\u3002
    • \n\t
    • s\u00a0\u53ea\u5305\u542b\u201c0\u201d\u6216\u201c1\u201d\u5b57\u7b26\u3002
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countBinarySubstrings(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countBinarySubstrings(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countBinarySubstrings(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countBinarySubstrings(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countBinarySubstrings(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountBinarySubstrings(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar countBinarySubstrings = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef count_binary_substrings(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countBinarySubstrings(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countBinarySubstrings(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countBinarySubstrings(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countBinarySubstrings(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_binary_substrings(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function countBinarySubstrings($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countBinarySubstrings(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-binary-substrings s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0696](https://leetcode-cn.com/problems/count-binary-substrings)", "[\u8ba1\u6570\u4e8c\u8fdb\u5236\u5b50\u4e32](/solution/0600-0699/0696.Count%20Binary%20Substrings/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0696](https://leetcode.com/problems/count-binary-substrings)", "[Count Binary Substrings](/solution/0600-0699/0696.Count%20Binary%20Substrings/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "0695", "frontend_question_id": "0695", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/max-area-of-island", "url_en": "https://leetcode.com/problems/max-area-of-island", "relative_path_cn": "/solution/0600-0699/0695.Max%20Area%20of%20Island/README.md", "relative_path_en": "/solution/0600-0699/0695.Max%20Area%20of%20Island/README_EN.md", "title_cn": "\u5c9b\u5c7f\u7684\u6700\u5927\u9762\u79ef", "title_en": "Max Area of Island", "question_title_slug": "max-area-of-island", "content_en": "

    You are given an m x n binary matrix grid. An island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrounded by water.

    \n\n

    The area of an island is the number of cells with a value 1 in the island.

    \n\n

    Return the maximum area of an island in grid. If there is no island, return 0.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: grid = [[0,0,1,0,0,0,0,1,0,0,0,0,0],[0,0,0,0,0,0,0,1,1,1,0,0,0],[0,1,1,0,1,0,0,0,0,0,0,0,0],[0,1,0,0,1,1,0,0,1,0,1,0,0],[0,1,0,0,1,1,0,0,1,1,1,0,0],[0,0,0,0,0,0,0,0,0,0,1,0,0],[0,0,0,0,0,0,0,1,1,1,0,0,0],[0,0,0,0,0,0,0,1,1,0,0,0,0]]\nOutput: 6\nExplanation: The answer is not 11, because the island must be connected 4-directionally.\n
    \n\n

    Example 2:

    \n\n
    \nInput: grid = [[0,0,0,0,0,0,0,0]]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= m, n <= 50
    • \n\t
    • grid[i][j] is either 0 or 1.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5305\u542b\u4e86\u4e00\u4e9b 0 \u548c 1 \u7684\u975e\u7a7a\u4e8c\u7ef4\u6570\u7ec4 grid \u3002

    \n\n

    \u4e00\u4e2a \u5c9b\u5c7f \u662f\u7531\u4e00\u4e9b\u76f8\u90bb\u7684 1 (\u4ee3\u8868\u571f\u5730) \u6784\u6210\u7684\u7ec4\u5408\uff0c\u8fd9\u91cc\u7684\u300c\u76f8\u90bb\u300d\u8981\u6c42\u4e24\u4e2a 1 \u5fc5\u987b\u5728\u6c34\u5e73\u6216\u8005\u7ad6\u76f4\u65b9\u5411\u4e0a\u76f8\u90bb\u3002\u4f60\u53ef\u4ee5\u5047\u8bbe grid \u7684\u56db\u4e2a\u8fb9\u7f18\u90fd\u88ab 0\uff08\u4ee3\u8868\u6c34\uff09\u5305\u56f4\u7740\u3002

    \n\n

    \u627e\u5230\u7ed9\u5b9a\u7684\u4e8c\u7ef4\u6570\u7ec4\u4e2d\u6700\u5927\u7684\u5c9b\u5c7f\u9762\u79ef\u3002(\u5982\u679c\u6ca1\u6709\u5c9b\u5c7f\uff0c\u5219\u8fd4\u56de\u9762\u79ef\u4e3a 0 \u3002)

    \n\n

     

    \n\n

    \u793a\u4f8b 1:

    \n\n
    [[0,0,1,0,0,0,0,1,0,0,0,0,0],\n [0,0,0,0,0,0,0,1,1,1,0,0,0],\n [0,1,1,0,1,0,0,0,0,0,0,0,0],\n [0,1,0,0,1,1,0,0,1,0,1,0,0],\n [0,1,0,0,1,1,0,0,1,1,1,0,0],\n [0,0,0,0,0,0,0,0,0,0,1,0,0],\n [0,0,0,0,0,0,0,1,1,1,0,0,0],\n [0,0,0,0,0,0,0,1,1,0,0,0,0]]\n
    \n\n

    \u5bf9\u4e8e\u4e0a\u9762\u8fd9\u4e2a\u7ed9\u5b9a\u77e9\u9635\u5e94\u8fd4\u56de 6\u3002\u6ce8\u610f\u7b54\u6848\u4e0d\u5e94\u8be5\u662f 11 \uff0c\u56e0\u4e3a\u5c9b\u5c7f\u53ea\u80fd\u5305\u542b\u6c34\u5e73\u6216\u5782\u76f4\u7684\u56db\u4e2a\u65b9\u5411\u7684 1 \u3002

    \n\n

    \u793a\u4f8b 2:

    \n\n
    [[0,0,0,0,0,0,0,0]]
    \n\n

    \u5bf9\u4e8e\u4e0a\u9762\u8fd9\u4e2a\u7ed9\u5b9a\u7684\u77e9\u9635, \u8fd4\u56de 0\u3002

    \n\n

     

    \n\n

    \u6ce8\u610f: \u7ed9\u5b9a\u7684\u77e9\u9635grid \u7684\u957f\u5ea6\u548c\u5bbd\u5ea6\u90fd\u4e0d\u8d85\u8fc7 50\u3002

    \n", "tags_en": ["Depth-first Search", "Array"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxAreaOfIsland(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxAreaOfIsland(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxAreaOfIsland(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxAreaOfIsland(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxAreaOfIsland(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxAreaOfIsland(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar maxAreaOfIsland = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef max_area_of_island(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxAreaOfIsland(_ grid: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxAreaOfIsland(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxAreaOfIsland(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxAreaOfIsland(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_area_of_island(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function maxAreaOfIsland($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxAreaOfIsland(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-area-of-island grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0695](https://leetcode-cn.com/problems/max-area-of-island)", "[\u5c9b\u5c7f\u7684\u6700\u5927\u9762\u79ef](/solution/0600-0699/0695.Max%20Area%20of%20Island/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0695](https://leetcode.com/problems/max-area-of-island)", "[Max Area of Island](/solution/0600-0699/0695.Max%20Area%20of%20Island/README_EN.md)", "`Depth-first Search`,`Array`", "Medium", ""]}, {"question_id": "0694", "frontend_question_id": "0694", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/number-of-distinct-islands", "url_en": "https://leetcode.com/problems/number-of-distinct-islands", "relative_path_cn": "/solution/0600-0699/0694.Number%20of%20Distinct%20Islands/README.md", "relative_path_en": "/solution/0600-0699/0694.Number%20of%20Distinct%20Islands/README_EN.md", "title_cn": "\u4e0d\u540c\u5c9b\u5c7f\u7684\u6570\u91cf", "title_en": "Number of Distinct Islands", "question_title_slug": "number-of-distinct-islands", "content_en": "

    You are given an m x n binary matrix grid. An island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrounded by water.

    \n\n

    An island is considered to be the same as another if and only if one island can be translated (and not rotated or reflected) to equal the other.

    \n\n

    Return the number of distinct islands.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: grid = [[1,1,0,0,0],[1,1,0,0,0],[0,0,0,1,1],[0,0,0,1,1]]\nOutput: 1\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: grid = [[1,1,0,1,1],[1,0,0,0,0],[0,0,0,0,1],[1,1,0,1,1]]\nOutput: 3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= m, n <= 50
    • \n\t
    • grid[i][j] is either 0 or 1.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u7a7a 01 \u4e8c\u7ef4\u6570\u7ec4\u8868\u793a\u7684\u7f51\u683c\uff0c\u4e00\u4e2a\u5c9b\u5c7f\u7531\u56db\u8fde\u901a\uff08\u4e0a\u3001\u4e0b\u3001\u5de6\u3001\u53f3\u56db\u4e2a\u65b9\u5411\uff09\u7684 1 \u7ec4\u6210\uff0c\u4f60\u53ef\u4ee5\u8ba4\u4e3a\u7f51\u683c\u7684\u56db\u5468\u88ab\u6d77\u6c34\u5305\u56f4\u3002

    \n\n

    \u8bf7\u4f60\u8ba1\u7b97\u8fd9\u4e2a\u7f51\u683c\u4e2d\u5171\u6709\u591a\u5c11\u4e2a\u5f62\u72b6\u4e0d\u540c\u7684\u5c9b\u5c7f\u3002\u4e24\u4e2a\u5c9b\u5c7f\u88ab\u8ba4\u4e3a\u662f\u76f8\u540c\u7684\uff0c\u5f53\u4e14\u4ec5\u5f53\u4e00\u4e2a\u5c9b\u5c7f\u53ef\u4ee5\u901a\u8fc7\u5e73\u79fb\u53d8\u6362\uff08\u4e0d\u53ef\u4ee5\u65cb\u8f6c\u3001\u7ffb\u8f6c\uff09\u548c\u53e6\u4e00\u4e2a\u5c9b\u5c7f\u91cd\u5408\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    11000\n11000\n00011\n00011\n
    \n\n

    \u7ed9\u5b9a\u4e0a\u56fe\uff0c\u8fd4\u56de\u7ed3\u679c 1 \u3002

    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    11011\n10000\n00001\n11011
    \n\n

    \u7ed9\u5b9a\u4e0a\u56fe\uff0c\u8fd4\u56de\u7ed3\u679c 3 \u3002
    \n
    \n\u6ce8\u610f\uff1a

    \n\n
    11\n1\n
    \n\n

    \u548c

    \n\n
     1\n11\n
    \n\n

    \u662f\u4e0d\u540c\u7684\u5c9b\u5c7f\uff0c\u56e0\u4e3a\u6211\u4eec\u4e0d\u8003\u8651\u65cb\u8f6c\u3001\u7ffb\u8f6c\u64cd\u4f5c\u3002

    \n\n

     

    \n\n

    \u63d0\u793a\uff1a\u4e8c\u7ef4\u6570\u7ec4\u6bcf\u7ef4\u7684\u5927\u5c0f\u90fd\u4e0d\u4f1a\u8d85\u8fc7 50 \u3002

    \n", "tags_en": ["Depth-first Search", "Breadth-first Search", "Hash Table"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numDistinctIslands(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numDistinctIslands(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numDistinctIslands(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numDistinctIslands(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numDistinctIslands(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumDistinctIslands(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar numDistinctIslands = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef num_distinct_islands(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numDistinctIslands(_ grid: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numDistinctIslands(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numDistinctIslands(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numDistinctIslands(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_distinct_islands(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function numDistinctIslands($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numDistinctIslands(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-distinct-islands grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0694](https://leetcode-cn.com/problems/number-of-distinct-islands)", "[\u4e0d\u540c\u5c9b\u5c7f\u7684\u6570\u91cf](/solution/0600-0699/0694.Number%20of%20Distinct%20Islands/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0694](https://leetcode.com/problems/number-of-distinct-islands)", "[Number of Distinct Islands](/solution/0600-0699/0694.Number%20of%20Distinct%20Islands/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`,`Hash Table`", "Medium", "\ud83d\udd12"]}, {"question_id": "0693", "frontend_question_id": "0693", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/binary-number-with-alternating-bits", "url_en": "https://leetcode.com/problems/binary-number-with-alternating-bits", "relative_path_cn": "/solution/0600-0699/0693.Binary%20Number%20with%20Alternating%20Bits/README.md", "relative_path_en": "/solution/0600-0699/0693.Binary%20Number%20with%20Alternating%20Bits/README_EN.md", "title_cn": "\u4ea4\u66ff\u4f4d\u4e8c\u8fdb\u5236\u6570", "title_en": "Binary Number with Alternating Bits", "question_title_slug": "binary-number-with-alternating-bits", "content_en": "

    Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will always have different values.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 5\nOutput: true\nExplanation: The binary representation of 5 is: 101\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 7\nOutput: false\nExplanation: The binary representation of 7 is: 111.
    \n\n

    Example 3:

    \n\n
    \nInput: n = 11\nOutput: false\nExplanation: The binary representation of 11 is: 1011.
    \n\n

    Example 4:

    \n\n
    \nInput: n = 10\nOutput: true\nExplanation: The binary representation of 10 is: 1010.
    \n\n

    Example 5:

    \n\n
    \nInput: n = 3\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 231 - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6b63\u6574\u6570\uff0c\u68c0\u67e5\u5b83\u7684\u4e8c\u8fdb\u5236\u8868\u793a\u662f\u5426\u603b\u662f 0\u30011 \u4ea4\u66ff\u51fa\u73b0\uff1a\u6362\u53e5\u8bdd\u8bf4\uff0c\u5c31\u662f\u4e8c\u8fdb\u5236\u8868\u793a\u4e2d\u76f8\u90bb\u4e24\u4f4d\u7684\u6570\u5b57\u6c38\u4e0d\u76f8\u540c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 5\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a5 \u7684\u4e8c\u8fdb\u5236\u8868\u793a\u662f\uff1a101\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 7\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a7 \u7684\u4e8c\u8fdb\u5236\u8868\u793a\u662f\uff1a111.
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 11\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a11 \u7684\u4e8c\u8fdb\u5236\u8868\u793a\u662f\uff1a1011.
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 10\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a10 \u7684\u4e8c\u8fdb\u5236\u8868\u793a\u662f\uff1a1010.
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 3\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 231 - 1
    • \n
    \n", "tags_en": ["Bit Manipulation"], "tags_cn": ["\u4f4d\u8fd0\u7b97"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool hasAlternatingBits(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean hasAlternatingBits(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def hasAlternatingBits(self, n):\n \"\"\"\n :type n: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def hasAlternatingBits(self, n: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool hasAlternatingBits(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool HasAlternatingBits(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {boolean}\n */\nvar hasAlternatingBits = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Boolean}\ndef has_alternating_bits(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func hasAlternatingBits(_ n: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func hasAlternatingBits(n int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def hasAlternatingBits(n: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun hasAlternatingBits(n: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn has_alternating_bits(n: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Boolean\n */\n function hasAlternatingBits($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function hasAlternatingBits(n: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (has-alternating-bits n)\n (-> exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0693](https://leetcode-cn.com/problems/binary-number-with-alternating-bits)", "[\u4ea4\u66ff\u4f4d\u4e8c\u8fdb\u5236\u6570](/solution/0600-0699/0693.Binary%20Number%20with%20Alternating%20Bits/README.md)", "`\u4f4d\u8fd0\u7b97`", "\u7b80\u5355", ""], "md_table_row_en": ["[0693](https://leetcode.com/problems/binary-number-with-alternating-bits)", "[Binary Number with Alternating Bits](/solution/0600-0699/0693.Binary%20Number%20with%20Alternating%20Bits/README_EN.md)", "`Bit Manipulation`", "Easy", ""]}, {"question_id": "0692", "frontend_question_id": "0692", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/top-k-frequent-words", "url_en": "https://leetcode.com/problems/top-k-frequent-words", "relative_path_cn": "/solution/0600-0699/0692.Top%20K%20Frequent%20Words/README.md", "relative_path_en": "/solution/0600-0699/0692.Top%20K%20Frequent%20Words/README_EN.md", "title_cn": "\u524dK\u4e2a\u9ad8\u9891\u5355\u8bcd", "title_en": "Top K Frequent Words", "question_title_slug": "top-k-frequent-words", "content_en": "

    Given a non-empty list of words, return the k most frequent elements.

    \r\n

    Your answer should be sorted by frequency from highest to lowest. If two words have the same frequency, then the word with the lower alphabetical order comes first.

    \r\n\r\n

    Example 1:
    \r\n

    \r\nInput: [\"i\", \"love\", \"leetcode\", \"i\", \"love\", \"coding\"], k = 2\r\nOutput: [\"i\", \"love\"]\r\nExplanation: \"i\" and \"love\" are the two most frequent words.\r\n    Note that \"i\" comes before \"love\" due to a lower alphabetical order.\r\n
    \r\n

    \r\n\r\n

    Example 2:
    \r\n

    \r\nInput: [\"the\", \"day\", \"is\", \"sunny\", \"the\", \"the\", \"the\", \"sunny\", \"is\", \"is\"], k = 4\r\nOutput: [\"the\", \"is\", \"sunny\", \"day\"]\r\nExplanation: \"the\", \"is\", \"sunny\" and \"day\" are the four most frequent words,\r\n    with the number of occurrence being 4, 3, 2 and 1 respectively.\r\n
    \r\n

    \r\n\r\n

    Note:
    \r\n

      \r\n
    1. You may assume k is always valid, 1 ≤ k ≤ number of unique elements.
    2. \r\n
    3. Input words contain only lowercase letters.
    4. \r\n
    \r\n

    \r\n\r\n

    Follow up:
    \r\n

      \r\n
    1. Try to solve it in O(n log k) time and O(n) extra space.
    2. \r\n
    \r\n

    ", "content_cn": "

    \u7ed9\u4e00\u975e\u7a7a\u7684\u5355\u8bcd\u5217\u8868\uff0c\u8fd4\u56de\u524d \u4e2a\u51fa\u73b0\u6b21\u6570\u6700\u591a\u7684\u5355\u8bcd\u3002

    \n\n

    \u8fd4\u56de\u7684\u7b54\u6848\u5e94\u8be5\u6309\u5355\u8bcd\u51fa\u73b0\u9891\u7387\u7531\u9ad8\u5230\u4f4e\u6392\u5e8f\u3002\u5982\u679c\u4e0d\u540c\u7684\u5355\u8bcd\u6709\u76f8\u540c\u51fa\u73b0\u9891\u7387\uff0c\u6309\u5b57\u6bcd\u987a\u5e8f\u6392\u5e8f\u3002

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165: ["i", "love", "leetcode", "i", "love", "coding"], k = 2\n\u8f93\u51fa: ["i", "love"]\n\u89e3\u6790: "i" \u548c "love" \u4e3a\u51fa\u73b0\u6b21\u6570\u6700\u591a\u7684\u4e24\u4e2a\u5355\u8bcd\uff0c\u5747\u4e3a2\u6b21\u3002\n    \u6ce8\u610f\uff0c\u6309\u5b57\u6bcd\u987a\u5e8f "i" \u5728 "love" \u4e4b\u524d\u3002\n
    \n\n

     

    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165: ["the", "day", "is", "sunny", "the", "the", "the", "sunny", "is", "is"], k = 4\n\u8f93\u51fa: ["the", "is", "sunny", "day"]\n\u89e3\u6790: "the", "is", "sunny" \u548c "day" \u662f\u51fa\u73b0\u6b21\u6570\u6700\u591a\u7684\u56db\u4e2a\u5355\u8bcd\uff0c\n    \u51fa\u73b0\u6b21\u6570\u4f9d\u6b21\u4e3a 4, 3, 2 \u548c 1 \u6b21\u3002\n
    \n\n

     

    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    1. \u5047\u5b9a k \u603b\u4e3a\u6709\u6548\u503c\uff0c 1 ≤ k ≤ \u96c6\u5408\u5143\u7d20\u6570\u3002
    2. \n\t
    3. \u8f93\u5165\u7684\u5355\u8bcd\u5747\u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210\u3002
    4. \n
    \n\n

     

    \n\n

    \u6269\u5c55\u7ec3\u4e60\uff1a

    \n\n
      \n\t
    1. \u5c1d\u8bd5\u4ee5 O(n log k) \u65f6\u95f4\u590d\u6742\u5ea6\u548c O(n) \u7a7a\u95f4\u590d\u6742\u5ea6\u89e3\u51b3\u3002
    2. \n
    \n", "tags_en": ["Heap", "Trie", "Hash Table"], "tags_cn": ["\u5806", "\u5b57\u5178\u6811", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector topKFrequent(vector& words, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List topKFrequent(String[] words, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def topKFrequent(self, words, k):\n \"\"\"\n :type words: List[str]\n :type k: int\n :rtype: List[str]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def topKFrequent(self, words: List[str], k: int) -> List[str]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** topKFrequent(char ** words, int wordsSize, int k, int* returnSize){\n\n}\n", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList TopKFrequent(string[] words, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @param {number} k\n * @return {string[]}\n */\nvar topKFrequent = function(words, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @param {Integer} k\n# @return {String[]}\ndef top_k_frequent(words, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func topKFrequent(_ words: [String], _ k: Int) -> [String] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func topKFrequent(words []string, k int) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def topKFrequent(words: Array[String], k: Int): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun topKFrequent(words: Array, k: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn top_k_frequent(words: Vec, k: i32) -> Vec {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @param Integer $k\n * @return String[]\n */\n function topKFrequent($words, $k) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function topKFrequent(words: string[], k: number): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (top-k-frequent words k)\n (-> (listof string?) exact-integer? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0692](https://leetcode-cn.com/problems/top-k-frequent-words)", "[\u524dK\u4e2a\u9ad8\u9891\u5355\u8bcd](/solution/0600-0699/0692.Top%20K%20Frequent%20Words/README.md)", "`\u5806`,`\u5b57\u5178\u6811`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0692](https://leetcode.com/problems/top-k-frequent-words)", "[Top K Frequent Words](/solution/0600-0699/0692.Top%20K%20Frequent%20Words/README_EN.md)", "`Heap`,`Trie`,`Hash Table`", "Medium", ""]}, {"question_id": "0691", "frontend_question_id": "0691", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/stickers-to-spell-word", "url_en": "https://leetcode.com/problems/stickers-to-spell-word", "relative_path_cn": "/solution/0600-0699/0691.Stickers%20to%20Spell%20Word/README.md", "relative_path_en": "/solution/0600-0699/0691.Stickers%20to%20Spell%20Word/README_EN.md", "title_cn": "\u8d34\u7eb8\u62fc\u8bcd", "title_en": "Stickers to Spell Word", "question_title_slug": "stickers-to-spell-word", "content_en": "

    We are given n different types of stickers. Each sticker has a lowercase English word on it.

    \n\n

    You would like to spell out the given string target by cutting individual letters from your collection of stickers and rearranging them. You can use each sticker more than once if you want, and you have infinite quantities of each sticker.

    \n\n

    Return the minimum number of stickers that you need to spell out target. If the task is impossible, return -1.

    \n\n

    Note: In all test cases, all words were chosen randomly from the 1000 most common US English words, and target was chosen as a concatenation of two random words.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: stickers = ["with","example","science"], target = "thehat"\nOutput: 3\nExplanation:\nWe can use 2 "with" stickers, and 1 "example" sticker.\nAfter cutting and rearrange the letters of those stickers, we can form the target "thehat".\nAlso, this is the minimum number of stickers necessary to form the target string.\n
    \n\n

    Example 2:

    \n\n
    \nInput: stickers = ["notice","possible"], target = "basicbasic"\nOutput: -1\nExplanation:\nWe cannot form the target "basicbasic" from cutting letters from the given stickers.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == stickers.length
    • \n\t
    • 1 <= n <= 50
    • \n\t
    • 1 <= stickers[i].length <= 10
    • \n\t
    • 1 <= target <= 15
    • \n\t
    • stickers[i] and target consist of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u6211\u4eec\u7ed9\u51fa\u4e86 N \u79cd\u4e0d\u540c\u7c7b\u578b\u7684\u8d34\u7eb8\u3002\u6bcf\u4e2a\u8d34\u7eb8\u4e0a\u90fd\u6709\u4e00\u4e2a\u5c0f\u5199\u7684\u82f1\u6587\u5355\u8bcd\u3002

    \n\n

    \u4f60\u5e0c\u671b\u4ece\u81ea\u5df1\u7684\u8d34\u7eb8\u96c6\u5408\u4e2d\u88c1\u526a\u5355\u4e2a\u5b57\u6bcd\u5e76\u91cd\u65b0\u6392\u5217\u5b83\u4eec\uff0c\u4ece\u800c\u62fc\u5199\u51fa\u7ed9\u5b9a\u7684\u76ee\u6807\u5b57\u7b26\u4e32 target\u3002

    \n\n

    \u5982\u679c\u4f60\u613f\u610f\u7684\u8bdd\uff0c\u4f60\u53ef\u4ee5\u4e0d\u6b62\u4e00\u6b21\u5730\u4f7f\u7528\u6bcf\u4e00\u5f20\u8d34\u7eb8\uff0c\u800c\u4e14\u6bcf\u4e00\u5f20\u8d34\u7eb8\u7684\u6570\u91cf\u90fd\u662f\u65e0\u9650\u7684\u3002

    \n\n

    \u62fc\u51fa\u76ee\u6807 target \u6240\u9700\u7684\u6700\u5c0f\u8d34\u7eb8\u6570\u91cf\u662f\u591a\u5c11\uff1f\u5982\u679c\u4efb\u52a1\u4e0d\u53ef\u80fd\uff0c\u5219\u8fd4\u56de -1\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \u8f93\u5165\uff1a

    \n\n
    ["with", "example", "science"], "thehat"\n
    \n\n

    \u8f93\u51fa\uff1a

    \n\n
    3\n
    \n\n

    \u89e3\u91ca\uff1a

    \n\n
    \u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 2 \u4e2a "with" \u8d34\u7eb8\uff0c\u548c 1 \u4e2a "example" \u8d34\u7eb8\u3002\n\u628a\u8d34\u7eb8\u4e0a\u7684\u5b57\u6bcd\u526a\u4e0b\u6765\u5e76\u91cd\u65b0\u6392\u5217\u540e\uff0c\u5c31\u53ef\u4ee5\u5f62\u6210\u76ee\u6807 “thehat“ \u4e86\u3002\n\u6b64\u5916\uff0c\u8fd9\u662f\u5f62\u6210\u76ee\u6807\u5b57\u7b26\u4e32\u6240\u9700\u7684\u6700\u5c0f\u8d34\u7eb8\u6570\u91cf\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \u8f93\u5165\uff1a

    \n\n
    ["notice", "possible"], "basicbasic"\n
    \n\n

    \u8f93\u51fa\uff1a

    \n\n
    -1\n
    \n\n

    \u89e3\u91ca\uff1a

    \n\n
    \u6211\u4eec\u4e0d\u80fd\u901a\u8fc7\u526a\u5207\u7ed9\u5b9a\u8d34\u7eb8\u7684\u5b57\u6bcd\u6765\u5f62\u6210\u76ee\u6807“basicbasic”\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • stickers \u957f\u5ea6\u8303\u56f4\u662f [1, 50]\u3002
    • \n\t
    • stickers \u7531\u5c0f\u5199\u82f1\u6587\u5355\u8bcd\u7ec4\u6210\uff08\u4e0d\u5e26\u6487\u53f7\uff09\u3002
    • \n\t
    • target \u7684\u957f\u5ea6\u5728 [1, 15] \u8303\u56f4\u5185\uff0c\u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210\u3002
    • \n\t
    • \u5728\u6240\u6709\u7684\u6d4b\u8bd5\u6848\u4f8b\u4e2d\uff0c\u6240\u6709\u7684\u5355\u8bcd\u90fd\u662f\u4ece 1000 \u4e2a\u6700\u5e38\u89c1\u7684\u7f8e\u56fd\u82f1\u8bed\u5355\u8bcd\u4e2d\u968f\u673a\u9009\u53d6\u7684\uff0c\u76ee\u6807\u662f\u4e24\u4e2a\u968f\u673a\u5355\u8bcd\u7684\u4e32\u8054\u3002
    • \n\t
    • \u65f6\u95f4\u9650\u5236\u53ef\u80fd\u6bd4\u5e73\u65f6\u66f4\u5177\u6311\u6218\u6027\u3002\u9884\u8ba1 50 \u4e2a\u8d34\u7eb8\u7684\u6d4b\u8bd5\u6848\u4f8b\u5e73\u5747\u53ef\u572835ms\u5185\u89e3\u51b3\u3002
    • \n
    \n\n

     

    \n", "tags_en": ["Dynamic Programming", "Backtracking"], "tags_cn": ["\u52a8\u6001\u89c4\u5212", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minStickers(vector& stickers, string target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minStickers(String[] stickers, String target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minStickers(self, stickers, target):\n \"\"\"\n :type stickers: List[str]\n :type target: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minStickers(self, stickers: List[str], target: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minStickers(char ** stickers, int stickersSize, char * target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinStickers(string[] stickers, string target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} stickers\n * @param {string} target\n * @return {number}\n */\nvar minStickers = function(stickers, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} stickers\n# @param {String} target\n# @return {Integer}\ndef min_stickers(stickers, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minStickers(_ stickers: [String], _ target: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minStickers(stickers []string, target string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minStickers(stickers: Array[String], target: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minStickers(stickers: Array, target: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_stickers(stickers: Vec, target: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $stickers\n * @param String $target\n * @return Integer\n */\n function minStickers($stickers, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minStickers(stickers: string[], target: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-stickers stickers target)\n (-> (listof string?) string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0691](https://leetcode-cn.com/problems/stickers-to-spell-word)", "[\u8d34\u7eb8\u62fc\u8bcd](/solution/0600-0699/0691.Stickers%20to%20Spell%20Word/README.md)", "`\u52a8\u6001\u89c4\u5212`,`\u56de\u6eaf\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[0691](https://leetcode.com/problems/stickers-to-spell-word)", "[Stickers to Spell Word](/solution/0600-0699/0691.Stickers%20to%20Spell%20Word/README_EN.md)", "`Dynamic Programming`,`Backtracking`", "Hard", ""]}, {"question_id": "0690", "frontend_question_id": "0690", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/employee-importance", "url_en": "https://leetcode.com/problems/employee-importance", "relative_path_cn": "/solution/0600-0699/0690.Employee%20Importance/README.md", "relative_path_en": "/solution/0600-0699/0690.Employee%20Importance/README_EN.md", "title_cn": "\u5458\u5de5\u7684\u91cd\u8981\u6027", "title_en": "Employee Importance", "question_title_slug": "employee-importance", "content_en": "

    You have a data structure of employee information, which includes the employee's unique id, their importance value, and their direct subordinates' id.

    \n\n

    You are given an array of employees employees where:

    \n\n
      \n\t
    • employees[i].id is the ID of the ith employee.
    • \n\t
    • employees[i].importance is the importance value of the ith employee.
    • \n\t
    • employees[i].subordinates is a list of the IDs of the subordinates of the ith employee.
    • \n
    \n\n

    Given an integer id that represents the ID of an employee, return the total importance value of this employee and all their subordinates.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: employees = [[1,5,[2,3]],[2,3,[]],[3,3,[]]], id = 1\nOutput: 11\nExplanation: Employee 1 has importance value 5, and he has two direct subordinates: employee 2 and employee 3.\nThey both have importance value 3.\nSo the total importance value of employee 1 is 5 + 3 + 3 = 11.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: employees = [[1,2,[5]],[5,-3,[]]], id = 5\nOutput: -3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= employees.length <= 2000
    • \n\t
    • 1 <= employees[i].id <= 2000
    • \n\t
    • All employees[i].id are unique.
    • \n\t
    • -100 <= employees[i].importance <= 100
    • \n\t
    • One employee has at most one direct leader and may have several subordinates.
    • \n\t
    • id is guaranteed to be a valid employee id.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4fdd\u5b58\u5458\u5de5\u4fe1\u606f\u7684\u6570\u636e\u7ed3\u6784\uff0c\u5b83\u5305\u542b\u4e86\u5458\u5de5 \u552f\u4e00\u7684 id \uff0c\u91cd\u8981\u5ea6\u00a0\u548c \u76f4\u7cfb\u4e0b\u5c5e\u7684 id \u3002

    \n\n

    \u6bd4\u5982\uff0c\u5458\u5de5 1 \u662f\u5458\u5de5 2 \u7684\u9886\u5bfc\uff0c\u5458\u5de5 2 \u662f\u5458\u5de5 3 \u7684\u9886\u5bfc\u3002\u4ed6\u4eec\u76f8\u5e94\u7684\u91cd\u8981\u5ea6\u4e3a 15 , 10 , 5 \u3002\u90a3\u4e48\u5458\u5de5 1 \u7684\u6570\u636e\u7ed3\u6784\u662f [1, 15, [2]] \uff0c\u5458\u5de5 2\u7684 \u6570\u636e\u7ed3\u6784\u662f [2, 10, [3]] \uff0c\u5458\u5de5 3 \u7684\u6570\u636e\u7ed3\u6784\u662f [3, 5, []] \u3002\u6ce8\u610f\u867d\u7136\u5458\u5de5 3 \u4e5f\u662f\u5458\u5de5 1 \u7684\u4e00\u4e2a\u4e0b\u5c5e\uff0c\u4f46\u662f\u7531\u4e8e \u5e76\u4e0d\u662f\u76f4\u7cfb \u4e0b\u5c5e\uff0c\u56e0\u6b64\u6ca1\u6709\u4f53\u73b0\u5728\u5458\u5de5 1 \u7684\u6570\u636e\u7ed3\u6784\u4e2d\u3002

    \n\n

    \u73b0\u5728\u8f93\u5165\u4e00\u4e2a\u516c\u53f8\u7684\u6240\u6709\u5458\u5de5\u4fe1\u606f\uff0c\u4ee5\u53ca\u5355\u4e2a\u5458\u5de5 id \uff0c\u8fd4\u56de\u8fd9\u4e2a\u5458\u5de5\u548c\u4ed6\u6240\u6709\u4e0b\u5c5e\u7684\u91cd\u8981\u5ea6\u4e4b\u548c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[[1, 5, [2, 3]], [2, 3, []], [3, 3, []]], 1\n\u8f93\u51fa\uff1a11\n\u89e3\u91ca\uff1a\n\u5458\u5de5 1 \u81ea\u8eab\u7684\u91cd\u8981\u5ea6\u662f 5 \uff0c\u4ed6\u6709\u4e24\u4e2a\u76f4\u7cfb\u4e0b\u5c5e 2 \u548c 3 \uff0c\u800c\u4e14 2 \u548c 3 \u7684\u91cd\u8981\u5ea6\u5747\u4e3a 3 \u3002\u56e0\u6b64\u5458\u5de5 1 \u7684\u603b\u91cd\u8981\u5ea6\u662f 5 + 3 + 3 = 11 \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u4e00\u4e2a\u5458\u5de5\u6700\u591a\u6709\u4e00\u4e2a \u76f4\u7cfb \u9886\u5bfc\uff0c\u4f46\u662f\u53ef\u4ee5\u6709\u591a\u4e2a \u76f4\u7cfb \u4e0b\u5c5e
    • \n\t
    • \u5458\u5de5\u6570\u91cf\u4e0d\u8d85\u8fc7 2000 \u3002
    • \n
    \n", "tags_en": ["Depth-first Search", "Breadth-first Search", "Hash Table"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n// Definition for Employee.\nclass Employee {\npublic:\n int id;\n int importance;\n vector subordinates;\n};\n*/\n\nclass Solution {\npublic:\n int getImportance(vector 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 subordinates;\n};\n*/\n\nclass Solution {\n public int getImportance(List 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 subordinates;\n}\n*/\n\nclass Solution {\n public int GetImportance(IList 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"}, {"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": "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}", "__typename": "CodeSnippetNode"}, {"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}", "__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}", "__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 = listOf()\n *\t}\n */\n\nclass Solution {\n fun getImportance(employees: List, id: Int): Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"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}", "__typename": "CodeSnippetNode"}, {"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};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0690](https://leetcode-cn.com/problems/employee-importance)", "[\u5458\u5de5\u7684\u91cd\u8981\u6027](/solution/0600-0699/0690.Employee%20Importance/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0690](https://leetcode.com/problems/employee-importance)", "[Employee Importance](/solution/0600-0699/0690.Employee%20Importance/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`,`Hash Table`", "Easy", ""]}, {"question_id": "0689", "frontend_question_id": "0689", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-sum-of-3-non-overlapping-subarrays", "url_en": "https://leetcode.com/problems/maximum-sum-of-3-non-overlapping-subarrays", "relative_path_cn": "/solution/0600-0699/0689.Maximum%20Sum%20of%203%20Non-Overlapping%20Subarrays/README.md", "relative_path_en": "/solution/0600-0699/0689.Maximum%20Sum%20of%203%20Non-Overlapping%20Subarrays/README_EN.md", "title_cn": "\u4e09\u4e2a\u65e0\u91cd\u53e0\u5b50\u6570\u7ec4\u7684\u6700\u5927\u548c", "title_en": "Maximum Sum of 3 Non-Overlapping Subarrays", "question_title_slug": "maximum-sum-of-3-non-overlapping-subarrays", "content_en": "

    Given an integer array nums and an integer k, find three non-overlapping subarrays of length k with maximum sum and return them.

    \n\n

    Return the result as a list of indices representing the starting position of each interval (0-indexed). If there are multiple answers, return the lexicographically smallest one.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,1,2,6,7,5,1], k = 2\nOutput: [0,3,5]\nExplanation: Subarrays [1, 2], [2, 6], [7, 5] correspond to the starting indices [0, 3, 5].\nWe could have also taken [2, 1], but an answer of [1, 3, 5] would be lexicographically larger.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,2,1,2,1,2,1,2,1], k = 2\nOutput: [0,2,4]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 2 * 104
    • \n\t
    • 1 <= nums[i] < 216
    • \n\t
    • 1 <= k <= floor(nums.length / 3)
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u6570\u7ec4 nums \u7531\u6b63\u6574\u6570\u7ec4\u6210\uff0c\u627e\u5230\u4e09\u4e2a\u4e92\u4e0d\u91cd\u53e0\u7684\u5b50\u6570\u7ec4\u7684\u6700\u5927\u548c\u3002

    \n\n

    \u6bcf\u4e2a\u5b50\u6570\u7ec4\u7684\u957f\u5ea6\u4e3ak\uff0c\u6211\u4eec\u8981\u4f7f\u8fd93*k\u4e2a\u9879\u7684\u548c\u6700\u5927\u5316\u3002

    \n\n

    \u8fd4\u56de\u6bcf\u4e2a\u533a\u95f4\u8d77\u59cb\u7d22\u5f15\u7684\u5217\u8868\uff08\u7d22\u5f15\u4ece 0 \u5f00\u59cb\uff09\u3002\u5982\u679c\u6709\u591a\u4e2a\u7ed3\u679c\uff0c\u8fd4\u56de\u5b57\u5178\u5e8f\u6700\u5c0f\u7684\u4e00\u4e2a\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \n\u8f93\u5165: [1,2,1,2,6,7,5,1], 2\n\u8f93\u51fa: [0, 3, 5]\n\u89e3\u91ca: \u5b50\u6570\u7ec4 [1, 2], [2, 6], [7, 5] \u5bf9\u5e94\u7684\u8d77\u59cb\u7d22\u5f15\u4e3a [0, 3, 5]\u3002\n\u6211\u4eec\u4e5f\u53ef\u4ee5\u53d6 [2, 1], \u4f46\u662f\u7ed3\u679c [1, 3, 5] \u5728\u5b57\u5178\u5e8f\u4e0a\u66f4\u5927\u3002\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    • nums.length\u7684\u8303\u56f4\u5728[1, 20000]\u4e4b\u95f4\u3002
    • \n\t
    • nums[i]\u7684\u8303\u56f4\u5728[1, 65535]\u4e4b\u95f4\u3002
    • \n\t
    • k\u7684\u8303\u56f4\u5728[1, floor(nums.length / 3)]\u4e4b\u95f4\u3002
    • \n
    \n", "tags_en": ["Array", "Dynamic Programming"], "tags_cn": ["\u6570\u7ec4", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector maxSumOfThreeSubarrays(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] maxSumOfThreeSubarrays(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxSumOfThreeSubarrays(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxSumOfThreeSubarrays(self, nums: List[int], k: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* maxSumOfThreeSubarrays(int* nums, int numsSize, int k, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] MaxSumOfThreeSubarrays(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number[]}\n */\nvar maxSumOfThreeSubarrays = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer[]}\ndef max_sum_of_three_subarrays(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxSumOfThreeSubarrays(_ nums: [Int], _ k: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxSumOfThreeSubarrays(nums []int, k int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxSumOfThreeSubarrays(nums: Array[Int], k: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxSumOfThreeSubarrays(nums: IntArray, k: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_sum_of_three_subarrays(nums: Vec, k: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer[]\n */\n function maxSumOfThreeSubarrays($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxSumOfThreeSubarrays(nums: number[], k: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-sum-of-three-subarrays nums k)\n (-> (listof exact-integer?) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0689](https://leetcode-cn.com/problems/maximum-sum-of-3-non-overlapping-subarrays)", "[\u4e09\u4e2a\u65e0\u91cd\u53e0\u5b50\u6570\u7ec4\u7684\u6700\u5927\u548c](/solution/0600-0699/0689.Maximum%20Sum%20of%203%20Non-Overlapping%20Subarrays/README.md)", "`\u6570\u7ec4`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0689](https://leetcode.com/problems/maximum-sum-of-3-non-overlapping-subarrays)", "[Maximum Sum of 3 Non-Overlapping Subarrays](/solution/0600-0699/0689.Maximum%20Sum%20of%203%20Non-Overlapping%20Subarrays/README_EN.md)", "`Array`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0688", "frontend_question_id": "0688", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/knight-probability-in-chessboard", "url_en": "https://leetcode.com/problems/knight-probability-in-chessboard", "relative_path_cn": "/solution/0600-0699/0688.Knight%20Probability%20in%20Chessboard/README.md", "relative_path_en": "/solution/0600-0699/0688.Knight%20Probability%20in%20Chessboard/README_EN.md", "title_cn": "\u201c\u9a6c\u201d\u5728\u68cb\u76d8\u4e0a\u7684\u6982\u7387", "title_en": "Knight Probability in Chessboard", "question_title_slug": "knight-probability-in-chessboard", "content_en": "

    On an n x n chessboard, a knight starts at the cell (row, column) and attempts to make exactly k moves. The rows and columns are 0-indexed, so the top-left cell is (0, 0), and the bottom-right cell is (n - 1, n - 1).

    \n\n

    A chess knight has eight possible moves it can make, as illustrated below. Each move is two cells in a cardinal direction, then one cell in an orthogonal direction.

    \n\n

    Each time the knight is to move, it chooses one of eight possible moves uniformly at random (even if the piece would go off the chessboard) and moves there.

    \n\n

    The knight continues moving until it has made exactly k moves or has moved off the chessboard.

    \n\n

    Return the probability that the knight remains on the board after it has stopped moving.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 3, k = 2, row = 0, column = 0\nOutput: 0.06250\nExplanation: There are two moves (to (1,2), (2,1)) that will keep the knight on the board.\nFrom each of those positions, there are also two moves that will keep the knight on the board.\nThe total probability the knight stays on the board is 0.0625.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 1, k = 0, row = 0, column = 0\nOutput: 1.00000\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 25
    • \n\t
    • 0 <= k <= 100
    • \n\t
    • 0 <= row, column <= n
    • \n
    \n", "content_cn": "

    \u5df2\u77e5\u4e00\u4e2a NxN \u7684\u56fd\u9645\u8c61\u68cb\u68cb\u76d8\uff0c\u68cb\u76d8\u7684\u884c\u53f7\u548c\u5217\u53f7\u90fd\u662f\u4ece 0 \u5f00\u59cb\u3002\u5373\u6700\u5de6\u4e0a\u89d2\u7684\u683c\u5b50\u8bb0\u4e3a (0, 0)\uff0c\u6700\u53f3\u4e0b\u89d2\u7684\u8bb0\u4e3a (N-1, N-1)\u3002 

    \n\n

    \u73b0\u6709\u4e00\u4e2a “\u9a6c”\uff08\u4e5f\u8bd1\u4f5c “\u9a91\u58eb”\uff09\u4f4d\u4e8e (r, c) \uff0c\u5e76\u6253\u7b97\u8fdb\u884c K \u6b21\u79fb\u52a8\u3002 

    \n\n

    \u5982\u4e0b\u56fe\u6240\u793a\uff0c\u56fd\u9645\u8c61\u68cb\u7684 “\u9a6c” \u6bcf\u4e00\u6b65\u5148\u6cbf\u6c34\u5e73\u6216\u5782\u76f4\u65b9\u5411\u79fb\u52a8 2 \u4e2a\u683c\u5b50\uff0c\u7136\u540e\u5411\u4e0e\u4e4b\u76f8\u5782\u76f4\u7684\u65b9\u5411\u518d\u79fb\u52a8 1 \u4e2a\u683c\u5b50\uff0c\u5171\u6709 8 \u4e2a\u53ef\u9009\u7684\u4f4d\u7f6e\u3002

    \n\n

     

    \n\n

    \n\n

     

    \n\n

    \u73b0\u5728 “\u9a6c” \u6bcf\u4e00\u6b65\u90fd\u4ece\u53ef\u9009\u7684\u4f4d\u7f6e\uff08\u5305\u62ec\u68cb\u76d8\u5916\u90e8\u7684\uff09\u4e2d\u72ec\u7acb\u968f\u673a\u5730\u9009\u62e9\u4e00\u4e2a\u8fdb\u884c\u79fb\u52a8\uff0c\u76f4\u5230\u79fb\u52a8\u4e86 K \u6b21\u6216\u8df3\u5230\u4e86\u68cb\u76d8\u5916\u9762\u3002

    \n\n

    \u6c42\u79fb\u52a8\u7ed3\u675f\u540e\uff0c“\u9a6c” \u4ecd\u7559\u5728\u68cb\u76d8\u4e0a\u7684\u6982\u7387\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165: 3, 2, 0, 0\n\u8f93\u51fa: 0.0625\n\u89e3\u91ca: \n\u8f93\u5165\u7684\u6570\u636e\u4f9d\u6b21\u4e3a N, K, r, c\n\u7b2c 1 \u6b65\u65f6\uff0c\u6709\u4e14\u53ea\u6709 2 \u79cd\u8d70\u6cd5\u4ee4 “\u9a6c” \u53ef\u4ee5\u7559\u5728\u68cb\u76d8\u4e0a\uff08\u8df3\u5230\uff081,2\uff09\u6216\uff082,1\uff09\uff09\u3002\u5bf9\u4e8e\u4ee5\u4e0a\u7684\u4e24\u79cd\u60c5\u51b5\uff0c\u5404\u81ea\u5728\u7b2c2\u6b65\u5747\u6709\u4e14\u53ea\u67092\u79cd\u8d70\u6cd5\u4ee4 “\u9a6c” \u4ecd\u7136\u7559\u5728\u68cb\u76d8\u4e0a\u3002\n\u6240\u4ee5 “\u9a6c” \u5728\u7ed3\u675f\u540e\u4ecd\u5728\u68cb\u76d8\u4e0a\u7684\u6982\u7387\u4e3a 0.0625\u3002\n
    \n\n

     

    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    • N \u7684\u53d6\u503c\u8303\u56f4\u4e3a [1, 25]
    • \n\t
    • K \u7684\u53d6\u503c\u8303\u56f4\u4e3a [0, 100]
    • \n\t
    • \u5f00\u59cb\u65f6\uff0c“\u9a6c” \u603b\u662f\u4f4d\u4e8e\u68cb\u76d8\u4e0a
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n double knightProbability(int n, int k, int row, int column) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double knightProbability(int n, int k, int row, int column) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def knightProbability(self, n, k, row, column):\n \"\"\"\n :type n: int\n :type k: int\n :type row: int\n :type column: int\n :rtype: float\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def knightProbability(self, n: int, k: int, row: int, column: int) -> float:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\ndouble knightProbability(int n, int k, int row, int column){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double KnightProbability(int n, int k, int row, int column) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} k\n * @param {number} row\n * @param {number} column\n * @return {number}\n */\nvar knightProbability = function(n, k, row, column) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} k\n# @param {Integer} row\n# @param {Integer} column\n# @return {Float}\ndef knight_probability(n, k, row, column)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func knightProbability(_ n: Int, _ k: Int, _ row: Int, _ column: Int) -> Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func knightProbability(n int, k int, row int, column int) float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def knightProbability(n: Int, k: Int, row: Int, column: Int): Double = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun knightProbability(n: Int, k: Int, row: Int, column: Int): Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn knight_probability(n: i32, k: i32, row: i32, column: i32) -> f64 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $k\n * @param Integer $row\n * @param Integer $column\n * @return Float\n */\n function knightProbability($n, $k, $row, $column) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function knightProbability(n: number, k: number, row: number, column: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (knight-probability n k row column)\n (-> exact-integer? exact-integer? exact-integer? exact-integer? flonum?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0688](https://leetcode-cn.com/problems/knight-probability-in-chessboard)", "[\u201c\u9a6c\u201d\u5728\u68cb\u76d8\u4e0a\u7684\u6982\u7387](/solution/0600-0699/0688.Knight%20Probability%20in%20Chessboard/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0688](https://leetcode.com/problems/knight-probability-in-chessboard)", "[Knight Probability in Chessboard](/solution/0600-0699/0688.Knight%20Probability%20in%20Chessboard/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0687", "frontend_question_id": "0687", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-univalue-path", "url_en": "https://leetcode.com/problems/longest-univalue-path", "relative_path_cn": "/solution/0600-0699/0687.Longest%20Univalue%20Path/README.md", "relative_path_en": "/solution/0600-0699/0687.Longest%20Univalue%20Path/README_EN.md", "title_cn": "\u6700\u957f\u540c\u503c\u8def\u5f84", "title_en": "Longest Univalue Path", "question_title_slug": "longest-univalue-path", "content_en": "

    Given the root of a binary tree, return the length of the longest path, where each node in the path has the same value. This path may or may not pass through the root.

    \n\n

    The length of the path between two nodes is represented by the number of edges between them.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [5,4,5,1,1,5]\nOutput: 2\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [1,4,5,4,4,5]\nOutput: 2\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [0, 104].
    • \n\t
    • -1000 <= Node.val <= 1000
    • \n\t
    • The depth of the tree will not exceed 1000.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811\uff0c\u627e\u5230\u6700\u957f\u7684\u8def\u5f84\uff0c\u8fd9\u4e2a\u8def\u5f84\u4e2d\u7684\u6bcf\u4e2a\u8282\u70b9\u5177\u6709\u76f8\u540c\u503c\u3002 \u8fd9\u6761\u8def\u5f84\u53ef\u4ee5\u7ecf\u8fc7\u4e5f\u53ef\u4ee5\u4e0d\u7ecf\u8fc7\u6839\u8282\u70b9\u3002

    \n\n

    \u6ce8\u610f\uff1a\u4e24\u4e2a\u8282\u70b9\u4e4b\u95f4\u7684\u8def\u5f84\u957f\u5ea6\u7531\u5b83\u4eec\u4e4b\u95f4\u7684\u8fb9\u6570\u8868\u793a\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n

    \u8f93\u5165:

    \n\n
    \n              5\n             / \\\n            4   5\n           / \\   \\\n          1   1   5\n
    \n\n

    \u8f93\u51fa:

    \n\n
    \n2\n
    \n\n

    \u793a\u4f8b 2:

    \n\n

    \u8f93\u5165:

    \n\n
    \n              1\n             / \\\n            4   5\n           / \\   \\\n          4   4   5\n
    \n\n

    \u8f93\u51fa:

    \n\n
    \n2\n
    \n\n

    \u6ce8\u610f: \u7ed9\u5b9a\u7684\u4e8c\u53c9\u6811\u4e0d\u8d85\u8fc710000\u4e2a\u7ed3\u70b9\u3002 \u6811\u7684\u9ad8\u5ea6\u4e0d\u8d85\u8fc71000\u3002

    \n", "tags_en": ["Tree", "Recursion"], "tags_cn": ["\u6811", "\u9012\u5f52"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int longestUnivaluePath(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int longestUnivaluePath(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def longestUnivaluePath(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def longestUnivaluePath(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint longestUnivaluePath(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int LongestUnivaluePath(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar longestUnivaluePath = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef longest_univalue_path(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func longestUnivaluePath(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc longestUnivaluePath(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def longestUnivaluePath(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun longestUnivaluePath(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn longest_univalue_path(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function longestUnivaluePath($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction longestUnivaluePath(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (longest-univalue-path root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0687](https://leetcode-cn.com/problems/longest-univalue-path)", "[\u6700\u957f\u540c\u503c\u8def\u5f84](/solution/0600-0699/0687.Longest%20Univalue%20Path/README.md)", "`\u6811`,`\u9012\u5f52`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0687](https://leetcode.com/problems/longest-univalue-path)", "[Longest Univalue Path](/solution/0600-0699/0687.Longest%20Univalue%20Path/README_EN.md)", "`Tree`,`Recursion`", "Medium", ""]}, {"question_id": "0686", "frontend_question_id": "0686", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/repeated-string-match", "url_en": "https://leetcode.com/problems/repeated-string-match", "relative_path_cn": "/solution/0600-0699/0686.Repeated%20String%20Match/README.md", "relative_path_en": "/solution/0600-0699/0686.Repeated%20String%20Match/README_EN.md", "title_cn": "\u91cd\u590d\u53e0\u52a0\u5b57\u7b26\u4e32\u5339\u914d", "title_en": "Repeated String Match", "question_title_slug": "repeated-string-match", "content_en": "

    Given two strings a and b, return the minimum number of times you should repeat string a so that string b is a substring of it. If it is impossible for b\u200b\u200b\u200b\u200b\u200b\u200b to be a substring of a after repeating it, return -1.

    \n\n

    Notice: string "abc" repeated 0 times is "",  repeated 1 time is "abc" and repeated 2 times is "abcabc".

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: a = "abcd", b = "cdabcdab"\nOutput: 3\nExplanation: We return 3 because by repeating a three times "abcdabcdabcd", b is a substring of it.\n
    \n\n

    Example 2:

    \n\n
    \nInput: a = "a", b = "aa"\nOutput: 2\n
    \n\n

    Example 3:

    \n\n
    \nInput: a = "a", b = "a"\nOutput: 1\n
    \n\n

    Example 4:

    \n\n
    \nInput: a = "abc", b = "wxyz"\nOutput: -1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= a.length <= 104
    • \n\t
    • 1 <= b.length <= 104
    • \n\t
    • a and b consist of lower-case English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u5b57\u7b26\u4e32 a \u548c b\uff0c\u5bfb\u627e\u91cd\u590d\u53e0\u52a0\u5b57\u7b26\u4e32 a \u7684\u6700\u5c0f\u6b21\u6570\uff0c\u4f7f\u5f97\u5b57\u7b26\u4e32 b \u6210\u4e3a\u53e0\u52a0\u540e\u7684\u5b57\u7b26\u4e32 a \u7684\u5b50\u4e32\uff0c\u5982\u679c\u4e0d\u5b58\u5728\u5219\u8fd4\u56de -1\u3002

    \n\n

    \u6ce8\u610f\uff1a\u5b57\u7b26\u4e32 "abc" \u91cd\u590d\u53e0\u52a0 0 \u6b21\u662f ""\uff0c\u91cd\u590d\u53e0\u52a0 1 \u6b21\u662f "abc"\uff0c\u91cd\u590d\u53e0\u52a0 2 \u6b21\u662f "abcabc"\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aa = "abcd", b = "cdabcdab"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1aa \u91cd\u590d\u53e0\u52a0\u4e09\u904d\u540e\u4e3a "abcdabcdabcd", \u6b64\u65f6 b \u662f\u5176\u5b50\u4e32\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aa = "a", b = "aa"\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aa = "a", b = "a"\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1aa = "abc", b = "wxyz"\n\u8f93\u51fa\uff1a-1\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= a.length <= 104
    • \n\t
    • 1 <= b.length <= 104
    • \n\t
    • a \u548c b \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int repeatedStringMatch(string a, string b) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int repeatedStringMatch(String a, String b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def repeatedStringMatch(self, a, b):\n \"\"\"\n :type a: str\n :type b: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def repeatedStringMatch(self, a: str, b: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint repeatedStringMatch(char * a, char * b){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int RepeatedStringMatch(string a, string b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} a\n * @param {string} b\n * @return {number}\n */\nvar repeatedStringMatch = function(a, b) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} a\n# @param {String} b\n# @return {Integer}\ndef repeated_string_match(a, b)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func repeatedStringMatch(_ a: String, _ b: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func repeatedStringMatch(a string, b string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def repeatedStringMatch(a: String, b: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun repeatedStringMatch(a: String, b: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn repeated_string_match(a: String, b: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $a\n * @param String $b\n * @return Integer\n */\n function repeatedStringMatch($a, $b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function repeatedStringMatch(a: string, b: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (repeated-string-match a b)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0686](https://leetcode-cn.com/problems/repeated-string-match)", "[\u91cd\u590d\u53e0\u52a0\u5b57\u7b26\u4e32\u5339\u914d](/solution/0600-0699/0686.Repeated%20String%20Match/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0686](https://leetcode.com/problems/repeated-string-match)", "[Repeated String Match](/solution/0600-0699/0686.Repeated%20String%20Match/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "0685", "frontend_question_id": "0685", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/redundant-connection-ii", "url_en": "https://leetcode.com/problems/redundant-connection-ii", "relative_path_cn": "/solution/0600-0699/0685.Redundant%20Connection%20II/README.md", "relative_path_en": "/solution/0600-0699/0685.Redundant%20Connection%20II/README_EN.md", "title_cn": "\u5197\u4f59\u8fde\u63a5 II", "title_en": "Redundant Connection II", "question_title_slug": "redundant-connection-ii", "content_en": "

    In this problem, a rooted tree is a directed graph such that, there is exactly one node (the root) for which all other nodes are descendants of this node, plus every node has exactly one parent, except for the root node which has no parents.

    \n\n

    The given input is a directed graph that started as a rooted tree with n nodes (with distinct values from 1 to n), with one additional directed edge added. The added edge has two different vertices chosen from 1 to n, and was not an edge that already existed.

    \n\n

    The resulting graph is given as a 2D-array of edges. Each element of edges is a pair [ui, vi] that represents a directed edge connecting nodes ui and vi, where ui is a parent of child vi.

    \n\n

    Return an edge that can be removed so that the resulting graph is a rooted tree of n nodes. If there are multiple answers, return the answer that occurs last in the given 2D-array.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: edges = [[1,2],[1,3],[2,3]]\nOutput: [2,3]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: edges = [[1,2],[2,3],[3,4],[4,1],[1,5]]\nOutput: [4,1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == edges.length
    • \n\t
    • 3 <= n <= 1000
    • \n\t
    • edges[i].length == 2
    • \n\t
    • 1 <= ui, vi <= n
    • \n\t
    • ui != vi
    • \n
    \n", "content_cn": "

    \u5728\u672c\u95ee\u9898\u4e2d\uff0c\u6709\u6839\u6811\u6307\u6ee1\u8db3\u4ee5\u4e0b\u6761\u4ef6\u7684 \u6709\u5411 \u56fe\u3002\u8be5\u6811\u53ea\u6709\u4e00\u4e2a\u6839\u8282\u70b9\uff0c\u6240\u6709\u5176\u4ed6\u8282\u70b9\u90fd\u662f\u8be5\u6839\u8282\u70b9\u7684\u540e\u7ee7\u3002\u8be5\u6811\u9664\u4e86\u6839\u8282\u70b9\u4e4b\u5916\u7684\u6bcf\u4e00\u4e2a\u8282\u70b9\u90fd\u6709\u4e14\u53ea\u6709\u4e00\u4e2a\u7236\u8282\u70b9\uff0c\u800c\u6839\u8282\u70b9\u6ca1\u6709\u7236\u8282\u70b9\u3002

    \n\n

    \u8f93\u5165\u4e00\u4e2a\u6709\u5411\u56fe\uff0c\u8be5\u56fe\u7531\u4e00\u4e2a\u6709\u7740 n \u4e2a\u8282\u70b9\uff08\u8282\u70b9\u503c\u4e0d\u91cd\u590d\uff0c\u4ece 1 \u5230 n\uff09\u7684\u6811\u53ca\u4e00\u6761\u9644\u52a0\u7684\u6709\u5411\u8fb9\u6784\u6210\u3002\u9644\u52a0\u7684\u8fb9\u5305\u542b\u5728 1 \u5230 n \u4e2d\u7684\u4e24\u4e2a\u4e0d\u540c\u9876\u70b9\u95f4\uff0c\u8fd9\u6761\u9644\u52a0\u7684\u8fb9\u4e0d\u5c5e\u4e8e\u6811\u4e2d\u5df2\u5b58\u5728\u7684\u8fb9\u3002

    \n\n

    \u7ed3\u679c\u56fe\u662f\u4e00\u4e2a\u4ee5\u8fb9\u7ec4\u6210\u7684\u4e8c\u7ef4\u6570\u7ec4\u00a0edges \u3002 \u6bcf\u4e2a\u5143\u7d20\u662f\u4e00\u5bf9 [ui, vi]\uff0c\u7528\u4ee5\u8868\u793a \u6709\u5411 \u56fe\u4e2d\u8fde\u63a5\u9876\u70b9 ui \u548c\u9876\u70b9 vi \u7684\u8fb9\uff0c\u5176\u4e2d ui \u662f vi \u7684\u4e00\u4e2a\u7236\u8282\u70b9\u3002

    \n\n

    \u8fd4\u56de\u4e00\u6761\u80fd\u5220\u9664\u7684\u8fb9\uff0c\u4f7f\u5f97\u5269\u4e0b\u7684\u56fe\u662f\u6709 n \u4e2a\u8282\u70b9\u7684\u6709\u6839\u6811\u3002\u82e5\u6709\u591a\u4e2a\u7b54\u6848\uff0c\u8fd4\u56de\u6700\u540e\u51fa\u73b0\u5728\u7ed9\u5b9a\u4e8c\u7ef4\u6570\u7ec4\u7684\u7b54\u6848\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aedges = [[1,2],[1,3],[2,3]]\n\u8f93\u51fa\uff1a[2,3]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aedges = [[1,2],[2,3],[3,4],[4,1],[1,5]]\n\u8f93\u51fa\uff1a[4,1]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == edges.length
    • \n\t
    • 3 <= n <= 1000
    • \n\t
    • edges[i].length == 2
    • \n\t
    • 1 <= ui, vi <= n
    • \n
    \n", "tags_en": ["Tree", "Depth-first Search", "Union Find", "Graph"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e76\u67e5\u96c6", "\u56fe"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findRedundantDirectedConnection(vector>& edges) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] findRedundantDirectedConnection(int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findRedundantDirectedConnection(self, edges):\n \"\"\"\n :type edges: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findRedundantDirectedConnection(self, edges: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* findRedundantDirectedConnection(int** edges, int edgesSize, int* edgesColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] FindRedundantDirectedConnection(int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} edges\n * @return {number[]}\n */\nvar findRedundantDirectedConnection = function(edges) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} edges\n# @return {Integer[]}\ndef find_redundant_directed_connection(edges)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findRedundantDirectedConnection(_ edges: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findRedundantDirectedConnection(edges [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findRedundantDirectedConnection(edges: Array[Array[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findRedundantDirectedConnection(edges: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_redundant_directed_connection(edges: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $edges\n * @return Integer[]\n */\n function findRedundantDirectedConnection($edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findRedundantDirectedConnection(edges: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-redundant-directed-connection edges)\n (-> (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0685](https://leetcode-cn.com/problems/redundant-connection-ii)", "[\u5197\u4f59\u8fde\u63a5 II](/solution/0600-0699/0685.Redundant%20Connection%20II/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e76\u67e5\u96c6`,`\u56fe`", "\u56f0\u96be", ""], "md_table_row_en": ["[0685](https://leetcode.com/problems/redundant-connection-ii)", "[Redundant Connection II](/solution/0600-0699/0685.Redundant%20Connection%20II/README_EN.md)", "`Tree`,`Depth-first Search`,`Union Find`,`Graph`", "Hard", ""]}, {"question_id": "0684", "frontend_question_id": "0684", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/redundant-connection", "url_en": "https://leetcode.com/problems/redundant-connection", "relative_path_cn": "/solution/0600-0699/0684.Redundant%20Connection/README.md", "relative_path_en": "/solution/0600-0699/0684.Redundant%20Connection/README_EN.md", "title_cn": "\u5197\u4f59\u8fde\u63a5", "title_en": "Redundant Connection", "question_title_slug": "redundant-connection", "content_en": "

    In this problem, a tree is an undirected graph that is connected and has no cycles.

    \n\n

    You are given a graph that started as a tree with n nodes labeled from 1 to n, with one additional edge added. The added edge has two different vertices chosen from 1 to n, and was not an edge that already existed. The graph is represented as an array edges of length n where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the graph.

    \n\n

    Return an edge that can be removed so that the resulting graph is a tree of n nodes. If there are multiple answers, return the answer that occurs last in the input.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: edges = [[1,2],[1,3],[2,3]]\nOutput: [2,3]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: edges = [[1,2],[2,3],[3,4],[1,4],[1,5]]\nOutput: [1,4]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == edges.length
    • \n\t
    • 3 <= n <= 1000
    • \n\t
    • edges[i].length == 2
    • \n\t
    • 1 <= ai < bi <= edges.length
    • \n\t
    • ai != bi
    • \n\t
    • There are no repeated edges.
    • \n\t
    • The given graph is connected.
    • \n
    \n", "content_cn": "

    \u5728\u672c\u95ee\u9898\u4e2d, \u6811\u6307\u7684\u662f\u4e00\u4e2a\u8fde\u901a\u4e14\u65e0\u73af\u7684\u65e0\u5411\u56fe\u3002

    \n\n

    \u8f93\u5165\u4e00\u4e2a\u56fe\uff0c\u8be5\u56fe\u7531\u4e00\u4e2a\u6709\u7740N\u4e2a\u8282\u70b9 (\u8282\u70b9\u503c\u4e0d\u91cd\u590d1, 2, ..., N) \u7684\u6811\u53ca\u4e00\u6761\u9644\u52a0\u7684\u8fb9\u6784\u6210\u3002\u9644\u52a0\u7684\u8fb9\u7684\u4e24\u4e2a\u9876\u70b9\u5305\u542b\u57281\u5230N\u4e2d\u95f4\uff0c\u8fd9\u6761\u9644\u52a0\u7684\u8fb9\u4e0d\u5c5e\u4e8e\u6811\u4e2d\u5df2\u5b58\u5728\u7684\u8fb9\u3002

    \n\n

    \u7ed3\u679c\u56fe\u662f\u4e00\u4e2a\u4ee5\u8fb9\u7ec4\u6210\u7684\u4e8c\u7ef4\u6570\u7ec4\u3002\u6bcf\u4e00\u4e2a\u8fb9\u7684\u5143\u7d20\u662f\u4e00\u5bf9[u, v] \uff0c\u6ee1\u8db3 u < v\uff0c\u8868\u793a\u8fde\u63a5\u9876\u70b9u \u548cv\u7684\u65e0\u5411\u56fe\u7684\u8fb9\u3002

    \n\n

    \u8fd4\u56de\u4e00\u6761\u53ef\u4ee5\u5220\u53bb\u7684\u8fb9\uff0c\u4f7f\u5f97\u7ed3\u679c\u56fe\u662f\u4e00\u4e2a\u6709\u7740N\u4e2a\u8282\u70b9\u7684\u6811\u3002\u5982\u679c\u6709\u591a\u4e2a\u7b54\u6848\uff0c\u5219\u8fd4\u56de\u4e8c\u7ef4\u6570\u7ec4\u4e2d\u6700\u540e\u51fa\u73b0\u7684\u8fb9\u3002\u7b54\u6848\u8fb9 [u, v] \u5e94\u6ee1\u8db3\u76f8\u540c\u7684\u683c\u5f0f u < v\u3002

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165: [[1,2], [1,3], [2,3]]\n\u8f93\u51fa: [2,3]\n\u89e3\u91ca: \u7ed9\u5b9a\u7684\u65e0\u5411\u56fe\u4e3a:\n  1\n / \\\n2 - 3\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165: [[1,2], [2,3], [3,4], [1,4], [1,5]]\n\u8f93\u51fa: [1,4]\n\u89e3\u91ca: \u7ed9\u5b9a\u7684\u65e0\u5411\u56fe\u4e3a:\n5 - 1 - 2\n    |   |\n    4 - 3\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    • \u8f93\u5165\u7684\u4e8c\u7ef4\u6570\u7ec4\u5927\u5c0f\u5728 3 \u5230 1000\u3002
    • \n\t
    • \u4e8c\u7ef4\u6570\u7ec4\u4e2d\u7684\u6574\u6570\u57281\u5230N\u4e4b\u95f4\uff0c\u5176\u4e2dN\u662f\u8f93\u5165\u6570\u7ec4\u7684\u5927\u5c0f\u3002
    • \n
    \n\n

    \u66f4\u65b0(2017-09-26):
    \n\u6211\u4eec\u5df2\u7ecf\u91cd\u65b0\u68c0\u67e5\u4e86\u95ee\u9898\u63cf\u8ff0\u53ca\u6d4b\u8bd5\u7528\u4f8b\uff0c\u660e\u786e\u56fe\u662f\u65e0\u5411 \u56fe\u3002\u5bf9\u4e8e\u6709\u5411\u56fe\u8be6\u89c1\u5197\u4f59\u8fde\u63a5II\u3002\u5bf9\u4e8e\u9020\u6210\u4efb\u4f55\u4e0d\u4fbf\uff0c\u6211\u4eec\u6df1\u611f\u6b49\u610f\u3002

    \n", "tags_en": ["Tree", "Union Find", "Graph"], "tags_cn": ["\u6811", "\u5e76\u67e5\u96c6", "\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findRedundantConnection(vector>& edges) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] findRedundantConnection(int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findRedundantConnection(self, edges):\n \"\"\"\n :type edges: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findRedundantConnection(self, edges: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* findRedundantConnection(int** edges, int edgesSize, int* edgesColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] FindRedundantConnection(int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} edges\n * @return {number[]}\n */\nvar findRedundantConnection = function(edges) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} edges\n# @return {Integer[]}\ndef find_redundant_connection(edges)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findRedundantConnection(_ edges: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findRedundantConnection(edges [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findRedundantConnection(edges: Array[Array[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findRedundantConnection(edges: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_redundant_connection(edges: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $edges\n * @return Integer[]\n */\n function findRedundantConnection($edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findRedundantConnection(edges: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-redundant-connection edges)\n (-> (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0684](https://leetcode-cn.com/problems/redundant-connection)", "[\u5197\u4f59\u8fde\u63a5](/solution/0600-0699/0684.Redundant%20Connection/README.md)", "`\u6811`,`\u5e76\u67e5\u96c6`,`\u56fe`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0684](https://leetcode.com/problems/redundant-connection)", "[Redundant Connection](/solution/0600-0699/0684.Redundant%20Connection/README_EN.md)", "`Tree`,`Union Find`,`Graph`", "Medium", ""]}, {"question_id": "0683", "frontend_question_id": "0683", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/k-empty-slots", "url_en": "https://leetcode.com/problems/k-empty-slots", "relative_path_cn": "/solution/0600-0699/0683.K%20Empty%20Slots/README.md", "relative_path_en": "/solution/0600-0699/0683.K%20Empty%20Slots/README_EN.md", "title_cn": "K \u4e2a\u5173\u95ed\u7684\u706f\u6ce1", "title_en": "K Empty Slots", "question_title_slug": "k-empty-slots", "content_en": "

    You have n bulbs in a row numbered from 1 to n. Initially, all the bulbs are turned off. We turn on exactly one bulb every day until all bulbs are on after n days.

    \n\n

    You are given an array bulbs of length n where bulbs[i] = x means that on the (i+1)th day, we will turn on the bulb at position x where i is 0-indexed and x is 1-indexed.

    \n\n

    Given an integer k, return the minimum day number such that there exists two turned on bulbs that have exactly k bulbs between them that are all turned off. If there isn't such day, return -1.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: bulbs = [1,3,2], k = 1\nOutput: 2\nExplanation:\nOn the first day: bulbs[0] = 1, first bulb is turned on: [1,0,0]\nOn the second day: bulbs[1] = 3, third bulb is turned on: [1,0,1]\nOn the third day: bulbs[2] = 2, second bulb is turned on: [1,1,1]\nWe return 2 because on the second day, there were two on bulbs with one off bulb between them.
    \n\n

    Example 2:

    \n\n
    \nInput: bulbs = [1,2,3], k = 1\nOutput: -1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == bulbs.length
    • \n\t
    • 1 <= n <= 2 * 104
    • \n\t
    • 1 <= bulbs[i] <= n
    • \n\t
    • bulbs is a permutation of numbers from 1 to n.
    • \n\t
    • 0 <= k <= 2 * 104
    • \n
    \n", "content_cn": "

    N \u4e2a\u706f\u6ce1\u6392\u6210\u4e00\u884c\uff0c\u7f16\u53f7\u4ece 1 \u5230 N \u3002\u6700\u521d\uff0c\u6240\u6709\u706f\u6ce1\u90fd\u5173\u95ed\u3002\u6bcf\u5929\u53ea\u6253\u5f00\u4e00\u4e2a\u706f\u6ce1\uff0c\u76f4\u5230 N \u5929\u540e\u6240\u6709\u706f\u6ce1\u90fd\u6253\u5f00\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u4e3a N \u7684\u706f\u6ce1\u6570\u7ec4 blubs \uff0c\u5176\u4e2d bulls[i] = x \u610f\u5473\u7740\u5728\u7b2c (i+1) \u5929\uff0c\u6211\u4eec\u4f1a\u628a\u5728\u4f4d\u7f6e x \u7684\u706f\u6ce1\u6253\u5f00\uff0c\u5176\u4e2d i \u4ece 0 \u5f00\u59cb\uff0cx \u4ece 1 \u5f00\u59cb\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 K \uff0c\u8bf7\u4f60\u8f93\u51fa\u5728\u7b2c\u51e0\u5929\u6070\u597d\u6709\u4e24\u4e2a\u6253\u5f00\u7684\u706f\u6ce1\uff0c\u4f7f\u5f97\u5b83\u4eec\u4e2d\u95f4 \u6b63\u597d \u6709 K \u4e2a\u706f\u6ce1\u4e14\u8fd9\u4e9b\u706f\u6ce1 \u5168\u90e8\u662f\u5173\u95ed\u7684 \u3002

    \n\n

    \u5982\u679c\u4e0d\u5b58\u5728\u8fd9\u79cd\u60c5\u51b5\uff0c\u8fd4\u56de -1 \u3002\u5982\u679c\u6709\u591a\u5929\u90fd\u51fa\u73b0\u8fd9\u79cd\u60c5\u51b5\uff0c\u8bf7\u8fd4\u56de \u6700\u5c0f\u7684\u5929\u6570 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\nbulbs: [1,3,2]\nK: 1\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n\u7b2c\u4e00\u5929 bulbs[0] = 1\uff0c\u6253\u5f00\u7b2c\u4e00\u4e2a\u706f\u6ce1 [1,0,0]\n\u7b2c\u4e8c\u5929 bulbs[1] = 3\uff0c\u6253\u5f00\u7b2c\u4e09\u4e2a\u706f\u6ce1 [1,0,1]\n\u7b2c\u4e09\u5929 bulbs[2] = 2\uff0c\u6253\u5f00\u7b2c\u4e8c\u4e2a\u706f\u6ce1 [1,1,1]\n\u8fd4\u56de2\uff0c\u56e0\u4e3a\u5728\u7b2c\u4e8c\u5929\uff0c\u4e24\u4e2a\u6253\u5f00\u7684\u706f\u6ce1\u4e4b\u95f4\u6070\u597d\u6709\u4e00\u4e2a\u5173\u95ed\u7684\u706f\u6ce1\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\nbulbs: [1,2,3]\nk: 1\n\u8f93\u51fa\uff1a-1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= N <= 20000
    • \n\t
    • 1 <= bulbs[i] <= N
    • \n\t
    • bulbs \u662f\u4e00\u4e2a\u7531\u4ece 1 \u5230 N \u7684\u6570\u5b57\u6784\u6210\u7684\u6392\u5217
    • \n\t
    • 0 <= K <= 20000
    • \n
    \n", "tags_en": ["Ordered Map"], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int kEmptySlots(vector& bulbs, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int kEmptySlots(int[] bulbs, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def kEmptySlots(self, bulbs, k):\n \"\"\"\n :type bulbs: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def kEmptySlots(self, bulbs: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint kEmptySlots(int* bulbs, int bulbsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int KEmptySlots(int[] bulbs, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} bulbs\n * @param {number} k\n * @return {number}\n */\nvar kEmptySlots = function(bulbs, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} bulbs\n# @param {Integer} k\n# @return {Integer}\ndef k_empty_slots(bulbs, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func kEmptySlots(_ bulbs: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func kEmptySlots(bulbs []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def kEmptySlots(bulbs: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun kEmptySlots(bulbs: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn k_empty_slots(bulbs: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $bulbs\n * @param Integer $k\n * @return Integer\n */\n function kEmptySlots($bulbs, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function kEmptySlots(bulbs: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (k-empty-slots bulbs k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0683](https://leetcode-cn.com/problems/k-empty-slots)", "[K \u4e2a\u5173\u95ed\u7684\u706f\u6ce1](/solution/0600-0699/0683.K%20Empty%20Slots/README.md)", "", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0683](https://leetcode.com/problems/k-empty-slots)", "[K Empty Slots](/solution/0600-0699/0683.K%20Empty%20Slots/README_EN.md)", "`Ordered Map`", "Hard", "\ud83d\udd12"]}, {"question_id": "0682", "frontend_question_id": "0682", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/baseball-game", "url_en": "https://leetcode.com/problems/baseball-game", "relative_path_cn": "/solution/0600-0699/0682.Baseball%20Game/README.md", "relative_path_en": "/solution/0600-0699/0682.Baseball%20Game/README_EN.md", "title_cn": "\u68d2\u7403\u6bd4\u8d5b", "title_en": "Baseball Game", "question_title_slug": "baseball-game", "content_en": "

    You are keeping score for a baseball game with strange rules. The game consists of several rounds, where the scores of past rounds may affect future rounds' scores.

    \n\n

    At the beginning of the game, you start with an empty record. You are given a list of strings ops, where ops[i] is the ith operation you must apply to the record and is one of the following:

    \n\n
      \n\t
    1. An integer x - Record a new score of x.
    2. \n\t
    3. "+" - Record a new score that is the sum of the previous two scores. It is guaranteed there will always be two previous scores.
    4. \n\t
    5. "D" - Record a new score that is double the previous score. It is guaranteed there will always be a previous score.
    6. \n\t
    7. "C" - Invalidate the previous score, removing it from the record. It is guaranteed there will always be a previous score.
    8. \n
    \n\n

    Return the sum of all the scores on the record.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: ops = ["5","2","C","D","+"]\nOutput: 30\nExplanation:\n"5" - Add 5 to the record, record is now [5].\n"2" - Add 2 to the record, record is now [5, 2].\n"C" - Invalidate and remove the previous score, record is now [5].\n"D" - Add 2 * 5 = 10 to the record, record is now [5, 10].\n"+" - Add 5 + 10 = 15 to the record, record is now [5, 10, 15].\nThe total sum is 5 + 10 + 15 = 30.\n
    \n\n

    Example 2:

    \n\n
    \nInput: ops = ["5","-2","4","C","D","9","+","+"]\nOutput: 27\nExplanation:\n"5" - Add 5 to the record, record is now [5].\n"-2" - Add -2 to the record, record is now [5, -2].\n"4" - Add 4 to the record, record is now [5, -2, 4].\n"C" - Invalidate and remove the previous score, record is now [5, -2].\n"D" - Add 2 * -2 = -4 to the record, record is now [5, -2, -4].\n"9" - Add 9 to the record, record is now [5, -2, -4, 9].\n"+" - Add -4 + 9 = 5 to the record, record is now [5, -2, -4, 9, 5].\n"+" - Add 9 + 5 = 14 to the record, record is now [5, -2, -4, 9, 5, 14].\nThe total sum is 5 + -2 + -4 + 9 + 5 + 14 = 27.\n
    \n\n

    Example 3:

    \n\n
    \nInput: ops = ["1"]\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= ops.length <= 1000
    • \n\t
    • ops[i] is "C", "D", "+", or a string representing an integer in the range [-3 * 104, 3 * 104].
    • \n\t
    • For operation "+", there will always be at least two previous scores on the record.
    • \n\t
    • For operations "C" and "D", there will always be at least one previous score on the record.
    • \n
    \n", "content_cn": "

    \u4f60\u73b0\u5728\u662f\u4e00\u573a\u91c7\u7528\u7279\u6b8a\u8d5b\u5236\u68d2\u7403\u6bd4\u8d5b\u7684\u8bb0\u5f55\u5458\u3002\u8fd9\u573a\u6bd4\u8d5b\u7531\u82e5\u5e72\u56de\u5408\u7ec4\u6210\uff0c\u8fc7\u53bb\u51e0\u56de\u5408\u7684\u5f97\u5206\u53ef\u80fd\u4f1a\u5f71\u54cd\u4ee5\u540e\u51e0\u56de\u5408\u7684\u5f97\u5206\u3002

    \n\n

    \u6bd4\u8d5b\u5f00\u59cb\u65f6\uff0c\u8bb0\u5f55\u662f\u7a7a\u767d\u7684\u3002\u4f60\u4f1a\u5f97\u5230\u4e00\u4e2a\u8bb0\u5f55\u64cd\u4f5c\u7684\u5b57\u7b26\u4e32\u5217\u8868 ops\uff0c\u5176\u4e2d ops[i] \u662f\u4f60\u9700\u8981\u8bb0\u5f55\u7684\u7b2c i \u9879\u64cd\u4f5c\uff0cops \u9075\u5faa\u4e0b\u8ff0\u89c4\u5219\uff1a

    \n\n
      \n\t
    1. \u6574\u6570 x - \u8868\u793a\u672c\u56de\u5408\u65b0\u83b7\u5f97\u5206\u6570 x
    2. \n\t
    3. \"+\" - \u8868\u793a\u672c\u56de\u5408\u65b0\u83b7\u5f97\u7684\u5f97\u5206\u662f\u524d\u4e24\u6b21\u5f97\u5206\u7684\u603b\u548c\u3002\u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u8bb0\u5f55\u6b64\u64cd\u4f5c\u65f6\u524d\u9762\u603b\u662f\u5b58\u5728\u4e24\u4e2a\u6709\u6548\u7684\u5206\u6570\u3002
    4. \n\t
    5. \"D\" - \u8868\u793a\u672c\u56de\u5408\u65b0\u83b7\u5f97\u7684\u5f97\u5206\u662f\u524d\u4e00\u6b21\u5f97\u5206\u7684\u4e24\u500d\u3002\u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u8bb0\u5f55\u6b64\u64cd\u4f5c\u65f6\u524d\u9762\u603b\u662f\u5b58\u5728\u4e00\u4e2a\u6709\u6548\u7684\u5206\u6570\u3002
    6. \n\t
    7. \"C\" - \u8868\u793a\u524d\u4e00\u6b21\u5f97\u5206\u65e0\u6548\uff0c\u5c06\u5176\u4ece\u8bb0\u5f55\u4e2d\u79fb\u9664\u3002\u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u8bb0\u5f55\u6b64\u64cd\u4f5c\u65f6\u524d\u9762\u603b\u662f\u5b58\u5728\u4e00\u4e2a\u6709\u6548\u7684\u5206\u6570\u3002
    8. \n
    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u8bb0\u5f55\u4e2d\u6240\u6709\u5f97\u5206\u7684\u603b\u548c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aops = [\"5\",\"2\",\"C\",\"D\",\"+\"]\n\u8f93\u51fa\uff1a30\n\u89e3\u91ca\uff1a\n\"5\" - \u8bb0\u5f55\u52a0 5 \uff0c\u8bb0\u5f55\u73b0\u5728\u662f [5]\n\"2\" - \u8bb0\u5f55\u52a0 2 \uff0c\u8bb0\u5f55\u73b0\u5728\u662f [5, 2]\n\"C\" - \u4f7f\u524d\u4e00\u6b21\u5f97\u5206\u7684\u8bb0\u5f55\u65e0\u6548\u5e76\u5c06\u5176\u79fb\u9664\uff0c\u8bb0\u5f55\u73b0\u5728\u662f [5].\n\"D\" - \u8bb0\u5f55\u52a0 2 * 5 = 10 \uff0c\u8bb0\u5f55\u73b0\u5728\u662f [5, 10].\n\"+\" - \u8bb0\u5f55\u52a0 5 + 10 = 15 \uff0c\u8bb0\u5f55\u73b0\u5728\u662f [5, 10, 15].\n\u6240\u6709\u5f97\u5206\u7684\u603b\u548c 5 + 10 + 15 = 30\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aops = [\"5\",\"-2\",\"4\",\"C\",\"D\",\"9\",\"+\",\"+\"]\n\u8f93\u51fa\uff1a27\n\u89e3\u91ca\uff1a\n\"5\" - \u8bb0\u5f55\u52a0 5 \uff0c\u8bb0\u5f55\u73b0\u5728\u662f [5]\n\"-2\" - \u8bb0\u5f55\u52a0 -2 \uff0c\u8bb0\u5f55\u73b0\u5728\u662f [5, -2]\n\"4\" - \u8bb0\u5f55\u52a0 4 \uff0c\u8bb0\u5f55\u73b0\u5728\u662f [5, -2, 4]\n\"C\" - \u4f7f\u524d\u4e00\u6b21\u5f97\u5206\u7684\u8bb0\u5f55\u65e0\u6548\u5e76\u5c06\u5176\u79fb\u9664\uff0c\u8bb0\u5f55\u73b0\u5728\u662f [5, -2]\n\"D\" - \u8bb0\u5f55\u52a0 2 * -2 = -4 \uff0c\u8bb0\u5f55\u73b0\u5728\u662f [5, -2, -4]\n\"9\" - \u8bb0\u5f55\u52a0 9 \uff0c\u8bb0\u5f55\u73b0\u5728\u662f [5, -2, -4, 9]\n\"+\" - \u8bb0\u5f55\u52a0 -4 + 9 = 5 \uff0c\u8bb0\u5f55\u73b0\u5728\u662f [5, -2, -4, 9, 5]\n\"+\" - \u8bb0\u5f55\u52a0 9 + 5 = 14 \uff0c\u8bb0\u5f55\u73b0\u5728\u662f [5, -2, -4, 9, 5, 14]\n\u6240\u6709\u5f97\u5206\u7684\u603b\u548c 5 + -2 + -4 + 9 + 5 + 14 = 27\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aops = [\"1\"]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= ops.length <= 1000
    • \n\t
    • ops[i] \u4e3a \"C\"\u3001\"D\"\u3001\"+\"\uff0c\u6216\u8005\u4e00\u4e2a\u8868\u793a\u6574\u6570\u7684\u5b57\u7b26\u4e32\u3002\u6574\u6570\u8303\u56f4\u662f [-3 * 104, 3 * 104]
    • \n\t
    • \u5bf9\u4e8e \"+\" \u64cd\u4f5c\uff0c\u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u8bb0\u5f55\u6b64\u64cd\u4f5c\u65f6\u524d\u9762\u603b\u662f\u5b58\u5728\u4e24\u4e2a\u6709\u6548\u7684\u5206\u6570
    • \n\t
    • \u5bf9\u4e8e \"C\" \u548c \"D\" \u64cd\u4f5c\uff0c\u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u8bb0\u5f55\u6b64\u64cd\u4f5c\u65f6\u524d\u9762\u603b\u662f\u5b58\u5728\u4e00\u4e2a\u6709\u6548\u7684\u5206\u6570
    • \n
    \n", "tags_en": ["Stack"], "tags_cn": ["\u6808"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int calPoints(vector& ops) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int calPoints(String[] ops) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def calPoints(self, ops):\n \"\"\"\n :type ops: List[str]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def calPoints(self, ops: List[str]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint calPoints(char ** ops, int opsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CalPoints(string[] ops) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} ops\n * @return {number}\n */\nvar calPoints = function(ops) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} ops\n# @return {Integer}\ndef cal_points(ops)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func calPoints(_ ops: [String]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func calPoints(ops []string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def calPoints(ops: Array[String]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun calPoints(ops: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn cal_points(ops: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $ops\n * @return Integer\n */\n function calPoints($ops) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function calPoints(ops: string[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (cal-points ops)\n (-> (listof string?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0682](https://leetcode-cn.com/problems/baseball-game)", "[\u68d2\u7403\u6bd4\u8d5b](/solution/0600-0699/0682.Baseball%20Game/README.md)", "`\u6808`", "\u7b80\u5355", ""], "md_table_row_en": ["[0682](https://leetcode.com/problems/baseball-game)", "[Baseball Game](/solution/0600-0699/0682.Baseball%20Game/README_EN.md)", "`Stack`", "Easy", ""]}, {"question_id": "0681", "frontend_question_id": "0681", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/next-closest-time", "url_en": "https://leetcode.com/problems/next-closest-time", "relative_path_cn": "/solution/0600-0699/0681.Next%20Closest%20Time/README.md", "relative_path_en": "/solution/0600-0699/0681.Next%20Closest%20Time/README_EN.md", "title_cn": "\u6700\u8fd1\u65f6\u523b", "title_en": "Next Closest Time", "question_title_slug": "next-closest-time", "content_en": "

    Given a time represented in the format "HH:MM", form the next closest time by reusing the current digits. There is no limit on how many times a digit can be reused.

    \n\n

    You may assume the given input string is always valid. For example, "01:34", "12:09" are all valid. "1:34", "12:9" are all invalid.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: time = "19:34"\nOutput: "19:39"\nExplanation: The next closest time choosing from digits 1, 9, 3, 4, is 19:39, which occurs 5 minutes later.\nIt is not 19:33, because this occurs 23 hours and 59 minutes later.\n
    \n\n

    Example 2:

    \n\n
    \nInput: time = "23:59"\nOutput: "22:22"\nExplanation: The next closest time choosing from digits 2, 3, 5, 9, is 22:22.\nIt may be assumed that the returned time is next day's time since it is smaller than the input time numerically.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • time.length == 5
    • \n\t
    • time is a valid time in the form "HH:MM".
    • \n\t
    • 0 <= HH < 24
    • \n\t
    • 0 <= MM < 60
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5f62\u5982 “HH:MM” \u8868\u793a\u7684\u65f6\u523b\uff0c\u5229\u7528\u5f53\u524d\u51fa\u73b0\u8fc7\u7684\u6570\u5b57\u6784\u9020\u4e0b\u4e00\u4e2a\u8ddd\u79bb\u5f53\u524d\u65f6\u95f4\u6700\u8fd1\u7684\u65f6\u523b\u3002\u6bcf\u4e2a\u51fa\u73b0\u6570\u5b57\u90fd\u53ef\u4ee5\u88ab\u65e0\u9650\u6b21\u4f7f\u7528\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u8ba4\u4e3a\u7ed9\u5b9a\u7684\u5b57\u7b26\u4e32\u4e00\u5b9a\u662f\u5408\u6cd5\u7684\u3002\u4f8b\u5982\uff0c“01:34” \u548c “12:09” \u662f\u5408\u6cd5\u7684\uff0c“1:34” \u548c “12:9” \u662f\u4e0d\u5408\u6cd5\u7684\u3002

    \n\n

     

    \n\n

    \u6837\u4f8b 1:

    \n\n
    \u8f93\u5165: "19:34"\n\u8f93\u51fa: "19:39"\n\u89e3\u91ca: \u5229\u7528\u6570\u5b57 1, 9, 3, 4 \u6784\u9020\u51fa\u6765\u7684\u6700\u8fd1\u65f6\u523b\u662f 19:39\uff0c\u662f 5 \u5206\u949f\u4e4b\u540e\u3002\u7ed3\u679c\u4e0d\u662f 19:33 \u56e0\u4e3a\u8fd9\u4e2a\u65f6\u523b\u662f 23 \u5c0f\u65f6 59 \u5206\u949f\u4e4b\u540e\u3002\n
    \n\n

     

    \n\n

    \u6837\u4f8b 2:

    \n\n
    \u8f93\u5165: "23:59"\n\u8f93\u51fa: "22:22"\n\u89e3\u91ca: \u5229\u7528\u6570\u5b57 2, 3, 5, 9 \u6784\u9020\u51fa\u6765\u7684\u6700\u8fd1\u65f6\u523b\u662f 22:22\u3002 \u7b54\u6848\u4e00\u5b9a\u662f\u7b2c\u4e8c\u5929\u7684\u67d0\u4e00\u65f6\u523b\uff0c\u6240\u4ee5\u9009\u62e9\u53ef\u6784\u9020\u7684\u6700\u5c0f\u65f6\u523b\u3002\n
    \n\n

     

    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string nextClosestTime(string time) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String nextClosestTime(String time) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def nextClosestTime(self, time):\n \"\"\"\n :type time: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def nextClosestTime(self, time: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * nextClosestTime(char * time){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string NextClosestTime(string time) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} time\n * @return {string}\n */\nvar nextClosestTime = function(time) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} time\n# @return {String}\ndef next_closest_time(time)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func nextClosestTime(_ time: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func nextClosestTime(time string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def nextClosestTime(time: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun nextClosestTime(time: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn next_closest_time(time: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $time\n * @return String\n */\n function nextClosestTime($time) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function nextClosestTime(time: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (next-closest-time time)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0681](https://leetcode-cn.com/problems/next-closest-time)", "[\u6700\u8fd1\u65f6\u523b](/solution/0600-0699/0681.Next%20Closest%20Time/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0681](https://leetcode.com/problems/next-closest-time)", "[Next Closest Time](/solution/0600-0699/0681.Next%20Closest%20Time/README_EN.md)", "`String`", "Medium", "\ud83d\udd12"]}, {"question_id": "0680", "frontend_question_id": "0680", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/valid-palindrome-ii", "url_en": "https://leetcode.com/problems/valid-palindrome-ii", "relative_path_cn": "/solution/0600-0699/0680.Valid%20Palindrome%20II/README.md", "relative_path_en": "/solution/0600-0699/0680.Valid%20Palindrome%20II/README_EN.md", "title_cn": "\u9a8c\u8bc1\u56de\u6587\u5b57\u7b26\u4e32 \u2161", "title_en": "Valid Palindrome II", "question_title_slug": "valid-palindrome-ii", "content_en": "

    Given a string s, return true if the s can be palindrome after deleting at most one character from it.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "aba"\nOutput: true\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "abca"\nOutput: true\nExplanation: You could delete the character 'c'.\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "abc"\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 105
    • \n\t
    • s consists of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u7a7a\u5b57\u7b26\u4e32 s\uff0c\u6700\u591a\u5220\u9664\u4e00\u4e2a\u5b57\u7b26\u3002\u5224\u65ad\u662f\u5426\u80fd\u6210\u4e3a\u56de\u6587\u5b57\u7b26\u4e32\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: "aba"\n\u8f93\u51fa: True\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: "abca"\n\u8f93\u51fa: True\n\u89e3\u91ca: \u4f60\u53ef\u4ee5\u5220\u9664c\u5b57\u7b26\u3002\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u5b57\u7b26\u4e32\u53ea\u5305\u542b\u4ece a-z \u7684\u5c0f\u5199\u5b57\u6bcd\u3002\u5b57\u7b26\u4e32\u7684\u6700\u5927\u957f\u5ea6\u662f50000\u3002
    2. \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool validPalindrome(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean validPalindrome(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def validPalindrome(self, s):\n \"\"\"\n :type s: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def validPalindrome(self, s: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool validPalindrome(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool ValidPalindrome(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {boolean}\n */\nvar validPalindrome = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Boolean}\ndef valid_palindrome(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func validPalindrome(_ s: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func validPalindrome(s string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def validPalindrome(s: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun validPalindrome(s: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn valid_palindrome(s: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Boolean\n */\n function validPalindrome($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function validPalindrome(s: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (valid-palindrome s)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0680](https://leetcode-cn.com/problems/valid-palindrome-ii)", "[\u9a8c\u8bc1\u56de\u6587\u5b57\u7b26\u4e32 \u2161](/solution/0600-0699/0680.Valid%20Palindrome%20II/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0680](https://leetcode.com/problems/valid-palindrome-ii)", "[Valid Palindrome II](/solution/0600-0699/0680.Valid%20Palindrome%20II/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "0679", "frontend_question_id": "0679", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/24-game", "url_en": "https://leetcode.com/problems/24-game", "relative_path_cn": "/solution/0600-0699/0679.24%20Game/README.md", "relative_path_en": "/solution/0600-0699/0679.24%20Game/README_EN.md", "title_cn": "24 \u70b9\u6e38\u620f", "title_en": "24 Game", "question_title_slug": "24-game", "content_en": "

    You are given an integer array cards of length 4. You have four cards, each containing a number in the range [1, 9]. You should arrange the numbers on these cards in a mathematical expression using the operators ['+', '-', '*', '/'] and the parentheses '(' and ')' to get the value 24.

    \n\n

    You are restricted with the following rules:

    \n\n
      \n\t
    • The division operator '/' represents real division, not integer division.\n\n\t
        \n\t\t
      • For example, 4 / (1 - 2 / 3) = 4 / (1 / 3) = 12.
      • \n\t
      \n\t
    • \n\t
    • Every operation done is between two numbers. In particular, we cannot use '-' as a unary operator.\n\t
        \n\t\t
      • For example, if cards = [1, 1, 1, 1], the expression "-1 - 1 - 1 - 1" is not allowed.
      • \n\t
      \n\t
    • \n\t
    • You cannot concatenate numbers together\n\t
        \n\t\t
      • For example, if cards = [1, 2, 1, 2], the expression "12 + 12" is not valid.
      • \n\t
      \n\t
    • \n
    \n\n

    Return true if you can get such expression that evaluates to 24, and false otherwise.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: cards = [4,1,8,7]\nOutput: true\nExplanation: (8-4) * (7-1) = 24\n
    \n\n

    Example 2:

    \n\n
    \nInput: cards = [1,2,1,2]\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • cards.length == 4
    • \n\t
    • 1 <= cards[i] <= 9
    • \n
    \n", "content_cn": "

    \u4f60\u6709 4 \u5f20\u5199\u6709 1 \u5230 9 \u6570\u5b57\u7684\u724c\u3002\u4f60\u9700\u8981\u5224\u65ad\u662f\u5426\u80fd\u901a\u8fc7 *\uff0c/\uff0c+\uff0c-\uff0c(\uff0c) \u7684\u8fd0\u7b97\u5f97\u5230 24\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: [4, 1, 8, 7]\n\u8f93\u51fa: True\n\u89e3\u91ca: (8-4) * (7-1) = 24\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: [1, 2, 1, 2]\n\u8f93\u51fa: False\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u9664\u6cd5\u8fd0\u7b97\u7b26 / \u8868\u793a\u5b9e\u6570\u9664\u6cd5\uff0c\u800c\u4e0d\u662f\u6574\u6570\u9664\u6cd5\u3002\u4f8b\u5982 4 / (1 - 2/3) = 12 \u3002
    2. \n\t
    3. \u6bcf\u4e2a\u8fd0\u7b97\u7b26\u5bf9\u4e24\u4e2a\u6570\u8fdb\u884c\u8fd0\u7b97\u3002\u7279\u522b\u662f\u6211\u4eec\u4e0d\u80fd\u7528 - \u4f5c\u4e3a\u4e00\u5143\u8fd0\u7b97\u7b26\u3002\u4f8b\u5982\uff0c[1, 1, 1, 1] \u4f5c\u4e3a\u8f93\u5165\u65f6\uff0c\u8868\u8fbe\u5f0f -1 - 1 - 1 - 1 \u662f\u4e0d\u5141\u8bb8\u7684\u3002
    4. \n\t
    5. \u4f60\u4e0d\u80fd\u5c06\u6570\u5b57\u8fde\u63a5\u5728\u4e00\u8d77\u3002\u4f8b\u5982\uff0c\u8f93\u5165\u4e3a [1, 2, 1, 2] \u65f6\uff0c\u4e0d\u80fd\u5199\u6210 12 + 12 \u3002
    6. \n
    \n", "tags_en": ["Depth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool judgePoint24(vector& cards) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean judgePoint24(int[] cards) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def judgePoint24(self, cards):\n \"\"\"\n :type cards: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def judgePoint24(self, cards: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool judgePoint24(int* cards, int cardsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool JudgePoint24(int[] cards) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} cards\n * @return {boolean}\n */\nvar judgePoint24 = function(cards) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} cards\n# @return {Boolean}\ndef judge_point24(cards)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func judgePoint24(_ cards: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func judgePoint24(cards []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def judgePoint24(cards: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun judgePoint24(cards: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn judge_point24(cards: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $cards\n * @return Boolean\n */\n function judgePoint24($cards) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function judgePoint24(cards: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (judge-point24 cards)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0679](https://leetcode-cn.com/problems/24-game)", "[24 \u70b9\u6e38\u620f](/solution/0600-0699/0679.24%20Game/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[0679](https://leetcode.com/problems/24-game)", "[24 Game](/solution/0600-0699/0679.24%20Game/README_EN.md)", "`Depth-first Search`", "Hard", ""]}, {"question_id": "0678", "frontend_question_id": "0678", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/valid-parenthesis-string", "url_en": "https://leetcode.com/problems/valid-parenthesis-string", "relative_path_cn": "/solution/0600-0699/0678.Valid%20Parenthesis%20String/README.md", "relative_path_en": "/solution/0600-0699/0678.Valid%20Parenthesis%20String/README_EN.md", "title_cn": "\u6709\u6548\u7684\u62ec\u53f7\u5b57\u7b26\u4e32", "title_en": "Valid Parenthesis String", "question_title_slug": "valid-parenthesis-string", "content_en": "

    Given a string s containing only three types of characters: '(', ')' and '*', return true if s is valid.

    \n\n

    The following rules define a valid string:

    \n\n
      \n\t
    • Any left parenthesis '(' must have a corresponding right parenthesis ')'.
    • \n\t
    • Any right parenthesis ')' must have a corresponding left parenthesis '('.
    • \n\t
    • Left parenthesis '(' must go before the corresponding right parenthesis ')'.
    • \n\t
    • '*' could be treated as a single right parenthesis ')' or a single left parenthesis '(' or an empty string "".
    • \n
    \n\n

     

    \n

    Example 1:

    \n
    Input: s = \"()\"\nOutput: true\n

    Example 2:

    \n
    Input: s = \"(*)\"\nOutput: true\n

    Example 3:

    \n
    Input: s = \"(*))\"\nOutput: true\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 100
    • \n\t
    • s[i] is '(', ')' or '*'.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u53ea\u5305\u542b\u4e09\u79cd\u5b57\u7b26\u7684\u5b57\u7b26\u4e32\uff1a\uff08 \uff0c\uff09 \u548c *\uff0c\u5199\u4e00\u4e2a\u51fd\u6570\u6765\u68c0\u9a8c\u8fd9\u4e2a\u5b57\u7b26\u4e32\u662f\u5426\u4e3a\u6709\u6548\u5b57\u7b26\u4e32\u3002\u6709\u6548\u5b57\u7b26\u4e32\u5177\u6709\u5982\u4e0b\u89c4\u5219\uff1a

    \n\n
      \n\t
    1. \u4efb\u4f55\u5de6\u62ec\u53f7 ( \u5fc5\u987b\u6709\u76f8\u5e94\u7684\u53f3\u62ec\u53f7 )\u3002
    2. \n\t
    3. \u4efb\u4f55\u53f3\u62ec\u53f7 ) \u5fc5\u987b\u6709\u76f8\u5e94\u7684\u5de6\u62ec\u53f7 ( \u3002
    4. \n\t
    5. \u5de6\u62ec\u53f7 ( \u5fc5\u987b\u5728\u5bf9\u5e94\u7684\u53f3\u62ec\u53f7\u4e4b\u524d )\u3002
    6. \n\t
    7. * \u53ef\u4ee5\u88ab\u89c6\u4e3a\u5355\u4e2a\u53f3\u62ec\u53f7 ) \uff0c\u6216\u5355\u4e2a\u5de6\u62ec\u53f7 ( \uff0c\u6216\u4e00\u4e2a\u7a7a\u5b57\u7b26\u4e32\u3002
    8. \n\t
    9. \u4e00\u4e2a\u7a7a\u5b57\u7b26\u4e32\u4e5f\u88ab\u89c6\u4e3a\u6709\u6548\u5b57\u7b26\u4e32\u3002
    10. \n
    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: "()"\n\u8f93\u51fa: True\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: "(*)"\n\u8f93\u51fa: True\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \n\u8f93\u5165: "(*))"\n\u8f93\u51fa: True\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u5b57\u7b26\u4e32\u5927\u5c0f\u5c06\u5728 [1\uff0c100] \u8303\u56f4\u5185\u3002
    2. \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool checkValidString(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean checkValidString(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def checkValidString(self, s):\n \"\"\"\n :type s: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def checkValidString(self, s: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool checkValidString(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CheckValidString(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {boolean}\n */\nvar checkValidString = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Boolean}\ndef check_valid_string(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func checkValidString(_ s: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func checkValidString(s string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def checkValidString(s: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun checkValidString(s: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn check_valid_string(s: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Boolean\n */\n function checkValidString($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function checkValidString(s: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (check-valid-string s)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0678](https://leetcode-cn.com/problems/valid-parenthesis-string)", "[\u6709\u6548\u7684\u62ec\u53f7\u5b57\u7b26\u4e32](/solution/0600-0699/0678.Valid%20Parenthesis%20String/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0678](https://leetcode.com/problems/valid-parenthesis-string)", "[Valid Parenthesis String](/solution/0600-0699/0678.Valid%20Parenthesis%20String/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "0677", "frontend_question_id": "0677", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/map-sum-pairs", "url_en": "https://leetcode.com/problems/map-sum-pairs", "relative_path_cn": "/solution/0600-0699/0677.Map%20Sum%20Pairs/README.md", "relative_path_en": "/solution/0600-0699/0677.Map%20Sum%20Pairs/README_EN.md", "title_cn": "\u952e\u503c\u6620\u5c04", "title_en": "Map Sum Pairs", "question_title_slug": "map-sum-pairs", "content_en": "

    Implement the MapSum class:

    \n\n
      \n\t
    • MapSum() Initializes the MapSum object.
    • \n\t
    • void insert(String key, int val) Inserts the key-val pair into the map. If the key already existed, the original key-value pair will be overridden to the new one.
    • \n\t
    • int sum(string prefix) Returns the sum of all the pairs' value whose key starts with the prefix.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["MapSum", "insert", "sum", "insert", "sum"]\n[[], ["apple", 3], ["ap"], ["app", 2], ["ap"]]\nOutput\n[null, null, 3, null, 5]\n\nExplanation\nMapSum mapSum = new MapSum();\nmapSum.insert("apple", 3);  \nmapSum.sum("ap");           // return 3 (apple = 3)\nmapSum.insert("app", 2);    \nmapSum.sum("ap");           // return 5 (apple + app = 3 + 2 = 5)\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= key.length, prefix.length <= 50
    • \n\t
    • key and prefix consist of only lowercase English letters.
    • \n\t
    • 1 <= val <= 1000
    • \n\t
    • At most 50 calls will be made to insert and sum.
    • \n
    \n", "content_cn": "

    \u5b9e\u73b0\u4e00\u4e2a MapSum \u7c7b\uff0c\u652f\u6301\u4e24\u4e2a\u65b9\u6cd5\uff0cinsert\u00a0\u548c\u00a0sum\uff1a

    \n\n
      \n\t
    • MapSum() \u521d\u59cb\u5316 MapSum \u5bf9\u8c61
    • \n\t
    • void insert(String key, int val) \u63d2\u5165 key-val \u952e\u503c\u5bf9\uff0c\u5b57\u7b26\u4e32\u8868\u793a\u952e key \uff0c\u6574\u6570\u8868\u793a\u503c val \u3002\u5982\u679c\u952e key \u5df2\u7ecf\u5b58\u5728\uff0c\u90a3\u4e48\u539f\u6765\u7684\u952e\u503c\u5bf9\u5c06\u88ab\u66ff\u4ee3\u6210\u65b0\u7684\u952e\u503c\u5bf9\u3002
    • \n\t
    • int sum(string prefix) \u8fd4\u56de\u6240\u6709\u4ee5\u8be5\u524d\u7f00 prefix \u5f00\u5934\u7684\u952e key \u7684\u503c\u7684\u603b\u548c\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\n[\"MapSum\", \"insert\", \"sum\", \"insert\", \"sum\"]\n[[], [\"apple\", 3], [\"ap\"], [\"app\", 2], [\"ap\"]]\n\u8f93\u51fa\uff1a\n[null, null, 3, null, 5]\n\n\u89e3\u91ca\uff1a\nMapSum mapSum = new MapSum();\nmapSum.insert(\"apple\", 3);  \nmapSum.sum(\"ap\");           // return 3 (apple = 3)\nmapSum.insert(\"app\", 2);    \nmapSum.sum(\"ap\");           // return 5 (apple + app = 3 + 2 = 5)\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= key.length, prefix.length <= 50
    • \n\t
    • key \u548c prefix \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n\t
    • 1 <= val <= 1000
    • \n\t
    • \u6700\u591a\u8c03\u7528 50 \u6b21 insert \u548c sum
    • \n
    \n", "tags_en": ["Trie"], "tags_cn": ["\u5b57\u5178\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class MapSum {\npublic:\n /** Initialize your data structure here. */\n MapSum() {\n\n }\n \n void insert(string key, int val) {\n\n }\n \n int sum(string prefix) {\n\n }\n};\n\n/**\n * Your MapSum object will be instantiated and called as such:\n * MapSum* obj = new MapSum();\n * obj->insert(key,val);\n * int param_2 = obj->sum(prefix);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class MapSum {\n\n /** Initialize your data structure here. */\n public MapSum() {\n\n }\n \n public void insert(String key, int val) {\n\n }\n \n public int sum(String prefix) {\n\n }\n}\n\n/**\n * Your MapSum object will be instantiated and called as such:\n * MapSum obj = new MapSum();\n * obj.insert(key,val);\n * int param_2 = obj.sum(prefix);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class MapSum(object):\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def insert(self, key, val):\n \"\"\"\n :type key: str\n :type val: int\n :rtype: None\n \"\"\"\n\n\n def sum(self, prefix):\n \"\"\"\n :type prefix: str\n :rtype: int\n \"\"\"\n\n\n\n# Your MapSum object will be instantiated and called as such:\n# obj = MapSum()\n# obj.insert(key,val)\n# param_2 = obj.sum(prefix)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class MapSum:\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def insert(self, key: str, val: int) -> None:\n\n\n def sum(self, prefix: str) -> int:\n\n\n\n# Your MapSum object will be instantiated and called as such:\n# obj = MapSum()\n# obj.insert(key,val)\n# param_2 = obj.sum(prefix)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} MapSum;\n\n/** Initialize your data structure here. */\n\nMapSum* mapSumCreate() {\n \n}\n\nvoid mapSumInsert(MapSum* obj, char * key, int val) {\n \n}\n\nint mapSumSum(MapSum* obj, char * prefix) {\n \n}\n\nvoid mapSumFree(MapSum* obj) {\n \n}\n\n/**\n * Your MapSum struct will be instantiated and called as such:\n * MapSum* obj = mapSumCreate();\n * mapSumInsert(obj, key, val);\n \n * int param_2 = mapSumSum(obj, prefix);\n \n * mapSumFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class MapSum {\n\n /** Initialize your data structure here. */\n public MapSum() {\n\n }\n \n public void Insert(string key, int val) {\n\n }\n \n public int Sum(string prefix) {\n\n }\n}\n\n/**\n * Your MapSum object will be instantiated and called as such:\n * MapSum obj = new MapSum();\n * obj.Insert(key,val);\n * int param_2 = obj.Sum(prefix);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Initialize your data structure here.\n */\nvar MapSum = function() {\n\n};\n\n/** \n * @param {string} key \n * @param {number} val\n * @return {void}\n */\nMapSum.prototype.insert = function(key, val) {\n\n};\n\n/** \n * @param {string} prefix\n * @return {number}\n */\nMapSum.prototype.sum = function(prefix) {\n\n};\n\n/**\n * Your MapSum object will be instantiated and called as such:\n * var obj = new MapSum()\n * obj.insert(key,val)\n * var param_2 = obj.sum(prefix)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class MapSum\n\n=begin\n Initialize your data structure here.\n=end\n def initialize()\n\n end\n\n\n=begin\n :type key: String\n :type val: Integer\n :rtype: Void\n=end\n def insert(key, val)\n\n end\n\n\n=begin\n :type prefix: String\n :rtype: Integer\n=end\n def sum(prefix)\n\n end\n\n\nend\n\n# Your MapSum object will be instantiated and called as such:\n# obj = MapSum.new()\n# obj.insert(key, val)\n# param_2 = obj.sum(prefix)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass MapSum {\n\n /** Initialize your data structure here. */\n init() {\n\n }\n \n func insert(_ key: String, _ val: Int) {\n\n }\n \n func sum(_ prefix: String) -> Int {\n\n }\n}\n\n/**\n * Your MapSum object will be instantiated and called as such:\n * let obj = MapSum()\n * obj.insert(key, val)\n * let ret_2: Int = obj.sum(prefix)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type MapSum struct {\n\n}\n\n\n/** Initialize your data structure here. */\nfunc Constructor() MapSum {\n\n}\n\n\nfunc (this *MapSum) Insert(key string, val int) {\n\n}\n\n\nfunc (this *MapSum) Sum(prefix string) int {\n\n}\n\n\n/**\n * Your MapSum object will be instantiated and called as such:\n * obj := Constructor();\n * obj.Insert(key,val);\n * param_2 := obj.Sum(prefix);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class MapSum() {\n\n /** Initialize your data structure here. */\n\n\n def insert(key: String, `val`: Int) {\n\n }\n\n def sum(prefix: String): Int = {\n\n }\n\n}\n\n/**\n * Your MapSum object will be instantiated and called as such:\n * var obj = new MapSum()\n * obj.insert(key,`val`)\n * var param_2 = obj.sum(prefix)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class MapSum() {\n\n /** Initialize your data structure here. */\n\n\n fun insert(key: String, `val`: Int) {\n\n }\n\n fun sum(prefix: String): Int {\n\n }\n\n}\n\n/**\n * Your MapSum object will be instantiated and called as such:\n * var obj = MapSum()\n * obj.insert(key,`val`)\n * var param_2 = obj.sum(prefix)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct MapSum {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl MapSum {\n\n /** Initialize your data structure here. */\n fn new() -> Self {\n\n }\n \n fn insert(&self, key: String, val: i32) {\n\n }\n \n fn sum(&self, prefix: String) -> i32 {\n\n }\n}\n\n/**\n * Your MapSum object will be instantiated and called as such:\n * let obj = MapSum::new();\n * obj.insert(key, val);\n * let ret_2: i32 = obj.sum(prefix);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class MapSum {\n /**\n * Initialize your data structure here.\n */\n function __construct() {\n\n }\n\n /**\n * @param String $key\n * @param Integer $val\n * @return NULL\n */\n function insert($key, $val) {\n\n }\n\n /**\n * @param String $prefix\n * @return Integer\n */\n function sum($prefix) {\n\n }\n}\n\n/**\n * Your MapSum object will be instantiated and called as such:\n * $obj = MapSum();\n * $obj->insert($key, $val);\n * $ret_2 = $obj->sum($prefix);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class MapSum {\n constructor() {\n\n }\n\n insert(key: string, val: number): void {\n\n }\n\n sum(prefix: string): number {\n\n }\n}\n\n/**\n * Your MapSum object will be instantiated and called as such:\n * var obj = new MapSum()\n * obj.insert(key,val)\n * var param_2 = obj.sum(prefix)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define map-sum%\n (class object%\n (super-new)\n (init-field)\n \n ; insert : string? exact-integer? -> void?\n (define/public (insert key val)\n\n )\n ; sum : string? -> exact-integer?\n (define/public (sum prefix)\n\n )))\n\n;; Your map-sum% object will be instantiated and called as such:\n;; (define obj (new map-sum%))\n;; (send obj insert key val)\n;; (define param_2 (send obj sum prefix))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0677](https://leetcode-cn.com/problems/map-sum-pairs)", "[\u952e\u503c\u6620\u5c04](/solution/0600-0699/0677.Map%20Sum%20Pairs/README.md)", "`\u5b57\u5178\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0677](https://leetcode.com/problems/map-sum-pairs)", "[Map Sum Pairs](/solution/0600-0699/0677.Map%20Sum%20Pairs/README_EN.md)", "`Trie`", "Medium", ""]}, {"question_id": "0676", "frontend_question_id": "0676", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/implement-magic-dictionary", "url_en": "https://leetcode.com/problems/implement-magic-dictionary", "relative_path_cn": "/solution/0600-0699/0676.Implement%20Magic%20Dictionary/README.md", "relative_path_en": "/solution/0600-0699/0676.Implement%20Magic%20Dictionary/README_EN.md", "title_cn": "\u5b9e\u73b0\u4e00\u4e2a\u9b54\u6cd5\u5b57\u5178", "title_en": "Implement Magic Dictionary", "question_title_slug": "implement-magic-dictionary", "content_en": "

    Design a data structure that is initialized with a list of different words. Provided a string, you should determine if you can change exactly one character in this string to match any word in the data structure.

    \n\n

    Implement the MagicDictionary class:

    \n\n
      \n\t
    • MagicDictionary() Initializes the object.
    • \n\t
    • void buildDict(String[] dictionary) Sets the data structure with an array of distinct strings dictionary.
    • \n\t
    • bool search(String searchWord) Returns true if you can change exactly one character in searchWord to match any string in the data structure, otherwise returns false.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["MagicDictionary", "buildDict", "search", "search", "search", "search"]\n[[], [["hello", "leetcode"]], ["hello"], ["hhllo"], ["hell"], ["leetcoded"]]\nOutput\n[null, null, false, true, false, false]\n\nExplanation\nMagicDictionary magicDictionary = new MagicDictionary();\nmagicDictionary.buildDict(["hello", "leetcode"]);\nmagicDictionary.search("hello"); // return False\nmagicDictionary.search("hhllo"); // We can change the second 'h' to 'e' to match "hello" so we return True\nmagicDictionary.search("hell"); // return False\nmagicDictionary.search("leetcoded"); // return False\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= dictionary.length <= 100
    • \n\t
    • 1 <= dictionary[i].length <= 100
    • \n\t
    • dictionary[i] consists of only lower-case English letters.
    • \n\t
    • All the strings in dictionary are distinct.
    • \n\t
    • 1 <= searchWord.length <= 100
    • \n\t
    • searchWord consists of only lower-case English letters.
    • \n\t
    • buildDict will be called only once before search.
    • \n\t
    • At most 100 calls will be made to search.
    • \n
    \n", "content_cn": "

    \u8bbe\u8ba1\u4e00\u4e2a\u4f7f\u7528\u5355\u8bcd\u5217\u8868\u8fdb\u884c\u521d\u59cb\u5316\u7684\u6570\u636e\u7ed3\u6784\uff0c\u5355\u8bcd\u5217\u8868\u4e2d\u7684\u5355\u8bcd \u4e92\u4e0d\u76f8\u540c \u3002 \u5982\u679c\u7ed9\u51fa\u4e00\u4e2a\u5355\u8bcd\uff0c\u8bf7\u5224\u5b9a\u80fd\u5426\u53ea\u5c06\u8fd9\u4e2a\u5355\u8bcd\u4e2d\u4e00\u4e2a\u5b57\u6bcd\u6362\u6210\u53e6\u4e00\u4e2a\u5b57\u6bcd\uff0c\u4f7f\u5f97\u6240\u5f62\u6210\u7684\u65b0\u5355\u8bcd\u5b58\u5728\u4e8e\u4f60\u6784\u5efa\u7684\u5b57\u5178\u4e2d\u3002

    \n\n

    \u5b9e\u73b0 MagicDictionary \u7c7b\uff1a

    \n\n
      \n\t
    • MagicDictionary() \u521d\u59cb\u5316\u5bf9\u8c61
    • \n\t
    • void buildDict(String[]\u00a0dictionary) \u4f7f\u7528\u5b57\u7b26\u4e32\u6570\u7ec4\u00a0dictionary \u8bbe\u5b9a\u8be5\u6570\u636e\u7ed3\u6784\uff0cdictionary \u4e2d\u7684\u5b57\u7b26\u4e32\u4e92\u4e0d\u76f8\u540c
    • \n\t
    • bool search(String searchWord) \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32 searchWord \uff0c\u5224\u5b9a\u80fd\u5426\u53ea\u5c06\u5b57\u7b26\u4e32\u4e2d \u4e00\u4e2a \u5b57\u6bcd\u6362\u6210\u53e6\u4e00\u4e2a\u5b57\u6bcd\uff0c\u4f7f\u5f97\u6240\u5f62\u6210\u7684\u65b0\u5b57\u7b26\u4e32\u80fd\u591f\u4e0e\u5b57\u5178\u4e2d\u7684\u4efb\u4e00\u5b57\u7b26\u4e32\u5339\u914d\u3002\u5982\u679c\u53ef\u4ee5\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002
    • \n
    \n\n

    \u00a0

    \n\n
    \n
    \n
    \n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\n[\"MagicDictionary\", \"buildDict\", \"search\", \"search\", \"search\", \"search\"]\n[[], [[\"hello\", \"leetcode\"]], [\"hello\"], [\"hhllo\"], [\"hell\"], [\"leetcoded\"]]\n\u8f93\u51fa\n[null, null, false, true, false, false]\n\n\u89e3\u91ca\nMagicDictionary magicDictionary = new MagicDictionary();\nmagicDictionary.buildDict([\"hello\", \"leetcode\"]);\nmagicDictionary.search(\"hello\"); // \u8fd4\u56de False\nmagicDictionary.search(\"hhllo\"); // \u5c06\u7b2c\u4e8c\u4e2a 'h' \u66ff\u6362\u4e3a 'e' \u53ef\u4ee5\u5339\u914d \"hello\" \uff0c\u6240\u4ee5\u8fd4\u56de True\nmagicDictionary.search(\"hell\"); // \u8fd4\u56de False\nmagicDictionary.search(\"leetcoded\"); // \u8fd4\u56de False\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <=\u00a0dictionary.length <= 100
    • \n\t
    • 1 <=\u00a0dictionary[i].length <= 100
    • \n\t
    • dictionary[i] \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n\t
    • dictionary \u4e2d\u7684\u6240\u6709\u5b57\u7b26\u4e32 \u4e92\u4e0d\u76f8\u540c
    • \n\t
    • 1 <=\u00a0searchWord.length <= 100
    • \n\t
    • searchWord \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n\t
    • buildDict \u4ec5\u5728 search \u4e4b\u524d\u8c03\u7528\u4e00\u6b21
    • \n\t
    • \u6700\u591a\u8c03\u7528 100 \u6b21 search
    • \n
    \n
    \n
    \n
    \n", "tags_en": ["Trie", "Hash Table"], "tags_cn": ["\u5b57\u5178\u6811", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class MagicDictionary {\npublic:\n /** Initialize your data structure here. */\n MagicDictionary() {\n\n }\n \n void buildDict(vector dictionary) {\n\n }\n \n bool search(string searchWord) {\n\n }\n};\n\n/**\n * Your MagicDictionary object will be instantiated and called as such:\n * MagicDictionary* obj = new MagicDictionary();\n * obj->buildDict(dictionary);\n * bool param_2 = obj->search(searchWord);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class MagicDictionary {\n\n /** Initialize your data structure here. */\n public MagicDictionary() {\n\n }\n \n public void buildDict(String[] dictionary) {\n\n }\n \n public boolean search(String searchWord) {\n\n }\n}\n\n/**\n * Your MagicDictionary object will be instantiated and called as such:\n * MagicDictionary obj = new MagicDictionary();\n * obj.buildDict(dictionary);\n * boolean param_2 = obj.search(searchWord);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class MagicDictionary(object):\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def buildDict(self, dictionary):\n \"\"\"\n :type dictionary: List[str]\n :rtype: None\n \"\"\"\n\n\n def search(self, searchWord):\n \"\"\"\n :type searchWord: str\n :rtype: bool\n \"\"\"\n\n\n\n# Your MagicDictionary object will be instantiated and called as such:\n# obj = MagicDictionary()\n# obj.buildDict(dictionary)\n# param_2 = obj.search(searchWord)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class MagicDictionary:\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def buildDict(self, dictionary: List[str]) -> None:\n\n\n def search(self, searchWord: str) -> bool:\n\n\n\n# Your MagicDictionary object will be instantiated and called as such:\n# obj = MagicDictionary()\n# obj.buildDict(dictionary)\n# param_2 = obj.search(searchWord)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} MagicDictionary;\n\n/** Initialize your data structure here. */\n\nMagicDictionary* magicDictionaryCreate() {\n \n}\n\nvoid magicDictionaryBuildDict(MagicDictionary* obj, char ** dictionary, int dictionarySize) {\n \n}\n\nbool magicDictionarySearch(MagicDictionary* obj, char * searchWord) {\n \n}\n\nvoid magicDictionaryFree(MagicDictionary* obj) {\n \n}\n\n/**\n * Your MagicDictionary struct will be instantiated and called as such:\n * MagicDictionary* obj = magicDictionaryCreate();\n * magicDictionaryBuildDict(obj, dictionary, dictionarySize);\n \n * bool param_2 = magicDictionarySearch(obj, searchWord);\n \n * magicDictionaryFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class MagicDictionary {\n\n /** Initialize your data structure here. */\n public MagicDictionary() {\n\n }\n \n public void BuildDict(string[] dictionary) {\n\n }\n \n public bool Search(string searchWord) {\n\n }\n}\n\n/**\n * Your MagicDictionary object will be instantiated and called as such:\n * MagicDictionary obj = new MagicDictionary();\n * obj.BuildDict(dictionary);\n * bool param_2 = obj.Search(searchWord);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Initialize your data structure here.\n */\nvar MagicDictionary = function() {\n\n};\n\n/** \n * @param {string[]} dictionary\n * @return {void}\n */\nMagicDictionary.prototype.buildDict = function(dictionary) {\n\n};\n\n/** \n * @param {string} searchWord\n * @return {boolean}\n */\nMagicDictionary.prototype.search = function(searchWord) {\n\n};\n\n/**\n * Your MagicDictionary object will be instantiated and called as such:\n * var obj = new MagicDictionary()\n * obj.buildDict(dictionary)\n * var param_2 = obj.search(searchWord)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class MagicDictionary\n\n=begin\n Initialize your data structure here.\n=end\n def initialize()\n\n end\n\n\n=begin\n :type dictionary: String[]\n :rtype: Void\n=end\n def build_dict(dictionary)\n\n end\n\n\n=begin\n :type search_word: String\n :rtype: Boolean\n=end\n def search(search_word)\n\n end\n\n\nend\n\n# Your MagicDictionary object will be instantiated and called as such:\n# obj = MagicDictionary.new()\n# obj.build_dict(dictionary)\n# param_2 = obj.search(search_word)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass MagicDictionary {\n\n /** Initialize your data structure here. */\n init() {\n \n }\n \n func buildDict(_ dictionary: [String]) {\n \n }\n \n func search(_ searchWord: String) -> Bool {\n \n }\n}\n\n/**\n * Your MagicDictionary object will be instantiated and called as such:\n * let obj = MagicDictionary()\n * obj.buildDict(dictionary)\n * let ret_2: Bool = obj.search(searchWord)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type MagicDictionary struct {\n\n}\n\n\n/** Initialize your data structure here. */\nfunc Constructor() MagicDictionary {\n\n}\n\n\nfunc (this *MagicDictionary) BuildDict(dictionary []string) {\n\n}\n\n\nfunc (this *MagicDictionary) Search(searchWord string) bool {\n\n}\n\n\n/**\n * Your MagicDictionary object will be instantiated and called as such:\n * obj := Constructor();\n * obj.BuildDict(dictionary);\n * param_2 := obj.Search(searchWord);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class MagicDictionary() {\n\n /** Initialize your data structure here. */\n\n\n def buildDict(dictionary: Array[String]) {\n\n }\n\n def search(searchWord: String): Boolean = {\n\n }\n\n}\n\n/**\n * Your MagicDictionary object will be instantiated and called as such:\n * var obj = new MagicDictionary()\n * obj.buildDict(dictionary)\n * var param_2 = obj.search(searchWord)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class MagicDictionary() {\n\n /** Initialize your data structure here. */\n\n\n fun buildDict(dictionary: Array) {\n\n }\n\n fun search(searchWord: String): Boolean {\n\n }\n\n}\n\n/**\n * Your MagicDictionary object will be instantiated and called as such:\n * var obj = MagicDictionary()\n * obj.buildDict(dictionary)\n * var param_2 = obj.search(searchWord)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct MagicDictionary {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl MagicDictionary {\n\n /** Initialize your data structure here. */\n fn new() -> Self {\n\n }\n \n fn build_dict(&self, dictionary: Vec) {\n\n }\n \n fn search(&self, search_word: String) -> bool {\n\n }\n}\n\n/**\n * Your MagicDictionary object will be instantiated and called as such:\n * let obj = MagicDictionary::new();\n * obj.build_dict(dictionary);\n * let ret_2: bool = obj.search(searchWord);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class MagicDictionary {\n /**\n * Initialize your data structure here.\n */\n function __construct() {\n\n }\n\n /**\n * @param String[] $dictionary\n * @return NULL\n */\n function buildDict($dictionary) {\n\n }\n\n /**\n * @param String $searchWord\n * @return Boolean\n */\n function search($searchWord) {\n\n }\n}\n\n/**\n * Your MagicDictionary object will be instantiated and called as such:\n * $obj = MagicDictionary();\n * $obj->buildDict($dictionary);\n * $ret_2 = $obj->search($searchWord);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class MagicDictionary {\n constructor() {\n\n }\n\n buildDict(dictionary: string[]): void {\n\n }\n\n search(searchWord: string): boolean {\n\n }\n}\n\n/**\n * Your MagicDictionary object will be instantiated and called as such:\n * var obj = new MagicDictionary()\n * obj.buildDict(dictionary)\n * var param_2 = obj.search(searchWord)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define magic-dictionary%\n (class object%\n (super-new)\n (init-field)\n \n ; build-dict : (listof string?) -> void?\n (define/public (build-dict dictionary)\n\n )\n ; search : string? -> boolean?\n (define/public (search searchWord)\n\n )))\n\n;; Your magic-dictionary% object will be instantiated and called as such:\n;; (define obj (new magic-dictionary%))\n;; (send obj build-dict dictionary)\n;; (define param_2 (send obj search search-word))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0676](https://leetcode-cn.com/problems/implement-magic-dictionary)", "[\u5b9e\u73b0\u4e00\u4e2a\u9b54\u6cd5\u5b57\u5178](/solution/0600-0699/0676.Implement%20Magic%20Dictionary/README.md)", "`\u5b57\u5178\u6811`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0676](https://leetcode.com/problems/implement-magic-dictionary)", "[Implement Magic Dictionary](/solution/0600-0699/0676.Implement%20Magic%20Dictionary/README_EN.md)", "`Trie`,`Hash Table`", "Medium", ""]}, {"question_id": "0675", "frontend_question_id": "0675", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/cut-off-trees-for-golf-event", "url_en": "https://leetcode.com/problems/cut-off-trees-for-golf-event", "relative_path_cn": "/solution/0600-0699/0675.Cut%20Off%20Trees%20for%20Golf%20Event/README.md", "relative_path_en": "/solution/0600-0699/0675.Cut%20Off%20Trees%20for%20Golf%20Event/README_EN.md", "title_cn": "\u4e3a\u9ad8\u5c14\u592b\u6bd4\u8d5b\u780d\u6811", "title_en": "Cut Off Trees for Golf Event", "question_title_slug": "cut-off-trees-for-golf-event", "content_en": "

    You are asked to cut off all the trees in a forest for a golf event. The forest is represented as an m x n matrix. In this matrix:

    \n\n
      \n\t
    • 0 means the cell cannot be walked through.
    • \n\t
    • 1 represents an empty cell that can be walked through.
    • \n\t
    • A number greater than 1 represents a tree in a cell that can be walked through, and this number is the tree's height.
    • \n
    \n\n

    In one step, you can walk in any of the four directions: north, east, south, and west. If you are standing in a cell with a tree, you can choose whether to cut it off.

    \n\n

    You must cut off the trees in order from shortest to tallest. When you cut off a tree, the value at its cell becomes 1 (an empty cell).

    \n\n

    Starting from the point (0, 0), return the minimum steps you need to walk to cut off all the trees. If you cannot cut off all the trees, return -1.

    \n\n

    You are guaranteed that no two trees have the same height, and there is at least one tree needs to be cut off.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: forest = [[1,2,3],[0,0,4],[7,6,5]]\nOutput: 6\nExplanation: Following the path above allows you to cut off the trees from shortest to tallest in 6 steps.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: forest = [[1,2,3],[0,0,0],[7,6,5]]\nOutput: -1\nExplanation: The trees in the bottom row cannot be accessed as the middle row is blocked.\n
    \n\n

    Example 3:

    \n\n
    \nInput: forest = [[2,3,4],[0,0,5],[8,7,6]]\nOutput: 6\nExplanation: You can follow the same path as Example 1 to cut off all the trees.\nNote that you can cut off the first tree at (0, 0) before making any steps.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == forest.length
    • \n\t
    • n == forest[i].length
    • \n\t
    • 1 <= m, n <= 50
    • \n\t
    • 0 <= forest[i][j] <= 109
    • \n
    \n", "content_cn": "

    \u4f60\u88ab\u8bf7\u6765\u7ed9\u4e00\u4e2a\u8981\u4e3e\u529e\u9ad8\u5c14\u592b\u6bd4\u8d5b\u7684\u6811\u6797\u780d\u6811\u3002\u6811\u6797\u7531\u4e00\u4e2a\u00a0m x n \u7684\u77e9\u9635\u8868\u793a\uff0c \u5728\u8fd9\u4e2a\u77e9\u9635\u4e2d\uff1a

    \n\n
      \n\t
    • 0 \u8868\u793a\u969c\u788d\uff0c\u65e0\u6cd5\u89e6\u78b0
    • \n\t
    • 1\u00a0\u8868\u793a\u5730\u9762\uff0c\u53ef\u4ee5\u884c\u8d70
    • \n\t
    • \u6bd4 1 \u5927\u7684\u6570\u00a0\u8868\u793a\u6709\u6811\u7684\u5355\u5143\u683c\uff0c\u53ef\u4ee5\u884c\u8d70\uff0c\u6570\u503c\u8868\u793a\u6811\u7684\u9ad8\u5ea6
    • \n
    \n\n

    \u6bcf\u4e00\u6b65\uff0c\u4f60\u90fd\u53ef\u4ee5\u5411\u4e0a\u3001\u4e0b\u3001\u5de6\u3001\u53f3\u56db\u4e2a\u65b9\u5411\u4e4b\u4e00\u79fb\u52a8\u4e00\u4e2a\u5355\u4f4d\uff0c\u5982\u679c\u4f60\u7ad9\u7684\u5730\u65b9\u6709\u4e00\u68f5\u6811\uff0c\u90a3\u4e48\u4f60\u53ef\u4ee5\u51b3\u5b9a\u662f\u5426\u8981\u780d\u5012\u5b83\u3002

    \n\n

    \u4f60\u9700\u8981\u6309\u7167\u6811\u7684\u9ad8\u5ea6\u4ece\u4f4e\u5411\u9ad8\u780d\u6389\u6240\u6709\u7684\u6811\uff0c\u6bcf\u780d\u8fc7\u4e00\u9897\u6811\uff0c\u8be5\u5355\u5143\u683c\u7684\u503c\u53d8\u4e3a 1\uff08\u5373\u53d8\u4e3a\u5730\u9762\uff09\u3002

    \n\n

    \u4f60\u5c06\u4ece (0, 0) \u70b9\u5f00\u59cb\u5de5\u4f5c\uff0c\u8fd4\u56de\u4f60\u780d\u5b8c\u6240\u6709\u6811\u9700\u8981\u8d70\u7684\u6700\u5c0f\u6b65\u6570\u3002 \u5982\u679c\u4f60\u65e0\u6cd5\u780d\u5b8c\u6240\u6709\u7684\u6811\uff0c\u8fd4\u56de -1 \u3002

    \n\n

    \u53ef\u4ee5\u4fdd\u8bc1\u7684\u662f\uff0c\u6ca1\u6709\u4e24\u68f5\u6811\u7684\u9ad8\u5ea6\u662f\u76f8\u540c\u7684\uff0c\u5e76\u4e14\u4f60\u81f3\u5c11\u9700\u8981\u780d\u5012\u4e00\u68f5\u6811\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aforest = [[1,2,3],[0,0,4],[7,6,5]]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u6cbf\u7740\u4e0a\u9762\u7684\u8def\u5f84\uff0c\u4f60\u53ef\u4ee5\u7528 6 \u6b65\uff0c\u6309\u4ece\u6700\u77ee\u5230\u6700\u9ad8\u7684\u987a\u5e8f\u780d\u6389\u8fd9\u4e9b\u6811\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aforest = [[1,2,3],[0,0,0],[7,6,5]]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u7531\u4e8e\u4e2d\u95f4\u4e00\u884c\u88ab\u969c\u788d\u963b\u585e\uff0c\u65e0\u6cd5\u8bbf\u95ee\u6700\u4e0b\u9762\u4e00\u884c\u4e2d\u7684\u6811\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aforest = [[2,3,4],[0,0,5],[8,7,6]]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u53ef\u4ee5\u6309\u4e0e\u793a\u4f8b 1 \u76f8\u540c\u7684\u8def\u5f84\u6765\u780d\u6389\u6240\u6709\u7684\u6811\u3002\n(0,0) \u4f4d\u7f6e\u7684\u6811\uff0c\u53ef\u4ee5\u76f4\u63a5\u780d\u53bb\uff0c\u4e0d\u7528\u7b97\u6b65\u6570\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == forest.length
    • \n\t
    • n == forest[i].length
    • \n\t
    • 1 <= m, n <= 50
    • \n\t
    • 0 <= forest[i][j] <= 109
    • \n
    \n", "tags_en": ["Breadth-first Search"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int cutOffTree(vector>& forest) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int cutOffTree(List> forest) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def cutOffTree(self, forest):\n \"\"\"\n :type forest: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def cutOffTree(self, forest: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint cutOffTree(int** forest, int forestSize, int* forestColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CutOffTree(IList> forest) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} forest\n * @return {number}\n */\nvar cutOffTree = function(forest) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} forest\n# @return {Integer}\ndef cut_off_tree(forest)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func cutOffTree(_ forest: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func cutOffTree(forest [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def cutOffTree(forest: List[List[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun cutOffTree(forest: List>): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn cut_off_tree(forest: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $forest\n * @return Integer\n */\n function cutOffTree($forest) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function cutOffTree(forest: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (cut-off-tree forest)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0675](https://leetcode-cn.com/problems/cut-off-trees-for-golf-event)", "[\u4e3a\u9ad8\u5c14\u592b\u6bd4\u8d5b\u780d\u6811](/solution/0600-0699/0675.Cut%20Off%20Trees%20for%20Golf%20Event/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[0675](https://leetcode.com/problems/cut-off-trees-for-golf-event)", "[Cut Off Trees for Golf Event](/solution/0600-0699/0675.Cut%20Off%20Trees%20for%20Golf%20Event/README_EN.md)", "`Breadth-first Search`", "Hard", ""]}, {"question_id": "0674", "frontend_question_id": "0674", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-continuous-increasing-subsequence", "url_en": "https://leetcode.com/problems/longest-continuous-increasing-subsequence", "relative_path_cn": "/solution/0600-0699/0674.Longest%20Continuous%20Increasing%20Subsequence/README.md", "relative_path_en": "/solution/0600-0699/0674.Longest%20Continuous%20Increasing%20Subsequence/README_EN.md", "title_cn": "\u6700\u957f\u8fde\u7eed\u9012\u589e\u5e8f\u5217", "title_en": "Longest Continuous Increasing Subsequence", "question_title_slug": "longest-continuous-increasing-subsequence", "content_en": "

    Given an unsorted array of integers nums, return the length of the longest continuous increasing subsequence (i.e. subarray). The subsequence must be strictly increasing.

    \n\n

    A continuous increasing subsequence is defined by two indices l and r (l < r) such that it is [nums[l], nums[l + 1], ..., nums[r - 1], nums[r]] and for each l <= i < r, nums[i] < nums[i + 1].

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,3,5,4,7]\nOutput: 3\nExplanation: The longest continuous increasing subsequence is [1,3,5] with length 3.\nEven though [1,3,5,7] is an increasing subsequence, it is not continuous as elements 5 and 7 are separated by element\n4.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [2,2,2,2,2]\nOutput: 1\nExplanation: The longest continuous increasing subsequence is [2] with length 1. Note that it must be strictly\nincreasing.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 104
    • \n\t
    • -109 <= nums[i] <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u672a\u7ecf\u6392\u5e8f\u7684\u6574\u6570\u6570\u7ec4\uff0c\u627e\u5230\u6700\u957f\u4e14 \u8fde\u7eed\u9012\u589e\u7684\u5b50\u5e8f\u5217\uff0c\u5e76\u8fd4\u56de\u8be5\u5e8f\u5217\u7684\u957f\u5ea6\u3002

    \n\n

    \u8fde\u7eed\u9012\u589e\u7684\u5b50\u5e8f\u5217 \u53ef\u4ee5\u7531\u4e24\u4e2a\u4e0b\u6807 l \u548c r\uff08l < r\uff09\u786e\u5b9a\uff0c\u5982\u679c\u5bf9\u4e8e\u6bcf\u4e2a l <= i < r\uff0c\u90fd\u6709 nums[i] < nums[i + 1] \uff0c\u90a3\u4e48\u5b50\u5e8f\u5217 [nums[l], nums[l + 1], ..., nums[r - 1], nums[r]] \u5c31\u662f\u8fde\u7eed\u9012\u589e\u5b50\u5e8f\u5217\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,3,5,4,7]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6700\u957f\u8fde\u7eed\u9012\u589e\u5e8f\u5217\u662f [1,3,5], \u957f\u5ea6\u4e3a3\u3002\n\u5c3d\u7ba1 [1,3,5,7] \u4e5f\u662f\u5347\u5e8f\u7684\u5b50\u5e8f\u5217, \u4f46\u5b83\u4e0d\u662f\u8fde\u7eed\u7684\uff0c\u56e0\u4e3a 5 \u548c 7 \u5728\u539f\u6570\u7ec4\u91cc\u88ab 4 \u9694\u5f00\u3002 \n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [2,2,2,2,2]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u6700\u957f\u8fde\u7eed\u9012\u589e\u5e8f\u5217\u662f [2], \u957f\u5ea6\u4e3a1\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 104
    • \n\t
    • -109 <= nums[i] <= 109
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findLengthOfLCIS(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findLengthOfLCIS(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findLengthOfLCIS(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findLengthOfLCIS(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findLengthOfLCIS(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindLengthOfLCIS(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar findLengthOfLCIS = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef find_length_of_lcis(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findLengthOfLCIS(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findLengthOfLCIS(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findLengthOfLCIS(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findLengthOfLCIS(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_length_of_lcis(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function findLengthOfLCIS($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findLengthOfLCIS(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-length-of-lcis nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0674](https://leetcode-cn.com/problems/longest-continuous-increasing-subsequence)", "[\u6700\u957f\u8fde\u7eed\u9012\u589e\u5e8f\u5217](/solution/0600-0699/0674.Longest%20Continuous%20Increasing%20Subsequence/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0674](https://leetcode.com/problems/longest-continuous-increasing-subsequence)", "[Longest Continuous Increasing Subsequence](/solution/0600-0699/0674.Longest%20Continuous%20Increasing%20Subsequence/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0673", "frontend_question_id": "0673", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-longest-increasing-subsequence", "url_en": "https://leetcode.com/problems/number-of-longest-increasing-subsequence", "relative_path_cn": "/solution/0600-0699/0673.Number%20of%20Longest%20Increasing%20Subsequence/README.md", "relative_path_en": "/solution/0600-0699/0673.Number%20of%20Longest%20Increasing%20Subsequence/README_EN.md", "title_cn": "\u6700\u957f\u9012\u589e\u5b50\u5e8f\u5217\u7684\u4e2a\u6570", "title_en": "Number of Longest Increasing Subsequence", "question_title_slug": "number-of-longest-increasing-subsequence", "content_en": "

    Given an integer array nums, return the number of longest increasing subsequences.

    \n\n

    Notice that the sequence has to be strictly increasing.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,3,5,4,7]\nOutput: 2\nExplanation: The two longest increasing subsequences are [1, 3, 4, 7] and [1, 3, 5, 7].\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [2,2,2,2,2]\nOutput: 5\nExplanation: The length of longest continuous increasing subsequence is 1, and there are 5 subsequences' length is 1, so output 5.\n\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 2000
    • \n\t
    • -106 <= nums[i] <= 106
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u672a\u6392\u5e8f\u7684\u6574\u6570\u6570\u7ec4\uff0c\u627e\u5230\u6700\u957f\u9012\u589e\u5b50\u5e8f\u5217\u7684\u4e2a\u6570\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: [1,3,5,4,7]\n\u8f93\u51fa: 2\n\u89e3\u91ca: \u6709\u4e24\u4e2a\u6700\u957f\u9012\u589e\u5b50\u5e8f\u5217\uff0c\u5206\u522b\u662f [1, 3, 4, 7] \u548c[1, 3, 5, 7]\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: [2,2,2,2,2]\n\u8f93\u51fa: 5\n\u89e3\u91ca: \u6700\u957f\u9012\u589e\u5b50\u5e8f\u5217\u7684\u957f\u5ea6\u662f1\uff0c\u5e76\u4e14\u5b58\u57285\u4e2a\u5b50\u5e8f\u5217\u7684\u957f\u5ea6\u4e3a1\uff0c\u56e0\u6b64\u8f93\u51fa5\u3002\n
    \n\n

    \u6ce8\u610f: \u7ed9\u5b9a\u7684\u6570\u7ec4\u957f\u5ea6\u4e0d\u8d85\u8fc7 2000 \u5e76\u4e14\u7ed3\u679c\u4e00\u5b9a\u662f32\u4f4d\u6709\u7b26\u53f7\u6574\u6570\u3002

    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findNumberOfLIS(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findNumberOfLIS(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findNumberOfLIS(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findNumberOfLIS(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findNumberOfLIS(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindNumberOfLIS(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar findNumberOfLIS = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef find_number_of_lis(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findNumberOfLIS(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findNumberOfLIS(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findNumberOfLIS(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findNumberOfLIS(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_number_of_lis(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function findNumberOfLIS($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findNumberOfLIS(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-number-of-lis nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0673](https://leetcode-cn.com/problems/number-of-longest-increasing-subsequence)", "[\u6700\u957f\u9012\u589e\u5b50\u5e8f\u5217\u7684\u4e2a\u6570](/solution/0600-0699/0673.Number%20of%20Longest%20Increasing%20Subsequence/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0673](https://leetcode.com/problems/number-of-longest-increasing-subsequence)", "[Number of Longest Increasing Subsequence](/solution/0600-0699/0673.Number%20of%20Longest%20Increasing%20Subsequence/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0672", "frontend_question_id": "0672", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/bulb-switcher-ii", "url_en": "https://leetcode.com/problems/bulb-switcher-ii", "relative_path_cn": "/solution/0600-0699/0672.Bulb%20Switcher%20II/README.md", "relative_path_en": "/solution/0600-0699/0672.Bulb%20Switcher%20II/README_EN.md", "title_cn": "\u706f\u6ce1\u5f00\u5173 \u2161", "title_en": "Bulb Switcher II", "question_title_slug": "bulb-switcher-ii", "content_en": "

    There is a room with n bulbs labeled from 1 to n that all are turned on initially, and four buttons on the wall. Each of the four buttons has a different functionality where:

    \n\n
      \n\t
    • Button 1: Flips the status of all the bulbs.
    • \n\t
    • Button 2: Flips the status of all the bulbs with even labels (i.e., 2, 4, ...).
    • \n\t
    • Button 3: Flips the status of all the bulbs with odd labels (i.e., 1, 3, ...).
    • \n\t
    • Button 4: Flips the status of all the bulbs with a label j = 3k + 1 where k = 0, 1, 2, ... (i.e., 1, 4, 7, 10, ...).
    • \n
    \n\n

    You will press one of the four mentioned buttons exactly presses times.

    \n\n

    Given the two integers n and presses, return the number of different statuses after pressing the four buttons exactly presses times.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 1, presses = 1\nOutput: 2\nExplanation: Status can be: [on], [off].\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 2, presses = 1\nOutput: 3\nExplanation: Status can be: [on, off], [off, on], [off, off].\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 3, presses = 1\nOutput: 4\nExplanation: Status can be: [off, on, off], [on, off, on], [off, off, off], [off, on, on].\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 1000
    • \n\t
    • 0 <= presses <= 1000
    • \n
    \n", "content_cn": "

    \u73b0\u6709\u4e00\u4e2a\u623f\u95f4\uff0c\u5899\u4e0a\u6302\u6709 n \u53ea\u5df2\u7ecf\u6253\u5f00\u7684\u706f\u6ce1\u548c 4 \u4e2a\u6309\u94ae\u3002\u5728\u8fdb\u884c\u4e86 m \u6b21\u672a\u77e5\u64cd\u4f5c\u540e\uff0c\u4f60\u9700\u8981\u8fd4\u56de\u8fd9 n \u53ea\u706f\u6ce1\u53ef\u80fd\u6709\u591a\u5c11\u79cd\u4e0d\u540c\u7684\u72b6\u6001\u3002

    \n\n

    \u5047\u8bbe\u8fd9 n \u53ea\u706f\u6ce1\u88ab\u7f16\u53f7\u4e3a [1, 2, 3 ..., n]\uff0c\u8fd9 4 \u4e2a\u6309\u94ae\u7684\u529f\u80fd\u5982\u4e0b\uff1a

    \n\n
      \n\t
    1. \u5c06\u6240\u6709\u706f\u6ce1\u7684\u72b6\u6001\u53cd\u8f6c\uff08\u5373\u5f00\u53d8\u4e3a\u5173\uff0c\u5173\u53d8\u4e3a\u5f00\uff09
    2. \n\t
    3. \u5c06\u7f16\u53f7\u4e3a\u5076\u6570\u7684\u706f\u6ce1\u7684\u72b6\u6001\u53cd\u8f6c
    4. \n\t
    5. \u5c06\u7f16\u53f7\u4e3a\u5947\u6570\u7684\u706f\u6ce1\u7684\u72b6\u6001\u53cd\u8f6c
    6. \n\t
    7. \u5c06\u7f16\u53f7\u4e3a 3k+1 \u7684\u706f\u6ce1\u7684\u72b6\u6001\u53cd\u8f6c\uff08k = 0, 1, 2, ...)
    8. \n
    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: n = 1, m = 1.\n\u8f93\u51fa: 2\n\u8bf4\u660e: \u72b6\u6001\u4e3a: [\u5f00], [\u5173]\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: n = 2, m = 1.\n\u8f93\u51fa: 3\n\u8bf4\u660e: \u72b6\u6001\u4e3a: [\u5f00, \u5173], [\u5173, \u5f00], [\u5173, \u5173]\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u8f93\u5165: n = 3, m = 1.\n\u8f93\u51fa: 4\n\u8bf4\u660e: \u72b6\u6001\u4e3a: [\u5173, \u5f00, \u5173], [\u5f00, \u5173, \u5f00], [\u5173, \u5173, \u5173], [\u5173, \u5f00, \u5f00].\n
    \n\n

    \u6ce8\u610f\uff1a n \u548c m \u90fd\u5c5e\u4e8e [0, 1000].

    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int flipLights(int n, int presses) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int flipLights(int n, int presses) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def flipLights(self, n, presses):\n \"\"\"\n :type n: int\n :type presses: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def flipLights(self, n: int, presses: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint flipLights(int n, int presses){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FlipLights(int n, int presses) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} presses\n * @return {number}\n */\nvar flipLights = function(n, presses) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} presses\n# @return {Integer}\ndef flip_lights(n, presses)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func flipLights(_ n: Int, _ presses: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func flipLights(n int, presses int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def flipLights(n: Int, presses: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun flipLights(n: Int, presses: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn flip_lights(n: i32, presses: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $presses\n * @return Integer\n */\n function flipLights($n, $presses) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function flipLights(n: number, presses: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (flip-lights n presses)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0672](https://leetcode-cn.com/problems/bulb-switcher-ii)", "[\u706f\u6ce1\u5f00\u5173 \u2161](/solution/0600-0699/0672.Bulb%20Switcher%20II/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0672](https://leetcode.com/problems/bulb-switcher-ii)", "[Bulb Switcher II](/solution/0600-0699/0672.Bulb%20Switcher%20II/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "0671", "frontend_question_id": "0671", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/second-minimum-node-in-a-binary-tree", "url_en": "https://leetcode.com/problems/second-minimum-node-in-a-binary-tree", "relative_path_cn": "/solution/0600-0699/0671.Second%20Minimum%20Node%20In%20a%20Binary%20Tree/README.md", "relative_path_en": "/solution/0600-0699/0671.Second%20Minimum%20Node%20In%20a%20Binary%20Tree/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u4e2d\u7b2c\u4e8c\u5c0f\u7684\u8282\u70b9", "title_en": "Second Minimum Node In a Binary Tree", "question_title_slug": "second-minimum-node-in-a-binary-tree", "content_en": "

    Given a non-empty special binary tree consisting of nodes with the non-negative value, where each node in this tree has exactly two or zero sub-node. If the node has two sub-nodes, then this node's value is the smaller value among its two sub-nodes. More formally, the property root.val = min(root.left.val, root.right.val) always holds.

    \n\n

    Given such a binary tree, you need to output the second minimum value in the set made of all the nodes' value in the whole tree.

    \n\n

    If no such second minimum value exists, output -1 instead.

    \n\n

     

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [2,2,5,null,null,5,7]\nOutput: 5\nExplanation: The smallest value is 2, the second smallest value is 5.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [2,2,2]\nOutput: -1\nExplanation: The smallest value is 2, but there isn't any second smallest value.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 25].
    • \n\t
    • 1 <= Node.val <= 231 - 1
    • \n\t
    • root.val == min(root.left.val, root.right.val) for each internal node of the tree.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u7a7a\u7279\u6b8a\u7684\u4e8c\u53c9\u6811\uff0c\u6bcf\u4e2a\u8282\u70b9\u90fd\u662f\u6b63\u6570\uff0c\u5e76\u4e14\u6bcf\u4e2a\u8282\u70b9\u7684\u5b50\u8282\u70b9\u6570\u91cf\u53ea\u80fd\u4e3a\u00a02\u00a0\u6216\u00a00\u3002\u5982\u679c\u4e00\u4e2a\u8282\u70b9\u6709\u4e24\u4e2a\u5b50\u8282\u70b9\u7684\u8bdd\uff0c\u90a3\u4e48\u8be5\u8282\u70b9\u7684\u503c\u7b49\u4e8e\u4e24\u4e2a\u5b50\u8282\u70b9\u4e2d\u8f83\u5c0f\u7684\u4e00\u4e2a\u3002

    \n\n

    \u66f4\u6b63\u5f0f\u5730\u8bf4\uff0croot.val = min(root.left.val, root.right.val) \u603b\u6210\u7acb\u3002

    \n\n

    \u7ed9\u51fa\u8fd9\u6837\u7684\u4e00\u4e2a\u4e8c\u53c9\u6811\uff0c\u4f60\u9700\u8981\u8f93\u51fa\u6240\u6709\u8282\u70b9\u4e2d\u7684\u7b2c\u4e8c\u5c0f\u7684\u503c\u3002\u5982\u679c\u7b2c\u4e8c\u5c0f\u7684\u503c\u4e0d\u5b58\u5728\u7684\u8bdd\uff0c\u8f93\u51fa -1 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [2,2,5,null,null,5,7]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u6700\u5c0f\u7684\u503c\u662f 2 \uff0c\u7b2c\u4e8c\u5c0f\u7684\u503c\u662f 5 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [2,2,2]\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1a\u6700\u5c0f\u7684\u503c\u662f 2, \u4f46\u662f\u4e0d\u5b58\u5728\u7b2c\u4e8c\u5c0f\u7684\u503c\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u6570\u76ee\u5728\u8303\u56f4 [1, 25] \u5185
    • \n\t
    • 1 <= Node.val <= 231 - 1
    • \n\t
    • \u5bf9\u4e8e\u6811\u4e2d\u6bcf\u4e2a\u8282\u70b9 root.val == min(root.left.val, root.right.val)
    • \n
    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int findSecondMinimumValue(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int findSecondMinimumValue(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def findSecondMinimumValue(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def findSecondMinimumValue(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint findSecondMinimumValue(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int FindSecondMinimumValue(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar findSecondMinimumValue = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef find_second_minimum_value(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func findSecondMinimumValue(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc findSecondMinimumValue(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def findSecondMinimumValue(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun findSecondMinimumValue(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn find_second_minimum_value(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function findSecondMinimumValue($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction findSecondMinimumValue(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (find-second-minimum-value root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0671](https://leetcode-cn.com/problems/second-minimum-node-in-a-binary-tree)", "[\u4e8c\u53c9\u6811\u4e2d\u7b2c\u4e8c\u5c0f\u7684\u8282\u70b9](/solution/0600-0699/0671.Second%20Minimum%20Node%20In%20a%20Binary%20Tree/README.md)", "`\u6811`", "\u7b80\u5355", ""], "md_table_row_en": ["[0671](https://leetcode.com/problems/second-minimum-node-in-a-binary-tree)", "[Second Minimum Node In a Binary Tree](/solution/0600-0699/0671.Second%20Minimum%20Node%20In%20a%20Binary%20Tree/README_EN.md)", "`Tree`", "Easy", ""]}, {"question_id": "0670", "frontend_question_id": "0670", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-swap", "url_en": "https://leetcode.com/problems/maximum-swap", "relative_path_cn": "/solution/0600-0699/0670.Maximum%20Swap/README.md", "relative_path_en": "/solution/0600-0699/0670.Maximum%20Swap/README_EN.md", "title_cn": "\u6700\u5927\u4ea4\u6362", "title_en": "Maximum Swap", "question_title_slug": "maximum-swap", "content_en": "

    You are given an integer num. You can swap two digits at most once to get the maximum valued number.

    \n\n

    Return the maximum valued number you can get.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: num = 2736\nOutput: 7236\nExplanation: Swap the number 2 and the number 7.\n
    \n\n

    Example 2:

    \n\n
    \nInput: num = 9973\nOutput: 9973\nExplanation: No swap.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= num <= 108
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\uff0c\u4f60\u81f3\u591a\u53ef\u4ee5\u4ea4\u6362\u4e00\u6b21\u6570\u5b57\u4e2d\u7684\u4efb\u610f\u4e24\u4f4d\u3002\u8fd4\u56de\u4f60\u80fd\u5f97\u5230\u7684\u6700\u5927\u503c\u3002

    \n\n

    \u793a\u4f8b 1 :

    \n\n
    \n\u8f93\u5165: 2736\n\u8f93\u51fa: 7236\n\u89e3\u91ca: \u4ea4\u6362\u6570\u5b572\u548c\u6570\u5b577\u3002\n
    \n\n

    \u793a\u4f8b 2 :

    \n\n
    \n\u8f93\u5165: 9973\n\u8f93\u51fa: 9973\n\u89e3\u91ca: \u4e0d\u9700\u8981\u4ea4\u6362\u3002\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u7ed9\u5b9a\u6570\u5b57\u7684\u8303\u56f4\u662f [0, 108]
    2. \n
    \n", "tags_en": ["Array", "Math"], "tags_cn": ["\u6570\u7ec4", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maximumSwap(int num) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maximumSwap(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximumSwap(self, num):\n \"\"\"\n :type num: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximumSwap(self, num: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maximumSwap(int num){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaximumSwap(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} num\n * @return {number}\n */\nvar maximumSwap = function(num) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} num\n# @return {Integer}\ndef maximum_swap(num)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximumSwap(_ num: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximumSwap(num int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximumSwap(num: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximumSwap(num: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximum_swap(num: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $num\n * @return Integer\n */\n function maximumSwap($num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximumSwap(num: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximum-swap num)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0670](https://leetcode-cn.com/problems/maximum-swap)", "[\u6700\u5927\u4ea4\u6362](/solution/0600-0699/0670.Maximum%20Swap/README.md)", "`\u6570\u7ec4`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0670](https://leetcode.com/problems/maximum-swap)", "[Maximum Swap](/solution/0600-0699/0670.Maximum%20Swap/README_EN.md)", "`Array`,`Math`", "Medium", ""]}, {"question_id": "0669", "frontend_question_id": "0669", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/trim-a-binary-search-tree", "url_en": "https://leetcode.com/problems/trim-a-binary-search-tree", "relative_path_cn": "/solution/0600-0699/0669.Trim%20a%20Binary%20Search%20Tree/README.md", "relative_path_en": "/solution/0600-0699/0669.Trim%20a%20Binary%20Search%20Tree/README_EN.md", "title_cn": "\u4fee\u526a\u4e8c\u53c9\u641c\u7d22\u6811", "title_en": "Trim a Binary Search Tree", "question_title_slug": "trim-a-binary-search-tree", "content_en": "

    Given the root of a binary search tree and the lowest and highest boundaries as low and high, trim the tree so that all its elements lies in [low, high]. Trimming the tree should not change the relative structure of the elements that will remain in the tree (i.e., any node's descendant should remain a descendant). It can be proven that there is a unique answer.

    \n\n

    Return the root of the trimmed binary search tree. Note that the root may change depending on the given bounds.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,0,2], low = 1, high = 2\nOutput: [1,null,2]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [3,0,4,null,2,null,null,1], low = 1, high = 3\nOutput: [3,2,null,1]\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = [1], low = 1, high = 2\nOutput: [1]\n
    \n\n

    Example 4:

    \n\n
    \nInput: root = [1,null,2], low = 1, high = 3\nOutput: [1,null,2]\n
    \n\n

    Example 5:

    \n\n
    \nInput: root = [1,null,2], low = 2, high = 4\nOutput: [2]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree in the range [1, 104].
    • \n\t
    • 0 <= Node.val <= 104
    • \n\t
    • The value of each node in the tree is unique.
    • \n\t
    • root is guaranteed to be a valid binary search tree.
    • \n\t
    • 0 <= low <= high <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6839\u8282\u70b9 root \uff0c\u540c\u65f6\u7ed9\u5b9a\u6700\u5c0f\u8fb9\u754clow \u548c\u6700\u5927\u8fb9\u754c high\u3002\u901a\u8fc7\u4fee\u526a\u4e8c\u53c9\u641c\u7d22\u6811\uff0c\u4f7f\u5f97\u6240\u6709\u8282\u70b9\u7684\u503c\u5728[low, high]\u4e2d\u3002\u4fee\u526a\u6811\u4e0d\u5e94\u8be5\u6539\u53d8\u4fdd\u7559\u5728\u6811\u4e2d\u7684\u5143\u7d20\u7684\u76f8\u5bf9\u7ed3\u6784\uff08\u5373\uff0c\u5982\u679c\u6ca1\u6709\u88ab\u79fb\u9664\uff0c\u539f\u6709\u7684\u7236\u4ee3\u5b50\u4ee3\u5173\u7cfb\u90fd\u5e94\u5f53\u4fdd\u7559\uff09\u3002 \u53ef\u4ee5\u8bc1\u660e\uff0c\u5b58\u5728\u552f\u4e00\u7684\u7b54\u6848\u3002

    \n\n

    \u6240\u4ee5\u7ed3\u679c\u5e94\u5f53\u8fd4\u56de\u4fee\u526a\u597d\u7684\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u65b0\u7684\u6839\u8282\u70b9\u3002\u6ce8\u610f\uff0c\u6839\u8282\u70b9\u53ef\u80fd\u4f1a\u6839\u636e\u7ed9\u5b9a\u7684\u8fb9\u754c\u53d1\u751f\u6539\u53d8\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [1,0,2], low = 1, high = 2\n\u8f93\u51fa\uff1a[1,null,2]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [3,0,4,null,2,null,null,1], low = 1, high = 3\n\u8f93\u51fa\uff1a[3,2,null,1]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [1], low = 1, high = 2\n\u8f93\u51fa\uff1a[1]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [1,null,2], low = 1, high = 3\n\u8f93\u51fa\uff1a[1,null,2]\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [1,null,2], low = 2, high = 4\n\u8f93\u51fa\uff1a[2]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u6570\u5728\u8303\u56f4 [1, 104] \u5185
    • \n\t
    • 0 <= Node.val <= 104
    • \n\t
    • \u6811\u4e2d\u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u90fd\u662f\u552f\u4e00\u7684
    • \n\t
    • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u8f93\u5165\u662f\u4e00\u68f5\u6709\u6548\u7684\u4e8c\u53c9\u641c\u7d22\u6811
    • \n\t
    • 0 <= low <= high <= 104
    • \n
    \n", "tags_en": ["Tree", "Recursion"], "tags_cn": ["\u6811", "\u9012\u5f52"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* trimBST(TreeNode* root, int low, int high) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode trimBST(TreeNode root, int low, int high) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def trimBST(self, root, low, high):\n \"\"\"\n :type root: TreeNode\n :type low: int\n :type high: int\n :rtype: TreeNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def trimBST(self, root: TreeNode, low: int, high: int) -> TreeNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* trimBST(struct TreeNode* root, int low, int high){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode TrimBST(TreeNode root, int low, int high) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number} low\n * @param {number} high\n * @return {TreeNode}\n */\nvar trimBST = function(root, low, high) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @param {Integer} low\n# @param {Integer} high\n# @return {TreeNode}\ndef trim_bst(root, low, high)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func trimBST(_ root: TreeNode?, _ low: Int, _ high: Int) -> TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc trimBST(root *TreeNode, low int, high int) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def trimBST(root: TreeNode, low: Int, high: Int): TreeNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun trimBST(root: TreeNode?, low: Int, high: Int): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn trim_bst(root: Option>>, low: i32, high: i32) -> Option>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param Integer $low\n * @param Integer $high\n * @return TreeNode\n */\n function trimBST($root, $low, $high) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction trimBST(root: TreeNode | null, low: number, high: number): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (trim-bst root low high)\n (-> (or/c tree-node? #f) exact-integer? exact-integer? (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0669](https://leetcode-cn.com/problems/trim-a-binary-search-tree)", "[\u4fee\u526a\u4e8c\u53c9\u641c\u7d22\u6811](/solution/0600-0699/0669.Trim%20a%20Binary%20Search%20Tree/README.md)", "`\u6811`,`\u9012\u5f52`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0669](https://leetcode.com/problems/trim-a-binary-search-tree)", "[Trim a Binary Search Tree](/solution/0600-0699/0669.Trim%20a%20Binary%20Search%20Tree/README_EN.md)", "`Tree`,`Recursion`", "Medium", ""]}, {"question_id": "0668", "frontend_question_id": "0668", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/kth-smallest-number-in-multiplication-table", "url_en": "https://leetcode.com/problems/kth-smallest-number-in-multiplication-table", "relative_path_cn": "/solution/0600-0699/0668.Kth%20Smallest%20Number%20in%20Multiplication%20Table/README.md", "relative_path_en": "/solution/0600-0699/0668.Kth%20Smallest%20Number%20in%20Multiplication%20Table/README_EN.md", "title_cn": "\u4e58\u6cd5\u8868\u4e2d\u7b2ck\u5c0f\u7684\u6570", "title_en": "Kth Smallest Number in Multiplication Table", "question_title_slug": "kth-smallest-number-in-multiplication-table", "content_en": "

    Nearly everyone has used the Multiplication Table. The multiplication table of size m x n is an integer matrix mat where mat[i][j] == i * j (1-indexed).

    \n\n

    Given three integers m, n, and k, return the kth smallest element in the m x n multiplication table.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: m = 3, n = 3, k = 5\nOutput: 3\nExplanation: The 5th smallest number is 3.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: m = 2, n = 3, k = 6\nOutput: 6\nExplanation: The 6th smallest number is 6.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= m, n <= 3 * 104
    • \n\t
    • 1 <= k <= m * n
    • \n
    \n", "content_cn": "

    \u51e0\u4e4e\u6bcf\u4e00\u4e2a\u4eba\u90fd\u7528 \u4e58\u6cd5\u8868\u3002\u4f46\u662f\u4f60\u80fd\u5728\u4e58\u6cd5\u8868\u4e2d\u5feb\u901f\u627e\u5230\u7b2ck\u5c0f\u7684\u6570\u5b57\u5417\uff1f

    \n\n

    \u7ed9\u5b9a\u9ad8\u5ea6m \u3001\u5bbd\u5ea6n \u7684\u4e00\u5f20 m * n\u7684\u4e58\u6cd5\u8868\uff0c\u4ee5\u53ca\u6b63\u6574\u6570k\uff0c\u4f60\u9700\u8981\u8fd4\u56de\u8868\u4e2d\u7b2ck \u5c0f\u7684\u6570\u5b57\u3002

    \n\n

    \u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165: m = 3, n = 3, k = 5\n\u8f93\u51fa: 3\n\u89e3\u91ca: \n\u4e58\u6cd5\u8868:\n1\t2\t3\n2\t4\t6\n3\t6\t9\n\n\u7b2c5\u5c0f\u7684\u6570\u5b57\u662f 3 (1, 2, 2, 3, 3).\n
    \n\n

    \u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165: m = 2, n = 3, k = 6\n\u8f93\u51fa: 6\n\u89e3\u91ca: \n\u4e58\u6cd5\u8868:\n1\t2\t3\n2\t4\t6\n\n\u7b2c6\u5c0f\u7684\u6570\u5b57\u662f 6 (1, 2, 2, 3, 4, 6).\n
    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    1. m \u548c n \u7684\u8303\u56f4\u5728 [1, 30000] \u4e4b\u95f4\u3002
    2. \n\t
    3. k \u7684\u8303\u56f4\u5728 [1, m * n] \u4e4b\u95f4\u3002
    4. \n
    \n", "tags_en": ["Binary Search"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findKthNumber(int m, int n, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findKthNumber(int m, int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findKthNumber(self, m, n, k):\n \"\"\"\n :type m: int\n :type n: int\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findKthNumber(self, m: int, n: int, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findKthNumber(int m, int n, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindKthNumber(int m, int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} m\n * @param {number} n\n * @param {number} k\n * @return {number}\n */\nvar findKthNumber = function(m, n, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} m\n# @param {Integer} n\n# @param {Integer} k\n# @return {Integer}\ndef find_kth_number(m, n, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findKthNumber(_ m: Int, _ n: Int, _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findKthNumber(m int, n int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findKthNumber(m: Int, n: Int, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findKthNumber(m: Int, n: Int, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_kth_number(m: i32, n: i32, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $m\n * @param Integer $n\n * @param Integer $k\n * @return Integer\n */\n function findKthNumber($m, $n, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findKthNumber(m: number, n: number, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-kth-number m n k)\n (-> exact-integer? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0668](https://leetcode-cn.com/problems/kth-smallest-number-in-multiplication-table)", "[\u4e58\u6cd5\u8868\u4e2d\u7b2ck\u5c0f\u7684\u6570](/solution/0600-0699/0668.Kth%20Smallest%20Number%20in%20Multiplication%20Table/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u56f0\u96be", ""], "md_table_row_en": ["[0668](https://leetcode.com/problems/kth-smallest-number-in-multiplication-table)", "[Kth Smallest Number in Multiplication Table](/solution/0600-0699/0668.Kth%20Smallest%20Number%20in%20Multiplication%20Table/README_EN.md)", "`Binary Search`", "Hard", ""]}, {"question_id": "0667", "frontend_question_id": "0667", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/beautiful-arrangement-ii", "url_en": "https://leetcode.com/problems/beautiful-arrangement-ii", "relative_path_cn": "/solution/0600-0699/0667.Beautiful%20Arrangement%20II/README.md", "relative_path_en": "/solution/0600-0699/0667.Beautiful%20Arrangement%20II/README_EN.md", "title_cn": "\u4f18\u7f8e\u7684\u6392\u5217 II", "title_en": "Beautiful Arrangement II", "question_title_slug": "beautiful-arrangement-ii", "content_en": "

    Given two integers n and k, construct a list answer that contains n different positive integers ranging from 1 to n and obeys the following requirement:

    \n\n
      \n\t
    • Suppose this list is answer = [a1, a2, a3, ... , an], then the list [|a1 - a2|, |a2 - a3|, |a3 - a4|, ... , |an-1 - an|] has exactly k distinct integers.
    • \n
    \n\n

    Return the list answer. If there multiple valid answers, return any of them.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 3, k = 1\nOutput: [1,2,3]\nExplanation: The [1,2,3] has three different positive integers ranging from 1 to 3, and the [1,1] has exactly 1 distinct integer: 1\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 3, k = 2\nOutput: [1,3,2]\nExplanation: The [1,3,2] has three different positive integers ranging from 1 to 3, and the [2,1] has exactly 2 distinct integers: 1 and 2.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= k < n <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u6574\u6570 n \u548c k \uff0c\u8bf7\u4f60\u6784\u9020\u4e00\u4e2a\u7b54\u6848\u5217\u8868 answer \uff0c\u8be5\u5217\u8868\u5e94\u5f53\u5305\u542b\u4ece 1 \u5230 n \u7684 n \u4e2a\u4e0d\u540c\u6b63\u6574\u6570\uff0c\u5e76\u540c\u65f6\u6ee1\u8db3\u4e0b\u8ff0\u6761\u4ef6\uff1a

    \n\n
      \n\t
    • \u5047\u8bbe\u8be5\u5217\u8868\u662f answer =\u00a0[a1, a2, a3, ... , an] \uff0c\u90a3\u4e48\u5217\u8868 [|a1 - a2|, |a2 - a3|, |a3 - a4|, ... , |an-1 - an|] \u4e2d\u5e94\u8be5\u6709\u4e14\u4ec5\u6709 k \u4e2a\u4e0d\u540c\u6574\u6570\u3002
    • \n
    \n\n

    \u8fd4\u56de\u5217\u8868 answer \u3002\u5982\u679c\u5b58\u5728\u591a\u79cd\u7b54\u6848\uff0c\u53ea\u9700\u8fd4\u56de\u5176\u4e2d \u4efb\u610f\u4e00\u79cd \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 3, k = 1\n\u8f93\u51fa\uff1a[1, 2, 3]\n\u89e3\u91ca\uff1a[1, 2, 3] \u5305\u542b 3 \u4e2a\u8303\u56f4\u5728 1-3 \u7684\u4e0d\u540c\u6574\u6570\uff0c\u5e76\u4e14 [1, 1] \u4e2d\u6709\u4e14\u4ec5\u6709 1 \u4e2a\u4e0d\u540c\u6574\u6570\uff1a1\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 3, k = 2\n\u8f93\u51fa\uff1a[1, 3, 2]\n\u89e3\u91ca\uff1a[1, 3, 2] \u5305\u542b 3 \u4e2a\u8303\u56f4\u5728 1-3 \u7684\u4e0d\u540c\u6574\u6570\uff0c\u5e76\u4e14 [2, 1] \u4e2d\u6709\u4e14\u4ec5\u6709 2 \u4e2a\u4e0d\u540c\u6574\u6570\uff1a1 \u548c 2\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= k < n <= 104
    • \n
    \n\n

    \u00a0

    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector constructArray(int n, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] constructArray(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def constructArray(self, n, k):\n \"\"\"\n :type n: int\n :type k: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def constructArray(self, n: int, k: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* constructArray(int n, int k, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] ConstructArray(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} k\n * @return {number[]}\n */\nvar constructArray = function(n, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} k\n# @return {Integer[]}\ndef construct_array(n, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func constructArray(_ n: Int, _ k: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func constructArray(n int, k int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def constructArray(n: Int, k: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun constructArray(n: Int, k: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn construct_array(n: i32, k: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $k\n * @return Integer[]\n */\n function constructArray($n, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function constructArray(n: number, k: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (construct-array n k)\n (-> exact-integer? exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0667](https://leetcode-cn.com/problems/beautiful-arrangement-ii)", "[\u4f18\u7f8e\u7684\u6392\u5217 II](/solution/0600-0699/0667.Beautiful%20Arrangement%20II/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0667](https://leetcode.com/problems/beautiful-arrangement-ii)", "[Beautiful Arrangement II](/solution/0600-0699/0667.Beautiful%20Arrangement%20II/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0666", "frontend_question_id": "0666", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/path-sum-iv", "url_en": "https://leetcode.com/problems/path-sum-iv", "relative_path_cn": "/solution/0600-0699/0666.Path%20Sum%20IV/README.md", "relative_path_en": "/solution/0600-0699/0666.Path%20Sum%20IV/README_EN.md", "title_cn": "\u8def\u5f84\u603b\u548c IV", "title_en": "Path Sum IV", "question_title_slug": "path-sum-iv", "content_en": "

    If the depth of a tree is smaller than 5, then this tree can be represented by an array of three-digit integers. For each integer in this array:

    \n\n
      \n\t
    • The hundreds digit represents the depth d of this node where 1 <= d <= 4.
    • \n\t
    • The tens digit represents the position p of this node in the level it belongs to where 1 <= p <= 8. The position is the same as that in a full binary tree.
    • \n\t
    • The units digit represents the value v of this node where 0 <= v <= 9.
    • \n
    \n\n

    Given an array of ascending three-digit integers nums representing a binary tree with a depth smaller than 5, return the sum of all paths from the root towards the leaves.

    \n\n

    It is guaranteed that the given array represents a valid connected binary tree.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: nums = [113,215,221]\nOutput: 12\nExplanation: The tree that the list represents is shown.\nThe path sum is (3 + 5) + (3 + 1) = 12.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: nums = [113,221]\nOutput: 4\nExplanation: The tree that the list represents is shown. \nThe path sum is (3 + 1) = 4.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 15
    • \n\t
    • 110 <= nums[i] <= 489
    • \n\t
    • nums represents a valid binary tree with depth less than 5.
    • \n
    \n", "content_cn": "

    \u5bf9\u4e8e\u4e00\u68f5\u6df1\u5ea6\u5c0f\u4e8e\u00a05\u00a0\u7684\u6811\uff0c\u53ef\u4ee5\u7528\u4e00\u7ec4\u4e09\u4f4d\u5341\u8fdb\u5236\u6574\u6570\u6765\u8868\u793a\u3002

    \n\n

    \u5bf9\u4e8e\u6bcf\u4e2a\u6574\u6570\uff1a

    \n\n
      \n\t
    1. \u767e\u4f4d\u4e0a\u7684\u6570\u5b57\u8868\u793a\u8fd9\u4e2a\u8282\u70b9\u7684\u6df1\u5ea6 D\uff0c1 <= D <= 4\u3002
    2. \n\t
    3. \u5341\u4f4d\u4e0a\u7684\u6570\u5b57\u8868\u793a\u8fd9\u4e2a\u8282\u70b9\u5728\u5f53\u524d\u5c42\u6240\u5728\u7684\u4f4d\u7f6e P\uff0c 1 <= P <= 8\u3002\u4f4d\u7f6e\u7f16\u53f7\u4e0e\u4e00\u68f5\u6ee1\u4e8c\u53c9\u6811\u7684\u4f4d\u7f6e\u7f16\u53f7\u76f8\u540c\u3002
    4. \n\t
    5. \u4e2a\u4f4d\u4e0a\u7684\u6570\u5b57\u8868\u793a\u8fd9\u4e2a\u8282\u70b9\u7684\u6743\u503c V\uff0c0 <= V <= 9\u3002
    6. \n
    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u5305\u542b\u4e09\u4f4d\u6574\u6570\u7684\u5347\u5e8f\u6570\u7ec4\uff0c\u8868\u793a\u4e00\u68f5\u6df1\u5ea6\u5c0f\u4e8e 5 \u7684\u4e8c\u53c9\u6811\uff0c\u8bf7\u4f60\u8fd4\u56de\u4ece\u6839\u5230\u6240\u6709\u53f6\u5b50\u7ed3\u70b9\u7684\u8def\u5f84\u4e4b\u548c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165: [113, 215, 221]\n\u8f93\u51fa: 12\n\u89e3\u91ca: \n\u8fd9\u68f5\u6811\u5f62\u72b6\u5982\u4e0b:\n    3\n   / \\\n  5   1\n\n\u8def\u5f84\u548c = (3 + 5) + (3 + 1) = 12.\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165: [113, 221]\n\u8f93\u51fa: 4\n\u89e3\u91ca: \n\u8fd9\u68f5\u6811\u5f62\u72b6\u5982\u4e0b: \n    3\n     \\\n      1\n\n\u8def\u5f84\u548c = (3 + 1) = 4.\n
    \n\n

    \u00a0

    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int pathSum(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int pathSum(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def pathSum(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def pathSum(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint pathSum(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int PathSum(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar pathSum = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef path_sum(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func pathSum(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func pathSum(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def pathSum(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun pathSum(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn path_sum(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function pathSum($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function pathSum(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (path-sum nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0666](https://leetcode-cn.com/problems/path-sum-iv)", "[\u8def\u5f84\u603b\u548c IV](/solution/0600-0699/0666.Path%20Sum%20IV/README.md)", "`\u6811`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0666](https://leetcode.com/problems/path-sum-iv)", "[Path Sum IV](/solution/0600-0699/0666.Path%20Sum%20IV/README_EN.md)", "`Tree`", "Medium", "\ud83d\udd12"]}, {"question_id": "0665", "frontend_question_id": "0665", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/non-decreasing-array", "url_en": "https://leetcode.com/problems/non-decreasing-array", "relative_path_cn": "/solution/0600-0699/0665.Non-decreasing%20Array/README.md", "relative_path_en": "/solution/0600-0699/0665.Non-decreasing%20Array/README_EN.md", "title_cn": "\u975e\u9012\u51cf\u6570\u5217", "title_en": "Non-decreasing Array", "question_title_slug": "non-decreasing-array", "content_en": "

    Given an array nums with n integers, your task is to check if it could become non-decreasing by modifying at most one element.

    \n\n

    We define an array is non-decreasing if nums[i] <= nums[i + 1] holds for every i (0-based) such that (0 <= i <= n - 2).

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [4,2,3]\nOutput: true\nExplanation: You could modify the first 4 to 1 to get a non-decreasing array.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [4,2,1]\nOutput: false\nExplanation: You can't get a non-decreasing array by modify at most one element.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= n <= 104
    • \n\t
    • -105 <= nums[i] <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u4e3a\u00a0n\u00a0\u7684\u6574\u6570\u6570\u7ec4\uff0c\u8bf7\u4f60\u5224\u65ad\u5728 \u6700\u591a \u6539\u53d8\u00a01 \u4e2a\u5143\u7d20\u7684\u60c5\u51b5\u4e0b\uff0c\u8be5\u6570\u7ec4\u80fd\u5426\u53d8\u6210\u4e00\u4e2a\u975e\u9012\u51cf\u6570\u5217\u3002

    \n\n

    \u6211\u4eec\u662f\u8fd9\u6837\u5b9a\u4e49\u4e00\u4e2a\u975e\u9012\u51cf\u6570\u5217\u7684\uff1a\u00a0\u5bf9\u4e8e\u6570\u7ec4\u4e2d\u4efb\u610f\u7684\u00a0i (0 <= i <= n-2)\uff0c\u603b\u6ee1\u8db3 nums[i] <= nums[i + 1]\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: nums = [4,2,3]\n\u8f93\u51fa: true\n\u89e3\u91ca: \u4f60\u53ef\u4ee5\u901a\u8fc7\u628a\u7b2c\u4e00\u4e2a4\u53d8\u62101\u6765\u4f7f\u5f97\u5b83\u6210\u4e3a\u4e00\u4e2a\u975e\u9012\u51cf\u6570\u5217\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: nums = [4,2,1]\n\u8f93\u51fa: false\n\u89e3\u91ca: \u4f60\u4e0d\u80fd\u5728\u53ea\u6539\u53d8\u4e00\u4e2a\u5143\u7d20\u7684\u60c5\u51b5\u4e0b\u5c06\u5176\u53d8\u4e3a\u975e\u9012\u51cf\u6570\u5217\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 10 ^ 4
    • \n\t
    • - 10 ^ 5\u00a0<= nums[i] <= 10 ^ 5
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool checkPossibility(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean checkPossibility(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def checkPossibility(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def checkPossibility(self, nums: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool checkPossibility(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CheckPossibility(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {boolean}\n */\nvar checkPossibility = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Boolean}\ndef check_possibility(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func checkPossibility(_ nums: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func checkPossibility(nums []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def checkPossibility(nums: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun checkPossibility(nums: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn check_possibility(nums: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Boolean\n */\n function checkPossibility($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function checkPossibility(nums: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (check-possibility nums)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0665](https://leetcode-cn.com/problems/non-decreasing-array)", "[\u975e\u9012\u51cf\u6570\u5217](/solution/0600-0699/0665.Non-decreasing%20Array/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0665](https://leetcode.com/problems/non-decreasing-array)", "[Non-decreasing Array](/solution/0600-0699/0665.Non-decreasing%20Array/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0664", "frontend_question_id": "0664", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/strange-printer", "url_en": "https://leetcode.com/problems/strange-printer", "relative_path_cn": "/solution/0600-0699/0664.Strange%20Printer/README.md", "relative_path_en": "/solution/0600-0699/0664.Strange%20Printer/README_EN.md", "title_cn": "\u5947\u602a\u7684\u6253\u5370\u673a", "title_en": "Strange Printer", "question_title_slug": "strange-printer", "content_en": "

    There is a strange printer with the following two special properties:

    \n\n
      \n\t
    • The printer can only print a sequence of the same character each time.
    • \n\t
    • At each turn, the printer can print new characters starting from and ending at any place and will cover the original existing characters.
    • \n
    \n\n

    Given a string s, return the minimum number of turns the printer needed to print it.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "aaabbb"\nOutput: 2\nExplanation: Print "aaa" first and then print "bbb".\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "aba"\nOutput: 2\nExplanation: Print "aaa" first and then print "b" from the second place of the string, which will cover the existing character 'a'.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 100
    • \n\t
    • s consists of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u6709\u53f0\u5947\u602a\u7684\u6253\u5370\u673a\u6709\u4ee5\u4e0b\u4e24\u4e2a\u7279\u6b8a\u8981\u6c42\uff1a

    \n\n
      \n\t
    • \u6253\u5370\u673a\u6bcf\u6b21\u53ea\u80fd\u6253\u5370\u7531 \u540c\u4e00\u4e2a\u5b57\u7b26 \u7ec4\u6210\u7684\u5e8f\u5217\u3002
    • \n\t
    • \u6bcf\u6b21\u53ef\u4ee5\u5728\u4efb\u610f\u8d77\u59cb\u548c\u7ed3\u675f\u4f4d\u7f6e\u6253\u5370\u65b0\u5b57\u7b26\uff0c\u5e76\u4e14\u4f1a\u8986\u76d6\u6389\u539f\u6765\u5df2\u6709\u7684\u5b57\u7b26\u3002
    • \n
    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \uff0c\u4f60\u7684\u4efb\u52a1\u662f\u8ba1\u7b97\u8fd9\u4e2a\u6253\u5370\u673a\u6253\u5370\u5b83\u9700\u8981\u7684\u6700\u5c11\u6253\u5370\u6b21\u6570\u3002

    \n\u00a0\n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"aaabbb\"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u9996\u5148\u6253\u5370 \"aaa\" \u7136\u540e\u6253\u5370 \"bbb\"\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"aba\"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u9996\u5148\u6253\u5370 \"aaa\" \u7136\u540e\u5728\u7b2c\u4e8c\u4e2a\u4f4d\u7f6e\u6253\u5370 \"b\" \u8986\u76d6\u6389\u539f\u6765\u7684\u5b57\u7b26 'a'\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 100
    • \n\t
    • s \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n", "tags_en": ["Depth-first Search", "Dynamic Programming"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int strangePrinter(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int strangePrinter(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def strangePrinter(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def strangePrinter(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint strangePrinter(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int StrangePrinter(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar strangePrinter = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef strange_printer(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func strangePrinter(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func strangePrinter(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def strangePrinter(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun strangePrinter(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn strange_printer(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function strangePrinter($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function strangePrinter(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (strange-printer s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0664](https://leetcode-cn.com/problems/strange-printer)", "[\u5947\u602a\u7684\u6253\u5370\u673a](/solution/0600-0699/0664.Strange%20Printer/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0664](https://leetcode.com/problems/strange-printer)", "[Strange Printer](/solution/0600-0699/0664.Strange%20Printer/README_EN.md)", "`Depth-first Search`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0663", "frontend_question_id": "0663", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/equal-tree-partition", "url_en": "https://leetcode.com/problems/equal-tree-partition", "relative_path_cn": "/solution/0600-0699/0663.Equal%20Tree%20Partition/README.md", "relative_path_en": "/solution/0600-0699/0663.Equal%20Tree%20Partition/README_EN.md", "title_cn": "\u5747\u5300\u6811\u5212\u5206", "title_en": "Equal Tree Partition", "question_title_slug": "equal-tree-partition", "content_en": "

    Given the root of a binary tree, return true if you can partition the tree into two trees with equal sums of values after removing exactly one edge on the original tree.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [5,10,10,null,null,2,3]\nOutput: true\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [1,2,10,null,null,2,20]\nOutput: false\nExplanation: You cannot split the tree into two trees with equal sums after removing exactly one edge on the tree.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 104].
    • \n\t
    • -105 <= Node.val <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u68f5\u6709 n \u4e2a\u7ed3\u70b9\u7684\u4e8c\u53c9\u6811\uff0c\u4f60\u7684\u4efb\u52a1\u662f\u68c0\u67e5\u662f\u5426\u53ef\u4ee5\u901a\u8fc7\u53bb\u6389\u6811\u4e0a\u7684\u4e00\u6761\u8fb9\u5c06\u6811\u5206\u6210\u4e24\u68f5\uff0c\u4e14\u8fd9\u4e24\u68f5\u6811\u7ed3\u70b9\u4e4b\u548c\u76f8\u7b49\u3002

    \n\n

    \u6837\u4f8b 1:

    \n\n
    \u8f93\u5165:     \n    5\n   / \\\n  10 10\n    /  \\\n   2   3\n\n\u8f93\u51fa: True\n\u89e3\u91ca: \n    5\n   / \n  10\n      \n\u548c: 15\n\n   10\n  /  \\\n 2    3\n\n\u548c: 15\n
    \n\n

     

    \n\n

    \u6837\u4f8b 2:

    \n\n
    \u8f93\u5165:     \n    1\n   / \\\n  2  10\n    /  \\\n   2   20\n\n\u8f93\u51fa: False\n\u89e3\u91ca: \u65e0\u6cd5\u901a\u8fc7\u79fb\u9664\u4e00\u6761\u6811\u8fb9\u5c06\u8fd9\u68f5\u6811\u5212\u5206\u6210\u7ed3\u70b9\u4e4b\u548c\u76f8\u7b49\u7684\u4e24\u68f5\u5b50\u6811\u3002\n
    \n\n

     

    \n\n

    \u6ce8\u91ca :

    \n\n
      \n\t
    1. \u6811\u4e0a\u7ed3\u70b9\u7684\u6743\u503c\u8303\u56f4 [-100000, 100000]\u3002
    2. \n\t
    3. 1 <= n <= 10000
    4. \n
    \n\n

     

    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n bool checkEqualTree(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public boolean checkEqualTree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def checkEqualTree(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def checkEqualTree(self, root: TreeNode) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nbool checkEqualTree(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public bool CheckEqualTree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {boolean}\n */\nvar checkEqualTree = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Boolean}\ndef check_equal_tree(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func checkEqualTree(_ root: TreeNode?) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc checkEqualTree(root *TreeNode) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def checkEqualTree(root: TreeNode): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun checkEqualTree(root: TreeNode?): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn check_equal_tree(root: Option>>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Boolean\n */\n function checkEqualTree($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction checkEqualTree(root: TreeNode | null): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (check-equal-tree root)\n (-> (or/c tree-node? #f) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0663](https://leetcode-cn.com/problems/equal-tree-partition)", "[\u5747\u5300\u6811\u5212\u5206](/solution/0600-0699/0663.Equal%20Tree%20Partition/README.md)", "`\u6811`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0663](https://leetcode.com/problems/equal-tree-partition)", "[Equal Tree Partition](/solution/0600-0699/0663.Equal%20Tree%20Partition/README_EN.md)", "`Tree`", "Medium", "\ud83d\udd12"]}, {"question_id": "0662", "frontend_question_id": "0662", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-width-of-binary-tree", "url_en": "https://leetcode.com/problems/maximum-width-of-binary-tree", "relative_path_cn": "/solution/0600-0699/0662.Maximum%20Width%20of%20Binary%20Tree/README.md", "relative_path_en": "/solution/0600-0699/0662.Maximum%20Width%20of%20Binary%20Tree/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u6700\u5927\u5bbd\u5ea6", "title_en": "Maximum Width of Binary Tree", "question_title_slug": "maximum-width-of-binary-tree", "content_en": "

    Given the root of a binary tree, return the maximum width of the given tree.

    \n\n

    The maximum width of a tree is the maximum width among all levels.

    \n\n

    The width of one level is defined as the length between the end-nodes (the leftmost and rightmost non-null nodes), where the null nodes between the end-nodes are also counted into the length calculation.

    \n\n

    It is guaranteed that the answer will in the range of 32-bit signed integer.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,3,2,5,3,null,9]\nOutput: 4\nExplanation: The maximum width existing in the third level with the length 4 (5,3,null,9).\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [1,3,null,5,3]\nOutput: 2\nExplanation: The maximum width existing in the third level with the length 2 (5,3).\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: root = [1,3,2,5]\nOutput: 2\nExplanation: The maximum width existing in the second level with the length 2 (3,2).\n
    \n\n

    Example 4:

    \n\"\"\n
    \nInput: root = [1,3,2,5,null,null,9,6,null,null,7]\nOutput: 8\nExplanation: The maximum width existing in the fourth level with the length 8 (6,null,null,null,null,null,null,7).\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 3000].
    • \n\t
    • -100 <= Node.val <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811\uff0c\u7f16\u5199\u4e00\u4e2a\u51fd\u6570\u6765\u83b7\u53d6\u8fd9\u4e2a\u6811\u7684\u6700\u5927\u5bbd\u5ea6\u3002\u6811\u7684\u5bbd\u5ea6\u662f\u6240\u6709\u5c42\u4e2d\u7684\u6700\u5927\u5bbd\u5ea6\u3002\u8fd9\u4e2a\u4e8c\u53c9\u6811\u4e0e\u6ee1\u4e8c\u53c9\u6811\uff08full binary tree\uff09\u7ed3\u6784\u76f8\u540c\uff0c\u4f46\u4e00\u4e9b\u8282\u70b9\u4e3a\u7a7a\u3002

    \n\n

    \u6bcf\u4e00\u5c42\u7684\u5bbd\u5ea6\u88ab\u5b9a\u4e49\u4e3a\u4e24\u4e2a\u7aef\u70b9\uff08\u8be5\u5c42\u6700\u5de6\u548c\u6700\u53f3\u7684\u975e\u7a7a\u8282\u70b9\uff0c\u4e24\u7aef\u70b9\u95f4\u7684null\u8282\u70b9\u4e5f\u8ba1\u5165\u957f\u5ea6\uff09\u4e4b\u95f4\u7684\u957f\u5ea6\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: \n\n           1\n         /   \\\n        3     2\n       / \\     \\  \n      5   3     9 \n\n\u8f93\u51fa: 4\n\u89e3\u91ca: \u6700\u5927\u503c\u51fa\u73b0\u5728\u6811\u7684\u7b2c 3 \u5c42\uff0c\u5bbd\u5ea6\u4e3a 4 (5,3,null,9)\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: \n\n          1\n         /  \n        3    \n       / \\       \n      5   3     \n\n\u8f93\u51fa: 2\n\u89e3\u91ca: \u6700\u5927\u503c\u51fa\u73b0\u5728\u6811\u7684\u7b2c 3 \u5c42\uff0c\u5bbd\u5ea6\u4e3a 2 (5,3)\u3002\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \n\u8f93\u5165: \n\n          1\n         / \\\n        3   2 \n       /        \n      5      \n\n\u8f93\u51fa: 2\n\u89e3\u91ca: \u6700\u5927\u503c\u51fa\u73b0\u5728\u6811\u7684\u7b2c 2 \u5c42\uff0c\u5bbd\u5ea6\u4e3a 2 (3,2)\u3002\n
    \n\n

    \u793a\u4f8b 4:

    \n\n
    \n\u8f93\u5165: \n\n          1\n         / \\\n        3   2\n       /     \\  \n      5       9 \n     /         \\\n    6           7\n\u8f93\u51fa: 8\n\u89e3\u91ca: \u6700\u5927\u503c\u51fa\u73b0\u5728\u6811\u7684\u7b2c 4 \u5c42\uff0c\u5bbd\u5ea6\u4e3a 8 (6,null,null,null,null,null,null,7)\u3002\n
    \n\n

    \u6ce8\u610f: \u7b54\u6848\u572832\u4f4d\u6709\u7b26\u53f7\u6574\u6570\u7684\u8868\u793a\u8303\u56f4\u5185\u3002

    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int widthOfBinaryTree(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int widthOfBinaryTree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def widthOfBinaryTree(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def widthOfBinaryTree(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint widthOfBinaryTree(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int WidthOfBinaryTree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar widthOfBinaryTree = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef width_of_binary_tree(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func widthOfBinaryTree(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc widthOfBinaryTree(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def widthOfBinaryTree(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun widthOfBinaryTree(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn width_of_binary_tree(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function widthOfBinaryTree($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction widthOfBinaryTree(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (width-of-binary-tree root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0662](https://leetcode-cn.com/problems/maximum-width-of-binary-tree)", "[\u4e8c\u53c9\u6811\u6700\u5927\u5bbd\u5ea6](/solution/0600-0699/0662.Maximum%20Width%20of%20Binary%20Tree/README.md)", "`\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0662](https://leetcode.com/problems/maximum-width-of-binary-tree)", "[Maximum Width of Binary Tree](/solution/0600-0699/0662.Maximum%20Width%20of%20Binary%20Tree/README_EN.md)", "`Tree`", "Medium", ""]}, {"question_id": "0661", "frontend_question_id": "0661", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/image-smoother", "url_en": "https://leetcode.com/problems/image-smoother", "relative_path_cn": "/solution/0600-0699/0661.Image%20Smoother/README.md", "relative_path_en": "/solution/0600-0699/0661.Image%20Smoother/README_EN.md", "title_cn": "\u56fe\u7247\u5e73\u6ed1\u5668", "title_en": "Image Smoother", "question_title_slug": "image-smoother", "content_en": "

    An image smoother is a filter of the size 3 x 3 that can be applied to each cell of an image by rounding down the average of the cell and the eight surrounding cells (i.e., the average of the nine cells in the blue smoother). If one or more of the surrounding cells of a cell is not present, we do not consider it in the average (i.e., the average of the four cells in the red smoother).

    \n\"\"\n

    Given an m x n integer matrix img representing the grayscale of an image, return the image after applying the smoother on each cell of it.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: img = [[1,1,1],[1,0,1],[1,1,1]]\nOutput: [[0,0,0],[0,0,0],[0,0,0]]\nExplanation:\nFor the points (0,0), (0,2), (2,0), (2,2): floor(3/4) = floor(0.75) = 0\nFor the points (0,1), (1,0), (1,2), (2,1): floor(5/6) = floor(0.83333333) = 0\nFor the point (1,1): floor(8/9) = floor(0.88888889) = 0\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: img = [[100,200,100],[200,50,200],[100,200,100]]\nOutput: [[137,141,137],[141,138,141],[137,141,137]]\nExplanation:\nFor the points (0,0), (0,2), (2,0), (2,2): floor((100+200+200+50)/4) = floor(137.5) = 137\nFor the points (0,1), (1,0), (1,2), (2,1): floor((200+200+50+200+100+100)/6) = floor(141.666667) = 141\nFor the point (1,1): floor((50+200+200+200+200+100+100+100+100)/9) = floor(138.888889) = 138\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == img.length
    • \n\t
    • n == img[i].length
    • \n\t
    • 1 <= m, n <= 200
    • \n\t
    • 0 <= img[i][j] <= 255
    • \n
    \n", "content_cn": "

    \u5305\u542b\u6574\u6570\u7684\u4e8c\u7ef4\u77e9\u9635 M \u8868\u793a\u4e00\u4e2a\u56fe\u7247\u7684\u7070\u5ea6\u3002\u4f60\u9700\u8981\u8bbe\u8ba1\u4e00\u4e2a\u5e73\u6ed1\u5668\u6765\u8ba9\u6bcf\u4e00\u4e2a\u5355\u5143\u7684\u7070\u5ea6\u6210\u4e3a\u5e73\u5747\u7070\u5ea6 (\u5411\u4e0b\u820d\u5165) \uff0c\u5e73\u5747\u7070\u5ea6\u7684\u8ba1\u7b97\u662f\u5468\u56f4\u76848\u4e2a\u5355\u5143\u548c\u5b83\u672c\u8eab\u7684\u503c\u6c42\u5e73\u5747\uff0c\u5982\u679c\u5468\u56f4\u7684\u5355\u5143\u683c\u4e0d\u8db3\u516b\u4e2a\uff0c\u5219\u5c3d\u53ef\u80fd\u591a\u7684\u5229\u7528\u5b83\u4eec\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165:\n[[1,1,1],\n [1,0,1],\n [1,1,1]]\n\u8f93\u51fa:\n[[0, 0, 0],\n [0, 0, 0],\n [0, 0, 0]]\n\u89e3\u91ca:\n\u5bf9\u4e8e\u70b9 (0,0), (0,2), (2,0), (2,2): \u5e73\u5747(3/4) = \u5e73\u5747(0.75) = 0\n\u5bf9\u4e8e\u70b9 (0,1), (1,0), (1,2), (2,1): \u5e73\u5747(5/6) = \u5e73\u5747(0.83333333) = 0\n\u5bf9\u4e8e\u70b9 (1,1): \u5e73\u5747(8/9) = \u5e73\u5747(0.88888889) = 0\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u7ed9\u5b9a\u77e9\u9635\u4e2d\u7684\u6574\u6570\u8303\u56f4\u4e3a [0, 255]\u3002
    2. \n\t
    3. \u77e9\u9635\u7684\u957f\u548c\u5bbd\u7684\u8303\u56f4\u5747\u4e3a [1, 150]\u3002
    4. \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> imageSmoother(vector>& img) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[][] imageSmoother(int[][] img) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def imageSmoother(self, img):\n \"\"\"\n :type img: List[List[int]]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def imageSmoother(self, img: List[List[int]]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** imageSmoother(int** img, int imgSize, int* imgColSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[][] ImageSmoother(int[][] img) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} img\n * @return {number[][]}\n */\nvar imageSmoother = function(img) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} img\n# @return {Integer[][]}\ndef image_smoother(img)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func imageSmoother(_ img: [[Int]]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func imageSmoother(img [][]int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def imageSmoother(img: Array[Array[Int]]): Array[Array[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun imageSmoother(img: Array): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn image_smoother(img: Vec>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $img\n * @return Integer[][]\n */\n function imageSmoother($img) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function imageSmoother(img: number[][]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (image-smoother img)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0661](https://leetcode-cn.com/problems/image-smoother)", "[\u56fe\u7247\u5e73\u6ed1\u5668](/solution/0600-0699/0661.Image%20Smoother/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0661](https://leetcode.com/problems/image-smoother)", "[Image Smoother](/solution/0600-0699/0661.Image%20Smoother/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0660", "frontend_question_id": "0660", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/remove-9", "url_en": "https://leetcode.com/problems/remove-9", "relative_path_cn": "/solution/0600-0699/0660.Remove%209/README.md", "relative_path_en": "/solution/0600-0699/0660.Remove%209/README_EN.md", "title_cn": "\u79fb\u9664 9", "title_en": "Remove 9", "question_title_slug": "remove-9", "content_en": "

    Start from integer 1, remove any integer that contains 9 such as 9, 19, 29...

    \n\n

    So now, you will have a new integer sequence: 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, ...

    \n\n

    Given a positive integer n, you need to return the n-th integer after removing. Note that 1 will be the first integer.

    \n\n

     

    \n

    Example 1:

    \n
    Input: n = 9\nOutput: 10\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 8 x 10^8
    • \n
    \n", "content_cn": "

    \u4ece 1 \u5f00\u59cb\uff0c\u79fb\u9664\u6240\u6709\u5305\u542b\u6570\u5b57 9 \u7684\u6240\u6709\u6574\u6570\uff0c\u4f8b\u5982 9\uff0c19\uff0c29\uff0c……

    \n\n

    \u8fd9\u6837\u5c31\u83b7\u5f97\u4e86\u4e00\u4e2a\u65b0\u7684\u6574\u6570\u6570\u5217\uff1a1\uff0c2\uff0c3\uff0c4\uff0c5\uff0c6\uff0c7\uff0c8\uff0c10\uff0c11\uff0c……

    \n\n

    \u7ed9\u5b9a\u6b63\u6574\u6570 n\uff0c\u8bf7\u4f60\u8fd4\u56de\u65b0\u6570\u5217\u4e2d\u7b2c n \u4e2a\u6570\u5b57\u662f\u591a\u5c11\u30021 \u662f\u65b0\u6570\u5217\u4e2d\u7684\u7b2c\u4e00\u4e2a\u6570\u5b57\u3002

    \n\n

     

    \n\n

    \u6837\u4f8b 1:

    \n\n
    \u8f93\u5165: 9\n\u8f93\u51fa: 10\n
    \n\n

     

    \n\n

    \u6ce8\u91ca \uff1an \u4e0d\u4f1a\u8d85\u8fc7 9 x 10^8\u3002

    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int newInteger(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int newInteger(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def newInteger(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def newInteger(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint newInteger(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NewInteger(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar newInteger = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef new_integer(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func newInteger(_ n: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func newInteger(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def newInteger(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun newInteger(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn new_integer(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function newInteger($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function newInteger(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (new-integer n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0660](https://leetcode-cn.com/problems/remove-9)", "[\u79fb\u9664 9](/solution/0600-0699/0660.Remove%209/README.md)", "`\u6570\u5b66`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0660](https://leetcode.com/problems/remove-9)", "[Remove 9](/solution/0600-0699/0660.Remove%209/README_EN.md)", "`Math`", "Hard", "\ud83d\udd12"]}, {"question_id": "0659", "frontend_question_id": "0659", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/split-array-into-consecutive-subsequences", "url_en": "https://leetcode.com/problems/split-array-into-consecutive-subsequences", "relative_path_cn": "/solution/0600-0699/0659.Split%20Array%20into%20Consecutive%20Subsequences/README.md", "relative_path_en": "/solution/0600-0699/0659.Split%20Array%20into%20Consecutive%20Subsequences/README_EN.md", "title_cn": "\u5206\u5272\u6570\u7ec4\u4e3a\u8fde\u7eed\u5b50\u5e8f\u5217", "title_en": "Split Array into Consecutive Subsequences", "question_title_slug": "split-array-into-consecutive-subsequences", "content_en": "

    You are given an integer array nums that is sorted in non-decreasing order.

    \n\n

    Determine if it is possible to split nums into one or more subsequences such that both of the following conditions are true:

    \n\n
      \n\t
    • Each subsequence is a consecutive increasing sequence (i.e. each integer is exactly one more than the previous integer).
    • \n\t
    • All subsequences have a length of 3 or more.
    • \n
    \n\n

    Return true if you can split nums according to the above conditions, or false otherwise.

    \n\n

    A subsequence of an array is a new array that is formed from the original array by deleting some (can be none) of the elements without disturbing the relative positions of the remaining elements. (i.e., [1,3,5] is a subsequence of [1,2,3,4,5] while [1,3,2] is not).

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,3,3,4,5]\nOutput: true\nExplanation: nums can be split into the following subsequences:\n[1,2,3,3,4,5] --> 1, 2, 3\n[1,2,3,3,4,5] --> 3, 4, 5\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,2,3,3,4,4,5,5]\nOutput: true\nExplanation: nums can be split into the following subsequences:\n[1,2,3,3,4,4,5,5] --> 1, 2, 3, 4, 5\n[1,2,3,3,4,4,5,5] --> 3, 4, 5\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [1,2,3,4,4,5]\nOutput: false\nExplanation: It is impossible to split nums into consecutive increasing subsequences of length 3 or more.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 104
    • \n\t
    • -1000 <= nums[i] <= 1000
    • \n\t
    • nums is sorted in non-decreasing order.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6309\u5347\u5e8f\u6392\u5e8f\u7684\u6574\u6570\u6570\u7ec4 num\uff08\u53ef\u80fd\u5305\u542b\u91cd\u590d\u6570\u5b57\uff09\uff0c\u8bf7\u4f60\u5c06\u5b83\u4eec\u5206\u5272\u6210\u4e00\u4e2a\u6216\u591a\u4e2a\u957f\u5ea6\u81f3\u5c11\u4e3a 3 \u7684\u5b50\u5e8f\u5217\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5b50\u5e8f\u5217\u90fd\u7531\u8fde\u7eed\u6574\u6570\u7ec4\u6210\u3002

    \n\n

    \u5982\u679c\u53ef\u4ee5\u5b8c\u6210\u4e0a\u8ff0\u5206\u5272\uff0c\u5219\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165: [1,2,3,3,4,5]\n\u8f93\u51fa: True\n\u89e3\u91ca:\n\u4f60\u53ef\u4ee5\u5206\u5272\u51fa\u8fd9\u6837\u4e24\u4e2a\u8fde\u7eed\u5b50\u5e8f\u5217 : \n1, 2, 3\n3, 4, 5\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165: [1,2,3,3,4,4,5,5]\n\u8f93\u51fa: True\n\u89e3\u91ca:\n\u4f60\u53ef\u4ee5\u5206\u5272\u51fa\u8fd9\u6837\u4e24\u4e2a\u8fde\u7eed\u5b50\u5e8f\u5217 : \n1, 2, 3, 4, 5\n3, 4, 5\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165: [1,2,3,4,4,5]\n\u8f93\u51fa: False\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 10000
    • \n
    \n", "tags_en": ["Heap", "Greedy"], "tags_cn": ["\u5806", "\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isPossible(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isPossible(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isPossible(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isPossible(self, nums: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isPossible(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsPossible(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {boolean}\n */\nvar isPossible = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Boolean}\ndef is_possible(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isPossible(_ nums: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isPossible(nums []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isPossible(nums: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isPossible(nums: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_possible(nums: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Boolean\n */\n function isPossible($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isPossible(nums: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-possible nums)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0659](https://leetcode-cn.com/problems/split-array-into-consecutive-subsequences)", "[\u5206\u5272\u6570\u7ec4\u4e3a\u8fde\u7eed\u5b50\u5e8f\u5217](/solution/0600-0699/0659.Split%20Array%20into%20Consecutive%20Subsequences/README.md)", "`\u5806`,`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0659](https://leetcode.com/problems/split-array-into-consecutive-subsequences)", "[Split Array into Consecutive Subsequences](/solution/0600-0699/0659.Split%20Array%20into%20Consecutive%20Subsequences/README_EN.md)", "`Heap`,`Greedy`", "Medium", ""]}, {"question_id": "0658", "frontend_question_id": "0658", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-k-closest-elements", "url_en": "https://leetcode.com/problems/find-k-closest-elements", "relative_path_cn": "/solution/0600-0699/0658.Find%20K%20Closest%20Elements/README.md", "relative_path_en": "/solution/0600-0699/0658.Find%20K%20Closest%20Elements/README_EN.md", "title_cn": "\u627e\u5230 K \u4e2a\u6700\u63a5\u8fd1\u7684\u5143\u7d20", "title_en": "Find K Closest Elements", "question_title_slug": "find-k-closest-elements", "content_en": "

    Given a sorted integer array arr, two integers k and x, return the k closest integers to x in the array. The result should also be sorted in ascending order.

    \n\n

    An integer a is closer to x than an integer b if:

    \n\n
      \n\t
    • |a - x| < |b - x|, or
    • \n\t
    • |a - x| == |b - x| and a < b
    • \n
    \n\n

     

    \n

    Example 1:

    \n
    Input: arr = [1,2,3,4,5], k = 4, x = 3\nOutput: [1,2,3,4]\n

    Example 2:

    \n
    Input: arr = [1,2,3,4,5], k = 4, x = -1\nOutput: [1,2,3,4]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= k <= arr.length
    • \n\t
    • 1 <= arr.length <= 104
    • \n\t
    • arr is sorted in ascending order.
    • \n\t
    • -104 <= arr[i], x <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6392\u5e8f\u597d\u7684\u6570\u7ec4\u00a0arr \uff0c\u4e24\u4e2a\u6574\u6570 k \u548c x \uff0c\u4ece\u6570\u7ec4\u4e2d\u627e\u5230\u6700\u9760\u8fd1 x\uff08\u4e24\u6570\u4e4b\u5dee\u6700\u5c0f\uff09\u7684 k \u4e2a\u6570\u3002\u8fd4\u56de\u7684\u7ed3\u679c\u5fc5\u987b\u8981\u662f\u6309\u5347\u5e8f\u6392\u597d\u7684\u3002

    \n\n

    \u6574\u6570 a \u6bd4\u6574\u6570 b \u66f4\u63a5\u8fd1 x \u9700\u8981\u6ee1\u8db3\uff1a

    \n\n
      \n\t
    • |a - x| < |b - x| \u6216\u8005
    • \n\t
    • |a - x| == |b - x| \u4e14 a < b
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [1,2,3,4,5], k = 4, x = 3\n\u8f93\u51fa\uff1a[1,2,3,4]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aarr = [1,2,3,4,5], k = 4, x = -1\n\u8f93\u51fa\uff1a[1,2,3,4]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= k <= arr.length
    • \n\t
    • 1 <= arr.length\u00a0<= 104
    • \n\t
    • \u6570\u7ec4\u91cc\u7684\u6bcf\u4e2a\u5143\u7d20\u4e0e\u00a0x \u7684\u7edd\u5bf9\u503c\u4e0d\u8d85\u8fc7 104
    • \n
    \n", "tags_en": ["Binary Search"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findClosestElements(vector& arr, int k, int x) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List findClosestElements(int[] arr, int k, int x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findClosestElements(self, arr, k, x):\n \"\"\"\n :type arr: List[int]\n :type k: int\n :type x: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findClosestElements(self, arr: List[int], k: int, x: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* findClosestElements(int* arr, int arrSize, int k, int x, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList FindClosestElements(int[] arr, int k, int x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} arr\n * @param {number} k\n * @param {number} x\n * @return {number[]}\n */\nvar findClosestElements = function(arr, k, x) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} arr\n# @param {Integer} k\n# @param {Integer} x\n# @return {Integer[]}\ndef find_closest_elements(arr, k, x)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findClosestElements(_ arr: [Int], _ k: Int, _ x: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findClosestElements(arr []int, k int, x int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findClosestElements(arr: Array[Int], k: Int, x: Int): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findClosestElements(arr: IntArray, k: Int, x: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_closest_elements(arr: Vec, k: i32, x: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $arr\n * @param Integer $k\n * @param Integer $x\n * @return Integer[]\n */\n function findClosestElements($arr, $k, $x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findClosestElements(arr: number[], k: number, x: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-closest-elements arr k x)\n (-> (listof exact-integer?) exact-integer? exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0658](https://leetcode-cn.com/problems/find-k-closest-elements)", "[\u627e\u5230 K \u4e2a\u6700\u63a5\u8fd1\u7684\u5143\u7d20](/solution/0600-0699/0658.Find%20K%20Closest%20Elements/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0658](https://leetcode.com/problems/find-k-closest-elements)", "[Find K Closest Elements](/solution/0600-0699/0658.Find%20K%20Closest%20Elements/README_EN.md)", "`Binary Search`", "Medium", ""]}, {"question_id": "0657", "frontend_question_id": "0657", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/robot-return-to-origin", "url_en": "https://leetcode.com/problems/robot-return-to-origin", "relative_path_cn": "/solution/0600-0699/0657.Robot%20Return%20to%20Origin/README.md", "relative_path_en": "/solution/0600-0699/0657.Robot%20Return%20to%20Origin/README_EN.md", "title_cn": "\u673a\u5668\u4eba\u80fd\u5426\u8fd4\u56de\u539f\u70b9", "title_en": "Robot Return to Origin", "question_title_slug": "robot-return-to-origin", "content_en": "

    There is a robot starting at position (0, 0), the origin, on a 2D plane. Given a sequence of its moves, judge if this robot ends up at (0, 0) after it completes its moves.

    \n\n

    The move sequence is represented by a string, and the character moves[i] represents its ith move. Valid moves are R (right), L (left), U (up), and D (down). If the robot returns to the origin after it finishes all of its moves, return true. Otherwise, return false.

    \n\n

    Note: The way that the robot is "facing" is irrelevant. "R" will always make the robot move to the right once, "L" will always make it move left, etc. Also, assume that the magnitude of the robot's movement is the same for each move.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: moves = "UD"\nOutput: true\nExplanation: The robot moves up once, and then down once. All moves have the same magnitude, so it ended up at the origin where it started. Therefore, we return true.\n
    \n\n

    Example 2:

    \n\n
    \nInput: moves = "LL"\nOutput: false\nExplanation: The robot moves left twice. It ends up two "moves" to the left of the origin. We return false because it is not at the origin at the end of its moves.\n
    \n\n

    Example 3:

    \n\n
    \nInput: moves = "RRDD"\nOutput: false\n
    \n\n

    Example 4:

    \n\n
    \nInput: moves = "LDRRLRUULR"\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= moves.length <= 2 * 104
    • \n\t
    • moves only contains the characters 'U', 'D', 'L' and 'R'.
    • \n
    \n", "content_cn": "

    \u5728\u4e8c\u7ef4\u5e73\u9762\u4e0a\uff0c\u6709\u4e00\u4e2a\u673a\u5668\u4eba\u4ece\u539f\u70b9 (0, 0) \u5f00\u59cb\u3002\u7ed9\u51fa\u5b83\u7684\u79fb\u52a8\u987a\u5e8f\uff0c\u5224\u65ad\u8fd9\u4e2a\u673a\u5668\u4eba\u5728\u5b8c\u6210\u79fb\u52a8\u540e\u662f\u5426\u5728 (0, 0) \u5904\u7ed3\u675f\u3002

    \n\n

    \u79fb\u52a8\u987a\u5e8f\u7531\u5b57\u7b26\u4e32\u8868\u793a\u3002\u5b57\u7b26 move[i] \u8868\u793a\u5176\u7b2c i \u6b21\u79fb\u52a8\u3002\u673a\u5668\u4eba\u7684\u6709\u6548\u52a8\u4f5c\u6709 R\uff08\u53f3\uff09\uff0cL\uff08\u5de6\uff09\uff0cU\uff08\u4e0a\uff09\u548c D\uff08\u4e0b\uff09\u3002\u5982\u679c\u673a\u5668\u4eba\u5728\u5b8c\u6210\u6240\u6709\u52a8\u4f5c\u540e\u8fd4\u56de\u539f\u70b9\uff0c\u5219\u8fd4\u56de true\u3002\u5426\u5219\uff0c\u8fd4\u56de false\u3002

    \n\n

    \u6ce8\u610f\uff1a\u673a\u5668\u4eba“\u9762\u671d”\u7684\u65b9\u5411\u65e0\u5173\u7d27\u8981\u3002 “R” \u5c06\u59cb\u7ec8\u4f7f\u673a\u5668\u4eba\u5411\u53f3\u79fb\u52a8\u4e00\u6b21\uff0c“L” \u5c06\u59cb\u7ec8\u5411\u5de6\u79fb\u52a8\u7b49\u3002\u6b64\u5916\uff0c\u5047\u8bbe\u6bcf\u6b21\u79fb\u52a8\u673a\u5668\u4eba\u7684\u79fb\u52a8\u5e45\u5ea6\u76f8\u540c\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: "UD"\n\u8f93\u51fa: true\n\u89e3\u91ca\uff1a\u673a\u5668\u4eba\u5411\u4e0a\u79fb\u52a8\u4e00\u6b21\uff0c\u7136\u540e\u5411\u4e0b\u79fb\u52a8\u4e00\u6b21\u3002\u6240\u6709\u52a8\u4f5c\u90fd\u5177\u6709\u76f8\u540c\u7684\u5e45\u5ea6\uff0c\u56e0\u6b64\u5b83\u6700\u7ec8\u56de\u5230\u5b83\u5f00\u59cb\u7684\u539f\u70b9\u3002\u56e0\u6b64\uff0c\u6211\u4eec\u8fd4\u56de true\u3002
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: "LL"\n\u8f93\u51fa: false\n\u89e3\u91ca\uff1a\u673a\u5668\u4eba\u5411\u5de6\u79fb\u52a8\u4e24\u6b21\u3002\u5b83\u6700\u7ec8\u4f4d\u4e8e\u539f\u70b9\u7684\u5de6\u4fa7\uff0c\u8ddd\u539f\u70b9\u6709\u4e24\u6b21 “\u79fb\u52a8” \u7684\u8ddd\u79bb\u3002\u6211\u4eec\u8fd4\u56de false\uff0c\u56e0\u4e3a\u5b83\u5728\u79fb\u52a8\u7ed3\u675f\u65f6\u6ca1\u6709\u8fd4\u56de\u539f\u70b9\u3002
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool judgeCircle(string moves) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean judgeCircle(String moves) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def judgeCircle(self, moves):\n \"\"\"\n :type moves: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def judgeCircle(self, moves: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool judgeCircle(char * moves){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool JudgeCircle(string moves) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} moves\n * @return {boolean}\n */\nvar judgeCircle = function(moves) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} moves\n# @return {Boolean}\ndef judge_circle(moves)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func judgeCircle(_ moves: String) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func judgeCircle(moves string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def judgeCircle(moves: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun judgeCircle(moves: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn judge_circle(moves: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $moves\n * @return Boolean\n */\n function judgeCircle($moves) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function judgeCircle(moves: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (judge-circle moves)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0657](https://leetcode-cn.com/problems/robot-return-to-origin)", "[\u673a\u5668\u4eba\u80fd\u5426\u8fd4\u56de\u539f\u70b9](/solution/0600-0699/0657.Robot%20Return%20to%20Origin/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0657](https://leetcode.com/problems/robot-return-to-origin)", "[Robot Return to Origin](/solution/0600-0699/0657.Robot%20Return%20to%20Origin/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "0656", "frontend_question_id": "0656", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/coin-path", "url_en": "https://leetcode.com/problems/coin-path", "relative_path_cn": "/solution/0600-0699/0656.Coin%20Path/README.md", "relative_path_en": "/solution/0600-0699/0656.Coin%20Path/README_EN.md", "title_cn": "\u91d1\u5e01\u8def\u5f84", "title_en": "Coin Path", "question_title_slug": "coin-path", "content_en": "

    You are given an integer array coins (1-indexed) of length n and an integer maxJump. You can jump to any index i of the array coins if coins[i] != -1 and you have to pay coins[i] when you visit index i. In addition to that, if you are currently at index i, you can only jump to any index i + k where i + k <= n and k is a value in the range [1, maxJump].

    \n\n

    You are initially positioned at index 1 (coins[1] is not -1). You want to find the path that reaches index n with the minimum cost.

    \n\n

    Return an integer array of the indices that you will visit in order so that you can reach index n with the minimum cost. If there are multiple paths with the same cost, return the lexicographically smallest such path. If it is not possible to reach index n, return an empty array.

    \n\n

    A path p1 = [Pa1, Pa2, ..., Pax] of length x is lexicographically smaller than p2 = [Pb1, Pb2, ..., Pbx] of length y, if and only if at the first j where Paj and Pbj differ, Paj < Pbj; when no such j exists, then x < y.

    \n\n

     

    \n

    Example 1:

    \n
    Input: coins = [1,2,4,-1,2], maxJump = 2\nOutput: [1,3,5]\n

    Example 2:

    \n
    Input: coins = [1,2,4,-1,2], maxJump = 1\nOutput: []\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= coins.length <= 1000
    • \n\t
    • -1 <= coins[i] <= 100
    • \n\t
    • coins[1] != -1
    • \n\t
    • 1 <= maxJump <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6570\u7ec4 A\uff08\u4e0b\u6807\u4ece 1 \u5f00\u59cb\uff09\u5305\u542b N \u4e2a\u6574\u6570\uff1aA1\uff0cA2\uff0c……\uff0cAN \u548c\u4e00\u4e2a\u6574\u6570 B\u3002\u4f60\u53ef\u4ee5\u4ece\u6570\u7ec4 A \u4e2d\u7684\u4efb\u4f55\u4e00\u4e2a\u4f4d\u7f6e\uff08\u4e0b\u6807\u4e3a i\uff09\u8df3\u5230\u4e0b\u6807 i+1\uff0ci+2\uff0c……\uff0ci+B \u7684\u4efb\u610f\u4e00\u4e2a\u53ef\u4ee5\u8df3\u5230\u7684\u4f4d\u7f6e\u4e0a\u3002\u5982\u679c\u4f60\u5728\u4e0b\u6807\u4e3a i \u7684\u4f4d\u7f6e\u4e0a\uff0c\u4f60\u9700\u8981\u652f\u4ed8 Ai \u4e2a\u91d1\u5e01\u3002\u5982\u679c Ai \u662f -1\uff0c\u610f\u5473\u7740\u4e0b\u6807\u4e3a i \u7684\u4f4d\u7f6e\u662f\u4e0d\u53ef\u4ee5\u8df3\u5230\u7684\u3002

    \n\n

    \u73b0\u5728\uff0c\u4f60\u5e0c\u671b\u82b1\u8d39\u6700\u5c11\u7684\u91d1\u5e01\u4ece\u6570\u7ec4 A \u7684 1 \u4f4d\u7f6e\u8df3\u5230 N \u4f4d\u7f6e\uff0c\u4f60\u9700\u8981\u8f93\u51fa\u82b1\u8d39\u6700\u5c11\u7684\u8def\u5f84\uff0c\u4f9d\u6b21\u8f93\u51fa\u6240\u6709\u7ecf\u8fc7\u7684\u4e0b\u6807\uff08\u4ece 1 \u5230 N\uff09\u3002

    \n\n

    \u5982\u679c\u6709\u591a\u79cd\u82b1\u8d39\u6700\u5c11\u7684\u65b9\u6848\uff0c\u8f93\u51fa\u5b57\u5178\u987a\u5e8f\u6700\u5c0f\u7684\u8def\u5f84\u3002

    \n\n

    \u5982\u679c\u65e0\u6cd5\u5230\u8fbe N \u4f4d\u7f6e\uff0c\u8bf7\u8fd4\u56de\u4e00\u4e2a\u7a7a\u6570\u7ec4\u3002

    \n\n

     

    \n\n

    \u6837\u4f8b 1 :

    \n\n
    \u8f93\u5165: [1,2,4,-1,2], 2\n\u8f93\u51fa: [1,3,5]\n
    \n\n

     

    \n\n

    \u6837\u4f8b 2 :

    \n\n
    \u8f93\u5165: [1,2,4,-1,2], 1\n\u8f93\u51fa: []\n
    \n\n

     

    \n\n

    \u6ce8\u91ca :

    \n\n
      \n\t
    1. \u8def\u5f84 Pa1\uff0cPa2\uff0c……\uff0cPa\u662f\u5b57\u5178\u5e8f\u5c0f\u4e8e Pb1\uff0cPb2\uff0c……\uff0cPb\u7684\uff0c\u5f53\u4e14\u4ec5\u5f53\u7b2c\u4e00\u4e2a Pai \u548c Pbi \u4e0d\u540c\u7684 i \u6ee1\u8db3 Pai < Pbi\uff0c\u5982\u679c\u4e0d\u5b58\u5728\u8fd9\u6837\u7684 i \u90a3\u4e48\u6ee1\u8db3 n < m\u3002
    2. \n\t
    3. A1 >= 0\u3002 A2, ..., AN \uff08\u5982\u679c\u5b58\u5728\uff09 \u7684\u8303\u56f4\u662f [-1, 100]\u3002
    4. \n\t
    5. A \u6570\u7ec4\u7684\u957f\u5ea6\u8303\u56f4 [1, 1000].
    6. \n\t
    7. B \u7684\u8303\u56f4 [1, 100].
    8. \n
    \n\n

     

    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector cheapestJump(vector& coins, int maxJump) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List cheapestJump(int[] coins, int maxJump) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def cheapestJump(self, coins, maxJump):\n \"\"\"\n :type coins: List[int]\n :type maxJump: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def cheapestJump(self, coins: List[int], maxJump: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* cheapestJump(int* coins, int coinsSize, int maxJump, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList CheapestJump(int[] coins, int maxJump) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} coins\n * @param {number} maxJump\n * @return {number[]}\n */\nvar cheapestJump = function(coins, maxJump) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} coins\n# @param {Integer} max_jump\n# @return {Integer[]}\ndef cheapest_jump(coins, max_jump)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func cheapestJump(_ coins: [Int], _ maxJump: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func cheapestJump(coins []int, maxJump int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def cheapestJump(coins: Array[Int], maxJump: Int): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun cheapestJump(coins: IntArray, maxJump: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn cheapest_jump(coins: Vec, max_jump: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $coins\n * @param Integer $maxJump\n * @return Integer[]\n */\n function cheapestJump($coins, $maxJump) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function cheapestJump(coins: number[], maxJump: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (cheapest-jump coins maxJump)\n (-> (listof exact-integer?) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0656](https://leetcode-cn.com/problems/coin-path)", "[\u91d1\u5e01\u8def\u5f84](/solution/0600-0699/0656.Coin%20Path/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0656](https://leetcode.com/problems/coin-path)", "[Coin Path](/solution/0600-0699/0656.Coin%20Path/README_EN.md)", "`Dynamic Programming`", "Hard", "\ud83d\udd12"]}, {"question_id": "0655", "frontend_question_id": "0655", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/print-binary-tree", "url_en": "https://leetcode.com/problems/print-binary-tree", "relative_path_cn": "/solution/0600-0699/0655.Print%20Binary%20Tree/README.md", "relative_path_en": "/solution/0600-0699/0655.Print%20Binary%20Tree/README_EN.md", "title_cn": "\u8f93\u51fa\u4e8c\u53c9\u6811", "title_en": "Print Binary Tree", "question_title_slug": "print-binary-tree", "content_en": "

    Given the root of a binary tree, construct a 0-indexed m x n string matrix res that represents a formatted layout of the tree. The formatted layout matrix should be constructed using the following rules:

    \n\n
      \n\t
    • The height of the tree is height and the number of rows m should be equal to height + 1.
    • \n\t
    • The number of columns n should be equal to 2height+1 - 1.
    • \n\t
    • Place the root node in the middle of the top row (more formally, at location res[0][(n-1)/2]).
    • \n\t
    • For each node that has been placed in the matrix at position res[r][c], place its left child at res[r+1][c-2height-r-1] and its right child at res[r+1][c+2height-r-1].
    • \n\t
    • Continue this process until all the nodes in the tree have been placed.
    • \n\t
    • Any empty cells should contain the empty string "".
    • \n
    \n\n

    Return the constructed matrix res.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,2]\nOutput: \n[["","1",""],\n ["2","",""]]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [1,2,3,null,4]\nOutput: \n[["","","","1","","",""],\n ["","2","","","","3",""],\n ["","","4","","","",""]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 210].
    • \n\t
    • -99 <= Node.val <= 99
    • \n\t
    • The depth of the tree will be in the range [1, 10].
    • \n
    \n", "content_cn": "

    \u5728\u4e00\u4e2a m*n \u7684\u4e8c\u7ef4\u5b57\u7b26\u4e32\u6570\u7ec4\u4e2d\u8f93\u51fa\u4e8c\u53c9\u6811\uff0c\u5e76\u9075\u5b88\u4ee5\u4e0b\u89c4\u5219\uff1a

    \n\n
      \n\t
    1. \u884c\u6570 m \u5e94\u5f53\u7b49\u4e8e\u7ed9\u5b9a\u4e8c\u53c9\u6811\u7684\u9ad8\u5ea6\u3002
    2. \n\t
    3. \u5217\u6570 n \u5e94\u5f53\u603b\u662f\u5947\u6570\u3002
    4. \n\t
    5. \u6839\u8282\u70b9\u7684\u503c\uff08\u4ee5\u5b57\u7b26\u4e32\u683c\u5f0f\u7ed9\u51fa\uff09\u5e94\u5f53\u653e\u5728\u53ef\u653e\u7f6e\u7684\u7b2c\u4e00\u884c\u6b63\u4e2d\u95f4\u3002\u6839\u8282\u70b9\u6240\u5728\u7684\u884c\u4e0e\u5217\u4f1a\u5c06\u5269\u4f59\u7a7a\u95f4\u5212\u5206\u4e3a\u4e24\u90e8\u5206\uff08\u5de6\u4e0b\u90e8\u5206\u548c\u53f3\u4e0b\u90e8\u5206\uff09\u3002\u4f60\u5e94\u8be5\u5c06\u5de6\u5b50\u6811\u8f93\u51fa\u5728\u5de6\u4e0b\u90e8\u5206\uff0c\u53f3\u5b50\u6811\u8f93\u51fa\u5728\u53f3\u4e0b\u90e8\u5206\u3002\u5de6\u4e0b\u548c\u53f3\u4e0b\u90e8\u5206\u5e94\u5f53\u6709\u76f8\u540c\u7684\u5927\u5c0f\u3002\u5373\u4f7f\u4e00\u4e2a\u5b50\u6811\u4e3a\u7a7a\u800c\u53e6\u4e00\u4e2a\u975e\u7a7a\uff0c\u4f60\u4e0d\u9700\u8981\u4e3a\u7a7a\u7684\u5b50\u6811\u8f93\u51fa\u4efb\u4f55\u4e1c\u897f\uff0c\u4f46\u4ecd\u9700\u8981\u4e3a\u53e6\u4e00\u4e2a\u5b50\u6811\u7559\u51fa\u8db3\u591f\u7684\u7a7a\u95f4\u3002\u7136\u800c\uff0c\u5982\u679c\u4e24\u4e2a\u5b50\u6811\u90fd\u4e3a\u7a7a\u5219\u4e0d\u9700\u8981\u4e3a\u5b83\u4eec\u7559\u51fa\u4efb\u4f55\u7a7a\u95f4\u3002
    6. \n\t
    7. \u6bcf\u4e2a\u672a\u4f7f\u7528\u7684\u7a7a\u95f4\u5e94\u5305\u542b\u4e00\u4e2a\u7a7a\u7684\u5b57\u7b26\u4e32""\u3002
    8. \n\t
    9. \u4f7f\u7528\u76f8\u540c\u7684\u89c4\u5219\u8f93\u51fa\u5b50\u6811\u3002
    10. \n
    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165:\n     1\n    /\n   2\n\u8f93\u51fa:\n[["", "1", ""],\n ["2", "", ""]]\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165:\n     1\n    / \\\n   2   3\n    \\\n     4\n\u8f93\u51fa:\n[["", "", "", "1", "", "", ""],\n ["", "2", "", "", "", "3", ""],\n ["", "", "4", "", "", "", ""]]\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \n\u8f93\u5165:\n      1\n     / \\\n    2   5\n   / \n  3 \n / \n4 \n\u8f93\u51fa:\n[["",  "",  "", "",  "", "", "", "1", "",  "",  "",  "",  "", "", ""]\n ["",  "",  "", "2", "", "", "", "",  "",  "",  "",  "5", "", "", ""]\n ["",  "3", "", "",  "", "", "", "",  "",  "",  "",  "",  "", "", ""]\n ["4", "",  "", "",  "", "", "", "",  "",  "",  "",  "",  "", "", ""]]\n
    \n\n

    \u6ce8\u610f: \u4e8c\u53c9\u6811\u7684\u9ad8\u5ea6\u5728\u8303\u56f4 [1, 10] \u4e2d\u3002

    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector> printTree(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public List> printTree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def printTree(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: List[List[str]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def printTree(self, root: TreeNode) -> List[List[str]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nchar *** printTree(struct TreeNode* root, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public IList> PrintTree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {string[][]}\n */\nvar printTree = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {String[][]}\ndef print_tree(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func printTree(_ root: TreeNode?) -> [[String]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc printTree(root *TreeNode) [][]string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def printTree(root: TreeNode): List[List[String]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun printTree(root: TreeNode?): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn print_tree(root: Option>>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return String[][]\n */\n function printTree($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction printTree(root: TreeNode | null): string[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (print-tree root)\n (-> (or/c tree-node? #f) (listof (listof string?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0655](https://leetcode-cn.com/problems/print-binary-tree)", "[\u8f93\u51fa\u4e8c\u53c9\u6811](/solution/0600-0699/0655.Print%20Binary%20Tree/README.md)", "`\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0655](https://leetcode.com/problems/print-binary-tree)", "[Print Binary Tree](/solution/0600-0699/0655.Print%20Binary%20Tree/README_EN.md)", "`Tree`", "Medium", ""]}, {"question_id": "0654", "frontend_question_id": "0654", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-binary-tree", "url_en": "https://leetcode.com/problems/maximum-binary-tree", "relative_path_cn": "/solution/0600-0699/0654.Maximum%20Binary%20Tree/README.md", "relative_path_en": "/solution/0600-0699/0654.Maximum%20Binary%20Tree/README_EN.md", "title_cn": "\u6700\u5927\u4e8c\u53c9\u6811", "title_en": "Maximum Binary Tree", "question_title_slug": "maximum-binary-tree", "content_en": "

    You are given an integer array nums with no duplicates. A maximum binary tree can be built recursively from nums using the following algorithm:

    \n\n
      \n\t
    1. Create a root node whose value is the maximum value in nums.
    2. \n\t
    3. Recursively build the left subtree on the subarray prefix to the left of the maximum value.
    4. \n\t
    5. Recursively build the right subtree on the subarray suffix to the right of the maximum value.
    6. \n
    \n\n

    Return the maximum binary tree built from nums.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: nums = [3,2,1,6,0,5]\nOutput: [6,3,5,null,2,0,null,null,1]\nExplanation: The recursive calls are as follow:\n- The largest value in [3,2,1,6,0,5] is 6. Left prefix is [3,2,1] and right suffix is [0,5].\n    - The largest value in [3,2,1] is 3. Left prefix is [] and right suffix is [2,1].\n        - Empty array, so no child.\n        - The largest value in [2,1] is 2. Left prefix is [] and right suffix is [1].\n            - Empty array, so no child.\n            - Only one element, so child is a node with value 1.\n    - The largest value in [0,5] is 5. Left prefix is [0] and right suffix is [].\n        - Only one element, so child is a node with value 0.\n        - Empty array, so no child.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: nums = [3,2,1]\nOutput: [3,null,2,null,1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 1000
    • \n\t
    • 0 <= nums[i] <= 1000
    • \n\t
    • All integers in nums are unique.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e0d\u542b\u91cd\u590d\u5143\u7d20\u7684\u6574\u6570\u6570\u7ec4 nums \u3002\u4e00\u4e2a\u4ee5\u6b64\u6570\u7ec4\u76f4\u63a5\u9012\u5f52\u6784\u5efa\u7684 \u6700\u5927\u4e8c\u53c9\u6811 \u5b9a\u4e49\u5982\u4e0b\uff1a

    \n\n
      \n\t
    1. \u4e8c\u53c9\u6811\u7684\u6839\u662f\u6570\u7ec4 nums \u4e2d\u7684\u6700\u5927\u5143\u7d20\u3002
    2. \n\t
    3. \u5de6\u5b50\u6811\u662f\u901a\u8fc7\u6570\u7ec4\u4e2d \u6700\u5927\u503c\u5de6\u8fb9\u90e8\u5206 \u9012\u5f52\u6784\u9020\u51fa\u7684\u6700\u5927\u4e8c\u53c9\u6811\u3002
    4. \n\t
    5. \u53f3\u5b50\u6811\u662f\u901a\u8fc7\u6570\u7ec4\u4e2d \u6700\u5927\u503c\u53f3\u8fb9\u90e8\u5206 \u9012\u5f52\u6784\u9020\u51fa\u7684\u6700\u5927\u4e8c\u53c9\u6811\u3002
    6. \n
    \n\n

    \u8fd4\u56de\u6709\u7ed9\u5b9a\u6570\u7ec4 nums \u6784\u5efa\u7684 \u6700\u5927\u4e8c\u53c9\u6811 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1anums = [3,2,1,6,0,5]\n\u8f93\u51fa\uff1a[6,3,5,null,2,0,null,null,1]\n\u89e3\u91ca\uff1a\u9012\u5f52\u8c03\u7528\u5982\u4e0b\u6240\u793a\uff1a\n- [3,2,1,6,0,5] \u4e2d\u7684\u6700\u5927\u503c\u662f 6 \uff0c\u5de6\u8fb9\u90e8\u5206\u662f [3,2,1] \uff0c\u53f3\u8fb9\u90e8\u5206\u662f [0,5] \u3002\n    - [3,2,1] \u4e2d\u7684\u6700\u5927\u503c\u662f 3 \uff0c\u5de6\u8fb9\u90e8\u5206\u662f [] \uff0c\u53f3\u8fb9\u90e8\u5206\u662f [2,1] \u3002\n        - \u7a7a\u6570\u7ec4\uff0c\u65e0\u5b50\u8282\u70b9\u3002\n        - [2,1] \u4e2d\u7684\u6700\u5927\u503c\u662f 2 \uff0c\u5de6\u8fb9\u90e8\u5206\u662f [] \uff0c\u53f3\u8fb9\u90e8\u5206\u662f [1] \u3002\n            - \u7a7a\u6570\u7ec4\uff0c\u65e0\u5b50\u8282\u70b9\u3002\n            - \u53ea\u6709\u4e00\u4e2a\u5143\u7d20\uff0c\u6240\u4ee5\u5b50\u8282\u70b9\u662f\u4e00\u4e2a\u503c\u4e3a 1 \u7684\u8282\u70b9\u3002\n    - [0,5] \u4e2d\u7684\u6700\u5927\u503c\u662f 5 \uff0c\u5de6\u8fb9\u90e8\u5206\u662f [0] \uff0c\u53f3\u8fb9\u90e8\u5206\u662f [] \u3002\n        - \u53ea\u6709\u4e00\u4e2a\u5143\u7d20\uff0c\u6240\u4ee5\u5b50\u8282\u70b9\u662f\u4e00\u4e2a\u503c\u4e3a 0 \u7684\u8282\u70b9\u3002\n        - \u7a7a\u6570\u7ec4\uff0c\u65e0\u5b50\u8282\u70b9\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1anums = [3,2,1]\n\u8f93\u51fa\uff1a[3,null,2,null,1]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 1000
    • \n\t
    • 0 <= nums[i] <= 1000
    • \n\t
    • nums \u4e2d\u7684\u6240\u6709\u6574\u6570 \u4e92\u4e0d\u76f8\u540c
    • \n
    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* constructMaximumBinaryTree(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode constructMaximumBinaryTree(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def constructMaximumBinaryTree(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: TreeNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def constructMaximumBinaryTree(self, nums: List[int]) -> TreeNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* constructMaximumBinaryTree(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode ConstructMaximumBinaryTree(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {number[]} nums\n * @return {TreeNode}\n */\nvar constructMaximumBinaryTree = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {Integer[]} nums\n# @return {TreeNode}\ndef construct_maximum_binary_tree(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func constructMaximumBinaryTree(_ nums: [Int]) -> TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc constructMaximumBinaryTree(nums []int) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def constructMaximumBinaryTree(nums: Array[Int]): TreeNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun constructMaximumBinaryTree(nums: IntArray): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn construct_maximum_binary_tree(nums: Vec) -> Option>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param Integer[] $nums\n * @return TreeNode\n */\n function constructMaximumBinaryTree($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction constructMaximumBinaryTree(nums: number[]): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (construct-maximum-binary-tree nums)\n (-> (listof exact-integer?) (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0654](https://leetcode-cn.com/problems/maximum-binary-tree)", "[\u6700\u5927\u4e8c\u53c9\u6811](/solution/0600-0699/0654.Maximum%20Binary%20Tree/README.md)", "`\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0654](https://leetcode.com/problems/maximum-binary-tree)", "[Maximum Binary Tree](/solution/0600-0699/0654.Maximum%20Binary%20Tree/README_EN.md)", "`Tree`", "Medium", ""]}, {"question_id": "0653", "frontend_question_id": "0653", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/two-sum-iv-input-is-a-bst", "url_en": "https://leetcode.com/problems/two-sum-iv-input-is-a-bst", "relative_path_cn": "/solution/0600-0699/0653.Two%20Sum%20IV%20-%20Input%20is%20a%20BST/README.md", "relative_path_en": "/solution/0600-0699/0653.Two%20Sum%20IV%20-%20Input%20is%20a%20BST/README_EN.md", "title_cn": "\u4e24\u6570\u4e4b\u548c IV - \u8f93\u5165 BST", "title_en": "Two Sum IV - Input is a BST", "question_title_slug": "two-sum-iv-input-is-a-bst", "content_en": "

    Given the root of a Binary Search Tree and a target number k, return true if there exist two elements in the BST such that their sum is equal to the given target.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [5,3,6,2,4,null,7], k = 9\nOutput: true\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [5,3,6,2,4,null,7], k = 28\nOutput: false\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = [2,1,3], k = 4\nOutput: true\n
    \n\n

    Example 4:

    \n\n
    \nInput: root = [2,1,3], k = 1\nOutput: false\n
    \n\n

    Example 5:

    \n\n
    \nInput: root = [2,1,3], k = 3\nOutput: true\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 104].
    • \n\t
    • -104 <= Node.val <= 104
    • \n\t
    • root is guaranteed to be a valid binary search tree.
    • \n\t
    • -105 <= k <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u641c\u7d22\u6811\u548c\u4e00\u4e2a\u76ee\u6807\u7ed3\u679c\uff0c\u5982\u679c BST \u4e2d\u5b58\u5728\u4e24\u4e2a\u5143\u7d20\u4e14\u5b83\u4eec\u7684\u548c\u7b49\u4e8e\u7ed9\u5b9a\u7684\u76ee\u6807\u7ed3\u679c\uff0c\u5219\u8fd4\u56de true\u3002

    \n\n

    \u6848\u4f8b 1:

    \n\n
    \n\u8f93\u5165: \n    5\n   / \\\n  3   6\n / \\   \\\n2   4   7\n\nTarget = 9\n\n\u8f93\u51fa: True\n
    \n\n

     

    \n\n

    \u6848\u4f8b 2:

    \n\n
    \n\u8f93\u5165: \n    5\n   / \\\n  3   6\n / \\   \\\n2   4   7\n\nTarget = 28\n\n\u8f93\u51fa: False\n
    \n\n

     

    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n bool findTarget(TreeNode* root, int k) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public boolean findTarget(TreeNode root, int k) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def findTarget(self, root, k):\n \"\"\"\n :type root: TreeNode\n :type k: int\n :rtype: bool\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def findTarget(self, root: TreeNode, k: int) -> bool:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nbool findTarget(struct TreeNode* root, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public bool FindTarget(TreeNode root, int k) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number} k\n * @return {boolean}\n */\nvar findTarget = function(root, k) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @param {Integer} k\n# @return {Boolean}\ndef find_target(root, k)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func findTarget(_ root: TreeNode?, _ k: Int) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc findTarget(root *TreeNode, k int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def findTarget(root: TreeNode, k: Int): Boolean = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun findTarget(root: TreeNode?, k: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn find_target(root: Option>>, k: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param Integer $k\n * @return Boolean\n */\n function findTarget($root, $k) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction findTarget(root: TreeNode | null, k: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (find-target root k)\n (-> (or/c tree-node? #f) exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0653](https://leetcode-cn.com/problems/two-sum-iv-input-is-a-bst)", "[\u4e24\u6570\u4e4b\u548c IV - \u8f93\u5165 BST](/solution/0600-0699/0653.Two%20Sum%20IV%20-%20Input%20is%20a%20BST/README.md)", "`\u6811`", "\u7b80\u5355", ""], "md_table_row_en": ["[0653](https://leetcode.com/problems/two-sum-iv-input-is-a-bst)", "[Two Sum IV - Input is a BST](/solution/0600-0699/0653.Two%20Sum%20IV%20-%20Input%20is%20a%20BST/README_EN.md)", "`Tree`", "Easy", ""]}, {"question_id": "0652", "frontend_question_id": "0652", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-duplicate-subtrees", "url_en": "https://leetcode.com/problems/find-duplicate-subtrees", "relative_path_cn": "/solution/0600-0699/0652.Find%20Duplicate%20Subtrees/README.md", "relative_path_en": "/solution/0600-0699/0652.Find%20Duplicate%20Subtrees/README_EN.md", "title_cn": "\u5bfb\u627e\u91cd\u590d\u7684\u5b50\u6811", "title_en": "Find Duplicate Subtrees", "question_title_slug": "find-duplicate-subtrees", "content_en": "

    Given the root of a binary tree, return all duplicate subtrees.

    \n\n

    For each kind of duplicate subtrees, you only need to return the root node of any one of them.

    \n\n

    Two trees are duplicate if they have the same structure with the same node values.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,2,3,4,null,2,4,null,null,4]\nOutput: [[2,4],[4]]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [2,1,1]\nOutput: [[1]]\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: root = [2,2,2,3,null,3,null]\nOutput: [[2,3],[3]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of the nodes in the tree will be in the range [1, 10^4]
    • \n\t
    • -200 <= Node.val <= 200
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u68f5\u4e8c\u53c9\u6811\uff0c\u8fd4\u56de\u6240\u6709\u91cd\u590d\u7684\u5b50\u6811\u3002\u5bf9\u4e8e\u540c\u4e00\u7c7b\u7684\u91cd\u590d\u5b50\u6811\uff0c\u4f60\u53ea\u9700\u8981\u8fd4\u56de\u5176\u4e2d\u4efb\u610f\u4e00\u68f5\u7684\u6839\u7ed3\u70b9\u5373\u53ef\u3002

    \n\n

    \u4e24\u68f5\u6811\u91cd\u590d\u662f\u6307\u5b83\u4eec\u5177\u6709\u76f8\u540c\u7684\u7ed3\u6784\u4ee5\u53ca\u76f8\u540c\u7684\u7ed3\u70b9\u503c\u3002

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
            1\n       / \\\n      2   3\n     /   / \\\n    4   2   4\n       /\n      4\n
    \n\n

    \u4e0b\u9762\u662f\u4e24\u4e2a\u91cd\u590d\u7684\u5b50\u6811\uff1a

    \n\n
          2\n     /\n    4\n
    \n\n

    \u548c

    \n\n
        4\n
    \n\n

    \u56e0\u6b64\uff0c\u4f60\u9700\u8981\u4ee5\u5217\u8868\u7684\u5f62\u5f0f\u8fd4\u56de\u4e0a\u8ff0\u91cd\u590d\u5b50\u6811\u7684\u6839\u7ed3\u70b9\u3002

    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector findDuplicateSubtrees(TreeNode* root) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public List findDuplicateSubtrees(TreeNode root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def findDuplicateSubtrees(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: List[TreeNode]\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def findDuplicateSubtrees(self, root: TreeNode) -> List[TreeNode]:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nstruct TreeNode** findDuplicateSubtrees(struct TreeNode* root, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public IList FindDuplicateSubtrees(TreeNode root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {TreeNode[]}\n */\nvar findDuplicateSubtrees = function(root) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {TreeNode[]}\ndef find_duplicate_subtrees(root)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func findDuplicateSubtrees(_ root: TreeNode?) -> [TreeNode?] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc findDuplicateSubtrees(root *TreeNode) []*TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def findDuplicateSubtrees(root: TreeNode): List[TreeNode] = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun findDuplicateSubtrees(root: TreeNode?): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn find_duplicate_subtrees(root: Option>>) -> Vec>>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return TreeNode[]\n */\n function findDuplicateSubtrees($root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction findDuplicateSubtrees(root: TreeNode | null): Array {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (find-duplicate-subtrees root)\n (-> (or/c tree-node? #f) (listof (or/c tree-node? #f)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0652](https://leetcode-cn.com/problems/find-duplicate-subtrees)", "[\u5bfb\u627e\u91cd\u590d\u7684\u5b50\u6811](/solution/0600-0699/0652.Find%20Duplicate%20Subtrees/README.md)", "`\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0652](https://leetcode.com/problems/find-duplicate-subtrees)", "[Find Duplicate Subtrees](/solution/0600-0699/0652.Find%20Duplicate%20Subtrees/README_EN.md)", "`Tree`", "Medium", ""]}, {"question_id": "0651", "frontend_question_id": "0651", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/4-keys-keyboard", "url_en": "https://leetcode.com/problems/4-keys-keyboard", "relative_path_cn": "/solution/0600-0699/0651.4%20Keys%20Keyboard/README.md", "relative_path_en": "/solution/0600-0699/0651.4%20Keys%20Keyboard/README_EN.md", "title_cn": "4\u952e\u952e\u76d8", "title_en": "4 Keys Keyboard", "question_title_slug": "4-keys-keyboard", "content_en": "

    Imagine you have a special keyboard with the following keys:

    \n\n
      \n\t
    • A: Print one 'A' on the screen.
    • \n\t
    • Ctrl-A: Select the whole screen.
    • \n\t
    • Ctrl-C: Copy selection to buffer.
    • \n\t
    • Ctrl-V: Print buffer on screen appending it after what has already been printed.
    • \n
    \n\n

    Given an integer n, return the maximum number of 'A' you can print on the screen with at most n presses on the keys.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 3\nOutput: 3\nExplanation: We can at most get 3 A's on screen by pressing the following key sequence:\nA, A, A\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 7\nOutput: 9\nExplanation: We can at most get 9 A's on screen by pressing following key sequence:\nA, A, A, Ctrl A, Ctrl C, Ctrl V, Ctrl V\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 50
    • \n
    \n", "content_cn": "

    \u5047\u8bbe\u4f60\u6709\u4e00\u4e2a\u7279\u6b8a\u7684\u952e\u76d8\u5305\u542b\u4e0b\u9762\u7684\u6309\u952e\uff1a

    \n\n

    Key 1: (A)\uff1a\u5728\u5c4f\u5e55\u4e0a\u6253\u5370\u4e00\u4e2a 'A'\u3002

    \n\n

    Key 2: (Ctrl-A)\uff1a\u9009\u4e2d\u6574\u4e2a\u5c4f\u5e55\u3002

    \n\n

    Key 3: (Ctrl-C)\uff1a\u590d\u5236\u9009\u4e2d\u533a\u57df\u5230\u7f13\u51b2\u533a\u3002

    \n\n

    Key 4: (Ctrl-V)\uff1a\u5c06\u7f13\u51b2\u533a\u5185\u5bb9\u8f93\u51fa\u5230\u4e0a\u6b21\u8f93\u5165\u7684\u7ed3\u675f\u4f4d\u7f6e\uff0c\u5e76\u663e\u793a\u5728\u5c4f\u5e55\u4e0a\u3002

    \n\n

    \u73b0\u5728\uff0c\u4f60\u53ea\u53ef\u4ee5\u6309\u952e N \u6b21\uff08\u4f7f\u7528\u4e0a\u8ff0\u56db\u79cd\u6309\u952e\uff09\uff0c\u8bf7\u95ee\u5c4f\u5e55\u4e0a\u6700\u591a\u53ef\u4ee5\u663e\u793a\u51e0\u4e2a 'A'\u5462\uff1f

    \n\n

    \u6837\u4f8b 1:

    \n\n
    \u8f93\u5165: N = 3\n\u8f93\u51fa: 3\n\u89e3\u91ca: \n\u6211\u4eec\u6700\u591a\u53ef\u4ee5\u5728\u5c4f\u5e55\u4e0a\u663e\u793a\u4e09\u4e2a'A'\u901a\u8fc7\u5982\u4e0b\u987a\u5e8f\u6309\u952e\uff1a\nA, A, A\n
    \n\n

     

    \n\n

    \u6837\u4f8b 2:

    \n\n
    \u8f93\u5165: N = 7\n\u8f93\u51fa: 9\n\u89e3\u91ca: \n\u6211\u4eec\u6700\u591a\u53ef\u4ee5\u5728\u5c4f\u5e55\u4e0a\u663e\u793a\u4e5d\u4e2a'A'\u901a\u8fc7\u5982\u4e0b\u987a\u5e8f\u6309\u952e\uff1a\nA, A, A, Ctrl A, Ctrl C, Ctrl V, Ctrl V\n
    \n\n

     

    \n\n

    \u6ce8\u91ca:

    \n\n
      \n\t
    1. 1 <= N <= 50
    2. \n\t
    3. \u7ed3\u679c\u4e0d\u4f1a\u8d85\u8fc7 32 \u4f4d\u6709\u7b26\u53f7\u6574\u6570\u8303\u56f4\u3002
    4. \n
    \n\n

     

    \n", "tags_en": ["Greedy", "Math", "Dynamic Programming"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u5b66", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxA(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxA(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxA(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxA(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxA(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxA(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar maxA = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef max_a(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxA(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxA(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxA(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxA(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_a(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function maxA($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxA(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-a n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0651](https://leetcode-cn.com/problems/4-keys-keyboard)", "[4\u952e\u952e\u76d8](/solution/0600-0699/0651.4%20Keys%20Keyboard/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u5b66`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0651](https://leetcode.com/problems/4-keys-keyboard)", "[4 Keys Keyboard](/solution/0600-0699/0651.4%20Keys%20Keyboard/README_EN.md)", "`Greedy`,`Math`,`Dynamic Programming`", "Medium", "\ud83d\udd12"]}, {"question_id": "0650", "frontend_question_id": "0650", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/2-keys-keyboard", "url_en": "https://leetcode.com/problems/2-keys-keyboard", "relative_path_cn": "/solution/0600-0699/0650.2%20Keys%20Keyboard/README.md", "relative_path_en": "/solution/0600-0699/0650.2%20Keys%20Keyboard/README_EN.md", "title_cn": "\u53ea\u6709\u4e24\u4e2a\u952e\u7684\u952e\u76d8", "title_en": "2 Keys Keyboard", "question_title_slug": "2-keys-keyboard", "content_en": "

    There is only one character 'A' on the screen of a notepad. You can perform two operations on this notepad for each step:

    \n\n
      \n\t
    • Copy All: You can copy all the characters present on the screen (a partial copy is not allowed).
    • \n\t
    • Paste: You can paste the characters which are copied last time.
    • \n
    \n\n

    Given an integer n, return the minimum number of operations to get the character 'A' exactly n times on the screen.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 3\nOutput: 3\nExplanation: Intitally, we have one character 'A'.\nIn step 1, we use Copy All operation.\nIn step 2, we use Paste operation to get 'AA'.\nIn step 3, we use Paste operation to get 'AAA'.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 1\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 1000
    • \n
    \n", "content_cn": "

    \u6700\u521d\u5728\u4e00\u4e2a\u8bb0\u4e8b\u672c\u4e0a\u53ea\u6709\u4e00\u4e2a\u5b57\u7b26 'A'\u3002\u4f60\u6bcf\u6b21\u53ef\u4ee5\u5bf9\u8fd9\u4e2a\u8bb0\u4e8b\u672c\u8fdb\u884c\u4e24\u79cd\u64cd\u4f5c\uff1a

    \n\n
      \n\t
    1. Copy All (\u590d\u5236\u5168\u90e8) : \u4f60\u53ef\u4ee5\u590d\u5236\u8fd9\u4e2a\u8bb0\u4e8b\u672c\u4e2d\u7684\u6240\u6709\u5b57\u7b26(\u90e8\u5206\u7684\u590d\u5236\u662f\u4e0d\u5141\u8bb8\u7684)\u3002
    2. \n\t
    3. Paste (\u7c98\u8d34) : \u4f60\u53ef\u4ee5\u7c98\u8d34\u4f60\u4e0a\u4e00\u6b21\u590d\u5236\u7684\u5b57\u7b26\u3002
    4. \n
    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u6570\u5b57 n \u3002\u4f60\u9700\u8981\u4f7f\u7528\u6700\u5c11\u7684\u64cd\u4f5c\u6b21\u6570\uff0c\u5728\u8bb0\u4e8b\u672c\u4e2d\u6253\u5370\u51fa\u6070\u597d n \u4e2a 'A'\u3002\u8f93\u51fa\u80fd\u591f\u6253\u5370\u51fa n \u4e2a 'A' \u7684\u6700\u5c11\u64cd\u4f5c\u6b21\u6570\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: 3\n\u8f93\u51fa: 3\n\u89e3\u91ca:\n\u6700\u521d, \u6211\u4eec\u53ea\u6709\u4e00\u4e2a\u5b57\u7b26 'A'\u3002\n\u7b2c 1 \u6b65, \u6211\u4eec\u4f7f\u7528 Copy All \u64cd\u4f5c\u3002\n\u7b2c 2 \u6b65, \u6211\u4eec\u4f7f\u7528 Paste \u64cd\u4f5c\u6765\u83b7\u5f97 'AA'\u3002\n\u7b2c 3 \u6b65, \u6211\u4eec\u4f7f\u7528 Paste \u64cd\u4f5c\u6765\u83b7\u5f97 'AAA'\u3002\n
    \n\n

    \u8bf4\u660e:

    \n\n
      \n\t
    1. n \u7684\u53d6\u503c\u8303\u56f4\u662f [1, 1000] \u3002
    2. \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minSteps(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minSteps(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minSteps(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minSteps(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minSteps(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinSteps(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar minSteps = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef min_steps(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minSteps(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minSteps(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minSteps(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minSteps(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_steps(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function minSteps($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minSteps(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-steps n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0650](https://leetcode-cn.com/problems/2-keys-keyboard)", "[\u53ea\u6709\u4e24\u4e2a\u952e\u7684\u952e\u76d8](/solution/0600-0699/0650.2%20Keys%20Keyboard/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0650](https://leetcode.com/problems/2-keys-keyboard)", "[2 Keys Keyboard](/solution/0600-0699/0650.2%20Keys%20Keyboard/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0649", "frontend_question_id": "0649", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/dota2-senate", "url_en": "https://leetcode.com/problems/dota2-senate", "relative_path_cn": "/solution/0600-0699/0649.Dota2%20Senate/README.md", "relative_path_en": "/solution/0600-0699/0649.Dota2%20Senate/README_EN.md", "title_cn": "Dota2 \u53c2\u8bae\u9662", "title_en": "Dota2 Senate", "question_title_slug": "dota2-senate", "content_en": "

    In the world of Dota2, there are two parties: the Radiant and the Dire.

    \n\n

    The Dota2 senate consists of senators coming from two parties. Now the Senate wants to decide on a change in the Dota2 game. The voting for this change is a round-based procedure. In each round, each senator can exercise one of the two rights:

    \n\n
      \n\t
    • Ban one senator's right: A senator can make another senator lose all his rights in this and all the following rounds.
    • \n\t
    • Announce the victory: If this senator found the senators who still have rights to vote are all from the same party, he can announce the victory and decide on the change in the game.
    • \n
    \n\n

    Given a string senate representing each senator's party belonging. The character 'R' and 'D' represent the Radiant party and the Dire party. Then if there are n senators, the size of the given string will be n.

    \n\n

    The round-based procedure starts from the first senator to the last senator in the given order. This procedure will last until the end of voting. All the senators who have lost their rights will be skipped during the procedure.

    \n\n

    Suppose every senator is smart enough and will play the best strategy for his own party. Predict which party will finally announce the victory and change the Dota2 game. The output should be "Radiant" or "Dire".

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: senate = "RD"\nOutput: "Radiant"\nExplanation: \nThe first senator comes from Radiant and he can just ban the next senator's right in round 1. \nAnd the second senator can't exercise any rights anymore since his right has been banned. \nAnd in round 2, the first senator can just announce the victory since he is the only guy in the senate who can vote.\n
    \n\n

    Example 2:

    \n\n
    \nInput: senate = "RDD"\nOutput: "Dire"\nExplanation: \nThe first senator comes from Radiant and he can just ban the next senator's right in round 1. \nAnd the second senator can't exercise any rights anymore since his right has been banned. \nAnd the third senator comes from Dire and he can ban the first senator's right in round 1. \nAnd in round 2, the third senator can just announce the victory since he is the only guy in the senate who can vote.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == senate.length
    • \n\t
    • 1 <= n <= 104
    • \n\t
    • senate[i] is either 'R' or 'D'.
    • \n
    \n", "content_cn": "

    Dota2 \u7684\u4e16\u754c\u91cc\u6709\u4e24\u4e2a\u9635\u8425\uff1aRadiant(\u5929\u8f89)\u548c\u00a0Dire(\u591c\u9b47)

    \n\n

    Dota2 \u53c2\u8bae\u9662\u7531\u6765\u81ea\u4e24\u6d3e\u7684\u53c2\u8bae\u5458\u7ec4\u6210\u3002\u73b0\u5728\u53c2\u8bae\u9662\u5e0c\u671b\u5bf9\u4e00\u4e2a Dota2 \u6e38\u620f\u91cc\u7684\u6539\u53d8\u4f5c\u51fa\u51b3\u5b9a\u3002\u4ed6\u4eec\u4ee5\u4e00\u4e2a\u57fa\u4e8e\u8f6e\u4e3a\u8fc7\u7a0b\u7684\u6295\u7968\u8fdb\u884c\u3002\u5728\u6bcf\u4e00\u8f6e\u4e2d\uff0c\u6bcf\u4e00\u4f4d\u53c2\u8bae\u5458\u90fd\u53ef\u4ee5\u884c\u4f7f\u4e24\u9879\u6743\u5229\u4e2d\u7684\u4e00\u9879\uff1a

    \n\n
      \n\t
    1. \n\t

      \u7981\u6b62\u4e00\u540d\u53c2\u8bae\u5458\u7684\u6743\u5229\uff1a

      \n\n\t

      \u53c2\u8bae\u5458\u53ef\u4ee5\u8ba9\u53e6\u4e00\u4f4d\u53c2\u8bae\u5458\u5728\u8fd9\u4e00\u8f6e\u548c\u968f\u540e\u7684\u51e0\u8f6e\u4e2d\u4e27\u5931\u6240\u6709\u7684\u6743\u5229\u3002

      \n\t
    2. \n\t
    3. \n\t

      \u5ba3\u5e03\u80dc\u5229\uff1a

      \n\t
    4. \n
    \n\n

    \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u5982\u679c\u53c2\u8bae\u5458\u53d1\u73b0\u6709\u6743\u5229\u6295\u7968\u7684\u53c2\u8bae\u5458\u90fd\u662f\u540c\u4e00\u4e2a\u9635\u8425\u7684\uff0c\u4ed6\u53ef\u4ee5\u5ba3\u5e03\u80dc\u5229\u5e76\u51b3\u5b9a\u5728\u6e38\u620f\u4e2d\u7684\u6709\u5173\u53d8\u5316\u3002

    \n\n

    \u00a0

    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\u4ee3\u8868\u6bcf\u4e2a\u53c2\u8bae\u5458\u7684\u9635\u8425\u3002\u5b57\u6bcd \u201cR\u201d \u548c \u201cD\u201d \u5206\u522b\u4ee3\u8868\u4e86\u00a0Radiant\uff08\u5929\u8f89\uff09\u548c\u00a0Dire\uff08\u591c\u9b47\uff09\u3002\u7136\u540e\uff0c\u5982\u679c\u6709 n \u4e2a\u53c2\u8bae\u5458\uff0c\u7ed9\u5b9a\u5b57\u7b26\u4e32\u7684\u5927\u5c0f\u5c06\u662f\u00a0n\u3002

    \n\n

    \u4ee5\u8f6e\u4e3a\u57fa\u7840\u7684\u8fc7\u7a0b\u4ece\u7ed9\u5b9a\u987a\u5e8f\u7684\u7b2c\u4e00\u4e2a\u53c2\u8bae\u5458\u5f00\u59cb\u5230\u6700\u540e\u4e00\u4e2a\u53c2\u8bae\u5458\u7ed3\u675f\u3002\u8fd9\u4e00\u8fc7\u7a0b\u5c06\u6301\u7eed\u5230\u6295\u7968\u7ed3\u675f\u3002\u6240\u6709\u5931\u53bb\u6743\u5229\u7684\u53c2\u8bae\u5458\u5c06\u5728\u8fc7\u7a0b\u4e2d\u88ab\u8df3\u8fc7\u3002

    \n\n

    \u5047\u8bbe\u6bcf\u4e00\u4f4d\u53c2\u8bae\u5458\u90fd\u8db3\u591f\u806a\u660e\uff0c\u4f1a\u4e3a\u81ea\u5df1\u7684\u653f\u515a\u505a\u51fa\u6700\u597d\u7684\u7b56\u7565\uff0c\u4f60\u9700\u8981\u9884\u6d4b\u54ea\u4e00\u65b9\u6700\u7ec8\u4f1a\u5ba3\u5e03\u80dc\u5229\u5e76\u5728 Dota2 \u6e38\u620f\u4e2d\u51b3\u5b9a\u6539\u53d8\u3002\u8f93\u51fa\u5e94\u8be5\u662f\u00a0Radiant\u00a0\u6216\u00a0Dire\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\"RD\"\n\u8f93\u51fa\uff1a\"Radiant\"\n\u89e3\u91ca\uff1a\u7b2c\u4e00\u4e2a\u53c2\u8bae\u5458\u6765\u81ea Radiant \u9635\u8425\u5e76\u4e14\u4ed6\u53ef\u4ee5\u4f7f\u7528\u7b2c\u4e00\u9879\u6743\u5229\u8ba9\u7b2c\u4e8c\u4e2a\u53c2\u8bae\u5458\u5931\u53bb\u6743\u529b\uff0c\u56e0\u6b64\u7b2c\u4e8c\u4e2a\u53c2\u8bae\u5458\u5c06\u88ab\u8df3\u8fc7\u56e0\u4e3a\u4ed6\u6ca1\u6709\u4efb\u4f55\u6743\u5229\u3002\u7136\u540e\u5728\u7b2c\u4e8c\u8f6e\u7684\u65f6\u5019\uff0c\u7b2c\u4e00\u4e2a\u53c2\u8bae\u5458\u53ef\u4ee5\u5ba3\u5e03\u80dc\u5229\uff0c\u56e0\u4e3a\u4ed6\u662f\u552f\u4e00\u4e00\u4e2a\u6709\u6295\u7968\u6743\u7684\u4eba\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\"RDD\"\n\u8f93\u51fa\uff1a\"Dire\"\n\u89e3\u91ca\uff1a\n\u7b2c\u4e00\u8f6e\u4e2d,\u7b2c\u4e00\u4e2a\u6765\u81ea Radiant \u9635\u8425\u7684\u53c2\u8bae\u5458\u53ef\u4ee5\u4f7f\u7528\u7b2c\u4e00\u9879\u6743\u5229\u7981\u6b62\u7b2c\u4e8c\u4e2a\u53c2\u8bae\u5458\u7684\u6743\u5229\n\u7b2c\u4e8c\u4e2a\u6765\u81ea Dire \u9635\u8425\u7684\u53c2\u8bae\u5458\u4f1a\u88ab\u8df3\u8fc7\u56e0\u4e3a\u4ed6\u7684\u6743\u5229\u88ab\u7981\u6b62\n\u7b2c\u4e09\u4e2a\u6765\u81ea Dire \u9635\u8425\u7684\u53c2\u8bae\u5458\u53ef\u4ee5\u4f7f\u7528\u4ed6\u7684\u7b2c\u4e00\u9879\u6743\u5229\u7981\u6b62\u7b2c\u4e00\u4e2a\u53c2\u8bae\u5458\u7684\u6743\u5229\n\u56e0\u6b64\u5728\u7b2c\u4e8c\u8f6e\u53ea\u5269\u4e0b\u7b2c\u4e09\u4e2a\u53c2\u8bae\u5458\u62e5\u6709\u6295\u7968\u7684\u6743\u5229,\u4e8e\u662f\u4ed6\u53ef\u4ee5\u5ba3\u5e03\u80dc\u5229\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u7ed9\u5b9a\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u5728 [1, 10,000] \u4e4b\u95f4.
    • \n
    \n\n

    \u00a0

    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string predictPartyVictory(string senate) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String predictPartyVictory(String senate) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def predictPartyVictory(self, senate):\n \"\"\"\n :type senate: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def predictPartyVictory(self, senate: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * predictPartyVictory(char * senate){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string PredictPartyVictory(string senate) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} senate\n * @return {string}\n */\nvar predictPartyVictory = function(senate) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} senate\n# @return {String}\ndef predict_party_victory(senate)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func predictPartyVictory(_ senate: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func predictPartyVictory(senate string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def predictPartyVictory(senate: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun predictPartyVictory(senate: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn predict_party_victory(senate: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $senate\n * @return String\n */\n function predictPartyVictory($senate) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function predictPartyVictory(senate: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (predict-party-victory senate)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0649](https://leetcode-cn.com/problems/dota2-senate)", "[Dota2 \u53c2\u8bae\u9662](/solution/0600-0699/0649.Dota2%20Senate/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0649](https://leetcode.com/problems/dota2-senate)", "[Dota2 Senate](/solution/0600-0699/0649.Dota2%20Senate/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "0648", "frontend_question_id": "0648", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/replace-words", "url_en": "https://leetcode.com/problems/replace-words", "relative_path_cn": "/solution/0600-0699/0648.Replace%20Words/README.md", "relative_path_en": "/solution/0600-0699/0648.Replace%20Words/README_EN.md", "title_cn": "\u5355\u8bcd\u66ff\u6362", "title_en": "Replace Words", "question_title_slug": "replace-words", "content_en": "

    In English, we have a concept called root, which can be followed by some other word to form another longer word - let's call this word successor. For example, when the root "an" is followed by the successor word "other", we can form a new word "another".

    \n\n

    Given a dictionary consisting of many roots and a sentence consisting of words separated by spaces, replace all the successors in the sentence with the root forming it. If a successor can be replaced by more than one root, replace it with the root that has the shortest length.

    \n\n

    Return the sentence after the replacement.

    \n\n

     

    \n

    Example 1:

    \n
    Input: dictionary = [\"cat\",\"bat\",\"rat\"], sentence = \"the cattle was rattled by the battery\"\nOutput: \"the cat was rat by the bat\"\n

    Example 2:

    \n
    Input: dictionary = [\"a\",\"b\",\"c\"], sentence = \"aadsfasf absbs bbab cadsfafs\"\nOutput: \"a a b c\"\n

    Example 3:

    \n
    Input: dictionary = [\"a\", \"aa\", \"aaa\", \"aaaa\"], sentence = \"a aa a aaaa aaa aaa aaa aaaaaa bbb baba ababa\"\nOutput: \"a a a a a a a a bbb baba a\"\n

    Example 4:

    \n
    Input: dictionary = [\"catt\",\"cat\",\"bat\",\"rat\"], sentence = \"the cattle was rattled by the battery\"\nOutput: \"the cat was rat by the bat\"\n

    Example 5:

    \n
    Input: dictionary = [\"ac\",\"ab\"], sentence = \"it is abnormal that this solution is accepted\"\nOutput: \"it is ab that this solution is ac\"\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= dictionary.length <= 1000
    • \n\t
    • 1 <= dictionary[i].length <= 100
    • \n\t
    • dictionary[i] consists of only lower-case letters.
    • \n\t
    • 1 <= sentence.length <= 10^6
    • \n\t
    • sentence consists of only lower-case letters and spaces.
    • \n\t
    • The number of words in sentence is in the range [1, 1000]
    • \n\t
    • The length of each word in sentence is in the range [1, 1000]
    • \n\t
    • Each two consecutive words in sentence will be separated by exactly one space.
    • \n\t
    • sentence does not have leading or trailing spaces.
    • \n
    \n", "content_cn": "

    \u5728\u82f1\u8bed\u4e2d\uff0c\u6211\u4eec\u6709\u4e00\u4e2a\u53eb\u505a \u8bcd\u6839(root)\u7684\u6982\u5ff5\uff0c\u5b83\u53ef\u4ee5\u8ddf\u7740\u5176\u4ed6\u4e00\u4e9b\u8bcd\u7ec4\u6210\u53e6\u4e00\u4e2a\u8f83\u957f\u7684\u5355\u8bcd——\u6211\u4eec\u79f0\u8fd9\u4e2a\u8bcd\u4e3a \u7ee7\u627f\u8bcd(successor)\u3002\u4f8b\u5982\uff0c\u8bcd\u6839an\uff0c\u8ddf\u968f\u7740\u5355\u8bcd other(\u5176\u4ed6)\uff0c\u53ef\u4ee5\u5f62\u6210\u65b0\u7684\u5355\u8bcd another(\u53e6\u4e00\u4e2a)\u3002

    \n\n

    \u73b0\u5728\uff0c\u7ed9\u5b9a\u4e00\u4e2a\u7531\u8bb8\u591a\u8bcd\u6839\u7ec4\u6210\u7684\u8bcd\u5178\u548c\u4e00\u4e2a\u53e5\u5b50\u3002\u4f60\u9700\u8981\u5c06\u53e5\u5b50\u4e2d\u7684\u6240\u6709\u7ee7\u627f\u8bcd\u7528\u8bcd\u6839\u66ff\u6362\u6389\u3002\u5982\u679c\u7ee7\u627f\u8bcd\u6709\u8bb8\u591a\u53ef\u4ee5\u5f62\u6210\u5b83\u7684\u8bcd\u6839\uff0c\u5219\u7528\u6700\u77ed\u7684\u8bcd\u6839\u66ff\u6362\u5b83\u3002

    \n\n

    \u4f60\u9700\u8981\u8f93\u51fa\u66ff\u6362\u4e4b\u540e\u7684\u53e5\u5b50\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1adictionary = ["cat","bat","rat"], sentence = "the cattle was rattled by the battery"\n\u8f93\u51fa\uff1a"the cat was rat by the bat"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1adictionary = ["a","b","c"], sentence = "aadsfasf absbs bbab cadsfafs"\n\u8f93\u51fa\uff1a"a a b c"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1adictionary = ["a", "aa", "aaa", "aaaa"], sentence = "a aa a aaaa aaa aaa aaa aaaaaa bbb baba ababa"\n\u8f93\u51fa\uff1a"a a a a a a a a bbb baba a"\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1adictionary = ["catt","cat","bat","rat"], sentence = "the cattle was rattled by the battery"\n\u8f93\u51fa\uff1a"the cat was rat by the bat"\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1adictionary = ["ac","ab"], sentence = "it is abnormal that this solution is accepted"\n\u8f93\u51fa\uff1a"it is ab that this solution is ac"\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= dictionary.length <= 1000
    • \n\t
    • 1 <= dictionary[i].length <= 100
    • \n\t
    • dictionary[i] \u4ec5\u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210\u3002
    • \n\t
    • 1 <= sentence.length <= 10^6
    • \n\t
    • sentence \u4ec5\u7531\u5c0f\u5199\u5b57\u6bcd\u548c\u7a7a\u683c\u7ec4\u6210\u3002
    • \n\t
    • sentence \u4e2d\u5355\u8bcd\u7684\u603b\u91cf\u5728\u8303\u56f4 [1, 1000] \u5185\u3002
    • \n\t
    • sentence \u4e2d\u6bcf\u4e2a\u5355\u8bcd\u7684\u957f\u5ea6\u5728\u8303\u56f4 [1, 1000] \u5185\u3002
    • \n\t
    • sentence \u4e2d\u5355\u8bcd\u4e4b\u95f4\u7531\u4e00\u4e2a\u7a7a\u683c\u9694\u5f00\u3002
    • \n\t
    • sentence \u6ca1\u6709\u524d\u5bfc\u6216\u5c3e\u968f\u7a7a\u683c\u3002
    • \n
    \n", "tags_en": ["Trie", "Hash Table"], "tags_cn": ["\u5b57\u5178\u6811", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string replaceWords(vector& dictionary, string sentence) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String replaceWords(List dictionary, String sentence) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def replaceWords(self, dictionary, sentence):\n \"\"\"\n :type dictionary: List[str]\n :type sentence: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def replaceWords(self, dictionary: List[str], sentence: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * replaceWords(char ** dictionary, int dictionarySize, char * sentence){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ReplaceWords(IList dictionary, string sentence) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} dictionary\n * @param {string} sentence\n * @return {string}\n */\nvar replaceWords = function(dictionary, sentence) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} dictionary\n# @param {String} sentence\n# @return {String}\ndef replace_words(dictionary, sentence)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func replaceWords(_ dictionary: [String], _ sentence: String) -> String {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func replaceWords(dictionary []string, sentence string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def replaceWords(dictionary: List[String], sentence: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun replaceWords(dictionary: List, sentence: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn replace_words(dictionary: Vec, sentence: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $dictionary\n * @param String $sentence\n * @return String\n */\n function replaceWords($dictionary, $sentence) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function replaceWords(dictionary: string[], sentence: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (replace-words dictionary sentence)\n (-> (listof string?) string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0648](https://leetcode-cn.com/problems/replace-words)", "[\u5355\u8bcd\u66ff\u6362](/solution/0600-0699/0648.Replace%20Words/README.md)", "`\u5b57\u5178\u6811`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0648](https://leetcode.com/problems/replace-words)", "[Replace Words](/solution/0600-0699/0648.Replace%20Words/README_EN.md)", "`Trie`,`Hash Table`", "Medium", ""]}, {"question_id": "0647", "frontend_question_id": "0647", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/palindromic-substrings", "url_en": "https://leetcode.com/problems/palindromic-substrings", "relative_path_cn": "/solution/0600-0699/0647.Palindromic%20Substrings/README.md", "relative_path_en": "/solution/0600-0699/0647.Palindromic%20Substrings/README_EN.md", "title_cn": "\u56de\u6587\u5b50\u4e32", "title_en": "Palindromic Substrings", "question_title_slug": "palindromic-substrings", "content_en": "

    Given a string s, return the number of palindromic substrings in it.

    \n\n

    A string is a palindrome when it reads the same backward as forward.

    \n\n

    A substring is a contiguous sequence of characters within the string.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "abc"\nOutput: 3\nExplanation: Three palindromic strings: "a", "b", "c".\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "aaa"\nOutput: 6\nExplanation: Six palindromic strings: "a", "a", "a", "aa", "aa", "aaa".\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 1000
    • \n\t
    • s consists of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u4f60\u7684\u4efb\u52a1\u662f\u8ba1\u7b97\u8fd9\u4e2a\u5b57\u7b26\u4e32\u4e2d\u6709\u591a\u5c11\u4e2a\u56de\u6587\u5b50\u4e32\u3002

    \n\n

    \u5177\u6709\u4e0d\u540c\u5f00\u59cb\u4f4d\u7f6e\u6216\u7ed3\u675f\u4f4d\u7f6e\u7684\u5b50\u4e32\uff0c\u5373\u4f7f\u662f\u7531\u76f8\u540c\u7684\u5b57\u7b26\u7ec4\u6210\uff0c\u4e5f\u4f1a\u88ab\u89c6\u4f5c\u4e0d\u540c\u7684\u5b50\u4e32\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a"abc"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u4e09\u4e2a\u56de\u6587\u5b50\u4e32: "a", "b", "c"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a"aaa"\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a6\u4e2a\u56de\u6587\u5b50\u4e32: "a", "a", "a", "aa", "aa", "aaa"
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u8f93\u5165\u7684\u5b57\u7b26\u4e32\u957f\u5ea6\u4e0d\u4f1a\u8d85\u8fc7 1000 \u3002
    • \n
    \n", "tags_en": ["String", "Dynamic Programming"], "tags_cn": ["\u5b57\u7b26\u4e32", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countSubstrings(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countSubstrings(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countSubstrings(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countSubstrings(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countSubstrings(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountSubstrings(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar countSubstrings = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef count_substrings(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countSubstrings(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countSubstrings(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countSubstrings(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countSubstrings(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_substrings(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function countSubstrings($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countSubstrings(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-substrings s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0647](https://leetcode-cn.com/problems/palindromic-substrings)", "[\u56de\u6587\u5b50\u4e32](/solution/0600-0699/0647.Palindromic%20Substrings/README.md)", "`\u5b57\u7b26\u4e32`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0647](https://leetcode.com/problems/palindromic-substrings)", "[Palindromic Substrings](/solution/0600-0699/0647.Palindromic%20Substrings/README_EN.md)", "`String`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0646", "frontend_question_id": "0646", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-length-of-pair-chain", "url_en": "https://leetcode.com/problems/maximum-length-of-pair-chain", "relative_path_cn": "/solution/0600-0699/0646.Maximum%20Length%20of%20Pair%20Chain/README.md", "relative_path_en": "/solution/0600-0699/0646.Maximum%20Length%20of%20Pair%20Chain/README_EN.md", "title_cn": "\u6700\u957f\u6570\u5bf9\u94fe", "title_en": "Maximum Length of Pair Chain", "question_title_slug": "maximum-length-of-pair-chain", "content_en": "

    You are given an array of n pairs pairs where pairs[i] = [lefti, righti] and lefti < righti.

    \n\n

    A pair p2 = [c, d] follows a pair p1 = [a, b] if b < c. A chain of pairs can be formed in this fashion.

    \n\n

    Return the length longest chain which can be formed.

    \n\n

    You do not need to use up all the given intervals. You can select pairs in any order.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: pairs = [[1,2],[2,3],[3,4]]\nOutput: 2\nExplanation: The longest chain is [1,2] -> [3,4].\n
    \n\n

    Example 2:

    \n\n
    \nInput: pairs = [[1,2],[7,8],[4,5]]\nOutput: 3\nExplanation: The longest chain is [1,2] -> [4,5] -> [7,8].\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == pairs.length
    • \n\t
    • 1 <= n <= 1000
    • \n\t
    • -1000 <= lefti < righti < 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u51fa\u00a0n\u00a0\u4e2a\u6570\u5bf9\u3002\u00a0\u5728\u6bcf\u4e00\u4e2a\u6570\u5bf9\u4e2d\uff0c\u7b2c\u4e00\u4e2a\u6570\u5b57\u603b\u662f\u6bd4\u7b2c\u4e8c\u4e2a\u6570\u5b57\u5c0f\u3002

    \n\n

    \u73b0\u5728\uff0c\u6211\u4eec\u5b9a\u4e49\u4e00\u79cd\u8ddf\u968f\u5173\u7cfb\uff0c\u5f53\u4e14\u4ec5\u5f53\u00a0b < c\u00a0\u65f6\uff0c\u6570\u5bf9(c, d)\u00a0\u624d\u53ef\u4ee5\u8ddf\u5728\u00a0(a, b)\u00a0\u540e\u9762\u3002\u6211\u4eec\u7528\u8fd9\u79cd\u5f62\u5f0f\u6765\u6784\u9020\u4e00\u4e2a\u6570\u5bf9\u94fe\u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u6570\u5bf9\u96c6\u5408\uff0c\u627e\u51fa\u80fd\u591f\u5f62\u6210\u7684\u6700\u957f\u6570\u5bf9\u94fe\u7684\u957f\u5ea6\u3002\u4f60\u4e0d\u9700\u8981\u7528\u5230\u6240\u6709\u7684\u6570\u5bf9\uff0c\u4f60\u53ef\u4ee5\u4ee5\u4efb\u4f55\u987a\u5e8f\u9009\u62e9\u5176\u4e2d\u7684\u4e00\u4e9b\u6570\u5bf9\u6765\u6784\u9020\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[[1,2], [2,3], [3,4]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6700\u957f\u7684\u6570\u5bf9\u94fe\u662f [1,2] -> [3,4]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u7ed9\u51fa\u6570\u5bf9\u7684\u4e2a\u6570\u5728\u00a0[1, 1000] \u8303\u56f4\u5185\u3002
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findLongestChain(vector>& pairs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findLongestChain(int[][] pairs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findLongestChain(self, pairs):\n \"\"\"\n :type pairs: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findLongestChain(self, pairs: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findLongestChain(int** pairs, int pairsSize, int* pairsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindLongestChain(int[][] pairs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} pairs\n * @return {number}\n */\nvar findLongestChain = function(pairs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} pairs\n# @return {Integer}\ndef find_longest_chain(pairs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findLongestChain(_ pairs: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findLongestChain(pairs [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findLongestChain(pairs: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findLongestChain(pairs: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_longest_chain(pairs: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $pairs\n * @return Integer\n */\n function findLongestChain($pairs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findLongestChain(pairs: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-longest-chain pairs)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0646](https://leetcode-cn.com/problems/maximum-length-of-pair-chain)", "[\u6700\u957f\u6570\u5bf9\u94fe](/solution/0600-0699/0646.Maximum%20Length%20of%20Pair%20Chain/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0646](https://leetcode.com/problems/maximum-length-of-pair-chain)", "[Maximum Length of Pair Chain](/solution/0600-0699/0646.Maximum%20Length%20of%20Pair%20Chain/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0645", "frontend_question_id": "0645", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/set-mismatch", "url_en": "https://leetcode.com/problems/set-mismatch", "relative_path_cn": "/solution/0600-0699/0645.Set%20Mismatch/README.md", "relative_path_en": "/solution/0600-0699/0645.Set%20Mismatch/README_EN.md", "title_cn": "\u9519\u8bef\u7684\u96c6\u5408", "title_en": "Set Mismatch", "question_title_slug": "set-mismatch", "content_en": "

    You have a set of integers s, which originally contains all the numbers from 1 to n. Unfortunately, due to some error, one of the numbers in s got duplicated to another number in the set, which results in repetition of one number and loss of another number.

    \n\n

    You are given an integer array nums representing the data status of this set after the error.

    \n\n

    Find the number that occurs twice and the number that is missing and return them in the form of an array.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [1,2,2,4]\nOutput: [2,3]\n

    Example 2:

    \n
    Input: nums = [1,1]\nOutput: [1,2]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= nums.length <= 104
    • \n\t
    • 1 <= nums[i] <= 104
    • \n
    \n", "content_cn": "

    \u96c6\u5408 s \u5305\u542b\u4ece 1 \u5230\u00a0n\u00a0\u7684\u6574\u6570\u3002\u4e0d\u5e78\u7684\u662f\uff0c\u56e0\u4e3a\u6570\u636e\u9519\u8bef\uff0c\u5bfc\u81f4\u96c6\u5408\u91cc\u9762\u67d0\u4e00\u4e2a\u6570\u5b57\u590d\u5236\u4e86\u6210\u4e86\u96c6\u5408\u91cc\u9762\u7684\u53e6\u5916\u4e00\u4e2a\u6570\u5b57\u7684\u503c\uff0c\u5bfc\u81f4\u96c6\u5408 \u4e22\u5931\u4e86\u4e00\u4e2a\u6570\u5b57 \u5e76\u4e14 \u6709\u4e00\u4e2a\u6570\u5b57\u91cd\u590d \u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u6570\u7ec4 nums \u4ee3\u8868\u4e86\u96c6\u5408 S \u53d1\u751f\u9519\u8bef\u540e\u7684\u7ed3\u679c\u3002

    \n\n

    \u8bf7\u4f60\u627e\u51fa\u91cd\u590d\u51fa\u73b0\u7684\u6574\u6570\uff0c\u518d\u627e\u5230\u4e22\u5931\u7684\u6574\u6570\uff0c\u5c06\u5b83\u4eec\u4ee5\u6570\u7ec4\u7684\u5f62\u5f0f\u8fd4\u56de\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,2,4]\n\u8f93\u51fa\uff1a[2,3]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,1]\n\u8f93\u51fa\uff1a[1,2]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= nums.length <= 104
    • \n\t
    • 1 <= nums[i] <= 104
    • \n
    \n", "tags_en": ["Hash Table", "Math"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findErrorNums(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] findErrorNums(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findErrorNums(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findErrorNums(self, nums: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* findErrorNums(int* nums, int numsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] FindErrorNums(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar findErrorNums = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer[]}\ndef find_error_nums(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findErrorNums(_ nums: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findErrorNums(nums []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findErrorNums(nums: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findErrorNums(nums: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_error_nums(nums: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer[]\n */\n function findErrorNums($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findErrorNums(nums: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-error-nums nums)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0645](https://leetcode-cn.com/problems/set-mismatch)", "[\u9519\u8bef\u7684\u96c6\u5408](/solution/0600-0699/0645.Set%20Mismatch/README.md)", "`\u54c8\u5e0c\u8868`,`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0645](https://leetcode.com/problems/set-mismatch)", "[Set Mismatch](/solution/0600-0699/0645.Set%20Mismatch/README_EN.md)", "`Hash Table`,`Math`", "Easy", ""]}, {"question_id": "0644", "frontend_question_id": "0644", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/maximum-average-subarray-ii", "url_en": "https://leetcode.com/problems/maximum-average-subarray-ii", "relative_path_cn": "/solution/0600-0699/0644.Maximum%20Average%20Subarray%20II/README.md", "relative_path_en": "/solution/0600-0699/0644.Maximum%20Average%20Subarray%20II/README_EN.md", "title_cn": "\u5b50\u6570\u7ec4\u6700\u5927\u5e73\u5747\u6570 II", "title_en": "Maximum Average Subarray II", "question_title_slug": "maximum-average-subarray-ii", "content_en": "

    You are given an integer array nums consisting of n elements, and an integer k.

    \n\n

    Find a contiguous subarray whose length is greater than or equal to k that has the maximum average value and return this value. Any answer with a calculation error less than 10-5 will be accepted.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,12,-5,-6,50,3], k = 4\nOutput: 12.75000\nExplanation:\n- When the length is 4, averages are [0.5, 12.75, 10.5] and the maximum average is 12.75\n- When the length is 5, averages are [10.4, 10.8] and the maximum average is 10.8\n- When the length is 6, averages are [9.16667] and the maximum average is 9.16667\nThe maximum average is when we choose a subarray of length 4 (i.e., the sub array [12, -5, -6, 50]) which has the max average 12.75, so we return 12.75\nNote that we do not consider the subarrays of length < 4.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [5], k = 1\nOutput: 5.00000\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= k <= n <= 104
    • \n\t
    • -104 <= nums[i] <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5305\u542b n \u4e2a\u6574\u6570\u7684\u6570\u7ec4 nums \uff0c\u548c\u4e00\u4e2a\u6574\u6570 k \u3002

    \n\n

    \u8bf7\u4f60\u627e\u51fa \u957f\u5ea6\u5927\u4e8e\u7b49\u4e8e k \u4e14\u542b\u6700\u5927\u5e73\u5747\u503c\u7684\u8fde\u7eed\u5b50\u6570\u7ec4\u3002\u5e76\u8f93\u51fa\u8fd9\u4e2a\u6700\u5927\u5e73\u5747\u503c\u3002\u4efb\u4f55\u8ba1\u7b97\u8bef\u5dee\u5c0f\u4e8e\u00a010-5 \u7684\u7ed3\u679c\u90fd\u5c06\u88ab\u89c6\u4e3a\u6b63\u786e\u7b54\u6848\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,12,-5,-6,50,3], k = 4\n\u8f93\u51fa\uff1a12.75000\n\u89e3\u91ca\uff1a\n- \u5f53\u957f\u5ea6\u4e3a 4 \u7684\u65f6\u5019\uff0c\u8fde\u7eed\u5b50\u6570\u7ec4\u5e73\u5747\u503c\u5206\u522b\u4e3a [0.5, 12.75, 10.5] \uff0c\u5176\u4e2d\u6700\u5927\u5e73\u5747\u503c\u662f 12.75 \u3002\n- \u5f53\u957f\u5ea6\u4e3a 5 \u7684\u65f6\u5019\uff0c\u8fde\u7eed\u5b50\u6570\u7ec4\u5e73\u5747\u503c\u5206\u522b\u4e3a [10.4, 10.8] \uff0c\u5176\u4e2d\u6700\u5927\u5e73\u5747\u503c\u662f 10.8 \u3002\n- \u5f53\u957f\u5ea6\u4e3a 6 \u7684\u65f6\u5019\uff0c\u8fde\u7eed\u5b50\u6570\u7ec4\u5e73\u5747\u503c\u5206\u522b\u4e3a [9.16667] \uff0c\u5176\u4e2d\u6700\u5927\u5e73\u5747\u503c\u662f 9.16667 \u3002\n\u5f53\u53d6\u957f\u5ea6\u4e3a 4 \u7684\u5b50\u6570\u7ec4\uff08\u5373\uff0c\u5b50\u6570\u7ec4 [12, -5, -6, 50]\uff09\u7684\u65f6\u5019\uff0c\u53ef\u4ee5\u5f97\u5230\u6700\u5927\u7684\u8fde\u7eed\u5b50\u6570\u7ec4\u5e73\u5747\u503c 12.75 \uff0c\u6240\u4ee5\u8fd4\u56de 12.75 \u3002\n\u6839\u636e\u9898\u76ee\u8981\u6c42\uff0c\u65e0\u9700\u8003\u8651\u957f\u5ea6\u5c0f\u4e8e 4 \u7684\u5b50\u6570\u7ec4\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [5], k = 1\n\u8f93\u51fa\uff1a5.00000\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= k <= n <= 104
    • \n\t
    • -104 <= nums[i] <= 104
    • \n
    \n", "tags_en": ["Array", "Binary Search"], "tags_cn": ["\u6570\u7ec4", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n double findMaxAverage(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double findMaxAverage(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findMaxAverage(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: float\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findMaxAverage(self, nums: List[int], k: int) -> float:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\ndouble findMaxAverage(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double FindMaxAverage(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar findMaxAverage = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Float}\ndef find_max_average(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findMaxAverage(_ nums: [Int], _ k: Int) -> Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findMaxAverage(nums []int, k int) float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findMaxAverage(nums: Array[Int], k: Int): Double = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findMaxAverage(nums: IntArray, k: Int): Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_max_average(nums: Vec, k: i32) -> f64 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Float\n */\n function findMaxAverage($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findMaxAverage(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-max-average nums k)\n (-> (listof exact-integer?) exact-integer? flonum?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0644](https://leetcode-cn.com/problems/maximum-average-subarray-ii)", "[\u5b50\u6570\u7ec4\u6700\u5927\u5e73\u5747\u6570 II](/solution/0600-0699/0644.Maximum%20Average%20Subarray%20II/README.md)", "`\u6570\u7ec4`,`\u4e8c\u5206\u67e5\u627e`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0644](https://leetcode.com/problems/maximum-average-subarray-ii)", "[Maximum Average Subarray II](/solution/0600-0699/0644.Maximum%20Average%20Subarray%20II/README_EN.md)", "`Array`,`Binary Search`", "Hard", "\ud83d\udd12"]}, {"question_id": "0643", "frontend_question_id": "0643", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-average-subarray-i", "url_en": "https://leetcode.com/problems/maximum-average-subarray-i", "relative_path_cn": "/solution/0600-0699/0643.Maximum%20Average%20Subarray%20I/README.md", "relative_path_en": "/solution/0600-0699/0643.Maximum%20Average%20Subarray%20I/README_EN.md", "title_cn": "\u5b50\u6570\u7ec4\u6700\u5927\u5e73\u5747\u6570 I", "title_en": "Maximum Average Subarray I", "question_title_slug": "maximum-average-subarray-i", "content_en": "

    You are given an integer array nums consisting of n elements, and an integer k.

    \n\n

    Find a contiguous subarray whose length is equal to k that has the maximum average value and return this value. Any answer with a calculation error less than 10-5 will be accepted.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,12,-5,-6,50,3], k = 4\nOutput: 12.75000\nExplanation: Maximum average is (12 - 5 - 6 + 50) / 4 = 51 / 4 = 12.75\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [5], k = 1\nOutput: 5.00000\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= k <= n <= 105
    • \n\t
    • -104 <= nums[i] <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a n \u4e2a\u6574\u6570\uff0c\u627e\u51fa\u5e73\u5747\u6570\u6700\u5927\u4e14\u957f\u5ea6\u4e3a k \u7684\u8fde\u7eed\u5b50\u6570\u7ec4\uff0c\u5e76\u8f93\u51fa\u8be5\u6700\u5927\u5e73\u5747\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[1,12,-5,-6,50,3], k = 4\n\u8f93\u51fa\uff1a12.75\n\u89e3\u91ca\uff1a\u6700\u5927\u5e73\u5747\u6570 (12-5-6+50)/4 = 51/4 = 12.75\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= k <= n <= 30,000\u3002
    • \n\t
    • \u6240\u7ed9\u6570\u636e\u8303\u56f4 [-10,000\uff0c10,000]\u3002
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n double findMaxAverage(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double findMaxAverage(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findMaxAverage(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: float\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findMaxAverage(self, nums: List[int], k: int) -> float:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\ndouble findMaxAverage(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double FindMaxAverage(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar findMaxAverage = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Float}\ndef find_max_average(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findMaxAverage(_ nums: [Int], _ k: Int) -> Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findMaxAverage(nums []int, k int) float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findMaxAverage(nums: Array[Int], k: Int): Double = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findMaxAverage(nums: IntArray, k: Int): Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_max_average(nums: Vec, k: i32) -> f64 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Float\n */\n function findMaxAverage($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findMaxAverage(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-max-average nums k)\n (-> (listof exact-integer?) exact-integer? flonum?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0643](https://leetcode-cn.com/problems/maximum-average-subarray-i)", "[\u5b50\u6570\u7ec4\u6700\u5927\u5e73\u5747\u6570 I](/solution/0600-0699/0643.Maximum%20Average%20Subarray%20I/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0643](https://leetcode.com/problems/maximum-average-subarray-i)", "[Maximum Average Subarray I](/solution/0600-0699/0643.Maximum%20Average%20Subarray%20I/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0642", "frontend_question_id": "0642", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/design-search-autocomplete-system", "url_en": "https://leetcode.com/problems/design-search-autocomplete-system", "relative_path_cn": "/solution/0600-0699/0642.Design%20Search%20Autocomplete%20System/README.md", "relative_path_en": "/solution/0600-0699/0642.Design%20Search%20Autocomplete%20System/README_EN.md", "title_cn": "\u8bbe\u8ba1\u641c\u7d22\u81ea\u52a8\u8865\u5168\u7cfb\u7edf", "title_en": "Design Search Autocomplete System", "question_title_slug": "design-search-autocomplete-system", "content_en": "

    Design a search autocomplete system for a search engine. Users may input a sentence (at least one word and end with a special character '#').

    \n\n

    You are given a string array sentences and an integer array times both of length n where sentences[i] is a previously typed sentence and times[i] is the corresponding number of times the sentence was typed. For each input character except '#', return the top 3 historical hot sentences that have the same prefix as the part of the sentence already typed.

    \n\n

    Here are the specific rules:

    \n\n
      \n\t
    • The hot degree for a sentence is defined as the number of times a user typed the exactly same sentence before.
    • \n\t
    • The returned top 3 hot sentences should be sorted by hot degree (The first is the hottest one). If several sentences have the same hot degree, use ASCII-code order (smaller one appears first).
    • \n\t
    • If less than 3 hot sentences exist, return as many as you can.
    • \n\t
    • When the input is a special character, it means the sentence ends, and in this case, you need to return an empty list.
    • \n
    \n\n

    Implement the AutocompleteSystem class:

    \n\n
      \n\t
    • AutocompleteSystem(String[] sentences, int[] times) Initializes the object with the sentences and times arrays.
    • \n\t
    • List<String> input(char c) This indicates that the user typed the character c.\n\t
        \n\t\t
      • Returns an empty array [] if c == '#' and stores the inputted sentence in the system.
      • \n\t\t
      • Returns the top 3 historical hot sentences that have the same prefix as the part of the sentence already typed. If there are fewer than 3 matches, return them all.
      • \n\t
      \n\t
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["AutocompleteSystem", "input", "input", "input", "input"]\n[[["i love you", "island", "iroman", "i love leetcode"], [5, 3, 2, 2]], ["i"], [" "], ["a"], ["#"]]\nOutput\n[null, ["i love you", "island", "i love leetcode"], ["i love you", "i love leetcode"], [], []]\n\nExplanation\nAutocompleteSystem obj = new AutocompleteSystem(["i love you", "island", "iroman", "i love leetcode"], [5, 3, 2, 2]);\nobj.input("i"); // return ["i love you", "island", "i love leetcode"]. There are four sentences that have prefix "i". Among them, "ironman" and "i love leetcode" have same hot degree. Since ' ' has ASCII code 32 and 'r' has ASCII code 114, "i love leetcode" should be in front of "ironman". Also we only need to output top 3 hot sentences, so "ironman" will be ignored.\nobj.input(" "); // return ["i love you", "i love leetcode"]. There are only two sentences that have prefix "i ".\nobj.input("a"); // return []. There are no sentences that have prefix "i a".\nobj.input("#"); // return []. The user finished the input, the sentence "i a" should be saved as a historical sentence in system. And the following input will be counted as a new search.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == sentences.length
    • \n\t
    • n == times.length
    • \n\t
    • 1 <= n <= 100
    • \n\t
    • 1 <= sentences[i].length <= 100
    • \n\t
    • 1 <= times[i] <= 50
    • \n\t
    • c is a lowercase English letter, a hash '#', or space ' '.
    • \n\t
    • Each tested sentence will be a sequence of characters c that end with the character '#'.
    • \n\t
    • Each tested sentence will have a length in the range [1, 200].
    • \n\t
    • The words in each input sentence are separated by single spaces.
    • \n\t
    • At most 5000 calls will be made to input.
    • \n
    \n", "content_cn": "

    \u4e3a\u641c\u7d22\u5f15\u64ce\u8bbe\u8ba1\u4e00\u4e2a\u641c\u7d22\u81ea\u52a8\u8865\u5168\u7cfb\u7edf\u3002\u7528\u6237\u4f1a\u8f93\u5165\u4e00\u6761\u8bed\u53e5\uff08\u6700\u5c11\u5305\u542b\u4e00\u4e2a\u5b57\u6bcd\uff0c\u4ee5\u7279\u6b8a\u5b57\u7b26 '#' \u7ed3\u5c3e\uff09\u3002\u9664 '#' \u4ee5\u5916\u7528\u6237\u8f93\u5165\u7684\u6bcf\u4e2a\u5b57\u7b26\uff0c\u8fd4\u56de\u5386\u53f2\u4e2d\u70ed\u5ea6\u524d\u4e09\u5e76\u4ee5\u5f53\u524d\u8f93\u5165\u90e8\u5206\u4e3a\u524d\u7f00\u7684\u53e5\u5b50\u3002\u4e0b\u9762\u662f\u8be6\u7ec6\u89c4\u5219\uff1a

    \n\n
      \n\t
    1. \u4e00\u6761\u53e5\u5b50\u7684\u70ed\u5ea6\u5b9a\u4e49\u4e3a\u5386\u53f2\u4e0a\u7528\u6237\u8f93\u5165\u8fd9\u4e2a\u53e5\u5b50\u7684\u603b\u6b21\u6570\u3002
    2. \n\t
    3. \u8fd4\u56de\u524d\u4e09\u7684\u53e5\u5b50\u9700\u8981\u6309\u7167\u70ed\u5ea6\u4ece\u9ad8\u5230\u4f4e\u6392\u5e8f\uff08\u7b2c\u4e00\u4e2a\u662f\u6700\u70ed\u95e8\u7684\uff09\u3002\u5982\u679c\u6709\u591a\u6761\u70ed\u5ea6\u76f8\u540c\u7684\u53e5\u5b50\uff0c\u8bf7\u6309\u7167 ASCII \u7801\u7684\u987a\u5e8f\u8f93\u51fa\uff08ASCII \u7801\u8d8a\u5c0f\u6392\u540d\u8d8a\u524d\uff09\u3002
    4. \n\t
    5. \u5982\u679c\u6ee1\u8db3\u6761\u4ef6\u7684\u53e5\u5b50\u4e2a\u6570\u5c11\u4e8e 3\uff0c\u5c06\u5b83\u4eec\u5168\u90e8\u8f93\u51fa\u3002
    6. \n\t
    7. \u5982\u679c\u8f93\u5165\u4e86\u7279\u6b8a\u5b57\u7b26\uff0c\u610f\u5473\u7740\u53e5\u5b50\u7ed3\u675f\u4e86\uff0c\u8bf7\u8fd4\u56de\u4e00\u4e2a\u7a7a\u96c6\u5408\u3002
    8. \n
    \n\n

    \u4f60\u7684\u5de5\u4f5c\u662f\u5b9e\u73b0\u4ee5\u4e0b\u529f\u80fd\uff1a

    \n\n

    \u6784\u9020\u51fd\u6570\uff1a

    \n\n

    AutocompleteSystem(String[] sentences, int[] times): \u8fd9\u662f\u6784\u9020\u51fd\u6570\uff0c\u8f93\u5165\u7684\u662f\u5386\u53f2\u6570\u636e\u3002 Sentences \u662f\u4e4b\u524d\u8f93\u5165\u8fc7\u7684\u6240\u6709\u53e5\u5b50\uff0cTimes \u662f\u6bcf\u6761\u53e5\u5b50\u8f93\u5165\u7684\u6b21\u6570\uff0c\u4f60\u7684\u7cfb\u7edf\u9700\u8981\u8bb0\u5f55\u8fd9\u4e9b\u5386\u53f2\u4fe1\u606f\u3002

    \n\n

    \u73b0\u5728\uff0c\u7528\u6237\u8f93\u5165\u4e00\u6761\u65b0\u7684\u53e5\u5b50\uff0c\u4e0b\u9762\u7684\u51fd\u6570\u4f1a\u63d0\u4f9b\u7528\u6237\u8f93\u5165\u7684\u4e0b\u4e00\u4e2a\u5b57\u7b26\uff1a

    \n\n

    List<String> input(char c): \u5176\u4e2d c \u662f\u7528\u6237\u8f93\u5165\u7684\u4e0b\u4e00\u4e2a\u5b57\u7b26\u3002\u5b57\u7b26\u53ea\u4f1a\u662f\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\uff08'a' \u5230 'z' \uff09\uff0c\u7a7a\u683c\uff08' '\uff09\u548c\u7279\u6b8a\u5b57\u7b26\uff08'#'\uff09\u3002\u8f93\u51fa\u5386\u53f2\u70ed\u5ea6\u524d\u4e09\u7684\u5177\u6709\u76f8\u540c\u524d\u7f00\u7684\u53e5\u5b50\u3002

    \n\n

     

    \n\n

    \u6837\u4f8b \uff1a
    \n\u64cd\u4f5c \uff1a AutocompleteSystem(["i love you", "island","ironman", "i love leetcode"], [5,3,2,2])
    \n\u7cfb\u7edf\u8bb0\u5f55\u4e0b\u6240\u6709\u7684\u53e5\u5b50\u548c\u51fa\u73b0\u7684\u6b21\u6570\uff1a
    \n"i love you" : 5 \u6b21
    \n"island" : 3 \u6b21
    \n"ironman" : 2 \u6b21
    \n"i love leetcode" : 2 \u6b21
    \n\u73b0\u5728\uff0c\u7528\u6237\u5f00\u59cb\u65b0\u7684\u952e\u5165\uff1a

    \n\n


    \n\u8f93\u5165 \uff1a input('i')
    \n\u8f93\u51fa \uff1a ["i love you", "island","i love leetcode"]
    \n\u89e3\u91ca \uff1a
    \n\u6709\u56db\u4e2a\u53e5\u5b50\u542b\u6709\u524d\u7f00 "i"\u3002\u5176\u4e2d "ironman" \u548c "i love leetcode" \u6709\u76f8\u540c\u7684\u70ed\u5ea6\uff0c\u7531\u4e8e ' ' \u7684 ASCII \u7801\u662f 32 \u800c 'r' \u7684 ASCII \u7801\u662f 114\uff0c\u6240\u4ee5 "i love leetcode" \u5728 "ironman" \u524d\u9762\u3002\u540c\u65f6\u6211\u4eec\u53ea\u8f93\u51fa\u524d\u4e09\u7684\u53e5\u5b50\uff0c\u6240\u4ee5 "ironman" \u88ab\u820d\u5f03\u3002
    \n
    \n\u8f93\u5165 \uff1a input(' ')
    \n\u8f93\u51fa \uff1a ["i love you","i love leetcode"]
    \n\u89e3\u91ca:
    \n\u53ea\u6709\u4e24\u4e2a\u53e5\u5b50\u542b\u6709\u524d\u7f00 "i "\u3002
    \n
    \n\u8f93\u5165 \uff1a input('a')
    \n\u8f93\u51fa \uff1a []
    \n\u89e3\u91ca \uff1a
    \n\u6ca1\u6709\u53e5\u5b50\u6709\u524d\u7f00 "i a"\u3002
    \n
    \n\u8f93\u5165 \uff1a input('#')
    \n\u8f93\u51fa \uff1a []
    \n\u89e3\u91ca \uff1a

    \n\n

    \u7528\u6237\u8f93\u5165\u7ed3\u675f\uff0c"i a" \u88ab\u5b58\u5230\u7cfb\u7edf\u4e2d\uff0c\u540e\u9762\u7684\u8f93\u5165\u88ab\u8ba4\u4e3a\u662f\u4e0b\u4e00\u6b21\u641c\u7d22\u3002

    \n\n

     

    \n\n

    \u6ce8\u91ca \uff1a

    \n\n
      \n\t
    1. \u8f93\u5165\u7684\u53e5\u5b50\u4ee5\u5b57\u6bcd\u5f00\u5934\uff0c\u4ee5 '#' \u7ed3\u5c3e\uff0c\u4e24\u4e2a\u5b57\u6bcd\u4e4b\u95f4\u6700\u591a\u53ea\u4f1a\u51fa\u73b0\u4e00\u4e2a\u7a7a\u683c\u3002
    2. \n\t
    3. \u5373\u5c06\u641c\u7d22\u7684\u53e5\u5b50\u603b\u6570\u4e0d\u4f1a\u8d85\u8fc7 100\u3002\u6bcf\u6761\u53e5\u5b50\u7684\u957f\u5ea6\uff08\u5305\u62ec\u5df2\u7ecf\u641c\u7d22\u7684\u548c\u5373\u5c06\u641c\u7d22\u7684\uff09\u4e5f\u4e0d\u4f1a\u8d85\u8fc7 100\u3002
    4. \n\t
    5. \u5373\u4f7f\u53ea\u6709\u4e00\u4e2a\u5b57\u6bcd\uff0c\u8f93\u51fa\u7684\u65f6\u5019\u8bf7\u4f7f\u7528\u53cc\u5f15\u53f7\u800c\u4e0d\u662f\u5355\u5f15\u53f7\u3002
    6. \n\t
    7. \u8bf7\u8bb0\u4f4f\u6e05\u96f6 AutocompleteSystem \u7c7b\u4e2d\u7684\u53d8\u91cf\uff0c\u56e0\u4e3a\u9759\u6001\u53d8\u91cf\u3001\u7c7b\u53d8\u91cf\u4f1a\u5728\u591a\u7ec4\u6d4b\u8bd5\u6570\u636e\u4e2d\u4fdd\u5b58\u4e4b\u524d\u7ed3\u679c\u3002\u8be6\u60c5\u8bf7\u770b\u8fd9\u91cc\u3002
    8. \n
    \n\n

     

    \n", "tags_en": ["Design", "Trie"], "tags_cn": ["\u8bbe\u8ba1", "\u5b57\u5178\u6811"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class AutocompleteSystem {\npublic:\n AutocompleteSystem(vector& sentences, vector& times) {\n\n }\n \n vector input(char c) {\n\n }\n};\n\n/**\n * Your AutocompleteSystem object will be instantiated and called as such:\n * AutocompleteSystem* obj = new AutocompleteSystem(sentences, times);\n * vector param_1 = obj->input(c);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class AutocompleteSystem {\n\n public AutocompleteSystem(String[] sentences, int[] times) {\n\n }\n \n public List input(char c) {\n\n }\n}\n\n/**\n * Your AutocompleteSystem object will be instantiated and called as such:\n * AutocompleteSystem obj = new AutocompleteSystem(sentences, times);\n * List param_1 = obj.input(c);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class AutocompleteSystem(object):\n\n def __init__(self, sentences, times):\n \"\"\"\n :type sentences: List[str]\n :type times: List[int]\n \"\"\"\n\n\n def input(self, c):\n \"\"\"\n :type c: str\n :rtype: List[str]\n \"\"\"\n\n\n\n# Your AutocompleteSystem object will be instantiated and called as such:\n# obj = AutocompleteSystem(sentences, times)\n# param_1 = obj.input(c)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class AutocompleteSystem:\n\n def __init__(self, sentences: List[str], times: List[int]):\n\n\n def input(self, c: str) -> List[str]:\n\n\n\n# Your AutocompleteSystem object will be instantiated and called as such:\n# obj = AutocompleteSystem(sentences, times)\n# param_1 = obj.input(c)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} AutocompleteSystem;\n\n\nAutocompleteSystem* autocompleteSystemCreate(char ** sentences, int sentencesSize, int* times, int timesSize) {\n \n}\n\nchar ** autocompleteSystemInput(AutocompleteSystem* obj, char c, int* retSize) {\n \n}\n\nvoid autocompleteSystemFree(AutocompleteSystem* obj) {\n \n}\n\n/**\n * Your AutocompleteSystem struct will be instantiated and called as such:\n * AutocompleteSystem* obj = autocompleteSystemCreate(sentences, sentencesSize, times, timesSize);\n * char ** param_1 = autocompleteSystemInput(obj, c, retSize);\n \n * autocompleteSystemFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class AutocompleteSystem {\n\n public AutocompleteSystem(string[] sentences, int[] times) {\n\n }\n \n public IList Input(char c) {\n\n }\n}\n\n/**\n * Your AutocompleteSystem object will be instantiated and called as such:\n * AutocompleteSystem obj = new AutocompleteSystem(sentences, times);\n * IList param_1 = obj.Input(c);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} sentences\n * @param {number[]} times\n */\nvar AutocompleteSystem = function(sentences, times) {\n\n};\n\n/** \n * @param {character} c\n * @return {string[]}\n */\nAutocompleteSystem.prototype.input = function(c) {\n\n};\n\n/**\n * Your AutocompleteSystem object will be instantiated and called as such:\n * var obj = new AutocompleteSystem(sentences, times)\n * var param_1 = obj.input(c)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class AutocompleteSystem\n\n=begin\n :type sentences: String[]\n :type times: Integer[]\n=end\n def initialize(sentences, times)\n\n end\n\n\n=begin\n :type c: Character\n :rtype: String[]\n=end\n def input(c)\n\n end\n\n\nend\n\n# Your AutocompleteSystem object will be instantiated and called as such:\n# obj = AutocompleteSystem.new(sentences, times)\n# param_1 = obj.input(c)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass AutocompleteSystem {\n\n init(_ sentences: [String], _ times: [Int]) {\n\n }\n \n func input(_ c: Character) -> [String] {\n\n }\n}\n\n/**\n * Your AutocompleteSystem object will be instantiated and called as such:\n * let obj = AutocompleteSystem(sentences, times)\n * let ret_1: [String] = obj.input(c)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type AutocompleteSystem struct {\n\n}\n\n\nfunc Constructor(sentences []string, times []int) AutocompleteSystem {\n\n}\n\n\nfunc (this *AutocompleteSystem) Input(c byte) []string {\n\n}\n\n\n/**\n * Your AutocompleteSystem object will be instantiated and called as such:\n * obj := Constructor(sentences, times);\n * param_1 := obj.Input(c);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class AutocompleteSystem(_sentences: Array[String], _times: Array[Int]) {\n\n def input(c: Char): List[String] = {\n\n }\n\n}\n\n/**\n * Your AutocompleteSystem object will be instantiated and called as such:\n * var obj = new AutocompleteSystem(sentences, times)\n * var param_1 = obj.input(c)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class AutocompleteSystem(sentences: Array, times: IntArray) {\n\n fun input(c: Char): List {\n\n }\n\n}\n\n/**\n * Your AutocompleteSystem object will be instantiated and called as such:\n * var obj = AutocompleteSystem(sentences, times)\n * var param_1 = obj.input(c)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct AutocompleteSystem {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl AutocompleteSystem {\n\n fn new(sentences: Vec, times: Vec) -> Self {\n\n }\n \n fn input(&self, c: char) -> Vec {\n\n }\n}\n\n/**\n * Your AutocompleteSystem object will be instantiated and called as such:\n * let obj = AutocompleteSystem::new(sentences, times);\n * let ret_1: Vec = obj.input(c);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class AutocompleteSystem {\n /**\n * @param String[] $sentences\n * @param Integer[] $times\n */\n function __construct($sentences, $times) {\n\n }\n\n /**\n * @param String $c\n * @return String[]\n */\n function input($c) {\n\n }\n}\n\n/**\n * Your AutocompleteSystem object will be instantiated and called as such:\n * $obj = AutocompleteSystem($sentences, $times);\n * $ret_1 = $obj->input($c);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class AutocompleteSystem {\n constructor(sentences: string[], times: number[]) {\n\n }\n\n input(c: string): string[] {\n\n }\n}\n\n/**\n * Your AutocompleteSystem object will be instantiated and called as such:\n * var obj = new AutocompleteSystem(sentences, times)\n * var param_1 = obj.input(c)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define autocomplete-system%\n (class object%\n (super-new)\n\n ; sentences : (listof string?)\n\n ; times : (listof exact-integer?)\n (init-field\n sentences\n times)\n \n ; input : char? -> (listof string?)\n (define/public (input c)\n\n )))\n\n;; Your autocomplete-system% object will be instantiated and called as such:\n;; (define obj (new autocomplete-system% [sentences sentences] [times times]))\n;; (define param_1 (send obj input c))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0642](https://leetcode-cn.com/problems/design-search-autocomplete-system)", "[\u8bbe\u8ba1\u641c\u7d22\u81ea\u52a8\u8865\u5168\u7cfb\u7edf](/solution/0600-0699/0642.Design%20Search%20Autocomplete%20System/README.md)", "`\u8bbe\u8ba1`,`\u5b57\u5178\u6811`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0642](https://leetcode.com/problems/design-search-autocomplete-system)", "[Design Search Autocomplete System](/solution/0600-0699/0642.Design%20Search%20Autocomplete%20System/README_EN.md)", "`Design`,`Trie`", "Hard", "\ud83d\udd12"]}, {"question_id": "0640", "frontend_question_id": "0640", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/solve-the-equation", "url_en": "https://leetcode.com/problems/solve-the-equation", "relative_path_cn": "/solution/0600-0699/0640.Solve%20the%20Equation/README.md", "relative_path_en": "/solution/0600-0699/0640.Solve%20the%20Equation/README_EN.md", "title_cn": "\u6c42\u89e3\u65b9\u7a0b", "title_en": "Solve the Equation", "question_title_slug": "solve-the-equation", "content_en": "

    Solve a given equation and return the value of 'x' in the form of a string "x=#value". The equation contains only '+', '-' operation, the variable 'x' and its coefficient. You should return "No solution" if there is no solution for the equation, or "Infinite solutions" if there are infinite solutions for the equation.

    \n\n

    If there is exactly one solution for the equation, we ensure that the value of 'x' is an integer.

    \n\n

     

    \n

    Example 1:

    \n
    Input: equation = \"x+5-3+x=6+x-2\"\nOutput: \"x=2\"\n

    Example 2:

    \n
    Input: equation = \"x=x\"\nOutput: \"Infinite solutions\"\n

    Example 3:

    \n
    Input: equation = \"2x=x\"\nOutput: \"x=0\"\n

    Example 4:

    \n
    Input: equation = \"2x+3x-6x=x+2\"\nOutput: \"x=-1\"\n

    Example 5:

    \n
    Input: equation = \"x=x+2\"\nOutput: \"No solution\"\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 3 <= equation.length <= 1000
    • \n\t
    • equation has exactly one '='.
    • \n\t
    • equation consists of integers with an absolute value in the range [0, 100] without any leading zeros, and the variable 'x'.
    • \n
    \n", "content_cn": "

    \u6c42\u89e3\u4e00\u4e2a\u7ed9\u5b9a\u7684\u65b9\u7a0b\uff0c\u5c06x\u4ee5\u5b57\u7b26\u4e32"x=#value"\u7684\u5f62\u5f0f\u8fd4\u56de\u3002\u8be5\u65b9\u7a0b\u4ec5\u5305\u542b'+'\uff0c' - '\u64cd\u4f5c\uff0c\u53d8\u91cf x \u548c\u5176\u5bf9\u5e94\u7cfb\u6570\u3002

    \n\n

    \u5982\u679c\u65b9\u7a0b\u6ca1\u6709\u89e3\uff0c\u8bf7\u8fd4\u56de“No solution”\u3002

    \n\n

    \u5982\u679c\u65b9\u7a0b\u6709\u65e0\u9650\u89e3\uff0c\u5219\u8fd4\u56de“Infinite solutions”\u3002

    \n\n

    \u5982\u679c\u65b9\u7a0b\u4e2d\u53ea\u6709\u4e00\u4e2a\u89e3\uff0c\u8981\u4fdd\u8bc1\u8fd4\u56de\u503c x \u662f\u4e00\u4e2a\u6574\u6570\u3002

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165: "x+5-3+x=6+x-2"\n\u8f93\u51fa: "x=2"\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: "x=x"\n\u8f93\u51fa: "Infinite solutions"\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u8f93\u5165: "2x=x"\n\u8f93\u51fa: "x=0"\n
    \n\n

    \u793a\u4f8b 4:

    \n\n
    \u8f93\u5165: "2x+3x-6x=x+2"\n\u8f93\u51fa: "x=-1"\n
    \n\n

    \u793a\u4f8b 5:

    \n\n
    \u8f93\u5165: "x=x+2"\n\u8f93\u51fa: "No solution"\n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string solveEquation(string equation) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String solveEquation(String equation) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def solveEquation(self, equation):\n \"\"\"\n :type equation: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def solveEquation(self, equation: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * solveEquation(char * equation){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string SolveEquation(string equation) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} equation\n * @return {string}\n */\nvar solveEquation = function(equation) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} equation\n# @return {String}\ndef solve_equation(equation)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func solveEquation(_ equation: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func solveEquation(equation string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def solveEquation(equation: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun solveEquation(equation: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn solve_equation(equation: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $equation\n * @return String\n */\n function solveEquation($equation) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function solveEquation(equation: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (solve-equation equation)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0640](https://leetcode-cn.com/problems/solve-the-equation)", "[\u6c42\u89e3\u65b9\u7a0b](/solution/0600-0699/0640.Solve%20the%20Equation/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0640](https://leetcode.com/problems/solve-the-equation)", "[Solve the Equation](/solution/0600-0699/0640.Solve%20the%20Equation/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "0639", "frontend_question_id": "0639", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/decode-ways-ii", "url_en": "https://leetcode.com/problems/decode-ways-ii", "relative_path_cn": "/solution/0600-0699/0639.Decode%20Ways%20II/README.md", "relative_path_en": "/solution/0600-0699/0639.Decode%20Ways%20II/README_EN.md", "title_cn": "\u89e3\u7801\u65b9\u6cd5 II", "title_en": "Decode Ways II", "question_title_slug": "decode-ways-ii", "content_en": "

    A message containing letters from A-Z can be encoded into numbers using the following mapping:

    \n\n
    \n'A' -> "1"\n'B' -> "2"\n...\n'Z' -> "26"\n
    \n\n

    To decode an encoded message, all the digits must be grouped then mapped back into letters using the reverse of the mapping above (there may be multiple ways). For example, "11106" can be mapped into:

    \n\n
      \n\t
    • "AAJF" with the grouping (1 1 10 6)
    • \n\t
    • "KJF" with the grouping (11 10 6)
    • \n
    \n\n

    Note that the grouping (1 11 06) is invalid because "06" cannot be mapped into 'F' since "6" is different from "06".

    \n\n

    In addition to the mapping above, an encoded message may contain the '*' character, which can represent any digit from '1' to '9' ('0' is excluded). For example, the encoded message "1*" may represent any of the encoded messages "11", "12", "13", "14", "15", "16", "17", "18", or "19". Decoding "1*" is equivalent to decoding any of the encoded messages it can represent.

    \n\n

    Given a string s containing digits and the '*' character, return the number of ways to decode it.

    \n\n

    Since the answer may be very large, return it modulo 109 + 7.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "*"\nOutput: 9\nExplanation: The encoded message can represent any of the encoded messages "1", "2", "3", "4", "5", "6", "7", "8", or "9".\nEach of these can be decoded to the strings "A", "B", "C", "D", "E", "F", "G", "H", and "I" respectively.\nHence, there are a total of 9 ways to decode "*".\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "1*"\nOutput: 18\nExplanation: The encoded message can represent any of the encoded messages "11", "12", "13", "14", "15", "16", "17", "18", or "19".\nEach of these encoded messages have 2 ways to be decoded (e.g. "11" can be decoded to "AA" or "K").\nHence, there are a total of 9 * 2 = 18 ways to decode "1*".\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "2*"\nOutput: 15\nExplanation: The encoded message can represent any of the encoded messages "21", "22", "23", "24", "25", "26", "27", "28", or "29".\n"21", "22", "23", "24", "25", and "26" have 2 ways of being decoded, but "27", "28", and "29" only have 1 way.\nHence, there are a total of (6 * 2) + (3 * 1) = 12 + 3 = 15 ways to decode "2*".\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 105
    • \n\t
    • s[i] is a digit or '*'.
    • \n
    \n", "content_cn": "

    \u4e00\u6761\u5305\u542b\u5b57\u6bcd A-Z \u7684\u6d88\u606f\u901a\u8fc7\u4ee5\u4e0b\u7684\u65b9\u5f0f\u8fdb\u884c\u4e86\u7f16\u7801\uff1a

    \n\n
    'A' -> 1\n'B' -> 2\n...\n'Z' -> 26\n
    \n\n

    \u9664\u4e86\u4e0a\u8ff0\u7684\u6761\u4ef6\u4ee5\u5916\uff0c\u73b0\u5728\u52a0\u5bc6\u5b57\u7b26\u4e32\u53ef\u4ee5\u5305\u542b\u5b57\u7b26 '*'\u4e86\uff0c\u5b57\u7b26'*'\u53ef\u4ee5\u88ab\u5f53\u505a1\u52309\u5f53\u4e2d\u7684\u4efb\u610f\u4e00\u4e2a\u6570\u5b57\u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u6761\u5305\u542b\u6570\u5b57\u548c\u5b57\u7b26'*'\u7684\u52a0\u5bc6\u4fe1\u606f\uff0c\u8bf7\u786e\u5b9a\u89e3\u7801\u65b9\u6cd5\u7684\u603b\u6570\u3002

    \n\n

    \u540c\u65f6\uff0c\u7531\u4e8e\u7ed3\u679c\u503c\u53ef\u80fd\u4f1a\u76f8\u5f53\u7684\u5927\uff0c\u6240\u4ee5\u4f60\u5e94\u5f53\u5bf9109 + 7\u53d6\u6a21\u3002\uff08\u7ffb\u8bd1\u8005\u6807\u6ce8\uff1a\u6b64\u5904\u53d6\u6a21\u4e3b\u8981\u662f\u4e3a\u4e86\u9632\u6b62\u6ea2\u51fa\uff09

    \n\n

    \u793a\u4f8b 1 :

    \n\n
    \u8f93\u5165: "*"\n\u8f93\u51fa: 9\n\u89e3\u91ca: \u52a0\u5bc6\u7684\u4fe1\u606f\u53ef\u4ee5\u88ab\u89e3\u5bc6\u4e3a: "A", "B", "C", "D", "E", "F", "G", "H", "I".\n
    \n\n

    \u793a\u4f8b 2 :

    \n\n
    \u8f93\u5165: "1*"\n\u8f93\u51fa: 9 + 9 = 18\uff08\u7ffb\u8bd1\u8005\u6807\u6ce8\uff1a\u8fd9\u91cc1*\u53ef\u4ee5\u5206\u89e3\u4e3a1,* \u6216\u8005\u5f53\u505a1*\u6765\u5904\u7406\uff0c\u6240\u4ee5\u7ed3\u679c\u662f9+9=18\uff09\n
    \n\n

    \u8bf4\u660e :

    \n\n
      \n\t
    1. \u8f93\u5165\u7684\u5b57\u7b26\u4e32\u957f\u5ea6\u8303\u56f4\u662f [1, 105]\u3002
    2. \n\t
    3. \u8f93\u5165\u7684\u5b57\u7b26\u4e32\u53ea\u4f1a\u5305\u542b\u5b57\u7b26 '*' \u548c \u6570\u5b57'0' - '9'\u3002
    4. \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numDecodings(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numDecodings(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numDecodings(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numDecodings(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numDecodings(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumDecodings(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar numDecodings = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef num_decodings(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numDecodings(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numDecodings(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numDecodings(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numDecodings(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_decodings(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function numDecodings($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numDecodings(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-decodings s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0639](https://leetcode-cn.com/problems/decode-ways-ii)", "[\u89e3\u7801\u65b9\u6cd5 II](/solution/0600-0699/0639.Decode%20Ways%20II/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0639](https://leetcode.com/problems/decode-ways-ii)", "[Decode Ways II](/solution/0600-0699/0639.Decode%20Ways%20II/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "0638", "frontend_question_id": "0638", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/shopping-offers", "url_en": "https://leetcode.com/problems/shopping-offers", "relative_path_cn": "/solution/0600-0699/0638.Shopping%20Offers/README.md", "relative_path_en": "/solution/0600-0699/0638.Shopping%20Offers/README_EN.md", "title_cn": "\u5927\u793c\u5305", "title_en": "Shopping Offers", "question_title_slug": "shopping-offers", "content_en": "

    In LeetCode Store, there are n items to sell. Each item has a price. However, there are some special offers, and a special offer consists of one or more different kinds of items with a sale price.

    \n\n

    You are given an integer array price where price[i] is the price of the ith item, and an integer array needs where needs[i] is the number of pieces of the ith item you want to buy.

    \n\n

    You are also given an array special where special[i] is of size n + 1 where special[i][j] is the number of pieces of the jth item in the ith offer and special[i][n] (i.e., the last integer in the array) is the price of the ith offer.

    \n\n

    Return the lowest price you have to pay for exactly certain items as given, where you could make optimal use of the special offers. You are not allowed to buy more items than you want, even if that would lower the overall price. You could use any of the special offers as many times as you want.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: price = [2,5], special = [[3,0,5],[1,2,10]], needs = [3,2]\nOutput: 14\nExplanation: There are two kinds of items, A and B. Their prices are $2 and $5 respectively. \nIn special offer 1, you can pay $5 for 3A and 0B\nIn special offer 2, you can pay $10 for 1A and 2B. \nYou need to buy 3A and 2B, so you may pay $10 for 1A and 2B (special offer #2), and $4 for 2A.\n
    \n\n

    Example 2:

    \n\n
    \nInput: price = [2,3,4], special = [[1,1,0,4],[2,2,1,9]], needs = [1,2,1]\nOutput: 11\nExplanation: The price of A is $2, and $3 for B, $4 for C. \nYou may pay $4 for 1A and 1B, and $9 for 2A ,2B and 1C. \nYou need to buy 1A ,2B and 1C, so you may pay $4 for 1A and 1B (special offer #1), and $3 for 1B, $4 for 1C. \nYou cannot add more items, though only $9 for 2A ,2B and 1C.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == price.length
    • \n\t
    • n == needs.length
    • \n\t
    • 1 <= n <= 6
    • \n\t
    • 0 <= price[i] <= 10
    • \n\t
    • 0 <= needs[i] <= 10
    • \n\t
    • 1 <= special.length <= 100
    • \n\t
    • special[i].length == n + 1
    • \n\t
    • 0 <= special[i][j] <= 50
    • \n
    \n", "content_cn": "

    \u5728 LeetCode \u5546\u5e97\u4e2d\uff0c \u6709 n \u4ef6\u5728\u552e\u7684\u7269\u54c1\u3002\u6bcf\u4ef6\u7269\u54c1\u90fd\u6709\u5bf9\u5e94\u7684\u4ef7\u683c\u3002\u7136\u800c\uff0c\u4e5f\u6709\u4e00\u4e9b\u5927\u793c\u5305\uff0c\u6bcf\u4e2a\u5927\u793c\u5305\u4ee5\u4f18\u60e0\u7684\u4ef7\u683c\u6346\u7ed1\u9500\u552e\u4e00\u7ec4\u7269\u54c1\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 price \u8868\u793a\u7269\u54c1\u4ef7\u683c\uff0c\u5176\u4e2d price[i] \u662f\u7b2c i \u4ef6\u7269\u54c1\u7684\u4ef7\u683c\u3002\u53e6\u6709\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 needs \u8868\u793a\u8d2d\u7269\u6e05\u5355\uff0c\u5176\u4e2d needs[i] \u662f\u9700\u8981\u8d2d\u4e70\u7b2c i \u4ef6\u7269\u54c1\u7684\u6570\u91cf\u3002

    \n\n

    \u8fd8\u6709\u4e00\u4e2a\u6570\u7ec4 special \u8868\u793a\u5927\u793c\u5305\uff0cspecial[i] \u7684\u957f\u5ea6\u4e3a n + 1 \uff0c\u5176\u4e2d special[i][j] \u8868\u793a\u7b2c i \u4e2a\u5927\u793c\u5305\u4e2d\u5185\u542b\u7b2c j \u4ef6\u7269\u54c1\u7684\u6570\u91cf\uff0c\u4e14 special[i][n] \uff08\u4e5f\u5c31\u662f\u6570\u7ec4\u4e2d\u7684\u6700\u540e\u4e00\u4e2a\u6574\u6570\uff09\u4e3a\u7b2c i \u4e2a\u5927\u793c\u5305\u7684\u4ef7\u683c\u3002

    \n\n

    \u8fd4\u56de \u786e\u5207 \u6ee1\u8db3\u8d2d\u7269\u6e05\u5355\u6240\u9700\u82b1\u8d39\u7684\u6700\u4f4e\u4ef7\u683c\uff0c\u4f60\u53ef\u4ee5\u5145\u5206\u5229\u7528\u5927\u793c\u5305\u7684\u4f18\u60e0\u6d3b\u52a8\u3002\u4f60\u4e0d\u80fd\u8d2d\u4e70\u8d85\u51fa\u8d2d\u7269\u6e05\u5355\u6307\u5b9a\u6570\u91cf\u7684\u7269\u54c1\uff0c\u5373\u4f7f\u90a3\u6837\u4f1a\u964d\u4f4e\u6574\u4f53\u4ef7\u683c\u3002\u4efb\u610f\u5927\u793c\u5305\u53ef\u65e0\u9650\u6b21\u8d2d\u4e70\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aprice = [2,5], special = [[3,0,5],[1,2,10]], needs = [3,2]\n\u8f93\u51fa\uff1a14\n\u89e3\u91ca\uff1a\u6709 A \u548c B \u4e24\u79cd\u7269\u54c1\uff0c\u4ef7\u683c\u5206\u522b\u4e3a \u00a52 \u548c \u00a55 \u3002 \n\u5927\u793c\u5305 1 \uff0c\u4f60\u53ef\u4ee5\u4ee5 \u00a55 \u7684\u4ef7\u683c\u8d2d\u4e70 3A \u548c 0B \u3002 \n\u5927\u793c\u5305 2 \uff0c\u4f60\u53ef\u4ee5\u4ee5 \u00a510 \u7684\u4ef7\u683c\u8d2d\u4e70 1A \u548c 2B \u3002 \n\u9700\u8981\u8d2d\u4e70 3 \u4e2a A \u548c 2 \u4e2a B \uff0c \u6240\u4ee5\u4ed8 \u00a510 \u8d2d\u4e70 1A \u548c 2B\uff08\u5927\u793c\u5305 2\uff09\uff0c\u4ee5\u53ca \u00a54 \u8d2d\u4e70 2A \u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aprice = [2,3,4], special = [[1,1,0,4],[2,2,1,9]], needs = [1,2,1]\n\u8f93\u51fa\uff1a11\n\u89e3\u91ca\uff1aA \uff0cB \uff0cC \u7684\u4ef7\u683c\u5206\u522b\u4e3a \u00a52 \uff0c\u00a53 \uff0c\u00a54 \u3002\n\u53ef\u4ee5\u7528 \u00a54 \u8d2d\u4e70 1A \u548c 1B \uff0c\u4e5f\u53ef\u4ee5\u7528 \u00a59 \u8d2d\u4e70 2A \uff0c2B \u548c 1C \u3002 \n\u9700\u8981\u4e70 1A \uff0c2B \u548c 1C \uff0c\u6240\u4ee5\u4ed8 \u00a54 \u4e70 1A \u548c 1B\uff08\u5927\u793c\u5305 1\uff09\uff0c\u4ee5\u53ca \u00a53 \u8d2d\u4e70 1B \uff0c \u00a54 \u8d2d\u4e70 1C \u3002 \n\u4e0d\u53ef\u4ee5\u8d2d\u4e70\u8d85\u51fa\u5f85\u8d2d\u6e05\u5355\u7684\u7269\u54c1\uff0c\u5c3d\u7ba1\u8d2d\u4e70\u5927\u793c\u5305 2 \u66f4\u52a0\u4fbf\u5b9c\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == price.length
    • \n\t
    • n == needs.length
    • \n\t
    • 1 <= n <= 6
    • \n\t
    • 0 <= price[i] <= 10
    • \n\t
    • 0 <= needs[i] <= 10
    • \n\t
    • 1 <= special.length <= 100
    • \n\t
    • special[i].length == n + 1
    • \n\t
    • 0 <= special[i][j] <= 50
    • \n
    \n", "tags_en": ["Depth-first Search", "Dynamic Programming"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int shoppingOffers(vector& price, vector>& special, vector& needs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int shoppingOffers(List price, List> special, List needs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def shoppingOffers(self, price, special, needs):\n \"\"\"\n :type price: List[int]\n :type special: List[List[int]]\n :type needs: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def shoppingOffers(self, price: List[int], special: List[List[int]], needs: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint shoppingOffers(int* price, int priceSize, int** special, int specialSize, int* specialColSize, int* needs, int needsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ShoppingOffers(IList price, IList> special, IList needs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} price\n * @param {number[][]} special\n * @param {number[]} needs\n * @return {number}\n */\nvar shoppingOffers = function(price, special, needs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} price\n# @param {Integer[][]} special\n# @param {Integer[]} needs\n# @return {Integer}\ndef shopping_offers(price, special, needs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func shoppingOffers(_ price: [Int], _ special: [[Int]], _ needs: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func shoppingOffers(price []int, special [][]int, needs []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def shoppingOffers(price: List[Int], special: List[List[Int]], needs: List[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun shoppingOffers(price: List, special: List>, needs: List): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn shopping_offers(price: Vec, special: Vec>, needs: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $price\n * @param Integer[][] $special\n * @param Integer[] $needs\n * @return Integer\n */\n function shoppingOffers($price, $special, $needs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function shoppingOffers(price: number[], special: number[][], needs: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (shopping-offers price special needs)\n (-> (listof exact-integer?) (listof (listof exact-integer?)) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0638](https://leetcode-cn.com/problems/shopping-offers)", "[\u5927\u793c\u5305](/solution/0600-0699/0638.Shopping%20Offers/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0638](https://leetcode.com/problems/shopping-offers)", "[Shopping Offers](/solution/0600-0699/0638.Shopping%20Offers/README_EN.md)", "`Depth-first Search`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0637", "frontend_question_id": "0637", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/average-of-levels-in-binary-tree", "url_en": "https://leetcode.com/problems/average-of-levels-in-binary-tree", "relative_path_cn": "/solution/0600-0699/0637.Average%20of%20Levels%20in%20Binary%20Tree/README.md", "relative_path_en": "/solution/0600-0699/0637.Average%20of%20Levels%20in%20Binary%20Tree/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u7684\u5c42\u5e73\u5747\u503c", "title_en": "Average of Levels in Binary Tree", "question_title_slug": "average-of-levels-in-binary-tree", "content_en": "Given the root of a binary tree, return the average value of the nodes on each level in the form of an array. Answers within 10-5 of the actual answer will be accepted.\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [3,9,20,null,15,7]\nOutput: [3.00000,14.50000,11.00000]\nExplanation: The average value of nodes on level 0 is 3, on level 1 is 14.5, and on level 2 is 11.\nHence return [3, 14.5, 11].\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [3,9,20,15,7]\nOutput: [3.00000,14.50000,11.00000]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 104].
    • \n\t
    • -231 <= Node.val <= 231 - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u7a7a\u4e8c\u53c9\u6811, \u8fd4\u56de\u4e00\u4e2a\u7531\u6bcf\u5c42\u8282\u70b9\u5e73\u5747\u503c\u7ec4\u6210\u7684\u6570\u7ec4\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a\n    3\n   / \\\n  9  20\n    /  \\\n   15   7\n\u8f93\u51fa\uff1a[3, 14.5, 11]\n\u89e3\u91ca\uff1a\n\u7b2c 0 \u5c42\u7684\u5e73\u5747\u503c\u662f 3 ,  \u7b2c1\u5c42\u662f 14.5 , \u7b2c2\u5c42\u662f 11 \u3002\u56e0\u6b64\u8fd4\u56de [3, 14.5, 11] \u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u8282\u70b9\u503c\u7684\u8303\u56f4\u572832\u4f4d\u6709\u7b26\u53f7\u6574\u6570\u8303\u56f4\u5185\u3002
    • \n
    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector averageOfLevels(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public List averageOfLevels(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def averageOfLevels(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: List[float]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def averageOfLevels(self, root: TreeNode) -> List[float]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\ndouble* averageOfLevels(struct TreeNode* root, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public IList AverageOfLevels(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number[]}\n */\nvar averageOfLevels = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Float[]}\ndef average_of_levels(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func averageOfLevels(_ root: TreeNode?) -> [Double] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc averageOfLevels(root *TreeNode) []float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def averageOfLevels(root: TreeNode): Array[Double] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun averageOfLevels(root: TreeNode?): DoubleArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn average_of_levels(root: Option>>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Float[]\n */\n function averageOfLevels($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction averageOfLevels(root: TreeNode | null): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (average-of-levels root)\n (-> (or/c tree-node? #f) (listof flonum?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0637](https://leetcode-cn.com/problems/average-of-levels-in-binary-tree)", "[\u4e8c\u53c9\u6811\u7684\u5c42\u5e73\u5747\u503c](/solution/0600-0699/0637.Average%20of%20Levels%20in%20Binary%20Tree/README.md)", "`\u6811`", "\u7b80\u5355", ""], "md_table_row_en": ["[0637](https://leetcode.com/problems/average-of-levels-in-binary-tree)", "[Average of Levels in Binary Tree](/solution/0600-0699/0637.Average%20of%20Levels%20in%20Binary%20Tree/README_EN.md)", "`Tree`", "Easy", ""]}, {"question_id": "0636", "frontend_question_id": "0636", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/exclusive-time-of-functions", "url_en": "https://leetcode.com/problems/exclusive-time-of-functions", "relative_path_cn": "/solution/0600-0699/0636.Exclusive%20Time%20of%20Functions/README.md", "relative_path_en": "/solution/0600-0699/0636.Exclusive%20Time%20of%20Functions/README_EN.md", "title_cn": "\u51fd\u6570\u7684\u72ec\u5360\u65f6\u95f4", "title_en": "Exclusive Time of Functions", "question_title_slug": "exclusive-time-of-functions", "content_en": "

    On a single-threaded CPU, we execute a program containing n functions. Each function has a unique ID between 0 and n-1.

    \n\n

    Function calls are stored in a call stack: when a function call starts, its ID is pushed onto the stack, and when a function call ends, its ID is popped off the stack. The function whose ID is at the top of the stack is the current function being executed. Each time a function starts or ends, we write a log with the ID, whether it started or ended, and the timestamp.

    \n\n

    You are given a list logs, where logs[i] represents the ith log message formatted as a string "{function_id}:{"start" | "end"}:{timestamp}". For example, "0:start:3" means a function call with function ID 0 started at the beginning of timestamp 3, and "1:end:2" means a function call with function ID 1 ended at the end of timestamp 2. Note that a function can be called multiple times, possibly recursively.

    \n\n

    A function's exclusive time is the sum of execution times for all function calls in the program. For example, if a function is called twice, one call executing for 2 time units and another call executing for 1 time unit, the exclusive time is 2 + 1 = 3.

    \n\n

    Return the exclusive time of each function in an array, where the value at the ith index represents the exclusive time for the function with ID i.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: n = 2, logs = ["0:start:0","1:start:2","1:end:5","0:end:6"]\nOutput: [3,4]\nExplanation:\nFunction 0 starts at the beginning of time 0, then it executes 2 for units of time and reaches the end of time 1.\nFunction 1 starts at the beginning of time 2, executes for 4 units of time, and ends at the end of time 5.\nFunction 0 resumes execution at the beginning of time 6 and executes for 1 unit of time.\nSo function 0 spends 2 + 1 = 3 units of total time executing, and function 1 spends 4 units of total time executing.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 1, logs = ["0:start:0","0:start:2","0:end:5","0:start:6","0:end:6","0:end:7"]\nOutput: [8]\nExplanation:\nFunction 0 starts at the beginning of time 0, executes for 2 units of time, and recursively calls itself.\nFunction 0 (recursive call) starts at the beginning of time 2 and executes for 4 units of time.\nFunction 0 (initial call) resumes execution then immediately calls itself again.\nFunction 0 (2nd recursive call) starts at the beginning of time 6 and executes for 1 unit of time.\nFunction 0 (initial call) resumes execution at the beginning of time 7 and executes for 1 unit of time.\nSo function 0 spends 2 + 4 + 1 + 1 = 8 units of total time executing.\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 2, logs = ["0:start:0","0:start:2","0:end:5","1:start:6","1:end:6","0:end:7"]\nOutput: [7,1]\nExplanation:\nFunction 0 starts at the beginning of time 0, executes for 2 units of time, and recursively calls itself.\nFunction 0 (recursive call) starts at the beginning of time 2 and executes for 4 units of time.\nFunction 0 (initial call) resumes execution then immediately calls function 1.\nFunction 1 starts at the beginning of time 6, executes 1 units of time, and ends at the end of time 6.\nFunction 0 resumes execution at the beginning of time 6 and executes for 2 units of time.\nSo function 0 spends 2 + 4 + 1 = 7 units of total time executing, and function 1 spends 1 unit of total time executing.\n
    \n\n

    Example 4:

    \n\n
    \nInput: n = 2, logs = ["0:start:0","0:start:2","0:end:5","1:start:7","1:end:7","0:end:8"]\nOutput: [8,1]\n
    \n\n

    Example 5:

    \n\n
    \nInput: n = 1, logs = ["0:start:0","0:end:0"]\nOutput: [1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 100
    • \n\t
    • 1 <= logs.length <= 500
    • \n\t
    • 0 <= function_id < n
    • \n\t
    • 0 <= timestamp <= 109
    • \n\t
    • No two start events will happen at the same timestamp.
    • \n\t
    • No two end events will happen at the same timestamp.
    • \n\t
    • Each function has an "end" log for each "start" log.
    • \n
    \n", "content_cn": "

    \u6709\u4e00\u4e2a \u5355\u7ebf\u7a0b CPU \u6b63\u5728\u8fd0\u884c\u4e00\u4e2a\u542b\u6709 n \u9053\u51fd\u6570\u7684\u7a0b\u5e8f\u3002\u6bcf\u9053\u51fd\u6570\u90fd\u6709\u4e00\u4e2a\u4f4d\u4e8e\u00a0 0 \u548c n-1 \u4e4b\u95f4\u7684\u552f\u4e00\u6807\u8bc6\u7b26\u3002

    \n\n

    \u51fd\u6570\u8c03\u7528 \u5b58\u50a8\u5728\u4e00\u4e2a \u8c03\u7528\u6808 \u4e0a \uff1a\u5f53\u4e00\u4e2a\u51fd\u6570\u8c03\u7528\u5f00\u59cb\u65f6\uff0c\u5b83\u7684\u6807\u8bc6\u7b26\u5c06\u4f1a\u63a8\u5165\u6808\u4e2d\u3002\u800c\u5f53\u4e00\u4e2a\u51fd\u6570\u8c03\u7528\u7ed3\u675f\u65f6\uff0c\u5b83\u7684\u6807\u8bc6\u7b26\u5c06\u4f1a\u4ece\u6808\u4e2d\u5f39\u51fa\u3002\u6807\u8bc6\u7b26\u4f4d\u4e8e\u6808\u9876\u7684\u51fd\u6570\u662f \u5f53\u524d\u6b63\u5728\u6267\u884c\u7684\u51fd\u6570 \u3002\u6bcf\u5f53\u4e00\u4e2a\u51fd\u6570\u5f00\u59cb\u6216\u8005\u7ed3\u675f\u65f6\uff0c\u5c06\u4f1a\u8bb0\u5f55\u4e00\u6761\u65e5\u5fd7\uff0c\u5305\u62ec\u51fd\u6570\u6807\u8bc6\u7b26\u3001\u662f\u5f00\u59cb\u8fd8\u662f\u7ed3\u675f\u3001\u4ee5\u53ca\u76f8\u5e94\u7684\u65f6\u95f4\u6233\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u7531\u65e5\u5fd7\u7ec4\u6210\u7684\u5217\u8868 logs \uff0c\u5176\u4e2d logs[i] \u8868\u793a\u7b2c i \u6761\u65e5\u5fd7\u6d88\u606f\uff0c\u8be5\u6d88\u606f\u662f\u4e00\u4e2a\u6309 \"{function_id}:{\"start\" | \"end\"}:{timestamp}\" \u8fdb\u884c\u683c\u5f0f\u5316\u7684\u5b57\u7b26\u4e32\u3002\u4f8b\u5982\uff0c\"0:start:3\" \u610f\u5473\u7740\u6807\u8bc6\u7b26\u4e3a 0 \u7684\u51fd\u6570\u8c03\u7528\u5728\u65f6\u95f4\u6233 3 \u7684 \u8d77\u59cb\u5f00\u59cb\u6267\u884c \uff1b\u800c \"1:end:2\" \u610f\u5473\u7740\u6807\u8bc6\u7b26\u4e3a 1 \u7684\u51fd\u6570\u8c03\u7528\u5728\u65f6\u95f4\u6233 2 \u7684 \u672b\u5c3e\u7ed3\u675f\u6267\u884c\u3002\u6ce8\u610f\uff0c\u51fd\u6570\u53ef\u4ee5 \u8c03\u7528\u591a\u6b21\uff0c\u53ef\u80fd\u5b58\u5728\u9012\u5f52\u8c03\u7528 \u3002

    \n\n

    \u51fd\u6570\u7684 \u72ec\u5360\u65f6\u95f4 \u5b9a\u4e49\u662f\u5728\u8fd9\u4e2a\u51fd\u6570\u5728\u7a0b\u5e8f\u6240\u6709\u51fd\u6570\u8c03\u7528\u4e2d\u6267\u884c\u65f6\u95f4\u7684\u603b\u548c\uff0c\u8c03\u7528\u5176\u4ed6\u51fd\u6570\u82b1\u8d39\u7684\u65f6\u95f4\u4e0d\u7b97\u8be5\u51fd\u6570\u7684\u72ec\u5360\u65f6\u95f4\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4e00\u4e2a\u51fd\u6570\u88ab\u8c03\u7528\u4e24\u6b21\uff0c\u4e00\u6b21\u8c03\u7528\u6267\u884c 2 \u5355\u4f4d\u65f6\u95f4\uff0c\u53e6\u4e00\u6b21\u8c03\u7528\u6267\u884c 1 \u5355\u4f4d\u65f6\u95f4\uff0c\u90a3\u4e48\u8be5\u51fd\u6570\u7684 \u72ec\u5360\u65f6\u95f4 \u4e3a 2 + 1 = 3 \u3002

    \n\n

    \u4ee5\u6570\u7ec4\u5f62\u5f0f\u8fd4\u56de\u6bcf\u4e2a\u51fd\u6570\u7684 \u72ec\u5360\u65f6\u95f4 \uff0c\u5176\u4e2d\u7b2c i \u4e2a\u4e0b\u6807\u5bf9\u5e94\u7684\u503c\u8868\u793a\u6807\u8bc6\u7b26 i \u7684\u51fd\u6570\u7684\u72ec\u5360\u65f6\u95f4\u3002

    \n\u00a0\n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1an = 2, logs = [\"0:start:0\",\"1:start:2\",\"1:end:5\",\"0:end:6\"]\n\u8f93\u51fa\uff1a[3,4]\n\u89e3\u91ca\uff1a\n\u51fd\u6570 0 \u5728\u65f6\u95f4\u6233 0 \u7684\u8d77\u59cb\u5f00\u59cb\u6267\u884c\uff0c\u6267\u884c 2 \u4e2a\u5355\u4f4d\u65f6\u95f4\uff0c\u4e8e\u65f6\u95f4\u6233 1 \u7684\u672b\u5c3e\u7ed3\u675f\u6267\u884c\u3002 \n\u51fd\u6570 1 \u5728\u65f6\u95f4\u6233 2 \u7684\u8d77\u59cb\u5f00\u59cb\u6267\u884c\uff0c\u6267\u884c 4 \u4e2a\u5355\u4f4d\u65f6\u95f4\uff0c\u4e8e\u65f6\u95f4\u6233 5 \u7684\u672b\u5c3e\u7ed3\u675f\u6267\u884c\u3002 \n\u51fd\u6570 0 \u5728\u65f6\u95f4\u6233 6 \u7684\u5f00\u59cb\u6062\u590d\u6267\u884c\uff0c\u6267\u884c 1 \u4e2a\u5355\u4f4d\u65f6\u95f4\u3002 \n\u6240\u4ee5\u51fd\u6570 0 \u603b\u5171\u6267\u884c 2 + 1 = 3 \u4e2a\u5355\u4f4d\u65f6\u95f4\uff0c\u51fd\u6570 1 \u603b\u5171\u6267\u884c 4 \u4e2a\u5355\u4f4d\u65f6\u95f4\u3002 \n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 1, logs = [\"0:start:0\",\"0:start:2\",\"0:end:5\",\"0:start:6\",\"0:end:6\",\"0:end:7\"]\n\u8f93\u51fa\uff1a[8]\n\u89e3\u91ca\uff1a\n\u51fd\u6570 0 \u5728\u65f6\u95f4\u6233 0 \u7684\u8d77\u59cb\u5f00\u59cb\u6267\u884c\uff0c\u6267\u884c 2 \u4e2a\u5355\u4f4d\u65f6\u95f4\uff0c\u5e76\u9012\u5f52\u8c03\u7528\u5b83\u81ea\u8eab\u3002\n\u51fd\u6570 0\uff08\u9012\u5f52\u8c03\u7528\uff09\u5728\u65f6\u95f4\u6233 2 \u7684\u8d77\u59cb\u5f00\u59cb\u6267\u884c\uff0c\u6267\u884c 4 \u4e2a\u5355\u4f4d\u65f6\u95f4\u3002\n\u51fd\u6570 0\uff08\u521d\u59cb\u8c03\u7528\uff09\u6062\u590d\u6267\u884c\uff0c\u5e76\u7acb\u523b\u518d\u6b21\u8c03\u7528\u5b83\u81ea\u8eab\u3002\n\u51fd\u6570 0\uff08\u7b2c\u4e8c\u6b21\u9012\u5f52\u8c03\u7528\uff09\u5728\u65f6\u95f4\u6233 6 \u7684\u8d77\u59cb\u5f00\u59cb\u6267\u884c\uff0c\u6267\u884c 1 \u4e2a\u5355\u4f4d\u65f6\u95f4\u3002\n\u51fd\u6570 0\uff08\u521d\u59cb\u8c03\u7528\uff09\u5728\u65f6\u95f4\u6233 7 \u7684\u8d77\u59cb\u6062\u590d\u6267\u884c\uff0c\u6267\u884c 1 \u4e2a\u5355\u4f4d\u65f6\u95f4\u3002\n\u6240\u4ee5\u51fd\u6570 0 \u603b\u5171\u6267\u884c 2 + 4 + 1 + 1 = 8 \u4e2a\u5355\u4f4d\u65f6\u95f4\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 2, logs = [\"0:start:0\",\"0:start:2\",\"0:end:5\",\"1:start:6\",\"1:end:6\",\"0:end:7\"]\n\u8f93\u51fa\uff1a[7,1]\n\u89e3\u91ca\uff1a\n\u51fd\u6570 0 \u5728\u65f6\u95f4\u6233 0 \u7684\u8d77\u59cb\u5f00\u59cb\u6267\u884c\uff0c\u6267\u884c 2 \u4e2a\u5355\u4f4d\u65f6\u95f4\uff0c\u5e76\u9012\u5f52\u8c03\u7528\u5b83\u81ea\u8eab\u3002\n\u51fd\u6570 0\uff08\u9012\u5f52\u8c03\u7528\uff09\u5728\u65f6\u95f4\u6233 2 \u7684\u8d77\u59cb\u5f00\u59cb\u6267\u884c\uff0c\u6267\u884c 4 \u4e2a\u5355\u4f4d\u65f6\u95f4\u3002\n\u51fd\u6570 0\uff08\u521d\u59cb\u8c03\u7528\uff09\u6062\u590d\u6267\u884c\uff0c\u5e76\u7acb\u523b\u8c03\u7528\u51fd\u6570 1 \u3002\n\u51fd\u6570 1\u5728\u65f6\u95f4\u6233 6 \u7684\u8d77\u59cb\u5f00\u59cb\u6267\u884c\uff0c\u6267\u884c 1 \u4e2a\u5355\u4f4d\u65f6\u95f4\uff0c\u4e8e\u65f6\u95f4\u6233 6 \u7684\u672b\u5c3e\u7ed3\u675f\u6267\u884c\u3002\n\u51fd\u6570 0\uff08\u521d\u59cb\u8c03\u7528\uff09\u5728\u65f6\u95f4\u6233 7 \u7684\u8d77\u59cb\u6062\u590d\u6267\u884c\uff0c\u6267\u884c 1 \u4e2a\u5355\u4f4d\u65f6\u95f4\uff0c\u4e8e\u65f6\u95f4\u6233 7 \u7684\u672b\u5c3e\u7ed3\u675f\u6267\u884c\u3002\n\u6240\u4ee5\u51fd\u6570 0 \u603b\u5171\u6267\u884c 2 + 4 + 1 = 7 \u4e2a\u5355\u4f4d\u65f6\u95f4\uff0c\u51fd\u6570 1 \u603b\u5171\u6267\u884c 1 \u4e2a\u5355\u4f4d\u65f6\u95f4\u3002 
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 2, logs = [\"0:start:0\",\"0:start:2\",\"0:end:5\",\"1:start:7\",\"1:end:7\",\"0:end:8\"]\n\u8f93\u51fa\uff1a[8,1]\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 1, logs = [\"0:start:0\",\"0:end:0\"]\n\u8f93\u51fa\uff1a[1]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 100
    • \n\t
    • 1 <= logs.length <= 500
    • \n\t
    • 0 <= function_id < n
    • \n\t
    • 0 <= timestamp <= 109
    • \n\t
    • \u4e24\u4e2a\u5f00\u59cb\u4e8b\u4ef6\u4e0d\u4f1a\u5728\u540c\u4e00\u65f6\u95f4\u6233\u53d1\u751f
    • \n\t
    • \u4e24\u4e2a\u7ed3\u675f\u4e8b\u4ef6\u4e0d\u4f1a\u5728\u540c\u4e00\u65f6\u95f4\u6233\u53d1\u751f
    • \n\t
    • \u6bcf\u9053\u51fd\u6570\u90fd\u6709\u4e00\u4e2a\u5bf9\u5e94\u00a0\"start\" \u65e5\u5fd7\u7684 \"end\" \u65e5\u5fd7
    • \n
    \n", "tags_en": ["Stack"], "tags_cn": ["\u6808"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector exclusiveTime(int n, vector& logs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] exclusiveTime(int n, List logs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def exclusiveTime(self, n, logs):\n \"\"\"\n :type n: int\n :type logs: List[str]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def exclusiveTime(self, n: int, logs: List[str]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* exclusiveTime(int n, char ** logs, int logsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] ExclusiveTime(int n, IList logs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {string[]} logs\n * @return {number[]}\n */\nvar exclusiveTime = function(n, logs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {String[]} logs\n# @return {Integer[]}\ndef exclusive_time(n, logs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func exclusiveTime(_ n: Int, _ logs: [String]) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func exclusiveTime(n int, logs []string) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def exclusiveTime(n: Int, logs: List[String]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun exclusiveTime(n: Int, logs: List): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn exclusive_time(n: i32, logs: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param String[] $logs\n * @return Integer[]\n */\n function exclusiveTime($n, $logs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function exclusiveTime(n: number, logs: string[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (exclusive-time n logs)\n (-> exact-integer? (listof string?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0636](https://leetcode-cn.com/problems/exclusive-time-of-functions)", "[\u51fd\u6570\u7684\u72ec\u5360\u65f6\u95f4](/solution/0600-0699/0636.Exclusive%20Time%20of%20Functions/README.md)", "`\u6808`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0636](https://leetcode.com/problems/exclusive-time-of-functions)", "[Exclusive Time of Functions](/solution/0600-0699/0636.Exclusive%20Time%20of%20Functions/README_EN.md)", "`Stack`", "Medium", ""]}, {"question_id": "0635", "frontend_question_id": "0635", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/design-log-storage-system", "url_en": "https://leetcode.com/problems/design-log-storage-system", "relative_path_cn": "/solution/0600-0699/0635.Design%20Log%20Storage%20System/README.md", "relative_path_en": "/solution/0600-0699/0635.Design%20Log%20Storage%20System/README_EN.md", "title_cn": "\u8bbe\u8ba1\u65e5\u5fd7\u5b58\u50a8\u7cfb\u7edf", "title_en": "Design Log Storage System", "question_title_slug": "design-log-storage-system", "content_en": "

    You are given several logs, where each log contains a unique ID and timestamp. Timestamp is a string that has the following format: Year:Month:Day:Hour:Minute:Second, for example, 2017:01:01:23:59:59. All domains are zero-padded decimal numbers.

    \n\n

    Implement the LogSystem class:

    \n\n
      \n\t
    • LogSystem() Initializes the LogSystem object.
    • \n\t
    • void put(int id, string timestamp) Stores the given log (id, timestamp) in your storage system.
    • \n\t
    • int[] retrieve(string start, string end, string granularity) Returns the IDs of the logs whose timestamps are within the range from start to end inclusive. start and end all have the same format as timestamp, and granularity means how precise the range should be (i.e. to the exact Day, Minute, etc.). For example, start = "2017:01:01:23:59:59", end = "2017:01:02:23:59:59", and granularity = "Day" means that we need to find the logs within the inclusive range from Jan. 1st 2017 to Jan. 2nd 2017, and the Hour, Minute, and Second for each log entry can be ignored.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["LogSystem", "put", "put", "put", "retrieve", "retrieve"]\n[[], [1, "2017:01:01:23:59:59"], [2, "2017:01:01:22:59:59"], [3, "2016:01:01:00:00:00"], ["2016:01:01:01:01:01", "2017:01:01:23:00:00", "Year"], ["2016:01:01:01:01:01", "2017:01:01:23:00:00", "Hour"]]\nOutput\n[null, null, null, null, [3, 2, 1], [2, 1]]\n\nExplanation\nLogSystem logSystem = new LogSystem();\nlogSystem.put(1, "2017:01:01:23:59:59");\nlogSystem.put(2, "2017:01:01:22:59:59");\nlogSystem.put(3, "2016:01:01:00:00:00");\n\n// return [3,2,1], because you need to return all logs between 2016 and 2017.\nlogSystem.retrieve("2016:01:01:01:01:01", "2017:01:01:23:00:00", "Year");\n\n// return [2,1], because you need to return all logs between Jan. 1, 2016 01:XX:XX and Jan. 1, 2017 23:XX:XX.\n// Log 3 is not returned because Jan. 1, 2016 00:00:00 comes before the start of the range.\nlogSystem.retrieve("2016:01:01:01:01:01", "2017:01:01:23:00:00", "Hour");\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= id <= 500
    • \n\t
    • 2000 <= Year <= 2017
    • \n\t
    • 1 <= Month <= 12
    • \n\t
    • 1 <= Day <= 31
    • \n\t
    • 0 <= Hour <= 23
    • \n\t
    • 0 <= Minute, Second <= 59
    • \n\t
    • granularity is one of the values ["Year", "Month", "Day", "Hour", "Minute", "Second"].
    • \n\t
    • At most 500 calls will be made to put and retrieve.
    • \n
    \n", "content_cn": "

    \u4f60\u5c06\u83b7\u5f97\u591a\u6761\u65e5\u5fd7\uff0c\u6bcf\u6761\u65e5\u5fd7\u90fd\u6709\u552f\u4e00\u7684 id \u548c timestamp \uff0ctimestamp \u662f\u5f62\u5982 Year:Month:Day:Hour:Minute:Second \u7684\u5b57\u7b26\u4e32\uff0c2017:01:01:23:59:59 \uff0c\u6240\u6709\u503c\u57df\u90fd\u662f\u96f6\u586b\u5145\u7684\u5341\u8fdb\u5236\u6570\u3002

    \n\n

    \u5b9e\u73b0 LogSystem \u7c7b\uff1a

    \n\n
      \n\t
    • LogSystem() \u521d\u59cb\u5316 LogSystem \u5bf9\u8c61
    • \n\t
    • void put(int id, string timestamp) \u7ed9\u5b9a\u65e5\u5fd7\u7684 id \u548c timestamp \uff0c\u5c06\u8fd9\u4e2a\u65e5\u5fd7\u5b58\u5165\u4f60\u7684\u5b58\u50a8\u7cfb\u7edf\u4e2d\u3002
    • \n\t
    • int[] retrieve(string start, string end, string granularity) \u8fd4\u56de\u5728\u7ed9\u5b9a\u65f6\u95f4\u533a\u95f4 [start, end] \uff08\u5305\u542b\u4e24\u7aef\uff09\u5185\u7684\u6240\u6709\u65e5\u5fd7\u7684 id \u3002start \u3001end \u548c timestamp \u7684\u683c\u5f0f\u76f8\u540c\uff0cgranularity \u8868\u793a\u8003\u8651\u7684\u65f6\u95f4\u7c92\u5ea6\uff08\u4f8b\u5982\uff0c\u7cbe\u786e\u5230 Day\u3001Minute \u7b49\uff09\u3002\u4f8b\u5982 start = \"2017:01:01:23:59:59\"\u3001end = \"2017:01:02:23:59:59\" \u4e14 granularity = \"Day\" \u610f\u5473\u7740\u9700\u8981\u67e5\u627e\u4ece Jan. 1st 2017 \u5230 Jan. 2nd 2017 \u8303\u56f4\u5185\u7684\u65e5\u5fd7\uff0c\u53ef\u4ee5\u5ffd\u7565\u65e5\u5fd7\u7684 Hour\u3001Minute \u548c Second \u3002
    • \n
    \n\u00a0\n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\n[\"LogSystem\", \"put\", \"put\", \"put\", \"retrieve\", \"retrieve\"]\n[[], [1, \"2017:01:01:23:59:59\"], [2, \"2017:01:01:22:59:59\"], [3, \"2016:01:01:00:00:00\"], [\"2016:01:01:01:01:01\", \"2017:01:01:23:00:00\", \"Year\"], [\"2016:01:01:01:01:01\", \"2017:01:01:23:00:00\", \"Hour\"]]\n\u8f93\u51fa\uff1a\n[null, null, null, null, [3, 2, 1], [2, 1]]\n\n\u89e3\u91ca\uff1a\nLogSystem logSystem = new LogSystem();\nlogSystem.put(1, \"2017:01:01:23:59:59\");\nlogSystem.put(2, \"2017:01:01:22:59:59\");\nlogSystem.put(3, \"2016:01:01:00:00:00\");\n\n// \u8fd4\u56de [3,2,1]\uff0c\u8fd4\u56de\u4ece 2016 \u5e74\u5230 2017 \u5e74\u6240\u6709\u7684\u65e5\u5fd7\u3002\nlogSystem.retrieve(\"2016:01:01:01:01:01\", \"2017:01:01:23:00:00\", \"Year\");\n\n// \u8fd4\u56de [2,1]\uff0c\u8fd4\u56de\u4ece Jan. 1, 2016 01:XX:XX \u5230 Jan. 1, 2017 23:XX:XX \u4e4b\u95f4\u7684\u6240\u6709\u65e5\u5fd7\n// \u4e0d\u8fd4\u56de\u65e5\u5fd7 3 \u56e0\u4e3a\u8bb0\u5f55\u65f6\u95f4 Jan. 1, 2016 00:00:00 \u8d85\u8fc7\u8303\u56f4\u7684\u8d77\u59cb\u65f6\u95f4\nlogSystem.retrieve(\"2016:01:01:01:01:01\", \"2017:01:01:23:00:00\", \"Hour\");\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= id <= 500
    • \n\t
    • 2000 <= Year <= 2017
    • \n\t
    • 1 <= Month <= 12
    • \n\t
    • 1 <= Day <= 31
    • \n\t
    • 0 <= Hour <= 23
    • \n\t
    • 0 <= Minute, Second <= 59
    • \n\t
    • granularity \u662f\u8fd9\u4e9b\u503c [\"Year\", \"Month\", \"Day\", \"Hour\", \"Minute\", \"Second\"] \u4e4b\u4e00
    • \n\t
    • \u6700\u591a\u8c03\u7528 500 \u6b21 put \u548c retrieve
    • \n
    \n", "tags_en": ["Design", "String"], "tags_cn": ["\u8bbe\u8ba1", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class LogSystem {\npublic:\n LogSystem() {\n\n }\n \n void put(int id, string timestamp) {\n\n }\n \n vector retrieve(string start, string end, string granularity) {\n\n }\n};\n\n/**\n * Your LogSystem object will be instantiated and called as such:\n * LogSystem* obj = new LogSystem();\n * obj->put(id,timestamp);\n * vector param_2 = obj->retrieve(start,end,granularity);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class LogSystem {\n\n public LogSystem() {\n\n }\n \n public void put(int id, String timestamp) {\n\n }\n \n public List retrieve(String start, String end, String granularity) {\n\n }\n}\n\n/**\n * Your LogSystem object will be instantiated and called as such:\n * LogSystem obj = new LogSystem();\n * obj.put(id,timestamp);\n * List param_2 = obj.retrieve(start,end,granularity);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class LogSystem(object):\n\n def __init__(self):\n\n\n def put(self, id, timestamp):\n \"\"\"\n :type id: int\n :type timestamp: str\n :rtype: None\n \"\"\"\n\n\n def retrieve(self, start, end, granularity):\n \"\"\"\n :type start: str\n :type end: str\n :type granularity: str\n :rtype: List[int]\n \"\"\"\n\n\n\n# Your LogSystem object will be instantiated and called as such:\n# obj = LogSystem()\n# obj.put(id,timestamp)\n# param_2 = obj.retrieve(start,end,granularity)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class LogSystem:\n\n def __init__(self):\n\n\n def put(self, id: int, timestamp: str) -> None:\n\n\n def retrieve(self, start: str, end: str, granularity: str) -> List[int]:\n\n\n\n# Your LogSystem object will be instantiated and called as such:\n# obj = LogSystem()\n# obj.put(id,timestamp)\n# param_2 = obj.retrieve(start,end,granularity)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} LogSystem;\n\n\nLogSystem* logSystemCreate() {\n \n}\n\nvoid logSystemPut(LogSystem* obj, int id, char * timestamp) {\n \n}\n\nint* logSystemRetrieve(LogSystem* obj, char * start, char * end, char * granularity, int* retSize) {\n \n}\n\nvoid logSystemFree(LogSystem* obj) {\n \n}\n\n/**\n * Your LogSystem struct will be instantiated and called as such:\n * LogSystem* obj = logSystemCreate();\n * logSystemPut(obj, id, timestamp);\n \n * int* param_2 = logSystemRetrieve(obj, start, end, granularity, retSize);\n \n * logSystemFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class LogSystem {\n\n public LogSystem() {\n\n }\n \n public void Put(int id, string timestamp) {\n\n }\n \n public IList Retrieve(string start, string end, string granularity) {\n\n }\n}\n\n/**\n * Your LogSystem object will be instantiated and called as such:\n * LogSystem obj = new LogSystem();\n * obj.Put(id,timestamp);\n * IList param_2 = obj.Retrieve(start,end,granularity);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "\nvar LogSystem = function() {\n\n};\n\n/** \n * @param {number} id \n * @param {string} timestamp\n * @return {void}\n */\nLogSystem.prototype.put = function(id, timestamp) {\n\n};\n\n/** \n * @param {string} start \n * @param {string} end \n * @param {string} granularity\n * @return {number[]}\n */\nLogSystem.prototype.retrieve = function(start, end, granularity) {\n\n};\n\n/**\n * Your LogSystem object will be instantiated and called as such:\n * var obj = new LogSystem()\n * obj.put(id,timestamp)\n * var param_2 = obj.retrieve(start,end,granularity)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class LogSystem\n def initialize()\n\n end\n\n\n=begin\n :type id: Integer\n :type timestamp: String\n :rtype: Void\n=end\n def put(id, timestamp)\n\n end\n\n\n=begin\n :type start: String\n :type end: String\n :type granularity: String\n :rtype: Integer[]\n=end\n def retrieve(start, end, granularity)\n\n end\n\n\nend\n\n# Your LogSystem object will be instantiated and called as such:\n# obj = LogSystem.new()\n# obj.put(id, timestamp)\n# param_2 = obj.retrieve(start, end, granularity)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass LogSystem {\n\n init() {\n \n }\n \n func put(_ id: Int, _ timestamp: String) {\n \n }\n \n func retrieve(_ start: String, _ end: String, _ granularity: String) -> [Int] {\n \n }\n}\n\n/**\n * Your LogSystem object will be instantiated and called as such:\n * let obj = LogSystem()\n * obj.put(id, timestamp)\n * let ret_2: [Int] = obj.retrieve(start, end, granularity)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type LogSystem struct {\n\n}\n\n\nfunc Constructor() LogSystem {\n\n}\n\n\nfunc (this *LogSystem) Put(id int, timestamp string) {\n\n}\n\n\nfunc (this *LogSystem) Retrieve(start string, end string, granularity string) []int {\n\n}\n\n\n/**\n * Your LogSystem object will be instantiated and called as such:\n * obj := Constructor();\n * obj.Put(id,timestamp);\n * param_2 := obj.Retrieve(start,end,granularity);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class LogSystem() {\n\n def put(id: Int, timestamp: String) {\n\n }\n\n def retrieve(start: String, end: String, granularity: String): List[Int] = {\n\n }\n\n}\n\n/**\n * Your LogSystem object will be instantiated and called as such:\n * var obj = new LogSystem()\n * obj.put(id,timestamp)\n * var param_2 = obj.retrieve(start,end,granularity)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class LogSystem() {\n\n fun put(id: Int, timestamp: String) {\n\n }\n\n fun retrieve(start: String, end: String, granularity: String): List {\n\n }\n\n}\n\n/**\n * Your LogSystem object will be instantiated and called as such:\n * var obj = LogSystem()\n * obj.put(id,timestamp)\n * var param_2 = obj.retrieve(start,end,granularity)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct LogSystem {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl LogSystem {\n\n fn new() -> Self {\n\n }\n \n fn put(&self, id: i32, timestamp: String) {\n\n }\n \n fn retrieve(&self, start: String, end: String, granularity: String) -> Vec {\n\n }\n}\n\n/**\n * Your LogSystem object will be instantiated and called as such:\n * let obj = LogSystem::new();\n * obj.put(id, timestamp);\n * let ret_2: Vec = obj.retrieve(start, end, granularity);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class LogSystem {\n /**\n */\n function __construct() {\n\n }\n\n /**\n * @param Integer $id\n * @param String $timestamp\n * @return NULL\n */\n function put($id, $timestamp) {\n\n }\n\n /**\n * @param String $start\n * @param String $end\n * @param String $granularity\n * @return Integer[]\n */\n function retrieve($start, $end, $granularity) {\n\n }\n}\n\n/**\n * Your LogSystem object will be instantiated and called as such:\n * $obj = LogSystem();\n * $obj->put($id, $timestamp);\n * $ret_2 = $obj->retrieve($start, $end, $granularity);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class LogSystem {\n constructor() {\n\n }\n\n put(id: number, timestamp: string): void {\n\n }\n\n retrieve(start: string, end: string, granularity: string): number[] {\n\n }\n}\n\n/**\n * Your LogSystem object will be instantiated and called as such:\n * var obj = new LogSystem()\n * obj.put(id,timestamp)\n * var param_2 = obj.retrieve(start,end,granularity)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define log-system%\n (class object%\n (super-new)\n (init-field)\n \n ; put : exact-integer? string? -> void?\n (define/public (put id timestamp)\n\n )\n ; retrieve : string? string? string? -> (listof exact-integer?)\n (define/public (retrieve start end granularity)\n\n )))\n\n;; Your log-system% object will be instantiated and called as such:\n;; (define obj (new log-system%))\n;; (send obj put id timestamp)\n;; (define param_2 (send obj retrieve start end granularity))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0635](https://leetcode-cn.com/problems/design-log-storage-system)", "[\u8bbe\u8ba1\u65e5\u5fd7\u5b58\u50a8\u7cfb\u7edf](/solution/0600-0699/0635.Design%20Log%20Storage%20System/README.md)", "`\u8bbe\u8ba1`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0635](https://leetcode.com/problems/design-log-storage-system)", "[Design Log Storage System](/solution/0600-0699/0635.Design%20Log%20Storage%20System/README_EN.md)", "`Design`,`String`", "Medium", "\ud83d\udd12"]}, {"question_id": "0634", "frontend_question_id": "0634", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/find-the-derangement-of-an-array", "url_en": "https://leetcode.com/problems/find-the-derangement-of-an-array", "relative_path_cn": "/solution/0600-0699/0634.Find%20the%20Derangement%20of%20An%20Array/README.md", "relative_path_en": "/solution/0600-0699/0634.Find%20the%20Derangement%20of%20An%20Array/README_EN.md", "title_cn": "\u5bfb\u627e\u6570\u7ec4\u7684\u9519\u4f4d\u6392\u5217", "title_en": "Find the Derangement of An Array", "question_title_slug": "find-the-derangement-of-an-array", "content_en": "

    In combinatorial mathematics, a derangement is a permutation of the elements of a set, such that no element appears in its original position.

    \n\n

    You are given an integer n. There is originally an array consisting of n integers from 1 to n in ascending order, return the number of derangements it can generate. Since the answer may be huge, return it modulo 109 + 7.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 3\nOutput: 2\nExplanation: The original array is [1,2,3]. The two derangements are [2,3,1] and [3,1,2].\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 2\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 106
    • \n
    \n", "content_cn": "

    \u5728\u7ec4\u5408\u6570\u5b66\u4e2d\uff0c\u5982\u679c\u4e00\u4e2a\u6392\u5217\u4e2d\u6240\u6709\u5143\u7d20\u90fd\u4e0d\u5728\u539f\u5148\u7684\u4f4d\u7f6e\u4e0a\uff0c\u90a3\u4e48\u8fd9\u4e2a\u6392\u5217\u5c31\u88ab\u79f0\u4e3a\u9519\u4f4d\u6392\u5217\u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u4ece 1 \u5230 n \u5347\u5e8f\u6392\u5217\u7684\u6570\u7ec4\uff0c\u4f60\u53ef\u4ee5\u8ba1\u7b97\u51fa\u603b\u5171\u6709\u591a\u5c11\u4e2a\u4e0d\u540c\u7684\u9519\u4f4d\u6392\u5217\u5417\uff1f

    \n\n

    \u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u975e\u5e38\u5927\uff0c\u4f60\u53ea\u9700\u8981\u5c06\u7b54\u6848\u5bf9 109+7 \u53d6\u4f59\u8f93\u51fa\u5373\u53ef\u3002

    \n\n

     

    \n\n

    \u6837\u4f8b 1:

    \n\n
    \u8f93\u5165: 3\n\u8f93\u51fa: 2\n\u89e3\u91ca: \u539f\u59cb\u7684\u6570\u7ec4\u4e3a [1,2,3]\u3002\u4e24\u4e2a\u9519\u4f4d\u6392\u5217\u7684\u6570\u7ec4\u4e3a [2,3,1] \u548c [3,1,2]\u3002\n
    \n\n

     

    \n\n

    \u6ce8\u91ca:
    \nn \u7684\u8303\u56f4\u662f [1, 106]\u3002

    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findDerangement(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findDerangement(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findDerangement(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findDerangement(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findDerangement(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindDerangement(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar findDerangement = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef find_derangement(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findDerangement(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findDerangement(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findDerangement(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findDerangement(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_derangement(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function findDerangement($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findDerangement(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-derangement n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0634](https://leetcode-cn.com/problems/find-the-derangement-of-an-array)", "[\u5bfb\u627e\u6570\u7ec4\u7684\u9519\u4f4d\u6392\u5217](/solution/0600-0699/0634.Find%20the%20Derangement%20of%20An%20Array/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0634](https://leetcode.com/problems/find-the-derangement-of-an-array)", "[Find the Derangement of An Array](/solution/0600-0699/0634.Find%20the%20Derangement%20of%20An%20Array/README_EN.md)", "`Math`", "Medium", "\ud83d\udd12"]}, {"question_id": "0633", "frontend_question_id": "0633", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sum-of-square-numbers", "url_en": "https://leetcode.com/problems/sum-of-square-numbers", "relative_path_cn": "/solution/0600-0699/0633.Sum%20of%20Square%20Numbers/README.md", "relative_path_en": "/solution/0600-0699/0633.Sum%20of%20Square%20Numbers/README_EN.md", "title_cn": "\u5e73\u65b9\u6570\u4e4b\u548c", "title_en": "Sum of Square Numbers", "question_title_slug": "sum-of-square-numbers", "content_en": "

    Given a non-negative integer c, decide whether there're two integers a and b such that a2 + b2 = c.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: c = 5\nOutput: true\nExplanation: 1 * 1 + 2 * 2 = 5\n
    \n\n

    Example 2:

    \n\n
    \nInput: c = 3\nOutput: false\n
    \n\n

    Example 3:

    \n\n
    \nInput: c = 4\nOutput: true\n
    \n\n

    Example 4:

    \n\n
    \nInput: c = 2\nOutput: true\n
    \n\n

    Example 5:

    \n\n
    \nInput: c = 1\nOutput: true\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= c <= 231 - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u8d1f\u6574\u6570 c \uff0c\u4f60\u8981\u5224\u65ad\u662f\u5426\u5b58\u5728\u4e24\u4e2a\u6574\u6570 a \u548c b\uff0c\u4f7f\u5f97 a2 + b2 = c \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1ac = 5\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a1 * 1 + 2 * 2 = 5\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1ac = 3\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1ac = 4\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1ac = 2\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1ac = 1\n\u8f93\u51fa\uff1atrue
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= c <= 231 - 1
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool judgeSquareSum(int c) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean judgeSquareSum(int c) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def judgeSquareSum(self, c):\n \"\"\"\n :type c: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def judgeSquareSum(self, c: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool judgeSquareSum(int c){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool JudgeSquareSum(int c) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} c\n * @return {boolean}\n */\nvar judgeSquareSum = function(c) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} c\n# @return {Boolean}\ndef judge_square_sum(c)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func judgeSquareSum(_ c: Int) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func judgeSquareSum(c int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def judgeSquareSum(c: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun judgeSquareSum(c: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn judge_square_sum(c: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $c\n * @return Boolean\n */\n function judgeSquareSum($c) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function judgeSquareSum(c: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (judge-square-sum c)\n (-> exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0633](https://leetcode-cn.com/problems/sum-of-square-numbers)", "[\u5e73\u65b9\u6570\u4e4b\u548c](/solution/0600-0699/0633.Sum%20of%20Square%20Numbers/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0633](https://leetcode.com/problems/sum-of-square-numbers)", "[Sum of Square Numbers](/solution/0600-0699/0633.Sum%20of%20Square%20Numbers/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "0632", "frontend_question_id": "0632", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/smallest-range-covering-elements-from-k-lists", "url_en": "https://leetcode.com/problems/smallest-range-covering-elements-from-k-lists", "relative_path_cn": "/solution/0600-0699/0632.Smallest%20Range%20Covering%20Elements%20from%20K%20Lists/README.md", "relative_path_en": "/solution/0600-0699/0632.Smallest%20Range%20Covering%20Elements%20from%20K%20Lists/README_EN.md", "title_cn": "\u6700\u5c0f\u533a\u95f4", "title_en": "Smallest Range Covering Elements from K Lists", "question_title_slug": "smallest-range-covering-elements-from-k-lists", "content_en": "

    You have k lists of sorted integers in non-decreasing order. Find the smallest range that includes at least one number from each of the k lists.

    \n\n

    We define the range [a, b] is smaller than range [c, d] if b - a < d - c or a < c if b - a == d - c.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [[4,10,15,24,26],[0,9,12,20],[5,18,22,30]]\nOutput: [20,24]\nExplanation: \nList 1: [4, 10, 15, 24,26], 24 is in range [20,24].\nList 2: [0, 9, 12, 20], 20 is in range [20,24].\nList 3: [5, 18, 22, 30], 22 is in range [20,24].\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [[1,2,3],[1,2,3],[1,2,3]]\nOutput: [1,1]\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [[10,10],[11,11]]\nOutput: [10,11]\n
    \n\n

    Example 4:

    \n\n
    \nInput: nums = [[10],[11]]\nOutput: [10,11]\n
    \n\n

    Example 5:

    \n\n
    \nInput: nums = [[1],[2],[3],[4],[5],[6],[7]]\nOutput: [1,7]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • nums.length == k
    • \n\t
    • 1 <= k <= 3500
    • \n\t
    • 1 <= nums[i].length <= 50
    • \n\t
    • -105 <= nums[i][j] <= 105
    • \n\t
    • nums[i] is sorted in non-decreasing order.
    • \n
    \n", "content_cn": "

    \u4f60\u6709\u00a0k\u00a0\u4e2a \u975e\u9012\u51cf\u6392\u5217 \u7684\u6574\u6570\u5217\u8868\u3002\u627e\u5230\u4e00\u4e2a \u6700\u5c0f \u533a\u95f4\uff0c\u4f7f\u5f97\u00a0k\u00a0\u4e2a\u5217\u8868\u4e2d\u7684\u6bcf\u4e2a\u5217\u8868\u81f3\u5c11\u6709\u4e00\u4e2a\u6570\u5305\u542b\u5728\u5176\u4e2d\u3002

    \n\n

    \u6211\u4eec\u5b9a\u4e49\u5982\u679c\u00a0b-a < d-c\u00a0\u6216\u8005\u5728\u00a0b-a == d-c\u00a0\u65f6\u00a0a < c\uff0c\u5219\u533a\u95f4 [a,b] \u6bd4 [c,d] \u5c0f\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [[4,10,15,24,26], [0,9,12,20], [5,18,22,30]]\n\u8f93\u51fa\uff1a[20,24]\n\u89e3\u91ca\uff1a \n\u5217\u8868 1\uff1a[4, 10, 15, 24, 26]\uff0c24 \u5728\u533a\u95f4 [20,24] \u4e2d\u3002\n\u5217\u8868 2\uff1a[0, 9, 12, 20]\uff0c20 \u5728\u533a\u95f4 [20,24] \u4e2d\u3002\n\u5217\u8868 3\uff1a[5, 18, 22, 30]\uff0c22 \u5728\u533a\u95f4 [20,24] \u4e2d\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [[1,2,3],[1,2,3],[1,2,3]]\n\u8f93\u51fa\uff1a[1,1]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [[10,10],[11,11]]\n\u8f93\u51fa\uff1a[10,11]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [[10],[11]]\n\u8f93\u51fa\uff1a[10,11]\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [[1],[2],[3],[4],[5],[6],[7]]\n\u8f93\u51fa\uff1a[1,7]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • nums.length == k
    • \n\t
    • 1 <= k <= 3500
    • \n\t
    • 1 <= nums[i].length <= 50
    • \n\t
    • -105 <= nums[i][j] <= 105
    • \n\t
    • nums[i] \u6309\u975e\u9012\u51cf\u987a\u5e8f\u6392\u5217
    • \n
    \n", "tags_en": ["Hash Table", "Two Pointers", "String"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u53cc\u6307\u9488", "\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector smallestRange(vector>& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] smallestRange(List> nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def smallestRange(self, nums):\n \"\"\"\n :type nums: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def smallestRange(self, nums: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* smallestRange(int** nums, int numsSize, int* numsColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] SmallestRange(IList> nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} nums\n * @return {number[]}\n */\nvar smallestRange = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} nums\n# @return {Integer[]}\ndef smallest_range(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func smallestRange(_ nums: [[Int]]) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func smallestRange(nums [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def smallestRange(nums: List[List[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun smallestRange(nums: List>): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn smallest_range(nums: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $nums\n * @return Integer[]\n */\n function smallestRange($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function smallestRange(nums: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (smallest-range nums)\n (-> (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0632](https://leetcode-cn.com/problems/smallest-range-covering-elements-from-k-lists)", "[\u6700\u5c0f\u533a\u95f4](/solution/0600-0699/0632.Smallest%20Range%20Covering%20Elements%20from%20K%20Lists/README.md)", "`\u54c8\u5e0c\u8868`,`\u53cc\u6307\u9488`,`\u5b57\u7b26\u4e32`", "\u56f0\u96be", ""], "md_table_row_en": ["[0632](https://leetcode.com/problems/smallest-range-covering-elements-from-k-lists)", "[Smallest Range Covering Elements from K Lists](/solution/0600-0699/0632.Smallest%20Range%20Covering%20Elements%20from%20K%20Lists/README_EN.md)", "`Hash Table`,`Two Pointers`,`String`", "Hard", ""]}, {"question_id": "0631", "frontend_question_id": "0631", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/design-excel-sum-formula", "url_en": "https://leetcode.com/problems/design-excel-sum-formula", "relative_path_cn": "/solution/0600-0699/0631.Design%20Excel%20Sum%20Formula/README.md", "relative_path_en": "/solution/0600-0699/0631.Design%20Excel%20Sum%20Formula/README_EN.md", "title_cn": "\u8bbe\u8ba1 Excel \u6c42\u548c\u516c\u5f0f", "title_en": "Design Excel Sum Formula", "question_title_slug": "design-excel-sum-formula", "content_en": "

    Design the basic function of Excel and implement the function of the sum formula.

    \n\n

    Implement the Excel class:

    \n\n
      \n\t
    • Excel(int height, char width) Initializes the object with the height and the width of the sheet. The sheet is an integer matrix mat of size height x width with the row index in the range [1, height] and the column index in the range ['A', width]. All the values should be zero initially.
    • \n\t
    • void set(int row, char column, int val) Changes the value at mat[row][column] to be val.
    • \n\t
    • int get(int row, char column) Returns the value at mat[row][column].
    • \n\t
    • int sum(int row, char column, List<String> numbers) Sets the value at mat[row][column] to be the sum of cells represented by numbers and returns the value at mat[row][column]. This sum formula should exist until this cell is overlapped by another value or another sum formula. numbers[i] could be on the format:\n\t
        \n\t\t
      • "ColRow" that represents a single cell.\n\t\t
          \n\t\t\t
        • For example, "F7" represents the cell mat[7]['F'].
        • \n\t\t
        \n\t\t
      • \n\t\t
      • "ColRow1:ColRow2" that represents a range of cells. The range will always be a rectangle where "ColRow1" represent the position of the top-left cell, and "ColRow2" represents the position of the bottom-right cell.\n\t\t
          \n\t\t\t
        • For example, "B3:F7" represents the cells mat[i][j] for 3 <= i <= 7 and 'B' <= j <= 'F'.
        • \n\t\t
        \n\t\t
      • \n\t
      \n\t
    • \n
    \n\n

    Note: You could assume that there will not be any circular sum reference.

    \n\n
      \n\t
    • For example, mat[1]['A'] == sum(1, "B") and mat[1]['B'] == sum(1, "A").
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["Excel", "set", "sum", "set", "get"]\n[[3, "C"], [1, "A", 2], [3, "C", ["A1", "A1:B2"]], [2, "B", 2], [3, "C"]]\nOutput\n[null, null, 4, null, 6]\n\nExplanation\nExcel excel = new Excel(3, "C");\n // construct a 3*3 2D array with all zero.\n //   A B C\n // 1 0 0 0\n // 2 0 0 0\n // 3 0 0 0\nexcel.set(1, "A", 2);\n // set mat[2]["B"] to be 2.\n //   A B C\n // 1 2 0 0\n // 2 0 0 0\n // 3 0 0 0\nexcel.sum(3, "C", ["A1", "A1:B2"]); // return 4\n // set mat[3]["C"] to be the sum of value at mat[1]["A"] and the values sum of the rectangle range whose top-left cell is mat[1]["A"] and bottom-right cell is mat[2]["B"].\n //   A B C\n // 1 2 0 0\n // 2 0 0 0\n // 3 0 0 4\nexcel.set(2, "B", 2);\n // set mat[2]["B"] to be 2. Note mat[3]["C"] should also be changed.\n //   A B C\n // 1 2 0 0\n // 2 0 2 0\n // 3 0 0 6\nexcel.get(3, "C"); // return 6\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= height <= 26
    • \n\t
    • 'A' <= width <= 'Z'
    • \n\t
    • 1 <= row <= height
    • \n\t
    • 'A' <= column <= width
    • \n\t
    • -100 <= val <= 100
    • \n\t
    • 1 <= numbers.length <= 5
    • \n\t
    • numbers[i] has the format "ColRow" or "ColRow1:ColRow2".
    • \n\t
    • At most 100 calls will be made to set, get, and sum.
    • \n
    \n", "content_cn": "

    \u4f60\u7684\u4efb\u52a1\u662f\u5b9e\u73b0 Excel \u7684\u6c42\u548c\u529f\u80fd\uff0c\u5177\u4f53\u7684\u64cd\u4f5c\u5982\u4e0b\uff1a

    \n\n

    Excel(int H, char W): \u8fd9\u662f\u4e00\u4e2a\u6784\u9020\u51fd\u6570\uff0c\u8f93\u5165\u8868\u660e\u4e86 Excel \u7684\u9ad8\u5ea6\u548c\u5bbd\u5ea6\u3002H \u662f\u4e00\u4e2a\u6b63\u6574\u6570\uff0c\u8303\u56f4\u4ece 1 \u5230 26\uff0c\u4ee3\u8868\u9ad8\u5ea6\u3002W \u662f\u4e00\u4e2a\u5b57\u7b26\uff0c\u8303\u56f4\u4ece 'A' \u5230 'Z'\uff0c\u5bbd\u5ea6\u7b49\u4e8e\u4ece 'A' \u5230 W \u7684\u5b57\u6bcd\u4e2a\u6570\u3002Excel \u8868\u683c\u662f\u4e00\u4e2a\u9ad8\u5ea6 * \u5bbd\u5ea6\u7684\u4e8c\u7ef4\u6574\u6570\u6570\u7ec4\uff0c\u6570\u7ec4\u4e2d\u5143\u7d20\u521d\u59cb\u5316\u4e3a 0\u3002\u7b2c\u4e00\u884c\u4e0b\u6807\u4ece 1 \u5f00\u59cb\uff0c\u7b2c\u4e00\u5217\u4e0b\u6807\u4ece 'A' \u5f00\u59cb\u3002

    \n\n

     

    \n\n

    void Set(int row, char column, int val): \u8bbe\u7f6e C(row, column) \u4e2d\u7684\u503c\u4e3a val\u3002

    \n\n

     

    \n\n

    int Get(int row, char column): \u8fd4\u56de C(row, column) \u4e2d\u7684\u503c\u3002

    \n\n

     

    \n\n

    int Sum(int row, char column, List of Strings : numbers): \u8fd9\u4e2a\u51fd\u6570\u4f1a\u5c06\u8ba1\u7b97\u7684\u7ed3\u679c\u653e\u5165 C(row, column) \u4e2d\uff0c\u8ba1\u7b97\u7684\u7ed3\u679c\u7b49\u4e8e\u5728 numbers \u4e2d\u4ee3\u8868\u7684\u6240\u6709\u5143\u7d20\u4e4b\u548c\uff0c\u8fd9\u4e2a\u51fd\u6570\u540c\u65f6\u4e5f\u4f1a\u5c06\u8fd9\u4e2a\u7ed3\u679c\u8fd4\u56de\u3002\u6c42\u548c\u516c\u5f0f\u4f1a\u4e00\u76f4\u8ba1\u7b97\u66f4\u65b0\u7ed3\u679c\u76f4\u5230\u8fd9\u4e2a\u516c\u5f0f\u88ab\u5176\u4ed6\u7684\u503c\u6216\u8005\u516c\u5f0f\u8986\u76d6\u3002

    \n\n

    numbers \u662f\u82e5\u5e72\u5b57\u7b26\u4e32\u7684\u96c6\u5408\uff0c\u6bcf\u4e2a\u5b57\u7b26\u4e32\u4ee3\u8868\u5355\u4e2a\u4f4d\u7f6e\u6216\u4e00\u4e2a\u533a\u95f4\u3002\u5982\u679c\u8fd9\u4e2a\u5b57\u7b26\u4e32\u8868\u793a\u5355\u4e2a\u4f4d\u7f6e\uff0c\u5b83\u7684\u683c\u5f0f\u5982\u4e0b\uff1aColRow\uff0c\u4f8b\u5982 "F7" \u8868\u793a\u4f4d\u7f6e (7, F) \u3002\u5982\u679c\u8fd9\u4e2a\u5b57\u7b26\u4e32\u8868\u793a\u4e00\u4e2a\u533a\u95f4\uff0c\u5b83\u7684\u683c\u5f0f\u5982\u4e0b\uff1aColRow1:ColRow2\u3002\u533a\u95f4\u5c31\u662f\u5de6\u4e0a\u89d2\u4e3a ColRow1 \u53f3\u4e0b\u89d2\u4e3a ColRow2 \u7684\u957f\u65b9\u5f62\u3002

    \n\n

     

    \n\n

    \u6837\u4f8b 1 \uff1a

    \n\n

     

    \n\n
    Excel(3,"C"); \n// \u6784\u9020\u4e00\u4e2a 3*3 \u7684\u4e8c\u7ef4\u6570\u7ec4\uff0c\u521d\u59cb\u5316\u5168\u662f 0\u3002\n//   A B C\n// 1 0 0 0\n// 2 0 0 0\n// 3 0 0 0\n\nSet(1, "A", 2);\n// \u8bbe\u7f6e C(1,"A") \u4e3a 2\u3002\n//   A B C\n// 1 2 0 0\n// 2 0 0 0\n// 3 0 0 0\n\nSum(3, "C", ["A1", "A1:B2"]);\n// \u5c06 C(3,"C") \u7684\u503c\u8bbe\u4e3a C(1,"A") \u5355\u70b9\uff0c\u5de6\u4e0a\u89d2\u4e3a C(1,"A") \u53f3\u4e0b\u89d2\u4e3a C(2,"B") \u7684\u957f\u65b9\u5f62\uff0c\u6240\u6709\u5143\u7d20\u4e4b\u548c\u3002\u8fd4\u56de\u503c 4\u3002 \n//   A B C\n// 1 2 0 0\n// 2 0 0 0\n// 3 0 0 4\n\nSet(2, "B", 2);\n// \u5c06 C(2,"B") \u8bbe\u4e3a 2\u3002 \u6ce8\u610f C(3, "C") \u7684\u503c\u4e5f\u540c\u65f6\u6539\u53d8\u3002\n//   A B C\n// 1 2 0 0\n// 2 0 2 0\n// 3 0 0 6\n
    \n\n

     

    \n\n

    \u6ce8\u91ca \uff1a

    \n\n
      \n\t
    1. \u4f60\u53ef\u4ee5\u8ba4\u4e3a\u4e0d\u4f1a\u51fa\u73b0\u5faa\u73af\u6c42\u548c\u7684\u5b9a\u4e49\uff0c\u6bd4\u5982\u8bf4\uff1a A1 = sum(B1) \uff0cB1 = sum(A1)\u3002
    2. \n\t
    3. \u6d4b\u8bd5\u6570\u636e\u4e2d\uff0c\u5b57\u6bcd\u8868\u793a\u7528\u53cc\u5f15\u53f7\u3002
    4. \n\t
    5. \u8bf7\u8bb0\u4f4f\u6e05\u96f6 Excel \u7c7b\u4e2d\u7684\u53d8\u91cf\uff0c\u56e0\u4e3a\u9759\u6001\u53d8\u91cf\u3001\u7c7b\u53d8\u91cf\u4f1a\u5728\u591a\u7ec4\u6d4b\u8bd5\u6570\u636e\u4e2d\u4fdd\u5b58\u4e4b\u524d\u7ed3\u679c\u3002\u8be6\u60c5\u8bf7\u770b\u8fd9\u91cc\u3002
    6. \n
    \n\n

     

    \n", "tags_en": ["Design"], "tags_cn": ["\u8bbe\u8ba1"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Excel {\npublic:\n Excel(int height, char width) {\n\n }\n \n void set(int row, char column, int val) {\n\n }\n \n int get(int row, char column) {\n\n }\n \n int sum(int row, char column, vector numbers) {\n\n }\n};\n\n/**\n * Your Excel object will be instantiated and called as such:\n * Excel* obj = new Excel(height, width);\n * obj->set(row,column,val);\n * int param_2 = obj->get(row,column);\n * int param_3 = obj->sum(row,column,numbers);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Excel {\n\n public Excel(int height, char width) {\n\n }\n \n public void set(int row, char column, int val) {\n\n }\n \n public int get(int row, char column) {\n\n }\n \n public int sum(int row, char column, String[] numbers) {\n\n }\n}\n\n/**\n * Your Excel object will be instantiated and called as such:\n * Excel obj = new Excel(height, width);\n * obj.set(row,column,val);\n * int param_2 = obj.get(row,column);\n * int param_3 = obj.sum(row,column,numbers);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Excel(object):\n\n def __init__(self, height, width):\n \"\"\"\n :type height: int\n :type width: str\n \"\"\"\n\n\n def set(self, row, column, val):\n \"\"\"\n :type row: int\n :type column: str\n :type val: int\n :rtype: None\n \"\"\"\n\n\n def get(self, row, column):\n \"\"\"\n :type row: int\n :type column: str\n :rtype: int\n \"\"\"\n\n\n def sum(self, row, column, numbers):\n \"\"\"\n :type row: int\n :type column: str\n :type numbers: List[str]\n :rtype: int\n \"\"\"\n\n\n\n# Your Excel object will be instantiated and called as such:\n# obj = Excel(height, width)\n# obj.set(row,column,val)\n# param_2 = obj.get(row,column)\n# param_3 = obj.sum(row,column,numbers)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Excel:\n\n def __init__(self, height: int, width: str):\n\n\n def set(self, row: int, column: str, val: int) -> None:\n\n\n def get(self, row: int, column: str) -> int:\n\n\n def sum(self, row: int, column: str, numbers: List[str]) -> int:\n\n\n\n# Your Excel object will be instantiated and called as such:\n# obj = Excel(height, width)\n# obj.set(row,column,val)\n# param_2 = obj.get(row,column)\n# param_3 = obj.sum(row,column,numbers)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} Excel;\n\n\nExcel* excelCreate(int height, char width) {\n \n}\n\nvoid excelSet(Excel* obj, int row, char column, int val) {\n \n}\n\nint excelGet(Excel* obj, int row, char column) {\n \n}\n\nint excelSum(Excel* obj, int row, char column, char ** numbers, int numbersSize) {\n \n}\n\nvoid excelFree(Excel* obj) {\n \n}\n\n/**\n * Your Excel struct will be instantiated and called as such:\n * Excel* obj = excelCreate(height, width);\n * excelSet(obj, row, column, val);\n \n * int param_2 = excelGet(obj, row, column);\n \n * int param_3 = excelSum(obj, row, column, numbers, numbersSize);\n \n * excelFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Excel {\n\n public Excel(int height, char width) {\n\n }\n \n public void Set(int row, char column, int val) {\n\n }\n \n public int Get(int row, char column) {\n\n }\n \n public int Sum(int row, char column, string[] numbers) {\n\n }\n}\n\n/**\n * Your Excel object will be instantiated and called as such:\n * Excel obj = new Excel(height, width);\n * obj.Set(row,column,val);\n * int param_2 = obj.Get(row,column);\n * int param_3 = obj.Sum(row,column,numbers);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} height\n * @param {character} width\n */\nvar Excel = function(height, width) {\n\n};\n\n/** \n * @param {number} row \n * @param {character} column \n * @param {number} val\n * @return {void}\n */\nExcel.prototype.set = function(row, column, val) {\n\n};\n\n/** \n * @param {number} row \n * @param {character} column\n * @return {number}\n */\nExcel.prototype.get = function(row, column) {\n\n};\n\n/** \n * @param {number} row \n * @param {character} column \n * @param {string[]} numbers\n * @return {number}\n */\nExcel.prototype.sum = function(row, column, numbers) {\n\n};\n\n/**\n * Your Excel object will be instantiated and called as such:\n * var obj = new Excel(height, width)\n * obj.set(row,column,val)\n * var param_2 = obj.get(row,column)\n * var param_3 = obj.sum(row,column,numbers)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class Excel\n\n=begin\n :type height: Integer\n :type width: Character\n=end\n def initialize(height, width)\n\n end\n\n\n=begin\n :type row: Integer\n :type column: Character\n :type val: Integer\n :rtype: Void\n=end\n def set(row, column, val)\n\n end\n\n\n=begin\n :type row: Integer\n :type column: Character\n :rtype: Integer\n=end\n def get(row, column)\n\n end\n\n\n=begin\n :type row: Integer\n :type column: Character\n :type numbers: String[]\n :rtype: Integer\n=end\n def sum(row, column, numbers)\n\n end\n\n\nend\n\n# Your Excel object will be instantiated and called as such:\n# obj = Excel.new(height, width)\n# obj.set(row, column, val)\n# param_2 = obj.get(row, column)\n# param_3 = obj.sum(row, column, numbers)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass Excel {\n\n init(_ height: Int, _ width: Character) {\n\n }\n \n func set(_ row: Int, _ column: Character, _ val: Int) {\n\n }\n \n func get(_ row: Int, _ column: Character) -> Int {\n\n }\n \n func sum(_ row: Int, _ column: Character, _ numbers: [String]) -> Int {\n\n }\n}\n\n/**\n * Your Excel object will be instantiated and called as such:\n * let obj = Excel(height, width)\n * obj.set(row, column, val)\n * let ret_2: Int = obj.get(row, column)\n * let ret_3: Int = obj.sum(row, column, numbers)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type Excel struct {\n\n}\n\n\nfunc Constructor(height int, width byte) Excel {\n\n}\n\n\nfunc (this *Excel) Set(row int, column byte, val int) {\n\n}\n\n\nfunc (this *Excel) Get(row int, column byte) int {\n\n}\n\n\nfunc (this *Excel) Sum(row int, column byte, numbers []string) int {\n\n}\n\n\n/**\n * Your Excel object will be instantiated and called as such:\n * obj := Constructor(height, width);\n * obj.Set(row,column,val);\n * param_2 := obj.Get(row,column);\n * param_3 := obj.Sum(row,column,numbers);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class Excel(_height: Int, _width: Char) {\n\n def set(row: Int, column: Char, `val`: Int) {\n\n }\n\n def get(row: Int, column: Char): Int = {\n\n }\n\n def sum(row: Int, column: Char, numbers: Array[String]): Int = {\n\n }\n\n}\n\n/**\n * Your Excel object will be instantiated and called as such:\n * var obj = new Excel(height, width)\n * obj.set(row,column,`val`)\n * var param_2 = obj.get(row,column)\n * var param_3 = obj.sum(row,column,numbers)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Excel(height: Int, width: Char) {\n\n fun set(row: Int, column: Char, `val`: Int) {\n\n }\n\n fun get(row: Int, column: Char): Int {\n\n }\n\n fun sum(row: Int, column: Char, numbers: Array): Int {\n\n }\n\n}\n\n/**\n * Your Excel object will be instantiated and called as such:\n * var obj = Excel(height, width)\n * obj.set(row,column,`val`)\n * var param_2 = obj.get(row,column)\n * var param_3 = obj.sum(row,column,numbers)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct Excel {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl Excel {\n\n fn new(height: i32, width: char) -> Self {\n\n }\n \n fn set(&self, row: i32, column: char, val: i32) {\n\n }\n \n fn get(&self, row: i32, column: char) -> i32 {\n\n }\n \n fn sum(&self, row: i32, column: char, numbers: Vec) -> i32 {\n\n }\n}\n\n/**\n * Your Excel object will be instantiated and called as such:\n * let obj = Excel::new(height, width);\n * obj.set(row, column, val);\n * let ret_2: i32 = obj.get(row, column);\n * let ret_3: i32 = obj.sum(row, column, numbers);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Excel {\n /**\n * @param Integer $height\n * @param String $width\n */\n function __construct($height, $width) {\n\n }\n\n /**\n * @param Integer $row\n * @param String $column\n * @param Integer $val\n * @return NULL\n */\n function set($row, $column, $val) {\n\n }\n\n /**\n * @param Integer $row\n * @param String $column\n * @return Integer\n */\n function get($row, $column) {\n\n }\n\n /**\n * @param Integer $row\n * @param String $column\n * @param String[] $numbers\n * @return Integer\n */\n function sum($row, $column, $numbers) {\n\n }\n}\n\n/**\n * Your Excel object will be instantiated and called as such:\n * $obj = Excel($height, $width);\n * $obj->set($row, $column, $val);\n * $ret_2 = $obj->get($row, $column);\n * $ret_3 = $obj->sum($row, $column, $numbers);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class Excel {\n constructor(height: number, width: string) {\n\n }\n\n set(row: number, column: string, val: number): void {\n\n }\n\n get(row: number, column: string): number {\n\n }\n\n sum(row: number, column: string, numbers: string[]): number {\n\n }\n}\n\n/**\n * Your Excel object will be instantiated and called as such:\n * var obj = new Excel(height, width)\n * obj.set(row,column,val)\n * var param_2 = obj.get(row,column)\n * var param_3 = obj.sum(row,column,numbers)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define excel%\n (class object%\n (super-new)\n\n ; height : exact-integer?\n\n ; width : char?\n (init-field\n height\n width)\n \n ; set : exact-integer? char? exact-integer? -> void?\n (define/public (set row column val)\n\n )\n ; get : exact-integer? char? -> exact-integer?\n (define/public (get row column)\n\n )\n ; sum : exact-integer? char? (listof string?) -> exact-integer?\n (define/public (sum row column numbers)\n\n )))\n\n;; Your excel% object will be instantiated and called as such:\n;; (define obj (new excel% [height height] [width width]))\n;; (send obj set row column val)\n;; (define param_2 (send obj get row column))\n;; (define param_3 (send obj sum row column numbers))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0631](https://leetcode-cn.com/problems/design-excel-sum-formula)", "[\u8bbe\u8ba1 Excel \u6c42\u548c\u516c\u5f0f](/solution/0600-0699/0631.Design%20Excel%20Sum%20Formula/README.md)", "`\u8bbe\u8ba1`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0631](https://leetcode.com/problems/design-excel-sum-formula)", "[Design Excel Sum Formula](/solution/0600-0699/0631.Design%20Excel%20Sum%20Formula/README_EN.md)", "`Design`", "Hard", "\ud83d\udd12"]}, {"question_id": "0630", "frontend_question_id": "0630", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/course-schedule-iii", "url_en": "https://leetcode.com/problems/course-schedule-iii", "relative_path_cn": "/solution/0600-0699/0630.Course%20Schedule%20III/README.md", "relative_path_en": "/solution/0600-0699/0630.Course%20Schedule%20III/README_EN.md", "title_cn": "\u8bfe\u7a0b\u8868 III", "title_en": "Course Schedule III", "question_title_slug": "course-schedule-iii", "content_en": "

    There are n different online courses numbered from 1 to n. You are given an array courses where courses[i] = [durationi, lastDayi] indicate that the ith course should be taken continuously for durationi days and must be finished before or on lastDayi.

    \n\n

    You will start on the 1st day and you cannot take two or more courses simultaneously.

    \n\n

    Return the maximum number of courses that you can take.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: courses = [[100,200],[200,1300],[1000,1250],[2000,3200]]\nOutput: 3\nExplanation: \nThere are totally 4 courses, but you can take 3 courses at most:\nFirst, take the 1st course, it costs 100 days so you will finish it on the 100th day, and ready to take the next course on the 101st day.\nSecond, take the 3rd course, it costs 1000 days so you will finish it on the 1100th day, and ready to take the next course on the 1101st day. \nThird, take the 2nd course, it costs 200 days so you will finish it on the 1300th day. \nThe 4th course cannot be taken now, since you will finish it on the 3300th day, which exceeds the closed date.\n
    \n\n

    Example 2:

    \n\n
    \nInput: courses = [[1,2]]\nOutput: 1\n
    \n\n

    Example 3:

    \n\n
    \nInput: courses = [[3,2],[4,3]]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= courses.length <= 104
    • \n\t
    • 1 <= durationi, lastDayi <= 104
    • \n
    \n", "content_cn": "

    \u8fd9\u91cc\u6709 n \u95e8\u4e0d\u540c\u7684\u5728\u7ebf\u8bfe\u7a0b\uff0c\u4ed6\u4eec\u6309\u4ece 1 \u5230 n \u7f16\u53f7\u3002\u6bcf\u4e00\u95e8\u8bfe\u7a0b\u6709\u4e00\u5b9a\u7684\u6301\u7eed\u4e0a\u8bfe\u65f6\u95f4\uff08\u8bfe\u7a0b\u65f6\u95f4\uff09t \u4ee5\u53ca\u5173\u95ed\u65f6\u95f4\u7b2c d \u5929\u3002\u4e00\u95e8\u8bfe\u8981\u6301\u7eed\u5b66\u4e60 t \u5929\u76f4\u5230\u7b2c d \u5929\u65f6\u8981\u5b8c\u6210\uff0c\u4f60\u5c06\u4f1a\u4ece\u7b2c 1 \u5929\u5f00\u59cb\u3002

    \n\n

    \u7ed9\u51fa n \u4e2a\u5728\u7ebf\u8bfe\u7a0b\u7528 (t, d) \u5bf9\u8868\u793a\u3002\u4f60\u7684\u4efb\u52a1\u662f\u627e\u51fa\u6700\u591a\u53ef\u4ee5\u4fee\u51e0\u95e8\u8bfe\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165: [[100, 200], [200, 1300], [1000, 1250], [2000, 3200]]\n\u8f93\u51fa: 3\n\u89e3\u91ca: \n\u8fd9\u91cc\u4e00\u5171\u6709 4 \u95e8\u8bfe\u7a0b, \u4f46\u662f\u4f60\u6700\u591a\u53ef\u4ee5\u4fee 3 \u95e8:\n\u9996\u5148, \u4fee\u7b2c\u4e00\u95e8\u8bfe\u65f6, \u5b83\u8981\u8017\u8d39 100 \u5929\uff0c\u4f60\u4f1a\u5728\u7b2c 100 \u5929\u5b8c\u6210, \u5728\u7b2c 101 \u5929\u51c6\u5907\u4e0b\u95e8\u8bfe\u3002\n\u7b2c\u4e8c, \u4fee\u7b2c\u4e09\u95e8\u8bfe\u65f6, \u5b83\u4f1a\u8017\u8d39 1000 \u5929\uff0c\u6240\u4ee5\u4f60\u5c06\u5728\u7b2c 1100 \u5929\u7684\u65f6\u5019\u5b8c\u6210\u5b83, \u4ee5\u53ca\u5728\u7b2c 1101 \u5929\u5f00\u59cb\u51c6\u5907\u4e0b\u95e8\u8bfe\u7a0b\u3002\n\u7b2c\u4e09, \u4fee\u7b2c\u4e8c\u95e8\u8bfe\u65f6, \u5b83\u4f1a\u8017\u65f6 200 \u5929\uff0c\u6240\u4ee5\u4f60\u5c06\u4f1a\u5728\u7b2c 1300 \u5929\u65f6\u5b8c\u6210\u5b83\u3002\n\u7b2c\u56db\u95e8\u8bfe\u73b0\u5728\u4e0d\u80fd\u4fee\uff0c\u56e0\u4e3a\u4f60\u5c06\u4f1a\u5728\u7b2c 3300 \u5929\u5b8c\u6210\u5b83\uff0c\u8fd9\u5df2\u7ecf\u8d85\u51fa\u4e86\u5173\u95ed\u65e5\u671f\u3002
    \n\n

     

    \n\n

    \u63d0\u793a:

    \n\n
      \n\t
    1. \u6574\u6570 1 <= d, t, n <= 10,000 \u3002
    2. \n\t
    3. \u4f60\u4e0d\u80fd\u540c\u65f6\u4fee\u4e24\u95e8\u8bfe\u7a0b\u3002
    4. \n
    \n\n

     

    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int scheduleCourse(vector>& courses) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int scheduleCourse(int[][] courses) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def scheduleCourse(self, courses):\n \"\"\"\n :type courses: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def scheduleCourse(self, courses: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint scheduleCourse(int** courses, int coursesSize, int* coursesColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ScheduleCourse(int[][] courses) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} courses\n * @return {number}\n */\nvar scheduleCourse = function(courses) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} courses\n# @return {Integer}\ndef schedule_course(courses)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func scheduleCourse(_ courses: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func scheduleCourse(courses [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def scheduleCourse(courses: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun scheduleCourse(courses: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn schedule_course(courses: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $courses\n * @return Integer\n */\n function scheduleCourse($courses) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function scheduleCourse(courses: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (schedule-course courses)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0630](https://leetcode-cn.com/problems/course-schedule-iii)", "[\u8bfe\u7a0b\u8868 III](/solution/0600-0699/0630.Course%20Schedule%20III/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[0630](https://leetcode.com/problems/course-schedule-iii)", "[Course Schedule III](/solution/0600-0699/0630.Course%20Schedule%20III/README_EN.md)", "`Greedy`", "Hard", ""]}, {"question_id": "0629", "frontend_question_id": "0629", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/k-inverse-pairs-array", "url_en": "https://leetcode.com/problems/k-inverse-pairs-array", "relative_path_cn": "/solution/0600-0699/0629.K%20Inverse%20Pairs%20Array/README.md", "relative_path_en": "/solution/0600-0699/0629.K%20Inverse%20Pairs%20Array/README_EN.md", "title_cn": "K\u4e2a\u9006\u5e8f\u5bf9\u6570\u7ec4", "title_en": "K Inverse Pairs Array", "question_title_slug": "k-inverse-pairs-array", "content_en": "

    For an integer array nums, an inverse pair is a pair of integers [i, j] where 0 <= i < j < nums.length and nums[i] > nums[j].

    \n\n

    Given two integers n and k, return the number of different arrays consist of numbers from 1 to n such that there are exactly k inverse pairs. Since the answer can be huge, return it modulo 109 + 7.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 3, k = 0\nOutput: 1\nExplanation: Only the array [1,2,3] which consists of numbers from 1 to 3 has exactly 0 inverse pairs.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 3, k = 1\nOutput: 2\nExplanation: The array [1,3,2] and [2,1,3] have exactly 1 inverse pair.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 1000
    • \n\t
    • 0 <= k <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u51fa\u4e24\u4e2a\u6574\u6570 n \u548c k\uff0c\u627e\u51fa\u6240\u6709\u5305\u542b\u4ece 1 \u5230 n \u7684\u6570\u5b57\uff0c\u4e14\u6070\u597d\u62e5\u6709 k \u4e2a\u9006\u5e8f\u5bf9\u7684\u4e0d\u540c\u7684\u6570\u7ec4\u7684\u4e2a\u6570\u3002

    \n\n

    \u9006\u5e8f\u5bf9\u7684\u5b9a\u4e49\u5982\u4e0b\uff1a\u5bf9\u4e8e\u6570\u7ec4\u7684\u7b2ci\u4e2a\u548c\u7b2c j\u4e2a\u5143\u7d20\uff0c\u5982\u679c\u6ee1i < j\u4e14 a[i] > a[j]\uff0c\u5219\u5176\u4e3a\u4e00\u4e2a\u9006\u5e8f\u5bf9\uff1b\u5426\u5219\u4e0d\u662f\u3002

    \n\n

    \u7531\u4e8e\u7b54\u6848\u53ef\u80fd\u5f88\u5927\uff0c\u53ea\u9700\u8981\u8fd4\u56de \u7b54\u6848 mod 109 + 7 \u7684\u503c\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: n = 3, k = 0\n\u8f93\u51fa: 1\n\u89e3\u91ca: \n\u53ea\u6709\u6570\u7ec4 [1,2,3] \u5305\u542b\u4e86\u4ece1\u52303\u7684\u6574\u6570\u5e76\u4e14\u6b63\u597d\u62e5\u6709 0 \u4e2a\u9006\u5e8f\u5bf9\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: n = 3, k = 1\n\u8f93\u51fa: 2\n\u89e3\u91ca: \n\u6570\u7ec4 [1,3,2] \u548c [2,1,3] \u90fd\u6709 1 \u4e2a\u9006\u5e8f\u5bf9\u3002\n
    \n\n

    \u8bf4\u660e:

    \n\n
      \n\t
    1.  n \u7684\u8303\u56f4\u662f [1, 1000] \u5e76\u4e14 k \u7684\u8303\u56f4\u662f [0, 1000]\u3002
    2. \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int kInversePairs(int n, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int kInversePairs(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def kInversePairs(self, n, k):\n \"\"\"\n :type n: int\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def kInversePairs(self, n: int, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint kInversePairs(int n, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int KInversePairs(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} k\n * @return {number}\n */\nvar kInversePairs = function(n, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} k\n# @return {Integer}\ndef k_inverse_pairs(n, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func kInversePairs(_ n: Int, _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func kInversePairs(n int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def kInversePairs(n: Int, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun kInversePairs(n: Int, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn k_inverse_pairs(n: i32, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $k\n * @return Integer\n */\n function kInversePairs($n, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function kInversePairs(n: number, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (k-inverse-pairs n k)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0629](https://leetcode-cn.com/problems/k-inverse-pairs-array)", "[K\u4e2a\u9006\u5e8f\u5bf9\u6570\u7ec4](/solution/0600-0699/0629.K%20Inverse%20Pairs%20Array/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0629](https://leetcode.com/problems/k-inverse-pairs-array)", "[K Inverse Pairs Array](/solution/0600-0699/0629.K%20Inverse%20Pairs%20Array/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "0628", "frontend_question_id": "0628", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-product-of-three-numbers", "url_en": "https://leetcode.com/problems/maximum-product-of-three-numbers", "relative_path_cn": "/solution/0600-0699/0628.Maximum%20Product%20of%20Three%20Numbers/README.md", "relative_path_en": "/solution/0600-0699/0628.Maximum%20Product%20of%20Three%20Numbers/README_EN.md", "title_cn": "\u4e09\u4e2a\u6570\u7684\u6700\u5927\u4e58\u79ef", "title_en": "Maximum Product of Three Numbers", "question_title_slug": "maximum-product-of-three-numbers", "content_en": "

    Given an integer array nums, find three numbers whose product is maximum and return the maximum product.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [1,2,3]\nOutput: 6\n

    Example 2:

    \n
    Input: nums = [1,2,3,4]\nOutput: 24\n

    Example 3:

    \n
    Input: nums = [-1,-2,-3]\nOutput: -6\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 3 <= nums.length <= 104
    • \n\t
    • -1000 <= nums[i] <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u578b\u6570\u7ec4 nums \uff0c\u5728\u6570\u7ec4\u4e2d\u627e\u51fa\u7531\u4e09\u4e2a\u6570\u7ec4\u6210\u7684\u6700\u5927\u4e58\u79ef\uff0c\u5e76\u8f93\u51fa\u8fd9\u4e2a\u4e58\u79ef\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,3]\n\u8f93\u51fa\uff1a6\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,3,4]\n\u8f93\u51fa\uff1a24\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [-1,-2,-3]\n\u8f93\u51fa\uff1a-6\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 3 <= nums.length <=\u00a0104
    • \n\t
    • -1000 <= nums[i] <= 1000
    • \n
    \n", "tags_en": ["Array", "Math"], "tags_cn": ["\u6570\u7ec4", "\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maximumProduct(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maximumProduct(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximumProduct(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximumProduct(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maximumProduct(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaximumProduct(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar maximumProduct = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef maximum_product(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximumProduct(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximumProduct(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximumProduct(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximumProduct(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximum_product(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function maximumProduct($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximumProduct(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximum-product nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0628](https://leetcode-cn.com/problems/maximum-product-of-three-numbers)", "[\u4e09\u4e2a\u6570\u7684\u6700\u5927\u4e58\u79ef](/solution/0600-0699/0628.Maximum%20Product%20of%20Three%20Numbers/README.md)", "`\u6570\u7ec4`,`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0628](https://leetcode.com/problems/maximum-product-of-three-numbers)", "[Maximum Product of Three Numbers](/solution/0600-0699/0628.Maximum%20Product%20of%20Three%20Numbers/README_EN.md)", "`Array`,`Math`", "Easy", ""]}, {"question_id": "0627", "frontend_question_id": "0627", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/swap-salary", "url_en": "https://leetcode.com/problems/swap-salary", "relative_path_cn": "/solution/0600-0699/0627.Swap%20Salary/README.md", "relative_path_en": "/solution/0600-0699/0627.Swap%20Salary/README_EN.md", "title_cn": "\u53d8\u66f4\u6027\u522b", "title_en": "Swap Salary", "question_title_slug": "swap-salary", "content_en": "

    Table: Salary

    \n\n
    \n+-------------+----------+\n| Column Name | Type     |\n+-------------+----------+\n| id          | int      |\n| name        | varchar  |\n| sex         | ENUM     |\n| salary      | int      |\n+-------------+----------+\nid is the primary key for this table.\nThe sex column is ENUM value of type ('m', 'f').\nThe table contains information about an employee.\n
    \n\n

     

    \n\n

    Write an SQL query to swap all 'f' and 'm' values (i.e., change all 'f' values to 'm' and vice versa) with a single update statement and no intermediate temp table(s).

    \n\n

    Note that you must write a single update statement, DO NOT write any select statement for this problem.

    \n\n

    The query result format is in the following example:

    \n\n

     

    \n\n
    \nSalary table:\n+----+------+-----+--------+\n| id | name | sex | salary |\n+----+------+-----+--------+\n| 1  | A    | m   | 2500   |\n| 2  | B    | f   | 1500   |\n| 3  | C    | m   | 5500   |\n| 4  | D    | f   | 500    |\n+----+------+-----+--------+\n\nResult table:\n+----+------+-----+--------+\n| id | name | sex | salary |\n+----+------+-----+--------+\n| 1  | A    | f   | 2500   |\n| 2  | B    | m   | 1500   |\n| 3  | C    | f   | 5500   |\n| 4  | D    | m   | 500    |\n+----+------+-----+--------+\n(1, A) and (3, C) were changed from 'm' to 'f'.\n(2, B) and (4, D) were changed from 'f' to 'm'.\n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a salary \u8868\uff0c\u5982\u4e0b\u6240\u793a\uff0c\u6709 m = \u7537\u6027 \u548c f = \u5973\u6027 \u7684\u503c\u3002\u4ea4\u6362\u6240\u6709\u7684 f \u548c m \u503c\uff08\u4f8b\u5982\uff0c\u5c06\u6240\u6709 f \u503c\u66f4\u6539\u4e3a m\uff0c\u53cd\u4e4b\u4ea6\u7136\uff09\u3002\u8981\u6c42\u53ea\u4f7f\u7528\u4e00\u4e2a\u66f4\u65b0\uff08Update\uff09\u8bed\u53e5\uff0c\u5e76\u4e14\u6ca1\u6709\u4e2d\u95f4\u7684\u4e34\u65f6\u8868\u3002

    \n\n

    \u6ce8\u610f\uff0c\u60a8\u5fc5\u53ea\u80fd\u5199\u4e00\u4e2a Update \u8bed\u53e5\uff0c\u8bf7\u4e0d\u8981\u7f16\u5199\u4efb\u4f55 Select \u8bed\u53e5\u3002

    \n\n

    \u4f8b\u5982\uff1a

    \n\n
    | id | name | sex | salary |\n|----|------|-----|--------|\n| 1  | A    | m   | 2500   |\n| 2  | B    | f   | 1500   |\n| 3  | C    | m   | 5500   |\n| 4  | D    | f   | 500    |\n
    \n\n

    \u8fd0\u884c\u4f60\u6240\u7f16\u5199\u7684\u66f4\u65b0\u8bed\u53e5\u4e4b\u540e\uff0c\u5c06\u4f1a\u5f97\u5230\u4ee5\u4e0b\u8868:

    \n\n
    | id | name | sex | salary |\n|----|------|-----|--------|\n| 1  | A    | f   | 2500   |\n| 2  | B    | m   | 1500   |\n| 3  | C    | f   | 5500   |\n| 4  | D    | m   | 500    |\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0627](https://leetcode-cn.com/problems/swap-salary)", "[\u53d8\u66f4\u6027\u522b](/solution/0600-0699/0627.Swap%20Salary/README.md)", "", "\u7b80\u5355", ""], "md_table_row_en": ["[0627](https://leetcode.com/problems/swap-salary)", "[Swap Salary](/solution/0600-0699/0627.Swap%20Salary/README_EN.md)", "", "Easy", ""]}, {"question_id": "0626", "frontend_question_id": "0626", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/exchange-seats", "url_en": "https://leetcode.com/problems/exchange-seats", "relative_path_cn": "/solution/0600-0699/0626.Exchange%20Seats/README.md", "relative_path_en": "/solution/0600-0699/0626.Exchange%20Seats/README_EN.md", "title_cn": "\u6362\u5ea7\u4f4d", "title_en": "Exchange Seats", "question_title_slug": "exchange-seats", "content_en": "

    Mary is a teacher in a middle school and she has a table seat storing students' names and their corresponding seat ids.

    \n\n

    The column id is continuous increment.

    \n\n

    Mary wants to change seats for the adjacent students.

    \n\n

    Can you write a SQL query to output the result for Mary?

    \n\n

     

    \n\n
    \n+---------+---------+\n|    id   | student |\n+---------+---------+\n|    1    | Abbot   |\n|    2    | Doris   |\n|    3    | Emerson |\n|    4    | Green   |\n|    5    | Jeames  |\n+---------+---------+\n
    \n\n

    For the sample input, the output is:

    \n\n
    \n+---------+---------+\n|    id   | student |\n+---------+---------+\n|    1    | Doris   |\n|    2    | Abbot   |\n|    3    | Green   |\n|    4    | Emerson |\n|    5    | Jeames  |\n+---------+---------+\n
    \n\n

    Note:

    \n\n

    If the number of students is odd, there is no need to change the last one's seat.

    \n", "content_cn": "

    \u5c0f\u7f8e\u662f\u4e00\u6240\u4e2d\u5b66\u7684\u4fe1\u606f\u79d1\u6280\u8001\u5e08\uff0c\u5979\u6709\u4e00\u5f20 seat \u5ea7\u4f4d\u8868\uff0c\u5e73\u65f6\u7528\u6765\u50a8\u5b58\u5b66\u751f\u540d\u5b57\u548c\u4e0e\u4ed6\u4eec\u76f8\u5bf9\u5e94\u7684\u5ea7\u4f4d id\u3002

    \n\n

    \u5176\u4e2d\u7eb5\u5217\u7684 id \u662f\u8fde\u7eed\u9012\u589e\u7684

    \n\n

    \u5c0f\u7f8e\u60f3\u6539\u53d8\u76f8\u90bb\u4fe9\u5b66\u751f\u7684\u5ea7\u4f4d\u3002

    \n\n

    \u4f60\u80fd\u4e0d\u80fd\u5e2e\u5979\u5199\u4e00\u4e2a SQL query \u6765\u8f93\u51fa\u5c0f\u7f8e\u60f3\u8981\u7684\u7ed3\u679c\u5462\uff1f

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n+---------+---------+\n|    id   | student |\n+---------+---------+\n|    1    | Abbot   |\n|    2    | Doris   |\n|    3    | Emerson |\n|    4    | Green   |\n|    5    | Jeames  |\n+---------+---------+\n
    \n\n

    \u5047\u5982\u6570\u636e\u8f93\u5165\u7684\u662f\u4e0a\u8868\uff0c\u5219\u8f93\u51fa\u7ed3\u679c\u5982\u4e0b\uff1a

    \n\n
    \n+---------+---------+\n|    id   | student |\n+---------+---------+\n|    1    | Doris   |\n|    2    | Abbot   |\n|    3    | Green   |\n|    4    | Emerson |\n|    5    | Jeames  |\n+---------+---------+
    \n\n

    \u6ce8\u610f\uff1a

    \n\n

    \u5982\u679c\u5b66\u751f\u4eba\u6570\u662f\u5947\u6570\uff0c\u5219\u4e0d\u9700\u8981\u6539\u53d8\u6700\u540e\u4e00\u4e2a\u540c\u5b66\u7684\u5ea7\u4f4d\u3002

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0626](https://leetcode-cn.com/problems/exchange-seats)", "[\u6362\u5ea7\u4f4d](/solution/0600-0699/0626.Exchange%20Seats/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0626](https://leetcode.com/problems/exchange-seats)", "[Exchange Seats](/solution/0600-0699/0626.Exchange%20Seats/README_EN.md)", "", "Medium", ""]}, {"question_id": "0625", "frontend_question_id": "0625", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/minimum-factorization", "url_en": "https://leetcode.com/problems/minimum-factorization", "relative_path_cn": "/solution/0600-0699/0625.Minimum%20Factorization/README.md", "relative_path_en": "/solution/0600-0699/0625.Minimum%20Factorization/README_EN.md", "title_cn": "\u6700\u5c0f\u56e0\u5f0f\u5206\u89e3", "title_en": "Minimum Factorization", "question_title_slug": "minimum-factorization", "content_en": "

    Given a positive integer num, return the smallest positive integer x whose multiplication of each digit equals num. If there is no answer or the answer is not fit in 32-bit signed integer, return 0.

    \n\n

     

    \n

    Example 1:

    \n
    Input: num = 48\nOutput: 68\n

    Example 2:

    \n
    Input: num = 15\nOutput: 35\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= num <= 231 - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6b63\u6574\u6570 a\uff0c\u627e\u51fa\u6700\u5c0f\u7684\u6b63\u6574\u6570 b \u4f7f\u5f97 b \u7684\u6240\u6709\u6570\u4f4d\u76f8\u4e58\u6070\u597d\u7b49\u4e8e a\u3002

    \n\n

    \u5982\u679c\u4e0d\u5b58\u5728\u8fd9\u6837\u7684\u7ed3\u679c\u6216\u8005\u7ed3\u679c\u4e0d\u662f 32 \u4f4d\u6709\u7b26\u53f7\u6574\u6570\uff0c\u8fd4\u56de 0\u3002

    \n\n

     

    \n\n

    \u6837\u4f8b 1

    \n\n

    \u8f93\u5165\uff1a

    \n\n
    48 \n
    \n\n

    \u8f93\u51fa\uff1a

    \n\n
    68
    \n\n

     

    \n\n

    \u6837\u4f8b 2

    \n\n

    \u8f93\u5165\uff1a

    \n\n
    15\n
    \n\n

    \u8f93\u51fa\uff1a

    \n\n
    35
    \n\n

     

    \n", "tags_en": ["Recursion", "Math"], "tags_cn": ["\u9012\u5f52", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int smallestFactorization(int num) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int smallestFactorization(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def smallestFactorization(self, num):\n \"\"\"\n :type num: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def smallestFactorization(self, num: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint smallestFactorization(int num){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SmallestFactorization(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} num\n * @return {number}\n */\nvar smallestFactorization = function(num) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} num\n# @return {Integer}\ndef smallest_factorization(num)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func smallestFactorization(_ num: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func smallestFactorization(num int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def smallestFactorization(num: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun smallestFactorization(num: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn smallest_factorization(num: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $num\n * @return Integer\n */\n function smallestFactorization($num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function smallestFactorization(num: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (smallest-factorization num)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0625](https://leetcode-cn.com/problems/minimum-factorization)", "[\u6700\u5c0f\u56e0\u5f0f\u5206\u89e3](/solution/0600-0699/0625.Minimum%20Factorization/README.md)", "`\u9012\u5f52`,`\u6570\u5b66`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0625](https://leetcode.com/problems/minimum-factorization)", "[Minimum Factorization](/solution/0600-0699/0625.Minimum%20Factorization/README_EN.md)", "`Recursion`,`Math`", "Medium", "\ud83d\udd12"]}, {"question_id": "0624", "frontend_question_id": "0624", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/maximum-distance-in-arrays", "url_en": "https://leetcode.com/problems/maximum-distance-in-arrays", "relative_path_cn": "/solution/0600-0699/0624.Maximum%20Distance%20in%20Arrays/README.md", "relative_path_en": "/solution/0600-0699/0624.Maximum%20Distance%20in%20Arrays/README_EN.md", "title_cn": "\u6570\u7ec4\u5217\u8868\u4e2d\u7684\u6700\u5927\u8ddd\u79bb", "title_en": "Maximum Distance in Arrays", "question_title_slug": "maximum-distance-in-arrays", "content_en": "

    You are given m arrays, where each array is sorted in ascending order.

    \n\n

    You can pick up two integers from two different arrays (each array picks one) and calculate the distance. We define the distance between two integers a and b to be their absolute difference |a - b|.

    \n\n

    Return the maximum distance.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: arrays = [[1,2,3],[4,5],[1,2,3]]\nOutput: 4\nExplanation: One way to reach the maximum distance 4 is to pick 1 in the first or third array and pick 5 in the second array.\n
    \n\n

    Example 2:

    \n\n
    \nInput: arrays = [[1],[1]]\nOutput: 0\n
    \n\n

    Example 3:

    \n\n
    \nInput: arrays = [[1],[2]]\nOutput: 1\n
    \n\n

    Example 4:

    \n\n
    \nInput: arrays = [[1,4],[0,5]]\nOutput: 4\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == arrays.length
    • \n\t
    • 2 <= m <= 105
    • \n\t
    • 1 <= arrays[i].length <= 500
    • \n\t
    • -104 <= arrays[i][j] <= 104
    • \n\t
    • arrays[i] is sorted in ascending order.
    • \n\t
    • There will be at most 105 integers in all the arrays.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a m \u4e2a\u6570\u7ec4\uff0c\u6bcf\u4e2a\u6570\u7ec4\u90fd\u5df2\u7ecf\u6309\u7167\u5347\u5e8f\u6392\u597d\u5e8f\u4e86\u3002\u73b0\u5728\u4f60\u9700\u8981\u4ece\u4e24\u4e2a\u4e0d\u540c\u7684\u6570\u7ec4\u4e2d\u9009\u62e9\u4e24\u4e2a\u6574\u6570\uff08\u6bcf\u4e2a\u6570\u7ec4\u9009\u4e00\u4e2a\uff09\u5e76\u4e14\u8ba1\u7b97\u5b83\u4eec\u7684\u8ddd\u79bb\u3002\u4e24\u4e2a\u6574\u6570 a \u548c b \u4e4b\u95f4\u7684\u8ddd\u79bb\u5b9a\u4e49\u4e3a\u5b83\u4eec\u5dee\u7684\u7edd\u5bf9\u503c |a-b| \u3002\u4f60\u7684\u4efb\u52a1\u5c31\u662f\u53bb\u627e\u5230\u6700\u5927\u8ddd\u79bb

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a \n[[1,2,3],\n [4,5],\n [1,2,3]]\n\u8f93\u51fa\uff1a 4\n\u89e3\u91ca\uff1a\n\u4e00\u79cd\u5f97\u5230\u7b54\u6848 4 \u7684\u65b9\u6cd5\u662f\u4ece\u7b2c\u4e00\u4e2a\u6570\u7ec4\u6216\u8005\u7b2c\u4e09\u4e2a\u6570\u7ec4\u4e2d\u9009\u62e9 1\uff0c\u540c\u65f6\u4ece\u7b2c\u4e8c\u4e2a\u6570\u7ec4\u4e2d\u9009\u62e9 5 \u3002\n
    \n\n

     

    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    1. \u6bcf\u4e2a\u7ed9\u5b9a\u6570\u7ec4\u81f3\u5c11\u4f1a\u6709 1 \u4e2a\u6570\u5b57\u3002\u5217\u8868\u4e2d\u81f3\u5c11\u6709\u4e24\u4e2a\u975e\u7a7a\u6570\u7ec4\u3002
    2. \n\t
    3. \u6240\u6709 m \u4e2a\u6570\u7ec4\u4e2d\u7684\u6570\u5b57\u603b\u6570\u76ee\u5728\u8303\u56f4 [2, 10000] \u5185\u3002
    4. \n\t
    5. m \u4e2a\u6570\u7ec4\u4e2d\u6240\u6709\u6574\u6570\u7684\u8303\u56f4\u5728 [-10000, 10000] \u5185\u3002
    6. \n
    \n\n

     

    \n", "tags_en": ["Array", "Hash Table"], "tags_cn": ["\u6570\u7ec4", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxDistance(vector>& arrays) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxDistance(List> arrays) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxDistance(self, arrays):\n \"\"\"\n :type arrays: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxDistance(self, arrays: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxDistance(int** arrays, int arraysSize, int* arraysColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxDistance(IList> arrays) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} arrays\n * @return {number}\n */\nvar maxDistance = function(arrays) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} arrays\n# @return {Integer}\ndef max_distance(arrays)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxDistance(_ arrays: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxDistance(arrays [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxDistance(arrays: List[List[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxDistance(arrays: List>): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_distance(arrays: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $arrays\n * @return Integer\n */\n function maxDistance($arrays) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxDistance(arrays: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-distance arrays)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0624](https://leetcode-cn.com/problems/maximum-distance-in-arrays)", "[\u6570\u7ec4\u5217\u8868\u4e2d\u7684\u6700\u5927\u8ddd\u79bb](/solution/0600-0699/0624.Maximum%20Distance%20in%20Arrays/README.md)", "`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0624](https://leetcode.com/problems/maximum-distance-in-arrays)", "[Maximum Distance in Arrays](/solution/0600-0699/0624.Maximum%20Distance%20in%20Arrays/README_EN.md)", "`Array`,`Hash Table`", "Medium", "\ud83d\udd12"]}, {"question_id": "0623", "frontend_question_id": "0623", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/add-one-row-to-tree", "url_en": "https://leetcode.com/problems/add-one-row-to-tree", "relative_path_cn": "/solution/0600-0699/0623.Add%20One%20Row%20to%20Tree/README.md", "relative_path_en": "/solution/0600-0699/0623.Add%20One%20Row%20to%20Tree/README_EN.md", "title_cn": "\u5728\u4e8c\u53c9\u6811\u4e2d\u589e\u52a0\u4e00\u884c", "title_en": "Add One Row to Tree", "question_title_slug": "add-one-row-to-tree", "content_en": "

    Given the root of a binary tree and two integers val and depth, add a row of nodes with value val at the given depth depth.

    \n\n

    Note that the root node is at depth 1.

    \n\n

    The adding rule is:

    \n\n
      \n\t
    • Given the integer depth, for each not null tree node cur at the depth depth - 1, create two tree nodes with value val as cur's left subtree root and right subtree root.
    • \n\t
    • cur's original left subtree should be the left subtree of the new left subtree root.
    • \n\t
    • cur's original right subtree should be the right subtree of the new right subtree root.
    • \n\t
    • If depth == 1 that means there is no depth depth - 1 at all, then create a tree node with value val as the new root of the whole original tree, and the original tree is the new root's left subtree.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [4,2,6,3,1,5], val = 1, depth = 2\nOutput: [4,1,1,2,null,null,6,3,1,5]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [4,2,null,3,1], val = 1, depth = 3\nOutput: [4,2,null,1,1,3,null,null,1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 104].
    • \n\t
    • The depth of the tree is in the range [1, 104].
    • \n\t
    • -100 <= Node.val <= 100
    • \n\t
    • -105 <= val <= 105
    • \n\t
    • 1 <= depth <= the depth of tree + 1
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811\uff0c\u6839\u8282\u70b9\u4e3a\u7b2c1\u5c42\uff0c\u6df1\u5ea6\u4e3a 1\u3002\u5728\u5176\u7b2c d \u5c42\u8ffd\u52a0\u4e00\u884c\u503c\u4e3a v \u7684\u8282\u70b9\u3002

    \n\n

    \u6dfb\u52a0\u89c4\u5219\uff1a\u7ed9\u5b9a\u4e00\u4e2a\u6df1\u5ea6\u503c d \uff08\u6b63\u6574\u6570\uff09\uff0c\u9488\u5bf9\u6df1\u5ea6\u4e3a d-1 \u5c42\u7684\u6bcf\u4e00\u975e\u7a7a\u8282\u70b9 N\uff0c\u4e3a N \u521b\u5efa\u4e24\u4e2a\u503c\u4e3a v \u7684\u5de6\u5b50\u6811\u548c\u53f3\u5b50\u6811\u3002

    \n\n

    \u5c06 N \u539f\u5148\u7684\u5de6\u5b50\u6811\uff0c\u8fde\u63a5\u4e3a\u65b0\u8282\u70b9 v \u7684\u5de6\u5b50\u6811\uff1b\u5c06 N \u539f\u5148\u7684\u53f3\u5b50\u6811\uff0c\u8fde\u63a5\u4e3a\u65b0\u8282\u70b9 v \u7684\u53f3\u5b50\u6811\u3002

    \n\n

    \u5982\u679c d \u7684\u503c\u4e3a 1\uff0c\u6df1\u5ea6 d - 1 \u4e0d\u5b58\u5728\uff0c\u5219\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6839\u8282\u70b9 v\uff0c\u539f\u5148\u7684\u6574\u68f5\u6811\u5c06\u4f5c\u4e3a v \u7684\u5de6\u5b50\u6811\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: \n\u4e8c\u53c9\u6811\u5982\u4e0b\u6240\u793a:\n       4\n     /   \\\n    2     6\n   / \\   / \n  3   1 5   \n\nv = 1\n\nd = 2\n\n\u8f93\u51fa: \n       4\n      / \\\n     1   1\n    /     \\\n   2       6\n  / \\     / \n 3   1   5   \n\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: \n\u4e8c\u53c9\u6811\u5982\u4e0b\u6240\u793a:\n      4\n     /   \n    2    \n   / \\   \n  3   1    \n\nv = 1\n\nd = 3\n\n\u8f93\u51fa: \n      4\n     /   \n    2\n   / \\    \n  1   1\n /     \\  \n3       1\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u8f93\u5165\u7684\u6df1\u5ea6\u503c d \u7684\u8303\u56f4\u662f\uff1a[1\uff0c\u4e8c\u53c9\u6811\u6700\u5927\u6df1\u5ea6 + 1]\u3002
    2. \n\t
    3. \u8f93\u5165\u7684\u4e8c\u53c9\u6811\u81f3\u5c11\u6709\u4e00\u4e2a\u8282\u70b9\u3002
    4. \n
    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* addOneRow(TreeNode* root, int val, int depth) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode addOneRow(TreeNode root, int val, int depth) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def addOneRow(self, root, val, depth):\n \"\"\"\n :type root: TreeNode\n :type val: int\n :type depth: int\n :rtype: TreeNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def addOneRow(self, root: TreeNode, val: int, depth: int) -> TreeNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* addOneRow(struct TreeNode* root, int val, int depth){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode AddOneRow(TreeNode root, int val, int depth) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number} val\n * @param {number} depth\n * @return {TreeNode}\n */\nvar addOneRow = function(root, val, depth) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @param {Integer} val\n# @param {Integer} depth\n# @return {TreeNode}\ndef add_one_row(root, val, depth)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func addOneRow(_ root: TreeNode?, _ val: Int, _ depth: Int) -> TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc addOneRow(root *TreeNode, val int, depth int) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def addOneRow(root: TreeNode, `val`: Int, depth: Int): TreeNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun addOneRow(root: TreeNode?, `val`: Int, depth: Int): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn add_one_row(root: Option>>, val: i32, depth: i32) -> Option>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param Integer $val\n * @param Integer $depth\n * @return TreeNode\n */\n function addOneRow($root, $val, $depth) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction addOneRow(root: TreeNode | null, val: number, depth: number): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (add-one-row root val depth)\n (-> (or/c tree-node? #f) exact-integer? exact-integer? (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0623](https://leetcode-cn.com/problems/add-one-row-to-tree)", "[\u5728\u4e8c\u53c9\u6811\u4e2d\u589e\u52a0\u4e00\u884c](/solution/0600-0699/0623.Add%20One%20Row%20to%20Tree/README.md)", "`\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0623](https://leetcode.com/problems/add-one-row-to-tree)", "[Add One Row to Tree](/solution/0600-0699/0623.Add%20One%20Row%20to%20Tree/README_EN.md)", "`Tree`", "Medium", ""]}, {"question_id": "0621", "frontend_question_id": "0621", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/task-scheduler", "url_en": "https://leetcode.com/problems/task-scheduler", "relative_path_cn": "/solution/0600-0699/0621.Task%20Scheduler/README.md", "relative_path_en": "/solution/0600-0699/0621.Task%20Scheduler/README_EN.md", "title_cn": "\u4efb\u52a1\u8c03\u5ea6\u5668", "title_en": "Task Scheduler", "question_title_slug": "task-scheduler", "content_en": "

    Given a characters array tasks, representing the tasks a CPU needs to do, where each letter represents a different task. Tasks could be done in any order. Each task is done in one unit of time. For each unit of time, the CPU could complete either one task or just be idle.

    \n\n

    However, there is a non-negative integer n that represents the cooldown period between two same tasks (the same letter in the array), that is that there must be at least n units of time between any two same tasks.

    \n\n

    Return the least number of units of times that the CPU will take to finish all the given tasks.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: tasks = ["A","A","A","B","B","B"], n = 2\nOutput: 8\nExplanation: \nA -> B -> idle -> A -> B -> idle -> A -> B\nThere is at least 2 units of time between any two same tasks.\n
    \n\n

    Example 2:

    \n\n
    \nInput: tasks = ["A","A","A","B","B","B"], n = 0\nOutput: 6\nExplanation: On this case any permutation of size 6 would work since n = 0.\n["A","A","A","B","B","B"]\n["A","B","A","B","A","B"]\n["B","B","B","A","A","A"]\n...\nAnd so on.\n
    \n\n

    Example 3:

    \n\n
    \nInput: tasks = ["A","A","A","A","A","A","B","C","D","E","F","G"], n = 2\nOutput: 16\nExplanation: \nOne possible solution is\nA -> B -> C -> A -> D -> E -> A -> F -> G -> A -> idle -> idle -> A -> idle -> idle -> A\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= task.length <= 104
    • \n\t
    • tasks[i] is upper-case English letter.
    • \n\t
    • The integer n is in the range [0, 100].
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u7528\u5b57\u7b26\u6570\u7ec4\u00a0tasks \u8868\u793a\u7684 CPU \u9700\u8981\u6267\u884c\u7684\u4efb\u52a1\u5217\u8868\u3002\u5176\u4e2d\u6bcf\u4e2a\u5b57\u6bcd\u8868\u793a\u4e00\u79cd\u4e0d\u540c\u79cd\u7c7b\u7684\u4efb\u52a1\u3002\u4efb\u52a1\u53ef\u4ee5\u4ee5\u4efb\u610f\u987a\u5e8f\u6267\u884c\uff0c\u5e76\u4e14\u6bcf\u4e2a\u4efb\u52a1\u90fd\u53ef\u4ee5\u5728 1 \u4e2a\u5355\u4f4d\u65f6\u95f4\u5185\u6267\u884c\u5b8c\u3002\u5728\u4efb\u4f55\u4e00\u4e2a\u5355\u4f4d\u65f6\u95f4\uff0cCPU \u53ef\u4ee5\u5b8c\u6210\u4e00\u4e2a\u4efb\u52a1\uff0c\u6216\u8005\u5904\u4e8e\u5f85\u547d\u72b6\u6001\u3002

    \n\n

    \u7136\u800c\uff0c\u4e24\u4e2a \u76f8\u540c\u79cd\u7c7b \u7684\u4efb\u52a1\u4e4b\u95f4\u5fc5\u987b\u6709\u957f\u5ea6\u4e3a\u6574\u6570 n \u7684\u51b7\u5374\u65f6\u95f4\uff0c\u56e0\u6b64\u81f3\u5c11\u6709\u8fde\u7eed n \u4e2a\u5355\u4f4d\u65f6\u95f4\u5185 CPU \u5728\u6267\u884c\u4e0d\u540c\u7684\u4efb\u52a1\uff0c\u6216\u8005\u5728\u5f85\u547d\u72b6\u6001\u3002

    \n\n

    \u4f60\u9700\u8981\u8ba1\u7b97\u5b8c\u6210\u6240\u6709\u4efb\u52a1\u6240\u9700\u8981\u7684 \u6700\u77ed\u65f6\u95f4 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1atasks = [\"A\",\"A\",\"A\",\"B\",\"B\",\"B\"], n = 2\n\u8f93\u51fa\uff1a8\n\u89e3\u91ca\uff1aA -> B -> (\u5f85\u547d) -> A -> B -> (\u5f85\u547d) -> A -> B\n     \u5728\u672c\u793a\u4f8b\u4e2d\uff0c\u4e24\u4e2a\u76f8\u540c\u7c7b\u578b\u4efb\u52a1\u4e4b\u95f4\u5fc5\u987b\u95f4\u9694\u957f\u5ea6\u4e3a n = 2 \u7684\u51b7\u5374\u65f6\u95f4\uff0c\u800c\u6267\u884c\u4e00\u4e2a\u4efb\u52a1\u53ea\u9700\u8981\u4e00\u4e2a\u5355\u4f4d\u65f6\u95f4\uff0c\u6240\u4ee5\u4e2d\u95f4\u51fa\u73b0\u4e86\uff08\u5f85\u547d\uff09\u72b6\u6001\u3002 
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1atasks = [\"A\",\"A\",\"A\",\"B\",\"B\",\"B\"], n = 0\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u4efb\u4f55\u5927\u5c0f\u4e3a 6 \u7684\u6392\u5217\u90fd\u53ef\u4ee5\u6ee1\u8db3\u8981\u6c42\uff0c\u56e0\u4e3a n = 0\n[\"A\",\"A\",\"A\",\"B\",\"B\",\"B\"]\n[\"A\",\"B\",\"A\",\"B\",\"A\",\"B\"]\n[\"B\",\"B\",\"B\",\"A\",\"A\",\"A\"]\n...\n\u8bf8\u5982\u6b64\u7c7b\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1atasks = [\"A\",\"A\",\"A\",\"A\",\"A\",\"A\",\"B\",\"C\",\"D\",\"E\",\"F\",\"G\"], n = 2\n\u8f93\u51fa\uff1a16\n\u89e3\u91ca\uff1a\u4e00\u79cd\u53ef\u80fd\u7684\u89e3\u51b3\u65b9\u6848\u662f\uff1a\n     A -> B -> C -> A -> D -> E -> A -> F -> G -> A -> (\u5f85\u547d) -> (\u5f85\u547d) -> A -> (\u5f85\u547d) -> (\u5f85\u547d) -> A\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= task.length <= 104
    • \n\t
    • tasks[i] \u662f\u5927\u5199\u82f1\u6587\u5b57\u6bcd
    • \n\t
    • n \u7684\u53d6\u503c\u8303\u56f4\u4e3a [0, 100]
    • \n
    \n", "tags_en": ["Greedy", "Queue", "Array"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u961f\u5217", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int leastInterval(vector& tasks, int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int leastInterval(char[] tasks, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def leastInterval(self, tasks, n):\n \"\"\"\n :type tasks: List[str]\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def leastInterval(self, tasks: List[str], n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint leastInterval(char* tasks, int tasksSize, int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LeastInterval(char[] tasks, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {character[]} tasks\n * @param {number} n\n * @return {number}\n */\nvar leastInterval = function(tasks, n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Character[]} tasks\n# @param {Integer} n\n# @return {Integer}\ndef least_interval(tasks, n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func leastInterval(_ tasks: [Character], _ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func leastInterval(tasks []byte, n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def leastInterval(tasks: Array[Char], n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun leastInterval(tasks: CharArray, n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn least_interval(tasks: Vec, n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $tasks\n * @param Integer $n\n * @return Integer\n */\n function leastInterval($tasks, $n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function leastInterval(tasks: string[], n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (least-interval tasks n)\n (-> (listof char?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0621](https://leetcode-cn.com/problems/task-scheduler)", "[\u4efb\u52a1\u8c03\u5ea6\u5668](/solution/0600-0699/0621.Task%20Scheduler/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u961f\u5217`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0621](https://leetcode.com/problems/task-scheduler)", "[Task Scheduler](/solution/0600-0699/0621.Task%20Scheduler/README_EN.md)", "`Greedy`,`Queue`,`Array`", "Medium", ""]}, {"question_id": "0620", "frontend_question_id": "0620", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/not-boring-movies", "url_en": "https://leetcode.com/problems/not-boring-movies", "relative_path_cn": "/solution/0600-0699/0620.Not%20Boring%20Movies/README.md", "relative_path_en": "/solution/0600-0699/0620.Not%20Boring%20Movies/README_EN.md", "title_cn": "\u6709\u8da3\u7684\u7535\u5f71", "title_en": "Not Boring Movies", "question_title_slug": "not-boring-movies", "content_en": "

    Table: Cinema

    \n\n
    \n+----------------+----------+\n| Column Name    | Type     |\n+----------------+----------+\n| id             | int      |\n| movie          | varchar  |\n| description    | varchar  |\n| rating         | float    |\n+----------------+----------+\nid is the primary key for this table.\nEach row contains information about the name of a movie, its genre, and its rating.\nrating is a 2 decimal places float in the range [0, 10]\n
    \n\n

     

    \n\n

    Write an SQL query to report the movies with an odd-numbered ID and a description that is not "boring".

    \n\n

    Return the result table in descending order by rating.

    \n\n

    The query result format is in the following example:

    \n\n

     

    \n\n
    \nCinema table:\n+----+------------+-------------+--------+\n| id | movie      | description | rating |\n+----+------------+-------------+--------+\n| 1  | War        | great 3D    | 8.9    |\n| 2  | Science    | fiction     | 8.5    |\n| 3  | irish      | boring      | 6.2    |\n| 4  | Ice song   | Fantacy     | 8.6    |\n| 5  | House card | Interesting | 9.1    |\n+----+------------+-------------+--------+\n\nResult table:\n+----+------------+-------------+--------+\n| id | movie      | description | rating |\n+----+------------+-------------+--------+\n| 5  | House card | Interesting | 9.1    |\n| 1  | War        | great 3D    | 8.9    |\n+----+------------+-------------+--------+\n\nWe have three movies with odd-numbered ID: 1, 3, and 5. The movie with ID = 3 is boring so we don't include it in the answer.
    \n", "content_cn": "

    \u67d0\u57ce\u5e02\u5f00\u4e86\u4e00\u5bb6\u65b0\u7684\u7535\u5f71\u9662\uff0c\u5438\u5f15\u4e86\u5f88\u591a\u4eba\u8fc7\u6765\u770b\u7535\u5f71\u3002\u8be5\u7535\u5f71\u9662\u7279\u522b\u6ce8\u610f\u7528\u6237\u4f53\u9a8c\uff0c\u4e13\u95e8\u6709\u4e2a LED\u663e\u793a\u677f\u505a\u7535\u5f71\u63a8\u8350\uff0c\u4e0a\u9762\u516c\u5e03\u7740\u5f71\u8bc4\u548c\u76f8\u5173\u7535\u5f71\u63cf\u8ff0\u3002

    \n\n

    \u4f5c\u4e3a\u8be5\u7535\u5f71\u9662\u7684\u4fe1\u606f\u90e8\u4e3b\u7ba1\uff0c\u60a8\u9700\u8981\u7f16\u5199\u4e00\u4e2a SQL\u67e5\u8be2\uff0c\u627e\u51fa\u6240\u6709\u5f71\u7247\u63cf\u8ff0\u4e3a\u975e boring (\u4e0d\u65e0\u804a) \u7684\u5e76\u4e14 id \u4e3a\u5947\u6570 \u7684\u5f71\u7247\uff0c\u7ed3\u679c\u8bf7\u6309\u7b49\u7ea7 rating \u6392\u5217\u3002

    \n\n

     

    \n\n

    \u4f8b\u5982\uff0c\u4e0b\u8868 cinema:

    \n\n
    \n+---------+-----------+--------------+-----------+\n|   id    | movie     |  description |  rating   |\n+---------+-----------+--------------+-----------+\n|   1     | War       |   great 3D   |   8.9     |\n|   2     | Science   |   fiction    |   8.5     |\n|   3     | irish     |   boring     |   6.2     |\n|   4     | Ice song  |   Fantacy    |   8.6     |\n|   5     | House card|   Interesting|   9.1     |\n+---------+-----------+--------------+-----------+\n
    \n\n

    \u5bf9\u4e8e\u4e0a\u9762\u7684\u4f8b\u5b50\uff0c\u5219\u6b63\u786e\u7684\u8f93\u51fa\u662f\u4e3a\uff1a

    \n\n
    \n+---------+-----------+--------------+-----------+\n|   id    | movie     |  description |  rating   |\n+---------+-----------+--------------+-----------+\n|   5     | House card|   Interesting|   9.1     |\n|   1     | War       |   great 3D   |   8.9     |\n+---------+-----------+--------------+-----------+\n
    \n\n

     

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0620](https://leetcode-cn.com/problems/not-boring-movies)", "[\u6709\u8da3\u7684\u7535\u5f71](/solution/0600-0699/0620.Not%20Boring%20Movies/README.md)", "", "\u7b80\u5355", ""], "md_table_row_en": ["[0620](https://leetcode.com/problems/not-boring-movies)", "[Not Boring Movies](/solution/0600-0699/0620.Not%20Boring%20Movies/README_EN.md)", "", "Easy", ""]}, {"question_id": "0619", "frontend_question_id": "0619", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/biggest-single-number", "url_en": "https://leetcode.com/problems/biggest-single-number", "relative_path_cn": "/solution/0600-0699/0619.Biggest%20Single%20Number/README.md", "relative_path_en": "/solution/0600-0699/0619.Biggest%20Single%20Number/README_EN.md", "title_cn": "\u53ea\u51fa\u73b0\u4e00\u6b21\u7684\u6700\u5927\u6570\u5b57", "title_en": "Biggest Single Number", "question_title_slug": "biggest-single-number", "content_en": "

    Table my_numbers contains many numbers in column num including duplicated ones.
    \r\nCan you write a SQL query to find the biggest number, which only appears once.

    \r\n\r\n
    \r\n+---+\r\n|num|\r\n+---+\r\n| 8 |\r\n| 8 |\r\n| 3 |\r\n| 3 |\r\n| 1 |\r\n| 4 |\r\n| 5 |\r\n| 6 | \r\n
    \r\nFor the sample data above, your query should return the following result:\r\n\r\n
    \r\n+---+\r\n|num|\r\n+---+\r\n| 6 |\r\n
    \r\nNote:
    \r\nIf there is no such number, just output null.\r\n\r\n

     

    \r\n", "content_cn": "

    \u8868 my_numbers \u7684 num \u5b57\u6bb5\u5305\u542b\u5f88\u591a\u6570\u5b57\uff0c\u5176\u4e2d\u5305\u62ec\u5f88\u591a\u91cd\u590d\u7684\u6570\u5b57\u3002

    \n\n

    \u4f60\u80fd\u5199\u4e00\u4e2a SQL \u67e5\u8be2\u8bed\u53e5\uff0c\u627e\u5230\u53ea\u51fa\u73b0\u8fc7\u4e00\u6b21\u7684\u6570\u5b57\u4e2d\uff0c\u6700\u5927\u7684\u4e00\u4e2a\u6570\u5b57\u5417\uff1f

    \n\n
    +---+\n|num|\n+---+\n| 8 |\n| 8 |\n| 3 |\n| 3 |\n| 1 |\n| 4 |\n| 5 |\n| 6 | \n
    \n\n

    \u5bf9\u4e8e\u4e0a\u9762\u7ed9\u51fa\u7684\u6837\u4f8b\u6570\u636e\uff0c\u4f60\u7684\u67e5\u8be2\u8bed\u53e5\u5e94\u8be5\u8fd4\u56de\u5982\u4e0b\u7ed3\u679c\uff1a

    \n\n
    +---+\n|num|\n+---+\n| 6 |\n
    \n\n

    \u6ce8\u610f\uff1a

    \n\n

    \u5982\u679c\u6ca1\u6709\u53ea\u51fa\u73b0\u4e00\u6b21\u7684\u6570\u5b57\uff0c\u8f93\u51fa null \u3002

    \n\n

     

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0619](https://leetcode-cn.com/problems/biggest-single-number)", "[\u53ea\u51fa\u73b0\u4e00\u6b21\u7684\u6700\u5927\u6570\u5b57](/solution/0600-0699/0619.Biggest%20Single%20Number/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0619](https://leetcode.com/problems/biggest-single-number)", "[Biggest Single Number](/solution/0600-0699/0619.Biggest%20Single%20Number/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "0618", "frontend_question_id": "0618", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/students-report-by-geography", "url_en": "https://leetcode.com/problems/students-report-by-geography", "relative_path_cn": "/solution/0600-0699/0618.Students%20Report%20By%20Geography/README.md", "relative_path_en": "/solution/0600-0699/0618.Students%20Report%20By%20Geography/README_EN.md", "title_cn": "\u5b66\u751f\u5730\u7406\u4fe1\u606f\u62a5\u544a", "title_en": "Students Report By Geography", "question_title_slug": "students-report-by-geography", "content_en": "A U.S graduate school has students from Asia, Europe and America. The students' location information are stored in table student as below.\r\n

     

    \r\n\r\n
    \r\n| name   | continent |\r\n|--------|-----------|\r\n| Jack   | America   |\r\n| Pascal | Europe    |\r\n| Xi     | Asia      |\r\n| Jane   | America   |\r\n
    \r\n\r\n

     

    \r\n Pivot the continent column in this table so that each name is sorted alphabetically and displayed underneath its corresponding continent. The output headers should be America, Asia and Europe respectively. It is guaranteed that the student number from America is no less than either Asia or Europe.\r\n\r\n

     

    \r\nFor the sample input, the output is:\r\n\r\n

     

    \r\n\r\n
    \r\n| America | Asia | Europe |\r\n|---------|------|--------|\r\n| Jack    | Xi   | Pascal |\r\n| Jane    |      |        |\r\n
    \r\n\r\n

     

    \r\nFollow-up: If it is unknown which continent has the most students, can you write a query to generate the student report?\r\n\r\n

     

    \r\n", "content_cn": "

    \u4e00\u6240\u7f8e\u56fd\u5927\u5b66\u6709\u6765\u81ea\u4e9a\u6d32\u3001\u6b27\u6d32\u548c\u7f8e\u6d32\u7684\u5b66\u751f\uff0c\u4ed6\u4eec\u7684\u5730\u7406\u4fe1\u606f\u5b58\u653e\u5728\u5982\u4e0b\u00a0student \u8868\u4e2d\u3002

    \n\n

    \u00a0

    \n\n
    \n| name   | continent |\n|--------|-----------|\n| Jack   | America   |\n| Pascal | Europe    |\n| Xi     | Asia      |\n| Jane   | America   |\n
    \n\n

    \u00a0

    \n\n

    \u5199\u4e00\u4e2a\u67e5\u8be2\u8bed\u53e5\u5b9e\u73b0\u5bf9\u5927\u6d32\uff08continent\uff09\u5217\u7684\u00a0\u900f\u89c6\u8868 \u64cd\u4f5c\uff0c\u4f7f\u5f97\u6bcf\u4e2a\u5b66\u751f\u6309\u7167\u59d3\u540d\u7684\u5b57\u6bcd\u987a\u5e8f\u4f9d\u6b21\u6392\u5217\u5728\u5bf9\u5e94\u7684\u5927\u6d32\u4e0b\u9762\u3002\u8f93\u51fa\u7684\u6807\u9898\u5e94\u4f9d\u6b21\u4e3a\u7f8e\u6d32\uff08America\uff09\u3001\u4e9a\u6d32\uff08Asia\uff09\u548c\u6b27\u6d32\uff08Europe\uff09\u3002

    \n\n

    \u00a0

    \n\n

    \u5bf9\u4e8e\u6837\u4f8b\u8f93\u5165\uff0c\u5b83\u7684\u5bf9\u5e94\u8f93\u51fa\u662f\uff1a

    \n\n

    \u00a0

    \n\n
    \n| America | Asia | Europe |\n|---------|------|--------|\n| Jack    | Xi   | Pascal |\n| Jane    |      |        |\n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u5982\u679c\u4e0d\u80fd\u786e\u5b9a\u54ea\u4e2a\u5927\u6d32\u7684\u5b66\u751f\u6570\u6700\u591a\uff0c\u4f60\u53ef\u4ee5\u5199\u51fa\u4e00\u4e2a\u67e5\u8be2\u53bb\u751f\u6210\u4e0a\u8ff0\u5b66\u751f\u62a5\u544a\u5417\uff1f

    \n\n

    \u00a0

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0618](https://leetcode-cn.com/problems/students-report-by-geography)", "[\u5b66\u751f\u5730\u7406\u4fe1\u606f\u62a5\u544a](/solution/0600-0699/0618.Students%20Report%20By%20Geography/README.md)", "", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0618](https://leetcode.com/problems/students-report-by-geography)", "[Students Report By Geography](/solution/0600-0699/0618.Students%20Report%20By%20Geography/README_EN.md)", "", "Hard", "\ud83d\udd12"]}, {"question_id": "0617", "frontend_question_id": "0617", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/merge-two-binary-trees", "url_en": "https://leetcode.com/problems/merge-two-binary-trees", "relative_path_cn": "/solution/0600-0699/0617.Merge%20Two%20Binary%20Trees/README.md", "relative_path_en": "/solution/0600-0699/0617.Merge%20Two%20Binary%20Trees/README_EN.md", "title_cn": "\u5408\u5e76\u4e8c\u53c9\u6811", "title_en": "Merge Two Binary Trees", "question_title_slug": "merge-two-binary-trees", "content_en": "

    You are given two binary trees root1 and root2.

    \n\n

    Imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not. You need to merge the two trees into a new binary tree. The merge rule is that if two nodes overlap, then sum node values up as the new value of the merged node. Otherwise, the NOT null node will be used as the node of the new tree.

    \n\n

    Return the merged tree.

    \n\n

    Note: The merging process must start from the root nodes of both trees.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root1 = [1,3,2,5], root2 = [2,1,3,null,4,null,7]\nOutput: [3,4,5,5,4,null,7]\n
    \n\n

    Example 2:

    \n\n
    \nInput: root1 = [1], root2 = [1,2]\nOutput: [2,2]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in both trees is in the range [0, 2000].
    • \n\t
    • -104 <= Node.val <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u4e8c\u53c9\u6811\uff0c\u60f3\u8c61\u5f53\u4f60\u5c06\u5b83\u4eec\u4e2d\u7684\u4e00\u4e2a\u8986\u76d6\u5230\u53e6\u4e00\u4e2a\u4e0a\u65f6\uff0c\u4e24\u4e2a\u4e8c\u53c9\u6811\u7684\u4e00\u4e9b\u8282\u70b9\u4fbf\u4f1a\u91cd\u53e0\u3002

    \n\n

    \u4f60\u9700\u8981\u5c06\u4ed6\u4eec\u5408\u5e76\u4e3a\u4e00\u4e2a\u65b0\u7684\u4e8c\u53c9\u6811\u3002\u5408\u5e76\u7684\u89c4\u5219\u662f\u5982\u679c\u4e24\u4e2a\u8282\u70b9\u91cd\u53e0\uff0c\u90a3\u4e48\u5c06\u4ed6\u4eec\u7684\u503c\u76f8\u52a0\u4f5c\u4e3a\u8282\u70b9\u5408\u5e76\u540e\u7684\u65b0\u503c\uff0c\u5426\u5219\u4e0d\u4e3a NULL \u7684\u8282\u70b9\u5c06\u76f4\u63a5\u4f5c\u4e3a\u65b0\u4e8c\u53c9\u6811\u7684\u8282\u70b9\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: \n\tTree 1                     Tree 2                  \n          1                         2                             \n         / \\                       / \\                            \n        3   2                     1   3                        \n       /                           \\   \\                      \n      5                             4   7                  \n\u8f93\u51fa: \n\u5408\u5e76\u540e\u7684\u6811:\n\t     3\n\t    / \\\n\t   4   5\n\t  / \\   \\ \n\t 5   4   7\n
    \n\n

    \u6ce8\u610f: \u5408\u5e76\u5fc5\u987b\u4ece\u4e24\u4e2a\u6811\u7684\u6839\u8282\u70b9\u5f00\u59cb\u3002

    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* mergeTrees(TreeNode* root1, TreeNode* root2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode mergeTrees(TreeNode root1, TreeNode root2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def mergeTrees(self, root1, root2):\n \"\"\"\n :type root1: TreeNode\n :type root2: TreeNode\n :rtype: TreeNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def mergeTrees(self, root1: TreeNode, root2: TreeNode) -> TreeNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* mergeTrees(struct TreeNode* root1, struct TreeNode* root2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode MergeTrees(TreeNode root1, TreeNode root2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root1\n * @param {TreeNode} root2\n * @return {TreeNode}\n */\nvar mergeTrees = function(root1, root2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root1\n# @param {TreeNode} root2\n# @return {TreeNode}\ndef merge_trees(root1, root2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func mergeTrees(_ root1: TreeNode?, _ root2: TreeNode?) -> TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc mergeTrees(root1 *TreeNode, root2 *TreeNode) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def mergeTrees(root1: TreeNode, root2: TreeNode): TreeNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun mergeTrees(root1: TreeNode?, root2: TreeNode?): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn merge_trees(root1: Option>>, root2: Option>>) -> Option>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root1\n * @param TreeNode $root2\n * @return TreeNode\n */\n function mergeTrees($root1, $root2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction mergeTrees(root1: TreeNode | null, root2: TreeNode | null): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (merge-trees root1 root2)\n (-> (or/c tree-node? #f) (or/c tree-node? #f) (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0617](https://leetcode-cn.com/problems/merge-two-binary-trees)", "[\u5408\u5e76\u4e8c\u53c9\u6811](/solution/0600-0699/0617.Merge%20Two%20Binary%20Trees/README.md)", "`\u6811`", "\u7b80\u5355", ""], "md_table_row_en": ["[0617](https://leetcode.com/problems/merge-two-binary-trees)", "[Merge Two Binary Trees](/solution/0600-0699/0617.Merge%20Two%20Binary%20Trees/README_EN.md)", "`Tree`", "Easy", ""]}, {"question_id": "0616", "frontend_question_id": "0616", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/add-bold-tag-in-string", "url_en": "https://leetcode.com/problems/add-bold-tag-in-string", "relative_path_cn": "/solution/0600-0699/0616.Add%20Bold%20Tag%20in%20String/README.md", "relative_path_en": "/solution/0600-0699/0616.Add%20Bold%20Tag%20in%20String/README_EN.md", "title_cn": "\u7ed9\u5b57\u7b26\u4e32\u6dfb\u52a0\u52a0\u7c97\u6807\u7b7e", "title_en": "Add Bold Tag in String", "question_title_slug": "add-bold-tag-in-string", "content_en": "

    You are given a string s and an array of strings words. You should add a closed pair of bold tag <b> and </b> to wrap the substrings in s that exist in words. If two such substrings overlap, you should wrap them together with only one pair of closed bold-tag. If two substrings wrapped by bold tags are consecutive, you should combine them.

    \n\n

    Return s after adding the bold tags.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "abcxyz123", words = ["abc","123"]\nOutput: "<b>abc</b>xyz<b>123</b>"\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "aaabbcc", words = ["aaa","aab","bc"]\nOutput: "<b>aaabbc</b>c"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 1000
    • \n\t
    • 0 <= words.length <= 100
    • \n\t
    • 1 <= words[i].length <= 1000
    • \n\t
    • s and words[i] consist of English letters and digits.
    • \n\t
    • All the values of words are unique.
    • \n
    \n\n

     

    \n

    Note: This question is the same as 758: https://leetcode.com/problems/bold-words-in-string/

    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32\u00a0s\u00a0\u548c\u4e00\u4e2a\u5b57\u7b26\u4e32\u5217\u8868\u00a0dict\u00a0\uff0c\u4f60\u9700\u8981\u5c06\u5728\u5b57\u7b26\u4e32\u5217\u8868\u4e2d\u51fa\u73b0\u8fc7\u7684 s \u7684\u5b50\u4e32\u6dfb\u52a0\u52a0\u7c97\u95ed\u5408\u6807\u7b7e\u00a0\u00a0\u548c\u00a0\u00a0\u3002

    \n\n

    \u5982\u679c\u4e24\u4e2a\u5b50\u4e32\u6709\u91cd\u53e0\u90e8\u5206\uff0c\u4f60\u9700\u8981\u628a\u5b83\u4eec\u4e00\u8d77\u7528\u4e00\u4e2a\u95ed\u5408\u6807\u7b7e\u5305\u56f4\u8d77\u6765\u3002\u540c\u7406\uff0c\u5982\u679c\u4e24\u4e2a\u5b50\u5b57\u7b26\u4e32\u8fde\u7eed\u88ab\u52a0\u7c97\uff0c\u90a3\u4e48\u4f60\u4e5f\u9700\u8981\u628a\u5b83\u4eec\u5408\u8d77\u6765\u7528\u4e00\u4e2a\u52a0\u7c97\u6807\u7b7e\u5305\u56f4\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\ns = \"abcxyz123\"\ndict = [\"abc\",\"123\"]\n\u8f93\u51fa\uff1a\n\"abcxyz123\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\ns = \"aaabbcc\"\ndict = [\"aaa\",\"aab\",\"bc\"]\n\u8f93\u51fa\uff1a\n\"aaabbcc\"\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u7ed9\u5b9a\u7684 dict \u4e2d\u4e0d\u4f1a\u6709\u91cd\u590d\u7684\u5b57\u7b26\u4e32\uff0c\u4e14\u5b57\u7b26\u4e32\u6570\u76ee\u4e0d\u4f1a\u8d85\u8fc7 100 \u3002
    • \n\t
    • \u8f93\u5165\u4e2d\u7684\u6240\u6709\u5b57\u7b26\u4e32\u957f\u5ea6\u90fd\u5728\u8303\u56f4 [1,1000] \u5185\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u6ce8\uff1a\u6b64\u9898\u4e0e\u300c758 - \u5b57\u7b26\u4e32\u4e2d\u7684\u52a0\u7c97\u5355\u8bcd\u300d\u76f8\u540c - https://leetcode-cn.com/problems/bold-words-in-string

    \n\n

    \u00a0

    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string addBoldTag(string s, vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String addBoldTag(String s, String[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def addBoldTag(self, s, words):\n \"\"\"\n :type s: str\n :type words: List[str]\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def addBoldTag(self, s: str, words: List[str]) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * addBoldTag(char * s, char ** words, int wordsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string AddBoldTag(string s, string[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string[]} words\n * @return {string}\n */\nvar addBoldTag = function(s, words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String[]} words\n# @return {String}\ndef add_bold_tag(s, words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func addBoldTag(_ s: String, _ words: [String]) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func addBoldTag(s string, words []string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def addBoldTag(s: String, words: Array[String]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun addBoldTag(s: String, words: Array): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn add_bold_tag(s: String, words: Vec) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String[] $words\n * @return String\n */\n function addBoldTag($s, $words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function addBoldTag(s: string, words: string[]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (add-bold-tag s words)\n (-> string? (listof string?) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0616](https://leetcode-cn.com/problems/add-bold-tag-in-string)", "[\u7ed9\u5b57\u7b26\u4e32\u6dfb\u52a0\u52a0\u7c97\u6807\u7b7e](/solution/0600-0699/0616.Add%20Bold%20Tag%20in%20String/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0616](https://leetcode.com/problems/add-bold-tag-in-string)", "[Add Bold Tag in String](/solution/0600-0699/0616.Add%20Bold%20Tag%20in%20String/README_EN.md)", "`String`", "Medium", "\ud83d\udd12"]}, {"question_id": "0615", "frontend_question_id": "0615", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/average-salary-departments-vs-company", "url_en": "https://leetcode.com/problems/average-salary-departments-vs-company", "relative_path_cn": "/solution/0600-0699/0615.Average%20Salary%20Departments%20VS%20Company/README.md", "relative_path_en": "/solution/0600-0699/0615.Average%20Salary%20Departments%20VS%20Company/README_EN.md", "title_cn": "\u5e73\u5747\u5de5\u8d44\uff1a\u90e8\u95e8\u4e0e\u516c\u53f8\u6bd4\u8f83", "title_en": "Average Salary Departments VS Company", "question_title_slug": "average-salary-departments-vs-company", "content_en": "Given two tables as below, write a query to display the comparison result (higher/lower/same) of the average salary of employees in a department to the company's average salary.\r\n

     

    \r\nTable: salary\r\n\r\n
    \r\n| id | employee_id | amount | pay_date   |\r\n|----|-------------|--------|------------|\r\n| 1  | 1           | 9000   | 2017-03-31 |\r\n| 2  | 2           | 6000   | 2017-03-31 |\r\n| 3  | 3           | 10000  | 2017-03-31 |\r\n| 4  | 1           | 7000   | 2017-02-28 |\r\n| 5  | 2           | 6000   | 2017-02-28 |\r\n| 6  | 3           | 8000   | 2017-02-28 |\r\n
    \r\n\r\n

     

    \r\nThe employee_id column refers to the employee_id in the following table employee.\r\n\r\n

     

    \r\n\r\n
    \r\n| employee_id | department_id |\r\n|-------------|---------------|\r\n| 1           | 1             |\r\n| 2           | 2             |\r\n| 3           | 2             |\r\n
    \r\n\r\n

     

    \r\nSo for the sample data above, the result is:\r\n\r\n

     

    \r\n\r\n
    \r\n| pay_month | department_id | comparison  |\r\n|-----------|---------------|-------------|\r\n| 2017-03   | 1             | higher      |\r\n| 2017-03   | 2             | lower       |\r\n| 2017-02   | 1             | same        |\r\n| 2017-02   | 2             | same        |\r\n
    \r\n\r\n

     

    \r\nExplanation\r\n\r\n

     

    \r\nIn March, the company's average salary is (9000+6000+10000)/3 = 8333.33...\r\n\r\n

     

    \r\nThe average salary for department '1' is 9000, which is the salary of employee_id '1' since there is only one employee in this department. So the comparison result is 'higher' since 9000 > 8333.33 obviously.\r\n\r\n

     

    \r\nThe average salary of department '2' is (6000 + 10000)/2 = 8000, which is the average of employee_id '2' and '3'. So the comparison result is 'lower' since 8000 < 8333.33.\r\n\r\n

     

    \r\nWith he same formula for the average salary comparison in February, the result is 'same' since both the department '1' and '2' have the same average salary with the company, which is 7000.\r\n\r\n

     

    \r\n", "content_cn": "

    \u7ed9\u5982\u4e0b\u4e24\u4e2a\u8868\uff0c\u5199\u4e00\u4e2a\u67e5\u8be2\u8bed\u53e5\uff0c\u6c42\u51fa\u5728\u6bcf\u4e00\u4e2a\u5de5\u8d44\u53d1\u653e\u65e5\uff0c\u6bcf\u4e2a\u90e8\u95e8\u7684\u5e73\u5747\u5de5\u8d44\u4e0e\u516c\u53f8\u7684\u5e73\u5747\u5de5\u8d44\u7684\u6bd4\u8f83\u7ed3\u679c \uff08\u9ad8 / \u4f4e / \u76f8\u540c\uff09\u3002

    \n\n

     

    \n\n

    \u8868\uff1a salary

    \n\n
    | id | employee_id | amount | pay_date   |\n|----|-------------|--------|------------|\n| 1  | 1           | 9000   | 2017-03-31 |\n| 2  | 2           | 6000   | 2017-03-31 |\n| 3  | 3           | 10000  | 2017-03-31 |\n| 4  | 1           | 7000   | 2017-02-28 |\n| 5  | 2           | 6000   | 2017-02-28 |\n| 6  | 3           | 8000   | 2017-02-28 |\n
    \n\n

     

    \n\n

    employee_id \u5b57\u6bb5\u662f\u8868 employee \u4e2d employee_id \u5b57\u6bb5\u7684\u5916\u952e\u3002

    \n\n

     

    \n\n
    | employee_id | department_id |\n|-------------|---------------|\n| 1           | 1             |\n| 2           | 2             |\n| 3           | 2             |\n
    \n\n

     

    \n\n

    \u5bf9\u4e8e\u5982\u4e0a\u6837\u4f8b\u6570\u636e\uff0c\u7ed3\u679c\u4e3a\uff1a

    \n\n

     

    \n\n
    | pay_month | department_id | comparison  |\n|-----------|---------------|-------------|\n| 2017-03   | 1             | higher      |\n| 2017-03   | 2             | lower       |\n| 2017-02   | 1             | same        |\n| 2017-02   | 2             | same        |\n
    \n\n

     

    \n\n

    \u89e3\u91ca

    \n\n

     

    \n\n

    \u5728\u4e09\u6708\uff0c\u516c\u53f8\u7684\u5e73\u5747\u5de5\u8d44\u662f (9000+6000+10000)/3 = 8333.33...

    \n\n

     

    \n\n

    \u7531\u4e8e\u90e8\u95e8 '1' \u91cc\u53ea\u6709\u4e00\u4e2a employee_id \u4e3a '1' \u7684\u5458\u5de5\uff0c\u6240\u4ee5\u90e8\u95e8 '1' \u7684\u5e73\u5747\u5de5\u8d44\u5c31\u662f\u6b64\u4eba\u7684\u5de5\u8d44 9000 \u3002\u56e0\u4e3a 9000 > 8333.33 \uff0c\u6240\u4ee5\u6bd4\u8f83\u7ed3\u679c\u662f 'higher'\u3002

    \n\n

     

    \n\n

    \u7b2c\u4e8c\u4e2a\u90e8\u95e8\u7684\u5e73\u5747\u5de5\u8d44\u4e3a employee_id \u4e3a '2' \u548c '3' \u4e24\u4e2a\u4eba\u7684\u5e73\u5747\u5de5\u8d44\uff0c\u4e3a (6000+10000)/2=8000 \u3002\u56e0\u4e3a 8000 < 8333.33 \uff0c\u6240\u4ee5\u6bd4\u8f83\u7ed3\u679c\u662f 'lower' \u3002

    \n\n

     

    \n\n

    \u5728\u4e8c\u6708\u7528\u540c\u6837\u7684\u516c\u5f0f\u6c42\u5e73\u5747\u5de5\u8d44\u5e76\u6bd4\u8f83\uff0c\u6bd4\u8f83\u7ed3\u679c\u4e3a 'same' \uff0c\u56e0\u4e3a\u90e8\u95e8 '1' \u548c\u90e8\u95e8 '2' \u7684\u5e73\u5747\u5de5\u8d44\u4e0e\u516c\u53f8\u7684\u5e73\u5747\u5de5\u8d44\u76f8\u540c\uff0c\u90fd\u662f 7000 \u3002

    \n\n

     

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0615](https://leetcode-cn.com/problems/average-salary-departments-vs-company)", "[\u5e73\u5747\u5de5\u8d44\uff1a\u90e8\u95e8\u4e0e\u516c\u53f8\u6bd4\u8f83](/solution/0600-0699/0615.Average%20Salary%20Departments%20VS%20Company/README.md)", "", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0615](https://leetcode.com/problems/average-salary-departments-vs-company)", "[Average Salary Departments VS Company](/solution/0600-0699/0615.Average%20Salary%20Departments%20VS%20Company/README_EN.md)", "", "Hard", "\ud83d\udd12"]}, {"question_id": "0614", "frontend_question_id": "0614", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/second-degree-follower", "url_en": "https://leetcode.com/problems/second-degree-follower", "relative_path_cn": "/solution/0600-0699/0614.Second%20Degree%20Follower/README.md", "relative_path_en": "/solution/0600-0699/0614.Second%20Degree%20Follower/README_EN.md", "title_cn": "\u4e8c\u7ea7\u5173\u6ce8\u8005", "title_en": "Second Degree Follower", "question_title_slug": "second-degree-follower", "content_en": "

    In facebook, there is a follow table with two columns: followee, follower.

    \r\n\r\n

    Please write a sql query to get the amount of each follower’s follower if he/she has one.

    \r\n\r\n

    For example:

    \r\n\r\n
    \r\n+-------------+------------+\r\n| followee    | follower   |\r\n+-------------+------------+\r\n|     A       |     B      |\r\n|     B       |     C      |\r\n|     B       |     D      |\r\n|     D       |     E      |\r\n+-------------+------------+\r\n
    \r\nshould output:\r\n\r\n
    \r\n+-------------+------------+\r\n| follower    | num        |\r\n+-------------+------------+\r\n|     B       |  2         |\r\n|     D       |  1         |\r\n+-------------+------------+\r\n
    \r\nExplaination:
    \r\nBoth B and D exist in the follower list, when as a followee, B's follower is C and D, and D's follower is E. A does not exist in follower list.\r\n

     

    \r\n\r\n

     

    \r\nNote:
    \r\nFollowee would not follow himself/herself in all cases.
    \r\nPlease display the result in follower's alphabet order.\r\n

     

    \r\n", "content_cn": "

    \u5728 facebook \u4e2d\uff0c\u8868 follow \u4f1a\u6709 2 \u4e2a\u5b57\u6bb5\uff1a followee, follower \uff0c\u5206\u522b\u8868\u793a\u88ab\u5173\u6ce8\u8005\u548c\u5173\u6ce8\u8005\u3002

    \n\n

    \u8bf7\u5199\u4e00\u4e2a sql \u67e5\u8be2\u8bed\u53e5\uff0c\u5bf9\u6bcf\u4e00\u4e2a\u5173\u6ce8\u8005\uff0c\u67e5\u8be2\u5173\u6ce8\u4ed6\u7684\u5173\u6ce8\u8005\u7684\u6570\u76ee\u3002

    \n\n

    \u6bd4\u65b9\u8bf4\uff1a

    \n\n
    +-------------+------------+\n| followee    | follower   |\n+-------------+------------+\n|     A       |     B      |\n|     B       |     C      |\n|     B       |     D      |\n|     D       |     E      |\n+-------------+------------+\n
    \n\n

    \u5e94\u8be5\u8f93\u51fa\uff1a

    \n\n
    +-------------+------------+\n| follower    | num        |\n+-------------+------------+\n|     B       |  2         |\n|     D       |  1         |\n+-------------+------------+\n
    \n\n

    \u89e3\u91ca\uff1a

    \n\n

    B \u548c D \u90fd\u5728\u5728 follower \u5b57\u6bb5\u4e2d\u51fa\u73b0\uff0c\u4f5c\u4e3a\u88ab\u5173\u6ce8\u8005\uff0cB \u88ab C \u548c D \u5173\u6ce8\uff0cD \u88ab E \u5173\u6ce8\u3002A \u4e0d\u5728 follower \u5b57\u6bb5\u5185\uff0c\u6240\u4ee5A\u4e0d\u5728\u8f93\u51fa\u5217\u8868\u4e2d\u3002

    \n\n

     

    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    • \u88ab\u5173\u6ce8\u8005\u6c38\u8fdc\u4e0d\u4f1a\u88ab\u4ed6 / \u5979\u81ea\u5df1\u5173\u6ce8\u3002
    • \n\t
    • \u5c06\u7ed3\u679c\u6309\u7167\u5b57\u5178\u5e8f\u8fd4\u56de\u3002
    • \n
    \n\n

     

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0614](https://leetcode-cn.com/problems/second-degree-follower)", "[\u4e8c\u7ea7\u5173\u6ce8\u8005](/solution/0600-0699/0614.Second%20Degree%20Follower/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0614](https://leetcode.com/problems/second-degree-follower)", "[Second Degree Follower](/solution/0600-0699/0614.Second%20Degree%20Follower/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "0613", "frontend_question_id": "0613", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/shortest-distance-in-a-line", "url_en": "https://leetcode.com/problems/shortest-distance-in-a-line", "relative_path_cn": "/solution/0600-0699/0613.Shortest%20Distance%20in%20a%20Line/README.md", "relative_path_en": "/solution/0600-0699/0613.Shortest%20Distance%20in%20a%20Line/README_EN.md", "title_cn": "\u76f4\u7ebf\u4e0a\u7684\u6700\u8fd1\u8ddd\u79bb", "title_en": "Shortest Distance in a Line", "question_title_slug": "shortest-distance-in-a-line", "content_en": "Table point holds the x coordinate of some points on x-axis in a plane, which are all integers.\r\n

     

    \r\nWrite a query to find the shortest distance between two points in these points.\r\n\r\n

     

    \r\n\r\n
    \r\n| x   |\r\n|-----|\r\n| -1  |\r\n| 0   |\r\n| 2   |\r\n
    \r\n\r\n

     

    \r\nThe shortest distance is '1' obviously, which is from point '-1' to '0'. So the output is as below:\r\n\r\n

     

    \r\n\r\n
    \r\n| shortest|\r\n|---------|\r\n| 1       |\r\n
    \r\n\r\n

     

    \r\nNote: Every point is unique, which means there is no duplicates in table point.\r\n\r\n

     

    \r\nFollow-up: What if all these points have an id and are arranged from the left most to the right most of x axis?\r\n\r\n

     

    \r\n", "content_cn": "

    \u8868 point \u4fdd\u5b58\u4e86\u4e00\u4e9b\u70b9\u5728 x \u8f74\u4e0a\u7684\u5750\u6807\uff0c\u8fd9\u4e9b\u5750\u6807\u90fd\u662f\u6574\u6570\u3002

    \n\n

     

    \n\n

    \u5199\u4e00\u4e2a\u67e5\u8be2\u8bed\u53e5\uff0c\u627e\u5230\u8fd9\u4e9b\u70b9\u4e2d\u6700\u8fd1\u4e24\u4e2a\u70b9\u4e4b\u95f4\u7684\u8ddd\u79bb\u3002

    \n\n

     

    \n\n
    | x   |\n|-----|\n| -1  |\n| 0   |\n| 2   |\n
    \n\n

     

    \n\n

    \u6700\u8fd1\u8ddd\u79bb\u663e\u7136\u662f '1' \uff0c\u662f\u70b9 '-1' \u548c '0' \u4e4b\u95f4\u7684\u8ddd\u79bb\u3002\u6240\u4ee5\u8f93\u51fa\u5e94\u8be5\u5982\u4e0b\uff1a

    \n\n

     

    \n\n
    | shortest|\n|---------|\n| 1       |\n
    \n\n

     

    \n\n

    \u6ce8\u610f\uff1a\u6bcf\u4e2a\u70b9\u90fd\u4e0e\u5176\u4ed6\u70b9\u5750\u6807\u4e0d\u540c\uff0c\u8868 table \u4e0d\u4f1a\u6709\u91cd\u590d\u5750\u6807\u51fa\u73b0\u3002

    \n\n

     

    \n\n

    \u8fdb\u9636\uff1a\u5982\u679c\u8fd9\u4e9b\u70b9\u5728 x \u8f74\u4e0a\u4ece\u5de6\u5230\u53f3\u90fd\u6709\u4e00\u4e2a\u7f16\u53f7\uff0c\u8f93\u51fa\u7ed3\u679c\u65f6\u9700\u8981\u8f93\u51fa\u6700\u8fd1\u70b9\u5bf9\u7684\u7f16\u53f7\u5462\uff1f

    \n\n

     

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0613](https://leetcode-cn.com/problems/shortest-distance-in-a-line)", "[\u76f4\u7ebf\u4e0a\u7684\u6700\u8fd1\u8ddd\u79bb](/solution/0600-0699/0613.Shortest%20Distance%20in%20a%20Line/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0613](https://leetcode.com/problems/shortest-distance-in-a-line)", "[Shortest Distance in a Line](/solution/0600-0699/0613.Shortest%20Distance%20in%20a%20Line/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "0612", "frontend_question_id": "0612", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/shortest-distance-in-a-plane", "url_en": "https://leetcode.com/problems/shortest-distance-in-a-plane", "relative_path_cn": "/solution/0600-0699/0612.Shortest%20Distance%20in%20a%20Plane/README.md", "relative_path_en": "/solution/0600-0699/0612.Shortest%20Distance%20in%20a%20Plane/README_EN.md", "title_cn": "\u5e73\u9762\u4e0a\u7684\u6700\u8fd1\u8ddd\u79bb", "title_en": "Shortest Distance in a Plane", "question_title_slug": "shortest-distance-in-a-plane", "content_en": "Table point_2d holds the coordinates (x,y) of some unique points (more than two) in a plane.\r\n

     

    \r\nWrite a query to find the shortest distance between these points rounded to 2 decimals.\r\n\r\n

     

    \r\n\r\n
    \r\n| x  | y  |\r\n|----|----|\r\n| -1 | -1 |\r\n| 0  | 0  |\r\n| -1 | -2 |\r\n
    \r\n\r\n

     

    \r\nThe shortest distance is 1.00 from point (-1,-1) to (-1,2). So the output should be:\r\n\r\n

     

    \r\n\r\n
    \r\n| shortest |\r\n|----------|\r\n| 1.00     |\r\n
    \r\n\r\n

     

    \r\nNote: The longest distance among all the points are less than 10000.\r\n\r\n

     

    \r\n", "content_cn": "

    \u8868 point_2d \u4fdd\u5b58\u4e86\u6240\u6709\u70b9\uff08\u591a\u4e8e 2 \u4e2a\u70b9\uff09\u7684\u5750\u6807 (x,y) \uff0c\u8fd9\u4e9b\u70b9\u5728\u5e73\u9762\u4e0a\u4e24\u4e24\u4e0d\u91cd\u5408\u3002

    \n\n

     

    \n\n

    \u5199\u4e00\u4e2a\u67e5\u8be2\u8bed\u53e5\u627e\u5230\u4e24\u70b9\u4e4b\u95f4\u7684\u6700\u8fd1\u8ddd\u79bb\uff0c\u4fdd\u7559 2 \u4f4d\u5c0f\u6570\u3002

    \n\n

     

    \n\n
    | x  | y  |\n|----|----|\n| -1 | -1 |\n| 0  | 0  |\n| -1 | -2 |\n
    \n\n

     

    \n\n

    \u6700\u8fd1\u8ddd\u79bb\u5728\u70b9 (-1,-1) \u548c(-1,2) \u4e4b\u95f4\uff0c\u8ddd\u79bb\u4e3a 1.00 \u3002\u6240\u4ee5\u8f93\u51fa\u5e94\u8be5\u4e3a\uff1a

    \n\n

     

    \n\n
    | shortest |\n|----------|\n| 1.00     |\n
    \n\n

     

    \n\n

    \u6ce8\u610f\uff1a\u4efb\u610f\u70b9\u4e4b\u95f4\u7684\u6700\u8fdc\u8ddd\u79bb\u5c0f\u4e8e 10000 \u3002

    \n\n

     

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0612](https://leetcode-cn.com/problems/shortest-distance-in-a-plane)", "[\u5e73\u9762\u4e0a\u7684\u6700\u8fd1\u8ddd\u79bb](/solution/0600-0699/0612.Shortest%20Distance%20in%20a%20Plane/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0612](https://leetcode.com/problems/shortest-distance-in-a-plane)", "[Shortest Distance in a Plane](/solution/0600-0699/0612.Shortest%20Distance%20in%20a%20Plane/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "0611", "frontend_question_id": "0611", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/valid-triangle-number", "url_en": "https://leetcode.com/problems/valid-triangle-number", "relative_path_cn": "/solution/0600-0699/0611.Valid%20Triangle%20Number/README.md", "relative_path_en": "/solution/0600-0699/0611.Valid%20Triangle%20Number/README_EN.md", "title_cn": "\u6709\u6548\u4e09\u89d2\u5f62\u7684\u4e2a\u6570", "title_en": "Valid Triangle Number", "question_title_slug": "valid-triangle-number", "content_en": "

    Given an integer array nums, return the number of triplets chosen from the array that can make triangles if we take them as side lengths of a triangle.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [2,2,3,4]\nOutput: 3\nExplanation: Valid combinations are: \n2,3,4 (using the first 2)\n2,3,4 (using the second 2)\n2,2,3\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [4,2,3,4]\nOutput: 4\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 1000
    • \n\t
    • 0 <= nums[i] <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5305\u542b\u975e\u8d1f\u6574\u6570\u7684\u6570\u7ec4\uff0c\u4f60\u7684\u4efb\u52a1\u662f\u7edf\u8ba1\u5176\u4e2d\u53ef\u4ee5\u7ec4\u6210\u4e09\u89d2\u5f62\u4e09\u6761\u8fb9\u7684\u4e09\u5143\u7ec4\u4e2a\u6570\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: [2,2,3,4]\n\u8f93\u51fa: 3\n\u89e3\u91ca:\n\u6709\u6548\u7684\u7ec4\u5408\u662f: \n2,3,4 (\u4f7f\u7528\u7b2c\u4e00\u4e2a 2)\n2,3,4 (\u4f7f\u7528\u7b2c\u4e8c\u4e2a 2)\n2,2,3\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u6570\u7ec4\u957f\u5ea6\u4e0d\u8d85\u8fc71000\u3002
    2. \n\t
    3. \u6570\u7ec4\u91cc\u6574\u6570\u7684\u8303\u56f4\u4e3a [0, 1000]\u3002
    4. \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int triangleNumber(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int triangleNumber(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def triangleNumber(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def triangleNumber(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint triangleNumber(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int TriangleNumber(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar triangleNumber = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef triangle_number(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func triangleNumber(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func triangleNumber(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def triangleNumber(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun triangleNumber(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn triangle_number(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function triangleNumber($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function triangleNumber(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (triangle-number nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0611](https://leetcode-cn.com/problems/valid-triangle-number)", "[\u6709\u6548\u4e09\u89d2\u5f62\u7684\u4e2a\u6570](/solution/0600-0699/0611.Valid%20Triangle%20Number/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0611](https://leetcode.com/problems/valid-triangle-number)", "[Valid Triangle Number](/solution/0600-0699/0611.Valid%20Triangle%20Number/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0610", "frontend_question_id": "0610", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/triangle-judgement", "url_en": "https://leetcode.com/problems/triangle-judgement", "relative_path_cn": "/solution/0600-0699/0610.Triangle%20Judgement/README.md", "relative_path_en": "/solution/0600-0699/0610.Triangle%20Judgement/README_EN.md", "title_cn": "\u5224\u65ad\u4e09\u89d2\u5f62", "title_en": "Triangle Judgement", "question_title_slug": "triangle-judgement", "content_en": "A pupil Tim gets homework to identify whether three line segments could possibly form a triangle.\r\n

     

    \r\nHowever, this assignment is very heavy because there are hundreds of records to calculate.\r\n\r\n

     

    \r\nCould you help Tim by writing a query to judge whether these three sides can form a triangle, assuming table triangle holds the length of the three sides x, y and z.\r\n\r\n

     

    \r\n\r\n
    \r\n| x  | y  | z  |\r\n|----|----|----|\r\n| 13 | 15 | 30 |\r\n| 10 | 20 | 15 |\r\n
    \r\nFor the sample data above, your query should return the follow result:\r\n\r\n
    \r\n| x  | y  | z  | triangle |\r\n|----|----|----|----------|\r\n| 13 | 15 | 30 | No       |\r\n| 10 | 20 | 15 | Yes      |\r\n
    \r\n", "content_cn": "

    \u4e00\u4e2a\u5c0f\u5b66\u751f Tim \u7684\u4f5c\u4e1a\u662f\u5224\u65ad\u4e09\u6761\u7ebf\u6bb5\u662f\u5426\u80fd\u5f62\u6210\u4e00\u4e2a\u4e09\u89d2\u5f62\u3002

    \n\n

    \u7136\u800c\uff0c\u8fd9\u4e2a\u4f5c\u4e1a\u975e\u5e38\u7e41\u91cd\uff0c\u56e0\u4e3a\u6709\u51e0\u767e\u7ec4\u7ebf\u6bb5\u9700\u8981\u5224\u65ad\u3002

    \n\n

    \u5047\u8bbe\u8868 triangle\u00a0\u4fdd\u5b58\u4e86\u6240\u6709\u4e09\u6761\u7ebf\u6bb5\u7684\u957f\u5ea6 x\u3001y\u3001z \uff0c\u8bf7\u4f60\u5e2e Tim \u5199\u4e00\u4e2a\u67e5\u8be2\u8bed\u53e5\uff0c\u6765\u5224\u65ad\u6bcf\u7ec4 x\u3001y\u3001z \u662f\u5426\u53ef\u4ee5\u7ec4\u6210\u4e00\u4e2a\u4e09\u89d2\u5f62\uff1f

    \n\n

    \u00a0

    \n\n
    \n| x  | y  | z  |\n|----|----|----|\n| 13 | 15 | 30 |\n| 10 | 20 | 15 |\n
    \n\n

    \u5bf9\u4e8e\u5982\u4e0a\u6837\u4f8b\u6570\u636e\uff0c\u4f60\u7684\u67e5\u8be2\u8bed\u53e5\u5e94\u8be5\u8fd4\u56de\u5982\u4e0b\u7ed3\u679c\uff1a

    \n\n
    \n| x  | y  | z  | triangle |\n|----|----|----|----------|\n| 13 | 15 | 30 | No       |\n| 10 | 20 | 15 | Yes      |\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0610](https://leetcode-cn.com/problems/triangle-judgement)", "[\u5224\u65ad\u4e09\u89d2\u5f62](/solution/0600-0699/0610.Triangle%20Judgement/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0610](https://leetcode.com/problems/triangle-judgement)", "[Triangle Judgement](/solution/0600-0699/0610.Triangle%20Judgement/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "0609", "frontend_question_id": "0609", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-duplicate-file-in-system", "url_en": "https://leetcode.com/problems/find-duplicate-file-in-system", "relative_path_cn": "/solution/0600-0699/0609.Find%20Duplicate%20File%20in%20System/README.md", "relative_path_en": "/solution/0600-0699/0609.Find%20Duplicate%20File%20in%20System/README_EN.md", "title_cn": "\u5728\u7cfb\u7edf\u4e2d\u67e5\u627e\u91cd\u590d\u6587\u4ef6", "title_en": "Find Duplicate File in System", "question_title_slug": "find-duplicate-file-in-system", "content_en": "

    Given a list paths of directory info, including the directory path, and all the files with contents in this directory, return all the duplicate files in the file system in terms of their paths. You may return the answer in any order.

    \n\n

    A group of duplicate files consists of at least two files that have the same content.

    \n\n

    A single directory info string in the input list has the following format:

    \n\n
      \n\t
    • "root/d1/d2/.../dm f1.txt(f1_content) f2.txt(f2_content) ... fn.txt(fn_content)"
    • \n
    \n\n

    It means there are n files (f1.txt, f2.txt ... fn.txt) with content (f1_content, f2_content ... fn_content) respectively in the directory "root/d1/d2/.../dm". Note that n >= 1 and m >= 0. If m = 0, it means the directory is just the root directory.

    \n\n

    The output is a list of groups of duplicate file paths. For each group, it contains all the file paths of the files that have the same content. A file path is a string that has the following format:

    \n\n
      \n\t
    • "directory_path/file_name.txt"
    • \n
    \n\n

     

    \n

    Example 1:

    \n
    Input: paths = [\"root/a 1.txt(abcd) 2.txt(efgh)\",\"root/c 3.txt(abcd)\",\"root/c/d 4.txt(efgh)\",\"root 4.txt(efgh)\"]\nOutput: [[\"root/a/2.txt\",\"root/c/d/4.txt\",\"root/4.txt\"],[\"root/a/1.txt\",\"root/c/3.txt\"]]\n

    Example 2:

    \n
    Input: paths = [\"root/a 1.txt(abcd) 2.txt(efgh)\",\"root/c 3.txt(abcd)\",\"root/c/d 4.txt(efgh)\"]\nOutput: [[\"root/a/2.txt\",\"root/c/d/4.txt\"],[\"root/a/1.txt\",\"root/c/3.txt\"]]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= paths.length <= 2 * 104
    • \n\t
    • 1 <= paths[i].length <= 3000
    • \n\t
    • 1 <= sum(paths[i].length) <= 5 * 105
    • \n\t
    • paths[i] consist of English letters, digits, '/', '.', '(', ')', and ' '.
    • \n\t
    • You may assume no files or directories share the same name in the same directory.
    • \n\t
    • You may assume each given directory info represents a unique directory. A single blank space separates the directory path and file info.
    • \n
    \n\n

     

    \n

    Follow up:

    \n\n
      \n\t
    • Imagine you are given a real file system, how will you search files? DFS or BFS?
    • \n\t
    • If the file content is very large (GB level), how will you modify your solution?
    • \n\t
    • If you can only read the file by 1kb each time, how will you modify your solution?
    • \n\t
    • What is the time complexity of your modified solution? What is the most time-consuming part and memory-consuming part of it? How to optimize?
    • \n\t
    • How to make sure the duplicated files you find are not false positive?
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u76ee\u5f55\u4fe1\u606f\u5217\u8868\uff0c\u5305\u62ec\u76ee\u5f55\u8def\u5f84\uff0c\u4ee5\u53ca\u8be5\u76ee\u5f55\u4e2d\u7684\u6240\u6709\u5305\u542b\u5185\u5bb9\u7684\u6587\u4ef6\uff0c\u60a8\u9700\u8981\u627e\u5230\u6587\u4ef6\u7cfb\u7edf\u4e2d\u7684\u6240\u6709\u91cd\u590d\u6587\u4ef6\u7ec4\u7684\u8def\u5f84\u3002\u4e00\u7ec4\u91cd\u590d\u7684\u6587\u4ef6\u81f3\u5c11\u5305\u62ec\u4e8c\u4e2a\u5177\u6709\u5b8c\u5168\u76f8\u540c\u5185\u5bb9\u7684\u6587\u4ef6\u3002

    \n\n

    \u8f93\u5165\u5217\u8868\u4e2d\u7684\u5355\u4e2a\u76ee\u5f55\u4fe1\u606f\u5b57\u7b26\u4e32\u7684\u683c\u5f0f\u5982\u4e0b\uff1a

    \n\n

    "root/d1/d2/.../dm f1.txt(f1_content) f2.txt(f2_content) ... fn.txt(fn_content)"

    \n\n

    \u8fd9\u610f\u5473\u7740\u6709 n \u4e2a\u6587\u4ef6\uff08f1.txtf2.txt ... fn.txt \u7684\u5185\u5bb9\u5206\u522b\u662f f1_contentf2_content ... fn_content\uff09\u5728\u76ee\u5f55 root/d1/d2/.../dm \u4e0b\u3002\u6ce8\u610f\uff1an>=1 \u4e14 m>=0\u3002\u5982\u679c m=0\uff0c\u5219\u8868\u793a\u8be5\u76ee\u5f55\u662f\u6839\u76ee\u5f55\u3002

    \n\n

    \u8be5\u8f93\u51fa\u662f\u91cd\u590d\u6587\u4ef6\u8def\u5f84\u7ec4\u7684\u5217\u8868\u3002\u5bf9\u4e8e\u6bcf\u4e2a\u7ec4\uff0c\u5b83\u5305\u542b\u5177\u6709\u76f8\u540c\u5185\u5bb9\u7684\u6587\u4ef6\u7684\u6240\u6709\u6587\u4ef6\u8def\u5f84\u3002\u6587\u4ef6\u8def\u5f84\u662f\u5177\u6709\u4e0b\u5217\u683c\u5f0f\u7684\u5b57\u7b26\u4e32\uff1a

    \n\n

    "directory_path/file_name.txt"

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a\n["root/a 1.txt(abcd) 2.txt(efgh)", "root/c 3.txt(abcd)", "root/c/d 4.txt(efgh)", "root 4.txt(efgh)"]\n\u8f93\u51fa\uff1a  \n[["root/a/2.txt","root/c/d/4.txt","root/4.txt"],["root/a/1.txt","root/c/3.txt"]]\n
    \n\n

     

    \n\n

    \u6ce8\uff1a

    \n\n
      \n\t
    1. \u6700\u7ec8\u8f93\u51fa\u4e0d\u9700\u8981\u987a\u5e8f\u3002
    2. \n\t
    3. \u60a8\u53ef\u4ee5\u5047\u8bbe\u76ee\u5f55\u540d\u3001\u6587\u4ef6\u540d\u548c\u6587\u4ef6\u5185\u5bb9\u53ea\u6709\u5b57\u6bcd\u548c\u6570\u5b57\uff0c\u5e76\u4e14\u6587\u4ef6\u5185\u5bb9\u7684\u957f\u5ea6\u5728 [1\uff0c50] \u7684\u8303\u56f4\u5185\u3002
    4. \n\t
    5. \u7ed9\u5b9a\u7684\u6587\u4ef6\u6570\u91cf\u5728 [1\uff0c20000] \u4e2a\u8303\u56f4\u5185\u3002
    6. \n\t
    7. \u60a8\u53ef\u4ee5\u5047\u8bbe\u5728\u540c\u4e00\u76ee\u5f55\u4e2d\u6ca1\u6709\u4efb\u4f55\u6587\u4ef6\u6216\u76ee\u5f55\u5171\u4eab\u76f8\u540c\u7684\u540d\u79f0\u3002
    8. \n\t
    9. \u60a8\u53ef\u4ee5\u5047\u8bbe\u6bcf\u4e2a\u7ed9\u5b9a\u7684\u76ee\u5f55\u4fe1\u606f\u4ee3\u8868\u4e00\u4e2a\u552f\u4e00\u7684\u76ee\u5f55\u3002\u76ee\u5f55\u8def\u5f84\u548c\u6587\u4ef6\u4fe1\u606f\u7528\u4e00\u4e2a\u7a7a\u683c\u5206\u9694\u3002
    10. \n
    \n\n

     

    \n\n

    \u8d85\u8d8a\u7ade\u8d5b\u7684\u540e\u7eed\u884c\u52a8\uff1a

    \n\n
      \n\t
    1. \u5047\u8bbe\u60a8\u6709\u4e00\u4e2a\u771f\u6b63\u7684\u6587\u4ef6\u7cfb\u7edf\uff0c\u60a8\u5c06\u5982\u4f55\u641c\u7d22\u6587\u4ef6\uff1f\u5e7f\u5ea6\u641c\u7d22\u8fd8\u662f\u5bbd\u5ea6\u641c\u7d22\uff1f
    2. \n\t
    3. \u5982\u679c\u6587\u4ef6\u5185\u5bb9\u975e\u5e38\u5927\uff08GB\u7ea7\u522b\uff09\uff0c\u60a8\u5c06\u5982\u4f55\u4fee\u6539\u60a8\u7684\u89e3\u51b3\u65b9\u6848\uff1f
    4. \n\t
    5. \u5982\u679c\u6bcf\u6b21\u53ea\u80fd\u8bfb\u53d6 1 kb \u7684\u6587\u4ef6\uff0c\u60a8\u5c06\u5982\u4f55\u4fee\u6539\u89e3\u51b3\u65b9\u6848\uff1f
    6. \n\t
    7. \u4fee\u6539\u540e\u7684\u89e3\u51b3\u65b9\u6848\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u662f\u591a\u5c11\uff1f\u5176\u4e2d\u6700\u8017\u65f6\u7684\u90e8\u5206\u548c\u6d88\u8017\u5185\u5b58\u7684\u90e8\u5206\u662f\u4ec0\u4e48\uff1f\u5982\u4f55\u4f18\u5316\uff1f
    8. \n\t
    9. \u5982\u4f55\u786e\u4fdd\u60a8\u53d1\u73b0\u7684\u91cd\u590d\u6587\u4ef6\u4e0d\u662f\u8bef\u62a5\uff1f
    10. \n
    \n", "tags_en": ["Hash Table", "String"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> findDuplicate(vector& paths) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> findDuplicate(String[] paths) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findDuplicate(self, paths):\n \"\"\"\n :type paths: List[str]\n :rtype: List[List[str]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findDuplicate(self, paths: List[str]) -> List[List[str]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nchar *** findDuplicate(char ** paths, int pathsSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> FindDuplicate(string[] paths) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} paths\n * @return {string[][]}\n */\nvar findDuplicate = function(paths) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} paths\n# @return {String[][]}\ndef find_duplicate(paths)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findDuplicate(_ paths: [String]) -> [[String]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findDuplicate(paths []string) [][]string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findDuplicate(paths: Array[String]): List[List[String]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findDuplicate(paths: Array): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_duplicate(paths: Vec) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $paths\n * @return String[][]\n */\n function findDuplicate($paths) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findDuplicate(paths: string[]): string[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-duplicate paths)\n (-> (listof string?) (listof (listof string?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0609](https://leetcode-cn.com/problems/find-duplicate-file-in-system)", "[\u5728\u7cfb\u7edf\u4e2d\u67e5\u627e\u91cd\u590d\u6587\u4ef6](/solution/0600-0699/0609.Find%20Duplicate%20File%20in%20System/README.md)", "`\u54c8\u5e0c\u8868`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0609](https://leetcode.com/problems/find-duplicate-file-in-system)", "[Find Duplicate File in System](/solution/0600-0699/0609.Find%20Duplicate%20File%20in%20System/README_EN.md)", "`Hash Table`,`String`", "Medium", ""]}, {"question_id": "0608", "frontend_question_id": "0608", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/tree-node", "url_en": "https://leetcode.com/problems/tree-node", "relative_path_cn": "/solution/0600-0699/0608.Tree%20Node/README.md", "relative_path_en": "/solution/0600-0699/0608.Tree%20Node/README_EN.md", "title_cn": "\u6811\u8282\u70b9", "title_en": "Tree Node", "question_title_slug": "tree-node", "content_en": "

    Given a table tree, id is identifier of the tree node and p_id is its parent node's id.

    \r\n\r\n
    \r\n+----+------+\r\n| id | p_id |\r\n+----+------+\r\n| 1  | null |\r\n| 2  | 1    |\r\n| 3  | 1    |\r\n| 4  | 2    |\r\n| 5  | 2    |\r\n+----+------+\r\n
    \r\nEach node in the tree can be one of three types:\r\n\r\n
      \r\n\t
    • Leaf: if the node is a leaf node.
    • \r\n\t
    • Root: if the node is the root of the tree.
    • \r\n\t
    • Inner: If the node is neither a leaf node nor a root node.
    • \r\n
    \r\n\r\n

     

    \r\nWrite a query to print the node id and the type of the node. Sort your output by the node id. The result for the above sample is:\r\n\r\n

     

    \r\n\r\n
    \r\n+----+------+\r\n| id | Type |\r\n+----+------+\r\n| 1  | Root |\r\n| 2  | Inner|\r\n| 3  | Leaf |\r\n| 4  | Leaf |\r\n| 5  | Leaf |\r\n+----+------+\r\n
    \r\n\r\n

     

    \r\n\r\n

    Explanation

    \r\n\r\n

     

    \r\n\r\n
      \r\n\t
    • Node '1' is root node, because its parent node is NULL and it has child node '2' and '3'.
    • \r\n\t
    • Node '2' is inner node, because it has parent node '1' and child node '4' and '5'.
    • \r\n\t
    • Node '3', '4' and '5' is Leaf node, because they have parent node and they don't have child node.
    • \r\n\t
      \r\n\t
    • And here is the image of the sample tree as below:\r\n\t

       

      \r\n\r\n\t
      \r\n\t\t\t  1\r\n\t\t\t/   \\\r\n                      2       3\r\n                    /   \\\r\n                  4       5\r\n
      \r\n\r\n\t

      Note

      \r\n\r\n\t

      If there is only one node on the tree, you only need to output its root attributes.

      \r\n\t
    • \r\n
    \r\n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u8868 tree\uff0cid \u662f\u6811\u8282\u70b9\u7684\u7f16\u53f7\uff0c p_id \u662f\u5b83\u7236\u8282\u70b9\u7684 id \u3002

    \n\n
    +----+------+\n| id | p_id |\n+----+------+\n| 1  | null |\n| 2  | 1    |\n| 3  | 1    |\n| 4  | 2    |\n| 5  | 2    |\n+----+------+
    \n\n

    \u6811\u4e2d\u6bcf\u4e2a\u8282\u70b9\u5c5e\u4e8e\u4ee5\u4e0b\u4e09\u79cd\u7c7b\u578b\u4e4b\u4e00\uff1a

    \n\n
      \n\t
    • \u53f6\u5b50\uff1a\u5982\u679c\u8fd9\u4e2a\u8282\u70b9\u6ca1\u6709\u4efb\u4f55\u5b69\u5b50\u8282\u70b9\u3002
    • \n\t
    • \u6839\uff1a\u5982\u679c\u8fd9\u4e2a\u8282\u70b9\u662f\u6574\u68f5\u6811\u7684\u6839\uff0c\u5373\u6ca1\u6709\u7236\u8282\u70b9\u3002
    • \n\t
    • \u5185\u90e8\u8282\u70b9\uff1a\u5982\u679c\u8fd9\u4e2a\u8282\u70b9\u65e2\u4e0d\u662f\u53f6\u5b50\u8282\u70b9\u4e5f\u4e0d\u662f\u6839\u8282\u70b9\u3002
    • \n
    \n\n

     

    \n\n

    \u5199\u4e00\u4e2a\u67e5\u8be2\u8bed\u53e5\uff0c\u8f93\u51fa\u6240\u6709\u8282\u70b9\u7684\u7f16\u53f7\u548c\u8282\u70b9\u7684\u7c7b\u578b\uff0c\u5e76\u5c06\u7ed3\u679c\u6309\u7167\u8282\u70b9\u7f16\u53f7\u6392\u5e8f\u3002\u4e0a\u9762\u6837\u4f8b\u7684\u7ed3\u679c\u4e3a\uff1a

    \n\n

     

    \n\n
    +----+------+\n| id | Type |\n+----+------+\n| 1  | Root |\n| 2  | Inner|\n| 3  | Leaf |\n| 4  | Leaf |\n| 5  | Leaf |\n+----+------+\n
    \n\n

     

    \n\n

    \u89e3\u91ca

    \n\n
      \n\t
    • \u8282\u70b9 '1' \u662f\u6839\u8282\u70b9\uff0c\u56e0\u4e3a\u5b83\u7684\u7236\u8282\u70b9\u662f NULL \uff0c\u540c\u65f6\u5b83\u6709\u5b69\u5b50\u8282\u70b9 '2' \u548c '3' \u3002
    • \n\t
    • \u8282\u70b9 '2' \u662f\u5185\u90e8\u8282\u70b9\uff0c\u56e0\u4e3a\u5b83\u6709\u7236\u8282\u70b9 '1' \uff0c\u4e5f\u6709\u5b69\u5b50\u8282\u70b9 '4' \u548c '5' \u3002
    • \n\t
    • \u8282\u70b9 '3', '4' \u548c '5' \u90fd\u662f\u53f6\u5b50\u8282\u70b9\uff0c\u56e0\u4e3a\u5b83\u4eec\u90fd\u6709\u7236\u8282\u70b9\u540c\u65f6\u6ca1\u6709\u5b69\u5b50\u8282\u70b9\u3002
    • \n\t
    • \u6837\u4f8b\u4e2d\u6811\u7684\u5f62\u6001\u5982\u4e0b\uff1a\n\t

       

      \n\n\t
      \t\t\t  1\n\t\t\t/   \\\n                      2       3\n                    /   \\\n                  4       5\n
      \n\n\t

       

      \n\t
    • \n
    \n\n

    \u6ce8\u610f

    \n\n

    \u5982\u679c\u6811\u4e2d\u53ea\u6709\u4e00\u4e2a\u8282\u70b9\uff0c\u4f60\u53ea\u9700\u8981\u8f93\u51fa\u5b83\u7684\u6839\u5c5e\u6027\u3002

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0608](https://leetcode-cn.com/problems/tree-node)", "[\u6811\u8282\u70b9](/solution/0600-0699/0608.Tree%20Node/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0608](https://leetcode.com/problems/tree-node)", "[Tree Node](/solution/0600-0699/0608.Tree%20Node/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "0607", "frontend_question_id": "0607", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/sales-person", "url_en": "https://leetcode.com/problems/sales-person", "relative_path_cn": "/solution/0600-0699/0607.Sales%20Person/README.md", "relative_path_en": "/solution/0600-0699/0607.Sales%20Person/README_EN.md", "title_cn": "\u9500\u552e\u5458", "title_en": "Sales Person", "question_title_slug": "sales-person", "content_en": "

    Description

    \n\n

    Given three tables: salesperson, company, orders.
    \nOutput all the names in the table salesperson, who didn’t have sales to company 'RED'.

    \n\n

    Example
    \nInput

    \n\n

    Table: salesperson

    \n\n
    \n+----------+------+--------+-----------------+-----------+\n| sales_id | name | salary | commission_rate | hire_date |\n+----------+------+--------+-----------------+-----------+\n|   1      | John | 100000 |     6           | 4/1/2006  |\n|   2      | Amy  | 120000 |     5           | 5/1/2010  |\n|   3      | Mark | 65000  |     12          | 12/25/2008|\n|   4      | Pam  | 25000  |     25          | 1/1/2005  |\n|   5      | Alex | 50000  |     10          | 2/3/2007  |\n+----------+------+--------+-----------------+-----------+\n
    \nThe table salesperson holds the salesperson information. Every salesperson has a sales_id and a name.\n\n

    Table: company

    \n\n
    \n+---------+--------+------------+\n| com_id  |  name  |    city    |\n+---------+--------+------------+\n|   1     |  RED   |   Boston   |\n|   2     | ORANGE |   New York |\n|   3     | YELLOW |   Boston   |\n|   4     | GREEN  |   Austin   |\n+---------+--------+------------+\n
    \nThe table company holds the company information. Every company has a com_id and a name.\n\n

    Table: orders

    \n\n
    \n+----------+------------+---------+----------+--------+\n| order_id | order_date | com_id  | sales_id | amount |\n+----------+------------+---------+----------+--------+\n| 1        |   1/1/2014 |    3    |    4     | 100000 |\n| 2        |   2/1/2014 |    4    |    5     | 5000   |\n| 3        |   3/1/2014 |    1    |    1     | 50000  |\n| 4        |   4/1/2014 |    1    |    4     | 25000  |\n+----------+----------+---------+----------+--------+\n
    \nThe table orders holds the sales record information, salesperson and customer company are represented by sales_id and com_id.\n\n

    output

    \n\n
    \n+------+\n| name | \n+------+\n| Amy  | \n| Mark | \n| Alex |\n+------+\n
    \n\n

    Explanation

    \n\n

    According to order '3' and '4' in table orders, it is easy to tell only salesperson 'John' and 'Pam' have sales to company 'RED',
    \nso we need to output all the other names in the table salesperson.

    \n", "content_cn": "

    \u63cf\u8ff0

    \n\n

    \u7ed9\u5b9a 3 \u4e2a\u8868\uff1a salesperson\uff0c company\uff0c orders\u3002
    \n\u8f93\u51fa\u6240\u6709\u8868 salesperson \u4e2d\uff0c\u6ca1\u6709\u5411\u516c\u53f8 'RED' \u9500\u552e\u4efb\u4f55\u4e1c\u897f\u7684\u9500\u552e\u5458\u3002

    \n\n

    \u793a\u4f8b\uff1a
    \n\u8f93\u5165

    \n\n

    \u8868\uff1a salesperson

    \n\n
    +----------+------+--------+-----------------+-----------+\n| sales_id | name | salary | commission_rate | hire_date |\n+----------+------+--------+-----------------+-----------+\n|   1      | John | 100000 |     6           | 4/1/2006  |\n|   2      | Amy  | 120000 |     5           | 5/1/2010  |\n|   3      | Mark | 65000  |     12          | 12/25/2008|\n|   4      | Pam  | 25000  |     25          | 1/1/2005  |\n|   5      | Alex | 50000  |     10          | 2/3/2007  |\n+----------+------+--------+-----------------+-----------+\n
    \n\n

    \u8868 salesperson \u5b58\u50a8\u4e86\u6240\u6709\u9500\u552e\u5458\u7684\u4fe1\u606f\u3002\u6bcf\u4e2a\u9500\u552e\u5458\u90fd\u6709\u4e00\u4e2a\u9500\u552e\u5458\u7f16\u53f7 sales_id \u548c\u4ed6\u7684\u540d\u5b57 name \u3002

    \n\n

    \u8868\uff1a company

    \n\n
    +---------+--------+------------+\n| com_id  |  name  |    city    |\n+---------+--------+------------+\n|   1     |  RED   |   Boston   |\n|   2     | ORANGE |   New York |\n|   3     | YELLOW |   Boston   |\n|   4     | GREEN  |   Austin   |\n+---------+--------+------------+\n
    \n\n

    \u8868 company \u5b58\u50a8\u4e86\u6240\u6709\u516c\u53f8\u7684\u4fe1\u606f\u3002\u6bcf\u4e2a\u516c\u53f8\u90fd\u6709\u4e00\u4e2a\u516c\u53f8\u7f16\u53f7 com_id \u548c\u5b83\u7684\u540d\u5b57 name \u3002

    \n\n

    \u8868\uff1a orders

    \n\n
    +----------+------------+---------+----------+--------+\n| order_id | order_date | com_id  | sales_id | amount |\n+----------+------------+---------+----------+--------+\n| 1        |   1/1/2014 |    3    |    4     | 100000 |\n| 2        |   2/1/2014 |    4    |    5     | 5000   |\n| 3        |   3/1/2014 |    1    |    1     | 50000  |\n| 4        |   4/1/2014 |    1    |    4     | 25000  |\n+----------+----------+---------+----------+--------+\n
    \n\n

    \u8868 orders \u5b58\u50a8\u4e86\u6240\u6709\u7684\u9500\u552e\u6570\u636e\uff0c\u5305\u62ec\u9500\u552e\u5458\u7f16\u53f7 sales_id \u548c\u516c\u53f8\u7f16\u53f7 com_id \u3002

    \n\n

    \u8f93\u51fa

    \n\n
    +------+\n| name | \n+------+\n| Amy  | \n| Mark | \n| Alex |\n+------+\n
    \n\n

    \u89e3\u91ca

    \n\n

    \u6839\u636e\u8868 orders \u4e2d\u7684\u8ba2\u5355 '3' \u548c '4' \uff0c\u5bb9\u6613\u770b\u51fa\u53ea\u6709 'John' \u548c 'Pam' \u4e24\u4e2a\u9500\u552e\u5458\u66fe\u7ecf\u5411\u516c\u53f8 'RED' \u9500\u552e\u8fc7\u3002

    \n\n

    \u6240\u4ee5\u6211\u4eec\u9700\u8981\u8f93\u51fa\u8868 salesperson \u4e2d\u6240\u6709\u5176\u4ed6\u4eba\u7684\u540d\u5b57\u3002

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0607](https://leetcode-cn.com/problems/sales-person)", "[\u9500\u552e\u5458](/solution/0600-0699/0607.Sales%20Person/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0607](https://leetcode.com/problems/sales-person)", "[Sales Person](/solution/0600-0699/0607.Sales%20Person/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "0606", "frontend_question_id": "0606", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/construct-string-from-binary-tree", "url_en": "https://leetcode.com/problems/construct-string-from-binary-tree", "relative_path_cn": "/solution/0600-0699/0606.Construct%20String%20from%20Binary%20Tree/README.md", "relative_path_en": "/solution/0600-0699/0606.Construct%20String%20from%20Binary%20Tree/README_EN.md", "title_cn": "\u6839\u636e\u4e8c\u53c9\u6811\u521b\u5efa\u5b57\u7b26\u4e32", "title_en": "Construct String from Binary Tree", "question_title_slug": "construct-string-from-binary-tree", "content_en": "

    Given the root of a binary tree, construct a string consists of parenthesis and integers from a binary tree with the preorder traversing way, and return it.

    \n\n

    Omit all the empty parenthesis pairs that do not affect the one-to-one mapping relationship between the string and the original binary tree.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,2,3,4]\nOutput: "1(2(4))(3)"\nExplanation: Originallay it needs to be "1(2(4)())(3()())", but you need to omit all the unnecessary empty parenthesis pairs. And it will be "1(2(4))(3)"\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [1,2,3,null,4]\nOutput: "1(2()(4))(3)"\nExplanation: Almost the same as the first example, except we cannot omit the first parenthesis pair to break the one-to-one mapping relationship between the input and the output.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 104].
    • \n\t
    • -1000 <= Node.val <= 1000
    • \n
    \n", "content_cn": "

    \u4f60\u9700\u8981\u91c7\u7528\u524d\u5e8f\u904d\u5386\u7684\u65b9\u5f0f\uff0c\u5c06\u4e00\u4e2a\u4e8c\u53c9\u6811\u8f6c\u6362\u6210\u4e00\u4e2a\u7531\u62ec\u53f7\u548c\u6574\u6570\u7ec4\u6210\u7684\u5b57\u7b26\u4e32\u3002

    \n\n

    \u7a7a\u8282\u70b9\u5219\u7528\u4e00\u5bf9\u7a7a\u62ec\u53f7 "()" \u8868\u793a\u3002\u800c\u4e14\u4f60\u9700\u8981\u7701\u7565\u6240\u6709\u4e0d\u5f71\u54cd\u5b57\u7b26\u4e32\u4e0e\u539f\u59cb\u4e8c\u53c9\u6811\u4e4b\u95f4\u7684\u4e00\u5bf9\u4e00\u6620\u5c04\u5173\u7cfb\u7684\u7a7a\u62ec\u53f7\u5bf9\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: \u4e8c\u53c9\u6811: [1,2,3,4]\n       1\n     /   \\\n    2     3\n   /    \n  4     \n\n\u8f93\u51fa: "1(2(4))(3)"\n\n\u89e3\u91ca: \u539f\u672c\u5c06\u662f“1(2(4)())(3())”\uff0c\n\u5728\u4f60\u7701\u7565\u6240\u6709\u4e0d\u5fc5\u8981\u7684\u7a7a\u62ec\u53f7\u5bf9\u4e4b\u540e\uff0c\n\u5b83\u5c06\u662f“1(2(4))(3)”\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: \u4e8c\u53c9\u6811: [1,2,3,null,4]\n       1\n     /   \\\n    2     3\n     \\  \n      4 \n\n\u8f93\u51fa: "1(2()(4))(3)"\n\n\u89e3\u91ca: \u548c\u7b2c\u4e00\u4e2a\u793a\u4f8b\u76f8\u4f3c\uff0c\n\u9664\u4e86\u6211\u4eec\u4e0d\u80fd\u7701\u7565\u7b2c\u4e00\u4e2a\u5bf9\u62ec\u53f7\u6765\u4e2d\u65ad\u8f93\u5165\u548c\u8f93\u51fa\u4e4b\u95f4\u7684\u4e00\u5bf9\u4e00\u6620\u5c04\u5173\u7cfb\u3002\n
    \n", "tags_en": ["Tree", "String"], "tags_cn": ["\u6811", "\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n string tree2str(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public String tree2str(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def tree2str(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def tree2str(self, root: TreeNode) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nchar * tree2str(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public string Tree2str(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {string}\n */\nvar tree2str = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {String}\ndef tree2str(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func tree2str(_ root: TreeNode?) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc tree2str(root *TreeNode) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def tree2str(root: TreeNode): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun tree2str(root: TreeNode?): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn tree2str(root: Option>>) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return String\n */\n function tree2str($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction tree2str(root: TreeNode | null): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (tree2str root)\n (-> (or/c tree-node? #f) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0606](https://leetcode-cn.com/problems/construct-string-from-binary-tree)", "[\u6839\u636e\u4e8c\u53c9\u6811\u521b\u5efa\u5b57\u7b26\u4e32](/solution/0600-0699/0606.Construct%20String%20from%20Binary%20Tree/README.md)", "`\u6811`,`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0606](https://leetcode.com/problems/construct-string-from-binary-tree)", "[Construct String from Binary Tree](/solution/0600-0699/0606.Construct%20String%20from%20Binary%20Tree/README_EN.md)", "`Tree`,`String`", "Easy", ""]}, {"question_id": "0605", "frontend_question_id": "0605", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/can-place-flowers", "url_en": "https://leetcode.com/problems/can-place-flowers", "relative_path_cn": "/solution/0600-0699/0605.Can%20Place%20Flowers/README.md", "relative_path_en": "/solution/0600-0699/0605.Can%20Place%20Flowers/README_EN.md", "title_cn": "\u79cd\u82b1\u95ee\u9898", "title_en": "Can Place Flowers", "question_title_slug": "can-place-flowers", "content_en": "

    You have a long flowerbed in which some of the plots are planted, and some are not. However, flowers cannot be planted in adjacent plots.

    \n\n

    Given an integer array flowerbed containing 0's and 1's, where 0 means empty and 1 means not empty, and an integer n, return if n new flowers can be planted in the flowerbed without violating the no-adjacent-flowers rule.

    \n\n

     

    \n

    Example 1:

    \n
    Input: flowerbed = [1,0,0,0,1], n = 1\nOutput: true\n

    Example 2:

    \n
    Input: flowerbed = [1,0,0,0,1], n = 2\nOutput: false\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= flowerbed.length <= 2 * 104
    • \n\t
    • flowerbed[i] is 0 or 1.
    • \n\t
    • There are no two adjacent flowers in flowerbed.
    • \n\t
    • 0 <= n <= flowerbed.length
    • \n
    \n", "content_cn": "

    \u5047\u8bbe\u6709\u4e00\u4e2a\u5f88\u957f\u7684\u82b1\u575b\uff0c\u4e00\u90e8\u5206\u5730\u5757\u79cd\u690d\u4e86\u82b1\uff0c\u53e6\u4e00\u90e8\u5206\u5374\u6ca1\u6709\u3002\u53ef\u662f\uff0c\u82b1\u4e0d\u80fd\u79cd\u690d\u5728\u76f8\u90bb\u7684\u5730\u5757\u4e0a\uff0c\u5b83\u4eec\u4f1a\u4e89\u593a\u6c34\u6e90\uff0c\u4e24\u8005\u90fd\u4f1a\u6b7b\u53bb\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0\u00a0flowerbed \u8868\u793a\u82b1\u575b\uff0c\u7531\u82e5\u5e72 0 \u548c 1 \u7ec4\u6210\uff0c\u5176\u4e2d 0 \u8868\u793a\u6ca1\u79cd\u690d\u82b1\uff0c1 \u8868\u793a\u79cd\u690d\u4e86\u82b1\u3002\u53e6\u6709\u4e00\u4e2a\u6570\u00a0n \uff0c\u80fd\u5426\u5728\u4e0d\u6253\u7834\u79cd\u690d\u89c4\u5219\u7684\u60c5\u51b5\u4e0b\u79cd\u5165\u00a0n\u00a0\u6735\u82b1\uff1f\u80fd\u5219\u8fd4\u56de true \uff0c\u4e0d\u80fd\u5219\u8fd4\u56de false\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aflowerbed = [1,0,0,0,1], n = 1\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aflowerbed = [1,0,0,0,1], n = 2\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= flowerbed.length <= 2 * 104
    • \n\t
    • flowerbed[i] \u4e3a 0 \u6216 1
    • \n\t
    • flowerbed \u4e2d\u4e0d\u5b58\u5728\u76f8\u90bb\u7684\u4e24\u6735\u82b1
    • \n\t
    • 0 <= n <= flowerbed.length
    • \n
    \n", "tags_en": ["Greedy", "Array"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canPlaceFlowers(vector& flowerbed, int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canPlaceFlowers(int[] flowerbed, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canPlaceFlowers(self, flowerbed, n):\n \"\"\"\n :type flowerbed: List[int]\n :type n: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canPlaceFlowers(self, flowerbed: List[int], n: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canPlaceFlowers(int* flowerbed, int flowerbedSize, int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanPlaceFlowers(int[] flowerbed, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} flowerbed\n * @param {number} n\n * @return {boolean}\n */\nvar canPlaceFlowers = function(flowerbed, n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} flowerbed\n# @param {Integer} n\n# @return {Boolean}\ndef can_place_flowers(flowerbed, n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canPlaceFlowers(_ flowerbed: [Int], _ n: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canPlaceFlowers(flowerbed []int, n int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canPlaceFlowers(flowerbed: Array[Int], n: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canPlaceFlowers(flowerbed: IntArray, n: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_place_flowers(flowerbed: Vec, n: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $flowerbed\n * @param Integer $n\n * @return Boolean\n */\n function canPlaceFlowers($flowerbed, $n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canPlaceFlowers(flowerbed: number[], n: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-place-flowers flowerbed n)\n (-> (listof exact-integer?) exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0605](https://leetcode-cn.com/problems/can-place-flowers)", "[\u79cd\u82b1\u95ee\u9898](/solution/0600-0699/0605.Can%20Place%20Flowers/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0605](https://leetcode.com/problems/can-place-flowers)", "[Can Place Flowers](/solution/0600-0699/0605.Can%20Place%20Flowers/README_EN.md)", "`Greedy`,`Array`", "Easy", ""]}, {"question_id": "0604", "frontend_question_id": "0604", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/design-compressed-string-iterator", "url_en": "https://leetcode.com/problems/design-compressed-string-iterator", "relative_path_cn": "/solution/0600-0699/0604.Design%20Compressed%20String%20Iterator/README.md", "relative_path_en": "/solution/0600-0699/0604.Design%20Compressed%20String%20Iterator/README_EN.md", "title_cn": "\u8fed\u4ee3\u538b\u7f29\u5b57\u7b26\u4e32", "title_en": "Design Compressed String Iterator", "question_title_slug": "design-compressed-string-iterator", "content_en": "

    Design and implement a data structure for a compressed string iterator. The given compressed string will be in the form of each letter followed by a positive integer representing the number of this letter existing in the original uncompressed string.

    \n\n

    Implement the StringIterator class:

    \n\n
      \n\t
    • next() Returns the next character if the original string still has uncompressed characters, otherwise returns a white space.
    • \n\t
    • hasNext() Returns true if there is any letter needs to be uncompressed in the original string, otherwise returns false.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["StringIterator", "next", "next", "next", "next", "next", "next", "hasNext", "next", "hasNext"]\n[["L1e2t1C1o1d1e1"], [], [], [], [], [], [], [], [], []]\nOutput\n[null, "L", "e", "e", "t", "C", "o", true, "d", true]\n\nExplanation\nStringIterator stringIterator = new StringIterator("L1e2t1C1o1d1e1");\nstringIterator.next(); // return "L"\nstringIterator.next(); // return "e"\nstringIterator.next(); // return "e"\nstringIterator.next(); // return "t"\nstringIterator.next(); // return "C"\nstringIterator.next(); // return "o"\nstringIterator.hasNext(); // return True\nstringIterator.next(); // return "d"\nstringIterator.hasNext(); // return True\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= compressedString.length <= 1000
    • \n\t
    • compressedString consists of lower-case an upper-case English letters and digits.
    • \n\t
    • The number of a single character repetitions in compressedString is in the range [1, 10^9]
    • \n\t
    • At most 100 calls will be made to next and hasNext.
    • \n
    \n", "content_cn": "

    \u5bf9\u4e8e\u4e00\u4e2a\u538b\u7f29\u5b57\u7b26\u4e32\uff0c\u8bbe\u8ba1\u4e00\u4e2a\u6570\u636e\u7ed3\u6784\uff0c\u5b83\u652f\u6301\u5982\u4e0b\u4e24\u79cd\u64cd\u4f5c\uff1a next \u548c hasNext\u3002

    \n\n

    \u7ed9\u5b9a\u7684\u538b\u7f29\u5b57\u7b26\u4e32\u683c\u5f0f\u4e3a\uff1a\u6bcf\u4e2a\u5b57\u6bcd\u540e\u9762\u7d27\u8ddf\u4e00\u4e2a\u6b63\u6574\u6570\uff0c\u8fd9\u4e2a\u6574\u6570\u8868\u793a\u8be5\u5b57\u6bcd\u5728\u89e3\u538b\u540e\u7684\u5b57\u7b26\u4e32\u91cc\u8fde\u7eed\u51fa\u73b0\u7684\u6b21\u6570\u3002

    \n\n

    next() - \u5982\u679c\u538b\u7f29\u5b57\u7b26\u4e32\u4ecd\u7136\u6709\u5b57\u6bcd\u672a\u88ab\u89e3\u538b\uff0c\u5219\u8fd4\u56de\u4e0b\u4e00\u4e2a\u5b57\u6bcd\uff0c\u5426\u5219\u8fd4\u56de\u4e00\u4e2a\u7a7a\u683c\u3002
    \nhasNext() - \u5224\u65ad\u662f\u5426\u8fd8\u6709\u5b57\u6bcd\u4ecd\u7136\u6ca1\u88ab\u89e3\u538b\u3002

    \n\n

    \u6ce8\u610f\uff1a

    \n\n

    \u8bf7\u8bb0\u5f97\u5c06\u4f60\u7684\u7c7b\u5728 StringIterator \u4e2d \u521d\u59cb\u5316 \uff0c\u56e0\u4e3a\u9759\u6001\u53d8\u91cf\u6216\u7c7b\u53d8\u91cf\u5728\u591a\u7ec4\u6d4b\u8bd5\u6570\u636e\u4e2d\u4e0d\u4f1a\u88ab\u81ea\u52a8\u6e05\u7a7a\u3002\u66f4\u591a\u7ec6\u8282\u8bf7\u8bbf\u95ee \u8fd9\u91cc \u3002

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    StringIterator iterator = new StringIterator("L1e2t1C1o1d1e1");\n\niterator.next(); // \u8fd4\u56de 'L'\niterator.next(); // \u8fd4\u56de 'e'\niterator.next(); // \u8fd4\u56de 'e'\niterator.next(); // \u8fd4\u56de 't'\niterator.next(); // \u8fd4\u56de 'C'\niterator.next(); // \u8fd4\u56de 'o'\niterator.next(); // \u8fd4\u56de 'd'\niterator.hasNext(); // \u8fd4\u56de true\niterator.next(); // \u8fd4\u56de 'e'\niterator.hasNext(); // \u8fd4\u56de false\niterator.next(); // \u8fd4\u56de ' '\n
    \n\n

     

    \n", "tags_en": ["Design"], "tags_cn": ["\u8bbe\u8ba1"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class StringIterator {\npublic:\n StringIterator(string compressedString) {\n\n }\n \n char next() {\n\n }\n \n bool hasNext() {\n\n }\n};\n\n/**\n * Your StringIterator object will be instantiated and called as such:\n * StringIterator* obj = new StringIterator(compressedString);\n * char param_1 = obj->next();\n * bool param_2 = obj->hasNext();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class StringIterator {\n\n public StringIterator(String compressedString) {\n\n }\n \n public char next() {\n\n }\n \n public boolean hasNext() {\n\n }\n}\n\n/**\n * Your StringIterator object will be instantiated and called as such:\n * StringIterator obj = new StringIterator(compressedString);\n * char param_1 = obj.next();\n * boolean param_2 = obj.hasNext();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class StringIterator(object):\n\n def __init__(self, compressedString):\n \"\"\"\n :type compressedString: str\n \"\"\"\n\n\n def next(self):\n \"\"\"\n :rtype: str\n \"\"\"\n\n\n def hasNext(self):\n \"\"\"\n :rtype: bool\n \"\"\"\n\n\n\n# Your StringIterator object will be instantiated and called as such:\n# obj = StringIterator(compressedString)\n# param_1 = obj.next()\n# param_2 = obj.hasNext()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class StringIterator:\n\n def __init__(self, compressedString: str):\n\n\n def next(self) -> str:\n\n\n def hasNext(self) -> bool:\n\n\n\n# Your StringIterator object will be instantiated and called as such:\n# obj = StringIterator(compressedString)\n# param_1 = obj.next()\n# param_2 = obj.hasNext()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} StringIterator;\n\n\nStringIterator* stringIteratorCreate(char * compressedString) {\n \n}\n\nchar stringIteratorNext(StringIterator* obj) {\n \n}\n\nbool stringIteratorHasNext(StringIterator* obj) {\n \n}\n\nvoid stringIteratorFree(StringIterator* obj) {\n \n}\n\n/**\n * Your StringIterator struct will be instantiated and called as such:\n * StringIterator* obj = stringIteratorCreate(compressedString);\n * char param_1 = stringIteratorNext(obj);\n \n * bool param_2 = stringIteratorHasNext(obj);\n \n * stringIteratorFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class StringIterator {\n\n public StringIterator(string compressedString) {\n\n }\n \n public char Next() {\n\n }\n \n public bool HasNext() {\n\n }\n}\n\n/**\n * Your StringIterator object will be instantiated and called as such:\n * StringIterator obj = new StringIterator(compressedString);\n * char param_1 = obj.Next();\n * bool param_2 = obj.HasNext();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} compressedString\n */\nvar StringIterator = function(compressedString) {\n\n};\n\n/**\n * @return {character}\n */\nStringIterator.prototype.next = function() {\n\n};\n\n/**\n * @return {boolean}\n */\nStringIterator.prototype.hasNext = function() {\n\n};\n\n/**\n * Your StringIterator object will be instantiated and called as such:\n * var obj = new StringIterator(compressedString)\n * var param_1 = obj.next()\n * var param_2 = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class StringIterator\n\n=begin\n :type compressed_string: String\n=end\n def initialize(compressed_string)\n\n end\n\n\n=begin\n :rtype: Character\n=end\n def next()\n\n end\n\n\n=begin\n :rtype: Boolean\n=end\n def has_next()\n\n end\n\n\nend\n\n# Your StringIterator object will be instantiated and called as such:\n# obj = StringIterator.new(compressed_string)\n# param_1 = obj.next()\n# param_2 = obj.has_next()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass StringIterator {\n\n init(_ compressedString: String) {\n\n }\n \n func next() -> Character {\n\n }\n \n func hasNext() -> Bool {\n\n }\n}\n\n/**\n * Your StringIterator object will be instantiated and called as such:\n * let obj = StringIterator(compressedString)\n * let ret_1: Character = obj.next()\n * let ret_2: Bool = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type StringIterator struct {\n\n}\n\n\nfunc Constructor(compressedString string) StringIterator {\n\n}\n\n\nfunc (this *StringIterator) Next() byte {\n\n}\n\n\nfunc (this *StringIterator) HasNext() bool {\n\n}\n\n\n/**\n * Your StringIterator object will be instantiated and called as such:\n * obj := Constructor(compressedString);\n * param_1 := obj.Next();\n * param_2 := obj.HasNext();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class StringIterator(_compressedString: String) {\n\n def next(): Char = {\n\n }\n\n def hasNext(): Boolean = {\n\n }\n\n}\n\n/**\n * Your StringIterator object will be instantiated and called as such:\n * var obj = new StringIterator(compressedString)\n * var param_1 = obj.next()\n * var param_2 = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class StringIterator(compressedString: String) {\n\n fun next(): Char {\n\n }\n\n fun hasNext(): Boolean {\n\n }\n\n}\n\n/**\n * Your StringIterator object will be instantiated and called as such:\n * var obj = StringIterator(compressedString)\n * var param_1 = obj.next()\n * var param_2 = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct StringIterator {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl StringIterator {\n\n fn new(compressedString: String) -> Self {\n\n }\n \n fn next(&self) -> char {\n\n }\n \n fn has_next(&self) -> bool {\n\n }\n}\n\n/**\n * Your StringIterator object will be instantiated and called as such:\n * let obj = StringIterator::new(compressedString);\n * let ret_1: char = obj.next();\n * let ret_2: bool = obj.has_next();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class StringIterator {\n /**\n * @param String $compressedString\n */\n function __construct($compressedString) {\n\n }\n\n /**\n * @return String\n */\n function next() {\n\n }\n\n /**\n * @return Boolean\n */\n function hasNext() {\n\n }\n}\n\n/**\n * Your StringIterator object will be instantiated and called as such:\n * $obj = StringIterator($compressedString);\n * $ret_1 = $obj->next();\n * $ret_2 = $obj->hasNext();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class StringIterator {\n constructor(compressedString: string) {\n\n }\n\n next(): string {\n\n }\n\n hasNext(): boolean {\n\n }\n}\n\n/**\n * Your StringIterator object will be instantiated and called as such:\n * var obj = new StringIterator(compressedString)\n * var param_1 = obj.next()\n * var param_2 = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define string-iterator%\n (class object%\n (super-new)\n\n ; compressed-string : string?\n (init-field\n compressed-string)\n \n ; next : -> char?\n (define/public (next)\n\n )\n ; has-next : -> boolean?\n (define/public (has-next)\n\n )))\n\n;; Your string-iterator% object will be instantiated and called as such:\n;; (define obj (new string-iterator% [compressedString compressedString]))\n;; (define param_1 (send obj next))\n;; (define param_2 (send obj has-next))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0604](https://leetcode-cn.com/problems/design-compressed-string-iterator)", "[\u8fed\u4ee3\u538b\u7f29\u5b57\u7b26\u4e32](/solution/0600-0699/0604.Design%20Compressed%20String%20Iterator/README.md)", "`\u8bbe\u8ba1`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0604](https://leetcode.com/problems/design-compressed-string-iterator)", "[Design Compressed String Iterator](/solution/0600-0699/0604.Design%20Compressed%20String%20Iterator/README_EN.md)", "`Design`", "Easy", "\ud83d\udd12"]}, {"question_id": "0603", "frontend_question_id": "0603", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/consecutive-available-seats", "url_en": "https://leetcode.com/problems/consecutive-available-seats", "relative_path_cn": "/solution/0600-0699/0603.Consecutive%20Available%20Seats/README.md", "relative_path_en": "/solution/0600-0699/0603.Consecutive%20Available%20Seats/README_EN.md", "title_cn": "\u8fde\u7eed\u7a7a\u4f59\u5ea7\u4f4d", "title_en": "Consecutive Available Seats", "question_title_slug": "consecutive-available-seats", "content_en": "Several friends at a cinema ticket office would like to reserve consecutive available seats.
    \r\nCan you help to query all the consecutive available seats order by the seat_id using the following cinema table?\r\n
    \r\n| seat_id | free |\r\n|---------|------|\r\n| 1       | 1    |\r\n| 2       | 0    |\r\n| 3       | 1    |\r\n| 4       | 1    |\r\n| 5       | 1    |\r\n
    \r\n\r\n

     

    \r\nYour query should return the following result for the sample case above.\r\n\r\n

     

    \r\n\r\n
    \r\n| seat_id |\r\n|---------|\r\n| 3       |\r\n| 4       |\r\n| 5       |\r\n
    \r\nNote:\r\n\r\n
      \r\n\t
    • The seat_id is an auto increment int, and free is bool ('1' means free, and '0' means occupied.).
    • \r\n\t
    • Consecutive available seats are more than 2(inclusive) seats consecutively available.
    • \r\n
    \r\n", "content_cn": "

    \u51e0\u4e2a\u670b\u53cb\u6765\u5230\u7535\u5f71\u9662\u7684\u552e\u7968\u5904\uff0c\u51c6\u5907\u9884\u7ea6\u8fde\u7eed\u7a7a\u4f59\u5ea7\u4f4d\u3002

    \n\n

    \u4f60\u80fd\u5229\u7528\u8868 cinema \uff0c\u5e2e\u4ed6\u4eec\u5199\u4e00\u4e2a\u67e5\u8be2\u8bed\u53e5\uff0c\u83b7\u53d6\u6240\u6709\u7a7a\u4f59\u5ea7\u4f4d\uff0c\u5e76\u5c06\u5b83\u4eec\u6309\u7167 seat_id \u6392\u5e8f\u540e\u8fd4\u56de\u5417\uff1f

    \n\n
    | seat_id | free |\n|---------|------|\n| 1       | 1    |\n| 2       | 0    |\n| 3       | 1    |\n| 4       | 1    |\n| 5       | 1    |\n
    \n\n

     

    \n\n

    \u5bf9\u4e8e\u5982\u4e0a\u6837\u4f8b\uff0c\u4f60\u7684\u67e5\u8be2\u8bed\u53e5\u5e94\u8be5\u8fd4\u56de\u5982\u4e0b\u7ed3\u679c\u3002

    \n\n

     

    \n\n
    | seat_id |\n|---------|\n| 3       |\n| 4       |\n| 5       |\n
    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    • seat_id \u5b57\u6bb5\u662f\u4e00\u4e2a\u81ea\u589e\u7684\u6574\u6570\uff0cfree \u5b57\u6bb5\u662f\u5e03\u5c14\u7c7b\u578b\uff08'1' \u8868\u793a\u7a7a\u4f59\uff0c '0' \u8868\u793a\u5df2\u88ab\u5360\u636e\uff09\u3002
    • \n\t
    • \u8fde\u7eed\u7a7a\u4f59\u5ea7\u4f4d\u7684\u5b9a\u4e49\u662f\u5927\u4e8e\u7b49\u4e8e 2 \u4e2a\u8fde\u7eed\u7a7a\u4f59\u7684\u5ea7\u4f4d\u3002
    • \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0603](https://leetcode-cn.com/problems/consecutive-available-seats)", "[\u8fde\u7eed\u7a7a\u4f59\u5ea7\u4f4d](/solution/0600-0699/0603.Consecutive%20Available%20Seats/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0603](https://leetcode.com/problems/consecutive-available-seats)", "[Consecutive Available Seats](/solution/0600-0699/0603.Consecutive%20Available%20Seats/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "0602", "frontend_question_id": "0602", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/friend-requests-ii-who-has-the-most-friends", "url_en": "https://leetcode.com/problems/friend-requests-ii-who-has-the-most-friends", "relative_path_cn": "/solution/0600-0699/0602.Friend%20Requests%20II%20Who%20Has%20the%20Most%20Friends/README.md", "relative_path_en": "/solution/0600-0699/0602.Friend%20Requests%20II%20Who%20Has%20the%20Most%20Friends/README_EN.md", "title_cn": "\u597d\u53cb\u7533\u8bf7 II \uff1a\u8c01\u6709\u6700\u591a\u7684\u597d\u53cb", "title_en": "Friend Requests II Who Has the Most Friends", "question_title_slug": "friend-requests-ii-who-has-the-most-friends", "content_en": "

    In social network like Facebook or Twitter, people send friend requests and accept others' requests as well.

    \n\n

     

    \n\n

    Table request_accepted

    \n\n
    \n+--------------+-------------+------------+\n| requester_id | accepter_id | accept_date|\n|--------------|-------------|------------|\n| 1            | 2           | 2016_06-03 |\n| 1            | 3           | 2016-06-08 |\n| 2            | 3           | 2016-06-08 |\n| 3            | 4           | 2016-06-09 |\n+--------------+-------------+------------+\nThis table holds the data of friend acceptance, while requester_id and accepter_id both are the id of a person.\n
    \n\n

     

    \n\n

    Write a query to find the the people who has most friends and the most friends number under the following rules:

    \n\n
      \n\t
    • It is guaranteed there is only 1 people having the most friends.
    • \n\t
    • The friend request could only been accepted once, which mean there is no multiple records with the same requester_id and accepter_id value.
    • \n
    \n\n

    For the sample data above, the result is:

    \n\n
    \nResult table:\n+------+------+\n| id   | num  |\n|------|------|\n| 3    | 3    |\n+------+------+\nThe person with id '3' is a friend of people '1', '2' and '4', so he has 3 friends in total, which is the most number than any others.\n
    \n\n

    Follow-up:
    \nIn the real world, multiple people could have the same most number of friends, can you find all these people in this case?

    \n", "content_cn": "

    \u5728 Facebook \u6216\u8005 Twitter \u8fd9\u6837\u7684\u793e\u4ea4\u5e94\u7528\u4e2d\uff0c\u4eba\u4eec\u7ecf\u5e38\u4f1a\u53d1\u597d\u53cb\u7533\u8bf7\u4e5f\u4f1a\u6536\u5230\u5176\u4ed6\u4eba\u7684\u597d\u53cb\u7533\u8bf7\u3002

    \n\n

     

    \n\n

    \u8868 request_accepted \u5b58\u50a8\u4e86\u6240\u6709\u597d\u53cb\u7533\u8bf7\u901a\u8fc7\u7684\u6570\u636e\u8bb0\u5f55\uff0c\u5176\u4e2d\uff0c requester_id \u548c accepter_id \u90fd\u662f\u7528\u6237\u7684\u7f16\u53f7\u3002

    \n\n

     

    \n\n
    | requester_id | accepter_id | accept_date|\n|--------------|-------------|------------|\n| 1            | 2           | 2016_06-03 |\n| 1            | 3           | 2016-06-08 |\n| 2            | 3           | 2016-06-08 |\n| 3            | 4           | 2016-06-09 |\n
    \n\n

    \u5199\u4e00\u4e2a\u67e5\u8be2\u8bed\u53e5\uff0c\u6c42\u51fa\u8c01\u62e5\u6709\u6700\u591a\u7684\u597d\u53cb\u548c\u4ed6\u62e5\u6709\u7684\u597d\u53cb\u6570\u76ee\u3002\u5bf9\u4e8e\u4e0a\u9762\u7684\u6837\u4f8b\u6570\u636e\uff0c\u7ed3\u679c\u4e3a\uff1a

    \n\n
    | id | num |\n|----|-----|\n| 3  | 3   |\n
    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    • \u4fdd\u8bc1\u62e5\u6709\u6700\u591a\u597d\u53cb\u6570\u76ee\u7684\u53ea\u6709 1 \u4e2a\u4eba\u3002
    • \n\t
    • \u597d\u53cb\u7533\u8bf7\u53ea\u4f1a\u88ab\u63a5\u53d7\u4e00\u6b21\uff0c\u6240\u4ee5\u4e0d\u4f1a\u6709 requester_id \u548c accepter_id \u503c\u90fd\u76f8\u540c\u7684\u91cd\u590d\u8bb0\u5f55\u3002
    • \n
    \n\n

     

    \n\n

    \u89e3\u91ca\uff1a

    \n\n

    \u7f16\u53f7\u4e3a '3' \u7684\u4eba\u662f\u7f16\u53f7\u4e3a '1'\uff0c'2' \u548c '4' \u7684\u597d\u53cb\uff0c\u6240\u4ee5\u4ed6\u603b\u5171\u6709 3 \u4e2a\u597d\u53cb\uff0c\u6bd4\u5176\u4ed6\u4eba\u90fd\u591a\u3002

    \n\n

     

    \n\n

    \u8fdb\u9636\uff1a

    \n\n

    \u5728\u771f\u5b9e\u4e16\u754c\u91cc\uff0c\u53ef\u80fd\u4f1a\u6709\u591a\u4e2a\u4eba\u62e5\u6709\u597d\u53cb\u6570\u76f8\u540c\u4e14\u6700\u591a\uff0c\u4f60\u80fd\u627e\u5230\u6240\u6709\u8fd9\u4e9b\u4eba\u5417\uff1f

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0602](https://leetcode-cn.com/problems/friend-requests-ii-who-has-the-most-friends)", "[\u597d\u53cb\u7533\u8bf7 II \uff1a\u8c01\u6709\u6700\u591a\u7684\u597d\u53cb](/solution/0600-0699/0602.Friend%20Requests%20II%20Who%20Has%20the%20Most%20Friends/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0602](https://leetcode.com/problems/friend-requests-ii-who-has-the-most-friends)", "[Friend Requests II Who Has the Most Friends](/solution/0600-0699/0602.Friend%20Requests%20II%20Who%20Has%20the%20Most%20Friends/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "0601", "frontend_question_id": "0601", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/human-traffic-of-stadium", "url_en": "https://leetcode.com/problems/human-traffic-of-stadium", "relative_path_cn": "/solution/0600-0699/0601.Human%20Traffic%20of%20Stadium/README.md", "relative_path_en": "/solution/0600-0699/0601.Human%20Traffic%20of%20Stadium/README_EN.md", "title_cn": "\u4f53\u80b2\u9986\u7684\u4eba\u6d41\u91cf", "title_en": "Human Traffic of Stadium", "question_title_slug": "human-traffic-of-stadium", "content_en": "

    Table: Stadium

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| visit_date    | date    |\n| people        | int     |\n+---------------+---------+\nvisit_date is the primary key for this table.\nEach row of this table contains the visit date and visit id to the stadium with the number of people during the visit.\nNo two rows will have the same visit_date, and as the id increases, the dates increase as well.\n
    \n\n

     

    \n\n

    Write an SQL query to display the records with three or more rows with consecutive id's, and the number of people is greater than or equal to 100 for each.

    \n\n

    Return the result table ordered by visit_date in ascending order.

    \n\n

    The query result format is in the following example.

    \n\n

     

    \n\n
    \nStadium table:\n+------+------------+-----------+\n| id   | visit_date | people    |\n+------+------------+-----------+\n| 1    | 2017-01-01 | 10        |\n| 2    | 2017-01-02 | 109       |\n| 3    | 2017-01-03 | 150       |\n| 4    | 2017-01-04 | 99        |\n| 5    | 2017-01-05 | 145       |\n| 6    | 2017-01-06 | 1455      |\n| 7    | 2017-01-07 | 199       |\n| 8    | 2017-01-09 | 188       |\n+------+------------+-----------+\n\nResult table:\n+------+------------+-----------+\n| id   | visit_date | people    |\n+------+------------+-----------+\n| 5    | 2017-01-05 | 145       |\n| 6    | 2017-01-06 | 1455      |\n| 7    | 2017-01-07 | 199       |\n| 8    | 2017-01-09 | 188       |\n+------+------------+-----------+\nThe four rows with ids 5, 6, 7, and 8 have consecutive ids and each of them has >= 100 people attended. Note that row 8 was included even though the visit_date was not the next day after row 7.\nThe rows with ids 2 and 3 are not included because we need at least three consecutive ids.
    \n", "content_cn": "\u8868\uff1aStadium\n
    \n
    \n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| visit_date    | date    |\n| people        | int     |\n+---------------+---------+\nvisit_date \u662f\u8868\u7684\u4e3b\u952e\n\u6bcf\u65e5\u4eba\u6d41\u91cf\u4fe1\u606f\u88ab\u8bb0\u5f55\u5728\u8fd9\u4e09\u5217\u4fe1\u606f\u4e2d\uff1a\u5e8f\u53f7 (id)\u3001\u65e5\u671f (visit_date)\u3001\u00a0\u4eba\u6d41\u91cf (people)\n\u6bcf\u5929\u53ea\u6709\u4e00\u884c\u8bb0\u5f55\uff0c\u65e5\u671f\u968f\u7740 id \u7684\u589e\u52a0\u800c\u589e\u52a0\n
    \n\n

    \u00a0

    \n\n

    \u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\u4ee5\u627e\u51fa\u6bcf\u884c\u7684\u4eba\u6570\u5927\u4e8e\u6216\u7b49\u4e8e 100 \u4e14 id \u8fde\u7eed\u7684\u4e09\u884c\u6216\u66f4\u591a\u884c\u8bb0\u5f55\u3002

    \n\n

    \u8fd4\u56de\u6309 visit_date \u5347\u5e8f\u6392\u5217\u7684\u7ed3\u679c\u8868\u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u6240\u793a\u3002

    \n\n
    \nStadium table:\n+------+------------+-----------+\n| id   | visit_date | people    |\n+------+------------+-----------+\n| 1    | 2017-01-01 | 10        |\n| 2    | 2017-01-02 | 109       |\n| 3    | 2017-01-03 | 150       |\n| 4    | 2017-01-04 | 99        |\n| 5    | 2017-01-05 | 145       |\n| 6    | 2017-01-06 | 1455      |\n| 7    | 2017-01-07 | 199       |\n| 8    | 2017-01-09 | 188       |\n+------+------------+-----------+\n\nResult table:\n+------+------------+-----------+\n| id   | visit_date | people    |\n+------+------------+-----------+\n| 5    | 2017-01-05 | 145       |\n| 6    | 2017-01-06 | 1455      |\n| 7    | 2017-01-07 | 199       |\n| 8    | 2017-01-09 | 188       |\n+------+------------+-----------+\nid \u4e3a 5\u30016\u30017\u30018 \u7684\u56db\u884c id \u8fde\u7eed\uff0c\u5e76\u4e14\u6bcf\u884c\u90fd\u6709 >= 100 \u7684\u4eba\u6570\u8bb0\u5f55\u3002\n\u8bf7\u6ce8\u610f\uff0c\u5373\u4f7f\u7b2c 7 \u884c\u548c\u7b2c 8 \u884c\u7684 visit_date \u4e0d\u662f\u8fde\u7eed\u7684\uff0c\u8f93\u51fa\u4e5f\u5e94\u5f53\u5305\u542b\u7b2c 8 \u884c\uff0c\u56e0\u4e3a\u6211\u4eec\u53ea\u9700\u8981\u8003\u8651 id \u8fde\u7eed\u7684\u8bb0\u5f55\u3002\n\u4e0d\u8f93\u51fa id \u4e3a 2 \u548c 3 \u7684\u884c\uff0c\u56e0\u4e3a\u81f3\u5c11\u9700\u8981\u4e09\u6761 id \u8fde\u7eed\u7684\u8bb0\u5f55\u3002\n
    \n
    \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0601](https://leetcode-cn.com/problems/human-traffic-of-stadium)", "[\u4f53\u80b2\u9986\u7684\u4eba\u6d41\u91cf](/solution/0600-0699/0601.Human%20Traffic%20of%20Stadium/README.md)", "", "\u56f0\u96be", ""], "md_table_row_en": ["[0601](https://leetcode.com/problems/human-traffic-of-stadium)", "[Human Traffic of Stadium](/solution/0600-0699/0601.Human%20Traffic%20of%20Stadium/README_EN.md)", "", "Hard", ""]}, {"question_id": "0600", "frontend_question_id": "0600", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/non-negative-integers-without-consecutive-ones", "url_en": "https://leetcode.com/problems/non-negative-integers-without-consecutive-ones", "relative_path_cn": "/solution/0600-0699/0600.Non-negative%20Integers%20without%20Consecutive%20Ones/README.md", "relative_path_en": "/solution/0600-0699/0600.Non-negative%20Integers%20without%20Consecutive%20Ones/README_EN.md", "title_cn": "\u4e0d\u542b\u8fde\u7eed1\u7684\u975e\u8d1f\u6574\u6570", "title_en": "Non-negative Integers without Consecutive Ones", "question_title_slug": "non-negative-integers-without-consecutive-ones", "content_en": "

    Given a positive integer n, return the number of the integers in the range [0, n] whose binary representations do not contain consecutive ones.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 5\nOutput: 5\nExplanation:\nHere are the non-negative integers <= 5 with their corresponding binary representations:\n0 : 0\n1 : 1\n2 : 10\n3 : 11\n4 : 100\n5 : 101\nAmong them, only integer 3 disobeys the rule (two consecutive ones) and the other 5 satisfy the rule. \n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 1\nOutput: 2\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 2\nOutput: 3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6b63\u6574\u6570 n\uff0c\u627e\u51fa\u5c0f\u4e8e\u6216\u7b49\u4e8e n \u7684\u975e\u8d1f\u6574\u6570\u4e2d\uff0c\u5176\u4e8c\u8fdb\u5236\u8868\u793a\u4e0d\u5305\u542b \u8fde\u7eed\u76841 \u7684\u4e2a\u6570\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: 5\n\u8f93\u51fa: 5\n\u89e3\u91ca: \n\u4e0b\u9762\u662f\u5e26\u6709\u76f8\u5e94\u4e8c\u8fdb\u5236\u8868\u793a\u7684\u975e\u8d1f\u6574\u6570<= 5\uff1a\n0 : 0\n1 : 1\n2 : 10\n3 : 11\n4 : 100\n5 : 101\n\u5176\u4e2d\uff0c\u53ea\u6709\u6574\u65703\u8fdd\u53cd\u89c4\u5219\uff08\u6709\u4e24\u4e2a\u8fde\u7eed\u76841\uff09\uff0c\u5176\u4ed65\u4e2a\u6ee1\u8db3\u89c4\u5219\u3002
    \n\n

    \u8bf4\u660e: 1 <= n <= 109

    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findIntegers(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findIntegers(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findIntegers(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findIntegers(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findIntegers(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindIntegers(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar findIntegers = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef find_integers(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findIntegers(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findIntegers(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findIntegers(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findIntegers(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_integers(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function findIntegers($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findIntegers(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-integers n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0600](https://leetcode-cn.com/problems/non-negative-integers-without-consecutive-ones)", "[\u4e0d\u542b\u8fde\u7eed1\u7684\u975e\u8d1f\u6574\u6570](/solution/0600-0699/0600.Non-negative%20Integers%20without%20Consecutive%20Ones/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0600](https://leetcode.com/problems/non-negative-integers-without-consecutive-ones)", "[Non-negative Integers without Consecutive Ones](/solution/0600-0699/0600.Non-negative%20Integers%20without%20Consecutive%20Ones/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "0599", "frontend_question_id": "0599", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-index-sum-of-two-lists", "url_en": "https://leetcode.com/problems/minimum-index-sum-of-two-lists", "relative_path_cn": "/solution/0500-0599/0599.Minimum%20Index%20Sum%20of%20Two%20Lists/README.md", "relative_path_en": "/solution/0500-0599/0599.Minimum%20Index%20Sum%20of%20Two%20Lists/README_EN.md", "title_cn": "\u4e24\u4e2a\u5217\u8868\u7684\u6700\u5c0f\u7d22\u5f15\u603b\u548c", "title_en": "Minimum Index Sum of Two Lists", "question_title_slug": "minimum-index-sum-of-two-lists", "content_en": "

    Suppose Andy and Doris want to choose a restaurant for dinner, and they both have a list of favorite restaurants represented by strings.

    \n\n

    You need to help them find out their common interest with the least list index sum. If there is a choice tie between answers, output all of them with no order requirement. You could assume there always exists an answer.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: list1 = ["Shogun","Tapioca Express","Burger King","KFC"], list2 = ["Piatti","The Grill at Torrey Pines","Hungry Hunter Steakhouse","Shogun"]\nOutput: ["Shogun"]\nExplanation: The only restaurant they both like is "Shogun".\n
    \n\n

    Example 2:

    \n\n
    \nInput: list1 = ["Shogun","Tapioca Express","Burger King","KFC"], list2 = ["KFC","Shogun","Burger King"]\nOutput: ["Shogun"]\nExplanation: The restaurant they both like and have the least index sum is "Shogun" with index sum 1 (0+1).\n
    \n\n

    Example 3:

    \n\n
    \nInput: list1 = ["Shogun","Tapioca Express","Burger King","KFC"], list2 = ["KFC","Burger King","Tapioca Express","Shogun"]\nOutput: ["KFC","Burger King","Tapioca Express","Shogun"]\n
    \n\n

    Example 4:

    \n\n
    \nInput: list1 = ["Shogun","Tapioca Express","Burger King","KFC"], list2 = ["KNN","KFC","Burger King","Tapioca Express","Shogun"]\nOutput: ["KFC","Burger King","Tapioca Express","Shogun"]\n
    \n\n

    Example 5:

    \n\n
    \nInput: list1 = ["KFC"], list2 = ["KFC"]\nOutput: ["KFC"]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= list1.length, list2.length <= 1000
    • \n\t
    • 1 <= list1[i].length, list2[i].length <= 30
    • \n\t
    • list1[i] and list2[i] consist of spaces ' ' and English letters.
    • \n\t
    • All the stings of list1 are unique.
    • \n\t
    • All the stings of list2 are unique.
    • \n
    \n", "content_cn": "

    \u5047\u8bbeAndy\u548cDoris\u60f3\u5728\u665a\u9910\u65f6\u9009\u62e9\u4e00\u5bb6\u9910\u5385\uff0c\u5e76\u4e14\u4ed6\u4eec\u90fd\u6709\u4e00\u4e2a\u8868\u793a\u6700\u559c\u7231\u9910\u5385\u7684\u5217\u8868\uff0c\u6bcf\u4e2a\u9910\u5385\u7684\u540d\u5b57\u7528\u5b57\u7b26\u4e32\u8868\u793a\u3002

    \n\n

    \u4f60\u9700\u8981\u5e2e\u52a9\u4ed6\u4eec\u7528\u6700\u5c11\u7684\u7d22\u5f15\u548c\u627e\u51fa\u4ed6\u4eec\u5171\u540c\u559c\u7231\u7684\u9910\u5385\u3002 \u5982\u679c\u7b54\u6848\u4e0d\u6b62\u4e00\u4e2a\uff0c\u5219\u8f93\u51fa\u6240\u6709\u7b54\u6848\u5e76\u4e14\u4e0d\u8003\u8651\u987a\u5e8f\u3002 \u4f60\u53ef\u4ee5\u5047\u8bbe\u603b\u662f\u5b58\u5728\u4e00\u4e2a\u7b54\u6848\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165:\n["Shogun", "Tapioca Express", "Burger King", "KFC"]\n["Piatti", "The Grill at Torrey Pines", "Hungry Hunter Steakhouse", "Shogun"]\n\u8f93\u51fa: ["Shogun"]\n\u89e3\u91ca: \u4ed6\u4eec\u552f\u4e00\u5171\u540c\u559c\u7231\u7684\u9910\u5385\u662f“Shogun”\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165:\n["Shogun", "Tapioca Express", "Burger King", "KFC"]\n["KFC", "Shogun", "Burger King"]\n\u8f93\u51fa: ["Shogun"]\n\u89e3\u91ca: \u4ed6\u4eec\u5171\u540c\u559c\u7231\u4e14\u5177\u6709\u6700\u5c0f\u7d22\u5f15\u548c\u7684\u9910\u5385\u662f“Shogun”\uff0c\u5b83\u6709\u6700\u5c0f\u7684\u7d22\u5f15\u548c1(0+1)\u3002\n
    \n\n

    \u63d0\u793a:

    \n\n
      \n\t
    1. \u4e24\u4e2a\u5217\u8868\u7684\u957f\u5ea6\u8303\u56f4\u90fd\u5728 [1, 1000]\u5185\u3002
    2. \n\t
    3. \u4e24\u4e2a\u5217\u8868\u4e2d\u7684\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u5c06\u5728[1\uff0c30]\u7684\u8303\u56f4\u5185\u3002
    4. \n\t
    5. \u4e0b\u6807\u4ece0\u5f00\u59cb\uff0c\u5230\u5217\u8868\u7684\u957f\u5ea6\u51cf1\u3002
    6. \n\t
    7. \u4e24\u4e2a\u5217\u8868\u90fd\u6ca1\u6709\u91cd\u590d\u7684\u5143\u7d20\u3002
    8. \n
    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findRestaurant(vector& list1, vector& list2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String[] findRestaurant(String[] list1, String[] list2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findRestaurant(self, list1, list2):\n \"\"\"\n :type list1: List[str]\n :type list2: List[str]\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findRestaurant(self, list1: List[str], list2: List[str]) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** findRestaurant(char ** list1, int list1Size, char ** list2, int list2Size, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string[] FindRestaurant(string[] list1, string[] list2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} list1\n * @param {string[]} list2\n * @return {string[]}\n */\nvar findRestaurant = function(list1, list2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} list1\n# @param {String[]} list2\n# @return {String[]}\ndef find_restaurant(list1, list2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findRestaurant(_ list1: [String], _ list2: [String]) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findRestaurant(list1 []string, list2 []string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findRestaurant(list1: Array[String], list2: Array[String]): Array[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findRestaurant(list1: Array, list2: Array): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_restaurant(list1: Vec, list2: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $list1\n * @param String[] $list2\n * @return String[]\n */\n function findRestaurant($list1, $list2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findRestaurant(list1: string[], list2: string[]): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-restaurant list1 list2)\n (-> (listof string?) (listof string?) (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0599](https://leetcode-cn.com/problems/minimum-index-sum-of-two-lists)", "[\u4e24\u4e2a\u5217\u8868\u7684\u6700\u5c0f\u7d22\u5f15\u603b\u548c](/solution/0500-0599/0599.Minimum%20Index%20Sum%20of%20Two%20Lists/README.md)", "`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0599](https://leetcode.com/problems/minimum-index-sum-of-two-lists)", "[Minimum Index Sum of Two Lists](/solution/0500-0599/0599.Minimum%20Index%20Sum%20of%20Two%20Lists/README_EN.md)", "`Hash Table`", "Easy", ""]}, {"question_id": "0598", "frontend_question_id": "0598", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/range-addition-ii", "url_en": "https://leetcode.com/problems/range-addition-ii", "relative_path_cn": "/solution/0500-0599/0598.Range%20Addition%20II/README.md", "relative_path_en": "/solution/0500-0599/0598.Range%20Addition%20II/README_EN.md", "title_cn": "\u8303\u56f4\u6c42\u548c II", "title_en": "Range Addition II", "question_title_slug": "range-addition-ii", "content_en": "

    You are given an m x n matrix M initialized with all 0's and an array of operations ops, where ops[i] = [ai, bi] means M[x][y] should be incremented by one for all 0 <= x < ai and 0 <= y < bi.

    \n\n

    Count and return the number of maximum integers in the matrix after performing all the operations.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: m = 3, n = 3, ops = [[2,2],[3,3]]\nOutput: 4\nExplanation: The maximum integer in M is 2, and there are four of it in M. So return 4.\n
    \n\n

    Example 2:

    \n\n
    \nInput: m = 3, n = 3, ops = [[2,2],[3,3],[3,3],[3,3],[2,2],[3,3],[3,3],[3,3],[2,2],[3,3],[3,3],[3,3]]\nOutput: 4\n
    \n\n

    Example 3:

    \n\n
    \nInput: m = 3, n = 3, ops = []\nOutput: 9\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= m, n <= 4 * 104
    • \n\t
    • 1 <= ops.length <= 104
    • \n\t
    • ops[i].length == 2
    • \n\t
    • 1 <= ai <= m
    • \n\t
    • 1 <= bi <= n
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u521d\u59cb\u5143\u7d20\u5168\u90e8\u4e3a 0\uff0c\u5927\u5c0f\u4e3a m*n \u7684\u77e9\u9635 \u4ee5\u53ca\u5728 \u4e0a\u7684\u4e00\u7cfb\u5217\u66f4\u65b0\u64cd\u4f5c\u3002

    \n\n

    \u64cd\u4f5c\u7528\u4e8c\u7ef4\u6570\u7ec4\u8868\u793a\uff0c\u5176\u4e2d\u7684\u6bcf\u4e2a\u64cd\u4f5c\u7528\u4e00\u4e2a\u542b\u6709\u4e24\u4e2a\u6b63\u6574\u6570 a \u548c b \u7684\u6570\u7ec4\u8868\u793a\uff0c\u542b\u4e49\u662f\u5c06\u6240\u6709\u7b26\u5408 0 <= i < a \u4ee5\u53ca 0 <= j < b \u7684\u5143\u7d20 M[i][j] \u7684\u503c\u90fd\u589e\u52a0 1\u3002

    \n\n

    \u5728\u6267\u884c\u7ed9\u5b9a\u7684\u4e00\u7cfb\u5217\u64cd\u4f5c\u540e\uff0c\u4f60\u9700\u8981\u8fd4\u56de\u77e9\u9635\u4e2d\u542b\u6709\u6700\u5927\u6574\u6570\u7684\u5143\u7d20\u4e2a\u6570\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: \nm = 3, n = 3\noperations = [[2,2],[3,3]]\n\u8f93\u51fa: 4\n\u89e3\u91ca: \n\u521d\u59cb\u72b6\u6001, M = \n[[0, 0, 0],\n [0, 0, 0],\n [0, 0, 0]]\n\n\u6267\u884c\u5b8c\u64cd\u4f5c [2,2] \u540e, M = \n[[1, 1, 0],\n [1, 1, 0],\n [0, 0, 0]]\n\n\u6267\u884c\u5b8c\u64cd\u4f5c [3,3] \u540e, M = \n[[2, 2, 1],\n [2, 2, 1],\n [1, 1, 1]]\n\nM \u4e2d\u6700\u5927\u7684\u6574\u6570\u662f 2, \u800c\u4e14 M \u4e2d\u67094\u4e2a\u503c\u4e3a2\u7684\u5143\u7d20\u3002\u56e0\u6b64\u8fd4\u56de 4\u3002\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. m \u548c n \u7684\u8303\u56f4\u662f [1,40000]\u3002
    2. \n\t
    3. a \u7684\u8303\u56f4\u662f [1,m]\uff0cb \u7684\u8303\u56f4\u662f [1,n]\u3002
    4. \n\t
    5. \u64cd\u4f5c\u6570\u76ee\u4e0d\u8d85\u8fc7 10000\u3002
    6. \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxCount(int m, int n, vector>& ops) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxCount(int m, int n, int[][] ops) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxCount(self, m, n, ops):\n \"\"\"\n :type m: int\n :type n: int\n :type ops: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxCount(int m, int n, int** ops, int opsSize, int* opsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxCount(int m, int n, int[][] ops) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} m\n * @param {number} n\n * @param {number[][]} ops\n * @return {number}\n */\nvar maxCount = function(m, n, ops) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} m\n# @param {Integer} n\n# @param {Integer[][]} ops\n# @return {Integer}\ndef max_count(m, n, ops)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxCount(_ m: Int, _ n: Int, _ ops: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxCount(m int, n int, ops [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxCount(m: Int, n: Int, ops: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxCount(m: Int, n: Int, ops: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_count(m: i32, n: i32, ops: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $m\n * @param Integer $n\n * @param Integer[][] $ops\n * @return Integer\n */\n function maxCount($m, $n, $ops) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxCount(m: number, n: number, ops: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-count m n ops)\n (-> exact-integer? exact-integer? (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0598](https://leetcode-cn.com/problems/range-addition-ii)", "[\u8303\u56f4\u6c42\u548c II](/solution/0500-0599/0598.Range%20Addition%20II/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0598](https://leetcode.com/problems/range-addition-ii)", "[Range Addition II](/solution/0500-0599/0598.Range%20Addition%20II/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "0597", "frontend_question_id": "0597", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/friend-requests-i-overall-acceptance-rate", "url_en": "https://leetcode.com/problems/friend-requests-i-overall-acceptance-rate", "relative_path_cn": "/solution/0500-0599/0597.Friend%20Requests%20I%20Overall%20Acceptance%20Rate/README.md", "relative_path_en": "/solution/0500-0599/0597.Friend%20Requests%20I%20Overall%20Acceptance%20Rate/README_EN.md", "title_cn": "\u597d\u53cb\u7533\u8bf7 I\uff1a\u603b\u4f53\u901a\u8fc7\u7387", "title_en": "Friend Requests I Overall Acceptance Rate", "question_title_slug": "friend-requests-i-overall-acceptance-rate", "content_en": "

    Table: FriendRequest

    \n\n
    \n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| sender_id      | int     |\n| send_to_id     | int     |\n| request_date   | date    |\n+----------------+---------+\nThere is no primary key for this table, it may contain duplicates.\nThis table contains the ID of the user who sent the request, the ID of the user who received the request, and the date of the request.\n
    \n\n

     

    \n\n

    Table: RequestAccepted

    \n\n
    \n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| requester_id   | int     |\n| accepter_id    | int     |\n| accept_date    | date    |\n+----------------+---------+\nThere is no primary key for this table, it may contain duplicates.\nThis table contains the ID of the user who sent the request, the ID of the user who received the request, and the date when the request was accepted.\n
    \n\n

     

    \n\n

    Write an SQL query to find the overall acceptance rate of requests, which is the number of acceptance divided by the number of requests. Return the answer rounded to 2 decimals places.

    \n\n

    Note that:

    \n\n
      \n\t
    • The accepted requests are not necessarily from the table friend_request. In this case, you just need to simply count the total accepted requests (no matter whether they are in the original requests), and divide it by the number of requests to get the acceptance rate.
    • \n\t
    • It is possible that a sender sends multiple requests to the same receiver, and a request could be accepted more than once. In this case, the ‘duplicated’ requests or acceptances are only counted once.
    • \n\t
    • If there are no requests at all, you should return 0.00 as the accept_rate.
    • \n
    \n\n

    The query result format is in the following example:

    \n\n

     

    \n\n
    \nFriendRequest table:\n+-----------+------------+--------------+\n| sender_id | send_to_id | request_date |\n+-----------+------------+--------------+\n| 1         | 2          | 2016/06/01   |\n| 1         | 3          | 2016/06/01   |\n| 1         | 4          | 2016/06/01   |\n| 2         | 3          | 2016/06/02   |\n| 3         | 4          | 2016/06/09   |\n+-----------+------------+--------------+\n\nRequestAccepted table:\n+--------------+-------------+-------------+\n| requester_id | accepter_id | accept_date |\n+--------------+-------------+-------------+\n| 1            | 2           | 2016/06/03  |\n| 1            | 3           | 2016/06/08  |\n| 2            | 3           | 2016/06/08  |\n| 3            | 4           | 2016/06/09  |\n| 3            | 4           | 2016/06/10  |\n+--------------+-------------+-------------+\n\nResult table:\n+-------------+\n| accept_rate |\n+-------------+\n| 0.8         |\n+-------------+\nThere are 4 unique accepted requests, and there are 5 requests in total. So the rate is 0.80.\n
    \n\n

     

    \nFollow up:\n
      \n\t
    • Could you write a query to return the acceptance rate for every month?
    • \n\t
    • Could you write a query to return the cumulative acceptance rate for every day?
    • \n
    \n", "content_cn": "

    \u5728 Facebook \u6216\u8005 Twitter \u8fd9\u6837\u7684\u793e\u4ea4\u5e94\u7528\u4e2d\uff0c\u4eba\u4eec\u7ecf\u5e38\u4f1a\u53d1\u597d\u53cb\u7533\u8bf7\u4e5f\u4f1a\u6536\u5230\u5176\u4ed6\u4eba\u7684\u597d\u53cb\u7533\u8bf7\u3002

    \n\n

    \u00a0

    \n\n

    \u8868\uff1aFriendRequest

    \n\n
    \n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| sender_id      | int     |\n| send_to_id     | int     |\n| request_date   | date    |\n+----------------+---------+\n\u6b64\u8868\u6ca1\u6709\u4e3b\u952e\uff0c\u5b83\u53ef\u80fd\u5305\u542b\u91cd\u590d\u9879\u3002\n\u8be5\u8868\u5305\u542b\u53d1\u9001\u8bf7\u6c42\u7684\u7528\u6237\u7684 ID \uff0c\u63a5\u53d7\u8bf7\u6c42\u7684\u7528\u6237\u7684 ID \u4ee5\u53ca\u8bf7\u6c42\u7684\u65e5\u671f\u3002\n
    \n\n

    \u8868\uff1aRequestAccepted

    \n\n
    \n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| requester_id   | int     |\n| accepter_id    | int     |\n| accept_date    | date    |\n+----------------+---------+\n\u6b64\u8868\u6ca1\u6709\u4e3b\u952e\uff0c\u5b83\u53ef\u80fd\u5305\u542b\u91cd\u590d\u9879\u3002\n\u8be5\u8868\u5305\u542b\u53d1\u9001\u8bf7\u6c42\u7684\u7528\u6237\u7684 ID \uff0c\u63a5\u53d7\u8bf7\u6c42\u7684\u7528\u6237\u7684 ID \u4ee5\u53ca\u8bf7\u6c42\u901a\u8fc7\u7684\u65e5\u671f\u3002
    \n\n

    \u00a0

    \n\n

    \u5199\u4e00\u4e2a\u67e5\u8be2\u8bed\u53e5\uff0c\u6c42\u51fa\u597d\u53cb\u7533\u8bf7\u7684\u901a\u8fc7\u7387\uff0c\u7528 2 \u4f4d\u5c0f\u6570\u8868\u793a\u3002\u901a\u8fc7\u7387\u7531\u63a5\u53d7\u597d\u53cb\u7533\u8bf7\u7684\u6570\u76ee\u9664\u4ee5\u7533\u8bf7\u603b\u6570\u3002

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u901a\u8fc7\u7684\u597d\u53cb\u7533\u8bf7\u4e0d\u4e00\u5b9a\u90fd\u5728\u8868\u00a0friend_request\u00a0\u4e2d\u3002\u4f60\u53ea\u9700\u8981\u7edf\u8ba1\u603b\u7684\u88ab\u901a\u8fc7\u7684\u7533\u8bf7\u6570\uff08\u4e0d\u7ba1\u5b83\u4eec\u5728\u4e0d\u5728\u8868\u00a0FriendRequest\u00a0\u4e2d\uff09\uff0c\u5e76\u5c06\u5b83\u9664\u4ee5\u7533\u8bf7\u603b\u6570\uff0c\u5f97\u5230\u901a\u8fc7\u7387
    • \n\t
    • \u4e00\u4e2a\u597d\u53cb\u7533\u8bf7\u53d1\u9001\u8005\u6709\u53ef\u80fd\u4f1a\u7ed9\u63a5\u53d7\u8005\u53d1\u51e0\u6761\u597d\u53cb\u7533\u8bf7\uff0c\u4e5f\u6709\u53ef\u80fd\u4e00\u4e2a\u597d\u53cb\u7533\u8bf7\u4f1a\u88ab\u901a\u8fc7\u597d\u51e0\u6b21\u3002\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u91cd\u590d\u7684\u597d\u53cb\u7533\u8bf7\u53ea\u7edf\u8ba1\u4e00\u6b21\u3002
    • \n\t
    • \u5982\u679c\u4e00\u4e2a\u597d\u53cb\u7533\u8bf7\u90fd\u6ca1\u6709\uff0c\u901a\u8fc7\u7387\u4e3a 0.00 \u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u5e94\u8be5\u5982\u4e0b\u4f8b\u6240\u793a\uff1a

    \n\n
    \nFriendRequest \u8868\uff1a\n+-----------+------------+--------------+\n| sender_id | send_to_id | request_date |\n+-----------+------------+--------------+\n| 1         | 2          | 2016/06/01   |\n| 1         | 3          | 2016/06/01   |\n| 1         | 4          | 2016/06/01   |\n| 2         | 3          | 2016/06/02   |\n| 3         | 4          | 2016/06/09   |\n+-----------+------------+--------------+\n\nRequestAccepted \u8868\uff1a\n+--------------+-------------+-------------+\n| requester_id | accepter_id | accept_date |\n+--------------+-------------+-------------+\n| 1            | 2           | 2016/06/03  |\n| 1            | 3           | 2016/06/08  |\n| 2            | 3           | 2016/06/08  |\n| 3            | 4           | 2016/06/09  |\n| 3            | 4           | 2016/06/10  |\n+--------------+-------------+-------------+\n\nResult \u8868\uff1a\n+-------------+\n| accept_rate |\n+-------------+\n| 0.8         |\n+-------------+\n\u603b\u5171\u6709 5 \u4e2a\u8bf7\u6c42\uff0c\u6709 4 \u4e2a\u4e0d\u540c\u7684\u901a\u8fc7\u8bf7\u6c42\uff0c\u6240\u4ee5\u901a\u8fc7\u7387\u662f 0.80
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636:

    \n\n
      \n\t
    • \u4f60\u80fd\u5199\u4e00\u4e2a\u67e5\u8be2\u8bed\u53e5\u5f97\u5230\u6bcf\u4e2a\u6708\u7684\u901a\u8fc7\u7387\u5417\uff1f
    • \n\t
    • \u4f60\u80fd\u6c42\u51fa\u6bcf\u4e00\u5929\u7684\u7d2f\u8ba1\u901a\u8fc7\u7387\u5417\uff1f
    • \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0597](https://leetcode-cn.com/problems/friend-requests-i-overall-acceptance-rate)", "[\u597d\u53cb\u7533\u8bf7 I\uff1a\u603b\u4f53\u901a\u8fc7\u7387](/solution/0500-0599/0597.Friend%20Requests%20I%20Overall%20Acceptance%20Rate/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0597](https://leetcode.com/problems/friend-requests-i-overall-acceptance-rate)", "[Friend Requests I Overall Acceptance Rate](/solution/0500-0599/0597.Friend%20Requests%20I%20Overall%20Acceptance%20Rate/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "0596", "frontend_question_id": "0596", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/classes-more-than-5-students", "url_en": "https://leetcode.com/problems/classes-more-than-5-students", "relative_path_cn": "/solution/0500-0599/0596.Classes%20More%20Than%205%20Students/README.md", "relative_path_en": "/solution/0500-0599/0596.Classes%20More%20Than%205%20Students/README_EN.md", "title_cn": "\u8d85\u8fc75\u540d\u5b66\u751f\u7684\u8bfe", "title_en": "Classes More Than 5 Students", "question_title_slug": "classes-more-than-5-students", "content_en": "

    There is a table courses with columns: student and class

    \r\n\r\n

    Please list out all classes which have more than or equal to 5 students.

    \r\n\r\n

    For example, the table:

    \r\n\r\n
    \r\n+---------+------------+\r\n| student | class      |\r\n+---------+------------+\r\n| A       | Math       |\r\n| B       | English    |\r\n| C       | Math       |\r\n| D       | Biology    |\r\n| E       | Math       |\r\n| F       | Computer   |\r\n| G       | Math       |\r\n| H       | Math       |\r\n| I       | Math       |\r\n+---------+------------+\r\n
    \r\n\r\n

    Should output:

    \r\n\r\n
    \r\n+---------+\r\n| class   |\r\n+---------+\r\n| Math    |\r\n+---------+\r\n
    \r\n\r\n

     

    \r\n\r\n

    Note:
    \r\nThe students should not be counted duplicate in each course.

    \r\n", "content_cn": "

    \u6709\u4e00\u4e2acourses \u8868 \uff0c\u6709: student (\u5b66\u751f) \u548c class (\u8bfe\u7a0b)\u3002

    \n\n

    \u8bf7\u5217\u51fa\u6240\u6709\u8d85\u8fc7\u6216\u7b49\u4e8e5\u540d\u5b66\u751f\u7684\u8bfe\u3002

    \n\n

    \u4f8b\u5982\uff0c\u8868\uff1a

    \n\n
    +---------+------------+\n| student | class      |\n+---------+------------+\n| A       | Math       |\n| B       | English    |\n| C       | Math       |\n| D       | Biology    |\n| E       | Math       |\n| F       | Computer   |\n| G       | Math       |\n| H       | Math       |\n| I       | Math       |\n+---------+------------+\n
    \n\n

    \u5e94\u8be5\u8f93\u51fa:

    \n\n
    +---------+\n| class   |\n+---------+\n| Math    |\n+---------+\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u5b66\u751f\u5728\u6bcf\u4e2a\u8bfe\u4e2d\u4e0d\u5e94\u88ab\u91cd\u590d\u8ba1\u7b97\u3002
    • \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0596](https://leetcode-cn.com/problems/classes-more-than-5-students)", "[\u8d85\u8fc75\u540d\u5b66\u751f\u7684\u8bfe](/solution/0500-0599/0596.Classes%20More%20Than%205%20Students/README.md)", "", "\u7b80\u5355", ""], "md_table_row_en": ["[0596](https://leetcode.com/problems/classes-more-than-5-students)", "[Classes More Than 5 Students](/solution/0500-0599/0596.Classes%20More%20Than%205%20Students/README_EN.md)", "", "Easy", ""]}, {"question_id": "0595", "frontend_question_id": "0595", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/big-countries", "url_en": "https://leetcode.com/problems/big-countries", "relative_path_cn": "/solution/0500-0599/0595.Big%20Countries/README.md", "relative_path_en": "/solution/0500-0599/0595.Big%20Countries/README_EN.md", "title_cn": "\u5927\u7684\u56fd\u5bb6", "title_en": "Big Countries", "question_title_slug": "big-countries", "content_en": "

    There is a table World

    \r\n\r\n
    \r\n+-----------------+------------+------------+--------------+---------------+\r\n| name            | continent  | area       | population   | gdp           |\r\n+-----------------+------------+------------+--------------+---------------+\r\n| Afghanistan     | Asia       | 652230     | 25500100     | 20343000      |\r\n| Albania         | Europe     | 28748      | 2831741      | 12960000      |\r\n| Algeria         | Africa     | 2381741    | 37100000     | 188681000     |\r\n| Andorra         | Europe     | 468        | 78115        | 3712000       |\r\n| Angola          | Africa     | 1246700    | 20609294     | 100990000     |\r\n+-----------------+------------+------------+--------------+---------------+\r\n
    \r\n\r\n

    A country is big if it has an area of bigger than 3 million square km or a population of more than 25 million.

    \r\n\r\n

    Write a SQL solution to output big countries' name, population and area.

    \r\n\r\n

    For example, according to the above table, we should output:

    \r\n\r\n
    \r\n+--------------+-------------+--------------+\r\n| name         | population  | area         |\r\n+--------------+-------------+--------------+\r\n| Afghanistan  | 25500100    | 652230       |\r\n| Algeria      | 37100000    | 2381741      |\r\n+--------------+-------------+--------------+\r\n
    \r\n\r\n

     

    \r\n", "content_cn": "

    \u8fd9\u91cc\u6709\u5f20\u00a0World \u8868

    \n\n
    \n+-----------------+------------+------------+--------------+---------------+\n| name            | continent  | area       | population   | gdp           |\n+-----------------+------------+------------+--------------+---------------+\n| Afghanistan     | Asia       | 652230     | 25500100     | 20343000      |\n| Albania         | Europe     | 28748      | 2831741      | 12960000      |\n| Algeria         | Africa     | 2381741    | 37100000     | 188681000     |\n| Andorra         | Europe     | 468        | 78115        | 3712000       |\n| Angola          | Africa     | 1246700    | 20609294     | 100990000     |\n+-----------------+------------+------------+--------------+---------------+\n
    \n\n

    \u5982\u679c\u4e00\u4e2a\u56fd\u5bb6\u7684\u9762\u79ef\u8d85\u8fc7 300 \u4e07\u5e73\u65b9\u516c\u91cc\uff0c\u6216\u8005\u4eba\u53e3\u8d85\u8fc7 2500 \u4e07\uff0c\u90a3\u4e48\u8fd9\u4e2a\u56fd\u5bb6\u5c31\u662f\u5927\u56fd\u5bb6\u3002

    \n\n

    \u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\uff0c\u8f93\u51fa\u8868\u4e2d\u6240\u6709\u5927\u56fd\u5bb6\u7684\u540d\u79f0\u3001\u4eba\u53e3\u548c\u9762\u79ef\u3002

    \n\n

    \u4f8b\u5982\uff0c\u6839\u636e\u4e0a\u8868\uff0c\u6211\u4eec\u5e94\u8be5\u8f93\u51fa:

    \n\n
    \n+--------------+-------------+--------------+\n| name         | population  | area         |\n+--------------+-------------+--------------+\n| Afghanistan  | 25500100    | 652230       |\n| Algeria      | 37100000    | 2381741      |\n+--------------+-------------+--------------+\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0595](https://leetcode-cn.com/problems/big-countries)", "[\u5927\u7684\u56fd\u5bb6](/solution/0500-0599/0595.Big%20Countries/README.md)", "", "\u7b80\u5355", ""], "md_table_row_en": ["[0595](https://leetcode.com/problems/big-countries)", "[Big Countries](/solution/0500-0599/0595.Big%20Countries/README_EN.md)", "", "Easy", ""]}, {"question_id": "0594", "frontend_question_id": "0594", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-harmonious-subsequence", "url_en": "https://leetcode.com/problems/longest-harmonious-subsequence", "relative_path_cn": "/solution/0500-0599/0594.Longest%20Harmonious%20Subsequence/README.md", "relative_path_en": "/solution/0500-0599/0594.Longest%20Harmonious%20Subsequence/README_EN.md", "title_cn": "\u6700\u957f\u548c\u8c10\u5b50\u5e8f\u5217", "title_en": "Longest Harmonious Subsequence", "question_title_slug": "longest-harmonious-subsequence", "content_en": "

    We define a harmonious array as an array where the difference between its maximum value and its minimum value is exactly 1.

    \n\n

    Given an integer array nums, return the length of its longest harmonious subsequence among all its possible subsequences.

    \n\n

    A subsequence of array is a sequence that can be derived from the array by deleting some or no elements without changing the order of the remaining elements.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,3,2,2,5,2,3,7]\nOutput: 5\nExplanation: The longest harmonious subsequence is [3,2,2,2,3].\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,2,3,4]\nOutput: 2\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [1,1,1,1]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 2 * 104
    • \n\t
    • -109 <= nums[i] <= 109
    • \n
    \n", "content_cn": "

    \u548c\u8c10\u6570\u7ec4\u662f\u6307\u4e00\u4e2a\u6570\u7ec4\u91cc\u5143\u7d20\u7684\u6700\u5927\u503c\u548c\u6700\u5c0f\u503c\u4e4b\u95f4\u7684\u5dee\u522b \u6b63\u597d\u662f 1 \u3002

    \n\n

    \u73b0\u5728\uff0c\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \uff0c\u8bf7\u4f60\u5728\u6240\u6709\u53ef\u80fd\u7684\u5b50\u5e8f\u5217\u4e2d\u627e\u5230\u6700\u957f\u7684\u548c\u8c10\u5b50\u5e8f\u5217\u7684\u957f\u5ea6\u3002

    \n\n

    \u6570\u7ec4\u7684\u5b50\u5e8f\u5217\u662f\u4e00\u4e2a\u7531\u6570\u7ec4\u6d3e\u751f\u51fa\u6765\u7684\u5e8f\u5217\uff0c\u5b83\u53ef\u4ee5\u901a\u8fc7\u5220\u9664\u4e00\u4e9b\u5143\u7d20\u6216\u4e0d\u5220\u9664\u5143\u7d20\u3001\u4e14\u4e0d\u6539\u53d8\u5176\u4f59\u5143\u7d20\u7684\u987a\u5e8f\u800c\u5f97\u5230\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,3,2,2,5,2,3,7]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u6700\u957f\u7684\u548c\u8c10\u5b50\u5e8f\u5217\u662f [3,2,2,2,3]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,3,4]\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,1,1,1]\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 2 * 104
    • \n\t
    • -109 <= nums[i] <= 109
    • \n
    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findLHS(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findLHS(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findLHS(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findLHS(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findLHS(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindLHS(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar findLHS = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef find_lhs(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findLHS(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findLHS(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findLHS(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findLHS(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_lhs(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function findLHS($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findLHS(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-lhs nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0594](https://leetcode-cn.com/problems/longest-harmonious-subsequence)", "[\u6700\u957f\u548c\u8c10\u5b50\u5e8f\u5217](/solution/0500-0599/0594.Longest%20Harmonious%20Subsequence/README.md)", "`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0594](https://leetcode.com/problems/longest-harmonious-subsequence)", "[Longest Harmonious Subsequence](/solution/0500-0599/0594.Longest%20Harmonious%20Subsequence/README_EN.md)", "`Hash Table`", "Easy", ""]}, {"question_id": "0593", "frontend_question_id": "0593", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/valid-square", "url_en": "https://leetcode.com/problems/valid-square", "relative_path_cn": "/solution/0500-0599/0593.Valid%20Square/README.md", "relative_path_en": "/solution/0500-0599/0593.Valid%20Square/README_EN.md", "title_cn": "\u6709\u6548\u7684\u6b63\u65b9\u5f62", "title_en": "Valid Square", "question_title_slug": "valid-square", "content_en": "

    Given the coordinates of four points in 2D space p1, p2, p3 and p4, return true if the four points construct a square.

    \n\n

    The coordinate of a point pi is represented as [xi, yi]. The input is not given in any order.

    \n\n

    A valid square has four equal sides with positive length and four equal angles (90-degree angles).

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: p1 = [0,0], p2 = [1,1], p3 = [1,0], p4 = [0,1]\nOutput: true\n
    \n\n

    Example 2:

    \n\n
    \nInput: p1 = [0,0], p2 = [1,1], p3 = [1,0], p4 = [0,12]\nOutput: false\n
    \n\n

    Example 3:

    \n\n
    \nInput: p1 = [1,0], p2 = [-1,0], p3 = [0,1], p4 = [0,-1]\nOutput: true\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • p1.length == p2.length == p3.length == p4.length == 2
    • \n\t
    • -104 <= xi, yi <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e8c\u7ef4\u7a7a\u95f4\u4e2d\u56db\u70b9\u7684\u5750\u6807\uff0c\u8fd4\u56de\u56db\u70b9\u662f\u5426\u53ef\u4ee5\u6784\u9020\u4e00\u4e2a\u6b63\u65b9\u5f62\u3002

    \n\n

    \u4e00\u4e2a\u70b9\u7684\u5750\u6807\uff08x\uff0cy\uff09\u7531\u4e00\u4e2a\u6709\u4e24\u4e2a\u6574\u6570\u7684\u6574\u6570\u6570\u7ec4\u8868\u793a\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \n\u8f93\u5165: p1 = [0,0], p2 = [1,1], p3 = [1,0], p4 = [0,1]\n\u8f93\u51fa: True\n
    \n\n

     

    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u6240\u6709\u8f93\u5165\u6574\u6570\u90fd\u5728 [-10000\uff0c10000] \u8303\u56f4\u5185\u3002
    2. \n\t
    3. \u4e00\u4e2a\u6709\u6548\u7684\u6b63\u65b9\u5f62\u6709\u56db\u4e2a\u7b49\u957f\u7684\u6b63\u957f\u548c\u56db\u4e2a\u7b49\u89d2\uff0890\u5ea6\u89d2\uff09\u3002
    4. \n\t
    5. \u8f93\u5165\u70b9\u6ca1\u6709\u987a\u5e8f\u3002
    6. \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool validSquare(vector& p1, vector& p2, vector& p3, vector& p4) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean validSquare(int[] p1, int[] p2, int[] p3, int[] p4) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def validSquare(self, p1, p2, p3, p4):\n \"\"\"\n :type p1: List[int]\n :type p2: List[int]\n :type p3: List[int]\n :type p4: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def validSquare(self, p1: List[int], p2: List[int], p3: List[int], p4: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool validSquare(int* p1, int p1Size, int* p2, int p2Size, int* p3, int p3Size, int* p4, int p4Size){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool ValidSquare(int[] p1, int[] p2, int[] p3, int[] p4) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} p1\n * @param {number[]} p2\n * @param {number[]} p3\n * @param {number[]} p4\n * @return {boolean}\n */\nvar validSquare = function(p1, p2, p3, p4) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} p1\n# @param {Integer[]} p2\n# @param {Integer[]} p3\n# @param {Integer[]} p4\n# @return {Boolean}\ndef valid_square(p1, p2, p3, p4)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func validSquare(_ p1: [Int], _ p2: [Int], _ p3: [Int], _ p4: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func validSquare(p1 []int, p2 []int, p3 []int, p4 []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def validSquare(p1: Array[Int], p2: Array[Int], p3: Array[Int], p4: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun validSquare(p1: IntArray, p2: IntArray, p3: IntArray, p4: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn valid_square(p1: Vec, p2: Vec, p3: Vec, p4: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $p1\n * @param Integer[] $p2\n * @param Integer[] $p3\n * @param Integer[] $p4\n * @return Boolean\n */\n function validSquare($p1, $p2, $p3, $p4) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function validSquare(p1: number[], p2: number[], p3: number[], p4: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (valid-square p1 p2 p3 p4)\n (-> (listof exact-integer?) (listof exact-integer?) (listof exact-integer?) (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0593](https://leetcode-cn.com/problems/valid-square)", "[\u6709\u6548\u7684\u6b63\u65b9\u5f62](/solution/0500-0599/0593.Valid%20Square/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0593](https://leetcode.com/problems/valid-square)", "[Valid Square](/solution/0500-0599/0593.Valid%20Square/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "0592", "frontend_question_id": "0592", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/fraction-addition-and-subtraction", "url_en": "https://leetcode.com/problems/fraction-addition-and-subtraction", "relative_path_cn": "/solution/0500-0599/0592.Fraction%20Addition%20and%20Subtraction/README.md", "relative_path_en": "/solution/0500-0599/0592.Fraction%20Addition%20and%20Subtraction/README_EN.md", "title_cn": "\u5206\u6570\u52a0\u51cf\u8fd0\u7b97", "title_en": "Fraction Addition and Subtraction", "question_title_slug": "fraction-addition-and-subtraction", "content_en": "

    Given a string expression representing an expression of fraction addition and subtraction, return the calculation result in string format.

    \n\n

    The final result should be an irreducible fraction. If your final result is an integer, say 2, you need to change it to the format of a fraction that has a denominator 1. So in this case, 2 should be converted to 2/1.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: expression = "-1/2+1/2"\nOutput: "0/1"\n
    \n\n

    Example 2:

    \n\n
    \nInput: expression = "-1/2+1/2+1/3"\nOutput: "1/3"\n
    \n\n

    Example 3:

    \n\n
    \nInput: expression = "1/3-1/2"\nOutput: "-1/6"\n
    \n\n

    Example 4:

    \n\n
    \nInput: expression = "5/3+1/3"\nOutput: "2/1"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The input string only contains '0' to '9', '/', '+' and '-'. So does the output.
    • \n\t
    • Each fraction (input and output) has the format ±numerator/denominator. If the first input fraction or the output is positive, then '+' will be omitted.
    • \n\t
    • The input only contains valid irreducible fractions, where the numerator and denominator of each fraction will always be in the range [1, 10]. If the denominator is 1, it means this fraction is actually an integer in a fraction format defined above.
    • \n\t
    • The number of given fractions will be in the range [1, 10].
    • \n\t
    • The numerator and denominator of the final result are guaranteed to be valid and in the range of 32-bit int.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u8868\u793a\u5206\u6570\u52a0\u51cf\u8fd0\u7b97\u8868\u8fbe\u5f0f\u7684\u5b57\u7b26\u4e32\uff0c\u4f60\u9700\u8981\u8fd4\u56de\u4e00\u4e2a\u5b57\u7b26\u4e32\u5f62\u5f0f\u7684\u8ba1\u7b97\u7ed3\u679c\u3002 \u8fd9\u4e2a\u7ed3\u679c\u5e94\u8be5\u662f\u4e0d\u53ef\u7ea6\u5206\u7684\u5206\u6570\uff0c\u5373\u6700\u7b80\u5206\u6570\u3002 \u5982\u679c\u6700\u7ec8\u7ed3\u679c\u662f\u4e00\u4e2a\u6574\u6570\uff0c\u4f8b\u5982 2\uff0c\u4f60\u9700\u8981\u5c06\u5b83\u8f6c\u6362\u6210\u5206\u6570\u5f62\u5f0f\uff0c\u5176\u5206\u6bcd\u4e3a 1\u3002\u6240\u4ee5\u5728\u4e0a\u8ff0\u4f8b\u5b50\u4e2d, 2 \u5e94\u8be5\u88ab\u8f6c\u6362\u4e3a 2/1\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165:"-1/2+1/2"\n\u8f93\u51fa: "0/1"\n
    \n\n

     \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165:"-1/2+1/2+1/3"\n\u8f93\u51fa: "1/3"\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \n\u8f93\u5165:"1/3-1/2"\n\u8f93\u51fa: "-1/6"\n
    \n\n

    \u793a\u4f8b 4:

    \n\n
    \n\u8f93\u5165:"5/3+1/3"\n\u8f93\u51fa: "2/1"\n
    \n\n

    \u8bf4\u660e:

    \n\n
      \n\t
    1. \u8f93\u5165\u548c\u8f93\u51fa\u5b57\u7b26\u4e32\u53ea\u5305\u542b '0' \u5230 '9' \u7684\u6570\u5b57\uff0c\u4ee5\u53ca '/', '+' \u548c '-'\u3002 
    2. \n\t
    3. \u8f93\u5165\u548c\u8f93\u51fa\u5206\u6570\u683c\u5f0f\u5747\u4e3a ±\u5206\u5b50/\u5206\u6bcd\u3002\u5982\u679c\u8f93\u5165\u7684\u7b2c\u4e00\u4e2a\u5206\u6570\u6216\u8005\u8f93\u51fa\u7684\u5206\u6570\u662f\u6b63\u6570\uff0c\u5219 '+' \u4f1a\u88ab\u7701\u7565\u6389\u3002
    4. \n\t
    5. \u8f93\u5165\u53ea\u5305\u542b\u5408\u6cd5\u7684\u6700\u7b80\u5206\u6570\uff0c\u6bcf\u4e2a\u5206\u6570\u7684\u5206\u5b50\u4e0e\u5206\u6bcd\u7684\u8303\u56f4\u662f  [1,10]\u3002 \u5982\u679c\u5206\u6bcd\u662f1\uff0c\u610f\u5473\u7740\u8fd9\u4e2a\u5206\u6570\u5b9e\u9645\u4e0a\u662f\u4e00\u4e2a\u6574\u6570\u3002
    6. \n\t
    7. \u8f93\u5165\u7684\u5206\u6570\u4e2a\u6570\u8303\u56f4\u662f [1,10]\u3002
    8. \n\t
    9. \u6700\u7ec8\u7ed3\u679c\u7684\u5206\u5b50\u4e0e\u5206\u6bcd\u4fdd\u8bc1\u662f 32 \u4f4d\u6574\u6570\u8303\u56f4\u5185\u7684\u6709\u6548\u6574\u6570\u3002
    10. \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string fractionAddition(string expression) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String fractionAddition(String expression) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def fractionAddition(self, expression):\n \"\"\"\n :type expression: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def fractionAddition(self, expression: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * fractionAddition(char * expression){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string FractionAddition(string expression) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} expression\n * @return {string}\n */\nvar fractionAddition = function(expression) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} expression\n# @return {String}\ndef fraction_addition(expression)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func fractionAddition(_ expression: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func fractionAddition(expression string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def fractionAddition(expression: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun fractionAddition(expression: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn fraction_addition(expression: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $expression\n * @return String\n */\n function fractionAddition($expression) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function fractionAddition(expression: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (fraction-addition expression)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0592](https://leetcode-cn.com/problems/fraction-addition-and-subtraction)", "[\u5206\u6570\u52a0\u51cf\u8fd0\u7b97](/solution/0500-0599/0592.Fraction%20Addition%20and%20Subtraction/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0592](https://leetcode.com/problems/fraction-addition-and-subtraction)", "[Fraction Addition and Subtraction](/solution/0500-0599/0592.Fraction%20Addition%20and%20Subtraction/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "0591", "frontend_question_id": "0591", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/tag-validator", "url_en": "https://leetcode.com/problems/tag-validator", "relative_path_cn": "/solution/0500-0599/0591.Tag%20Validator/README.md", "relative_path_en": "/solution/0500-0599/0591.Tag%20Validator/README_EN.md", "title_cn": "\u6807\u7b7e\u9a8c\u8bc1\u5668", "title_en": "Tag Validator", "question_title_slug": "tag-validator", "content_en": "

    Given a string representing a code snippet, implement a tag validator to parse the code and return whether it is valid.

    \n\n

    A code snippet is valid if all the following rules hold:

    \n\n
      \n\t
    1. The code must be wrapped in a valid closed tag. Otherwise, the code is invalid.
    2. \n\t
    3. A closed tag (not necessarily valid) has exactly the following format : <TAG_NAME>TAG_CONTENT</TAG_NAME>. Among them, <TAG_NAME> is the start tag, and </TAG_NAME> is the end tag. The TAG_NAME in start and end tags should be the same. A closed tag is valid if and only if the TAG_NAME and TAG_CONTENT are valid.
    4. \n\t
    5. A valid TAG_NAME only contain upper-case letters, and has length in range [1,9]. Otherwise, the TAG_NAME is invalid.
    6. \n\t
    7. A valid TAG_CONTENT may contain other valid closed tags, cdata and any characters (see note1) EXCEPT unmatched <, unmatched start and end tag, and unmatched or closed tags with invalid TAG_NAME. Otherwise, the TAG_CONTENT is invalid.
    8. \n\t
    9. A start tag is unmatched if no end tag exists with the same TAG_NAME, and vice versa. However, you also need to consider the issue of unbalanced when tags are nested.
    10. \n\t
    11. A < is unmatched if you cannot find a subsequent >. And when you find a < or </, all the subsequent characters until the next > should be parsed as TAG_NAME (not necessarily valid).
    12. \n\t
    13. The cdata has the following format : <![CDATA[CDATA_CONTENT]]>. The range of CDATA_CONTENT is defined as the characters between <![CDATA[ and the first subsequent ]]>.
    14. \n\t
    15. CDATA_CONTENT may contain any characters. The function of cdata is to forbid the validator to parse CDATA_CONTENT, so even it has some characters that can be parsed as tag (no matter valid or invalid), you should treat it as regular characters.
    16. \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: code = "<DIV>This is the first line <![CDATA[<div>]]></DIV>"\nOutput: true\nExplanation: \nThe code is wrapped in a closed tag : <DIV> and </DIV>. \nThe TAG_NAME is valid, the TAG_CONTENT consists of some characters and cdata. \nAlthough CDATA_CONTENT has an unmatched start tag with invalid TAG_NAME, it should be considered as plain text, not parsed as a tag.\nSo TAG_CONTENT is valid, and then the code is valid. Thus return true.\n
    \n\n

    Example 2:

    \n\n
    \nInput: code = "<DIV>>>  ![cdata[]] <![CDATA[<div>]>]]>]]>>]</DIV>"\nOutput: true\nExplanation:\nWe first separate the code into : start_tag|tag_content|end_tag.\nstart_tag -> "<DIV>"\nend_tag -> "</DIV>"\ntag_content could also be separated into : text1|cdata|text2.\ntext1 -> ">>  ![cdata[]] "\ncdata -> "<![CDATA[<div>]>]]>", where the CDATA_CONTENT is "<div>]>"\ntext2 -> "]]>>]"\nThe reason why start_tag is NOT "<DIV>>>" is because of the rule 6.\nThe reason why cdata is NOT "<![CDATA[<div>]>]]>]]>" is because of the rule 7.\n
    \n\n

    Example 3:

    \n\n
    \nInput: code = "<A>  <B> </A>   </B>"\nOutput: false\nExplanation: Unbalanced. If "<A>" is closed, then "<B>" must be unmatched, and vice versa.\n
    \n\n

    Example 4:

    \n\n
    \nInput: code = "<DIV>  div tag is not closed  <DIV>"\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= code.length <= 500
    • \n\t
    • code consists of English letters, digits, '<', '>', '/', '!', '[', ']', '.', and ' '.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u8868\u793a\u4ee3\u7801\u7247\u6bb5\u7684\u5b57\u7b26\u4e32\uff0c\u4f60\u9700\u8981\u5b9e\u73b0\u4e00\u4e2a\u9a8c\u8bc1\u5668\u6765\u89e3\u6790\u8fd9\u6bb5\u4ee3\u7801\uff0c\u5e76\u8fd4\u56de\u5b83\u662f\u5426\u5408\u6cd5\u3002\u5408\u6cd5\u7684\u4ee3\u7801\u7247\u6bb5\u9700\u8981\u9075\u5b88\u4ee5\u4e0b\u7684\u6240\u6709\u89c4\u5219\uff1a

    \n\n
      \n\t
    1. \u4ee3\u7801\u5fc5\u987b\u88ab\u5408\u6cd5\u7684\u95ed\u5408\u6807\u7b7e\u5305\u56f4\u3002\u5426\u5219\uff0c\u4ee3\u7801\u662f\u65e0\u6548\u7684\u3002
    2. \n\t
    3. \u95ed\u5408\u6807\u7b7e\uff08\u4e0d\u4e00\u5b9a\u5408\u6cd5\uff09\u8981\u4e25\u683c\u7b26\u5408\u683c\u5f0f\uff1a<TAG_NAME>TAG_CONTENT</TAG_NAME>\u3002\u5176\u4e2d\uff0c<TAG_NAME>\u662f\u8d77\u59cb\u6807\u7b7e\uff0c</TAG_NAME>\u662f\u7ed3\u675f\u6807\u7b7e\u3002\u8d77\u59cb\u548c\u7ed3\u675f\u6807\u7b7e\u4e2d\u7684 TAG_NAME \u5e94\u5f53\u76f8\u540c\u3002\u5f53\u4e14\u4ec5\u5f53 TAG_NAME \u548c TAG_CONTENT \u90fd\u662f\u5408\u6cd5\u7684\uff0c\u95ed\u5408\u6807\u7b7e\u624d\u662f\u5408\u6cd5\u7684\u3002
    4. \n\t
    5. \u5408\u6cd5\u7684 TAG_NAME \u4ec5\u542b\u6709\u5927\u5199\u5b57\u6bcd\uff0c\u957f\u5ea6\u5728\u8303\u56f4 [1,9] \u4e4b\u95f4\u3002\u5426\u5219\uff0c\u8be5 TAG_NAME \u662f\u4e0d\u5408\u6cd5\u7684\u3002
    6. \n\t
    7. \u5408\u6cd5\u7684 TAG_CONTENT \u53ef\u4ee5\u5305\u542b\u5176\u4ed6\u5408\u6cd5\u7684\u95ed\u5408\u6807\u7b7e\uff0ccdata \uff08\u8bf7\u53c2\u8003\u89c4\u52197\uff09\u548c\u4efb\u610f\u5b57\u7b26\uff08\u6ce8\u610f\u53c2\u8003\u89c4\u52191\uff09\u9664\u4e86\u4e0d\u5339\u914d\u7684<\u3001\u4e0d\u5339\u914d\u7684\u8d77\u59cb\u548c\u7ed3\u675f\u6807\u7b7e\u3001\u4e0d\u5339\u914d\u7684\u6216\u5e26\u6709\u4e0d\u5408\u6cd5 TAG_NAME \u7684\u95ed\u5408\u6807\u7b7e\u3002\u5426\u5219\uff0cTAG_CONTENT \u662f\u4e0d\u5408\u6cd5\u7684\u3002
    8. \n\t
    9. \u4e00\u4e2a\u8d77\u59cb\u6807\u7b7e\uff0c\u5982\u679c\u6ca1\u6709\u5177\u6709\u76f8\u540c TAG_NAME \u7684\u7ed3\u675f\u6807\u7b7e\u4e0e\u4e4b\u5339\u914d\uff0c\u662f\u4e0d\u5408\u6cd5\u7684\u3002\u53cd\u4e4b\u4ea6\u7136\u3002\u4e0d\u8fc7\uff0c\u4f60\u4e5f\u9700\u8981\u8003\u8651\u6807\u7b7e\u5d4c\u5957\u7684\u95ee\u9898\u3002
    10. \n\t
    11. \u4e00\u4e2a<\uff0c\u5982\u679c\u4f60\u627e\u4e0d\u5230\u4e00\u4e2a\u540e\u7eed\u7684>\u4e0e\u4e4b\u5339\u914d\uff0c\u662f\u4e0d\u5408\u6cd5\u7684\u3002\u5e76\u4e14\u5f53\u4f60\u627e\u5230\u4e00\u4e2a<\u6216</\u65f6\uff0c\u6240\u6709\u76f4\u5230\u4e0b\u4e00\u4e2a>\u7684\u524d\u7684\u5b57\u7b26\uff0c\u90fd\u5e94\u5f53\u88ab\u89e3\u6790\u4e3a TAG_NAME\uff08\u4e0d\u4e00\u5b9a\u5408\u6cd5\uff09\u3002
    12. \n\t
    13. cdata \u6709\u5982\u4e0b\u683c\u5f0f\uff1a<![CDATA[CDATA_CONTENT]]>\u3002CDATA_CONTENT \u7684\u8303\u56f4\u88ab\u5b9a\u4e49\u6210 <![CDATA[ \u548c\u540e\u7eed\u7684\u7b2c\u4e00\u4e2a ]]>\u4e4b\u95f4\u7684\u5b57\u7b26\u3002
    14. \n\t
    15. CDATA_CONTENT \u53ef\u4ee5\u5305\u542b\u4efb\u610f\u5b57\u7b26\u3002cdata \u7684\u529f\u80fd\u662f\u963b\u6b62\u9a8c\u8bc1\u5668\u89e3\u6790CDATA_CONTENT\uff0c\u6240\u4ee5\u5373\u4f7f\u5176\u4e2d\u6709\u4e00\u4e9b\u5b57\u7b26\u53ef\u4ee5\u88ab\u89e3\u6790\u4e3a\u6807\u7b7e\uff08\u65e0\u8bba\u5408\u6cd5\u8fd8\u662f\u4e0d\u5408\u6cd5\uff09\uff0c\u4e5f\u5e94\u8be5\u5c06\u5b83\u4eec\u89c6\u4e3a\u5e38\u89c4\u5b57\u7b26\u3002
    16. \n
    \n\n

    \u5408\u6cd5\u4ee3\u7801\u7684\u4f8b\u5b50:

    \n\n
    \n\u8f93\u5165: "<DIV>This is the first line <![CDATA[<div>]]></DIV>"\n\n\u8f93\u51fa: True\n\n\u89e3\u91ca: \n\n\u4ee3\u7801\u88ab\u5305\u542b\u5728\u4e86\u95ed\u5408\u7684\u6807\u7b7e\u5185\uff1a <DIV> \u548c </DIV> \u3002\n\nTAG_NAME \u662f\u5408\u6cd5\u7684\uff0cTAG_CONTENT \u5305\u542b\u4e86\u4e00\u4e9b\u5b57\u7b26\u548c cdata \u3002 \n\n\u5373\u4f7f CDATA_CONTENT \u542b\u6709\u4e0d\u5339\u914d\u7684\u8d77\u59cb\u6807\u7b7e\u548c\u4e0d\u5408\u6cd5\u7684 TAG_NAME\uff0c\u5b83\u5e94\u8be5\u88ab\u89c6\u4e3a\u666e\u901a\u7684\u6587\u672c\uff0c\u800c\u4e0d\u662f\u6807\u7b7e\u3002\n\n\u6240\u4ee5 TAG_CONTENT \u662f\u5408\u6cd5\u7684\uff0c\u56e0\u6b64\u4ee3\u7801\u662f\u5408\u6cd5\u7684\u3002\u6700\u7ec8\u8fd4\u56deTrue\u3002\n\n\n\u8f93\u5165: "<DIV>>>  ![cdata[]] <![CDATA[<div>]>]]>]]>>]</DIV>"\n\n\u8f93\u51fa: True\n\n\u89e3\u91ca:\n\n\u6211\u4eec\u9996\u5148\u5c06\u4ee3\u7801\u5206\u5272\u4e3a\uff1a start_tag|tag_content|end_tag \u3002\n\nstart_tag -> "<DIV>"\n\nend_tag -> "</DIV>"\n\ntag_content \u4e5f\u53ef\u88ab\u5206\u5272\u4e3a\uff1a text1|cdata|text2 \u3002\n\ntext1 -> ">>  ![cdata[]] "\n\ncdata -> "<![CDATA[<div>]>]]>" \uff0c\u5176\u4e2d CDATA_CONTENT \u4e3a "<div>]>"\n\ntext2 -> "]]>>]"\n\n\nstart_tag \u4e0d\u662f "<DIV>>>" \u7684\u539f\u56e0\u53c2\u7167\u89c4\u5219 6 \u3002\ncdata \u4e0d\u662f "<![CDATA[<div>]>]]>]]>" \u7684\u539f\u56e0\u53c2\u7167\u89c4\u5219 7 \u3002\n
    \n\n

    \u4e0d\u5408\u6cd5\u4ee3\u7801\u7684\u4f8b\u5b50:

    \n\n
    \n\u8f93\u5165: "<A>  <B> </A>   </B>"\n\u8f93\u51fa: False\n\u89e3\u91ca: \u4e0d\u5408\u6cd5\u3002\u5982\u679c "<A>" \u662f\u95ed\u5408\u7684\uff0c\u90a3\u4e48 "<B>" \u4e00\u5b9a\u662f\u4e0d\u5339\u914d\u7684\uff0c\u53cd\u4e4b\u4ea6\u7136\u3002\n\n\u8f93\u5165: "<DIV>  div tag is not closed  <DIV>"\n\u8f93\u51fa: False\n\n\u8f93\u5165: "<DIV>  unmatched <  </DIV>"\n\u8f93\u51fa: False\n\n\u8f93\u5165: "<DIV> closed tags with invalid tag name  <b>123</b> </DIV>"\n\u8f93\u51fa: False\n\n\u8f93\u5165: "<DIV> unmatched tags with invalid tag name  </1234567890> and <CDATA[[]]>  </DIV>"\n\u8f93\u51fa: False\n\n\u8f93\u5165: "<DIV>  unmatched start tag <B>  and unmatched end tag </C>  </DIV>"\n\u8f93\u51fa: False\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u4e3a\u7b80\u660e\u8d77\u89c1\uff0c\u4f60\u53ef\u4ee5\u5047\u8bbe\u8f93\u5165\u7684\u4ee3\u7801\uff08\u5305\u62ec\u63d0\u5230\u7684\u4efb\u610f\u5b57\u7b26\uff09\u53ea\u5305\u542b\u6570\u5b57, \u5b57\u6bcd, '<','>','/','!','[',']'\u548c' '\u3002
    2. \n
    \n", "tags_en": ["Stack", "String"], "tags_cn": ["\u6808", "\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isValid(string code) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isValid(String code) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isValid(self, code):\n \"\"\"\n :type code: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isValid(self, code: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isValid(char * code){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsValid(string code) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} code\n * @return {boolean}\n */\nvar isValid = function(code) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} code\n# @return {Boolean}\ndef is_valid(code)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isValid(_ code: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isValid(code string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isValid(code: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isValid(code: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_valid(code: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $code\n * @return Boolean\n */\n function isValid($code) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isValid(code: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-valid code)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0591](https://leetcode-cn.com/problems/tag-validator)", "[\u6807\u7b7e\u9a8c\u8bc1\u5668](/solution/0500-0599/0591.Tag%20Validator/README.md)", "`\u6808`,`\u5b57\u7b26\u4e32`", "\u56f0\u96be", ""], "md_table_row_en": ["[0591](https://leetcode.com/problems/tag-validator)", "[Tag Validator](/solution/0500-0599/0591.Tag%20Validator/README_EN.md)", "`Stack`,`String`", "Hard", ""]}, {"question_id": "0588", "frontend_question_id": "0588", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/design-in-memory-file-system", "url_en": "https://leetcode.com/problems/design-in-memory-file-system", "relative_path_cn": "/solution/0500-0599/0588.Design%20In-Memory%20File%20System/README.md", "relative_path_en": "/solution/0500-0599/0588.Design%20In-Memory%20File%20System/README_EN.md", "title_cn": "\u8bbe\u8ba1\u5185\u5b58\u6587\u4ef6\u7cfb\u7edf", "title_en": "Design In-Memory File System", "question_title_slug": "design-in-memory-file-system", "content_en": "

    Design a data structure that simulates an in-memory file system.

    \n\n

    Implement the FileSystem class:

    \n\n
      \n\t
    • FileSystem() Initializes the object of the system.
    • \n\t
    • List<String> ls(String path)\n\t
        \n\t\t
      • If path is a file path, returns a list that only contains this file's name.
      • \n\t\t
      • If path is a directory path, returns the list of file and directory names in this directory.
      • \n\t
      \n\tThe answer should in lexicographic order.
    • \n\t
    • void mkdir(String path) Makes a new directory according to the given path. The given directory path does not exist. If the middle directories in the path do not exist, you should create them as well.
    • \n\t
    • void addContentToFile(String filePath, String content)\n\t
        \n\t\t
      • If filePath does not exist, creates that file containing given content.
      • \n\t\t
      • If filePath already exists, appends the given content to original content.
      • \n\t
      \n\t
    • \n\t
    • String readContentFromFile(String filePath) Returns the content in the file at filePath.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput\n["FileSystem", "ls", "mkdir", "addContentToFile", "ls", "readContentFromFile"]\n[[], ["/"], ["/a/b/c"], ["/a/b/c/d", "hello"], ["/"], ["/a/b/c/d"]]\nOutput\n[null, [], null, null, ["a"], "hello"]\n\nExplanation\nFileSystem fileSystem = new FileSystem();\nfileSystem.ls("/");                         // return []\nfileSystem.mkdir("/a/b/c");\nfileSystem.addContentToFile("/a/b/c/d", "hello");\nfileSystem.ls("/");                         // return ["a"]\nfileSystem.readContentFromFile("/a/b/c/d"); // return "hello"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= path.length, filePath.length <= 100
    • \n\t
    • path and filePath are absolute paths which begin with '/' and do not end with '/' except that the path is just "/".
    • \n\t
    • You can assume that all directory names and file names only contain lowercase letters, and the same names will not exist in the same directory.
    • \n\t
    • You can assume that all operations will be passed valid parameters, and users will not attempt to retrieve file content or list a directory or file that does not exist.
    • \n\t
    • 1 <= content.length <= 50
    • \n\t
    • At most 300 calls will be made to ls, mkdiraddContentToFile, and readContentFromFile.
    • \n
    \n", "content_cn": "

    \u8bbe\u8ba1\u4e00\u4e2a\u5185\u5b58\u6587\u4ef6\u7cfb\u7edf\uff0c\u6a21\u62df\u4ee5\u4e0b\u529f\u80fd\uff1a

    \n\n

    ls\uff1a \u4ee5\u5b57\u7b26\u4e32\u7684\u683c\u5f0f\u8f93\u5165\u4e00\u4e2a\u8def\u5f84\u3002\u5982\u679c\u5b83\u662f\u4e00\u4e2a\u6587\u4ef6\u7684\u8def\u5f84\uff0c\u90a3\u4e48\u51fd\u6570\u8fd4\u56de\u4e00\u4e2a\u5217\u8868\uff0c\u4ec5\u5305\u542b\u8fd9\u4e2a\u6587\u4ef6\u7684\u540d\u5b57\u3002\u5982\u679c\u5b83\u662f\u4e00\u4e2a\u6587\u4ef6\u5939\u7684\u7684\u8def\u5f84\uff0c\u90a3\u4e48\u8fd4\u56de\u8be5 \u6587\u4ef6\u5939\u5185 \u7684\u6240\u6709\u6587\u4ef6\u548c\u5b50\u6587\u4ef6\u5939\u7684\u540d\u5b57\u3002\u4f60\u7684\u8fd4\u56de\u7ed3\u679c\uff08\u5305\u62ec\u6587\u4ef6\u548c\u5b50\u6587\u4ef6\u5939\uff09\u5e94\u8be5\u6309\u5b57\u5178\u5e8f\u6392\u5217\u3002

    \n\n

    mkdir\uff1a\u8f93\u5165\u4e00\u4e2a\u5f53\u524d\u4e0d\u5b58\u5728\u7684 \u6587\u4ef6\u5939\u8def\u5f84 \uff0c\u4f60\u9700\u8981\u6839\u636e\u8def\u5f84\u540d\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6587\u4ef6\u5939\u3002\u5982\u679c\u6709\u4e0a\u5c42\u6587\u4ef6\u5939\u8def\u5f84\u4e0d\u5b58\u5728\uff0c\u90a3\u4e48\u4f60\u4e5f\u5e94\u8be5\u5c06\u5b83\u4eec\u5168\u90e8\u521b\u5efa\u3002\u8fd9\u4e2a\u51fd\u6570\u7684\u8fd4\u56de\u7c7b\u578b\u4e3a void \u3002

    \n\n

    addContentToFile\uff1a \u8f93\u5165\u5b57\u7b26\u4e32\u5f62\u5f0f\u7684 \u6587\u4ef6\u8def\u5f84 \u548c \u6587\u4ef6\u5185\u5bb9 \u3002\u5982\u679c\u6587\u4ef6\u4e0d\u5b58\u5728\uff0c\u4f60\u9700\u8981\u521b\u5efa\u5305\u542b\u7ed9\u5b9a\u6587\u4ef6\u5185\u5bb9\u7684\u6587\u4ef6\u3002\u5982\u679c\u6587\u4ef6\u5df2\u7ecf\u5b58\u5728\uff0c\u90a3\u4e48\u4f60\u9700\u8981\u5c06\u7ed9\u5b9a\u7684\u6587\u4ef6\u5185\u5bb9 \u8ffd\u52a0 \u5728\u539f\u672c\u5185\u5bb9\u7684\u540e\u9762\u3002\u8fd9\u4e2a\u51fd\u6570\u7684\u8fd4\u56de\u7c7b\u578b\u4e3a void \u3002

    \n\n

    readContentFromFile\uff1a \u8f93\u5165 \u6587\u4ef6\u8def\u5f84 \uff0c\u4ee5\u5b57\u7b26\u4e32\u5f62\u5f0f\u8fd4\u56de\u8be5\u6587\u4ef6\u7684 \u5185\u5bb9 \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: \n["FileSystem","ls","mkdir","addContentToFile","ls","readContentFromFile"]\n[[],["/"],["/a/b/c"],["/a/b/c/d","hello"],["/"],["/a/b/c/d"]]\n\n\u8f93\u51fa:\n[null,[],null,null,["a"],"hello"]\n\n\u89e3\u91ca:\n\"filesystem\"\n
    \n\n

     

    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u4f60\u53ef\u4ee5\u5047\u5b9a\u6240\u6709\u6587\u4ef6\u548c\u6587\u4ef6\u5939\u7684\u8def\u5f84\u90fd\u662f\u7edd\u5bf9\u8def\u5f84\uff0c\u9664\u975e\u662f\u6839\u76ee\u5f55 / \u81ea\u8eab\uff0c\u5176\u4ed6\u8def\u5f84\u90fd\u662f\u4ee5 / \u5f00\u5934\u4e14 \u4e0d \u4ee5 / \u7ed3\u675f\u3002
    2. \n\t
    3. \u4f60\u53ef\u4ee5\u5047\u5b9a\u6240\u6709\u64cd\u4f5c\u7684\u53c2\u6570\u90fd\u662f\u6709\u6548\u7684\uff0c\u5373\u7528\u6237\u4e0d\u4f1a\u83b7\u53d6\u4e0d\u5b58\u5728\u6587\u4ef6\u7684\u5185\u5bb9\uff0c\u6216\u8005\u83b7\u53d6\u4e0d\u5b58\u5728\u6587\u4ef6\u5939\u548c\u6587\u4ef6\u7684\u5217\u8868\u3002
    4. \n\t
    5. \u4f60\u53ef\u4ee5\u5047\u5b9a\u6240\u6709\u6587\u4ef6\u5939\u540d\u5b57\u548c\u6587\u4ef6\u540d\u5b57\u90fd\u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd\uff0c\u4e14\u540c\u4e00\u6587\u4ef6\u5939\u4e0b\u4e0d\u4f1a\u6709\u76f8\u540c\u540d\u5b57\u7684\u6587\u4ef6\u5939\u6216\u6587\u4ef6\u3002
    6. \n
    \n", "tags_en": ["Design"], "tags_cn": ["\u8bbe\u8ba1"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class FileSystem {\npublic:\n FileSystem() {\n\n }\n \n vector ls(string path) {\n\n }\n \n void mkdir(string path) {\n\n }\n \n void addContentToFile(string filePath, string content) {\n\n }\n \n string readContentFromFile(string filePath) {\n\n }\n};\n\n/**\n * Your FileSystem object will be instantiated and called as such:\n * FileSystem* obj = new FileSystem();\n * vector param_1 = obj->ls(path);\n * obj->mkdir(path);\n * obj->addContentToFile(filePath,content);\n * string param_4 = obj->readContentFromFile(filePath);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class FileSystem {\n\n public FileSystem() {\n\n }\n \n public List ls(String path) {\n\n }\n \n public void mkdir(String path) {\n\n }\n \n public void addContentToFile(String filePath, String content) {\n\n }\n \n public String readContentFromFile(String filePath) {\n\n }\n}\n\n/**\n * Your FileSystem object will be instantiated and called as such:\n * FileSystem obj = new FileSystem();\n * List param_1 = obj.ls(path);\n * obj.mkdir(path);\n * obj.addContentToFile(filePath,content);\n * String param_4 = obj.readContentFromFile(filePath);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class FileSystem(object):\n\n def __init__(self):\n\n\n def ls(self, path):\n \"\"\"\n :type path: str\n :rtype: List[str]\n \"\"\"\n\n\n def mkdir(self, path):\n \"\"\"\n :type path: str\n :rtype: None\n \"\"\"\n\n\n def addContentToFile(self, filePath, content):\n \"\"\"\n :type filePath: str\n :type content: str\n :rtype: None\n \"\"\"\n\n\n def readContentFromFile(self, filePath):\n \"\"\"\n :type filePath: str\n :rtype: str\n \"\"\"\n\n\n\n# Your FileSystem object will be instantiated and called as such:\n# obj = FileSystem()\n# param_1 = obj.ls(path)\n# obj.mkdir(path)\n# obj.addContentToFile(filePath,content)\n# param_4 = obj.readContentFromFile(filePath)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class FileSystem:\n\n def __init__(self):\n\n\n def ls(self, path: str) -> List[str]:\n\n\n def mkdir(self, path: str) -> None:\n\n\n def addContentToFile(self, filePath: str, content: str) -> None:\n\n\n def readContentFromFile(self, filePath: str) -> str:\n\n\n\n# Your FileSystem object will be instantiated and called as such:\n# obj = FileSystem()\n# param_1 = obj.ls(path)\n# obj.mkdir(path)\n# obj.addContentToFile(filePath,content)\n# param_4 = obj.readContentFromFile(filePath)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} FileSystem;\n\n\nFileSystem* fileSystemCreate() {\n \n}\n\nchar ** fileSystemLs(FileSystem* obj, char * path, int* retSize) {\n \n}\n\nvoid fileSystemMkdir(FileSystem* obj, char * path) {\n \n}\n\nvoid fileSystemAddContentToFile(FileSystem* obj, char * filePath, char * content) {\n \n}\n\nchar * fileSystemReadContentFromFile(FileSystem* obj, char * filePath) {\n \n}\n\nvoid fileSystemFree(FileSystem* obj) {\n \n}\n\n/**\n * Your FileSystem struct will be instantiated and called as such:\n * FileSystem* obj = fileSystemCreate();\n * char ** param_1 = fileSystemLs(obj, path, retSize);\n \n * fileSystemMkdir(obj, path);\n \n * fileSystemAddContentToFile(obj, filePath, content);\n \n * char * param_4 = fileSystemReadContentFromFile(obj, filePath);\n \n * fileSystemFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class FileSystem {\n\n public FileSystem() {\n\n }\n \n public IList Ls(string path) {\n\n }\n \n public void Mkdir(string path) {\n\n }\n \n public void AddContentToFile(string filePath, string content) {\n\n }\n \n public string ReadContentFromFile(string filePath) {\n\n }\n}\n\n/**\n * Your FileSystem object will be instantiated and called as such:\n * FileSystem obj = new FileSystem();\n * IList param_1 = obj.Ls(path);\n * obj.Mkdir(path);\n * obj.AddContentToFile(filePath,content);\n * string param_4 = obj.ReadContentFromFile(filePath);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "\nvar FileSystem = function() {\n\n};\n\n/** \n * @param {string} path\n * @return {string[]}\n */\nFileSystem.prototype.ls = function(path) {\n\n};\n\n/** \n * @param {string} path\n * @return {void}\n */\nFileSystem.prototype.mkdir = function(path) {\n\n};\n\n/** \n * @param {string} filePath \n * @param {string} content\n * @return {void}\n */\nFileSystem.prototype.addContentToFile = function(filePath, content) {\n\n};\n\n/** \n * @param {string} filePath\n * @return {string}\n */\nFileSystem.prototype.readContentFromFile = function(filePath) {\n\n};\n\n/**\n * Your FileSystem object will be instantiated and called as such:\n * var obj = new FileSystem()\n * var param_1 = obj.ls(path)\n * obj.mkdir(path)\n * obj.addContentToFile(filePath,content)\n * var param_4 = obj.readContentFromFile(filePath)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class FileSystem\n def initialize()\n\n end\n\n\n=begin\n :type path: String\n :rtype: String[]\n=end\n def ls(path)\n\n end\n\n\n=begin\n :type path: String\n :rtype: Void\n=end\n def mkdir(path)\n\n end\n\n\n=begin\n :type file_path: String\n :type content: String\n :rtype: Void\n=end\n def add_content_to_file(file_path, content)\n\n end\n\n\n=begin\n :type file_path: String\n :rtype: String\n=end\n def read_content_from_file(file_path)\n\n end\n\n\nend\n\n# Your FileSystem object will be instantiated and called as such:\n# obj = FileSystem.new()\n# param_1 = obj.ls(path)\n# obj.mkdir(path)\n# obj.add_content_to_file(file_path, content)\n# param_4 = obj.read_content_from_file(file_path)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass FileSystem {\n\n init() {\n\n }\n \n func ls(_ path: String) -> [String] {\n\n }\n \n func mkdir(_ path: String) {\n\n }\n \n func addContentToFile(_ filePath: String, _ content: String) {\n\n }\n \n func readContentFromFile(_ filePath: String) -> String {\n\n }\n}\n\n/**\n * Your FileSystem object will be instantiated and called as such:\n * let obj = FileSystem()\n * let ret_1: [String] = obj.ls(path)\n * obj.mkdir(path)\n * obj.addContentToFile(filePath, content)\n * let ret_4: String = obj.readContentFromFile(filePath)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type FileSystem struct {\n\n}\n\n\nfunc Constructor() FileSystem {\n\n}\n\n\nfunc (this *FileSystem) Ls(path string) []string {\n\n}\n\n\nfunc (this *FileSystem) Mkdir(path string) {\n\n}\n\n\nfunc (this *FileSystem) AddContentToFile(filePath string, content string) {\n\n}\n\n\nfunc (this *FileSystem) ReadContentFromFile(filePath string) string {\n\n}\n\n\n/**\n * Your FileSystem object will be instantiated and called as such:\n * obj := Constructor();\n * param_1 := obj.Ls(path);\n * obj.Mkdir(path);\n * obj.AddContentToFile(filePath,content);\n * param_4 := obj.ReadContentFromFile(filePath);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class FileSystem() {\n\n def ls(path: String): List[String] = {\n\n }\n\n def mkdir(path: String) {\n\n }\n\n def addContentToFile(filePath: String, content: String) {\n\n }\n\n def readContentFromFile(filePath: String): String = {\n\n }\n\n}\n\n/**\n * Your FileSystem object will be instantiated and called as such:\n * var obj = new FileSystem()\n * var param_1 = obj.ls(path)\n * obj.mkdir(path)\n * obj.addContentToFile(filePath,content)\n * var param_4 = obj.readContentFromFile(filePath)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class FileSystem() {\n\n fun ls(path: String): List {\n\n }\n\n fun mkdir(path: String) {\n\n }\n\n fun addContentToFile(filePath: String, content: String) {\n\n }\n\n fun readContentFromFile(filePath: String): String {\n\n }\n\n}\n\n/**\n * Your FileSystem object will be instantiated and called as such:\n * var obj = FileSystem()\n * var param_1 = obj.ls(path)\n * obj.mkdir(path)\n * obj.addContentToFile(filePath,content)\n * var param_4 = obj.readContentFromFile(filePath)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct FileSystem {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl FileSystem {\n\n fn new() -> Self {\n\n }\n \n fn ls(&self, path: String) -> Vec {\n\n }\n \n fn mkdir(&self, path: String) {\n\n }\n \n fn add_content_to_file(&self, file_path: String, content: String) {\n\n }\n \n fn read_content_from_file(&self, file_path: String) -> String {\n\n }\n}\n\n/**\n * Your FileSystem object will be instantiated and called as such:\n * let obj = FileSystem::new();\n * let ret_1: Vec = obj.ls(path);\n * obj.mkdir(path);\n * obj.add_content_to_file(filePath, content);\n * let ret_4: String = obj.read_content_from_file(filePath);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class FileSystem {\n /**\n */\n function __construct() {\n\n }\n\n /**\n * @param String $path\n * @return String[]\n */\n function ls($path) {\n\n }\n\n /**\n * @param String $path\n * @return NULL\n */\n function mkdir($path) {\n\n }\n\n /**\n * @param String $filePath\n * @param String $content\n * @return NULL\n */\n function addContentToFile($filePath, $content) {\n\n }\n\n /**\n * @param String $filePath\n * @return String\n */\n function readContentFromFile($filePath) {\n\n }\n}\n\n/**\n * Your FileSystem object will be instantiated and called as such:\n * $obj = FileSystem();\n * $ret_1 = $obj->ls($path);\n * $obj->mkdir($path);\n * $obj->addContentToFile($filePath, $content);\n * $ret_4 = $obj->readContentFromFile($filePath);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class FileSystem {\n constructor() {\n\n }\n\n ls(path: string): string[] {\n\n }\n\n mkdir(path: string): void {\n\n }\n\n addContentToFile(filePath: string, content: string): void {\n\n }\n\n readContentFromFile(filePath: string): string {\n\n }\n}\n\n/**\n * Your FileSystem object will be instantiated and called as such:\n * var obj = new FileSystem()\n * var param_1 = obj.ls(path)\n * obj.mkdir(path)\n * obj.addContentToFile(filePath,content)\n * var param_4 = obj.readContentFromFile(filePath)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define file-system%\n (class object%\n (super-new)\n (init-field)\n \n ; ls : string? -> (listof string?)\n (define/public (ls path)\n\n )\n ; mkdir : string? -> void?\n (define/public (mkdir path)\n\n )\n ; add-content-to-file : string? string? -> void?\n (define/public (add-content-to-file filePath content)\n\n )\n ; read-content-from-file : string? -> string?\n (define/public (read-content-from-file filePath)\n\n )))\n\n;; Your file-system% object will be instantiated and called as such:\n;; (define obj (new file-system%))\n;; (define param_1 (send obj ls path))\n;; (send obj mkdir path)\n;; (send obj add-content-to-file file-path content)\n;; (define param_4 (send obj read-content-from-file file-path))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0588](https://leetcode-cn.com/problems/design-in-memory-file-system)", "[\u8bbe\u8ba1\u5185\u5b58\u6587\u4ef6\u7cfb\u7edf](/solution/0500-0599/0588.Design%20In-Memory%20File%20System/README.md)", "`\u8bbe\u8ba1`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0588](https://leetcode.com/problems/design-in-memory-file-system)", "[Design In-Memory File System](/solution/0500-0599/0588.Design%20In-Memory%20File%20System/README_EN.md)", "`Design`", "Hard", "\ud83d\udd12"]}, {"question_id": "0587", "frontend_question_id": "0587", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/erect-the-fence", "url_en": "https://leetcode.com/problems/erect-the-fence", "relative_path_cn": "/solution/0500-0599/0587.Erect%20the%20Fence/README.md", "relative_path_en": "/solution/0500-0599/0587.Erect%20the%20Fence/README_EN.md", "title_cn": "\u5b89\u88c5\u6805\u680f", "title_en": "Erect the Fence", "question_title_slug": "erect-the-fence", "content_en": "

    You are given an array trees where trees[i] = [xi, yi] represents the location of a tree in the garden.

    \n\n

    You are asked to fence the entire garden using the minimum length of rope as it is expensive. The garden is well fenced only if all the trees are enclosed.

    \n\n

    Return the coordinates of trees that are exactly located on the fence perimeter.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: points = [[1,1],[2,2],[2,0],[2,4],[3,3],[4,2]]\nOutput: [[1,1],[2,0],[3,3],[2,4],[4,2]]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: points = [[1,2],[2,2],[4,2]]\nOutput: [[4,2],[2,2],[1,2]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= points.length <= 3000
    • \n\t
    • points[i].length == 2
    • \n\t
    • 0 <= xi, yi <= 100
    • \n\t
    • All the given points are unique.
    • \n
    \n", "content_cn": "

    \u5728\u4e00\u4e2a\u4e8c\u7ef4\u7684\u82b1\u56ed\u4e2d\uff0c\u6709\u4e00\u4e9b\u7528 (x, y) \u5750\u6807\u8868\u793a\u7684\u6811\u3002\u7531\u4e8e\u5b89\u88c5\u8d39\u7528\u5341\u5206\u6602\u8d35\uff0c\u4f60\u7684\u4efb\u52a1\u662f\u5148\u7528\u6700\u77ed\u7684\u7ef3\u5b50\u56f4\u8d77\u6240\u6709\u7684\u6811\u3002\u53ea\u6709\u5f53\u6240\u6709\u7684\u6811\u90fd\u88ab\u7ef3\u5b50\u5305\u56f4\u65f6\uff0c\u82b1\u56ed\u624d\u80fd\u56f4\u597d\u6805\u680f\u3002\u4f60\u9700\u8981\u627e\u5230\u6b63\u597d\u4f4d\u4e8e\u6805\u680f\u8fb9\u754c\u4e0a\u7684\u6811\u7684\u5750\u6807\u3002

    \r\n\r\n

     

    \r\n\r\n

    \u793a\u4f8b 1:

    \r\n\r\n
    \u8f93\u5165: [[1,1],[2,2],[2,0],[2,4],[3,3],[4,2]]\r\n\u8f93\u51fa: [[1,1],[2,0],[4,2],[3,3],[2,4]]\r\n\u89e3\u91ca:\r\n\r\n
    \r\n\r\n

    \u793a\u4f8b 2:

    \r\n\r\n
    \u8f93\u5165: [[1,2],[2,2],[4,2]]\r\n\u8f93\u51fa: [[1,2],[2,2],[4,2]]\r\n\u89e3\u91ca:\r\n\r\n\u5373\u4f7f\u6811\u90fd\u5728\u4e00\u6761\u76f4\u7ebf\u4e0a\uff0c\u4f60\u4e5f\u9700\u8981\u5148\u7528\u7ef3\u5b50\u5305\u56f4\u5b83\u4eec\u3002\r\n
    \r\n\r\n

     

    \r\n\r\n

    \u6ce8\u610f:

    \r\n\r\n
      \r\n\t
    1. \u6240\u6709\u7684\u6811\u5e94\u5f53\u88ab\u56f4\u5728\u4e00\u8d77\u3002\u4f60\u4e0d\u80fd\u526a\u65ad\u7ef3\u5b50\u6765\u5305\u56f4\u6811\u6216\u8005\u628a\u6811\u5206\u6210\u4e00\u7ec4\u4ee5\u4e0a\u3002
    2. \r\n\t
    3. \u8f93\u5165\u7684\u6574\u6570\u5728 0 \u5230 100 \u4e4b\u95f4\u3002
    4. \r\n\t
    5. \u82b1\u56ed\u81f3\u5c11\u6709\u4e00\u68f5\u6811\u3002
    6. \r\n\t
    7. \u6240\u6709\u6811\u7684\u5750\u6807\u90fd\u662f\u4e0d\u540c\u7684\u3002
    8. \r\n\t
    9. \u8f93\u5165\u7684\u70b9\u6ca1\u6709\u987a\u5e8f\u3002\u8f93\u51fa\u987a\u5e8f\u4e5f\u6ca1\u6709\u8981\u6c42\u3002
    10. \r\n
    ", "tags_en": ["Geometry"], "tags_cn": ["\u51e0\u4f55"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> outerTrees(vector>& trees) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[][] outerTrees(int[][] trees) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def outerTrees(self, trees):\n \"\"\"\n :type trees: List[List[int]]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def outerTrees(self, trees: List[List[int]]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** outerTrees(int** trees, int treesSize, int* treesColSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[][] OuterTrees(int[][] trees) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} trees\n * @return {number[][]}\n */\nvar outerTrees = function(trees) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} trees\n# @return {Integer[][]}\ndef outer_trees(trees)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func outerTrees(_ trees: [[Int]]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func outerTrees(trees [][]int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def outerTrees(trees: Array[Array[Int]]): Array[Array[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun outerTrees(trees: Array): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn outer_trees(trees: Vec>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $trees\n * @return Integer[][]\n */\n function outerTrees($trees) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function outerTrees(trees: number[][]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (outer-trees trees)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0587](https://leetcode-cn.com/problems/erect-the-fence)", "[\u5b89\u88c5\u6805\u680f](/solution/0500-0599/0587.Erect%20the%20Fence/README.md)", "`\u51e0\u4f55`", "\u56f0\u96be", ""], "md_table_row_en": ["[0587](https://leetcode.com/problems/erect-the-fence)", "[Erect the Fence](/solution/0500-0599/0587.Erect%20the%20Fence/README_EN.md)", "`Geometry`", "Hard", ""]}, {"question_id": "0586", "frontend_question_id": "0586", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/customer-placing-the-largest-number-of-orders", "url_en": "https://leetcode.com/problems/customer-placing-the-largest-number-of-orders", "relative_path_cn": "/solution/0500-0599/0586.Customer%20Placing%20the%20Largest%20Number%20of%20Orders/README.md", "relative_path_en": "/solution/0500-0599/0586.Customer%20Placing%20the%20Largest%20Number%20of%20Orders/README_EN.md", "title_cn": "\u8ba2\u5355\u6700\u591a\u7684\u5ba2\u6237", "title_en": "Customer Placing the Largest Number of Orders", "question_title_slug": "customer-placing-the-largest-number-of-orders", "content_en": "

    Table: Orders

    \n\n
    \n+-----------------+----------+\n| Column Name     | Type     |\n+-----------------+----------+\n| order_number    | int      |\n| customer_number | int      |\n+-----------------+----------+\norder_number is the primary key for this table.\nThis table contains information about the order ID and the customer ID.\n
    \n\n

     

    \n\n

    Write an SQL query to find the customer_number for the customer who has placed the largest number of orders.

    \n\n

    It is guaranteed that exactly one customer will have placed more orders than any other customer.

    \n\n

    The query result format is in the following example:

    \n\n

     

    \n\n
    \nOrders table:\n+--------------+-----------------+\n| order_number | customer_number |\n+--------------+-----------------+\n| 1            | 1               |\n| 2            | 2               |\n| 3            | 3               |\n| 4            | 3               |\n+--------------+-----------------+\n\nResult table:\n+-----------------+\n| customer_number |\n+-----------------+\n| 3               |\n+-----------------+\nThe customer with number 3 has two orders, which is greater than either customer 1 or 2 because each of them only has one order. \nSo the result is customer_number 3.\n
    \n\n

     

    \nFollow up: What if more than one customer have the largest number of orders, can you find all the customer_number in this case?", "content_cn": "

    \u5728\u8868 orders \u4e2d\u627e\u5230\u8ba2\u5355\u6570\u6700\u591a\u5ba2\u6237\u5bf9\u5e94\u7684 customer_number \u3002

    \n\n

    \u6570\u636e\u4fdd\u8bc1\u8ba2\u5355\u6570\u6700\u591a\u7684\u987e\u5ba2\u6070\u597d\u53ea\u6709\u4e00\u4f4d\u3002

    \n\n

    \u8868 orders \u5b9a\u4e49\u5982\u4e0b\uff1a

    \n\n
    | Column            | Type      |\n|-------------------|-----------|\n| order_number (PK) | int       |\n| customer_number   | int       |\n| order_date        | date      |\n| required_date     | date      |\n| shipped_date      | date      |\n| status            | char(15)  |\n| comment           | char(200) |\n
    \n\n

    \u6837\u4f8b\u8f93\u5165

    \n\n
    | order_number | customer_number | order_date | required_date | shipped_date | status | comment |\n|--------------|-----------------|------------|---------------|--------------|--------|---------|\n| 1            | 1               | 2017-04-09 | 2017-04-13    | 2017-04-12   | Closed |         |\n| 2            | 2               | 2017-04-15 | 2017-04-20    | 2017-04-18   | Closed |         |\n| 3            | 3               | 2017-04-16 | 2017-04-25    | 2017-04-20   | Closed |         |\n| 4            | 3               | 2017-04-18 | 2017-04-28    | 2017-04-25   | Closed |         |\n
    \n\n

    \u6837\u4f8b\u8f93\u51fa

    \n\n
    | customer_number |\n|-----------------|\n| 3               |\n
    \n\n

    \u89e3\u91ca

    \n\n
    customer_number \u4e3a '3' \u7684\u987e\u5ba2\u6709\u4e24\u4e2a\u8ba2\u5355\uff0c\u6bd4\u987e\u5ba2 '1' \u6216\u8005 '2' \u90fd\u8981\u591a\uff0c\u56e0\u4e3a\u4ed6\u4eec\u53ea\u6709\u4e00\u4e2a\u8ba2\u5355\n\u6240\u4ee5\u7ed3\u679c\u662f\u8be5\u987e\u5ba2\u7684 customer_number \uff0c\u4e5f\u5c31\u662f 3 \u3002\n
    \n\n

    \u8fdb\u9636\uff1a \u5982\u679c\u6709\u591a\u4f4d\u987e\u5ba2\u8ba2\u5355\u6570\u5e76\u5217\u6700\u591a\uff0c\u4f60\u80fd\u627e\u5230\u4ed6\u4eec\u6240\u6709\u7684 customer_number \u5417\uff1f

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0586](https://leetcode-cn.com/problems/customer-placing-the-largest-number-of-orders)", "[\u8ba2\u5355\u6700\u591a\u7684\u5ba2\u6237](/solution/0500-0599/0586.Customer%20Placing%20the%20Largest%20Number%20of%20Orders/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0586](https://leetcode.com/problems/customer-placing-the-largest-number-of-orders)", "[Customer Placing the Largest Number of Orders](/solution/0500-0599/0586.Customer%20Placing%20the%20Largest%20Number%20of%20Orders/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "0585", "frontend_question_id": "0585", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/investments-in-2016", "url_en": "https://leetcode.com/problems/investments-in-2016", "relative_path_cn": "/solution/0500-0599/0585.Investments%20in%202016/README.md", "relative_path_en": "/solution/0500-0599/0585.Investments%20in%202016/README_EN.md", "title_cn": "2016\u5e74\u7684\u6295\u8d44", "title_en": "Investments in 2016", "question_title_slug": "investments-in-2016", "content_en": "

    Write a query to print the sum of all total investment values in 2016 (TIV_2016), to a scale of 2 decimal places, for all policy holders who meet the following criteria:

    \r\n\r\n
      \r\n\t
    1. Have the same TIV_2015 value as one or more other policyholders.
    2. \r\n\t
    3. Are not located in the same city as any other policyholder (i.e.: the (latitude, longitude) attribute pairs must be unique).
    4. \r\n
    \r\n\r\n

    Input Format:
    \r\nThe insurance table is described as follows:

    \r\n\r\n
    \r\n| Column Name | Type          |\r\n|-------------|---------------|\r\n| PID         | INTEGER(11)   |\r\n| TIV_2015    | NUMERIC(15,2) |\r\n| TIV_2016    | NUMERIC(15,2) |\r\n| LAT         | NUMERIC(5,2)  |\r\n| LON         | NUMERIC(5,2)  |\r\n
    \r\n\r\n

    where PID is the policyholder's policy ID, TIV_2015 is the total investment value in 2015, TIV_2016 is the total investment value in 2016, LAT is the latitude of the policy holder's city, and LON is the longitude of the policy holder's city.

    \r\n\r\n

    Sample Input

    \r\n\r\n
    \r\n| PID | TIV_2015 | TIV_2016 | LAT | LON |\r\n|-----|----------|----------|-----|-----|\r\n| 1   | 10       | 5        | 10  | 10  |\r\n| 2   | 20       | 20       | 20  | 20  |\r\n| 3   | 10       | 30       | 20  | 20  |\r\n| 4   | 10       | 40       | 40  | 40  |\r\n
    \r\n\r\n

    Sample Output

    \r\n\r\n
    \r\n| TIV_2016 |\r\n|----------|\r\n| 45.00    |\r\n
    \r\n\r\n

    Explanation

    \r\n\r\n
    \r\nThe first record in the table, like the last record, meets both of the two criteria.\r\nThe TIV_2015 value '10' is as the same as the third and forth record, and its location unique.\r\n\r\nThe second record does not meet any of the two criteria. Its TIV_2015 is not like any other policyholders.\r\n\r\nAnd its location is the same with the third record, which makes the third record fail, too.\r\n\r\nSo, the result is the sum of TIV_2016 of the first and last record, which is 45.
    \r\n", "content_cn": "

    \u5199\u4e00\u4e2a\u67e5\u8be2\u8bed\u53e5\uff0c\u5c06 2016 \u5e74 (TIV_2016) \u6240\u6709\u6210\u529f\u6295\u8d44\u7684\u91d1\u989d\u52a0\u8d77\u6765\uff0c\u4fdd\u7559 2 \u4f4d\u5c0f\u6570\u3002

    \n\n

    \u5bf9\u4e8e\u4e00\u4e2a\u6295\u4fdd\u4eba\uff0c\u4ed6\u5728 2016 \u5e74\u6210\u529f\u6295\u8d44\u7684\u6761\u4ef6\u662f\uff1a

    \n\n
      \n\t
    1. \u4ed6\u5728 2015 \u5e74\u7684\u6295\u4fdd\u989d (TIV_2015) \u81f3\u5c11\u8ddf\u4e00\u4e2a\u5176\u4ed6\u6295\u4fdd\u4eba\u5728 2015 \u5e74\u7684\u6295\u4fdd\u989d\u76f8\u540c\u3002
    2. \n\t
    3. \u4ed6\u6240\u5728\u7684\u57ce\u5e02\u5fc5\u987b\u4e0e\u5176\u4ed6\u6295\u4fdd\u4eba\u90fd\u4e0d\u540c\uff08\u4e5f\u5c31\u662f\u8bf4\u7ef4\u5ea6\u548c\u7ecf\u5ea6\u4e0d\u80fd\u8ddf\u5176\u4ed6\u4efb\u4f55\u4e00\u4e2a\u6295\u4fdd\u4eba\u5b8c\u5168\u76f8\u540c\uff09\u3002
    4. \n
    \n\n

    \u8f93\u5165\u683c\u5f0f:
    \n\u8868 insurance \u683c\u5f0f\u5982\u4e0b\uff1a

    \n\n
    | Column Name | Type          |\n|-------------|---------------|\n| PID         | INTEGER(11)   |\n| TIV_2015    | NUMERIC(15,2) |\n| TIV_2016    | NUMERIC(15,2) |\n| LAT         | NUMERIC(5,2)  |\n| LON         | NUMERIC(5,2)  |\n
    \n\n

    PID \u5b57\u6bb5\u662f\u6295\u4fdd\u4eba\u7684\u6295\u4fdd\u7f16\u53f7\uff0c TIV_2015 \u662f\u8be5\u6295\u4fdd\u4eba\u57282015\u5e74\u7684\u603b\u6295\u4fdd\u91d1\u989d\uff0c TIV_2016 \u662f\u8be5\u6295\u4fdd\u4eba\u57282016\u5e74\u7684\u6295\u4fdd\u91d1\u989d\uff0c LAT \u662f\u6295\u4fdd\u4eba\u6240\u5728\u57ce\u5e02\u7684\u7ef4\u5ea6\uff0c LON \u662f\u6295\u4fdd\u4eba\u6240\u5728\u57ce\u5e02\u7684\u7ecf\u5ea6\u3002

    \n\n

    \u6837\u4f8b\u8f93\u5165

    \n\n
    | PID | TIV_2015 | TIV_2016 | LAT | LON |\n|-----|----------|----------|-----|-----|\n| 1   | 10       | 5        | 10  | 10  |\n| 2   | 20       | 20       | 20  | 20  |\n| 3   | 10       | 30       | 20  | 20  |\n| 4   | 10       | 40       | 40  | 40  |\n
    \n\n

    \u6837\u4f8b\u8f93\u51fa

    \n\n
    | TIV_2016 |\n|----------|\n| 45.00    |\n
    \n\n

    \u89e3\u91ca

    \n\n
    \u5c31\u5982\u6700\u540e\u4e00\u4e2a\u6295\u4fdd\u4eba\uff0c\u7b2c\u4e00\u4e2a\u6295\u4fdd\u4eba\u540c\u65f6\u6ee1\u8db3\u4e24\u4e2a\u6761\u4ef6\uff1a\n1. \u4ed6\u5728 2015 \u5e74\u7684\u6295\u4fdd\u91d1\u989d TIV_2015 \u4e3a '10' \uff0c\u4e0e\u7b2c\u4e09\u4e2a\u548c\u7b2c\u56db\u4e2a\u6295\u4fdd\u4eba\u5728 2015 \u5e74\u7684\u6295\u4fdd\u91d1\u989d\u76f8\u540c\u3002\n2. \u4ed6\u6240\u5728\u57ce\u5e02\u7684\u7ecf\u7eac\u5ea6\u662f\u72ec\u4e00\u65e0\u4e8c\u7684\u3002\n\n\u7b2c\u4e8c\u4e2a\u6295\u4fdd\u4eba\u4e24\u4e2a\u6761\u4ef6\u90fd\u4e0d\u6ee1\u8db3\u3002\u4ed6\u5728 2015 \u5e74\u7684\u6295\u8d44 TIV_2015 \u4e0e\u5176\u4ed6\u4efb\u4f55\u6295\u4fdd\u4eba\u90fd\u4e0d\u76f8\u540c\u3002\n\u4e14\u4ed6\u6240\u5728\u57ce\u5e02\u7684\u7ecf\u7eac\u5ea6\u4e0e\u7b2c\u4e09\u4e2a\u6295\u4fdd\u4eba\u76f8\u540c\u3002\u57fa\u4e8e\u540c\u6837\u7684\u539f\u56e0\uff0c\u7b2c\u4e09\u4e2a\u6295\u4fdd\u4eba\u6295\u8d44\u5931\u8d25\u3002\n\n\u6240\u4ee5\u8fd4\u56de\u7684\u7ed3\u679c\u662f\u7b2c\u4e00\u4e2a\u6295\u4fdd\u4eba\u548c\u6700\u540e\u4e00\u4e2a\u6295\u4fdd\u4eba\u7684 TIV_2016 \u4e4b\u548c\uff0c\u7ed3\u679c\u662f 45 \u3002
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0585](https://leetcode-cn.com/problems/investments-in-2016)", "[2016\u5e74\u7684\u6295\u8d44](/solution/0500-0599/0585.Investments%20in%202016/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0585](https://leetcode.com/problems/investments-in-2016)", "[Investments in 2016](/solution/0500-0599/0585.Investments%20in%202016/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "0584", "frontend_question_id": "0584", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/find-customer-referee", "url_en": "https://leetcode.com/problems/find-customer-referee", "relative_path_cn": "/solution/0500-0599/0584.Find%20Customer%20Referee/README.md", "relative_path_en": "/solution/0500-0599/0584.Find%20Customer%20Referee/README_EN.md", "title_cn": "\u5bfb\u627e\u7528\u6237\u63a8\u8350\u4eba", "title_en": "Find Customer Referee", "question_title_slug": "find-customer-referee", "content_en": "

    Given a table customer holding customers information and the referee.

    \r\n\r\n
    \r\n+------+------+-----------+\r\n| id   | name | referee_id|\r\n+------+------+-----------+\r\n|    1 | Will |      NULL |\r\n|    2 | Jane |      NULL |\r\n|    3 | Alex |         2 |\r\n|    4 | Bill |      NULL |\r\n|    5 | Zack |         1 |\r\n|    6 | Mark |         2 |\r\n+------+------+-----------+\r\n
    \r\n\r\n

    Write a query to return the list of customers NOT referred by the person with id '2'.

    \r\n\r\n

    For the sample data above, the result is:

    \r\n\r\n
    \r\n+------+\r\n| name |\r\n+------+\r\n| Will |\r\n| Jane |\r\n| Bill |\r\n| Zack |\r\n+------+\r\n
    \r\n", "content_cn": "

    \u7ed9\u5b9a\u8868\u00a0customer\u00a0\uff0c\u91cc\u9762\u4fdd\u5b58\u4e86\u6240\u6709\u5ba2\u6237\u4fe1\u606f\u548c\u4ed6\u4eec\u7684\u63a8\u8350\u4eba\u3002

    \n\n
    \n+------+------+-----------+\n| id   | name | referee_id|\n+------+------+-----------+\n|    1 | Will |      NULL |\n|    2 | Jane |      NULL |\n|    3 | Alex |         2 |\n|    4 | Bill |      NULL |\n|    5 | Zack |         1 |\n|    6 | Mark |         2 |\n+------+------+-----------+\n
    \n\n

    \u5199\u4e00\u4e2a\u67e5\u8be2\u8bed\u53e5\uff0c\u8fd4\u56de\u4e00\u4e2a\u5ba2\u6237\u5217\u8868\uff0c\u5217\u8868\u4e2d\u5ba2\u6237\u7684\u63a8\u8350\u4eba\u7684\u7f16\u53f7\u90fd\u00a0\u4e0d\u662f 2\u3002

    \n\n

    \u5bf9\u4e8e\u4e0a\u9762\u7684\u793a\u4f8b\u6570\u636e\uff0c\u7ed3\u679c\u4e3a\uff1a

    \n\n
    \n+------+\n| name |\n+------+\n| Will |\n| Jane |\n| Bill |\n| Zack |\n+------+\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0584](https://leetcode-cn.com/problems/find-customer-referee)", "[\u5bfb\u627e\u7528\u6237\u63a8\u8350\u4eba](/solution/0500-0599/0584.Find%20Customer%20Referee/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0584](https://leetcode.com/problems/find-customer-referee)", "[Find Customer Referee](/solution/0500-0599/0584.Find%20Customer%20Referee/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "0583", "frontend_question_id": "0583", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/delete-operation-for-two-strings", "url_en": "https://leetcode.com/problems/delete-operation-for-two-strings", "relative_path_cn": "/solution/0500-0599/0583.Delete%20Operation%20for%20Two%20Strings/README.md", "relative_path_en": "/solution/0500-0599/0583.Delete%20Operation%20for%20Two%20Strings/README_EN.md", "title_cn": "\u4e24\u4e2a\u5b57\u7b26\u4e32\u7684\u5220\u9664\u64cd\u4f5c", "title_en": "Delete Operation for Two Strings", "question_title_slug": "delete-operation-for-two-strings", "content_en": "

    Given two strings word1 and word2, return the minimum number of steps required to make word1 and word2 the same.

    \n\n

    In one step, you can delete exactly one character in either string.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: word1 = "sea", word2 = "eat"\nOutput: 2\nExplanation: You need one step to make "sea" to "ea" and another step to make "eat" to "ea".\n
    \n\n

    Example 2:

    \n\n
    \nInput: word1 = "leetcode", word2 = "etco"\nOutput: 4\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= word1.length, word2.length <= 500
    • \n\t
    • word1 and word2 consist of only lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u5355\u8bcd word1 \u548c word2\uff0c\u627e\u5230\u4f7f\u5f97 word1 \u548c word2 \u76f8\u540c\u6240\u9700\u7684\u6700\u5c0f\u6b65\u6570\uff0c\u6bcf\u6b65\u53ef\u4ee5\u5220\u9664\u4efb\u610f\u4e00\u4e2a\u5b57\u7b26\u4e32\u4e2d\u7684\u4e00\u4e2a\u5b57\u7b26\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165: "sea", "eat"\n\u8f93\u51fa: 2\n\u89e3\u91ca: \u7b2c\u4e00\u6b65\u5c06"sea"\u53d8\u4e3a"ea"\uff0c\u7b2c\u4e8c\u6b65\u5c06"eat"\u53d8\u4e3a"ea"\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. \u7ed9\u5b9a\u5355\u8bcd\u7684\u957f\u5ea6\u4e0d\u8d85\u8fc7500\u3002
    2. \n\t
    3. \u7ed9\u5b9a\u5355\u8bcd\u4e2d\u7684\u5b57\u7b26\u53ea\u542b\u6709\u5c0f\u5199\u5b57\u6bcd\u3002
    4. \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minDistance(string word1, string word2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minDistance(String word1, String word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minDistance(self, word1, word2):\n \"\"\"\n :type word1: str\n :type word2: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minDistance(self, word1: str, word2: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minDistance(char * word1, char * word2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinDistance(string word1, string word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} word1\n * @param {string} word2\n * @return {number}\n */\nvar minDistance = function(word1, word2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} word1\n# @param {String} word2\n# @return {Integer}\ndef min_distance(word1, word2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minDistance(_ word1: String, _ word2: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minDistance(word1 string, word2 string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minDistance(word1: String, word2: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minDistance(word1: String, word2: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_distance(word1: String, word2: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $word1\n * @param String $word2\n * @return Integer\n */\n function minDistance($word1, $word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minDistance(word1: string, word2: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-distance word1 word2)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0583](https://leetcode-cn.com/problems/delete-operation-for-two-strings)", "[\u4e24\u4e2a\u5b57\u7b26\u4e32\u7684\u5220\u9664\u64cd\u4f5c](/solution/0500-0599/0583.Delete%20Operation%20for%20Two%20Strings/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0583](https://leetcode.com/problems/delete-operation-for-two-strings)", "[Delete Operation for Two Strings](/solution/0500-0599/0583.Delete%20Operation%20for%20Two%20Strings/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "0582", "frontend_question_id": "0582", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/kill-process", "url_en": "https://leetcode.com/problems/kill-process", "relative_path_cn": "/solution/0500-0599/0582.Kill%20Process/README.md", "relative_path_en": "/solution/0500-0599/0582.Kill%20Process/README_EN.md", "title_cn": "\u6740\u6389\u8fdb\u7a0b", "title_en": "Kill Process", "question_title_slug": "kill-process", "content_en": "

    You have n processes forming a rooted tree structure. You are given two integer arrays pid and ppid, where pid[i] is the ID of the ith process and ppid[i] is the ID of the ith process's parent process.

    \n\n

    Each process has only one parent process but may have multiple children processes. Only one process has ppid[i] = 0, which means this process has no parent process (the root of the tree).

    \n\n

    When a process is killed, all of its children processes will also be killed.

    \n\n

    Given an integer kill representing the ID of a process you want to kill, return a list of the IDs of the processes that will be killed. You may return the answer in any order.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: pid = [1,3,10,5], ppid = [3,0,5,3], kill = 5\nOutput: [5,10]\nExplanation: The processes colored in red are the processes that should be killed.\n
    \n\n

    Example 2:

    \n\n
    \nInput: pid = [1], ppid = [0], kill = 1\nOutput: [1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == pid.length
    • \n\t
    • n == ppid.length
    • \n\t
    • 1 <= n <= 5 * 104
    • \n\t
    • 1 <= pid[i] <= 5 * 104
    • \n\t
    • 0 <= ppid[i] <= 5 * 104
    • \n\t
    • Only one process has no parent.
    • \n\t
    • All the values of pid are unique.
    • \n\t
    • kill is guaranteed to be in pid.
    • \n
    \n", "content_cn": "

    \u7cfb\u7edf\u4e2d\u5b58\u5728 n\u00a0\u4e2a\u8fdb\u7a0b\uff0c\u5f62\u6210\u4e00\u4e2a\u6709\u6839\u6811\u7ed3\u6784\u3002\u7ed9\u4f60\u4e24\u4e2a\u6574\u6570\u6570\u7ec4\u00a0pid \u548c ppid \uff0c\u5176\u4e2d pid[i] \u662f\u7b2c i \u4e2a\u8fdb\u7a0b\u7684 ID \uff0cppid[i] \u662f\u7b2c i \u4e2a\u8fdb\u7a0b\u7684\u7236\u8fdb\u7a0b ID \u3002

    \n\n

    \u6bcf\u4e00\u4e2a\u8fdb\u7a0b\u53ea\u6709 \u4e00\u4e2a\u7236\u8fdb\u7a0b \uff0c\u4f46\u662f\u53ef\u80fd\u4f1a\u6709 \u4e00\u4e2a\u6216\u8005\u591a\u4e2a\u5b50\u8fdb\u7a0b \u3002\u53ea\u6709\u4e00\u4e2a\u8fdb\u7a0b\u7684 ppid[i] = 0 \uff0c\u610f\u5473\u7740\u8fd9\u4e2a\u8fdb\u7a0b \u6ca1\u6709\u7236\u8fdb\u7a0b \u3002

    \n\n

    \u5f53\u4e00\u4e2a\u8fdb\u7a0b \u88ab\u6740\u6389 \u7684\u65f6\u5019\uff0c\u5b83\u6240\u6709\u7684\u5b50\u8fdb\u7a0b\u548c\u540e\u4ee3\u8fdb\u7a0b\u90fd\u8981\u88ab\u6740\u6389\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 kill \u8868\u793a\u8981\u6740\u6389\u200b\u200b\u8fdb\u7a0b\u7684 ID \uff0c\u8fd4\u56de\u6740\u6389\u8be5\u8fdb\u7a0b\u540e\u7684\u6240\u6709\u8fdb\u7a0b ID \u7684\u5217\u8868\u3002\u53ef\u4ee5\u6309 \u4efb\u610f\u987a\u5e8f \u8fd4\u56de\u7b54\u6848\u3002

    \n\u00a0\n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1apid = [1,3,10,5], ppid = [3,0,5,3], kill = 5\n\u8f93\u51fa\uff1a[5,10]\n\u89e3\u91ca\uff1a\u6d82\u4e3a\u7ea2\u8272\u7684\u8fdb\u7a0b\u662f\u5e94\u8be5\u88ab\u6740\u6389\u7684\u8fdb\u7a0b\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1apid = [1], ppid = [0], kill = 1\n\u8f93\u51fa\uff1a[1]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == pid.length
    • \n\t
    • n == ppid.length
    • \n\t
    • 1 <= n <= 5 * 104
    • \n\t
    • 1 <= pid[i] <= 5 * 104
    • \n\t
    • 0 <= ppid[i] <= 5 * 104
    • \n\t
    • \u4ec5\u6709\u4e00\u4e2a\u8fdb\u7a0b\u6ca1\u6709\u7236\u8fdb\u7a0b
    • \n\t
    • pid \u4e2d\u7684\u6240\u6709\u503c \u4e92\u4e0d\u76f8\u540c
    • \n\t
    • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1 kill \u5728 pid \u4e2d
    • \n
    \n", "tags_en": ["Tree", "Queue"], "tags_cn": ["\u6811", "\u961f\u5217"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector killProcess(vector& pid, vector& ppid, int kill) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List killProcess(List pid, List ppid, int kill) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def killProcess(self, pid, ppid, kill):\n \"\"\"\n :type pid: List[int]\n :type ppid: List[int]\n :type kill: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def killProcess(self, pid: List[int], ppid: List[int], kill: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* killProcess(int* pid, int pidSize, int* ppid, int ppidSize, int kill, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList KillProcess(IList pid, IList ppid, int kill) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} pid\n * @param {number[]} ppid\n * @param {number} kill\n * @return {number[]}\n */\nvar killProcess = function(pid, ppid, kill) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} pid\n# @param {Integer[]} ppid\n# @param {Integer} kill\n# @return {Integer[]}\ndef kill_process(pid, ppid, kill)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func killProcess(_ pid: [Int], _ ppid: [Int], _ kill: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func killProcess(pid []int, ppid []int, kill int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def killProcess(pid: List[Int], ppid: List[Int], kill: Int): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun killProcess(pid: List, ppid: List, kill: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn kill_process(pid: Vec, ppid: Vec, kill: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $pid\n * @param Integer[] $ppid\n * @param Integer $kill\n * @return Integer[]\n */\n function killProcess($pid, $ppid, $kill) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function killProcess(pid: number[], ppid: number[], kill: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (kill-process pid ppid kill)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0582](https://leetcode-cn.com/problems/kill-process)", "[\u6740\u6389\u8fdb\u7a0b](/solution/0500-0599/0582.Kill%20Process/README.md)", "`\u6811`,`\u961f\u5217`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0582](https://leetcode.com/problems/kill-process)", "[Kill Process](/solution/0500-0599/0582.Kill%20Process/README_EN.md)", "`Tree`,`Queue`", "Medium", "\ud83d\udd12"]}, {"question_id": "0581", "frontend_question_id": "0581", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/shortest-unsorted-continuous-subarray", "url_en": "https://leetcode.com/problems/shortest-unsorted-continuous-subarray", "relative_path_cn": "/solution/0500-0599/0581.Shortest%20Unsorted%20Continuous%20Subarray/README.md", "relative_path_en": "/solution/0500-0599/0581.Shortest%20Unsorted%20Continuous%20Subarray/README_EN.md", "title_cn": "\u6700\u77ed\u65e0\u5e8f\u8fde\u7eed\u5b50\u6570\u7ec4", "title_en": "Shortest Unsorted Continuous Subarray", "question_title_slug": "shortest-unsorted-continuous-subarray", "content_en": "

    Given an integer array nums, you need to find one continuous subarray that if you only sort this subarray in ascending order, then the whole array will be sorted in ascending order.

    \n\n

    Return the shortest such subarray and output its length.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [2,6,4,8,10,9,15]\nOutput: 5\nExplanation: You need to sort [6, 4, 8, 10, 9] in ascending order to make the whole array sorted in ascending order.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,2,3,4]\nOutput: 0\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [1]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 104
    • \n\t
    • -105 <= nums[i] <= 105
    • \n
    \n\n

     

    \nFollow up: Can you solve it in O(n) time complexity?", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \uff0c\u4f60\u9700\u8981\u627e\u51fa\u4e00\u4e2a \u8fde\u7eed\u5b50\u6570\u7ec4 \uff0c\u5982\u679c\u5bf9\u8fd9\u4e2a\u5b50\u6570\u7ec4\u8fdb\u884c\u5347\u5e8f\u6392\u5e8f\uff0c\u90a3\u4e48\u6574\u4e2a\u6570\u7ec4\u90fd\u4f1a\u53d8\u4e3a\u5347\u5e8f\u6392\u5e8f\u3002

    \n\n

    \u8bf7\u4f60\u627e\u51fa\u7b26\u5408\u9898\u610f\u7684 \u6700\u77ed \u5b50\u6570\u7ec4\uff0c\u5e76\u8f93\u51fa\u5b83\u7684\u957f\u5ea6\u3002

    \n\n

    \u00a0

    \n\n
    \n
    \n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [2,6,4,8,10,9,15]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u4f60\u53ea\u9700\u8981\u5bf9 [6, 4, 8, 10, 9] \u8fdb\u884c\u5347\u5e8f\u6392\u5e8f\uff0c\u90a3\u4e48\u6574\u4e2a\u8868\u90fd\u4f1a\u53d8\u4e3a\u5347\u5e8f\u6392\u5e8f\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,3,4]\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1]\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 104
    • \n\t
    • -105 <= nums[i] <= 105
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u53ef\u4ee5\u8bbe\u8ba1\u4e00\u4e2a\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n) \u7684\u89e3\u51b3\u65b9\u6848\u5417\uff1f

    \n
    \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findUnsortedSubarray(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findUnsortedSubarray(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findUnsortedSubarray(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findUnsortedSubarray(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findUnsortedSubarray(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindUnsortedSubarray(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar findUnsortedSubarray = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef find_unsorted_subarray(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findUnsortedSubarray(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findUnsortedSubarray(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findUnsortedSubarray(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findUnsortedSubarray(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_unsorted_subarray(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function findUnsortedSubarray($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findUnsortedSubarray(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-unsorted-subarray nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0581](https://leetcode-cn.com/problems/shortest-unsorted-continuous-subarray)", "[\u6700\u77ed\u65e0\u5e8f\u8fde\u7eed\u5b50\u6570\u7ec4](/solution/0500-0599/0581.Shortest%20Unsorted%20Continuous%20Subarray/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0581](https://leetcode.com/problems/shortest-unsorted-continuous-subarray)", "[Shortest Unsorted Continuous Subarray](/solution/0500-0599/0581.Shortest%20Unsorted%20Continuous%20Subarray/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0580", "frontend_question_id": "0580", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/count-student-number-in-departments", "url_en": "https://leetcode.com/problems/count-student-number-in-departments", "relative_path_cn": "/solution/0500-0599/0580.Count%20Student%20Number%20in%20Departments/README.md", "relative_path_en": "/solution/0500-0599/0580.Count%20Student%20Number%20in%20Departments/README_EN.md", "title_cn": "\u7edf\u8ba1\u5404\u4e13\u4e1a\u5b66\u751f\u4eba\u6570", "title_en": "Count Student Number in Departments", "question_title_slug": "count-student-number-in-departments", "content_en": "

    A university uses 2 data tables, student and department, to store data about its students and the departments associated with each major.

    \r\n\r\n

    Write a query to print the respective department name and number of students majoring in each department for all departments in the department table (even ones with no current students).

    \r\n\r\n

    Sort your results by descending number of students; if two or more departments have the same number of students, then sort those departments alphabetically by department name.

    \r\n\r\n

    The student is described as follow:

    \r\n\r\n
    \r\n| Column Name  | Type      |\r\n|--------------|-----------|\r\n| student_id   | Integer   |\r\n| student_name | String    |\r\n| gender       | Character |\r\n| dept_id      | Integer   |\r\n
    \r\n\r\n

    where student_id is the student's ID number, student_name is the student's name, gender is their gender, and dept_id is the department ID associated with their declared major.

    \r\n\r\n

    And the department table is described as below:

    \r\n\r\n
    \r\n| Column Name | Type    |\r\n|-------------|---------|\r\n| dept_id     | Integer |\r\n| dept_name   | String  |\r\n
    \r\n\r\n

    where dept_id is the department's ID number and dept_name is the department name.

    \r\n\r\n

    Here is an example input:
    \r\nstudent table:

    \r\n\r\n
    \r\n| student_id | student_name | gender | dept_id |\r\n|------------|--------------|--------|---------|\r\n| 1          | Jack         | M      | 1       |\r\n| 2          | Jane         | F      | 1       |\r\n| 3          | Mark         | M      | 2       |\r\n
    \r\n\r\n

    department table:

    \r\n\r\n
    \r\n| dept_id | dept_name   |\r\n|---------|-------------|\r\n| 1       | Engineering |\r\n| 2       | Science     |\r\n| 3       | Law         |\r\n
    \r\n\r\n

    The Output should be:

    \r\n\r\n
    \r\n| dept_name   | student_number |\r\n|-------------|----------------|\r\n| Engineering | 2              |\r\n| Science     | 1              |\r\n| Law         | 0              |\r\n
    \r\n", "content_cn": "

    \u4e00\u6240\u5927\u5b66\u6709 2 \u4e2a\u6570\u636e\u8868\uff0c\u5206\u522b\u662f student \u548c department \uff0c\u8fd9\u4e24\u4e2a\u8868\u4fdd\u5b58\u7740\u6bcf\u4e2a\u4e13\u4e1a\u7684\u5b66\u751f\u6570\u636e\u548c\u9662\u7cfb\u6570\u636e\u3002

    \n\n

    \u5199\u4e00\u4e2a\u67e5\u8be2\u8bed\u53e5\uff0c\u67e5\u8be2 department \u8868\u4e2d\u6bcf\u4e2a\u4e13\u4e1a\u7684\u5b66\u751f\u4eba\u6570 \uff08\u5373\u4f7f\u6ca1\u6709\u5b66\u751f\u7684\u4e13\u4e1a\u4e5f\u9700\u5217\u51fa\uff09\u3002

    \n\n

    \u5c06\u4f60\u7684\u67e5\u8be2\u7ed3\u679c\u6309\u7167\u5b66\u751f\u4eba\u6570\u964d\u5e8f\u6392\u5217\u3002 \u5982\u679c\u6709\u4e24\u4e2a\u6216\u4e24\u4e2a\u4ee5\u4e0a\u4e13\u4e1a\u6709\u76f8\u540c\u7684\u5b66\u751f\u6570\u76ee\uff0c\u5c06\u8fd9\u4e9b\u90e8\u95e8\u6309\u7167\u90e8\u95e8\u540d\u5b57\u7684\u5b57\u5178\u5e8f\u4ece\u5c0f\u5230\u5927\u6392\u5217\u3002

    \n\n

    student \u8868\u683c\u5982\u4e0b\uff1a

    \n\n
    | Column Name  | Type      |\n|--------------|-----------|\n| student_id   | Integer   |\n| student_name | String    |\n| gender       | Character |\n| dept_id      | Integer   |\n
    \n\n

    \u5176\u4e2d\uff0c student_id \u662f\u5b66\u751f\u7684\u5b66\u53f7\uff0c student_name \u662f\u5b66\u751f\u7684\u59d3\u540d\uff0c gender \u662f\u5b66\u751f\u7684\u6027\u522b\uff0c dept_id \u662f\u5b66\u751f\u6240\u5c5e\u4e13\u4e1a\u7684\u4e13\u4e1a\u7f16\u53f7\u3002

    \n\n

    department \u8868\u683c\u5982\u4e0b\uff1a

    \n\n
    | Column Name | Type    |\n|-------------|---------|\n| dept_id     | Integer |\n| dept_name   | String  |\n
    \n\n

    dept_id \u662f\u4e13\u4e1a\u7f16\u53f7\uff0c dept_name \u662f\u4e13\u4e1a\u540d\u5b57\u3002

    \n\n

    \u8fd9\u91cc\u662f\u4e00\u4e2a\u793a\u4f8b\u8f93\u5165\uff1a
    \nstudent \u8868\u683c\uff1a

    \n\n
    | student_id | student_name | gender | dept_id |\n|------------|--------------|--------|---------|\n| 1          | Jack         | M      | 1       |\n| 2          | Jane         | F      | 1       |\n| 3          | Mark         | M      | 2       |\n
    \n\n

    department \u8868\u683c\uff1a

    \n\n
    | dept_id | dept_name   |\n|---------|-------------|\n| 1       | Engineering |\n| 2       | Science     |\n| 3       | Law         |\n
    \n\n

    \u793a\u4f8b\u8f93\u51fa\u4e3a\uff1a

    \n\n
    | dept_name   | student_number |\n|-------------|----------------|\n| Engineering | 2              |\n| Science     | 1              |\n| Law         | 0              |\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0580](https://leetcode-cn.com/problems/count-student-number-in-departments)", "[\u7edf\u8ba1\u5404\u4e13\u4e1a\u5b66\u751f\u4eba\u6570](/solution/0500-0599/0580.Count%20Student%20Number%20in%20Departments/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0580](https://leetcode.com/problems/count-student-number-in-departments)", "[Count Student Number in Departments](/solution/0500-0599/0580.Count%20Student%20Number%20in%20Departments/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "0579", "frontend_question_id": "0579", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/find-cumulative-salary-of-an-employee", "url_en": "https://leetcode.com/problems/find-cumulative-salary-of-an-employee", "relative_path_cn": "/solution/0500-0599/0579.Find%20Cumulative%20Salary%20of%20an%20Employee/README.md", "relative_path_en": "/solution/0500-0599/0579.Find%20Cumulative%20Salary%20of%20an%20Employee/README_EN.md", "title_cn": "\u67e5\u8be2\u5458\u5de5\u7684\u7d2f\u8ba1\u85aa\u6c34", "title_en": "Find Cumulative Salary of an Employee", "question_title_slug": "find-cumulative-salary-of-an-employee", "content_en": "

    The Employee table holds the salary information in a year.

    \r\n\r\n

    Write a SQL to get the cumulative sum of an employee's salary over a period of 3 months but exclude the most recent month.

    \r\n\r\n

    The result should be displayed by 'Id' ascending, and then by 'Month' descending.

    \r\n\r\n

    Example
    \r\nInput

    \r\n\r\n
    \r\n| Id | Month | Salary |\r\n|----|-------|--------|\r\n| 1  | 1     | 20     |\r\n| 2  | 1     | 20     |\r\n| 1  | 2     | 30     |\r\n| 2  | 2     | 30     |\r\n| 3  | 2     | 40     |\r\n| 1  | 3     | 40     |\r\n| 3  | 3     | 60     |\r\n| 1  | 4     | 60     |\r\n| 3  | 4     | 70     |\r\n
    \r\nOutput\r\n\r\n
    \r\n\r\n| Id | Month | Salary |\r\n|----|-------|--------|\r\n| 1  | 3     | 90     |\r\n| 1  | 2     | 50     |\r\n| 1  | 1     | 20     |\r\n| 2  | 1     | 20     |\r\n| 3  | 3     | 100    |\r\n| 3  | 2     | 40     |\r\n
    \r\n\r\n

     

    \r\nExplanation\r\n\r\n

    Employee '1' has 3 salary records for the following 3 months except the most recent month '4': salary 40 for month '3', 30 for month '2' and 20 for month '1'
    \r\nSo the cumulative sum of salary of this employee over 3 months is 90(40+30+20), 50(30+20) and 20 respectively.

    \r\n\r\n
    \r\n| Id | Month | Salary |\r\n|----|-------|--------|\r\n| 1  | 3     | 90     |\r\n| 1  | 2     | 50     |\r\n| 1  | 1     | 20     |\r\n
    \r\nEmployee '2' only has one salary record (month '1') except its most recent month '2'.\r\n\r\n
    \r\n| Id | Month | Salary |\r\n|----|-------|--------|\r\n| 2  | 1     | 20     |\r\n
    \r\n\r\n

     

    \r\nEmploy '3' has two salary records except its most recent pay month '4': month '3' with 60 and month '2' with 40. So the cumulative salary is as following.\r\n\r\n
    \r\n| Id | Month | Salary |\r\n|----|-------|--------|\r\n| 3  | 3     | 100    |\r\n| 3  | 2     | 40     |\r\n
    \r\n\r\n

     

    \r\n", "content_cn": "

    Employee \u8868\u4fdd\u5b58\u4e86\u4e00\u5e74\u5185\u7684\u85aa\u6c34\u4fe1\u606f\u3002

    \n\n

    \u8bf7\u4f60\u7f16\u5199 SQL \u8bed\u53e5\uff0c\u5bf9\u4e8e\u6bcf\u4e2a\u5458\u5de5\uff0c\u67e5\u8be2\u4ed6\u9664\u6700\u8fd1\u4e00\u4e2a\u6708\uff08\u5373\u6700\u5927\u6708\uff09\u4e4b\u5916\uff0c\u5269\u4e0b\u6bcf\u4e2a\u6708\u7684\u8fd1\u4e09\u4e2a\u6708\u7684\u7d2f\u8ba1\u85aa\u6c34\uff08\u4e0d\u8db3\u4e09\u4e2a\u6708\u4e5f\u8981\u8ba1\u7b97\uff09\u3002

    \n\n

    \u7ed3\u679c\u8bf7\u6309 Id \u5347\u5e8f\uff0c\u7136\u540e\u6309 Month \u964d\u5e8f\u663e\u793a\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a
    \n\u8f93\u5165\uff1a

    \n\n
    \n| Id | Month | Salary |\n|----|-------|--------|\n| 1  | 1     | 20     |\n| 2  | 1     | 20     |\n| 1  | 2     | 30     |\n| 2  | 2     | 30     |\n| 3  | 2     | 40     |\n| 1  | 3     | 40     |\n| 3  | 3     | 60     |\n| 1  | 4     | 60     |\n| 3  | 4     | 70     |\n
    \n\n

    \u8f93\u51fa\uff1a

    \n\n
    \n| Id | Month | Salary |\n|----|-------|--------|\n| 1  | 3     | 90     |\n| 1  | 2     | 50     |\n| 1  | 1     | 20     |\n| 2  | 1     | 20     |\n| 3  | 3     | 100    |\n| 3  | 2     | 40     |\n
    \n\n

    \u00a0

    \n\n

    \u89e3\u91ca\uff1a

    \n\n

    \u5458\u5de5 '1'\u00a0\u9664\u53bb\u6700\u8fd1\u4e00\u4e2a\u6708\uff08\u6708\u4efd '4'\uff09\uff0c\u6709\u4e09\u4e2a\u6708\u7684\u85aa\u6c34\u8bb0\u5f55\uff1a\u6708\u4efd '3'\u00a0\u85aa\u6c34\u4e3a\u00a040\uff0c\u6708\u4efd '2'\u00a0\u85aa\u6c34\u4e3a 30\uff0c\u6708\u4efd '1'\u00a0\u85aa\u6c34\u4e3a 20\u3002

    \n\n

    \u6240\u4ee5\u8fd1 3 \u4e2a\u6708\u7684\u85aa\u6c34\u7d2f\u8ba1\u5206\u522b\u4e3a\u00a0(40 + 30 + 20) =\u00a090\uff0c(30 + 20) = 50 \u548c 20\u3002

    \n\n
    \n| Id | Month | Salary |\n|----|-------|--------|\n| 1  | 3     | 90     |\n| 1  | 2     | 50     |\n| 1  | 1     | 20     |\n
    \n\n

    \u5458\u5de5 '2' \u9664\u53bb\u6700\u8fd1\u7684\u4e00\u4e2a\u6708\uff08\u6708\u4efd '2'\uff09\u7684\u8bdd\uff0c\u53ea\u6709\u6708\u4efd '1' \u8fd9\u4e00\u4e2a\u6708\u7684\u85aa\u6c34\u8bb0\u5f55\u3002

    \n\n
    \n| Id | Month | Salary |\n|----|-------|--------|\n| 2  | 1     | 20     |\n
    \n\n

    \u5458\u5de5 '3' \u9664\u53bb\u6700\u8fd1\u4e00\u4e2a\u6708\uff08\u6708\u4efd '4'\uff09\u540e\u6709\u4e24\u4e2a\u6708\uff0c\u5206\u522b\u4e3a\uff1a\u6708\u4efd '3' \u85aa\u6c34\u4e3a 60 \u548c \u6708\u4efd '2' \u85aa\u6c34\u4e3a 40\u3002\u6240\u4ee5\u5404\u6708\u7684\u7d2f\u8ba1\u60c5\u51b5\u5982\u4e0b\uff1a

    \n\n
    \n| Id | Month | Salary |\n|----|-------|--------|\n| 3  | 3     | 100    |\n| 3  | 2     | 40     |\n
    \n\n

    \u00a0

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0579](https://leetcode-cn.com/problems/find-cumulative-salary-of-an-employee)", "[\u67e5\u8be2\u5458\u5de5\u7684\u7d2f\u8ba1\u85aa\u6c34](/solution/0500-0599/0579.Find%20Cumulative%20Salary%20of%20an%20Employee/README.md)", "", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0579](https://leetcode.com/problems/find-cumulative-salary-of-an-employee)", "[Find Cumulative Salary of an Employee](/solution/0500-0599/0579.Find%20Cumulative%20Salary%20of%20an%20Employee/README_EN.md)", "", "Hard", "\ud83d\udd12"]}, {"question_id": "0578", "frontend_question_id": "0578", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/get-highest-answer-rate-question", "url_en": "https://leetcode.com/problems/get-highest-answer-rate-question", "relative_path_cn": "/solution/0500-0599/0578.Get%20Highest%20Answer%20Rate%20Question/README.md", "relative_path_en": "/solution/0500-0599/0578.Get%20Highest%20Answer%20Rate%20Question/README_EN.md", "title_cn": "\u67e5\u8be2\u56de\u7b54\u7387\u6700\u9ad8\u7684\u95ee\u9898", "title_en": "Get Highest Answer Rate Question", "question_title_slug": "get-highest-answer-rate-question", "content_en": "

    Get the highest answer rate question from a table survey_log with these columns: id, action, question_id, answer_id, q_num, timestamp.

    \n\n

    id means user id; action has these kind of values: "show", "answer", "skip"; answer_id is not null when action column is "answer", while is null for "show" and "skip"; q_num is the numeral order of the question in current session.

    \n\n

    Write a sql query to identify the question which has the highest answer rate.

    \n\n

    Example:

    \n\n
    \nInput:\n+------+-----------+--------------+------------+-----------+------------+\n| id   | action    | question_id  | answer_id  | q_num     | timestamp  |\n+------+-----------+--------------+------------+-----------+------------+\n| 5    | show      | 285          | null       | 1         | 123        |\n| 5    | answer    | 285          | 124124     | 1         | 124        |\n| 5    | show      | 369          | null       | 2         | 125        |\n| 5    | skip      | 369          | null       | 2         | 126        |\n+------+-----------+--------------+------------+-----------+------------+\nOutput:\n+-------------+\n| survey_log  |\n+-------------+\n|    285      |\n+-------------+\nExplanation:\nquestion 285 has answer rate 1/1, while question 369 has 0/1 answer rate, so output 285.\n
    \n\n

     

    \n\n

    Note: The highest answer rate meaning is: answer number's ratio in show number in the same question.

    \n", "content_cn": "

    \u4ece survey_log \u8868\u4e2d\u83b7\u5f97\u56de\u7b54\u7387\u6700\u9ad8\u7684\u95ee\u9898\uff0csurvey_log \u8868\u5305\u542b\u8fd9\u4e9b\u5217\uff1aid, action, question_id, answer_id, q_num, timestamp\u3002

    \n\n

    id \u8868\u793a\u7528\u6237 id\uff1baction \u6709\u4ee5\u4e0b\u51e0\u79cd\u503c\uff1a"show"\uff0c"answer"\uff0c"skip"\uff1b\u5f53 action \u503c\u4e3a "answer" \u65f6 answer_id \u975e\u7a7a\uff0c\u800c action \u503c\u4e3a "show" \u6216\u8005 "skip" \u65f6 answer_id \u4e3a\u7a7a\uff1bq_num \u8868\u793a\u5f53\u524d\u4f1a\u8bdd\u4e2d\u95ee\u9898\u7684\u7f16\u53f7\u3002

    \n\n

    \u8bf7\u7f16\u5199 SQL \u67e5\u8be2\u6765\u627e\u5230\u5177\u6709\u6700\u9ad8\u56de\u7b54\u7387\u7684\u95ee\u9898\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1a\n+------+-----------+--------------+------------+-----------+------------+\n| id   | action    | question_id  | answer_id  | q_num     | timestamp  |\n+------+-----------+--------------+------------+-----------+------------+\n| 5    | show      | 285          | null       | 1         | 123        |\n| 5    | answer    | 285          | 124124     | 1         | 124        |\n| 5    | show      | 369          | null       | 2         | 125        |\n| 5    | skip      | 369          | null       | 2         | 126        |\n+------+-----------+--------------+------------+-----------+------------+\n\u8f93\u51fa\uff1a\n+-------------+\n| survey_log  |\n+-------------+\n|    285      |\n+-------------+\n\u89e3\u91ca\uff1a\n\u95ee\u9898 285 \u7684\u56de\u7b54\u7387\u4e3a 1/1\uff0c\u800c\u95ee\u9898 369 \u56de\u7b54\u7387\u4e3a 0/1\uff0c\u56e0\u6b64\u8f93\u51fa 285 \u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a\u56de\u7b54\u7387\u6700\u9ad8\u7684\u542b\u4e49\u662f\uff1a\u540c\u4e00\u95ee\u9898\u7f16\u53f7\u4e2d\u56de\u7b54\u6570\u5360\u663e\u793a\u6570\u7684\u6bd4\u4f8b\u6700\u9ad8\u3002

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0578](https://leetcode-cn.com/problems/get-highest-answer-rate-question)", "[\u67e5\u8be2\u56de\u7b54\u7387\u6700\u9ad8\u7684\u95ee\u9898](/solution/0500-0599/0578.Get%20Highest%20Answer%20Rate%20Question/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0578](https://leetcode.com/problems/get-highest-answer-rate-question)", "[Get Highest Answer Rate Question](/solution/0500-0599/0578.Get%20Highest%20Answer%20Rate%20Question/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "0577", "frontend_question_id": "0577", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/employee-bonus", "url_en": "https://leetcode.com/problems/employee-bonus", "relative_path_cn": "/solution/0500-0599/0577.Employee%20Bonus/README.md", "relative_path_en": "/solution/0500-0599/0577.Employee%20Bonus/README_EN.md", "title_cn": "\u5458\u5de5\u5956\u91d1", "title_en": "Employee Bonus", "question_title_slug": "employee-bonus", "content_en": "

    Select all employee's name and bonus whose bonus is < 1000.

    \r\n\r\n

    Table:Employee

    \r\n\r\n
    \r\n+-------+--------+-----------+--------+\r\n| empId |  name  | supervisor| salary |\r\n+-------+--------+-----------+--------+\r\n|   1   | John   |  3        | 1000   |\r\n|   2   | Dan    |  3        | 2000   |\r\n|   3   | Brad   |  null     | 4000   |\r\n|   4   | Thomas |  3        | 4000   |\r\n+-------+--------+-----------+--------+\r\nempId is the primary key column for this table.\r\n
    \r\n\r\n

    Table: Bonus

    \r\n\r\n
    \r\n+-------+-------+\r\n| empId | bonus |\r\n+-------+-------+\r\n| 2     | 500   |\r\n| 4     | 2000  |\r\n+-------+-------+\r\nempId is the primary key column for this table.\r\n
    \r\n\r\n

    Example ouput:

    \r\n\r\n
    \r\n+-------+-------+\r\n| name  | bonus |\r\n+-------+-------+\r\n| John  | null  |\r\n| Dan   | 500   |\r\n| Brad  | null  |\r\n+-------+-------+\r\n
    \r\n", "content_cn": "

    \u9009\u51fa\u6240\u6709 bonus < 1000 \u7684\u5458\u5de5\u7684 name \u53ca\u5176 bonus\u3002

    \n\n

    Employee \u8868\u5355

    \n\n
    +-------+--------+-----------+--------+\n| empId |  name  | supervisor| salary |\n+-------+--------+-----------+--------+\n|   1   | John   |  3        | 1000   |\n|   2   | Dan    |  3        | 2000   |\n|   3   | Brad   |  null     | 4000   |\n|   4   | Thomas |  3        | 4000   |\n+-------+--------+-----------+--------+\nempId \u662f\u8fd9\u5f20\u8868\u5355\u7684\u4e3b\u5173\u952e\u5b57\n
    \n\n

    Bonus \u8868\u5355

    \n\n
    +-------+-------+\n| empId | bonus |\n+-------+-------+\n| 2     | 500   |\n| 4     | 2000  |\n+-------+-------+\nempId \u662f\u8fd9\u5f20\u8868\u5355\u7684\u4e3b\u5173\u952e\u5b57\n
    \n\n

    \u8f93\u51fa\u793a\u4f8b\uff1a

    \n\n
    +-------+-------+\n| name  | bonus |\n+-------+-------+\n| John  | null  |\n| Dan   | 500   |\n| Brad  | null  |\n+-------+-------+\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0577](https://leetcode-cn.com/problems/employee-bonus)", "[\u5458\u5de5\u5956\u91d1](/solution/0500-0599/0577.Employee%20Bonus/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0577](https://leetcode.com/problems/employee-bonus)", "[Employee Bonus](/solution/0500-0599/0577.Employee%20Bonus/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "0576", "frontend_question_id": "0576", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/out-of-boundary-paths", "url_en": "https://leetcode.com/problems/out-of-boundary-paths", "relative_path_cn": "/solution/0500-0599/0576.Out%20of%20Boundary%20Paths/README.md", "relative_path_en": "/solution/0500-0599/0576.Out%20of%20Boundary%20Paths/README_EN.md", "title_cn": "\u51fa\u754c\u7684\u8def\u5f84\u6570", "title_en": "Out of Boundary Paths", "question_title_slug": "out-of-boundary-paths", "content_en": "

    There is an m x n grid with a ball. The ball is initially at the position [startRow, startColumn]. You are allowed to move the ball to one of the four adjacent four cells in the grid (possibly out of the grid crossing the grid boundary). You can apply at most maxMove moves to the ball.

    \n\n

    Given the five integers m, n, maxMove, startRow, startColumn, return the number of paths to move the ball out of the grid boundary. Since the answer can be very large, return it modulo 109 + 7.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: m = 2, n = 2, maxMove = 2, startRow = 0, startColumn = 0\nOutput: 6\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: m = 1, n = 3, maxMove = 3, startRow = 0, startColumn = 1\nOutput: 12\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= m, n <= 50
    • \n\t
    • 0 <= maxMove <= 50
    • \n\t
    • 0 <= startRow <= m
    • \n\t
    • 0 <= startColumn <= n
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a m × n \u7684\u7f51\u683c\u548c\u4e00\u4e2a\u7403\u3002\u7403\u7684\u8d77\u59cb\u5750\u6807\u4e3a (i,j) \uff0c\u4f60\u53ef\u4ee5\u5c06\u7403\u79fb\u5230\u76f8\u90bb\u7684\u5355\u5143\u683c\u5185\uff0c\u6216\u8005\u5f80\u4e0a\u3001\u4e0b\u3001\u5de6\u3001\u53f3\u56db\u4e2a\u65b9\u5411\u4e0a\u79fb\u52a8\u4f7f\u7403\u7a7f\u8fc7\u7f51\u683c\u8fb9\u754c\u3002\u4f46\u662f\uff0c\u4f60\u6700\u591a\u53ef\u4ee5\u79fb\u52a8 \u6b21\u3002\u627e\u51fa\u53ef\u4ee5\u5c06\u7403\u79fb\u51fa\u8fb9\u754c\u7684\u8def\u5f84\u6570\u91cf\u3002\u7b54\u6848\u53ef\u80fd\u975e\u5e38\u5927\uff0c\u8fd4\u56de \u7ed3\u679c mod 109 + 7 \u7684\u503c\u3002

    \r\n\r\n

     

    \r\n\r\n

    \u793a\u4f8b 1\uff1a

    \r\n\r\n
    \u8f93\u5165: m = 2, n = 2, N = 2, i = 0, j = 0\r\n\u8f93\u51fa: 6\r\n\u89e3\u91ca:\r\n\r\n
    \r\n\r\n

    \u793a\u4f8b 2\uff1a

    \r\n\r\n
    \u8f93\u5165: m = 1, n = 3, N = 3, i = 0, j = 1\r\n\u8f93\u51fa: 12\r\n\u89e3\u91ca:\r\n\r\n
    \r\n\r\n

     

    \r\n\r\n

    \u8bf4\u660e:

    \r\n\r\n
      \r\n\t
    1. \u7403\u4e00\u65e6\u51fa\u754c\uff0c\u5c31\u4e0d\u80fd\u518d\u88ab\u79fb\u52a8\u56de\u7f51\u683c\u5185\u3002
    2. \r\n\t
    3. \u7f51\u683c\u7684\u957f\u5ea6\u548c\u9ad8\u5ea6\u5728 [1,50] \u7684\u8303\u56f4\u5185\u3002
    4. \r\n\t
    5. N \u5728 [0,50] \u7684\u8303\u56f4\u5185\u3002
    6. \r\n
    ", "tags_en": ["Depth-first Search", "Dynamic Programming"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findPaths(int m, int n, int maxMove, int startRow, int startColumn) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findPaths(int m, int n, int maxMove, int startRow, int startColumn) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findPaths(self, m, n, maxMove, startRow, startColumn):\n \"\"\"\n :type m: int\n :type n: int\n :type maxMove: int\n :type startRow: int\n :type startColumn: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findPaths(self, m: int, n: int, maxMove: int, startRow: int, startColumn: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findPaths(int m, int n, int maxMove, int startRow, int startColumn){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindPaths(int m, int n, int maxMove, int startRow, int startColumn) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} m\n * @param {number} n\n * @param {number} maxMove\n * @param {number} startRow\n * @param {number} startColumn\n * @return {number}\n */\nvar findPaths = function(m, n, maxMove, startRow, startColumn) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} m\n# @param {Integer} n\n# @param {Integer} max_move\n# @param {Integer} start_row\n# @param {Integer} start_column\n# @return {Integer}\ndef find_paths(m, n, max_move, start_row, start_column)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findPaths(_ m: Int, _ n: Int, _ maxMove: Int, _ startRow: Int, _ startColumn: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findPaths(m int, n int, maxMove int, startRow int, startColumn int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findPaths(m: Int, n: Int, maxMove: Int, startRow: Int, startColumn: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findPaths(m: Int, n: Int, maxMove: Int, startRow: Int, startColumn: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_paths(m: i32, n: i32, max_move: i32, start_row: i32, start_column: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $m\n * @param Integer $n\n * @param Integer $maxMove\n * @param Integer $startRow\n * @param Integer $startColumn\n * @return Integer\n */\n function findPaths($m, $n, $maxMove, $startRow, $startColumn) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findPaths(m: number, n: number, maxMove: number, startRow: number, startColumn: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-paths m n maxMove startRow startColumn)\n (-> exact-integer? exact-integer? exact-integer? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0576](https://leetcode-cn.com/problems/out-of-boundary-paths)", "[\u51fa\u754c\u7684\u8def\u5f84\u6570](/solution/0500-0599/0576.Out%20of%20Boundary%20Paths/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0576](https://leetcode.com/problems/out-of-boundary-paths)", "[Out of Boundary Paths](/solution/0500-0599/0576.Out%20of%20Boundary%20Paths/README_EN.md)", "`Depth-first Search`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0575", "frontend_question_id": "0575", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/distribute-candies", "url_en": "https://leetcode.com/problems/distribute-candies", "relative_path_cn": "/solution/0500-0599/0575.Distribute%20Candies/README.md", "relative_path_en": "/solution/0500-0599/0575.Distribute%20Candies/README_EN.md", "title_cn": "\u5206\u7cd6\u679c", "title_en": "Distribute Candies", "question_title_slug": "distribute-candies", "content_en": "

    Alice has n candies, where the ith candy is of type candyType[i]. Alice noticed that she started to gain weight, so she visited a doctor.

    \n\n

    The doctor advised Alice to only eat n / 2 of the candies she has (n is always even). Alice likes her candies very much, and she wants to eat the maximum number of different types of candies while still following the doctor's advice.

    \n\n

    Given the integer array candyType of length n, return the maximum number of different types of candies she can eat if she only eats n / 2 of them.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: candyType = [1,1,2,2,3,3]\nOutput: 3\nExplanation: Alice can only eat 6 / 2 = 3 candies. Since there are only 3 types, she can eat one of each type.\n
    \n\n

    Example 2:

    \n\n
    \nInput: candyType = [1,1,2,3]\nOutput: 2\nExplanation: Alice can only eat 4 / 2 = 2 candies. Whether she eats types [1,2], [1,3], or [2,3], she still can only eat 2 different types.\n
    \n\n

    Example 3:

    \n\n
    \nInput: candyType = [6,6,6,6]\nOutput: 1\nExplanation: Alice can only eat 4 / 2 = 2 candies. Even though she can eat 2 candies, she only has 1 type.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == candyType.length
    • \n\t
    • 2 <= n <= 104
    • \n\t
    • n is even.
    • \n\t
    • -105 <= candyType[i] <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5076\u6570\u957f\u5ea6\u7684\u6570\u7ec4\uff0c\u5176\u4e2d\u4e0d\u540c\u7684\u6570\u5b57\u4ee3\u8868\u7740\u4e0d\u540c\u79cd\u7c7b\u7684\u7cd6\u679c\uff0c\u6bcf\u4e00\u4e2a\u6570\u5b57\u4ee3\u8868\u4e00\u4e2a\u7cd6\u679c\u3002\u4f60\u9700\u8981\u628a\u8fd9\u4e9b\u7cd6\u679c\u5e73\u5747\u5206\u7ed9\u4e00\u4e2a\u5f1f\u5f1f\u548c\u4e00\u4e2a\u59b9\u59b9\u3002\u8fd4\u56de\u59b9\u59b9\u53ef\u4ee5\u83b7\u5f97\u7684\u6700\u5927\u7cd6\u679c\u7684\u79cd\u7c7b\u6570\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: candies = [1,1,2,2,3,3]\n\u8f93\u51fa: 3\n\u89e3\u6790: \u4e00\u5171\u6709\u4e09\u79cd\u79cd\u7c7b\u7684\u7cd6\u679c\uff0c\u6bcf\u4e00\u79cd\u90fd\u6709\u4e24\u4e2a\u3002\n     \u6700\u4f18\u5206\u914d\u65b9\u6848\uff1a\u59b9\u59b9\u83b7\u5f97[1,2,3],\u5f1f\u5f1f\u4e5f\u83b7\u5f97[1,2,3]\u3002\u8fd9\u6837\u4f7f\u59b9\u59b9\u83b7\u5f97\u7cd6\u679c\u7684\u79cd\u7c7b\u6570\u6700\u591a\u3002\n
    \n\n

    \u793a\u4f8b 2 :

    \n\n
    \n\u8f93\u5165: candies = [1,1,2,3]\n\u8f93\u51fa: 2\n\u89e3\u6790: \u59b9\u59b9\u83b7\u5f97\u7cd6\u679c[2,3],\u5f1f\u5f1f\u83b7\u5f97\u7cd6\u679c[1,1]\uff0c\u59b9\u59b9\u6709\u4e24\u79cd\u4e0d\u540c\u7684\u7cd6\u679c\uff0c\u5f1f\u5f1f\u53ea\u6709\u4e00\u79cd\u3002\u8fd9\u6837\u4f7f\u5f97\u59b9\u59b9\u53ef\u4ee5\u83b7\u5f97\u7684\u7cd6\u679c\u79cd\u7c7b\u6570\u6700\u591a\u3002\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u6570\u7ec4\u7684\u957f\u5ea6\u4e3a[2, 10,000]\uff0c\u5e76\u4e14\u786e\u5b9a\u4e3a\u5076\u6570\u3002
    2. \n\t
    3. \u6570\u7ec4\u4e2d\u6570\u5b57\u7684\u5927\u5c0f\u5728\u8303\u56f4[-100,000, 100,000]\u5185\u3002\n\t
        \n\t
      \n\t
    4. \n
    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int distributeCandies(vector& candyType) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int distributeCandies(int[] candyType) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def distributeCandies(self, candyType):\n \"\"\"\n :type candyType: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def distributeCandies(self, candyType: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint distributeCandies(int* candyType, int candyTypeSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int DistributeCandies(int[] candyType) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} candyType\n * @return {number}\n */\nvar distributeCandies = function(candyType) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} candy_type\n# @return {Integer}\ndef distribute_candies(candy_type)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func distributeCandies(_ candyType: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func distributeCandies(candyType []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def distributeCandies(candyType: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun distributeCandies(candyType: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn distribute_candies(candy_type: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $candyType\n * @return Integer\n */\n function distributeCandies($candyType) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function distributeCandies(candyType: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (distribute-candies candyType)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0575](https://leetcode-cn.com/problems/distribute-candies)", "[\u5206\u7cd6\u679c](/solution/0500-0599/0575.Distribute%20Candies/README.md)", "`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0575](https://leetcode.com/problems/distribute-candies)", "[Distribute Candies](/solution/0500-0599/0575.Distribute%20Candies/README_EN.md)", "`Hash Table`", "Easy", ""]}, {"question_id": "0574", "frontend_question_id": "0574", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/winning-candidate", "url_en": "https://leetcode.com/problems/winning-candidate", "relative_path_cn": "/solution/0500-0599/0574.Winning%20Candidate/README.md", "relative_path_en": "/solution/0500-0599/0574.Winning%20Candidate/README_EN.md", "title_cn": "\u5f53\u9009\u8005", "title_en": "Winning Candidate", "question_title_slug": "winning-candidate", "content_en": "

    Table: Candidate

    \n\n
    \n+-----+---------+\n| id  | Name    |\n+-----+---------+\n| 1   | A       |\n| 2   | B       |\n| 3   | C       |\n| 4   | D       |\n| 5   | E       |\n+-----+---------+  \n
    \n\n

    Table: Vote

    \n\n
    \n+-----+--------------+\n| id  | CandidateId  |\n+-----+--------------+\n| 1   |     2        |\n| 2   |     4        |\n| 3   |     3        |\n| 4   |     2        |\n| 5   |     5        |\n+-----+--------------+\nid is the auto-increment primary key,\nCandidateId is the id appeared in Candidate table.\n
    \n\n

    Write a sql to find the name of the winning candidate, the above example will return the winner B.

    \n\n
    \n+------+\n| Name |\n+------+\n| B    |\n+------+\n
    \n\n

    Notes:

    \n\n
      \n\t
    1. You may assume there is no tie, in other words there will be only one winning candidate.
    2. \n
    \n\n

     

    \n", "content_cn": "

    \u8868: Candidate

    \n\n
    +-----+---------+\n| id  | Name    |\n+-----+---------+\n| 1   | A       |\n| 2   | B       |\n| 3   | C       |\n| 4   | D       |\n| 5   | E       |\n+-----+---------+  \n
    \n\n

    \u8868: Vote

    \n\n
    +-----+--------------+\n| id  | CandidateId  |\n+-----+--------------+\n| 1   |     2        |\n| 2   |     4        |\n| 3   |     3        |\n| 4   |     2        |\n| 5   |     5        |\n+-----+--------------+\nid \u662f\u81ea\u52a8\u9012\u589e\u7684\u4e3b\u952e\uff0c\nCandidateId \u662f Candidate \u8868\u4e2d\u7684 id.\n
    \n\n

    \u8bf7\u7f16\u5199 sql \u8bed\u53e5\u6765\u627e\u5230\u5f53\u9009\u8005\u7684\u540d\u5b57\uff0c\u4e0a\u9762\u7684\u4f8b\u5b50\u5c06\u8fd4\u56de\u5f53\u9009\u8005 B.

    \n\n
    +------+\n| Name |\n+------+\n| B    |\n+------+\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u4f60\u53ef\u4ee5\u5047\u8bbe\u6ca1\u6709\u5e73\u5c40\uff0c\u6362\u8a00\u4e4b\uff0c\u6700\u591a\u53ea\u6709\u4e00\u4f4d\u5f53\u9009\u8005\u3002
    2. \n
    \n\n

     

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0574](https://leetcode-cn.com/problems/winning-candidate)", "[\u5f53\u9009\u8005](/solution/0500-0599/0574.Winning%20Candidate/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0574](https://leetcode.com/problems/winning-candidate)", "[Winning Candidate](/solution/0500-0599/0574.Winning%20Candidate/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "0573", "frontend_question_id": "0573", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/squirrel-simulation", "url_en": "https://leetcode.com/problems/squirrel-simulation", "relative_path_cn": "/solution/0500-0599/0573.Squirrel%20Simulation/README.md", "relative_path_en": "/solution/0500-0599/0573.Squirrel%20Simulation/README_EN.md", "title_cn": "\u677e\u9f20\u6a21\u62df", "title_en": "Squirrel Simulation", "question_title_slug": "squirrel-simulation", "content_en": "

    You are given two integers height and width representing a garden of size height x width. You are also given:

    \n\n
      \n\t
    • an array tree where tree = [treer, treec] is the position of the tree in the garden,
    • \n\t
    • an array squirrel where squirrel = [squirrelr, squirrelc] is the position of the squirrel in the garden,
    • \n\t
    • and an array nuts where nuts[i] = [nutir, nutic] is the position of the ith nut in the garden.
    • \n
    \n\n

    The squirrel can only take at most one nut at one time and can move in four directions: up, down, left, and right, to the adjacent cell.

    \n\n

    Return the minimal distance for the squirrel to collect all the nuts and put them under the tree one by one.

    \n\n

    The distance is the number of moves.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: height = 5, width = 7, tree = [2,2], squirrel = [4,4], nuts = [[3,0], [2,5]]\nOutput: 12\nExplanation: The squirrel should go to the nut at [2, 5] first to achieve a minimal distance.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: height = 1, width = 3, tree = [0,1], squirrel = [0,0], nuts = [[0,2]]\nOutput: 3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= height, width <= 100
    • \n\t
    • tree.length == 2
    • \n\t
    • squirrel.length == 2
    • \n\t
    • 1 <= nuts.length <= 5000
    • \n\t
    • nuts[i].length == 2
    • \n\t
    • 0 <= treer, squirrelr, nutir <= height
    • \n\t
    • 0 <= treec, squirrelc, nutic <= width
    • \n
    \n", "content_cn": "

    \u73b0\u5728\u6709\u4e00\u68f5\u6811\uff0c\u4e00\u53ea\u677e\u9f20\u548c\u4e00\u4e9b\u575a\u679c\u3002\u4f4d\u7f6e\u7531\u4e8c\u7ef4\u7f51\u683c\u7684\u5355\u5143\u683c\u8868\u793a\u3002\u4f60\u7684\u76ee\u6807\u662f\u627e\u5230\u677e\u9f20\u6536\u96c6\u6240\u6709\u575a\u679c\u7684\u6700\u5c0f\u8def\u7a0b\uff0c\u4e14\u575a\u679c\u662f\u4e00\u9897\u63a5\u4e00\u9897\u5730\u88ab\u653e\u5728\u6811\u4e0b\u3002\u677e\u9f20\u4e00\u6b21\u6700\u591a\u53ea\u80fd\u643a\u5e26\u4e00\u9897\u575a\u679c\uff0c\u677e\u9f20\u53ef\u4ee5\u5411\u4e0a\uff0c\u5411\u4e0b\uff0c\u5411\u5de6\u548c\u5411\u53f3\u56db\u4e2a\u65b9\u5411\u79fb\u52a8\u5230\u76f8\u90bb\u7684\u5355\u5143\u683c\u3002\u79fb\u52a8\u6b21\u6570\u8868\u793a\u8def\u7a0b\u3002

    \n\n

    \u8f93\u5165 1:

    \n\n
    \u8f93\u5165: \n\u9ad8\u5ea6 : 5\n\u5bbd\u5ea6 : 7\n\u6811\u7684\u4f4d\u7f6e : [2,2]\n\u677e\u9f20 : [4,4]\n\u575a\u679c : [[3,0], [2,5]]\n\u8f93\u51fa: 12\n\u89e3\u91ca:\n\u200b\u200b\u200b\u200b\u200b\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u6240\u6709\u7ed9\u5b9a\u7684\u4f4d\u7f6e\u4e0d\u4f1a\u91cd\u53e0\u3002
    2. \n\t
    3. \u677e\u9f20\u4e00\u6b21\u6700\u591a\u53ea\u80fd\u643a\u5e26\u4e00\u9897\u575a\u679c\u3002
    4. \n\t
    5. \u7ed9\u5b9a\u7684\u575a\u679c\u4f4d\u7f6e\u6ca1\u6709\u987a\u5e8f\u3002
    6. \n\t
    7. \u9ad8\u5ea6\u548c\u5bbd\u5ea6\u662f\u6b63\u6574\u6570\u3002 3 <= \u9ad8\u5ea6 * \u5bbd\u5ea6 <= 10,000\u3002
    8. \n\t
    9. \u7ed9\u5b9a\u7684\u7f51\u683c\u81f3\u5c11\u5305\u542b\u4e00\u9897\u575a\u679c\uff0c\u552f\u4e00\u7684\u4e00\u68f5\u6811\u548c\u4e00\u53ea\u677e\u9f20\u3002
    10. \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minDistance(int height, int width, vector& tree, vector& squirrel, vector>& nuts) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minDistance(int height, int width, int[] tree, int[] squirrel, int[][] nuts) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minDistance(self, height, width, tree, squirrel, nuts):\n \"\"\"\n :type height: int\n :type width: int\n :type tree: List[int]\n :type squirrel: List[int]\n :type nuts: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minDistance(self, height: int, width: int, tree: List[int], squirrel: List[int], nuts: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minDistance(int height, int width, int* tree, int treeSize, int* squirrel, int squirrelSize, int** nuts, int nutsSize, int* nutsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinDistance(int height, int width, int[] tree, int[] squirrel, int[][] nuts) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} height\n * @param {number} width\n * @param {number[]} tree\n * @param {number[]} squirrel\n * @param {number[][]} nuts\n * @return {number}\n */\nvar minDistance = function(height, width, tree, squirrel, nuts) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} height\n# @param {Integer} width\n# @param {Integer[]} tree\n# @param {Integer[]} squirrel\n# @param {Integer[][]} nuts\n# @return {Integer}\ndef min_distance(height, width, tree, squirrel, nuts)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minDistance(_ height: Int, _ width: Int, _ tree: [Int], _ squirrel: [Int], _ nuts: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minDistance(height int, width int, tree []int, squirrel []int, nuts [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minDistance(height: Int, width: Int, tree: Array[Int], squirrel: Array[Int], nuts: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minDistance(height: Int, width: Int, tree: IntArray, squirrel: IntArray, nuts: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_distance(height: i32, width: i32, tree: Vec, squirrel: Vec, nuts: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $height\n * @param Integer $width\n * @param Integer[] $tree\n * @param Integer[] $squirrel\n * @param Integer[][] $nuts\n * @return Integer\n */\n function minDistance($height, $width, $tree, $squirrel, $nuts) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minDistance(height: number, width: number, tree: number[], squirrel: number[], nuts: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-distance height width tree squirrel nuts)\n (-> exact-integer? exact-integer? (listof exact-integer?) (listof exact-integer?) (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0573](https://leetcode-cn.com/problems/squirrel-simulation)", "[\u677e\u9f20\u6a21\u62df](/solution/0500-0599/0573.Squirrel%20Simulation/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0573](https://leetcode.com/problems/squirrel-simulation)", "[Squirrel Simulation](/solution/0500-0599/0573.Squirrel%20Simulation/README_EN.md)", "`Math`", "Medium", "\ud83d\udd12"]}, {"question_id": "0572", "frontend_question_id": "0572", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/subtree-of-another-tree", "url_en": "https://leetcode.com/problems/subtree-of-another-tree", "relative_path_cn": "/solution/0500-0599/0572.Subtree%20of%20Another%20Tree/README.md", "relative_path_en": "/solution/0500-0599/0572.Subtree%20of%20Another%20Tree/README_EN.md", "title_cn": "\u53e6\u4e00\u4e2a\u6811\u7684\u5b50\u6811", "title_en": "Subtree of Another Tree", "question_title_slug": "subtree-of-another-tree", "content_en": "

    Given the roots of two binary trees root and subRoot, return true if there is a subtree of root with the same structure and node values of subRoot and false otherwise.

    \n\n

    A subtree of a binary tree tree is a tree that consists of a node in tree and all of this node's descendants. The tree tree could also be considered as a subtree of itself.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [3,4,5,1,2], subRoot = [4,1,2]\nOutput: true\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [3,4,5,1,2,null,null,null,null,0], subRoot = [4,1,2]\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the root tree is in the range [1, 2000].
    • \n\t
    • The number of nodes in the subRoot tree is in the range [1, 1000].
    • \n\t
    • -104 <= root.val <= 104
    • \n\t
    • -104 <= subRoot.val <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u975e\u7a7a\u4e8c\u53c9\u6811 s \u548c t\uff0c\u68c0\u9a8c s \u4e2d\u662f\u5426\u5305\u542b\u548c t \u5177\u6709\u76f8\u540c\u7ed3\u6784\u548c\u8282\u70b9\u503c\u7684\u5b50\u6811\u3002s \u7684\u4e00\u4e2a\u5b50\u6811\u5305\u62ec s \u7684\u4e00\u4e2a\u8282\u70b9\u548c\u8fd9\u4e2a\u8282\u70b9\u7684\u6240\u6709\u5b50\u5b59\u3002s \u4e5f\u53ef\u4ee5\u770b\u505a\u5b83\u81ea\u8eab\u7684\u4e00\u68f5\u5b50\u6811\u3002

    \n\n

    \u793a\u4f8b 1:
    \n\u7ed9\u5b9a\u7684\u6811 s:

    \n\n
    \n     3\n    / \\\n   4   5\n  / \\\n 1   2\n
    \n\n

    \u7ed9\u5b9a\u7684\u6811 t\uff1a

    \n\n
    \n   4 \n  / \\\n 1   2\n
    \n\n

    \u8fd4\u56de true\uff0c\u56e0\u4e3a t \u4e0e s \u7684\u4e00\u4e2a\u5b50\u6811\u62e5\u6709\u76f8\u540c\u7684\u7ed3\u6784\u548c\u8282\u70b9\u503c\u3002

    \n\n

    \u793a\u4f8b 2:
    \n\u7ed9\u5b9a\u7684\u6811 s\uff1a

    \n\n
    \n     3\n    / \\\n   4   5\n  / \\\n 1   2\n    /\n   0\n
    \n\n

    \u7ed9\u5b9a\u7684\u6811 t\uff1a

    \n\n
    \n   4\n  / \\\n 1   2\n
    \n\n

    \u8fd4\u56de false\u3002

    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n bool isSubtree(TreeNode* root, TreeNode* subRoot) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public boolean isSubtree(TreeNode root, TreeNode subRoot) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def isSubtree(self, root, subRoot):\n \"\"\"\n :type root: TreeNode\n :type subRoot: TreeNode\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def isSubtree(self, root: TreeNode, subRoot: TreeNode) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nbool isSubtree(struct TreeNode* root, struct TreeNode* subRoot){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public bool IsSubtree(TreeNode root, TreeNode subRoot) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {TreeNode} subRoot\n * @return {boolean}\n */\nvar isSubtree = function(root, subRoot) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @param {TreeNode} sub_root\n# @return {Boolean}\ndef is_subtree(root, sub_root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func isSubtree(_ root: TreeNode?, _ subRoot: TreeNode?) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc isSubtree(root *TreeNode, subRoot *TreeNode) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def isSubtree(root: TreeNode, subRoot: TreeNode): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun isSubtree(root: TreeNode?, subRoot: TreeNode?): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn is_subtree(root: Option>>, sub_root: Option>>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param TreeNode $subRoot\n * @return Boolean\n */\n function isSubtree($root, $subRoot) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction isSubtree(root: TreeNode | null, subRoot: TreeNode | null): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (is-subtree root subRoot)\n (-> (or/c tree-node? #f) (or/c tree-node? #f) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0572](https://leetcode-cn.com/problems/subtree-of-another-tree)", "[\u53e6\u4e00\u4e2a\u6811\u7684\u5b50\u6811](/solution/0500-0599/0572.Subtree%20of%20Another%20Tree/README.md)", "`\u6811`", "\u7b80\u5355", ""], "md_table_row_en": ["[0572](https://leetcode.com/problems/subtree-of-another-tree)", "[Subtree of Another Tree](/solution/0500-0599/0572.Subtree%20of%20Another%20Tree/README_EN.md)", "`Tree`", "Easy", ""]}, {"question_id": "0571", "frontend_question_id": "0571", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/find-median-given-frequency-of-numbers", "url_en": "https://leetcode.com/problems/find-median-given-frequency-of-numbers", "relative_path_cn": "/solution/0500-0599/0571.Find%20Median%20Given%20Frequency%20of%20Numbers/README.md", "relative_path_en": "/solution/0500-0599/0571.Find%20Median%20Given%20Frequency%20of%20Numbers/README_EN.md", "title_cn": "\u7ed9\u5b9a\u6570\u5b57\u7684\u9891\u7387\u67e5\u8be2\u4e2d\u4f4d\u6570", "title_en": "Find Median Given Frequency of Numbers", "question_title_slug": "find-median-given-frequency-of-numbers", "content_en": "

    The Numbers table keeps the value of number and its frequency.

    \r\n\r\n
    \r\n+----------+-------------+\r\n|  Number  |  Frequency  |\r\n+----------+-------------|\r\n|  0       |  7          |\r\n|  1       |  1          |\r\n|  2       |  3          |\r\n|  3       |  1          |\r\n+----------+-------------+\r\n
    \r\n\r\n

    In this table, the numbers are 0, 0, 0, 0, 0, 0, 0, 1, 2, 2, 2, 3, so the median is (0 + 0) / 2 = 0.

    \r\n\r\n
    \r\n+--------+\r\n| median |\r\n+--------|\r\n| 0.0000 |\r\n+--------+\r\n
    \r\n\r\n

    Write a query to find the median of all numbers and name the result as median.

    \r\n", "content_cn": "

    Numbers \u8868\u4fdd\u5b58\u6570\u5b57\u7684\u503c\u53ca\u5176\u9891\u7387\u3002

    \n\n
    +----------+-------------+\n|  Number  |  Frequency  |\n+----------+-------------|\n|  0       |  7          |\n|  1       |  1          |\n|  2       |  3          |\n|  3       |  1          |\n+----------+-------------+\n
    \n\n

    \u5728\u6b64\u8868\u4e2d\uff0c\u6570\u5b57\u4e3a 0, 0, 0, 0, 0, 0, 0, 1, 2, 2, 2, 3\uff0c\u6240\u4ee5\u4e2d\u4f4d\u6570\u662f (0 + 0) / 2 = 0\u3002

    \n\n
    +--------+\n| median |\n+--------|\n| 0.0000 |\n+--------+\n
    \n\n

    \u8bf7\u7f16\u5199\u4e00\u4e2a\u67e5\u8be2\u6765\u67e5\u627e\u6240\u6709\u6570\u5b57\u7684\u4e2d\u4f4d\u6570\u5e76\u5c06\u7ed3\u679c\u547d\u540d\u4e3a median \u3002

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0571](https://leetcode-cn.com/problems/find-median-given-frequency-of-numbers)", "[\u7ed9\u5b9a\u6570\u5b57\u7684\u9891\u7387\u67e5\u8be2\u4e2d\u4f4d\u6570](/solution/0500-0599/0571.Find%20Median%20Given%20Frequency%20of%20Numbers/README.md)", "", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0571](https://leetcode.com/problems/find-median-given-frequency-of-numbers)", "[Find Median Given Frequency of Numbers](/solution/0500-0599/0571.Find%20Median%20Given%20Frequency%20of%20Numbers/README_EN.md)", "", "Hard", "\ud83d\udd12"]}, {"question_id": "0570", "frontend_question_id": "0570", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/managers-with-at-least-5-direct-reports", "url_en": "https://leetcode.com/problems/managers-with-at-least-5-direct-reports", "relative_path_cn": "/solution/0500-0599/0570.Managers%20with%20at%20Least%205%20Direct%20Reports/README.md", "relative_path_en": "/solution/0500-0599/0570.Managers%20with%20at%20Least%205%20Direct%20Reports/README_EN.md", "title_cn": "\u81f3\u5c11\u67095\u540d\u76f4\u63a5\u4e0b\u5c5e\u7684\u7ecf\u7406", "title_en": "Managers with at Least 5 Direct Reports", "question_title_slug": "managers-with-at-least-5-direct-reports", "content_en": "

    The Employee table holds all employees including their managers. Every employee has an Id, and there is also a column for the manager Id.

    \r\n\r\n
    \r\n+------+----------+-----------+----------+\r\n|Id    |Name \t  |Department |ManagerId |\r\n+------+----------+-----------+----------+\r\n|101   |John \t  |A \t      |null      |\r\n|102   |Dan \t  |A \t      |101       |\r\n|103   |James \t  |A \t      |101       |\r\n|104   |Amy \t  |A \t      |101       |\r\n|105   |Anne \t  |A \t      |101       |\r\n|106   |Ron \t  |B \t      |101       |\r\n+------+----------+-----------+----------+\r\n
    \r\n\r\n

    Given the Employee table, write a SQL query that finds out managers with at least 5 direct report. For the above table, your SQL query should return:

    \r\n\r\n
    \r\n+-------+\r\n| Name  |\r\n+-------+\r\n| John  |\r\n+-------+\r\n
    \r\n\r\n

    Note:
    \r\nNo one would report to himself.

    \r\n", "content_cn": "

    Employee \u8868\u5305\u542b\u6240\u6709\u5458\u5de5\u548c\u4ed6\u4eec\u7684\u7ecf\u7406\u3002\u6bcf\u4e2a\u5458\u5de5\u90fd\u6709\u4e00\u4e2a Id\uff0c\u5e76\u4e14\u8fd8\u6709\u4e00\u5217\u662f\u7ecf\u7406\u7684 Id\u3002

    \n\n
    +------+----------+-----------+----------+\n|Id    |Name \t  |Department |ManagerId |\n+------+----------+-----------+----------+\n|101   |John \t  |A \t      |null      |\n|102   |Dan \t  |A \t      |101       |\n|103   |James \t  |A \t      |101       |\n|104   |Amy \t  |A \t      |101       |\n|105   |Anne \t  |A \t      |101       |\n|106   |Ron \t  |B \t      |101       |\n+------+----------+-----------+----------+\n
    \n\n

    \u7ed9\u5b9a Employee \u8868\uff0c\u8bf7\u7f16\u5199\u4e00\u4e2aSQL\u67e5\u8be2\u6765\u67e5\u627e\u81f3\u5c11\u67095\u540d\u76f4\u63a5\u4e0b\u5c5e\u7684\u7ecf\u7406\u3002\u5bf9\u4e8e\u4e0a\u8868\uff0c\u60a8\u7684SQL\u67e5\u8be2\u5e94\u8be5\u8fd4\u56de\uff1a

    \n\n
    +-------+\n| Name  |\n+-------+\n| John  |\n+-------+\n
    \n\n

    \u6ce8\u610f:
    \n\u6ca1\u6709\u4eba\u662f\u81ea\u5df1\u7684\u4e0b\u5c5e\u3002

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0570](https://leetcode-cn.com/problems/managers-with-at-least-5-direct-reports)", "[\u81f3\u5c11\u67095\u540d\u76f4\u63a5\u4e0b\u5c5e\u7684\u7ecf\u7406](/solution/0500-0599/0570.Managers%20with%20at%20Least%205%20Direct%20Reports/README.md)", "", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0570](https://leetcode.com/problems/managers-with-at-least-5-direct-reports)", "[Managers with at Least 5 Direct Reports](/solution/0500-0599/0570.Managers%20with%20at%20Least%205%20Direct%20Reports/README_EN.md)", "", "Medium", "\ud83d\udd12"]}, {"question_id": "0569", "frontend_question_id": "0569", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/median-employee-salary", "url_en": "https://leetcode.com/problems/median-employee-salary", "relative_path_cn": "/solution/0500-0599/0569.Median%20Employee%20Salary/README.md", "relative_path_en": "/solution/0500-0599/0569.Median%20Employee%20Salary/README_EN.md", "title_cn": "\u5458\u5de5\u85aa\u6c34\u4e2d\u4f4d\u6570", "title_en": "Median Employee Salary", "question_title_slug": "median-employee-salary", "content_en": "

    The Employee table holds all employees. The employee table has three columns: Employee Id, Company Name, and Salary.

    \r\n\r\n
    \r\n+-----+------------+--------+\r\n|Id   | Company    | Salary |\r\n+-----+------------+--------+\r\n|1    | A          | 2341   |\r\n|2    | A          | 341    |\r\n|3    | A          | 15     |\r\n|4    | A          | 15314  |\r\n|5    | A          | 451    |\r\n|6    | A          | 513    |\r\n|7    | B          | 15     |\r\n|8    | B          | 13     |\r\n|9    | B          | 1154   |\r\n|10   | B          | 1345   |\r\n|11   | B          | 1221   |\r\n|12   | B          | 234    |\r\n|13   | C          | 2345   |\r\n|14   | C          | 2645   |\r\n|15   | C          | 2645   |\r\n|16   | C          | 2652   |\r\n|17   | C          | 65     |\r\n+-----+------------+--------+\r\n
    \r\n\r\n

    Write a SQL query to find the median salary of each company. Bonus points if you can solve it without using any built-in SQL functions.

    \r\n\r\n
    \r\n+-----+------------+--------+\r\n|Id   | Company    | Salary |\r\n+-----+------------+--------+\r\n|5    | A          | 451    |\r\n|6    | A          | 513    |\r\n|12   | B          | 234    |\r\n|9    | B          | 1154   |\r\n|14   | C          | 2645   |\r\n+-----+------------+--------+\r\n
    \r\n", "content_cn": "

    Employee \u8868\u5305\u542b\u6240\u6709\u5458\u5de5\u3002Employee \u8868\u6709\u4e09\u5217\uff1a\u5458\u5de5Id\uff0c\u516c\u53f8\u540d\u548c\u85aa\u6c34\u3002

    \n\n
    +-----+------------+--------+\n|Id   | Company    | Salary |\n+-----+------------+--------+\n|1    | A          | 2341   |\n|2    | A          | 341    |\n|3    | A          | 15     |\n|4    | A          | 15314  |\n|5    | A          | 451    |\n|6    | A          | 513    |\n|7    | B          | 15     |\n|8    | B          | 13     |\n|9    | B          | 1154   |\n|10   | B          | 1345   |\n|11   | B          | 1221   |\n|12   | B          | 234    |\n|13   | C          | 2345   |\n|14   | C          | 2645   |\n|15   | C          | 2645   |\n|16   | C          | 2652   |\n|17   | C          | 65     |\n+-----+------------+--------+\n
    \n\n

    \u8bf7\u7f16\u5199SQL\u67e5\u8be2\u6765\u67e5\u627e\u6bcf\u4e2a\u516c\u53f8\u7684\u85aa\u6c34\u4e2d\u4f4d\u6570\u3002\u6311\u6218\u70b9\uff1a\u4f60\u662f\u5426\u53ef\u4ee5\u5728\u4e0d\u4f7f\u7528\u4efb\u4f55\u5185\u7f6e\u7684SQL\u51fd\u6570\u7684\u60c5\u51b5\u4e0b\u89e3\u51b3\u6b64\u95ee\u9898\u3002

    \n\n
    +-----+------------+--------+\n|Id   | Company    | Salary |\n+-----+------------+--------+\n|5    | A          | 451    |\n|6    | A          | 513    |\n|12   | B          | 234    |\n|9    | B          | 1154   |\n|14   | C          | 2645   |\n+-----+------------+--------+\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0569](https://leetcode-cn.com/problems/median-employee-salary)", "[\u5458\u5de5\u85aa\u6c34\u4e2d\u4f4d\u6570](/solution/0500-0599/0569.Median%20Employee%20Salary/README.md)", "", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0569](https://leetcode.com/problems/median-employee-salary)", "[Median Employee Salary](/solution/0500-0599/0569.Median%20Employee%20Salary/README_EN.md)", "", "Hard", "\ud83d\udd12"]}, {"question_id": "0568", "frontend_question_id": "0568", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/maximum-vacation-days", "url_en": "https://leetcode.com/problems/maximum-vacation-days", "relative_path_cn": "/solution/0500-0599/0568.Maximum%20Vacation%20Days/README.md", "relative_path_en": "/solution/0500-0599/0568.Maximum%20Vacation%20Days/README_EN.md", "title_cn": "\u6700\u5927\u4f11\u5047\u5929\u6570", "title_en": "Maximum Vacation Days", "question_title_slug": "maximum-vacation-days", "content_en": "

    LeetCode wants to give one of its best employees the option to travel among n cities to collect algorithm problems. But all work and no play makes Jack a dull boy, you could take vacations in some particular cities and weeks. Your job is to schedule the traveling to maximize the number of vacation days you could take, but there are certain rules and restrictions you need to follow.

    \n\n

    Rules and restrictions:

    \n\n
      \n\t
    1. You can only travel among n cities, represented by indexes from 0 to n - 1. Initially, you are in the city indexed 0 on Monday.
    2. \n\t
    3. The cities are connected by flights. The flights are represented as an n x n matrix (not necessarily symmetrical), called flights representing the airline status from the city i to the city j. If there is no flight from the city i to the city j, flights[i][j] == 0; Otherwise, flights[i][j] == 1. Also, flights[i][i] == 0 for all i.
    4. \n\t
    5. You totally have k weeks (each week has seven days) to travel. You can only take flights at most once per day and can only take flights on each week's Monday morning. Since flight time is so short, we do not consider the impact of flight time.
    6. \n\t
    7. For each city, you can only have restricted vacation days in different weeks, given an n x k matrix called days representing this relationship. For the value of days[i][j], it represents the maximum days you could take a vacation in the city i in the week j.
    8. \n\t
    9. You could stay in a city beyond the number of vacation days, but you should work on the extra days, which will not be counted as vacation days.
    10. \n\t
    11. If you fly from city A to city B and take the vacation on that day, the deduction towards vacation days will count towards the vacation days of city B in that week.
    12. \n\t
    13. We do not consider the impact of flight hours on the calculation of vacation days.
    14. \n
    \n\n

    Given the two matrices flights and days, return the maximum vacation days you could take during k weeks.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: flights = [[0,1,1],[1,0,1],[1,1,0]], days = [[1,3,1],[6,0,3],[3,3,3]]\nOutput: 12\nExplanation:\nOne of the best strategies is:\n1st week : fly from city 0 to city 1 on Monday, and play 6 days and work 1 day.\n(Although you start at city 0, we could also fly to and start at other cities since it is Monday.)\n2nd week : fly from city 1 to city 2 on Monday, and play 3 days and work 4 days.\n3rd week : stay at city 2, and play 3 days and work 4 days.\nAns = 6 + 3 + 3 = 12.\n
    \n\n

    Example 2:

    \n\n
    \nInput: flights = [[0,0,0],[0,0,0],[0,0,0]], days = [[1,1,1],[7,7,7],[7,7,7]]\nOutput: 3\nExplanation:\nSince there are no flights that enable you to move to another city, you have to stay at city 0 for the whole 3 weeks. \nFor each week, you only have one day to play and six days to work.\nSo the maximum number of vacation days is 3.\nAns = 1 + 1 + 1 = 3.\n
    \n\n

    Example 3:

    \n\n
    \nInput: flights = [[0,1,1],[1,0,1],[1,1,0]], days = [[7,0,0],[0,7,0],[0,0,7]]\nOutput: 21\nExplanation:\nOne of the best strategies is:\n1st week : stay at city 0, and play 7 days.\n2nd week : fly from city 0 to city 1 on Monday, and play 7 days.\n3rd week : fly from city 1 to city 2 on Monday, and play 7 days.\nAns = 7 + 7 + 7 = 21\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == flights.length
    • \n\t
    • n == flights[i].length
    • \n\t
    • n == days.length
    • \n\t
    • k == days[i].length
    • \n\t
    • 1 <= n, k <= 100
    • \n\t
    • flights[i][j] is either 0 or 1.
    • \n\t
    • 0 <= days[i] <= 7
    • \n
    \n", "content_cn": "

    \u529b\u6263\u60f3\u8ba9\u4e00\u4e2a\u6700\u4f18\u79c0\u7684\u5458\u5de5\u5728 N \u4e2a\u57ce\u5e02\u95f4\u65c5\u884c\u6765\u6536\u96c6\u7b97\u6cd5\u95ee\u9898\u3002 \u4f46\u53ea\u5de5\u4f5c\u4e0d\u73a9\u800d\uff0c\u806a\u660e\u7684\u5b69\u5b50\u4e5f\u4f1a\u53d8\u50bb\uff0c\u6240\u4ee5\u60a8\u53ef\u4ee5\u5728\u67d0\u4e9b\u7279\u5b9a\u7684\u57ce\u5e02\u548c\u661f\u671f\u4f11\u5047\u3002\u60a8\u7684\u5de5\u4f5c\u5c31\u662f\u5b89\u6392\u65c5\u884c\u4f7f\u5f97\u6700\u5927\u5316\u4f60\u53ef\u4ee5\u4f11\u5047\u7684\u5929\u6570\uff0c\u4f46\u662f\u60a8\u9700\u8981\u9075\u5b88\u4e00\u4e9b\u89c4\u5219\u548c\u9650\u5236\u3002

    \n\n

    \u89c4\u5219\u548c\u9650\u5236\uff1a

    \n\n
      \n\t
    1. \u60a8\u53ea\u80fd\u5728 N \u4e2a\u57ce\u5e02\u4e4b\u95f4\u65c5\u884c\uff0c\u7528 0 \u5230 N-1 \u7684\u7d22\u5f15\u8868\u793a\u3002\u4e00\u5f00\u59cb\uff0c\u60a8\u5728\u7d22\u5f15\u4e3a0\u7684\u57ce\u5e02\uff0c\u5e76\u4e14\u90a3\u5929\u662f\u661f\u671f\u4e00\u3002
    2. \n\t
    3. \u8fd9\u4e9b\u57ce\u5e02\u901a\u8fc7\u822a\u73ed\u76f8\u8fde\u3002\u8fd9\u4e9b\u822a\u73ed\u7528 N*N \u77e9\u9635 flights\uff08\u4e0d\u4e00\u5b9a\u662f\u5bf9\u79f0\u7684\uff09\u8868\u793a\uff0cflights[i][j] \u4ee3\u8868\u57ce\u5e02i\u5230\u57ce\u5e02j\u7684\u822a\u7a7a\u72b6\u6001\u3002\u5982\u679c\u6ca1\u6709\u57ce\u5e02i\u5230\u57ce\u5e02j\u7684\u822a\u73ed\uff0cflights[i][j] = 0\uff1b\u5426\u5219\uff0cflights[i][j] = 1\u3002\u540c\u65f6\uff0c\u5bf9\u4e8e\u6240\u6709\u7684i\uff0cflights[i][i] = 0\u3002
    4. \n\t
    5. \u60a8\u603b\u5171\u6709 K \u5468\uff08\u6bcf\u54687\u5929\uff09\u7684\u65f6\u95f4\u65c5\u884c\u3002\u60a8\u6bcf\u5929\u6700\u591a\u53ea\u80fd\u4e58\u5750\u4e00\u6b21\u822a\u73ed\uff0c\u5e76\u4e14\u53ea\u80fd\u5728\u6bcf\u5468\u7684\u661f\u671f\u4e00\u4e0a\u5348\u4e58\u5750\u822a\u73ed\u3002\u7531\u4e8e\u98de\u884c\u65f6\u95f4\u5f88\u77ed\uff0c\u6211\u4eec\u4e0d\u8003\u8651\u98de\u884c\u65f6\u95f4\u7684\u5f71\u54cd\u3002
    6. \n\t
    7. \u5bf9\u4e8e\u6bcf\u4e2a\u57ce\u5e02\uff0c\u4e0d\u540c\u7684\u661f\u671f\u60a8\u4f11\u5047\u5929\u6570\u662f\u4e0d\u540c\u7684\uff0c\u7ed9\u5b9a\u4e00\u4e2a N*K \u77e9\u9635 days \u4ee3\u8868\u8fd9\u79cd\u9650\u5236\uff0cdays[i][j] \u4ee3\u8868\u60a8\u5728\u7b2cj\u4e2a\u661f\u671f\u5728\u57ce\u5e02i\u80fd\u4f11\u5047\u7684\u6700\u957f\u5929\u6570\u3002
    8. \n
    \n\n

    \u7ed9\u5b9a flights \u77e9\u9635\u548c days \u77e9\u9635\uff0c\u60a8\u9700\u8981\u8f93\u51fa K \u5468\u5185\u53ef\u4ee5\u4f11\u5047\u7684\u6700\u957f\u5929\u6570\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165:flights = [[0,1,1],[1,0,1],[1,1,0]], days = [[1,3,1],[6,0,3],[3,3,3]]\n\u8f93\u51fa: 12\n\u89e3\u91ca: \nAns = 6 + 3 + 3 = 12. \n\n\u6700\u597d\u7684\u7b56\u7565\u4e4b\u4e00\uff1a\n\u7b2c\u4e00\u4e2a\u661f\u671f : \u661f\u671f\u4e00\u4ece\u57ce\u5e020\u98de\u5230\u57ce\u5e021\uff0c\u73a96\u5929\uff0c\u5de5\u4f5c1\u5929\u3002 \n\uff08\u867d\u7136\u4f60\u662f\u4ece\u57ce\u5e020\u5f00\u59cb\uff0c\u4f46\u56e0\u4e3a\u662f\u661f\u671f\u4e00\uff0c\u6211\u4eec\u4e5f\u53ef\u4ee5\u98de\u5230\u5176\u4ed6\u57ce\u5e02\u3002\uff09 \n\u7b2c\u4e8c\u4e2a\u661f\u671f : \u661f\u671f\u4e00\u4ece\u57ce\u5e021\u98de\u5230\u57ce\u5e022\uff0c\u73a93\u5929\uff0c\u5de5\u4f5c4\u5929\u3002\n\u7b2c\u4e09\u4e2a\u661f\u671f : \u5446\u5728\u57ce\u5e022\uff0c\u73a93\u5929\uff0c\u5de5\u4f5c4\u5929\u3002\n
    \n\n

     

    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165:flights = [[0,0,0],[0,0,0],[0,0,0]], days = [[1,1,1],[7,7,7],[7,7,7]]\n\u8f93\u51fa: 3\n\u89e3\u91ca: \nAns = 1 + 1 + 1 = 3. \n\n\u7531\u4e8e\u6ca1\u6709\u822a\u73ed\u53ef\u4ee5\u8ba9\u60a8\u98de\u5230\u5176\u4ed6\u57ce\u5e02\uff0c\u4f60\u5fc5\u987b\u5728\u57ce\u5e020\u5446\u6574\u65743\u4e2a\u661f\u671f\u3002 \n\u5bf9\u4e8e\u6bcf\u4e00\u4e2a\u661f\u671f\uff0c\u4f60\u53ea\u6709\u4e00\u5929\u65f6\u95f4\u73a9\uff0c\u5269\u4e0b\u516d\u5929\u90fd\u8981\u5de5\u4f5c\u3002 \n\u6240\u4ee5\u6700\u5927\u4f11\u5047\u5929\u6570\u4e3a3.\n
    \n\n

     

    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u8f93\u5165:flights = [[0,1,1],[1,0,1],[1,1,0]], days = [[7,0,0],[0,7,0],[0,0,7]]\n\u8f93\u51fa: 21\n\u89e3\u91ca:\nAns = 7 + 7 + 7 = 21\n\n\u6700\u597d\u7684\u7b56\u7565\u4e4b\u4e00\u662f\uff1a\n\u7b2c\u4e00\u4e2a\u661f\u671f : \u5446\u5728\u57ce\u5e020\uff0c\u73a97\u5929\u3002 \n\u7b2c\u4e8c\u4e2a\u661f\u671f : \u661f\u671f\u4e00\u4ece\u57ce\u5e020\u98de\u5230\u57ce\u5e021\uff0c\u73a97\u5929\u3002\n\u7b2c\u4e09\u4e2a\u661f\u671f : \u661f\u671f\u4e00\u4ece\u57ce\u5e021\u98de\u5230\u57ce\u5e022\uff0c\u73a97\u5929\u3002\n
    \n\n

     

    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. N \u548c K \u90fd\u662f\u6b63\u6574\u6570\uff0c\u5728 [1, 100] \u8303\u56f4\u5185\u3002
    2. \n\t
    3. \u77e9\u9635 flights \u7684\u6240\u6709\u503c\u90fd\u662f [0, 1] \u8303\u56f4\u5185\u7684\u6574\u6570\u3002
    4. \n\t
    5. \u77e9\u9635 days \u7684\u6240\u6709\u503c\u90fd\u662f [0, 7] \u8303\u56f4\u5185\u7684\u6574\u6570\u3002
    6. \n\t
    7. \u8d85\u8fc7\u4f11\u5047\u5929\u6570\u60a8\u4ecd\u53ef\u4ee5\u5446\u5728\u90a3\u4e2a\u57ce\u5e02\uff0c\u4f46\u662f\u5728\u989d\u5916\u7684\u65e5\u5b50\u60a8\u9700\u8981 \u5de5\u4f5c \uff0c\u8fd9\u4e9b\u65e5\u5b50\u4e0d\u4f1a\u7b97\u505a\u4f11\u5047\u65e5\u3002
    8. \n\t
    9. \u5982\u679c\u60a8\u4ece\u57ce\u5e02A\u98de\u5f80\u57ce\u5e02B\u5e76\u5728\u5f53\u5929\u4f11\u5047\u65e5\uff0c\u8fd9\u4e2a\u4f11\u5047\u4f1a\u88ab\u7b97\u4f5c\u662f\u57ce\u5e02B\u7684\u4f11\u5047\u65e5\u3002
    10. \n\t
    11. \u6211\u4eec\u4e0d\u8003\u8651\u98de\u884c\u65f6\u95f4\u5bf9\u8ba1\u7b97\u4f11\u5047\u65e5\u7684\u5f71\u54cd\u3002
    12. \n
    \n\n

     

    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxVacationDays(vector>& flights, vector>& days) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxVacationDays(int[][] flights, int[][] days) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxVacationDays(self, flights, days):\n \"\"\"\n :type flights: List[List[int]]\n :type days: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxVacationDays(self, flights: List[List[int]], days: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxVacationDays(int** flights, int flightsSize, int* flightsColSize, int** days, int daysSize, int* daysColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxVacationDays(int[][] flights, int[][] days) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} flights\n * @param {number[][]} days\n * @return {number}\n */\nvar maxVacationDays = function(flights, days) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} flights\n# @param {Integer[][]} days\n# @return {Integer}\ndef max_vacation_days(flights, days)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxVacationDays(_ flights: [[Int]], _ days: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxVacationDays(flights [][]int, days [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxVacationDays(flights: Array[Array[Int]], days: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxVacationDays(flights: Array, days: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_vacation_days(flights: Vec>, days: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $flights\n * @param Integer[][] $days\n * @return Integer\n */\n function maxVacationDays($flights, $days) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxVacationDays(flights: number[][], days: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-vacation-days flights days)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0568](https://leetcode-cn.com/problems/maximum-vacation-days)", "[\u6700\u5927\u4f11\u5047\u5929\u6570](/solution/0500-0599/0568.Maximum%20Vacation%20Days/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0568](https://leetcode.com/problems/maximum-vacation-days)", "[Maximum Vacation Days](/solution/0500-0599/0568.Maximum%20Vacation%20Days/README_EN.md)", "`Dynamic Programming`", "Hard", "\ud83d\udd12"]}, {"question_id": "0567", "frontend_question_id": "0567", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/permutation-in-string", "url_en": "https://leetcode.com/problems/permutation-in-string", "relative_path_cn": "/solution/0500-0599/0567.Permutation%20in%20String/README.md", "relative_path_en": "/solution/0500-0599/0567.Permutation%20in%20String/README_EN.md", "title_cn": "\u5b57\u7b26\u4e32\u7684\u6392\u5217", "title_en": "Permutation in String", "question_title_slug": "permutation-in-string", "content_en": "

    Given two strings s1 and s2, return true if s2 contains the permutation of s1.

    \n\n

    In other words, one of s1's permutations is the substring of s2.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s1 = "ab", s2 = "eidbaooo"\nOutput: true\nExplanation: s2 contains one permutation of s1 ("ba").\n
    \n\n

    Example 2:

    \n\n
    \nInput: s1 = "ab", s2 = "eidboaoo"\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s1.length, s2.length <= 104
    • \n\t
    • s1 and s2 consist of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u5b57\u7b26\u4e32\u00a0s1\u00a0\u548c\u00a0s2\uff0c\u5199\u4e00\u4e2a\u51fd\u6570\u6765\u5224\u65ad s2 \u662f\u5426\u5305\u542b s1\u00a0\u7684\u6392\u5217\u3002

    \n\n

    \u6362\u53e5\u8bdd\u8bf4\uff0c\u7b2c\u4e00\u4e2a\u5b57\u7b26\u4e32\u7684\u6392\u5217\u4e4b\u4e00\u662f\u7b2c\u4e8c\u4e2a\u5b57\u7b26\u4e32\u7684 \u5b50\u4e32 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165: s1 = \"ab\" s2 = \"eidbaooo\"\n\u8f93\u51fa: True\n\u89e3\u91ca: s2 \u5305\u542b s1 \u7684\u6392\u5217\u4e4b\u4e00 (\"ba\").\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165: s1= \"ab\" s2 = \"eidboaoo\"\n\u8f93\u51fa: False\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u8f93\u5165\u7684\u5b57\u7b26\u4e32\u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd
    • \n\t
    • \u4e24\u4e2a\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u90fd\u5728 [1, 10,000] \u4e4b\u95f4
    • \n
    \n", "tags_en": ["Two Pointers", "Sliding Window"], "tags_cn": ["\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool checkInclusion(string s1, string s2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean checkInclusion(String s1, String s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def checkInclusion(self, s1, s2):\n \"\"\"\n :type s1: str\n :type s2: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def checkInclusion(self, s1: str, s2: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool checkInclusion(char * s1, char * s2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CheckInclusion(string s1, string s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s1\n * @param {string} s2\n * @return {boolean}\n */\nvar checkInclusion = function(s1, s2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s1\n# @param {String} s2\n# @return {Boolean}\ndef check_inclusion(s1, s2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func checkInclusion(_ s1: String, _ s2: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func checkInclusion(s1 string, s2 string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def checkInclusion(s1: String, s2: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun checkInclusion(s1: String, s2: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn check_inclusion(s1: String, s2: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s1\n * @param String $s2\n * @return Boolean\n */\n function checkInclusion($s1, $s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function checkInclusion(s1: string, s2: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (check-inclusion s1 s2)\n (-> string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0567](https://leetcode-cn.com/problems/permutation-in-string)", "[\u5b57\u7b26\u4e32\u7684\u6392\u5217](/solution/0500-0599/0567.Permutation%20in%20String/README.md)", "`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0567](https://leetcode.com/problems/permutation-in-string)", "[Permutation in String](/solution/0500-0599/0567.Permutation%20in%20String/README_EN.md)", "`Two Pointers`,`Sliding Window`", "Medium", ""]}, {"question_id": "0566", "frontend_question_id": "0566", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reshape-the-matrix", "url_en": "https://leetcode.com/problems/reshape-the-matrix", "relative_path_cn": "/solution/0500-0599/0566.Reshape%20the%20Matrix/README.md", "relative_path_en": "/solution/0500-0599/0566.Reshape%20the%20Matrix/README_EN.md", "title_cn": "\u91cd\u5851\u77e9\u9635", "title_en": "Reshape the Matrix", "question_title_slug": "reshape-the-matrix", "content_en": "

    In MATLAB, there is a handy function called reshape which can reshape an m x n matrix into a new one with a different size r x c keeping its original data.

    \n\n

    You are given an m x n matrix mat and two integers r and c representing the row number and column number of the wanted reshaped matrix.

    \n\n

    The reshaped matrix should be filled with all the elements of the original matrix in the same row-traversing order as they were.

    \n\n

    If the reshape operation with given parameters is possible and legal, output the new reshaped matrix; Otherwise, output the original matrix.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: mat = [[1,2],[3,4]], r = 1, c = 4\nOutput: [[1,2,3,4]]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: mat = [[1,2],[3,4]], r = 2, c = 4\nOutput: [[1,2],[3,4]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == mat.length
    • \n\t
    • n == mat[i].length
    • \n\t
    • 1 <= m, n <= 100
    • \n\t
    • -1000 <= mat[i][j] <= 1000
    • \n\t
    • 1 <= r, c <= 300
    • \n
    \n", "content_cn": "

    \u5728MATLAB\u4e2d\uff0c\u6709\u4e00\u4e2a\u975e\u5e38\u6709\u7528\u7684\u51fd\u6570 reshape\uff0c\u5b83\u53ef\u4ee5\u5c06\u4e00\u4e2a\u77e9\u9635\u91cd\u5851\u4e3a\u53e6\u4e00\u4e2a\u5927\u5c0f\u4e0d\u540c\u7684\u65b0\u77e9\u9635\uff0c\u4f46\u4fdd\u7559\u5176\u539f\u59cb\u6570\u636e\u3002

    \n\n

    \u7ed9\u51fa\u4e00\u4e2a\u7531\u4e8c\u7ef4\u6570\u7ec4\u8868\u793a\u7684\u77e9\u9635\uff0c\u4ee5\u53ca\u4e24\u4e2a\u6b63\u6574\u6570r\u548cc\uff0c\u5206\u522b\u8868\u793a\u60f3\u8981\u7684\u91cd\u6784\u7684\u77e9\u9635\u7684\u884c\u6570\u548c\u5217\u6570\u3002

    \n\n

    \u91cd\u6784\u540e\u7684\u77e9\u9635\u9700\u8981\u5c06\u539f\u59cb\u77e9\u9635\u7684\u6240\u6709\u5143\u7d20\u4ee5\u76f8\u540c\u7684\u884c\u904d\u5386\u987a\u5e8f\u586b\u5145\u3002

    \n\n

    \u5982\u679c\u5177\u6709\u7ed9\u5b9a\u53c2\u6570\u7684reshape\u64cd\u4f5c\u662f\u53ef\u884c\u4e14\u5408\u7406\u7684\uff0c\u5219\u8f93\u51fa\u65b0\u7684\u91cd\u5851\u77e9\u9635\uff1b\u5426\u5219\uff0c\u8f93\u51fa\u539f\u59cb\u77e9\u9635\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: \nnums = \n[[1,2],\n [3,4]]\nr = 1, c = 4\n\u8f93\u51fa: \n[[1,2,3,4]]\n\u89e3\u91ca:\n\u884c\u904d\u5386nums\u7684\u7ed3\u679c\u662f [1,2,3,4]\u3002\u65b0\u7684\u77e9\u9635\u662f 1 * 4 \u77e9\u9635, \u7528\u4e4b\u524d\u7684\u5143\u7d20\u503c\u4e00\u884c\u4e00\u884c\u586b\u5145\u65b0\u77e9\u9635\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: \nnums = \n[[1,2],\n [3,4]]\nr = 2, c = 4\n\u8f93\u51fa: \n[[1,2],\n [3,4]]\n\u89e3\u91ca:\n\u6ca1\u6709\u529e\u6cd5\u5c06 2 * 2 \u77e9\u9635\u8f6c\u5316\u4e3a 2 * 4 \u77e9\u9635\u3002 \u6240\u4ee5\u8f93\u51fa\u539f\u77e9\u9635\u3002\n
    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    1. \u7ed9\u5b9a\u77e9\u9635\u7684\u5bbd\u548c\u9ad8\u8303\u56f4\u5728 [1, 100]\u3002
    2. \n\t
    3. \u7ed9\u5b9a\u7684 r \u548c c \u90fd\u662f\u6b63\u6570\u3002
    4. \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> matrixReshape(vector>& mat, int r, int c) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[][] matrixReshape(int[][] mat, int r, int c) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def matrixReshape(self, mat, r, c):\n \"\"\"\n :type mat: List[List[int]]\n :type r: int\n :type c: int\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def matrixReshape(self, mat: List[List[int]], r: int, c: int) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** matrixReshape(int** mat, int matSize, int* matColSize, int r, int c, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[][] MatrixReshape(int[][] mat, int r, int c) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} mat\n * @param {number} r\n * @param {number} c\n * @return {number[][]}\n */\nvar matrixReshape = function(mat, r, c) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} mat\n# @param {Integer} r\n# @param {Integer} c\n# @return {Integer[][]}\ndef matrix_reshape(mat, r, c)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func matrixReshape(_ mat: [[Int]], _ r: Int, _ c: Int) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func matrixReshape(mat [][]int, r int, c int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def matrixReshape(mat: Array[Array[Int]], r: Int, c: Int): Array[Array[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun matrixReshape(mat: Array, r: Int, c: Int): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn matrix_reshape(mat: Vec>, r: i32, c: i32) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $mat\n * @param Integer $r\n * @param Integer $c\n * @return Integer[][]\n */\n function matrixReshape($mat, $r, $c) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function matrixReshape(mat: number[][], r: number, c: number): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (matrix-reshape mat r c)\n (-> (listof (listof exact-integer?)) exact-integer? exact-integer? (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0566](https://leetcode-cn.com/problems/reshape-the-matrix)", "[\u91cd\u5851\u77e9\u9635](/solution/0500-0599/0566.Reshape%20the%20Matrix/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0566](https://leetcode.com/problems/reshape-the-matrix)", "[Reshape the Matrix](/solution/0500-0599/0566.Reshape%20the%20Matrix/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0565", "frontend_question_id": "0565", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/array-nesting", "url_en": "https://leetcode.com/problems/array-nesting", "relative_path_cn": "/solution/0500-0599/0565.Array%20Nesting/README.md", "relative_path_en": "/solution/0500-0599/0565.Array%20Nesting/README_EN.md", "title_cn": "\u6570\u7ec4\u5d4c\u5957", "title_en": "Array Nesting", "question_title_slug": "array-nesting", "content_en": "

    You are given an integer array nums of length n where nums is a permutation of the numbers in the range [0, n - 1].

    \n\n

    You should build a set s[k] = {nums[k], nums[nums[k]], nums[nums[nums[k]]], ... } subjected to the following rule:

    \n\n
      \n\t
    • The first element in s[k] starts with the selection of the element nums[k] of index = k.
    • \n\t
    • The next element in s[k] should be nums[nums[k]], and then nums[nums[nums[k]]], and so on.
    • \n\t
    • We stop adding right before a duplicate element occurs in s[k].
    • \n
    \n\n

    Return the longest length of a set s[k].

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [5,4,0,3,1,6,2]\nOutput: 4\nExplanation: \nnums[0] = 5, nums[1] = 4, nums[2] = 0, nums[3] = 3, nums[4] = 1, nums[5] = 6, nums[6] = 2.\nOne of the longest sets s[k]:\ns[0] = {nums[0], nums[5], nums[6], nums[2]} = {5, 6, 2, 0}\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [0,1,2]\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • 0 <= nums[i] < nums.length
    • \n\t
    • All the values of nums are unique.
    • \n
    \n", "content_cn": "

    \u7d22\u5f15\u4ece0\u5f00\u59cb\u957f\u5ea6\u4e3aN\u7684\u6570\u7ec4A\uff0c\u5305\u542b0\u5230N - 1\u7684\u6240\u6709\u6574\u6570\u3002\u627e\u5230\u6700\u5927\u7684\u96c6\u5408S\u5e76\u8fd4\u56de\u5176\u5927\u5c0f\uff0c\u5176\u4e2d S[i] = {A[i], A[A[i]], A[A[A[i]]], ... }\u4e14\u9075\u5b88\u4ee5\u4e0b\u7684\u89c4\u5219\u3002

    \n\n

    \u5047\u8bbe\u9009\u62e9\u7d22\u5f15\u4e3ai\u7684\u5143\u7d20A[i]\u4e3aS\u7684\u7b2c\u4e00\u4e2a\u5143\u7d20\uff0cS\u7684\u4e0b\u4e00\u4e2a\u5143\u7d20\u5e94\u8be5\u662fA[A[i]]\uff0c\u4e4b\u540e\u662fA[A[A[i]]]... \u4ee5\u6b64\u7c7b\u63a8\uff0c\u4e0d\u65ad\u6dfb\u52a0\u76f4\u5230S\u51fa\u73b0\u91cd\u590d\u7684\u5143\u7d20\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: A = [5,4,0,3,1,6,2]\n\u8f93\u51fa: 4\n\u89e3\u91ca: \nA[0] = 5, A[1] = 4, A[2] = 0, A[3] = 3, A[4] = 1, A[5] = 6, A[6] = 2.\n\n\u5176\u4e2d\u4e00\u79cd\u6700\u957f\u7684 S[K]:\nS[0] = {A[0], A[5], A[6], A[2]} = {5, 6, 2, 0}\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. N\u662f[1, 20,000]\u4e4b\u95f4\u7684\u6574\u6570\u3002
    2. \n\t
    3. A\u4e2d\u4e0d\u542b\u6709\u91cd\u590d\u7684\u5143\u7d20\u3002
    4. \n\t
    5. A\u4e2d\u7684\u5143\u7d20\u5927\u5c0f\u5728[0, N-1]\u4e4b\u95f4\u3002
    6. \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int arrayNesting(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int arrayNesting(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def arrayNesting(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def arrayNesting(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint arrayNesting(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ArrayNesting(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar arrayNesting = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef array_nesting(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func arrayNesting(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func arrayNesting(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def arrayNesting(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun arrayNesting(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn array_nesting(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function arrayNesting($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function arrayNesting(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (array-nesting nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0565](https://leetcode-cn.com/problems/array-nesting)", "[\u6570\u7ec4\u5d4c\u5957](/solution/0500-0599/0565.Array%20Nesting/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0565](https://leetcode.com/problems/array-nesting)", "[Array Nesting](/solution/0500-0599/0565.Array%20Nesting/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0564", "frontend_question_id": "0564", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-the-closest-palindrome", "url_en": "https://leetcode.com/problems/find-the-closest-palindrome", "relative_path_cn": "/solution/0500-0599/0564.Find%20the%20Closest%20Palindrome/README.md", "relative_path_en": "/solution/0500-0599/0564.Find%20the%20Closest%20Palindrome/README_EN.md", "title_cn": "\u5bfb\u627e\u6700\u8fd1\u7684\u56de\u6587\u6570", "title_en": "Find the Closest Palindrome", "question_title_slug": "find-the-closest-palindrome", "content_en": "

    Given a string n representing an integer, return the closest integer (not including itself), which is a palindrome. If there is a tie, return the smaller one.

    \n\n

    The closest is defined as the absolute difference minimized between two integers.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = "123"\nOutput: "121"\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = "1"\nOutput: "0"\nExplanation: 0 and 2 are the closest palindromes but we return the smallest which is 0.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n.length <= 18
    • \n\t
    • n consists of only digits.
    • \n\t
    • n does not have leading zeros.
    • \n\t
    • n is representing an integer in the range [1, 1018 - 1].
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570 n \uff0c\u4f60\u9700\u8981\u627e\u5230\u4e0e\u5b83\u6700\u8fd1\u7684\u56de\u6587\u6570\uff08\u4e0d\u5305\u62ec\u81ea\u8eab\uff09\u3002

    \n\n

    “\u6700\u8fd1\u7684”\u5b9a\u4e49\u4e3a\u4e24\u4e2a\u6574\u6570\u5dee\u7684\u7edd\u5bf9\u503c\u6700\u5c0f\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: "123"\n\u8f93\u51fa: "121"\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. n \u662f\u7531\u5b57\u7b26\u4e32\u8868\u793a\u7684\u6b63\u6574\u6570\uff0c\u5176\u957f\u5ea6\u4e0d\u8d85\u8fc718\u3002
    2. \n\t
    3. \u5982\u679c\u6709\u591a\u4e2a\u7ed3\u679c\uff0c\u8fd4\u56de\u6700\u5c0f\u7684\u90a3\u4e2a\u3002
    4. \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string nearestPalindromic(string n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String nearestPalindromic(String n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def nearestPalindromic(self, n):\n \"\"\"\n :type n: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def nearestPalindromic(self, n: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * nearestPalindromic(char * n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string NearestPalindromic(string n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} n\n * @return {string}\n */\nvar nearestPalindromic = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} n\n# @return {String}\ndef nearest_palindromic(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func nearestPalindromic(_ n: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func nearestPalindromic(n string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def nearestPalindromic(n: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun nearestPalindromic(n: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn nearest_palindromic(n: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $n\n * @return String\n */\n function nearestPalindromic($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function nearestPalindromic(n: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (nearest-palindromic n)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0564](https://leetcode-cn.com/problems/find-the-closest-palindrome)", "[\u5bfb\u627e\u6700\u8fd1\u7684\u56de\u6587\u6570](/solution/0500-0599/0564.Find%20the%20Closest%20Palindrome/README.md)", "`\u5b57\u7b26\u4e32`", "\u56f0\u96be", ""], "md_table_row_en": ["[0564](https://leetcode.com/problems/find-the-closest-palindrome)", "[Find the Closest Palindrome](/solution/0500-0599/0564.Find%20the%20Closest%20Palindrome/README_EN.md)", "`String`", "Hard", ""]}, {"question_id": "0563", "frontend_question_id": "0563", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/binary-tree-tilt", "url_en": "https://leetcode.com/problems/binary-tree-tilt", "relative_path_cn": "/solution/0500-0599/0563.Binary%20Tree%20Tilt/README.md", "relative_path_en": "/solution/0500-0599/0563.Binary%20Tree%20Tilt/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u7684\u5761\u5ea6", "title_en": "Binary Tree Tilt", "question_title_slug": "binary-tree-tilt", "content_en": "

    Given the root of a binary tree, return the sum of every tree node's tilt.

    \n\n

    The tilt of a tree node is the absolute difference between the sum of all left subtree node values and all right subtree node values. If a node does not have a left child, then the sum of the left subtree node values is treated as 0. The rule is similar if there the node does not have a right child.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,2,3]\nOutput: 1\nExplanation: \nTilt of node 2 : |0-0| = 0 (no children)\nTilt of node 3 : |0-0| = 0 (no children)\nTilt of node 1 : |2-3| = 1 (left subtree is just left child, so sum is 2; right subtree is just right child, so sum is 3)\nSum of every tilt : 0 + 0 + 1 = 1\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [4,2,9,3,5,null,7]\nOutput: 15\nExplanation: \nTilt of node 3 : |0-0| = 0 (no children)\nTilt of node 5 : |0-0| = 0 (no children)\nTilt of node 7 : |0-0| = 0 (no children)\nTilt of node 2 : |3-5| = 2 (left subtree is just left child, so sum is 3; right subtree is just right child, so sum is 5)\nTilt of node 9 : |0-7| = 7 (no left child, so sum is 0; right subtree is just right child, so sum is 7)\nTilt of node 4 : |(3+5+2)-(9+7)| = |10-16| = 6 (left subtree values are 3, 5, and 2, which sums to 10; right subtree values are 9 and 7, which sums to 16)\nSum of every tilt : 0 + 0 + 0 + 2 + 7 + 6 = 15\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: root = [21,7,14,1,1,2,2,3,3]\nOutput: 9\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [0, 104].
    • \n\t
    • -1000 <= Node.val <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811\uff0c\u8ba1\u7b97 \u6574\u4e2a\u6811 \u7684\u5761\u5ea6 \u3002

    \n\n

    \u4e00\u4e2a\u6811\u7684 \u8282\u70b9\u7684\u5761\u5ea6 \u5b9a\u4e49\u5373\u4e3a\uff0c\u8be5\u8282\u70b9\u5de6\u5b50\u6811\u7684\u8282\u70b9\u4e4b\u548c\u548c\u53f3\u5b50\u6811\u8282\u70b9\u4e4b\u548c\u7684 \u5dee\u7684\u7edd\u5bf9\u503c \u3002\u5982\u679c\u6ca1\u6709\u5de6\u5b50\u6811\u7684\u8bdd\uff0c\u5de6\u5b50\u6811\u7684\u8282\u70b9\u4e4b\u548c\u4e3a 0 \uff1b\u6ca1\u6709\u53f3\u5b50\u6811\u7684\u8bdd\u4e5f\u662f\u4e00\u6837\u3002\u7a7a\u7ed3\u70b9\u7684\u5761\u5ea6\u662f 0 \u3002

    \n\n

    \u6574\u4e2a\u6811 \u7684\u5761\u5ea6\u5c31\u662f\u5176\u6240\u6709\u8282\u70b9\u7684\u5761\u5ea6\u4e4b\u548c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [1,2,3]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\n\u8282\u70b9 2 \u7684\u5761\u5ea6\uff1a|0-0| = 0\uff08\u6ca1\u6709\u5b50\u8282\u70b9\uff09\n\u8282\u70b9 3 \u7684\u5761\u5ea6\uff1a|0-0| = 0\uff08\u6ca1\u6709\u5b50\u8282\u70b9\uff09\n\u8282\u70b9 1 \u7684\u5761\u5ea6\uff1a|2-3| = 1\uff08\u5de6\u5b50\u6811\u5c31\u662f\u5de6\u5b50\u8282\u70b9\uff0c\u6240\u4ee5\u548c\u662f 2 \uff1b\u53f3\u5b50\u6811\u5c31\u662f\u53f3\u5b50\u8282\u70b9\uff0c\u6240\u4ee5\u548c\u662f 3 \uff09\n\u5761\u5ea6\u603b\u548c\uff1a0 + 0 + 1 = 1\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [4,2,9,3,5,null,7]\n\u8f93\u51fa\uff1a15\n\u89e3\u91ca\uff1a\n\u8282\u70b9 3 \u7684\u5761\u5ea6\uff1a|0-0| = 0\uff08\u6ca1\u6709\u5b50\u8282\u70b9\uff09\n\u8282\u70b9 5 \u7684\u5761\u5ea6\uff1a|0-0| = 0\uff08\u6ca1\u6709\u5b50\u8282\u70b9\uff09\n\u8282\u70b9 7 \u7684\u5761\u5ea6\uff1a|0-0| = 0\uff08\u6ca1\u6709\u5b50\u8282\u70b9\uff09\n\u8282\u70b9 2 \u7684\u5761\u5ea6\uff1a|3-5| = 2\uff08\u5de6\u5b50\u6811\u5c31\u662f\u5de6\u5b50\u8282\u70b9\uff0c\u6240\u4ee5\u548c\u662f 3 \uff1b\u53f3\u5b50\u6811\u5c31\u662f\u53f3\u5b50\u8282\u70b9\uff0c\u6240\u4ee5\u548c\u662f 5 \uff09\n\u8282\u70b9 9 \u7684\u5761\u5ea6\uff1a|0-7| = 7\uff08\u6ca1\u6709\u5de6\u5b50\u6811\uff0c\u6240\u4ee5\u548c\u662f 0 \uff1b\u53f3\u5b50\u6811\u6b63\u597d\u662f\u53f3\u5b50\u8282\u70b9\uff0c\u6240\u4ee5\u548c\u662f 7 \uff09\n\u8282\u70b9 4 \u7684\u5761\u5ea6\uff1a|(3+5+2)-(9+7)| = |10-16| = 6\uff08\u5de6\u5b50\u6811\u503c\u4e3a 3\u30015 \u548c 2 \uff0c\u548c\u662f 10 \uff1b\u53f3\u5b50\u6811\u503c\u4e3a 9 \u548c 7 \uff0c\u548c\u662f 16 \uff09\n\u5761\u5ea6\u603b\u548c\uff1a0 + 0 + 0 + 2 + 7 + 6 = 15\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [21,7,14,1,1,2,2,3,3]\n\u8f93\u51fa\uff1a9\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u6570\u76ee\u7684\u8303\u56f4\u5728 [0, 104] \u5185
    • \n\t
    • -1000 <= Node.val <= 1000
    • \n
    \n", "tags_en": ["Tree", "Depth-first Search", "Recursion"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u9012\u5f52"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int findTilt(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int findTilt(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def findTilt(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def findTilt(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint findTilt(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int FindTilt(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar findTilt = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef find_tilt(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func findTilt(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc findTilt(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def findTilt(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun findTilt(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn find_tilt(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function findTilt($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction findTilt(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (find-tilt root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0563](https://leetcode-cn.com/problems/binary-tree-tilt)", "[\u4e8c\u53c9\u6811\u7684\u5761\u5ea6](/solution/0500-0599/0563.Binary%20Tree%20Tilt/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u9012\u5f52`", "\u7b80\u5355", ""], "md_table_row_en": ["[0563](https://leetcode.com/problems/binary-tree-tilt)", "[Binary Tree Tilt](/solution/0500-0599/0563.Binary%20Tree%20Tilt/README_EN.md)", "`Tree`,`Depth-first Search`,`Recursion`", "Easy", ""]}, {"question_id": "0562", "frontend_question_id": "0562", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/longest-line-of-consecutive-one-in-matrix", "url_en": "https://leetcode.com/problems/longest-line-of-consecutive-one-in-matrix", "relative_path_cn": "/solution/0500-0599/0562.Longest%20Line%20of%20Consecutive%20One%20in%20Matrix/README.md", "relative_path_en": "/solution/0500-0599/0562.Longest%20Line%20of%20Consecutive%20One%20in%20Matrix/README_EN.md", "title_cn": "\u77e9\u9635\u4e2d\u6700\u957f\u7684\u8fde\u7eed1\u7ebf\u6bb5", "title_en": "Longest Line of Consecutive One in Matrix", "question_title_slug": "longest-line-of-consecutive-one-in-matrix", "content_en": "

    Given an m x n binary matrix mat, return the length of the longest line of consecutive one in the matrix.

    \r\n\r\n

    The line could be horizontal, vertical, diagonal, or anti-diagonal.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\"\"\r\n
    \r\nInput: mat = [[0,1,1,0],[0,1,1,0],[0,0,0,1]]\r\nOutput: 3\r\n
    \r\n\r\n

    Example 2:

    \r\n\"\"\r\n
    \r\nInput: mat = [[1,1,1,1],[0,1,1,0],[0,0,0,1]]\r\nOutput: 4\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • m == mat.length
    • \r\n\t
    • n == mat[i].length
    • \r\n\t
    • 1 <= m, n <= 104
    • \r\n\t
    • 1 <= m * n <= 104
    • \r\n\t
    • mat[i][j] is either 0 or 1.
    • \r\n
    ", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a01\u77e9\u9635 M\uff0c\u627e\u5230\u77e9\u9635\u4e2d\u6700\u957f\u7684\u8fde\u7eed1\u7ebf\u6bb5\u3002\u8fd9\u6761\u7ebf\u6bb5\u53ef\u4ee5\u662f\u6c34\u5e73\u7684\u3001\u5782\u76f4\u7684\u3001\u5bf9\u89d2\u7ebf\u7684\u6216\u8005\u53cd\u5bf9\u89d2\u7ebf\u7684\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165:\n[[0,1,1,0],\n [0,1,1,0],\n [0,0,0,1]]\n\u8f93\u51fa: 3\n
    \n\n

    \u63d0\u793a: \u7ed9\u5b9a\u77e9\u9635\u4e2d\u7684\u5143\u7d20\u6570\u91cf\u4e0d\u4f1a\u8d85\u8fc7 10,000\u3002

    \n", "tags_en": ["Array", "Dynamic Programming"], "tags_cn": ["\u6570\u7ec4", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int longestLine(vector>& mat) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int longestLine(int[][] mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestLine(self, mat):\n \"\"\"\n :type mat: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestLine(self, mat: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint longestLine(int** mat, int matSize, int* matColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LongestLine(int[][] mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} mat\n * @return {number}\n */\nvar longestLine = function(mat) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} mat\n# @return {Integer}\ndef longest_line(mat)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestLine(_ mat: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestLine(mat [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestLine(mat: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestLine(mat: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_line(mat: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $mat\n * @return Integer\n */\n function longestLine($mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestLine(mat: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-line mat)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0562](https://leetcode-cn.com/problems/longest-line-of-consecutive-one-in-matrix)", "[\u77e9\u9635\u4e2d\u6700\u957f\u7684\u8fde\u7eed1\u7ebf\u6bb5](/solution/0500-0599/0562.Longest%20Line%20of%20Consecutive%20One%20in%20Matrix/README.md)", "`\u6570\u7ec4`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0562](https://leetcode.com/problems/longest-line-of-consecutive-one-in-matrix)", "[Longest Line of Consecutive One in Matrix](/solution/0500-0599/0562.Longest%20Line%20of%20Consecutive%20One%20in%20Matrix/README_EN.md)", "`Array`,`Dynamic Programming`", "Medium", "\ud83d\udd12"]}, {"question_id": "0561", "frontend_question_id": "0561", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/array-partition-i", "url_en": "https://leetcode.com/problems/array-partition-i", "relative_path_cn": "/solution/0500-0599/0561.Array%20Partition%20I/README.md", "relative_path_en": "/solution/0500-0599/0561.Array%20Partition%20I/README_EN.md", "title_cn": "\u6570\u7ec4\u62c6\u5206 I", "title_en": "Array Partition I", "question_title_slug": "array-partition-i", "content_en": "

    Given an integer array nums of 2n integers, group these integers into n pairs (a1, b1), (a2, b2), ..., (an, bn) such that the sum of min(ai, bi) for all i is maximized. Return the maximized sum.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,4,3,2]\nOutput: 4\nExplanation: All possible pairings (ignoring the ordering of elements) are:\n1. (1, 4), (2, 3) -> min(1, 4) + min(2, 3) = 1 + 2 = 3\n2. (1, 3), (2, 4) -> min(1, 3) + min(2, 4) = 1 + 2 = 3\n3. (1, 2), (3, 4) -> min(1, 2) + min(3, 4) = 1 + 3 = 4\nSo the maximum possible sum is 4.
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [6,2,6,5,1,2]\nOutput: 9\nExplanation: The optimal pairing is (2, 1), (2, 5), (6, 6). min(2, 1) + min(2, 5) + min(6, 6) = 1 + 2 + 6 = 9.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 104
    • \n\t
    • nums.length == 2 * n
    • \n\t
    • -104 <= nums[i] <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u957f\u5ea6\u4e3a\u00a02n\u00a0\u7684\u6574\u6570\u6570\u7ec4 nums \uff0c\u4f60\u7684\u4efb\u52a1\u662f\u5c06\u8fd9\u4e9b\u6570\u5206\u6210\u00a0n \u5bf9, \u4f8b\u5982 (a1, b1), (a2, b2), ..., (an, bn) \uff0c\u4f7f\u5f97\u4ece 1 \u5230\u00a0n \u7684 min(ai, bi) \u603b\u548c\u6700\u5927\u3002

    \n\n

    \u8fd4\u56de\u8be5 \u6700\u5927\u603b\u548c \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,4,3,2]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u6240\u6709\u53ef\u80fd\u7684\u5206\u6cd5\uff08\u5ffd\u7565\u5143\u7d20\u987a\u5e8f\uff09\u4e3a\uff1a\n1. (1, 4), (2, 3) -> min(1, 4) + min(2, 3) = 1 + 2 = 3\n2. (1, 3), (2, 4) -> min(1, 3) + min(2, 4) = 1 + 2 = 3\n3. (1, 2), (3, 4) -> min(1, 2) + min(3, 4) = 1 + 3 = 4\n\u6240\u4ee5\u6700\u5927\u603b\u548c\u4e3a 4
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [6,2,6,5,1,2]\n\u8f93\u51fa\uff1a9\n\u89e3\u91ca\uff1a\u6700\u4f18\u7684\u5206\u6cd5\u4e3a (2, 1), (2, 5), (6, 6). min(2, 1) + min(2, 5) + min(6, 6) = 1 + 2 + 6 = 9\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 104
    • \n\t
    • nums.length == 2 * n
    • \n\t
    • -104 <= nums[i] <= 104
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int arrayPairSum(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int arrayPairSum(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def arrayPairSum(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def arrayPairSum(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint arrayPairSum(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ArrayPairSum(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar arrayPairSum = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef array_pair_sum(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func arrayPairSum(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func arrayPairSum(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def arrayPairSum(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun arrayPairSum(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn array_pair_sum(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function arrayPairSum($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function arrayPairSum(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (array-pair-sum nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0561](https://leetcode-cn.com/problems/array-partition-i)", "[\u6570\u7ec4\u62c6\u5206 I](/solution/0500-0599/0561.Array%20Partition%20I/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0561](https://leetcode.com/problems/array-partition-i)", "[Array Partition I](/solution/0500-0599/0561.Array%20Partition%20I/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0560", "frontend_question_id": "0560", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/subarray-sum-equals-k", "url_en": "https://leetcode.com/problems/subarray-sum-equals-k", "relative_path_cn": "/solution/0500-0599/0560.Subarray%20Sum%20Equals%20K/README.md", "relative_path_en": "/solution/0500-0599/0560.Subarray%20Sum%20Equals%20K/README_EN.md", "title_cn": "\u548c\u4e3aK\u7684\u5b50\u6570\u7ec4", "title_en": "Subarray Sum Equals K", "question_title_slug": "subarray-sum-equals-k", "content_en": "

    Given an array of integers nums and an integer k, return the total number of continuous subarrays whose sum equals to k.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [1,1,1], k = 2\nOutput: 2\n

    Example 2:

    \n
    Input: nums = [1,2,3], k = 3\nOutput: 2\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 2 * 104
    • \n\t
    • -1000 <= nums[i] <= 1000
    • \n\t
    • -107 <= k <= 107
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u548c\u4e00\u4e2a\u6574\u6570 k\uff0c\u4f60\u9700\u8981\u627e\u5230\u8be5\u6570\u7ec4\u4e2d\u548c\u4e3a \u7684\u8fde\u7eed\u7684\u5b50\u6570\u7ec4\u7684\u4e2a\u6570\u3002

    \n\n

    \u793a\u4f8b 1 :

    \n\n
    \n\u8f93\u5165:nums = [1,1,1], k = 2\n\u8f93\u51fa: 2 , [1,1] \u4e0e [1,1] \u4e3a\u4e24\u79cd\u4e0d\u540c\u7684\u60c5\u51b5\u3002\n
    \n\n

    \u8bf4\u660e :

    \n\n
      \n\t
    1. \u6570\u7ec4\u7684\u957f\u5ea6\u4e3a [1, 20,000]\u3002
    2. \n\t
    3. \u6570\u7ec4\u4e2d\u5143\u7d20\u7684\u8303\u56f4\u662f [-1000, 1000] \uff0c\u4e14\u6574\u6570 \u7684\u8303\u56f4\u662f [-1e7, 1e7]\u3002
    4. \n
    \n", "tags_en": ["Array", "Hash Table"], "tags_cn": ["\u6570\u7ec4", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int subarraySum(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int subarraySum(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def subarraySum(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def subarraySum(self, nums: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint subarraySum(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SubarraySum(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar subarraySum = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef subarray_sum(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func subarraySum(_ nums: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func subarraySum(nums []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def subarraySum(nums: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun subarraySum(nums: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn subarray_sum(nums: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer\n */\n function subarraySum($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function subarraySum(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (subarray-sum nums k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0560](https://leetcode-cn.com/problems/subarray-sum-equals-k)", "[\u548c\u4e3aK\u7684\u5b50\u6570\u7ec4](/solution/0500-0599/0560.Subarray%20Sum%20Equals%20K/README.md)", "`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0560](https://leetcode.com/problems/subarray-sum-equals-k)", "[Subarray Sum Equals K](/solution/0500-0599/0560.Subarray%20Sum%20Equals%20K/README_EN.md)", "`Array`,`Hash Table`", "Medium", ""]}, {"question_id": "0557", "frontend_question_id": "0557", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reverse-words-in-a-string-iii", "url_en": "https://leetcode.com/problems/reverse-words-in-a-string-iii", "relative_path_cn": "/solution/0500-0599/0557.Reverse%20Words%20in%20a%20String%20III/README.md", "relative_path_en": "/solution/0500-0599/0557.Reverse%20Words%20in%20a%20String%20III/README_EN.md", "title_cn": "\u53cd\u8f6c\u5b57\u7b26\u4e32\u4e2d\u7684\u5355\u8bcd III", "title_en": "Reverse Words in a String III", "question_title_slug": "reverse-words-in-a-string-iii", "content_en": "

    Given a string s, reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.

    \n\n

     

    \n

    Example 1:

    \n
    Input: s = \"Let's take LeetCode contest\"\nOutput: \"s'teL ekat edoCteeL tsetnoc\"\n

    Example 2:

    \n
    Input: s = \"God Ding\"\nOutput: \"doG gniD\"\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 5 * 104
    • \n\t
    • s contains printable ASCII characters.
    • \n\t
    • s does not contain any leading or trailing spaces.
    • \n\t
    • There is at least one word in s.
    • \n\t
    • All the words in s are separated by a single space.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u4f60\u9700\u8981\u53cd\u8f6c\u5b57\u7b26\u4e32\u4e2d\u6bcf\u4e2a\u5355\u8bcd\u7684\u5b57\u7b26\u987a\u5e8f\uff0c\u540c\u65f6\u4ecd\u4fdd\u7559\u7a7a\u683c\u548c\u5355\u8bcd\u7684\u521d\u59cb\u987a\u5e8f\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1a"Let's take LeetCode contest"\n\u8f93\u51fa\uff1a"s'teL ekat edoCteeL tsetnoc"\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u5728\u5b57\u7b26\u4e32\u4e2d\uff0c\u6bcf\u4e2a\u5355\u8bcd\u7531\u5355\u4e2a\u7a7a\u683c\u5206\u9694\uff0c\u5e76\u4e14\u5b57\u7b26\u4e32\u4e2d\u4e0d\u4f1a\u6709\u4efb\u4f55\u989d\u5916\u7684\u7a7a\u683c\u3002
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string reverseWords(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String reverseWords(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def reverseWords(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def reverseWords(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * reverseWords(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ReverseWords(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar reverseWords = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef reverse_words(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func reverseWords(_ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func reverseWords(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def reverseWords(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun reverseWords(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn reverse_words(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function reverseWords($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function reverseWords(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (reverse-words s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0557](https://leetcode-cn.com/problems/reverse-words-in-a-string-iii)", "[\u53cd\u8f6c\u5b57\u7b26\u4e32\u4e2d\u7684\u5355\u8bcd III](/solution/0500-0599/0557.Reverse%20Words%20in%20a%20String%20III/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0557](https://leetcode.com/problems/reverse-words-in-a-string-iii)", "[Reverse Words in a String III](/solution/0500-0599/0557.Reverse%20Words%20in%20a%20String%20III/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "0556", "frontend_question_id": "0556", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/next-greater-element-iii", "url_en": "https://leetcode.com/problems/next-greater-element-iii", "relative_path_cn": "/solution/0500-0599/0556.Next%20Greater%20Element%20III/README.md", "relative_path_en": "/solution/0500-0599/0556.Next%20Greater%20Element%20III/README_EN.md", "title_cn": "\u4e0b\u4e00\u4e2a\u66f4\u5927\u5143\u7d20 III", "title_en": "Next Greater Element III", "question_title_slug": "next-greater-element-iii", "content_en": "

    Given a positive integer n, find the smallest integer which has exactly the same digits existing in the integer n and is greater in value than n. If no such positive integer exists, return -1.

    \n\n

    Note that the returned integer should fit in 32-bit integer, if there is a valid answer but it does not fit in 32-bit integer, return -1.

    \n\n

     

    \n

    Example 1:

    \n
    Input: n = 12\nOutput: 21\n

    Example 2:

    \n
    Input: n = 21\nOutput: -1\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 231 - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6b63\u6574\u6570\u00a0n \uff0c\u8bf7\u4f60\u627e\u51fa\u7b26\u5408\u6761\u4ef6\u7684\u6700\u5c0f\u6574\u6570\uff0c\u5176\u7531\u91cd\u65b0\u6392\u5217 n\u00a0\u4e2d\u5b58\u5728\u7684\u6bcf\u4f4d\u6570\u5b57\u7ec4\u6210\uff0c\u5e76\u4e14\u5176\u503c\u5927\u4e8e n \u3002\u5982\u679c\u4e0d\u5b58\u5728\u8fd9\u6837\u7684\u6b63\u6574\u6570\uff0c\u5219\u8fd4\u56de -1 \u3002

    \n\n

    \u6ce8\u610f \uff0c\u8fd4\u56de\u7684\u6574\u6570\u5e94\u5f53\u662f\u4e00\u4e2a 32 \u4f4d\u6574\u6570 \uff0c\u5982\u679c\u5b58\u5728\u6ee1\u8db3\u9898\u610f\u7684\u7b54\u6848\uff0c\u4f46\u4e0d\u662f 32 \u4f4d\u6574\u6570 \uff0c\u540c\u6837\u8fd4\u56de -1 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 12\n\u8f93\u51fa\uff1a21\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 21\n\u8f93\u51fa\uff1a-1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 231 - 1
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int nextGreaterElement(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int nextGreaterElement(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def nextGreaterElement(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def nextGreaterElement(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint nextGreaterElement(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NextGreaterElement(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar nextGreaterElement = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef next_greater_element(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func nextGreaterElement(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func nextGreaterElement(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def nextGreaterElement(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun nextGreaterElement(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn next_greater_element(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function nextGreaterElement($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function nextGreaterElement(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (next-greater-element n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0556](https://leetcode-cn.com/problems/next-greater-element-iii)", "[\u4e0b\u4e00\u4e2a\u66f4\u5927\u5143\u7d20 III](/solution/0500-0599/0556.Next%20Greater%20Element%20III/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0556](https://leetcode.com/problems/next-greater-element-iii)", "[Next Greater Element III](/solution/0500-0599/0556.Next%20Greater%20Element%20III/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "0555", "frontend_question_id": "0555", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/split-concatenated-strings", "url_en": "https://leetcode.com/problems/split-concatenated-strings", "relative_path_cn": "/solution/0500-0599/0555.Split%20Concatenated%20Strings/README.md", "relative_path_en": "/solution/0500-0599/0555.Split%20Concatenated%20Strings/README_EN.md", "title_cn": "\u5206\u5272\u8fde\u63a5\u5b57\u7b26\u4e32", "title_en": "Split Concatenated Strings", "question_title_slug": "split-concatenated-strings", "content_en": "

    You are given an array of strings strs. You could concatenate these strings together into a loop, where for each string, you could choose to reverse it or not. Among all the possible loops

    \n\n

    Return the lexicographically largest string after cutting the loop, which will make the looped string into a regular one.

    \n\n

    Specifically, to find the lexicographically largest string, you need to experience two phases:

    \n\n
      \n\t
    1. Concatenate all the strings into a loop, where you can reverse some strings or not and connect them in the same order as given.
    2. \n\t
    3. Cut and make one breakpoint in any place of the loop, which will make the looped string into a regular one starting from the character at the cutpoint.
    4. \n
    \n\n

    And your job is to find the lexicographically largest one among all the possible regular strings.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: strs = ["abc","xyz"]\nOutput: "zyxcba"\nExplanation: You can get the looped string "-abcxyz-", "-abczyx-", "-cbaxyz-", "-cbazyx-", where '-' represents the looped status. \nThe answer string came from the fourth looped one, where you could cut from the middle character 'a' and get "zyxcba".\n
    \n\n

    Example 2:

    \n\n
    \nInput: strs = ["abc"]\nOutput: "cba"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= strs.length <= 1000
    • \n\t
    • 1 <= strs[i].length <= 1000
    • \n\t
    • 1 <= sum(strs[i].length) <= 1000
    • \n\t
    • strs[i] consists of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\u5217\u8868\uff0c\u4f60\u53ef\u4ee5\u5c06\u8fd9\u4e9b\u5b57\u7b26\u4e32\u8fde\u63a5\u6210\u4e00\u4e2a\u5faa\u73af\u5b57\u7b26\u4e32\uff0c\u5bf9\u4e8e\u6bcf\u4e2a\u5b57\u7b26\u4e32\uff0c\u4f60\u53ef\u4ee5\u9009\u62e9\u662f\u5426\u7ffb\u8f6c\u5b83\u3002\u5728\u6240\u6709\u53ef\u80fd\u7684\u5faa\u73af\u5b57\u7b26\u4e32\u4e2d\uff0c\u4f60\u9700\u8981\u5206\u5272\u5faa\u73af\u5b57\u7b26\u4e32\uff08\u8fd9\u5c06\u4f7f\u5faa\u73af\u5b57\u7b26\u4e32\u53d8\u6210\u4e00\u4e2a\u5e38\u89c4\u7684\u5b57\u7b26\u4e32\uff09\uff0c\u7136\u540e\u627e\u5230\u5b57\u5178\u5e8f\u6700\u5927\u7684\u5b57\u7b26\u4e32\u3002

    \n\n

    \u5177\u4f53\u6765\u8bf4\uff0c\u8981\u627e\u5230\u5b57\u5178\u5e8f\u6700\u5927\u7684\u5b57\u7b26\u4e32\uff0c\u4f60\u9700\u8981\u7ecf\u5386\u4e24\u4e2a\u9636\u6bb5\uff1a

    \n\n
      \n\t
    1. \u5c06\u6240\u6709\u5b57\u7b26\u4e32\u8fde\u63a5\u6210\u4e00\u4e2a\u5faa\u73af\u5b57\u7b26\u4e32\uff0c\u4f60\u53ef\u4ee5\u9009\u62e9\u662f\u5426\u7ffb\u8f6c\u67d0\u4e9b\u5b57\u7b26\u4e32\uff0c\u5e76\u6309\u7167\u7ed9\u5b9a\u7684\u987a\u5e8f\u8fde\u63a5\u5b83\u4eec\u3002
    2. \n\t
    3. \u5728\u5faa\u73af\u5b57\u7b26\u4e32\u7684\u67d0\u4e2a\u4f4d\u7f6e\u5206\u5272\u5b83\uff0c\u8fd9\u5c06\u4f7f\u5faa\u73af\u5b57\u7b26\u4e32\u4ece\u5206\u5272\u70b9\u53d8\u6210\u4e00\u4e2a\u5e38\u89c4\u7684\u5b57\u7b26\u4e32\u3002
    4. \n
    \n\n

    \u4f60\u7684\u5de5\u4f5c\u662f\u5728\u6240\u6709\u53ef\u80fd\u7684\u5e38\u89c4\u5b57\u7b26\u4e32\u4e2d\u627e\u5230\u5b57\u5178\u5e8f\u6700\u5927\u7684\u4e00\u4e2a\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: "abc", "xyz"\n\u8f93\u51fa: "zyxcba"\n\u89e3\u91ca: \u4f60\u53ef\u4ee5\u5f97\u5230\u5faa\u73af\u5b57\u7b26\u4e32 "-abcxyz-", "-abczyx-", "-cbaxyz-", "-cbazyx-"\uff0c\n\u5176\u4e2d '-' \u4ee3\u8868\u5faa\u73af\u72b6\u6001\u3002 \n\u7b54\u6848\u5b57\u7b26\u4e32\u6765\u81ea\u7b2c\u56db\u4e2a\u5faa\u73af\u5b57\u7b26\u4e32\uff0c \n\u4f60\u53ef\u4ee5\u4ece\u4e2d\u95f4\u5b57\u7b26 'a' \u5206\u5272\u5f00\u7136\u540e\u5f97\u5230 "zyxcba"\u3002\n
    \n\n

     

    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u8f93\u5165\u5b57\u7b26\u4e32\u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd\u3002
    2. \n\t
    3. \u6240\u6709\u5b57\u7b26\u4e32\u7684\u603b\u957f\u5ea6\u4e0d\u4f1a\u8d85\u8fc7 1,000\u3002
    4. \n
    \n\n

     

    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string splitLoopedString(vector& strs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String splitLoopedString(String[] strs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def splitLoopedString(self, strs):\n \"\"\"\n :type strs: List[str]\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def splitLoopedString(self, strs: List[str]) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * splitLoopedString(char ** strs, int strsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string SplitLoopedString(string[] strs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} strs\n * @return {string}\n */\nvar splitLoopedString = function(strs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} strs\n# @return {String}\ndef split_looped_string(strs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func splitLoopedString(_ strs: [String]) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func splitLoopedString(strs []string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def splitLoopedString(strs: Array[String]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun splitLoopedString(strs: Array): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn split_looped_string(strs: Vec) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $strs\n * @return String\n */\n function splitLoopedString($strs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function splitLoopedString(strs: string[]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (split-looped-string strs)\n (-> (listof string?) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0555](https://leetcode-cn.com/problems/split-concatenated-strings)", "[\u5206\u5272\u8fde\u63a5\u5b57\u7b26\u4e32](/solution/0500-0599/0555.Split%20Concatenated%20Strings/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0555](https://leetcode.com/problems/split-concatenated-strings)", "[Split Concatenated Strings](/solution/0500-0599/0555.Split%20Concatenated%20Strings/README_EN.md)", "`String`", "Medium", "\ud83d\udd12"]}, {"question_id": "0554", "frontend_question_id": "0554", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/brick-wall", "url_en": "https://leetcode.com/problems/brick-wall", "relative_path_cn": "/solution/0500-0599/0554.Brick%20Wall/README.md", "relative_path_en": "/solution/0500-0599/0554.Brick%20Wall/README_EN.md", "title_cn": "\u7816\u5899", "title_en": "Brick Wall", "question_title_slug": "brick-wall", "content_en": "

    There is a rectangular brick wall in front of you with n rows of bricks. The ith row has some number of bricks each of the same height (i.e., one unit) but they can be of different widths. The total width of each row is the same.

    \n\n

    Draw a vertical line from the top to the bottom and cross the least bricks. If your line goes through the edge of a brick, then the brick is not considered as crossed. You cannot draw a line just along one of the two vertical edges of the wall, in which case the line will obviously cross no bricks.

    \n\n

    Given the 2D array wall that contains the information about the wall, return the minimum number of crossed bricks after drawing such a vertical line.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: wall = [[1,2,2,1],[3,1,2],[1,3,2],[2,4],[3,1,2],[1,3,1,1]]\nOutput: 2\n
    \n\n

    Example 2:

    \n\n
    \nInput: wall = [[1],[1],[1]]\nOutput: 3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == wall.length
    • \n\t
    • 1 <= n <= 104
    • \n\t
    • 1 <= wall[i].length <= 104
    • \n\t
    • 1 <= sum(wall[i].length) <= 2 * 104
    • \n\t
    • sum(wall[i]) is the same for each row i.
    • \n\t
    • 1 <= wall[i][j] <= 231 - 1
    • \n
    \n", "content_cn": "

    \u4f60\u7684\u9762\u524d\u6709\u4e00\u5835\u77e9\u5f62\u7684\u3001\u7531 n \u884c\u7816\u5757\u7ec4\u6210\u7684\u7816\u5899\u3002\u8fd9\u4e9b\u7816\u5757\u9ad8\u5ea6\u76f8\u540c\uff08\u4e5f\u5c31\u662f\u4e00\u4e2a\u5355\u4f4d\u9ad8\uff09\u4f46\u662f\u5bbd\u5ea6\u4e0d\u540c\u3002\u6bcf\u4e00\u884c\u7816\u5757\u7684\u5bbd\u5ea6\u4e4b\u548c\u76f8\u7b49\u3002

    \n\n

    \u4f60\u73b0\u5728\u8981\u753b\u4e00\u6761 \u81ea\u9876\u5411\u4e0b \u7684\u3001\u7a7f\u8fc7 \u6700\u5c11 \u7816\u5757\u7684\u5782\u7ebf\u3002\u5982\u679c\u4f60\u753b\u7684\u7ebf\u53ea\u662f\u4ece\u7816\u5757\u7684\u8fb9\u7f18\u7ecf\u8fc7\uff0c\u5c31\u4e0d\u7b97\u7a7f\u8fc7\u8fd9\u5757\u7816\u3002\u4f60\u4e0d\u80fd\u6cbf\u7740\u5899\u7684\u4e24\u4e2a\u5782\u76f4\u8fb9\u7f18\u4e4b\u4e00\u753b\u7ebf\uff0c\u8fd9\u6837\u663e\u7136\u662f\u6ca1\u6709\u7a7f\u8fc7\u4e00\u5757\u7816\u7684\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u4e8c\u7ef4\u6570\u7ec4 wall \uff0c\u8be5\u6570\u7ec4\u5305\u542b\u8fd9\u5835\u5899\u7684\u76f8\u5173\u4fe1\u606f\u3002\u5176\u4e2d\uff0cwall[i] \u662f\u4e00\u4e2a\u4ee3\u8868\u4ece\u5de6\u81f3\u53f3\u6bcf\u5757\u7816\u7684\u5bbd\u5ea6\u7684\u6570\u7ec4\u3002\u4f60\u9700\u8981\u627e\u51fa\u600e\u6837\u753b\u624d\u80fd\u4f7f\u8fd9\u6761\u7ebf \u7a7f\u8fc7\u7684\u7816\u5757\u6570\u91cf\u6700\u5c11 \uff0c\u5e76\u4e14\u8fd4\u56de \u7a7f\u8fc7\u7684\u7816\u5757\u6570\u91cf \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1awall = [[1,2,2,1],[3,1,2],[1,3,2],[2,4],[3,1,2],[1,3,1,1]]\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1awall = [[1],[1],[1]]\n\u8f93\u51fa\uff1a3\n
    \n\u00a0\n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == wall.length
    • \n\t
    • 1 <= n <= 104
    • \n\t
    • 1 <= wall[i].length <= 104
    • \n\t
    • 1 <= sum(wall[i].length) <= 2 * 104
    • \n\t
    • \u5bf9\u4e8e\u6bcf\u4e00\u884c i \uff0csum(wall[i]) \u662f\u76f8\u540c\u7684
    • \n\t
    • 1 <= wall[i][j] <= 231 - 1
    • \n
    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int leastBricks(vector>& wall) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int leastBricks(List> wall) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def leastBricks(self, wall):\n \"\"\"\n :type wall: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def leastBricks(self, wall: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint leastBricks(int** wall, int wallSize, int* wallColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LeastBricks(IList> wall) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} wall\n * @return {number}\n */\nvar leastBricks = function(wall) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} wall\n# @return {Integer}\ndef least_bricks(wall)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func leastBricks(_ wall: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func leastBricks(wall [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def leastBricks(wall: List[List[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun leastBricks(wall: List>): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn least_bricks(wall: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $wall\n * @return Integer\n */\n function leastBricks($wall) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function leastBricks(wall: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (least-bricks wall)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0554](https://leetcode-cn.com/problems/brick-wall)", "[\u7816\u5899](/solution/0500-0599/0554.Brick%20Wall/README.md)", "`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0554](https://leetcode.com/problems/brick-wall)", "[Brick Wall](/solution/0500-0599/0554.Brick%20Wall/README_EN.md)", "`Hash Table`", "Medium", ""]}, {"question_id": "0553", "frontend_question_id": "0553", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/optimal-division", "url_en": "https://leetcode.com/problems/optimal-division", "relative_path_cn": "/solution/0500-0599/0553.Optimal%20Division/README.md", "relative_path_en": "/solution/0500-0599/0553.Optimal%20Division/README_EN.md", "title_cn": "\u6700\u4f18\u9664\u6cd5", "title_en": "Optimal Division", "question_title_slug": "optimal-division", "content_en": "

    You are given an integer array nums. The adjacent integers in nums will perform the float division.

    \n\n
      \n\t
    • For example, for nums = [2,3,4], we will evaluate the expression "2/3/4".
    • \n
    \n\n

    However, you can add any number of parenthesis at any position to change the priority of operations. You want to add these parentheses such the value of the expression after the evaluation is maximum.

    \n\n

    Return the corresponding expression that has the maximum value in string format.

    \n\n

    Note: your expression should not contain redundant parenthesis.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1000,100,10,2]\nOutput: "1000/(100/10/2)"\nExplanation:\n1000/(100/10/2) = 1000/((100/10)/2) = 200\nHowever, the bold parenthesis in "1000/((100/10)/2)" are redundant, since they don't influence the operation priority. So you should return "1000/(100/10/2)".\nOther cases:\n1000/(100/10)/2 = 50\n1000/(100/(10/2)) = 50\n1000/100/10/2 = 0.5\n1000/100/(10/2) = 2\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [2,3,4]\nOutput: "2/(3/4)"\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [2]\nOutput: "2"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 10
    • \n\t
    • 2 <= nums[i] <= 1000
    • \n\t
    • There is only one optimal division for the given iput.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u7ec4\u6b63\u6574\u6570\uff0c\u76f8\u90bb\u7684\u6574\u6570\u4e4b\u95f4\u5c06\u4f1a\u8fdb\u884c\u6d6e\u70b9\u9664\u6cd5\u64cd\u4f5c\u3002\u4f8b\u5982\uff0c [2,3,4] -> 2 / 3 / 4 \u3002

    \n\n

    \u4f46\u662f\uff0c\u4f60\u53ef\u4ee5\u5728\u4efb\u610f\u4f4d\u7f6e\u6dfb\u52a0\u4efb\u610f\u6570\u76ee\u7684\u62ec\u53f7\uff0c\u6765\u6539\u53d8\u7b97\u6570\u7684\u4f18\u5148\u7ea7\u3002\u4f60\u9700\u8981\u627e\u51fa\u600e\u4e48\u6dfb\u52a0\u62ec\u53f7\uff0c\u624d\u80fd\u5f97\u5230\u6700\u5927\u7684\u7ed3\u679c\uff0c\u5e76\u4e14\u8fd4\u56de\u76f8\u5e94\u7684\u5b57\u7b26\u4e32\u683c\u5f0f\u7684\u8868\u8fbe\u5f0f\u3002\u4f60\u7684\u8868\u8fbe\u5f0f\u4e0d\u5e94\u8be5\u542b\u6709\u5197\u4f59\u7684\u62ec\u53f7\u3002

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165: [1000,100,10,2]\n\u8f93\u51fa: "1000/(100/10/2)"\n\u89e3\u91ca:\n1000/(100/10/2) = 1000/((100/10)/2) = 200\n\u4f46\u662f\uff0c\u4ee5\u4e0b\u52a0\u7c97\u7684\u62ec\u53f7 "1000/((100/10)/2)" \u662f\u5197\u4f59\u7684\uff0c\n\u56e0\u4e3a\u4ed6\u4eec\u5e76\u4e0d\u5f71\u54cd\u64cd\u4f5c\u7684\u4f18\u5148\u7ea7\uff0c\u6240\u4ee5\u4f60\u9700\u8981\u8fd4\u56de "1000/(100/10/2)"\u3002\n\n\u5176\u4ed6\u7528\u4f8b:\n1000/(100/10)/2 = 50\n1000/(100/(10/2)) = 50\n1000/100/10/2 = 0.5\n1000/100/(10/2) = 2\n
    \n\n

    \u8bf4\u660e:

    \n\n
      \n\t
    1. \u8f93\u5165\u6570\u7ec4\u7684\u957f\u5ea6\u5728 [1, 10] \u4e4b\u95f4\u3002
    2. \n\t
    3. \u6570\u7ec4\u4e2d\u6bcf\u4e2a\u5143\u7d20\u7684\u5927\u5c0f\u90fd\u5728 [2, 1000] \u4e4b\u95f4\u3002
    4. \n\t
    5. \u6bcf\u4e2a\u6d4b\u8bd5\u7528\u4f8b\u53ea\u6709\u4e00\u4e2a\u6700\u4f18\u9664\u6cd5\u89e3\u3002
    6. \n
    \n", "tags_en": ["Math", "String"], "tags_cn": ["\u6570\u5b66", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string optimalDivision(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String optimalDivision(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def optimalDivision(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def optimalDivision(self, nums: List[int]) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * optimalDivision(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string OptimalDivision(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {string}\n */\nvar optimalDivision = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {String}\ndef optimal_division(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func optimalDivision(_ nums: [Int]) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func optimalDivision(nums []int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def optimalDivision(nums: Array[Int]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun optimalDivision(nums: IntArray): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn optimal_division(nums: Vec) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return String\n */\n function optimalDivision($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function optimalDivision(nums: number[]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (optimal-division nums)\n (-> (listof exact-integer?) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0553](https://leetcode-cn.com/problems/optimal-division)", "[\u6700\u4f18\u9664\u6cd5](/solution/0500-0599/0553.Optimal%20Division/README.md)", "`\u6570\u5b66`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0553](https://leetcode.com/problems/optimal-division)", "[Optimal Division](/solution/0500-0599/0553.Optimal%20Division/README_EN.md)", "`Math`,`String`", "Medium", ""]}, {"question_id": "0552", "frontend_question_id": "0552", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/student-attendance-record-ii", "url_en": "https://leetcode.com/problems/student-attendance-record-ii", "relative_path_cn": "/solution/0500-0599/0552.Student%20Attendance%20Record%20II/README.md", "relative_path_en": "/solution/0500-0599/0552.Student%20Attendance%20Record%20II/README_EN.md", "title_cn": "\u5b66\u751f\u51fa\u52e4\u8bb0\u5f55 II", "title_en": "Student Attendance Record II", "question_title_slug": "student-attendance-record-ii", "content_en": "

    An attendance record for a student can be represented as a string where each character signifies whether the student was absent, late, or present on that day. The record only contains the following three characters:

    \n\n
      \n\t
    • 'A': Absent.
    • \n\t
    • 'L': Late.
    • \n\t
    • 'P': Present.
    • \n
    \n\n

    Any student is eligible for an attendance award if they meet both of the following criteria:

    \n\n
      \n\t
    • The student was absent ('A') for strictly fewer than 2 days total.
    • \n\t
    • The student was never late ('L') for 3 or more consecutive days.
    • \n
    \n\n

    Given an integer n, return the number of possible attendance records of length n that make a student eligible for an attendance award. The answer may be very large, so return it modulo 109 + 7.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 2\nOutput: 8\nExplanation: There are 8 records with length 2 that are eligible for an award:\n"PP", "AP", "PA", "LP", "PL", "AL", "LA", "LL"\nOnly "AA" is not eligible because there are 2 absences (there need to be fewer than 2).\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 1\nOutput: 3\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 10101\nOutput: 183236316\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6b63\u6574\u6570 n\uff0c\u8fd4\u56de\u957f\u5ea6\u4e3a n \u7684\u6240\u6709\u53ef\u88ab\u89c6\u4e3a\u53ef\u5956\u52b1\u7684\u51fa\u52e4\u8bb0\u5f55\u7684\u6570\u91cf\u3002 \u7b54\u6848\u53ef\u80fd\u975e\u5e38\u5927\uff0c\u4f60\u53ea\u9700\u8fd4\u56de\u7ed3\u679cmod 109 + 7\u7684\u503c\u3002

    \n\n

    \u5b66\u751f\u51fa\u52e4\u8bb0\u5f55\u662f\u53ea\u5305\u542b\u4ee5\u4e0b\u4e09\u4e2a\u5b57\u7b26\u7684\u5b57\u7b26\u4e32\uff1a

    \n\n
      \n\t
    1. 'A' : Absent\uff0c\u7f3a\u52e4
    2. \n\t
    3. 'L' : Late\uff0c\u8fdf\u5230
    4. \n\t
    5. 'P' : Present\uff0c\u5230\u573a
    6. \n
    \n\n

    \u5982\u679c\u8bb0\u5f55\u4e0d\u5305\u542b\u591a\u4e8e\u4e00\u4e2a'A'\uff08\u7f3a\u52e4\uff09\u6216\u8d85\u8fc7\u4e24\u4e2a\u8fde\u7eed\u7684'L'\uff08\u8fdf\u5230\uff09\uff0c\u5219\u8be5\u8bb0\u5f55\u88ab\u89c6\u4e3a\u53ef\u5956\u52b1\u7684\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: n = 2\n\u8f93\u51fa: 8 \n\u89e3\u91ca\uff1a\n\u67098\u4e2a\u957f\u5ea6\u4e3a2\u7684\u8bb0\u5f55\u5c06\u88ab\u89c6\u4e3a\u53ef\u5956\u52b1\uff1a\n"PP" , "AP", "PA", "LP", "PL", "AL", "LA", "LL"\n\u53ea\u6709"AA"\u4e0d\u4f1a\u88ab\u89c6\u4e3a\u53ef\u5956\u52b1\uff0c\u56e0\u4e3a\u7f3a\u52e4\u6b21\u6570\u8d85\u8fc7\u4e00\u6b21\u3002
    \n\n

    \u6ce8\u610f\uff1an \u7684\u503c\u4e0d\u4f1a\u8d85\u8fc7100000\u3002

    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int checkRecord(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int checkRecord(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def checkRecord(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def checkRecord(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint checkRecord(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CheckRecord(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar checkRecord = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef check_record(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func checkRecord(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func checkRecord(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def checkRecord(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun checkRecord(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn check_record(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function checkRecord($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function checkRecord(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (check-record n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0552](https://leetcode-cn.com/problems/student-attendance-record-ii)", "[\u5b66\u751f\u51fa\u52e4\u8bb0\u5f55 II](/solution/0500-0599/0552.Student%20Attendance%20Record%20II/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0552](https://leetcode.com/problems/student-attendance-record-ii)", "[Student Attendance Record II](/solution/0500-0599/0552.Student%20Attendance%20Record%20II/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "0551", "frontend_question_id": "0551", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/student-attendance-record-i", "url_en": "https://leetcode.com/problems/student-attendance-record-i", "relative_path_cn": "/solution/0500-0599/0551.Student%20Attendance%20Record%20I/README.md", "relative_path_en": "/solution/0500-0599/0551.Student%20Attendance%20Record%20I/README_EN.md", "title_cn": "\u5b66\u751f\u51fa\u52e4\u8bb0\u5f55 I", "title_en": "Student Attendance Record I", "question_title_slug": "student-attendance-record-i", "content_en": "

    You are given a string s representing an attendance record for a student where each character signifies whether the student was absent, late, or present on that day. The record only contains the following three characters:

    \n\n
      \n\t
    • 'A': Absent.
    • \n\t
    • 'L': Late.
    • \n\t
    • 'P': Present.
    • \n
    \n\n

    The student is eligible for an attendance award if they meet both of the following criteria:

    \n\n
      \n\t
    • The student was absent ('A') for strictly fewer than 2 days total.
    • \n\t
    • The student was never late ('L') for 3 or more consecutive days.
    • \n
    \n\n

    Return true if the student is eligible for an attendance award, or false otherwise.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "PPALLP"\nOutput: true\nExplanation: The student has fewer than 2 absences and was never late 3 or more consecutive days.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "PPALLL"\nOutput: false\nExplanation: The student was late 3 consecutive days in the last 3 days, so is not eligible for the award.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 1000
    • \n\t
    • s[i] is either 'A', 'L', or 'P'.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\u6765\u4ee3\u8868\u4e00\u4e2a\u5b66\u751f\u7684\u51fa\u52e4\u8bb0\u5f55\uff0c\u8fd9\u4e2a\u8bb0\u5f55\u4ec5\u5305\u542b\u4ee5\u4e0b\u4e09\u4e2a\u5b57\u7b26\uff1a

    \n\n
      \n\t
    1. 'A' : Absent\uff0c\u7f3a\u52e4
    2. \n\t
    3. 'L' : Late\uff0c\u8fdf\u5230
    4. \n\t
    5. 'P' : Present\uff0c\u5230\u573a
    6. \n
    \n\n

    \u5982\u679c\u4e00\u4e2a\u5b66\u751f\u7684\u51fa\u52e4\u8bb0\u5f55\u4e2d\u4e0d\u8d85\u8fc7\u4e00\u4e2a'A'(\u7f3a\u52e4)\u5e76\u4e14\u4e0d\u8d85\u8fc7\u4e24\u4e2a\u8fde\u7eed\u7684'L'(\u8fdf\u5230),\u90a3\u4e48\u8fd9\u4e2a\u5b66\u751f\u4f1a\u88ab\u5956\u8d4f\u3002

    \n\n

    \u4f60\u9700\u8981\u6839\u636e\u8fd9\u4e2a\u5b66\u751f\u7684\u51fa\u52e4\u8bb0\u5f55\u5224\u65ad\u4ed6\u662f\u5426\u4f1a\u88ab\u5956\u8d4f\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: "PPALLP"\n\u8f93\u51fa: True\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: "PPALLL"\n\u8f93\u51fa: False\n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool checkRecord(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean checkRecord(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def checkRecord(self, s):\n \"\"\"\n :type s: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def checkRecord(self, s: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool checkRecord(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CheckRecord(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {boolean}\n */\nvar checkRecord = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Boolean}\ndef check_record(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func checkRecord(_ s: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func checkRecord(s string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def checkRecord(s: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun checkRecord(s: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn check_record(s: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Boolean\n */\n function checkRecord($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function checkRecord(s: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (check-record s)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0551](https://leetcode-cn.com/problems/student-attendance-record-i)", "[\u5b66\u751f\u51fa\u52e4\u8bb0\u5f55 I](/solution/0500-0599/0551.Student%20Attendance%20Record%20I/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0551](https://leetcode.com/problems/student-attendance-record-i)", "[Student Attendance Record I](/solution/0500-0599/0551.Student%20Attendance%20Record%20I/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "0550", "frontend_question_id": "1730", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/shortest-path-to-get-food", "url_en": "https://leetcode.com/problems/shortest-path-to-get-food", "relative_path_cn": "/solution/1700-1799/1730.Shortest%20Path%20to%20Get%20Food/README.md", "relative_path_en": "/solution/1700-1799/1730.Shortest%20Path%20to%20Get%20Food/README_EN.md", "title_cn": "\u83b7\u53d6\u98df\u7269\u7684\u6700\u77ed\u8def\u5f84", "title_en": "Shortest Path to Get Food", "question_title_slug": "shortest-path-to-get-food", "content_en": "

    You are starving and you want to eat food as quickly as possible. You want to find the shortest path to arrive at any food cell.

    \n\n

    You are given an m x n character matrix, grid, of these different types of cells:

    \n\n
      \n\t
    • '*' is your location. There is exactly one '*' cell.
    • \n\t
    • '#' is a food cell. There may be multiple food cells.
    • \n\t
    • 'O' is free space, and you can travel through these cells.
    • \n\t
    • 'X' is an obstacle, and you cannot travel through these cells.
    • \n
    \n\n

    You can travel to any adjacent cell north, east, south, or west of your current location if there is not an obstacle.

    \n\n

    Return the length of the shortest path for you to reach any food cell. If there is no path for you to reach food, return -1.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: grid = [["X","X","X","X","X","X"],["X","*","O","O","O","X"],["X","O","O","#","O","X"],["X","X","X","X","X","X"]]\nOutput: 3\nExplanation: It takes 3 steps to reach the food.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: grid = [["X","X","X","X","X"],["X","*","X","O","X"],["X","O","X","#","X"],["X","X","X","X","X"]]\nOutput: -1\nExplanation: It is not possible to reach the food.\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: grid = [["X","X","X","X","X","X","X","X"],["X","*","O","X","O","#","O","X"],["X","O","O","X","O","O","X","X"],["X","O","O","O","O","#","O","X"],["X","X","X","X","X","X","X","X"]]\nOutput: 6\nExplanation: There can be multiple food cells. It only takes 6 steps to reach the bottom food.
    \n\n

    Example 4:

    \n\n
    \nInput: grid = [["O","*"],["#","O"]]\nOutput: 2\n
    \n\n

    Example 5:

    \n\n
    \nInput: grid = [["X","*"],["#","X"]]\nOutput: -1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= m, n <= 200
    • \n\t
    • grid[row][col] is '*', 'X', 'O', or '#'.
    • \n\t
    • The grid contains exactly one '*'.
    • \n
    \n", "content_cn": "

    \u4f60\u73b0\u5728\u5f88\u997f\uff0c\u60f3\u8981\u5c3d\u5feb\u627e\u4e1c\u897f\u5403\u3002\u4f60\u9700\u8981\u627e\u5230\u6700\u77ed\u7684\u8def\u5f84\u5230\u8fbe\u4e00\u4e2a\u98df\u7269\u6240\u5728\u7684\u683c\u5b50\u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u00a0m x n\u00a0\u7684\u5b57\u7b26\u77e9\u9635\u00a0grid\u00a0\uff0c\u5305\u542b\u4e0b\u5217\u4e0d\u540c\u7c7b\u578b\u7684\u683c\u5b50\uff1a

    \n\n
      \n\t
    • '*'\u00a0\u662f\u4f60\u7684\u4f4d\u7f6e\u3002\u77e9\u9635\u4e2d\u6709\u4e14\u53ea\u6709\u4e00\u4e2a\u00a0'*'\u00a0\u683c\u5b50\u3002
    • \n\t
    • '#' \u662f\u98df\u7269\u3002\u77e9\u9635\u4e2d\u53ef\u80fd\u5b58\u5728\u591a\u4e2a\u98df\u7269\u3002
    • \n\t
    • 'O'\u00a0\u662f\u7a7a\u5730\uff0c\u4f60\u53ef\u4ee5\u7a7f\u8fc7\u8fd9\u4e9b\u683c\u5b50\u3002
    • \n\t
    • 'X'\u00a0\u662f\u969c\u788d\uff0c\u4f60\u4e0d\u53ef\u4ee5\u7a7f\u8fc7\u8fd9\u4e9b\u683c\u5b50\u3002
    • \n
    \n\n

    \u8fd4\u56de\u4f60\u5230\u4efb\u610f\u98df\u7269\u7684\u6700\u77ed\u8def\u5f84\u7684\u957f\u5ea6\u3002\u5982\u679c\u4e0d\u5b58\u5728\u4f60\u5230\u4efb\u610f\u98df\u7269\u7684\u8def\u5f84\uff0c\u8fd4\u56de\u00a0-1\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1:

    \n\"\"\n
    \u8f93\u5165\uff1a grid = [[\"X\",\"X\",\"X\",\"X\",\"X\",\"X\"],[\"X\",\"*\",\"O\",\"O\",\"O\",\"X\"],[\"X\",\"O\",\"O\",\"#\",\"O\",\"X\"],[\"X\",\"X\",\"X\",\"X\",\"X\",\"X\"]]\n\u8f93\u51fa\uff1a 3\n\u89e3\u91ca\uff1a \u8981\u62ff\u5230\u98df\u7269\uff0c\u4f60\u9700\u8981\u8d70 3 \u6b65\u3002
    \n\n

    Example 2:

    \n\"\"\n
    \u8f93\u5165\uff1a grid = [[\"X\",\"X\",\"X\",\"X\",\"X\"],[\"X\",\"*\",\"X\",\"O\",\"X\"],[\"X\",\"O\",\"X\",\"#\",\"X\"],[\"X\",\"X\",\"X\",\"X\",\"X\"]]\n\u8f93\u51fa\uff1a -1\n\u89e3\u91ca\uff1a \u4f60\u4e0d\u53ef\u80fd\u62ff\u5230\u98df\u7269\u3002\n
    \n\n

    \u793a\u4f8b\u00a03:

    \n\"\"\n
    \u8f93\u5165: grid = [[\"X\",\"X\",\"X\",\"X\",\"X\",\"X\",\"X\",\"X\"],[\"X\",\"*\",\"O\",\"X\",\"O\",\"#\",\"O\",\"X\"],[\"X\",\"O\",\"O\",\"X\",\"O\",\"O\",\"X\",\"X\"],[\"X\",\"O\",\"O\",\"O\",\"O\",\"#\",\"O\",\"X\"],[\"X\",\"X\",\"X\",\"X\",\"X\",\"X\",\"X\",\"X\"]]\n\u8f93\u51fa: 6\n\u89e3\u91ca: \u8fd9\u91cc\u6709\u591a\u4e2a\u98df\u7269\u3002\u62ff\u5230\u4e0b\u8fb9\u7684\u98df\u7269\u4ec5\u9700\u8d70 6 \u6b65\u3002
    \n\n

    \u793a\u4f8b 4:

    \n\n
    \u8f93\u5165: grid = [[\"O\",\"*\"],[\"#\",\"O\"]]\n\u8f93\u51fa: 2\n
    \n\n

    \u793a\u4f8b 5:

    \n\n
    \u8f93\u5165: grid = [[\"X\",\"*\"],[\"#\",\"X\"]]\n\u8f93\u51fa:\u00a0-1
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= m, n <= 200
    • \n\t
    • grid[row][col]\u00a0\u662f\u00a0'*'\u3001\u00a0'X'\u3001\u00a0'O'\u00a0\u6216\u00a0'#'\u00a0\u3002
    • \n\t
    • grid\u00a0\u4e2d\u6709\u4e14\u53ea\u6709\u4e00\u4e2a\u00a0'*'\u00a0\u3002
    • \n
    \n", "tags_en": ["Depth-first Search", "Breadth-first Search", "Graph"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int getFood(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int getFood(char[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getFood(self, grid):\n \"\"\"\n :type grid: List[List[str]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getFood(self, grid: List[List[str]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint getFood(char** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int GetFood(char[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {character[][]} grid\n * @return {number}\n */\nvar getFood = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Character[][]} grid\n# @return {Integer}\ndef get_food(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getFood(_ grid: [[Character]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getFood(grid [][]byte) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getFood(grid: Array[Array[Char]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getFood(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_food(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $grid\n * @return Integer\n */\n function getFood($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getFood(grid: string[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-food grid)\n (-> (listof (listof char?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1730](https://leetcode-cn.com/problems/shortest-path-to-get-food)", "[\u83b7\u53d6\u98df\u7269\u7684\u6700\u77ed\u8def\u5f84](/solution/1700-1799/1730.Shortest%20Path%20to%20Get%20Food/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u56fe`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1730](https://leetcode.com/problems/shortest-path-to-get-food)", "[Shortest Path to Get Food](/solution/1700-1799/1730.Shortest%20Path%20to%20Get%20Food/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`,`Graph`", "Medium", "\ud83d\udd12"]}, {"question_id": "0549", "frontend_question_id": "0549", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/binary-tree-longest-consecutive-sequence-ii", "url_en": "https://leetcode.com/problems/binary-tree-longest-consecutive-sequence-ii", "relative_path_cn": "/solution/0500-0599/0549.Binary%20Tree%20Longest%20Consecutive%20Sequence%20II/README.md", "relative_path_en": "/solution/0500-0599/0549.Binary%20Tree%20Longest%20Consecutive%20Sequence%20II/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u4e2d\u6700\u957f\u7684\u8fde\u7eed\u5e8f\u5217", "title_en": "Binary Tree Longest Consecutive Sequence II", "question_title_slug": "binary-tree-longest-consecutive-sequence-ii", "content_en": "

    Given the root of a binary tree, return the length of the longest consecutive path in the tree.

    \n\n

    This path can be either increasing or decreasing.

    \n\n
      \n\t
    • For example, [1,2,3,4] and [4,3,2,1] are both considered valid, but the path [1,2,4,3] is not valid.
    • \n
    \n\n

    On the other hand, the path can be in the child-Parent-child order, where not necessarily be parent-child order.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,2,3]\nOutput: 2\nExplanation: The longest consecutive path is [1, 2] or [2, 1].\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [2,1,3]\nOutput: 3\nExplanation: The longest consecutive path is [1, 2, 3] or [3, 2, 1].\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 3 * 104].
    • \n\t
    • -3 * 104 <= Node.val <= 3 * 104
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811\uff0c\u4f60\u9700\u8981\u627e\u51fa\u4e8c\u53c9\u6811\u4e2d\u6700\u957f\u7684\u8fde\u7eed\u5e8f\u5217\u8def\u5f84\u7684\u957f\u5ea6\u3002

    \n\n

    \u8bf7\u6ce8\u610f\uff0c\u8be5\u8def\u5f84\u53ef\u4ee5\u662f\u9012\u589e\u7684\u6216\u8005\u662f\u9012\u51cf\u3002\u4f8b\u5982\uff0c[1,2,3,4] \u548c [4,3,2,1] \u90fd\u88ab\u8ba4\u4e3a\u662f\u5408\u6cd5\u7684\uff0c\u800c\u8def\u5f84 [1,2,4,3] \u5219\u4e0d\u5408\u6cd5\u3002\u53e6\u4e00\u65b9\u9762\uff0c\u8def\u5f84\u53ef\u4ee5\u662f \u5b50-\u7236-\u5b50 \u987a\u5e8f\uff0c\u5e76\u4e0d\u4e00\u5b9a\u662f \u7236-\u5b50 \u987a\u5e8f\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165:\n        1\n       / \\\n      2   3\n\u8f93\u51fa: 2\n\u89e3\u91ca: \u6700\u957f\u7684\u8fde\u7eed\u8def\u5f84\u662f [1, 2] \u6216\u8005 [2, 1]\u3002\n
    \n\n

     

    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165:\n        2\n       / \\\n      1   3\n\u8f93\u51fa: 3\n\u89e3\u91ca: \u6700\u957f\u7684\u8fde\u7eed\u8def\u5f84\u662f [1, 2, 3] \u6216\u8005 [3, 2, 1]\u3002\n
    \n\n

     

    \n\n

    \u6ce8\u610f: \u6811\u4e0a\u6240\u6709\u8282\u70b9\u7684\u503c\u90fd\u5728 [-1e7, 1e7] \u8303\u56f4\u5185\u3002

    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int longestConsecutive(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int longestConsecutive(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def longestConsecutive(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def longestConsecutive(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint longestConsecutive(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int LongestConsecutive(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar longestConsecutive = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef longest_consecutive(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func longestConsecutive(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc longestConsecutive(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def longestConsecutive(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun longestConsecutive(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn longest_consecutive(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function longestConsecutive($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction longestConsecutive(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (longest-consecutive root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0549](https://leetcode-cn.com/problems/binary-tree-longest-consecutive-sequence-ii)", "[\u4e8c\u53c9\u6811\u4e2d\u6700\u957f\u7684\u8fde\u7eed\u5e8f\u5217](/solution/0500-0599/0549.Binary%20Tree%20Longest%20Consecutive%20Sequence%20II/README.md)", "`\u6811`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0549](https://leetcode.com/problems/binary-tree-longest-consecutive-sequence-ii)", "[Binary Tree Longest Consecutive Sequence II](/solution/0500-0599/0549.Binary%20Tree%20Longest%20Consecutive%20Sequence%20II/README_EN.md)", "`Tree`", "Medium", "\ud83d\udd12"]}, {"question_id": "0548", "frontend_question_id": "0548", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/split-array-with-equal-sum", "url_en": "https://leetcode.com/problems/split-array-with-equal-sum", "relative_path_cn": "/solution/0500-0599/0548.Split%20Array%20with%20Equal%20Sum/README.md", "relative_path_en": "/solution/0500-0599/0548.Split%20Array%20with%20Equal%20Sum/README_EN.md", "title_cn": "\u5c06\u6570\u7ec4\u5206\u5272\u6210\u548c\u76f8\u7b49\u7684\u5b50\u6570\u7ec4", "title_en": "Split Array with Equal Sum", "question_title_slug": "split-array-with-equal-sum", "content_en": "

    Given an integer array nums of length n, return true if there is a triplet (i, j, k) which satisfies the following conditions:

    \n\n
      \n\t
    • 0 < i, i + 1 < j, j + 1 < k < n - 1
    • \n\t
    • The sum of subarrays (0, i - 1), (i + 1, j - 1), (j + 1, k - 1) and (k + 1, n - 1) is equal.
    • \n
    \nA subarray (l, r) represents a slice of the original array starting from the element indexed l to the element indexed r.\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,1,2,1,2,1]\nOutput: true\nExplanation:\ni = 1, j = 3, k = 5. \nsum(0, i - 1) = sum(0, 0) = 1\nsum(i + 1, j - 1) = sum(2, 2) = 1\nsum(j + 1, k - 1) = sum(4, 4) = 1\nsum(k + 1, n - 1) = sum(6, 6) = 1\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,2,1,2,1,2,1,2]\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= n <= 2000
    • \n\t
    • -106 <= nums[i] <= 106
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6709 n \u4e2a\u6574\u6570\u7684\u6570\u7ec4\uff0c\u4f60\u9700\u8981\u627e\u5230\u6ee1\u8db3\u4ee5\u4e0b\u6761\u4ef6\u7684\u4e09\u5143\u7ec4 (i, j, k) \uff1a

    \n\n
      \n\t
    1. 0 < i, i + 1 < j, j + 1 < k < n - 1
    2. \n\t
    3. \u5b50\u6570\u7ec4 (0, i - 1)\uff0c(i + 1, j - 1)\uff0c(j + 1, k - 1)\uff0c(k + 1, n - 1) \u7684\u548c\u5e94\u8be5\u76f8\u7b49\u3002
    4. \n
    \n\n

    \u8fd9\u91cc\u6211\u4eec\u5b9a\u4e49\u5b50\u6570\u7ec4 (L, R) \u8868\u793a\u539f\u6570\u7ec4\u4ece\u7d22\u5f15\u4e3aL\u7684\u5143\u7d20\u5f00\u59cb\u81f3\u7d22\u5f15\u4e3aR\u7684\u5143\u7d20\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: [1,2,1,2,1,2,1]\n\u8f93\u51fa: True\n\u89e3\u91ca:\ni = 1, j = 3, k = 5. \nsum(0, i - 1) = sum(0, 0) = 1\nsum(i + 1, j - 1) = sum(2, 2) = 1\nsum(j + 1, k - 1) = sum(4, 4) = 1\nsum(k + 1, n - 1) = sum(6, 6) = 1\n
    \n\n

     

    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. 1 <= n <= 2000\u3002
    2. \n\t
    3. \u7ed9\u5b9a\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u4f1a\u5728 [-1,000,000, 1,000,000] \u8303\u56f4\u5185\u3002
    4. \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool splitArray(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean splitArray(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def splitArray(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def splitArray(self, nums: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool splitArray(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool SplitArray(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {boolean}\n */\nvar splitArray = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Boolean}\ndef split_array(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func splitArray(_ nums: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func splitArray(nums []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def splitArray(nums: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun splitArray(nums: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn split_array(nums: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Boolean\n */\n function splitArray($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function splitArray(nums: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (split-array nums)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0548](https://leetcode-cn.com/problems/split-array-with-equal-sum)", "[\u5c06\u6570\u7ec4\u5206\u5272\u6210\u548c\u76f8\u7b49\u7684\u5b50\u6570\u7ec4](/solution/0500-0599/0548.Split%20Array%20with%20Equal%20Sum/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0548](https://leetcode.com/problems/split-array-with-equal-sum)", "[Split Array with Equal Sum](/solution/0500-0599/0548.Split%20Array%20with%20Equal%20Sum/README_EN.md)", "`Array`", "Medium", "\ud83d\udd12"]}, {"question_id": "0547", "frontend_question_id": "0547", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-provinces", "url_en": "https://leetcode.com/problems/number-of-provinces", "relative_path_cn": "/solution/0500-0599/0547.Number%20of%20Provinces/README.md", "relative_path_en": "/solution/0500-0599/0547.Number%20of%20Provinces/README_EN.md", "title_cn": "\u7701\u4efd\u6570\u91cf", "title_en": "Number of Provinces", "question_title_slug": "number-of-provinces", "content_en": "

    There are n cities. Some of them are connected, while some are not. If city a is connected directly with city b, and city b is connected directly with city c, then city a is connected indirectly with city c.

    \n\n

    A province is a group of directly or indirectly connected cities and no other cities outside of the group.

    \n\n

    You are given an n x n matrix isConnected where isConnected[i][j] = 1 if the ith city and the jth city are directly connected, and isConnected[i][j] = 0 otherwise.

    \n\n

    Return the total number of provinces.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: isConnected = [[1,1,0],[1,1,0],[0,0,1]]\nOutput: 2\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: isConnected = [[1,0,0],[0,1,0],[0,0,1]]\nOutput: 3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 200
    • \n\t
    • n == isConnected.length
    • \n\t
    • n == isConnected[i].length
    • \n\t
    • isConnected[i][j] is 1 or 0.
    • \n\t
    • isConnected[i][i] == 1
    • \n\t
    • isConnected[i][j] == isConnected[j][i]
    • \n
    \n", "content_cn": "
    \n
    \n

    \u6709 n \u4e2a\u57ce\u5e02\uff0c\u5176\u4e2d\u4e00\u4e9b\u5f7c\u6b64\u76f8\u8fde\uff0c\u53e6\u4e00\u4e9b\u6ca1\u6709\u76f8\u8fde\u3002\u5982\u679c\u57ce\u5e02 a \u4e0e\u57ce\u5e02 b \u76f4\u63a5\u76f8\u8fde\uff0c\u4e14\u57ce\u5e02 b \u4e0e\u57ce\u5e02 c \u76f4\u63a5\u76f8\u8fde\uff0c\u90a3\u4e48\u57ce\u5e02 a \u4e0e\u57ce\u5e02 c \u95f4\u63a5\u76f8\u8fde\u3002

    \n\n

    \u7701\u4efd \u662f\u4e00\u7ec4\u76f4\u63a5\u6216\u95f4\u63a5\u76f8\u8fde\u7684\u57ce\u5e02\uff0c\u7ec4\u5185\u4e0d\u542b\u5176\u4ed6\u6ca1\u6709\u76f8\u8fde\u7684\u57ce\u5e02\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a n x n \u7684\u77e9\u9635 isConnected \uff0c\u5176\u4e2d isConnected[i][j] = 1 \u8868\u793a\u7b2c i \u4e2a\u57ce\u5e02\u548c\u7b2c j \u4e2a\u57ce\u5e02\u76f4\u63a5\u76f8\u8fde\uff0c\u800c isConnected[i][j] = 0 \u8868\u793a\u4e8c\u8005\u4e0d\u76f4\u63a5\u76f8\u8fde\u3002

    \n\n

    \u8fd4\u56de\u77e9\u9635\u4e2d \u7701\u4efd \u7684\u6570\u91cf\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aisConnected = [[1,1,0],[1,1,0],[0,0,1]]\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aisConnected = [[1,0,0],[0,1,0],[0,0,1]]\n\u8f93\u51fa\uff1a3\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 200
    • \n\t
    • n == isConnected.length
    • \n\t
    • n == isConnected[i].length
    • \n\t
    • isConnected[i][j] \u4e3a 1 \u6216 0
    • \n\t
    • isConnected[i][i] == 1
    • \n\t
    • isConnected[i][j] == isConnected[j][i]
    • \n
    \n
    \n
    \n", "tags_en": ["Depth-first Search", "Union Find"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e76\u67e5\u96c6"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findCircleNum(vector>& isConnected) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findCircleNum(int[][] isConnected) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findCircleNum(self, isConnected):\n \"\"\"\n :type isConnected: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findCircleNum(self, isConnected: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findCircleNum(int** isConnected, int isConnectedSize, int* isConnectedColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindCircleNum(int[][] isConnected) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} isConnected\n * @return {number}\n */\nvar findCircleNum = function(isConnected) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} is_connected\n# @return {Integer}\ndef find_circle_num(is_connected)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findCircleNum(_ isConnected: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findCircleNum(isConnected [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findCircleNum(isConnected: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findCircleNum(isConnected: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_circle_num(is_connected: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $isConnected\n * @return Integer\n */\n function findCircleNum($isConnected) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findCircleNum(isConnected: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-circle-num isConnected)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0547](https://leetcode-cn.com/problems/number-of-provinces)", "[\u7701\u4efd\u6570\u91cf](/solution/0500-0599/0547.Number%20of%20Provinces/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e76\u67e5\u96c6`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0547](https://leetcode.com/problems/number-of-provinces)", "[Number of Provinces](/solution/0500-0599/0547.Number%20of%20Provinces/README_EN.md)", "`Depth-first Search`,`Union Find`", "Medium", ""]}, {"question_id": "0546", "frontend_question_id": "0546", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/remove-boxes", "url_en": "https://leetcode.com/problems/remove-boxes", "relative_path_cn": "/solution/0500-0599/0546.Remove%20Boxes/README.md", "relative_path_en": "/solution/0500-0599/0546.Remove%20Boxes/README_EN.md", "title_cn": "\u79fb\u9664\u76d2\u5b50", "title_en": "Remove Boxes", "question_title_slug": "remove-boxes", "content_en": "

    You are given several boxes with different colors represented by different positive numbers.

    \n\n

    You may experience several rounds to remove boxes until there is no box left. Each time you can choose some continuous boxes with the same color (i.e., composed of k boxes, k >= 1), remove them and get k * k points.

    \n\n

    Return the maximum points you can get.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: boxes = [1,3,2,2,2,3,4,3,1]\nOutput: 23\nExplanation:\n[1, 3, 2, 2, 2, 3, 4, 3, 1] \n----> [1, 3, 3, 4, 3, 1] (3*3=9 points) \n----> [1, 3, 3, 3, 1] (1*1=1 points) \n----> [1, 1] (3*3=9 points) \n----> [] (2*2=4 points)\n
    \n\n

    Example 2:

    \n\n
    \nInput: boxes = [1,1,1]\nOutput: 9\n
    \n\n

    Example 3:

    \n\n
    \nInput: boxes = [1]\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= boxes.length <= 100
    • \n\t
    • 1 <= boxes[i] <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u51fa\u4e00\u4e9b\u4e0d\u540c\u989c\u8272\u7684\u76d2\u5b50\uff0c\u76d2\u5b50\u7684\u989c\u8272\u7531\u6570\u5b57\u8868\u793a\uff0c\u5373\u4e0d\u540c\u7684\u6570\u5b57\u8868\u793a\u4e0d\u540c\u7684\u989c\u8272\u3002

    \n\n

    \u4f60\u5c06\u7ecf\u8fc7\u82e5\u5e72\u8f6e\u64cd\u4f5c\u53bb\u53bb\u6389\u76d2\u5b50\uff0c\u76f4\u5230\u6240\u6709\u7684\u76d2\u5b50\u90fd\u53bb\u6389\u4e3a\u6b62\u3002\u6bcf\u4e00\u8f6e\u4f60\u53ef\u4ee5\u79fb\u9664\u5177\u6709\u76f8\u540c\u989c\u8272\u7684\u8fde\u7eed k \u4e2a\u76d2\u5b50\uff08k\u00a0>= 1\uff09\uff0c\u8fd9\u6837\u4e00\u8f6e\u4e4b\u540e\u4f60\u5c06\u5f97\u5230 k * k \u4e2a\u79ef\u5206\u3002

    \n\n

    \u5f53\u4f60\u5c06\u6240\u6709\u76d2\u5b50\u90fd\u53bb\u6389\u4e4b\u540e\uff0c\u6c42\u4f60\u80fd\u83b7\u5f97\u7684\u6700\u5927\u79ef\u5206\u548c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aboxes = [1,3,2,2,2,3,4,3,1]\n\u8f93\u51fa\uff1a23\n\u89e3\u91ca\uff1a\n[1, 3, 2, 2, 2, 3, 4, 3, 1] \n----> [1, 3, 3, 4, 3, 1] (3*3=9 \u5206) \n----> [1, 3, 3, 3, 1] (1*1=1 \u5206) \n----> [1, 1] (3*3=9 \u5206) \n----> [] (2*2=4 \u5206)\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aboxes = [1,1,1]\n\u8f93\u51fa\uff1a9\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aboxes = [1]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= boxes.length <= 100
    • \n\t
    • 1 <= boxes[i]\u00a0<= 100
    • \n
    \n", "tags_en": ["Depth-first Search", "Dynamic Programming"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int removeBoxes(vector& boxes) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int removeBoxes(int[] boxes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def removeBoxes(self, boxes):\n \"\"\"\n :type boxes: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def removeBoxes(self, boxes: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint removeBoxes(int* boxes, int boxesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int RemoveBoxes(int[] boxes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} boxes\n * @return {number}\n */\nvar removeBoxes = function(boxes) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} boxes\n# @return {Integer}\ndef remove_boxes(boxes)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func removeBoxes(_ boxes: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func removeBoxes(boxes []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def removeBoxes(boxes: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun removeBoxes(boxes: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn remove_boxes(boxes: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $boxes\n * @return Integer\n */\n function removeBoxes($boxes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function removeBoxes(boxes: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (remove-boxes boxes)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0546](https://leetcode-cn.com/problems/remove-boxes)", "[\u79fb\u9664\u76d2\u5b50](/solution/0500-0599/0546.Remove%20Boxes/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0546](https://leetcode.com/problems/remove-boxes)", "[Remove Boxes](/solution/0500-0599/0546.Remove%20Boxes/README_EN.md)", "`Depth-first Search`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0545", "frontend_question_id": "0545", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/boundary-of-binary-tree", "url_en": "https://leetcode.com/problems/boundary-of-binary-tree", "relative_path_cn": "/solution/0500-0599/0545.Boundary%20of%20Binary%20Tree/README.md", "relative_path_en": "/solution/0500-0599/0545.Boundary%20of%20Binary%20Tree/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u7684\u8fb9\u754c", "title_en": "Boundary of Binary Tree", "question_title_slug": "boundary-of-binary-tree", "content_en": "

    The boundary of a binary tree is the concatenation of the root, the left boundary, the leaves ordered from left-to-right, and the reverse order of the right boundary.

    \n\n

    The left boundary is the set of nodes defined by the following:

    \n\n
      \n\t
    • The root node's left child is in the left boundary. If the root does not have a left child, then the left boundary is empty.
    • \n\t
    • If a node in the left boundary and has a left child, then the left child is in the left boundary.
    • \n\t
    • If a node is in the left boundary, has no left child, but has a right child, then the right child is in the left boundary.
    • \n\t
    • The leftmost leaf is not in the left boundary.
    • \n
    \n\n

    The right boundary is similar to the left boundary, except it is the right side of the root's right subtree. Again, the leaf is not part of the right boundary, and the right boundary is empty if the root does not have a right child.

    \n\n

    The leaves are nodes that do not have any children. For this problem, the root is not a leaf.

    \n\n

    Given the root of a binary tree, return the values of its boundary.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,null,2,3,4]\nOutput: [1,3,4,2]\nExplanation:\n- The left boundary is empty because the root does not have a left child.\n- The right boundary follows the path starting from the root's right child 2 -> 4.\n  4 is a leaf, so the right boundary is [2].\n- The leaves from left to right are [3,4].\nConcatenating everything results in [1] + [] + [3,4] + [2] = [1,3,4,2].\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [1,2,3,4,5,6,null,null,null,7,8,9,10]\nOutput: [1,2,4,7,8,9,10,6,3]\nExplanation:\n- The left boundary follows the path starting from the root's left child 2 -> 4.\n  4 is a leaf, so the left boundary is [2].\n- The right boundary follows the path starting from the root's right child 3 -> 6 -> 10.\n  10 is a leaf, so the right boundary is [3,6], and in reverse order is [6,3].\n- The leaves from left to right are [4,7,8,9,10].\nConcatenating everything results in [1] + [2] + [4,7,8,9,10] + [6,3] = [1,2,4,7,8,9,10,6,3].\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 104].
    • \n\t
    • -1000 <= Node.val <= 1000
    • \n
    \n", "content_cn": "

    \u4e8c\u53c9\u6811\u7684 \u8fb9\u754c \u662f\u7531 \u6839\u8282\u70b9 \u3001\u5de6\u8fb9\u754c \u3001\u6309\u4ece\u5de6\u5230\u53f3\u987a\u5e8f\u7684 \u53f6\u8282\u70b9 \u548c \u9006\u5e8f\u7684\u53f3\u8fb9\u754c \uff0c\u6309\u987a\u5e8f\u4f9d\u6b21\u8fde\u63a5\u7ec4\u6210\u3002

    \n\n

    \u5de6\u8fb9\u754c \u662f\u6ee1\u8db3\u4e0b\u8ff0\u5b9a\u4e49\u7684\u8282\u70b9\u96c6\u5408\uff1a

    \n\n
      \n\t
    • \u6839\u8282\u70b9\u7684\u5de6\u5b50\u8282\u70b9\u5728\u5de6\u8fb9\u754c\u4e2d\u3002\u5982\u679c\u6839\u8282\u70b9\u4e0d\u542b\u5de6\u5b50\u8282\u70b9\uff0c\u90a3\u4e48\u5de6\u8fb9\u754c\u5c31\u4e3a \u7a7a \u3002
    • \n\t
    • \u5982\u679c\u4e00\u4e2a\u8282\u70b9\u5728\u5de6\u8fb9\u754c\u4e2d\uff0c\u5e76\u4e14\u8be5\u8282\u70b9\u6709\u5de6\u5b50\u8282\u70b9\uff0c\u90a3\u4e48\u5b83\u7684\u5de6\u5b50\u8282\u70b9\u4e5f\u5728\u5de6\u8fb9\u754c\u4e2d\u3002
    • \n\t
    • \u5982\u679c\u4e00\u4e2a\u8282\u70b9\u5728\u5de6\u8fb9\u754c\u4e2d\uff0c\u5e76\u4e14\u8be5\u8282\u70b9 \u4e0d\u542b \u5de6\u5b50\u8282\u70b9\uff0c\u90a3\u4e48\u5b83\u7684\u53f3\u5b50\u8282\u70b9\u5c31\u5728\u5de6\u8fb9\u754c\u4e2d\u3002
    • \n\t
    • \u6700\u5de6\u4fa7\u7684\u53f6\u8282\u70b9 \u4e0d\u5728 \u5de6\u8fb9\u754c\u4e2d\u3002
    • \n
    \n\n

    \u53f3\u8fb9\u754c \u5b9a\u4e49\u65b9\u5f0f\u4e0e \u5de6\u8fb9\u754c \u76f8\u540c\uff0c\u53ea\u662f\u5c06\u5de6\u66ff\u6362\u6210\u53f3\u3002\u5373\uff0c\u53f3\u8fb9\u754c\u662f\u6839\u8282\u70b9\u53f3\u5b50\u6811\u7684\u53f3\u4fa7\u90e8\u5206\uff1b\u53f6\u8282\u70b9 \u4e0d\u662f \u53f3\u8fb9\u754c\u7684\u7ec4\u6210\u90e8\u5206\uff1b\u5982\u679c\u6839\u8282\u70b9\u4e0d\u542b\u53f3\u5b50\u8282\u70b9\uff0c\u90a3\u4e48\u53f3\u8fb9\u754c\u4e3a \u7a7a \u3002

    \n\n

    \u53f6\u8282\u70b9 \u662f\u6ca1\u6709\u4efb\u4f55\u5b50\u8282\u70b9\u7684\u8282\u70b9\u3002\u5bf9\u4e8e\u6b64\u95ee\u9898\uff0c\u6839\u8282\u70b9 \u4e0d\u662f \u53f6\u8282\u70b9\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u68f5\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9 root \uff0c\u6309\u987a\u5e8f\u8fd4\u56de\u7ec4\u6210\u4e8c\u53c9\u6811 \u8fb9\u754c \u7684\u8fd9\u4e9b\u503c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [1,null,2,3,4]\n\u8f93\u51fa\uff1a[1,3,4,2]\n\u89e3\u91ca\uff1a\n- \u5de6\u8fb9\u754c\u4e3a\u7a7a\uff0c\u56e0\u4e3a\u4e8c\u53c9\u6811\u4e0d\u542b\u5de6\u5b50\u8282\u70b9\u3002\n- \u53f3\u8fb9\u754c\u662f [2] \u3002\u4ece\u6839\u8282\u70b9\u7684\u53f3\u5b50\u8282\u70b9\u5f00\u59cb\u7684\u8def\u5f84\u4e3a 2 -> 4 \uff0c\u4f46 4 \u662f\u53f6\u8282\u70b9\uff0c\u6240\u4ee5\u53f3\u8fb9\u754c\u53ea\u6709 2 \u3002\n- \u53f6\u8282\u70b9\u4ece\u5de6\u5230\u53f3\u662f [3,4] \u3002\n\u6309\u9898\u76ee\u8981\u6c42\u4f9d\u5e8f\u8fde\u63a5\u5f97\u5230\u7ed3\u679c [1] + [] + [3,4] + [2] = [1,3,4,2] \u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [1,2,3,4,5,6,null,null,null,7,8,9,10]\n\u8f93\u51fa\uff1a[1,2,4,7,8,9,10,6,3]\n\u89e3\u91ca\uff1a\n- \u5de6\u8fb9\u754c\u4e3a [2] \u3002\u4ece\u6839\u8282\u70b9\u7684\u5de6\u5b50\u8282\u70b9\u5f00\u59cb\u7684\u8def\u5f84\u4e3a 2 -> 4 \uff0c\u4f46 4 \u662f\u53f6\u8282\u70b9\uff0c\u6240\u4ee5\u5de6\u8fb9\u754c\u53ea\u6709 2 \u3002\n- \u53f3\u8fb9\u754c\u662f [3,6] \uff0c\u9006\u5e8f\u4e3a [6,3] \u3002\u4ece\u6839\u8282\u70b9\u7684\u53f3\u5b50\u8282\u70b9\u5f00\u59cb\u7684\u8def\u5f84\u4e3a 3 -> 6 -> 10 \uff0c\u4f46 10 \u662f\u53f6\u8282\u70b9\u3002\n- \u53f6\u8282\u70b9\u4ece\u5de6\u5230\u53f3\u662f [4,7,8,9,10]\n\u6309\u9898\u76ee\u8981\u6c42\u4f9d\u5e8f\u8fde\u63a5\u5f97\u5230\u7ed3\u679c [1] + [2] + [4,7,8,9,10] + [6,3] = [1,2,4,7,8,9,10,6,3] \u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u7684\u6570\u76ee\u5728\u8303\u56f4 [1, 104] \u5185
    • \n\t
    • -1000 <= Node.val <= 1000
    • \n
    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector boundaryOfBinaryTree(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public List boundaryOfBinaryTree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def boundaryOfBinaryTree(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def boundaryOfBinaryTree(self, root: TreeNode) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* boundaryOfBinaryTree(struct TreeNode* root, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public IList BoundaryOfBinaryTree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number[]}\n */\nvar boundaryOfBinaryTree = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer[]}\ndef boundary_of_binary_tree(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func boundaryOfBinaryTree(_ root: TreeNode?) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc boundaryOfBinaryTree(root *TreeNode) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def boundaryOfBinaryTree(root: TreeNode): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun boundaryOfBinaryTree(root: TreeNode?): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn boundary_of_binary_tree(root: Option>>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer[]\n */\n function boundaryOfBinaryTree($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction boundaryOfBinaryTree(root: TreeNode | null): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (boundary-of-binary-tree root)\n (-> (or/c tree-node? #f) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0545](https://leetcode-cn.com/problems/boundary-of-binary-tree)", "[\u4e8c\u53c9\u6811\u7684\u8fb9\u754c](/solution/0500-0599/0545.Boundary%20of%20Binary%20Tree/README.md)", "`\u6811`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0545](https://leetcode.com/problems/boundary-of-binary-tree)", "[Boundary of Binary Tree](/solution/0500-0599/0545.Boundary%20of%20Binary%20Tree/README_EN.md)", "`Tree`", "Medium", "\ud83d\udd12"]}, {"question_id": "0544", "frontend_question_id": "0544", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/output-contest-matches", "url_en": "https://leetcode.com/problems/output-contest-matches", "relative_path_cn": "/solution/0500-0599/0544.Output%20Contest%20Matches/README.md", "relative_path_en": "/solution/0500-0599/0544.Output%20Contest%20Matches/README_EN.md", "title_cn": "\u8f93\u51fa\u6bd4\u8d5b\u5339\u914d\u5bf9", "title_en": "Output Contest Matches", "question_title_slug": "output-contest-matches", "content_en": "

    During the NBA playoffs, we always set the rather strong team to play with the rather weak team, like make the rank 1 team play with the rank nth team, which is a good strategy to make the contest more interesting.

    \n\n

    Given n teams, return their final contest matches in the form of a string.

    \n\n

    The n teams are labeled from 1 to n, which represents their initial rank (i.e., Rank 1 is the strongest team and Rank n is the weakest team).

    \n\n

    We will use parentheses '(', and ')' and commas ',' to represent the contest team pairing. We use the parentheses for pairing and the commas for partition. During the pairing process in each round, you always need to follow the strategy of making the rather strong one pair with the rather weak one.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 4\nOutput: "((1,4),(2,3))"\nExplanation:\nIn the first round, we pair the team 1 and 4, the teams 2 and 3 together, as we need to make the strong team and weak team together.\nAnd we got (1, 4),(2, 3).\nIn the second round, the winners of (1, 4) and (2, 3) need to play again to generate the final winner, so you need to add the paratheses outside them.\nAnd we got the final answer ((1,4),(2,3)).\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 8\nOutput: "(((1,8),(4,5)),((2,7),(3,6)))"\nExplanation:\nFirst round: (1, 8),(2, 7),(3, 6),(4, 5)\nSecond round: ((1, 8),(4, 5)),((2, 7),(3, 6))\nThird round: (((1, 8),(4, 5)),((2, 7),(3, 6)))\nSince the third round will generate the final winner, you need to output the answer (((1,8),(4,5)),((2,7),(3,6))).\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == 2x where x in in the range [1, 12].
    • \n
    \n", "content_cn": "

    \u5728 NBA \u5b63\u540e\u8d5b\u4e2d\uff0c\u6211\u4eec\u603b\u662f\u5b89\u6392\u8f83\u5f3a\u7684\u961f\u4f0d\u5bf9\u6218\u8f83\u5f31\u7684\u961f\u4f0d\uff0c\u4f8b\u5982\u7528\u6392\u540d\u7b2c 1 \u7684\u961f\u4f0d\u548c\u7b2c n \u7684\u961f\u4f0d\u5bf9\u51b3\uff0c\u8fd9\u662f\u4e00\u4e2a\u53ef\u4ee5\u8ba9\u6bd4\u8d5b\u66f4\u52a0\u6709\u8da3\u7684\u597d\u7b56\u7565\u3002\u73b0\u5728\uff0c\u7ed9\u4f60 \u652f\u961f\u4f0d\uff0c\u4f60\u9700\u8981\u4ee5\u5b57\u7b26\u4e32\u683c\u5f0f\u8f93\u51fa\u5b83\u4eec\u7684 \u6700\u7ec8 \u6bd4\u8d5b\u914d\u5bf9\u3002

    \n\n

    n \u652f\u961f\u4f0d\u6309\u4ece 1 \u5230 n \u7684\u6b63\u6574\u6570\u683c\u5f0f\u7ed9\u51fa\uff0c\u5206\u522b\u4ee3\u8868\u5b83\u4eec\u7684\u521d\u59cb\u6392\u540d\uff08\u6392\u540d 1 \u6700\u5f3a\uff0c\u6392\u540d n \u6700\u5f31\uff09\u3002\u6211\u4eec\u7528\u62ec\u53f7\uff08'(', ')'\uff09\u548c\u9017\u53f7\uff08','\uff09\u6765\u8868\u793a\u5339\u914d\u5bf9——\u62ec\u53f7\uff08'(', ')'\uff09\u8868\u793a\u5339\u914d\uff0c\u9017\u53f7\uff08','\uff09\u6765\u7528\u4e8e\u5206\u5272\u3002 \u5728\u6bcf\u4e00\u8f6e\u7684\u5339\u914d\u8fc7\u7a0b\u4e2d\uff0c\u4f60\u90fd\u9700\u8981\u9075\u5faa\u5c06\u5f3a\u961f\u4e0e\u5f31\u961f\u914d\u5bf9\u7684\u539f\u5219\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165: 2\n\u8f93\u51fa: (1,2)\n\u89e3\u6790: \n\u521d\u59cb\u5730\uff0c\u6211\u4eec\u6709\u961f1\u548c\u961f2\u4e24\u652f\u961f\u4f0d\uff0c\u6309\u71671\uff0c2\u6392\u5217\u3002\n\u56e0\u6b64 \u7528 '(', ')' \u548c ','\u6765\u5c06\u961f1\u548c\u961f2\u8fdb\u884c\u914d\u5bf9\uff0c\u5f97\u5230\u6700\u7ec8\u7b54\u6848\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165: 4\n\u8f93\u51fa: ((1,4),(2,3))\n\u89e3\u6790: \n\u5728\u7b2c\u4e00\u8f6e\uff0c\u6211\u4eec\u5c06\u961f\u4f0d1\u548c4\u914d\u5bf9\uff0c2\u548c3\u914d\u5bf9\uff0c\u4ee5\u6ee1\u8db3\u5c06\u5f3a\u961f\u548c\u5f31\u961f\u642d\u914d\u7684\u6548\u679c\u3002\u5f97\u5230(1,4),(2,3).\n\u5728\u7b2c\u4e8c\u8f6e\uff0c(1,4) \u548c (2,3) \u7684\u8d62\u5bb6\u9700\u8981\u8fdb\u884c\u6bd4\u8d5b\u4ee5\u786e\u5b9a\u6700\u7ec8\u8d62\u5bb6\uff0c\u56e0\u6b64\u9700\u8981\u518d\u5728\u5916\u9762\u52a0\u4e00\u5c42\u62ec\u53f7\u3002\n\u4e8e\u662f\u6700\u7ec8\u7b54\u6848\u662f((1,4),(2,3))\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165: 8\n\u8f93\u51fa: (((1,8),(4,5)),((2,7),(3,6)))\n\u89e3\u6790: \n\u7b2c\u4e00\u8f6e: (1,8),(2,7),(3,6),(4,5)\n\u7b2c\u4e8c\u8f6e: ((1,8),(4,5)),((2,7),(3,6))\n\u7b2c\u4e09\u8f6e (((1,8),(4,5)),((2,7),(3,6)))\n\u7531\u4e8e\u7b2c\u4e09\u8f6e\u4f1a\u51b3\u51fa\u6700\u7ec8\u80dc\u8005\uff0c\u6545\u8f93\u51fa\u7b54\u6848\u4e3a(((1,8),(4,5)),((2,7),(3,6)))\u3002\n
    \n\n

     

    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u7684\u8303\u56f4\u662f [2, 212].
    2. \n\t
    3. \u4fdd\u8bc1 n \u53ef\u4ee5\u5199\u6210 2k \u7684\u5f62\u5f0f\uff0c\u5176\u4e2d k \u662f\u6b63\u6574\u6570\u3002
    4. \n
    \n\n

     

    \n", "tags_en": ["Recursion", "String"], "tags_cn": ["\u9012\u5f52", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string findContestMatch(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String findContestMatch(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findContestMatch(self, n):\n \"\"\"\n :type n: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findContestMatch(self, n: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * findContestMatch(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string FindContestMatch(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {string}\n */\nvar findContestMatch = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {String}\ndef find_contest_match(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findContestMatch(_ n: Int) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findContestMatch(n int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findContestMatch(n: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findContestMatch(n: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_contest_match(n: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return String\n */\n function findContestMatch($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findContestMatch(n: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-contest-match n)\n (-> exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0544](https://leetcode-cn.com/problems/output-contest-matches)", "[\u8f93\u51fa\u6bd4\u8d5b\u5339\u914d\u5bf9](/solution/0500-0599/0544.Output%20Contest%20Matches/README.md)", "`\u9012\u5f52`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0544](https://leetcode.com/problems/output-contest-matches)", "[Output Contest Matches](/solution/0500-0599/0544.Output%20Contest%20Matches/README_EN.md)", "`Recursion`,`String`", "Medium", "\ud83d\udd12"]}, {"question_id": "0543", "frontend_question_id": "0543", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/diameter-of-binary-tree", "url_en": "https://leetcode.com/problems/diameter-of-binary-tree", "relative_path_cn": "/solution/0500-0599/0543.Diameter%20of%20Binary%20Tree/README.md", "relative_path_en": "/solution/0500-0599/0543.Diameter%20of%20Binary%20Tree/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u7684\u76f4\u5f84", "title_en": "Diameter of Binary Tree", "question_title_slug": "diameter-of-binary-tree", "content_en": "

    Given the root of a binary tree, return the length of the diameter of the tree.

    \n\n

    The diameter of a binary tree is the length of the longest path between any two nodes in a tree. This path may or may not pass through the root.

    \n\n

    The length of a path between two nodes is represented by the number of edges between them.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,2,3,4,5]\nOutput: 3\nExplanation: 3is the length of the path [4,2,1,3] or [5,2,1,3].\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = [1,2]\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 104].
    • \n\t
    • -100 <= Node.val <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u68f5\u4e8c\u53c9\u6811\uff0c\u4f60\u9700\u8981\u8ba1\u7b97\u5b83\u7684\u76f4\u5f84\u957f\u5ea6\u3002\u4e00\u68f5\u4e8c\u53c9\u6811\u7684\u76f4\u5f84\u957f\u5ea6\u662f\u4efb\u610f\u4e24\u4e2a\u7ed3\u70b9\u8def\u5f84\u957f\u5ea6\u4e2d\u7684\u6700\u5927\u503c\u3002\u8fd9\u6761\u8def\u5f84\u53ef\u80fd\u7a7f\u8fc7\u4e5f\u53ef\u80fd\u4e0d\u7a7f\u8fc7\u6839\u7ed3\u70b9\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b :
    \n\u7ed9\u5b9a\u4e8c\u53c9\u6811

    \n\n
              1\n         / \\\n        2   3\n       / \\     \n      4   5    \n
    \n\n

    \u8fd4\u56de 3, \u5b83\u7684\u957f\u5ea6\u662f\u8def\u5f84 [4,2,1,3] \u6216\u8005 [5,2,1,3]\u3002

    \n\n

     

    \n\n

    \u6ce8\u610f\uff1a\u4e24\u7ed3\u70b9\u4e4b\u95f4\u7684\u8def\u5f84\u957f\u5ea6\u662f\u4ee5\u5b83\u4eec\u4e4b\u95f4\u8fb9\u7684\u6570\u76ee\u8868\u793a\u3002

    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int diameterOfBinaryTree(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int diameterOfBinaryTree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def diameterOfBinaryTree(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def diameterOfBinaryTree(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint diameterOfBinaryTree(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int DiameterOfBinaryTree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar diameterOfBinaryTree = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef diameter_of_binary_tree(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func diameterOfBinaryTree(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc diameterOfBinaryTree(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def diameterOfBinaryTree(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun diameterOfBinaryTree(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn diameter_of_binary_tree(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function diameterOfBinaryTree($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction diameterOfBinaryTree(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (diameter-of-binary-tree root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0543](https://leetcode-cn.com/problems/diameter-of-binary-tree)", "[\u4e8c\u53c9\u6811\u7684\u76f4\u5f84](/solution/0500-0599/0543.Diameter%20of%20Binary%20Tree/README.md)", "`\u6811`", "\u7b80\u5355", ""], "md_table_row_en": ["[0543](https://leetcode.com/problems/diameter-of-binary-tree)", "[Diameter of Binary Tree](/solution/0500-0599/0543.Diameter%20of%20Binary%20Tree/README_EN.md)", "`Tree`", "Easy", ""]}, {"question_id": "0542", "frontend_question_id": "0542", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/01-matrix", "url_en": "https://leetcode.com/problems/01-matrix", "relative_path_cn": "/solution/0500-0599/0542.01%20Matrix/README.md", "relative_path_en": "/solution/0500-0599/0542.01%20Matrix/README_EN.md", "title_cn": "01 \u77e9\u9635", "title_en": "01 Matrix", "question_title_slug": "01-matrix", "content_en": "

    Given an m x n binary matrix mat, return the distance of the nearest 0 for each cell.

    \n\n

    The distance between two adjacent cells is 1.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: mat = [[0,0,0],[0,1,0],[0,0,0]]\nOutput: [[0,0,0],[0,1,0],[0,0,0]]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: mat = [[0,0,0],[0,1,0],[1,1,1]]\nOutput: [[0,0,0],[0,1,0],[1,2,1]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == mat.length
    • \n\t
    • n == mat[i].length
    • \n\t
    • 1 <= m, n <= 104
    • \n\t
    • 1 <= m * n <= 104
    • \n\t
    • mat[i][j] is either 0 or 1.
    • \n\t
    • There is at least one 0 in mat.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u7531 0 \u548c 1 \u7ec4\u6210\u7684\u77e9\u9635\uff0c\u627e\u51fa\u6bcf\u4e2a\u5143\u7d20\u5230\u6700\u8fd1\u7684 0 \u7684\u8ddd\u79bb\u3002

    \n\n

    \u4e24\u4e2a\u76f8\u90bb\u5143\u7d20\u95f4\u7684\u8ddd\u79bb\u4e3a 1 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\n[[0,0,0],\n [0,1,0],\n [0,0,0]]\n\n\u8f93\u51fa\uff1a\n[[0,0,0],\n\u00a0[0,1,0],\n\u00a0[0,0,0]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\n[[0,0,0],\n [0,1,0],\n [1,1,1]]\n\n\u8f93\u51fa\uff1a\n[[0,0,0],\n [0,1,0],\n [1,2,1]]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u7ed9\u5b9a\u77e9\u9635\u7684\u5143\u7d20\u4e2a\u6570\u4e0d\u8d85\u8fc7 10000\u3002
    • \n\t
    • \u7ed9\u5b9a\u77e9\u9635\u4e2d\u81f3\u5c11\u6709\u4e00\u4e2a\u5143\u7d20\u662f 0\u3002
    • \n\t
    • \u77e9\u9635\u4e2d\u7684\u5143\u7d20\u53ea\u5728\u56db\u4e2a\u65b9\u5411\u4e0a\u76f8\u90bb: \u4e0a\u3001\u4e0b\u3001\u5de6\u3001\u53f3\u3002
    • \n
    \n", "tags_en": ["Depth-first Search", "Breadth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> updateMatrix(vector>& mat) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[][] updateMatrix(int[][] mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def updateMatrix(self, mat):\n \"\"\"\n :type mat: List[List[int]]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def updateMatrix(self, mat: List[List[int]]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** updateMatrix(int** mat, int matSize, int* matColSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[][] UpdateMatrix(int[][] mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} mat\n * @return {number[][]}\n */\nvar updateMatrix = function(mat) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} mat\n# @return {Integer[][]}\ndef update_matrix(mat)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func updateMatrix(_ mat: [[Int]]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func updateMatrix(mat [][]int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def updateMatrix(mat: Array[Array[Int]]): Array[Array[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun updateMatrix(mat: Array): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn update_matrix(mat: Vec>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $mat\n * @return Integer[][]\n */\n function updateMatrix($mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function updateMatrix(mat: number[][]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (update-matrix mat)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0542](https://leetcode-cn.com/problems/01-matrix)", "[01 \u77e9\u9635](/solution/0500-0599/0542.01%20Matrix/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0542](https://leetcode.com/problems/01-matrix)", "[01 Matrix](/solution/0500-0599/0542.01%20Matrix/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`", "Medium", ""]}, {"question_id": "0541", "frontend_question_id": "0541", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reverse-string-ii", "url_en": "https://leetcode.com/problems/reverse-string-ii", "relative_path_cn": "/solution/0500-0599/0541.Reverse%20String%20II/README.md", "relative_path_en": "/solution/0500-0599/0541.Reverse%20String%20II/README_EN.md", "title_cn": "\u53cd\u8f6c\u5b57\u7b26\u4e32 II", "title_en": "Reverse String II", "question_title_slug": "reverse-string-ii", "content_en": "

    Given a string s and an integer k, reverse the first k characters for every 2k characters counting from the start of the string.

    \n\n

    If there are fewer than k characters left, reverse all of them. If there are less than 2k but greater than or equal to k characters, then reverse the first k characters and left the other as original.

    \n\n

     

    \n

    Example 1:

    \n
    Input: s = \"abcdefg\", k = 2\nOutput: \"bacdfeg\"\n

    Example 2:

    \n
    Input: s = \"abcd\", k = 2\nOutput: \"bacd\"\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 104
    • \n\t
    • s consists of only lowercase English letters.
    • \n\t
    • 1 <= k <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32 s \u548c\u4e00\u4e2a\u6574\u6570 k\uff0c\u4f60\u9700\u8981\u5bf9\u4ece\u5b57\u7b26\u4e32\u5f00\u5934\u7b97\u8d77\u7684\u6bcf\u9694 2k \u4e2a\u5b57\u7b26\u7684\u524d k \u4e2a\u5b57\u7b26\u8fdb\u884c\u53cd\u8f6c\u3002

    \n\n
      \n\t
    • \u5982\u679c\u5269\u4f59\u5b57\u7b26\u5c11\u4e8e k \u4e2a\uff0c\u5219\u5c06\u5269\u4f59\u5b57\u7b26\u5168\u90e8\u53cd\u8f6c\u3002
    • \n\t
    • \u5982\u679c\u5269\u4f59\u5b57\u7b26\u5c0f\u4e8e 2k \u4f46\u5927\u4e8e\u6216\u7b49\u4e8e k \u4e2a\uff0c\u5219\u53cd\u8f6c\u524d k \u4e2a\u5b57\u7b26\uff0c\u5176\u4f59\u5b57\u7b26\u4fdd\u6301\u539f\u6837\u3002
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: s = "abcdefg", k = 2\n\u8f93\u51fa: "bacdfeg"\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. \u8be5\u5b57\u7b26\u4e32\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    2. \n\t
    3. \u7ed9\u5b9a\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u548c k \u5728 [1, 10000] \u8303\u56f4\u5185\u3002
    4. \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string reverseStr(string s, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String reverseStr(String s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def reverseStr(self, s, k):\n \"\"\"\n :type s: str\n :type k: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def reverseStr(self, s: str, k: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * reverseStr(char * s, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ReverseStr(string s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number} k\n * @return {string}\n */\nvar reverseStr = function(s, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer} k\n# @return {String}\ndef reverse_str(s, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func reverseStr(_ s: String, _ k: Int) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func reverseStr(s string, k int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def reverseStr(s: String, k: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun reverseStr(s: String, k: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn reverse_str(s: String, k: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer $k\n * @return String\n */\n function reverseStr($s, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function reverseStr(s: string, k: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (reverse-str s k)\n (-> string? exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0541](https://leetcode-cn.com/problems/reverse-string-ii)", "[\u53cd\u8f6c\u5b57\u7b26\u4e32 II](/solution/0500-0599/0541.Reverse%20String%20II/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0541](https://leetcode.com/problems/reverse-string-ii)", "[Reverse String II](/solution/0500-0599/0541.Reverse%20String%20II/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "0540", "frontend_question_id": "0540", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/single-element-in-a-sorted-array", "url_en": "https://leetcode.com/problems/single-element-in-a-sorted-array", "relative_path_cn": "/solution/0500-0599/0540.Single%20Element%20in%20a%20Sorted%20Array/README.md", "relative_path_en": "/solution/0500-0599/0540.Single%20Element%20in%20a%20Sorted%20Array/README_EN.md", "title_cn": "\u6709\u5e8f\u6570\u7ec4\u4e2d\u7684\u5355\u4e00\u5143\u7d20", "title_en": "Single Element in a Sorted Array", "question_title_slug": "single-element-in-a-sorted-array", "content_en": "

    You are given a sorted array consisting of only integers where every element appears exactly twice, except for one element which appears exactly once. Find this single element that appears only once.

    \r\n\r\n

    Follow up: Your solution should run in O(log n) time and O(1) space.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n
    Input: nums = [1,1,2,3,3,4,4,8,8]\r\nOutput: 2\r\n

    Example 2:

    \r\n
    Input: nums = [3,3,7,7,10,11,11]\r\nOutput: 10\r\n
    \r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • 1 <= nums.length <= 10^5
    • \r\n\t
    • 0 <= nums[i] <= 10^5
    • \r\n
    ", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u53ea\u5305\u542b\u6574\u6570\u7684\u6709\u5e8f\u6570\u7ec4\uff0c\u6bcf\u4e2a\u5143\u7d20\u90fd\u4f1a\u51fa\u73b0\u4e24\u6b21\uff0c\u552f\u6709\u4e00\u4e2a\u6570\u53ea\u4f1a\u51fa\u73b0\u4e00\u6b21\uff0c\u627e\u51fa\u8fd9\u4e2a\u6570\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: [1,1,2,3,3,4,4,8,8]\n\u8f93\u51fa: 2\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: [3,3,7,7,10,11,11]\n\u8f93\u51fa: 10\n
    \n\n

    \u6ce8\u610f: \u60a8\u7684\u65b9\u6848\u5e94\u8be5\u5728 O(log n)\u65f6\u95f4\u590d\u6742\u5ea6\u548c O(1)\u7a7a\u95f4\u590d\u6742\u5ea6\u4e2d\u8fd0\u884c\u3002

    \n", "tags_en": ["Binary Search"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int singleNonDuplicate(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int singleNonDuplicate(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def singleNonDuplicate(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def singleNonDuplicate(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint singleNonDuplicate(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SingleNonDuplicate(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar singleNonDuplicate = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef single_non_duplicate(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func singleNonDuplicate(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func singleNonDuplicate(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def singleNonDuplicate(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun singleNonDuplicate(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn single_non_duplicate(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function singleNonDuplicate($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function singleNonDuplicate(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (single-non-duplicate nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0540](https://leetcode-cn.com/problems/single-element-in-a-sorted-array)", "[\u6709\u5e8f\u6570\u7ec4\u4e2d\u7684\u5355\u4e00\u5143\u7d20](/solution/0500-0599/0540.Single%20Element%20in%20a%20Sorted%20Array/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0540](https://leetcode.com/problems/single-element-in-a-sorted-array)", "[Single Element in a Sorted Array](/solution/0500-0599/0540.Single%20Element%20in%20a%20Sorted%20Array/README_EN.md)", "`Binary Search`", "Medium", ""]}, {"question_id": "0539", "frontend_question_id": "0539", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-time-difference", "url_en": "https://leetcode.com/problems/minimum-time-difference", "relative_path_cn": "/solution/0500-0599/0539.Minimum%20Time%20Difference/README.md", "relative_path_en": "/solution/0500-0599/0539.Minimum%20Time%20Difference/README_EN.md", "title_cn": "\u6700\u5c0f\u65f6\u95f4\u5dee", "title_en": "Minimum Time Difference", "question_title_slug": "minimum-time-difference", "content_en": "Given a list of 24-hour clock time points in "HH:MM" format, return the minimum minutes difference between any two time-points in the list.\n

     

    \n

    Example 1:

    \n
    Input: timePoints = [\"23:59\",\"00:00\"]\nOutput: 1\n

    Example 2:

    \n
    Input: timePoints = [\"00:00\",\"23:59\",\"00:00\"]\nOutput: 0\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= timePoints <= 2 * 104
    • \n\t
    • timePoints[i] is in the format "HH:MM".
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a 24 \u5c0f\u65f6\u5236\uff08\u5c0f\u65f6:\u5206\u949f \"HH:MM\"\uff09\u7684\u65f6\u95f4\u5217\u8868\uff0c\u627e\u51fa\u5217\u8868\u4e2d\u4efb\u610f\u4e24\u4e2a\u65f6\u95f4\u7684\u6700\u5c0f\u65f6\u95f4\u5dee\u5e76\u4ee5\u5206\u949f\u6570\u8868\u793a\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1atimePoints = [\"23:59\",\"00:00\"]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1atimePoints = [\"00:00\",\"23:59\",\"00:00\"]\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= timePoints <= 2 * 104
    • \n\t
    • timePoints[i] \u683c\u5f0f\u4e3a \"HH:MM\"
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findMinDifference(vector& timePoints) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findMinDifference(List timePoints) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findMinDifference(self, timePoints):\n \"\"\"\n :type timePoints: List[str]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findMinDifference(self, timePoints: List[str]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findMinDifference(char ** timePoints, int timePointsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindMinDifference(IList timePoints) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} timePoints\n * @return {number}\n */\nvar findMinDifference = function(timePoints) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} time_points\n# @return {Integer}\ndef find_min_difference(time_points)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findMinDifference(_ timePoints: [String]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findMinDifference(timePoints []string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findMinDifference(timePoints: List[String]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findMinDifference(timePoints: List): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_min_difference(time_points: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $timePoints\n * @return Integer\n */\n function findMinDifference($timePoints) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findMinDifference(timePoints: string[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-min-difference timePoints)\n (-> (listof string?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0539](https://leetcode-cn.com/problems/minimum-time-difference)", "[\u6700\u5c0f\u65f6\u95f4\u5dee](/solution/0500-0599/0539.Minimum%20Time%20Difference/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0539](https://leetcode.com/problems/minimum-time-difference)", "[Minimum Time Difference](/solution/0500-0599/0539.Minimum%20Time%20Difference/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "0538", "frontend_question_id": "0538", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/convert-bst-to-greater-tree", "url_en": "https://leetcode.com/problems/convert-bst-to-greater-tree", "relative_path_cn": "/solution/0500-0599/0538.Convert%20BST%20to%20Greater%20Tree/README.md", "relative_path_en": "/solution/0500-0599/0538.Convert%20BST%20to%20Greater%20Tree/README_EN.md", "title_cn": "\u628a\u4e8c\u53c9\u641c\u7d22\u6811\u8f6c\u6362\u4e3a\u7d2f\u52a0\u6811", "title_en": "Convert BST to Greater Tree", "question_title_slug": "convert-bst-to-greater-tree", "content_en": "

    Given the root of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus sum of all keys greater than the original key in BST.

    \r\n\r\n

    As a reminder, a binary search tree is a tree that satisfies these constraints:

    \r\n\r\n
      \r\n\t
    • The left subtree of a node contains only nodes with keys less than the node's key.
    • \r\n\t
    • The right subtree of a node contains only nodes with keys greater than the node's key.
    • \r\n\t
    • Both the left and right subtrees must also be binary search trees.
    • \r\n
    \r\n\r\n

    Note: This question is the same as 1038: https://leetcode.com/problems/binary-search-tree-to-greater-sum-tree/

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\"\"\r\n
    \r\nInput: root = [4,1,6,0,2,5,7,null,null,null,3,null,null,null,8]\r\nOutput: [30,36,21,36,35,26,15,null,null,null,33,null,null,null,8]\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: root = [0,null,1]\r\nOutput: [1,null,1]\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: root = [1,0,2]\r\nOutput: [3,3,2]\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: root = [3,2,4,1]\r\nOutput: [7,9,4,10]\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • The number of nodes in the tree is in the range [0, 104].
    • \r\n\t
    • -104 <= Node.val <= 104
    • \r\n\t
    • All the values in the tree are unique.
    • \r\n\t
    • root is guaranteed to be a valid binary search tree.
    • \r\n
    ", "content_cn": "

    \u7ed9\u51fa\u4e8c\u53c9 \u641c\u7d22 \u6811\u7684\u6839\u8282\u70b9\uff0c\u8be5\u6811\u7684\u8282\u70b9\u503c\u5404\u4e0d\u76f8\u540c\uff0c\u8bf7\u4f60\u5c06\u5176\u8f6c\u6362\u4e3a\u7d2f\u52a0\u6811\uff08Greater Sum Tree\uff09\uff0c\u4f7f\u6bcf\u4e2a\u8282\u70b9 node \u7684\u65b0\u503c\u7b49\u4e8e\u539f\u6811\u4e2d\u5927\u4e8e\u6216\u7b49\u4e8e node.val \u7684\u503c\u4e4b\u548c\u3002

    \n\n

    \u63d0\u9192\u4e00\u4e0b\uff0c\u4e8c\u53c9\u641c\u7d22\u6811\u6ee1\u8db3\u4e0b\u5217\u7ea6\u675f\u6761\u4ef6\uff1a

    \n\n
      \n\t
    • \u8282\u70b9\u7684\u5de6\u5b50\u6811\u4ec5\u5305\u542b\u952e \u5c0f\u4e8e \u8282\u70b9\u952e\u7684\u8282\u70b9\u3002
    • \n\t
    • \u8282\u70b9\u7684\u53f3\u5b50\u6811\u4ec5\u5305\u542b\u952e \u5927\u4e8e \u8282\u70b9\u952e\u7684\u8282\u70b9\u3002
    • \n\t
    • \u5de6\u53f3\u5b50\u6811\u4e5f\u5fc5\u987b\u662f\u4e8c\u53c9\u641c\u7d22\u6811\u3002
    • \n
    \n\n

    \u6ce8\u610f\uff1a\u672c\u9898\u548c 1038: https://leetcode-cn.com/problems/binary-search-tree-to-greater-sum-tree/ \u76f8\u540c

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1a[4,1,6,0,2,5,7,null,null,null,3,null,null,null,8]\n\u8f93\u51fa\uff1a[30,36,21,36,35,26,15,null,null,null,33,null,null,null,8]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aroot = [0,null,1]\n\u8f93\u51fa\uff1a[1,null,1]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aroot = [1,0,2]\n\u8f93\u51fa\uff1a[3,3,2]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1aroot = [3,2,4,1]\n\u8f93\u51fa\uff1a[7,9,4,10]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u7684\u8282\u70b9\u6570\u4ecb\u4e8e 0 \u548c 104 \u4e4b\u95f4\u3002
    • \n\t
    • \u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u4ecb\u4e8e -104 \u548c 104 \u4e4b\u95f4\u3002
    • \n\t
    • \u6811\u4e2d\u7684\u6240\u6709\u503c \u4e92\u4e0d\u76f8\u540c \u3002
    • \n\t
    • \u7ed9\u5b9a\u7684\u6811\u4e3a\u4e8c\u53c9\u641c\u7d22\u6811\u3002
    • \n
    \n", "tags_en": ["Tree", "Depth-first Search", "Binary Search Tree", "Recursion"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u4e8c\u53c9\u641c\u7d22\u6811", "\u9012\u5f52"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* convertBST(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode convertBST(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def convertBST(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: TreeNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def convertBST(self, root: TreeNode) -> TreeNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* convertBST(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode ConvertBST(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {TreeNode}\n */\nvar convertBST = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {TreeNode}\ndef convert_bst(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func convertBST(_ root: TreeNode?) -> TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc convertBST(root *TreeNode) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def convertBST(root: TreeNode): TreeNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun convertBST(root: TreeNode?): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn convert_bst(root: Option>>) -> Option>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return TreeNode\n */\n function convertBST($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction convertBST(root: TreeNode | null): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (convert-bst root)\n (-> (or/c tree-node? #f) (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0538](https://leetcode-cn.com/problems/convert-bst-to-greater-tree)", "[\u628a\u4e8c\u53c9\u641c\u7d22\u6811\u8f6c\u6362\u4e3a\u7d2f\u52a0\u6811](/solution/0500-0599/0538.Convert%20BST%20to%20Greater%20Tree/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u4e8c\u53c9\u641c\u7d22\u6811`,`\u9012\u5f52`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0538](https://leetcode.com/problems/convert-bst-to-greater-tree)", "[Convert BST to Greater Tree](/solution/0500-0599/0538.Convert%20BST%20to%20Greater%20Tree/README_EN.md)", "`Tree`,`Depth-first Search`,`Binary Search Tree`,`Recursion`", "Medium", ""]}, {"question_id": "0537", "frontend_question_id": "0537", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/complex-number-multiplication", "url_en": "https://leetcode.com/problems/complex-number-multiplication", "relative_path_cn": "/solution/0500-0599/0537.Complex%20Number%20Multiplication/README.md", "relative_path_en": "/solution/0500-0599/0537.Complex%20Number%20Multiplication/README_EN.md", "title_cn": "\u590d\u6570\u4e58\u6cd5", "title_en": "Complex Number Multiplication", "question_title_slug": "complex-number-multiplication", "content_en": "

    A complex number can be represented as a string on the form "real+imaginaryi" where:

    \n\n
      \n\t
    • real is the real part and is an integer in the range [-100, 100].
    • \n\t
    • imaginary is the imaginary part and is an integer in the range [-100, 100].
    • \n\t
    • i2 == -1.
    • \n
    \n\n

    Given two complex numbers num1 and num2 as strings, return a string of the complex number that represents their multiplications.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: num1 = "1+1i", num2 = "1+1i"\nOutput: "0+2i"\nExplanation: (1 + i) * (1 + i) = 1 + i2 + 2 * i = 2i, and you need convert it to the form of 0+2i.\n
    \n\n

    Example 2:

    \n\n
    \nInput: num1 = "1+-1i", num2 = "1+-1i"\nOutput: "0+-2i"\nExplanation: (1 - i) * (1 - i) = 1 + i2 - 2 * i = -2i, and you need convert it to the form of 0+-2i.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • num1 and num2 are valid complex numbers.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u8868\u793a\u590d\u6570\u7684\u5b57\u7b26\u4e32\u3002

    \n\n

    \u8fd4\u56de\u8868\u793a\u5b83\u4eec\u4e58\u79ef\u7684\u5b57\u7b26\u4e32\u3002\u6ce8\u610f\uff0c\u6839\u636e\u5b9a\u4e49 i2 = -1 \u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: "1+1i", "1+1i"\n\u8f93\u51fa: "0+2i"\n\u89e3\u91ca: (1 + i) * (1 + i) = 1 + i2 + 2 * i = 2i \uff0c\u4f60\u9700\u8981\u5c06\u5b83\u8f6c\u6362\u4e3a 0+2i \u7684\u5f62\u5f0f\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: "1+-1i", "1+-1i"\n\u8f93\u51fa: "0+-2i"\n\u89e3\u91ca: (1 - i) * (1 - i) = 1 + i2 - 2 * i = -2i \uff0c\u4f60\u9700\u8981\u5c06\u5b83\u8f6c\u6362\u4e3a 0+-2i \u7684\u5f62\u5f0f\u3002 \n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u8f93\u5165\u5b57\u7b26\u4e32\u4e0d\u5305\u542b\u989d\u5916\u7684\u7a7a\u683c\u3002
    2. \n\t
    3. \u8f93\u5165\u5b57\u7b26\u4e32\u5c06\u4ee5 a+bi \u7684\u5f62\u5f0f\u7ed9\u51fa\uff0c\u5176\u4e2d\u6574\u6570 a \u548c b \u7684\u8303\u56f4\u5747\u5728 [-100, 100] \u4e4b\u95f4\u3002\u8f93\u51fa\u4e5f\u5e94\u5f53\u7b26\u5408\u8fd9\u79cd\u5f62\u5f0f\u3002
    4. \n
    \n", "tags_en": ["Math", "String"], "tags_cn": ["\u6570\u5b66", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string complexNumberMultiply(string num1, string num2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String complexNumberMultiply(String num1, String num2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def complexNumberMultiply(self, num1, num2):\n \"\"\"\n :type num1: str\n :type num2: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def complexNumberMultiply(self, num1: str, num2: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * complexNumberMultiply(char * num1, char * num2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ComplexNumberMultiply(string num1, string num2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} num1\n * @param {string} num2\n * @return {string}\n */\nvar complexNumberMultiply = function(num1, num2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} num1\n# @param {String} num2\n# @return {String}\ndef complex_number_multiply(num1, num2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func complexNumberMultiply(_ num1: String, _ num2: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func complexNumberMultiply(num1 string, num2 string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def complexNumberMultiply(num1: String, num2: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun complexNumberMultiply(num1: String, num2: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn complex_number_multiply(num1: String, num2: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $num1\n * @param String $num2\n * @return String\n */\n function complexNumberMultiply($num1, $num2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function complexNumberMultiply(num1: string, num2: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (complex-number-multiply num1 num2)\n (-> string? string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0537](https://leetcode-cn.com/problems/complex-number-multiplication)", "[\u590d\u6570\u4e58\u6cd5](/solution/0500-0599/0537.Complex%20Number%20Multiplication/README.md)", "`\u6570\u5b66`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0537](https://leetcode.com/problems/complex-number-multiplication)", "[Complex Number Multiplication](/solution/0500-0599/0537.Complex%20Number%20Multiplication/README_EN.md)", "`Math`,`String`", "Medium", ""]}, {"question_id": "0536", "frontend_question_id": "0536", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/construct-binary-tree-from-string", "url_en": "https://leetcode.com/problems/construct-binary-tree-from-string", "relative_path_cn": "/solution/0500-0599/0536.Construct%20Binary%20Tree%20from%20String/README.md", "relative_path_en": "/solution/0500-0599/0536.Construct%20Binary%20Tree%20from%20String/README_EN.md", "title_cn": "\u4ece\u5b57\u7b26\u4e32\u751f\u6210\u4e8c\u53c9\u6811", "title_en": "Construct Binary Tree from String", "question_title_slug": "construct-binary-tree-from-string", "content_en": "

    You need to construct a binary tree from a string consisting of parenthesis and integers.

    \n\n

    The whole input represents a binary tree. It contains an integer followed by zero, one or two pairs of parenthesis. The integer represents the root's value and a pair of parenthesis contains a child binary tree with the same structure.

    \n\n

    You always start to construct the left child node of the parent first if it exists.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: s = "4(2(3)(1))(6(5))"\nOutput: [4,2,6,3,1,5]\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "4(2(3)(1))(6(5)(7))"\nOutput: [4,2,6,3,1,5,7]\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "-4(2(3)(1))(6(5)(7))"\nOutput: [-4,2,6,3,1,5,7]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= s.length <= 3 * 104
    • \n\t
    • s consists of digits, '(', ')', and '-' only.
    • \n
    \n", "content_cn": "

    \u4f60\u9700\u8981\u4ece\u4e00\u4e2a\u5305\u62ec\u62ec\u53f7\u548c\u6574\u6570\u7684\u5b57\u7b26\u4e32\u6784\u5efa\u4e00\u68f5\u4e8c\u53c9\u6811\u3002

    \n\n

    \u8f93\u5165\u7684\u5b57\u7b26\u4e32\u4ee3\u8868\u4e00\u68f5\u4e8c\u53c9\u6811\u3002\u5b83\u5305\u62ec\u6574\u6570\u548c\u968f\u540e\u7684 0 \uff0c1 \u6216 2 \u5bf9\u62ec\u53f7\u3002\u6574\u6570\u4ee3\u8868\u6839\u7684\u503c\uff0c\u4e00\u5bf9\u62ec\u53f7\u5185\u8868\u793a\u540c\u6837\u7ed3\u6784\u7684\u5b50\u6811\u3002

    \n\n

    \u82e5\u5b58\u5728\u5de6\u5b50\u7ed3\u70b9\uff0c\u5219\u4ece\u5de6\u5b50\u7ed3\u70b9\u5f00\u59cb\u6784\u5efa\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1a"4(2(3)(1))(6(5))"\n\u8f93\u51fa\uff1a\u8fd4\u56de\u4ee3\u8868\u4e0b\u5217\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9:\n\n       4\n     /   \\\n    2     6\n   / \\   / \n  3   1 5   \n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u8f93\u5165\u5b57\u7b26\u4e32\u4e2d\u53ea\u5305\u542b '(', ')', '-' \u548c '0' ~ '9' 
    • \n\t
    • \u7a7a\u6811\u7531 "" \u800c\u975e"()"\u8868\u793a\u3002
    • \n
    \n\n

     

    \n", "tags_en": ["Tree", "String"], "tags_cn": ["\u6811", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* str2tree(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode str2tree(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def str2tree(self, s):\n \"\"\"\n :type s: str\n :rtype: TreeNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def str2tree(self, s: str) -> TreeNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* str2tree(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode Str2tree(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {string} s\n * @return {TreeNode}\n */\nvar str2tree = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {String} s\n# @return {TreeNode}\ndef str2tree(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func str2tree(_ s: String) -> TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc str2tree(s string) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def str2tree(s: String): TreeNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun str2tree(s: String): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn str2tree(s: String) -> Option>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param String $s\n * @return TreeNode\n */\n function str2tree($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction str2tree(s: string): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (str2tree s)\n (-> string? (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0536](https://leetcode-cn.com/problems/construct-binary-tree-from-string)", "[\u4ece\u5b57\u7b26\u4e32\u751f\u6210\u4e8c\u53c9\u6811](/solution/0500-0599/0536.Construct%20Binary%20Tree%20from%20String/README.md)", "`\u6811`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0536](https://leetcode.com/problems/construct-binary-tree-from-string)", "[Construct Binary Tree from String](/solution/0500-0599/0536.Construct%20Binary%20Tree%20from%20String/README_EN.md)", "`Tree`,`String`", "Medium", "\ud83d\udd12"]}, {"question_id": "0535", "frontend_question_id": "0535", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/encode-and-decode-tinyurl", "url_en": "https://leetcode.com/problems/encode-and-decode-tinyurl", "relative_path_cn": "/solution/0500-0599/0535.Encode%20and%20Decode%20TinyURL/README.md", "relative_path_en": "/solution/0500-0599/0535.Encode%20and%20Decode%20TinyURL/README_EN.md", "title_cn": "TinyURL \u7684\u52a0\u5bc6\u4e0e\u89e3\u5bc6", "title_en": "Encode and Decode TinyURL", "question_title_slug": "encode-and-decode-tinyurl", "content_en": "
    Note: This is a companion problem to the System Design problem: Design TinyURL.
    \n\n

    TinyURL is a URL shortening service where you enter a URL such as https://leetcode.com/problems/design-tinyurl and it returns a short URL such as http://tinyurl.com/4e9iAk. Design a class to encode a URL and decode a tiny URL.

    \n\n

    There is no restriction on how your encode/decode algorithm should work. You just need to ensure that a URL can be encoded to a tiny URL and the tiny URL can be decoded to the original URL.

    \n\n

    Implement the Solution class:

    \n\n
      \n\t
    • Solution() Initializes the object of the system.
    • \n\t
    • String encode(String longUrl) Returns a tiny URL for the given longUrl.
    • \n\t
    • String decode(String shortUrl) Returns the original long URL for the given shortUrl. It is guaranteed that the given shortUrl was encoded by the same object.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: url = "https://leetcode.com/problems/design-tinyurl"\nOutput: "https://leetcode.com/problems/design-tinyurl"\n\nExplanation:\nSolution obj = new Solution();\nstring tiny = obj.encode(url); // returns the encoded tiny url.\nstring ans = obj.decode(tiny); // returns the original url after deconding it.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= url.length <= 104
    • \n\t
    • url is guranteed to be a valid URL.
    • \n
    \n", "content_cn": "

    TinyURL\u662f\u4e00\u79cdURL\u7b80\u5316\u670d\u52a1\uff0c \u6bd4\u5982\uff1a\u5f53\u4f60\u8f93\u5165\u4e00\u4e2aURL https://leetcode.com/problems/design-tinyurl \u65f6\uff0c\u5b83\u5c06\u8fd4\u56de\u4e00\u4e2a\u7b80\u5316\u7684URL http://tinyurl.com/4e9iAk.

    \n\n

    \u8981\u6c42\uff1a\u8bbe\u8ba1\u4e00\u4e2a TinyURL \u7684\u52a0\u5bc6 encode \u548c\u89e3\u5bc6 decode \u7684\u65b9\u6cd5\u3002\u4f60\u7684\u52a0\u5bc6\u548c\u89e3\u5bc6\u7b97\u6cd5\u5982\u4f55\u8bbe\u8ba1\u548c\u8fd0\u4f5c\u662f\u6ca1\u6709\u9650\u5236\u7684\uff0c\u4f60\u53ea\u9700\u8981\u4fdd\u8bc1\u4e00\u4e2aURL\u53ef\u4ee5\u88ab\u52a0\u5bc6\u6210\u4e00\u4e2aTinyURL\uff0c\u5e76\u4e14\u8fd9\u4e2aTinyURL\u53ef\u4ee5\u7528\u89e3\u5bc6\u65b9\u6cd5\u6062\u590d\u6210\u539f\u672c\u7684URL\u3002

    \n", "tags_en": ["Hash Table", "Math"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n\n // Encodes a URL to a shortened URL.\n string encode(string longUrl) {\n \n }\n\n // Decodes a shortened URL to its original URL.\n string decode(string shortUrl) {\n \n }\n};\n\n// Your Solution object will be instantiated and called as such:\n// Solution solution;\n// solution.decode(solution.encode(url));", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "public class Codec {\n\n // Encodes a URL to a shortened URL.\n public String encode(String longUrl) {\n \n }\n\n // Decodes a shortened URL to its original URL.\n public String decode(String shortUrl) {\n \n }\n}\n\n// Your Codec object will be instantiated and called as such:\n// Codec codec = new Codec();\n// codec.decode(codec.encode(url));", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Codec:\n\n def encode(self, longUrl):\n \"\"\"Encodes a URL to a shortened URL.\n \n :type longUrl: str\n :rtype: str\n \"\"\"\n \n\n def decode(self, shortUrl):\n \"\"\"Decodes a shortened URL to its original URL.\n \n :type shortUrl: str\n :rtype: str\n \"\"\"\n \n\n# Your Codec object will be instantiated and called as such:\n# codec = Codec()\n# codec.decode(codec.encode(url))", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Codec:\n\n def encode(self, longUrl: str) -> str:\n \"\"\"Encodes a URL to a shortened URL.\n \"\"\"\n \n\n def decode(self, shortUrl: str) -> str:\n \"\"\"Decodes a shortened URL to its original URL.\n \"\"\"\n \n\n# Your Codec object will be instantiated and called as such:\n# codec = Codec()\n# codec.decode(codec.encode(url))", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/** Encodes a URL to a shortened URL. */\nchar* encode(char* longUrl) {\n \n}\n\n/** Decodes a shortened URL to its original URL. */\nchar* decode(char* shortUrl) {\n \n}\n\n// Your functions will be called as such:\n// char* s = encode(s);\n// decode(s);", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Codec {\n\n // Encodes a URL to a shortened URL\n public string encode(string longUrl) {\n \n }\n\n // Decodes a shortened URL to its original URL.\n public string decode(string shortUrl) {\n \n }\n}\n\n// Your Codec object will be instantiated and called as such:\n// Codec codec = new Codec();\n// codec.decode(codec.encode(url));", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Encodes a URL to a shortened URL.\n *\n * @param {string} longUrl\n * @return {string}\n */\nvar encode = function(longUrl) {\n \n};\n\n/**\n * Decodes a shortened URL to its original URL.\n *\n * @param {string} shortUrl\n * @return {string}\n */\nvar decode = function(shortUrl) {\n \n};\n\n/**\n * Your functions will be called as such:\n * decode(encode(url));\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Encodes a URL to a shortened URL.\n#\n# @param {string} longUrl\n# @return {string}\ndef encode(longUrl)\n \nend\n\n# Decodes a shortened URL to its original URL.\n#\n# @param {string} shortUrl\n# @return {string}\ndef decode(shortUrl)\n \nend\n\n\n# Your functions will be called as such:\n# decode(encode(url))", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Codec {\n // Encodes a URL to a shortened URL.\n func encode(_ longUrl: String) -> String {\n \n }\n \n // Decodes a shortened URL to its original URL.\n func decode(_ shortUrl: String) -> String {\n \n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * let obj = Codec()\n * val s = obj.encode(longUrl)\n * let ans = obj.decode(s)\n*/", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type Codec struct {\n \n}\n\n\nfunc Constructor() Codec {\n \n}\n\n// Encodes a URL to a shortened URL.\nfunc (this *Codec) encode(longUrl string) string {\n\t\n}\n\n// Decodes a shortened URL to its original URL.\nfunc (this *Codec) decode(shortUrl string) string {\n \n}\n\n\n/**\n * Your Codec object will be instantiated and called as such:\n * obj := Constructor();\n * url := obj.encode(longUrl);\n * ans := obj.decode(url);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class Codec {\n // Encodes a URL to a shortened URL.\n def encode(longURL: String): String = {\n \n }\n \n // Decodes a shortened URL to its original URL.\n def decode(shortURL: String): String = {\n \n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * var obj = new Codec()\n * val s = obj.encode(longURL)\n * val ans = obj.decode(s)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Codec() {\n // Encodes a URL to a shortened URL.\n fun encode(longUrl: String): String {\n \n }\n\n // Decodes a shortened URL to its original URL.\n fun decode(shortUrl: String): String {\n \n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * var obj = Codec()\n * var url = obj.encode(longUrl)\n * var ans = obj.decode(url)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct Codec {\n\t\n}\n\n/** \n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl Codec {\n fn new() -> Self {\n \n }\n\t\n // Encodes a URL to a shortened URL.\n fn encode(&self, longURL: String) -> String {\n \n }\n\t\n // Decodes a shortened URL to its original URL.\n fn decode(&self, shortURL: String) -> String {\n \n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * let obj = Codec::new();\n * let s: String = obj.encode(strs);\n * let ans: VecVec = obj.decode(s);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Codec {\n /**\n * Encodes a URL to a shortened URL.\n * @param String $longUrl\n * @return String\n */\n function encode($longUrl) {\n \n }\n \n /**\n * Decodes a shortened URL to its original URL.\n * @param String $shortUrl\n * @return String\n */\n function decode($shortUrl) {\n \n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * $obj = Codec();\n * $s = $obj->encode($longUrl);\n * $ans = $obj->decode($s);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Encodes a URL to a shortened URL.\n */\nfunction encode(longUrl: string): string {\n\t\n};\n\n/**\n * Decodes a shortened URL to its original URL.\n */\nfunction decode(shortUrl: string): string {\n\t\n};\n\n/**\n * Your functions will be called as such:\n * decode(encode(strs));\n */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0535](https://leetcode-cn.com/problems/encode-and-decode-tinyurl)", "[TinyURL \u7684\u52a0\u5bc6\u4e0e\u89e3\u5bc6](/solution/0500-0599/0535.Encode%20and%20Decode%20TinyURL/README.md)", "`\u54c8\u5e0c\u8868`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0535](https://leetcode.com/problems/encode-and-decode-tinyurl)", "[Encode and Decode TinyURL](/solution/0500-0599/0535.Encode%20and%20Decode%20TinyURL/README_EN.md)", "`Hash Table`,`Math`", "Medium", ""]}, {"question_id": "0533", "frontend_question_id": "0533", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/lonely-pixel-ii", "url_en": "https://leetcode.com/problems/lonely-pixel-ii", "relative_path_cn": "/solution/0500-0599/0533.Lonely%20Pixel%20II/README.md", "relative_path_en": "/solution/0500-0599/0533.Lonely%20Pixel%20II/README_EN.md", "title_cn": "\u5b64\u72ec\u50cf\u7d20 II", "title_en": "Lonely Pixel II", "question_title_slug": "lonely-pixel-ii", "content_en": "

    Given an m x n picture consisting of black 'B' and white 'W' pixels and an integer target, return the number of black lonely pixels.

    \n\n

    A black lonely pixel is a character 'B' that located at a specific position (r, c) where:

    \n\n
      \n\t
    • Row r and column c both contain exactly target black pixels.
    • \n\t
    • For all rows that have a black pixel at column c, they should be exactly the same as row r.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: picture = [["W","B","W","B","B","W"],["W","B","W","B","B","W"],["W","B","W","B","B","W"],["W","W","B","W","B","W"]], target = 3\nOutput: 6\nExplanation: All the green 'B' are the black pixels we need (all 'B's at column 1 and 3).\nTake 'B' at row r = 0 and column c = 1 as an example:\n - Rule 1, row r = 0 and column c = 1 both have exactly target = 3 black pixels. \n - Rule 2, the rows have black pixel at column c = 1 are row 0, row 1 and row 2. They are exactly the same as row r = 0.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: picture = [["W","W","B"],["W","W","B"],["W","W","B"]], target = 1\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == picture.length
    • \n\t
    • n == picture[i].length
    • \n\t
    • 1 <= m, n <= 200
    • \n\t
    • picture[i][j] is 'W' or 'B'.
    • \n\t
    • 1 <= target <= min(m, n)
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u5e45\u7531\u9ed1\u8272\u50cf\u7d20\u548c\u767d\u8272\u50cf\u7d20\u7ec4\u6210\u7684\u56fe\u50cf\uff0c \u4e0e\u4e00\u4e2a\u6b63\u6574\u6570N, \u627e\u5230\u4f4d\u4e8e\u67d0\u884c R \u548c\u67d0\u5217 C \u4e2d\u4e14\u7b26\u5408\u4e0b\u5217\u89c4\u5219\u7684\u9ed1\u8272\u50cf\u7d20\u7684\u6570\u91cf:

    \n\n
      \n\t
    1. \u884cR \u548c\u5217C\u90fd\u6070\u597d\u5305\u62ecN\u4e2a\u9ed1\u8272\u50cf\u7d20\u3002
    2. \n\t
    3. \u5217C\u4e2d\u6240\u6709\u9ed1\u8272\u50cf\u7d20\u6240\u5728\u7684\u884c\u5fc5\u987b\u548c\u884cR\u5b8c\u5168\u76f8\u540c\u3002
    4. \n
    \n\n

    \u56fe\u50cf\u7531\u4e00\u4e2a\u7531‘B’\u548c‘W’\u7ec4\u6210\u4e8c\u7ef4\u5b57\u7b26\u6570\u7ec4\u8868\u793a, ‘B’\u548c‘W’\u5206\u522b\u4ee3\u8868\u9ed1\u8272\u50cf\u7d20\u548c\u767d\u8272\u50cf\u7d20\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165:                                            \n[['W', 'B', 'W', 'B', 'B', 'W'],    \n ['W', 'B', 'W', 'B', 'B', 'W'],    \n ['W', 'B', 'W', 'B', 'B', 'W'],    \n ['W', 'W', 'B', 'W', 'B', 'W']] \n\nN = 3\n\u8f93\u51fa: 6\n\u89e3\u6790: \u6240\u6709\u7c97\u4f53\u7684'B'\u90fd\u662f\u6211\u4eec\u6240\u6c42\u7684\u50cf\u7d20(\u7b2c1\u5217\u548c\u7b2c3\u5217\u7684\u6240\u6709'B').\n        0    1    2    3    4    5         \u5217\u53f7                                          \n0    [['W', 'B', 'W', 'B', 'B', 'W'],    \n1     ['W', 'B', 'W', 'B', 'B', 'W'],    \n2     ['W', 'B', 'W', 'B', 'B', 'W'],    \n3     ['W', 'W', 'B', 'W', 'B', 'W']]    \n\u884c\u53f7\n\n\u4ee5R = 0\u884c\u548cC = 1\u5217\u7684'B'\u4e3a\u4f8b:\n\u89c4\u5219 1\uff0cR = 0\u884c\u548cC = 1\u5217\u90fd\u6070\u597d\u6709N = 3\u4e2a\u9ed1\u8272\u50cf\u7d20. \n\u89c4\u5219 2\uff0c\u5728C = 1\u5217\u7684\u9ed1\u8272\u50cf\u7d20\u5206\u522b\u4f4d\u4e8e0\uff0c1\u548c2\u884c\u3002\u5b83\u4eec\u90fd\u548cR = 0\u884c\u5b8c\u5168\u76f8\u540c\u3002\n\n
    \n\n

     

    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u8f93\u5165\u4e8c\u7ef4\u6570\u7ec4\u884c\u548c\u5217\u7684\u8303\u56f4\u662f [1,200]\u3002
    2. \n
    \n\n

     

    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findBlackPixel(vector>& picture, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findBlackPixel(char[][] picture, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findBlackPixel(self, picture, target):\n \"\"\"\n :type picture: List[List[str]]\n :type target: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findBlackPixel(self, picture: List[List[str]], target: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findBlackPixel(char** picture, int pictureSize, int* pictureColSize, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindBlackPixel(char[][] picture, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {character[][]} picture\n * @param {number} target\n * @return {number}\n */\nvar findBlackPixel = function(picture, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Character[][]} picture\n# @param {Integer} target\n# @return {Integer}\ndef find_black_pixel(picture, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findBlackPixel(_ picture: [[Character]], _ target: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findBlackPixel(picture [][]byte, target int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findBlackPixel(picture: Array[Array[Char]], target: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findBlackPixel(picture: Array, target: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_black_pixel(picture: Vec>, target: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $picture\n * @param Integer $target\n * @return Integer\n */\n function findBlackPixel($picture, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findBlackPixel(picture: string[][], target: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-black-pixel picture target)\n (-> (listof (listof char?)) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0533](https://leetcode-cn.com/problems/lonely-pixel-ii)", "[\u5b64\u72ec\u50cf\u7d20 II](/solution/0500-0599/0533.Lonely%20Pixel%20II/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0533](https://leetcode.com/problems/lonely-pixel-ii)", "[Lonely Pixel II](/solution/0500-0599/0533.Lonely%20Pixel%20II/README_EN.md)", "`Array`", "Medium", "\ud83d\udd12"]}, {"question_id": "0532", "frontend_question_id": "0532", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/k-diff-pairs-in-an-array", "url_en": "https://leetcode.com/problems/k-diff-pairs-in-an-array", "relative_path_cn": "/solution/0500-0599/0532.K-diff%20Pairs%20in%20an%20Array/README.md", "relative_path_en": "/solution/0500-0599/0532.K-diff%20Pairs%20in%20an%20Array/README_EN.md", "title_cn": "\u6570\u7ec4\u4e2d\u7684 k-diff \u6570\u5bf9", "title_en": "K-diff Pairs in an Array", "question_title_slug": "k-diff-pairs-in-an-array", "content_en": "

    Given an array of integers nums and an integer k, return the number of unique k-diff pairs in the array.

    \n\n

    A k-diff pair is an integer pair (nums[i], nums[j]), where the following are true:

    \n\n
      \n\t
    • 0 <= i < j < nums.length
    • \n\t
    • |nums[i] - nums[j]| == k
    • \n
    \n\n

    Notice that |val| denotes the absolute value of val.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [3,1,4,1,5], k = 2\nOutput: 2\nExplanation: There are two 2-diff pairs in the array, (1, 3) and (3, 5).\nAlthough we have two 1s in the input, we should only return the number of unique pairs.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,2,3,4,5], k = 1\nOutput: 4\nExplanation: There are four 1-diff pairs in the array, (1, 2), (2, 3), (3, 4) and (4, 5).\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [1,3,1,5,4], k = 0\nOutput: 1\nExplanation: There is one 0-diff pair in the array, (1, 1).\n
    \n\n

    Example 4:

    \n\n
    \nInput: nums = [1,2,4,4,3,3,0,9,2,3], k = 3\nOutput: 2\n
    \n\n

    Example 5:

    \n\n
    \nInput: nums = [-1,-2,-3], k = 1\nOutput: 2\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 104
    • \n\t
    • -107 <= nums[i] <= 107
    • \n\t
    • 0 <= k <= 107
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u548c\u4e00\u4e2a\u6574\u6570\u00a0k\uff0c\u4f60\u9700\u8981\u5728\u6570\u7ec4\u91cc\u627e\u5230 \u4e0d\u540c\u7684\u00a0k-diff \u6570\u5bf9\uff0c\u5e76\u8fd4\u56de\u4e0d\u540c\u7684 k-diff \u6570\u5bf9 \u7684\u6570\u76ee\u3002

    \n\n

    \u8fd9\u91cc\u5c06\u00a0k-diff\u00a0\u6570\u5bf9\u5b9a\u4e49\u4e3a\u4e00\u4e2a\u6574\u6570\u5bf9 (nums[i], nums[j])\uff0c\u5e76\u6ee1\u8db3\u4e0b\u8ff0\u5168\u90e8\u6761\u4ef6\uff1a

    \n\n
      \n\t
    • 0 <= i < j < nums.length
    • \n\t
    • |nums[i] - nums[j]| == k
    • \n
    \n\n

    \u6ce8\u610f\uff0c|val| \u8868\u793a val \u7684\u7edd\u5bf9\u503c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [3, 1, 4, 1, 5], k = 2\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6570\u7ec4\u4e2d\u6709\u4e24\u4e2a 2-diff \u6570\u5bf9, (1, 3) \u548c (3, 5)\u3002\n\u5c3d\u7ba1\u6570\u7ec4\u4e2d\u6709\u4e24\u4e2a1\uff0c\u4f46\u6211\u4eec\u53ea\u5e94\u8fd4\u56de\u4e0d\u540c\u7684\u6570\u5bf9\u7684\u6570\u91cf\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1, 2, 3, 4, 5], k = 1\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u6570\u7ec4\u4e2d\u6709\u56db\u4e2a 1-diff \u6570\u5bf9, (1, 2), (2, 3), (3, 4) \u548c (4, 5)\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1, 3, 1, 5, 4], k = 0\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u6570\u7ec4\u4e2d\u53ea\u6709\u4e00\u4e2a 0-diff \u6570\u5bf9\uff0c(1, 1)\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,4,4,3,3,0,9,2,3], k = 3\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [-1,-2,-3], k = 1\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 104
    • \n\t
    • -107 <= nums[i] <= 107
    • \n\t
    • 0 <= k <= 107
    • \n
    \n", "tags_en": ["Array", "Two Pointers"], "tags_cn": ["\u6570\u7ec4", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findPairs(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findPairs(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findPairs(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findPairs(self, nums: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findPairs(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindPairs(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar findPairs = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef find_pairs(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findPairs(_ nums: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findPairs(nums []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findPairs(nums: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findPairs(nums: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_pairs(nums: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer\n */\n function findPairs($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findPairs(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-pairs nums k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0532](https://leetcode-cn.com/problems/k-diff-pairs-in-an-array)", "[\u6570\u7ec4\u4e2d\u7684 k-diff \u6570\u5bf9](/solution/0500-0599/0532.K-diff%20Pairs%20in%20an%20Array/README.md)", "`\u6570\u7ec4`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0532](https://leetcode.com/problems/k-diff-pairs-in-an-array)", "[K-diff Pairs in an Array](/solution/0500-0599/0532.K-diff%20Pairs%20in%20an%20Array/README_EN.md)", "`Array`,`Two Pointers`", "Medium", ""]}, {"question_id": "0531", "frontend_question_id": "0531", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/lonely-pixel-i", "url_en": "https://leetcode.com/problems/lonely-pixel-i", "relative_path_cn": "/solution/0500-0599/0531.Lonely%20Pixel%20I/README.md", "relative_path_en": "/solution/0500-0599/0531.Lonely%20Pixel%20I/README_EN.md", "title_cn": "\u5b64\u72ec\u50cf\u7d20 I", "title_en": "Lonely Pixel I", "question_title_slug": "lonely-pixel-i", "content_en": "

    Given an m x n picture consisting of black 'B' and white 'W' pixels, return the number of black lonely pixels.

    \n\n

    A black lonely pixel is a character 'B' that located at a specific position where the same row and same column don't have any other black pixels.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: picture = [["W","W","B"],["W","B","W"],["B","W","W"]]\nOutput: 3\nExplanation: All the three 'B's are black lonely pixels.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: picture = [["B","B","B"],["B","B","B"],["B","B","B"]]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == picture.length
    • \n\t
    • n == picture[i].length
    • \n\t
    • 1 <= m, n <= 500
    • \n\t
    • picture[i][j] is 'W' or 'B'.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u5e45\u9ed1\u767d\u50cf\u7d20\u7ec4\u6210\u7684\u56fe\u50cf, \u8ba1\u7b97\u9ed1\u8272\u5b64\u72ec\u50cf\u7d20\u7684\u6570\u91cf\u3002

    \n\n

    \u56fe\u50cf\u7531\u4e00\u4e2a\u7531‘B’\u548c‘W’\u7ec4\u6210\u4e8c\u7ef4\u5b57\u7b26\u6570\u7ec4\u8868\u793a, ‘B’\u548c‘W’\u5206\u522b\u4ee3\u8868\u9ed1\u8272\u50cf\u7d20\u548c\u767d\u8272\u50cf\u7d20\u3002

    \n\n

    \u9ed1\u8272\u5b64\u72ec\u50cf\u7d20\u6307\u7684\u662f\u5728\u540c\u4e00\u884c\u548c\u540c\u4e00\u5217\u4e0d\u5b58\u5728\u5176\u4ed6\u9ed1\u8272\u50cf\u7d20\u7684\u9ed1\u8272\u50cf\u7d20\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: \n[['W', 'W', 'B'],\n ['W', 'B', 'W'],\n ['B', 'W', 'W']]\n\n\u8f93\u51fa: 3\n\u89e3\u6790: \u5168\u90e8\u4e09\u4e2a'B'\u90fd\u662f\u9ed1\u8272\u5b64\u72ec\u50cf\u7d20\u3002\n
    \n\n

     

    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u8f93\u5165\u4e8c\u7ef4\u6570\u7ec4\u884c\u548c\u5217\u7684\u8303\u56f4\u662f [1,500]\u3002
    2. \n
    \n\n

     

    \n", "tags_en": ["Depth-first Search", "Array"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findLonelyPixel(vector>& picture) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findLonelyPixel(char[][] picture) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findLonelyPixel(self, picture):\n \"\"\"\n :type picture: List[List[str]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findLonelyPixel(self, picture: List[List[str]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findLonelyPixel(char** picture, int pictureSize, int* pictureColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindLonelyPixel(char[][] picture) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {character[][]} picture\n * @return {number}\n */\nvar findLonelyPixel = function(picture) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Character[][]} picture\n# @return {Integer}\ndef find_lonely_pixel(picture)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findLonelyPixel(_ picture: [[Character]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findLonelyPixel(picture [][]byte) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findLonelyPixel(picture: Array[Array[Char]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findLonelyPixel(picture: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_lonely_pixel(picture: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $picture\n * @return Integer\n */\n function findLonelyPixel($picture) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findLonelyPixel(picture: string[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-lonely-pixel picture)\n (-> (listof (listof char?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0531](https://leetcode-cn.com/problems/lonely-pixel-i)", "[\u5b64\u72ec\u50cf\u7d20 I](/solution/0500-0599/0531.Lonely%20Pixel%20I/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u6570\u7ec4`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0531](https://leetcode.com/problems/lonely-pixel-i)", "[Lonely Pixel I](/solution/0500-0599/0531.Lonely%20Pixel%20I/README_EN.md)", "`Depth-first Search`,`Array`", "Medium", "\ud83d\udd12"]}, {"question_id": "0530", "frontend_question_id": "0530", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-absolute-difference-in-bst", "url_en": "https://leetcode.com/problems/minimum-absolute-difference-in-bst", "relative_path_cn": "/solution/0500-0599/0530.Minimum%20Absolute%20Difference%20in%20BST/README.md", "relative_path_en": "/solution/0500-0599/0530.Minimum%20Absolute%20Difference%20in%20BST/README_EN.md", "title_cn": "\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6700\u5c0f\u7edd\u5bf9\u5dee", "title_en": "Minimum Absolute Difference in BST", "question_title_slug": "minimum-absolute-difference-in-bst", "content_en": "

    Given the root of a Binary Search Tree (BST), return the minimum absolute difference between the values of any two different nodes in the tree.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [4,2,6,1,3]\nOutput: 1\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [1,0,48,null,null,12,49]\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [2, 104].
    • \n\t
    • 0 <= Node.val <= 105
    • \n
    \n\n

     

    \n

    Note: This question is the same as 783: https://leetcode.com/problems/minimum-distance-between-bst-nodes/

    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u68f5\u6240\u6709\u8282\u70b9\u4e3a\u975e\u8d1f\u503c\u7684\u4e8c\u53c9\u641c\u7d22\u6811\uff0c\u8bf7\u4f60\u8ba1\u7b97\u6811\u4e2d\u4efb\u610f\u4e24\u8282\u70b9\u7684\u5dee\u7684\u7edd\u5bf9\u503c\u7684\u6700\u5c0f\u503c\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1a\n\n   1\n    \\\n     3\n    /\n   2\n\n\u8f93\u51fa\uff1a\n1\n\n\u89e3\u91ca\uff1a\n\u6700\u5c0f\u7edd\u5bf9\u5dee\u4e3a 1\uff0c\u5176\u4e2d 2 \u548c 1 \u7684\u5dee\u7684\u7edd\u5bf9\u503c\u4e3a 1\uff08\u6216\u8005 2 \u548c 3\uff09\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n\n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int getMinimumDifference(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int getMinimumDifference(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def getMinimumDifference(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def getMinimumDifference(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint getMinimumDifference(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int GetMinimumDifference(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar getMinimumDifference = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef get_minimum_difference(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func getMinimumDifference(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc getMinimumDifference(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def getMinimumDifference(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun getMinimumDifference(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn get_minimum_difference(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function getMinimumDifference($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction getMinimumDifference(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (get-minimum-difference root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0530](https://leetcode-cn.com/problems/minimum-absolute-difference-in-bst)", "[\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6700\u5c0f\u7edd\u5bf9\u5dee](/solution/0500-0599/0530.Minimum%20Absolute%20Difference%20in%20BST/README.md)", "`\u6811`", "\u7b80\u5355", ""], "md_table_row_en": ["[0530](https://leetcode.com/problems/minimum-absolute-difference-in-bst)", "[Minimum Absolute Difference in BST](/solution/0500-0599/0530.Minimum%20Absolute%20Difference%20in%20BST/README_EN.md)", "`Tree`", "Easy", ""]}, {"question_id": "0529", "frontend_question_id": "0529", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minesweeper", "url_en": "https://leetcode.com/problems/minesweeper", "relative_path_cn": "/solution/0500-0599/0529.Minesweeper/README.md", "relative_path_en": "/solution/0500-0599/0529.Minesweeper/README_EN.md", "title_cn": "\u626b\u96f7\u6e38\u620f", "title_en": "Minesweeper", "question_title_slug": "minesweeper", "content_en": "

    Let's play the minesweeper game (Wikipedia, online game)!

    \n\n

    You are given an m x n char matrix board representing the game board where:

    \n\n
      \n\t
    • 'M' represents an unrevealed mine,
    • \n\t
    • 'E' represents an unrevealed empty square,
    • \n\t
    • 'B' represents a revealed blank square that has no adjacent mines (i.e., above, below, left, right, and all 4 diagonals),
    • \n\t
    • digit ('1' to '8') represents how many mines are adjacent to this revealed square, and
    • \n\t
    • 'X' represents a revealed mine.
    • \n
    \n\n

    You are also given an integer array click where click = [clickr, clickc] represents the next click position among all the unrevealed squares ('M' or 'E').

    \n\n

    Return the board after revealing this position according to the following rules:

    \n\n
      \n\t
    1. If a mine 'M' is revealed, then the game is over. You should change it to 'X'.
    2. \n\t
    3. If an empty square 'E' with no adjacent mines is revealed, then change it to a revealed blank 'B' and all of its adjacent unrevealed squares should be revealed recursively.
    4. \n\t
    5. If an empty square 'E' with at least one adjacent mine is revealed, then change it to a digit ('1' to '8') representing the number of adjacent mines.
    6. \n\t
    7. Return the board when no more squares will be revealed.
    8. \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: board = [["E","E","E","E","E"],["E","E","M","E","E"],["E","E","E","E","E"],["E","E","E","E","E"]], click = [3,0]\nOutput: [["B","1","E","1","B"],["B","1","M","1","B"],["B","1","1","1","B"],["B","B","B","B","B"]]\n
    \n\n

    Example 2:

    \n\n
    \nInput: board = [["B","1","E","1","B"],["B","1","M","1","B"],["B","1","1","1","B"],["B","B","B","B","B"]], click = [1,2]\nOutput: [["B","1","E","1","B"],["B","1","X","1","B"],["B","1","1","1","B"],["B","B","B","B","B"]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == board.length
    • \n\t
    • n == board[i].length
    • \n\t
    • 1 <= m, n <= 50
    • \n\t
    • board[i][j] is either 'M', 'E', 'B', or a digit from '1' to '8'.
    • \n\t
    • click.length == 2
    • \n\t
    • 0 <= clickr <= m
    • \n\t
    • 0 <= clickc <= n
    • \n\t
    • board[clickr][clickc] is either 'M' or 'E'.
    • \n
    \n", "content_cn": "

    \u8ba9\u6211\u4eec\u4e00\u8d77\u6765\u73a9\u626b\u96f7\u6e38\u620f\uff01

    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u4ee3\u8868\u6e38\u620f\u677f\u7684\u4e8c\u7ef4\u5b57\u7b26\u77e9\u9635\u3002 'M' \u4ee3\u8868\u4e00\u4e2a\u672a\u6316\u51fa\u7684\u5730\u96f7\uff0c'E' \u4ee3\u8868\u4e00\u4e2a\u672a\u6316\u51fa\u7684\u7a7a\u65b9\u5757\uff0c'B' \u4ee3\u8868\u6ca1\u6709\u76f8\u90bb\uff08\u4e0a\uff0c\u4e0b\uff0c\u5de6\uff0c\u53f3\uff0c\u548c\u6240\u67094\u4e2a\u5bf9\u89d2\u7ebf\uff09\u5730\u96f7\u7684\u5df2\u6316\u51fa\u7684\u7a7a\u767d\u65b9\u5757\uff0c\u6570\u5b57\uff08'1' \u5230 '8'\uff09\u8868\u793a\u6709\u591a\u5c11\u5730\u96f7\u4e0e\u8fd9\u5757\u5df2\u6316\u51fa\u7684\u65b9\u5757\u76f8\u90bb\uff0c'X' \u5219\u8868\u793a\u4e00\u4e2a\u5df2\u6316\u51fa\u7684\u5730\u96f7\u3002

    \n\n

    \u73b0\u5728\u7ed9\u51fa\u5728\u6240\u6709\u672a\u6316\u51fa\u7684\u65b9\u5757\u4e2d\uff08'M'\u6216\u8005'E'\uff09\u7684\u4e0b\u4e00\u4e2a\u70b9\u51fb\u4f4d\u7f6e\uff08\u884c\u548c\u5217\u7d22\u5f15\uff09\uff0c\u6839\u636e\u4ee5\u4e0b\u89c4\u5219\uff0c\u8fd4\u56de\u76f8\u5e94\u4f4d\u7f6e\u88ab\u70b9\u51fb\u540e\u5bf9\u5e94\u7684\u9762\u677f\uff1a

    \n\n
      \n\t
    1. \u5982\u679c\u4e00\u4e2a\u5730\u96f7\uff08'M'\uff09\u88ab\u6316\u51fa\uff0c\u6e38\u620f\u5c31\u7ed3\u675f\u4e86- \u628a\u5b83\u6539\u4e3a 'X'\u3002
    2. \n\t
    3. \u5982\u679c\u4e00\u4e2a\u6ca1\u6709\u76f8\u90bb\u5730\u96f7\u7684\u7a7a\u65b9\u5757\uff08'E'\uff09\u88ab\u6316\u51fa\uff0c\u4fee\u6539\u5b83\u4e3a\uff08'B'\uff09\uff0c\u5e76\u4e14\u6240\u6709\u548c\u5176\u76f8\u90bb\u7684\u672a\u6316\u51fa\u65b9\u5757\u90fd\u5e94\u8be5\u88ab\u9012\u5f52\u5730\u63ed\u9732\u3002
    4. \n\t
    5. \u5982\u679c\u4e00\u4e2a\u81f3\u5c11\u4e0e\u4e00\u4e2a\u5730\u96f7\u76f8\u90bb\u7684\u7a7a\u65b9\u5757\uff08'E'\uff09\u88ab\u6316\u51fa\uff0c\u4fee\u6539\u5b83\u4e3a\u6570\u5b57\uff08'1'\u5230'8'\uff09\uff0c\u8868\u793a\u76f8\u90bb\u5730\u96f7\u7684\u6570\u91cf\u3002
    6. \n\t
    7. \u5982\u679c\u5728\u6b64\u6b21\u70b9\u51fb\u4e2d\uff0c\u82e5\u65e0\u66f4\u591a\u65b9\u5757\u53ef\u88ab\u63ed\u9732\uff0c\u5219\u8fd4\u56de\u9762\u677f\u3002
    8. \n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165: \n\n[['E', 'E', 'E', 'E', 'E'],\n ['E', 'E', 'M', 'E', 'E'],\n ['E', 'E', 'E', 'E', 'E'],\n ['E', 'E', 'E', 'E', 'E']]\n\nClick : [3,0]\n\n\u8f93\u51fa: \n\n[['B', '1', 'E', '1', 'B'],\n ['B', '1', 'M', '1', 'B'],\n ['B', '1', '1', '1', 'B'],\n ['B', 'B', 'B', 'B', 'B']]\n\n\u89e3\u91ca:\n\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165: \n\n[['B', '1', 'E', '1', 'B'],\n ['B', '1', 'M', '1', 'B'],\n ['B', '1', '1', '1', 'B'],\n ['B', 'B', 'B', 'B', 'B']]\n\nClick : [1,2]\n\n\u8f93\u51fa: \n\n[['B', '1', 'E', '1', 'B'],\n ['B', '1', 'X', '1', 'B'],\n ['B', '1', '1', '1', 'B'],\n ['B', 'B', 'B', 'B', 'B']]\n\n\u89e3\u91ca:\n\n
    \n\n

     

    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    1. \u8f93\u5165\u77e9\u9635\u7684\u5bbd\u548c\u9ad8\u7684\u8303\u56f4\u4e3a [1,50]\u3002
    2. \n\t
    3. \u70b9\u51fb\u7684\u4f4d\u7f6e\u53ea\u80fd\u662f\u672a\u88ab\u6316\u51fa\u7684\u65b9\u5757 ('M' \u6216\u8005 'E')\uff0c\u8fd9\u4e5f\u610f\u5473\u7740\u9762\u677f\u81f3\u5c11\u5305\u542b\u4e00\u4e2a\u53ef\u70b9\u51fb\u7684\u65b9\u5757\u3002
    4. \n\t
    5. \u8f93\u5165\u9762\u677f\u4e0d\u4f1a\u662f\u6e38\u620f\u7ed3\u675f\u7684\u72b6\u6001\uff08\u5373\u6709\u5730\u96f7\u5df2\u88ab\u6316\u51fa\uff09\u3002
    6. \n\t
    7. \u7b80\u5355\u8d77\u89c1\uff0c\u672a\u63d0\u53ca\u7684\u89c4\u5219\u5728\u8fd9\u4e2a\u95ee\u9898\u4e2d\u53ef\u88ab\u5ffd\u7565\u3002\u4f8b\u5982\uff0c\u5f53\u6e38\u620f\u7ed3\u675f\u65f6\u4f60\u4e0d\u9700\u8981\u6316\u51fa\u6240\u6709\u5730\u96f7\uff0c\u8003\u8651\u6240\u6709\u4f60\u53ef\u80fd\u8d62\u5f97\u6e38\u620f\u6216\u6807\u8bb0\u65b9\u5757\u7684\u60c5\u51b5\u3002
    8. \n
    \n", "tags_en": ["Depth-first Search", "Breadth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> updateBoard(vector>& board, vector& click) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public char[][] updateBoard(char[][] board, int[] click) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def updateBoard(self, board, click):\n \"\"\"\n :type board: List[List[str]]\n :type click: List[int]\n :rtype: List[List[str]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def updateBoard(self, board: List[List[str]], click: List[int]) -> List[List[str]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nchar** updateBoard(char** board, int boardSize, int* boardColSize, int* click, int clickSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public char[][] UpdateBoard(char[][] board, int[] click) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {character[][]} board\n * @param {number[]} click\n * @return {character[][]}\n */\nvar updateBoard = function(board, click) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Character[][]} board\n# @param {Integer[]} click\n# @return {Character[][]}\ndef update_board(board, click)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func updateBoard(_ board: [[Character]], _ click: [Int]) -> [[Character]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func updateBoard(board [][]byte, click []int) [][]byte {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def updateBoard(board: Array[Array[Char]], click: Array[Int]): Array[Array[Char]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun updateBoard(board: Array, click: IntArray): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn update_board(board: Vec>, click: Vec) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $board\n * @param Integer[] $click\n * @return String[][]\n */\n function updateBoard($board, $click) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function updateBoard(board: string[][], click: number[]): string[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (update-board board click)\n (-> (listof (listof char?)) (listof exact-integer?) (listof (listof char?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0529](https://leetcode-cn.com/problems/minesweeper)", "[\u626b\u96f7\u6e38\u620f](/solution/0500-0599/0529.Minesweeper/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0529](https://leetcode.com/problems/minesweeper)", "[Minesweeper](/solution/0500-0599/0529.Minesweeper/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`", "Medium", ""]}, {"question_id": "0528", "frontend_question_id": "1721", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/swapping-nodes-in-a-linked-list", "url_en": "https://leetcode.com/problems/swapping-nodes-in-a-linked-list", "relative_path_cn": "/solution/1700-1799/1721.Swapping%20Nodes%20in%20a%20Linked%20List/README.md", "relative_path_en": "/solution/1700-1799/1721.Swapping%20Nodes%20in%20a%20Linked%20List/README_EN.md", "title_cn": "\u4ea4\u6362\u94fe\u8868\u4e2d\u7684\u8282\u70b9", "title_en": "Swapping Nodes in a Linked List", "question_title_slug": "swapping-nodes-in-a-linked-list", "content_en": "

    You are given the head of a linked list, and an integer k.

    \n\n

    Return the head of the linked list after swapping the values of the kth node from the beginning and the kth node from the end (the list is 1-indexed).

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: head = [1,2,3,4,5], k = 2\nOutput: [1,4,3,2,5]\n
    \n\n

    Example 2:

    \n\n
    \nInput: head = [7,9,6,6,7,8,3,0,9,5], k = 5\nOutput: [7,9,6,6,8,7,3,0,9,5]\n
    \n\n

    Example 3:

    \n\n
    \nInput: head = [1], k = 1\nOutput: [1]\n
    \n\n

    Example 4:

    \n\n
    \nInput: head = [1,2], k = 1\nOutput: [2,1]\n
    \n\n

    Example 5:

    \n\n
    \nInput: head = [1,2,3], k = 2\nOutput: [1,2,3]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the list is n.
    • \n\t
    • 1 <= k <= n <= 105
    • \n\t
    • 0 <= Node.val <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u94fe\u8868\u7684\u5934\u8282\u70b9 head \u548c\u4e00\u4e2a\u6574\u6570 k \u3002

    \n\n

    \u4ea4\u6362 \u94fe\u8868\u6b63\u6570\u7b2c k \u4e2a\u8282\u70b9\u548c\u5012\u6570\u7b2c k \u4e2a\u8282\u70b9\u7684\u503c\u540e\uff0c\u8fd4\u56de\u94fe\u8868\u7684\u5934\u8282\u70b9\uff08\u94fe\u8868 \u4ece 1 \u5f00\u59cb\u7d22\u5f15\uff09\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1ahead = [1,2,3,4,5], k = 2\n\u8f93\u51fa\uff1a[1,4,3,2,5]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahead = [7,9,6,6,7,8,3,0,9,5], k = 5\n\u8f93\u51fa\uff1a[7,9,6,6,8,7,3,0,9,5]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahead = [1], k = 1\n\u8f93\u51fa\uff1a[1]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahead = [1,2], k = 1\n\u8f93\u51fa\uff1a[2,1]\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahead = [1,2,3], k = 2\n\u8f93\u51fa\uff1a[1,2,3]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u94fe\u8868\u4e2d\u8282\u70b9\u7684\u6570\u76ee\u662f n
    • \n\t
    • 1 <= k <= n <= 105
    • \n\t
    • 0 <= Node.val <= 100
    • \n
    \n", "tags_en": ["Linked List"], "tags_cn": ["\u94fe\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n ListNode* swapNodes(ListNode* head, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public ListNode swapNodes(ListNode head, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def swapNodes(self, head, k):\n \"\"\"\n :type head: ListNode\n :type k: int\n :rtype: ListNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def swapNodes(self, head: ListNode, k: int) -> ListNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nstruct ListNode* swapNodes(struct ListNode* head, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public ListNode SwapNodes(ListNode head, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} head\n * @param {number} k\n * @return {ListNode}\n */\nvar swapNodes = function(head, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode} head\n# @param {Integer} k\n# @return {ListNode}\ndef swap_nodes(head, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func swapNodes(_ head: ListNode?, _ k: Int) -> ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc swapNodes(head *ListNode, k int) *ListNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def swapNodes(head: ListNode, k: Int): ListNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun swapNodes(head: ListNode?, k: Int): ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn swap_nodes(head: Option>, k: i32) -> Option> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @param Integer $k\n * @return ListNode\n */\n function swapNodes($head, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction swapNodes(head: ListNode | null, k: number): ListNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (swap-nodes head k)\n (-> (or/c list-node? #f) exact-integer? (or/c list-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1721](https://leetcode-cn.com/problems/swapping-nodes-in-a-linked-list)", "[\u4ea4\u6362\u94fe\u8868\u4e2d\u7684\u8282\u70b9](/solution/1700-1799/1721.Swapping%20Nodes%20in%20a%20Linked%20List/README.md)", "`\u94fe\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[1721](https://leetcode.com/problems/swapping-nodes-in-a-linked-list)", "[Swapping Nodes in a Linked List](/solution/1700-1799/1721.Swapping%20Nodes%20in%20a%20Linked%20List/README_EN.md)", "`Linked List`", "Medium", ""]}, {"question_id": "0527", "frontend_question_id": "0527", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/word-abbreviation", "url_en": "https://leetcode.com/problems/word-abbreviation", "relative_path_cn": "/solution/0500-0599/0527.Word%20Abbreviation/README.md", "relative_path_en": "/solution/0500-0599/0527.Word%20Abbreviation/README_EN.md", "title_cn": "\u5355\u8bcd\u7f29\u5199", "title_en": "Word Abbreviation", "question_title_slug": "word-abbreviation", "content_en": "

    Given an array of distinct strings words, return the minimal possible abbreviations for every word.

    \n\n

    The following are the rules for a string abbreviation:

    \n\n
      \n\t
    1. Begin with the first character, and then the number of characters abbreviated, followed by the last character.
    2. \n\t
    3. If there is any conflict and more than one word shares the same abbreviation, a longer prefix is used instead of only the first character until making the map from word to abbreviation become unique. In other words, a final abbreviation cannot map to more than one original word.
    4. \n\t
    5. If the abbreviation does not make the word shorter, then keep it as the original.
    6. \n
    \n\n

     

    \n

    Example 1:

    \n
    Input: words = [\"like\",\"god\",\"internal\",\"me\",\"internet\",\"interval\",\"intension\",\"face\",\"intrusion\"]\nOutput: [\"l2e\",\"god\",\"internal\",\"me\",\"i6t\",\"interval\",\"inte4n\",\"f2e\",\"intr4n\"]\n

    Example 2:

    \n
    Input: words = [\"aa\",\"aaa\"]\nOutput: [\"aa\",\"aaa\"]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= words.length <= 400
    • \n\t
    • 2 <= words[i].length <= 400
    • \n\t
    • words[i] consists of lowercase English letters.
    • \n\t
    • All the strings of words are unique.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u7531n\u4e2a\u4e0d\u91cd\u590d\u975e\u7a7a\u5b57\u7b26\u4e32\u7ec4\u6210\u7684\u6570\u7ec4\uff0c\u4f60\u9700\u8981\u6309\u7167\u4ee5\u4e0b\u89c4\u5219\u4e3a\u6bcf\u4e2a\u5355\u8bcd\u751f\u6210\u6700\u5c0f\u7684\u7f29\u5199\u3002

    \n\n
      \n\t
    1. \u521d\u59cb\u7f29\u5199\u7531\u8d77\u59cb\u5b57\u6bcd+\u7701\u7565\u5b57\u6bcd\u7684\u6570\u91cf+\u7ed3\u5c3e\u5b57\u6bcd\u7ec4\u6210\u3002
    2. \n\t
    3. \u82e5\u5b58\u5728\u51b2\u7a81\uff0c\u4ea6\u5373\u591a\u4e8e\u4e00\u4e2a\u5355\u8bcd\u6709\u540c\u6837\u7684\u7f29\u5199\uff0c\u5219\u4f7f\u7528\u66f4\u957f\u7684\u524d\u7f00\u4ee3\u66ff\u9996\u5b57\u6bcd\uff0c\u76f4\u5230\u4ece\u5355\u8bcd\u5230\u7f29\u5199\u7684\u6620\u5c04\u552f\u4e00\u3002\u6362\u800c\u8a00\u4e4b\uff0c\u6700\u7ec8\u7684\u7f29\u5199\u5fc5\u987b\u53ea\u80fd\u6620\u5c04\u5230\u4e00\u4e2a\u5355\u8bcd\u3002
    4. \n\t
    5. \u82e5\u7f29\u5199\u5e76\u4e0d\u6bd4\u539f\u5355\u8bcd\u66f4\u77ed\uff0c\u5219\u4fdd\u7559\u539f\u6837\u3002
    6. \n
    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: ["like", "god", "internal", "me", "internet", "interval", "intension", "face", "intrusion"]\n\u8f93\u51fa: ["l2e","god","internal","me","i6t","interval","inte4n","f2e","intr4n"]\n
    \n\n

     

    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. n\u548c\u6bcf\u4e2a\u5355\u8bcd\u7684\u957f\u5ea6\u5747\u4e0d\u8d85\u8fc7 400\u3002
    2. \n\t
    3. \u6bcf\u4e2a\u5355\u8bcd\u7684\u957f\u5ea6\u5927\u4e8e 1\u3002
    4. \n\t
    5. \u5355\u8bcd\u53ea\u7531\u82f1\u6587\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210\u3002
    6. \n\t
    7. \u8fd4\u56de\u7684\u7b54\u6848\u9700\u8981\u548c\u539f\u6570\u7ec4\u4fdd\u6301\u540c\u4e00\u987a\u5e8f\u3002
    8. \n
    \n", "tags_en": ["Sort", "String"], "tags_cn": ["\u6392\u5e8f", "\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector wordsAbbreviation(vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List wordsAbbreviation(List words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def wordsAbbreviation(self, words):\n \"\"\"\n :type words: List[str]\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def wordsAbbreviation(self, words: List[str]) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** wordsAbbreviation(char ** words, int wordsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList WordsAbbreviation(IList words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @return {string[]}\n */\nvar wordsAbbreviation = function(words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @return {String[]}\ndef words_abbreviation(words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func wordsAbbreviation(_ words: [String]) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func wordsAbbreviation(words []string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def wordsAbbreviation(words: List[String]): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun wordsAbbreviation(words: List): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn words_abbreviation(words: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @return String[]\n */\n function wordsAbbreviation($words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function wordsAbbreviation(words: string[]): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (words-abbreviation words)\n (-> (listof string?) (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0527](https://leetcode-cn.com/problems/word-abbreviation)", "[\u5355\u8bcd\u7f29\u5199](/solution/0500-0599/0527.Word%20Abbreviation/README.md)", "`\u6392\u5e8f`,`\u5b57\u7b26\u4e32`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0527](https://leetcode.com/problems/word-abbreviation)", "[Word Abbreviation](/solution/0500-0599/0527.Word%20Abbreviation/README_EN.md)", "`Sort`,`String`", "Hard", "\ud83d\udd12"]}, {"question_id": "0526", "frontend_question_id": "0526", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/beautiful-arrangement", "url_en": "https://leetcode.com/problems/beautiful-arrangement", "relative_path_cn": "/solution/0500-0599/0526.Beautiful%20Arrangement/README.md", "relative_path_en": "/solution/0500-0599/0526.Beautiful%20Arrangement/README_EN.md", "title_cn": "\u4f18\u7f8e\u7684\u6392\u5217", "title_en": "Beautiful Arrangement", "question_title_slug": "beautiful-arrangement", "content_en": "

    Suppose you have n integers labeled 1 through n. A permutation of those n integers perm (1-indexed) is considered a beautiful arrangement if for every i (1 <= i <= n), either of the following is true:

    \n\n
      \n\t
    • perm[i] is divisible by i.
    • \n\t
    • i is divisible by perm[i].
    • \n
    \n\n

    Given an integer n, return the number of the beautiful arrangements that you can construct.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 2\nOutput: 2\nExplanation: \nThe first beautiful arrangement is [1,2]:\n    - perm[1] = 1 is divisible by i = 1\n    - perm[2] = 2 is divisible by i = 2\nThe second beautiful arrangement is [2,1]:\n    - perm[1] = 2 is divisible by i = 1\n    - i = 2 is divisible by perm[2] = 1\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 1\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 15
    • \n
    \n", "content_cn": "

    \u5047\u8bbe\u6709\u4ece 1 \u5230 N \u7684 \u4e2a\u6574\u6570\uff0c\u5982\u679c\u4ece\u8fd9 \u4e2a\u6570\u5b57\u4e2d\u6210\u529f\u6784\u9020\u51fa\u4e00\u4e2a\u6570\u7ec4\uff0c\u4f7f\u5f97\u6570\u7ec4\u7684\u7b2c i \u4f4d (1 <= i <= N) \u6ee1\u8db3\u5982\u4e0b\u4e24\u4e2a\u6761\u4ef6\u4e2d\u7684\u4e00\u4e2a\uff0c\u6211\u4eec\u5c31\u79f0\u8fd9\u4e2a\u6570\u7ec4\u4e3a\u4e00\u4e2a\u4f18\u7f8e\u7684\u6392\u5217\u3002\u6761\u4ef6\uff1a

    \n\n
      \n\t
    1. \u7b2c \u4f4d\u7684\u6570\u5b57\u80fd\u88ab \u6574\u9664
    2. \n\t
    3. i \u80fd\u88ab\u7b2c i \u4f4d\u4e0a\u7684\u6570\u5b57\u6574\u9664
    4. \n
    \n\n

    \u73b0\u5728\u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570 N\uff0c\u8bf7\u95ee\u53ef\u4ee5\u6784\u9020\u591a\u5c11\u4e2a\u4f18\u7f8e\u7684\u6392\u5217\uff1f

    \n\n

    \u793a\u4f8b1:

    \n\n
    \n\u8f93\u5165: 2\n\u8f93\u51fa: 2\n\u89e3\u91ca: \n\n\u7b2c 1 \u4e2a\u4f18\u7f8e\u7684\u6392\u5217\u662f [1, 2]:\n  \u7b2c 1 \u4e2a\u4f4d\u7f6e\uff08i=1\uff09\u4e0a\u7684\u6570\u5b57\u662f1\uff0c1\u80fd\u88ab i\uff08i=1\uff09\u6574\u9664\n  \u7b2c 2 \u4e2a\u4f4d\u7f6e\uff08i=2\uff09\u4e0a\u7684\u6570\u5b57\u662f2\uff0c2\u80fd\u88ab i\uff08i=2\uff09\u6574\u9664\n\n\u7b2c 2 \u4e2a\u4f18\u7f8e\u7684\u6392\u5217\u662f [2, 1]:\n  \u7b2c 1 \u4e2a\u4f4d\u7f6e\uff08i=1\uff09\u4e0a\u7684\u6570\u5b57\u662f2\uff0c2\u80fd\u88ab i\uff08i=1\uff09\u6574\u9664\n  \u7b2c 2 \u4e2a\u4f4d\u7f6e\uff08i=2\uff09\u4e0a\u7684\u6570\u5b57\u662f1\uff0ci\uff08i=2\uff09\u80fd\u88ab 1 \u6574\u9664\n
    \n\n

    \u8bf4\u660e:

    \n\n
      \n\t
    1. N \u662f\u4e00\u4e2a\u6b63\u6574\u6570\uff0c\u5e76\u4e14\u4e0d\u4f1a\u8d85\u8fc715\u3002
    2. \n
    \n", "tags_en": ["Depth-first Search", "Backtracking"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countArrangement(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countArrangement(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countArrangement(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countArrangement(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countArrangement(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountArrangement(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar countArrangement = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef count_arrangement(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countArrangement(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countArrangement(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countArrangement(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countArrangement(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_arrangement(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function countArrangement($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countArrangement(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-arrangement n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0526](https://leetcode-cn.com/problems/beautiful-arrangement)", "[\u4f18\u7f8e\u7684\u6392\u5217](/solution/0500-0599/0526.Beautiful%20Arrangement/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0526](https://leetcode.com/problems/beautiful-arrangement)", "[Beautiful Arrangement](/solution/0500-0599/0526.Beautiful%20Arrangement/README_EN.md)", "`Depth-first Search`,`Backtracking`", "Medium", ""]}, {"question_id": "0525", "frontend_question_id": "0525", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/contiguous-array", "url_en": "https://leetcode.com/problems/contiguous-array", "relative_path_cn": "/solution/0500-0599/0525.Contiguous%20Array/README.md", "relative_path_en": "/solution/0500-0599/0525.Contiguous%20Array/README_EN.md", "title_cn": "\u8fde\u7eed\u6570\u7ec4", "title_en": "Contiguous Array", "question_title_slug": "contiguous-array", "content_en": "

    Given a binary array nums, return the maximum length of a contiguous subarray with an equal number of 0 and 1.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [0,1]\nOutput: 2\nExplanation: [0, 1] is the longest contiguous subarray with an equal number of 0 and 1.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [0,1,0]\nOutput: 2\nExplanation: [0, 1] (or [1, 0]) is a longest contiguous subarray with equal number of 0 and 1.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • nums[i] is either 0 or 1.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u8fdb\u5236\u6570\u7ec4 nums , \u627e\u5230\u542b\u6709\u76f8\u540c\u6570\u91cf\u7684 0 \u548c 1 \u7684\u6700\u957f\u8fde\u7eed\u5b50\u6570\u7ec4\uff0c\u5e76\u8fd4\u56de\u8be5\u5b50\u6570\u7ec4\u7684\u957f\u5ea6\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: nums = [0,1]\n\u8f93\u51fa: 2\n\u8bf4\u660e: [0, 1] \u662f\u5177\u6709\u76f8\u540c\u6570\u91cf 0 \u548c 1 \u7684\u6700\u957f\u8fde\u7eed\u5b50\u6570\u7ec4\u3002
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: nums = [0,1,0]\n\u8f93\u51fa: 2\n\u8bf4\u660e: [0, 1] (\u6216 [1, 0]) \u662f\u5177\u6709\u76f8\u540c\u6570\u91cf0\u548c1\u7684\u6700\u957f\u8fde\u7eed\u5b50\u6570\u7ec4\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • nums[i] \u4e0d\u662f 0 \u5c31\u662f 1
    • \n
    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findMaxLength(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findMaxLength(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findMaxLength(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findMaxLength(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findMaxLength(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindMaxLength(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar findMaxLength = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef find_max_length(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findMaxLength(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findMaxLength(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findMaxLength(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findMaxLength(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_max_length(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function findMaxLength($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findMaxLength(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-max-length nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0525](https://leetcode-cn.com/problems/contiguous-array)", "[\u8fde\u7eed\u6570\u7ec4](/solution/0500-0599/0525.Contiguous%20Array/README.md)", "`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0525](https://leetcode.com/problems/contiguous-array)", "[Contiguous Array](/solution/0500-0599/0525.Contiguous%20Array/README_EN.md)", "`Hash Table`", "Medium", ""]}, {"question_id": "0524", "frontend_question_id": "0524", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-word-in-dictionary-through-deleting", "url_en": "https://leetcode.com/problems/longest-word-in-dictionary-through-deleting", "relative_path_cn": "/solution/0500-0599/0524.Longest%20Word%20in%20Dictionary%20through%20Deleting/README.md", "relative_path_en": "/solution/0500-0599/0524.Longest%20Word%20in%20Dictionary%20through%20Deleting/README_EN.md", "title_cn": "\u901a\u8fc7\u5220\u9664\u5b57\u6bcd\u5339\u914d\u5230\u5b57\u5178\u91cc\u6700\u957f\u5355\u8bcd", "title_en": "Longest Word in Dictionary through Deleting", "question_title_slug": "longest-word-in-dictionary-through-deleting", "content_en": "

    Given a string s and a string array dictionary, return the longest string in the dictionary that can be formed by deleting some of the given string characters. If there is more than one possible result, return the longest word with the smallest lexicographical order. If there is no possible result, return the empty string.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "abpcplea", dictionary = ["ale","apple","monkey","plea"]\nOutput: "apple"\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "abpcplea", dictionary = ["a","b","c"]\nOutput: "a"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 1000
    • \n\t
    • 1 <= dictionary.length <= 1000
    • \n\t
    • 1 <= dictionary[i].length <= 1000
    • \n\t
    • s and dictionary[i] consist of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \u548c\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4 dictionary \u4f5c\u4e3a\u5b57\u5178\uff0c\u627e\u51fa\u5e76\u8fd4\u56de\u5b57\u5178\u4e2d\u6700\u957f\u7684\u5b57\u7b26\u4e32\uff0c\u8be5\u5b57\u7b26\u4e32\u53ef\u4ee5\u901a\u8fc7\u5220\u9664 s \u4e2d\u7684\u67d0\u4e9b\u5b57\u7b26\u5f97\u5230\u3002

    \n\n

    \u5982\u679c\u7b54\u6848\u4e0d\u6b62\u4e00\u4e2a\uff0c\u8fd4\u56de\u957f\u5ea6\u6700\u957f\u4e14\u5b57\u5178\u5e8f\u6700\u5c0f\u7684\u5b57\u7b26\u4e32\u3002\u5982\u679c\u7b54\u6848\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"abpcplea\", dictionary = [\"ale\",\"apple\",\"monkey\",\"plea\"]\n\u8f93\u51fa\uff1a\"apple\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"abpcplea\", dictionary = [\"a\",\"b\",\"c\"]\n\u8f93\u51fa\uff1a\"a\"\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 1000
    • \n\t
    • 1 <= dictionary.length <= 1000
    • \n\t
    • 1 <= dictionary[i].length <= 1000
    • \n\t
    • s \u548c dictionary[i] \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n", "tags_en": ["Sort", "Two Pointers"], "tags_cn": ["\u6392\u5e8f", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string findLongestWord(string s, vector& dictionary) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String findLongestWord(String s, List dictionary) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findLongestWord(self, s, dictionary):\n \"\"\"\n :type s: str\n :type dictionary: List[str]\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findLongestWord(self, s: str, dictionary: List[str]) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * findLongestWord(char * s, char ** dictionary, int dictionarySize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string FindLongestWord(string s, IList dictionary) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string[]} dictionary\n * @return {string}\n */\nvar findLongestWord = function(s, dictionary) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String[]} dictionary\n# @return {String}\ndef find_longest_word(s, dictionary)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findLongestWord(_ s: String, _ dictionary: [String]) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findLongestWord(s string, dictionary []string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findLongestWord(s: String, dictionary: List[String]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findLongestWord(s: String, dictionary: List): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_longest_word(s: String, dictionary: Vec) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String[] $dictionary\n * @return String\n */\n function findLongestWord($s, $dictionary) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findLongestWord(s: string, dictionary: string[]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-longest-word s dictionary)\n (-> string? (listof string?) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0524](https://leetcode-cn.com/problems/longest-word-in-dictionary-through-deleting)", "[\u901a\u8fc7\u5220\u9664\u5b57\u6bcd\u5339\u914d\u5230\u5b57\u5178\u91cc\u6700\u957f\u5355\u8bcd](/solution/0500-0599/0524.Longest%20Word%20in%20Dictionary%20through%20Deleting/README.md)", "`\u6392\u5e8f`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0524](https://leetcode.com/problems/longest-word-in-dictionary-through-deleting)", "[Longest Word in Dictionary through Deleting](/solution/0500-0599/0524.Longest%20Word%20in%20Dictionary%20through%20Deleting/README_EN.md)", "`Sort`,`Two Pointers`", "Medium", ""]}, {"question_id": "0523", "frontend_question_id": "0523", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/continuous-subarray-sum", "url_en": "https://leetcode.com/problems/continuous-subarray-sum", "relative_path_cn": "/solution/0500-0599/0523.Continuous%20Subarray%20Sum/README.md", "relative_path_en": "/solution/0500-0599/0523.Continuous%20Subarray%20Sum/README_EN.md", "title_cn": "\u8fde\u7eed\u7684\u5b50\u6570\u7ec4\u548c", "title_en": "Continuous Subarray Sum", "question_title_slug": "continuous-subarray-sum", "content_en": "

    Given an integer array nums and an integer k, return true if nums has a continuous subarray of size at least two whose elements sum up to a multiple of k, or false otherwise.

    \n\n

    An integer x is a multiple of k if there exists an integer n such that x = n * k. 0 is always a multiple of k.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [23,2,4,6,7], k = 6\nOutput: true\nExplanation: [2, 4] is a continuous subarray of size 2 whose elements sum up to 6.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [23,2,6,4,7], k = 6\nOutput: true\nExplanation: [23, 2, 6, 4, 7] is an continuous subarray of size 5 whose elements sum up to 42.\n42 is a multiple of 6 because 42 = 7 * 6 and 7 is an integer.\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [23,2,6,4,7], k = 13\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • 0 <= nums[i] <= 109
    • \n\t
    • 0 <= sum(nums[i]) <= 231 - 1
    • \n\t
    • 1 <= k <= 231 - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \u548c\u4e00\u4e2a\u6574\u6570\u00a0k \uff0c\u7f16\u5199\u4e00\u4e2a\u51fd\u6570\u6765\u5224\u65ad\u8be5\u6570\u7ec4\u662f\u5426\u542b\u6709\u540c\u65f6\u6ee1\u8db3\u4e0b\u8ff0\u6761\u4ef6\u7684\u8fde\u7eed\u5b50\u6570\u7ec4\uff1a

    \n\n
      \n\t
    • \u5b50\u6570\u7ec4\u5927\u5c0f \u81f3\u5c11\u4e3a 2 \uff0c\u4e14
    • \n\t
    • \u5b50\u6570\u7ec4\u5143\u7d20\u603b\u548c\u4e3a k \u7684\u500d\u6570\u3002
    • \n
    \n\n

    \u5982\u679c\u5b58\u5728\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n

    \u5982\u679c\u5b58\u5728\u4e00\u4e2a\u6574\u6570 n \uff0c\u4ee4\u6574\u6570 x \u7b26\u5408 x = n * k \uff0c\u5219\u79f0 x \u662f k \u7684\u4e00\u4e2a\u500d\u6570\u30020 \u59cb\u7ec8\u89c6\u4e3a k \u7684\u4e00\u4e2a\u500d\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [23,2,4,6,7], k = 6\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a[2,4] \u662f\u4e00\u4e2a\u5927\u5c0f\u4e3a 2 \u7684\u5b50\u6570\u7ec4\uff0c\u5e76\u4e14\u548c\u4e3a 6 \u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [23,2,6,4,7], k = 6\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a[23, 2, 6, 4, 7] \u662f\u5927\u5c0f\u4e3a 5 \u7684\u5b50\u6570\u7ec4\uff0c\u5e76\u4e14\u548c\u4e3a 42 \u3002 \n42 \u662f 6 \u7684\u500d\u6570\uff0c\u56e0\u4e3a 42 = 7 * 6 \u4e14 7 \u662f\u4e00\u4e2a\u6574\u6570\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [23,2,6,4,7], k = 13\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • 0 <= nums[i] <= 109
    • \n\t
    • 0 <= sum(nums[i]) <= 231 - 1
    • \n\t
    • 1 <= k <= 231 - 1
    • \n
    \n", "tags_en": ["Math", "Dynamic Programming"], "tags_cn": ["\u6570\u5b66", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool checkSubarraySum(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean checkSubarraySum(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def checkSubarraySum(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def checkSubarraySum(self, nums: List[int], k: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool checkSubarraySum(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CheckSubarraySum(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {boolean}\n */\nvar checkSubarraySum = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Boolean}\ndef check_subarray_sum(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func checkSubarraySum(_ nums: [Int], _ k: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func checkSubarraySum(nums []int, k int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def checkSubarraySum(nums: Array[Int], k: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun checkSubarraySum(nums: IntArray, k: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn check_subarray_sum(nums: Vec, k: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Boolean\n */\n function checkSubarraySum($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function checkSubarraySum(nums: number[], k: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (check-subarray-sum nums k)\n (-> (listof exact-integer?) exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0523](https://leetcode-cn.com/problems/continuous-subarray-sum)", "[\u8fde\u7eed\u7684\u5b50\u6570\u7ec4\u548c](/solution/0500-0599/0523.Continuous%20Subarray%20Sum/README.md)", "`\u6570\u5b66`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0523](https://leetcode.com/problems/continuous-subarray-sum)", "[Continuous Subarray Sum](/solution/0500-0599/0523.Continuous%20Subarray%20Sum/README_EN.md)", "`Math`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0522", "frontend_question_id": "0522", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-uncommon-subsequence-ii", "url_en": "https://leetcode.com/problems/longest-uncommon-subsequence-ii", "relative_path_cn": "/solution/0500-0599/0522.Longest%20Uncommon%20Subsequence%20II/README.md", "relative_path_en": "/solution/0500-0599/0522.Longest%20Uncommon%20Subsequence%20II/README_EN.md", "title_cn": "\u6700\u957f\u7279\u6b8a\u5e8f\u5217 II", "title_en": "Longest Uncommon Subsequence II", "question_title_slug": "longest-uncommon-subsequence-ii", "content_en": "

    Given an array of strings strs, return the length of the longest uncommon subsequence between them. If the longest uncommon subsequence does not exist, return -1.

    \n\n

    An uncommon subsequence between an array of strings is a string that is a subsequence of one string but not the others.

    \n\n

    A subsequence of a string s is a string that can be obtained after deleting any number of characters from s.

    \n\n
      \n\t
    • For example, "abc" is a subsequence of "aebdc" because you can delete the underlined characters in "aebdc" to get "abc". Other subsequences of "aebdc" include "aebdc", "aeb", and "" (empty string).
    • \n
    \n\n

     

    \n

    Example 1:

    \n
    Input: strs = [\"aba\",\"cdc\",\"eae\"]\nOutput: 3\n

    Example 2:

    \n
    Input: strs = [\"aaa\",\"aaa\",\"aa\"]\nOutput: -1\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= strs.length <= 50
    • \n\t
    • 1 <= strs[i].length <= 10
    • \n\t
    • strs[i] consists of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u5b57\u7b26\u4e32\u5217\u8868\uff0c\u4f60\u9700\u8981\u4ece\u5b83\u4eec\u4e2d\u627e\u51fa\u6700\u957f\u7684\u7279\u6b8a\u5e8f\u5217\u3002\u6700\u957f\u7279\u6b8a\u5e8f\u5217\u5b9a\u4e49\u5982\u4e0b\uff1a\u8be5\u5e8f\u5217\u4e3a\u67d0\u5b57\u7b26\u4e32\u72ec\u6709\u7684\u6700\u957f\u5b50\u5e8f\u5217\uff08\u5373\u4e0d\u80fd\u662f\u5176\u4ed6\u5b57\u7b26\u4e32\u7684\u5b50\u5e8f\u5217\uff09\u3002

    \n\n

    \u5b50\u5e8f\u5217\u53ef\u4ee5\u901a\u8fc7\u5220\u53bb\u5b57\u7b26\u4e32\u4e2d\u7684\u67d0\u4e9b\u5b57\u7b26\u5b9e\u73b0\uff0c\u4f46\u4e0d\u80fd\u6539\u53d8\u5269\u4f59\u5b57\u7b26\u7684\u76f8\u5bf9\u987a\u5e8f\u3002\u7a7a\u5e8f\u5217\u4e3a\u6240\u6709\u5b57\u7b26\u4e32\u7684\u5b50\u5e8f\u5217\uff0c\u4efb\u4f55\u5b57\u7b26\u4e32\u4e3a\u5176\u81ea\u8eab\u7684\u5b50\u5e8f\u5217\u3002

    \n\n

    \u8f93\u5165\u5c06\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\u5217\u8868\uff0c\u8f93\u51fa\u662f\u6700\u957f\u7279\u6b8a\u5e8f\u5217\u7684\u957f\u5ea6\u3002\u5982\u679c\u6700\u957f\u7279\u6b8a\u5e8f\u5217\u4e0d\u5b58\u5728\uff0c\u8fd4\u56de -1 \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165: "aba", "cdc", "eae"\n\u8f93\u51fa: 3\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. \u6240\u6709\u7ed9\u5b9a\u7684\u5b57\u7b26\u4e32\u957f\u5ea6\u4e0d\u4f1a\u8d85\u8fc7 10 \u3002
    2. \n\t
    3. \u7ed9\u5b9a\u5b57\u7b26\u4e32\u5217\u8868\u7684\u957f\u5ea6\u5c06\u5728 [2, 50 ] \u4e4b\u95f4\u3002
    4. \n
    \n\n

     

    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findLUSlength(vector& strs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findLUSlength(String[] strs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findLUSlength(self, strs):\n \"\"\"\n :type strs: List[str]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findLUSlength(self, strs: List[str]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findLUSlength(char ** strs, int strsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindLUSlength(string[] strs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} strs\n * @return {number}\n */\nvar findLUSlength = function(strs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} strs\n# @return {Integer}\ndef find_lu_slength(strs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findLUSlength(_ strs: [String]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findLUSlength(strs []string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findLUSlength(strs: Array[String]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findLUSlength(strs: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_lu_slength(strs: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $strs\n * @return Integer\n */\n function findLUSlength($strs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findLUSlength(strs: string[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-lu-slength strs)\n (-> (listof string?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0522](https://leetcode-cn.com/problems/longest-uncommon-subsequence-ii)", "[\u6700\u957f\u7279\u6b8a\u5e8f\u5217 II](/solution/0500-0599/0522.Longest%20Uncommon%20Subsequence%20II/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0522](https://leetcode.com/problems/longest-uncommon-subsequence-ii)", "[Longest Uncommon Subsequence II](/solution/0500-0599/0522.Longest%20Uncommon%20Subsequence%20II/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "0521", "frontend_question_id": "0521", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-uncommon-subsequence-i", "url_en": "https://leetcode.com/problems/longest-uncommon-subsequence-i", "relative_path_cn": "/solution/0500-0599/0521.Longest%20Uncommon%20Subsequence%20I/README.md", "relative_path_en": "/solution/0500-0599/0521.Longest%20Uncommon%20Subsequence%20I/README_EN.md", "title_cn": "\u6700\u957f\u7279\u6b8a\u5e8f\u5217 \u2160", "title_en": "Longest Uncommon Subsequence I", "question_title_slug": "longest-uncommon-subsequence-i", "content_en": "

    Given two strings a and b, return the length of the longest uncommon subsequence between a and b. If the longest uncommon subsequence does not exist, return -1.

    \n\n

    An uncommon subsequence between two strings is a string that is a subsequence of one but not the other.

    \n\n

    A subsequence of a string s is a string that can be obtained after deleting any number of characters from s.

    \n\n
      \n\t
    • For example, "abc" is a subsequence of "aebdc" because you can delete the underlined characters in "aebdc" to get "abc". Other subsequences of "aebdc" include "aebdc", "aeb", and "" (empty string).
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: a = "aba", b = "cdc"\nOutput: 3\nExplanation: One longest uncommon subsequence is "aba" because "aba" is a subsequence of "aba" but not "cdc".\nNote that "cdc" is also a longest uncommon subsequence.\n
    \n\n

    Example 2:

    \n\n
    \nInput: a = "aaa", b = "bbb"\nOutput: 3\nExplanation: The longest uncommon subsequences are "aaa" and "bbb".\n
    \n\n

    Example 3:

    \n\n
    \nInput: a = "aaa", b = "aaa"\nOutput: -1\nExplanation: Every subsequence of string a is also a subsequence of string b. Similarly, every subsequence of string b is also a subsequence of string a.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= a.length, b.length <= 100
    • \n\t
    • a and b consist of lower-case English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u5b57\u7b26\u4e32\uff0c\u8bf7\u4f60\u4ece\u8fd9\u4e24\u4e2a\u5b57\u7b26\u4e32\u4e2d\u627e\u51fa\u6700\u957f\u7684\u7279\u6b8a\u5e8f\u5217\u3002

    \n\n

    \u300c\u6700\u957f\u7279\u6b8a\u5e8f\u5217\u300d\u5b9a\u4e49\u5982\u4e0b\uff1a\u8be5\u5e8f\u5217\u4e3a\u67d0\u5b57\u7b26\u4e32\u72ec\u6709\u7684\u6700\u957f\u5b50\u5e8f\u5217\uff08\u5373\u4e0d\u80fd\u662f\u5176\u4ed6\u5b57\u7b26\u4e32\u7684\u5b50\u5e8f\u5217\uff09\u3002

    \n\n

    \u5b50\u5e8f\u5217 \u53ef\u4ee5\u901a\u8fc7\u5220\u53bb\u5b57\u7b26\u4e32\u4e2d\u7684\u67d0\u4e9b\u5b57\u7b26\u5b9e\u73b0\uff0c\u4f46\u4e0d\u80fd\u6539\u53d8\u5269\u4f59\u5b57\u7b26\u7684\u76f8\u5bf9\u987a\u5e8f\u3002\u7a7a\u5e8f\u5217\u4e3a\u6240\u6709\u5b57\u7b26\u4e32\u7684\u5b50\u5e8f\u5217\uff0c\u4efb\u4f55\u5b57\u7b26\u4e32\u4e3a\u5176\u81ea\u8eab\u7684\u5b50\u5e8f\u5217\u3002

    \n\n

    \u8f93\u5165\u4e3a\u4e24\u4e2a\u5b57\u7b26\u4e32\uff0c\u8f93\u51fa\u6700\u957f\u7279\u6b8a\u5e8f\u5217\u7684\u957f\u5ea6\u3002\u5982\u679c\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de -1\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165: "aba", "cdc"\n\u8f93\u51fa: 3\n\u89e3\u91ca: \u6700\u957f\u7279\u6b8a\u5e8f\u5217\u53ef\u4e3a "aba" (\u6216 "cdc")\uff0c\u4e24\u8005\u5747\u4e3a\u81ea\u8eab\u7684\u5b50\u5e8f\u5217\u4e14\u4e0d\u662f\u5bf9\u65b9\u7684\u5b50\u5e8f\u5217\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aa = "aaa", b = "bbb"\n\u8f93\u51fa\uff1a3\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aa = "aaa", b = "aaa"\n\u8f93\u51fa\uff1a-1\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. \u4e24\u4e2a\u5b57\u7b26\u4e32\u957f\u5ea6\u5747\u5904\u4e8e\u533a\u95f4 [1 - 100] \u3002
    2. \n\t
    3. \u5b57\u7b26\u4e32\u4e2d\u7684\u5b57\u7b26\u4ec5\u542b\u6709 'a'~'z' \u3002
    4. \n
    \n", "tags_en": ["Brainteaser", "String"], "tags_cn": ["\u8111\u7b4b\u6025\u8f6c\u5f2f", "\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findLUSlength(string a, string b) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findLUSlength(String a, String b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findLUSlength(self, a, b):\n \"\"\"\n :type a: str\n :type b: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findLUSlength(self, a: str, b: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findLUSlength(char * a, char * b){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindLUSlength(string a, string b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} a\n * @param {string} b\n * @return {number}\n */\nvar findLUSlength = function(a, b) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} a\n# @param {String} b\n# @return {Integer}\ndef find_lu_slength(a, b)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findLUSlength(_ a: String, _ b: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findLUSlength(a string, b string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findLUSlength(a: String, b: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findLUSlength(a: String, b: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_lu_slength(a: String, b: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $a\n * @param String $b\n * @return Integer\n */\n function findLUSlength($a, $b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findLUSlength(a: string, b: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-lu-slength a b)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0521](https://leetcode-cn.com/problems/longest-uncommon-subsequence-i)", "[\u6700\u957f\u7279\u6b8a\u5e8f\u5217 \u2160](/solution/0500-0599/0521.Longest%20Uncommon%20Subsequence%20I/README.md)", "`\u8111\u7b4b\u6025\u8f6c\u5f2f`,`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0521](https://leetcode.com/problems/longest-uncommon-subsequence-i)", "[Longest Uncommon Subsequence I](/solution/0500-0599/0521.Longest%20Uncommon%20Subsequence%20I/README_EN.md)", "`Brainteaser`,`String`", "Easy", ""]}, {"question_id": "0520", "frontend_question_id": "0520", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/detect-capital", "url_en": "https://leetcode.com/problems/detect-capital", "relative_path_cn": "/solution/0500-0599/0520.Detect%20Capital/README.md", "relative_path_en": "/solution/0500-0599/0520.Detect%20Capital/README_EN.md", "title_cn": "\u68c0\u6d4b\u5927\u5199\u5b57\u6bcd", "title_en": "Detect Capital", "question_title_slug": "detect-capital", "content_en": "

    We define the usage of capitals in a word to be right when one of the following cases holds:

    \n\n
      \n\t
    • All letters in this word are capitals, like "USA".
    • \n\t
    • All letters in this word are not capitals, like "leetcode".
    • \n\t
    • Only the first letter in this word is capital, like "Google".
    • \n
    \n\n

    Given a string word, return true if the usage of capitals in it is right.

    \n\n

     

    \n

    Example 1:

    \n
    Input: word = \"USA\"\nOutput: true\n

    Example 2:

    \n
    Input: word = \"FlaG\"\nOutput: false\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= word.length <= 100
    • \n\t
    • word consists of lowercase and uppercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5355\u8bcd\uff0c\u4f60\u9700\u8981\u5224\u65ad\u5355\u8bcd\u7684\u5927\u5199\u4f7f\u7528\u662f\u5426\u6b63\u786e\u3002

    \n\n

    \u6211\u4eec\u5b9a\u4e49\uff0c\u5728\u4ee5\u4e0b\u60c5\u51b5\u65f6\uff0c\u5355\u8bcd\u7684\u5927\u5199\u7528\u6cd5\u662f\u6b63\u786e\u7684\uff1a

    \n\n
      \n\t
    1. \u5168\u90e8\u5b57\u6bcd\u90fd\u662f\u5927\u5199\uff0c\u6bd4\u5982"USA"\u3002
    2. \n\t
    3. \u5355\u8bcd\u4e2d\u6240\u6709\u5b57\u6bcd\u90fd\u4e0d\u662f\u5927\u5199\uff0c\u6bd4\u5982"leetcode"\u3002
    4. \n\t
    5. \u5982\u679c\u5355\u8bcd\u4e0d\u53ea\u542b\u6709\u4e00\u4e2a\u5b57\u6bcd\uff0c\u53ea\u6709\u9996\u5b57\u6bcd\u5927\u5199\uff0c \u6bd4\u5982 "Google"\u3002
    6. \n
    \n\n

    \u5426\u5219\uff0c\u6211\u4eec\u5b9a\u4e49\u8fd9\u4e2a\u5355\u8bcd\u6ca1\u6709\u6b63\u786e\u4f7f\u7528\u5927\u5199\u5b57\u6bcd\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: "USA"\n\u8f93\u51fa: True\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: "FlaG"\n\u8f93\u51fa: False\n
    \n\n

    \u6ce8\u610f: \u8f93\u5165\u662f\u7531\u5927\u5199\u548c\u5c0f\u5199\u62c9\u4e01\u5b57\u6bcd\u7ec4\u6210\u7684\u975e\u7a7a\u5355\u8bcd\u3002

    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool detectCapitalUse(string word) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean detectCapitalUse(String word) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def detectCapitalUse(self, word):\n \"\"\"\n :type word: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def detectCapitalUse(self, word: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool detectCapitalUse(char * word){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool DetectCapitalUse(string word) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} word\n * @return {boolean}\n */\nvar detectCapitalUse = function(word) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} word\n# @return {Boolean}\ndef detect_capital_use(word)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func detectCapitalUse(_ word: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func detectCapitalUse(word string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def detectCapitalUse(word: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun detectCapitalUse(word: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn detect_capital_use(word: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $word\n * @return Boolean\n */\n function detectCapitalUse($word) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function detectCapitalUse(word: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (detect-capital-use word)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0520](https://leetcode-cn.com/problems/detect-capital)", "[\u68c0\u6d4b\u5927\u5199\u5b57\u6bcd](/solution/0500-0599/0520.Detect%20Capital/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0520](https://leetcode.com/problems/detect-capital)", "[Detect Capital](/solution/0500-0599/0520.Detect%20Capital/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "0518", "frontend_question_id": "0518", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/coin-change-2", "url_en": "https://leetcode.com/problems/coin-change-2", "relative_path_cn": "/solution/0500-0599/0518.Coin%20Change%202/README.md", "relative_path_en": "/solution/0500-0599/0518.Coin%20Change%202/README_EN.md", "title_cn": "\u96f6\u94b1\u5151\u6362 II", "title_en": "Coin Change 2", "question_title_slug": "coin-change-2", "content_en": "

    You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money.

    \n\n

    Return the number of combinations that make up that amount. If that amount of money cannot be made up by any combination of the coins, return 0.

    \n\n

    You may assume that you have an infinite number of each kind of coin.

    \n\n

    The answer is guaranteed to fit into a signed 32-bit integer.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: amount = 5, coins = [1,2,5]\nOutput: 4\nExplanation: there are four ways to make up the amount:\n5=5\n5=2+2+1\n5=2+1+1+1\n5=1+1+1+1+1\n
    \n\n

    Example 2:

    \n\n
    \nInput: amount = 3, coins = [2]\nOutput: 0\nExplanation: the amount of 3 cannot be made up just with coins of 2.\n
    \n\n

    Example 3:

    \n\n
    \nInput: amount = 10, coins = [10]\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= coins.length <= 300
    • \n\t
    • 1 <= coins[i] <= 5000
    • \n\t
    • All the values of coins are unique.
    • \n\t
    • 0 <= amount <= 5000
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e0d\u540c\u9762\u989d\u7684\u786c\u5e01\u548c\u4e00\u4e2a\u603b\u91d1\u989d\u3002\u5199\u51fa\u51fd\u6570\u6765\u8ba1\u7b97\u53ef\u4ee5\u51d1\u6210\u603b\u91d1\u989d\u7684\u786c\u5e01\u7ec4\u5408\u6570\u3002\u5047\u8bbe\u6bcf\u4e00\u79cd\u9762\u989d\u7684\u786c\u5e01\u6709\u65e0\u9650\u4e2a\u3002 

    \n\n

     

    \n\n
      \n
    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: amount = 5, coins = [1, 2, 5]\n\u8f93\u51fa: 4\n\u89e3\u91ca: \u6709\u56db\u79cd\u65b9\u5f0f\u53ef\u4ee5\u51d1\u6210\u603b\u91d1\u989d:\n5=5\n5=2+2+1\n5=2+1+1+1\n5=1+1+1+1+1\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: amount = 3, coins = [2]\n\u8f93\u51fa: 0\n\u89e3\u91ca: \u53ea\u7528\u9762\u989d2\u7684\u786c\u5e01\u4e0d\u80fd\u51d1\u6210\u603b\u91d1\u989d3\u3002\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u8f93\u5165: amount = 10, coins = [10] \n\u8f93\u51fa: 1\n
    \n\n

     

    \n\n

    \u6ce8\u610f:

    \n\n

    \u4f60\u53ef\u4ee5\u5047\u8bbe\uff1a

    \n\n
      \n\t
    • 0 <= amount (\u603b\u91d1\u989d) <= 5000
    • \n\t
    • 1 <= coin (\u786c\u5e01\u9762\u989d) <= 5000
    • \n\t
    • \u786c\u5e01\u79cd\u7c7b\u4e0d\u8d85\u8fc7 500 \u79cd
    • \n\t
    • \u7ed3\u679c\u7b26\u5408 32 \u4f4d\u7b26\u53f7\u6574\u6570
    • \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int change(int amount, vector& coins) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int change(int amount, int[] coins) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def change(self, amount, coins):\n \"\"\"\n :type amount: int\n :type coins: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def change(self, amount: int, coins: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint change(int amount, int* coins, int coinsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int Change(int amount, int[] coins) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} amount\n * @param {number[]} coins\n * @return {number}\n */\nvar change = function(amount, coins) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} amount\n# @param {Integer[]} coins\n# @return {Integer}\ndef change(amount, coins)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func change(_ amount: Int, _ coins: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func change(amount int, coins []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def change(amount: Int, coins: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun change(amount: Int, coins: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn change(amount: i32, coins: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $amount\n * @param Integer[] $coins\n * @return Integer\n */\n function change($amount, $coins) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function change(amount: number, coins: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (change amount coins)\n (-> exact-integer? (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0518](https://leetcode-cn.com/problems/coin-change-2)", "[\u96f6\u94b1\u5151\u6362 II](/solution/0500-0599/0518.Coin%20Change%202/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0518](https://leetcode.com/problems/coin-change-2)", "[Coin Change 2](/solution/0500-0599/0518.Coin%20Change%202/README_EN.md)", "", "Medium", ""]}, {"question_id": "0517", "frontend_question_id": "0517", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/super-washing-machines", "url_en": "https://leetcode.com/problems/super-washing-machines", "relative_path_cn": "/solution/0500-0599/0517.Super%20Washing%20Machines/README.md", "relative_path_en": "/solution/0500-0599/0517.Super%20Washing%20Machines/README_EN.md", "title_cn": "\u8d85\u7ea7\u6d17\u8863\u673a", "title_en": "Super Washing Machines", "question_title_slug": "super-washing-machines", "content_en": "

    You have n super washing machines on a line. Initially, each washing machine has some dresses or is empty.

    \n\n

    For each move, you could choose any m (1 <= m <= n) washing machines, and pass one dress of each washing machine to one of its adjacent washing machines at the same time.

    \n\n

    Given an integer array machines representing the number of dresses in each washing machine from left to right on the line, return the minimum number of moves to make all the washing machines have the same number of dresses. If it is not possible to do it, return -1.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: machines = [1,0,5]\nOutput: 3\nExplanation:\n1st move:    1     0 <-- 5    =>    1     1     4\n2nd move:    1 <-- 1 <-- 4    =>    2     1     3\n3rd move:    2     1 <-- 3    =>    2     2     2\n
    \n\n

    Example 2:

    \n\n
    \nInput: machines = [0,3,0]\nOutput: 2\nExplanation:\n1st move:    0 <-- 3     0    =>    1     2     0\n2nd move:    1     2 --> 0    =>    1     1     1\n
    \n\n

    Example 3:

    \n\n
    \nInput: machines = [0,2,0]\nOutput: -1\nExplanation:\nIt's impossible to make all three washing machines have the same number of dresses.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == machines.length
    • \n\t
    • 1 <= n <= 104
    • \n\t
    • 0 <= machines[i] <= 105
    • \n
    \n", "content_cn": "

    \u5047\u8bbe\u6709 \u53f0\u8d85\u7ea7\u6d17\u8863\u673a\u653e\u5728\u540c\u4e00\u6392\u4e0a\u3002\u5f00\u59cb\u7684\u65f6\u5019\uff0c\u6bcf\u53f0\u6d17\u8863\u673a\u5185\u53ef\u80fd\u6709\u4e00\u5b9a\u91cf\u7684\u8863\u670d\uff0c\u4e5f\u53ef\u80fd\u662f\u7a7a\u7684\u3002

    \n\n

    \u5728\u6bcf\u4e00\u6b65\u64cd\u4f5c\u4e2d\uff0c\u4f60\u53ef\u4ee5\u9009\u62e9\u4efb\u610f m \uff081 ≤ m ≤ n\uff09 \u53f0\u6d17\u8863\u673a\uff0c\u4e0e\u6b64\u540c\u65f6\u5c06\u6bcf\u53f0\u6d17\u8863\u673a\u7684\u4e00\u4ef6\u8863\u670d\u9001\u5230\u76f8\u90bb\u7684\u4e00\u53f0\u6d17\u8863\u673a\u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\u6570\u7ec4\u4ee3\u8868\u4ece\u5de6\u81f3\u53f3\u6bcf\u53f0\u6d17\u8863\u673a\u4e2d\u7684\u8863\u7269\u6570\u91cf\uff0c\u8bf7\u7ed9\u51fa\u80fd\u8ba9\u6240\u6709\u6d17\u8863\u673a\u4e2d\u5269\u4e0b\u7684\u8863\u7269\u7684\u6570\u91cf\u76f8\u7b49\u7684\u6700\u5c11\u7684\u64cd\u4f5c\u6b65\u6570\u3002\u5982\u679c\u4e0d\u80fd\u4f7f\u6bcf\u53f0\u6d17\u8863\u673a\u4e2d\u8863\u7269\u7684\u6570\u91cf\u76f8\u7b49\uff0c\u5219\u8fd4\u56de -1\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165: [1,0,5]\n\n\u8f93\u51fa: 3\n\n\u89e3\u91ca: \n\u7b2c\u4e00\u6b65:    1     0 <-- 5    =>    1     1     4\n\u7b2c\u4e8c\u6b65:    1 <-- 1 <-- 4    =>    2     1     3    \n\u7b2c\u4e09\u6b65:    2     1 <-- 3    =>    2     2     2   \n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165: [0,3,0]\n\n\u8f93\u51fa: 2\n\n\u89e3\u91ca: \n\u7b2c\u4e00\u6b65:    0 <-- 3     0    =>    1     2     0    \n\u7b2c\u4e8c\u6b65:    1     2 --> 0    =>    1     1     1     \n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u8f93\u5165: [0,2,0]\n\n\u8f93\u51fa: -1\n\n\u89e3\u91ca: \n\u4e0d\u53ef\u80fd\u8ba9\u6240\u6709\u4e09\u4e2a\u6d17\u8863\u673a\u540c\u65f6\u5269\u4e0b\u76f8\u540c\u6570\u91cf\u7684\u8863\u7269\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. n \u7684\u8303\u56f4\u662f [1, 10000]\u3002
    2. \n\t
    3. \u5728\u6bcf\u53f0\u8d85\u7ea7\u6d17\u8863\u673a\u4e2d\uff0c\u8863\u7269\u6570\u91cf\u7684\u8303\u56f4\u662f [0, 1e5]\u3002
    4. \n
    \n\n

     

    \n", "tags_en": ["Math", "Dynamic Programming"], "tags_cn": ["\u6570\u5b66", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findMinMoves(vector& machines) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findMinMoves(int[] machines) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findMinMoves(self, machines):\n \"\"\"\n :type machines: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findMinMoves(self, machines: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findMinMoves(int* machines, int machinesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindMinMoves(int[] machines) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} machines\n * @return {number}\n */\nvar findMinMoves = function(machines) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} machines\n# @return {Integer}\ndef find_min_moves(machines)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findMinMoves(_ machines: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findMinMoves(machines []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findMinMoves(machines: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findMinMoves(machines: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_min_moves(machines: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $machines\n * @return Integer\n */\n function findMinMoves($machines) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findMinMoves(machines: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-min-moves machines)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0517](https://leetcode-cn.com/problems/super-washing-machines)", "[\u8d85\u7ea7\u6d17\u8863\u673a](/solution/0500-0599/0517.Super%20Washing%20Machines/README.md)", "`\u6570\u5b66`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0517](https://leetcode.com/problems/super-washing-machines)", "[Super Washing Machines](/solution/0500-0599/0517.Super%20Washing%20Machines/README_EN.md)", "`Math`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0516", "frontend_question_id": "0516", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-palindromic-subsequence", "url_en": "https://leetcode.com/problems/longest-palindromic-subsequence", "relative_path_cn": "/solution/0500-0599/0516.Longest%20Palindromic%20Subsequence/README.md", "relative_path_en": "/solution/0500-0599/0516.Longest%20Palindromic%20Subsequence/README_EN.md", "title_cn": "\u6700\u957f\u56de\u6587\u5b50\u5e8f\u5217", "title_en": "Longest Palindromic Subsequence", "question_title_slug": "longest-palindromic-subsequence", "content_en": "

    Given a string s, find the longest palindromic subsequence's length in s.

    \n\n

    A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "bbbab"\nOutput: 4\nExplanation: One possible longest palindromic subsequence is "bbbb".\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "cbbd"\nOutput: 2\nExplanation: One possible longest palindromic subsequence is "bb".\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 1000
    • \n\t
    • s consists only of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32 s \uff0c\u627e\u5230\u5176\u4e2d\u6700\u957f\u7684\u56de\u6587\u5b50\u5e8f\u5217\uff0c\u5e76\u8fd4\u56de\u8be5\u5e8f\u5217\u7684\u957f\u5ea6\u3002\u53ef\u4ee5\u5047\u8bbe s \u7684\u6700\u5927\u957f\u5ea6\u4e3a 1000 \u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1:
    \n\u8f93\u5165:

    \n\n
    "bbbab"\n
    \n\n

    \u8f93\u51fa:

    \n\n
    4\n
    \n\n

    \u4e00\u4e2a\u53ef\u80fd\u7684\u6700\u957f\u56de\u6587\u5b50\u5e8f\u5217\u4e3a "bbbb"\u3002

    \n\n

    \u793a\u4f8b 2:
    \n\u8f93\u5165:

    \n\n
    "cbbd"\n
    \n\n

    \u8f93\u51fa:

    \n\n
    2\n
    \n\n

    \u4e00\u4e2a\u53ef\u80fd\u7684\u6700\u957f\u56de\u6587\u5b50\u5e8f\u5217\u4e3a "bb"\u3002

    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 1000
    • \n\t
    • s \u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int longestPalindromeSubseq(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int longestPalindromeSubseq(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestPalindromeSubseq(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestPalindromeSubseq(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint longestPalindromeSubseq(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LongestPalindromeSubseq(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar longestPalindromeSubseq = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef longest_palindrome_subseq(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestPalindromeSubseq(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestPalindromeSubseq(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestPalindromeSubseq(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestPalindromeSubseq(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_palindrome_subseq(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function longestPalindromeSubseq($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestPalindromeSubseq(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-palindrome-subseq s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0516](https://leetcode-cn.com/problems/longest-palindromic-subsequence)", "[\u6700\u957f\u56de\u6587\u5b50\u5e8f\u5217](/solution/0500-0599/0516.Longest%20Palindromic%20Subsequence/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0516](https://leetcode.com/problems/longest-palindromic-subsequence)", "[Longest Palindromic Subsequence](/solution/0500-0599/0516.Longest%20Palindromic%20Subsequence/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0515", "frontend_question_id": "0515", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-largest-value-in-each-tree-row", "url_en": "https://leetcode.com/problems/find-largest-value-in-each-tree-row", "relative_path_cn": "/solution/0500-0599/0515.Find%20Largest%20Value%20in%20Each%20Tree%20Row/README.md", "relative_path_en": "/solution/0500-0599/0515.Find%20Largest%20Value%20in%20Each%20Tree%20Row/README_EN.md", "title_cn": "\u5728\u6bcf\u4e2a\u6811\u884c\u4e2d\u627e\u6700\u5927\u503c", "title_en": "Find Largest Value in Each Tree Row", "question_title_slug": "find-largest-value-in-each-tree-row", "content_en": "

    Given the root of a binary tree, return an array of the largest value in each row of the tree (0-indexed).

    \n\n

     

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,3,2,5,3,null,9]\nOutput: [1,3,9]\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = [1,2,3]\nOutput: [1,3]\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = [1]\nOutput: [1]\n
    \n\n

    Example 4:

    \n\n
    \nInput: root = [1,null,2]\nOutput: [1,2]\n
    \n\n

    Example 5:

    \n\n
    \nInput: root = []\nOutput: []\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree will be in the range [0, 104].
    • \n\t
    • -231 <= Node.val <= 231 - 1
    • \n
    \n", "content_cn": "

    \u60a8\u9700\u8981\u5728\u4e8c\u53c9\u6811\u7684\u6bcf\u4e00\u884c\u4e2d\u627e\u5230\u6700\u5927\u7684\u503c\u3002

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165: \n\n          1\n         / \\\n        3   2\n       / \\   \\  \n      5   3   9 \n\n\u8f93\u51fa: [1, 3, 9]\n
    \n", "tags_en": ["Tree", "Depth-first Search", "Breadth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector largestValues(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public List largestValues(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def largestValues(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def largestValues(self, root: TreeNode) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* largestValues(struct TreeNode* root, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public IList LargestValues(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number[]}\n */\nvar largestValues = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer[]}\ndef largest_values(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func largestValues(_ root: TreeNode?) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc largestValues(root *TreeNode) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def largestValues(root: TreeNode): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun largestValues(root: TreeNode?): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn largest_values(root: Option>>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer[]\n */\n function largestValues($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction largestValues(root: TreeNode | null): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (largest-values root)\n (-> (or/c tree-node? #f) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0515](https://leetcode-cn.com/problems/find-largest-value-in-each-tree-row)", "[\u5728\u6bcf\u4e2a\u6811\u884c\u4e2d\u627e\u6700\u5927\u503c](/solution/0500-0599/0515.Find%20Largest%20Value%20in%20Each%20Tree%20Row/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0515](https://leetcode.com/problems/find-largest-value-in-each-tree-row)", "[Find Largest Value in Each Tree Row](/solution/0500-0599/0515.Find%20Largest%20Value%20in%20Each%20Tree%20Row/README_EN.md)", "`Tree`,`Depth-first Search`,`Breadth-first Search`", "Medium", ""]}, {"question_id": "0514", "frontend_question_id": "0514", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/freedom-trail", "url_en": "https://leetcode.com/problems/freedom-trail", "relative_path_cn": "/solution/0500-0599/0514.Freedom%20Trail/README.md", "relative_path_en": "/solution/0500-0599/0514.Freedom%20Trail/README_EN.md", "title_cn": "\u81ea\u7531\u4e4b\u8def", "title_en": "Freedom Trail", "question_title_slug": "freedom-trail", "content_en": "

    In the video game Fallout 4, the quest "Road to Freedom" requires players to reach a metal dial called the "Freedom Trail Ring" and use the dial to spell a specific keyword to open the door.

    \n\n

    Given a string ring that represents the code engraved on the outer ring and another string key that represents the keyword that needs to be spelled, return the minimum number of steps to spell all the characters in the keyword.

    \n\n

    Initially, the first character of the ring is aligned at the "12:00" direction. You should spell all the characters in key one by one by rotating ring clockwise or anticlockwise to make each character of the string key aligned at the "12:00" direction and then by pressing the center button.

    \n\n

    At the stage of rotating the ring to spell the key character key[i]:

    \n\n
      \n\t
    1. You can rotate the ring clockwise or anticlockwise by one place, which counts as one step. The final purpose of the rotation is to align one of ring's characters at the "12:00" direction, where this character must equal key[i].
    2. \n\t
    3. If the character key[i] has been aligned at the "12:00" direction, press the center button to spell, which also counts as one step. After the pressing, you could begin to spell the next character in the key (next stage). Otherwise, you have finished all the spelling.
    4. \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: ring = "godding", key = "gd"\nOutput: 4\nExplanation:\nFor the first key character 'g', since it is already in place, we just need 1 step to spell this character. \nFor the second key character 'd', we need to rotate the ring "godding" anticlockwise by two steps to make it become "ddinggo".\nAlso, we need 1 more step for spelling.\nSo the final output is 4.\n
    \n\n

    Example 2:

    \n\n
    \nInput: ring = "godding", key = "godding"\nOutput: 13\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= ring.length, key.length <= 100
    • \n\t
    • ring and key consist of only lower case English letters.
    • \n\t
    • It is guaranteed that key could always be spelled by rotating ring.
    • \n
    \n", "content_cn": "

    \u7535\u5b50\u6e38\u620f\u201c\u8f90\u5c044\u201d\u4e2d\uff0c\u4efb\u52a1\u201c\u901a\u5411\u81ea\u7531\u201d\u8981\u6c42\u73a9\u5bb6\u5230\u8fbe\u540d\u4e3a\u201cFreedom Trail Ring\u201d\u7684\u91d1\u5c5e\u8868\u76d8\uff0c\u5e76\u4f7f\u7528\u8868\u76d8\u62fc\u5199\u7279\u5b9a\u5173\u952e\u8bcd\u624d\u80fd\u5f00\u95e8\u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\u00a0ring\uff0c\u8868\u793a\u523b\u5728\u5916\u73af\u4e0a\u7684\u7f16\u7801\uff1b\u7ed9\u5b9a\u53e6\u4e00\u4e2a\u5b57\u7b26\u4e32\u00a0key\uff0c\u8868\u793a\u9700\u8981\u62fc\u5199\u7684\u5173\u952e\u8bcd\u3002\u60a8\u9700\u8981\u7b97\u51fa\u80fd\u591f\u62fc\u5199\u5173\u952e\u8bcd\u4e2d\u6240\u6709\u5b57\u7b26\u7684\u6700\u5c11\u6b65\u6570\u3002

    \n\n

    \u6700\u521d\uff0cring\u00a0\u7684\u7b2c\u4e00\u4e2a\u5b57\u7b26\u4e0e12:00\u65b9\u5411\u5bf9\u9f50\u3002\u60a8\u9700\u8981\u987a\u65f6\u9488\u6216\u9006\u65f6\u9488\u65cb\u8f6c ring \u4ee5\u4f7f\u00a0key\u00a0\u7684\u4e00\u4e2a\u5b57\u7b26\u5728 12:00 \u65b9\u5411\u5bf9\u9f50\uff0c\u7136\u540e\u6309\u4e0b\u4e2d\u5fc3\u6309\u94ae\uff0c\u4ee5\u6b64\u9010\u4e2a\u62fc\u5199\u5b8c\u00a0key\u00a0\u4e2d\u7684\u6240\u6709\u5b57\u7b26\u3002

    \n\n

    \u65cb\u8f6c\u00a0ring\u00a0\u62fc\u51fa key \u5b57\u7b26\u00a0key[i]\u00a0\u7684\u9636\u6bb5\u4e2d\uff1a

    \n\n
      \n\t
    1. \u60a8\u53ef\u4ee5\u5c06\u00a0ring\u00a0\u987a\u65f6\u9488\u6216\u9006\u65f6\u9488\u65cb\u8f6c\u4e00\u4e2a\u4f4d\u7f6e\uff0c\u8ba1\u4e3a1\u6b65\u3002\u65cb\u8f6c\u7684\u6700\u7ec8\u76ee\u7684\u662f\u5c06\u5b57\u7b26\u4e32\u00a0ring\u00a0\u7684\u4e00\u4e2a\u5b57\u7b26\u4e0e 12:00 \u65b9\u5411\u5bf9\u9f50\uff0c\u5e76\u4e14\u8fd9\u4e2a\u5b57\u7b26\u5fc5\u987b\u7b49\u4e8e\u5b57\u7b26\u00a0key[i] \u3002
    2. \n\t
    3. \u5982\u679c\u5b57\u7b26\u00a0key[i]\u00a0\u5df2\u7ecf\u5bf9\u9f50\u523012:00\u65b9\u5411\uff0c\u60a8\u9700\u8981\u6309\u4e0b\u4e2d\u5fc3\u6309\u94ae\u8fdb\u884c\u62fc\u5199\uff0c\u8fd9\u4e5f\u5c06\u7b97\u4f5c\u00a01 \u6b65\u3002\u6309\u5b8c\u4e4b\u540e\uff0c\u60a8\u53ef\u4ee5\u5f00\u59cb\u62fc\u5199\u00a0key\u00a0\u7684\u4e0b\u4e00\u4e2a\u5b57\u7b26\uff08\u4e0b\u4e00\u9636\u6bb5\uff09, \u76f4\u81f3\u5b8c\u6210\u6240\u6709\u62fc\u5199\u3002
    4. \n
    \n\n

    \u793a\u4f8b\uff1a

    \n\n

    \u00a0

    \n\n
    \n\u00a0\n\n
    \n\u8f93\u5165: ring = \"godding\", key = \"gd\"\n\u8f93\u51fa: 4\n\u89e3\u91ca:\n \u5bf9\u4e8e key \u7684\u7b2c\u4e00\u4e2a\u5b57\u7b26 'g'\uff0c\u5df2\u7ecf\u5728\u6b63\u786e\u7684\u4f4d\u7f6e, \u6211\u4eec\u53ea\u9700\u89811\u6b65\u6765\u62fc\u5199\u8fd9\u4e2a\u5b57\u7b26\u3002 \n \u5bf9\u4e8e key \u7684\u7b2c\u4e8c\u4e2a\u5b57\u7b26 'd'\uff0c\u6211\u4eec\u9700\u8981\u9006\u65f6\u9488\u65cb\u8f6c ring \"godding\" 2\u6b65\u4f7f\u5b83\u53d8\u6210 \"ddinggo\"\u3002\n \u5f53\u7136, \u6211\u4eec\u8fd8\u9700\u89811\u6b65\u8fdb\u884c\u62fc\u5199\u3002\n \u56e0\u6b64\u6700\u7ec8\u7684\u8f93\u51fa\u662f 4\u3002\n
    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. ring \u548c\u00a0key\u00a0\u7684\u5b57\u7b26\u4e32\u957f\u5ea6\u53d6\u503c\u8303\u56f4\u5747\u4e3a\u00a01 \u81f3\u00a0100\uff1b
    2. \n\t
    3. \u4e24\u4e2a\u5b57\u7b26\u4e32\u4e2d\u90fd\u53ea\u6709\u5c0f\u5199\u5b57\u7b26\uff0c\u5e76\u4e14\u5747\u53ef\u80fd\u5b58\u5728\u91cd\u590d\u5b57\u7b26\uff1b
    4. \n\t
    5. \u5b57\u7b26\u4e32\u00a0key\u00a0\u4e00\u5b9a\u53ef\u4ee5\u7531\u5b57\u7b26\u4e32 ring\u00a0\u65cb\u8f6c\u62fc\u51fa\u3002
    6. \n
    \n", "tags_en": ["Depth-first Search", "Divide and Conquer", "Dynamic Programming"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5206\u6cbb\u7b97\u6cd5", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findRotateSteps(string ring, string key) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findRotateSteps(String ring, String key) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findRotateSteps(self, ring, key):\n \"\"\"\n :type ring: str\n :type key: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findRotateSteps(self, ring: str, key: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findRotateSteps(char * ring, char * key){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindRotateSteps(string ring, string key) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} ring\n * @param {string} key\n * @return {number}\n */\nvar findRotateSteps = function(ring, key) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} ring\n# @param {String} key\n# @return {Integer}\ndef find_rotate_steps(ring, key)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findRotateSteps(_ ring: String, _ key: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findRotateSteps(ring string, key string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findRotateSteps(ring: String, key: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findRotateSteps(ring: String, key: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_rotate_steps(ring: String, key: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $ring\n * @param String $key\n * @return Integer\n */\n function findRotateSteps($ring, $key) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findRotateSteps(ring: string, key: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-rotate-steps ring key)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0514](https://leetcode-cn.com/problems/freedom-trail)", "[\u81ea\u7531\u4e4b\u8def](/solution/0500-0599/0514.Freedom%20Trail/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5206\u6cbb\u7b97\u6cd5`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0514](https://leetcode.com/problems/freedom-trail)", "[Freedom Trail](/solution/0500-0599/0514.Freedom%20Trail/README_EN.md)", "`Depth-first Search`,`Divide and Conquer`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0513", "frontend_question_id": "0513", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-bottom-left-tree-value", "url_en": "https://leetcode.com/problems/find-bottom-left-tree-value", "relative_path_cn": "/solution/0500-0599/0513.Find%20Bottom%20Left%20Tree%20Value/README.md", "relative_path_en": "/solution/0500-0599/0513.Find%20Bottom%20Left%20Tree%20Value/README_EN.md", "title_cn": "\u627e\u6811\u5de6\u4e0b\u89d2\u7684\u503c", "title_en": "Find Bottom Left Tree Value", "question_title_slug": "find-bottom-left-tree-value", "content_en": "

    Given the root of a binary tree, return the leftmost value in the last row of the tree.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [2,1,3]\nOutput: 1\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [1,2,3,4,null,5,6,null,null,7]\nOutput: 7\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 104].
    • \n\t
    • -231 <= Node.val <= 231 - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811\uff0c\u5728\u6811\u7684\u6700\u540e\u4e00\u884c\u627e\u5230\u6700\u5de6\u8fb9\u7684\u503c\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165:\n\n    2\n   / \\\n  1   3\n\n\u8f93\u51fa:\n1\n
    \n\n

     

    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165:\n\n        1\n       / \\\n      2   3\n     /   / \\\n    4   5   6\n       /\n      7\n\n\u8f93\u51fa:\n7\n
    \n\n

     

    \n\n

    \u6ce8\u610f: \u60a8\u53ef\u4ee5\u5047\u8bbe\u6811\uff08\u5373\u7ed9\u5b9a\u7684\u6839\u8282\u70b9\uff09\u4e0d\u4e3a NULL\u3002

    \n", "tags_en": ["Tree", "Depth-first Search", "Breadth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int findBottomLeftValue(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int findBottomLeftValue(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def findBottomLeftValue(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def findBottomLeftValue(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint findBottomLeftValue(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int FindBottomLeftValue(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar findBottomLeftValue = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef find_bottom_left_value(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func findBottomLeftValue(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc findBottomLeftValue(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def findBottomLeftValue(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun findBottomLeftValue(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn find_bottom_left_value(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function findBottomLeftValue($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction findBottomLeftValue(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (find-bottom-left-value root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0513](https://leetcode-cn.com/problems/find-bottom-left-tree-value)", "[\u627e\u6811\u5de6\u4e0b\u89d2\u7684\u503c](/solution/0500-0599/0513.Find%20Bottom%20Left%20Tree%20Value/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0513](https://leetcode.com/problems/find-bottom-left-tree-value)", "[Find Bottom Left Tree Value](/solution/0500-0599/0513.Find%20Bottom%20Left%20Tree%20Value/README_EN.md)", "`Tree`,`Depth-first Search`,`Breadth-first Search`", "Medium", ""]}, {"question_id": "0511", "frontend_question_id": "1059", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/all-paths-from-source-lead-to-destination", "url_en": "https://leetcode.com/problems/all-paths-from-source-lead-to-destination", "relative_path_cn": "/solution/1000-1099/1059.All%20Paths%20from%20Source%20Lead%20to%20Destination/README.md", "relative_path_en": "/solution/1000-1099/1059.All%20Paths%20from%20Source%20Lead%20to%20Destination/README_EN.md", "title_cn": "\u4ece\u59cb\u70b9\u5230\u7ec8\u70b9\u7684\u6240\u6709\u8def\u5f84", "title_en": "All Paths from Source Lead to Destination", "question_title_slug": "all-paths-from-source-lead-to-destination", "content_en": "

    Given the edges of a directed graph where edges[i] = [ai, bi] indicates there is an edge between nodes ai and bi, and two nodes source and destination of this graph, determine whether or not all paths starting from source eventually, end at destination, that is:

    \n\n
      \n\t
    • At least one path exists from the source node to the destination node
    • \n\t
    • If a path exists from the source node to a node with no outgoing edges, then that node is equal to destination.
    • \n\t
    • The number of possible paths from source to destination is a finite number.
    • \n
    \n\n

    Return true if and only if all roads from source lead to destination.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: n = 3, edges = [[0,1],[0,2]], source = 0, destination = 2\nOutput: false\nExplanation: It is possible to reach and get stuck on both node 1 and node 2.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: n = 4, edges = [[0,1],[0,3],[1,2],[2,1]], source = 0, destination = 3\nOutput: false\nExplanation: We have two possibilities: to end at node 3, or to loop over node 1 and node 2 indefinitely.\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: n = 4, edges = [[0,1],[0,2],[1,3],[2,3]], source = 0, destination = 3\nOutput: true\n
    \n\n

    Example 4:

    \n\"\"\n
    \nInput: n = 3, edges = [[0,1],[1,1],[1,2]], source = 0, destination = 2\nOutput: false\nExplanation: All paths from the source node end at the destination node, but there are an infinite number of paths, such as 0-1-2, 0-1-1-2, 0-1-1-1-2, 0-1-1-1-1-2, and so on.\n
    \n\n

    Example 5:

    \n\"\"\n
    \nInput: n = 2, edges = [[0,1],[1,1]], source = 0, destination = 1\nOutput: false\nExplanation: There is infinite self-loop at destination node.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 104
    • \n\t
    • 0 <= edges.length <= 104
    • \n\t
    • edges.length == 2
    • \n\t
    • 0 <= ai, bi <= n - 1
    • \n\t
    • 0 <= source <= n - 1
    • \n\t
    • 0 <= destination <= n - 1
    • \n\t
    • The given graph may have self-loops and parallel edges.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u6709\u5411\u56fe\u7684\u8fb9 edges\uff0c\u4ee5\u53ca\u8be5\u56fe\u7684\u59cb\u70b9 source \u548c\u76ee\u6807\u7ec8\u70b9 destination\uff0c\u786e\u5b9a\u4ece\u59cb\u70b9 source \u51fa\u53d1\u7684\u6240\u6709\u8def\u5f84\u662f\u5426\u6700\u7ec8\u7ed3\u675f\u4e8e\u76ee\u6807\u7ec8\u70b9 destination\uff0c\u5373\uff1a

    \n\n
      \n\t
    • \u4ece\u59cb\u70b9 source \u5230\u76ee\u6807\u7ec8\u70b9 destination \u5b58\u5728\u81f3\u5c11\u4e00\u6761\u8def\u5f84
    • \n\t
    • \u5982\u679c\u5b58\u5728\u4ece\u59cb\u70b9 source \u5230\u6ca1\u6709\u51fa\u8fb9\u7684\u8282\u70b9\u7684\u8def\u5f84\uff0c\u5219\u8be5\u8282\u70b9\u5c31\u662f\u8def\u5f84\u7ec8\u70b9\u3002
    • \n\t
    • \u4ece\u59cb\u70b9source\u5230\u76ee\u6807\u7ec8\u70b9 destination \u53ef\u80fd\u8def\u5f84\u6570\u662f\u6709\u9650\u6570\u5b57
    • \n
    \n\n

    \u5f53\u4ece\u59cb\u70b9 source \u51fa\u53d1\u7684\u6240\u6709\u8def\u5f84\u90fd\u53ef\u4ee5\u5230\u8fbe\u76ee\u6807\u7ec8\u70b9 destination \u65f6\u8fd4\u56de true\uff0c\u5426\u5219\u8fd4\u56de false\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 3, edges = [[0,1],[0,2]], source = 0, destination = 2\n\u8f93\u51fa\uff1afalse\n\u8bf4\u660e\uff1a\u8282\u70b9 1 \u548c\u8282\u70b9 2 \u90fd\u53ef\u4ee5\u5230\u8fbe\uff0c\u4f46\u4e5f\u4f1a\u5361\u5728\u90a3\u91cc\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 4, edges = [[0,1],[0,3],[1,2],[2,1]], source = 0, destination = 3\n\u8f93\u51fa\uff1afalse\n\u8bf4\u660e\uff1a\u6709\u4e24\u79cd\u53ef\u80fd\uff1a\u5728\u8282\u70b9 3 \u5904\u7ed3\u675f\uff0c\u6216\u662f\u5728\u8282\u70b9 1 \u548c\u8282\u70b9 2 \u4e4b\u95f4\u65e0\u9650\u5faa\u73af\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 4, edges = [[0,1],[0,2],[1,3],[2,3]], source = 0, destination = 3\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 3, edges = [[0,1],[1,1],[1,2]], source = 0, destination = 2\n\u8f93\u51fa\uff1afalse\n\u8bf4\u660e\uff1a\u4ece\u59cb\u70b9\u51fa\u53d1\u7684\u6240\u6709\u8def\u5f84\u90fd\u5728\u76ee\u6807\u7ec8\u70b9\u7ed3\u675f\uff0c\u4f46\u5b58\u5728\u65e0\u9650\u591a\u7684\u8def\u5f84\uff0c\u5982 0-1-2\uff0c0-1-1-2\uff0c0-1-1-1-2\uff0c0-1-1-1-1-2 \u7b49\u3002\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1an = 2, edges = [[0,1],[1,1]], source = 0, destination = 1\n\u8f93\u51fa\uff1afalse\n\u8bf4\u660e\uff1a\u5728\u76ee\u6807\u8282\u70b9\u4e0a\u5b58\u5728\u65e0\u9650\u7684\u81ea\u73af\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. \u7ed9\u5b9a\u7684\u56fe\u4e2d\u53ef\u80fd\u5e26\u6709\u81ea\u73af\u548c\u5e73\u884c\u8fb9\u3002
    2. \n\t
    3. \u56fe\u4e2d\u7684\u8282\u70b9\u6570 n \u4ecb\u4e8e 1 \u548c 10000 \u4e4b\u95f4\u3002
    4. \n\t
    5. \u56fe\u4e2d\u7684\u8fb9\u6570\u5728 0 \u5230 10000 \u4e4b\u95f4\u3002
    6. \n\t
    7. 0 <= edges.length <= 10000
    8. \n\t
    9. edges[i].length == 2
    10. \n\t
    11. 0 <= source <= n - 1
    12. \n\t
    13. 0 <= destination <= n - 1
    14. \n
    \n", "tags_en": ["Depth-first Search", "Graph"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool leadsToDestination(int n, vector>& edges, int source, int destination) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean leadsToDestination(int n, int[][] edges, int source, int destination) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def leadsToDestination(self, n, edges, source, destination):\n \"\"\"\n :type n: int\n :type edges: List[List[int]]\n :type source: int\n :type destination: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def leadsToDestination(self, n: int, edges: List[List[int]], source: int, destination: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool leadsToDestination(int n, int** edges, int edgesSize, int* edgesColSize, int source, int destination){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool LeadsToDestination(int n, int[][] edges, int source, int destination) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} edges\n * @param {number} source\n * @param {number} destination\n * @return {boolean}\n */\nvar leadsToDestination = function(n, edges, source, destination) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} edges\n# @param {Integer} source\n# @param {Integer} destination\n# @return {Boolean}\ndef leads_to_destination(n, edges, source, destination)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func leadsToDestination(_ n: Int, _ edges: [[Int]], _ source: Int, _ destination: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func leadsToDestination(n int, edges [][]int, source int, destination int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def leadsToDestination(n: Int, edges: Array[Array[Int]], source: Int, destination: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun leadsToDestination(n: Int, edges: Array, source: Int, destination: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn leads_to_destination(n: i32, edges: Vec>, source: i32, destination: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $edges\n * @param Integer $source\n * @param Integer $destination\n * @return Boolean\n */\n function leadsToDestination($n, $edges, $source, $destination) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function leadsToDestination(n: number, edges: number[][], source: number, destination: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (leads-to-destination n edges source destination)\n (-> exact-integer? (listof (listof exact-integer?)) exact-integer? exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1059](https://leetcode-cn.com/problems/all-paths-from-source-lead-to-destination)", "[\u4ece\u59cb\u70b9\u5230\u7ec8\u70b9\u7684\u6240\u6709\u8def\u5f84](/solution/1000-1099/1059.All%20Paths%20from%20Source%20Lead%20to%20Destination/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u56fe`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[1059](https://leetcode.com/problems/all-paths-from-source-lead-to-destination)", "[All Paths from Source Lead to Destination](/solution/1000-1099/1059.All%20Paths%20from%20Source%20Lead%20to%20Destination/README_EN.md)", "`Depth-first Search`,`Graph`", "Medium", "\ud83d\udd12"]}, {"question_id": "0509", "frontend_question_id": "0510", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/inorder-successor-in-bst-ii", "url_en": "https://leetcode.com/problems/inorder-successor-in-bst-ii", "relative_path_cn": "/solution/0500-0599/0510.Inorder%20Successor%20in%20BST%20II/README.md", "relative_path_en": "/solution/0500-0599/0510.Inorder%20Successor%20in%20BST%20II/README_EN.md", "title_cn": "\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u7684\u4e2d\u5e8f\u540e\u7ee7 II", "title_en": "Inorder Successor in BST II", "question_title_slug": "inorder-successor-in-bst-ii", "content_en": "

    Given a node in a binary search tree, return the in-order successor of that node in the BST. If that node has no in-order successor, return null.

    \n\n

    The successor of a node is the node with the smallest key greater than node.val.

    \n\n

    You will have direct access to the node but not to the root of the tree. Each node will have a reference to its parent node. Below is the definition for Node:

    \n\n
    \nclass Node {\n    public int val;\n    public Node left;\n    public Node right;\n    public Node parent;\n}\n
    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: tree = [2,1,3], node = 1\nOutput: 2\nExplanation: 1's in-order successor node is 2. Note that both the node and the return value is of Node type.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: tree = [5,3,6,2,4,null,null,1], node = 6\nOutput: null\nExplanation: There is no in-order successor of the current node, so the answer is null.\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: tree = [15,6,18,3,7,17,20,2,4,null,13,null,null,null,null,null,null,null,null,9], node = 15\nOutput: 17\n
    \n\n

    Example 4:

    \n\"\"\n
    \nInput: tree = [15,6,18,3,7,17,20,2,4,null,13,null,null,null,null,null,null,null,null,9], node = 13\nOutput: 15\n
    \n\n

    Example 5:

    \n\n
    \nInput: tree = [0], node = 0\nOutput: null\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 104].
    • \n\t
    • -105 <= Node.val <= 105
    • \n\t
    • All Nodes will have unique values.
    • \n
    \n\n

     

    \n

    Follow up: Could you solve it without looking up any of the node's values?

    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u68f5\u4e8c\u53c9\u641c\u7d22\u6811\u548c\u5176\u4e2d\u7684\u4e00\u4e2a\u8282\u70b9 node \uff0c\u627e\u5230\u8be5\u8282\u70b9\u5728\u6811\u4e2d\u7684\u4e2d\u5e8f\u540e\u7ee7\u3002\u5982\u679c\u8282\u70b9\u6ca1\u6709\u4e2d\u5e8f\u540e\u7ee7\uff0c\u8bf7\u8fd4\u56de null \u3002

    \n\n

    \u4e00\u4e2a\u8282\u70b9 node \u7684\u4e2d\u5e8f\u540e\u7ee7\u662f\u952e\u503c\u6bd4 node.val \u5927\u6240\u6709\u7684\u8282\u70b9\u4e2d\u952e\u503c\u6700\u5c0f\u7684\u90a3\u4e2a\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u76f4\u63a5\u8bbf\u95ee\u7ed3\u70b9\uff0c\u4f46\u65e0\u6cd5\u76f4\u63a5\u8bbf\u95ee\u6811\u3002\u6bcf\u4e2a\u8282\u70b9\u90fd\u4f1a\u6709\u5176\u7236\u8282\u70b9\u7684\u5f15\u7528\u3002\u8282\u70b9\u00a0Node \u5b9a\u4e49\u5982\u4e0b\uff1a

    \n\n
    \nclass Node {\n    public int val;\n    public Node left;\n    public Node right;\n    public Node parent;\n}
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1atree = [2,1,3], node = 1\n\u8f93\u51fa\uff1a2\n\u89e3\u6790\uff1a1 \u7684\u4e2d\u5e8f\u540e\u7ee7\u7ed3\u70b9\u662f 2 \u3002\u6ce8\u610f\u8282\u70b9\u548c\u8fd4\u56de\u503c\u90fd\u662f Node \u7c7b\u578b\u7684\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1atree = [5,3,6,2,4,null,null,1], node = 6\n\u8f93\u51fa\uff1anull\n\u89e3\u6790\uff1a\u8be5\u7ed3\u70b9\u6ca1\u6709\u4e2d\u5e8f\u540e\u7ee7\uff0c\u56e0\u6b64\u8fd4\u56de null \u3002\n
    \n\n

    \u793a\u4f8b\u00a03\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1atree = [15,6,18,3,7,17,20,2,4,null,13,null,null,null,null,null,null,null,null,9], node = 15\n\u8f93\u51fa\uff1a17\n
    \n\n

    \u793a\u4f8b\u00a04\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1atree = [15,6,18,3,7,17,20,2,4,null,13,null,null,null,null,null,null,null,null,9], node = 13\n\u8f93\u51fa\uff1a15\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1atree = [0], node = 0\n\u8f93\u51fa\uff1anull\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u7684\u6570\u76ee\u5728\u8303\u56f4 [1, 104] \u5185\u3002
    • \n\t
    • -105 <= Node.val <= 105
    • \n\t
    • \u6811\u4e2d\u5404\u7ed3\u70b9\u7684\u503c\u5747\u4fdd\u8bc1\u552f\u4e00\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u80fd\u5426\u5728\u4e0d\u8bbf\u95ee\u4efb\u4f55\u7ed3\u70b9\u7684\u503c\u7684\u60c5\u51b5\u4e0b\u89e3\u51b3\u95ee\u9898?

    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* parent;\n};\n*/\n\nclass Solution {\npublic:\n Node* inorderSuccessor(Node* node) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/*\n// Definition for a Node.\nclass Node {\n public int val;\n public Node left;\n public Node right;\n public Node parent;\n};\n*/\n\nclass Solution {\n public Node inorderSuccessor(Node node) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "\"\"\"\n# Definition for a Node.\nclass Node:\n def __init__(self, val):\n self.val = val\n self.left = None\n self.right = None\n self.parent = None\n\"\"\"\n\nclass Solution(object):\n def inorderSuccessor(self, node):\n \"\"\"\n :type node: Node\n :rtype: Node\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "\"\"\"\n# Definition for a Node.\nclass Node:\n def __init__(self, val):\n self.val = val\n self.left = None\n self.right = None\n self.parent = None\n\"\"\"\n\nclass Solution:\n def inorderSuccessor(self, node: 'Node') -> 'Node':\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/*\n// Definition for a Node.\nstruct Node {\n int val;\n struct Node* left;\n struct Node* right;\n struct Node* parent;\n};\n*/\n\nstruct Node* inorderSuccessor(struct Node* node) {\n\t\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/*\n// Definition for a Node.\npublic class Node {\n public int val;\n public Node left;\n public Node right;\n public Node parent;\n}\n*/\n\npublic class Solution {\n public Node InorderSuccessor(Node x) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // Definition for a Node.\n * function Node(val) {\n * this.val = val;\n * this.left = null;\n * this.right = null;\n * this.parent = null;\n * };\n */\n\n/**\n * @param {Node} node\n * @return {Node}\n */\nvar inorderSuccessor = function(node) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a Node.\n# class Node\n# attr_accessor :val, :left, :right, :parent\n# def initialize(val=0)\n# @val = val\n# @left, @right, parent = nil, nil, nil\n# end\n# end\n\n# @param {Node} root\n# @return {Node}\ndef inorderSuccessor(node)\n\t\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a Node.\n * public class Node {\n * public var val: Int\n * public var left: Node?\n * public var right: Node?\n * public var parent: Node?\n * public init(_ val: Int) {\n * self.val = val\n * self.left = nil\n * self.right = nil\n * self.parent = nil\n * }\n * }\n */\n\nclass Solution {\n func inorderSuccessor(_ node: Node?) -> Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for Node.\n * type Node struct {\n * Val int\n * Left *Node\n * Right *Node\n * Parent *Node\n * }\n */\n\nfunc inorderSuccessor(node *Node) *Node {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a Node.\n * class Node(var _value: Int) {\n * var value: Int = _value\n * var left: Node = null\n * var right: Node = null\n * var parent: Node = null\n * }\n */\n\nobject Solution {\n def inorderSuccessor(node: Node): Node = {\n\t\t\n\t}\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a Node.\n * class Node(var `val`: Int) {\n *\t\tvar left: TreeNode? = null\n *\t\tvar right: TreeNode? = null\n *\t\tvar parent: Node? = null\n * }\n */\n\nclass Solution {\n fun inorderSuccessor(node: Node?): Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a Node.\n * class Node {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * public $parent = null;\n * function __construct($val = 0) {\n * $this->val = $val;\n * $this->left = null;\n * $this->right = null;\n * $this->parent = null;\n * }\n * }\n */\n\nclass Solution {\n /**\n * @param Node $node\n * @return Node\n */\n function inorderSuccessor($node) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class Node {\n * val: number\n * left: Node | null\n * right: Node | null\n * parent: Node | null\n * constructor(val?: number, left?: Node | null, right?: Node | null, parent?: Node | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * this.parent = (parent===undefined ? null : parent)\n * }\n * }\n */\n\nfunction inorderSuccessor(node: Node | null): Node | null {\n\t\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0510](https://leetcode-cn.com/problems/inorder-successor-in-bst-ii)", "[\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u7684\u4e2d\u5e8f\u540e\u7ee7 II](/solution/0500-0599/0510.Inorder%20Successor%20in%20BST%20II/README.md)", "`\u6811`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0510](https://leetcode.com/problems/inorder-successor-in-bst-ii)", "[Inorder Successor in BST II](/solution/0500-0599/0510.Inorder%20Successor%20in%20BST%20II/README_EN.md)", "`Tree`", "Medium", "\ud83d\udd12"]}, {"question_id": "0508", "frontend_question_id": "0508", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/most-frequent-subtree-sum", "url_en": "https://leetcode.com/problems/most-frequent-subtree-sum", "relative_path_cn": "/solution/0500-0599/0508.Most%20Frequent%20Subtree%20Sum/README.md", "relative_path_en": "/solution/0500-0599/0508.Most%20Frequent%20Subtree%20Sum/README_EN.md", "title_cn": "\u51fa\u73b0\u6b21\u6570\u6700\u591a\u7684\u5b50\u6811\u5143\u7d20\u548c", "title_en": "Most Frequent Subtree Sum", "question_title_slug": "most-frequent-subtree-sum", "content_en": "

    Given the root of a binary tree, return the most frequent subtree sum. If there is a tie, return all the values with the highest frequency in any order.

    \n\n

    The subtree sum of a node is defined as the sum of all the node values formed by the subtree rooted at that node (including the node itself).

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [5,2,-3]\nOutput: [2,-3,4]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [5,2,-5]\nOutput: [2]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 104].
    • \n\t
    • -105 <= Node.val <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u4e8c\u53c9\u6811\u7684\u6839\u7ed3\u70b9\uff0c\u8bf7\u4f60\u627e\u51fa\u51fa\u73b0\u6b21\u6570\u6700\u591a\u7684\u5b50\u6811\u5143\u7d20\u548c\u3002\u4e00\u4e2a\u7ed3\u70b9\u7684\u300c\u5b50\u6811\u5143\u7d20\u548c\u300d\u5b9a\u4e49\u4e3a\u4ee5\u8be5\u7ed3\u70b9\u4e3a\u6839\u7684\u4e8c\u53c9\u6811\u4e0a\u6240\u6709\u7ed3\u70b9\u7684\u5143\u7d20\u4e4b\u548c\uff08\u5305\u62ec\u7ed3\u70b9\u672c\u8eab\uff09\u3002

    \n\n

    \u4f60\u9700\u8981\u8fd4\u56de\u51fa\u73b0\u6b21\u6570\u6700\u591a\u7684\u5b50\u6811\u5143\u7d20\u548c\u3002\u5982\u679c\u6709\u591a\u4e2a\u5143\u7d20\u51fa\u73b0\u7684\u6b21\u6570\u76f8\u540c\uff0c\u8fd4\u56de\u6240\u6709\u51fa\u73b0\u6b21\u6570\u6700\u591a\u7684\u5b50\u6811\u5143\u7d20\u548c\uff08\u4e0d\u9650\u987a\u5e8f\uff09\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a
    \n\u8f93\u5165:

    \n\n
      5\n /  \\\n2   -3\n
    \n\n

    \u8fd4\u56de [2, -3, 4]\uff0c\u6240\u6709\u7684\u503c\u5747\u53ea\u51fa\u73b0\u4e00\u6b21\uff0c\u4ee5\u4efb\u610f\u987a\u5e8f\u8fd4\u56de\u6240\u6709\u503c\u3002

    \n\n

    \u793a\u4f8b 2\uff1a
    \n\u8f93\u5165\uff1a

    \n\n
      5\n /  \\\n2   -5\n
    \n\n

    \u8fd4\u56de [2]\uff0c\u53ea\u6709 2 \u51fa\u73b0\u4e24\u6b21\uff0c-5 \u53ea\u51fa\u73b0 1 \u6b21\u3002

    \n\n

     

    \n\n

    \u63d0\u793a\uff1a \u5047\u8bbe\u4efb\u610f\u5b50\u6811\u5143\u7d20\u548c\u5747\u53ef\u4ee5\u7528 32 \u4f4d\u6709\u7b26\u53f7\u6574\u6570\u8868\u793a\u3002

    \n", "tags_en": ["Tree", "Hash Table"], "tags_cn": ["\u6811", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector findFrequentTreeSum(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int[] findFrequentTreeSum(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def findFrequentTreeSum(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def findFrequentTreeSum(self, root: TreeNode) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* findFrequentTreeSum(struct TreeNode* root, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int[] FindFrequentTreeSum(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number[]}\n */\nvar findFrequentTreeSum = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer[]}\ndef find_frequent_tree_sum(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func findFrequentTreeSum(_ root: TreeNode?) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc findFrequentTreeSum(root *TreeNode) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def findFrequentTreeSum(root: TreeNode): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun findFrequentTreeSum(root: TreeNode?): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn find_frequent_tree_sum(root: Option>>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer[]\n */\n function findFrequentTreeSum($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction findFrequentTreeSum(root: TreeNode | null): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (find-frequent-tree-sum root)\n (-> (or/c tree-node? #f) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0508](https://leetcode-cn.com/problems/most-frequent-subtree-sum)", "[\u51fa\u73b0\u6b21\u6570\u6700\u591a\u7684\u5b50\u6811\u5143\u7d20\u548c](/solution/0500-0599/0508.Most%20Frequent%20Subtree%20Sum/README.md)", "`\u6811`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0508](https://leetcode.com/problems/most-frequent-subtree-sum)", "[Most Frequent Subtree Sum](/solution/0500-0599/0508.Most%20Frequent%20Subtree%20Sum/README_EN.md)", "`Tree`,`Hash Table`", "Medium", ""]}, {"question_id": "0507", "frontend_question_id": "0507", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/perfect-number", "url_en": "https://leetcode.com/problems/perfect-number", "relative_path_cn": "/solution/0500-0599/0507.Perfect%20Number/README.md", "relative_path_en": "/solution/0500-0599/0507.Perfect%20Number/README_EN.md", "title_cn": "\u5b8c\u7f8e\u6570", "title_en": "Perfect Number", "question_title_slug": "perfect-number", "content_en": "

    A perfect number is a positive integer that is equal to the sum of its positive divisors, excluding the number itself. A divisor of an integer x is an integer that can divide x evenly.

    \n\n

    Given an integer n, return true if n is a perfect number, otherwise return false.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: num = 28\nOutput: true\nExplanation: 28 = 1 + 2 + 4 + 7 + 14\n1, 2, 4, 7, and 14 are all divisors of 28.\n
    \n\n

    Example 2:

    \n\n
    \nInput: num = 6\nOutput: true\n
    \n\n

    Example 3:

    \n\n
    \nInput: num = 496\nOutput: true\n
    \n\n

    Example 4:

    \n\n
    \nInput: num = 8128\nOutput: true\n
    \n\n

    Example 5:

    \n\n
    \nInput: num = 2\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= num <= 108
    • \n
    \n", "content_cn": "

    \u5bf9\u4e8e\u4e00\u4e2a \u6b63\u6574\u6570\uff0c\u5982\u679c\u5b83\u548c\u9664\u4e86\u5b83\u81ea\u8eab\u4ee5\u5916\u7684\u6240\u6709 \u6b63\u56e0\u5b50 \u4e4b\u548c\u76f8\u7b49\uff0c\u6211\u4eec\u79f0\u5b83\u4e3a \u300c\u5b8c\u7f8e\u6570\u300d\u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a \u6574\u6570 n\uff0c \u5982\u679c\u662f\u5b8c\u7f8e\u6570\uff0c\u8fd4\u56de true\uff0c\u5426\u5219\u8fd4\u56de false

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a28\n\u8f93\u51fa\uff1aTrue\n\u89e3\u91ca\uff1a28 = 1 + 2 + 4 + 7 + 14\n1, 2, 4, 7, \u548c 14 \u662f 28 \u7684\u6240\u6709\u6b63\u56e0\u5b50\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anum = 6\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1anum = 496\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1anum = 8128\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1anum = 2\n\u8f93\u51fa\uff1afalse\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= num <= 108
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool checkPerfectNumber(int num) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean checkPerfectNumber(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def checkPerfectNumber(self, num):\n \"\"\"\n :type num: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def checkPerfectNumber(self, num: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool checkPerfectNumber(int num){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CheckPerfectNumber(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} num\n * @return {boolean}\n */\nvar checkPerfectNumber = function(num) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} num\n# @return {Boolean}\ndef check_perfect_number(num)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func checkPerfectNumber(_ num: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func checkPerfectNumber(num int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def checkPerfectNumber(num: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun checkPerfectNumber(num: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn check_perfect_number(num: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $num\n * @return Boolean\n */\n function checkPerfectNumber($num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function checkPerfectNumber(num: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (check-perfect-number num)\n (-> exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0507](https://leetcode-cn.com/problems/perfect-number)", "[\u5b8c\u7f8e\u6570](/solution/0500-0599/0507.Perfect%20Number/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0507](https://leetcode.com/problems/perfect-number)", "[Perfect Number](/solution/0500-0599/0507.Perfect%20Number/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "0506", "frontend_question_id": "0506", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/relative-ranks", "url_en": "https://leetcode.com/problems/relative-ranks", "relative_path_cn": "/solution/0500-0599/0506.Relative%20Ranks/README.md", "relative_path_en": "/solution/0500-0599/0506.Relative%20Ranks/README_EN.md", "title_cn": "\u76f8\u5bf9\u540d\u6b21", "title_en": "Relative Ranks", "question_title_slug": "relative-ranks", "content_en": "

    You are given an integer array score of size n, where score[i] is the score of the ith athlete in a competition. All the scores are guaranteed to be unique.

    \n\n

    The athletes are placed based on their scores, where the 1st place athlete has the highest score, the 2nd place athlete has the 2nd highest score, and so on. The placement of each athlete determines their rank:

    \n\n
      \n\t
    • The 1st place athlete's rank is "Gold Medal".
    • \n\t
    • The 2nd place athlete's rank is "Silver Medal".
    • \n\t
    • The 3rd place athlete's rank is "Bronze Medal".
    • \n\t
    • For the 4th place to the nth place athlete, their rank is their placement number (i.e., the xth place athlete's rank is "x").
    • \n
    \n\n

    Return an array answer of size n where answer[i] is the rank of the ith athlete.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: score = [5,4,3,2,1]\nOutput: ["Gold Medal","Silver Medal","Bronze Medal","4","5"]\nExplanation: The placements are [1st, 2nd, 3rd, 4th, 5th].
    \n\n

    Example 2:

    \n\n
    \nInput: score = [10,3,8,9,4]\nOutput: ["Gold Medal","5","Bronze Medal","Silver Medal","4"]\nExplanation: The placements are [1st, 5th, 3rd, 2nd, 4th].\n\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == score.length
    • \n\t
    • 1 <= n <= 104
    • \n\t
    • 0 <= score[i] <= 106
    • \n\t
    • All the values in score are unique.
    • \n
    \n", "content_cn": "

    \u7ed9\u51fa N \u540d\u8fd0\u52a8\u5458\u7684\u6210\u7ee9\uff0c\u627e\u51fa\u4ed6\u4eec\u7684\u76f8\u5bf9\u540d\u6b21\u5e76\u6388\u4e88\u524d\u4e09\u540d\u5bf9\u5e94\u7684\u5956\u724c\u3002\u524d\u4e09\u540d\u8fd0\u52a8\u5458\u5c06\u4f1a\u88ab\u5206\u522b\u6388\u4e88 “\u91d1\u724c”\uff0c“\u94f6\u724c” \u548c“ \u94dc\u724c”\uff08"Gold Medal", "Silver Medal", "Bronze Medal"\uff09\u3002

    \n\n

    (\u6ce8\uff1a\u5206\u6570\u8d8a\u9ad8\u7684\u9009\u624b\uff0c\u6392\u540d\u8d8a\u9760\u524d\u3002)

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: [5, 4, 3, 2, 1]\n\u8f93\u51fa: ["Gold Medal", "Silver Medal", "Bronze Medal", "4", "5"]\n\u89e3\u91ca: \u524d\u4e09\u540d\u8fd0\u52a8\u5458\u7684\u6210\u7ee9\u4e3a\u524d\u4e09\u9ad8\u7684\uff0c\u56e0\u6b64\u5c06\u4f1a\u5206\u522b\u88ab\u6388\u4e88 “\u91d1\u724c”\uff0c“\u94f6\u724c”\u548c“\u94dc\u724c” ("Gold Medal", "Silver Medal" and "Bronze Medal").\n\u4f59\u4e0b\u7684\u4e24\u540d\u8fd0\u52a8\u5458\uff0c\u6211\u4eec\u53ea\u9700\u8981\u901a\u8fc7\u4ed6\u4eec\u7684\u6210\u7ee9\u8ba1\u7b97\u5c06\u5176\u76f8\u5bf9\u540d\u6b21\u5373\u53ef\u3002
    \n\n

    \u63d0\u793a:

    \n\n
      \n\t
    1. N \u662f\u4e00\u4e2a\u6b63\u6574\u6570\u5e76\u4e14\u4e0d\u4f1a\u8d85\u8fc7 10000\u3002
    2. \n\t
    3. \u6240\u6709\u8fd0\u52a8\u5458\u7684\u6210\u7ee9\u90fd\u4e0d\u76f8\u540c\u3002
    4. \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findRelativeRanks(vector& score) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String[] findRelativeRanks(int[] score) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findRelativeRanks(self, score):\n \"\"\"\n :type score: List[int]\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findRelativeRanks(self, score: List[int]) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** findRelativeRanks(int* score, int scoreSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string[] FindRelativeRanks(int[] score) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} score\n * @return {string[]}\n */\nvar findRelativeRanks = function(score) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} score\n# @return {String[]}\ndef find_relative_ranks(score)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findRelativeRanks(_ score: [Int]) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findRelativeRanks(score []int) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findRelativeRanks(score: Array[Int]): Array[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findRelativeRanks(score: IntArray): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_relative_ranks(score: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $score\n * @return String[]\n */\n function findRelativeRanks($score) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findRelativeRanks(score: number[]): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-relative-ranks score)\n (-> (listof exact-integer?) (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0506](https://leetcode-cn.com/problems/relative-ranks)", "[\u76f8\u5bf9\u540d\u6b21](/solution/0500-0599/0506.Relative%20Ranks/README.md)", "", "\u7b80\u5355", ""], "md_table_row_en": ["[0506](https://leetcode.com/problems/relative-ranks)", "[Relative Ranks](/solution/0500-0599/0506.Relative%20Ranks/README_EN.md)", "", "Easy", ""]}, {"question_id": "0505", "frontend_question_id": "0505", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/the-maze-ii", "url_en": "https://leetcode.com/problems/the-maze-ii", "relative_path_cn": "/solution/0500-0599/0505.The%20Maze%20II/README.md", "relative_path_en": "/solution/0500-0599/0505.The%20Maze%20II/README_EN.md", "title_cn": "\u8ff7\u5bab II", "title_en": "The Maze II", "question_title_slug": "the-maze-ii", "content_en": "

    There is a ball in a maze with empty spaces (represented as 0) and walls (represented as 1). The ball can go through the empty spaces by rolling up, down, left or right, but it won't stop rolling until hitting a wall. When the ball stops, it could choose the next direction.

    \n\n

    Given the m x n maze, the ball's start position and the destination, where start = [startrow, startcol] and destination = [destinationrow, destinationcol], return the shortest distance for the ball to stop at the destination. If the ball cannot stop at destination, return -1.

    \n\n

    The distance is the number of empty spaces traveled by the ball from the start position (excluded) to the destination (included).

    \n\n

    You may assume that the borders of the maze are all walls (see examples).

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: maze = [[0,0,1,0,0],[0,0,0,0,0],[0,0,0,1,0],[1,1,0,1,1],[0,0,0,0,0]], start = [0,4], destination = [4,4]\nOutput: 12\nExplanation: One possible way is : left -> down -> left -> down -> right -> down -> right.\nThe length of the path is 1 + 1 + 3 + 1 + 2 + 2 + 2 = 12.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: maze = [[0,0,1,0,0],[0,0,0,0,0],[0,0,0,1,0],[1,1,0,1,1],[0,0,0,0,0]], start = [0,4], destination = [3,2]\nOutput: -1\nExplanation: There is no way for the ball to stop at the destination. Notice that you can pass through the destination but you cannot stop there.\n
    \n\n

    Example 3:

    \n\n
    \nInput: maze = [[0,0,0,0,0],[1,1,0,0,1],[0,0,0,0,0],[0,1,0,0,1],[0,1,0,0,0]], start = [4,3], destination = [0,1]\nOutput: -1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == maze.length
    • \n\t
    • n == maze[i].length
    • \n\t
    • 1 <= m, n <= 100
    • \n\t
    • maze[i][j] is 0 or 1.
    • \n\t
    • start.length == 2
    • \n\t
    • destination.length == 2
    • \n\t
    • 0 <= startrow, destinationrow <= m
    • \n\t
    • 0 <= startcol, destinationcol <= n
    • \n\t
    • Both the ball and the destination exist in an empty space, and they will not be in the same position initially.
    • \n\t
    • The maze contains at least 2 empty spaces.
    • \n
    \n", "content_cn": "

    \u7531\u7a7a\u5730\u548c\u5899\u7ec4\u6210\u7684\u8ff7\u5bab\u4e2d\u6709\u4e00\u4e2a\u7403\u3002\u7403\u53ef\u4ee5\u5411\u4e0a\u4e0b\u5de6\u53f3\u56db\u4e2a\u65b9\u5411\u6eda\u52a8\uff0c\u4f46\u5728\u9047\u5230\u5899\u58c1\u524d\u4e0d\u4f1a\u505c\u6b62\u6eda\u52a8\u3002\u5f53\u7403\u505c\u4e0b\u65f6\uff0c\u53ef\u4ee5\u9009\u62e9\u4e0b\u4e00\u4e2a\u65b9\u5411\u3002

    \n\n

    \u7ed9\u5b9a\u7403\u7684\u8d77\u59cb\u4f4d\u7f6e\uff0c\u76ee\u7684\u5730\u548c\u8ff7\u5bab\uff0c\u627e\u51fa\u8ba9\u7403\u505c\u5728\u76ee\u7684\u5730\u7684\u6700\u77ed\u8ddd\u79bb\u3002\u8ddd\u79bb\u7684\u5b9a\u4e49\u662f\u7403\u4ece\u8d77\u59cb\u4f4d\u7f6e\uff08\u4e0d\u5305\u62ec\uff09\u5230\u76ee\u7684\u5730\uff08\u5305\u62ec\uff09\u7ecf\u8fc7\u7684\u7a7a\u5730\u4e2a\u6570\u3002\u5982\u679c\u7403\u65e0\u6cd5\u505c\u5728\u76ee\u7684\u5730\uff0c\u8fd4\u56de -1\u3002

    \n\n

    \u8ff7\u5bab\u7531\u4e00\u4e2a0\u548c1\u7684\u4e8c\u7ef4\u6570\u7ec4\u8868\u793a\u3002 1\u8868\u793a\u5899\u58c1\uff0c0\u8868\u793a\u7a7a\u5730\u3002\u4f60\u53ef\u4ee5\u5047\u5b9a\u8ff7\u5bab\u7684\u8fb9\u7f18\u90fd\u662f\u5899\u58c1\u3002\u8d77\u59cb\u4f4d\u7f6e\u548c\u76ee\u7684\u5730\u7684\u5750\u6807\u901a\u8fc7\u884c\u53f7\u548c\u5217\u53f7\u7ed9\u51fa\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165 1: \u8ff7\u5bab\u7531\u4ee5\u4e0b\u4e8c\u7ef4\u6570\u7ec4\u8868\u793a\n\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 1 0\n1 1 0 1 1\n0 0 0 0 0\n\n\u8f93\u5165 2: \u8d77\u59cb\u4f4d\u7f6e\u5750\u6807 (rowStart, colStart) = (0, 4)\n\u8f93\u5165 3: \u76ee\u7684\u5730\u5750\u6807 (rowDest, colDest) = (4, 4)\n\n\u8f93\u51fa: 12\n\n\u89e3\u6790: \u4e00\u6761\u6700\u77ed\u8def\u5f84 : left -> down -> left -> down -> right -> down -> right\u3002\n             \u603b\u8ddd\u79bb\u4e3a 1 + 1 + 3 + 1 + 2 + 2 + 2 = 12\u3002\n\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165 1: \u8ff7\u5bab\u7531\u4ee5\u4e0b\u4e8c\u7ef4\u6570\u7ec4\u8868\u793a\n\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 1 0\n1 1 0 1 1\n0 0 0 0 0\n\n\u8f93\u5165 2: \u8d77\u59cb\u4f4d\u7f6e\u5750\u6807 (rowStart, colStart) = (0, 4)\n\u8f93\u5165 3: \u76ee\u7684\u5730\u5750\u6807 (rowDest, colDest) = (3, 2)\n\n\u8f93\u51fa: -1\n\n\u89e3\u6790: \u6ca1\u6709\u80fd\u591f\u4f7f\u7403\u505c\u5728\u76ee\u7684\u5730\u7684\u8def\u5f84\u3002\n\n
    \n\n

     

    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u8ff7\u5bab\u4e2d\u53ea\u6709\u4e00\u4e2a\u7403\u548c\u4e00\u4e2a\u76ee\u7684\u5730\u3002
    2. \n\t
    3. \u7403\u548c\u76ee\u7684\u5730\u90fd\u5728\u7a7a\u5730\u4e0a\uff0c\u4e14\u521d\u59cb\u65f6\u5b83\u4eec\u4e0d\u5728\u540c\u4e00\u4f4d\u7f6e\u3002
    4. \n\t
    5. \u7ed9\u5b9a\u7684\u8ff7\u5bab\u4e0d\u5305\u62ec\u8fb9\u754c (\u5982\u56fe\u4e2d\u7684\u7ea2\u8272\u77e9\u5f62), \u4f46\u4f60\u53ef\u4ee5\u5047\u8bbe\u8ff7\u5bab\u7684\u8fb9\u7f18\u90fd\u662f\u5899\u58c1\u3002
    6. \n\t
    7. \u8ff7\u5bab\u81f3\u5c11\u5305\u62ec2\u5757\u7a7a\u5730\uff0c\u884c\u6570\u548c\u5217\u6570\u5747\u4e0d\u8d85\u8fc7100\u3002
    8. \n
    \n", "tags_en": ["Depth-first Search", "Breadth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int shortestDistance(vector>& maze, vector& start, vector& destination) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int shortestDistance(int[][] maze, int[] start, int[] destination) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def shortestDistance(self, maze, start, destination):\n \"\"\"\n :type maze: List[List[int]]\n :type start: List[int]\n :type destination: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def shortestDistance(self, maze: List[List[int]], start: List[int], destination: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint shortestDistance(int** maze, int mazeSize, int* mazeColSize, int* start, int startSize, int* destination, int destinationSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ShortestDistance(int[][] maze, int[] start, int[] destination) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} maze\n * @param {number[]} start\n * @param {number[]} destination\n * @return {number}\n */\nvar shortestDistance = function(maze, start, destination) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} maze\n# @param {Integer[]} start\n# @param {Integer[]} destination\n# @return {Integer}\ndef shortest_distance(maze, start, destination)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func shortestDistance(_ maze: [[Int]], _ start: [Int], _ destination: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func shortestDistance(maze [][]int, start []int, destination []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def shortestDistance(maze: Array[Array[Int]], start: Array[Int], destination: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun shortestDistance(maze: Array, start: IntArray, destination: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn shortest_distance(maze: Vec>, start: Vec, destination: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $maze\n * @param Integer[] $start\n * @param Integer[] $destination\n * @return Integer\n */\n function shortestDistance($maze, $start, $destination) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function shortestDistance(maze: number[][], start: number[], destination: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (shortest-distance maze start destination)\n (-> (listof (listof exact-integer?)) (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0505](https://leetcode-cn.com/problems/the-maze-ii)", "[\u8ff7\u5bab II](/solution/0500-0599/0505.The%20Maze%20II/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0505](https://leetcode.com/problems/the-maze-ii)", "[The Maze II](/solution/0500-0599/0505.The%20Maze%20II/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`", "Medium", "\ud83d\udd12"]}, {"question_id": "0504", "frontend_question_id": "0504", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/base-7", "url_en": "https://leetcode.com/problems/base-7", "relative_path_cn": "/solution/0500-0599/0504.Base%207/README.md", "relative_path_en": "/solution/0500-0599/0504.Base%207/README_EN.md", "title_cn": "\u4e03\u8fdb\u5236\u6570", "title_en": "Base 7", "question_title_slug": "base-7", "content_en": "

    Given an integer num, return a string of its base 7 representation.

    \n\n

     

    \n

    Example 1:

    \n
    Input: num = 100\nOutput: \"202\"\n

    Example 2:

    \n
    Input: num = -7\nOutput: \"-10\"\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • -107 <= num <= 107
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\uff0c\u5c06\u5176\u8f6c\u5316\u4e3a7\u8fdb\u5236\uff0c\u5e76\u4ee5\u5b57\u7b26\u4e32\u5f62\u5f0f\u8f93\u51fa\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: 100\n\u8f93\u51fa: "202"\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: -7\n\u8f93\u51fa: "-10"\n
    \n\n

    \u6ce8\u610f: \u8f93\u5165\u8303\u56f4\u662f [-1e7, 1e7] \u3002

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string convertToBase7(int num) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String convertToBase7(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def convertToBase7(self, num):\n \"\"\"\n :type num: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def convertToBase7(self, num: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * convertToBase7(int num){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ConvertToBase7(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} num\n * @return {string}\n */\nvar convertToBase7 = function(num) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} num\n# @return {String}\ndef convert_to_base7(num)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func convertToBase7(_ num: Int) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func convertToBase7(num int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def convertToBase7(num: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun convertToBase7(num: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn convert_to_base7(num: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $num\n * @return String\n */\n function convertToBase7($num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function convertToBase7(num: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (convert-to-base7 num)\n (-> exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0504](https://leetcode-cn.com/problems/base-7)", "[\u4e03\u8fdb\u5236\u6570](/solution/0500-0599/0504.Base%207/README.md)", "", "\u7b80\u5355", ""], "md_table_row_en": ["[0504](https://leetcode.com/problems/base-7)", "[Base 7](/solution/0500-0599/0504.Base%207/README_EN.md)", "", "Easy", ""]}, {"question_id": "0503", "frontend_question_id": "0503", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/next-greater-element-ii", "url_en": "https://leetcode.com/problems/next-greater-element-ii", "relative_path_cn": "/solution/0500-0599/0503.Next%20Greater%20Element%20II/README.md", "relative_path_en": "/solution/0500-0599/0503.Next%20Greater%20Element%20II/README_EN.md", "title_cn": "\u4e0b\u4e00\u4e2a\u66f4\u5927\u5143\u7d20 II", "title_en": "Next Greater Element II", "question_title_slug": "next-greater-element-ii", "content_en": "

    Given a circular integer array nums (i.e., the next element of nums[nums.length - 1] is nums[0]), return the next greater number for every element in nums.

    \n\n

    The next greater number of a number x is the first greater number to its traversing-order next in the array, which means you could search circularly to find its next greater number. If it doesn't exist, return -1 for this number.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,1]\nOutput: [2,-1,2]\nExplanation: The first 1's next greater number is 2; \nThe number 2 can't find next greater number. \nThe second 1's next greater number needs to search circularly, which is also 2.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,2,3,4,3]\nOutput: [2,3,4,-1,4]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 104
    • \n\t
    • -109 <= nums[i] <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5faa\u73af\u6570\u7ec4\uff08\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u7684\u4e0b\u4e00\u4e2a\u5143\u7d20\u662f\u6570\u7ec4\u7684\u7b2c\u4e00\u4e2a\u5143\u7d20\uff09\uff0c\u8f93\u51fa\u6bcf\u4e2a\u5143\u7d20\u7684\u4e0b\u4e00\u4e2a\u66f4\u5927\u5143\u7d20\u3002\u6570\u5b57 x \u7684\u4e0b\u4e00\u4e2a\u66f4\u5927\u7684\u5143\u7d20\u662f\u6309\u6570\u7ec4\u904d\u5386\u987a\u5e8f\uff0c\u8fd9\u4e2a\u6570\u5b57\u4e4b\u540e\u7684\u7b2c\u4e00\u4e2a\u6bd4\u5b83\u66f4\u5927\u7684\u6570\uff0c\u8fd9\u610f\u5473\u7740\u4f60\u5e94\u8be5\u5faa\u73af\u5730\u641c\u7d22\u5b83\u7684\u4e0b\u4e00\u4e2a\u66f4\u5927\u7684\u6570\u3002\u5982\u679c\u4e0d\u5b58\u5728\uff0c\u5219\u8f93\u51fa -1\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: [1,2,1]\n\u8f93\u51fa: [2,-1,2]\n\u89e3\u91ca: \u7b2c\u4e00\u4e2a 1 \u7684\u4e0b\u4e00\u4e2a\u66f4\u5927\u7684\u6570\u662f 2\uff1b\n\u6570\u5b57 2 \u627e\u4e0d\u5230\u4e0b\u4e00\u4e2a\u66f4\u5927\u7684\u6570\uff1b \n\u7b2c\u4e8c\u4e2a 1 \u7684\u4e0b\u4e00\u4e2a\u6700\u5927\u7684\u6570\u9700\u8981\u5faa\u73af\u641c\u7d22\uff0c\u7ed3\u679c\u4e5f\u662f 2\u3002\n
    \n\n

    \u6ce8\u610f: \u8f93\u5165\u6570\u7ec4\u7684\u957f\u5ea6\u4e0d\u4f1a\u8d85\u8fc7 10000\u3002

    \n", "tags_en": ["Stack"], "tags_cn": ["\u6808"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector nextGreaterElements(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] nextGreaterElements(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def nextGreaterElements(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def nextGreaterElements(self, nums: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* nextGreaterElements(int* nums, int numsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] NextGreaterElements(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar nextGreaterElements = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer[]}\ndef next_greater_elements(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func nextGreaterElements(_ nums: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func nextGreaterElements(nums []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def nextGreaterElements(nums: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun nextGreaterElements(nums: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn next_greater_elements(nums: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer[]\n */\n function nextGreaterElements($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function nextGreaterElements(nums: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (next-greater-elements nums)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0503](https://leetcode-cn.com/problems/next-greater-element-ii)", "[\u4e0b\u4e00\u4e2a\u66f4\u5927\u5143\u7d20 II](/solution/0500-0599/0503.Next%20Greater%20Element%20II/README.md)", "`\u6808`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0503](https://leetcode.com/problems/next-greater-element-ii)", "[Next Greater Element II](/solution/0500-0599/0503.Next%20Greater%20Element%20II/README_EN.md)", "`Stack`", "Medium", ""]}, {"question_id": "0502", "frontend_question_id": "0502", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/ipo", "url_en": "https://leetcode.com/problems/ipo", "relative_path_cn": "/solution/0500-0599/0502.IPO/README.md", "relative_path_en": "/solution/0500-0599/0502.IPO/README_EN.md", "title_cn": "IPO", "title_en": "IPO", "question_title_slug": "ipo", "content_en": "

    Suppose LeetCode will start its IPO soon. In order to sell a good price of its shares to Venture Capital, LeetCode would like to work on some projects to increase its capital before the IPO. Since it has limited resources, it can only finish at most k distinct projects before the IPO. Help LeetCode design the best way to maximize its total capital after finishing at most k distinct projects.

    \n\n

    You are given n projects where the ith project has a pure profit profits[i] and a minimum capital of capital[i] is needed to start it.

    \n\n

    Initially, you have w capital. When you finish a project, you will obtain its pure profit and the profit will be added to your total capital.

    \n\n

    Pick a list of at most k distinct projects from given projects to maximize your final capital, and return the final maximized capital.

    \n\n

    The answer is guaranteed to fit in a 32-bit signed integer.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: k = 2, w = 0, profits = [1,2,3], capital = [0,1,1]\nOutput: 4\nExplanation: Since your initial capital is 0, you can only start the project indexed 0.\nAfter finishing it you will obtain profit 1 and your capital becomes 1.\nWith capital 1, you can either start the project indexed 1 or the project indexed 2.\nSince you can choose at most 2 projects, you need to finish the project indexed 2 to get the maximum capital.\nTherefore, output the final maximized capital, which is 0 + 1 + 3 = 4.\n
    \n\n

    Example 2:

    \n\n
    \nInput: k = 3, w = 0, profits = [1,2,3], capital = [0,1,2]\nOutput: 6\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= k <= 105
    • \n\t
    • 0 <= w <= 109
    • \n\t
    • n == profits.length
    • \n\t
    • n == capital.length
    • \n\t
    • 1 <= n <= 105
    • \n\t
    • 0 <= profits[i] <= 104
    • \n\t
    • 0 <= capital[i] <= 109
    • \n
    \n", "content_cn": "

    \u5047\u8bbe \u529b\u6263\uff08LeetCode\uff09\u5373\u5c06\u5f00\u59cb\u5176 IPO\u3002\u4e3a\u4e86\u4ee5\u66f4\u9ad8\u7684\u4ef7\u683c\u5c06\u80a1\u7968\u5356\u7ed9\u98ce\u9669\u6295\u8d44\u516c\u53f8\uff0c\u529b\u6263 \u5e0c\u671b\u5728 IPO \u4e4b\u524d\u5f00\u5c55\u4e00\u4e9b\u9879\u76ee\u4ee5\u589e\u52a0\u5176\u8d44\u672c\u3002 \u7531\u4e8e\u8d44\u6e90\u6709\u9650\uff0c\u5b83\u53ea\u80fd\u5728 IPO \u4e4b\u524d\u5b8c\u6210\u6700\u591a k \u4e2a\u4e0d\u540c\u7684\u9879\u76ee\u3002\u5e2e\u52a9 \u529b\u6263 \u8bbe\u8ba1\u5b8c\u6210\u6700\u591a k \u4e2a\u4e0d\u540c\u9879\u76ee\u540e\u5f97\u5230\u6700\u5927\u603b\u8d44\u672c\u7684\u65b9\u5f0f\u3002

    \n\n

    \u7ed9\u5b9a\u82e5\u5e72\u4e2a\u9879\u76ee\u3002\u5bf9\u4e8e\u6bcf\u4e2a\u9879\u76ee i\uff0c\u5b83\u90fd\u6709\u4e00\u4e2a\u7eaf\u5229\u6da6 Pi\uff0c\u5e76\u4e14\u9700\u8981\u6700\u5c0f\u7684\u8d44\u672c Ci \u6765\u542f\u52a8\u76f8\u5e94\u7684\u9879\u76ee\u3002\u6700\u521d\uff0c\u4f60\u6709 W \u8d44\u672c\u3002\u5f53\u4f60\u5b8c\u6210\u4e00\u4e2a\u9879\u76ee\u65f6\uff0c\u4f60\u5c06\u83b7\u5f97\u7eaf\u5229\u6da6\uff0c\u4e14\u5229\u6da6\u5c06\u88ab\u6dfb\u52a0\u5230\u4f60\u7684\u603b\u8d44\u672c\u4e2d\u3002

    \n\n

    \u603b\u800c\u8a00\u4e4b\uff0c\u4ece\u7ed9\u5b9a\u9879\u76ee\u4e2d\u9009\u62e9\u6700\u591a k \u4e2a\u4e0d\u540c\u9879\u76ee\u7684\u5217\u8868\uff0c\u4ee5\u6700\u5927\u5316\u6700\u7ec8\u8d44\u672c\uff0c\u5e76\u8f93\u51fa\u6700\u7ec8\u53ef\u83b7\u5f97\u7684\u6700\u591a\u8d44\u672c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1ak=2, W=0, Profits=[1,2,3], Capital=[0,1,1].\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\n\u7531\u4e8e\u4f60\u7684\u521d\u59cb\u8d44\u672c\u4e3a 0\uff0c\u4f60\u4ec5\u53ef\u4ee5\u4ece 0 \u53f7\u9879\u76ee\u5f00\u59cb\u3002\n\u5728\u5b8c\u6210\u540e\uff0c\u4f60\u5c06\u83b7\u5f97 1 \u7684\u5229\u6da6\uff0c\u4f60\u7684\u603b\u8d44\u672c\u5c06\u53d8\u4e3a 1\u3002\n\u6b64\u65f6\u4f60\u53ef\u4ee5\u9009\u62e9\u5f00\u59cb 1 \u53f7\u6216 2 \u53f7\u9879\u76ee\u3002\n\u7531\u4e8e\u4f60\u6700\u591a\u53ef\u4ee5\u9009\u62e9\u4e24\u4e2a\u9879\u76ee\uff0c\u6240\u4ee5\u4f60\u9700\u8981\u5b8c\u6210 2 \u53f7\u9879\u76ee\u4ee5\u83b7\u5f97\u6700\u5927\u7684\u8d44\u672c\u3002\n\u56e0\u6b64\uff0c\u8f93\u51fa\u6700\u540e\u6700\u5927\u5316\u7684\u8d44\u672c\uff0c\u4e3a 0 + 1 + 3 = 4\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u5047\u8bbe\u6240\u6709\u8f93\u5165\u6570\u5b57\u90fd\u662f\u975e\u8d1f\u6574\u6570\u3002
    • \n\t
    • \u8868\u793a\u5229\u6da6\u548c\u8d44\u672c\u7684\u6570\u7ec4\u7684\u957f\u5ea6\u4e0d\u8d85\u8fc7 50000\u3002
    • \n\t
    • \u7b54\u6848\u4fdd\u8bc1\u5728 32 \u4f4d\u6709\u7b26\u53f7\u6574\u6570\u8303\u56f4\u5185\u3002
    • \n
    \n", "tags_en": ["Heap", "Greedy"], "tags_cn": ["\u5806", "\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findMaximizedCapital(int k, int w, vector& profits, vector& capital) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findMaximizedCapital(int k, int w, int[] profits, int[] capital) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findMaximizedCapital(self, k, w, profits, capital):\n \"\"\"\n :type k: int\n :type w: int\n :type profits: List[int]\n :type capital: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findMaximizedCapital(self, k: int, w: int, profits: List[int], capital: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findMaximizedCapital(int k, int w, int* profits, int profitsSize, int* capital, int capitalSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindMaximizedCapital(int k, int w, int[] profits, int[] capital) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} k\n * @param {number} w\n * @param {number[]} profits\n * @param {number[]} capital\n * @return {number}\n */\nvar findMaximizedCapital = function(k, w, profits, capital) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} k\n# @param {Integer} w\n# @param {Integer[]} profits\n# @param {Integer[]} capital\n# @return {Integer}\ndef find_maximized_capital(k, w, profits, capital)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findMaximizedCapital(_ k: Int, _ w: Int, _ profits: [Int], _ capital: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findMaximizedCapital(k int, w int, profits []int, capital []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findMaximizedCapital(k: Int, w: Int, profits: Array[Int], capital: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findMaximizedCapital(k: Int, w: Int, profits: IntArray, capital: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_maximized_capital(k: i32, w: i32, profits: Vec, capital: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $k\n * @param Integer $w\n * @param Integer[] $profits\n * @param Integer[] $capital\n * @return Integer\n */\n function findMaximizedCapital($k, $w, $profits, $capital) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findMaximizedCapital(k: number, w: number, profits: number[], capital: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-maximized-capital k w profits capital)\n (-> exact-integer? exact-integer? (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0502](https://leetcode-cn.com/problems/ipo)", "[IPO](/solution/0500-0599/0502.IPO/README.md)", "`\u5806`,`\u8d2a\u5fc3\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[0502](https://leetcode.com/problems/ipo)", "[IPO](/solution/0500-0599/0502.IPO/README_EN.md)", "`Heap`,`Greedy`", "Hard", ""]}, {"question_id": "0501", "frontend_question_id": "0501", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-mode-in-binary-search-tree", "url_en": "https://leetcode.com/problems/find-mode-in-binary-search-tree", "relative_path_cn": "/solution/0500-0599/0501.Find%20Mode%20in%20Binary%20Search%20Tree/README.md", "relative_path_en": "/solution/0500-0599/0501.Find%20Mode%20in%20Binary%20Search%20Tree/README_EN.md", "title_cn": "\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u7684\u4f17\u6570", "title_en": "Find Mode in Binary Search Tree", "question_title_slug": "find-mode-in-binary-search-tree", "content_en": "

    Given the root of a binary search tree (BST) with duplicates, return all the mode(s) (i.e., the most frequently occurred element) in it.

    \n\n

    If the tree has more than one mode, return them in any order.

    \n\n

    Assume a BST is defined as follows:

    \n\n
      \n\t
    • The left subtree of a node contains only nodes with keys less than or equal to the node's key.
    • \n\t
    • The right subtree of a node contains only nodes with keys greater than or equal to the node's key.
    • \n\t
    • Both the left and right subtrees must also be binary search trees.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,null,2,2]\nOutput: [2]\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = [0]\nOutput: [0]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 104].
    • \n\t
    • -105 <= Node.val <= 105
    • \n
    \n\n

     

    \nFollow up: Could you do that without using any extra space? (Assume that the implicit stack space incurred due to recursion does not count).", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6709\u76f8\u540c\u503c\u7684\u4e8c\u53c9\u641c\u7d22\u6811\uff08BST\uff09\uff0c\u627e\u51fa BST \u4e2d\u7684\u6240\u6709\u4f17\u6570\uff08\u51fa\u73b0\u9891\u7387\u6700\u9ad8\u7684\u5143\u7d20\uff09\u3002

    \n\n

    \u5047\u5b9a BST \u6709\u5982\u4e0b\u5b9a\u4e49\uff1a

    \n\n
      \n\t
    • \u7ed3\u70b9\u5de6\u5b50\u6811\u4e2d\u6240\u542b\u7ed3\u70b9\u7684\u503c\u5c0f\u4e8e\u7b49\u4e8e\u5f53\u524d\u7ed3\u70b9\u7684\u503c
    • \n\t
    • \u7ed3\u70b9\u53f3\u5b50\u6811\u4e2d\u6240\u542b\u7ed3\u70b9\u7684\u503c\u5927\u4e8e\u7b49\u4e8e\u5f53\u524d\u7ed3\u70b9\u7684\u503c
    • \n\t
    • \u5de6\u5b50\u6811\u548c\u53f3\u5b50\u6811\u90fd\u662f\u4e8c\u53c9\u641c\u7d22\u6811
    • \n
    \n\n

    \u4f8b\u5982\uff1a
    \n\u7ed9\u5b9a BST [1,null,2,2],

    \n\n
       1\n    \\\n     2\n    /\n   2\n
    \n\n

    \u8fd4\u56de[2].

    \n\n

    \u63d0\u793a\uff1a\u5982\u679c\u4f17\u6570\u8d85\u8fc71\u4e2a\uff0c\u4e0d\u9700\u8003\u8651\u8f93\u51fa\u987a\u5e8f

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u53ef\u4ee5\u4e0d\u4f7f\u7528\u989d\u5916\u7684\u7a7a\u95f4\u5417\uff1f\uff08\u5047\u8bbe\u7531\u9012\u5f52\u4ea7\u751f\u7684\u9690\u5f0f\u8c03\u7528\u6808\u7684\u5f00\u9500\u4e0d\u88ab\u8ba1\u7b97\u5728\u5185\uff09

    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector findMode(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int[] findMode(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def findMode(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def findMode(self, root: TreeNode) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* findMode(struct TreeNode* root, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int[] FindMode(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number[]}\n */\nvar findMode = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer[]}\ndef find_mode(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func findMode(_ root: TreeNode?) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc findMode(root *TreeNode) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def findMode(root: TreeNode): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun findMode(root: TreeNode?): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn find_mode(root: Option>>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer[]\n */\n function findMode($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction findMode(root: TreeNode | null): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (find-mode root)\n (-> (or/c tree-node? #f) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0501](https://leetcode-cn.com/problems/find-mode-in-binary-search-tree)", "[\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u7684\u4f17\u6570](/solution/0500-0599/0501.Find%20Mode%20in%20Binary%20Search%20Tree/README.md)", "`\u6811`", "\u7b80\u5355", ""], "md_table_row_en": ["[0501](https://leetcode.com/problems/find-mode-in-binary-search-tree)", "[Find Mode in Binary Search Tree](/solution/0500-0599/0501.Find%20Mode%20in%20Binary%20Search%20Tree/README_EN.md)", "`Tree`", "Easy", ""]}, {"question_id": "0500", "frontend_question_id": "0500", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/keyboard-row", "url_en": "https://leetcode.com/problems/keyboard-row", "relative_path_cn": "/solution/0500-0599/0500.Keyboard%20Row/README.md", "relative_path_en": "/solution/0500-0599/0500.Keyboard%20Row/README_EN.md", "title_cn": "\u952e\u76d8\u884c", "title_en": "Keyboard Row", "question_title_slug": "keyboard-row", "content_en": "

    Given an array of strings words, return the words that can be typed using letters of the alphabet on only one row of American keyboard like the image below.

    \n\n

    In the American keyboard:

    \n\n
      \n\t
    • the first row consists of the characters "qwertyuiop",
    • \n\t
    • the second row consists of the characters "asdfghjkl", and
    • \n\t
    • the third row consists of the characters "zxcvbnm".
    • \n
    \n\"\"\n

     

    \n

    Example 1:

    \n\n
    \nInput: words = ["Hello","Alaska","Dad","Peace"]\nOutput: ["Alaska","Dad"]\n
    \n\n

    Example 2:

    \n\n
    \nInput: words = ["omk"]\nOutput: []\n
    \n\n

    Example 3:

    \n\n
    \nInput: words = ["adsdf","sfd"]\nOutput: ["adsdf","sfd"]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= words.length <= 20
    • \n\t
    • 1 <= words[i].length <= 100
    • \n\t
    • words[i] consists of English letters (both lowercase and uppercase). 
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4 words \uff0c\u53ea\u8fd4\u56de\u53ef\u4ee5\u4f7f\u7528\u5728 \u7f8e\u5f0f\u952e\u76d8 \u540c\u4e00\u884c\u7684\u5b57\u6bcd\u6253\u5370\u51fa\u6765\u7684\u5355\u8bcd\u3002\u952e\u76d8\u5982\u4e0b\u56fe\u6240\u793a\u3002

    \n\n

    \u7f8e\u5f0f\u952e\u76d8 \u4e2d\uff1a

    \n\n
      \n\t
    • \u7b2c\u4e00\u884c\u7531\u5b57\u7b26 \"qwertyuiop\" \u7ec4\u6210\u3002
    • \n\t
    • \u7b2c\u4e8c\u884c\u7531\u5b57\u7b26 \"asdfghjkl\" \u7ec4\u6210\u3002
    • \n\t
    • \u7b2c\u4e09\u884c\u7531\u5b57\u7b26 \"zxcvbnm\" \u7ec4\u6210\u3002
    • \n
    \n\n

    \"American

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1awords = [\"Hello\",\"Alaska\",\"Dad\",\"Peace\"]\n\u8f93\u51fa\uff1a[\"Alaska\",\"Dad\"]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1awords = [\"omk\"]\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1awords = [\"adsdf\",\"sfd\"]\n\u8f93\u51fa\uff1a[\"adsdf\",\"sfd\"]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= words.length <= 20
    • \n\t
    • 1 <= words[i].length <= 100
    • \n\t
    • words[i] \u7531\u82f1\u6587\u5b57\u6bcd\uff08\u5c0f\u5199\u548c\u5927\u5199\u5b57\u6bcd\uff09\u7ec4\u6210
    • \n
    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findWords(vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String[] findWords(String[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findWords(self, words):\n \"\"\"\n :type words: List[str]\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findWords(self, words: List[str]) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** findWords(char ** words, int wordsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string[] FindWords(string[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @return {string[]}\n */\nvar findWords = function(words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @return {String[]}\ndef find_words(words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findWords(_ words: [String]) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findWords(words []string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findWords(words: Array[String]): Array[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findWords(words: Array): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_words(words: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @return String[]\n */\n function findWords($words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findWords(words: string[]): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-words words)\n (-> (listof string?) (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0500](https://leetcode-cn.com/problems/keyboard-row)", "[\u952e\u76d8\u884c](/solution/0500-0599/0500.Keyboard%20Row/README.md)", "`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0500](https://leetcode.com/problems/keyboard-row)", "[Keyboard Row](/solution/0500-0599/0500.Keyboard%20Row/README_EN.md)", "`Hash Table`", "Easy", ""]}, {"question_id": "0499", "frontend_question_id": "0499", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/the-maze-iii", "url_en": "https://leetcode.com/problems/the-maze-iii", "relative_path_cn": "/solution/0400-0499/0499.The%20Maze%20III/README.md", "relative_path_en": "/solution/0400-0499/0499.The%20Maze%20III/README_EN.md", "title_cn": "\u8ff7\u5bab III", "title_en": "The Maze III", "question_title_slug": "the-maze-iii", "content_en": "

    There is a ball in a maze with empty spaces (represented as 0) and walls (represented as 1). The ball can go through the empty spaces by rolling up, down, left or right, but it won't stop rolling until hitting a wall. When the ball stops, it could choose the next direction. There is also a hole in this maze. The ball will drop into the hole if it rolls onto the hole.

    \n\n

    Given the m x n maze, the ball's position ball and the hole's position hole, where ball = [ballrow, ballcol] and hole = [holerow, holecol], return a string instructions of all the instructions that the ball should follow to drop in the hole with the shortest distance possible. If there are multiple valid instructions, return the lexicographically minimum one. If the ball can't drop in the hole, return "impossible".

    \n\n

    If there is a way for the ball to drop in the hole, the answer instructions should contain the characters 'u' (i.e., up), 'd' (i.e., down), 'l' (i.e., left), and 'r' (i.e., right).

    \n\n

    The distance is the number of empty spaces traveled by the ball from the start position (excluded) to the destination (included).

    \n\n

    You may assume that the borders of the maze are all walls (see examples).

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: maze = [[0,0,0,0,0],[1,1,0,0,1],[0,0,0,0,0],[0,1,0,0,1],[0,1,0,0,0]], ball = [4,3], hole = [0,1]\nOutput: "lul"\nExplanation: There are two shortest ways for the ball to drop into the hole.\nThe first way is left -> up -> left, represented by "lul".\nThe second way is up -> left, represented by 'ul'.\nBoth ways have shortest distance 6, but the first way is lexicographically smaller because 'l' < 'u'. So the output is "lul".\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: maze = [[0,0,0,0,0],[1,1,0,0,1],[0,0,0,0,0],[0,1,0,0,1],[0,1,0,0,0]], ball = [4,3], hole = [3,0]\nOutput: "impossible"\nExplanation: The ball cannot reach the hole.\n
    \n\n

    Example 3:

    \n\n
    \nInput: maze = [[0,0,0,0,0,0,0],[0,0,1,0,0,1,0],[0,0,0,0,1,0,0],[0,0,0,0,0,0,1]], ball = [0,4], hole = [3,5]\nOutput: "dldr"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == maze.length
    • \n\t
    • n == maze[i].length
    • \n\t
    • 1 <= m, n <= 100
    • \n\t
    • maze[i][j] is 0 or 1.
    • \n\t
    • ball.length == 2
    • \n\t
    • hole.length == 2
    • \n\t
    • 0 <= ballrow, holerow <= m
    • \n\t
    • 0 <= ballcol, holecol <= n
    • \n\t
    • Both the ball and the hole exist in an empty space, and they will not be in the same position initially.
    • \n\t
    • The maze contains at least 2 empty spaces.
    • \n
    \n", "content_cn": "

    \u7531\u7a7a\u5730\u548c\u5899\u7ec4\u6210\u7684\u8ff7\u5bab\u4e2d\u6709\u4e00\u4e2a\u7403\u3002\u7403\u53ef\u4ee5\u5411\u4e0a\uff08u\uff09\u4e0b\uff08d\uff09\u5de6\uff08l\uff09\u53f3\uff08r\uff09\u56db\u4e2a\u65b9\u5411\u6eda\u52a8\uff0c\u4f46\u5728\u9047\u5230\u5899\u58c1\u524d\u4e0d\u4f1a\u505c\u6b62\u6eda\u52a8\u3002\u5f53\u7403\u505c\u4e0b\u65f6\uff0c\u53ef\u4ee5\u9009\u62e9\u4e0b\u4e00\u4e2a\u65b9\u5411\u3002\u8ff7\u5bab\u4e2d\u8fd8\u6709\u4e00\u4e2a\u6d1e\uff0c\u5f53\u7403\u8fd0\u52a8\u7ecf\u8fc7\u6d1e\u65f6\uff0c\u5c31\u4f1a\u6389\u8fdb\u6d1e\u91cc\u3002

    \n\n

    \u7ed9\u5b9a\u7403\u7684\u8d77\u59cb\u4f4d\u7f6e\uff0c\u76ee\u7684\u5730\u548c\u8ff7\u5bab\uff0c\u627e\u51fa\u8ba9\u7403\u4ee5\u6700\u77ed\u8ddd\u79bb\u6389\u8fdb\u6d1e\u91cc\u7684\u8def\u5f84\u3002 \u8ddd\u79bb\u7684\u5b9a\u4e49\u662f\u7403\u4ece\u8d77\u59cb\u4f4d\u7f6e\uff08\u4e0d\u5305\u62ec\uff09\u5230\u76ee\u7684\u5730\uff08\u5305\u62ec\uff09\u7ecf\u8fc7\u7684\u7a7a\u5730\u4e2a\u6570\u3002\u901a\u8fc7'u', 'd', 'l' \u548c 'r'\u8f93\u51fa\u7403\u7684\u79fb\u52a8\u65b9\u5411\u3002 \u7531\u4e8e\u53ef\u80fd\u6709\u591a\u6761\u6700\u77ed\u8def\u5f84\uff0c \u8bf7\u8f93\u51fa\u5b57\u5178\u5e8f\u6700\u5c0f\u7684\u8def\u5f84\u3002\u5982\u679c\u7403\u65e0\u6cd5\u8fdb\u5165\u6d1e\uff0c\u8f93\u51fa"impossible"\u3002

    \n\n

    \u8ff7\u5bab\u7531\u4e00\u4e2a0\u548c1\u7684\u4e8c\u7ef4\u6570\u7ec4\u8868\u793a\u3002 1\u8868\u793a\u5899\u58c1\uff0c0\u8868\u793a\u7a7a\u5730\u3002\u4f60\u53ef\u4ee5\u5047\u5b9a\u8ff7\u5bab\u7684\u8fb9\u7f18\u90fd\u662f\u5899\u58c1\u3002\u8d77\u59cb\u4f4d\u7f6e\u548c\u76ee\u7684\u5730\u7684\u5750\u6807\u901a\u8fc7\u884c\u53f7\u548c\u5217\u53f7\u7ed9\u51fa\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b1:

    \n\n
    \u8f93\u5165 1: \u8ff7\u5bab\u7531\u4ee5\u4e0b\u4e8c\u7ef4\u6570\u7ec4\u8868\u793a\n\n0 0 0 0 0\n1 1 0 0 1\n0 0 0 0 0\n0 1 0 0 1\n0 1 0 0 0\n\n\u8f93\u5165 2: \u7403\u7684\u521d\u59cb\u4f4d\u7f6e (rowBall, colBall) = (4, 3)\n\u8f93\u5165 3: \u6d1e\u7684\u4f4d\u7f6e (rowHole, colHole) = (0, 1)\n\n\u8f93\u51fa: "lul"\n\n\u89e3\u6790: \u6709\u4e24\u6761\u8ba9\u7403\u8fdb\u6d1e\u7684\u6700\u77ed\u8def\u5f84\u3002\n\u7b2c\u4e00\u6761\u8def\u5f84\u662f \u5de6 -> \u4e0a -> \u5de6, \u8bb0\u4e3a "lul".\n\u7b2c\u4e8c\u6761\u8def\u5f84\u662f \u4e0a -> \u5de6, \u8bb0\u4e3a 'ul'.\n\u4e24\u6761\u8def\u5f84\u90fd\u5177\u6709\u6700\u77ed\u8ddd\u79bb6, \u4f46'l' < 'u'\uff0c\u6545\u7b2c\u4e00\u6761\u8def\u5f84\u5b57\u5178\u5e8f\u66f4\u5c0f\u3002\u56e0\u6b64\u8f93\u51fa"lul"\u3002\n\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165 1: \u8ff7\u5bab\u7531\u4ee5\u4e0b\u4e8c\u7ef4\u6570\u7ec4\u8868\u793a\n\n0 0 0 0 0\n1 1 0 0 1\n0 0 0 0 0\n0 1 0 0 1\n0 1 0 0 0\n\n\u8f93\u5165 2: \u7403\u7684\u521d\u59cb\u4f4d\u7f6e (rowBall, colBall) = (4, 3)\n\u8f93\u5165 3: \u6d1e\u7684\u4f4d\u7f6e (rowHole, colHole) = (3, 0)\n\n\u8f93\u51fa: "impossible"\n\n\u793a\u4f8b: \u7403\u65e0\u6cd5\u5230\u8fbe\u6d1e\u3002\n\n
    \n\n

     

    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u8ff7\u5bab\u4e2d\u53ea\u6709\u4e00\u4e2a\u7403\u548c\u4e00\u4e2a\u76ee\u7684\u5730\u3002
    2. \n\t
    3. \u7403\u548c\u6d1e\u90fd\u5728\u7a7a\u5730\u4e0a\uff0c\u4e14\u521d\u59cb\u65f6\u5b83\u4eec\u4e0d\u5728\u540c\u4e00\u4f4d\u7f6e\u3002
    4. \n\t
    5. \u7ed9\u5b9a\u7684\u8ff7\u5bab\u4e0d\u5305\u62ec\u8fb9\u754c (\u5982\u56fe\u4e2d\u7684\u7ea2\u8272\u77e9\u5f62), \u4f46\u4f60\u53ef\u4ee5\u5047\u8bbe\u8ff7\u5bab\u7684\u8fb9\u7f18\u90fd\u662f\u5899\u58c1\u3002
    6. \n\t
    7. \u8ff7\u5bab\u81f3\u5c11\u5305\u62ec2\u5757\u7a7a\u5730\uff0c\u884c\u6570\u548c\u5217\u6570\u5747\u4e0d\u8d85\u8fc730\u3002
    8. \n
    \n", "tags_en": ["Depth-first Search", "Breadth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string findShortestWay(vector>& maze, vector& ball, vector& hole) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String findShortestWay(int[][] maze, int[] ball, int[] hole) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findShortestWay(self, maze, ball, hole):\n \"\"\"\n :type maze: List[List[int]]\n :type ball: List[int]\n :type hole: List[int]\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findShortestWay(self, maze: List[List[int]], ball: List[int], hole: List[int]) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * findShortestWay(int** maze, int mazeSize, int* mazeColSize, int* ball, int ballSize, int* hole, int holeSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string FindShortestWay(int[][] maze, int[] ball, int[] hole) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} maze\n * @param {number[]} ball\n * @param {number[]} hole\n * @return {string}\n */\nvar findShortestWay = function(maze, ball, hole) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} maze\n# @param {Integer[]} ball\n# @param {Integer[]} hole\n# @return {String}\ndef find_shortest_way(maze, ball, hole)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findShortestWay(_ maze: [[Int]], _ ball: [Int], _ hole: [Int]) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findShortestWay(maze [][]int, ball []int, hole []int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findShortestWay(maze: Array[Array[Int]], ball: Array[Int], hole: Array[Int]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findShortestWay(maze: Array, ball: IntArray, hole: IntArray): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_shortest_way(maze: Vec>, ball: Vec, hole: Vec) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $maze\n * @param Integer[] $ball\n * @param Integer[] $hole\n * @return String\n */\n function findShortestWay($maze, $ball, $hole) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findShortestWay(maze: number[][], ball: number[], hole: number[]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-shortest-way maze ball hole)\n (-> (listof (listof exact-integer?)) (listof exact-integer?) (listof exact-integer?) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0499](https://leetcode-cn.com/problems/the-maze-iii)", "[\u8ff7\u5bab III](/solution/0400-0499/0499.The%20Maze%20III/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0499](https://leetcode.com/problems/the-maze-iii)", "[The Maze III](/solution/0400-0499/0499.The%20Maze%20III/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`", "Hard", "\ud83d\udd12"]}, {"question_id": "0498", "frontend_question_id": "0498", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/diagonal-traverse", "url_en": "https://leetcode.com/problems/diagonal-traverse", "relative_path_cn": "/solution/0400-0499/0498.Diagonal%20Traverse/README.md", "relative_path_en": "/solution/0400-0499/0498.Diagonal%20Traverse/README_EN.md", "title_cn": "\u5bf9\u89d2\u7ebf\u904d\u5386", "title_en": "Diagonal Traverse", "question_title_slug": "diagonal-traverse", "content_en": "

    Given an m x n matrix mat, return an array of all the elements of the array in a diagonal order.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: mat = [[1,2,3],[4,5,6],[7,8,9]]\nOutput: [1,2,4,7,5,3,6,8,9]\n
    \n\n

    Example 2:

    \n\n
    \nInput: mat = [[1,2],[3,4]]\nOutput: [1,2,3,4]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == mat.length
    • \n\t
    • n == mat[i].length
    • \n\t
    • 1 <= m, n <= 104
    • \n\t
    • 1 <= m * n <= 104
    • \n\t
    • -105 <= mat[i][j] <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u542b\u6709 M x N \u4e2a\u5143\u7d20\u7684\u77e9\u9635\uff08M \u884c\uff0cN \u5217\uff09\uff0c\u8bf7\u4ee5\u5bf9\u89d2\u7ebf\u904d\u5386\u7684\u987a\u5e8f\u8fd4\u56de\u8fd9\u4e2a\u77e9\u9635\u4e2d\u7684\u6240\u6709\u5143\u7d20\uff0c\u5bf9\u89d2\u7ebf\u904d\u5386\u5982\u4e0b\u56fe\u6240\u793a\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165:\n[\n [ 1, 2, 3 ],\n [ 4, 5, 6 ],\n [ 7, 8, 9 ]\n]\n\n\u8f93\u51fa:  [1,2,4,7,5,3,6,8,9]\n\n\u89e3\u91ca:\n\n
    \n\n

     

    \n\n

    \u8bf4\u660e:

    \n\n
      \n\t
    1. \u7ed9\u5b9a\u77e9\u9635\u4e2d\u7684\u5143\u7d20\u603b\u6570\u4e0d\u4f1a\u8d85\u8fc7 100000 \u3002
    2. \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findDiagonalOrder(vector>& mat) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] findDiagonalOrder(int[][] mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findDiagonalOrder(self, mat):\n \"\"\"\n :type mat: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findDiagonalOrder(self, mat: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* findDiagonalOrder(int** mat, int matSize, int* matColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] FindDiagonalOrder(int[][] mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} mat\n * @return {number[]}\n */\nvar findDiagonalOrder = function(mat) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} mat\n# @return {Integer[]}\ndef find_diagonal_order(mat)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findDiagonalOrder(_ mat: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findDiagonalOrder(mat [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findDiagonalOrder(mat: Array[Array[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findDiagonalOrder(mat: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_diagonal_order(mat: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $mat\n * @return Integer[]\n */\n function findDiagonalOrder($mat) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findDiagonalOrder(mat: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-diagonal-order mat)\n (-> (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0498](https://leetcode-cn.com/problems/diagonal-traverse)", "[\u5bf9\u89d2\u7ebf\u904d\u5386](/solution/0400-0499/0498.Diagonal%20Traverse/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0498](https://leetcode.com/problems/diagonal-traverse)", "[Diagonal Traverse](/solution/0400-0499/0498.Diagonal%20Traverse/README_EN.md)", "", "Medium", ""]}, {"question_id": "0496", "frontend_question_id": "0496", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/next-greater-element-i", "url_en": "https://leetcode.com/problems/next-greater-element-i", "relative_path_cn": "/solution/0400-0499/0496.Next%20Greater%20Element%20I/README.md", "relative_path_en": "/solution/0400-0499/0496.Next%20Greater%20Element%20I/README_EN.md", "title_cn": "\u4e0b\u4e00\u4e2a\u66f4\u5927\u5143\u7d20 I", "title_en": "Next Greater Element I", "question_title_slug": "next-greater-element-i", "content_en": "

    You are given two integer arrays nums1 and nums2 both of unique elements, where nums1 is a subset of nums2.

    \n\n

    Find all the next greater numbers for nums1's elements in the corresponding places of nums2.

    \n\n

    The Next Greater Number of a number x in nums1 is the first greater number to its right in nums2. If it does not exist, return -1 for this number.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums1 = [4,1,2], nums2 = [1,3,4,2]\nOutput: [-1,3,-1]\nExplanation:\nFor number 4 in the first array, you cannot find the next greater number for it in the second array, so output -1.\nFor number 1 in the first array, the next greater number for it in the second array is 3.\nFor number 2 in the first array, there is no next greater number for it in the second array, so output -1.
    \n\n

    Example 2:

    \n\n
    \nInput: nums1 = [2,4], nums2 = [1,2,3,4]\nOutput: [3,-1]\nExplanation:\nFor number 2 in the first array, the next greater number for it in the second array is 3.\nFor number 4 in the first array, there is no next greater number for it in the second array, so output -1.
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums1.length <= nums2.length <= 1000
    • \n\t
    • 0 <= nums1[i], nums2[i] <= 104
    • \n\t
    • All integers in nums1 and nums2 are unique.
    • \n\t
    • All the integers of nums1 also appear in nums2.
    • \n
    \n\n

     

    \nFollow up: Could you find an O(nums1.length + nums2.length) solution?", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a \u6ca1\u6709\u91cd\u590d\u5143\u7d20 \u7684\u6570\u7ec4\u00a0nums1 \u548c\u00a0nums2\u00a0\uff0c\u5176\u4e2dnums1\u00a0\u662f\u00a0nums2\u00a0\u7684\u5b50\u96c6\u3002

    \n\n

    \u8bf7\u4f60\u627e\u51fa nums1\u00a0\u4e2d\u6bcf\u4e2a\u5143\u7d20\u5728\u00a0nums2\u00a0\u4e2d\u7684\u4e0b\u4e00\u4e2a\u6bd4\u5176\u5927\u7684\u503c\u3002

    \n\n

    nums1\u00a0\u4e2d\u6570\u5b57\u00a0x\u00a0\u7684\u4e0b\u4e00\u4e2a\u66f4\u5927\u5143\u7d20\u662f\u6307\u00a0x\u00a0\u5728\u00a0nums2\u00a0\u4e2d\u5bf9\u5e94\u4f4d\u7f6e\u7684\u53f3\u8fb9\u7684\u7b2c\u4e00\u4e2a\u6bd4\u00a0x\u00a0\u5927\u7684\u5143\u7d20\u3002\u5982\u679c\u4e0d\u5b58\u5728\uff0c\u5bf9\u5e94\u4f4d\u7f6e\u8f93\u51fa -1 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: nums1 = [4,1,2], nums2 = [1,3,4,2].\n\u8f93\u51fa: [-1,3,-1]\n\u89e3\u91ca:\n    \u5bf9\u4e8e num1 \u4e2d\u7684\u6570\u5b57 4 \uff0c\u4f60\u65e0\u6cd5\u5728\u7b2c\u4e8c\u4e2a\u6570\u7ec4\u4e2d\u627e\u5230\u4e0b\u4e00\u4e2a\u66f4\u5927\u7684\u6570\u5b57\uff0c\u56e0\u6b64\u8f93\u51fa -1 \u3002\n    \u5bf9\u4e8e num1 \u4e2d\u7684\u6570\u5b57 1 \uff0c\u7b2c\u4e8c\u4e2a\u6570\u7ec4\u4e2d\u6570\u5b571\u53f3\u8fb9\u7684\u4e0b\u4e00\u4e2a\u8f83\u5927\u6570\u5b57\u662f 3 \u3002\n    \u5bf9\u4e8e num1 \u4e2d\u7684\u6570\u5b57 2 \uff0c\u7b2c\u4e8c\u4e2a\u6570\u7ec4\u4e2d\u6ca1\u6709\u4e0b\u4e00\u4e2a\u66f4\u5927\u7684\u6570\u5b57\uff0c\u56e0\u6b64\u8f93\u51fa -1 \u3002
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: nums1 = [2,4], nums2 = [1,2,3,4].\n\u8f93\u51fa: [3,-1]\n\u89e3\u91ca:\n\u00a0   \u5bf9\u4e8e num1 \u4e2d\u7684\u6570\u5b57 2 \uff0c\u7b2c\u4e8c\u4e2a\u6570\u7ec4\u4e2d\u7684\u4e0b\u4e00\u4e2a\u8f83\u5927\u6570\u5b57\u662f 3 \u3002\n    \u5bf9\u4e8e num1 \u4e2d\u7684\u6570\u5b57 4 \uff0c\u7b2c\u4e8c\u4e2a\u6570\u7ec4\u4e2d\u6ca1\u6709\u4e0b\u4e00\u4e2a\u66f4\u5927\u7684\u6570\u5b57\uff0c\u56e0\u6b64\u8f93\u51fa -1 \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums1.length <= nums2.length <= 1000
    • \n\t
    • 0 <= nums1[i], nums2[i] <= 104
    • \n\t
    • nums1\u548cnums2\u4e2d\u6240\u6709\u6574\u6570 \u4e92\u4e0d\u76f8\u540c
    • \n\t
    • nums1 \u4e2d\u7684\u6240\u6709\u6574\u6570\u540c\u6837\u51fa\u73b0\u5728 nums2 \u4e2d
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u53ef\u4ee5\u8bbe\u8ba1\u4e00\u4e2a\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(nums1.length + nums2.length) \u7684\u89e3\u51b3\u65b9\u6848\u5417\uff1f

    \n", "tags_en": ["Stack"], "tags_cn": ["\u6808"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector nextGreaterElement(vector& nums1, vector& nums2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] nextGreaterElement(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def nextGreaterElement(self, nums1, nums2):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def nextGreaterElement(self, nums1: List[int], nums2: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* nextGreaterElement(int* nums1, int nums1Size, int* nums2, int nums2Size, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] NextGreaterElement(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums1\n * @param {number[]} nums2\n * @return {number[]}\n */\nvar nextGreaterElement = function(nums1, nums2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums1\n# @param {Integer[]} nums2\n# @return {Integer[]}\ndef next_greater_element(nums1, nums2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func nextGreaterElement(_ nums1: [Int], _ nums2: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func nextGreaterElement(nums1 []int, nums2 []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def nextGreaterElement(nums1: Array[Int], nums2: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun nextGreaterElement(nums1: IntArray, nums2: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn next_greater_element(nums1: Vec, nums2: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums1\n * @param Integer[] $nums2\n * @return Integer[]\n */\n function nextGreaterElement($nums1, $nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function nextGreaterElement(nums1: number[], nums2: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (next-greater-element nums1 nums2)\n (-> (listof exact-integer?) (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0496](https://leetcode-cn.com/problems/next-greater-element-i)", "[\u4e0b\u4e00\u4e2a\u66f4\u5927\u5143\u7d20 I](/solution/0400-0499/0496.Next%20Greater%20Element%20I/README.md)", "`\u6808`", "\u7b80\u5355", ""], "md_table_row_en": ["[0496](https://leetcode.com/problems/next-greater-element-i)", "[Next Greater Element I](/solution/0400-0499/0496.Next%20Greater%20Element%20I/README_EN.md)", "`Stack`", "Easy", ""]}, {"question_id": "0495", "frontend_question_id": "0495", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/teemo-attacking", "url_en": "https://leetcode.com/problems/teemo-attacking", "relative_path_cn": "/solution/0400-0499/0495.Teemo%20Attacking/README.md", "relative_path_en": "/solution/0400-0499/0495.Teemo%20Attacking/README_EN.md", "title_cn": "\u63d0\u83ab\u653b\u51fb", "title_en": "Teemo Attacking", "question_title_slug": "teemo-attacking", "content_en": "

    Our hero Teemo is attacking an enemy Ashe with poison attacks! When Teemo attacks Ashe, Ashe gets poisoned for a exactly duration seconds. More formally, an attack at second t will mean Ashe is poisoned during the inclusive time interval [t, t + duration - 1]. If Teemo attacks again before the poison effect ends, the timer for it is reset, and the poison effect will end duration seconds after the new attack.

    \n\n

    You are given a non-decreasing integer array timeSeries, where timeSeries[i] denotes that Teemo attacks Ashe at second timeSeries[i], and an integer duration.

    \n\n

    Return the total number of seconds that Ashe is poisoned.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: timeSeries = [1,4], duration = 2\nOutput: 4\nExplanation: Teemo's attacks on Ashe go as follows:\n- At second 1, Teemo attacks, and Ashe is poisoned for seconds 1 and 2.\n- At second 4, Teemo attacks, and Ashe is poisoned for seconds 4 and 5.\nAshe is poisoned for seconds 1, 2, 4, and 5, which is 4 seconds in total.\n
    \n\n

    Example 2:

    \n\n
    \nInput: timeSeries = [1,2], duration = 2\nOutput: 3\nExplanation: Teemo's attacks on Ashe go as follows:\n- At second 1, Teemo attacks, and Ashe is poisoned for seconds 1 and 2.\n- At second 2 however, Teemo attacks again and resets the poison timer. Ashe is poisoned for seconds 2 and 3.\nAshe is poisoned for seconds 1, 2, and 3, which is 3 seconds in total.
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= timeSeries.length <= 104
    • \n\t
    • 0 <= timeSeries[i], duration <= 107
    • \n\t
    • timeSeries is sorted in non-decreasing order.
    • \n
    \n", "content_cn": "

    \u5728\u300a\u82f1\u96c4\u8054\u76df\u300b\u7684\u4e16\u754c\u4e2d\uff0c\u6709\u4e00\u4e2a\u53eb “\u63d0\u83ab” \u7684\u82f1\u96c4\uff0c\u4ed6\u7684\u653b\u51fb\u53ef\u4ee5\u8ba9\u654c\u65b9\u82f1\u96c4\u827e\u5e0c\uff08\u7f16\u8005\u6ce8\uff1a\u5bd2\u51b0\u5c04\u624b\uff09\u8fdb\u5165\u4e2d\u6bd2\u72b6\u6001\u3002\u73b0\u5728\uff0c\u7ed9\u51fa\u63d0\u83ab\u5bf9\u827e\u5e0c\u7684\u653b\u51fb\u65f6\u95f4\u5e8f\u5217\u548c\u63d0\u83ab\u653b\u51fb\u7684\u4e2d\u6bd2\u6301\u7eed\u65f6\u95f4\uff0c\u4f60\u9700\u8981\u8f93\u51fa\u827e\u5e0c\u7684\u4e2d\u6bd2\u72b6\u6001\u603b\u65f6\u957f\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u8ba4\u4e3a\u63d0\u83ab\u5728\u7ed9\u5b9a\u7684\u65f6\u95f4\u70b9\u8fdb\u884c\u653b\u51fb\uff0c\u5e76\u7acb\u5373\u4f7f\u827e\u5e0c\u5904\u4e8e\u4e2d\u6bd2\u72b6\u6001\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b1:

    \n\n
    \u8f93\u5165: [1,4], 2\n\u8f93\u51fa: 4\n\u539f\u56e0: \u7b2c 1 \u79d2\u521d\uff0c\u63d0\u83ab\u5f00\u59cb\u5bf9\u827e\u5e0c\u8fdb\u884c\u653b\u51fb\u5e76\u4f7f\u5176\u7acb\u5373\u4e2d\u6bd2\u3002\u4e2d\u6bd2\u72b6\u6001\u4f1a\u7ef4\u6301 2 \u79d2\u949f\uff0c\u76f4\u5230\u7b2c 2 \u79d2\u672b\u7ed3\u675f\u3002\n\u7b2c 4 \u79d2\u521d\uff0c\u63d0\u83ab\u518d\u6b21\u653b\u51fb\u827e\u5e0c\uff0c\u4f7f\u5f97\u827e\u5e0c\u83b7\u5f97\u53e6\u5916 2 \u79d2\u4e2d\u6bd2\u65f6\u95f4\u3002\n\u6240\u4ee5\u6700\u7ec8\u8f93\u51fa 4 \u79d2\u3002\n
    \n\n

    \u793a\u4f8b2:

    \n\n
    \u8f93\u5165: [1,2], 2\n\u8f93\u51fa: 3\n\u539f\u56e0: \u7b2c 1 \u79d2\u521d\uff0c\u63d0\u83ab\u5f00\u59cb\u5bf9\u827e\u5e0c\u8fdb\u884c\u653b\u51fb\u5e76\u4f7f\u5176\u7acb\u5373\u4e2d\u6bd2\u3002\u4e2d\u6bd2\u72b6\u6001\u4f1a\u7ef4\u6301 2 \u79d2\u949f\uff0c\u76f4\u5230\u7b2c 2 \u79d2\u672b\u7ed3\u675f\u3002\n\u4f46\u662f\u7b2c 2 \u79d2\u521d\uff0c\u63d0\u83ab\u518d\u6b21\u653b\u51fb\u4e86\u5df2\u7ecf\u5904\u4e8e\u4e2d\u6bd2\u72b6\u6001\u7684\u827e\u5e0c\u3002\n\u7531\u4e8e\u4e2d\u6bd2\u72b6\u6001\u4e0d\u53ef\u53e0\u52a0\uff0c\u63d0\u83ab\u5728\u7b2c 2 \u79d2\u521d\u7684\u8fd9\u6b21\u653b\u51fb\u4f1a\u5728\u7b2c 3 \u79d2\u672b\u7ed3\u675f\u3002\n\u6240\u4ee5\u6700\u7ec8\u8f93\u51fa 3 \u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. \u4f60\u53ef\u4ee5\u5047\u5b9a\u65f6\u95f4\u5e8f\u5217\u6570\u7ec4\u7684\u603b\u957f\u5ea6\u4e0d\u8d85\u8fc7 10000\u3002
    2. \n\t
    3. \u4f60\u53ef\u4ee5\u5047\u5b9a\u63d0\u83ab\u653b\u51fb\u65f6\u95f4\u5e8f\u5217\u4e2d\u7684\u6570\u5b57\u548c\u63d0\u83ab\u653b\u51fb\u7684\u4e2d\u6bd2\u6301\u7eed\u65f6\u95f4\u90fd\u662f\u975e\u8d1f\u6574\u6570\uff0c\u5e76\u4e14\u4e0d\u8d85\u8fc7 10,000,000\u3002
    4. \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findPoisonedDuration(vector& timeSeries, int duration) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findPoisonedDuration(int[] timeSeries, int duration) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findPoisonedDuration(self, timeSeries, duration):\n \"\"\"\n :type timeSeries: List[int]\n :type duration: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findPoisonedDuration(self, timeSeries: List[int], duration: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findPoisonedDuration(int* timeSeries, int timeSeriesSize, int duration){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindPoisonedDuration(int[] timeSeries, int duration) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} timeSeries\n * @param {number} duration\n * @return {number}\n */\nvar findPoisonedDuration = function(timeSeries, duration) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} time_series\n# @param {Integer} duration\n# @return {Integer}\ndef find_poisoned_duration(time_series, duration)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findPoisonedDuration(_ timeSeries: [Int], _ duration: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findPoisonedDuration(timeSeries []int, duration int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findPoisonedDuration(timeSeries: Array[Int], duration: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findPoisonedDuration(timeSeries: IntArray, duration: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_poisoned_duration(time_series: Vec, duration: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $timeSeries\n * @param Integer $duration\n * @return Integer\n */\n function findPoisonedDuration($timeSeries, $duration) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findPoisonedDuration(timeSeries: number[], duration: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-poisoned-duration timeSeries duration)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0495](https://leetcode-cn.com/problems/teemo-attacking)", "[\u63d0\u83ab\u653b\u51fb](/solution/0400-0499/0495.Teemo%20Attacking/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0495](https://leetcode.com/problems/teemo-attacking)", "[Teemo Attacking](/solution/0400-0499/0495.Teemo%20Attacking/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0494", "frontend_question_id": "0494", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/target-sum", "url_en": "https://leetcode.com/problems/target-sum", "relative_path_cn": "/solution/0400-0499/0494.Target%20Sum/README.md", "relative_path_en": "/solution/0400-0499/0494.Target%20Sum/README_EN.md", "title_cn": "\u76ee\u6807\u548c", "title_en": "Target Sum", "question_title_slug": "target-sum", "content_en": "

    You are given an integer array nums and an integer target.

    \n\n

    You want to build an expression out of nums by adding one of the symbols '+' and '-' before each integer in nums and then concatenate all the integers.

    \n\n
      \n\t
    • For example, if nums = [2, 1], you can add a '+' before 2 and a '-' before 1 and concatenate them to build the expression "+2-1".
    • \n
    \n\n

    Return the number of different expressions that you can build, which evaluates to target.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,1,1,1,1], target = 3\nOutput: 5\nExplanation: There are 5 ways to assign symbols to make the sum of nums be target 3.\n-1 + 1 + 1 + 1 + 1 = 3\n+1 - 1 + 1 + 1 + 1 = 3\n+1 + 1 - 1 + 1 + 1 = 3\n+1 + 1 + 1 - 1 + 1 = 3\n+1 + 1 + 1 + 1 - 1 = 3\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1], target = 1\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 20
    • \n\t
    • 0 <= nums[i] <= 1000
    • \n\t
    • 0 <= sum(nums[i]) <= 1000
    • \n\t
    • -1000 <= target <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \u548c\u4e00\u4e2a\u6574\u6570 target \u3002

    \n\n

    \u5411\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u6574\u6570\u524d\u6dfb\u52a0\u00a0'+' \u6216 '-' \uff0c\u7136\u540e\u4e32\u8054\u8d77\u6240\u6709\u6574\u6570\uff0c\u53ef\u4ee5\u6784\u9020\u4e00\u4e2a \u8868\u8fbe\u5f0f \uff1a

    \n\n
      \n\t
    • \u4f8b\u5982\uff0cnums = [2, 1] \uff0c\u53ef\u4ee5\u5728 2 \u4e4b\u524d\u6dfb\u52a0 '+' \uff0c\u5728 1 \u4e4b\u524d\u6dfb\u52a0 '-' \uff0c\u7136\u540e\u4e32\u8054\u8d77\u6765\u5f97\u5230\u8868\u8fbe\u5f0f \"+2-1\" \u3002
    • \n
    \n\n

    \u8fd4\u56de\u53ef\u4ee5\u901a\u8fc7\u4e0a\u8ff0\u65b9\u6cd5\u6784\u9020\u7684\u3001\u8fd0\u7b97\u7ed3\u679c\u7b49\u4e8e target \u7684\u4e0d\u540c \u8868\u8fbe\u5f0f \u7684\u6570\u76ee\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,1,1,1,1], target = 3\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u4e00\u5171\u6709 5 \u79cd\u65b9\u6cd5\u8ba9\u6700\u7ec8\u76ee\u6807\u548c\u4e3a 3 \u3002\n-1 + 1 + 1 + 1 + 1 = 3\n+1 - 1 + 1 + 1 + 1 = 3\n+1 + 1 - 1 + 1 + 1 = 3\n+1 + 1 + 1 - 1 + 1 = 3\n+1 + 1 + 1 + 1 - 1 = 3\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1], target = 1\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 20
    • \n\t
    • 0 <= nums[i] <= 1000
    • \n\t
    • 0 <= sum(nums[i]) <= 1000
    • \n\t
    • -1000 <= target <= 100
    • \n
    \n", "tags_en": ["Depth-first Search", "Dynamic Programming"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findTargetSumWays(vector& nums, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findTargetSumWays(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findTargetSumWays(self, nums, target):\n \"\"\"\n :type nums: List[int]\n :type target: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findTargetSumWays(self, nums: List[int], target: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findTargetSumWays(int* nums, int numsSize, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindTargetSumWays(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} target\n * @return {number}\n */\nvar findTargetSumWays = function(nums, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} target\n# @return {Integer}\ndef find_target_sum_ways(nums, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findTargetSumWays(_ nums: [Int], _ target: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findTargetSumWays(nums []int, target int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findTargetSumWays(nums: Array[Int], target: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findTargetSumWays(nums: IntArray, target: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_target_sum_ways(nums: Vec, target: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $target\n * @return Integer\n */\n function findTargetSumWays($nums, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findTargetSumWays(nums: number[], target: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-target-sum-ways nums target)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0494](https://leetcode-cn.com/problems/target-sum)", "[\u76ee\u6807\u548c](/solution/0400-0499/0494.Target%20Sum/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0494](https://leetcode.com/problems/target-sum)", "[Target Sum](/solution/0400-0499/0494.Target%20Sum/README_EN.md)", "`Depth-first Search`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0493", "frontend_question_id": "0493", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reverse-pairs", "url_en": "https://leetcode.com/problems/reverse-pairs", "relative_path_cn": "/solution/0400-0499/0493.Reverse%20Pairs/README.md", "relative_path_en": "/solution/0400-0499/0493.Reverse%20Pairs/README_EN.md", "title_cn": "\u7ffb\u8f6c\u5bf9", "title_en": "Reverse Pairs", "question_title_slug": "reverse-pairs", "content_en": "

    Given an integer array nums, return the number of reverse pairs in the array.

    \n\n

    A reverse pair is a pair (i, j) where 0 <= i < j < nums.length and nums[i] > 2 * nums[j].

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [1,3,2,3,1]\nOutput: 2\n

    Example 2:

    \n
    Input: nums = [2,4,3,5,1]\nOutput: 3\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 5 * 104
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6570\u7ec4 nums \uff0c\u5982\u679c i < j \u4e14 nums[i] > 2*nums[j] \u6211\u4eec\u5c31\u5c06 (i, j) \u79f0\u4f5c\u4e00\u4e2a\u91cd\u8981\u7ffb\u8f6c\u5bf9\u3002

    \n\n

    \u4f60\u9700\u8981\u8fd4\u56de\u7ed9\u5b9a\u6570\u7ec4\u4e2d\u7684\u91cd\u8981\u7ffb\u8f6c\u5bf9\u7684\u6570\u91cf\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: [1,3,2,3,1]\n\u8f93\u51fa: 2\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: [2,4,3,5,1]\n\u8f93\u51fa: 3\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u7ed9\u5b9a\u6570\u7ec4\u7684\u957f\u5ea6\u4e0d\u4f1a\u8d85\u8fc750000\u3002
    2. \n\t
    3. \u8f93\u5165\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u6570\u5b57\u90fd\u572832\u4f4d\u6574\u6570\u7684\u8868\u793a\u8303\u56f4\u5185\u3002
    4. \n
    \n", "tags_en": ["Sort", "Binary Indexed Tree", "Segment Tree", "Binary Search", "Divide and Conquer"], "tags_cn": ["\u6392\u5e8f", "\u6811\u72b6\u6570\u7ec4", "\u7ebf\u6bb5\u6811", "\u4e8c\u5206\u67e5\u627e", "\u5206\u6cbb\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int reversePairs(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int reversePairs(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def reversePairs(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def reversePairs(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint reversePairs(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ReversePairs(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar reversePairs = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef reverse_pairs(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func reversePairs(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func reversePairs(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def reversePairs(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun reversePairs(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn reverse_pairs(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function reversePairs($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function reversePairs(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (reverse-pairs nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0493](https://leetcode-cn.com/problems/reverse-pairs)", "[\u7ffb\u8f6c\u5bf9](/solution/0400-0499/0493.Reverse%20Pairs/README.md)", "`\u6392\u5e8f`,`\u6811\u72b6\u6570\u7ec4`,`\u7ebf\u6bb5\u6811`,`\u4e8c\u5206\u67e5\u627e`,`\u5206\u6cbb\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[0493](https://leetcode.com/problems/reverse-pairs)", "[Reverse Pairs](/solution/0400-0499/0493.Reverse%20Pairs/README_EN.md)", "`Sort`,`Binary Indexed Tree`,`Segment Tree`,`Binary Search`,`Divide and Conquer`", "Hard", ""]}, {"question_id": "0492", "frontend_question_id": "0492", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/construct-the-rectangle", "url_en": "https://leetcode.com/problems/construct-the-rectangle", "relative_path_cn": "/solution/0400-0499/0492.Construct%20the%20Rectangle/README.md", "relative_path_en": "/solution/0400-0499/0492.Construct%20the%20Rectangle/README_EN.md", "title_cn": "\u6784\u9020\u77e9\u5f62", "title_en": "Construct the Rectangle", "question_title_slug": "construct-the-rectangle", "content_en": "

    A web developer needs to know how to design a web page's size. So, given a specific rectangular web page’s area, your job by now is to design a rectangular web page, whose length L and width W satisfy the following requirements:

    \n\n
      \n\t
    1. The area of the rectangular web page you designed must equal to the given target area.
    2. \n\t
    3. The width W should not be larger than the length L, which means L >= W.
    4. \n\t
    5. The difference between length L and width W should be as small as possible.
    6. \n
    \n\n

    Return an array [L, W] where L and W are the length and width of the web page you designed in sequence.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: area = 4\nOutput: [2,2]\nExplanation: The target area is 4, and all the possible ways to construct it are [1,4], [2,2], [4,1]. \nBut according to requirement 2, [1,4] is illegal; according to requirement 3,  [4,1] is not optimal compared to [2,2]. So the length L is 2, and the width W is 2.\n
    \n\n

    Example 2:

    \n\n
    \nInput: area = 37\nOutput: [37,1]\n
    \n\n

    Example 3:

    \n\n
    \nInput: area = 122122\nOutput: [427,286]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= area <= 107
    • \n
    \n", "content_cn": "

    \u4f5c\u4e3a\u4e00\u4f4dweb\u5f00\u53d1\u8005\uff0c \u61c2\u5f97\u600e\u6837\u53bb\u89c4\u5212\u4e00\u4e2a\u9875\u9762\u7684\u5c3a\u5bf8\u662f\u5f88\u91cd\u8981\u7684\u3002 \u73b0\u7ed9\u5b9a\u4e00\u4e2a\u5177\u4f53\u7684\u77e9\u5f62\u9875\u9762\u9762\u79ef\uff0c\u4f60\u7684\u4efb\u52a1\u662f\u8bbe\u8ba1\u4e00\u4e2a\u957f\u5ea6\u4e3a L \u548c\u5bbd\u5ea6\u4e3a W \u4e14\u6ee1\u8db3\u4ee5\u4e0b\u8981\u6c42\u7684\u77e9\u5f62\u7684\u9875\u9762\u3002\u8981\u6c42\uff1a

    \n\n
    \n1. \u4f60\u8bbe\u8ba1\u7684\u77e9\u5f62\u9875\u9762\u5fc5\u987b\u7b49\u4e8e\u7ed9\u5b9a\u7684\u76ee\u6807\u9762\u79ef\u3002\n\n2. \u5bbd\u5ea6 W \u4e0d\u5e94\u5927\u4e8e\u957f\u5ea6 L\uff0c\u6362\u8a00\u4e4b\uff0c\u8981\u6c42 L >= W \u3002\n\n3. \u957f\u5ea6 L \u548c\u5bbd\u5ea6 W \u4e4b\u95f4\u7684\u5dee\u8ddd\u5e94\u5f53\u5c3d\u53ef\u80fd\u5c0f\u3002\n
    \n\n

    \u4f60\u9700\u8981\u6309\u987a\u5e8f\u8f93\u51fa\u4f60\u8bbe\u8ba1\u7684\u9875\u9762\u7684\u957f\u5ea6 L \u548c\u5bbd\u5ea6 W\u3002

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165: 4\n\u8f93\u51fa: [2, 2]\n\u89e3\u91ca: \u76ee\u6807\u9762\u79ef\u662f 4\uff0c \u6240\u6709\u53ef\u80fd\u7684\u6784\u9020\u65b9\u6848\u6709 [1,4], [2,2], [4,1]\u3002\n\u4f46\u662f\u6839\u636e\u8981\u6c422\uff0c[1,4] \u4e0d\u7b26\u5408\u8981\u6c42; \u6839\u636e\u8981\u6c423\uff0c[2,2] \u6bd4 [4,1] \u66f4\u80fd\u7b26\u5408\u8981\u6c42. \u6240\u4ee5\u8f93\u51fa\u957f\u5ea6 L \u4e3a 2\uff0c \u5bbd\u5ea6 W \u4e3a 2\u3002\n
    \n\n

    \u8bf4\u660e:

    \n\n
      \n\t
    1. \u7ed9\u5b9a\u7684\u9762\u79ef\u4e0d\u5927\u4e8e 10,000,000 \u4e14\u4e3a\u6b63\u6574\u6570\u3002
    2. \n\t
    3. \u4f60\u8bbe\u8ba1\u7684\u9875\u9762\u7684\u957f\u5ea6\u548c\u5bbd\u5ea6\u5fc5\u987b\u90fd\u662f\u6b63\u6574\u6570\u3002
    4. \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector constructRectangle(int area) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] constructRectangle(int area) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def constructRectangle(self, area):\n \"\"\"\n :type area: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def constructRectangle(self, area: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* constructRectangle(int area, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] ConstructRectangle(int area) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} area\n * @return {number[]}\n */\nvar constructRectangle = function(area) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} area\n# @return {Integer[]}\ndef construct_rectangle(area)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func constructRectangle(_ area: Int) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func constructRectangle(area int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def constructRectangle(area: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun constructRectangle(area: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn construct_rectangle(area: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $area\n * @return Integer[]\n */\n function constructRectangle($area) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function constructRectangle(area: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (construct-rectangle area)\n (-> exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0492](https://leetcode-cn.com/problems/construct-the-rectangle)", "[\u6784\u9020\u77e9\u5f62](/solution/0400-0499/0492.Construct%20the%20Rectangle/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0492](https://leetcode.com/problems/construct-the-rectangle)", "[Construct the Rectangle](/solution/0400-0499/0492.Construct%20the%20Rectangle/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "0491", "frontend_question_id": "0491", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/increasing-subsequences", "url_en": "https://leetcode.com/problems/increasing-subsequences", "relative_path_cn": "/solution/0400-0499/0491.Increasing%20Subsequences/README.md", "relative_path_en": "/solution/0400-0499/0491.Increasing%20Subsequences/README_EN.md", "title_cn": "\u9012\u589e\u5b50\u5e8f\u5217", "title_en": "Increasing Subsequences", "question_title_slug": "increasing-subsequences", "content_en": "

    Given an integer array nums, return all the different possible increasing subsequences of the given array with at least two elements. You may return the answer in any order.

    \n\n

    The given array may contain duplicates, and two equal integers should also be considered a special case of increasing sequence.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [4,6,7,7]\nOutput: [[4,6],[4,6,7],[4,6,7,7],[4,7],[4,7,7],[6,7],[6,7,7],[7,7]]\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [4,4,3,2,1]\nOutput: [[4,4]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 15
    • \n\t
    • -100 <= nums[i] <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u578b\u6570\u7ec4, \u4f60\u7684\u4efb\u52a1\u662f\u627e\u5230\u6240\u6709\u8be5\u6570\u7ec4\u7684\u9012\u589e\u5b50\u5e8f\u5217\uff0c\u9012\u589e\u5b50\u5e8f\u5217\u7684\u957f\u5ea6\u81f3\u5c11\u662f 2 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[4, 6, 7, 7]\n\u8f93\u51fa\uff1a[[4, 6], [4, 7], [4, 6, 7], [4, 6, 7, 7], [6, 7], [6, 7, 7], [7,7], [4,7,7]]
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u7ed9\u5b9a\u6570\u7ec4\u7684\u957f\u5ea6\u4e0d\u4f1a\u8d85\u8fc715\u3002
    • \n\t
    • \u6570\u7ec4\u4e2d\u7684\u6574\u6570\u8303\u56f4\u662f\u00a0[-100,100]\u3002
    • \n\t
    • \u7ed9\u5b9a\u6570\u7ec4\u4e2d\u53ef\u80fd\u5305\u542b\u91cd\u590d\u6570\u5b57\uff0c\u76f8\u7b49\u7684\u6570\u5b57\u5e94\u8be5\u88ab\u89c6\u4e3a\u9012\u589e\u7684\u4e00\u79cd\u60c5\u51b5\u3002
    • \n
    \n", "tags_en": ["Depth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> findSubsequences(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> findSubsequences(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findSubsequences(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findSubsequences(self, nums: List[int]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** findSubsequences(int* nums, int numsSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> FindSubsequences(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number[][]}\n */\nvar findSubsequences = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer[][]}\ndef find_subsequences(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findSubsequences(_ nums: [Int]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findSubsequences(nums []int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findSubsequences(nums: Array[Int]): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findSubsequences(nums: IntArray): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_subsequences(nums: Vec) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer[][]\n */\n function findSubsequences($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findSubsequences(nums: number[]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-subsequences nums)\n (-> (listof exact-integer?) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0491](https://leetcode-cn.com/problems/increasing-subsequences)", "[\u9012\u589e\u5b50\u5e8f\u5217](/solution/0400-0499/0491.Increasing%20Subsequences/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0491](https://leetcode.com/problems/increasing-subsequences)", "[Increasing Subsequences](/solution/0400-0499/0491.Increasing%20Subsequences/README_EN.md)", "`Depth-first Search`", "Medium", ""]}, {"question_id": "0490", "frontend_question_id": "0490", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/the-maze", "url_en": "https://leetcode.com/problems/the-maze", "relative_path_cn": "/solution/0400-0499/0490.The%20Maze/README.md", "relative_path_en": "/solution/0400-0499/0490.The%20Maze/README_EN.md", "title_cn": "\u8ff7\u5bab", "title_en": "The Maze", "question_title_slug": "the-maze", "content_en": "

    There is a ball in a maze with empty spaces (represented as 0) and walls (represented as 1). The ball can go through the empty spaces by rolling up, down, left or right, but it won't stop rolling until hitting a wall. When the ball stops, it could choose the next direction.

    \n\n

    Given the m x n maze, the ball's start position and the destination, where start = [startrow, startcol] and destination = [destinationrow, destinationcol], return true if the ball can stop at the destination, otherwise return false.

    \n\n

    You may assume that the borders of the maze are all walls (see examples).

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: maze = [[0,0,1,0,0],[0,0,0,0,0],[0,0,0,1,0],[1,1,0,1,1],[0,0,0,0,0]], start = [0,4], destination = [4,4]\nOutput: true\nExplanation: One possible way is : left -> down -> left -> down -> right -> down -> right.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: maze = [[0,0,1,0,0],[0,0,0,0,0],[0,0,0,1,0],[1,1,0,1,1],[0,0,0,0,0]], start = [0,4], destination = [3,2]\nOutput: false\nExplanation: There is no way for the ball to stop at the destination. Notice that you can pass through the destination but you cannot stop there.\n
    \n\n

    Example 3:

    \n\n
    \nInput: maze = [[0,0,0,0,0],[1,1,0,0,1],[0,0,0,0,0],[0,1,0,0,1],[0,1,0,0,0]], start = [4,3], destination = [0,1]\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == maze.length
    • \n\t
    • n == maze[i].length
    • \n\t
    • 1 <= m, n <= 100
    • \n\t
    • maze[i][j] is 0 or 1.
    • \n\t
    • start.length == 2
    • \n\t
    • destination.length == 2
    • \n\t
    • 0 <= startrow, destinationrow <= m
    • \n\t
    • 0 <= startcol, destinationcol <= n
    • \n\t
    • Both the ball and the destination exist in an empty space, and they will not be in the same position initially.
    • \n\t
    • The maze contains at least 2 empty spaces.
    • \n
    \n", "content_cn": "\u7531\u7a7a\u5730\uff08\u7528 0 \u8868\u793a\uff09\u548c\u5899\uff08\u7528 1 \u8868\u793a\uff09\u7ec4\u6210\u7684\u8ff7\u5bab maze \u4e2d\u6709\u4e00\u4e2a\u7403\u3002\u7403\u53ef\u4ee5\u9014\u7ecf\u7a7a\u5730\u5411 \u4e0a\u3001\u4e0b\u3001\u5de6\u3001\u53f3 \u56db\u4e2a\u65b9\u5411\u6eda\u52a8\uff0c\u4e14\u5728\u9047\u5230\u5899\u58c1\u524d\u4e0d\u4f1a\u505c\u6b62\u6eda\u52a8\u3002\u5f53\u7403\u505c\u4e0b\u65f6\uff0c\u53ef\u4ee5\u9009\u62e9\u5411\u4e0b\u4e00\u4e2a\u65b9\u5411\u6eda\u52a8\u3002\n
    \n
    \n
    \n

    \u7ed9\u4f60\u4e00\u4e2a\u5927\u5c0f\u4e3a m x n \u7684\u8ff7\u5bab maze \uff0c\u4ee5\u53ca\u7403\u7684\u521d\u59cb\u4f4d\u7f6e start \u548c\u76ee\u7684\u5730 destination \uff0c\u5176\u4e2d start = [startrow, startcol] \u4e14 destination = [destinationrow, destinationcol] \u3002\u8bf7\u4f60\u5224\u65ad\u7403\u80fd\u5426\u5728\u76ee\u7684\u5730\u505c\u4e0b\uff1a\u5982\u679c\u53ef\u4ee5\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n

    \u4f60\u53ef\u4ee5 \u5047\u5b9a\u8ff7\u5bab\u7684\u8fb9\u7f18\u90fd\u662f\u5899\u58c1\uff08\u53c2\u8003\u793a\u4f8b\uff09\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1amaze = [[0,0,1,0,0],[0,0,0,0,0],[0,0,0,1,0],[1,1,0,1,1],[0,0,0,0,0]], start = [0,4], destination = [4,4]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u4e00\u79cd\u53ef\u80fd\u7684\u8def\u5f84\u662f : \u5de6 -> \u4e0b -> \u5de6 -> \u4e0b -> \u53f3 -> \u4e0b -> \u53f3\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1amaze = [[0,0,1,0,0],[0,0,0,0,0],[0,0,0,1,0],[1,1,0,1,1],[0,0,0,0,0]], start = [0,4], destination = [3,2]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u4e0d\u5b58\u5728\u80fd\u591f\u4f7f\u7403\u505c\u5728\u76ee\u7684\u5730\u7684\u8def\u5f84\u3002\u6ce8\u610f\uff0c\u7403\u53ef\u4ee5\u7ecf\u8fc7\u76ee\u7684\u5730\uff0c\u4f46\u65e0\u6cd5\u5728\u90a3\u91cc\u505c\u9a7b\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1amaze = [[0,0,0,0,0],[1,1,0,0,1],[0,0,0,0,0],[0,1,0,0,1],[0,1,0,0,0]], start = [4,3], destination = [0,1]\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == maze.length
    • \n\t
    • n == maze[i].length
    • \n\t
    • 1 <= m, n <= 100
    • \n\t
    • maze[i][j] is 0 or 1.
    • \n\t
    • start.length == 2
    • \n\t
    • destination.length == 2
    • \n\t
    • 0 <= startrow, destinationrow <= m
    • \n\t
    • 0 <= startcol, destinationcol <= n
    • \n\t
    • \u7403\u548c\u76ee\u7684\u5730\u90fd\u5728\u7a7a\u5730\u4e0a\uff0c\u4e14\u521d\u59cb\u65f6\u5b83\u4eec\u4e0d\u5728\u540c\u4e00\u4f4d\u7f6e
    • \n\t
    • \u8ff7\u5bab \u81f3\u5c11\u5305\u62ec 2 \u5757\u7a7a\u5730
    • \n
    \n
    \n
    \n
    \n", "tags_en": ["Depth-first Search", "Breadth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool hasPath(vector>& maze, vector& start, vector& destination) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean hasPath(int[][] maze, int[] start, int[] destination) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def hasPath(self, maze, start, destination):\n \"\"\"\n :type maze: List[List[int]]\n :type start: List[int]\n :type destination: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def hasPath(self, maze: List[List[int]], start: List[int], destination: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool hasPath(int** maze, int mazeSize, int* mazeColSize, int* start, int startSize, int* destination, int destinationSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool HasPath(int[][] maze, int[] start, int[] destination) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} maze\n * @param {number[]} start\n * @param {number[]} destination\n * @return {boolean}\n */\nvar hasPath = function(maze, start, destination) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} maze\n# @param {Integer[]} start\n# @param {Integer[]} destination\n# @return {Boolean}\ndef has_path(maze, start, destination)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func hasPath(_ maze: [[Int]], _ start: [Int], _ destination: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func hasPath(maze [][]int, start []int, destination []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def hasPath(maze: Array[Array[Int]], start: Array[Int], destination: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun hasPath(maze: Array, start: IntArray, destination: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn has_path(maze: Vec>, start: Vec, destination: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $maze\n * @param Integer[] $start\n * @param Integer[] $destination\n * @return Boolean\n */\n function hasPath($maze, $start, $destination) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function hasPath(maze: number[][], start: number[], destination: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (has-path maze start destination)\n (-> (listof (listof exact-integer?)) (listof exact-integer?) (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0490](https://leetcode-cn.com/problems/the-maze)", "[\u8ff7\u5bab](/solution/0400-0499/0490.The%20Maze/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0490](https://leetcode.com/problems/the-maze)", "[The Maze](/solution/0400-0499/0490.The%20Maze/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`", "Medium", "\ud83d\udd12"]}, {"question_id": "0489", "frontend_question_id": "1643", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/kth-smallest-instructions", "url_en": "https://leetcode.com/problems/kth-smallest-instructions", "relative_path_cn": "/solution/1600-1699/1643.Kth%20Smallest%20Instructions/README.md", "relative_path_en": "/solution/1600-1699/1643.Kth%20Smallest%20Instructions/README_EN.md", "title_cn": "\u7b2c K \u6761\u6700\u5c0f\u6307\u4ee4", "title_en": "Kth Smallest Instructions", "question_title_slug": "kth-smallest-instructions", "content_en": "

    Bob is standing at cell (0, 0), and he wants to reach destination: (row, column). He can only travel right and down. You are going to help Bob by providing instructions for him to reach destination.

    \n\n

    The instructions are represented as a string, where each character is either:

    \n\n
      \n\t
    • 'H', meaning move horizontally (go right), or
    • \n\t
    • 'V', meaning move vertically (go down).
    • \n
    \n\n

    Multiple instructions will lead Bob to destination. For example, if destination is (2, 3), both "HHHVV" and "HVHVH" are valid instructions.

    \n\n

    However, Bob is very picky. Bob has a lucky number k, and he wants the kth lexicographically smallest instructions that will lead him to destination. k is 1-indexed.

    \n\n

    Given an integer array destination and an integer k, return the kth lexicographically smallest instructions that will take Bob to destination.

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: destination = [2,3], k = 1\nOutput: "HHHVV"\nExplanation: All the instructions that reach (2, 3) in lexicographic order are as follows:\n["HHHVV", "HHVHV", "HHVVH", "HVHHV", "HVHVH", "HVVHH", "VHHHV", "VHHVH", "VHVHH", "VVHHH"].\n
    \n\n

    Example 2:

    \n\n

    \"\"

    \n\n
    \nInput: destination = [2,3], k = 2\nOutput: "HHVHV"\n
    \n\n

    Example 3:

    \n\n

    \"\"

    \n\n
    \nInput: destination = [2,3], k = 3\nOutput: "HHVVH"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • destination.length == 2
    • \n\t
    • 1 <= row, column <= 15
    • \n\t
    • 1 <= k <= nCr(row + column, row), where nCr(a, b) denotes a choose b\u200b\u200b\u200b\u200b\u200b.
    • \n
    \n", "content_cn": "

    Bob \u7ad9\u5728\u5355\u5143\u683c (0, 0) \uff0c\u60f3\u8981\u524d\u5f80\u76ee\u7684\u5730 destination \uff1a(row, column) \u3002\u4ed6\u53ea\u80fd\u5411 \u53f3 \u6216\u5411 \u4e0b \u8d70\u3002\u4f60\u53ef\u4ee5\u4e3a Bob \u63d0\u4f9b\u5bfc\u822a \u6307\u4ee4 \u6765\u5e2e\u52a9\u4ed6\u5230\u8fbe\u76ee\u7684\u5730 destination \u3002

    \n\n

    \u6307\u4ee4 \u7528\u5b57\u7b26\u4e32\u8868\u793a\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5b57\u7b26\uff1a

    \n\n
      \n\t
    • 'H' \uff0c\u610f\u5473\u7740\u6c34\u5e73\u5411\u53f3\u79fb\u52a8
    • \n\t
    • 'V' \uff0c\u610f\u5473\u7740\u7ad6\u76f4\u5411\u4e0b\u79fb\u52a8
    • \n
    \n\n

    \u80fd\u591f\u4e3a Bob \u5bfc\u822a\u5230\u76ee\u7684\u5730 destination \u7684\u6307\u4ee4\u53ef\u4ee5\u6709\u591a\u79cd\uff0c\u4f8b\u5982\uff0c\u5982\u679c\u76ee\u7684\u5730 destination \u662f (2, 3)\uff0c\"HHHVV\" \u548c \"HVHVH\" \u90fd\u662f\u6709\u6548 \u6307\u4ee4 \u3002

    \n\n
      \n
    \n\n

    \u7136\u800c\uff0cBob \u5f88\u6311\u5254\u3002\u56e0\u4e3a\u4ed6\u7684\u5e78\u8fd0\u6570\u5b57\u662f k\uff0c\u4ed6\u60f3\u8981\u9075\u5faa \u6309\u5b57\u5178\u5e8f\u6392\u5217\u540e\u7684\u7b2c k \u6761\u6700\u5c0f\u6307\u4ee4 \u7684\u5bfc\u822a\u524d\u5f80\u76ee\u7684\u5730 destination \u3002k\u00a0 \u7684\u7f16\u53f7 \u4ece 1 \u5f00\u59cb \u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 destination \u548c\u4e00\u4e2a\u6574\u6570 k \uff0c\u8bf7\u4f60\u8fd4\u56de\u53ef\u4ee5\u4e3a Bob \u63d0\u4f9b\u524d\u5f80\u76ee\u7684\u5730\u00a0destination \u5bfc\u822a\u7684 \u6309\u5b57\u5178\u5e8f\u6392\u5217\u540e\u7684\u7b2c k \u6761\u6700\u5c0f\u6307\u4ee4 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1adestination = [2,3], k = 1\n\u8f93\u51fa\uff1a\"HHHVV\"\n\u89e3\u91ca\uff1a\u80fd\u524d\u5f80 (2, 3) \u7684\u6240\u6709\u5bfc\u822a\u6307\u4ee4 \u6309\u5b57\u5178\u5e8f\u6392\u5217\u540e \u5982\u4e0b\u6240\u793a\uff1a\n[\"HHHVV\", \"HHVHV\", \"HHVVH\", \"HVHHV\", \"HVHVH\", \"HVVHH\", \"VHHHV\", \"VHHVH\", \"VHVHH\", \"VVHHH\"].\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1adestination = [2,3], k = 2\n\u8f93\u51fa\uff1a\"HHVHV\"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1adestination = [2,3], k = 3\n\u8f93\u51fa\uff1a\"HHVVH\"\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • destination.length == 2
    • \n\t
    • 1 <= row, column <= 15
    • \n\t
    • 1 <= k <= nCr(row + column, row)\uff0c\u5176\u4e2d nCr(a, b) \u8868\u793a\u7ec4\u5408\u6570\uff0c\u5373\u4ece a \u4e2a\u7269\u54c1\u4e2d\u9009 b \u4e2a\u7269\u54c1\u7684\u4e0d\u540c\u65b9\u6848\u6570\u3002
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string kthSmallestPath(vector& destination, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String kthSmallestPath(int[] destination, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def kthSmallestPath(self, destination, k):\n \"\"\"\n :type destination: List[int]\n :type k: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def kthSmallestPath(self, destination: List[int], k: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * kthSmallestPath(int* destination, int destinationSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string KthSmallestPath(int[] destination, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} destination\n * @param {number} k\n * @return {string}\n */\nvar kthSmallestPath = function(destination, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} destination\n# @param {Integer} k\n# @return {String}\ndef kth_smallest_path(destination, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func kthSmallestPath(_ destination: [Int], _ k: Int) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func kthSmallestPath(destination []int, k int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def kthSmallestPath(destination: Array[Int], k: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun kthSmallestPath(destination: IntArray, k: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn kth_smallest_path(destination: Vec, k: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $destination\n * @param Integer $k\n * @return String\n */\n function kthSmallestPath($destination, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function kthSmallestPath(destination: number[], k: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (kth-smallest-path destination k)\n (-> (listof exact-integer?) exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[1643](https://leetcode-cn.com/problems/kth-smallest-instructions)", "[\u7b2c K \u6761\u6700\u5c0f\u6307\u4ee4](/solution/1600-1699/1643.Kth%20Smallest%20Instructions/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[1643](https://leetcode.com/problems/kth-smallest-instructions)", "[Kth Smallest Instructions](/solution/1600-1699/1643.Kth%20Smallest%20Instructions/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "0488", "frontend_question_id": "0488", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/zuma-game", "url_en": "https://leetcode.com/problems/zuma-game", "relative_path_cn": "/solution/0400-0499/0488.Zuma%20Game/README.md", "relative_path_en": "/solution/0400-0499/0488.Zuma%20Game/README_EN.md", "title_cn": "\u7956\u739b\u6e38\u620f", "title_en": "Zuma Game", "question_title_slug": "zuma-game", "content_en": "

    Think about Zuma Game. You have a row of balls on the table, colored red(R), yellow(Y), blue(B), green(G), and white(W). You also have several balls in your hand.

    \n\n

    Each time, you may choose a ball in your hand, and insert it into the row (including the leftmost place and rightmost place). Then, if there is a group of 3 or more balls in the same color touching, remove these balls. Keep doing this until no more balls can be removed.

    \n\n

    Find the minimal balls you have to insert to remove all the balls on the table. If you cannot remove all the balls, output -1.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: board = "WRRBBW", hand = "RB"\nOutput: -1\nExplanation: WRRBBW -> WRR[R]BBW -> WBBW -> WBB[B]W -> WW\n
    \n\n

    Example 2:

    \n\n
    \nInput: board = "WWRRBBWW", hand = "WRBRW"\nOutput: 2\nExplanation: WWRRBBWW -> WWRR[R]BBWW -> WWBBWW -> WWBB[B]WW -> WWWW -> empty\n
    \n\n

    Example 3:

    \n\n
    \nInput: board = "G", hand = "GGGGG"\nOutput: 2\nExplanation: G -> G[G] -> GG[G] -> empty \n
    \n\n

    Example 4:

    \n\n
    \nInput: board = "RBYYBBRRB", hand = "YRBGB"\nOutput: 3\nExplanation: RBYYBBRRB -> RBYY[Y]BBRRB -> RBBBRRB -> RRRB -> B -> B[B] -> BB[B] -> empty \n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • You may assume that the initial row of balls on the table won’t have any 3 or more consecutive balls with the same color.
    • \n\t
    • 1 <= board.length <= 16
    • \n\t
    • 1 <= hand.length <= 5
    • \n\t
    • Both input strings will be non-empty and only contain characters 'R','Y','B','G','W'.
    • \n
    \n", "content_cn": "

    \u56de\u5fc6\u4e00\u4e0b\u7956\u739b\u6e38\u620f\u3002\u73b0\u5728\u684c\u4e0a\u6709\u4e00\u4e32\u7403\uff0c\u989c\u8272\u6709\u7ea2\u8272(R)\uff0c\u9ec4\u8272(Y)\uff0c\u84dd\u8272(B)\uff0c\u7eff\u8272(G)\uff0c\u8fd8\u6709\u767d\u8272(W)\u3002 \u73b0\u5728\u4f60\u624b\u91cc\u4e5f\u6709\u51e0\u4e2a\u7403\u3002

    \n\n

    \u6bcf\u4e00\u6b21\uff0c\u4f60\u53ef\u4ee5\u4ece\u624b\u91cc\u7684\u7403\u9009\u4e00\u4e2a\uff0c\u7136\u540e\u628a\u8fd9\u4e2a\u7403\u63d2\u5165\u5230\u4e00\u4e32\u7403\u4e2d\u7684\u67d0\u4e2a\u4f4d\u7f6e\u4e0a\uff08\u5305\u62ec\u6700\u5de6\u7aef\uff0c\u6700\u53f3\u7aef\uff09\u3002\u63a5\u7740\uff0c\u5982\u679c\u6709\u51fa\u73b0\u4e09\u4e2a\u6216\u8005\u4e09\u4e2a\u4ee5\u4e0a\u989c\u8272\u76f8\u540c\u7684\u7403\u76f8\u8fde\u7684\u8bdd\uff0c\u5c31\u628a\u5b83\u4eec\u79fb\u9664\u6389\u3002\u91cd\u590d\u8fd9\u4e00\u6b65\u9aa4\u76f4\u5230\u684c\u4e0a\u6240\u6709\u7684\u7403\u90fd\u88ab\u79fb\u9664\u3002

    \n\n

    \u627e\u5230\u63d2\u5165\u5e76\u53ef\u4ee5\u79fb\u9664\u6389\u684c\u4e0a\u6240\u6709\u7403\u6240\u9700\u7684\u6700\u5c11\u7684\u7403\u6570\u3002\u5982\u679c\u4e0d\u80fd\u79fb\u9664\u684c\u4e0a\u6240\u6709\u7684\u7403\uff0c\u8f93\u51fa -1 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aboard = \"WRRBBW\", hand = \"RB\"\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1aWRRBBW -> WRR[R]BBW -> WBBW -> WBB[B]W -> WW\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aboard = \"WWRRBBWW\", hand = \"WRBRW\"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1aWWRRBBWW -> WWRR[R]BBWW -> WWBBWW -> WWBB[B]WW -> WWWW -> empty\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aboard = \"G\", hand = \"GGGGG\"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1aG -> G[G] -> GG[G] -> empty \n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1aboard = \"RBYYBBRRB\", hand = \"YRBGB\"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1aRBYYBBRRB -> RBYY[Y]BBRRB -> RBBBRRB -> RRRB -> B -> B[B] -> BB[B] -> empty \n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u4f60\u53ef\u4ee5\u5047\u8bbe\u684c\u4e0a\u4e00\u5f00\u59cb\u7684\u7403\u4e2d\uff0c\u4e0d\u4f1a\u6709\u4e09\u4e2a\u53ca\u4e09\u4e2a\u4ee5\u4e0a\u989c\u8272\u76f8\u540c\u4e14\u8fde\u7740\u7684\u7403\u3002
    • \n\t
    • 1 <= board.length <= 16
    • \n\t
    • 1 <= hand.length <= 5
    • \n\t
    • \u8f93\u5165\u7684\u4e24\u4e2a\u5b57\u7b26\u4e32\u5747\u4e3a\u975e\u7a7a\u5b57\u7b26\u4e32\uff0c\u4e14\u53ea\u5305\u542b\u5b57\u7b26 'R','Y','B','G','W'\u3002
    • \n
    \n", "tags_en": ["Depth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findMinStep(string board, string hand) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findMinStep(String board, String hand) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findMinStep(self, board, hand):\n \"\"\"\n :type board: str\n :type hand: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findMinStep(self, board: str, hand: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findMinStep(char * board, char * hand){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindMinStep(string board, string hand) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} board\n * @param {string} hand\n * @return {number}\n */\nvar findMinStep = function(board, hand) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} board\n# @param {String} hand\n# @return {Integer}\ndef find_min_step(board, hand)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findMinStep(_ board: String, _ hand: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findMinStep(board string, hand string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findMinStep(board: String, hand: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findMinStep(board: String, hand: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_min_step(board: String, hand: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $board\n * @param String $hand\n * @return Integer\n */\n function findMinStep($board, $hand) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findMinStep(board: string, hand: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-min-step board hand)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0488](https://leetcode-cn.com/problems/zuma-game)", "[\u7956\u739b\u6e38\u620f](/solution/0400-0499/0488.Zuma%20Game/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[0488](https://leetcode.com/problems/zuma-game)", "[Zuma Game](/solution/0400-0499/0488.Zuma%20Game/README_EN.md)", "`Depth-first Search`", "Hard", ""]}, {"question_id": "0487", "frontend_question_id": "0487", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/max-consecutive-ones-ii", "url_en": "https://leetcode.com/problems/max-consecutive-ones-ii", "relative_path_cn": "/solution/0400-0499/0487.Max%20Consecutive%20Ones%20II/README.md", "relative_path_en": "/solution/0400-0499/0487.Max%20Consecutive%20Ones%20II/README_EN.md", "title_cn": "\u6700\u5927\u8fde\u7eed1\u7684\u4e2a\u6570 II", "title_en": "Max Consecutive Ones II", "question_title_slug": "max-consecutive-ones-ii", "content_en": "

    Given a binary array nums, return the maximum number of consecutive 1's in the array if you can flip at most one 0.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,0,1,1,0]\nOutput: 4\nExplanation: Flip the first zero will get the maximum number of consecutive 1s. After flipping, the maximum number of consecutive 1s is 4.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,0,1,1,0,1]\nOutput: 4\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • nums[i] is either 0 or 1.
    • \n
    \n\n

     

    \n

    Follow up: What if the input numbers come in one by one as an infinite stream? In other words, you can't store all numbers coming from the stream as it's too large to hold in memory. Could you solve it efficiently?

    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u8fdb\u5236\u6570\u7ec4\uff0c\u4f60\u53ef\u4ee5\u6700\u591a\u5c06 1 \u4e2a 0 \u7ffb\u8f6c\u4e3a 1\uff0c\u627e\u51fa\u5176\u4e2d\u6700\u5927\u8fde\u7eed 1 \u7684\u4e2a\u6570\u3002

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a[1,0,1,1,0]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u7ffb\u8f6c\u7b2c\u4e00\u4e2a 0 \u53ef\u4ee5\u5f97\u5230\u6700\u957f\u7684\u8fde\u7eed 1\u3002\n     \u5f53\u7ffb\u8f6c\u4ee5\u540e\uff0c\u6700\u5927\u8fde\u7eed 1 \u7684\u4e2a\u6570\u4e3a 4\u3002\n
    \n\n

     

    \n\n

    \u6ce8\uff1a

    \n\n
      \n\t
    • \u8f93\u5165\u6570\u7ec4\u53ea\u5305\u542b 0 \u548c 1.
    • \n\t
    • \u8f93\u5165\u6570\u7ec4\u7684\u957f\u5ea6\u4e3a\u6b63\u6574\u6570\uff0c\u4e14\u4e0d\u8d85\u8fc7 10,000
    • \n
    \n\n

     

    \n\n

    \u8fdb\u9636\uff1a
    \n\u5982\u679c\u8f93\u5165\u7684\u6570\u5b57\u662f\u4f5c\u4e3a \u65e0\u9650\u6d41 \u9010\u4e2a\u8f93\u5165\u5982\u4f55\u5904\u7406\uff1f\u6362\u53e5\u8bdd\u8bf4\uff0c\u5185\u5b58\u4e0d\u80fd\u5b58\u50a8\u4e0b\u6240\u6709\u4ece\u6d41\u4e2d\u8f93\u5165\u7684\u6570\u5b57\u3002\u60a8\u53ef\u4ee5\u6709\u6548\u5730\u89e3\u51b3\u5417\uff1f

    \n", "tags_en": ["Two Pointers"], "tags_cn": ["\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findMaxConsecutiveOnes(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findMaxConsecutiveOnes(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findMaxConsecutiveOnes(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findMaxConsecutiveOnes(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindMaxConsecutiveOnes(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar findMaxConsecutiveOnes = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef find_max_consecutive_ones(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findMaxConsecutiveOnes(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findMaxConsecutiveOnes(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findMaxConsecutiveOnes(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findMaxConsecutiveOnes(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_max_consecutive_ones(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function findMaxConsecutiveOnes($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findMaxConsecutiveOnes(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-max-consecutive-ones nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0487](https://leetcode-cn.com/problems/max-consecutive-ones-ii)", "[\u6700\u5927\u8fde\u7eed1\u7684\u4e2a\u6570 II](/solution/0400-0499/0487.Max%20Consecutive%20Ones%20II/README.md)", "`\u53cc\u6307\u9488`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0487](https://leetcode.com/problems/max-consecutive-ones-ii)", "[Max Consecutive Ones II](/solution/0400-0499/0487.Max%20Consecutive%20Ones%20II/README_EN.md)", "`Two Pointers`", "Medium", "\ud83d\udd12"]}, {"question_id": "0486", "frontend_question_id": "0486", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/predict-the-winner", "url_en": "https://leetcode.com/problems/predict-the-winner", "relative_path_cn": "/solution/0400-0499/0486.Predict%20the%20Winner/README.md", "relative_path_en": "/solution/0400-0499/0486.Predict%20the%20Winner/README_EN.md", "title_cn": "\u9884\u6d4b\u8d62\u5bb6", "title_en": "Predict the Winner", "question_title_slug": "predict-the-winner", "content_en": "

    You are given an integer array nums. Two players are playing a game with this array: player 1 and player 2.

    \n\n

    Player 1 and player 2 take turns, with player 1 starting first. Both players start the game with a score of 0. At each turn, the player takes one of the numbers from either end of the array (i.e., nums[0] or nums[nums.length - 1]) which reduces the size of the array by 1. The player adds the chosen number to their score. The game ends when there are no more elements in the array.

    \n\n

    Return true if Player 1 can win the game. If the scores of both players are equal, then player 1 is still the winner, and you should also return true. You may assume that both players are playing optimally.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,5,2]\nOutput: false\nExplanation: Initially, player 1 can choose between 1 and 2. \nIf he chooses 2 (or 1), then player 2 can choose from 1 (or 2) and 5. If player 2 chooses 5, then player 1 will be left with 1 (or 2). \nSo, final score of player 1 is 1 + 2 = 3, and player 2 is 5. \nHence, player 1 will never be the winner and you need to return false.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,5,233,7]\nOutput: true\nExplanation: Player 1 first chooses 1. Then player 2 has to choose between 5 and 7. No matter which number player 2 choose, player 1 can choose 233.\nFinally, player 1 has more score (234) than player 2 (12), so you need to return True representing player1 can win.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 20
    • \n\t
    • 0 <= nums[i] <= 107
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u8868\u793a\u5206\u6570\u7684\u975e\u8d1f\u6574\u6570\u6570\u7ec4\u3002 \u73a9\u5bb6 1 \u4ece\u6570\u7ec4\u4efb\u610f\u4e00\u7aef\u62ff\u53d6\u4e00\u4e2a\u5206\u6570\uff0c\u968f\u540e\u73a9\u5bb6 2 \u7ee7\u7eed\u4ece\u5269\u4f59\u6570\u7ec4\u4efb\u610f\u4e00\u7aef\u62ff\u53d6\u5206\u6570\uff0c\u7136\u540e\u73a9\u5bb6 1 \u62ff\uff0c…… \u3002\u6bcf\u6b21\u4e00\u4e2a\u73a9\u5bb6\u53ea\u80fd\u62ff\u53d6\u4e00\u4e2a\u5206\u6570\uff0c\u5206\u6570\u88ab\u62ff\u53d6\u4e4b\u540e\u4e0d\u518d\u53ef\u53d6\u3002\u76f4\u5230\u6ca1\u6709\u5269\u4f59\u5206\u6570\u53ef\u53d6\u65f6\u6e38\u620f\u7ed3\u675f\u3002\u6700\u7ec8\u83b7\u5f97\u5206\u6570\u603b\u548c\u6700\u591a\u7684\u73a9\u5bb6\u83b7\u80dc\u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u8868\u793a\u5206\u6570\u7684\u6570\u7ec4\uff0c\u9884\u6d4b\u73a9\u5bb61\u662f\u5426\u4f1a\u6210\u4e3a\u8d62\u5bb6\u3002\u4f60\u53ef\u4ee5\u5047\u8bbe\u6bcf\u4e2a\u73a9\u5bb6\u7684\u73a9\u6cd5\u90fd\u4f1a\u4f7f\u4ed6\u7684\u5206\u6570\u6700\u5927\u5316\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a[1, 5, 2]\n\u8f93\u51fa\uff1aFalse\n\u89e3\u91ca\uff1a\u4e00\u5f00\u59cb\uff0c\u73a9\u5bb61\u53ef\u4ee5\u4ece1\u548c2\u4e2d\u8fdb\u884c\u9009\u62e9\u3002\n\u5982\u679c\u4ed6\u9009\u62e9 2\uff08\u6216\u8005 1 \uff09\uff0c\u90a3\u4e48\u73a9\u5bb6 2 \u53ef\u4ee5\u4ece 1\uff08\u6216\u8005 2 \uff09\u548c 5 \u4e2d\u8fdb\u884c\u9009\u62e9\u3002\u5982\u679c\u73a9\u5bb6 2 \u9009\u62e9\u4e86 5 \uff0c\u90a3\u4e48\u73a9\u5bb6 1 \u5219\u53ea\u5269\u4e0b 1\uff08\u6216\u8005 2 \uff09\u53ef\u9009\u3002\n\u6240\u4ee5\uff0c\u73a9\u5bb6 1 \u7684\u6700\u7ec8\u5206\u6570\u4e3a 1 + 2 = 3\uff0c\u800c\u73a9\u5bb6 2 \u4e3a 5 \u3002\n\u56e0\u6b64\uff0c\u73a9\u5bb6 1 \u6c38\u8fdc\u4e0d\u4f1a\u6210\u4e3a\u8d62\u5bb6\uff0c\u8fd4\u56de False \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a[1, 5, 233, 7]\n\u8f93\u51fa\uff1aTrue\n\u89e3\u91ca\uff1a\u73a9\u5bb6 1 \u4e00\u5f00\u59cb\u9009\u62e9 1 \u3002\u7136\u540e\u73a9\u5bb6 2 \u5fc5\u987b\u4ece 5 \u548c 7 \u4e2d\u8fdb\u884c\u9009\u62e9\u3002\u65e0\u8bba\u73a9\u5bb6 2 \u9009\u62e9\u4e86\u54ea\u4e2a\uff0c\u73a9\u5bb6 1 \u90fd\u53ef\u4ee5\u9009\u62e9 233 \u3002\n     \u6700\u7ec8\uff0c\u73a9\u5bb6 1\uff08234 \u5206\uff09\u6bd4\u73a9\u5bb6 2\uff0812 \u5206\uff09\u83b7\u5f97\u66f4\u591a\u7684\u5206\u6570\uff0c\u6240\u4ee5\u8fd4\u56de True\uff0c\u8868\u793a\u73a9\u5bb6 1 \u53ef\u4ee5\u6210\u4e3a\u8d62\u5bb6\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= \u7ed9\u5b9a\u7684\u6570\u7ec4\u957f\u5ea6 <= 20.
    • \n\t
    • \u6570\u7ec4\u91cc\u6240\u6709\u5206\u6570\u90fd\u4e3a\u975e\u8d1f\u6570\u4e14\u4e0d\u4f1a\u5927\u4e8e 10000000 \u3002
    • \n\t
    • \u5982\u679c\u6700\u7ec8\u4e24\u4e2a\u73a9\u5bb6\u7684\u5206\u6570\u76f8\u7b49\uff0c\u90a3\u4e48\u73a9\u5bb6 1 \u4ecd\u4e3a\u8d62\u5bb6\u3002
    • \n
    \n", "tags_en": ["Minimax", "Dynamic Programming"], "tags_cn": ["\u6781\u5c0f\u5316\u6781\u5927", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool PredictTheWinner(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean PredictTheWinner(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def PredictTheWinner(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def PredictTheWinner(self, nums: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool PredictTheWinner(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool PredictTheWinner(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {boolean}\n */\nvar PredictTheWinner = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Boolean}\ndef predict_the_winner(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func PredictTheWinner(_ nums: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func PredictTheWinner(nums []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def PredictTheWinner(nums: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun PredictTheWinner(nums: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn predict_the_winner(nums: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Boolean\n */\n function PredictTheWinner($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function PredictTheWinner(nums: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (predict-the-winner nums)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0486](https://leetcode-cn.com/problems/predict-the-winner)", "[\u9884\u6d4b\u8d62\u5bb6](/solution/0400-0499/0486.Predict%20the%20Winner/README.md)", "`\u6781\u5c0f\u5316\u6781\u5927`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0486](https://leetcode.com/problems/predict-the-winner)", "[Predict the Winner](/solution/0400-0499/0486.Predict%20the%20Winner/README_EN.md)", "`Minimax`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0485", "frontend_question_id": "0485", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/max-consecutive-ones", "url_en": "https://leetcode.com/problems/max-consecutive-ones", "relative_path_cn": "/solution/0400-0499/0485.Max%20Consecutive%20Ones/README.md", "relative_path_en": "/solution/0400-0499/0485.Max%20Consecutive%20Ones/README_EN.md", "title_cn": "\u6700\u5927\u8fde\u7eed 1 \u7684\u4e2a\u6570", "title_en": "Max Consecutive Ones", "question_title_slug": "max-consecutive-ones", "content_en": "

    Given a binary array nums, return the maximum number of consecutive 1's in the array.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,1,0,1,1,1]\nOutput: 3\nExplanation: The first two digits or the last three digits are consecutive 1s. The maximum number of consecutive 1s is 3.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,0,1,1,0,1]\nOutput: 2\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • nums[i] is either 0 or 1.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u8fdb\u5236\u6570\u7ec4\uff0c \u8ba1\u7b97\u5176\u4e2d\u6700\u5927\u8fde\u7eed 1 \u7684\u4e2a\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[1,1,0,1,1,1]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u5f00\u5934\u7684\u4e24\u4f4d\u548c\u6700\u540e\u7684\u4e09\u4f4d\u90fd\u662f\u8fde\u7eed 1 \uff0c\u6240\u4ee5\u6700\u5927\u8fde\u7eed 1 \u7684\u4e2a\u6570\u662f 3.\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u8f93\u5165\u7684\u6570\u7ec4\u53ea\u5305\u542b\u00a00 \u548c 1 \u3002
    • \n\t
    • \u8f93\u5165\u6570\u7ec4\u7684\u957f\u5ea6\u662f\u6b63\u6574\u6570\uff0c\u4e14\u4e0d\u8d85\u8fc7 10,000\u3002
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findMaxConsecutiveOnes(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findMaxConsecutiveOnes(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findMaxConsecutiveOnes(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findMaxConsecutiveOnes(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindMaxConsecutiveOnes(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar findMaxConsecutiveOnes = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef find_max_consecutive_ones(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findMaxConsecutiveOnes(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findMaxConsecutiveOnes(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findMaxConsecutiveOnes(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findMaxConsecutiveOnes(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_max_consecutive_ones(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function findMaxConsecutiveOnes($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findMaxConsecutiveOnes(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-max-consecutive-ones nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0485](https://leetcode-cn.com/problems/max-consecutive-ones)", "[\u6700\u5927\u8fde\u7eed 1 \u7684\u4e2a\u6570](/solution/0400-0499/0485.Max%20Consecutive%20Ones/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0485](https://leetcode.com/problems/max-consecutive-ones)", "[Max Consecutive Ones](/solution/0400-0499/0485.Max%20Consecutive%20Ones/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0484", "frontend_question_id": "0484", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/find-permutation", "url_en": "https://leetcode.com/problems/find-permutation", "relative_path_cn": "/solution/0400-0499/0484.Find%20Permutation/README.md", "relative_path_en": "/solution/0400-0499/0484.Find%20Permutation/README_EN.md", "title_cn": "\u5bfb\u627e\u6392\u5217", "title_en": "Find Permutation", "question_title_slug": "find-permutation", "content_en": "

    A permutation perm of n integers of all the integers in the range [1, n] can be represented as a string s of length n - 1 where:

    \n\n
      \n\t
    • s[i] == 'I' if perm[i] < perm[i + 1], and
    • \n\t
    • s[i] == 'D' if perm[i] > perm[i + 1].
    • \n
    \n\n

    Given a string s, reconstruct the lexicographically smallest permutation perm and return it.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "I"\nOutput: [1,2]\nExplanation: [1,2] is the only legal permutation that can represented by s, where the number 1 and 2 construct an increasing relationship.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "DI"\nOutput: [2,1,3]\nExplanation: Both [2,1,3] and [3,1,2] can be represented as "DI", but since we want to find the smallest lexicographical permutation, you should return [2,1,3]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 105
    • \n\t
    • s[i] is either 'I' or 'D'.
    • \n
    \n", "content_cn": "

    \u73b0\u5728\u7ed9\u5b9a\u4e00\u4e2a\u53ea\u7531\u5b57\u7b26 'D' \u548c 'I' \u7ec4\u6210\u7684 \u79d8\u5bc6\u7b7e\u540d\u3002'D' \u8868\u793a\u4e24\u4e2a\u6570\u5b57\u95f4\u7684\u9012\u51cf\u5173\u7cfb\uff0c'I' \u8868\u793a\u4e24\u4e2a\u6570\u5b57\u95f4\u7684\u9012\u589e\u5173\u7cfb\u3002\u5e76\u4e14 \u79d8\u5bc6\u7b7e\u540d \u662f\u7531\u4e00\u4e2a\u7279\u5b9a\u7684\u6574\u6570\u6570\u7ec4\u751f\u6210\u7684\uff0c\u8be5\u6570\u7ec4\u552f\u4e00\u5730\u5305\u542b 1 \u5230 n \u4e2d\u6240\u6709\u4e0d\u540c\u7684\u6570\u5b57\uff08\u79d8\u5bc6\u7b7e\u540d\u7684\u957f\u5ea6\u52a0 1 \u7b49\u4e8e n\uff09\u3002\u4f8b\u5982\uff0c\u79d8\u5bc6\u7b7e\u540d "DI" \u53ef\u4ee5\u7531\u6570\u7ec4 [2,1,3] \u6216 [3,1,2] \u751f\u6210\uff0c\u4f46\u662f\u4e0d\u80fd\u7531\u6570\u7ec4 [3,2,4] \u6216 [2,1,3,4] \u751f\u6210\uff0c\u56e0\u4e3a\u5b83\u4eec\u90fd\u4e0d\u662f\u5408\u6cd5\u7684\u80fd\u4ee3\u8868 "DI" \u79d8\u5bc6\u7b7e\u540d \u7684\u7279\u5b9a\u4e32\u3002

    \n\n

    \u73b0\u5728\u4f60\u7684\u4efb\u52a1\u662f\u627e\u5230\u5177\u6709\u6700\u5c0f\u5b57\u5178\u5e8f\u7684 [1, 2, ... n] \u7684\u6392\u5217\uff0c\u4f7f\u5176\u80fd\u4ee3\u8868\u8f93\u5165\u7684 \u79d8\u5bc6\u7b7e\u540d\u3002

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a "I"\n\u8f93\u51fa\uff1a [1,2]\n\u89e3\u91ca\uff1a [1,2] \u662f\u552f\u4e00\u5408\u6cd5\u7684\u53ef\u4ee5\u751f\u6210\u79d8\u5bc6\u7b7e\u540d "I" \u7684\u7279\u5b9a\u4e32\uff0c\u6570\u5b57 1 \u548c 2 \u6784\u6210\u9012\u589e\u5173\u7cfb\u3002\n
    \n\n

     

    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a "DI"\n\u8f93\u51fa\uff1a [2,1,3]\n\u89e3\u91ca\uff1a [2,1,3] \u548c [3,1,2] \u53ef\u4ee5\u751f\u6210\u79d8\u5bc6\u7b7e\u540d "DI"\uff0c\n\u4f46\u662f\u7531\u4e8e\u6211\u4eec\u8981\u627e\u5b57\u5178\u5e8f\u6700\u5c0f\u7684\u6392\u5217\uff0c\u56e0\u6b64\u4f60\u9700\u8981\u8f93\u51fa [2,1,3]\u3002\n
    \n\n

     

    \n\n

    \u6ce8\uff1a

    \n\n
      \n\t
    • \u8f93\u51fa\u5b57\u7b26\u4e32\u53ea\u4f1a\u5305\u542b\u5b57\u7b26 'D' \u548c 'I'\u3002
    • \n\t
    • \u8f93\u5165\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u662f\u4e00\u4e2a\u6b63\u6574\u6570\u4e14\u4e0d\u4f1a\u8d85\u8fc7 10,000\u3002
    • \n
    \n\n

     

    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findPermutation(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] findPermutation(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findPermutation(self, s):\n \"\"\"\n :type s: str\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findPermutation(self, s: str) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* findPermutation(char * s, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] FindPermutation(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number[]}\n */\nvar findPermutation = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer[]}\ndef find_permutation(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findPermutation(_ s: String) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findPermutation(s string) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findPermutation(s: String): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findPermutation(s: String): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_permutation(s: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer[]\n */\n function findPermutation($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findPermutation(s: string): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-permutation s)\n (-> string? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0484](https://leetcode-cn.com/problems/find-permutation)", "[\u5bfb\u627e\u6392\u5217](/solution/0400-0499/0484.Find%20Permutation/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0484](https://leetcode.com/problems/find-permutation)", "[Find Permutation](/solution/0400-0499/0484.Find%20Permutation/README_EN.md)", "`Greedy`", "Medium", "\ud83d\udd12"]}, {"question_id": "0483", "frontend_question_id": "0483", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/smallest-good-base", "url_en": "https://leetcode.com/problems/smallest-good-base", "relative_path_cn": "/solution/0400-0499/0483.Smallest%20Good%20Base/README.md", "relative_path_en": "/solution/0400-0499/0483.Smallest%20Good%20Base/README_EN.md", "title_cn": "\u6700\u5c0f\u597d\u8fdb\u5236", "title_en": "Smallest Good Base", "question_title_slug": "smallest-good-base", "content_en": "

    Given an integer n represented as a string, return the smallest good base of n.

    \n\n

    We call k >= 2 a good base of n, if all digits of n base k are 1's.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = "13"\nOutput: "3"\nExplanation: 13 base 3 is 111.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = "4681"\nOutput: "8"\nExplanation: 4681 base 8 is 11111.\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = "1000000000000000000"\nOutput: "999999999999999999"\nExplanation: 1000000000000000000 base 999999999999999999 is 11.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n is an integer in the range [3, 1018].
    • \n\t
    • n does not contain any leading zeros.
    • \n
    \n", "content_cn": "

    \u5bf9\u4e8e\u7ed9\u5b9a\u7684\u6574\u6570 n, \u5982\u679cn\u7684k\uff08k>=2\uff09\u8fdb\u5236\u6570\u7684\u6240\u6709\u6570\u4f4d\u5168\u4e3a1\uff0c\u5219\u79f0 k\uff08k>=2\uff09\u662f n \u7684\u4e00\u4e2a\u597d\u8fdb\u5236\u3002

    \n\n

    \u4ee5\u5b57\u7b26\u4e32\u7684\u5f62\u5f0f\u7ed9\u51fa n, \u4ee5\u5b57\u7b26\u4e32\u7684\u5f62\u5f0f\u8fd4\u56de n \u7684\u6700\u5c0f\u597d\u8fdb\u5236\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1a"13"\n\u8f93\u51fa\uff1a"3"\n\u89e3\u91ca\uff1a13 \u7684 3 \u8fdb\u5236\u662f 111\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1a"4681"\n\u8f93\u51fa\uff1a"8"\n\u89e3\u91ca\uff1a4681 \u7684 8 \u8fdb\u5236\u662f 11111\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1a"1000000000000000000"\n\u8f93\u51fa\uff1a"999999999999999999"\n\u89e3\u91ca\uff1a1000000000000000000 \u7684 999999999999999999 \u8fdb\u5236\u662f 11\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. n\u7684\u53d6\u503c\u8303\u56f4\u662f [3, 10^18]\u3002
    2. \n\t
    3. \u8f93\u5165\u603b\u662f\u6709\u6548\u4e14\u6ca1\u6709\u524d\u5bfc 0\u3002
    4. \n
    \n\n

     

    \n", "tags_en": ["Math", "Binary Search"], "tags_cn": ["\u6570\u5b66", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string smallestGoodBase(string n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String smallestGoodBase(String n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def smallestGoodBase(self, n):\n \"\"\"\n :type n: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def smallestGoodBase(self, n: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * smallestGoodBase(char * n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string SmallestGoodBase(string n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} n\n * @return {string}\n */\nvar smallestGoodBase = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} n\n# @return {String}\ndef smallest_good_base(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func smallestGoodBase(_ n: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func smallestGoodBase(n string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def smallestGoodBase(n: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun smallestGoodBase(n: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn smallest_good_base(n: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $n\n * @return String\n */\n function smallestGoodBase($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function smallestGoodBase(n: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (smallest-good-base n)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0483](https://leetcode-cn.com/problems/smallest-good-base)", "[\u6700\u5c0f\u597d\u8fdb\u5236](/solution/0400-0499/0483.Smallest%20Good%20Base/README.md)", "`\u6570\u5b66`,`\u4e8c\u5206\u67e5\u627e`", "\u56f0\u96be", ""], "md_table_row_en": ["[0483](https://leetcode.com/problems/smallest-good-base)", "[Smallest Good Base](/solution/0400-0499/0483.Smallest%20Good%20Base/README_EN.md)", "`Math`,`Binary Search`", "Hard", ""]}, {"question_id": "0482", "frontend_question_id": "0482", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/license-key-formatting", "url_en": "https://leetcode.com/problems/license-key-formatting", "relative_path_cn": "/solution/0400-0499/0482.License%20Key%20Formatting/README.md", "relative_path_en": "/solution/0400-0499/0482.License%20Key%20Formatting/README_EN.md", "title_cn": "\u5bc6\u94a5\u683c\u5f0f\u5316", "title_en": "License Key Formatting", "question_title_slug": "license-key-formatting", "content_en": "

    You are given a license key represented as a string s that consists of only alphanumeric characters and dashes. The string is separated into n + 1 groups by n dashes. You are also given an integer k.

    \n\n

    We want to reformat the string s such that each group contains exactly k characters, except for the first group, which could be shorter than k but still must contain at least one character. Furthermore, there must be a dash inserted between two groups, and you should convert all lowercase letters to uppercase.

    \n\n

    Return the reformatted license key.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "5F3Z-2e-9-w", k = 4\nOutput: "5F3Z-2E9W"\nExplanation: The string s has been split into two parts, each part has 4 characters.\nNote that the two extra dashes are not needed and can be removed.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "2-5g-3-J", k = 2\nOutput: "2-5G-3J"\nExplanation: The string s has been split into three parts, each part has 2 characters except the first part as it could be shorter as mentioned above.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 105
    • \n\t
    • s consists of English letters, digits, and dashes '-'.
    • \n\t
    • 1 <= k <= 104
    • \n
    \n", "content_cn": "

    \u6709\u4e00\u4e2a\u5bc6\u94a5\u5b57\u7b26\u4e32 S \uff0c\u53ea\u5305\u542b\u5b57\u6bcd\uff0c\u6570\u5b57\u4ee5\u53ca '-'\uff08\u7834\u6298\u53f7\uff09\u3002\u5176\u4e2d\uff0c N \u4e2a '-' \u5c06\u5b57\u7b26\u4e32\u5206\u6210\u4e86 N+1 \u7ec4\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6570\u5b57 K\uff0c\u8bf7\u4f60\u91cd\u65b0\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\uff0c\u4f7f\u6bcf\u4e2a\u5206\u7ec4\u6070\u597d\u5305\u542b K \u4e2a\u5b57\u7b26\u3002\u7279\u522b\u5730\uff0c\u7b2c\u4e00\u4e2a\u5206\u7ec4\u5305\u542b\u7684\u5b57\u7b26\u4e2a\u6570\u5fc5\u987b\u5c0f\u4e8e\u7b49\u4e8e K\uff0c\u4f46\u81f3\u5c11\u8981\u5305\u542b 1 \u4e2a\u5b57\u7b26\u3002\u4e24\u4e2a\u5206\u7ec4\u4e4b\u95f4\u9700\u8981\u7528 '-'\uff08\u7834\u6298\u53f7\uff09\u9694\u5f00\uff0c\u5e76\u4e14\u5c06\u6240\u6709\u7684\u5c0f\u5199\u5b57\u6bcd\u8f6c\u6362\u4e3a\u5927\u5199\u5b57\u6bcd\u3002

    \n\n

    \u7ed9\u5b9a\u975e\u7a7a\u5b57\u7b26\u4e32 S \u548c\u6570\u5b57 K\uff0c\u6309\u7167\u4e0a\u9762\u63cf\u8ff0\u7684\u89c4\u5219\u8fdb\u884c\u683c\u5f0f\u5316\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aS = "5F3Z-2e-9-w", K = 4\n\u8f93\u51fa\uff1a"5F3Z-2E9W"\n\u89e3\u91ca\uff1a\u5b57\u7b26\u4e32 S \u88ab\u5206\u6210\u4e86\u4e24\u4e2a\u90e8\u5206\uff0c\u6bcf\u90e8\u5206 4 \u4e2a\u5b57\u7b26\uff1b\n     \u6ce8\u610f\uff0c\u4e24\u4e2a\u989d\u5916\u7684\u7834\u6298\u53f7\u9700\u8981\u5220\u6389\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aS = "2-5g-3-J", K = 2\n\u8f93\u51fa\uff1a"2-5G-3J"\n\u89e3\u91ca\uff1a\u5b57\u7b26\u4e32 S \u88ab\u5206\u6210\u4e86 3 \u4e2a\u90e8\u5206\uff0c\u6309\u7167\u524d\u9762\u7684\u89c4\u5219\u63cf\u8ff0\uff0c\u7b2c\u4e00\u90e8\u5206\u7684\u5b57\u7b26\u53ef\u4ee5\u5c11\u4e8e\u7ed9\u5b9a\u7684\u6570\u91cf\uff0c\u5176\u4f59\u90e8\u5206\u7686\u4e3a 2 \u4e2a\u5b57\u7b26\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a:

    \n\n
      \n\t
    1. S \u7684\u957f\u5ea6\u53ef\u80fd\u5f88\u957f\uff0c\u8bf7\u6309\u9700\u5206\u914d\u5927\u5c0f\u3002K \u4e3a\u6b63\u6574\u6570\u3002
    2. \n\t
    3. S \u53ea\u5305\u542b\u5b57\u6bcd\u6570\u5b57\uff08a-z\uff0cA-Z\uff0c0-9\uff09\u4ee5\u53ca\u7834\u6298\u53f7'-'
    4. \n\t
    5. S \u975e\u7a7a
    6. \n
    \n\n

     

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string licenseKeyFormatting(string s, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String licenseKeyFormatting(String s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def licenseKeyFormatting(self, s, k):\n \"\"\"\n :type s: str\n :type k: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def licenseKeyFormatting(self, s: str, k: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * licenseKeyFormatting(char * s, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string LicenseKeyFormatting(string s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number} k\n * @return {string}\n */\nvar licenseKeyFormatting = function(s, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer} k\n# @return {String}\ndef license_key_formatting(s, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func licenseKeyFormatting(_ s: String, _ k: Int) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func licenseKeyFormatting(s string, k int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def licenseKeyFormatting(s: String, k: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun licenseKeyFormatting(s: String, k: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn license_key_formatting(s: String, k: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer $k\n * @return String\n */\n function licenseKeyFormatting($s, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function licenseKeyFormatting(s: string, k: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (license-key-formatting s k)\n (-> string? exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0482](https://leetcode-cn.com/problems/license-key-formatting)", "[\u5bc6\u94a5\u683c\u5f0f\u5316](/solution/0400-0499/0482.License%20Key%20Formatting/README.md)", "", "\u7b80\u5355", ""], "md_table_row_en": ["[0482](https://leetcode.com/problems/license-key-formatting)", "[License Key Formatting](/solution/0400-0499/0482.License%20Key%20Formatting/README_EN.md)", "", "Easy", ""]}, {"question_id": "0481", "frontend_question_id": "0481", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/magical-string", "url_en": "https://leetcode.com/problems/magical-string", "relative_path_cn": "/solution/0400-0499/0481.Magical%20String/README.md", "relative_path_en": "/solution/0400-0499/0481.Magical%20String/README_EN.md", "title_cn": "\u795e\u5947\u5b57\u7b26\u4e32", "title_en": "Magical String", "question_title_slug": "magical-string", "content_en": "

    A magical string s consists of only '1' and '2' and obeys the following rules:

    \n\n
      \n\t
    • The string s is magical because concatenating the number of contiguous occurrences of characters '1' and '2' generates the string s itself.
    • \n
    \n\n

    The first few elements of s is s = "1221121221221121122……". If we group the consecutive 1's and 2's in s, it will be "1 22 11 2 1 22 1 22 11 2 11 22 ......" and the occurrences of 1's or 2's in each group are "1 2 2 1 1 2 1 2 2 1 2 2 ......". You can see that the occurrence sequence is s itself.

    \n\n

    Given an integer n, return the number of 1's in the first n number in the magical string s.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 6\nOutput: 3\nExplanation: The first 6 elements of magical string s is "12211" and it contains three 1's, so return 3.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 1\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 105
    • \n
    \n", "content_cn": "

    \u795e\u5947\u7684\u5b57\u7b26\u4e32 \u53ea\u5305\u542b '1' \u548c '2'\uff0c\u5e76\u9075\u5b88\u4ee5\u4e0b\u89c4\u5219\uff1a

    \n\n

    \u5b57\u7b26\u4e32 S \u662f\u795e\u5947\u7684\uff0c\u56e0\u4e3a\u4e32\u8054\u5b57\u7b26 '1' \u548c '2' \u7684\u8fde\u7eed\u51fa\u73b0\u6b21\u6570\u4f1a\u751f\u6210\u5b57\u7b26\u4e32 S \u672c\u8eab\u3002

    \n\n

    \u5b57\u7b26\u4e32 \u7684\u524d\u51e0\u4e2a\u5143\u7d20\u5982\u4e0b\uff1aS = “1221121221221121122 ......”

    \n\n

    \u5982\u679c\u6211\u4eec\u5c06 S \u4e2d\u8fde\u7eed\u7684 1 \u548c 2 \u8fdb\u884c\u5206\u7ec4\uff0c\u5b83\u5c06\u53d8\u6210\uff1a

    \n\n

    1 22 11 2 1 22 1 22 11 2 11 22 ......

    \n\n

    \u5e76\u4e14\u6bcf\u4e2a\u7ec4\u4e2d '1' \u6216 '2' \u7684\u51fa\u73b0\u6b21\u6570\u5206\u522b\u662f\uff1a

    \n\n

    1 2 2 1 1 2 1 2 2 1 2 2 ......

    \n\n

    \u4f60\u53ef\u4ee5\u770b\u5230\u4e0a\u9762\u7684\u51fa\u73b0\u6b21\u6570\u5c31\u662f S \u672c\u8eab\u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570 N \u4f5c\u4e3a\u8f93\u5165\uff0c\u8fd4\u56de\u795e\u5947\u5b57\u7b26\u4e32 \u4e2d\u524d N \u4e2a\u6570\u5b57\u4e2d\u7684 '1' \u7684\u6570\u76ee\u3002

    \n\n

    \u6ce8\u610f\uff1aN \u4e0d\u4f1a\u8d85\u8fc7 100,000\u3002

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1a6\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u795e\u5947\u5b57\u7b26\u4e32 S \u7684\u524d 6 \u4e2a\u5143\u7d20\u662f “12211”\uff0c\u5b83\u5305\u542b\u4e09\u4e2a 1\uff0c\u56e0\u6b64\u8fd4\u56de 3\u3002\n
    \n\n

     

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int magicalString(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int magicalString(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def magicalString(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def magicalString(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint magicalString(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MagicalString(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar magicalString = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef magical_string(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func magicalString(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func magicalString(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def magicalString(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun magicalString(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn magical_string(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function magicalString($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function magicalString(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (magical-string n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0481](https://leetcode-cn.com/problems/magical-string)", "[\u795e\u5947\u5b57\u7b26\u4e32](/solution/0400-0499/0481.Magical%20String/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0481](https://leetcode.com/problems/magical-string)", "[Magical String](/solution/0400-0499/0481.Magical%20String/README_EN.md)", "", "Medium", ""]}, {"question_id": "0480", "frontend_question_id": "0480", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sliding-window-median", "url_en": "https://leetcode.com/problems/sliding-window-median", "relative_path_cn": "/solution/0400-0499/0480.Sliding%20Window%20Median/README.md", "relative_path_en": "/solution/0400-0499/0480.Sliding%20Window%20Median/README_EN.md", "title_cn": "\u6ed1\u52a8\u7a97\u53e3\u4e2d\u4f4d\u6570", "title_en": "Sliding Window Median", "question_title_slug": "sliding-window-median", "content_en": "

    The median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.

    \n\n
      \n\t
    • For examples, if arr = [2,3,4], the median is 3.
    • \n\t
    • For examples, if arr = [1,2,3,4], the median is (2 + 3) / 2 = 2.5.
    • \n
    \n\n

    You are given an integer array nums and an integer k. There is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window moves right by one position.

    \n\n

    Return the median array for each window in the original array. Answers within 10-5 of the actual value will be accepted.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,3,-1,-3,5,3,6,7], k = 3\nOutput: [1.00000,-1.00000,-1.00000,3.00000,5.00000,6.00000]\nExplanation: \nWindow position                Median\n---------------                -----\n[1  3  -1] -3  5  3  6  7        1\n 1 [3  -1  -3] 5  3  6  7       -1\n 1  3 [-1  -3  5] 3  6  7       -1\n 1  3  -1 [-3  5  3] 6  7        3\n 1  3  -1  -3 [5  3  6] 7        5\n 1  3  -1  -3  5 [3  6  7]       6\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,2,3,4,2,3,1,4,2], k = 3\nOutput: [2.00000,3.00000,3.00000,3.00000,2.00000,3.00000,2.00000]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= k <= nums.length <= 105
    • \n\t
    • 231 <= nums[i] <= 231 - 1
    • \n
    \n", "content_cn": "

    \u4e2d\u4f4d\u6570\u662f\u6709\u5e8f\u5e8f\u5217\u6700\u4e2d\u95f4\u7684\u90a3\u4e2a\u6570\u3002\u5982\u679c\u5e8f\u5217\u7684\u957f\u5ea6\u662f\u5076\u6570\uff0c\u5219\u6ca1\u6709\u6700\u4e2d\u95f4\u7684\u6570\uff1b\u6b64\u65f6\u4e2d\u4f4d\u6570\u662f\u6700\u4e2d\u95f4\u7684\u4e24\u4e2a\u6570\u7684\u5e73\u5747\u6570\u3002

    \n\n

    \u4f8b\u5982\uff1a

    \n\n
      \n\t
    • [2,3,4]\uff0c\u4e2d\u4f4d\u6570\u662f\u00a03
    • \n\t
    • [2,3]\uff0c\u4e2d\u4f4d\u6570\u662f (2 + 3) / 2 = 2.5
    • \n
    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 nums\uff0c\u6709\u4e00\u4e2a\u957f\u5ea6\u4e3a k \u7684\u7a97\u53e3\u4ece\u6700\u5de6\u7aef\u6ed1\u52a8\u5230\u6700\u53f3\u7aef\u3002\u7a97\u53e3\u4e2d\u6709 k \u4e2a\u6570\uff0c\u6bcf\u6b21\u7a97\u53e3\u5411\u53f3\u79fb\u52a8 1 \u4f4d\u3002\u4f60\u7684\u4efb\u52a1\u662f\u627e\u51fa\u6bcf\u6b21\u7a97\u53e3\u79fb\u52a8\u540e\u5f97\u5230\u7684\u65b0\u7a97\u53e3\u4e2d\u5143\u7d20\u7684\u4e2d\u4f4d\u6570\uff0c\u5e76\u8f93\u51fa\u7531\u5b83\u4eec\u7ec4\u6210\u7684\u6570\u7ec4\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n

    \u7ed9\u51fa\u00a0nums = [1,3,-1,-3,5,3,6,7]\uff0c\u4ee5\u53ca\u00a0k = 3\u3002

    \n\n
    \n\u7a97\u53e3\u4f4d\u7f6e                      \u4e2d\u4f4d\u6570\n---------------               -----\n[1  3  -1] -3  5  3  6  7       1\n 1 [3  -1  -3] 5  3  6  7      -1\n 1  3 [-1  -3  5] 3  6  7      -1\n 1  3  -1 [-3  5  3] 6  7       3\n 1  3  -1  -3 [5  3  6] 7       5\n 1  3  -1  -3  5 [3  6  7]      6\n
    \n\n

    \u00a0\u56e0\u6b64\uff0c\u8fd4\u56de\u8be5\u6ed1\u52a8\u7a97\u53e3\u7684\u4e2d\u4f4d\u6570\u6570\u7ec4\u00a0[1,-1,-1,3,5,6]\u3002

    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u4f60\u53ef\u4ee5\u5047\u8bbe\u00a0k\u00a0\u59cb\u7ec8\u6709\u6548\uff0c\u5373\uff1ak \u59cb\u7ec8\u5c0f\u4e8e\u7b49\u4e8e\u8f93\u5165\u7684\u975e\u7a7a\u6570\u7ec4\u7684\u5143\u7d20\u4e2a\u6570\u3002
    • \n\t
    • \u4e0e\u771f\u5b9e\u503c\u8bef\u5dee\u5728 10 ^ -5 \u4ee5\u5185\u7684\u7b54\u6848\u5c06\u88ab\u89c6\u4f5c\u6b63\u786e\u7b54\u6848\u3002
    • \n
    \n", "tags_en": ["Sliding Window"], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector medianSlidingWindow(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double[] medianSlidingWindow(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def medianSlidingWindow(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: List[float]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def medianSlidingWindow(self, nums: List[int], k: int) -> List[float]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\ndouble* medianSlidingWindow(int* nums, int numsSize, int k, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double[] MedianSlidingWindow(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number[]}\n */\nvar medianSlidingWindow = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Float[]}\ndef median_sliding_window(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func medianSlidingWindow(_ nums: [Int], _ k: Int) -> [Double] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func medianSlidingWindow(nums []int, k int) []float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def medianSlidingWindow(nums: Array[Int], k: Int): Array[Double] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun medianSlidingWindow(nums: IntArray, k: Int): DoubleArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn median_sliding_window(nums: Vec, k: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Float[]\n */\n function medianSlidingWindow($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function medianSlidingWindow(nums: number[], k: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (median-sliding-window nums k)\n (-> (listof exact-integer?) exact-integer? (listof flonum?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0480](https://leetcode-cn.com/problems/sliding-window-median)", "[\u6ed1\u52a8\u7a97\u53e3\u4e2d\u4f4d\u6570](/solution/0400-0499/0480.Sliding%20Window%20Median/README.md)", "", "\u56f0\u96be", ""], "md_table_row_en": ["[0480](https://leetcode.com/problems/sliding-window-median)", "[Sliding Window Median](/solution/0400-0499/0480.Sliding%20Window%20Median/README_EN.md)", "`Sliding Window`", "Hard", ""]}, {"question_id": "0479", "frontend_question_id": "0479", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/largest-palindrome-product", "url_en": "https://leetcode.com/problems/largest-palindrome-product", "relative_path_cn": "/solution/0400-0499/0479.Largest%20Palindrome%20Product/README.md", "relative_path_en": "/solution/0400-0499/0479.Largest%20Palindrome%20Product/README_EN.md", "title_cn": "\u6700\u5927\u56de\u6587\u6570\u4e58\u79ef", "title_en": "Largest Palindrome Product", "question_title_slug": "largest-palindrome-product", "content_en": "

    Given an integer n, return the largest palindromic integer that can be represented as the product of two n-digits integers. Since the answer can be very large, return it modulo 1337.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 2\nOutput: 987\nExplanation: 99 x 91 = 9009, 9009 % 1337 = 987\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 1\nOutput: 9\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 8
    • \n
    \n", "content_cn": "

    \u4f60\u9700\u8981\u627e\u5230\u7531\u4e24\u4e2a n \u4f4d\u6570\u7684\u4e58\u79ef\u7ec4\u6210\u7684\u6700\u5927\u56de\u6587\u6570\u3002

    \n\n

    \u7531\u4e8e\u7ed3\u679c\u4f1a\u5f88\u5927\uff0c\u4f60\u53ea\u9700\u8fd4\u56de\u6700\u5927\u56de\u6587\u6570 mod 1337\u5f97\u5230\u7684\u7ed3\u679c\u3002

    \n\n

    \u793a\u4f8b:

    \n\n

    \u8f93\u5165: 2

    \n\n

    \u8f93\u51fa: 987

    \n\n

    \u89e3\u91ca: 99 x 91 = 9009, 9009 % 1337 = 987

    \n\n

    \u8bf4\u660e:

    \n\n

    n \u7684\u53d6\u503c\u8303\u56f4\u4e3a [1,8]\u3002

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int largestPalindrome(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int largestPalindrome(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def largestPalindrome(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def largestPalindrome(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint largestPalindrome(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LargestPalindrome(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar largestPalindrome = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef largest_palindrome(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func largestPalindrome(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func largestPalindrome(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def largestPalindrome(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun largestPalindrome(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn largest_palindrome(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function largestPalindrome($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function largestPalindrome(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (largest-palindrome n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0479](https://leetcode-cn.com/problems/largest-palindrome-product)", "[\u6700\u5927\u56de\u6587\u6570\u4e58\u79ef](/solution/0400-0499/0479.Largest%20Palindrome%20Product/README.md)", "", "\u56f0\u96be", ""], "md_table_row_en": ["[0479](https://leetcode.com/problems/largest-palindrome-product)", "[Largest Palindrome Product](/solution/0400-0499/0479.Largest%20Palindrome%20Product/README_EN.md)", "", "Hard", ""]}, {"question_id": "0477", "frontend_question_id": "0477", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/total-hamming-distance", "url_en": "https://leetcode.com/problems/total-hamming-distance", "relative_path_cn": "/solution/0400-0499/0477.Total%20Hamming%20Distance/README.md", "relative_path_en": "/solution/0400-0499/0477.Total%20Hamming%20Distance/README_EN.md", "title_cn": "\u6c49\u660e\u8ddd\u79bb\u603b\u548c", "title_en": "Total Hamming Distance", "question_title_slug": "total-hamming-distance", "content_en": "

    The Hamming distance between two integers is the number of positions at which the corresponding bits are different.

    \n\n

    Given an integer array nums, return the sum of Hamming distances between all the pairs of the integers in nums.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [4,14,2]\nOutput: 6\nExplanation: In binary representation, the 4 is 0100, 14 is 1110, and 2 is 0010 (just\nshowing the four bits relevant in this case).\nThe answer will be:\nHammingDistance(4, 14) + HammingDistance(4, 2) + HammingDistance(14, 2) = 2 + 2 + 2 = 6.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [4,14,4]\nOutput: 4\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • 0 <= nums[i] <= 109
    • \n
    \n", "content_cn": "

    \u4e24\u4e2a\u6574\u6570\u7684\u00a0\u6c49\u660e\u8ddd\u79bb \u6307\u7684\u662f\u8fd9\u4e24\u4e2a\u6570\u5b57\u7684\u4e8c\u8fdb\u5236\u6570\u5bf9\u5e94\u4f4d\u4e0d\u540c\u7684\u6570\u91cf\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums\uff0c\u8bf7\u4f60\u8ba1\u7b97\u5e76\u8fd4\u56de nums \u4e2d\u4efb\u610f\u4e24\u4e2a\u6570\u4e4b\u95f4\u6c49\u660e\u8ddd\u79bb\u7684\u603b\u548c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [4,14,2]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u5728\u4e8c\u8fdb\u5236\u8868\u793a\u4e2d\uff0c4 \u8868\u793a\u4e3a 0100 \uff0c14 \u8868\u793a\u4e3a 1110 \uff0c2\u8868\u793a\u4e3a 0010 \u3002\uff08\u8fd9\u6837\u8868\u793a\u662f\u4e3a\u4e86\u4f53\u73b0\u540e\u56db\u4f4d\u4e4b\u95f4\u5173\u7cfb\uff09\n\u6240\u4ee5\u7b54\u6848\u4e3a\uff1a\nHammingDistance(4, 14) + HammingDistance(4, 2) + HammingDistance(14, 2) = 2 + 2 + 2 = 6\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [4,14,4]\n\u8f93\u51fa\uff1a4\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • 0 <= nums[i] <= 109
    • \n
    \n", "tags_en": ["Bit Manipulation"], "tags_cn": ["\u4f4d\u8fd0\u7b97"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int totalHammingDistance(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int totalHammingDistance(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def totalHammingDistance(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def totalHammingDistance(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint totalHammingDistance(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int TotalHammingDistance(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar totalHammingDistance = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef total_hamming_distance(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func totalHammingDistance(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func totalHammingDistance(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def totalHammingDistance(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun totalHammingDistance(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn total_hamming_distance(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function totalHammingDistance($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function totalHammingDistance(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (total-hamming-distance nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0477](https://leetcode-cn.com/problems/total-hamming-distance)", "[\u6c49\u660e\u8ddd\u79bb\u603b\u548c](/solution/0400-0499/0477.Total%20Hamming%20Distance/README.md)", "`\u4f4d\u8fd0\u7b97`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0477](https://leetcode.com/problems/total-hamming-distance)", "[Total Hamming Distance](/solution/0400-0499/0477.Total%20Hamming%20Distance/README_EN.md)", "`Bit Manipulation`", "Medium", ""]}, {"question_id": "0476", "frontend_question_id": "0476", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-complement", "url_en": "https://leetcode.com/problems/number-complement", "relative_path_cn": "/solution/0400-0499/0476.Number%20Complement/README.md", "relative_path_en": "/solution/0400-0499/0476.Number%20Complement/README_EN.md", "title_cn": "\u6570\u5b57\u7684\u8865\u6570", "title_en": "Number Complement", "question_title_slug": "number-complement", "content_en": "

    Given a positive integer num, output its complement number. The complement strategy is to flip the bits of its binary representation.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: num = 5\nOutput: 2\nExplanation: The binary representation of 5 is 101 (no leading zero bits), and its complement is 010. So you need to output 2.\n
    \n\n

    Example 2:

    \n\n
    \nInput: num = 1\nOutput: 0\nExplanation: The binary representation of 1 is 1 (no leading zero bits), and its complement is 0. So you need to output 0.\n
    \n\n

     

    \n

    Constraints:

    \n\n\n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a \u6b63 \u6574\u6570 num \uff0c\u8f93\u51fa\u5b83\u7684\u8865\u6570\u3002\u8865\u6570\u662f\u5bf9\u8be5\u6570\u7684\u4e8c\u8fdb\u5236\u8868\u793a\u53d6\u53cd\u3002

    \n\n

    \u00a0

    \n\n
      \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anum = 5\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a5 \u7684\u4e8c\u8fdb\u5236\u8868\u793a\u4e3a 101\uff08\u6ca1\u6709\u524d\u5bfc\u96f6\u4f4d\uff09\uff0c\u5176\u8865\u6570\u4e3a 010\u3002\u6240\u4ee5\u4f60\u9700\u8981\u8f93\u51fa 2 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anum = 1\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a1 \u7684\u4e8c\u8fdb\u5236\u8868\u793a\u4e3a 1\uff08\u6ca1\u6709\u524d\u5bfc\u96f6\u4f4d\uff09\uff0c\u5176\u8865\u6570\u4e3a 0\u3002\u6240\u4ee5\u4f60\u9700\u8981\u8f93\u51fa 0 \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u7ed9\u5b9a\u7684\u6574\u6570 num \u4fdd\u8bc1\u5728 32 \u4f4d\u5e26\u7b26\u53f7\u6574\u6570\u7684\u8303\u56f4\u5185\u3002
    • \n\t
    • num >= 1
    • \n\t
    • \u4f60\u53ef\u4ee5\u5047\u5b9a\u4e8c\u8fdb\u5236\u6570\u4e0d\u5305\u542b\u524d\u5bfc\u96f6\u4f4d\u3002
    • \n\t
    • \u672c\u9898\u4e0e 1009 https://leetcode-cn.com/problems/complement-of-base-10-integer/ \u76f8\u540c
    • \n
    \n", "tags_en": ["Bit Manipulation"], "tags_cn": ["\u4f4d\u8fd0\u7b97"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findComplement(int num) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findComplement(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findComplement(self, num):\n \"\"\"\n :type num: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findComplement(self, num: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findComplement(int num){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindComplement(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} num\n * @return {number}\n */\nvar findComplement = function(num) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} num\n# @return {Integer}\ndef find_complement(num)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findComplement(_ num: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findComplement(num int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findComplement(num: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findComplement(num: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_complement(num: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $num\n * @return Integer\n */\n function findComplement($num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findComplement(num: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-complement num)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0476](https://leetcode-cn.com/problems/number-complement)", "[\u6570\u5b57\u7684\u8865\u6570](/solution/0400-0499/0476.Number%20Complement/README.md)", "`\u4f4d\u8fd0\u7b97`", "\u7b80\u5355", ""], "md_table_row_en": ["[0476](https://leetcode.com/problems/number-complement)", "[Number Complement](/solution/0400-0499/0476.Number%20Complement/README_EN.md)", "`Bit Manipulation`", "Easy", ""]}, {"question_id": "0475", "frontend_question_id": "0475", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/heaters", "url_en": "https://leetcode.com/problems/heaters", "relative_path_cn": "/solution/0400-0499/0475.Heaters/README.md", "relative_path_en": "/solution/0400-0499/0475.Heaters/README_EN.md", "title_cn": "\u4f9b\u6696\u5668", "title_en": "Heaters", "question_title_slug": "heaters", "content_en": "

    Winter is coming! During the contest, your first job is to design a standard heater with a fixed warm radius to warm all the houses.

    \n\n

    Every house can be warmed, as long as the house is within the heater's warm radius range. 

    \n\n

    Given the positions of houses and heaters on a horizontal line, return the minimum radius standard of heaters so that those heaters could cover all houses.

    \n\n

    Notice that all the heaters follow your radius standard, and the warm radius will the same.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: houses = [1,2,3], heaters = [2]\nOutput: 1\nExplanation: The only heater was placed in the position 2, and if we use the radius 1 standard, then all the houses can be warmed.\n
    \n\n

    Example 2:

    \n\n
    \nInput: houses = [1,2,3,4], heaters = [1,4]\nOutput: 1\nExplanation: The two heater was placed in the position 1 and 4. We need to use radius 1 standard, then all the houses can be warmed.\n
    \n\n

    Example 3:

    \n\n
    \nInput: houses = [1,5], heaters = [2]\nOutput: 3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= houses.length, heaters.length <= 3 * 104
    • \n\t
    • 1 <= houses[i], heaters[i] <= 109
    • \n
    \n", "content_cn": "

    \u51ac\u5b63\u5df2\u7ecf\u6765\u4e34\u3002\u00a0\u4f60\u7684\u4efb\u52a1\u662f\u8bbe\u8ba1\u4e00\u4e2a\u6709\u56fa\u5b9a\u52a0\u70ed\u534a\u5f84\u7684\u4f9b\u6696\u5668\u5411\u6240\u6709\u623f\u5c4b\u4f9b\u6696\u3002

    \n\n

    \u5728\u52a0\u70ed\u5668\u7684\u52a0\u70ed\u534a\u5f84\u8303\u56f4\u5185\u7684\u6bcf\u4e2a\u623f\u5c4b\u90fd\u53ef\u4ee5\u83b7\u5f97\u4f9b\u6696\u3002

    \n\n

    \u73b0\u5728\uff0c\u7ed9\u51fa\u4f4d\u4e8e\u4e00\u6761\u6c34\u5e73\u7ebf\u4e0a\u7684\u623f\u5c4b\u00a0houses \u548c\u4f9b\u6696\u5668\u00a0heaters \u7684\u4f4d\u7f6e\uff0c\u8bf7\u4f60\u627e\u51fa\u5e76\u8fd4\u56de\u53ef\u4ee5\u8986\u76d6\u6240\u6709\u623f\u5c4b\u7684\u6700\u5c0f\u52a0\u70ed\u534a\u5f84\u3002

    \n\n

    \u8bf4\u660e\uff1a\u6240\u6709\u4f9b\u6696\u5668\u90fd\u9075\u5faa\u4f60\u7684\u534a\u5f84\u6807\u51c6\uff0c\u52a0\u70ed\u7684\u534a\u5f84\u4e5f\u4e00\u6837\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: houses = [1,2,3], heaters = [2]\n\u8f93\u51fa: 1\n\u89e3\u91ca: \u4ec5\u5728\u4f4d\u7f6e2\u4e0a\u6709\u4e00\u4e2a\u4f9b\u6696\u5668\u3002\u5982\u679c\u6211\u4eec\u5c06\u52a0\u70ed\u534a\u5f84\u8bbe\u4e3a1\uff0c\u90a3\u4e48\u6240\u6709\u623f\u5c4b\u5c31\u90fd\u80fd\u5f97\u5230\u4f9b\u6696\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: houses = [1,2,3,4], heaters = [1,4]\n\u8f93\u51fa: 1\n\u89e3\u91ca: \u5728\u4f4d\u7f6e1, 4\u4e0a\u6709\u4e24\u4e2a\u4f9b\u6696\u5668\u3002\u6211\u4eec\u9700\u8981\u5c06\u52a0\u70ed\u534a\u5f84\u8bbe\u4e3a1\uff0c\u8fd9\u6837\u6240\u6709\u623f\u5c4b\u5c31\u90fd\u80fd\u5f97\u5230\u4f9b\u6696\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahouses = [1,5], heaters = [2]\n\u8f93\u51fa\uff1a3\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= houses.length, heaters.length <= 3 * 104
    • \n\t
    • 1 <= houses[i], heaters[i] <= 109
    • \n
    \n", "tags_en": ["Binary Search"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findRadius(vector& houses, vector& heaters) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findRadius(int[] houses, int[] heaters) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findRadius(self, houses, heaters):\n \"\"\"\n :type houses: List[int]\n :type heaters: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findRadius(self, houses: List[int], heaters: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findRadius(int* houses, int housesSize, int* heaters, int heatersSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindRadius(int[] houses, int[] heaters) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} houses\n * @param {number[]} heaters\n * @return {number}\n */\nvar findRadius = function(houses, heaters) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} houses\n# @param {Integer[]} heaters\n# @return {Integer}\ndef find_radius(houses, heaters)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findRadius(_ houses: [Int], _ heaters: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findRadius(houses []int, heaters []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findRadius(houses: Array[Int], heaters: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findRadius(houses: IntArray, heaters: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_radius(houses: Vec, heaters: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $houses\n * @param Integer[] $heaters\n * @return Integer\n */\n function findRadius($houses, $heaters) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findRadius(houses: number[], heaters: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-radius houses heaters)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0475](https://leetcode-cn.com/problems/heaters)", "[\u4f9b\u6696\u5668](/solution/0400-0499/0475.Heaters/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0475](https://leetcode.com/problems/heaters)", "[Heaters](/solution/0400-0499/0475.Heaters/README_EN.md)", "`Binary Search`", "Medium", ""]}, {"question_id": "0474", "frontend_question_id": "0474", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/ones-and-zeroes", "url_en": "https://leetcode.com/problems/ones-and-zeroes", "relative_path_cn": "/solution/0400-0499/0474.Ones%20and%20Zeroes/README.md", "relative_path_en": "/solution/0400-0499/0474.Ones%20and%20Zeroes/README_EN.md", "title_cn": "\u4e00\u548c\u96f6", "title_en": "Ones and Zeroes", "question_title_slug": "ones-and-zeroes", "content_en": "

    You are given an array of binary strings strs and two integers m and n.

    \n\n

    Return the size of the largest subset of strs such that there are at most m 0's and n 1's in the subset.

    \n\n

    A set x is a subset of a set y if all elements of x are also elements of y.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: strs = ["10","0001","111001","1","0"], m = 5, n = 3\nOutput: 4\nExplanation: The largest subset with at most 5 0's and 3 1's is {"10", "0001", "1", "0"}, so the answer is 4.\nOther valid but smaller subsets include {"0001", "1"} and {"10", "1", "0"}.\n{"111001"} is an invalid subset because it contains 4 1's, greater than the maximum of 3.\n
    \n\n

    Example 2:

    \n\n
    \nInput: strs = ["10","0","1"], m = 1, n = 1\nOutput: 2\nExplanation: The largest subset is {"0", "1"}, so the answer is 2.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= strs.length <= 600
    • \n\t
    • 1 <= strs[i].length <= 100
    • \n\t
    • strs[i] consists only of digits '0' and '1'.
    • \n\t
    • 1 <= m, n <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32\u6570\u7ec4 strs \u548c\u4e24\u4e2a\u6574\u6570 m \u548c n \u3002

    \n\n
    \n

    \u8bf7\u4f60\u627e\u51fa\u5e76\u8fd4\u56de strs \u7684\u6700\u5927\u5b50\u96c6\u7684\u5927\u5c0f\uff0c\u8be5\u5b50\u96c6\u4e2d \u6700\u591a \u6709 m \u4e2a 0 \u548c n \u4e2a 1 \u3002

    \n\n

    \u5982\u679c x \u7684\u6240\u6709\u5143\u7d20\u4e5f\u662f y \u7684\u5143\u7d20\uff0c\u96c6\u5408 x \u662f\u96c6\u5408 y \u7684 \u5b50\u96c6 \u3002

    \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1astrs = [\"10\", \"0001\", \"111001\", \"1\", \"0\"], m = 5, n = 3\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u6700\u591a\u6709 5 \u4e2a 0 \u548c 3 \u4e2a 1 \u7684\u6700\u5927\u5b50\u96c6\u662f {\"10\",\"0001\",\"1\",\"0\"} \uff0c\u56e0\u6b64\u7b54\u6848\u662f 4 \u3002\n\u5176\u4ed6\u6ee1\u8db3\u9898\u610f\u4f46\u8f83\u5c0f\u7684\u5b50\u96c6\u5305\u62ec {\"0001\",\"1\"} \u548c {\"10\",\"1\",\"0\"} \u3002{\"111001\"} \u4e0d\u6ee1\u8db3\u9898\u610f\uff0c\u56e0\u4e3a\u5b83\u542b 4 \u4e2a 1 \uff0c\u5927\u4e8e n \u7684\u503c 3 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1astrs = [\"10\", \"0\", \"1\"], m = 1, n = 1\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6700\u5927\u7684\u5b50\u96c6\u662f {\"0\", \"1\"} \uff0c\u6240\u4ee5\u7b54\u6848\u662f 2 \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= strs.length <= 600
    • \n\t
    • 1 <= strs[i].length <= 100
    • \n\t
    • strs[i]\u00a0\u4ec5\u7531\u00a0'0' \u548c\u00a0'1' \u7ec4\u6210
    • \n\t
    • 1 <= m, n <= 100
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findMaxForm(vector& strs, int m, int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findMaxForm(String[] strs, int m, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findMaxForm(self, strs, m, n):\n \"\"\"\n :type strs: List[str]\n :type m: int\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findMaxForm(self, strs: List[str], m: int, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findMaxForm(char ** strs, int strsSize, int m, int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindMaxForm(string[] strs, int m, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} strs\n * @param {number} m\n * @param {number} n\n * @return {number}\n */\nvar findMaxForm = function(strs, m, n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} strs\n# @param {Integer} m\n# @param {Integer} n\n# @return {Integer}\ndef find_max_form(strs, m, n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findMaxForm(_ strs: [String], _ m: Int, _ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findMaxForm(strs []string, m int, n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findMaxForm(strs: Array[String], m: Int, n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findMaxForm(strs: Array, m: Int, n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_max_form(strs: Vec, m: i32, n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $strs\n * @param Integer $m\n * @param Integer $n\n * @return Integer\n */\n function findMaxForm($strs, $m, $n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findMaxForm(strs: string[], m: number, n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-max-form strs m n)\n (-> (listof string?) exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0474](https://leetcode-cn.com/problems/ones-and-zeroes)", "[\u4e00\u548c\u96f6](/solution/0400-0499/0474.Ones%20and%20Zeroes/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0474](https://leetcode.com/problems/ones-and-zeroes)", "[Ones and Zeroes](/solution/0400-0499/0474.Ones%20and%20Zeroes/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0473", "frontend_question_id": "0473", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/matchsticks-to-square", "url_en": "https://leetcode.com/problems/matchsticks-to-square", "relative_path_cn": "/solution/0400-0499/0473.Matchsticks%20to%20Square/README.md", "relative_path_en": "/solution/0400-0499/0473.Matchsticks%20to%20Square/README_EN.md", "title_cn": "\u706b\u67f4\u62fc\u6b63\u65b9\u5f62", "title_en": "Matchsticks to Square", "question_title_slug": "matchsticks-to-square", "content_en": "

    You are given an integer array matchsticks where matchsticks[i] is the length of the ith matchstick. You want to use all the matchsticks to make one square. You should not break any stick, but you can link them up, and each matchstick must be used exactly one time.

    \n\n

    Return true if you can make this square and false otherwise.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: matchsticks = [1,1,2,2,2]\nOutput: true\nExplanation: You can form a square with length 2, one side of the square came two sticks with length 1.\n
    \n\n

    Example 2:

    \n\n
    \nInput: matchsticks = [3,3,3,3,4]\nOutput: false\nExplanation: You cannot find a way to form a square with all the matchsticks.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= matchsticks.length <= 15
    • \n\t
    • 0 <= matchsticks[i] <= 109
    • \n
    \n", "content_cn": "

    \u8fd8\u8bb0\u5f97\u7ae5\u8bdd\u300a\u5356\u706b\u67f4\u7684\u5c0f\u5973\u5b69\u300b\u5417\uff1f\u73b0\u5728\uff0c\u4f60\u77e5\u9053\u5c0f\u5973\u5b69\u6709\u591a\u5c11\u6839\u706b\u67f4\uff0c\u8bf7\u627e\u51fa\u4e00\u79cd\u80fd\u4f7f\u7528\u6240\u6709\u706b\u67f4\u62fc\u6210\u4e00\u4e2a\u6b63\u65b9\u5f62\u7684\u65b9\u6cd5\u3002\u4e0d\u80fd\u6298\u65ad\u706b\u67f4\uff0c\u53ef\u4ee5\u628a\u706b\u67f4\u8fde\u63a5\u8d77\u6765\uff0c\u5e76\u4e14\u6bcf\u6839\u706b\u67f4\u90fd\u8981\u7528\u5230\u3002

    \n\n

    \u8f93\u5165\u4e3a\u5c0f\u5973\u5b69\u62e5\u6709\u706b\u67f4\u7684\u6570\u76ee\uff0c\u6bcf\u6839\u706b\u67f4\u7528\u5176\u957f\u5ea6\u8868\u793a\u3002\u8f93\u51fa\u5373\u4e3a\u662f\u5426\u80fd\u7528\u6240\u6709\u7684\u706b\u67f4\u62fc\u6210\u6b63\u65b9\u5f62\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: [1,1,2,2,2]\n\u8f93\u51fa: true\n\n\u89e3\u91ca: \u80fd\u62fc\u6210\u4e00\u4e2a\u8fb9\u957f\u4e3a2\u7684\u6b63\u65b9\u5f62\uff0c\u6bcf\u8fb9\u4e24\u6839\u706b\u67f4\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: [3,3,3,3,4]\n\u8f93\u51fa: false\n\n\u89e3\u91ca: \u4e0d\u80fd\u7528\u6240\u6709\u706b\u67f4\u62fc\u6210\u4e00\u4e2a\u6b63\u65b9\u5f62\u3002\n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u7ed9\u5b9a\u7684\u706b\u67f4\u957f\u5ea6\u548c\u5728 0 \u5230 10^9\u4e4b\u95f4\u3002
    2. \n\t
    3. \u706b\u67f4\u6570\u7ec4\u7684\u957f\u5ea6\u4e0d\u8d85\u8fc715\u3002
    4. \n
    \n", "tags_en": ["Depth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool makesquare(vector& matchsticks) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean makesquare(int[] matchsticks) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def makesquare(self, matchsticks):\n \"\"\"\n :type matchsticks: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def makesquare(self, matchsticks: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool makesquare(int* matchsticks, int matchsticksSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool Makesquare(int[] matchsticks) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} matchsticks\n * @return {boolean}\n */\nvar makesquare = function(matchsticks) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} matchsticks\n# @return {Boolean}\ndef makesquare(matchsticks)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func makesquare(_ matchsticks: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func makesquare(matchsticks []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def makesquare(matchsticks: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun makesquare(matchsticks: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn makesquare(matchsticks: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $matchsticks\n * @return Boolean\n */\n function makesquare($matchsticks) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function makesquare(matchsticks: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (makesquare matchsticks)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0473](https://leetcode-cn.com/problems/matchsticks-to-square)", "[\u706b\u67f4\u62fc\u6b63\u65b9\u5f62](/solution/0400-0499/0473.Matchsticks%20to%20Square/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0473](https://leetcode.com/problems/matchsticks-to-square)", "[Matchsticks to Square](/solution/0400-0499/0473.Matchsticks%20to%20Square/README_EN.md)", "`Depth-first Search`", "Medium", ""]}, {"question_id": "0472", "frontend_question_id": "0472", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/concatenated-words", "url_en": "https://leetcode.com/problems/concatenated-words", "relative_path_cn": "/solution/0400-0499/0472.Concatenated%20Words/README.md", "relative_path_en": "/solution/0400-0499/0472.Concatenated%20Words/README_EN.md", "title_cn": "\u8fde\u63a5\u8bcd", "title_en": "Concatenated Words", "question_title_slug": "concatenated-words", "content_en": "

    Given an array of strings words (without duplicates), return all the concatenated words in the given list of words.

    \n\n

    A concatenated word is defined as a string that is comprised entirely of at least two shorter words in the given array.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: words = ["cat","cats","catsdogcats","dog","dogcatsdog","hippopotamuses","rat","ratcatdogcat"]\nOutput: ["catsdogcats","dogcatsdog","ratcatdogcat"]\nExplanation: "catsdogcats" can be concatenated by "cats", "dog" and "cats"; \n"dogcatsdog" can be concatenated by "dog", "cats" and "dog"; \n"ratcatdogcat" can be concatenated by "rat", "cat", "dog" and "cat".
    \n\n

    Example 2:

    \n\n
    \nInput: words = ["cat","dog","catdog"]\nOutput: ["catdog"]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= words.length <= 104
    • \n\t
    • 0 <= words[i].length <= 1000
    • \n\t
    • words[i] consists of only lowercase English letters.
    • \n\t
    • 0 <= sum(words[i].length) <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a \u4e0d\u542b\u91cd\u590d \u5355\u8bcd\u7684\u5b57\u7b26\u4e32\u6570\u7ec4 words \uff0c\u7f16\u5199\u4e00\u4e2a\u7a0b\u5e8f\uff0c\u8fd4\u56de\u00a0words \u4e2d\u7684\u6240\u6709 \u8fde\u63a5\u8bcd \u3002

    \n\n

    \u8fde\u63a5\u8bcd \u7684\u5b9a\u4e49\u4e3a\uff1a\u4e00\u4e2a\u5b57\u7b26\u4e32\u5b8c\u5168\u662f\u7531\u81f3\u5c11\u4e24\u4e2a\u7ed9\u5b9a\u6570\u7ec4\u4e2d\u7684\u5355\u8bcd\u7ec4\u6210\u7684\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1awords = [\"cat\",\"cats\",\"catsdogcats\",\"dog\",\"dogcatsdog\",\"hippopotamuses\",\"rat\",\"ratcatdogcat\"]\n\u8f93\u51fa\uff1a[\"catsdogcats\",\"dogcatsdog\",\"ratcatdogcat\"]\n\u89e3\u91ca\uff1a\"catsdogcats\"\u7531\"cats\", \"dog\" \u548c \"cats\"\u7ec4\u6210; \n     \"dogcatsdog\"\u7531\"dog\", \"cats\"\u548c\"dog\"\u7ec4\u6210; \n     \"ratcatdogcat\"\u7531\"rat\", \"cat\", \"dog\"\u548c\"cat\"\u7ec4\u6210\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1awords = [\"cat\",\"dog\",\"catdog\"]\n\u8f93\u51fa\uff1a[\"catdog\"]
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= words.length <= 104
    • \n\t
    • 0 <= words[i].length <= 1000
    • \n\t
    • words[i] \u4ec5\u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210
    • \n\t
    • 0 <= sum(words[i].length) <= 6 * 105
    • \n
    \n", "tags_en": ["Depth-first Search", "Trie", "Dynamic Programming"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5b57\u5178\u6811", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findAllConcatenatedWordsInADict(vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List findAllConcatenatedWordsInADict(String[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findAllConcatenatedWordsInADict(self, words):\n \"\"\"\n :type words: List[str]\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findAllConcatenatedWordsInADict(self, words: List[str]) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** findAllConcatenatedWordsInADict(char ** words, int wordsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList FindAllConcatenatedWordsInADict(string[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @return {string[]}\n */\nvar findAllConcatenatedWordsInADict = function(words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @return {String[]}\ndef find_all_concatenated_words_in_a_dict(words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findAllConcatenatedWordsInADict(_ words: [String]) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findAllConcatenatedWordsInADict(words []string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findAllConcatenatedWordsInADict(words: Array[String]): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findAllConcatenatedWordsInADict(words: Array): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_all_concatenated_words_in_a_dict(words: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @return String[]\n */\n function findAllConcatenatedWordsInADict($words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findAllConcatenatedWordsInADict(words: string[]): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-all-concatenated-words-in-a-dict words)\n (-> (listof string?) (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0472](https://leetcode-cn.com/problems/concatenated-words)", "[\u8fde\u63a5\u8bcd](/solution/0400-0499/0472.Concatenated%20Words/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5b57\u5178\u6811`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0472](https://leetcode.com/problems/concatenated-words)", "[Concatenated Words](/solution/0400-0499/0472.Concatenated%20Words/README_EN.md)", "`Depth-first Search`,`Trie`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0471", "frontend_question_id": "0471", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/encode-string-with-shortest-length", "url_en": "https://leetcode.com/problems/encode-string-with-shortest-length", "relative_path_cn": "/solution/0400-0499/0471.Encode%20String%20with%20Shortest%20Length/README.md", "relative_path_en": "/solution/0400-0499/0471.Encode%20String%20with%20Shortest%20Length/README_EN.md", "title_cn": "\u7f16\u7801\u6700\u77ed\u957f\u5ea6\u7684\u5b57\u7b26\u4e32", "title_en": "Encode String with Shortest Length", "question_title_slug": "encode-string-with-shortest-length", "content_en": "

    Given a string s, encode the string such that its encoded length is the shortest.

    \n\n

    The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. k should be a positive integer.

    \n\n

    If an encoding process does not make the string shorter, then do not encode it. If there are several solutions, return any of them.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "aaa"\nOutput: "aaa"\nExplanation: There is no way to encode it such that it is shorter than the input string, so we do not encode it.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "aaaaa"\nOutput: "5[a]"\nExplanation: "5[a]" is shorter than "aaaaa" by 1 character.\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "aaaaaaaaaa"\nOutput: "10[a]"\nExplanation: "a9[a]" or "9[a]a" are also valid solutions, both of them have the same length = 5, which is the same as "10[a]".\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "aabcaabcd"\nOutput: "2[aabc]d"\nExplanation: "aabc" occurs twice, so one answer can be "2[aabc]d".\n
    \n\n

    Example 5:

    \n\n
    \nInput: s = "abbbabbbcabbbabbbc"\nOutput: "2[2[abbb]c]"\nExplanation: "abbbabbbc" occurs twice, but "abbbabbbc" can also be encoded to "2[abbb]c", so one answer can be "2[2[abbb]c]".\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 150
    • \n\t
    • s consists of only lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a \u975e\u7a7a\u00a0\u5b57\u7b26\u4e32\uff0c\u5c06\u5176\u7f16\u7801\u4e3a\u5177\u6709\u6700\u77ed\u957f\u5ea6\u7684\u5b57\u7b26\u4e32\u3002

    \n\n

    \u7f16\u7801\u89c4\u5219\u662f\uff1ak[encoded_string]\uff0c\u5176\u4e2d\u5728\u65b9\u62ec\u53f7\u00a0encoded_string \u4e2d\u7684\u5185\u5bb9\u91cd\u590d k \u6b21\u3002

    \n\n

    \u6ce8\uff1a

    \n\n
      \n\t
    • k\u00a0\u4e3a\u6b63\u6574\u6570
    • \n\t
    • \u5982\u679c\u7f16\u7801\u7684\u8fc7\u7a0b\u4e0d\u80fd\u4f7f\u5b57\u7b26\u4e32\u7f29\u77ed\uff0c\u5219\u4e0d\u8981\u5bf9\u5176\u8fdb\u884c\u7f16\u7801\u3002\u5982\u679c\u6709\u591a\u79cd\u7f16\u7801\u65b9\u5f0f\uff0c\u8fd4\u56de \u4efb\u610f\u4e00\u79cd \u5373\u53ef
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"aaa\"\n\u8f93\u51fa\uff1a\"aaa\"\n\u89e3\u91ca\uff1a\u65e0\u6cd5\u5c06\u5176\u7f16\u7801\u4e3a\u66f4\u77ed\u7684\u5b57\u7b26\u4e32\uff0c\u56e0\u6b64\u4e0d\u8fdb\u884c\u7f16\u7801\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"aaaaa\"\n\u8f93\u51fa\uff1a\"5[a]\"\n\u89e3\u91ca\uff1a\"5[a]\" \u6bd4 \"aaaaa\" \u77ed 1 \u4e2a\u5b57\u7b26\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"aaaaaaaaaa\"\n\u8f93\u51fa\uff1a\"10[a]\"\n\u89e3\u91ca\uff1a\"a9[a]\" \u6216 \"9[a]a\" \u90fd\u662f\u5408\u6cd5\u7684\u7f16\u7801\uff0c\u548c \"10[a]\" \u4e00\u6837\u957f\u5ea6\u90fd\u4e3a 5\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"aabcaabcd\"\n\u8f93\u51fa\uff1a\"2[aabc]d\"\n\u89e3\u91ca\uff1a\"aabc\" \u51fa\u73b0\u4e24\u6b21\uff0c\u56e0\u6b64\u4e00\u79cd\u7b54\u6848\u53ef\u4ee5\u662f \"2[aabc]d\"\u3002\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"abbbabbbcabbbabbbc\"\n\u8f93\u51fa\uff1a\"2[2[abbb]c]\"\n\u89e3\u91ca\uff1a\"abbbabbbc\" \u51fa\u73b0\u4e24\u6b21\uff0c\u4f46\u662f \"abbbabbbc\" \u53ef\u4ee5\u7f16\u7801\u4e3a \"2[abbb]c\"\uff0c\u56e0\u6b64\u4e00\u79cd\u7b54\u6848\u53ef\u4ee5\u662f \"2[2[abbb]c]\"\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 150
    • \n\t
    • s \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string encode(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String encode(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def encode(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def encode(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * encode(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string Encode(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar encode = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef encode(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func encode(_ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func encode(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def encode(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun encode(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn encode(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function encode($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function encode(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (encode s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0471](https://leetcode-cn.com/problems/encode-string-with-shortest-length)", "[\u7f16\u7801\u6700\u77ed\u957f\u5ea6\u7684\u5b57\u7b26\u4e32](/solution/0400-0499/0471.Encode%20String%20with%20Shortest%20Length/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0471](https://leetcode.com/problems/encode-string-with-shortest-length)", "[Encode String with Shortest Length](/solution/0400-0499/0471.Encode%20String%20with%20Shortest%20Length/README_EN.md)", "`Dynamic Programming`", "Hard", "\ud83d\udd12"]}, {"question_id": "0469", "frontend_question_id": "0469", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/convex-polygon", "url_en": "https://leetcode.com/problems/convex-polygon", "relative_path_cn": "/solution/0400-0499/0469.Convex%20Polygon/README.md", "relative_path_en": "/solution/0400-0499/0469.Convex%20Polygon/README_EN.md", "title_cn": "\u51f8\u591a\u8fb9\u5f62", "title_en": "Convex Polygon", "question_title_slug": "convex-polygon", "content_en": "

    You are given an array of points on the X-Y plane points where points[i] = [xi, yi]. The points form a polygon when joined sequentially.

    \n\n

    Return true if this polygon is convex and false otherwise.

    \n\n

    You may assume the polygon formed by given points is always a simple polygon. In other words, we ensure that exactly two edges intersect at each vertex and that edges otherwise don't intersect each other.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: points = [[0,0],[0,5],[5,5],[5,0]]\nOutput: true\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: points = [[0,0],[0,10],[10,10],[10,0],[5,5]]\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 3 <= points.length <= 104
    • \n\t
    • points[i].length == 2
    • \n\t
    • -104 <= xi, yi <= 104
    • \n\t
    • All the given points are unique.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6309\u987a\u5e8f\u8fde\u63a5\u7684\u591a\u8fb9\u5f62\u7684\u9876\u70b9\uff0c\u5224\u65ad\u8be5\u591a\u8fb9\u5f62\u662f\u5426\u4e3a\u51f8\u591a\u8fb9\u5f62\u3002\uff08\u51f8\u591a\u8fb9\u5f62\u7684\u5b9a\u4e49\uff09

    \n\n

    \u6ce8\uff1a

    \n\n
      \n\t
    1. \u9876\u70b9\u4e2a\u6570\u81f3\u5c11\u4e3a 3 \u4e2a\u4e14\u4e0d\u8d85\u8fc7 10,000\u3002
    2. \n\t
    3. \u5750\u6807\u8303\u56f4\u4e3a -10,000 \u5230 10,000\u3002
    4. \n\t
    5. \u4f60\u53ef\u4ee5\u5047\u5b9a\u7ed9\u5b9a\u7684\u70b9\u5f62\u6210\u7684\u591a\u8fb9\u5f62\u5747\u4e3a\u7b80\u5355\u591a\u8fb9\u5f62\uff08\u7b80\u5355\u591a\u8fb9\u5f62\u7684\u5b9a\u4e49\uff09\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u4fdd\u8bc1\u6bcf\u4e2a\u9876\u70b9\u5904\u6070\u597d\u662f\u4e24\u6761\u8fb9\u7684\u6c47\u5408\u70b9\uff0c\u5e76\u4e14\u8fd9\u4e9b\u8fb9 \u4e92\u4e0d\u76f8\u4ea4 \u3002
    6. \n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    [[0,0],[0,1],[1,1],[1,0]]\n\n\u8f93\u51fa\uff1a True\n\n\u89e3\u91ca\uff1a\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    [[0,0],[0,10],[10,10],[10,0],[5,5]]\n\n\u8f93\u51fa\uff1a False\n\n\u89e3\u91ca\uff1a\n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isConvex(vector>& points) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isConvex(List> points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isConvex(self, points):\n \"\"\"\n :type points: List[List[int]]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isConvex(self, points: List[List[int]]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isConvex(int** points, int pointsSize, int* pointsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsConvex(IList> points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} points\n * @return {boolean}\n */\nvar isConvex = function(points) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} points\n# @return {Boolean}\ndef is_convex(points)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isConvex(_ points: [[Int]]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isConvex(points [][]int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isConvex(points: List[List[Int]]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isConvex(points: List>): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_convex(points: Vec>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $points\n * @return Boolean\n */\n function isConvex($points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isConvex(points: number[][]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-convex points)\n (-> (listof (listof exact-integer?)) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0469](https://leetcode-cn.com/problems/convex-polygon)", "[\u51f8\u591a\u8fb9\u5f62](/solution/0400-0499/0469.Convex%20Polygon/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0469](https://leetcode.com/problems/convex-polygon)", "[Convex Polygon](/solution/0400-0499/0469.Convex%20Polygon/README_EN.md)", "`Math`", "Medium", "\ud83d\udd12"]}, {"question_id": "0468", "frontend_question_id": "0468", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/validate-ip-address", "url_en": "https://leetcode.com/problems/validate-ip-address", "relative_path_cn": "/solution/0400-0499/0468.Validate%20IP%20Address/README.md", "relative_path_en": "/solution/0400-0499/0468.Validate%20IP%20Address/README_EN.md", "title_cn": "\u9a8c\u8bc1IP\u5730\u5740", "title_en": "Validate IP Address", "question_title_slug": "validate-ip-address", "content_en": "

    Given a string IP, return "IPv4" if IP is a valid IPv4 address, "IPv6" if IP is a valid IPv6 address or "Neither" if IP is not a correct IP of any type.

    \n\n

    A valid IPv4 address is an IP in the form "x1.x2.x3.x4" where 0 <= xi <= 255 and xi cannot contain leading zeros. For example, "192.168.1.1" and "192.168.1.0" are valid IPv4 addresses but "192.168.01.1", while "192.168.1.00" and "192.168@1.1" are invalid IPv4 addresses.

    \n\n

    A valid IPv6 address is an IP in the form "x1:x2:x3:x4:x5:x6:x7:x8" where:

    \n\n
      \n\t
    • 1 <= xi.length <= 4
    • \n\t
    • xi is a hexadecimal string which may contain digits, lower-case English letter ('a' to 'f') and upper-case English letters ('A' to 'F').
    • \n\t
    • Leading zeros are allowed in xi.
    • \n
    \n\n

    For example, "2001:0db8:85a3:0000:0000:8a2e:0370:7334" and "2001:db8:85a3:0:0:8A2E:0370:7334" are valid IPv6 addresses, while "2001:0db8:85a3::8A2E:037j:7334" and "02001:0db8:85a3:0000:0000:8a2e:0370:7334" are invalid IPv6 addresses.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: IP = "172.16.254.1"\nOutput: "IPv4"\nExplanation: This is a valid IPv4 address, return "IPv4".\n
    \n\n

    Example 2:

    \n\n
    \nInput: IP = "2001:0db8:85a3:0:0:8A2E:0370:7334"\nOutput: "IPv6"\nExplanation: This is a valid IPv6 address, return "IPv6".\n
    \n\n

    Example 3:

    \n\n
    \nInput: IP = "256.256.256.256"\nOutput: "Neither"\nExplanation: This is neither a IPv4 address nor a IPv6 address.\n
    \n\n

    Example 4:

    \n\n
    \nInput: IP = "2001:0db8:85a3:0:0:8A2E:0370:7334:"\nOutput: "Neither"\n
    \n\n

    Example 5:

    \n\n
    \nInput: IP = "1e1.4.5.6"\nOutput: "Neither"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • IP consists only of English letters, digits and the characters '.' and ':'.
    • \n
    \n", "content_cn": "

    \u7f16\u5199\u4e00\u4e2a\u51fd\u6570\u6765\u9a8c\u8bc1\u8f93\u5165\u7684\u5b57\u7b26\u4e32\u662f\u5426\u662f\u6709\u6548\u7684 IPv4 \u6216 IPv6 \u5730\u5740\u3002

    \n\n
      \n\t
    • \u5982\u679c\u662f\u6709\u6548\u7684 IPv4 \u5730\u5740\uff0c\u8fd4\u56de "IPv4" \uff1b
    • \n\t
    • \u5982\u679c\u662f\u6709\u6548\u7684 IPv6 \u5730\u5740\uff0c\u8fd4\u56de "IPv6" \uff1b
    • \n\t
    • \u5982\u679c\u4e0d\u662f\u4e0a\u8ff0\u7c7b\u578b\u7684 IP \u5730\u5740\uff0c\u8fd4\u56de "Neither" \u3002
    • \n
    \n\n

    IPv4 \u5730\u5740\u7531\u5341\u8fdb\u5236\u6570\u548c\u70b9\u6765\u8868\u793a\uff0c\u6bcf\u4e2a\u5730\u5740\u5305\u542b 4 \u4e2a\u5341\u8fdb\u5236\u6570\uff0c\u5176\u8303\u56f4\u4e3a 0 - 255\uff0c \u7528(".")\u5206\u5272\u3002\u6bd4\u5982\uff0c172.16.254.1\uff1b

    \n\n

    \u540c\u65f6\uff0cIPv4 \u5730\u5740\u5185\u7684\u6570\u4e0d\u4f1a\u4ee5 0 \u5f00\u5934\u3002\u6bd4\u5982\uff0c\u5730\u5740 172.16.254.01 \u662f\u4e0d\u5408\u6cd5\u7684\u3002

    \n\n

    IPv6 \u5730\u5740\u7531 8 \u7ec4 16 \u8fdb\u5236\u7684\u6570\u5b57\u6765\u8868\u793a\uff0c\u6bcf\u7ec4\u8868\u793a 16 \u6bd4\u7279\u3002\u8fd9\u4e9b\u7ec4\u6570\u5b57\u901a\u8fc7 (":")\u5206\u5272\u3002\u6bd4\u5982,  2001:0db8:85a3:0000:0000:8a2e:0370:7334 \u662f\u4e00\u4e2a\u6709\u6548\u7684\u5730\u5740\u3002\u800c\u4e14\uff0c\u6211\u4eec\u53ef\u4ee5\u52a0\u5165\u4e00\u4e9b\u4ee5 0 \u5f00\u5934\u7684\u6570\u5b57\uff0c\u5b57\u6bcd\u53ef\u4ee5\u4f7f\u7528\u5927\u5199\uff0c\u4e5f\u53ef\u4ee5\u662f\u5c0f\u5199\u3002\u6240\u4ee5\uff0c 2001:db8:85a3:0:0:8A2E:0370:7334 \u4e5f\u662f\u4e00\u4e2a\u6709\u6548\u7684 IPv6 address\u5730\u5740 (\u5373\uff0c\u5ffd\u7565 0 \u5f00\u5934\uff0c\u5ffd\u7565\u5927\u5c0f\u5199)\u3002

    \n\n

    \u7136\u800c\uff0c\u6211\u4eec\u4e0d\u80fd\u56e0\u4e3a\u67d0\u4e2a\u7ec4\u7684\u503c\u4e3a 0\uff0c\u800c\u4f7f\u7528\u4e00\u4e2a\u7a7a\u7684\u7ec4\uff0c\u4ee5\u81f3\u4e8e\u51fa\u73b0 (::) \u7684\u60c5\u51b5\u3002 \u6bd4\u5982\uff0c 2001:0db8:85a3::8A2E:0370:7334 \u662f\u65e0\u6548\u7684 IPv6 \u5730\u5740\u3002

    \n\n

    \u540c\u65f6\uff0c\u5728 IPv6 \u5730\u5740\u4e2d\uff0c\u591a\u4f59\u7684 0 \u4e5f\u662f\u4e0d\u88ab\u5141\u8bb8\u7684\u3002\u6bd4\u5982\uff0c 02001:0db8:85a3:0000:0000:8a2e:0370:7334 \u662f\u65e0\u6548\u7684\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1aIP = "172.16.254.1"\n\u8f93\u51fa\uff1a"IPv4"\n\u89e3\u91ca\uff1a\u6709\u6548\u7684 IPv4 \u5730\u5740\uff0c\u8fd4\u56de "IPv4"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1aIP = "2001:0db8:85a3:0:0:8A2E:0370:7334"\n\u8f93\u51fa\uff1a"IPv6"\n\u89e3\u91ca\uff1a\u6709\u6548\u7684 IPv6 \u5730\u5740\uff0c\u8fd4\u56de "IPv6"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aIP = "256.256.256.256"\n\u8f93\u51fa\uff1a"Neither"\n\u89e3\u91ca\uff1a\u65e2\u4e0d\u662f IPv4 \u5730\u5740\uff0c\u53c8\u4e0d\u662f IPv6 \u5730\u5740\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1aIP = "2001:0db8:85a3:0:0:8A2E:0370:7334:"\n\u8f93\u51fa\uff1a"Neither"\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \u8f93\u5165\uff1aIP = "1e1.4.5.6"\n\u8f93\u51fa\uff1a"Neither"\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • IP \u4ec5\u7531\u82f1\u6587\u5b57\u6bcd\uff0c\u6570\u5b57\uff0c\u5b57\u7b26 '.' \u548c ':' \u7ec4\u6210\u3002
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string validIPAddress(string IP) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String validIPAddress(String IP) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def validIPAddress(self, IP):\n \"\"\"\n :type IP: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def validIPAddress(self, IP: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * validIPAddress(char * IP){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ValidIPAddress(string IP) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} IP\n * @return {string}\n */\nvar validIPAddress = function(IP) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} ip\n# @return {String}\ndef valid_ip_address(ip)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func validIPAddress(_ IP: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func validIPAddress(IP string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def validIPAddress(IP: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun validIPAddress(IP: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn valid_ip_address(ip: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $IP\n * @return String\n */\n function validIPAddress($IP) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function validIPAddress(IP: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (valid-ip-address IP)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0468](https://leetcode-cn.com/problems/validate-ip-address)", "[\u9a8c\u8bc1IP\u5730\u5740](/solution/0400-0499/0468.Validate%20IP%20Address/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0468](https://leetcode.com/problems/validate-ip-address)", "[Validate IP Address](/solution/0400-0499/0468.Validate%20IP%20Address/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "0467", "frontend_question_id": "0467", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/unique-substrings-in-wraparound-string", "url_en": "https://leetcode.com/problems/unique-substrings-in-wraparound-string", "relative_path_cn": "/solution/0400-0499/0467.Unique%20Substrings%20in%20Wraparound%20String/README.md", "relative_path_en": "/solution/0400-0499/0467.Unique%20Substrings%20in%20Wraparound%20String/README_EN.md", "title_cn": "\u73af\u7ed5\u5b57\u7b26\u4e32\u4e2d\u552f\u4e00\u7684\u5b50\u5b57\u7b26\u4e32", "title_en": "Unique Substrings in Wraparound String", "question_title_slug": "unique-substrings-in-wraparound-string", "content_en": "

    We define the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz", so s will look like this:

    \n\n
      \n\t
    • "...zabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcd....".
    • \n
    \n\n

    Given a string p, return the number of unique non-empty substrings of p are present in s.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: p = "a"\nOutput: 1\nExplanation: Only the substring "a" of p is in s.\n
    \n\n

    Example 2:

    \n\n
    \nInput: p = "cac"\nOutput: 2\nExplanation: There are two substrings ("a", "c") of p in s.\n
    \n\n

    Example 3:

    \n\n
    \nInput: p = "zab"\nOutput: 6\nExplanation: There are six substrings ("z", "a", "b", "za", "ab", and "zab") of p in s.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= p.length <= 105
    • \n\t
    • p consists of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u628a\u5b57\u7b26\u4e32 s \u770b\u4f5c\u662f“abcdefghijklmnopqrstuvwxyz”\u7684\u65e0\u9650\u73af\u7ed5\u5b57\u7b26\u4e32\uff0c\u6240\u4ee5 s \u770b\u8d77\u6765\u662f\u8fd9\u6837\u7684\uff1a"...zabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcd....". 

    \n\n

    \u73b0\u5728\u6211\u4eec\u6709\u4e86\u53e6\u4e00\u4e2a\u5b57\u7b26\u4e32 p \u3002\u4f60\u9700\u8981\u7684\u662f\u627e\u51fa s \u4e2d\u6709\u591a\u5c11\u4e2a\u552f\u4e00\u7684 p \u7684\u975e\u7a7a\u5b50\u4e32\uff0c\u5c24\u5176\u662f\u5f53\u4f60\u7684\u8f93\u5165\u662f\u5b57\u7b26\u4e32 p \uff0c\u4f60\u9700\u8981\u8f93\u51fa\u5b57\u7b26\u4e32 s \u4e2d p \u7684\u4e0d\u540c\u7684\u975e\u7a7a\u5b50\u4e32\u7684\u6570\u76ee\u3002 

    \n\n

    \u6ce8\u610f: p \u4ec5\u7531\u5c0f\u5199\u7684\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\uff0cp \u7684\u5927\u5c0f\u53ef\u80fd\u8d85\u8fc7 10000\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: "a"\n\u8f93\u51fa: 1\n\u89e3\u91ca: \u5b57\u7b26\u4e32 S \u4e2d\u53ea\u6709\u4e00\u4e2a"a"\u5b50\u5b57\u7b26\u3002\n
    \n\n

     

    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: "cac"\n\u8f93\u51fa: 2\n\u89e3\u91ca: \u5b57\u7b26\u4e32 S \u4e2d\u7684\u5b57\u7b26\u4e32“cac”\u53ea\u6709\u4e24\u4e2a\u5b50\u4e32“a”\u3001“c”\u3002.\n
    \n\n

     

    \n\n

    \u793a\u4f8b 3:

    \n\n
    \n\u8f93\u5165: "zab"\n\u8f93\u51fa: 6\n\u89e3\u91ca: \u5728\u5b57\u7b26\u4e32 S \u4e2d\u6709\u516d\u4e2a\u5b50\u4e32“z”\u3001“a”\u3001“b”\u3001“za”\u3001“ab”\u3001“zab”\u3002.\n
    \n\n

     

    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findSubstringInWraproundString(string p) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findSubstringInWraproundString(String p) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findSubstringInWraproundString(self, p):\n \"\"\"\n :type p: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findSubstringInWraproundString(self, p: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findSubstringInWraproundString(char * p){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindSubstringInWraproundString(string p) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} p\n * @return {number}\n */\nvar findSubstringInWraproundString = function(p) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} p\n# @return {Integer}\ndef find_substring_in_wrapround_string(p)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findSubstringInWraproundString(_ p: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findSubstringInWraproundString(p string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findSubstringInWraproundString(p: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findSubstringInWraproundString(p: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_substring_in_wrapround_string(p: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $p\n * @return Integer\n */\n function findSubstringInWraproundString($p) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findSubstringInWraproundString(p: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-substring-in-wrapround-string p)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0467](https://leetcode-cn.com/problems/unique-substrings-in-wraparound-string)", "[\u73af\u7ed5\u5b57\u7b26\u4e32\u4e2d\u552f\u4e00\u7684\u5b50\u5b57\u7b26\u4e32](/solution/0400-0499/0467.Unique%20Substrings%20in%20Wraparound%20String/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0467](https://leetcode.com/problems/unique-substrings-in-wraparound-string)", "[Unique Substrings in Wraparound String](/solution/0400-0499/0467.Unique%20Substrings%20in%20Wraparound%20String/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0466", "frontend_question_id": "0466", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-the-repetitions", "url_en": "https://leetcode.com/problems/count-the-repetitions", "relative_path_cn": "/solution/0400-0499/0466.Count%20The%20Repetitions/README.md", "relative_path_en": "/solution/0400-0499/0466.Count%20The%20Repetitions/README_EN.md", "title_cn": "\u7edf\u8ba1\u91cd\u590d\u4e2a\u6570", "title_en": "Count The Repetitions", "question_title_slug": "count-the-repetitions", "content_en": "

    We define str = [s, n] as the string str which consists of the string s concatenated n times.

    \n\n
      \n\t
    • For example, str == ["abc", 3] =="abcabcabc".
    • \n
    \n\n

    We define that string s1 can be obtained from string s2 if we can remove some characters from s2 such that it becomes s1.

    \n\n
      \n\t
    • For example, s1 = "abc" can be obtained from s2 = "abdbec" based on our definition by removing the bolded underlined characters.
    • \n
    \n\n

    You are given two strings s1 and s2 and two integers n1 and n2. You have the two strings str1 = [s1, n1] and str2 = [s2, n2].

    \n\n

    Return the maximum integer m such that str = [str2, m] can be obtained from str1.

    \n\n

     

    \n

    Example 1:

    \n
    Input: s1 = \"acb\", n1 = 4, s2 = \"ab\", n2 = 2\nOutput: 2\n

    Example 2:

    \n
    Input: s1 = \"acb\", n1 = 1, s2 = \"acb\", n2 = 1\nOutput: 1\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s1.length, s2.length <= 100
    • \n\t
    • s1 and s2 consist of lowercase English letters.
    • \n\t
    • 1 <= n1, n2 <= 106
    • \n
    \n", "content_cn": "

    \u5b9a\u4e49 str = [s, n] \u8868\u793a str \u7531 n \u4e2a\u5b57\u7b26\u4e32 s \u8fde\u63a5\u6784\u6210\u3002

    \n\n
      \n\t
    • \u4f8b\u5982\uff0cstr == [\"abc\", 3] ==\"abcabcabc\" \u3002
    • \n
    \n\n

    \u5982\u679c\u53ef\u4ee5\u4ece s2\u00a0\u4e2d\u5220\u9664\u67d0\u4e9b\u5b57\u7b26\u4f7f\u5176\u53d8\u4e3a s1\uff0c\u5219\u79f0\u5b57\u7b26\u4e32 s1\u00a0\u53ef\u4ee5\u4ece\u5b57\u7b26\u4e32 s2 \u83b7\u5f97\u3002

    \n\n
      \n\t
    • \u4f8b\u5982\uff0c\u6839\u636e\u5b9a\u4e49\uff0cs1 = \"abc\" \u53ef\u4ee5\u4ece s2 = \"abdbec\" \u83b7\u5f97\uff0c\u4ec5\u9700\u8981\u5220\u9664\u52a0\u7c97\u4e14\u7528\u659c\u4f53\u6807\u8bc6\u7684\u5b57\u7b26\u3002
    • \n
    \n\n

    \u73b0\u5728\u7ed9\u4f60\u4e24\u4e2a\u5b57\u7b26\u4e32 s1\u00a0\u548c s2 \u548c\u4e24\u4e2a\u6574\u6570 n1 \u548c n2 \u3002\u7531\u6b64\u6784\u9020\u5f97\u5230\u4e24\u4e2a\u5b57\u7b26\u4e32\uff0c\u5176\u4e2d str1 = [s1, n1]\u3001str2 = [s2, n2] \u3002

    \n\n

    \u8bf7\u4f60\u627e\u51fa\u4e00\u4e2a\u6700\u5927\u6574\u6570 m \uff0c\u4ee5\u6ee1\u8db3 str = [str2, m] \u53ef\u4ee5\u4ece str1\u00a0\u83b7\u5f97\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as1 = \"acb\", n1 = 4, s2 = \"ab\", n2 = 2\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as1 = \"acb\", n1 = 1, s2 = \"acb\", n2 = 1\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s1.length, s2.length <= 100
    • \n\t
    • s1 \u548c s2 \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n\t
    • 1 <= n1, n2 <= 106
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int getMaxRepetitions(string s1, int n1, string s2, int n2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int getMaxRepetitions(String s1, int n1, String s2, int n2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getMaxRepetitions(self, s1, n1, s2, n2):\n \"\"\"\n :type s1: str\n :type n1: int\n :type s2: str\n :type n2: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getMaxRepetitions(self, s1: str, n1: int, s2: str, n2: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint getMaxRepetitions(char * s1, int n1, char * s2, int n2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int GetMaxRepetitions(string s1, int n1, string s2, int n2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s1\n * @param {number} n1\n * @param {string} s2\n * @param {number} n2\n * @return {number}\n */\nvar getMaxRepetitions = function(s1, n1, s2, n2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s1\n# @param {Integer} n1\n# @param {String} s2\n# @param {Integer} n2\n# @return {Integer}\ndef get_max_repetitions(s1, n1, s2, n2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getMaxRepetitions(_ s1: String, _ n1: Int, _ s2: String, _ n2: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getMaxRepetitions(s1 string, n1 int, s2 string, n2 int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getMaxRepetitions(s1: String, n1: Int, s2: String, n2: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getMaxRepetitions(s1: String, n1: Int, s2: String, n2: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_max_repetitions(s1: String, n1: i32, s2: String, n2: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s1\n * @param Integer $n1\n * @param String $s2\n * @param Integer $n2\n * @return Integer\n */\n function getMaxRepetitions($s1, $n1, $s2, $n2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getMaxRepetitions(s1: string, n1: number, s2: string, n2: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-max-repetitions s1 n1 s2 n2)\n (-> string? exact-integer? string? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0466](https://leetcode-cn.com/problems/count-the-repetitions)", "[\u7edf\u8ba1\u91cd\u590d\u4e2a\u6570](/solution/0400-0499/0466.Count%20The%20Repetitions/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0466](https://leetcode.com/problems/count-the-repetitions)", "[Count The Repetitions](/solution/0400-0499/0466.Count%20The%20Repetitions/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "0465", "frontend_question_id": "0465", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/optimal-account-balancing", "url_en": "https://leetcode.com/problems/optimal-account-balancing", "relative_path_cn": "/solution/0400-0499/0465.Optimal%20Account%20Balancing/README.md", "relative_path_en": "/solution/0400-0499/0465.Optimal%20Account%20Balancing/README_EN.md", "title_cn": "\u6700\u4f18\u8d26\u5355\u5e73\u8861", "title_en": "Optimal Account Balancing", "question_title_slug": "optimal-account-balancing", "content_en": "

    You are given an array of transactions transactions where transactions[i] = [fromi, toi, amounti] indicates that the person with ID = fromi gave amounti $ to the person with ID = toi.

    \n\n

    Return the minimum number of transactions required to settle the debt.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: transactions = [[0,1,10],[2,0,5]]\nOutput: 2\nExplanation:\nPerson #0 gave person #1 $10.\nPerson #2 gave person #0 $5.\nTwo transactions are needed. One way to settle the debt is person #1 pays person #0 and #2 $5 each.\n
    \n\n

    Example 2:

    \n\n
    \nInput: transactions = [[0,1,10],[1,0,1],[1,2,5],[2,0,5]]\nOutput: 1\nExplanation:\nPerson #0 gave person #1 $10.\nPerson #1 gave person #0 $1.\nPerson #1 gave person #2 $5.\nPerson #2 gave person #0 $5.\nTherefore, person #1 only need to give person #0 $4, and all debt is settled.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= transactions.length <= 8
    • \n\t
    • transactions[i].length == 3
    • \n\t
    • 0 <= fromi, toi <= 20
    • \n\t
    • fromi != toi
    • \n\t
    • 1 <= amounti <= 100
    • \n
    \n", "content_cn": "

    \u4e00\u7fa4\u670b\u53cb\u5728\u5ea6\u5047\u671f\u95f4\u4f1a\u76f8\u4e92\u501f\u94b1\u3002\u6bd4\u5982\u8bf4\uff0c\u5c0f\u7231\u540c\u5b66\u652f\u4ed8\u4e86\u5c0f\u65b0\u540c\u5b66\u7684\u5348\u9910\u5171\u8ba1 10 \u7f8e\u5143\u3002\u5982\u679c\u5c0f\u660e\u540c\u5b66\u652f\u4ed8\u4e86\u5c0f\u7231\u540c\u5b66\u7684\u51fa\u79df\u8f66\u94b1\u5171\u8ba1 5 \u7f8e\u5143\u3002\u6211\u4eec\u53ef\u4ee5\u7528\u4e00\u4e2a\u4e09\u5143\u7ec4 (x, y, z) \u8868\u793a\u4e00\u6b21\u4ea4\u6613\uff0c\u8868\u793a x \u501f\u7ed9 y \u5171\u8ba1 z \u7f8e\u5143\u3002\u7528 0, 1, 2 \u8868\u793a\u5c0f\u7231\u540c\u5b66\u3001\u5c0f\u65b0\u540c\u5b66\u548c\u5c0f\u660e\u540c\u5b66\uff080, 1, 2 \u4e3a\u4eba\u7684\u6807\u53f7\uff09\uff0c\u4e0a\u8ff0\u4ea4\u6613\u53ef\u4ee5\u8868\u793a\u4e3a [[0, 1, 10], [2, 0, 5]]\u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u7fa4\u4eba\u4e4b\u95f4\u7684\u4ea4\u6613\u4fe1\u606f\u5217\u8868\uff0c\u8ba1\u7b97\u80fd\u591f\u8fd8\u6e05\u6240\u6709\u503a\u52a1\u7684\u6700\u5c0f\u6b21\u6570\u3002

    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    1. \u4e00\u6b21\u4ea4\u6613\u4f1a\u4ee5\u4e09\u5143\u7ec4 (x, y, z) \u8868\u793a\uff0c\u5e76\u6709 x ≠ y \u4e14 z > 0\u3002
    2. \n\t
    3. \u4eba\u7684\u6807\u53f7\u53ef\u80fd\u4e0d\u662f\u6309\u987a\u5e8f\u7684\uff0c\u4f8b\u5982\u6807\u53f7\u53ef\u80fd\u4e3a 0, 1, 2 \u4e5f\u53ef\u80fd\u4e3a 0, 2, 6\u3002
    4. \n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a\n[[0,1,10], [2,0,5]]\n\n\u8f93\u51fa\uff1a\n2\n\n\u89e3\u91ca\uff1a\n\u4eba #0 \u7ed9\u4eba #1 \u5171\u8ba1 10 \u7f8e\u5143\u3002\n\u4eba #2 \u7ed9\u4eba #0 \u5171\u8ba1 5 \u7f8e\u5143\u3002\n\n\u9700\u8981\u4e24\u6b21\u4ea4\u6613\u3002\u4e00\u79cd\u65b9\u5f0f\u662f\u4eba #1 \u5206\u522b\u7ed9\u4eba #0 \u548c\u4eba #2 \u5404 5 \u7f8e\u5143\u3002\n
    \n\n

     

    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a\n[[0,1,10], [1,0,1], [1,2,5], [2,0,5]]\n\n\u8f93\u51fa\uff1a\n1\n\n\u89e3\u91ca\uff1a\n\u4eba #0 \u7ed9\u4eba #1 \u5171\u8ba1 10 \u7f8e\u5143\u3002Person #0 gave person #1 $10.\n\u4eba #1 \u7ed9\u4eba #0 \u5171\u8ba1 1 \u7f8e\u5143\u3002Person #1 gave person #0 $1.\n\u4eba #1 \u7ed9\u4eba #2 \u5171\u8ba1 5 \u7f8e\u5143\u3002Person #1 gave person #2 $5.\n\u4eba #2 \u7ed9\u4eba #0 \u5171\u8ba1 5 \u7f8e\u5143\u3002Person #2 gave person #0 $5.\n\n\u56e0\u6b64\uff0c\u4eba #1 \u9700\u8981\u7ed9\u4eba #0 \u5171\u8ba1 4 \u7f8e\u5143\uff0c\u6240\u6709\u7684\u503a\u52a1\u5373\u53ef\u8fd8\u6e05\u3002\n
    \n\n

     

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minTransfers(vector>& transactions) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minTransfers(int[][] transactions) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minTransfers(self, transactions):\n \"\"\"\n :type transactions: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minTransfers(self, transactions: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minTransfers(int** transactions, int transactionsSize, int* transactionsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinTransfers(int[][] transactions) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} transactions\n * @return {number}\n */\nvar minTransfers = function(transactions) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} transactions\n# @return {Integer}\ndef min_transfers(transactions)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minTransfers(_ transactions: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minTransfers(transactions [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minTransfers(transactions: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minTransfers(transactions: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_transfers(transactions: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $transactions\n * @return Integer\n */\n function minTransfers($transactions) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minTransfers(transactions: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-transfers transactions)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0465](https://leetcode-cn.com/problems/optimal-account-balancing)", "[\u6700\u4f18\u8d26\u5355\u5e73\u8861](/solution/0400-0499/0465.Optimal%20Account%20Balancing/README.md)", "", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0465](https://leetcode.com/problems/optimal-account-balancing)", "[Optimal Account Balancing](/solution/0400-0499/0465.Optimal%20Account%20Balancing/README_EN.md)", "", "Hard", "\ud83d\udd12"]}, {"question_id": "0464", "frontend_question_id": "0464", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/can-i-win", "url_en": "https://leetcode.com/problems/can-i-win", "relative_path_cn": "/solution/0400-0499/0464.Can%20I%20Win/README.md", "relative_path_en": "/solution/0400-0499/0464.Can%20I%20Win/README_EN.md", "title_cn": "\u6211\u80fd\u8d62\u5417", "title_en": "Can I Win", "question_title_slug": "can-i-win", "content_en": "

    In the "100 game" two players take turns adding, to a running total, any integer from 1 to 10. The player who first causes the running total to reach or exceed 100 wins.

    \n\n

    What if we change the game so that players cannot re-use integers?

    \n\n

    For example, two players might take turns drawing from a common pool of numbers from 1 to 15 without replacement until they reach a total >= 100.

    \n\n

    Given two integers maxChoosableInteger and desiredTotal, return true if the first player to move can force a win, otherwise, return false. Assume both players play optimally.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: maxChoosableInteger = 10, desiredTotal = 11\nOutput: false\nExplanation:\nNo matter which integer the first player choose, the first player will lose.\nThe first player can choose an integer from 1 up to 10.\nIf the first player choose 1, the second player can only choose integers from 2 up to 10.\nThe second player will win by choosing 10 and get a total = 11, which is >= desiredTotal.\nSame with other integers chosen by the first player, the second player will always win.\n
    \n\n

    Example 2:

    \n\n
    \nInput: maxChoosableInteger = 10, desiredTotal = 0\nOutput: true\n
    \n\n

    Example 3:

    \n\n
    \nInput: maxChoosableInteger = 10, desiredTotal = 1\nOutput: true\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= maxChoosableInteger <= 20
    • \n\t
    • 0 <= desiredTotal <= 300
    • \n
    \n", "content_cn": "

    \u5728 "100 game" \u8fd9\u4e2a\u6e38\u620f\u4e2d\uff0c\u4e24\u540d\u73a9\u5bb6\u8f6e\u6d41\u9009\u62e9\u4ece 1 \u5230 10 \u7684\u4efb\u610f\u6574\u6570\uff0c\u7d2f\u8ba1\u6574\u6570\u548c\uff0c\u5148\u4f7f\u5f97\u7d2f\u8ba1\u6574\u6570\u548c\u8fbe\u5230\u6216\u8d85\u8fc7 100 \u7684\u73a9\u5bb6\uff0c\u5373\u4e3a\u80dc\u8005\u3002

    \n\n

    \u5982\u679c\u6211\u4eec\u5c06\u6e38\u620f\u89c4\u5219\u6539\u4e3a “\u73a9\u5bb6\u4e0d\u80fd\u91cd\u590d\u4f7f\u7528\u6574\u6570” \u5462\uff1f

    \n\n

    \u4f8b\u5982\uff0c\u4e24\u4e2a\u73a9\u5bb6\u53ef\u4ee5\u8f6e\u6d41\u4ece\u516c\u5171\u6574\u6570\u6c60\u4e2d\u62bd\u53d6\u4ece 1 \u5230 15 \u7684\u6574\u6570\uff08\u4e0d\u653e\u56de\uff09\uff0c\u76f4\u5230\u7d2f\u8ba1\u6574\u6570\u548c >= 100\u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570 maxChoosableInteger \uff08\u6574\u6570\u6c60\u4e2d\u53ef\u9009\u62e9\u7684\u6700\u5927\u6570\uff09\u548c\u53e6\u4e00\u4e2a\u6574\u6570 desiredTotal\uff08\u7d2f\u8ba1\u548c\uff09\uff0c\u5224\u65ad\u5148\u51fa\u624b\u7684\u73a9\u5bb6\u662f\u5426\u80fd\u7a33\u8d62\uff08\u5047\u8bbe\u4e24\u4f4d\u73a9\u5bb6\u6e38\u620f\u65f6\u90fd\u8868\u73b0\u6700\u4f73\uff09\uff1f

    \n\n

    \u4f60\u53ef\u4ee5\u5047\u8bbe maxChoosableInteger \u4e0d\u4f1a\u5927\u4e8e 20\uff0c desiredTotal \u4e0d\u4f1a\u5927\u4e8e 300\u3002

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1a\nmaxChoosableInteger = 10\ndesiredTotal = 11\n\n\u8f93\u51fa\uff1a\nfalse\n\n\u89e3\u91ca\uff1a\n\u65e0\u8bba\u7b2c\u4e00\u4e2a\u73a9\u5bb6\u9009\u62e9\u54ea\u4e2a\u6574\u6570\uff0c\u4ed6\u90fd\u4f1a\u5931\u8d25\u3002\n\u7b2c\u4e00\u4e2a\u73a9\u5bb6\u53ef\u4ee5\u9009\u62e9\u4ece 1 \u5230 10 \u7684\u6574\u6570\u3002\n\u5982\u679c\u7b2c\u4e00\u4e2a\u73a9\u5bb6\u9009\u62e9 1\uff0c\u90a3\u4e48\u7b2c\u4e8c\u4e2a\u73a9\u5bb6\u53ea\u80fd\u9009\u62e9\u4ece 2 \u5230 10 \u7684\u6574\u6570\u3002\n\u7b2c\u4e8c\u4e2a\u73a9\u5bb6\u53ef\u4ee5\u901a\u8fc7\u9009\u62e9\u6574\u6570 10\uff08\u90a3\u4e48\u7d2f\u79ef\u548c\u4e3a 11 >= desiredTotal\uff09\uff0c\u4ece\u800c\u53d6\u5f97\u80dc\u5229.\n\u540c\u6837\u5730\uff0c\u7b2c\u4e00\u4e2a\u73a9\u5bb6\u9009\u62e9\u4efb\u610f\u5176\u4ed6\u6574\u6570\uff0c\u7b2c\u4e8c\u4e2a\u73a9\u5bb6\u90fd\u4f1a\u8d62\u3002\n
    \n", "tags_en": ["Minimax", "Dynamic Programming"], "tags_cn": ["\u6781\u5c0f\u5316\u6781\u5927", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canIWin(int maxChoosableInteger, int desiredTotal) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canIWin(int maxChoosableInteger, int desiredTotal) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canIWin(self, maxChoosableInteger, desiredTotal):\n \"\"\"\n :type maxChoosableInteger: int\n :type desiredTotal: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canIWin(self, maxChoosableInteger: int, desiredTotal: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canIWin(int maxChoosableInteger, int desiredTotal){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanIWin(int maxChoosableInteger, int desiredTotal) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} maxChoosableInteger\n * @param {number} desiredTotal\n * @return {boolean}\n */\nvar canIWin = function(maxChoosableInteger, desiredTotal) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} max_choosable_integer\n# @param {Integer} desired_total\n# @return {Boolean}\ndef can_i_win(max_choosable_integer, desired_total)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canIWin(_ maxChoosableInteger: Int, _ desiredTotal: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canIWin(maxChoosableInteger int, desiredTotal int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canIWin(maxChoosableInteger: Int, desiredTotal: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canIWin(maxChoosableInteger: Int, desiredTotal: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_i_win(max_choosable_integer: i32, desired_total: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $maxChoosableInteger\n * @param Integer $desiredTotal\n * @return Boolean\n */\n function canIWin($maxChoosableInteger, $desiredTotal) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canIWin(maxChoosableInteger: number, desiredTotal: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-i-win maxChoosableInteger desiredTotal)\n (-> exact-integer? exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0464](https://leetcode-cn.com/problems/can-i-win)", "[\u6211\u80fd\u8d62\u5417](/solution/0400-0499/0464.Can%20I%20Win/README.md)", "`\u6781\u5c0f\u5316\u6781\u5927`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0464](https://leetcode.com/problems/can-i-win)", "[Can I Win](/solution/0400-0499/0464.Can%20I%20Win/README_EN.md)", "`Minimax`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0463", "frontend_question_id": "0463", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/island-perimeter", "url_en": "https://leetcode.com/problems/island-perimeter", "relative_path_cn": "/solution/0400-0499/0463.Island%20Perimeter/README.md", "relative_path_en": "/solution/0400-0499/0463.Island%20Perimeter/README_EN.md", "title_cn": "\u5c9b\u5c7f\u7684\u5468\u957f", "title_en": "Island Perimeter", "question_title_slug": "island-perimeter", "content_en": "

    You are given row x col grid representing a map where grid[i][j] = 1 represents land and grid[i][j] = 0 represents water.

    \n\n

    Grid cells are connected horizontally/vertically (not diagonally). The grid is completely surrounded by water, and there is exactly one island (i.e., one or more connected land cells).

    \n\n

    The island doesn't have "lakes", meaning the water inside isn't connected to the water around the island. One cell is a square with side length 1. The grid is rectangular, width and height don't exceed 100. Determine the perimeter of the island.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: grid = [[0,1,0,0],[1,1,1,0],[0,1,0,0],[1,1,0,0]]\nOutput: 16\nExplanation: The perimeter is the 16 yellow stripes in the image above.\n
    \n\n

    Example 2:

    \n\n
    \nInput: grid = [[1]]\nOutput: 4\n
    \n\n

    Example 3:

    \n\n
    \nInput: grid = [[1,0]]\nOutput: 4\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • row == grid.length
    • \n\t
    • col == grid[i].length
    • \n\t
    • 1 <= row, col <= 100
    • \n\t
    • grid[i][j] is 0 or 1.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a row x col \u7684\u4e8c\u7ef4\u7f51\u683c\u5730\u56fe grid \uff0c\u5176\u4e2d\uff1agrid[i][j] = 1 \u8868\u793a\u9646\u5730\uff0c grid[i][j] = 0 \u8868\u793a\u6c34\u57df\u3002

    \n\n

    \u7f51\u683c\u4e2d\u7684\u683c\u5b50 \u6c34\u5e73\u548c\u5782\u76f4 \u65b9\u5411\u76f8\u8fde\uff08\u5bf9\u89d2\u7ebf\u65b9\u5411\u4e0d\u76f8\u8fde\uff09\u3002\u6574\u4e2a\u7f51\u683c\u88ab\u6c34\u5b8c\u5168\u5305\u56f4\uff0c\u4f46\u5176\u4e2d\u6070\u597d\u6709\u4e00\u4e2a\u5c9b\u5c7f\uff08\u6216\u8005\u8bf4\uff0c\u4e00\u4e2a\u6216\u591a\u4e2a\u8868\u793a\u9646\u5730\u7684\u683c\u5b50\u76f8\u8fde\u7ec4\u6210\u7684\u5c9b\u5c7f\uff09\u3002

    \n\n

    \u5c9b\u5c7f\u4e2d\u6ca1\u6709\u201c\u6e56\u201d\uff08\u201c\u6e56\u201d \u6307\u6c34\u57df\u5728\u5c9b\u5c7f\u5185\u90e8\u4e14\u4e0d\u548c\u5c9b\u5c7f\u5468\u56f4\u7684\u6c34\u76f8\u8fde\uff09\u3002\u683c\u5b50\u662f\u8fb9\u957f\u4e3a 1 \u7684\u6b63\u65b9\u5f62\u3002\u7f51\u683c\u4e3a\u957f\u65b9\u5f62\uff0c\u4e14\u5bbd\u5ea6\u548c\u9ad8\u5ea6\u5747\u4e0d\u8d85\u8fc7 100 \u3002\u8ba1\u7b97\u8fd9\u4e2a\u5c9b\u5c7f\u7684\u5468\u957f\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \n\n
    \n\u8f93\u5165\uff1agrid = [[0,1,0,0],[1,1,1,0],[0,1,0,0],[1,1,0,0]]\n\u8f93\u51fa\uff1a16\n\u89e3\u91ca\uff1a\u5b83\u7684\u5468\u957f\u662f\u4e0a\u9762\u56fe\u7247\u4e2d\u7684 16 \u4e2a\u9ec4\u8272\u7684\u8fb9
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1agrid = [[1]]\n\u8f93\u51fa\uff1a4\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1agrid = [[1,0]]\n\u8f93\u51fa\uff1a4\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • row == grid.length
    • \n\t
    • col == grid[i].length
    • \n\t
    • 1 <= row, col <= 100
    • \n\t
    • grid[i][j] \u4e3a 0 \u6216 1
    • \n
    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int islandPerimeter(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int islandPerimeter(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def islandPerimeter(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def islandPerimeter(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint islandPerimeter(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int IslandPerimeter(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar islandPerimeter = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef island_perimeter(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func islandPerimeter(_ grid: [[Int]]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func islandPerimeter(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def islandPerimeter(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun islandPerimeter(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn island_perimeter(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function islandPerimeter($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function islandPerimeter(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (island-perimeter grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0463](https://leetcode-cn.com/problems/island-perimeter)", "[\u5c9b\u5c7f\u7684\u5468\u957f](/solution/0400-0499/0463.Island%20Perimeter/README.md)", "`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0463](https://leetcode.com/problems/island-perimeter)", "[Island Perimeter](/solution/0400-0499/0463.Island%20Perimeter/README_EN.md)", "`Hash Table`", "Easy", ""]}, {"question_id": "0462", "frontend_question_id": "0462", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-moves-to-equal-array-elements-ii", "url_en": "https://leetcode.com/problems/minimum-moves-to-equal-array-elements-ii", "relative_path_cn": "/solution/0400-0499/0462.Minimum%20Moves%20to%20Equal%20Array%20Elements%20II/README.md", "relative_path_en": "/solution/0400-0499/0462.Minimum%20Moves%20to%20Equal%20Array%20Elements%20II/README_EN.md", "title_cn": "\u6700\u5c11\u79fb\u52a8\u6b21\u6570\u4f7f\u6570\u7ec4\u5143\u7d20\u76f8\u7b49 II", "title_en": "Minimum Moves to Equal Array Elements II", "question_title_slug": "minimum-moves-to-equal-array-elements-ii", "content_en": "

    Given an integer array nums of size n, return the minimum number of moves required to make all array elements equal.

    \n\n

    In one move, you can increment or decrement an element of the array by 1.

    \n\n

    Test cases are designed so that the answer will fit in a 32-bit integer.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,3]\nOutput: 2\nExplanation:\nOnly two moves are needed (remember each move increments or decrements one element):\n[1,2,3]  =>  [2,2,3]  =>  [2,2,2]\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,10,2,9]\nOutput: 16\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • -109 <= nums[i] <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u7a7a\u6574\u6570\u6570\u7ec4\uff0c\u627e\u5230\u4f7f\u6240\u6709\u6570\u7ec4\u5143\u7d20\u76f8\u7b49\u6240\u9700\u7684\u6700\u5c0f\u79fb\u52a8\u6570\uff0c\u5176\u4e2d\u6bcf\u6b21\u79fb\u52a8\u53ef\u5c06\u9009\u5b9a\u7684\u4e00\u4e2a\u5143\u7d20\u52a01\u6216\u51cf1\u3002 \u60a8\u53ef\u4ee5\u5047\u8bbe\u6570\u7ec4\u7684\u957f\u5ea6\u6700\u591a\u4e3a10000\u3002

    \n\n

    \u4f8b\u5982:

    \n\n
    \n\u8f93\u5165:\n[1,2,3]\n\n\u8f93\u51fa:\n2\n\n\u8bf4\u660e\uff1a\n\u53ea\u6709\u4e24\u4e2a\u52a8\u4f5c\u662f\u5fc5\u8981\u7684\uff08\u8bb0\u5f97\u6bcf\u4e00\u6b65\u4ec5\u53ef\u4f7f\u5176\u4e2d\u4e00\u4e2a\u5143\u7d20\u52a01\u6216\u51cf1\uff09\uff1a \n\n[1,2,3]  =>  [2,2,3]  =>  [2,2,2]\n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minMoves2(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minMoves2(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minMoves2(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minMoves2(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minMoves2(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinMoves2(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar minMoves2 = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef min_moves2(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minMoves2(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minMoves2(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minMoves2(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minMoves2(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_moves2(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function minMoves2($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minMoves2(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-moves2 nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0462](https://leetcode-cn.com/problems/minimum-moves-to-equal-array-elements-ii)", "[\u6700\u5c11\u79fb\u52a8\u6b21\u6570\u4f7f\u6570\u7ec4\u5143\u7d20\u76f8\u7b49 II](/solution/0400-0499/0462.Minimum%20Moves%20to%20Equal%20Array%20Elements%20II/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0462](https://leetcode.com/problems/minimum-moves-to-equal-array-elements-ii)", "[Minimum Moves to Equal Array Elements II](/solution/0400-0499/0462.Minimum%20Moves%20to%20Equal%20Array%20Elements%20II/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "0461", "frontend_question_id": "0461", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/hamming-distance", "url_en": "https://leetcode.com/problems/hamming-distance", "relative_path_cn": "/solution/0400-0499/0461.Hamming%20Distance/README.md", "relative_path_en": "/solution/0400-0499/0461.Hamming%20Distance/README_EN.md", "title_cn": "\u6c49\u660e\u8ddd\u79bb", "title_en": "Hamming Distance", "question_title_slug": "hamming-distance", "content_en": "

    The Hamming distance between two integers is the number of positions at which the corresponding bits are different.

    \n\n

    Given two integers x and y, return the Hamming distance between them.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: x = 1, y = 4\nOutput: 2\nExplanation:\n1   (0 0 0 1)\n4   (0 1 0 0)\n       ↑   ↑\nThe above arrows point to positions where the corresponding bits are different.\n
    \n\n

    Example 2:

    \n\n
    \nInput: x = 3, y = 1\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= x, y <= 231 - 1
    • \n
    \n", "content_cn": "

    \u4e24\u4e2a\u6574\u6570\u4e4b\u95f4\u7684 \u6c49\u660e\u8ddd\u79bb \u6307\u7684\u662f\u8fd9\u4e24\u4e2a\u6570\u5b57\u5bf9\u5e94\u4e8c\u8fdb\u5236\u4f4d\u4e0d\u540c\u7684\u4f4d\u7f6e\u7684\u6570\u76ee\u3002

    \n\n

    \u7ed9\u4f60\u4e24\u4e2a\u6574\u6570 x \u548c y\uff0c\u8ba1\u7b97\u5e76\u8fd4\u56de\u5b83\u4eec\u4e4b\u95f4\u7684\u6c49\u660e\u8ddd\u79bb\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1ax = 1, y = 4\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n1   (0 0 0 1)\n4   (0 1 0 0)\n       \u2191   \u2191\n\u4e0a\u9762\u7684\u7bad\u5934\u6307\u51fa\u4e86\u5bf9\u5e94\u4e8c\u8fdb\u5236\u4f4d\u4e0d\u540c\u7684\u4f4d\u7f6e\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1ax = 3, y = 1\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <=\u00a0x, y <= 231 - 1
    • \n
    \n", "tags_en": ["Bit Manipulation"], "tags_cn": ["\u4f4d\u8fd0\u7b97"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int hammingDistance(int x, int y) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int hammingDistance(int x, int y) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def hammingDistance(self, x, y):\n \"\"\"\n :type x: int\n :type y: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def hammingDistance(self, x: int, y: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint hammingDistance(int x, int y){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int HammingDistance(int x, int y) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} x\n * @param {number} y\n * @return {number}\n */\nvar hammingDistance = function(x, y) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} x\n# @param {Integer} y\n# @return {Integer}\ndef hamming_distance(x, y)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func hammingDistance(_ x: Int, _ y: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func hammingDistance(x int, y int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def hammingDistance(x: Int, y: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun hammingDistance(x: Int, y: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn hamming_distance(x: i32, y: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $x\n * @param Integer $y\n * @return Integer\n */\n function hammingDistance($x, $y) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function hammingDistance(x: number, y: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (hamming-distance x y)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0461](https://leetcode-cn.com/problems/hamming-distance)", "[\u6c49\u660e\u8ddd\u79bb](/solution/0400-0499/0461.Hamming%20Distance/README.md)", "`\u4f4d\u8fd0\u7b97`", "\u7b80\u5355", ""], "md_table_row_en": ["[0461](https://leetcode.com/problems/hamming-distance)", "[Hamming Distance](/solution/0400-0499/0461.Hamming%20Distance/README_EN.md)", "`Bit Manipulation`", "Easy", ""]}, {"question_id": "0460", "frontend_question_id": "0460", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/lfu-cache", "url_en": "https://leetcode.com/problems/lfu-cache", "relative_path_cn": "/solution/0400-0499/0460.LFU%20Cache/README.md", "relative_path_en": "/solution/0400-0499/0460.LFU%20Cache/README_EN.md", "title_cn": "LFU \u7f13\u5b58", "title_en": "LFU Cache", "question_title_slug": "lfu-cache", "content_en": "

    Design and implement a data structure for a Least Frequently Used (LFU) cache.

    \n\n

    Implement the LFUCache class:

    \n\n
      \n\t
    • LFUCache(int capacity) Initializes the object with the capacity of the data structure.
    • \n\t
    • int get(int key) Gets the value of the key if the key exists in the cache. Otherwise, returns -1.
    • \n\t
    • void put(int key, int value) Update the value of the key if present, or inserts the key if not already present. When the cache reaches its capacity, it should invalidate and remove the least frequently used key before inserting a new item. For this problem, when there is a tie (i.e., two or more keys with the same frequency), the least recently used key would be invalidated.
    • \n
    \n\n

    To determine the least frequently used key, a use counter is maintained for each key in the cache. The key with the smallest use counter is the least frequently used key.

    \n\n

    When a key is first inserted into the cache, its use counter is set to 1 (due to the put operation). The use counter for a key in the cache is incremented either a get or put operation is called on it.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["LFUCache", "put", "put", "get", "put", "get", "get", "put", "get", "get", "get"]\n[[2], [1, 1], [2, 2], [1], [3, 3], [2], [3], [4, 4], [1], [3], [4]]\nOutput\n[null, null, null, 1, null, -1, 3, null, -1, 3, 4]\n\nExplanation\n// cnt(x) = the use counter for key x\n// cache=[] will show the last used order for tiebreakers (leftmost element is  most recent)\nLFUCache lfu = new LFUCache(2);\nlfu.put(1, 1);   // cache=[1,_], cnt(1)=1\nlfu.put(2, 2);   // cache=[2,1], cnt(2)=1, cnt(1)=1\nlfu.get(1);      // return 1\n                 // cache=[1,2], cnt(2)=1, cnt(1)=2\nlfu.put(3, 3);   // 2 is the LFU key because cnt(2)=1 is the smallest, invalidate 2.\n                 // cache=[3,1], cnt(3)=1, cnt(1)=2\nlfu.get(2);      // return -1 (not found)\nlfu.get(3);      // return 3\n                 // cache=[3,1], cnt(3)=2, cnt(1)=2\nlfu.put(4, 4);   // Both 1 and 3 have the same cnt, but 1 is LRU, invalidate 1.\n                 // cache=[4,3], cnt(4)=1, cnt(3)=2\nlfu.get(1);      // return -1 (not found)\nlfu.get(3);      // return 3\n                 // cache=[3,4], cnt(4)=1, cnt(3)=3\nlfu.get(4);      // return 4\n                 // cache=[3,4], cnt(4)=2, cnt(3)=3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= capacity, key, value <= 104
    • \n\t
    • At most 105 calls will be made to get and put.
    • \n
    \n\n

     

    \nFollow up: Could you do both operations in O(1) time complexity? ", "content_cn": "

    \u8bf7\u4f60\u4e3a \u6700\u4e0d\u7ecf\u5e38\u4f7f\u7528\uff08LFU\uff09\u7f13\u5b58\u7b97\u6cd5\u8bbe\u8ba1\u5e76\u5b9e\u73b0\u6570\u636e\u7ed3\u6784\u3002

    \n\n

    \u5b9e\u73b0 LFUCache \u7c7b\uff1a

    \n\n
      \n\t
    • LFUCache(int capacity) - \u7528\u6570\u636e\u7ed3\u6784\u7684\u5bb9\u91cf\u00a0capacity \u521d\u59cb\u5316\u5bf9\u8c61
    • \n\t
    • int get(int key)\u00a0- \u5982\u679c\u952e\u5b58\u5728\u4e8e\u7f13\u5b58\u4e2d\uff0c\u5219\u83b7\u53d6\u952e\u7684\u503c\uff0c\u5426\u5219\u8fd4\u56de -1\u3002
    • \n\t
    • void put(int key, int value)\u00a0- \u5982\u679c\u952e\u5df2\u5b58\u5728\uff0c\u5219\u53d8\u66f4\u5176\u503c\uff1b\u5982\u679c\u952e\u4e0d\u5b58\u5728\uff0c\u8bf7\u63d2\u5165\u952e\u503c\u5bf9\u3002\u5f53\u7f13\u5b58\u8fbe\u5230\u5176\u5bb9\u91cf\u65f6\uff0c\u5219\u5e94\u8be5\u5728\u63d2\u5165\u65b0\u9879\u4e4b\u524d\uff0c\u4f7f\u6700\u4e0d\u7ecf\u5e38\u4f7f\u7528\u7684\u9879\u65e0\u6548\u3002\u5728\u6b64\u95ee\u9898\u4e2d\uff0c\u5f53\u5b58\u5728\u5e73\u5c40\uff08\u5373\u4e24\u4e2a\u6216\u66f4\u591a\u4e2a\u952e\u5177\u6709\u76f8\u540c\u4f7f\u7528\u9891\u7387\uff09\u65f6\uff0c\u5e94\u8be5\u53bb\u9664 \u6700\u8fd1\u6700\u4e45\u672a\u4f7f\u7528 \u7684\u952e\u3002
    • \n
    \n\n

    \u6ce8\u610f\u300c\u9879\u7684\u4f7f\u7528\u6b21\u6570\u300d\u5c31\u662f\u81ea\u63d2\u5165\u8be5\u9879\u4ee5\u6765\u5bf9\u5176\u8c03\u7528 get \u548c put \u51fd\u6570\u7684\u6b21\u6570\u4e4b\u548c\u3002\u4f7f\u7528\u6b21\u6570\u4f1a\u5728\u5bf9\u5e94\u9879\u88ab\u79fb\u9664\u540e\u7f6e\u4e3a 0 \u3002

    \n\n

    \u4e3a\u4e86\u786e\u5b9a\u6700\u4e0d\u5e38\u4f7f\u7528\u7684\u952e\uff0c\u53ef\u4ee5\u4e3a\u7f13\u5b58\u4e2d\u7684\u6bcf\u4e2a\u952e\u7ef4\u62a4\u4e00\u4e2a \u4f7f\u7528\u8ba1\u6570\u5668 \u3002\u4f7f\u7528\u8ba1\u6570\u6700\u5c0f\u7684\u952e\u662f\u6700\u4e45\u672a\u4f7f\u7528\u7684\u952e\u3002

    \n\n

    \u5f53\u4e00\u4e2a\u952e\u9996\u6b21\u63d2\u5165\u5230\u7f13\u5b58\u4e2d\u65f6\uff0c\u5b83\u7684\u4f7f\u7528\u8ba1\u6570\u5668\u88ab\u8bbe\u7f6e\u4e3a 1 (\u7531\u4e8e put \u64cd\u4f5c)\u3002\u5bf9\u7f13\u5b58\u4e2d\u7684\u952e\u6267\u884c get \u6216 put \u64cd\u4f5c\uff0c\u4f7f\u7528\u8ba1\u6570\u5668\u7684\u503c\u5c06\u4f1a\u9012\u589e\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\n[\"LFUCache\", \"put\", \"put\", \"get\", \"put\", \"get\", \"get\", \"put\", \"get\", \"get\", \"get\"]\n[[2], [1, 1], [2, 2], [1], [3, 3], [2], [3], [4, 4], [1], [3], [4]]\n\u8f93\u51fa\uff1a\n[null, null, null, 1, null, -1, 3, null, -1, 3, 4]\n\n\u89e3\u91ca\uff1a\n// cnt(x) = \u952e x \u7684\u4f7f\u7528\u8ba1\u6570\n// cache=[] \u5c06\u663e\u793a\u6700\u540e\u4e00\u6b21\u4f7f\u7528\u7684\u987a\u5e8f\uff08\u6700\u5de6\u8fb9\u7684\u5143\u7d20\u662f\u6700\u8fd1\u7684\uff09\nLFUCache lFUCache = new LFUCache(2);\nlFUCache.put(1, 1);   // cache=[1,_], cnt(1)=1\nlFUCache.put(2, 2);   // cache=[2,1], cnt(2)=1, cnt(1)=1\nlFUCache.get(1);      // \u8fd4\u56de 1\n                      // cache=[1,2], cnt(2)=1, cnt(1)=2\nlFUCache.put(3, 3);   // \u53bb\u9664\u952e 2 \uff0c\u56e0\u4e3a cnt(2)=1 \uff0c\u4f7f\u7528\u8ba1\u6570\u6700\u5c0f\n                      // cache=[3,1], cnt(3)=1, cnt(1)=2\nlFUCache.get(2);      // \u8fd4\u56de -1\uff08\u672a\u627e\u5230\uff09\nlFUCache.get(3);      // \u8fd4\u56de 3\n                      // cache=[3,1], cnt(3)=2, cnt(1)=2\nlFUCache.put(4, 4);   // \u53bb\u9664\u952e 1 \uff0c1 \u548c 3 \u7684 cnt \u76f8\u540c\uff0c\u4f46 1 \u6700\u4e45\u672a\u4f7f\u7528\n                      // cache=[4,3], cnt(4)=1, cnt(3)=2\nlFUCache.get(1);      // \u8fd4\u56de -1\uff08\u672a\u627e\u5230\uff09\nlFUCache.get(3);      // \u8fd4\u56de 3\n                      // cache=[3,4], cnt(4)=1, cnt(3)=3\nlFUCache.get(4);      // \u8fd4\u56de 4\n                      // cache=[3,4], cnt(4)=2, cnt(3)=3
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <=\u00a0capacity, key, value <= 104
    • \n\t
    • \u6700\u591a\u8c03\u7528 105 \u6b21 get \u548c put \u65b9\u6cd5
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u53ef\u4ee5\u4e3a\u8fd9\u4e24\u79cd\u64cd\u4f5c\u8bbe\u8ba1\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(1) \u7684\u5b9e\u73b0\u5417\uff1f

    \n", "tags_en": ["Design"], "tags_cn": ["\u8bbe\u8ba1"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class LFUCache {\npublic:\n LFUCache(int capacity) {\n\n }\n \n int get(int key) {\n\n }\n \n void put(int key, int value) {\n\n }\n};\n\n/**\n * Your LFUCache object will be instantiated and called as such:\n * LFUCache* obj = new LFUCache(capacity);\n * int param_1 = obj->get(key);\n * obj->put(key,value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class LFUCache {\n\n public LFUCache(int capacity) {\n\n }\n \n public int get(int key) {\n\n }\n \n public void put(int key, int value) {\n\n }\n}\n\n/**\n * Your LFUCache object will be instantiated and called as such:\n * LFUCache obj = new LFUCache(capacity);\n * int param_1 = obj.get(key);\n * obj.put(key,value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class LFUCache(object):\n\n def __init__(self, capacity):\n \"\"\"\n :type capacity: int\n \"\"\"\n\n\n def get(self, key):\n \"\"\"\n :type key: int\n :rtype: int\n \"\"\"\n\n\n def put(self, key, value):\n \"\"\"\n :type key: int\n :type value: int\n :rtype: None\n \"\"\"\n\n\n\n# Your LFUCache object will be instantiated and called as such:\n# obj = LFUCache(capacity)\n# param_1 = obj.get(key)\n# obj.put(key,value)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class LFUCache:\n\n def __init__(self, capacity: int):\n\n\n def get(self, key: int) -> int:\n\n\n def put(self, key: int, value: int) -> None:\n\n\n\n# Your LFUCache object will be instantiated and called as such:\n# obj = LFUCache(capacity)\n# param_1 = obj.get(key)\n# obj.put(key,value)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} LFUCache;\n\n\nLFUCache* lFUCacheCreate(int capacity) {\n\n}\n\nint lFUCacheGet(LFUCache* obj, int key) {\n\n}\n\nvoid lFUCachePut(LFUCache* obj, int key, int value) {\n\n}\n\nvoid lFUCacheFree(LFUCache* obj) {\n\n}\n\n/**\n * Your LFUCache struct will be instantiated and called as such:\n * LFUCache* obj = lFUCacheCreate(capacity);\n * int param_1 = lFUCacheGet(obj, key);\n \n * lFUCachePut(obj, key, value);\n \n * lFUCacheFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class LFUCache {\n\n public LFUCache(int capacity) {\n\n }\n \n public int Get(int key) {\n\n }\n \n public void Put(int key, int value) {\n\n }\n}\n\n/**\n * Your LFUCache object will be instantiated and called as such:\n * LFUCache obj = new LFUCache(capacity);\n * int param_1 = obj.Get(key);\n * obj.Put(key,value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} capacity\n */\nvar LFUCache = function(capacity) {\n\n};\n\n/** \n * @param {number} key\n * @return {number}\n */\nLFUCache.prototype.get = function(key) {\n\n};\n\n/** \n * @param {number} key \n * @param {number} value\n * @return {void}\n */\nLFUCache.prototype.put = function(key, value) {\n\n};\n\n/**\n * Your LFUCache object will be instantiated and called as such:\n * var obj = new LFUCache(capacity)\n * var param_1 = obj.get(key)\n * obj.put(key,value)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class LFUCache\n\n=begin\n :type capacity: Integer\n=end\n def initialize(capacity)\n\n end\n\n\n=begin\n :type key: Integer\n :rtype: Integer\n=end\n def get(key)\n\n end\n\n\n=begin\n :type key: Integer\n :type value: Integer\n :rtype: Void\n=end\n def put(key, value)\n\n end\n\n\nend\n\n# Your LFUCache object will be instantiated and called as such:\n# obj = LFUCache.new(capacity)\n# param_1 = obj.get(key)\n# obj.put(key, value)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass LFUCache {\n\n init(_ capacity: Int) {\n\n }\n \n func get(_ key: Int) -> Int {\n\n }\n \n func put(_ key: Int, _ value: Int) {\n\n }\n}\n\n/**\n * Your LFUCache object will be instantiated and called as such:\n * let obj = LFUCache(capacity)\n * let ret_1: Int = obj.get(key)\n * obj.put(key, value)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type LFUCache struct {\n\n}\n\n\nfunc Constructor(capacity int) LFUCache {\n\n}\n\n\nfunc (this *LFUCache) Get(key int) int {\n\n}\n\n\nfunc (this *LFUCache) Put(key int, value int) {\n\n}\n\n\n/**\n * Your LFUCache object will be instantiated and called as such:\n * obj := Constructor(capacity);\n * param_1 := obj.Get(key);\n * obj.Put(key,value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class LFUCache(_capacity: Int) {\n\n def get(key: Int): Int = {\n\n }\n\n def put(key: Int, value: Int) {\n\n }\n\n}\n\n/**\n * Your LFUCache object will be instantiated and called as such:\n * var obj = new LFUCache(capacity)\n * var param_1 = obj.get(key)\n * obj.put(key,value)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class LFUCache(capacity: Int) {\n\n fun get(key: Int): Int {\n\n }\n\n fun put(key: Int, value: Int) {\n\n }\n\n}\n\n/**\n * Your LFUCache object will be instantiated and called as such:\n * var obj = LFUCache(capacity)\n * var param_1 = obj.get(key)\n * obj.put(key,value)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct LFUCache {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl LFUCache {\n\n fn new(capacity: i32) -> Self {\n\n }\n \n fn get(&self, key: i32) -> i32 {\n\n }\n \n fn put(&self, key: i32, value: i32) {\n\n }\n}\n\n/**\n * Your LFUCache object will be instantiated and called as such:\n * let obj = LFUCache::new(capacity);\n * let ret_1: i32 = obj.get(key);\n * obj.put(key, value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class LFUCache {\n /**\n * @param Integer $capacity\n */\n function __construct($capacity) {\n\n }\n\n /**\n * @param Integer $key\n * @return Integer\n */\n function get($key) {\n\n }\n\n /**\n * @param Integer $key\n * @param Integer $value\n * @return NULL\n */\n function put($key, $value) {\n\n }\n}\n\n/**\n * Your LFUCache object will be instantiated and called as such:\n * $obj = LFUCache($capacity);\n * $ret_1 = $obj->get($key);\n * $obj->put($key, $value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class LFUCache {\n constructor(capacity: number) {\n\n }\n\n get(key: number): number {\n\n }\n\n put(key: number, value: number): void {\n\n }\n}\n\n/**\n * Your LFUCache object will be instantiated and called as such:\n * var obj = new LFUCache(capacity)\n * var param_1 = obj.get(key)\n * obj.put(key,value)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define lfu-cache%\n (class object%\n (super-new)\n\n ; capacity : exact-integer?\n (init-field\n capacity)\n \n ; get : exact-integer? -> exact-integer?\n (define/public (get key)\n\n )\n ; put : exact-integer? exact-integer? -> void?\n (define/public (put key value)\n\n )))\n\n;; Your lfu-cache% object will be instantiated and called as such:\n;; (define obj (new lfu-cache% [capacity capacity]))\n;; (define param_1 (send obj get key))\n;; (send obj put key value)", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0460](https://leetcode-cn.com/problems/lfu-cache)", "[LFU \u7f13\u5b58](/solution/0400-0499/0460.LFU%20Cache/README.md)", "`\u8bbe\u8ba1`", "\u56f0\u96be", ""], "md_table_row_en": ["[0460](https://leetcode.com/problems/lfu-cache)", "[LFU Cache](/solution/0400-0499/0460.LFU%20Cache/README_EN.md)", "`Design`", "Hard", ""]}, {"question_id": "0459", "frontend_question_id": "0459", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/repeated-substring-pattern", "url_en": "https://leetcode.com/problems/repeated-substring-pattern", "relative_path_cn": "/solution/0400-0499/0459.Repeated%20Substring%20Pattern/README.md", "relative_path_en": "/solution/0400-0499/0459.Repeated%20Substring%20Pattern/README_EN.md", "title_cn": "\u91cd\u590d\u7684\u5b50\u5b57\u7b26\u4e32", "title_en": "Repeated Substring Pattern", "question_title_slug": "repeated-substring-pattern", "content_en": "

    Given a string s, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "abab"\nOutput: true\nExplanation: It is the substring "ab" twice.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "aba"\nOutput: false\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "abcabcabcabc"\nOutput: true\nExplanation: It is the substring "abc" four times or the substring "abcabc" twice.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 104
    • \n\t
    • s consists of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u7a7a\u7684\u5b57\u7b26\u4e32\uff0c\u5224\u65ad\u5b83\u662f\u5426\u53ef\u4ee5\u7531\u5b83\u7684\u4e00\u4e2a\u5b50\u4e32\u91cd\u590d\u591a\u6b21\u6784\u6210\u3002\u7ed9\u5b9a\u7684\u5b57\u7b26\u4e32\u53ea\u542b\u6709\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\uff0c\u5e76\u4e14\u957f\u5ea6\u4e0d\u8d85\u8fc710000\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: "abab"\n\n\u8f93\u51fa: True\n\n\u89e3\u91ca: \u53ef\u7531\u5b50\u5b57\u7b26\u4e32 "ab" \u91cd\u590d\u4e24\u6b21\u6784\u6210\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: "aba"\n\n\u8f93\u51fa: False\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \n\u8f93\u5165: "abcabcabcabc"\n\n\u8f93\u51fa: True\n\n\u89e3\u91ca: \u53ef\u7531\u5b50\u5b57\u7b26\u4e32 "abc" \u91cd\u590d\u56db\u6b21\u6784\u6210\u3002 (\u6216\u8005\u5b50\u5b57\u7b26\u4e32 "abcabc" \u91cd\u590d\u4e24\u6b21\u6784\u6210\u3002)\n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool repeatedSubstringPattern(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean repeatedSubstringPattern(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def repeatedSubstringPattern(self, s):\n \"\"\"\n :type s: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def repeatedSubstringPattern(self, s: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool repeatedSubstringPattern(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool RepeatedSubstringPattern(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {boolean}\n */\nvar repeatedSubstringPattern = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Boolean}\ndef repeated_substring_pattern(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func repeatedSubstringPattern(_ s: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func repeatedSubstringPattern(s string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def repeatedSubstringPattern(s: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun repeatedSubstringPattern(s: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn repeated_substring_pattern(s: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Boolean\n */\n function repeatedSubstringPattern($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function repeatedSubstringPattern(s: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (repeated-substring-pattern s)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0459](https://leetcode-cn.com/problems/repeated-substring-pattern)", "[\u91cd\u590d\u7684\u5b50\u5b57\u7b26\u4e32](/solution/0400-0499/0459.Repeated%20Substring%20Pattern/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0459](https://leetcode.com/problems/repeated-substring-pattern)", "[Repeated Substring Pattern](/solution/0400-0499/0459.Repeated%20Substring%20Pattern/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "0458", "frontend_question_id": "0458", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/poor-pigs", "url_en": "https://leetcode.com/problems/poor-pigs", "relative_path_cn": "/solution/0400-0499/0458.Poor%20Pigs/README.md", "relative_path_en": "/solution/0400-0499/0458.Poor%20Pigs/README_EN.md", "title_cn": "\u53ef\u601c\u7684\u5c0f\u732a", "title_en": "Poor Pigs", "question_title_slug": "poor-pigs", "content_en": "

    There are buckets buckets of liquid, where exactly one of the buckets is poisonous. To figure out which one is poisonous, you feed some number of (poor) pigs the liquid to see whether they will die or not. Unfortunately, you only have minutesToTest minutes to determine which bucket is poisonous.

    \n\n

    You can feed the pigs according to these steps:

    \n\n
      \n\t
    1. Choose some live pigs to feed.
    2. \n\t
    3. For each pig, choose which buckets to feed it. The pig will consume all the chosen buckets simultaneously and will take no time.
    4. \n\t
    5. Wait for minutesToDie minutes. You may not feed any other pigs during this time.
    6. \n\t
    7. After minutesToDie minutes have passed, any pigs that have been fed the poisonous bucket will die, and all others will survive.
    8. \n\t
    9. Repeat this process until you run out of time.
    10. \n
    \n\n

    Given buckets, minutesToDie, and minutesToTest, return the minimum number of pigs needed to figure out which bucket is poisonous within the allotted time.

    \n\n

     

    \n

    Example 1:

    \n
    Input: buckets = 1000, minutesToDie = 15, minutesToTest = 60\nOutput: 5\n

    Example 2:

    \n
    Input: buckets = 4, minutesToDie = 15, minutesToTest = 15\nOutput: 2\n

    Example 3:

    \n
    Input: buckets = 4, minutesToDie = 15, minutesToTest = 30\nOutput: 2\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= buckets <= 1000
    • \n\t
    • 1 <= minutesToDie <= minutesToTest <= 100
    • \n
    \n", "content_cn": "

    \u6709 buckets \u6876\u6db2\u4f53\uff0c\u5176\u4e2d \u6b63\u597d \u6709\u4e00\u6876\u542b\u6709\u6bd2\u836f\uff0c\u5176\u4f59\u88c5\u7684\u90fd\u662f\u6c34\u3002\u5b83\u4eec\u4ece\u5916\u89c2\u770b\u8d77\u6765\u90fd\u4e00\u6837\u3002\u4e3a\u4e86\u5f04\u6e05\u695a\u54ea\u53ea\u6c34\u6876\u542b\u6709\u6bd2\u836f\uff0c\u4f60\u53ef\u4ee5\u5582\u4e00\u4e9b\u732a\u559d\uff0c\u901a\u8fc7\u89c2\u5bdf\u732a\u662f\u5426\u4f1a\u6b7b\u8fdb\u884c\u5224\u65ad\u3002\u4e0d\u5e78\u7684\u662f\uff0c\u4f60\u53ea\u6709\u00a0minutesToTest \u5206\u949f\u65f6\u95f4\u6765\u786e\u5b9a\u54ea\u6876\u6db2\u4f53\u662f\u6709\u6bd2\u7684\u3002

    \n\n

    \u5582\u732a\u7684\u89c4\u5219\u5982\u4e0b\uff1a

    \n\n
      \n\t
    1. \u9009\u62e9\u82e5\u5e72\u6d3b\u732a\u8fdb\u884c\u5582\u517b
    2. \n\t
    3. \u53ef\u4ee5\u5141\u8bb8\u5c0f\u732a\u540c\u65f6\u996e\u7528\u4efb\u610f\u6570\u91cf\u7684\u6876\u4e2d\u7684\u6c34\uff0c\u5e76\u4e14\u8be5\u8fc7\u7a0b\u4e0d\u9700\u8981\u65f6\u95f4\u3002
    4. \n\t
    5. \u5c0f\u732a\u559d\u5b8c\u6c34\u540e\uff0c\u5fc5\u987b\u6709 minutesToDie \u5206\u949f\u7684\u51b7\u5374\u65f6\u95f4\u3002\u5728\u8fd9\u6bb5\u65f6\u95f4\u91cc\uff0c\u4f60\u53ea\u80fd\u89c2\u5bdf\uff0c\u800c\u4e0d\u5141\u8bb8\u7ee7\u7eed\u5582\u732a\u3002
    6. \n\t
    7. \u8fc7\u4e86 minutesToDie \u5206\u949f\u540e\uff0c\u6240\u6709\u559d\u5230\u6bd2\u836f\u7684\u732a\u90fd\u4f1a\u6b7b\u53bb\uff0c\u5176\u4ed6\u6240\u6709\u732a\u90fd\u4f1a\u6d3b\u4e0b\u6765\u3002
    8. \n\t
    9. \u91cd\u590d\u8fd9\u4e00\u8fc7\u7a0b\uff0c\u76f4\u5230\u65f6\u95f4\u7528\u5b8c\u3002
    10. \n
    \n\n

    \u7ed9\u4f60\u6876\u7684\u6570\u76ee buckets \uff0cminutesToDie \u548c minutesToTest \uff0c\u8fd4\u56de\u5728\u89c4\u5b9a\u65f6\u95f4\u5185\u5224\u65ad\u54ea\u4e2a\u6876\u6709\u6bd2\u6240\u9700\u7684 \u6700\u5c0f \u732a\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1abuckets = 1000, minutesToDie = 15, minutesToTest = 60\n\u8f93\u51fa\uff1a5\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1abuckets = 4, minutesToDie = 15, minutesToTest = 15\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1abuckets = 4, minutesToDie = 15, minutesToTest = 30\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= buckets <= 1000
    • \n\t
    • 1 <=\u00a0minutesToDie <=\u00a0minutesToTest <= 100
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int poorPigs(int buckets, int minutesToDie, int minutesToTest) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int poorPigs(int buckets, int minutesToDie, int minutesToTest) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def poorPigs(self, buckets, minutesToDie, minutesToTest):\n \"\"\"\n :type buckets: int\n :type minutesToDie: int\n :type minutesToTest: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def poorPigs(self, buckets: int, minutesToDie: int, minutesToTest: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint poorPigs(int buckets, int minutesToDie, int minutesToTest){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int PoorPigs(int buckets, int minutesToDie, int minutesToTest) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} buckets\n * @param {number} minutesToDie\n * @param {number} minutesToTest\n * @return {number}\n */\nvar poorPigs = function(buckets, minutesToDie, minutesToTest) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} buckets\n# @param {Integer} minutes_to_die\n# @param {Integer} minutes_to_test\n# @return {Integer}\ndef poor_pigs(buckets, minutes_to_die, minutes_to_test)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func poorPigs(_ buckets: Int, _ minutesToDie: Int, _ minutesToTest: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func poorPigs(buckets int, minutesToDie int, minutesToTest int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def poorPigs(buckets: Int, minutesToDie: Int, minutesToTest: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun poorPigs(buckets: Int, minutesToDie: Int, minutesToTest: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn poor_pigs(buckets: i32, minutes_to_die: i32, minutes_to_test: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $buckets\n * @param Integer $minutesToDie\n * @param Integer $minutesToTest\n * @return Integer\n */\n function poorPigs($buckets, $minutesToDie, $minutesToTest) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function poorPigs(buckets: number, minutesToDie: number, minutesToTest: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (poor-pigs buckets minutesToDie minutesToTest)\n (-> exact-integer? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0458](https://leetcode-cn.com/problems/poor-pigs)", "[\u53ef\u601c\u7684\u5c0f\u732a](/solution/0400-0499/0458.Poor%20Pigs/README.md)", "`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[0458](https://leetcode.com/problems/poor-pigs)", "[Poor Pigs](/solution/0400-0499/0458.Poor%20Pigs/README_EN.md)", "`Math`", "Hard", ""]}, {"question_id": "0457", "frontend_question_id": "0457", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/circular-array-loop", "url_en": "https://leetcode.com/problems/circular-array-loop", "relative_path_cn": "/solution/0400-0499/0457.Circular%20Array%20Loop/README.md", "relative_path_en": "/solution/0400-0499/0457.Circular%20Array%20Loop/README_EN.md", "title_cn": "\u73af\u5f62\u6570\u7ec4\u662f\u5426\u5b58\u5728\u5faa\u73af", "title_en": "Circular Array Loop", "question_title_slug": "circular-array-loop", "content_en": "

    You are playing a game involving a circular array of non-zero integers nums. Each nums[i] denotes the number of indices forward/backward you must move if you are located at index i:

    \n\n
      \n\t
    • If nums[i] is positive, move nums[i] steps forward, and
    • \n\t
    • If nums[i] is negative, move nums[i] steps backward.
    • \n
    \n\n

    Since the array is circular, you may assume that moving forward from the last element puts you on the first element, and moving backwards from the first element puts you on the last element.

    \n\n

    A cycle in the array consists of a sequence of indices seq of length k where:

    \n\n
      \n\t
    • Following the movement rules above results in the repeating index sequence seq[0] -> seq[1] -> ... -> seq[k - 1] -> seq[0] -> ...
    • \n\t
    • Every nums[seq[j]] is either all positive or all negative.
    • \n\t
    • k > 1
    • \n
    \n\n

    Return true if there is a cycle in nums, or false otherwise.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [2,-1,1,2,2]\nOutput: true\nExplanation:\nThere is a cycle from index 0 -> 2 -> 3 -> 0 -> ...\nThe cycle's length is 3.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [-1,2]\nOutput: false\nExplanation:\nThe sequence from index 1 -> 1 -> 1 -> ... is not a cycle because the sequence's length is 1.\nBy definition the sequence's length must be strictly greater than 1 to be a cycle.\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [-2,1,-1,-2,-2]\nOutput: false\nExplanation:\nThe sequence from index 1 -> 2 -> 1 -> ... is not a cycle because nums[1] is positive, but nums[2] is negative.\nEvery nums[seq[j]] must be either all positive or all negative.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 5000
    • \n\t
    • -1000 <= nums[i] <= 1000
    • \n\t
    • nums[i] != 0
    • \n
    \n\n

     

    \n

    Follow up: Could you solve it in O(n) time complexity and O(1) extra space complexity?

    \n", "content_cn": "

    \u5b58\u5728\u4e00\u4e2a\u4e0d\u542b 0 \u7684 \u73af\u5f62 \u6570\u7ec4\u00a0nums \uff0c\u6bcf\u4e2a nums[i] \u90fd\u8868\u793a\u4f4d\u4e8e\u4e0b\u6807 i \u7684\u89d2\u8272\u5e94\u8be5\u5411\u524d\u6216\u5411\u540e\u79fb\u52a8\u7684\u4e0b\u6807\u4e2a\u6570\uff1a

    \n\n
      \n\t
    • \u5982\u679c nums[i] \u662f\u6b63\u6570\uff0c\u5411\u524d \u79fb\u52a8 nums[i] \u6b65
    • \n\t
    • \u5982\u679c\u00a0nums[i] \u662f\u8d1f\u6570\uff0c\u5411\u540e \u79fb\u52a8 nums[i] \u6b65
    • \n
    \n\n

    \u56e0\u4e3a\u6570\u7ec4\u662f \u73af\u5f62 \u7684\uff0c\u6240\u4ee5\u53ef\u4ee5\u5047\u8bbe\u4ece\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u5411\u524d\u79fb\u52a8\u4e00\u6b65\u4f1a\u5230\u8fbe\u7b2c\u4e00\u4e2a\u5143\u7d20\uff0c\u800c\u7b2c\u4e00\u4e2a\u5143\u7d20\u5411\u540e\u79fb\u52a8\u4e00\u6b65\u4f1a\u5230\u8fbe\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u3002

    \n\n

    \u6570\u7ec4\u4e2d\u7684 \u5faa\u73af \u7531\u957f\u5ea6\u4e3a k \u7684\u4e0b\u6807\u5e8f\u5217 seq \uff1a

    \n\n
      \n\t
    • \u9075\u5faa\u4e0a\u8ff0\u79fb\u52a8\u89c4\u5219\u5c06\u5bfc\u81f4\u91cd\u590d\u4e0b\u6807\u5e8f\u5217 seq[0] -> seq[1] -> ... -> seq[k - 1] -> seq[0] -> ...
    • \n\t
    • \u6240\u6709 nums[seq[j]] \u5e94\u5f53\u4e0d\u662f \u5168\u6b63 \u5c31\u662f \u5168\u8d1f
    • \n\t
    • k > 1
    • \n
    \n\n

    \u5982\u679c nums \u4e2d\u5b58\u5728\u5faa\u73af\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [2,-1,1,2,2]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u5b58\u5728\u5faa\u73af\uff0c\u6309\u4e0b\u6807 0 -> 2 -> 3 -> 0 \u3002\u5faa\u73af\u957f\u5ea6\u4e3a 3 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [-1,2]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u6309\u4e0b\u6807 1 -> 1 -> 1 ... \u7684\u8fd0\u52a8\u65e0\u6cd5\u6784\u6210\u5faa\u73af\uff0c\u56e0\u4e3a\u5faa\u73af\u7684\u957f\u5ea6\u4e3a 1 \u3002\u6839\u636e\u5b9a\u4e49\uff0c\u5faa\u73af\u7684\u957f\u5ea6\u5fc5\u987b\u5927\u4e8e 1 \u3002\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \n\u8f93\u5165\uff1anums = [-2,1,-1,-2,-2]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u6309\u4e0b\u6807 1 -> 2 -> 1 -> ... \u7684\u8fd0\u52a8\u65e0\u6cd5\u6784\u6210\u5faa\u73af\uff0c\u56e0\u4e3a nums[1] \u662f\u6b63\u6570\uff0c\u800c nums[2] \u662f\u8d1f\u6570\u3002\n\u6240\u6709 nums[seq[j]] \u5e94\u5f53\u4e0d\u662f\u5168\u6b63\u5c31\u662f\u5168\u8d1f\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 5000
    • \n\t
    • -1000 <= nums[i] <= 1000
    • \n\t
    • nums[i] != 0
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u80fd\u8bbe\u8ba1\u4e00\u4e2a\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n) \u4e14\u989d\u5916\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a O(1) \u7684\u7b97\u6cd5\u5417\uff1f

    \n", "tags_en": ["Array", "Two Pointers"], "tags_cn": ["\u6570\u7ec4", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool circularArrayLoop(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean circularArrayLoop(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def circularArrayLoop(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def circularArrayLoop(self, nums: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool circularArrayLoop(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CircularArrayLoop(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {boolean}\n */\nvar circularArrayLoop = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Boolean}\ndef circular_array_loop(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func circularArrayLoop(_ nums: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func circularArrayLoop(nums []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def circularArrayLoop(nums: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun circularArrayLoop(nums: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn circular_array_loop(nums: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Boolean\n */\n function circularArrayLoop($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function circularArrayLoop(nums: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (circular-array-loop nums)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0457](https://leetcode-cn.com/problems/circular-array-loop)", "[\u73af\u5f62\u6570\u7ec4\u662f\u5426\u5b58\u5728\u5faa\u73af](/solution/0400-0499/0457.Circular%20Array%20Loop/README.md)", "`\u6570\u7ec4`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0457](https://leetcode.com/problems/circular-array-loop)", "[Circular Array Loop](/solution/0400-0499/0457.Circular%20Array%20Loop/README_EN.md)", "`Array`,`Two Pointers`", "Medium", ""]}, {"question_id": "0456", "frontend_question_id": "0456", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/132-pattern", "url_en": "https://leetcode.com/problems/132-pattern", "relative_path_cn": "/solution/0400-0499/0456.132%20Pattern/README.md", "relative_path_en": "/solution/0400-0499/0456.132%20Pattern/README_EN.md", "title_cn": "132 \u6a21\u5f0f", "title_en": "132 Pattern", "question_title_slug": "132-pattern", "content_en": "

    Given an array of n integers nums, a 132 pattern is a subsequence of three integers nums[i], nums[j] and nums[k] such that i < j < k and nums[i] < nums[k] < nums[j].

    \n\n

    Return true if there is a 132 pattern in nums, otherwise, return false.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,3,4]\nOutput: false\nExplanation: There is no 132 pattern in the sequence.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [3,1,4,2]\nOutput: true\nExplanation: There is a 132 pattern in the sequence: [1, 4, 2].\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [-1,3,2,0]\nOutput: true\nExplanation: There are three 132 patterns in the sequence: [-1, 3, 2], [-1, 3, 0] and [-1, 2, 0].\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= n <= 2 * 105
    • \n\t
    • -109 <= nums[i] <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \uff0c\u6570\u7ec4\u4e2d\u5171\u6709 n \u4e2a\u6574\u6570\u3002132 \u6a21\u5f0f\u7684\u5b50\u5e8f\u5217 \u7531\u4e09\u4e2a\u6574\u6570 nums[i]\u3001nums[j] \u548c nums[k] \u7ec4\u6210\uff0c\u5e76\u540c\u65f6\u6ee1\u8db3\uff1ai < j < k \u548c nums[i] < nums[k] < nums[j] \u3002

    \n\n

    \u5982\u679c nums \u4e2d\u5b58\u5728 132 \u6a21\u5f0f\u7684\u5b50\u5e8f\u5217 \uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u5f88\u5bb9\u6613\u60f3\u5230\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n^2) \u7684\u89e3\u51b3\u65b9\u6848\uff0c\u4f60\u53ef\u4ee5\u8bbe\u8ba1\u4e00\u4e2a\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n logn) \u6216 O(n) \u7684\u89e3\u51b3\u65b9\u6848\u5417\uff1f

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,3,4]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u5e8f\u5217\u4e2d\u4e0d\u5b58\u5728 132 \u6a21\u5f0f\u7684\u5b50\u5e8f\u5217\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [3,1,4,2]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u5e8f\u5217\u4e2d\u6709 1 \u4e2a 132 \u6a21\u5f0f\u7684\u5b50\u5e8f\u5217\uff1a [1, 4, 2] \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [-1,3,2,0]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u5e8f\u5217\u4e2d\u6709 3 \u4e2a 132 \u6a21\u5f0f\u7684\u7684\u5b50\u5e8f\u5217\uff1a[-1, 3, 2]\u3001[-1, 3, 0] \u548c [-1, 2, 0] \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= n <= 104
    • \n\t
    • -109 <= nums[i] <= 109
    • \n
    \n", "tags_en": ["Stack"], "tags_cn": ["\u6808"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool find132pattern(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean find132pattern(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def find132pattern(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def find132pattern(self, nums: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool find132pattern(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool Find132pattern(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {boolean}\n */\nvar find132pattern = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Boolean}\ndef find132pattern(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func find132pattern(_ nums: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func find132pattern(nums []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def find132pattern(nums: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun find132pattern(nums: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find132pattern(nums: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Boolean\n */\n function find132pattern($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function find132pattern(nums: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find132pattern nums)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0456](https://leetcode-cn.com/problems/132-pattern)", "[132 \u6a21\u5f0f](/solution/0400-0499/0456.132%20Pattern/README.md)", "`\u6808`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0456](https://leetcode.com/problems/132-pattern)", "[132 Pattern](/solution/0400-0499/0456.132%20Pattern/README_EN.md)", "`Stack`", "Medium", ""]}, {"question_id": "0455", "frontend_question_id": "0455", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/assign-cookies", "url_en": "https://leetcode.com/problems/assign-cookies", "relative_path_cn": "/solution/0400-0499/0455.Assign%20Cookies/README.md", "relative_path_en": "/solution/0400-0499/0455.Assign%20Cookies/README_EN.md", "title_cn": "\u5206\u53d1\u997c\u5e72", "title_en": "Assign Cookies", "question_title_slug": "assign-cookies", "content_en": "

    Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie.

    \n\n

    Each child i has a greed factor g[i], which is the minimum size of a cookie that the child will be content with; and each cookie j has a size s[j]. If s[j] >= g[i], we can assign the cookie j to the child i, and the child i will be content. Your goal is to maximize the number of your content children and output the maximum number.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: g = [1,2,3], s = [1,1]\nOutput: 1\nExplanation: You have 3 children and 2 cookies. The greed factors of 3 children are 1, 2, 3. \nAnd even though you have 2 cookies, since their size is both 1, you could only make the child whose greed factor is 1 content.\nYou need to output 1.\n
    \n\n

    Example 2:

    \n\n
    \nInput: g = [1,2], s = [1,2,3]\nOutput: 2\nExplanation: You have 2 children and 3 cookies. The greed factors of 2 children are 1, 2. \nYou have 3 cookies and their sizes are big enough to gratify all of the children, \nYou need to output 2.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= g.length <= 3 * 104
    • \n\t
    • 0 <= s.length <= 3 * 104
    • \n\t
    • 1 <= g[i], s[j] <= 231 - 1
    • \n
    \n", "content_cn": "

    \u5047\u8bbe\u4f60\u662f\u4e00\u4f4d\u5f88\u68d2\u7684\u5bb6\u957f\uff0c\u60f3\u8981\u7ed9\u4f60\u7684\u5b69\u5b50\u4eec\u4e00\u4e9b\u5c0f\u997c\u5e72\u3002\u4f46\u662f\uff0c\u6bcf\u4e2a\u5b69\u5b50\u6700\u591a\u53ea\u80fd\u7ed9\u4e00\u5757\u997c\u5e72\u3002

    \n\n

    \u5bf9\u6bcf\u4e2a\u5b69\u5b50 i\uff0c\u90fd\u6709\u4e00\u4e2a\u80c3\u53e3\u503c\u00a0g[i]\uff0c\u8fd9\u662f\u80fd\u8ba9\u5b69\u5b50\u4eec\u6ee1\u8db3\u80c3\u53e3\u7684\u997c\u5e72\u7684\u6700\u5c0f\u5c3a\u5bf8\uff1b\u5e76\u4e14\u6bcf\u5757\u997c\u5e72 j\uff0c\u90fd\u6709\u4e00\u4e2a\u5c3a\u5bf8 s[j]\u00a0\u3002\u5982\u679c s[j]\u00a0>= g[i]\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u8fd9\u4e2a\u997c\u5e72 j \u5206\u914d\u7ed9\u5b69\u5b50 i \uff0c\u8fd9\u4e2a\u5b69\u5b50\u4f1a\u5f97\u5230\u6ee1\u8db3\u3002\u4f60\u7684\u76ee\u6807\u662f\u5c3d\u53ef\u80fd\u6ee1\u8db3\u8d8a\u591a\u6570\u91cf\u7684\u5b69\u5b50\uff0c\u5e76\u8f93\u51fa\u8fd9\u4e2a\u6700\u5927\u6570\u503c\u3002

    \n\u00a0\n\n

    \u793a\u4f8b\u00a01:

    \n\n
    \n\u8f93\u5165: g = [1,2,3], s = [1,1]\n\u8f93\u51fa: 1\n\u89e3\u91ca: \n\u4f60\u6709\u4e09\u4e2a\u5b69\u5b50\u548c\u4e24\u5757\u5c0f\u997c\u5e72\uff0c3\u4e2a\u5b69\u5b50\u7684\u80c3\u53e3\u503c\u5206\u522b\u662f\uff1a1,2,3\u3002\n\u867d\u7136\u4f60\u6709\u4e24\u5757\u5c0f\u997c\u5e72\uff0c\u7531\u4e8e\u4ed6\u4eec\u7684\u5c3a\u5bf8\u90fd\u662f1\uff0c\u4f60\u53ea\u80fd\u8ba9\u80c3\u53e3\u503c\u662f1\u7684\u5b69\u5b50\u6ee1\u8db3\u3002\n\u6240\u4ee5\u4f60\u5e94\u8be5\u8f93\u51fa1\u3002\n
    \n\n

    \u793a\u4f8b\u00a02:

    \n\n
    \n\u8f93\u5165: g = [1,2], s = [1,2,3]\n\u8f93\u51fa: 2\n\u89e3\u91ca: \n\u4f60\u6709\u4e24\u4e2a\u5b69\u5b50\u548c\u4e09\u5757\u5c0f\u997c\u5e72\uff0c2\u4e2a\u5b69\u5b50\u7684\u80c3\u53e3\u503c\u5206\u522b\u662f1,2\u3002\n\u4f60\u62e5\u6709\u7684\u997c\u5e72\u6570\u91cf\u548c\u5c3a\u5bf8\u90fd\u8db3\u4ee5\u8ba9\u6240\u6709\u5b69\u5b50\u6ee1\u8db3\u3002\n\u6240\u4ee5\u4f60\u5e94\u8be5\u8f93\u51fa2.\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= g.length <= 3 * 104
    • \n\t
    • 0 <= s.length <= 3 * 104
    • \n\t
    • 1 <= g[i], s[j] <=\u00a0231 - 1
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findContentChildren(vector& g, vector& s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findContentChildren(int[] g, int[] s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findContentChildren(self, g, s):\n \"\"\"\n :type g: List[int]\n :type s: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findContentChildren(self, g: List[int], s: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findContentChildren(int* g, int gSize, int* s, int sSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindContentChildren(int[] g, int[] s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} g\n * @param {number[]} s\n * @return {number}\n */\nvar findContentChildren = function(g, s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} g\n# @param {Integer[]} s\n# @return {Integer}\ndef find_content_children(g, s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findContentChildren(_ g: [Int], _ s: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findContentChildren(g []int, s []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findContentChildren(g: Array[Int], s: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findContentChildren(g: IntArray, s: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_content_children(g: Vec, s: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $g\n * @param Integer[] $s\n * @return Integer\n */\n function findContentChildren($g, $s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findContentChildren(g: number[], s: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-content-children g s)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0455](https://leetcode-cn.com/problems/assign-cookies)", "[\u5206\u53d1\u997c\u5e72](/solution/0400-0499/0455.Assign%20Cookies/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u7b80\u5355", ""], "md_table_row_en": ["[0455](https://leetcode.com/problems/assign-cookies)", "[Assign Cookies](/solution/0400-0499/0455.Assign%20Cookies/README_EN.md)", "`Greedy`", "Easy", ""]}, {"question_id": "0454", "frontend_question_id": "0454", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/4sum-ii", "url_en": "https://leetcode.com/problems/4sum-ii", "relative_path_cn": "/solution/0400-0499/0454.4Sum%20II/README.md", "relative_path_en": "/solution/0400-0499/0454.4Sum%20II/README_EN.md", "title_cn": "\u56db\u6570\u76f8\u52a0 II", "title_en": "4Sum II", "question_title_slug": "4sum-ii", "content_en": "

    Given four integer arrays nums1, nums2, nums3, and nums4 all of length n, return the number of tuples (i, j, k, l) such that:

    \n\n
      \n\t
    • 0 <= i, j, k, l < n
    • \n\t
    • nums1[i] + nums2[j] + nums3[k] + nums4[l] == 0
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums1 = [1,2], nums2 = [-2,-1], nums3 = [-1,2], nums4 = [0,2]\nOutput: 2\nExplanation:\nThe two tuples are:\n1. (0, 0, 0, 1) -> nums1[0] + nums2[0] + nums3[0] + nums4[1] = 1 + (-2) + (-1) + 2 = 0\n2. (1, 1, 0, 0) -> nums1[1] + nums2[1] + nums3[0] + nums4[0] = 2 + (-1) + (-1) + 0 = 0\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums1 = [0], nums2 = [0], nums3 = [0], nums4 = [0]\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == nums1.length
    • \n\t
    • n == nums2.length
    • \n\t
    • n == nums3.length
    • \n\t
    • n == nums4.length
    • \n\t
    • 1 <= n <= 200
    • \n\t
    • -228 <= nums1[i], nums2[i], nums3[i], nums4[i] <= 228
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u56db\u4e2a\u5305\u542b\u6574\u6570\u7684\u6570\u7ec4\u5217\u8868 A , B , C , D ,\u8ba1\u7b97\u6709\u591a\u5c11\u4e2a\u5143\u7ec4 (i, j, k, l) \uff0c\u4f7f\u5f97 A[i] + B[j] + C[k] + D[l] = 0\u3002

    \n\n

    \u4e3a\u4e86\u4f7f\u95ee\u9898\u7b80\u5355\u5316\uff0c\u6240\u6709\u7684 A, B, C, D \u5177\u6709\u76f8\u540c\u7684\u957f\u5ea6 N\uff0c\u4e14 0 ≤ N ≤ 500 \u3002\u6240\u6709\u6574\u6570\u7684\u8303\u56f4\u5728 -228 \u5230 228 - 1 \u4e4b\u95f4\uff0c\u6700\u7ec8\u7ed3\u679c\u4e0d\u4f1a\u8d85\u8fc7 231 - 1 \u3002

    \n\n

    \u4f8b\u5982:

    \n\n
    \n\u8f93\u5165:\nA = [ 1, 2]\nB = [-2,-1]\nC = [-1, 2]\nD = [ 0, 2]\n\n\u8f93\u51fa:\n2\n\n\u89e3\u91ca:\n\u4e24\u4e2a\u5143\u7ec4\u5982\u4e0b:\n1. (0, 0, 0, 1) -> A[0] + B[0] + C[0] + D[1] = 1 + (-2) + (-1) + 2 = 0\n2. (1, 1, 0, 0) -> A[1] + B[1] + C[0] + D[0] = 2 + (-1) + (-1) + 0 = 0\n
    \n", "tags_en": ["Hash Table", "Binary Search"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int fourSumCount(vector& nums1, vector& nums2, vector& nums3, vector& nums4) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int fourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def fourSumCount(self, nums1, nums2, nums3, nums4):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n :type nums3: List[int]\n :type nums4: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def fourSumCount(self, nums1: List[int], nums2: List[int], nums3: List[int], nums4: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint fourSumCount(int* nums1, int nums1Size, int* nums2, int nums2Size, int* nums3, int nums3Size, int* nums4, int nums4Size){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums1\n * @param {number[]} nums2\n * @param {number[]} nums3\n * @param {number[]} nums4\n * @return {number}\n */\nvar fourSumCount = function(nums1, nums2, nums3, nums4) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums1\n# @param {Integer[]} nums2\n# @param {Integer[]} nums3\n# @param {Integer[]} nums4\n# @return {Integer}\ndef four_sum_count(nums1, nums2, nums3, nums4)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func fourSumCount(_ nums1: [Int], _ nums2: [Int], _ nums3: [Int], _ nums4: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func fourSumCount(nums1 []int, nums2 []int, nums3 []int, nums4 []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def fourSumCount(nums1: Array[Int], nums2: Array[Int], nums3: Array[Int], nums4: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun fourSumCount(nums1: IntArray, nums2: IntArray, nums3: IntArray, nums4: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn four_sum_count(nums1: Vec, nums2: Vec, nums3: Vec, nums4: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums1\n * @param Integer[] $nums2\n * @param Integer[] $nums3\n * @param Integer[] $nums4\n * @return Integer\n */\n function fourSumCount($nums1, $nums2, $nums3, $nums4) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function fourSumCount(nums1: number[], nums2: number[], nums3: number[], nums4: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (four-sum-count nums1 nums2 nums3 nums4)\n (-> (listof exact-integer?) (listof exact-integer?) (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0454](https://leetcode-cn.com/problems/4sum-ii)", "[\u56db\u6570\u76f8\u52a0 II](/solution/0400-0499/0454.4Sum%20II/README.md)", "`\u54c8\u5e0c\u8868`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0454](https://leetcode.com/problems/4sum-ii)", "[4Sum II](/solution/0400-0499/0454.4Sum%20II/README_EN.md)", "`Hash Table`,`Binary Search`", "Medium", ""]}, {"question_id": "0453", "frontend_question_id": "0453", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-moves-to-equal-array-elements", "url_en": "https://leetcode.com/problems/minimum-moves-to-equal-array-elements", "relative_path_cn": "/solution/0400-0499/0453.Minimum%20Moves%20to%20Equal%20Array%20Elements/README.md", "relative_path_en": "/solution/0400-0499/0453.Minimum%20Moves%20to%20Equal%20Array%20Elements/README_EN.md", "title_cn": "\u6700\u5c0f\u64cd\u4f5c\u6b21\u6570\u4f7f\u6570\u7ec4\u5143\u7d20\u76f8\u7b49", "title_en": "Minimum Moves to Equal Array Elements", "question_title_slug": "minimum-moves-to-equal-array-elements", "content_en": "

    Given an integer array nums of size n, return the minimum number of moves required to make all array elements equal.

    \n\n

    In one move, you can increment n - 1 elements of the array by 1.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,3]\nOutput: 3\nExplanation: Only three moves are needed (remember each move increments two elements):\n[1,2,3]  =>  [2,3,3]  =>  [3,4,3]  =>  [4,4,4]\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,1,1]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • -109 <= nums[i] <= 109
    • \n\t
    • The answer is guaranteed to fit in a 32-bit integer.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684 \u975e\u7a7a \u6574\u6570\u6570\u7ec4\uff0c\u6bcf\u6b21\u64cd\u4f5c\u5c06\u4f1a\u4f7f n - 1 \u4e2a\u5143\u7d20\u589e\u52a0 1\u3002\u627e\u51fa\u8ba9\u6570\u7ec4\u6240\u6709\u5143\u7d20\u76f8\u7b49\u7684\u6700\u5c0f\u64cd\u4f5c\u6b21\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\n[1,2,3]\n\u8f93\u51fa\uff1a\n3\n\u89e3\u91ca\uff1a\n\u53ea\u9700\u89813\u6b21\u64cd\u4f5c\uff08\u6ce8\u610f\u6bcf\u6b21\u64cd\u4f5c\u4f1a\u589e\u52a0\u4e24\u4e2a\u5143\u7d20\u7684\u503c\uff09\uff1a\n[1,2,3]  =>  [2,3,3]  =>  [3,4,3]  =>  [4,4,4]\n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minMoves(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minMoves(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minMoves(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minMoves(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minMoves(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinMoves(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar minMoves = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef min_moves(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minMoves(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minMoves(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minMoves(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minMoves(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_moves(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function minMoves($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minMoves(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-moves nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0453](https://leetcode-cn.com/problems/minimum-moves-to-equal-array-elements)", "[\u6700\u5c0f\u64cd\u4f5c\u6b21\u6570\u4f7f\u6570\u7ec4\u5143\u7d20\u76f8\u7b49](/solution/0400-0499/0453.Minimum%20Moves%20to%20Equal%20Array%20Elements/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0453](https://leetcode.com/problems/minimum-moves-to-equal-array-elements)", "[Minimum Moves to Equal Array Elements](/solution/0400-0499/0453.Minimum%20Moves%20to%20Equal%20Array%20Elements/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "0452", "frontend_question_id": "0452", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-number-of-arrows-to-burst-balloons", "url_en": "https://leetcode.com/problems/minimum-number-of-arrows-to-burst-balloons", "relative_path_cn": "/solution/0400-0499/0452.Minimum%20Number%20of%20Arrows%20to%20Burst%20Balloons/README.md", "relative_path_en": "/solution/0400-0499/0452.Minimum%20Number%20of%20Arrows%20to%20Burst%20Balloons/README_EN.md", "title_cn": "\u7528\u6700\u5c11\u6570\u91cf\u7684\u7bad\u5f15\u7206\u6c14\u7403", "title_en": "Minimum Number of Arrows to Burst Balloons", "question_title_slug": "minimum-number-of-arrows-to-burst-balloons", "content_en": "

    There are some spherical balloons spread in two-dimensional space. For each balloon, provided input is the start and end coordinates of the horizontal diameter. Since it's horizontal, y-coordinates don't matter, and hence the x-coordinates of start and end of the diameter suffice. The start is always smaller than the end.

    \n\n

    An arrow can be shot up exactly vertically from different points along the x-axis. A balloon with xstart and xend bursts by an arrow shot at x if xstart ≤ x ≤ xend. There is no limit to the number of arrows that can be shot. An arrow once shot keeps traveling up infinitely.

    \n\n

    Given an array points where points[i] = [xstart, xend], return the minimum number of arrows that must be shot to burst all balloons.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: points = [[10,16],[2,8],[1,6],[7,12]]\nOutput: 2\nExplanation: One way is to shoot one arrow for example at x = 6 (bursting the balloons [2,8] and [1,6]) and another arrow at x = 11 (bursting the other two balloons).\n
    \n\n

    Example 2:

    \n\n
    \nInput: points = [[1,2],[3,4],[5,6],[7,8]]\nOutput: 4\n
    \n\n

    Example 3:

    \n\n
    \nInput: points = [[1,2],[2,3],[3,4],[4,5]]\nOutput: 2\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= points.length <= 104
    • \n\t
    • points[i].length == 2
    • \n\t
    • -231 <= xstart < xend <= 231 - 1
    • \n
    \n", "content_cn": "

    \u5728\u4e8c\u7ef4\u7a7a\u95f4\u4e2d\u6709\u8bb8\u591a\u7403\u5f62\u7684\u6c14\u7403\u3002\u5bf9\u4e8e\u6bcf\u4e2a\u6c14\u7403\uff0c\u63d0\u4f9b\u7684\u8f93\u5165\u662f\u6c34\u5e73\u65b9\u5411\u4e0a\uff0c\u6c14\u7403\u76f4\u5f84\u7684\u5f00\u59cb\u548c\u7ed3\u675f\u5750\u6807\u3002\u7531\u4e8e\u5b83\u662f\u6c34\u5e73\u7684\uff0c\u6240\u4ee5\u7eb5\u5750\u6807\u5e76\u4e0d\u91cd\u8981\uff0c\u56e0\u6b64\u53ea\u8981\u77e5\u9053\u5f00\u59cb\u548c\u7ed3\u675f\u7684\u6a2a\u5750\u6807\u5c31\u8db3\u591f\u4e86\u3002\u5f00\u59cb\u5750\u6807\u603b\u662f\u5c0f\u4e8e\u7ed3\u675f\u5750\u6807\u3002

    \n\n

    \u4e00\u652f\u5f13\u7bad\u53ef\u4ee5\u6cbf\u7740 x \u8f74\u4ece\u4e0d\u540c\u70b9\u5b8c\u5168\u5782\u76f4\u5730\u5c04\u51fa\u3002\u5728\u5750\u6807 x \u5904\u5c04\u51fa\u4e00\u652f\u7bad\uff0c\u82e5\u6709\u4e00\u4e2a\u6c14\u7403\u7684\u76f4\u5f84\u7684\u5f00\u59cb\u548c\u7ed3\u675f\u5750\u6807\u4e3a xstart\uff0cxend\uff0c \u4e14\u6ee1\u8db3 \u00a0xstart\u00a0\u2264 x \u2264 xend\uff0c\u5219\u8be5\u6c14\u7403\u4f1a\u88ab\u5f15\u7206\u3002\u53ef\u4ee5\u5c04\u51fa\u7684\u5f13\u7bad\u7684\u6570\u91cf\u6ca1\u6709\u9650\u5236\u3002 \u5f13\u7bad\u4e00\u65e6\u88ab\u5c04\u51fa\u4e4b\u540e\uff0c\u53ef\u4ee5\u65e0\u9650\u5730\u524d\u8fdb\u3002\u6211\u4eec\u60f3\u627e\u5230\u4f7f\u5f97\u6240\u6709\u6c14\u7403\u5168\u90e8\u88ab\u5f15\u7206\uff0c\u6240\u9700\u7684\u5f13\u7bad\u7684\u6700\u5c0f\u6570\u91cf\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 points \uff0c\u5176\u4e2d points [i] = [xstart,xend] \uff0c\u8fd4\u56de\u5f15\u7206\u6240\u6709\u6c14\u7403\u6240\u5fc5\u987b\u5c04\u51fa\u7684\u6700\u5c0f\u5f13\u7bad\u6570\u3002

    \n\u00a0\n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1apoints = [[10,16],[2,8],[1,6],[7,12]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5bf9\u4e8e\u8be5\u6837\u4f8b\uff0cx = 6 \u53ef\u4ee5\u5c04\u7206 [2,8],[1,6] \u4e24\u4e2a\u6c14\u7403\uff0c\u4ee5\u53ca x = 11 \u5c04\u7206\u53e6\u5916\u4e24\u4e2a\u6c14\u7403
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1apoints = [[1,2],[3,4],[5,6],[7,8]]\n\u8f93\u51fa\uff1a4\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1apoints = [[1,2],[2,3],[3,4],[4,5]]\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1apoints = [[1,2]]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1apoints = [[2,3],[2,3]]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= points.length <= 104
    • \n\t
    • points[i].length == 2
    • \n\t
    • -231 <= xstart <\u00a0xend <= 231 - 1
    • \n
    \n", "tags_en": ["Greedy", "Sort"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6392\u5e8f"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findMinArrowShots(vector>& points) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findMinArrowShots(int[][] points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findMinArrowShots(self, points):\n \"\"\"\n :type points: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findMinArrowShots(self, points: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findMinArrowShots(int** points, int pointsSize, int* pointsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindMinArrowShots(int[][] points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} points\n * @return {number}\n */\nvar findMinArrowShots = function(points) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} points\n# @return {Integer}\ndef find_min_arrow_shots(points)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findMinArrowShots(_ points: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findMinArrowShots(points [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findMinArrowShots(points: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findMinArrowShots(points: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_min_arrow_shots(points: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $points\n * @return Integer\n */\n function findMinArrowShots($points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findMinArrowShots(points: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-min-arrow-shots points)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0452](https://leetcode-cn.com/problems/minimum-number-of-arrows-to-burst-balloons)", "[\u7528\u6700\u5c11\u6570\u91cf\u7684\u7bad\u5f15\u7206\u6c14\u7403](/solution/0400-0499/0452.Minimum%20Number%20of%20Arrows%20to%20Burst%20Balloons/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6392\u5e8f`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0452](https://leetcode.com/problems/minimum-number-of-arrows-to-burst-balloons)", "[Minimum Number of Arrows to Burst Balloons](/solution/0400-0499/0452.Minimum%20Number%20of%20Arrows%20to%20Burst%20Balloons/README_EN.md)", "`Greedy`,`Sort`", "Medium", ""]}, {"question_id": "0451", "frontend_question_id": "0451", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sort-characters-by-frequency", "url_en": "https://leetcode.com/problems/sort-characters-by-frequency", "relative_path_cn": "/solution/0400-0499/0451.Sort%20Characters%20By%20Frequency/README.md", "relative_path_en": "/solution/0400-0499/0451.Sort%20Characters%20By%20Frequency/README_EN.md", "title_cn": "\u6839\u636e\u5b57\u7b26\u51fa\u73b0\u9891\u7387\u6392\u5e8f", "title_en": "Sort Characters By Frequency", "question_title_slug": "sort-characters-by-frequency", "content_en": "

    Given a string s, sort it in decreasing order based on the frequency of characters, and return the sorted string.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "tree"\nOutput: "eert"\nExplanation: 'e' appears twice while 'r' and 't' both appear once.\nSo 'e' must appear before both 'r' and 't'. Therefore "eetr" is also a valid answer.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "cccaaa"\nOutput: "aaaccc"\nExplanation: Both 'c' and 'a' appear three times, so "aaaccc" is also a valid answer.\nNote that "cacaca" is incorrect, as the same characters must be together.\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "Aabb"\nOutput: "bbAa"\nExplanation: "bbaA" is also a valid answer, but "Aabb" is incorrect.\nNote that 'A' and 'a' are treated as two different characters.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 5 * 105
    • \n\t
    • s consists of English letters and digits.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u8bf7\u5c06\u5b57\u7b26\u4e32\u91cc\u7684\u5b57\u7b26\u6309\u7167\u51fa\u73b0\u7684\u9891\u7387\u964d\u5e8f\u6392\u5217\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165:\n"tree"\n\n\u8f93\u51fa:\n"eert"\n\n\u89e3\u91ca:\n'e'\u51fa\u73b0\u4e24\u6b21\uff0c'r'\u548c't'\u90fd\u53ea\u51fa\u73b0\u4e00\u6b21\u3002\n\u56e0\u6b64'e'\u5fc5\u987b\u51fa\u73b0\u5728'r'\u548c't'\u4e4b\u524d\u3002\u6b64\u5916\uff0c"eetr"\u4e5f\u662f\u4e00\u4e2a\u6709\u6548\u7684\u7b54\u6848\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165:\n"cccaaa"\n\n\u8f93\u51fa:\n"cccaaa"\n\n\u89e3\u91ca:\n'c'\u548c'a'\u90fd\u51fa\u73b0\u4e09\u6b21\u3002\u6b64\u5916\uff0c"aaaccc"\u4e5f\u662f\u6709\u6548\u7684\u7b54\u6848\u3002\n\u6ce8\u610f"cacaca"\u662f\u4e0d\u6b63\u786e\u7684\uff0c\u56e0\u4e3a\u76f8\u540c\u7684\u5b57\u6bcd\u5fc5\u987b\u653e\u5728\u4e00\u8d77\u3002\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \n\u8f93\u5165:\n"Aabb"\n\n\u8f93\u51fa:\n"bbAa"\n\n\u89e3\u91ca:\n\u6b64\u5916\uff0c"bbaA"\u4e5f\u662f\u4e00\u4e2a\u6709\u6548\u7684\u7b54\u6848\uff0c\u4f46"Aabb"\u662f\u4e0d\u6b63\u786e\u7684\u3002\n\u6ce8\u610f'A'\u548c'a'\u88ab\u8ba4\u4e3a\u662f\u4e24\u79cd\u4e0d\u540c\u7684\u5b57\u7b26\u3002\n
    \n", "tags_en": ["Heap", "Hash Table"], "tags_cn": ["\u5806", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string frequencySort(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String frequencySort(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def frequencySort(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def frequencySort(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * frequencySort(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string FrequencySort(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar frequencySort = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef frequency_sort(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func frequencySort(_ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func frequencySort(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def frequencySort(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun frequencySort(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn frequency_sort(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function frequencySort($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function frequencySort(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (frequency-sort s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0451](https://leetcode-cn.com/problems/sort-characters-by-frequency)", "[\u6839\u636e\u5b57\u7b26\u51fa\u73b0\u9891\u7387\u6392\u5e8f](/solution/0400-0499/0451.Sort%20Characters%20By%20Frequency/README.md)", "`\u5806`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0451](https://leetcode.com/problems/sort-characters-by-frequency)", "[Sort Characters By Frequency](/solution/0400-0499/0451.Sort%20Characters%20By%20Frequency/README_EN.md)", "`Heap`,`Hash Table`", "Medium", ""]}, {"question_id": "0450", "frontend_question_id": "0450", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/delete-node-in-a-bst", "url_en": "https://leetcode.com/problems/delete-node-in-a-bst", "relative_path_cn": "/solution/0400-0499/0450.Delete%20Node%20in%20a%20BST/README.md", "relative_path_en": "/solution/0400-0499/0450.Delete%20Node%20in%20a%20BST/README_EN.md", "title_cn": "\u5220\u9664\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u7684\u8282\u70b9", "title_en": "Delete Node in a BST", "question_title_slug": "delete-node-in-a-bst", "content_en": "

    Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return the root node reference (possibly updated) of the BST.

    \n\n

    Basically, the deletion can be divided into two stages:

    \n\n
      \n\t
    1. Search for a node to remove.
    2. \n\t
    3. If the node is found, delete the node.
    4. \n
    \n\n

    Follow up: Can you solve it with time complexity O(height of tree)?

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [5,3,6,2,4,null,7], key = 3\nOutput: [5,4,6,2,null,null,7]\nExplanation: Given key to delete is 3. So we find the node with value 3 and delete it.\nOne valid answer is [5,4,6,2,null,null,7], shown in the above BST.\nPlease notice that another valid answer is [5,2,6,null,4,null,7] and it's also accepted.\n\"\"\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = [5,3,6,2,4,null,7], key = 0\nOutput: [5,3,6,2,4,null,7]\nExplanation: The tree does not contain a node with value = 0.\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = [], key = 0\nOutput: []\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [0, 104].
    • \n\t
    • -105 <= Node.val <= 105
    • \n\t
    • Each node has a unique value.
    • \n\t
    • root is a valid binary search tree.
    • \n\t
    • -105 <= key <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6839\u8282\u70b9 root \u548c\u4e00\u4e2a\u503c key\uff0c\u5220\u9664\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u7684 key \u5bf9\u5e94\u7684\u8282\u70b9\uff0c\u5e76\u4fdd\u8bc1\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6027\u8d28\u4e0d\u53d8\u3002\u8fd4\u56de\u4e8c\u53c9\u641c\u7d22\u6811\uff08\u6709\u53ef\u80fd\u88ab\u66f4\u65b0\uff09\u7684\u6839\u8282\u70b9\u7684\u5f15\u7528\u3002

    \n\n

    \u4e00\u822c\u6765\u8bf4\uff0c\u5220\u9664\u8282\u70b9\u53ef\u5206\u4e3a\u4e24\u4e2a\u6b65\u9aa4\uff1a

    \n\n
      \n\t
    1. \u9996\u5148\u627e\u5230\u9700\u8981\u5220\u9664\u7684\u8282\u70b9\uff1b
    2. \n\t
    3. \u5982\u679c\u627e\u5230\u4e86\uff0c\u5220\u9664\u5b83\u3002
    4. \n
    \n\n

    \u8bf4\u660e\uff1a \u8981\u6c42\u7b97\u6cd5\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(h)\uff0ch \u4e3a\u6811\u7684\u9ad8\u5ea6\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \nroot = [5,3,6,2,4,null,7]\nkey = 3\n\n    5\n   / \\\n  3   6\n / \\   \\\n2   4   7\n\n\u7ed9\u5b9a\u9700\u8981\u5220\u9664\u7684\u8282\u70b9\u503c\u662f 3\uff0c\u6240\u4ee5\u6211\u4eec\u9996\u5148\u627e\u5230 3 \u8fd9\u4e2a\u8282\u70b9\uff0c\u7136\u540e\u5220\u9664\u5b83\u3002\n\n\u4e00\u4e2a\u6b63\u786e\u7684\u7b54\u6848\u662f [5,4,6,2,null,null,7], \u5982\u4e0b\u56fe\u6240\u793a\u3002\n\n    5\n   / \\\n  4   6\n /     \\\n2       7\n\n\u53e6\u4e00\u4e2a\u6b63\u786e\u7b54\u6848\u662f [5,2,6,null,4,null,7]\u3002\n\n    5\n   / \\\n  2   6\n   \\   \\\n    4   7\n
    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* deleteNode(TreeNode* root, int key) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode deleteNode(TreeNode root, int key) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def deleteNode(self, root, key):\n \"\"\"\n :type root: TreeNode\n :type key: int\n :rtype: TreeNode\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def deleteNode(self, root: TreeNode, key: int) -> TreeNode:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* deleteNode(struct TreeNode* root, int key){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode DeleteNode(TreeNode root, int key) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number} key\n * @return {TreeNode}\n */\nvar deleteNode = function(root, key) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @param {Integer} key\n# @return {TreeNode}\ndef delete_node(root, key)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func deleteNode(_ root: TreeNode?, _ key: Int) -> TreeNode? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc deleteNode(root *TreeNode, key int) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def deleteNode(root: TreeNode, key: Int): TreeNode = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun deleteNode(root: TreeNode?, key: Int): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn delete_node(root: Option>>, key: i32) -> Option>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param Integer $key\n * @return TreeNode\n */\n function deleteNode($root, $key) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction deleteNode(root: TreeNode | null, key: number): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (delete-node root key)\n (-> (or/c tree-node? #f) exact-integer? (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0450](https://leetcode-cn.com/problems/delete-node-in-a-bst)", "[\u5220\u9664\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u7684\u8282\u70b9](/solution/0400-0499/0450.Delete%20Node%20in%20a%20BST/README.md)", "`\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0450](https://leetcode.com/problems/delete-node-in-a-bst)", "[Delete Node in a BST](/solution/0400-0499/0450.Delete%20Node%20in%20a%20BST/README_EN.md)", "`Tree`", "Medium", ""]}, {"question_id": "0449", "frontend_question_id": "0449", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/serialize-and-deserialize-bst", "url_en": "https://leetcode.com/problems/serialize-and-deserialize-bst", "relative_path_cn": "/solution/0400-0499/0449.Serialize%20and%20Deserialize%20BST/README.md", "relative_path_en": "/solution/0400-0499/0449.Serialize%20and%20Deserialize%20BST/README_EN.md", "title_cn": "\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316\u4e8c\u53c9\u641c\u7d22\u6811", "title_en": "Serialize and Deserialize BST", "question_title_slug": "serialize-and-deserialize-bst", "content_en": "

    Serialization is converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be reconstructed later in the same or another computer environment.

    \n\n

    Design an algorithm to serialize and deserialize a binary search tree. There is no restriction on how your serialization/deserialization algorithm should work. You need to ensure that a binary search tree can be serialized to a string, and this string can be deserialized to the original tree structure.

    \n\n

    The encoded string should be as compact as possible.

    \n\n

     

    \n

    Example 1:

    \n
    Input: root = [2,1,3]\nOutput: [2,1,3]\n

    Example 2:

    \n
    Input: root = []\nOutput: []\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [0, 104].
    • \n\t
    • 0 <= Node.val <= 104
    • \n\t
    • The input tree is guaranteed to be a binary search tree.
    • \n
    \n", "content_cn": "

    \u5e8f\u5217\u5316\u662f\u5c06\u6570\u636e\u7ed3\u6784\u6216\u5bf9\u8c61\u8f6c\u6362\u4e3a\u4e00\u7cfb\u5217\u4f4d\u7684\u8fc7\u7a0b\uff0c\u4ee5\u4fbf\u5b83\u53ef\u4ee5\u5b58\u50a8\u5728\u6587\u4ef6\u6216\u5185\u5b58\u7f13\u51b2\u533a\u4e2d\uff0c\u6216\u901a\u8fc7\u7f51\u7edc\u8fde\u63a5\u94fe\u8def\u4f20\u8f93\uff0c\u4ee5\u4fbf\u7a0d\u540e\u5728\u540c\u4e00\u4e2a\u6216\u53e6\u4e00\u4e2a\u8ba1\u7b97\u673a\u73af\u5883\u4e2d\u91cd\u5efa\u3002

    \n\n

    \u8bbe\u8ba1\u4e00\u4e2a\u7b97\u6cd5\u6765\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316 \u4e8c\u53c9\u641c\u7d22\u6811 \u3002 \u5bf9\u5e8f\u5217\u5316/\u53cd\u5e8f\u5217\u5316\u7b97\u6cd5\u7684\u5de5\u4f5c\u65b9\u5f0f\u6ca1\u6709\u9650\u5236\u3002 \u60a8\u53ea\u9700\u786e\u4fdd\u4e8c\u53c9\u641c\u7d22\u6811\u53ef\u4ee5\u5e8f\u5217\u5316\u4e3a\u5b57\u7b26\u4e32\uff0c\u5e76\u4e14\u53ef\u4ee5\u5c06\u8be5\u5b57\u7b26\u4e32\u53cd\u5e8f\u5217\u5316\u4e3a\u6700\u521d\u7684\u4e8c\u53c9\u641c\u7d22\u6811\u3002

    \n\n

    \u7f16\u7801\u7684\u5b57\u7b26\u4e32\u5e94\u5c3d\u53ef\u80fd\u7d27\u51d1\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [2,1,3]\n\u8f93\u51fa\uff1a[2,1,3]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = []\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u6570\u8303\u56f4\u662f [0, 104]
    • \n\t
    • 0 <= Node.val <= 104
    • \n\t
    • \u9898\u76ee\u6570\u636e \u4fdd\u8bc1 \u8f93\u5165\u7684\u6811\u662f\u4e00\u68f5\u4e8c\u53c9\u641c\u7d22\u6811\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u6ce8\u610f\uff1a\u4e0d\u8981\u4f7f\u7528\u7c7b\u6210\u5458/\u5168\u5c40/\u9759\u6001\u53d8\u91cf\u6765\u5b58\u50a8\u72b6\u6001\u3002 \u4f60\u7684\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316\u7b97\u6cd5\u5e94\u8be5\u662f\u65e0\u72b6\u6001\u7684\u3002

    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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 */\nclass Codec {\npublic:\n\n // Encodes a tree to a single string.\n string serialize(TreeNode* root) {\n \n }\n\n // Decodes your encoded data to tree.\n TreeNode* deserialize(string data) {\n \n }\n};\n\n// Your Codec object will be instantiated and called as such:\n// Codec* ser = new Codec();\n// Codec* deser = new Codec();\n// string tree = ser->serialize(root);\n// TreeNode* ans = deser->deserialize(tree);\n// return ans;", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode(int x) { val = x; }\n * }\n */\npublic class Codec {\n\n // Encodes a tree to a single string.\n public String serialize(TreeNode root) {\n \n }\n\n // Decodes your encoded data to tree.\n public TreeNode deserialize(String data) {\n \n }\n}\n\n// Your Codec object will be instantiated and called as such:\n// Codec ser = new Codec();\n// Codec deser = new Codec();\n// String tree = ser.serialize(root);\n// TreeNode ans = deser.deserialize(tree);\n// return ans;", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Codec:\n\n def serialize(self, root):\n \"\"\"Encodes a tree to a single string.\n \n :type root: TreeNode\n :rtype: str\n \"\"\"\n \n\n def deserialize(self, data):\n \"\"\"Decodes your encoded data to tree.\n \n :type data: str\n :rtype: TreeNode\n \"\"\"\n \n\n# Your Codec object will be instantiated and called as such:\n# ser = Codec()\n# deser = Codec()\n# tree = ser.serialize(root)\n# ans = deser.deserialize(tree)\n# return ans", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Codec:\n\n def serialize(self, root: TreeNode) -> str:\n \"\"\"Encodes a tree to a single string.\n \"\"\"\n \n\n def deserialize(self, data: str) -> TreeNode:\n \"\"\"Decodes your encoded data to tree.\n \"\"\"\n \n\n# Your Codec object will be instantiated and called as such:\n# Your Codec object will be instantiated and called as such:\n# ser = Codec()\n# deser = Codec()\n# tree = ser.serialize(root)\n# ans = deser.deserialize(tree)\n# return ans", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n/** Encodes a tree to a single string. */\nchar* serialize(struct TreeNode* root) {\n \n}\n\n/** Decodes your encoded data to tree. */\nstruct TreeNode* deserialize(char* data) {\n \n}\n\n// Your functions will be called as such:\n// char* data = serialize(root);\n// deserialize(data);", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int x) { val = x; }\n * }\n */\npublic class Codec {\n\n // Encodes a tree to a single string.\n public string serialize(TreeNode root) {\n \n }\n\n // Decodes your encoded data to tree.\n public TreeNode deserialize(string data) {\n \n }\n}\n\n// Your Codec object will be instantiated and called as such:\n// Codec ser = new Codec();\n// Codec deser = new Codec();\n// String tree = ser.serialize(root);\n// TreeNode ans = deser.deserialize(tree);\n// return ans;", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val) {\n * this.val = val;\n * this.left = this.right = null;\n * }\n */\n\n/**\n * Encodes a tree to a single string.\n *\n * @param {TreeNode} root\n * @return {string}\n */\nvar serialize = function(root) {\n \n};\n\n/**\n * Decodes your encoded data to tree.\n *\n * @param {string} data\n * @return {TreeNode}\n */\nvar deserialize = function(data) {\n \n};\n\n/**\n * Your functions will be called as such:\n * deserialize(serialize(root));\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val)\n# @val = val\n# @left, @right = nil, nil\n# end\n# end\n\n# Encodes a tree to a single string.\n#\n# @param {TreeNode} root\n# @return {string}\ndef serialize(root)\n \nend\n\n# Decodes your encoded data to tree.\n#\n# @param {string} data\n# @return {TreeNode}\ndef deserialize(data)\n \nend\n\n\n# Your functions will be called as such:\n# deserialize(serialize(data))", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.left = nil\n * self.right = nil\n * }\n * }\n */\n\nclass Codec {\n // Encodes a tree to a single string.\n func serialize(_ root: TreeNode?) -> String {\n \n }\n \n // Decodes your encoded data to tree.\n func deserialize(_ data: String) -> TreeNode? {\n \n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * let ser = Codec()\n * let deser = Codec()\n * let tree: String = ser.serialize(root)\n * let ans = deser.deserialize(tree)\n * return ans\n*/", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\n\ntype Codec struct {\n \n}\n\nfunc Constructor() Codec {\n \n}\n\n// Serializes a tree to a single string.\nfunc (this *Codec) serialize(root *TreeNode) string {\n \n}\n\n// Deserializes your encoded data to tree.\nfunc (this *Codec) deserialize(data string) *TreeNode { \n \n}\n\n\n/**\n * Your Codec object will be instantiated and called as such:\n * ser := Constructor()\n * deser := Constructor()\n * tree := ser.serialize(root)\n * ans := deser.deserialize(tree)\n * return ans\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(var _value: Int) {\n * var value: Int = _value\n * var left: TreeNode = null\n * var right: TreeNode = null\n * }\n */\n\nclass Codec {\n // Encodes a list of strings to a single string.\n def serialize(root: TreeNode): String = {\n \n }\n \n // Decodes a single string to a list of strings.\n def deserialize(data: String): TreeNode = {\n \n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * val ser = new Codec()\n * val deser = new Codec()\n * val tree: String = ser.serialize(root)\n * val ans = deser.deserialize(tree)\n * return ans\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\n\nclass Codec() {\n\t// Encodes a URL to a shortened URL.\n fun serialize(root: TreeNode?): String {\n \n }\n\n // Decodes your encoded data to tree.\n fun deserialize(data: String): TreeNode? {\n \n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * val ser = Codec()\n * val deser = Codec()\n * val tree: String = ser.serialize(root)\n * val ans = deser.deserialize(tree)\n * return ans\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n// \n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nstruct Codec {\n\t\n}\n\n/** \n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl Codec {\n fn new() -> Self {\n \n }\n\n fn serialize(&self, root: Option>>) -> String {\n \n }\n\t\n fn deserialize(&self, data: String) -> Option>> {\n \n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * let obj = Codec::new();\n * let data: String = obj.serialize(strs);\n * let ans: Option>> = obj.deserialize(data);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($value) { $this->val = $value; }\n * }\n */\n\nclass Codec {\n function __construct() {\n \n }\n \n /**\n * @param TreeNode $root\n * @return String\n */\n function serialize($root) {\n \n }\n \n /**\n * @param String $data\n * @return TreeNode\n */\n function deserialize($data) {\n \n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * $ser = new Codec();\n * $tree = $ser->serialize($param_1);\n * $deser = new Codec();\n * $ret = $deser->deserialize($tree);\n * return $ret;\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\n/*\n * Encodes a tree to a single string.\n */\nfunction serialize(root: TreeNode | null): string {\n\n};\n\n/*\n * Decodes your encoded data to tree.\n */\nfunction deserialize(data: string): TreeNode | null {\n\n};\n\n\n/**\n * Your functions will be called as such:\n * deserialize(serialize(root));\n */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0449](https://leetcode-cn.com/problems/serialize-and-deserialize-bst)", "[\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316\u4e8c\u53c9\u641c\u7d22\u6811](/solution/0400-0499/0449.Serialize%20and%20Deserialize%20BST/README.md)", "`\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0449](https://leetcode.com/problems/serialize-and-deserialize-bst)", "[Serialize and Deserialize BST](/solution/0400-0499/0449.Serialize%20and%20Deserialize%20BST/README_EN.md)", "`Tree`", "Medium", ""]}, {"question_id": "0448", "frontend_question_id": "0448", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-all-numbers-disappeared-in-an-array", "url_en": "https://leetcode.com/problems/find-all-numbers-disappeared-in-an-array", "relative_path_cn": "/solution/0400-0499/0448.Find%20All%20Numbers%20Disappeared%20in%20an%20Array/README.md", "relative_path_en": "/solution/0400-0499/0448.Find%20All%20Numbers%20Disappeared%20in%20an%20Array/README_EN.md", "title_cn": "\u627e\u5230\u6240\u6709\u6570\u7ec4\u4e2d\u6d88\u5931\u7684\u6570\u5b57", "title_en": "Find All Numbers Disappeared in an Array", "question_title_slug": "find-all-numbers-disappeared-in-an-array", "content_en": "

    Given an array nums of n integers where nums[i] is in the range [1, n], return an array of all the integers in the range [1, n] that do not appear in nums.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [4,3,2,7,8,2,3,1]\nOutput: [5,6]\n

    Example 2:

    \n
    Input: nums = [1,1]\nOutput: [2]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= n <= 105
    • \n\t
    • 1 <= nums[i] <= n
    • \n
    \n\n

     

    \n

    Follow up: Could you do it without extra space and in O(n) runtime? You may assume the returned list does not count as extra space.

    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u542b n \u4e2a\u6574\u6570\u7684\u6570\u7ec4 nums \uff0c\u5176\u4e2d nums[i] \u5728\u533a\u95f4 [1, n] \u5185\u3002\u8bf7\u4f60\u627e\u51fa\u6240\u6709\u5728 [1, n] \u8303\u56f4\u5185\u4f46\u6ca1\u6709\u51fa\u73b0\u5728 nums \u4e2d\u7684\u6570\u5b57\uff0c\u5e76\u4ee5\u6570\u7ec4\u7684\u5f62\u5f0f\u8fd4\u56de\u7ed3\u679c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [4,3,2,7,8,2,3,1]\n\u8f93\u51fa\uff1a[5,6]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,1]\n\u8f93\u51fa\uff1a[2]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= n <= 105
    • \n\t
    • 1 <= nums[i] <= n
    • \n
    \n\n

    \u8fdb\u9636\uff1a\u4f60\u80fd\u5728\u4e0d\u4f7f\u7528\u989d\u5916\u7a7a\u95f4\u4e14\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n) \u7684\u60c5\u51b5\u4e0b\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u5417? \u4f60\u53ef\u4ee5\u5047\u5b9a\u8fd4\u56de\u7684\u6570\u7ec4\u4e0d\u7b97\u5728\u989d\u5916\u7a7a\u95f4\u5185\u3002

    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findDisappearedNumbers(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List findDisappearedNumbers(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findDisappearedNumbers(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findDisappearedNumbers(self, nums: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* findDisappearedNumbers(int* nums, int numsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList FindDisappearedNumbers(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar findDisappearedNumbers = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer[]}\ndef find_disappeared_numbers(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findDisappearedNumbers(_ nums: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findDisappearedNumbers(nums []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findDisappearedNumbers(nums: Array[Int]): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findDisappearedNumbers(nums: IntArray): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_disappeared_numbers(nums: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer[]\n */\n function findDisappearedNumbers($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findDisappearedNumbers(nums: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-disappeared-numbers nums)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0448](https://leetcode-cn.com/problems/find-all-numbers-disappeared-in-an-array)", "[\u627e\u5230\u6240\u6709\u6570\u7ec4\u4e2d\u6d88\u5931\u7684\u6570\u5b57](/solution/0400-0499/0448.Find%20All%20Numbers%20Disappeared%20in%20an%20Array/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0448](https://leetcode.com/problems/find-all-numbers-disappeared-in-an-array)", "[Find All Numbers Disappeared in an Array](/solution/0400-0499/0448.Find%20All%20Numbers%20Disappeared%20in%20an%20Array/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0447", "frontend_question_id": "0447", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-boomerangs", "url_en": "https://leetcode.com/problems/number-of-boomerangs", "relative_path_cn": "/solution/0400-0499/0447.Number%20of%20Boomerangs/README.md", "relative_path_en": "/solution/0400-0499/0447.Number%20of%20Boomerangs/README_EN.md", "title_cn": "\u56de\u65cb\u9556\u7684\u6570\u91cf", "title_en": "Number of Boomerangs", "question_title_slug": "number-of-boomerangs", "content_en": "

    You are given n points in the plane that are all distinct, where points[i] = [xi, yi]. A boomerang is a tuple of points (i, j, k) such that the distance between i and j equals the distance between i and k (the order of the tuple matters).

    \n\n

    Return the number of boomerangs.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: points = [[0,0],[1,0],[2,0]]\nOutput: 2\nExplanation: The two boomerangs are [[1,0],[0,0],[2,0]] and [[1,0],[2,0],[0,0]].\n
    \n\n

    Example 2:

    \n\n
    \nInput: points = [[1,1],[2,2],[3,3]]\nOutput: 2\n
    \n\n

    Example 3:

    \n\n
    \nInput: points = [[1,1]]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == points.length
    • \n\t
    • 1 <= n <= 500
    • \n\t
    • points[i].length == 2
    • \n\t
    • -104 <= xi, yi <= 104
    • \n\t
    • All the points are unique.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u5e73\u9762\u4e0a\u00a0n \u5bf9 \u4e92\u4e0d\u76f8\u540c \u7684\u70b9\u00a0points \uff0c\u5176\u4e2d points[i] = [xi, yi] \u3002\u56de\u65cb\u9556 \u662f\u7531\u70b9\u00a0(i, j, k) \u8868\u793a\u7684\u5143\u7ec4 \uff0c\u5176\u4e2d\u00a0i\u00a0\u548c\u00a0j\u00a0\u4e4b\u95f4\u7684\u8ddd\u79bb\u548c\u00a0i\u00a0\u548c\u00a0k\u00a0\u4e4b\u95f4\u7684\u8ddd\u79bb\u76f8\u7b49\uff08\u9700\u8981\u8003\u8651\u5143\u7ec4\u7684\u987a\u5e8f\uff09\u3002

    \n\n

    \u8fd4\u56de\u5e73\u9762\u4e0a\u6240\u6709\u56de\u65cb\u9556\u7684\u6570\u91cf\u3002

    \n\u00a0\n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1apoints = [[0,0],[1,0],[2,0]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u4e24\u4e2a\u56de\u65cb\u9556\u4e3a [[1,0],[0,0],[2,0]] \u548c [[1,0],[2,0],[0,0]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1apoints = [[1,1],[2,2],[3,3]]\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1apoints = [[1,1]]\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n ==\u00a0points.length
    • \n\t
    • 1 <= n <= 500
    • \n\t
    • points[i].length == 2
    • \n\t
    • -104 <= xi, yi <= 104
    • \n\t
    • \u6240\u6709\u70b9\u90fd \u4e92\u4e0d\u76f8\u540c
    • \n
    \n", "tags_en": ["Hash Table", "Math"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numberOfBoomerangs(vector>& points) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numberOfBoomerangs(int[][] points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numberOfBoomerangs(self, points):\n \"\"\"\n :type points: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numberOfBoomerangs(self, points: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numberOfBoomerangs(int** points, int pointsSize, int* pointsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumberOfBoomerangs(int[][] points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} points\n * @return {number}\n */\nvar numberOfBoomerangs = function(points) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} points\n# @return {Integer}\ndef number_of_boomerangs(points)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numberOfBoomerangs(_ points: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numberOfBoomerangs(points [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numberOfBoomerangs(points: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numberOfBoomerangs(points: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn number_of_boomerangs(points: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $points\n * @return Integer\n */\n function numberOfBoomerangs($points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numberOfBoomerangs(points: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (number-of-boomerangs points)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0447](https://leetcode-cn.com/problems/number-of-boomerangs)", "[\u56de\u65cb\u9556\u7684\u6570\u91cf](/solution/0400-0499/0447.Number%20of%20Boomerangs/README.md)", "`\u54c8\u5e0c\u8868`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0447](https://leetcode.com/problems/number-of-boomerangs)", "[Number of Boomerangs](/solution/0400-0499/0447.Number%20of%20Boomerangs/README_EN.md)", "`Hash Table`,`Math`", "Medium", ""]}, {"question_id": "0446", "frontend_question_id": "0446", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/arithmetic-slices-ii-subsequence", "url_en": "https://leetcode.com/problems/arithmetic-slices-ii-subsequence", "relative_path_cn": "/solution/0400-0499/0446.Arithmetic%20Slices%20II%20-%20Subsequence/README.md", "relative_path_en": "/solution/0400-0499/0446.Arithmetic%20Slices%20II%20-%20Subsequence/README_EN.md", "title_cn": "\u7b49\u5dee\u6570\u5217\u5212\u5206 II - \u5b50\u5e8f\u5217", "title_en": "Arithmetic Slices II - Subsequence", "question_title_slug": "arithmetic-slices-ii-subsequence", "content_en": "

    Given an integer array nums, return the number of all the arithmetic subsequences of nums.

    \n\n

    A sequence of numbers is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.

    \n\n
      \n\t
    • For example, [1, 3, 5, 7, 9], [7, 7, 7, 7], and [3, -1, -5, -9] are arithmetic sequences.
    • \n\t
    • For example, [1, 1, 2, 5, 7] is not an arithmetic sequence.
    • \n
    \n\n

    A subsequence of an array is a sequence that can be formed by removing some elements (possibly none) of the array.

    \n\n
      \n\t
    • For example, [2,5,10] is a subsequence of [1,2,1,2,4,1,5,10].
    • \n
    \n\n

    The answer is guaranteed to fit in 32-bit integer.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [2,4,6,8,10]\nOutput: 7\nExplanation: All arithmetic subsequence slices are:\n[2,4,6]\n[4,6,8]\n[6,8,10]\n[2,4,6,8]\n[4,6,8,10]\n[2,4,6,8,10]\n[2,6,10]\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [7,7,7,7,7]\nOutput: 16\nExplanation: Any subsequence of this array is arithmetic.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1  <= nums.length <= 1000
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n
    \n", "content_cn": "

    \u5982\u679c\u4e00\u4e2a\u6570\u5217\u81f3\u5c11\u6709\u4e09\u4e2a\u5143\u7d20\uff0c\u5e76\u4e14\u4efb\u610f\u4e24\u4e2a\u76f8\u90bb\u5143\u7d20\u4e4b\u5dee\u76f8\u540c\uff0c\u5219\u79f0\u8be5\u6570\u5217\u4e3a\u7b49\u5dee\u6570\u5217\u3002

    \n\n

    \u4f8b\u5982\uff0c\u4ee5\u4e0b\u6570\u5217\u4e3a\u7b49\u5dee\u6570\u5217:

    \n\n
    \n1, 3, 5, 7, 9\n7, 7, 7, 7\n3, -1, -5, -9
    \n\n

    \u4ee5\u4e0b\u6570\u5217\u4e0d\u662f\u7b49\u5dee\u6570\u5217\u3002

    \n\n
    \n1, 1, 2, 5, 7
    \n\n

    \u00a0

    \n\n

    \u6570\u7ec4 A \u5305\u542b N \u4e2a\u6570\uff0c\u4e14\u7d22\u5f15\u4ece 0 \u5f00\u59cb\u3002\u8be5\u6570\u7ec4\u5b50\u5e8f\u5217\u5c06\u5212\u5206\u4e3a\u6574\u6570\u5e8f\u5217\u00a0(P0, P1, ..., Pk)\uff0c\u6ee1\u8db3 0 \u2264 P0 < P1 < ... < Pk < N\u3002

    \n\n

    \u00a0

    \n\n

    \u5982\u679c\u5e8f\u5217 A[P0]\uff0cA[P1]\uff0c...\uff0cA[Pk-1]\uff0cA[Pk] \u662f\u7b49\u5dee\u7684\uff0c\u90a3\u4e48\u6570\u7ec4 A \u7684\u5b50\u5e8f\u5217 (P0\uff0cP1\uff0c\u2026\uff0cPK) \u79f0\u4e3a\u7b49\u5dee\u5e8f\u5217\u3002\u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0c\u8fd9\u610f\u5473\u7740 k \u2265 2\u3002

    \n\n

    \u51fd\u6570\u8981\u8fd4\u56de\u6570\u7ec4 A \u4e2d\u6240\u6709\u7b49\u5dee\u5b50\u5e8f\u5217\u7684\u4e2a\u6570\u3002

    \n\n

    \u8f93\u5165\u5305\u542b N \u4e2a\u6574\u6570\u3002\u6bcf\u4e2a\u6574\u6570\u90fd\u5728 -231 \u548c 231-1 \u4e4b\u95f4\uff0c\u53e6\u5916 0 \u2264 N \u2264 1000\u3002\u4fdd\u8bc1\u8f93\u51fa\u5c0f\u4e8e 231-1\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[2, 4, 6, 8, 10]\n\n\u8f93\u51fa\uff1a7\n\n\u89e3\u91ca\uff1a\n\u6240\u6709\u7684\u7b49\u5dee\u5b50\u5e8f\u5217\u4e3a\uff1a\n[2,4,6]\n[4,6,8]\n[6,8,10]\n[2,4,6,8]\n[4,6,8,10]\n[2,4,6,8,10]\n[2,6,10]\n
    \n\n

    \u00a0

    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numberOfArithmeticSlices(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numberOfArithmeticSlices(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numberOfArithmeticSlices(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numberOfArithmeticSlices(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numberOfArithmeticSlices(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumberOfArithmeticSlices(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar numberOfArithmeticSlices = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef number_of_arithmetic_slices(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numberOfArithmeticSlices(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numberOfArithmeticSlices(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numberOfArithmeticSlices(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numberOfArithmeticSlices(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn number_of_arithmetic_slices(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function numberOfArithmeticSlices($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numberOfArithmeticSlices(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (number-of-arithmetic-slices nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0446](https://leetcode-cn.com/problems/arithmetic-slices-ii-subsequence)", "[\u7b49\u5dee\u6570\u5217\u5212\u5206 II - \u5b50\u5e8f\u5217](/solution/0400-0499/0446.Arithmetic%20Slices%20II%20-%20Subsequence/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0446](https://leetcode.com/problems/arithmetic-slices-ii-subsequence)", "[Arithmetic Slices II - Subsequence](/solution/0400-0499/0446.Arithmetic%20Slices%20II%20-%20Subsequence/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "0445", "frontend_question_id": "0445", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/add-two-numbers-ii", "url_en": "https://leetcode.com/problems/add-two-numbers-ii", "relative_path_cn": "/solution/0400-0499/0445.Add%20Two%20Numbers%20II/README.md", "relative_path_en": "/solution/0400-0499/0445.Add%20Two%20Numbers%20II/README_EN.md", "title_cn": "\u4e24\u6570\u76f8\u52a0 II", "title_en": "Add Two Numbers II", "question_title_slug": "add-two-numbers-ii", "content_en": "

    You are given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list.

    \n\n

    You may assume the two numbers do not contain any leading zero, except the number 0 itself.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: l1 = [7,2,4,3], l2 = [5,6,4]\nOutput: [7,8,0,7]\n
    \n\n

    Example 2:

    \n\n
    \nInput: l1 = [2,4,3], l2 = [5,6,4]\nOutput: [8,0,7]\n
    \n\n

    Example 3:

    \n\n
    \nInput: l1 = [0], l2 = [0]\nOutput: [0]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in each linked list is in the range [1, 100].
    • \n\t
    • 0 <= Node.val <= 9
    • \n\t
    • It is guaranteed that the list represents a number that does not have leading zeros.
    • \n
    \n\n

     

    \n

    Follow up: Could you solve it without reversing the input lists?

    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a \u975e\u7a7a \u94fe\u8868\u6765\u4ee3\u8868\u4e24\u4e2a\u975e\u8d1f\u6574\u6570\u3002\u6570\u5b57\u6700\u9ad8\u4f4d\u4f4d\u4e8e\u94fe\u8868\u5f00\u59cb\u4f4d\u7f6e\u3002\u5b83\u4eec\u7684\u6bcf\u4e2a\u8282\u70b9\u53ea\u5b58\u50a8\u4e00\u4f4d\u6570\u5b57\u3002\u5c06\u8fd9\u4e24\u6570\u76f8\u52a0\u4f1a\u8fd4\u56de\u4e00\u4e2a\u65b0\u7684\u94fe\u8868\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u5047\u8bbe\u9664\u4e86\u6570\u5b57 0 \u4e4b\u5916\uff0c\u8fd9\u4e24\u4e2a\u6570\u5b57\u90fd\u4e0d\u4f1a\u4ee5\u96f6\u5f00\u5934\u3002

    \n\n

     

    \n\n

    \u8fdb\u9636\uff1a

    \n\n

    \u5982\u679c\u8f93\u5165\u94fe\u8868\u4e0d\u80fd\u4fee\u6539\u8be5\u5982\u4f55\u5904\u7406\uff1f\u6362\u53e5\u8bdd\u8bf4\uff0c\u4f60\u4e0d\u80fd\u5bf9\u5217\u8868\u4e2d\u7684\u8282\u70b9\u8fdb\u884c\u7ffb\u8f6c\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1a(7 -> 2 -> 4 -> 3) + (5 -> 6 -> 4)\n\u8f93\u51fa\uff1a7 -> 8 -> 0 -> 7\n
    \n", "tags_en": ["Linked List"], "tags_cn": ["\u94fe\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public ListNode addTwoNumbers(ListNode l1, ListNode l2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def addTwoNumbers(self, l1, l2):\n \"\"\"\n :type l1: ListNode\n :type l2: ListNode\n :rtype: ListNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nstruct ListNode* addTwoNumbers(struct ListNode* l1, struct ListNode* l2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public ListNode AddTwoNumbers(ListNode l1, ListNode l2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} l1\n * @param {ListNode} l2\n * @return {ListNode}\n */\nvar addTwoNumbers = function(l1, l2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode} l1\n# @param {ListNode} l2\n# @return {ListNode}\ndef add_two_numbers(l1, l2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func addTwoNumbers(_ l1: ListNode?, _ l2: ListNode?) -> ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc addTwoNumbers(l1 *ListNode, l2 *ListNode) *ListNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def addTwoNumbers(l1: ListNode, l2: ListNode): ListNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun addTwoNumbers(l1: ListNode?, l2: ListNode?): ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn add_two_numbers(l1: Option>, l2: Option>) -> Option> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $l1\n * @param ListNode $l2\n * @return ListNode\n */\n function addTwoNumbers($l1, $l2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction addTwoNumbers(l1: ListNode | null, l2: ListNode | null): ListNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (add-two-numbers l1 l2)\n (-> (or/c list-node? #f) (or/c list-node? #f) (or/c list-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0445](https://leetcode-cn.com/problems/add-two-numbers-ii)", "[\u4e24\u6570\u76f8\u52a0 II](/solution/0400-0499/0445.Add%20Two%20Numbers%20II/README.md)", "`\u94fe\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0445](https://leetcode.com/problems/add-two-numbers-ii)", "[Add Two Numbers II](/solution/0400-0499/0445.Add%20Two%20Numbers%20II/README_EN.md)", "`Linked List`", "Medium", ""]}, {"question_id": "0444", "frontend_question_id": "0444", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/sequence-reconstruction", "url_en": "https://leetcode.com/problems/sequence-reconstruction", "relative_path_cn": "/solution/0400-0499/0444.Sequence%20Reconstruction/README.md", "relative_path_en": "/solution/0400-0499/0444.Sequence%20Reconstruction/README_EN.md", "title_cn": "\u5e8f\u5217\u91cd\u5efa", "title_en": "Sequence Reconstruction", "question_title_slug": "sequence-reconstruction", "content_en": "

    Check whether the original sequence org can be uniquely reconstructed from the sequences in seqs. The org sequence is a permutation of the integers from 1 to n, with 1 ≤ n ≤ 104. Reconstruction means building a shortest common supersequence of the sequences in seqs (i.e., a shortest sequence so that all sequences in seqs are subsequences of it). Determine whether there is only one sequence that can be reconstructed from seqs and it is the org sequence.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: org = [1,2,3], seqs = [[1,2],[1,3]]\nOutput: false\nExplanation: [1,2,3] is not the only one sequence that can be reconstructed, because [1,3,2] is also a valid sequence that can be reconstructed.\n
    \n\n

    Example 2:

    \n\n
    \nInput: org = [1,2,3], seqs = [[1,2]]\nOutput: false\nExplanation: The reconstructed sequence can only be [1,2].\n
    \n\n

    Example 3:

    \n\n
    \nInput: org = [1,2,3], seqs = [[1,2],[1,3],[2,3]]\nOutput: true\nExplanation: The sequences [1,2], [1,3], and [2,3] can uniquely reconstruct the original sequence [1,2,3].\n
    \n\n

    Example 4:

    \n\n
    \nInput: org = [4,1,5,2,6,3], seqs = [[5,2,6,3],[4,1,5,2]]\nOutput: true\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 10^4
    • \n\t
    • org is a permutation of {1,2,...,n}.
    • \n\t
    • 1 <= segs[i].length <= 10^5
    • \n\t
    • seqs[i][j] fits in a 32-bit signed integer.
    • \n
    \n\n

     

    \n\n

    UPDATE (2017/1/8):
    \nThe seqs parameter had been changed to a list of list of strings (instead of a 2d array of strings). Please reload the code definition to get the latest changes.

    \n", "content_cn": "

    \u9a8c\u8bc1\u539f\u59cb\u7684\u5e8f\u5217 org \u662f\u5426\u53ef\u4ee5\u4ece\u5e8f\u5217\u96c6 seqs \u4e2d\u552f\u4e00\u5730\u91cd\u5efa\u3002\u5e8f\u5217 org \u662f 1 \u5230 n \u6574\u6570\u7684\u6392\u5217\uff0c\u5176\u4e2d 1 ≤ n ≤ 104\u3002\u91cd\u5efa\u662f\u6307\u5728\u5e8f\u5217\u96c6 seqs \u4e2d\u6784\u5efa\u6700\u77ed\u7684\u516c\u5171\u8d85\u5e8f\u5217\u3002\uff08\u5373\u4f7f\u5f97\u6240\u6709  seqs \u4e2d\u7684\u5e8f\u5217\u90fd\u662f\u8be5\u6700\u77ed\u5e8f\u5217\u7684\u5b50\u5e8f\u5217\uff09\u3002\u786e\u5b9a\u662f\u5426\u53ea\u53ef\u4ee5\u4ece seqs \u91cd\u5efa\u552f\u4e00\u7684\u5e8f\u5217\uff0c\u4e14\u8be5\u5e8f\u5217\u5c31\u662f org \u3002

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a\norg: [1,2,3], seqs: [[1,2],[1,3]]\n\n\u8f93\u51fa\uff1a\nfalse\n\n\u89e3\u91ca\uff1a\n[1,2,3] \u4e0d\u662f\u53ef\u4ee5\u88ab\u91cd\u5efa\u7684\u552f\u4e00\u7684\u5e8f\u5217\uff0c\u56e0\u4e3a [1,3,2] \u4e5f\u662f\u4e00\u4e2a\u5408\u6cd5\u7684\u5e8f\u5217\u3002\n
    \n\n

     

    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a\norg: [1,2,3], seqs: [[1,2]]\n\n\u8f93\u51fa\uff1a\nfalse\n\n\u89e3\u91ca\uff1a\n\u53ef\u4ee5\u91cd\u5efa\u7684\u5e8f\u5217\u53ea\u6709 [1,2]\u3002\n
    \n\n

     

    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1a\norg: [1,2,3], seqs: [[1,2],[1,3],[2,3]]\n\n\u8f93\u51fa\uff1a\ntrue\n\n\u89e3\u91ca\uff1a\n\u5e8f\u5217 [1,2], [1,3] \u548c [2,3] \u53ef\u4ee5\u88ab\u552f\u4e00\u5730\u91cd\u5efa\u4e3a\u539f\u59cb\u7684\u5e8f\u5217 [1,2,3]\u3002\n
    \n\n

     

    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1a\norg: [4,1,5,2,6,3], seqs: [[5,2,6,3],[4,1,5,2]]\n\n\u8f93\u51fa\uff1a\ntrue\n
    \n", "tags_en": ["Graph", "Topological Sort"], "tags_cn": ["\u56fe", "\u62d3\u6251\u6392\u5e8f"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool sequenceReconstruction(vector& org, vector>& seqs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean sequenceReconstruction(int[] org, List> seqs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def sequenceReconstruction(self, org, seqs):\n \"\"\"\n :type org: List[int]\n :type seqs: List[List[int]]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def sequenceReconstruction(self, org: List[int], seqs: List[List[int]]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool sequenceReconstruction(int* org, int orgSize, int** seqs, int seqsSize, int* seqsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool SequenceReconstruction(int[] org, IList> seqs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} org\n * @param {number[][]} seqs\n * @return {boolean}\n */\nvar sequenceReconstruction = function(org, seqs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} org\n# @param {Integer[][]} seqs\n# @return {Boolean}\ndef sequence_reconstruction(org, seqs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func sequenceReconstruction(_ org: [Int], _ seqs: [[Int]]) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func sequenceReconstruction(org []int, seqs [][]int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def sequenceReconstruction(org: Array[Int], seqs: List[List[Int]]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun sequenceReconstruction(org: IntArray, seqs: List>): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sequence_reconstruction(org: Vec, seqs: Vec>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $org\n * @param Integer[][] $seqs\n * @return Boolean\n */\n function sequenceReconstruction($org, $seqs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function sequenceReconstruction(org: number[], seqs: number[][]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (sequence-reconstruction org seqs)\n (-> (listof exact-integer?) (listof (listof exact-integer?)) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0444](https://leetcode-cn.com/problems/sequence-reconstruction)", "[\u5e8f\u5217\u91cd\u5efa](/solution/0400-0499/0444.Sequence%20Reconstruction/README.md)", "`\u56fe`,`\u62d3\u6251\u6392\u5e8f`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0444](https://leetcode.com/problems/sequence-reconstruction)", "[Sequence Reconstruction](/solution/0400-0499/0444.Sequence%20Reconstruction/README_EN.md)", "`Graph`,`Topological Sort`", "Medium", "\ud83d\udd12"]}, {"question_id": "0443", "frontend_question_id": "0443", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/string-compression", "url_en": "https://leetcode.com/problems/string-compression", "relative_path_cn": "/solution/0400-0499/0443.String%20Compression/README.md", "relative_path_en": "/solution/0400-0499/0443.String%20Compression/README_EN.md", "title_cn": "\u538b\u7f29\u5b57\u7b26\u4e32", "title_en": "String Compression", "question_title_slug": "string-compression", "content_en": "

    Given an array of characters chars, compress it using the following algorithm:

    \n\n

    Begin with an empty string s. For each group of consecutive repeating characters in chars:

    \n\n
      \n\t
    • If the group's length is 1, append the character to s.
    • \n\t
    • Otherwise, append the character followed by the group's length.
    • \n
    \n\n

    The compressed string s should not be returned separately, but instead be stored in the input character array chars. Note that group lengths that are 10 or longer will be split into multiple characters in chars.

    \n\n

    After you are done modifying the input array, return the new length of the array.

    \nYou must write an algorithm that uses only constant extra space.\n

     

    \n

    Example 1:

    \n\n
    \nInput: chars = ["a","a","b","b","c","c","c"]\nOutput: Return 6, and the first 6 characters of the input array should be: ["a","2","b","2","c","3"]\nExplanation: The groups are "aa", "bb", and "ccc". This compresses to "a2b2c3".\n
    \n\n

    Example 2:

    \n\n
    \nInput: chars = ["a"]\nOutput: Return 1, and the first character of the input array should be: ["a"]\nExplanation: The only group is "a", which remains uncompressed since it's a single character.\n
    \n\n

    Example 3:

    \n\n
    \nInput: chars = ["a","b","b","b","b","b","b","b","b","b","b","b","b"]\nOutput: Return 4, and the first 4 characters of the input array should be: ["a","b","1","2"].\nExplanation: The groups are "a" and "bbbbbbbbbbbb". This compresses to "ab12".
    \n\n

    Example 4:

    \n\n
    \nInput: chars = ["a","a","a","b","b","a","a"]\nOutput: Return 6, and the first 6 characters of the input array should be: ["a","3","b","2","a","2"].\nExplanation: The groups are "aaa", "bb", and "aa". This compresses to "a3b2a2". Note that each group is independent even if two groups have the same character.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= chars.length <= 2000
    • \n\t
    • chars[i] is a lower-case English letter, upper-case English letter, digit, or symbol.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u7ec4\u5b57\u7b26\uff0c\u4f7f\u7528\u539f\u5730\u7b97\u6cd5\u5c06\u5176\u538b\u7f29\u3002

    \n\n

    \u538b\u7f29\u540e\u7684\u957f\u5ea6\u5fc5\u987b\u59cb\u7ec8\u5c0f\u4e8e\u6216\u7b49\u4e8e\u539f\u6570\u7ec4\u957f\u5ea6\u3002

    \n\n

    \u6570\u7ec4\u7684\u6bcf\u4e2a\u5143\u7d20\u5e94\u8be5\u662f\u957f\u5ea6\u4e3a1 \u7684\u5b57\u7b26\uff08\u4e0d\u662f int \u6574\u6570\u7c7b\u578b\uff09\u3002

    \n\n

    \u5728\u5b8c\u6210\u539f\u5730\u4fee\u6539\u8f93\u5165\u6570\u7ec4\u540e\uff0c\u8fd4\u56de\u6570\u7ec4\u7684\u65b0\u957f\u5ea6\u3002

    \n\n

     

    \n\n

    \u8fdb\u9636\uff1a
    \n\u4f60\u80fd\u5426\u4ec5\u4f7f\u7528O(1) \u7a7a\u95f4\u89e3\u51b3\u95ee\u9898\uff1f

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a\n["a","a","b","b","c","c","c"]\n\n\u8f93\u51fa\uff1a\n\u8fd4\u56de 6 \uff0c\u8f93\u5165\u6570\u7ec4\u7684\u524d 6 \u4e2a\u5b57\u7b26\u5e94\u8be5\u662f\uff1a["a","2","b","2","c","3"]\n\n\u8bf4\u660e\uff1a\n"aa" \u88ab "a2" \u66ff\u4ee3\u3002"bb" \u88ab "b2" \u66ff\u4ee3\u3002"ccc" \u88ab "c3" \u66ff\u4ee3\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a\n["a"]\n\n\u8f93\u51fa\uff1a\n\u8fd4\u56de 1 \uff0c\u8f93\u5165\u6570\u7ec4\u7684\u524d 1 \u4e2a\u5b57\u7b26\u5e94\u8be5\u662f\uff1a["a"]\n\n\u89e3\u91ca\uff1a\n\u6ca1\u6709\u4efb\u4f55\u5b57\u7b26\u4e32\u88ab\u66ff\u4ee3\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1a\n["a","b","b","b","b","b","b","b","b","b","b","b","b"]\n\n\u8f93\u51fa\uff1a\n\u8fd4\u56de 4 \uff0c\u8f93\u5165\u6570\u7ec4\u7684\u524d4\u4e2a\u5b57\u7b26\u5e94\u8be5\u662f\uff1a["a","b","1","2"]\u3002\n\n\u89e3\u91ca\uff1a\n\u7531\u4e8e\u5b57\u7b26 "a" \u4e0d\u91cd\u590d\uff0c\u6240\u4ee5\u4e0d\u4f1a\u88ab\u538b\u7f29\u3002"bbbbbbbbbbbb" \u88ab “b12” \u66ff\u4ee3\u3002\n\u6ce8\u610f\u6bcf\u4e2a\u6570\u5b57\u5728\u6570\u7ec4\u4e2d\u90fd\u6709\u5b83\u81ea\u5df1\u7684\u4f4d\u7f6e\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6240\u6709\u5b57\u7b26\u90fd\u6709\u4e00\u4e2aASCII\u503c\u5728[35, 126]\u533a\u95f4\u5185\u3002
    • \n\t
    • 1 <= len(chars) <= 1000\u3002
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int compress(vector& chars) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int compress(char[] chars) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def compress(self, chars):\n \"\"\"\n :type chars: List[str]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def compress(self, chars: List[str]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint compress(char* chars, int charsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int Compress(char[] chars) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {character[]} chars\n * @return {number}\n */\nvar compress = function(chars) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Character[]} chars\n# @return {Integer}\ndef compress(chars)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func compress(_ chars: inout [Character]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func compress(chars []byte) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def compress(chars: Array[Char]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun compress(chars: CharArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn compress(chars: &mut Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $chars\n * @return Integer\n */\n function compress(&$chars) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function compress(chars: string[]): number {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0443](https://leetcode-cn.com/problems/string-compression)", "[\u538b\u7f29\u5b57\u7b26\u4e32](/solution/0400-0499/0443.String%20Compression/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0443](https://leetcode.com/problems/string-compression)", "[String Compression](/solution/0400-0499/0443.String%20Compression/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "0442", "frontend_question_id": "0442", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-all-duplicates-in-an-array", "url_en": "https://leetcode.com/problems/find-all-duplicates-in-an-array", "relative_path_cn": "/solution/0400-0499/0442.Find%20All%20Duplicates%20in%20an%20Array/README.md", "relative_path_en": "/solution/0400-0499/0442.Find%20All%20Duplicates%20in%20an%20Array/README_EN.md", "title_cn": "\u6570\u7ec4\u4e2d\u91cd\u590d\u7684\u6570\u636e", "title_en": "Find All Duplicates in an Array", "question_title_slug": "find-all-duplicates-in-an-array", "content_en": "

    Given an integer array nums of length n where all the integers of nums are in the range [1, n] and each integer appears once or twice, return an array of all the integers that appears twice.

    \n\n

    You must write an algorithm that runs in O(n) time and uses only constant extra space.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [4,3,2,7,8,2,3,1]\nOutput: [2,3]\n

    Example 2:

    \n
    Input: nums = [1,1,2]\nOutput: [1]\n

    Example 3:

    \n
    Input: nums = [1]\nOutput: []\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= n <= 105
    • \n\t
    • 1 <= nums[i] <= n
    • \n\t
    • Each element in nums appears once or twice.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 a\uff0c\u5176\u4e2d1 ≤ a[i] ≤ n \uff08n\u4e3a\u6570\u7ec4\u957f\u5ea6\uff09, \u5176\u4e2d\u6709\u4e9b\u5143\u7d20\u51fa\u73b0\u4e24\u6b21\u800c\u5176\u4ed6\u5143\u7d20\u51fa\u73b0\u4e00\u6b21\u3002

    \n\n

    \u627e\u5230\u6240\u6709\u51fa\u73b0\u4e24\u6b21\u7684\u5143\u7d20\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u4e0d\u7528\u5230\u4efb\u4f55\u989d\u5916\u7a7a\u95f4\u5e76\u5728O(n)\u65f6\u95f4\u590d\u6742\u5ea6\u5185\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u5417\uff1f

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165:\n[4,3,2,7,8,2,3,1]\n\n\u8f93\u51fa:\n[2,3]\n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findDuplicates(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List findDuplicates(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findDuplicates(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findDuplicates(self, nums: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* findDuplicates(int* nums, int numsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList FindDuplicates(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar findDuplicates = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer[]}\ndef find_duplicates(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findDuplicates(_ nums: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findDuplicates(nums []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findDuplicates(nums: Array[Int]): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findDuplicates(nums: IntArray): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_duplicates(nums: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer[]\n */\n function findDuplicates($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findDuplicates(nums: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-duplicates nums)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0442](https://leetcode-cn.com/problems/find-all-duplicates-in-an-array)", "[\u6570\u7ec4\u4e2d\u91cd\u590d\u7684\u6570\u636e](/solution/0400-0499/0442.Find%20All%20Duplicates%20in%20an%20Array/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0442](https://leetcode.com/problems/find-all-duplicates-in-an-array)", "[Find All Duplicates in an Array](/solution/0400-0499/0442.Find%20All%20Duplicates%20in%20an%20Array/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0441", "frontend_question_id": "0441", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/arranging-coins", "url_en": "https://leetcode.com/problems/arranging-coins", "relative_path_cn": "/solution/0400-0499/0441.Arranging%20Coins/README.md", "relative_path_en": "/solution/0400-0499/0441.Arranging%20Coins/README_EN.md", "title_cn": "\u6392\u5217\u786c\u5e01", "title_en": "Arranging Coins", "question_title_slug": "arranging-coins", "content_en": "

    You have n coins and you want to build a staircase with these coins. The staircase consists of k rows where the ith row has exactly i coins. The last row of the staircase may be incomplete.

    \n\n

    Given the integer n, return the number of complete rows of the staircase you will build.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: n = 5\nOutput: 2\nExplanation: Because the 3rd row is incomplete, we return 2.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: n = 8\nOutput: 3\nExplanation: Because the 4th row is incomplete, we return 3.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 231 - 1
    • \n
    \n", "content_cn": "

    \u4f60\u603b\u5171\u6709 \u679a\u786c\u5e01\uff0c\u4f60\u9700\u8981\u5c06\u5b83\u4eec\u6446\u6210\u4e00\u4e2a\u9636\u68af\u5f62\u72b6\uff0c\u7b2c \u884c\u5c31\u5fc5\u987b\u6b63\u597d\u6709 \u679a\u786c\u5e01\u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u6570\u5b57 n\uff0c\u627e\u51fa\u53ef\u5f62\u6210\u5b8c\u6574\u9636\u68af\u884c\u7684\u603b\u884c\u6570\u3002

    \n\n

    \u662f\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\uff0c\u5e76\u4e14\u572832\u4f4d\u6709\u7b26\u53f7\u6574\u578b\u7684\u8303\u56f4\u5185\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \nn = 5\n\n\u786c\u5e01\u53ef\u6392\u5217\u6210\u4ee5\u4e0b\u51e0\u884c:\n¤\n¤ ¤\n¤ ¤\n\n\u56e0\u4e3a\u7b2c\u4e09\u884c\u4e0d\u5b8c\u6574\uff0c\u6240\u4ee5\u8fd4\u56de2.\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \nn = 8\n\n\u786c\u5e01\u53ef\u6392\u5217\u6210\u4ee5\u4e0b\u51e0\u884c:\n¤\n¤ ¤\n¤ ¤ ¤\n¤ ¤\n\n\u56e0\u4e3a\u7b2c\u56db\u884c\u4e0d\u5b8c\u6574\uff0c\u6240\u4ee5\u8fd4\u56de3.\n
    \n", "tags_en": ["Math", "Binary Search"], "tags_cn": ["\u6570\u5b66", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int arrangeCoins(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int arrangeCoins(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def arrangeCoins(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def arrangeCoins(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint arrangeCoins(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ArrangeCoins(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar arrangeCoins = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef arrange_coins(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func arrangeCoins(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func arrangeCoins(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def arrangeCoins(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun arrangeCoins(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn arrange_coins(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function arrangeCoins($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function arrangeCoins(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (arrange-coins n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0441](https://leetcode-cn.com/problems/arranging-coins)", "[\u6392\u5217\u786c\u5e01](/solution/0400-0499/0441.Arranging%20Coins/README.md)", "`\u6570\u5b66`,`\u4e8c\u5206\u67e5\u627e`", "\u7b80\u5355", ""], "md_table_row_en": ["[0441](https://leetcode.com/problems/arranging-coins)", "[Arranging Coins](/solution/0400-0499/0441.Arranging%20Coins/README_EN.md)", "`Math`,`Binary Search`", "Easy", ""]}, {"question_id": "0440", "frontend_question_id": "0440", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/k-th-smallest-in-lexicographical-order", "url_en": "https://leetcode.com/problems/k-th-smallest-in-lexicographical-order", "relative_path_cn": "/solution/0400-0499/0440.K-th%20Smallest%20in%20Lexicographical%20Order/README.md", "relative_path_en": "/solution/0400-0499/0440.K-th%20Smallest%20in%20Lexicographical%20Order/README_EN.md", "title_cn": "\u5b57\u5178\u5e8f\u7684\u7b2cK\u5c0f\u6570\u5b57", "title_en": "K-th Smallest in Lexicographical Order", "question_title_slug": "k-th-smallest-in-lexicographical-order", "content_en": "

    Given two integers n and k, return the kth lexicographically smallest integer in the range [1, n].

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 13, k = 2\nOutput: 10\nExplanation: The lexicographical order is [1, 10, 11, 12, 13, 2, 3, 4, 5, 6, 7, 8, 9], so the second smallest number is 10.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 1, k = 1\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= k <= n <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u6574\u6570 n \u548c k\uff0c\u627e\u5230 1 \u5230 n \u4e2d\u5b57\u5178\u5e8f\u7b2c k \u5c0f\u7684\u6570\u5b57\u3002

    \n\n

    \u6ce8\u610f\uff1a1 ≤ k ≤ n ≤ 109\u3002

    \n\n

    \u793a\u4f8b :

    \n\n
    \n\u8f93\u5165:\nn: 13   k: 2\n\n\u8f93\u51fa:\n10\n\n\u89e3\u91ca:\n\u5b57\u5178\u5e8f\u7684\u6392\u5217\u662f [1, 10, 11, 12, 13, 2, 3, 4, 5, 6, 7, 8, 9]\uff0c\u6240\u4ee5\u7b2c\u4e8c\u5c0f\u7684\u6570\u5b57\u662f 10\u3002\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findKthNumber(int n, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findKthNumber(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findKthNumber(self, n, k):\n \"\"\"\n :type n: int\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findKthNumber(self, n: int, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findKthNumber(int n, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindKthNumber(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} k\n * @return {number}\n */\nvar findKthNumber = function(n, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} k\n# @return {Integer}\ndef find_kth_number(n, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findKthNumber(_ n: Int, _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findKthNumber(n int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findKthNumber(n: Int, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findKthNumber(n: Int, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_kth_number(n: i32, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $k\n * @return Integer\n */\n function findKthNumber($n, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findKthNumber(n: number, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-kth-number n k)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0440](https://leetcode-cn.com/problems/k-th-smallest-in-lexicographical-order)", "[\u5b57\u5178\u5e8f\u7684\u7b2cK\u5c0f\u6570\u5b57](/solution/0400-0499/0440.K-th%20Smallest%20in%20Lexicographical%20Order/README.md)", "", "\u56f0\u96be", ""], "md_table_row_en": ["[0440](https://leetcode.com/problems/k-th-smallest-in-lexicographical-order)", "[K-th Smallest in Lexicographical Order](/solution/0400-0499/0440.K-th%20Smallest%20in%20Lexicographical%20Order/README_EN.md)", "", "Hard", ""]}, {"question_id": "0439", "frontend_question_id": "0439", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/ternary-expression-parser", "url_en": "https://leetcode.com/problems/ternary-expression-parser", "relative_path_cn": "/solution/0400-0499/0439.Ternary%20Expression%20Parser/README.md", "relative_path_en": "/solution/0400-0499/0439.Ternary%20Expression%20Parser/README_EN.md", "title_cn": "\u4e09\u5143\u8868\u8fbe\u5f0f\u89e3\u6790\u5668", "title_en": "Ternary Expression Parser", "question_title_slug": "ternary-expression-parser", "content_en": "

    Given a string expression representing arbitrarily nested ternary expressions, evaluate the expression, and return the result of it.

    \n\n

    You can always assume that the given expression is valid and only contains digits, '?', ':', 'T', and 'F' where 'T' is true and 'F' is false. All the numbers in the expression are one-digit numbers (i.e., in the range [0, 9]).

    \n\n

    The conditional expressions group right-to-left (as usual in most languages), and the result of the expression will always evaluate to either a digit, 'T' or 'F'.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: expression = "T?2:3"\nOutput: "2"\nExplanation: If true, then result is 2; otherwise result is 3.\n
    \n\n

    Example 2:

    \n\n
    \nInput: expression = "F?1:T?4:5"\nOutput: "4"\nExplanation: The conditional expressions group right-to-left. Using parenthesis, it is read/evaluated as:\n"(F ? 1 : (T ? 4 : 5))" --> "(F ? 1 : 4)" --> "4"\nor "(F ? 1 : (T ? 4 : 5))" --> "(T ? 4 : 5)" --> "4"\n
    \n\n

    Example 3:

    \n\n
    \nInput: expression = "T?T?F:5:3"\nOutput: "F"\nExplanation: The conditional expressions group right-to-left. Using parenthesis, it is read/evaluated as:\n"(T ? (T ? F : 5) : 3)" --> "(T ? F : 3)" --> "F"\n"(T ? (T ? F : 5) : 3)" --> "(T ? F : 5)" --> "F"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 5 <= expression.length <= 104
    • \n\t
    • expression consists of digits, 'T', 'F', '?', and ':'.
    • \n\t
    • It is guaranteed that expression is a valid ternary expression and that each number is a one-digit number.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4ee5\u5b57\u7b26\u4e32\u8868\u793a\u7684\u4efb\u610f\u5d4c\u5957\u7684\u4e09\u5143\u8868\u8fbe\u5f0f\uff0c\u8ba1\u7b97\u8868\u8fbe\u5f0f\u7684\u503c\u3002\u4f60\u53ef\u4ee5\u5047\u5b9a\u7ed9\u5b9a\u7684\u8868\u8fbe\u5f0f\u59cb\u7ec8\u90fd\u662f\u6709\u6548\u7684\u5e76\u4e14\u53ea\u5305\u542b\u6570\u5b57 0-9, ?, :, T \u548c F (T \u548c F \u5206\u522b\u8868\u793a\u771f\u548c\u5047\uff09\u3002

    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    1. \u7ed9\u5b9a\u7684\u5b57\u7b26\u4e32\u957f\u5ea6 ≤ 10000\u3002
    2. \n\t
    3. \u6240\u5305\u542b\u7684\u6570\u5b57\u90fd\u53ea\u6709\u4e00\u4f4d\u6570\u3002
    4. \n\t
    5. \u6761\u4ef6\u8868\u8fbe\u5f0f\u4ece\u53f3\u81f3\u5de6\u7ed3\u5408\uff08\u548c\u5927\u591a\u6570\u7a0b\u5e8f\u8bbe\u8ba1\u8bed\u8a00\u7c7b\u4f3c\uff09\u3002
    6. \n\t
    7. \u6761\u4ef6\u662f T \u548c F\u5176\u4e00\uff0c\u5373\u6761\u4ef6\u6c38\u8fdc\u4e0d\u4f1a\u662f\u6570\u5b57\u3002
    8. \n\t
    9. \u8868\u8fbe\u5f0f\u7684\u7ed3\u679c\u662f\u6570\u5b57 0-9, T \u6216\u8005 F\u3002
    10. \n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a "T?2:3"\n\n\u8f93\u51fa\uff1a "2"\n\n\u89e3\u91ca\uff1a \u5982\u679c\u6761\u4ef6\u4e3a\u771f\uff0c\u7ed3\u679c\u4e3a 2\uff1b\u5426\u5219\uff0c\u7ed3\u679c\u4e3a 3\u3002\n
    \n\n

     

    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a "F?1:T?4:5"\n\n\u8f93\u51fa\uff1a "4"\n\n\u89e3\u91ca\uff1a \u6761\u4ef6\u8868\u8fbe\u5f0f\u81ea\u53f3\u5411\u5de6\u7ed3\u5408\u3002\u4f7f\u7528\u62ec\u53f7\u7684\u8bdd\uff0c\u76f8\u5f53\u4e8e\uff1a\n\n             "(F ? 1 : (T ? 4 : 5))"                   "(F ? 1 : (T ? 4 : 5))"\n          -> "(F ? 1 : 4)"                 \u6216\u8005     -> "(T ? 4 : 5)"\n          -> "4"                                    -> "4"\n
    \n\n

     

    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1a "T?T?F:5:3"\n\n\u8f93\u51fa\uff1a "F"\n\n\u89e3\u91ca\uff1a \u6761\u4ef6\u8868\u8fbe\u5f0f\u81ea\u53f3\u5411\u5de6\u7ed3\u5408\u3002\u4f7f\u7528\u62ec\u53f7\u7684\u8bdd\uff0c\u76f8\u5f53\u4e8e\uff1a\n\n             "(T ? (T ? F : 5) : 3)"                   "(T ? (T ? F : 5) : 3)"\n          -> "(T ? F : 3)"                 \u6216\u8005       -> "(T ? F : 5)"\n          -> "F"                                     -> "F"\n
    \n\n

     

    \n", "tags_en": ["Stack", "Depth-first Search"], "tags_cn": ["\u6808", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string parseTernary(string expression) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String parseTernary(String expression) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def parseTernary(self, expression):\n \"\"\"\n :type expression: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def parseTernary(self, expression: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * parseTernary(char * expression){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ParseTernary(string expression) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} expression\n * @return {string}\n */\nvar parseTernary = function(expression) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} expression\n# @return {String}\ndef parse_ternary(expression)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func parseTernary(_ expression: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func parseTernary(expression string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def parseTernary(expression: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun parseTernary(expression: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn parse_ternary(expression: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $expression\n * @return String\n */\n function parseTernary($expression) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function parseTernary(expression: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (parse-ternary expression)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0439](https://leetcode-cn.com/problems/ternary-expression-parser)", "[\u4e09\u5143\u8868\u8fbe\u5f0f\u89e3\u6790\u5668](/solution/0400-0499/0439.Ternary%20Expression%20Parser/README.md)", "`\u6808`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0439](https://leetcode.com/problems/ternary-expression-parser)", "[Ternary Expression Parser](/solution/0400-0499/0439.Ternary%20Expression%20Parser/README_EN.md)", "`Stack`,`Depth-first Search`", "Medium", "\ud83d\udd12"]}, {"question_id": "0438", "frontend_question_id": "0438", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-all-anagrams-in-a-string", "url_en": "https://leetcode.com/problems/find-all-anagrams-in-a-string", "relative_path_cn": "/solution/0400-0499/0438.Find%20All%20Anagrams%20in%20a%20String/README.md", "relative_path_en": "/solution/0400-0499/0438.Find%20All%20Anagrams%20in%20a%20String/README_EN.md", "title_cn": "\u627e\u5230\u5b57\u7b26\u4e32\u4e2d\u6240\u6709\u5b57\u6bcd\u5f02\u4f4d\u8bcd", "title_en": "Find All Anagrams in a String", "question_title_slug": "find-all-anagrams-in-a-string", "content_en": "

    Given two strings s and p, return an array of all the start indices of p's anagrams in s. You may return the answer in any order.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "cbaebabacd", p = "abc"\nOutput: [0,6]\nExplanation:\nThe substring with start index = 0 is "cba", which is an anagram of "abc".\nThe substring with start index = 6 is "bac", which is an anagram of "abc".\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "abab", p = "ab"\nOutput: [0,1,2]\nExplanation:\nThe substring with start index = 0 is "ab", which is an anagram of "ab".\nThe substring with start index = 1 is "ba", which is an anagram of "ab".\nThe substring with start index = 2 is "ab", which is an anagram of "ab".\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length, p.length <= 3 * 104
    • \n\t
    • s and p consist of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32 \u548c\u4e00\u4e2a\u975e\u7a7a\u5b57\u7b26\u4e32 p\uff0c\u627e\u5230 \u4e2d\u6240\u6709\u662f \u7684\u5b57\u6bcd\u5f02\u4f4d\u8bcd\u7684\u5b50\u4e32\uff0c\u8fd4\u56de\u8fd9\u4e9b\u5b50\u4e32\u7684\u8d77\u59cb\u7d22\u5f15\u3002

    \n\n

    \u5b57\u7b26\u4e32\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\uff0c\u5e76\u4e14\u5b57\u7b26\u4e32 \u548c \u7684\u957f\u5ea6\u90fd\u4e0d\u8d85\u8fc7 20100\u3002

    \n\n

    \u8bf4\u660e\uff1a

    \n\n
      \n\t
    • \u5b57\u6bcd\u5f02\u4f4d\u8bcd\u6307\u5b57\u6bcd\u76f8\u540c\uff0c\u4f46\u6392\u5217\u4e0d\u540c\u7684\u5b57\u7b26\u4e32\u3002
    • \n\t
    • \u4e0d\u8003\u8651\u7b54\u6848\u8f93\u51fa\u7684\u987a\u5e8f\u3002
    • \n
    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165:\ns: "cbaebabacd" p: "abc"\n\n\u8f93\u51fa:\n[0, 6]\n\n\u89e3\u91ca:\n\u8d77\u59cb\u7d22\u5f15\u7b49\u4e8e 0 \u7684\u5b50\u4e32\u662f "cba", \u5b83\u662f "abc" \u7684\u5b57\u6bcd\u5f02\u4f4d\u8bcd\u3002\n\u8d77\u59cb\u7d22\u5f15\u7b49\u4e8e 6 \u7684\u5b50\u4e32\u662f "bac", \u5b83\u662f "abc" \u7684\u5b57\u6bcd\u5f02\u4f4d\u8bcd\u3002\n
    \n\n

     \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165:\ns: "abab" p: "ab"\n\n\u8f93\u51fa:\n[0, 1, 2]\n\n\u89e3\u91ca:\n\u8d77\u59cb\u7d22\u5f15\u7b49\u4e8e 0 \u7684\u5b50\u4e32\u662f "ab", \u5b83\u662f "ab" \u7684\u5b57\u6bcd\u5f02\u4f4d\u8bcd\u3002\n\u8d77\u59cb\u7d22\u5f15\u7b49\u4e8e 1 \u7684\u5b50\u4e32\u662f "ba", \u5b83\u662f "ab" \u7684\u5b57\u6bcd\u5f02\u4f4d\u8bcd\u3002\n\u8d77\u59cb\u7d22\u5f15\u7b49\u4e8e 2 \u7684\u5b50\u4e32\u662f "ab", \u5b83\u662f "ab" \u7684\u5b57\u6bcd\u5f02\u4f4d\u8bcd\u3002\n
    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findAnagrams(string s, string p) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List findAnagrams(String s, String p) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findAnagrams(self, s, p):\n \"\"\"\n :type s: str\n :type p: str\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findAnagrams(self, s: str, p: str) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* findAnagrams(char * s, char * p, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList FindAnagrams(string s, string p) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string} p\n * @return {number[]}\n */\nvar findAnagrams = function(s, p) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String} p\n# @return {Integer[]}\ndef find_anagrams(s, p)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findAnagrams(_ s: String, _ p: String) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findAnagrams(s string, p string) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findAnagrams(s: String, p: String): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findAnagrams(s: String, p: String): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_anagrams(s: String, p: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String $p\n * @return Integer[]\n */\n function findAnagrams($s, $p) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findAnagrams(s: string, p: string): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-anagrams s p)\n (-> string? string? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0438](https://leetcode-cn.com/problems/find-all-anagrams-in-a-string)", "[\u627e\u5230\u5b57\u7b26\u4e32\u4e2d\u6240\u6709\u5b57\u6bcd\u5f02\u4f4d\u8bcd](/solution/0400-0499/0438.Find%20All%20Anagrams%20in%20a%20String/README.md)", "`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0438](https://leetcode.com/problems/find-all-anagrams-in-a-string)", "[Find All Anagrams in a String](/solution/0400-0499/0438.Find%20All%20Anagrams%20in%20a%20String/README_EN.md)", "`Hash Table`", "Medium", ""]}, {"question_id": "0437", "frontend_question_id": "0437", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/path-sum-iii", "url_en": "https://leetcode.com/problems/path-sum-iii", "relative_path_cn": "/solution/0400-0499/0437.Path%20Sum%20III/README.md", "relative_path_en": "/solution/0400-0499/0437.Path%20Sum%20III/README_EN.md", "title_cn": "\u8def\u5f84\u603b\u548c III", "title_en": "Path Sum III", "question_title_slug": "path-sum-iii", "content_en": "

    Given the root of a binary tree and an integer targetSum, return the number of paths where the sum of the values along the path equals targetSum.

    \n\n

    The path does not need to start or end at the root or a leaf, but it must go downwards (i.e., traveling only from parent nodes to child nodes).

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [10,5,-3,3,2,null,11,3,-2,null,1], targetSum = 8\nOutput: 3\nExplanation: The paths that sum to 8 are shown.\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = [5,4,8,11,null,13,4,7,2,null,null,5,1], targetSum = 22\nOutput: 3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [0, 1000].
    • \n\t
    • -109 <= Node.val <= 109
    • \n\t
    • -1000 <= targetSum <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811\uff0c\u5b83\u7684\u6bcf\u4e2a\u7ed3\u70b9\u90fd\u5b58\u653e\u7740\u4e00\u4e2a\u6574\u6570\u503c\u3002

    \n\n

    \u627e\u51fa\u8def\u5f84\u548c\u7b49\u4e8e\u7ed9\u5b9a\u6570\u503c\u7684\u8def\u5f84\u603b\u6570\u3002

    \n\n

    \u8def\u5f84\u4e0d\u9700\u8981\u4ece\u6839\u8282\u70b9\u5f00\u59cb\uff0c\u4e5f\u4e0d\u9700\u8981\u5728\u53f6\u5b50\u8282\u70b9\u7ed3\u675f\uff0c\u4f46\u662f\u8def\u5f84\u65b9\u5411\u5fc5\u987b\u662f\u5411\u4e0b\u7684\uff08\u53ea\u80fd\u4ece\u7236\u8282\u70b9\u5230\u5b50\u8282\u70b9\uff09\u3002

    \n\n

    \u4e8c\u53c9\u6811\u4e0d\u8d85\u8fc71000\u4e2a\u8282\u70b9\uff0c\u4e14\u8282\u70b9\u6570\u503c\u8303\u56f4\u662f [-1000000,1000000] \u7684\u6574\u6570\u3002

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    root = [10,5,-3,3,2,null,11,3,-2,null,1], sum = 8\n\n      10\n     /  \\\n    5   -3\n   / \\    \\\n  3   2   11\n / \\   \\\n3  -2   1\n\n\u8fd4\u56de 3\u3002\u548c\u7b49\u4e8e 8 \u7684\u8def\u5f84\u6709:\n\n1.  5 -> 3\n2.  5 -> 2 -> 1\n3.  -3 -> 11\n
    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int pathSum(TreeNode* root, int targetSum) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int pathSum(TreeNode root, int targetSum) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def pathSum(self, root, targetSum):\n \"\"\"\n :type root: TreeNode\n :type targetSum: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def pathSum(self, root: TreeNode, targetSum: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint pathSum(struct TreeNode* root, int targetSum){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int PathSum(TreeNode root, int targetSum) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number} targetSum\n * @return {number}\n */\nvar pathSum = function(root, targetSum) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @param {Integer} target_sum\n# @return {Integer}\ndef path_sum(root, target_sum)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func pathSum(_ root: TreeNode?, _ targetSum: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc pathSum(root *TreeNode, targetSum int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def pathSum(root: TreeNode, targetSum: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun pathSum(root: TreeNode?, targetSum: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn path_sum(root: Option>>, target_sum: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param Integer $targetSum\n * @return Integer\n */\n function pathSum($root, $targetSum) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction pathSum(root: TreeNode | null, targetSum: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (path-sum root targetSum)\n (-> (or/c tree-node? #f) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0437](https://leetcode-cn.com/problems/path-sum-iii)", "[\u8def\u5f84\u603b\u548c III](/solution/0400-0499/0437.Path%20Sum%20III/README.md)", "`\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0437](https://leetcode.com/problems/path-sum-iii)", "[Path Sum III](/solution/0400-0499/0437.Path%20Sum%20III/README_EN.md)", "`Tree`", "Medium", ""]}, {"question_id": "0436", "frontend_question_id": "0436", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-right-interval", "url_en": "https://leetcode.com/problems/find-right-interval", "relative_path_cn": "/solution/0400-0499/0436.Find%20Right%20Interval/README.md", "relative_path_en": "/solution/0400-0499/0436.Find%20Right%20Interval/README_EN.md", "title_cn": "\u5bfb\u627e\u53f3\u533a\u95f4", "title_en": "Find Right Interval", "question_title_slug": "find-right-interval", "content_en": "

    You are given an array of intervals, where intervals[i] = [starti, endi] and each starti is unique.

    \n\n

    The right interval for an interval i is an interval j such that startj >= endi and startj is minimized.

    \n\n

    Return an array of right interval indices for each interval i. If no right interval exists for interval i, then put -1 at index i.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: intervals = [[1,2]]\nOutput: [-1]\nExplanation: There is only one interval in the collection, so it outputs -1.\n
    \n\n

    Example 2:

    \n\n
    \nInput: intervals = [[3,4],[2,3],[1,2]]\nOutput: [-1,0,1]\nExplanation: There is no right interval for [3,4].\nThe right interval for [2,3] is [3,4] since start0 = 3 is the smallest start that is >= end1 = 3.\nThe right interval for [1,2] is [2,3] since start1 = 2 is the smallest start that is >= end2 = 2.\n
    \n\n

    Example 3:

    \n\n
    \nInput: intervals = [[1,4],[2,3],[3,4]]\nOutput: [-1,2,-1]\nExplanation: There is no right interval for [1,4] and [3,4].\nThe right interval for [2,3] is [3,4] since start2 = 3 is the smallest start that is >= end1 = 3.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= intervals.length <= 2 * 104
    • \n\t
    • intervals[i].length == 2
    • \n\t
    • -106 <= starti <= endi <= 106
    • \n\t
    • The start point of each interval is unique.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u533a\u95f4\u6570\u7ec4 intervals \uff0c\u5176\u4e2d\u00a0intervals[i] = [starti, endi] \uff0c\u4e14\u6bcf\u4e2a\u00a0starti \u90fd \u4e0d\u540c \u3002

    \n\n

    \u533a\u95f4 i \u7684 \u53f3\u4fa7\u533a\u95f4 \u53ef\u4ee5\u8bb0\u4f5c\u533a\u95f4 j \uff0c\u5e76\u6ee1\u8db3 startj\u00a0>= endi \uff0c\u4e14 startj \u6700\u5c0f\u5316 \u3002

    \n\n

    \u8fd4\u56de\u4e00\u4e2a\u7531\u6bcf\u4e2a\u533a\u95f4 i \u7684 \u53f3\u4fa7\u533a\u95f4 \u7684\u6700\u5c0f\u8d77\u59cb\u4f4d\u7f6e\u7ec4\u6210\u7684\u6570\u7ec4\u3002\u5982\u679c\u67d0\u4e2a\u533a\u95f4 i \u4e0d\u5b58\u5728\u5bf9\u5e94\u7684 \u53f3\u4fa7\u533a\u95f4 \uff0c\u5219\u4e0b\u6807 i \u5904\u7684\u503c\u8bbe\u4e3a -1 \u3002

    \n\u00a0\n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aintervals = [[1,2]]\n\u8f93\u51fa\uff1a[-1]\n\u89e3\u91ca\uff1a\u96c6\u5408\u4e2d\u53ea\u6709\u4e00\u4e2a\u533a\u95f4\uff0c\u6240\u4ee5\u8f93\u51fa-1\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aintervals = [[3,4],[2,3],[1,2]]\n\u8f93\u51fa\uff1a[-1, 0, 1]\n\u89e3\u91ca\uff1a\u5bf9\u4e8e [3,4] \uff0c\u6ca1\u6709\u6ee1\u8db3\u6761\u4ef6\u7684\u201c\u53f3\u4fa7\u201d\u533a\u95f4\u3002\n\u5bf9\u4e8e [2,3] \uff0c\u533a\u95f4[3,4]\u5177\u6709\u6700\u5c0f\u7684\u201c\u53f3\u201d\u8d77\u70b9;\n\u5bf9\u4e8e [1,2] \uff0c\u533a\u95f4[2,3]\u5177\u6709\u6700\u5c0f\u7684\u201c\u53f3\u201d\u8d77\u70b9\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aintervals = [[1,4],[2,3],[3,4]]\n\u8f93\u51fa\uff1a[-1, 2, -1]\n\u89e3\u91ca\uff1a\u5bf9\u4e8e\u533a\u95f4 [1,4] \u548c [3,4] \uff0c\u6ca1\u6709\u6ee1\u8db3\u6761\u4ef6\u7684\u201c\u53f3\u4fa7\u201d\u533a\u95f4\u3002\n\u5bf9\u4e8e [2,3] \uff0c\u533a\u95f4 [3,4] \u6709\u6700\u5c0f\u7684\u201c\u53f3\u201d\u8d77\u70b9\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <=\u00a0intervals.length <= 2 * 104
    • \n\t
    • intervals[i].length == 2
    • \n\t
    • -106 <= starti <= endi <= 106
    • \n\t
    • \u6bcf\u4e2a\u95f4\u9694\u7684\u8d77\u70b9\u90fd \u4e0d\u76f8\u540c
    • \n
    \n", "tags_en": ["Binary Search"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findRightInterval(vector>& intervals) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] findRightInterval(int[][] intervals) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findRightInterval(self, intervals):\n \"\"\"\n :type intervals: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findRightInterval(self, intervals: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* findRightInterval(int** intervals, int intervalsSize, int* intervalsColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] FindRightInterval(int[][] intervals) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} intervals\n * @return {number[]}\n */\nvar findRightInterval = function(intervals) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} intervals\n# @return {Integer[]}\ndef find_right_interval(intervals)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findRightInterval(_ intervals: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findRightInterval(intervals [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findRightInterval(intervals: Array[Array[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findRightInterval(intervals: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_right_interval(intervals: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $intervals\n * @return Integer[]\n */\n function findRightInterval($intervals) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findRightInterval(intervals: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-right-interval intervals)\n (-> (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0436](https://leetcode-cn.com/problems/find-right-interval)", "[\u5bfb\u627e\u53f3\u533a\u95f4](/solution/0400-0499/0436.Find%20Right%20Interval/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0436](https://leetcode.com/problems/find-right-interval)", "[Find Right Interval](/solution/0400-0499/0436.Find%20Right%20Interval/README_EN.md)", "`Binary Search`", "Medium", ""]}, {"question_id": "0435", "frontend_question_id": "0435", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/non-overlapping-intervals", "url_en": "https://leetcode.com/problems/non-overlapping-intervals", "relative_path_cn": "/solution/0400-0499/0435.Non-overlapping%20Intervals/README.md", "relative_path_en": "/solution/0400-0499/0435.Non-overlapping%20Intervals/README_EN.md", "title_cn": "\u65e0\u91cd\u53e0\u533a\u95f4", "title_en": "Non-overlapping Intervals", "question_title_slug": "non-overlapping-intervals", "content_en": "

    Given an array of intervals intervals where intervals[i] = [starti, endi], return the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: intervals = [[1,2],[2,3],[3,4],[1,3]]\nOutput: 1\nExplanation: [1,3] can be removed and the rest of the intervals are non-overlapping.\n
    \n\n

    Example 2:

    \n\n
    \nInput: intervals = [[1,2],[1,2],[1,2]]\nOutput: 2\nExplanation: You need to remove two [1,2] to make the rest of the intervals non-overlapping.\n
    \n\n

    Example 3:

    \n\n
    \nInput: intervals = [[1,2],[2,3]]\nOutput: 0\nExplanation: You don't need to remove any of the intervals since they're already non-overlapping.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= intervals.length <= 2 * 104
    • \n\t
    • intervals[i].length == 2
    • \n\t
    • -2 * 104 <= starti < endi <= 2 * 104
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u533a\u95f4\u7684\u96c6\u5408\uff0c\u627e\u5230\u9700\u8981\u79fb\u9664\u533a\u95f4\u7684\u6700\u5c0f\u6570\u91cf\uff0c\u4f7f\u5269\u4f59\u533a\u95f4\u4e92\u4e0d\u91cd\u53e0\u3002

    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u53ef\u4ee5\u8ba4\u4e3a\u533a\u95f4\u7684\u7ec8\u70b9\u603b\u662f\u5927\u4e8e\u5b83\u7684\u8d77\u70b9\u3002
    2. \n\t
    3. \u533a\u95f4 [1,2] \u548c [2,3] \u7684\u8fb9\u754c\u76f8\u4e92“\u63a5\u89e6”\uff0c\u4f46\u6ca1\u6709\u76f8\u4e92\u91cd\u53e0\u3002
    4. \n
    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: [ [1,2], [2,3], [3,4], [1,3] ]\n\n\u8f93\u51fa: 1\n\n\u89e3\u91ca: \u79fb\u9664 [1,3] \u540e\uff0c\u5269\u4e0b\u7684\u533a\u95f4\u6ca1\u6709\u91cd\u53e0\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: [ [1,2], [1,2], [1,2] ]\n\n\u8f93\u51fa: 2\n\n\u89e3\u91ca: \u4f60\u9700\u8981\u79fb\u9664\u4e24\u4e2a [1,2] \u6765\u4f7f\u5269\u4e0b\u7684\u533a\u95f4\u6ca1\u6709\u91cd\u53e0\u3002\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \n\u8f93\u5165: [ [1,2], [2,3] ]\n\n\u8f93\u51fa: 0\n\n\u89e3\u91ca: \u4f60\u4e0d\u9700\u8981\u79fb\u9664\u4efb\u4f55\u533a\u95f4\uff0c\u56e0\u4e3a\u5b83\u4eec\u5df2\u7ecf\u662f\u65e0\u91cd\u53e0\u7684\u4e86\u3002\n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int eraseOverlapIntervals(vector>& intervals) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int eraseOverlapIntervals(int[][] intervals) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def eraseOverlapIntervals(self, intervals):\n \"\"\"\n :type intervals: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def eraseOverlapIntervals(self, intervals: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint eraseOverlapIntervals(int** intervals, int intervalsSize, int* intervalsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int EraseOverlapIntervals(int[][] intervals) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} intervals\n * @return {number}\n */\nvar eraseOverlapIntervals = function(intervals) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} intervals\n# @return {Integer}\ndef erase_overlap_intervals(intervals)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func eraseOverlapIntervals(_ intervals: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func eraseOverlapIntervals(intervals [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def eraseOverlapIntervals(intervals: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun eraseOverlapIntervals(intervals: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn erase_overlap_intervals(intervals: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $intervals\n * @return Integer\n */\n function eraseOverlapIntervals($intervals) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function eraseOverlapIntervals(intervals: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (erase-overlap-intervals intervals)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0435](https://leetcode-cn.com/problems/non-overlapping-intervals)", "[\u65e0\u91cd\u53e0\u533a\u95f4](/solution/0400-0499/0435.Non-overlapping%20Intervals/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0435](https://leetcode.com/problems/non-overlapping-intervals)", "[Non-overlapping Intervals](/solution/0400-0499/0435.Non-overlapping%20Intervals/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "0434", "frontend_question_id": "0434", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-segments-in-a-string", "url_en": "https://leetcode.com/problems/number-of-segments-in-a-string", "relative_path_cn": "/solution/0400-0499/0434.Number%20of%20Segments%20in%20a%20String/README.md", "relative_path_en": "/solution/0400-0499/0434.Number%20of%20Segments%20in%20a%20String/README_EN.md", "title_cn": "\u5b57\u7b26\u4e32\u4e2d\u7684\u5355\u8bcd\u6570", "title_en": "Number of Segments in a String", "question_title_slug": "number-of-segments-in-a-string", "content_en": "

    You are given a string s, return the number of segments in the string

    \n\n

    A segment is defined to be a contiguous sequence of non-space characters.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "Hello, my name is John"\nOutput: 5\nExplanation: The five segments are ["Hello,", "my", "name", "is", "John"]\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "Hello"\nOutput: 1\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "love live! mu'sic forever"\nOutput: 4\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = ""\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= s.length <= 300
    • \n\t
    • s consists of lower-case and upper-case English letters, digits or one of the following characters "!@#$%^&*()_+-=',.:".
    • \n\t
    • The only space character in s is ' '.
    • \n
    \n", "content_cn": "

    \u7edf\u8ba1\u5b57\u7b26\u4e32\u4e2d\u7684\u5355\u8bcd\u4e2a\u6570\uff0c\u8fd9\u91cc\u7684\u5355\u8bcd\u6307\u7684\u662f\u8fde\u7eed\u7684\u4e0d\u662f\u7a7a\u683c\u7684\u5b57\u7b26\u3002

    \n\n

    \u8bf7\u6ce8\u610f\uff0c\u4f60\u53ef\u4ee5\u5047\u5b9a\u5b57\u7b26\u4e32\u91cc\u4e0d\u5305\u62ec\u4efb\u4f55\u4e0d\u53ef\u6253\u5370\u7684\u5b57\u7b26\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: "Hello, my name is John"\n\u8f93\u51fa: 5\n\u89e3\u91ca: \u8fd9\u91cc\u7684\u5355\u8bcd\u662f\u6307\u8fde\u7eed\u7684\u4e0d\u662f\u7a7a\u683c\u7684\u5b57\u7b26\uff0c\u6240\u4ee5 "Hello," \u7b97\u4f5c 1 \u4e2a\u5355\u8bcd\u3002\n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countSegments(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countSegments(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countSegments(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countSegments(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countSegments(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountSegments(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar countSegments = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef count_segments(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countSegments(_ s: String) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countSegments(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countSegments(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countSegments(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_segments(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function countSegments($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countSegments(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-segments s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0434](https://leetcode-cn.com/problems/number-of-segments-in-a-string)", "[\u5b57\u7b26\u4e32\u4e2d\u7684\u5355\u8bcd\u6570](/solution/0400-0499/0434.Number%20of%20Segments%20in%20a%20String/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0434](https://leetcode.com/problems/number-of-segments-in-a-string)", "[Number of Segments in a String](/solution/0400-0499/0434.Number%20of%20Segments%20in%20a%20String/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "0433", "frontend_question_id": "0433", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-genetic-mutation", "url_en": "https://leetcode.com/problems/minimum-genetic-mutation", "relative_path_cn": "/solution/0400-0499/0433.Minimum%20Genetic%20Mutation/README.md", "relative_path_en": "/solution/0400-0499/0433.Minimum%20Genetic%20Mutation/README_EN.md", "title_cn": "\u6700\u5c0f\u57fa\u56e0\u53d8\u5316", "title_en": "Minimum Genetic Mutation", "question_title_slug": "minimum-genetic-mutation", "content_en": "

    A gene string can be represented by an 8-character long string, with choices from 'A', 'C', 'G', and 'T'.

    \n\n

    Suppose we need to investigate a mutation from a gene string start to a gene string end where one mutation is defined as one single character changed in the gene string.

    \n\n
      \n\t
    • For example, "AACCGGTT" --> "AACCGGTA" is one mutation.
    • \n
    \n\n

    There is also a gene bank bank that records all the valid gene mutations. A gene must be in bank to make it a valid gene string.

    \n\n

    Given the two gene strings start and end and the gene bank bank, return the minimum number of mutations needed to mutate from start to end. If there is no such a mutation, return -1.

    \n\n

    Note that the starting point is assumed to be valid, so it might not be included in the bank.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: start = "AACCGGTT", end = "AACCGGTA", bank = ["AACCGGTA"]\nOutput: 1\n
    \n\n

    Example 2:

    \n\n
    \nInput: start = "AACCGGTT", end = "AAACGGTA", bank = ["AACCGGTA","AACCGCTA","AAACGGTA"]\nOutput: 2\n
    \n\n

    Example 3:

    \n\n
    \nInput: start = "AAAAACCC", end = "AACCCCCC", bank = ["AAAACCCC","AAACCCCC","AACCCCCC"]\nOutput: 3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • start.length == 8
    • \n\t
    • end.length == 8
    • \n\t
    • 0 <= bank.length <= 10
    • \n\t
    • bank[i].length == 8
    • \n\t
    • start, end, and bank[i] consist of only the characters ['A', 'C', 'G', 'T'].
    • \n
    \n", "content_cn": "

    \u4e00\u6761\u57fa\u56e0\u5e8f\u5217\u7531\u4e00\u4e2a\u5e26\u67098\u4e2a\u5b57\u7b26\u7684\u5b57\u7b26\u4e32\u8868\u793a\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5b57\u7b26\u90fd\u5c5e\u4e8e \"A\", \"C\", \"G\", \"T\"\u4e2d\u7684\u4efb\u610f\u4e00\u4e2a\u3002

    \n\n

    \u5047\u8bbe\u6211\u4eec\u8981\u8c03\u67e5\u4e00\u4e2a\u57fa\u56e0\u5e8f\u5217\u7684\u53d8\u5316\u3002\u4e00\u6b21\u57fa\u56e0\u53d8\u5316\u610f\u5473\u7740\u8fd9\u4e2a\u57fa\u56e0\u5e8f\u5217\u4e2d\u7684\u4e00\u4e2a\u5b57\u7b26\u53d1\u751f\u4e86\u53d8\u5316\u3002

    \n\n

    \u4f8b\u5982\uff0c\u57fa\u56e0\u5e8f\u5217\u7531\"AACCGGTT\"\u00a0\u53d8\u5316\u81f3\u00a0\"AACCGGTA\"\u00a0\u5373\u53d1\u751f\u4e86\u4e00\u6b21\u57fa\u56e0\u53d8\u5316\u3002

    \n\n

    \u4e0e\u6b64\u540c\u65f6\uff0c\u6bcf\u4e00\u6b21\u57fa\u56e0\u53d8\u5316\u7684\u7ed3\u679c\uff0c\u90fd\u9700\u8981\u662f\u4e00\u4e2a\u5408\u6cd5\u7684\u57fa\u56e0\u4e32\uff0c\u5373\u8be5\u7ed3\u679c\u5c5e\u4e8e\u4e00\u4e2a\u57fa\u56e0\u5e93\u3002

    \n\n

    \u73b0\u5728\u7ed9\u5b9a3\u4e2a\u53c2\u6570 \u2014 start, end, bank\uff0c\u5206\u522b\u4ee3\u8868\u8d77\u59cb\u57fa\u56e0\u5e8f\u5217\uff0c\u76ee\u6807\u57fa\u56e0\u5e8f\u5217\u53ca\u57fa\u56e0\u5e93\uff0c\u8bf7\u627e\u51fa\u80fd\u591f\u4f7f\u8d77\u59cb\u57fa\u56e0\u5e8f\u5217\u53d8\u5316\u4e3a\u76ee\u6807\u57fa\u56e0\u5e8f\u5217\u6240\u9700\u7684\u6700\u5c11\u53d8\u5316\u6b21\u6570\u3002\u5982\u679c\u65e0\u6cd5\u5b9e\u73b0\u76ee\u6807\u53d8\u5316\uff0c\u8bf7\u8fd4\u56de -1\u3002

    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    1. \u8d77\u59cb\u57fa\u56e0\u5e8f\u5217\u9ed8\u8ba4\u662f\u5408\u6cd5\u7684\uff0c\u4f46\u662f\u5b83\u5e76\u4e0d\u4e00\u5b9a\u4f1a\u51fa\u73b0\u5728\u57fa\u56e0\u5e93\u4e2d\u3002
    2. \n\t
    3. \u5982\u679c\u4e00\u4e2a\u8d77\u59cb\u57fa\u56e0\u5e8f\u5217\u9700\u8981\u591a\u6b21\u53d8\u5316\uff0c\u90a3\u4e48\u5b83\u6bcf\u4e00\u6b21\u53d8\u5316\u4e4b\u540e\u7684\u57fa\u56e0\u5e8f\u5217\u90fd\u5fc5\u987b\u662f\u5408\u6cd5\u7684\u3002
    4. \n\t
    5. \u5047\u5b9a\u8d77\u59cb\u57fa\u56e0\u5e8f\u5217\u4e0e\u76ee\u6807\u57fa\u56e0\u5e8f\u5217\u662f\u4e0d\u4e00\u6837\u7684\u3002
    6. \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \nstart: \"AACCGGTT\"\nend:   \"AACCGGTA\"\nbank: [\"AACCGGTA\"]\n\n\u8fd4\u56de\u503c: 1\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \nstart: \"AACCGGTT\"\nend:   \"AAACGGTA\"\nbank: [\"AACCGGTA\", \"AACCGCTA\", \"AAACGGTA\"]\n\n\u8fd4\u56de\u503c: 2\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \nstart: \"AAAAACCC\"\nend:   \"AACCCCCC\"\nbank: [\"AAAACCCC\", \"AAACCCCC\", \"AACCCCCC\"]\n\n\u8fd4\u56de\u503c: 3\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minMutation(string start, string end, vector& bank) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minMutation(String start, String end, String[] bank) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minMutation(self, start, end, bank):\n \"\"\"\n :type start: str\n :type end: str\n :type bank: List[str]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minMutation(self, start: str, end: str, bank: List[str]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minMutation(char * start, char * end, char ** bank, int bankSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinMutation(string start, string end, string[] bank) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} start\n * @param {string} end\n * @param {string[]} bank\n * @return {number}\n */\nvar minMutation = function(start, end, bank) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} start\n# @param {String} end\n# @param {String[]} bank\n# @return {Integer}\ndef min_mutation(start, end, bank)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minMutation(_ start: String, _ end: String, _ bank: [String]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minMutation(start string, end string, bank []string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minMutation(start: String, end: String, bank: Array[String]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minMutation(start: String, end: String, bank: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_mutation(start: String, end: String, bank: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $start\n * @param String $end\n * @param String[] $bank\n * @return Integer\n */\n function minMutation($start, $end, $bank) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minMutation(start: string, end: string, bank: string[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-mutation start end bank)\n (-> string? string? (listof string?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0433](https://leetcode-cn.com/problems/minimum-genetic-mutation)", "[\u6700\u5c0f\u57fa\u56e0\u53d8\u5316](/solution/0400-0499/0433.Minimum%20Genetic%20Mutation/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0433](https://leetcode.com/problems/minimum-genetic-mutation)", "[Minimum Genetic Mutation](/solution/0400-0499/0433.Minimum%20Genetic%20Mutation/README_EN.md)", "", "Medium", ""]}, {"question_id": "0432", "frontend_question_id": "0432", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/all-oone-data-structure", "url_en": "https://leetcode.com/problems/all-oone-data-structure", "relative_path_cn": "/solution/0400-0499/0432.All%20O%60one%20Data%20Structure/README.md", "relative_path_en": "/solution/0400-0499/0432.All%20O%60one%20Data%20Structure/README_EN.md", "title_cn": "\u5168 O(1) \u7684\u6570\u636e\u7ed3\u6784", "title_en": "All O`one Data Structure", "question_title_slug": "all-oone-data-structure", "content_en": "

    Design a data structure to store the strings' count with the ability to return the strings with minimum and maximum counts.

    \n\n

    Implement the AllOne class:

    \n\n
      \n\t
    • AllOne() Initializes the object of the data structure.
    • \n\t
    • inc(String key) Increments the count of the string key by 1. If key does not exist in the data structure, insert it with count 1.
    • \n\t
    • dec(String key) Decrements the count of the string key by 1. If the count of key is 0 after the decrement, remove it from the data structure. It is guaranteed that key exists in the data structure before the decrement.
    • \n\t
    • getMaxKey() Returns one of the keys with the maximal count. If no element exists, return an empty string "".
    • \n\t
    • getMinKey() Returns one of the keys with the minimum count. If no element exists, return an empty string "".
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["AllOne", "inc", "inc", "getMaxKey", "getMinKey", "inc", "getMaxKey", "getMinKey"]\n[[], ["hello"], ["hello"], [], [], ["leet"], [], []]\nOutput\n[null, null, null, "hello", "hello", null, "hello", "leet"]\n\nExplanation\nAllOne allOne = new AllOne();\nallOne.inc("hello");\nallOne.inc("hello");\nallOne.getMaxKey(); // return "hello"\nallOne.getMinKey(); // return "hello"\nallOne.inc("leet");\nallOne.getMaxKey(); // return "hello"\nallOne.getMinKey(); // return "leet"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= key.length <= 10
    • \n\t
    • key consists of lowercase English letters.
    • \n\t
    • It is guaranteed that for each call to dec, key is existing in the data structure.
    • \n\t
    • At most 5 * 104 calls will be made to inc, dec, getMaxKey, and getMinKey.
    • \n
    \n", "content_cn": "

    \u8bf7\u4f60\u5b9e\u73b0\u4e00\u4e2a\u6570\u636e\u7ed3\u6784\u652f\u6301\u4ee5\u4e0b\u64cd\u4f5c\uff1a

    \n\n
      \n\t
    1. Inc(key) - \u63d2\u5165\u4e00\u4e2a\u65b0\u7684\u503c\u4e3a 1 \u7684 key\u3002\u6216\u8005\u4f7f\u4e00\u4e2a\u5b58\u5728\u7684 key \u589e\u52a0\u4e00\uff0c\u4fdd\u8bc1 key \u4e0d\u4e3a\u7a7a\u5b57\u7b26\u4e32\u3002
    2. \n\t
    3. Dec(key) - \u5982\u679c\u8fd9\u4e2a key \u7684\u503c\u662f 1\uff0c\u90a3\u4e48\u628a\u4ed6\u4ece\u6570\u636e\u7ed3\u6784\u4e2d\u79fb\u9664\u6389\u3002\u5426\u5219\u4f7f\u4e00\u4e2a\u5b58\u5728\u7684 key \u503c\u51cf\u4e00\u3002\u5982\u679c\u8fd9\u4e2a key \u4e0d\u5b58\u5728\uff0c\u8fd9\u4e2a\u51fd\u6570\u4e0d\u505a\u4efb\u4f55\u4e8b\u60c5\u3002key \u4fdd\u8bc1\u4e0d\u4e3a\u7a7a\u5b57\u7b26\u4e32\u3002
    4. \n\t
    5. GetMaxKey() - \u8fd4\u56de key \u4e2d\u503c\u6700\u5927\u7684\u4efb\u610f\u4e00\u4e2a\u3002\u5982\u679c\u6ca1\u6709\u5143\u7d20\u5b58\u5728\uff0c\u8fd4\u56de\u4e00\u4e2a\u7a7a\u5b57\u7b26\u4e32"" \u3002
    6. \n\t
    7. GetMinKey() - \u8fd4\u56de key \u4e2d\u503c\u6700\u5c0f\u7684\u4efb\u610f\u4e00\u4e2a\u3002\u5982\u679c\u6ca1\u6709\u5143\u7d20\u5b58\u5728\uff0c\u8fd4\u56de\u4e00\u4e2a\u7a7a\u5b57\u7b26\u4e32""\u3002
    8. \n
    \n\n

     

    \n\n

    \u6311\u6218\uff1a

    \n\n

    \u4f60\u80fd\u591f\u4ee5 O(1) \u7684\u65f6\u95f4\u590d\u6742\u5ea6\u5b9e\u73b0\u6240\u6709\u64cd\u4f5c\u5417\uff1f

    \n", "tags_en": ["Design"], "tags_cn": ["\u8bbe\u8ba1"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class AllOne {\npublic:\n /** Initialize your data structure here. */\n AllOne() {\n\n }\n \n /** Inserts a new key with value 1. Or increments an existing key by 1. */\n void inc(string key) {\n\n }\n \n /** Decrements an existing key by 1. If Key's value is 1, remove it from the data structure. */\n void dec(string key) {\n\n }\n \n /** Returns one of the keys with maximal value. */\n string getMaxKey() {\n\n }\n \n /** Returns one of the keys with Minimal value. */\n string getMinKey() {\n\n }\n};\n\n/**\n * Your AllOne object will be instantiated and called as such:\n * AllOne* obj = new AllOne();\n * obj->inc(key);\n * obj->dec(key);\n * string param_3 = obj->getMaxKey();\n * string param_4 = obj->getMinKey();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class AllOne {\n\n /** Initialize your data structure here. */\n public AllOne() {\n\n }\n \n /** Inserts a new key with value 1. Or increments an existing key by 1. */\n public void inc(String key) {\n\n }\n \n /** Decrements an existing key by 1. If Key's value is 1, remove it from the data structure. */\n public void dec(String key) {\n\n }\n \n /** Returns one of the keys with maximal value. */\n public String getMaxKey() {\n\n }\n \n /** Returns one of the keys with Minimal value. */\n public String getMinKey() {\n\n }\n}\n\n/**\n * Your AllOne object will be instantiated and called as such:\n * AllOne obj = new AllOne();\n * obj.inc(key);\n * obj.dec(key);\n * String param_3 = obj.getMaxKey();\n * String param_4 = obj.getMinKey();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class AllOne(object):\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def inc(self, key):\n \"\"\"\n Inserts a new key with value 1. Or increments an existing key by 1.\n :type key: str\n :rtype: None\n \"\"\"\n\n\n def dec(self, key):\n \"\"\"\n Decrements an existing key by 1. If Key's value is 1, remove it from the data structure.\n :type key: str\n :rtype: None\n \"\"\"\n\n\n def getMaxKey(self):\n \"\"\"\n Returns one of the keys with maximal value.\n :rtype: str\n \"\"\"\n\n\n def getMinKey(self):\n \"\"\"\n Returns one of the keys with Minimal value.\n :rtype: str\n \"\"\"\n\n\n\n# Your AllOne object will be instantiated and called as such:\n# obj = AllOne()\n# obj.inc(key)\n# obj.dec(key)\n# param_3 = obj.getMaxKey()\n# param_4 = obj.getMinKey()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class AllOne:\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def inc(self, key: str) -> None:\n \"\"\"\n Inserts a new key with value 1. Or increments an existing key by 1.\n \"\"\"\n\n\n def dec(self, key: str) -> None:\n \"\"\"\n Decrements an existing key by 1. If Key's value is 1, remove it from the data structure.\n \"\"\"\n\n\n def getMaxKey(self) -> str:\n \"\"\"\n Returns one of the keys with maximal value.\n \"\"\"\n\n\n def getMinKey(self) -> str:\n \"\"\"\n Returns one of the keys with Minimal value.\n \"\"\"\n\n\n\n# Your AllOne object will be instantiated and called as such:\n# obj = AllOne()\n# obj.inc(key)\n# obj.dec(key)\n# param_3 = obj.getMaxKey()\n# param_4 = obj.getMinKey()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} AllOne;\n\n/** Initialize your data structure here. */\n\nAllOne* allOneCreate() {\n \n}\n\n/** Inserts a new key with value 1. Or increments an existing key by 1. */\nvoid allOneInc(AllOne* obj, char * key) {\n \n}\n\n/** Decrements an existing key by 1. If Key's value is 1, remove it from the data structure. */\nvoid allOneDec(AllOne* obj, char * key) {\n \n}\n\n/** Returns one of the keys with maximal value. */\nchar * allOneGetMaxKey(AllOne* obj) {\n \n}\n\n/** Returns one of the keys with Minimal value. */\nchar * allOneGetMinKey(AllOne* obj) {\n \n}\n\nvoid allOneFree(AllOne* obj) {\n \n}\n\n/**\n * Your AllOne struct will be instantiated and called as such:\n * AllOne* obj = allOneCreate();\n * allOneInc(obj, key);\n \n * allOneDec(obj, key);\n \n * char * param_3 = allOneGetMaxKey(obj);\n \n * char * param_4 = allOneGetMinKey(obj);\n \n * allOneFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class AllOne {\n\n /** Initialize your data structure here. */\n public AllOne() {\n\n }\n \n /** Inserts a new key with value 1. Or increments an existing key by 1. */\n public void Inc(string key) {\n\n }\n \n /** Decrements an existing key by 1. If Key's value is 1, remove it from the data structure. */\n public void Dec(string key) {\n\n }\n \n /** Returns one of the keys with maximal value. */\n public string GetMaxKey() {\n\n }\n \n /** Returns one of the keys with Minimal value. */\n public string GetMinKey() {\n\n }\n}\n\n/**\n * Your AllOne object will be instantiated and called as such:\n * AllOne obj = new AllOne();\n * obj.Inc(key);\n * obj.Dec(key);\n * string param_3 = obj.GetMaxKey();\n * string param_4 = obj.GetMinKey();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Initialize your data structure here.\n */\nvar AllOne = function() {\n\n};\n\n/**\n * Inserts a new key with value 1. Or increments an existing key by 1. \n * @param {string} key\n * @return {void}\n */\nAllOne.prototype.inc = function(key) {\n\n};\n\n/**\n * Decrements an existing key by 1. If Key's value is 1, remove it from the data structure. \n * @param {string} key\n * @return {void}\n */\nAllOne.prototype.dec = function(key) {\n\n};\n\n/**\n * Returns one of the keys with maximal value.\n * @return {string}\n */\nAllOne.prototype.getMaxKey = function() {\n\n};\n\n/**\n * Returns one of the keys with Minimal value.\n * @return {string}\n */\nAllOne.prototype.getMinKey = function() {\n\n};\n\n/**\n * Your AllOne object will be instantiated and called as such:\n * var obj = new AllOne()\n * obj.inc(key)\n * obj.dec(key)\n * var param_3 = obj.getMaxKey()\n * var param_4 = obj.getMinKey()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class AllOne\n\n=begin\n Initialize your data structure here.\n=end\n def initialize()\n\n end\n\n\n=begin\n Inserts a new key with value 1. Or increments an existing key by 1.\n :type key: String\n :rtype: Void\n=end\n def inc(key)\n\n end\n\n\n=begin\n Decrements an existing key by 1. If Key's value is 1, remove it from the data structure.\n :type key: String\n :rtype: Void\n=end\n def dec(key)\n\n end\n\n\n=begin\n Returns one of the keys with maximal value.\n :rtype: String\n=end\n def get_max_key()\n\n end\n\n\n=begin\n Returns one of the keys with Minimal value.\n :rtype: String\n=end\n def get_min_key()\n\n end\n\n\nend\n\n# Your AllOne object will be instantiated and called as such:\n# obj = AllOne.new()\n# obj.inc(key)\n# obj.dec(key)\n# param_3 = obj.get_max_key()\n# param_4 = obj.get_min_key()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass AllOne {\n\n /** Initialize your data structure here. */\n init() {\n\n }\n \n /** Inserts a new key with value 1. Or increments an existing key by 1. */\n func inc(_ key: String) {\n\n }\n \n /** Decrements an existing key by 1. If Key's value is 1, remove it from the data structure. */\n func dec(_ key: String) {\n\n }\n \n /** Returns one of the keys with maximal value. */\n func getMaxKey() -> String {\n\n }\n \n /** Returns one of the keys with Minimal value. */\n func getMinKey() -> String {\n\n }\n}\n\n/**\n * Your AllOne object will be instantiated and called as such:\n * let obj = AllOne()\n * obj.inc(key)\n * obj.dec(key)\n * let ret_3: String = obj.getMaxKey()\n * let ret_4: String = obj.getMinKey()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type AllOne struct {\n\n}\n\n\n/** Initialize your data structure here. */\nfunc Constructor() AllOne {\n\n}\n\n\n/** Inserts a new key with value 1. Or increments an existing key by 1. */\nfunc (this *AllOne) Inc(key string) {\n\n}\n\n\n/** Decrements an existing key by 1. If Key's value is 1, remove it from the data structure. */\nfunc (this *AllOne) Dec(key string) {\n\n}\n\n\n/** Returns one of the keys with maximal value. */\nfunc (this *AllOne) GetMaxKey() string {\n\n}\n\n\n/** Returns one of the keys with Minimal value. */\nfunc (this *AllOne) GetMinKey() string {\n\n}\n\n\n/**\n * Your AllOne object will be instantiated and called as such:\n * obj := Constructor();\n * obj.Inc(key);\n * obj.Dec(key);\n * param_3 := obj.GetMaxKey();\n * param_4 := obj.GetMinKey();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class AllOne() {\n\n /** Initialize your data structure here. */\n\n\n /** Inserts a new key with value 1. Or increments an existing key by 1. */\n def inc(key: String) {\n\n }\n\n /** Decrements an existing key by 1. If Key's value is 1, remove it from the data structure. */\n def dec(key: String) {\n\n }\n\n /** Returns one of the keys with maximal value. */\n def getMaxKey(): String = {\n\n }\n\n /** Returns one of the keys with Minimal value. */\n def getMinKey(): String = {\n\n }\n\n}\n\n/**\n * Your AllOne object will be instantiated and called as such:\n * var obj = new AllOne()\n * obj.inc(key)\n * obj.dec(key)\n * var param_3 = obj.getMaxKey()\n * var param_4 = obj.getMinKey()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class AllOne() {\n\n /** Initialize your data structure here. */\n\n\n /** Inserts a new key with value 1. Or increments an existing key by 1. */\n fun inc(key: String) {\n\n }\n\n /** Decrements an existing key by 1. If Key's value is 1, remove it from the data structure. */\n fun dec(key: String) {\n\n }\n\n /** Returns one of the keys with maximal value. */\n fun getMaxKey(): String {\n\n }\n\n /** Returns one of the keys with Minimal value. */\n fun getMinKey(): String {\n\n }\n\n}\n\n/**\n * Your AllOne object will be instantiated and called as such:\n * var obj = AllOne()\n * obj.inc(key)\n * obj.dec(key)\n * var param_3 = obj.getMaxKey()\n * var param_4 = obj.getMinKey()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct AllOne {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl AllOne {\n\n /** Initialize your data structure here. */\n fn new() -> Self {\n\n }\n \n /** Inserts a new key with value 1. Or increments an existing key by 1. */\n fn inc(&self, key: String) {\n\n }\n \n /** Decrements an existing key by 1. If Key's value is 1, remove it from the data structure. */\n fn dec(&self, key: String) {\n\n }\n \n /** Returns one of the keys with maximal value. */\n fn get_max_key(&self) -> String {\n\n }\n \n /** Returns one of the keys with Minimal value. */\n fn get_min_key(&self) -> String {\n\n }\n}\n\n/**\n * Your AllOne object will be instantiated and called as such:\n * let obj = AllOne::new();\n * obj.inc(key);\n * obj.dec(key);\n * let ret_3: String = obj.get_max_key();\n * let ret_4: String = obj.get_min_key();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class AllOne {\n /**\n * Initialize your data structure here.\n */\n function __construct() {\n\n }\n\n /**\n * Inserts a new key with value 1. Or increments an existing key by 1.\n * @param String $key\n * @return NULL\n */\n function inc($key) {\n\n }\n\n /**\n * Decrements an existing key by 1. If Key's value is 1, remove it from the data structure.\n * @param String $key\n * @return NULL\n */\n function dec($key) {\n\n }\n\n /**\n * Returns one of the keys with maximal value.\n * @return String\n */\n function getMaxKey() {\n\n }\n\n /**\n * Returns one of the keys with Minimal value.\n * @return String\n */\n function getMinKey() {\n\n }\n}\n\n/**\n * Your AllOne object will be instantiated and called as such:\n * $obj = AllOne();\n * $obj->inc($key);\n * $obj->dec($key);\n * $ret_3 = $obj->getMaxKey();\n * $ret_4 = $obj->getMinKey();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class AllOne {\n constructor() {\n\n }\n\n inc(key: string): void {\n\n }\n\n dec(key: string): void {\n\n }\n\n getMaxKey(): string {\n\n }\n\n getMinKey(): string {\n\n }\n}\n\n/**\n * Your AllOne object will be instantiated and called as such:\n * var obj = new AllOne()\n * obj.inc(key)\n * obj.dec(key)\n * var param_3 = obj.getMaxKey()\n * var param_4 = obj.getMinKey()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define all-one%\n (class object%\n (super-new)\n (init-field)\n \n ; inc : string? -> void?\n (define/public (inc key)\n\n )\n ; dec : string? -> void?\n (define/public (dec key)\n\n )\n ; get-max-key : -> string?\n (define/public (get-max-key)\n\n )\n ; get-min-key : -> string?\n (define/public (get-min-key)\n\n )))\n\n;; Your all-one% object will be instantiated and called as such:\n;; (define obj (new all-one%))\n;; (send obj inc key)\n;; (send obj dec key)\n;; (define param_3 (send obj get-max-key))\n;; (define param_4 (send obj get-min-key))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0432](https://leetcode-cn.com/problems/all-oone-data-structure)", "[\u5168 O(1) \u7684\u6570\u636e\u7ed3\u6784](/solution/0400-0499/0432.All%20O%60one%20Data%20Structure/README.md)", "`\u8bbe\u8ba1`", "\u56f0\u96be", ""], "md_table_row_en": ["[0432](https://leetcode.com/problems/all-oone-data-structure)", "[All O`one Data Structure](/solution/0400-0499/0432.All%20O%60one%20Data%20Structure/README_EN.md)", "`Design`", "Hard", ""]}, {"question_id": "0425", "frontend_question_id": "0425", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/word-squares", "url_en": "https://leetcode.com/problems/word-squares", "relative_path_cn": "/solution/0400-0499/0425.Word%20Squares/README.md", "relative_path_en": "/solution/0400-0499/0425.Word%20Squares/README_EN.md", "title_cn": "\u5355\u8bcd\u65b9\u5757", "title_en": "Word Squares", "question_title_slug": "word-squares", "content_en": "

    Given an array of unique strings words, return all the word squares you can build from words. The same word from words can be used multiple times. You can return the answer in any order.

    \n\n

    A sequence of strings forms a valid word square if the kth row and column read the same string, where 0 <= k < max(numRows, numColumns).

    \n\n
      \n\t
    • For example, the word sequence ["ball","area","lead","lady"] forms a word square because each word reads the same both horizontally and vertically.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: words = ["area","lead","wall","lady","ball"]\nOutput: [["ball","area","lead","lady"],["wall","area","lead","lady"]]\nExplanation:\nThe output consists of two word squares. The order of output does not matter (just the order of words in each word square matters).\n
    \n\n

    Example 2:

    \n\n
    \nInput: words = ["abat","baba","atan","atal"]\nOutput: [["baba","abat","baba","atal"],["baba","abat","baba","atan"]]\nExplanation:\nThe output consists of two word squares. The order of output does not matter (just the order of words in each word square matters).\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= words.length <= 1000
    • \n\t
    • 1 <= words[i].length <= 5
    • \n\t
    • All words[i] have the same length.
    • \n\t
    • words[i] consists of only lowercase English letters.
    • \n\t
    • All words[i] are unique.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5355\u8bcd\u96c6\u5408 \uff08\u6ca1\u6709\u91cd\u590d\uff09\uff0c\u627e\u51fa\u5176\u4e2d\u6240\u6709\u7684 \u5355\u8bcd\u65b9\u5757 \u3002

    \n\n

    \u4e00\u4e2a\u5355\u8bcd\u5e8f\u5217\u5f62\u6210\u4e86\u4e00\u4e2a\u6709\u6548\u7684\u5355\u8bcd\u65b9\u5757\u7684\u610f\u601d\u662f\u6307\u4ece\u7b2c k \u884c\u548c\u7b2c k \u5217 (0 ≤ k < max(\u884c\u6570, \u5217\u6570)) \u6765\u770b\u90fd\u662f\u76f8\u540c\u7684\u5b57\u7b26\u4e32\u3002

    \n\n

    \u4f8b\u5982\uff0c\u5355\u8bcd\u5e8f\u5217 ["ball","area","lead","lady"] \u5f62\u6210\u4e86\u4e00\u4e2a\u5355\u8bcd\u65b9\u5757\uff0c\u56e0\u4e3a\u6bcf\u4e2a\u5355\u8bcd\u4ece\u6c34\u5e73\u65b9\u5411\u770b\u548c\u4ece\u7ad6\u76f4\u65b9\u5411\u770b\u90fd\u662f\u76f8\u540c\u7684\u3002

    \n\n
    b a l l\na r e a\nl e a d\nl a d y\n
    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    1. \u5355\u8bcd\u4e2a\u6570\u5927\u4e8e\u7b49\u4e8e 1 \u4e14\u4e0d\u8d85\u8fc7 500\u3002
    2. \n\t
    3. \u6240\u6709\u7684\u5355\u8bcd\u957f\u5ea6\u90fd\u76f8\u540c\u3002
    4. \n\t
    5. \u5355\u8bcd\u957f\u5ea6\u5927\u4e8e\u7b49\u4e8e 1 \u4e14\u4e0d\u8d85\u8fc7 5\u3002
    6. \n\t
    7. \u6bcf\u4e2a\u5355\u8bcd\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd a-z\u3002
    8. \n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a\n["area","lead","wall","lady","ball"]\n\n\u8f93\u51fa\uff1a\n[\n  [ "wall",\n    "area",\n    "lead",\n    "lady"\n  ],\n  [ "ball",\n    "area",\n    "lead",\n    "lady"\n  ]\n]\n\n\u89e3\u91ca\uff1a\n\u8f93\u51fa\u5305\u542b\u4e24\u4e2a\u5355\u8bcd\u65b9\u5757\uff0c\u8f93\u51fa\u7684\u987a\u5e8f\u4e0d\u91cd\u8981\uff0c\u53ea\u9700\u8981\u4fdd\u8bc1\u6bcf\u4e2a\u5355\u8bcd\u65b9\u5757\u5185\u7684\u5355\u8bcd\u987a\u5e8f\u6b63\u786e\u5373\u53ef\u3002 \n
    \n\n

     

    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a\n["abat","baba","atan","atal"]\n\n\u8f93\u51fa\uff1a\n[\n  [ "baba",\n    "abat",\n    "baba",\n    "atan"\n  ],\n  [ "baba",\n    "abat",\n    "baba",\n    "atal"\n  ]\n]\n\n\u89e3\u91ca\uff1a\n\u8f93\u51fa\u5305\u542b\u4e24\u4e2a\u5355\u8bcd\u65b9\u5757\uff0c\u8f93\u51fa\u7684\u987a\u5e8f\u4e0d\u91cd\u8981\uff0c\u53ea\u9700\u8981\u4fdd\u8bc1\u6bcf\u4e2a\u5355\u8bcd\u65b9\u5757\u5185\u7684\u5355\u8bcd\u987a\u5e8f\u6b63\u786e\u5373\u53ef\u3002 \n
    \n\n

     

    \n", "tags_en": ["Trie", "Backtracking"], "tags_cn": ["\u5b57\u5178\u6811", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> wordSquares(vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> wordSquares(String[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def wordSquares(self, words):\n \"\"\"\n :type words: List[str]\n :rtype: List[List[str]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def wordSquares(self, words: List[str]) -> List[List[str]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nchar *** wordSquares(char ** words, int wordsSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> WordSquares(string[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @return {string[][]}\n */\nvar wordSquares = function(words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @return {String[][]}\ndef word_squares(words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func wordSquares(_ words: [String]) -> [[String]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func wordSquares(words []string) [][]string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def wordSquares(words: Array[String]): List[List[String]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun wordSquares(words: Array): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn word_squares(words: Vec) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @return String[][]\n */\n function wordSquares($words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function wordSquares(words: string[]): string[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (word-squares words)\n (-> (listof string?) (listof (listof string?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0425](https://leetcode-cn.com/problems/word-squares)", "[\u5355\u8bcd\u65b9\u5757](/solution/0400-0499/0425.Word%20Squares/README.md)", "`\u5b57\u5178\u6811`,`\u56de\u6eaf\u7b97\u6cd5`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0425](https://leetcode.com/problems/word-squares)", "[Word Squares](/solution/0400-0499/0425.Word%20Squares/README_EN.md)", "`Trie`,`Backtracking`", "Hard", "\ud83d\udd12"]}, {"question_id": "0424", "frontend_question_id": "0424", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-repeating-character-replacement", "url_en": "https://leetcode.com/problems/longest-repeating-character-replacement", "relative_path_cn": "/solution/0400-0499/0424.Longest%20Repeating%20Character%20Replacement/README.md", "relative_path_en": "/solution/0400-0499/0424.Longest%20Repeating%20Character%20Replacement/README_EN.md", "title_cn": "\u66ff\u6362\u540e\u7684\u6700\u957f\u91cd\u590d\u5b57\u7b26", "title_en": "Longest Repeating Character Replacement", "question_title_slug": "longest-repeating-character-replacement", "content_en": "

    You are given a string s and an integer k. You can choose any character of the string and change it to any other uppercase English character. You can perform this operation at most k times.

    \n\n

    Return the length of the longest substring containing the same letter you can get after performing the above operations.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "ABAB", k = 2\nOutput: 4\nExplanation: Replace the two 'A's with two 'B's or vice versa.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "AABABBA", k = 1\nOutput: 4\nExplanation: Replace the one 'A' in the middle with 'B' and form "AABBBBA".\nThe substring "BBBB" has the longest repeating letters, which is 4.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 105
    • \n\t
    • s consists of only uppercase English letters.
    • \n\t
    • 0 <= k <= s.length
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u4ec5\u7531\u5927\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210\u7684\u5b57\u7b26\u4e32\uff0c\u4f60\u53ef\u4ee5\u5c06\u4efb\u610f\u4f4d\u7f6e\u4e0a\u7684\u5b57\u7b26\u66ff\u6362\u6210\u53e6\u5916\u7684\u5b57\u7b26\uff0c\u603b\u5171\u53ef\u6700\u591a\u66ff\u6362\u00a0k\u00a0\u6b21\u3002\u5728\u6267\u884c\u4e0a\u8ff0\u64cd\u4f5c\u540e\uff0c\u627e\u5230\u5305\u542b\u91cd\u590d\u5b57\u6bcd\u7684\u6700\u957f\u5b50\u4e32\u7684\u957f\u5ea6\u3002

    \n\n

    \u6ce8\u610f\uff1a\u5b57\u7b26\u4e32\u957f\u5ea6 \u548c k \u4e0d\u4f1a\u8d85\u8fc7\u00a0104\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"ABAB\", k = 2\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u7528\u4e24\u4e2a'A'\u66ff\u6362\u4e3a\u4e24\u4e2a'B',\u53cd\u4e4b\u4ea6\u7136\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"AABABBA\", k = 1\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\n\u5c06\u4e2d\u95f4\u7684\u4e00\u4e2a'A'\u66ff\u6362\u4e3a'B',\u5b57\u7b26\u4e32\u53d8\u4e3a \"AABBBBA\"\u3002\n\u5b50\u4e32 \"BBBB\" \u6709\u6700\u957f\u91cd\u590d\u5b57\u6bcd, \u7b54\u6848\u4e3a 4\u3002\n
    \n", "tags_en": ["Two Pointers", "Sliding Window"], "tags_cn": ["\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int characterReplacement(string s, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int characterReplacement(String s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def characterReplacement(self, s, k):\n \"\"\"\n :type s: str\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def characterReplacement(self, s: str, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint characterReplacement(char * s, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CharacterReplacement(string s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number} k\n * @return {number}\n */\nvar characterReplacement = function(s, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer} k\n# @return {Integer}\ndef character_replacement(s, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func characterReplacement(_ s: String, _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func characterReplacement(s string, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def characterReplacement(s: String, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun characterReplacement(s: String, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn character_replacement(s: String, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer $k\n * @return Integer\n */\n function characterReplacement($s, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function characterReplacement(s: string, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (character-replacement s k)\n (-> string? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0424](https://leetcode-cn.com/problems/longest-repeating-character-replacement)", "[\u66ff\u6362\u540e\u7684\u6700\u957f\u91cd\u590d\u5b57\u7b26](/solution/0400-0499/0424.Longest%20Repeating%20Character%20Replacement/README.md)", "`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0424](https://leetcode.com/problems/longest-repeating-character-replacement)", "[Longest Repeating Character Replacement](/solution/0400-0499/0424.Longest%20Repeating%20Character%20Replacement/README_EN.md)", "`Two Pointers`,`Sliding Window`", "Medium", ""]}, {"question_id": "0423", "frontend_question_id": "0423", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reconstruct-original-digits-from-english", "url_en": "https://leetcode.com/problems/reconstruct-original-digits-from-english", "relative_path_cn": "/solution/0400-0499/0423.Reconstruct%20Original%20Digits%20from%20English/README.md", "relative_path_en": "/solution/0400-0499/0423.Reconstruct%20Original%20Digits%20from%20English/README_EN.md", "title_cn": "\u4ece\u82f1\u6587\u4e2d\u91cd\u5efa\u6570\u5b57", "title_en": "Reconstruct Original Digits from English", "question_title_slug": "reconstruct-original-digits-from-english", "content_en": "

    Given a string s containing an out-of-order English representation of digits 0-9, return the digits in ascending order.

    \n\n

     

    \n

    Example 1:

    \n
    Input: s = \"owoztneoer\"\nOutput: \"012\"\n

    Example 2:

    \n
    Input: s = \"fviefuro\"\nOutput: \"45\"\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 105
    • \n\t
    • s[i] is one of the characters ["e","g","f","i","h","o","n","s","r","u","t","w","v","x","z"].
    • \n\t
    • s is guaranteed to be valid.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u7a7a\u5b57\u7b26\u4e32\uff0c\u5176\u4e2d\u5305\u542b\u5b57\u6bcd\u987a\u5e8f\u6253\u4e71\u7684\u82f1\u6587\u5355\u8bcd\u8868\u793a\u7684\u6570\u5b570-9\u3002\u6309\u5347\u5e8f\u8f93\u51fa\u539f\u59cb\u7684\u6570\u5b57\u3002

    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u8f93\u5165\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u3002
    2. \n\t
    3. \u8f93\u5165\u4fdd\u8bc1\u5408\u6cd5\u5e76\u53ef\u4ee5\u8f6c\u6362\u4e3a\u539f\u59cb\u7684\u6570\u5b57\uff0c\u8fd9\u610f\u5473\u7740\u50cf "abc" \u6216 "zerone" \u7684\u8f93\u5165\u662f\u4e0d\u5141\u8bb8\u7684\u3002
    4. \n\t
    5. \u8f93\u5165\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u5c0f\u4e8e 50,000\u3002
    6. \n
    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: "owoztneoer"\n\n\u8f93\u51fa: "012" (zeroonetwo)\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: "fviefuro"\n\n\u8f93\u51fa: "45" (fourfive)\n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string originalDigits(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String originalDigits(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def originalDigits(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def originalDigits(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * originalDigits(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string OriginalDigits(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar originalDigits = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef original_digits(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func originalDigits(_ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func originalDigits(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def originalDigits(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun originalDigits(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn original_digits(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function originalDigits($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function originalDigits(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (original-digits s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0423](https://leetcode-cn.com/problems/reconstruct-original-digits-from-english)", "[\u4ece\u82f1\u6587\u4e2d\u91cd\u5efa\u6570\u5b57](/solution/0400-0499/0423.Reconstruct%20Original%20Digits%20from%20English/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0423](https://leetcode.com/problems/reconstruct-original-digits-from-english)", "[Reconstruct Original Digits from English](/solution/0400-0499/0423.Reconstruct%20Original%20Digits%20from%20English/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "0422", "frontend_question_id": "0422", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/valid-word-square", "url_en": "https://leetcode.com/problems/valid-word-square", "relative_path_cn": "/solution/0400-0499/0422.Valid%20Word%20Square/README.md", "relative_path_en": "/solution/0400-0499/0422.Valid%20Word%20Square/README_EN.md", "title_cn": "\u6709\u6548\u7684\u5355\u8bcd\u65b9\u5757", "title_en": "Valid Word Square", "question_title_slug": "valid-word-square", "content_en": "

    Given an array of strings words, return true if it forms a valid word square.

    \n\n

    A sequence of strings forms a valid word square if the kth row and column read the same string, where 0 <= k < max(numRows, numColumns).

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: words = ["abcd","bnrt","crmy","dtye"]\nOutput: true\nExplanation:\nThe 1st row and 1st column both read "abcd".\nThe 2nd row and 2nd column both read "bnrt".\nThe 3rd row and 3rd column both read "crmy".\nThe 4th row and 4th column both read "dtye".\nTherefore, it is a valid word square.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: words = ["abcd","bnrt","crm","dt"]\nOutput: true\nExplanation:\nThe 1st row and 1st column both read "abcd".\nThe 2nd row and 2nd column both read "bnrt".\nThe 3rd row and 3rd column both read "crm".\nThe 4th row and 4th column both read "dt".\nTherefore, it is a valid word square.\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: words = ["ball","area","read","lady"]\nOutput: false\nExplanation:\nThe 3rd row reads "read" while the 3rd column reads "lead".\nTherefore, it is NOT a valid word square.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= words.length <= 500
    • \n\t
    • 1 <= words[i].length <= 500
    • \n\t
    • words[i] consists of only lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5355\u8bcd\u5e8f\u5217\uff0c\u5224\u65ad\u5176\u662f\u5426\u5f62\u6210\u4e86\u4e00\u4e2a\u6709\u6548\u7684\u5355\u8bcd\u65b9\u5757\u3002

    \n\n

    \u6709\u6548\u7684\u5355\u8bcd\u65b9\u5757\u662f\u6307\u6b64\u7531\u5355\u8bcd\u5e8f\u5217\u7ec4\u6210\u7684\u6587\u5b57\u65b9\u5757\u7684 \u7b2c k \u884c \u548c \u7b2c k \u5217 (0 ≤ k < max(\u884c\u6570, \u5217\u6570)) \u6240\u663e\u793a\u7684\u5b57\u7b26\u4e32\u5b8c\u5168\u76f8\u540c\u3002

    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    1. \u7ed9\u5b9a\u7684\u5355\u8bcd\u6570\u5927\u4e8e\u7b49\u4e8e 1 \u4e14\u4e0d\u8d85\u8fc7 500\u3002
    2. \n\t
    3. \u5355\u8bcd\u957f\u5ea6\u5927\u4e8e\u7b49\u4e8e 1 \u4e14\u4e0d\u8d85\u8fc7 500\u3002
    4. \n\t
    5. \u6bcf\u4e2a\u5355\u8bcd\u53ea\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd a-z\u3002
    6. \n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a\n[\n  "abcd",\n  "bnrt",\n  "crmy",\n  "dtye"\n]\n\n\u8f93\u51fa\uff1a\ntrue\n\n\u89e3\u91ca\uff1a\n\u7b2c 1 \u884c\u548c\u7b2c 1 \u5217\u90fd\u662f "abcd"\u3002\n\u7b2c 2 \u884c\u548c\u7b2c 2 \u5217\u90fd\u662f "bnrt"\u3002\n\u7b2c 3 \u884c\u548c\u7b2c 3 \u5217\u90fd\u662f "crmy"\u3002\n\u7b2c 4 \u884c\u548c\u7b2c 4 \u5217\u90fd\u662f "dtye"\u3002\n\n\u56e0\u6b64\uff0c\u8fd9\u662f\u4e00\u4e2a\u6709\u6548\u7684\u5355\u8bcd\u65b9\u5757\u3002\n
    \n\n

     

    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a\n[\n  "abcd",\n  "bnrt",\n  "crm",\n  "dt"\n]\n\n\u8f93\u51fa\uff1a\ntrue\n\n\u89e3\u91ca\uff1a\n\u7b2c 1 \u884c\u548c\u7b2c 1 \u5217\u90fd\u662f "abcd"\u3002\n\u7b2c 2 \u884c\u548c\u7b2c 2 \u5217\u90fd\u662f "bnrt"\u3002\n\u7b2c 3 \u884c\u548c\u7b2c 3 \u5217\u90fd\u662f "crm"\u3002\n\u7b2c 4 \u884c\u548c\u7b2c 4 \u5217\u90fd\u662f "dt"\u3002\n\n\u56e0\u6b64\uff0c\u8fd9\u662f\u4e00\u4e2a\u6709\u6548\u7684\u5355\u8bcd\u65b9\u5757\u3002\n
    \n\n

     

    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1a\n[\n  "ball",\n  "area",\n  "read",\n  "lady"\n]\n\n\u8f93\u51fa\uff1a\nfalse\n\n\u89e3\u91ca\uff1a\n\u7b2c 3 \u884c\u662f "read" \uff0c\u7136\u800c\u7b2c 3 \u5217\u662f "lead"\u3002\n\n\u56e0\u6b64\uff0c\u8fd9 \u4e0d\u662f \u4e00\u4e2a\u6709\u6548\u7684\u5355\u8bcd\u65b9\u5757\u3002\n
    \n\n

     

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool validWordSquare(vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean validWordSquare(List words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def validWordSquare(self, words):\n \"\"\"\n :type words: List[str]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def validWordSquare(self, words: List[str]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool validWordSquare(char ** words, int wordsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool ValidWordSquare(IList words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @return {boolean}\n */\nvar validWordSquare = function(words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @return {Boolean}\ndef valid_word_square(words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func validWordSquare(_ words: [String]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func validWordSquare(words []string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def validWordSquare(words: List[String]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun validWordSquare(words: List): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn valid_word_square(words: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @return Boolean\n */\n function validWordSquare($words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function validWordSquare(words: string[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (valid-word-square words)\n (-> (listof string?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0422](https://leetcode-cn.com/problems/valid-word-square)", "[\u6709\u6548\u7684\u5355\u8bcd\u65b9\u5757](/solution/0400-0499/0422.Valid%20Word%20Square/README.md)", "", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0422](https://leetcode.com/problems/valid-word-square)", "[Valid Word Square](/solution/0400-0499/0422.Valid%20Word%20Square/README_EN.md)", "", "Easy", "\ud83d\udd12"]}, {"question_id": "0421", "frontend_question_id": "0421", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-xor-of-two-numbers-in-an-array", "url_en": "https://leetcode.com/problems/maximum-xor-of-two-numbers-in-an-array", "relative_path_cn": "/solution/0400-0499/0421.Maximum%20XOR%20of%20Two%20Numbers%20in%20an%20Array/README.md", "relative_path_en": "/solution/0400-0499/0421.Maximum%20XOR%20of%20Two%20Numbers%20in%20an%20Array/README_EN.md", "title_cn": "\u6570\u7ec4\u4e2d\u4e24\u4e2a\u6570\u7684\u6700\u5927\u5f02\u6216\u503c", "title_en": "Maximum XOR of Two Numbers in an Array", "question_title_slug": "maximum-xor-of-two-numbers-in-an-array", "content_en": "

    Given an integer array nums, return the maximum result of nums[i] XOR nums[j], where 0 <= i <= j < n.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [3,10,5,25,2,8]\nOutput: 28\nExplanation: The maximum result is 5 XOR 25 = 28.
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [0]\nOutput: 0\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [2,4]\nOutput: 6\n
    \n\n

    Example 4:

    \n\n
    \nInput: nums = [8,10,2]\nOutput: 10\n
    \n\n

    Example 5:

    \n\n
    \nInput: nums = [14,70,53,83,49,91,36,80,92,51,66,70]\nOutput: 127\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 2 * 105
    • \n\t
    • 0 <= nums[i] <= 231 - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \uff0c\u8fd4\u56de nums[i] XOR nums[j] \u7684\u6700\u5927\u8fd0\u7b97\u7ed3\u679c\uff0c\u5176\u4e2d 0 \u2264 i \u2264 j < n \u3002

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u53ef\u4ee5\u5728 O(n) \u7684\u65f6\u95f4\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u5417\uff1f

    \n\n

    \u00a0

    \n\n
    \n
    \n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [3,10,5,25,2,8]\n\u8f93\u51fa\uff1a28\n\u89e3\u91ca\uff1a\u6700\u5927\u8fd0\u7b97\u7ed3\u679c\u662f 5 XOR 25 = 28.
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [0]\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [2,4]\n\u8f93\u51fa\uff1a6\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [8,10,2]\n\u8f93\u51fa\uff1a10\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [14,70,53,83,49,91,36,80,92,51,66,70]\n\u8f93\u51fa\uff1a127\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 2 * 104
    • \n\t
    • 0 <= nums[i] <= 231 - 1
    • \n
    \n
    \n
    \n", "tags_en": ["Bit Manipulation", "Trie"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u5b57\u5178\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findMaximumXOR(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findMaximumXOR(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findMaximumXOR(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findMaximumXOR(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findMaximumXOR(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindMaximumXOR(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar findMaximumXOR = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef find_maximum_xor(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findMaximumXOR(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findMaximumXOR(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findMaximumXOR(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findMaximumXOR(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_maximum_xor(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function findMaximumXOR($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findMaximumXOR(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-maximum-xor nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0421](https://leetcode-cn.com/problems/maximum-xor-of-two-numbers-in-an-array)", "[\u6570\u7ec4\u4e2d\u4e24\u4e2a\u6570\u7684\u6700\u5927\u5f02\u6216\u503c](/solution/0400-0499/0421.Maximum%20XOR%20of%20Two%20Numbers%20in%20an%20Array/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u5b57\u5178\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0421](https://leetcode.com/problems/maximum-xor-of-two-numbers-in-an-array)", "[Maximum XOR of Two Numbers in an Array](/solution/0400-0499/0421.Maximum%20XOR%20of%20Two%20Numbers%20in%20an%20Array/README_EN.md)", "`Bit Manipulation`,`Trie`", "Medium", ""]}, {"question_id": "0420", "frontend_question_id": "0420", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/strong-password-checker", "url_en": "https://leetcode.com/problems/strong-password-checker", "relative_path_cn": "/solution/0400-0499/0420.Strong%20Password%20Checker/README.md", "relative_path_en": "/solution/0400-0499/0420.Strong%20Password%20Checker/README_EN.md", "title_cn": "\u5f3a\u5bc6\u7801\u68c0\u9a8c\u5668", "title_en": "Strong Password Checker", "question_title_slug": "strong-password-checker", "content_en": "

    A password is considered strong if the below conditions are all met:

    \n\n
      \n\t
    • It has at least 6 characters and at most 20 characters.
    • \n\t
    • It contains at least one lowercase letter, at least one uppercase letter, and at least one digit.
    • \n\t
    • It does not contain three repeating characters in a row (i.e., "...aaa..." is weak, but "...aa...a..." is strong, assuming other conditions are met).
    • \n
    \n\n

    Given a string password, return the minimum number of steps required to make password strong. if password is already strong, return 0.

    \n\n

    In one step, you can:

    \n\n
      \n\t
    • Insert one character to password,
    • \n\t
    • Delete one character from password, or
    • \n\t
    • Replace one character of password with another character.
    • \n
    \n\n

     

    \n

    Example 1:

    \n
    Input: password = \"a\"\nOutput: 5\n

    Example 2:

    \n
    Input: password = \"aA1\"\nOutput: 3\n

    Example 3:

    \n
    Input: password = \"1337C0d3\"\nOutput: 0\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= password.length <= 50
    • \n\t
    • password consists of letters, digits, dot '.' or exclamation mark '!'.
    • \n
    \n", "content_cn": "

    \u4e00\u4e2a\u5f3a\u5bc6\u7801\u5e94\u6ee1\u8db3\u4ee5\u4e0b\u6240\u6709\u6761\u4ef6\uff1a

    \n\n
      \n\t
    1. \u7531\u81f3\u5c116\u4e2a\uff0c\u81f3\u591a20\u4e2a\u5b57\u7b26\u7ec4\u6210\u3002
    2. \n\t
    3. \u81f3\u5c11\u5305\u542b\u4e00\u4e2a\u5c0f\u5199\u5b57\u6bcd\uff0c\u4e00\u4e2a\u5927\u5199\u5b57\u6bcd\uff0c\u548c\u4e00\u4e2a\u6570\u5b57\u3002
    4. \n\t
    5. \u540c\u4e00\u5b57\u7b26\u4e0d\u80fd\u8fde\u7eed\u51fa\u73b0\u4e09\u6b21 (\u6bd4\u5982 "...aaa..." \u662f\u4e0d\u5141\u8bb8\u7684, \u4f46\u662f "...aa...a..." \u662f\u53ef\u4ee5\u7684)\u3002
    6. \n
    \n\n

    \u7f16\u5199\u51fd\u6570 strongPasswordChecker(s)\uff0cs \u4ee3\u8868\u8f93\u5165\u5b57\u7b26\u4e32\uff0c\u5982\u679c s \u5df2\u7ecf\u7b26\u5408\u5f3a\u5bc6\u7801\u6761\u4ef6\uff0c\u5219\u8fd4\u56de0\uff1b\u5426\u5219\u8fd4\u56de\u8981\u5c06 s \u4fee\u6539\u4e3a\u6ee1\u8db3\u5f3a\u5bc6\u7801\u6761\u4ef6\u7684\u5b57\u7b26\u4e32\u6240\u9700\u8981\u8fdb\u884c\u4fee\u6539\u7684\u6700\u5c0f\u6b65\u6570\u3002

    \n\n

    \u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\u4efb\u4e00\u5b57\u7b26\u90fd\u7b97\u4f5c\u4e00\u6b21\u4fee\u6539\u3002

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int strongPasswordChecker(string password) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int strongPasswordChecker(String password) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def strongPasswordChecker(self, password):\n \"\"\"\n :type password: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def strongPasswordChecker(self, password: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint strongPasswordChecker(char * password){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int StrongPasswordChecker(string password) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} password\n * @return {number}\n */\nvar strongPasswordChecker = function(password) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} password\n# @return {Integer}\ndef strong_password_checker(password)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func strongPasswordChecker(_ password: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func strongPasswordChecker(password string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def strongPasswordChecker(password: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun strongPasswordChecker(password: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn strong_password_checker(password: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $password\n * @return Integer\n */\n function strongPasswordChecker($password) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function strongPasswordChecker(password: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (strong-password-checker password)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0420](https://leetcode-cn.com/problems/strong-password-checker)", "[\u5f3a\u5bc6\u7801\u68c0\u9a8c\u5668](/solution/0400-0499/0420.Strong%20Password%20Checker/README.md)", "", "\u56f0\u96be", ""], "md_table_row_en": ["[0420](https://leetcode.com/problems/strong-password-checker)", "[Strong Password Checker](/solution/0400-0499/0420.Strong%20Password%20Checker/README_EN.md)", "", "Hard", ""]}, {"question_id": "0419", "frontend_question_id": "0419", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/battleships-in-a-board", "url_en": "https://leetcode.com/problems/battleships-in-a-board", "relative_path_cn": "/solution/0400-0499/0419.Battleships%20in%20a%20Board/README.md", "relative_path_en": "/solution/0400-0499/0419.Battleships%20in%20a%20Board/README_EN.md", "title_cn": "\u7532\u677f\u4e0a\u7684\u6218\u8230", "title_en": "Battleships in a Board", "question_title_slug": "battleships-in-a-board", "content_en": "

    Given an m x n matrix board where each cell is a battleship 'X' or empty '.', return the number of the battleships on board.

    \n\n

    Battleships can only be placed horizontally or vertically on board. In other words, they can only be made of the shape 1 x k (1 row, k columns) or k x 1 (k rows, 1 column), where k can be of any size. At least one horizontal or vertical cell separates between two battleships (i.e., there are no adjacent battleships).

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: board = [["X",".",".","X"],[".",".",".","X"],[".",".",".","X"]]\nOutput: 2\n
    \n\n

    Example 2:

    \n\n
    \nInput: board = [["."]]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == board.length
    • \n\t
    • n == board[i].length
    • \n\t
    • 1 <= m, n <= 200
    • \n\t
    • board[i][j] is either '.' or 'X'.
    • \n
    \n\n

     

    \n

    Follow up: Could you do it in one-pass, using only O(1) extra memory and without modifying the values board?

    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u7ef4\u7684\u7532\u677f\uff0c \u8bf7\u8ba1\u7b97\u5176\u4e2d\u6709\u591a\u5c11\u8258\u6218\u8230\u3002 \u6218\u8230\u7528 'X'\u8868\u793a\uff0c\u7a7a\u4f4d\u7528 '.'\u8868\u793a\u3002 \u4f60\u9700\u8981\u9075\u5b88\u4ee5\u4e0b\u89c4\u5219\uff1a

    \n\n
      \n\t
    • \u7ed9\u4f60\u4e00\u4e2a\u6709\u6548\u7684\u7532\u677f\uff0c\u4ec5\u7531\u6218\u8230\u6216\u8005\u7a7a\u4f4d\u7ec4\u6210\u3002
    • \n\t
    • \u6218\u8230\u53ea\u80fd\u6c34\u5e73\u6216\u8005\u5782\u76f4\u653e\u7f6e\u3002\u6362\u53e5\u8bdd\u8bf4,\u6218\u8230\u53ea\u80fd\u7531 1xN (1 \u884c, N \u5217)\u7ec4\u6210\uff0c\u6216\u8005 Nx1 (N \u884c, 1 \u5217)\u7ec4\u6210\uff0c\u5176\u4e2dN\u53ef\u4ee5\u662f\u4efb\u610f\u5927\u5c0f\u3002
    • \n\t
    • \u4e24\u8258\u6218\u8230\u4e4b\u95f4\u81f3\u5c11\u6709\u4e00\u4e2a\u6c34\u5e73\u6216\u5782\u76f4\u7684\u7a7a\u4f4d\u5206\u9694 - \u5373\u6ca1\u6709\u76f8\u90bb\u7684\u6218\u8230\u3002
    • \n
    \n\n

    \u793a\u4f8b :

    \n\n
    \nX..X\n...X\n...X\n
    \n\n

    \u5728\u4e0a\u9762\u7684\u7532\u677f\u4e2d\u67092\u8258\u6218\u8230\u3002

    \n\n

    \u65e0\u6548\u6837\u4f8b :

    \n\n
    \n...X\nXXXX\n...X\n
    \n\n

    \u4f60\u4e0d\u4f1a\u6536\u5230\u8fd9\u6837\u7684\u65e0\u6548\u7532\u677f - \u56e0\u4e3a\u6218\u8230\u4e4b\u95f4\u81f3\u5c11\u4f1a\u6709\u4e00\u4e2a\u7a7a\u4f4d\u5c06\u5b83\u4eec\u5206\u5f00\u3002

    \n\n

    \u8fdb\u9636:

    \n\n

    \u4f60\u53ef\u4ee5\u7528\u4e00\u6b21\u626b\u63cf\u7b97\u6cd5\uff0c\u53ea\u4f7f\u7528O(1)\u989d\u5916\u7a7a\u95f4\uff0c\u5e76\u4e14\u4e0d\u4fee\u6539\u7532\u677f\u7684\u503c\u6765\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u5417\uff1f

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countBattleships(vector>& board) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countBattleships(char[][] board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countBattleships(self, board):\n \"\"\"\n :type board: List[List[str]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countBattleships(self, board: List[List[str]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countBattleships(char** board, int boardSize, int* boardColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountBattleships(char[][] board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {character[][]} board\n * @return {number}\n */\nvar countBattleships = function(board) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Character[][]} board\n# @return {Integer}\ndef count_battleships(board)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countBattleships(_ board: [[Character]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countBattleships(board [][]byte) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countBattleships(board: Array[Array[Char]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countBattleships(board: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_battleships(board: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $board\n * @return Integer\n */\n function countBattleships($board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countBattleships(board: string[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-battleships board)\n (-> (listof (listof char?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0419](https://leetcode-cn.com/problems/battleships-in-a-board)", "[\u7532\u677f\u4e0a\u7684\u6218\u8230](/solution/0400-0499/0419.Battleships%20in%20a%20Board/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0419](https://leetcode.com/problems/battleships-in-a-board)", "[Battleships in a Board](/solution/0400-0499/0419.Battleships%20in%20a%20Board/README_EN.md)", "", "Medium", ""]}, {"question_id": "0418", "frontend_question_id": "0418", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/sentence-screen-fitting", "url_en": "https://leetcode.com/problems/sentence-screen-fitting", "relative_path_cn": "/solution/0400-0499/0418.Sentence%20Screen%20Fitting/README.md", "relative_path_en": "/solution/0400-0499/0418.Sentence%20Screen%20Fitting/README_EN.md", "title_cn": "\u5c4f\u5e55\u53ef\u663e\u793a\u53e5\u5b50\u7684\u6570\u91cf", "title_en": "Sentence Screen Fitting", "question_title_slug": "sentence-screen-fitting", "content_en": "

    Given a rows x cols screen and a sentence represented as a list of strings, return the number of times the given sentence can be fitted on the screen.

    \n\n

    The order of words in the sentence must remain unchanged, and a word cannot be split into two lines. A single space must separate two consecutive words in a line.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: sentence = ["hello","world"], rows = 2, cols = 8\nOutput: 1\nExplanation:\nhello---\nworld---\nThe character '-' signifies an empty space on the screen.\n
    \n\n

    Example 2:

    \n\n
    \nInput: sentence = ["a", "bcd", "e"], rows = 3, cols = 6\nOutput: 2\nExplanation:\na-bcd- \ne-a---\nbcd-e-\nThe character '-' signifies an empty space on the screen.\n
    \n\n

    Example 3:

    \n\n
    \nInput: sentence = ["i","had","apple","pie"], rows = 4, cols = 5\nOutput: 1\nExplanation:\ni-had\napple\npie-i\nhad--\nThe character '-' signifies an empty space on the screen.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= sentence.length <= 100
    • \n\t
    • 1 <= sentence[i].length <= 10
    • \n\t
    • sentence[i] consists of lowercase English letters.
    • \n\t
    • 1 <= rows, cols <= 2 * 104
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a rows x cols \u7684\u5c4f\u5e55\u548c\u4e00\u4e2a\u7528 \u975e\u7a7a \u7684\u5355\u8bcd\u5217\u8868\u7ec4\u6210\u7684\u53e5\u5b50\uff0c\u8bf7\u4f60\u8ba1\u7b97\u51fa\u7ed9\u5b9a\u53e5\u5b50\u53ef\u4ee5\u5728\u5c4f\u5e55\u4e0a\u5b8c\u6574\u663e\u793a\u7684\u6b21\u6570\u3002

    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    1. \u4e00\u4e2a\u5355\u8bcd\u4e0d\u80fd\u62c6\u5206\u6210\u4e24\u884c\u3002
    2. \n\t
    3. \u5355\u8bcd\u5728\u53e5\u5b50\u4e2d\u7684\u987a\u5e8f\u5fc5\u987b\u4fdd\u6301\u4e0d\u53d8\u3002
    4. \n\t
    5. \u5728\u4e00\u884c\u4e2d \u7684\u4e24\u4e2a\u8fde\u7eed\u5355\u8bcd\u5fc5\u987b\u7528\u4e00\u4e2a\u7a7a\u683c\u7b26\u5206\u9694\u3002
    6. \n\t
    7. \u53e5\u5b50\u4e2d\u7684\u5355\u8bcd\u603b\u91cf\u4e0d\u4f1a\u8d85\u8fc7 100\u3002
    8. \n\t
    9. \u6bcf\u4e2a\u5355\u8bcd\u7684\u957f\u5ea6\u5927\u4e8e 0 \u4e14\u4e0d\u4f1a\u8d85\u8fc7 10\u3002
    10. \n\t
    11. 1 ≤ rows, cols ≤ 20,000.
    12. \n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a\nrows = 2, cols = 8, \u53e5\u5b50 sentence = ["hello", "world"]\n\n\u8f93\u51fa\uff1a\n1\n\n\u89e3\u91ca\uff1a\nhello---\nworld---\n\n\u5b57\u7b26 '-' \u8868\u793a\u5c4f\u5e55\u4e0a\u7684\u4e00\u4e2a\u7a7a\u767d\u4f4d\u7f6e\u3002\n
    \n\n

     

    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a\nrows = 3, cols = 6, \u53e5\u5b50 sentence = ["a", "bcd", "e"]\n\n\u8f93\u51fa\uff1a\n2\n\n\u89e3\u91ca\uff1a\na-bcd- \ne-a---\nbcd-e-\n\n\u5b57\u7b26 '-' \u8868\u793a\u5c4f\u5e55\u4e0a\u7684\u4e00\u4e2a\u7a7a\u767d\u4f4d\u7f6e\u3002\n
    \n\n

     

    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1a\nrows = 4, cols = 5, \u53e5\u5b50 sentence = ["I", "had", "apple", "pie"]\n\n\u8f93\u51fa\uff1a\n1\n\n\u89e3\u91ca\uff1a\nI-had\napple\npie-I\nhad--\n\n\u5b57\u7b26 '-' \u8868\u793a\u5c4f\u5e55\u4e0a\u7684\u4e00\u4e2a\u7a7a\u767d\u4f4d\u7f6e\u3002\n
    \n\n

     

    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int wordsTyping(vector& sentence, int rows, int cols) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int wordsTyping(String[] sentence, int rows, int cols) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def wordsTyping(self, sentence, rows, cols):\n \"\"\"\n :type sentence: List[str]\n :type rows: int\n :type cols: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def wordsTyping(self, sentence: List[str], rows: int, cols: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint wordsTyping(char ** sentence, int sentenceSize, int rows, int cols){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int WordsTyping(string[] sentence, int rows, int cols) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} sentence\n * @param {number} rows\n * @param {number} cols\n * @return {number}\n */\nvar wordsTyping = function(sentence, rows, cols) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} sentence\n# @param {Integer} rows\n# @param {Integer} cols\n# @return {Integer}\ndef words_typing(sentence, rows, cols)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func wordsTyping(_ sentence: [String], _ rows: Int, _ cols: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func wordsTyping(sentence []string, rows int, cols int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def wordsTyping(sentence: Array[String], rows: Int, cols: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun wordsTyping(sentence: Array, rows: Int, cols: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn words_typing(sentence: Vec, rows: i32, cols: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $sentence\n * @param Integer $rows\n * @param Integer $cols\n * @return Integer\n */\n function wordsTyping($sentence, $rows, $cols) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function wordsTyping(sentence: string[], rows: number, cols: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (words-typing sentence rows cols)\n (-> (listof string?) exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0418](https://leetcode-cn.com/problems/sentence-screen-fitting)", "[\u5c4f\u5e55\u53ef\u663e\u793a\u53e5\u5b50\u7684\u6570\u91cf](/solution/0400-0499/0418.Sentence%20Screen%20Fitting/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0418](https://leetcode.com/problems/sentence-screen-fitting)", "[Sentence Screen Fitting](/solution/0400-0499/0418.Sentence%20Screen%20Fitting/README_EN.md)", "`Dynamic Programming`", "Medium", "\ud83d\udd12"]}, {"question_id": "0417", "frontend_question_id": "0417", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/pacific-atlantic-water-flow", "url_en": "https://leetcode.com/problems/pacific-atlantic-water-flow", "relative_path_cn": "/solution/0400-0499/0417.Pacific%20Atlantic%20Water%20Flow/README.md", "relative_path_en": "/solution/0400-0499/0417.Pacific%20Atlantic%20Water%20Flow/README_EN.md", "title_cn": "\u592a\u5e73\u6d0b\u5927\u897f\u6d0b\u6c34\u6d41\u95ee\u9898", "title_en": "Pacific Atlantic Water Flow", "question_title_slug": "pacific-atlantic-water-flow", "content_en": "

    You are given an m x n integer matrix heights representing the height of each unit cell in a continent. The Pacific ocean touches the continent's left and top edges, and the Atlantic ocean touches the continent's right and bottom edges.

    \n\n

    Water can only flow in four directions: up, down, left, and right. Water flows from a cell to an adjacent one with an equal or lower height.

    \n\n

    Return a list of grid coordinates where water can flow to both the Pacific and Atlantic oceans.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: heights = [[1,2,2,3,5],[3,2,3,4,4],[2,4,5,3,1],[6,7,1,4,5],[5,1,1,2,4]]\nOutput: [[0,4],[1,3],[1,4],[2,2],[3,0],[3,1],[4,0]]\n
    \n\n

    Example 2:

    \n\n
    \nInput: heights = [[2,1],[1,2]]\nOutput: [[0,0],[0,1],[1,0],[1,1]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == heights.length
    • \n\t
    • n == heights[i].length
    • \n\t
    • 1 <= m, n <= 200
    • \n\t
    • 0 <= heights[i][j] <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a m x n \u7684\u975e\u8d1f\u6574\u6570\u77e9\u9635\u6765\u8868\u793a\u4e00\u7247\u5927\u9646\u4e0a\u5404\u4e2a\u5355\u5143\u683c\u7684\u9ad8\u5ea6\u3002“\u592a\u5e73\u6d0b”\u5904\u4e8e\u5927\u9646\u7684\u5de6\u8fb9\u754c\u548c\u4e0a\u8fb9\u754c\uff0c\u800c“\u5927\u897f\u6d0b”\u5904\u4e8e\u5927\u9646\u7684\u53f3\u8fb9\u754c\u548c\u4e0b\u8fb9\u754c\u3002

    \n\n

    \u89c4\u5b9a\u6c34\u6d41\u53ea\u80fd\u6309\u7167\u4e0a\u3001\u4e0b\u3001\u5de6\u3001\u53f3\u56db\u4e2a\u65b9\u5411\u6d41\u52a8\uff0c\u4e14\u53ea\u80fd\u4ece\u9ad8\u5230\u4f4e\u6216\u8005\u5728\u540c\u7b49\u9ad8\u5ea6\u4e0a\u6d41\u52a8\u3002

    \n\n

    \u8bf7\u627e\u51fa\u90a3\u4e9b\u6c34\u6d41\u65e2\u53ef\u4ee5\u6d41\u52a8\u5230“\u592a\u5e73\u6d0b”\uff0c\u53c8\u80fd\u6d41\u52a8\u5230“\u5927\u897f\u6d0b”\u7684\u9646\u5730\u5355\u5143\u7684\u5750\u6807\u3002

    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. \u8f93\u51fa\u5750\u6807\u7684\u987a\u5e8f\u4e0d\u91cd\u8981
    2. \n\t
    3. m \u548c n \u90fd\u5c0f\u4e8e150
    4. \n
    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n

     

    \n\n
    \n\u7ed9\u5b9a\u4e0b\u9762\u7684 5x5 \u77e9\u9635:\n\n  \u592a\u5e73\u6d0b ~   ~   ~   ~   ~ \n       ~  1   2   2   3  (5) *\n       ~  3   2   3  (4) (4) *\n       ~  2   4  (5)  3   1  *\n       ~ (6) (7)  1   4   5  *\n       ~ (5)  1   1   2   4  *\n          *   *   *   *   * \u5927\u897f\u6d0b\n\n\u8fd4\u56de:\n\n[[0, 4], [1, 3], [1, 4], [2, 2], [3, 0], [3, 1], [4, 0]] (\u4e0a\u56fe\u4e2d\u5e26\u62ec\u53f7\u7684\u5355\u5143).\n
    \n\n

     

    \n", "tags_en": ["Depth-first Search", "Breadth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> pacificAtlantic(vector>& heights) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> pacificAtlantic(int[][] heights) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def pacificAtlantic(self, heights):\n \"\"\"\n :type heights: List[List[int]]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def pacificAtlantic(self, heights: List[List[int]]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** pacificAtlantic(int** heights, int heightsSize, int* heightsColSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> PacificAtlantic(int[][] heights) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} heights\n * @return {number[][]}\n */\nvar pacificAtlantic = function(heights) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} heights\n# @return {Integer[][]}\ndef pacific_atlantic(heights)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func pacificAtlantic(_ heights: [[Int]]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func pacificAtlantic(heights [][]int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def pacificAtlantic(heights: Array[Array[Int]]): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun pacificAtlantic(heights: Array): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn pacific_atlantic(heights: Vec>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $heights\n * @return Integer[][]\n */\n function pacificAtlantic($heights) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function pacificAtlantic(heights: number[][]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (pacific-atlantic heights)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0417](https://leetcode-cn.com/problems/pacific-atlantic-water-flow)", "[\u592a\u5e73\u6d0b\u5927\u897f\u6d0b\u6c34\u6d41\u95ee\u9898](/solution/0400-0499/0417.Pacific%20Atlantic%20Water%20Flow/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0417](https://leetcode.com/problems/pacific-atlantic-water-flow)", "[Pacific Atlantic Water Flow](/solution/0400-0499/0417.Pacific%20Atlantic%20Water%20Flow/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`", "Medium", ""]}, {"question_id": "0416", "frontend_question_id": "0416", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/partition-equal-subset-sum", "url_en": "https://leetcode.com/problems/partition-equal-subset-sum", "relative_path_cn": "/solution/0400-0499/0416.Partition%20Equal%20Subset%20Sum/README.md", "relative_path_en": "/solution/0400-0499/0416.Partition%20Equal%20Subset%20Sum/README_EN.md", "title_cn": "\u5206\u5272\u7b49\u548c\u5b50\u96c6", "title_en": "Partition Equal Subset Sum", "question_title_slug": "partition-equal-subset-sum", "content_en": "

    Given a non-empty array nums containing only positive integers, find if the array can be partitioned into two subsets such that the sum of elements in both subsets is equal.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,5,11,5]\nOutput: true\nExplanation: The array can be partitioned as [1, 5, 5] and [11].\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,2,3,5]\nOutput: false\nExplanation: The array cannot be partitioned into equal sum subsets.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 200
    • \n\t
    • 1 <= nums[i] <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a \u53ea\u5305\u542b\u6b63\u6574\u6570 \u7684 \u975e\u7a7a \u6570\u7ec4\u00a0nums \u3002\u8bf7\u4f60\u5224\u65ad\u662f\u5426\u53ef\u4ee5\u5c06\u8fd9\u4e2a\u6570\u7ec4\u5206\u5272\u6210\u4e24\u4e2a\u5b50\u96c6\uff0c\u4f7f\u5f97\u4e24\u4e2a\u5b50\u96c6\u7684\u5143\u7d20\u548c\u76f8\u7b49\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,5,11,5]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u6570\u7ec4\u53ef\u4ee5\u5206\u5272\u6210 [1, 5, 5] \u548c [11] \u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,3,5]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u6570\u7ec4\u4e0d\u80fd\u5206\u5272\u6210\u4e24\u4e2a\u5143\u7d20\u548c\u76f8\u7b49\u7684\u5b50\u96c6\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 200
    • \n\t
    • 1 <= nums[i] <= 100
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canPartition(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canPartition(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canPartition(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canPartition(self, nums: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canPartition(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanPartition(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {boolean}\n */\nvar canPartition = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Boolean}\ndef can_partition(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canPartition(_ nums: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canPartition(nums []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canPartition(nums: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canPartition(nums: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_partition(nums: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Boolean\n */\n function canPartition($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canPartition(nums: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-partition nums)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0416](https://leetcode-cn.com/problems/partition-equal-subset-sum)", "[\u5206\u5272\u7b49\u548c\u5b50\u96c6](/solution/0400-0499/0416.Partition%20Equal%20Subset%20Sum/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0416](https://leetcode.com/problems/partition-equal-subset-sum)", "[Partition Equal Subset Sum](/solution/0400-0499/0416.Partition%20Equal%20Subset%20Sum/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0415", "frontend_question_id": "0415", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/add-strings", "url_en": "https://leetcode.com/problems/add-strings", "relative_path_cn": "/solution/0400-0499/0415.Add%20Strings/README.md", "relative_path_en": "/solution/0400-0499/0415.Add%20Strings/README_EN.md", "title_cn": "\u5b57\u7b26\u4e32\u76f8\u52a0", "title_en": "Add Strings", "question_title_slug": "add-strings", "content_en": "

    Given two non-negative integers, num1 and num2 represented as string, return the sum of num1 and num2 as a string.

    \n\n

    You must solve the problem without using any built-in library for handling large integers (such as BigInteger). You must also not convert the inputs to integers directly.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: num1 = "11", num2 = "123"\nOutput: "134"\n
    \n\n

    Example 2:

    \n\n
    \nInput: num1 = "456", num2 = "77"\nOutput: "533"\n
    \n\n

    Example 3:

    \n\n
    \nInput: num1 = "0", num2 = "0"\nOutput: "0"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= num1.length, num2.length <= 104
    • \n\t
    • num1 and num2 consist of only digits.
    • \n\t
    • num1 and num2 don't have any leading zeros except for the zero itself.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u5b57\u7b26\u4e32\u5f62\u5f0f\u7684\u975e\u8d1f\u6574\u6570 num1 \u548cnum2 \uff0c\u8ba1\u7b97\u5b83\u4eec\u7684\u548c\u3002

    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. num1 \u548cnum2 \u7684\u957f\u5ea6\u90fd\u5c0f\u4e8e 5100
    2. \n\t
    3. num1 \u548cnum2 \u90fd\u53ea\u5305\u542b\u6570\u5b57 0-9
    4. \n\t
    5. num1 \u548cnum2 \u90fd\u4e0d\u5305\u542b\u4efb\u4f55\u524d\u5bfc\u96f6
    6. \n\t
    7. \u4f60\u4e0d\u80fd\u4f7f\u7528\u4efb\u4f55\u5167\u5efa BigInteger \u5e93\uff0c \u4e5f\u4e0d\u80fd\u76f4\u63a5\u5c06\u8f93\u5165\u7684\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u6574\u6570\u5f62\u5f0f
    8. \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string addStrings(string num1, string num2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String addStrings(String num1, String num2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def addStrings(self, num1, num2):\n \"\"\"\n :type num1: str\n :type num2: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def addStrings(self, num1: str, num2: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * addStrings(char * num1, char * num2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string AddStrings(string num1, string num2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} num1\n * @param {string} num2\n * @return {string}\n */\nvar addStrings = function(num1, num2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} num1\n# @param {String} num2\n# @return {String}\ndef add_strings(num1, num2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func addStrings(_ num1: String, _ num2: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func addStrings(num1 string, num2 string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def addStrings(num1: String, num2: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun addStrings(num1: String, num2: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn add_strings(num1: String, num2: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $num1\n * @param String $num2\n * @return String\n */\n function addStrings($num1, $num2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function addStrings(num1: string, num2: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (add-strings num1 num2)\n (-> string? string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0415](https://leetcode-cn.com/problems/add-strings)", "[\u5b57\u7b26\u4e32\u76f8\u52a0](/solution/0400-0499/0415.Add%20Strings/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0415](https://leetcode.com/problems/add-strings)", "[Add Strings](/solution/0400-0499/0415.Add%20Strings/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "0414", "frontend_question_id": "0414", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/third-maximum-number", "url_en": "https://leetcode.com/problems/third-maximum-number", "relative_path_cn": "/solution/0400-0499/0414.Third%20Maximum%20Number/README.md", "relative_path_en": "/solution/0400-0499/0414.Third%20Maximum%20Number/README_EN.md", "title_cn": "\u7b2c\u4e09\u5927\u7684\u6570", "title_en": "Third Maximum Number", "question_title_slug": "third-maximum-number", "content_en": "

    Given integer array nums, return the third maximum number in this array. If the third maximum does not exist, return the maximum number.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [3,2,1]\nOutput: 1\nExplanation: The third maximum is 1.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,2]\nOutput: 2\nExplanation: The third maximum does not exist, so the maximum (2) is returned instead.\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [2,2,3,1]\nOutput: 1\nExplanation: Note that the third maximum here means the third maximum distinct number.\nBoth numbers with value 2 are both considered as second maximum.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 104
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n
    \n\n

     

    \nFollow up: Can you find an O(n) solution?", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u975e\u7a7a\u6570\u7ec4\uff0c\u8fd4\u56de\u6b64\u6570\u7ec4\u4e2d \u7b2c\u4e09\u5927\u7684\u6570 \u3002\u5982\u679c\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u6570\u7ec4\u4e2d\u6700\u5927\u7684\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[3, 2, 1]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u7b2c\u4e09\u5927\u7684\u6570\u662f 1 \u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[1, 2]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u7b2c\u4e09\u5927\u7684\u6570\u4e0d\u5b58\u5728, \u6240\u4ee5\u8fd4\u56de\u6700\u5927\u7684\u6570 2 \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[2, 2, 3, 1]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u6ce8\u610f\uff0c\u8981\u6c42\u8fd4\u56de\u7b2c\u4e09\u5927\u7684\u6570\uff0c\u662f\u6307\u5728\u6240\u6709\u4e0d\u540c\u6570\u5b57\u4e2d\u6392\u7b2c\u4e09\u5927\u7684\u6570\u3002\n\u6b64\u4f8b\u4e2d\u5b58\u5728\u4e24\u4e2a\u503c\u4e3a 2 \u7684\u6570\uff0c\u5b83\u4eec\u90fd\u6392\u7b2c\u4e8c\u3002\u5728\u6240\u6709\u4e0d\u540c\u6570\u5b57\u4e2d\u6392\u7b2c\u4e09\u5927\u7684\u6570\u4e3a 1 \u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 104
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u80fd\u8bbe\u8ba1\u4e00\u4e2a\u65f6\u95f4\u590d\u6742\u5ea6 O(n) \u7684\u89e3\u51b3\u65b9\u6848\u5417\uff1f

    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int thirdMax(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int thirdMax(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def thirdMax(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def thirdMax(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint thirdMax(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ThirdMax(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar thirdMax = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef third_max(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func thirdMax(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func thirdMax(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def thirdMax(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun thirdMax(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn third_max(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function thirdMax($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function thirdMax(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (third-max nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0414](https://leetcode-cn.com/problems/third-maximum-number)", "[\u7b2c\u4e09\u5927\u7684\u6570](/solution/0400-0499/0414.Third%20Maximum%20Number/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0414](https://leetcode.com/problems/third-maximum-number)", "[Third Maximum Number](/solution/0400-0499/0414.Third%20Maximum%20Number/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0413", "frontend_question_id": "0413", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/arithmetic-slices", "url_en": "https://leetcode.com/problems/arithmetic-slices", "relative_path_cn": "/solution/0400-0499/0413.Arithmetic%20Slices/README.md", "relative_path_en": "/solution/0400-0499/0413.Arithmetic%20Slices/README_EN.md", "title_cn": "\u7b49\u5dee\u6570\u5217\u5212\u5206", "title_en": "Arithmetic Slices", "question_title_slug": "arithmetic-slices", "content_en": "

    An integer array is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.

    \n\n
      \n\t
    • For example, [1,3,5,7,9], [7,7,7,7], and [3,-1,-5,-9] are arithmetic sequences.
    • \n
    \n\n

    Given an integer array nums, return the number of arithmetic subarrays of nums.

    \n\n

    A subarray is a contiguous subsequence of the array.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,3,4]\nOutput: 3\nExplanation: We have 3 arithmetic slices in nums: [1, 2, 3], [2, 3, 4] and [1,2,3,4] itself.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 5000
    • \n\t
    • -1000 <= nums[i] <= 1000
    • \n
    \n", "content_cn": "

    \u5982\u679c\u4e00\u4e2a\u6570\u5217\u81f3\u5c11\u6709\u4e09\u4e2a\u5143\u7d20\uff0c\u5e76\u4e14\u4efb\u610f\u4e24\u4e2a\u76f8\u90bb\u5143\u7d20\u4e4b\u5dee\u76f8\u540c\uff0c\u5219\u79f0\u8be5\u6570\u5217\u4e3a\u7b49\u5dee\u6570\u5217\u3002

    \n\n

    \u4f8b\u5982\uff0c\u4ee5\u4e0b\u6570\u5217\u4e3a\u7b49\u5dee\u6570\u5217:

    \n\n
    \n1, 3, 5, 7, 9\n7, 7, 7, 7\n3, -1, -5, -9
    \n\n

    \u4ee5\u4e0b\u6570\u5217\u4e0d\u662f\u7b49\u5dee\u6570\u5217\u3002

    \n\n
    \n1, 1, 2, 5, 7
    \n\n

     

    \n\n

    \u6570\u7ec4 A \u5305\u542b N \u4e2a\u6570\uff0c\u4e14\u7d22\u5f15\u4ece0\u5f00\u59cb\u3002\u6570\u7ec4 A \u7684\u4e00\u4e2a\u5b50\u6570\u7ec4\u5212\u5206\u4e3a\u6570\u7ec4 (P, Q)\uff0cP \u4e0e Q \u662f\u6574\u6570\u4e14\u6ee1\u8db3 0<=P<Q<N \u3002

    \n\n

    \u5982\u679c\u6ee1\u8db3\u4ee5\u4e0b\u6761\u4ef6\uff0c\u5219\u79f0\u5b50\u6570\u7ec4(P, Q)\u4e3a\u7b49\u5dee\u6570\u7ec4\uff1a

    \n\n

    \u5143\u7d20 A[P], A[p + 1], ..., A[Q - 1], A[Q] \u662f\u7b49\u5dee\u7684\u3002\u5e76\u4e14 P + 1 < Q \u3002

    \n\n

    \u51fd\u6570\u8981\u8fd4\u56de\u6570\u7ec4 A \u4e2d\u6240\u6709\u4e3a\u7b49\u5dee\u6570\u7ec4\u7684\u5b50\u6570\u7ec4\u4e2a\u6570\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b:

    \n\n
    \nA = [1, 2, 3, 4]\n\n\u8fd4\u56de: 3, A \u4e2d\u6709\u4e09\u4e2a\u5b50\u7b49\u5dee\u6570\u7ec4: [1, 2, 3], [2, 3, 4] \u4ee5\u53ca\u81ea\u8eab [1, 2, 3, 4]\u3002\n
    \n", "tags_en": ["Math", "Dynamic Programming"], "tags_cn": ["\u6570\u5b66", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numberOfArithmeticSlices(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numberOfArithmeticSlices(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numberOfArithmeticSlices(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numberOfArithmeticSlices(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numberOfArithmeticSlices(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumberOfArithmeticSlices(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar numberOfArithmeticSlices = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef number_of_arithmetic_slices(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numberOfArithmeticSlices(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numberOfArithmeticSlices(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numberOfArithmeticSlices(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numberOfArithmeticSlices(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn number_of_arithmetic_slices(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function numberOfArithmeticSlices($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numberOfArithmeticSlices(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (number-of-arithmetic-slices nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0413](https://leetcode-cn.com/problems/arithmetic-slices)", "[\u7b49\u5dee\u6570\u5217\u5212\u5206](/solution/0400-0499/0413.Arithmetic%20Slices/README.md)", "`\u6570\u5b66`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0413](https://leetcode.com/problems/arithmetic-slices)", "[Arithmetic Slices](/solution/0400-0499/0413.Arithmetic%20Slices/README_EN.md)", "`Math`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0412", "frontend_question_id": "0412", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/fizz-buzz", "url_en": "https://leetcode.com/problems/fizz-buzz", "relative_path_cn": "/solution/0400-0499/0412.Fizz%20Buzz/README.md", "relative_path_en": "/solution/0400-0499/0412.Fizz%20Buzz/README_EN.md", "title_cn": "Fizz Buzz", "title_en": "Fizz Buzz", "question_title_slug": "fizz-buzz", "content_en": "

    Given an integer n, return a string array answer (1-indexed) where:

    \n\n
      \n\t
    • answer[i] == "FizzBuzz" if i is divisible by 3 and 5.
    • \n\t
    • answer[i] == "Fizz" if i is divisible by 3.
    • \n\t
    • answer[i] == "Buzz" if i is divisible by 5.
    • \n\t
    • answer[i] == i if non of the above conditions are true.
    • \n
    \n\n

     

    \n

    Example 1:

    \n
    Input: n = 3\nOutput: [\"1\",\"2\",\"Fizz\"]\n

    Example 2:

    \n
    Input: n = 5\nOutput: [\"1\",\"2\",\"Fizz\",\"4\",\"Buzz\"]\n

    Example 3:

    \n
    Input: n = 15\nOutput: [\"1\",\"2\",\"Fizz\",\"4\",\"Buzz\",\"Fizz\",\"7\",\"8\",\"Fizz\",\"Buzz\",\"11\",\"Fizz\",\"13\",\"14\",\"FizzBuzz\"]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 104
    • \n
    \n", "content_cn": "

    \u5199\u4e00\u4e2a\u7a0b\u5e8f\uff0c\u8f93\u51fa\u4ece 1 \u5230 n \u6570\u5b57\u7684\u5b57\u7b26\u4e32\u8868\u793a\u3002

    \n\n

    1. \u5982\u679c \u662f3\u7684\u500d\u6570\uff0c\u8f93\u51fa“Fizz”\uff1b

    \n\n

    2. \u5982\u679c \u662f5\u7684\u500d\u6570\uff0c\u8f93\u51fa“Buzz”\uff1b

    \n\n

    3.\u5982\u679c \u540c\u65f6\u662f3\u548c5\u7684\u500d\u6570\uff0c\u8f93\u51fa “FizzBuzz”\u3002

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    n = 15,\n\n\u8fd4\u56de:\n[\n    "1",\n    "2",\n    "Fizz",\n    "4",\n    "Buzz",\n    "Fizz",\n    "7",\n    "8",\n    "Fizz",\n    "Buzz",\n    "11",\n    "Fizz",\n    "13",\n    "14",\n    "FizzBuzz"\n]\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector fizzBuzz(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List fizzBuzz(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def fizzBuzz(self, n):\n \"\"\"\n :type n: int\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def fizzBuzz(self, n: int) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** fizzBuzz(int n, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList FizzBuzz(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {string[]}\n */\nvar fizzBuzz = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {String[]}\ndef fizz_buzz(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func fizzBuzz(_ n: Int) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func fizzBuzz(n int) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def fizzBuzz(n: Int): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun fizzBuzz(n: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn fizz_buzz(n: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return String[]\n */\n function fizzBuzz($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function fizzBuzz(n: number): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (fizz-buzz n)\n (-> exact-integer? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0412](https://leetcode-cn.com/problems/fizz-buzz)", "[Fizz Buzz](/solution/0400-0499/0412.Fizz%20Buzz/README.md)", "", "\u7b80\u5355", ""], "md_table_row_en": ["[0412](https://leetcode.com/problems/fizz-buzz)", "[Fizz Buzz](/solution/0400-0499/0412.Fizz%20Buzz/README_EN.md)", "", "Easy", ""]}, {"question_id": "0411", "frontend_question_id": "0411", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/minimum-unique-word-abbreviation", "url_en": "https://leetcode.com/problems/minimum-unique-word-abbreviation", "relative_path_cn": "/solution/0400-0499/0411.Minimum%20Unique%20Word%20Abbreviation/README.md", "relative_path_en": "/solution/0400-0499/0411.Minimum%20Unique%20Word%20Abbreviation/README_EN.md", "title_cn": "\u6700\u77ed\u72ec\u5360\u5355\u8bcd\u7f29\u5199", "title_en": "Minimum Unique Word Abbreviation", "question_title_slug": "minimum-unique-word-abbreviation", "content_en": "

    A string can be abbreviated by replacing any number of non-adjacent substrings with their lengths. For example, a string such as "substitution" could be abbreviated as (but not limited to):

    \n\n
      \n\t
    • "s10n" ("s ubstitutio n")
    • \n\t
    • "sub4u4" ("sub stit u tion")
    • \n\t
    • "12" ("substitution")
    • \n\t
    • "su3i1u2on" ("su bst i t u ti on")
    • \n\t
    • "substitution" (no substrings replaced)
    • \n
    \n\n

    Note that "s55n" ("s ubsti tutio n") is not a valid abbreviation of "substitution" because the replaced substrings are adjacent.

    \n\n

    The length of an abbreviation is the number of letters that were not replaced plus the number of substrings that were replaced. For example, the abbreviation "s10n" has a length of 3 (2 letters + 1 substring) and "su3i1u2on" has a length of 9 (6 letters + 3 substrings).

    \n\n

    Given a target string target and an array of strings dictionary, return an abbreviation of target with the shortest possible length such that it is not an abbreviation of any string in dictionary. If there are multiple shortest abbreviations, return any of them.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: target = "apple", dictionary = ["blade"]\nOutput: "a4"\nExplanation: The shortest abbreviation of "apple" is "5", but this is also an abbreviation of "blade".\nThe next shortest abbreviations are "a4" and "4e". "4e" is an abbreviation of blade while "a4" is not.\nHence, return "a4".\n
    \n\n

    Example 2:

    \n\n
    \nInput: target = "apple", dictionary = ["blade","plain","amber"]\nOutput: "1p3"\nExplanation: "5" is an abbreviation of both "apple" but also every word in the dictionary.\n"a4" is an abbreviation of "apple" but also "amber".\n"4e" is an abbreviation of "apple" but also "blade".\n"1p3", "2p2", and "3l1" are the next shortest abbreviations of "apple".\nSince none of them are abbreviations of words in the dictionary, returning any of them is correct.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • target.length == m
    • \n\t
    • dictionary.length == n
    • \n\t
    • 1 <= m <= 21
    • \n\t
    • 0 <= n <= 1000
    • \n\t
    • 1 <= dictionary[i] <= 100
    • \n\t
    • log2(n) + m <= 21 if n > 0
    • \n
    \n", "content_cn": "

    \u901a\u8fc7\u5c06\u4efb\u610f\u6570\u91cf\u7684 \u4e0d\u76f8\u90bb \u5b50\u5b57\u7b26\u4e32\u66ff\u6362\u4e3a\u5b83\u4eec\u7684\u957f\u5ea6\uff0c\u53ef\u4ee5\u5b8c\u6210\u5bf9\u5b57\u7b26\u4e32\u7684 \u7f29\u5199 \u3002 \u4f8b\u5982\uff0c\u50cf \"substitution\" \u8fd9\u6837\u7684\u5b57\u7b26\u4e32\u53ef\u4ee5\u7f29\u5199\u4e3a\uff08\u4f46\u4e0d\u9650\u4e8e\uff09\uff1a

    \n\n
      \n\t
    • \"s10n\" (\"s ubstitutio n\")
    • \n\t
    • \"sub4u4\" (\"sub stit u tion\")
    • \n\t
    • \"12\" (\"substitution\")
    • \n\t
    • \"su3i1u2on\" (\"su bst i t u ti on\")
    • \n\t
    • \"substitution\" (\u4e0d\u66ff\u6362\u5b50\u5b57\u7b26\u4e32)
    • \n
    \n\n

    \u6ce8\u610f\uff1a\"s55n\" (\"s ubsti tutio n\") \u4e0d\u662f\u00a0\"substitution\" \u7684\u6709\u6548\u7f29\u5199\u5f62\u5f0f\uff0c\u56e0\u4e3a\u5b83\u8bd5\u56fe\u66ff\u6362\u4e24\u4e2a\u76f8\u90bb\u7684\u5b50\u5b57\u7b26\u4e32\u3002

    \n\n

    \u7f29\u5199\u7684 \u957f\u5ea6 \u662f\u672a\u88ab\u66ff\u6362\u7684\u5b57\u6bcd\u6570\u52a0\u4e0a\u88ab\u66ff\u6362\u7684\u5b57\u7b26\u4e32\u6570\u3002\u4f8b\u5982\uff0c\u7f29\u5199 \"s10n\" \u7684\u957f\u5ea6\u4e3a 3\uff082 \u4e2a\u5b57\u6bcd + 1 \u4e2a\u5b50\u5b57\u7b26\u4e32\uff09\uff0c\u800c \"su3i1u2on\" \u7684\u957f\u5ea6\u4e3a 9\uff086 \u4e2a\u5b57\u6bcd + 3 \u5b50\u5b57\u7b26\u4e32\uff09\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u76ee\u6807\u5b57\u7b26\u4e32 target \u548c\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4 dictionary \u4f5c\u4e3a\u5b57\u5178\uff0c\u4e3a target \u627e\u51fa\u5e76\u8fd4\u56de\u4e00\u4e2a\u00a0\u6700\u77ed \u957f\u5ea6\u7684\u7f29\u5199\u5b57\u7b26\u4e32\uff0c\u540c\u65f6\u8fd9\u4e2a\u7f29\u5199\u5b57\u7b26\u4e32 \u4e0d\u662f \u5b57\u5178\u00a0dictionary \u4e2d\u5176\u4ed6\u5b57\u7b26\u4e32\u7684\u7f29\u5199\u5f62\u5f0f\u3002\u5982\u679c\u6709\u591a\u4e2a\u6709\u6548\u7b54\u6848\uff0c\u53ef\u4ee5\u8fd4\u56de\u5176\u4e2d\u4efb\u610f\u4e00\u4e2a\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1atarget = \"apple\", dictionary = [\"blade\"]\n\u8f93\u51fa\uff1a\"a4\"\n\u89e3\u91ca\uff1a\"apple\" \u7684\u6700\u77ed\u7f29\u5199\u5f62\u5f0f\u4e3a \"5\" \uff0c\u4f46\u8fd9\u4e5f\u662f \"blade\" \u7684\u7f29\u5199\u5f62\u5f0f\u4e4b\u4e00\u3002\n\u4e0b\u4e00\u7ec4\u6700\u77ed\u7f29\u5199\u662f \"a4\" \u548c \"4e\" \uff0c\u5176\u4e2d \"4e\" \u4e5f\u662f \"blade\" \u7684\u7f29\u5199\u5f62\u5f0f\u4e4b\u4e00\uff0c\u800c \"a4\" \u4e0d\u662f\u3002\n\u56e0\u6b64\uff0c\u8fd4\u56de \"a4\" \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1atarget = \"apple\", dictionary = [\"blade\",\"plain\",\"amber\"]\n\u8f93\u51fa\uff1a\"1p3\"\n\u89e3\u91ca\uff1a\"5\" \u540c\u65f6\u662f \"apple\" \u548c\u5b57\u5178\u4e2d\u6240\u6709\u5355\u8bcd\u7684\u7f29\u5199\u5f62\u5f0f\u3002\n\"a4\" \u540c\u65f6\u662f \"apple\" \u548c \"amber\" \u7684\u7f29\u5199\u5f62\u5f0f\u3002\n\"4e\" \u540c\u65f6\u662f \"apple\" \u548c \"blade\" \u7684\u7f29\u5199\u5f62\u5f0f\u3002\n\"1p3\"\u3001\"2p2\" \u548c \"3l1\" \u662f \"apple\" \u7684\u4e0b\u4e00\u7ec4\u6700\u77ed\u7f29\u5199\u5f62\u5f0f\u3002\n\u56e0\u4e3a\u5b83\u4eec\u4e0d\u662f\u5b57\u5178\u4e2d\u5176\u4ed6\u5355\u8bcd\u7684\u7f29\u5199\u5f62\u5f0f\uff0c\u8fd4\u56de\u5176\u4e2d\u4efb\u610f\u4e00\u4e2a\u90fd\u662f\u6b63\u786e\u7684\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • target.length == m
    • \n\t
    • dictionary.length == n
    • \n\t
    • 1 <= m <= 21
    • \n\t
    • 0 <= n <= 1000
    • \n\t
    • 1 <= dictionary[i] <= 100
    • \n\t
    • \u5982\u679c n > 0 \uff0c\u90a3\u4e48 log2(n) + m <= 21
    • \n
    \n\n

    \u00a0

    \n", "tags_en": ["Bit Manipulation", "Backtracking"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string minAbbreviation(string target, vector& dictionary) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String minAbbreviation(String target, String[] dictionary) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minAbbreviation(self, target, dictionary):\n \"\"\"\n :type target: str\n :type dictionary: List[str]\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minAbbreviation(self, target: str, dictionary: List[str]) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * minAbbreviation(char * target, char ** dictionary, int dictionarySize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string MinAbbreviation(string target, string[] dictionary) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} target\n * @param {string[]} dictionary\n * @return {string}\n */\nvar minAbbreviation = function(target, dictionary) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} target\n# @param {String[]} dictionary\n# @return {String}\ndef min_abbreviation(target, dictionary)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minAbbreviation(_ target: String, _ dictionary: [String]) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minAbbreviation(target string, dictionary []string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minAbbreviation(target: String, dictionary: Array[String]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minAbbreviation(target: String, dictionary: Array): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_abbreviation(target: String, dictionary: Vec) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $target\n * @param String[] $dictionary\n * @return String\n */\n function minAbbreviation($target, $dictionary) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minAbbreviation(target: string, dictionary: string[]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-abbreviation target dictionary)\n (-> string? (listof string?) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0411](https://leetcode-cn.com/problems/minimum-unique-word-abbreviation)", "[\u6700\u77ed\u72ec\u5360\u5355\u8bcd\u7f29\u5199](/solution/0400-0499/0411.Minimum%20Unique%20Word%20Abbreviation/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u56de\u6eaf\u7b97\u6cd5`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0411](https://leetcode.com/problems/minimum-unique-word-abbreviation)", "[Minimum Unique Word Abbreviation](/solution/0400-0499/0411.Minimum%20Unique%20Word%20Abbreviation/README_EN.md)", "`Bit Manipulation`,`Backtracking`", "Hard", "\ud83d\udd12"]}, {"question_id": "0410", "frontend_question_id": "0410", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/split-array-largest-sum", "url_en": "https://leetcode.com/problems/split-array-largest-sum", "relative_path_cn": "/solution/0400-0499/0410.Split%20Array%20Largest%20Sum/README.md", "relative_path_en": "/solution/0400-0499/0410.Split%20Array%20Largest%20Sum/README_EN.md", "title_cn": "\u5206\u5272\u6570\u7ec4\u7684\u6700\u5927\u503c", "title_en": "Split Array Largest Sum", "question_title_slug": "split-array-largest-sum", "content_en": "

    Given an array nums which consists of non-negative integers and an integer m, you can split the array into m non-empty continuous subarrays.

    \n\n

    Write an algorithm to minimize the largest sum among these m subarrays.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [7,2,5,10,8], m = 2\nOutput: 18\nExplanation:\nThere are four ways to split nums into two subarrays.\nThe best way is to split it into [7,2,5] and [10,8],\nwhere the largest sum among the two subarrays is only 18.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,2,3,4,5], m = 2\nOutput: 9\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [1,4,4], m = 3\nOutput: 4\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 1000
    • \n\t
    • 0 <= nums[i] <= 106
    • \n\t
    • 1 <= m <= min(50, nums.length)
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\u6570\u7ec4 nums \u548c\u4e00\u4e2a\u6574\u6570\u00a0m \uff0c\u4f60\u9700\u8981\u5c06\u8fd9\u4e2a\u6570\u7ec4\u5206\u6210\u00a0m\u00a0\u4e2a\u975e\u7a7a\u7684\u8fde\u7eed\u5b50\u6570\u7ec4\u3002

    \n\n

    \u8bbe\u8ba1\u4e00\u4e2a\u7b97\u6cd5\u4f7f\u5f97\u8fd9\u00a0m\u00a0\u4e2a\u5b50\u6570\u7ec4\u5404\u81ea\u548c\u7684\u6700\u5927\u503c\u6700\u5c0f\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [7,2,5,10,8], m = 2\n\u8f93\u51fa\uff1a18\n\u89e3\u91ca\uff1a\n\u4e00\u5171\u6709\u56db\u79cd\u65b9\u6cd5\u5c06 nums \u5206\u5272\u4e3a 2 \u4e2a\u5b50\u6570\u7ec4\u3002 \u5176\u4e2d\u6700\u597d\u7684\u65b9\u5f0f\u662f\u5c06\u5176\u5206\u4e3a [7,2,5] \u548c [10,8] \u3002\n\u56e0\u4e3a\u6b64\u65f6\u8fd9\u4e24\u4e2a\u5b50\u6570\u7ec4\u5404\u81ea\u7684\u548c\u7684\u6700\u5927\u503c\u4e3a18\uff0c\u5728\u6240\u6709\u60c5\u51b5\u4e2d\u6700\u5c0f\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,3,4,5], m = 2\n\u8f93\u51fa\uff1a9\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,4,4], m = 3\n\u8f93\u51fa\uff1a4\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 1000
    • \n\t
    • 0 <= nums[i] <= 106
    • \n\t
    • 1 <= m <= min(50, nums.length)
    • \n
    \n", "tags_en": ["Binary Search", "Dynamic Programming"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int splitArray(vector& nums, int m) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int splitArray(int[] nums, int m) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def splitArray(self, nums, m):\n \"\"\"\n :type nums: List[int]\n :type m: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def splitArray(self, nums: List[int], m: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint splitArray(int* nums, int numsSize, int m){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SplitArray(int[] nums, int m) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} m\n * @return {number}\n */\nvar splitArray = function(nums, m) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} m\n# @return {Integer}\ndef split_array(nums, m)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func splitArray(_ nums: [Int], _ m: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func splitArray(nums []int, m int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def splitArray(nums: Array[Int], m: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun splitArray(nums: IntArray, m: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn split_array(nums: Vec, m: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $m\n * @return Integer\n */\n function splitArray($nums, $m) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function splitArray(nums: number[], m: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (split-array nums m)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0410](https://leetcode-cn.com/problems/split-array-largest-sum)", "[\u5206\u5272\u6570\u7ec4\u7684\u6700\u5927\u503c](/solution/0400-0499/0410.Split%20Array%20Largest%20Sum/README.md)", "`\u4e8c\u5206\u67e5\u627e`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0410](https://leetcode.com/problems/split-array-largest-sum)", "[Split Array Largest Sum](/solution/0400-0499/0410.Split%20Array%20Largest%20Sum/README_EN.md)", "`Binary Search`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0409", "frontend_question_id": "0409", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-palindrome", "url_en": "https://leetcode.com/problems/longest-palindrome", "relative_path_cn": "/solution/0400-0499/0409.Longest%20Palindrome/README.md", "relative_path_en": "/solution/0400-0499/0409.Longest%20Palindrome/README_EN.md", "title_cn": "\u6700\u957f\u56de\u6587\u4e32", "title_en": "Longest Palindrome", "question_title_slug": "longest-palindrome", "content_en": "

    Given a string s which consists of lowercase or uppercase letters, return the length of the longest palindrome that can be built with those letters.

    \n\n

    Letters are case sensitive, for example, "Aa" is not considered a palindrome here.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "abccccdd"\nOutput: 7\nExplanation:\nOne longest palindrome that can be built is "dccaccd", whose length is 7.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "a"\nOutput: 1\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "bb"\nOutput: 2\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 2000
    • \n\t
    • s consists of lowercase and/or uppercase English letters only.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5305\u542b\u5927\u5199\u5b57\u6bcd\u548c\u5c0f\u5199\u5b57\u6bcd\u7684\u5b57\u7b26\u4e32\uff0c\u627e\u5230\u901a\u8fc7\u8fd9\u4e9b\u5b57\u6bcd\u6784\u9020\u6210\u7684\u6700\u957f\u7684\u56de\u6587\u4e32\u3002

    \n\n

    \u5728\u6784\u9020\u8fc7\u7a0b\u4e2d\uff0c\u8bf7\u6ce8\u610f\u533a\u5206\u5927\u5c0f\u5199\u3002\u6bd4\u5982 "Aa" \u4e0d\u80fd\u5f53\u505a\u4e00\u4e2a\u56de\u6587\u5b57\u7b26\u4e32\u3002

    \n\n

    \u6ce8\u610f:
    \n\u5047\u8bbe\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u4e0d\u4f1a\u8d85\u8fc7 1010\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165:\n"abccccdd"\n\n\u8f93\u51fa:\n7\n\n\u89e3\u91ca:\n\u6211\u4eec\u53ef\u4ee5\u6784\u9020\u7684\u6700\u957f\u7684\u56de\u6587\u4e32\u662f"dccaccd", \u5b83\u7684\u957f\u5ea6\u662f 7\u3002\n
    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int longestPalindrome(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int longestPalindrome(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestPalindrome(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestPalindrome(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint longestPalindrome(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LongestPalindrome(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar longestPalindrome = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef longest_palindrome(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestPalindrome(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestPalindrome(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestPalindrome(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestPalindrome(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_palindrome(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function longestPalindrome($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestPalindrome(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-palindrome s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0409](https://leetcode-cn.com/problems/longest-palindrome)", "[\u6700\u957f\u56de\u6587\u4e32](/solution/0400-0499/0409.Longest%20Palindrome/README.md)", "`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0409](https://leetcode.com/problems/longest-palindrome)", "[Longest Palindrome](/solution/0400-0499/0409.Longest%20Palindrome/README_EN.md)", "`Hash Table`", "Easy", ""]}, {"question_id": "0408", "frontend_question_id": "0408", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/valid-word-abbreviation", "url_en": "https://leetcode.com/problems/valid-word-abbreviation", "relative_path_cn": "/solution/0400-0499/0408.Valid%20Word%20Abbreviation/README.md", "relative_path_en": "/solution/0400-0499/0408.Valid%20Word%20Abbreviation/README_EN.md", "title_cn": "\u6709\u6548\u5355\u8bcd\u7f29\u5199", "title_en": "Valid Word Abbreviation", "question_title_slug": "valid-word-abbreviation", "content_en": "

    A string can be abbreviated by replacing any number of non-adjacent substrings with their lengths. For example, a string such as "substitution" could be abbreviated as (but not limited to):

    \n\n
      \n\t
    • "s10n" ("s ubstitutio n")
    • \n\t
    • "sub4u4" ("sub stit u tion")
    • \n\t
    • "12" ("substitution")
    • \n\t
    • "su3i1u2on" ("su bst i t u ti on")
    • \n\t
    • "substitution" (no substrings replaced)
    • \n
    \n\n

    Note that "s55n" ("s ubsti tutio n") is not a valid abbreviation of "substitution" because the replaced substrings are adjacent.

    \n\n

    Given a string s and an abbreviation abbr, return whether the string matches with the given abbreviation.

    \n\n

     

    \n

    Example 1:

    \n
    Input: word = \"internationalization\", abbr = \"i12iz4n\"\nOutput: true\n

    Example 2:

    \n
    Input: word = \"apple\", abbr = \"a2e\"\nOutput: false\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= word.length, abbr.length <= 20
    • \n\t
    • word consists of only lowercase English letters.
    • \n\t
    • abbr consists of lowercase English letters and digits.
    • \n
    \n", "content_cn": "

    \u7ed9\u4e00\u4e2a \u975e\u7a7a \u5b57\u7b26\u4e32 s \u548c\u4e00\u4e2a\u5355\u8bcd\u7f29\u5199 abbr \uff0c\u5224\u65ad\u8fd9\u4e2a\u7f29\u5199\u662f\u5426\u53ef\u4ee5\u662f\u7ed9\u5b9a\u5355\u8bcd\u7684\u7f29\u5199\u3002

    \n\n

    \u5b57\u7b26\u4e32 "word" \u7684\u6240\u6709\u6709\u6548\u7f29\u5199\u4e3a\uff1a

    \n\n
    ["word", "1ord", "w1rd", "wo1d", "wor1", "2rd", "w2d", "wo2", "1o1d", "1or1", "w1r1", "1o2", "2r1", "3d", "w3", "4"]
    \n\n

    \u6ce8\u610f\u5355\u8bcd "word" \u7684\u6240\u6709\u6709\u6548\u7f29\u5199\u4ec5\u5305\u542b\u4ee5\u4e0a\u8fd9\u4e9b\u3002\u4efb\u4f55\u5176\u4ed6\u7684\u5b57\u7b26\u4e32\u90fd\u4e0d\u662f "word" \u7684\u6709\u6548\u7f29\u5199\u3002

    \n\n

    \u6ce8\u610f:
    \n\u5047\u8bbe\u5b57\u7b26\u4e32 s \u4ec5\u5305\u542b\u5c0f\u5199\u5b57\u6bcd\u4e14 abbr \u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd\u548c\u6570\u5b57\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u7ed9\u5b9a s = "internationalization", abbr = "i12iz4n":\n\n\u51fd\u6570\u8fd4\u56de true.\n
    \n\n

     

    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u7ed9\u5b9a s = "apple", abbr = "a2e":\n\n\u51fd\u6570\u8fd4\u56de false.\n
    \n\n

     

    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool validWordAbbreviation(string word, string abbr) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean validWordAbbreviation(String word, String abbr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def validWordAbbreviation(self, word, abbr):\n \"\"\"\n :type word: str\n :type abbr: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def validWordAbbreviation(self, word: str, abbr: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool validWordAbbreviation(char * word, char * abbr){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool ValidWordAbbreviation(string word, string abbr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} word\n * @param {string} abbr\n * @return {boolean}\n */\nvar validWordAbbreviation = function(word, abbr) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} word\n# @param {String} abbr\n# @return {Boolean}\ndef valid_word_abbreviation(word, abbr)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func validWordAbbreviation(_ word: String, _ abbr: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func validWordAbbreviation(word string, abbr string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def validWordAbbreviation(word: String, abbr: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun validWordAbbreviation(word: String, abbr: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn valid_word_abbreviation(word: String, abbr: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $word\n * @param String $abbr\n * @return Boolean\n */\n function validWordAbbreviation($word, $abbr) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function validWordAbbreviation(word: string, abbr: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (valid-word-abbreviation word abbr)\n (-> string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0408](https://leetcode-cn.com/problems/valid-word-abbreviation)", "[\u6709\u6548\u5355\u8bcd\u7f29\u5199](/solution/0400-0499/0408.Valid%20Word%20Abbreviation/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0408](https://leetcode.com/problems/valid-word-abbreviation)", "[Valid Word Abbreviation](/solution/0400-0499/0408.Valid%20Word%20Abbreviation/README_EN.md)", "`String`", "Easy", "\ud83d\udd12"]}, {"question_id": "0407", "frontend_question_id": "0407", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/trapping-rain-water-ii", "url_en": "https://leetcode.com/problems/trapping-rain-water-ii", "relative_path_cn": "/solution/0400-0499/0407.Trapping%20Rain%20Water%20II/README.md", "relative_path_en": "/solution/0400-0499/0407.Trapping%20Rain%20Water%20II/README_EN.md", "title_cn": "\u63a5\u96e8\u6c34 II", "title_en": "Trapping Rain Water II", "question_title_slug": "trapping-rain-water-ii", "content_en": "

    Given an m x n integer matrix heightMap representing the height of each unit cell in a 2D elevation map, return the volume of water it can trap after raining.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: heightMap = [[1,4,3,1,3,2],[3,2,1,3,2,4],[2,3,3,2,3,1]]\nOutput: 4\nExplanation: After the rain, water is trapped between the blocks.\nWe have two small pounds 1 and 3 units trapped.\nThe total volume of water trapped is 4.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: heightMap = [[3,3,3,3,3],[3,2,2,2,3],[3,2,1,2,3],[3,2,2,2,3],[3,3,3,3,3]]\nOutput: 10\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == heightMap.length
    • \n\t
    • n == heightMap[i].length
    • \n\t
    • 1 <= m, n <= 200
    • \n\t
    • 0 <= heightMap[i][j] <= 2 * 104
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a m x n \u7684\u77e9\u9635\uff0c\u5176\u4e2d\u7684\u503c\u5747\u4e3a\u975e\u8d1f\u6574\u6570\uff0c\u4ee3\u8868\u4e8c\u7ef4\u9ad8\u5ea6\u56fe\u6bcf\u4e2a\u5355\u5143\u7684\u9ad8\u5ea6\uff0c\u8bf7\u8ba1\u7b97\u56fe\u4e2d\u5f62\u72b6\u6700\u591a\u80fd\u63a5\u591a\u5c11\u4f53\u79ef\u7684\u96e8\u6c34\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u7ed9\u51fa\u5982\u4e0b 3x6 \u7684\u9ad8\u5ea6\u56fe:\n[\n  [1,4,3,1,3,2],\n  [3,2,1,3,2,4],\n  [2,3,3,2,3,1]\n]\n\n\u8fd4\u56de 4 \u3002\n
    \n\n

    \n\n

    \u5982\u4e0a\u56fe\u6240\u793a\uff0c\u8fd9\u662f\u4e0b\u96e8\u524d\u7684\u9ad8\u5ea6\u56fe[[1,4,3,1,3,2],[3,2,1,3,2,4],[2,3,3,2,3,1]] \u7684\u72b6\u6001\u3002

    \n\n

     

    \n\n

    \n\n

    \u4e0b\u96e8\u540e\uff0c\u96e8\u6c34\u5c06\u4f1a\u88ab\u5b58\u50a8\u5728\u8fd9\u4e9b\u65b9\u5757\u4e2d\u3002\u603b\u7684\u63a5\u96e8\u6c34\u91cf\u662f4\u3002

    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= m, n <= 110
    • \n\t
    • 0 <= heightMap[i][j] <= 20000
    • \n
    \n", "tags_en": ["Heap", "Breadth-first Search"], "tags_cn": ["\u5806", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int trapRainWater(vector>& heightMap) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int trapRainWater(int[][] heightMap) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def trapRainWater(self, heightMap):\n \"\"\"\n :type heightMap: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def trapRainWater(self, heightMap: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint trapRainWater(int** heightMap, int heightMapSize, int* heightMapColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int TrapRainWater(int[][] heightMap) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} heightMap\n * @return {number}\n */\nvar trapRainWater = function(heightMap) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} height_map\n# @return {Integer}\ndef trap_rain_water(height_map)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func trapRainWater(_ heightMap: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func trapRainWater(heightMap [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def trapRainWater(heightMap: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun trapRainWater(heightMap: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn trap_rain_water(height_map: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $heightMap\n * @return Integer\n */\n function trapRainWater($heightMap) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function trapRainWater(heightMap: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (trap-rain-water heightMap)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0407](https://leetcode-cn.com/problems/trapping-rain-water-ii)", "[\u63a5\u96e8\u6c34 II](/solution/0400-0499/0407.Trapping%20Rain%20Water%20II/README.md)", "`\u5806`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[0407](https://leetcode.com/problems/trapping-rain-water-ii)", "[Trapping Rain Water II](/solution/0400-0499/0407.Trapping%20Rain%20Water%20II/README_EN.md)", "`Heap`,`Breadth-first Search`", "Hard", ""]}, {"question_id": "0406", "frontend_question_id": "0406", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/queue-reconstruction-by-height", "url_en": "https://leetcode.com/problems/queue-reconstruction-by-height", "relative_path_cn": "/solution/0400-0499/0406.Queue%20Reconstruction%20by%20Height/README.md", "relative_path_en": "/solution/0400-0499/0406.Queue%20Reconstruction%20by%20Height/README_EN.md", "title_cn": "\u6839\u636e\u8eab\u9ad8\u91cd\u5efa\u961f\u5217", "title_en": "Queue Reconstruction by Height", "question_title_slug": "queue-reconstruction-by-height", "content_en": "

    You are given an array of people, people, which are the attributes of some people in a queue (not necessarily in order). Each people[i] = [hi, ki] represents the ith person of height hi with exactly ki other people in front who have a height greater than or equal to hi.

    \n\n

    Reconstruct and return the queue that is represented by the input array people. The returned queue should be formatted as an array queue, where queue[j] = [hj, kj] is the attributes of the jth person in the queue (queue[0] is the person at the front of the queue).

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: people = [[7,0],[4,4],[7,1],[5,0],[6,1],[5,2]]\nOutput: [[5,0],[7,0],[5,2],[6,1],[4,4],[7,1]]\nExplanation:\nPerson 0 has height 5 with no other people taller or the same height in front.\nPerson 1 has height 7 with no other people taller or the same height in front.\nPerson 2 has height 5 with two persons taller or the same height in front, which is person 0 and 1.\nPerson 3 has height 6 with one person taller or the same height in front, which is person 1.\nPerson 4 has height 4 with four people taller or the same height in front, which are people 0, 1, 2, and 3.\nPerson 5 has height 7 with one person taller or the same height in front, which is person 1.\nHence [[5,0],[7,0],[5,2],[6,1],[4,4],[7,1]] is the reconstructed queue.\n
    \n\n

    Example 2:

    \n\n
    \nInput: people = [[6,0],[5,0],[4,0],[3,2],[2,2],[1,4]]\nOutput: [[4,0],[5,0],[2,2],[3,2],[1,4],[6,0]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= people.length <= 2000
    • \n\t
    • 0 <= hi <= 106
    • \n\t
    • 0 <= ki < people.length
    • \n\t
    • It is guaranteed that the queue can be reconstructed.
    • \n
    \n", "content_cn": "

    \u5047\u8bbe\u6709\u6253\u4e71\u987a\u5e8f\u7684\u4e00\u7fa4\u4eba\u7ad9\u6210\u4e00\u4e2a\u961f\u5217\uff0c\u6570\u7ec4 people \u8868\u793a\u961f\u5217\u4e2d\u4e00\u4e9b\u4eba\u7684\u5c5e\u6027\uff08\u4e0d\u4e00\u5b9a\u6309\u987a\u5e8f\uff09\u3002\u6bcf\u4e2a people[i] = [hi, ki] \u8868\u793a\u7b2c i \u4e2a\u4eba\u7684\u8eab\u9ad8\u4e3a hi \uff0c\u524d\u9762 \u6b63\u597d \u6709 ki \u4e2a\u8eab\u9ad8\u5927\u4e8e\u6216\u7b49\u4e8e hi \u7684\u4eba\u3002

    \n\n

    \u8bf7\u4f60\u91cd\u65b0\u6784\u9020\u5e76\u8fd4\u56de\u8f93\u5165\u6570\u7ec4\u00a0people \u6240\u8868\u793a\u7684\u961f\u5217\u3002\u8fd4\u56de\u7684\u961f\u5217\u5e94\u8be5\u683c\u5f0f\u5316\u4e3a\u6570\u7ec4 queue \uff0c\u5176\u4e2d queue[j] = [hj, kj] \u662f\u961f\u5217\u4e2d\u7b2c j \u4e2a\u4eba\u7684\u5c5e\u6027\uff08queue[0] \u662f\u6392\u5728\u961f\u5217\u524d\u9762\u7684\u4eba\uff09\u3002

    \n\n

    \u00a0

    \n\n
      \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1apeople = [[7,0],[4,4],[7,1],[5,0],[6,1],[5,2]]\n\u8f93\u51fa\uff1a[[5,0],[7,0],[5,2],[6,1],[4,4],[7,1]]\n\u89e3\u91ca\uff1a\n\u7f16\u53f7\u4e3a 0 \u7684\u4eba\u8eab\u9ad8\u4e3a 5 \uff0c\u6ca1\u6709\u8eab\u9ad8\u66f4\u9ad8\u6216\u8005\u76f8\u540c\u7684\u4eba\u6392\u5728\u4ed6\u524d\u9762\u3002\n\u7f16\u53f7\u4e3a 1 \u7684\u4eba\u8eab\u9ad8\u4e3a 7 \uff0c\u6ca1\u6709\u8eab\u9ad8\u66f4\u9ad8\u6216\u8005\u76f8\u540c\u7684\u4eba\u6392\u5728\u4ed6\u524d\u9762\u3002\n\u7f16\u53f7\u4e3a 2 \u7684\u4eba\u8eab\u9ad8\u4e3a 5 \uff0c\u6709 2 \u4e2a\u8eab\u9ad8\u66f4\u9ad8\u6216\u8005\u76f8\u540c\u7684\u4eba\u6392\u5728\u4ed6\u524d\u9762\uff0c\u5373\u7f16\u53f7\u4e3a 0 \u548c 1 \u7684\u4eba\u3002\n\u7f16\u53f7\u4e3a 3 \u7684\u4eba\u8eab\u9ad8\u4e3a 6 \uff0c\u6709 1 \u4e2a\u8eab\u9ad8\u66f4\u9ad8\u6216\u8005\u76f8\u540c\u7684\u4eba\u6392\u5728\u4ed6\u524d\u9762\uff0c\u5373\u7f16\u53f7\u4e3a 1 \u7684\u4eba\u3002\n\u7f16\u53f7\u4e3a 4 \u7684\u4eba\u8eab\u9ad8\u4e3a 4 \uff0c\u6709 4 \u4e2a\u8eab\u9ad8\u66f4\u9ad8\u6216\u8005\u76f8\u540c\u7684\u4eba\u6392\u5728\u4ed6\u524d\u9762\uff0c\u5373\u7f16\u53f7\u4e3a 0\u30011\u30012\u30013 \u7684\u4eba\u3002\n\u7f16\u53f7\u4e3a 5 \u7684\u4eba\u8eab\u9ad8\u4e3a 7 \uff0c\u6709 1 \u4e2a\u8eab\u9ad8\u66f4\u9ad8\u6216\u8005\u76f8\u540c\u7684\u4eba\u6392\u5728\u4ed6\u524d\u9762\uff0c\u5373\u7f16\u53f7\u4e3a 1 \u7684\u4eba\u3002\n\u56e0\u6b64 [[5,0],[7,0],[5,2],[6,1],[4,4],[7,1]] \u662f\u91cd\u65b0\u6784\u9020\u540e\u7684\u961f\u5217\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1apeople = [[6,0],[5,0],[4,0],[3,2],[2,2],[1,4]]\n\u8f93\u51fa\uff1a[[4,0],[5,0],[2,2],[3,2],[1,4],[6,0]]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= people.length <= 2000
    • \n\t
    • 0 <= hi <= 106
    • \n\t
    • 0 <= ki < people.length
    • \n\t
    • \u9898\u76ee\u6570\u636e\u786e\u4fdd\u961f\u5217\u53ef\u4ee5\u88ab\u91cd\u5efa
    • \n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> reconstructQueue(vector>& people) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[][] reconstructQueue(int[][] people) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def reconstructQueue(self, people):\n \"\"\"\n :type people: List[List[int]]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def reconstructQueue(self, people: List[List[int]]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** reconstructQueue(int** people, int peopleSize, int* peopleColSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[][] ReconstructQueue(int[][] people) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} people\n * @return {number[][]}\n */\nvar reconstructQueue = function(people) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} people\n# @return {Integer[][]}\ndef reconstruct_queue(people)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func reconstructQueue(_ people: [[Int]]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func reconstructQueue(people [][]int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def reconstructQueue(people: Array[Array[Int]]): Array[Array[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun reconstructQueue(people: Array): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn reconstruct_queue(people: Vec>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $people\n * @return Integer[][]\n */\n function reconstructQueue($people) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function reconstructQueue(people: number[][]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (reconstruct-queue people)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0406](https://leetcode-cn.com/problems/queue-reconstruction-by-height)", "[\u6839\u636e\u8eab\u9ad8\u91cd\u5efa\u961f\u5217](/solution/0400-0499/0406.Queue%20Reconstruction%20by%20Height/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0406](https://leetcode.com/problems/queue-reconstruction-by-height)", "[Queue Reconstruction by Height](/solution/0400-0499/0406.Queue%20Reconstruction%20by%20Height/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "0405", "frontend_question_id": "0405", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/convert-a-number-to-hexadecimal", "url_en": "https://leetcode.com/problems/convert-a-number-to-hexadecimal", "relative_path_cn": "/solution/0400-0499/0405.Convert%20a%20Number%20to%20Hexadecimal/README.md", "relative_path_en": "/solution/0400-0499/0405.Convert%20a%20Number%20to%20Hexadecimal/README_EN.md", "title_cn": "\u6570\u5b57\u8f6c\u6362\u4e3a\u5341\u516d\u8fdb\u5236\u6570", "title_en": "Convert a Number to Hexadecimal", "question_title_slug": "convert-a-number-to-hexadecimal", "content_en": "

    Given an integer num, return a string representing its hexadecimal representation. For negative integers, two’s complement method is used.

    \n\n

    All the letters in the answer string should be lowercase characters, and there should not be any leading zeros in the answer except for the zero itself.

    \n\n

    Note: You are not allowed to use any built-in library method to directly solve this problem.

    \n\n

     

    \n

    Example 1:

    \n
    Input: num = 26\nOutput: \"1a\"\n

    Example 2:

    \n
    Input: num = -1\nOutput: \"ffffffff\"\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • -231 <= num <= 231 - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\uff0c\u7f16\u5199\u4e00\u4e2a\u7b97\u6cd5\u5c06\u8fd9\u4e2a\u6570\u8f6c\u6362\u4e3a\u5341\u516d\u8fdb\u5236\u6570\u3002\u5bf9\u4e8e\u8d1f\u6574\u6570\uff0c\u6211\u4eec\u901a\u5e38\u4f7f\u7528 \u8865\u7801\u8fd0\u7b97 \u65b9\u6cd5\u3002

    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u5341\u516d\u8fdb\u5236\u4e2d\u6240\u6709\u5b57\u6bcd(a-f)\u90fd\u5fc5\u987b\u662f\u5c0f\u5199\u3002
    2. \n\t
    3. \u5341\u516d\u8fdb\u5236\u5b57\u7b26\u4e32\u4e2d\u4e0d\u80fd\u5305\u542b\u591a\u4f59\u7684\u524d\u5bfc\u96f6\u3002\u5982\u679c\u8981\u8f6c\u5316\u7684\u6570\u4e3a0\uff0c\u90a3\u4e48\u4ee5\u5355\u4e2a\u5b57\u7b26'0'\u6765\u8868\u793a\uff1b\u5bf9\u4e8e\u5176\u4ed6\u60c5\u51b5\uff0c\u5341\u516d\u8fdb\u5236\u5b57\u7b26\u4e32\u4e2d\u7684\u7b2c\u4e00\u4e2a\u5b57\u7b26\u5c06\u4e0d\u4f1a\u662f0\u5b57\u7b26\u3002 
    4. \n\t
    5. \u7ed9\u5b9a\u7684\u6570\u786e\u4fdd\u572832\u4f4d\u6709\u7b26\u53f7\u6574\u6570\u8303\u56f4\u5185\u3002
    6. \n\t
    7. \u4e0d\u80fd\u4f7f\u7528\u4efb\u4f55\u7531\u5e93\u63d0\u4f9b\u7684\u5c06\u6570\u5b57\u76f4\u63a5\u8f6c\u6362\u6216\u683c\u5f0f\u5316\u4e3a\u5341\u516d\u8fdb\u5236\u7684\u65b9\u6cd5\u3002
    8. \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165:\n26\n\n\u8f93\u51fa:\n"1a"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165:\n-1\n\n\u8f93\u51fa:\n"ffffffff"\n
    \n", "tags_en": ["Bit Manipulation"], "tags_cn": ["\u4f4d\u8fd0\u7b97"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string toHex(int num) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String toHex(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def toHex(self, num):\n \"\"\"\n :type num: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def toHex(self, num: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * toHex(int num){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ToHex(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} num\n * @return {string}\n */\nvar toHex = function(num) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} num\n# @return {String}\ndef to_hex(num)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func toHex(_ num: Int) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func toHex(num int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def toHex(num: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun toHex(num: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn to_hex(num: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $num\n * @return String\n */\n function toHex($num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function toHex(num: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (to-hex num)\n (-> exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0405](https://leetcode-cn.com/problems/convert-a-number-to-hexadecimal)", "[\u6570\u5b57\u8f6c\u6362\u4e3a\u5341\u516d\u8fdb\u5236\u6570](/solution/0400-0499/0405.Convert%20a%20Number%20to%20Hexadecimal/README.md)", "`\u4f4d\u8fd0\u7b97`", "\u7b80\u5355", ""], "md_table_row_en": ["[0405](https://leetcode.com/problems/convert-a-number-to-hexadecimal)", "[Convert a Number to Hexadecimal](/solution/0400-0499/0405.Convert%20a%20Number%20to%20Hexadecimal/README_EN.md)", "`Bit Manipulation`", "Easy", ""]}, {"question_id": "0404", "frontend_question_id": "0404", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sum-of-left-leaves", "url_en": "https://leetcode.com/problems/sum-of-left-leaves", "relative_path_cn": "/solution/0400-0499/0404.Sum%20of%20Left%20Leaves/README.md", "relative_path_en": "/solution/0400-0499/0404.Sum%20of%20Left%20Leaves/README_EN.md", "title_cn": "\u5de6\u53f6\u5b50\u4e4b\u548c", "title_en": "Sum of Left Leaves", "question_title_slug": "sum-of-left-leaves", "content_en": "

    Given the root of a binary tree, return the sum of all left leaves.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [3,9,20,null,null,15,7]\nOutput: 24\nExplanation: There are two left leaves in the binary tree, with values 9 and 15 respectively.\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = [1]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 1000].
    • \n\t
    • -1000 <= Node.val <= 1000
    • \n
    \n", "content_cn": "

    \u8ba1\u7b97\u7ed9\u5b9a\u4e8c\u53c9\u6811\u7684\u6240\u6709\u5de6\u53f6\u5b50\u4e4b\u548c\u3002

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n    3\n   / \\\n  9  20\n    /  \\\n   15   7\n\n\u5728\u8fd9\u4e2a\u4e8c\u53c9\u6811\u4e2d\uff0c\u6709\u4e24\u4e2a\u5de6\u53f6\u5b50\uff0c\u5206\u522b\u662f 9 \u548c 15\uff0c\u6240\u4ee5\u8fd4\u56de 24
    \n\n

     

    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int sumOfLeftLeaves(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int sumOfLeftLeaves(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def sumOfLeftLeaves(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def sumOfLeftLeaves(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint sumOfLeftLeaves(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int SumOfLeftLeaves(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar sumOfLeftLeaves = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef sum_of_left_leaves(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func sumOfLeftLeaves(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc sumOfLeftLeaves(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def sumOfLeftLeaves(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun sumOfLeftLeaves(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn sum_of_left_leaves(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function sumOfLeftLeaves($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction sumOfLeftLeaves(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (sum-of-left-leaves root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0404](https://leetcode-cn.com/problems/sum-of-left-leaves)", "[\u5de6\u53f6\u5b50\u4e4b\u548c](/solution/0400-0499/0404.Sum%20of%20Left%20Leaves/README.md)", "`\u6811`", "\u7b80\u5355", ""], "md_table_row_en": ["[0404](https://leetcode.com/problems/sum-of-left-leaves)", "[Sum of Left Leaves](/solution/0400-0499/0404.Sum%20of%20Left%20Leaves/README_EN.md)", "`Tree`", "Easy", ""]}, {"question_id": "0403", "frontend_question_id": "0403", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/frog-jump", "url_en": "https://leetcode.com/problems/frog-jump", "relative_path_cn": "/solution/0400-0499/0403.Frog%20Jump/README.md", "relative_path_en": "/solution/0400-0499/0403.Frog%20Jump/README_EN.md", "title_cn": "\u9752\u86d9\u8fc7\u6cb3", "title_en": "Frog Jump", "question_title_slug": "frog-jump", "content_en": "

    A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.

    \n\n

    Given a list of stones' positions (in units) in sorted ascending order, determine if the frog can cross the river by landing on the last stone. Initially, the frog is on the first stone and assumes the first jump must be 1 unit.

    \n\n

    If the frog's last jump was k units, its next jump must be either k - 1, k, or k + 1 units. The frog can only jump in the forward direction.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: stones = [0,1,3,5,6,8,12,17]\nOutput: true\nExplanation: The frog can jump to the last stone by jumping 1 unit to the 2nd stone, then 2 units to the 3rd stone, then 2 units to the 4th stone, then 3 units to the 6th stone, 4 units to the 7th stone, and 5 units to the 8th stone.\n
    \n\n

    Example 2:

    \n\n
    \nInput: stones = [0,1,2,3,4,8,9,11]\nOutput: false\nExplanation: There is no way to jump to the last stone as the gap between the 5th and 6th stone is too large.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= stones.length <= 2000
    • \n\t
    • 0 <= stones[i] <= 231 - 1
    • \n\t
    • stones[0] == 0
    • \n
    \n", "content_cn": "

    \u4e00\u53ea\u9752\u86d9\u60f3\u8981\u8fc7\u6cb3\u3002 \u5047\u5b9a\u6cb3\u6d41\u88ab\u7b49\u5206\u4e3a\u82e5\u5e72\u4e2a\u5355\u5143\u683c\uff0c\u5e76\u4e14\u5728\u6bcf\u4e00\u4e2a\u5355\u5143\u683c\u5185\u90fd\u6709\u53ef\u80fd\u653e\u6709\u4e00\u5757\u77f3\u5b50\uff08\u4e5f\u6709\u53ef\u80fd\u6ca1\u6709\uff09\u3002 \u9752\u86d9\u53ef\u4ee5\u8df3\u4e0a\u77f3\u5b50\uff0c\u4f46\u662f\u4e0d\u53ef\u4ee5\u8df3\u5165\u6c34\u4e2d\u3002

    \n\n

    \u7ed9\u4f60\u77f3\u5b50\u7684\u4f4d\u7f6e\u5217\u8868 stones\uff08\u7528\u5355\u5143\u683c\u5e8f\u53f7 \u5347\u5e8f \u8868\u793a\uff09\uff0c\u00a0\u8bf7\u5224\u5b9a\u9752\u86d9\u80fd\u5426\u6210\u529f\u8fc7\u6cb3\uff08\u5373\u80fd\u5426\u5728\u6700\u540e\u4e00\u6b65\u8df3\u81f3\u6700\u540e\u4e00\u5757\u77f3\u5b50\u4e0a\uff09\u3002

    \n\n

    \u5f00\u59cb\u65f6\uff0c\u00a0\u9752\u86d9\u9ed8\u8ba4\u5df2\u7ad9\u5728\u7b2c\u4e00\u5757\u77f3\u5b50\u4e0a\uff0c\u5e76\u53ef\u4ee5\u5047\u5b9a\u5b83\u7b2c\u4e00\u6b65\u53ea\u80fd\u8df3\u8dc3\u4e00\u4e2a\u5355\u4f4d\uff08\u5373\u53ea\u80fd\u4ece\u5355\u5143\u683c 1 \u8df3\u81f3\u5355\u5143\u683c 2 \uff09\u3002

    \n\n

    \u5982\u679c\u9752\u86d9\u4e0a\u4e00\u6b65\u8df3\u8dc3\u4e86\u00a0k\u00a0\u4e2a\u5355\u4f4d\uff0c\u90a3\u4e48\u5b83\u63a5\u4e0b\u6765\u7684\u8df3\u8dc3\u8ddd\u79bb\u53ea\u80fd\u9009\u62e9\u4e3a\u00a0k - 1\u3001k\u00a0\u6216\u00a0k + 1 \u4e2a\u5355\u4f4d\u3002\u00a0\u53e6\u8bf7\u6ce8\u610f\uff0c\u9752\u86d9\u53ea\u80fd\u5411\u524d\u65b9\uff08\u7ec8\u70b9\u7684\u65b9\u5411\uff09\u8df3\u8dc3\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1astones = [0,1,3,5,6,8,12,17]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u9752\u86d9\u53ef\u4ee5\u6210\u529f\u8fc7\u6cb3\uff0c\u6309\u7167\u5982\u4e0b\u65b9\u6848\u8df3\u8dc3\uff1a\u8df3 1 \u4e2a\u5355\u4f4d\u5230\u7b2c 2 \u5757\u77f3\u5b50, \u7136\u540e\u8df3 2 \u4e2a\u5355\u4f4d\u5230\u7b2c 3 \u5757\u77f3\u5b50, \u63a5\u7740 \u8df3 2 \u4e2a\u5355\u4f4d\u5230\u7b2c 4 \u5757\u77f3\u5b50, \u7136\u540e\u8df3 3 \u4e2a\u5355\u4f4d\u5230\u7b2c 6 \u5757\u77f3\u5b50, \u8df3 4 \u4e2a\u5355\u4f4d\u5230\u7b2c 7 \u5757\u77f3\u5b50, \u6700\u540e\uff0c\u8df3 5 \u4e2a\u5355\u4f4d\u5230\u7b2c 8 \u4e2a\u77f3\u5b50\uff08\u5373\u6700\u540e\u4e00\u5757\u77f3\u5b50\uff09\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1astones = [0,1,2,3,4,8,9,11]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u8fd9\u662f\u56e0\u4e3a\u7b2c 5 \u548c\u7b2c 6 \u4e2a\u77f3\u5b50\u4e4b\u95f4\u7684\u95f4\u8ddd\u592a\u5927\uff0c\u6ca1\u6709\u53ef\u9009\u7684\u65b9\u6848\u4f9b\u9752\u86d9\u8df3\u8dc3\u8fc7\u53bb\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= stones.length <= 2000
    • \n\t
    • 0 <= stones[i] <= 231 - 1
    • \n\t
    • stones[0] == 0
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canCross(vector& stones) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canCross(int[] stones) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canCross(self, stones):\n \"\"\"\n :type stones: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canCross(self, stones: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canCross(int* stones, int stonesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanCross(int[] stones) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} stones\n * @return {boolean}\n */\nvar canCross = function(stones) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} stones\n# @return {Boolean}\ndef can_cross(stones)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canCross(_ stones: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canCross(stones []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canCross(stones: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canCross(stones: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_cross(stones: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $stones\n * @return Boolean\n */\n function canCross($stones) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canCross(stones: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-cross stones)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0403](https://leetcode-cn.com/problems/frog-jump)", "[\u9752\u86d9\u8fc7\u6cb3](/solution/0400-0499/0403.Frog%20Jump/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0403](https://leetcode.com/problems/frog-jump)", "[Frog Jump](/solution/0400-0499/0403.Frog%20Jump/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "0402", "frontend_question_id": "0402", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/remove-k-digits", "url_en": "https://leetcode.com/problems/remove-k-digits", "relative_path_cn": "/solution/0400-0499/0402.Remove%20K%20Digits/README.md", "relative_path_en": "/solution/0400-0499/0402.Remove%20K%20Digits/README_EN.md", "title_cn": "\u79fb\u6389K\u4f4d\u6570\u5b57", "title_en": "Remove K Digits", "question_title_slug": "remove-k-digits", "content_en": "

    Given string num representing a non-negative integer num, and an integer k, return the smallest possible integer after removing k digits from num.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: num = "1432219", k = 3\nOutput: "1219"\nExplanation: Remove the three digits 4, 3, and 2 to form the new number 1219 which is the smallest.\n
    \n\n

    Example 2:

    \n\n
    \nInput: num = "10200", k = 1\nOutput: "200"\nExplanation: Remove the leading 1 and the number is 200. Note that the output must not contain leading zeroes.\n
    \n\n

    Example 3:

    \n\n
    \nInput: num = "10", k = 2\nOutput: "0"\nExplanation: Remove all the digits from the number and it is left with nothing which is 0.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= k <= num.length <= 105
    • \n\t
    • num consists of only digits.
    • \n\t
    • num does not have any leading zeros except for the zero itself.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4ee5\u5b57\u7b26\u4e32\u8868\u793a\u7684\u975e\u8d1f\u6574\u6570 num\uff0c\u79fb\u9664\u8fd9\u4e2a\u6570\u4e2d\u7684 k \u4f4d\u6570\u5b57\uff0c\u4f7f\u5f97\u5269\u4e0b\u7684\u6570\u5b57\u6700\u5c0f\u3002

    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    • num \u7684\u957f\u5ea6\u5c0f\u4e8e 10002 \u4e14 ≥ k\u3002
    • \n\t
    • num \u4e0d\u4f1a\u5305\u542b\u4efb\u4f55\u524d\u5bfc\u96f6\u3002
    • \n
    \n\n

    \u793a\u4f8b 1 :

    \n\n
    \n\u8f93\u5165: num = "1432219", k = 3\n\u8f93\u51fa: "1219"\n\u89e3\u91ca: \u79fb\u9664\u6389\u4e09\u4e2a\u6570\u5b57 4, 3, \u548c 2 \u5f62\u6210\u4e00\u4e2a\u65b0\u7684\u6700\u5c0f\u7684\u6570\u5b57 1219\u3002\n
    \n\n

    \u793a\u4f8b 2 :

    \n\n
    \n\u8f93\u5165: num = "10200", k = 1\n\u8f93\u51fa: "200"\n\u89e3\u91ca: \u79fb\u6389\u9996\u4f4d\u7684 1 \u5269\u4e0b\u7684\u6570\u5b57\u4e3a 200. \u6ce8\u610f\u8f93\u51fa\u4e0d\u80fd\u6709\u4efb\u4f55\u524d\u5bfc\u96f6\u3002\n
    \n\n

    \u793a\u4f8b 3 :

    \n\n
    \n\u8f93\u5165: num = "10", k = 2\n\u8f93\u51fa: "0"\n\u89e3\u91ca: \u4ece\u539f\u6570\u5b57\u79fb\u9664\u6240\u6709\u7684\u6570\u5b57\uff0c\u5269\u4f59\u4e3a\u7a7a\u5c31\u662f0\u3002\n
    \n", "tags_en": ["Stack", "Greedy"], "tags_cn": ["\u6808", "\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string removeKdigits(string num, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String removeKdigits(String num, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def removeKdigits(self, num, k):\n \"\"\"\n :type num: str\n :type k: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def removeKdigits(self, num: str, k: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * removeKdigits(char * num, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string RemoveKdigits(string num, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} num\n * @param {number} k\n * @return {string}\n */\nvar removeKdigits = function(num, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} num\n# @param {Integer} k\n# @return {String}\ndef remove_kdigits(num, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func removeKdigits(_ num: String, _ k: Int) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func removeKdigits(num string, k int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def removeKdigits(num: String, k: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun removeKdigits(num: String, k: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn remove_kdigits(num: String, k: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $num\n * @param Integer $k\n * @return String\n */\n function removeKdigits($num, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function removeKdigits(num: string, k: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (remove-kdigits num k)\n (-> string? exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0402](https://leetcode-cn.com/problems/remove-k-digits)", "[\u79fb\u6389K\u4f4d\u6570\u5b57](/solution/0400-0499/0402.Remove%20K%20Digits/README.md)", "`\u6808`,`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0402](https://leetcode.com/problems/remove-k-digits)", "[Remove K Digits](/solution/0400-0499/0402.Remove%20K%20Digits/README_EN.md)", "`Stack`,`Greedy`", "Medium", ""]}, {"question_id": "0401", "frontend_question_id": "0401", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/binary-watch", "url_en": "https://leetcode.com/problems/binary-watch", "relative_path_cn": "/solution/0400-0499/0401.Binary%20Watch/README.md", "relative_path_en": "/solution/0400-0499/0401.Binary%20Watch/README_EN.md", "title_cn": "\u4e8c\u8fdb\u5236\u624b\u8868", "title_en": "Binary Watch", "question_title_slug": "binary-watch", "content_en": "

    A binary watch has 4 LEDs on the top which represent the hours (0-11), and the 6 LEDs on the bottom represent the minutes (0-59). Each LED represents a zero or one, with the least significant bit on the right.

    \n\n
      \n\t
    • For example, the below binary watch reads "4:51".
    • \n
    \n\n

    \"\"

    \n\n

    Given an integer turnedOn which represents the number of LEDs that are currently on, return all possible times the watch could represent. You may return the answer in any order.

    \n\n

    The hour must not contain a leading zero.

    \n\n
      \n\t
    • For example, "01:00" is not valid. It should be "1:00".
    • \n
    \n\n

    The minute must be consist of two digits and may contain a leading zero.

    \n\n
      \n\t
    • For example, "10:2" is not valid. It should be "10:02".
    • \n
    \n\n

     

    \n

    Example 1:

    \n
    Input: turnedOn = 1\nOutput: [\"0:01\",\"0:02\",\"0:04\",\"0:08\",\"0:16\",\"0:32\",\"1:00\",\"2:00\",\"4:00\",\"8:00\"]\n

    Example 2:

    \n
    Input: turnedOn = 9\nOutput: []\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= turnedOn <= 10
    • \n
    \n", "content_cn": "

    \u4e8c\u8fdb\u5236\u624b\u8868\u9876\u90e8\u6709 4 \u4e2a LED \u4ee3\u8868 \u5c0f\u65f6\uff080-11\uff09\uff0c\u5e95\u90e8\u7684 6 \u4e2a LED \u4ee3\u8868 \u5206\u949f\uff080-59\uff09\u3002\u6bcf\u4e2a LED \u4ee3\u8868\u4e00\u4e2a 0 \u6216 1\uff0c\u6700\u4f4e\u4f4d\u5728\u53f3\u4fa7\u3002

    \n\n
      \n\t
    • \u4f8b\u5982\uff0c\u4e0b\u9762\u7684\u4e8c\u8fdb\u5236\u624b\u8868\u8bfb\u53d6 \"3:25\" \u3002
    • \n
    \n\n

    \n\n

    \uff08\u56fe\u6e90\uff1aWikiMedia - Binary clock samui moon.jpg \uff0c\u8bb8\u53ef\u534f\u8bae\uff1aAttribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) \uff09

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 turnedOn \uff0c\u8868\u793a\u5f53\u524d\u4eae\u7740\u7684 LED \u7684\u6570\u91cf\uff0c\u8fd4\u56de\u4e8c\u8fdb\u5236\u624b\u8868\u53ef\u4ee5\u8868\u793a\u7684\u6240\u6709\u53ef\u80fd\u65f6\u95f4\u3002\u4f60\u53ef\u4ee5 \u6309\u4efb\u610f\u987a\u5e8f \u8fd4\u56de\u7b54\u6848\u3002

    \n\n

    \u5c0f\u65f6\u4e0d\u4f1a\u4ee5\u96f6\u5f00\u5934\uff1a

    \n\n
      \n\t
    • \u4f8b\u5982\uff0c\"01:00\" \u662f\u65e0\u6548\u7684\u65f6\u95f4\uff0c\u6b63\u786e\u7684\u5199\u6cd5\u5e94\u8be5\u662f \"1:00\" \u3002
    • \n
    \n\n

    \u5206\u949f\u5fc5\u987b\u7531\u4e24\u4f4d\u6570\u7ec4\u6210\uff0c\u53ef\u80fd\u4f1a\u4ee5\u96f6\u5f00\u5934\uff1a

    \n\n
      \n\t
    • \u4f8b\u5982\uff0c\"10:2\" \u662f\u65e0\u6548\u7684\u65f6\u95f4\uff0c\u6b63\u786e\u7684\u5199\u6cd5\u5e94\u8be5\u662f \"10:02\" \u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aturnedOn = 1\n\u8f93\u51fa\uff1a[\"0:01\",\"0:02\",\"0:04\",\"0:08\",\"0:16\",\"0:32\",\"1:00\",\"2:00\",\"4:00\",\"8:00\"]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aturnedOn = 9\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u00a0

    \n\n

    \u89e3\u91ca\uff1a

    \n\n
      \n\t
    • 0 <= turnedOn <= 10
    • \n
    \n", "tags_en": ["Bit Manipulation", "Backtracking"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector readBinaryWatch(int turnedOn) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List readBinaryWatch(int turnedOn) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def readBinaryWatch(self, turnedOn):\n \"\"\"\n :type turnedOn: int\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def readBinaryWatch(self, turnedOn: int) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** readBinaryWatch(int turnedOn, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList ReadBinaryWatch(int turnedOn) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} turnedOn\n * @return {string[]}\n */\nvar readBinaryWatch = function(turnedOn) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} turned_on\n# @return {String[]}\ndef read_binary_watch(turned_on)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func readBinaryWatch(_ turnedOn: Int) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func readBinaryWatch(turnedOn int) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def readBinaryWatch(turnedOn: Int): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun readBinaryWatch(turnedOn: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn read_binary_watch(turned_on: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $turnedOn\n * @return String[]\n */\n function readBinaryWatch($turnedOn) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function readBinaryWatch(turnedOn: number): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (read-binary-watch turnedOn)\n (-> exact-integer? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0401](https://leetcode-cn.com/problems/binary-watch)", "[\u4e8c\u8fdb\u5236\u624b\u8868](/solution/0400-0499/0401.Binary%20Watch/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u56de\u6eaf\u7b97\u6cd5`", "\u7b80\u5355", ""], "md_table_row_en": ["[0401](https://leetcode.com/problems/binary-watch)", "[Binary Watch](/solution/0400-0499/0401.Binary%20Watch/README_EN.md)", "`Bit Manipulation`,`Backtracking`", "Easy", ""]}, {"question_id": "0400", "frontend_question_id": "0400", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/nth-digit", "url_en": "https://leetcode.com/problems/nth-digit", "relative_path_cn": "/solution/0400-0499/0400.Nth%20Digit/README.md", "relative_path_en": "/solution/0400-0499/0400.Nth%20Digit/README_EN.md", "title_cn": "\u7b2c N \u4f4d\u6570\u5b57", "title_en": "Nth Digit", "question_title_slug": "nth-digit", "content_en": "

    Given an integer n, return the nth digit of the infinite integer sequence [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ...].

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 3\nOutput: 3\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 11\nOutput: 0\nExplanation: The 11th digit of the sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... is a 0, which is part of the number 10.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 231 - 1
    • \n
    \n", "content_cn": "

    \u5728\u65e0\u9650\u7684\u6574\u6570\u5e8f\u5217\u00a01, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ...\u4e2d\u627e\u5230\u7b2c\u00a0n \u4f4d\u6570\u5b57\u3002

    \n\n

    \u00a0

    \n\n

    \u6ce8\u610f\uff1an\u00a0\u662f\u6b63\u6570\u4e14\u5728 32 \u4f4d\u6574\u6570\u8303\u56f4\u5185\uff08n < 231\uff09\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1a3\n\u8f93\u51fa\uff1a3\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1a11\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u7b2c 11 \u4f4d\u6570\u5b57\u5728\u5e8f\u5217 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... \u91cc\u662f 0 \uff0c\u5b83\u662f 10 \u7684\u4e00\u90e8\u5206\u3002\n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findNthDigit(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findNthDigit(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findNthDigit(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findNthDigit(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findNthDigit(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindNthDigit(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar findNthDigit = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef find_nth_digit(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findNthDigit(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findNthDigit(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findNthDigit(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findNthDigit(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_nth_digit(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function findNthDigit($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findNthDigit(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-nth-digit n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0400](https://leetcode-cn.com/problems/nth-digit)", "[\u7b2c N \u4f4d\u6570\u5b57](/solution/0400-0499/0400.Nth%20Digit/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0400](https://leetcode.com/problems/nth-digit)", "[Nth Digit](/solution/0400-0499/0400.Nth%20Digit/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "0399", "frontend_question_id": "0399", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/evaluate-division", "url_en": "https://leetcode.com/problems/evaluate-division", "relative_path_cn": "/solution/0300-0399/0399.Evaluate%20Division/README.md", "relative_path_en": "/solution/0300-0399/0399.Evaluate%20Division/README_EN.md", "title_cn": "\u9664\u6cd5\u6c42\u503c", "title_en": "Evaluate Division", "question_title_slug": "evaluate-division", "content_en": "

    You are given an array of variable pairs equations and an array of real numbers values, where equations[i] = [Ai, Bi] and values[i] represent the equation Ai / Bi = values[i]. Each Ai or Bi is a string that represents a single variable.

    \n\n

    You are also given some queries, where queries[j] = [Cj, Dj] represents the jth query where you must find the answer for Cj / Dj = ?.

    \n\n

    Return the answers to all queries. If a single answer cannot be determined, return -1.0.

    \n\n

    Note: The input is always valid. You may assume that evaluating the queries will not result in division by zero and that there is no contradiction.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: equations = [["a","b"],["b","c"]], values = [2.0,3.0], queries = [["a","c"],["b","a"],["a","e"],["a","a"],["x","x"]]\nOutput: [6.00000,0.50000,-1.00000,1.00000,-1.00000]\nExplanation: \nGiven: a / b = 2.0, b / c = 3.0\nqueries are: a / c = ?, b / a = ?, a / e = ?, a / a = ?, x / x = ?\nreturn: [6.0, 0.5, -1.0, 1.0, -1.0 ]\n
    \n\n

    Example 2:

    \n\n
    \nInput: equations = [["a","b"],["b","c"],["bc","cd"]], values = [1.5,2.5,5.0], queries = [["a","c"],["c","b"],["bc","cd"],["cd","bc"]]\nOutput: [3.75000,0.40000,5.00000,0.20000]\n
    \n\n

    Example 3:

    \n\n
    \nInput: equations = [["a","b"]], values = [0.5], queries = [["a","b"],["b","a"],["a","c"],["x","y"]]\nOutput: [0.50000,2.00000,-1.00000,-1.00000]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= equations.length <= 20
    • \n\t
    • equations[i].length == 2
    • \n\t
    • 1 <= Ai.length, Bi.length <= 5
    • \n\t
    • values.length == equations.length
    • \n\t
    • 0.0 < values[i] <= 20.0
    • \n\t
    • 1 <= queries.length <= 20
    • \n\t
    • queries[i].length == 2
    • \n\t
    • 1 <= Cj.length, Dj.length <= 5
    • \n\t
    • Ai, Bi, Cj, Dj consist of lower case English letters and digits.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u53d8\u91cf\u5bf9\u6570\u7ec4 equations \u548c\u4e00\u4e2a\u5b9e\u6570\u503c\u6570\u7ec4 values \u4f5c\u4e3a\u5df2\u77e5\u6761\u4ef6\uff0c\u5176\u4e2d equations[i] = [Ai, Bi] \u548c values[i] \u5171\u540c\u8868\u793a\u7b49\u5f0f Ai / Bi = values[i] \u3002\u6bcf\u4e2a Ai \u6216 Bi \u662f\u4e00\u4e2a\u8868\u793a\u5355\u4e2a\u53d8\u91cf\u7684\u5b57\u7b26\u4e32\u3002

    \n\n

    \u53e6\u6709\u4e00\u4e9b\u4ee5\u6570\u7ec4 queries \u8868\u793a\u7684\u95ee\u9898\uff0c\u5176\u4e2d queries[j] = [Cj, Dj] \u8868\u793a\u7b2c j \u4e2a\u95ee\u9898\uff0c\u8bf7\u4f60\u6839\u636e\u5df2\u77e5\u6761\u4ef6\u627e\u51fa Cj / Dj = ? \u7684\u7ed3\u679c\u4f5c\u4e3a\u7b54\u6848\u3002

    \n\n

    \u8fd4\u56de \u6240\u6709\u95ee\u9898\u7684\u7b54\u6848 \u3002\u5982\u679c\u5b58\u5728\u67d0\u4e2a\u65e0\u6cd5\u786e\u5b9a\u7684\u7b54\u6848\uff0c\u5219\u7528 -1.0 \u66ff\u4ee3\u8fd9\u4e2a\u7b54\u6848\u3002\u5982\u679c\u95ee\u9898\u4e2d\u51fa\u73b0\u4e86\u7ed9\u5b9a\u7684\u5df2\u77e5\u6761\u4ef6\u4e2d\u6ca1\u6709\u51fa\u73b0\u7684\u5b57\u7b26\u4e32\uff0c\u4e5f\u9700\u8981\u7528 -1.0 \u66ff\u4ee3\u8fd9\u4e2a\u7b54\u6848\u3002

    \n\n

    \u6ce8\u610f\uff1a\u8f93\u5165\u603b\u662f\u6709\u6548\u7684\u3002\u4f60\u53ef\u4ee5\u5047\u8bbe\u9664\u6cd5\u8fd0\u7b97\u4e2d\u4e0d\u4f1a\u51fa\u73b0\u9664\u6570\u4e3a 0 \u7684\u60c5\u51b5\uff0c\u4e14\u4e0d\u5b58\u5728\u4efb\u4f55\u77db\u76fe\u7684\u7ed3\u679c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aequations = [[\"a\",\"b\"],[\"b\",\"c\"]], values = [2.0,3.0], queries = [[\"a\",\"c\"],[\"b\",\"a\"],[\"a\",\"e\"],[\"a\",\"a\"],[\"x\",\"x\"]]\n\u8f93\u51fa\uff1a[6.00000,0.50000,-1.00000,1.00000,-1.00000]\n\u89e3\u91ca\uff1a\n\u6761\u4ef6\uff1aa / b = 2.0, b / c = 3.0\n\u95ee\u9898\uff1aa / c = ?, b / a = ?, a / e = ?, a / a = ?, x / x = ?\n\u7ed3\u679c\uff1a[6.0, 0.5, -1.0, 1.0, -1.0 ]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aequations = [[\"a\",\"b\"],[\"b\",\"c\"],[\"bc\",\"cd\"]], values = [1.5,2.5,5.0], queries = [[\"a\",\"c\"],[\"c\",\"b\"],[\"bc\",\"cd\"],[\"cd\",\"bc\"]]\n\u8f93\u51fa\uff1a[3.75000,0.40000,5.00000,0.20000]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aequations = [[\"a\",\"b\"]], values = [0.5], queries = [[\"a\",\"b\"],[\"b\",\"a\"],[\"a\",\"c\"],[\"x\",\"y\"]]\n\u8f93\u51fa\uff1a[0.50000,2.00000,-1.00000,-1.00000]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= equations.length <= 20
    • \n\t
    • equations[i].length == 2
    • \n\t
    • 1 <= Ai.length, Bi.length <= 5
    • \n\t
    • values.length == equations.length
    • \n\t
    • 0.0 < values[i] <= 20.0
    • \n\t
    • 1 <= queries.length <= 20
    • \n\t
    • queries[i].length == 2
    • \n\t
    • 1 <= Cj.length, Dj.length <= 5
    • \n\t
    • Ai, Bi, Cj, Dj \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u4e0e\u6570\u5b57\u7ec4\u6210
    • \n
    \n", "tags_en": ["Union Find", "Graph"], "tags_cn": ["\u5e76\u67e5\u96c6", "\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector calcEquation(vector>& equations, vector& values, vector>& queries) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double[] calcEquation(List> equations, double[] values, List> queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def calcEquation(self, equations, values, queries):\n \"\"\"\n :type equations: List[List[str]]\n :type values: List[float]\n :type queries: List[List[str]]\n :rtype: List[float]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def calcEquation(self, equations: List[List[str]], values: List[float], queries: List[List[str]]) -> List[float]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\ndouble* calcEquation(char *** equations, int equationsSize, int* equationsColSize, double* values, int valuesSize, char *** queries, int queriesSize, int* queriesColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double[] CalcEquation(IList> equations, double[] values, IList> queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[][]} equations\n * @param {number[]} values\n * @param {string[][]} queries\n * @return {number[]}\n */\nvar calcEquation = function(equations, values, queries) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[][]} equations\n# @param {Float[]} values\n# @param {String[][]} queries\n# @return {Float[]}\ndef calc_equation(equations, values, queries)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func calcEquation(_ equations: [[String]], _ values: [Double], _ queries: [[String]]) -> [Double] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func calcEquation(equations [][]string, values []float64, queries [][]string) []float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def calcEquation(equations: List[List[String]], values: Array[Double], queries: List[List[String]]): Array[Double] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun calcEquation(equations: List>, values: DoubleArray, queries: List>): DoubleArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn calc_equation(equations: Vec>, values: Vec, queries: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $equations\n * @param Float[] $values\n * @param String[][] $queries\n * @return Float[]\n */\n function calcEquation($equations, $values, $queries) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function calcEquation(equations: string[][], values: number[], queries: string[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (calc-equation equations values queries)\n (-> (listof (listof string?)) (listof flonum?) (listof (listof string?)) (listof flonum?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0399](https://leetcode-cn.com/problems/evaluate-division)", "[\u9664\u6cd5\u6c42\u503c](/solution/0300-0399/0399.Evaluate%20Division/README.md)", "`\u5e76\u67e5\u96c6`,`\u56fe`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0399](https://leetcode.com/problems/evaluate-division)", "[Evaluate Division](/solution/0300-0399/0399.Evaluate%20Division/README_EN.md)", "`Union Find`,`Graph`", "Medium", ""]}, {"question_id": "0398", "frontend_question_id": "0398", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/random-pick-index", "url_en": "https://leetcode.com/problems/random-pick-index", "relative_path_cn": "/solution/0300-0399/0398.Random%20Pick%20Index/README.md", "relative_path_en": "/solution/0300-0399/0398.Random%20Pick%20Index/README_EN.md", "title_cn": "\u968f\u673a\u6570\u7d22\u5f15", "title_en": "Random Pick Index", "question_title_slug": "random-pick-index", "content_en": "

    Given an integer array nums with possible duplicates, randomly output the index of a given target number. You can assume that the given target number must exist in the array.

    \n\n

    Implement the Solution class:

    \n\n
      \n\t
    • Solution(int[] nums) Initializes the object with the array nums.
    • \n\t
    • int pick(int target) Picks a random index i from nums where nums[i] == target. If there are multiple valid i's, then each index should have an equal probability of returning.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["Solution", "pick", "pick", "pick"]\n[[[1, 2, 3, 3, 3]], [3], [1], [3]]\nOutput\n[null, 4, 0, 2]\n\nExplanation\nSolution solution = new Solution([1, 2, 3, 3, 3]);\nsolution.pick(3); // It should return either index 2, 3, or 4 randomly. Each index should have equal probability of returning.\nsolution.pick(1); // It should return 0. Since in the array only nums[0] is equal to 1.\nsolution.pick(3); // It should return either index 2, 3, or 4 randomly. Each index should have equal probability of returning.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 2 * 104
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n\t
    • target is an integer from nums.
    • \n\t
    • At most 104 calls will be made to pick.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u53ef\u80fd\u542b\u6709\u91cd\u590d\u5143\u7d20\u7684\u6574\u6570\u6570\u7ec4\uff0c\u8981\u6c42\u968f\u673a\u8f93\u51fa\u7ed9\u5b9a\u7684\u6570\u5b57\u7684\u7d22\u5f15\u3002 \u60a8\u53ef\u4ee5\u5047\u8bbe\u7ed9\u5b9a\u7684\u6570\u5b57\u4e00\u5b9a\u5b58\u5728\u4e8e\u6570\u7ec4\u4e2d\u3002

    \n\n

    \u6ce8\u610f\uff1a
    \n\u6570\u7ec4\u5927\u5c0f\u53ef\u80fd\u975e\u5e38\u5927\u3002 \u4f7f\u7528\u592a\u591a\u989d\u5916\u7a7a\u95f4\u7684\u89e3\u51b3\u65b9\u6848\u5c06\u4e0d\u4f1a\u901a\u8fc7\u6d4b\u8bd5\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \nint[] nums = new int[] {1,2,3,3,3};\nSolution solution = new Solution(nums);\n\n// pick(3) \u5e94\u8be5\u8fd4\u56de\u7d22\u5f15 2,3 \u6216\u8005 4\u3002\u6bcf\u4e2a\u7d22\u5f15\u7684\u8fd4\u56de\u6982\u7387\u5e94\u8be5\u76f8\u7b49\u3002\nsolution.pick(3);\n\n// pick(1) \u5e94\u8be5\u8fd4\u56de 0\u3002\u56e0\u4e3a\u53ea\u6709nums[0]\u7b49\u4e8e1\u3002\nsolution.pick(1);\n
    \n", "tags_en": ["Reservoir Sampling"], "tags_cn": ["\u84c4\u6c34\u6c60\u62bd\u6837"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n Solution(vector& nums) {\n\n }\n \n int pick(int target) {\n\n }\n};\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution* obj = new Solution(nums);\n * int param_1 = obj->pick(target);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n\n public Solution(int[] nums) {\n\n }\n \n public int pick(int target) {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution obj = new Solution(nums);\n * int param_1 = obj.pick(target);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n\n def __init__(self, nums):\n \"\"\"\n :type nums: List[int]\n \"\"\"\n\n\n def pick(self, target):\n \"\"\"\n :type target: int\n :rtype: int\n \"\"\"\n\n\n\n# Your Solution object will be instantiated and called as such:\n# obj = Solution(nums)\n# param_1 = obj.pick(target)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n\n def __init__(self, nums: List[int]):\n\n\n def pick(self, target: int) -> int:\n\n\n\n# Your Solution object will be instantiated and called as such:\n# obj = Solution(nums)\n# param_1 = obj.pick(target)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} Solution;\n\n\nSolution* solutionCreate(int* nums, int numsSize) {\n\n}\n\nint solutionPick(Solution* obj, int target) {\n\n}\n\nvoid solutionFree(Solution* obj) {\n\n}\n\n/**\n * Your Solution struct will be instantiated and called as such:\n * Solution* obj = solutionCreate(nums, numsSize);\n * int param_1 = solutionPick(obj, target);\n \n * solutionFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n\n public Solution(int[] nums) {\n\n }\n \n public int Pick(int target) {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution obj = new Solution(nums);\n * int param_1 = obj.Pick(target);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n */\nvar Solution = function(nums) {\n\n};\n\n/** \n * @param {number} target\n * @return {number}\n */\nSolution.prototype.pick = function(target) {\n\n};\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = new Solution(nums)\n * var param_1 = obj.pick(target)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class Solution\n\n=begin\n :type nums: Integer[]\n=end\n def initialize(nums)\n\n end\n\n\n=begin\n :type target: Integer\n :rtype: Integer\n=end\n def pick(target)\n\n end\n\n\nend\n\n# Your Solution object will be instantiated and called as such:\n# obj = Solution.new(nums)\n# param_1 = obj.pick(target)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass Solution {\n\n init(_ nums: [Int]) {\n\n }\n \n func pick(_ target: Int) -> Int {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * let obj = Solution(nums)\n * let ret_1: Int = obj.pick(target)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type Solution struct {\n\n}\n\n\nfunc Constructor(nums []int) Solution {\n\n}\n\n\nfunc (this *Solution) Pick(target int) int {\n\n}\n\n\n/**\n * Your Solution object will be instantiated and called as such:\n * obj := Constructor(nums);\n * param_1 := obj.Pick(target);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class Solution(_nums: Array[Int]) {\n\n def pick(target: Int): Int = {\n\n }\n\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = new Solution(nums)\n * var param_1 = obj.pick(target)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution(nums: IntArray) {\n\n fun pick(target: Int): Int {\n\n }\n\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = Solution(nums)\n * var param_1 = obj.pick(target)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct Solution {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl Solution {\n\n fn new(nums: Vec) -> Self {\n\n }\n \n fn pick(&self, target: i32) -> i32 {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * let obj = Solution::new(nums);\n * let ret_1: i32 = obj.pick(target);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n /**\n * @param Integer[] $nums\n */\n function __construct($nums) {\n\n }\n\n /**\n * @param Integer $target\n * @return Integer\n */\n function pick($target) {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * $obj = Solution($nums);\n * $ret_1 = $obj->pick($target);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class Solution {\n constructor(nums: number[]) {\n\n }\n\n pick(target: number): number {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = new Solution(nums)\n * var param_1 = obj.pick(target)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define solution%\n (class object%\n (super-new)\n\n ; nums : (listof exact-integer?)\n (init-field\n nums)\n \n ; pick : exact-integer? -> exact-integer?\n (define/public (pick target)\n\n )))\n\n;; Your solution% object will be instantiated and called as such:\n;; (define obj (new solution% [nums nums]))\n;; (define param_1 (send obj pick target))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0398](https://leetcode-cn.com/problems/random-pick-index)", "[\u968f\u673a\u6570\u7d22\u5f15](/solution/0300-0399/0398.Random%20Pick%20Index/README.md)", "`\u84c4\u6c34\u6c60\u62bd\u6837`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0398](https://leetcode.com/problems/random-pick-index)", "[Random Pick Index](/solution/0300-0399/0398.Random%20Pick%20Index/README_EN.md)", "`Reservoir Sampling`", "Medium", ""]}, {"question_id": "0397", "frontend_question_id": "0397", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/integer-replacement", "url_en": "https://leetcode.com/problems/integer-replacement", "relative_path_cn": "/solution/0300-0399/0397.Integer%20Replacement/README.md", "relative_path_en": "/solution/0300-0399/0397.Integer%20Replacement/README_EN.md", "title_cn": "\u6574\u6570\u66ff\u6362", "title_en": "Integer Replacement", "question_title_slug": "integer-replacement", "content_en": "

    Given a positive integer n, you can apply one of the following operations:

    \n\n
      \n\t
    1. If n is even, replace n with n / 2.
    2. \n\t
    3. If n is odd, replace n with either n + 1 or n - 1.
    4. \n
    \n\n

    Return the minimum number of operations needed for n to become 1.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 8\nOutput: 3\nExplanation: 8 -> 4 -> 2 -> 1\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 7\nOutput: 4\nExplanation: 7 -> 8 -> 4 -> 2 -> 1\nor 7 -> 6 -> 3 -> 2 -> 1\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 4\nOutput: 2\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 231 - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6b63\u6574\u6570\u00a0n \uff0c\u4f60\u53ef\u4ee5\u505a\u5982\u4e0b\u64cd\u4f5c\uff1a

    \n\n
      \n\t
    1. \u5982\u679c\u00a0n\u00a0\u662f\u5076\u6570\uff0c\u5219\u7528\u00a0n / 2\u66ff\u6362\u00a0n \u3002
    2. \n\t
    3. \u5982\u679c\u00a0n\u00a0\u662f\u5947\u6570\uff0c\u5219\u53ef\u4ee5\u7528\u00a0n + 1\u6216n - 1\u66ff\u6362\u00a0n \u3002
    4. \n
    \n\n

    n\u00a0\u53d8\u4e3a 1 \u6240\u9700\u7684\u6700\u5c0f\u66ff\u6362\u6b21\u6570\u662f\u591a\u5c11\uff1f

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 8\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a8 -> 4 -> 2 -> 1\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 7\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a7 -> 8 -> 4 -> 2 -> 1\n\u6216 7 -> 6 -> 3 -> 2 -> 1\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 4\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 231 - 1
    • \n
    \n", "tags_en": ["Bit Manipulation", "Math"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int integerReplacement(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int integerReplacement(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def integerReplacement(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def integerReplacement(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint integerReplacement(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int IntegerReplacement(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar integerReplacement = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef integer_replacement(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func integerReplacement(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func integerReplacement(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def integerReplacement(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun integerReplacement(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn integer_replacement(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function integerReplacement($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function integerReplacement(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (integer-replacement n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0397](https://leetcode-cn.com/problems/integer-replacement)", "[\u6574\u6570\u66ff\u6362](/solution/0300-0399/0397.Integer%20Replacement/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0397](https://leetcode.com/problems/integer-replacement)", "[Integer Replacement](/solution/0300-0399/0397.Integer%20Replacement/README_EN.md)", "`Bit Manipulation`,`Math`", "Medium", ""]}, {"question_id": "0396", "frontend_question_id": "0396", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/rotate-function", "url_en": "https://leetcode.com/problems/rotate-function", "relative_path_cn": "/solution/0300-0399/0396.Rotate%20Function/README.md", "relative_path_en": "/solution/0300-0399/0396.Rotate%20Function/README_EN.md", "title_cn": "\u65cb\u8f6c\u51fd\u6570", "title_en": "Rotate Function", "question_title_slug": "rotate-function", "content_en": "

    You are given an integer array nums of length n.

    \n\n

    Assume arrk to be an array obtained by rotating nums by k positions clock-wise. We define the rotation function F on nums as follow:

    \n\n
      \n\t
    • F(k) = 0 * arrk[0] + 1 * arrk[1] + ... + (n - 1) * arrk[n - 1].
    • \n
    \n\n

    Return the maximum value of F(0), F(1), ..., F(n-1).

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [4,3,2,6]\nOutput: 26\nExplanation:\nF(0) = (0 * 4) + (1 * 3) + (2 * 2) + (3 * 6) = 0 + 3 + 4 + 18 = 25\nF(1) = (0 * 6) + (1 * 4) + (2 * 3) + (3 * 2) = 0 + 4 + 6 + 6 = 16\nF(2) = (0 * 2) + (1 * 6) + (2 * 4) + (3 * 3) = 0 + 6 + 8 + 9 = 23\nF(3) = (0 * 3) + (1 * 2) + (2 * 6) + (3 * 4) = 0 + 2 + 12 + 12 = 26\nSo the maximum value of F(0), F(1), F(2), F(3) is F(3) = 26.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1000000007]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= n <= 3 * 104
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u6574\u6570\u6570\u7ec4 A \u3002

    \n\n

    \u5047\u8bbe Bk \u662f\u6570\u7ec4 A \u987a\u65f6\u9488\u65cb\u8f6c k \u4e2a\u4f4d\u7f6e\u540e\u7684\u6570\u7ec4\uff0c\u6211\u4eec\u5b9a\u4e49 A \u7684“\u65cb\u8f6c\u51fd\u6570” F \u4e3a\uff1a

    \n\n

    F(k) = 0 * Bk[0] + 1 * Bk[1] + ... + (n-1) * Bk[n-1]\u3002

    \n\n

    \u8ba1\u7b97F(0), F(1), ..., F(n-1)\u4e2d\u7684\u6700\u5927\u503c\u3002

    \n\n

    \u6ce8\u610f:
    \n\u53ef\u4ee5\u8ba4\u4e3a n \u7684\u503c\u5c0f\u4e8e 105\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \nA = [4, 3, 2, 6]\n\nF(0) = (0 * 4) + (1 * 3) + (2 * 2) + (3 * 6) = 0 + 3 + 4 + 18 = 25\nF(1) = (0 * 6) + (1 * 4) + (2 * 3) + (3 * 2) = 0 + 4 + 6 + 6 = 16\nF(2) = (0 * 2) + (1 * 6) + (2 * 4) + (3 * 3) = 0 + 6 + 8 + 9 = 23\nF(3) = (0 * 3) + (1 * 2) + (2 * 6) + (3 * 4) = 0 + 2 + 12 + 12 = 26\n\n\u6240\u4ee5 F(0), F(1), F(2), F(3) \u4e2d\u7684\u6700\u5927\u503c\u662f F(3) = 26 \u3002\n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxRotateFunction(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxRotateFunction(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxRotateFunction(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxRotateFunction(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxRotateFunction(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxRotateFunction(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar maxRotateFunction = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef max_rotate_function(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxRotateFunction(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxRotateFunction(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxRotateFunction(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxRotateFunction(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_rotate_function(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function maxRotateFunction($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxRotateFunction(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-rotate-function nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0396](https://leetcode-cn.com/problems/rotate-function)", "[\u65cb\u8f6c\u51fd\u6570](/solution/0300-0399/0396.Rotate%20Function/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0396](https://leetcode.com/problems/rotate-function)", "[Rotate Function](/solution/0300-0399/0396.Rotate%20Function/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "0395", "frontend_question_id": "0395", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-substring-with-at-least-k-repeating-characters", "url_en": "https://leetcode.com/problems/longest-substring-with-at-least-k-repeating-characters", "relative_path_cn": "/solution/0300-0399/0395.Longest%20Substring%20with%20At%20Least%20K%20Repeating%20Characters/README.md", "relative_path_en": "/solution/0300-0399/0395.Longest%20Substring%20with%20At%20Least%20K%20Repeating%20Characters/README_EN.md", "title_cn": "\u81f3\u5c11\u6709 K \u4e2a\u91cd\u590d\u5b57\u7b26\u7684\u6700\u957f\u5b50\u4e32", "title_en": "Longest Substring with At Least K Repeating Characters", "question_title_slug": "longest-substring-with-at-least-k-repeating-characters", "content_en": "

    Given a string s and an integer k, return the length of the longest substring of s such that the frequency of each character in this substring is greater than or equal to k.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "aaabb", k = 3\nOutput: 3\nExplanation: The longest substring is "aaa", as 'a' is repeated 3 times.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "ababbc", k = 2\nOutput: 5\nExplanation: The longest substring is "ababb", as 'a' is repeated 2 times and 'b' is repeated 3 times.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 104
    • \n\t
    • s consists of only lowercase English letters.
    • \n\t
    • 1 <= k <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \u548c\u4e00\u4e2a\u6574\u6570 k \uff0c\u8bf7\u4f60\u627e\u51fa s \u4e2d\u7684\u6700\u957f\u5b50\u4e32\uff0c\u00a0\u8981\u6c42\u8be5\u5b50\u4e32\u4e2d\u7684\u6bcf\u4e00\u5b57\u7b26\u51fa\u73b0\u6b21\u6570\u90fd\u4e0d\u5c11\u4e8e k \u3002\u8fd4\u56de\u8fd9\u4e00\u5b50\u4e32\u7684\u957f\u5ea6\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"aaabb\", k = 3\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6700\u957f\u5b50\u4e32\u4e3a \"aaa\" \uff0c\u5176\u4e2d 'a' \u91cd\u590d\u4e86 3 \u6b21\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"ababbc\", k = 2\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u6700\u957f\u5b50\u4e32\u4e3a \"ababb\" \uff0c\u5176\u4e2d 'a' \u91cd\u590d\u4e86 2 \u6b21\uff0c 'b' \u91cd\u590d\u4e86 3 \u6b21\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 104
    • \n\t
    • s \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n\t
    • 1 <= k <= 105
    • \n
    \n", "tags_en": ["Recursion", "Divide and Conquer", "Sliding Window"], "tags_cn": ["\u9012\u5f52", "\u5206\u6cbb\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int longestSubstring(string s, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int longestSubstring(String s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestSubstring(self, s, k):\n \"\"\"\n :type s: str\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestSubstring(self, s: str, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint longestSubstring(char * s, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LongestSubstring(string s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number} k\n * @return {number}\n */\nvar longestSubstring = function(s, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer} k\n# @return {Integer}\ndef longest_substring(s, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestSubstring(_ s: String, _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestSubstring(s string, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestSubstring(s: String, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestSubstring(s: String, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_substring(s: String, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer $k\n * @return Integer\n */\n function longestSubstring($s, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestSubstring(s: string, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-substring s k)\n (-> string? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0395](https://leetcode-cn.com/problems/longest-substring-with-at-least-k-repeating-characters)", "[\u81f3\u5c11\u6709 K \u4e2a\u91cd\u590d\u5b57\u7b26\u7684\u6700\u957f\u5b50\u4e32](/solution/0300-0399/0395.Longest%20Substring%20with%20At%20Least%20K%20Repeating%20Characters/README.md)", "`\u9012\u5f52`,`\u5206\u6cbb\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0395](https://leetcode.com/problems/longest-substring-with-at-least-k-repeating-characters)", "[Longest Substring with At Least K Repeating Characters](/solution/0300-0399/0395.Longest%20Substring%20with%20At%20Least%20K%20Repeating%20Characters/README_EN.md)", "`Recursion`,`Divide and Conquer`,`Sliding Window`", "Medium", ""]}, {"question_id": "0394", "frontend_question_id": "0394", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/decode-string", "url_en": "https://leetcode.com/problems/decode-string", "relative_path_cn": "/solution/0300-0399/0394.Decode%20String/README.md", "relative_path_en": "/solution/0300-0399/0394.Decode%20String/README_EN.md", "title_cn": "\u5b57\u7b26\u4e32\u89e3\u7801", "title_en": "Decode String", "question_title_slug": "decode-string", "content_en": "

    Given an encoded string, return its decoded string.

    \n\n

    The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note that k is guaranteed to be a positive integer.

    \n\n

    You may assume that the input string is always valid; No extra white spaces, square brackets are well-formed, etc.

    \n\n

    Furthermore, you may assume that the original data does not contain any digits and that digits are only for those repeat numbers, k. For example, there won't be input like 3a or 2[4].

    \n\n

     

    \n

    Example 1:

    \n
    Input: s = \"3[a]2[bc]\"\nOutput: \"aaabcbc\"\n

    Example 2:

    \n
    Input: s = \"3[a2[c]]\"\nOutput: \"accaccacc\"\n

    Example 3:

    \n
    Input: s = \"2[abc]3[cd]ef\"\nOutput: \"abcabccdcdcdef\"\n

    Example 4:

    \n
    Input: s = \"abc3[cd]xyz\"\nOutput: \"abccdcdcdxyz\"\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 30
    • \n\t
    • s consists of lowercase English letters, digits, and square brackets '[]'.
    • \n\t
    • s is guaranteed to be a valid input.
    • \n\t
    • All the integers in s are in the range [1, 300].
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u7ecf\u8fc7\u7f16\u7801\u7684\u5b57\u7b26\u4e32\uff0c\u8fd4\u56de\u5b83\u89e3\u7801\u540e\u7684\u5b57\u7b26\u4e32\u3002

    \n\n

    \u7f16\u7801\u89c4\u5219\u4e3a: k[encoded_string]\uff0c\u8868\u793a\u5176\u4e2d\u65b9\u62ec\u53f7\u5185\u90e8\u7684 encoded_string \u6b63\u597d\u91cd\u590d k \u6b21\u3002\u6ce8\u610f k \u4fdd\u8bc1\u4e3a\u6b63\u6574\u6570\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u8ba4\u4e3a\u8f93\u5165\u5b57\u7b26\u4e32\u603b\u662f\u6709\u6548\u7684\uff1b\u8f93\u5165\u5b57\u7b26\u4e32\u4e2d\u6ca1\u6709\u989d\u5916\u7684\u7a7a\u683c\uff0c\u4e14\u8f93\u5165\u7684\u65b9\u62ec\u53f7\u603b\u662f\u7b26\u5408\u683c\u5f0f\u8981\u6c42\u7684\u3002

    \n\n

    \u6b64\u5916\uff0c\u4f60\u53ef\u4ee5\u8ba4\u4e3a\u539f\u59cb\u6570\u636e\u4e0d\u5305\u542b\u6570\u5b57\uff0c\u6240\u6709\u7684\u6570\u5b57\u53ea\u8868\u793a\u91cd\u590d\u7684\u6b21\u6570 k \uff0c\u4f8b\u5982\u4e0d\u4f1a\u51fa\u73b0\u50cf 3a \u6216 2[4] \u7684\u8f93\u5165\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1as = "3[a]2[bc]"\n\u8f93\u51fa\uff1a"aaabcbc"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1as = "3[a2[c]]"\n\u8f93\u51fa\uff1a"accaccacc"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1as = "2[abc]3[cd]ef"\n\u8f93\u51fa\uff1a"abcabccdcdcdef"\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1as = "abc3[cd]xyz"\n\u8f93\u51fa\uff1a"abccdcdcdxyz"\n
    \n", "tags_en": ["Stack", "Depth-first Search"], "tags_cn": ["\u6808", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string decodeString(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String decodeString(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def decodeString(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def decodeString(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * decodeString(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string DecodeString(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar decodeString = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef decode_string(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func decodeString(_ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func decodeString(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def decodeString(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun decodeString(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn decode_string(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function decodeString($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function decodeString(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (decode-string s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0394](https://leetcode-cn.com/problems/decode-string)", "[\u5b57\u7b26\u4e32\u89e3\u7801](/solution/0300-0399/0394.Decode%20String/README.md)", "`\u6808`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0394](https://leetcode.com/problems/decode-string)", "[Decode String](/solution/0300-0399/0394.Decode%20String/README_EN.md)", "`Stack`,`Depth-first Search`", "Medium", ""]}, {"question_id": "0393", "frontend_question_id": "0393", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/utf-8-validation", "url_en": "https://leetcode.com/problems/utf-8-validation", "relative_path_cn": "/solution/0300-0399/0393.UTF-8%20Validation/README.md", "relative_path_en": "/solution/0300-0399/0393.UTF-8%20Validation/README_EN.md", "title_cn": "UTF-8 \u7f16\u7801\u9a8c\u8bc1", "title_en": "UTF-8 Validation", "question_title_slug": "utf-8-validation", "content_en": "

    Given an integer array data representing the data, return whether it is a valid UTF-8 encoding.

    \n\n

    A character in UTF8 can be from 1 to 4 bytes long, subjected to the following rules:

    \n\n
      \n\t
    1. For a 1-byte character, the first bit is a 0, followed by its Unicode code.
    2. \n\t
    3. For an n-bytes character, the first n bits are all one's, the n + 1 bit is 0, followed by n - 1 bytes with the most significant 2 bits being 10.
    4. \n
    \n\n

    This is how the UTF-8 encoding would work:

    \n\n
    \n   Char. number range  |        UTF-8 octet sequence\n      (hexadecimal)    |              (binary)\n   --------------------+---------------------------------------------\n   0000 0000-0000 007F | 0xxxxxxx\n   0000 0080-0000 07FF | 110xxxxx 10xxxxxx\n   0000 0800-0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx\n   0001 0000-0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx\n
    \n\n

    Note: The input is an array of integers. Only the least significant 8 bits of each integer is used to store the data. This means each integer represents only 1 byte of data.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: data = [197,130,1]\nOutput: true\nExplanation: data represents the octet sequence: 11000101 10000010 00000001.\nIt is a valid utf-8 encoding for a 2-bytes character followed by a 1-byte character.\n
    \n\n

    Example 2:

    \n\n
    \nInput: data = [235,140,4]\nOutput: false\nExplanation: data represented the octet sequence: 11101011 10001100 00000100.\nThe first 3 bits are all one's and the 4th bit is 0 means it is a 3-bytes character.\nThe next byte is a continuation byte which starts with 10 and that's correct.\nBut the second continuation byte does not start with 10, so it is invalid.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= data.length <= 2 * 104
    • \n\t
    • 0 <= data[i] <= 255
    • \n
    \n", "content_cn": "

    UTF-8 \u4e2d\u7684\u4e00\u4e2a\u5b57\u7b26\u53ef\u80fd\u7684\u957f\u5ea6\u4e3a 1 \u5230 4 \u5b57\u8282\uff0c\u9075\u5faa\u4ee5\u4e0b\u7684\u89c4\u5219\uff1a

    \n\n
      \n\t
    1. \u5bf9\u4e8e 1 \u5b57\u8282\u7684\u5b57\u7b26\uff0c\u5b57\u8282\u7684\u7b2c\u4e00\u4f4d\u8bbe\u4e3a 0 \uff0c\u540e\u9762 7 \u4f4d\u4e3a\u8fd9\u4e2a\u7b26\u53f7\u7684 unicode \u7801\u3002
    2. \n\t
    3. \u5bf9\u4e8e n \u5b57\u8282\u7684\u5b57\u7b26 (n > 1)\uff0c\u7b2c\u4e00\u4e2a\u5b57\u8282\u7684\u524d n \u4f4d\u90fd\u8bbe\u4e3a1\uff0c\u7b2c n+1 \u4f4d\u8bbe\u4e3a 0 \uff0c\u540e\u9762\u5b57\u8282\u7684\u524d\u4e24\u4f4d\u4e00\u5f8b\u8bbe\u4e3a 10 \u3002\u5269\u4e0b\u7684\u6ca1\u6709\u63d0\u53ca\u7684\u4e8c\u8fdb\u5236\u4f4d\uff0c\u5168\u90e8\u4e3a\u8fd9\u4e2a\u7b26\u53f7\u7684 unicode \u7801\u3002
    4. \n
    \n\n

    \u8fd9\u662f UTF-8 \u7f16\u7801\u7684\u5de5\u4f5c\u65b9\u5f0f\uff1a

    \n\n
    \n   Char. number range  |        UTF-8 octet sequence\n      (hexadecimal)    |              (binary)\n   --------------------+---------------------------------------------\n   0000 0000-0000 007F | 0xxxxxxx\n   0000 0080-0000 07FF | 110xxxxx 10xxxxxx\n   0000 0800-0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx\n   0001 0000-0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx\n
    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u8868\u793a\u6570\u636e\u7684\u6574\u6570\u6570\u7ec4\uff0c\u8fd4\u56de\u5b83\u662f\u5426\u4e3a\u6709\u6548\u7684 utf-8 \u7f16\u7801\u3002

    \n\n

    \u6ce8\u610f\uff1a
    \n\u8f93\u5165\u662f\u6574\u6570\u6570\u7ec4\u3002\u53ea\u6709\u6bcf\u4e2a\u6574\u6570\u7684 \u6700\u4f4e 8 \u4e2a\u6709\u6548\u4f4d \u7528\u6765\u5b58\u50a8\u6570\u636e\u3002\u8fd9\u610f\u5473\u7740\u6bcf\u4e2a\u6574\u6570\u53ea\u8868\u793a 1 \u5b57\u8282\u7684\u6570\u636e\u3002

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \ndata = [197, 130, 1], \u8868\u793a 8 \u4f4d\u7684\u5e8f\u5217: 11000101 10000010 00000001.\n\n\u8fd4\u56de true \u3002\n\u8fd9\u662f\u6709\u6548\u7684 utf-8 \u7f16\u7801\uff0c\u4e3a\u4e00\u4e2a2\u5b57\u8282\u5b57\u7b26\uff0c\u8ddf\u7740\u4e00\u4e2a1\u5b57\u8282\u5b57\u7b26\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \ndata = [235, 140, 4], \u8868\u793a 8 \u4f4d\u7684\u5e8f\u5217: 11101011 10001100 00000100.\n\n\u8fd4\u56de false \u3002\n\u524d 3 \u4f4d\u90fd\u662f 1 \uff0c\u7b2c 4 \u4f4d\u4e3a 0 \u8868\u793a\u5b83\u662f\u4e00\u4e2a3\u5b57\u8282\u5b57\u7b26\u3002\n\u4e0b\u4e00\u4e2a\u5b57\u8282\u662f\u5f00\u5934\u4e3a 10 \u7684\u5ef6\u7eed\u5b57\u8282\uff0c\u8fd9\u662f\u6b63\u786e\u7684\u3002\n\u4f46\u7b2c\u4e8c\u4e2a\u5ef6\u7eed\u5b57\u8282\u4e0d\u4ee5 10 \u5f00\u5934\uff0c\u6240\u4ee5\u662f\u4e0d\u7b26\u5408\u89c4\u5219\u7684\u3002\n
    \n", "tags_en": ["Bit Manipulation"], "tags_cn": ["\u4f4d\u8fd0\u7b97"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool validUtf8(vector& data) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean validUtf8(int[] data) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def validUtf8(self, data):\n \"\"\"\n :type data: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def validUtf8(self, data: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool validUtf8(int* data, int dataSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool ValidUtf8(int[] data) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} data\n * @return {boolean}\n */\nvar validUtf8 = function(data) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} data\n# @return {Boolean}\ndef valid_utf8(data)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func validUtf8(_ data: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func validUtf8(data []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def validUtf8(data: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun validUtf8(data: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn valid_utf8(data: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $data\n * @return Boolean\n */\n function validUtf8($data) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function validUtf8(data: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (valid-utf8 data)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0393](https://leetcode-cn.com/problems/utf-8-validation)", "[UTF-8 \u7f16\u7801\u9a8c\u8bc1](/solution/0300-0399/0393.UTF-8%20Validation/README.md)", "`\u4f4d\u8fd0\u7b97`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0393](https://leetcode.com/problems/utf-8-validation)", "[UTF-8 Validation](/solution/0300-0399/0393.UTF-8%20Validation/README_EN.md)", "`Bit Manipulation`", "Medium", ""]}, {"question_id": "0392", "frontend_question_id": "0392", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/is-subsequence", "url_en": "https://leetcode.com/problems/is-subsequence", "relative_path_cn": "/solution/0300-0399/0392.Is%20Subsequence/README.md", "relative_path_en": "/solution/0300-0399/0392.Is%20Subsequence/README_EN.md", "title_cn": "\u5224\u65ad\u5b50\u5e8f\u5217", "title_en": "Is Subsequence", "question_title_slug": "is-subsequence", "content_en": "

    Given two strings s and t, return true if s is a subsequence of t, or false otherwise.

    \n\n

    A subsequence of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., "ace" is a subsequence of "abcde" while "aec" is not).

    \n\n

     

    \n

    Example 1:

    \n
    Input: s = \"abc\", t = \"ahbgdc\"\nOutput: true\n

    Example 2:

    \n
    Input: s = \"axc\", t = \"ahbgdc\"\nOutput: false\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= s.length <= 100
    • \n\t
    • 0 <= t.length <= 104
    • \n\t
    • s and t consist only of lowercase English letters.
    • \n
    \n\n

     

    \nFollow up: Suppose there are lots of incoming s, say s1, s2, ..., sk where k >= 109, and you want to check one by one to see if t has its subsequence. In this scenario, how would you change your code?", "content_cn": "

    \u7ed9\u5b9a\u5b57\u7b26\u4e32 s \u548c t \uff0c\u5224\u65ad s \u662f\u5426\u4e3a t \u7684\u5b50\u5e8f\u5217\u3002

    \n\n

    \u5b57\u7b26\u4e32\u7684\u4e00\u4e2a\u5b50\u5e8f\u5217\u662f\u539f\u59cb\u5b57\u7b26\u4e32\u5220\u9664\u4e00\u4e9b\uff08\u4e5f\u53ef\u4ee5\u4e0d\u5220\u9664\uff09\u5b57\u7b26\u800c\u4e0d\u6539\u53d8\u5269\u4f59\u5b57\u7b26\u76f8\u5bf9\u4f4d\u7f6e\u5f62\u6210\u7684\u65b0\u5b57\u7b26\u4e32\u3002\uff08\u4f8b\u5982\uff0c\"ace\"\u662f\"abcde\"\u7684\u4e00\u4e2a\u5b50\u5e8f\u5217\uff0c\u800c\"aec\"\u4e0d\u662f\uff09\u3002

    \n\n

    \u8fdb\u9636\uff1a

    \n\n

    \u5982\u679c\u6709\u5927\u91cf\u8f93\u5165\u7684 S\uff0c\u79f0\u4f5c S1, S2, ... , Sk \u5176\u4e2d k >= 10\u4ebf\uff0c\u4f60\u9700\u8981\u4f9d\u6b21\u68c0\u67e5\u5b83\u4eec\u662f\u5426\u4e3a T \u7684\u5b50\u5e8f\u5217\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u4f60\u4f1a\u600e\u6837\u6539\u53d8\u4ee3\u7801\uff1f

    \n\n

    \u81f4\u8c22\uff1a

    \n\n

    \u7279\u522b\u611f\u8c22 @pbrother\u00a0\u6dfb\u52a0\u6b64\u95ee\u9898\u5e76\u4e14\u521b\u5efa\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"abc\", t = \"ahbgdc\"\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"axc\", t = \"ahbgdc\"\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= s.length <= 100
    • \n\t
    • 0 <= t.length <= 10^4
    • \n\t
    • \u4e24\u4e2a\u5b57\u7b26\u4e32\u90fd\u53ea\u7531\u5c0f\u5199\u5b57\u7b26\u7ec4\u6210\u3002
    • \n
    \n", "tags_en": ["Greedy", "Binary Search", "Dynamic Programming"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u4e8c\u5206\u67e5\u627e", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isSubsequence(string s, string t) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isSubsequence(String s, String t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isSubsequence(self, s, t):\n \"\"\"\n :type s: str\n :type t: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isSubsequence(self, s: str, t: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isSubsequence(char * s, char * t){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsSubsequence(string s, string t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string} t\n * @return {boolean}\n */\nvar isSubsequence = function(s, t) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String} t\n# @return {Boolean}\ndef is_subsequence(s, t)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isSubsequence(_ s: String, _ t: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isSubsequence(s string, t string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isSubsequence(s: String, t: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isSubsequence(s: String, t: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_subsequence(s: String, t: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String $t\n * @return Boolean\n */\n function isSubsequence($s, $t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isSubsequence(s: string, t: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-subsequence s t)\n (-> string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0392](https://leetcode-cn.com/problems/is-subsequence)", "[\u5224\u65ad\u5b50\u5e8f\u5217](/solution/0300-0399/0392.Is%20Subsequence/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u4e8c\u5206\u67e5\u627e`,`\u52a8\u6001\u89c4\u5212`", "\u7b80\u5355", ""], "md_table_row_en": ["[0392](https://leetcode.com/problems/is-subsequence)", "[Is Subsequence](/solution/0300-0399/0392.Is%20Subsequence/README_EN.md)", "`Greedy`,`Binary Search`,`Dynamic Programming`", "Easy", ""]}, {"question_id": "0391", "frontend_question_id": "0391", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/perfect-rectangle", "url_en": "https://leetcode.com/problems/perfect-rectangle", "relative_path_cn": "/solution/0300-0399/0391.Perfect%20Rectangle/README.md", "relative_path_en": "/solution/0300-0399/0391.Perfect%20Rectangle/README_EN.md", "title_cn": "\u5b8c\u7f8e\u77e9\u5f62", "title_en": "Perfect Rectangle", "question_title_slug": "perfect-rectangle", "content_en": "

    Given an array rectangles where rectangles[i] = [xi, yi, ai, bi] represents an axis-aligned rectangle. The bottom-left point of the rectangle is (xi, yi) and the top-right point of it is (ai, bi).

    \n\n

    Return true if all the rectangles together form an exact cover of a rectangular region.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: rectangles = [[1,1,3,3],[3,1,4,2],[3,2,4,4],[1,3,2,4],[2,3,3,4]]\nOutput: true\nExplanation: All 5 rectangles together form an exact cover of a rectangular region.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: rectangles = [[1,1,2,3],[1,3,2,4],[3,1,4,2],[3,2,4,4]]\nOutput: false\nExplanation: Because there is a gap between the two rectangular regions.\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: rectangles = [[1,1,3,3],[3,1,4,2],[1,3,2,4],[3,2,4,4]]\nOutput: false\nExplanation: Because there is a gap in the top center.\n
    \n\n

    Example 4:

    \n\"\"\n
    \nInput: rectangles = [[1,1,3,3],[3,1,4,2],[1,3,2,4],[2,2,4,4]]\nOutput: false\nExplanation: Because two of the rectangles overlap with each other.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= rectangles.length <= 2 * 104
    • \n\t
    • rectangles[i].length == 4
    • \n\t
    • -105 <= xi, yi, ai, bi <= 105
    • \n
    \n", "content_cn": "

    \u6211\u4eec\u6709 N \u4e2a\u4e0e\u5750\u6807\u8f74\u5bf9\u9f50\u7684\u77e9\u5f62, \u5176\u4e2d N > 0, \u5224\u65ad\u5b83\u4eec\u662f\u5426\u80fd\u7cbe\u786e\u5730\u8986\u76d6\u4e00\u4e2a\u77e9\u5f62\u533a\u57df\u3002

    \n\n

    \u6bcf\u4e2a\u77e9\u5f62\u7528\u5de6\u4e0b\u89d2\u7684\u70b9\u548c\u53f3\u4e0a\u89d2\u7684\u70b9\u7684\u5750\u6807\u6765\u8868\u793a\u3002\u4f8b\u5982\uff0c \u4e00\u4e2a\u5355\u4f4d\u6b63\u65b9\u5f62\u53ef\u4ee5\u8868\u793a\u4e3a [1,1,2,2]\u3002 ( \u5de6\u4e0b\u89d2\u7684\u70b9\u7684\u5750\u6807\u4e3a (1, 1) \u4ee5\u53ca\u53f3\u4e0a\u89d2\u7684\u70b9\u7684\u5750\u6807\u4e3a (2, 2) )\u3002

    \n\n

    \n\n

    \u793a\u4f8b 1:

    \n\n
    rectangles = [\n  [1,1,3,3],\n  [3,1,4,2],\n  [3,2,4,4],\n  [1,3,2,4],\n  [2,3,3,4]\n]\n\n\u8fd4\u56de true\u30025\u4e2a\u77e9\u5f62\u4e00\u8d77\u53ef\u4ee5\u7cbe\u786e\u5730\u8986\u76d6\u4e00\u4e2a\u77e9\u5f62\u533a\u57df\u3002\n
    \n\n

     

    \n\n

    \n\n

    \u793a\u4f8b 2:

    \n\n
    rectangles = [\n  [1,1,2,3],\n  [1,3,2,4],\n  [3,1,4,2],\n  [3,2,4,4]\n]\n\n\u8fd4\u56de false\u3002\u4e24\u4e2a\u77e9\u5f62\u4e4b\u95f4\u6709\u95f4\u9694\uff0c\u65e0\u6cd5\u8986\u76d6\u6210\u4e00\u4e2a\u77e9\u5f62\u3002\n
    \n\n

     

    \n\n

    \n\n

    \u793a\u4f8b 3:

    \n\n
    rectangles = [\n  [1,1,3,3],\n  [3,1,4,2],\n  [1,3,2,4],\n  [3,2,4,4]\n]\n\n\u8fd4\u56de false\u3002\u56fe\u5f62\u9876\u7aef\u7559\u6709\u95f4\u9694\uff0c\u65e0\u6cd5\u8986\u76d6\u6210\u4e00\u4e2a\u77e9\u5f62\u3002\n
    \n\n

     

    \n\n

    \n\n

    \u793a\u4f8b 4:

    \n\n
    rectangles = [\n  [1,1,3,3],\n  [3,1,4,2],\n  [1,3,2,4],\n  [2,2,4,4]\n]\n\n\u8fd4\u56de false\u3002\u56e0\u4e3a\u4e2d\u95f4\u6709\u76f8\u4ea4\u533a\u57df\uff0c\u867d\u7136\u5f62\u6210\u4e86\u77e9\u5f62\uff0c\u4f46\u4e0d\u662f\u7cbe\u786e\u8986\u76d6\u3002\n
    \n", "tags_en": ["Line Sweep"], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isRectangleCover(vector>& rectangles) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isRectangleCover(int[][] rectangles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isRectangleCover(self, rectangles):\n \"\"\"\n :type rectangles: List[List[int]]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isRectangleCover(self, rectangles: List[List[int]]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isRectangleCover(int** rectangles, int rectanglesSize, int* rectanglesColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsRectangleCover(int[][] rectangles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} rectangles\n * @return {boolean}\n */\nvar isRectangleCover = function(rectangles) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} rectangles\n# @return {Boolean}\ndef is_rectangle_cover(rectangles)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isRectangleCover(_ rectangles: [[Int]]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isRectangleCover(rectangles [][]int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isRectangleCover(rectangles: Array[Array[Int]]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isRectangleCover(rectangles: Array): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_rectangle_cover(rectangles: Vec>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $rectangles\n * @return Boolean\n */\n function isRectangleCover($rectangles) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isRectangleCover(rectangles: number[][]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-rectangle-cover rectangles)\n (-> (listof (listof exact-integer?)) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0391](https://leetcode-cn.com/problems/perfect-rectangle)", "[\u5b8c\u7f8e\u77e9\u5f62](/solution/0300-0399/0391.Perfect%20Rectangle/README.md)", "", "\u56f0\u96be", ""], "md_table_row_en": ["[0391](https://leetcode.com/problems/perfect-rectangle)", "[Perfect Rectangle](/solution/0300-0399/0391.Perfect%20Rectangle/README_EN.md)", "`Line Sweep`", "Hard", ""]}, {"question_id": "0390", "frontend_question_id": "0390", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/elimination-game", "url_en": "https://leetcode.com/problems/elimination-game", "relative_path_cn": "/solution/0300-0399/0390.Elimination%20Game/README.md", "relative_path_en": "/solution/0300-0399/0390.Elimination%20Game/README_EN.md", "title_cn": "\u6d88\u9664\u6e38\u620f", "title_en": "Elimination Game", "question_title_slug": "elimination-game", "content_en": "

    You have a list arr of all integers in the range [1, n] sorted in a strictly increasing order. Apply the following algorithm on arr:

    \n\n
      \n\t
    • Starting from left to right, remove the first number and every other number afterward until you reach the end of the list.
    • \n\t
    • Repeat the previous step again, but this time from right to left, remove the rightmost number and every other number from the remaining numbers.
    • \n\t
    • Keep repeating the steps again, alternating left to right and right to left, until a single number remains.
    • \n
    \n\n

    Given the integer n, return the last number that remains in arr.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 9\nOutput: 6\nExplanation:\narr = [1, 2, 3, 4, 5, 6, 7, 8, 9]\narr = [2, 4, 6, 8]\narr = [2, 6]\narr = [6]\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 1\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4ece1 \u5230 n \u6392\u5e8f\u7684\u6574\u6570\u5217\u8868\u3002
    \n\u9996\u5148\uff0c\u4ece\u5de6\u5230\u53f3\uff0c\u4ece\u7b2c\u4e00\u4e2a\u6570\u5b57\u5f00\u59cb\uff0c\u6bcf\u9694\u4e00\u4e2a\u6570\u5b57\u8fdb\u884c\u5220\u9664\uff0c\u76f4\u5230\u5217\u8868\u7684\u672b\u5c3e\u3002
    \n\u7b2c\u4e8c\u6b65\uff0c\u5728\u5269\u4e0b\u7684\u6570\u5b57\u4e2d\uff0c\u4ece\u53f3\u5230\u5de6\uff0c\u4ece\u5012\u6570\u7b2c\u4e00\u4e2a\u6570\u5b57\u5f00\u59cb\uff0c\u6bcf\u9694\u4e00\u4e2a\u6570\u5b57\u8fdb\u884c\u5220\u9664\uff0c\u76f4\u5230\u5217\u8868\u5f00\u5934\u3002
    \n\u6211\u4eec\u4e0d\u65ad\u91cd\u590d\u8fd9\u4e24\u6b65\uff0c\u4ece\u5de6\u5230\u53f3\u548c\u4ece\u53f3\u5230\u5de6\u4ea4\u66ff\u8fdb\u884c\uff0c\u76f4\u5230\u53ea\u5269\u4e0b\u4e00\u4e2a\u6570\u5b57\u3002
    \n\u8fd4\u56de\u957f\u5ea6\u4e3a n \u7684\u5217\u8868\u4e2d\uff0c\u6700\u540e\u5269\u4e0b\u7684\u6570\u5b57\u3002

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165:\nn = 9,\n1 2 3 4 5 6 7 8 9\n2 4 6 8\n2 6\n6\n\n\u8f93\u51fa:\n6
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int lastRemaining(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int lastRemaining(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def lastRemaining(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def lastRemaining(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint lastRemaining(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LastRemaining(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar lastRemaining = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef last_remaining(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func lastRemaining(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func lastRemaining(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def lastRemaining(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun lastRemaining(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn last_remaining(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function lastRemaining($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function lastRemaining(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (last-remaining n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0390](https://leetcode-cn.com/problems/elimination-game)", "[\u6d88\u9664\u6e38\u620f](/solution/0300-0399/0390.Elimination%20Game/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0390](https://leetcode.com/problems/elimination-game)", "[Elimination Game](/solution/0300-0399/0390.Elimination%20Game/README_EN.md)", "", "Medium", ""]}, {"question_id": "0389", "frontend_question_id": "0389", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-the-difference", "url_en": "https://leetcode.com/problems/find-the-difference", "relative_path_cn": "/solution/0300-0399/0389.Find%20the%20Difference/README.md", "relative_path_en": "/solution/0300-0399/0389.Find%20the%20Difference/README_EN.md", "title_cn": "\u627e\u4e0d\u540c", "title_en": "Find the Difference", "question_title_slug": "find-the-difference", "content_en": "

    You are given two strings s and t.

    \n\n

    String t is generated by random shuffling string s and then add one more letter at a random position.

    \n\n

    Return the letter that was added to t.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "abcd", t = "abcde"\nOutput: "e"\nExplanation: 'e' is the letter that was added.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "", t = "y"\nOutput: "y"\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "a", t = "aa"\nOutput: "a"\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "ae", t = "aea"\nOutput: "a"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= s.length <= 1000
    • \n\t
    • t.length == s.length + 1
    • \n\t
    • s and t consist of lower-case English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u5b57\u7b26\u4e32 s \u548c t\uff0c\u5b83\u4eec\u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd\u3002

    \n\n

    \u5b57\u7b26\u4e32 t \u7531\u5b57\u7b26\u4e32 s \u968f\u673a\u91cd\u6392\uff0c\u7136\u540e\u5728\u968f\u673a\u4f4d\u7f6e\u6dfb\u52a0\u4e00\u4e2a\u5b57\u6bcd\u3002

    \n\n

    \u8bf7\u627e\u51fa\u5728 t \u4e2d\u88ab\u6dfb\u52a0\u7684\u5b57\u6bcd\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1as = "abcd", t = "abcde"\n\u8f93\u51fa\uff1a"e"\n\u89e3\u91ca\uff1a'e' \u662f\u90a3\u4e2a\u88ab\u6dfb\u52a0\u7684\u5b57\u6bcd\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1as = "", t = "y"\n\u8f93\u51fa\uff1a"y"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1as = "a", t = "aa"\n\u8f93\u51fa\uff1a"a"\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1as = "ae", t = "aea"\n\u8f93\u51fa\uff1a"a"\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= s.length <= 1000
    • \n\t
    • t.length == s.length + 1
    • \n\t
    • s \u548c t \u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd
    • \n
    \n", "tags_en": ["Bit Manipulation", "Hash Table"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n char findTheDifference(string s, string t) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public char findTheDifference(String s, String t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findTheDifference(self, s, t):\n \"\"\"\n :type s: str\n :type t: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findTheDifference(self, s: str, t: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar findTheDifference(char * s, char * t){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public char FindTheDifference(string s, string t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string} t\n * @return {character}\n */\nvar findTheDifference = function(s, t) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String} t\n# @return {Character}\ndef find_the_difference(s, t)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findTheDifference(_ s: String, _ t: String) -> Character {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findTheDifference(s string, t string) byte {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findTheDifference(s: String, t: String): Char = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findTheDifference(s: String, t: String): Char {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_the_difference(s: String, t: String) -> char {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String $t\n * @return String\n */\n function findTheDifference($s, $t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findTheDifference(s: string, t: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-the-difference s t)\n (-> string? string? char?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0389](https://leetcode-cn.com/problems/find-the-difference)", "[\u627e\u4e0d\u540c](/solution/0300-0399/0389.Find%20the%20Difference/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0389](https://leetcode.com/problems/find-the-difference)", "[Find the Difference](/solution/0300-0399/0389.Find%20the%20Difference/README_EN.md)", "`Bit Manipulation`,`Hash Table`", "Easy", ""]}, {"question_id": "0388", "frontend_question_id": "0388", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-absolute-file-path", "url_en": "https://leetcode.com/problems/longest-absolute-file-path", "relative_path_cn": "/solution/0300-0399/0388.Longest%20Absolute%20File%20Path/README.md", "relative_path_en": "/solution/0300-0399/0388.Longest%20Absolute%20File%20Path/README_EN.md", "title_cn": "\u6587\u4ef6\u7684\u6700\u957f\u7edd\u5bf9\u8def\u5f84", "title_en": "Longest Absolute File Path", "question_title_slug": "longest-absolute-file-path", "content_en": "

    Suppose we have a file system that stores both files and directories. An example of one system is represented in the following picture:

    \n\n

    \"\"

    \n\n

    Here, we have dir as the only directory in the root. dir contains two subdirectories, subdir1 and subdir2. subdir1 contains a file file1.ext and subdirectory subsubdir1. subdir2 contains a subdirectory subsubdir2, which contains a file file2.ext.

    \n\n

    In text form, it looks like this (with \u27f6 representing the tab character):

    \n\n
    \ndir\n\u27f6 subdir1\n\u27f6 \u27f6 file1.ext\n\u27f6 \u27f6 subsubdir1\n\u27f6 subdir2\n\u27f6 \u27f6 subsubdir2\n\u27f6 \u27f6 \u27f6 file2.ext\n
    \n\n

    If we were to write this representation in code, it will look like this: "dir\\n\\tsubdir1\\n\\t\\tfile1.ext\\n\\t\\tsubsubdir1\\n\\tsubdir2\\n\\t\\tsubsubdir2\\n\\t\\t\\tfile2.ext". Note that the '\\n' and '\\t' are the new-line and tab characters.

    \n\n

    Every file and directory has a unique absolute path in the file system, which is the order of directories that must be opened to reach the file/directory itself, all concatenated by '/'s. Using the above example, the absolute path to file2.ext is "dir/subdir2/subsubdir2/file2.ext". Each directory name consists of letters, digits, and/or spaces. Each file name is of the form name.extension, where name and extension consist of letters, digits, and/or spaces.

    \n\n

    Given a string input representing the file system in the explained format, return the length of the longest absolute path to a file in the abstracted file system. If there is no file in the system, return 0.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: input = "dir\\n\\tsubdir1\\n\\tsubdir2\\n\\t\\tfile.ext"\nOutput: 20\nExplanation: We have only one file, and the absolute path is "dir/subdir2/file.ext" of length 20.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: input = "dir\\n\\tsubdir1\\n\\t\\tfile1.ext\\n\\t\\tsubsubdir1\\n\\tsubdir2\\n\\t\\tsubsubdir2\\n\\t\\t\\tfile2.ext"\nOutput: 32\nExplanation: We have two files:\n"dir/subdir1/file1.ext" of length 21\n"dir/subdir2/subsubdir2/file2.ext" of length 32.\nWe return 32 since it is the longest absolute path to a file.\n
    \n\n

    Example 3:

    \n\n
    \nInput: input = "a"\nOutput: 0\nExplanation: We do not have any files, just a single directory named "a".\n
    \n\n

    Example 4:

    \n\n
    \nInput: input = "file1.txt\\nfile2.txt\\nlongfile.txt"\nOutput: 12\nExplanation: There are 3 files at the root directory.\nSince the absolute path for anything at the root directory is just the name itself, the answer is "longfile.txt" with length 12.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= input.length <= 104
    • \n\t
    • input may contain lowercase or uppercase English letters, a new line character '\\n', a tab character '\\t', a dot '.', a space ' ', and digits.
    • \n
    \n", "content_cn": "

    \u5047\u8bbe\u6587\u4ef6\u7cfb\u7edf\u5982\u4e0b\u56fe\u6240\u793a\uff1a

    \n\n

    \"\"

    \n\n

    \u8fd9\u91cc\u5c06 dir \u4f5c\u4e3a\u6839\u76ee\u5f55\u4e2d\u7684\u552f\u4e00\u76ee\u5f55\u3002dir \u5305\u542b\u4e24\u4e2a\u5b50\u76ee\u5f55 subdir1 \u548c subdir2 \u3002subdir1 \u5305\u542b\u6587\u4ef6 file1.ext \u548c\u5b50\u76ee\u5f55 subsubdir1\uff1bsubdir2 \u5305\u542b\u5b50\u76ee\u5f55 subsubdir2\uff0c\u8be5\u5b50\u76ee\u5f55\u4e0b\u5305\u542b\u6587\u4ef6 file2.ext \u3002

    \n\n

    \u5728\u6587\u672c\u683c\u5f0f\u4e2d\uff0c\u5982\u4e0b\u6240\u793a(\u27f6\u8868\u793a\u5236\u8868\u7b26)\uff1a

    \n\n
    \ndir\n\u27f6 subdir1\n\u27f6 \u27f6 file1.ext\n\u27f6 \u27f6 subsubdir1\n\u27f6 subdir2\n\u27f6 \u27f6 subsubdir2\n\u27f6 \u27f6 \u27f6 file2.ext\n
    \n\n

    \u5982\u679c\u662f\u4ee3\u7801\u8868\u793a\uff0c\u4e0a\u9762\u7684\u6587\u4ef6\u7cfb\u7edf\u53ef\u4ee5\u5199\u4e3a \"dir\\n\\tsubdir1\\n\\t\\tfile1.ext\\n\\t\\tsubsubdir1\\n\\tsubdir2\\n\\t\\tsubsubdir2\\n\\t\\t\\tfile2.ext\" \u3002'\\n' \u548c '\\t' \u5206\u522b\u662f\u6362\u884c\u7b26\u548c\u5236\u8868\u7b26\u3002

    \n\n

    \u6587\u4ef6\u7cfb\u7edf\u4e2d\u7684\u6bcf\u4e2a\u6587\u4ef6\u548c\u6587\u4ef6\u5939\u90fd\u6709\u4e00\u4e2a\u552f\u4e00\u7684 \u7edd\u5bf9\u8def\u5f84 \uff0c\u5373\u5fc5\u987b\u6253\u5f00\u624d\u80fd\u5230\u8fbe\u6587\u4ef6/\u76ee\u5f55\u6240\u5728\u4f4d\u7f6e\u7684\u76ee\u5f55\u987a\u5e8f\uff0c\u6240\u6709\u8def\u5f84\u7528 '/' \u8fde\u63a5\u3002\u4e0a\u9762\u4f8b\u5b50\u4e2d\uff0c\u6307\u5411 file2.ext \u7684\u7edd\u5bf9\u8def\u5f84\u662f \"dir/subdir2/subsubdir2/file2.ext\" \u3002\u6bcf\u4e2a\u76ee\u5f55\u540d\u7531\u5b57\u6bcd\u3001\u6570\u5b57\u548c/\u6216\u7a7a\u683c\u7ec4\u6210\uff0c\u6bcf\u4e2a\u6587\u4ef6\u540d\u9075\u5faa name.extension \u7684\u683c\u5f0f\uff0c\u5176\u4e2d\u540d\u79f0\u548c\u6269\u5c55\u540d\u7531\u5b57\u6bcd\u3001\u6570\u5b57\u548c/\u6216\u7a7a\u683c\u7ec4\u6210\u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u4ee5\u4e0a\u8ff0\u683c\u5f0f\u8868\u793a\u6587\u4ef6\u7cfb\u7edf\u7684\u5b57\u7b26\u4e32 input \uff0c\u8fd4\u56de\u6587\u4ef6\u7cfb\u7edf\u4e2d \u6307\u5411\u6587\u4ef6\u7684\u6700\u957f\u7edd\u5bf9\u8def\u5f84 \u7684\u957f\u5ea6\u3002 \u5982\u679c\u7cfb\u7edf\u4e2d\u6ca1\u6709\u6587\u4ef6\uff0c\u8fd4\u56de\u00a00\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1ainput = \"dir\\n\\tsubdir1\\n\\tsubdir2\\n\\t\\tfile.ext\"\n\u8f93\u51fa\uff1a20\n\u89e3\u91ca\uff1a\u53ea\u6709\u4e00\u4e2a\u6587\u4ef6\uff0c\u7edd\u5bf9\u8def\u5f84\u4e3a \"dir/subdir2/file.ext\" \uff0c\u8def\u5f84\u957f\u5ea6 20\n\u8def\u5f84 \"dir/subdir1\" \u4e0d\u542b\u4efb\u4f55\u6587\u4ef6\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1ainput = \"dir\\n\\tsubdir1\\n\\t\\tfile1.ext\\n\\t\\tsubsubdir1\\n\\tsubdir2\\n\\t\\tsubsubdir2\\n\\t\\t\\tfile2.ext\"\n\u8f93\u51fa\uff1a32\n\u89e3\u91ca\uff1a\u5b58\u5728\u4e24\u4e2a\u6587\u4ef6\uff1a\n\"dir/subdir1/file1.ext\" \uff0c\u8def\u5f84\u957f\u5ea6 21\n\"dir/subdir2/subsubdir2/file2.ext\" \uff0c\u8def\u5f84\u957f\u5ea6 32\n\u8fd4\u56de 32 \uff0c\u56e0\u4e3a\u8fd9\u662f\u6700\u957f\u7684\u8def\u5f84
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1ainput = \"a\"\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u4e0d\u5b58\u5728\u4efb\u4f55\u6587\u4ef6
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1ainput = \"file1.txt\\nfile2.txt\\nlongfile.txt\"\n\u8f93\u51fa\uff1a12\n\u89e3\u91ca\uff1a\u6839\u76ee\u5f55\u4e0b\u6709 3 \u4e2a\u6587\u4ef6\u3002\n\u56e0\u4e3a\u6839\u76ee\u5f55\u4e2d\u4efb\u4f55\u4e1c\u897f\u7684\u7edd\u5bf9\u8def\u5f84\u53ea\u662f\u540d\u79f0\u672c\u8eab\uff0c\u6240\u4ee5\u7b54\u6848\u662f \"longfile.txt\" \uff0c\u8def\u5f84\u957f\u5ea6\u4e3a 12\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= input.length <= 104
    • \n\t
    • input \u53ef\u80fd\u5305\u542b\u5c0f\u5199\u6216\u5927\u5199\u7684\u82f1\u6587\u5b57\u6bcd\uff0c\u4e00\u4e2a\u6362\u884c\u7b26 '\\n'\uff0c\u4e00\u4e2a\u6307\u8868\u7b26 '\\t'\uff0c\u4e00\u4e2a\u70b9 '.'\uff0c\u4e00\u4e2a\u7a7a\u683c ' '\uff0c\u548c\u6570\u5b57\u3002
    • \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int lengthLongestPath(string input) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int lengthLongestPath(String input) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def lengthLongestPath(self, input):\n \"\"\"\n :type input: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def lengthLongestPath(self, input: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint lengthLongestPath(char * input){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LengthLongestPath(string input) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} input\n * @return {number}\n */\nvar lengthLongestPath = function(input) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} input\n# @return {Integer}\ndef length_longest_path(input)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func lengthLongestPath(_ input: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func lengthLongestPath(input string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def lengthLongestPath(input: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun lengthLongestPath(input: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn length_longest_path(input: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $input\n * @return Integer\n */\n function lengthLongestPath($input) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function lengthLongestPath(input: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (length-longest-path input)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0388](https://leetcode-cn.com/problems/longest-absolute-file-path)", "[\u6587\u4ef6\u7684\u6700\u957f\u7edd\u5bf9\u8def\u5f84](/solution/0300-0399/0388.Longest%20Absolute%20File%20Path/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0388](https://leetcode.com/problems/longest-absolute-file-path)", "[Longest Absolute File Path](/solution/0300-0399/0388.Longest%20Absolute%20File%20Path/README_EN.md)", "", "Medium", ""]}, {"question_id": "0387", "frontend_question_id": "0387", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/first-unique-character-in-a-string", "url_en": "https://leetcode.com/problems/first-unique-character-in-a-string", "relative_path_cn": "/solution/0300-0399/0387.First%20Unique%20Character%20in%20a%20String/README.md", "relative_path_en": "/solution/0300-0399/0387.First%20Unique%20Character%20in%20a%20String/README_EN.md", "title_cn": "\u5b57\u7b26\u4e32\u4e2d\u7684\u7b2c\u4e00\u4e2a\u552f\u4e00\u5b57\u7b26", "title_en": "First Unique Character in a String", "question_title_slug": "first-unique-character-in-a-string", "content_en": "

    Given a string s, return the first non-repeating character in it and return its index. If it does not exist, return -1.

    \n\n

     

    \n

    Example 1:

    \n
    Input: s = \"leetcode\"\nOutput: 0\n

    Example 2:

    \n
    Input: s = \"loveleetcode\"\nOutput: 2\n

    Example 3:

    \n
    Input: s = \"aabb\"\nOutput: -1\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 105
    • \n\t
    • s consists of only lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u627e\u5230\u5b83\u7684\u7b2c\u4e00\u4e2a\u4e0d\u91cd\u590d\u7684\u5b57\u7b26\uff0c\u5e76\u8fd4\u56de\u5b83\u7684\u7d22\u5f15\u3002\u5982\u679c\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de -1\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    s = "leetcode"\n\u8fd4\u56de 0\n\ns = "loveleetcode"\n\u8fd4\u56de 2\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a\u4f60\u53ef\u4ee5\u5047\u5b9a\u8be5\u5b57\u7b26\u4e32\u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd\u3002

    \n", "tags_en": ["Hash Table", "String"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int firstUniqChar(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int firstUniqChar(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def firstUniqChar(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def firstUniqChar(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint firstUniqChar(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FirstUniqChar(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar firstUniqChar = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef first_uniq_char(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func firstUniqChar(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func firstUniqChar(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def firstUniqChar(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun firstUniqChar(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn first_uniq_char(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function firstUniqChar($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function firstUniqChar(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (first-uniq-char s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0387](https://leetcode-cn.com/problems/first-unique-character-in-a-string)", "[\u5b57\u7b26\u4e32\u4e2d\u7684\u7b2c\u4e00\u4e2a\u552f\u4e00\u5b57\u7b26](/solution/0300-0399/0387.First%20Unique%20Character%20in%20a%20String/README.md)", "`\u54c8\u5e0c\u8868`,`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0387](https://leetcode.com/problems/first-unique-character-in-a-string)", "[First Unique Character in a String](/solution/0300-0399/0387.First%20Unique%20Character%20in%20a%20String/README_EN.md)", "`Hash Table`,`String`", "Easy", ""]}, {"question_id": "0386", "frontend_question_id": "0386", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/lexicographical-numbers", "url_en": "https://leetcode.com/problems/lexicographical-numbers", "relative_path_cn": "/solution/0300-0399/0386.Lexicographical%20Numbers/README.md", "relative_path_en": "/solution/0300-0399/0386.Lexicographical%20Numbers/README_EN.md", "title_cn": "\u5b57\u5178\u5e8f\u6392\u6570", "title_en": "Lexicographical Numbers", "question_title_slug": "lexicographical-numbers", "content_en": "

    Given an integer n, return all the numbers in the range [1, n] sorted in lexicographical order.

    \n\n

    You must write an algorithm that runs in O(n) time and uses O(1) extra space. 

    \n\n

     

    \n

    Example 1:

    \n
    Input: n = 13\nOutput: [1,10,11,12,13,2,3,4,5,6,7,8,9]\n

    Example 2:

    \n
    Input: n = 2\nOutput: [1,2]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 5 * 104
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570 n, \u8fd4\u56de\u4ece \u5230 \u7684\u5b57\u5178\u987a\u5e8f\u3002

    \n\n

    \u4f8b\u5982\uff0c

    \n\n

    \u7ed9\u5b9a n =1 3\uff0c\u8fd4\u56de [1,10,11,12,13,2,3,4,5,6,7,8,9] \u3002

    \n\n

    \u8bf7\u5c3d\u53ef\u80fd\u7684\u4f18\u5316\u7b97\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u548c\u7a7a\u95f4\u590d\u6742\u5ea6\u3002 \u8f93\u5165\u7684\u6570\u636e \u5c0f\u4e8e\u7b49\u4e8e 5,000,000\u3002

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector lexicalOrder(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List lexicalOrder(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def lexicalOrder(self, n):\n \"\"\"\n :type n: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def lexicalOrder(self, n: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* lexicalOrder(int n, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList LexicalOrder(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number[]}\n */\nvar lexicalOrder = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer[]}\ndef lexical_order(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func lexicalOrder(_ n: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func lexicalOrder(n int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def lexicalOrder(n: Int): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun lexicalOrder(n: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn lexical_order(n: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer[]\n */\n function lexicalOrder($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function lexicalOrder(n: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (lexical-order n)\n (-> exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0386](https://leetcode-cn.com/problems/lexicographical-numbers)", "[\u5b57\u5178\u5e8f\u6392\u6570](/solution/0300-0399/0386.Lexicographical%20Numbers/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0386](https://leetcode.com/problems/lexicographical-numbers)", "[Lexicographical Numbers](/solution/0300-0399/0386.Lexicographical%20Numbers/README_EN.md)", "", "Medium", ""]}, {"question_id": "0385", "frontend_question_id": "0385", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/mini-parser", "url_en": "https://leetcode.com/problems/mini-parser", "relative_path_cn": "/solution/0300-0399/0385.Mini%20Parser/README.md", "relative_path_en": "/solution/0300-0399/0385.Mini%20Parser/README_EN.md", "title_cn": "\u8ff7\u4f60\u8bed\u6cd5\u5206\u6790\u5668", "title_en": "Mini Parser", "question_title_slug": "mini-parser", "content_en": "

    Given a string s represents the serialization of a nested list, implement a parser to deserialize it and return the deserialized NestedInteger.

    \n\n

    Each element is either an integer or a list whose elements may also be integers or other lists.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "324"\nOutput: 324\nExplanation: You should return a NestedInteger object which contains a single integer 324.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "[123,[456,[789]]]"\nOutput: [123,[456,[789]]]\nExplanation: Return a NestedInteger object containing a nested list with 2 elements:\n1. An integer containing value 123.\n2. A nested list containing two elements:\n    i.  An integer containing value 456.\n    ii. A nested list with one element:\n         a. An integer containing value 789\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 5 * 104
    • \n\t
    • s consists of digits, square brackets "[]", negative sign '-', and commas ','.
    • \n\t
    • s is the serialization of valid NestedInteger.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u7528\u5b57\u7b26\u4e32\u8868\u793a\u7684\u6574\u6570\u7684\u5d4c\u5957\u5217\u8868\uff0c\u5b9e\u73b0\u4e00\u4e2a\u89e3\u6790\u5b83\u7684\u8bed\u6cd5\u5206\u6790\u5668\u3002

    \n\n

    \u5217\u8868\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u53ea\u53ef\u80fd\u662f\u6574\u6570\u6216\u6574\u6570\u5d4c\u5957\u5217\u8868

    \n\n

    \u63d0\u793a\uff1a\u4f60\u53ef\u4ee5\u5047\u5b9a\u8fd9\u4e9b\u5b57\u7b26\u4e32\u90fd\u662f\u683c\u5f0f\u826f\u597d\u7684\uff1a

    \n\n
      \n\t
    • \u5b57\u7b26\u4e32\u975e\u7a7a
    • \n\t
    • \u5b57\u7b26\u4e32\u4e0d\u5305\u542b\u7a7a\u683c
    • \n\t
    • \u5b57\u7b26\u4e32\u53ea\u5305\u542b\u6570\u5b570-9\u3001[\u3001-\u3001,\u3001]
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u7ed9\u5b9a s = "324",\n\n\u4f60\u5e94\u8be5\u8fd4\u56de\u4e00\u4e2a NestedInteger \u5bf9\u8c61\uff0c\u5176\u4e2d\u53ea\u5305\u542b\u6574\u6570\u503c 324\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u7ed9\u5b9a s = "[123,[456,[789]]]",\n\n\u8fd4\u56de\u4e00\u4e2a NestedInteger \u5bf9\u8c61\u5305\u542b\u4e00\u4e2a\u6709\u4e24\u4e2a\u5143\u7d20\u7684\u5d4c\u5957\u5217\u8868\uff1a\n\n1. \u4e00\u4e2a integer \u5305\u542b\u503c 123\n2. \u4e00\u4e2a\u5305\u542b\u4e24\u4e2a\u5143\u7d20\u7684\u5d4c\u5957\u5217\u8868\uff1a\n    i.  \u4e00\u4e2a integer \u5305\u542b\u503c 456\n    ii. \u4e00\u4e2a\u5305\u542b\u4e00\u4e2a\u5143\u7d20\u7684\u5d4c\u5957\u5217\u8868\n         a. \u4e00\u4e2a integer \u5305\u542b\u503c 789\n
    \n", "tags_en": ["Stack", "String"], "tags_cn": ["\u6808", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * class NestedInteger {\n * public:\n * // Constructor initializes an empty nested list.\n * NestedInteger();\n *\n * // Constructor initializes a single integer.\n * NestedInteger(int value);\n *\n * // Return true if this NestedInteger holds a single integer, rather than a nested list.\n * bool isInteger() const;\n *\n * // Return the single integer that this NestedInteger holds, if it holds a single integer\n * // The result is undefined if this NestedInteger holds a nested list\n * int getInteger() const;\n *\n * // Set this NestedInteger to hold a single integer.\n * void setInteger(int value);\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * void add(const NestedInteger &ni);\n *\n * // Return the nested list that this NestedInteger holds, if it holds a nested list\n * // The result is undefined if this NestedInteger holds a single integer\n * const vector &getList() const;\n * };\n */\nclass Solution {\npublic:\n NestedInteger deserialize(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * public interface NestedInteger {\n * // Constructor initializes an empty nested list.\n * public NestedInteger();\n *\n * // Constructor initializes a single integer.\n * public NestedInteger(int value);\n *\n * // @return true if this NestedInteger holds a single integer, rather than a nested list.\n * public boolean isInteger();\n *\n * // @return the single integer that this NestedInteger holds, if it holds a single integer\n * // Return null if this NestedInteger holds a nested list\n * public Integer getInteger();\n *\n * // Set this NestedInteger to hold a single integer.\n * public void setInteger(int value);\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * public void add(NestedInteger ni);\n *\n * // @return the nested list that this NestedInteger holds, if it holds a nested list\n * // Return empty list if this NestedInteger holds a single integer\n * public List getList();\n * }\n */\nclass Solution {\n public NestedInteger deserialize(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# \"\"\"\n# This is the interface that allows for creating nested lists.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class NestedInteger(object):\n# def __init__(self, value=None):\n# \"\"\"\n# If value is not specified, initializes an empty list.\n# Otherwise initializes a single integer equal to value.\n# \"\"\"\n#\n# def isInteger(self):\n# \"\"\"\n# @return True if this NestedInteger holds a single integer, rather than a nested list.\n# :rtype bool\n# \"\"\"\n#\n# def add(self, elem):\n# \"\"\"\n# Set this NestedInteger to hold a nested list and adds a nested integer elem to it.\n# :rtype void\n# \"\"\"\n#\n# def setInteger(self, value):\n# \"\"\"\n# Set this NestedInteger to hold a single integer equal to value.\n# :rtype void\n# \"\"\"\n#\n# def getInteger(self):\n# \"\"\"\n# @return the single integer that this NestedInteger holds, if it holds a single integer\n# Return None if this NestedInteger holds a nested list\n# :rtype int\n# \"\"\"\n#\n# def getList(self):\n# \"\"\"\n# @return the nested list that this NestedInteger holds, if it holds a nested list\n# Return None if this NestedInteger holds a single integer\n# :rtype List[NestedInteger]\n# \"\"\"\nclass Solution(object):\n def deserialize(self, s):\n \"\"\"\n :type s: str\n :rtype: NestedInteger\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# \"\"\"\n# This is the interface that allows for creating nested lists.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class NestedInteger:\n# def __init__(self, value=None):\n# \"\"\"\n# If value is not specified, initializes an empty list.\n# Otherwise initializes a single integer equal to value.\n# \"\"\"\n#\n# def isInteger(self):\n# \"\"\"\n# @return True if this NestedInteger holds a single integer, rather than a nested list.\n# :rtype bool\n# \"\"\"\n#\n# def add(self, elem):\n# \"\"\"\n# Set this NestedInteger to hold a nested list and adds a nested integer elem to it.\n# :rtype void\n# \"\"\"\n#\n# def setInteger(self, value):\n# \"\"\"\n# Set this NestedInteger to hold a single integer equal to value.\n# :rtype void\n# \"\"\"\n#\n# def getInteger(self):\n# \"\"\"\n# @return the single integer that this NestedInteger holds, if it holds a single integer\n# Return None if this NestedInteger holds a nested list\n# :rtype int\n# \"\"\"\n#\n# def getList(self):\n# \"\"\"\n# @return the nested list that this NestedInteger holds, if it holds a nested list\n# Return None if this NestedInteger holds a single integer\n# :rtype List[NestedInteger]\n# \"\"\"\nclass Solution:\n def deserialize(self, s: str) -> NestedInteger:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * *********************************************************************\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * *********************************************************************\n *\n * // Initializes an empty nested list and return a reference to the nested integer.\n * struct NestedInteger *NestedIntegerInit();\n *\n * // Return true if this NestedInteger holds a single integer, rather than a nested list.\n * bool NestedIntegerIsInteger(struct NestedInteger *);\n *\n * // Return the single integer that this NestedInteger holds, if it holds a single integer\n * // The result is undefined if this NestedInteger holds a nested list\n * int NestedIntegerGetInteger(struct NestedInteger *);\n *\n * // Set this NestedInteger to hold a single integer.\n * void NestedIntegerSetInteger(struct NestedInteger *ni, int value);\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer elem to it.\n * void NestedIntegerAdd(struct NestedInteger *ni, struct NestedInteger *elem);\n *\n * // Return the nested list that this NestedInteger holds, if it holds a nested list\n * // The result is undefined if this NestedInteger holds a single integer\n * struct NestedInteger **NestedIntegerGetList(struct NestedInteger *);\n *\n * // Return the nested list's size that this NestedInteger holds, if it holds a nested list\n * // The result is undefined if this NestedInteger holds a single integer\n * int NestedIntegerGetListSize(struct NestedInteger *);\n * };\n */\n\n\nstruct NestedInteger* deserialize(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * interface NestedInteger {\n *\n * // Constructor initializes an empty nested list.\n * public NestedInteger();\n *\n * // Constructor initializes a single integer.\n * public NestedInteger(int value);\n *\n * // @return true if this NestedInteger holds a single integer, rather than a nested list.\n * bool IsInteger();\n *\n * // @return the single integer that this NestedInteger holds, if it holds a single integer\n * // Return null if this NestedInteger holds a nested list\n * int GetInteger();\n *\n * // Set this NestedInteger to hold a single integer.\n * public void SetInteger(int value);\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * public void Add(NestedInteger ni);\n *\n * // @return the nested list that this NestedInteger holds, if it holds a nested list\n * // Return null if this NestedInteger holds a single integer\n * IList GetList();\n * }\n */\npublic class Solution {\n public NestedInteger Deserialize(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * function NestedInteger() {\n *\n * Return true if this NestedInteger holds a single integer, rather than a nested list.\n * @return {boolean}\n * this.isInteger = function() {\n * ...\n * };\n *\n * Return the single integer that this NestedInteger holds, if it holds a single integer\n * Return null if this NestedInteger holds a nested list\n * @return {integer}\n * this.getInteger = function() {\n * ...\n * };\n *\n * Set this NestedInteger to hold a single integer equal to value.\n * @return {void}\n * this.setInteger = function(value) {\n * ...\n * };\n *\n * Set this NestedInteger to hold a nested list and adds a nested integer elem to it.\n * @return {void}\n * this.add = function(elem) {\n * ...\n * };\n *\n * Return the nested list that this NestedInteger holds, if it holds a nested list\n * Return null if this NestedInteger holds a single integer\n * @return {NestedInteger[]}\n * this.getList = function() {\n * ...\n * };\n * };\n */\n/**\n * @param {string} s\n * @return {NestedInteger}\n */\nvar deserialize = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# This is the interface that allows for creating nested lists.\n# You should not implement it, or speculate about its implementation\n#\n#class NestedInteger\n# def is_integer()\n# \"\"\"\n# Return true if this NestedInteger holds a single integer, rather than a nested list.\n# @return {Boolean}\n# \"\"\"\n#\n# def get_integer()\n# \"\"\"\n# Return the single integer that this NestedInteger holds, if it holds a single integer\n# Return nil if this NestedInteger holds a nested list\n# @return {Integer}\n# \"\"\"\n#\n# def set_integer(value)\n# \"\"\"\n# Set this NestedInteger to hold a single integer equal to value.\n# @return {Void}\n# \"\"\"\n#\n# def add(elem)\n# \"\"\"\n# Set this NestedInteger to hold a nested list and adds a nested integer elem to it.\n# @return {Void}\n# \"\"\"\n#\n# def get_list()\n# \"\"\"\n# Return the nested list that this NestedInteger holds, if it holds a nested list\n# Return nil if this NestedInteger holds a single integer\n# @return {NestedInteger[]}\n# \"\"\"\n# @param {String} s\n# @return {NestedInteger}\ndef deserialize(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * class NestedInteger {\n * // Return true if this NestedInteger holds a single integer, rather than a nested list.\n * public func isInteger() -> Bool\n *\n * // Return the single integer that this NestedInteger holds, if it holds a single integer\n * // The result is undefined if this NestedInteger holds a nested list\n * public func getInteger() -> Int\n *\n * // Set this NestedInteger to hold a single integer.\n * public func setInteger(value: Int)\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * public func add(elem: NestedInteger)\n *\n * // Return the nested list that this NestedInteger holds, if it holds a nested list\n * // The result is undefined if this NestedInteger holds a single integer\n * public func getList() -> [NestedInteger]\n * }\n */\nclass Solution {\n func deserialize(_ s: String) -> NestedInteger {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * type NestedInteger struct {\n * }\n *\n * // Return true if this NestedInteger holds a single integer, rather than a nested list.\n * func (n NestedInteger) IsInteger() bool {}\n *\n * // Return the single integer that this NestedInteger holds, if it holds a single integer\n * // The result is undefined if this NestedInteger holds a nested list\n * // So before calling this method, you should have a check\n * func (n NestedInteger) GetInteger() int {}\n *\n * // Set this NestedInteger to hold a single integer.\n * func (n *NestedInteger) SetInteger(value int) {}\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * func (n *NestedInteger) Add(elem NestedInteger) {}\n *\n * // Return the nested list that this NestedInteger holds, if it holds a nested list\n * // The list length is zero if this NestedInteger holds a single integer\n * // You can access NestedInteger's List element directly if you want to modify it\n * func (n NestedInteger) GetList() []*NestedInteger {}\n */\nfunc deserialize(s string) *NestedInteger {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * trait NestedInteger {\n *\n * // Return true if this NestedInteger holds a single integer, rather than a nested list.\n * def isInteger: Boolean\n *\n * // Return the single integer that this NestedInteger holds, if it holds a single integer.\n * def getInteger: Int\n *\n * // Set this NestedInteger to hold a single integer.\n * def setInteger(i: Int): Unit\n *\n * // Return the nested list that this NestedInteger holds, if it holds a nested list.\n * def getList: Array[NestedInteger]\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * def add(ni: NestedInteger): Unit\n * }\n */\nobject Solution {\n def deserialize(s: String): NestedInteger = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * class NestedInteger {\n * // Constructor initializes an empty nested list.\n * constructor()\n *\n * // Constructor initializes a single integer.\n * constructor(value: Int)\n *\n * // @return true if this NestedInteger holds a single integer, rather than a nested list.\n * fun isInteger(): Boolean\n *\n * // @return the single integer that this NestedInteger holds, if it holds a single integer\n * // Return null if this NestedInteger holds a nested list\n * fun getInteger(): Int?\n *\n * // Set this NestedInteger to hold a single integer.\n * fun setInteger(value: Int): Unit\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * fun add(ni: NestedInteger): Unit\n *\n * // @return the nested list that this NestedInteger holds, if it holds a nested list\n * // Return null if this NestedInteger holds a single integer\n * fun getList(): List?\n * }\n */\nclass Solution {\n fun deserialize(s: String): NestedInteger {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// #[derive(Debug, PartialEq, Eq)]\n// pub enum NestedInteger {\n// Int(i32),\n// List(Vec)\n// }\nimpl Solution {\n pub fn deserialize(s: String) -> NestedInteger {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * class NestedInteger {\n\n * // if value is not specified, initializes an empty list.\n * // Otherwise initializes a single integer equal to value.\n * function __construct($value = null)\n\n * // Return true if this NestedInteger holds a single integer, rather than a nested list.\n * function isInteger() : bool\n *\n * // Return the single integer that this NestedInteger holds, if it holds a single integer\n * // The result is undefined if this NestedInteger holds a nested list\n * function getInteger()\n *\n * // Set this NestedInteger to hold a single integer.\n * function setInteger($i) : void\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * function add($ni) : void\n *\n * // Return the nested list that this NestedInteger holds, if it holds a nested list\n * // The result is undefined if this NestedInteger holds a single integer\n * function getList() : array\n * }\n */\nclass Solution {\n\n /**\n * @param String $s\n * @return NestedInteger\n */\n function deserialize($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * class NestedInteger {\n * If value is provided, then it holds a single integer\n * Otherwise it holds an empty nested list\n * constructor(value?: number) {\n * ...\n * };\n *\n * Return true if this NestedInteger holds a single integer, rather than a nested list.\n * isInteger(): boolean {\n * ...\n * };\n *\n * Return the single integer that this NestedInteger holds, if it holds a single integer\n * Return null if this NestedInteger holds a nested list\n * getInteger(): number | null {\n * ...\n * };\n *\n * Set this NestedInteger to hold a single integer equal to value.\n * setInteger(value: number) {\n * ...\n * };\n *\n * Set this NestedInteger to hold a nested list and adds a nested integer elem to it.\n * add(elem: NestedInteger) {\n * ...\n * };\n *\n * Return the nested list that this NestedInteger holds,\n * or an empty list if this NestedInteger holds a single integer\n * getList(): NestedInteger[] {\n * ...\n * };\n * };\n */\n\nfunction deserialize(s: string): NestedInteger {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": ";; This is the interface that allows for creating nested lists.\n;; You should not implement it, or speculate about its implementation\n\n#|\n\n(define nested-integer%\n (class object%\n ...\n\n ; Return true if this nested-integer% holds a single integer, rather than a nested list.\n ; -> boolean?\n (define/public (is-integer)\n ...)\n\n ; Return the single integer that this nested-integer% holds, if it holds a single integer,\n ; or #f if this nested-integer% holds a nested list.\n ; -> integer?\n (define/public (get-integer)\n ...)\n\n ; Set this nested-integer% to hold a single integer equal to value.\n ; -> integer? void?\n (define/public (set-integer i)\n ...)\n\n ; Set this nested-integer% to hold a nested list and adds a nested integer elem to it.\n ; -> (is-a?/c nested-integer%) void?\n (define/public (add ni)\n ...)\n\n ; Return the nested list that this nested-integer% holds,\n ; or an empty list if this nested-integer% holds a single integer.\n ; -> gvector?\n (define/public (get-list)\n ...)))\n\n|#\n\n(define/contract (deserialize s)\n (-> string? (is-a?/c nested-integer%))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0385](https://leetcode-cn.com/problems/mini-parser)", "[\u8ff7\u4f60\u8bed\u6cd5\u5206\u6790\u5668](/solution/0300-0399/0385.Mini%20Parser/README.md)", "`\u6808`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0385](https://leetcode.com/problems/mini-parser)", "[Mini Parser](/solution/0300-0399/0385.Mini%20Parser/README_EN.md)", "`Stack`,`String`", "Medium", ""]}, {"question_id": "0384", "frontend_question_id": "0384", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/shuffle-an-array", "url_en": "https://leetcode.com/problems/shuffle-an-array", "relative_path_cn": "/solution/0300-0399/0384.Shuffle%20an%20Array/README.md", "relative_path_en": "/solution/0300-0399/0384.Shuffle%20an%20Array/README_EN.md", "title_cn": "\u6253\u4e71\u6570\u7ec4", "title_en": "Shuffle an Array", "question_title_slug": "shuffle-an-array", "content_en": "

    Given an integer array nums, design an algorithm to randomly shuffle the array.

    \n\n

    Implement the Solution class:

    \n\n
      \n\t
    • Solution(int[] nums) Initializes the object with the integer array nums.
    • \n\t
    • int[] reset() Resets the array to its original configuration and returns it.
    • \n\t
    • int[] shuffle() Returns a random shuffling of the array.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["Solution", "shuffle", "reset", "shuffle"]\n[[[1, 2, 3]], [], [], []]\nOutput\n[null, [3, 1, 2], [1, 2, 3], [1, 3, 2]]\n\nExplanation\nSolution solution = new Solution([1, 2, 3]);\nsolution.shuffle();    // Shuffle the array [1,2,3] and return its result. Any permutation of [1,2,3] must be equally likely to be returned. Example: return [3, 1, 2]\nsolution.reset();      // Resets the array back to its original configuration [1,2,3]. Return [1, 2, 3]\nsolution.shuffle();    // Returns the random shuffling of array [1,2,3]. Example: return [1, 3, 2]\n\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 200
    • \n\t
    • -106 <= nums[i] <= 106
    • \n\t
    • All the elements of nums are unique.
    • \n\t
    • At most 5 * 104 calls will be made to reset and shuffle.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \uff0c\u8bbe\u8ba1\u7b97\u6cd5\u6765\u6253\u4e71\u4e00\u4e2a\u6ca1\u6709\u91cd\u590d\u5143\u7d20\u7684\u6570\u7ec4\u3002

    \n\n

    \u5b9e\u73b0 Solution class:

    \n\n
      \n\t
    • Solution(int[] nums) \u4f7f\u7528\u6574\u6570\u6570\u7ec4 nums \u521d\u59cb\u5316\u5bf9\u8c61
    • \n\t
    • int[] reset() \u91cd\u8bbe\u6570\u7ec4\u5230\u5b83\u7684\u521d\u59cb\u72b6\u6001\u5e76\u8fd4\u56de
    • \n\t
    • int[] shuffle() \u8fd4\u56de\u6570\u7ec4\u968f\u673a\u6253\u4e71\u540e\u7684\u7ed3\u679c
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\n[\"Solution\", \"shuffle\", \"reset\", \"shuffle\"]\n[[[1, 2, 3]], [], [], []]\n\u8f93\u51fa\n[null, [3, 1, 2], [1, 2, 3], [1, 3, 2]]\n\n\u89e3\u91ca\nSolution solution = new Solution([1, 2, 3]);\nsolution.shuffle();    // \u6253\u4e71\u6570\u7ec4 [1,2,3] \u5e76\u8fd4\u56de\u7ed3\u679c\u3002\u4efb\u4f55 [1,2,3]\u7684\u6392\u5217\u8fd4\u56de\u7684\u6982\u7387\u5e94\u8be5\u76f8\u540c\u3002\u4f8b\u5982\uff0c\u8fd4\u56de [3, 1, 2]\nsolution.reset();      // \u91cd\u8bbe\u6570\u7ec4\u5230\u5b83\u7684\u521d\u59cb\u72b6\u6001 [1, 2, 3] \u3002\u8fd4\u56de [1, 2, 3]\nsolution.shuffle();    // \u968f\u673a\u8fd4\u56de\u6570\u7ec4 [1, 2, 3] \u6253\u4e71\u540e\u7684\u7ed3\u679c\u3002\u4f8b\u5982\uff0c\u8fd4\u56de [1, 3, 2]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 200
    • \n\t
    • -106 <= nums[i] <= 106
    • \n\t
    • nums \u4e2d\u7684\u6240\u6709\u5143\u7d20\u90fd\u662f \u552f\u4e00\u7684
    • \n\t
    • \u6700\u591a\u53ef\u4ee5\u8c03\u7528 5 * 104 \u6b21 reset \u548c shuffle
    • \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n Solution(vector& nums) {\n\n }\n \n /** Resets the array to its original configuration and return it. */\n vector reset() {\n\n }\n \n /** Returns a random shuffling of the array. */\n vector shuffle() {\n\n }\n};\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution* obj = new Solution(nums);\n * vector param_1 = obj->reset();\n * vector param_2 = obj->shuffle();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n\n public Solution(int[] nums) {\n\n }\n \n /** Resets the array to its original configuration and return it. */\n public int[] reset() {\n\n }\n \n /** Returns a random shuffling of the array. */\n public int[] shuffle() {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution obj = new Solution(nums);\n * int[] param_1 = obj.reset();\n * int[] param_2 = obj.shuffle();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n\n def __init__(self, nums):\n \"\"\"\n :type nums: List[int]\n \"\"\"\n\n\n def reset(self):\n \"\"\"\n Resets the array to its original configuration and return it.\n :rtype: List[int]\n \"\"\"\n\n\n def shuffle(self):\n \"\"\"\n Returns a random shuffling of the array.\n :rtype: List[int]\n \"\"\"\n\n\n\n# Your Solution object will be instantiated and called as such:\n# obj = Solution(nums)\n# param_1 = obj.reset()\n# param_2 = obj.shuffle()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n\n def __init__(self, nums: List[int]):\n\n\n def reset(self) -> List[int]:\n \"\"\"\n Resets the array to its original configuration and return it.\n \"\"\"\n\n\n def shuffle(self) -> List[int]:\n \"\"\"\n Returns a random shuffling of the array.\n \"\"\"\n\n\n\n# Your Solution object will be instantiated and called as such:\n# obj = Solution(nums)\n# param_1 = obj.reset()\n# param_2 = obj.shuffle()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} Solution;\n\n\nSolution* solutionCreate(int* nums, int numsSize) {\n\n}\n\n/** Resets the array to its original configuration and return it. */\nint* solutionReset(Solution* obj, int* retSize) {\n\n}\n\n/** Returns a random shuffling of the array. */\nint* solutionShuffle(Solution* obj, int* retSize) {\n\n}\n\nvoid solutionFree(Solution* obj) {\n\n}\n\n/**\n * Your Solution struct will be instantiated and called as such:\n * Solution* obj = solutionCreate(nums, numsSize);\n * int* param_1 = solutionReset(obj, retSize);\n \n * int* param_2 = solutionShuffle(obj, retSize);\n \n * solutionFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n\n public Solution(int[] nums) {\n\n }\n \n /** Resets the array to its original configuration and return it. */\n public int[] Reset() {\n\n }\n \n /** Returns a random shuffling of the array. */\n public int[] Shuffle() {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution obj = new Solution(nums);\n * int[] param_1 = obj.Reset();\n * int[] param_2 = obj.Shuffle();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n */\nvar Solution = function(nums) {\n\n};\n\n/**\n * Resets the array to its original configuration and return it.\n * @return {number[]}\n */\nSolution.prototype.reset = function() {\n\n};\n\n/**\n * Returns a random shuffling of the array.\n * @return {number[]}\n */\nSolution.prototype.shuffle = function() {\n\n};\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = new Solution(nums)\n * var param_1 = obj.reset()\n * var param_2 = obj.shuffle()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class Solution\n\n=begin\n :type nums: Integer[]\n=end\n def initialize(nums)\n\n end\n\n\n=begin\n Resets the array to its original configuration and return it.\n :rtype: Integer[]\n=end\n def reset()\n\n end\n\n\n=begin\n Returns a random shuffling of the array.\n :rtype: Integer[]\n=end\n def shuffle()\n\n end\n\n\nend\n\n# Your Solution object will be instantiated and called as such:\n# obj = Solution.new(nums)\n# param_1 = obj.reset()\n# param_2 = obj.shuffle()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass Solution {\n\n init(_ nums: [Int]) {\n\n }\n \n /** Resets the array to its original configuration and return it. */\n func reset() -> [Int] {\n\n }\n \n /** Returns a random shuffling of the array. */\n func shuffle() -> [Int] {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * let obj = Solution(nums)\n * let ret_1: [Int] = obj.reset()\n * let ret_2: [Int] = obj.shuffle()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type Solution struct {\n\n}\n\n\nfunc Constructor(nums []int) Solution {\n\n}\n\n\n/** Resets the array to its original configuration and return it. */\nfunc (this *Solution) Reset() []int {\n\n}\n\n\n/** Returns a random shuffling of the array. */\nfunc (this *Solution) Shuffle() []int {\n\n}\n\n\n/**\n * Your Solution object will be instantiated and called as such:\n * obj := Constructor(nums);\n * param_1 := obj.Reset();\n * param_2 := obj.Shuffle();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class Solution(_nums: Array[Int]) {\n\n /** Resets the array to its original configuration and return it. */\n def reset(): Array[Int] = {\n\n }\n\n /** Returns a random shuffling of the array. */\n def shuffle(): Array[Int] = {\n\n }\n\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = new Solution(nums)\n * var param_1 = obj.reset()\n * var param_2 = obj.shuffle()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution(nums: IntArray) {\n\n /** Resets the array to its original configuration and return it. */\n fun reset(): IntArray {\n\n }\n\n /** Returns a random shuffling of the array. */\n fun shuffle(): IntArray {\n\n }\n\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = Solution(nums)\n * var param_1 = obj.reset()\n * var param_2 = obj.shuffle()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct Solution {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl Solution {\n\n fn new(nums: Vec) -> Self {\n\n }\n \n /** Resets the array to its original configuration and return it. */\n fn reset(&self) -> Vec {\n\n }\n \n /** Returns a random shuffling of the array. */\n fn shuffle(&self) -> Vec {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * let obj = Solution::new(nums);\n * let ret_1: Vec = obj.reset();\n * let ret_2: Vec = obj.shuffle();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n /**\n * @param Integer[] $nums\n */\n function __construct($nums) {\n\n }\n\n /**\n * Resets the array to its original configuration and return it.\n * @return Integer[]\n */\n function reset() {\n\n }\n\n /**\n * Returns a random shuffling of the array.\n * @return Integer[]\n */\n function shuffle() {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * $obj = Solution($nums);\n * $ret_1 = $obj->reset();\n * $ret_2 = $obj->shuffle();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class Solution {\n constructor(nums: number[]) {\n\n }\n\n reset(): number[] {\n\n }\n\n shuffle(): number[] {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = new Solution(nums)\n * var param_1 = obj.reset()\n * var param_2 = obj.shuffle()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define solution%\n (class object%\n (super-new)\n\n ; nums : (listof exact-integer?)\n (init-field\n nums)\n \n ; reset : -> (listof exact-integer?)\n (define/public (reset)\n\n )\n ; shuffle : -> (listof exact-integer?)\n (define/public (shuffle)\n\n )))\n\n;; Your solution% object will be instantiated and called as such:\n;; (define obj (new solution% [nums nums]))\n;; (define param_1 (send obj reset))\n;; (define param_2 (send obj shuffle))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0384](https://leetcode-cn.com/problems/shuffle-an-array)", "[\u6253\u4e71\u6570\u7ec4](/solution/0300-0399/0384.Shuffle%20an%20Array/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0384](https://leetcode.com/problems/shuffle-an-array)", "[Shuffle an Array](/solution/0300-0399/0384.Shuffle%20an%20Array/README_EN.md)", "", "Medium", ""]}, {"question_id": "0383", "frontend_question_id": "0383", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/ransom-note", "url_en": "https://leetcode.com/problems/ransom-note", "relative_path_cn": "/solution/0300-0399/0383.Ransom%20Note/README.md", "relative_path_en": "/solution/0300-0399/0383.Ransom%20Note/README_EN.md", "title_cn": "\u8d4e\u91d1\u4fe1", "title_en": "Ransom Note", "question_title_slug": "ransom-note", "content_en": "

    Given two stings ransomNote and magazine, return true if ransomNote can be constructed from magazine and false otherwise.

    \n\n

    Each letter in magazine can only be used once in ransomNote.

    \n\n

     

    \n

    Example 1:

    \n
    Input: ransomNote = \"a\", magazine = \"b\"\nOutput: false\n

    Example 2:

    \n
    Input: ransomNote = \"aa\", magazine = \"ab\"\nOutput: false\n

    Example 3:

    \n
    Input: ransomNote = \"aa\", magazine = \"aab\"\nOutput: true\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= ransomNote.length, magazine.length <= 105
    • \n\t
    • ransomNote and magazine consist of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u8d4e\u91d1\u4fe1 (ransom) \u5b57\u7b26\u4e32\u548c\u4e00\u4e2a\u6742\u5fd7(magazine)\u5b57\u7b26\u4e32\uff0c\u5224\u65ad\u7b2c\u4e00\u4e2a\u5b57\u7b26\u4e32 ransom \u80fd\u4e0d\u80fd\u7531\u7b2c\u4e8c\u4e2a\u5b57\u7b26\u4e32 magazines \u91cc\u9762\u7684\u5b57\u7b26\u6784\u6210\u3002\u5982\u679c\u53ef\u4ee5\u6784\u6210\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\u8fd4\u56de false\u3002

    \n\n

    (\u9898\u76ee\u8bf4\u660e\uff1a\u4e3a\u4e86\u4e0d\u66b4\u9732\u8d4e\u91d1\u4fe1\u5b57\u8ff9\uff0c\u8981\u4ece\u6742\u5fd7\u4e0a\u641c\u7d22\u5404\u4e2a\u9700\u8981\u7684\u5b57\u6bcd\uff0c\u7ec4\u6210\u5355\u8bcd\u6765\u8868\u8fbe\u610f\u601d\u3002\u6742\u5fd7\u5b57\u7b26\u4e32\u4e2d\u7684\u6bcf\u4e2a\u5b57\u7b26\u53ea\u80fd\u5728\u8d4e\u91d1\u4fe1\u5b57\u7b26\u4e32\u4e2d\u4f7f\u7528\u4e00\u6b21\u3002)

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aransomNote = \"a\", magazine = \"b\"\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aransomNote = \"aa\", magazine = \"ab\"\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aransomNote = \"aa\", magazine = \"aab\"\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u4f60\u53ef\u4ee5\u5047\u8bbe\u4e24\u4e2a\u5b57\u7b26\u4e32\u5747\u53ea\u542b\u6709\u5c0f\u5199\u5b57\u6bcd\u3002
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canConstruct(string ransomNote, string magazine) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canConstruct(String ransomNote, String magazine) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canConstruct(self, ransomNote, magazine):\n \"\"\"\n :type ransomNote: str\n :type magazine: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canConstruct(self, ransomNote: str, magazine: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canConstruct(char * ransomNote, char * magazine){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanConstruct(string ransomNote, string magazine) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} ransomNote\n * @param {string} magazine\n * @return {boolean}\n */\nvar canConstruct = function(ransomNote, magazine) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} ransom_note\n# @param {String} magazine\n# @return {Boolean}\ndef can_construct(ransom_note, magazine)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canConstruct(_ ransomNote: String, _ magazine: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canConstruct(ransomNote string, magazine string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canConstruct(ransomNote: String, magazine: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canConstruct(ransomNote: String, magazine: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_construct(ransom_note: String, magazine: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $ransomNote\n * @param String $magazine\n * @return Boolean\n */\n function canConstruct($ransomNote, $magazine) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canConstruct(ransomNote: string, magazine: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-construct ransomNote magazine)\n (-> string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0383](https://leetcode-cn.com/problems/ransom-note)", "[\u8d4e\u91d1\u4fe1](/solution/0300-0399/0383.Ransom%20Note/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0383](https://leetcode.com/problems/ransom-note)", "[Ransom Note](/solution/0300-0399/0383.Ransom%20Note/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "0382", "frontend_question_id": "0382", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/linked-list-random-node", "url_en": "https://leetcode.com/problems/linked-list-random-node", "relative_path_cn": "/solution/0300-0399/0382.Linked%20List%20Random%20Node/README.md", "relative_path_en": "/solution/0300-0399/0382.Linked%20List%20Random%20Node/README_EN.md", "title_cn": "\u94fe\u8868\u968f\u673a\u8282\u70b9", "title_en": "Linked List Random Node", "question_title_slug": "linked-list-random-node", "content_en": "

    Given a singly linked list, return a random node's value from the linked list. Each node must have the same probability of being chosen.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput\n["Solution", "getRandom", "getRandom", "getRandom", "getRandom", "getRandom"]\n[[[1, 2, 3]], [], [], [], [], []]\nOutput\n[null, 1, 3, 2, 2, 3]\n\nExplanation\nSolution solution = new Solution([1, 2, 3]);\nsolution.getRandom(); // return 1\nsolution.getRandom(); // return 3\nsolution.getRandom(); // return 2\nsolution.getRandom(); // return 2\nsolution.getRandom(); // return 3\n// getRandom() should return either 1, 2, or 3 randomly. Each element should have equal probability of returning.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the linked list will be in the range [1, 104].
    • \n\t
    • -104 <= Node.val <= 104
    • \n\t
    • At most 104 calls will be made to getRandom.
    • \n
    \n\n

     

    \n

    Follow up:

    \n\n
      \n\t
    • What if the linked list is extremely large and its length is unknown to you?
    • \n\t
    • Could you solve this efficiently without using extra space?
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5355\u94fe\u8868\uff0c\u968f\u673a\u9009\u62e9\u94fe\u8868\u7684\u4e00\u4e2a\u8282\u70b9\uff0c\u5e76\u8fd4\u56de\u76f8\u5e94\u7684\u8282\u70b9\u503c\u3002\u4fdd\u8bc1\u6bcf\u4e2a\u8282\u70b9\u88ab\u9009\u7684\u6982\u7387\u4e00\u6837\u3002

    \n\n

    \u8fdb\u9636:
    \n\u5982\u679c\u94fe\u8868\u5341\u5206\u5927\u4e14\u957f\u5ea6\u672a\u77e5\uff0c\u5982\u4f55\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff1f\u4f60\u80fd\u5426\u4f7f\u7528\u5e38\u6570\u7ea7\u7a7a\u95f4\u590d\u6742\u5ea6\u5b9e\u73b0\uff1f

    \n\n

    \u793a\u4f8b:

    \n\n
    \n// \u521d\u59cb\u5316\u4e00\u4e2a\u5355\u94fe\u8868 [1,2,3].\nListNode head = new ListNode(1);\nhead.next = new ListNode(2);\nhead.next.next = new ListNode(3);\nSolution solution = new Solution(head);\n\n// getRandom()\u65b9\u6cd5\u5e94\u968f\u673a\u8fd4\u56de1,2,3\u4e2d\u7684\u4e00\u4e2a\uff0c\u4fdd\u8bc1\u6bcf\u4e2a\u5143\u7d20\u88ab\u8fd4\u56de\u7684\u6982\u7387\u76f8\u7b49\u3002\nsolution.getRandom();\n
    \n", "tags_en": ["Reservoir Sampling"], "tags_cn": ["\u84c4\u6c34\u6c60\u62bd\u6837"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n /** @param head The linked list's head.\n Note that the head is guaranteed to be not null, so it contains at least one node. */\n Solution(ListNode* head) {\n\n }\n \n /** Returns a random node's value. */\n int getRandom() {\n\n }\n};\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution* obj = new Solution(head);\n * int param_1 = obj->getRandom();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n\n /** @param head The linked list's head.\n Note that the head is guaranteed to be not null, so it contains at least one node. */\n public Solution(ListNode head) {\n\n }\n \n /** Returns a random node's value. */\n public int getRandom() {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution obj = new Solution(head);\n * int param_1 = obj.getRandom();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n\n def __init__(self, head):\n \"\"\"\n @param head The linked list's head.\n Note that the head is guaranteed to be not null, so it contains at least one node.\n :type head: ListNode\n \"\"\"\n\n\n def getRandom(self):\n \"\"\"\n Returns a random node's value.\n :rtype: int\n \"\"\"\n\n\n\n# Your Solution object will be instantiated and called as such:\n# obj = Solution(head)\n# param_1 = obj.getRandom()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n\n def __init__(self, head: ListNode):\n \"\"\"\n @param head The linked list's head.\n Note that the head is guaranteed to be not null, so it contains at least one node.\n \"\"\"\n\n\n def getRandom(self) -> int:\n \"\"\"\n Returns a random node's value.\n \"\"\"\n\n\n\n# Your Solution object will be instantiated and called as such:\n# obj = Solution(head)\n# param_1 = obj.getRandom()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\n\ntypedef struct {\n\n} Solution;\n\n/** @param head The linked list's head.\n Note that the head is guaranteed to be not null, so it contains at least one node. */\n\nSolution* solutionCreate(struct ListNode* head) {\n\n}\n\n/** Returns a random node's value. */\nint solutionGetRandom(Solution* obj) {\n\n}\n\nvoid solutionFree(Solution* obj) {\n\n}\n\n/**\n * Your Solution struct will be instantiated and called as such:\n * Solution* obj = solutionCreate(head);\n * int param_1 = solutionGetRandom(obj);\n \n * solutionFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n\n /** @param head The linked list's head.\n Note that the head is guaranteed to be not null, so it contains at least one node. */\n public Solution(ListNode head) {\n\n }\n \n /** Returns a random node's value. */\n public int GetRandom() {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution obj = new Solution(head);\n * int param_1 = obj.GetRandom();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param head The linked list's head.\n Note that the head is guaranteed to be not null, so it contains at least one node.\n * @param {ListNode} head\n */\nvar Solution = function(head) {\n\n};\n\n/**\n * Returns a random node's value.\n * @return {number}\n */\nSolution.prototype.getRandom = function() {\n\n};\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = new Solution(head)\n * var param_1 = obj.getRandom()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\nclass Solution\n\n=begin\n @param head The linked list's head.\n Note that the head is guaranteed to be not null, so it contains at least one node.\n :type head: ListNode\n=end\n def initialize(head)\n\n end\n\n\n=begin\n Returns a random node's value.\n :rtype: Integer\n=end\n def get_random()\n\n end\n\n\nend\n\n# Your Solution object will be instantiated and called as such:\n# obj = Solution.new(head)\n# param_1 = obj.get_random()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\n\nclass Solution {\n\n /** @param head The linked list's head.\n Note that the head is guaranteed to be not null, so it contains at least one node. */\n init(_ head: ListNode?) {\n\n }\n \n /** Returns a random node's value. */\n func getRandom() -> Int {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * let obj = Solution(head)\n * let ret_1: Int = obj.getRandom()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\ntype Solution struct {\n\n}\n\n\n/** @param head The linked list's head.\n Note that the head is guaranteed to be not null, so it contains at least one node. */\nfunc Constructor(head *ListNode) Solution {\n\n}\n\n\n/** Returns a random node's value. */\nfunc (this *Solution) GetRandom() int {\n\n}\n\n\n/**\n * Your Solution object will be instantiated and called as such:\n * obj := Constructor(head);\n * param_1 := obj.GetRandom();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nclass Solution(_head: ListNode) {\n\n /** @param head The linked list's head.\n Note that the head is guaranteed to be not null, so it contains at least one node. */\n\n\n /** Returns a random node's value. */\n def getRandom(): Int = {\n\n }\n\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = new Solution(head)\n * var param_1 = obj.getRandom()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution(head: ListNode?) {\n\n /** @param head The linked list's head.\n Note that the head is guaranteed to be not null, so it contains at least one node. */\n\n\n /** Returns a random node's value. */\n fun getRandom(): Int {\n\n }\n\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = Solution(head)\n * var param_1 = obj.getRandom()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nstruct Solution {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl Solution {\n\n /** @param head The linked list's head.\n Note that the head is guaranteed to be not null, so it contains at least one node. */\n fn new(head: Option>) -> Self {\n\n }\n \n /** Returns a random node's value. */\n fn get_random(&self) -> i32 {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * let obj = Solution::new(head);\n * let ret_1: i32 = obj.get_random();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n /**\n * @param head The linked list's head.\n Note that the head is guaranteed to be not null, so it contains at least one node.\n * @param ListNode $head\n */\n function __construct($head) {\n\n }\n\n /**\n * Returns a random node's value.\n * @return Integer\n */\n function getRandom() {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * $obj = Solution($head);\n * $ret_1 = $obj->getRandom();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nclass Solution {\n constructor(head: ListNode | null) {\n\n }\n\n getRandom(): number {\n\n }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * var obj = new Solution(head)\n * var param_1 = obj.getRandom()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define solution%\n (class object%\n (super-new)\n\n ; head : (or/c list-node? #f)\n (init-field\n head)\n \n ; get-random : -> exact-integer?\n (define/public (get-random)\n\n )))\n\n;; Your solution% object will be instantiated and called as such:\n;; (define obj (new solution% [head head]))\n;; (define param_1 (send obj get-random))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0382](https://leetcode-cn.com/problems/linked-list-random-node)", "[\u94fe\u8868\u968f\u673a\u8282\u70b9](/solution/0300-0399/0382.Linked%20List%20Random%20Node/README.md)", "`\u84c4\u6c34\u6c60\u62bd\u6837`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0382](https://leetcode.com/problems/linked-list-random-node)", "[Linked List Random Node](/solution/0300-0399/0382.Linked%20List%20Random%20Node/README_EN.md)", "`Reservoir Sampling`", "Medium", ""]}, {"question_id": "0381", "frontend_question_id": "0381", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/insert-delete-getrandom-o1-duplicates-allowed", "url_en": "https://leetcode.com/problems/insert-delete-getrandom-o1-duplicates-allowed", "relative_path_cn": "/solution/0300-0399/0381.Insert%20Delete%20GetRandom%20O%281%29%20-%20Duplicates%20allowed/README.md", "relative_path_en": "/solution/0300-0399/0381.Insert%20Delete%20GetRandom%20O%281%29%20-%20Duplicates%20allowed/README_EN.md", "title_cn": "O(1) \u65f6\u95f4\u63d2\u5165\u3001\u5220\u9664\u548c\u83b7\u53d6\u968f\u673a\u5143\u7d20 - \u5141\u8bb8\u91cd\u590d", "title_en": "Insert Delete GetRandom O(1) - Duplicates allowed", "question_title_slug": "insert-delete-getrandom-o1-duplicates-allowed", "content_en": "

    Implement the RandomizedCollection class:

    \n\n
      \n\t
    • RandomizedCollection() Initializes the RandomizedCollection object.
    • \n\t
    • bool insert(int val) Inserts an item val into the multiset if not present. Returns true if the item was not present, false otherwise.
    • \n\t
    • bool remove(int val) Removes an item val from the multiset if present. Returns true if the item was present, false otherwise. Note that if val has multiple occurrences in the multiset, we only remove one of them.
    • \n\t
    • int getRandom() Returns a random element from the current multiset of elements (it's guaranteed that at least one element exists when this method is called). The probability of each element being returned is linearly related to the number of same values the multiset contains.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["RandomizedCollection", "insert", "insert", "insert", "getRandom", "remove", "getRandom"]\n[[], [1], [1], [2], [], [1], []]\nOutput\n[null, true, false, true, 2, true, 1]\n\nExplanation\nRandomizedCollection randomizedCollection = new RandomizedCollection();\nrandomizedCollection.insert(1);   // return True. Inserts 1 to the collection. Returns true as the collection did not contain 1.\nrandomizedCollection.insert(1);   // return False. Inserts another 1 to the collection. Returns false as the collection contained 1. Collection now contains [1,1].\nrandomizedCollection.insert(2);   // return True. Inserts 2 to the collection, returns true. Collection now contains [1,1,2].\nrandomizedCollection.getRandom(); // getRandom should return 1 with the probability 2/3, and returns 2 with the probability 1/3.\nrandomizedCollection.remove(1);   // return True. Removes 1 from the collection, returns true. Collection now contains [1,2].\nrandomizedCollection.getRandom(); // getRandom should return 1 and 2 both equally likely.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • -231 <= val <= 231 - 1
    • \n\t
    • At most 105 calls will be made to insert, remove, and getRandom.
    • \n\t
    • There will be at least one element in the data structure when getRandom is called.
    • \n
    \n\n

     

    \nFollow up: Could you implement the functions of the class with each function works in average O(1) time?", "content_cn": "

    \u8bbe\u8ba1\u4e00\u4e2a\u652f\u6301\u5728\u5e73\u5747 \u65f6\u95f4\u590d\u6742\u5ea6 O(1) \u4e0b\uff0c \u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\u7684\u6570\u636e\u7ed3\u6784\u3002

    \n\n

    \u6ce8\u610f: \u5141\u8bb8\u51fa\u73b0\u91cd\u590d\u5143\u7d20\u3002

    \n\n
      \n\t
    1. insert(val)\uff1a\u5411\u96c6\u5408\u4e2d\u63d2\u5165\u5143\u7d20 val\u3002
    2. \n\t
    3. remove(val)\uff1a\u5f53 val \u5b58\u5728\u65f6\uff0c\u4ece\u96c6\u5408\u4e2d\u79fb\u9664\u4e00\u4e2a val\u3002
    4. \n\t
    5. getRandom\uff1a\u4ece\u73b0\u6709\u96c6\u5408\u4e2d\u968f\u673a\u83b7\u53d6\u4e00\u4e2a\u5143\u7d20\u3002\u6bcf\u4e2a\u5143\u7d20\u88ab\u8fd4\u56de\u7684\u6982\u7387\u5e94\u8be5\u4e0e\u5176\u5728\u96c6\u5408\u4e2d\u7684\u6570\u91cf\u5448\u7ebf\u6027\u76f8\u5173\u3002
    6. \n
    \n\n

    \u793a\u4f8b:

    \n\n
    // \u521d\u59cb\u5316\u4e00\u4e2a\u7a7a\u7684\u96c6\u5408\u3002\nRandomizedCollection collection = new RandomizedCollection();\n\n// \u5411\u96c6\u5408\u4e2d\u63d2\u5165 1 \u3002\u8fd4\u56de true \u8868\u793a\u96c6\u5408\u4e0d\u5305\u542b 1 \u3002\ncollection.insert(1);\n\n// \u5411\u96c6\u5408\u4e2d\u63d2\u5165\u53e6\u4e00\u4e2a 1 \u3002\u8fd4\u56de false \u8868\u793a\u96c6\u5408\u5305\u542b 1 \u3002\u96c6\u5408\u73b0\u5728\u5305\u542b [1,1] \u3002\ncollection.insert(1);\n\n// \u5411\u96c6\u5408\u4e2d\u63d2\u5165 2 \uff0c\u8fd4\u56de true \u3002\u96c6\u5408\u73b0\u5728\u5305\u542b [1,1,2] \u3002\ncollection.insert(2);\n\n// getRandom \u5e94\u5f53\u6709 2/3 \u7684\u6982\u7387\u8fd4\u56de 1 \uff0c1/3 \u7684\u6982\u7387\u8fd4\u56de 2 \u3002\ncollection.getRandom();\n\n// \u4ece\u96c6\u5408\u4e2d\u5220\u9664 1 \uff0c\u8fd4\u56de true \u3002\u96c6\u5408\u73b0\u5728\u5305\u542b [1,2] \u3002\ncollection.remove(1);\n\n// getRandom \u5e94\u6709\u76f8\u540c\u6982\u7387\u8fd4\u56de 1 \u548c 2 \u3002\ncollection.getRandom();\n
    \n", "tags_en": ["Design", "Array", "Hash Table"], "tags_cn": ["\u8bbe\u8ba1", "\u6570\u7ec4", "\u54c8\u5e0c\u8868"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class RandomizedCollection {\npublic:\n /** Initialize your data structure here. */\n RandomizedCollection() {\n\n }\n \n /** Inserts a value to the collection. Returns true if the collection did not already contain the specified element. */\n bool insert(int val) {\n\n }\n \n /** Removes a value from the collection. Returns true if the collection contained the specified element. */\n bool remove(int val) {\n\n }\n \n /** Get a random element from the collection. */\n int getRandom() {\n\n }\n};\n\n/**\n * Your RandomizedCollection object will be instantiated and called as such:\n * RandomizedCollection* obj = new RandomizedCollection();\n * bool param_1 = obj->insert(val);\n * bool param_2 = obj->remove(val);\n * int param_3 = obj->getRandom();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class RandomizedCollection {\n\n /** Initialize your data structure here. */\n public RandomizedCollection() {\n\n }\n \n /** Inserts a value to the collection. Returns true if the collection did not already contain the specified element. */\n public boolean insert(int val) {\n\n }\n \n /** Removes a value from the collection. Returns true if the collection contained the specified element. */\n public boolean remove(int val) {\n\n }\n \n /** Get a random element from the collection. */\n public int getRandom() {\n\n }\n}\n\n/**\n * Your RandomizedCollection object will be instantiated and called as such:\n * RandomizedCollection obj = new RandomizedCollection();\n * boolean param_1 = obj.insert(val);\n * boolean param_2 = obj.remove(val);\n * int param_3 = obj.getRandom();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class RandomizedCollection(object):\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def insert(self, val):\n \"\"\"\n Inserts a value to the collection. Returns true if the collection did not already contain the specified element.\n :type val: int\n :rtype: bool\n \"\"\"\n\n\n def remove(self, val):\n \"\"\"\n Removes a value from the collection. Returns true if the collection contained the specified element.\n :type val: int\n :rtype: bool\n \"\"\"\n\n\n def getRandom(self):\n \"\"\"\n Get a random element from the collection.\n :rtype: int\n \"\"\"\n\n\n\n# Your RandomizedCollection object will be instantiated and called as such:\n# obj = RandomizedCollection()\n# param_1 = obj.insert(val)\n# param_2 = obj.remove(val)\n# param_3 = obj.getRandom()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class RandomizedCollection:\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def insert(self, val: int) -> bool:\n \"\"\"\n Inserts a value to the collection. Returns true if the collection did not already contain the specified element.\n \"\"\"\n\n\n def remove(self, val: int) -> bool:\n \"\"\"\n Removes a value from the collection. Returns true if the collection contained the specified element.\n \"\"\"\n\n\n def getRandom(self) -> int:\n \"\"\"\n Get a random element from the collection.\n \"\"\"\n\n\n\n# Your RandomizedCollection object will be instantiated and called as such:\n# obj = RandomizedCollection()\n# param_1 = obj.insert(val)\n# param_2 = obj.remove(val)\n# param_3 = obj.getRandom()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} RandomizedCollection;\n\n/** Initialize your data structure here. */\n\nRandomizedCollection* randomizedCollectionCreate() {\n\n}\n\n/** Inserts a value to the collection. Returns true if the collection did not already contain the specified element. */\nbool randomizedCollectionInsert(RandomizedCollection* obj, int val) {\n\n}\n\n/** Removes a value from the collection. Returns true if the collection contained the specified element. */\nbool randomizedCollectionRemove(RandomizedCollection* obj, int val) {\n\n}\n\n/** Get a random element from the collection. */\nint randomizedCollectionGetRandom(RandomizedCollection* obj) {\n\n}\n\nvoid randomizedCollectionFree(RandomizedCollection* obj) {\n\n}\n\n/**\n * Your RandomizedCollection struct will be instantiated and called as such:\n * RandomizedCollection* obj = randomizedCollectionCreate();\n * bool param_1 = randomizedCollectionInsert(obj, val);\n \n * bool param_2 = randomizedCollectionRemove(obj, val);\n \n * int param_3 = randomizedCollectionGetRandom(obj);\n \n * randomizedCollectionFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class RandomizedCollection {\n\n /** Initialize your data structure here. */\n public RandomizedCollection() {\n\n }\n \n /** Inserts a value to the collection. Returns true if the collection did not already contain the specified element. */\n public bool Insert(int val) {\n\n }\n \n /** Removes a value from the collection. Returns true if the collection contained the specified element. */\n public bool Remove(int val) {\n\n }\n \n /** Get a random element from the collection. */\n public int GetRandom() {\n\n }\n}\n\n/**\n * Your RandomizedCollection object will be instantiated and called as such:\n * RandomizedCollection obj = new RandomizedCollection();\n * bool param_1 = obj.Insert(val);\n * bool param_2 = obj.Remove(val);\n * int param_3 = obj.GetRandom();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Initialize your data structure here.\n */\nvar RandomizedCollection = function() {\n\n};\n\n/**\n * Inserts a value to the collection. Returns true if the collection did not already contain the specified element. \n * @param {number} val\n * @return {boolean}\n */\nRandomizedCollection.prototype.insert = function(val) {\n\n};\n\n/**\n * Removes a value from the collection. Returns true if the collection contained the specified element. \n * @param {number} val\n * @return {boolean}\n */\nRandomizedCollection.prototype.remove = function(val) {\n\n};\n\n/**\n * Get a random element from the collection.\n * @return {number}\n */\nRandomizedCollection.prototype.getRandom = function() {\n\n};\n\n/**\n * Your RandomizedCollection object will be instantiated and called as such:\n * var obj = new RandomizedCollection()\n * var param_1 = obj.insert(val)\n * var param_2 = obj.remove(val)\n * var param_3 = obj.getRandom()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class RandomizedCollection\n\n=begin\n Initialize your data structure here.\n=end\n def initialize()\n\n end\n\n\n=begin\n Inserts a value to the collection. Returns true if the collection did not already contain the specified element.\n :type val: Integer\n :rtype: Boolean\n=end\n def insert(val)\n\n end\n\n\n=begin\n Removes a value from the collection. Returns true if the collection contained the specified element.\n :type val: Integer\n :rtype: Boolean\n=end\n def remove(val)\n\n end\n\n\n=begin\n Get a random element from the collection.\n :rtype: Integer\n=end\n def get_random()\n\n end\n\n\nend\n\n# Your RandomizedCollection object will be instantiated and called as such:\n# obj = RandomizedCollection.new()\n# param_1 = obj.insert(val)\n# param_2 = obj.remove(val)\n# param_3 = obj.get_random()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass RandomizedCollection {\n\n /** Initialize your data structure here. */\n init() {\n\n }\n \n /** Inserts a value to the collection. Returns true if the collection did not already contain the specified element. */\n func insert(_ val: Int) -> Bool {\n\n }\n \n /** Removes a value from the collection. Returns true if the collection contained the specified element. */\n func remove(_ val: Int) -> Bool {\n\n }\n \n /** Get a random element from the collection. */\n func getRandom() -> Int {\n\n }\n}\n\n/**\n * Your RandomizedCollection object will be instantiated and called as such:\n * let obj = RandomizedCollection()\n * let ret_1: Bool = obj.insert(val)\n * let ret_2: Bool = obj.remove(val)\n * let ret_3: Int = obj.getRandom()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type RandomizedCollection struct {\n\n}\n\n\n/** Initialize your data structure here. */\nfunc Constructor() RandomizedCollection {\n\n}\n\n\n/** Inserts a value to the collection. Returns true if the collection did not already contain the specified element. */\nfunc (this *RandomizedCollection) Insert(val int) bool {\n\n}\n\n\n/** Removes a value from the collection. Returns true if the collection contained the specified element. */\nfunc (this *RandomizedCollection) Remove(val int) bool {\n\n}\n\n\n/** Get a random element from the collection. */\nfunc (this *RandomizedCollection) GetRandom() int {\n\n}\n\n\n/**\n * Your RandomizedCollection object will be instantiated and called as such:\n * obj := Constructor();\n * param_1 := obj.Insert(val);\n * param_2 := obj.Remove(val);\n * param_3 := obj.GetRandom();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class RandomizedCollection() {\n\n /** Initialize your data structure here. */\n\n\n /** Inserts a value to the collection. Returns true if the collection did not already contain the specified element. */\n def insert(`val`: Int): Boolean = {\n\n }\n\n /** Removes a value from the collection. Returns true if the collection contained the specified element. */\n def remove(`val`: Int): Boolean = {\n\n }\n\n /** Get a random element from the collection. */\n def getRandom(): Int = {\n\n }\n\n}\n\n/**\n * Your RandomizedCollection object will be instantiated and called as such:\n * var obj = new RandomizedCollection()\n * var param_1 = obj.insert(`val`)\n * var param_2 = obj.remove(`val`)\n * var param_3 = obj.getRandom()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class RandomizedCollection() {\n\n /** Initialize your data structure here. */\n\n\n /** Inserts a value to the collection. Returns true if the collection did not already contain the specified element. */\n fun insert(`val`: Int): Boolean {\n\n }\n\n /** Removes a value from the collection. Returns true if the collection contained the specified element. */\n fun remove(`val`: Int): Boolean {\n\n }\n\n /** Get a random element from the collection. */\n fun getRandom(): Int {\n\n }\n\n}\n\n/**\n * Your RandomizedCollection object will be instantiated and called as such:\n * var obj = RandomizedCollection()\n * var param_1 = obj.insert(`val`)\n * var param_2 = obj.remove(`val`)\n * var param_3 = obj.getRandom()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct RandomizedCollection {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl RandomizedCollection {\n\n /** Initialize your data structure here. */\n fn new() -> Self {\n\n }\n \n /** Inserts a value to the collection. Returns true if the collection did not already contain the specified element. */\n fn insert(&self, val: i32) -> bool {\n\n }\n \n /** Removes a value from the collection. Returns true if the collection contained the specified element. */\n fn remove(&self, val: i32) -> bool {\n\n }\n \n /** Get a random element from the collection. */\n fn get_random(&self) -> i32 {\n\n }\n}\n\n/**\n * Your RandomizedCollection object will be instantiated and called as such:\n * let obj = RandomizedCollection::new();\n * let ret_1: bool = obj.insert(val);\n * let ret_2: bool = obj.remove(val);\n * let ret_3: i32 = obj.get_random();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class RandomizedCollection {\n /**\n * Initialize your data structure here.\n */\n function __construct() {\n\n }\n\n /**\n * Inserts a value to the collection. Returns true if the collection did not already contain the specified element.\n * @param Integer $val\n * @return Boolean\n */\n function insert($val) {\n\n }\n\n /**\n * Removes a value from the collection. Returns true if the collection contained the specified element.\n * @param Integer $val\n * @return Boolean\n */\n function remove($val) {\n\n }\n\n /**\n * Get a random element from the collection.\n * @return Integer\n */\n function getRandom() {\n\n }\n}\n\n/**\n * Your RandomizedCollection object will be instantiated and called as such:\n * $obj = RandomizedCollection();\n * $ret_1 = $obj->insert($val);\n * $ret_2 = $obj->remove($val);\n * $ret_3 = $obj->getRandom();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class RandomizedCollection {\n constructor() {\n\n }\n\n insert(val: number): boolean {\n\n }\n\n remove(val: number): boolean {\n\n }\n\n getRandom(): number {\n\n }\n}\n\n/**\n * Your RandomizedCollection object will be instantiated and called as such:\n * var obj = new RandomizedCollection()\n * var param_1 = obj.insert(val)\n * var param_2 = obj.remove(val)\n * var param_3 = obj.getRandom()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define randomized-collection%\n (class object%\n (super-new)\n (init-field)\n \n ; insert : exact-integer? -> boolean?\n (define/public (insert val)\n\n )\n ; remove : exact-integer? -> boolean?\n (define/public (remove val)\n\n )\n ; get-random : -> exact-integer?\n (define/public (get-random)\n\n )))\n\n;; Your randomized-collection% object will be instantiated and called as such:\n;; (define obj (new randomized-collection%))\n;; (define param_1 (send obj insert val))\n;; (define param_2 (send obj remove val))\n;; (define param_3 (send obj get-random))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0381](https://leetcode-cn.com/problems/insert-delete-getrandom-o1-duplicates-allowed)", "[O(1) \u65f6\u95f4\u63d2\u5165\u3001\u5220\u9664\u548c\u83b7\u53d6\u968f\u673a\u5143\u7d20 - \u5141\u8bb8\u91cd\u590d](/solution/0300-0399/0381.Insert%20Delete%20GetRandom%20O%281%29%20-%20Duplicates%20allowed/README.md)", "`\u8bbe\u8ba1`,`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`", "\u56f0\u96be", ""], "md_table_row_en": ["[0381](https://leetcode.com/problems/insert-delete-getrandom-o1-duplicates-allowed)", "[Insert Delete GetRandom O(1) - Duplicates allowed](/solution/0300-0399/0381.Insert%20Delete%20GetRandom%20O%281%29%20-%20Duplicates%20allowed/README_EN.md)", "`Design`,`Array`,`Hash Table`", "Hard", ""]}, {"question_id": "0380", "frontend_question_id": "0380", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/insert-delete-getrandom-o1", "url_en": "https://leetcode.com/problems/insert-delete-getrandom-o1", "relative_path_cn": "/solution/0300-0399/0380.Insert%20Delete%20GetRandom%20O%281%29/README.md", "relative_path_en": "/solution/0300-0399/0380.Insert%20Delete%20GetRandom%20O%281%29/README_EN.md", "title_cn": "O(1) \u65f6\u95f4\u63d2\u5165\u3001\u5220\u9664\u548c\u83b7\u53d6\u968f\u673a\u5143\u7d20", "title_en": "Insert Delete GetRandom O(1)", "question_title_slug": "insert-delete-getrandom-o1", "content_en": "

    Implement the RandomizedSet class:

    \n\n
      \n\t
    • RandomizedSet() Initializes the RandomizedSet object.
    • \n\t
    • bool insert(int val) Inserts an item val into the set if not present. Returns true if the item was not present, false otherwise.
    • \n\t
    • bool remove(int val) Removes an item val from the set if present. Returns true if the item was present, false otherwise.
    • \n\t
    • int getRandom() Returns a random element from the current set of elements (it's guaranteed that at least one element exists when this method is called). Each element must have the same probability of being returned.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["RandomizedSet", "insert", "remove", "insert", "getRandom", "remove", "insert", "getRandom"]\n[[], [1], [2], [2], [], [1], [2], []]\nOutput\n[null, true, false, true, 2, true, false, 2]\n\nExplanation\nRandomizedSet randomizedSet = new RandomizedSet();\nrandomizedSet.insert(1); // Inserts 1 to the set. Returns true as 1 was inserted successfully.\nrandomizedSet.remove(2); // Returns false as 2 does not exist in the set.\nrandomizedSet.insert(2); // Inserts 2 to the set, returns true. Set now contains [1,2].\nrandomizedSet.getRandom(); // getRandom() should return either 1 or 2 randomly.\nrandomizedSet.remove(1); // Removes 1 from the set, returns true. Set now contains [2].\nrandomizedSet.insert(2); // 2 was already in the set, so return false.\nrandomizedSet.getRandom(); // Since 2 is the only number in the set, getRandom() will always return 2.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • -231 <= val <= 231 - 1
    • \n\t
    • At most 105 calls will be made to insert, remove, and getRandom.
    • \n\t
    • There will be at least one element in the data structure when getRandom is called.
    • \n
    \n\n

     

    \nFollow up: Could you implement the functions of the class with each function works in average O(1) time?", "content_cn": "

    \u8bbe\u8ba1\u4e00\u4e2a\u652f\u6301\u5728\u5e73\u5747 \u65f6\u95f4\u590d\u6742\u5ea6 O(1) \u4e0b\uff0c\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\u7684\u6570\u636e\u7ed3\u6784\u3002

    \n\n
      \n\t
    1. insert(val)\uff1a\u5f53\u5143\u7d20 val \u4e0d\u5b58\u5728\u65f6\uff0c\u5411\u96c6\u5408\u4e2d\u63d2\u5165\u8be5\u9879\u3002
    2. \n\t
    3. remove(val)\uff1a\u5143\u7d20 val \u5b58\u5728\u65f6\uff0c\u4ece\u96c6\u5408\u4e2d\u79fb\u9664\u8be5\u9879\u3002
    4. \n\t
    5. getRandom\uff1a\u968f\u673a\u8fd4\u56de\u73b0\u6709\u96c6\u5408\u4e2d\u7684\u4e00\u9879\u3002\u6bcf\u4e2a\u5143\u7d20\u5e94\u8be5\u6709\u76f8\u540c\u7684\u6982\u7387\u88ab\u8fd4\u56de\u3002
    6. \n
    \n\n

    \u793a\u4f8b :

    \n\n
    \n// \u521d\u59cb\u5316\u4e00\u4e2a\u7a7a\u7684\u96c6\u5408\u3002\nRandomizedSet randomSet = new RandomizedSet();\n\n// \u5411\u96c6\u5408\u4e2d\u63d2\u5165 1 \u3002\u8fd4\u56de true \u8868\u793a 1 \u88ab\u6210\u529f\u5730\u63d2\u5165\u3002\nrandomSet.insert(1);\n\n// \u8fd4\u56de false \uff0c\u8868\u793a\u96c6\u5408\u4e2d\u4e0d\u5b58\u5728 2 \u3002\nrandomSet.remove(2);\n\n// \u5411\u96c6\u5408\u4e2d\u63d2\u5165 2 \u3002\u8fd4\u56de true \u3002\u96c6\u5408\u73b0\u5728\u5305\u542b [1,2] \u3002\nrandomSet.insert(2);\n\n// getRandom \u5e94\u968f\u673a\u8fd4\u56de 1 \u6216 2 \u3002\nrandomSet.getRandom();\n\n// \u4ece\u96c6\u5408\u4e2d\u79fb\u9664 1 \uff0c\u8fd4\u56de true \u3002\u96c6\u5408\u73b0\u5728\u5305\u542b [2] \u3002\nrandomSet.remove(1);\n\n// 2 \u5df2\u5728\u96c6\u5408\u4e2d\uff0c\u6240\u4ee5\u8fd4\u56de false \u3002\nrandomSet.insert(2);\n\n// \u7531\u4e8e 2 \u662f\u96c6\u5408\u4e2d\u552f\u4e00\u7684\u6570\u5b57\uff0cgetRandom \u603b\u662f\u8fd4\u56de 2 \u3002\nrandomSet.getRandom();\n
    \n", "tags_en": ["Design", "Array", "Hash Table"], "tags_cn": ["\u8bbe\u8ba1", "\u6570\u7ec4", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class RandomizedSet {\npublic:\n /** Initialize your data structure here. */\n RandomizedSet() {\n\n }\n \n /** Inserts a value to the set. Returns true if the set did not already contain the specified element. */\n bool insert(int val) {\n\n }\n \n /** Removes a value from the set. Returns true if the set contained the specified element. */\n bool remove(int val) {\n\n }\n \n /** Get a random element from the set. */\n int getRandom() {\n\n }\n};\n\n/**\n * Your RandomizedSet object will be instantiated and called as such:\n * RandomizedSet* obj = new RandomizedSet();\n * bool param_1 = obj->insert(val);\n * bool param_2 = obj->remove(val);\n * int param_3 = obj->getRandom();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class RandomizedSet {\n\n /** Initialize your data structure here. */\n public RandomizedSet() {\n\n }\n \n /** Inserts a value to the set. Returns true if the set did not already contain the specified element. */\n public boolean insert(int val) {\n\n }\n \n /** Removes a value from the set. Returns true if the set contained the specified element. */\n public boolean remove(int val) {\n\n }\n \n /** Get a random element from the set. */\n public int getRandom() {\n\n }\n}\n\n/**\n * Your RandomizedSet object will be instantiated and called as such:\n * RandomizedSet obj = new RandomizedSet();\n * boolean param_1 = obj.insert(val);\n * boolean param_2 = obj.remove(val);\n * int param_3 = obj.getRandom();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class RandomizedSet(object):\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def insert(self, val):\n \"\"\"\n Inserts a value to the set. Returns true if the set did not already contain the specified element.\n :type val: int\n :rtype: bool\n \"\"\"\n\n\n def remove(self, val):\n \"\"\"\n Removes a value from the set. Returns true if the set contained the specified element.\n :type val: int\n :rtype: bool\n \"\"\"\n\n\n def getRandom(self):\n \"\"\"\n Get a random element from the set.\n :rtype: int\n \"\"\"\n\n\n\n# Your RandomizedSet object will be instantiated and called as such:\n# obj = RandomizedSet()\n# param_1 = obj.insert(val)\n# param_2 = obj.remove(val)\n# param_3 = obj.getRandom()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class RandomizedSet:\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def insert(self, val: int) -> bool:\n \"\"\"\n Inserts a value to the set. Returns true if the set did not already contain the specified element.\n \"\"\"\n\n\n def remove(self, val: int) -> bool:\n \"\"\"\n Removes a value from the set. Returns true if the set contained the specified element.\n \"\"\"\n\n\n def getRandom(self) -> int:\n \"\"\"\n Get a random element from the set.\n \"\"\"\n\n\n\n# Your RandomizedSet object will be instantiated and called as such:\n# obj = RandomizedSet()\n# param_1 = obj.insert(val)\n# param_2 = obj.remove(val)\n# param_3 = obj.getRandom()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} RandomizedSet;\n\n/** Initialize your data structure here. */\n\nRandomizedSet* randomizedSetCreate() {\n\n}\n\n/** Inserts a value to the set. Returns true if the set did not already contain the specified element. */\nbool randomizedSetInsert(RandomizedSet* obj, int val) {\n\n}\n\n/** Removes a value from the set. Returns true if the set contained the specified element. */\nbool randomizedSetRemove(RandomizedSet* obj, int val) {\n\n}\n\n/** Get a random element from the set. */\nint randomizedSetGetRandom(RandomizedSet* obj) {\n\n}\n\nvoid randomizedSetFree(RandomizedSet* obj) {\n\n}\n\n/**\n * Your RandomizedSet struct will be instantiated and called as such:\n * RandomizedSet* obj = randomizedSetCreate();\n * bool param_1 = randomizedSetInsert(obj, val);\n \n * bool param_2 = randomizedSetRemove(obj, val);\n \n * int param_3 = randomizedSetGetRandom(obj);\n \n * randomizedSetFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class RandomizedSet {\n\n /** Initialize your data structure here. */\n public RandomizedSet() {\n\n }\n \n /** Inserts a value to the set. Returns true if the set did not already contain the specified element. */\n public bool Insert(int val) {\n\n }\n \n /** Removes a value from the set. Returns true if the set contained the specified element. */\n public bool Remove(int val) {\n\n }\n \n /** Get a random element from the set. */\n public int GetRandom() {\n\n }\n}\n\n/**\n * Your RandomizedSet object will be instantiated and called as such:\n * RandomizedSet obj = new RandomizedSet();\n * bool param_1 = obj.Insert(val);\n * bool param_2 = obj.Remove(val);\n * int param_3 = obj.GetRandom();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Initialize your data structure here.\n */\nvar RandomizedSet = function() {\n\n};\n\n/**\n * Inserts a value to the set. Returns true if the set did not already contain the specified element. \n * @param {number} val\n * @return {boolean}\n */\nRandomizedSet.prototype.insert = function(val) {\n\n};\n\n/**\n * Removes a value from the set. Returns true if the set contained the specified element. \n * @param {number} val\n * @return {boolean}\n */\nRandomizedSet.prototype.remove = function(val) {\n\n};\n\n/**\n * Get a random element from the set.\n * @return {number}\n */\nRandomizedSet.prototype.getRandom = function() {\n\n};\n\n/**\n * Your RandomizedSet object will be instantiated and called as such:\n * var obj = new RandomizedSet()\n * var param_1 = obj.insert(val)\n * var param_2 = obj.remove(val)\n * var param_3 = obj.getRandom()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class RandomizedSet\n\n=begin\n Initialize your data structure here.\n=end\n def initialize()\n\n end\n\n\n=begin\n Inserts a value to the set. Returns true if the set did not already contain the specified element.\n :type val: Integer\n :rtype: Boolean\n=end\n def insert(val)\n\n end\n\n\n=begin\n Removes a value from the set. Returns true if the set contained the specified element.\n :type val: Integer\n :rtype: Boolean\n=end\n def remove(val)\n\n end\n\n\n=begin\n Get a random element from the set.\n :rtype: Integer\n=end\n def get_random()\n\n end\n\n\nend\n\n# Your RandomizedSet object will be instantiated and called as such:\n# obj = RandomizedSet.new()\n# param_1 = obj.insert(val)\n# param_2 = obj.remove(val)\n# param_3 = obj.get_random()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass RandomizedSet {\n\n /** Initialize your data structure here. */\n init() {\n\n }\n \n /** Inserts a value to the set. Returns true if the set did not already contain the specified element. */\n func insert(_ val: Int) -> Bool {\n\n }\n \n /** Removes a value from the set. Returns true if the set contained the specified element. */\n func remove(_ val: Int) -> Bool {\n\n }\n \n /** Get a random element from the set. */\n func getRandom() -> Int {\n\n }\n}\n\n/**\n * Your RandomizedSet object will be instantiated and called as such:\n * let obj = RandomizedSet()\n * let ret_1: Bool = obj.insert(val)\n * let ret_2: Bool = obj.remove(val)\n * let ret_3: Int = obj.getRandom()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type RandomizedSet struct {\n\n}\n\n\n/** Initialize your data structure here. */\nfunc Constructor() RandomizedSet {\n\n}\n\n\n/** Inserts a value to the set. Returns true if the set did not already contain the specified element. */\nfunc (this *RandomizedSet) Insert(val int) bool {\n\n}\n\n\n/** Removes a value from the set. Returns true if the set contained the specified element. */\nfunc (this *RandomizedSet) Remove(val int) bool {\n\n}\n\n\n/** Get a random element from the set. */\nfunc (this *RandomizedSet) GetRandom() int {\n\n}\n\n\n/**\n * Your RandomizedSet object will be instantiated and called as such:\n * obj := Constructor();\n * param_1 := obj.Insert(val);\n * param_2 := obj.Remove(val);\n * param_3 := obj.GetRandom();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class RandomizedSet() {\n\n /** Initialize your data structure here. */\n\n\n /** Inserts a value to the set. Returns true if the set did not already contain the specified element. */\n def insert(`val`: Int): Boolean = {\n\n }\n\n /** Removes a value from the set. Returns true if the set contained the specified element. */\n def remove(`val`: Int): Boolean = {\n\n }\n\n /** Get a random element from the set. */\n def getRandom(): Int = {\n\n }\n\n}\n\n/**\n * Your RandomizedSet object will be instantiated and called as such:\n * var obj = new RandomizedSet()\n * var param_1 = obj.insert(`val`)\n * var param_2 = obj.remove(`val`)\n * var param_3 = obj.getRandom()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class RandomizedSet() {\n\n /** Initialize your data structure here. */\n\n\n /** Inserts a value to the set. Returns true if the set did not already contain the specified element. */\n fun insert(`val`: Int): Boolean {\n\n }\n\n /** Removes a value from the set. Returns true if the set contained the specified element. */\n fun remove(`val`: Int): Boolean {\n\n }\n\n /** Get a random element from the set. */\n fun getRandom(): Int {\n\n }\n\n}\n\n/**\n * Your RandomizedSet object will be instantiated and called as such:\n * var obj = RandomizedSet()\n * var param_1 = obj.insert(`val`)\n * var param_2 = obj.remove(`val`)\n * var param_3 = obj.getRandom()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct RandomizedSet {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl RandomizedSet {\n\n /** Initialize your data structure here. */\n fn new() -> Self {\n\n }\n \n /** Inserts a value to the set. Returns true if the set did not already contain the specified element. */\n fn insert(&self, val: i32) -> bool {\n\n }\n \n /** Removes a value from the set. Returns true if the set contained the specified element. */\n fn remove(&self, val: i32) -> bool {\n\n }\n \n /** Get a random element from the set. */\n fn get_random(&self) -> i32 {\n\n }\n}\n\n/**\n * Your RandomizedSet object will be instantiated and called as such:\n * let obj = RandomizedSet::new();\n * let ret_1: bool = obj.insert(val);\n * let ret_2: bool = obj.remove(val);\n * let ret_3: i32 = obj.get_random();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class RandomizedSet {\n /**\n * Initialize your data structure here.\n */\n function __construct() {\n\n }\n\n /**\n * Inserts a value to the set. Returns true if the set did not already contain the specified element.\n * @param Integer $val\n * @return Boolean\n */\n function insert($val) {\n\n }\n\n /**\n * Removes a value from the set. Returns true if the set contained the specified element.\n * @param Integer $val\n * @return Boolean\n */\n function remove($val) {\n\n }\n\n /**\n * Get a random element from the set.\n * @return Integer\n */\n function getRandom() {\n\n }\n}\n\n/**\n * Your RandomizedSet object will be instantiated and called as such:\n * $obj = RandomizedSet();\n * $ret_1 = $obj->insert($val);\n * $ret_2 = $obj->remove($val);\n * $ret_3 = $obj->getRandom();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class RandomizedSet {\n constructor() {\n\n }\n\n insert(val: number): boolean {\n\n }\n\n remove(val: number): boolean {\n\n }\n\n getRandom(): number {\n\n }\n}\n\n/**\n * Your RandomizedSet object will be instantiated and called as such:\n * var obj = new RandomizedSet()\n * var param_1 = obj.insert(val)\n * var param_2 = obj.remove(val)\n * var param_3 = obj.getRandom()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define randomized-set%\n (class object%\n (super-new)\n (init-field)\n \n ; insert : exact-integer? -> boolean?\n (define/public (insert val)\n\n )\n ; remove : exact-integer? -> boolean?\n (define/public (remove val)\n\n )\n ; get-random : -> exact-integer?\n (define/public (get-random)\n\n )))\n\n;; Your randomized-set% object will be instantiated and called as such:\n;; (define obj (new randomized-set%))\n;; (define param_1 (send obj insert val))\n;; (define param_2 (send obj remove val))\n;; (define param_3 (send obj get-random))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0380](https://leetcode-cn.com/problems/insert-delete-getrandom-o1)", "[O(1) \u65f6\u95f4\u63d2\u5165\u3001\u5220\u9664\u548c\u83b7\u53d6\u968f\u673a\u5143\u7d20](/solution/0300-0399/0380.Insert%20Delete%20GetRandom%20O%281%29/README.md)", "`\u8bbe\u8ba1`,`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0380](https://leetcode.com/problems/insert-delete-getrandom-o1)", "[Insert Delete GetRandom O(1)](/solution/0300-0399/0380.Insert%20Delete%20GetRandom%20O%281%29/README_EN.md)", "`Design`,`Array`,`Hash Table`", "Medium", ""]}, {"question_id": "0379", "frontend_question_id": "0379", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/design-phone-directory", "url_en": "https://leetcode.com/problems/design-phone-directory", "relative_path_cn": "/solution/0300-0399/0379.Design%20Phone%20Directory/README.md", "relative_path_en": "/solution/0300-0399/0379.Design%20Phone%20Directory/README_EN.md", "title_cn": "\u7535\u8bdd\u76ee\u5f55\u7ba1\u7406\u7cfb\u7edf", "title_en": "Design Phone Directory", "question_title_slug": "design-phone-directory", "content_en": "

    Design a phone directory that initially has maxNumbers empty slots that can store numbers. The directory should store numbers, check if a certain slot is empty or not, and empty a given slot.

    \n\n

    Implement the PhoneDirectory class:

    \n\n
      \n\t
    • PhoneDirectory(int maxNumbers) Initializes the phone directory with the number of available slots maxNumbers.
    • \n\t
    • int get() Provides a number that is not assigned to anyone. Returns -1 if no number is available.
    • \n\t
    • bool check(int number) Returns true if the slot number is available and false otherwise.
    • \n\t
    • void release(int number) Recycles or releases the slot number.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["PhoneDirectory", "get", "get", "check", "get", "check", "release", "check"]\n[[3], [], [], [2], [], [2], [2], [2]]\nOutput\n[null, 0, 1, true, 2, false, null, true]\n\nExplanation\nPhoneDirectory phoneDirectory = new PhoneDirectory(3);\nphoneDirectory.get();      // It can return any available phone number. Here we assume it returns 0.\nphoneDirectory.get();      // Assume it returns 1.\nphoneDirectory.check(2);   // The number 2 is available, so return true.\nphoneDirectory.get();      // It returns 2, the only number that is left.\nphoneDirectory.check(2);   // The number 2 is no longer available, so return false.\nphoneDirectory.release(2); // Release number 2 back to the pool.\nphoneDirectory.check(2);   // Number 2 is available again, return true.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= maxNumbers <= 104
    • \n\t
    • 0 <= number < maxNumbers
    • \n\t
    • At most 2 * 104 calls will be made to get, check, and release.
    • \n
    \n", "content_cn": "

    \u8bbe\u8ba1\u4e00\u4e2a\u7535\u8bdd\u76ee\u5f55\u7ba1\u7406\u7cfb\u7edf\uff0c\u8ba9\u5b83\u652f\u6301\u4ee5\u4e0b\u529f\u80fd\uff1a

    \n\n
      \n\t
    1. get: \u5206\u914d\u7ed9\u7528\u6237\u4e00\u4e2a\u672a\u88ab\u4f7f\u7528\u7684\u7535\u8bdd\u53f7\u7801\uff0c\u83b7\u53d6\u5931\u8d25\u8bf7\u8fd4\u56de -1
    2. \n\t
    3. check: \u68c0\u67e5\u6307\u5b9a\u7684\u7535\u8bdd\u53f7\u7801\u662f\u5426\u88ab\u4f7f\u7528
    4. \n\t
    5. release: \u91ca\u653e\u6389\u4e00\u4e2a\u7535\u8bdd\u53f7\u7801\uff0c\u4f7f\u5176\u80fd\u591f\u91cd\u65b0\u88ab\u5206\u914d
    6. \n
    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    // \u521d\u59cb\u5316\u7535\u8bdd\u76ee\u5f55\uff0c\u5305\u62ec 3 \u4e2a\u7535\u8bdd\u53f7\u7801\uff1a0\uff0c1 \u548c 2\u3002\nPhoneDirectory directory = new PhoneDirectory(3);\n\n// \u53ef\u4ee5\u8fd4\u56de\u4efb\u610f\u672a\u5206\u914d\u7684\u53f7\u7801\uff0c\u8fd9\u91cc\u6211\u4eec\u5047\u8bbe\u5b83\u8fd4\u56de 0\u3002\ndirectory.get();\n\n// \u5047\u8bbe\uff0c\u51fd\u6570\u8fd4\u56de 1\u3002\ndirectory.get();\n\n// \u53f7\u7801 2 \u672a\u5206\u914d\uff0c\u6240\u4ee5\u8fd4\u56de\u4e3a true\u3002\ndirectory.check(2);\n\n// \u8fd4\u56de 2\uff0c\u5206\u914d\u540e\uff0c\u53ea\u5269\u4e00\u4e2a\u53f7\u7801\u672a\u88ab\u5206\u914d\u3002\ndirectory.get();\n\n// \u6b64\u65f6\uff0c\u53f7\u7801 2 \u5df2\u7ecf\u88ab\u5206\u914d\uff0c\u6240\u4ee5\u8fd4\u56de false\u3002\ndirectory.check(2);\n\n// \u91ca\u653e\u53f7\u7801 2\uff0c\u5c06\u8be5\u53f7\u7801\u53d8\u56de\u672a\u5206\u914d\u72b6\u6001\u3002\ndirectory.release(2);\n\n// \u53f7\u7801 2 \u73b0\u5728\u662f\u672a\u5206\u914d\u72b6\u6001\uff0c\u6240\u4ee5\u8fd4\u56de true\u3002\ndirectory.check(2);\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= maxNumbers <= 10^4
    • \n\t
    • 0 <= number < maxNumbers
    • \n\t
    • \u8c03\u7528\u65b9\u6cd5\u7684\u603b\u6570\u5904\u4e8e\u533a\u95f4 [0 - 20000] \u4e4b\u5185
    • \n
    \n", "tags_en": ["Design", "Linked List"], "tags_cn": ["\u8bbe\u8ba1", "\u94fe\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class PhoneDirectory {\npublic:\n /** Initialize your data structure here\n @param maxNumbers - The maximum numbers that can be stored in the phone directory. */\n PhoneDirectory(int maxNumbers) {\n\n }\n \n /** Provide a number which is not assigned to anyone.\n @return - Return an available number. Return -1 if none is available. */\n int get() {\n\n }\n \n /** Check if a number is available or not. */\n bool check(int number) {\n\n }\n \n /** Recycle or release a number. */\n void release(int number) {\n\n }\n};\n\n/**\n * Your PhoneDirectory object will be instantiated and called as such:\n * PhoneDirectory* obj = new PhoneDirectory(maxNumbers);\n * int param_1 = obj->get();\n * bool param_2 = obj->check(number);\n * obj->release(number);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class PhoneDirectory {\n\n /** Initialize your data structure here\n @param maxNumbers - The maximum numbers that can be stored in the phone directory. */\n public PhoneDirectory(int maxNumbers) {\n\n }\n \n /** Provide a number which is not assigned to anyone.\n @return - Return an available number. Return -1 if none is available. */\n public int get() {\n\n }\n \n /** Check if a number is available or not. */\n public boolean check(int number) {\n\n }\n \n /** Recycle or release a number. */\n public void release(int number) {\n\n }\n}\n\n/**\n * Your PhoneDirectory object will be instantiated and called as such:\n * PhoneDirectory obj = new PhoneDirectory(maxNumbers);\n * int param_1 = obj.get();\n * boolean param_2 = obj.check(number);\n * obj.release(number);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class PhoneDirectory(object):\n\n def __init__(self, maxNumbers):\n \"\"\"\n Initialize your data structure here\n @param maxNumbers - The maximum numbers that can be stored in the phone directory.\n :type maxNumbers: int\n \"\"\"\n\n\n def get(self):\n \"\"\"\n Provide a number which is not assigned to anyone.\n @return - Return an available number. Return -1 if none is available.\n :rtype: int\n \"\"\"\n\n\n def check(self, number):\n \"\"\"\n Check if a number is available or not.\n :type number: int\n :rtype: bool\n \"\"\"\n\n\n def release(self, number):\n \"\"\"\n Recycle or release a number.\n :type number: int\n :rtype: None\n \"\"\"\n\n\n\n# Your PhoneDirectory object will be instantiated and called as such:\n# obj = PhoneDirectory(maxNumbers)\n# param_1 = obj.get()\n# param_2 = obj.check(number)\n# obj.release(number)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class PhoneDirectory:\n\n def __init__(self, maxNumbers: int):\n \"\"\"\n Initialize your data structure here\n @param maxNumbers - The maximum numbers that can be stored in the phone directory.\n \"\"\"\n\n\n def get(self) -> int:\n \"\"\"\n Provide a number which is not assigned to anyone.\n @return - Return an available number. Return -1 if none is available.\n \"\"\"\n\n\n def check(self, number: int) -> bool:\n \"\"\"\n Check if a number is available or not.\n \"\"\"\n\n\n def release(self, number: int) -> None:\n \"\"\"\n Recycle or release a number.\n \"\"\"\n\n\n\n# Your PhoneDirectory object will be instantiated and called as such:\n# obj = PhoneDirectory(maxNumbers)\n# param_1 = obj.get()\n# param_2 = obj.check(number)\n# obj.release(number)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} PhoneDirectory;\n\n/** Initialize your data structure here\n @param maxNumbers - The maximum numbers that can be stored in the phone directory. */\n\nPhoneDirectory* phoneDirectoryCreate(int maxNumbers) {\n\n}\n\n/** Provide a number which is not assigned to anyone.\n @return - Return an available number. Return -1 if none is available. */\nint phoneDirectoryGet(PhoneDirectory* obj) {\n\n}\n\n/** Check if a number is available or not. */\nbool phoneDirectoryCheck(PhoneDirectory* obj, int number) {\n\n}\n\n/** Recycle or release a number. */\nvoid phoneDirectoryRelease(PhoneDirectory* obj, int number) {\n\n}\n\nvoid phoneDirectoryFree(PhoneDirectory* obj) {\n\n}\n\n/**\n * Your PhoneDirectory struct will be instantiated and called as such:\n * PhoneDirectory* obj = phoneDirectoryCreate(maxNumbers);\n * int param_1 = phoneDirectoryGet(obj);\n \n * bool param_2 = phoneDirectoryCheck(obj, number);\n \n * phoneDirectoryRelease(obj, number);\n \n * phoneDirectoryFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class PhoneDirectory {\n\n /** Initialize your data structure here\n @param maxNumbers - The maximum numbers that can be stored in the phone directory. */\n public PhoneDirectory(int maxNumbers) {\n\n }\n \n /** Provide a number which is not assigned to anyone.\n @return - Return an available number. Return -1 if none is available. */\n public int Get() {\n\n }\n \n /** Check if a number is available or not. */\n public bool Check(int number) {\n\n }\n \n /** Recycle or release a number. */\n public void Release(int number) {\n\n }\n}\n\n/**\n * Your PhoneDirectory object will be instantiated and called as such:\n * PhoneDirectory obj = new PhoneDirectory(maxNumbers);\n * int param_1 = obj.Get();\n * bool param_2 = obj.Check(number);\n * obj.Release(number);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Initialize your data structure here\n @param maxNumbers - The maximum numbers that can be stored in the phone directory.\n * @param {number} maxNumbers\n */\nvar PhoneDirectory = function(maxNumbers) {\n\n};\n\n/**\n * Provide a number which is not assigned to anyone.\n @return - Return an available number. Return -1 if none is available.\n * @return {number}\n */\nPhoneDirectory.prototype.get = function() {\n\n};\n\n/**\n * Check if a number is available or not. \n * @param {number} number\n * @return {boolean}\n */\nPhoneDirectory.prototype.check = function(number) {\n\n};\n\n/**\n * Recycle or release a number. \n * @param {number} number\n * @return {void}\n */\nPhoneDirectory.prototype.release = function(number) {\n\n};\n\n/**\n * Your PhoneDirectory object will be instantiated and called as such:\n * var obj = new PhoneDirectory(maxNumbers)\n * var param_1 = obj.get()\n * var param_2 = obj.check(number)\n * obj.release(number)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class PhoneDirectory\n\n=begin\n Initialize your data structure here\n @param maxNumbers - The maximum numbers that can be stored in the phone directory.\n :type max_numbers: Integer\n=end\n def initialize(max_numbers)\n\n end\n\n\n=begin\n Provide a number which is not assigned to anyone.\n @return - Return an available number. Return -1 if none is available.\n :rtype: Integer\n=end\n def get()\n\n end\n\n\n=begin\n Check if a number is available or not.\n :type number: Integer\n :rtype: Boolean\n=end\n def check(number)\n\n end\n\n\n=begin\n Recycle or release a number.\n :type number: Integer\n :rtype: Void\n=end\n def release(number)\n\n end\n\n\nend\n\n# Your PhoneDirectory object will be instantiated and called as such:\n# obj = PhoneDirectory.new(max_numbers)\n# param_1 = obj.get()\n# param_2 = obj.check(number)\n# obj.release(number)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass PhoneDirectory {\n\n /** Initialize your data structure here\n @param maxNumbers - The maximum numbers that can be stored in the phone directory. */\n init(_ maxNumbers: Int) {\n\n }\n \n /** Provide a number which is not assigned to anyone.\n @return - Return an available number. Return -1 if none is available. */\n func get() -> Int {\n\n }\n \n /** Check if a number is available or not. */\n func check(_ number: Int) -> Bool {\n\n }\n \n /** Recycle or release a number. */\n func release(_ number: Int) {\n\n }\n}\n\n/**\n * Your PhoneDirectory object will be instantiated and called as such:\n * let obj = PhoneDirectory(maxNumbers)\n * let ret_1: Int = obj.get()\n * let ret_2: Bool = obj.check(number)\n * obj.release(number)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type PhoneDirectory struct {\n\n}\n\n\n/** Initialize your data structure here\n @param maxNumbers - The maximum numbers that can be stored in the phone directory. */\nfunc Constructor(maxNumbers int) PhoneDirectory {\n\n}\n\n\n/** Provide a number which is not assigned to anyone.\n @return - Return an available number. Return -1 if none is available. */\nfunc (this *PhoneDirectory) Get() int {\n\n}\n\n\n/** Check if a number is available or not. */\nfunc (this *PhoneDirectory) Check(number int) bool {\n\n}\n\n\n/** Recycle or release a number. */\nfunc (this *PhoneDirectory) Release(number int) {\n\n}\n\n\n/**\n * Your PhoneDirectory object will be instantiated and called as such:\n * obj := Constructor(maxNumbers);\n * param_1 := obj.Get();\n * param_2 := obj.Check(number);\n * obj.Release(number);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class PhoneDirectory(_maxNumbers: Int) {\n\n /** Initialize your data structure here\n @param maxNumbers - The maximum numbers that can be stored in the phone directory. */\n\n\n /** Provide a number which is not assigned to anyone.\n @return - Return an available number. Return -1 if none is available. */\n def get(): Int = {\n\n }\n\n /** Check if a number is available or not. */\n def check(number: Int): Boolean = {\n\n }\n\n /** Recycle or release a number. */\n def release(number: Int) {\n\n }\n\n}\n\n/**\n * Your PhoneDirectory object will be instantiated and called as such:\n * var obj = new PhoneDirectory(maxNumbers)\n * var param_1 = obj.get()\n * var param_2 = obj.check(number)\n * obj.release(number)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class PhoneDirectory(maxNumbers: Int) {\n\n /** Initialize your data structure here\n @param maxNumbers - The maximum numbers that can be stored in the phone directory. */\n\n\n /** Provide a number which is not assigned to anyone.\n @return - Return an available number. Return -1 if none is available. */\n fun get(): Int {\n\n }\n\n /** Check if a number is available or not. */\n fun check(number: Int): Boolean {\n\n }\n\n /** Recycle or release a number. */\n fun release(number: Int) {\n\n }\n\n}\n\n/**\n * Your PhoneDirectory object will be instantiated and called as such:\n * var obj = PhoneDirectory(maxNumbers)\n * var param_1 = obj.get()\n * var param_2 = obj.check(number)\n * obj.release(number)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct PhoneDirectory {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl PhoneDirectory {\n\n /** Initialize your data structure here\n @param maxNumbers - The maximum numbers that can be stored in the phone directory. */\n fn new(maxNumbers: i32) -> Self {\n\n }\n \n /** Provide a number which is not assigned to anyone.\n @return - Return an available number. Return -1 if none is available. */\n fn get(&self) -> i32 {\n\n }\n \n /** Check if a number is available or not. */\n fn check(&self, number: i32) -> bool {\n\n }\n \n /** Recycle or release a number. */\n fn release(&self, number: i32) {\n\n }\n}\n\n/**\n * Your PhoneDirectory object will be instantiated and called as such:\n * let obj = PhoneDirectory::new(maxNumbers);\n * let ret_1: i32 = obj.get();\n * let ret_2: bool = obj.check(number);\n * obj.release(number);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class PhoneDirectory {\n /**\n * Initialize your data structure here\n @param maxNumbers - The maximum numbers that can be stored in the phone directory.\n * @param Integer $maxNumbers\n */\n function __construct($maxNumbers) {\n\n }\n\n /**\n * Provide a number which is not assigned to anyone.\n @return - Return an available number. Return -1 if none is available.\n * @return Integer\n */\n function get() {\n\n }\n\n /**\n * Check if a number is available or not.\n * @param Integer $number\n * @return Boolean\n */\n function check($number) {\n\n }\n\n /**\n * Recycle or release a number.\n * @param Integer $number\n * @return NULL\n */\n function release($number) {\n\n }\n}\n\n/**\n * Your PhoneDirectory object will be instantiated and called as such:\n * $obj = PhoneDirectory($maxNumbers);\n * $ret_1 = $obj->get();\n * $ret_2 = $obj->check($number);\n * $obj->release($number);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class PhoneDirectory {\n constructor(maxNumbers: number) {\n\n }\n\n get(): number {\n\n }\n\n check(number: number): boolean {\n\n }\n\n release(number: number): void {\n\n }\n}\n\n/**\n * Your PhoneDirectory object will be instantiated and called as such:\n * var obj = new PhoneDirectory(maxNumbers)\n * var param_1 = obj.get()\n * var param_2 = obj.check(number)\n * obj.release(number)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define phone-directory%\n (class object%\n (super-new)\n\n ; max-numbers : exact-integer?\n (init-field\n max-numbers)\n \n ; get : -> exact-integer?\n (define/public (get)\n\n )\n ; check : exact-integer? -> boolean?\n (define/public (check number)\n\n )\n ; release : exact-integer? -> void?\n (define/public (release number)\n\n )))\n\n;; Your phone-directory% object will be instantiated and called as such:\n;; (define obj (new phone-directory% [maxNumbers maxNumbers]))\n;; (define param_1 (send obj get))\n;; (define param_2 (send obj check number))\n;; (send obj release number)", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0379](https://leetcode-cn.com/problems/design-phone-directory)", "[\u7535\u8bdd\u76ee\u5f55\u7ba1\u7406\u7cfb\u7edf](/solution/0300-0399/0379.Design%20Phone%20Directory/README.md)", "`\u8bbe\u8ba1`,`\u94fe\u8868`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0379](https://leetcode.com/problems/design-phone-directory)", "[Design Phone Directory](/solution/0300-0399/0379.Design%20Phone%20Directory/README_EN.md)", "`Design`,`Linked List`", "Medium", "\ud83d\udd12"]}, {"question_id": "0378", "frontend_question_id": "0378", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/kth-smallest-element-in-a-sorted-matrix", "url_en": "https://leetcode.com/problems/kth-smallest-element-in-a-sorted-matrix", "relative_path_cn": "/solution/0300-0399/0378.Kth%20Smallest%20Element%20in%20a%20Sorted%20Matrix/README.md", "relative_path_en": "/solution/0300-0399/0378.Kth%20Smallest%20Element%20in%20a%20Sorted%20Matrix/README_EN.md", "title_cn": "\u6709\u5e8f\u77e9\u9635\u4e2d\u7b2c K \u5c0f\u7684\u5143\u7d20", "title_en": "Kth Smallest Element in a Sorted Matrix", "question_title_slug": "kth-smallest-element-in-a-sorted-matrix", "content_en": "

    Given an n x n matrix where each of the rows and columns are sorted in ascending order, return the kth smallest element in the matrix.

    \n\n

    Note that it is the kth smallest element in the sorted order, not the kth distinct element.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: matrix = [[1,5,9],[10,11,13],[12,13,15]], k = 8\nOutput: 13\nExplanation: The elements in the matrix are [1,5,9,10,11,12,13,13,15], and the 8th smallest number is 13\n
    \n\n

    Example 2:

    \n\n
    \nInput: matrix = [[-5]], k = 1\nOutput: -5\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == matrix.length
    • \n\t
    • n == matrix[i].length
    • \n\t
    • 1 <= n <= 300
    • \n\t
    • -109 <= matrix[i][j] <= 109
    • \n\t
    • All the rows and columns of matrix are guaranteed to be sorted in non-decreasing order.
    • \n\t
    • 1 <= k <= n2
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u00a0n x n\u00a0\u77e9\u9635\u00a0matrix \uff0c\u5176\u4e2d\u6bcf\u884c\u548c\u6bcf\u5217\u5143\u7d20\u5747\u6309\u5347\u5e8f\u6392\u5e8f\uff0c\u627e\u5230\u77e9\u9635\u4e2d\u7b2c k \u5c0f\u7684\u5143\u7d20\u3002
    \n\u8bf7\u6ce8\u610f\uff0c\u5b83\u662f \u6392\u5e8f\u540e \u7684\u7b2c k \u5c0f\u5143\u7d20\uff0c\u800c\u4e0d\u662f\u7b2c k \u4e2a \u4e0d\u540c \u7684\u5143\u7d20\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1amatrix = [[1,5,9],[10,11,13],[12,13,15]], k = 8\n\u8f93\u51fa\uff1a13\n\u89e3\u91ca\uff1a\u77e9\u9635\u4e2d\u7684\u5143\u7d20\u4e3a [1,5,9,10,11,12,13,13,15]\uff0c\u7b2c 8 \u5c0f\u5143\u7d20\u662f 13\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1amatrix = [[-5]], k = 1\n\u8f93\u51fa\uff1a-5\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == matrix.length
    • \n\t
    • n == matrix[i].length
    • \n\t
    • 1 <= n <= 300
    • \n\t
    • -109 <= matrix[i][j] <= 109
    • \n\t
    • \u9898\u76ee\u6570\u636e \u4fdd\u8bc1 matrix \u4e2d\u7684\u6240\u6709\u884c\u548c\u5217\u90fd\u6309 \u975e\u9012\u51cf\u987a\u5e8f \u6392\u5217
    • \n\t
    • 1 <= k <= n2
    • \n
    \n", "tags_en": ["Heap", "Binary Search"], "tags_cn": ["\u5806", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int kthSmallest(vector>& matrix, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int kthSmallest(int[][] matrix, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def kthSmallest(self, matrix, k):\n \"\"\"\n :type matrix: List[List[int]]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def kthSmallest(self, matrix: List[List[int]], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint kthSmallest(int** matrix, int matrixSize, int* matrixColSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int KthSmallest(int[][] matrix, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} matrix\n * @param {number} k\n * @return {number}\n */\nvar kthSmallest = function(matrix, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} matrix\n# @param {Integer} k\n# @return {Integer}\ndef kth_smallest(matrix, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func kthSmallest(_ matrix: [[Int]], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func kthSmallest(matrix [][]int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def kthSmallest(matrix: Array[Array[Int]], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun kthSmallest(matrix: Array, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn kth_smallest(matrix: Vec>, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $matrix\n * @param Integer $k\n * @return Integer\n */\n function kthSmallest($matrix, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function kthSmallest(matrix: number[][], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (kth-smallest matrix k)\n (-> (listof (listof exact-integer?)) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0378](https://leetcode-cn.com/problems/kth-smallest-element-in-a-sorted-matrix)", "[\u6709\u5e8f\u77e9\u9635\u4e2d\u7b2c K \u5c0f\u7684\u5143\u7d20](/solution/0300-0399/0378.Kth%20Smallest%20Element%20in%20a%20Sorted%20Matrix/README.md)", "`\u5806`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0378](https://leetcode.com/problems/kth-smallest-element-in-a-sorted-matrix)", "[Kth Smallest Element in a Sorted Matrix](/solution/0300-0399/0378.Kth%20Smallest%20Element%20in%20a%20Sorted%20Matrix/README_EN.md)", "`Heap`,`Binary Search`", "Medium", ""]}, {"question_id": "0377", "frontend_question_id": "0377", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/combination-sum-iv", "url_en": "https://leetcode.com/problems/combination-sum-iv", "relative_path_cn": "/solution/0300-0399/0377.Combination%20Sum%20IV/README.md", "relative_path_en": "/solution/0300-0399/0377.Combination%20Sum%20IV/README_EN.md", "title_cn": "\u7ec4\u5408\u603b\u548c \u2163", "title_en": "Combination Sum IV", "question_title_slug": "combination-sum-iv", "content_en": "

    Given an array of distinct integers nums and a target integer target, return the number of possible combinations that add up to target.

    \n\n

    The answer is guaranteed to fit in a 32-bit integer.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,3], target = 4\nOutput: 7\nExplanation:\nThe possible combination ways are:\n(1, 1, 1, 1)\n(1, 1, 2)\n(1, 2, 1)\n(1, 3)\n(2, 1, 1)\n(2, 2)\n(3, 1)\nNote that different sequences are counted as different combinations.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [9], target = 3\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 200
    • \n\t
    • 1 <= nums[i] <= 1000
    • \n\t
    • All the elements of nums are unique.
    • \n\t
    • 1 <= target <= 1000
    • \n
    \n\n

     

    \n

    Follow up: What if negative numbers are allowed in the given array? How does it change the problem? What limitation we need to add to the question to allow negative numbers?

    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u7531 \u4e0d\u540c \u6574\u6570\u7ec4\u6210\u7684\u6570\u7ec4 nums \uff0c\u548c\u4e00\u4e2a\u76ee\u6807\u6574\u6570 target \u3002\u8bf7\u4f60\u4ece nums \u4e2d\u627e\u51fa\u5e76\u8fd4\u56de\u603b\u548c\u4e3a target \u7684\u5143\u7d20\u7ec4\u5408\u7684\u4e2a\u6570\u3002

    \n\n

    \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u7b54\u6848\u7b26\u5408 32 \u4f4d\u6574\u6570\u8303\u56f4\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,3], target = 4\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\n\u6240\u6709\u53ef\u80fd\u7684\u7ec4\u5408\u4e3a\uff1a\n(1, 1, 1, 1)\n(1, 1, 2)\n(1, 2, 1)\n(1, 3)\n(2, 1, 1)\n(2, 2)\n(3, 1)\n\u8bf7\u6ce8\u610f\uff0c\u987a\u5e8f\u4e0d\u540c\u7684\u5e8f\u5217\u88ab\u89c6\u4f5c\u4e0d\u540c\u7684\u7ec4\u5408\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [9], target = 3\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 200
    • \n\t
    • 1 <= nums[i] <= 1000
    • \n\t
    • nums \u4e2d\u7684\u6240\u6709\u5143\u7d20 \u4e92\u4e0d\u76f8\u540c
    • \n\t
    • 1 <= target <= 1000
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u5982\u679c\u7ed9\u5b9a\u7684\u6570\u7ec4\u4e2d\u542b\u6709\u8d1f\u6570\u4f1a\u53d1\u751f\u4ec0\u4e48\uff1f\u95ee\u9898\u4f1a\u4ea7\u751f\u4f55\u79cd\u53d8\u5316\uff1f\u5982\u679c\u5141\u8bb8\u8d1f\u6570\u51fa\u73b0\uff0c\u9700\u8981\u5411\u9898\u76ee\u4e2d\u6dfb\u52a0\u54ea\u4e9b\u9650\u5236\u6761\u4ef6\uff1f

    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int combinationSum4(vector& nums, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int combinationSum4(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def combinationSum4(self, nums, target):\n \"\"\"\n :type nums: List[int]\n :type target: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def combinationSum4(self, nums: List[int], target: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint combinationSum4(int* nums, int numsSize, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CombinationSum4(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} target\n * @return {number}\n */\nvar combinationSum4 = function(nums, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} target\n# @return {Integer}\ndef combination_sum4(nums, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func combinationSum4(_ nums: [Int], _ target: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func combinationSum4(nums []int, target int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def combinationSum4(nums: Array[Int], target: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun combinationSum4(nums: IntArray, target: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn combination_sum4(nums: Vec, target: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $target\n * @return Integer\n */\n function combinationSum4($nums, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function combinationSum4(nums: number[], target: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (combination-sum4 nums target)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0377](https://leetcode-cn.com/problems/combination-sum-iv)", "[\u7ec4\u5408\u603b\u548c \u2163](/solution/0300-0399/0377.Combination%20Sum%20IV/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0377](https://leetcode.com/problems/combination-sum-iv)", "[Combination Sum IV](/solution/0300-0399/0377.Combination%20Sum%20IV/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0376", "frontend_question_id": "0376", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/wiggle-subsequence", "url_en": "https://leetcode.com/problems/wiggle-subsequence", "relative_path_cn": "/solution/0300-0399/0376.Wiggle%20Subsequence/README.md", "relative_path_en": "/solution/0300-0399/0376.Wiggle%20Subsequence/README_EN.md", "title_cn": "\u6446\u52a8\u5e8f\u5217", "title_en": "Wiggle Subsequence", "question_title_slug": "wiggle-subsequence", "content_en": "

    A wiggle sequence is a sequence where the differences between successive numbers strictly alternate between positive and negative. The first difference (if one exists) may be either positive or negative. A sequence with one element and a sequence with two non-equal elements are trivially wiggle sequences.

    \n\n
      \n\t
    • For example, [1, 7, 4, 9, 2, 5] is a wiggle sequence because the differences (6, -3, 5, -7, 3) alternate between positive and negative.
    • \n\t
    • In contrast, [1, 4, 7, 2, 5] and [1, 7, 4, 5, 5] are not wiggle sequences. The first is not because its first two differences are positive, and the second is not because its last difference is zero.
    • \n
    \n\n

    A subsequence is obtained by deleting some elements (possibly zero) from the original sequence, leaving the remaining elements in their original order.

    \n\n

    Given an integer array nums, return the length of the longest wiggle subsequence of nums.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,7,4,9,2,5]\nOutput: 6\nExplanation: The entire sequence is a wiggle sequence with differences (6, -3, 5, -7, 3).\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,17,5,10,13,15,10,5,16,8]\nOutput: 7\nExplanation: There are several subsequences that achieve this length.\nOne is [1, 17, 10, 13, 10, 16, 8] with differences (16, -7, 3, -3, 6, -8).\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [1,2,3,4,5,6,7,8,9]\nOutput: 2\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 1000
    • \n\t
    • 0 <= nums[i] <= 1000
    • \n
    \n\n

     

    \n

    Follow up: Could you solve this in O(n) time?

    \n", "content_cn": "

    \u5982\u679c\u8fde\u7eed\u6570\u5b57\u4e4b\u95f4\u7684\u5dee\u4e25\u683c\u5730\u5728\u6b63\u6570\u548c\u8d1f\u6570\u4e4b\u95f4\u4ea4\u66ff\uff0c\u5219\u6570\u5b57\u5e8f\u5217\u79f0\u4e3a \u6446\u52a8\u5e8f\u5217 \u3002\u7b2c\u4e00\u4e2a\u5dee\uff08\u5982\u679c\u5b58\u5728\u7684\u8bdd\uff09\u53ef\u80fd\u662f\u6b63\u6570\u6216\u8d1f\u6570\u3002\u4ec5\u6709\u4e00\u4e2a\u5143\u7d20\u6216\u8005\u542b\u4e24\u4e2a\u4e0d\u7b49\u5143\u7d20\u7684\u5e8f\u5217\u4e5f\u89c6\u4f5c\u6446\u52a8\u5e8f\u5217\u3002

    \n\n
      \n\t
    • \n\t

      \u4f8b\u5982\uff0c\u00a0[1, 7, 4, 9, 2, 5] \u662f\u4e00\u4e2a \u6446\u52a8\u5e8f\u5217 \uff0c\u56e0\u4e3a\u5dee\u503c (6, -3, 5, -7, 3)\u00a0\u662f\u6b63\u8d1f\u4ea4\u66ff\u51fa\u73b0\u7684\u3002

      \n\t
    • \n\t
    • \u76f8\u53cd\uff0c[1, 4, 7, 2, 5]\u00a0\u548c\u00a0[1, 7, 4, 5, 5] \u4e0d\u662f\u6446\u52a8\u5e8f\u5217\uff0c\u7b2c\u4e00\u4e2a\u5e8f\u5217\u662f\u56e0\u4e3a\u5b83\u7684\u524d\u4e24\u4e2a\u5dee\u503c\u90fd\u662f\u6b63\u6570\uff0c\u7b2c\u4e8c\u4e2a\u5e8f\u5217\u662f\u56e0\u4e3a\u5b83\u7684\u6700\u540e\u4e00\u4e2a\u5dee\u503c\u4e3a\u96f6\u3002
    • \n
    \n\n

    \u5b50\u5e8f\u5217 \u53ef\u4ee5\u901a\u8fc7\u4ece\u539f\u59cb\u5e8f\u5217\u4e2d\u5220\u9664\u4e00\u4e9b\uff08\u4e5f\u53ef\u4ee5\u4e0d\u5220\u9664\uff09\u5143\u7d20\u6765\u83b7\u5f97\uff0c\u5269\u4e0b\u7684\u5143\u7d20\u4fdd\u6301\u5176\u539f\u59cb\u987a\u5e8f\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \uff0c\u8fd4\u56de nums \u4e2d\u4f5c\u4e3a \u6446\u52a8\u5e8f\u5217 \u7684 \u6700\u957f\u5b50\u5e8f\u5217\u7684\u957f\u5ea6 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,7,4,9,2,5]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u6574\u4e2a\u5e8f\u5217\u5747\u4e3a\u6446\u52a8\u5e8f\u5217\uff0c\u5404\u5143\u7d20\u4e4b\u95f4\u7684\u5dee\u503c\u4e3a (6, -3, 5, -7, 3) \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,17,5,10,13,15,10,5,16,8]\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\u8fd9\u4e2a\u5e8f\u5217\u5305\u542b\u51e0\u4e2a\u957f\u5ea6\u4e3a 7 \u6446\u52a8\u5e8f\u5217\u3002\n\u5176\u4e2d\u4e00\u4e2a\u662f [1, 17, 10, 13, 10, 16, 8] \uff0c\u5404\u5143\u7d20\u4e4b\u95f4\u7684\u5dee\u503c\u4e3a (16, -7, 3, -3, 6, -8) \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,3,4,5,6,7,8,9]\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 1000
    • \n\t
    • 0 <= nums[i] <= 1000
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u80fd\u5426\u7528\u00a0O(n) \u65f6\u95f4\u590d\u6742\u5ea6\u5b8c\u6210\u6b64\u9898?

    \n", "tags_en": ["Greedy", "Dynamic Programming"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int wiggleMaxLength(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int wiggleMaxLength(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def wiggleMaxLength(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def wiggleMaxLength(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint wiggleMaxLength(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int WiggleMaxLength(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar wiggleMaxLength = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef wiggle_max_length(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func wiggleMaxLength(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func wiggleMaxLength(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def wiggleMaxLength(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun wiggleMaxLength(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn wiggle_max_length(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function wiggleMaxLength($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function wiggleMaxLength(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (wiggle-max-length nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0376](https://leetcode-cn.com/problems/wiggle-subsequence)", "[\u6446\u52a8\u5e8f\u5217](/solution/0300-0399/0376.Wiggle%20Subsequence/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0376](https://leetcode.com/problems/wiggle-subsequence)", "[Wiggle Subsequence](/solution/0300-0399/0376.Wiggle%20Subsequence/README_EN.md)", "`Greedy`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0375", "frontend_question_id": "0375", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/guess-number-higher-or-lower-ii", "url_en": "https://leetcode.com/problems/guess-number-higher-or-lower-ii", "relative_path_cn": "/solution/0300-0399/0375.Guess%20Number%20Higher%20or%20Lower%20II/README.md", "relative_path_en": "/solution/0300-0399/0375.Guess%20Number%20Higher%20or%20Lower%20II/README_EN.md", "title_cn": "\u731c\u6570\u5b57\u5927\u5c0f II", "title_en": "Guess Number Higher or Lower II", "question_title_slug": "guess-number-higher-or-lower-ii", "content_en": "

    We are playing the Guessing Game. The game will work as follows:

    \n\n
      \n\t
    1. I pick a number between 1 and n.
    2. \n\t
    3. You guess a number.
    4. \n\t
    5. If you guess the right number, you win the game.
    6. \n\t
    7. If you guess the wrong number, then I will tell you whether the number I picked is higher or lower, and you will continue guessing.
    8. \n\t
    9. Every time you guess a wrong number x, you will pay x dollars. If you run out of money, you lose the game.
    10. \n
    \n\n

    Given a particular n, return the minimum amount of money you need to guarantee a win regardless of what number I pick.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: n = 10\nOutput: 16\nExplanation: The winning strategy is as follows:\n- The range is [1,10]. Guess 7.\n    - If this is my number, your total is $0. Otherwise, you pay $7.\n    - If my number is higher, the range is [8,10]. Guess 9.\n        - If this is my number, your total is $7. Otherwise, you pay $9.\n        - If my number is higher, it must be 10. Guess 10. Your total is $7 + $9 = $16.\n        - If my number is lower, it must be 8. Guess 8. Your total is $7 + $9 = $16.\n    - If my number is lower, the range is [1,6]. Guess 3.\n        - If this is my number, your total is $7. Otherwise, you pay $3.\n        - If my number is higher, the range is [4,6]. Guess 5.\n            - If this is my number, your total is $7 + $3 = $10. Otherwise, you pay $5.\n            - If my number is higher, it must be 6. Guess 6. Your total is $7 + $3 + $5 = $15.\n            - If my number is lower, it must be 4. Guess 4. Your total is $7 + $3 + $5 = $15.\n        - If my number is lower, the range is [1,2]. Guess 1.\n            - If this is my number, your total is $7 + $3 = $10. Otherwise, you pay $1.\n            - If my number is higher, it must be 2. Guess 2. Your total is $7 + $3 + $1 = $11.\nThe worst case in all these scenarios is that you pay $16. Hence, you only need $16 to guarantee a win.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 1\nOutput: 0\nExplanation: There is only one possible number, so you can guess 1 and not have to pay anything.\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 2\nOutput: 1\nExplanation: There are two possible numbers, 1 and 2.\n- Guess 1.\n    - If this is my number, your total is $0. Otherwise, you pay $1.\n    - If my number is higher, it must be 2. Guess 2. Your total is $1.\nThe worst case is that you pay $1.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 200
    • \n
    \n", "content_cn": "

    \u6211\u4eec\u6b63\u5728\u73a9\u4e00\u4e2a\u731c\u6570\u6e38\u620f\uff0c\u6e38\u620f\u89c4\u5219\u5982\u4e0b\uff1a

    \n\n

    \u6211\u4ece \u5230 n \u4e4b\u95f4\u9009\u62e9\u4e00\u4e2a\u6570\u5b57\uff0c\u4f60\u6765\u731c\u6211\u9009\u4e86\u54ea\u4e2a\u6570\u5b57\u3002

    \n\n

    \u6bcf\u6b21\u4f60\u731c\u9519\u4e86\uff0c\u6211\u90fd\u4f1a\u544a\u8bc9\u4f60\uff0c\u6211\u9009\u7684\u6570\u5b57\u6bd4\u4f60\u7684\u5927\u4e86\u6216\u8005\u5c0f\u4e86\u3002

    \n\n

    \u7136\u800c\uff0c\u5f53\u4f60\u731c\u4e86\u6570\u5b57 x \u5e76\u4e14\u731c\u9519\u4e86\u7684\u65f6\u5019\uff0c\u4f60\u9700\u8981\u652f\u4ed8\u91d1\u989d\u4e3a x \u7684\u73b0\u91d1\u3002\u76f4\u5230\u4f60\u731c\u5230\u6211\u9009\u7684\u6570\u5b57\uff0c\u4f60\u624d\u7b97\u8d62\u5f97\u4e86\u8fd9\u4e2a\u6e38\u620f\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    n = 10, \u6211\u9009\u62e9\u4e868.\n\n\u7b2c\u4e00\u8f6e: \u4f60\u731c\u6211\u9009\u62e9\u7684\u6570\u5b57\u662f5\uff0c\u6211\u4f1a\u544a\u8bc9\u4f60\uff0c\u6211\u7684\u6570\u5b57\u66f4\u5927\u4e00\u4e9b\uff0c\u7136\u540e\u4f60\u9700\u8981\u652f\u4ed85\u5757\u3002\n\u7b2c\u4e8c\u8f6e: \u4f60\u731c\u662f7\uff0c\u6211\u544a\u8bc9\u4f60\uff0c\u6211\u7684\u6570\u5b57\u66f4\u5927\u4e00\u4e9b\uff0c\u4f60\u652f\u4ed87\u5757\u3002\n\u7b2c\u4e09\u8f6e: \u4f60\u731c\u662f9\uff0c\u6211\u544a\u8bc9\u4f60\uff0c\u6211\u7684\u6570\u5b57\u66f4\u5c0f\u4e00\u4e9b\uff0c\u4f60\u652f\u4ed89\u5757\u3002\n\n\u6e38\u620f\u7ed3\u675f\u30028 \u5c31\u662f\u6211\u9009\u7684\u6570\u5b57\u3002\n\n\u4f60\u6700\u7ec8\u8981\u652f\u4ed8 5 + 7 + 9 = 21 \u5757\u94b1\u3002\n
    \n\n

    \u7ed9\u5b9a n ≥ 1\uff0c\u8ba1\u7b97\u4f60\u81f3\u5c11\u9700\u8981\u62e5\u6709\u591a\u5c11\u73b0\u91d1\u624d\u80fd\u786e\u4fdd\u4f60\u80fd\u8d62\u5f97\u8fd9\u4e2a\u6e38\u620f\u3002

    \n", "tags_en": ["Minimax", "Dynamic Programming"], "tags_cn": ["\u6781\u5c0f\u5316\u6781\u5927", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int getMoneyAmount(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int getMoneyAmount(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getMoneyAmount(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getMoneyAmount(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint getMoneyAmount(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int GetMoneyAmount(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar getMoneyAmount = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef get_money_amount(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getMoneyAmount(_ n: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getMoneyAmount(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getMoneyAmount(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getMoneyAmount(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_money_amount(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function getMoneyAmount($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getMoneyAmount(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-money-amount n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0375](https://leetcode-cn.com/problems/guess-number-higher-or-lower-ii)", "[\u731c\u6570\u5b57\u5927\u5c0f II](/solution/0300-0399/0375.Guess%20Number%20Higher%20or%20Lower%20II/README.md)", "`\u6781\u5c0f\u5316\u6781\u5927`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0375](https://leetcode.com/problems/guess-number-higher-or-lower-ii)", "[Guess Number Higher or Lower II](/solution/0300-0399/0375.Guess%20Number%20Higher%20or%20Lower%20II/README_EN.md)", "`Minimax`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0374", "frontend_question_id": "0374", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/guess-number-higher-or-lower", "url_en": "https://leetcode.com/problems/guess-number-higher-or-lower", "relative_path_cn": "/solution/0300-0399/0374.Guess%20Number%20Higher%20or%20Lower/README.md", "relative_path_en": "/solution/0300-0399/0374.Guess%20Number%20Higher%20or%20Lower/README_EN.md", "title_cn": "\u731c\u6570\u5b57\u5927\u5c0f", "title_en": "Guess Number Higher or Lower", "question_title_slug": "guess-number-higher-or-lower", "content_en": "

    We are playing the Guess Game. The game is as follows:

    \n\n

    I pick a number from 1 to n. You have to guess which number I picked.

    \n\n

    Every time you guess wrong, I will tell you whether the number I picked is higher or lower than your guess.

    \n\n

    You call a pre-defined API int guess(int num), which returns 3 possible results:

    \n\n
      \n\t
    • -1: The number I picked is lower than your guess (i.e. pick < num).
    • \n\t
    • 1: The number I picked is higher than your guess (i.e. pick > num).
    • \n\t
    • 0: The number I picked is equal to your guess (i.e. pick == num).
    • \n
    \n\n

    Return the number that I picked.

    \n\n

     

    \n

    Example 1:

    \n
    Input: n = 10, pick = 6\nOutput: 6\n

    Example 2:

    \n
    Input: n = 1, pick = 1\nOutput: 1\n

    Example 3:

    \n
    Input: n = 2, pick = 1\nOutput: 1\n

    Example 4:

    \n
    Input: n = 2, pick = 2\nOutput: 2\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 231 - 1
    • \n\t
    • 1 <= pick <= n
    • \n
    \n", "content_cn": "

    \u731c\u6570\u5b57\u6e38\u620f\u7684\u89c4\u5219\u5982\u4e0b\uff1a

    \n\n
      \n\t
    • \u6bcf\u8f6e\u6e38\u620f\uff0c\u6211\u90fd\u4f1a\u4ece\u00a01\u00a0\u5230\u00a0n \u968f\u673a\u9009\u62e9\u4e00\u4e2a\u6570\u5b57\u3002 \u8bf7\u4f60\u731c\u9009\u51fa\u7684\u662f\u54ea\u4e2a\u6570\u5b57\u3002
    • \n\t
    • \u5982\u679c\u4f60\u731c\u9519\u4e86\uff0c\u6211\u4f1a\u544a\u8bc9\u4f60\uff0c\u4f60\u731c\u6d4b\u7684\u6570\u5b57\u6bd4\u6211\u9009\u51fa\u7684\u6570\u5b57\u662f\u5927\u4e86\u8fd8\u662f\u5c0f\u4e86\u3002
    • \n
    \n\n

    \u4f60\u53ef\u4ee5\u901a\u8fc7\u8c03\u7528\u4e00\u4e2a\u9884\u5148\u5b9a\u4e49\u597d\u7684\u63a5\u53e3 int guess(int num) \u6765\u83b7\u53d6\u731c\u6d4b\u7ed3\u679c\uff0c\u8fd4\u56de\u503c\u4e00\u5171\u6709 3 \u79cd\u53ef\u80fd\u7684\u60c5\u51b5\uff08-1\uff0c1\u00a0\u6216 0\uff09\uff1a

    \n\n
      \n\t
    • -1\uff1a\u6211\u9009\u51fa\u7684\u6570\u5b57\u6bd4\u4f60\u731c\u7684\u6570\u5b57\u5c0f pick < num
    • \n\t
    • 1\uff1a\u6211\u9009\u51fa\u7684\u6570\u5b57\u6bd4\u4f60\u731c\u7684\u6570\u5b57\u5927 pick > num
    • \n\t
    • 0\uff1a\u6211\u9009\u51fa\u7684\u6570\u5b57\u548c\u4f60\u731c\u7684\u6570\u5b57\u4e00\u6837\u3002\u606d\u559c\uff01\u4f60\u731c\u5bf9\u4e86\uff01pick == num
    • \n
    \n\n

    \u8fd4\u56de\u6211\u9009\u51fa\u7684\u6570\u5b57\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 10, pick = 6\n\u8f93\u51fa\uff1a6\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 1, pick = 1\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 2, pick = 1\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 2, pick = 2\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 231 - 1
    • \n\t
    • 1 <= pick <= n
    • \n
    \n", "tags_en": ["Binary Search"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/** \n * Forward declaration of guess API.\n * @param num your guess\n * @return \t -1 if num is lower than the guess number\n *\t\t\t 1 if num is higher than the guess number\n * otherwise return 0\n * int guess(int num);\n */\n\nclass Solution {\npublic:\n int guessNumber(int n) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/** \n * Forward declaration of guess API.\n * @param num your guess\n * @return \t -1 if num is lower than the guess number\n *\t\t\t 1 if num is higher than the guess number\n * otherwise return 0\n * int guess(int num);\n */\n\npublic class Solution extends GuessGame {\n public int guessNumber(int n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# The guess API is already defined for you.\n# @param num, your guess\n# @return -1 if my number is lower, 1 if my number is higher, otherwise return 0\n# def guess(num):\n\nclass Solution(object):\n def guessNumber(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# The guess API is already defined for you.\n# @param num, your guess\n# @return -1 if my number is lower, 1 if my number is higher, otherwise return 0\n# def guess(num: int) -> int:\n\nclass Solution:\n def guessNumber(self, n: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/** \n * Forward declaration of guess API.\n * @param num your guess\n * @return \t -1 if num is lower than the guess number\n *\t\t\t 1 if num is higher than the guess number\n * otherwise return 0\n * int guess(int num);\n */\n\nint guessNumber(int n){\n\t\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/** \n * Forward declaration of guess API.\n * @param num your guess\n * @return \t -1 if num is lower than the guess number\n *\t\t\t 1 if num is higher than the guess number\n * otherwise return 0\n * int guess(int num);\n */\n\npublic class Solution : GuessGame {\n public int GuessNumber(int n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/** \n * Forward declaration of guess API.\n * @param {number} num your guess\n * @return \t -1 if num is lower than the guess number\n *\t\t\t 1 if num is higher than the guess number\n * otherwise return 0\n * var guess = function(num) {}\n */\n\n/**\n * @param {number} n\n * @return {number}\n */\nvar guessNumber = function(n) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# The guess API is already defined for you.\n# @param num, your guess\n# @return -1 if my number is lower, 1 if my number is higher, otherwise return 0\n# def guess(num)\n\ndef guessNumber(n)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/** \n * Forward declaration of guess API.\n * @param num -> your guess number\n * @return \t -1 if the picked number is lower than your guess number\n *\t\t\t 1 if the picked number is higher than your guess number\n * otherwise return 0\n * func guess(_ num: Int) -> Int \n */\n\nclass Solution : GuessGame {\n func guessNumber(_ n: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/** \n * Forward declaration of guess API.\n * @param num your guess\n * @return \t -1 if num is lower than the guess number\n *\t\t\t 1 if num is higher than the guess number\n * otherwise return 0\n * func guess(num int) int;\n */\n\nfunc guessNumber(n int) int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/** \n * The API guess is defined in the parent class.\n * @param num your guess\n * @return \t -1 if num is lower than the guess number\n *\t\t\t 1 if num is higher than the guess number\n * otherwise return 0\n * def guess(num: Int): Int = {}\n */\n\nclass Solution extends GuessGame {\n def guessNumber(n: Int): Int = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/** \n * The API guess is defined in the parent class.\n * @param num your guess\n * @return \t -1 if num is lower than the guess number\n *\t\t\t 1 if num is higher than the guess number\n * otherwise return 0\n * fun guess(num:Int):Int {}\n */\n\nclass Solution:GuessGame() {\n override fun guessNumber(n:Int):Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "/** \n * Forward declaration of guess API.\n * @param num your guess\n * @return \t -1 if num is lower than the guess number\n *\t\t\t 1 if num is higher than the guess number\n * otherwise return 0\n * unsafe fn guess(num: i32) -> i32 {}\n */\n\nimpl Solution {\n unsafe fn guessNumber(n: i32) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/** \n * The API guess is defined in the parent class.\n * @param num your guess\n * @return \t -1 if num is lower than the guess number\n *\t\t\t 1 if num is higher than the guess number\n * otherwise return 0\n * public function guess($num){}\n */\n\nclass Solution extends GuessGame {\n /**\n * @param Integer $n\n * @return Integer\n */\n function guessNumber($n) {\n \n }\n}", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0374](https://leetcode-cn.com/problems/guess-number-higher-or-lower)", "[\u731c\u6570\u5b57\u5927\u5c0f](/solution/0300-0399/0374.Guess%20Number%20Higher%20or%20Lower/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u7b80\u5355", ""], "md_table_row_en": ["[0374](https://leetcode.com/problems/guess-number-higher-or-lower)", "[Guess Number Higher or Lower](/solution/0300-0399/0374.Guess%20Number%20Higher%20or%20Lower/README_EN.md)", "`Binary Search`", "Easy", ""]}, {"question_id": "0373", "frontend_question_id": "0373", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-k-pairs-with-smallest-sums", "url_en": "https://leetcode.com/problems/find-k-pairs-with-smallest-sums", "relative_path_cn": "/solution/0300-0399/0373.Find%20K%20Pairs%20with%20Smallest%20Sums/README.md", "relative_path_en": "/solution/0300-0399/0373.Find%20K%20Pairs%20with%20Smallest%20Sums/README_EN.md", "title_cn": "\u67e5\u627e\u548c\u6700\u5c0f\u7684K\u5bf9\u6570\u5b57", "title_en": "Find K Pairs with Smallest Sums", "question_title_slug": "find-k-pairs-with-smallest-sums", "content_en": "

    You are given two integer arrays nums1 and nums2 sorted in ascending order and an integer k.

    \n\n

    Define a pair (u, v) which consists of one element from the first array and one element from the second array.

    \n\n

    Return the k pairs (u1, v1), (u2, v2), ..., (uk, vk) with the smallest sums.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums1 = [1,7,11], nums2 = [2,4,6], k = 3\nOutput: [[1,2],[1,4],[1,6]]\nExplanation: The first 3 pairs are returned from the sequence: [1,2],[1,4],[1,6],[7,2],[7,4],[11,2],[7,6],[11,4],[11,6]\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums1 = [1,1,2], nums2 = [1,2,3], k = 2\nOutput: [[1,1],[1,1]]\nExplanation: The first 2 pairs are returned from the sequence: [1,1],[1,1],[1,2],[2,1],[1,2],[2,2],[1,3],[1,3],[2,3]\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums1 = [1,2], nums2 = [3], k = 3\nOutput: [[1,3],[2,3]]\nExplanation: All possible pairs are returned from the sequence: [1,3],[2,3]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums1.length, nums2.length <= 104
    • \n\t
    • -109 <= nums1[i], nums2[i] <= 109
    • \n\t
    • nums1 and nums2 both are sorted in ascending order.
    • \n\t
    • 1 <= k <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u4ee5\u5347\u5e8f\u6392\u5217\u7684\u6574\u5f62\u6570\u7ec4 nums1 \u548c nums2, \u4ee5\u53ca\u4e00\u4e2a\u6574\u6570 k\u3002

    \n\n

    \u5b9a\u4e49\u4e00\u5bf9\u503c (u,v)\uff0c\u5176\u4e2d\u7b2c\u4e00\u4e2a\u5143\u7d20\u6765\u81ea nums1\uff0c\u7b2c\u4e8c\u4e2a\u5143\u7d20\u6765\u81ea nums2\u3002

    \n\n

    \u627e\u5230\u548c\u6700\u5c0f\u7684 k \u5bf9\u6570\u5b57 (u1,v1), (u2,v2) ... (uk,vk)\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: nums1 = [1,7,11], nums2 = [2,4,6], k = 3\n\u8f93\u51fa: [1,2],[1,4],[1,6]\n\u89e3\u91ca: \u8fd4\u56de\u5e8f\u5217\u4e2d\u7684\u524d 3 \u5bf9\u6570\uff1a\n     [1,2],[1,4],[1,6],[7,2],[7,4],[11,2],[7,6],[11,4],[11,6]\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: nums1 = [1,1,2], nums2 = [1,2,3], k = 2\n\u8f93\u51fa: [1,1],[1,1]\n\u89e3\u91ca: \u8fd4\u56de\u5e8f\u5217\u4e2d\u7684\u524d 2 \u5bf9\u6570\uff1a\n     [1,1],[1,1],[1,2],[2,1],[1,2],[2,2],[1,3],[1,3],[2,3]\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u8f93\u5165: nums1 = [1,2], nums2 = [3], k = 3 \n\u8f93\u51fa: [1,3],[2,3]\n\u89e3\u91ca: \u4e5f\u53ef\u80fd\u5e8f\u5217\u4e2d\u6240\u6709\u7684\u6570\u5bf9\u90fd\u88ab\u8fd4\u56de:[1,3],[2,3]\n
    \n", "tags_en": ["Heap"], "tags_cn": ["\u5806"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> kSmallestPairs(vector& nums1, vector& nums2, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> kSmallestPairs(int[] nums1, int[] nums2, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def kSmallestPairs(self, nums1, nums2, k):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n :type k: int\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def kSmallestPairs(self, nums1: List[int], nums2: List[int], k: int) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** kSmallestPairs(int* nums1, int nums1Size, int* nums2, int nums2Size, int k, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> KSmallestPairs(int[] nums1, int[] nums2, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums1\n * @param {number[]} nums2\n * @param {number} k\n * @return {number[][]}\n */\nvar kSmallestPairs = function(nums1, nums2, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums1\n# @param {Integer[]} nums2\n# @param {Integer} k\n# @return {Integer[][]}\ndef k_smallest_pairs(nums1, nums2, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func kSmallestPairs(_ nums1: [Int], _ nums2: [Int], _ k: Int) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func kSmallestPairs(nums1 []int, nums2 []int, k int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def kSmallestPairs(nums1: Array[Int], nums2: Array[Int], k: Int): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun kSmallestPairs(nums1: IntArray, nums2: IntArray, k: Int): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn k_smallest_pairs(nums1: Vec, nums2: Vec, k: i32) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums1\n * @param Integer[] $nums2\n * @param Integer $k\n * @return Integer[][]\n */\n function kSmallestPairs($nums1, $nums2, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function kSmallestPairs(nums1: number[], nums2: number[], k: number): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (k-smallest-pairs nums1 nums2 k)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer? (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0373](https://leetcode-cn.com/problems/find-k-pairs-with-smallest-sums)", "[\u67e5\u627e\u548c\u6700\u5c0f\u7684K\u5bf9\u6570\u5b57](/solution/0300-0399/0373.Find%20K%20Pairs%20with%20Smallest%20Sums/README.md)", "`\u5806`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0373](https://leetcode.com/problems/find-k-pairs-with-smallest-sums)", "[Find K Pairs with Smallest Sums](/solution/0300-0399/0373.Find%20K%20Pairs%20with%20Smallest%20Sums/README_EN.md)", "`Heap`", "Medium", ""]}, {"question_id": "0372", "frontend_question_id": "0372", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/super-pow", "url_en": "https://leetcode.com/problems/super-pow", "relative_path_cn": "/solution/0300-0399/0372.Super%20Pow/README.md", "relative_path_en": "/solution/0300-0399/0372.Super%20Pow/README_EN.md", "title_cn": "\u8d85\u7ea7\u6b21\u65b9", "title_en": "Super Pow", "question_title_slug": "super-pow", "content_en": "

    Your task is to calculate ab mod 1337 where a is a positive integer and b is an extremely large positive integer given in the form of an array.

    \n\n

     

    \n

    Example 1:

    \n
    Input: a = 2, b = [3]\nOutput: 8\n

    Example 2:

    \n
    Input: a = 2, b = [1,0]\nOutput: 1024\n

    Example 3:

    \n
    Input: a = 1, b = [4,3,3,8,5,2]\nOutput: 1\n

    Example 4:

    \n
    Input: a = 2147483647, b = [2,0,0]\nOutput: 1198\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= a <= 231 - 1
    • \n\t
    • 1 <= b.length <= 2000
    • \n\t
    • 0 <= b[i] <= 9
    • \n\t
    • b doesn't contain leading zeros.
    • \n
    \n", "content_cn": "

    \u4f60\u7684\u4efb\u52a1\u662f\u8ba1\u7b97\u00a0ab\u00a0\u5bf9\u00a01337 \u53d6\u6a21\uff0ca \u662f\u4e00\u4e2a\u6b63\u6574\u6570\uff0cb \u662f\u4e00\u4e2a\u975e\u5e38\u5927\u7684\u6b63\u6574\u6570\u4e14\u4f1a\u4ee5\u6570\u7ec4\u5f62\u5f0f\u7ed9\u51fa\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aa = 2, b = [3]\n\u8f93\u51fa\uff1a8\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aa = 2, b = [1,0]\n\u8f93\u51fa\uff1a1024\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aa = 1, b = [4,3,3,8,5,2]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1aa = 2147483647, b = [2,0,0]\n\u8f93\u51fa\uff1a1198\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= a <= 231 - 1
    • \n\t
    • 1 <= b.length <= 2000
    • \n\t
    • 0 <= b[i] <= 9
    • \n\t
    • b \u4e0d\u542b\u524d\u5bfc 0
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int superPow(int a, vector& b) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int superPow(int a, int[] b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def superPow(self, a, b):\n \"\"\"\n :type a: int\n :type b: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def superPow(self, a: int, b: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint superPow(int a, int* b, int bSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SuperPow(int a, int[] b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} a\n * @param {number[]} b\n * @return {number}\n */\nvar superPow = function(a, b) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} a\n# @param {Integer[]} b\n# @return {Integer}\ndef super_pow(a, b)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func superPow(_ a: Int, _ b: [Int]) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func superPow(a int, b []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def superPow(a: Int, b: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun superPow(a: Int, b: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn super_pow(a: i32, b: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $a\n * @param Integer[] $b\n * @return Integer\n */\n function superPow($a, $b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function superPow(a: number, b: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (super-pow a b)\n (-> exact-integer? (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0372](https://leetcode-cn.com/problems/super-pow)", "[\u8d85\u7ea7\u6b21\u65b9](/solution/0300-0399/0372.Super%20Pow/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0372](https://leetcode.com/problems/super-pow)", "[Super Pow](/solution/0300-0399/0372.Super%20Pow/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "0371", "frontend_question_id": "0371", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sum-of-two-integers", "url_en": "https://leetcode.com/problems/sum-of-two-integers", "relative_path_cn": "/solution/0300-0399/0371.Sum%20of%20Two%20Integers/README.md", "relative_path_en": "/solution/0300-0399/0371.Sum%20of%20Two%20Integers/README_EN.md", "title_cn": "\u4e24\u6574\u6570\u4e4b\u548c", "title_en": "Sum of Two Integers", "question_title_slug": "sum-of-two-integers", "content_en": "

    Given two integers a and b, return the sum of the two integers without using the operators + and -.

    \n\n

     

    \n

    Example 1:

    \n
    Input: a = 1, b = 2\nOutput: 3\n

    Example 2:

    \n
    Input: a = 2, b = 3\nOutput: 5\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • -1000 <= a, b <= 1000
    • \n
    \n", "content_cn": "

    \u4e0d\u4f7f\u7528\u8fd0\u7b97\u7b26 + \u548c - \u200b\u200b\u200b\u200b\u200b\u200b\u200b\uff0c\u8ba1\u7b97\u4e24\u6574\u6570 \u200b\u200b\u200b\u200b\u200b\u200b\u200ba \u3001b \u200b\u200b\u200b\u200b\u200b\u200b\u200b\u4e4b\u548c\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: a = 1, b = 2\n\u8f93\u51fa: 3\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: a = -2, b = 3\n\u8f93\u51fa: 1
    \n", "tags_en": ["Bit Manipulation"], "tags_cn": ["\u4f4d\u8fd0\u7b97"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int getSum(int a, int b) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int getSum(int a, int b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getSum(self, a, b):\n \"\"\"\n :type a: int\n :type b: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getSum(self, a: int, b: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint getSum(int a, int b){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int GetSum(int a, int b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} a\n * @param {number} b\n * @return {number}\n */\nvar getSum = function(a, b) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} a\n# @param {Integer} b\n# @return {Integer}\ndef get_sum(a, b)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getSum(_ a: Int, _ b: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getSum(a int, b int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getSum(a: Int, b: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getSum(a: Int, b: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_sum(a: i32, b: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $a\n * @param Integer $b\n * @return Integer\n */\n function getSum($a, $b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getSum(a: number, b: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-sum a b)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0371](https://leetcode-cn.com/problems/sum-of-two-integers)", "[\u4e24\u6574\u6570\u4e4b\u548c](/solution/0300-0399/0371.Sum%20of%20Two%20Integers/README.md)", "`\u4f4d\u8fd0\u7b97`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0371](https://leetcode.com/problems/sum-of-two-integers)", "[Sum of Two Integers](/solution/0300-0399/0371.Sum%20of%20Two%20Integers/README_EN.md)", "`Bit Manipulation`", "Medium", ""]}, {"question_id": "0370", "frontend_question_id": "0370", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/range-addition", "url_en": "https://leetcode.com/problems/range-addition", "relative_path_cn": "/solution/0300-0399/0370.Range%20Addition/README.md", "relative_path_en": "/solution/0300-0399/0370.Range%20Addition/README_EN.md", "title_cn": "\u533a\u95f4\u52a0\u6cd5", "title_en": "Range Addition", "question_title_slug": "range-addition", "content_en": "

    You are given an integer length and an array updates where updates[i] = [startIdxi, endIdxi, inci].

    \n\n

    You have an array arr of length length with all zeros, and you have some operation to apply on arr. In the ith operation, you should increment all the elements arr[startIdxi], arr[startIdxi + 1], ..., arr[endIdxi] by inci.

    \n\n

    Return arr after applying all the updates.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: length = 5, updates = [[1,3,2],[2,4,3],[0,2,-2]]\nOutput: [-2,0,3,5,3]\n
    \n\n

    Example 2:

    \n\n
    \nInput: length = 10, updates = [[2,4,6],[5,6,8],[1,9,-4]]\nOutput: [0,-4,2,2,2,4,4,-4,-4,-4]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= length <= 105
    • \n\t
    • 0 <= updates.length <= 104
    • \n\t
    • 0 <= startIdxi <= endIdxi < length
    • \n\t
    • -1000 <= inci <= 1000
    • \n
    \n", "content_cn": "

    \u5047\u8bbe\u4f60\u6709\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u6570\u7ec4\uff0c\u521d\u59cb\u60c5\u51b5\u4e0b\u6240\u6709\u7684\u6570\u5b57\u5747\u4e3a 0\uff0c\u4f60\u5c06\u4f1a\u88ab\u7ed9\u51fa k\u200b\u200b\u200b\u200b\u200b\u200b\u200b \u4e2a\u66f4\u65b0\u7684\u64cd\u4f5c\u3002

    \n\n

    \u5176\u4e2d\uff0c\u6bcf\u4e2a\u64cd\u4f5c\u4f1a\u88ab\u8868\u793a\u4e3a\u4e00\u4e2a\u4e09\u5143\u7ec4\uff1a[startIndex, endIndex, inc]\uff0c\u4f60\u9700\u8981\u5c06\u5b50\u6570\u7ec4 A[startIndex ... endIndex]\uff08\u5305\u62ec startIndex \u548c endIndex\uff09\u589e\u52a0 inc\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de k \u6b21\u64cd\u4f5c\u540e\u7684\u6570\u7ec4\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: length = 5, updates = [[1,3,2],[2,4,3],[0,2,-2]]\n\u8f93\u51fa: [-2,0,3,5,3]\n
    \n\n

    \u89e3\u91ca:

    \n\n
    \u521d\u59cb\u72b6\u6001:\n[0,0,0,0,0]\n\n\u8fdb\u884c\u4e86\u64cd\u4f5c [1,3,2] \u540e\u7684\u72b6\u6001:\n[0,2,2,2,0]\n\n\u8fdb\u884c\u4e86\u64cd\u4f5c [2,4,3] \u540e\u7684\u72b6\u6001:\n[0,2,5,5,3]\n\n\u8fdb\u884c\u4e86\u64cd\u4f5c [0,2,-2] \u540e\u7684\u72b6\u6001:\n[-2,0,3,5,3]\n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector getModifiedArray(int length, vector>& updates) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] getModifiedArray(int length, int[][] updates) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getModifiedArray(self, length, updates):\n \"\"\"\n :type length: int\n :type updates: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getModifiedArray(self, length: int, updates: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* getModifiedArray(int length, int** updates, int updatesSize, int* updatesColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] GetModifiedArray(int length, int[][] updates) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} length\n * @param {number[][]} updates\n * @return {number[]}\n */\nvar getModifiedArray = function(length, updates) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} length\n# @param {Integer[][]} updates\n# @return {Integer[]}\ndef get_modified_array(length, updates)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getModifiedArray(_ length: Int, _ updates: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getModifiedArray(length int, updates [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getModifiedArray(length: Int, updates: Array[Array[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getModifiedArray(length: Int, updates: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_modified_array(length: i32, updates: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $length\n * @param Integer[][] $updates\n * @return Integer[]\n */\n function getModifiedArray($length, $updates) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getModifiedArray(length: number, updates: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-modified-array length updates)\n (-> exact-integer? (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0370](https://leetcode-cn.com/problems/range-addition)", "[\u533a\u95f4\u52a0\u6cd5](/solution/0300-0399/0370.Range%20Addition/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0370](https://leetcode.com/problems/range-addition)", "[Range Addition](/solution/0300-0399/0370.Range%20Addition/README_EN.md)", "`Array`", "Medium", "\ud83d\udd12"]}, {"question_id": "0369", "frontend_question_id": "0369", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/plus-one-linked-list", "url_en": "https://leetcode.com/problems/plus-one-linked-list", "relative_path_cn": "/solution/0300-0399/0369.Plus%20One%20Linked%20List/README.md", "relative_path_en": "/solution/0300-0399/0369.Plus%20One%20Linked%20List/README_EN.md", "title_cn": "\u7ed9\u5355\u94fe\u8868\u52a0\u4e00", "title_en": "Plus One Linked List", "question_title_slug": "plus-one-linked-list", "content_en": "

    Given a non-negative integer represented as a linked list of digits, plus one to the integer.

    \n\n

    The digits are stored such that the most significant digit is at the head of the list.

    \n\n

     

    \n

    Example 1:

    \n
    Input: head = [1,2,3]\nOutput: [1,2,4]\n

    Example 2:

    \n
    Input: head = [0]\nOutput: [1]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the linked list is in the range [1, 100].
    • \n\t
    • 0 <= Node.val <= 9
    • \n\t
    • The number represented by the linked list does not contain leading zeros except for the zero itself. 
    • \n
    \n", "content_cn": "

    \u7528\u4e00\u4e2a \u975e\u7a7a \u5355\u94fe\u8868\u6765\u8868\u793a\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\uff0c\u7136\u540e\u5c06\u8fd9\u4e2a\u6574\u6570\u52a0\u4e00\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u5047\u8bbe\u8fd9\u4e2a\u6574\u6570\u9664\u4e86 0 \u672c\u8eab\uff0c\u6ca1\u6709\u4efb\u4f55\u524d\u5bfc\u7684 0\u3002

    \n\n

    \u8fd9\u4e2a\u6574\u6570\u7684\u5404\u4e2a\u6570\u4f4d\u6309\u7167 \u9ad8\u4f4d\u5728\u94fe\u8868\u5934\u90e8\u3001\u4f4e\u4f4d\u5728\u94fe\u8868\u5c3e\u90e8 \u7684\u987a\u5e8f\u6392\u5217\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: [1,2,3]\n\u8f93\u51fa: [1,2,4]\n
    \n", "tags_en": ["Recursion", "Linked List"], "tags_cn": ["\u9012\u5f52", "\u94fe\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n ListNode* plusOne(ListNode* head) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public ListNode plusOne(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def plusOne(self, head):\n \"\"\"\n :type head: ListNode\n :rtype: ListNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def plusOne(self, head: ListNode) -> ListNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nstruct ListNode* plusOne(struct ListNode* head){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public ListNode PlusOne(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} head\n * @return {ListNode}\n */\nvar plusOne = function(head) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode} head\n# @return {ListNode}\ndef plus_one(head)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func plusOne(_ head: ListNode?) -> ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc plusOne(head *ListNode) *ListNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def plusOne(head: ListNode): ListNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun plusOne(head: ListNode?): ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn plus_one(head: Option>) -> Option> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @return ListNode\n */\n function plusOne($head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction plusOne(head: ListNode | null): ListNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (plus-one head)\n (-> (or/c list-node? #f) (or/c list-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0369](https://leetcode-cn.com/problems/plus-one-linked-list)", "[\u7ed9\u5355\u94fe\u8868\u52a0\u4e00](/solution/0300-0399/0369.Plus%20One%20Linked%20List/README.md)", "`\u9012\u5f52`,`\u94fe\u8868`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0369](https://leetcode.com/problems/plus-one-linked-list)", "[Plus One Linked List](/solution/0300-0399/0369.Plus%20One%20Linked%20List/README_EN.md)", "`Recursion`,`Linked List`", "Medium", "\ud83d\udd12"]}, {"question_id": "0368", "frontend_question_id": "0368", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/largest-divisible-subset", "url_en": "https://leetcode.com/problems/largest-divisible-subset", "relative_path_cn": "/solution/0300-0399/0368.Largest%20Divisible%20Subset/README.md", "relative_path_en": "/solution/0300-0399/0368.Largest%20Divisible%20Subset/README_EN.md", "title_cn": "\u6700\u5927\u6574\u9664\u5b50\u96c6", "title_en": "Largest Divisible Subset", "question_title_slug": "largest-divisible-subset", "content_en": "

    Given a set of distinct positive integers nums, return the largest subset answer such that every pair (answer[i], answer[j]) of elements in this subset satisfies:

    \n\n
      \n\t
    • answer[i] % answer[j] == 0, or
    • \n\t
    • answer[j] % answer[i] == 0
    • \n
    \n\n

    If there are multiple solutions, return any of them.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,3]\nOutput: [1,2]\nExplanation: [1,3] is also accepted.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,2,4,8]\nOutput: [1,2,4,8]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 1000
    • \n\t
    • 1 <= nums[i] <= 2 * 109
    • \n\t
    • All the integers in nums are unique.
    • \n
    \n", "content_cn": "\u7ed9\u4f60\u4e00\u4e2a\u7531 \u65e0\u91cd\u590d \u6b63\u6574\u6570\u7ec4\u6210\u7684\u96c6\u5408 nums \uff0c\u8bf7\u4f60\u627e\u51fa\u5e76\u8fd4\u56de\u5176\u4e2d\u6700\u5927\u7684\u6574\u9664\u5b50\u96c6 answer \uff0c\u5b50\u96c6\u4e2d\u6bcf\u4e00\u5143\u7d20\u5bf9 (answer[i], answer[j]) \u90fd\u5e94\u5f53\u6ee1\u8db3\uff1a\n
      \n\t
    • answer[i] % answer[j] == 0 \uff0c\u6216
    • \n\t
    • answer[j] % answer[i] == 0
    • \n
    \n\n

    \u5982\u679c\u5b58\u5728\u591a\u4e2a\u6709\u6548\u89e3\u5b50\u96c6\uff0c\u8fd4\u56de\u5176\u4e2d\u4efb\u4f55\u4e00\u4e2a\u5747\u53ef\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,3]\n\u8f93\u51fa\uff1a[1,2]\n\u89e3\u91ca\uff1a[1,3] \u4e5f\u4f1a\u88ab\u89c6\u4e3a\u6b63\u786e\u7b54\u6848\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,4,8]\n\u8f93\u51fa\uff1a[1,2,4,8]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 1000
    • \n\t
    • 1 <= nums[i] <= 2 * 109
    • \n\t
    • nums \u4e2d\u7684\u6240\u6709\u6574\u6570 \u4e92\u4e0d\u76f8\u540c
    • \n
    \n", "tags_en": ["Math", "Dynamic Programming"], "tags_cn": ["\u6570\u5b66", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector largestDivisibleSubset(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List largestDivisibleSubset(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def largestDivisibleSubset(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def largestDivisibleSubset(self, nums: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* largestDivisibleSubset(int* nums, int numsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList LargestDivisibleSubset(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar largestDivisibleSubset = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer[]}\ndef largest_divisible_subset(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func largestDivisibleSubset(_ nums: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func largestDivisibleSubset(nums []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def largestDivisibleSubset(nums: Array[Int]): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun largestDivisibleSubset(nums: IntArray): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn largest_divisible_subset(nums: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer[]\n */\n function largestDivisibleSubset($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function largestDivisibleSubset(nums: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (largest-divisible-subset nums)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0368](https://leetcode-cn.com/problems/largest-divisible-subset)", "[\u6700\u5927\u6574\u9664\u5b50\u96c6](/solution/0300-0399/0368.Largest%20Divisible%20Subset/README.md)", "`\u6570\u5b66`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0368](https://leetcode.com/problems/largest-divisible-subset)", "[Largest Divisible Subset](/solution/0300-0399/0368.Largest%20Divisible%20Subset/README_EN.md)", "`Math`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0367", "frontend_question_id": "0367", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/valid-perfect-square", "url_en": "https://leetcode.com/problems/valid-perfect-square", "relative_path_cn": "/solution/0300-0399/0367.Valid%20Perfect%20Square/README.md", "relative_path_en": "/solution/0300-0399/0367.Valid%20Perfect%20Square/README_EN.md", "title_cn": "\u6709\u6548\u7684\u5b8c\u5168\u5e73\u65b9\u6570", "title_en": "Valid Perfect Square", "question_title_slug": "valid-perfect-square", "content_en": "

    Given a positive integer num, write a function which returns True if num is a perfect square else False.

    \n\n

    Follow up: Do not use any built-in library function such as sqrt.

    \n\n

     

    \n

    Example 1:

    \n
    Input: num = 16\nOutput: true\n

    Example 2:

    \n
    Input: num = 14\nOutput: false\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= num <= 2^31 - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a \u6b63\u6574\u6570 num \uff0c\u7f16\u5199\u4e00\u4e2a\u51fd\u6570\uff0c\u5982\u679c num \u662f\u4e00\u4e2a\u5b8c\u5168\u5e73\u65b9\u6570\uff0c\u5219\u8fd4\u56de true \uff0c\u5426\u5219\u8fd4\u56de false \u3002

    \n\n

    \u8fdb\u9636\uff1a\u4e0d\u8981 \u4f7f\u7528\u4efb\u4f55\u5185\u7f6e\u7684\u5e93\u51fd\u6570\uff0c\u5982\u00a0 sqrt \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anum = 16\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anum = 14\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= num <= 2^31 - 1
    • \n
    \n", "tags_en": ["Math", "Binary Search"], "tags_cn": ["\u6570\u5b66", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isPerfectSquare(int num) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isPerfectSquare(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isPerfectSquare(self, num):\n \"\"\"\n :type num: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isPerfectSquare(self, num: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isPerfectSquare(int num){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsPerfectSquare(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} num\n * @return {boolean}\n */\nvar isPerfectSquare = function(num) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} num\n# @return {Boolean}\ndef is_perfect_square(num)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isPerfectSquare(_ num: Int) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isPerfectSquare(num int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isPerfectSquare(num: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isPerfectSquare(num: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_perfect_square(num: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $num\n * @return Boolean\n */\n function isPerfectSquare($num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isPerfectSquare(num: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-perfect-square num)\n (-> exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0367](https://leetcode-cn.com/problems/valid-perfect-square)", "[\u6709\u6548\u7684\u5b8c\u5168\u5e73\u65b9\u6570](/solution/0300-0399/0367.Valid%20Perfect%20Square/README.md)", "`\u6570\u5b66`,`\u4e8c\u5206\u67e5\u627e`", "\u7b80\u5355", ""], "md_table_row_en": ["[0367](https://leetcode.com/problems/valid-perfect-square)", "[Valid Perfect Square](/solution/0300-0399/0367.Valid%20Perfect%20Square/README_EN.md)", "`Math`,`Binary Search`", "Easy", ""]}, {"question_id": "0366", "frontend_question_id": "0366", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/find-leaves-of-binary-tree", "url_en": "https://leetcode.com/problems/find-leaves-of-binary-tree", "relative_path_cn": "/solution/0300-0399/0366.Find%20Leaves%20of%20Binary%20Tree/README.md", "relative_path_en": "/solution/0300-0399/0366.Find%20Leaves%20of%20Binary%20Tree/README_EN.md", "title_cn": "\u5bfb\u627e\u4e8c\u53c9\u6811\u7684\u53f6\u5b50\u8282\u70b9", "title_en": "Find Leaves of Binary Tree", "question_title_slug": "find-leaves-of-binary-tree", "content_en": "

    Given the root of a binary tree, collect a tree's nodes as if you were doing this:

    \n\n
      \n\t
    • Collect all the leaf nodes.
    • \n\t
    • Remove all the leaf nodes.
    • \n\t
    • Repeat until the tree is empty.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,2,3,4,5]\nOutput: [[4,5,3],[2],[1]]\nExplanation:\n[[3,5,4],[2],[1]] and [[3,4,5],[2],[1]] are also considered correct answers since per each level it does not matter the order on which elements are returned.\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = [1]\nOutput: [[1]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 100].
    • \n\t
    • -100 <= Node.val <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u68f5\u4e8c\u53c9\u6811\uff0c\u8bf7\u6309\u4ee5\u4e0b\u8981\u6c42\u7684\u987a\u5e8f\u6536\u96c6\u5b83\u7684\u5168\u90e8\u8282\u70b9\uff1a

    \n\n
      \n\t
    1. \u4f9d\u6b21\u4ece\u5de6\u5230\u53f3\uff0c\u6bcf\u6b21\u6536\u96c6\u5e76\u5220\u9664\u6240\u6709\u7684\u53f6\u5b50\u8282\u70b9
    2. \n\t
    3. \u91cd\u590d\u5982\u4e0a\u8fc7\u7a0b\u76f4\u5230\u6574\u68f5\u6811\u4e3a\u7a7a
    4. \n
    \n\n

     

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: [1,2,3,4,5]\n  \n          1\n         / \\\n        2   3\n       / \\     \n      4   5    \n\n\u8f93\u51fa: [[4,5,3],[2],[1]]\n
    \n\n

     

    \n\n

    \u89e3\u91ca:

    \n\n

    1. \u5220\u9664\u53f6\u5b50\u8282\u70b9 [4,5,3] \uff0c\u5f97\u5230\u5982\u4e0b\u6811\u7ed3\u6784\uff1a

    \n\n
              1\n         / \n        2          \n
    \n\n

     

    \n\n

    2. \u73b0\u5728\u5220\u53bb\u53f6\u5b50\u8282\u70b9 [2] \uff0c\u5f97\u5230\u5982\u4e0b\u6811\u7ed3\u6784\uff1a

    \n\n
              1          \n
    \n\n

     

    \n\n

    3. \u73b0\u5728\u5220\u53bb\u53f6\u5b50\u8282\u70b9 [1] \uff0c\u5f97\u5230\u7a7a\u6811\uff1a

    \n\n
              []         \n
    \n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector> findLeaves(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public List> findLeaves(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def findLeaves(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def findLeaves(self, root: TreeNode) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** findLeaves(struct TreeNode* root, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public IList> FindLeaves(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number[][]}\n */\nvar findLeaves = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer[][]}\ndef find_leaves(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func findLeaves(_ root: TreeNode?) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc findLeaves(root *TreeNode) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def findLeaves(root: TreeNode): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun findLeaves(root: TreeNode?): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn find_leaves(root: Option>>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer[][]\n */\n function findLeaves($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction findLeaves(root: TreeNode | null): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (find-leaves root)\n (-> (or/c tree-node? #f) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0366](https://leetcode-cn.com/problems/find-leaves-of-binary-tree)", "[\u5bfb\u627e\u4e8c\u53c9\u6811\u7684\u53f6\u5b50\u8282\u70b9](/solution/0300-0399/0366.Find%20Leaves%20of%20Binary%20Tree/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0366](https://leetcode.com/problems/find-leaves-of-binary-tree)", "[Find Leaves of Binary Tree](/solution/0300-0399/0366.Find%20Leaves%20of%20Binary%20Tree/README_EN.md)", "`Tree`,`Depth-first Search`", "Medium", "\ud83d\udd12"]}, {"question_id": "0365", "frontend_question_id": "0365", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/water-and-jug-problem", "url_en": "https://leetcode.com/problems/water-and-jug-problem", "relative_path_cn": "/solution/0300-0399/0365.Water%20and%20Jug%20Problem/README.md", "relative_path_en": "/solution/0300-0399/0365.Water%20and%20Jug%20Problem/README_EN.md", "title_cn": "\u6c34\u58f6\u95ee\u9898", "title_en": "Water and Jug Problem", "question_title_slug": "water-and-jug-problem", "content_en": "

    You are given two jugs with capacities jug1Capacity and jug2Capacity liters. There is an infinite amount of water supply available. Determine whether it is possible to measure exactly targetCapacity liters using these two jugs.

    \n\n

    If targetCapacity liters of water are measurable, you must have targetCapacity liters of water contained within one or both buckets by the end.

    \n\n

    Operations allowed:

    \n\n
      \n\t
    • Fill any of the jugs with water.
    • \n\t
    • Empty any of the jugs.
    • \n\t
    • Pour water from one jug into another till the other jug is completely full, or the first jug itself is empty.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: jug1Capacity = 3, jug2Capacity = 5, targetCapacity = 4\nOutput: true\nExplanation: The famous Die Hard example \n
    \n\n

    Example 2:

    \n\n
    \nInput: jug1Capacity = 2, jug2Capacity = 6, targetCapacity = 5\nOutput: false\n
    \n\n

    Example 3:

    \n\n
    \nInput: jug1Capacity = 1, jug2Capacity = 2, targetCapacity = 3\nOutput: true\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= jug1Capacity, jug2Capacity, targetCapacity <= 106
    • \n
    \n", "content_cn": "

    \u6709\u4e24\u4e2a\u5bb9\u91cf\u5206\u522b\u4e3a x\u5347 \u548c y\u5347 \u7684\u6c34\u58f6\u4ee5\u53ca\u65e0\u9650\u591a\u7684\u6c34\u3002\u8bf7\u5224\u65ad\u80fd\u5426\u901a\u8fc7\u4f7f\u7528\u8fd9\u4e24\u4e2a\u6c34\u58f6\uff0c\u4ece\u800c\u53ef\u4ee5\u5f97\u5230\u6070\u597d z\u5347 \u7684\u6c34\uff1f

    \n\n

    \u5982\u679c\u53ef\u4ee5\uff0c\u6700\u540e\u8bf7\u7528\u4ee5\u4e0a\u6c34\u58f6\u4e2d\u7684\u4e00\u6216\u4e24\u4e2a\u6765\u76db\u653e\u53d6\u5f97\u7684 z\u5347 \u6c34\u3002

    \n\n

    \u4f60\u5141\u8bb8\uff1a

    \n\n
      \n\t
    • \u88c5\u6ee1\u4efb\u610f\u4e00\u4e2a\u6c34\u58f6
    • \n\t
    • \u6e05\u7a7a\u4efb\u610f\u4e00\u4e2a\u6c34\u58f6
    • \n\t
    • \u4ece\u4e00\u4e2a\u6c34\u58f6\u5411\u53e6\u5916\u4e00\u4e2a\u6c34\u58f6\u5012\u6c34\uff0c\u76f4\u5230\u88c5\u6ee1\u6216\u8005\u5012\u7a7a
    • \n
    \n\n

    \u793a\u4f8b 1: (From the famous "Die Hard" example)

    \n\n
    \u8f93\u5165: x = 3, y = 5, z = 4\n\u8f93\u51fa: True\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: x = 2, y = 6, z = 5\n\u8f93\u51fa: False\n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canMeasureWater(int jug1Capacity, int jug2Capacity, int targetCapacity) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canMeasureWater(int jug1Capacity, int jug2Capacity, int targetCapacity) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canMeasureWater(self, jug1Capacity, jug2Capacity, targetCapacity):\n \"\"\"\n :type jug1Capacity: int\n :type jug2Capacity: int\n :type targetCapacity: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canMeasureWater(self, jug1Capacity: int, jug2Capacity: int, targetCapacity: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canMeasureWater(int jug1Capacity, int jug2Capacity, int targetCapacity){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanMeasureWater(int jug1Capacity, int jug2Capacity, int targetCapacity) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} jug1Capacity\n * @param {number} jug2Capacity\n * @param {number} targetCapacity\n * @return {boolean}\n */\nvar canMeasureWater = function(jug1Capacity, jug2Capacity, targetCapacity) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} jug1_capacity\n# @param {Integer} jug2_capacity\n# @param {Integer} target_capacity\n# @return {Boolean}\ndef can_measure_water(jug1_capacity, jug2_capacity, target_capacity)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canMeasureWater(_ jug1Capacity: Int, _ jug2Capacity: Int, _ targetCapacity: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canMeasureWater(jug1Capacity int, jug2Capacity int, targetCapacity int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canMeasureWater(jug1Capacity: Int, jug2Capacity: Int, targetCapacity: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canMeasureWater(jug1Capacity: Int, jug2Capacity: Int, targetCapacity: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_measure_water(jug1_capacity: i32, jug2_capacity: i32, target_capacity: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $jug1Capacity\n * @param Integer $jug2Capacity\n * @param Integer $targetCapacity\n * @return Boolean\n */\n function canMeasureWater($jug1Capacity, $jug2Capacity, $targetCapacity) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canMeasureWater(jug1Capacity: number, jug2Capacity: number, targetCapacity: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-measure-water jug1Capacity jug2Capacity targetCapacity)\n (-> exact-integer? exact-integer? exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0365](https://leetcode-cn.com/problems/water-and-jug-problem)", "[\u6c34\u58f6\u95ee\u9898](/solution/0300-0399/0365.Water%20and%20Jug%20Problem/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0365](https://leetcode.com/problems/water-and-jug-problem)", "[Water and Jug Problem](/solution/0300-0399/0365.Water%20and%20Jug%20Problem/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "0364", "frontend_question_id": "0364", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/nested-list-weight-sum-ii", "url_en": "https://leetcode.com/problems/nested-list-weight-sum-ii", "relative_path_cn": "/solution/0300-0399/0364.Nested%20List%20Weight%20Sum%20II/README.md", "relative_path_en": "/solution/0300-0399/0364.Nested%20List%20Weight%20Sum%20II/README_EN.md", "title_cn": "\u52a0\u6743\u5d4c\u5957\u5e8f\u5217\u548c II", "title_en": "Nested List Weight Sum II", "question_title_slug": "nested-list-weight-sum-ii", "content_en": "

    You are given a nested list of integers nestedList. Each element is either an integer or a list whose elements may also be integers or other lists.

    \n\n

    The depth of an integer is the number of lists that it is inside of. For example, the nested list [1,[2,2],[[3],2],1] has each integer's value set to its depth. Let maxDepth be the maximum depth of any integer.

    \n\n

    The weight of an integer is maxDepth - (the depth of the integer) + 1.

    \n\n

    Return the sum of each integer in nestedList multiplied by its weight.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: nestedList = [[1,1],2,[1,1]]\nOutput: 8\nExplanation: Four 1's with a weight of 1, one 2 with a weight of 2.\n1*1 + 1*1 + 2*2 + 1*1 + 1*1 = 8\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: nestedList = [1,[4,[6]]]\nOutput: 17\nExplanation: One 1 at depth 3, one 4 at depth 2, and one 6 at depth 1.\n1*3 + 4*2 + 6*1 = 17\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nestedList.length <= 50
    • \n\t
    • The values of the integers in the nested list is in the range [-100, 100].
    • \n\t
    • The maximum depth of any integer is less than or equal to 50.
    • \n
    \n", "content_cn": "

    \u7ed9\u4e00\u4e2a\u5d4c\u5957\u6574\u6570\u5e8f\u5217\uff0c\u8bf7\u4f60\u8fd4\u56de\u6bcf\u4e2a\u6570\u5b57\u5728\u5e8f\u5217\u4e2d\u7684\u52a0\u6743\u548c\uff0c\u5b83\u4eec\u7684\u6743\u91cd\u7531\u5b83\u4eec\u7684\u6df1\u5ea6\u51b3\u5b9a\u3002

    \n\n

    \u5e8f\u5217\u4e2d\u7684\u6bcf\u4e00\u4e2a\u5143\u7d20\u8981\u4e48\u662f\u4e00\u4e2a\u6574\u6570\uff0c\u8981\u4e48\u662f\u4e00\u4e2a\u5e8f\u5217\uff08\u8fd9\u4e2a\u5e8f\u5217\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u4e5f\u540c\u6837\u662f\u6574\u6570\u6216\u5e8f\u5217\uff09\u3002

    \n\n

    \u4e0e \u524d\u4e00\u4e2a\u95ee\u9898 \u4e0d\u540c\u7684\u662f\uff0c\u524d\u4e00\u9898\u7684\u6743\u91cd\u6309\u7167\u4ece\u6839\u5230\u53f6\u9010\u4e00\u589e\u52a0\uff0c\u800c\u672c\u9898\u7684\u6743\u91cd\u4ece\u53f6\u5230\u6839\u9010\u4e00\u589e\u52a0\u3002

    \n\n

    \u4e5f\u5c31\u662f\u8bf4\uff0c\u5728\u672c\u9898\u4e2d\uff0c\u53f6\u5b50\u7684\u6743\u91cd\u4e3a1\uff0c\u800c\u6839\u62e5\u6709\u6700\u5927\u7684\u6743\u91cd\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: [[1,1],2,[1,1]]\n\u8f93\u51fa: 8 \n\u89e3\u91ca: \u56db\u4e2a 1 \u5728\u6df1\u5ea6\u4e3a 1 \u7684\u4f4d\u7f6e\uff0c \u4e00\u4e2a 2 \u5728\u6df1\u5ea6\u4e3a 2 \u7684\u4f4d\u7f6e\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: [1,[4,[6]]]\n\u8f93\u51fa: 17 \n\u89e3\u91ca: \u4e00\u4e2a 1 \u5728\u6df1\u5ea6\u4e3a 3 \u7684\u4f4d\u7f6e\uff0c \u4e00\u4e2a 4 \u5728\u6df1\u5ea6\u4e3a 2 \u7684\u4f4d\u7f6e\uff0c\u4e00\u4e2a 6 \u5728\u6df1\u5ea6\u4e3a 1 \u7684\u4f4d\u7f6e\u3002 1*3 + 4*2 + 6*1 = 17\u3002\n
    \n", "tags_en": ["Depth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * class NestedInteger {\n * public:\n * // Constructor initializes an empty nested list.\n * NestedInteger();\n *\n * // Constructor initializes a single integer.\n * NestedInteger(int value);\n *\n * // Return true if this NestedInteger holds a single integer, rather than a nested list.\n * bool isInteger() const;\n *\n * // Return the single integer that this NestedInteger holds, if it holds a single integer\n * // The result is undefined if this NestedInteger holds a nested list\n * int getInteger() const;\n *\n * // Set this NestedInteger to hold a single integer.\n * void setInteger(int value);\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * void add(const NestedInteger &ni);\n *\n * // Return the nested list that this NestedInteger holds, if it holds a nested list\n * // The result is undefined if this NestedInteger holds a single integer\n * const vector &getList() const;\n * };\n */\nclass Solution {\npublic:\n int depthSumInverse(vector& nestedList) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * public interface NestedInteger {\n * // Constructor initializes an empty nested list.\n * public NestedInteger();\n *\n * // Constructor initializes a single integer.\n * public NestedInteger(int value);\n *\n * // @return true if this NestedInteger holds a single integer, rather than a nested list.\n * public boolean isInteger();\n *\n * // @return the single integer that this NestedInteger holds, if it holds a single integer\n * // Return null if this NestedInteger holds a nested list\n * public Integer getInteger();\n *\n * // Set this NestedInteger to hold a single integer.\n * public void setInteger(int value);\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * public void add(NestedInteger ni);\n *\n * // @return the nested list that this NestedInteger holds, if it holds a nested list\n * // Return empty list if this NestedInteger holds a single integer\n * public List getList();\n * }\n */\nclass Solution {\n public int depthSumInverse(List nestedList) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# \"\"\"\n# This is the interface that allows for creating nested lists.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class NestedInteger(object):\n# def __init__(self, value=None):\n# \"\"\"\n# If value is not specified, initializes an empty list.\n# Otherwise initializes a single integer equal to value.\n# \"\"\"\n#\n# def isInteger(self):\n# \"\"\"\n# @return True if this NestedInteger holds a single integer, rather than a nested list.\n# :rtype bool\n# \"\"\"\n#\n# def add(self, elem):\n# \"\"\"\n# Set this NestedInteger to hold a nested list and adds a nested integer elem to it.\n# :rtype void\n# \"\"\"\n#\n# def setInteger(self, value):\n# \"\"\"\n# Set this NestedInteger to hold a single integer equal to value.\n# :rtype void\n# \"\"\"\n#\n# def getInteger(self):\n# \"\"\"\n# @return the single integer that this NestedInteger holds, if it holds a single integer\n# Return None if this NestedInteger holds a nested list\n# :rtype int\n# \"\"\"\n#\n# def getList(self):\n# \"\"\"\n# @return the nested list that this NestedInteger holds, if it holds a nested list\n# Return None if this NestedInteger holds a single integer\n# :rtype List[NestedInteger]\n# \"\"\"\nclass Solution(object):\n def depthSumInverse(self, nestedList):\n \"\"\"\n :type nestedList: List[NestedInteger]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# \"\"\"\n# This is the interface that allows for creating nested lists.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class NestedInteger:\n# def __init__(self, value=None):\n# \"\"\"\n# If value is not specified, initializes an empty list.\n# Otherwise initializes a single integer equal to value.\n# \"\"\"\n#\n# def isInteger(self):\n# \"\"\"\n# @return True if this NestedInteger holds a single integer, rather than a nested list.\n# :rtype bool\n# \"\"\"\n#\n# def add(self, elem):\n# \"\"\"\n# Set this NestedInteger to hold a nested list and adds a nested integer elem to it.\n# :rtype void\n# \"\"\"\n#\n# def setInteger(self, value):\n# \"\"\"\n# Set this NestedInteger to hold a single integer equal to value.\n# :rtype void\n# \"\"\"\n#\n# def getInteger(self):\n# \"\"\"\n# @return the single integer that this NestedInteger holds, if it holds a single integer\n# Return None if this NestedInteger holds a nested list\n# :rtype int\n# \"\"\"\n#\n# def getList(self):\n# \"\"\"\n# @return the nested list that this NestedInteger holds, if it holds a nested list\n# Return None if this NestedInteger holds a single integer\n# :rtype List[NestedInteger]\n# \"\"\"\nclass Solution:\n def depthSumInverse(self, nestedList: List[NestedInteger]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * *********************************************************************\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * *********************************************************************\n *\n * // Initializes an empty nested list and return a reference to the nested integer.\n * struct NestedInteger *NestedIntegerInit();\n *\n * // Return true if this NestedInteger holds a single integer, rather than a nested list.\n * bool NestedIntegerIsInteger(struct NestedInteger *);\n *\n * // Return the single integer that this NestedInteger holds, if it holds a single integer\n * // The result is undefined if this NestedInteger holds a nested list\n * int NestedIntegerGetInteger(struct NestedInteger *);\n *\n * // Set this NestedInteger to hold a single integer.\n * void NestedIntegerSetInteger(struct NestedInteger *ni, int value);\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer elem to it.\n * void NestedIntegerAdd(struct NestedInteger *ni, struct NestedInteger *elem);\n *\n * // Return the nested list that this NestedInteger holds, if it holds a nested list\n * // The result is undefined if this NestedInteger holds a single integer\n * struct NestedInteger **NestedIntegerGetList(struct NestedInteger *);\n *\n * // Return the nested list's size that this NestedInteger holds, if it holds a nested list\n * // The result is undefined if this NestedInteger holds a single integer\n * int NestedIntegerGetListSize(struct NestedInteger *);\n * };\n */\n\n\nint depthSumInverse(struct NestedInteger** nestedList, int nestedListSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * interface NestedInteger {\n *\n * // Constructor initializes an empty nested list.\n * public NestedInteger();\n *\n * // Constructor initializes a single integer.\n * public NestedInteger(int value);\n *\n * // @return true if this NestedInteger holds a single integer, rather than a nested list.\n * bool IsInteger();\n *\n * // @return the single integer that this NestedInteger holds, if it holds a single integer\n * // Return null if this NestedInteger holds a nested list\n * int GetInteger();\n *\n * // Set this NestedInteger to hold a single integer.\n * public void SetInteger(int value);\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * public void Add(NestedInteger ni);\n *\n * // @return the nested list that this NestedInteger holds, if it holds a nested list\n * // Return null if this NestedInteger holds a single integer\n * IList GetList();\n * }\n */\npublic class Solution {\n public int DepthSumInverse(IList nestedList) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * function NestedInteger() {\n *\n * Return true if this NestedInteger holds a single integer, rather than a nested list.\n * @return {boolean}\n * this.isInteger = function() {\n * ...\n * };\n *\n * Return the single integer that this NestedInteger holds, if it holds a single integer\n * Return null if this NestedInteger holds a nested list\n * @return {integer}\n * this.getInteger = function() {\n * ...\n * };\n *\n * Set this NestedInteger to hold a single integer equal to value.\n * @return {void}\n * this.setInteger = function(value) {\n * ...\n * };\n *\n * Set this NestedInteger to hold a nested list and adds a nested integer elem to it.\n * @return {void}\n * this.add = function(elem) {\n * ...\n * };\n *\n * Return the nested list that this NestedInteger holds, if it holds a nested list\n * Return null if this NestedInteger holds a single integer\n * @return {NestedInteger[]}\n * this.getList = function() {\n * ...\n * };\n * };\n */\n/**\n * @param {NestedInteger[]} nestedList\n * @return {number}\n */\nvar depthSumInverse = function(nestedList) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# This is the interface that allows for creating nested lists.\n# You should not implement it, or speculate about its implementation\n#\n#class NestedInteger\n# def is_integer()\n# \"\"\"\n# Return true if this NestedInteger holds a single integer, rather than a nested list.\n# @return {Boolean}\n# \"\"\"\n#\n# def get_integer()\n# \"\"\"\n# Return the single integer that this NestedInteger holds, if it holds a single integer\n# Return nil if this NestedInteger holds a nested list\n# @return {Integer}\n# \"\"\"\n#\n# def set_integer(value)\n# \"\"\"\n# Set this NestedInteger to hold a single integer equal to value.\n# @return {Void}\n# \"\"\"\n#\n# def add(elem)\n# \"\"\"\n# Set this NestedInteger to hold a nested list and adds a nested integer elem to it.\n# @return {Void}\n# \"\"\"\n#\n# def get_list()\n# \"\"\"\n# Return the nested list that this NestedInteger holds, if it holds a nested list\n# Return nil if this NestedInteger holds a single integer\n# @return {NestedInteger[]}\n# \"\"\"\n# @param {NestedInteger[]} nested_list\n# @return {Integer}\ndef depth_sum_inverse(nested_list)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * class NestedInteger {\n * // Return true if this NestedInteger holds a single integer, rather than a nested list.\n * public func isInteger() -> Bool\n *\n * // Return the single integer that this NestedInteger holds, if it holds a single integer\n * // The result is undefined if this NestedInteger holds a nested list\n * public func getInteger() -> Int\n *\n * // Set this NestedInteger to hold a single integer.\n * public func setInteger(value: Int)\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * public func add(elem: NestedInteger)\n *\n * // Return the nested list that this NestedInteger holds, if it holds a nested list\n * // The result is undefined if this NestedInteger holds a single integer\n * public func getList() -> [NestedInteger]\n * }\n */\nclass Solution {\n func depthSumInverse(_ nestedList: [NestedInteger]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * type NestedInteger struct {\n * }\n *\n * // Return true if this NestedInteger holds a single integer, rather than a nested list.\n * func (n NestedInteger) IsInteger() bool {}\n *\n * // Return the single integer that this NestedInteger holds, if it holds a single integer\n * // The result is undefined if this NestedInteger holds a nested list\n * // So before calling this method, you should have a check\n * func (n NestedInteger) GetInteger() int {}\n *\n * // Set this NestedInteger to hold a single integer.\n * func (n *NestedInteger) SetInteger(value int) {}\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * func (n *NestedInteger) Add(elem NestedInteger) {}\n *\n * // Return the nested list that this NestedInteger holds, if it holds a nested list\n * // The list length is zero if this NestedInteger holds a single integer\n * // You can access NestedInteger's List element directly if you want to modify it\n * func (n NestedInteger) GetList() []*NestedInteger {}\n */\nfunc depthSumInverse(nestedList []*NestedInteger) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * trait NestedInteger {\n *\n * // Return true if this NestedInteger holds a single integer, rather than a nested list.\n * def isInteger: Boolean\n *\n * // Return the single integer that this NestedInteger holds, if it holds a single integer.\n * def getInteger: Int\n *\n * // Set this NestedInteger to hold a single integer.\n * def setInteger(i: Int): Unit\n *\n * // Return the nested list that this NestedInteger holds, if it holds a nested list.\n * def getList: Array[NestedInteger]\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * def add(ni: NestedInteger): Unit\n * }\n */\nobject Solution {\n def depthSumInverse(nestedList: List[NestedInteger]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * class NestedInteger {\n * // Constructor initializes an empty nested list.\n * constructor()\n *\n * // Constructor initializes a single integer.\n * constructor(value: Int)\n *\n * // @return true if this NestedInteger holds a single integer, rather than a nested list.\n * fun isInteger(): Boolean\n *\n * // @return the single integer that this NestedInteger holds, if it holds a single integer\n * // Return null if this NestedInteger holds a nested list\n * fun getInteger(): Int?\n *\n * // Set this NestedInteger to hold a single integer.\n * fun setInteger(value: Int): Unit\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * fun add(ni: NestedInteger): Unit\n *\n * // @return the nested list that this NestedInteger holds, if it holds a nested list\n * // Return null if this NestedInteger holds a single integer\n * fun getList(): List?\n * }\n */\nclass Solution {\n fun depthSumInverse(nestedList: List): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// #[derive(Debug, PartialEq, Eq)]\n// pub enum NestedInteger {\n// Int(i32),\n// List(Vec)\n// }\nimpl Solution {\n pub fn depth_sum_inverse(nested_list: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * class NestedInteger {\n\n * // if value is not specified, initializes an empty list.\n * // Otherwise initializes a single integer equal to value.\n * function __construct($value = null)\n\n * // Return true if this NestedInteger holds a single integer, rather than a nested list.\n * function isInteger() : bool\n *\n * // Return the single integer that this NestedInteger holds, if it holds a single integer\n * // The result is undefined if this NestedInteger holds a nested list\n * function getInteger()\n *\n * // Set this NestedInteger to hold a single integer.\n * function setInteger($i) : void\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * function add($ni) : void\n *\n * // Return the nested list that this NestedInteger holds, if it holds a nested list\n * // The result is undefined if this NestedInteger holds a single integer\n * function getList() : array\n * }\n */\nclass Solution {\n\n /**\n * @param NestedInteger[] $nestedList\n * @return Integer\n */\n function depthSumInverse($nestedList) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * class NestedInteger {\n * If value is provided, then it holds a single integer\n * Otherwise it holds an empty nested list\n * constructor(value?: number) {\n * ...\n * };\n *\n * Return true if this NestedInteger holds a single integer, rather than a nested list.\n * isInteger(): boolean {\n * ...\n * };\n *\n * Return the single integer that this NestedInteger holds, if it holds a single integer\n * Return null if this NestedInteger holds a nested list\n * getInteger(): number | null {\n * ...\n * };\n *\n * Set this NestedInteger to hold a single integer equal to value.\n * setInteger(value: number) {\n * ...\n * };\n *\n * Set this NestedInteger to hold a nested list and adds a nested integer elem to it.\n * add(elem: NestedInteger) {\n * ...\n * };\n *\n * Return the nested list that this NestedInteger holds,\n * or an empty list if this NestedInteger holds a single integer\n * getList(): NestedInteger[] {\n * ...\n * };\n * };\n */\n\nfunction depthSumInverse(nestedList: NestedInteger[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": ";; This is the interface that allows for creating nested lists.\n;; You should not implement it, or speculate about its implementation\n\n#|\n\n(define nested-integer%\n (class object%\n ...\n\n ; Return true if this nested-integer% holds a single integer, rather than a nested list.\n ; -> boolean?\n (define/public (is-integer)\n ...)\n\n ; Return the single integer that this nested-integer% holds, if it holds a single integer,\n ; or #f if this nested-integer% holds a nested list.\n ; -> integer?\n (define/public (get-integer)\n ...)\n\n ; Set this nested-integer% to hold a single integer equal to value.\n ; -> integer? void?\n (define/public (set-integer i)\n ...)\n\n ; Set this nested-integer% to hold a nested list and adds a nested integer elem to it.\n ; -> (is-a?/c nested-integer%) void?\n (define/public (add ni)\n ...)\n\n ; Return the nested list that this nested-integer% holds,\n ; or an empty list if this nested-integer% holds a single integer.\n ; -> gvector?\n (define/public (get-list)\n ...)))\n\n|#\n\n(define/contract (depth-sum-inverse nestedList)\n (-> (listof (is-a?/c nested-integer%)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0364](https://leetcode-cn.com/problems/nested-list-weight-sum-ii)", "[\u52a0\u6743\u5d4c\u5957\u5e8f\u5217\u548c II](/solution/0300-0399/0364.Nested%20List%20Weight%20Sum%20II/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0364](https://leetcode.com/problems/nested-list-weight-sum-ii)", "[Nested List Weight Sum II](/solution/0300-0399/0364.Nested%20List%20Weight%20Sum%20II/README_EN.md)", "`Depth-first Search`", "Medium", "\ud83d\udd12"]}, {"question_id": "0363", "frontend_question_id": "0363", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/max-sum-of-rectangle-no-larger-than-k", "url_en": "https://leetcode.com/problems/max-sum-of-rectangle-no-larger-than-k", "relative_path_cn": "/solution/0300-0399/0363.Max%20Sum%20of%20Rectangle%20No%20Larger%20Than%20K/README.md", "relative_path_en": "/solution/0300-0399/0363.Max%20Sum%20of%20Rectangle%20No%20Larger%20Than%20K/README_EN.md", "title_cn": "\u77e9\u5f62\u533a\u57df\u4e0d\u8d85\u8fc7 K \u7684\u6700\u5927\u6570\u503c\u548c", "title_en": "Max Sum of Rectangle No Larger Than K", "question_title_slug": "max-sum-of-rectangle-no-larger-than-k", "content_en": "

    Given an m x n matrix matrix and an integer k, return the max sum of a rectangle in the matrix such that its sum is no larger than k.

    \n\n

    It is guaranteed that there will be a rectangle with a sum no larger than k.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: matrix = [[1,0,1],[0,-2,3]], k = 2\nOutput: 2\nExplanation: Because the sum of the blue rectangle [[0, 1], [-2, 3]] is 2, and 2 is the max number no larger than k (k = 2).\n
    \n\n

    Example 2:

    \n\n
    \nInput: matrix = [[2,2,-1]], k = 3\nOutput: 3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == matrix.length
    • \n\t
    • n == matrix[i].length
    • \n\t
    • 1 <= m, n <= 100
    • \n\t
    • -100 <= matrix[i][j] <= 100
    • \n\t
    • -105 <= k <= 105
    • \n
    \n\n

     

    \n

    Follow up: What if the number of rows is much larger than the number of columns?

    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a m x n \u7684\u77e9\u9635 matrix \u548c\u4e00\u4e2a\u6574\u6570 k \uff0c\u627e\u51fa\u5e76\u8fd4\u56de\u77e9\u9635\u5185\u90e8\u77e9\u5f62\u533a\u57df\u7684\u4e0d\u8d85\u8fc7 k \u7684\u6700\u5927\u6570\u503c\u548c\u3002

    \n\n

    \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u603b\u4f1a\u5b58\u5728\u4e00\u4e2a\u6570\u503c\u548c\u4e0d\u8d85\u8fc7 k \u7684\u77e9\u5f62\u533a\u57df\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1amatrix = [[1,0,1],[0,-2,3]], k = 2\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u84dd\u8272\u8fb9\u6846\u5708\u51fa\u6765\u7684\u77e9\u5f62\u533a\u57df\u00a0[[0, 1], [-2, 3]]\u00a0\u7684\u6570\u503c\u548c\u662f 2\uff0c\u4e14 2 \u662f\u4e0d\u8d85\u8fc7 k \u7684\u6700\u5927\u6570\u5b57\uff08k = 2\uff09\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1amatrix = [[2,2,-1]], k = 3\n\u8f93\u51fa\uff1a3\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == matrix.length
    • \n\t
    • n == matrix[i].length
    • \n\t
    • 1 <= m, n <= 100
    • \n\t
    • -100 <= matrix[i][j] <= 100
    • \n\t
    • -105 <= k <= 105
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u5982\u679c\u884c\u6570\u8fdc\u5927\u4e8e\u5217\u6570\uff0c\u8be5\u5982\u4f55\u8bbe\u8ba1\u89e3\u51b3\u65b9\u6848\uff1f

    \n", "tags_en": ["Queue", "Binary Search", "Dynamic Programming"], "tags_cn": ["\u961f\u5217", "\u4e8c\u5206\u67e5\u627e", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxSumSubmatrix(vector>& matrix, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxSumSubmatrix(int[][] matrix, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxSumSubmatrix(self, matrix, k):\n \"\"\"\n :type matrix: List[List[int]]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxSumSubmatrix(self, matrix: List[List[int]], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxSumSubmatrix(int** matrix, int matrixSize, int* matrixColSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxSumSubmatrix(int[][] matrix, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} matrix\n * @param {number} k\n * @return {number}\n */\nvar maxSumSubmatrix = function(matrix, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} matrix\n# @param {Integer} k\n# @return {Integer}\ndef max_sum_submatrix(matrix, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxSumSubmatrix(_ matrix: [[Int]], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxSumSubmatrix(matrix [][]int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxSumSubmatrix(matrix: Array[Array[Int]], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxSumSubmatrix(matrix: Array, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_sum_submatrix(matrix: Vec>, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $matrix\n * @param Integer $k\n * @return Integer\n */\n function maxSumSubmatrix($matrix, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxSumSubmatrix(matrix: number[][], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-sum-submatrix matrix k)\n (-> (listof (listof exact-integer?)) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0363](https://leetcode-cn.com/problems/max-sum-of-rectangle-no-larger-than-k)", "[\u77e9\u5f62\u533a\u57df\u4e0d\u8d85\u8fc7 K \u7684\u6700\u5927\u6570\u503c\u548c](/solution/0300-0399/0363.Max%20Sum%20of%20Rectangle%20No%20Larger%20Than%20K/README.md)", "`\u961f\u5217`,`\u4e8c\u5206\u67e5\u627e`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0363](https://leetcode.com/problems/max-sum-of-rectangle-no-larger-than-k)", "[Max Sum of Rectangle No Larger Than K](/solution/0300-0399/0363.Max%20Sum%20of%20Rectangle%20No%20Larger%20Than%20K/README_EN.md)", "`Queue`,`Binary Search`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0362", "frontend_question_id": "0362", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/design-hit-counter", "url_en": "https://leetcode.com/problems/design-hit-counter", "relative_path_cn": "/solution/0300-0399/0362.Design%20Hit%20Counter/README.md", "relative_path_en": "/solution/0300-0399/0362.Design%20Hit%20Counter/README_EN.md", "title_cn": "\u6572\u51fb\u8ba1\u6570\u5668", "title_en": "Design Hit Counter", "question_title_slug": "design-hit-counter", "content_en": "

    Design a hit counter which counts the number of hits received in the past 5 minutes (i.e., the past 300 seconds).

    \n\n

    Your system should accept a timestamp parameter (in seconds granularity), and you may assume that calls are being made to the system in chronological order (i.e., timestamp is monotonically increasing). Several hits may arrive roughly at the same time.

    \n\n

    Implement the HitCounter class:

    \n\n
      \n\t
    • HitCounter() Initializes the object of the hit counter system.
    • \n\t
    • void hit(int timestamp) Records a hit that happened at timestamp (in seconds). Several hits may happen at the same timestamp.
    • \n\t
    • int getHits(int timestamp) Returns the number of hits in the past 5 minutes from timestamp (i.e., the past 300 seconds).
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["HitCounter", "hit", "hit", "hit", "getHits", "hit", "getHits", "getHits"]\n[[], [1], [2], [3], [4], [300], [300], [301]]\nOutput\n[null, null, null, null, 3, null, 4, 3]\n\nExplanation\nHitCounter hitCounter = new HitCounter();\nhitCounter.hit(1);       // hit at timestamp 1.\nhitCounter.hit(2);       // hit at timestamp 2.\nhitCounter.hit(3);       // hit at timestamp 3.\nhitCounter.getHits(4);   // get hits at timestamp 4, return 3.\nhitCounter.hit(300);     // hit at timestamp 300.\nhitCounter.getHits(300); // get hits at timestamp 300, return 4.\nhitCounter.getHits(301); // get hits at timestamp 301, return 3.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= timestamp <= 2 * 109
    • \n\t
    • All the calls are being made to the system in chronological order (i.e., timestamp is monotonically increasing).
    • \n\t
    • At most 300 calls will be made to hit and getHits.
    • \n
    \n\n

     

    \n

    Follow up: What if the number of hits per second could be huge? Does your design scale?

    \n", "content_cn": "

    \u8bbe\u8ba1\u4e00\u4e2a\u6572\u51fb\u8ba1\u6570\u5668\uff0c\u4f7f\u5b83\u53ef\u4ee5\u7edf\u8ba1\u5728\u8fc7\u53bb5\u5206\u949f\u5185\u88ab\u6572\u51fb\u6b21\u6570\u3002

    \n\n

    \u6bcf\u4e2a\u51fd\u6570\u4f1a\u63a5\u6536\u4e00\u4e2a\u65f6\u95f4\u6233\u53c2\u6570\uff08\u4ee5\u79d2\u4e3a\u5355\u4f4d\uff09\uff0c\u4f60\u53ef\u4ee5\u5047\u8bbe\u6700\u65e9\u7684\u65f6\u95f4\u6233\u4ece1\u5f00\u59cb\uff0c\u4e14\u90fd\u662f\u6309\u7167\u65f6\u95f4\u987a\u5e8f\u5bf9\u7cfb\u7edf\u8fdb\u884c\u8c03\u7528\uff08\u5373\u65f6\u95f4\u6233\u662f\u5355\u8c03\u9012\u589e\uff09\u3002

    \n\n

    \u5728\u540c\u4e00\u65f6\u523b\u6709\u53ef\u80fd\u4f1a\u6709\u591a\u6b21\u6572\u51fb\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    HitCounter counter = new HitCounter();\n\n// \u5728\u65f6\u523b 1 \u6572\u51fb\u4e00\u6b21\u3002\ncounter.hit(1);\n\n// \u5728\u65f6\u523b 2 \u6572\u51fb\u4e00\u6b21\u3002\ncounter.hit(2);\n\n// \u5728\u65f6\u523b 3 \u6572\u51fb\u4e00\u6b21\u3002\ncounter.hit(3);\n\n// \u5728\u65f6\u523b 4 \u7edf\u8ba1\u8fc7\u53bb 5 \u5206\u949f\u5185\u7684\u6572\u51fb\u6b21\u6570, \u51fd\u6570\u8fd4\u56de 3 \u3002\ncounter.getHits(4);\n\n// \u5728\u65f6\u523b 300 \u6572\u51fb\u4e00\u6b21\u3002\ncounter.hit(300);\n\n// \u5728\u65f6\u523b 300 \u7edf\u8ba1\u8fc7\u53bb 5 \u5206\u949f\u5185\u7684\u6572\u51fb\u6b21\u6570\uff0c\u51fd\u6570\u8fd4\u56de 4 \u3002\ncounter.getHits(300);\n\n// \u5728\u65f6\u523b 301 \u7edf\u8ba1\u8fc7\u53bb 5 \u5206\u949f\u5185\u7684\u6572\u51fb\u6b21\u6570\uff0c\u51fd\u6570\u8fd4\u56de 3 \u3002\ncounter.getHits(301); \n
    \n\n

    \u8fdb\u9636:

    \n\n

    \u5982\u679c\u6bcf\u79d2\u7684\u6572\u51fb\u6b21\u6570\u662f\u4e00\u4e2a\u5f88\u5927\u7684\u6570\u5b57\uff0c\u4f60\u7684\u8ba1\u6570\u5668\u53ef\u4ee5\u5e94\u5bf9\u5417\uff1f

    \n", "tags_en": ["Design"], "tags_cn": ["\u8bbe\u8ba1"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class HitCounter {\npublic:\n /** Initialize your data structure here. */\n HitCounter() {\n\n }\n \n /** Record a hit.\n @param timestamp - The current timestamp (in seconds granularity). */\n void hit(int timestamp) {\n\n }\n \n /** Return the number of hits in the past 5 minutes.\n @param timestamp - The current timestamp (in seconds granularity). */\n int getHits(int timestamp) {\n\n }\n};\n\n/**\n * Your HitCounter object will be instantiated and called as such:\n * HitCounter* obj = new HitCounter();\n * obj->hit(timestamp);\n * int param_2 = obj->getHits(timestamp);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class HitCounter {\n\n /** Initialize your data structure here. */\n public HitCounter() {\n\n }\n \n /** Record a hit.\n @param timestamp - The current timestamp (in seconds granularity). */\n public void hit(int timestamp) {\n\n }\n \n /** Return the number of hits in the past 5 minutes.\n @param timestamp - The current timestamp (in seconds granularity). */\n public int getHits(int timestamp) {\n\n }\n}\n\n/**\n * Your HitCounter object will be instantiated and called as such:\n * HitCounter obj = new HitCounter();\n * obj.hit(timestamp);\n * int param_2 = obj.getHits(timestamp);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class HitCounter(object):\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def hit(self, timestamp):\n \"\"\"\n Record a hit.\n @param timestamp - The current timestamp (in seconds granularity).\n :type timestamp: int\n :rtype: None\n \"\"\"\n\n\n def getHits(self, timestamp):\n \"\"\"\n Return the number of hits in the past 5 minutes.\n @param timestamp - The current timestamp (in seconds granularity).\n :type timestamp: int\n :rtype: int\n \"\"\"\n\n\n\n# Your HitCounter object will be instantiated and called as such:\n# obj = HitCounter()\n# obj.hit(timestamp)\n# param_2 = obj.getHits(timestamp)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class HitCounter:\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def hit(self, timestamp: int) -> None:\n \"\"\"\n Record a hit.\n @param timestamp - The current timestamp (in seconds granularity).\n \"\"\"\n\n\n def getHits(self, timestamp: int) -> int:\n \"\"\"\n Return the number of hits in the past 5 minutes.\n @param timestamp - The current timestamp (in seconds granularity).\n \"\"\"\n\n\n\n# Your HitCounter object will be instantiated and called as such:\n# obj = HitCounter()\n# obj.hit(timestamp)\n# param_2 = obj.getHits(timestamp)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} HitCounter;\n\n/** Initialize your data structure here. */\n\nHitCounter* hitCounterCreate() {\n\n}\n\n/** Record a hit.\n @param timestamp - The current timestamp (in seconds granularity). */\nvoid hitCounterHit(HitCounter* obj, int timestamp) {\n\n}\n\n/** Return the number of hits in the past 5 minutes.\n @param timestamp - The current timestamp (in seconds granularity). */\nint hitCounterGetHits(HitCounter* obj, int timestamp) {\n\n}\n\nvoid hitCounterFree(HitCounter* obj) {\n\n}\n\n/**\n * Your HitCounter struct will be instantiated and called as such:\n * HitCounter* obj = hitCounterCreate();\n * hitCounterHit(obj, timestamp);\n \n * int param_2 = hitCounterGetHits(obj, timestamp);\n \n * hitCounterFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class HitCounter {\n\n /** Initialize your data structure here. */\n public HitCounter() {\n\n }\n \n /** Record a hit.\n @param timestamp - The current timestamp (in seconds granularity). */\n public void Hit(int timestamp) {\n\n }\n \n /** Return the number of hits in the past 5 minutes.\n @param timestamp - The current timestamp (in seconds granularity). */\n public int GetHits(int timestamp) {\n\n }\n}\n\n/**\n * Your HitCounter object will be instantiated and called as such:\n * HitCounter obj = new HitCounter();\n * obj.Hit(timestamp);\n * int param_2 = obj.GetHits(timestamp);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Initialize your data structure here.\n */\nvar HitCounter = function() {\n\n};\n\n/**\n * Record a hit.\n @param timestamp - The current timestamp (in seconds granularity). \n * @param {number} timestamp\n * @return {void}\n */\nHitCounter.prototype.hit = function(timestamp) {\n\n};\n\n/**\n * Return the number of hits in the past 5 minutes.\n @param timestamp - The current timestamp (in seconds granularity). \n * @param {number} timestamp\n * @return {number}\n */\nHitCounter.prototype.getHits = function(timestamp) {\n\n};\n\n/**\n * Your HitCounter object will be instantiated and called as such:\n * var obj = new HitCounter()\n * obj.hit(timestamp)\n * var param_2 = obj.getHits(timestamp)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class HitCounter\n\n=begin\n Initialize your data structure here.\n=end\n def initialize()\n\n end\n\n\n=begin\n Record a hit.\n @param timestamp - The current timestamp (in seconds granularity).\n :type timestamp: Integer\n :rtype: Void\n=end\n def hit(timestamp)\n\n end\n\n\n=begin\n Return the number of hits in the past 5 minutes.\n @param timestamp - The current timestamp (in seconds granularity).\n :type timestamp: Integer\n :rtype: Integer\n=end\n def get_hits(timestamp)\n\n end\n\n\nend\n\n# Your HitCounter object will be instantiated and called as such:\n# obj = HitCounter.new()\n# obj.hit(timestamp)\n# param_2 = obj.get_hits(timestamp)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass HitCounter {\n\n /** Initialize your data structure here. */\n init() {\n\n }\n \n /** Record a hit.\n @param timestamp - The current timestamp (in seconds granularity). */\n func hit(_ timestamp: Int) {\n\n }\n \n /** Return the number of hits in the past 5 minutes.\n @param timestamp - The current timestamp (in seconds granularity). */\n func getHits(_ timestamp: Int) -> Int {\n\n }\n}\n\n/**\n * Your HitCounter object will be instantiated and called as such:\n * let obj = HitCounter()\n * obj.hit(timestamp)\n * let ret_2: Int = obj.getHits(timestamp)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type HitCounter struct {\n\n}\n\n\n/** Initialize your data structure here. */\nfunc Constructor() HitCounter {\n\n}\n\n\n/** Record a hit.\n @param timestamp - The current timestamp (in seconds granularity). */\nfunc (this *HitCounter) Hit(timestamp int) {\n\n}\n\n\n/** Return the number of hits in the past 5 minutes.\n @param timestamp - The current timestamp (in seconds granularity). */\nfunc (this *HitCounter) GetHits(timestamp int) int {\n\n}\n\n\n/**\n * Your HitCounter object will be instantiated and called as such:\n * obj := Constructor();\n * obj.Hit(timestamp);\n * param_2 := obj.GetHits(timestamp);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class HitCounter() {\n\n /** Initialize your data structure here. */\n\n\n /** Record a hit.\n @param timestamp - The current timestamp (in seconds granularity). */\n def hit(timestamp: Int) {\n\n }\n\n /** Return the number of hits in the past 5 minutes.\n @param timestamp - The current timestamp (in seconds granularity). */\n def getHits(timestamp: Int): Int = {\n\n }\n\n}\n\n/**\n * Your HitCounter object will be instantiated and called as such:\n * var obj = new HitCounter()\n * obj.hit(timestamp)\n * var param_2 = obj.getHits(timestamp)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class HitCounter() {\n\n /** Initialize your data structure here. */\n\n\n /** Record a hit.\n @param timestamp - The current timestamp (in seconds granularity). */\n fun hit(timestamp: Int) {\n\n }\n\n /** Return the number of hits in the past 5 minutes.\n @param timestamp - The current timestamp (in seconds granularity). */\n fun getHits(timestamp: Int): Int {\n\n }\n\n}\n\n/**\n * Your HitCounter object will be instantiated and called as such:\n * var obj = HitCounter()\n * obj.hit(timestamp)\n * var param_2 = obj.getHits(timestamp)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct HitCounter {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl HitCounter {\n\n /** Initialize your data structure here. */\n fn new() -> Self {\n\n }\n \n /** Record a hit.\n @param timestamp - The current timestamp (in seconds granularity). */\n fn hit(&self, timestamp: i32) {\n\n }\n \n /** Return the number of hits in the past 5 minutes.\n @param timestamp - The current timestamp (in seconds granularity). */\n fn get_hits(&self, timestamp: i32) -> i32 {\n\n }\n}\n\n/**\n * Your HitCounter object will be instantiated and called as such:\n * let obj = HitCounter::new();\n * obj.hit(timestamp);\n * let ret_2: i32 = obj.get_hits(timestamp);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class HitCounter {\n /**\n * Initialize your data structure here.\n */\n function __construct() {\n\n }\n\n /**\n * Record a hit.\n @param timestamp - The current timestamp (in seconds granularity).\n * @param Integer $timestamp\n * @return NULL\n */\n function hit($timestamp) {\n\n }\n\n /**\n * Return the number of hits in the past 5 minutes.\n @param timestamp - The current timestamp (in seconds granularity).\n * @param Integer $timestamp\n * @return Integer\n */\n function getHits($timestamp) {\n\n }\n}\n\n/**\n * Your HitCounter object will be instantiated and called as such:\n * $obj = HitCounter();\n * $obj->hit($timestamp);\n * $ret_2 = $obj->getHits($timestamp);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class HitCounter {\n constructor() {\n\n }\n\n hit(timestamp: number): void {\n\n }\n\n getHits(timestamp: number): number {\n\n }\n}\n\n/**\n * Your HitCounter object will be instantiated and called as such:\n * var obj = new HitCounter()\n * obj.hit(timestamp)\n * var param_2 = obj.getHits(timestamp)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define hit-counter%\n (class object%\n (super-new)\n (init-field)\n \n ; hit : exact-integer? -> void?\n (define/public (hit timestamp)\n\n )\n ; get-hits : exact-integer? -> exact-integer?\n (define/public (get-hits timestamp)\n\n )))\n\n;; Your hit-counter% object will be instantiated and called as such:\n;; (define obj (new hit-counter%))\n;; (send obj hit timestamp)\n;; (define param_2 (send obj get-hits timestamp))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0362](https://leetcode-cn.com/problems/design-hit-counter)", "[\u6572\u51fb\u8ba1\u6570\u5668](/solution/0300-0399/0362.Design%20Hit%20Counter/README.md)", "`\u8bbe\u8ba1`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0362](https://leetcode.com/problems/design-hit-counter)", "[Design Hit Counter](/solution/0300-0399/0362.Design%20Hit%20Counter/README_EN.md)", "`Design`", "Medium", "\ud83d\udd12"]}, {"question_id": "0361", "frontend_question_id": "0361", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/bomb-enemy", "url_en": "https://leetcode.com/problems/bomb-enemy", "relative_path_cn": "/solution/0300-0399/0361.Bomb%20Enemy/README.md", "relative_path_en": "/solution/0300-0399/0361.Bomb%20Enemy/README_EN.md", "title_cn": "\u8f70\u70b8\u654c\u4eba", "title_en": "Bomb Enemy", "question_title_slug": "bomb-enemy", "content_en": "

    Given an m x n matrix grid where each cell is either a wall 'W', an enemy 'E' or empty '0', return the maximum enemies you can kill using one bomb. You can only place the bomb in an empty cell.

    \n\n

    The bomb kills all the enemies in the same row and column from the planted point until it hits the wall since it is too strong to be destroyed.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: grid = [["0","E","0","0"],["E","0","W","E"],["0","E","0","0"]]\nOutput: 3\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: grid = [["W","W","W"],["0","0","0"],["E","E","E"]]\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= m, n <= 500
    • \n\t
    • grid[i][j] is either 'W', 'E', or '0'.
    • \n
    \n", "content_cn": "

    \u60f3\u8c61\u4e00\u4e0b\u70b8\u5f39\u4eba\u6e38\u620f\uff0c\u5728\u4f60\u9762\u524d\u6709\u4e00\u4e2a\u4e8c\u7ef4\u7684\u7f51\u683c\u6765\u8868\u793a\u5730\u56fe\uff0c\u7f51\u683c\u4e2d\u7684\u683c\u5b50\u5206\u522b\u88ab\u4ee5\u4e0b\u4e09\u79cd\u7b26\u53f7\u5360\u636e\uff1a

    \n\n
      \n\t
    • 'W' \u8868\u793a\u4e00\u5835\u5899
    • \n\t
    • 'E' \u8868\u793a\u4e00\u4e2a\u654c\u4eba
    • \n\t
    • '0'\uff08\u6570\u5b57 0\uff09\u8868\u793a\u4e00\u4e2a\u7a7a\u4f4d
    • \n
    \n\n

    \n\n

    \u8bf7\u4f60\u8ba1\u7b97\u4e00\u4e2a\u70b8\u5f39\u6700\u591a\u80fd\u70b8\u591a\u5c11\u654c\u4eba\u3002

    \n\n

    \u7531\u4e8e\u70b8\u5f39\u7684\u5a01\u529b\u4e0d\u8db3\u4ee5\u7a7f\u900f\u5899\u4f53\uff0c\u70b8\u5f39\u53ea\u80fd\u70b8\u5230\u540c\u4e00\u884c\u548c\u540c\u4e00\u5217\u6ca1\u88ab\u5899\u4f53\u6321\u4f4f\u7684\u654c\u4eba\u3002

    \n\n

    \u6ce8\u610f\uff1a\u4f60\u53ea\u80fd\u628a\u70b8\u5f39\u653e\u5728\u4e00\u4e2a\u7a7a\u7684\u683c\u5b50\u91cc

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: [["0","E","0","0"],["E","0","W","E"],["0","E","0","0"]]\n\u8f93\u51fa: 3 \n\u89e3\u91ca: \u5bf9\u4e8e\u5982\u4e0b\u7f51\u683c\n\n0 E 0 0 \nE 0 W E \n0 E 0 0\n\n\u5047\u5982\u5728\u4f4d\u7f6e (1,1) \u653e\u7f6e\u70b8\u5f39\u7684\u8bdd\uff0c\u53ef\u4ee5\u70b8\u5230 3 \u4e2a\u654c\u4eba\n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxKilledEnemies(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxKilledEnemies(char[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxKilledEnemies(self, grid):\n \"\"\"\n :type grid: List[List[str]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxKilledEnemies(self, grid: List[List[str]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxKilledEnemies(char** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxKilledEnemies(char[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {character[][]} grid\n * @return {number}\n */\nvar maxKilledEnemies = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Character[][]} grid\n# @return {Integer}\ndef max_killed_enemies(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxKilledEnemies(_ grid: [[Character]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxKilledEnemies(grid [][]byte) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxKilledEnemies(grid: Array[Array[Char]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxKilledEnemies(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_killed_enemies(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $grid\n * @return Integer\n */\n function maxKilledEnemies($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxKilledEnemies(grid: string[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-killed-enemies grid)\n (-> (listof (listof char?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0361](https://leetcode-cn.com/problems/bomb-enemy)", "[\u8f70\u70b8\u654c\u4eba](/solution/0300-0399/0361.Bomb%20Enemy/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0361](https://leetcode.com/problems/bomb-enemy)", "[Bomb Enemy](/solution/0300-0399/0361.Bomb%20Enemy/README_EN.md)", "`Dynamic Programming`", "Medium", "\ud83d\udd12"]}, {"question_id": "0360", "frontend_question_id": "0360", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/sort-transformed-array", "url_en": "https://leetcode.com/problems/sort-transformed-array", "relative_path_cn": "/solution/0300-0399/0360.Sort%20Transformed%20Array/README.md", "relative_path_en": "/solution/0300-0399/0360.Sort%20Transformed%20Array/README_EN.md", "title_cn": "\u6709\u5e8f\u8f6c\u5316\u6570\u7ec4", "title_en": "Sort Transformed Array", "question_title_slug": "sort-transformed-array", "content_en": "

    Given a sorted integer array nums and three integers a, b and c, apply a quadratic function of the form f(x) = ax2 + bx + c to each element nums[i] in the array, and return the array in a sorted order.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [-4,-2,2,4], a = 1, b = 3, c = 5\nOutput: [3,9,15,33]\n

    Example 2:

    \n
    Input: nums = [-4,-2,2,4], a = -1, b = 3, c = 5\nOutput: [-23,-5,1,7]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 200
    • \n\t
    • -100 <= nums[i], a, b, c <= 100
    • \n\t
    • nums is sorted in ascending order.
    • \n
    \n\n

     

    \n

    Follow up: Could you solve it in O(n) time?

    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5df2\u7ecf \u6392\u597d\u5e8f \u7684\u6574\u6570\u6570\u7ec4 nums \u548c\u6574\u6570 a\u3001b\u3001c\u3002\u5bf9\u4e8e\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e00\u4e2a\u6570 x\uff0c\u8ba1\u7b97\u51fd\u6570\u503c f(x) = ax2 + bx + c\uff0c\u8bf7\u5c06\u51fd\u6570\u503c\u4ea7\u751f\u7684\u6570\u7ec4\u8fd4\u56de\u3002

    \n\n

    \u8981\u6ce8\u610f\uff0c\u8fd4\u56de\u7684\u8fd9\u4e2a\u6570\u7ec4\u5fc5\u987b\u6309\u7167 \u5347\u5e8f\u6392\u5217\uff0c\u5e76\u4e14\u6211\u4eec\u6240\u671f\u671b\u7684\u89e3\u6cd5\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\u3002

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165: nums = [-4,-2,2,4], a = 1, b = 3, c = 5\n\u8f93\u51fa: [3,9,15,33]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165: nums = [-4,-2,2,4], a = -1, b = 3, c = 5\n\u8f93\u51fa: [-23,-5,1,7]\n
    \n", "tags_en": ["Sort", "Math", "Two Pointers"], "tags_cn": ["\u6392\u5e8f", "\u6570\u5b66", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector sortTransformedArray(vector& nums, int a, int b, int c) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] sortTransformedArray(int[] nums, int a, int b, int c) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def sortTransformedArray(self, nums, a, b, c):\n \"\"\"\n :type nums: List[int]\n :type a: int\n :type b: int\n :type c: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def sortTransformedArray(self, nums: List[int], a: int, b: int, c: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* sortTransformedArray(int* nums, int numsSize, int a, int b, int c, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] SortTransformedArray(int[] nums, int a, int b, int c) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} a\n * @param {number} b\n * @param {number} c\n * @return {number[]}\n */\nvar sortTransformedArray = function(nums, a, b, c) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} a\n# @param {Integer} b\n# @param {Integer} c\n# @return {Integer[]}\ndef sort_transformed_array(nums, a, b, c)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func sortTransformedArray(_ nums: [Int], _ a: Int, _ b: Int, _ c: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func sortTransformedArray(nums []int, a int, b int, c int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def sortTransformedArray(nums: Array[Int], a: Int, b: Int, c: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun sortTransformedArray(nums: IntArray, a: Int, b: Int, c: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sort_transformed_array(nums: Vec, a: i32, b: i32, c: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $a\n * @param Integer $b\n * @param Integer $c\n * @return Integer[]\n */\n function sortTransformedArray($nums, $a, $b, $c) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function sortTransformedArray(nums: number[], a: number, b: number, c: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (sort-transformed-array nums a b c)\n (-> (listof exact-integer?) exact-integer? exact-integer? exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0360](https://leetcode-cn.com/problems/sort-transformed-array)", "[\u6709\u5e8f\u8f6c\u5316\u6570\u7ec4](/solution/0300-0399/0360.Sort%20Transformed%20Array/README.md)", "`\u6392\u5e8f`,`\u6570\u5b66`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0360](https://leetcode.com/problems/sort-transformed-array)", "[Sort Transformed Array](/solution/0300-0399/0360.Sort%20Transformed%20Array/README_EN.md)", "`Sort`,`Math`,`Two Pointers`", "Medium", "\ud83d\udd12"]}, {"question_id": "0359", "frontend_question_id": "0359", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/logger-rate-limiter", "url_en": "https://leetcode.com/problems/logger-rate-limiter", "relative_path_cn": "/solution/0300-0399/0359.Logger%20Rate%20Limiter/README.md", "relative_path_en": "/solution/0300-0399/0359.Logger%20Rate%20Limiter/README_EN.md", "title_cn": "\u65e5\u5fd7\u901f\u7387\u9650\u5236\u5668", "title_en": "Logger Rate Limiter", "question_title_slug": "logger-rate-limiter", "content_en": "

    Design a logger system that receives a stream of messages along with their timestamps. Each unique message should only be printed at most every 10 seconds (i.e. a message printed at timestamp t will prevent other identical messages from being printed until timestamp t + 10).

    \n\n

    All messages will come in chronological order. Several messages may arrive at the same timestamp.

    \n\n

    Implement the Logger class:

    \n\n
      \n\t
    • Logger() Initializes the logger object.
    • \n\t
    • bool shouldPrintMessage(int timestamp, string message) Returns true if the message should be printed in the given timestamp, otherwise returns false.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["Logger", "shouldPrintMessage", "shouldPrintMessage", "shouldPrintMessage", "shouldPrintMessage", "shouldPrintMessage", "shouldPrintMessage"]\n[[], [1, "foo"], [2, "bar"], [3, "foo"], [8, "bar"], [10, "foo"], [11, "foo"]]\nOutput\n[null, true, true, false, false, false, true]\n\nExplanation\nLogger logger = new Logger();\nlogger.shouldPrintMessage(1, "foo");  // return true, next allowed timestamp for "foo" is 1 + 10 = 11\nlogger.shouldPrintMessage(2, "bar");  // return true, next allowed timestamp for "bar" is 2 + 10 = 12\nlogger.shouldPrintMessage(3, "foo");  // 3 < 11, return false\nlogger.shouldPrintMessage(8, "bar");  // 8 < 12, return false\nlogger.shouldPrintMessage(10, "foo"); // 10 < 11, return false\nlogger.shouldPrintMessage(11, "foo"); // 11 >= 11, return true, next allowed timestamp for "foo" is\n                                      // 11 + 10 = 21\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= timestamp <= 109
    • \n\t
    • Every timestamp will be passed in non-decreasing order (chronological order).
    • \n\t
    • 1 <= message.length <= 30
    • \n\t
    • At most 104 calls will be made to shouldPrintMessage.
    • \n
    \n", "content_cn": "

    \u8bf7\u4f60\u8bbe\u8ba1\u4e00\u4e2a\u65e5\u5fd7\u7cfb\u7edf\uff0c\u53ef\u4ee5\u6d41\u5f0f\u63a5\u6536\u6d88\u606f\u4ee5\u53ca\u5b83\u7684\u65f6\u95f4\u6233\u3002\u6bcf\u6761 \u4e0d\u91cd\u590d \u7684\u6d88\u606f\u6700\u591a\u53ea\u80fd\u6bcf 10 \u79d2\u6253\u5370\u4e00\u6b21\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u5982\u679c\u5728\u65f6\u95f4\u6233 t \u6253\u5370\u67d0\u6761\u6d88\u606f\uff0c\u90a3\u4e48\u76f8\u540c\u5185\u5bb9\u7684\u6d88\u606f\u76f4\u5230\u65f6\u95f4\u6233\u53d8\u4e3a t + 10 \u4e4b\u524d\u90fd\u4e0d\u4f1a\u88ab\u6253\u5370\u3002

    \n\n

    \u6240\u6709\u6d88\u606f\u90fd\u6309\u65f6\u95f4\u987a\u5e8f\u53d1\u9001\u3002\u591a\u6761\u6d88\u606f\u53ef\u80fd\u5230\u8fbe\u540c\u4e00\u65f6\u95f4\u6233\u3002

    \n\n

    \u5b9e\u73b0 Logger \u7c7b\uff1a

    \n\n
      \n\t
    • Logger() \u521d\u59cb\u5316 logger \u5bf9\u8c61
    • \n\t
    • bool shouldPrintMessage(int timestamp, string message) \u5982\u679c\u8fd9\u6761\u6d88\u606f message \u5728\u7ed9\u5b9a\u7684\u65f6\u95f4\u6233 timestamp \u5e94\u8be5\u88ab\u6253\u5370\u51fa\u6765\uff0c\u5219\u8fd4\u56de\u00a0true \uff0c\u5426\u5219\u8bf7\u8fd4\u56de\u00a0false \u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\n[\"Logger\", \"shouldPrintMessage\", \"shouldPrintMessage\", \"shouldPrintMessage\", \"shouldPrintMessage\", \"shouldPrintMessage\", \"shouldPrintMessage\"]\n[[], [1, \"foo\"], [2, \"bar\"], [3, \"foo\"], [8, \"bar\"], [10, \"foo\"], [11, \"foo\"]]\n\u8f93\u51fa\uff1a\n[null, true, true, false, false, false, true]\n\n\u89e3\u91ca\uff1a\nLogger logger = new Logger();\nlogger.shouldPrintMessage(1, \"foo\");  // \u8fd4\u56de true \uff0c\u4e0b\u4e00\u6b21 \"foo\" \u53ef\u4ee5\u6253\u5370\u7684\u65f6\u95f4\u6233\u662f 1 + 10 = 11\nlogger.shouldPrintMessage(2, \"bar\");  // \u8fd4\u56de true \uff0c\u4e0b\u4e00\u6b21 \"bar\" \u53ef\u4ee5\u6253\u5370\u7684\u65f6\u95f4\u6233\u662f 2 + 10 = 12\nlogger.shouldPrintMessage(3, \"foo\");  // 3 < 11 \uff0c\u8fd4\u56de false\nlogger.shouldPrintMessage(8, \"bar\");  // 8 < 12 \uff0c\u8fd4\u56de false\nlogger.shouldPrintMessage(10, \"foo\"); // 10 < 11 \uff0c\u8fd4\u56de false\nlogger.shouldPrintMessage(11, \"foo\"); // 11 >= 11 \uff0c\u8fd4\u56de true \uff0c\u4e0b\u4e00\u6b21 \"foo\" \u53ef\u4ee5\u6253\u5370\u7684\u65f6\u95f4\u6233\u662f 11 + 10 = 21\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= timestamp <= 109
    • \n\t
    • \u6bcf\u4e2a timestamp \u90fd\u5c06\u6309\u975e\u9012\u51cf\u987a\u5e8f\uff08\u65f6\u95f4\u987a\u5e8f\uff09\u4f20\u9012
    • \n\t
    • 1 <= message.length <= 30
    • \n\t
    • \u6700\u591a\u8c03\u7528 104 \u6b21 shouldPrintMessage \u65b9\u6cd5
    • \n
    \n", "tags_en": ["Design", "Hash Table"], "tags_cn": ["\u8bbe\u8ba1", "\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Logger {\npublic:\n /** Initialize your data structure here. */\n Logger() {\n\n }\n \n /** Returns true if the message should be printed in the given timestamp, otherwise returns false.\n If this method returns false, the message will not be printed.\n The timestamp is in seconds granularity. */\n bool shouldPrintMessage(int timestamp, string message) {\n\n }\n};\n\n/**\n * Your Logger object will be instantiated and called as such:\n * Logger* obj = new Logger();\n * bool param_1 = obj->shouldPrintMessage(timestamp,message);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Logger {\n\n /** Initialize your data structure here. */\n public Logger() {\n\n }\n \n /** Returns true if the message should be printed in the given timestamp, otherwise returns false.\n If this method returns false, the message will not be printed.\n The timestamp is in seconds granularity. */\n public boolean shouldPrintMessage(int timestamp, String message) {\n\n }\n}\n\n/**\n * Your Logger object will be instantiated and called as such:\n * Logger obj = new Logger();\n * boolean param_1 = obj.shouldPrintMessage(timestamp,message);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Logger(object):\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def shouldPrintMessage(self, timestamp, message):\n \"\"\"\n Returns true if the message should be printed in the given timestamp, otherwise returns false.\n If this method returns false, the message will not be printed.\n The timestamp is in seconds granularity.\n :type timestamp: int\n :type message: str\n :rtype: bool\n \"\"\"\n\n\n\n# Your Logger object will be instantiated and called as such:\n# obj = Logger()\n# param_1 = obj.shouldPrintMessage(timestamp,message)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Logger:\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def shouldPrintMessage(self, timestamp: int, message: str) -> bool:\n \"\"\"\n Returns true if the message should be printed in the given timestamp, otherwise returns false.\n If this method returns false, the message will not be printed.\n The timestamp is in seconds granularity.\n \"\"\"\n\n\n\n# Your Logger object will be instantiated and called as such:\n# obj = Logger()\n# param_1 = obj.shouldPrintMessage(timestamp,message)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} Logger;\n\n/** Initialize your data structure here. */\n\nLogger* loggerCreate() {\n \n}\n\n/** Returns true if the message should be printed in the given timestamp, otherwise returns false.\n If this method returns false, the message will not be printed.\n The timestamp is in seconds granularity. */\nbool loggerShouldPrintMessage(Logger* obj, int timestamp, char * message) {\n \n}\n\nvoid loggerFree(Logger* obj) {\n \n}\n\n/**\n * Your Logger struct will be instantiated and called as such:\n * Logger* obj = loggerCreate();\n * bool param_1 = loggerShouldPrintMessage(obj, timestamp, message);\n \n * loggerFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Logger {\n\n /** Initialize your data structure here. */\n public Logger() {\n\n }\n \n /** Returns true if the message should be printed in the given timestamp, otherwise returns false.\n If this method returns false, the message will not be printed.\n The timestamp is in seconds granularity. */\n public bool ShouldPrintMessage(int timestamp, string message) {\n\n }\n}\n\n/**\n * Your Logger object will be instantiated and called as such:\n * Logger obj = new Logger();\n * bool param_1 = obj.ShouldPrintMessage(timestamp,message);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Initialize your data structure here.\n */\nvar Logger = function() {\n\n};\n\n/**\n * Returns true if the message should be printed in the given timestamp, otherwise returns false.\n If this method returns false, the message will not be printed.\n The timestamp is in seconds granularity. \n * @param {number} timestamp \n * @param {string} message\n * @return {boolean}\n */\nLogger.prototype.shouldPrintMessage = function(timestamp, message) {\n\n};\n\n/**\n * Your Logger object will be instantiated and called as such:\n * var obj = new Logger()\n * var param_1 = obj.shouldPrintMessage(timestamp,message)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class Logger\n\n=begin\n Initialize your data structure here.\n=end\n def initialize()\n\n end\n\n\n=begin\n Returns true if the message should be printed in the given timestamp, otherwise returns false.\n If this method returns false, the message will not be printed.\n The timestamp is in seconds granularity.\n :type timestamp: Integer\n :type message: String\n :rtype: Boolean\n=end\n def should_print_message(timestamp, message)\n\n end\n\n\nend\n\n# Your Logger object will be instantiated and called as such:\n# obj = Logger.new()\n# param_1 = obj.should_print_message(timestamp, message)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass Logger {\n\n /** Initialize your data structure here. */\n init() {\n\n }\n \n /** Returns true if the message should be printed in the given timestamp, otherwise returns false.\n If this method returns false, the message will not be printed.\n The timestamp is in seconds granularity. */\n func shouldPrintMessage(_ timestamp: Int, _ message: String) -> Bool {\n\n }\n}\n\n/**\n * Your Logger object will be instantiated and called as such:\n * let obj = Logger()\n * let ret_1: Bool = obj.shouldPrintMessage(timestamp, message)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type Logger struct {\n\n}\n\n\n/** Initialize your data structure here. */\nfunc Constructor() Logger {\n\n}\n\n\n/** Returns true if the message should be printed in the given timestamp, otherwise returns false.\n If this method returns false, the message will not be printed.\n The timestamp is in seconds granularity. */\nfunc (this *Logger) ShouldPrintMessage(timestamp int, message string) bool {\n\n}\n\n\n/**\n * Your Logger object will be instantiated and called as such:\n * obj := Constructor();\n * param_1 := obj.ShouldPrintMessage(timestamp,message);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class Logger() {\n\n /** Initialize your data structure here. */\n\n\n /** Returns true if the message should be printed in the given timestamp, otherwise returns false.\n If this method returns false, the message will not be printed.\n The timestamp is in seconds granularity. */\n def shouldPrintMessage(timestamp: Int, message: String): Boolean = {\n\n }\n\n}\n\n/**\n * Your Logger object will be instantiated and called as such:\n * var obj = new Logger()\n * var param_1 = obj.shouldPrintMessage(timestamp,message)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Logger() {\n\n /** Initialize your data structure here. */\n\n\n /** Returns true if the message should be printed in the given timestamp, otherwise returns false.\n If this method returns false, the message will not be printed.\n The timestamp is in seconds granularity. */\n fun shouldPrintMessage(timestamp: Int, message: String): Boolean {\n\n }\n\n}\n\n/**\n * Your Logger object will be instantiated and called as such:\n * var obj = Logger()\n * var param_1 = obj.shouldPrintMessage(timestamp,message)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct Logger {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl Logger {\n\n /** Initialize your data structure here. */\n fn new() -> Self {\n\n }\n \n /** Returns true if the message should be printed in the given timestamp, otherwise returns false.\n If this method returns false, the message will not be printed.\n The timestamp is in seconds granularity. */\n fn should_print_message(&self, timestamp: i32, message: String) -> bool {\n\n }\n}\n\n/**\n * Your Logger object will be instantiated and called as such:\n * let obj = Logger::new();\n * let ret_1: bool = obj.should_print_message(timestamp, message);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Logger {\n /**\n * Initialize your data structure here.\n */\n function __construct() {\n\n }\n\n /**\n * Returns true if the message should be printed in the given timestamp, otherwise returns false.\n If this method returns false, the message will not be printed.\n The timestamp is in seconds granularity.\n * @param Integer $timestamp\n * @param String $message\n * @return Boolean\n */\n function shouldPrintMessage($timestamp, $message) {\n\n }\n}\n\n/**\n * Your Logger object will be instantiated and called as such:\n * $obj = Logger();\n * $ret_1 = $obj->shouldPrintMessage($timestamp, $message);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class Logger {\n constructor() {\n\n }\n\n shouldPrintMessage(timestamp: number, message: string): boolean {\n\n }\n}\n\n/**\n * Your Logger object will be instantiated and called as such:\n * var obj = new Logger()\n * var param_1 = obj.shouldPrintMessage(timestamp,message)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define logger%\n (class object%\n (super-new)\n (init-field)\n \n ; should-print-message : exact-integer? string? -> boolean?\n (define/public (should-print-message timestamp message)\n\n )))\n\n;; Your logger% object will be instantiated and called as such:\n;; (define obj (new logger%))\n;; (define param_1 (send obj should-print-message timestamp message))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0359](https://leetcode-cn.com/problems/logger-rate-limiter)", "[\u65e5\u5fd7\u901f\u7387\u9650\u5236\u5668](/solution/0300-0399/0359.Logger%20Rate%20Limiter/README.md)", "`\u8bbe\u8ba1`,`\u54c8\u5e0c\u8868`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0359](https://leetcode.com/problems/logger-rate-limiter)", "[Logger Rate Limiter](/solution/0300-0399/0359.Logger%20Rate%20Limiter/README_EN.md)", "`Design`,`Hash Table`", "Easy", "\ud83d\udd12"]}, {"question_id": "0358", "frontend_question_id": "0358", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/rearrange-string-k-distance-apart", "url_en": "https://leetcode.com/problems/rearrange-string-k-distance-apart", "relative_path_cn": "/solution/0300-0399/0358.Rearrange%20String%20k%20Distance%20Apart/README.md", "relative_path_en": "/solution/0300-0399/0358.Rearrange%20String%20k%20Distance%20Apart/README_EN.md", "title_cn": "K \u8ddd\u79bb\u95f4\u9694\u91cd\u6392\u5b57\u7b26\u4e32", "title_en": "Rearrange String k Distance Apart", "question_title_slug": "rearrange-string-k-distance-apart", "content_en": "

    Given a string s and an integer k, rearrange s such that the same characters are at least distance k from each other. If it is not possible to rearrange the string, return an empty string "".

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "aabbcc", k = 3\nOutput: "abcabc"\nExplanation: The same letters are at least a distance of 3 from each other.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "aaabc", k = 3\nOutput: ""\nExplanation: It is not possible to rearrange the string.\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "aaadbbcc", k = 2\nOutput: "abacabcd"\nExplanation: The same letters are at least a distance of 2 from each other.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 3 * 105
    • \n\t
    • s consists of only lowercase English letters.
    • \n\t
    • 0 <= k <= s.length
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u975e\u7a7a\u7684\u5b57\u7b26\u4e32 s \u548c\u4e00\u4e2a\u6574\u6570 k\uff0c\u4f60\u8981\u5c06\u8fd9\u4e2a\u5b57\u7b26\u4e32\u4e2d\u7684\u5b57\u6bcd\u8fdb\u884c\u91cd\u65b0\u6392\u5217\uff0c\u4f7f\u5f97\u91cd\u6392\u540e\u7684\u5b57\u7b26\u4e32\u4e2d\u76f8\u540c\u5b57\u6bcd\u7684\u4f4d\u7f6e\u95f4\u9694\u8ddd\u79bb\u81f3\u5c11\u4e3a k\u3002

    \n\n

    \u6240\u6709\u8f93\u5165\u7684\u5b57\u7b26\u4e32\u90fd\u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210\uff0c\u5982\u679c\u627e\u4e0d\u5230\u8ddd\u79bb\u81f3\u5c11\u4e3a k \u7684\u91cd\u6392\u7ed3\u679c\uff0c\u8bf7\u8fd4\u56de\u4e00\u4e2a\u7a7a\u5b57\u7b26\u4e32 ""\u3002

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165: s = "aabbcc", k = 3\n\u8f93\u51fa: "abcabc" \n\u89e3\u91ca: \u76f8\u540c\u7684\u5b57\u6bcd\u5728\u65b0\u7684\u5b57\u7b26\u4e32\u4e2d\u95f4\u9694\u81f3\u5c11 3 \u4e2a\u5355\u4f4d\u8ddd\u79bb\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: s = "aaabc", k = 3\n\u8f93\u51fa: "" \n\u89e3\u91ca: \u6ca1\u6709\u529e\u6cd5\u627e\u5230\u53ef\u80fd\u7684\u91cd\u6392\u7ed3\u679c\u3002\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u8f93\u5165: s = "aaadbbcc", k = 2\n\u8f93\u51fa: "abacabcd"\n\u89e3\u91ca: \u76f8\u540c\u7684\u5b57\u6bcd\u5728\u65b0\u7684\u5b57\u7b26\u4e32\u4e2d\u95f4\u9694\u81f3\u5c11 2 \u4e2a\u5355\u4f4d\u8ddd\u79bb\u3002\n
    \n", "tags_en": ["Heap", "Greedy", "Hash Table"], "tags_cn": ["\u5806", "\u8d2a\u5fc3\u7b97\u6cd5", "\u54c8\u5e0c\u8868"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string rearrangeString(string s, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String rearrangeString(String s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def rearrangeString(self, s, k):\n \"\"\"\n :type s: str\n :type k: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def rearrangeString(self, s: str, k: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * rearrangeString(char * s, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string RearrangeString(string s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number} k\n * @return {string}\n */\nvar rearrangeString = function(s, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer} k\n# @return {String}\ndef rearrange_string(s, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func rearrangeString(_ s: String, _ k: Int) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func rearrangeString(s string, k int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def rearrangeString(s: String, k: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun rearrangeString(s: String, k: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn rearrange_string(s: String, k: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer $k\n * @return String\n */\n function rearrangeString($s, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function rearrangeString(s: string, k: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (rearrange-string s k)\n (-> string? exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0358](https://leetcode-cn.com/problems/rearrange-string-k-distance-apart)", "[K \u8ddd\u79bb\u95f4\u9694\u91cd\u6392\u5b57\u7b26\u4e32](/solution/0300-0399/0358.Rearrange%20String%20k%20Distance%20Apart/README.md)", "`\u5806`,`\u8d2a\u5fc3\u7b97\u6cd5`,`\u54c8\u5e0c\u8868`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0358](https://leetcode.com/problems/rearrange-string-k-distance-apart)", "[Rearrange String k Distance Apart](/solution/0300-0399/0358.Rearrange%20String%20k%20Distance%20Apart/README_EN.md)", "`Heap`,`Greedy`,`Hash Table`", "Hard", "\ud83d\udd12"]}, {"question_id": "0357", "frontend_question_id": "0357", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-numbers-with-unique-digits", "url_en": "https://leetcode.com/problems/count-numbers-with-unique-digits", "relative_path_cn": "/solution/0300-0399/0357.Count%20Numbers%20with%20Unique%20Digits/README.md", "relative_path_en": "/solution/0300-0399/0357.Count%20Numbers%20with%20Unique%20Digits/README_EN.md", "title_cn": "\u8ba1\u7b97\u5404\u4e2a\u4f4d\u6570\u4e0d\u540c\u7684\u6570\u5b57\u4e2a\u6570", "title_en": "Count Numbers with Unique Digits", "question_title_slug": "count-numbers-with-unique-digits", "content_en": "

    Given an integer n, return the count of all numbers with unique digits, x, where 0 <= x < 10n.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 2\nOutput: 91\nExplanation: The answer should be the total numbers in the range of 0 ≤ x < 100, excluding 11,22,33,44,55,66,77,88,99\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 0\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= n <= 8
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u8d1f\u6574\u6570 n\uff0c\u8ba1\u7b97\u5404\u4f4d\u6570\u5b57\u90fd\u4e0d\u540c\u7684\u6570\u5b57 x \u7684\u4e2a\u6570\uff0c\u5176\u4e2d 0 ≤ x < 10\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: 2\n\u8f93\u51fa: 91 \n\u89e3\u91ca: \u7b54\u6848\u5e94\u4e3a\u9664\u53bb 11,22,33,44,55,66,77,88,99 \u5916\uff0c\u5728 [0,100) \u533a\u95f4\u5185\u7684\u6240\u6709\u6570\u5b57\u3002\n
    \n", "tags_en": ["Math", "Dynamic Programming", "Backtracking"], "tags_cn": ["\u6570\u5b66", "\u52a8\u6001\u89c4\u5212", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countNumbersWithUniqueDigits(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countNumbersWithUniqueDigits(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countNumbersWithUniqueDigits(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countNumbersWithUniqueDigits(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countNumbersWithUniqueDigits(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountNumbersWithUniqueDigits(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar countNumbersWithUniqueDigits = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef count_numbers_with_unique_digits(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countNumbersWithUniqueDigits(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countNumbersWithUniqueDigits(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countNumbersWithUniqueDigits(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countNumbersWithUniqueDigits(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_numbers_with_unique_digits(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function countNumbersWithUniqueDigits($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countNumbersWithUniqueDigits(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-numbers-with-unique-digits n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0357](https://leetcode-cn.com/problems/count-numbers-with-unique-digits)", "[\u8ba1\u7b97\u5404\u4e2a\u4f4d\u6570\u4e0d\u540c\u7684\u6570\u5b57\u4e2a\u6570](/solution/0300-0399/0357.Count%20Numbers%20with%20Unique%20Digits/README.md)", "`\u6570\u5b66`,`\u52a8\u6001\u89c4\u5212`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0357](https://leetcode.com/problems/count-numbers-with-unique-digits)", "[Count Numbers with Unique Digits](/solution/0300-0399/0357.Count%20Numbers%20with%20Unique%20Digits/README_EN.md)", "`Math`,`Dynamic Programming`,`Backtracking`", "Medium", ""]}, {"question_id": "0356", "frontend_question_id": "0356", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/line-reflection", "url_en": "https://leetcode.com/problems/line-reflection", "relative_path_cn": "/solution/0300-0399/0356.Line%20Reflection/README.md", "relative_path_en": "/solution/0300-0399/0356.Line%20Reflection/README_EN.md", "title_cn": "\u76f4\u7ebf\u955c\u50cf", "title_en": "Line Reflection", "question_title_slug": "line-reflection", "content_en": "

    Given n points on a 2D plane, find if there is such a line parallel to y-axis that reflect the given points symmetrically, in other words, answer whether or not if there exists a line that after reflecting all points over the given line the set of the original points is the same that the reflected ones.

    \n\n

    Note that there can be repeated points.

    \n\n

    Follow up:
    \nCould you do better than O(n2) ?

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: points = [[1,1],[-1,1]]\nOutput: true\nExplanation: We can choose the line x = 0.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: points = [[1,1],[-1,-1]]\nOutput: false\nExplanation: We can't choose a line.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == points.length
    • \n\t
    • 1 <= n <= 10^4
    • \n\t
    • -10^8 <= points[i][j] <= 10^8
    • \n
    \n", "content_cn": "

    \u5728\u4e00\u4e2a\u4e8c\u7ef4\u5e73\u9762\u7a7a\u95f4\u4e2d\uff0c\u7ed9\u4f60 n\u00a0\u4e2a\u70b9\u7684\u5750\u6807\u3002\u95ee\uff0c\u662f\u5426\u80fd\u627e\u51fa\u4e00\u6761\u5e73\u884c\u4e8e y\u00a0\u8f74\u7684\u76f4\u7ebf\uff0c\u8ba9\u8fd9\u4e9b\u70b9\u5173\u4e8e\u8fd9\u6761\u76f4\u7ebf\u6210\u955c\u50cf\u6392\u5e03\uff1f

    \n\n

    \u6ce8\u610f\uff1a\u9898\u76ee\u6570\u636e\u4e2d\u53ef\u80fd\u6709\u91cd\u590d\u7684\u70b9\u3002

    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u80fd\u627e\u5230\u6bd4 O(n2) \u66f4\u4f18\u7684\u89e3\u6cd5\u5417?

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1apoints = [[1,1],[-1,1]]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u53ef\u4ee5\u627e\u51fa x = 0 \u8fd9\u6761\u7ebf\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1apoints = [[1,1],[-1,-1]]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u65e0\u6cd5\u627e\u51fa\u8fd9\u6837\u4e00\u6761\u7ebf\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == points.length
    • \n\t
    • 1 <= n <= 10^4
    • \n\t
    • -10^8\u00a0<= points[i][j] <=\u00a010^8
    • \n
    \n", "tags_en": ["Hash Table", "Math"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isReflected(vector>& points) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isReflected(int[][] points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isReflected(self, points):\n \"\"\"\n :type points: List[List[int]]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isReflected(self, points: List[List[int]]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isReflected(int** points, int pointsSize, int* pointsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsReflected(int[][] points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} points\n * @return {boolean}\n */\nvar isReflected = function(points) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} points\n# @return {Boolean}\ndef is_reflected(points)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isReflected(_ points: [[Int]]) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isReflected(points [][]int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isReflected(points: Array[Array[Int]]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isReflected(points: Array): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_reflected(points: Vec>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $points\n * @return Boolean\n */\n function isReflected($points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isReflected(points: number[][]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-reflected points)\n (-> (listof (listof exact-integer?)) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0356](https://leetcode-cn.com/problems/line-reflection)", "[\u76f4\u7ebf\u955c\u50cf](/solution/0300-0399/0356.Line%20Reflection/README.md)", "`\u54c8\u5e0c\u8868`,`\u6570\u5b66`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0356](https://leetcode.com/problems/line-reflection)", "[Line Reflection](/solution/0300-0399/0356.Line%20Reflection/README_EN.md)", "`Hash Table`,`Math`", "Medium", "\ud83d\udd12"]}, {"question_id": "0355", "frontend_question_id": "0355", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/design-twitter", "url_en": "https://leetcode.com/problems/design-twitter", "relative_path_cn": "/solution/0300-0399/0355.Design%20Twitter/README.md", "relative_path_en": "/solution/0300-0399/0355.Design%20Twitter/README_EN.md", "title_cn": "\u8bbe\u8ba1\u63a8\u7279", "title_en": "Design Twitter", "question_title_slug": "design-twitter", "content_en": "

    Design a simplified version of Twitter where users can post tweets, follow/unfollow another user, and is able to see the 10 most recent tweets in the user's news feed.

    \n\n

    Implement the Twitter class:

    \n\n
      \n\t
    • Twitter() Initializes your twitter object.
    • \n\t
    • void postTweet(int userId, int tweetId) Composes a new tweet with ID tweetId by the user userId. Each call to this function will be made with a unique tweetId.
    • \n\t
    • List<Integer> getNewsFeed(int userId) Retrieves the 10 most recent tweet IDs in the user's news feed. Each item in the news feed must be posted by users who the user followed or by the user themself. Tweets must be ordered from most recent to least recent.
    • \n\t
    • void follow(int followerId, int followeeId) The user with ID followerId started following the user with ID followeeId.
    • \n\t
    • void unfollow(int followerId, int followeeId) The user with ID followerId started unfollowing the user with ID followeeId.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["Twitter", "postTweet", "getNewsFeed", "follow", "postTweet", "getNewsFeed", "unfollow", "getNewsFeed"]\n[[], [1, 5], [1], [1, 2], [2, 6], [1], [1, 2], [1]]\nOutput\n[null, null, [5], null, null, [6, 5], null, [5]]\n\nExplanation\nTwitter twitter = new Twitter();\ntwitter.postTweet(1, 5); // User 1 posts a new tweet (id = 5).\ntwitter.getNewsFeed(1);  // User 1's news feed should return a list with 1 tweet id -> [5]. return [5]\ntwitter.follow(1, 2);    // User 1 follows user 2.\ntwitter.postTweet(2, 6); // User 2 posts a new tweet (id = 6).\ntwitter.getNewsFeed(1);  // User 1's news feed should return a list with 2 tweet ids -> [6, 5]. Tweet id 6 should precede tweet id 5 because it is posted after tweet id 5.\ntwitter.unfollow(1, 2);  // User 1 unfollows user 2.\ntwitter.getNewsFeed(1);  // User 1's news feed should return a list with 1 tweet id -> [5], since user 1 is no longer following user 2.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= userId, followerId, followeeId <= 500
    • \n\t
    • 0 <= tweetId <= 104
    • \n\t
    • All the tweets have unique IDs.
    • \n\t
    • At most 3 * 104 calls will be made to postTweet, getNewsFeed, follow, and unfollow.
    • \n
    \n", "content_cn": "

    \u8bbe\u8ba1\u4e00\u4e2a\u7b80\u5316\u7248\u7684\u63a8\u7279(Twitter)\uff0c\u53ef\u4ee5\u8ba9\u7528\u6237\u5b9e\u73b0\u53d1\u9001\u63a8\u6587\uff0c\u5173\u6ce8/\u53d6\u6d88\u5173\u6ce8\u5176\u4ed6\u7528\u6237\uff0c\u80fd\u591f\u770b\u89c1\u5173\u6ce8\u4eba\uff08\u5305\u62ec\u81ea\u5df1\uff09\u7684\u6700\u8fd1\u5341\u6761\u63a8\u6587\u3002\u4f60\u7684\u8bbe\u8ba1\u9700\u8981\u652f\u6301\u4ee5\u4e0b\u7684\u51e0\u4e2a\u529f\u80fd\uff1a

    \n\n
      \n\t
    1. postTweet(userId, tweetId): \u521b\u5efa\u4e00\u6761\u65b0\u7684\u63a8\u6587
    2. \n\t
    3. getNewsFeed(userId): \u68c0\u7d22\u6700\u8fd1\u7684\u5341\u6761\u63a8\u6587\u3002\u6bcf\u4e2a\u63a8\u6587\u90fd\u5fc5\u987b\u662f\u7531\u6b64\u7528\u6237\u5173\u6ce8\u7684\u4eba\u6216\u8005\u662f\u7528\u6237\u81ea\u5df1\u53d1\u51fa\u7684\u3002\u63a8\u6587\u5fc5\u987b\u6309\u7167\u65f6\u95f4\u987a\u5e8f\u7531\u6700\u8fd1\u7684\u5f00\u59cb\u6392\u5e8f\u3002
    4. \n\t
    5. follow(followerId, followeeId): \u5173\u6ce8\u4e00\u4e2a\u7528\u6237
    6. \n\t
    7. unfollow(followerId, followeeId): \u53d6\u6d88\u5173\u6ce8\u4e00\u4e2a\u7528\u6237
    8. \n
    \n\n

    \u793a\u4f8b:

    \n\n
    \nTwitter twitter = new Twitter();\n\n// \u7528\u62371\u53d1\u9001\u4e86\u4e00\u6761\u65b0\u63a8\u6587 (\u7528\u6237id = 1, \u63a8\u6587id = 5).\ntwitter.postTweet(1, 5);\n\n// \u7528\u62371\u7684\u83b7\u53d6\u63a8\u6587\u5e94\u5f53\u8fd4\u56de\u4e00\u4e2a\u5217\u8868\uff0c\u5176\u4e2d\u5305\u542b\u4e00\u4e2aid\u4e3a5\u7684\u63a8\u6587.\ntwitter.getNewsFeed(1);\n\n// \u7528\u62371\u5173\u6ce8\u4e86\u7528\u62372.\ntwitter.follow(1, 2);\n\n// \u7528\u62372\u53d1\u9001\u4e86\u4e00\u4e2a\u65b0\u63a8\u6587 (\u63a8\u6587id = 6).\ntwitter.postTweet(2, 6);\n\n// \u7528\u62371\u7684\u83b7\u53d6\u63a8\u6587\u5e94\u5f53\u8fd4\u56de\u4e00\u4e2a\u5217\u8868\uff0c\u5176\u4e2d\u5305\u542b\u4e24\u4e2a\u63a8\u6587\uff0cid\u5206\u522b\u4e3a -> [6, 5].\n// \u63a8\u6587id6\u5e94\u5f53\u5728\u63a8\u6587id5\u4e4b\u524d\uff0c\u56e0\u4e3a\u5b83\u662f\u57285\u4e4b\u540e\u53d1\u9001\u7684.\ntwitter.getNewsFeed(1);\n\n// \u7528\u62371\u53d6\u6d88\u5173\u6ce8\u4e86\u7528\u62372.\ntwitter.unfollow(1, 2);\n\n// \u7528\u62371\u7684\u83b7\u53d6\u63a8\u6587\u5e94\u5f53\u8fd4\u56de\u4e00\u4e2a\u5217\u8868\uff0c\u5176\u4e2d\u5305\u542b\u4e00\u4e2aid\u4e3a5\u7684\u63a8\u6587.\n// \u56e0\u4e3a\u7528\u62371\u5df2\u7ecf\u4e0d\u518d\u5173\u6ce8\u7528\u62372.\ntwitter.getNewsFeed(1);\n
    \n", "tags_en": ["Heap", "Design", "Hash Table"], "tags_cn": ["\u5806", "\u8bbe\u8ba1", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Twitter {\npublic:\n /** Initialize your data structure here. */\n Twitter() {\n\n }\n \n /** Compose a new tweet. */\n void postTweet(int userId, int tweetId) {\n\n }\n \n /** Retrieve the 10 most recent tweet ids in the user's news feed. Each item in the news feed must be posted by users who the user followed or by the user herself. Tweets must be ordered from most recent to least recent. */\n vector getNewsFeed(int userId) {\n\n }\n \n /** Follower follows a followee. If the operation is invalid, it should be a no-op. */\n void follow(int followerId, int followeeId) {\n\n }\n \n /** Follower unfollows a followee. If the operation is invalid, it should be a no-op. */\n void unfollow(int followerId, int followeeId) {\n\n }\n};\n\n/**\n * Your Twitter object will be instantiated and called as such:\n * Twitter* obj = new Twitter();\n * obj->postTweet(userId,tweetId);\n * vector param_2 = obj->getNewsFeed(userId);\n * obj->follow(followerId,followeeId);\n * obj->unfollow(followerId,followeeId);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Twitter {\n\n /** Initialize your data structure here. */\n public Twitter() {\n\n }\n \n /** Compose a new tweet. */\n public void postTweet(int userId, int tweetId) {\n\n }\n \n /** Retrieve the 10 most recent tweet ids in the user's news feed. Each item in the news feed must be posted by users who the user followed or by the user herself. Tweets must be ordered from most recent to least recent. */\n public List getNewsFeed(int userId) {\n\n }\n \n /** Follower follows a followee. If the operation is invalid, it should be a no-op. */\n public void follow(int followerId, int followeeId) {\n\n }\n \n /** Follower unfollows a followee. If the operation is invalid, it should be a no-op. */\n public void unfollow(int followerId, int followeeId) {\n\n }\n}\n\n/**\n * Your Twitter object will be instantiated and called as such:\n * Twitter obj = new Twitter();\n * obj.postTweet(userId,tweetId);\n * List param_2 = obj.getNewsFeed(userId);\n * obj.follow(followerId,followeeId);\n * obj.unfollow(followerId,followeeId);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Twitter(object):\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def postTweet(self, userId, tweetId):\n \"\"\"\n Compose a new tweet.\n :type userId: int\n :type tweetId: int\n :rtype: None\n \"\"\"\n\n\n def getNewsFeed(self, userId):\n \"\"\"\n Retrieve the 10 most recent tweet ids in the user's news feed. Each item in the news feed must be posted by users who the user followed or by the user herself. Tweets must be ordered from most recent to least recent.\n :type userId: int\n :rtype: List[int]\n \"\"\"\n\n\n def follow(self, followerId, followeeId):\n \"\"\"\n Follower follows a followee. If the operation is invalid, it should be a no-op.\n :type followerId: int\n :type followeeId: int\n :rtype: None\n \"\"\"\n\n\n def unfollow(self, followerId, followeeId):\n \"\"\"\n Follower unfollows a followee. If the operation is invalid, it should be a no-op.\n :type followerId: int\n :type followeeId: int\n :rtype: None\n \"\"\"\n\n\n\n# Your Twitter object will be instantiated and called as such:\n# obj = Twitter()\n# obj.postTweet(userId,tweetId)\n# param_2 = obj.getNewsFeed(userId)\n# obj.follow(followerId,followeeId)\n# obj.unfollow(followerId,followeeId)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Twitter:\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def postTweet(self, userId: int, tweetId: int) -> None:\n \"\"\"\n Compose a new tweet.\n \"\"\"\n\n\n def getNewsFeed(self, userId: int) -> List[int]:\n \"\"\"\n Retrieve the 10 most recent tweet ids in the user's news feed. Each item in the news feed must be posted by users who the user followed or by the user herself. Tweets must be ordered from most recent to least recent.\n \"\"\"\n\n\n def follow(self, followerId: int, followeeId: int) -> None:\n \"\"\"\n Follower follows a followee. If the operation is invalid, it should be a no-op.\n \"\"\"\n\n\n def unfollow(self, followerId: int, followeeId: int) -> None:\n \"\"\"\n Follower unfollows a followee. If the operation is invalid, it should be a no-op.\n \"\"\"\n\n\n\n# Your Twitter object will be instantiated and called as such:\n# obj = Twitter()\n# obj.postTweet(userId,tweetId)\n# param_2 = obj.getNewsFeed(userId)\n# obj.follow(followerId,followeeId)\n# obj.unfollow(followerId,followeeId)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} Twitter;\n\n/** Initialize your data structure here. */\n\nTwitter* twitterCreate() {\n\n}\n\n/** Compose a new tweet. */\nvoid twitterPostTweet(Twitter* obj, int userId, int tweetId) {\n\n}\n\n/** Retrieve the 10 most recent tweet ids in the user's news feed. Each item in the news feed must be posted by users who the user followed or by the user herself. Tweets must be ordered from most recent to least recent. */\nint* twitterGetNewsFeed(Twitter* obj, int userId, int* retSize) {\n\n}\n\n/** Follower follows a followee. If the operation is invalid, it should be a no-op. */\nvoid twitterFollow(Twitter* obj, int followerId, int followeeId) {\n\n}\n\n/** Follower unfollows a followee. If the operation is invalid, it should be a no-op. */\nvoid twitterUnfollow(Twitter* obj, int followerId, int followeeId) {\n\n}\n\nvoid twitterFree(Twitter* obj) {\n\n}\n\n/**\n * Your Twitter struct will be instantiated and called as such:\n * Twitter* obj = twitterCreate();\n * twitterPostTweet(obj, userId, tweetId);\n \n * int* param_2 = twitterGetNewsFeed(obj, userId, retSize);\n \n * twitterFollow(obj, followerId, followeeId);\n \n * twitterUnfollow(obj, followerId, followeeId);\n \n * twitterFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Twitter {\n\n /** Initialize your data structure here. */\n public Twitter() {\n\n }\n \n /** Compose a new tweet. */\n public void PostTweet(int userId, int tweetId) {\n\n }\n \n /** Retrieve the 10 most recent tweet ids in the user's news feed. Each item in the news feed must be posted by users who the user followed or by the user herself. Tweets must be ordered from most recent to least recent. */\n public IList GetNewsFeed(int userId) {\n\n }\n \n /** Follower follows a followee. If the operation is invalid, it should be a no-op. */\n public void Follow(int followerId, int followeeId) {\n\n }\n \n /** Follower unfollows a followee. If the operation is invalid, it should be a no-op. */\n public void Unfollow(int followerId, int followeeId) {\n\n }\n}\n\n/**\n * Your Twitter object will be instantiated and called as such:\n * Twitter obj = new Twitter();\n * obj.PostTweet(userId,tweetId);\n * IList param_2 = obj.GetNewsFeed(userId);\n * obj.Follow(followerId,followeeId);\n * obj.Unfollow(followerId,followeeId);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Initialize your data structure here.\n */\nvar Twitter = function() {\n\n};\n\n/**\n * Compose a new tweet. \n * @param {number} userId \n * @param {number} tweetId\n * @return {void}\n */\nTwitter.prototype.postTweet = function(userId, tweetId) {\n\n};\n\n/**\n * Retrieve the 10 most recent tweet ids in the user's news feed. Each item in the news feed must be posted by users who the user followed or by the user herself. Tweets must be ordered from most recent to least recent. \n * @param {number} userId\n * @return {number[]}\n */\nTwitter.prototype.getNewsFeed = function(userId) {\n\n};\n\n/**\n * Follower follows a followee. If the operation is invalid, it should be a no-op. \n * @param {number} followerId \n * @param {number} followeeId\n * @return {void}\n */\nTwitter.prototype.follow = function(followerId, followeeId) {\n\n};\n\n/**\n * Follower unfollows a followee. If the operation is invalid, it should be a no-op. \n * @param {number} followerId \n * @param {number} followeeId\n * @return {void}\n */\nTwitter.prototype.unfollow = function(followerId, followeeId) {\n\n};\n\n/**\n * Your Twitter object will be instantiated and called as such:\n * var obj = new Twitter()\n * obj.postTweet(userId,tweetId)\n * var param_2 = obj.getNewsFeed(userId)\n * obj.follow(followerId,followeeId)\n * obj.unfollow(followerId,followeeId)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class Twitter\n\n=begin\n Initialize your data structure here.\n=end\n def initialize()\n\n end\n\n\n=begin\n Compose a new tweet.\n :type user_id: Integer\n :type tweet_id: Integer\n :rtype: Void\n=end\n def post_tweet(user_id, tweet_id)\n\n end\n\n\n=begin\n Retrieve the 10 most recent tweet ids in the user's news feed. Each item in the news feed must be posted by users who the user followed or by the user herself. Tweets must be ordered from most recent to least recent.\n :type user_id: Integer\n :rtype: Integer[]\n=end\n def get_news_feed(user_id)\n\n end\n\n\n=begin\n Follower follows a followee. If the operation is invalid, it should be a no-op.\n :type follower_id: Integer\n :type followee_id: Integer\n :rtype: Void\n=end\n def follow(follower_id, followee_id)\n\n end\n\n\n=begin\n Follower unfollows a followee. If the operation is invalid, it should be a no-op.\n :type follower_id: Integer\n :type followee_id: Integer\n :rtype: Void\n=end\n def unfollow(follower_id, followee_id)\n\n end\n\n\nend\n\n# Your Twitter object will be instantiated and called as such:\n# obj = Twitter.new()\n# obj.post_tweet(user_id, tweet_id)\n# param_2 = obj.get_news_feed(user_id)\n# obj.follow(follower_id, followee_id)\n# obj.unfollow(follower_id, followee_id)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass Twitter {\n\n /** Initialize your data structure here. */\n init() {\n\n }\n \n /** Compose a new tweet. */\n func postTweet(_ userId: Int, _ tweetId: Int) {\n\n }\n \n /** Retrieve the 10 most recent tweet ids in the user's news feed. Each item in the news feed must be posted by users who the user followed or by the user herself. Tweets must be ordered from most recent to least recent. */\n func getNewsFeed(_ userId: Int) -> [Int] {\n\n }\n \n /** Follower follows a followee. If the operation is invalid, it should be a no-op. */\n func follow(_ followerId: Int, _ followeeId: Int) {\n\n }\n \n /** Follower unfollows a followee. If the operation is invalid, it should be a no-op. */\n func unfollow(_ followerId: Int, _ followeeId: Int) {\n\n }\n}\n\n/**\n * Your Twitter object will be instantiated and called as such:\n * let obj = Twitter()\n * obj.postTweet(userId, tweetId)\n * let ret_2: [Int] = obj.getNewsFeed(userId)\n * obj.follow(followerId, followeeId)\n * obj.unfollow(followerId, followeeId)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type Twitter struct {\n\n}\n\n\n/** Initialize your data structure here. */\nfunc Constructor() Twitter {\n\n}\n\n\n/** Compose a new tweet. */\nfunc (this *Twitter) PostTweet(userId int, tweetId int) {\n\n}\n\n\n/** Retrieve the 10 most recent tweet ids in the user's news feed. Each item in the news feed must be posted by users who the user followed or by the user herself. Tweets must be ordered from most recent to least recent. */\nfunc (this *Twitter) GetNewsFeed(userId int) []int {\n\n}\n\n\n/** Follower follows a followee. If the operation is invalid, it should be a no-op. */\nfunc (this *Twitter) Follow(followerId int, followeeId int) {\n\n}\n\n\n/** Follower unfollows a followee. If the operation is invalid, it should be a no-op. */\nfunc (this *Twitter) Unfollow(followerId int, followeeId int) {\n\n}\n\n\n/**\n * Your Twitter object will be instantiated and called as such:\n * obj := Constructor();\n * obj.PostTweet(userId,tweetId);\n * param_2 := obj.GetNewsFeed(userId);\n * obj.Follow(followerId,followeeId);\n * obj.Unfollow(followerId,followeeId);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class Twitter() {\n\n /** Initialize your data structure here. */\n\n\n /** Compose a new tweet. */\n def postTweet(userId: Int, tweetId: Int) {\n\n }\n\n /** Retrieve the 10 most recent tweet ids in the user's news feed. Each item in the news feed must be posted by users who the user followed or by the user herself. Tweets must be ordered from most recent to least recent. */\n def getNewsFeed(userId: Int): List[Int] = {\n\n }\n\n /** Follower follows a followee. If the operation is invalid, it should be a no-op. */\n def follow(followerId: Int, followeeId: Int) {\n\n }\n\n /** Follower unfollows a followee. If the operation is invalid, it should be a no-op. */\n def unfollow(followerId: Int, followeeId: Int) {\n\n }\n\n}\n\n/**\n * Your Twitter object will be instantiated and called as such:\n * var obj = new Twitter()\n * obj.postTweet(userId,tweetId)\n * var param_2 = obj.getNewsFeed(userId)\n * obj.follow(followerId,followeeId)\n * obj.unfollow(followerId,followeeId)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Twitter() {\n\n /** Initialize your data structure here. */\n\n\n /** Compose a new tweet. */\n fun postTweet(userId: Int, tweetId: Int) {\n\n }\n\n /** Retrieve the 10 most recent tweet ids in the user's news feed. Each item in the news feed must be posted by users who the user followed or by the user herself. Tweets must be ordered from most recent to least recent. */\n fun getNewsFeed(userId: Int): List {\n\n }\n\n /** Follower follows a followee. If the operation is invalid, it should be a no-op. */\n fun follow(followerId: Int, followeeId: Int) {\n\n }\n\n /** Follower unfollows a followee. If the operation is invalid, it should be a no-op. */\n fun unfollow(followerId: Int, followeeId: Int) {\n\n }\n\n}\n\n/**\n * Your Twitter object will be instantiated and called as such:\n * var obj = Twitter()\n * obj.postTweet(userId,tweetId)\n * var param_2 = obj.getNewsFeed(userId)\n * obj.follow(followerId,followeeId)\n * obj.unfollow(followerId,followeeId)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct Twitter {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl Twitter {\n\n /** Initialize your data structure here. */\n fn new() -> Self {\n\n }\n \n /** Compose a new tweet. */\n fn post_tweet(&self, user_id: i32, tweet_id: i32) {\n\n }\n \n /** Retrieve the 10 most recent tweet ids in the user's news feed. Each item in the news feed must be posted by users who the user followed or by the user herself. Tweets must be ordered from most recent to least recent. */\n fn get_news_feed(&self, user_id: i32) -> Vec {\n\n }\n \n /** Follower follows a followee. If the operation is invalid, it should be a no-op. */\n fn follow(&self, follower_id: i32, followee_id: i32) {\n\n }\n \n /** Follower unfollows a followee. If the operation is invalid, it should be a no-op. */\n fn unfollow(&self, follower_id: i32, followee_id: i32) {\n\n }\n}\n\n/**\n * Your Twitter object will be instantiated and called as such:\n * let obj = Twitter::new();\n * obj.post_tweet(userId, tweetId);\n * let ret_2: Vec = obj.get_news_feed(userId);\n * obj.follow(followerId, followeeId);\n * obj.unfollow(followerId, followeeId);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Twitter {\n /**\n * Initialize your data structure here.\n */\n function __construct() {\n\n }\n\n /**\n * Compose a new tweet.\n * @param Integer $userId\n * @param Integer $tweetId\n * @return NULL\n */\n function postTweet($userId, $tweetId) {\n\n }\n\n /**\n * Retrieve the 10 most recent tweet ids in the user's news feed. Each item in the news feed must be posted by users who the user followed or by the user herself. Tweets must be ordered from most recent to least recent.\n * @param Integer $userId\n * @return Integer[]\n */\n function getNewsFeed($userId) {\n\n }\n\n /**\n * Follower follows a followee. If the operation is invalid, it should be a no-op.\n * @param Integer $followerId\n * @param Integer $followeeId\n * @return NULL\n */\n function follow($followerId, $followeeId) {\n\n }\n\n /**\n * Follower unfollows a followee. If the operation is invalid, it should be a no-op.\n * @param Integer $followerId\n * @param Integer $followeeId\n * @return NULL\n */\n function unfollow($followerId, $followeeId) {\n\n }\n}\n\n/**\n * Your Twitter object will be instantiated and called as such:\n * $obj = Twitter();\n * $obj->postTweet($userId, $tweetId);\n * $ret_2 = $obj->getNewsFeed($userId);\n * $obj->follow($followerId, $followeeId);\n * $obj->unfollow($followerId, $followeeId);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class Twitter {\n constructor() {\n\n }\n\n postTweet(userId: number, tweetId: number): void {\n\n }\n\n getNewsFeed(userId: number): number[] {\n\n }\n\n follow(followerId: number, followeeId: number): void {\n\n }\n\n unfollow(followerId: number, followeeId: number): void {\n\n }\n}\n\n/**\n * Your Twitter object will be instantiated and called as such:\n * var obj = new Twitter()\n * obj.postTweet(userId,tweetId)\n * var param_2 = obj.getNewsFeed(userId)\n * obj.follow(followerId,followeeId)\n * obj.unfollow(followerId,followeeId)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define twitter%\n (class object%\n (super-new)\n (init-field)\n \n ; post-tweet : exact-integer? exact-integer? -> void?\n (define/public (post-tweet userId tweetId)\n\n )\n ; get-news-feed : exact-integer? -> (listof exact-integer?)\n (define/public (get-news-feed userId)\n\n )\n ; follow : exact-integer? exact-integer? -> void?\n (define/public (follow followerId followeeId)\n\n )\n ; unfollow : exact-integer? exact-integer? -> void?\n (define/public (unfollow followerId followeeId)\n\n )))\n\n;; Your twitter% object will be instantiated and called as such:\n;; (define obj (new twitter%))\n;; (send obj post-tweet user-id tweet-id)\n;; (define param_2 (send obj get-news-feed user-id))\n;; (send obj follow follower-id followee-id)\n;; (send obj unfollow follower-id followee-id)", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0355](https://leetcode-cn.com/problems/design-twitter)", "[\u8bbe\u8ba1\u63a8\u7279](/solution/0300-0399/0355.Design%20Twitter/README.md)", "`\u5806`,`\u8bbe\u8ba1`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0355](https://leetcode.com/problems/design-twitter)", "[Design Twitter](/solution/0300-0399/0355.Design%20Twitter/README_EN.md)", "`Heap`,`Design`,`Hash Table`", "Medium", ""]}, {"question_id": "0354", "frontend_question_id": "0354", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/russian-doll-envelopes", "url_en": "https://leetcode.com/problems/russian-doll-envelopes", "relative_path_cn": "/solution/0300-0399/0354.Russian%20Doll%20Envelopes/README.md", "relative_path_en": "/solution/0300-0399/0354.Russian%20Doll%20Envelopes/README_EN.md", "title_cn": "\u4fc4\u7f57\u65af\u5957\u5a03\u4fe1\u5c01\u95ee\u9898", "title_en": "Russian Doll Envelopes", "question_title_slug": "russian-doll-envelopes", "content_en": "

    You are given a 2D array of integers envelopes where envelopes[i] = [wi, hi] represents the width and the height of an envelope.

    \n\n

    One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope's width and height.

    \n\n

    Return the maximum number of envelopes you can Russian doll (i.e., put one inside the other).

    \n\n

    Note: You cannot rotate an envelope.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: envelopes = [[5,4],[6,4],[6,7],[2,3]]\nOutput: 3\nExplanation: The maximum number of envelopes you can Russian doll is 3 ([2,3] => [5,4] => [6,7]).\n
    \n\n

    Example 2:

    \n\n
    \nInput: envelopes = [[1,1],[1,1],[1,1]]\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= envelopes.length <= 5000
    • \n\t
    • envelopes[i].length == 2
    • \n\t
    • 1 <= wi, hi <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u4e8c\u7ef4\u6574\u6570\u6570\u7ec4 envelopes \uff0c\u5176\u4e2d envelopes[i] = [wi, hi] \uff0c\u8868\u793a\u7b2c i \u4e2a\u4fe1\u5c01\u7684\u5bbd\u5ea6\u548c\u9ad8\u5ea6\u3002

    \n\n

    \u5f53\u53e6\u4e00\u4e2a\u4fe1\u5c01\u7684\u5bbd\u5ea6\u548c\u9ad8\u5ea6\u90fd\u6bd4\u8fd9\u4e2a\u4fe1\u5c01\u5927\u7684\u65f6\u5019\uff0c\u8fd9\u4e2a\u4fe1\u5c01\u5c31\u53ef\u4ee5\u653e\u8fdb\u53e6\u4e00\u4e2a\u4fe1\u5c01\u91cc\uff0c\u5982\u540c\u4fc4\u7f57\u65af\u5957\u5a03\u4e00\u6837\u3002

    \n\n

    \u8bf7\u8ba1\u7b97 \u6700\u591a\u80fd\u6709\u591a\u5c11\u4e2a \u4fe1\u5c01\u80fd\u7ec4\u6210\u4e00\u7ec4\u201c\u4fc4\u7f57\u65af\u5957\u5a03\u201d\u4fe1\u5c01\uff08\u5373\u53ef\u4ee5\u628a\u4e00\u4e2a\u4fe1\u5c01\u653e\u5230\u53e6\u4e00\u4e2a\u4fe1\u5c01\u91cc\u9762\uff09\u3002

    \n\n

    \u6ce8\u610f\uff1a\u4e0d\u5141\u8bb8\u65cb\u8f6c\u4fe1\u5c01\u3002

    \n\u00a0\n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aenvelopes = [[5,4],[6,4],[6,7],[2,3]]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u6700\u591a\u4fe1\u5c01\u7684\u4e2a\u6570\u4e3a 3, \u7ec4\u5408\u4e3a: [2,3] => [5,4] => [6,7]\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aenvelopes = [[1,1],[1,1],[1,1]]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= envelopes.length <= 5000
    • \n\t
    • envelopes[i].length == 2
    • \n\t
    • 1 <= wi, hi <= 104
    • \n
    \n", "tags_en": ["Binary Search", "Dynamic Programming"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxEnvelopes(vector>& envelopes) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxEnvelopes(int[][] envelopes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxEnvelopes(self, envelopes):\n \"\"\"\n :type envelopes: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxEnvelopes(self, envelopes: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxEnvelopes(int** envelopes, int envelopesSize, int* envelopesColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxEnvelopes(int[][] envelopes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} envelopes\n * @return {number}\n */\nvar maxEnvelopes = function(envelopes) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} envelopes\n# @return {Integer}\ndef max_envelopes(envelopes)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxEnvelopes(_ envelopes: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxEnvelopes(envelopes [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxEnvelopes(envelopes: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxEnvelopes(envelopes: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_envelopes(envelopes: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $envelopes\n * @return Integer\n */\n function maxEnvelopes($envelopes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxEnvelopes(envelopes: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-envelopes envelopes)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0354](https://leetcode-cn.com/problems/russian-doll-envelopes)", "[\u4fc4\u7f57\u65af\u5957\u5a03\u4fe1\u5c01\u95ee\u9898](/solution/0300-0399/0354.Russian%20Doll%20Envelopes/README.md)", "`\u4e8c\u5206\u67e5\u627e`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0354](https://leetcode.com/problems/russian-doll-envelopes)", "[Russian Doll Envelopes](/solution/0300-0399/0354.Russian%20Doll%20Envelopes/README_EN.md)", "`Binary Search`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0353", "frontend_question_id": "0353", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/design-snake-game", "url_en": "https://leetcode.com/problems/design-snake-game", "relative_path_cn": "/solution/0300-0399/0353.Design%20Snake%20Game/README.md", "relative_path_en": "/solution/0300-0399/0353.Design%20Snake%20Game/README_EN.md", "title_cn": "\u8d2a\u5403\u86c7", "title_en": "Design Snake Game", "question_title_slug": "design-snake-game", "content_en": "

    Design a Snake game that is played on a device with screen size height x width. Play the game online if you are not familiar with the game.

    \n\n

    The snake is initially positioned at the top left corner (0, 0) with a length of 1 unit.

    \n\n

    You are given an array food where food[i] = (ri, ci) is the row and column position of a piece of food that the snake can eat. When a snake eats a piece of food, its length and the game's score both increase by 1.

    \n\n

    Each piece of food appears one by one on the screen, meaning the second piece of food will not appear until the snake eats the first piece of food.

    \n\n

    When a piece of food appears on the screen, it is guaranteed that it will not appear on a block occupied by the snake.

    \n\n

    The game is over if the snake goes out of bounds (hits a wall) or if its head occupies a space that its body occupies after moving (i.e. a snake of length 4 cannot run into itself).

    \n\n

    Implement the SnakeGame class:

    \n\n
      \n\t
    • SnakeGame(int width, int height, int[][] food) Initializes the object with a screen of size height x width and the positions of the food.
    • \n\t
    • int move(String direction) Returns the score of the game after applying one direction move by the snake. If the game is over, return -1.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput\n["SnakeGame", "move", "move", "move", "move", "move", "move"]\n[[3, 2, [[1, 2], [0, 1]]], ["R"], ["D"], ["R"], ["U"], ["L"], ["U"]]\nOutput\n[null, 0, 0, 1, 1, 2, -1]\n\nExplanation\nSnakeGame snakeGame = new SnakeGame(3, 2, [[1, 2], [0, 1]]);\nsnakeGame.move("R"); // return 0\nsnakeGame.move("D"); // return 0\nsnakeGame.move("R"); // return 1, snake eats the first piece of food. The second piece of food appears\n                     // at (0, 1).\nsnakeGame.move("U"); // return 1\nsnakeGame.move("L"); // return 2, snake eats the second food. No more food appears.\nsnakeGame.move("U"); // return -1, game over because snake collides with border\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= width, height <= 104
    • \n\t
    • 1 <= food.length <= 50
    • \n\t
    • food[i].length == 2
    • \n\t
    • 0 <= ri < height
    • \n\t
    • 0 <= ci < width
    • \n\t
    • direction.length == 1
    • \n\t
    • direction is 'U', 'D', 'L', or 'R'.
    • \n\t
    • At most 104 calls will be made to move.
    • \n
    \n", "content_cn": "

    \u8bf7\u4f60\u8bbe\u8ba1\u4e00\u4e2a\u00a0\u8d2a\u5403\u86c7\u6e38\u620f\uff0c\u8be5\u6e38\u620f\u5c06\u4f1a\u5728\u4e00\u4e2a \u5c4f\u5e55\u5c3a\u5bf8 = \u5bbd\u5ea6 x \u9ad8\u5ea6\u00a0\u7684\u5c4f\u5e55\u4e0a\u8fd0\u884c\u3002\u5982\u679c\u4f60\u4e0d\u719f\u6089\u8fd9\u4e2a\u6e38\u620f\uff0c\u53ef\u4ee5\u00a0\u70b9\u51fb\u8fd9\u91cc\u00a0\u5728\u7ebf\u8bd5\u73a9\u3002

    \n\n

    \u8d77\u521d\u65f6\uff0c\u86c7\u5728\u5de6\u4e0a\u89d2\u7684 (0, 0) \u4f4d\u7f6e\uff0c\u8eab\u4f53\u957f\u5ea6\u4e3a 1 \u4e2a\u5355\u4f4d\u3002

    \n\n

    \u4f60\u5c06\u4f1a\u88ab\u7ed9\u51fa\u4e00\u4e2a\u6570\u7ec4\u5f62\u5f0f\u7684\u98df\u7269\u4f4d\u7f6e\u5e8f\u5217 food \uff0c\u5176\u4e2d\u00a0food[i] = (ri, ci) \u3002\u5f53\u86c7\u5403\u5230\u98df\u7269\u65f6\uff0c\u8eab\u5b50\u7684\u957f\u5ea6\u4f1a\u589e\u52a0 1 \u4e2a\u5355\u4f4d\uff0c\u5f97\u5206\u4e5f\u4f1a +1 \u3002

    \n\n

    \u98df\u7269\u4e0d\u4f1a\u540c\u65f6\u51fa\u73b0\uff0c\u4f1a\u6309\u5217\u8868\u7684\u987a\u5e8f\u9010\u4e00\u663e\u793a\u5728\u5c4f\u5e55\u4e0a\u3002\u6bd4\u65b9\u8bb2\uff0c\u7b2c\u4e00\u4e2a\u98df\u7269\u88ab\u86c7\u5403\u6389\u540e\uff0c\u7b2c\u4e8c\u4e2a\u98df\u7269\u624d\u4f1a\u51fa\u73b0\u3002

    \n\n

    \u5f53\u4e00\u4e2a\u98df\u7269\u5728\u5c4f\u5e55\u4e0a\u51fa\u73b0\u65f6\uff0c\u4fdd\u8bc1 \u4e0d\u4f1a \u51fa\u73b0\u5728\u88ab\u86c7\u8eab\u4f53\u5360\u636e\u7684\u683c\u5b50\u91cc\u3002

    \n\n

    \u5982\u679c\u86c7\u8d8a\u754c\uff08\u4e0e\u8fb9\u754c\u76f8\u649e\uff09\u6216\u8005\u5934\u4e0e \u79fb\u52a8\u540e \u7684\u8eab\u4f53\u76f8\u649e\uff08\u5373\uff0c\u8eab\u957f\u4e3a 4 \u7684\u86c7\u65e0\u6cd5\u4e0e\u81ea\u5df1\u76f8\u649e\uff09\uff0c\u6e38\u620f\u7ed3\u675f\u3002

    \n\n

    \u5b9e\u73b0 SnakeGame \u7c7b\uff1a

    \n\n
      \n\t
    • SnakeGame(int width, int height, int[][] food) \u521d\u59cb\u5316\u5bf9\u8c61\uff0c\u5c4f\u5e55\u5927\u5c0f\u4e3a height x width \uff0c\u98df\u7269\u4f4d\u7f6e\u5e8f\u5217\u4e3a food
    • \n\t
    • int move(String direction) \u8fd4\u56de\u86c7\u5728\u65b9\u5411 direction \u4e0a\u79fb\u52a8\u540e\u7684\u5f97\u5206\u3002\u5982\u679c\u6e38\u620f\u7ed3\u675f\uff0c\u8fd4\u56de -1 \u3002
    • \n
    \n\u00a0\n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1a\n[\"SnakeGame\", \"move\", \"move\", \"move\", \"move\", \"move\", \"move\"]\n[[3, 2, [[1, 2], [0, 1]]], [\"R\"], [\"D\"], [\"R\"], [\"U\"], [\"L\"], [\"U\"]]\n\u8f93\u51fa\uff1a\n[null, 0, 0, 1, 1, 2, -1]\n\n\u89e3\u91ca\uff1a\nSnakeGame snakeGame = new SnakeGame(3, 2, [[1, 2], [0, 1]]);\nsnakeGame.move(\"R\"); // \u8fd4\u56de 0\nsnakeGame.move(\"D\"); // \u8fd4\u56de 0\nsnakeGame.move(\"R\"); // \u8fd4\u56de 1 \uff0c\u86c7\u5403\u6389\u4e86\u7b2c\u4e00\u4e2a\u98df\u7269\uff0c\u540c\u65f6\u7b2c\u4e8c\u4e2a\u98df\u7269\u51fa\u73b0\u5728 (0, 1)\nsnakeGame.move(\"U\"); // \u8fd4\u56de 1\nsnakeGame.move(\"L\"); // \u8fd4\u56de 2 \uff0c\u86c7\u5403\u6389\u4e86\u7b2c\u4e8c\u4e2a\u98df\u7269\uff0c\u6ca1\u6709\u51fa\u73b0\u66f4\u591a\u98df\u7269\nsnakeGame.move(\"U\"); // \u8fd4\u56de -1 \uff0c\u86c7\u4e0e\u8fb9\u754c\u76f8\u649e\uff0c\u6e38\u620f\u7ed3\u675f\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= width, height <= 104
    • \n\t
    • 1 <= food.length <= 50
    • \n\t
    • food[i].length == 2
    • \n\t
    • 0 <= ri < height
    • \n\t
    • 0 <= ci < width
    • \n\t
    • direction.length == 1
    • \n\t
    • direction is 'U', 'D', 'L', or 'R'.
    • \n\t
    • \u6700\u591a\u8c03\u7528 104 \u6b21 move \u65b9\u6cd5
    • \n
    \n", "tags_en": ["Design", "Queue"], "tags_cn": ["\u8bbe\u8ba1", "\u961f\u5217"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class SnakeGame {\npublic:\n /** Initialize your data structure here.\n @param width - screen width\n @param height - screen height \n @param food - A list of food positions\n E.g food = [[1,1], [1,0]] means the first food is positioned at [1,1], the second is at [1,0]. */\n SnakeGame(int width, int height, vector>& food) {\n \n }\n \n /** Moves the snake.\n @param direction - 'U' = Up, 'L' = Left, 'R' = Right, 'D' = Down \n @return The game's score after the move. Return -1 if game over. \n Game over when snake crosses the screen boundary or bites its body. */\n int move(string direction) {\n \n }\n};\n\n/**\n * Your SnakeGame object will be instantiated and called as such:\n * SnakeGame* obj = new SnakeGame(width, height, food);\n * int param_1 = obj->move(direction);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class SnakeGame {\n\n /** Initialize your data structure here.\n @param width - screen width\n @param height - screen height \n @param food - A list of food positions\n E.g food = [[1,1], [1,0]] means the first food is positioned at [1,1], the second is at [1,0]. */\n public SnakeGame(int width, int height, int[][] food) {\n \n }\n \n /** Moves the snake.\n @param direction - 'U' = Up, 'L' = Left, 'R' = Right, 'D' = Down \n @return The game's score after the move. Return -1 if game over. \n Game over when snake crosses the screen boundary or bites its body. */\n public int move(String direction) {\n \n }\n}\n\n/**\n * Your SnakeGame object will be instantiated and called as such:\n * SnakeGame obj = new SnakeGame(width, height, food);\n * int param_1 = obj.move(direction);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class SnakeGame(object):\n\n def __init__(self, width, height, food):\n \"\"\"\n Initialize your data structure here.\n @param width - screen width\n @param height - screen height \n @param food - A list of food positions\n E.g food = [[1,1], [1,0]] means the first food is positioned at [1,1], the second is at [1,0].\n :type width: int\n :type height: int\n :type food: List[List[int]]\n \"\"\"\n \n\n def move(self, direction):\n \"\"\"\n Moves the snake.\n @param direction - 'U' = Up, 'L' = Left, 'R' = Right, 'D' = Down \n @return The game's score after the move. Return -1 if game over. \n Game over when snake crosses the screen boundary or bites its body.\n :type direction: str\n :rtype: int\n \"\"\"\n \n\n\n# Your SnakeGame object will be instantiated and called as such:\n# obj = SnakeGame(width, height, food)\n# param_1 = obj.move(direction)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class SnakeGame:\n\n def __init__(self, width: int, height: int, food: List[List[int]]):\n \"\"\"\n Initialize your data structure here.\n @param width - screen width\n @param height - screen height \n @param food - A list of food positions\n E.g food = [[1,1], [1,0]] means the first food is positioned at [1,1], the second is at [1,0].\n \"\"\"\n \n\n def move(self, direction: str) -> int:\n \"\"\"\n Moves the snake.\n @param direction - 'U' = Up, 'L' = Left, 'R' = Right, 'D' = Down \n @return The game's score after the move. Return -1 if game over. \n Game over when snake crosses the screen boundary or bites its body.\n \"\"\"\n \n\n\n# Your SnakeGame object will be instantiated and called as such:\n# obj = SnakeGame(width, height, food)\n# param_1 = obj.move(direction)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} SnakeGame;\n\n/** Initialize your data structure here.\n @param width - screen width\n @param height - screen height \n @param food - A list of food positions\n E.g food = [[1,1], [1,0]] means the first food is positioned at [1,1], the second is at [1,0]. */\n\nSnakeGame* snakeGameCreate(int width, int height, int** food, int foodSize, int* foodColSize) {\n \n}\n\n/** Moves the snake.\n @param direction - 'U' = Up, 'L' = Left, 'R' = Right, 'D' = Down \n @return The game's score after the move. Return -1 if game over. \n Game over when snake crosses the screen boundary or bites its body. */\nint snakeGameMove(SnakeGame* obj, char * direction) {\n \n}\n\nvoid snakeGameFree(SnakeGame* obj) {\n \n}\n\n/**\n * Your SnakeGame struct will be instantiated and called as such:\n * SnakeGame* obj = snakeGameCreate(width, height, food, foodSize, foodColSize);\n * int param_1 = snakeGameMove(obj, direction);\n \n * snakeGameFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class SnakeGame {\n\n /** Initialize your data structure here.\n @param width - screen width\n @param height - screen height \n @param food - A list of food positions\n E.g food = [[1,1], [1,0]] means the first food is positioned at [1,1], the second is at [1,0]. */\n public SnakeGame(int width, int height, int[][] food) {\n \n }\n \n /** Moves the snake.\n @param direction - 'U' = Up, 'L' = Left, 'R' = Right, 'D' = Down \n @return The game's score after the move. Return -1 if game over. \n Game over when snake crosses the screen boundary or bites its body. */\n public int Move(string direction) {\n \n }\n}\n\n/**\n * Your SnakeGame object will be instantiated and called as such:\n * SnakeGame obj = new SnakeGame(width, height, food);\n * int param_1 = obj.Move(direction);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Initialize your data structure here.\n @param width - screen width\n @param height - screen height \n @param food - A list of food positions\n E.g food = [[1,1], [1,0]] means the first food is positioned at [1,1], the second is at [1,0].\n * @param {number} width\n * @param {number} height\n * @param {number[][]} food\n */\nvar SnakeGame = function(width, height, food) {\n \n};\n\n/**\n * Moves the snake.\n @param direction - 'U' = Up, 'L' = Left, 'R' = Right, 'D' = Down \n @return The game's score after the move. Return -1 if game over. \n Game over when snake crosses the screen boundary or bites its body. \n * @param {string} direction\n * @return {number}\n */\nSnakeGame.prototype.move = function(direction) {\n \n};\n\n/** \n * Your SnakeGame object will be instantiated and called as such:\n * var obj = new SnakeGame(width, height, food)\n * var param_1 = obj.move(direction)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class SnakeGame\n\n=begin\n Initialize your data structure here.\n @param width - screen width\n @param height - screen height \n @param food - A list of food positions\n E.g food = [[1,1], [1,0]] means the first food is positioned at [1,1], the second is at [1,0].\n :type width: Integer\n :type height: Integer\n :type food: Integer[][]\n=end\n def initialize(width, height, food)\n \n end\n\n\n=begin\n Moves the snake.\n @param direction - 'U' = Up, 'L' = Left, 'R' = Right, 'D' = Down \n @return The game's score after the move. Return -1 if game over. \n Game over when snake crosses the screen boundary or bites its body.\n :type direction: String\n :rtype: Integer\n=end\n def move(direction)\n \n end\n\n\nend\n\n# Your SnakeGame object will be instantiated and called as such:\n# obj = SnakeGame.new(width, height, food)\n# param_1 = obj.move(direction)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass SnakeGame {\n\n /** Initialize your data structure here.\n @param width - screen width\n @param height - screen height \n @param food - A list of food positions\n E.g food = [[1,1], [1,0]] means the first food is positioned at [1,1], the second is at [1,0]. */\n init(_ width: Int, _ height: Int, _ food: [[Int]]) {\n \n }\n \n /** Moves the snake.\n @param direction - 'U' = Up, 'L' = Left, 'R' = Right, 'D' = Down \n @return The game's score after the move. Return -1 if game over. \n Game over when snake crosses the screen boundary or bites its body. */\n func move(_ direction: String) -> Int {\n \n }\n}\n\n/**\n * Your SnakeGame object will be instantiated and called as such:\n * let obj = SnakeGame(width, height, food)\n * let ret_1: Int = obj.move(direction)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type SnakeGame struct {\n \n}\n\n\n/** Initialize your data structure here.\n @param width - screen width\n @param height - screen height \n @param food - A list of food positions\n E.g food = [[1,1], [1,0]] means the first food is positioned at [1,1], the second is at [1,0]. */\nfunc Constructor(width int, height int, food [][]int) SnakeGame {\n \n}\n\n\n/** Moves the snake.\n @param direction - 'U' = Up, 'L' = Left, 'R' = Right, 'D' = Down \n @return The game's score after the move. Return -1 if game over. \n Game over when snake crosses the screen boundary or bites its body. */\nfunc (this *SnakeGame) Move(direction string) int {\n \n}\n\n\n/**\n * Your SnakeGame object will be instantiated and called as such:\n * obj := Constructor(width, height, food);\n * param_1 := obj.Move(direction);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class SnakeGame(_width: Int, _height: Int, _food: Array[Array[Int]]) {\n\n /** Initialize your data structure here.\n @param width - screen width\n @param height - screen height \n @param food - A list of food positions\n E.g food = [[1,1], [1,0]] means the first food is positioned at [1,1], the second is at [1,0]. */\n \n\n /** Moves the snake.\n @param direction - 'U' = Up, 'L' = Left, 'R' = Right, 'D' = Down \n @return The game's score after the move. Return -1 if game over. \n Game over when snake crosses the screen boundary or bites its body. */\n def move(direction: String): Int = {\n \n }\n\n}\n\n/**\n * Your SnakeGame object will be instantiated and called as such:\n * var obj = new SnakeGame(width, height, food)\n * var param_1 = obj.move(direction)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class SnakeGame(width: Int, height: Int, food: Array) {\n\n /** Initialize your data structure here.\n @param width - screen width\n @param height - screen height \n @param food - A list of food positions\n E.g food = [[1,1], [1,0]] means the first food is positioned at [1,1], the second is at [1,0]. */\n \n\n /** Moves the snake.\n @param direction - 'U' = Up, 'L' = Left, 'R' = Right, 'D' = Down \n @return The game's score after the move. Return -1 if game over. \n Game over when snake crosses the screen boundary or bites its body. */\n fun move(direction: String): Int {\n \n }\n\n}\n\n/**\n * Your SnakeGame object will be instantiated and called as such:\n * var obj = SnakeGame(width, height, food)\n * var param_1 = obj.move(direction)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct SnakeGame {\n\n}\n\n\n/** \n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl SnakeGame {\n\n /** Initialize your data structure here.\n @param width - screen width\n @param height - screen height \n @param food - A list of food positions\n E.g food = [[1,1], [1,0]] means the first food is positioned at [1,1], the second is at [1,0]. */\n fn new(width: i32, height: i32, food: Vec>) -> Self {\n \n }\n \n /** Moves the snake.\n @param direction - 'U' = Up, 'L' = Left, 'R' = Right, 'D' = Down \n @return The game's score after the move. Return -1 if game over. \n Game over when snake crosses the screen boundary or bites its body. */\n fn make_a_move(&self, direction: String) -> i32 {\n \n }\n}\n\n/**\n * Your SnakeGame object will be instantiated and called as such:\n * let obj = SnakeGame::new(width, height, food);\n * let ret_1: i32 = obj.make_a_move(direction);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class SnakeGame {\n /**\n * Initialize your data structure here.\n @param width - screen width\n @param height - screen height \n @param food - A list of food positions\n E.g food = [[1,1], [1,0]] means the first food is positioned at [1,1], the second is at [1,0].\n * @param Integer $width\n * @param Integer $height\n * @param Integer[][] $food\n */\n function __construct($width, $height, $food) {\n \n }\n \n /**\n * Moves the snake.\n @param direction - 'U' = Up, 'L' = Left, 'R' = Right, 'D' = Down \n @return The game's score after the move. Return -1 if game over. \n Game over when snake crosses the screen boundary or bites its body.\n * @param String $direction\n * @return Integer\n */\n function move($direction) {\n \n }\n}\n\n/**\n * Your SnakeGame object will be instantiated and called as such:\n * $obj = SnakeGame($width, $height, $food);\n * $ret_1 = $obj->move($direction);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class SnakeGame {\n /**\n * Initialize your data structure here.\n @param width - screen width\n @param height - screen height \n @param food - A list of food positions\n E.g food = [[1,1], [1,0]] means the first food is positioned at [1,1], the second is at [1,0].\n */\n constructor(width: number, height: number, food: number[][]) {\n\t\t\n }\n\n\t/**\n * Moves the snake.\n @param direction - 'U' = Up, 'L' = Left, 'R' = Right, 'D' = Down \n @return The game's score after the move. Return -1 if game over. \n Game over when snake crosses the screen boundary or bites its body. \n */\n move(direction: string): number {\n\n }\n}\n\n/**\n * Your SnakeGame object will be instantiated and called as such:\n * var obj = new SnakeGame(width, height, food)\n * var param_1 = obj.move(direction)\n */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0353](https://leetcode-cn.com/problems/design-snake-game)", "[\u8d2a\u5403\u86c7](/solution/0300-0399/0353.Design%20Snake%20Game/README.md)", "`\u8bbe\u8ba1`,`\u961f\u5217`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0353](https://leetcode.com/problems/design-snake-game)", "[Design Snake Game](/solution/0300-0399/0353.Design%20Snake%20Game/README_EN.md)", "`Design`,`Queue`", "Medium", "\ud83d\udd12"]}, {"question_id": "0352", "frontend_question_id": "0352", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/data-stream-as-disjoint-intervals", "url_en": "https://leetcode.com/problems/data-stream-as-disjoint-intervals", "relative_path_cn": "/solution/0300-0399/0352.Data%20Stream%20as%20Disjoint%20Intervals/README.md", "relative_path_en": "/solution/0300-0399/0352.Data%20Stream%20as%20Disjoint%20Intervals/README_EN.md", "title_cn": "\u5c06\u6570\u636e\u6d41\u53d8\u4e3a\u591a\u4e2a\u4e0d\u76f8\u4ea4\u533a\u95f4", "title_en": "Data Stream as Disjoint Intervals", "question_title_slug": "data-stream-as-disjoint-intervals", "content_en": "

    Given a data stream input of non-negative integers a1, a2, ..., an, summarize the numbers seen so far as a list of disjoint intervals.

    \n\n

    Implement the SummaryRanges class:

    \n\n
      \n\t
    • SummaryRanges() Initializes the object with an empty stream.
    • \n\t
    • void addNum(int val) Adds the integer val to the stream.
    • \n\t
    • int[][] getIntervals() Returns a summary of the integers in the stream currently as a list of disjoint intervals [starti, endi].
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["SummaryRanges", "addNum", "getIntervals", "addNum", "getIntervals", "addNum", "getIntervals", "addNum", "getIntervals", "addNum", "getIntervals"]\n[[], [1], [], [3], [], [7], [], [2], [], [6], []]\nOutput\n[null, null, [[1, 1]], null, [[1, 1], [3, 3]], null, [[1, 1], [3, 3], [7, 7]], null, [[1, 3], [7, 7]], null, [[1, 3], [6, 7]]]\n\nExplanation\nSummaryRanges summaryRanges = new SummaryRanges();\nsummaryRanges.addNum(1);      // arr = [1]\nsummaryRanges.getIntervals(); // return [[1, 1]]\nsummaryRanges.addNum(3);      // arr = [1, 3]\nsummaryRanges.getIntervals(); // return [[1, 1], [3, 3]]\nsummaryRanges.addNum(7);      // arr = [1, 3, 7]\nsummaryRanges.getIntervals(); // return [[1, 1], [3, 3], [7, 7]]\nsummaryRanges.addNum(2);      // arr = [1, 2, 3, 7]\nsummaryRanges.getIntervals(); // return [[1, 3], [7, 7]]\nsummaryRanges.addNum(6);      // arr = [1, 2, 3, 6, 7]\nsummaryRanges.getIntervals(); // return [[1, 3], [6, 7]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= val <= 104
    • \n\t
    • At most 3 * 104 calls will be made to addNum and getIntervals.
    • \n
    \n\n

     

    \n

    Follow up: What if there are lots of merges and the number of disjoint intervals is small compared to the size of the data stream?

    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\u7684\u6570\u636e\u6d41\u8f93\u5165 a1\uff0ca2\uff0c…\uff0can\uff0c…\uff0c\u5c06\u5230\u76ee\u524d\u4e3a\u6b62\u770b\u5230\u7684\u6570\u5b57\u603b\u7ed3\u4e3a\u4e0d\u76f8\u4ea4\u7684\u533a\u95f4\u5217\u8868\u3002

    \n\n

    \u4f8b\u5982\uff0c\u5047\u8bbe\u6570\u636e\u6d41\u4e2d\u7684\u6574\u6570\u4e3a 1\uff0c3\uff0c7\uff0c2\uff0c6\uff0c…\uff0c\u6bcf\u6b21\u7684\u603b\u7ed3\u4e3a\uff1a

    \n\n
    [1, 1]\n[1, 1], [3, 3]\n[1, 1], [3, 3], [7, 7]\n[1, 3], [7, 7]\n[1, 3], [6, 7]\n
    \n\n

     

    \n\n

    \u8fdb\u9636\uff1a
    \n\u5982\u679c\u6709\u5f88\u591a\u5408\u5e76\uff0c\u5e76\u4e14\u4e0e\u6570\u636e\u6d41\u7684\u5927\u5c0f\u76f8\u6bd4\uff0c\u4e0d\u76f8\u4ea4\u533a\u95f4\u7684\u6570\u91cf\u5f88\u5c0f\uff0c\u8be5\u600e\u4e48\u529e?

    \n\n

    \u63d0\u793a\uff1a
    \n\u7279\u522b\u611f\u8c22 @yunhong \u63d0\u4f9b\u4e86\u672c\u95ee\u9898\u548c\u5176\u6d4b\u8bd5\u7528\u4f8b\u3002

    \n", "tags_en": ["Binary Search", "Ordered Map"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class SummaryRanges {\npublic:\n /** Initialize your data structure here. */\n SummaryRanges() {\n\n }\n \n void addNum(int val) {\n\n }\n \n vector> getIntervals() {\n\n }\n};\n\n/**\n * Your SummaryRanges object will be instantiated and called as such:\n * SummaryRanges* obj = new SummaryRanges();\n * obj->addNum(val);\n * vector> param_2 = obj->getIntervals();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class SummaryRanges {\n\n /** Initialize your data structure here. */\n public SummaryRanges() {\n\n }\n \n public void addNum(int val) {\n\n }\n \n public int[][] getIntervals() {\n\n }\n}\n\n/**\n * Your SummaryRanges object will be instantiated and called as such:\n * SummaryRanges obj = new SummaryRanges();\n * obj.addNum(val);\n * int[][] param_2 = obj.getIntervals();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class SummaryRanges(object):\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def addNum(self, val):\n \"\"\"\n :type val: int\n :rtype: None\n \"\"\"\n\n\n def getIntervals(self):\n \"\"\"\n :rtype: List[List[int]]\n \"\"\"\n\n\n\n# Your SummaryRanges object will be instantiated and called as such:\n# obj = SummaryRanges()\n# obj.addNum(val)\n# param_2 = obj.getIntervals()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class SummaryRanges:\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def addNum(self, val: int) -> None:\n\n\n def getIntervals(self) -> List[List[int]]:\n\n\n\n# Your SummaryRanges object will be instantiated and called as such:\n# obj = SummaryRanges()\n# obj.addNum(val)\n# param_2 = obj.getIntervals()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} SummaryRanges;\n\n/** Initialize your data structure here. */\n\nSummaryRanges* summaryRangesCreate() {\n\n}\n\nvoid summaryRangesAddNum(SummaryRanges* obj, int val) {\n\n}\n\nint** summaryRangesGetIntervals(SummaryRanges* obj, int* retSize, int** retColSize) {\n\n}\n\nvoid summaryRangesFree(SummaryRanges* obj) {\n\n}\n\n/**\n * Your SummaryRanges struct will be instantiated and called as such:\n * SummaryRanges* obj = summaryRangesCreate();\n * summaryRangesAddNum(obj, val);\n \n * int** param_2 = summaryRangesGetIntervals(obj, retSize, retColSize);\n \n * summaryRangesFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class SummaryRanges {\n\n /** Initialize your data structure here. */\n public SummaryRanges() {\n\n }\n \n public void AddNum(int val) {\n\n }\n \n public int[][] GetIntervals() {\n\n }\n}\n\n/**\n * Your SummaryRanges object will be instantiated and called as such:\n * SummaryRanges obj = new SummaryRanges();\n * obj.AddNum(val);\n * int[][] param_2 = obj.GetIntervals();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Initialize your data structure here.\n */\nvar SummaryRanges = function() {\n\n};\n\n/** \n * @param {number} val\n * @return {void}\n */\nSummaryRanges.prototype.addNum = function(val) {\n\n};\n\n/**\n * @return {number[][]}\n */\nSummaryRanges.prototype.getIntervals = function() {\n\n};\n\n/**\n * Your SummaryRanges object will be instantiated and called as such:\n * var obj = new SummaryRanges()\n * obj.addNum(val)\n * var param_2 = obj.getIntervals()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class SummaryRanges\n\n=begin\n Initialize your data structure here.\n=end\n def initialize()\n\n end\n\n\n=begin\n :type val: Integer\n :rtype: Void\n=end\n def add_num(val)\n\n end\n\n\n=begin\n :rtype: Integer[][]\n=end\n def get_intervals()\n\n end\n\n\nend\n\n# Your SummaryRanges object will be instantiated and called as such:\n# obj = SummaryRanges.new()\n# obj.add_num(val)\n# param_2 = obj.get_intervals()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass SummaryRanges {\n\n /** Initialize your data structure here. */\n init() {\n\n }\n \n func addNum(_ val: Int) {\n\n }\n \n func getIntervals() -> [[Int]] {\n\n }\n}\n\n/**\n * Your SummaryRanges object will be instantiated and called as such:\n * let obj = SummaryRanges()\n * obj.addNum(val)\n * let ret_2: [[Int]] = obj.getIntervals()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type SummaryRanges struct {\n\n}\n\n\n/** Initialize your data structure here. */\nfunc Constructor() SummaryRanges {\n\n}\n\n\nfunc (this *SummaryRanges) AddNum(val int) {\n\n}\n\n\nfunc (this *SummaryRanges) GetIntervals() [][]int {\n\n}\n\n\n/**\n * Your SummaryRanges object will be instantiated and called as such:\n * obj := Constructor();\n * obj.AddNum(val);\n * param_2 := obj.GetIntervals();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class SummaryRanges() {\n\n /** Initialize your data structure here. */\n\n\n def addNum(`val`: Int) {\n\n }\n\n def getIntervals(): Array[Array[Int]] = {\n\n }\n\n}\n\n/**\n * Your SummaryRanges object will be instantiated and called as such:\n * var obj = new SummaryRanges()\n * obj.addNum(`val`)\n * var param_2 = obj.getIntervals()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class SummaryRanges() {\n\n /** Initialize your data structure here. */\n\n\n fun addNum(`val`: Int) {\n\n }\n\n fun getIntervals(): Array {\n\n }\n\n}\n\n/**\n * Your SummaryRanges object will be instantiated and called as such:\n * var obj = SummaryRanges()\n * obj.addNum(`val`)\n * var param_2 = obj.getIntervals()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct SummaryRanges {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl SummaryRanges {\n\n /** Initialize your data structure here. */\n fn new() -> Self {\n\n }\n \n fn add_num(&self, val: i32) {\n\n }\n \n fn get_intervals(&self) -> Vec> {\n\n }\n}\n\n/**\n * Your SummaryRanges object will be instantiated and called as such:\n * let obj = SummaryRanges::new();\n * obj.add_num(val);\n * let ret_2: Vec> = obj.get_intervals();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class SummaryRanges {\n /**\n * Initialize your data structure here.\n */\n function __construct() {\n\n }\n\n /**\n * @param Integer $val\n * @return NULL\n */\n function addNum($val) {\n\n }\n\n /**\n * @return Integer[][]\n */\n function getIntervals() {\n\n }\n}\n\n/**\n * Your SummaryRanges object will be instantiated and called as such:\n * $obj = SummaryRanges();\n * $obj->addNum($val);\n * $ret_2 = $obj->getIntervals();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class SummaryRanges {\n constructor() {\n\n }\n\n addNum(val: number): void {\n\n }\n\n getIntervals(): number[][] {\n\n }\n}\n\n/**\n * Your SummaryRanges object will be instantiated and called as such:\n * var obj = new SummaryRanges()\n * obj.addNum(val)\n * var param_2 = obj.getIntervals()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define summary-ranges%\n (class object%\n (super-new)\n (init-field)\n \n ; add-num : exact-integer? -> void?\n (define/public (add-num val)\n\n )\n ; get-intervals : -> (listof (listof exact-integer?))\n (define/public (get-intervals)\n\n )))\n\n;; Your summary-ranges% object will be instantiated and called as such:\n;; (define obj (new summary-ranges%))\n;; (send obj add-num val)\n;; (define param_2 (send obj get-intervals))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0352](https://leetcode-cn.com/problems/data-stream-as-disjoint-intervals)", "[\u5c06\u6570\u636e\u6d41\u53d8\u4e3a\u591a\u4e2a\u4e0d\u76f8\u4ea4\u533a\u95f4](/solution/0300-0399/0352.Data%20Stream%20as%20Disjoint%20Intervals/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u56f0\u96be", ""], "md_table_row_en": ["[0352](https://leetcode.com/problems/data-stream-as-disjoint-intervals)", "[Data Stream as Disjoint Intervals](/solution/0300-0399/0352.Data%20Stream%20as%20Disjoint%20Intervals/README_EN.md)", "`Binary Search`,`Ordered Map`", "Hard", ""]}, {"question_id": "0351", "frontend_question_id": "0351", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/android-unlock-patterns", "url_en": "https://leetcode.com/problems/android-unlock-patterns", "relative_path_cn": "/solution/0300-0399/0351.Android%20Unlock%20Patterns/README.md", "relative_path_en": "/solution/0300-0399/0351.Android%20Unlock%20Patterns/README_EN.md", "title_cn": "\u5b89\u5353\u7cfb\u7edf\u624b\u52bf\u89e3\u9501", "title_en": "Android Unlock Patterns", "question_title_slug": "android-unlock-patterns", "content_en": "

    Android devices have a special lock screen with a 3 x 3 grid of dots. Users can set an "unlock pattern" by connecting the dots in a specific sequence, forming a series of joined line segments where each segment's endpoints are two consecutive dots in the sequence. A sequence of k dots is a valid unlock pattern if both of the following are true:

    \n\n
      \n\t
    • All the dots in the sequence are distinct.
    • \n\t
    • If the line segment connecting two consecutive dots in the sequence passes through any other dot, the other dot must have previously appeared in the sequence. No jumps through non-selected dots are allowed.
    • \n
    \n\n

    Here are some example valid and invalid unlock patterns:

    \n\n

    \n\n
      \n\t
    • The 1st pattern [4,1,3,6] is invalid because the line connecting dots 1 and 3 pass through dot 2, but dot 2 did not previously appear in the sequence.
    • \n\t
    • The 2nd pattern [4,1,9,2] is invalid because the line connecting dots 1 and 9 pass through dot 5, but dot 5 did not previously appear in the sequence.
    • \n\t
    • The 3rd pattern [2,4,1,3,6] is valid because it follows the conditions. The line connecting dots 1 and 3 meets the condition because dot 2 previously appeared in the sequence.
    • \n\t
    • The 4th pattern [6,5,4,1,9,2] is valid because it follows the conditions. The line connecting dots 1 and 9 meets the condition because dot 5 previously appeared in the sequence.
    • \n
    \n\n

    Given two integers m and n, return the number of unique and valid unlock patterns of the Android grid lock screen that consist of at least m keys and at most n keys.

    \n\n

    Two unlock patterns are considered unique if there is a dot in one sequence that is not in the other, or the order of the dots is different.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: m = 1, n = 1\nOutput: 9\n
    \n\n

    Example 2:

    \n\n
    \nInput: m = 1, n = 2\nOutput: 65\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= m, n <= 9
    • \n
    \n", "content_cn": "

    \u6211\u4eec\u90fd\u77e5\u9053\u5b89\u5353\u6709\u4e2a\u624b\u52bf\u89e3\u9501\u7684\u754c\u9762\uff0c\u662f\u4e00\u4e2a\u00a03 x 3 \u7684\u70b9\u6240\u7ed8\u5236\u51fa\u6765\u7684\u7f51\u683c\u3002\u7528\u6237\u53ef\u4ee5\u8bbe\u7f6e\u4e00\u4e2a \u201c\u89e3\u9501\u6a21\u5f0f\u201d \uff0c\u901a\u8fc7\u8fde\u63a5\u7279\u5b9a\u5e8f\u5217\u4e2d\u7684\u70b9\uff0c\u5f62\u6210\u4e00\u7cfb\u5217\u5f7c\u6b64\u8fde\u63a5\u7684\u7ebf\u6bb5\uff0c\u6bcf\u4e2a\u7ebf\u6bb5\u7684\u7aef\u70b9\u90fd\u662f\u5e8f\u5217\u4e2d\u4e24\u4e2a\u8fde\u7eed\u7684\u70b9\u3002\u5982\u679c\u6ee1\u8db3\u4ee5\u4e0b\u4e24\u4e2a\u6761\u4ef6\uff0c\u5219 k \u70b9\u5e8f\u5217\u662f\u6709\u6548\u7684\u89e3\u9501\u6a21\u5f0f\uff1a

    \n\n
      \n\t
    • \u89e3\u9501\u6a21\u5f0f\u4e2d\u7684\u6240\u6709\u70b9 \u4e92\u4e0d\u76f8\u540c \u3002
    • \n\t
    • \u5047\u5982\u6a21\u5f0f\u4e2d\u4e24\u4e2a\u8fde\u7eed\u70b9\u7684\u7ebf\u6bb5\u9700\u8981\u7ecf\u8fc7\u5176\u4ed6\u70b9\uff0c\u90a3\u4e48\u8981\u7ecf\u8fc7\u7684\u70b9\u5fc5\u987b\u4e8b\u5148\u51fa\u73b0\u5728\u5e8f\u5217\u4e2d\uff08\u5df2\u7ecf\u7ecf\u8fc7\uff09\uff0c\u4e0d\u80fd\u8de8\u8fc7\u4efb\u4f55\u8fd8\u672a\u88ab\u7ecf\u8fc7\u7684\u70b9\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u4ee5\u4e0b\u662f\u4e00\u4e9b\u6709\u6548\u548c\u65e0\u6548\u89e3\u9501\u6a21\u5f0f\u7684\u793a\u4f8b\uff1a

    \n\n

    \n\u00a0\n\n
      \n\t
    • \u65e0\u6548\u624b\u52bf\uff1a[4,1,3,6] \uff0c\u8fde\u63a5\u70b9 1 \u548c\u70b9\u00a03 \u65f6\u7ecf\u8fc7\u4e86\u672a\u88ab\u8fde\u63a5\u8fc7\u7684\u00a02 \u53f7\u70b9\u3002
    • \n\t
    • \u65e0\u6548\u624b\u52bf\uff1a[4,1,9,2] \uff0c\u8fde\u63a5\u70b9 1 \u548c\u70b9 9 \u65f6\u7ecf\u8fc7\u4e86\u672a\u88ab\u8fde\u63a5\u8fc7\u7684 5\u00a0\u53f7\u70b9\u3002
    • \n\t
    • \u6709\u6548\u624b\u52bf\uff1a[2,4,1,3,6] \uff0c\u8fde\u63a5\u70b9 1 \u548c\u70b9\u00a03 \u662f\u6709\u6548\u7684\uff0c\u56e0\u4e3a\u867d\u7136\u5b83\u7ecf\u8fc7\u4e86\u70b9\u00a02 \uff0c\u4f46\u662f\u70b9 2 \u5728\u8be5\u624b\u52bf\u4e2d\u4e4b\u524d\u5df2\u7ecf\u88ab\u8fde\u8fc7\u4e86\u3002
    • \n\t
    • \u6709\u6548\u624b\u52bf\uff1a[6,5,4,1,9,2] \uff0c\u8fde\u63a5\u70b9 1 \u548c\u70b9\u00a09 \u662f\u6709\u6548\u7684\uff0c\u56e0\u4e3a\u867d\u7136\u5b83\u7ecf\u8fc7\u4e86\u6309\u952e 5 \uff0c\u4f46\u662f\u70b9\u00a05 \u5728\u8be5\u624b\u52bf\u4e2d\u4e4b\u524d\u5df2\u7ecf\u88ab\u8fde\u8fc7\u4e86\u3002
    • \n
    \n\n

    \u7ed9\u4f60\u4e24\u4e2a\u6574\u6570\uff0c\u5206\u522b\u4e3a \u200b\u200bm \u548c n \uff0c\u90a3\u4e48\u8bf7\u4f60\u7edf\u8ba1\u4e00\u4e0b\u6709\u591a\u5c11\u79cd \u4e0d\u540c\u4e14\u6709\u6548\u7684\u89e3\u9501\u6a21\u5f0f \uff0c\u662f \u81f3\u5c11 \u9700\u8981\u7ecf\u8fc7 m \u4e2a\u70b9\uff0c\u4f46\u662f \u4e0d\u8d85\u8fc7 n \u4e2a\u70b9\u7684\u3002

    \n\n

    \u4e24\u4e2a\u89e3\u9501\u6a21\u5f0f \u4e0d\u540c \u9700\u6ee1\u8db3\uff1a\u7ecf\u8fc7\u7684\u70b9\u4e0d\u540c\u6216\u8005\u7ecf\u8fc7\u70b9\u7684\u987a\u5e8f\u4e0d\u540c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1am = 1, n = 1\n\u8f93\u51fa\uff1a9\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1am = 1, n = 2\n\u8f93\u51fa\uff1a65\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= m, n <= 9
    • \n
    \n", "tags_en": ["Dynamic Programming", "Backtracking"], "tags_cn": ["\u52a8\u6001\u89c4\u5212", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numberOfPatterns(int m, int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numberOfPatterns(int m, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numberOfPatterns(self, m, n):\n \"\"\"\n :type m: int\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numberOfPatterns(self, m: int, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numberOfPatterns(int m, int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumberOfPatterns(int m, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} m\n * @param {number} n\n * @return {number}\n */\nvar numberOfPatterns = function(m, n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} m\n# @param {Integer} n\n# @return {Integer}\ndef number_of_patterns(m, n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numberOfPatterns(_ m: Int, _ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numberOfPatterns(m int, n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numberOfPatterns(m: Int, n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numberOfPatterns(m: Int, n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn number_of_patterns(m: i32, n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $m\n * @param Integer $n\n * @return Integer\n */\n function numberOfPatterns($m, $n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numberOfPatterns(m: number, n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (number-of-patterns m n)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0351](https://leetcode-cn.com/problems/android-unlock-patterns)", "[\u5b89\u5353\u7cfb\u7edf\u624b\u52bf\u89e3\u9501](/solution/0300-0399/0351.Android%20Unlock%20Patterns/README.md)", "`\u52a8\u6001\u89c4\u5212`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0351](https://leetcode.com/problems/android-unlock-patterns)", "[Android Unlock Patterns](/solution/0300-0399/0351.Android%20Unlock%20Patterns/README_EN.md)", "`Dynamic Programming`,`Backtracking`", "Medium", "\ud83d\udd12"]}, {"question_id": "0350", "frontend_question_id": "0350", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/intersection-of-two-arrays-ii", "url_en": "https://leetcode.com/problems/intersection-of-two-arrays-ii", "relative_path_cn": "/solution/0300-0399/0350.Intersection%20of%20Two%20Arrays%20II/README.md", "relative_path_en": "/solution/0300-0399/0350.Intersection%20of%20Two%20Arrays%20II/README_EN.md", "title_cn": "\u4e24\u4e2a\u6570\u7ec4\u7684\u4ea4\u96c6 II", "title_en": "Intersection of Two Arrays II", "question_title_slug": "intersection-of-two-arrays-ii", "content_en": "

    Given two integer arrays nums1 and nums2, return an array of their intersection. Each element in the result must appear as many times as it shows in both arrays and you may return the result in any order.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums1 = [1,2,2,1], nums2 = [2,2]\nOutput: [2,2]\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums1 = [4,9,5], nums2 = [9,4,9,8,4]\nOutput: [4,9]\nExplanation: [9,4] is also accepted.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums1.length, nums2.length <= 1000
    • \n\t
    • 0 <= nums1[i], nums2[i] <= 1000
    • \n
    \n\n

     

    \n

    Follow up:

    \n\n
      \n\t
    • What if the given array is already sorted? How would you optimize your algorithm?
    • \n\t
    • What if nums1's size is small compared to nums2's size? Which algorithm is better?
    • \n\t
    • What if elements of nums2 are stored on disk, and the memory is limited such that you cannot load all elements into the memory at once?
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u6570\u7ec4\uff0c\u7f16\u5199\u4e00\u4e2a\u51fd\u6570\u6765\u8ba1\u7b97\u5b83\u4eec\u7684\u4ea4\u96c6\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anums1 = [1,2,2,1], nums2 = [2,2]\n\u8f93\u51fa\uff1a[2,2]\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165\uff1anums1 = [4,9,5], nums2 = [9,4,9,8,4]\n\u8f93\u51fa\uff1a[4,9]
    \n\n

     

    \n\n

    \u8bf4\u660e\uff1a

    \n\n
      \n\t
    • \u8f93\u51fa\u7ed3\u679c\u4e2d\u6bcf\u4e2a\u5143\u7d20\u51fa\u73b0\u7684\u6b21\u6570\uff0c\u5e94\u4e0e\u5143\u7d20\u5728\u4e24\u4e2a\u6570\u7ec4\u4e2d\u51fa\u73b0\u6b21\u6570\u7684\u6700\u5c0f\u503c\u4e00\u81f4\u3002
    • \n\t
    • \u6211\u4eec\u53ef\u4ee5\u4e0d\u8003\u8651\u8f93\u51fa\u7ed3\u679c\u7684\u987a\u5e8f\u3002
    • \n
    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u5982\u679c\u7ed9\u5b9a\u7684\u6570\u7ec4\u5df2\u7ecf\u6392\u597d\u5e8f\u5462\uff1f\u4f60\u5c06\u5982\u4f55\u4f18\u5316\u4f60\u7684\u7b97\u6cd5\uff1f
    • \n\t
    • \u5982\u679c nums1 \u7684\u5927\u5c0f\u6bd4 nums2 \u5c0f\u5f88\u591a\uff0c\u54ea\u79cd\u65b9\u6cd5\u66f4\u4f18\uff1f
    • \n\t
    • \u5982\u679c nums2 \u7684\u5143\u7d20\u5b58\u50a8\u5728\u78c1\u76d8\u4e0a\uff0c\u5185\u5b58\u662f\u6709\u9650\u7684\uff0c\u5e76\u4e14\u4f60\u4e0d\u80fd\u4e00\u6b21\u52a0\u8f7d\u6240\u6709\u7684\u5143\u7d20\u5230\u5185\u5b58\u4e2d\uff0c\u4f60\u8be5\u600e\u4e48\u529e\uff1f
    • \n
    \n", "tags_en": ["Sort", "Hash Table", "Two Pointers", "Binary Search"], "tags_cn": ["\u6392\u5e8f", "\u54c8\u5e0c\u8868", "\u53cc\u6307\u9488", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector intersect(vector& nums1, vector& nums2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] intersect(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def intersect(self, nums1, nums2):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def intersect(self, nums1: List[int], nums2: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* intersect(int* nums1, int nums1Size, int* nums2, int nums2Size, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] Intersect(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums1\n * @param {number[]} nums2\n * @return {number[]}\n */\nvar intersect = function(nums1, nums2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums1\n# @param {Integer[]} nums2\n# @return {Integer[]}\ndef intersect(nums1, nums2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func intersect(_ nums1: [Int], _ nums2: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func intersect(nums1 []int, nums2 []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def intersect(nums1: Array[Int], nums2: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun intersect(nums1: IntArray, nums2: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn intersect(nums1: Vec, nums2: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums1\n * @param Integer[] $nums2\n * @return Integer[]\n */\n function intersect($nums1, $nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function intersect(nums1: number[], nums2: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (intersect nums1 nums2)\n (-> (listof exact-integer?) (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0350](https://leetcode-cn.com/problems/intersection-of-two-arrays-ii)", "[\u4e24\u4e2a\u6570\u7ec4\u7684\u4ea4\u96c6 II](/solution/0300-0399/0350.Intersection%20of%20Two%20Arrays%20II/README.md)", "`\u6392\u5e8f`,`\u54c8\u5e0c\u8868`,`\u53cc\u6307\u9488`,`\u4e8c\u5206\u67e5\u627e`", "\u7b80\u5355", ""], "md_table_row_en": ["[0350](https://leetcode.com/problems/intersection-of-two-arrays-ii)", "[Intersection of Two Arrays II](/solution/0300-0399/0350.Intersection%20of%20Two%20Arrays%20II/README_EN.md)", "`Sort`,`Hash Table`,`Two Pointers`,`Binary Search`", "Easy", ""]}, {"question_id": "0349", "frontend_question_id": "0349", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/intersection-of-two-arrays", "url_en": "https://leetcode.com/problems/intersection-of-two-arrays", "relative_path_cn": "/solution/0300-0399/0349.Intersection%20of%20Two%20Arrays/README.md", "relative_path_en": "/solution/0300-0399/0349.Intersection%20of%20Two%20Arrays/README_EN.md", "title_cn": "\u4e24\u4e2a\u6570\u7ec4\u7684\u4ea4\u96c6", "title_en": "Intersection of Two Arrays", "question_title_slug": "intersection-of-two-arrays", "content_en": "

    Given two integer arrays nums1 and nums2, return an array of their intersection. Each element in the result must be unique and you may return the result in any order.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums1 = [1,2,2,1], nums2 = [2,2]\nOutput: [2]\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums1 = [4,9,5], nums2 = [9,4,9,8,4]\nOutput: [9,4]\nExplanation: [4,9] is also accepted.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums1.length, nums2.length <= 1000
    • \n\t
    • 0 <= nums1[i], nums2[i] <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u6570\u7ec4\uff0c\u7f16\u5199\u4e00\u4e2a\u51fd\u6570\u6765\u8ba1\u7b97\u5b83\u4eec\u7684\u4ea4\u96c6\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1anums1 = [1,2,2,1], nums2 = [2,2]\n\u8f93\u51fa\uff1a[2]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1anums1 = [4,9,5], nums2 = [9,4,9,8,4]\n\u8f93\u51fa\uff1a[9,4]
    \n\n

     

    \n\n

    \u8bf4\u660e\uff1a

    \n\n
      \n\t
    • \u8f93\u51fa\u7ed3\u679c\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u4e00\u5b9a\u662f\u552f\u4e00\u7684\u3002
    • \n\t
    • \u6211\u4eec\u53ef\u4ee5\u4e0d\u8003\u8651\u8f93\u51fa\u7ed3\u679c\u7684\u987a\u5e8f\u3002
    • \n
    \n", "tags_en": ["Sort", "Hash Table", "Two Pointers", "Binary Search"], "tags_cn": ["\u6392\u5e8f", "\u54c8\u5e0c\u8868", "\u53cc\u6307\u9488", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector intersection(vector& nums1, vector& nums2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] intersection(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def intersection(self, nums1, nums2):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def intersection(self, nums1: List[int], nums2: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* intersection(int* nums1, int nums1Size, int* nums2, int nums2Size, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] Intersection(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums1\n * @param {number[]} nums2\n * @return {number[]}\n */\nvar intersection = function(nums1, nums2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums1\n# @param {Integer[]} nums2\n# @return {Integer[]}\ndef intersection(nums1, nums2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func intersection(_ nums1: [Int], _ nums2: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func intersection(nums1 []int, nums2 []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def intersection(nums1: Array[Int], nums2: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun intersection(nums1: IntArray, nums2: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn intersection(nums1: Vec, nums2: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums1\n * @param Integer[] $nums2\n * @return Integer[]\n */\n function intersection($nums1, $nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function intersection(nums1: number[], nums2: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (intersection nums1 nums2)\n (-> (listof exact-integer?) (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0349](https://leetcode-cn.com/problems/intersection-of-two-arrays)", "[\u4e24\u4e2a\u6570\u7ec4\u7684\u4ea4\u96c6](/solution/0300-0399/0349.Intersection%20of%20Two%20Arrays/README.md)", "`\u6392\u5e8f`,`\u54c8\u5e0c\u8868`,`\u53cc\u6307\u9488`,`\u4e8c\u5206\u67e5\u627e`", "\u7b80\u5355", ""], "md_table_row_en": ["[0349](https://leetcode.com/problems/intersection-of-two-arrays)", "[Intersection of Two Arrays](/solution/0300-0399/0349.Intersection%20of%20Two%20Arrays/README_EN.md)", "`Sort`,`Hash Table`,`Two Pointers`,`Binary Search`", "Easy", ""]}, {"question_id": "0348", "frontend_question_id": "0348", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/design-tic-tac-toe", "url_en": "https://leetcode.com/problems/design-tic-tac-toe", "relative_path_cn": "/solution/0300-0399/0348.Design%20Tic-Tac-Toe/README.md", "relative_path_en": "/solution/0300-0399/0348.Design%20Tic-Tac-Toe/README_EN.md", "title_cn": "\u8bbe\u8ba1\u4e95\u5b57\u68cb", "title_en": "Design Tic-Tac-Toe", "question_title_slug": "design-tic-tac-toe", "content_en": "

    Assume the following rules are for the tic-tac-toe game on an n x n board between two players:

    \n\n
      \n\t
    1. A move is guaranteed to be valid and is placed on an empty block.
    2. \n\t
    3. Once a winning condition is reached, no more moves are allowed.
    4. \n\t
    5. A player who succeeds in placing n of their marks in a horizontal, vertical, or diagonal row wins the game.
    6. \n
    \n\n

    Implement the TicTacToe class:

    \n\n
      \n\t
    • TicTacToe(int n) Initializes the object the size of the board n.
    • \n\t
    • int move(int row, int col, int player) Indicates that player with id player plays at the cell (row, col) of the board. The move is guaranteed to be a valid move.
    • \n
    \n\n

    Follow up:
    \nCould you do better than O(n2) per move() operation?

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["TicTacToe", "move", "move", "move", "move", "move", "move", "move"]\n[[3], [0, 0, 1], [0, 2, 2], [2, 2, 1], [1, 1, 2], [2, 0, 1], [1, 0, 2], [2, 1, 1]]\nOutput\n[null, 0, 0, 0, 0, 0, 0, 1]\n\nExplanation\nTicTacToe ticTacToe = new TicTacToe(3);\nAssume that player 1 is "X" and player 2 is "O" in the board.\nticTacToe.move(0, 0, 1); // return 0 (no one wins)\n|X| | |\n| | | |    // Player 1 makes a move at (0, 0).\n| | | |\n\nticTacToe.move(0, 2, 2); // return 0 (no one wins)\n|X| |O|\n| | | |    // Player 2 makes a move at (0, 2).\n| | | |\n\nticTacToe.move(2, 2, 1); // return 0 (no one wins)\n|X| |O|\n| | | |    // Player 1 makes a move at (2, 2).\n| | |X|\n\nticTacToe.move(1, 1, 2); // return 0 (no one wins)\n|X| |O|\n| |O| |    // Player 2 makes a move at (1, 1).\n| | |X|\n\nticTacToe.move(2, 0, 1); // return 0 (no one wins)\n|X| |O|\n| |O| |    // Player 1 makes a move at (2, 0).\n|X| |X|\n\nticTacToe.move(1, 0, 2); // return 0 (no one wins)\n|X| |O|\n|O|O| |    // Player 2 makes a move at (1, 0).\n|X| |X|\n\nticTacToe.move(2, 1, 1); // return 1 (player 1 wins)\n|X| |O|\n|O|O| |    // Player 1 makes a move at (2, 1).\n|X|X|X|\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= n <= 100
    • \n\t
    • player is 1 or 2.
    • \n\t
    • 0 <= row, col < n
    • \n\t
    • (row, col) are unique for each different call to move.
    • \n\t
    • At most n2 calls will be made to move.
    • \n
    \n", "content_cn": "

    \u8bf7\u5728 n × n \u7684\u68cb\u76d8\u4e0a\uff0c\u5b9e\u73b0\u4e00\u4e2a\u5224\u5b9a\u4e95\u5b57\u68cb\uff08Tic-Tac-Toe\uff09\u80dc\u8d1f\u7684\u795e\u5668\uff0c\u5224\u65ad\u6bcf\u4e00\u6b21\u73a9\u5bb6\u843d\u5b50\u540e\uff0c\u662f\u5426\u6709\u80dc\u51fa\u7684\u73a9\u5bb6\u3002

    \n\n

    \u5728\u8fd9\u4e2a\u4e95\u5b57\u68cb\u6e38\u620f\u4e2d\uff0c\u4f1a\u6709 2 \u540d\u73a9\u5bb6\uff0c\u4ed6\u4eec\u5c06\u8f6e\u6d41\u5728\u68cb\u76d8\u4e0a\u653e\u7f6e\u81ea\u5df1\u7684\u68cb\u5b50\u3002

    \n\n

    \u5728\u5b9e\u73b0\u8fd9\u4e2a\u5224\u5b9a\u5668\u7684\u8fc7\u7a0b\u4e2d\uff0c\u4f60\u53ef\u4ee5\u5047\u8bbe\u4ee5\u4e0b\u8fd9\u4e9b\u89c4\u5219\u4e00\u5b9a\u6210\u7acb\uff1a

    \n\n

          1. \u6bcf\u4e00\u6b65\u68cb\u90fd\u662f\u5728\u68cb\u76d8\u5185\u7684\uff0c\u5e76\u4e14\u53ea\u80fd\u88ab\u653e\u7f6e\u5728\u4e00\u4e2a\u7a7a\u7684\u683c\u5b50\u91cc\uff1b

    \n\n

          2. \u4e00\u65e6\u6e38\u620f\u4e2d\u6709\u4e00\u540d\u73a9\u5bb6\u80dc\u51fa\u7684\u8bdd\uff0c\u6e38\u620f\u5c06\u4e0d\u80fd\u518d\u7ee7\u7eed\uff1b

    \n\n

          3. \u4e00\u4e2a\u73a9\u5bb6\u5982\u679c\u5728\u540c\u4e00\u884c\u3001\u540c\u4e00\u5217\u6216\u8005\u540c\u4e00\u659c\u5bf9\u89d2\u7ebf\u4e0a\u90fd\u653e\u7f6e\u4e86\u81ea\u5df1\u7684\u68cb\u5b50\uff0c\u90a3\u4e48\u4ed6\u4fbf\u83b7\u5f97\u80dc\u5229\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u7ed9\u5b9a\u68cb\u76d8\u8fb9\u957f n = 3, \u73a9\u5bb6 1 \u7684\u68cb\u5b50\u7b26\u53f7\u662f "X"\uff0c\u73a9\u5bb6 2 \u7684\u68cb\u5b50\u7b26\u53f7\u662f "O"\u3002\n\nTicTacToe toe = new TicTacToe(3);\n\ntoe.move(0, 0, 1); -> \u51fd\u6570\u8fd4\u56de 0 (\u6b64\u65f6\uff0c\u6682\u65f6\u6ca1\u6709\u73a9\u5bb6\u8d62\u5f97\u8fd9\u573a\u5bf9\u51b3)\n|X| | |\n| | | |    // \u73a9\u5bb6 1 \u5728 (0, 0) \u843d\u5b50\u3002\n| | | |\n\ntoe.move(0, 2, 2); -> \u51fd\u6570\u8fd4\u56de 0 (\u6682\u65f6\u6ca1\u6709\u73a9\u5bb6\u8d62\u5f97\u672c\u573a\u6bd4\u8d5b)\n|X| |O|\n| | | |    // \u73a9\u5bb6 2 \u5728 (0, 2) \u843d\u5b50\u3002\n| | | |\n\ntoe.move(2, 2, 1); -> \u51fd\u6570\u8fd4\u56de 0 (\u6682\u65f6\u6ca1\u6709\u73a9\u5bb6\u8d62\u5f97\u6bd4\u8d5b)\n|X| |O|\n| | | |    // \u73a9\u5bb6 1 \u5728 (2, 2) \u843d\u5b50\u3002\n| | |X|\n\ntoe.move(1, 1, 2); -> \u51fd\u6570\u8fd4\u56de 0 (\u6682\u6ca1\u6709\u73a9\u5bb6\u8d62\u5f97\u6bd4\u8d5b)\n|X| |O|\n| |O| |    // \u73a9\u5bb6 2 \u5728 (1, 1) \u843d\u5b50\u3002\n| | |X|\n\ntoe.move(2, 0, 1); -> \u51fd\u6570\u8fd4\u56de 0 (\u6682\u65e0\u73a9\u5bb6\u8d62\u5f97\u6bd4\u8d5b)\n|X| |O|\n| |O| |    // \u73a9\u5bb6 1 \u5728 (2, 0) \u843d\u5b50\u3002\n|X| |X|\n\ntoe.move(1, 0, 2); -> \u51fd\u6570\u8fd4\u56de 0 (\u6ca1\u6709\u73a9\u5bb6\u8d62\u5f97\u6bd4\u8d5b)\n|X| |O|\n|O|O| |    // \u73a9\u5bb6 2 \u5728 (1, 0) \u843d\u5b50.\n|X| |X|\n\ntoe.move(2, 1, 1); -> \u51fd\u6570\u8fd4\u56de 1 (\u6b64\u65f6\uff0c\u73a9\u5bb6 1 \u8d62\u5f97\u4e86\u8be5\u573a\u6bd4\u8d5b)\n|X| |O|\n|O|O| |    // \u73a9\u5bb6 1 \u5728 (2, 1) \u843d\u5b50\u3002\n|X|X|X|\n
    \n\n

     

    \n\n

    \u8fdb\u9636:
    \n\u60a8\u6709\u6ca1\u6709\u53ef\u80fd\u5c06\u6bcf\u4e00\u6b65\u7684 move() \u64cd\u4f5c\u4f18\u5316\u5230\u6bd4 O(n2) \u66f4\u5feb\u5417?

    \n", "tags_en": ["Design"], "tags_cn": ["\u8bbe\u8ba1"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class TicTacToe {\npublic:\n /** Initialize your data structure here. */\n TicTacToe(int n) {\n \n }\n \n /** Player {player} makes a move at ({row}, {col}).\n @param row The row of the board.\n @param col The column of the board.\n @param player The player, can be either 1 or 2.\n @return The current winning condition, can be either:\n 0: No one wins.\n 1: Player 1 wins.\n 2: Player 2 wins. */\n int move(int row, int col, int player) {\n \n }\n};\n\n/**\n * Your TicTacToe object will be instantiated and called as such:\n * TicTacToe* obj = new TicTacToe(n);\n * int param_1 = obj->move(row,col,player);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class TicTacToe {\n\n /** Initialize your data structure here. */\n public TicTacToe(int n) {\n \n }\n \n /** Player {player} makes a move at ({row}, {col}).\n @param row The row of the board.\n @param col The column of the board.\n @param player The player, can be either 1 or 2.\n @return The current winning condition, can be either:\n 0: No one wins.\n 1: Player 1 wins.\n 2: Player 2 wins. */\n public int move(int row, int col, int player) {\n \n }\n}\n\n/**\n * Your TicTacToe object will be instantiated and called as such:\n * TicTacToe obj = new TicTacToe(n);\n * int param_1 = obj.move(row,col,player);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class TicTacToe(object):\n\n def __init__(self, n):\n \"\"\"\n Initialize your data structure here.\n :type n: int\n \"\"\"\n \n\n def move(self, row, col, player):\n \"\"\"\n Player {player} makes a move at ({row}, {col}).\n @param row The row of the board.\n @param col The column of the board.\n @param player The player, can be either 1 or 2.\n @return The current winning condition, can be either:\n 0: No one wins.\n 1: Player 1 wins.\n 2: Player 2 wins.\n :type row: int\n :type col: int\n :type player: int\n :rtype: int\n \"\"\"\n \n\n\n# Your TicTacToe object will be instantiated and called as such:\n# obj = TicTacToe(n)\n# param_1 = obj.move(row,col,player)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class TicTacToe:\n\n def __init__(self, n: int):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n \n\n def move(self, row: int, col: int, player: int) -> int:\n \"\"\"\n Player {player} makes a move at ({row}, {col}).\n @param row The row of the board.\n @param col The column of the board.\n @param player The player, can be either 1 or 2.\n @return The current winning condition, can be either:\n 0: No one wins.\n 1: Player 1 wins.\n 2: Player 2 wins.\n \"\"\"\n \n\n\n# Your TicTacToe object will be instantiated and called as such:\n# obj = TicTacToe(n)\n# param_1 = obj.move(row,col,player)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} TicTacToe;\n\n/** Initialize your data structure here. */\n\nTicTacToe* ticTacToeCreate(int n) {\n \n}\n\n/** Player {player} makes a move at ({row}, {col}).\n @param row The row of the board.\n @param col The column of the board.\n @param player The player, can be either 1 or 2.\n @return The current winning condition, can be either:\n 0: No one wins.\n 1: Player 1 wins.\n 2: Player 2 wins. */\nint ticTacToeMove(TicTacToe* obj, int row, int col, int player) {\n \n}\n\nvoid ticTacToeFree(TicTacToe* obj) {\n \n}\n\n/**\n * Your TicTacToe struct will be instantiated and called as such:\n * TicTacToe* obj = ticTacToeCreate(n);\n * int param_1 = ticTacToeMove(obj, row, col, player);\n \n * ticTacToeFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class TicTacToe {\n\n /** Initialize your data structure here. */\n public TicTacToe(int n) {\n \n }\n \n /** Player {player} makes a move at ({row}, {col}).\n @param row The row of the board.\n @param col The column of the board.\n @param player The player, can be either 1 or 2.\n @return The current winning condition, can be either:\n 0: No one wins.\n 1: Player 1 wins.\n 2: Player 2 wins. */\n public int Move(int row, int col, int player) {\n \n }\n}\n\n/**\n * Your TicTacToe object will be instantiated and called as such:\n * TicTacToe obj = new TicTacToe(n);\n * int param_1 = obj.Move(row,col,player);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Initialize your data structure here.\n * @param {number} n\n */\nvar TicTacToe = function(n) {\n \n};\n\n/**\n * Player {player} makes a move at ({row}, {col}).\n @param row The row of the board.\n @param col The column of the board.\n @param player The player, can be either 1 or 2.\n @return The current winning condition, can be either:\n 0: No one wins.\n 1: Player 1 wins.\n 2: Player 2 wins. \n * @param {number} row \n * @param {number} col \n * @param {number} player\n * @return {number}\n */\nTicTacToe.prototype.move = function(row, col, player) {\n \n};\n\n/** \n * Your TicTacToe object will be instantiated and called as such:\n * var obj = new TicTacToe(n)\n * var param_1 = obj.move(row,col,player)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class TicTacToe\n\n=begin\n Initialize your data structure here.\n :type n: Integer\n=end\n def initialize(n)\n \n end\n\n\n=begin\n Player {player} makes a move at ({row}, {col}).\n @param row The row of the board.\n @param col The column of the board.\n @param player The player, can be either 1 or 2.\n @return The current winning condition, can be either:\n 0: No one wins.\n 1: Player 1 wins.\n 2: Player 2 wins.\n :type row: Integer\n :type col: Integer\n :type player: Integer\n :rtype: Integer\n=end\n def move(row, col, player)\n \n end\n\n\nend\n\n# Your TicTacToe object will be instantiated and called as such:\n# obj = TicTacToe.new(n)\n# param_1 = obj.move(row, col, player)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass TicTacToe {\n\n /** Initialize your data structure here. */\n init(_ n: Int) {\n \n }\n \n /** Player {player} makes a move at ({row}, {col}).\n @param row The row of the board.\n @param col The column of the board.\n @param player The player, can be either 1 or 2.\n @return The current winning condition, can be either:\n 0: No one wins.\n 1: Player 1 wins.\n 2: Player 2 wins. */\n func move(_ row: Int, _ col: Int, _ player: Int) -> Int {\n \n }\n}\n\n/**\n * Your TicTacToe object will be instantiated and called as such:\n * let obj = TicTacToe(n)\n * let ret_1: Int = obj.move(row, col, player)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type TicTacToe struct {\n \n}\n\n\n/** Initialize your data structure here. */\nfunc Constructor(n int) TicTacToe {\n \n}\n\n\n/** Player {player} makes a move at ({row}, {col}).\n @param row The row of the board.\n @param col The column of the board.\n @param player The player, can be either 1 or 2.\n @return The current winning condition, can be either:\n 0: No one wins.\n 1: Player 1 wins.\n 2: Player 2 wins. */\nfunc (this *TicTacToe) Move(row int, col int, player int) int {\n \n}\n\n\n/**\n * Your TicTacToe object will be instantiated and called as such:\n * obj := Constructor(n);\n * param_1 := obj.Move(row,col,player);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class TicTacToe(_n: Int) {\n\n /** Initialize your data structure here. */\n \n\n /** Player {player} makes a move at ({row}, {col}).\n @param row The row of the board.\n @param col The column of the board.\n @param player The player, can be either 1 or 2.\n @return The current winning condition, can be either:\n 0: No one wins.\n 1: Player 1 wins.\n 2: Player 2 wins. */\n def move(row: Int, col: Int, player: Int): Int = {\n \n }\n\n}\n\n/**\n * Your TicTacToe object will be instantiated and called as such:\n * var obj = new TicTacToe(n)\n * var param_1 = obj.move(row,col,player)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class TicTacToe(n: Int) {\n\n /** Initialize your data structure here. */\n \n\n /** Player {player} makes a move at ({row}, {col}).\n @param row The row of the board.\n @param col The column of the board.\n @param player The player, can be either 1 or 2.\n @return The current winning condition, can be either:\n 0: No one wins.\n 1: Player 1 wins.\n 2: Player 2 wins. */\n fun move(row: Int, col: Int, player: Int): Int {\n \n }\n\n}\n\n/**\n * Your TicTacToe object will be instantiated and called as such:\n * var obj = TicTacToe(n)\n * var param_1 = obj.move(row,col,player)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct TicTacToe {\n\n}\n\n\n/** \n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl TicTacToe {\n\n /** Initialize your data structure here. */\n fn new(n: i32) -> Self {\n \n }\n \n /** Player {player} makes a move at ({row}, {col}).\n @param row The row of the board.\n @param col The column of the board.\n @param player The player, can be either 1 or 2.\n @return The current winning condition, can be either:\n 0: No one wins.\n 1: Player 1 wins.\n 2: Player 2 wins. */\n fn make_a_move(&self, row: i32, col: i32, player: i32) -> i32 {\n \n }\n}\n\n/**\n * Your TicTacToe object will be instantiated and called as such:\n * let obj = TicTacToe::new(n);\n * let ret_1: i32 = obj.make_a_move(row, col, player);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class TicTacToe {\n /**\n * Initialize your data structure here.\n * @param Integer $n\n */\n function __construct($n) {\n \n }\n \n /**\n * Player {player} makes a move at ({row}, {col}).\n @param row The row of the board.\n @param col The column of the board.\n @param player The player, can be either 1 or 2.\n @return The current winning condition, can be either:\n 0: No one wins.\n 1: Player 1 wins.\n 2: Player 2 wins.\n * @param Integer $row\n * @param Integer $col\n * @param Integer $player\n * @return Integer\n */\n function move($row, $col, $player) {\n \n }\n}\n\n/**\n * Your TicTacToe object will be instantiated and called as such:\n * $obj = TicTacToe($n);\n * $ret_1 = $obj->move($row, $col, $player);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class TicTacToe {\n /**\n * Initialize your data structure here.\n */\n constructor(n: number) {\n\t\t\n }\n\t\n /**\n * Player {player} makes a move at ({row}, {col}).\n @param row The row of the board.\n @param col The column of the board.\n @param player The player, can be either 1 or 2.\n @return The current winning condition, can be either:\n 0: No one wins.\n 1: Player 1 wins.\n 2: Player 2 wins. \n */\n move(row: number, col: number, player: number): number {\n\t\t\n }\n}\n\n/**\n * Your TicTacToe object will be instantiated and called as such:\n * var obj = new TicTacToe(n)\n * var param_1 = obj.move(row,col,player)\n */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0348](https://leetcode-cn.com/problems/design-tic-tac-toe)", "[\u8bbe\u8ba1\u4e95\u5b57\u68cb](/solution/0300-0399/0348.Design%20Tic-Tac-Toe/README.md)", "`\u8bbe\u8ba1`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0348](https://leetcode.com/problems/design-tic-tac-toe)", "[Design Tic-Tac-Toe](/solution/0300-0399/0348.Design%20Tic-Tac-Toe/README_EN.md)", "`Design`", "Medium", "\ud83d\udd12"]}, {"question_id": "0347", "frontend_question_id": "0347", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/top-k-frequent-elements", "url_en": "https://leetcode.com/problems/top-k-frequent-elements", "relative_path_cn": "/solution/0300-0399/0347.Top%20K%20Frequent%20Elements/README.md", "relative_path_en": "/solution/0300-0399/0347.Top%20K%20Frequent%20Elements/README_EN.md", "title_cn": "\u524d K \u4e2a\u9ad8\u9891\u5143\u7d20", "title_en": "Top K Frequent Elements", "question_title_slug": "top-k-frequent-elements", "content_en": "

    Given an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any order.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [1,1,1,2,2,3], k = 2\nOutput: [1,2]\n

    Example 2:

    \n
    Input: nums = [1], k = 1\nOutput: [1]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • k is in the range [1, the number of unique elements in the array].
    • \n\t
    • It is guaranteed that the answer is unique.
    • \n
    \n\n

     

    \n

    Follow up: Your algorithm's time complexity must be better than O(n log n), where n is the array's size.

    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \u548c\u4e00\u4e2a\u6574\u6570 k \uff0c\u8bf7\u4f60\u8fd4\u56de\u5176\u4e2d\u51fa\u73b0\u9891\u7387\u524d k \u9ad8\u7684\u5143\u7d20\u3002\u4f60\u53ef\u4ee5\u6309 \u4efb\u610f\u987a\u5e8f \u8fd4\u56de\u7b54\u6848\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: nums = [1,1,1,2,2,3], k = 2\n\u8f93\u51fa: [1,2]\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: nums = [1], k = 1\n\u8f93\u51fa: [1]
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • k \u7684\u53d6\u503c\u8303\u56f4\u662f [1, \u6570\u7ec4\u4e2d\u4e0d\u76f8\u540c\u7684\u5143\u7d20\u7684\u4e2a\u6570]
    • \n\t
    • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u7b54\u6848\u552f\u4e00\uff0c\u6362\u53e5\u8bdd\u8bf4\uff0c\u6570\u7ec4\u4e2d\u524d k \u4e2a\u9ad8\u9891\u5143\u7d20\u7684\u96c6\u5408\u662f\u552f\u4e00\u7684
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u6240\u8bbe\u8ba1\u7b97\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6 \u5fc5\u987b \u4f18\u4e8e O(n log n) \uff0c\u5176\u4e2d n\u00a0\u662f\u6570\u7ec4\u5927\u5c0f\u3002

    \n", "tags_en": ["Heap", "Hash Table"], "tags_cn": ["\u5806", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector topKFrequent(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] topKFrequent(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def topKFrequent(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def topKFrequent(self, nums: List[int], k: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* topKFrequent(int* nums, int numsSize, int k, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] TopKFrequent(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number[]}\n */\nvar topKFrequent = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer[]}\ndef top_k_frequent(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func topKFrequent(_ nums: [Int], _ k: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func topKFrequent(nums []int, k int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def topKFrequent(nums: Array[Int], k: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun topKFrequent(nums: IntArray, k: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn top_k_frequent(nums: Vec, k: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer[]\n */\n function topKFrequent($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function topKFrequent(nums: number[], k: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (top-k-frequent nums k)\n (-> (listof exact-integer?) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0347](https://leetcode-cn.com/problems/top-k-frequent-elements)", "[\u524d K \u4e2a\u9ad8\u9891\u5143\u7d20](/solution/0300-0399/0347.Top%20K%20Frequent%20Elements/README.md)", "`\u5806`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0347](https://leetcode.com/problems/top-k-frequent-elements)", "[Top K Frequent Elements](/solution/0300-0399/0347.Top%20K%20Frequent%20Elements/README_EN.md)", "`Heap`,`Hash Table`", "Medium", ""]}, {"question_id": "0346", "frontend_question_id": "0346", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/moving-average-from-data-stream", "url_en": "https://leetcode.com/problems/moving-average-from-data-stream", "relative_path_cn": "/solution/0300-0399/0346.Moving%20Average%20from%20Data%20Stream/README.md", "relative_path_en": "/solution/0300-0399/0346.Moving%20Average%20from%20Data%20Stream/README_EN.md", "title_cn": "\u6570\u636e\u6d41\u4e2d\u7684\u79fb\u52a8\u5e73\u5747\u503c", "title_en": "Moving Average from Data Stream", "question_title_slug": "moving-average-from-data-stream", "content_en": "

    Given a stream of integers and a window size, calculate the moving average of all integers in the sliding window.

    \n\n

    Implement the MovingAverage class:

    \n\n
      \n\t
    • MovingAverage(int size) Initializes the object with the size of the window size.
    • \n\t
    • double next(int val) Returns the moving average of the last size values of the stream.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["MovingAverage", "next", "next", "next", "next"]\n[[3], [1], [10], [3], [5]]\nOutput\n[null, 1.0, 5.5, 4.66667, 6.0]\n\nExplanation\nMovingAverage movingAverage = new MovingAverage(3);\nmovingAverage.next(1); // return 1.0 = 1 / 1\nmovingAverage.next(10); // return 5.5 = (1 + 10) / 2\nmovingAverage.next(3); // return 4.66667 = (1 + 10 + 3) / 3\nmovingAverage.next(5); // return 6.0 = (10 + 3 + 5) / 3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= size <= 1000
    • \n\t
    • -105 <= val <= 105
    • \n\t
    • At most 104 calls will be made to next.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u636e\u6d41\u548c\u4e00\u4e2a\u7a97\u53e3\u5927\u5c0f\uff0c\u6839\u636e\u8be5\u6ed1\u52a8\u7a97\u53e3\u7684\u5927\u5c0f\uff0c\u8ba1\u7b97\u5176\u6240\u6709\u6574\u6570\u7684\u79fb\u52a8\u5e73\u5747\u503c\u3002

    \n\n

    \u5b9e\u73b0 MovingAverage \u7c7b\uff1a

    \n\n
      \n\t
    • MovingAverage(int size) \u7528\u7a97\u53e3\u5927\u5c0f size \u521d\u59cb\u5316\u5bf9\u8c61\u3002
    • \n\t
    • double next(int val) \u8ba1\u7b97\u5e76\u8fd4\u56de\u6570\u636e\u6d41\u4e2d\u6700\u540e size \u4e2a\u503c\u7684\u79fb\u52a8\u5e73\u5747\u503c\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\n[\"MovingAverage\", \"next\", \"next\", \"next\", \"next\"]\n[[3], [1], [10], [3], [5]]\n\u8f93\u51fa\uff1a\n[null, 1.0, 5.5, 4.66667, 6.0]\n\n\u89e3\u91ca\uff1a\nMovingAverage movingAverage = new MovingAverage(3);\nmovingAverage.next(1); // \u8fd4\u56de 1.0 = 1 / 1\nmovingAverage.next(10); // \u8fd4\u56de 5.5 = (1 + 10) / 2\nmovingAverage.next(3); // \u8fd4\u56de 4.66667 = (1 + 10 + 3) / 3\nmovingAverage.next(5); // \u8fd4\u56de 6.0 = (10 + 3 + 5) / 3\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= size <= 1000
    • \n\t
    • -105 <= val <= 105
    • \n\t
    • \u6700\u591a\u8c03\u7528 next \u65b9\u6cd5 104 \u6b21
    • \n
    \n", "tags_en": ["Design", "Queue"], "tags_cn": ["\u8bbe\u8ba1", "\u961f\u5217"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class MovingAverage {\npublic:\n /** Initialize your data structure here. */\n MovingAverage(int size) {\n\n }\n \n double next(int val) {\n\n }\n};\n\n/**\n * Your MovingAverage object will be instantiated and called as such:\n * MovingAverage* obj = new MovingAverage(size);\n * double param_1 = obj->next(val);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class MovingAverage {\n\n /** Initialize your data structure here. */\n public MovingAverage(int size) {\n\n }\n \n public double next(int val) {\n\n }\n}\n\n/**\n * Your MovingAverage object will be instantiated and called as such:\n * MovingAverage obj = new MovingAverage(size);\n * double param_1 = obj.next(val);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class MovingAverage(object):\n\n def __init__(self, size):\n \"\"\"\n Initialize your data structure here.\n :type size: int\n \"\"\"\n\n\n def next(self, val):\n \"\"\"\n :type val: int\n :rtype: float\n \"\"\"\n\n\n\n# Your MovingAverage object will be instantiated and called as such:\n# obj = MovingAverage(size)\n# param_1 = obj.next(val)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class MovingAverage:\n\n def __init__(self, size: int):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def next(self, val: int) -> float:\n\n\n\n# Your MovingAverage object will be instantiated and called as such:\n# obj = MovingAverage(size)\n# param_1 = obj.next(val)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} MovingAverage;\n\n/** Initialize your data structure here. */\n\nMovingAverage* movingAverageCreate(int size) {\n\n}\n\ndouble movingAverageNext(MovingAverage* obj, int val) {\n\n}\n\nvoid movingAverageFree(MovingAverage* obj) {\n\n}\n\n/**\n * Your MovingAverage struct will be instantiated and called as such:\n * MovingAverage* obj = movingAverageCreate(size);\n * double param_1 = movingAverageNext(obj, val);\n \n * movingAverageFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class MovingAverage {\n\n /** Initialize your data structure here. */\n public MovingAverage(int size) {\n\n }\n \n public double Next(int val) {\n\n }\n}\n\n/**\n * Your MovingAverage object will be instantiated and called as such:\n * MovingAverage obj = new MovingAverage(size);\n * double param_1 = obj.Next(val);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Initialize your data structure here.\n * @param {number} size\n */\nvar MovingAverage = function(size) {\n\n};\n\n/** \n * @param {number} val\n * @return {number}\n */\nMovingAverage.prototype.next = function(val) {\n\n};\n\n/**\n * Your MovingAverage object will be instantiated and called as such:\n * var obj = new MovingAverage(size)\n * var param_1 = obj.next(val)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class MovingAverage\n\n=begin\n Initialize your data structure here.\n :type size: Integer\n=end\n def initialize(size)\n\n end\n\n\n=begin\n :type val: Integer\n :rtype: Float\n=end\n def next(val)\n\n end\n\n\nend\n\n# Your MovingAverage object will be instantiated and called as such:\n# obj = MovingAverage.new(size)\n# param_1 = obj.next(val)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass MovingAverage {\n\n /** Initialize your data structure here. */\n init(_ size: Int) {\n\n }\n \n func next(_ val: Int) -> Double {\n\n }\n}\n\n/**\n * Your MovingAverage object will be instantiated and called as such:\n * let obj = MovingAverage(size)\n * let ret_1: Double = obj.next(val)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type MovingAverage struct {\n\n}\n\n\n/** Initialize your data structure here. */\nfunc Constructor(size int) MovingAverage {\n\n}\n\n\nfunc (this *MovingAverage) Next(val int) float64 {\n\n}\n\n\n/**\n * Your MovingAverage object will be instantiated and called as such:\n * obj := Constructor(size);\n * param_1 := obj.Next(val);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class MovingAverage(_size: Int) {\n\n /** Initialize your data structure here. */\n\n\n def next(`val`: Int): Double = {\n\n }\n\n}\n\n/**\n * Your MovingAverage object will be instantiated and called as such:\n * var obj = new MovingAverage(size)\n * var param_1 = obj.next(`val`)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class MovingAverage(size: Int) {\n\n /** Initialize your data structure here. */\n\n\n fun next(`val`: Int): Double {\n\n }\n\n}\n\n/**\n * Your MovingAverage object will be instantiated and called as such:\n * var obj = MovingAverage(size)\n * var param_1 = obj.next(`val`)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct MovingAverage {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl MovingAverage {\n\n /** Initialize your data structure here. */\n fn new(size: i32) -> Self {\n\n }\n \n fn next(&self, val: i32) -> f64 {\n\n }\n}\n\n/**\n * Your MovingAverage object will be instantiated and called as such:\n * let obj = MovingAverage::new(size);\n * let ret_1: f64 = obj.next(val);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class MovingAverage {\n /**\n * Initialize your data structure here.\n * @param Integer $size\n */\n function __construct($size) {\n\n }\n\n /**\n * @param Integer $val\n * @return Float\n */\n function next($val) {\n\n }\n}\n\n/**\n * Your MovingAverage object will be instantiated and called as such:\n * $obj = MovingAverage($size);\n * $ret_1 = $obj->next($val);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class MovingAverage {\n constructor(size: number) {\n\n }\n\n next(val: number): number {\n\n }\n}\n\n/**\n * Your MovingAverage object will be instantiated and called as such:\n * var obj = new MovingAverage(size)\n * var param_1 = obj.next(val)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define moving-average%\n (class object%\n (super-new)\n\n ; size : exact-integer?\n (init-field\n size)\n \n ; next : exact-integer? -> flonum?\n (define/public (next val)\n\n )))\n\n;; Your moving-average% object will be instantiated and called as such:\n;; (define obj (new moving-average% [size size]))\n;; (define param_1 (send obj next val))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0346](https://leetcode-cn.com/problems/moving-average-from-data-stream)", "[\u6570\u636e\u6d41\u4e2d\u7684\u79fb\u52a8\u5e73\u5747\u503c](/solution/0300-0399/0346.Moving%20Average%20from%20Data%20Stream/README.md)", "`\u8bbe\u8ba1`,`\u961f\u5217`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0346](https://leetcode.com/problems/moving-average-from-data-stream)", "[Moving Average from Data Stream](/solution/0300-0399/0346.Moving%20Average%20from%20Data%20Stream/README_EN.md)", "`Design`,`Queue`", "Easy", "\ud83d\udd12"]}, {"question_id": "0345", "frontend_question_id": "0345", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reverse-vowels-of-a-string", "url_en": "https://leetcode.com/problems/reverse-vowels-of-a-string", "relative_path_cn": "/solution/0300-0399/0345.Reverse%20Vowels%20of%20a%20String/README.md", "relative_path_en": "/solution/0300-0399/0345.Reverse%20Vowels%20of%20a%20String/README_EN.md", "title_cn": "\u53cd\u8f6c\u5b57\u7b26\u4e32\u4e2d\u7684\u5143\u97f3\u5b57\u6bcd", "title_en": "Reverse Vowels of a String", "question_title_slug": "reverse-vowels-of-a-string", "content_en": "

    Given a string s, reverse only all the vowels in the string and return it.

    \n\n

    The vowels are 'a', 'e', 'i', 'o', and 'u', and they can appear in both cases.

    \n\n

     

    \n

    Example 1:

    \n
    Input: s = \"hello\"\nOutput: \"holle\"\n

    Example 2:

    \n
    Input: s = \"leetcode\"\nOutput: \"leotcede\"\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 3 * 105
    • \n\t
    • s consist of printable ASCII characters.
    • \n
    \n", "content_cn": "

    \u7f16\u5199\u4e00\u4e2a\u51fd\u6570\uff0c\u4ee5\u5b57\u7b26\u4e32\u4f5c\u4e3a\u8f93\u5165\uff0c\u53cd\u8f6c\u8be5\u5b57\u7b26\u4e32\u4e2d\u7684\u5143\u97f3\u5b57\u6bcd\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a"hello"\n\u8f93\u51fa\uff1a"holle"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a"leetcode"\n\u8f93\u51fa\uff1a"leotcede"
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u5143\u97f3\u5b57\u6bcd\u4e0d\u5305\u542b\u5b57\u6bcd "y" \u3002
    • \n
    \n", "tags_en": ["Two Pointers", "String"], "tags_cn": ["\u53cc\u6307\u9488", "\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string reverseVowels(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String reverseVowels(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def reverseVowels(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def reverseVowels(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * reverseVowels(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ReverseVowels(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar reverseVowels = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef reverse_vowels(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func reverseVowels(_ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func reverseVowels(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def reverseVowels(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun reverseVowels(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn reverse_vowels(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function reverseVowels($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function reverseVowels(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (reverse-vowels s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0345](https://leetcode-cn.com/problems/reverse-vowels-of-a-string)", "[\u53cd\u8f6c\u5b57\u7b26\u4e32\u4e2d\u7684\u5143\u97f3\u5b57\u6bcd](/solution/0300-0399/0345.Reverse%20Vowels%20of%20a%20String/README.md)", "`\u53cc\u6307\u9488`,`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0345](https://leetcode.com/problems/reverse-vowels-of-a-string)", "[Reverse Vowels of a String](/solution/0300-0399/0345.Reverse%20Vowels%20of%20a%20String/README_EN.md)", "`Two Pointers`,`String`", "Easy", ""]}, {"question_id": "0344", "frontend_question_id": "0344", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reverse-string", "url_en": "https://leetcode.com/problems/reverse-string", "relative_path_cn": "/solution/0300-0399/0344.Reverse%20String/README.md", "relative_path_en": "/solution/0300-0399/0344.Reverse%20String/README_EN.md", "title_cn": "\u53cd\u8f6c\u5b57\u7b26\u4e32", "title_en": "Reverse String", "question_title_slug": "reverse-string", "content_en": "

    Write a function that reverses a string. The input string is given as an array of characters s.

    \n\n

     

    \n

    Example 1:

    \n
    Input: s = [\"h\",\"e\",\"l\",\"l\",\"o\"]\nOutput: [\"o\",\"l\",\"l\",\"e\",\"h\"]\n

    Example 2:

    \n
    Input: s = [\"H\",\"a\",\"n\",\"n\",\"a\",\"h\"]\nOutput: [\"h\",\"a\",\"n\",\"n\",\"a\",\"H\"]\n
    \n

     

    \n

    Constraints:

    \n\n\n\n

     

    \n

    Follow up: Do not allocate extra space for another array. You must do this by modifying the input array in-place with O(1) extra memory.

    \n", "content_cn": "

    \u7f16\u5199\u4e00\u4e2a\u51fd\u6570\uff0c\u5176\u4f5c\u7528\u662f\u5c06\u8f93\u5165\u7684\u5b57\u7b26\u4e32\u53cd\u8f6c\u8fc7\u6765\u3002\u8f93\u5165\u5b57\u7b26\u4e32\u4ee5\u5b57\u7b26\u6570\u7ec4 char[] \u7684\u5f62\u5f0f\u7ed9\u51fa\u3002

    \n\n

    \u4e0d\u8981\u7ed9\u53e6\u5916\u7684\u6570\u7ec4\u5206\u914d\u989d\u5916\u7684\u7a7a\u95f4\uff0c\u4f60\u5fc5\u987b\u539f\u5730\u4fee\u6539\u8f93\u5165\u6570\u7ec4\u3001\u4f7f\u7528 O(1) \u7684\u989d\u5916\u7a7a\u95f4\u89e3\u51b3\u8fd9\u4e00\u95ee\u9898\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u5047\u8bbe\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5b57\u7b26\u90fd\u662f ASCII \u7801\u8868\u4e2d\u7684\u53ef\u6253\u5370\u5b57\u7b26\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a["h","e","l","l","o"]\n\u8f93\u51fa\uff1a["o","l","l","e","h"]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a["H","a","n","n","a","h"]\n\u8f93\u51fa\uff1a["h","a","n","n","a","H"]
    \n", "tags_en": ["Two Pointers", "String"], "tags_cn": ["\u53cc\u6307\u9488", "\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n void reverseString(vector& s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public void reverseString(char[] s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def reverseString(self, s):\n \"\"\"\n :type s: List[str]\n :rtype: None Do not return anything, modify s in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def reverseString(self, s: List[str]) -> None:\n \"\"\"\n Do not return anything, modify s in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nvoid reverseString(char* s, int sSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public void ReverseString(char[] s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {character[]} s\n * @return {void} Do not return anything, modify s in-place instead.\n */\nvar reverseString = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Character[]} s\n# @return {Void} Do not return anything, modify s in-place instead.\ndef reverse_string(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func reverseString(_ s: inout [Character]) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func reverseString(s []byte) {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def reverseString(s: Array[Char]): Unit = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun reverseString(s: CharArray): Unit {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn reverse_string(s: &mut Vec) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $s\n * @return NULL\n */\n function reverseString(&$s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n Do not return anything, modify s in-place instead.\n */\nfunction reverseString(s: string[]): void {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0344](https://leetcode-cn.com/problems/reverse-string)", "[\u53cd\u8f6c\u5b57\u7b26\u4e32](/solution/0300-0399/0344.Reverse%20String/README.md)", "`\u53cc\u6307\u9488`,`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0344](https://leetcode.com/problems/reverse-string)", "[Reverse String](/solution/0300-0399/0344.Reverse%20String/README_EN.md)", "`Two Pointers`,`String`", "Easy", ""]}, {"question_id": "0343", "frontend_question_id": "0343", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/integer-break", "url_en": "https://leetcode.com/problems/integer-break", "relative_path_cn": "/solution/0300-0399/0343.Integer%20Break/README.md", "relative_path_en": "/solution/0300-0399/0343.Integer%20Break/README_EN.md", "title_cn": "\u6574\u6570\u62c6\u5206", "title_en": "Integer Break", "question_title_slug": "integer-break", "content_en": "

    Given an integer n, break it into the sum of k positive integers, where k >= 2, and maximize the product of those integers.

    \n\n

    Return the maximum product you can get.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 2\nOutput: 1\nExplanation: 2 = 1 + 1, 1 × 1 = 1.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 10\nOutput: 36\nExplanation: 10 = 3 + 3 + 4, 3 × 3 × 4 = 36.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= n <= 58
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6b63\u6574\u6570 n\uff0c\u5c06\u5176\u62c6\u5206\u4e3a\u81f3\u5c11\u4e24\u4e2a\u6b63\u6574\u6570\u7684\u548c\uff0c\u5e76\u4f7f\u8fd9\u4e9b\u6574\u6570\u7684\u4e58\u79ef\u6700\u5927\u5316\u3002 \u8fd4\u56de\u4f60\u53ef\u4ee5\u83b7\u5f97\u7684\u6700\u5927\u4e58\u79ef\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: 2\n\u8f93\u51fa: 1\n\u89e3\u91ca: 2 = 1 + 1, 1 × 1 = 1\u3002
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: 10\n\u8f93\u51fa: 36\n\u89e3\u91ca: 10 = 3 + 3 + 4, 3 × 3 × 4 = 36\u3002
    \n\n

    \u8bf4\u660e: \u4f60\u53ef\u4ee5\u5047\u8bbe \u4e0d\u5c0f\u4e8e 2 \u4e14\u4e0d\u5927\u4e8e 58\u3002

    \n", "tags_en": ["Math", "Dynamic Programming"], "tags_cn": ["\u6570\u5b66", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int integerBreak(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int integerBreak(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def integerBreak(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def integerBreak(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint integerBreak(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int IntegerBreak(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar integerBreak = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef integer_break(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func integerBreak(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func integerBreak(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def integerBreak(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun integerBreak(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn integer_break(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function integerBreak($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function integerBreak(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (integer-break n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0343](https://leetcode-cn.com/problems/integer-break)", "[\u6574\u6570\u62c6\u5206](/solution/0300-0399/0343.Integer%20Break/README.md)", "`\u6570\u5b66`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0343](https://leetcode.com/problems/integer-break)", "[Integer Break](/solution/0300-0399/0343.Integer%20Break/README_EN.md)", "`Math`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0342", "frontend_question_id": "0342", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/power-of-four", "url_en": "https://leetcode.com/problems/power-of-four", "relative_path_cn": "/solution/0300-0399/0342.Power%20of%20Four/README.md", "relative_path_en": "/solution/0300-0399/0342.Power%20of%20Four/README_EN.md", "title_cn": "4\u7684\u5e42", "title_en": "Power of Four", "question_title_slug": "power-of-four", "content_en": "

    Given an integer n, return true if it is a power of four. Otherwise, return false.

    \n\n

    An integer n is a power of four, if there exists an integer x such that n == 4x.

    \n\n

     

    \n

    Example 1:

    \n
    Input: n = 16\nOutput: true\n

    Example 2:

    \n
    Input: n = 5\nOutput: false\n

    Example 3:

    \n
    Input: n = 1\nOutput: true\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • -231 <= n <= 231 - 1
    • \n
    \n\n

     

    \nFollow up: Could you solve it without loops/recursion?", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\uff0c\u5199\u4e00\u4e2a\u51fd\u6570\u6765\u5224\u65ad\u5b83\u662f\u5426\u662f 4 \u7684\u5e42\u6b21\u65b9\u3002\u5982\u679c\u662f\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n

    \u6574\u6570 n \u662f 4 \u7684\u5e42\u6b21\u65b9\u9700\u6ee1\u8db3\uff1a\u5b58\u5728\u6574\u6570 x \u4f7f\u5f97 n == 4x

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 16\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 5\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • -231 <= n <= 231 - 1
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u4f60\u80fd\u4e0d\u4f7f\u7528\u5faa\u73af\u6216\u8005\u9012\u5f52\u6765\u5b8c\u6210\u672c\u9898\u5417\uff1f
    • \n
    \n", "tags_en": ["Bit Manipulation"], "tags_cn": ["\u4f4d\u8fd0\u7b97"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isPowerOfFour(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isPowerOfFour(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isPowerOfFour(self, n):\n \"\"\"\n :type n: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isPowerOfFour(self, n: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isPowerOfFour(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsPowerOfFour(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {boolean}\n */\nvar isPowerOfFour = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Boolean}\ndef is_power_of_four(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isPowerOfFour(_ n: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isPowerOfFour(n int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isPowerOfFour(n: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isPowerOfFour(n: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_power_of_four(n: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Boolean\n */\n function isPowerOfFour($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isPowerOfFour(n: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-power-of-four n)\n (-> exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0342](https://leetcode-cn.com/problems/power-of-four)", "[4\u7684\u5e42](/solution/0300-0399/0342.Power%20of%20Four/README.md)", "`\u4f4d\u8fd0\u7b97`", "\u7b80\u5355", ""], "md_table_row_en": ["[0342](https://leetcode.com/problems/power-of-four)", "[Power of Four](/solution/0300-0399/0342.Power%20of%20Four/README_EN.md)", "`Bit Manipulation`", "Easy", ""]}, {"question_id": "0341", "frontend_question_id": "0341", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/flatten-nested-list-iterator", "url_en": "https://leetcode.com/problems/flatten-nested-list-iterator", "relative_path_cn": "/solution/0300-0399/0341.Flatten%20Nested%20List%20Iterator/README.md", "relative_path_en": "/solution/0300-0399/0341.Flatten%20Nested%20List%20Iterator/README_EN.md", "title_cn": "\u6241\u5e73\u5316\u5d4c\u5957\u5217\u8868\u8fed\u4ee3\u5668", "title_en": "Flatten Nested List Iterator", "question_title_slug": "flatten-nested-list-iterator", "content_en": "

    You are given a nested list of integers nestedList. Each element is either an integer or a list whose elements may also be integers or other lists. Implement an iterator to flatten it.

    \n\n

    Implement the NestedIterator class:

    \n\n
      \n\t
    • NestedIterator(List<NestedInteger> nestedList) Initializes the iterator with the nested list nestedList.
    • \n\t
    • int next() Returns the next integer in the nested list.
    • \n\t
    • boolean hasNext() Returns true if there are still some integers in the nested list and false otherwise.
    • \n
    \n\n

    Your code will be tested with the following pseudocode:

    \n\n
    \ninitialize iterator with nestedList\nres = []\nwhile iterator.hasNext()\n    append iterator.next() to the end of res\nreturn res\n
    \n\n

    If res matches the expected flattened list, then your code will be judged as correct.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nestedList = [[1,1],2,[1,1]]\nOutput: [1,1,2,1,1]\nExplanation: By calling next repeatedly until hasNext returns false, the order of elements returned by next should be: [1,1,2,1,1].\n
    \n\n

    Example 2:

    \n\n
    \nInput: nestedList = [1,[4,[6]]]\nOutput: [1,4,6]\nExplanation: By calling next repeatedly until hasNext returns false, the order of elements returned by next should be: [1,4,6].\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nestedList.length <= 500
    • \n\t
    • The values of the integers in the nested list is in the range [-106, 106].
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5d4c\u5957\u7684\u6574\u578b\u5217\u8868\u3002\u8bf7\u4f60\u8bbe\u8ba1\u4e00\u4e2a\u8fed\u4ee3\u5668\uff0c\u4f7f\u5176\u80fd\u591f\u904d\u5386\u8fd9\u4e2a\u6574\u578b\u5217\u8868\u4e2d\u7684\u6240\u6709\u6574\u6570\u3002

    \n\n

    \u5217\u8868\u4e2d\u7684\u6bcf\u4e00\u9879\u6216\u8005\u4e3a\u4e00\u4e2a\u6574\u6570\uff0c\u6216\u8005\u662f\u53e6\u4e00\u4e2a\u5217\u8868\u3002\u5176\u4e2d\u5217\u8868\u7684\u5143\u7d20\u4e5f\u53ef\u80fd\u662f\u6574\u6570\u6216\u662f\u5176\u4ed6\u5217\u8868\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: [[1,1],2,[1,1]]\n\u8f93\u51fa: [1,1,2,1,1]\n\u89e3\u91ca: \u901a\u8fc7\u91cd\u590d\u8c03\u7528 next \u76f4\u5230 hasNext \u8fd4\u56de false\uff0cnext \u8fd4\u56de\u7684\u5143\u7d20\u7684\u987a\u5e8f\u5e94\u8be5\u662f: [1,1,2,1,1]\u3002
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: [1,[4,[6]]]\n\u8f93\u51fa: [1,4,6]\n\u89e3\u91ca: \u901a\u8fc7\u91cd\u590d\u8c03\u7528 next \u76f4\u5230 hasNext \u8fd4\u56de false\uff0cnext \u8fd4\u56de\u7684\u5143\u7d20\u7684\u987a\u5e8f\u5e94\u8be5\u662f: [1,4,6]\u3002\n
    \n", "tags_en": ["Stack", "Design"], "tags_cn": ["\u6808", "\u8bbe\u8ba1"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * class NestedInteger {\n * public:\n * // Return true if this NestedInteger holds a single integer, rather than a nested list.\n * bool isInteger() const;\n *\n * // Return the single integer that this NestedInteger holds, if it holds a single integer\n * // The result is undefined if this NestedInteger holds a nested list\n * int getInteger() const;\n *\n * // Return the nested list that this NestedInteger holds, if it holds a nested list\n * // The result is undefined if this NestedInteger holds a single integer\n * const vector &getList() const;\n * };\n */\n\nclass NestedIterator {\npublic:\n NestedIterator(vector &nestedList) {\n \n }\n \n int next() {\n \n }\n \n bool hasNext() {\n \n }\n};\n\n/**\n * Your NestedIterator object will be instantiated and called as such:\n * NestedIterator i(nestedList);\n * while (i.hasNext()) cout << i.next();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * public interface NestedInteger {\n *\n * // @return true if this NestedInteger holds a single integer, rather than a nested list.\n * public boolean isInteger();\n *\n * // @return the single integer that this NestedInteger holds, if it holds a single integer\n * // Return null if this NestedInteger holds a nested list\n * public Integer getInteger();\n *\n * // @return the nested list that this NestedInteger holds, if it holds a nested list\n * // Return empty list if this NestedInteger holds a single integer\n * public List getList();\n * }\n */\npublic class NestedIterator implements Iterator {\n\n public NestedIterator(List nestedList) {\n \n }\n\n @Override\n public Integer next() {\n \n }\n\n @Override\n public boolean hasNext() {\n \n }\n}\n\n/**\n * Your NestedIterator object will be instantiated and called as such:\n * NestedIterator i = new NestedIterator(nestedList);\n * while (i.hasNext()) v[f()] = i.next();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# \"\"\"\n# This is the interface that allows for creating nested lists.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class NestedInteger(object):\n# def isInteger(self):\n# \"\"\"\n# @return True if this NestedInteger holds a single integer, rather than a nested list.\n# :rtype bool\n# \"\"\"\n#\n# def getInteger(self):\n# \"\"\"\n# @return the single integer that this NestedInteger holds, if it holds a single integer\n# Return None if this NestedInteger holds a nested list\n# :rtype int\n# \"\"\"\n#\n# def getList(self):\n# \"\"\"\n# @return the nested list that this NestedInteger holds, if it holds a nested list\n# Return None if this NestedInteger holds a single integer\n# :rtype List[NestedInteger]\n# \"\"\"\n\nclass NestedIterator(object):\n\n def __init__(self, nestedList):\n \"\"\"\n Initialize your data structure here.\n :type nestedList: List[NestedInteger]\n \"\"\"\n \n\n def next(self):\n \"\"\"\n :rtype: int\n \"\"\"\n \n\n def hasNext(self):\n \"\"\"\n :rtype: bool\n \"\"\"\n \n\n# Your NestedIterator object will be instantiated and called as such:\n# i, v = NestedIterator(nestedList), []\n# while i.hasNext(): v.append(i.next())", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# \"\"\"\n# This is the interface that allows for creating nested lists.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class NestedInteger:\n# def isInteger(self) -> bool:\n# \"\"\"\n# @return True if this NestedInteger holds a single integer, rather than a nested list.\n# \"\"\"\n#\n# def getInteger(self) -> int:\n# \"\"\"\n# @return the single integer that this NestedInteger holds, if it holds a single integer\n# Return None if this NestedInteger holds a nested list\n# \"\"\"\n#\n# def getList(self) -> [NestedInteger]:\n# \"\"\"\n# @return the nested list that this NestedInteger holds, if it holds a nested list\n# Return None if this NestedInteger holds a single integer\n# \"\"\"\n\nclass NestedIterator:\n def __init__(self, nestedList: [NestedInteger]):\n \n \n def next(self) -> int:\n \n \n def hasNext(self) -> bool:\n \n\n# Your NestedIterator object will be instantiated and called as such:\n# i, v = NestedIterator(nestedList), []\n# while i.hasNext(): v.append(i.next())", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * *********************************************************************\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * *********************************************************************\n *\n * // Return true if this NestedInteger holds a single integer, rather than a nested list.\n * bool NestedIntegerIsInteger(struct NestedInteger *);\n *\n * // Return the single integer that this NestedInteger holds, if it holds a single integer\n * // The result is undefined if this NestedInteger holds a nested list\n * int NestedIntegerGetInteger(struct NestedInteger *);\n *\n * // Return the nested list that this NestedInteger holds, if it holds a nested list\n * // The result is undefined if this NestedInteger holds a single integer\n * struct NestedInteger **NestedIntegerGetList(struct NestedInteger *);\n *\n * // Return the nested list's size that this NestedInteger holds, if it holds a nested list\n * // The result is undefined if this NestedInteger holds a single integer\n * int NestedIntegerGetListSize(struct NestedInteger *);\n * };\n */\nstruct NestedIterator {\n \n};\n\nstruct NestedIterator *nestedIterCreate(struct NestedInteger** nestedList, int nestedListSize) {\n \n}\n\nbool nestedIterHasNext(struct NestedIterator *iter) {\n \n}\n\nint nestedIterNext(struct NestedIterator *iter) {\n \n}\n\n/** Deallocates memory previously allocated for the iterator */\nvoid nestedIterFree(struct NestedIterator *iter) {\n \n}\n\n/**\n * Your NestedIterator will be called like this:\n * struct NestedIterator *i = nestedIterCreate(nestedList, nestedListSize);\n * while (nestedIterHasNext(i)) printf(\"%d\\n\", nestedIterNext(i));\n * nestedIterFree(i);\n */", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * interface NestedInteger {\n *\n * // @return true if this NestedInteger holds a single integer, rather than a nested list.\n * bool IsInteger();\n *\n * // @return the single integer that this NestedInteger holds, if it holds a single integer\n * // Return null if this NestedInteger holds a nested list\n * int GetInteger();\n *\n * // @return the nested list that this NestedInteger holds, if it holds a nested list\n * // Return null if this NestedInteger holds a single integer\n * IList GetList();\n * }\n */\npublic class NestedIterator {\n\n public NestedIterator(IList nestedList) {\n \n }\n\n public bool HasNext() {\n \n }\n\n public int Next() {\n \n }\n}\n\n/**\n * Your NestedIterator will be called like this:\n * NestedIterator i = new NestedIterator(nestedList);\n * while (i.HasNext()) v[f()] = i.Next();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * function NestedInteger() {\n *\n * Return true if this NestedInteger holds a single integer, rather than a nested list.\n * @return {boolean}\n * this.isInteger = function() {\n * ...\n * };\n *\n * Return the single integer that this NestedInteger holds, if it holds a single integer\n * Return null if this NestedInteger holds a nested list\n * @return {integer}\n * this.getInteger = function() {\n * ...\n * };\n *\n * Return the nested list that this NestedInteger holds, if it holds a nested list\n * Return null if this NestedInteger holds a single integer\n * @return {NestedInteger[]}\n * this.getList = function() {\n * ...\n * };\n * };\n */\n/**\n * @constructor\n * @param {NestedInteger[]} nestedList\n */\nvar NestedIterator = function(nestedList) {\n \n};\n\n\n/**\n * @this NestedIterator\n * @returns {boolean}\n */\nNestedIterator.prototype.hasNext = function() {\n \n};\n\n/**\n * @this NestedIterator\n * @returns {integer}\n */\nNestedIterator.prototype.next = function() {\n \n};\n\n/**\n * Your NestedIterator will be called like this:\n * var i = new NestedIterator(nestedList), a = [];\n * while (i.hasNext()) a.push(i.next());\n*/", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# This is the interface that allows for creating nested lists.\n# You should not implement it, or speculate about its implementation\n#\n#class NestedInteger\n# def is_integer()\n# \"\"\"\n# Return true if this NestedInteger holds a single integer, rather than a nested list.\n# @return {Boolean}\n# \"\"\"\n#\n# def get_integer()\n# \"\"\"\n# Return the single integer that this NestedInteger holds, if it holds a single integer\n# Return nil if this NestedInteger holds a nested list\n# @return {Integer}\n# \"\"\"\n#\n# def get_list()\n# \"\"\"\n# Return the nested list that this NestedInteger holds, if it holds a nested list\n# Return nil if this NestedInteger holds a single integer\n# @return {NestedInteger[]}\n# \"\"\"\n\nclass NestedIterator\n # @param {NestedInteger[]} nested_list\n def initialize(nested_list)\n \n end\n\n # @return {Boolean}\n def has_next\n \n end\n\n # @return {Integer}\n def next\n \n end\nend\n\n# Your NestedIterator will be called like this:\n# i, v = NestedIterator.new(nested_list), []\n# while i.has_next()\n# v << i.next\n# end", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * class NestedInteger {\n * // Return true if this NestedInteger holds a single integer, rather than a nested list.\n * public func isInteger() -> Bool\n *\n * // Return the single integer that this NestedInteger holds, if it holds a single integer\n * // The result is undefined if this NestedInteger holds a nested list\n * public func getInteger() -> Int\n *\n * // Set this NestedInteger to hold a single integer.\n * public func setInteger(value: Int)\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * public func add(elem: NestedInteger)\n *\n * // Return the nested list that this NestedInteger holds, if it holds a nested list\n * // The result is undefined if this NestedInteger holds a single integer\n * public func getList() -> [NestedInteger]\n * }\n */\n\nclass NestedIterator {\n\n init(_ nestedList: [NestedInteger]) {\n \n }\n \n func next() -> Int {\n \n }\n \n func hasNext() -> Bool {\n \n }\n}\n\n/**\n * Your NestedIterator object will be instantiated and called as such:\n * let obj = NestedIterator(nestedList)\n * let ret_1: Int = obj.next()\n * let ret_2: Bool = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * type NestedInteger struct {\n * }\n *\n * // Return true if this NestedInteger holds a single integer, rather than a nested list.\n * func (this NestedInteger) IsInteger() bool {}\n *\n * // Return the single integer that this NestedInteger holds, if it holds a single integer\n * // The result is undefined if this NestedInteger holds a nested list\n * // So before calling this method, you should have a check\n * func (this NestedInteger) GetInteger() int {}\n *\n * // Set this NestedInteger to hold a single integer.\n * func (n *NestedInteger) SetInteger(value int) {}\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * func (this *NestedInteger) Add(elem NestedInteger) {}\n *\n * // Return the nested list that this NestedInteger holds, if it holds a nested list\n * // The list length is zero if this NestedInteger holds a single integer\n * // You can access NestedInteger's List element directly if you want to modify it\n * func (this NestedInteger) GetList() []*NestedInteger {}\n */\n\ntype NestedIterator struct {\n \n}\n\nfunc Constructor(nestedList []*NestedInteger) *NestedIterator {\n \n}\n\nfunc (this *NestedIterator) Next() int {\n \n}\n\nfunc (this *NestedIterator) HasNext() bool {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * trait NestedInteger {\n *\n * // Return true if this NestedInteger holds a single integer, rather than a nested list.\n * def isInteger: Boolean\n *\n * // Return the single integer that this NestedInteger holds, if it holds a single integer.\n * def getInteger: Int\n *\n * // Set this NestedInteger to hold a single integer.\n * def setInteger(i: Int): Unit\n *\n * // Return the nested list that this NestedInteger holds, if it holds a nested list.\n * def getList: Array[NestedInteger]\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * def add(ni: NestedInteger): Unit\n * }\n */\n\nclass NestedIterator(_nestedList: List[NestedInteger]) {\n def next(): Int = {\n \n }\n \n def hasNext(): Boolean = {\n \n }\n}\n\n/**\n * Your NestedIterator object will be instantiated and called as such:\n * var obj = new NestedIterator(nestedList)\n * var param_1 = obj.next()\n * var param_2 = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * class NestedInteger {\n * // Constructor initializes an empty nested list.\n * constructor()\n *\n * // Constructor initializes a single integer.\n * constructor(value: Int)\n *\n * // @return true if this NestedInteger holds a single integer, rather than a nested list.\n * fun isInteger(): Boolean\n *\n * // @return the single integer that this NestedInteger holds, if it holds a single integer\n * // Return null if this NestedInteger holds a nested list\n * fun getInteger(): Int?\n *\n * // Set this NestedInteger to hold a single integer.\n * fun setInteger(value: Int): Unit\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * fun add(ni: NestedInteger): Unit\n *\n * // @return the nested list that this NestedInteger holds, if it holds a nested list\n * // Return null if this NestedInteger holds a single integer\n * fun getList(): List?\n * }\n */\n\nclass NestedIterator(nestedList: List) {\n fun next(): Int {\n \n }\n \n fun hasNext(): Boolean {\n \n }\n}\n\n/**\n * Your NestedIterator object will be instantiated and called as such:\n * var obj = NestedIterator(nestedList)\n * var param_1 = obj.next()\n * var param_2 = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// #[derive(Debug, PartialEq, Eq)]\n// pub enum NestedInteger {\n// Int(i32),\n// List(Vec)\n// }\nstruct NestedIterator {\n\n}\n\n\n/** \n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl NestedIterator {\n\n fn new(nestedList: Vec) -> Self {\n \n }\n \n fn next(&self) -> i32 {\n \n }\n \n fn has_next(&self) -> bool {\n \n }\n}\n\n/**\n * Your NestedIterator object will be instantiated and called as such:\n * let obj = NestedIterator::new(nestedList);\n * let ret_1: i32 = obj.next();\n * let ret_2: bool = obj.has_next();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * class NestedInteger {\n *\n * // if value is not specified, initializes an empty list.\n * // Otherwise initializes a single integer equal to value.\n * function __construct($value = null)\n *\n * // Return true if this NestedInteger holds a single integer, rather than a nested list.\n * function isInteger() : bool\n *\n * // Return the single integer that this NestedInteger holds, if it holds a single integer\n * // The result is undefined if this NestedInteger holds a nested list\n * function getInteger()\n *\n * // Set this NestedInteger to hold a single integer.\n * function setInteger($i) : void\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * function add($ni) : void\n *\n * // Return the nested list that this NestedInteger holds, if it holds a nested list\n * // The result is undefined if this NestedInteger holds a single integer\n * function getList() : array\n * }\n */\n\nclass NestedIterator {\n /**\n * @param NestedInteger[] $nestedList\n */\n function __construct($nestedList) {\n \n }\n \n /**\n * @return Integer\n */\n function next() {\n \n }\n \n /**\n * @return Boolean\n */\n function hasNext() {\n \n }\n}\n\n/**\n * Your NestedIterator object will be instantiated and called as such:\n * $obj = NestedIterator($nestedList);\n * $ret_1 = $obj->next();\n * $ret_2 = $obj->hasNext();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * class NestedInteger {\n * If value is provided, then it holds a single integer\n * Otherwise it holds an empty nested list\n * constructor(value?: number) {\n * ...\n * };\n *\n * Return true if this NestedInteger holds a single integer, rather than a nested list.\n * isInteger(): boolean {\n * ...\n * };\n *\n * Return the single integer that this NestedInteger holds, if it holds a single integer\n * Return null if this NestedInteger holds a nested list\n * getInteger(): number | null {\n * ...\n * };\n *\n * Set this NestedInteger to hold a single integer equal to value.\n * setInteger(value: number) {\n * ...\n * };\n *\n * Set this NestedInteger to hold a nested list and adds a nested integer elem to it.\n * add(elem: NestedInteger) {\n * ...\n * };\n *\n * Return the nested list that this NestedInteger holds,\n * or an empty list if this NestedInteger holds a single integer\n * getList(): NestedInteger[] {\n * ...\n * };\n * };\n */\n\nclass NestedIterator {\n constructor(nestedList: NestedInteger[]) {\n\t\t\n }\n\n hasNext(): boolean {\n\t\t\n }\n\n\tnext(): number {\n\t\t\n }\n}\n\n/**\n * Your ParkingSystem object will be instantiated and called as such:\n * var obj = new NestedIterator(nestedList)\n * var a: number[] = []\n * while (obj.hasNext()) a.push(obj.next());\n */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0341](https://leetcode-cn.com/problems/flatten-nested-list-iterator)", "[\u6241\u5e73\u5316\u5d4c\u5957\u5217\u8868\u8fed\u4ee3\u5668](/solution/0300-0399/0341.Flatten%20Nested%20List%20Iterator/README.md)", "`\u6808`,`\u8bbe\u8ba1`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0341](https://leetcode.com/problems/flatten-nested-list-iterator)", "[Flatten Nested List Iterator](/solution/0300-0399/0341.Flatten%20Nested%20List%20Iterator/README_EN.md)", "`Stack`,`Design`", "Medium", ""]}, {"question_id": "0340", "frontend_question_id": "0340", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/longest-substring-with-at-most-k-distinct-characters", "url_en": "https://leetcode.com/problems/longest-substring-with-at-most-k-distinct-characters", "relative_path_cn": "/solution/0300-0399/0340.Longest%20Substring%20with%20At%20Most%20K%20Distinct%20Characters/README.md", "relative_path_en": "/solution/0300-0399/0340.Longest%20Substring%20with%20At%20Most%20K%20Distinct%20Characters/README_EN.md", "title_cn": "\u81f3\u591a\u5305\u542b K \u4e2a\u4e0d\u540c\u5b57\u7b26\u7684\u6700\u957f\u5b50\u4e32", "title_en": "Longest Substring with At Most K Distinct Characters", "question_title_slug": "longest-substring-with-at-most-k-distinct-characters", "content_en": "

    Given a string s and an integer k, return the length of the longest substring of s that contains at most k distinct characters.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "eceba", k = 2\nOutput: 3\nExplanation: The substring is "ece" with length 3.
    \n\n

    Example 2:

    \n\n
    \nInput: s = "aa", k = 1\nOutput: 2\nExplanation: The substring is "aa" with length 2.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 5 * 104
    • \n\t
    • 0 <= k <= 50
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32 s \uff0c\u627e\u51fa \u81f3\u591a \u5305\u542b k \u4e2a\u4e0d\u540c\u5b57\u7b26\u7684\u6700\u957f\u5b50\u4e32 T\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: s = "eceba", k = 2\n\u8f93\u51fa: 3\n\u89e3\u91ca: \u5219 T \u4e3a "ece"\uff0c\u6240\u4ee5\u957f\u5ea6\u4e3a 3\u3002
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: s = "aa", k = 1\n\u8f93\u51fa: 2\n\u89e3\u91ca: \u5219 T \u4e3a "aa"\uff0c\u6240\u4ee5\u957f\u5ea6\u4e3a 2\u3002\n
    \n", "tags_en": ["Hash Table", "Two Pointers", "String", "Sliding Window"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u53cc\u6307\u9488", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int lengthOfLongestSubstringKDistinct(string s, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int lengthOfLongestSubstringKDistinct(String s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def lengthOfLongestSubstringKDistinct(self, s, k):\n \"\"\"\n :type s: str\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def lengthOfLongestSubstringKDistinct(self, s: str, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint lengthOfLongestSubstringKDistinct(char * s, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LengthOfLongestSubstringKDistinct(string s, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number} k\n * @return {number}\n */\nvar lengthOfLongestSubstringKDistinct = function(s, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer} k\n# @return {Integer}\ndef length_of_longest_substring_k_distinct(s, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func lengthOfLongestSubstringKDistinct(_ s: String, _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func lengthOfLongestSubstringKDistinct(s string, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def lengthOfLongestSubstringKDistinct(s: String, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun lengthOfLongestSubstringKDistinct(s: String, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn length_of_longest_substring_k_distinct(s: String, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer $k\n * @return Integer\n */\n function lengthOfLongestSubstringKDistinct($s, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function lengthOfLongestSubstringKDistinct(s: string, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (length-of-longest-substring-k-distinct s k)\n (-> string? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0340](https://leetcode-cn.com/problems/longest-substring-with-at-most-k-distinct-characters)", "[\u81f3\u591a\u5305\u542b K \u4e2a\u4e0d\u540c\u5b57\u7b26\u7684\u6700\u957f\u5b50\u4e32](/solution/0300-0399/0340.Longest%20Substring%20with%20At%20Most%20K%20Distinct%20Characters/README.md)", "`\u54c8\u5e0c\u8868`,`\u53cc\u6307\u9488`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0340](https://leetcode.com/problems/longest-substring-with-at-most-k-distinct-characters)", "[Longest Substring with At Most K Distinct Characters](/solution/0300-0399/0340.Longest%20Substring%20with%20At%20Most%20K%20Distinct%20Characters/README_EN.md)", "`Hash Table`,`Two Pointers`,`String`,`Sliding Window`", "Medium", "\ud83d\udd12"]}, {"question_id": "0339", "frontend_question_id": "0339", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/nested-list-weight-sum", "url_en": "https://leetcode.com/problems/nested-list-weight-sum", "relative_path_cn": "/solution/0300-0399/0339.Nested%20List%20Weight%20Sum/README.md", "relative_path_en": "/solution/0300-0399/0339.Nested%20List%20Weight%20Sum/README_EN.md", "title_cn": "\u5d4c\u5957\u5217\u8868\u6743\u91cd\u548c", "title_en": "Nested List Weight Sum", "question_title_slug": "nested-list-weight-sum", "content_en": "

    You are given a nested list of integers nestedList. Each element is either an integer or a list whose elements may also be integers or other lists.

    \n\n

    The depth of an integer is the number of lists that it is inside of. For example, the nested list [1,[2,2],[[3],2],1] has each integer's value set to its depth.

    \n\n

    Return the sum of each integer in nestedList multiplied by its depth.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: nestedList = [[1,1],2,[1,1]]\nOutput: 10\nExplanation: Four 1's at depth 2, one 2 at depth 1. 1*2 + 1*2 + 2*1 + 1*2 + 1*2 = 10.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: nestedList = [1,[4,[6]]]\nOutput: 27\nExplanation: One 1 at depth 1, one 4 at depth 2, and one 6 at depth 3. 1*1 + 4*2 + 6*3 = 27.
    \n\n

    Example 3:

    \n\n
    \nInput: nestedList = [0]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nestedList.length <= 50
    • \n\t
    • The values of the integers in the nested list is in the range [-100, 100].
    • \n\t
    • The maximum depth of any integer is less than or equal to 50.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5d4c\u5957\u7684\u6574\u6570\u5217\u8868\u00a0nestedList \uff0c\u6bcf\u4e2a\u5143\u7d20\u8981\u4e48\u662f\u6574\u6570\uff0c\u8981\u4e48\u662f\u5217\u8868\u3002\u540c\u65f6\uff0c\u5217\u8868\u4e2d\u5143\u7d20\u540c\u6837\u4e5f\u53ef\u4ee5\u662f\u6574\u6570\u6216\u8005\u662f\u53e6\u4e00\u4e2a\u5217\u8868\u3002

    \n\n

    \u6574\u6570\u7684 \u6df1\u5ea6 \u662f\u5176\u5728\u5217\u8868\u5185\u90e8\u7684\u5d4c\u5957\u5c42\u6570\u3002\u4f8b\u5982\uff0c\u5d4c\u5957\u5217\u8868\u00a0[1,[2,2],[[3],2],1] \u4e2d\u6bcf\u4e2a\u6574\u6570\u7684\u503c\u5c31\u662f\u5176\u6df1\u5ea6\u3002

    \n\n

    \u8bf7\u8fd4\u56de\u8be5\u5217\u8868\u6309\u6df1\u5ea6\u52a0\u6743\u540e\u6240\u6709\u6574\u6570\u7684\u603b\u548c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1anestedList = [[1,1],2,[1,1]]\n\u8f93\u51fa\uff1a10 \n\u89e3\u91ca\uff1a\u56e0\u4e3a\u5217\u8868\u4e2d\u6709\u56db\u4e2a\u6df1\u5ea6\u4e3a 2 \u7684 1 \uff0c\u548c\u4e00\u4e2a\u6df1\u5ea6\u4e3a 1 \u7684 2\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1anestedList = [1,[4,[6]]]\n\u8f93\u51fa\uff1a27 \n\u89e3\u91ca\uff1a\u4e00\u4e2a\u6df1\u5ea6\u4e3a 1 \u7684 1\uff0c\u4e00\u4e2a\u6df1\u5ea6\u4e3a 2 \u7684 4\uff0c\u4e00\u4e2a\u6df1\u5ea6\u4e3a 3 \u7684 6\u3002\u6240\u4ee5\uff0c1 + 4*2 + 6*3 = 27\u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anestedList = [0]\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nestedList.length <= 50
    • \n\t
    • \u5d4c\u5957\u5217\u8868\u4e2d\u6574\u6570\u7684\u503c\u5728\u8303\u56f4 [-100, 100] \u5185
    • \n\t
    • \u4efb\u4f55\u6574\u6570\u7684\u6700\u5927 \u6df1\u5ea6 \u90fd\u5c0f\u4e8e\u6216\u7b49\u4e8e 50
    • \n
    \n", "tags_en": ["Depth-first Search", "Breadth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * class NestedInteger {\n * public:\n * // Constructor initializes an empty nested list.\n * NestedInteger();\n *\n * // Constructor initializes a single integer.\n * NestedInteger(int value);\n *\n * // Return true if this NestedInteger holds a single integer, rather than a nested list.\n * bool isInteger() const;\n *\n * // Return the single integer that this NestedInteger holds, if it holds a single integer\n * // The result is undefined if this NestedInteger holds a nested list\n * int getInteger() const;\n *\n * // Set this NestedInteger to hold a single integer.\n * void setInteger(int value);\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * void add(const NestedInteger &ni);\n *\n * // Return the nested list that this NestedInteger holds, if it holds a nested list\n * // The result is undefined if this NestedInteger holds a single integer\n * const vector &getList() const;\n * };\n */\nclass Solution {\npublic:\n int depthSum(vector& nestedList) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * public interface NestedInteger {\n * // Constructor initializes an empty nested list.\n * public NestedInteger();\n *\n * // Constructor initializes a single integer.\n * public NestedInteger(int value);\n *\n * // @return true if this NestedInteger holds a single integer, rather than a nested list.\n * public boolean isInteger();\n *\n * // @return the single integer that this NestedInteger holds, if it holds a single integer\n * // Return null if this NestedInteger holds a nested list\n * public Integer getInteger();\n *\n * // Set this NestedInteger to hold a single integer.\n * public void setInteger(int value);\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * public void add(NestedInteger ni);\n *\n * // @return the nested list that this NestedInteger holds, if it holds a nested list\n * // Return empty list if this NestedInteger holds a single integer\n * public List getList();\n * }\n */\nclass Solution {\n public int depthSum(List nestedList) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# \"\"\"\n# This is the interface that allows for creating nested lists.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class NestedInteger(object):\n# def __init__(self, value=None):\n# \"\"\"\n# If value is not specified, initializes an empty list.\n# Otherwise initializes a single integer equal to value.\n# \"\"\"\n#\n# def isInteger(self):\n# \"\"\"\n# @return True if this NestedInteger holds a single integer, rather than a nested list.\n# :rtype bool\n# \"\"\"\n#\n# def add(self, elem):\n# \"\"\"\n# Set this NestedInteger to hold a nested list and adds a nested integer elem to it.\n# :rtype void\n# \"\"\"\n#\n# def setInteger(self, value):\n# \"\"\"\n# Set this NestedInteger to hold a single integer equal to value.\n# :rtype void\n# \"\"\"\n#\n# def getInteger(self):\n# \"\"\"\n# @return the single integer that this NestedInteger holds, if it holds a single integer\n# Return None if this NestedInteger holds a nested list\n# :rtype int\n# \"\"\"\n#\n# def getList(self):\n# \"\"\"\n# @return the nested list that this NestedInteger holds, if it holds a nested list\n# Return None if this NestedInteger holds a single integer\n# :rtype List[NestedInteger]\n# \"\"\"\nclass Solution(object):\n def depthSum(self, nestedList):\n \"\"\"\n :type nestedList: List[NestedInteger]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# \"\"\"\n# This is the interface that allows for creating nested lists.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n#class NestedInteger:\n# def __init__(self, value=None):\n# \"\"\"\n# If value is not specified, initializes an empty list.\n# Otherwise initializes a single integer equal to value.\n# \"\"\"\n#\n# def isInteger(self):\n# \"\"\"\n# @return True if this NestedInteger holds a single integer, rather than a nested list.\n# :rtype bool\n# \"\"\"\n#\n# def add(self, elem):\n# \"\"\"\n# Set this NestedInteger to hold a nested list and adds a nested integer elem to it.\n# :rtype void\n# \"\"\"\n#\n# def setInteger(self, value):\n# \"\"\"\n# Set this NestedInteger to hold a single integer equal to value.\n# :rtype void\n# \"\"\"\n#\n# def getInteger(self):\n# \"\"\"\n# @return the single integer that this NestedInteger holds, if it holds a single integer\n# Return None if this NestedInteger holds a nested list\n# :rtype int\n# \"\"\"\n#\n# def getList(self):\n# \"\"\"\n# @return the nested list that this NestedInteger holds, if it holds a nested list\n# Return None if this NestedInteger holds a single integer\n# :rtype List[NestedInteger]\n# \"\"\"\nclass Solution:\n def depthSum(self, nestedList: List[NestedInteger]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * *********************************************************************\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * *********************************************************************\n *\n * // Initializes an empty nested list and return a reference to the nested integer.\n * struct NestedInteger *NestedIntegerInit();\n *\n * // Return true if this NestedInteger holds a single integer, rather than a nested list.\n * bool NestedIntegerIsInteger(struct NestedInteger *);\n *\n * // Return the single integer that this NestedInteger holds, if it holds a single integer\n * // The result is undefined if this NestedInteger holds a nested list\n * int NestedIntegerGetInteger(struct NestedInteger *);\n *\n * // Set this NestedInteger to hold a single integer.\n * void NestedIntegerSetInteger(struct NestedInteger *ni, int value);\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer elem to it.\n * void NestedIntegerAdd(struct NestedInteger *ni, struct NestedInteger *elem);\n *\n * // Return the nested list that this NestedInteger holds, if it holds a nested list\n * // The result is undefined if this NestedInteger holds a single integer\n * struct NestedInteger **NestedIntegerGetList(struct NestedInteger *);\n *\n * // Return the nested list's size that this NestedInteger holds, if it holds a nested list\n * // The result is undefined if this NestedInteger holds a single integer\n * int NestedIntegerGetListSize(struct NestedInteger *);\n * };\n */\n\n\nint depthSum(struct NestedInteger** nestedList, int nestedListSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * interface NestedInteger {\n *\n * // Constructor initializes an empty nested list.\n * public NestedInteger();\n *\n * // Constructor initializes a single integer.\n * public NestedInteger(int value);\n *\n * // @return true if this NestedInteger holds a single integer, rather than a nested list.\n * bool IsInteger();\n *\n * // @return the single integer that this NestedInteger holds, if it holds a single integer\n * // Return null if this NestedInteger holds a nested list\n * int GetInteger();\n *\n * // Set this NestedInteger to hold a single integer.\n * public void SetInteger(int value);\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * public void Add(NestedInteger ni);\n *\n * // @return the nested list that this NestedInteger holds, if it holds a nested list\n * // Return null if this NestedInteger holds a single integer\n * IList GetList();\n * }\n */\npublic class Solution {\n public int DepthSum(IList nestedList) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * function NestedInteger() {\n *\n * Return true if this NestedInteger holds a single integer, rather than a nested list.\n * @return {boolean}\n * this.isInteger = function() {\n * ...\n * };\n *\n * Return the single integer that this NestedInteger holds, if it holds a single integer\n * Return null if this NestedInteger holds a nested list\n * @return {integer}\n * this.getInteger = function() {\n * ...\n * };\n *\n * Set this NestedInteger to hold a single integer equal to value.\n * @return {void}\n * this.setInteger = function(value) {\n * ...\n * };\n *\n * Set this NestedInteger to hold a nested list and adds a nested integer elem to it.\n * @return {void}\n * this.add = function(elem) {\n * ...\n * };\n *\n * Return the nested list that this NestedInteger holds, if it holds a nested list\n * Return null if this NestedInteger holds a single integer\n * @return {NestedInteger[]}\n * this.getList = function() {\n * ...\n * };\n * };\n */\n/**\n * @param {NestedInteger[]} nestedList\n * @return {number}\n */\nvar depthSum = function(nestedList) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# This is the interface that allows for creating nested lists.\n# You should not implement it, or speculate about its implementation\n#\n#class NestedInteger\n# def is_integer()\n# \"\"\"\n# Return true if this NestedInteger holds a single integer, rather than a nested list.\n# @return {Boolean}\n# \"\"\"\n#\n# def get_integer()\n# \"\"\"\n# Return the single integer that this NestedInteger holds, if it holds a single integer\n# Return nil if this NestedInteger holds a nested list\n# @return {Integer}\n# \"\"\"\n#\n# def set_integer(value)\n# \"\"\"\n# Set this NestedInteger to hold a single integer equal to value.\n# @return {Void}\n# \"\"\"\n#\n# def add(elem)\n# \"\"\"\n# Set this NestedInteger to hold a nested list and adds a nested integer elem to it.\n# @return {Void}\n# \"\"\"\n#\n# def get_list()\n# \"\"\"\n# Return the nested list that this NestedInteger holds, if it holds a nested list\n# Return nil if this NestedInteger holds a single integer\n# @return {NestedInteger[]}\n# \"\"\"\n# @param {NestedInteger[]} nested_list\n# @return {Integer}\ndef depth_sum(nested_list)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * class NestedInteger {\n * // Return true if this NestedInteger holds a single integer, rather than a nested list.\n * public func isInteger() -> Bool\n *\n * // Return the single integer that this NestedInteger holds, if it holds a single integer\n * // The result is undefined if this NestedInteger holds a nested list\n * public func getInteger() -> Int\n *\n * // Set this NestedInteger to hold a single integer.\n * public func setInteger(value: Int)\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * public func add(elem: NestedInteger)\n *\n * // Return the nested list that this NestedInteger holds, if it holds a nested list\n * // The result is undefined if this NestedInteger holds a single integer\n * public func getList() -> [NestedInteger]\n * }\n */\nclass Solution {\n func depthSum(_ nestedList: [NestedInteger]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * type NestedInteger struct {\n * }\n *\n * // Return true if this NestedInteger holds a single integer, rather than a nested list.\n * func (n NestedInteger) IsInteger() bool {}\n *\n * // Return the single integer that this NestedInteger holds, if it holds a single integer\n * // The result is undefined if this NestedInteger holds a nested list\n * // So before calling this method, you should have a check\n * func (n NestedInteger) GetInteger() int {}\n *\n * // Set this NestedInteger to hold a single integer.\n * func (n *NestedInteger) SetInteger(value int) {}\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * func (n *NestedInteger) Add(elem NestedInteger) {}\n *\n * // Return the nested list that this NestedInteger holds, if it holds a nested list\n * // The list length is zero if this NestedInteger holds a single integer\n * // You can access NestedInteger's List element directly if you want to modify it\n * func (n NestedInteger) GetList() []*NestedInteger {}\n */\nfunc depthSum(nestedList []*NestedInteger) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * trait NestedInteger {\n *\n * // Return true if this NestedInteger holds a single integer, rather than a nested list.\n * def isInteger: Boolean\n *\n * // Return the single integer that this NestedInteger holds, if it holds a single integer.\n * def getInteger: Int\n *\n * // Set this NestedInteger to hold a single integer.\n * def setInteger(i: Int): Unit\n *\n * // Return the nested list that this NestedInteger holds, if it holds a nested list.\n * def getList: Array[NestedInteger]\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * def add(ni: NestedInteger): Unit\n * }\n */\nobject Solution {\n def depthSum(nestedList: List[NestedInteger]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * class NestedInteger {\n * // Constructor initializes an empty nested list.\n * constructor()\n *\n * // Constructor initializes a single integer.\n * constructor(value: Int)\n *\n * // @return true if this NestedInteger holds a single integer, rather than a nested list.\n * fun isInteger(): Boolean\n *\n * // @return the single integer that this NestedInteger holds, if it holds a single integer\n * // Return null if this NestedInteger holds a nested list\n * fun getInteger(): Int?\n *\n * // Set this NestedInteger to hold a single integer.\n * fun setInteger(value: Int): Unit\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * fun add(ni: NestedInteger): Unit\n *\n * // @return the nested list that this NestedInteger holds, if it holds a nested list\n * // Return null if this NestedInteger holds a single integer\n * fun getList(): List?\n * }\n */\nclass Solution {\n fun depthSum(nestedList: List): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// #[derive(Debug, PartialEq, Eq)]\n// pub enum NestedInteger {\n// Int(i32),\n// List(Vec)\n// }\nimpl Solution {\n pub fn depth_sum(nested_list: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * class NestedInteger {\n\n * // if value is not specified, initializes an empty list.\n * // Otherwise initializes a single integer equal to value.\n * function __construct($value = null)\n\n * // Return true if this NestedInteger holds a single integer, rather than a nested list.\n * function isInteger() : bool\n *\n * // Return the single integer that this NestedInteger holds, if it holds a single integer\n * // The result is undefined if this NestedInteger holds a nested list\n * function getInteger()\n *\n * // Set this NestedInteger to hold a single integer.\n * function setInteger($i) : void\n *\n * // Set this NestedInteger to hold a nested list and adds a nested integer to it.\n * function add($ni) : void\n *\n * // Return the nested list that this NestedInteger holds, if it holds a nested list\n * // The result is undefined if this NestedInteger holds a single integer\n * function getList() : array\n * }\n */\nclass Solution {\n\n /**\n * @param NestedInteger[] $nestedList\n * @return Integer\n */\n function depthSum($nestedList) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * // This is the interface that allows for creating nested lists.\n * // You should not implement it, or speculate about its implementation\n * class NestedInteger {\n * If value is provided, then it holds a single integer\n * Otherwise it holds an empty nested list\n * constructor(value?: number) {\n * ...\n * };\n *\n * Return true if this NestedInteger holds a single integer, rather than a nested list.\n * isInteger(): boolean {\n * ...\n * };\n *\n * Return the single integer that this NestedInteger holds, if it holds a single integer\n * Return null if this NestedInteger holds a nested list\n * getInteger(): number | null {\n * ...\n * };\n *\n * Set this NestedInteger to hold a single integer equal to value.\n * setInteger(value: number) {\n * ...\n * };\n *\n * Set this NestedInteger to hold a nested list and adds a nested integer elem to it.\n * add(elem: NestedInteger) {\n * ...\n * };\n *\n * Return the nested list that this NestedInteger holds,\n * or an empty list if this NestedInteger holds a single integer\n * getList(): NestedInteger[] {\n * ...\n * };\n * };\n */\n\nfunction depthSum(nestedList: NestedInteger[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": ";; This is the interface that allows for creating nested lists.\n;; You should not implement it, or speculate about its implementation\n\n#|\n\n(define nested-integer%\n (class object%\n ...\n\n ; Return true if this nested-integer% holds a single integer, rather than a nested list.\n ; -> boolean?\n (define/public (is-integer)\n ...)\n\n ; Return the single integer that this nested-integer% holds, if it holds a single integer,\n ; or #f if this nested-integer% holds a nested list.\n ; -> integer?\n (define/public (get-integer)\n ...)\n\n ; Set this nested-integer% to hold a single integer equal to value.\n ; -> integer? void?\n (define/public (set-integer i)\n ...)\n\n ; Set this nested-integer% to hold a nested list and adds a nested integer elem to it.\n ; -> (is-a?/c nested-integer%) void?\n (define/public (add ni)\n ...)\n\n ; Return the nested list that this nested-integer% holds,\n ; or an empty list if this nested-integer% holds a single integer.\n ; -> gvector?\n (define/public (get-list)\n ...)))\n\n|#\n\n(define/contract (depth-sum nestedList)\n (-> (listof (is-a?/c nested-integer%)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0339](https://leetcode-cn.com/problems/nested-list-weight-sum)", "[\u5d4c\u5957\u5217\u8868\u6743\u91cd\u548c](/solution/0300-0399/0339.Nested%20List%20Weight%20Sum/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0339](https://leetcode.com/problems/nested-list-weight-sum)", "[Nested List Weight Sum](/solution/0300-0399/0339.Nested%20List%20Weight%20Sum/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`", "Medium", "\ud83d\udd12"]}, {"question_id": "0338", "frontend_question_id": "0338", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/counting-bits", "url_en": "https://leetcode.com/problems/counting-bits", "relative_path_cn": "/solution/0300-0399/0338.Counting%20Bits/README.md", "relative_path_en": "/solution/0300-0399/0338.Counting%20Bits/README_EN.md", "title_cn": "\u6bd4\u7279\u4f4d\u8ba1\u6570", "title_en": "Counting Bits", "question_title_slug": "counting-bits", "content_en": "

    Given an integer n, return an array ans of length n + 1 such that for each i (0 <= i <= n), ans[i] is the number of 1's in the binary representation of i.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 2\nOutput: [0,1,1]\nExplanation:\n0 --> 0\n1 --> 1\n2 --> 10\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 5\nOutput: [0,1,1,2,1,2]\nExplanation:\n0 --> 0\n1 --> 1\n2 --> 10\n3 --> 11\n4 --> 100\n5 --> 101\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= n <= 105
    • \n
    \n\n

     

    \n

    Follow up:

    \n\n
      \n\t
    • It is very easy to come up with a solution with a runtime of O(n log n). Can you do it in linear time O(n) and possibly in a single pass?
    • \n\t
    • Can you do it without using any built-in function (i.e., like __builtin_popcount in C++)?
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u8d1f\u6574\u6570 num\u3002\u5bf9\u4e8e 0 ≤ i ≤ num \u8303\u56f4\u4e2d\u7684\u6bcf\u4e2a\u6570\u5b57 \uff0c\u8ba1\u7b97\u5176\u4e8c\u8fdb\u5236\u6570\u4e2d\u7684 1 \u7684\u6570\u76ee\u5e76\u5c06\u5b83\u4eec\u4f5c\u4e3a\u6570\u7ec4\u8fd4\u56de\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: 2\n\u8f93\u51fa: [0,1,1]
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: 5\n\u8f93\u51fa: [0,1,1,2,1,2]
    \n\n

    \u8fdb\u9636:

    \n\n
      \n\t
    • \u7ed9\u51fa\u65f6\u95f4\u590d\u6742\u5ea6\u4e3aO(n*sizeof(integer))\u7684\u89e3\u7b54\u975e\u5e38\u5bb9\u6613\u3002\u4f46\u4f60\u53ef\u4ee5\u5728\u7ebf\u6027\u65f6\u95f4O(n)\u5185\u7528\u4e00\u8d9f\u626b\u63cf\u505a\u5230\u5417\uff1f
    • \n\t
    • \u8981\u6c42\u7b97\u6cd5\u7684\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3aO(n)\u3002
    • \n\t
    • \u4f60\u80fd\u8fdb\u4e00\u6b65\u5b8c\u5584\u89e3\u6cd5\u5417\uff1f\u8981\u6c42\u5728C++\u6216\u4efb\u4f55\u5176\u4ed6\u8bed\u8a00\u4e2d\u4e0d\u4f7f\u7528\u4efb\u4f55\u5185\u7f6e\u51fd\u6570\uff08\u5982 C++ \u4e2d\u7684 __builtin_popcount\uff09\u6765\u6267\u884c\u6b64\u64cd\u4f5c\u3002
    • \n
    \n", "tags_en": ["Bit Manipulation", "Dynamic Programming"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector countBits(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] countBits(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countBits(self, n):\n \"\"\"\n :type n: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countBits(self, n: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* countBits(int n, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] CountBits(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number[]}\n */\nvar countBits = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer[]}\ndef count_bits(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countBits(_ n: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countBits(n int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countBits(n: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countBits(n: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_bits(n: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer[]\n */\n function countBits($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countBits(n: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-bits n)\n (-> exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0338](https://leetcode-cn.com/problems/counting-bits)", "[\u6bd4\u7279\u4f4d\u8ba1\u6570](/solution/0300-0399/0338.Counting%20Bits/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u52a8\u6001\u89c4\u5212`", "\u7b80\u5355", ""], "md_table_row_en": ["[0338](https://leetcode.com/problems/counting-bits)", "[Counting Bits](/solution/0300-0399/0338.Counting%20Bits/README_EN.md)", "`Bit Manipulation`,`Dynamic Programming`", "Easy", ""]}, {"question_id": "0337", "frontend_question_id": "0337", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/house-robber-iii", "url_en": "https://leetcode.com/problems/house-robber-iii", "relative_path_cn": "/solution/0300-0399/0337.House%20Robber%20III/README.md", "relative_path_en": "/solution/0300-0399/0337.House%20Robber%20III/README_EN.md", "title_cn": "\u6253\u5bb6\u52ab\u820d III", "title_en": "House Robber III", "question_title_slug": "house-robber-iii", "content_en": "

    The thief has found himself a new place for his thievery again. There is only one entrance to this area, called root.

    \n\n

    Besides the root, each house has one and only one parent house. After a tour, the smart thief realized that all houses in this place form a binary tree. It will automatically contact the police if two directly-linked houses were broken into on the same night.

    \n\n

    Given the root of the binary tree, return the maximum amount of money the thief can rob without alerting the police.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [3,2,3,null,3,null,1]\nOutput: 7\nExplanation: Maximum amount of money the thief can rob = 3 + 3 + 1 = 7.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [3,4,5,1,3,null,1]\nOutput: 9\nExplanation: Maximum amount of money the thief can rob = 4 + 5 = 9.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 104].
    • \n\t
    • 0 <= Node.val <= 104
    • \n
    \n", "content_cn": "

    \u5728\u4e0a\u6b21\u6253\u52ab\u5b8c\u4e00\u6761\u8857\u9053\u4e4b\u540e\u548c\u4e00\u5708\u623f\u5c4b\u540e\uff0c\u5c0f\u5077\u53c8\u53d1\u73b0\u4e86\u4e00\u4e2a\u65b0\u7684\u53ef\u884c\u7a83\u7684\u5730\u533a\u3002\u8fd9\u4e2a\u5730\u533a\u53ea\u6709\u4e00\u4e2a\u5165\u53e3\uff0c\u6211\u4eec\u79f0\u4e4b\u4e3a“\u6839”\u3002 \u9664\u4e86“\u6839”\u4e4b\u5916\uff0c\u6bcf\u680b\u623f\u5b50\u6709\u4e14\u53ea\u6709\u4e00\u4e2a“\u7236“\u623f\u5b50\u4e0e\u4e4b\u76f8\u8fde\u3002\u4e00\u756a\u4fa6\u5bdf\u4e4b\u540e\uff0c\u806a\u660e\u7684\u5c0f\u5077\u610f\u8bc6\u5230“\u8fd9\u4e2a\u5730\u65b9\u7684\u6240\u6709\u623f\u5c4b\u7684\u6392\u5217\u7c7b\u4f3c\u4e8e\u4e00\u68f5\u4e8c\u53c9\u6811”\u3002 \u5982\u679c\u4e24\u4e2a\u76f4\u63a5\u76f8\u8fde\u7684\u623f\u5b50\u5728\u540c\u4e00\u5929\u665a\u4e0a\u88ab\u6253\u52ab\uff0c\u623f\u5c4b\u5c06\u81ea\u52a8\u62a5\u8b66\u3002

    \n\n

    \u8ba1\u7b97\u5728\u4e0d\u89e6\u52a8\u8b66\u62a5\u7684\u60c5\u51b5\u4e0b\uff0c\u5c0f\u5077\u4e00\u665a\u80fd\u591f\u76d7\u53d6\u7684\u6700\u9ad8\u91d1\u989d\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: [3,2,3,null,3,null,1]\n\n     3\n    / \\\n   2   3\n    \\   \\ \n     3   1\n\n\u8f93\u51fa: 7 \n\u89e3\u91ca: \u5c0f\u5077\u4e00\u665a\u80fd\u591f\u76d7\u53d6\u7684\u6700\u9ad8\u91d1\u989d = 3 + 3 + 1 = 7.
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: [3,4,5,1,3,null,1]\n\n     3\n    / \\\n   4   5\n  / \\   \\ \n 1   3   1\n\n\u8f93\u51fa: 9\n\u89e3\u91ca: \u5c0f\u5077\u4e00\u665a\u80fd\u591f\u76d7\u53d6\u7684\u6700\u9ad8\u91d1\u989d = 4 + 5 = 9.\n
    \n", "tags_en": ["Tree", "Depth-first Search", "Dynamic Programming"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int rob(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int rob(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def rob(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def rob(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint rob(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int Rob(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar rob = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef rob(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func rob(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc rob(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def rob(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun rob(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn rob(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function rob($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction rob(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (rob root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0337](https://leetcode-cn.com/problems/house-robber-iii)", "[\u6253\u5bb6\u52ab\u820d III](/solution/0300-0399/0337.House%20Robber%20III/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0337](https://leetcode.com/problems/house-robber-iii)", "[House Robber III](/solution/0300-0399/0337.House%20Robber%20III/README_EN.md)", "`Tree`,`Depth-first Search`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0336", "frontend_question_id": "0336", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/palindrome-pairs", "url_en": "https://leetcode.com/problems/palindrome-pairs", "relative_path_cn": "/solution/0300-0399/0336.Palindrome%20Pairs/README.md", "relative_path_en": "/solution/0300-0399/0336.Palindrome%20Pairs/README_EN.md", "title_cn": "\u56de\u6587\u5bf9", "title_en": "Palindrome Pairs", "question_title_slug": "palindrome-pairs", "content_en": "

    Given a list of unique words, return all the pairs of the distinct indices (i, j) in the given list, so that the concatenation of the two words words[i] + words[j] is a palindrome.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: words = ["abcd","dcba","lls","s","sssll"]\nOutput: [[0,1],[1,0],[3,2],[2,4]]\nExplanation: The palindromes are ["dcbaabcd","abcddcba","slls","llssssll"]\n
    \n\n

    Example 2:

    \n\n
    \nInput: words = ["bat","tab","cat"]\nOutput: [[0,1],[1,0]]\nExplanation: The palindromes are ["battab","tabbat"]\n
    \n\n

    Example 3:

    \n\n
    \nInput: words = ["a",""]\nOutput: [[0,1],[1,0]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= words.length <= 5000
    • \n\t
    • 0 <= words[i].length <= 300
    • \n\t
    • words[i] consists of lower-case English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u7ec4 \u4e92\u4e0d\u76f8\u540c \u7684\u5355\u8bcd\uff0c \u627e\u51fa\u6240\u6709 \u4e0d\u540c\u00a0\u7684\u7d22\u5f15\u5bf9 (i, j)\uff0c\u4f7f\u5f97\u5217\u8868\u4e2d\u7684\u4e24\u4e2a\u5355\u8bcd\uff0c\u00a0words[i] + words[j]\u00a0\uff0c\u53ef\u62fc\u63a5\u6210\u56de\u6587\u4e32\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1awords = [\"abcd\",\"dcba\",\"lls\",\"s\",\"sssll\"]\n\u8f93\u51fa\uff1a[[0,1],[1,0],[3,2],[2,4]] \n\u89e3\u91ca\uff1a\u53ef\u62fc\u63a5\u6210\u7684\u56de\u6587\u4e32\u4e3a [\"dcbaabcd\",\"abcddcba\",\"slls\",\"llssssll\"]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1awords = [\"bat\",\"tab\",\"cat\"]\n\u8f93\u51fa\uff1a[[0,1],[1,0]] \n\u89e3\u91ca\uff1a\u53ef\u62fc\u63a5\u6210\u7684\u56de\u6587\u4e32\u4e3a [\"battab\",\"tabbat\"]
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1awords = [\"a\",\"\"]\n\u8f93\u51fa\uff1a[[0,1],[1,0]]\n
    \n\u00a0\n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= words.length <= 5000
    • \n\t
    • 0 <= words[i].length <= 300
    • \n\t
    • words[i] \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n", "tags_en": ["Trie", "Hash Table", "String"], "tags_cn": ["\u5b57\u5178\u6811", "\u54c8\u5e0c\u8868", "\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> palindromePairs(vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> palindromePairs(String[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def palindromePairs(self, words):\n \"\"\"\n :type words: List[str]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def palindromePairs(self, words: List[str]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** palindromePairs(char ** words, int wordsSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> PalindromePairs(string[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @return {number[][]}\n */\nvar palindromePairs = function(words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @return {Integer[][]}\ndef palindrome_pairs(words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func palindromePairs(_ words: [String]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func palindromePairs(words []string) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def palindromePairs(words: Array[String]): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun palindromePairs(words: Array): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn palindrome_pairs(words: Vec) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @return Integer[][]\n */\n function palindromePairs($words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function palindromePairs(words: string[]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (palindrome-pairs words)\n (-> (listof string?) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0336](https://leetcode-cn.com/problems/palindrome-pairs)", "[\u56de\u6587\u5bf9](/solution/0300-0399/0336.Palindrome%20Pairs/README.md)", "`\u5b57\u5178\u6811`,`\u54c8\u5e0c\u8868`,`\u5b57\u7b26\u4e32`", "\u56f0\u96be", ""], "md_table_row_en": ["[0336](https://leetcode.com/problems/palindrome-pairs)", "[Palindrome Pairs](/solution/0300-0399/0336.Palindrome%20Pairs/README_EN.md)", "`Trie`,`Hash Table`,`String`", "Hard", ""]}, {"question_id": "0335", "frontend_question_id": "0335", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/self-crossing", "url_en": "https://leetcode.com/problems/self-crossing", "relative_path_cn": "/solution/0300-0399/0335.Self%20Crossing/README.md", "relative_path_en": "/solution/0300-0399/0335.Self%20Crossing/README_EN.md", "title_cn": "\u8def\u5f84\u4ea4\u53c9", "title_en": "Self Crossing", "question_title_slug": "self-crossing", "content_en": "

    You are given an array of integers distance.

    \n\n

    You start at point (0,0) on an X-Y plane and you move distance[0] meters to the north, then distance[1] meters to the west, distance[2] meters to the south, distance[3] meters to the east, and so on. In other words, after each move, your direction changes counter-clockwise.

    \n\n

    Return true if your path crosses itself, and false if it does not.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: distance = [2,1,1,2]\nOutput: true\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: distance = [1,2,3,4]\nOutput: false\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: distance = [1,1,1,1]\nOutput: true\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= distance.length <= 105
    • \n\t
    • 1 <= distance[i] <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u542b\u6709 n \u4e2a\u6b63\u6570\u7684\u6570\u7ec4 x\u3002\u4ece\u70b9 (0,0) \u5f00\u59cb\uff0c\u5148\u5411\u5317\u79fb\u52a8 x[0] \u7c73\uff0c\u7136\u540e\u5411\u897f\u79fb\u52a8 x[1] \u7c73\uff0c\u5411\u5357\u79fb\u52a8 x[2] \u7c73\uff0c\u5411\u4e1c\u79fb\u52a8 x[3] \u7c73\uff0c\u6301\u7eed\u79fb\u52a8\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u6bcf\u6b21\u79fb\u52a8\u540e\u4f60\u7684\u65b9\u4f4d\u4f1a\u53d1\u751f\u9006\u65f6\u9488\u53d8\u5316\u3002

    \n\n

    \u7f16\u5199\u4e00\u4e2a O(1) \u7a7a\u95f4\u590d\u6742\u5ea6\u7684\u4e00\u8d9f\u626b\u63cf\u7b97\u6cd5\uff0c\u5224\u65ad\u4f60\u6240\u7ecf\u8fc7\u7684\u8def\u5f84\u662f\u5426\u76f8\u4ea4\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u250c\u2500\u2500\u2500\u2510\n\u2502   \u2502\n\u2514\u2500\u2500\u2500\u253c\u2500\u2500>\n    \u2502\n\n\u8f93\u5165: [2,1,1,2]\n\u8f93\u51fa: true \n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n\u2502      \u2502\n\u2502\n\u2502\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500>\n\n\u8f93\u5165: [1,2,3,4]\n\u8f93\u51fa: false \n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u250c\u2500\u2500\u2500\u2510\n\u2502   \u2502\n\u2514\u2500\u2500\u2500\u253c>\n\n\u8f93\u5165: [1,1,1,1]\n\u8f93\u51fa: true \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isSelfCrossing(vector& distance) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isSelfCrossing(int[] distance) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isSelfCrossing(self, distance):\n \"\"\"\n :type distance: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isSelfCrossing(self, distance: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isSelfCrossing(int* distance, int distanceSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsSelfCrossing(int[] distance) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} distance\n * @return {boolean}\n */\nvar isSelfCrossing = function(distance) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} distance\n# @return {Boolean}\ndef is_self_crossing(distance)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isSelfCrossing(_ distance: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isSelfCrossing(distance []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isSelfCrossing(distance: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isSelfCrossing(distance: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_self_crossing(distance: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $distance\n * @return Boolean\n */\n function isSelfCrossing($distance) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isSelfCrossing(distance: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-self-crossing distance)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0335](https://leetcode-cn.com/problems/self-crossing)", "[\u8def\u5f84\u4ea4\u53c9](/solution/0300-0399/0335.Self%20Crossing/README.md)", "`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[0335](https://leetcode.com/problems/self-crossing)", "[Self Crossing](/solution/0300-0399/0335.Self%20Crossing/README_EN.md)", "`Math`", "Hard", ""]}, {"question_id": "0334", "frontend_question_id": "0334", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/increasing-triplet-subsequence", "url_en": "https://leetcode.com/problems/increasing-triplet-subsequence", "relative_path_cn": "/solution/0300-0399/0334.Increasing%20Triplet%20Subsequence/README.md", "relative_path_en": "/solution/0300-0399/0334.Increasing%20Triplet%20Subsequence/README_EN.md", "title_cn": "\u9012\u589e\u7684\u4e09\u5143\u5b50\u5e8f\u5217", "title_en": "Increasing Triplet Subsequence", "question_title_slug": "increasing-triplet-subsequence", "content_en": "

    Given an integer array nums, return true if there exists a triple of indices (i, j, k) such that i < j < k and nums[i] < nums[j] < nums[k]. If no such indices exists, return false.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,3,4,5]\nOutput: true\nExplanation: Any triplet where i < j < k is valid.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [5,4,3,2,1]\nOutput: false\nExplanation: No triplet exists.\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [2,1,5,0,4,6]\nOutput: true\nExplanation: The triplet (3, 4, 5) is valid because nums[3] == 0 < nums[4] == 4 < nums[5] == 6.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 5 * 105
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n
    \n\n

     

    \nFollow up: Could you implement a solution that runs in O(n) time complexity and O(1) space complexity?", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0nums \uff0c\u5224\u65ad\u8fd9\u4e2a\u6570\u7ec4\u4e2d\u662f\u5426\u5b58\u5728\u957f\u5ea6\u4e3a 3 \u7684\u9012\u589e\u5b50\u5e8f\u5217\u3002

    \n\n

    \u5982\u679c\u5b58\u5728\u8fd9\u6837\u7684\u4e09\u5143\u7ec4\u4e0b\u6807 (i, j, k)\u00a0\u4e14\u6ee1\u8db3 i < j < k \uff0c\u4f7f\u5f97\u00a0nums[i] < nums[j] < nums[k] \uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,3,4,5]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u4efb\u4f55 i < j < k \u7684\u4e09\u5143\u7ec4\u90fd\u6ee1\u8db3\u9898\u610f\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [5,4,3,2,1]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u4e0d\u5b58\u5728\u6ee1\u8db3\u9898\u610f\u7684\u4e09\u5143\u7ec4
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [2,1,5,0,4,6]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u4e09\u5143\u7ec4 (3, 4, 5) \u6ee1\u8db3\u9898\u610f\uff0c\u56e0\u4e3a nums[3] == 0 < nums[4] == 4 < nums[5] == 6\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u80fd\u5b9e\u73b0\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n) \uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a O(1) \u7684\u89e3\u51b3\u65b9\u6848\u5417\uff1f

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool increasingTriplet(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean increasingTriplet(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def increasingTriplet(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def increasingTriplet(self, nums: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool increasingTriplet(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IncreasingTriplet(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {boolean}\n */\nvar increasingTriplet = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Boolean}\ndef increasing_triplet(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func increasingTriplet(_ nums: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func increasingTriplet(nums []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def increasingTriplet(nums: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun increasingTriplet(nums: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn increasing_triplet(nums: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Boolean\n */\n function increasingTriplet($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function increasingTriplet(nums: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (increasing-triplet nums)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0334](https://leetcode-cn.com/problems/increasing-triplet-subsequence)", "[\u9012\u589e\u7684\u4e09\u5143\u5b50\u5e8f\u5217](/solution/0300-0399/0334.Increasing%20Triplet%20Subsequence/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0334](https://leetcode.com/problems/increasing-triplet-subsequence)", "[Increasing Triplet Subsequence](/solution/0300-0399/0334.Increasing%20Triplet%20Subsequence/README_EN.md)", "", "Medium", ""]}, {"question_id": "0333", "frontend_question_id": "0333", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/largest-bst-subtree", "url_en": "https://leetcode.com/problems/largest-bst-subtree", "relative_path_cn": "/solution/0300-0399/0333.Largest%20BST%20Subtree/README.md", "relative_path_en": "/solution/0300-0399/0333.Largest%20BST%20Subtree/README_EN.md", "title_cn": "\u6700\u5927 BST \u5b50\u6811", "title_en": "Largest BST Subtree", "question_title_slug": "largest-bst-subtree", "content_en": "

    Given the root of a binary tree, find the largest subtree, which is also a Binary Search Tree (BST), where the largest means subtree has the largest number of nodes.

    \n\n

    A Binary Search Tree (BST) is a tree in which all the nodes follow the below-mentioned properties:

    \n\n
      \n\t
    • The left subtree values are less than the value of their parent (root) node's value.
    • \n\t
    • The right subtree values are greater than the value of their parent (root) node's value.
    • \n
    \n\n

    Note: A subtree must include all of its descendants.

    \n\n

    Follow up: Can you figure out ways to solve it with O(n) time complexity?

    \n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: root = [10,5,15,1,8,null,7]\nOutput: 3\nExplanation: The Largest BST Subtree in this case is the highlighted one. The return value is the subtree's size, which is 3.
    \n\n

    Example 2:

    \n\n
    \nInput: root = [4,2,7,2,3,5,null,2,null,null,null,null,null,1]\nOutput: 2\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [0, 104].
    • \n\t
    • -104 <= Node.val <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811\uff0c\u627e\u5230\u5176\u4e2d\u6700\u5927\u7684\u4e8c\u53c9\u641c\u7d22\u6811\uff08BST\uff09\u5b50\u6811\uff0c\u5e76\u8fd4\u56de\u8be5\u5b50\u6811\u7684\u5927\u5c0f\u3002\u5176\u4e2d\uff0c\u6700\u5927\u6307\u7684\u662f\u5b50\u6811\u8282\u70b9\u6570\u6700\u591a\u7684\u3002

    \n\n

    \u4e8c\u53c9\u641c\u7d22\u6811\uff08BST\uff09\u4e2d\u7684\u6240\u6709\u8282\u70b9\u90fd\u5177\u5907\u4ee5\u4e0b\u5c5e\u6027\uff1a

    \n\n
      \n\t
    • \n\t

      \u5de6\u5b50\u6811\u7684\u503c\u5c0f\u4e8e\u5176\u7236\uff08\u6839\uff09\u8282\u70b9\u7684\u503c\u3002

      \n\t
    • \n\t
    • \n\t

      \u53f3\u5b50\u6811\u7684\u503c\u5927\u4e8e\u5176\u7236\uff08\u6839\uff09\u8282\u70b9\u7684\u503c\u3002

      \n\t
    • \n
    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    • \u5b50\u6811\u5fc5\u987b\u5305\u542b\u5176\u6240\u6709\u540e\u4ee3\u3002
    • \n
    \n\n

    \u8fdb\u9636:

    \n\n
      \n\t
    • \u4f60\u80fd\u60f3\u51fa O(n) \u65f6\u95f4\u590d\u6742\u5ea6\u7684\u89e3\u6cd5\u5417\uff1f
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aroot = [10,5,15,1,8,null,7]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u672c\u4f8b\u4e2d\u6700\u5927\u7684 BST \u5b50\u6811\u662f\u9ad8\u4eae\u663e\u793a\u7684\u5b50\u6811\u3002\u8fd4\u56de\u503c\u662f\u5b50\u6811\u7684\u5927\u5c0f\uff0c\u5373 3 \u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [4,2,7,2,3,5,null,2,null,null,null,null,null,1]\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e0a\u8282\u70b9\u6570\u76ee\u7684\u8303\u56f4\u662f [0, 104]
    • \n\t
    • -104 <= Node.val <= 104
    • \n
    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int largestBSTSubtree(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int largestBSTSubtree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def largestBSTSubtree(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def largestBSTSubtree(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint largestBSTSubtree(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int LargestBSTSubtree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar largestBSTSubtree = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef largest_bst_subtree(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func largestBSTSubtree(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc largestBSTSubtree(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def largestBSTSubtree(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun largestBSTSubtree(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn largest_bst_subtree(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function largestBSTSubtree($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction largestBSTSubtree(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (largest-bst-subtree root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0333](https://leetcode-cn.com/problems/largest-bst-subtree)", "[\u6700\u5927 BST \u5b50\u6811](/solution/0300-0399/0333.Largest%20BST%20Subtree/README.md)", "`\u6811`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0333](https://leetcode.com/problems/largest-bst-subtree)", "[Largest BST Subtree](/solution/0300-0399/0333.Largest%20BST%20Subtree/README_EN.md)", "`Tree`", "Medium", "\ud83d\udd12"]}, {"question_id": "0332", "frontend_question_id": "0332", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reconstruct-itinerary", "url_en": "https://leetcode.com/problems/reconstruct-itinerary", "relative_path_cn": "/solution/0300-0399/0332.Reconstruct%20Itinerary/README.md", "relative_path_en": "/solution/0300-0399/0332.Reconstruct%20Itinerary/README_EN.md", "title_cn": "\u91cd\u65b0\u5b89\u6392\u884c\u7a0b", "title_en": "Reconstruct Itinerary", "question_title_slug": "reconstruct-itinerary", "content_en": "

    You are given a list of airline tickets where tickets[i] = [fromi, toi] represent the departure and the arrival airports of one flight. Reconstruct the itinerary in order and return it.

    \n\n

    All of the tickets belong to a man who departs from "JFK", thus, the itinerary must begin with "JFK". If there are multiple valid itineraries, you should return the itinerary that has the smallest lexical order when read as a single string.

    \n\n
      \n\t
    • For example, the itinerary ["JFK", "LGA"] has a smaller lexical order than ["JFK", "LGB"].
    • \n
    \n\n

    You may assume all tickets form at least one valid itinerary. You must use all the tickets once and only once.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: tickets = [["MUC","LHR"],["JFK","MUC"],["SFO","SJC"],["LHR","SFO"]]\nOutput: ["JFK","MUC","LHR","SFO","SJC"]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: tickets = [["JFK","SFO"],["JFK","ATL"],["SFO","ATL"],["ATL","JFK"],["ATL","SFO"]]\nOutput: ["JFK","ATL","JFK","SFO","ATL","SFO"]\nExplanation: Another possible reconstruction is ["JFK","SFO","ATL","JFK","ATL","SFO"] but it is larger in lexical order.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= tickets.length <= 300
    • \n\t
    • tickets[i].length == 2
    • \n\t
    • fromi.length == 3
    • \n\t
    • toi.length == 3
    • \n\t
    • fromi and toi consist of uppercase English letters.
    • \n\t
    • fromi != toi
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u673a\u7968\u7684\u5b57\u7b26\u4e32\u4e8c\u7ef4\u6570\u7ec4 [from, to]\uff0c\u5b50\u6570\u7ec4\u4e2d\u7684\u4e24\u4e2a\u6210\u5458\u5206\u522b\u8868\u793a\u98de\u673a\u51fa\u53d1\u548c\u964d\u843d\u7684\u673a\u573a\u5730\u70b9\uff0c\u5bf9\u8be5\u884c\u7a0b\u8fdb\u884c\u91cd\u65b0\u89c4\u5212\u6392\u5e8f\u3002\u6240\u6709\u8fd9\u4e9b\u673a\u7968\u90fd\u5c5e\u4e8e\u4e00\u4e2a\u4ece JFK\uff08\u80af\u5c3c\u8fea\u56fd\u9645\u673a\u573a\uff09\u51fa\u53d1\u7684\u5148\u751f\uff0c\u6240\u4ee5\u8be5\u884c\u7a0b\u5fc5\u987b\u4ece JFK \u5f00\u59cb\u3002

    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. \u5982\u679c\u5b58\u5728\u591a\u79cd\u6709\u6548\u7684\u884c\u7a0b\uff0c\u8bf7\u4f60\u6309\u5b57\u7b26\u81ea\u7136\u6392\u5e8f\u8fd4\u56de\u6700\u5c0f\u7684\u884c\u7a0b\u7ec4\u5408\u3002\u4f8b\u5982\uff0c\u884c\u7a0b [\"JFK\", \"LGA\"] \u4e0e [\"JFK\", \"LGB\"] \u76f8\u6bd4\u5c31\u66f4\u5c0f\uff0c\u6392\u5e8f\u66f4\u9760\u524d
    2. \n\t
    3. \u6240\u6709\u7684\u673a\u573a\u90fd\u7528\u4e09\u4e2a\u5927\u5199\u5b57\u6bcd\u8868\u793a\uff08\u673a\u573a\u4ee3\u7801\uff09\u3002
    4. \n\t
    5. \u5047\u5b9a\u6240\u6709\u673a\u7968\u81f3\u5c11\u5b58\u5728\u4e00\u79cd\u5408\u7406\u7684\u884c\u7a0b\u3002
    6. \n\t
    7. \u6240\u6709\u7684\u673a\u7968\u5fc5\u987b\u90fd\u7528\u4e00\u6b21 \u4e14 \u53ea\u80fd\u7528\u4e00\u6b21\u3002
    8. \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[[\"MUC\", \"LHR\"], [\"JFK\", \"MUC\"], [\"SFO\", \"SJC\"], [\"LHR\", \"SFO\"]]\n\u8f93\u51fa\uff1a[\"JFK\", \"MUC\", \"LHR\", \"SFO\", \"SJC\"]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[[\"JFK\",\"SFO\"],[\"JFK\",\"ATL\"],[\"SFO\",\"ATL\"],[\"ATL\",\"JFK\"],[\"ATL\",\"SFO\"]]\n\u8f93\u51fa\uff1a[\"JFK\",\"ATL\",\"JFK\",\"SFO\",\"ATL\",\"SFO\"]\n\u89e3\u91ca\uff1a\u53e6\u4e00\u79cd\u6709\u6548\u7684\u884c\u7a0b\u662f\u00a0[\"JFK\",\"SFO\",\"ATL\",\"JFK\",\"ATL\",\"SFO\"]\u3002\u4f46\u662f\u5b83\u81ea\u7136\u6392\u5e8f\u66f4\u5927\u66f4\u9760\u540e\u3002
    \n", "tags_en": ["Depth-first Search", "Graph"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findItinerary(vector>& tickets) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List findItinerary(List> tickets) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findItinerary(self, tickets):\n \"\"\"\n :type tickets: List[List[str]]\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findItinerary(self, tickets: List[List[str]]) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** findItinerary(char *** tickets, int ticketsSize, int* ticketsColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList FindItinerary(IList> tickets) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[][]} tickets\n * @return {string[]}\n */\nvar findItinerary = function(tickets) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[][]} tickets\n# @return {String[]}\ndef find_itinerary(tickets)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findItinerary(_ tickets: [[String]]) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findItinerary(tickets [][]string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findItinerary(tickets: List[List[String]]): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findItinerary(tickets: List>): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_itinerary(tickets: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $tickets\n * @return String[]\n */\n function findItinerary($tickets) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findItinerary(tickets: string[][]): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-itinerary tickets)\n (-> (listof (listof string?)) (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0332](https://leetcode-cn.com/problems/reconstruct-itinerary)", "[\u91cd\u65b0\u5b89\u6392\u884c\u7a0b](/solution/0300-0399/0332.Reconstruct%20Itinerary/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u56fe`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0332](https://leetcode.com/problems/reconstruct-itinerary)", "[Reconstruct Itinerary](/solution/0300-0399/0332.Reconstruct%20Itinerary/README_EN.md)", "`Depth-first Search`,`Graph`", "Medium", ""]}, {"question_id": "0331", "frontend_question_id": "0331", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/verify-preorder-serialization-of-a-binary-tree", "url_en": "https://leetcode.com/problems/verify-preorder-serialization-of-a-binary-tree", "relative_path_cn": "/solution/0300-0399/0331.Verify%20Preorder%20Serialization%20of%20a%20Binary%20Tree/README.md", "relative_path_en": "/solution/0300-0399/0331.Verify%20Preorder%20Serialization%20of%20a%20Binary%20Tree/README_EN.md", "title_cn": "\u9a8c\u8bc1\u4e8c\u53c9\u6811\u7684\u524d\u5e8f\u5e8f\u5217\u5316", "title_en": "Verify Preorder Serialization of a Binary Tree", "question_title_slug": "verify-preorder-serialization-of-a-binary-tree", "content_en": "

    One way to serialize a binary tree is to use preorder traversal. When we encounter a non-null node, we record the node's value. If it is a null node, we record using a sentinel value such as '#'.

    \n\"\"\n

    For example, the above binary tree can be serialized to the string "9,3,4,#,#,1,#,#,2,#,6,#,#", where '#' represents a null node.

    \n\n

    Given a string of comma-separated values preorder, return true if it is a correct preorder traversal serialization of a binary tree.

    \n\n

    It is guaranteed that each comma-separated value in the string must be either an integer or a character '#' representing null pointer.

    \n\n

    You may assume that the input format is always valid.

    \n\n
      \n\t
    • For example, it could never contain two consecutive commas, such as "1,,3".
    • \n
    \n\n

    Note: You are not allowed to reconstruct the tree.

    \n\n

     

    \n

    Example 1:

    \n
    Input: preorder = \"9,3,4,#,#,1,#,#,2,#,6,#,#\"\nOutput: true\n

    Example 2:

    \n
    Input: preorder = \"1,#\"\nOutput: false\n

    Example 3:

    \n
    Input: preorder = \"9,#,#,1\"\nOutput: false\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= preorder.length <= 104
    • \n\t
    • preoder consist of integers in the range [0, 100] and '#' separated by commas ','.
    • \n
    \n", "content_cn": "

    \u5e8f\u5217\u5316\u4e8c\u53c9\u6811\u7684\u4e00\u79cd\u65b9\u6cd5\u662f\u4f7f\u7528\u524d\u5e8f\u904d\u5386\u3002\u5f53\u6211\u4eec\u9047\u5230\u4e00\u4e2a\u975e\u7a7a\u8282\u70b9\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u8bb0\u5f55\u4e0b\u8fd9\u4e2a\u8282\u70b9\u7684\u503c\u3002\u5982\u679c\u5b83\u662f\u4e00\u4e2a\u7a7a\u8282\u70b9\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e2a\u6807\u8bb0\u503c\u8bb0\u5f55\uff0c\u4f8b\u5982 #\u3002

    \n\n
         _9_\n    /   \\\n   3     2\n  / \\   / \\\n 4   1  #  6\n/ \\ / \\   / \\\n# # # #   # #\n
    \n\n

    \u4f8b\u5982\uff0c\u4e0a\u9762\u7684\u4e8c\u53c9\u6811\u53ef\u4ee5\u88ab\u5e8f\u5217\u5316\u4e3a\u5b57\u7b26\u4e32 "9,3,4,#,#,1,#,#,2,#,6,#,#"\uff0c\u5176\u4e2d # \u4ee3\u8868\u4e00\u4e2a\u7a7a\u8282\u70b9\u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u4e32\u4ee5\u9017\u53f7\u5206\u9694\u7684\u5e8f\u5217\uff0c\u9a8c\u8bc1\u5b83\u662f\u5426\u662f\u6b63\u786e\u7684\u4e8c\u53c9\u6811\u7684\u524d\u5e8f\u5e8f\u5217\u5316\u3002\u7f16\u5199\u4e00\u4e2a\u5728\u4e0d\u91cd\u6784\u6811\u7684\u6761\u4ef6\u4e0b\u7684\u53ef\u884c\u7b97\u6cd5\u3002

    \n\n

    \u6bcf\u4e2a\u4ee5\u9017\u53f7\u5206\u9694\u7684\u5b57\u7b26\u6216\u4e3a\u4e00\u4e2a\u6574\u6570\u6216\u4e3a\u4e00\u4e2a\u8868\u793a null \u6307\u9488\u7684 '#' \u3002

    \n\n

    \u4f60\u53ef\u4ee5\u8ba4\u4e3a\u8f93\u5165\u683c\u5f0f\u603b\u662f\u6709\u6548\u7684\uff0c\u4f8b\u5982\u5b83\u6c38\u8fdc\u4e0d\u4f1a\u5305\u542b\u4e24\u4e2a\u8fde\u7eed\u7684\u9017\u53f7\uff0c\u6bd4\u5982 "1,,3" \u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: "9,3,4,#,#,1,#,#,2,#,6,#,#"\n\u8f93\u51fa: true
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: "1,#"\n\u8f93\u51fa: false\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u8f93\u5165: "9,#,#,1"\n\u8f93\u51fa: false
    \n", "tags_en": ["Stack"], "tags_cn": ["\u6808"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isValidSerialization(string preorder) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isValidSerialization(String preorder) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isValidSerialization(self, preorder):\n \"\"\"\n :type preorder: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isValidSerialization(self, preorder: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isValidSerialization(char * preorder){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsValidSerialization(string preorder) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} preorder\n * @return {boolean}\n */\nvar isValidSerialization = function(preorder) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} preorder\n# @return {Boolean}\ndef is_valid_serialization(preorder)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isValidSerialization(_ preorder: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isValidSerialization(preorder string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isValidSerialization(preorder: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isValidSerialization(preorder: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_valid_serialization(preorder: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $preorder\n * @return Boolean\n */\n function isValidSerialization($preorder) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isValidSerialization(preorder: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-valid-serialization preorder)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0331](https://leetcode-cn.com/problems/verify-preorder-serialization-of-a-binary-tree)", "[\u9a8c\u8bc1\u4e8c\u53c9\u6811\u7684\u524d\u5e8f\u5e8f\u5217\u5316](/solution/0300-0399/0331.Verify%20Preorder%20Serialization%20of%20a%20Binary%20Tree/README.md)", "`\u6808`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0331](https://leetcode.com/problems/verify-preorder-serialization-of-a-binary-tree)", "[Verify Preorder Serialization of a Binary Tree](/solution/0300-0399/0331.Verify%20Preorder%20Serialization%20of%20a%20Binary%20Tree/README_EN.md)", "`Stack`", "Medium", ""]}, {"question_id": "0330", "frontend_question_id": "0330", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/patching-array", "url_en": "https://leetcode.com/problems/patching-array", "relative_path_cn": "/solution/0300-0399/0330.Patching%20Array/README.md", "relative_path_en": "/solution/0300-0399/0330.Patching%20Array/README_EN.md", "title_cn": "\u6309\u8981\u6c42\u8865\u9f50\u6570\u7ec4", "title_en": "Patching Array", "question_title_slug": "patching-array", "content_en": "

    Given a sorted integer array nums and an integer n, add/patch elements to the array such that any number in the range [1, n] inclusive can be formed by the sum of some elements in the array.

    \n\n

    Return the minimum number of patches required.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,3], n = 6\nOutput: 1\nExplanation:\nCombinations of nums are [1], [3], [1,3], which form possible sums of: 1, 3, 4.\nNow if we add/patch 2 to nums, the combinations are: [1], [2], [3], [1,3], [2,3], [1,2,3].\nPossible sums are 1, 2, 3, 4, 5, 6, which now covers the range [1, 6].\nSo we only need 1 patch.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,5,10], n = 20\nOutput: 2\nExplanation: The two patches can be [2, 4].\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [1,2,2], n = 5\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 1000
    • \n\t
    • 1 <= nums[i] <= 104
    • \n\t
    • nums is sorted in ascending order.
    • \n\t
    • 1 <= n <= 231 - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5df2\u6392\u5e8f\u7684\u6b63\u6574\u6570\u6570\u7ec4 nums\uff0c\u548c\u4e00\u4e2a\u6b63\u6574\u6570 n \u3002\u4ece [1, n] \u533a\u95f4\u5185\u9009\u53d6\u4efb\u610f\u4e2a\u6570\u5b57\u8865\u5145\u5230 nums \u4e2d\uff0c\u4f7f\u5f97 [1, n] \u533a\u95f4\u5185\u7684\u4efb\u4f55\u6570\u5b57\u90fd\u53ef\u4ee5\u7528 nums \u4e2d\u67d0\u51e0\u4e2a\u6570\u5b57\u7684\u548c\u6765\u8868\u793a\u3002\u8bf7\u8f93\u51fa\u6ee1\u8db3\u4e0a\u8ff0\u8981\u6c42\u7684\u6700\u5c11\u9700\u8981\u8865\u5145\u7684\u6570\u5b57\u4e2a\u6570\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: nums = [1,3], n = 6\n\u8f93\u51fa: 1 \n\u89e3\u91ca:\n\u6839\u636e nums \u91cc\u73b0\u6709\u7684\u7ec4\u5408 [1], [3], [1,3]\uff0c\u53ef\u4ee5\u5f97\u51fa 1, 3, 4\u3002\n\u73b0\u5728\u5982\u679c\u6211\u4eec\u5c06 2 \u6dfb\u52a0\u5230 nums \u4e2d\uff0c \u7ec4\u5408\u53d8\u4e3a: [1], [2], [3], [1,3], [2,3], [1,2,3]\u3002\n\u5176\u548c\u53ef\u4ee5\u8868\u793a\u6570\u5b57 1, 2, 3, 4, 5, 6\uff0c\u80fd\u591f\u8986\u76d6 [1, 6] \u533a\u95f4\u91cc\u6240\u6709\u7684\u6570\u3002\n\u6240\u4ee5\u6211\u4eec\u6700\u5c11\u9700\u8981\u6dfb\u52a0\u4e00\u4e2a\u6570\u5b57\u3002
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: nums = [1,5,10], n = 20\n\u8f93\u51fa: 2\n\u89e3\u91ca: \u6211\u4eec\u9700\u8981\u6dfb\u52a0 [2, 4]\u3002\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u8f93\u5165: nums = [1,2,2], n = 5\n\u8f93\u51fa: 0\n
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minPatches(vector& nums, int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minPatches(int[] nums, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minPatches(self, nums, n):\n \"\"\"\n :type nums: List[int]\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minPatches(self, nums: List[int], n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minPatches(int* nums, int numsSize, int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinPatches(int[] nums, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} n\n * @return {number}\n */\nvar minPatches = function(nums, n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} n\n# @return {Integer}\ndef min_patches(nums, n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minPatches(_ nums: [Int], _ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minPatches(nums []int, n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minPatches(nums: Array[Int], n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minPatches(nums: IntArray, n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_patches(nums: Vec, n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $n\n * @return Integer\n */\n function minPatches($nums, $n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minPatches(nums: number[], n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-patches nums n)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0330](https://leetcode-cn.com/problems/patching-array)", "[\u6309\u8981\u6c42\u8865\u9f50\u6570\u7ec4](/solution/0300-0399/0330.Patching%20Array/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[0330](https://leetcode.com/problems/patching-array)", "[Patching Array](/solution/0300-0399/0330.Patching%20Array/README_EN.md)", "`Greedy`", "Hard", ""]}, {"question_id": "0329", "frontend_question_id": "0329", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-increasing-path-in-a-matrix", "url_en": "https://leetcode.com/problems/longest-increasing-path-in-a-matrix", "relative_path_cn": "/solution/0300-0399/0329.Longest%20Increasing%20Path%20in%20a%20Matrix/README.md", "relative_path_en": "/solution/0300-0399/0329.Longest%20Increasing%20Path%20in%20a%20Matrix/README_EN.md", "title_cn": "\u77e9\u9635\u4e2d\u7684\u6700\u957f\u9012\u589e\u8def\u5f84", "title_en": "Longest Increasing Path in a Matrix", "question_title_slug": "longest-increasing-path-in-a-matrix", "content_en": "

    Given an m x n integers matrix, return the length of the longest increasing path in matrix.

    \n\n

    From each cell, you can either move in four directions: left, right, up, or down. You may not move diagonally or move outside the boundary (i.e., wrap-around is not allowed).

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: matrix = [[9,9,4],[6,6,8],[2,1,1]]\nOutput: 4\nExplanation: The longest increasing path is [1, 2, 6, 9].\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: matrix = [[3,4,5],[3,2,6],[2,2,1]]\nOutput: 4\nExplanation: The longest increasing path is [3, 4, 5, 6]. Moving diagonally is not allowed.\n
    \n\n

    Example 3:

    \n\n
    \nInput: matrix = [[1]]\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == matrix.length
    • \n\t
    • n == matrix[i].length
    • \n\t
    • 1 <= m, n <= 200
    • \n\t
    • 0 <= matrix[i][j] <= 231 - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u00a0m x n \u6574\u6570\u77e9\u9635\u00a0matrix \uff0c\u627e\u51fa\u5176\u4e2d \u6700\u957f\u9012\u589e\u8def\u5f84 \u7684\u957f\u5ea6\u3002

    \n\n

    \u5bf9\u4e8e\u6bcf\u4e2a\u5355\u5143\u683c\uff0c\u4f60\u53ef\u4ee5\u5f80\u4e0a\uff0c\u4e0b\uff0c\u5de6\uff0c\u53f3\u56db\u4e2a\u65b9\u5411\u79fb\u52a8\u3002 \u4f60 \u4e0d\u80fd \u5728 \u5bf9\u89d2\u7ebf \u65b9\u5411\u4e0a\u79fb\u52a8\u6216\u79fb\u52a8\u5230 \u8fb9\u754c\u5916\uff08\u5373\u4e0d\u5141\u8bb8\u73af\u7ed5\uff09\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1amatrix = [[9,9,4],[6,6,8],[2,1,1]]\n\u8f93\u51fa\uff1a4 \n\u89e3\u91ca\uff1a\u6700\u957f\u9012\u589e\u8def\u5f84\u4e3a\u00a0[1, 2, 6, 9]\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1amatrix = [[3,4,5],[3,2,6],[2,2,1]]\n\u8f93\u51fa\uff1a4 \n\u89e3\u91ca\uff1a\u6700\u957f\u9012\u589e\u8def\u5f84\u662f\u00a0[3, 4, 5, 6]\u3002\u6ce8\u610f\u4e0d\u5141\u8bb8\u5728\u5bf9\u89d2\u7ebf\u65b9\u5411\u4e0a\u79fb\u52a8\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1amatrix = [[1]]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == matrix.length
    • \n\t
    • n == matrix[i].length
    • \n\t
    • 1 <= m, n <= 200
    • \n\t
    • 0 <= matrix[i][j] <= 231 - 1
    • \n
    \n", "tags_en": ["Depth-first Search", "Topological Sort", "Memoization"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u62d3\u6251\u6392\u5e8f", "\u8bb0\u5fc6\u5316"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int longestIncreasingPath(vector>& matrix) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int longestIncreasingPath(int[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestIncreasingPath(self, matrix):\n \"\"\"\n :type matrix: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestIncreasingPath(self, matrix: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint longestIncreasingPath(int** matrix, int matrixSize, int* matrixColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LongestIncreasingPath(int[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} matrix\n * @return {number}\n */\nvar longestIncreasingPath = function(matrix) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} matrix\n# @return {Integer}\ndef longest_increasing_path(matrix)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestIncreasingPath(_ matrix: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestIncreasingPath(matrix [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestIncreasingPath(matrix: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestIncreasingPath(matrix: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_increasing_path(matrix: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $matrix\n * @return Integer\n */\n function longestIncreasingPath($matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestIncreasingPath(matrix: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-increasing-path matrix)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0329](https://leetcode-cn.com/problems/longest-increasing-path-in-a-matrix)", "[\u77e9\u9635\u4e2d\u7684\u6700\u957f\u9012\u589e\u8def\u5f84](/solution/0300-0399/0329.Longest%20Increasing%20Path%20in%20a%20Matrix/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u62d3\u6251\u6392\u5e8f`,`\u8bb0\u5fc6\u5316`", "\u56f0\u96be", ""], "md_table_row_en": ["[0329](https://leetcode.com/problems/longest-increasing-path-in-a-matrix)", "[Longest Increasing Path in a Matrix](/solution/0300-0399/0329.Longest%20Increasing%20Path%20in%20a%20Matrix/README_EN.md)", "`Depth-first Search`,`Topological Sort`,`Memoization`", "Hard", ""]}, {"question_id": "0328", "frontend_question_id": "0328", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/odd-even-linked-list", "url_en": "https://leetcode.com/problems/odd-even-linked-list", "relative_path_cn": "/solution/0300-0399/0328.Odd%20Even%20Linked%20List/README.md", "relative_path_en": "/solution/0300-0399/0328.Odd%20Even%20Linked%20List/README_EN.md", "title_cn": "\u5947\u5076\u94fe\u8868", "title_en": "Odd Even Linked List", "question_title_slug": "odd-even-linked-list", "content_en": "

    Given the head of a singly linked list, group all the nodes with odd indices together followed by the nodes with even indices, and return the reordered list.

    \n\n

    The first node is considered odd, and the second node is even, and so on.

    \n\n

    Note that the relative order inside both the even and odd groups should remain as it was in the input.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: head = [1,2,3,4,5]\nOutput: [1,3,5,2,4]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: head = [2,1,3,5,6,4,7]\nOutput: [2,3,6,7,1,5,4]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the linked list is in the range [0, 104].
    • \n\t
    • -106 <= Node.val <= 106
    • \n
    \n\n

     

    \nFollow up: Could you solve it in O(1) space complexity and O(nodes) time complexity?", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5355\u94fe\u8868\uff0c\u628a\u6240\u6709\u7684\u5947\u6570\u8282\u70b9\u548c\u5076\u6570\u8282\u70b9\u5206\u522b\u6392\u5728\u4e00\u8d77\u3002\u8bf7\u6ce8\u610f\uff0c\u8fd9\u91cc\u7684\u5947\u6570\u8282\u70b9\u548c\u5076\u6570\u8282\u70b9\u6307\u7684\u662f\u8282\u70b9\u7f16\u53f7\u7684\u5947\u5076\u6027\uff0c\u800c\u4e0d\u662f\u8282\u70b9\u7684\u503c\u7684\u5947\u5076\u6027\u3002

    \n\n

    \u8bf7\u5c1d\u8bd5\u4f7f\u7528\u539f\u5730\u7b97\u6cd5\u5b8c\u6210\u3002\u4f60\u7684\u7b97\u6cd5\u7684\u7a7a\u95f4\u590d\u6742\u5ea6\u5e94\u4e3a O(1)\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u5e94\u4e3a O(nodes)\uff0cnodes \u4e3a\u8282\u70b9\u603b\u6570\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: 1->2->3->4->5->NULL\n\u8f93\u51fa: 1->3->5->2->4->NULL\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: 2->1->3->5->6->4->7->NULL \n\u8f93\u51fa: 2->3->6->7->1->5->4->NULL
    \n\n

    \u8bf4\u660e:

    \n\n
      \n\t
    • \u5e94\u5f53\u4fdd\u6301\u5947\u6570\u8282\u70b9\u548c\u5076\u6570\u8282\u70b9\u7684\u76f8\u5bf9\u987a\u5e8f\u3002
    • \n\t
    • \u94fe\u8868\u7684\u7b2c\u4e00\u4e2a\u8282\u70b9\u89c6\u4e3a\u5947\u6570\u8282\u70b9\uff0c\u7b2c\u4e8c\u4e2a\u8282\u70b9\u89c6\u4e3a\u5076\u6570\u8282\u70b9\uff0c\u4ee5\u6b64\u7c7b\u63a8\u3002
    • \n
    \n", "tags_en": ["Linked List"], "tags_cn": ["\u94fe\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n ListNode* oddEvenList(ListNode* head) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public ListNode oddEvenList(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def oddEvenList(self, head):\n \"\"\"\n :type head: ListNode\n :rtype: ListNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def oddEvenList(self, head: ListNode) -> ListNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nstruct ListNode* oddEvenList(struct ListNode* head){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public ListNode OddEvenList(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} head\n * @return {ListNode}\n */\nvar oddEvenList = function(head) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode} head\n# @return {ListNode}\ndef odd_even_list(head)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func oddEvenList(_ head: ListNode?) -> ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc oddEvenList(head *ListNode) *ListNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def oddEvenList(head: ListNode): ListNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun oddEvenList(head: ListNode?): ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn odd_even_list(head: Option>) -> Option> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @return ListNode\n */\n function oddEvenList($head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction oddEvenList(head: ListNode | null): ListNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (odd-even-list head)\n (-> (or/c list-node? #f) (or/c list-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0328](https://leetcode-cn.com/problems/odd-even-linked-list)", "[\u5947\u5076\u94fe\u8868](/solution/0300-0399/0328.Odd%20Even%20Linked%20List/README.md)", "`\u94fe\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0328](https://leetcode.com/problems/odd-even-linked-list)", "[Odd Even Linked List](/solution/0300-0399/0328.Odd%20Even%20Linked%20List/README_EN.md)", "`Linked List`", "Medium", ""]}, {"question_id": "0327", "frontend_question_id": "0327", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-of-range-sum", "url_en": "https://leetcode.com/problems/count-of-range-sum", "relative_path_cn": "/solution/0300-0399/0327.Count%20of%20Range%20Sum/README.md", "relative_path_en": "/solution/0300-0399/0327.Count%20of%20Range%20Sum/README_EN.md", "title_cn": "\u533a\u95f4\u548c\u7684\u4e2a\u6570", "title_en": "Count of Range Sum", "question_title_slug": "count-of-range-sum", "content_en": "

    Given an integer array nums and two integers lower and upper, return the number of range sums that lie in [lower, upper] inclusive.

    \n\n

    Range sum S(i, j) is defined as the sum of the elements in nums between indices i and j inclusive, where i <= j.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [-2,5,-1], lower = -2, upper = 2\nOutput: 3\nExplanation: The three ranges are: [0,0], [2,2], and [0,2] and their respective sums are: -2, -1, 2.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [0], lower = 0, upper = 0\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n\t
    • -105 <= lower <= upper <= 105
    • \n\t
    • The answer is guaranteed to fit in a 32-bit integer.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0nums \u4ee5\u53ca\u4e24\u4e2a\u6574\u6570\u00a0lower \u548c upper \u3002\u6c42\u6570\u7ec4\u4e2d\uff0c\u503c\u4f4d\u4e8e\u8303\u56f4 [lower, upper] \uff08\u5305\u542b\u00a0lower\u00a0\u548c\u00a0upper\uff09\u4e4b\u5185\u7684 \u533a\u95f4\u548c\u7684\u4e2a\u6570 \u3002

    \n\n

    \u533a\u95f4\u548c\u00a0S(i, j)\u00a0\u8868\u793a\u5728\u00a0nums\u00a0\u4e2d\uff0c\u4f4d\u7f6e\u4ece\u00a0i\u00a0\u5230\u00a0j\u00a0\u7684\u5143\u7d20\u4e4b\u548c\uff0c\u5305\u542b\u00a0i\u00a0\u548c\u00a0j\u00a0(i \u2264 j)\u3002

    \n\n

    \u00a0

    \n\u793a\u4f8b 1\uff1a\n\n
    \n\u8f93\u5165\uff1anums = [-2,5,-1], lower = -2, upper = 2\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u5b58\u5728\u4e09\u4e2a\u533a\u95f4\uff1a[0,0]\u3001[2,2] \u548c [0,2] \uff0c\u5bf9\u5e94\u7684\u533a\u95f4\u548c\u5206\u522b\u662f\uff1a-2 \u3001-1 \u30012 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [0], lower = 0, upper = 0\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n\t
    • -105 <= lower <= upper <= 105
    • \n\t
    • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u7b54\u6848\u662f\u4e00\u4e2a 32 \u4f4d \u7684\u6574\u6570
    • \n
    \n", "tags_en": ["Sort", "Binary Indexed Tree", "Segment Tree", "Binary Search", "Divide and Conquer"], "tags_cn": ["\u6392\u5e8f", "\u6811\u72b6\u6570\u7ec4", "\u7ebf\u6bb5\u6811", "\u4e8c\u5206\u67e5\u627e", "\u5206\u6cbb\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countRangeSum(vector& nums, int lower, int upper) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countRangeSum(int[] nums, int lower, int upper) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countRangeSum(self, nums, lower, upper):\n \"\"\"\n :type nums: List[int]\n :type lower: int\n :type upper: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countRangeSum(self, nums: List[int], lower: int, upper: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countRangeSum(int* nums, int numsSize, int lower, int upper){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountRangeSum(int[] nums, int lower, int upper) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} lower\n * @param {number} upper\n * @return {number}\n */\nvar countRangeSum = function(nums, lower, upper) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} lower\n# @param {Integer} upper\n# @return {Integer}\ndef count_range_sum(nums, lower, upper)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countRangeSum(_ nums: [Int], _ lower: Int, _ upper: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countRangeSum(nums []int, lower int, upper int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countRangeSum(nums: Array[Int], lower: Int, upper: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countRangeSum(nums: IntArray, lower: Int, upper: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_range_sum(nums: Vec, lower: i32, upper: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $lower\n * @param Integer $upper\n * @return Integer\n */\n function countRangeSum($nums, $lower, $upper) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countRangeSum(nums: number[], lower: number, upper: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-range-sum nums lower upper)\n (-> (listof exact-integer?) exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0327](https://leetcode-cn.com/problems/count-of-range-sum)", "[\u533a\u95f4\u548c\u7684\u4e2a\u6570](/solution/0300-0399/0327.Count%20of%20Range%20Sum/README.md)", "`\u6392\u5e8f`,`\u6811\u72b6\u6570\u7ec4`,`\u7ebf\u6bb5\u6811`,`\u4e8c\u5206\u67e5\u627e`,`\u5206\u6cbb\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[0327](https://leetcode.com/problems/count-of-range-sum)", "[Count of Range Sum](/solution/0300-0399/0327.Count%20of%20Range%20Sum/README_EN.md)", "`Sort`,`Binary Indexed Tree`,`Segment Tree`,`Binary Search`,`Divide and Conquer`", "Hard", ""]}, {"question_id": "0326", "frontend_question_id": "0326", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/power-of-three", "url_en": "https://leetcode.com/problems/power-of-three", "relative_path_cn": "/solution/0300-0399/0326.Power%20of%20Three/README.md", "relative_path_en": "/solution/0300-0399/0326.Power%20of%20Three/README_EN.md", "title_cn": "3\u7684\u5e42", "title_en": "Power of Three", "question_title_slug": "power-of-three", "content_en": "

    Given an integer n, return true if it is a power of three. Otherwise, return false.

    \n\n

    An integer n is a power of three, if there exists an integer x such that n == 3x.

    \n\n

     

    \n

    Example 1:

    \n
    Input: n = 27\nOutput: true\n

    Example 2:

    \n
    Input: n = 0\nOutput: false\n

    Example 3:

    \n
    Input: n = 9\nOutput: true\n

    Example 4:

    \n
    Input: n = 45\nOutput: false\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • -231 <= n <= 231 - 1
    • \n
    \n\n

     

    \nFollow up: Could you solve it without loops/recursion?", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\uff0c\u5199\u4e00\u4e2a\u51fd\u6570\u6765\u5224\u65ad\u5b83\u662f\u5426\u662f 3\u00a0\u7684\u5e42\u6b21\u65b9\u3002\u5982\u679c\u662f\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n

    \u6574\u6570 n \u662f 3 \u7684\u5e42\u6b21\u65b9\u9700\u6ee1\u8db3\uff1a\u5b58\u5728\u6574\u6570 x \u4f7f\u5f97 n == 3x

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 27\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 0\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 9\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 45\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • -231 <= n <= 231 - 1
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u4f60\u80fd\u4e0d\u4f7f\u7528\u5faa\u73af\u6216\u8005\u9012\u5f52\u6765\u5b8c\u6210\u672c\u9898\u5417\uff1f
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isPowerOfThree(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isPowerOfThree(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isPowerOfThree(self, n):\n \"\"\"\n :type n: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isPowerOfThree(self, n: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isPowerOfThree(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsPowerOfThree(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {boolean}\n */\nvar isPowerOfThree = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Boolean}\ndef is_power_of_three(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isPowerOfThree(_ n: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isPowerOfThree(n int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isPowerOfThree(n: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isPowerOfThree(n: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_power_of_three(n: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Boolean\n */\n function isPowerOfThree($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isPowerOfThree(n: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-power-of-three n)\n (-> exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0326](https://leetcode-cn.com/problems/power-of-three)", "[3\u7684\u5e42](/solution/0300-0399/0326.Power%20of%20Three/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0326](https://leetcode.com/problems/power-of-three)", "[Power of Three](/solution/0300-0399/0326.Power%20of%20Three/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "0325", "frontend_question_id": "0325", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/maximum-size-subarray-sum-equals-k", "url_en": "https://leetcode.com/problems/maximum-size-subarray-sum-equals-k", "relative_path_cn": "/solution/0300-0399/0325.Maximum%20Size%20Subarray%20Sum%20Equals%20k/README.md", "relative_path_en": "/solution/0300-0399/0325.Maximum%20Size%20Subarray%20Sum%20Equals%20k/README_EN.md", "title_cn": "\u548c\u7b49\u4e8e k \u7684\u6700\u957f\u5b50\u6570\u7ec4\u957f\u5ea6", "title_en": "Maximum Size Subarray Sum Equals k", "question_title_slug": "maximum-size-subarray-sum-equals-k", "content_en": "

    Given an integer array nums and an integer k, return the maximum length of a subarray that sums to k. If there isn't one, return 0 instead.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,-1,5,-2,3], k = 3\nOutput: 4\nExplanation: The subarray [1, -1, 5, -2] sums to 3 and is the longest.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [-2,-1,2,1], k = 1\nOutput: 2\nExplanation: The subarray [-1, 2] sums to 1 and is the longest.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 2 * 105
    • \n\t
    • -104 <= nums[i] <= 104
    • \n\t
    • -109 <= k <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6570\u7ec4 nums \u548c\u4e00\u4e2a\u76ee\u6807\u503c k\uff0c\u627e\u5230\u548c\u7b49\u4e8e k \u7684\u6700\u957f\u5b50\u6570\u7ec4\u957f\u5ea6\u3002\u5982\u679c\u4e0d\u5b58\u5728\u4efb\u610f\u4e00\u4e2a\u7b26\u5408\u8981\u6c42\u7684\u5b50\u6570\u7ec4\uff0c\u5219\u8fd4\u56de 0\u3002

    \n\n

    \u6ce8\u610f:
    \n nums \u6570\u7ec4\u7684\u603b\u548c\u662f\u4e00\u5b9a\u5728 32 \u4f4d\u6709\u7b26\u53f7\u6574\u6570\u8303\u56f4\u4e4b\u5185\u7684\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: nums = [1, -1, 5, -2, 3], k = 3\n\u8f93\u51fa: 4 \n\u89e3\u91ca: \u5b50\u6570\u7ec4 [1, -1, 5, -2] \u548c\u7b49\u4e8e 3\uff0c\u4e14\u957f\u5ea6\u6700\u957f\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: nums = [-2, -1, 2, 1], k = 1\n\u8f93\u51fa: 2 \n\u89e3\u91ca: \u5b50\u6570\u7ec4 [-1, 2] \u548c\u7b49\u4e8e 1\uff0c\u4e14\u957f\u5ea6\u6700\u957f\u3002
    \n\n

    \u8fdb\u9636:
    \n\u4f60\u80fd\u4f7f\u65f6\u95f4\u590d\u6742\u5ea6\u5728 O(n) \u5185\u5b8c\u6210\u6b64\u9898\u5417?

    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxSubArrayLen(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxSubArrayLen(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxSubArrayLen(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxSubArrayLen(self, nums: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxSubArrayLen(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxSubArrayLen(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar maxSubArrayLen = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef max_sub_array_len(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxSubArrayLen(_ nums: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxSubArrayLen(nums []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxSubArrayLen(nums: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxSubArrayLen(nums: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_sub_array_len(nums: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer\n */\n function maxSubArrayLen($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxSubArrayLen(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-sub-array-len nums k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0325](https://leetcode-cn.com/problems/maximum-size-subarray-sum-equals-k)", "[\u548c\u7b49\u4e8e k \u7684\u6700\u957f\u5b50\u6570\u7ec4\u957f\u5ea6](/solution/0300-0399/0325.Maximum%20Size%20Subarray%20Sum%20Equals%20k/README.md)", "`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0325](https://leetcode.com/problems/maximum-size-subarray-sum-equals-k)", "[Maximum Size Subarray Sum Equals k](/solution/0300-0399/0325.Maximum%20Size%20Subarray%20Sum%20Equals%20k/README_EN.md)", "`Hash Table`", "Medium", "\ud83d\udd12"]}, {"question_id": "0324", "frontend_question_id": "0324", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/wiggle-sort-ii", "url_en": "https://leetcode.com/problems/wiggle-sort-ii", "relative_path_cn": "/solution/0300-0399/0324.Wiggle%20Sort%20II/README.md", "relative_path_en": "/solution/0300-0399/0324.Wiggle%20Sort%20II/README_EN.md", "title_cn": "\u6446\u52a8\u6392\u5e8f II", "title_en": "Wiggle Sort II", "question_title_slug": "wiggle-sort-ii", "content_en": "

    Given an integer array nums, reorder it such that nums[0] < nums[1] > nums[2] < nums[3]....

    \n\n

    You may assume the input array always has a valid answer.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,5,1,1,6,4]\nOutput: [1,6,1,5,1,4]\nExplanation: [1,4,1,5,1,6] is also accepted.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,3,2,2,3,1]\nOutput: [2,3,1,3,1,2]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 5 * 104
    • \n\t
    • 0 <= nums[i] <= 5000
    • \n\t
    • It is guaranteed that there will be an answer for the given input nums.
    • \n
    \n\n

     

    \nFollow Up: Can you do it in O(n) time and/or in-place with O(1) extra space?", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0nums\uff0c\u5c06\u5b83\u91cd\u65b0\u6392\u5217\u6210\u00a0nums[0] < nums[1] > nums[2] < nums[3]...\u00a0\u7684\u987a\u5e8f\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u5047\u8bbe\u6240\u6709\u8f93\u5165\u6570\u7ec4\u90fd\u53ef\u4ee5\u5f97\u5230\u6ee1\u8db3\u9898\u76ee\u8981\u6c42\u7684\u7ed3\u679c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,5,1,1,6,4]\n\u8f93\u51fa\uff1a[1,6,1,5,1,4]\n\u89e3\u91ca\uff1a[1,4,1,5,1,6] \u540c\u6837\u662f\u7b26\u5408\u9898\u76ee\u8981\u6c42\u7684\u7ed3\u679c\uff0c\u53ef\u4ee5\u88ab\u5224\u9898\u7a0b\u5e8f\u63a5\u53d7\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,3,2,2,3,1]\n\u8f93\u51fa\uff1a[2,3,1,3,1,2]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 5 * 104
    • \n\t
    • 0 <= nums[i] <= 5000
    • \n\t
    • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\uff0c\u5bf9\u4e8e\u7ed9\u5b9a\u7684\u8f93\u5165 nums \uff0c\u603b\u80fd\u4ea7\u751f\u6ee1\u8db3\u9898\u76ee\u8981\u6c42\u7684\u7ed3\u679c
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u80fd\u7528\u00a0O(n) \u65f6\u95f4\u590d\u6742\u5ea6\u548c / \u6216\u539f\u5730 O(1) \u989d\u5916\u7a7a\u95f4\u6765\u5b9e\u73b0\u5417\uff1f

    \n", "tags_en": ["Sort"], "tags_cn": ["\u6392\u5e8f"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n void wiggleSort(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public void wiggleSort(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def wiggleSort(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: None Do not return anything, modify nums in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def wiggleSort(self, nums: List[int]) -> None:\n \"\"\"\n Do not return anything, modify nums in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nvoid wiggleSort(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public void WiggleSort(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {void} Do not return anything, modify nums in-place instead.\n */\nvar wiggleSort = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Void} Do not return anything, modify nums in-place instead.\ndef wiggle_sort(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func wiggleSort(_ nums: inout [Int]) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func wiggleSort(nums []int) {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def wiggleSort(nums: Array[Int]): Unit = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun wiggleSort(nums: IntArray): Unit {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn wiggle_sort(nums: &mut Vec) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return NULL\n */\n function wiggleSort(&$nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n Do not return anything, modify nums in-place instead.\n */\nfunction wiggleSort(nums: number[]): void {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0324](https://leetcode-cn.com/problems/wiggle-sort-ii)", "[\u6446\u52a8\u6392\u5e8f II](/solution/0300-0399/0324.Wiggle%20Sort%20II/README.md)", "`\u6392\u5e8f`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0324](https://leetcode.com/problems/wiggle-sort-ii)", "[Wiggle Sort II](/solution/0300-0399/0324.Wiggle%20Sort%20II/README_EN.md)", "`Sort`", "Medium", ""]}, {"question_id": "0323", "frontend_question_id": "0323", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/number-of-connected-components-in-an-undirected-graph", "url_en": "https://leetcode.com/problems/number-of-connected-components-in-an-undirected-graph", "relative_path_cn": "/solution/0300-0399/0323.Number%20of%20Connected%20Components%20in%20an%20Undirected%20Graph/README.md", "relative_path_en": "/solution/0300-0399/0323.Number%20of%20Connected%20Components%20in%20an%20Undirected%20Graph/README_EN.md", "title_cn": "\u65e0\u5411\u56fe\u4e2d\u8fde\u901a\u5206\u91cf\u7684\u6570\u76ee", "title_en": "Number of Connected Components in an Undirected Graph", "question_title_slug": "number-of-connected-components-in-an-undirected-graph", "content_en": "

    You have a graph of n nodes. You are given an integer n and an array edges where edges[i] = [ai, bi] indicates that there is an edge between ai and bi in the graph.

    \n\n

    Return the number of connected components in the graph.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: n = 5, edges = [[0,1],[1,2],[3,4]]\nOutput: 2\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: n = 5, edges = [[0,1],[1,2],[2,3],[3,4]]\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 2000
    • \n\t
    • 1 <= edges.length <= 5000
    • \n\t
    • edges[i].length == 2
    • \n\t
    • 0 <= ai <= bi < n
    • \n\t
    • ai != bi
    • \n\t
    • There are no repeated edges.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u7f16\u53f7\u4ece 0 \u5230 n-1 \u7684 n \u4e2a\u8282\u70b9\u548c\u4e00\u4e2a\u65e0\u5411\u8fb9\u5217\u8868\uff08\u6bcf\u6761\u8fb9\u90fd\u662f\u4e00\u5bf9\u8282\u70b9\uff09\uff0c\u8bf7\u7f16\u5199\u4e00\u4e2a\u51fd\u6570\u6765\u8ba1\u7b97\u65e0\u5411\u56fe\u4e2d\u8fde\u901a\u5206\u91cf\u7684\u6570\u76ee\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: n = 5 \u548c edges = [[0, 1], [1, 2], [3, 4]]\n\n     0          3\n     |          |\n     1 --- 2    4 \n\n\u8f93\u51fa: 2\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: n = 5 \u548c edges = [[0, 1], [1, 2], [2, 3], [3, 4]]\n\n     0           4\n     |           |\n     1 --- 2 --- 3\n\n\u8f93\u51fa:  1\n
    \n\n

    \u6ce8\u610f:
    \n\u4f60\u53ef\u4ee5\u5047\u8bbe\u5728 edges \u4e2d\u4e0d\u4f1a\u51fa\u73b0\u91cd\u590d\u7684\u8fb9\u3002\u800c\u4e14\u7531\u4e8e\u6240\u4ee5\u7684\u8fb9\u90fd\u662f\u65e0\u5411\u8fb9\uff0c[0, 1] \u4e0e [1, 0]  \u76f8\u540c\uff0c\u6240\u4ee5\u5b83\u4eec\u4e0d\u4f1a\u540c\u65f6\u5728 edges \u4e2d\u51fa\u73b0\u3002

    \n", "tags_en": ["Depth-first Search", "Breadth-first Search", "Union Find", "Graph"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e76\u67e5\u96c6", "\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countComponents(int n, vector>& edges) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countComponents(int n, int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countComponents(self, n, edges):\n \"\"\"\n :type n: int\n :type edges: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countComponents(self, n: int, edges: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countComponents(int n, int** edges, int edgesSize, int* edgesColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountComponents(int n, int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} edges\n * @return {number}\n */\nvar countComponents = function(n, edges) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} edges\n# @return {Integer}\ndef count_components(n, edges)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countComponents(_ n: Int, _ edges: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countComponents(n int, edges [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countComponents(n: Int, edges: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countComponents(n: Int, edges: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_components(n: i32, edges: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $edges\n * @return Integer\n */\n function countComponents($n, $edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countComponents(n: number, edges: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-components n edges)\n (-> exact-integer? (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0323](https://leetcode-cn.com/problems/number-of-connected-components-in-an-undirected-graph)", "[\u65e0\u5411\u56fe\u4e2d\u8fde\u901a\u5206\u91cf\u7684\u6570\u76ee](/solution/0300-0399/0323.Number%20of%20Connected%20Components%20in%20an%20Undirected%20Graph/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e76\u67e5\u96c6`,`\u56fe`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0323](https://leetcode.com/problems/number-of-connected-components-in-an-undirected-graph)", "[Number of Connected Components in an Undirected Graph](/solution/0300-0399/0323.Number%20of%20Connected%20Components%20in%20an%20Undirected%20Graph/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`,`Union Find`,`Graph`", "Medium", "\ud83d\udd12"]}, {"question_id": "0322", "frontend_question_id": "0322", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/coin-change", "url_en": "https://leetcode.com/problems/coin-change", "relative_path_cn": "/solution/0300-0399/0322.Coin%20Change/README.md", "relative_path_en": "/solution/0300-0399/0322.Coin%20Change/README_EN.md", "title_cn": "\u96f6\u94b1\u5151\u6362", "title_en": "Coin Change", "question_title_slug": "coin-change", "content_en": "

    You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money.

    \n\n

    Return the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination of the coins, return -1.

    \n\n

    You may assume that you have an infinite number of each kind of coin.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: coins = [1,2,5], amount = 11\nOutput: 3\nExplanation: 11 = 5 + 5 + 1\n
    \n\n

    Example 2:

    \n\n
    \nInput: coins = [2], amount = 3\nOutput: -1\n
    \n\n

    Example 3:

    \n\n
    \nInput: coins = [1], amount = 0\nOutput: 0\n
    \n\n

    Example 4:

    \n\n
    \nInput: coins = [1], amount = 1\nOutput: 1\n
    \n\n

    Example 5:

    \n\n
    \nInput: coins = [1], amount = 2\nOutput: 2\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= coins.length <= 12
    • \n\t
    • 1 <= coins[i] <= 231 - 1
    • \n\t
    • 0 <= amount <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e0d\u540c\u9762\u989d\u7684\u786c\u5e01 coins \u548c\u4e00\u4e2a\u603b\u91d1\u989d amount\u3002\u7f16\u5199\u4e00\u4e2a\u51fd\u6570\u6765\u8ba1\u7b97\u53ef\u4ee5\u51d1\u6210\u603b\u91d1\u989d\u6240\u9700\u7684\u6700\u5c11\u7684\u786c\u5e01\u4e2a\u6570\u3002\u5982\u679c\u6ca1\u6709\u4efb\u4f55\u4e00\u79cd\u786c\u5e01\u7ec4\u5408\u80fd\u7ec4\u6210\u603b\u91d1\u989d\uff0c\u8fd4\u56de\u00a0-1\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u8ba4\u4e3a\u6bcf\u79cd\u786c\u5e01\u7684\u6570\u91cf\u662f\u65e0\u9650\u7684\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\u00a01\uff1a

    \n\n
    \n\u8f93\u5165\uff1acoins = [1, 2, 5], amount = 11\n\u8f93\u51fa\uff1a3 \n\u89e3\u91ca\uff1a11 = 5 + 5 + 1
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1acoins = [2], amount = 3\n\u8f93\u51fa\uff1a-1
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1acoins = [1], amount = 0\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1acoins = [1], amount = 1\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1acoins = [1], amount = 2\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= coins.length <= 12
    • \n\t
    • 1 <= coins[i] <= 231 - 1
    • \n\t
    • 0 <= amount <= 104
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int coinChange(vector& coins, int amount) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int coinChange(int[] coins, int amount) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def coinChange(self, coins, amount):\n \"\"\"\n :type coins: List[int]\n :type amount: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def coinChange(self, coins: List[int], amount: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint coinChange(int* coins, int coinsSize, int amount){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CoinChange(int[] coins, int amount) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} coins\n * @param {number} amount\n * @return {number}\n */\nvar coinChange = function(coins, amount) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} coins\n# @param {Integer} amount\n# @return {Integer}\ndef coin_change(coins, amount)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func coinChange(_ coins: [Int], _ amount: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func coinChange(coins []int, amount int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def coinChange(coins: Array[Int], amount: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun coinChange(coins: IntArray, amount: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn coin_change(coins: Vec, amount: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $coins\n * @param Integer $amount\n * @return Integer\n */\n function coinChange($coins, $amount) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function coinChange(coins: number[], amount: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (coin-change coins amount)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0322](https://leetcode-cn.com/problems/coin-change)", "[\u96f6\u94b1\u5151\u6362](/solution/0300-0399/0322.Coin%20Change/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0322](https://leetcode.com/problems/coin-change)", "[Coin Change](/solution/0300-0399/0322.Coin%20Change/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0321", "frontend_question_id": "0321", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/create-maximum-number", "url_en": "https://leetcode.com/problems/create-maximum-number", "relative_path_cn": "/solution/0300-0399/0321.Create%20Maximum%20Number/README.md", "relative_path_en": "/solution/0300-0399/0321.Create%20Maximum%20Number/README_EN.md", "title_cn": "\u62fc\u63a5\u6700\u5927\u6570", "title_en": "Create Maximum Number", "question_title_slug": "create-maximum-number", "content_en": "

    You are given two integer arrays nums1 and nums2 of lengths m and n respectively. nums1 and nums2 represent the digits of two numbers. You are also given an integer k.

    \n\n

    Create the maximum number of length k <= m + n from digits of the two numbers. The relative order of the digits from the same array must be preserved.

    \n\n

    Return an array of the k digits representing the answer.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums1 = [3,4,6,5], nums2 = [9,1,2,5,8,3], k = 5\nOutput: [9,8,6,5,3]\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums1 = [6,7], nums2 = [6,0,4], k = 5\nOutput: [6,7,6,0,4]\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums1 = [3,9], nums2 = [8,9], k = 3\nOutput: [9,8,9]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == nums1.length
    • \n\t
    • n == nums2.length
    • \n\t
    • 1 <= m, n <= 500
    • \n\t
    • 0 <= nums1[i], nums2[i] <= 9
    • \n\t
    • 1 <= k <= m + n
    • \n
    \n\n

     

    \n

    Follow up: Try to optimize your time and space complexity.

    \n", "content_cn": "

    \u7ed9\u5b9a\u957f\u5ea6\u5206\u522b\u4e3a m \u548c n \u7684\u4e24\u4e2a\u6570\u7ec4\uff0c\u5176\u5143\u7d20\u7531 0-9 \u6784\u6210\uff0c\u8868\u793a\u4e24\u4e2a\u81ea\u7136\u6570\u5404\u4f4d\u4e0a\u7684\u6570\u5b57\u3002\u73b0\u5728\u4ece\u8fd9\u4e24\u4e2a\u6570\u7ec4\u4e2d\u9009\u51fa k (k <= m + n) \u4e2a\u6570\u5b57\u62fc\u63a5\u6210\u4e00\u4e2a\u65b0\u7684\u6570\uff0c\u8981\u6c42\u4ece\u540c\u4e00\u4e2a\u6570\u7ec4\u4e2d\u53d6\u51fa\u7684\u6570\u5b57\u4fdd\u6301\u5176\u5728\u539f\u6570\u7ec4\u4e2d\u7684\u76f8\u5bf9\u987a\u5e8f\u3002

    \n\n

    \u6c42\u6ee1\u8db3\u8be5\u6761\u4ef6\u7684\u6700\u5927\u6570\u3002\u7ed3\u679c\u8fd4\u56de\u4e00\u4e2a\u8868\u793a\u8be5\u6700\u5927\u6570\u7684\u957f\u5ea6\u4e3a k \u7684\u6570\u7ec4\u3002

    \n\n

    \u8bf4\u660e: \u8bf7\u5c3d\u53ef\u80fd\u5730\u4f18\u5316\u4f60\u7b97\u6cd5\u7684\u65f6\u95f4\u548c\u7a7a\u95f4\u590d\u6742\u5ea6\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165:\nnums1 = [3, 4, 6, 5]\nnums2 = [9, 1, 2, 5, 8, 3]\nk = 5\n\u8f93\u51fa:\n[9, 8, 6, 5, 3]
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165:\nnums1 = [6, 7]\nnums2 = [6, 0, 4]\nk = 5\n\u8f93\u51fa:\n[6, 7, 6, 0, 4]
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u8f93\u5165:\nnums1 = [3, 9]\nnums2 = [8, 9]\nk = 3\n\u8f93\u51fa:\n[9, 8, 9]
    \n", "tags_en": ["Greedy", "Dynamic Programming"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector maxNumber(vector& nums1, vector& nums2, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] maxNumber(int[] nums1, int[] nums2, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxNumber(self, nums1, nums2, k):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n :type k: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxNumber(self, nums1: List[int], nums2: List[int], k: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* maxNumber(int* nums1, int nums1Size, int* nums2, int nums2Size, int k, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] MaxNumber(int[] nums1, int[] nums2, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums1\n * @param {number[]} nums2\n * @param {number} k\n * @return {number[]}\n */\nvar maxNumber = function(nums1, nums2, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums1\n# @param {Integer[]} nums2\n# @param {Integer} k\n# @return {Integer[]}\ndef max_number(nums1, nums2, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxNumber(_ nums1: [Int], _ nums2: [Int], _ k: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxNumber(nums1 []int, nums2 []int, k int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxNumber(nums1: Array[Int], nums2: Array[Int], k: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxNumber(nums1: IntArray, nums2: IntArray, k: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_number(nums1: Vec, nums2: Vec, k: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums1\n * @param Integer[] $nums2\n * @param Integer $k\n * @return Integer[]\n */\n function maxNumber($nums1, $nums2, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxNumber(nums1: number[], nums2: number[], k: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-number nums1 nums2 k)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0321](https://leetcode-cn.com/problems/create-maximum-number)", "[\u62fc\u63a5\u6700\u5927\u6570](/solution/0300-0399/0321.Create%20Maximum%20Number/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0321](https://leetcode.com/problems/create-maximum-number)", "[Create Maximum Number](/solution/0300-0399/0321.Create%20Maximum%20Number/README_EN.md)", "`Greedy`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0320", "frontend_question_id": "0320", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/generalized-abbreviation", "url_en": "https://leetcode.com/problems/generalized-abbreviation", "relative_path_cn": "/solution/0300-0399/0320.Generalized%20Abbreviation/README.md", "relative_path_en": "/solution/0300-0399/0320.Generalized%20Abbreviation/README_EN.md", "title_cn": "\u5217\u4e3e\u5355\u8bcd\u7684\u5168\u90e8\u7f29\u5199", "title_en": "Generalized Abbreviation", "question_title_slug": "generalized-abbreviation", "content_en": "

    A word's generalized abbreviation can be constructed by taking any number of non-overlapping substrings and replacing them with their respective lengths. For example, "abcde" can be abbreviated into "a3e" ("bcd" turned into "3"), "1bcd1" ("a" and "e" both turned into "1"), and "23" ("ab" turned into "2" and "cde" turned into "3").

    \n\n

    Given a string word, return a list of all the possible generalized abbreviations of word. Return the answer in any order.

    \n\n

     

    \n

    Example 1:

    \n
    Input: word = \"word\"\nOutput: [\"4\",\"3d\",\"2r1\",\"2rd\",\"1o2\",\"1o1d\",\"1or1\",\"1ord\",\"w3\",\"w2d\",\"w1r1\",\"w1rd\",\"wo2\",\"wo1d\",\"wor1\",\"word\"]\n

    Example 2:

    \n
    Input: word = \"a\"\nOutput: [\"1\",\"a\"]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= word.length <= 15
    • \n\t
    • word consists of only lowercase English letters.
    • \n
    \n", "content_cn": "

    \u8bf7\u4f60\u5199\u51fa\u4e00\u4e2a\u80fd\u591f\u4e3e\u5355\u8bcd\u5168\u90e8\u7f29\u5199\u7684\u51fd\u6570\u3002

    \n\n

    \u6ce8\u610f\uff1a\u8f93\u51fa\u7684\u987a\u5e8f\u5e76\u4e0d\u91cd\u8981\u3002

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165: "word"\n\u8f93\u51fa:\n["word", "1ord", "w1rd", "wo1d", "wor1", "2rd", "w2d", "wo2", "1o1d", "1or1", "w1r1", "1o2", "2r1", "3d", "w3", "4"]\n
    \n\n

     

    \n", "tags_en": ["Bit Manipulation", "Backtracking"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector generateAbbreviations(string word) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List generateAbbreviations(String word) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def generateAbbreviations(self, word):\n \"\"\"\n :type word: str\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def generateAbbreviations(self, word: str) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** generateAbbreviations(char * word, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList GenerateAbbreviations(string word) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} word\n * @return {string[]}\n */\nvar generateAbbreviations = function(word) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} word\n# @return {String[]}\ndef generate_abbreviations(word)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func generateAbbreviations(_ word: String) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func generateAbbreviations(word string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def generateAbbreviations(word: String): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun generateAbbreviations(word: String): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn generate_abbreviations(word: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $word\n * @return String[]\n */\n function generateAbbreviations($word) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function generateAbbreviations(word: string): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (generate-abbreviations word)\n (-> string? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0320](https://leetcode-cn.com/problems/generalized-abbreviation)", "[\u5217\u4e3e\u5355\u8bcd\u7684\u5168\u90e8\u7f29\u5199](/solution/0300-0399/0320.Generalized%20Abbreviation/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0320](https://leetcode.com/problems/generalized-abbreviation)", "[Generalized Abbreviation](/solution/0300-0399/0320.Generalized%20Abbreviation/README_EN.md)", "`Bit Manipulation`,`Backtracking`", "Medium", "\ud83d\udd12"]}, {"question_id": "0319", "frontend_question_id": "0319", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/bulb-switcher", "url_en": "https://leetcode.com/problems/bulb-switcher", "relative_path_cn": "/solution/0300-0399/0319.Bulb%20Switcher/README.md", "relative_path_en": "/solution/0300-0399/0319.Bulb%20Switcher/README_EN.md", "title_cn": "\u706f\u6ce1\u5f00\u5173", "title_en": "Bulb Switcher", "question_title_slug": "bulb-switcher", "content_en": "

    There are n bulbs that are initially off. You first turn on all the bulbs, then you turn off every second bulb.

    \n\n

    On the third round, you toggle every third bulb (turning on if it's off or turning off if it's on). For the ith round, you toggle every i bulb. For the nth round, you only toggle the last bulb.

    \n\n

    Return the number of bulbs that are on after n rounds.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: n = 3\nOutput: 1\nExplanation: At first, the three bulbs are [off, off, off].\nAfter the first round, the three bulbs are [on, on, on].\nAfter the second round, the three bulbs are [on, off, on].\nAfter the third round, the three bulbs are [on, off, off]. \nSo you should return 1 because there is only one bulb is on.
    \n\n

    Example 2:

    \n\n
    \nInput: n = 0\nOutput: 0\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 1\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= n <= 109
    • \n
    \n", "content_cn": "

    \u521d\u59cb\u65f6\u6709\u00a0n\u00a0\u4e2a\u706f\u6ce1\u5904\u4e8e\u5173\u95ed\u72b6\u6001\u3002

    \n\n

    \u5bf9\u67d0\u4e2a\u706f\u6ce1\u5207\u6362\u5f00\u5173\u610f\u5473\u7740\uff1a\u5982\u679c\u706f\u6ce1\u72b6\u6001\u4e3a\u5173\u95ed\uff0c\u90a3\u8be5\u706f\u6ce1\u5c31\u4f1a\u88ab\u5f00\u542f\uff1b\u800c\u706f\u6ce1\u72b6\u6001\u4e3a\u5f00\u542f\uff0c\u90a3\u8be5\u706f\u6ce1\u5c31\u4f1a\u88ab\u5173\u95ed\u3002

    \n\n

    \u7b2c 1 \u8f6e\uff0c\u6bcf\u4e2a\u706f\u6ce1\u5207\u6362\u4e00\u6b21\u5f00\u5173\u3002\u5373\uff0c\u6253\u5f00\u6240\u6709\u7684\u706f\u6ce1\u3002

    \n\n

    \u7b2c 2 \u8f6e\uff0c\u6bcf\u4e24\u4e2a\u706f\u6ce1\u5207\u6362\u4e00\u6b21\u5f00\u5173\u3002 \u5373\uff0c\u6bcf\u4e24\u4e2a\u706f\u6ce1\u5173\u95ed\u4e00\u4e2a\u3002

    \n\n

    \u7b2c 3 \u8f6e\uff0c\u6bcf\u4e09\u4e2a\u706f\u6ce1\u5207\u6362\u4e00\u6b21\u5f00\u5173\u3002

    \n\n

    \u7b2c\u00a0i \u8f6e\uff0c\u6bcf\u00a0i\u00a0\u4e2a\u706f\u6ce1\u5207\u6362\u4e00\u6b21\u5f00\u5173\u3002 \u800c\u7b2c\u00a0n\u00a0\u8f6e\uff0c\u4f60\u53ea\u5207\u6362\u6700\u540e\u4e00\u4e2a\u706f\u6ce1\u7684\u5f00\u5173\u3002

    \n\n

    \u627e\u51fa\u00a0n\u00a0\u8f6e\u540e\u6709\u591a\u5c11\u4e2a\u4eae\u7740\u7684\u706f\u6ce1\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1an = 3\n\u8f93\u51fa\uff1a1 \n\u89e3\u91ca\uff1a\n\u521d\u59cb\u65f6, \u706f\u6ce1\u72b6\u6001 [\u5173\u95ed, \u5173\u95ed, \u5173\u95ed].\n\u7b2c\u4e00\u8f6e\u540e, \u706f\u6ce1\u72b6\u6001 [\u5f00\u542f, \u5f00\u542f, \u5f00\u542f].\n\u7b2c\u4e8c\u8f6e\u540e, \u706f\u6ce1\u72b6\u6001 [\u5f00\u542f, \u5173\u95ed, \u5f00\u542f].\n\u7b2c\u4e09\u8f6e\u540e, \u706f\u6ce1\u72b6\u6001 [\u5f00\u542f, \u5173\u95ed, \u5173\u95ed]. \n\n\u4f60\u5e94\u8be5\u8fd4\u56de 1\uff0c\u56e0\u4e3a\u53ea\u6709\u4e00\u4e2a\u706f\u6ce1\u8fd8\u4eae\u7740\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 0\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= n <= 109
    • \n
    \n", "tags_en": ["Brainteaser", "Math"], "tags_cn": ["\u8111\u7b4b\u6025\u8f6c\u5f2f", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int bulbSwitch(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int bulbSwitch(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def bulbSwitch(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def bulbSwitch(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint bulbSwitch(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int BulbSwitch(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar bulbSwitch = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef bulb_switch(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func bulbSwitch(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func bulbSwitch(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def bulbSwitch(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun bulbSwitch(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn bulb_switch(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function bulbSwitch($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function bulbSwitch(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (bulb-switch n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0319](https://leetcode-cn.com/problems/bulb-switcher)", "[\u706f\u6ce1\u5f00\u5173](/solution/0300-0399/0319.Bulb%20Switcher/README.md)", "`\u8111\u7b4b\u6025\u8f6c\u5f2f`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0319](https://leetcode.com/problems/bulb-switcher)", "[Bulb Switcher](/solution/0300-0399/0319.Bulb%20Switcher/README_EN.md)", "`Brainteaser`,`Math`", "Medium", ""]}, {"question_id": "0318", "frontend_question_id": "0318", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-product-of-word-lengths", "url_en": "https://leetcode.com/problems/maximum-product-of-word-lengths", "relative_path_cn": "/solution/0300-0399/0318.Maximum%20Product%20of%20Word%20Lengths/README.md", "relative_path_en": "/solution/0300-0399/0318.Maximum%20Product%20of%20Word%20Lengths/README_EN.md", "title_cn": "\u6700\u5927\u5355\u8bcd\u957f\u5ea6\u4e58\u79ef", "title_en": "Maximum Product of Word Lengths", "question_title_slug": "maximum-product-of-word-lengths", "content_en": "

    Given a string array words, return the maximum value of length(word[i]) * length(word[j]) where the two words do not share common letters. If no such two words exist, return 0.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: words = ["abcw","baz","foo","bar","xtfn","abcdef"]\nOutput: 16\nExplanation: The two words can be "abcw", "xtfn".\n
    \n\n

    Example 2:

    \n\n
    \nInput: words = ["a","ab","abc","d","cd","bcd","abcd"]\nOutput: 4\nExplanation: The two words can be "ab", "cd".\n
    \n\n

    Example 3:

    \n\n
    \nInput: words = ["a","aa","aaa","aaaa"]\nOutput: 0\nExplanation: No such pair of words.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= words.length <= 1000
    • \n\t
    • 1 <= words[i].length <= 1000
    • \n\t
    • words[i] consists only of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4 words\uff0c\u627e\u5230 length(word[i]) * length(word[j]) \u7684\u6700\u5927\u503c\uff0c\u5e76\u4e14\u8fd9\u4e24\u4e2a\u5355\u8bcd\u4e0d\u542b\u6709\u516c\u5171\u5b57\u6bcd\u3002\u4f60\u53ef\u4ee5\u8ba4\u4e3a\u6bcf\u4e2a\u5355\u8bcd\u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd\u3002\u5982\u679c\u4e0d\u5b58\u5728\u8fd9\u6837\u7684\u4e24\u4e2a\u5355\u8bcd\uff0c\u8fd4\u56de 0\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: ["abcw","baz","foo","bar","xtfn","abcdef"]\n\u8f93\u51fa: 16 \n\u89e3\u91ca: \u8fd9\u4e24\u4e2a\u5355\u8bcd\u4e3a "abcw", "xtfn"\u3002
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: ["a","ab","abc","d","cd","bcd","abcd"]\n\u8f93\u51fa: 4 \n\u89e3\u91ca: \u8fd9\u4e24\u4e2a\u5355\u8bcd\u4e3a "ab", "cd"\u3002
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u8f93\u5165: ["a","aa","aaa","aaaa"]\n\u8f93\u51fa: 0 \n\u89e3\u91ca: \u4e0d\u5b58\u5728\u8fd9\u6837\u7684\u4e24\u4e2a\u5355\u8bcd\u3002
    \n", "tags_en": ["Bit Manipulation"], "tags_cn": ["\u4f4d\u8fd0\u7b97"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxProduct(vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxProduct(String[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxProduct(self, words):\n \"\"\"\n :type words: List[str]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxProduct(self, words: List[str]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxProduct(char ** words, int wordsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxProduct(string[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @return {number}\n */\nvar maxProduct = function(words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @return {Integer}\ndef max_product(words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxProduct(_ words: [String]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxProduct(words []string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxProduct(words: Array[String]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxProduct(words: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_product(words: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @return Integer\n */\n function maxProduct($words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxProduct(words: string[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-product words)\n (-> (listof string?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0318](https://leetcode-cn.com/problems/maximum-product-of-word-lengths)", "[\u6700\u5927\u5355\u8bcd\u957f\u5ea6\u4e58\u79ef](/solution/0300-0399/0318.Maximum%20Product%20of%20Word%20Lengths/README.md)", "`\u4f4d\u8fd0\u7b97`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0318](https://leetcode.com/problems/maximum-product-of-word-lengths)", "[Maximum Product of Word Lengths](/solution/0300-0399/0318.Maximum%20Product%20of%20Word%20Lengths/README_EN.md)", "`Bit Manipulation`", "Medium", ""]}, {"question_id": "0317", "frontend_question_id": "0317", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/shortest-distance-from-all-buildings", "url_en": "https://leetcode.com/problems/shortest-distance-from-all-buildings", "relative_path_cn": "/solution/0300-0399/0317.Shortest%20Distance%20from%20All%20Buildings/README.md", "relative_path_en": "/solution/0300-0399/0317.Shortest%20Distance%20from%20All%20Buildings/README_EN.md", "title_cn": "\u79bb\u5efa\u7b51\u7269\u6700\u8fd1\u7684\u8ddd\u79bb", "title_en": "Shortest Distance from All Buildings", "question_title_slug": "shortest-distance-from-all-buildings", "content_en": "

    You are given an m x n grid grid of values 0, 1, or 2, where:

    \n\n
      \n\t
    • each 0 marks an empty land that you can pass by freely,
    • \n\t
    • each 1 marks a building that you cannot pass through, and
    • \n\t
    • each 2 marks an obstacle that you cannot pass through.
    • \n
    \n\n

    You want to build a house on an empty land that reaches all buildings in the shortest total travel distance. You can only move up, down, left, and right.

    \n\n

    Return the shortest travel distance for such a house. If it is not possible to build such a house according to the above rules, return -1.

    \n\n

    The total travel distance is the sum of the distances between the houses of the friends and the meeting point.

    \n\n

    The distance is calculated using Manhattan Distance, where distance(p1, p2) = |p2.x - p1.x| + |p2.y - p1.y|.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: grid = [[1,0,2,0,1],[0,0,0,0,0],[0,0,1,0,0]]\nOutput: 7\nExplanation: Given three buildings at (0,0), (0,4), (2,2), and an obstacle at (0,2).\nThe point (1,2) is an ideal empty land to build a house, as the total travel distance of 3+3+1=7 is minimal.\nSo return 7.\n
    \n\n

    Example 2:

    \n\n
    \nInput: grid = [[1,0]]\nOutput: 1\n
    \n\n

    Example 3:

    \n\n
    \nInput: grid = [[1]]\nOutput: -1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= m, n <= 100
    • \n\t
    • grid[i][j] is either 0, 1, or 2.
    • \n\t
    • There will be at least one building in the grid.
    • \n
    \n", "content_cn": "

    \u4f60\u662f\u4e2a\u623f\u5730\u4ea7\u5f00\u53d1\u5546\uff0c\u60f3\u8981\u9009\u62e9\u4e00\u7247\u7a7a\u5730 \u5efa\u4e00\u680b\u5927\u697c\u3002\u4f60\u60f3\u628a\u8fd9\u680b\u5927\u697c\u591f\u9020\u5728\u4e00\u4e2a\u8ddd\u79bb\u5468\u8fb9\u8bbe\u65bd\u90fd\u6bd4\u8f83\u65b9\u4fbf\u7684\u5730\u65b9\uff0c\u901a\u8fc7\u8c03\u7814\uff0c\u4f60\u5e0c\u671b\u4ece\u5b83\u51fa\u53d1\u80fd\u5728 \u6700\u77ed\u7684\u8ddd\u79bb\u548c \u5185\u62b5\u8fbe\u5468\u8fb9\u5168\u90e8\u7684\u5efa\u7b51\u7269\u3002\u8bf7\u4f60\u8ba1\u7b97\u51fa\u8fd9\u4e2a\u6700\u4f73\u7684\u9009\u5740\u5230\u5468\u8fb9\u5168\u90e8\u5efa\u7b51\u7269\u7684 \u6700\u77ed\u8ddd\u79bb\u548c\u3002

    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n

    \u4f60\u53ea\u80fd\u901a\u8fc7\u5411\u4e0a\u3001\u4e0b\u3001\u5de6\u3001\u53f3\u56db\u4e2a\u65b9\u5411\u4e0a\u79fb\u52a8\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u7531 0\u30011 \u548c 2 \u7ec4\u6210\u7684\u4e8c\u7ef4\u7f51\u683c\uff0c\u5176\u4e2d\uff1a

    \n\n
      \n\t
    • 0 \u4ee3\u8868\u4f60\u53ef\u4ee5\u81ea\u7531\u901a\u8fc7\u548c\u9009\u62e9\u5efa\u9020\u7684\u7a7a\u5730
    • \n\t
    • 1 \u4ee3\u8868\u4f60\u65e0\u6cd5\u901a\u884c\u7684\u5efa\u7b51\u7269
    • \n\t
    • 2 \u4ee3\u8868\u4f60\u65e0\u6cd5\u901a\u884c\u7684\u969c\u788d\u7269
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1a[[1,0,2,0,1],[0,0,0,0,0],[0,0,1,0,0]]\n\n1 - 0 - 2 - 0 - 1\n|   |   |   |   |\n0 - 0 - 0 - 0 - 0\n|   |   |   |   |\n0 - 0 - 1 - 0 - 0\n\u8f93\u51fa\uff1a7 \n\u89e3\u6790\uff1a\n\u7ed9\u5b9a\u4e09\u4e2a\u5efa\u7b51\u7269 (0,0)\u3001(0,4) \u548c (2,2) \u4ee5\u53ca\u4e00\u4e2a\u4f4d\u4e8e (0,2) \u7684\u969c\u788d\u7269\u3002\n\u7531\u4e8e\u603b\u8ddd\u79bb\u4e4b\u548c 3+3+1=7 \u6700\u4f18\uff0c\u6240\u4ee5\u4f4d\u7f6e (1,2) \u662f\u7b26\u5408\u8981\u6c42\u7684\u6700\u4f18\u5730\u70b9\uff0c\u6545\u8fd4\u56de7\u3002\n
    \n\n

     

    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u81f3\u5c11\u5b58\u5728\u4e00\u680b\u5efa\u7b51\u7269\uff0c\u5982\u679c\u65e0\u6cd5\u6309\u7167\u4e0a\u8ff0\u89c4\u5219\u8fd4\u56de\u5efa\u623f\u5730\u70b9\uff0c\u5219\u8bf7\u4f60\u8fd4\u56de -1\u3002
    • \n
    \n", "tags_en": ["Breadth-first Search"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int shortestDistance(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int shortestDistance(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def shortestDistance(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def shortestDistance(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint shortestDistance(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ShortestDistance(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar shortestDistance = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef shortest_distance(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func shortestDistance(_ grid: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func shortestDistance(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def shortestDistance(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun shortestDistance(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn shortest_distance(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function shortestDistance($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function shortestDistance(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (shortest-distance grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0317](https://leetcode-cn.com/problems/shortest-distance-from-all-buildings)", "[\u79bb\u5efa\u7b51\u7269\u6700\u8fd1\u7684\u8ddd\u79bb](/solution/0300-0399/0317.Shortest%20Distance%20from%20All%20Buildings/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0317](https://leetcode.com/problems/shortest-distance-from-all-buildings)", "[Shortest Distance from All Buildings](/solution/0300-0399/0317.Shortest%20Distance%20from%20All%20Buildings/README_EN.md)", "`Breadth-first Search`", "Hard", "\ud83d\udd12"]}, {"question_id": "0316", "frontend_question_id": "0316", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/remove-duplicate-letters", "url_en": "https://leetcode.com/problems/remove-duplicate-letters", "relative_path_cn": "/solution/0300-0399/0316.Remove%20Duplicate%20Letters/README.md", "relative_path_en": "/solution/0300-0399/0316.Remove%20Duplicate%20Letters/README_EN.md", "title_cn": "\u53bb\u9664\u91cd\u590d\u5b57\u6bcd", "title_en": "Remove Duplicate Letters", "question_title_slug": "remove-duplicate-letters", "content_en": "

    Given a string s, remove duplicate letters so that every letter appears once and only once. You must make sure your result is the smallest in lexicographical order among all possible results.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "bcabc"\nOutput: "abc"\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "cbacdcbc"\nOutput: "acdb"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 104
    • \n\t
    • s consists of lowercase English letters.
    • \n
    \n\n

     

    \n

    Note: This question is the same as 1081: https://leetcode.com/problems/smallest-subsequence-of-distinct-characters/

    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \uff0c\u8bf7\u4f60\u53bb\u9664\u5b57\u7b26\u4e32\u4e2d\u91cd\u590d\u7684\u5b57\u6bcd\uff0c\u4f7f\u5f97\u6bcf\u4e2a\u5b57\u6bcd\u53ea\u51fa\u73b0\u4e00\u6b21\u3002\u9700\u4fdd\u8bc1 \u8fd4\u56de\u7ed3\u679c\u7684\u5b57\u5178\u5e8f\u6700\u5c0f\uff08\u8981\u6c42\u4e0d\u80fd\u6253\u4e71\u5176\u4ed6\u5b57\u7b26\u7684\u76f8\u5bf9\u4f4d\u7f6e\uff09\u3002

    \n\n

    \u6ce8\u610f\uff1a\u8be5\u9898\u4e0e 1081 https://leetcode-cn.com/problems/smallest-subsequence-of-distinct-characters \u76f8\u540c

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"bcabc\"\n\u8f93\u51fa\uff1a\"abc\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"cbacdcbc\"\n\u8f93\u51fa\uff1a\"acdb\"
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 104
    • \n\t
    • s \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n", "tags_en": ["Stack", "Greedy", "String"], "tags_cn": ["\u6808", "\u8d2a\u5fc3\u7b97\u6cd5", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string removeDuplicateLetters(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String removeDuplicateLetters(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def removeDuplicateLetters(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def removeDuplicateLetters(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * removeDuplicateLetters(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string RemoveDuplicateLetters(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar removeDuplicateLetters = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef remove_duplicate_letters(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func removeDuplicateLetters(_ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func removeDuplicateLetters(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def removeDuplicateLetters(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun removeDuplicateLetters(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn remove_duplicate_letters(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function removeDuplicateLetters($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function removeDuplicateLetters(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (remove-duplicate-letters s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0316](https://leetcode-cn.com/problems/remove-duplicate-letters)", "[\u53bb\u9664\u91cd\u590d\u5b57\u6bcd](/solution/0300-0399/0316.Remove%20Duplicate%20Letters/README.md)", "`\u6808`,`\u8d2a\u5fc3\u7b97\u6cd5`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0316](https://leetcode.com/problems/remove-duplicate-letters)", "[Remove Duplicate Letters](/solution/0300-0399/0316.Remove%20Duplicate%20Letters/README_EN.md)", "`Stack`,`Greedy`,`String`", "Medium", ""]}, {"question_id": "0315", "frontend_question_id": "0315", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-of-smaller-numbers-after-self", "url_en": "https://leetcode.com/problems/count-of-smaller-numbers-after-self", "relative_path_cn": "/solution/0300-0399/0315.Count%20of%20Smaller%20Numbers%20After%20Self/README.md", "relative_path_en": "/solution/0300-0399/0315.Count%20of%20Smaller%20Numbers%20After%20Self/README_EN.md", "title_cn": "\u8ba1\u7b97\u53f3\u4fa7\u5c0f\u4e8e\u5f53\u524d\u5143\u7d20\u7684\u4e2a\u6570", "title_en": "Count of Smaller Numbers After Self", "question_title_slug": "count-of-smaller-numbers-after-self", "content_en": "

    You are given an integer array nums and you have to return a new counts array. The counts array has the property where counts[i] is the number of smaller elements to the right of nums[i].

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [5,2,6,1]\nOutput: [2,1,1,0]\nExplanation:\nTo the right of 5 there are 2 smaller elements (2 and 1).\nTo the right of 2 there is only 1 smaller element (1).\nTo the right of 6 there is 1 smaller element (1).\nTo the right of 1 there is 0 smaller element.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [-1]\nOutput: [0]\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [-1,-1]\nOutput: [0,0]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • -104 <= nums[i] <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums\uff0c\u6309\u8981\u6c42\u8fd4\u56de\u4e00\u4e2a\u65b0\u6570\u7ec4 counts\u3002\u6570\u7ec4 counts \u6709\u8be5\u6027\u8d28\uff1a counts[i] \u7684\u503c\u662f  nums[i] \u53f3\u4fa7\u5c0f\u4e8e nums[i] \u7684\u5143\u7d20\u7684\u6570\u91cf\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [5,2,6,1]\n\u8f93\u51fa\uff1a[2,1,1,0] \n\u89e3\u91ca\uff1a\n5 \u7684\u53f3\u4fa7\u6709 2 \u4e2a\u66f4\u5c0f\u7684\u5143\u7d20 (2 \u548c 1)\n2 \u7684\u53f3\u4fa7\u4ec5\u6709 1 \u4e2a\u66f4\u5c0f\u7684\u5143\u7d20 (1)\n6 \u7684\u53f3\u4fa7\u6709 1 \u4e2a\u66f4\u5c0f\u7684\u5143\u7d20 (1)\n1 \u7684\u53f3\u4fa7\u6709 0 \u4e2a\u66f4\u5c0f\u7684\u5143\u7d20\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= nums.length <= 10^5
    • \n\t
    • -10^4 <= nums[i] <= 10^4
    • \n
    \n", "tags_en": ["Sort", "Binary Indexed Tree", "Segment Tree", "Binary Search", "Divide and Conquer"], "tags_cn": ["\u6392\u5e8f", "\u6811\u72b6\u6570\u7ec4", "\u7ebf\u6bb5\u6811", "\u4e8c\u5206\u67e5\u627e", "\u5206\u6cbb\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector countSmaller(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List countSmaller(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countSmaller(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countSmaller(self, nums: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* countSmaller(int* nums, int numsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList CountSmaller(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar countSmaller = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer[]}\ndef count_smaller(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countSmaller(_ nums: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countSmaller(nums []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countSmaller(nums: Array[Int]): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countSmaller(nums: IntArray): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_smaller(nums: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer[]\n */\n function countSmaller($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countSmaller(nums: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-smaller nums)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0315](https://leetcode-cn.com/problems/count-of-smaller-numbers-after-self)", "[\u8ba1\u7b97\u53f3\u4fa7\u5c0f\u4e8e\u5f53\u524d\u5143\u7d20\u7684\u4e2a\u6570](/solution/0300-0399/0315.Count%20of%20Smaller%20Numbers%20After%20Self/README.md)", "`\u6392\u5e8f`,`\u6811\u72b6\u6570\u7ec4`,`\u7ebf\u6bb5\u6811`,`\u4e8c\u5206\u67e5\u627e`,`\u5206\u6cbb\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[0315](https://leetcode.com/problems/count-of-smaller-numbers-after-self)", "[Count of Smaller Numbers After Self](/solution/0300-0399/0315.Count%20of%20Smaller%20Numbers%20After%20Self/README_EN.md)", "`Sort`,`Binary Indexed Tree`,`Segment Tree`,`Binary Search`,`Divide and Conquer`", "Hard", ""]}, {"question_id": "0314", "frontend_question_id": "0314", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/binary-tree-vertical-order-traversal", "url_en": "https://leetcode.com/problems/binary-tree-vertical-order-traversal", "relative_path_cn": "/solution/0300-0399/0314.Binary%20Tree%20Vertical%20Order%20Traversal/README.md", "relative_path_en": "/solution/0300-0399/0314.Binary%20Tree%20Vertical%20Order%20Traversal/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u7684\u5782\u76f4\u904d\u5386", "title_en": "Binary Tree Vertical Order Traversal", "question_title_slug": "binary-tree-vertical-order-traversal", "content_en": "

    Given the root of a binary tree, return the vertical order traversal of its nodes' values. (i.e., from top to bottom, column by column).

    \n\n

    If two nodes are in the same row and column, the order should be from left to right.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [3,9,20,null,null,15,7]\nOutput: [[9],[3,15],[20],[7]]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [3,9,8,4,0,1,7]\nOutput: [[4],[9],[3,0,1],[8],[7]]\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: root = [3,9,8,4,0,1,7,null,null,null,2,5]\nOutput: [[4],[9,5],[3,0,1],[8,2],[7]]\n
    \n\n

    Example 4:

    \n\n
    \nInput: root = []\nOutput: []\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [0, 100].
    • \n\t
    • -100 <= Node.val <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u4e8c\u53c9\u6811\u7684\u6839\u7ed3\u70b9\uff0c\u8fd4\u56de\u5176\u7ed3\u70b9\u6309 \u5782\u76f4\u65b9\u5411\uff08\u4ece\u4e0a\u5230\u4e0b\uff0c\u9010\u5217\uff09\u904d\u5386\u7684\u7ed3\u679c\u3002

    \n\n

    \u5982\u679c\u4e24\u4e2a\u7ed3\u70b9\u5728\u540c\u4e00\u884c\u548c\u5217\uff0c\u90a3\u4e48\u987a\u5e8f\u5219\u4e3a\u00a0\u4ece\u5de6\u5230\u53f3\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [3,9,20,null,null,15,7]\n\u8f93\u51fa\uff1a[[9],[3,15],[20],[7]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [3,9,8,4,0,1,7]\n\u8f93\u51fa\uff1a[[4],[9],[3,0,1],[8],[7]]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [3,9,8,4,0,1,7,null,null,null,2,5]\n\u8f93\u51fa\uff1a[[4],[9,5],[3,0,1],[8,2],[7]]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = []\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u7ed3\u70b9\u7684\u6570\u76ee\u5728\u8303\u56f4 [0, 100] \u5185
    • \n\t
    • -100 <= Node.val <= 100
    • \n
    \n", "tags_en": ["Depth-first Search", "Breadth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector> verticalOrder(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public List> verticalOrder(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def verticalOrder(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def verticalOrder(self, root: TreeNode) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** verticalOrder(struct TreeNode* root, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public IList> VerticalOrder(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number[][]}\n */\nvar verticalOrder = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer[][]}\ndef vertical_order(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func verticalOrder(_ root: TreeNode?) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc verticalOrder(root *TreeNode) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def verticalOrder(root: TreeNode): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun verticalOrder(root: TreeNode?): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn vertical_order(root: Option>>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer[][]\n */\n function verticalOrder($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction verticalOrder(root: TreeNode | null): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (vertical-order root)\n (-> (or/c tree-node? #f) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0314](https://leetcode-cn.com/problems/binary-tree-vertical-order-traversal)", "[\u4e8c\u53c9\u6811\u7684\u5782\u76f4\u904d\u5386](/solution/0300-0399/0314.Binary%20Tree%20Vertical%20Order%20Traversal/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0314](https://leetcode.com/problems/binary-tree-vertical-order-traversal)", "[Binary Tree Vertical Order Traversal](/solution/0300-0399/0314.Binary%20Tree%20Vertical%20Order%20Traversal/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`", "Medium", "\ud83d\udd12"]}, {"question_id": "0313", "frontend_question_id": "0313", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/super-ugly-number", "url_en": "https://leetcode.com/problems/super-ugly-number", "relative_path_cn": "/solution/0300-0399/0313.Super%20Ugly%20Number/README.md", "relative_path_en": "/solution/0300-0399/0313.Super%20Ugly%20Number/README_EN.md", "title_cn": "\u8d85\u7ea7\u4e11\u6570", "title_en": "Super Ugly Number", "question_title_slug": "super-ugly-number", "content_en": "

    A super ugly number is a positive integer whose prime factors are in the array primes.

    \n\n

    Given an integer n and an array of integers primes, return the nth super ugly number.

    \n\n

    The nth super ugly number is guaranteed to fit in a 32-bit signed integer.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 12, primes = [2,7,13,19]\nOutput: 32\nExplanation: [1,2,4,7,8,13,14,16,19,26,28,32] is the sequence of the first 12 super ugly numbers given primes = [2,7,13,19].\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 1, primes = [2,3,5]\nOutput: 1\nExplanation: 1 has no prime factors, therefore all of its prime factors are in the array primes = [2,3,5].\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 106
    • \n\t
    • 1 <= primes.length <= 100
    • \n\t
    • 2 <= primes[i] <= 1000
    • \n\t
    • primes[i] is guaranteed to be a prime number.
    • \n\t
    • All the values of primes are unique and sorted in ascending order.
    • \n
    \n", "content_cn": "

    \u7f16\u5199\u4e00\u6bb5\u7a0b\u5e8f\u6765\u67e5\u627e\u7b2c n \u4e2a\u8d85\u7ea7\u4e11\u6570\u3002

    \n\n

    \u8d85\u7ea7\u4e11\u6570\u662f\u6307\u5176\u6240\u6709\u8d28\u56e0\u6570\u90fd\u662f\u957f\u5ea6\u4e3a k \u7684\u8d28\u6570\u5217\u8868 primes \u4e2d\u7684\u6b63\u6574\u6570\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: n = 12, primes = [2,7,13,19]\n\u8f93\u51fa: 32 \n\u89e3\u91ca: \u7ed9\u5b9a\u957f\u5ea6\u4e3a 4 \u7684\u8d28\u6570\u5217\u8868 primes = [2,7,13,19]\uff0c\u524d 12 \u4e2a\u8d85\u7ea7\u4e11\u6570\u5e8f\u5217\u4e3a\uff1a[1,2,4,7,8,13,14,16,19,26,28,32] \u3002
    \n\n

    \u8bf4\u660e:

    \n\n
      \n\t
    • 1 \u662f\u4efb\u4f55\u7ed9\u5b9a primes \u7684\u8d85\u7ea7\u4e11\u6570\u3002
    • \n\t
    •  \u7ed9\u5b9a primes \u4e2d\u7684\u6570\u5b57\u4ee5\u5347\u5e8f\u6392\u5217\u3002
    • \n\t
    • 0 < k ≤ 100, 0 < n ≤ 106, 0 < primes[i] < 1000 \u3002
    • \n\t
    • \u7b2c n \u4e2a\u8d85\u7ea7\u4e11\u6570\u786e\u4fdd\u5728 32 \u4f4d\u6709\u7b26\u6574\u6570\u8303\u56f4\u5185\u3002
    • \n
    \n", "tags_en": ["Heap", "Math"], "tags_cn": ["\u5806", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int nthSuperUglyNumber(int n, vector& primes) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int nthSuperUglyNumber(int n, int[] primes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def nthSuperUglyNumber(self, n, primes):\n \"\"\"\n :type n: int\n :type primes: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def nthSuperUglyNumber(self, n: int, primes: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint nthSuperUglyNumber(int n, int* primes, int primesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NthSuperUglyNumber(int n, int[] primes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[]} primes\n * @return {number}\n */\nvar nthSuperUglyNumber = function(n, primes) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[]} primes\n# @return {Integer}\ndef nth_super_ugly_number(n, primes)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func nthSuperUglyNumber(_ n: Int, _ primes: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func nthSuperUglyNumber(n int, primes []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def nthSuperUglyNumber(n: Int, primes: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun nthSuperUglyNumber(n: Int, primes: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn nth_super_ugly_number(n: i32, primes: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[] $primes\n * @return Integer\n */\n function nthSuperUglyNumber($n, $primes) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function nthSuperUglyNumber(n: number, primes: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (nth-super-ugly-number n primes)\n (-> exact-integer? (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0313](https://leetcode-cn.com/problems/super-ugly-number)", "[\u8d85\u7ea7\u4e11\u6570](/solution/0300-0399/0313.Super%20Ugly%20Number/README.md)", "`\u5806`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0313](https://leetcode.com/problems/super-ugly-number)", "[Super Ugly Number](/solution/0300-0399/0313.Super%20Ugly%20Number/README_EN.md)", "`Heap`,`Math`", "Medium", ""]}, {"question_id": "0312", "frontend_question_id": "0312", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/burst-balloons", "url_en": "https://leetcode.com/problems/burst-balloons", "relative_path_cn": "/solution/0300-0399/0312.Burst%20Balloons/README.md", "relative_path_en": "/solution/0300-0399/0312.Burst%20Balloons/README_EN.md", "title_cn": "\u6233\u6c14\u7403", "title_en": "Burst Balloons", "question_title_slug": "burst-balloons", "content_en": "

    You are given n balloons, indexed from 0 to n - 1. Each balloon is painted with a number on it represented by an array nums. You are asked to burst all the balloons.

    \n\n

    If you burst the ith balloon, you will get nums[i - 1] * nums[i] * nums[i + 1] coins. If i - 1 or i + 1 goes out of bounds of the array, then treat it as if there is a balloon with a 1 painted on it.

    \n\n

    Return the maximum coins you can collect by bursting the balloons wisely.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [3,1,5,8]\nOutput: 167\nExplanation:\nnums = [3,1,5,8] --> [3,5,8] --> [3,8] --> [8] --> []\ncoins =  3*1*5    +   3*5*8   +  1*3*8  + 1*8*1 = 167
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,5]\nOutput: 10\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= n <= 500
    • \n\t
    • 0 <= nums[i] <= 100
    • \n
    \n", "content_cn": "

    \u6709 n \u4e2a\u6c14\u7403\uff0c\u7f16\u53f7\u4e3a0 \u5230 n - 1\uff0c\u6bcf\u4e2a\u6c14\u7403\u4e0a\u90fd\u6807\u6709\u4e00\u4e2a\u6570\u5b57\uff0c\u8fd9\u4e9b\u6570\u5b57\u5b58\u5728\u6570\u7ec4\u00a0nums\u00a0\u4e2d\u3002

    \n\n

    \u73b0\u5728\u8981\u6c42\u4f60\u6233\u7834\u6240\u6709\u7684\u6c14\u7403\u3002\u6233\u7834\u7b2c i \u4e2a\u6c14\u7403\uff0c\u4f60\u53ef\u4ee5\u83b7\u5f97\u00a0nums[i - 1] * nums[i] * nums[i + 1] \u679a\u786c\u5e01\u3002\u00a0\u8fd9\u91cc\u7684 i - 1 \u548c i + 1 \u4ee3\u8868\u548c\u00a0i\u00a0\u76f8\u90bb\u7684\u4e24\u4e2a\u6c14\u7403\u7684\u5e8f\u53f7\u3002\u5982\u679c i - 1\u6216 i + 1 \u8d85\u51fa\u4e86\u6570\u7ec4\u7684\u8fb9\u754c\uff0c\u90a3\u4e48\u5c31\u5f53\u5b83\u662f\u4e00\u4e2a\u6570\u5b57\u4e3a 1 \u7684\u6c14\u7403\u3002

    \n\n

    \u6c42\u6240\u80fd\u83b7\u5f97\u786c\u5e01\u7684\u6700\u5927\u6570\u91cf\u3002

    \n\n

    \u00a0

    \n\u793a\u4f8b 1\uff1a\n\n
    \n\u8f93\u5165\uff1anums = [3,1,5,8]\n\u8f93\u51fa\uff1a167\n\u89e3\u91ca\uff1a\nnums = [3,1,5,8] --> [3,5,8] --> [3,8] --> [8] --> []\ncoins =  3*1*5    +   3*5*8   +  1*3*8  + 1*8*1 = 167
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,5]\n\u8f93\u51fa\uff1a10\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= n <= 500
    • \n\t
    • 0 <= nums[i] <= 100
    • \n
    \n", "tags_en": ["Divide and Conquer", "Dynamic Programming"], "tags_cn": ["\u5206\u6cbb\u7b97\u6cd5", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxCoins(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxCoins(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxCoins(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxCoins(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxCoins(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxCoins(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar maxCoins = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef max_coins(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxCoins(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxCoins(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxCoins(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxCoins(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_coins(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function maxCoins($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxCoins(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-coins nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0312](https://leetcode-cn.com/problems/burst-balloons)", "[\u6233\u6c14\u7403](/solution/0300-0399/0312.Burst%20Balloons/README.md)", "`\u5206\u6cbb\u7b97\u6cd5`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0312](https://leetcode.com/problems/burst-balloons)", "[Burst Balloons](/solution/0300-0399/0312.Burst%20Balloons/README_EN.md)", "`Divide and Conquer`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0311", "frontend_question_id": "0311", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/sparse-matrix-multiplication", "url_en": "https://leetcode.com/problems/sparse-matrix-multiplication", "relative_path_cn": "/solution/0300-0399/0311.Sparse%20Matrix%20Multiplication/README.md", "relative_path_en": "/solution/0300-0399/0311.Sparse%20Matrix%20Multiplication/README_EN.md", "title_cn": "\u7a00\u758f\u77e9\u9635\u7684\u4e58\u6cd5", "title_en": "Sparse Matrix Multiplication", "question_title_slug": "sparse-matrix-multiplication", "content_en": "

    Given two sparse matrices mat1 of size m x k and mat2 of size k x n, return the result of mat1 x mat2. You may assume that multiplication is always possible.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: mat1 = [[1,0,0],[-1,0,3]], mat2 = [[7,0,0],[0,0,0],[0,0,1]]\nOutput: [[7,0,0],[-7,0,3]]\n
    \n\n

    Example 2:

    \n\n
    \nInput: mat1 = [[0]], mat2 = [[0]]\nOutput: [[0]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == mat1.length
    • \n\t
    • k == mat1[i].length == mat2.length
    • \n\t
    • n == mat2[i].length
    • \n\t
    • 1 <= m, n, k <= 100
    • \n\t
    • -100 <= mat1[i][j], mat2[i][j] <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a \u7a00\u758f\u77e9\u9635 A \u548c B\uff0c\u8bf7\u4f60\u8fd4\u56de AB \u7684\u7ed3\u679c\u3002\u4f60\u53ef\u4ee5\u9ed8\u8ba4 \u7684\u5217\u6570\u7b49\u4e8e \u7684\u884c\u6570\u3002

    \n\n

    \u8bf7\u4ed4\u7ec6\u9605\u8bfb\u4e0b\u9762\u7684\u793a\u4f8b\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1a\n\nA = [\n  [ 1, 0, 0],\n  [-1, 0, 3]\n]\n\nB = [\n  [ 7, 0, 0 ],\n  [ 0, 0, 0 ],\n  [ 0, 0, 1 ]\n]\n\n\u8f93\u51fa\uff1a\n\n     |  1 0 0 |   | 7 0 0 |   |  7 0 0 |\nAB = | -1 0 3 | x | 0 0 0 | = | -7 0 3 |\n                  | 0 0 1 |\n
    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> multiply(vector>& mat1, vector>& mat2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[][] multiply(int[][] mat1, int[][] mat2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def multiply(self, mat1, mat2):\n \"\"\"\n :type mat1: List[List[int]]\n :type mat2: List[List[int]]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def multiply(self, mat1: List[List[int]], mat2: List[List[int]]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** multiply(int** mat1, int mat1Size, int* mat1ColSize, int** mat2, int mat2Size, int* mat2ColSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[][] Multiply(int[][] mat1, int[][] mat2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} mat1\n * @param {number[][]} mat2\n * @return {number[][]}\n */\nvar multiply = function(mat1, mat2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} mat1\n# @param {Integer[][]} mat2\n# @return {Integer[][]}\ndef multiply(mat1, mat2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func multiply(_ mat1: [[Int]], _ mat2: [[Int]]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func multiply(mat1 [][]int, mat2 [][]int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def multiply(mat1: Array[Array[Int]], mat2: Array[Array[Int]]): Array[Array[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun multiply(mat1: Array, mat2: Array): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn multiply(mat1: Vec>, mat2: Vec>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $mat1\n * @param Integer[][] $mat2\n * @return Integer[][]\n */\n function multiply($mat1, $mat2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function multiply(mat1: number[][], mat2: number[][]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (multiply mat1 mat2)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0311](https://leetcode-cn.com/problems/sparse-matrix-multiplication)", "[\u7a00\u758f\u77e9\u9635\u7684\u4e58\u6cd5](/solution/0300-0399/0311.Sparse%20Matrix%20Multiplication/README.md)", "`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0311](https://leetcode.com/problems/sparse-matrix-multiplication)", "[Sparse Matrix Multiplication](/solution/0300-0399/0311.Sparse%20Matrix%20Multiplication/README_EN.md)", "`Hash Table`", "Medium", "\ud83d\udd12"]}, {"question_id": "0310", "frontend_question_id": "0310", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-height-trees", "url_en": "https://leetcode.com/problems/minimum-height-trees", "relative_path_cn": "/solution/0300-0399/0310.Minimum%20Height%20Trees/README.md", "relative_path_en": "/solution/0300-0399/0310.Minimum%20Height%20Trees/README_EN.md", "title_cn": "\u6700\u5c0f\u9ad8\u5ea6\u6811", "title_en": "Minimum Height Trees", "question_title_slug": "minimum-height-trees", "content_en": "

    A tree is an undirected graph in which any two vertices are connected by exactly one path. In other words, any connected graph without simple cycles is a tree.

    \n\n

    Given a tree of n nodes labelled from 0 to n - 1, and an array of n - 1 edges where edges[i] = [ai, bi] indicates that there is an undirected edge between the two nodes ai and bi in the tree, you can choose any node of the tree as the root. When you select a node x as the root, the result tree has height h. Among all possible rooted trees, those with minimum height (i.e. min(h))  are called minimum height trees (MHTs).

    \n\n

    Return a list of all MHTs' root labels. You can return the answer in any order.

    \n\n

    The height of a rooted tree is the number of edges on the longest downward path between the root and a leaf.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: n = 4, edges = [[1,0],[1,2],[1,3]]\nOutput: [1]\nExplanation: As shown, the height of the tree is 1 when the root is the node with label 1 which is the only MHT.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: n = 6, edges = [[3,0],[3,1],[3,2],[3,4],[5,4]]\nOutput: [3,4]\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 1, edges = []\nOutput: [0]\n
    \n\n

    Example 4:

    \n\n
    \nInput: n = 2, edges = [[0,1]]\nOutput: [0,1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 2 * 104
    • \n\t
    • edges.length == n - 1
    • \n\t
    • 0 <= ai, bi < n
    • \n\t
    • ai != bi
    • \n\t
    • All the pairs (ai, bi) are distinct.
    • \n\t
    • The given input is guaranteed to be a tree and there will be no repeated edges.
    • \n
    \n", "content_cn": "

    \u6811\u662f\u4e00\u4e2a\u65e0\u5411\u56fe\uff0c\u5176\u4e2d\u4efb\u4f55\u4e24\u4e2a\u9876\u70b9\u53ea\u901a\u8fc7\u4e00\u6761\u8def\u5f84\u8fde\u63a5\u3002 \u6362\u53e5\u8bdd\u8bf4\uff0c\u4e00\u4e2a\u4efb\u4f55\u6ca1\u6709\u7b80\u5355\u73af\u8def\u7684\u8fde\u901a\u56fe\u90fd\u662f\u4e00\u68f5\u6811\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u68f5\u5305\u542b\u00a0n\u00a0\u4e2a\u8282\u70b9\u7684\u6811\uff0c\u6807\u8bb0\u4e3a\u00a00\u00a0\u5230\u00a0n - 1 \u3002\u7ed9\u5b9a\u6570\u5b57\u00a0n\u00a0\u548c\u4e00\u4e2a\u6709 n - 1 \u6761\u65e0\u5411\u8fb9\u7684 edges\u00a0\u5217\u8868\uff08\u6bcf\u4e00\u4e2a\u8fb9\u90fd\u662f\u4e00\u5bf9\u6807\u7b7e\uff09\uff0c\u5176\u4e2d edges[i] = [ai, bi] \u8868\u793a\u6811\u4e2d\u8282\u70b9 ai \u548c bi \u4e4b\u95f4\u5b58\u5728\u4e00\u6761\u65e0\u5411\u8fb9\u3002

    \n\n

    \u53ef\u9009\u62e9\u6811\u4e2d\u4efb\u4f55\u4e00\u4e2a\u8282\u70b9\u4f5c\u4e3a\u6839\u3002\u5f53\u9009\u62e9\u8282\u70b9 x \u4f5c\u4e3a\u6839\u8282\u70b9\u65f6\uff0c\u8bbe\u7ed3\u679c\u6811\u7684\u9ad8\u5ea6\u4e3a h \u3002\u5728\u6240\u6709\u53ef\u80fd\u7684\u6811\u4e2d\uff0c\u5177\u6709\u6700\u5c0f\u9ad8\u5ea6\u7684\u6811\uff08\u5373\uff0cmin(h)\uff09\u88ab\u79f0\u4e3a \u6700\u5c0f\u9ad8\u5ea6\u6811 \u3002

    \n\n

    \u8bf7\u4f60\u627e\u5230\u6240\u6709\u7684 \u6700\u5c0f\u9ad8\u5ea6\u6811 \u5e76\u6309 \u4efb\u610f\u987a\u5e8f \u8fd4\u56de\u5b83\u4eec\u7684\u6839\u8282\u70b9\u6807\u7b7e\u5217\u8868\u3002

    \n\u6811\u7684 \u9ad8\u5ea6 \u662f\u6307\u6839\u8282\u70b9\u548c\u53f6\u5b50\u8282\u70b9\u4e4b\u95f4\u6700\u957f\u5411\u4e0b\u8def\u5f84\u4e0a\u8fb9\u7684\u6570\u91cf\u3002\n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1an = 4, edges = [[1,0],[1,2],[1,3]]\n\u8f93\u51fa\uff1a[1]\n\u89e3\u91ca\uff1a\u5982\u56fe\u6240\u793a\uff0c\u5f53\u6839\u662f\u6807\u7b7e\u4e3a 1 \u7684\u8282\u70b9\u65f6\uff0c\u6811\u7684\u9ad8\u5ea6\u662f 1 \uff0c\u8fd9\u662f\u552f\u4e00\u7684\u6700\u5c0f\u9ad8\u5ea6\u6811\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1an = 6, edges = [[3,0],[3,1],[3,2],[3,4],[5,4]]\n\u8f93\u51fa\uff1a[3,4]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 1, edges = []\n\u8f93\u51fa\uff1a[0]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 2, edges = [[0,1]]\n\u8f93\u51fa\uff1a[0,1]\n
    \n\n

    \u00a0

    \n\n
      \n
    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 2 * 104
    • \n\t
    • edges.length == n - 1
    • \n\t
    • 0 <= ai, bi < n
    • \n\t
    • ai != bi
    • \n\t
    • \u6240\u6709 (ai, bi) \u4e92\u4e0d\u76f8\u540c
    • \n\t
    • \u7ed9\u5b9a\u7684\u8f93\u5165 \u4fdd\u8bc1 \u662f\u4e00\u68f5\u6811\uff0c\u5e76\u4e14 \u4e0d\u4f1a\u6709\u91cd\u590d\u7684\u8fb9
    • \n
    \n", "tags_en": ["Breadth-first Search", "Graph"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findMinHeightTrees(int n, vector>& edges) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List findMinHeightTrees(int n, int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findMinHeightTrees(self, n, edges):\n \"\"\"\n :type n: int\n :type edges: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findMinHeightTrees(self, n: int, edges: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* findMinHeightTrees(int n, int** edges, int edgesSize, int* edgesColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList FindMinHeightTrees(int n, int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} edges\n * @return {number[]}\n */\nvar findMinHeightTrees = function(n, edges) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} edges\n# @return {Integer[]}\ndef find_min_height_trees(n, edges)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findMinHeightTrees(_ n: Int, _ edges: [[Int]]) -> [Int] {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findMinHeightTrees(n int, edges [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findMinHeightTrees(n: Int, edges: Array[Array[Int]]): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findMinHeightTrees(n: Int, edges: Array): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_min_height_trees(n: i32, edges: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $edges\n * @return Integer[]\n */\n function findMinHeightTrees($n, $edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findMinHeightTrees(n: number, edges: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-min-height-trees n edges)\n (-> exact-integer? (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0310](https://leetcode-cn.com/problems/minimum-height-trees)", "[\u6700\u5c0f\u9ad8\u5ea6\u6811](/solution/0300-0399/0310.Minimum%20Height%20Trees/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u56fe`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0310](https://leetcode.com/problems/minimum-height-trees)", "[Minimum Height Trees](/solution/0300-0399/0310.Minimum%20Height%20Trees/README_EN.md)", "`Breadth-first Search`,`Graph`", "Medium", ""]}, {"question_id": "0309", "frontend_question_id": "0309", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-with-cooldown", "url_en": "https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-cooldown", "relative_path_cn": "/solution/0300-0399/0309.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20with%20Cooldown/README.md", "relative_path_en": "/solution/0300-0399/0309.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20with%20Cooldown/README_EN.md", "title_cn": "\u6700\u4f73\u4e70\u5356\u80a1\u7968\u65f6\u673a\u542b\u51b7\u51bb\u671f", "title_en": "Best Time to Buy and Sell Stock with Cooldown", "question_title_slug": "best-time-to-buy-and-sell-stock-with-cooldown", "content_en": "

    You are given an array prices where prices[i] is the price of a given stock on the ith day.

    \n\n

    Find the maximum profit you can achieve. You may complete as many transactions as you like (i.e., buy one and sell one share of the stock multiple times) with the following restrictions:

    \n\n
      \n\t
    • After you sell your stock, you cannot buy stock on the next day (i.e., cooldown one day).
    • \n
    \n\n

    Note: You may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again).

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: prices = [1,2,3,0,2]\nOutput: 3\nExplanation: transactions = [buy, sell, cooldown, buy, sell]\n
    \n\n

    Example 2:

    \n\n
    \nInput: prices = [1]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= prices.length <= 5000
    • \n\t
    • 0 <= prices[i] <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\uff0c\u5176\u4e2d\u7b2c i \u4e2a\u5143\u7d20\u4ee3\u8868\u4e86\u7b2c i \u5929\u7684\u80a1\u7968\u4ef7\u683c \u3002\u200b

    \n\n

    \u8bbe\u8ba1\u4e00\u4e2a\u7b97\u6cd5\u8ba1\u7b97\u51fa\u6700\u5927\u5229\u6da6\u3002\u5728\u6ee1\u8db3\u4ee5\u4e0b\u7ea6\u675f\u6761\u4ef6\u4e0b\uff0c\u4f60\u53ef\u4ee5\u5c3d\u53ef\u80fd\u5730\u5b8c\u6210\u66f4\u591a\u7684\u4ea4\u6613\uff08\u591a\u6b21\u4e70\u5356\u4e00\u652f\u80a1\u7968\uff09:

    \n\n
      \n\t
    • \u4f60\u4e0d\u80fd\u540c\u65f6\u53c2\u4e0e\u591a\u7b14\u4ea4\u6613\uff08\u4f60\u5fc5\u987b\u5728\u518d\u6b21\u8d2d\u4e70\u524d\u51fa\u552e\u6389\u4e4b\u524d\u7684\u80a1\u7968\uff09\u3002
    • \n\t
    • \u5356\u51fa\u80a1\u7968\u540e\uff0c\u4f60\u65e0\u6cd5\u5728\u7b2c\u4e8c\u5929\u4e70\u5165\u80a1\u7968 (\u5373\u51b7\u51bb\u671f\u4e3a 1 \u5929)\u3002
    • \n
    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: [1,2,3,0,2]\n\u8f93\u51fa: 3 \n\u89e3\u91ca: \u5bf9\u5e94\u7684\u4ea4\u6613\u72b6\u6001\u4e3a: [\u4e70\u5165, \u5356\u51fa, \u51b7\u51bb\u671f, \u4e70\u5165, \u5356\u51fa]
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxProfit(vector& prices) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxProfit(int[] prices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxProfit(self, prices):\n \"\"\"\n :type prices: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxProfit(self, prices: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxProfit(int* prices, int pricesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxProfit(int[] prices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} prices\n * @return {number}\n */\nvar maxProfit = function(prices) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} prices\n# @return {Integer}\ndef max_profit(prices)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxProfit(_ prices: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxProfit(prices []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxProfit(prices: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxProfit(prices: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_profit(prices: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $prices\n * @return Integer\n */\n function maxProfit($prices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxProfit(prices: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-profit prices)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0309](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-with-cooldown)", "[\u6700\u4f73\u4e70\u5356\u80a1\u7968\u65f6\u673a\u542b\u51b7\u51bb\u671f](/solution/0300-0399/0309.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20with%20Cooldown/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0309](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-cooldown)", "[Best Time to Buy and Sell Stock with Cooldown](/solution/0300-0399/0309.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20with%20Cooldown/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0308", "frontend_question_id": "0308", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/range-sum-query-2d-mutable", "url_en": "https://leetcode.com/problems/range-sum-query-2d-mutable", "relative_path_cn": "/solution/0300-0399/0308.Range%20Sum%20Query%202D%20-%20Mutable/README.md", "relative_path_en": "/solution/0300-0399/0308.Range%20Sum%20Query%202D%20-%20Mutable/README_EN.md", "title_cn": "\u4e8c\u7ef4\u533a\u57df\u548c\u68c0\u7d22 - \u53ef\u53d8", "title_en": "Range Sum Query 2D - Mutable", "question_title_slug": "range-sum-query-2d-mutable", "content_en": "

    Given a 2D matrix matrix, handle multiple queries of the following types:

    \n\n
      \n\t
    1. Update the value of a cell in matrix.
    2. \n\t
    3. Calculate the sum of the elements of matrix inside the rectangle defined by its upper left corner (row1, col1) and lower right corner (row2, col2).
    4. \n
    \n\n

    Implement the NumMatrix class:

    \n\n
      \n\t
    • NumMatrix(int[][] matrix) Initializes the object with the integer matrix matrix.
    • \n\t
    • void update(int row, int col, int val) Updates the value of matrix[row][col] to be val.
    • \n\t
    • int sumRegion(int row1, int col1, int row2, int col2) Returns the sum of the elements of matrix inside the rectangle defined by its upper left corner (row1, col1) and lower right corner (row2, col2).
    • \n
    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput\n["NumMatrix", "sumRegion", "update", "sumRegion"]\n[[[[3, 0, 1, 4, 2], [5, 6, 3, 2, 1], [1, 2, 0, 1, 5], [4, 1, 0, 1, 7], [1, 0, 3, 0, 5]]], [2, 1, 4, 3], [3, 2, 2], [2, 1, 4, 3]]\nOutput\n[null, 8, null, 10]\n\nExplanation\nNumMatrix numMatrix = new NumMatrix([[3, 0, 1, 4, 2], [5, 6, 3, 2, 1], [1, 2, 0, 1, 5], [4, 1, 0, 1, 7], [1, 0, 3, 0, 5]]);\nnumMatrix.sumRegion(2, 1, 4, 3); // return 8 (i.e. sum of the left red rectangle)\nnumMatrix.update(3, 2, 2);       // matrix changes from left image to right image\nnumMatrix.sumRegion(2, 1, 4, 3); // return 10 (i.e. sum of the right red rectangle)\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == matrix.length
    • \n\t
    • n == matrix[i].length
    • \n\t
    • 1 <= m, n <= 200
    • \n\t
    • -105 <= matrix[i][j] <= 105
    • \n\t
    • 0 <= row < m
    • \n\t
    • 0 <= col < n
    • \n\t
    • -105 <= val <= 105
    • \n\t
    • 0 <= row1 <= row2 < m
    • \n\t
    • 0 <= col1 <= col2 < n
    • \n\t
    • At most 104 calls will be made to sumRegion and update.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a 2D \u77e9\u9635 matrix\uff0c\u8bf7\u8ba1\u7b97\u51fa\u4ece\u5de6\u4e0a\u89d2 (row1, col1) \u5230\u53f3\u4e0b\u89d2 (row2, col2) \u7ec4\u6210\u7684\u77e9\u5f62\u4e2d\u6240\u6709\u5143\u7d20\u7684\u548c\u3002

    \n\n

    \"Range
    \n\u4e0a\u8ff0\u7c89\u8272\u77e9\u5f62\u6846\u5185\u7684\uff0c\u8be5\u77e9\u5f62\u7531\u5de6\u4e0a\u89d2 (row1, col1) = (2, 1) \u548c\u53f3\u4e0b\u89d2 (row2, col2) = (4, 3) \u786e\u5b9a\u3002\u5176\u4e2d\uff0c\u6240\u5305\u62ec\u7684\u5143\u7d20\u603b\u548c sum = 8\u3002

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u7ed9\u5b9a matrix = [\n  [3, 0, 1, 4, 2],\n  [5, 6, 3, 2, 1],\n  [1, 2, 0, 1, 5],\n  [4, 1, 0, 1, 7],\n  [1, 0, 3, 0, 5]\n]\n\nsumRegion(2, 1, 4, 3) -> 8\nupdate(3, 2, 2)\nsumRegion(2, 1, 4, 3) -> 10\n
    \n\n

     

    \n\n

    \u6ce8\u610f:

    \n\n
      \n\t
    1. \u77e9\u9635 matrix \u7684\u503c\u53ea\u80fd\u901a\u8fc7 update \u51fd\u6570\u6765\u8fdb\u884c\u4fee\u6539
    2. \n\t
    3. \u4f60\u53ef\u4ee5\u9ed8\u8ba4 update \u51fd\u6570\u548c sumRegion \u51fd\u6570\u7684\u8c03\u7528\u6b21\u6570\u662f\u5747\u5300\u5206\u5e03\u7684
    4. \n\t
    5. \u4f60\u53ef\u4ee5\u9ed8\u8ba4 row1 ≤ row2\uff0ccol1 ≤ col2
    6. \n
    \n\n

     

    \n", "tags_en": ["Binary Indexed Tree", "Segment Tree"], "tags_cn": ["\u6811\u72b6\u6570\u7ec4", "\u7ebf\u6bb5\u6811"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class NumMatrix {\npublic:\n NumMatrix(vector>& matrix) {\n\n }\n \n void update(int row, int col, int val) {\n\n }\n \n int sumRegion(int row1, int col1, int row2, int col2) {\n\n }\n};\n\n/**\n * Your NumMatrix object will be instantiated and called as such:\n * NumMatrix* obj = new NumMatrix(matrix);\n * obj->update(row,col,val);\n * int param_2 = obj->sumRegion(row1,col1,row2,col2);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class NumMatrix {\n\n public NumMatrix(int[][] matrix) {\n\n }\n \n public void update(int row, int col, int val) {\n\n }\n \n public int sumRegion(int row1, int col1, int row2, int col2) {\n\n }\n}\n\n/**\n * Your NumMatrix object will be instantiated and called as such:\n * NumMatrix obj = new NumMatrix(matrix);\n * obj.update(row,col,val);\n * int param_2 = obj.sumRegion(row1,col1,row2,col2);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class NumMatrix(object):\n\n def __init__(self, matrix):\n \"\"\"\n :type matrix: List[List[int]]\n \"\"\"\n\n\n def update(self, row, col, val):\n \"\"\"\n :type row: int\n :type col: int\n :type val: int\n :rtype: None\n \"\"\"\n\n\n def sumRegion(self, row1, col1, row2, col2):\n \"\"\"\n :type row1: int\n :type col1: int\n :type row2: int\n :type col2: int\n :rtype: int\n \"\"\"\n\n\n\n# Your NumMatrix object will be instantiated and called as such:\n# obj = NumMatrix(matrix)\n# obj.update(row,col,val)\n# param_2 = obj.sumRegion(row1,col1,row2,col2)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class NumMatrix:\n\n def __init__(self, matrix: List[List[int]]):\n\n\n def update(self, row: int, col: int, val: int) -> None:\n\n\n def sumRegion(self, row1: int, col1: int, row2: int, col2: int) -> int:\n\n\n\n# Your NumMatrix object will be instantiated and called as such:\n# obj = NumMatrix(matrix)\n# obj.update(row,col,val)\n# param_2 = obj.sumRegion(row1,col1,row2,col2)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} NumMatrix;\n\n\nNumMatrix* numMatrixCreate(int** matrix, int matrixSize, int* matrixColSize) {\n\n}\n\nvoid numMatrixUpdate(NumMatrix* obj, int row, int col, int val) {\n\n}\n\nint numMatrixSumRegion(NumMatrix* obj, int row1, int col1, int row2, int col2) {\n\n}\n\nvoid numMatrixFree(NumMatrix* obj) {\n\n}\n\n/**\n * Your NumMatrix struct will be instantiated and called as such:\n * NumMatrix* obj = numMatrixCreate(matrix, matrixSize, matrixColSize);\n * numMatrixUpdate(obj, row, col, val);\n \n * int param_2 = numMatrixSumRegion(obj, row1, col1, row2, col2);\n \n * numMatrixFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class NumMatrix {\n\n public NumMatrix(int[][] matrix) {\n\n }\n \n public void Update(int row, int col, int val) {\n\n }\n \n public int SumRegion(int row1, int col1, int row2, int col2) {\n\n }\n}\n\n/**\n * Your NumMatrix object will be instantiated and called as such:\n * NumMatrix obj = new NumMatrix(matrix);\n * obj.Update(row,col,val);\n * int param_2 = obj.SumRegion(row1,col1,row2,col2);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} matrix\n */\nvar NumMatrix = function(matrix) {\n\n};\n\n/** \n * @param {number} row \n * @param {number} col \n * @param {number} val\n * @return {void}\n */\nNumMatrix.prototype.update = function(row, col, val) {\n\n};\n\n/** \n * @param {number} row1 \n * @param {number} col1 \n * @param {number} row2 \n * @param {number} col2\n * @return {number}\n */\nNumMatrix.prototype.sumRegion = function(row1, col1, row2, col2) {\n\n};\n\n/**\n * Your NumMatrix object will be instantiated and called as such:\n * var obj = new NumMatrix(matrix)\n * obj.update(row,col,val)\n * var param_2 = obj.sumRegion(row1,col1,row2,col2)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class NumMatrix\n\n=begin\n :type matrix: Integer[][]\n=end\n def initialize(matrix)\n\n end\n\n\n=begin\n :type row: Integer\n :type col: Integer\n :type val: Integer\n :rtype: Void\n=end\n def update(row, col, val)\n\n end\n\n\n=begin\n :type row1: Integer\n :type col1: Integer\n :type row2: Integer\n :type col2: Integer\n :rtype: Integer\n=end\n def sum_region(row1, col1, row2, col2)\n\n end\n\n\nend\n\n# Your NumMatrix object will be instantiated and called as such:\n# obj = NumMatrix.new(matrix)\n# obj.update(row, col, val)\n# param_2 = obj.sum_region(row1, col1, row2, col2)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass NumMatrix {\n\n init(_ matrix: [[Int]]) {\n\n }\n \n func update(_ row: Int, _ col: Int, _ val: Int) {\n\n }\n \n func sumRegion(_ row1: Int, _ col1: Int, _ row2: Int, _ col2: Int) -> Int {\n\n }\n}\n\n/**\n * Your NumMatrix object will be instantiated and called as such:\n * let obj = NumMatrix(matrix)\n * obj.update(row, col, val)\n * let ret_2: Int = obj.sumRegion(row1, col1, row2, col2)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type NumMatrix struct {\n\n}\n\n\nfunc Constructor(matrix [][]int) NumMatrix {\n\n}\n\n\nfunc (this *NumMatrix) Update(row int, col int, val int) {\n\n}\n\n\nfunc (this *NumMatrix) SumRegion(row1 int, col1 int, row2 int, col2 int) int {\n\n}\n\n\n/**\n * Your NumMatrix object will be instantiated and called as such:\n * obj := Constructor(matrix);\n * obj.Update(row,col,val);\n * param_2 := obj.SumRegion(row1,col1,row2,col2);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class NumMatrix(_matrix: Array[Array[Int]]) {\n\n def update(row: Int, col: Int, `val`: Int) {\n\n }\n\n def sumRegion(row1: Int, col1: Int, row2: Int, col2: Int): Int = {\n\n }\n\n}\n\n/**\n * Your NumMatrix object will be instantiated and called as such:\n * var obj = new NumMatrix(matrix)\n * obj.update(row,col,`val`)\n * var param_2 = obj.sumRegion(row1,col1,row2,col2)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class NumMatrix(matrix: Array) {\n\n fun update(row: Int, col: Int, `val`: Int) {\n\n }\n\n fun sumRegion(row1: Int, col1: Int, row2: Int, col2: Int): Int {\n\n }\n\n}\n\n/**\n * Your NumMatrix object will be instantiated and called as such:\n * var obj = NumMatrix(matrix)\n * obj.update(row,col,`val`)\n * var param_2 = obj.sumRegion(row1,col1,row2,col2)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct NumMatrix {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl NumMatrix {\n\n fn new(matrix: Vec>) -> Self {\n\n }\n \n fn update(&self, row: i32, col: i32, val: i32) {\n\n }\n \n fn sum_region(&self, row1: i32, col1: i32, row2: i32, col2: i32) -> i32 {\n\n }\n}\n\n/**\n * Your NumMatrix object will be instantiated and called as such:\n * let obj = NumMatrix::new(matrix);\n * obj.update(row, col, val);\n * let ret_2: i32 = obj.sum_region(row1, col1, row2, col2);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class NumMatrix {\n /**\n * @param Integer[][] $matrix\n */\n function __construct($matrix) {\n\n }\n\n /**\n * @param Integer $row\n * @param Integer $col\n * @param Integer $val\n * @return NULL\n */\n function update($row, $col, $val) {\n\n }\n\n /**\n * @param Integer $row1\n * @param Integer $col1\n * @param Integer $row2\n * @param Integer $col2\n * @return Integer\n */\n function sumRegion($row1, $col1, $row2, $col2) {\n\n }\n}\n\n/**\n * Your NumMatrix object will be instantiated and called as such:\n * $obj = NumMatrix($matrix);\n * $obj->update($row, $col, $val);\n * $ret_2 = $obj->sumRegion($row1, $col1, $row2, $col2);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class NumMatrix {\n constructor(matrix: number[][]) {\n\n }\n\n update(row: number, col: number, val: number): void {\n\n }\n\n sumRegion(row1: number, col1: number, row2: number, col2: number): number {\n\n }\n}\n\n/**\n * Your NumMatrix object will be instantiated and called as such:\n * var obj = new NumMatrix(matrix)\n * obj.update(row,col,val)\n * var param_2 = obj.sumRegion(row1,col1,row2,col2)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define num-matrix%\n (class object%\n (super-new)\n\n ; matrix : (listof (listof exact-integer?))\n (init-field\n matrix)\n \n ; update : exact-integer? exact-integer? exact-integer? -> void?\n (define/public (update row col val)\n\n )\n ; sum-region : exact-integer? exact-integer? exact-integer? exact-integer? -> exact-integer?\n (define/public (sum-region row1 col1 row2 col2)\n\n )))\n\n;; Your num-matrix% object will be instantiated and called as such:\n;; (define obj (new num-matrix% [matrix matrix]))\n;; (send obj update row col val)\n;; (define param_2 (send obj sum-region row1 col1 row2 col2))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0308](https://leetcode-cn.com/problems/range-sum-query-2d-mutable)", "[\u4e8c\u7ef4\u533a\u57df\u548c\u68c0\u7d22 - \u53ef\u53d8](/solution/0300-0399/0308.Range%20Sum%20Query%202D%20-%20Mutable/README.md)", "`\u6811\u72b6\u6570\u7ec4`,`\u7ebf\u6bb5\u6811`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0308](https://leetcode.com/problems/range-sum-query-2d-mutable)", "[Range Sum Query 2D - Mutable](/solution/0300-0399/0308.Range%20Sum%20Query%202D%20-%20Mutable/README_EN.md)", "`Binary Indexed Tree`,`Segment Tree`", "Hard", "\ud83d\udd12"]}, {"question_id": "0307", "frontend_question_id": "0307", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/range-sum-query-mutable", "url_en": "https://leetcode.com/problems/range-sum-query-mutable", "relative_path_cn": "/solution/0300-0399/0307.Range%20Sum%20Query%20-%20Mutable/README.md", "relative_path_en": "/solution/0300-0399/0307.Range%20Sum%20Query%20-%20Mutable/README_EN.md", "title_cn": "\u533a\u57df\u548c\u68c0\u7d22 - \u6570\u7ec4\u53ef\u4fee\u6539", "title_en": "Range Sum Query - Mutable", "question_title_slug": "range-sum-query-mutable", "content_en": "

    Given an integer array nums, handle multiple queries of the following types:

    \n\n
      \n\t
    1. Update the value of an element in nums.
    2. \n\t
    3. Calculate the sum of the elements of nums between indices left and right inclusive where left <= right.
    4. \n
    \n\n

    Implement the NumArray class:

    \n\n
      \n\t
    • NumArray(int[] nums) Initializes the object with the integer array nums.
    • \n\t
    • void update(int index, int val) Updates the value of nums[index] to be val.
    • \n\t
    • int sumRange(int left, int right) Returns the sum of the elements of nums between indices left and right inclusive (i.e. nums[left] + nums[left + 1] + ... + nums[right]).
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["NumArray", "sumRange", "update", "sumRange"]\n[[[1, 3, 5]], [0, 2], [1, 2], [0, 2]]\nOutput\n[null, 9, null, 8]\n\nExplanation\nNumArray numArray = new NumArray([1, 3, 5]);\nnumArray.sumRange(0, 2); // return 1 + 3 + 5 = 9\nnumArray.update(1, 2);   // nums = [1, 2, 5]\nnumArray.sumRange(0, 2); // return 1 + 2 + 5 = 8\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 3 * 104
    • \n\t
    • -100 <= nums[i] <= 100
    • \n\t
    • 0 <= index < nums.length
    • \n\t
    • -100 <= val <= 100
    • \n\t
    • 0 <= left <= right < nums.length
    • \n\t
    • At most 3 * 104 calls will be made to update and sumRange.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 nums \uff0c\u8bf7\u4f60\u5b8c\u6210\u4e24\u7c7b\u67e5\u8be2\uff0c\u5176\u4e2d\u4e00\u7c7b\u67e5\u8be2\u8981\u6c42\u66f4\u65b0\u6570\u7ec4\u4e0b\u6807\u5bf9\u5e94\u7684\u503c\uff0c\u53e6\u4e00\u7c7b\u67e5\u8be2\u8981\u6c42\u8fd4\u56de\u6570\u7ec4\u4e2d\u67d0\u4e2a\u8303\u56f4\u5185\u5143\u7d20\u7684\u603b\u548c\u3002

    \n\n

    \u5b9e\u73b0 NumArray \u7c7b\uff1a

    \n\n
    \n
    \n
      \n\t
    • NumArray(int[] nums) \u7528\u6574\u6570\u6570\u7ec4 nums \u521d\u59cb\u5316\u5bf9\u8c61
    • \n\t
    • void update(int index, int val) \u5c06 nums[index] \u7684\u503c\u66f4\u65b0\u4e3a val
    • \n\t
    • int sumRange(int left, int right) \u8fd4\u56de\u5b50\u6570\u7ec4 nums[left, right] \u7684\u603b\u548c\uff08\u5373\uff0cnums[left] + nums[left + 1], ..., nums[right]\uff09
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\n[\"NumArray\", \"sumRange\", \"update\", \"sumRange\"]\n[[[1, 3, 5]], [0, 2], [1, 2], [0, 2]]\n\u8f93\u51fa\uff1a\n[null, 9, null, 8]\n\n\u89e3\u91ca\uff1a\nNumArray numArray = new NumArray([1, 3, 5]);\nnumArray.sumRange(0, 2); // \u8fd4\u56de 9 \uff0csum([1,3,5]) = 9\nnumArray.update(1, 2);   // nums = [1,2,5]\nnumArray.sumRange(0, 2); // \u8fd4\u56de 8 \uff0csum([1,2,5]) = 8\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 3 * 104
    • \n\t
    • -100 <= nums[i] <= 100
    • \n\t
    • 0 <= index < nums.length
    • \n\t
    • -100 <= val <= 100
    • \n\t
    • 0 <= left <= right < nums.length
    • \n\t
    • \u6700\u591a\u8c03\u7528 3 * 104 \u6b21 update \u548c sumRange \u65b9\u6cd5
    • \n
    \n
    \n
    \n", "tags_en": ["Binary Indexed Tree", "Segment Tree"], "tags_cn": ["\u6811\u72b6\u6570\u7ec4", "\u7ebf\u6bb5\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class NumArray {\npublic:\n NumArray(vector& nums) {\n\n }\n \n void update(int index, int val) {\n\n }\n \n int sumRange(int left, int right) {\n\n }\n};\n\n/**\n * Your NumArray object will be instantiated and called as such:\n * NumArray* obj = new NumArray(nums);\n * obj->update(index,val);\n * int param_2 = obj->sumRange(left,right);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class NumArray {\n\n public NumArray(int[] nums) {\n\n }\n \n public void update(int index, int val) {\n\n }\n \n public int sumRange(int left, int right) {\n\n }\n}\n\n/**\n * Your NumArray object will be instantiated and called as such:\n * NumArray obj = new NumArray(nums);\n * obj.update(index,val);\n * int param_2 = obj.sumRange(left,right);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class NumArray(object):\n\n def __init__(self, nums):\n \"\"\"\n :type nums: List[int]\n \"\"\"\n\n\n def update(self, index, val):\n \"\"\"\n :type index: int\n :type val: int\n :rtype: None\n \"\"\"\n\n\n def sumRange(self, left, right):\n \"\"\"\n :type left: int\n :type right: int\n :rtype: int\n \"\"\"\n\n\n\n# Your NumArray object will be instantiated and called as such:\n# obj = NumArray(nums)\n# obj.update(index,val)\n# param_2 = obj.sumRange(left,right)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class NumArray:\n\n def __init__(self, nums: List[int]):\n\n\n def update(self, index: int, val: int) -> None:\n\n\n def sumRange(self, left: int, right: int) -> int:\n\n\n\n# Your NumArray object will be instantiated and called as such:\n# obj = NumArray(nums)\n# obj.update(index,val)\n# param_2 = obj.sumRange(left,right)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} NumArray;\n\n\nNumArray* numArrayCreate(int* nums, int numsSize) {\n\n}\n\nvoid numArrayUpdate(NumArray* obj, int index, int val) {\n\n}\n\nint numArraySumRange(NumArray* obj, int left, int right) {\n\n}\n\nvoid numArrayFree(NumArray* obj) {\n\n}\n\n/**\n * Your NumArray struct will be instantiated and called as such:\n * NumArray* obj = numArrayCreate(nums, numsSize);\n * numArrayUpdate(obj, index, val);\n \n * int param_2 = numArraySumRange(obj, left, right);\n \n * numArrayFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class NumArray {\n\n public NumArray(int[] nums) {\n\n }\n \n public void Update(int index, int val) {\n\n }\n \n public int SumRange(int left, int right) {\n\n }\n}\n\n/**\n * Your NumArray object will be instantiated and called as such:\n * NumArray obj = new NumArray(nums);\n * obj.Update(index,val);\n * int param_2 = obj.SumRange(left,right);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n */\nvar NumArray = function(nums) {\n\n};\n\n/** \n * @param {number} index \n * @param {number} val\n * @return {void}\n */\nNumArray.prototype.update = function(index, val) {\n\n};\n\n/** \n * @param {number} left \n * @param {number} right\n * @return {number}\n */\nNumArray.prototype.sumRange = function(left, right) {\n\n};\n\n/**\n * Your NumArray object will be instantiated and called as such:\n * var obj = new NumArray(nums)\n * obj.update(index,val)\n * var param_2 = obj.sumRange(left,right)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class NumArray\n\n=begin\n :type nums: Integer[]\n=end\n def initialize(nums)\n\n end\n\n\n=begin\n :type index: Integer\n :type val: Integer\n :rtype: Void\n=end\n def update(index, val)\n\n end\n\n\n=begin\n :type left: Integer\n :type right: Integer\n :rtype: Integer\n=end\n def sum_range(left, right)\n\n end\n\n\nend\n\n# Your NumArray object will be instantiated and called as such:\n# obj = NumArray.new(nums)\n# obj.update(index, val)\n# param_2 = obj.sum_range(left, right)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass NumArray {\n\n init(_ nums: [Int]) {\n\n }\n \n func update(_ index: Int, _ val: Int) {\n\n }\n \n func sumRange(_ left: Int, _ right: Int) -> Int {\n\n }\n}\n\n/**\n * Your NumArray object will be instantiated and called as such:\n * let obj = NumArray(nums)\n * obj.update(index, val)\n * let ret_2: Int = obj.sumRange(left, right)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type NumArray struct {\n\n}\n\n\nfunc Constructor(nums []int) NumArray {\n\n}\n\n\nfunc (this *NumArray) Update(index int, val int) {\n\n}\n\n\nfunc (this *NumArray) SumRange(left int, right int) int {\n\n}\n\n\n/**\n * Your NumArray object will be instantiated and called as such:\n * obj := Constructor(nums);\n * obj.Update(index,val);\n * param_2 := obj.SumRange(left,right);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class NumArray(_nums: Array[Int]) {\n\n def update(index: Int, `val`: Int) {\n\n }\n\n def sumRange(left: Int, right: Int): Int = {\n\n }\n\n}\n\n/**\n * Your NumArray object will be instantiated and called as such:\n * var obj = new NumArray(nums)\n * obj.update(index,`val`)\n * var param_2 = obj.sumRange(left,right)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class NumArray(nums: IntArray) {\n\n fun update(index: Int, `val`: Int) {\n\n }\n\n fun sumRange(left: Int, right: Int): Int {\n\n }\n\n}\n\n/**\n * Your NumArray object will be instantiated and called as such:\n * var obj = NumArray(nums)\n * obj.update(index,`val`)\n * var param_2 = obj.sumRange(left,right)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct NumArray {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl NumArray {\n\n fn new(nums: Vec) -> Self {\n\n }\n \n fn update(&self, index: i32, val: i32) {\n\n }\n \n fn sum_range(&self, left: i32, right: i32) -> i32 {\n\n }\n}\n\n/**\n * Your NumArray object will be instantiated and called as such:\n * let obj = NumArray::new(nums);\n * obj.update(index, val);\n * let ret_2: i32 = obj.sum_range(left, right);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class NumArray {\n /**\n * @param Integer[] $nums\n */\n function __construct($nums) {\n\n }\n\n /**\n * @param Integer $index\n * @param Integer $val\n * @return NULL\n */\n function update($index, $val) {\n\n }\n\n /**\n * @param Integer $left\n * @param Integer $right\n * @return Integer\n */\n function sumRange($left, $right) {\n\n }\n}\n\n/**\n * Your NumArray object will be instantiated and called as such:\n * $obj = NumArray($nums);\n * $obj->update($index, $val);\n * $ret_2 = $obj->sumRange($left, $right);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class NumArray {\n constructor(nums: number[]) {\n\n }\n\n update(index: number, val: number): void {\n\n }\n\n sumRange(left: number, right: number): number {\n\n }\n}\n\n/**\n * Your NumArray object will be instantiated and called as such:\n * var obj = new NumArray(nums)\n * obj.update(index,val)\n * var param_2 = obj.sumRange(left,right)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define num-array%\n (class object%\n (super-new)\n\n ; nums : (listof exact-integer?)\n (init-field\n nums)\n \n ; update : exact-integer? exact-integer? -> void?\n (define/public (update index val)\n\n )\n ; sum-range : exact-integer? exact-integer? -> exact-integer?\n (define/public (sum-range left right)\n\n )))\n\n;; Your num-array% object will be instantiated and called as such:\n;; (define obj (new num-array% [nums nums]))\n;; (send obj update index val)\n;; (define param_2 (send obj sum-range left right))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0307](https://leetcode-cn.com/problems/range-sum-query-mutable)", "[\u533a\u57df\u548c\u68c0\u7d22 - \u6570\u7ec4\u53ef\u4fee\u6539](/solution/0300-0399/0307.Range%20Sum%20Query%20-%20Mutable/README.md)", "`\u6811\u72b6\u6570\u7ec4`,`\u7ebf\u6bb5\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0307](https://leetcode.com/problems/range-sum-query-mutable)", "[Range Sum Query - Mutable](/solution/0300-0399/0307.Range%20Sum%20Query%20-%20Mutable/README_EN.md)", "`Binary Indexed Tree`,`Segment Tree`", "Medium", ""]}, {"question_id": "0306", "frontend_question_id": "0306", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/additive-number", "url_en": "https://leetcode.com/problems/additive-number", "relative_path_cn": "/solution/0300-0399/0306.Additive%20Number/README.md", "relative_path_en": "/solution/0300-0399/0306.Additive%20Number/README_EN.md", "title_cn": "\u7d2f\u52a0\u6570", "title_en": "Additive Number", "question_title_slug": "additive-number", "content_en": "

    Additive number is a string whose digits can form additive sequence.

    \n\n

    A valid additive sequence should contain at least three numbers. Except for the first two numbers, each subsequent number in the sequence must be the sum of the preceding two.

    \n\n

    Given a string containing only digits '0'-'9', write a function to determine if it's an additive number.

    \n\n

    Note: Numbers in the additive sequence cannot have leading zeros, so sequence 1, 2, 03 or 1, 02, 3 is invalid.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: "112358"\nOutput: true\nExplanation: The digits can form an additive sequence: 1, 1, 2, 3, 5, 8. \n             1 + 1 = 2, 1 + 2 = 3, 2 + 3 = 5, 3 + 5 = 8\n
    \n\n

    Example 2:

    \n\n
    \nInput: "199100199"\nOutput: true\nExplanation: The additive sequence is: 1, 99, 100, 199. \n             1 + 99 = 100, 99 + 100 = 199\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • num consists only of digits '0'-'9'.
    • \n\t
    • 1 <= num.length <= 35
    • \n
    \n\n

    Follow up:
    \nHow would you handle overflow for very large input integers?

    \n", "content_cn": "

    \u7d2f\u52a0\u6570\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u7ec4\u6210\u5b83\u7684\u6570\u5b57\u53ef\u4ee5\u5f62\u6210\u7d2f\u52a0\u5e8f\u5217\u3002

    \n\n

    \u4e00\u4e2a\u6709\u6548\u7684\u7d2f\u52a0\u5e8f\u5217\u5fc5\u987b\u81f3\u5c11\u5305\u542b 3 \u4e2a\u6570\u3002\u9664\u4e86\u6700\u5f00\u59cb\u7684\u4e24\u4e2a\u6570\u4ee5\u5916\uff0c\u5b57\u7b26\u4e32\u4e2d\u7684\u5176\u4ed6\u6570\u90fd\u7b49\u4e8e\u5b83\u4e4b\u524d\u4e24\u4e2a\u6570\u76f8\u52a0\u7684\u548c\u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u53ea\u5305\u542b\u6570\u5b57 '0'-'9' \u7684\u5b57\u7b26\u4e32\uff0c\u7f16\u5199\u4e00\u4e2a\u7b97\u6cd5\u6765\u5224\u65ad\u7ed9\u5b9a\u8f93\u5165\u662f\u5426\u662f\u7d2f\u52a0\u6570\u3002

    \n\n

    \u8bf4\u660e: \u7d2f\u52a0\u5e8f\u5217\u91cc\u7684\u6570\u4e0d\u4f1a\u4ee5 0 \u5f00\u5934\uff0c\u6240\u4ee5\u4e0d\u4f1a\u51fa\u73b0 1, 2, 03 \u6216\u8005 1, 02, 3 \u7684\u60c5\u51b5\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: "112358"\n\u8f93\u51fa: true \n\u89e3\u91ca: \u7d2f\u52a0\u5e8f\u5217\u4e3a: 1, 1, 2, 3, 5, 8 \u30021 + 1 = 2, 1 + 2 = 3, 2 + 3 = 5, 3 + 5 = 8\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: "199100199"\n\u8f93\u51fa: true \n\u89e3\u91ca: \u7d2f\u52a0\u5e8f\u5217\u4e3a: 1, 99, 100, 199\u30021 + 99 = 100, 99 + 100 = 199
    \n\n

    \u8fdb\u9636:
    \n\u4f60\u5982\u4f55\u5904\u7406\u4e00\u4e2a\u6ea2\u51fa\u7684\u8fc7\u5927\u7684\u6574\u6570\u8f93\u5165?

    \n", "tags_en": ["Backtracking"], "tags_cn": ["\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isAdditiveNumber(string num) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isAdditiveNumber(String num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isAdditiveNumber(self, num):\n \"\"\"\n :type num: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isAdditiveNumber(self, num: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isAdditiveNumber(char * num){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsAdditiveNumber(string num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} num\n * @return {boolean}\n */\nvar isAdditiveNumber = function(num) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} num\n# @return {Boolean}\ndef is_additive_number(num)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isAdditiveNumber(_ num: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isAdditiveNumber(num string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isAdditiveNumber(num: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isAdditiveNumber(num: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_additive_number(num: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $num\n * @return Boolean\n */\n function isAdditiveNumber($num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isAdditiveNumber(num: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-additive-number num)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0306](https://leetcode-cn.com/problems/additive-number)", "[\u7d2f\u52a0\u6570](/solution/0300-0399/0306.Additive%20Number/README.md)", "`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0306](https://leetcode.com/problems/additive-number)", "[Additive Number](/solution/0300-0399/0306.Additive%20Number/README_EN.md)", "`Backtracking`", "Medium", ""]}, {"question_id": "0305", "frontend_question_id": "0305", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/number-of-islands-ii", "url_en": "https://leetcode.com/problems/number-of-islands-ii", "relative_path_cn": "/solution/0300-0399/0305.Number%20of%20Islands%20II/README.md", "relative_path_en": "/solution/0300-0399/0305.Number%20of%20Islands%20II/README_EN.md", "title_cn": "\u5c9b\u5c7f\u6570\u91cf II", "title_en": "Number of Islands II", "question_title_slug": "number-of-islands-ii", "content_en": "

    You are given an empty 2D binary grid grid of size m x n. The grid represents a map where 0's represent water and 1's represent land. Initially, all the cells of grid are water cells (i.e., all the cells are 0's).

    \n\n

    We may perform an add land operation which turns the water at position into a land. You are given an array positions where positions[i] = [ri, ci] is the position (ri, ci) at which we should operate the ith operation.

    \n\n

    Return an array of integers answer where answer[i] is the number of islands after turning the cell (ri, ci) into a land.

    \n\n

    An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surrounded by water.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: m = 3, n = 3, positions = [[0,0],[0,1],[1,2],[2,1]]\nOutput: [1,1,2,3]\nExplanation:\nInitially, the 2d grid is filled with water.\n- Operation #1: addLand(0, 0) turns the water at grid[0][0] into a land. We have 1 island.\n- Operation #2: addLand(0, 1) turns the water at grid[0][1] into a land. We still have 1 island.\n- Operation #3: addLand(1, 2) turns the water at grid[1][2] into a land. We have 2 islands.\n- Operation #4: addLand(2, 1) turns the water at grid[2][1] into a land. We have 3 islands.\n
    \n\n

    Example 2:

    \n\n
    \nInput: m = 1, n = 1, positions = [[0,0]]\nOutput: [1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= m, n, positions.length <= 104
    • \n\t
    • 1 <= m * n <= 104
    • \n\t
    • positions[i].length == 2
    • \n\t
    • 0 <= ri < m
    • \n\t
    • 0 <= ci < n
    • \n
    \n\n

     

    \n

    Follow up: Could you solve it in time complexity O(k log(mn)), where k == positions.length?

    \n", "content_cn": "

    \u5047\u8bbe\u4f60\u8bbe\u8ba1\u4e00\u4e2a\u6e38\u620f\uff0c\u7528\u4e00\u4e2a m \u884c n \u5217\u7684 2D \u7f51\u683c\u6765\u5b58\u50a8\u4f60\u7684\u6e38\u620f\u5730\u56fe\u3002

    \n\n

    \u8d77\u59cb\u7684\u65f6\u5019\uff0c\u6bcf\u4e2a\u683c\u5b50\u7684\u5730\u5f62\u90fd\u88ab\u9ed8\u8ba4\u6807\u8bb0\u4e3a\u300c\u6c34\u300d\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528 addLand \u8fdb\u884c\u64cd\u4f5c\uff0c\u5c06\u4f4d\u7f6e (row, col) \u7684\u300c\u6c34\u300d\u53d8\u6210\u300c\u9646\u5730\u300d\u3002

    \n\n

    \u4f60\u5c06\u4f1a\u88ab\u7ed9\u5b9a\u4e00\u4e2a\u5217\u8868\uff0c\u6765\u8bb0\u5f55\u6240\u6709\u9700\u8981\u88ab\u64cd\u4f5c\u7684\u4f4d\u7f6e\uff0c\u7136\u540e\u4f60\u9700\u8981\u8fd4\u56de\u8ba1\u7b97\u51fa\u6765 \u6bcf\u6b21 addLand \u64cd\u4f5c\u540e\u5c9b\u5c7f\u7684\u6570\u91cf\u3002

    \n\n

    \u6ce8\u610f\uff1a\u4e00\u4e2a\u5c9b\u7684\u5b9a\u4e49\u662f\u88ab\u300c\u6c34\u300d\u5305\u56f4\u7684\u300c\u9646\u5730\u300d\uff0c\u901a\u8fc7\u6c34\u5e73\u65b9\u5411\u6216\u8005\u5782\u76f4\u65b9\u5411\u4e0a\u76f8\u90bb\u7684\u9646\u5730\u8fde\u63a5\u800c\u6210\u3002\u4f60\u53ef\u4ee5\u5047\u8bbe\u5730\u56fe\u7f51\u683c\u7684\u56db\u8fb9\u5747\u88ab\u65e0\u8fb9\u65e0\u9645\u7684\u300c\u6c34\u300d\u6240\u5305\u56f4\u3002

    \n\n

    \u8bf7\u4ed4\u7ec6\u9605\u8bfb\u4e0b\u65b9\u793a\u4f8b\u4e0e\u89e3\u6790\uff0c\u66f4\u52a0\u6df1\u5165\u4e86\u89e3\u5c9b\u5c7f\u7684\u5224\u5b9a\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: m = 3, n = 3, positions = [[0,0], [0,1], [1,2], [2,1]]\n\u8f93\u51fa: [1,1,2,3]\n
    \n\n

    \u89e3\u6790:

    \n\n

    \u8d77\u521d\uff0c\u4e8c\u7ef4\u7f51\u683c grid \u88ab\u5168\u90e8\u6ce8\u5165\u300c\u6c34\u300d\u3002\uff080 \u4ee3\u8868\u300c\u6c34\u300d\uff0c1 \u4ee3\u8868\u300c\u9646\u5730\u300d\uff09

    \n\n
    0 0 0\n0 0 0\n0 0 0\n
    \n\n

    \u64cd\u4f5c #1\uff1aaddLand(0, 0) \u5c06 grid[0][0] \u7684\u6c34\u53d8\u4e3a\u9646\u5730\u3002

    \n\n
    1 0 0\n0 0 0   Number of islands = 1\n0 0 0\n
    \n\n

    \u64cd\u4f5c #2\uff1aaddLand(0, 1) \u5c06 grid[0][1] \u7684\u6c34\u53d8\u4e3a\u9646\u5730\u3002

    \n\n
    1 1 0\n0 0 0   \u5c9b\u5c7f\u7684\u6570\u91cf\u4e3a 1\n0 0 0\n
    \n\n

    \u64cd\u4f5c #3\uff1aaddLand(1, 2) \u5c06 grid[1][2] \u7684\u6c34\u53d8\u4e3a\u9646\u5730\u3002

    \n\n
    1 1 0\n0 0 1   \u5c9b\u5c7f\u7684\u6570\u91cf\u4e3a 2\n0 0 0\n
    \n\n

    \u64cd\u4f5c #4\uff1aaddLand(2, 1) \u5c06 grid[2][1] \u7684\u6c34\u53d8\u4e3a\u9646\u5730\u3002

    \n\n
    1 1 0\n0 0 1   \u5c9b\u5c7f\u7684\u6570\u91cf\u4e3a 3\n0 1 0\n
    \n\n

    \u62d3\u5c55\uff1a

    \n\n

    \u4f60\u662f\u5426\u80fd\u5728 O(k log mn) \u7684\u65f6\u95f4\u590d\u6742\u5ea6\u7a0b\u5ea6\u5185\u5b8c\u6210\u6bcf\u6b21\u7684\u8ba1\u7b97\uff1f\uff08k \u8868\u793a positions \u7684\u957f\u5ea6\uff09

    \n", "tags_en": ["Union Find"], "tags_cn": ["\u5e76\u67e5\u96c6"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector numIslands2(int m, int n, vector>& positions) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List numIslands2(int m, int n, int[][] positions) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numIslands2(self, m, n, positions):\n \"\"\"\n :type m: int\n :type n: int\n :type positions: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numIslands2(self, m: int, n: int, positions: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* numIslands2(int m, int n, int** positions, int positionsSize, int* positionsColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList NumIslands2(int m, int n, int[][] positions) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} m\n * @param {number} n\n * @param {number[][]} positions\n * @return {number[]}\n */\nvar numIslands2 = function(m, n, positions) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} m\n# @param {Integer} n\n# @param {Integer[][]} positions\n# @return {Integer[]}\ndef num_islands2(m, n, positions)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numIslands2(_ m: Int, _ n: Int, _ positions: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numIslands2(m int, n int, positions [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numIslands2(m: Int, n: Int, positions: Array[Array[Int]]): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numIslands2(m: Int, n: Int, positions: Array): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_islands2(m: i32, n: i32, positions: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $m\n * @param Integer $n\n * @param Integer[][] $positions\n * @return Integer[]\n */\n function numIslands2($m, $n, $positions) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numIslands2(m: number, n: number, positions: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-islands2 m n positions)\n (-> exact-integer? exact-integer? (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0305](https://leetcode-cn.com/problems/number-of-islands-ii)", "[\u5c9b\u5c7f\u6570\u91cf II](/solution/0300-0399/0305.Number%20of%20Islands%20II/README.md)", "`\u5e76\u67e5\u96c6`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0305](https://leetcode.com/problems/number-of-islands-ii)", "[Number of Islands II](/solution/0300-0399/0305.Number%20of%20Islands%20II/README_EN.md)", "`Union Find`", "Hard", "\ud83d\udd12"]}, {"question_id": "0304", "frontend_question_id": "0304", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/range-sum-query-2d-immutable", "url_en": "https://leetcode.com/problems/range-sum-query-2d-immutable", "relative_path_cn": "/solution/0300-0399/0304.Range%20Sum%20Query%202D%20-%20Immutable/README.md", "relative_path_en": "/solution/0300-0399/0304.Range%20Sum%20Query%202D%20-%20Immutable/README_EN.md", "title_cn": "\u4e8c\u7ef4\u533a\u57df\u548c\u68c0\u7d22 - \u77e9\u9635\u4e0d\u53ef\u53d8", "title_en": "Range Sum Query 2D - Immutable", "question_title_slug": "range-sum-query-2d-immutable", "content_en": "

    Given a 2D matrix matrix, handle multiple queries of the following type:

    \n\n
      \n\t
    1. Calculate the sum of the elements of matrix inside the rectangle defined by its upper left corner (row1, col1) and lower right corner (row2, col2).
    2. \n
    \n\n

    Implement the NumMatrix class:

    \n\n
      \n\t
    • NumMatrix(int[][] matrix) Initializes the object with the integer matrix matrix.
    • \n\t
    • int sumRegion(int row1, int col1, int row2, int col2) Returns the sum of the elements of matrix inside the rectangle defined by its upper left corner (row1, col1) and lower right corner (row2, col2).
    • \n
    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput\n["NumMatrix", "sumRegion", "sumRegion", "sumRegion"]\n[[[[3, 0, 1, 4, 2], [5, 6, 3, 2, 1], [1, 2, 0, 1, 5], [4, 1, 0, 1, 7], [1, 0, 3, 0, 5]]], [2, 1, 4, 3], [1, 1, 2, 2], [1, 2, 2, 4]]\nOutput\n[null, 8, 11, 12]\n\nExplanation\nNumMatrix numMatrix = new NumMatrix([[3, 0, 1, 4, 2], [5, 6, 3, 2, 1], [1, 2, 0, 1, 5], [4, 1, 0, 1, 7], [1, 0, 3, 0, 5]]);\nnumMatrix.sumRegion(2, 1, 4, 3); // return 8 (i.e sum of the red rectangle)\nnumMatrix.sumRegion(1, 1, 2, 2); // return 11 (i.e sum of the green rectangle)\nnumMatrix.sumRegion(1, 2, 2, 4); // return 12 (i.e sum of the blue rectangle)\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == matrix.length
    • \n\t
    • n == matrix[i].length
    • \n\t
    • 1 <= m, n <= 200
    • \n\t
    • -105 <= matrix[i][j] <= 105
    • \n\t
    • 0 <= row1 <= row2 < m
    • \n\t
    • 0 <= col1 <= col2 < n
    • \n\t
    • At most 104 calls will be made to sumRegion.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u7ef4\u77e9\u9635\uff0c\u8ba1\u7b97\u5176\u5b50\u77e9\u5f62\u8303\u56f4\u5185\u5143\u7d20\u7684\u603b\u548c\uff0c\u8be5\u5b50\u77e9\u9635\u7684\u5de6\u4e0a\u89d2\u4e3a (row1,\u00a0col1) \uff0c\u53f3\u4e0b\u89d2\u4e3a (row2,\u00a0col2) \u3002

    \n\n

    \"Range
    \n\u4e0a\u56fe\u5b50\u77e9\u9635\u5de6\u4e0a\u89d2\u00a0(row1, col1) = (2, 1)\u00a0\uff0c\u53f3\u4e0b\u89d2(row2, col2) = (4, 3)\uff0c\u8be5\u5b50\u77e9\u5f62\u5185\u5143\u7d20\u7684\u603b\u548c\u4e3a 8\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u7ed9\u5b9a matrix = [\n  [3, 0, 1, 4, 2],\n  [5, 6, 3, 2, 1],\n  [1, 2, 0, 1, 5],\n  [4, 1, 0, 1, 7],\n  [1, 0, 3, 0, 5]\n]\n\nsumRegion(2, 1, 4, 3) -> 8\nsumRegion(1, 1, 2, 2) -> 11\nsumRegion(1, 2, 2, 4) -> 12\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u4f60\u53ef\u4ee5\u5047\u8bbe\u77e9\u9635\u4e0d\u53ef\u53d8\u3002
    • \n\t
    • \u4f1a\u591a\u6b21\u8c03\u7528\u00a0sumRegion\u00a0\u65b9\u6cd5\u3002
    • \n\t
    • \u4f60\u53ef\u4ee5\u5047\u8bbe\u00a0row1 \u2264 row2 \u4e14\u00a0col1 \u2264 col2 \u3002
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class NumMatrix {\npublic:\n NumMatrix(vector>& matrix) {\n\n }\n \n int sumRegion(int row1, int col1, int row2, int col2) {\n\n }\n};\n\n/**\n * Your NumMatrix object will be instantiated and called as such:\n * NumMatrix* obj = new NumMatrix(matrix);\n * int param_1 = obj->sumRegion(row1,col1,row2,col2);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class NumMatrix {\n\n public NumMatrix(int[][] matrix) {\n\n }\n \n public int sumRegion(int row1, int col1, int row2, int col2) {\n\n }\n}\n\n/**\n * Your NumMatrix object will be instantiated and called as such:\n * NumMatrix obj = new NumMatrix(matrix);\n * int param_1 = obj.sumRegion(row1,col1,row2,col2);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class NumMatrix(object):\n\n def __init__(self, matrix):\n \"\"\"\n :type matrix: List[List[int]]\n \"\"\"\n\n\n def sumRegion(self, row1, col1, row2, col2):\n \"\"\"\n :type row1: int\n :type col1: int\n :type row2: int\n :type col2: int\n :rtype: int\n \"\"\"\n\n\n\n# Your NumMatrix object will be instantiated and called as such:\n# obj = NumMatrix(matrix)\n# param_1 = obj.sumRegion(row1,col1,row2,col2)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class NumMatrix:\n\n def __init__(self, matrix: List[List[int]]):\n\n\n def sumRegion(self, row1: int, col1: int, row2: int, col2: int) -> int:\n\n\n\n# Your NumMatrix object will be instantiated and called as such:\n# obj = NumMatrix(matrix)\n# param_1 = obj.sumRegion(row1,col1,row2,col2)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} NumMatrix;\n\n\nNumMatrix* numMatrixCreate(int** matrix, int matrixSize, int* matrixColSize) {\n\n}\n\nint numMatrixSumRegion(NumMatrix* obj, int row1, int col1, int row2, int col2) {\n\n}\n\nvoid numMatrixFree(NumMatrix* obj) {\n\n}\n\n/**\n * Your NumMatrix struct will be instantiated and called as such:\n * NumMatrix* obj = numMatrixCreate(matrix, matrixSize, matrixColSize);\n * int param_1 = numMatrixSumRegion(obj, row1, col1, row2, col2);\n \n * numMatrixFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class NumMatrix {\n\n public NumMatrix(int[][] matrix) {\n\n }\n \n public int SumRegion(int row1, int col1, int row2, int col2) {\n\n }\n}\n\n/**\n * Your NumMatrix object will be instantiated and called as such:\n * NumMatrix obj = new NumMatrix(matrix);\n * int param_1 = obj.SumRegion(row1,col1,row2,col2);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} matrix\n */\nvar NumMatrix = function(matrix) {\n\n};\n\n/** \n * @param {number} row1 \n * @param {number} col1 \n * @param {number} row2 \n * @param {number} col2\n * @return {number}\n */\nNumMatrix.prototype.sumRegion = function(row1, col1, row2, col2) {\n\n};\n\n/**\n * Your NumMatrix object will be instantiated and called as such:\n * var obj = new NumMatrix(matrix)\n * var param_1 = obj.sumRegion(row1,col1,row2,col2)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class NumMatrix\n\n=begin\n :type matrix: Integer[][]\n=end\n def initialize(matrix)\n\n end\n\n\n=begin\n :type row1: Integer\n :type col1: Integer\n :type row2: Integer\n :type col2: Integer\n :rtype: Integer\n=end\n def sum_region(row1, col1, row2, col2)\n\n end\n\n\nend\n\n# Your NumMatrix object will be instantiated and called as such:\n# obj = NumMatrix.new(matrix)\n# param_1 = obj.sum_region(row1, col1, row2, col2)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass NumMatrix {\n\n init(_ matrix: [[Int]]) {\n\n }\n \n func sumRegion(_ row1: Int, _ col1: Int, _ row2: Int, _ col2: Int) -> Int {\n\n }\n}\n\n/**\n * Your NumMatrix object will be instantiated and called as such:\n * let obj = NumMatrix(matrix)\n * let ret_1: Int = obj.sumRegion(row1, col1, row2, col2)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type NumMatrix struct {\n\n}\n\n\nfunc Constructor(matrix [][]int) NumMatrix {\n\n}\n\n\nfunc (this *NumMatrix) SumRegion(row1 int, col1 int, row2 int, col2 int) int {\n\n}\n\n\n/**\n * Your NumMatrix object will be instantiated and called as such:\n * obj := Constructor(matrix);\n * param_1 := obj.SumRegion(row1,col1,row2,col2);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class NumMatrix(_matrix: Array[Array[Int]]) {\n\n def sumRegion(row1: Int, col1: Int, row2: Int, col2: Int): Int = {\n\n }\n\n}\n\n/**\n * Your NumMatrix object will be instantiated and called as such:\n * var obj = new NumMatrix(matrix)\n * var param_1 = obj.sumRegion(row1,col1,row2,col2)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class NumMatrix(matrix: Array) {\n\n fun sumRegion(row1: Int, col1: Int, row2: Int, col2: Int): Int {\n\n }\n\n}\n\n/**\n * Your NumMatrix object will be instantiated and called as such:\n * var obj = NumMatrix(matrix)\n * var param_1 = obj.sumRegion(row1,col1,row2,col2)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct NumMatrix {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl NumMatrix {\n\n fn new(matrix: Vec>) -> Self {\n\n }\n \n fn sum_region(&self, row1: i32, col1: i32, row2: i32, col2: i32) -> i32 {\n\n }\n}\n\n/**\n * Your NumMatrix object will be instantiated and called as such:\n * let obj = NumMatrix::new(matrix);\n * let ret_1: i32 = obj.sum_region(row1, col1, row2, col2);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class NumMatrix {\n /**\n * @param Integer[][] $matrix\n */\n function __construct($matrix) {\n\n }\n\n /**\n * @param Integer $row1\n * @param Integer $col1\n * @param Integer $row2\n * @param Integer $col2\n * @return Integer\n */\n function sumRegion($row1, $col1, $row2, $col2) {\n\n }\n}\n\n/**\n * Your NumMatrix object will be instantiated and called as such:\n * $obj = NumMatrix($matrix);\n * $ret_1 = $obj->sumRegion($row1, $col1, $row2, $col2);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class NumMatrix {\n constructor(matrix: number[][]) {\n\n }\n\n sumRegion(row1: number, col1: number, row2: number, col2: number): number {\n\n }\n}\n\n/**\n * Your NumMatrix object will be instantiated and called as such:\n * var obj = new NumMatrix(matrix)\n * var param_1 = obj.sumRegion(row1,col1,row2,col2)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define num-matrix%\n (class object%\n (super-new)\n\n ; matrix : (listof (listof exact-integer?))\n (init-field\n matrix)\n \n ; sum-region : exact-integer? exact-integer? exact-integer? exact-integer? -> exact-integer?\n (define/public (sum-region row1 col1 row2 col2)\n\n )))\n\n;; Your num-matrix% object will be instantiated and called as such:\n;; (define obj (new num-matrix% [matrix matrix]))\n;; (define param_1 (send obj sum-region row1 col1 row2 col2))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0304](https://leetcode-cn.com/problems/range-sum-query-2d-immutable)", "[\u4e8c\u7ef4\u533a\u57df\u548c\u68c0\u7d22 - \u77e9\u9635\u4e0d\u53ef\u53d8](/solution/0300-0399/0304.Range%20Sum%20Query%202D%20-%20Immutable/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0304](https://leetcode.com/problems/range-sum-query-2d-immutable)", "[Range Sum Query 2D - Immutable](/solution/0300-0399/0304.Range%20Sum%20Query%202D%20-%20Immutable/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0303", "frontend_question_id": "0303", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/range-sum-query-immutable", "url_en": "https://leetcode.com/problems/range-sum-query-immutable", "relative_path_cn": "/solution/0300-0399/0303.Range%20Sum%20Query%20-%20Immutable/README.md", "relative_path_en": "/solution/0300-0399/0303.Range%20Sum%20Query%20-%20Immutable/README_EN.md", "title_cn": "\u533a\u57df\u548c\u68c0\u7d22 - \u6570\u7ec4\u4e0d\u53ef\u53d8", "title_en": "Range Sum Query - Immutable", "question_title_slug": "range-sum-query-immutable", "content_en": "

    Given an integer array nums, handle multiple queries of the following type:

    \n\n
      \n\t
    1. Calculate the sum of the elements of nums between indices left and right inclusive where left <= right.
    2. \n
    \n\n

    Implement the NumArray class:

    \n\n
      \n\t
    • NumArray(int[] nums) Initializes the object with the integer array nums.
    • \n\t
    • int sumRange(int left, int right) Returns the sum of the elements of nums between indices left and right inclusive (i.e. nums[left] + nums[left + 1] + ... + nums[right]).
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["NumArray", "sumRange", "sumRange", "sumRange"]\n[[[-2, 0, 3, -5, 2, -1]], [0, 2], [2, 5], [0, 5]]\nOutput\n[null, 1, -1, -3]\n\nExplanation\nNumArray numArray = new NumArray([-2, 0, 3, -5, 2, -1]);\nnumArray.sumRange(0, 2); // return (-2) + 0 + 3 = 1\nnumArray.sumRange(2, 5); // return 3 + (-5) + 2 + (-1) = -1\nnumArray.sumRange(0, 5); // return (-2) + 0 + 3 + (-5) + 2 + (-1) = -3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 104
    • \n\t
    • -105 <= nums[i] <= 105
    • \n\t
    • 0 <= left <= right < nums.length
    • \n\t
    • At most 104 calls will be made to sumRange.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 \u00a0nums\uff0c\u6c42\u51fa\u6570\u7ec4\u4ece\u7d22\u5f15\u00a0i\u00a0\u5230\u00a0j\uff08i\u00a0\u2264\u00a0j\uff09\u8303\u56f4\u5185\u5143\u7d20\u7684\u603b\u548c\uff0c\u5305\u542b\u00a0i\u3001j\u00a0\u4e24\u70b9\u3002

    \n\n
    \n
    \n

    \u5b9e\u73b0 NumArray \u7c7b\uff1a

    \n\n
      \n\t
    • NumArray(int[] nums) \u4f7f\u7528\u6570\u7ec4 nums \u521d\u59cb\u5316\u5bf9\u8c61
    • \n\t
    • int sumRange(int i, int j) \u8fd4\u56de\u6570\u7ec4 nums \u4ece\u7d22\u5f15\u00a0i\u00a0\u5230\u00a0j\uff08i\u00a0\u2264\u00a0j\uff09\u8303\u56f4\u5185\u5143\u7d20\u7684\u603b\u548c\uff0c\u5305\u542b\u00a0i\u3001j\u00a0\u4e24\u70b9\uff08\u4e5f\u5c31\u662f sum(nums[i], nums[i + 1], ... , nums[j])\uff09
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\n[\"NumArray\", \"sumRange\", \"sumRange\", \"sumRange\"]\n[[[-2, 0, 3, -5, 2, -1]], [0, 2], [2, 5], [0, 5]]\n\u8f93\u51fa\uff1a\n[null, 1, -1, -3]\n\n\u89e3\u91ca\uff1a\nNumArray numArray = new NumArray([-2, 0, 3, -5, 2, -1]);\nnumArray.sumRange(0, 2); // return 1 ((-2) + 0 + 3)\nnumArray.sumRange(2, 5); // return -1 (3 + (-5) + 2 + (-1)) \nnumArray.sumRange(0, 5); // return -3 ((-2) + 0 + 3 + (-5) + 2 + (-1))\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= nums.length <= 104
    • \n\t
    • -105\u00a0<= nums[i] <=\u00a0105
    • \n\t
    • 0 <= i <= j < nums.length
    • \n\t
    • \u6700\u591a\u8c03\u7528 104 \u6b21 sumRange \u65b9\u6cd5
    • \n
    \n
    \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class NumArray {\npublic:\n NumArray(vector& nums) {\n\n }\n \n int sumRange(int left, int right) {\n\n }\n};\n\n/**\n * Your NumArray object will be instantiated and called as such:\n * NumArray* obj = new NumArray(nums);\n * int param_1 = obj->sumRange(left,right);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class NumArray {\n\n public NumArray(int[] nums) {\n\n }\n \n public int sumRange(int left, int right) {\n\n }\n}\n\n/**\n * Your NumArray object will be instantiated and called as such:\n * NumArray obj = new NumArray(nums);\n * int param_1 = obj.sumRange(left,right);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class NumArray(object):\n\n def __init__(self, nums):\n \"\"\"\n :type nums: List[int]\n \"\"\"\n\n\n def sumRange(self, left, right):\n \"\"\"\n :type left: int\n :type right: int\n :rtype: int\n \"\"\"\n\n\n\n# Your NumArray object will be instantiated and called as such:\n# obj = NumArray(nums)\n# param_1 = obj.sumRange(left,right)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class NumArray:\n\n def __init__(self, nums: List[int]):\n\n\n def sumRange(self, left: int, right: int) -> int:\n\n\n\n# Your NumArray object will be instantiated and called as such:\n# obj = NumArray(nums)\n# param_1 = obj.sumRange(left,right)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} NumArray;\n\n\nNumArray* numArrayCreate(int* nums, int numsSize) {\n\n}\n\nint numArraySumRange(NumArray* obj, int left, int right) {\n\n}\n\nvoid numArrayFree(NumArray* obj) {\n\n}\n\n/**\n * Your NumArray struct will be instantiated and called as such:\n * NumArray* obj = numArrayCreate(nums, numsSize);\n * int param_1 = numArraySumRange(obj, left, right);\n \n * numArrayFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class NumArray {\n\n public NumArray(int[] nums) {\n\n }\n \n public int SumRange(int left, int right) {\n\n }\n}\n\n/**\n * Your NumArray object will be instantiated and called as such:\n * NumArray obj = new NumArray(nums);\n * int param_1 = obj.SumRange(left,right);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n */\nvar NumArray = function(nums) {\n\n};\n\n/** \n * @param {number} left \n * @param {number} right\n * @return {number}\n */\nNumArray.prototype.sumRange = function(left, right) {\n\n};\n\n/**\n * Your NumArray object will be instantiated and called as such:\n * var obj = new NumArray(nums)\n * var param_1 = obj.sumRange(left,right)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class NumArray\n\n=begin\n :type nums: Integer[]\n=end\n def initialize(nums)\n\n end\n\n\n=begin\n :type left: Integer\n :type right: Integer\n :rtype: Integer\n=end\n def sum_range(left, right)\n\n end\n\n\nend\n\n# Your NumArray object will be instantiated and called as such:\n# obj = NumArray.new(nums)\n# param_1 = obj.sum_range(left, right)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass NumArray {\n\n init(_ nums: [Int]) {\n\n }\n \n func sumRange(_ left: Int, _ right: Int) -> Int {\n\n }\n}\n\n/**\n * Your NumArray object will be instantiated and called as such:\n * let obj = NumArray(nums)\n * let ret_1: Int = obj.sumRange(left, right)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type NumArray struct {\n\n}\n\n\nfunc Constructor(nums []int) NumArray {\n\n}\n\n\nfunc (this *NumArray) SumRange(left int, right int) int {\n\n}\n\n\n/**\n * Your NumArray object will be instantiated and called as such:\n * obj := Constructor(nums);\n * param_1 := obj.SumRange(left,right);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class NumArray(_nums: Array[Int]) {\n\n def sumRange(left: Int, right: Int): Int = {\n\n }\n\n}\n\n/**\n * Your NumArray object will be instantiated and called as such:\n * var obj = new NumArray(nums)\n * var param_1 = obj.sumRange(left,right)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class NumArray(nums: IntArray) {\n\n fun sumRange(left: Int, right: Int): Int {\n\n }\n\n}\n\n/**\n * Your NumArray object will be instantiated and called as such:\n * var obj = NumArray(nums)\n * var param_1 = obj.sumRange(left,right)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct NumArray {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl NumArray {\n\n fn new(nums: Vec) -> Self {\n\n }\n \n fn sum_range(&self, left: i32, right: i32) -> i32 {\n\n }\n}\n\n/**\n * Your NumArray object will be instantiated and called as such:\n * let obj = NumArray::new(nums);\n * let ret_1: i32 = obj.sum_range(left, right);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class NumArray {\n /**\n * @param Integer[] $nums\n */\n function __construct($nums) {\n\n }\n\n /**\n * @param Integer $left\n * @param Integer $right\n * @return Integer\n */\n function sumRange($left, $right) {\n\n }\n}\n\n/**\n * Your NumArray object will be instantiated and called as such:\n * $obj = NumArray($nums);\n * $ret_1 = $obj->sumRange($left, $right);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class NumArray {\n constructor(nums: number[]) {\n\n }\n\n sumRange(left: number, right: number): number {\n\n }\n}\n\n/**\n * Your NumArray object will be instantiated and called as such:\n * var obj = new NumArray(nums)\n * var param_1 = obj.sumRange(left,right)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define num-array%\n (class object%\n (super-new)\n\n ; nums : (listof exact-integer?)\n (init-field\n nums)\n \n ; sum-range : exact-integer? exact-integer? -> exact-integer?\n (define/public (sum-range left right)\n\n )))\n\n;; Your num-array% object will be instantiated and called as such:\n;; (define obj (new num-array% [nums nums]))\n;; (define param_1 (send obj sum-range left right))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0303](https://leetcode-cn.com/problems/range-sum-query-immutable)", "[\u533a\u57df\u548c\u68c0\u7d22 - \u6570\u7ec4\u4e0d\u53ef\u53d8](/solution/0300-0399/0303.Range%20Sum%20Query%20-%20Immutable/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u7b80\u5355", ""], "md_table_row_en": ["[0303](https://leetcode.com/problems/range-sum-query-immutable)", "[Range Sum Query - Immutable](/solution/0300-0399/0303.Range%20Sum%20Query%20-%20Immutable/README_EN.md)", "`Dynamic Programming`", "Easy", ""]}, {"question_id": "0302", "frontend_question_id": "0302", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/smallest-rectangle-enclosing-black-pixels", "url_en": "https://leetcode.com/problems/smallest-rectangle-enclosing-black-pixels", "relative_path_cn": "/solution/0300-0399/0302.Smallest%20Rectangle%20Enclosing%20Black%20Pixels/README.md", "relative_path_en": "/solution/0300-0399/0302.Smallest%20Rectangle%20Enclosing%20Black%20Pixels/README_EN.md", "title_cn": "\u5305\u542b\u5168\u90e8\u9ed1\u8272\u50cf\u7d20\u7684\u6700\u5c0f\u77e9\u5f62", "title_en": "Smallest Rectangle Enclosing Black Pixels", "question_title_slug": "smallest-rectangle-enclosing-black-pixels", "content_en": "

    You are given an image that is represented by a binary matrix with 0 as a white pixel and 1 as a black pixel.

    \n\n

    The black pixels are connected (i.e., there is only one black region). Pixels are connected horizontally and vertically.

    \n\n

    Given two integers x and y that represent the location of one of the black pixels, return the area of the smallest (axis-aligned) rectangle that encloses all black pixels.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: image = [["0","0","1","0"],["0","1","1","0"],["0","1","0","0"]], x = 0, y = 2\nOutput: 6\n
    \n\n

    Example 2:

    \n\n
    \nInput: image = [["1"]], x = 0, y = 0\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == image.length
    • \n\t
    • n == image[i].length
    • \n\t
    • 1 <= m, n <= 100
    • \n\t
    • image[i][j] is either '0' or '1'.
    • \n\t
    • 1 <= x < m
    • \n\t
    • 1 <= y < n
    • \n\t
    • image[x][y] == '1'.
    • \n\t
    • The black pixels in the image only form one component.
    • \n
    \n", "content_cn": "

    \u56fe\u7247\u5728\u8ba1\u7b97\u673a\u5904\u7406\u4e2d\u5f80\u5f80\u662f\u4f7f\u7528\u4e8c\u7ef4\u77e9\u9635\u6765\u8868\u793a\u7684\u3002

    \n\n

    \u5047\u8bbe\uff0c\u8fd9\u91cc\u6211\u4eec\u7528\u7684\u662f\u4e00\u5f20\u9ed1\u767d\u7684\u56fe\u7247\uff0c\u90a3\u4e48 0 \u4ee3\u8868\u767d\u8272\u50cf\u7d20\uff0c1 \u4ee3\u8868\u9ed1\u8272\u50cf\u7d20\u3002

    \n\n

    \u5176\u4e2d\u9ed1\u8272\u7684\u50cf\u7d20\u4ed6\u4eec\u76f8\u4e92\u8fde\u63a5\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u56fe\u7247\u4e2d\u53ea\u4f1a\u6709\u4e00\u7247\u8fde\u5728\u4e00\u5757\u513f\u7684\u9ed1\u8272\u50cf\u7d20\uff08\u50cf\u7d20\u70b9\u662f\u6c34\u5e73\u6216\u7ad6\u76f4\u65b9\u5411\u8fde\u63a5\u7684\uff09\u3002

    \n\n

    \u90a3\u4e48\uff0c\u7ed9\u51fa\u67d0\u4e00\u4e2a\u9ed1\u8272\u50cf\u7d20\u70b9 (x, y) \u7684\u4f4d\u7f6e\uff0c\u4f60\u662f\u5426\u53ef\u4ee5\u627e\u51fa\u5305\u542b\u5168\u90e8\u9ed1\u8272\u50cf\u7d20\u7684\u6700\u5c0f\u77e9\u5f62\uff08\u4e0e\u5750\u6807\u8f74\u5bf9\u9f50\uff09\u7684\u9762\u79ef\u5462\uff1f

    \n\n

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165:\n[\n  "0010",\n  "0110",\n  "0100"\n]\n\u548c x = 0, y = 2\n\n\u8f93\u51fa: 6\n
    \n\n

     

    \n", "tags_en": ["Binary Search"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minArea(vector>& image, int x, int y) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minArea(char[][] image, int x, int y) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minArea(self, image, x, y):\n \"\"\"\n :type image: List[List[str]]\n :type x: int\n :type y: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minArea(self, image: List[List[str]], x: int, y: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minArea(char** image, int imageSize, int* imageColSize, int x, int y){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinArea(char[][] image, int x, int y) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {character[][]} image\n * @param {number} x\n * @param {number} y\n * @return {number}\n */\nvar minArea = function(image, x, y) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Character[][]} image\n# @param {Integer} x\n# @param {Integer} y\n# @return {Integer}\ndef min_area(image, x, y)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minArea(_ image: [[Character]], _ x: Int, _ y: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minArea(image [][]byte, x int, y int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minArea(image: Array[Array[Char]], x: Int, y: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minArea(image: Array, x: Int, y: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_area(image: Vec>, x: i32, y: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $image\n * @param Integer $x\n * @param Integer $y\n * @return Integer\n */\n function minArea($image, $x, $y) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minArea(image: string[][], x: number, y: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-area image x y)\n (-> (listof (listof char?)) exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0302](https://leetcode-cn.com/problems/smallest-rectangle-enclosing-black-pixels)", "[\u5305\u542b\u5168\u90e8\u9ed1\u8272\u50cf\u7d20\u7684\u6700\u5c0f\u77e9\u5f62](/solution/0300-0399/0302.Smallest%20Rectangle%20Enclosing%20Black%20Pixels/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0302](https://leetcode.com/problems/smallest-rectangle-enclosing-black-pixels)", "[Smallest Rectangle Enclosing Black Pixels](/solution/0300-0399/0302.Smallest%20Rectangle%20Enclosing%20Black%20Pixels/README_EN.md)", "`Binary Search`", "Hard", "\ud83d\udd12"]}, {"question_id": "0301", "frontend_question_id": "0301", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/remove-invalid-parentheses", "url_en": "https://leetcode.com/problems/remove-invalid-parentheses", "relative_path_cn": "/solution/0300-0399/0301.Remove%20Invalid%20Parentheses/README.md", "relative_path_en": "/solution/0300-0399/0301.Remove%20Invalid%20Parentheses/README_EN.md", "title_cn": "\u5220\u9664\u65e0\u6548\u7684\u62ec\u53f7", "title_en": "Remove Invalid Parentheses", "question_title_slug": "remove-invalid-parentheses", "content_en": "

    Given a string s that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.

    \n\n

    Return all the possible results. You may return the answer in any order.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "()())()"\nOutput: ["(())()","()()()"]\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "(a)())()"\nOutput: ["(a())()","(a)()()"]\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = ")("\nOutput: [""]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 25
    • \n\t
    • s consists of lowercase English letters and parentheses '(' and ')'.
    • \n\t
    • There will be at most 20 parentheses in s.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u7531\u82e5\u5e72\u62ec\u53f7\u548c\u5b57\u6bcd\u7ec4\u6210\u7684\u5b57\u7b26\u4e32 s \uff0c\u5220\u9664\u6700\u5c0f\u6570\u91cf\u7684\u65e0\u6548\u62ec\u53f7\uff0c\u4f7f\u5f97\u8f93\u5165\u7684\u5b57\u7b26\u4e32\u6709\u6548\u3002

    \n\n

    \u8fd4\u56de\u6240\u6709\u53ef\u80fd\u7684\u7ed3\u679c\u3002\u7b54\u6848\u53ef\u4ee5\u6309 \u4efb\u610f\u987a\u5e8f \u8fd4\u56de\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"()())()\"\n\u8f93\u51fa\uff1a[\"(())()\",\"()()()\"]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"(a)())()\"\n\u8f93\u51fa\uff1a[\"(a())()\",\"(a)()()\"]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \")(\"\n\u8f93\u51fa\uff1a[\"\"]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 25
    • \n\t
    • s \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u4ee5\u53ca\u62ec\u53f7 '(' \u548c ')' \u7ec4\u6210
    • \n\t
    • s \u4e2d\u81f3\u591a\u542b 20 \u4e2a\u62ec\u53f7
    • \n
    \n", "tags_en": ["Depth-first Search", "Breadth-first Search"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector removeInvalidParentheses(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List removeInvalidParentheses(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def removeInvalidParentheses(self, s):\n \"\"\"\n :type s: str\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def removeInvalidParentheses(self, s: str) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** removeInvalidParentheses(char * s, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList RemoveInvalidParentheses(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string[]}\n */\nvar removeInvalidParentheses = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String[]}\ndef remove_invalid_parentheses(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func removeInvalidParentheses(_ s: String) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func removeInvalidParentheses(s string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def removeInvalidParentheses(s: String): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun removeInvalidParentheses(s: String): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn remove_invalid_parentheses(s: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String[]\n */\n function removeInvalidParentheses($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function removeInvalidParentheses(s: string): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (remove-invalid-parentheses s)\n (-> string? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0301](https://leetcode-cn.com/problems/remove-invalid-parentheses)", "[\u5220\u9664\u65e0\u6548\u7684\u62ec\u53f7](/solution/0300-0399/0301.Remove%20Invalid%20Parentheses/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[0301](https://leetcode.com/problems/remove-invalid-parentheses)", "[Remove Invalid Parentheses](/solution/0300-0399/0301.Remove%20Invalid%20Parentheses/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`", "Hard", ""]}, {"question_id": "0300", "frontend_question_id": "0300", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-increasing-subsequence", "url_en": "https://leetcode.com/problems/longest-increasing-subsequence", "relative_path_cn": "/solution/0300-0399/0300.Longest%20Increasing%20Subsequence/README.md", "relative_path_en": "/solution/0300-0399/0300.Longest%20Increasing%20Subsequence/README_EN.md", "title_cn": "\u6700\u957f\u9012\u589e\u5b50\u5e8f\u5217", "title_en": "Longest Increasing Subsequence", "question_title_slug": "longest-increasing-subsequence", "content_en": "

    Given an integer array nums, return the length of the longest strictly increasing subsequence.

    \n\n

    A subsequence is a sequence that can be derived from an array by deleting some or no elements without changing the order of the remaining elements. For example, [3,6,2,7] is a subsequence of the array [0,3,1,6,2,2,7].

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [10,9,2,5,3,7,101,18]\nOutput: 4\nExplanation: The longest increasing subsequence is [2,3,7,101], therefore the length is 4.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [0,1,0,3,2,3]\nOutput: 4\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [7,7,7,7,7,7,7]\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 2500
    • \n\t
    • -104 <= nums[i] <= 104
    • \n
    \n\n

     

    \n

    Follow up: Can you come up with an algorithm that runs in O(n log(n)) time complexity?

    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \uff0c\u627e\u5230\u5176\u4e2d\u6700\u957f\u4e25\u683c\u9012\u589e\u5b50\u5e8f\u5217\u7684\u957f\u5ea6\u3002

    \n\n

    \u5b50\u5e8f\u5217\u662f\u7531\u6570\u7ec4\u6d3e\u751f\u800c\u6765\u7684\u5e8f\u5217\uff0c\u5220\u9664\uff08\u6216\u4e0d\u5220\u9664\uff09\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u800c\u4e0d\u6539\u53d8\u5176\u4f59\u5143\u7d20\u7684\u987a\u5e8f\u3002\u4f8b\u5982\uff0c[3,6,2,7] \u662f\u6570\u7ec4 [0,3,1,6,2,2,7] \u7684\u5b50\u5e8f\u5217\u3002

    \n\u00a0\n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [10,9,2,5,3,7,101,18]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u6700\u957f\u9012\u589e\u5b50\u5e8f\u5217\u662f [2,3,7,101]\uff0c\u56e0\u6b64\u957f\u5ea6\u4e3a 4 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [0,1,0,3,2,3]\n\u8f93\u51fa\uff1a4\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [7,7,7,7,7,7,7]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 2500
    • \n\t
    • -104 <= nums[i] <= 104
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u4f60\u53ef\u4ee5\u8bbe\u8ba1\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n2) \u7684\u89e3\u51b3\u65b9\u6848\u5417\uff1f
    • \n\t
    • \u4f60\u80fd\u5c06\u7b97\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u964d\u4f4e\u5230\u00a0O(n log(n)) \u5417?
    • \n
    \n", "tags_en": ["Binary Search", "Dynamic Programming"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int lengthOfLIS(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int lengthOfLIS(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def lengthOfLIS(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def lengthOfLIS(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint lengthOfLIS(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LengthOfLIS(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar lengthOfLIS = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef length_of_lis(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func lengthOfLIS(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func lengthOfLIS(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def lengthOfLIS(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun lengthOfLIS(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn length_of_lis(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function lengthOfLIS($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function lengthOfLIS(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (length-of-lis nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0300](https://leetcode-cn.com/problems/longest-increasing-subsequence)", "[\u6700\u957f\u9012\u589e\u5b50\u5e8f\u5217](/solution/0300-0399/0300.Longest%20Increasing%20Subsequence/README.md)", "`\u4e8c\u5206\u67e5\u627e`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0300](https://leetcode.com/problems/longest-increasing-subsequence)", "[Longest Increasing Subsequence](/solution/0300-0399/0300.Longest%20Increasing%20Subsequence/README_EN.md)", "`Binary Search`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0299", "frontend_question_id": "0299", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/bulls-and-cows", "url_en": "https://leetcode.com/problems/bulls-and-cows", "relative_path_cn": "/solution/0200-0299/0299.Bulls%20and%20Cows/README.md", "relative_path_en": "/solution/0200-0299/0299.Bulls%20and%20Cows/README_EN.md", "title_cn": "\u731c\u6570\u5b57\u6e38\u620f", "title_en": "Bulls and Cows", "question_title_slug": "bulls-and-cows", "content_en": "

    You are playing the Bulls and Cows game with your friend.

    \n\n

    You write down a secret number and ask your friend to guess what the number is. When your friend makes a guess, you provide a hint with the following info:

    \n\n
      \n\t
    • The number of "bulls", which are digits in the guess that are in the correct position.
    • \n\t
    • The number of "cows", which are digits in the guess that are in your secret number but are located in the wrong position. Specifically, the non-bull digits in the guess that could be rearranged such that they become bulls.
    • \n
    \n\n

    Given the secret number secret and your friend's guess guess, return the hint for your friend's guess.

    \n\n

    The hint should be formatted as "xAyB", where x is the number of bulls and y is the number of cows. Note that both secret and guess may contain duplicate digits.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: secret = "1807", guess = "7810"\nOutput: "1A3B"\nExplanation: Bulls are connected with a '|' and cows are underlined:\n"1807"\n  |\n"7810"
    \n\n

    Example 2:

    \n\n
    \nInput: secret = "1123", guess = "0111"\nOutput: "1A1B"\nExplanation: Bulls are connected with a '|' and cows are underlined:\n"1123"        "1123"\n  |      or     |\n"0111"        "0111"\nNote that only one of the two unmatched 1s is counted as a cow since the non-bull digits can only be rearranged to allow one 1 to be a bull.\n
    \n\n

    Example 3:

    \n\n
    \nInput: secret = "1", guess = "0"\nOutput: "0A0B"\n
    \n\n

    Example 4:

    \n\n
    \nInput: secret = "1", guess = "1"\nOutput: "1A0B"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= secret.length, guess.length <= 1000
    • \n\t
    • secret.length == guess.length
    • \n\t
    • secret and guess consist of digits only.
    • \n
    \n", "content_cn": "

    \u4f60\u5728\u548c\u670b\u53cb\u4e00\u8d77\u73a9 \u731c\u6570\u5b57\uff08Bulls and Cows\uff09\u6e38\u620f\uff0c\u8be5\u6e38\u620f\u89c4\u5219\u5982\u4e0b\uff1a

    \n\n
      \n\t
    1. \u4f60\u5199\u51fa\u4e00\u4e2a\u79d8\u5bc6\u6570\u5b57\uff0c\u5e76\u8bf7\u670b\u53cb\u731c\u8fd9\u4e2a\u6570\u5b57\u662f\u591a\u5c11\u3002
    2. \n\t
    3. \u670b\u53cb\u6bcf\u731c\u6d4b\u4e00\u6b21\uff0c\u4f60\u5c31\u4f1a\u7ed9\u4ed6\u4e00\u4e2a\u63d0\u793a\uff0c\u544a\u8bc9\u4ed6\u7684\u731c\u6d4b\u6570\u5b57\u4e2d\u6709\u591a\u5c11\u4f4d\u5c5e\u4e8e\u6570\u5b57\u548c\u786e\u5207\u4f4d\u7f6e\u90fd\u731c\u5bf9\u4e86\uff08\u79f0\u4e3a“Bulls”, \u516c\u725b\uff09\uff0c\u6709\u591a\u5c11\u4f4d\u5c5e\u4e8e\u6570\u5b57\u731c\u5bf9\u4e86\u4f46\u662f\u4f4d\u7f6e\u4e0d\u5bf9\uff08\u79f0\u4e3a“Cows”, \u5976\u725b\uff09\u3002
    4. \n\t
    5. \u670b\u53cb\u6839\u636e\u63d0\u793a\u7ee7\u7eed\u731c\uff0c\u76f4\u5230\u731c\u51fa\u79d8\u5bc6\u6570\u5b57\u3002
    6. \n
    \n\n

    \u8bf7\u5199\u51fa\u4e00\u4e2a\u6839\u636e\u79d8\u5bc6\u6570\u5b57\u548c\u670b\u53cb\u7684\u731c\u6d4b\u6570\u8fd4\u56de\u63d0\u793a\u7684\u51fd\u6570\uff0c\u8fd4\u56de\u5b57\u7b26\u4e32\u7684\u683c\u5f0f\u4e3a xAyB \uff0cx \u548c y \u90fd\u662f\u6570\u5b57\uff0cA \u8868\u793a\u516c\u725b\uff0c\u7528 B \u8868\u793a\u5976\u725b\u3002

    \n\n
      \n\t
    • xA \u8868\u793a\u6709 x \u4f4d\u6570\u5b57\u51fa\u73b0\u5728\u79d8\u5bc6\u6570\u5b57\u4e2d\uff0c\u4e14\u4f4d\u7f6e\u90fd\u4e0e\u79d8\u5bc6\u6570\u5b57\u4e00\u81f4\u3002
    • \n\t
    • yB \u8868\u793a\u6709 y \u4f4d\u6570\u5b57\u51fa\u73b0\u5728\u79d8\u5bc6\u6570\u5b57\u4e2d\uff0c\u4f46\u4f4d\u7f6e\u4e0e\u79d8\u5bc6\u6570\u5b57\u4e0d\u4e00\u81f4\u3002
    • \n
    \n\n

    \u8bf7\u6ce8\u610f\u79d8\u5bc6\u6570\u5b57\u548c\u670b\u53cb\u7684\u731c\u6d4b\u6570\u90fd\u53ef\u80fd\u542b\u6709\u91cd\u590d\u6570\u5b57\uff0c\u6bcf\u4f4d\u6570\u5b57\u53ea\u80fd\u7edf\u8ba1\u4e00\u6b21\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: secret = "1807", guess = "7810"\n\u8f93\u51fa: "1A3B"\n\u89e3\u91ca: 1 \u516c\u725b\u548c 3 \u5976\u725b\u3002\u516c\u725b\u662f 8\uff0c\u5976\u725b\u662f 0, 1 \u548c 7\u3002
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: secret = "1123", guess = "0111"\n\u8f93\u51fa: "1A1B"\n\u89e3\u91ca: \u670b\u53cb\u731c\u6d4b\u6570\u4e2d\u7684\u7b2c\u4e00\u4e2a 1 \u662f\u516c\u725b\uff0c\u7b2c\u4e8c\u4e2a\u6216\u7b2c\u4e09\u4e2a 1 \u53ef\u88ab\u89c6\u4e3a\u5976\u725b\u3002
    \n\n

     

    \n\n

    \u8bf4\u660e: \u4f60\u53ef\u4ee5\u5047\u8bbe\u79d8\u5bc6\u6570\u5b57\u548c\u670b\u53cb\u7684\u731c\u6d4b\u6570\u90fd\u53ea\u5305\u542b\u6570\u5b57\uff0c\u5e76\u4e14\u5b83\u4eec\u7684\u957f\u5ea6\u6c38\u8fdc\u76f8\u7b49\u3002

    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string getHint(string secret, string guess) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String getHint(String secret, String guess) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getHint(self, secret, guess):\n \"\"\"\n :type secret: str\n :type guess: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getHint(self, secret: str, guess: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * getHint(char * secret, char * guess){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string GetHint(string secret, string guess) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} secret\n * @param {string} guess\n * @return {string}\n */\nvar getHint = function(secret, guess) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} secret\n# @param {String} guess\n# @return {String}\ndef get_hint(secret, guess)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getHint(_ secret: String, _ guess: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getHint(secret string, guess string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getHint(secret: String, guess: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getHint(secret: String, guess: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_hint(secret: String, guess: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $secret\n * @param String $guess\n * @return String\n */\n function getHint($secret, $guess) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getHint(secret: string, guess: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-hint secret guess)\n (-> string? string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0299](https://leetcode-cn.com/problems/bulls-and-cows)", "[\u731c\u6570\u5b57\u6e38\u620f](/solution/0200-0299/0299.Bulls%20and%20Cows/README.md)", "`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0299](https://leetcode.com/problems/bulls-and-cows)", "[Bulls and Cows](/solution/0200-0299/0299.Bulls%20and%20Cows/README_EN.md)", "`Hash Table`", "Medium", ""]}, {"question_id": "0298", "frontend_question_id": "0298", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/binary-tree-longest-consecutive-sequence", "url_en": "https://leetcode.com/problems/binary-tree-longest-consecutive-sequence", "relative_path_cn": "/solution/0200-0299/0298.Binary%20Tree%20Longest%20Consecutive%20Sequence/README.md", "relative_path_en": "/solution/0200-0299/0298.Binary%20Tree%20Longest%20Consecutive%20Sequence/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u6700\u957f\u8fde\u7eed\u5e8f\u5217", "title_en": "Binary Tree Longest Consecutive Sequence", "question_title_slug": "binary-tree-longest-consecutive-sequence", "content_en": "

    Given the root of a binary tree, return the length of the longest consecutive sequence path.

    \n\n

    The path refers to any sequence of nodes from some starting node to any node in the tree along the parent-child connections. The longest consecutive path needs to be from parent to child (cannot be the reverse).

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,null,3,2,4,null,null,null,5]\nOutput: 3\nExplanation: Longest consecutive sequence path is 3-4-5, so return 3.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [2,null,3,2,null,1]\nOutput: 2\nExplanation: Longest consecutive sequence path is 2-3, not 3-2-1, so return 2.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 3 * 104].
    • \n\t
    • -3 * 104 <= Node.val <= 3 * 104
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u68f5\u6307\u5b9a\u7684\u4e8c\u53c9\u6811\uff0c\u8bf7\u4f60\u8ba1\u7b97\u5b83\u6700\u957f\u8fde\u7eed\u5e8f\u5217\u8def\u5f84\u7684\u957f\u5ea6\u3002

    \n\n

    \u8be5\u8def\u5f84\uff0c\u53ef\u4ee5\u662f\u4ece\u67d0\u4e2a\u521d\u59cb\u7ed3\u70b9\u5230\u6811\u4e2d\u4efb\u610f\u7ed3\u70b9\uff0c\u901a\u8fc7\u300c\u7236 - \u5b50\u300d\u5173\u7cfb\u8fde\u63a5\u800c\u4ea7\u751f\u7684\u4efb\u610f\u8def\u5f84\u3002

    \n\n

    \u8fd9\u4e2a\u6700\u957f\u8fde\u7eed\u7684\u8def\u5f84\uff0c\u5fc5\u987b\u4ece\u7236\u7ed3\u70b9\u5230\u5b50\u7ed3\u70b9\uff0c\u53cd\u8fc7\u6765\u662f\u4e0d\u53ef\u4ee5\u7684\u3002

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165:\n\n   1\n    \\\n     3\n    / \\\n   2   4\n        \\\n         5\n\n\u8f93\u51fa: 3\n\n\u89e3\u6790: \u5f53\u4e2d\uff0c\u6700\u957f\u8fde\u7eed\u5e8f\u5217\u662f 3-4-5\uff0c\u6240\u4ee5\u8fd4\u56de\u7ed3\u679c\u4e3a 3
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165:\n\n   2\n    \\\n     3\n    / \n   2    \n  / \n 1\n\n\u8f93\u51fa: 2 \n\n\u89e3\u6790: \u5f53\u4e2d\uff0c\u6700\u957f\u8fde\u7eed\u5e8f\u5217\u662f 2-3\u3002\u6ce8\u610f\uff0c\u4e0d\u662f 3-2-1\uff0c\u6240\u4ee5\u8fd4\u56de 2\u3002
    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int longestConsecutive(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int longestConsecutive(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def longestConsecutive(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def longestConsecutive(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint longestConsecutive(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int LongestConsecutive(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar longestConsecutive = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef longest_consecutive(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func longestConsecutive(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc longestConsecutive(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def longestConsecutive(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun longestConsecutive(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn longest_consecutive(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function longestConsecutive($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction longestConsecutive(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (longest-consecutive root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0298](https://leetcode-cn.com/problems/binary-tree-longest-consecutive-sequence)", "[\u4e8c\u53c9\u6811\u6700\u957f\u8fde\u7eed\u5e8f\u5217](/solution/0200-0299/0298.Binary%20Tree%20Longest%20Consecutive%20Sequence/README.md)", "`\u6811`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0298](https://leetcode.com/problems/binary-tree-longest-consecutive-sequence)", "[Binary Tree Longest Consecutive Sequence](/solution/0200-0299/0298.Binary%20Tree%20Longest%20Consecutive%20Sequence/README_EN.md)", "`Tree`", "Medium", "\ud83d\udd12"]}, {"question_id": "0297", "frontend_question_id": "0297", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/serialize-and-deserialize-binary-tree", "url_en": "https://leetcode.com/problems/serialize-and-deserialize-binary-tree", "relative_path_cn": "/solution/0200-0299/0297.Serialize%20and%20Deserialize%20Binary%20Tree/README.md", "relative_path_en": "/solution/0200-0299/0297.Serialize%20and%20Deserialize%20Binary%20Tree/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u7684\u5e8f\u5217\u5316\u4e0e\u53cd\u5e8f\u5217\u5316", "title_en": "Serialize and Deserialize Binary Tree", "question_title_slug": "serialize-and-deserialize-binary-tree", "content_en": "

    Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be reconstructed later in the same or another computer environment.

    \n\n

    Design an algorithm to serialize and deserialize a binary tree. There is no restriction on how your serialization/deserialization algorithm should work. You just need to ensure that a binary tree can be serialized to a string and this string can be deserialized to the original tree structure.

    \n\n

    Clarification: The input/output format is the same as how LeetCode serializes a binary tree. You do not necessarily need to follow this format, so please be creative and come up with different approaches yourself.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,2,3,null,null,4,5]\nOutput: [1,2,3,null,null,4,5]\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = []\nOutput: []\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = [1]\nOutput: [1]\n
    \n\n

    Example 4:

    \n\n
    \nInput: root = [1,2]\nOutput: [1,2]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [0, 104].
    • \n\t
    • -1000 <= Node.val <= 1000
    • \n
    \n", "content_cn": "

    \u5e8f\u5217\u5316\u662f\u5c06\u4e00\u4e2a\u6570\u636e\u7ed3\u6784\u6216\u8005\u5bf9\u8c61\u8f6c\u6362\u4e3a\u8fde\u7eed\u7684\u6bd4\u7279\u4f4d\u7684\u64cd\u4f5c\uff0c\u8fdb\u800c\u53ef\u4ee5\u5c06\u8f6c\u6362\u540e\u7684\u6570\u636e\u5b58\u50a8\u5728\u4e00\u4e2a\u6587\u4ef6\u6216\u8005\u5185\u5b58\u4e2d\uff0c\u540c\u65f6\u4e5f\u53ef\u4ee5\u901a\u8fc7\u7f51\u7edc\u4f20\u8f93\u5230\u53e6\u4e00\u4e2a\u8ba1\u7b97\u673a\u73af\u5883\uff0c\u91c7\u53d6\u76f8\u53cd\u65b9\u5f0f\u91cd\u6784\u5f97\u5230\u539f\u6570\u636e\u3002

    \n\n

    \u8bf7\u8bbe\u8ba1\u4e00\u4e2a\u7b97\u6cd5\u6765\u5b9e\u73b0\u4e8c\u53c9\u6811\u7684\u5e8f\u5217\u5316\u4e0e\u53cd\u5e8f\u5217\u5316\u3002\u8fd9\u91cc\u4e0d\u9650\u5b9a\u4f60\u7684\u5e8f\u5217 / \u53cd\u5e8f\u5217\u5316\u7b97\u6cd5\u6267\u884c\u903b\u8f91\uff0c\u4f60\u53ea\u9700\u8981\u4fdd\u8bc1\u4e00\u4e2a\u4e8c\u53c9\u6811\u53ef\u4ee5\u88ab\u5e8f\u5217\u5316\u4e3a\u4e00\u4e2a\u5b57\u7b26\u4e32\u5e76\u4e14\u5c06\u8fd9\u4e2a\u5b57\u7b26\u4e32\u53cd\u5e8f\u5217\u5316\u4e3a\u539f\u59cb\u7684\u6811\u7ed3\u6784\u3002

    \n\n

    \u63d0\u793a: \u8f93\u5165\u8f93\u51fa\u683c\u5f0f\u4e0e LeetCode \u76ee\u524d\u4f7f\u7528\u7684\u65b9\u5f0f\u4e00\u81f4\uff0c\u8be6\u60c5\u8bf7\u53c2\u9605\u00a0LeetCode \u5e8f\u5217\u5316\u4e8c\u53c9\u6811\u7684\u683c\u5f0f\u3002\u4f60\u5e76\u975e\u5fc5\u987b\u91c7\u53d6\u8fd9\u79cd\u65b9\u5f0f\uff0c\u4f60\u4e5f\u53ef\u4ee5\u91c7\u7528\u5176\u4ed6\u7684\u65b9\u6cd5\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [1,2,3,null,null,4,5]\n\u8f93\u51fa\uff1a[1,2,3,null,null,4,5]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = []\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [1]\n\u8f93\u51fa\uff1a[1]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [1,2]\n\u8f93\u51fa\uff1a[1,2]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u7ed3\u70b9\u6570\u5728\u8303\u56f4 [0, 104] \u5185
    • \n\t
    • -1000 <= Node.val <= 1000
    • \n
    \n", "tags_en": ["Tree", "Design"], "tags_cn": ["\u6811", "\u8bbe\u8ba1"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"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 */\nclass Codec {\npublic:\n\n // Encodes a tree to a single string.\n string serialize(TreeNode* root) {\n \n }\n\n // Decodes your encoded data to tree.\n TreeNode* deserialize(string data) {\n \n }\n};\n\n// Your Codec object will be instantiated and called as such:\n// Codec ser, deser;\n// TreeNode* ans = deser.deserialize(ser.serialize(root));", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode(int x) { val = x; }\n * }\n */\npublic class Codec {\n\n // Encodes a tree to a single string.\n public String serialize(TreeNode root) {\n \n }\n\n // Decodes your encoded data to tree.\n public TreeNode deserialize(String data) {\n \n }\n}\n\n// Your Codec object will be instantiated and called as such:\n// Codec ser = new Codec();\n// Codec deser = new Codec();\n// TreeNode ans = deser.deserialize(ser.serialize(root));", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Codec:\n\n def serialize(self, root):\n \"\"\"Encodes a tree to a single string.\n \n :type root: TreeNode\n :rtype: str\n \"\"\"\n \n\n def deserialize(self, data):\n \"\"\"Decodes your encoded data to tree.\n \n :type data: str\n :rtype: TreeNode\n \"\"\"\n \n\n# Your Codec object will be instantiated and called as such:\n# ser = Codec()\n# deser = Codec()\n# ans = deser.deserialize(ser.serialize(root))", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Codec:\n\n def serialize(self, root):\n \"\"\"Encodes a tree to a single string.\n \n :type root: TreeNode\n :rtype: str\n \"\"\"\n \n\n def deserialize(self, data):\n \"\"\"Decodes your encoded data to tree.\n \n :type data: str\n :rtype: TreeNode\n \"\"\"\n \n\n# Your Codec object will be instantiated and called as such:\n# ser = Codec()\n# deser = Codec()\n# ans = deser.deserialize(ser.serialize(root))", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n/** Encodes a tree to a single string. */\nchar* serialize(struct TreeNode* root) {\n \n}\n\n/** Decodes your encoded data to tree. */\nstruct TreeNode* deserialize(char* data) {\n \n}\n\n// Your functions will be called as such:\n// char* data = serialize(root);\n// deserialize(data);", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int x) { val = x; }\n * }\n */\npublic class Codec {\n\n // Encodes a tree to a single string.\n public string serialize(TreeNode root) {\n \n }\n\n // Decodes your encoded data to tree.\n public TreeNode deserialize(string data) {\n \n }\n}\n\n// Your Codec object will be instantiated and called as such:\n// Codec ser = new Codec();\n// Codec deser = new Codec();\n// TreeNode ans = deser.deserialize(ser.serialize(root));", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val) {\n * this.val = val;\n * this.left = this.right = null;\n * }\n */\n\n/**\n * Encodes a tree to a single string.\n *\n * @param {TreeNode} root\n * @return {string}\n */\nvar serialize = function(root) {\n \n};\n\n/**\n * Decodes your encoded data to tree.\n *\n * @param {string} data\n * @return {TreeNode}\n */\nvar deserialize = function(data) {\n \n};\n\n/**\n * Your functions will be called as such:\n * deserialize(serialize(root));\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val)\n# @val = val\n# @left, @right = nil, nil\n# end\n# end\n\n# Encodes a tree to a single string.\n#\n# @param {TreeNode} root\n# @return {string}\ndef serialize(root)\n \nend\n\n# Decodes your encoded data to tree.\n#\n# @param {string} data\n# @return {TreeNode}\ndef deserialize(data)\n \nend\n\n\n# Your functions will be called as such:\n# deserialize(serialize(data))", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.left = nil\n * self.right = nil\n * }\n * }\n */\n\nclass Codec {\n func serialize(_ root: TreeNode?) -> String {\n \n }\n \n func deserialize(_ data: String) -> TreeNode? {\n \n }\n}\n\n// Your Codec object will be instantiated and called as such:\n// var ser = Codec()\n// var deser = Codec()\n// deser.deserialize(ser.serialize(root))", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\n\ntype Codec struct {\n \n}\n\nfunc Constructor() Codec {\n \n}\n\n// Serializes a tree to a single string.\nfunc (this *Codec) serialize(root *TreeNode) string {\n \n}\n\n// Deserializes your encoded data to tree.\nfunc (this *Codec) deserialize(data string) *TreeNode { \n \n}\n\n\n/**\n * Your Codec object will be instantiated and called as such:\n * ser := Constructor();\n * deser := Constructor();\n * data := ser.serialize(root);\n * ans := deser.deserialize(data);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(var _value: Int) {\n * var value: Int = _value\n * var left: TreeNode = null\n * var right: TreeNode = null\n * }\n */\n\nclass Codec {\n // Encodes a list of strings to a single string.\n def serialize(root: TreeNode): String = {\n \n }\n \n // Decodes a single string to a list of strings.\n def deserialize(data: String): TreeNode = {\n \n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * var ser = new Codec()\n * var deser = new Codec()\n * val s = ser.serialize(root)\n * val ans = deser.deserialize(s)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\n\nclass Codec() {\n\t// Encodes a URL to a shortened URL.\n fun serialize(root: TreeNode?): String {\n \n }\n\n // Decodes your encoded data to tree.\n fun deserialize(data: String): TreeNode? {\n \n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * var ser = Codec()\n * var deser = Codec()\n * var data = ser.serialize(longUrl)\n * var ans = deser.deserialize(data)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n// \n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nstruct Codec {\n\t\n}\n\n/** \n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl Codec {\n fn new() -> Self {\n \n }\n\n fn serialize(&self, root: Option>>) -> String {\n \n }\n\t\n fn deserialize(&self, data: String) -> Option>> {\n \n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * let obj = Codec::new();\n * let data: String = obj.serialize(strs);\n * let ans: Option>> = obj.deserialize(data);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($value) { $this->val = $value; }\n * }\n */\n\nclass Codec {\n function __construct() {\n \n }\n \n /**\n * @param TreeNode $root\n * @return String\n */\n function serialize($root) {\n \n }\n \n /**\n * @param String $data\n * @return TreeNode\n */\n function deserialize($data) {\n \n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * $ser = Codec();\n * $deser = Codec();\n * $data = $ser->serialize($root);\n * $ans = $deser->deserialize($data);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\n/*\n * Encodes a tree to a single string.\n */\nfunction serialize(root: TreeNode | null): string {\n\n};\n\n/*\n * Decodes your encoded data to tree.\n */\nfunction deserialize(data: string): TreeNode | null {\n\n};\n\n\n/**\n * Your functions will be called as such:\n * deserialize(serialize(root));\n */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0297](https://leetcode-cn.com/problems/serialize-and-deserialize-binary-tree)", "[\u4e8c\u53c9\u6811\u7684\u5e8f\u5217\u5316\u4e0e\u53cd\u5e8f\u5217\u5316](/solution/0200-0299/0297.Serialize%20and%20Deserialize%20Binary%20Tree/README.md)", "`\u6811`,`\u8bbe\u8ba1`", "\u56f0\u96be", ""], "md_table_row_en": ["[0297](https://leetcode.com/problems/serialize-and-deserialize-binary-tree)", "[Serialize and Deserialize Binary Tree](/solution/0200-0299/0297.Serialize%20and%20Deserialize%20Binary%20Tree/README_EN.md)", "`Tree`,`Design`", "Hard", ""]}, {"question_id": "0296", "frontend_question_id": "0296", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/best-meeting-point", "url_en": "https://leetcode.com/problems/best-meeting-point", "relative_path_cn": "/solution/0200-0299/0296.Best%20Meeting%20Point/README.md", "relative_path_en": "/solution/0200-0299/0296.Best%20Meeting%20Point/README_EN.md", "title_cn": "\u6700\u4f73\u7684\u78b0\u5934\u5730\u70b9", "title_en": "Best Meeting Point", "question_title_slug": "best-meeting-point", "content_en": "

    Given an m x n binary grid grid where each 1 marks the home of one friend, return the minimal total travel distance.

    \n\n

    The total travel distance is the sum of the distances between the houses of the friends and the meeting point.

    \n\n

    The distance is calculated using Manhattan Distance, where distance(p1, p2) = |p2.x - p1.x| + |p2.y - p1.y|.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: grid = [[1,0,0,0,1],[0,0,0,0,0],[0,0,1,0,0]]\nOutput: 6\nExplanation: Given three friends living at (0,0), (0,4), and (2,2).\nThe point (0,2) is an ideal meeting point, as the total travel distance of 2 + 2 + 2 = 6 is minimal.\nSo return 6.\n
    \n\n

    Example 2:

    \n\n
    \nInput: grid = [[1,1]]\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= m, n <= 200
    • \n\t
    • grid[i][j] is either 0 or 1.
    • \n\t
    • There will be at least two friends in the grid.
    • \n
    \n", "content_cn": "

    \u6709\u4e00\u961f\u4eba\uff08\u4e24\u4eba\u6216\u4ee5\u4e0a\uff09\u60f3\u8981\u5728\u4e00\u4e2a\u5730\u65b9\u78b0\u9762\uff0c\u4ed6\u4eec\u5e0c\u671b\u80fd\u591f\u6700\u5c0f\u5316\u4ed6\u4eec\u7684\u603b\u884c\u8d70\u8ddd\u79bb\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a 2D \u7f51\u683c\uff0c\u5176\u4e2d\u5404\u4e2a\u683c\u5b50\u5185\u7684\u503c\u8981\u4e48\u662f 0\uff0c\u8981\u4e48\u662f 1\u3002

    \n\n

    1 \u8868\u793a\u67d0\u4e2a\u4eba\u7684\u5bb6\u6240\u5904\u7684\u4f4d\u7f6e\u3002\u8fd9\u91cc\uff0c\u6211\u4eec\u5c06\u4f7f\u7528 \u66fc\u54c8\u987f\u8ddd\u79bb \u6765\u8ba1\u7b97\uff0c\u5176\u4e2d distance(p1, p2) = |p2.x - p1.x| + |p2.y - p1.y|\u3002

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165: \n\n1 - 0 - 0 - 0 - 1\n|   |   |   |   |\n0 - 0 - 0 - 0 - 0\n|   |   |   |   |\n0 - 0 - 1 - 0 - 0\n\n\u8f93\u51fa: 6 \n\n\u89e3\u6790: \u7ed9\u5b9a\u7684\u4e09\u4e2a\u4eba\u5206\u522b\u4f4f\u5728(0,0)\uff0c(0,4) \u548c (2,2):\n     (0,2) \u662f\u4e00\u4e2a\u6700\u4f73\u7684\u78b0\u9762\u70b9\uff0c\u5176\u603b\u884c\u8d70\u8ddd\u79bb\u4e3a 2 + 2 + 2 = 6\uff0c\u6700\u5c0f\uff0c\u56e0\u6b64\u8fd4\u56de 6\u3002
    \n", "tags_en": ["Sort", "Math"], "tags_cn": ["\u6392\u5e8f", "\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minTotalDistance(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minTotalDistance(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minTotalDistance(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minTotalDistance(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minTotalDistance(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinTotalDistance(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar minTotalDistance = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef min_total_distance(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minTotalDistance(_ grid: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minTotalDistance(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minTotalDistance(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minTotalDistance(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_total_distance(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function minTotalDistance($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minTotalDistance(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-total-distance grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0296](https://leetcode-cn.com/problems/best-meeting-point)", "[\u6700\u4f73\u7684\u78b0\u5934\u5730\u70b9](/solution/0200-0299/0296.Best%20Meeting%20Point/README.md)", "`\u6392\u5e8f`,`\u6570\u5b66`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0296](https://leetcode.com/problems/best-meeting-point)", "[Best Meeting Point](/solution/0200-0299/0296.Best%20Meeting%20Point/README_EN.md)", "`Sort`,`Math`", "Hard", "\ud83d\udd12"]}, {"question_id": "0295", "frontend_question_id": "0295", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-median-from-data-stream", "url_en": "https://leetcode.com/problems/find-median-from-data-stream", "relative_path_cn": "/solution/0200-0299/0295.Find%20Median%20from%20Data%20Stream/README.md", "relative_path_en": "/solution/0200-0299/0295.Find%20Median%20from%20Data%20Stream/README_EN.md", "title_cn": "\u6570\u636e\u6d41\u7684\u4e2d\u4f4d\u6570", "title_en": "Find Median from Data Stream", "question_title_slug": "find-median-from-data-stream", "content_en": "

    The median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value and the median is the mean of the two middle values.

    \n\n
      \n\t
    • For example, for arr = [2,3,4], the median is 3.
    • \n\t
    • For example, for arr = [2,3], the median is (2 + 3) / 2 = 2.5.
    • \n
    \n\n

    Implement the MedianFinder class:

    \n\n
      \n\t
    • MedianFinder() initializes the MedianFinder object.
    • \n\t
    • void addNum(int num) adds the integer num from the data stream to the data structure.
    • \n\t
    • double findMedian() returns the median of all elements so far. Answers within 10-5 of the actual answer will be accepted.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["MedianFinder", "addNum", "addNum", "findMedian", "addNum", "findMedian"]\n[[], [1], [2], [], [3], []]\nOutput\n[null, null, null, 1.5, null, 2.0]\n\nExplanation\nMedianFinder medianFinder = new MedianFinder();\nmedianFinder.addNum(1);    // arr = [1]\nmedianFinder.addNum(2);    // arr = [1, 2]\nmedianFinder.findMedian(); // return 1.5 (i.e., (1 + 2) / 2)\nmedianFinder.addNum(3);    // arr[1, 2, 3]\nmedianFinder.findMedian(); // return 2.0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • -105 <= num <= 105
    • \n\t
    • There will be at least one element in the data structure before calling findMedian.
    • \n\t
    • At most 5 * 104 calls will be made to addNum and findMedian.
    • \n
    \n\n

     

    \n

    Follow up:

    \n\n
      \n\t
    • If all integer numbers from the stream are in the range [0, 100], how would you optimize your solution?
    • \n\t
    • If 99% of all integer numbers from the stream are in the range [0, 100], how would you optimize your solution?
    • \n
    \n", "content_cn": "

    \u4e2d\u4f4d\u6570\u662f\u6709\u5e8f\u5217\u8868\u4e2d\u95f4\u7684\u6570\u3002\u5982\u679c\u5217\u8868\u957f\u5ea6\u662f\u5076\u6570\uff0c\u4e2d\u4f4d\u6570\u5219\u662f\u4e2d\u95f4\u4e24\u4e2a\u6570\u7684\u5e73\u5747\u503c\u3002

    \n\n

    \u4f8b\u5982\uff0c

    \n\n

    [2,3,4] \u7684\u4e2d\u4f4d\u6570\u662f 3

    \n\n

    [2,3] \u7684\u4e2d\u4f4d\u6570\u662f (2 + 3) / 2 = 2.5

    \n\n

    \u8bbe\u8ba1\u4e00\u4e2a\u652f\u6301\u4ee5\u4e0b\u4e24\u79cd\u64cd\u4f5c\u7684\u6570\u636e\u7ed3\u6784\uff1a

    \n\n
      \n\t
    • void addNum(int num) - \u4ece\u6570\u636e\u6d41\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u6574\u6570\u5230\u6570\u636e\u7ed3\u6784\u4e2d\u3002
    • \n\t
    • double findMedian() - \u8fd4\u56de\u76ee\u524d\u6240\u6709\u5143\u7d20\u7684\u4e2d\u4f4d\u6570\u3002
    • \n
    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    addNum(1)\naddNum(2)\nfindMedian() -> 1.5\naddNum(3) \nfindMedian() -> 2
    \n\n

    \u8fdb\u9636:

    \n\n
      \n\t
    1. \u5982\u679c\u6570\u636e\u6d41\u4e2d\u6240\u6709\u6574\u6570\u90fd\u5728 0 \u5230 100 \u8303\u56f4\u5185\uff0c\u4f60\u5c06\u5982\u4f55\u4f18\u5316\u4f60\u7684\u7b97\u6cd5\uff1f
    2. \n\t
    3. \u5982\u679c\u6570\u636e\u6d41\u4e2d 99% \u7684\u6574\u6570\u90fd\u5728 0 \u5230 100 \u8303\u56f4\u5185\uff0c\u4f60\u5c06\u5982\u4f55\u4f18\u5316\u4f60\u7684\u7b97\u6cd5\uff1f
    4. \n
    \n", "tags_en": ["Heap", "Design"], "tags_cn": ["\u5806", "\u8bbe\u8ba1"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class MedianFinder {\npublic:\n /** initialize your data structure here. */\n MedianFinder() {\n\n }\n \n void addNum(int num) {\n\n }\n \n double findMedian() {\n\n }\n};\n\n/**\n * Your MedianFinder object will be instantiated and called as such:\n * MedianFinder* obj = new MedianFinder();\n * obj->addNum(num);\n * double param_2 = obj->findMedian();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class MedianFinder {\n\n /** initialize your data structure here. */\n public MedianFinder() {\n\n }\n \n public void addNum(int num) {\n\n }\n \n public double findMedian() {\n\n }\n}\n\n/**\n * Your MedianFinder object will be instantiated and called as such:\n * MedianFinder obj = new MedianFinder();\n * obj.addNum(num);\n * double param_2 = obj.findMedian();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class MedianFinder(object):\n\n def __init__(self):\n \"\"\"\n initialize your data structure here.\n \"\"\"\n\n\n def addNum(self, num):\n \"\"\"\n :type num: int\n :rtype: None\n \"\"\"\n\n\n def findMedian(self):\n \"\"\"\n :rtype: float\n \"\"\"\n\n\n\n# Your MedianFinder object will be instantiated and called as such:\n# obj = MedianFinder()\n# obj.addNum(num)\n# param_2 = obj.findMedian()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class MedianFinder:\n\n def __init__(self):\n \"\"\"\n initialize your data structure here.\n \"\"\"\n\n\n def addNum(self, num: int) -> None:\n\n\n def findMedian(self) -> float:\n\n\n\n# Your MedianFinder object will be instantiated and called as such:\n# obj = MedianFinder()\n# obj.addNum(num)\n# param_2 = obj.findMedian()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} MedianFinder;\n\n/** initialize your data structure here. */\n\nMedianFinder* medianFinderCreate() {\n\n}\n\nvoid medianFinderAddNum(MedianFinder* obj, int num) {\n\n}\n\ndouble medianFinderFindMedian(MedianFinder* obj) {\n\n}\n\nvoid medianFinderFree(MedianFinder* obj) {\n\n}\n\n/**\n * Your MedianFinder struct will be instantiated and called as such:\n * MedianFinder* obj = medianFinderCreate();\n * medianFinderAddNum(obj, num);\n \n * double param_2 = medianFinderFindMedian(obj);\n \n * medianFinderFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class MedianFinder {\n\n /** initialize your data structure here. */\n public MedianFinder() {\n\n }\n \n public void AddNum(int num) {\n\n }\n \n public double FindMedian() {\n\n }\n}\n\n/**\n * Your MedianFinder object will be instantiated and called as such:\n * MedianFinder obj = new MedianFinder();\n * obj.AddNum(num);\n * double param_2 = obj.FindMedian();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * initialize your data structure here.\n */\nvar MedianFinder = function() {\n\n};\n\n/** \n * @param {number} num\n * @return {void}\n */\nMedianFinder.prototype.addNum = function(num) {\n\n};\n\n/**\n * @return {number}\n */\nMedianFinder.prototype.findMedian = function() {\n\n};\n\n/**\n * Your MedianFinder object will be instantiated and called as such:\n * var obj = new MedianFinder()\n * obj.addNum(num)\n * var param_2 = obj.findMedian()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class MedianFinder\n\n=begin\n initialize your data structure here.\n=end\n def initialize()\n\n end\n\n\n=begin\n :type num: Integer\n :rtype: Void\n=end\n def add_num(num)\n\n end\n\n\n=begin\n :rtype: Float\n=end\n def find_median()\n\n end\n\n\nend\n\n# Your MedianFinder object will be instantiated and called as such:\n# obj = MedianFinder.new()\n# obj.add_num(num)\n# param_2 = obj.find_median()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass MedianFinder {\n\n /** initialize your data structure here. */\n init() {\n\n }\n \n func addNum(_ num: Int) {\n\n }\n \n func findMedian() -> Double {\n\n }\n}\n\n/**\n * Your MedianFinder object will be instantiated and called as such:\n * let obj = MedianFinder()\n * obj.addNum(num)\n * let ret_2: Double = obj.findMedian()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type MedianFinder struct {\n\n}\n\n\n/** initialize your data structure here. */\nfunc Constructor() MedianFinder {\n\n}\n\n\nfunc (this *MedianFinder) AddNum(num int) {\n\n}\n\n\nfunc (this *MedianFinder) FindMedian() float64 {\n\n}\n\n\n/**\n * Your MedianFinder object will be instantiated and called as such:\n * obj := Constructor();\n * obj.AddNum(num);\n * param_2 := obj.FindMedian();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class MedianFinder() {\n\n /** initialize your data structure here. */\n\n\n def addNum(num: Int) {\n\n }\n\n def findMedian(): Double = {\n\n }\n\n}\n\n/**\n * Your MedianFinder object will be instantiated and called as such:\n * var obj = new MedianFinder()\n * obj.addNum(num)\n * var param_2 = obj.findMedian()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class MedianFinder() {\n\n /** initialize your data structure here. */\n\n\n fun addNum(num: Int) {\n\n }\n\n fun findMedian(): Double {\n\n }\n\n}\n\n/**\n * Your MedianFinder object will be instantiated and called as such:\n * var obj = MedianFinder()\n * obj.addNum(num)\n * var param_2 = obj.findMedian()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct MedianFinder {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl MedianFinder {\n\n /** initialize your data structure here. */\n fn new() -> Self {\n\n }\n \n fn add_num(&self, num: i32) {\n\n }\n \n fn find_median(&self) -> f64 {\n\n }\n}\n\n/**\n * Your MedianFinder object will be instantiated and called as such:\n * let obj = MedianFinder::new();\n * obj.add_num(num);\n * let ret_2: f64 = obj.find_median();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class MedianFinder {\n /**\n * initialize your data structure here.\n */\n function __construct() {\n\n }\n\n /**\n * @param Integer $num\n * @return NULL\n */\n function addNum($num) {\n\n }\n\n /**\n * @return Float\n */\n function findMedian() {\n\n }\n}\n\n/**\n * Your MedianFinder object will be instantiated and called as such:\n * $obj = MedianFinder();\n * $obj->addNum($num);\n * $ret_2 = $obj->findMedian();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class MedianFinder {\n constructor() {\n\n }\n\n addNum(num: number): void {\n\n }\n\n findMedian(): number {\n\n }\n}\n\n/**\n * Your MedianFinder object will be instantiated and called as such:\n * var obj = new MedianFinder()\n * obj.addNum(num)\n * var param_2 = obj.findMedian()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define median-finder%\n (class object%\n (super-new)\n (init-field)\n \n ; add-num : exact-integer? -> void?\n (define/public (add-num num)\n\n )\n ; find-median : -> flonum?\n (define/public (find-median)\n\n )))\n\n;; Your median-finder% object will be instantiated and called as such:\n;; (define obj (new median-finder%))\n;; (send obj add-num num)\n;; (define param_2 (send obj find-median))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0295](https://leetcode-cn.com/problems/find-median-from-data-stream)", "[\u6570\u636e\u6d41\u7684\u4e2d\u4f4d\u6570](/solution/0200-0299/0295.Find%20Median%20from%20Data%20Stream/README.md)", "`\u5806`,`\u8bbe\u8ba1`", "\u56f0\u96be", ""], "md_table_row_en": ["[0295](https://leetcode.com/problems/find-median-from-data-stream)", "[Find Median from Data Stream](/solution/0200-0299/0295.Find%20Median%20from%20Data%20Stream/README_EN.md)", "`Heap`,`Design`", "Hard", ""]}, {"question_id": "0294", "frontend_question_id": "0294", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/flip-game-ii", "url_en": "https://leetcode.com/problems/flip-game-ii", "relative_path_cn": "/solution/0200-0299/0294.Flip%20Game%20II/README.md", "relative_path_en": "/solution/0200-0299/0294.Flip%20Game%20II/README_EN.md", "title_cn": "\u7ffb\u8f6c\u6e38\u620f II", "title_en": "Flip Game II", "question_title_slug": "flip-game-ii", "content_en": "

    You are playing a Flip Game with your friend.

    \n\n

    You are given a string currentState that contains only '+' and '-'. You and your friend take turns to flip two consecutive "++" into "--". The game ends when a person can no longer make a move, and therefore the other person will be the winner.

    \n\n

    Return true if the starting player can guarantee a win, and false otherwise.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: currentState = "++++"\nOutput: true\nExplanation: The starting player can guarantee a win by flipping the middle "++" to become "+--+".\n
    \n\n

    Example 2:

    \n\n
    \nInput: currentState = "+"\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= currentState.length <= 60
    • \n\t
    • currentState[i] is either '+' or '-'.
    • \n
    \n\n

     

    \nFollow up: Derive your algorithm's runtime complexity.", "content_cn": "

    \u4f60\u548c\u670b\u53cb\u73a9\u4e00\u4e2a\u53eb\u505a\u300c\u7ffb\u8f6c\u6e38\u620f\u300d\u7684\u6e38\u620f\u3002\u6e38\u620f\u89c4\u5219\u5982\u4e0b\uff1a

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 currentState \uff0c\u5176\u4e2d\u53ea\u542b '+' \u548c '-' \u3002\u4f60\u548c\u670b\u53cb\u8f6e\u6d41\u5c06\u00a0\u8fde\u7eed \u7684\u4e24\u4e2a\u00a0\"++\"\u00a0\u53cd\u8f6c\u6210\u00a0\"--\" \u3002\u5f53\u4e00\u65b9\u65e0\u6cd5\u8fdb\u884c\u6709\u6548\u7684\u7ffb\u8f6c\u65f6\u4fbf\u610f\u5473\u7740\u6e38\u620f\u7ed3\u675f\uff0c\u5219\u53e6\u4e00\u65b9\u83b7\u80dc\u3002

    \n\n

    \u8bf7\u4f60\u5199\u51fa\u4e00\u4e2a\u51fd\u6570\u6765\u5224\u5b9a\u8d77\u59cb\u73a9\u5bb6 \u662f\u5426\u5b58\u5728\u5fc5\u80dc\u7684\u65b9\u6848 \uff1a\u5982\u679c\u5b58\u5728\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\u00a0\n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1acurrentState = \"++++\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u8d77\u59cb\u73a9\u5bb6\u53ef\u5c06\u4e2d\u95f4\u7684 \"++\" \u7ffb\u8f6c\u53d8\u4e3a \"+--+\" \u4ece\u800c\u5f97\u80dc\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1acurrentState = \"+\"\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= currentState.length <= 60
    • \n\t
    • currentState[i] \u4e0d\u662f '+' \u5c31\u662f '-'
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u8bf7\u63a8\u5bfc\u4f60\u7b97\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u3002

    \n", "tags_en": ["Minimax", "Backtracking"], "tags_cn": ["\u6781\u5c0f\u5316\u6781\u5927", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canWin(string currentState) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canWin(String currentState) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canWin(self, currentState):\n \"\"\"\n :type currentState: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canWin(self, currentState: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canWin(char * currentState){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanWin(string currentState) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} currentState\n * @return {boolean}\n */\nvar canWin = function(currentState) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} current_state\n# @return {Boolean}\ndef can_win(current_state)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canWin(_ currentState: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canWin(currentState string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canWin(currentState: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canWin(currentState: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_win(current_state: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $currentState\n * @return Boolean\n */\n function canWin($currentState) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canWin(currentState: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-win currentState)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0294](https://leetcode-cn.com/problems/flip-game-ii)", "[\u7ffb\u8f6c\u6e38\u620f II](/solution/0200-0299/0294.Flip%20Game%20II/README.md)", "`\u6781\u5c0f\u5316\u6781\u5927`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0294](https://leetcode.com/problems/flip-game-ii)", "[Flip Game II](/solution/0200-0299/0294.Flip%20Game%20II/README_EN.md)", "`Minimax`,`Backtracking`", "Medium", "\ud83d\udd12"]}, {"question_id": "0293", "frontend_question_id": "0293", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/flip-game", "url_en": "https://leetcode.com/problems/flip-game", "relative_path_cn": "/solution/0200-0299/0293.Flip%20Game/README.md", "relative_path_en": "/solution/0200-0299/0293.Flip%20Game/README_EN.md", "title_cn": "\u7ffb\u8f6c\u6e38\u620f", "title_en": "Flip Game", "question_title_slug": "flip-game", "content_en": "

    You are playing a Flip Game with your friend.

    \n\n

    You are given a string currentState that contains only '+' and '-'. You and your friend take turns to flip two consecutive "++" into "--". The game ends when a person can no longer make a move, and therefore the other person will be the winner.

    \n\n

    Return all possible states of the string currentState after one valid move. You may return the answer in any order. If there is no valid move, return an empty list [].

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: currentState = "++++"\nOutput: ["--++","+--+","++--"]\n
    \n\n

    Example 2:

    \n\n
    \nInput: currentState = "+"\nOutput: []\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= currentState.length <= 500
    • \n\t
    • currentState[i] is either '+' or '-'.
    • \n
    \n", "content_cn": "

    \u4f60\u548c\u670b\u53cb\u73a9\u4e00\u4e2a\u53eb\u505a\u300c\u7ffb\u8f6c\u6e38\u620f\u300d\u7684\u6e38\u620f\u3002\u6e38\u620f\u89c4\u5219\u5982\u4e0b\uff1a

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 currentState \uff0c\u5176\u4e2d\u53ea\u542b '+' \u548c '-' \u3002\u4f60\u548c\u670b\u53cb\u8f6e\u6d41\u5c06\u00a0\u8fde\u7eed \u7684\u4e24\u4e2a\u00a0\"++\"\u00a0\u53cd\u8f6c\u6210\u00a0\"--\" \u3002\u5f53\u4e00\u65b9\u65e0\u6cd5\u8fdb\u884c\u6709\u6548\u7684\u7ffb\u8f6c\u65f6\u4fbf\u610f\u5473\u7740\u6e38\u620f\u7ed3\u675f\uff0c\u5219\u53e6\u4e00\u65b9\u83b7\u80dc\u3002

    \n\n

    \u8ba1\u7b97\u5e76\u8fd4\u56de \u4e00\u6b21\u6709\u6548\u64cd\u4f5c \u540e\uff0c\u5b57\u7b26\u4e32\u00a0currentState \u6240\u6709\u7684\u53ef\u80fd\u72b6\u6001\uff0c\u8fd4\u56de\u7ed3\u679c\u53ef\u4ee5\u6309 \u4efb\u610f\u987a\u5e8f \u6392\u5217\u3002\u5982\u679c\u4e0d\u5b58\u5728\u53ef\u80fd\u7684\u6709\u6548\u64cd\u4f5c\uff0c\u8bf7\u8fd4\u56de\u4e00\u4e2a\u7a7a\u5217\u8868\u00a0[] \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1acurrentState = \"++++\"\n\u8f93\u51fa\uff1a[\"--++\",\"+--+\",\"++--\"]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1acurrentState = \"+\"\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= currentState.length <= 500
    • \n\t
    • currentState[i] \u4e0d\u662f '+' \u5c31\u662f '-'
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector generatePossibleNextMoves(string currentState) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List generatePossibleNextMoves(String currentState) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def generatePossibleNextMoves(self, currentState):\n \"\"\"\n :type currentState: str\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def generatePossibleNextMoves(self, currentState: str) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** generatePossibleNextMoves(char * currentState, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList GeneratePossibleNextMoves(string currentState) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} currentState\n * @return {string[]}\n */\nvar generatePossibleNextMoves = function(currentState) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} current_state\n# @return {String[]}\ndef generate_possible_next_moves(current_state)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func generatePossibleNextMoves(_ currentState: String) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func generatePossibleNextMoves(currentState string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def generatePossibleNextMoves(currentState: String): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun generatePossibleNextMoves(currentState: String): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn generate_possible_next_moves(current_state: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $currentState\n * @return String[]\n */\n function generatePossibleNextMoves($currentState) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function generatePossibleNextMoves(currentState: string): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (generate-possible-next-moves currentState)\n (-> string? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0293](https://leetcode-cn.com/problems/flip-game)", "[\u7ffb\u8f6c\u6e38\u620f](/solution/0200-0299/0293.Flip%20Game/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0293](https://leetcode.com/problems/flip-game)", "[Flip Game](/solution/0200-0299/0293.Flip%20Game/README_EN.md)", "`String`", "Easy", "\ud83d\udd12"]}, {"question_id": "0292", "frontend_question_id": "0292", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/nim-game", "url_en": "https://leetcode.com/problems/nim-game", "relative_path_cn": "/solution/0200-0299/0292.Nim%20Game/README.md", "relative_path_en": "/solution/0200-0299/0292.Nim%20Game/README_EN.md", "title_cn": "Nim \u6e38\u620f", "title_en": "Nim Game", "question_title_slug": "nim-game", "content_en": "

    You are playing the following Nim Game with your friend:

    \n\n
      \n\t
    • Initially, there is a heap of stones on the table.
    • \n\t
    • You and your friend will alternate taking turns, and you go first.
    • \n\t
    • On each turn, the person whose turn it is will remove 1 to 3 stones from the heap.
    • \n\t
    • The one who removes the last stone is the winner.
    • \n
    \n\n

    Given n, the number of stones in the heap, return true if you can win the game assuming both you and your friend play optimally, otherwise return false.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 4\nOutput: false\nExplanation: These are the possible outcomes:\n1. You remove 1 stone. Your friend removes 3 stones, including the last stone. Your friend wins.\n2. You remove 2 stones. Your friend removes 2 stones, including the last stone. Your friend wins.\n3. You remove 3 stones. Your friend removes the last stone. Your friend wins.\nIn all outcomes, your friend wins.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 1\nOutput: true\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 2\nOutput: true\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 231 - 1
    • \n
    \n", "content_cn": "

    \u4f60\u548c\u4f60\u7684\u670b\u53cb\uff0c\u4e24\u4e2a\u4eba\u4e00\u8d77\u73a9\u00a0Nim \u6e38\u620f\uff1a

    \n\n
      \n\t
    • \u684c\u5b50\u4e0a\u6709\u4e00\u5806\u77f3\u5934\u3002
    • \n\t
    • \u4f60\u4eec\u8f6e\u6d41\u8fdb\u884c\u81ea\u5df1\u7684\u56de\u5408\uff0c\u4f60\u4f5c\u4e3a\u5148\u624b\u3002
    • \n\t
    • \u6bcf\u4e00\u56de\u5408\uff0c\u8f6e\u5230\u7684\u4eba\u62ff\u6389\u00a01 - 3 \u5757\u77f3\u5934\u3002
    • \n\t
    • \u62ff\u6389\u6700\u540e\u4e00\u5757\u77f3\u5934\u7684\u4eba\u5c31\u662f\u83b7\u80dc\u8005\u3002
    • \n
    \n\n

    \u5047\u8bbe\u4f60\u4eec\u6bcf\u4e00\u6b65\u90fd\u662f\u6700\u4f18\u89e3\u3002\u8bf7\u7f16\u5199\u4e00\u4e2a\u51fd\u6570\uff0c\u6765\u5224\u65ad\u4f60\u662f\u5426\u53ef\u4ee5\u5728\u7ed9\u5b9a\u77f3\u5934\u6570\u91cf\u4e3a n \u7684\u60c5\u51b5\u4e0b\u8d62\u5f97\u6e38\u620f\u3002\u5982\u679c\u53ef\u4ee5\u8d62\uff0c\u8fd4\u56de true\uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 4\n\u8f93\u51fa\uff1afalse \n\u89e3\u91ca\uff1a\u5982\u679c\u5806\u4e2d\u6709 4 \u5757\u77f3\u5934\uff0c\u90a3\u4e48\u4f60\u6c38\u8fdc\u4e0d\u4f1a\u8d62\u5f97\u6bd4\u8d5b\uff1b\n\u00a0    \u56e0\u4e3a\u65e0\u8bba\u4f60\u62ff\u8d70 1 \u5757\u30012 \u5757 \u8fd8\u662f 3 \u5757\u77f3\u5934\uff0c\u6700\u540e\u4e00\u5757\u77f3\u5934\u603b\u662f\u4f1a\u88ab\u4f60\u7684\u670b\u53cb\u62ff\u8d70\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 2\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 231 - 1
    • \n
    \n", "tags_en": ["Brainteaser", "Minimax"], "tags_cn": ["\u8111\u7b4b\u6025\u8f6c\u5f2f", "\u6781\u5c0f\u5316\u6781\u5927"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canWinNim(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canWinNim(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canWinNim(self, n):\n \"\"\"\n :type n: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canWinNim(self, n: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canWinNim(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanWinNim(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {boolean}\n */\nvar canWinNim = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Boolean}\ndef can_win_nim(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canWinNim(_ n: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canWinNim(n int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canWinNim(n: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canWinNim(n: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_win_nim(n: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Boolean\n */\n function canWinNim($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canWinNim(n: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-win-nim n)\n (-> exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0292](https://leetcode-cn.com/problems/nim-game)", "[Nim \u6e38\u620f](/solution/0200-0299/0292.Nim%20Game/README.md)", "`\u8111\u7b4b\u6025\u8f6c\u5f2f`,`\u6781\u5c0f\u5316\u6781\u5927`", "\u7b80\u5355", ""], "md_table_row_en": ["[0292](https://leetcode.com/problems/nim-game)", "[Nim Game](/solution/0200-0299/0292.Nim%20Game/README_EN.md)", "`Brainteaser`,`Minimax`", "Easy", ""]}, {"question_id": "0291", "frontend_question_id": "0291", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/word-pattern-ii", "url_en": "https://leetcode.com/problems/word-pattern-ii", "relative_path_cn": "/solution/0200-0299/0291.Word%20Pattern%20II/README.md", "relative_path_en": "/solution/0200-0299/0291.Word%20Pattern%20II/README_EN.md", "title_cn": "\u5355\u8bcd\u89c4\u5f8b II", "title_en": "Word Pattern II", "question_title_slug": "word-pattern-ii", "content_en": "

    Given a pattern and a string s, return true if s matches the pattern.

    \n\n

    A string s matches a pattern if there is some bijective mapping of single characters to strings such that if each character in pattern is replaced by the string it maps to, then the resulting string is s. A bijective mapping means that no two characters map to the same string, and no character maps to two different strings.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: pattern = "abab", s = "redblueredblue"\nOutput: true\nExplanation: One possible mapping is as follows:\n'a' -> "red"\n'b' -> "blue"
    \n\n

    Example 2:

    \n\n
    \nInput: pattern = "aaaa", s = "asdasdasdasd"\nOutput: true\nExplanation: One possible mapping is as follows:\n'a' -> "asd"\n
    \n\n

    Example 3:

    \n\n
    \nInput: pattern = "abab", s = "asdasdasdasd"\nOutput: true\nExplanation: One possible mapping is as follows:\n'a' -> "a"\n'b' -> "sdasd"\nNote that 'a' and 'b' cannot both map to "asd" since the mapping is a bijection.\n
    \n\n

    Example 4:

    \n\n
    \nInput: pattern = "aabb", s = "xyzabcxzyabc"\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= pattern.length, s.length <= 20
    • \n\t
    • pattern and s consist of only lower-case English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u79cd\u89c4\u5f8b\u00a0pattern\u00a0\u548c\u4e00\u4e2a\u5b57\u7b26\u4e32\u00a0str\uff0c\u8bf7\u4f60\u5224\u65ad\u00a0str\u00a0\u662f\u5426\u9075\u5faa\u5176\u76f8\u540c\u7684\u89c4\u5f8b\u3002

    \n\n

    \u8fd9\u91cc\u6211\u4eec\u6307\u7684\u662f \u5b8c\u5168\u9075\u5faa\uff0c\u4f8b\u5982 pattern\u00a0\u91cc\u7684\u6bcf\u4e2a\u5b57\u6bcd\u548c\u5b57\u7b26\u4e32\u00a0str\u00a0\u4e2d\u6bcf\u4e2a \u975e\u7a7a \u5355\u8bcd\u4e4b\u95f4\uff0c\u5b58\u5728\u7740 \u53cc\u5c04 \u7684\u5bf9\u5e94\u89c4\u5f8b\u3002\u53cc\u5c04 \u610f\u5473\u7740\u6620\u5c04\u53cc\u65b9\u4e00\u4e00\u5bf9\u5e94\uff0c\u4e0d\u4f1a\u5b58\u5728\u4e24\u4e2a\u5b57\u7b26\u6620\u5c04\u5230\u540c\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u4e5f\u4e0d\u4f1a\u5b58\u5728\u4e00\u4e2a\u5b57\u7b26\u5206\u522b\u6620\u5c04\u5230\u4e24\u4e2a\u4e0d\u540c\u7684\u5b57\u7b26\u4e32\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1apattern = \"abab\", s = \"redblueredblue\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u4e00\u79cd\u53ef\u80fd\u7684\u6620\u5c04\u5982\u4e0b\uff1a\n'a' -> \"red\"\n'b' -> \"blue\"
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1apattern = \"aaaa\", s = \"asdasdasdasd\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u4e00\u79cd\u53ef\u80fd\u7684\u6620\u5c04\u5982\u4e0b\uff1a\n'a' -> \"asd\"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1apattern = \"abab\", s = \"asdasdasdasd\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u4e00\u79cd\u53ef\u80fd\u7684\u6620\u5c04\u5982\u4e0b\uff1a\n'a' -> \"a\"\n'b' -> \"sdasd\"\n\u6ce8\u610f 'a' \u548c 'b' \u4e0d\u80fd\u540c\u65f6\u6620\u5c04\u5230 \"asd\"\uff0c\u56e0\u4e3a\u8fd9\u91cc\u7684\u6620\u5c04\u662f\u4e00\u79cd\u53cc\u5c04\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1apattern = \"aabb\", s = \"xyzabcxzyabc\"\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= pattern.length <= 20
    • \n\t
    • 0 <= s.length <= 50
    • \n\t
    • pattern \u548c s \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n", "tags_en": ["Backtracking"], "tags_cn": ["\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool wordPatternMatch(string pattern, string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean wordPatternMatch(String pattern, String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def wordPatternMatch(self, pattern, s):\n \"\"\"\n :type pattern: str\n :type s: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def wordPatternMatch(self, pattern: str, s: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool wordPatternMatch(char * pattern, char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool WordPatternMatch(string pattern, string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} pattern\n * @param {string} s\n * @return {boolean}\n */\nvar wordPatternMatch = function(pattern, s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} pattern\n# @param {String} s\n# @return {Boolean}\ndef word_pattern_match(pattern, s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func wordPatternMatch(_ pattern: String, _ s: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func wordPatternMatch(pattern string, s string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def wordPatternMatch(pattern: String, s: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun wordPatternMatch(pattern: String, s: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn word_pattern_match(pattern: String, s: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $pattern\n * @param String $s\n * @return Boolean\n */\n function wordPatternMatch($pattern, $s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function wordPatternMatch(pattern: string, s: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (word-pattern-match pattern s)\n (-> string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0291](https://leetcode-cn.com/problems/word-pattern-ii)", "[\u5355\u8bcd\u89c4\u5f8b II](/solution/0200-0299/0291.Word%20Pattern%20II/README.md)", "`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0291](https://leetcode.com/problems/word-pattern-ii)", "[Word Pattern II](/solution/0200-0299/0291.Word%20Pattern%20II/README_EN.md)", "`Backtracking`", "Medium", "\ud83d\udd12"]}, {"question_id": "0290", "frontend_question_id": "0290", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/word-pattern", "url_en": "https://leetcode.com/problems/word-pattern", "relative_path_cn": "/solution/0200-0299/0290.Word%20Pattern/README.md", "relative_path_en": "/solution/0200-0299/0290.Word%20Pattern/README_EN.md", "title_cn": "\u5355\u8bcd\u89c4\u5f8b", "title_en": "Word Pattern", "question_title_slug": "word-pattern", "content_en": "

    Given a pattern and a string s, find if s follows the same pattern.

    \n\n

    Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in s.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: pattern = "abba", s = "dog cat cat dog"\nOutput: true\n
    \n\n

    Example 2:

    \n\n
    \nInput: pattern = "abba", s = "dog cat cat fish"\nOutput: false\n
    \n\n

    Example 3:

    \n\n
    \nInput: pattern = "aaaa", s = "dog cat cat dog"\nOutput: false\n
    \n\n

    Example 4:

    \n\n
    \nInput: pattern = "abba", s = "dog dog dog dog"\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= pattern.length <= 300
    • \n\t
    • pattern contains only lower-case English letters.
    • \n\t
    • 1 <= s.length <= 3000
    • \n\t
    • s contains only lower-case English letters and spaces ' '.
    • \n\t
    • s does not contain any leading or trailing spaces.
    • \n\t
    • All the words in s are separated by a single space.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u79cd\u89c4\u5f8b pattern \u548c\u4e00\u4e2a\u5b57\u7b26\u4e32 str \uff0c\u5224\u65ad str \u662f\u5426\u9075\u5faa\u76f8\u540c\u7684\u89c4\u5f8b\u3002

    \n\n

    \u8fd9\u91cc\u7684 \u9075\u5faa \u6307\u5b8c\u5168\u5339\u914d\uff0c\u4f8b\u5982\uff0c pattern \u91cc\u7684\u6bcf\u4e2a\u5b57\u6bcd\u548c\u5b57\u7b26\u4e32 str \u4e2d\u7684\u6bcf\u4e2a\u975e\u7a7a\u5355\u8bcd\u4e4b\u95f4\u5b58\u5728\u7740\u53cc\u5411\u8fde\u63a5\u7684\u5bf9\u5e94\u89c4\u5f8b\u3002

    \n\n

    \u793a\u4f8b1:

    \n\n
    \u8f93\u5165: pattern = "abba", str = "dog cat cat dog"\n\u8f93\u51fa: true
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165:pattern = "abba", str = "dog cat cat fish"\n\u8f93\u51fa: false
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u8f93\u5165: pattern = "aaaa", str = "dog cat cat dog"\n\u8f93\u51fa: false
    \n\n

    \u793a\u4f8b 4:

    \n\n
    \u8f93\u5165: pattern = "abba", str = "dog dog dog dog"\n\u8f93\u51fa: false
    \n\n

    \u8bf4\u660e:
    \n\u4f60\u53ef\u4ee5\u5047\u8bbe pattern \u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd\uff0c str \u5305\u542b\u4e86\u7531\u5355\u4e2a\u7a7a\u683c\u5206\u9694\u7684\u5c0f\u5199\u5b57\u6bcd\u3002    

    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool wordPattern(string pattern, string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean wordPattern(String pattern, String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def wordPattern(self, pattern, s):\n \"\"\"\n :type pattern: str\n :type s: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def wordPattern(self, pattern: str, s: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool wordPattern(char * pattern, char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool WordPattern(string pattern, string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} pattern\n * @param {string} s\n * @return {boolean}\n */\nvar wordPattern = function(pattern, s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} pattern\n# @param {String} s\n# @return {Boolean}\ndef word_pattern(pattern, s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func wordPattern(_ pattern: String, _ s: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func wordPattern(pattern string, s string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def wordPattern(pattern: String, s: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun wordPattern(pattern: String, s: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn word_pattern(pattern: String, s: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $pattern\n * @param String $s\n * @return Boolean\n */\n function wordPattern($pattern, $s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function wordPattern(pattern: string, s: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (word-pattern pattern s)\n (-> string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0290](https://leetcode-cn.com/problems/word-pattern)", "[\u5355\u8bcd\u89c4\u5f8b](/solution/0200-0299/0290.Word%20Pattern/README.md)", "`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0290](https://leetcode.com/problems/word-pattern)", "[Word Pattern](/solution/0200-0299/0290.Word%20Pattern/README_EN.md)", "`Hash Table`", "Easy", ""]}, {"question_id": "0289", "frontend_question_id": "0289", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/game-of-life", "url_en": "https://leetcode.com/problems/game-of-life", "relative_path_cn": "/solution/0200-0299/0289.Game%20of%20Life/README.md", "relative_path_en": "/solution/0200-0299/0289.Game%20of%20Life/README_EN.md", "title_cn": "\u751f\u547d\u6e38\u620f", "title_en": "Game of Life", "question_title_slug": "game-of-life", "content_en": "

    According to Wikipedia's article: "The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970."

    \n\n

    The board is made up of an m x n grid of cells, where each cell has an initial state: live (represented by a 1) or dead (represented by a 0). Each cell interacts with its eight neighbors (horizontal, vertical, diagonal) using the following four rules (taken from the above Wikipedia article):

    \n\n
      \n\t
    1. Any live cell with fewer than two live neighbors dies as if caused by under-population.
    2. \n\t
    3. Any live cell with two or three live neighbors lives on to the next generation.
    4. \n\t
    5. Any live cell with more than three live neighbors dies, as if by over-population.
    6. \n\t
    7. Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction.
    8. \n
    \n\n

    The next state is created by applying the above rules simultaneously to every cell in the current state, where births and deaths occur simultaneously. Given the current state of the m x n grid board, return the next state.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: board = [[0,1,0],[0,0,1],[1,1,1],[0,0,0]]\nOutput: [[0,0,0],[1,0,1],[0,1,1],[0,1,0]]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: board = [[1,1],[1,0]]\nOutput: [[1,1],[1,1]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == board.length
    • \n\t
    • n == board[i].length
    • \n\t
    • 1 <= m, n <= 25
    • \n\t
    • board[i][j] is 0 or 1.
    • \n
    \n\n

     

    \n

    Follow up:

    \n\n
      \n\t
    • Could you solve it in-place? Remember that the board needs to be updated simultaneously: You cannot update some cells first and then use their updated values to update other cells.
    • \n\t
    • In this question, we represent the board using a 2D array. In principle, the board is infinite, which would cause problems when the active area encroaches upon the border of the array (i.e., live cells reach the border). How would you address these problems?
    • \n
    \n", "content_cn": "

    \u6839\u636e\u00a0\u767e\u5ea6\u767e\u79d1\u00a0\uff0c\u751f\u547d\u6e38\u620f\uff0c\u7b80\u79f0\u4e3a\u751f\u547d\uff0c\u662f\u82f1\u56fd\u6570\u5b66\u5bb6\u7ea6\u7ff0\u00b7\u4f55\u987f\u00b7\u5eb7\u5a01\u5728 1970 \u5e74\u53d1\u660e\u7684\u7ec6\u80de\u81ea\u52a8\u673a\u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u5305\u542b m \u00d7 n \u4e2a\u683c\u5b50\u7684\u9762\u677f\uff0c\u6bcf\u4e00\u4e2a\u683c\u5b50\u90fd\u53ef\u4ee5\u770b\u6210\u662f\u4e00\u4e2a\u7ec6\u80de\u3002\u6bcf\u4e2a\u7ec6\u80de\u90fd\u5177\u6709\u4e00\u4e2a\u521d\u59cb\u72b6\u6001\uff1a1 \u5373\u4e3a\u6d3b\u7ec6\u80de\uff08live\uff09\uff0c\u6216 0 \u5373\u4e3a\u6b7b\u7ec6\u80de\uff08dead\uff09\u3002\u6bcf\u4e2a\u7ec6\u80de\u4e0e\u5176\u516b\u4e2a\u76f8\u90bb\u4f4d\u7f6e\uff08\u6c34\u5e73\uff0c\u5782\u76f4\uff0c\u5bf9\u89d2\u7ebf\uff09\u7684\u7ec6\u80de\u90fd\u9075\u5faa\u4ee5\u4e0b\u56db\u6761\u751f\u5b58\u5b9a\u5f8b\uff1a

    \n\n
      \n\t
    1. \u5982\u679c\u6d3b\u7ec6\u80de\u5468\u56f4\u516b\u4e2a\u4f4d\u7f6e\u7684\u6d3b\u7ec6\u80de\u6570\u5c11\u4e8e\u4e24\u4e2a\uff0c\u5219\u8be5\u4f4d\u7f6e\u6d3b\u7ec6\u80de\u6b7b\u4ea1\uff1b
    2. \n\t
    3. \u5982\u679c\u6d3b\u7ec6\u80de\u5468\u56f4\u516b\u4e2a\u4f4d\u7f6e\u6709\u4e24\u4e2a\u6216\u4e09\u4e2a\u6d3b\u7ec6\u80de\uff0c\u5219\u8be5\u4f4d\u7f6e\u6d3b\u7ec6\u80de\u4ecd\u7136\u5b58\u6d3b\uff1b
    4. \n\t
    5. \u5982\u679c\u6d3b\u7ec6\u80de\u5468\u56f4\u516b\u4e2a\u4f4d\u7f6e\u6709\u8d85\u8fc7\u4e09\u4e2a\u6d3b\u7ec6\u80de\uff0c\u5219\u8be5\u4f4d\u7f6e\u6d3b\u7ec6\u80de\u6b7b\u4ea1\uff1b
    6. \n\t
    7. \u5982\u679c\u6b7b\u7ec6\u80de\u5468\u56f4\u6b63\u597d\u6709\u4e09\u4e2a\u6d3b\u7ec6\u80de\uff0c\u5219\u8be5\u4f4d\u7f6e\u6b7b\u7ec6\u80de\u590d\u6d3b\uff1b
    8. \n
    \n\n

    \u4e0b\u4e00\u4e2a\u72b6\u6001\u662f\u901a\u8fc7\u5c06\u4e0a\u8ff0\u89c4\u5219\u540c\u65f6\u5e94\u7528\u4e8e\u5f53\u524d\u72b6\u6001\u4e0b\u7684\u6bcf\u4e2a\u7ec6\u80de\u6240\u5f62\u6210\u7684\uff0c\u5176\u4e2d\u7ec6\u80de\u7684\u51fa\u751f\u548c\u6b7b\u4ea1\u662f\u540c\u65f6\u53d1\u751f\u7684\u3002\u7ed9\u4f60 m x n \u7f51\u683c\u9762\u677f board \u7684\u5f53\u524d\u72b6\u6001\uff0c\u8fd4\u56de\u4e0b\u4e00\u4e2a\u72b6\u6001\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aboard = [[0,1,0],[0,0,1],[1,1,1],[0,0,0]]\n\u8f93\u51fa\uff1a[[0,0,0],[1,0,1],[0,1,1],[0,1,0]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aboard = [[1,1],[1,0]]\n\u8f93\u51fa\uff1a[[1,1],[1,1]]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == board.length
    • \n\t
    • n == board[i].length
    • \n\t
    • 1 <= m, n <= 25
    • \n\t
    • board[i][j] \u4e3a 0 \u6216 1
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u4f60\u53ef\u4ee5\u4f7f\u7528\u539f\u5730\u7b97\u6cd5\u89e3\u51b3\u672c\u9898\u5417\uff1f\u8bf7\u6ce8\u610f\uff0c\u9762\u677f\u4e0a\u6240\u6709\u683c\u5b50\u9700\u8981\u540c\u65f6\u88ab\u66f4\u65b0\uff1a\u4f60\u4e0d\u80fd\u5148\u66f4\u65b0\u67d0\u4e9b\u683c\u5b50\uff0c\u7136\u540e\u4f7f\u7528\u5b83\u4eec\u7684\u66f4\u65b0\u540e\u7684\u503c\u518d\u66f4\u65b0\u5176\u4ed6\u683c\u5b50\u3002
    • \n\t
    • \u672c\u9898\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u4e8c\u7ef4\u6570\u7ec4\u6765\u8868\u793a\u9762\u677f\u3002\u539f\u5219\u4e0a\uff0c\u9762\u677f\u662f\u65e0\u9650\u7684\uff0c\u4f46\u5f53\u6d3b\u7ec6\u80de\u4fb5\u5360\u4e86\u9762\u677f\u8fb9\u754c\u65f6\u4f1a\u9020\u6210\u95ee\u9898\u3002\u4f60\u5c06\u5982\u4f55\u89e3\u51b3\u8fd9\u4e9b\u95ee\u9898\uff1f
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n void gameOfLife(vector>& board) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public void gameOfLife(int[][] board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def gameOfLife(self, board):\n \"\"\"\n :type board: List[List[int]]\n :rtype: None Do not return anything, modify board in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def gameOfLife(self, board: List[List[int]]) -> None:\n \"\"\"\n Do not return anything, modify board in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nvoid gameOfLife(int** board, int boardSize, int* boardColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public void GameOfLife(int[][] board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} board\n * @return {void} Do not return anything, modify board in-place instead.\n */\nvar gameOfLife = function(board) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} board\n# @return {Void} Do not return anything, modify board in-place instead.\ndef game_of_life(board)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func gameOfLife(_ board: inout [[Int]]) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func gameOfLife(board [][]int) {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def gameOfLife(board: Array[Array[Int]]): Unit = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun gameOfLife(board: Array): Unit {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn game_of_life(board: &mut Vec>) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $board\n * @return NULL\n */\n function gameOfLife(&$board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n Do not return anything, modify board in-place instead.\n */\nfunction gameOfLife(board: number[][]): void {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0289](https://leetcode-cn.com/problems/game-of-life)", "[\u751f\u547d\u6e38\u620f](/solution/0200-0299/0289.Game%20of%20Life/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0289](https://leetcode.com/problems/game-of-life)", "[Game of Life](/solution/0200-0299/0289.Game%20of%20Life/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0288", "frontend_question_id": "0288", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/unique-word-abbreviation", "url_en": "https://leetcode.com/problems/unique-word-abbreviation", "relative_path_cn": "/solution/0200-0299/0288.Unique%20Word%20Abbreviation/README.md", "relative_path_en": "/solution/0200-0299/0288.Unique%20Word%20Abbreviation/README_EN.md", "title_cn": "\u5355\u8bcd\u7684\u552f\u4e00\u7f29\u5199", "title_en": "Unique Word Abbreviation", "question_title_slug": "unique-word-abbreviation", "content_en": "

    The abbreviation of a word is a concatenation of its first letter, the number of characters between the first and last letter, and its last letter. If a word has only two characters, then it is an abbreviation of itself.

    \n\n

    For example:

    \n\n
      \n\t
    • dog --> d1g because there is one letter between the first letter 'd' and the last letter 'g'.
    • \n\t
    • internationalization --> i18n because there are 18 letters between the first letter 'i' and the last letter 'n'.
    • \n\t
    • it --> it because any word with only two characters is an abbreviation of itself.
    • \n
    \n\n

    Implement the ValidWordAbbr class:

    \n\n
      \n\t
    • ValidWordAbbr(String[] dictionary) Initializes the object with a dictionary of words.
    • \n\t
    • boolean isUnique(string word) Returns true if either of the following conditions are met (otherwise returns false):\n\t
        \n\t\t
      • There is no word in dictionary whose abbreviation is equal to word's abbreviation.
      • \n\t\t
      • For any word in dictionary whose abbreviation is equal to word's abbreviation, that word and word are the same.
      • \n\t
      \n\t
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["ValidWordAbbr", "isUnique", "isUnique", "isUnique", "isUnique"]\n[[["deer", "door", "cake", "card"]], ["dear"], ["cart"], ["cane"], ["make"]]\nOutput\n[null, false, true, false, true]\n\nExplanation\nValidWordAbbr validWordAbbr = new ValidWordAbbr(["deer", "door", "cake", "card"]);\nvalidWordAbbr.isUnique("dear"); // return false, dictionary word "deer" and word "dear" have the same abbreviation\n                                // "d2r" but are not the same.\nvalidWordAbbr.isUnique("cart"); // return true, no words in the dictionary have the abbreviation "c2t".\nvalidWordAbbr.isUnique("cane"); // return false, dictionary word "cake" and word "cane" have the same abbreviation \n                                // "c2e" but are not the same.\nvalidWordAbbr.isUnique("make"); // return true, no words in the dictionary have the abbreviation "m2e".\nvalidWordAbbr.isUnique("cake"); // return true, because "cake" is already in the dictionary and no other word in the dictionary has "c2e" abbreviation.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= dictionary.length <= 3 * 104
    • \n\t
    • 1 <= dictionary[i].length <= 20
    • \n\t
    • dictionary[i] consists of lowercase English letters.
    • \n\t
    • 1 <= word.length <= 20
    • \n\t
    • word consists of lowercase English letters.
    • \n\t
    • At most 5000 calls will be made to isUnique.
    • \n
    \n", "content_cn": "

    \u5355\u8bcd\u7684 \u7f29\u5199 \u9700\u8981\u9075\u5faa\u00a0<\u8d77\u59cb\u5b57\u6bcd><\u4e2d\u95f4\u5b57\u6bcd\u6570><\u7ed3\u5c3e\u5b57\u6bcd> \u8fd9\u6837\u7684\u683c\u5f0f\u3002\u5982\u679c\u5355\u8bcd\u53ea\u6709\u4e24\u4e2a\u5b57\u7b26\uff0c\u90a3\u4e48\u5b83\u5c31\u662f\u5b83\u81ea\u8eab\u7684 \u7f29\u5199 \u3002

    \n\n

    \u4ee5\u4e0b\u662f\u4e00\u4e9b\u5355\u8bcd\u7f29\u5199\u7684\u8303\u4f8b\uff1a

    \n\n
      \n\t
    • dog --> d1g \u56e0\u4e3a\u7b2c\u4e00\u4e2a\u5b57\u6bcd 'd' \u548c\u6700\u540e\u4e00\u4e2a\u5b57\u6bcd 'g' \u4e4b\u95f4\u6709 1 \u4e2a\u5b57\u6bcd
    • \n\t
    • internationalization --> i18n \u56e0\u4e3a\u7b2c\u4e00\u4e2a\u5b57\u6bcd 'i' \u548c\u6700\u540e\u4e00\u4e2a\u5b57\u6bcd 'n' \u4e4b\u95f4\u6709 18 \u4e2a\u5b57\u6bcd
    • \n\t
    • it --> it \u5355\u8bcd\u53ea\u6709\u4e24\u4e2a\u5b57\u7b26\uff0c\u5b83\u5c31\u662f\u5b83\u81ea\u8eab\u7684 \u7f29\u5199
    • \n
    \n\n

    \u00a0

    \n\n

    \u5b9e\u73b0 ValidWordAbbr \u7c7b\uff1a

    \n\n
      \n\t
    • ValidWordAbbr(String[] dictionary) \u4f7f\u7528\u5355\u8bcd\u5b57\u5178 dictionary \u521d\u59cb\u5316\u5bf9\u8c61
    • \n\t
    • boolean isUnique(string word) \u5982\u679c\u6ee1\u8db3\u4e0b\u8ff0\u4efb\u610f\u4e00\u4e2a\u6761\u4ef6\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \uff1a\n\t
        \n\t\t
      • \u5b57\u5178 dictionary \u4e2d\u6ca1\u6709\u4efb\u4f55\u5176\u4ed6\u5355\u8bcd\u7684 \u7f29\u5199 \u4e0e\u8be5\u5355\u8bcd word \u7684 \u7f29\u5199 \u76f8\u540c\u3002
      • \n\t\t
      • \u5b57\u5178 dictionary \u4e2d\u7684\u6240\u6709 \u7f29\u5199 \u4e0e\u8be5\u5355\u8bcd word \u7684 \u7f29\u5199 \u76f8\u540c\u7684\u5355\u8bcd\u90fd\u4e0e word \u76f8\u540c \u3002
      • \n\t
      \n\t
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\n[\"ValidWordAbbr\", \"isUnique\", \"isUnique\", \"isUnique\", \"isUnique\"]\n[[[\"deer\", \"door\", \"cake\", \"card\"]], [\"dear\"], [\"cart\"], [\"cane\"], [\"make\"]]\n\u8f93\u51fa\n[null, false, true, false, true]\n\n\u89e3\u91ca\nValidWordAbbr validWordAbbr = new ValidWordAbbr([\"deer\", \"door\", \"cake\", \"card\"]);\nvalidWordAbbr.isUnique(\"dear\"); // \u8fd4\u56de false\uff0c\u5b57\u5178\u4e2d\u7684 \"deer\" \u4e0e\u8f93\u5165 \"dear\" \u7684\u7f29\u5199\u90fd\u662f \"d2r\"\uff0c\u4f46\u8fd9\u4e24\u4e2a\u5355\u8bcd\u4e0d\u76f8\u540c\nvalidWordAbbr.isUnique(\"cart\"); // \u8fd4\u56de true\uff0c\u5b57\u5178\u4e2d\u4e0d\u5b58\u5728\u7f29\u5199\u4e3a \"c2t\" \u7684\u5355\u8bcd\nvalidWordAbbr.isUnique(\"cane\"); // \u8fd4\u56de false\uff0c\u5b57\u5178\u4e2d\u7684 \"cake\" \u4e0e\u8f93\u5165 \"cane\" \u7684\u7f29\u5199\u90fd\u662f \"c2e\"\uff0c\u4f46\u8fd9\u4e24\u4e2a\u5355\u8bcd\u4e0d\u76f8\u540c\nvalidWordAbbr.isUnique(\"make\"); // \u8fd4\u56de true\uff0c\u5b57\u5178\u4e2d\u4e0d\u5b58\u5728\u7f29\u5199\u4e3a \"m2e\" \u7684\u5355\u8bcd\nvalidWordAbbr.isUnique(\"cake\"); // \u8fd4\u56de true\uff0c\u56e0\u4e3a \"cake\" \u5df2\u7ecf\u5b58\u5728\u4e8e\u5b57\u5178\u4e2d\uff0c\u5e76\u4e14\u5b57\u5178\u4e2d\u6ca1\u6709\u5176\u4ed6\u7f29\u5199\u4e3a \"c2e\" \u7684\u5355\u8bcd\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= dictionary.length <= 3 * 104
    • \n\t
    • 1 <= dictionary[i].length <= 20
    • \n\t
    • dictionary[i] \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n\t
    • 1 <= word <= 20
    • \n\t
    • word \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n\t
    • \u6700\u591a\u8c03\u7528 5000 \u6b21 isUnique
    • \n
    \n", "tags_en": ["Design", "Hash Table"], "tags_cn": ["\u8bbe\u8ba1", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class ValidWordAbbr {\npublic:\n ValidWordAbbr(vector& dictionary) {\n\n }\n \n bool isUnique(string word) {\n\n }\n};\n\n/**\n * Your ValidWordAbbr object will be instantiated and called as such:\n * ValidWordAbbr* obj = new ValidWordAbbr(dictionary);\n * bool param_1 = obj->isUnique(word);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class ValidWordAbbr {\n\n public ValidWordAbbr(String[] dictionary) {\n\n }\n \n public boolean isUnique(String word) {\n\n }\n}\n\n/**\n * Your ValidWordAbbr object will be instantiated and called as such:\n * ValidWordAbbr obj = new ValidWordAbbr(dictionary);\n * boolean param_1 = obj.isUnique(word);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class ValidWordAbbr(object):\n\n def __init__(self, dictionary):\n \"\"\"\n :type dictionary: List[str]\n \"\"\"\n\n\n def isUnique(self, word):\n \"\"\"\n :type word: str\n :rtype: bool\n \"\"\"\n\n\n\n# Your ValidWordAbbr object will be instantiated and called as such:\n# obj = ValidWordAbbr(dictionary)\n# param_1 = obj.isUnique(word)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class ValidWordAbbr:\n\n def __init__(self, dictionary: List[str]):\n\n\n def isUnique(self, word: str) -> bool:\n\n\n\n# Your ValidWordAbbr object will be instantiated and called as such:\n# obj = ValidWordAbbr(dictionary)\n# param_1 = obj.isUnique(word)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} ValidWordAbbr;\n\n\nValidWordAbbr* validWordAbbrCreate(char ** dictionary, int dictionarySize) {\n \n}\n\nbool validWordAbbrIsUnique(ValidWordAbbr* obj, char * word) {\n \n}\n\nvoid validWordAbbrFree(ValidWordAbbr* obj) {\n \n}\n\n/**\n * Your ValidWordAbbr struct will be instantiated and called as such:\n * ValidWordAbbr* obj = validWordAbbrCreate(dictionary, dictionarySize);\n * bool param_1 = validWordAbbrIsUnique(obj, word);\n \n * validWordAbbrFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class ValidWordAbbr {\n\n public ValidWordAbbr(string[] dictionary) {\n\n }\n \n public bool IsUnique(string word) {\n\n }\n}\n\n/**\n * Your ValidWordAbbr object will be instantiated and called as such:\n * ValidWordAbbr obj = new ValidWordAbbr(dictionary);\n * bool param_1 = obj.IsUnique(word);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} dictionary\n */\nvar ValidWordAbbr = function(dictionary) {\n\n};\n\n/** \n * @param {string} word\n * @return {boolean}\n */\nValidWordAbbr.prototype.isUnique = function(word) {\n\n};\n\n/**\n * Your ValidWordAbbr object will be instantiated and called as such:\n * var obj = new ValidWordAbbr(dictionary)\n * var param_1 = obj.isUnique(word)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class ValidWordAbbr\n\n=begin\n :type dictionary: String[]\n=end\n def initialize(dictionary)\n\n end\n\n\n=begin\n :type word: String\n :rtype: Boolean\n=end\n def is_unique(word)\n\n end\n\n\nend\n\n# Your ValidWordAbbr object will be instantiated and called as such:\n# obj = ValidWordAbbr.new(dictionary)\n# param_1 = obj.is_unique(word)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass ValidWordAbbr {\n\n init(_ dictionary: [String]) {\n\n }\n \n func isUnique(_ word: String) -> Bool {\n\n }\n}\n\n/**\n * Your ValidWordAbbr object will be instantiated and called as such:\n * let obj = ValidWordAbbr(dictionary)\n * let ret_1: Bool = obj.isUnique(word)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type ValidWordAbbr struct {\n\n}\n\n\nfunc Constructor(dictionary []string) ValidWordAbbr {\n\n}\n\n\nfunc (this *ValidWordAbbr) IsUnique(word string) bool {\n\n}\n\n\n/**\n * Your ValidWordAbbr object will be instantiated and called as such:\n * obj := Constructor(dictionary);\n * param_1 := obj.IsUnique(word);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class ValidWordAbbr(_dictionary: Array[String]) {\n\n def isUnique(word: String): Boolean = {\n\n }\n\n}\n\n/**\n * Your ValidWordAbbr object will be instantiated and called as such:\n * var obj = new ValidWordAbbr(dictionary)\n * var param_1 = obj.isUnique(word)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class ValidWordAbbr(dictionary: Array) {\n\n fun isUnique(word: String): Boolean {\n\n }\n\n}\n\n/**\n * Your ValidWordAbbr object will be instantiated and called as such:\n * var obj = ValidWordAbbr(dictionary)\n * var param_1 = obj.isUnique(word)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct ValidWordAbbr {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl ValidWordAbbr {\n\n fn new(dictionary: Vec) -> Self {\n\n }\n \n fn is_unique(&self, word: String) -> bool {\n\n }\n}\n\n/**\n * Your ValidWordAbbr object will be instantiated and called as such:\n * let obj = ValidWordAbbr::new(dictionary);\n * let ret_1: bool = obj.is_unique(word);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class ValidWordAbbr {\n /**\n * @param String[] $dictionary\n */\n function __construct($dictionary) {\n\n }\n\n /**\n * @param String $word\n * @return Boolean\n */\n function isUnique($word) {\n\n }\n}\n\n/**\n * Your ValidWordAbbr object will be instantiated and called as such:\n * $obj = ValidWordAbbr($dictionary);\n * $ret_1 = $obj->isUnique($word);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class ValidWordAbbr {\n constructor(dictionary: string[]) {\n\n }\n\n isUnique(word: string): boolean {\n\n }\n}\n\n/**\n * Your ValidWordAbbr object will be instantiated and called as such:\n * var obj = new ValidWordAbbr(dictionary)\n * var param_1 = obj.isUnique(word)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define valid-word-abbr%\n (class object%\n (super-new)\n\n ; dictionary : (listof string?)\n (init-field\n dictionary)\n \n ; is-unique : string? -> boolean?\n (define/public (is-unique word)\n\n )))\n\n;; Your valid-word-abbr% object will be instantiated and called as such:\n;; (define obj (new valid-word-abbr% [dictionary dictionary]))\n;; (define param_1 (send obj is-unique word))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0288](https://leetcode-cn.com/problems/unique-word-abbreviation)", "[\u5355\u8bcd\u7684\u552f\u4e00\u7f29\u5199](/solution/0200-0299/0288.Unique%20Word%20Abbreviation/README.md)", "`\u8bbe\u8ba1`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0288](https://leetcode.com/problems/unique-word-abbreviation)", "[Unique Word Abbreviation](/solution/0200-0299/0288.Unique%20Word%20Abbreviation/README_EN.md)", "`Design`,`Hash Table`", "Medium", "\ud83d\udd12"]}, {"question_id": "0287", "frontend_question_id": "0287", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-the-duplicate-number", "url_en": "https://leetcode.com/problems/find-the-duplicate-number", "relative_path_cn": "/solution/0200-0299/0287.Find%20the%20Duplicate%20Number/README.md", "relative_path_en": "/solution/0200-0299/0287.Find%20the%20Duplicate%20Number/README_EN.md", "title_cn": "\u5bfb\u627e\u91cd\u590d\u6570", "title_en": "Find the Duplicate Number", "question_title_slug": "find-the-duplicate-number", "content_en": "

    Given an array of integers nums containing n + 1 integers where each integer is in the range [1, n] inclusive.

    \n\n

    There is only one repeated number in nums, return this repeated number.

    \n\n

    You must solve the problem without modifying the array nums and uses only constant extra space.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [1,3,4,2,2]\nOutput: 2\n

    Example 2:

    \n
    Input: nums = [3,1,3,4,2]\nOutput: 3\n

    Example 3:

    \n
    Input: nums = [1,1]\nOutput: 1\n

    Example 4:

    \n
    Input: nums = [1,1,2]\nOutput: 1\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 105
    • \n\t
    • nums.length == n + 1
    • \n\t
    • 1 <= nums[i] <= n
    • \n\t
    • All the integers in nums appear only once except for precisely one integer which appears two or more times.
    • \n
    \n\n

     

    \n

    Follow up:

    \n\n
      \n\t
    • How can we prove that at least one duplicate number must exist in nums?
    • \n\t
    • Can you solve the problem in linear runtime complexity?
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5305\u542b\u00a0n + 1 \u4e2a\u6574\u6570\u7684\u6570\u7ec4\u00a0nums \uff0c\u5176\u6570\u5b57\u90fd\u5728 1 \u5230 n\u00a0\u4e4b\u95f4\uff08\u5305\u62ec 1 \u548c n\uff09\uff0c\u53ef\u77e5\u81f3\u5c11\u5b58\u5728\u4e00\u4e2a\u91cd\u590d\u7684\u6574\u6570\u3002

    \n\n

    \u5047\u8bbe nums \u53ea\u6709 \u4e00\u4e2a\u91cd\u590d\u7684\u6574\u6570 \uff0c\u627e\u51fa \u8fd9\u4e2a\u91cd\u590d\u7684\u6570 \u3002

    \n\n

    \u4f60\u8bbe\u8ba1\u7684\u89e3\u51b3\u65b9\u6848\u5fc5\u987b\u4e0d\u4fee\u6539\u6570\u7ec4 nums \u4e14\u53ea\u7528\u5e38\u91cf\u7ea7 O(1) \u7684\u989d\u5916\u7a7a\u95f4\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,3,4,2,2]\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [3,1,3,4,2]\n\u8f93\u51fa\uff1a3\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,1]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,1,2]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 105
    • \n\t
    • nums.length == n + 1
    • \n\t
    • 1 <= nums[i] <= n
    • \n\t
    • nums \u4e2d \u53ea\u6709\u4e00\u4e2a\u6574\u6570 \u51fa\u73b0 \u4e24\u6b21\u6216\u591a\u6b21 \uff0c\u5176\u4f59\u6574\u6570\u5747\u53ea\u51fa\u73b0 \u4e00\u6b21
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u5982\u4f55\u8bc1\u660e nums \u4e2d\u81f3\u5c11\u5b58\u5728\u4e00\u4e2a\u91cd\u590d\u7684\u6570\u5b57?
    • \n\t
    • \u4f60\u53ef\u4ee5\u8bbe\u8ba1\u4e00\u4e2a\u7ebf\u6027\u7ea7\u65f6\u95f4\u590d\u6742\u5ea6 O(n) \u7684\u89e3\u51b3\u65b9\u6848\u5417\uff1f
    • \n
    \n", "tags_en": ["Array", "Two Pointers", "Binary Search"], "tags_cn": ["\u6570\u7ec4", "\u53cc\u6307\u9488", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findDuplicate(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findDuplicate(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findDuplicate(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findDuplicate(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findDuplicate(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindDuplicate(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar findDuplicate = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef find_duplicate(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findDuplicate(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findDuplicate(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findDuplicate(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findDuplicate(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_duplicate(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function findDuplicate($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findDuplicate(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-duplicate nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0287](https://leetcode-cn.com/problems/find-the-duplicate-number)", "[\u5bfb\u627e\u91cd\u590d\u6570](/solution/0200-0299/0287.Find%20the%20Duplicate%20Number/README.md)", "`\u6570\u7ec4`,`\u53cc\u6307\u9488`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0287](https://leetcode.com/problems/find-the-duplicate-number)", "[Find the Duplicate Number](/solution/0200-0299/0287.Find%20the%20Duplicate%20Number/README_EN.md)", "`Array`,`Two Pointers`,`Binary Search`", "Medium", ""]}, {"question_id": "0286", "frontend_question_id": "0286", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/walls-and-gates", "url_en": "https://leetcode.com/problems/walls-and-gates", "relative_path_cn": "/solution/0200-0299/0286.Walls%20and%20Gates/README.md", "relative_path_en": "/solution/0200-0299/0286.Walls%20and%20Gates/README_EN.md", "title_cn": "\u5899\u4e0e\u95e8", "title_en": "Walls and Gates", "question_title_slug": "walls-and-gates", "content_en": "

    You are given an m x n grid rooms initialized with these three possible values.

    \n\n
      \n\t
    • -1 A wall or an obstacle.
    • \n\t
    • 0 A gate.
    • \n\t
    • INF Infinity means an empty room. We use the value 231 - 1 = 2147483647 to represent INF as you may assume that the distance to a gate is less than 2147483647.
    • \n
    \n\n

    Fill each empty room with the distance to its nearest gate. If it is impossible to reach a gate, it should be filled with INF.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: rooms = [[2147483647,-1,0,2147483647],[2147483647,2147483647,2147483647,-1],[2147483647,-1,2147483647,-1],[0,-1,2147483647,2147483647]]\nOutput: [[3,-1,0,1],[2,2,1,-1],[1,-1,2,-1],[0,-1,3,4]]\n
    \n\n

    Example 2:

    \n\n
    \nInput: rooms = [[-1]]\nOutput: [[-1]]\n
    \n\n

    Example 3:

    \n\n
    \nInput: rooms = [[2147483647]]\nOutput: [[2147483647]]\n
    \n\n

    Example 4:

    \n\n
    \nInput: rooms = [[0]]\nOutput: [[0]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == rooms.length
    • \n\t
    • n == rooms[i].length
    • \n\t
    • 1 <= m, n <= 250
    • \n\t
    • rooms[i][j] is -1, 0, or 231 - 1.
    • \n
    \n", "content_cn": "

    \u4f60\u88ab\u7ed9\u5b9a\u4e00\u4e2a\u00a0m \u00d7 n\u00a0\u7684\u4e8c\u7ef4\u7f51\u683c rooms \uff0c\u7f51\u683c\u4e2d\u6709\u4ee5\u4e0b\u4e09\u79cd\u53ef\u80fd\u7684\u521d\u59cb\u5316\u503c\uff1a

    \n\n
      \n\t
    1. -1\u00a0\u8868\u793a\u5899\u6216\u662f\u969c\u788d\u7269
    2. \n\t
    3. 0\u00a0\u8868\u793a\u4e00\u6247\u95e8
    4. \n\t
    5. INF\u00a0\u65e0\u9650\u8868\u793a\u4e00\u4e2a\u7a7a\u7684\u623f\u95f4\u3002\u7136\u540e\uff0c\u6211\u4eec\u7528\u00a0231 - 1 = 2147483647\u00a0\u4ee3\u8868\u00a0INF\u3002\u4f60\u53ef\u4ee5\u8ba4\u4e3a\u901a\u5f80\u95e8\u7684\u8ddd\u79bb\u603b\u662f\u5c0f\u4e8e\u00a02147483647\u00a0\u7684\u3002
    6. \n
    \n\n

    \u4f60\u8981\u7ed9\u6bcf\u4e2a\u7a7a\u623f\u95f4\u4f4d\u4e0a\u586b\u4e0a\u8be5\u623f\u95f4\u5230\u00a0\u6700\u8fd1\u95e8\u7684\u8ddd\u79bb \uff0c\u5982\u679c\u65e0\u6cd5\u5230\u8fbe\u95e8\uff0c\u5219\u586b\u00a0INF\u00a0\u5373\u53ef\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1arooms = [[2147483647,-1,0,2147483647],[2147483647,2147483647,2147483647,-1],[2147483647,-1,2147483647,-1],[0,-1,2147483647,2147483647]]\n\u8f93\u51fa\uff1a[[3,-1,0,1],[2,2,1,-1],[1,-1,2,-1],[0,-1,3,4]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1arooms = [[-1]]\n\u8f93\u51fa\uff1a[[-1]]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1arooms = [[2147483647]]\n\u8f93\u51fa\uff1a[[2147483647]]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1arooms = [[0]]\n\u8f93\u51fa\uff1a[[0]]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == rooms.length
    • \n\t
    • n == rooms[i].length
    • \n\t
    • 1 <= m, n <= 250
    • \n\t
    • rooms[i][j] \u662f -1\u30010 \u6216 231 - 1
    • \n
    \n", "tags_en": ["Breadth-first Search"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n void wallsAndGates(vector>& rooms) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public void wallsAndGates(int[][] rooms) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def wallsAndGates(self, rooms):\n \"\"\"\n :type rooms: List[List[int]]\n :rtype: None Do not return anything, modify rooms in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def wallsAndGates(self, rooms: List[List[int]]) -> None:\n \"\"\"\n Do not return anything, modify rooms in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nvoid wallsAndGates(int** rooms, int roomsSize, int* roomsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public void WallsAndGates(int[][] rooms) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} rooms\n * @return {void} Do not return anything, modify rooms in-place instead.\n */\nvar wallsAndGates = function(rooms) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} rooms\n# @return {Void} Do not return anything, modify rooms in-place instead.\ndef walls_and_gates(rooms)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func wallsAndGates(_ rooms: inout [[Int]]) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func wallsAndGates(rooms [][]int) {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def wallsAndGates(rooms: Array[Array[Int]]): Unit = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun wallsAndGates(rooms: Array): Unit {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn walls_and_gates(rooms: &mut Vec>) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $rooms\n * @return NULL\n */\n function wallsAndGates(&$rooms) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n Do not return anything, modify rooms in-place instead.\n */\nfunction wallsAndGates(rooms: number[][]): void {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0286](https://leetcode-cn.com/problems/walls-and-gates)", "[\u5899\u4e0e\u95e8](/solution/0200-0299/0286.Walls%20and%20Gates/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0286](https://leetcode.com/problems/walls-and-gates)", "[Walls and Gates](/solution/0200-0299/0286.Walls%20and%20Gates/README_EN.md)", "`Breadth-first Search`", "Medium", "\ud83d\udd12"]}, {"question_id": "0285", "frontend_question_id": "0285", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/inorder-successor-in-bst", "url_en": "https://leetcode.com/problems/inorder-successor-in-bst", "relative_path_cn": "/solution/0200-0299/0285.Inorder%20Successor%20in%20BST/README.md", "relative_path_en": "/solution/0200-0299/0285.Inorder%20Successor%20in%20BST/README_EN.md", "title_cn": "\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u7684\u4e2d\u5e8f\u540e\u7ee7", "title_en": "Inorder Successor in BST", "question_title_slug": "inorder-successor-in-bst", "content_en": "

    Given the root of a binary search tree and a node p in it, return the in-order successor of that node in the BST. If the given node has no in-order successor in the tree, return null.

    \n\n

    The successor of a node p is the node with the smallest key greater than p.val.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [2,1,3], p = 1\nOutput: 2\nExplanation: 1's in-order successor node is 2. Note that both p and the return value is of TreeNode type.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [5,3,6,2,4,null,null,1], p = 6\nOutput: null\nExplanation: There is no in-order successor of the current node, so the answer is null.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 104].
    • \n\t
    • -105 <= Node.val <= 105
    • \n\t
    • All Nodes will have unique values.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u68f5\u4e8c\u53c9\u641c\u7d22\u6811\u548c\u5176\u4e2d\u7684\u4e00\u4e2a\u8282\u70b9 p \uff0c\u627e\u5230\u8be5\u8282\u70b9\u5728\u6811\u4e2d\u7684\u4e2d\u5e8f\u540e\u7ee7\u3002\u5982\u679c\u8282\u70b9\u6ca1\u6709\u4e2d\u5e8f\u540e\u7ee7\uff0c\u8bf7\u8fd4\u56de null \u3002

    \n\n

    \u8282\u70b9\u00a0p\u00a0\u7684\u540e\u7ee7\u662f\u503c\u6bd4\u00a0p.val\u00a0\u5927\u7684\u8282\u70b9\u4e2d\u952e\u503c\u6700\u5c0f\u7684\u8282\u70b9\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aroot = [2,1,3], p = 1\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u8fd9\u91cc 1 \u7684\u4e2d\u5e8f\u540e\u7ee7\u662f 2\u3002\u8bf7\u6ce8\u610f p \u548c\u8fd4\u56de\u503c\u90fd\u5e94\u662f TreeNode \u7c7b\u578b\u3002\n
    \n\n

    \u793a\u4f8b\u00a02\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aroot = [5,3,6,2,4,null,null,1], p = 6\n\u8f93\u51fa\uff1anull\n\u89e3\u91ca\uff1a\u56e0\u4e3a\u7ed9\u51fa\u7684\u8282\u70b9\u6ca1\u6709\u4e2d\u5e8f\u540e\u7ee7\uff0c\u6240\u4ee5\u7b54\u6848\u5c31\u8fd4\u56de null \u4e86\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u7684\u6570\u76ee\u5728\u8303\u56f4 [1, 104] \u5185\u3002
    • \n\t
    • -105 <= Node.val <= 105
    • \n\t
    • \u6811\u4e2d\u5404\u8282\u70b9\u7684\u503c\u5747\u4fdd\u8bc1\u552f\u4e00\u3002
    • \n
    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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 */\nclass Solution {\npublic:\n TreeNode* inorderSuccessor(TreeNode* root, TreeNode* p) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode(int x) { val = x; }\n * }\n */\nclass Solution {\n public TreeNode inorderSuccessor(TreeNode root, TreeNode p) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution(object):\n def inorderSuccessor(self, root, p):\n \"\"\"\n :type root: TreeNode\n :type p: TreeNode\n :rtype: TreeNode\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution:\n def inorderSuccessor(self, root: 'TreeNode', p: 'TreeNode') -> 'TreeNode':\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\nstruct TreeNode* inorderSuccessor(struct TreeNode* root, struct TreeNode* p) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int x) { val = x; }\n * }\n */\npublic class Solution {\n public TreeNode InorderSuccessor(TreeNode root, TreeNode p) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val) {\n * this.val = val;\n * this.left = this.right = null;\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {TreeNode} p\n * @return {TreeNode}\n */\nvar inorderSuccessor = function(root, p) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val)\n# @val = val\n# @left, @right = nil, nil\n# end\n# end\n\n# @param {TreeNode} root\n# @param {TreeNode} p\n# @return {TreeNode}\ndef inorder_successor(root, p)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.left = nil\n * self.right = nil\n * }\n * }\n */\n\nclass Solution {\n func inorderSuccessor(_ root: TreeNode?, _ p: TreeNode?) -> TreeNode? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc inorderSuccessor(root *TreeNode, p *TreeNode) *TreeNode {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(var _value: Int) {\n * var value: Int = _value\n * var left: TreeNode = null\n * var right: TreeNode = null\n * }\n */\n\nobject Solution {\n def inorderSuccessor(root: TreeNode, p: TreeNode): TreeNode = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int = 0) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\n\nclass Solution {\n fun inorderSuccessor(root: TreeNode?, p: TreeNode?): TreeNode? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n// \n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn inorder_successor(root: Option>>, p: Option>>) -> Option>> {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($value) { $this->val = $value; }\n * }\n */\n\nclass Solution {\n /**\n * @param TreeNode $root\n * @param TreeNode $p\n * @return TreeNode\n */\n function inorderSuccessor($root, $p) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction inorderSuccessor(root: TreeNode | null, p: TreeNode | null): TreeNode | null {\n\t\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0285](https://leetcode-cn.com/problems/inorder-successor-in-bst)", "[\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u7684\u4e2d\u5e8f\u540e\u7ee7](/solution/0200-0299/0285.Inorder%20Successor%20in%20BST/README.md)", "`\u6811`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0285](https://leetcode.com/problems/inorder-successor-in-bst)", "[Inorder Successor in BST](/solution/0200-0299/0285.Inorder%20Successor%20in%20BST/README_EN.md)", "`Tree`", "Medium", "\ud83d\udd12"]}, {"question_id": "0284", "frontend_question_id": "0284", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/peeking-iterator", "url_en": "https://leetcode.com/problems/peeking-iterator", "relative_path_cn": "/solution/0200-0299/0284.Peeking%20Iterator/README.md", "relative_path_en": "/solution/0200-0299/0284.Peeking%20Iterator/README_EN.md", "title_cn": "\u9876\u7aef\u8fed\u4ee3\u5668", "title_en": "Peeking Iterator", "question_title_slug": "peeking-iterator", "content_en": "

    Design an iterator that supports the peek operation on a list in addition to the hasNext and the next operations.

    \n\n

    Implement the PeekingIterator class:

    \n\n
      \n\t
    • PeekingIterator(int[] nums) Initializes the object with the given integer array nums.
    • \n\t
    • int next() Returns the next element in the array and moves the pointer to the next element.
    • \n\t
    • bool hasNext() Returns true if there are still elements in the array.
    • \n\t
    • int peek() Returns the next element in the array without moving the pointer.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["PeekingIterator", "next", "peek", "next", "next", "hasNext"]\n[[[1, 2, 3]], [], [], [], [], []]\nOutput\n[null, 1, 2, 2, 3, false]\n\nExplanation\nPeekingIterator peekingIterator = new PeekingIterator([1, 2, 3]); // [1,2,3]\npeekingIterator.next();    // return 1, the pointer moves to the next element [1,2,3].\npeekingIterator.peek();    // return 2, the pointer does not move [1,2,3].\npeekingIterator.next();    // return 2, the pointer moves to the next element [1,2,3]\npeekingIterator.next();    // return 3, the pointer moves to the next element [1,2,3]\npeekingIterator.hasNext(); // return False\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 1000
    • \n\t
    • 1 <= nums[i] <= 1000
    • \n\t
    • All the calls to next and peek are valid.
    • \n\t
    • At most 1000 calls will be made to next, hasNext, and peek.
    • \n
    \n\n

     

    \nFollow up: How would you extend your design to be generic and work with all types, not just integer?", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u8fed\u4ee3\u5668\u7c7b\u7684\u63a5\u53e3\uff0c\u63a5\u53e3\u5305\u542b\u4e24\u4e2a\u65b9\u6cd5\uff1a next() \u548c hasNext()\u3002\u8bbe\u8ba1\u5e76\u5b9e\u73b0\u4e00\u4e2a\u652f\u6301 peek() \u64cd\u4f5c\u7684\u9876\u7aef\u8fed\u4ee3\u5668 -- \u5176\u672c\u8d28\u5c31\u662f\u628a\u539f\u672c\u5e94\u7531 next() \u65b9\u6cd5\u8fd4\u56de\u7684\u5143\u7d20 peek() \u51fa\u6765\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u5047\u8bbe\u8fed\u4ee3\u5668\u88ab\u521d\u59cb\u5316\u4e3a\u5217\u8868 [1,2,3]\u3002\n\n\u8c03\u7528 next() \u8fd4\u56de 1\uff0c\u5f97\u5230\u5217\u8868\u4e2d\u7684\u7b2c\u4e00\u4e2a\u5143\u7d20\u3002\n\u73b0\u5728\u8c03\u7528 peek() \u8fd4\u56de 2\uff0c\u4e0b\u4e00\u4e2a\u5143\u7d20\u3002\u5728\u6b64\u4e4b\u540e\u8c03\u7528 next() \u4ecd\u7136\u8fd4\u56de 2\u3002\n\u6700\u540e\u4e00\u6b21\u8c03\u7528 next() \u8fd4\u56de 3\uff0c\u672b\u5c3e\u5143\u7d20\u3002\u5728\u6b64\u4e4b\u540e\u8c03\u7528 hasNext() \u5e94\u8be5\u8fd4\u56de false\u3002\n
    \n\n

    \u8fdb\u9636\uff1a\u4f60\u5c06\u5982\u4f55\u62d3\u5c55\u4f60\u7684\u8bbe\u8ba1\uff1f\u4f7f\u4e4b\u53d8\u5f97\u901a\u7528\u5316\uff0c\u4ece\u800c\u9002\u5e94\u6240\u6709\u7684\u7c7b\u578b\uff0c\u800c\u4e0d\u53ea\u662f\u6574\u6570\u578b\uff1f

    \n", "tags_en": ["Design"], "tags_cn": ["\u8bbe\u8ba1"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n * Below is the interface for Iterator, which is already defined for you.\n * **DO NOT** modify the interface for Iterator.\n *\n * class Iterator {\n *\t\tstruct Data;\n * \t\tData* data;\n * public:\n *\t\tIterator(const vector& nums);\n * \t\tIterator(const Iterator& iter);\n *\n * \t\t// Returns the next element in the iteration.\n *\t\tint next();\n *\n *\t\t// Returns true if the iteration has more elements.\n *\t\tbool hasNext() const;\n *\t};\n */\n\nclass PeekingIterator : public Iterator {\npublic:\n\tPeekingIterator(const vector& nums) : Iterator(nums) {\n\t // Initialize any member here.\n\t // **DO NOT** save a copy of nums and manipulate it directly.\n\t // You should only use the Iterator interface methods.\n\t \n\t}\n\t\n // Returns the next element in the iteration without advancing the iterator.\n\tint peek() {\n \n\t}\n\t\n\t// hasNext() and next() should behave the same as in the Iterator interface.\n\t// Override them if needed.\n\tint next() {\n\t \n\t}\n\t\n\tbool hasNext() const {\n\t \n\t}\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "// Java Iterator interface reference:\n// https://docs.oracle.com/javase/8/docs/api/java/util/Iterator.html\n\nclass PeekingIterator implements Iterator {\n\tpublic PeekingIterator(Iterator iterator) {\n\t // initialize any member here.\n\t \n\t}\n\t\n // Returns the next element in the iteration without advancing the iterator.\n\tpublic Integer peek() {\n \n\t}\n\t\n\t// hasNext() and next() should behave the same as in the Iterator interface.\n\t// Override them if needed.\n\t@Override\n\tpublic Integer next() {\n\t \n\t}\n\t\n\t@Override\n\tpublic boolean hasNext() {\n\t \n\t}\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Below is the interface for Iterator, which is already defined for you.\n#\n# class Iterator(object):\n# def __init__(self, nums):\n# \"\"\"\n# Initializes an iterator object to the beginning of a list.\n# :type nums: List[int]\n# \"\"\"\n#\n# def hasNext(self):\n# \"\"\"\n# Returns true if the iteration has more elements.\n# :rtype: bool\n# \"\"\"\n#\n# def next(self):\n# \"\"\"\n# Returns the next element in the iteration.\n# :rtype: int\n# \"\"\"\n\nclass PeekingIterator(object):\n def __init__(self, iterator):\n \"\"\"\n Initialize your data structure here.\n :type iterator: Iterator\n \"\"\"\n \n\n def peek(self):\n \"\"\"\n Returns the next element in the iteration without advancing the iterator.\n :rtype: int\n \"\"\"\n \n\n def next(self):\n \"\"\"\n :rtype: int\n \"\"\"\n \n\n def hasNext(self):\n \"\"\"\n :rtype: bool\n \"\"\"\n \n\n# Your PeekingIterator object will be instantiated and called as such:\n# iter = PeekingIterator(Iterator(nums))\n# while iter.hasNext():\n# val = iter.peek() # Get the next element but not advance the iterator.\n# iter.next() # Should return the same value as [val].", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Below is the interface for Iterator, which is already defined for you.\n#\n# class Iterator:\n# def __init__(self, nums):\n# \"\"\"\n# Initializes an iterator object to the beginning of a list.\n# :type nums: List[int]\n# \"\"\"\n#\n# def hasNext(self):\n# \"\"\"\n# Returns true if the iteration has more elements.\n# :rtype: bool\n# \"\"\"\n#\n# def next(self):\n# \"\"\"\n# Returns the next element in the iteration.\n# :rtype: int\n# \"\"\"\n\nclass PeekingIterator:\n def __init__(self, iterator):\n \"\"\"\n Initialize your data structure here.\n :type iterator: Iterator\n \"\"\"\n \n\n def peek(self):\n \"\"\"\n Returns the next element in the iteration without advancing the iterator.\n :rtype: int\n \"\"\"\n \n\n def next(self):\n \"\"\"\n :rtype: int\n \"\"\"\n \n\n def hasNext(self):\n \"\"\"\n :rtype: bool\n \"\"\"\n \n\n# Your PeekingIterator object will be instantiated and called as such:\n# iter = PeekingIterator(Iterator(nums))\n# while iter.hasNext():\n# val = iter.peek() # Get the next element but not advance the iterator.\n# iter.next() # Should return the same value as [val].", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/*\n *\tstruct Iterator {\n *\t\t// Returns true if the iteration has more elements.\n *\t\tbool (*hasNext)();\n *\n * \t\t// Returns the next element in the iteration.\n *\t\tint (*next)();\n *\t};\n */\n\nstruct PeekingIterator {\n \n};\n\nstruct PeekingIterator* Constructor(struct Iterator* iter) {\n struct PeekingIterator* piter = malloc(sizeof(struct PeekingIterator));\n piter->iterator = iter;\n piter->hasPeeked = false;\n return piter;\n}\n\nint peek(struct PeekingIterator* obj) {\n \n}\n\nint next(struct PeekingIterator* obj) {\n \n}\n\nbool hasNext(struct PeekingIterator* obj) {\n \n}\n\n/**\n * Your PeekingIterator struct will be instantiated and called as such:\n * PeekingIterator* obj = peekingIteratorCreate(arr, arrSize);\n * int param_1 = peek(obj);\n * int param_2 = next(obj);\n * bool param_3 = hasNext(obj);\n * peekingIteratorFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "// C# IEnumerator interface reference:\n// https://docs.microsoft.com/en-us/dotnet/api/system.collections.ienumerator?view=netframework-4.8\n\nclass PeekingIterator {\n // iterators refers to the first element of the array.\n public PeekingIterator(IEnumerator iterator) {\n // initialize any member here.\n }\n \n // Returns the next element in the iteration without advancing the iterator.\n public int Peek() {\n \n }\n \n // Returns the next element in the iteration and advances the iterator.\n public int Next() {\n \n }\n \n // Returns false if the iterator is refering to the end of the array of true otherwise.\n public bool HasNext() {\n\t\t\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // This is the Iterator's API interface.\n * // You should not implement it, or speculate about its implementation.\n * function Iterator() {\n * @ return {number}\n * this.next = function() { // return the next number of the iterator\n * ...\n * }; \n *\n * @return {boolean}\n * this.hasNext = function() { // return true if it still has numbers\n * ...\n * };\n * };\n */\n\n/**\n * @param {Iterator} iterator\n */\nvar PeekingIterator = function(iterator) {\n \n};\n\n/**\n * @return {number}\n */\nPeekingIterator.prototype.peek = function() {\n \n};\n\n/**\n * @return {number}\n */\nPeekingIterator.prototype.next = function() {\n \n};\n\n/**\n * @return {boolean}\n */\nPeekingIterator.prototype.hasNext = function() {\n \n};\n\n/** \n * Your PeekingIterator object will be instantiated and called as such:\n * var obj = new PeekingIterator(arr)\n * var param_1 = obj.peek()\n * var param_2 = obj.next()\n * var param_3 = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Below is the interface for Iterator, which is already defined for you.\n#\n# class Iterator\n# \tdef initialize(v)\n# \n# end\n#\n# def hasNext()\n#\t\tReturns true if the iteration has more elements.\n# end\n#\n# def next()\n# \tReturns the next element in the iteration.\n# end\n# end\n\nclass PeekingIterator\n # @param {Iterator} iter\n def initialize(iter)\n \t\n end\n \n # Returns true if the iteration has more elements.\n # @return {boolean}\n def hasNext()\n \t\n end\n \n # Returns the next element in the iteration.\n # @return {integer}\n def next()\n \t\n end\n \n # Returns the next element in the iteration without advancing the iterator.\n # @return {integer}\n def peek()\n \t\n end\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "// Swift IndexingIterator refernence:\n// https://developer.apple.com/documentation/swift/indexingiterator\n\nclass PeekingIterator {\n init(_ arr: IndexingIterator>) {\n \n }\n \n func next() -> Int {\n \n }\n \n func peek() -> Int {\n \n }\n \n func hasNext() -> Bool {\n \n }\n}\n\n/**\n * Your PeekingIterator object will be instantiated and called as such:\n * let obj = PeekingIterator(arr)\n * let ret_1: Int = obj.next()\n * let ret_2: Int = obj.peek()\n * let ret_3: Bool = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/* Below is the interface for Iterator, which is already defined for you.\n *\n * type Iterator struct {\n * \n * }\n *\n * func (this *Iterator) hasNext() bool {\n *\t\t// Returns true if the iteration has more elements.\n * }\n *\n * func (this *Iterator) next() int {\n *\t\t// Returns the next element in the iteration.\n * }\n */\n\ntype PeekingIterator struct {\n \n}\n\nfunc Constructor(iter *Iterator) *PeekingIterator {\n \n}\n\nfunc (this *PeekingIterator) hasNext() bool {\n \n}\n\nfunc (this *PeekingIterator) next() int {\n \n}\n\nfunc (this *PeekingIterator) peek() int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "// Scala Iterator reference:\n// https://www.scala-lang.org/api/2.12.2/scala/collection/Iterator.html\n\nclass PeekingIterator(_iterator: Iterator[Int]) {\n def peek(): Int = {\n \n }\n \n def next(): Int = {\n \n }\n \n def hasNext(): Boolean = {\n \n }\n}\n\n/**\n * Your PeekingIterator object will be instantiated and called as such:\n * var obj = new PeekingIterator(arr)\n * var param_1 = obj.next()\n * var param_2 = obj.peek()\n * var param_3 = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "// Kotlin Iterator reference:\n// https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-iterator/\n\nclass PeekingIterator(iterator:Iterator):Iterator {\n fun peek(): Int {\n \t\n }\n \n override fun next(): Int {\n \n }\n \n override fun hasNext(): Boolean {\n \n }\n}\n\n/**\n * Your PeekingIterator object will be instantiated and called as such:\n * var obj = PeekingIterator(arr)\n * var param_1 = obj.next()\n * var param_2 = obj.peek()\n * var param_3 = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "// PHP ArrayIterator reference:\n// https://www.php.net/arrayiterator\n\nclass PeekingIterator {\n /**\n * @param ArrayIterator $arr\n */\n function __construct($arr) {\n \n }\n \n /**\n * @return Integer\n */\n function next() {\n \n }\n \n /**\n * @return Integer\n */\n function peek() {\n \n }\n \n /**\n * @return Boolean\n */\n function hasNext() {\n \n }\n}\n\n/**\n * Your PeekingIterator object will be instantiated and called as such:\n * $obj = PeekingIterator($arr);\n * $ret_1 = $obj->next();\n * $ret_2 = $obj->peek();\n * $ret_3 = $obj->hasNext();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * // This is the Iterator's API interface.\n * // You should not implement it, or speculate about its implementation\n * class Iterator {\n * hasNext(): boolean {}\n *\n * next(): number {}\n * }\n */\n\nclass PeekingIterator {\n constructor(iterator: Iterator) {\n\n }\n\n peek(): number {\n\n }\n\n next(): number {\n\n }\n\n hasNext(): boolean {\n\n }\n}\n\n/**\n * Your PeekingIterator object will be instantiated and called as such:\n * var obj = new PeekingIterator(iterator)\n * var param_1 = obj.peek()\n * var param_2 = obj.next()\n * var param_3 = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0284](https://leetcode-cn.com/problems/peeking-iterator)", "[\u9876\u7aef\u8fed\u4ee3\u5668](/solution/0200-0299/0284.Peeking%20Iterator/README.md)", "`\u8bbe\u8ba1`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0284](https://leetcode.com/problems/peeking-iterator)", "[Peeking Iterator](/solution/0200-0299/0284.Peeking%20Iterator/README_EN.md)", "`Design`", "Medium", ""]}, {"question_id": "0283", "frontend_question_id": "0283", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/move-zeroes", "url_en": "https://leetcode.com/problems/move-zeroes", "relative_path_cn": "/solution/0200-0299/0283.Move%20Zeroes/README.md", "relative_path_en": "/solution/0200-0299/0283.Move%20Zeroes/README_EN.md", "title_cn": "\u79fb\u52a8\u96f6", "title_en": "Move Zeroes", "question_title_slug": "move-zeroes", "content_en": "

    Given an integer array nums, move all 0's to the end of it while maintaining the relative order of the non-zero elements.

    \n\n

    Note that you must do this in-place without making a copy of the array.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [0,1,0,3,12]\nOutput: [1,3,12,0,0]\n

    Example 2:

    \n
    Input: nums = [0]\nOutput: [0]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 104
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n
    \n\n

     

    \nFollow up: Could you minimize the total number of operations done?", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6570\u7ec4 nums\uff0c\u7f16\u5199\u4e00\u4e2a\u51fd\u6570\u5c06\u6240\u6709 0 \u79fb\u52a8\u5230\u6570\u7ec4\u7684\u672b\u5c3e\uff0c\u540c\u65f6\u4fdd\u6301\u975e\u96f6\u5143\u7d20\u7684\u76f8\u5bf9\u987a\u5e8f\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: [0,1,0,3,12]\n\u8f93\u51fa: [1,3,12,0,0]
    \n\n

    \u8bf4\u660e:

    \n\n
      \n\t
    1. \u5fc5\u987b\u5728\u539f\u6570\u7ec4\u4e0a\u64cd\u4f5c\uff0c\u4e0d\u80fd\u62f7\u8d1d\u989d\u5916\u7684\u6570\u7ec4\u3002
    2. \n\t
    3. \u5c3d\u91cf\u51cf\u5c11\u64cd\u4f5c\u6b21\u6570\u3002
    4. \n
    \n", "tags_en": ["Array", "Two Pointers"], "tags_cn": ["\u6570\u7ec4", "\u53cc\u6307\u9488"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n void moveZeroes(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public void moveZeroes(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def moveZeroes(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: None Do not return anything, modify nums in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def moveZeroes(self, nums: List[int]) -> None:\n \"\"\"\n Do not return anything, modify nums in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nvoid moveZeroes(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public void MoveZeroes(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {void} Do not return anything, modify nums in-place instead.\n */\nvar moveZeroes = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Void} Do not return anything, modify nums in-place instead.\ndef move_zeroes(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func moveZeroes(_ nums: inout [Int]) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func moveZeroes(nums []int) {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def moveZeroes(nums: Array[Int]): Unit = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun moveZeroes(nums: IntArray): Unit {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn move_zeroes(nums: &mut Vec) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return NULL\n */\n function moveZeroes(&$nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n Do not return anything, modify nums in-place instead.\n */\nfunction moveZeroes(nums: number[]): void {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (move-zeroes nums)\n (-> (listof exact-integer?) void?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0283](https://leetcode-cn.com/problems/move-zeroes)", "[\u79fb\u52a8\u96f6](/solution/0200-0299/0283.Move%20Zeroes/README.md)", "`\u6570\u7ec4`,`\u53cc\u6307\u9488`", "\u7b80\u5355", ""], "md_table_row_en": ["[0283](https://leetcode.com/problems/move-zeroes)", "[Move Zeroes](/solution/0200-0299/0283.Move%20Zeroes/README_EN.md)", "`Array`,`Two Pointers`", "Easy", ""]}, {"question_id": "0282", "frontend_question_id": "0282", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/expression-add-operators", "url_en": "https://leetcode.com/problems/expression-add-operators", "relative_path_cn": "/solution/0200-0299/0282.Expression%20Add%20Operators/README.md", "relative_path_en": "/solution/0200-0299/0282.Expression%20Add%20Operators/README_EN.md", "title_cn": "\u7ed9\u8868\u8fbe\u5f0f\u6dfb\u52a0\u8fd0\u7b97\u7b26", "title_en": "Expression Add Operators", "question_title_slug": "expression-add-operators", "content_en": "

    Given a string num that contains only digits and an integer target, return all possibilities to add the binary operators '+', '-', or '*' between the digits of num so that the resultant expression evaluates to the target value.

    \n\n

     

    \n

    Example 1:

    \n
    Input: num = \"123\", target = 6\nOutput: [\"1*2*3\",\"1+2+3\"]\n

    Example 2:

    \n
    Input: num = \"232\", target = 8\nOutput: [\"2*3+2\",\"2+3*2\"]\n

    Example 3:

    \n
    Input: num = \"105\", target = 5\nOutput: [\"1*0+5\",\"10-5\"]\n

    Example 4:

    \n
    Input: num = \"00\", target = 0\nOutput: [\"0*0\",\"0+0\",\"0-0\"]\n

    Example 5:

    \n
    Input: num = \"3456237490\", target = 9191\nOutput: []\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= num.length <= 10
    • \n\t
    • num consists of only digits.
    • \n\t
    • -231 <= target <= 231 - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4ec5\u5305\u542b\u6570\u5b57\u00a00-9\u00a0\u7684\u5b57\u7b26\u4e32\u548c\u4e00\u4e2a\u76ee\u6807\u503c\uff0c\u5728\u6570\u5b57\u4e4b\u95f4\u6dfb\u52a0 \u4e8c\u5143 \u8fd0\u7b97\u7b26\uff08\u4e0d\u662f\u4e00\u5143\uff09+\u3001-\u00a0\u6216\u00a0*\u00a0\uff0c\u8fd4\u56de\u6240\u6709\u80fd\u591f\u5f97\u5230\u76ee\u6807\u503c\u7684\u8868\u8fbe\u5f0f\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: num = \"123\", target = 6\n\u8f93\u51fa: [\"1+2+3\", \"1*2*3\"] \n
    \n\n

    \u793a\u4f8b\u00a02:

    \n\n
    \n\u8f93\u5165: num = \"232\", target = 8\n\u8f93\u51fa: [\"2*3+2\", \"2+3*2\"]
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \n\u8f93\u5165: num = \"105\", target = 5\n\u8f93\u51fa: [\"1*0+5\",\"10-5\"]
    \n\n

    \u793a\u4f8b\u00a04:

    \n\n
    \n\u8f93\u5165: num = \"00\", target = 0\n\u8f93\u51fa: [\"0+0\", \"0-0\", \"0*0\"]\n
    \n\n

    \u793a\u4f8b 5:

    \n\n
    \n\u8f93\u5165: num = \"3456237490\", target = 9191\n\u8f93\u51fa: []
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= num.length <= 10
    • \n\t
    • num \u4ec5\u542b\u6570\u5b57
    • \n
    \n", "tags_en": ["Divide and Conquer"], "tags_cn": ["\u5206\u6cbb\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector addOperators(string num, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List addOperators(String num, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def addOperators(self, num, target):\n \"\"\"\n :type num: str\n :type target: int\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def addOperators(self, num: str, target: int) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** addOperators(char * num, int target, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList AddOperators(string num, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} num\n * @param {number} target\n * @return {string[]}\n */\nvar addOperators = function(num, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} num\n# @param {Integer} target\n# @return {String[]}\ndef add_operators(num, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func addOperators(_ num: String, _ target: Int) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func addOperators(num string, target int) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def addOperators(num: String, target: Int): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun addOperators(num: String, target: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn add_operators(num: String, target: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $num\n * @param Integer $target\n * @return String[]\n */\n function addOperators($num, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function addOperators(num: string, target: number): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (add-operators num target)\n (-> string? exact-integer? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0282](https://leetcode-cn.com/problems/expression-add-operators)", "[\u7ed9\u8868\u8fbe\u5f0f\u6dfb\u52a0\u8fd0\u7b97\u7b26](/solution/0200-0299/0282.Expression%20Add%20Operators/README.md)", "`\u5206\u6cbb\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[0282](https://leetcode.com/problems/expression-add-operators)", "[Expression Add Operators](/solution/0200-0299/0282.Expression%20Add%20Operators/README_EN.md)", "`Divide and Conquer`", "Hard", ""]}, {"question_id": "0281", "frontend_question_id": "0281", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/zigzag-iterator", "url_en": "https://leetcode.com/problems/zigzag-iterator", "relative_path_cn": "/solution/0200-0299/0281.Zigzag%20Iterator/README.md", "relative_path_en": "/solution/0200-0299/0281.Zigzag%20Iterator/README_EN.md", "title_cn": "\u952f\u9f7f\u8fed\u4ee3\u5668", "title_en": "Zigzag Iterator", "question_title_slug": "zigzag-iterator", "content_en": "

    Given two vectors of integers v1 and v2, implement an iterator to return their elements alternately.

    \n\n

    Implement the ZigzagIterator class:

    \n\n
      \n\t
    • ZigzagIterator(List<int> v1, List<int> v2) initializes the object with the two vectors v1 and v2.
    • \n\t
    • boolean hasNext() returns true if the iterator still has elements, and false otherwise.
    • \n\t
    • int next() returns the current element of the iterator and moves the iterator to the next element.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: v1 = [1,2], v2 = [3,4,5,6]\nOutput: [1,3,2,4,5,6]\nExplanation: By calling next repeatedly until hasNext returns false, the order of elements returned by next should be: [1,3,2,4,5,6].\n
    \n\n

    Example 2:

    \n\n
    \nInput: v1 = [1], v2 = []\nOutput: [1]\n
    \n\n

    Example 3:

    \n\n
    \nInput: v1 = [], v2 = [1]\nOutput: [1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= v1.length, v2.length <= 1000
    • \n\t
    • 1 <= v1.length + v2.length <= 2000
    • \n\t
    • -231 <= v1[i], v2[i] <= 231 - 1
    • \n
    \n\n

     

    \n

    Follow up: What if you are given k vectors? How well can your code be extended to such cases?

    \n\n

    Clarification for the follow-up question:

    \n\n

    The "Zigzag" order is not clearly defined and is ambiguous for k > 2 cases. If "Zigzag" does not look right to you, replace "Zigzag" with "Cyclic".

    \n\n

    Example:

    \n\n
    \nInput: v1 = [1,2,3], v2 = [4,5,6,7], v3 = [8,9]\nOutput: [1,4,8,2,5,9,3,6,7]\n
    \n", "content_cn": "

    \u7ed9\u51fa\u4e24\u4e2a\u4e00\u7ef4\u7684\u5411\u91cf\uff0c\u8bf7\u4f60\u5b9e\u73b0\u4e00\u4e2a\u8fed\u4ee3\u5668\uff0c\u4ea4\u66ff\u8fd4\u56de\u5b83\u4eec\u4e2d\u95f4\u7684\u5143\u7d20\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165:\nv1 = [1,2]\nv2 = [3,4,5,6] \n\n\u8f93\u51fa: [1,3,2,4,5,6]\n\n\u89e3\u6790: \u901a\u8fc7\u8fde\u7eed\u8c03\u7528 next \u51fd\u6570\u76f4\u5230 hasNext \u51fd\u6570\u8fd4\u56de false\uff0c\n     next \u51fd\u6570\u8fd4\u56de\u503c\u7684\u6b21\u5e8f\u5e94\u4f9d\u6b21\u4e3a: [1,3,2,4,5,6]\u3002
    \n\n

    \u62d3\u5c55\uff1a\u5047\u5982\u7ed9\u4f60 k \u4e2a\u4e00\u7ef4\u5411\u91cf\u5462\uff1f\u4f60\u7684\u4ee3\u7801\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\u7684\u6269\u5c55\u6027\u53c8\u4f1a\u5982\u4f55\u5462?

    \n\n

    \u62d3\u5c55\u58f0\u660e\uff1a
    \n “\u952f\u9f7f” \u987a\u5e8f\u5bf9\u4e8e k > 2 \u7684\u60c5\u51b5\u5b9a\u4e49\u53ef\u80fd\u4f1a\u6709\u4e9b\u6b67\u4e49\u3002\u6240\u4ee5\uff0c\u5047\u5982\u4f60\u89c9\u5f97 “\u952f\u9f7f” \u8fd9\u4e2a\u8868\u8ff0\u4e0d\u59a5\uff0c\u4e5f\u53ef\u4ee5\u8ba4\u4e3a\u8fd9\u662f\u4e00\u79cd “\u5faa\u73af”\u3002\u4f8b\u5982\uff1a

    \n\n
    \u8f93\u5165:\n[1,2,3]\n[4,5,6,7]\n[8,9]\n\n\u8f93\u51fa: [1,4,8,2,5,9,3,6,7].\n
    \n", "tags_en": ["Design"], "tags_cn": ["\u8bbe\u8ba1"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class ZigzagIterator {\npublic:\n ZigzagIterator(vector& v1, vector& v2) {\n \n }\n\n int next() {\n \n }\n\n bool hasNext() {\n \n }\n};\n\n/**\n * Your ZigzagIterator object will be instantiated and called as such:\n * ZigzagIterator i(v1, v2);\n * while (i.hasNext()) cout << i.next();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "public class ZigzagIterator {\n\n public ZigzagIterator(List v1, List v2) {\n \n }\n\n public int next() {\n \n }\n\n public boolean hasNext() {\n \n }\n}\n\n/**\n * Your ZigzagIterator object will be instantiated and called as such:\n * ZigzagIterator i = new ZigzagIterator(v1, v2);\n * while (i.hasNext()) v[f()] = i.next();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class ZigzagIterator(object):\n\n def __init__(self, v1, v2):\n \"\"\"\n Initialize your data structure here.\n :type v1: List[int]\n :type v2: List[int]\n \"\"\"\n \n\n def next(self):\n \"\"\"\n :rtype: int\n \"\"\"\n \n\n def hasNext(self):\n \"\"\"\n :rtype: bool\n \"\"\"\n \n\n# Your ZigzagIterator object will be instantiated and called as such:\n# i, v = ZigzagIterator(v1, v2), []\n# while i.hasNext(): v.append(i.next())", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class ZigzagIterator:\n def __init__(self, v1: List[int], v2: List[int]):\n \n\n def next(self) -> int:\n \n\n def hasNext(self) -> bool:\n \n\n# Your ZigzagIterator object will be instantiated and called as such:\n# i, v = ZigzagIterator(v1, v2), []\n# while i.hasNext(): v.append(i.next())", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "struct ZigzagIterator {\n \n};\n\nstruct ZigzagIterator *zigzagIteratorCreate(int* v1, int v1Size, int* v2, int v2Size) {\n \n}\n\nbool zigzagIteratorHasNext(struct ZigzagIterator *iter) {\n \n}\n\nint zigzagIteratorNext(struct ZigzagIterator *iter) {\n \n}\n\n/** Deallocates memory previously allocated for the iterator */\nvoid zigzagIteratorFree(struct ZigzagIterator *iter) {\n \n}\n\n/**\n * Your ZigzagIterator will be called like this:\n * struct ZigzagIterator *i = zigzagIteratorCreate(v1, v1Size, v2, v2Size);\n * while (zigzagIteratorHasNext(i)) printf(\"%d\\n\", zigzagIteratorNext(i));\n * zigzagIteratorFree(i);\n */", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class ZigzagIterator {\n\n public ZigzagIterator(IList v1, IList v2) {\n \n }\n\n public bool HasNext() {\n \n }\n\n public int Next() {\n \n }\n}\n\n/**\n * Your ZigzagIterator will be called like this:\n * ZigzagIterator i = new ZigzagIterator(v1, v2);\n * while (i.HasNext()) v[f()] = i.Next();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @constructor\n * @param {Integer[]} v1\n * @param {Integer[]} v1\n */\nvar ZigzagIterator = function ZigzagIterator(v1, v2) {\n \n};\n\n\n/**\n * @this ZigzagIterator\n * @returns {boolean}\n */\nZigzagIterator.prototype.hasNext = function hasNext() {\n \n};\n\n/**\n * @this ZigzagIterator\n * @returns {integer}\n */\nZigzagIterator.prototype.next = function next() {\n \n};\n\n/**\n * Your ZigzagIterator will be called like this:\n * var i = new ZigzagIterator(v1, v2), a = [];\n * while (i.hasNext()) a.push(i.next());\n*/", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class ZigzagIterator\n # @param {Integer[]} v1\n # @param {Integer[]} v2\n def initialize(v1, v2)\n \n end\n\n # @return {Boolean}\n def has_next\n \n end\n\n # @return {Integer}\n def next\n \n end\nend\n\n# Your ZigzagIterator will be called like this:\n# i, v = ZigzagIterator.new(v1, v2), []\n# while i.has_next()\n# v << i.next\n# end", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class ZigzagIterator {\n init(_ v1: [Int], _ v2: [Int]) {\n \n }\n \n func next() -> Int {\n \n }\n \n func hasNext() -> Bool {\n \n }\n}\n\n// Your ZigzagIterator object will be instantiated and called as such:\n// var i = ZigzagIterator(v1, v2)\n// var ret = [Int]()\n// while i.hasNext() {\n// \t\tret.append(i.next())\n// }", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type ZigzagIterator struct {\n \n}\n\nfunc Constructor(v1, v2 []int) *ZigzagIterator {\n \n}\n\nfunc (this *ZigzagIterator) next() int {\n \n}\n\nfunc (this *ZigzagIterator) hasNext() bool {\n\t\n}\n\n/**\n * Your ZigzagIterator object will be instantiated and called as such:\n * obj := Constructor(param_1, param_2);\n * for obj.hasNext() {\n *\t ans = append(ans, obj.next())\n * }\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class ZigzagIterator(_v1: Array[Int], _v2: Array[Int]) {\n /** initialize your data structure here. */\n \n def next(): Int = {\n \n }\n \n def hasNext(): Boolean = {\n \n }\n}\n\n/**\n * Your ZigzagIterator object will be instantiated and called as such:\n * var obj = new ZigzagIterator(v1, v2)\n * while (obj.hasNext()) {\n * ans += obj.next()\n * }\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class ZigzagIterator {\n constructor(v1: IntArray, v2: IntArray) {\n \n }\n \n fun next(): Int {\n \n }\n \n fun hasNext(): Boolean {\n \n }\n}\n\n// Your ZigzagIterator object will be instantiated and called as such:\n// var i = ZigzagIterator(v1, v2)\n// var ret = ArrayList()\n// while(i.hasNext()){\n//\t\tret.add(i.next())\n// }", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct ZigzagIterator {\n \n}\n\n/** \n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl ZigzagIterator {\n /** initialize your data structure here. */\n \n fn new(v1: Vec, v2: Vec) -> Self {\n \n }\n \n fn next(&self) -> i32 {\n \n }\n \n fn has_next(&self) -> bool {\n \n }\n}\n\n/**\n * Your ZigzagIterator object will be instantiated and called as such:\n * let obj = ZigzagIterator::new(v1, v2);\n * let ret_1: i32 = obj.next();\n * let ret_2: bool = obj.has_next();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class ZigzagIterator {\n /**\n * Initialize your data structure here.\n * @param Integer[] $v1\n * @param Integer[] $v2\n */\n function __construct($v1, $v2) {\n \n }\n \n /**\n * @return Integer\n */\n function next() {\n \n }\n \n /**\n * @return Boolean\n */\n function hasNext() {\n \n }\n}\n\n/**\n * Your ZigzagIterator object will be instantiated and called as such:\n * $obj = ZigzagIterator($v1, $v2);\n * while ($obj->hasNext()) {\n * array_push($ans, $obj->next())\n * }\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class ZigzagIterator {\n constructor(v1: number[], v2: number[]) {\n\t\t\n }\n\n next(): number {\n\t\t\n }\n\n hasNext(): boolean {\n\t\t\n }\n}\n\n/**\n * Your PeekingIterator object will be instantiated and called as such:\n * var obj = new PeekingIterator(iterator)\n * while (obj.hasNext()) ret.push(obj.next());\n */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0281](https://leetcode-cn.com/problems/zigzag-iterator)", "[\u952f\u9f7f\u8fed\u4ee3\u5668](/solution/0200-0299/0281.Zigzag%20Iterator/README.md)", "`\u8bbe\u8ba1`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0281](https://leetcode.com/problems/zigzag-iterator)", "[Zigzag Iterator](/solution/0200-0299/0281.Zigzag%20Iterator/README_EN.md)", "`Design`", "Medium", "\ud83d\udd12"]}, {"question_id": "0280", "frontend_question_id": "0280", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/wiggle-sort", "url_en": "https://leetcode.com/problems/wiggle-sort", "relative_path_cn": "/solution/0200-0299/0280.Wiggle%20Sort/README.md", "relative_path_en": "/solution/0200-0299/0280.Wiggle%20Sort/README_EN.md", "title_cn": "\u6446\u52a8\u6392\u5e8f", "title_en": "Wiggle Sort", "question_title_slug": "wiggle-sort", "content_en": "

    Given an integer array nums, reorder it such that nums[0] <= nums[1] >= nums[2] <= nums[3]....

    \n\n

    You may assume the input array always has a valid answer.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [3,5,2,1,6,4]\nOutput: [3,5,1,6,2,4]\nExplanation: [1,6,2,5,3,4] is also accepted.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [6,6,5,6,3,8]\nOutput: [6,6,5,6,3,8]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 5 * 104
    • \n\t
    • 0 <= nums[i] <= 104
    • \n\t
    • It is guaranteed that there will be an answer for the given input nums.
    • \n
    \n\n

     

    \nFollow up: Could you do it without sorting the array?", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u65e0\u5e8f\u7684\u6570\u7ec4 nums, \u5c06\u8be5\u6570\u5b57 \u539f\u5730 \u91cd\u6392\u540e\u4f7f\u5f97 nums[0] <= nums[1] >= nums[2] <= nums[3]...\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: nums = [3,5,2,1,6,4]\n\u8f93\u51fa: \u4e00\u4e2a\u53ef\u80fd\u7684\u89e3\u7b54\u662f [3,5,1,6,2,4]
    \n", "tags_en": ["Sort", "Array"], "tags_cn": ["\u6392\u5e8f", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n void wiggleSort(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public void wiggleSort(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def wiggleSort(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: None Do not return anything, modify nums in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def wiggleSort(self, nums: List[int]) -> None:\n \"\"\"\n Do not return anything, modify nums in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nvoid wiggleSort(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public void WiggleSort(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {void} Do not return anything, modify nums in-place instead.\n */\nvar wiggleSort = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Void} Do not return anything, modify nums in-place instead.\ndef wiggle_sort(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func wiggleSort(_ nums: inout [Int]) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func wiggleSort(nums []int) {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def wiggleSort(nums: Array[Int]): Unit = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun wiggleSort(nums: IntArray): Unit {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn wiggle_sort(nums: &mut Vec) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return NULL\n */\n function wiggleSort(&$nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n Do not return anything, modify nums in-place instead.\n */\nfunction wiggleSort(nums: number[]): void {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (wiggle-sort nums)\n (-> (listof exact-integer?) void?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0280](https://leetcode-cn.com/problems/wiggle-sort)", "[\u6446\u52a8\u6392\u5e8f](/solution/0200-0299/0280.Wiggle%20Sort/README.md)", "`\u6392\u5e8f`,`\u6570\u7ec4`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0280](https://leetcode.com/problems/wiggle-sort)", "[Wiggle Sort](/solution/0200-0299/0280.Wiggle%20Sort/README_EN.md)", "`Sort`,`Array`", "Medium", "\ud83d\udd12"]}, {"question_id": "0279", "frontend_question_id": "0279", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/perfect-squares", "url_en": "https://leetcode.com/problems/perfect-squares", "relative_path_cn": "/solution/0200-0299/0279.Perfect%20Squares/README.md", "relative_path_en": "/solution/0200-0299/0279.Perfect%20Squares/README_EN.md", "title_cn": "\u5b8c\u5168\u5e73\u65b9\u6570", "title_en": "Perfect Squares", "question_title_slug": "perfect-squares", "content_en": "

    Given an integer n, return the least number of perfect square numbers that sum to n.

    \n\n

    A perfect square is an integer that is the square of an integer; in other words, it is the product of some integer with itself. For example, 1, 4, 9, and 16 are perfect squares while 3 and 11 are not.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 12\nOutput: 3\nExplanation: 12 = 4 + 4 + 4.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 13\nOutput: 2\nExplanation: 13 = 4 + 9.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u6b63\u6574\u6570\u00a0n\uff0c\u627e\u5230\u82e5\u5e72\u4e2a\u5b8c\u5168\u5e73\u65b9\u6570\uff08\u6bd4\u5982\u00a01, 4, 9, 16, ...\uff09\u4f7f\u5f97\u5b83\u4eec\u7684\u548c\u7b49\u4e8e n\u3002\u4f60\u9700\u8981\u8ba9\u7ec4\u6210\u548c\u7684\u5b8c\u5168\u5e73\u65b9\u6570\u7684\u4e2a\u6570\u6700\u5c11\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n \uff0c\u8fd4\u56de\u548c\u4e3a n \u7684\u5b8c\u5168\u5e73\u65b9\u6570\u7684 \u6700\u5c11\u6570\u91cf \u3002

    \n\n

    \u5b8c\u5168\u5e73\u65b9\u6570 \u662f\u4e00\u4e2a\u6574\u6570\uff0c\u5176\u503c\u7b49\u4e8e\u53e6\u4e00\u4e2a\u6574\u6570\u7684\u5e73\u65b9\uff1b\u6362\u53e5\u8bdd\u8bf4\uff0c\u5176\u503c\u7b49\u4e8e\u4e00\u4e2a\u6574\u6570\u81ea\u4e58\u7684\u79ef\u3002\u4f8b\u5982\uff0c1\u30014\u30019 \u548c 16 \u90fd\u662f\u5b8c\u5168\u5e73\u65b9\u6570\uff0c\u800c 3 \u548c 11 \u4e0d\u662f\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\u00a01\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 12\n\u8f93\u51fa\uff1a3 \n\u89e3\u91ca\uff1a12 = 4 + 4 + 4
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 13\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a13 = 4 + 9
    \n\u00a0\n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 104
    • \n
    \n", "tags_en": ["Breadth-first Search", "Math", "Dynamic Programming"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u6570\u5b66", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numSquares(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numSquares(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numSquares(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numSquares(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numSquares(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumSquares(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar numSquares = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef num_squares(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numSquares(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numSquares(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numSquares(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numSquares(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_squares(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function numSquares($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numSquares(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-squares n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0279](https://leetcode-cn.com/problems/perfect-squares)", "[\u5b8c\u5168\u5e73\u65b9\u6570](/solution/0200-0299/0279.Perfect%20Squares/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u6570\u5b66`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0279](https://leetcode.com/problems/perfect-squares)", "[Perfect Squares](/solution/0200-0299/0279.Perfect%20Squares/README_EN.md)", "`Breadth-first Search`,`Math`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0278", "frontend_question_id": "0278", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/first-bad-version", "url_en": "https://leetcode.com/problems/first-bad-version", "relative_path_cn": "/solution/0200-0299/0278.First%20Bad%20Version/README.md", "relative_path_en": "/solution/0200-0299/0278.First%20Bad%20Version/README_EN.md", "title_cn": "\u7b2c\u4e00\u4e2a\u9519\u8bef\u7684\u7248\u672c", "title_en": "First Bad Version", "question_title_slug": "first-bad-version", "content_en": "

    You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the previous version, all the versions after a bad version are also bad.

    \n\n

    Suppose you have n versions [1, 2, ..., n] and you want to find out the first bad one, which causes all the following ones to be bad.

    \n\n

    You are given an API bool isBadVersion(version) which returns whether version is bad. Implement a function to find the first bad version. You should minimize the number of calls to the API.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 5, bad = 4\nOutput: 4\nExplanation:\ncall isBadVersion(3) -> false\ncall isBadVersion(5) -> true\ncall isBadVersion(4) -> true\nThen 4 is the first bad version.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 1, bad = 1\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= bad <= n <= 231 - 1
    • \n
    \n", "content_cn": "

    \u4f60\u662f\u4ea7\u54c1\u7ecf\u7406\uff0c\u76ee\u524d\u6b63\u5728\u5e26\u9886\u4e00\u4e2a\u56e2\u961f\u5f00\u53d1\u65b0\u7684\u4ea7\u54c1\u3002\u4e0d\u5e78\u7684\u662f\uff0c\u4f60\u7684\u4ea7\u54c1\u7684\u6700\u65b0\u7248\u672c\u6ca1\u6709\u901a\u8fc7\u8d28\u91cf\u68c0\u6d4b\u3002\u7531\u4e8e\u6bcf\u4e2a\u7248\u672c\u90fd\u662f\u57fa\u4e8e\u4e4b\u524d\u7684\u7248\u672c\u5f00\u53d1\u7684\uff0c\u6240\u4ee5\u9519\u8bef\u7684\u7248\u672c\u4e4b\u540e\u7684\u6240\u6709\u7248\u672c\u90fd\u662f\u9519\u7684\u3002

    \n\n

    \u5047\u8bbe\u4f60\u6709 n \u4e2a\u7248\u672c [1, 2, ..., n]\uff0c\u4f60\u60f3\u627e\u51fa\u5bfc\u81f4\u4e4b\u540e\u6240\u6709\u7248\u672c\u51fa\u9519\u7684\u7b2c\u4e00\u4e2a\u9519\u8bef\u7684\u7248\u672c\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u901a\u8fc7\u8c03\u7528 bool isBadVersion(version) \u63a5\u53e3\u6765\u5224\u65ad\u7248\u672c\u53f7 version \u662f\u5426\u5728\u5355\u5143\u6d4b\u8bd5\u4e2d\u51fa\u9519\u3002\u5b9e\u73b0\u4e00\u4e2a\u51fd\u6570\u6765\u67e5\u627e\u7b2c\u4e00\u4e2a\u9519\u8bef\u7684\u7248\u672c\u3002\u4f60\u5e94\u8be5\u5c3d\u91cf\u51cf\u5c11\u5bf9\u8c03\u7528 API \u7684\u6b21\u6570\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u7ed9\u5b9a n = 5\uff0c\u5e76\u4e14 version = 4 \u662f\u7b2c\u4e00\u4e2a\u9519\u8bef\u7684\u7248\u672c\u3002\n\n\u8c03\u7528 isBadVersion(3) -> false\n\u8c03\u7528 isBadVersion(5) -> true\n\u8c03\u7528 isBadVersion(4) -> true\n\n\u6240\u4ee5\uff0c4 \u662f\u7b2c\u4e00\u4e2a\u9519\u8bef\u7684\u7248\u672c\u3002 
    \n", "tags_en": ["Binary Search"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "// The API isBadVersion is defined for you.\n// bool isBadVersion(int version);\n\nclass Solution {\npublic:\n int firstBadVersion(int n) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/* The isBadVersion API is defined in the parent class VersionControl.\n boolean isBadVersion(int version); */\n\npublic class Solution extends VersionControl {\n public int firstBadVersion(int n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# The isBadVersion API is already defined for you.\n# @param version, an integer\n# @return a bool\n# def isBadVersion(version):\n\nclass Solution(object):\n def firstBadVersion(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# The isBadVersion API is already defined for you.\n# @param version, an integer\n# @return an integer\n# def isBadVersion(version):\n\nclass Solution:\n def firstBadVersion(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "// The API isBadVersion is defined for you.\n// bool isBadVersion(int version);\n\nint firstBadVersion(int n) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/* The isBadVersion API is defined in the parent class VersionControl.\n bool IsBadVersion(int version); */\n\npublic class Solution : VersionControl {\n public int FirstBadVersion(int n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for isBadVersion()\n * \n * @param {integer} version number\n * @return {boolean} whether the version is bad\n * isBadVersion = function(version) {\n * ...\n * };\n */\n\n/**\n * @param {function} isBadVersion()\n * @return {function}\n */\nvar solution = function(isBadVersion) {\n /**\n * @param {integer} n Total versions\n * @return {integer} The first bad version\n */\n return function(n) {\n \n };\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# The is_bad_version API is already defined for you.\n# @param {Integer} version\n# @return {boolean} whether the version is bad\n# def is_bad_version(version):\n\n# @param {Integer} n\n# @return {Integer}\ndef first_bad_version(n)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * The knows API is defined in the parent class VersionControl.\n * func isBadVersion(_ version: Int) -> Bool{}\n */\n\nclass Solution : VersionControl {\n func firstBadVersion(_ n: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/** \n * Forward declaration of isBadVersion API.\n * @param version your guess about first bad version\n * @return \t \t true if current version is bad \n *\t\t\t false if current version is good\n * func isBadVersion(version int) bool;\n */\n\nfunc firstBadVersion(n int) int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/* The isBadVersion API is defined in the parent class VersionControl.\n def isBadVersion(version: Int): Boolean = {} */\n\nclass Solution extends VersionControl {\n def firstBadVersion(n: Int): Int = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/* The isBadVersion API is defined in the parent class VersionControl.\n def isBadVersion(version: Int): Boolean = {} */\n\nclass Solution: VersionControl() {\n override fun firstBadVersion(n: Int) : Int {\n \n\t}\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// The API isBadVersion is defined for you.\n// isBadVersion(versions:i32)-> bool;\n// to call it use self.isBadVersion(versions)\n\nimpl Solution {\n pub fn first_bad_version(&self, n: i32) -> i32 {\n\t\t\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/* The isBadVersion API is defined in the parent class VersionControl.\n public function isBadVersion($version){} */\n\nclass Solution extends VersionControl {\n /**\n * @param Integer $n\n * @return Integer\n */\n function firstBadVersion($n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * The knows API is defined in the parent class Relation.\n * isBadVersion(version: number): boolean {\n * ...\n * };\n */\n\nvar solution = function(isBadVersion: any) {\n\n return function(n: number): number {\n \n };\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0278](https://leetcode-cn.com/problems/first-bad-version)", "[\u7b2c\u4e00\u4e2a\u9519\u8bef\u7684\u7248\u672c](/solution/0200-0299/0278.First%20Bad%20Version/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u7b80\u5355", ""], "md_table_row_en": ["[0278](https://leetcode.com/problems/first-bad-version)", "[First Bad Version](/solution/0200-0299/0278.First%20Bad%20Version/README_EN.md)", "`Binary Search`", "Easy", ""]}, {"question_id": "0277", "frontend_question_id": "0277", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/find-the-celebrity", "url_en": "https://leetcode.com/problems/find-the-celebrity", "relative_path_cn": "/solution/0200-0299/0277.Find%20the%20Celebrity/README.md", "relative_path_en": "/solution/0200-0299/0277.Find%20the%20Celebrity/README_EN.md", "title_cn": "\u641c\u5bfb\u540d\u4eba", "title_en": "Find the Celebrity", "question_title_slug": "find-the-celebrity", "content_en": "

    Suppose you are at a party with n people (labeled from 0 to n - 1), and among them, there may exist one celebrity. The definition of a celebrity is that all the other n - 1 people know him/her, but he/she does not know any of them.

    \n\n

    Now you want to find out who the celebrity is or verify that there is not one. The only thing you are allowed to do is to ask questions like: "Hi, A. Do you know B?" to get information about whether A knows B. You need to find out the celebrity (or verify there is not one) by asking as few questions as possible (in the asymptotic sense).

    \n\n

    You are given a helper function bool knows(a, b) which tells you whether A knows B. Implement a function int findCelebrity(n). There will be exactly one celebrity if he/she is in the party. Return the celebrity's label if there is a celebrity in the party. If there is no celebrity, return -1.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: graph = [[1,1,0],[0,1,0],[1,1,1]]\nOutput: 1\nExplanation: There are three persons labeled with 0, 1 and 2. graph[i][j] = 1 means person i knows person j, otherwise graph[i][j] = 0 means person i does not know person j. The celebrity is the person labeled as 1 because both 0 and 2 know him but 1 does not know anybody.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: graph = [[1,0,1],[1,1,0],[0,1,1]]\nOutput: -1\nExplanation: There is no celebrity.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == graph.length
    • \n\t
    • n == graph[i].length
    • \n\t
    • 2 <= n <= 100
    • \n\t
    • graph[i][j] is 0 or 1.
    • \n\t
    • graph[i][i] == 1
    • \n
    \n\n

     

    \nFollow up: If the maximum number of allowed calls to the API knows is 3 * n, could you find a solution without exceeding the maximum number of calls?", "content_cn": "

    \u5047\u8bbe\u4f60\u662f\u4e00\u4e2a\u4e13\u4e1a\u7684\u72d7\u4ed4\uff0c\u53c2\u52a0\u4e86\u4e00\u4e2a\u00a0n\u00a0\u4eba\u6d3e\u5bf9\uff0c\u5176\u4e2d\u6bcf\u4e2a\u4eba\u88ab\u4ece\u00a00\u00a0\u5230\u00a0n - 1\u00a0\u6807\u53f7\u3002\u5728\u8fd9\u4e2a\u6d3e\u5bf9\u4eba\u7fa4\u5f53\u4e2d\u53ef\u80fd\u5b58\u5728\u4e00\u4f4d\u00a0\u201c\u540d\u4eba\u201d\u3002\u6240\u8c13 \u201c\u540d\u4eba\u201d \u7684\u5b9a\u4e49\u662f\uff1a\u5176\u4ed6\u6240\u6709\u00a0n - 1\u00a0\u4e2a\u4eba\u90fd\u8ba4\u8bc6\u4ed6/\u5979\uff0c\u800c\u4ed6/\u5979\u5e76\u4e0d\u8ba4\u8bc6\u5176\u4ed6\u4efb\u4f55\u4eba\u3002

    \n\n

    \u73b0\u5728\u4f60\u60f3\u8981\u786e\u8ba4\u8fd9\u4e2a \u201c\u540d\u4eba\u201d \u662f\u8c01\uff0c\u6216\u8005\u786e\u5b9a\u8fd9\u91cc\u6ca1\u6709\u00a0\u201c\u540d\u4eba\u201d\u3002\u800c\u4f60\u552f\u4e00\u80fd\u505a\u7684\u5c31\u662f\u95ee\u8bf8\u5982 \u201cA\u00a0\u4f60\u597d\u5440\uff0c\u8bf7\u95ee\u4f60\u8ba4\u4e0d\u8ba4\u8bc6\u00a0B\u5440\uff1f\u201d\u00a0\u7684\u95ee\u9898\uff0c\u4ee5\u786e\u5b9a A \u662f\u5426\u8ba4\u8bc6 B\u3002\u4f60\u9700\u8981\u5728\uff08\u6e10\u8fd1\u610f\u4e49\u4e0a\uff09\u5c3d\u53ef\u80fd\u5c11\u7684\u95ee\u9898\u5185\u6765\u786e\u5b9a\u8fd9\u4f4d \u201c\u540d\u4eba\u201d \u662f\u8c01\uff08\u6216\u8005\u786e\u5b9a\u8fd9\u91cc\u6ca1\u6709 \u201c\u540d\u4eba\u201d\uff09\u3002

    \n\n

    \u5728\u672c\u9898\u4e2d\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u8f85\u52a9\u51fd\u6570\u00a0bool knows(a, b)\u00a0\u83b7\u53d6\u5230 A\u00a0\u662f\u5426\u8ba4\u8bc6 B\u3002\u8bf7\u4f60\u6765\u5b9e\u73b0\u4e00\u4e2a\u51fd\u6570\u00a0int findCelebrity(n)\u3002

    \n\n

    \u6d3e\u5bf9\u6700\u591a\u53ea\u4f1a\u6709\u4e00\u4e2a \u201c\u540d\u4eba\u201d \u53c2\u52a0\u3002\u82e5\u00a0\u201c\u540d\u4eba\u201d \u5b58\u5728\uff0c\u8bf7\u8fd4\u56de\u4ed6/\u5979\u7684\u7f16\u53f7\uff1b\u82e5\u00a0\u201c\u540d\u4eba\u201d\u00a0\u4e0d\u5b58\u5728\uff0c\u8bf7\u8fd4\u56de\u00a0-1\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1:

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165: graph = [\n\u00a0 [1,1,0],\n\u00a0 [0,1,0],\n\u00a0 [1,1,1]\n]\n\u8f93\u51fa: 1\n\u89e3\u91ca: \u6709\u7f16\u53f7\u5206\u522b\u4e3a 0\u30011 \u548c 2 \u7684\u4e09\u4e2a\u4eba\u3002graph[i][j] = 1 \u4ee3\u8868\u7f16\u53f7\u4e3a i \u7684\u4eba\u8ba4\u8bc6\u7f16\u53f7\u4e3a j \u7684\u4eba\uff0c\u800c graph[i][j] = 0 \u5219\u4ee3\u8868\u7f16\u53f7\u4e3a i \u7684\u4eba\u4e0d\u8ba4\u8bc6\u7f16\u53f7\u4e3a j \u7684\u4eba\u3002\u201c\u540d\u4eba\u201d \u662f\u7f16\u53f7 1 \u7684\u4eba\uff0c\u56e0\u4e3a 0 \u548c 2 \u5747\u8ba4\u8bc6\u4ed6/\u5979\uff0c\u4f46 1 \u4e0d\u8ba4\u8bc6\u4efb\u4f55\u4eba\u3002\n
    \n\n

    \u793a\u4f8b\u00a02:

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165: graph = [\n\u00a0 [1,0,1],\n\u00a0 [1,1,0],\n\u00a0 [0,1,1]\n]\n\u8f93\u51fa: -1\n\u89e3\u91ca: \u6ca1\u6709 \u201c\u540d\u4eba\u201d\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == graph.length
    • \n\t
    • n == graph[i].length
    • \n\t
    • 2 <= n <= 100
    • \n\t
    • graph[i][j] \u662f 0 \u6216 1.
    • \n\t
    • graph[i][i] == 1
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u5982\u679c\u5141\u8bb8\u8c03\u7528 API knows \u7684\u6700\u5927\u6b21\u6570\u4e3a 3 * n \uff0c\u4f60\u53ef\u4ee5\u8bbe\u8ba1\u4e00\u4e2a\u4e0d\u8d85\u8fc7\u6700\u5927\u8c03\u7528\u6b21\u6570\u7684\u89e3\u51b3\u65b9\u6848\u5417\uff1f

    \n\n
      \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/* The knows API is defined for you.\n bool knows(int a, int b); */\n\nclass Solution {\npublic:\n int findCelebrity(int n) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/* The knows API is defined in the parent class Relation.\n boolean knows(int a, int b); */\n\npublic class Solution extends Relation {\n public int findCelebrity(int n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# The knows API is already defined for you.\n# @param a, person a\n# @param b, person b\n# @return a boolean, whether a knows b\n# def knows(a, b):\n\nclass Solution(object):\n def findCelebrity(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# The knows API is already defined for you.\n# return a bool, whether a knows b\n# def knows(a: int, b: int) -> bool:\n\nclass Solution:\n def findCelebrity(self, n: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/* The knows API is defined for you.\n bool knows(int a, int b); */\n\nint findCelebrity(int n) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/* The Knows API is defined in the parent class Relation.\n bool Knows(int a, int b); */\n\npublic class Solution : Relation {\n public int FindCelebrity(int n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for knows()\n * \n * @param {integer} person a\n * @param {integer} person b\n * @return {boolean} whether a knows b\n * knows = function(a, b) {\n * ...\n * };\n */\n\n/**\n * @param {function} knows()\n * @return {function}\n */\nvar solution = function(knows) {\n /**\n * @param {integer} n Total people\n * @return {integer} The celebrity\n */\n return function(n) {\n \n };\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# The knows API is already defined for you.\n# @param {Integer} person a\n# @param {Integer} person b\n# @return {Boolean} whether a knows b\n# def knows(a, b)\n\n# @param {Integer} n\n# @return {Integer}\ndef find_celebrity(n)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * The knows API is defined in the parent class Relation.\n * func knows(_ a: Int, _ b: Int) -> Bool;\n */\n\nclass Solution : Relation {\n func findCelebrity(_ n: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * The knows API is already defined for you.\n * knows := func(a int, b int) bool\n */\nfunc solution(knows func(a int, b int) bool) func(n int) int {\n return func(n int) int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/* The knows API is defined in the parent class Relation.\n def knows(a: Int, b: Int): Boolean = {} */\n\nclass Solution extends Relation {\n def findCelebrity(n: Int): Int = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/* The knows API is defined in the parent class Relation.\n fun knows(a: Int, b: Int) : Boolean {} */\n\nclass Solution: Relation() {\n override fun findCelebrity(n: Int) : Int {\n \n\t}\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "/* The knows API is defined for you.\n knows(a: i32, b: i32)->bool;\n to call it use self.knows(a,b)\n*/\n\nimpl Solution {\n pub fn find_celebrity(&self, n: i32) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/* The knows API is defined in the parent class Relation.\n public function knows($a, $b){} */\n\nclass Solution extends Relation {\n /**\n * @param Integer $n\n * @return Integer\n */\n function findCelebrity($n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * The knows API is defined in the parent class Relation.\n * knows(a: number, b: number): boolean {\n * ...\n * };\n */\n\nvar solution = function(knows: any) {\n\n return function(n: number): number {\n \n };\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0277](https://leetcode-cn.com/problems/find-the-celebrity)", "[\u641c\u5bfb\u540d\u4eba](/solution/0200-0299/0277.Find%20the%20Celebrity/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0277](https://leetcode.com/problems/find-the-celebrity)", "[Find the Celebrity](/solution/0200-0299/0277.Find%20the%20Celebrity/README_EN.md)", "`Array`", "Medium", "\ud83d\udd12"]}, {"question_id": "0276", "frontend_question_id": "0276", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/paint-fence", "url_en": "https://leetcode.com/problems/paint-fence", "relative_path_cn": "/solution/0200-0299/0276.Paint%20Fence/README.md", "relative_path_en": "/solution/0200-0299/0276.Paint%20Fence/README_EN.md", "title_cn": "\u6805\u680f\u6d82\u8272", "title_en": "Paint Fence", "question_title_slug": "paint-fence", "content_en": "

    You are painting a fence of n posts with k different colors. You must paint the posts following these rules:

    \n\n
      \n\t
    • Every post must be painted exactly one color.
    • \n\t
    • At most one pair of adjacent fence posts can have the same color.
    • \n
    \n\n

    Given the two integers n and k, return the number of ways you can paint the fence.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: n = 3, k = 2\nOutput: 6\nExplanation: All the possibilities are shown.\nNote that painting all the posts red or all the posts green is invalid because there can only be at most one pair of adjacent posts that are the same color.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 1, k = 1\nOutput: 1\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 7, k = 2\nOutput: 42\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 50
    • \n\t
    • 1 <= k <= 105
    • \n\t
    • The answer is guaranteed to be in the range [0, 231 - 1] for the given n and k.
    • \n
    \n", "content_cn": "

    \u6709 k \u79cd\u989c\u8272\u7684\u6d82\u6599\u548c\u4e00\u4e2a\u5305\u542b n \u4e2a\u6805\u680f\u67f1\u7684\u6805\u680f\uff0c\u8bf7\u4f60\u6309\u4e0b\u8ff0\u89c4\u5219\u4e3a\u6805\u680f\u8bbe\u8ba1\u6d82\u8272\u65b9\u6848\uff1a

    \n\n
      \n\t
    • \u6bcf\u4e2a\u6805\u680f\u67f1\u53ef\u4ee5\u7528\u5176\u4e2d \u4e00\u79cd \u989c\u8272\u8fdb\u884c\u4e0a\u8272\u3002
    • \n\t
    • \u76f8\u90bb\u7684\u6805\u680f\u67f1 \u6700\u591a\u8fde\u7eed\u4e24\u4e2a\u00a0\u989c\u8272\u76f8\u540c\u3002
    • \n
    \n\n

    \u7ed9\u4f60\u4e24\u4e2a\u6574\u6570 k \u548c n \uff0c\u8fd4\u56de\u6240\u6709\u6709\u6548\u7684\u6d82\u8272 \u65b9\u6848\u6570 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1an = 3, k = 2\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u6240\u6709\u7684\u53ef\u80fd\u6d82\u8272\u65b9\u6848\u5982\u4e0a\u56fe\u6240\u793a\u3002\u6ce8\u610f\uff0c\u5168\u6d82\u7ea2\u6216\u8005\u5168\u6d82\u7eff\u7684\u65b9\u6848\u5c5e\u4e8e\u65e0\u6548\u65b9\u6848\uff0c\u56e0\u4e3a\u76f8\u90bb\u7684\u6805\u680f\u67f1 \u6700\u591a\u8fde\u7eed\u4e24\u4e2a\u00a0\u989c\u8272\u76f8\u540c\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 1, k = 1\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 7, k = 2\n\u8f93\u51fa\uff1a42\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 50
    • \n\t
    • 1 <= k <= 105
    • \n\t
    • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\uff1a\u5bf9\u4e8e\u8f93\u5165\u7684 n \u548c k \uff0c\u5176\u7b54\u6848\u5728\u8303\u56f4 [0, 231 - 1] \u5185
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numWays(int n, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numWays(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numWays(self, n, k):\n \"\"\"\n :type n: int\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numWays(self, n: int, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numWays(int n, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumWays(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} k\n * @return {number}\n */\nvar numWays = function(n, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} k\n# @return {Integer}\ndef num_ways(n, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numWays(_ n: Int, _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numWays(n int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numWays(n: Int, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numWays(n: Int, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_ways(n: i32, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $k\n * @return Integer\n */\n function numWays($n, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numWays(n: number, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-ways n k)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0276](https://leetcode-cn.com/problems/paint-fence)", "[\u6805\u680f\u6d82\u8272](/solution/0200-0299/0276.Paint%20Fence/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0276](https://leetcode.com/problems/paint-fence)", "[Paint Fence](/solution/0200-0299/0276.Paint%20Fence/README_EN.md)", "`Dynamic Programming`", "Medium", "\ud83d\udd12"]}, {"question_id": "0275", "frontend_question_id": "0275", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/h-index-ii", "url_en": "https://leetcode.com/problems/h-index-ii", "relative_path_cn": "/solution/0200-0299/0275.H-Index%20II/README.md", "relative_path_en": "/solution/0200-0299/0275.H-Index%20II/README_EN.md", "title_cn": "H \u6307\u6570 II", "title_en": "H-Index II", "question_title_slug": "h-index-ii", "content_en": "

    Given an array of integers citations where citations[i] is the number of citations a researcher received for their ith paper and citations is sorted in an ascending order, return compute the researcher's h-index.

    \n\n

    According to the definition of h-index on Wikipedia: A scientist has an index h if h of their n papers have at least h citations each, and the other n − h papers have no more than h citations each.

    \n\n

    If there are several possible values for h, the maximum one is taken as the h-index.

    \n\n

    You must write an algorithm that runs in logarithmic time.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: citations = [0,1,3,5,6]\nOutput: 3\nExplanation: [0,1,3,5,6] means the researcher has 5 papers in total and each of them had received 0, 1, 3, 5, 6 citations respectively.\nSince the researcher has 3 papers with at least 3 citations each and the remaining two with no more than 3 citations each, their h-index is 3.\n
    \n\n

    Example 2:

    \n\n
    \nInput: citations = [1,2,100]\nOutput: 2\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == citations.length
    • \n\t
    • 1 <= n <= 105
    • \n\t
    • 0 <= citations[i] <= 1000
    • \n\t
    • citations is sorted in ascending order.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4f4d\u7814\u7a76\u8005\u8bba\u6587\u88ab\u5f15\u7528\u6b21\u6570\u7684\u6570\u7ec4\uff08\u88ab\u5f15\u7528\u6b21\u6570\u662f\u975e\u8d1f\u6574\u6570\uff09\uff0c\u6570\u7ec4\u5df2\u7ecf\u6309\u7167 \u5347\u5e8f\u6392\u5217 \u3002\u7f16\u5199\u4e00\u4e2a\u65b9\u6cd5\uff0c\u8ba1\u7b97\u51fa\u7814\u7a76\u8005\u7684 h \u6307\u6570\u3002

    \n\n

    h \u6307\u6570\u7684\u5b9a\u4e49: “h \u4ee3\u8868“\u9ad8\u5f15\u7528\u6b21\u6570”\uff08high citations\uff09\uff0c\u4e00\u540d\u79d1\u7814\u4eba\u5458\u7684 h \u6307\u6570\u662f\u6307\u4ed6\uff08\u5979\uff09\u7684 \uff08N \u7bc7\u8bba\u6587\u4e2d\uff09\u603b\u5171\u6709 h \u7bc7\u8bba\u6587\u5206\u522b\u88ab\u5f15\u7528\u4e86\u81f3\u5c11 h \u6b21\u3002\uff08\u5176\u4f59\u7684 N - h \u7bc7\u8bba\u6587\u6bcf\u7bc7\u88ab\u5f15\u7528\u6b21\u6570\u4e0d\u591a\u4e8e h \u6b21\u3002\uff09"

    \n\n

     

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: citations = [0,1,3,5,6]\n\u8f93\u51fa: 3 \n\u89e3\u91ca: \u7ed9\u5b9a\u6570\u7ec4\u8868\u793a\u7814\u7a76\u8005\u603b\u5171\u6709 5 \u7bc7\u8bba\u6587\uff0c\u6bcf\u7bc7\u8bba\u6587\u76f8\u5e94\u7684\u88ab\u5f15\u7528\u4e86 0, 1, 3, 5, 6 \u6b21\u3002\n     \u7531\u4e8e\u7814\u7a76\u8005\u6709 3 \u7bc7\u8bba\u6587\u6bcf\u7bc7\u81f3\u5c11\u88ab\u5f15\u7528\u4e86 3 \u6b21\uff0c\u5176\u4f59\u4e24\u7bc7\u8bba\u6587\u6bcf\u7bc7\u88ab\u5f15\u7528\u4e0d\u591a\u4e8e 3 \u6b21\uff0c\u6240\u4ee5\u5979\u7684 h \u6307\u6570\u662f 3\u3002
    \n\n

     

    \n\n

    \u8bf4\u660e:

    \n\n

    \u5982\u679c h \u6709\u591a\u6709\u79cd\u53ef\u80fd\u7684\u503c \uff0ch \u6307\u6570\u662f\u5176\u4e2d\u6700\u5927\u7684\u90a3\u4e2a\u3002

    \n\n

     

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u8fd9\u662f H \u6307\u6570 \u7684\u5ef6\u4f38\u9898\u76ee\uff0c\u672c\u9898\u4e2d\u7684 citations \u6570\u7ec4\u662f\u4fdd\u8bc1\u6709\u5e8f\u7684\u3002
    • \n\t
    • \u4f60\u53ef\u4ee5\u4f18\u5316\u4f60\u7684\u7b97\u6cd5\u5230\u5bf9\u6570\u65f6\u95f4\u590d\u6742\u5ea6\u5417\uff1f
    • \n
    \n", "tags_en": ["Binary Search"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int hIndex(vector& citations) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int hIndex(int[] citations) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def hIndex(self, citations):\n \"\"\"\n :type citations: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def hIndex(self, citations: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint hIndex(int* citations, int citationsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int HIndex(int[] citations) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} citations\n * @return {number}\n */\nvar hIndex = function(citations) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} citations\n# @return {Integer}\ndef h_index(citations)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func hIndex(_ citations: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func hIndex(citations []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def hIndex(citations: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun hIndex(citations: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn h_index(citations: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $citations\n * @return Integer\n */\n function hIndex($citations) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function hIndex(citations: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (h-index citations)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0275](https://leetcode-cn.com/problems/h-index-ii)", "[H \u6307\u6570 II](/solution/0200-0299/0275.H-Index%20II/README.md)", "`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0275](https://leetcode.com/problems/h-index-ii)", "[H-Index II](/solution/0200-0299/0275.H-Index%20II/README_EN.md)", "`Binary Search`", "Medium", ""]}, {"question_id": "0274", "frontend_question_id": "0274", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/h-index", "url_en": "https://leetcode.com/problems/h-index", "relative_path_cn": "/solution/0200-0299/0274.H-Index/README.md", "relative_path_en": "/solution/0200-0299/0274.H-Index/README_EN.md", "title_cn": "H \u6307\u6570", "title_en": "H-Index", "question_title_slug": "h-index", "content_en": "

    Given an array of integers citations where citations[i] is the number of citations a researcher received for their ith paper, return compute the researcher's h-index.

    \n\n

    According to the definition of h-index on Wikipedia: A scientist has an index h if h of their n papers have at least h citations each, and the other n − h papers have no more than h citations each.

    \n\n

    If there are several possible values for h, the maximum one is taken as the h-index.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: citations = [3,0,6,1,5]\nOutput: 3\nExplanation: [3,0,6,1,5] means the researcher has 5 papers in total and each of them had received 3, 0, 6, 1, 5 citations respectively.\nSince the researcher has 3 papers with at least 3 citations each and the remaining two with no more than 3 citations each, their h-index is 3.\n
    \n\n

    Example 2:

    \n\n
    \nInput: citations = [1,3,1]\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == citations.length
    • \n\t
    • 1 <= n <= 5000
    • \n\t
    • 0 <= citations[i] <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4f4d\u7814\u7a76\u8005\u8bba\u6587\u88ab\u5f15\u7528\u6b21\u6570\u7684\u6570\u7ec4\uff08\u88ab\u5f15\u7528\u6b21\u6570\u662f\u975e\u8d1f\u6574\u6570\uff09\u3002\u7f16\u5199\u4e00\u4e2a\u65b9\u6cd5\uff0c\u8ba1\u7b97\u51fa\u7814\u7a76\u8005\u7684 h\u00a0\u6307\u6570\u3002

    \n\n

    h \u6307\u6570\u7684\u5b9a\u4e49\uff1ah \u4ee3\u8868\u201c\u9ad8\u5f15\u7528\u6b21\u6570\u201d\uff08high citations\uff09\uff0c\u4e00\u540d\u79d1\u7814\u4eba\u5458\u7684 h \u6307\u6570\u662f\u6307\u4ed6\uff08\u5979\uff09\u7684 \uff08N \u7bc7\u8bba\u6587\u4e2d\uff09\u603b\u5171\u6709 h \u7bc7\u8bba\u6587\u5206\u522b\u88ab\u5f15\u7528\u4e86\u81f3\u5c11 h \u6b21\u3002\u4e14\u5176\u4f59\u7684\u00a0N - h\u00a0\u7bc7\u8bba\u6587\u6bcf\u7bc7\u88ab\u5f15\u7528\u6b21\u6570\u00a0\u4e0d\u8d85\u8fc7 h \u6b21\u3002

    \n\n

    \u4f8b\u5982\uff1a\u67d0\u4eba\u7684 h \u6307\u6570\u662f 20\uff0c\u8fd9\u8868\u793a\u4ed6\u5df2\u53d1\u8868\u7684\u8bba\u6587\u4e2d\uff0c\u6bcf\u7bc7\u88ab\u5f15\u7528\u4e86\u81f3\u5c11 20 \u6b21\u7684\u8bba\u6587\u603b\u5171\u6709 20 \u7bc7\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1acitations = [3,0,6,1,5]\n\u8f93\u51fa\uff1a3 \n\u89e3\u91ca\uff1a\u7ed9\u5b9a\u6570\u7ec4\u8868\u793a\u7814\u7a76\u8005\u603b\u5171\u6709 5 \u7bc7\u8bba\u6587\uff0c\u6bcf\u7bc7\u8bba\u6587\u76f8\u5e94\u7684\u88ab\u5f15\u7528\u4e86 3, 0, 6, 1, 5 \u6b21\u3002\n\u00a0    \u7531\u4e8e\u7814\u7a76\u8005\u6709 3 \u7bc7\u8bba\u6587\u6bcf\u7bc7 \u81f3\u5c11 \u88ab\u5f15\u7528\u4e86 3 \u6b21\uff0c\u5176\u4f59\u4e24\u7bc7\u8bba\u6587\u6bcf\u7bc7\u88ab\u5f15\u7528 \u4e0d\u591a\u4e8e 3 \u6b21\uff0c\u6240\u4ee5\u5979\u7684 h \u6307\u6570\u662f 3\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a\u5982\u679c h \u6709\u591a\u79cd\u53ef\u80fd\u7684\u503c\uff0ch \u6307\u6570\u662f\u5176\u4e2d\u6700\u5927\u7684\u90a3\u4e2a\u3002

    \n", "tags_en": ["Sort", "Hash Table"], "tags_cn": ["\u6392\u5e8f", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int hIndex(vector& citations) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int hIndex(int[] citations) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def hIndex(self, citations):\n \"\"\"\n :type citations: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def hIndex(self, citations: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint hIndex(int* citations, int citationsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int HIndex(int[] citations) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} citations\n * @return {number}\n */\nvar hIndex = function(citations) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} citations\n# @return {Integer}\ndef h_index(citations)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func hIndex(_ citations: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func hIndex(citations []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def hIndex(citations: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun hIndex(citations: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn h_index(citations: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $citations\n * @return Integer\n */\n function hIndex($citations) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function hIndex(citations: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (h-index citations)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0274](https://leetcode-cn.com/problems/h-index)", "[H \u6307\u6570](/solution/0200-0299/0274.H-Index/README.md)", "`\u6392\u5e8f`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0274](https://leetcode.com/problems/h-index)", "[H-Index](/solution/0200-0299/0274.H-Index/README_EN.md)", "`Sort`,`Hash Table`", "Medium", ""]}, {"question_id": "0273", "frontend_question_id": "0273", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/integer-to-english-words", "url_en": "https://leetcode.com/problems/integer-to-english-words", "relative_path_cn": "/solution/0200-0299/0273.Integer%20to%20English%20Words/README.md", "relative_path_en": "/solution/0200-0299/0273.Integer%20to%20English%20Words/README_EN.md", "title_cn": "\u6574\u6570\u8f6c\u6362\u82f1\u6587\u8868\u793a", "title_en": "Integer to English Words", "question_title_slug": "integer-to-english-words", "content_en": "

    Convert a non-negative integer num to its English words representation.

    \n\n

     

    \n

    Example 1:

    \n
    Input: num = 123\nOutput: \"One Hundred Twenty Three\"\n

    Example 2:

    \n
    Input: num = 12345\nOutput: \"Twelve Thousand Three Hundred Forty Five\"\n

    Example 3:

    \n
    Input: num = 1234567\nOutput: \"One Million Two Hundred Thirty Four Thousand Five Hundred Sixty Seven\"\n

    Example 4:

    \n
    Input: num = 1234567891\nOutput: \"One Billion Two Hundred Thirty Four Million Five Hundred Sixty Seven Thousand Eight Hundred Ninety One\"\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= num <= 231 - 1
    • \n
    \n", "content_cn": "

    \u5c06\u975e\u8d1f\u6574\u6570 num \u8f6c\u6362\u4e3a\u5176\u5bf9\u5e94\u7684\u82f1\u6587\u8868\u793a\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anum = 123\n\u8f93\u51fa\uff1a\"One Hundred Twenty Three\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anum = 12345\n\u8f93\u51fa\uff1a\"Twelve Thousand Three Hundred Forty Five\"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anum = 1234567\n\u8f93\u51fa\uff1a\"One Million Two Hundred Thirty Four Thousand Five Hundred Sixty Seven\"\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1anum = 1234567891\n\u8f93\u51fa\uff1a\"One Billion Two Hundred Thirty Four Million Five Hundred Sixty Seven Thousand Eight Hundred Ninety One\"\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= num <= 231 - 1
    • \n
    \n", "tags_en": ["Math", "String"], "tags_cn": ["\u6570\u5b66", "\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string numberToWords(int num) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String numberToWords(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numberToWords(self, num):\n \"\"\"\n :type num: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numberToWords(self, num: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * numberToWords(int num){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string NumberToWords(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} num\n * @return {string}\n */\nvar numberToWords = function(num) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} num\n# @return {String}\ndef number_to_words(num)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numberToWords(_ num: Int) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numberToWords(num int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numberToWords(num: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numberToWords(num: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn number_to_words(num: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $num\n * @return String\n */\n function numberToWords($num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numberToWords(num: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (number-to-words num)\n (-> exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0273](https://leetcode-cn.com/problems/integer-to-english-words)", "[\u6574\u6570\u8f6c\u6362\u82f1\u6587\u8868\u793a](/solution/0200-0299/0273.Integer%20to%20English%20Words/README.md)", "`\u6570\u5b66`,`\u5b57\u7b26\u4e32`", "\u56f0\u96be", ""], "md_table_row_en": ["[0273](https://leetcode.com/problems/integer-to-english-words)", "[Integer to English Words](/solution/0200-0299/0273.Integer%20to%20English%20Words/README_EN.md)", "`Math`,`String`", "Hard", ""]}, {"question_id": "0272", "frontend_question_id": "0272", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/closest-binary-search-tree-value-ii", "url_en": "https://leetcode.com/problems/closest-binary-search-tree-value-ii", "relative_path_cn": "/solution/0200-0299/0272.Closest%20Binary%20Search%20Tree%20Value%20II/README.md", "relative_path_en": "/solution/0200-0299/0272.Closest%20Binary%20Search%20Tree%20Value%20II/README_EN.md", "title_cn": "\u6700\u63a5\u8fd1\u7684\u4e8c\u53c9\u641c\u7d22\u6811\u503c II", "title_en": "Closest Binary Search Tree Value II", "question_title_slug": "closest-binary-search-tree-value-ii", "content_en": "

    Given the root of a binary search tree, a target value, and an integer k, return the k values in the BST that are closest to the target. You may return the answer in any order.

    \n\n

    You are guaranteed to have only one unique set of k values in the BST that are closest to the target.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [4,2,5,1,3], target = 3.714286, k = 2\nOutput: [4,3]\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = [1], target = 0.000000, k = 1\nOutput: [1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is n.
    • \n\t
    • 1 <= k <= n <= 104.
    • \n\t
    • 0 <= Node.val <= 109
    • \n\t
    • -109 <= target <= 109
    • \n
    \n\n

     

    \n

    Follow up: Assume that the BST is balanced. Could you solve it in less than O(n) runtime (where n = total nodes)?

    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e0d\u4e3a\u7a7a\u7684\u4e8c\u53c9\u641c\u7d22\u6811\u548c\u4e00\u4e2a\u76ee\u6807\u503c target\uff0c\u8bf7\u5728\u8be5\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u627e\u5230\u6700\u63a5\u8fd1\u76ee\u6807\u503c target \u7684 k \u4e2a\u503c\u3002

    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    • \u7ed9\u5b9a\u7684\u76ee\u6807\u503c target \u662f\u4e00\u4e2a\u6d6e\u70b9\u6570
    • \n\t
    • \u4f60\u53ef\u4ee5\u9ed8\u8ba4 k \u503c\u6c38\u8fdc\u662f\u6709\u6548\u7684\uff0c\u5373 k ≤ \u603b\u7ed3\u70b9\u6570
    • \n\t
    • \u9898\u76ee\u4fdd\u8bc1\u8be5\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u53ea\u4f1a\u5b58\u5728\u4e00\u79cd k \u4e2a\u503c\u96c6\u5408\u6700\u63a5\u8fd1\u76ee\u6807\u503c
    • \n
    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165: root = [4,2,5,1,3]\uff0c\u76ee\u6807\u503c = 3.714286\uff0c\u4e14 k = 2\n\n    4\n   / \\\n  2   5\n / \\\n1   3\n\n\u8f93\u51fa: [4,3]
    \n\n

    \u62d3\u5c55\uff1a
    \n\u5047\u8bbe\u8be5\u4e8c\u53c9\u641c\u7d22\u6811\u662f\u5e73\u8861\u7684\uff0c\u8bf7\u95ee\u60a8\u662f\u5426\u80fd\u5728\u5c0f\u4e8e O(n)\uff08n \u4e3a\u603b\u7ed3\u70b9\u6570\uff09\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u5185\u89e3\u51b3\u8be5\u95ee\u9898\u5462\uff1f

    \n", "tags_en": ["Stack", "Tree"], "tags_cn": ["\u6808", "\u6811"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector closestKValues(TreeNode* root, double target, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public List closestKValues(TreeNode root, double target, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def closestKValues(self, root, target, k):\n \"\"\"\n :type root: TreeNode\n :type target: float\n :type k: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def closestKValues(self, root: TreeNode, target: float, k: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* closestKValues(struct TreeNode* root, double target, int k, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public IList ClosestKValues(TreeNode root, double target, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number} target\n * @param {number} k\n * @return {number[]}\n */\nvar closestKValues = function(root, target, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @param {Float} target\n# @param {Integer} k\n# @return {Integer[]}\ndef closest_k_values(root, target, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func closestKValues(_ root: TreeNode?, _ target: Double, _ k: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc closestKValues(root *TreeNode, target float64, k int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def closestKValues(root: TreeNode, target: Double, k: Int): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun closestKValues(root: TreeNode?, target: Double, k: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn closest_k_values(root: Option>>, target: f64, k: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param Float $target\n * @param Integer $k\n * @return Integer[]\n */\n function closestKValues($root, $target, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction closestKValues(root: TreeNode | null, target: number, k: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (closest-k-values root target k)\n (-> (or/c tree-node? #f) flonum? exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0272](https://leetcode-cn.com/problems/closest-binary-search-tree-value-ii)", "[\u6700\u63a5\u8fd1\u7684\u4e8c\u53c9\u641c\u7d22\u6811\u503c II](/solution/0200-0299/0272.Closest%20Binary%20Search%20Tree%20Value%20II/README.md)", "`\u6808`,`\u6811`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0272](https://leetcode.com/problems/closest-binary-search-tree-value-ii)", "[Closest Binary Search Tree Value II](/solution/0200-0299/0272.Closest%20Binary%20Search%20Tree%20Value%20II/README_EN.md)", "`Stack`,`Tree`", "Hard", "\ud83d\udd12"]}, {"question_id": "0271", "frontend_question_id": "0271", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/encode-and-decode-strings", "url_en": "https://leetcode.com/problems/encode-and-decode-strings", "relative_path_cn": "/solution/0200-0299/0271.Encode%20and%20Decode%20Strings/README.md", "relative_path_en": "/solution/0200-0299/0271.Encode%20and%20Decode%20Strings/README_EN.md", "title_cn": "\u5b57\u7b26\u4e32\u7684\u7f16\u7801\u4e0e\u89e3\u7801", "title_en": "Encode and Decode Strings", "question_title_slug": "encode-and-decode-strings", "content_en": "

    Design an algorithm to encode a list of strings to a string. The encoded string is then sent over the network and is decoded back to the original list of strings.

    \n\n

    Machine 1 (sender) has the function:

    \n\n
    \nstring encode(vector<string> strs) {\n  // ... your code\n  return encoded_string;\n}
    \nMachine 2 (receiver) has the function:\n\n
    \nvector<string> decode(string s) {\n  //... your code\n  return strs;\n}\n
    \n\n

    So Machine 1 does:

    \n\n
    \nstring encoded_string = encode(strs);\n
    \n\n

    and Machine 2 does:

    \n\n
    \nvector<string> strs2 = decode(encoded_string);\n
    \n\n

    strs2 in Machine 2 should be the same as strs in Machine 1.

    \n\n

    Implement the encode and decode methods.

    \n\n

    You are not allowed to solve the problem using any serialize methods (such as eval).

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: dummy_input = ["Hello","World"]\nOutput: ["Hello","World"]\nExplanation:\nMachine 1:\nCodec encoder = new Codec();\nString msg = encoder.encode(strs);\nMachine 1 ---msg---> Machine 2\n\nMachine 2:\nCodec decoder = new Codec();\nString[] strs = decoder.decode(msg);\n
    \n\n

    Example 2:

    \n\n
    \nInput: dummy_input = [""]\nOutput: [""]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= strs.length <= 200
    • \n\t
    • 0 <= strs[i].length <= 200
    • \n\t
    • strs[i] contains any possible characters out of 256 valid ASCII characters.
    • \n
    \n\n

     

    \n

    Follow up: Could you write a generalized algorithm to work on any possible set of characters?

    \n", "content_cn": "

    \u8bf7\u4f60\u8bbe\u8ba1\u4e00\u4e2a\u7b97\u6cd5\uff0c\u53ef\u4ee5\u5c06\u4e00\u4e2a \u5b57\u7b26\u4e32\u5217\u8868 \u7f16\u7801\u6210\u4e3a\u4e00\u4e2a \u5b57\u7b26\u4e32\u3002\u8fd9\u4e2a\u7f16\u7801\u540e\u7684\u5b57\u7b26\u4e32\u662f\u53ef\u4ee5\u901a\u8fc7\u7f51\u7edc\u8fdb\u884c\u9ad8\u6548\u4f20\u9001\u7684\uff0c\u5e76\u4e14\u53ef\u4ee5\u5728\u63a5\u6536\u7aef\u88ab\u89e3\u7801\u56de\u539f\u6765\u7684\u5b57\u7b26\u4e32\u5217\u8868\u3002

    \n\n

    1 \u53f7\u673a\uff08\u53d1\u9001\u65b9\uff09\u6709\u5982\u4e0b\u51fd\u6570\uff1a

    \n\n
    string encode(vector<string> strs) {\n  // ... your code\n  return encoded_string;\n}
    \n\n

    2 \u53f7\u673a\uff08\u63a5\u6536\u65b9\uff09\u6709\u5982\u4e0b\u51fd\u6570\uff1a

    \n\n
    vector<string> decode(string s) {\n  //... your code\n  return strs;\n}\n
    \n\n

    1 \u53f7\u673a\uff08\u53d1\u9001\u65b9\uff09\u6267\u884c\uff1a

    \n\n
    string encoded_string = encode(strs);\n
    \n\n

    2 \u53f7\u673a\uff08\u63a5\u6536\u65b9\uff09\u6267\u884c\uff1a

    \n\n
    vector<string> strs2 = decode(encoded_string);\n
    \n\n

    \u6b64\u65f6\uff0c2 \u53f7\u673a\uff08\u63a5\u6536\u65b9\uff09\u7684 strs2 \u9700\u8981\u548c 1 \u53f7\u673a\uff08\u53d1\u9001\u65b9\uff09\u7684 strs \u76f8\u540c\u3002

    \n\n

    \u8bf7\u4f60\u6765\u5b9e\u73b0\u8fd9\u4e2a encode \u548c decode \u65b9\u6cd5\u3002

    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    • \u56e0\u4e3a\u5b57\u7b26\u4e32\u53ef\u80fd\u4f1a\u5305\u542b 256 \u4e2a\u5408\u6cd5 ascii \u5b57\u7b26\u4e2d\u7684\u4efb\u4f55\u5b57\u7b26\uff0c\u6240\u4ee5\u60a8\u7684\u7b97\u6cd5\u5fc5\u987b\u8981\u80fd\u591f\u5904\u7406\u4efb\u4f55\u53ef\u80fd\u4f1a\u51fa\u73b0\u7684\u5b57\u7b26\u3002
    • \n\t
    • \u8bf7\u52ff\u4f7f\u7528 “\u7c7b\u6210\u5458”\u3001“\u5168\u5c40\u53d8\u91cf” \u6216 “\u9759\u6001\u53d8\u91cf” \u6765\u5b58\u50a8\u8fd9\u4e9b\u72b6\u6001\uff0c\u60a8\u7684\u7f16\u7801\u548c\u89e3\u7801\u7b97\u6cd5\u5e94\u8be5\u662f\u975e\u72b6\u6001\u4f9d\u8d56\u7684\u3002
    • \n\t
    • \u8bf7\u4e0d\u8981\u4f9d\u8d56\u4efb\u4f55\u65b9\u6cd5\u5e93\uff0c\u4f8b\u5982 eval \u53c8\u6216\u8005\u662f serialize \u4e4b\u7c7b\u7684\u65b9\u6cd5\u3002\u672c\u9898\u7684\u5b97\u65e8\u662f\u9700\u8981\u60a8\u81ea\u5df1\u5b9e\u73b0 “\u7f16\u7801” \u548c “\u89e3\u7801” \u7b97\u6cd5\u3002
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Codec {\npublic:\n\n // Encodes a list of strings to a single string.\n string encode(vector& strs) {\n \n }\n\n // Decodes a single string to a list of strings.\n vector decode(string s) {\n \n }\n};\n\n// Your Codec object will be instantiated and called as such:\n// Codec codec;\n// codec.decode(codec.encode(strs));", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "public class Codec {\n\n // Encodes a list of strings to a single string.\n public String encode(List strs) {\n \n }\n\n // Decodes a single string to a list of strings.\n public List decode(String s) {\n \n }\n}\n\n// Your Codec object will be instantiated and called as such:\n// Codec codec = new Codec();\n// codec.decode(codec.encode(strs));", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Codec:\n\n def encode(self, strs):\n \"\"\"Encodes a list of strings to a single string.\n \n :type strs: List[str]\n :rtype: str\n \"\"\"\n \n\n def decode(self, s):\n \"\"\"Decodes a single string to a list of strings.\n \n :type s: str\n :rtype: List[str]\n \"\"\"\n \n\n# Your Codec object will be instantiated and called as such:\n# codec = Codec()\n# codec.decode(codec.encode(strs))", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Codec:\n def encode(self, strs: [str]) -> str:\n \"\"\"Encodes a list of strings to a single string.\n \"\"\"\n \n\n def decode(self, s: str) -> [str]:\n \"\"\"Decodes a single string to a list of strings.\n \"\"\"\n \n\n\n# Your Codec object will be instantiated and called as such:\n# codec = Codec()\n# codec.decode(codec.encode(strs))", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/** Encodes a list of strings to a single string */\nchar* encode(char** strs, int strsSize) {\n \n}\n\n/**\n * Decodes a single string to a list of strings.\n *\n * Return an array of size *returnSize.\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar** decode(char* s, int* returnSize) {\n \n}\n\n// Your functions will be called as such:\n// char* s = encode(strs, strsSize);\n// decode(s, &returnSize);", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Codec {\n\n // Encodes a list of strings to a single string.\n public string encode(IList strs) {\n \n }\n\n // Decodes a single string to a list of strings.\n public IList decode(string s) {\n \n }\n}\n\n// Your Codec object will be instantiated and called as such:\n// Codec codec = new Codec();\n// codec.decode(codec.encode(strs));", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Encodes a list of strings to a single string.\n *\n * @param {string[]} strs\n * @return {string}\n */\nvar encode = function(strs) {\n \n};\n\n/**\n * Decodes a single string to a list of strings.\n *\n * @param {string} s\n * @return {string[]}\n */\nvar decode = function(s) {\n \n};\n\n/**\n * Your functions will be called as such:\n * decode(encode(strs));\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Encodes a list of strings to a single string.\n#\n# @param {string[]} strs\n# @return {string}\ndef encode(strs)\n \nend\n\n# Decodes a single string to a list of strings.\n#\n# @param {string} s\n# @return {string[]}\ndef decode(s)\n \nend\n\n\n# Your functions will be called as such:\n# decode(encode(strs))", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Codec {\n func encode(_ strs: [String]) -> String {\n \n }\n \n func decode(_ s: String) -> [String] {\n \n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * let obj = Codec()\n * val s = obj.encode(strs)\n * let ans = obj.decode(s)\n*/", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type Codec struct {\n \n}\n\n// Encodes a list of strings to a single string.\nfunc (codec *Codec) Encode(strs []string) string {\n \n}\n\n// Decodes a single string to a list of strings.\nfunc (codec *Codec) Decode(strs string) []string {\n \n}\n\n// Your Codec object will be instantiated and called as such:\n// var codec Codec\n// codec.Decode(codec.Encode(strs));", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class Codec {\n // Encodes a list of strings to a single string.\n def encode(strs: List[String]): String = {\n \n }\n \n // Decodes a single string to a list of strings.\n def decode(s: String): List[String] = {\n \n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * var obj = new Codec()\n * val s = obj.encode(strs)\n * val ans = obj.decode(s)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Codec {\n // Encodes a list of strings to a single string.\n fun encode(strs: List): String {\n \n }\n \n // Decodes a single string to a list of strings.\n fun decode(s: String): List {\n \n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * var obj = Codec()\n * val s = obj.encode(strs)\n * val ans = obj.decode(s)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct Codec {\n\t\n}\n\n/** \n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl Codec {\n fn new() -> Self {\n \n }\n\t\n fn encode(&self, strs: Vec) -> String {\n \n }\n\t\n fn decode(&self, s: String) -> Vec {\n \n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * let obj = Codec::new();\n * let s: String = obj.encode(strs);\n * let ans: VecVec = obj.decode(s);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Codec {\n /**\n * @param String[] $strs\n * @return String\n */\n function encode($strs) {\n \n }\n \n /**\n * @param String $s\n * @return String[]\n */\n function decode($s) {\n \n }\n}\n\n/**\n * Your Codec object will be instantiated and called as such:\n * $obj = Codec();\n * $s = $obj->encode($strs);\n * $ans = $obj->decode($s);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Encodes a list of strings to a single string.\n */\nfunction encode(strs: string[]): string {\n\t\n};\n\n/**\n * Decodes a single string to a list of strings.\n */\nfunction decode(s: string): string[] {\n\t\n};\n\n/**\n * Your functions will be called as such:\n * decode(encode(strs));\n */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0271](https://leetcode-cn.com/problems/encode-and-decode-strings)", "[\u5b57\u7b26\u4e32\u7684\u7f16\u7801\u4e0e\u89e3\u7801](/solution/0200-0299/0271.Encode%20and%20Decode%20Strings/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0271](https://leetcode.com/problems/encode-and-decode-strings)", "[Encode and Decode Strings](/solution/0200-0299/0271.Encode%20and%20Decode%20Strings/README_EN.md)", "`String`", "Medium", "\ud83d\udd12"]}, {"question_id": "0270", "frontend_question_id": "0270", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/closest-binary-search-tree-value", "url_en": "https://leetcode.com/problems/closest-binary-search-tree-value", "relative_path_cn": "/solution/0200-0299/0270.Closest%20Binary%20Search%20Tree%20Value/README.md", "relative_path_en": "/solution/0200-0299/0270.Closest%20Binary%20Search%20Tree%20Value/README_EN.md", "title_cn": "\u6700\u63a5\u8fd1\u7684\u4e8c\u53c9\u641c\u7d22\u6811\u503c", "title_en": "Closest Binary Search Tree Value", "question_title_slug": "closest-binary-search-tree-value", "content_en": "

    Given the root of a binary search tree and a target value, return the value in the BST that is closest to the target.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [4,2,5,1,3], target = 3.714286\nOutput: 4\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = [1], target = 4.428571\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 104].
    • \n\t
    • 0 <= Node.val <= 109
    • \n\t
    • -109 <= target <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e0d\u4e3a\u7a7a\u7684\u4e8c\u53c9\u641c\u7d22\u6811\u548c\u4e00\u4e2a\u76ee\u6807\u503c target\uff0c\u8bf7\u5728\u8be5\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u627e\u5230\u6700\u63a5\u8fd1\u76ee\u6807\u503c target \u7684\u6570\u503c\u3002

    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    • \u7ed9\u5b9a\u7684\u76ee\u6807\u503c target \u662f\u4e00\u4e2a\u6d6e\u70b9\u6570
    • \n\t
    • \u9898\u76ee\u4fdd\u8bc1\u5728\u8be5\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u53ea\u4f1a\u5b58\u5728\u4e00\u4e2a\u6700\u63a5\u8fd1\u76ee\u6807\u503c\u7684\u6570
    • \n
    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165: root = [4,2,5,1,3]\uff0c\u76ee\u6807\u503c target = 3.714286\n\n    4\n   / \\\n  2   5\n / \\\n1   3\n\n\u8f93\u51fa: 4\n
    \n", "tags_en": ["Tree", "Binary Search"], "tags_cn": ["\u6811", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int closestValue(TreeNode* root, double target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int closestValue(TreeNode root, double target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def closestValue(self, root, target):\n \"\"\"\n :type root: TreeNode\n :type target: float\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def closestValue(self, root: TreeNode, target: float) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint closestValue(struct TreeNode* root, double target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int ClosestValue(TreeNode root, double target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number} target\n * @return {number}\n */\nvar closestValue = function(root, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @param {Float} target\n# @return {Integer}\ndef closest_value(root, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func closestValue(_ root: TreeNode?, _ target: Double) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc closestValue(root *TreeNode, target float64) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def closestValue(root: TreeNode, target: Double): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun closestValue(root: TreeNode?, target: Double): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn closest_value(root: Option>>, target: f64) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param Float $target\n * @return Integer\n */\n function closestValue($root, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction closestValue(root: TreeNode | null, target: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (closest-value root target)\n (-> (or/c tree-node? #f) flonum? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0270](https://leetcode-cn.com/problems/closest-binary-search-tree-value)", "[\u6700\u63a5\u8fd1\u7684\u4e8c\u53c9\u641c\u7d22\u6811\u503c](/solution/0200-0299/0270.Closest%20Binary%20Search%20Tree%20Value/README.md)", "`\u6811`,`\u4e8c\u5206\u67e5\u627e`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0270](https://leetcode.com/problems/closest-binary-search-tree-value)", "[Closest Binary Search Tree Value](/solution/0200-0299/0270.Closest%20Binary%20Search%20Tree%20Value/README_EN.md)", "`Tree`,`Binary Search`", "Easy", "\ud83d\udd12"]}, {"question_id": "0269", "frontend_question_id": "0269", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/alien-dictionary", "url_en": "https://leetcode.com/problems/alien-dictionary", "relative_path_cn": "/solution/0200-0299/0269.Alien%20Dictionary/README.md", "relative_path_en": "/solution/0200-0299/0269.Alien%20Dictionary/README_EN.md", "title_cn": "\u706b\u661f\u8bcd\u5178", "title_en": "Alien Dictionary", "question_title_slug": "alien-dictionary", "content_en": "

    There is a new alien language that uses the English alphabet. However, the order among the letters is unknown to you.

    \n\n

    You are given a list of strings words from the alien language's dictionary, where the strings in words are sorted lexicographically by the rules of this new language.

    \n\n

    Return a string of the unique letters in the new alien language sorted in lexicographically increasing order by the new language's rules. If there is no solution, return "". If there are multiple solutions, return any of them.

    \n\n

    A string s is lexicographically smaller than a string t if at the first letter where they differ, the letter in s comes before the letter in t in the alien language. If the first min(s.length, t.length) letters are the same, then s is smaller if and only if s.length < t.length.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: words = ["wrt","wrf","er","ett","rftt"]\nOutput: "wertf"\n
    \n\n

    Example 2:

    \n\n
    \nInput: words = ["z","x"]\nOutput: "zx"\n
    \n\n

    Example 3:

    \n\n
    \nInput: words = ["z","x","z"]\nOutput: ""\nExplanation: The order is invalid, so return "".\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= words.length <= 100
    • \n\t
    • 1 <= words[i].length <= 100
    • \n\t
    • words[i] consists of only lowercase English letters.
    • \n
    \n", "content_cn": "

    \u73b0\u6709\u4e00\u79cd\u4f7f\u7528\u82f1\u8bed\u5b57\u6bcd\u7684\u706b\u661f\u8bed\u8a00\uff0c\u8fd9\u95e8\u8bed\u8a00\u7684\u5b57\u6bcd\u987a\u5e8f\u4e0e\u82f1\u8bed\u987a\u5e8f\u4e0d\u540c\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32\u5217\u8868 words \uff0c\u4f5c\u4e3a\u8fd9\u95e8\u8bed\u8a00\u7684\u8bcd\u5178\uff0cwords \u4e2d\u7684\u5b57\u7b26\u4e32\u5df2\u7ecf \u6309\u8fd9\u95e8\u65b0\u8bed\u8a00\u7684\u5b57\u6bcd\u987a\u5e8f\u8fdb\u884c\u4e86\u6392\u5e8f \u3002

    \n\n

    \u8bf7\u4f60\u6839\u636e\u8be5\u8bcd\u5178\u8fd8\u539f\u51fa\u6b64\u8bed\u8a00\u4e2d\u5df2\u77e5\u7684\u5b57\u6bcd\u987a\u5e8f\uff0c\u5e76 \u6309\u5b57\u6bcd\u9012\u589e\u987a\u5e8f \u6392\u5217\u3002\u82e5\u4e0d\u5b58\u5728\u5408\u6cd5\u5b57\u6bcd\u987a\u5e8f\uff0c\u8fd4\u56de \"\" \u3002\u82e5\u5b58\u5728\u591a\u79cd\u53ef\u80fd\u7684\u5408\u6cd5\u5b57\u6bcd\u987a\u5e8f\uff0c\u8fd4\u56de\u5176\u4e2d \u4efb\u610f\u4e00\u79cd \u987a\u5e8f\u5373\u53ef\u3002

    \n\n

    \u5b57\u7b26\u4e32 s \u5b57\u5178\u987a\u5e8f\u5c0f\u4e8e \u5b57\u7b26\u4e32 t \u6709\u4e24\u79cd\u60c5\u51b5\uff1a

    \n\n
      \n\t
    • \u5728\u7b2c\u4e00\u4e2a\u4e0d\u540c\u5b57\u6bcd\u5904\uff0c\u5982\u679c s \u4e2d\u7684\u5b57\u6bcd\u5728\u8fd9\u95e8\u5916\u661f\u8bed\u8a00\u7684\u5b57\u6bcd\u987a\u5e8f\u4e2d\u4f4d\u4e8e t \u4e2d\u5b57\u6bcd\u4e4b\u524d\uff0c\u90a3\u4e48\u00a0s \u7684\u5b57\u5178\u987a\u5e8f\u5c0f\u4e8e t \u3002
    • \n\t
    • \u5982\u679c\u524d\u9762 min(s.length, t.length) \u5b57\u6bcd\u90fd\u76f8\u540c\uff0c\u90a3\u4e48 s.length < t.length \u65f6\uff0cs \u7684\u5b57\u5178\u987a\u5e8f\u4e5f\u5c0f\u4e8e t \u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1awords = [\"wrt\",\"wrf\",\"er\",\"ett\",\"rftt\"]\n\u8f93\u51fa\uff1a\"wertf\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1awords = [\"z\",\"x\"]\n\u8f93\u51fa\uff1a\"zx\"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1awords = [\"z\",\"x\",\"z\"]\n\u8f93\u51fa\uff1a\"\"\n\u89e3\u91ca\uff1a\u4e0d\u5b58\u5728\u5408\u6cd5\u5b57\u6bcd\u987a\u5e8f\uff0c\u56e0\u6b64\u8fd4\u56de \"\" \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= words.length <= 100
    • \n\t
    • 1 <= words[i].length <= 100
    • \n\t
    • words[i] \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n", "tags_en": ["Graph", "Topological Sort"], "tags_cn": ["\u56fe", "\u62d3\u6251\u6392\u5e8f"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string alienOrder(vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String alienOrder(String[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def alienOrder(self, words):\n \"\"\"\n :type words: List[str]\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def alienOrder(self, words: List[str]) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * alienOrder(char ** words, int wordsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string AlienOrder(string[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @return {string}\n */\nvar alienOrder = function(words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @return {String}\ndef alien_order(words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func alienOrder(_ words: [String]) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func alienOrder(words []string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def alienOrder(words: Array[String]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun alienOrder(words: Array): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn alien_order(words: Vec) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @return String\n */\n function alienOrder($words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function alienOrder(words: string[]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (alien-order words)\n (-> (listof string?) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0269](https://leetcode-cn.com/problems/alien-dictionary)", "[\u706b\u661f\u8bcd\u5178](/solution/0200-0299/0269.Alien%20Dictionary/README.md)", "`\u56fe`,`\u62d3\u6251\u6392\u5e8f`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0269](https://leetcode.com/problems/alien-dictionary)", "[Alien Dictionary](/solution/0200-0299/0269.Alien%20Dictionary/README_EN.md)", "`Graph`,`Topological Sort`", "Hard", "\ud83d\udd12"]}, {"question_id": "0268", "frontend_question_id": "0268", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/missing-number", "url_en": "https://leetcode.com/problems/missing-number", "relative_path_cn": "/solution/0200-0299/0268.Missing%20Number/README.md", "relative_path_en": "/solution/0200-0299/0268.Missing%20Number/README_EN.md", "title_cn": "\u4e22\u5931\u7684\u6570\u5b57", "title_en": "Missing Number", "question_title_slug": "missing-number", "content_en": "

    Given an array nums containing n distinct numbers in the range [0, n], return the only number in the range that is missing from the array.

    \n\n

    Follow up: Could you implement a solution using only O(1) extra space complexity and O(n) runtime complexity?

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [3,0,1]\nOutput: 2\nExplanation: n = 3 since there are 3 numbers, so all numbers are in the range [0,3]. 2 is the missing number in the range since it does not appear in nums.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [0,1]\nOutput: 2\nExplanation: n = 2 since there are 2 numbers, so all numbers are in the range [0,2]. 2 is the missing number in the range since it does not appear in nums.\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [9,6,4,2,3,5,7,0,1]\nOutput: 8\nExplanation: n = 9 since there are 9 numbers, so all numbers are in the range [0,9]. 8 is the missing number in the range since it does not appear in nums.\n
    \n\n

    Example 4:

    \n\n
    \nInput: nums = [0]\nOutput: 1\nExplanation: n = 1 since there is 1 number, so all numbers are in the range [0,1]. 1 is the missing number in the range since it does not appear in nums.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= n <= 104
    • \n\t
    • 0 <= nums[i] <= n
    • \n\t
    • All the numbers of nums are unique.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5305\u542b [0, n]\u00a0\u4e2d\u00a0n\u00a0\u4e2a\u6570\u7684\u6570\u7ec4 nums \uff0c\u627e\u51fa [0, n] \u8fd9\u4e2a\u8303\u56f4\u5185\u6ca1\u6709\u51fa\u73b0\u5728\u6570\u7ec4\u4e2d\u7684\u90a3\u4e2a\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u4f60\u80fd\u5426\u5b9e\u73b0\u7ebf\u6027\u65f6\u95f4\u590d\u6742\u5ea6\u3001\u4ec5\u4f7f\u7528\u989d\u5916\u5e38\u6570\u7a7a\u95f4\u7684\u7b97\u6cd5\u89e3\u51b3\u6b64\u95ee\u9898?
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [3,0,1]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1an = 3\uff0c\u56e0\u4e3a\u6709 3 \u4e2a\u6570\u5b57\uff0c\u6240\u4ee5\u6240\u6709\u7684\u6570\u5b57\u90fd\u5728\u8303\u56f4 [0,3] \u5185\u30022 \u662f\u4e22\u5931\u7684\u6570\u5b57\uff0c\u56e0\u4e3a\u5b83\u6ca1\u6709\u51fa\u73b0\u5728 nums \u4e2d\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [0,1]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1an = 2\uff0c\u56e0\u4e3a\u6709 2 \u4e2a\u6570\u5b57\uff0c\u6240\u4ee5\u6240\u6709\u7684\u6570\u5b57\u90fd\u5728\u8303\u56f4 [0,2] \u5185\u30022 \u662f\u4e22\u5931\u7684\u6570\u5b57\uff0c\u56e0\u4e3a\u5b83\u6ca1\u6709\u51fa\u73b0\u5728 nums \u4e2d\u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [9,6,4,2,3,5,7,0,1]\n\u8f93\u51fa\uff1a8\n\u89e3\u91ca\uff1an = 9\uff0c\u56e0\u4e3a\u6709 9 \u4e2a\u6570\u5b57\uff0c\u6240\u4ee5\u6240\u6709\u7684\u6570\u5b57\u90fd\u5728\u8303\u56f4 [0,9] \u5185\u30028 \u662f\u4e22\u5931\u7684\u6570\u5b57\uff0c\u56e0\u4e3a\u5b83\u6ca1\u6709\u51fa\u73b0\u5728 nums \u4e2d\u3002
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [0]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1an = 1\uff0c\u56e0\u4e3a\u6709 1 \u4e2a\u6570\u5b57\uff0c\u6240\u4ee5\u6240\u6709\u7684\u6570\u5b57\u90fd\u5728\u8303\u56f4 [0,1] \u5185\u30021 \u662f\u4e22\u5931\u7684\u6570\u5b57\uff0c\u56e0\u4e3a\u5b83\u6ca1\u6709\u51fa\u73b0\u5728 nums \u4e2d\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= n <= 104
    • \n\t
    • 0 <= nums[i] <= n
    • \n\t
    • nums \u4e2d\u7684\u6240\u6709\u6570\u5b57\u90fd \u72ec\u4e00\u65e0\u4e8c
    • \n
    \n", "tags_en": ["Bit Manipulation", "Array", "Math"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u6570\u7ec4", "\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int missingNumber(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int missingNumber(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def missingNumber(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def missingNumber(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint missingNumber(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MissingNumber(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar missingNumber = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef missing_number(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func missingNumber(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func missingNumber(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def missingNumber(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun missingNumber(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn missing_number(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function missingNumber($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function missingNumber(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (missing-number nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0268](https://leetcode-cn.com/problems/missing-number)", "[\u4e22\u5931\u7684\u6570\u5b57](/solution/0200-0299/0268.Missing%20Number/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u6570\u7ec4`,`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0268](https://leetcode.com/problems/missing-number)", "[Missing Number](/solution/0200-0299/0268.Missing%20Number/README_EN.md)", "`Bit Manipulation`,`Array`,`Math`", "Easy", ""]}, {"question_id": "0267", "frontend_question_id": "0267", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/palindrome-permutation-ii", "url_en": "https://leetcode.com/problems/palindrome-permutation-ii", "relative_path_cn": "/solution/0200-0299/0267.Palindrome%20Permutation%20II/README.md", "relative_path_en": "/solution/0200-0299/0267.Palindrome%20Permutation%20II/README_EN.md", "title_cn": "\u56de\u6587\u6392\u5217 II", "title_en": "Palindrome Permutation II", "question_title_slug": "palindrome-permutation-ii", "content_en": "

    Given a string s, return all the palindromic permutations (without duplicates) of it.

    \n\n

    You may return the answer in any order. If s has no palindromic permutation, return an empty list.

    \n\n

     

    \n

    Example 1:

    \n
    Input: s = \"aabb\"\nOutput: [\"abba\",\"baab\"]\n

    Example 2:

    \n
    Input: s = \"abc\"\nOutput: []\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 16
    • \n\t
    • s consists of only lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32 s \uff0c\u8fd4\u56de\u5176\u901a\u8fc7\u91cd\u65b0\u6392\u5217\u7ec4\u5408\u540e\u6240\u6709\u53ef\u80fd\u7684\u56de\u6587\u5b57\u7b26\u4e32\uff0c\u5e76\u53bb\u9664\u91cd\u590d\u7684\u7ec4\u5408\u3002

    \n\n

    \u5982\u4e0d\u80fd\u5f62\u6210\u4efb\u4f55\u56de\u6587\u6392\u5217\u65f6\uff0c\u5219\u8fd4\u56de\u4e00\u4e2a\u7a7a\u5217\u8868\u3002

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165: "aabb"\n\u8f93\u51fa: ["abba", "baab"]
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165: "abc"\n\u8f93\u51fa: []
    \n", "tags_en": ["Backtracking"], "tags_cn": ["\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector generatePalindromes(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List generatePalindromes(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def generatePalindromes(self, s):\n \"\"\"\n :type s: str\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def generatePalindromes(self, s: str) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** generatePalindromes(char * s, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList GeneratePalindromes(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string[]}\n */\nvar generatePalindromes = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String[]}\ndef generate_palindromes(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func generatePalindromes(_ s: String) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func generatePalindromes(s string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def generatePalindromes(s: String): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun generatePalindromes(s: String): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn generate_palindromes(s: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String[]\n */\n function generatePalindromes($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function generatePalindromes(s: string): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (generate-palindromes s)\n (-> string? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0267](https://leetcode-cn.com/problems/palindrome-permutation-ii)", "[\u56de\u6587\u6392\u5217 II](/solution/0200-0299/0267.Palindrome%20Permutation%20II/README.md)", "`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0267](https://leetcode.com/problems/palindrome-permutation-ii)", "[Palindrome Permutation II](/solution/0200-0299/0267.Palindrome%20Permutation%20II/README_EN.md)", "`Backtracking`", "Medium", "\ud83d\udd12"]}, {"question_id": "0266", "frontend_question_id": "0266", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/palindrome-permutation", "url_en": "https://leetcode.com/problems/palindrome-permutation", "relative_path_cn": "/solution/0200-0299/0266.Palindrome%20Permutation/README.md", "relative_path_en": "/solution/0200-0299/0266.Palindrome%20Permutation/README_EN.md", "title_cn": "\u56de\u6587\u6392\u5217", "title_en": "Palindrome Permutation", "question_title_slug": "palindrome-permutation", "content_en": "

    Given a string s, return true if a permutation of the string could form a palindrome.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "code"\nOutput: false\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "aab"\nOutput: true\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "carerac"\nOutput: true\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 5000
    • \n\t
    • s consists of only lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u5224\u65ad\u8be5\u5b57\u7b26\u4e32\u4e2d\u662f\u5426\u53ef\u4ee5\u901a\u8fc7\u91cd\u65b0\u6392\u5217\u7ec4\u5408\uff0c\u5f62\u6210\u4e00\u4e2a\u56de\u6587\u5b57\u7b26\u4e32\u3002

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165: "code"\n\u8f93\u51fa: false
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165: "aab"\n\u8f93\u51fa: true
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165: "carerac"\n\u8f93\u51fa: true
    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canPermutePalindrome(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canPermutePalindrome(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canPermutePalindrome(self, s):\n \"\"\"\n :type s: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canPermutePalindrome(self, s: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canPermutePalindrome(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanPermutePalindrome(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {boolean}\n */\nvar canPermutePalindrome = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Boolean}\ndef can_permute_palindrome(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canPermutePalindrome(_ s: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canPermutePalindrome(s string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canPermutePalindrome(s: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canPermutePalindrome(s: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_permute_palindrome(s: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Boolean\n */\n function canPermutePalindrome($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canPermutePalindrome(s: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-permute-palindrome s)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0266](https://leetcode-cn.com/problems/palindrome-permutation)", "[\u56de\u6587\u6392\u5217](/solution/0200-0299/0266.Palindrome%20Permutation/README.md)", "`\u54c8\u5e0c\u8868`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0266](https://leetcode.com/problems/palindrome-permutation)", "[Palindrome Permutation](/solution/0200-0299/0266.Palindrome%20Permutation/README_EN.md)", "`Hash Table`", "Easy", "\ud83d\udd12"]}, {"question_id": "0265", "frontend_question_id": "0265", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/paint-house-ii", "url_en": "https://leetcode.com/problems/paint-house-ii", "relative_path_cn": "/solution/0200-0299/0265.Paint%20House%20II/README.md", "relative_path_en": "/solution/0200-0299/0265.Paint%20House%20II/README_EN.md", "title_cn": "\u7c89\u5237\u623f\u5b50 II", "title_en": "Paint House II", "question_title_slug": "paint-house-ii", "content_en": "

    There are a row of n houses, each house can be painted with one of the k colors. The cost of painting each house with a certain color is different. You have to paint all the houses such that no two adjacent houses have the same color.

    \n\n

    The cost of painting each house with a certain color is represented by an n x k cost matrix costs.

    \n\n
      \n\t
    • For example, costs[0][0] is the cost of painting house 0 with color 0; costs[1][2] is the cost of painting house 1 with color 2, and so on...
    • \n
    \n\n

    Return the minimum cost to paint all houses.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: costs = [[1,5,3],[2,9,4]]\nOutput: 5\nExplanation:\nPaint house 0 into color 0, paint house 1 into color 2. Minimum cost: 1 + 4 = 5; \nOr paint house 0 into color 2, paint house 1 into color 0. Minimum cost: 3 + 2 = 5.\n
    \n\n

    Example 2:

    \n\n
    \nInput: costs = [[1,3],[2,4]]\nOutput: 5\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • costs.length == n
    • \n\t
    • costs[i].length == k
    • \n\t
    • 1 <= n <= 100
    • \n\t
    • 1 <= k <= 20
    • \n\t
    • 1 <= costs[i][j] <= 20
    • \n
    \n\n

     

    \n

    Follow up: Could you solve it in O(nk) runtime?

    \n", "content_cn": "

    \u5047\u5982\u6709\u4e00\u6392\u623f\u5b50\uff0c\u5171 n \u4e2a\uff0c\u6bcf\u4e2a\u623f\u5b50\u53ef\u4ee5\u88ab\u7c89\u5237\u6210 k \u79cd\u989c\u8272\u4e2d\u7684\u4e00\u79cd\uff0c\u4f60\u9700\u8981\u7c89\u5237\u6240\u6709\u7684\u623f\u5b50\u5e76\u4e14\u4f7f\u5176\u76f8\u90bb\u7684\u4e24\u4e2a\u623f\u5b50\u989c\u8272\u4e0d\u80fd\u76f8\u540c\u3002

    \n\n

    \u5f53\u7136\uff0c\u56e0\u4e3a\u5e02\u573a\u4e0a\u4e0d\u540c\u989c\u8272\u6cb9\u6f06\u7684\u4ef7\u683c\u4e0d\u540c\uff0c\u6240\u4ee5\u623f\u5b50\u7c89\u5237\u6210\u4e0d\u540c\u989c\u8272\u7684\u82b1\u8d39\u6210\u672c\u4e5f\u662f\u4e0d\u540c\u7684\u3002\u6bcf\u4e2a\u623f\u5b50\u7c89\u5237\u6210\u4e0d\u540c\u989c\u8272\u7684\u82b1\u8d39\u662f\u4ee5\u4e00\u4e2a n x k \u7684\u77e9\u9635\u6765\u8868\u793a\u7684\u3002

    \n\n

    \u4f8b\u5982\uff0ccosts[0][0] \u8868\u793a\u7b2c 0 \u53f7\u623f\u5b50\u7c89\u5237\u6210 0 \u53f7\u989c\u8272\u7684\u6210\u672c\u82b1\u8d39\uff1bcosts[1][2] \u8868\u793a\u7b2c 1 \u53f7\u623f\u5b50\u7c89\u5237\u6210 2 \u53f7\u989c\u8272\u7684\u6210\u672c\u82b1\u8d39\uff0c\u4ee5\u6b64\u7c7b\u63a8\u3002\u8bf7\u4f60\u8ba1\u7b97\u51fa\u7c89\u5237\u5b8c\u6240\u6709\u623f\u5b50\u6700\u5c11\u7684\u82b1\u8d39\u6210\u672c\u3002

    \n\n

    \u6ce8\u610f\uff1a

    \n\n

    \u6240\u6709\u82b1\u8d39\u5747\u4e3a\u6b63\u6574\u6570\u3002

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165: [[1,5,3],[2,9,4]]\n\u8f93\u51fa: 5\n\u89e3\u91ca: \u5c06 0 \u53f7\u623f\u5b50\u7c89\u5237\u6210 0 \u53f7\u989c\u8272\uff0c1 \u53f7\u623f\u5b50\u7c89\u5237\u6210 2 \u53f7\u989c\u8272\u3002\u6700\u5c11\u82b1\u8d39: 1 + 4 = 5; \n     \u6216\u8005\u5c06 0 \u53f7\u623f\u5b50\u7c89\u5237\u6210 2 \u53f7\u989c\u8272\uff0c1 \u53f7\u623f\u5b50\u7c89\u5237\u6210 0 \u53f7\u989c\u8272\u3002\u6700\u5c11\u82b1\u8d39: 3 + 2 = 5. \n
    \n\n

    \u8fdb\u9636\uff1a
    \n\u60a8\u80fd\u5426\u5728 O(nk) \u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e0b\u89e3\u51b3\u6b64\u95ee\u9898\uff1f

    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minCostII(vector>& costs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minCostII(int[][] costs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minCostII(self, costs):\n \"\"\"\n :type costs: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minCostII(self, costs: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minCostII(int** costs, int costsSize, int* costsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinCostII(int[][] costs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} costs\n * @return {number}\n */\nvar minCostII = function(costs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} costs\n# @return {Integer}\ndef min_cost_ii(costs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minCostII(_ costs: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minCostII(costs [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minCostII(costs: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minCostII(costs: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_cost_ii(costs: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $costs\n * @return Integer\n */\n function minCostII($costs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minCostII(costs: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-cost-ii costs)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0265](https://leetcode-cn.com/problems/paint-house-ii)", "[\u7c89\u5237\u623f\u5b50 II](/solution/0200-0299/0265.Paint%20House%20II/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0265](https://leetcode.com/problems/paint-house-ii)", "[Paint House II](/solution/0200-0299/0265.Paint%20House%20II/README_EN.md)", "`Dynamic Programming`", "Hard", "\ud83d\udd12"]}, {"question_id": "0264", "frontend_question_id": "0264", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/ugly-number-ii", "url_en": "https://leetcode.com/problems/ugly-number-ii", "relative_path_cn": "/solution/0200-0299/0264.Ugly%20Number%20II/README.md", "relative_path_en": "/solution/0200-0299/0264.Ugly%20Number%20II/README_EN.md", "title_cn": "\u4e11\u6570 II", "title_en": "Ugly Number II", "question_title_slug": "ugly-number-ii", "content_en": "

    An ugly number is a positive integer whose prime factors are limited to 2, 3, and 5.

    \n\n

    Given an integer n, return the nth ugly number.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 10\nOutput: 12\nExplanation: [1, 2, 3, 4, 5, 6, 8, 9, 10, 12] is the sequence of the first 10 ugly numbers.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 1\nOutput: 1\nExplanation: 1 has no prime factors, therefore all of its prime factors are limited to 2, 3, and 5.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 1690
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n \uff0c\u8bf7\u4f60\u627e\u51fa\u5e76\u8fd4\u56de\u7b2c n \u4e2a \u4e11\u6570 \u3002

    \n\n

    \u4e11\u6570 \u5c31\u662f\u53ea\u5305\u542b\u8d28\u56e0\u6570\u00a02\u30013 \u548c/\u6216\u00a05\u00a0\u7684\u6b63\u6574\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 10\n\u8f93\u51fa\uff1a12\n\u89e3\u91ca\uff1a[1, 2, 3, 4, 5, 6, 8, 9, 10, 12] \u662f\u7531\u524d 10 \u4e2a\u4e11\u6570\u7ec4\u6210\u7684\u5e8f\u5217\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a1 \u901a\u5e38\u88ab\u89c6\u4e3a\u4e11\u6570\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 1690
    • \n
    \n", "tags_en": ["Heap", "Math", "Dynamic Programming"], "tags_cn": ["\u5806", "\u6570\u5b66", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int nthUglyNumber(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def nthUglyNumber(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def nthUglyNumber(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint nthUglyNumber(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NthUglyNumber(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar nthUglyNumber = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef nth_ugly_number(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func nthUglyNumber(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func nthUglyNumber(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def nthUglyNumber(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun nthUglyNumber(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn nth_ugly_number(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function nthUglyNumber($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function nthUglyNumber(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (nth-ugly-number n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0264](https://leetcode-cn.com/problems/ugly-number-ii)", "[\u4e11\u6570 II](/solution/0200-0299/0264.Ugly%20Number%20II/README.md)", "`\u5806`,`\u6570\u5b66`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0264](https://leetcode.com/problems/ugly-number-ii)", "[Ugly Number II](/solution/0200-0299/0264.Ugly%20Number%20II/README_EN.md)", "`Heap`,`Math`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0263", "frontend_question_id": "0263", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/ugly-number", "url_en": "https://leetcode.com/problems/ugly-number", "relative_path_cn": "/solution/0200-0299/0263.Ugly%20Number/README.md", "relative_path_en": "/solution/0200-0299/0263.Ugly%20Number/README_EN.md", "title_cn": "\u4e11\u6570", "title_en": "Ugly Number", "question_title_slug": "ugly-number", "content_en": "

    An ugly number is a positive integer whose prime factors are limited to 2, 3, and 5.

    \n\n

    Given an integer n, return true if n is an ugly number.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 6\nOutput: true\nExplanation: 6 = 2 × 3
    \n\n

    Example 2:

    \n\n
    \nInput: n = 8\nOutput: true\nExplanation: 8 = 2 × 2 × 2\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 14\nOutput: false\nExplanation: 14 is not ugly since it includes the prime factor 7.\n
    \n\n

    Example 4:

    \n\n
    \nInput: n = 1\nOutput: true\nExplanation: 1 has no prime factors, therefore all of its prime factors are limited to 2, 3, and 5.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • -231 <= n <= 231 - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n \uff0c\u8bf7\u4f60\u5224\u65ad n \u662f\u5426\u4e3a \u4e11\u6570 \u3002\u5982\u679c\u662f\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n

    \u4e11\u6570 \u5c31\u662f\u53ea\u5305\u542b\u8d28\u56e0\u6570\u00a02\u30013 \u548c/\u6216\u00a05\u00a0\u7684\u6b63\u6574\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 6\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a6 = 2 \u00d7 3
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 8\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a8 = 2 \u00d7 2 \u00d7 2\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 14\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a14 \u4e0d\u662f\u4e11\u6570\uff0c\u56e0\u4e3a\u5b83\u5305\u542b\u4e86\u53e6\u5916\u4e00\u4e2a\u8d28\u56e0\u6570\u00a07 \u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a1 \u901a\u5e38\u88ab\u89c6\u4e3a\u4e11\u6570\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • -231 <= n <= 231 - 1
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isUgly(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isUgly(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isUgly(self, n):\n \"\"\"\n :type n: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isUgly(self, n: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isUgly(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsUgly(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {boolean}\n */\nvar isUgly = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Boolean}\ndef is_ugly(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isUgly(_ n: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isUgly(n int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isUgly(n: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isUgly(n: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_ugly(n: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Boolean\n */\n function isUgly($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isUgly(n: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-ugly n)\n (-> exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0263](https://leetcode-cn.com/problems/ugly-number)", "[\u4e11\u6570](/solution/0200-0299/0263.Ugly%20Number/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0263](https://leetcode.com/problems/ugly-number)", "[Ugly Number](/solution/0200-0299/0263.Ugly%20Number/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "0262", "frontend_question_id": "0262", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/trips-and-users", "url_en": "https://leetcode.com/problems/trips-and-users", "relative_path_cn": "/solution/0200-0299/0262.Trips%20and%20Users/README.md", "relative_path_en": "/solution/0200-0299/0262.Trips%20and%20Users/README_EN.md", "title_cn": "\u884c\u7a0b\u548c\u7528\u6237", "title_en": "Trips and Users", "question_title_slug": "trips-and-users", "content_en": "

    Table: Trips

    \n\n
    \n+-------------+----------+\n| Column Name | Type     |\n+-------------+----------+\n| Id          | int      |\n| Client_Id   | int      |\n| Driver_Id   | int      |\n| City_Id     | int      |\n| Status      | enum     |\n| Request_at  | date     |     \n+-------------+----------+\nId is the primary key for this table.\nThe table holds all taxi trips. Each trip has a unique Id, while Client_Id and Driver_Id are foreign keys to the Users_Id at the Users table.\nStatus is an ENUM type of (‘completed’, ‘cancelled_by_driver’, ‘cancelled_by_client’).\n
    \n\n

     

    \n\n

    Table: Users

    \n\n
    \n+-------------+----------+\n| Column Name | Type     |\n+-------------+----------+\n| Users_Id    | int      |\n| Banned      | enum     |\n| Role        | enum     |\n+-------------+----------+\nUsers_Id is the primary key for this table.\nThe table holds all users. Each user has a unique Users_Id, and Role is an ENUM type of (‘client’, ‘driver’, ‘partner’).\nStatus is an ENUM type of (‘Yes’, ‘No’).\n
    \n\n

     

    \n\n

    Write a SQL query to find the cancellation rate of requests with unbanned users (both client and driver must not be banned) each day between "2013-10-01" and "2013-10-03".

    \n\n

    The cancellation rate is computed by dividing the number of canceled (by client or driver) requests with unbanned users by the total number of requests with unbanned users on that day.

    \n\n

    Return the result table in any order. Round Cancellation Rate to two decimal points.

    \n\n

    The query result format is in the following example:

    \n\n

     

    \n\n
    \nTrips table:\n+----+-----------+-----------+---------+---------------------+------------+\n| Id | Client_Id | Driver_Id | City_Id | Status              | Request_at |\n+----+-----------+-----------+---------+---------------------+------------+\n| 1  | 1         | 10        | 1       | completed           | 2013-10-01 |\n| 2  | 2         | 11        | 1       | cancelled_by_driver | 2013-10-01 |\n| 3  | 3         | 12        | 6       | completed           | 2013-10-01 |\n| 4  | 4         | 13        | 6       | cancelled_by_client | 2013-10-01 |\n| 5  | 1         | 10        | 1       | completed           | 2013-10-02 |\n| 6  | 2         | 11        | 6       | completed           | 2013-10-02 |\n| 7  | 3         | 12        | 6       | completed           | 2013-10-02 |\n| 8  | 2         | 12        | 12      | completed           | 2013-10-03 |\n| 9  | 3         | 10        | 12      | completed           | 2013-10-03 |\n| 10 | 4         | 13        | 12      | cancelled_by_driver | 2013-10-03 |\n+----+-----------+-----------+---------+---------------------+------------+\n\nUsers table:\n+----------+--------+--------+\n| Users_Id | Banned | Role   |\n+----------+--------+--------+\n| 1        | No     | client |\n| 2        | Yes    | client |\n| 3        | No     | client |\n| 4        | No     | client |\n| 10       | No     | driver |\n| 11       | No     | driver |\n| 12       | No     | driver |\n| 13       | No     | driver |\n+----------+--------+--------+\n\nResult table:\n+------------+-------------------+\n| Day        | Cancellation Rate |\n+------------+-------------------+\n| 2013-10-01 | 0.33              |\n| 2013-10-02 | 0.00              |\n| 2013-10-03 | 0.50              |\n+------------+-------------------+\n\nOn 2013-10-01:\n  - There were 4 requests in total, 2 of which were canceled.\n  - However, the request with Id=2 was made by a banned client (User_Id=2), so it is ignored in the calculation.\n  - Hence there are 3 unbanned requests in total, 1 of which was canceled.\n  - The Cancellation Rate is (1 / 3) = 0.33\nOn 2013-10-02:\n  - There were 3 requests in total, 0 of which were canceled.\n  - The request with Id=6 was made by a banned client, so it is ignored.\n  - Hence there are 2 unbanned requests in total, 0 of which were canceled.\n  - The Cancellation Rate is (0 / 2) = 0.00\nOn 2013-10-03:\n  - There were 3 requests in total, 1 of which was canceled.\n  - The request with Id=8 was made by a banned client, so it is ignored.\n  - Hence there are 2 unbanned request in total, 1 of which were canceled.\n  - The Cancellation Rate is (1 / 2) = 0.50\n
    \n", "content_cn": "\u8868\uff1aTrips\n
    \n
    \n
    \n+-------------+----------+\n| Column Name | Type     |\n+-------------+----------+\n| Id          | int      |\n| Client_Id   | int      |\n| Driver_Id   | int      |\n| City_Id     | int      |\n| Status      | enum     |\n| Request_at  | date     |     \n+-------------+----------+\nId \u662f\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\u3002\n\u8fd9\u5f20\u8868\u4e2d\u5b58\u6240\u6709\u51fa\u79df\u8f66\u7684\u884c\u7a0b\u4fe1\u606f\u3002\u6bcf\u6bb5\u884c\u7a0b\u6709\u552f\u4e00 Id \uff0c\u5176\u4e2d Client_Id \u548c Driver_Id \u662f Users \u8868\u4e2d Users_Id \u7684\u5916\u952e\u3002\nStatus \u662f\u4e00\u4e2a\u8868\u793a\u884c\u7a0b\u72b6\u6001\u7684\u679a\u4e3e\u7c7b\u578b\uff0c\u679a\u4e3e\u6210\u5458\u4e3a(\u2018completed\u2019, \u2018cancelled_by_driver\u2019, \u2018cancelled_by_client\u2019) \u3002\n
    \n\n

    \u00a0

    \n\n
    \n
    \n

    \u8868\uff1aUsers

    \n
    \n
    \n\n
    \n+-------------+----------+\n| Column Name | Type     |\n+-------------+----------+\n| Users_Id    | int      |\n| Banned      | enum     |\n| Role        | enum     |\n+-------------+----------+\nUsers_Id \u662f\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\u3002\n\u8fd9\u5f20\u8868\u4e2d\u5b58\u6240\u6709\u7528\u6237\uff0c\u6bcf\u4e2a\u7528\u6237\u90fd\u6709\u4e00\u4e2a\u552f\u4e00\u7684 Users_Id \uff0cRole \u662f\u4e00\u4e2a\u8868\u793a\u7528\u6237\u8eab\u4efd\u7684\u679a\u4e3e\u7c7b\u578b\uff0c\u679a\u4e3e\u6210\u5458\u4e3a (\u2018client\u2019, \u2018driver\u2019, \u2018partner\u2019) \u3002\nBanned \u662f\u4e00\u4e2a\u8868\u793a\u7528\u6237\u662f\u5426\u88ab\u7981\u6b62\u7684\u679a\u4e3e\u7c7b\u578b\uff0c\u679a\u4e3e\u6210\u5458\u4e3a (\u2018Yes\u2019, \u2018No\u2019) \u3002\n
    \n\n

    \u00a0

    \n\n

    \u5199\u4e00\u6bb5 SQL \u8bed\u53e5\u67e5\u51fa\u00a0\"2013-10-01\"\u00a0\u81f3\u00a0\"2013-10-03\"\u00a0\u671f\u95f4\u975e\u7981\u6b62\u7528\u6237\uff08\u4e58\u5ba2\u548c\u53f8\u673a\u90fd\u5fc5\u987b\u672a\u88ab\u7981\u6b62\uff09\u7684\u53d6\u6d88\u7387\u3002\u975e\u7981\u6b62\u7528\u6237\u5373 Banned \u4e3a No \u7684\u7528\u6237\uff0c\u7981\u6b62\u7528\u6237\u5373 Banned \u4e3a Yes \u7684\u7528\u6237\u3002

    \n\n

    \u53d6\u6d88\u7387 \u7684\u8ba1\u7b97\u65b9\u5f0f\u5982\u4e0b\uff1a(\u88ab\u53f8\u673a\u6216\u4e58\u5ba2\u53d6\u6d88\u7684\u975e\u7981\u6b62\u7528\u6237\u751f\u6210\u7684\u8ba2\u5355\u6570\u91cf) / (\u975e\u7981\u6b62\u7528\u6237\u751f\u6210\u7684\u8ba2\u5355\u603b\u6570)\u3002

    \n\n

    \u8fd4\u56de\u7ed3\u679c\u8868\u4e2d\u7684\u6570\u636e\u53ef\u4ee5\u6309\u4efb\u610f\u987a\u5e8f\u7ec4\u7ec7\u3002\u5176\u4e2d\u53d6\u6d88\u7387 Cancellation Rate \u9700\u8981\u56db\u820d\u4e94\u5165\u4fdd\u7559 \u4e24\u4f4d\u5c0f\u6570 \u3002

    \n\n

    \u00a0

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u6240\u793a\uff1a

    \n\n
    \nTrips \u8868\uff1a\n+----+-----------+-----------+---------+---------------------+------------+\n| Id | Client_Id | Driver_Id | City_Id | Status              | Request_at |\n+----+-----------+-----------+---------+---------------------+------------+\n| 1  | 1         | 10        | 1       | completed           | 2013-10-01 |\n| 2  | 2         | 11        | 1       | cancelled_by_driver | 2013-10-01 |\n| 3  | 3         | 12        | 6       | completed           | 2013-10-01 |\n| 4  | 4         | 13        | 6       | cancelled_by_client | 2013-10-01 |\n| 5  | 1         | 10        | 1       | completed           | 2013-10-02 |\n| 6  | 2         | 11        | 6       | completed           | 2013-10-02 |\n| 7  | 3         | 12        | 6       | completed           | 2013-10-02 |\n| 8  | 2         | 12        | 12      | completed           | 2013-10-03 |\n| 9  | 3         | 10        | 12      | completed           | 2013-10-03 |\n| 10 | 4         | 13        | 12      | cancelled_by_driver | 2013-10-03 |\n+----+-----------+-----------+---------+---------------------+------------+\n\nUsers \u8868\uff1a\n+----------+--------+--------+\n| Users_Id | Banned | Role   |\n+----------+--------+--------+\n| 1        | No     | client |\n| 2        | Yes    | client |\n| 3        | No     | client |\n| 4        | No     | client |\n| 10       | No     | driver |\n| 11       | No     | driver |\n| 12       | No     | driver |\n| 13       | No     | driver |\n+----------+--------+--------+\n\nResult \u8868\uff1a\n+------------+-------------------+\n| Day        | Cancellation Rate |\n+------------+-------------------+\n| 2013-10-01 | 0.33              |\n| 2013-10-02 | 0.00              |\n| 2013-10-03 | 0.50              |\n+------------+-------------------+\n\n2013-10-01\uff1a\n  - \u5171\u6709 4 \u6761\u8bf7\u6c42\uff0c\u5176\u4e2d 2 \u6761\u53d6\u6d88\u3002\n  - \u7136\u800c\uff0cId=2 \u7684\u8bf7\u6c42\u662f\u7531\u7981\u6b62\u7528\u6237\uff08User_Id=2\uff09\u53d1\u51fa\u7684\uff0c\u6240\u4ee5\u8ba1\u7b97\u65f6\u5e94\u5f53\u5ffd\u7565\u5b83\u3002\n  - \u56e0\u6b64\uff0c\u603b\u5171\u6709 3 \u6761\u975e\u7981\u6b62\u8bf7\u6c42\u53c2\u4e0e\u8ba1\u7b97\uff0c\u5176\u4e2d 1 \u6761\u53d6\u6d88\u3002\n  - \u53d6\u6d88\u7387\u4e3a (1 / 3) = 0.33\n2013-10-02\uff1a\n  - \u5171\u6709 3 \u6761\u8bf7\u6c42\uff0c\u5176\u4e2d 0 \u6761\u53d6\u6d88\u3002\n  - \u7136\u800c\uff0cId=6 \u7684\u8bf7\u6c42\u662f\u7531\u7981\u6b62\u7528\u6237\u53d1\u51fa\u7684\uff0c\u6240\u4ee5\u8ba1\u7b97\u65f6\u5e94\u5f53\u5ffd\u7565\u5b83\u3002\n  - \u56e0\u6b64\uff0c\u603b\u5171\u6709 2 \u6761\u975e\u7981\u6b62\u8bf7\u6c42\u53c2\u4e0e\u8ba1\u7b97\uff0c\u5176\u4e2d 0 \u6761\u53d6\u6d88\u3002\n  - \u53d6\u6d88\u7387\u4e3a (0 / 2) = 0.00\n2013-10-03\uff1a\n  - \u5171\u6709 3 \u6761\u8bf7\u6c42\uff0c\u5176\u4e2d 1 \u6761\u53d6\u6d88\u3002\n  - \u7136\u800c\uff0cId=8 \u7684\u8bf7\u6c42\u662f\u7531\u7981\u6b62\u7528\u6237\u53d1\u51fa\u7684\uff0c\u6240\u4ee5\u8ba1\u7b97\u65f6\u5e94\u5f53\u5ffd\u7565\u5b83\u3002\n  - \u56e0\u6b64\uff0c\u603b\u5171\u6709 2 \u6761\u975e\u7981\u6b62\u8bf7\u6c42\u53c2\u4e0e\u8ba1\u7b97\uff0c\u5176\u4e2d 1 \u6761\u53d6\u6d88\u3002\n  - \u53d6\u6d88\u7387\u4e3a (1 / 2) = 0.50\n
    \n
    \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0262](https://leetcode-cn.com/problems/trips-and-users)", "[\u884c\u7a0b\u548c\u7528\u6237](/solution/0200-0299/0262.Trips%20and%20Users/README.md)", "", "\u56f0\u96be", ""], "md_table_row_en": ["[0262](https://leetcode.com/problems/trips-and-users)", "[Trips and Users](/solution/0200-0299/0262.Trips%20and%20Users/README_EN.md)", "", "Hard", ""]}, {"question_id": "0261", "frontend_question_id": "0261", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/graph-valid-tree", "url_en": "https://leetcode.com/problems/graph-valid-tree", "relative_path_cn": "/solution/0200-0299/0261.Graph%20Valid%20Tree/README.md", "relative_path_en": "/solution/0200-0299/0261.Graph%20Valid%20Tree/README_EN.md", "title_cn": "\u4ee5\u56fe\u5224\u6811", "title_en": "Graph Valid Tree", "question_title_slug": "graph-valid-tree", "content_en": "

    You have a graph of n nodes labeled from 0 to n - 1. You are given an integer n and a list of edges where edges[i] = [ai, bi] indicates that there is an undirected edge between nodes ai and bi in the graph.

    \n\n

    Return true if the edges of the given graph make up a valid tree, and false otherwise.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: n = 5, edges = [[0,1],[0,2],[0,3],[1,4]]\nOutput: true\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: n = 5, edges = [[0,1],[1,2],[2,3],[1,3],[1,4]]\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= 2000 <= n
    • \n\t
    • 0 <= edges.length <= 5000
    • \n\t
    • edges[i].length == 2
    • \n\t
    • 0 <= ai, bi < n
    • \n\t
    • ai != bi
    • \n\t
    • There are no self-loops or repeated edges.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4ece 0 \u5230 n-1 \u6807\u53f7\u7684 n \u4e2a\u7ed3\u70b9\uff0c\u548c\u4e00\u4e2a\u65e0\u5411\u8fb9\u5217\u8868\uff08\u6bcf\u6761\u8fb9\u4ee5\u7ed3\u70b9\u5bf9\u6765\u8868\u793a\uff09\uff0c\u8bf7\u7f16\u5199\u4e00\u4e2a\u51fd\u6570\u7528\u6765\u5224\u65ad\u8fd9\u4e9b\u8fb9\u662f\u5426\u80fd\u591f\u5f62\u6210\u4e00\u4e2a\u5408\u6cd5\u6709\u6548\u7684\u6811\u7ed3\u6784\u3002

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165: n = 5, \u8fb9\u5217\u8868 edges = [[0,1], [0,2], [0,3], [1,4]]\n\u8f93\u51fa: true
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: n = 5, \u8fb9\u5217\u8868 edges = [[0,1], [1,2], [2,3], [1,3], [1,4]]\n\u8f93\u51fa: false
    \n\n

    \u6ce8\u610f\uff1a\u4f60\u53ef\u4ee5\u5047\u5b9a\u8fb9\u5217\u8868 edges \u4e2d\u4e0d\u4f1a\u51fa\u73b0\u91cd\u590d\u7684\u8fb9\u3002\u7531\u4e8e\u6240\u6709\u7684\u8fb9\u662f\u65e0\u5411\u8fb9\uff0c\u8fb9 [0,1] \u548c\u8fb9 [1,0] \u662f\u76f8\u540c\u7684\uff0c\u56e0\u6b64\u4e0d\u4f1a\u540c\u65f6\u51fa\u73b0\u5728\u8fb9\u5217\u8868 edges \u4e2d\u3002

    \n", "tags_en": ["Depth-first Search", "Breadth-first Search", "Union Find", "Graph"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e76\u67e5\u96c6", "\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool validTree(int n, vector>& edges) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean validTree(int n, int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def validTree(self, n, edges):\n \"\"\"\n :type n: int\n :type edges: List[List[int]]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def validTree(self, n: int, edges: List[List[int]]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool validTree(int n, int** edges, int edgesSize, int* edgesColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool ValidTree(int n, int[][] edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number[][]} edges\n * @return {boolean}\n */\nvar validTree = function(n, edges) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer[][]} edges\n# @return {Boolean}\ndef valid_tree(n, edges)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func validTree(_ n: Int, _ edges: [[Int]]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func validTree(n int, edges [][]int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def validTree(n: Int, edges: Array[Array[Int]]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun validTree(n: Int, edges: Array): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn valid_tree(n: i32, edges: Vec>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer[][] $edges\n * @return Boolean\n */\n function validTree($n, $edges) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function validTree(n: number, edges: number[][]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (valid-tree n edges)\n (-> exact-integer? (listof (listof exact-integer?)) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0261](https://leetcode-cn.com/problems/graph-valid-tree)", "[\u4ee5\u56fe\u5224\u6811](/solution/0200-0299/0261.Graph%20Valid%20Tree/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e76\u67e5\u96c6`,`\u56fe`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0261](https://leetcode.com/problems/graph-valid-tree)", "[Graph Valid Tree](/solution/0200-0299/0261.Graph%20Valid%20Tree/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`,`Union Find`,`Graph`", "Medium", "\ud83d\udd12"]}, {"question_id": "0260", "frontend_question_id": "0260", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/single-number-iii", "url_en": "https://leetcode.com/problems/single-number-iii", "relative_path_cn": "/solution/0200-0299/0260.Single%20Number%20III/README.md", "relative_path_en": "/solution/0200-0299/0260.Single%20Number%20III/README_EN.md", "title_cn": "\u53ea\u51fa\u73b0\u4e00\u6b21\u7684\u6570\u5b57 III", "title_en": "Single Number III", "question_title_slug": "single-number-iii", "content_en": "

    Given an integer array nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in any order.

    \n\n

    You must write an algorithm that runs in linear runtime complexity and uses only constant extra space.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,1,3,2,5]\nOutput: [3,5]\nExplanation:  [5, 3] is also a valid answer.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [-1,0]\nOutput: [-1,0]\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [0,1]\nOutput: [1,0]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= nums.length <= 3 * 104
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n\t
    • Each integer in nums will appear twice, only two integers will appear once.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0nums\uff0c\u5176\u4e2d\u6070\u597d\u6709\u4e24\u4e2a\u5143\u7d20\u53ea\u51fa\u73b0\u4e00\u6b21\uff0c\u5176\u4f59\u6240\u6709\u5143\u7d20\u5747\u51fa\u73b0\u4e24\u6b21\u3002 \u627e\u51fa\u53ea\u51fa\u73b0\u4e00\u6b21\u7684\u90a3\u4e24\u4e2a\u5143\u7d20\u3002\u4f60\u53ef\u4ee5\u6309 \u4efb\u610f\u987a\u5e8f \u8fd4\u56de\u7b54\u6848\u3002

    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u7684\u7b97\u6cd5\u5e94\u8be5\u5177\u6709\u7ebf\u6027\u65f6\u95f4\u590d\u6742\u5ea6\u3002\u4f60\u80fd\u5426\u4ec5\u4f7f\u7528\u5e38\u6570\u7a7a\u95f4\u590d\u6742\u5ea6\u6765\u5b9e\u73b0\uff1f

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,1,3,2,5]\n\u8f93\u51fa\uff1a[3,5]\n\u89e3\u91ca\uff1a[5, 3] \u4e5f\u662f\u6709\u6548\u7684\u7b54\u6848\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [-1,0]\n\u8f93\u51fa\uff1a[-1,0]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [0,1]\n\u8f93\u51fa\uff1a[1,0]\n
    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= nums.length <= 3 * 104
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n\t
    • \u9664\u4e24\u4e2a\u53ea\u51fa\u73b0\u4e00\u6b21\u7684\u6574\u6570\u5916\uff0cnums \u4e2d\u7684\u5176\u4ed6\u6570\u5b57\u90fd\u51fa\u73b0\u4e24\u6b21
    • \n
    \n", "tags_en": ["Bit Manipulation"], "tags_cn": ["\u4f4d\u8fd0\u7b97"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector singleNumber(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] singleNumber(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def singleNumber(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def singleNumber(self, nums: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* singleNumber(int* nums, int numsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] SingleNumber(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar singleNumber = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer[]}\ndef single_number(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func singleNumber(_ nums: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func singleNumber(nums []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def singleNumber(nums: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun singleNumber(nums: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn single_number(nums: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer[]\n */\n function singleNumber($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function singleNumber(nums: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (single-number nums)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0260](https://leetcode-cn.com/problems/single-number-iii)", "[\u53ea\u51fa\u73b0\u4e00\u6b21\u7684\u6570\u5b57 III](/solution/0200-0299/0260.Single%20Number%20III/README.md)", "`\u4f4d\u8fd0\u7b97`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0260](https://leetcode.com/problems/single-number-iii)", "[Single Number III](/solution/0200-0299/0260.Single%20Number%20III/README_EN.md)", "`Bit Manipulation`", "Medium", ""]}, {"question_id": "0259", "frontend_question_id": "0259", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/3sum-smaller", "url_en": "https://leetcode.com/problems/3sum-smaller", "relative_path_cn": "/solution/0200-0299/0259.3Sum%20Smaller/README.md", "relative_path_en": "/solution/0200-0299/0259.3Sum%20Smaller/README_EN.md", "title_cn": "\u8f83\u5c0f\u7684\u4e09\u6570\u4e4b\u548c", "title_en": "3Sum Smaller", "question_title_slug": "3sum-smaller", "content_en": "

    Given an array of n integers nums and an integer target, find the number of index triplets i, j, k with 0 <= i < j < k < n that satisfy the condition nums[i] + nums[j] + nums[k] < target.

    \n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [-2,0,1,3], target = 2\nOutput: 2\nExplanation: Because there are two triplets which sums are less than 2:\n[-2,0,1]\n[-2,0,3]\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [], target = 0\nOutput: 0\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [0], target = 0\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 0 <= n <= 3500
    • \n\t
    • -100 <= nums[i] <= 100
    • \n\t
    • -100 <= target <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u6574\u6570\u6570\u7ec4\u548c\u4e00\u4e2a\u76ee\u6807\u503c target\uff0c\u5bfb\u627e\u80fd\u591f\u4f7f\u6761\u4ef6 nums[i] + nums[j] + nums[k] < target \u6210\u7acb\u7684\u4e09\u5143\u7ec4  i, j, k \u4e2a\u6570\uff080 <= i < j < k < n\uff09\u3002

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165: nums = [-2,0,1,3], target = 2\n\u8f93\u51fa: 2 \n\u89e3\u91ca: \u56e0\u4e3a\u4e00\u5171\u6709\u4e24\u4e2a\u4e09\u5143\u7ec4\u6ee1\u8db3\u7d2f\u52a0\u548c\u5c0f\u4e8e 2:\n     [-2,0,1]\n     [-2,0,3]\n
    \n\n

    \u8fdb\u9636\uff1a\u662f\u5426\u80fd\u5728 O(n2) \u7684\u65f6\u95f4\u590d\u6742\u5ea6\u5185\u89e3\u51b3\uff1f

    \n", "tags_en": ["Array", "Two Pointers"], "tags_cn": ["\u6570\u7ec4", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int threeSumSmaller(vector& nums, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int threeSumSmaller(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def threeSumSmaller(self, nums, target):\n \"\"\"\n :type nums: List[int]\n :type target: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def threeSumSmaller(self, nums: List[int], target: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint threeSumSmaller(int* nums, int numsSize, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ThreeSumSmaller(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} target\n * @return {number}\n */\nvar threeSumSmaller = function(nums, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} target\n# @return {Integer}\ndef three_sum_smaller(nums, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func threeSumSmaller(_ nums: [Int], _ target: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func threeSumSmaller(nums []int, target int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def threeSumSmaller(nums: Array[Int], target: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun threeSumSmaller(nums: IntArray, target: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn three_sum_smaller(nums: Vec, target: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $target\n * @return Integer\n */\n function threeSumSmaller($nums, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function threeSumSmaller(nums: number[], target: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (three-sum-smaller nums target)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0259](https://leetcode-cn.com/problems/3sum-smaller)", "[\u8f83\u5c0f\u7684\u4e09\u6570\u4e4b\u548c](/solution/0200-0299/0259.3Sum%20Smaller/README.md)", "`\u6570\u7ec4`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0259](https://leetcode.com/problems/3sum-smaller)", "[3Sum Smaller](/solution/0200-0299/0259.3Sum%20Smaller/README_EN.md)", "`Array`,`Two Pointers`", "Medium", "\ud83d\udd12"]}, {"question_id": "0258", "frontend_question_id": "0258", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/add-digits", "url_en": "https://leetcode.com/problems/add-digits", "relative_path_cn": "/solution/0200-0299/0258.Add%20Digits/README.md", "relative_path_en": "/solution/0200-0299/0258.Add%20Digits/README_EN.md", "title_cn": "\u5404\u4f4d\u76f8\u52a0", "title_en": "Add Digits", "question_title_slug": "add-digits", "content_en": "

    Given an integer num, repeatedly add all its digits until the result has only one digit, and return it.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: num = 38\nOutput: 2\nExplanation: The process is\n38 --> 3 + 8 --> 11\n11 --> 1 + 1 --> 2 \nSince 2 has only one digit, return it.\n
    \n\n

    Example 2:

    \n\n
    \nInput: num = 0\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= num <= 231 - 1
    • \n
    \n\n

     

    \n

    Follow up: Could you do it without any loop/recursion in O(1) runtime?

    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u8d1f\u6574\u6570 num\uff0c\u53cd\u590d\u5c06\u5404\u4e2a\u4f4d\u4e0a\u7684\u6570\u5b57\u76f8\u52a0\uff0c\u76f4\u5230\u7ed3\u679c\u4e3a\u4e00\u4f4d\u6570\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: 38\n\u8f93\u51fa: 2 \n\u89e3\u91ca: \u5404\u4f4d\u76f8\u52a0\u7684\u8fc7\u7a0b\u4e3a\uff1a3 + 8 = 11, 1 + 1 = 2\u3002 \u7531\u4e8e 2 \u662f\u4e00\u4f4d\u6570\uff0c\u6240\u4ee5\u8fd4\u56de 2\u3002\n
    \n\n

    \u8fdb\u9636:
    \n\u4f60\u53ef\u4ee5\u4e0d\u4f7f\u7528\u5faa\u73af\u6216\u8005\u9012\u5f52\uff0c\u4e14\u5728 O(1) \u65f6\u95f4\u590d\u6742\u5ea6\u5185\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u5417\uff1f

    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int addDigits(int num) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int addDigits(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def addDigits(self, num):\n \"\"\"\n :type num: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def addDigits(self, num: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint addDigits(int num){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int AddDigits(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} num\n * @return {number}\n */\nvar addDigits = function(num) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} num\n# @return {Integer}\ndef add_digits(num)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func addDigits(_ num: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func addDigits(num int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def addDigits(num: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun addDigits(num: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn add_digits(num: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $num\n * @return Integer\n */\n function addDigits($num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function addDigits(num: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (add-digits num)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0258](https://leetcode-cn.com/problems/add-digits)", "[\u5404\u4f4d\u76f8\u52a0](/solution/0200-0299/0258.Add%20Digits/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0258](https://leetcode.com/problems/add-digits)", "[Add Digits](/solution/0200-0299/0258.Add%20Digits/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "0257", "frontend_question_id": "0257", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/binary-tree-paths", "url_en": "https://leetcode.com/problems/binary-tree-paths", "relative_path_cn": "/solution/0200-0299/0257.Binary%20Tree%20Paths/README.md", "relative_path_en": "/solution/0200-0299/0257.Binary%20Tree%20Paths/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u7684\u6240\u6709\u8def\u5f84", "title_en": "Binary Tree Paths", "question_title_slug": "binary-tree-paths", "content_en": "

    Given the root of a binary tree, return all root-to-leaf paths in any order.

    \n\n

    A leaf is a node with no children.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,2,3,null,5]\nOutput: ["1->2->5","1->3"]\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = [1]\nOutput: ["1"]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 100].
    • \n\t
    • -100 <= Node.val <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811\uff0c\u8fd4\u56de\u6240\u6709\u4ece\u6839\u8282\u70b9\u5230\u53f6\u5b50\u8282\u70b9\u7684\u8def\u5f84\u3002

    \n\n

    \u8bf4\u660e: \u53f6\u5b50\u8282\u70b9\u662f\u6307\u6ca1\u6709\u5b50\u8282\u70b9\u7684\u8282\u70b9\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165:\n\n   1\n /   \\\n2     3\n \\\n  5\n\n\u8f93\u51fa: ["1->2->5", "1->3"]\n\n\u89e3\u91ca: \u6240\u6709\u6839\u8282\u70b9\u5230\u53f6\u5b50\u8282\u70b9\u7684\u8def\u5f84\u4e3a: 1->2->5, 1->3
    \n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector binaryTreePaths(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public List binaryTreePaths(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def binaryTreePaths(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def binaryTreePaths(self, root: TreeNode) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** binaryTreePaths(struct TreeNode* root, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public IList BinaryTreePaths(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {string[]}\n */\nvar binaryTreePaths = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {String[]}\ndef binary_tree_paths(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func binaryTreePaths(_ root: TreeNode?) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc binaryTreePaths(root *TreeNode) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def binaryTreePaths(root: TreeNode): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun binaryTreePaths(root: TreeNode?): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn binary_tree_paths(root: Option>>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return String[]\n */\n function binaryTreePaths($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction binaryTreePaths(root: TreeNode | null): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (binary-tree-paths root)\n (-> (or/c tree-node? #f) (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0257](https://leetcode-cn.com/problems/binary-tree-paths)", "[\u4e8c\u53c9\u6811\u7684\u6240\u6709\u8def\u5f84](/solution/0200-0299/0257.Binary%20Tree%20Paths/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u7b80\u5355", ""], "md_table_row_en": ["[0257](https://leetcode.com/problems/binary-tree-paths)", "[Binary Tree Paths](/solution/0200-0299/0257.Binary%20Tree%20Paths/README_EN.md)", "`Tree`,`Depth-first Search`", "Easy", ""]}, {"question_id": "0256", "frontend_question_id": "0256", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/paint-house", "url_en": "https://leetcode.com/problems/paint-house", "relative_path_cn": "/solution/0200-0299/0256.Paint%20House/README.md", "relative_path_en": "/solution/0200-0299/0256.Paint%20House/README_EN.md", "title_cn": "\u7c89\u5237\u623f\u5b50", "title_en": "Paint House", "question_title_slug": "paint-house", "content_en": "

    There is a row of n houses, where each house can be painted one of three colors: red, blue, or green. The cost of painting each house with a certain color is different. You have to paint all the houses such that no two adjacent houses have the same color.

    \n\n

    The cost of painting each house with a certain color is represented by an n x 3 cost matrix costs.

    \n\n
      \n\t
    • For example, costs[0][0] is the cost of painting house 0 with the color red; costs[1][2] is the cost of painting house 1 with color green, and so on...
    • \n
    \n\n

    Return the minimum cost to paint all houses.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: costs = [[17,2,17],[16,16,5],[14,3,19]]\nOutput: 10\nExplanation: Paint house 0 into blue, paint house 1 into green, paint house 2 into blue.\nMinimum cost: 2 + 5 + 3 = 10.\n
    \n\n

    Example 2:

    \n\n
    \nInput: costs = [[7,6,2]]\nOutput: 2\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • costs.length == n
    • \n\t
    • costs[i].length == 3
    • \n\t
    • 1 <= n <= 100
    • \n\t
    • 1 <= costs[i][j] <= 20
    • \n
    \n", "content_cn": "

    \u5047\u5982\u6709\u4e00\u6392\u623f\u5b50\uff0c\u5171 n \u4e2a\uff0c\u6bcf\u4e2a\u623f\u5b50\u53ef\u4ee5\u88ab\u7c89\u5237\u6210\u7ea2\u8272\u3001\u84dd\u8272\u6216\u8005\u7eff\u8272\u8fd9\u4e09\u79cd\u989c\u8272\u4e2d\u7684\u4e00\u79cd\uff0c\u4f60\u9700\u8981\u7c89\u5237\u6240\u6709\u7684\u623f\u5b50\u5e76\u4e14\u4f7f\u5176\u76f8\u90bb\u7684\u4e24\u4e2a\u623f\u5b50\u989c\u8272\u4e0d\u80fd\u76f8\u540c\u3002

    \n\n

    \u5f53\u7136\uff0c\u56e0\u4e3a\u5e02\u573a\u4e0a\u4e0d\u540c\u989c\u8272\u6cb9\u6f06\u7684\u4ef7\u683c\u4e0d\u540c\uff0c\u6240\u4ee5\u623f\u5b50\u7c89\u5237\u6210\u4e0d\u540c\u989c\u8272\u7684\u82b1\u8d39\u6210\u672c\u4e5f\u662f\u4e0d\u540c\u7684\u3002\u6bcf\u4e2a\u623f\u5b50\u7c89\u5237\u6210\u4e0d\u540c\u989c\u8272\u7684\u82b1\u8d39\u662f\u4ee5\u4e00\u4e2a n x 3 \u7684\u77e9\u9635\u6765\u8868\u793a\u7684\u3002

    \n\n

    \u4f8b\u5982\uff0ccosts[0][0] \u8868\u793a\u7b2c 0 \u53f7\u623f\u5b50\u7c89\u5237\u6210\u7ea2\u8272\u7684\u6210\u672c\u82b1\u8d39\uff1bcosts[1][2] \u8868\u793a\u7b2c 1 \u53f7\u623f\u5b50\u7c89\u5237\u6210\u7eff\u8272\u7684\u82b1\u8d39\uff0c\u4ee5\u6b64\u7c7b\u63a8\u3002\u8bf7\u4f60\u8ba1\u7b97\u51fa\u7c89\u5237\u5b8c\u6240\u6709\u623f\u5b50\u6700\u5c11\u7684\u82b1\u8d39\u6210\u672c\u3002

    \n\n

    \u6ce8\u610f\uff1a

    \n\n

    \u6240\u6709\u82b1\u8d39\u5747\u4e3a\u6b63\u6574\u6570\u3002

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165: [[17,2,17],[16,16,5],[14,3,19]]\n\u8f93\u51fa: 10\n\u89e3\u91ca: \u5c06 0 \u53f7\u623f\u5b50\u7c89\u5237\u6210\u84dd\u8272\uff0c1 \u53f7\u623f\u5b50\u7c89\u5237\u6210\u7eff\u8272\uff0c2 \u53f7\u623f\u5b50\u7c89\u5237\u6210\u84dd\u8272\u3002\n     \u6700\u5c11\u82b1\u8d39: 2 + 5 + 3 = 10\u3002\n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minCost(vector>& costs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minCost(int[][] costs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minCost(self, costs):\n \"\"\"\n :type costs: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minCost(self, costs: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minCost(int** costs, int costsSize, int* costsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinCost(int[][] costs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} costs\n * @return {number}\n */\nvar minCost = function(costs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} costs\n# @return {Integer}\ndef min_cost(costs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minCost(_ costs: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minCost(costs [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minCost(costs: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minCost(costs: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_cost(costs: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $costs\n * @return Integer\n */\n function minCost($costs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minCost(costs: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-cost costs)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0256](https://leetcode-cn.com/problems/paint-house)", "[\u7c89\u5237\u623f\u5b50](/solution/0200-0299/0256.Paint%20House/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0256](https://leetcode.com/problems/paint-house)", "[Paint House](/solution/0200-0299/0256.Paint%20House/README_EN.md)", "`Dynamic Programming`", "Medium", "\ud83d\udd12"]}, {"question_id": "0255", "frontend_question_id": "0255", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/verify-preorder-sequence-in-binary-search-tree", "url_en": "https://leetcode.com/problems/verify-preorder-sequence-in-binary-search-tree", "relative_path_cn": "/solution/0200-0299/0255.Verify%20Preorder%20Sequence%20in%20Binary%20Search%20Tree/README.md", "relative_path_en": "/solution/0200-0299/0255.Verify%20Preorder%20Sequence%20in%20Binary%20Search%20Tree/README_EN.md", "title_cn": "\u9a8c\u8bc1\u524d\u5e8f\u904d\u5386\u5e8f\u5217\u4e8c\u53c9\u641c\u7d22\u6811", "title_en": "Verify Preorder Sequence in Binary Search Tree", "question_title_slug": "verify-preorder-sequence-in-binary-search-tree", "content_en": "

    Given an array of unique integers preorder, return true if it is the correct preorder traversal sequence of a binary search tree.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: preorder = [5,2,1,3,6]\nOutput: true\n
    \n\n

    Example 2:

    \n\n
    \nInput: preorder = [5,2,6,1,3]\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= preorder.length <= 104
    • \n\t
    • 1 <= preorder[i] <= 104
    • \n\t
    • All the elements of preorder are unique.
    • \n
    \n\n

     

    \n

    Follow up: Could you do it using only constant space complexity?

    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\uff0c\u4f60\u9700\u8981\u9a8c\u8bc1\u5b83\u662f\u5426\u662f\u4e00\u4e2a\u4e8c\u53c9\u641c\u7d22\u6811\u6b63\u786e\u7684\u5148\u5e8f\u904d\u5386\u5e8f\u5217\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u5047\u5b9a\u8be5\u5e8f\u5217\u4e2d\u7684\u6570\u90fd\u662f\u4e0d\u76f8\u540c\u7684\u3002

    \n\n

    \u53c2\u8003\u4ee5\u4e0b\u8fd9\u9897\u4e8c\u53c9\u641c\u7d22\u6811\uff1a

    \n\n
         5\n    / \\\n   2   6\n  / \\\n 1   3
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165: [5,2,6,1,3]\n\u8f93\u51fa: false
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165: [5,2,1,3,6]\n\u8f93\u51fa: true
    \n\n

    \u8fdb\u9636\u6311\u6218\uff1a

    \n\n

    \u60a8\u80fd\u5426\u4f7f\u7528\u6052\u5b9a\u7684\u7a7a\u95f4\u590d\u6742\u5ea6\u6765\u5b8c\u6210\u6b64\u9898\uff1f

    \n", "tags_en": ["Stack", "Tree"], "tags_cn": ["\u6808", "\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool verifyPreorder(vector& preorder) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean verifyPreorder(int[] preorder) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def verifyPreorder(self, preorder):\n \"\"\"\n :type preorder: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def verifyPreorder(self, preorder: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool verifyPreorder(int* preorder, int preorderSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool VerifyPreorder(int[] preorder) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} preorder\n * @return {boolean}\n */\nvar verifyPreorder = function(preorder) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} preorder\n# @return {Boolean}\ndef verify_preorder(preorder)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func verifyPreorder(_ preorder: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func verifyPreorder(preorder []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def verifyPreorder(preorder: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun verifyPreorder(preorder: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn verify_preorder(preorder: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $preorder\n * @return Boolean\n */\n function verifyPreorder($preorder) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function verifyPreorder(preorder: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (verify-preorder preorder)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0255](https://leetcode-cn.com/problems/verify-preorder-sequence-in-binary-search-tree)", "[\u9a8c\u8bc1\u524d\u5e8f\u904d\u5386\u5e8f\u5217\u4e8c\u53c9\u641c\u7d22\u6811](/solution/0200-0299/0255.Verify%20Preorder%20Sequence%20in%20Binary%20Search%20Tree/README.md)", "`\u6808`,`\u6811`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0255](https://leetcode.com/problems/verify-preorder-sequence-in-binary-search-tree)", "[Verify Preorder Sequence in Binary Search Tree](/solution/0200-0299/0255.Verify%20Preorder%20Sequence%20in%20Binary%20Search%20Tree/README_EN.md)", "`Stack`,`Tree`", "Medium", "\ud83d\udd12"]}, {"question_id": "0254", "frontend_question_id": "0254", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/factor-combinations", "url_en": "https://leetcode.com/problems/factor-combinations", "relative_path_cn": "/solution/0200-0299/0254.Factor%20Combinations/README.md", "relative_path_en": "/solution/0200-0299/0254.Factor%20Combinations/README_EN.md", "title_cn": "\u56e0\u5b50\u7684\u7ec4\u5408", "title_en": "Factor Combinations", "question_title_slug": "factor-combinations", "content_en": "

    Numbers can be regarded as the product of their factors.

    \n\n
      \n\t
    • For example, 8 = 2 x 2 x 2 = 2 x 4.
    • \n
    \n\n

    Given an integer n, return all possible combinations of its factors. You may return the answer in any order.

    \n\n

    Note that the factors should be in the range [2, n - 1].

    \n\n

     

    \n

    Example 1:

    \n
    Input: n = 1\nOutput: []\n

    Example 2:

    \n
    Input: n = 12\nOutput: [[2,6],[3,4],[2,2,3]]\n

    Example 3:

    \n
    Input: n = 37\nOutput: []\n

    Example 4:

    \n
    Input: n = 32\nOutput: [[2,16],[4,8],[2,2,8],[2,4,4],[2,2,2,4],[2,2,2,2,2]]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 108
    • \n
    \n", "content_cn": "

    \u6574\u6570\u53ef\u4ee5\u88ab\u770b\u4f5c\u662f\u5176\u56e0\u5b50\u7684\u4e58\u79ef\u3002

    \n\n

    \u4f8b\u5982\uff1a

    \n\n
    8 = 2 x 2 x 2;\n  = 2 x 4.
    \n\n

    \u8bf7\u5b9e\u73b0\u4e00\u4e2a\u51fd\u6570\uff0c\u8be5\u51fd\u6570\u63a5\u6536\u4e00\u4e2a\u6574\u6570 n \u5e76\u8fd4\u56de\u8be5\u6574\u6570\u6240\u6709\u7684\u56e0\u5b50\u7ec4\u5408\u3002

    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    1. \u4f60\u53ef\u4ee5\u5047\u5b9a n \u4e3a\u6c38\u8fdc\u4e3a\u6b63\u6570\u3002
    2. \n\t
    3. \u56e0\u5b50\u5fc5\u987b\u5927\u4e8e 1 \u5e76\u4e14\u5c0f\u4e8e n\u3002
    4. \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165: 1\n\u8f93\u51fa: []\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165: 37\n\u8f93\u51fa: []
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165: 12\n\u8f93\u51fa:\n[\n  [2, 6],\n  [2, 2, 3],\n  [3, 4]\n]
    \n\n

    \u793a\u4f8b 4:

    \n\n
    \u8f93\u5165: 32\n\u8f93\u51fa:\n[\n  [2, 16],\n  [2, 2, 8],\n  [2, 2, 2, 4],\n  [2, 2, 2, 2, 2],\n  [2, 4, 4],\n  [4, 8]\n]\n
    \n", "tags_en": ["Backtracking"], "tags_cn": ["\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> getFactors(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> getFactors(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getFactors(self, n):\n \"\"\"\n :type n: int\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getFactors(self, n: int) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** getFactors(int n, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> GetFactors(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number[][]}\n */\nvar getFactors = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer[][]}\ndef get_factors(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getFactors(_ n: Int) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getFactors(n int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getFactors(n: Int): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getFactors(n: Int): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_factors(n: i32) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer[][]\n */\n function getFactors($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getFactors(n: number): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-factors n)\n (-> exact-integer? (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0254](https://leetcode-cn.com/problems/factor-combinations)", "[\u56e0\u5b50\u7684\u7ec4\u5408](/solution/0200-0299/0254.Factor%20Combinations/README.md)", "`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0254](https://leetcode.com/problems/factor-combinations)", "[Factor Combinations](/solution/0200-0299/0254.Factor%20Combinations/README_EN.md)", "`Backtracking`", "Medium", "\ud83d\udd12"]}, {"question_id": "0253", "frontend_question_id": "0253", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/meeting-rooms-ii", "url_en": "https://leetcode.com/problems/meeting-rooms-ii", "relative_path_cn": "/solution/0200-0299/0253.Meeting%20Rooms%20II/README.md", "relative_path_en": "/solution/0200-0299/0253.Meeting%20Rooms%20II/README_EN.md", "title_cn": "\u4f1a\u8bae\u5ba4 II", "title_en": "Meeting Rooms II", "question_title_slug": "meeting-rooms-ii", "content_en": "

    Given an array of meeting time intervals intervals where intervals[i] = [starti, endi], return the minimum number of conference rooms required.

    \n\n

     

    \n

    Example 1:

    \n
    Input: intervals = [[0,30],[5,10],[15,20]]\nOutput: 2\n

    Example 2:

    \n
    Input: intervals = [[7,10],[2,4]]\nOutput: 1\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= intervals.length <= 104
    • \n\t
    • 0 <= starti < endi <= 106
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u4f1a\u8bae\u65f6\u95f4\u5b89\u6392\u7684\u6570\u7ec4 intervals \uff0c\u6bcf\u4e2a\u4f1a\u8bae\u65f6\u95f4\u90fd\u4f1a\u5305\u62ec\u5f00\u59cb\u548c\u7ed3\u675f\u7684\u65f6\u95f4 intervals[i] = [starti, endi] \uff0c\u4e3a\u907f\u514d\u4f1a\u8bae\u51b2\u7a81\uff0c\u540c\u65f6\u8981\u8003\u8651\u5145\u5206\u5229\u7528\u4f1a\u8bae\u5ba4\u8d44\u6e90\uff0c\u8bf7\u4f60\u8ba1\u7b97\u81f3\u5c11\u9700\u8981\u591a\u5c11\u95f4\u4f1a\u8bae\u5ba4\uff0c\u624d\u80fd\u6ee1\u8db3\u8fd9\u4e9b\u4f1a\u8bae\u5b89\u6392\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aintervals = [[0,30],[5,10],[15,20]]\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aintervals = [[7,10],[2,4]]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <=\u00a0intervals.length <= 104
    • \n\t
    • 0 <= starti < endi <= 106
    • \n
    \n", "tags_en": ["Heap", "Greedy", "Sort"], "tags_cn": ["\u5806", "\u8d2a\u5fc3\u7b97\u6cd5", "\u6392\u5e8f"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minMeetingRooms(vector>& intervals) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minMeetingRooms(int[][] intervals) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minMeetingRooms(self, intervals):\n \"\"\"\n :type intervals: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minMeetingRooms(self, intervals: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minMeetingRooms(int** intervals, int intervalsSize, int* intervalsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinMeetingRooms(int[][] intervals) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} intervals\n * @return {number}\n */\nvar minMeetingRooms = function(intervals) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} intervals\n# @return {Integer}\ndef min_meeting_rooms(intervals)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minMeetingRooms(_ intervals: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minMeetingRooms(intervals [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minMeetingRooms(intervals: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minMeetingRooms(intervals: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_meeting_rooms(intervals: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $intervals\n * @return Integer\n */\n function minMeetingRooms($intervals) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minMeetingRooms(intervals: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-meeting-rooms intervals)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0253](https://leetcode-cn.com/problems/meeting-rooms-ii)", "[\u4f1a\u8bae\u5ba4 II](/solution/0200-0299/0253.Meeting%20Rooms%20II/README.md)", "`\u5806`,`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6392\u5e8f`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0253](https://leetcode.com/problems/meeting-rooms-ii)", "[Meeting Rooms II](/solution/0200-0299/0253.Meeting%20Rooms%20II/README_EN.md)", "`Heap`,`Greedy`,`Sort`", "Medium", "\ud83d\udd12"]}, {"question_id": "0252", "frontend_question_id": "0252", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/meeting-rooms", "url_en": "https://leetcode.com/problems/meeting-rooms", "relative_path_cn": "/solution/0200-0299/0252.Meeting%20Rooms/README.md", "relative_path_en": "/solution/0200-0299/0252.Meeting%20Rooms/README_EN.md", "title_cn": "\u4f1a\u8bae\u5ba4", "title_en": "Meeting Rooms", "question_title_slug": "meeting-rooms", "content_en": "

    Given an array of meeting time intervals where intervals[i] = [starti, endi], determine if a person could attend all meetings.

    \n\n

     

    \n

    Example 1:

    \n
    Input: intervals = [[0,30],[5,10],[15,20]]\nOutput: false\n

    Example 2:

    \n
    Input: intervals = [[7,10],[2,4]]\nOutput: true\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= intervals.length <= 104
    • \n\t
    • intervals[i].length == 2
    • \n\t
    • 0 <= starti < endi <= 106
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4f1a\u8bae\u65f6\u95f4\u5b89\u6392\u7684\u6570\u7ec4 intervals \uff0c\u6bcf\u4e2a\u4f1a\u8bae\u65f6\u95f4\u90fd\u4f1a\u5305\u62ec\u5f00\u59cb\u548c\u7ed3\u675f\u7684\u65f6\u95f4 intervals[i] = [starti, endi] \uff0c\u8bf7\u4f60\u5224\u65ad\u4e00\u4e2a\u4eba\u662f\u5426\u80fd\u591f\u53c2\u52a0\u8fd9\u91cc\u9762\u7684\u5168\u90e8\u4f1a\u8bae\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aintervals = [[0,30],[5,10],[15,20]]\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aintervals = [[7,10],[2,4]]\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= intervals.length <= 104
    • \n\t
    • intervals[i].length == 2
    • \n\t
    • 0 <= starti <\u00a0endi <= 106
    • \n
    \n", "tags_en": ["Sort"], "tags_cn": ["\u6392\u5e8f"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canAttendMeetings(vector>& intervals) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canAttendMeetings(int[][] intervals) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canAttendMeetings(self, intervals):\n \"\"\"\n :type intervals: List[List[int]]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canAttendMeetings(self, intervals: List[List[int]]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canAttendMeetings(int** intervals, int intervalsSize, int* intervalsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanAttendMeetings(int[][] intervals) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} intervals\n * @return {boolean}\n */\nvar canAttendMeetings = function(intervals) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} intervals\n# @return {Boolean}\ndef can_attend_meetings(intervals)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canAttendMeetings(_ intervals: [[Int]]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canAttendMeetings(intervals [][]int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canAttendMeetings(intervals: Array[Array[Int]]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canAttendMeetings(intervals: Array): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_attend_meetings(intervals: Vec>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $intervals\n * @return Boolean\n */\n function canAttendMeetings($intervals) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canAttendMeetings(intervals: number[][]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-attend-meetings intervals)\n (-> (listof (listof exact-integer?)) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0252](https://leetcode-cn.com/problems/meeting-rooms)", "[\u4f1a\u8bae\u5ba4](/solution/0200-0299/0252.Meeting%20Rooms/README.md)", "`\u6392\u5e8f`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0252](https://leetcode.com/problems/meeting-rooms)", "[Meeting Rooms](/solution/0200-0299/0252.Meeting%20Rooms/README_EN.md)", "`Sort`", "Easy", "\ud83d\udd12"]}, {"question_id": "0251", "frontend_question_id": "0251", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/flatten-2d-vector", "url_en": "https://leetcode.com/problems/flatten-2d-vector", "relative_path_cn": "/solution/0200-0299/0251.Flatten%202D%20Vector/README.md", "relative_path_en": "/solution/0200-0299/0251.Flatten%202D%20Vector/README_EN.md", "title_cn": "\u5c55\u5f00\u4e8c\u7ef4\u5411\u91cf", "title_en": "Flatten 2D Vector", "question_title_slug": "flatten-2d-vector", "content_en": "

    Design an iterator to flatten a 2D vector. It should support the next and hasNext operations.

    \n\n

    Implement the Vector2D class:

    \n\n
      \n\t
    • Vector2D(int[][] vec) initializes the object with the 2D vector vec.
    • \n\t
    • next() returns the next element from the 2D vector and moves the pointer one step forward. You may assume that all the calls to next are valid.
    • \n\t
    • hasNext() returns true if there are still some elements in the vector, and false otherwise.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["Vector2D", "next", "next", "next", "hasNext", "hasNext", "next", "hasNext"]\n[[[[1, 2], [3], [4]]], [], [], [], [], [], [], []]\nOutput\n[null, 1, 2, 3, true, true, 4, false]\n\nExplanation\nVector2D vector2D = new Vector2D([[1, 2], [3], [4]]);\nvector2D.next();    // return 1\nvector2D.next();    // return 2\nvector2D.next();    // return 3\nvector2D.hasNext(); // return True\nvector2D.hasNext(); // return True\nvector2D.next();    // return 4\nvector2D.hasNext(); // return False\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= vec.length <= 200
    • \n\t
    • 0 <= vec[i].length <= 500
    • \n\t
    • -500 <= vec[i][j] <= 500
    • \n\t
    • At most 105 calls will be made to next and hasNext.
    • \n
    \n\n

     

    \n

    Follow up: As an added challenge, try to code it using only iterators in C++ or iterators in Java.

    \n", "content_cn": "

    \u8bf7\u8bbe\u8ba1\u5e76\u5b9e\u73b0\u4e00\u4e2a\u80fd\u591f\u5c55\u5f00\u4e8c\u7ef4\u5411\u91cf\u7684\u8fed\u4ee3\u5668\u3002\u8be5\u8fed\u4ee3\u5668\u9700\u8981\u652f\u6301\u00a0next \u548c\u00a0hasNext\u00a0\u4e24\u79cd\u64cd\u4f5c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \nVector2D iterator = new Vector2D([[1,2],[3],[4]]);\n\niterator.next(); // \u8fd4\u56de 1\niterator.next(); // \u8fd4\u56de 2\niterator.next(); // \u8fd4\u56de 3\niterator.hasNext(); // \u8fd4\u56de true\niterator.hasNext(); // \u8fd4\u56de true\niterator.next(); // \u8fd4\u56de 4\niterator.hasNext(); // \u8fd4\u56de false\n
    \n\n

    \u00a0

    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    1. \u8bf7\u8bb0\u5f97\u00a0\u91cd\u7f6e\u00a0\u5728 Vector2D \u4e2d\u58f0\u660e\u7684\u7c7b\u53d8\u91cf\uff08\u9759\u6001\u53d8\u91cf\uff09\uff0c\u56e0\u4e3a\u7c7b\u53d8\u91cf\u4f1a\u00a0\u5728\u591a\u4e2a\u6d4b\u8bd5\u7528\u4f8b\u4e2d\u4fdd\u6301\u4e0d\u53d8\uff0c\u5f71\u54cd\u5224\u9898\u51c6\u786e\u3002\u8bf7 \u67e5\u9605 \u8fd9\u91cc\u3002
    2. \n\t
    3. \u4f60\u53ef\u4ee5\u5047\u5b9a next() \u7684\u8c03\u7528\u603b\u662f\u5408\u6cd5\u7684\uff0c\u5373\u5f53 next() \u88ab\u8c03\u7528\u65f6\uff0c\u4e8c\u7ef4\u5411\u91cf\u603b\u662f\u5b58\u5728\u81f3\u5c11\u4e00\u4e2a\u540e\u7eed\u5143\u7d20\u3002
    4. \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u5c1d\u8bd5\u5728\u4ee3\u7801\u4e2d\u4ec5\u4f7f\u7528 C++ \u63d0\u4f9b\u7684\u8fed\u4ee3\u5668 \u6216 Java \u63d0\u4f9b\u7684\u8fed\u4ee3\u5668\u3002

    \n", "tags_en": ["Design"], "tags_cn": ["\u8bbe\u8ba1"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Vector2D {\npublic:\n Vector2D(vector>& vec) {\n\n }\n \n int next() {\n\n }\n \n bool hasNext() {\n\n }\n};\n\n/**\n * Your Vector2D object will be instantiated and called as such:\n * Vector2D* obj = new Vector2D(vec);\n * int param_1 = obj->next();\n * bool param_2 = obj->hasNext();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Vector2D {\n\n public Vector2D(int[][] vec) {\n\n }\n \n public int next() {\n\n }\n \n public boolean hasNext() {\n\n }\n}\n\n/**\n * Your Vector2D object will be instantiated and called as such:\n * Vector2D obj = new Vector2D(vec);\n * int param_1 = obj.next();\n * boolean param_2 = obj.hasNext();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Vector2D(object):\n\n def __init__(self, vec):\n \"\"\"\n :type vec: List[List[int]]\n \"\"\"\n\n\n def next(self):\n \"\"\"\n :rtype: int\n \"\"\"\n\n\n def hasNext(self):\n \"\"\"\n :rtype: bool\n \"\"\"\n\n\n\n# Your Vector2D object will be instantiated and called as such:\n# obj = Vector2D(vec)\n# param_1 = obj.next()\n# param_2 = obj.hasNext()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Vector2D:\n\n def __init__(self, vec: List[List[int]]):\n\n\n def next(self) -> int:\n\n\n def hasNext(self) -> bool:\n\n\n\n# Your Vector2D object will be instantiated and called as such:\n# obj = Vector2D(vec)\n# param_1 = obj.next()\n# param_2 = obj.hasNext()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} Vector2D;\n\n\nVector2D* vector2DCreate(int** vec, int vecSize, int* vecColSize) {\n\n}\n\nint vector2DNext(Vector2D* obj) {\n\n}\n\nbool vector2DHasNext(Vector2D* obj) {\n\n}\n\nvoid vector2DFree(Vector2D* obj) {\n\n}\n\n/**\n * Your Vector2D struct will be instantiated and called as such:\n * Vector2D* obj = vector2DCreate(vec, vecSize, vecColSize);\n * int param_1 = vector2DNext(obj);\n \n * bool param_2 = vector2DHasNext(obj);\n \n * vector2DFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Vector2D {\n\n public Vector2D(int[][] vec) {\n\n }\n \n public int Next() {\n\n }\n \n public bool HasNext() {\n\n }\n}\n\n/**\n * Your Vector2D object will be instantiated and called as such:\n * Vector2D obj = new Vector2D(vec);\n * int param_1 = obj.Next();\n * bool param_2 = obj.HasNext();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} vec\n */\nvar Vector2D = function(vec) {\n\n};\n\n/**\n * @return {number}\n */\nVector2D.prototype.next = function() {\n\n};\n\n/**\n * @return {boolean}\n */\nVector2D.prototype.hasNext = function() {\n\n};\n\n/**\n * Your Vector2D object will be instantiated and called as such:\n * var obj = new Vector2D(vec)\n * var param_1 = obj.next()\n * var param_2 = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class Vector2D\n\n=begin\n :type vec: Integer[][]\n=end\n def initialize(vec)\n\n end\n\n\n=begin\n :rtype: Integer\n=end\n def next()\n\n end\n\n\n=begin\n :rtype: Boolean\n=end\n def has_next()\n\n end\n\n\nend\n\n# Your Vector2D object will be instantiated and called as such:\n# obj = Vector2D.new(vec)\n# param_1 = obj.next()\n# param_2 = obj.has_next()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass Vector2D {\n\n init(_ vec: [[Int]]) {\n\n }\n \n func next() -> Int {\n\n }\n \n func hasNext() -> Bool {\n\n }\n}\n\n/**\n * Your Vector2D object will be instantiated and called as such:\n * let obj = Vector2D(vec)\n * let ret_1: Int = obj.next()\n * let ret_2: Bool = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type Vector2D struct {\n\n}\n\n\nfunc Constructor(vec [][]int) Vector2D {\n\n}\n\n\nfunc (this *Vector2D) Next() int {\n\n}\n\n\nfunc (this *Vector2D) HasNext() bool {\n\n}\n\n\n/**\n * Your Vector2D object will be instantiated and called as such:\n * obj := Constructor(vec);\n * param_1 := obj.Next();\n * param_2 := obj.HasNext();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class Vector2D(_vec: Array[Array[Int]]) {\n\n def next(): Int = {\n\n }\n\n def hasNext(): Boolean = {\n\n }\n\n}\n\n/**\n * Your Vector2D object will be instantiated and called as such:\n * var obj = new Vector2D(vec)\n * var param_1 = obj.next()\n * var param_2 = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Vector2D(vec: Array) {\n\n fun next(): Int {\n\n }\n\n fun hasNext(): Boolean {\n\n }\n\n}\n\n/**\n * Your Vector2D object will be instantiated and called as such:\n * var obj = Vector2D(vec)\n * var param_1 = obj.next()\n * var param_2 = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct Vector2D {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl Vector2D {\n\n fn new(vec: Vec>) -> Self {\n\n }\n \n fn next(&self) -> i32 {\n\n }\n \n fn has_next(&self) -> bool {\n\n }\n}\n\n/**\n * Your Vector2D object will be instantiated and called as such:\n * let obj = Vector2D::new(vec);\n * let ret_1: i32 = obj.next();\n * let ret_2: bool = obj.has_next();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Vector2D {\n /**\n * @param Integer[][] $vec\n */\n function __construct($vec) {\n\n }\n\n /**\n * @return Integer\n */\n function next() {\n\n }\n\n /**\n * @return Boolean\n */\n function hasNext() {\n\n }\n}\n\n/**\n * Your Vector2D object will be instantiated and called as such:\n * $obj = Vector2D($vec);\n * $ret_1 = $obj->next();\n * $ret_2 = $obj->hasNext();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class Vector2D {\n constructor(vec: number[][]) {\n\n }\n\n next(): number {\n\n }\n\n hasNext(): boolean {\n\n }\n}\n\n/**\n * Your Vector2D object will be instantiated and called as such:\n * var obj = new Vector2D(vec)\n * var param_1 = obj.next()\n * var param_2 = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define vector2-d%\n (class object%\n (super-new)\n\n ; vec : (listof (listof exact-integer?))\n (init-field\n vec)\n \n ; next : -> exact-integer?\n (define/public (next)\n\n )\n ; has-next : -> boolean?\n (define/public (has-next)\n\n )))\n\n;; Your vector2-d% object will be instantiated and called as such:\n;; (define obj (new vector2-d% [vec vec]))\n;; (define param_1 (send obj next))\n;; (define param_2 (send obj has-next))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0251](https://leetcode-cn.com/problems/flatten-2d-vector)", "[\u5c55\u5f00\u4e8c\u7ef4\u5411\u91cf](/solution/0200-0299/0251.Flatten%202D%20Vector/README.md)", "`\u8bbe\u8ba1`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0251](https://leetcode.com/problems/flatten-2d-vector)", "[Flatten 2D Vector](/solution/0200-0299/0251.Flatten%202D%20Vector/README_EN.md)", "`Design`", "Medium", "\ud83d\udd12"]}, {"question_id": "0250", "frontend_question_id": "0250", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/count-univalue-subtrees", "url_en": "https://leetcode.com/problems/count-univalue-subtrees", "relative_path_cn": "/solution/0200-0299/0250.Count%20Univalue%20Subtrees/README.md", "relative_path_en": "/solution/0200-0299/0250.Count%20Univalue%20Subtrees/README_EN.md", "title_cn": "\u7edf\u8ba1\u540c\u503c\u5b50\u6811", "title_en": "Count Univalue Subtrees", "question_title_slug": "count-univalue-subtrees", "content_en": "

    Given the root of a binary tree, return the number of uni-value subtrees.

    \n\n

    A uni-value subtree means all nodes of the subtree have the same value.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [5,1,5,5,5,null,5]\nOutput: 4\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = []\nOutput: 0\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = [5,5,5,5,5,null,5]\nOutput: 6\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The numbrt of the node in the tree will be in the range [0, 1000].
    • \n\t
    • -1000 <= Node.val <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811\uff0c\u7edf\u8ba1\u8be5\u4e8c\u53c9\u6811\u6570\u503c\u76f8\u540c\u7684\u5b50\u6811\u4e2a\u6570\u3002

    \n\n

    \u540c\u503c\u5b50\u6811\u662f\u6307\u8be5\u5b50\u6811\u7684\u6240\u6709\u8282\u70b9\u90fd\u62e5\u6709\u76f8\u540c\u7684\u6570\u503c\u3002

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165: root = [5,1,5,5,5,null,5]\n\n              5\n             / \\\n            1   5\n           / \\   \\\n          5   5   5\n\n\u8f93\u51fa: 4\n
    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int countUnivalSubtrees(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int countUnivalSubtrees(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def countUnivalSubtrees(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def countUnivalSubtrees(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint countUnivalSubtrees(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int CountUnivalSubtrees(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar countUnivalSubtrees = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef count_unival_subtrees(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func countUnivalSubtrees(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc countUnivalSubtrees(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def countUnivalSubtrees(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun countUnivalSubtrees(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn count_unival_subtrees(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function countUnivalSubtrees($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction countUnivalSubtrees(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (count-unival-subtrees root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0250](https://leetcode-cn.com/problems/count-univalue-subtrees)", "[\u7edf\u8ba1\u540c\u503c\u5b50\u6811](/solution/0200-0299/0250.Count%20Univalue%20Subtrees/README.md)", "`\u6811`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0250](https://leetcode.com/problems/count-univalue-subtrees)", "[Count Univalue Subtrees](/solution/0200-0299/0250.Count%20Univalue%20Subtrees/README_EN.md)", "`Tree`", "Medium", "\ud83d\udd12"]}, {"question_id": "0249", "frontend_question_id": "0249", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/group-shifted-strings", "url_en": "https://leetcode.com/problems/group-shifted-strings", "relative_path_cn": "/solution/0200-0299/0249.Group%20Shifted%20Strings/README.md", "relative_path_en": "/solution/0200-0299/0249.Group%20Shifted%20Strings/README_EN.md", "title_cn": "\u79fb\u4f4d\u5b57\u7b26\u4e32\u5206\u7ec4", "title_en": "Group Shifted Strings", "question_title_slug": "group-shifted-strings", "content_en": "

    We can shift a string by shifting each of its letters to its successive letter.

    \n\n
      \n\t
    • For example, "abc" can be shifted to be "bcd".
    • \n
    \n\n

    We can keep shifting the string to form a sequence.

    \n\n
      \n\t
    • For example, we can keep shifting "abc" to form the sequence: "abc" -> "bcd" -> ... -> "xyz".
    • \n
    \n\n

    Given an array of strings strings, group all strings[i] that belong to the same shifting sequence. You may return the answer in any order.

    \n\n

     

    \n

    Example 1:

    \n
    Input: strings = [\"abc\",\"bcd\",\"acef\",\"xyz\",\"az\",\"ba\",\"a\",\"z\"]\nOutput: [[\"acef\"],[\"a\",\"z\"],[\"abc\",\"bcd\",\"xyz\"],[\"az\",\"ba\"]]\n

    Example 2:

    \n
    Input: strings = [\"a\"]\nOutput: [[\"a\"]]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= strings.length <= 200
    • \n\t
    • 1 <= strings[i].length <= 50
    • \n\t
    • strings[i] consists of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u5bf9\u8be5\u5b57\u7b26\u4e32\u53ef\u4ee5\u8fdb\u884c “\u79fb\u4f4d” \u7684\u64cd\u4f5c\uff0c\u4e5f\u5c31\u662f\u5c06\u5b57\u7b26\u4e32\u4e2d\u6bcf\u4e2a\u5b57\u6bcd\u90fd\u53d8\u4e3a\u5176\u5728\u5b57\u6bcd\u8868\u4e2d\u540e\u7eed\u7684\u5b57\u6bcd\uff0c\u6bd4\u5982\uff1a"abc" -> "bcd"\u3002\u8fd9\u6837\uff0c\u6211\u4eec\u53ef\u4ee5\u6301\u7eed\u8fdb\u884c “\u79fb\u4f4d” \u64cd\u4f5c\uff0c\u4ece\u800c\u751f\u6210\u5982\u4e0b\u79fb\u4f4d\u5e8f\u5217\uff1a

    \n\n
    "abc" -> "bcd" -> ... -> "xyz"
    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u5305\u542b\u4ec5\u5c0f\u5199\u5b57\u6bcd\u5b57\u7b26\u4e32\u7684\u5217\u8868\uff0c\u5c06\u8be5\u5217\u8868\u4e2d\u6240\u6709\u6ee1\u8db3 “\u79fb\u4f4d” \u64cd\u4f5c\u89c4\u5f8b\u7684\u7ec4\u5408\u8fdb\u884c\u5206\u7ec4\u5e76\u8fd4\u56de\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1a["abc", "bcd", "acef", "xyz", "az", "ba", "a", "z"]\n\u8f93\u51fa\uff1a\n[\n  ["abc","bcd","xyz"],\n  ["az","ba"],\n  ["acef"],\n  ["a","z"]\n]\n\u89e3\u91ca\uff1a\u53ef\u4ee5\u8ba4\u4e3a\u5b57\u6bcd\u8868\u9996\u5c3e\u76f8\u63a5\uff0c\u6240\u4ee5 'z' \u7684\u540e\u7eed\u4e3a 'a'\uff0c\u6240\u4ee5 ["az","ba"] \u4e5f\u6ee1\u8db3 “\u79fb\u4f4d” \u64cd\u4f5c\u89c4\u5f8b\u3002
    \n", "tags_en": ["Hash Table", "String"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> groupStrings(vector& strings) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> groupStrings(String[] strings) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def groupStrings(self, strings):\n \"\"\"\n :type strings: List[str]\n :rtype: List[List[str]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def groupStrings(self, strings: List[str]) -> List[List[str]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nchar *** groupStrings(char ** strings, int stringsSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> GroupStrings(string[] strings) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} strings\n * @return {string[][]}\n */\nvar groupStrings = function(strings) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} strings\n# @return {String[][]}\ndef group_strings(strings)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func groupStrings(_ strings: [String]) -> [[String]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func groupStrings(strings []string) [][]string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def groupStrings(strings: Array[String]): List[List[String]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun groupStrings(strings: Array): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn group_strings(strings: Vec) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $strings\n * @return String[][]\n */\n function groupStrings($strings) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function groupStrings(strings: string[]): string[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (group-strings strings)\n (-> (listof string?) (listof (listof string?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0249](https://leetcode-cn.com/problems/group-shifted-strings)", "[\u79fb\u4f4d\u5b57\u7b26\u4e32\u5206\u7ec4](/solution/0200-0299/0249.Group%20Shifted%20Strings/README.md)", "`\u54c8\u5e0c\u8868`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0249](https://leetcode.com/problems/group-shifted-strings)", "[Group Shifted Strings](/solution/0200-0299/0249.Group%20Shifted%20Strings/README_EN.md)", "`Hash Table`,`String`", "Medium", "\ud83d\udd12"]}, {"question_id": "0248", "frontend_question_id": "0248", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/strobogrammatic-number-iii", "url_en": "https://leetcode.com/problems/strobogrammatic-number-iii", "relative_path_cn": "/solution/0200-0299/0248.Strobogrammatic%20Number%20III/README.md", "relative_path_en": "/solution/0200-0299/0248.Strobogrammatic%20Number%20III/README_EN.md", "title_cn": "\u4e2d\u5fc3\u5bf9\u79f0\u6570 III", "title_en": "Strobogrammatic Number III", "question_title_slug": "strobogrammatic-number-iii", "content_en": "

    Given two strings low and high that represent two integers low and high where low <= high, return the number of strobogrammatic numbers in the range [low, high].

    \n\n

    A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down).

    \n\n

     

    \n

    Example 1:

    \n
    Input: low = \"50\", high = \"100\"\nOutput: 3\n

    Example 2:

    \n
    Input: low = \"0\", high = \"0\"\nOutput: 1\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= low.length, high.length <= 15
    • \n\t
    • low and high consist of only digits.
    • \n\t
    • low <= high
    • \n\t
    • low and high do not contain any leading zeros except for zero itself.
    • \n
    \n", "content_cn": "

    \u4e2d\u5fc3\u5bf9\u79f0\u6570\u662f\u6307\u4e00\u4e2a\u6570\u5b57\u5728\u65cb\u8f6c\u4e86 180 \u5ea6\u4e4b\u540e\u770b\u8d77\u6765\u4f9d\u65e7\u76f8\u540c\u7684\u6570\u5b57\uff08\u6216\u8005\u4e0a\u4e0b\u98a0\u5012\u5730\u770b\uff09\u3002

    \n\n

    \u5199\u4e00\u4e2a\u51fd\u6570\u6765\u8ba1\u7b97\u8303\u56f4\u5728 [low, high] \u4e4b\u95f4\u4e2d\u5fc3\u5bf9\u79f0\u6570\u7684\u4e2a\u6570\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: low = "50", high = "100"\n\u8f93\u51fa: 3 \n\u89e3\u91ca: 69\uff0c88 \u548c 96 \u662f\u4e09\u4e2a\u5728\u8be5\u8303\u56f4\u5185\u7684\u4e2d\u5fc3\u5bf9\u79f0\u6570
    \n\n

    \u6ce8\u610f:
    \n\u7531\u4e8e\u8303\u56f4\u53ef\u80fd\u5f88\u5927\uff0c\u6240\u4ee5 low \u548c high \u90fd\u7528\u5b57\u7b26\u4e32\u8868\u793a\u3002

    \n", "tags_en": ["Recursion", "Math"], "tags_cn": ["\u9012\u5f52", "\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int strobogrammaticInRange(string low, string high) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int strobogrammaticInRange(String low, String high) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def strobogrammaticInRange(self, low, high):\n \"\"\"\n :type low: str\n :type high: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def strobogrammaticInRange(self, low: str, high: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint strobogrammaticInRange(char * low, char * high){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int StrobogrammaticInRange(string low, string high) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} low\n * @param {string} high\n * @return {number}\n */\nvar strobogrammaticInRange = function(low, high) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} low\n# @param {String} high\n# @return {Integer}\ndef strobogrammatic_in_range(low, high)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func strobogrammaticInRange(_ low: String, _ high: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func strobogrammaticInRange(low string, high string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def strobogrammaticInRange(low: String, high: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun strobogrammaticInRange(low: String, high: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn strobogrammatic_in_range(low: String, high: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $low\n * @param String $high\n * @return Integer\n */\n function strobogrammaticInRange($low, $high) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function strobogrammaticInRange(low: string, high: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (strobogrammatic-in-range low high)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0248](https://leetcode-cn.com/problems/strobogrammatic-number-iii)", "[\u4e2d\u5fc3\u5bf9\u79f0\u6570 III](/solution/0200-0299/0248.Strobogrammatic%20Number%20III/README.md)", "`\u9012\u5f52`,`\u6570\u5b66`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0248](https://leetcode.com/problems/strobogrammatic-number-iii)", "[Strobogrammatic Number III](/solution/0200-0299/0248.Strobogrammatic%20Number%20III/README_EN.md)", "`Recursion`,`Math`", "Hard", "\ud83d\udd12"]}, {"question_id": "0247", "frontend_question_id": "0247", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/strobogrammatic-number-ii", "url_en": "https://leetcode.com/problems/strobogrammatic-number-ii", "relative_path_cn": "/solution/0200-0299/0247.Strobogrammatic%20Number%20II/README.md", "relative_path_en": "/solution/0200-0299/0247.Strobogrammatic%20Number%20II/README_EN.md", "title_cn": "\u4e2d\u5fc3\u5bf9\u79f0\u6570 II", "title_en": "Strobogrammatic Number II", "question_title_slug": "strobogrammatic-number-ii", "content_en": "

    Given an integer n, return all the strobogrammatic numbers that are of length n. You may return the answer in any order.

    \n\n

    A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down).

    \n\n

     

    \n

    Example 1:

    \n
    Input: n = 2\nOutput: [\"11\",\"69\",\"88\",\"96\"]\n

    Example 2:

    \n
    Input: n = 1\nOutput: [\"0\",\"1\",\"8\"]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 14
    • \n
    \n", "content_cn": "

    \u4e2d\u5fc3\u5bf9\u79f0\u6570\u662f\u6307\u4e00\u4e2a\u6570\u5b57\u5728\u65cb\u8f6c\u4e86 180 \u5ea6\u4e4b\u540e\u770b\u8d77\u6765\u4f9d\u65e7\u76f8\u540c\u7684\u6570\u5b57\uff08\u6216\u8005\u4e0a\u4e0b\u98a0\u5012\u5730\u770b\uff09\u3002

    \n\n

    \u627e\u5230\u6240\u6709\u957f\u5ea6\u4e3a n \u7684\u4e2d\u5fc3\u5bf9\u79f0\u6570\u3002

    \n\n

    \u793a\u4f8b :

    \n\n
    \u8f93\u5165:  n = 2\n\u8f93\u51fa: ["11","69","88","96"]\n
    \n", "tags_en": ["Recursion", "Math"], "tags_cn": ["\u9012\u5f52", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findStrobogrammatic(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List findStrobogrammatic(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findStrobogrammatic(self, n):\n \"\"\"\n :type n: int\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findStrobogrammatic(self, n: int) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** findStrobogrammatic(int n, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList FindStrobogrammatic(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {string[]}\n */\nvar findStrobogrammatic = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {String[]}\ndef find_strobogrammatic(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findStrobogrammatic(_ n: Int) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findStrobogrammatic(n int) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findStrobogrammatic(n: Int): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findStrobogrammatic(n: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_strobogrammatic(n: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return String[]\n */\n function findStrobogrammatic($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findStrobogrammatic(n: number): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-strobogrammatic n)\n (-> exact-integer? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0247](https://leetcode-cn.com/problems/strobogrammatic-number-ii)", "[\u4e2d\u5fc3\u5bf9\u79f0\u6570 II](/solution/0200-0299/0247.Strobogrammatic%20Number%20II/README.md)", "`\u9012\u5f52`,`\u6570\u5b66`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0247](https://leetcode.com/problems/strobogrammatic-number-ii)", "[Strobogrammatic Number II](/solution/0200-0299/0247.Strobogrammatic%20Number%20II/README_EN.md)", "`Recursion`,`Math`", "Medium", "\ud83d\udd12"]}, {"question_id": "0246", "frontend_question_id": "0246", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/strobogrammatic-number", "url_en": "https://leetcode.com/problems/strobogrammatic-number", "relative_path_cn": "/solution/0200-0299/0246.Strobogrammatic%20Number/README.md", "relative_path_en": "/solution/0200-0299/0246.Strobogrammatic%20Number/README_EN.md", "title_cn": "\u4e2d\u5fc3\u5bf9\u79f0\u6570", "title_en": "Strobogrammatic Number", "question_title_slug": "strobogrammatic-number", "content_en": "

    Given a string num which represents an integer, return true if num is a strobogrammatic number.

    \n\n

    A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down).

    \n\n

     

    \n

    Example 1:

    \n
    Input: num = \"69\"\nOutput: true\n

    Example 2:

    \n
    Input: num = \"88\"\nOutput: true\n

    Example 3:

    \n
    Input: num = \"962\"\nOutput: false\n

    Example 4:

    \n
    Input: num = \"1\"\nOutput: true\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= num.length <= 50
    • \n\t
    • num consists of only digits.
    • \n\t
    • num does not contain any leading zeros except for zero itself.
    • \n
    \n", "content_cn": "

    \u4e2d\u5fc3\u5bf9\u79f0\u6570\u662f\u6307\u4e00\u4e2a\u6570\u5b57\u5728\u65cb\u8f6c\u4e86 180 \u5ea6\u4e4b\u540e\u770b\u8d77\u6765\u4f9d\u65e7\u76f8\u540c\u7684\u6570\u5b57\uff08\u6216\u8005\u4e0a\u4e0b\u98a0\u5012\u5730\u770b\uff09\u3002

    \n\n

    \u8bf7\u5199\u4e00\u4e2a\u51fd\u6570\u6765\u5224\u65ad\u8be5\u6570\u5b57\u662f\u5426\u662f\u4e2d\u5fc3\u5bf9\u79f0\u6570\uff0c\u5176\u8f93\u5165\u5c06\u4f1a\u4ee5\u4e00\u4e2a\u5b57\u7b26\u4e32\u7684\u5f62\u5f0f\u6765\u8868\u8fbe\u6570\u5b57\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: num = "69"\n\u8f93\u51fa: true\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: num = "88"\n\u8f93\u51fa: true
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u8f93\u5165: num = "962"\n\u8f93\u51fa: false
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \u8f93\u5165\uff1anum = "1"\n\u8f93\u51fa\uff1atrue\n
    \n", "tags_en": ["Hash Table", "Math"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isStrobogrammatic(string num) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isStrobogrammatic(String num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isStrobogrammatic(self, num):\n \"\"\"\n :type num: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isStrobogrammatic(self, num: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isStrobogrammatic(char * num){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsStrobogrammatic(string num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} num\n * @return {boolean}\n */\nvar isStrobogrammatic = function(num) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} num\n# @return {Boolean}\ndef is_strobogrammatic(num)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isStrobogrammatic(_ num: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isStrobogrammatic(num string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isStrobogrammatic(num: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isStrobogrammatic(num: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_strobogrammatic(num: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $num\n * @return Boolean\n */\n function isStrobogrammatic($num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isStrobogrammatic(num: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-strobogrammatic num)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0246](https://leetcode-cn.com/problems/strobogrammatic-number)", "[\u4e2d\u5fc3\u5bf9\u79f0\u6570](/solution/0200-0299/0246.Strobogrammatic%20Number/README.md)", "`\u54c8\u5e0c\u8868`,`\u6570\u5b66`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0246](https://leetcode.com/problems/strobogrammatic-number)", "[Strobogrammatic Number](/solution/0200-0299/0246.Strobogrammatic%20Number/README_EN.md)", "`Hash Table`,`Math`", "Easy", "\ud83d\udd12"]}, {"question_id": "0245", "frontend_question_id": "0245", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/shortest-word-distance-iii", "url_en": "https://leetcode.com/problems/shortest-word-distance-iii", "relative_path_cn": "/solution/0200-0299/0245.Shortest%20Word%20Distance%20III/README.md", "relative_path_en": "/solution/0200-0299/0245.Shortest%20Word%20Distance%20III/README_EN.md", "title_cn": "\u6700\u77ed\u5355\u8bcd\u8ddd\u79bb III", "title_en": "Shortest Word Distance III", "question_title_slug": "shortest-word-distance-iii", "content_en": "

    Given an array of strings wordsDict and two strings that already exist in the array word1 and word2, return the shortest distance between these two words in the list.

    \n\n

    Note that word1 and word2 may be the same. It is guaranteed that they represent two individual words in the list.

    \n\n

     

    \n

    Example 1:

    \n
    Input: wordsDict = [\"practice\", \"makes\", \"perfect\", \"coding\", \"makes\"], word1 = \"makes\", word2 = \"coding\"\nOutput: 1\n

    Example 2:

    \n
    Input: wordsDict = [\"practice\", \"makes\", \"perfect\", \"coding\", \"makes\"], word1 = \"makes\", word2 = \"makes\"\nOutput: 3\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= wordsDict.length <= 3 * 104
    • \n\t
    • 1 <= wordsDict[i].length <= 10
    • \n\t
    • wordsDict[i] consists of lowercase English letters.
    • \n\t
    • word1 and word2 are in wordsDict.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5355\u8bcd\u5217\u8868\u548c\u4e24\u4e2a\u5355\u8bcd word1 \u548c word2\uff0c\u8fd4\u56de\u5217\u8868\u4e2d\u8fd9\u4e24\u4e2a\u5355\u8bcd\u4e4b\u95f4\u7684\u6700\u77ed\u8ddd\u79bb\u3002

    \n\n

    word1 \u548c word2 \u662f\u6709\u53ef\u80fd\u76f8\u540c\u7684\uff0c\u5e76\u4e14\u5b83\u4eec\u5c06\u5206\u522b\u8868\u793a\u4e3a\u5217\u8868\u4e2d\u4e24\u4e2a\u72ec\u7acb\u7684\u5355\u8bcd\u3002

    \n\n

    \u793a\u4f8b:
    \n\u5047\u8bbe words = ["practice", "makes", "perfect", "coding", "makes"].

    \n\n
    \u8f93\u5165: word1 = “makes”, word2 = “coding”\n\u8f93\u51fa: 1\n
    \n\n
    \u8f93\u5165: word1 = "makes", word2 = "makes"\n\u8f93\u51fa: 3\n
    \n\n

    \u6ce8\u610f:
    \n\u4f60\u53ef\u4ee5\u5047\u8bbe word1 \u548c word2 \u90fd\u5728\u5217\u8868\u91cc\u3002

    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int shortestWordDistance(vector& wordsDict, string word1, string word2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int shortestWordDistance(String[] wordsDict, String word1, String word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def shortestWordDistance(self, wordsDict, word1, word2):\n \"\"\"\n :type wordsDict: List[str]\n :type word1: str\n :type word2: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def shortestWordDistance(self, wordsDict: List[str], word1: str, word2: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint shortestWordDistance(char ** wordsDict, int wordsDictSize, char * word1, char * word2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ShortestWordDistance(string[] wordsDict, string word1, string word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} wordsDict\n * @param {string} word1\n * @param {string} word2\n * @return {number}\n */\nvar shortestWordDistance = function(wordsDict, word1, word2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words_dict\n# @param {String} word1\n# @param {String} word2\n# @return {Integer}\ndef shortest_word_distance(words_dict, word1, word2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func shortestWordDistance(_ wordsDict: [String], _ word1: String, _ word2: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func shortestWordDistance(wordsDict []string, word1 string, word2 string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def shortestWordDistance(wordsDict: Array[String], word1: String, word2: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun shortestWordDistance(wordsDict: Array, word1: String, word2: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn shortest_word_distance(words_dict: Vec, word1: String, word2: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $wordsDict\n * @param String $word1\n * @param String $word2\n * @return Integer\n */\n function shortestWordDistance($wordsDict, $word1, $word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function shortestWordDistance(wordsDict: string[], word1: string, word2: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (shortest-word-distance wordsDict word1 word2)\n (-> (listof string?) string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0245](https://leetcode-cn.com/problems/shortest-word-distance-iii)", "[\u6700\u77ed\u5355\u8bcd\u8ddd\u79bb III](/solution/0200-0299/0245.Shortest%20Word%20Distance%20III/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0245](https://leetcode.com/problems/shortest-word-distance-iii)", "[Shortest Word Distance III](/solution/0200-0299/0245.Shortest%20Word%20Distance%20III/README_EN.md)", "`Array`", "Medium", "\ud83d\udd12"]}, {"question_id": "0244", "frontend_question_id": "0244", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/shortest-word-distance-ii", "url_en": "https://leetcode.com/problems/shortest-word-distance-ii", "relative_path_cn": "/solution/0200-0299/0244.Shortest%20Word%20Distance%20II/README.md", "relative_path_en": "/solution/0200-0299/0244.Shortest%20Word%20Distance%20II/README_EN.md", "title_cn": "\u6700\u77ed\u5355\u8bcd\u8ddd\u79bb II", "title_en": "Shortest Word Distance II", "question_title_slug": "shortest-word-distance-ii", "content_en": "

    Design a data structure that will be initialized with a string array, and then it should answer queries of the shortest distance between two different strings from the array.

    \n\n

    Implement the WordDistance class:

    \n\n
      \n\t
    • WordDistance(String[] wordsDict) initializes the object with the strings array wordsDict.
    • \n\t
    • int shortest(String word1, String word2) returns the shortest distance between word1 and word2 in the array wordsDict.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["WordDistance", "shortest", "shortest"]\n[[["practice", "makes", "perfect", "coding", "makes"]], ["coding", "practice"], ["makes", "coding"]]\nOutput\n[null, 3, 1]\n\nExplanation\nWordDistance wordDistance = new WordDistance(["practice", "makes", "perfect", "coding", "makes"]);\nwordDistance.shortest("coding", "practice"); // return 3\nwordDistance.shortest("makes", "coding");    // return 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= wordsDict.length <= 3 * 104
    • \n\t
    • 1 <= wordsDict[i].length <= 10
    • \n\t
    • wordsDict[i] consists of lowercase English letters.
    • \n\t
    • word1 and word2 are in wordsDict.
    • \n\t
    • word1 != word2
    • \n\t
    • At most 5000 calls will be made to shortest.
    • \n
    \n", "content_cn": "

    \u8bf7\u8bbe\u8ba1\u4e00\u4e2a\u7c7b\uff0c\u4f7f\u8be5\u7c7b\u7684\u6784\u9020\u51fd\u6570\u80fd\u591f\u63a5\u6536\u4e00\u4e2a\u5355\u8bcd\u5217\u8868\u3002\u7136\u540e\u518d\u5b9e\u73b0\u4e00\u4e2a\u65b9\u6cd5\uff0c\u8be5\u65b9\u6cd5\u80fd\u591f\u5206\u522b\u63a5\u6536\u4e24\u4e2a\u5355\u8bcd word1 \u548c word2\uff0c\u5e76\u8fd4\u56de\u5217\u8868\u4e2d\u8fd9\u4e24\u4e2a\u5355\u8bcd\u4e4b\u95f4\u7684\u6700\u77ed\u8ddd\u79bb\u3002\u60a8\u7684\u65b9\u6cd5\u5c06\u88ab\u4ee5\u4e0d\u540c\u7684\u53c2\u6570\u8c03\u7528 \u591a\u6b21\u3002

    \n\n

    \u793a\u4f8b:
    \n\u5047\u8bbe words = ["practice", "makes", "perfect", "coding", "makes"]

    \n\n
    \u8f93\u5165: word1 = “coding”, word2 = “practice”\n\u8f93\u51fa: 3\n
    \n\n
    \u8f93\u5165: word1 = "makes", word2 = "coding"\n\u8f93\u51fa: 1
    \n\n

    \u6ce8\u610f:
    \n\u4f60\u53ef\u4ee5\u5047\u8bbe word1 \u4e0d\u7b49\u4e8e word2, \u5e76\u4e14 word1 \u548c word2 \u90fd\u5728\u5217\u8868\u91cc\u3002

    \n", "tags_en": ["Design", "Hash Table"], "tags_cn": ["\u8bbe\u8ba1", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class WordDistance {\npublic:\n WordDistance(vector& wordsDict) {\n\n }\n \n int shortest(string word1, string word2) {\n\n }\n};\n\n/**\n * Your WordDistance object will be instantiated and called as such:\n * WordDistance* obj = new WordDistance(wordsDict);\n * int param_1 = obj->shortest(word1,word2);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class WordDistance {\n\n public WordDistance(String[] wordsDict) {\n\n }\n \n public int shortest(String word1, String word2) {\n\n }\n}\n\n/**\n * Your WordDistance object will be instantiated and called as such:\n * WordDistance obj = new WordDistance(wordsDict);\n * int param_1 = obj.shortest(word1,word2);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class WordDistance(object):\n\n def __init__(self, wordsDict):\n \"\"\"\n :type wordsDict: List[str]\n \"\"\"\n\n\n def shortest(self, word1, word2):\n \"\"\"\n :type word1: str\n :type word2: str\n :rtype: int\n \"\"\"\n\n\n\n# Your WordDistance object will be instantiated and called as such:\n# obj = WordDistance(wordsDict)\n# param_1 = obj.shortest(word1,word2)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class WordDistance:\n\n def __init__(self, wordsDict: List[str]):\n\n\n def shortest(self, word1: str, word2: str) -> int:\n\n\n\n# Your WordDistance object will be instantiated and called as such:\n# obj = WordDistance(wordsDict)\n# param_1 = obj.shortest(word1,word2)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} WordDistance;\n\n\nWordDistance* wordDistanceCreate(char ** wordsDict, int wordsDictSize) {\n \n}\n\nint wordDistanceShortest(WordDistance* obj, char * word1, char * word2) {\n \n}\n\nvoid wordDistanceFree(WordDistance* obj) {\n \n}\n\n/**\n * Your WordDistance struct will be instantiated and called as such:\n * WordDistance* obj = wordDistanceCreate(wordsDict, wordsDictSize);\n * int param_1 = wordDistanceShortest(obj, word1, word2);\n \n * wordDistanceFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class WordDistance {\n\n public WordDistance(string[] wordsDict) {\n\n }\n \n public int Shortest(string word1, string word2) {\n\n }\n}\n\n/**\n * Your WordDistance object will be instantiated and called as such:\n * WordDistance obj = new WordDistance(wordsDict);\n * int param_1 = obj.Shortest(word1,word2);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} wordsDict\n */\nvar WordDistance = function(wordsDict) {\n\n};\n\n/** \n * @param {string} word1 \n * @param {string} word2\n * @return {number}\n */\nWordDistance.prototype.shortest = function(word1, word2) {\n\n};\n\n/**\n * Your WordDistance object will be instantiated and called as such:\n * var obj = new WordDistance(wordsDict)\n * var param_1 = obj.shortest(word1,word2)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class WordDistance\n\n=begin\n :type words_dict: String[]\n=end\n def initialize(words_dict)\n\n end\n\n\n=begin\n :type word1: String\n :type word2: String\n :rtype: Integer\n=end\n def shortest(word1, word2)\n\n end\n\n\nend\n\n# Your WordDistance object will be instantiated and called as such:\n# obj = WordDistance.new(words_dict)\n# param_1 = obj.shortest(word1, word2)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass WordDistance {\n\n init(_ wordsDict: [String]) {\n\n }\n \n func shortest(_ word1: String, _ word2: String) -> Int {\n\n }\n}\n\n/**\n * Your WordDistance object will be instantiated and called as such:\n * let obj = WordDistance(wordsDict)\n * let ret_1: Int = obj.shortest(word1, word2)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type WordDistance struct {\n\n}\n\n\nfunc Constructor(wordsDict []string) WordDistance {\n\n}\n\n\nfunc (this *WordDistance) Shortest(word1 string, word2 string) int {\n\n}\n\n\n/**\n * Your WordDistance object will be instantiated and called as such:\n * obj := Constructor(wordsDict);\n * param_1 := obj.Shortest(word1,word2);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class WordDistance(_wordsDict: Array[String]) {\n\n def shortest(word1: String, word2: String): Int = {\n\n }\n\n}\n\n/**\n * Your WordDistance object will be instantiated and called as such:\n * var obj = new WordDistance(wordsDict)\n * var param_1 = obj.shortest(word1,word2)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class WordDistance(wordsDict: Array) {\n\n fun shortest(word1: String, word2: String): Int {\n\n }\n\n}\n\n/**\n * Your WordDistance object will be instantiated and called as such:\n * var obj = WordDistance(wordsDict)\n * var param_1 = obj.shortest(word1,word2)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct WordDistance {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl WordDistance {\n\n fn new(wordsDict: Vec) -> Self {\n\n }\n \n fn shortest(&self, word1: String, word2: String) -> i32 {\n\n }\n}\n\n/**\n * Your WordDistance object will be instantiated and called as such:\n * let obj = WordDistance::new(wordsDict);\n * let ret_1: i32 = obj.shortest(word1, word2);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class WordDistance {\n /**\n * @param String[] $wordsDict\n */\n function __construct($wordsDict) {\n\n }\n\n /**\n * @param String $word1\n * @param String $word2\n * @return Integer\n */\n function shortest($word1, $word2) {\n\n }\n}\n\n/**\n * Your WordDistance object will be instantiated and called as such:\n * $obj = WordDistance($wordsDict);\n * $ret_1 = $obj->shortest($word1, $word2);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class WordDistance {\n constructor(wordsDict: string[]) {\n\n }\n\n shortest(word1: string, word2: string): number {\n\n }\n}\n\n/**\n * Your WordDistance object will be instantiated and called as such:\n * var obj = new WordDistance(wordsDict)\n * var param_1 = obj.shortest(word1,word2)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define word-distance%\n (class object%\n (super-new)\n\n ; words-dict : (listof string?)\n (init-field\n words-dict)\n \n ; shortest : string? string? -> exact-integer?\n (define/public (shortest word1 word2)\n\n )))\n\n;; Your word-distance% object will be instantiated and called as such:\n;; (define obj (new word-distance% [wordsDict wordsDict]))\n;; (define param_1 (send obj shortest word1 word2))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0244](https://leetcode-cn.com/problems/shortest-word-distance-ii)", "[\u6700\u77ed\u5355\u8bcd\u8ddd\u79bb II](/solution/0200-0299/0244.Shortest%20Word%20Distance%20II/README.md)", "`\u8bbe\u8ba1`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0244](https://leetcode.com/problems/shortest-word-distance-ii)", "[Shortest Word Distance II](/solution/0200-0299/0244.Shortest%20Word%20Distance%20II/README_EN.md)", "`Design`,`Hash Table`", "Medium", "\ud83d\udd12"]}, {"question_id": "0243", "frontend_question_id": "0243", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/shortest-word-distance", "url_en": "https://leetcode.com/problems/shortest-word-distance", "relative_path_cn": "/solution/0200-0299/0243.Shortest%20Word%20Distance/README.md", "relative_path_en": "/solution/0200-0299/0243.Shortest%20Word%20Distance/README_EN.md", "title_cn": "\u6700\u77ed\u5355\u8bcd\u8ddd\u79bb", "title_en": "Shortest Word Distance", "question_title_slug": "shortest-word-distance", "content_en": "

    Given an array of strings wordsDict and two different strings that already exist in the array word1 and word2, return the shortest distance between these two words in the list.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: wordsDict = ["practice", "makes", "perfect", "coding", "makes"], word1 = "coding", word2 = "practice"\nOutput: 3\n
    \n\n

    Example 2:

    \n\n
    \nInput: wordsDict = ["practice", "makes", "perfect", "coding", "makes"], word1 = "makes", word2 = "coding"\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= wordsDict.length <= 3 * 104
    • \n\t
    • 1 <= wordsDict[i].length <= 10
    • \n\t
    • wordsDict[i] consists of lowercase English letters.
    • \n\t
    • word1 and word2 are in wordsDict.
    • \n\t
    • word1 != word2
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5355\u8bcd\u5217\u8868\u548c\u4e24\u4e2a\u5355\u8bcd word1 \u548c word2\uff0c\u8fd4\u56de\u5217\u8868\u4e2d\u8fd9\u4e24\u4e2a\u5355\u8bcd\u4e4b\u95f4\u7684\u6700\u77ed\u8ddd\u79bb\u3002

    \n\n

    \u793a\u4f8b:
    \n\u5047\u8bbe words = ["practice", "makes", "perfect", "coding", "makes"]

    \n\n
    \u8f93\u5165: word1 = “coding”, word2 = “practice”\n\u8f93\u51fa: 3\n
    \n\n
    \u8f93\u5165: word1 = "makes", word2 = "coding"\n\u8f93\u51fa: 1\n
    \n\n

    \u6ce8\u610f:
    \n\u4f60\u53ef\u4ee5\u5047\u8bbe word1 \u4e0d\u7b49\u4e8e word2, \u5e76\u4e14 word1 \u548c word2 \u90fd\u5728\u5217\u8868\u91cc\u3002

    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int shortestDistance(vector& wordsDict, string word1, string word2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int shortestDistance(String[] wordsDict, String word1, String word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def shortestDistance(self, wordsDict, word1, word2):\n \"\"\"\n :type wordsDict: List[str]\n :type word1: str\n :type word2: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def shortestDistance(self, wordsDict: List[str], word1: str, word2: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint shortestDistance(char ** wordsDict, int wordsDictSize, char * word1, char * word2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ShortestDistance(string[] wordsDict, string word1, string word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} wordsDict\n * @param {string} word1\n * @param {string} word2\n * @return {number}\n */\nvar shortestDistance = function(wordsDict, word1, word2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words_dict\n# @param {String} word1\n# @param {String} word2\n# @return {Integer}\ndef shortest_distance(words_dict, word1, word2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func shortestDistance(_ wordsDict: [String], _ word1: String, _ word2: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func shortestDistance(wordsDict []string, word1 string, word2 string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def shortestDistance(wordsDict: Array[String], word1: String, word2: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun shortestDistance(wordsDict: Array, word1: String, word2: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn shortest_distance(words_dict: Vec, word1: String, word2: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $wordsDict\n * @param String $word1\n * @param String $word2\n * @return Integer\n */\n function shortestDistance($wordsDict, $word1, $word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function shortestDistance(wordsDict: string[], word1: string, word2: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (shortest-distance wordsDict word1 word2)\n (-> (listof string?) string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0243](https://leetcode-cn.com/problems/shortest-word-distance)", "[\u6700\u77ed\u5355\u8bcd\u8ddd\u79bb](/solution/0200-0299/0243.Shortest%20Word%20Distance/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0243](https://leetcode.com/problems/shortest-word-distance)", "[Shortest Word Distance](/solution/0200-0299/0243.Shortest%20Word%20Distance/README_EN.md)", "`Array`", "Easy", "\ud83d\udd12"]}, {"question_id": "0242", "frontend_question_id": "0242", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/valid-anagram", "url_en": "https://leetcode.com/problems/valid-anagram", "relative_path_cn": "/solution/0200-0299/0242.Valid%20Anagram/README.md", "relative_path_en": "/solution/0200-0299/0242.Valid%20Anagram/README_EN.md", "title_cn": "\u6709\u6548\u7684\u5b57\u6bcd\u5f02\u4f4d\u8bcd", "title_en": "Valid Anagram", "question_title_slug": "valid-anagram", "content_en": "

    Given two strings s and t, return true if t is an anagram of s, and false otherwise.

    \n\n

     

    \n

    Example 1:

    \n
    Input: s = \"anagram\", t = \"nagaram\"\nOutput: true\n

    Example 2:

    \n
    Input: s = \"rat\", t = \"car\"\nOutput: false\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length, t.length <= 5 * 104
    • \n\t
    • s and t consist of lowercase English letters.
    • \n
    \n\n

     

    \n

    Follow up: What if the inputs contain Unicode characters? How would you adapt your solution to such a case?

    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u5b57\u7b26\u4e32 s \u548c t \uff0c\u7f16\u5199\u4e00\u4e2a\u51fd\u6570\u6765\u5224\u65ad t \u662f\u5426\u662f s \u7684\u5b57\u6bcd\u5f02\u4f4d\u8bcd\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: s = "anagram", t = "nagaram"\n\u8f93\u51fa: true\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: s = "rat", t = "car"\n\u8f93\u51fa: false
    \n\n

    \u8bf4\u660e:
    \n\u4f60\u53ef\u4ee5\u5047\u8bbe\u5b57\u7b26\u4e32\u53ea\u5305\u542b\u5c0f\u5199\u5b57\u6bcd\u3002

    \n\n

    \u8fdb\u9636:
    \n\u5982\u679c\u8f93\u5165\u5b57\u7b26\u4e32\u5305\u542b unicode \u5b57\u7b26\u600e\u4e48\u529e\uff1f\u4f60\u80fd\u5426\u8c03\u6574\u4f60\u7684\u89e3\u6cd5\u6765\u5e94\u5bf9\u8fd9\u79cd\u60c5\u51b5\uff1f

    \n", "tags_en": ["Sort", "Hash Table"], "tags_cn": ["\u6392\u5e8f", "\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isAnagram(string s, string t) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isAnagram(String s, String t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isAnagram(self, s, t):\n \"\"\"\n :type s: str\n :type t: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isAnagram(self, s: str, t: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isAnagram(char * s, char * t){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsAnagram(string s, string t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string} t\n * @return {boolean}\n */\nvar isAnagram = function(s, t) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String} t\n# @return {Boolean}\ndef is_anagram(s, t)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isAnagram(_ s: String, _ t: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isAnagram(s string, t string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isAnagram(s: String, t: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isAnagram(s: String, t: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_anagram(s: String, t: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String $t\n * @return Boolean\n */\n function isAnagram($s, $t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isAnagram(s: string, t: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-anagram s t)\n (-> string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0242](https://leetcode-cn.com/problems/valid-anagram)", "[\u6709\u6548\u7684\u5b57\u6bcd\u5f02\u4f4d\u8bcd](/solution/0200-0299/0242.Valid%20Anagram/README.md)", "`\u6392\u5e8f`,`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0242](https://leetcode.com/problems/valid-anagram)", "[Valid Anagram](/solution/0200-0299/0242.Valid%20Anagram/README_EN.md)", "`Sort`,`Hash Table`", "Easy", ""]}, {"question_id": "0241", "frontend_question_id": "0241", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/different-ways-to-add-parentheses", "url_en": "https://leetcode.com/problems/different-ways-to-add-parentheses", "relative_path_cn": "/solution/0200-0299/0241.Different%20Ways%20to%20Add%20Parentheses/README.md", "relative_path_en": "/solution/0200-0299/0241.Different%20Ways%20to%20Add%20Parentheses/README_EN.md", "title_cn": "\u4e3a\u8fd0\u7b97\u8868\u8fbe\u5f0f\u8bbe\u8ba1\u4f18\u5148\u7ea7", "title_en": "Different Ways to Add Parentheses", "question_title_slug": "different-ways-to-add-parentheses", "content_en": "

    Given a string expression of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. You may return the answer in any order.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: expression = "2-1-1"\nOutput: [0,2]\nExplanation:\n((2-1)-1) = 0 \n(2-(1-1)) = 2\n
    \n\n

    Example 2:

    \n\n
    \nInput: expression = "2*3-4*5"\nOutput: [-34,-14,-10,-10,10]\nExplanation:\n(2*(3-(4*5))) = -34 \n((2*3)-(4*5)) = -14 \n((2*(3-4))*5) = -10 \n(2*((3-4)*5)) = -10 \n(((2*3)-4)*5) = 10\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= expression.length <= 20
    • \n\t
    • expression consists of digits and the operator '+', '-', and '*'.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u542b\u6709\u6570\u5b57\u548c\u8fd0\u7b97\u7b26\u7684\u5b57\u7b26\u4e32\uff0c\u4e3a\u8868\u8fbe\u5f0f\u6dfb\u52a0\u62ec\u53f7\uff0c\u6539\u53d8\u5176\u8fd0\u7b97\u4f18\u5148\u7ea7\u4ee5\u6c42\u51fa\u4e0d\u540c\u7684\u7ed3\u679c\u3002\u4f60\u9700\u8981\u7ed9\u51fa\u6240\u6709\u53ef\u80fd\u7684\u7ec4\u5408\u7684\u7ed3\u679c\u3002\u6709\u6548\u7684\u8fd0\u7b97\u7b26\u53f7\u5305\u542b +- \u4ee5\u53ca * \u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: "2-1-1"\n\u8f93\u51fa: [0, 2]\n\u89e3\u91ca: \n((2-1)-1) = 0 \n(2-(1-1)) = 2
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: "2*3-4*5"\n\u8f93\u51fa: [-34, -14, -10, -10, 10]\n\u89e3\u91ca: \n(2*(3-(4*5))) = -34 \n((2*3)-(4*5)) = -14 \n((2*(3-4))*5) = -10 \n(2*((3-4)*5)) = -10 \n(((2*3)-4)*5) = 10
    \n", "tags_en": ["Divide and Conquer"], "tags_cn": ["\u5206\u6cbb\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector diffWaysToCompute(string expression) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List diffWaysToCompute(String expression) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def diffWaysToCompute(self, expression):\n \"\"\"\n :type expression: str\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def diffWaysToCompute(self, expression: str) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* diffWaysToCompute(char * expression, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList DiffWaysToCompute(string expression) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} expression\n * @return {number[]}\n */\nvar diffWaysToCompute = function(expression) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} expression\n# @return {Integer[]}\ndef diff_ways_to_compute(expression)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func diffWaysToCompute(_ expression: String) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func diffWaysToCompute(expression string) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def diffWaysToCompute(expression: String): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun diffWaysToCompute(expression: String): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn diff_ways_to_compute(expression: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $expression\n * @return Integer[]\n */\n function diffWaysToCompute($expression) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function diffWaysToCompute(expression: string): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (diff-ways-to-compute expression)\n (-> string? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0241](https://leetcode-cn.com/problems/different-ways-to-add-parentheses)", "[\u4e3a\u8fd0\u7b97\u8868\u8fbe\u5f0f\u8bbe\u8ba1\u4f18\u5148\u7ea7](/solution/0200-0299/0241.Different%20Ways%20to%20Add%20Parentheses/README.md)", "`\u5206\u6cbb\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0241](https://leetcode.com/problems/different-ways-to-add-parentheses)", "[Different Ways to Add Parentheses](/solution/0200-0299/0241.Different%20Ways%20to%20Add%20Parentheses/README_EN.md)", "`Divide and Conquer`", "Medium", ""]}, {"question_id": "0240", "frontend_question_id": "0240", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/search-a-2d-matrix-ii", "url_en": "https://leetcode.com/problems/search-a-2d-matrix-ii", "relative_path_cn": "/solution/0200-0299/0240.Search%20a%202D%20Matrix%20II/README.md", "relative_path_en": "/solution/0200-0299/0240.Search%20a%202D%20Matrix%20II/README_EN.md", "title_cn": "\u641c\u7d22\u4e8c\u7ef4\u77e9\u9635 II", "title_en": "Search a 2D Matrix II", "question_title_slug": "search-a-2d-matrix-ii", "content_en": "

    Write an efficient algorithm that searches for a target value in an m x n integer matrix. The matrix has the following properties:

    \n\n
      \n\t
    • Integers in each row are sorted in ascending from left to right.
    • \n\t
    • Integers in each column are sorted in ascending from top to bottom.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: matrix = [[1,4,7,11,15],[2,5,8,12,19],[3,6,9,16,22],[10,13,14,17,24],[18,21,23,26,30]], target = 5\nOutput: true\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: matrix = [[1,4,7,11,15],[2,5,8,12,19],[3,6,9,16,22],[10,13,14,17,24],[18,21,23,26,30]], target = 20\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == matrix.length
    • \n\t
    • n == matrix[i].length
    • \n\t
    • 1 <= n, m <= 300
    • \n\t
    • -109 <= matix[i][j] <= 109
    • \n\t
    • All the integers in each row are sorted in ascending order.
    • \n\t
    • All the integers in each column are sorted in ascending order.
    • \n\t
    • -109 <= target <= 109
    • \n
    \n", "content_cn": "

    \u7f16\u5199\u4e00\u4e2a\u9ad8\u6548\u7684\u7b97\u6cd5\u6765\u641c\u7d22\u00a0m\u00a0x\u00a0n\u00a0\u77e9\u9635 matrix \u4e2d\u7684\u4e00\u4e2a\u76ee\u6807\u503c target \u3002\u8be5\u77e9\u9635\u5177\u6709\u4ee5\u4e0b\u7279\u6027\uff1a

    \n\n
      \n\t
    • \u6bcf\u884c\u7684\u5143\u7d20\u4ece\u5de6\u5230\u53f3\u5347\u5e8f\u6392\u5217\u3002
    • \n\t
    • \u6bcf\u5217\u7684\u5143\u7d20\u4ece\u4e0a\u5230\u4e0b\u5347\u5e8f\u6392\u5217\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1amatrix = [[1,4,7,11,15],[2,5,8,12,19],[3,6,9,16,22],[10,13,14,17,24],[18,21,23,26,30]], target = 5\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1amatrix = [[1,4,7,11,15],[2,5,8,12,19],[3,6,9,16,22],[10,13,14,17,24],[18,21,23,26,30]], target = 20\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == matrix.length
    • \n\t
    • n == matrix[i].length
    • \n\t
    • 1 <= n, m <= 300
    • \n\t
    • -109\u00a0<= matix[i][j] <= 109
    • \n\t
    • \u6bcf\u884c\u7684\u6240\u6709\u5143\u7d20\u4ece\u5de6\u5230\u53f3\u5347\u5e8f\u6392\u5217
    • \n\t
    • \u6bcf\u5217\u7684\u6240\u6709\u5143\u7d20\u4ece\u4e0a\u5230\u4e0b\u5347\u5e8f\u6392\u5217
    • \n\t
    • -109\u00a0<= target <= 109
    • \n
    \n", "tags_en": ["Binary Search", "Divide and Conquer"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e", "\u5206\u6cbb\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool searchMatrix(vector>& matrix, int target) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean searchMatrix(int[][] matrix, int target) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def searchMatrix(self, matrix, target):\n \"\"\"\n :type matrix: List[List[int]]\n :type target: int\n :rtype: bool\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def searchMatrix(self, matrix: List[List[int]], target: int) -> bool:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool searchMatrix(int** matrix, int matrixSize, int* matrixColSize, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool SearchMatrix(int[][] matrix, int target) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} matrix\n * @param {number} target\n * @return {boolean}\n */\nvar searchMatrix = function(matrix, target) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} matrix\n# @param {Integer} target\n# @return {Boolean}\ndef search_matrix(matrix, target)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func searchMatrix(_ matrix: [[Int]], _ target: Int) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func searchMatrix(matrix [][]int, target int) bool {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def searchMatrix(matrix: Array[Array[Int]], target: Int): Boolean = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun searchMatrix(matrix: Array, target: Int): Boolean {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn search_matrix(matrix: Vec>, target: i32) -> bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $matrix\n * @param Integer $target\n * @return Boolean\n */\n function searchMatrix($matrix, $target) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function searchMatrix(matrix: number[][], target: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0240](https://leetcode-cn.com/problems/search-a-2d-matrix-ii)", "[\u641c\u7d22\u4e8c\u7ef4\u77e9\u9635 II](/solution/0200-0299/0240.Search%20a%202D%20Matrix%20II/README.md)", "`\u4e8c\u5206\u67e5\u627e`,`\u5206\u6cbb\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0240](https://leetcode.com/problems/search-a-2d-matrix-ii)", "[Search a 2D Matrix II](/solution/0200-0299/0240.Search%20a%202D%20Matrix%20II/README_EN.md)", "`Binary Search`,`Divide and Conquer`", "Medium", ""]}, {"question_id": "0239", "frontend_question_id": "0239", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sliding-window-maximum", "url_en": "https://leetcode.com/problems/sliding-window-maximum", "relative_path_cn": "/solution/0200-0299/0239.Sliding%20Window%20Maximum/README.md", "relative_path_en": "/solution/0200-0299/0239.Sliding%20Window%20Maximum/README_EN.md", "title_cn": "\u6ed1\u52a8\u7a97\u53e3\u6700\u5927\u503c", "title_en": "Sliding Window Maximum", "question_title_slug": "sliding-window-maximum", "content_en": "

    You are given an array of integers nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window moves right by one position.

    \n\n

    Return the max sliding window.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,3,-1,-3,5,3,6,7], k = 3\nOutput: [3,3,5,5,6,7]\nExplanation: \nWindow position                Max\n---------------               -----\n[1  3  -1] -3  5  3  6  7       3\n 1 [3  -1  -3] 5  3  6  7       3\n 1  3 [-1  -3  5] 3  6  7       5\n 1  3  -1 [-3  5  3] 6  7       5\n 1  3  -1  -3 [5  3  6] 7       6\n 1  3  -1  -3  5 [3  6  7]      7\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1], k = 1\nOutput: [1]\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [1,-1], k = 1\nOutput: [1,-1]\n
    \n\n

    Example 4:

    \n\n
    \nInput: nums = [9,11], k = 2\nOutput: [11]\n
    \n\n

    Example 5:

    \n\n
    \nInput: nums = [4,-2], k = 2\nOutput: [4]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • -104 <= nums[i] <= 104
    • \n\t
    • 1 <= k <= nums.length
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums\uff0c\u6709\u4e00\u4e2a\u5927\u5c0f\u4e3a\u00a0k\u00a0\u7684\u6ed1\u52a8\u7a97\u53e3\u4ece\u6570\u7ec4\u7684\u6700\u5de6\u4fa7\u79fb\u52a8\u5230\u6570\u7ec4\u7684\u6700\u53f3\u4fa7\u3002\u4f60\u53ea\u53ef\u4ee5\u770b\u5230\u5728\u6ed1\u52a8\u7a97\u53e3\u5185\u7684 k\u00a0\u4e2a\u6570\u5b57\u3002\u6ed1\u52a8\u7a97\u53e3\u6bcf\u6b21\u53ea\u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\u3002

    \n\n

    \u8fd4\u56de\u6ed1\u52a8\u7a97\u53e3\u4e2d\u7684\u6700\u5927\u503c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,3,-1,-3,5,3,6,7], k = 3\n\u8f93\u51fa\uff1a[3,3,5,5,6,7]\n\u89e3\u91ca\uff1a\n\u6ed1\u52a8\u7a97\u53e3\u7684\u4f4d\u7f6e                \u6700\u5927\u503c\n---------------               -----\n[1  3  -1] -3  5  3  6  7       3\n 1 [3  -1  -3] 5  3  6  7       3\n 1  3 [-1  -3  5] 3  6  7       5\n 1  3  -1 [-3  5  3] 6  7       5\n 1  3  -1  -3 [5  3  6] 7       6\n 1  3  -1  -3  5 [3  6  7]      7\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1], k = 1\n\u8f93\u51fa\uff1a[1]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,-1], k = 1\n\u8f93\u51fa\uff1a[1,-1]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [9,11], k = 2\n\u8f93\u51fa\uff1a[11]\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [4,-2], k = 2\n\u8f93\u51fa\uff1a[4]
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • -104\u00a0<= nums[i] <= 104
    • \n\t
    • 1 <= k <= nums.length
    • \n
    \n", "tags_en": ["Heap", "Sliding Window"], "tags_cn": ["\u5806"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector maxSlidingWindow(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] maxSlidingWindow(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxSlidingWindow(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxSlidingWindow(self, nums: List[int], k: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* maxSlidingWindow(int* nums, int numsSize, int k, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] MaxSlidingWindow(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number[]}\n */\nvar maxSlidingWindow = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer[]}\ndef max_sliding_window(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxSlidingWindow(_ nums: [Int], _ k: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxSlidingWindow(nums []int, k int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxSlidingWindow(nums: Array[Int], k: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxSlidingWindow(nums: IntArray, k: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_sliding_window(nums: Vec, k: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer[]\n */\n function maxSlidingWindow($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxSlidingWindow(nums: number[], k: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-sliding-window nums k)\n (-> (listof exact-integer?) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0239](https://leetcode-cn.com/problems/sliding-window-maximum)", "[\u6ed1\u52a8\u7a97\u53e3\u6700\u5927\u503c](/solution/0200-0299/0239.Sliding%20Window%20Maximum/README.md)", "`\u5806`", "\u56f0\u96be", ""], "md_table_row_en": ["[0239](https://leetcode.com/problems/sliding-window-maximum)", "[Sliding Window Maximum](/solution/0200-0299/0239.Sliding%20Window%20Maximum/README_EN.md)", "`Heap`,`Sliding Window`", "Hard", ""]}, {"question_id": "0238", "frontend_question_id": "0238", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/product-of-array-except-self", "url_en": "https://leetcode.com/problems/product-of-array-except-self", "relative_path_cn": "/solution/0200-0299/0238.Product%20of%20Array%20Except%20Self/README.md", "relative_path_en": "/solution/0200-0299/0238.Product%20of%20Array%20Except%20Self/README_EN.md", "title_cn": "\u9664\u81ea\u8eab\u4ee5\u5916\u6570\u7ec4\u7684\u4e58\u79ef", "title_en": "Product of Array Except Self", "question_title_slug": "product-of-array-except-self", "content_en": "

    Given an integer array nums, return an array answer such that answer[i] is equal to the product of all the elements of nums except nums[i].

    \n\n

    The product of any prefix or suffix of nums is guaranteed to fit in a 32-bit integer.

    \n\n

    You must write an algorithm that runs in O(n) time and without using the division operation.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [1,2,3,4]\nOutput: [24,12,8,6]\n

    Example 2:

    \n
    Input: nums = [-1,1,0,-3,3]\nOutput: [0,0,9,0,0]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= nums.length <= 105
    • \n\t
    • -30 <= nums[i] <= 30
    • \n\t
    • The product of any prefix or suffix of nums is guaranteed to fit in a 32-bit integer.
    • \n
    \n\n

     

    \n

    Follow up: Can you solve the problem in O(1) extra space complexity? (The output array does not count as extra space for space complexity analysis.)

    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u6574\u6570\u6570\u7ec4 nums\uff0c\u5176\u4e2d n > 1\uff0c\u8fd4\u56de\u8f93\u51fa\u6570\u7ec4 output \uff0c\u5176\u4e2d output[i] \u7b49\u4e8e nums \u4e2d\u9664 nums[i] \u4e4b\u5916\u5176\u4f59\u5404\u5143\u7d20\u7684\u4e58\u79ef\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: [1,2,3,4]\n\u8f93\u51fa: [24,12,8,6]
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a\u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u6570\u7ec4\u4e4b\u4e2d\u4efb\u610f\u5143\u7d20\u7684\u5168\u90e8\u524d\u7f00\u5143\u7d20\u548c\u540e\u7f00\uff08\u751a\u81f3\u662f\u6574\u4e2a\u6570\u7ec4\uff09\u7684\u4e58\u79ef\u90fd\u5728 32 \u4f4d\u6574\u6570\u8303\u56f4\u5185\u3002

    \n\n

    \u8bf4\u660e: \u8bf7\u4e0d\u8981\u4f7f\u7528\u9664\u6cd5\uff0c\u4e14\u5728 O(n) \u65f6\u95f4\u590d\u6742\u5ea6\u5185\u5b8c\u6210\u6b64\u9898\u3002

    \n\n

    \u8fdb\u9636\uff1a
    \n\u4f60\u53ef\u4ee5\u5728\u5e38\u6570\u7a7a\u95f4\u590d\u6742\u5ea6\u5185\u5b8c\u6210\u8fd9\u4e2a\u9898\u76ee\u5417\uff1f\uff08 \u51fa\u4e8e\u5bf9\u7a7a\u95f4\u590d\u6742\u5ea6\u5206\u6790\u7684\u76ee\u7684\uff0c\u8f93\u51fa\u6570\u7ec4\u4e0d\u88ab\u89c6\u4e3a\u989d\u5916\u7a7a\u95f4\u3002\uff09

    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector productExceptSelf(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] productExceptSelf(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def productExceptSelf(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def productExceptSelf(self, nums: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* productExceptSelf(int* nums, int numsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] ProductExceptSelf(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar productExceptSelf = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer[]}\ndef product_except_self(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func productExceptSelf(_ nums: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func productExceptSelf(nums []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def productExceptSelf(nums: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun productExceptSelf(nums: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn product_except_self(nums: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer[]\n */\n function productExceptSelf($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function productExceptSelf(nums: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (product-except-self nums)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0238](https://leetcode-cn.com/problems/product-of-array-except-self)", "[\u9664\u81ea\u8eab\u4ee5\u5916\u6570\u7ec4\u7684\u4e58\u79ef](/solution/0200-0299/0238.Product%20of%20Array%20Except%20Self/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0238](https://leetcode.com/problems/product-of-array-except-self)", "[Product of Array Except Self](/solution/0200-0299/0238.Product%20of%20Array%20Except%20Self/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0237", "frontend_question_id": "0237", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/delete-node-in-a-linked-list", "url_en": "https://leetcode.com/problems/delete-node-in-a-linked-list", "relative_path_cn": "/solution/0200-0299/0237.Delete%20Node%20in%20a%20Linked%20List/README.md", "relative_path_en": "/solution/0200-0299/0237.Delete%20Node%20in%20a%20Linked%20List/README_EN.md", "title_cn": "\u5220\u9664\u94fe\u8868\u4e2d\u7684\u8282\u70b9", "title_en": "Delete Node in a Linked List", "question_title_slug": "delete-node-in-a-linked-list", "content_en": "

    Write a function to delete a node in a singly-linked list. You will not be given access to the head of the list, instead you will be given access to the node to be deleted directly.

    \n\n

    It is guaranteed that the node to be deleted is not a tail node in the list.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: head = [4,5,1,9], node = 5\nOutput: [4,1,9]\nExplanation: You are given the second node with value 5, the linked list should become 4 -> 1 -> 9 after calling your function.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: head = [4,5,1,9], node = 1\nOutput: [4,5,9]\nExplanation: You are given the third node with value 1, the linked list should become 4 -> 5 -> 9 after calling your function.\n
    \n\n

    Example 3:

    \n\n
    \nInput: head = [1,2,3,4], node = 3\nOutput: [1,2,4]\n
    \n\n

    Example 4:

    \n\n
    \nInput: head = [0,1], node = 0\nOutput: [1]\n
    \n\n

    Example 5:

    \n\n
    \nInput: head = [-3,5,-99], node = -3\nOutput: [5,-99]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of the nodes in the given list is in the range [2, 1000].
    • \n\t
    • -1000 <= Node.val <= 1000
    • \n\t
    • The value of each node in the list is unique.
    • \n\t
    • The node to be deleted is in the list and is not a tail node
    • \n
    \n", "content_cn": "

    \u8bf7\u7f16\u5199\u4e00\u4e2a\u51fd\u6570\uff0c\u4f7f\u5176\u53ef\u4ee5\u5220\u9664\u67d0\u4e2a\u94fe\u8868\u4e2d\u7ed9\u5b9a\u7684\uff08\u975e\u672b\u5c3e\uff09\u8282\u70b9\u3002\u4f20\u5165\u51fd\u6570\u7684\u552f\u4e00\u53c2\u6570\u4e3a \u8981\u88ab\u5220\u9664\u7684\u8282\u70b9 \u3002

    \n\n

     

    \n\n

    \u73b0\u6709\u4e00\u4e2a\u94fe\u8868 -- head = [4,5,1,9]\uff0c\u5b83\u53ef\u4ee5\u8868\u793a\u4e3a:

    \n\n

    \"\"

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1ahead = [4,5,1,9], node = 5\n\u8f93\u51fa\uff1a[4,1,9]\n\u89e3\u91ca\uff1a\u7ed9\u5b9a\u4f60\u94fe\u8868\u4e2d\u503c\u4e3a 5 \u7684\u7b2c\u4e8c\u4e2a\u8282\u70b9\uff0c\u90a3\u4e48\u5728\u8c03\u7528\u4e86\u4f60\u7684\u51fd\u6570\u4e4b\u540e\uff0c\u8be5\u94fe\u8868\u5e94\u53d8\u4e3a 4 -> 1 -> 9.\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1ahead = [4,5,1,9], node = 1\n\u8f93\u51fa\uff1a[4,5,9]\n\u89e3\u91ca\uff1a\u7ed9\u5b9a\u4f60\u94fe\u8868\u4e2d\u503c\u4e3a 1 \u7684\u7b2c\u4e09\u4e2a\u8282\u70b9\uff0c\u90a3\u4e48\u5728\u8c03\u7528\u4e86\u4f60\u7684\u51fd\u6570\u4e4b\u540e\uff0c\u8be5\u94fe\u8868\u5e94\u53d8\u4e3a 4 -> 5 -> 9.\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u94fe\u8868\u81f3\u5c11\u5305\u542b\u4e24\u4e2a\u8282\u70b9\u3002
    • \n\t
    • \u94fe\u8868\u4e2d\u6240\u6709\u8282\u70b9\u7684\u503c\u90fd\u662f\u552f\u4e00\u7684\u3002
    • \n\t
    • \u7ed9\u5b9a\u7684\u8282\u70b9\u4e3a\u975e\u672b\u5c3e\u8282\u70b9\u5e76\u4e14\u4e00\u5b9a\u662f\u94fe\u8868\u4e2d\u7684\u4e00\u4e2a\u6709\u6548\u8282\u70b9\u3002
    • \n\t
    • \u4e0d\u8981\u4ece\u4f60\u7684\u51fd\u6570\u4e2d\u8fd4\u56de\u4efb\u4f55\u7ed3\u679c\u3002
    • \n
    \n", "tags_en": ["Linked List"], "tags_cn": ["\u94fe\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\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 void deleteNode(ListNode* node) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode(int x) { val = x; }\n * }\n */\nclass Solution {\n public void deleteNode(ListNode node) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.next = None\n\nclass Solution(object):\n def deleteNode(self, node):\n \"\"\"\n :type node: ListNode\n :rtype: void Do not return anything, modify node in-place instead.\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, x):\n# self.val = x\n# self.next = None\n\nclass Solution:\n def deleteNode(self, node):\n \"\"\"\n :type node: ListNode\n :rtype: void Do not return anything, modify node in-place instead.\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\nvoid deleteNode(struct ListNode* node) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int x) { val = x; }\n * }\n */\npublic class Solution {\n public void DeleteNode(ListNode node) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val) {\n * this.val = val;\n * this.next = null;\n * }\n */\n/**\n * @param {ListNode} node\n * @return {void} Do not return anything, modify node in-place instead.\n */\nvar deleteNode = function(node) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val)\n# @val = val\n# @next = nil\n# end\n# end\n\n# @param {ListNode} node\n# @return {Void} Do not return anything, modify node in-place instead.\ndef delete_node(node)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.next = nil\n * }\n * }\n */\n\nclass Solution {\n func deleteNode(_ node: ListNode?) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc deleteNode(node *ListNode) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(var _x: Int = 0) {\n * var next: ListNode = null\n * var x: Int = _x\n * }\n */\n\nobject Solution {\n def deleteNode(node: ListNode): Unit = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\n\nclass Solution {\n fun deleteNode(node: ListNode?) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val) { $this->val = $val; }\n * }\n */\n\nclass Solution {\n /**\n * @param ListNode $node\n * @return \n */\n function deleteNode($node) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\n/**\n Do not return anything, modify it in-place instead.\n */\nfunction deleteNode(root: ListNode | null): void {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0237](https://leetcode-cn.com/problems/delete-node-in-a-linked-list)", "[\u5220\u9664\u94fe\u8868\u4e2d\u7684\u8282\u70b9](/solution/0200-0299/0237.Delete%20Node%20in%20a%20Linked%20List/README.md)", "`\u94fe\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0237](https://leetcode.com/problems/delete-node-in-a-linked-list)", "[Delete Node in a Linked List](/solution/0200-0299/0237.Delete%20Node%20in%20a%20Linked%20List/README_EN.md)", "`Linked List`", "Easy", ""]}, {"question_id": "0236", "frontend_question_id": "0236", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-tree", "url_en": "https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree", "relative_path_cn": "/solution/0200-0299/0236.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree/README.md", "relative_path_en": "/solution/0200-0299/0236.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148", "title_en": "Lowest Common Ancestor of a Binary Tree", "question_title_slug": "lowest-common-ancestor-of-a-binary-tree", "content_en": "

    Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.

    \n\n

    According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes p and q as the lowest node in T that has both p and q as descendants (where we allow a node to be a descendant of itself).”

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 1\nOutput: 3\nExplanation: The LCA of nodes 5 and 1 is 3.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 4\nOutput: 5\nExplanation: The LCA of nodes 5 and 4 is 5, since a node can be a descendant of itself according to the LCA definition.\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = [1,2], p = 1, q = 2\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [2, 105].
    • \n\t
    • -109 <= Node.val <= 109
    • \n\t
    • All Node.val are unique.
    • \n\t
    • p != q
    • \n\t
    • p and q will exist in the tree.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811, \u627e\u5230\u8be5\u6811\u4e2d\u4e24\u4e2a\u6307\u5b9a\u8282\u70b9\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148\u3002

    \n\n

    \u767e\u5ea6\u767e\u79d1\u4e2d\u6700\u8fd1\u516c\u5171\u7956\u5148\u7684\u5b9a\u4e49\u4e3a\uff1a\u201c\u5bf9\u4e8e\u6709\u6839\u6811 T \u7684\u4e24\u4e2a\u8282\u70b9 p\u3001q\uff0c\u6700\u8fd1\u516c\u5171\u7956\u5148\u8868\u793a\u4e3a\u4e00\u4e2a\u8282\u70b9 x\uff0c\u6ee1\u8db3 x \u662f p\u3001q \u7684\u7956\u5148\u4e14 x \u7684\u6df1\u5ea6\u5c3d\u53ef\u80fd\u5927\uff08\u4e00\u4e2a\u8282\u70b9\u4e5f\u53ef\u4ee5\u662f\u5b83\u81ea\u5df1\u7684\u7956\u5148\uff09\u3002\u201d

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 1\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u8282\u70b9 5 \u548c\u8282\u70b9 1 \u7684\u6700\u8fd1\u516c\u5171\u7956\u5148\u662f\u8282\u70b9 3 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 4\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u8282\u70b9 5 \u548c\u8282\u70b9 4 \u7684\u6700\u8fd1\u516c\u5171\u7956\u5148\u662f\u8282\u70b9 5 \u3002\u56e0\u4e3a\u6839\u636e\u5b9a\u4e49\u6700\u8fd1\u516c\u5171\u7956\u5148\u8282\u70b9\u53ef\u4ee5\u4e3a\u8282\u70b9\u672c\u8eab\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [1,2], p = 1, q = 2\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u6570\u76ee\u5728\u8303\u56f4 [2, 105] \u5185\u3002
    • \n\t
    • -109 <= Node.val <= 109
    • \n\t
    • \u6240\u6709 Node.val \u4e92\u4e0d\u76f8\u540c \u3002
    • \n\t
    • p != q
    • \n\t
    • p \u548c q \u5747\u5b58\u5728\u4e8e\u7ed9\u5b9a\u7684\u4e8c\u53c9\u6811\u4e2d\u3002
    • \n
    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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 */\nclass Solution {\npublic:\n TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode(int x) { val = x; }\n * }\n */\nclass Solution {\n public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution(object):\n def lowestCommonAncestor(self, root, p, q):\n \"\"\"\n :type root: TreeNode\n :type p: TreeNode\n :type q: TreeNode\n :rtype: TreeNode\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution:\n def lowestCommonAncestor(self, root: 'TreeNode', p: 'TreeNode', q: 'TreeNode') -> 'TreeNode':\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\nstruct TreeNode* lowestCommonAncestor(struct TreeNode* root, struct TreeNode* p, struct TreeNode* q) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int x) { val = x; }\n * }\n */\npublic class Solution {\n public TreeNode LowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val) {\n * this.val = val;\n * this.left = this.right = null;\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {TreeNode} p\n * @param {TreeNode} q\n * @return {TreeNode}\n */\nvar lowestCommonAncestor = function(root, p, q) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val)\n# @val = val\n# @left, @right = nil, nil\n# end\n# end\n\n# @param {TreeNode} root\n# @param {TreeNode} p\n# @param {TreeNode} q\n# @return {TreeNode}\ndef lowest_common_ancestor(root, p, q)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.left = nil\n * self.right = nil\n * }\n * }\n */\n\nclass Solution {\n func lowestCommonAncestor(_ root: TreeNode?, _ p: TreeNode?, _ q: TreeNode?) -> TreeNode? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\n func lowestCommonAncestor(root, p, q *TreeNode) *TreeNode {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(var _value: Int) {\n * var value: Int = _value\n * var left: TreeNode = null\n * var right: TreeNode = null\n * }\n */\n\nobject Solution {\n def lowestCommonAncestor(root: TreeNode, p: TreeNode, q: TreeNode): TreeNode = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int = 0) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\n\nclass Solution {\n fun lowestCommonAncestor(root: TreeNode?, p: TreeNode?, q: TreeNode?): TreeNode? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n// \n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn lowest_common_ancestor(root: Option>>, p: Option>>, q: Option>>) -> Option>> {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($value) { $this->val = $value; }\n * }\n */\n\nclass Solution {\n /**\n * @param TreeNode $root\n * @param TreeNode $p\n * @param TreeNode $q\n * @return TreeNode\n */\n function lowestCommonAncestor($root, $p, $q) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction lowestCommonAncestor(root: TreeNode | null, p: TreeNode | null, q: TreeNode | null): TreeNode | null {\n\t\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0236](https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-tree)", "[\u4e8c\u53c9\u6811\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148](/solution/0200-0299/0236.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree/README.md)", "`\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0236](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree)", "[Lowest Common Ancestor of a Binary Tree](/solution/0200-0299/0236.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree/README_EN.md)", "`Tree`", "Medium", ""]}, {"question_id": "0235", "frontend_question_id": "0235", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-search-tree", "url_en": "https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree", "relative_path_cn": "/solution/0200-0299/0235.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Search%20Tree/README.md", "relative_path_en": "/solution/0200-0299/0235.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Search%20Tree/README_EN.md", "title_cn": "\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148", "title_en": "Lowest Common Ancestor of a Binary Search Tree", "question_title_slug": "lowest-common-ancestor-of-a-binary-search-tree", "content_en": "

    Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.

    \n\n

    According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes p and q as the lowest node in T that has both p and q as descendants (where we allow a node to be a descendant of itself).”

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [6,2,8,0,4,7,9,null,null,3,5], p = 2, q = 8\nOutput: 6\nExplanation: The LCA of nodes 2 and 8 is 6.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [6,2,8,0,4,7,9,null,null,3,5], p = 2, q = 4\nOutput: 2\nExplanation: The LCA of nodes 2 and 4 is 2, since a node can be a descendant of itself according to the LCA definition.\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = [2,1], p = 2, q = 1\nOutput: 2\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [2, 105].
    • \n\t
    • -109 <= Node.val <= 109
    • \n\t
    • All Node.val are unique.
    • \n\t
    • p != q
    • \n\t
    • p and q will exist in the BST.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u641c\u7d22\u6811, \u627e\u5230\u8be5\u6811\u4e2d\u4e24\u4e2a\u6307\u5b9a\u8282\u70b9\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148\u3002

    \n\n

    \u767e\u5ea6\u767e\u79d1\u4e2d\u6700\u8fd1\u516c\u5171\u7956\u5148\u7684\u5b9a\u4e49\u4e3a\uff1a“\u5bf9\u4e8e\u6709\u6839\u6811 T \u7684\u4e24\u4e2a\u7ed3\u70b9 p\u3001q\uff0c\u6700\u8fd1\u516c\u5171\u7956\u5148\u8868\u793a\u4e3a\u4e00\u4e2a\u7ed3\u70b9 x\uff0c\u6ee1\u8db3 x \u662f p\u3001q \u7684\u7956\u5148\u4e14 x \u7684\u6df1\u5ea6\u5c3d\u53ef\u80fd\u5927\uff08\u4e00\u4e2a\u8282\u70b9\u4e5f\u53ef\u4ee5\u662f\u5b83\u81ea\u5df1\u7684\u7956\u5148\uff09\u3002”

    \n\n

    \u4f8b\u5982\uff0c\u7ed9\u5b9a\u5982\u4e0b\u4e8c\u53c9\u641c\u7d22\u6811:  root = [6,2,8,0,4,7,9,null,null,3,5]

    \n\n

    \"\"

    \n\n

     

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: root = [6,2,8,0,4,7,9,null,null,3,5], p = 2, q = 8\n\u8f93\u51fa: 6 \n\u89e3\u91ca: \u8282\u70b9 2 \u548c\u8282\u70b9 8 \u7684\u6700\u8fd1\u516c\u5171\u7956\u5148\u662f 6\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: root = [6,2,8,0,4,7,9,null,null,3,5], p = 2, q = 4\n\u8f93\u51fa: 2\n\u89e3\u91ca: \u8282\u70b9 2 \u548c\u8282\u70b9 4 \u7684\u6700\u8fd1\u516c\u5171\u7956\u5148\u662f 2, \u56e0\u4e3a\u6839\u636e\u5b9a\u4e49\u6700\u8fd1\u516c\u5171\u7956\u5148\u8282\u70b9\u53ef\u4ee5\u4e3a\u8282\u70b9\u672c\u8eab\u3002
    \n\n

     

    \n\n

    \u8bf4\u660e:

    \n\n
      \n\t
    • \u6240\u6709\u8282\u70b9\u7684\u503c\u90fd\u662f\u552f\u4e00\u7684\u3002
    • \n\t
    • p\u3001q \u4e3a\u4e0d\u540c\u8282\u70b9\u4e14\u5747\u5b58\u5728\u4e8e\u7ed9\u5b9a\u7684\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u3002
    • \n
    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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\nclass Solution {\npublic:\n TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode(int x) { val = x; }\n * }\n */\n\nclass Solution {\n public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution(object):\n def lowestCommonAncestor(self, root, p, q):\n \"\"\"\n :type root: TreeNode\n :type p: TreeNode\n :type q: TreeNode\n :rtype: TreeNode\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution:\n def lowestCommonAncestor(self, root: 'TreeNode', p: 'TreeNode', q: 'TreeNode') -> 'TreeNode':\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\nstruct TreeNode* lowestCommonAncestor(struct TreeNode* root, struct TreeNode* p, struct TreeNode* q) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int x) { val = x; }\n * }\n */\n\npublic class Solution {\n public TreeNode LowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val) {\n * this.val = val;\n * this.left = this.right = null;\n * }\n */\n\n/**\n * @param {TreeNode} root\n * @param {TreeNode} p\n * @param {TreeNode} q\n * @return {TreeNode}\n */\nvar lowestCommonAncestor = function(root, p, q) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val)\n# @val = val\n# @left, @right = nil, nil\n# end\n# end\n\n# @param {TreeNode} root\n# @param {TreeNode} p\n# @param {TreeNode} q\n# @return {TreeNode}\ndef lowest_common_ancestor(root, p, q)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.left = nil\n * self.right = nil\n * }\n * }\n */\n\nclass Solution {\n func lowestCommonAncestor(_ root: TreeNode?, _ p: TreeNode?, _ q: TreeNode?) -> TreeNode? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\n\nfunc lowestCommonAncestor(root, p, q *TreeNode) *TreeNode {\n\t\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(var _value: Int) {\n * var value: Int = _value\n * var left: TreeNode = null\n * var right: TreeNode = null\n * }\n */\n\nobject Solution {\n def lowestCommonAncestor(root: TreeNode, p: TreeNode, q: TreeNode): TreeNode = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int = 0) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\n\nclass Solution {\n fun lowestCommonAncestor(root: TreeNode?, p: TreeNode?, q: TreeNode?): TreeNode? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n// \n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn lowest_common_ancestor(root: Option>>, p: Option>>, q: Option>>) -> Option>> {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($value) { $this->val = $value; }\n * }\n */\n\nclass Solution {\n /**\n * @param TreeNode $root\n * @param TreeNode $p\n * @param TreeNode $q\n * @return TreeNode\n */\n function lowestCommonAncestor($root, $p, $q) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction lowestCommonAncestor(root: TreeNode | null, p: TreeNode | null, q: TreeNode | null): TreeNode | null {\n\t\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0235](https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-search-tree)", "[\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148](/solution/0200-0299/0235.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Search%20Tree/README.md)", "`\u6811`", "\u7b80\u5355", ""], "md_table_row_en": ["[0235](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree)", "[Lowest Common Ancestor of a Binary Search Tree](/solution/0200-0299/0235.Lowest%20Common%20Ancestor%20of%20a%20Binary%20Search%20Tree/README_EN.md)", "`Tree`", "Easy", ""]}, {"question_id": "0234", "frontend_question_id": "0234", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/palindrome-linked-list", "url_en": "https://leetcode.com/problems/palindrome-linked-list", "relative_path_cn": "/solution/0200-0299/0234.Palindrome%20Linked%20List/README.md", "relative_path_en": "/solution/0200-0299/0234.Palindrome%20Linked%20List/README_EN.md", "title_cn": "\u56de\u6587\u94fe\u8868", "title_en": "Palindrome Linked List", "question_title_slug": "palindrome-linked-list", "content_en": "

    Given the head of a singly linked list, return true if it is a palindrome.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: head = [1,2,2,1]\nOutput: true\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: head = [1,2]\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the list is in the range [1, 105].
    • \n\t
    • 0 <= Node.val <= 9
    • \n
    \n\n

     

    \nFollow up: Could you do it in O(n) time and O(1) space?", "content_cn": "

    \u8bf7\u5224\u65ad\u4e00\u4e2a\u94fe\u8868\u662f\u5426\u4e3a\u56de\u6587\u94fe\u8868\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: 1->2\n\u8f93\u51fa: false
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: 1->2->2->1\n\u8f93\u51fa: true\n
    \n\n

    \u8fdb\u9636\uff1a
    \n\u4f60\u80fd\u5426\u7528 O(n) \u65f6\u95f4\u590d\u6742\u5ea6\u548c O(1) \u7a7a\u95f4\u590d\u6742\u5ea6\u89e3\u51b3\u6b64\u9898\uff1f

    \n", "tags_en": ["Linked List", "Two Pointers"], "tags_cn": ["\u94fe\u8868", "\u53cc\u6307\u9488"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n bool isPalindrome(ListNode* head) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public boolean isPalindrome(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def isPalindrome(self, head):\n \"\"\"\n :type head: ListNode\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def isPalindrome(self, head: ListNode) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nbool isPalindrome(struct ListNode* head){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public bool IsPalindrome(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} head\n * @return {boolean}\n */\nvar isPalindrome = function(head) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode} head\n# @return {Boolean}\ndef is_palindrome(head)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func isPalindrome(_ head: ListNode?) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc isPalindrome(head *ListNode) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def isPalindrome(head: ListNode): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun isPalindrome(head: ListNode?): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn is_palindrome(head: Option>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @return Boolean\n */\n function isPalindrome($head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction isPalindrome(head: ListNode | null): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (is-palindrome head)\n (-> (or/c list-node? #f) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0234](https://leetcode-cn.com/problems/palindrome-linked-list)", "[\u56de\u6587\u94fe\u8868](/solution/0200-0299/0234.Palindrome%20Linked%20List/README.md)", "`\u94fe\u8868`,`\u53cc\u6307\u9488`", "\u7b80\u5355", ""], "md_table_row_en": ["[0234](https://leetcode.com/problems/palindrome-linked-list)", "[Palindrome Linked List](/solution/0200-0299/0234.Palindrome%20Linked%20List/README_EN.md)", "`Linked List`,`Two Pointers`", "Easy", ""]}, {"question_id": "0233", "frontend_question_id": "0233", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-digit-one", "url_en": "https://leetcode.com/problems/number-of-digit-one", "relative_path_cn": "/solution/0200-0299/0233.Number%20of%20Digit%20One/README.md", "relative_path_en": "/solution/0200-0299/0233.Number%20of%20Digit%20One/README_EN.md", "title_cn": "\u6570\u5b57 1 \u7684\u4e2a\u6570", "title_en": "Number of Digit One", "question_title_slug": "number-of-digit-one", "content_en": "

    Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 13\nOutput: 6\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 0\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= n <= 2 * 109
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570 n\uff0c\u8ba1\u7b97\u6240\u6709\u5c0f\u4e8e\u7b49\u4e8e n \u7684\u975e\u8d1f\u6574\u6570\u4e2d\u6570\u5b57 1 \u51fa\u73b0\u7684\u4e2a\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 13\n\u8f93\u51fa\uff1a6\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 0\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= n <= 2 * 109
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countDigitOne(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countDigitOne(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countDigitOne(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countDigitOne(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countDigitOne(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountDigitOne(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar countDigitOne = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef count_digit_one(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countDigitOne(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countDigitOne(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countDigitOne(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countDigitOne(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_digit_one(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function countDigitOne($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countDigitOne(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-digit-one n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0233](https://leetcode-cn.com/problems/number-of-digit-one)", "[\u6570\u5b57 1 \u7684\u4e2a\u6570](/solution/0200-0299/0233.Number%20of%20Digit%20One/README.md)", "`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[0233](https://leetcode.com/problems/number-of-digit-one)", "[Number of Digit One](/solution/0200-0299/0233.Number%20of%20Digit%20One/README_EN.md)", "`Math`", "Hard", ""]}, {"question_id": "0232", "frontend_question_id": "0232", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/implement-queue-using-stacks", "url_en": "https://leetcode.com/problems/implement-queue-using-stacks", "relative_path_cn": "/solution/0200-0299/0232.Implement%20Queue%20using%20Stacks/README.md", "relative_path_en": "/solution/0200-0299/0232.Implement%20Queue%20using%20Stacks/README_EN.md", "title_cn": "\u7528\u6808\u5b9e\u73b0\u961f\u5217", "title_en": "Implement Queue using Stacks", "question_title_slug": "implement-queue-using-stacks", "content_en": "

    Implement a first in first out (FIFO) queue using only two stacks. The implemented queue should support all the functions of a normal queue (push, peek, pop, and empty).

    \n\n

    Implement the MyQueue class:

    \n\n
      \n\t
    • void push(int x) Pushes element x to the back of the queue.
    • \n\t
    • int pop() Removes the element from the front of the queue and returns it.
    • \n\t
    • int peek() Returns the element at the front of the queue.
    • \n\t
    • boolean empty() Returns true if the queue is empty, false otherwise.
    • \n
    \n\n

    Notes:

    \n\n
      \n\t
    • You must use only standard operations of a stack, which means only push to top, peek/pop from top, size, and is empty operations are valid.
    • \n\t
    • Depending on your language, the stack may not be supported natively. You may simulate a stack using a list or deque (double-ended queue) as long as you use only a stack's standard operations.
    • \n
    \n\n

    Follow-up: Can you implement the queue such that each operation is amortized O(1) time complexity? In other words, performing n operations will take overall O(n) time even if one of those operations may take longer.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["MyQueue", "push", "push", "peek", "pop", "empty"]\n[[], [1], [2], [], [], []]\nOutput\n[null, null, null, 1, 1, false]\n\nExplanation\nMyQueue myQueue = new MyQueue();\nmyQueue.push(1); // queue is: [1]\nmyQueue.push(2); // queue is: [1, 2] (leftmost is front of the queue)\nmyQueue.peek(); // return 1\nmyQueue.pop(); // return 1, queue is [2]\nmyQueue.empty(); // return false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= x <= 9
    • \n\t
    • At most 100 calls will be made to push, pop, peek, and empty.
    • \n\t
    • All the calls to pop and peek are valid.
    • \n
    \n", "content_cn": "

    \u8bf7\u4f60\u4ec5\u4f7f\u7528\u4e24\u4e2a\u6808\u5b9e\u73b0\u5148\u5165\u5148\u51fa\u961f\u5217\u3002\u961f\u5217\u5e94\u5f53\u652f\u6301\u4e00\u822c\u961f\u5217\u652f\u6301\u7684\u6240\u6709\u64cd\u4f5c\uff08push\u3001pop\u3001peek\u3001empty\uff09\uff1a

    \n\n

    \u5b9e\u73b0 MyQueue \u7c7b\uff1a

    \n\n
      \n\t
    • void push(int x) \u5c06\u5143\u7d20 x \u63a8\u5230\u961f\u5217\u7684\u672b\u5c3e
    • \n\t
    • int pop() \u4ece\u961f\u5217\u7684\u5f00\u5934\u79fb\u9664\u5e76\u8fd4\u56de\u5143\u7d20
    • \n\t
    • int peek() \u8fd4\u56de\u961f\u5217\u5f00\u5934\u7684\u5143\u7d20
    • \n\t
    • boolean empty() \u5982\u679c\u961f\u5217\u4e3a\u7a7a\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false
    • \n
    \n\n

    \u00a0

    \n\n

    \u8bf4\u660e\uff1a

    \n\n
      \n\t
    • \u4f60\u53ea\u80fd\u4f7f\u7528\u6807\u51c6\u7684\u6808\u64cd\u4f5c \u2014\u2014 \u4e5f\u5c31\u662f\u53ea\u6709\u00a0push to top,\u00a0peek/pop from top,\u00a0size, \u548c\u00a0is empty\u00a0\u64cd\u4f5c\u662f\u5408\u6cd5\u7684\u3002
    • \n\t
    • \u4f60\u6240\u4f7f\u7528\u7684\u8bed\u8a00\u4e5f\u8bb8\u4e0d\u652f\u6301\u6808\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528 list \u6216\u8005 deque\uff08\u53cc\u7aef\u961f\u5217\uff09\u6765\u6a21\u62df\u4e00\u4e2a\u6808\uff0c\u53ea\u8981\u662f\u6807\u51c6\u7684\u6808\u64cd\u4f5c\u5373\u53ef\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u4f60\u80fd\u5426\u5b9e\u73b0\u6bcf\u4e2a\u64cd\u4f5c\u5747\u644a\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(1) \u7684\u961f\u5217\uff1f\u6362\u53e5\u8bdd\u8bf4\uff0c\u6267\u884c n \u4e2a\u64cd\u4f5c\u7684\u603b\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n) \uff0c\u5373\u4f7f\u5176\u4e2d\u4e00\u4e2a\u64cd\u4f5c\u53ef\u80fd\u82b1\u8d39\u8f83\u957f\u65f6\u95f4\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\n[\"MyQueue\", \"push\", \"push\", \"peek\", \"pop\", \"empty\"]\n[[], [1], [2], [], [], []]\n\u8f93\u51fa\uff1a\n[null, null, null, 1, 1, false]\n\n\u89e3\u91ca\uff1a\nMyQueue myQueue = new MyQueue();\nmyQueue.push(1); // queue is: [1]\nmyQueue.push(2); // queue is: [1, 2] (leftmost is front of the queue)\nmyQueue.peek(); // return 1\nmyQueue.pop(); // return 1, queue is [2]\nmyQueue.empty(); // return false\n
    \n\n
      \n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= x <= 9
    • \n\t
    • \u6700\u591a\u8c03\u7528 100 \u6b21 push\u3001pop\u3001peek \u548c empty
    • \n\t
    • \u5047\u8bbe\u6240\u6709\u64cd\u4f5c\u90fd\u662f\u6709\u6548\u7684 \uff08\u4f8b\u5982\uff0c\u4e00\u4e2a\u7a7a\u7684\u961f\u5217\u4e0d\u4f1a\u8c03\u7528 pop \u6216\u8005 peek \u64cd\u4f5c\uff09
    • \n
    \n", "tags_en": ["Stack", "Design"], "tags_cn": ["\u6808", "\u8bbe\u8ba1"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class MyQueue {\npublic:\n /** Initialize your data structure here. */\n MyQueue() {\n\n }\n \n /** Push element x to the back of queue. */\n void push(int x) {\n\n }\n \n /** Removes the element from in front of queue and returns that element. */\n int pop() {\n\n }\n \n /** Get the front element. */\n int peek() {\n\n }\n \n /** Returns whether the queue is empty. */\n bool empty() {\n\n }\n};\n\n/**\n * Your MyQueue object will be instantiated and called as such:\n * MyQueue* obj = new MyQueue();\n * obj->push(x);\n * int param_2 = obj->pop();\n * int param_3 = obj->peek();\n * bool param_4 = obj->empty();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class MyQueue {\n\n /** Initialize your data structure here. */\n public MyQueue() {\n\n }\n \n /** Push element x to the back of queue. */\n public void push(int x) {\n\n }\n \n /** Removes the element from in front of queue and returns that element. */\n public int pop() {\n\n }\n \n /** Get the front element. */\n public int peek() {\n\n }\n \n /** Returns whether the queue is empty. */\n public boolean empty() {\n\n }\n}\n\n/**\n * Your MyQueue object will be instantiated and called as such:\n * MyQueue obj = new MyQueue();\n * obj.push(x);\n * int param_2 = obj.pop();\n * int param_3 = obj.peek();\n * boolean param_4 = obj.empty();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class MyQueue(object):\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def push(self, x):\n \"\"\"\n Push element x to the back of queue.\n :type x: int\n :rtype: None\n \"\"\"\n\n\n def pop(self):\n \"\"\"\n Removes the element from in front of queue and returns that element.\n :rtype: int\n \"\"\"\n\n\n def peek(self):\n \"\"\"\n Get the front element.\n :rtype: int\n \"\"\"\n\n\n def empty(self):\n \"\"\"\n Returns whether the queue is empty.\n :rtype: bool\n \"\"\"\n\n\n\n# Your MyQueue object will be instantiated and called as such:\n# obj = MyQueue()\n# obj.push(x)\n# param_2 = obj.pop()\n# param_3 = obj.peek()\n# param_4 = obj.empty()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class MyQueue:\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def push(self, x: int) -> None:\n \"\"\"\n Push element x to the back of queue.\n \"\"\"\n\n\n def pop(self) -> int:\n \"\"\"\n Removes the element from in front of queue and returns that element.\n \"\"\"\n\n\n def peek(self) -> int:\n \"\"\"\n Get the front element.\n \"\"\"\n\n\n def empty(self) -> bool:\n \"\"\"\n Returns whether the queue is empty.\n \"\"\"\n\n\n\n# Your MyQueue object will be instantiated and called as such:\n# obj = MyQueue()\n# obj.push(x)\n# param_2 = obj.pop()\n# param_3 = obj.peek()\n# param_4 = obj.empty()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} MyQueue;\n\n/** Initialize your data structure here. */\n\nMyQueue* myQueueCreate() {\n\n}\n\n/** Push element x to the back of queue. */\nvoid myQueuePush(MyQueue* obj, int x) {\n\n}\n\n/** Removes the element from in front of queue and returns that element. */\nint myQueuePop(MyQueue* obj) {\n\n}\n\n/** Get the front element. */\nint myQueuePeek(MyQueue* obj) {\n\n}\n\n/** Returns whether the queue is empty. */\nbool myQueueEmpty(MyQueue* obj) {\n\n}\n\nvoid myQueueFree(MyQueue* obj) {\n\n}\n\n/**\n * Your MyQueue struct will be instantiated and called as such:\n * MyQueue* obj = myQueueCreate();\n * myQueuePush(obj, x);\n \n * int param_2 = myQueuePop(obj);\n \n * int param_3 = myQueuePeek(obj);\n \n * bool param_4 = myQueueEmpty(obj);\n \n * myQueueFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class MyQueue {\n\n /** Initialize your data structure here. */\n public MyQueue() {\n\n }\n \n /** Push element x to the back of queue. */\n public void Push(int x) {\n\n }\n \n /** Removes the element from in front of queue and returns that element. */\n public int Pop() {\n\n }\n \n /** Get the front element. */\n public int Peek() {\n\n }\n \n /** Returns whether the queue is empty. */\n public bool Empty() {\n\n }\n}\n\n/**\n * Your MyQueue object will be instantiated and called as such:\n * MyQueue obj = new MyQueue();\n * obj.Push(x);\n * int param_2 = obj.Pop();\n * int param_3 = obj.Peek();\n * bool param_4 = obj.Empty();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Initialize your data structure here.\n */\nvar MyQueue = function() {\n\n};\n\n/**\n * Push element x to the back of queue. \n * @param {number} x\n * @return {void}\n */\nMyQueue.prototype.push = function(x) {\n\n};\n\n/**\n * Removes the element from in front of queue and returns that element.\n * @return {number}\n */\nMyQueue.prototype.pop = function() {\n\n};\n\n/**\n * Get the front element.\n * @return {number}\n */\nMyQueue.prototype.peek = function() {\n\n};\n\n/**\n * Returns whether the queue is empty.\n * @return {boolean}\n */\nMyQueue.prototype.empty = function() {\n\n};\n\n/**\n * Your MyQueue object will be instantiated and called as such:\n * var obj = new MyQueue()\n * obj.push(x)\n * var param_2 = obj.pop()\n * var param_3 = obj.peek()\n * var param_4 = obj.empty()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class MyQueue\n\n=begin\n Initialize your data structure here.\n=end\n def initialize()\n\n end\n\n\n=begin\n Push element x to the back of queue.\n :type x: Integer\n :rtype: Void\n=end\n def push(x)\n\n end\n\n\n=begin\n Removes the element from in front of queue and returns that element.\n :rtype: Integer\n=end\n def pop()\n\n end\n\n\n=begin\n Get the front element.\n :rtype: Integer\n=end\n def peek()\n\n end\n\n\n=begin\n Returns whether the queue is empty.\n :rtype: Boolean\n=end\n def empty()\n\n end\n\n\nend\n\n# Your MyQueue object will be instantiated and called as such:\n# obj = MyQueue.new()\n# obj.push(x)\n# param_2 = obj.pop()\n# param_3 = obj.peek()\n# param_4 = obj.empty()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass MyQueue {\n\n /** Initialize your data structure here. */\n init() {\n\n }\n \n /** Push element x to the back of queue. */\n func push(_ x: Int) {\n\n }\n \n /** Removes the element from in front of queue and returns that element. */\n func pop() -> Int {\n\n }\n \n /** Get the front element. */\n func peek() -> Int {\n\n }\n \n /** Returns whether the queue is empty. */\n func empty() -> Bool {\n\n }\n}\n\n/**\n * Your MyQueue object will be instantiated and called as such:\n * let obj = MyQueue()\n * obj.push(x)\n * let ret_2: Int = obj.pop()\n * let ret_3: Int = obj.peek()\n * let ret_4: Bool = obj.empty()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type MyQueue struct {\n\n}\n\n\n/** Initialize your data structure here. */\nfunc Constructor() MyQueue {\n\n}\n\n\n/** Push element x to the back of queue. */\nfunc (this *MyQueue) Push(x int) {\n\n}\n\n\n/** Removes the element from in front of queue and returns that element. */\nfunc (this *MyQueue) Pop() int {\n\n}\n\n\n/** Get the front element. */\nfunc (this *MyQueue) Peek() int {\n\n}\n\n\n/** Returns whether the queue is empty. */\nfunc (this *MyQueue) Empty() bool {\n\n}\n\n\n/**\n * Your MyQueue object will be instantiated and called as such:\n * obj := Constructor();\n * obj.Push(x);\n * param_2 := obj.Pop();\n * param_3 := obj.Peek();\n * param_4 := obj.Empty();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class MyQueue() {\n\n /** Initialize your data structure here. */\n\n\n /** Push element x to the back of queue. */\n def push(x: Int) {\n\n }\n\n /** Removes the element from in front of queue and returns that element. */\n def pop(): Int = {\n\n }\n\n /** Get the front element. */\n def peek(): Int = {\n\n }\n\n /** Returns whether the queue is empty. */\n def empty(): Boolean = {\n\n }\n\n}\n\n/**\n * Your MyQueue object will be instantiated and called as such:\n * var obj = new MyQueue()\n * obj.push(x)\n * var param_2 = obj.pop()\n * var param_3 = obj.peek()\n * var param_4 = obj.empty()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class MyQueue() {\n\n /** Initialize your data structure here. */\n\n\n /** Push element x to the back of queue. */\n fun push(x: Int) {\n\n }\n\n /** Removes the element from in front of queue and returns that element. */\n fun pop(): Int {\n\n }\n\n /** Get the front element. */\n fun peek(): Int {\n\n }\n\n /** Returns whether the queue is empty. */\n fun empty(): Boolean {\n\n }\n\n}\n\n/**\n * Your MyQueue object will be instantiated and called as such:\n * var obj = MyQueue()\n * obj.push(x)\n * var param_2 = obj.pop()\n * var param_3 = obj.peek()\n * var param_4 = obj.empty()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct MyQueue {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl MyQueue {\n\n /** Initialize your data structure here. */\n fn new() -> Self {\n\n }\n \n /** Push element x to the back of queue. */\n fn push(&self, x: i32) {\n\n }\n \n /** Removes the element from in front of queue and returns that element. */\n fn pop(&self) -> i32 {\n\n }\n \n /** Get the front element. */\n fn peek(&self) -> i32 {\n\n }\n \n /** Returns whether the queue is empty. */\n fn empty(&self) -> bool {\n\n }\n}\n\n/**\n * Your MyQueue object will be instantiated and called as such:\n * let obj = MyQueue::new();\n * obj.push(x);\n * let ret_2: i32 = obj.pop();\n * let ret_3: i32 = obj.peek();\n * let ret_4: bool = obj.empty();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class MyQueue {\n /**\n * Initialize your data structure here.\n */\n function __construct() {\n\n }\n\n /**\n * Push element x to the back of queue.\n * @param Integer $x\n * @return NULL\n */\n function push($x) {\n\n }\n\n /**\n * Removes the element from in front of queue and returns that element.\n * @return Integer\n */\n function pop() {\n\n }\n\n /**\n * Get the front element.\n * @return Integer\n */\n function peek() {\n\n }\n\n /**\n * Returns whether the queue is empty.\n * @return Boolean\n */\n function empty() {\n\n }\n}\n\n/**\n * Your MyQueue object will be instantiated and called as such:\n * $obj = MyQueue();\n * $obj->push($x);\n * $ret_2 = $obj->pop();\n * $ret_3 = $obj->peek();\n * $ret_4 = $obj->empty();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class MyQueue {\n constructor() {\n\n }\n\n push(x: number): void {\n\n }\n\n pop(): number {\n\n }\n\n peek(): number {\n\n }\n\n empty(): boolean {\n\n }\n}\n\n/**\n * Your MyQueue object will be instantiated and called as such:\n * var obj = new MyQueue()\n * obj.push(x)\n * var param_2 = obj.pop()\n * var param_3 = obj.peek()\n * var param_4 = obj.empty()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define my-queue%\n (class object%\n (super-new)\n (init-field)\n \n ; push : exact-integer? -> void?\n (define/public (push x)\n\n )\n ; pop : -> exact-integer?\n (define/public (pop)\n\n )\n ; peek : -> exact-integer?\n (define/public (peek)\n\n )\n ; empty : -> boolean?\n (define/public (empty)\n\n )))\n\n;; Your my-queue% object will be instantiated and called as such:\n;; (define obj (new my-queue%))\n;; (send obj push x)\n;; (define param_2 (send obj pop))\n;; (define param_3 (send obj peek))\n;; (define param_4 (send obj empty))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0232](https://leetcode-cn.com/problems/implement-queue-using-stacks)", "[\u7528\u6808\u5b9e\u73b0\u961f\u5217](/solution/0200-0299/0232.Implement%20Queue%20using%20Stacks/README.md)", "`\u6808`,`\u8bbe\u8ba1`", "\u7b80\u5355", ""], "md_table_row_en": ["[0232](https://leetcode.com/problems/implement-queue-using-stacks)", "[Implement Queue using Stacks](/solution/0200-0299/0232.Implement%20Queue%20using%20Stacks/README_EN.md)", "`Stack`,`Design`", "Easy", ""]}, {"question_id": "0231", "frontend_question_id": "0231", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/power-of-two", "url_en": "https://leetcode.com/problems/power-of-two", "relative_path_cn": "/solution/0200-0299/0231.Power%20of%20Two/README.md", "relative_path_en": "/solution/0200-0299/0231.Power%20of%20Two/README_EN.md", "title_cn": "2 \u7684\u5e42", "title_en": "Power of Two", "question_title_slug": "power-of-two", "content_en": "

    Given an integer n, return true if it is a power of two. Otherwise, return false.

    \n\n

    An integer n is a power of two, if there exists an integer x such that n == 2x.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 1\nOutput: true\nExplanation: 20 = 1\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 16\nOutput: true\nExplanation: 24 = 16\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 3\nOutput: false\n
    \n\n

    Example 4:

    \n\n
    \nInput: n = 4\nOutput: true\n
    \n\n

    Example 5:

    \n\n
    \nInput: n = 5\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • -231 <= n <= 231 - 1
    • \n
    \n\n

     

    \nFollow up: Could you solve it without loops/recursion?", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n\uff0c\u8bf7\u4f60\u5224\u65ad\u8be5\u6574\u6570\u662f\u5426\u662f 2 \u7684\u5e42\u6b21\u65b9\u3002\u5982\u679c\u662f\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n

    \u5982\u679c\u5b58\u5728\u4e00\u4e2a\u6574\u6570 x \u4f7f\u5f97\u00a0n == 2x \uff0c\u5219\u8ba4\u4e3a n \u662f 2 \u7684\u5e42\u6b21\u65b9\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a20 = 1\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 16\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a24 = 16\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 3\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 4\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 5\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • -231 <= n <= 231 - 1
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u80fd\u591f\u4e0d\u4f7f\u7528\u5faa\u73af/\u9012\u5f52\u89e3\u51b3\u6b64\u95ee\u9898\u5417\uff1f

    \n", "tags_en": ["Bit Manipulation", "Math"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isPowerOfTwo(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isPowerOfTwo(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isPowerOfTwo(self, n):\n \"\"\"\n :type n: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isPowerOfTwo(self, n: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isPowerOfTwo(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsPowerOfTwo(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {boolean}\n */\nvar isPowerOfTwo = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Boolean}\ndef is_power_of_two(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isPowerOfTwo(_ n: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isPowerOfTwo(n int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isPowerOfTwo(n: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isPowerOfTwo(n: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_power_of_two(n: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Boolean\n */\n function isPowerOfTwo($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isPowerOfTwo(n: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-power-of-two n)\n (-> exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0231](https://leetcode-cn.com/problems/power-of-two)", "[2 \u7684\u5e42](/solution/0200-0299/0231.Power%20of%20Two/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0231](https://leetcode.com/problems/power-of-two)", "[Power of Two](/solution/0200-0299/0231.Power%20of%20Two/README_EN.md)", "`Bit Manipulation`,`Math`", "Easy", ""]}, {"question_id": "0230", "frontend_question_id": "0230", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/kth-smallest-element-in-a-bst", "url_en": "https://leetcode.com/problems/kth-smallest-element-in-a-bst", "relative_path_cn": "/solution/0200-0299/0230.Kth%20Smallest%20Element%20in%20a%20BST/README.md", "relative_path_en": "/solution/0200-0299/0230.Kth%20Smallest%20Element%20in%20a%20BST/README_EN.md", "title_cn": "\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u7b2cK\u5c0f\u7684\u5143\u7d20", "title_en": "Kth Smallest Element in a BST", "question_title_slug": "kth-smallest-element-in-a-bst", "content_en": "

    Given the root of a binary search tree, and an integer k, return the kth (1-indexed) smallest element in the tree.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [3,1,4,null,2], k = 1\nOutput: 1\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [5,3,6,2,4,null,null,1], k = 3\nOutput: 3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is n.
    • \n\t
    • 1 <= k <= n <= 104
    • \n\t
    • 0 <= Node.val <= 104
    • \n
    \n\n

     

    \nFollow up: If the BST is modified often (i.e., we can do insert and delete operations) and you need to find the kth smallest frequently, how would you optimize?", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6839\u8282\u70b9 root \uff0c\u548c\u4e00\u4e2a\u6574\u6570 k \uff0c\u8bf7\u4f60\u8bbe\u8ba1\u4e00\u4e2a\u7b97\u6cd5\u67e5\u627e\u5176\u4e2d\u7b2c\u00a0k\u00a0\u4e2a\u6700\u5c0f\u5143\u7d20\uff08\u4ece 1 \u5f00\u59cb\u8ba1\u6570\uff09\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [3,1,4,null,2], k = 1\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [5,3,6,2,4,null,null,1], k = 3\n\u8f93\u51fa\uff1a3\n
    \n\n

    \u00a0

    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u7684\u8282\u70b9\u6570\u4e3a n \u3002
    • \n\t
    • 1 <= k <= n <= 104
    • \n\t
    • 0 <= Node.val <= 104
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u5982\u679c\u4e8c\u53c9\u641c\u7d22\u6811\u7ecf\u5e38\u88ab\u4fee\u6539\uff08\u63d2\u5165/\u5220\u9664\u64cd\u4f5c\uff09\u5e76\u4e14\u4f60\u9700\u8981\u9891\u7e41\u5730\u67e5\u627e\u7b2c k \u5c0f\u7684\u503c\uff0c\u4f60\u5c06\u5982\u4f55\u4f18\u5316\u7b97\u6cd5\uff1f

    \n", "tags_en": ["Tree", "Binary Search"], "tags_cn": ["\u6811", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int kthSmallest(TreeNode* root, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int kthSmallest(TreeNode root, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def kthSmallest(self, root, k):\n \"\"\"\n :type root: TreeNode\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def kthSmallest(self, root: TreeNode, k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint kthSmallest(struct TreeNode* root, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int KthSmallest(TreeNode root, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number} k\n * @return {number}\n */\nvar kthSmallest = function(root, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @param {Integer} k\n# @return {Integer}\ndef kth_smallest(root, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func kthSmallest(_ root: TreeNode?, _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc kthSmallest(root *TreeNode, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def kthSmallest(root: TreeNode, k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun kthSmallest(root: TreeNode?, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn kth_smallest(root: Option>>, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param Integer $k\n * @return Integer\n */\n function kthSmallest($root, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction kthSmallest(root: TreeNode | null, k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (kth-smallest root k)\n (-> (or/c tree-node? #f) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0230](https://leetcode-cn.com/problems/kth-smallest-element-in-a-bst)", "[\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u7b2cK\u5c0f\u7684\u5143\u7d20](/solution/0200-0299/0230.Kth%20Smallest%20Element%20in%20a%20BST/README.md)", "`\u6811`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0230](https://leetcode.com/problems/kth-smallest-element-in-a-bst)", "[Kth Smallest Element in a BST](/solution/0200-0299/0230.Kth%20Smallest%20Element%20in%20a%20BST/README_EN.md)", "`Tree`,`Binary Search`", "Medium", ""]}, {"question_id": "0229", "frontend_question_id": "0229", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/majority-element-ii", "url_en": "https://leetcode.com/problems/majority-element-ii", "relative_path_cn": "/solution/0200-0299/0229.Majority%20Element%20II/README.md", "relative_path_en": "/solution/0200-0299/0229.Majority%20Element%20II/README_EN.md", "title_cn": "\u6c42\u4f17\u6570 II", "title_en": "Majority Element II", "question_title_slug": "majority-element-ii", "content_en": "

    Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times.

    \n\n

    Follow-up: Could you solve the problem in linear time and in O(1) space?

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [3,2,3]\nOutput: [3]\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1]\nOutput: [1]\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [1,2]\nOutput: [1,2]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 5 * 104
    • \n\t
    • -109 <= nums[i] <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5927\u5c0f\u4e3a\u00a0n\u00a0\u7684\u6574\u6570\u6570\u7ec4\uff0c\u627e\u51fa\u5176\u4e2d\u6240\u6709\u51fa\u73b0\u8d85\u8fc7\u00a0\u230a n/3 \u230b\u00a0\u6b21\u7684\u5143\u7d20\u3002

    \n\n

    \u8fdb\u9636\uff1a\u5c1d\u8bd5\u8bbe\u8ba1\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\u3001\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a O(1)\u7684\u7b97\u6cd5\u89e3\u51b3\u6b64\u95ee\u9898\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\u00a01\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[3,2,3]\n\u8f93\u51fa\uff1a[3]
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1]\n\u8f93\u51fa\uff1a[1]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[1,1,1,3,3,2,2,2]\n\u8f93\u51fa\uff1a[1,2]
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 5 * 104
    • \n\t
    • -109 <= nums[i] <= 109
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector majorityElement(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List majorityElement(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def majorityElement(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def majorityElement(self, nums: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* majorityElement(int* nums, int numsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList MajorityElement(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar majorityElement = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer[]}\ndef majority_element(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func majorityElement(_ nums: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func majorityElement(nums []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def majorityElement(nums: Array[Int]): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun majorityElement(nums: IntArray): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn majority_element(nums: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer[]\n */\n function majorityElement($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function majorityElement(nums: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (majority-element nums)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0229](https://leetcode-cn.com/problems/majority-element-ii)", "[\u6c42\u4f17\u6570 II](/solution/0200-0299/0229.Majority%20Element%20II/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0229](https://leetcode.com/problems/majority-element-ii)", "[Majority Element II](/solution/0200-0299/0229.Majority%20Element%20II/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0228", "frontend_question_id": "0228", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/summary-ranges", "url_en": "https://leetcode.com/problems/summary-ranges", "relative_path_cn": "/solution/0200-0299/0228.Summary%20Ranges/README.md", "relative_path_en": "/solution/0200-0299/0228.Summary%20Ranges/README_EN.md", "title_cn": "\u6c47\u603b\u533a\u95f4", "title_en": "Summary Ranges", "question_title_slug": "summary-ranges", "content_en": "

    You are given a sorted unique integer array nums.

    \n\n

    Return the smallest sorted list of ranges that cover all the numbers in the array exactly. That is, each element of nums is covered by exactly one of the ranges, and there is no integer x such that x is in one of the ranges but not in nums.

    \n\n

    Each range [a,b] in the list should be output as:

    \n\n
      \n\t
    • "a->b" if a != b
    • \n\t
    • "a" if a == b
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [0,1,2,4,5,7]\nOutput: ["0->2","4->5","7"]\nExplanation: The ranges are:\n[0,2] --> "0->2"\n[4,5] --> "4->5"\n[7,7] --> "7"\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [0,2,3,4,6,8,9]\nOutput: ["0","2->4","6","8->9"]\nExplanation: The ranges are:\n[0,0] --> "0"\n[2,4] --> "2->4"\n[6,6] --> "6"\n[8,9] --> "8->9"\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = []\nOutput: []\n
    \n\n

    Example 4:

    \n\n
    \nInput: nums = [-1]\nOutput: ["-1"]\n
    \n\n

    Example 5:

    \n\n
    \nInput: nums = [0]\nOutput: ["0"]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= nums.length <= 20
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n\t
    • All the values of nums are unique.
    • \n\t
    • nums is sorted in ascending order.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u65e0\u91cd\u590d\u5143\u7d20\u7684\u6709\u5e8f\u6574\u6570\u6570\u7ec4 nums \u3002

    \n\n

    \u8fd4\u56de \u6070\u597d\u8986\u76d6\u6570\u7ec4\u4e2d\u6240\u6709\u6570\u5b57 \u7684 \u6700\u5c0f\u6709\u5e8f \u533a\u95f4\u8303\u56f4\u5217\u8868\u3002\u4e5f\u5c31\u662f\u8bf4\uff0cnums \u7684\u6bcf\u4e2a\u5143\u7d20\u90fd\u6070\u597d\u88ab\u67d0\u4e2a\u533a\u95f4\u8303\u56f4\u6240\u8986\u76d6\uff0c\u5e76\u4e14\u4e0d\u5b58\u5728\u5c5e\u4e8e\u67d0\u4e2a\u8303\u56f4\u4f46\u4e0d\u5c5e\u4e8e nums \u7684\u6570\u5b57 x \u3002

    \n\n

    \u5217\u8868\u4e2d\u7684\u6bcf\u4e2a\u533a\u95f4\u8303\u56f4 [a,b] \u5e94\u8be5\u6309\u5982\u4e0b\u683c\u5f0f\u8f93\u51fa\uff1a

    \n\n
      \n\t
    • \"a->b\" \uff0c\u5982\u679c a != b
    • \n\t
    • \"a\" \uff0c\u5982\u679c a == b
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [0,1,2,4,5,7]\n\u8f93\u51fa\uff1a[\"0->2\",\"4->5\",\"7\"]\n\u89e3\u91ca\uff1a\u533a\u95f4\u8303\u56f4\u662f\uff1a\n[0,2] --> \"0->2\"\n[4,5] --> \"4->5\"\n[7,7] --> \"7\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [0,2,3,4,6,8,9]\n\u8f93\u51fa\uff1a[\"0\",\"2->4\",\"6\",\"8->9\"]\n\u89e3\u91ca\uff1a\u533a\u95f4\u8303\u56f4\u662f\uff1a\n[0,0] --> \"0\"\n[2,4] --> \"2->4\"\n[6,6] --> \"6\"\n[8,9] --> \"8->9\"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = []\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [-1]\n\u8f93\u51fa\uff1a[\"-1\"]\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [0]\n\u8f93\u51fa\uff1a[\"0\"]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= nums.length <= 20
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n\t
    • nums \u4e2d\u7684\u6240\u6709\u503c\u90fd \u4e92\u4e0d\u76f8\u540c
    • \n\t
    • nums \u6309\u5347\u5e8f\u6392\u5217
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector summaryRanges(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List summaryRanges(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def summaryRanges(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def summaryRanges(self, nums: List[int]) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** summaryRanges(int* nums, int numsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList SummaryRanges(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {string[]}\n */\nvar summaryRanges = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {String[]}\ndef summary_ranges(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func summaryRanges(_ nums: [Int]) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func summaryRanges(nums []int) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def summaryRanges(nums: Array[Int]): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun summaryRanges(nums: IntArray): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn summary_ranges(nums: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return String[]\n */\n function summaryRanges($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function summaryRanges(nums: number[]): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (summary-ranges nums)\n (-> (listof exact-integer?) (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0228](https://leetcode-cn.com/problems/summary-ranges)", "[\u6c47\u603b\u533a\u95f4](/solution/0200-0299/0228.Summary%20Ranges/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0228](https://leetcode.com/problems/summary-ranges)", "[Summary Ranges](/solution/0200-0299/0228.Summary%20Ranges/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0227", "frontend_question_id": "0227", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/basic-calculator-ii", "url_en": "https://leetcode.com/problems/basic-calculator-ii", "relative_path_cn": "/solution/0200-0299/0227.Basic%20Calculator%20II/README.md", "relative_path_en": "/solution/0200-0299/0227.Basic%20Calculator%20II/README_EN.md", "title_cn": "\u57fa\u672c\u8ba1\u7b97\u5668 II", "title_en": "Basic Calculator II", "question_title_slug": "basic-calculator-ii", "content_en": "

    Given a string s which represents an expression, evaluate this expression and return its value

    \n\n

    The integer division should truncate toward zero.

    \n\n

    Note: You are not allowed to use any built-in function which evaluates strings as mathematical expressions, such as eval().

    \n\n

     

    \n

    Example 1:

    \n
    Input: s = \"3+2*2\"\nOutput: 7\n

    Example 2:

    \n
    Input: s = \" 3/2 \"\nOutput: 1\n

    Example 3:

    \n
    Input: s = \" 3+5 / 2 \"\nOutput: 5\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 3 * 105
    • \n\t
    • s consists of integers and operators ('+', '-', '*', '/') separated by some number of spaces.
    • \n\t
    • s represents a valid expression.
    • \n\t
    • All the integers in the expression are non-negative integers in the range [0, 231 - 1].
    • \n\t
    • The answer is guaranteed to fit in a 32-bit integer.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32\u8868\u8fbe\u5f0f s \uff0c\u8bf7\u4f60\u5b9e\u73b0\u4e00\u4e2a\u57fa\u672c\u8ba1\u7b97\u5668\u6765\u8ba1\u7b97\u5e76\u8fd4\u56de\u5b83\u7684\u503c\u3002

    \n\n

    \u6574\u6570\u9664\u6cd5\u4ec5\u4fdd\u7559\u6574\u6570\u90e8\u5206\u3002

    \n\n
    \n
    \n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"3+2*2\"\n\u8f93\u51fa\uff1a7\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \" 3/2 \"\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \" 3+5 / 2 \"\n\u8f93\u51fa\uff1a5\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 3 * 105
    • \n\t
    • s \u7531\u6574\u6570\u548c\u7b97\u7b26 ('+', '-', '*', '/') \u7ec4\u6210\uff0c\u4e2d\u95f4\u7531\u4e00\u4e9b\u7a7a\u683c\u9694\u5f00
    • \n\t
    • s \u8868\u793a\u4e00\u4e2a \u6709\u6548\u8868\u8fbe\u5f0f
    • \n\t
    • \u8868\u8fbe\u5f0f\u4e2d\u7684\u6240\u6709\u6574\u6570\u90fd\u662f\u975e\u8d1f\u6574\u6570\uff0c\u4e14\u5728\u8303\u56f4 [0, 231 - 1] \u5185
    • \n\t
    • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u7b54\u6848\u662f\u4e00\u4e2a 32-bit \u6574\u6570
    • \n
    \n
    \n
    \n", "tags_en": ["Stack", "String"], "tags_cn": ["\u6808", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int calculate(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int calculate(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def calculate(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def calculate(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint calculate(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int Calculate(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar calculate = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef calculate(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func calculate(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func calculate(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def calculate(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun calculate(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn calculate(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function calculate($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function calculate(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (calculate s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0227](https://leetcode-cn.com/problems/basic-calculator-ii)", "[\u57fa\u672c\u8ba1\u7b97\u5668 II](/solution/0200-0299/0227.Basic%20Calculator%20II/README.md)", "`\u6808`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0227](https://leetcode.com/problems/basic-calculator-ii)", "[Basic Calculator II](/solution/0200-0299/0227.Basic%20Calculator%20II/README_EN.md)", "`Stack`,`String`", "Medium", ""]}, {"question_id": "0226", "frontend_question_id": "0226", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/invert-binary-tree", "url_en": "https://leetcode.com/problems/invert-binary-tree", "relative_path_cn": "/solution/0200-0299/0226.Invert%20Binary%20Tree/README.md", "relative_path_en": "/solution/0200-0299/0226.Invert%20Binary%20Tree/README_EN.md", "title_cn": "\u7ffb\u8f6c\u4e8c\u53c9\u6811", "title_en": "Invert Binary Tree", "question_title_slug": "invert-binary-tree", "content_en": "

    Given the root of a binary tree, invert the tree, and return its root.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [4,2,7,1,3,6,9]\nOutput: [4,7,2,9,6,3,1]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [2,1,3]\nOutput: [2,3,1]\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = []\nOutput: []\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [0, 100].
    • \n\t
    • -100 <= Node.val <= 100
    • \n
    \n", "content_cn": "

    \u7ffb\u8f6c\u4e00\u68f5\u4e8c\u53c9\u6811\u3002

    \n\n

    \u793a\u4f8b\uff1a

    \n\n

    \u8f93\u5165\uff1a

    \n\n
         4\n   /   \\\n  2     7\n / \\   / \\\n1   3 6   9
    \n\n

    \u8f93\u51fa\uff1a

    \n\n
         4\n   /   \\\n  7     2\n / \\   / \\\n9   6 3   1
    \n\n

    \u5907\u6ce8:
    \n\u8fd9\u4e2a\u95ee\u9898\u662f\u53d7\u5230 Max Howell \u7684 \u539f\u95ee\u9898 \u542f\u53d1\u7684 \uff1a

    \n\n
    \u8c37\u6b4c\uff1a\u6211\u4eec90\uff05\u7684\u5de5\u7a0b\u5e08\u4f7f\u7528\u60a8\u7f16\u5199\u7684\u8f6f\u4ef6(Homebrew)\uff0c\u4f46\u662f\u60a8\u5374\u65e0\u6cd5\u5728\u9762\u8bd5\u65f6\u5728\u767d\u677f\u4e0a\u5199\u51fa\u7ffb\u8f6c\u4e8c\u53c9\u6811\u8fd9\u9053\u9898\uff0c\u8fd9\u592a\u7cdf\u7cd5\u4e86\u3002
    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* invertTree(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode invertTree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def invertTree(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: TreeNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def invertTree(self, root: TreeNode) -> TreeNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* invertTree(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode InvertTree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {TreeNode}\n */\nvar invertTree = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {TreeNode}\ndef invert_tree(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func invertTree(_ root: TreeNode?) -> TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc invertTree(root *TreeNode) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def invertTree(root: TreeNode): TreeNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun invertTree(root: TreeNode?): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn invert_tree(root: Option>>) -> Option>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return TreeNode\n */\n function invertTree($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction invertTree(root: TreeNode | null): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (invert-tree root)\n (-> (or/c tree-node? #f) (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0226](https://leetcode-cn.com/problems/invert-binary-tree)", "[\u7ffb\u8f6c\u4e8c\u53c9\u6811](/solution/0200-0299/0226.Invert%20Binary%20Tree/README.md)", "`\u6811`", "\u7b80\u5355", ""], "md_table_row_en": ["[0226](https://leetcode.com/problems/invert-binary-tree)", "[Invert Binary Tree](/solution/0200-0299/0226.Invert%20Binary%20Tree/README_EN.md)", "`Tree`", "Easy", ""]}, {"question_id": "0225", "frontend_question_id": "0225", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/implement-stack-using-queues", "url_en": "https://leetcode.com/problems/implement-stack-using-queues", "relative_path_cn": "/solution/0200-0299/0225.Implement%20Stack%20using%20Queues/README.md", "relative_path_en": "/solution/0200-0299/0225.Implement%20Stack%20using%20Queues/README_EN.md", "title_cn": "\u7528\u961f\u5217\u5b9e\u73b0\u6808", "title_en": "Implement Stack using Queues", "question_title_slug": "implement-stack-using-queues", "content_en": "

    Implement a last in first out (LIFO) stack using only two queues. The implemented stack should support all the functions of a normal queue (push, top, pop, and empty).

    \n\n

    Implement the MyStack class:

    \n\n
      \n\t
    • void push(int x) Pushes element x to the top of the stack.
    • \n\t
    • int pop() Removes the element on the top of the stack and returns it.
    • \n\t
    • int top() Returns the element on the top of the stack.
    • \n\t
    • boolean empty() Returns true if the stack is empty, false otherwise.
    • \n
    \n\n

    Notes:

    \n\n
      \n\t
    • You must use only standard operations of a queue, which means only push to back, peek/pop from front, size, and is empty operations are valid.
    • \n\t
    • Depending on your language, the queue may not be supported natively. You may simulate a queue using a list or deque (double-ended queue), as long as you use only a queue's standard operations.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["MyStack", "push", "push", "top", "pop", "empty"]\n[[], [1], [2], [], [], []]\nOutput\n[null, null, null, 2, 2, false]\n\nExplanation\nMyStack myStack = new MyStack();\nmyStack.push(1);\nmyStack.push(2);\nmyStack.top(); // return 2\nmyStack.pop(); // return 2\nmyStack.empty(); // return False\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= x <= 9
    • \n\t
    • At most 100 calls will be made to push, pop, top, and empty.
    • \n\t
    • All the calls to pop and top are valid.
    • \n
    \n\n

     

    \n

    Follow-up: Can you implement the stack such that each operation is amortized O(1) time complexity? In other words, performing n operations will take overall O(n) time even if one of those operations may take longer. You can use more than two queues.

    \n", "content_cn": "

    \u8bf7\u4f60\u4ec5\u4f7f\u7528\u4e24\u4e2a\u961f\u5217\u5b9e\u73b0\u4e00\u4e2a\u540e\u5165\u5148\u51fa\uff08LIFO\uff09\u7684\u6808\uff0c\u5e76\u652f\u6301\u666e\u901a\u961f\u5217\u7684\u5168\u90e8\u56db\u79cd\u64cd\u4f5c\uff08push\u3001top\u3001pop \u548c empty\uff09\u3002

    \n\n

    \u5b9e\u73b0 MyStack \u7c7b\uff1a

    \n\n
      \n\t
    • void push(int x) \u5c06\u5143\u7d20 x \u538b\u5165\u6808\u9876\u3002
    • \n\t
    • int pop() \u79fb\u9664\u5e76\u8fd4\u56de\u6808\u9876\u5143\u7d20\u3002
    • \n\t
    • int top() \u8fd4\u56de\u6808\u9876\u5143\u7d20\u3002
    • \n\t
    • boolean empty() \u5982\u679c\u6808\u662f\u7a7a\u7684\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    • \u4f60\u53ea\u80fd\u4f7f\u7528\u961f\u5217\u7684\u57fa\u672c\u64cd\u4f5c \u2014\u2014 \u4e5f\u5c31\u662f\u00a0push to back\u3001peek/pop from front\u3001size \u548c\u00a0is empty\u00a0\u8fd9\u4e9b\u64cd\u4f5c\u3002
    • \n\t
    • \u4f60\u6240\u4f7f\u7528\u7684\u8bed\u8a00\u4e5f\u8bb8\u4e0d\u652f\u6301\u961f\u5217\u3002\u00a0\u4f60\u53ef\u4ee5\u4f7f\u7528 list \uff08\u5217\u8868\uff09\u6216\u8005 deque\uff08\u53cc\u7aef\u961f\u5217\uff09\u6765\u6a21\u62df\u4e00\u4e2a\u961f\u5217\u00a0, \u53ea\u8981\u662f\u6807\u51c6\u7684\u961f\u5217\u64cd\u4f5c\u5373\u53ef\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\n[\"MyStack\", \"push\", \"push\", \"top\", \"pop\", \"empty\"]\n[[], [1], [2], [], [], []]\n\u8f93\u51fa\uff1a\n[null, null, null, 2, 2, false]\n\n\u89e3\u91ca\uff1a\nMyStack myStack = new MyStack();\nmyStack.push(1);\nmyStack.push(2);\nmyStack.top(); // \u8fd4\u56de 2\nmyStack.pop(); // \u8fd4\u56de 2\nmyStack.empty(); // \u8fd4\u56de False\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= x <= 9
    • \n\t
    • \u6700\u591a\u8c03\u7528100 \u6b21 push\u3001pop\u3001top \u548c empty
    • \n\t
    • \u6bcf\u6b21\u8c03\u7528 pop \u548c top \u90fd\u4fdd\u8bc1\u6808\u4e0d\u4e3a\u7a7a
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u80fd\u5426\u5b9e\u73b0\u6bcf\u79cd\u64cd\u4f5c\u7684\u5747\u644a\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(1) \u7684\u6808\uff1f\u6362\u53e5\u8bdd\u8bf4\uff0c\u6267\u884c n \u4e2a\u64cd\u4f5c\u7684\u603b\u65f6\u95f4\u590d\u6742\u5ea6 O(n) \uff0c\u5c3d\u7ba1\u5176\u4e2d\u67d0\u4e2a\u64cd\u4f5c\u53ef\u80fd\u9700\u8981\u6bd4\u5176\u4ed6\u64cd\u4f5c\u66f4\u957f\u7684\u65f6\u95f4\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u4e24\u4e2a\u4ee5\u4e0a\u7684\u961f\u5217\u3002

    \n", "tags_en": ["Stack", "Design"], "tags_cn": ["\u6808", "\u8bbe\u8ba1"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class MyStack {\npublic:\n /** Initialize your data structure here. */\n MyStack() {\n\n }\n \n /** Push element x onto stack. */\n void push(int x) {\n\n }\n \n /** Removes the element on top of the stack and returns that element. */\n int pop() {\n\n }\n \n /** Get the top element. */\n int top() {\n\n }\n \n /** Returns whether the stack is empty. */\n bool empty() {\n\n }\n};\n\n/**\n * Your MyStack object will be instantiated and called as such:\n * MyStack* obj = new MyStack();\n * obj->push(x);\n * int param_2 = obj->pop();\n * int param_3 = obj->top();\n * bool param_4 = obj->empty();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class MyStack {\n\n /** Initialize your data structure here. */\n public MyStack() {\n\n }\n \n /** Push element x onto stack. */\n public void push(int x) {\n\n }\n \n /** Removes the element on top of the stack and returns that element. */\n public int pop() {\n\n }\n \n /** Get the top element. */\n public int top() {\n\n }\n \n /** Returns whether the stack is empty. */\n public boolean empty() {\n\n }\n}\n\n/**\n * Your MyStack object will be instantiated and called as such:\n * MyStack obj = new MyStack();\n * obj.push(x);\n * int param_2 = obj.pop();\n * int param_3 = obj.top();\n * boolean param_4 = obj.empty();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class MyStack(object):\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def push(self, x):\n \"\"\"\n Push element x onto stack.\n :type x: int\n :rtype: None\n \"\"\"\n\n\n def pop(self):\n \"\"\"\n Removes the element on top of the stack and returns that element.\n :rtype: int\n \"\"\"\n\n\n def top(self):\n \"\"\"\n Get the top element.\n :rtype: int\n \"\"\"\n\n\n def empty(self):\n \"\"\"\n Returns whether the stack is empty.\n :rtype: bool\n \"\"\"\n\n\n\n# Your MyStack object will be instantiated and called as such:\n# obj = MyStack()\n# obj.push(x)\n# param_2 = obj.pop()\n# param_3 = obj.top()\n# param_4 = obj.empty()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class MyStack:\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def push(self, x: int) -> None:\n \"\"\"\n Push element x onto stack.\n \"\"\"\n\n\n def pop(self) -> int:\n \"\"\"\n Removes the element on top of the stack and returns that element.\n \"\"\"\n\n\n def top(self) -> int:\n \"\"\"\n Get the top element.\n \"\"\"\n\n\n def empty(self) -> bool:\n \"\"\"\n Returns whether the stack is empty.\n \"\"\"\n\n\n\n# Your MyStack object will be instantiated and called as such:\n# obj = MyStack()\n# obj.push(x)\n# param_2 = obj.pop()\n# param_3 = obj.top()\n# param_4 = obj.empty()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} MyStack;\n\n/** Initialize your data structure here. */\n\nMyStack* myStackCreate() {\n\n}\n\n/** Push element x onto stack. */\nvoid myStackPush(MyStack* obj, int x) {\n\n}\n\n/** Removes the element on top of the stack and returns that element. */\nint myStackPop(MyStack* obj) {\n\n}\n\n/** Get the top element. */\nint myStackTop(MyStack* obj) {\n\n}\n\n/** Returns whether the stack is empty. */\nbool myStackEmpty(MyStack* obj) {\n\n}\n\nvoid myStackFree(MyStack* obj) {\n\n}\n\n/**\n * Your MyStack struct will be instantiated and called as such:\n * MyStack* obj = myStackCreate();\n * myStackPush(obj, x);\n \n * int param_2 = myStackPop(obj);\n \n * int param_3 = myStackTop(obj);\n \n * bool param_4 = myStackEmpty(obj);\n \n * myStackFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class MyStack {\n\n /** Initialize your data structure here. */\n public MyStack() {\n\n }\n \n /** Push element x onto stack. */\n public void Push(int x) {\n\n }\n \n /** Removes the element on top of the stack and returns that element. */\n public int Pop() {\n\n }\n \n /** Get the top element. */\n public int Top() {\n\n }\n \n /** Returns whether the stack is empty. */\n public bool Empty() {\n\n }\n}\n\n/**\n * Your MyStack object will be instantiated and called as such:\n * MyStack obj = new MyStack();\n * obj.Push(x);\n * int param_2 = obj.Pop();\n * int param_3 = obj.Top();\n * bool param_4 = obj.Empty();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Initialize your data structure here.\n */\nvar MyStack = function() {\n\n};\n\n/**\n * Push element x onto stack. \n * @param {number} x\n * @return {void}\n */\nMyStack.prototype.push = function(x) {\n\n};\n\n/**\n * Removes the element on top of the stack and returns that element.\n * @return {number}\n */\nMyStack.prototype.pop = function() {\n\n};\n\n/**\n * Get the top element.\n * @return {number}\n */\nMyStack.prototype.top = function() {\n\n};\n\n/**\n * Returns whether the stack is empty.\n * @return {boolean}\n */\nMyStack.prototype.empty = function() {\n\n};\n\n/**\n * Your MyStack object will be instantiated and called as such:\n * var obj = new MyStack()\n * obj.push(x)\n * var param_2 = obj.pop()\n * var param_3 = obj.top()\n * var param_4 = obj.empty()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class MyStack\n\n=begin\n Initialize your data structure here.\n=end\n def initialize()\n\n end\n\n\n=begin\n Push element x onto stack.\n :type x: Integer\n :rtype: Void\n=end\n def push(x)\n\n end\n\n\n=begin\n Removes the element on top of the stack and returns that element.\n :rtype: Integer\n=end\n def pop()\n\n end\n\n\n=begin\n Get the top element.\n :rtype: Integer\n=end\n def top()\n\n end\n\n\n=begin\n Returns whether the stack is empty.\n :rtype: Boolean\n=end\n def empty()\n\n end\n\n\nend\n\n# Your MyStack object will be instantiated and called as such:\n# obj = MyStack.new()\n# obj.push(x)\n# param_2 = obj.pop()\n# param_3 = obj.top()\n# param_4 = obj.empty()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass MyStack {\n\n /** Initialize your data structure here. */\n init() {\n\n }\n \n /** Push element x onto stack. */\n func push(_ x: Int) {\n\n }\n \n /** Removes the element on top of the stack and returns that element. */\n func pop() -> Int {\n\n }\n \n /** Get the top element. */\n func top() -> Int {\n\n }\n \n /** Returns whether the stack is empty. */\n func empty() -> Bool {\n\n }\n}\n\n/**\n * Your MyStack object will be instantiated and called as such:\n * let obj = MyStack()\n * obj.push(x)\n * let ret_2: Int = obj.pop()\n * let ret_3: Int = obj.top()\n * let ret_4: Bool = obj.empty()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type MyStack struct {\n\n}\n\n\n/** Initialize your data structure here. */\nfunc Constructor() MyStack {\n\n}\n\n\n/** Push element x onto stack. */\nfunc (this *MyStack) Push(x int) {\n\n}\n\n\n/** Removes the element on top of the stack and returns that element. */\nfunc (this *MyStack) Pop() int {\n\n}\n\n\n/** Get the top element. */\nfunc (this *MyStack) Top() int {\n\n}\n\n\n/** Returns whether the stack is empty. */\nfunc (this *MyStack) Empty() bool {\n\n}\n\n\n/**\n * Your MyStack object will be instantiated and called as such:\n * obj := Constructor();\n * obj.Push(x);\n * param_2 := obj.Pop();\n * param_3 := obj.Top();\n * param_4 := obj.Empty();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class MyStack() {\n\n /** Initialize your data structure here. */\n\n\n /** Push element x onto stack. */\n def push(x: Int) {\n\n }\n\n /** Removes the element on top of the stack and returns that element. */\n def pop(): Int = {\n\n }\n\n /** Get the top element. */\n def top(): Int = {\n\n }\n\n /** Returns whether the stack is empty. */\n def empty(): Boolean = {\n\n }\n\n}\n\n/**\n * Your MyStack object will be instantiated and called as such:\n * var obj = new MyStack()\n * obj.push(x)\n * var param_2 = obj.pop()\n * var param_3 = obj.top()\n * var param_4 = obj.empty()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class MyStack() {\n\n /** Initialize your data structure here. */\n\n\n /** Push element x onto stack. */\n fun push(x: Int) {\n\n }\n\n /** Removes the element on top of the stack and returns that element. */\n fun pop(): Int {\n\n }\n\n /** Get the top element. */\n fun top(): Int {\n\n }\n\n /** Returns whether the stack is empty. */\n fun empty(): Boolean {\n\n }\n\n}\n\n/**\n * Your MyStack object will be instantiated and called as such:\n * var obj = MyStack()\n * obj.push(x)\n * var param_2 = obj.pop()\n * var param_3 = obj.top()\n * var param_4 = obj.empty()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct MyStack {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl MyStack {\n\n /** Initialize your data structure here. */\n fn new() -> Self {\n\n }\n \n /** Push element x onto stack. */\n fn push(&self, x: i32) {\n\n }\n \n /** Removes the element on top of the stack and returns that element. */\n fn pop(&self) -> i32 {\n\n }\n \n /** Get the top element. */\n fn top(&self) -> i32 {\n\n }\n \n /** Returns whether the stack is empty. */\n fn empty(&self) -> bool {\n\n }\n}\n\n/**\n * Your MyStack object will be instantiated and called as such:\n * let obj = MyStack::new();\n * obj.push(x);\n * let ret_2: i32 = obj.pop();\n * let ret_3: i32 = obj.top();\n * let ret_4: bool = obj.empty();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class MyStack {\n /**\n * Initialize your data structure here.\n */\n function __construct() {\n\n }\n\n /**\n * Push element x onto stack.\n * @param Integer $x\n * @return NULL\n */\n function push($x) {\n\n }\n\n /**\n * Removes the element on top of the stack and returns that element.\n * @return Integer\n */\n function pop() {\n\n }\n\n /**\n * Get the top element.\n * @return Integer\n */\n function top() {\n\n }\n\n /**\n * Returns whether the stack is empty.\n * @return Boolean\n */\n function empty() {\n\n }\n}\n\n/**\n * Your MyStack object will be instantiated and called as such:\n * $obj = MyStack();\n * $obj->push($x);\n * $ret_2 = $obj->pop();\n * $ret_3 = $obj->top();\n * $ret_4 = $obj->empty();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class MyStack {\n constructor() {\n\n }\n\n push(x: number): void {\n\n }\n\n pop(): number {\n\n }\n\n top(): number {\n\n }\n\n empty(): boolean {\n\n }\n}\n\n/**\n * Your MyStack object will be instantiated and called as such:\n * var obj = new MyStack()\n * obj.push(x)\n * var param_2 = obj.pop()\n * var param_3 = obj.top()\n * var param_4 = obj.empty()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define my-stack%\n (class object%\n (super-new)\n (init-field)\n \n ; push : exact-integer? -> void?\n (define/public (push x)\n\n )\n ; pop : -> exact-integer?\n (define/public (pop)\n\n )\n ; top : -> exact-integer?\n (define/public (top)\n\n )\n ; empty : -> boolean?\n (define/public (empty)\n\n )))\n\n;; Your my-stack% object will be instantiated and called as such:\n;; (define obj (new my-stack%))\n;; (send obj push x)\n;; (define param_2 (send obj pop))\n;; (define param_3 (send obj top))\n;; (define param_4 (send obj empty))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0225](https://leetcode-cn.com/problems/implement-stack-using-queues)", "[\u7528\u961f\u5217\u5b9e\u73b0\u6808](/solution/0200-0299/0225.Implement%20Stack%20using%20Queues/README.md)", "`\u6808`,`\u8bbe\u8ba1`", "\u7b80\u5355", ""], "md_table_row_en": ["[0225](https://leetcode.com/problems/implement-stack-using-queues)", "[Implement Stack using Queues](/solution/0200-0299/0225.Implement%20Stack%20using%20Queues/README_EN.md)", "`Stack`,`Design`", "Easy", ""]}, {"question_id": "0224", "frontend_question_id": "0224", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/basic-calculator", "url_en": "https://leetcode.com/problems/basic-calculator", "relative_path_cn": "/solution/0200-0299/0224.Basic%20Calculator/README.md", "relative_path_en": "/solution/0200-0299/0224.Basic%20Calculator/README_EN.md", "title_cn": "\u57fa\u672c\u8ba1\u7b97\u5668", "title_en": "Basic Calculator", "question_title_slug": "basic-calculator", "content_en": "

    Given a string s representing a valid expression, implement a basic calculator to evaluate it, and return the result of the evaluation.

    \n\n

    Note: You are not allowed to use any built-in function which evaluates strings as mathematical expressions, such as eval().

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "1 + 1"\nOutput: 2\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = " 2-1 + 2 "\nOutput: 3\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "(1+(4+5+2)-3)+(6+8)"\nOutput: 23\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "+48 + -48"\nOutput: 0\nExplanation: Numbers can have multiple digits and start with +/-.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 3 * 105
    • \n\t
    • s consists of digits, '+', '-', '(', ')', and ' '.
    • \n\t
    • s represents a valid expression.
    • \n\t
    • Every number and running calculation will fit in a signed 32-bit integer.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32\u8868\u8fbe\u5f0f s \uff0c\u8bf7\u4f60\u5b9e\u73b0\u4e00\u4e2a\u57fa\u672c\u8ba1\u7b97\u5668\u6765\u8ba1\u7b97\u5e76\u8fd4\u56de\u5b83\u7684\u503c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"1 + 1\"\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \" 2-1 + 2 \"\n\u8f93\u51fa\uff1a3\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"(1+(4+5+2)-3)+(6+8)\"\n\u8f93\u51fa\uff1a23\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 3\u00a0* 105
    • \n\t
    • s \u7531\u6570\u5b57\u3001'+'\u3001'-'\u3001'('\u3001')'\u3001\u548c ' ' \u7ec4\u6210
    • \n\t
    • s \u8868\u793a\u4e00\u4e2a\u6709\u6548\u7684\u8868\u8fbe\u5f0f
    • \n
    \n", "tags_en": ["Stack", "Math"], "tags_cn": ["\u6808", "\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int calculate(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int calculate(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def calculate(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def calculate(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint calculate(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int Calculate(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar calculate = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef calculate(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func calculate(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func calculate(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def calculate(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun calculate(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn calculate(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function calculate($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function calculate(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (calculate s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0224](https://leetcode-cn.com/problems/basic-calculator)", "[\u57fa\u672c\u8ba1\u7b97\u5668](/solution/0200-0299/0224.Basic%20Calculator/README.md)", "`\u6808`,`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[0224](https://leetcode.com/problems/basic-calculator)", "[Basic Calculator](/solution/0200-0299/0224.Basic%20Calculator/README_EN.md)", "`Stack`,`Math`", "Hard", ""]}, {"question_id": "0223", "frontend_question_id": "0223", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/rectangle-area", "url_en": "https://leetcode.com/problems/rectangle-area", "relative_path_cn": "/solution/0200-0299/0223.Rectangle%20Area/README.md", "relative_path_en": "/solution/0200-0299/0223.Rectangle%20Area/README_EN.md", "title_cn": "\u77e9\u5f62\u9762\u79ef", "title_en": "Rectangle Area", "question_title_slug": "rectangle-area", "content_en": "

    Given the coordinates of two rectilinear rectangles in a 2D plane, return the total area covered by the two rectangles.

    \n\n

    The first rectangle is defined by its bottom-left corner (ax1, ay1) and its top-right corner (ax2, ay2).

    \n\n

    The second rectangle is defined by its bottom-left corner (bx1, by1) and its top-right corner (bx2, by2).

    \n\n

     

    \n

    Example 1:

    \n\"Rectangle\n
    \nInput: ax1 = -3, ay1 = 0, ax2 = 3, ay2 = 4, bx1 = 0, by1 = -1, bx2 = 9, by2 = 2\nOutput: 45\n
    \n\n

    Example 2:

    \n\n
    \nInput: ax1 = -2, ay1 = -2, ax2 = 2, ay2 = 2, bx1 = -2, by1 = -2, bx2 = 2, by2 = 2\nOutput: 16\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • -104 <= ax1, ay1, ax2, ay2, bx1, by1, bx2, by2 <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60 \u4e8c\u7ef4 \u5e73\u9762\u4e0a\u4e24\u4e2a \u7531\u76f4\u7ebf\u6784\u6210\u7684 \u77e9\u5f62\uff0c\u8bf7\u4f60\u8ba1\u7b97\u5e76\u8fd4\u56de\u4e24\u4e2a\u77e9\u5f62\u8986\u76d6\u7684\u603b\u9762\u79ef\u3002

    \n\n

    \u6bcf\u4e2a\u77e9\u5f62\u7531\u5176 \u5de6\u4e0b \u9876\u70b9\u548c \u53f3\u4e0a \u9876\u70b9\u5750\u6807\u8868\u793a\uff1a

    \n\n
    \n
      \n\t
    • \u7b2c\u4e00\u4e2a\u77e9\u5f62\u7531\u5176\u5de6\u4e0b\u9876\u70b9 (ax1, ay1) \u548c\u53f3\u4e0a\u9876\u70b9 (ax2, ay2) \u5b9a\u4e49\u3002
    • \n\t
    • \u7b2c\u4e8c\u4e2a\u77e9\u5f62\u7531\u5176\u5de6\u4e0b\u9876\u70b9 (bx1, by1) \u548c\u53f3\u4e0a\u9876\u70b9 (bx2, by2) \u5b9a\u4e49\u3002
    • \n
    \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"Rectangle\n
    \n\u8f93\u5165\uff1aax1 = -3, ay1 = 0, ax2 = 3, ay2 = 4, bx1 = 0, by1 = -1, bx2 = 9, by2 = 2\n\u8f93\u51fa\uff1a45\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aax1 = -2, ay1 = -2, ax2 = 2, ay2 = 2, bx1 = -2, by1 = -2, bx2 = 2, by2 = 2\n\u8f93\u51fa\uff1a16\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • -104 <= ax1, ay1, ax2, ay2, bx1, by1, bx2, by2 <= 104
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int computeArea(int ax1, int ay1, int ax2, int ay2, int bx1, int by1, int bx2, int by2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int computeArea(int ax1, int ay1, int ax2, int ay2, int bx1, int by1, int bx2, int by2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def computeArea(self, ax1, ay1, ax2, ay2, bx1, by1, bx2, by2):\n \"\"\"\n :type ax1: int\n :type ay1: int\n :type ax2: int\n :type ay2: int\n :type bx1: int\n :type by1: int\n :type bx2: int\n :type by2: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def computeArea(self, ax1: int, ay1: int, ax2: int, ay2: int, bx1: int, by1: int, bx2: int, by2: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint computeArea(int ax1, int ay1, int ax2, int ay2, int bx1, int by1, int bx2, int by2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ComputeArea(int ax1, int ay1, int ax2, int ay2, int bx1, int by1, int bx2, int by2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} ax1\n * @param {number} ay1\n * @param {number} ax2\n * @param {number} ay2\n * @param {number} bx1\n * @param {number} by1\n * @param {number} bx2\n * @param {number} by2\n * @return {number}\n */\nvar computeArea = function(ax1, ay1, ax2, ay2, bx1, by1, bx2, by2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} ax1\n# @param {Integer} ay1\n# @param {Integer} ax2\n# @param {Integer} ay2\n# @param {Integer} bx1\n# @param {Integer} by1\n# @param {Integer} bx2\n# @param {Integer} by2\n# @return {Integer}\ndef compute_area(ax1, ay1, ax2, ay2, bx1, by1, bx2, by2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func computeArea(_ ax1: Int, _ ay1: Int, _ ax2: Int, _ ay2: Int, _ bx1: Int, _ by1: Int, _ bx2: Int, _ by2: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func computeArea(ax1 int, ay1 int, ax2 int, ay2 int, bx1 int, by1 int, bx2 int, by2 int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def computeArea(ax1: Int, ay1: Int, ax2: Int, ay2: Int, bx1: Int, by1: Int, bx2: Int, by2: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun computeArea(ax1: Int, ay1: Int, ax2: Int, ay2: Int, bx1: Int, by1: Int, bx2: Int, by2: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn compute_area(ax1: i32, ay1: i32, ax2: i32, ay2: i32, bx1: i32, by1: i32, bx2: i32, by2: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $ax1\n * @param Integer $ay1\n * @param Integer $ax2\n * @param Integer $ay2\n * @param Integer $bx1\n * @param Integer $by1\n * @param Integer $bx2\n * @param Integer $by2\n * @return Integer\n */\n function computeArea($ax1, $ay1, $ax2, $ay2, $bx1, $by1, $bx2, $by2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function computeArea(ax1: number, ay1: number, ax2: number, ay2: number, bx1: number, by1: number, bx2: number, by2: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (compute-area ax1 ay1 ax2 ay2 bx1 by1 bx2 by2)\n (-> exact-integer? exact-integer? exact-integer? exact-integer? exact-integer? exact-integer? exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0223](https://leetcode-cn.com/problems/rectangle-area)", "[\u77e9\u5f62\u9762\u79ef](/solution/0200-0299/0223.Rectangle%20Area/README.md)", "`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0223](https://leetcode.com/problems/rectangle-area)", "[Rectangle Area](/solution/0200-0299/0223.Rectangle%20Area/README_EN.md)", "`Math`", "Medium", ""]}, {"question_id": "0222", "frontend_question_id": "0222", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-complete-tree-nodes", "url_en": "https://leetcode.com/problems/count-complete-tree-nodes", "relative_path_cn": "/solution/0200-0299/0222.Count%20Complete%20Tree%20Nodes/README.md", "relative_path_en": "/solution/0200-0299/0222.Count%20Complete%20Tree%20Nodes/README_EN.md", "title_cn": "\u5b8c\u5168\u4e8c\u53c9\u6811\u7684\u8282\u70b9\u4e2a\u6570", "title_en": "Count Complete Tree Nodes", "question_title_slug": "count-complete-tree-nodes", "content_en": "

    Given the root of a complete binary tree, return the number of the nodes in the tree.

    \n\n

    According to Wikipedia, every level, except possibly the last, is completely filled in a complete binary tree, and all nodes in the last level are as far left as possible. It can have between 1 and 2h nodes inclusive at the last level h.

    \n\n

    Design an algorithm that runs in less than O(n) time complexity.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,2,3,4,5,6]\nOutput: 6\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = []\nOutput: 0\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = [1]\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [0, 5 * 104].
    • \n\t
    • 0 <= Node.val <= 5 * 104
    • \n\t
    • The tree is guaranteed to be complete.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u68f5 \u5b8c\u5168\u4e8c\u53c9\u6811 \u7684\u6839\u8282\u70b9 root \uff0c\u6c42\u51fa\u8be5\u6811\u7684\u8282\u70b9\u4e2a\u6570\u3002

    \n\n

    \u5b8c\u5168\u4e8c\u53c9\u6811 \u7684\u5b9a\u4e49\u5982\u4e0b\uff1a\u5728\u5b8c\u5168\u4e8c\u53c9\u6811\u4e2d\uff0c\u9664\u4e86\u6700\u5e95\u5c42\u8282\u70b9\u53ef\u80fd\u6ca1\u586b\u6ee1\u5916\uff0c\u5176\u4f59\u6bcf\u5c42\u8282\u70b9\u6570\u90fd\u8fbe\u5230\u6700\u5927\u503c\uff0c\u5e76\u4e14\u6700\u4e0b\u9762\u4e00\u5c42\u7684\u8282\u70b9\u90fd\u96c6\u4e2d\u5728\u8be5\u5c42\u6700\u5de6\u8fb9\u7684\u82e5\u5e72\u4f4d\u7f6e\u3002\u82e5\u6700\u5e95\u5c42\u4e3a\u7b2c h \u5c42\uff0c\u5219\u8be5\u5c42\u5305\u542b 1~\u00a02h\u00a0\u4e2a\u8282\u70b9\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [1,2,3,4,5,6]\n\u8f93\u51fa\uff1a6\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = []\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [1]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u7684\u6570\u76ee\u8303\u56f4\u662f[0, 5 * 104]
    • \n\t
    • 0 <= Node.val <= 5 * 104
    • \n\t
    • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u8f93\u5165\u7684\u6811\u662f \u5b8c\u5168\u4e8c\u53c9\u6811
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u904d\u5386\u6811\u6765\u7edf\u8ba1\u8282\u70b9\u662f\u4e00\u79cd\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n) \u7684\u7b80\u5355\u89e3\u51b3\u65b9\u6848\u3002\u4f60\u53ef\u4ee5\u8bbe\u8ba1\u4e00\u4e2a\u66f4\u5feb\u7684\u7b97\u6cd5\u5417\uff1f

    \n", "tags_en": ["Tree", "Binary Search"], "tags_cn": ["\u6811", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int countNodes(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int countNodes(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def countNodes(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def countNodes(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint countNodes(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int CountNodes(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar countNodes = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef count_nodes(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func countNodes(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc countNodes(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def countNodes(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun countNodes(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn count_nodes(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function countNodes($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction countNodes(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (count-nodes root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0222](https://leetcode-cn.com/problems/count-complete-tree-nodes)", "[\u5b8c\u5168\u4e8c\u53c9\u6811\u7684\u8282\u70b9\u4e2a\u6570](/solution/0200-0299/0222.Count%20Complete%20Tree%20Nodes/README.md)", "`\u6811`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0222](https://leetcode.com/problems/count-complete-tree-nodes)", "[Count Complete Tree Nodes](/solution/0200-0299/0222.Count%20Complete%20Tree%20Nodes/README_EN.md)", "`Tree`,`Binary Search`", "Medium", ""]}, {"question_id": "0221", "frontend_question_id": "0221", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximal-square", "url_en": "https://leetcode.com/problems/maximal-square", "relative_path_cn": "/solution/0200-0299/0221.Maximal%20Square/README.md", "relative_path_en": "/solution/0200-0299/0221.Maximal%20Square/README_EN.md", "title_cn": "\u6700\u5927\u6b63\u65b9\u5f62", "title_en": "Maximal Square", "question_title_slug": "maximal-square", "content_en": "

    Given an m x n binary matrix filled with 0's and 1's, find the largest square containing only 1's and return its area.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: matrix = [["1","0","1","0","0"],["1","0","1","1","1"],["1","1","1","1","1"],["1","0","0","1","0"]]\nOutput: 4\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: matrix = [["0","1"],["1","0"]]\nOutput: 1\n
    \n\n

    Example 3:

    \n\n
    \nInput: matrix = [["0"]]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == matrix.length
    • \n\t
    • n == matrix[i].length
    • \n\t
    • 1 <= m, n <= 300
    • \n\t
    • matrix[i][j] is '0' or '1'.
    • \n
    \n", "content_cn": "

    \u5728\u4e00\u4e2a\u7531 '0' \u548c '1' \u7ec4\u6210\u7684\u4e8c\u7ef4\u77e9\u9635\u5185\uff0c\u627e\u5230\u53ea\u5305\u542b '1' \u7684\u6700\u5927\u6b63\u65b9\u5f62\uff0c\u5e76\u8fd4\u56de\u5176\u9762\u79ef\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1amatrix = [[\"1\",\"0\",\"1\",\"0\",\"0\"],[\"1\",\"0\",\"1\",\"1\",\"1\"],[\"1\",\"1\",\"1\",\"1\",\"1\"],[\"1\",\"0\",\"0\",\"1\",\"0\"]]\n\u8f93\u51fa\uff1a4\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1amatrix = [[\"0\",\"1\"],[\"1\",\"0\"]]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1amatrix = [[\"0\"]]\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == matrix.length
    • \n\t
    • n == matrix[i].length
    • \n\t
    • 1 <= m, n <= 300
    • \n\t
    • matrix[i][j] \u4e3a '0' \u6216 '1'
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maximalSquare(vector>& matrix) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maximalSquare(char[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximalSquare(self, matrix):\n \"\"\"\n :type matrix: List[List[str]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximalSquare(self, matrix: List[List[str]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maximalSquare(char** matrix, int matrixSize, int* matrixColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaximalSquare(char[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {character[][]} matrix\n * @return {number}\n */\nvar maximalSquare = function(matrix) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Character[][]} matrix\n# @return {Integer}\ndef maximal_square(matrix)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximalSquare(_ matrix: [[Character]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximalSquare(matrix [][]byte) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximalSquare(matrix: Array[Array[Char]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximalSquare(matrix: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximal_square(matrix: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $matrix\n * @return Integer\n */\n function maximalSquare($matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximalSquare(matrix: string[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximal-square matrix)\n (-> (listof (listof char?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0221](https://leetcode-cn.com/problems/maximal-square)", "[\u6700\u5927\u6b63\u65b9\u5f62](/solution/0200-0299/0221.Maximal%20Square/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0221](https://leetcode.com/problems/maximal-square)", "[Maximal Square](/solution/0200-0299/0221.Maximal%20Square/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0220", "frontend_question_id": "0220", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/contains-duplicate-iii", "url_en": "https://leetcode.com/problems/contains-duplicate-iii", "relative_path_cn": "/solution/0200-0299/0220.Contains%20Duplicate%20III/README.md", "relative_path_en": "/solution/0200-0299/0220.Contains%20Duplicate%20III/README_EN.md", "title_cn": "\u5b58\u5728\u91cd\u590d\u5143\u7d20 III", "title_en": "Contains Duplicate III", "question_title_slug": "contains-duplicate-iii", "content_en": "

    Given an integer array nums and two integers k and t, return true if there are two distinct indices i and j in the array such that abs(nums[i] - nums[j]) <= t and abs(i - j) <= k.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [1,2,3,1], k = 3, t = 0\nOutput: true\n

    Example 2:

    \n
    Input: nums = [1,0,1,1], k = 1, t = 2\nOutput: true\n

    Example 3:

    \n
    Input: nums = [1,5,9,1,5,9], k = 2, t = 3\nOutput: false\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= nums.length <= 2 * 104
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n\t
    • 0 <= k <= 104
    • \n\t
    • 0 <= t <= 231 - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \u548c\u4e24\u4e2a\u6574\u6570\u00a0k \u548c t \u3002\u8bf7\u4f60\u5224\u65ad\u662f\u5426\u5b58\u5728 \u4e24\u4e2a\u4e0d\u540c\u4e0b\u6807 i \u548c j\uff0c\u4f7f\u5f97\u00a0abs(nums[i] - nums[j]) <= t \uff0c\u540c\u65f6\u53c8\u6ee1\u8db3 abs(i - j) <= k \u3002

    \n\n

    \u5982\u679c\u5b58\u5728\u5219\u8fd4\u56de true\uff0c\u4e0d\u5b58\u5728\u8fd4\u56de false\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\u00a01\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,3,1], k = 3, t = 0\n\u8f93\u51fa\uff1atrue
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,0,1,1], k = 1, t = 2\n\u8f93\u51fa\uff1atrue
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,5,9,1,5,9], k = 2, t = 3\n\u8f93\u51fa\uff1afalse
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= nums.length <= 2 * 104
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n\t
    • 0 <= k <= 104
    • \n\t
    • 0 <= t <= 231 - 1
    • \n
    \n", "tags_en": ["Sort", "Ordered Map"], "tags_cn": ["\u6392\u5e8f"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool containsNearbyAlmostDuplicate(vector& nums, int k, int t) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean containsNearbyAlmostDuplicate(int[] nums, int k, int t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def containsNearbyAlmostDuplicate(self, nums, k, t):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :type t: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def containsNearbyAlmostDuplicate(self, nums: List[int], k: int, t: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool containsNearbyAlmostDuplicate(int* nums, int numsSize, int k, int t){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool ContainsNearbyAlmostDuplicate(int[] nums, int k, int t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @param {number} t\n * @return {boolean}\n */\nvar containsNearbyAlmostDuplicate = function(nums, k, t) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @param {Integer} t\n# @return {Boolean}\ndef contains_nearby_almost_duplicate(nums, k, t)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func containsNearbyAlmostDuplicate(_ nums: [Int], _ k: Int, _ t: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func containsNearbyAlmostDuplicate(nums []int, k int, t int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def containsNearbyAlmostDuplicate(nums: Array[Int], k: Int, t: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun containsNearbyAlmostDuplicate(nums: IntArray, k: Int, t: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn contains_nearby_almost_duplicate(nums: Vec, k: i32, t: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @param Integer $t\n * @return Boolean\n */\n function containsNearbyAlmostDuplicate($nums, $k, $t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function containsNearbyAlmostDuplicate(nums: number[], k: number, t: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (contains-nearby-almost-duplicate nums k t)\n (-> (listof exact-integer?) exact-integer? exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0220](https://leetcode-cn.com/problems/contains-duplicate-iii)", "[\u5b58\u5728\u91cd\u590d\u5143\u7d20 III](/solution/0200-0299/0220.Contains%20Duplicate%20III/README.md)", "`\u6392\u5e8f`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0220](https://leetcode.com/problems/contains-duplicate-iii)", "[Contains Duplicate III](/solution/0200-0299/0220.Contains%20Duplicate%20III/README_EN.md)", "`Sort`,`Ordered Map`", "Medium", ""]}, {"question_id": "0219", "frontend_question_id": "0219", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/contains-duplicate-ii", "url_en": "https://leetcode.com/problems/contains-duplicate-ii", "relative_path_cn": "/solution/0200-0299/0219.Contains%20Duplicate%20II/README.md", "relative_path_en": "/solution/0200-0299/0219.Contains%20Duplicate%20II/README_EN.md", "title_cn": "\u5b58\u5728\u91cd\u590d\u5143\u7d20 II", "title_en": "Contains Duplicate II", "question_title_slug": "contains-duplicate-ii", "content_en": "

    Given an integer array nums and an integer k, return true if there are two distinct indices i and j in the array such that nums[i] == nums[j] and abs(i - j) <= k.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,3,1], k = 3\nOutput: true\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,0,1,1], k = 1\nOutput: true\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [1,2,3,1,2,3], k = 2\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • -109 <= nums[i] <= 109
    • \n\t
    • 0 <= k <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u548c\u4e00\u4e2a\u6574\u6570 k\uff0c\u5224\u65ad\u6570\u7ec4\u4e2d\u662f\u5426\u5b58\u5728\u4e24\u4e2a\u4e0d\u540c\u7684\u7d22\u5f15 i \u548c j\uff0c\u4f7f\u5f97 nums [i] = nums [j]\uff0c\u5e76\u4e14 i \u548c j \u7684\u5dee\u7684 \u7edd\u5bf9\u503c \u81f3\u591a\u4e3a k\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: nums = [1,2,3,1], k = 3\n\u8f93\u51fa: true
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: nums = [1,0,1,1], k = 1\n\u8f93\u51fa: true
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u8f93\u5165: nums = [1,2,3,1,2,3], k = 2\n\u8f93\u51fa: false
    \n", "tags_en": ["Array", "Hash Table"], "tags_cn": ["\u6570\u7ec4", "\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool containsNearbyDuplicate(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean containsNearbyDuplicate(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def containsNearbyDuplicate(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def containsNearbyDuplicate(self, nums: List[int], k: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool containsNearbyDuplicate(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool ContainsNearbyDuplicate(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {boolean}\n */\nvar containsNearbyDuplicate = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Boolean}\ndef contains_nearby_duplicate(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func containsNearbyDuplicate(_ nums: [Int], _ k: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func containsNearbyDuplicate(nums []int, k int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def containsNearbyDuplicate(nums: Array[Int], k: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun containsNearbyDuplicate(nums: IntArray, k: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn contains_nearby_duplicate(nums: Vec, k: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Boolean\n */\n function containsNearbyDuplicate($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function containsNearbyDuplicate(nums: number[], k: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (contains-nearby-duplicate nums k)\n (-> (listof exact-integer?) exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0219](https://leetcode-cn.com/problems/contains-duplicate-ii)", "[\u5b58\u5728\u91cd\u590d\u5143\u7d20 II](/solution/0200-0299/0219.Contains%20Duplicate%20II/README.md)", "`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0219](https://leetcode.com/problems/contains-duplicate-ii)", "[Contains Duplicate II](/solution/0200-0299/0219.Contains%20Duplicate%20II/README_EN.md)", "`Array`,`Hash Table`", "Easy", ""]}, {"question_id": "0218", "frontend_question_id": "0218", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/the-skyline-problem", "url_en": "https://leetcode.com/problems/the-skyline-problem", "relative_path_cn": "/solution/0200-0299/0218.The%20Skyline%20Problem/README.md", "relative_path_en": "/solution/0200-0299/0218.The%20Skyline%20Problem/README_EN.md", "title_cn": "\u5929\u9645\u7ebf\u95ee\u9898", "title_en": "The Skyline Problem", "question_title_slug": "the-skyline-problem", "content_en": "

    A city's skyline is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return the skyline formed by these buildings collectively.

    \n\n

    The geometric information of each building is given in the array buildings where buildings[i] = [lefti, righti, heighti]:

    \n\n
      \n\t
    • lefti is the x coordinate of the left edge of the ith building.
    • \n\t
    • righti is the x coordinate of the right edge of the ith building.
    • \n\t
    • heighti is the height of the ith building.
    • \n
    \n\n

    You may assume all buildings are perfect rectangles grounded on an absolutely flat surface at height 0.

    \n\n

    The skyline should be represented as a list of "key points" sorted by their x-coordinate in the form [[x1,y1],[x2,y2],...]. Each key point is the left endpoint of some horizontal segment in the skyline except the last point in the list, which always has a y-coordinate 0 and is used to mark the skyline's termination where the rightmost building ends. Any ground between the leftmost and rightmost buildings should be part of the skyline's contour.

    \n\n

    Note: There must be no consecutive horizontal lines of equal height in the output skyline. For instance, [...,[2 3],[4 5],[7 5],[11 5],[12 7],...] is not acceptable; the three lines of height 5 should be merged into one in the final output as such: [...,[2 3],[4 5],[12 7],...]

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: buildings = [[2,9,10],[3,7,15],[5,12,12],[15,20,10],[19,24,8]]\nOutput: [[2,10],[3,15],[7,12],[12,0],[15,10],[20,8],[24,0]]\nExplanation:\nFigure A shows the buildings of the input.\nFigure B shows the skyline formed by those buildings. The red points in figure B represent the key points in the output list.\n
    \n\n

    Example 2:

    \n\n
    \nInput: buildings = [[0,2,3],[2,5,3]]\nOutput: [[0,3],[5,0]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= buildings.length <= 104
    • \n\t
    • 0 <= lefti < righti <= 231 - 1
    • \n\t
    • 1 <= heighti <= 231 - 1
    • \n\t
    • buildings is sorted by lefti in non-decreasing order.
    • \n
    \n", "content_cn": "

    \u57ce\u5e02\u7684\u5929\u9645\u7ebf\u662f\u4ece\u8fdc\u5904\u89c2\u770b\u8be5\u57ce\u5e02\u4e2d\u6240\u6709\u5efa\u7b51\u7269\u5f62\u6210\u7684\u8f6e\u5ed3\u7684\u5916\u90e8\u8f6e\u5ed3\u3002\u7ed9\u4f60\u6240\u6709\u5efa\u7b51\u7269\u7684\u4f4d\u7f6e\u548c\u9ad8\u5ea6\uff0c\u8bf7\u8fd4\u56de\u7531\u8fd9\u4e9b\u5efa\u7b51\u7269\u5f62\u6210\u7684 \u5929\u9645\u7ebf \u3002

    \n\n

    \u6bcf\u4e2a\u5efa\u7b51\u7269\u7684\u51e0\u4f55\u4fe1\u606f\u7531\u6570\u7ec4 buildings \u8868\u793a\uff0c\u5176\u4e2d\u4e09\u5143\u7ec4 buildings[i] = [lefti, righti, heighti] \u8868\u793a\uff1a

    \n\n
      \n\t
    • lefti \u662f\u7b2c i \u5ea7\u5efa\u7b51\u7269\u5de6\u8fb9\u7f18\u7684 x \u5750\u6807\u3002
    • \n\t
    • righti \u662f\u7b2c i \u5ea7\u5efa\u7b51\u7269\u53f3\u8fb9\u7f18\u7684 x \u5750\u6807\u3002
    • \n\t
    • heighti \u662f\u7b2c i \u5ea7\u5efa\u7b51\u7269\u7684\u9ad8\u5ea6\u3002
    • \n
    \n\n

    \u5929\u9645\u7ebf \u5e94\u8be5\u8868\u793a\u4e3a\u7531 \u201c\u5173\u952e\u70b9\u201d \u7ec4\u6210\u7684\u5217\u8868\uff0c\u683c\u5f0f [[x1,y1],[x2,y2],...] \uff0c\u5e76\u6309 x \u5750\u6807 \u8fdb\u884c \u6392\u5e8f \u3002\u5173\u952e\u70b9\u662f\u6c34\u5e73\u7ebf\u6bb5\u7684\u5de6\u7aef\u70b9\u3002\u5217\u8868\u4e2d\u6700\u540e\u4e00\u4e2a\u70b9\u662f\u6700\u53f3\u4fa7\u5efa\u7b51\u7269\u7684\u7ec8\u70b9\uff0cy \u5750\u6807\u59cb\u7ec8\u4e3a 0 \uff0c\u4ec5\u7528\u4e8e\u6807\u8bb0\u5929\u9645\u7ebf\u7684\u7ec8\u70b9\u3002\u6b64\u5916\uff0c\u4efb\u4f55\u4e24\u4e2a\u76f8\u90bb\u5efa\u7b51\u7269\u4e4b\u95f4\u7684\u5730\u9762\u90fd\u5e94\u88ab\u89c6\u4e3a\u5929\u9645\u7ebf\u8f6e\u5ed3\u7684\u4e00\u90e8\u5206\u3002

    \n\n

    \u6ce8\u610f\uff1a\u8f93\u51fa\u5929\u9645\u7ebf\u4e2d\u4e0d\u5f97\u6709\u8fde\u7eed\u7684\u76f8\u540c\u9ad8\u5ea6\u7684\u6c34\u5e73\u7ebf\u3002\u4f8b\u5982 [...[2 3], [4 5], [7 5], [11 5], [12 7]...] \u662f\u4e0d\u6b63\u786e\u7684\u7b54\u6848\uff1b\u4e09\u6761\u9ad8\u5ea6\u4e3a 5 \u7684\u7ebf\u5e94\u8be5\u5728\u6700\u7ec8\u8f93\u51fa\u4e2d\u5408\u5e76\u4e3a\u4e00\u4e2a\uff1a[...[2 3], [4 5], [12 7], ...]

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1abuildings = [[2,9,10],[3,7,15],[5,12,12],[15,20,10],[19,24,8]]\n\u8f93\u51fa\uff1a[[2,10],[3,15],[7,12],[12,0],[15,10],[20,8],[24,0]]\n\u89e3\u91ca\uff1a\n\u56fe A \u663e\u793a\u8f93\u5165\u7684\u6240\u6709\u5efa\u7b51\u7269\u7684\u4f4d\u7f6e\u548c\u9ad8\u5ea6\uff0c\n\u56fe B \u663e\u793a\u7531\u8fd9\u4e9b\u5efa\u7b51\u7269\u5f62\u6210\u7684\u5929\u9645\u7ebf\u3002\u56fe B \u4e2d\u7684\u7ea2\u70b9\u8868\u793a\u8f93\u51fa\u5217\u8868\u4e2d\u7684\u5173\u952e\u70b9\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1abuildings = [[0,2,3],[2,5,3]]\n\u8f93\u51fa\uff1a[[0,3],[5,0]]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= buildings.length <= 104
    • \n\t
    • 0 <= lefti < righti <= 231 - 1
    • \n\t
    • 1 <= heighti <= 231 - 1
    • \n\t
    • buildings \u6309 lefti \u975e\u9012\u51cf\u6392\u5e8f
    • \n
    \n", "tags_en": ["Heap", "Binary Indexed Tree", "Segment Tree", "Divide and Conquer", "Line Sweep"], "tags_cn": ["\u5806", "\u6811\u72b6\u6570\u7ec4", "\u7ebf\u6bb5\u6811", "\u5206\u6cbb\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> getSkyline(vector>& buildings) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> getSkyline(int[][] buildings) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getSkyline(self, buildings):\n \"\"\"\n :type buildings: List[List[int]]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getSkyline(self, buildings: List[List[int]]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** getSkyline(int** buildings, int buildingsSize, int* buildingsColSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> GetSkyline(int[][] buildings) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} buildings\n * @return {number[][]}\n */\nvar getSkyline = function(buildings) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} buildings\n# @return {Integer[][]}\ndef get_skyline(buildings)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getSkyline(_ buildings: [[Int]]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getSkyline(buildings [][]int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getSkyline(buildings: Array[Array[Int]]): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getSkyline(buildings: Array): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_skyline(buildings: Vec>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $buildings\n * @return Integer[][]\n */\n function getSkyline($buildings) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getSkyline(buildings: number[][]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-skyline buildings)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0218](https://leetcode-cn.com/problems/the-skyline-problem)", "[\u5929\u9645\u7ebf\u95ee\u9898](/solution/0200-0299/0218.The%20Skyline%20Problem/README.md)", "`\u5806`,`\u6811\u72b6\u6570\u7ec4`,`\u7ebf\u6bb5\u6811`,`\u5206\u6cbb\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[0218](https://leetcode.com/problems/the-skyline-problem)", "[The Skyline Problem](/solution/0200-0299/0218.The%20Skyline%20Problem/README_EN.md)", "`Heap`,`Binary Indexed Tree`,`Segment Tree`,`Divide and Conquer`,`Line Sweep`", "Hard", ""]}, {"question_id": "0217", "frontend_question_id": "0217", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/contains-duplicate", "url_en": "https://leetcode.com/problems/contains-duplicate", "relative_path_cn": "/solution/0200-0299/0217.Contains%20Duplicate/README.md", "relative_path_en": "/solution/0200-0299/0217.Contains%20Duplicate/README_EN.md", "title_cn": "\u5b58\u5728\u91cd\u590d\u5143\u7d20", "title_en": "Contains Duplicate", "question_title_slug": "contains-duplicate", "content_en": "

    Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [1,2,3,1]\nOutput: true\n

    Example 2:

    \n
    Input: nums = [1,2,3,4]\nOutput: false\n

    Example 3:

    \n
    Input: nums = [1,1,1,3,3,4,3,2,4,2]\nOutput: true\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • -109 <= nums[i] <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\uff0c\u5224\u65ad\u662f\u5426\u5b58\u5728\u91cd\u590d\u5143\u7d20\u3002

    \n\n

    \u5982\u679c\u5b58\u5728\u4e00\u503c\u5728\u6570\u7ec4\u4e2d\u51fa\u73b0\u81f3\u5c11\u4e24\u6b21\uff0c\u51fd\u6570\u8fd4\u56de true \u3002\u5982\u679c\u6570\u7ec4\u4e2d\u6bcf\u4e2a\u5143\u7d20\u90fd\u4e0d\u76f8\u540c\uff0c\u5219\u8fd4\u56de false \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: [1,2,3,1]\n\u8f93\u51fa: true
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: [1,2,3,4]\n\u8f93\u51fa: false
    \n\n

    \u793a\u4f8b\u00a03:

    \n\n
    \n\u8f93\u5165: [1,1,1,3,3,4,3,2,4,2]\n\u8f93\u51fa: true
    \n", "tags_en": ["Array", "Hash Table"], "tags_cn": ["\u6570\u7ec4", "\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool containsDuplicate(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean containsDuplicate(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def containsDuplicate(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def containsDuplicate(self, nums: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool containsDuplicate(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool ContainsDuplicate(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {boolean}\n */\nvar containsDuplicate = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Boolean}\ndef contains_duplicate(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func containsDuplicate(_ nums: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func containsDuplicate(nums []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def containsDuplicate(nums: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun containsDuplicate(nums: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn contains_duplicate(nums: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Boolean\n */\n function containsDuplicate($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function containsDuplicate(nums: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (contains-duplicate nums)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0217](https://leetcode-cn.com/problems/contains-duplicate)", "[\u5b58\u5728\u91cd\u590d\u5143\u7d20](/solution/0200-0299/0217.Contains%20Duplicate/README.md)", "`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0217](https://leetcode.com/problems/contains-duplicate)", "[Contains Duplicate](/solution/0200-0299/0217.Contains%20Duplicate/README_EN.md)", "`Array`,`Hash Table`", "Easy", ""]}, {"question_id": "0216", "frontend_question_id": "0216", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/combination-sum-iii", "url_en": "https://leetcode.com/problems/combination-sum-iii", "relative_path_cn": "/solution/0200-0299/0216.Combination%20Sum%20III/README.md", "relative_path_en": "/solution/0200-0299/0216.Combination%20Sum%20III/README_EN.md", "title_cn": "\u7ec4\u5408\u603b\u548c III", "title_en": "Combination Sum III", "question_title_slug": "combination-sum-iii", "content_en": "

    Find all valid combinations of k numbers that sum up to n such that the following conditions are true:

    \n\n
      \n\t
    • Only numbers 1 through 9 are used.
    • \n\t
    • Each number is used at most once.
    • \n
    \n\n

    Return a list of all possible valid combinations. The list must not contain the same combination twice, and the combinations may be returned in any order.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: k = 3, n = 7\nOutput: [[1,2,4]]\nExplanation:\n1 + 2 + 4 = 7\nThere are no other valid combinations.
    \n\n

    Example 2:

    \n\n
    \nInput: k = 3, n = 9\nOutput: [[1,2,6],[1,3,5],[2,3,4]]\nExplanation:\n1 + 2 + 6 = 9\n1 + 3 + 5 = 9\n2 + 3 + 4 = 9\nThere are no other valid combinations.\n
    \n\n

    Example 3:

    \n\n
    \nInput: k = 4, n = 1\nOutput: []\nExplanation: There are no valid combinations. [1,2,1] is not valid because 1 is used twice.\n
    \n\n

    Example 4:

    \n\n
    \nInput: k = 3, n = 2\nOutput: []\nExplanation: There are no valid combinations.\n
    \n\n

    Example 5:

    \n\n
    \nInput: k = 9, n = 45\nOutput: [[1,2,3,4,5,6,7,8,9]]\nExplanation:\n1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 = 45\n\u200b\u200b\u200b\u200b\u200b\u200b\u200bThere are no other valid combinations.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= k <= 9
    • \n\t
    • 1 <= n <= 60
    • \n
    \n", "content_cn": "

    \u627e\u51fa\u6240\u6709\u76f8\u52a0\u4e4b\u548c\u4e3a n \u7684 \u4e2a\u6570\u7684\u7ec4\u5408\u3002\u7ec4\u5408\u4e2d\u53ea\u5141\u8bb8\u542b\u6709 1 - 9 \u7684\u6b63\u6574\u6570\uff0c\u5e76\u4e14\u6bcf\u79cd\u7ec4\u5408\u4e2d\u4e0d\u5b58\u5728\u91cd\u590d\u7684\u6570\u5b57\u3002

    \n\n

    \u8bf4\u660e\uff1a

    \n\n
      \n\t
    • \u6240\u6709\u6570\u5b57\u90fd\u662f\u6b63\u6574\u6570\u3002
    • \n\t
    • \u89e3\u96c6\u4e0d\u80fd\u5305\u542b\u91cd\u590d\u7684\u7ec4\u5408\u3002 
    • \n
    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: k = 3, n = 7\n\u8f93\u51fa: [[1,2,4]]\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: k = 3, n = 9\n\u8f93\u51fa: [[1,2,6], [1,3,5], [2,3,4]]\n
    \n", "tags_en": ["Array", "Backtracking"], "tags_cn": ["\u6570\u7ec4", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> combinationSum3(int k, int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> combinationSum3(int k, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def combinationSum3(self, k, n):\n \"\"\"\n :type k: int\n :type n: int\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def combinationSum3(self, k: int, n: int) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** combinationSum3(int k, int n, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> CombinationSum3(int k, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} k\n * @param {number} n\n * @return {number[][]}\n */\nvar combinationSum3 = function(k, n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} k\n# @param {Integer} n\n# @return {Integer[][]}\ndef combination_sum3(k, n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func combinationSum3(_ k: Int, _ n: Int) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func combinationSum3(k int, n int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def combinationSum3(k: Int, n: Int): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun combinationSum3(k: Int, n: Int): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn combination_sum3(k: i32, n: i32) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $k\n * @param Integer $n\n * @return Integer[][]\n */\n function combinationSum3($k, $n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function combinationSum3(k: number, n: number): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (combination-sum3 k n)\n (-> exact-integer? exact-integer? (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0216](https://leetcode-cn.com/problems/combination-sum-iii)", "[\u7ec4\u5408\u603b\u548c III](/solution/0200-0299/0216.Combination%20Sum%20III/README.md)", "`\u6570\u7ec4`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0216](https://leetcode.com/problems/combination-sum-iii)", "[Combination Sum III](/solution/0200-0299/0216.Combination%20Sum%20III/README_EN.md)", "`Array`,`Backtracking`", "Medium", ""]}, {"question_id": "0215", "frontend_question_id": "0215", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/kth-largest-element-in-an-array", "url_en": "https://leetcode.com/problems/kth-largest-element-in-an-array", "relative_path_cn": "/solution/0200-0299/0215.Kth%20Largest%20Element%20in%20an%20Array/README.md", "relative_path_en": "/solution/0200-0299/0215.Kth%20Largest%20Element%20in%20an%20Array/README_EN.md", "title_cn": "\u6570\u7ec4\u4e2d\u7684\u7b2cK\u4e2a\u6700\u5927\u5143\u7d20", "title_en": "Kth Largest Element in an Array", "question_title_slug": "kth-largest-element-in-an-array", "content_en": "

    Given an integer array nums and an integer k, return the kth largest element in the array.

    \n\n

    Note that it is the kth largest element in the sorted order, not the kth distinct element.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [3,2,1,5,6,4], k = 2\nOutput: 5\n

    Example 2:

    \n
    Input: nums = [3,2,3,1,2,4,5,5,6], k = 4\nOutput: 4\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= k <= nums.length <= 104
    • \n\t
    • -104 <= nums[i] <= 104
    • \n
    \n", "content_cn": "

    \u5728\u672a\u6392\u5e8f\u7684\u6570\u7ec4\u4e2d\u627e\u5230\u7b2c k \u4e2a\u6700\u5927\u7684\u5143\u7d20\u3002\u8bf7\u6ce8\u610f\uff0c\u4f60\u9700\u8981\u627e\u7684\u662f\u6570\u7ec4\u6392\u5e8f\u540e\u7684\u7b2c k \u4e2a\u6700\u5927\u7684\u5143\u7d20\uff0c\u800c\u4e0d\u662f\u7b2c k \u4e2a\u4e0d\u540c\u7684\u5143\u7d20\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: [3,2,1,5,6,4] \u548c k = 2\n\u8f93\u51fa: 5\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: [3,2,3,1,2,4,5,5,6] \u548c k = 4\n\u8f93\u51fa: 4
    \n\n

    \u8bf4\u660e:

    \n\n

    \u4f60\u53ef\u4ee5\u5047\u8bbe k \u603b\u662f\u6709\u6548\u7684\uff0c\u4e14 1 ≤ k ≤ \u6570\u7ec4\u7684\u957f\u5ea6\u3002

    \n", "tags_en": ["Heap", "Divide and Conquer"], "tags_cn": ["\u5806", "\u5206\u6cbb\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findKthLargest(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findKthLargest(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findKthLargest(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findKthLargest(self, nums: List[int], k: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findKthLargest(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindKthLargest(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar findKthLargest = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Integer}\ndef find_kth_largest(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findKthLargest(_ nums: [Int], _ k: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findKthLargest(nums []int, k int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findKthLargest(nums: Array[Int], k: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findKthLargest(nums: IntArray, k: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_kth_largest(nums: Vec, k: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return Integer\n */\n function findKthLargest($nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findKthLargest(nums: number[], k: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-kth-largest nums k)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0215](https://leetcode-cn.com/problems/kth-largest-element-in-an-array)", "[\u6570\u7ec4\u4e2d\u7684\u7b2cK\u4e2a\u6700\u5927\u5143\u7d20](/solution/0200-0299/0215.Kth%20Largest%20Element%20in%20an%20Array/README.md)", "`\u5806`,`\u5206\u6cbb\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0215](https://leetcode.com/problems/kth-largest-element-in-an-array)", "[Kth Largest Element in an Array](/solution/0200-0299/0215.Kth%20Largest%20Element%20in%20an%20Array/README_EN.md)", "`Heap`,`Divide and Conquer`", "Medium", ""]}, {"question_id": "0214", "frontend_question_id": "0214", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/shortest-palindrome", "url_en": "https://leetcode.com/problems/shortest-palindrome", "relative_path_cn": "/solution/0200-0299/0214.Shortest%20Palindrome/README.md", "relative_path_en": "/solution/0200-0299/0214.Shortest%20Palindrome/README_EN.md", "title_cn": "\u6700\u77ed\u56de\u6587\u4e32", "title_en": "Shortest Palindrome", "question_title_slug": "shortest-palindrome", "content_en": "

    You are given a string s. You can convert s to a palindrome by adding characters in front of it.

    \n\n

    Return the shortest palindrome you can find by performing this transformation.

    \n\n

     

    \n

    Example 1:

    \n
    Input: s = \"aacecaaa\"\nOutput: \"aaacecaaa\"\n

    Example 2:

    \n
    Input: s = \"abcd\"\nOutput: \"dcbabcd\"\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= s.length <= 5 * 104
    • \n\t
    • s consists of lowercase English letters only.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32 s\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u5728\u5b57\u7b26\u4e32\u524d\u9762\u6dfb\u52a0\u5b57\u7b26\u5c06\u5176\u8f6c\u6362\u4e3a\u56de\u6587\u4e32\u3002\u627e\u5230\u5e76\u8fd4\u56de\u53ef\u4ee5\u7528\u8fd9\u79cd\u65b9\u5f0f\u8f6c\u6362\u7684\u6700\u77ed\u56de\u6587\u4e32\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"aacecaaa\"\n\u8f93\u51fa\uff1a\"aaacecaaa\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"abcd\"\n\u8f93\u51fa\uff1a\"dcbabcd\"\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= s.length <= 5 * 104
    • \n\t
    • s \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string shortestPalindrome(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String shortestPalindrome(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def shortestPalindrome(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def shortestPalindrome(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * shortestPalindrome(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ShortestPalindrome(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar shortestPalindrome = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef shortest_palindrome(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func shortestPalindrome(_ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func shortestPalindrome(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def shortestPalindrome(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun shortestPalindrome(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn shortest_palindrome(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function shortestPalindrome($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function shortestPalindrome(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (shortest-palindrome s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0214](https://leetcode-cn.com/problems/shortest-palindrome)", "[\u6700\u77ed\u56de\u6587\u4e32](/solution/0200-0299/0214.Shortest%20Palindrome/README.md)", "`\u5b57\u7b26\u4e32`", "\u56f0\u96be", ""], "md_table_row_en": ["[0214](https://leetcode.com/problems/shortest-palindrome)", "[Shortest Palindrome](/solution/0200-0299/0214.Shortest%20Palindrome/README_EN.md)", "`String`", "Hard", ""]}, {"question_id": "0213", "frontend_question_id": "0213", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/house-robber-ii", "url_en": "https://leetcode.com/problems/house-robber-ii", "relative_path_cn": "/solution/0200-0299/0213.House%20Robber%20II/README.md", "relative_path_en": "/solution/0200-0299/0213.House%20Robber%20II/README_EN.md", "title_cn": "\u6253\u5bb6\u52ab\u820d II", "title_en": "House Robber II", "question_title_slug": "house-robber-ii", "content_en": "

    You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place are arranged in a circle. That means the first house is the neighbor of the last one. Meanwhile, adjacent houses have a security system connected, and it will automatically contact the police if two adjacent houses were broken into on the same night.

    \n\n

    Given an integer array nums representing the amount of money of each house, return the maximum amount of money you can rob tonight without alerting the police.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [2,3,2]\nOutput: 3\nExplanation: You cannot rob house 1 (money = 2) and then rob house 3 (money = 2), because they are adjacent houses.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,2,3,1]\nOutput: 4\nExplanation: Rob house 1 (money = 1) and then rob house 3 (money = 3).\nTotal amount you can rob = 1 + 3 = 4.\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [0]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 100
    • \n\t
    • 0 <= nums[i] <= 1000
    • \n
    \n", "content_cn": "

    \u4f60\u662f\u4e00\u4e2a\u4e13\u4e1a\u7684\u5c0f\u5077\uff0c\u8ba1\u5212\u5077\u7a83\u6cbf\u8857\u7684\u623f\u5c4b\uff0c\u6bcf\u95f4\u623f\u5185\u90fd\u85cf\u6709\u4e00\u5b9a\u7684\u73b0\u91d1\u3002\u8fd9\u4e2a\u5730\u65b9\u6240\u6709\u7684\u623f\u5c4b\u90fd \u56f4\u6210\u4e00\u5708 \uff0c\u8fd9\u610f\u5473\u7740\u7b2c\u4e00\u4e2a\u623f\u5c4b\u548c\u6700\u540e\u4e00\u4e2a\u623f\u5c4b\u662f\u7d27\u6328\u7740\u7684\u3002\u540c\u65f6\uff0c\u76f8\u90bb\u7684\u623f\u5c4b\u88c5\u6709\u76f8\u4e92\u8fde\u901a\u7684\u9632\u76d7\u7cfb\u7edf\uff0c\u5982\u679c\u4e24\u95f4\u76f8\u90bb\u7684\u623f\u5c4b\u5728\u540c\u4e00\u665a\u4e0a\u88ab\u5c0f\u5077\u95ef\u5165\uff0c\u7cfb\u7edf\u4f1a\u81ea\u52a8\u62a5\u8b66 \u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u4ee3\u8868\u6bcf\u4e2a\u623f\u5c4b\u5b58\u653e\u91d1\u989d\u7684\u975e\u8d1f\u6574\u6570\u6570\u7ec4\uff0c\u8ba1\u7b97\u4f60 \u5728\u4e0d\u89e6\u52a8\u8b66\u62a5\u88c5\u7f6e\u7684\u60c5\u51b5\u4e0b \uff0c\u4eca\u665a\u80fd\u591f\u5077\u7a83\u5230\u7684\u6700\u9ad8\u91d1\u989d\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\u00a01\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [2,3,2]\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u4f60\u4e0d\u80fd\u5148\u5077\u7a83 1 \u53f7\u623f\u5c4b\uff08\u91d1\u989d = 2\uff09\uff0c\u7136\u540e\u5077\u7a83 3 \u53f7\u623f\u5c4b\uff08\u91d1\u989d = 2\uff09, \u56e0\u4e3a\u4ed6\u4eec\u662f\u76f8\u90bb\u7684\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,3,1]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u5148\u5077\u7a83 1 \u53f7\u623f\u5c4b\uff08\u91d1\u989d = 1\uff09\uff0c\u7136\u540e\u5077\u7a83 3 \u53f7\u623f\u5c4b\uff08\u91d1\u989d = 3\uff09\u3002\n\u00a0    \u5077\u7a83\u5230\u7684\u6700\u9ad8\u91d1\u989d = 1 + 3 = 4 \u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [0]\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 100
    • \n\t
    • 0 <= nums[i] <= 1000
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int rob(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int rob(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def rob(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def rob(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint rob(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int Rob(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar rob = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef rob(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func rob(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func rob(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def rob(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun rob(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn rob(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function rob($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function rob(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (rob nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0213](https://leetcode-cn.com/problems/house-robber-ii)", "[\u6253\u5bb6\u52ab\u820d II](/solution/0200-0299/0213.House%20Robber%20II/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0213](https://leetcode.com/problems/house-robber-ii)", "[House Robber II](/solution/0200-0299/0213.House%20Robber%20II/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0212", "frontend_question_id": "0212", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/word-search-ii", "url_en": "https://leetcode.com/problems/word-search-ii", "relative_path_cn": "/solution/0200-0299/0212.Word%20Search%20II/README.md", "relative_path_en": "/solution/0200-0299/0212.Word%20Search%20II/README_EN.md", "title_cn": "\u5355\u8bcd\u641c\u7d22 II", "title_en": "Word Search II", "question_title_slug": "word-search-ii", "content_en": "

    Given an m x n board of characters and a list of strings words, return all words on the board.

    \n\n

    Each word must be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically neighboring. The same letter cell may not be used more than once in a word.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: board = [["o","a","a","n"],["e","t","a","e"],["i","h","k","r"],["i","f","l","v"]], words = ["oath","pea","eat","rain"]\nOutput: ["eat","oath"]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: board = [["a","b"],["c","d"]], words = ["abcb"]\nOutput: []\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == board.length
    • \n\t
    • n == board[i].length
    • \n\t
    • 1 <= m, n <= 12
    • \n\t
    • board[i][j] is a lowercase English letter.
    • \n\t
    • 1 <= words.length <= 3 * 104
    • \n\t
    • 1 <= words[i].length <= 10
    • \n\t
    • words[i] consists of lowercase English letters.
    • \n\t
    • All the strings of words are unique.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u00a0m x n \u4e8c\u7ef4\u5b57\u7b26\u7f51\u683c\u00a0board\u00a0\u548c\u4e00\u4e2a\u5355\u8bcd\uff08\u5b57\u7b26\u4e32\uff09\u5217\u8868 words\uff0c\u627e\u51fa\u6240\u6709\u540c\u65f6\u5728\u4e8c\u7ef4\u7f51\u683c\u548c\u5b57\u5178\u4e2d\u51fa\u73b0\u7684\u5355\u8bcd\u3002

    \n\n

    \u5355\u8bcd\u5fc5\u987b\u6309\u7167\u5b57\u6bcd\u987a\u5e8f\uff0c\u901a\u8fc7 \u76f8\u90bb\u7684\u5355\u5143\u683c \u5185\u7684\u5b57\u6bcd\u6784\u6210\uff0c\u5176\u4e2d\u201c\u76f8\u90bb\u201d\u5355\u5143\u683c\u662f\u90a3\u4e9b\u6c34\u5e73\u76f8\u90bb\u6216\u5782\u76f4\u76f8\u90bb\u7684\u5355\u5143\u683c\u3002\u540c\u4e00\u4e2a\u5355\u5143\u683c\u5185\u7684\u5b57\u6bcd\u5728\u4e00\u4e2a\u5355\u8bcd\u4e2d\u4e0d\u5141\u8bb8\u88ab\u91cd\u590d\u4f7f\u7528\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aboard = [[\"o\",\"a\",\"a\",\"n\"],[\"e\",\"t\",\"a\",\"e\"],[\"i\",\"h\",\"k\",\"r\"],[\"i\",\"f\",\"l\",\"v\"]], words = [\"oath\",\"pea\",\"eat\",\"rain\"]\n\u8f93\u51fa\uff1a[\"eat\",\"oath\"]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aboard = [[\"a\",\"b\"],[\"c\",\"d\"]], words = [\"abcb\"]\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == board.length
    • \n\t
    • n == board[i].length
    • \n\t
    • 1 <= m, n <= 12
    • \n\t
    • board[i][j] \u662f\u4e00\u4e2a\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd
    • \n\t
    • 1 <= words.length <= 3 * 104
    • \n\t
    • 1 <= words[i].length <= 10
    • \n\t
    • words[i] \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n\t
    • words \u4e2d\u7684\u6240\u6709\u5b57\u7b26\u4e32\u4e92\u4e0d\u76f8\u540c
    • \n
    \n", "tags_en": ["Trie", "Backtracking"], "tags_cn": ["\u5b57\u5178\u6811", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findWords(vector>& board, vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List findWords(char[][] board, String[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findWords(self, board, words):\n \"\"\"\n :type board: List[List[str]]\n :type words: List[str]\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findWords(self, board: List[List[str]], words: List[str]) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** findWords(char** board, int boardSize, int* boardColSize, char ** words, int wordsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList FindWords(char[][] board, string[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {character[][]} board\n * @param {string[]} words\n * @return {string[]}\n */\nvar findWords = function(board, words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Character[][]} board\n# @param {String[]} words\n# @return {String[]}\ndef find_words(board, words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findWords(_ board: [[Character]], _ words: [String]) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findWords(board [][]byte, words []string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findWords(board: Array[Array[Char]], words: Array[String]): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findWords(board: Array, words: Array): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_words(board: Vec>, words: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $board\n * @param String[] $words\n * @return String[]\n */\n function findWords($board, $words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findWords(board: string[][], words: string[]): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-words board words)\n (-> (listof (listof char?)) (listof string?) (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0212](https://leetcode-cn.com/problems/word-search-ii)", "[\u5355\u8bcd\u641c\u7d22 II](/solution/0200-0299/0212.Word%20Search%20II/README.md)", "`\u5b57\u5178\u6811`,`\u56de\u6eaf\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[0212](https://leetcode.com/problems/word-search-ii)", "[Word Search II](/solution/0200-0299/0212.Word%20Search%20II/README_EN.md)", "`Trie`,`Backtracking`", "Hard", ""]}, {"question_id": "0211", "frontend_question_id": "0211", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/design-add-and-search-words-data-structure", "url_en": "https://leetcode.com/problems/design-add-and-search-words-data-structure", "relative_path_cn": "/solution/0200-0299/0211.Design%20Add%20and%20Search%20Words%20Data%20Structure/README.md", "relative_path_en": "/solution/0200-0299/0211.Design%20Add%20and%20Search%20Words%20Data%20Structure/README_EN.md", "title_cn": "\u6dfb\u52a0\u4e0e\u641c\u7d22\u5355\u8bcd - \u6570\u636e\u7ed3\u6784\u8bbe\u8ba1", "title_en": "Design Add and Search Words Data Structure", "question_title_slug": "design-add-and-search-words-data-structure", "content_en": "

    Design a data structure that supports adding new words and finding if a string matches any previously added string.

    \n\n

    Implement the WordDictionary class:

    \n\n
      \n\t
    • WordDictionary() Initializes the object.
    • \n\t
    • void addWord(word) Adds word to the data structure, it can be matched later.
    • \n\t
    • bool search(word) Returns true if there is any string in the data structure that matches word or false otherwise. word may contain dots '.' where dots can be matched with any letter.
    • \n
    \n\n

     

    \n

    Example:

    \n\n
    \nInput\n["WordDictionary","addWord","addWord","addWord","search","search","search","search"]\n[[],["bad"],["dad"],["mad"],["pad"],["bad"],[".ad"],["b.."]]\nOutput\n[null,null,null,null,false,true,true,true]\n\nExplanation\nWordDictionary wordDictionary = new WordDictionary();\nwordDictionary.addWord("bad");\nwordDictionary.addWord("dad");\nwordDictionary.addWord("mad");\nwordDictionary.search("pad"); // return False\nwordDictionary.search("bad"); // return True\nwordDictionary.search(".ad"); // return True\nwordDictionary.search("b.."); // return True\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= word.length <= 500
    • \n\t
    • word in addWord consists lower-case English letters.
    • \n\t
    • word in search consist of  '.' or lower-case English letters.
    • \n\t
    • At most 50000 calls will be made to addWord and search.
    • \n
    \n", "content_cn": "

    \u8bf7\u4f60\u8bbe\u8ba1\u4e00\u4e2a\u6570\u636e\u7ed3\u6784\uff0c\u652f\u6301 \u6dfb\u52a0\u65b0\u5355\u8bcd \u548c \u67e5\u627e\u5b57\u7b26\u4e32\u662f\u5426\u4e0e\u4efb\u4f55\u5148\u524d\u6dfb\u52a0\u7684\u5b57\u7b26\u4e32\u5339\u914d \u3002

    \n\n

    \u5b9e\u73b0\u8bcd\u5178\u7c7b WordDictionary \uff1a

    \n\n
      \n\t
    • WordDictionary() \u521d\u59cb\u5316\u8bcd\u5178\u5bf9\u8c61
    • \n\t
    • void addWord(word) \u5c06 word \u6dfb\u52a0\u5230\u6570\u636e\u7ed3\u6784\u4e2d\uff0c\u4e4b\u540e\u53ef\u4ee5\u5bf9\u5b83\u8fdb\u884c\u5339\u914d
    • \n\t
    • bool search(word) \u5982\u679c\u6570\u636e\u7ed3\u6784\u4e2d\u5b58\u5728\u5b57\u7b26\u4e32\u4e0e\u00a0word \u5339\u914d\uff0c\u5219\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de\u00a0 false \u3002word \u4e2d\u53ef\u80fd\u5305\u542b\u4e00\u4e9b '.' \uff0c\u6bcf\u4e2a\u00a0. \u90fd\u53ef\u4ee5\u8868\u793a\u4efb\u4f55\u4e00\u4e2a\u5b57\u6bcd\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\n[\"WordDictionary\",\"addWord\",\"addWord\",\"addWord\",\"search\",\"search\",\"search\",\"search\"]\n[[],[\"bad\"],[\"dad\"],[\"mad\"],[\"pad\"],[\"bad\"],[\".ad\"],[\"b..\"]]\n\u8f93\u51fa\uff1a\n[null,null,null,null,false,true,true,true]\n\n\u89e3\u91ca\uff1a\nWordDictionary wordDictionary = new WordDictionary();\nwordDictionary.addWord(\"bad\");\nwordDictionary.addWord(\"dad\");\nwordDictionary.addWord(\"mad\");\nwordDictionary.search(\"pad\"); // return False\nwordDictionary.search(\"bad\"); // return True\nwordDictionary.search(\".ad\"); // return True\nwordDictionary.search(\"b..\"); // return True\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= word.length <= 500
    • \n\t
    • addWord \u4e2d\u7684 word \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n\t
    • search \u4e2d\u7684 word \u7531 '.' \u6216\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n\t
    • \u6700\u591a\u8c03\u7528 50000 \u6b21 addWord \u548c search
    • \n
    \n", "tags_en": ["Depth-first Search", "Design", "Trie", "Backtracking"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u8bbe\u8ba1", "\u5b57\u5178\u6811", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class WordDictionary {\npublic:\n /** Initialize your data structure here. */\n WordDictionary() {\n\n }\n \n void addWord(string word) {\n\n }\n \n bool search(string word) {\n\n }\n};\n\n/**\n * Your WordDictionary object will be instantiated and called as such:\n * WordDictionary* obj = new WordDictionary();\n * obj->addWord(word);\n * bool param_2 = obj->search(word);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class WordDictionary {\n\n /** Initialize your data structure here. */\n public WordDictionary() {\n\n }\n \n public void addWord(String word) {\n\n }\n \n public boolean search(String word) {\n\n }\n}\n\n/**\n * Your WordDictionary object will be instantiated and called as such:\n * WordDictionary obj = new WordDictionary();\n * obj.addWord(word);\n * boolean param_2 = obj.search(word);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class WordDictionary(object):\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def addWord(self, word):\n \"\"\"\n :type word: str\n :rtype: None\n \"\"\"\n\n\n def search(self, word):\n \"\"\"\n :type word: str\n :rtype: bool\n \"\"\"\n\n\n\n# Your WordDictionary object will be instantiated and called as such:\n# obj = WordDictionary()\n# obj.addWord(word)\n# param_2 = obj.search(word)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class WordDictionary:\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def addWord(self, word: str) -> None:\n\n\n def search(self, word: str) -> bool:\n\n\n\n# Your WordDictionary object will be instantiated and called as such:\n# obj = WordDictionary()\n# obj.addWord(word)\n# param_2 = obj.search(word)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} WordDictionary;\n\n/** Initialize your data structure here. */\n\nWordDictionary* wordDictionaryCreate() {\n \n}\n\nvoid wordDictionaryAddWord(WordDictionary* obj, char * word) {\n \n}\n\nbool wordDictionarySearch(WordDictionary* obj, char * word) {\n \n}\n\nvoid wordDictionaryFree(WordDictionary* obj) {\n \n}\n\n/**\n * Your WordDictionary struct will be instantiated and called as such:\n * WordDictionary* obj = wordDictionaryCreate();\n * wordDictionaryAddWord(obj, word);\n \n * bool param_2 = wordDictionarySearch(obj, word);\n \n * wordDictionaryFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class WordDictionary {\n\n /** Initialize your data structure here. */\n public WordDictionary() {\n\n }\n \n public void AddWord(string word) {\n\n }\n \n public bool Search(string word) {\n\n }\n}\n\n/**\n * Your WordDictionary object will be instantiated and called as such:\n * WordDictionary obj = new WordDictionary();\n * obj.AddWord(word);\n * bool param_2 = obj.Search(word);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Initialize your data structure here.\n */\nvar WordDictionary = function() {\n\n};\n\n/** \n * @param {string} word\n * @return {void}\n */\nWordDictionary.prototype.addWord = function(word) {\n\n};\n\n/** \n * @param {string} word\n * @return {boolean}\n */\nWordDictionary.prototype.search = function(word) {\n\n};\n\n/**\n * Your WordDictionary object will be instantiated and called as such:\n * var obj = new WordDictionary()\n * obj.addWord(word)\n * var param_2 = obj.search(word)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class WordDictionary\n\n=begin\n Initialize your data structure here.\n=end\n def initialize()\n\n end\n\n\n=begin\n :type word: String\n :rtype: Void\n=end\n def add_word(word)\n\n end\n\n\n=begin\n :type word: String\n :rtype: Boolean\n=end\n def search(word)\n\n end\n\n\nend\n\n# Your WordDictionary object will be instantiated and called as such:\n# obj = WordDictionary.new()\n# obj.add_word(word)\n# param_2 = obj.search(word)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass WordDictionary {\n\n /** Initialize your data structure here. */\n init() {\n\n }\n \n func addWord(_ word: String) {\n\n }\n \n func search(_ word: String) -> Bool {\n\n }\n}\n\n/**\n * Your WordDictionary object will be instantiated and called as such:\n * let obj = WordDictionary()\n * obj.addWord(word)\n * let ret_2: Bool = obj.search(word)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type WordDictionary struct {\n\n}\n\n\n/** Initialize your data structure here. */\nfunc Constructor() WordDictionary {\n\n}\n\n\nfunc (this *WordDictionary) AddWord(word string) {\n\n}\n\n\nfunc (this *WordDictionary) Search(word string) bool {\n\n}\n\n\n/**\n * Your WordDictionary object will be instantiated and called as such:\n * obj := Constructor();\n * obj.AddWord(word);\n * param_2 := obj.Search(word);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class WordDictionary() {\n\n /** Initialize your data structure here. */\n\n\n def addWord(word: String) {\n\n }\n\n def search(word: String): Boolean = {\n\n }\n\n}\n\n/**\n * Your WordDictionary object will be instantiated and called as such:\n * var obj = new WordDictionary()\n * obj.addWord(word)\n * var param_2 = obj.search(word)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class WordDictionary() {\n\n /** Initialize your data structure here. */\n\n\n fun addWord(word: String) {\n\n }\n\n fun search(word: String): Boolean {\n\n }\n\n}\n\n/**\n * Your WordDictionary object will be instantiated and called as such:\n * var obj = WordDictionary()\n * obj.addWord(word)\n * var param_2 = obj.search(word)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct WordDictionary {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl WordDictionary {\n\n /** Initialize your data structure here. */\n fn new() -> Self {\n\n }\n \n fn add_word(&self, word: String) {\n\n }\n \n fn search(&self, word: String) -> bool {\n\n }\n}\n\n/**\n * Your WordDictionary object will be instantiated and called as such:\n * let obj = WordDictionary::new();\n * obj.add_word(word);\n * let ret_2: bool = obj.search(word);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class WordDictionary {\n /**\n * Initialize your data structure here.\n */\n function __construct() {\n\n }\n\n /**\n * @param String $word\n * @return NULL\n */\n function addWord($word) {\n\n }\n\n /**\n * @param String $word\n * @return Boolean\n */\n function search($word) {\n\n }\n}\n\n/**\n * Your WordDictionary object will be instantiated and called as such:\n * $obj = WordDictionary();\n * $obj->addWord($word);\n * $ret_2 = $obj->search($word);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class WordDictionary {\n constructor() {\n\n }\n\n addWord(word: string): void {\n\n }\n\n search(word: string): boolean {\n\n }\n}\n\n/**\n * Your WordDictionary object will be instantiated and called as such:\n * var obj = new WordDictionary()\n * obj.addWord(word)\n * var param_2 = obj.search(word)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define word-dictionary%\n (class object%\n (super-new)\n (init-field)\n \n ; add-word : string? -> void?\n (define/public (add-word word)\n\n )\n ; search : string? -> boolean?\n (define/public (search word)\n\n )))\n\n;; Your word-dictionary% object will be instantiated and called as such:\n;; (define obj (new word-dictionary%))\n;; (send obj add-word word)\n;; (define param_2 (send obj search word))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0211](https://leetcode-cn.com/problems/design-add-and-search-words-data-structure)", "[\u6dfb\u52a0\u4e0e\u641c\u7d22\u5355\u8bcd - \u6570\u636e\u7ed3\u6784\u8bbe\u8ba1](/solution/0200-0299/0211.Design%20Add%20and%20Search%20Words%20Data%20Structure/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u8bbe\u8ba1`,`\u5b57\u5178\u6811`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0211](https://leetcode.com/problems/design-add-and-search-words-data-structure)", "[Design Add and Search Words Data Structure](/solution/0200-0299/0211.Design%20Add%20and%20Search%20Words%20Data%20Structure/README_EN.md)", "`Depth-first Search`,`Design`,`Trie`,`Backtracking`", "Medium", ""]}, {"question_id": "0210", "frontend_question_id": "0210", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/course-schedule-ii", "url_en": "https://leetcode.com/problems/course-schedule-ii", "relative_path_cn": "/solution/0200-0299/0210.Course%20Schedule%20II/README.md", "relative_path_en": "/solution/0200-0299/0210.Course%20Schedule%20II/README_EN.md", "title_cn": "\u8bfe\u7a0b\u8868 II", "title_en": "Course Schedule II", "question_title_slug": "course-schedule-ii", "content_en": "

    There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i] = [ai, bi] indicates that you must take course bi first if you want to take course ai.

    \n\n
      \n\t
    • For example, the pair [0, 1], indicates that to take course 0 you have to first take course 1.
    • \n
    \n\n

    Return the ordering of courses you should take to finish all courses. If there are many valid answers, return any of them. If it is impossible to finish all courses, return an empty array.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: numCourses = 2, prerequisites = [[1,0]]\nOutput: [0,1]\nExplanation: There are a total of 2 courses to take. To take course 1 you should have finished course 0. So the correct course order is [0,1].\n
    \n\n

    Example 2:

    \n\n
    \nInput: numCourses = 4, prerequisites = [[1,0],[2,0],[3,1],[3,2]]\nOutput: [0,2,1,3]\nExplanation: There are a total of 4 courses to take. To take course 3 you should have finished both courses 1 and 2. Both courses 1 and 2 should be taken after you finished course 0.\nSo one correct course order is [0,1,2,3]. Another correct ordering is [0,2,1,3].\n
    \n\n

    Example 3:

    \n\n
    \nInput: numCourses = 1, prerequisites = []\nOutput: [0]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= numCourses <= 2000
    • \n\t
    • 0 <= prerequisites.length <= numCourses * (numCourses - 1)
    • \n\t
    • prerequisites[i].length == 2
    • \n\t
    • 0 <= ai, bi < numCourses
    • \n\t
    • ai != bi
    • \n\t
    • All the pairs [ai, bi] are distinct.
    • \n
    \n", "content_cn": "

    \u73b0\u5728\u4f60\u603b\u5171\u6709 n \u95e8\u8bfe\u9700\u8981\u9009\uff0c\u8bb0\u4e3a 0 \u5230 n-1\u3002

    \n\n

    \u5728\u9009\u4fee\u67d0\u4e9b\u8bfe\u7a0b\u4e4b\u524d\u9700\u8981\u4e00\u4e9b\u5148\u4fee\u8bfe\u7a0b\u3002 \u4f8b\u5982\uff0c\u60f3\u8981\u5b66\u4e60\u8bfe\u7a0b 0 \uff0c\u4f60\u9700\u8981\u5148\u5b8c\u6210\u8bfe\u7a0b 1 \uff0c\u6211\u4eec\u7528\u4e00\u4e2a\u5339\u914d\u6765\u8868\u793a\u4ed6\u4eec: [0,1]

    \n\n

    \u7ed9\u5b9a\u8bfe\u7a0b\u603b\u91cf\u4ee5\u53ca\u5b83\u4eec\u7684\u5148\u51b3\u6761\u4ef6\uff0c\u8fd4\u56de\u4f60\u4e3a\u4e86\u5b66\u5b8c\u6240\u6709\u8bfe\u7a0b\u6240\u5b89\u6392\u7684\u5b66\u4e60\u987a\u5e8f\u3002

    \n\n

    \u53ef\u80fd\u4f1a\u6709\u591a\u4e2a\u6b63\u786e\u7684\u987a\u5e8f\uff0c\u4f60\u53ea\u8981\u8fd4\u56de\u4e00\u79cd\u5c31\u53ef\u4ee5\u4e86\u3002\u5982\u679c\u4e0d\u53ef\u80fd\u5b8c\u6210\u6240\u6709\u8bfe\u7a0b\uff0c\u8fd4\u56de\u4e00\u4e2a\u7a7a\u6570\u7ec4\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: 2, [[1,0]] \n\u8f93\u51fa: [0,1]\n\u89e3\u91ca: \u603b\u5171\u6709 2 \u95e8\u8bfe\u7a0b\u3002\u8981\u5b66\u4e60\u8bfe\u7a0b 1\uff0c\u4f60\u9700\u8981\u5148\u5b8c\u6210\u8bfe\u7a0b 0\u3002\u56e0\u6b64\uff0c\u6b63\u786e\u7684\u8bfe\u7a0b\u987a\u5e8f\u4e3a [0,1] \u3002
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: 4, [[1,0],[2,0],[3,1],[3,2]]\n\u8f93\u51fa: [0,1,2,3] or [0,2,1,3]\n\u89e3\u91ca: \u603b\u5171\u6709 4 \u95e8\u8bfe\u7a0b\u3002\u8981\u5b66\u4e60\u8bfe\u7a0b 3\uff0c\u4f60\u5e94\u8be5\u5148\u5b8c\u6210\u8bfe\u7a0b 1 \u548c\u8bfe\u7a0b 2\u3002\u5e76\u4e14\u8bfe\u7a0b 1 \u548c\u8bfe\u7a0b 2 \u90fd\u5e94\u8be5\u6392\u5728\u8bfe\u7a0b 0 \u4e4b\u540e\u3002\n     \u56e0\u6b64\uff0c\u4e00\u4e2a\u6b63\u786e\u7684\u8bfe\u7a0b\u987a\u5e8f\u662f [0,1,2,3] \u3002\u53e6\u4e00\u4e2a\u6b63\u786e\u7684\u6392\u5e8f\u662f [0,2,1,3] \u3002\n
    \n\n

    \u8bf4\u660e:

    \n\n
      \n\t
    1. \u8f93\u5165\u7684\u5148\u51b3\u6761\u4ef6\u662f\u7531\u8fb9\u7f18\u5217\u8868\u8868\u793a\u7684\u56fe\u5f62\uff0c\u800c\u4e0d\u662f\u90bb\u63a5\u77e9\u9635\u3002\u8be6\u60c5\u8bf7\u53c2\u89c1\u56fe\u7684\u8868\u793a\u6cd5\u3002
    2. \n\t
    3. \u4f60\u53ef\u4ee5\u5047\u5b9a\u8f93\u5165\u7684\u5148\u51b3\u6761\u4ef6\u4e2d\u6ca1\u6709\u91cd\u590d\u7684\u8fb9\u3002
    4. \n
    \n\n

    \u63d0\u793a:

    \n\n
      \n\t
    1. \u8fd9\u4e2a\u95ee\u9898\u76f8\u5f53\u4e8e\u67e5\u627e\u4e00\u4e2a\u5faa\u73af\u662f\u5426\u5b58\u5728\u4e8e\u6709\u5411\u56fe\u4e2d\u3002\u5982\u679c\u5b58\u5728\u5faa\u73af\uff0c\u5219\u4e0d\u5b58\u5728\u62d3\u6251\u6392\u5e8f\uff0c\u56e0\u6b64\u4e0d\u53ef\u80fd\u9009\u53d6\u6240\u6709\u8bfe\u7a0b\u8fdb\u884c\u5b66\u4e60\u3002
    2. \n\t
    3. \u901a\u8fc7 DFS \u8fdb\u884c\u62d3\u6251\u6392\u5e8f - \u4e00\u4e2a\u5173\u4e8eCoursera\u7684\u7cbe\u5f69\u89c6\u9891\u6559\u7a0b\uff0821\u5206\u949f\uff09\uff0c\u4ecb\u7ecd\u62d3\u6251\u6392\u5e8f\u7684\u57fa\u672c\u6982\u5ff5\u3002
    4. \n\t
    5. \n\t

      \u62d3\u6251\u6392\u5e8f\u4e5f\u53ef\u4ee5\u901a\u8fc7 BFS \u5b8c\u6210\u3002

      \n\t
    6. \n
    \n", "tags_en": ["Depth-first Search", "Breadth-first Search", "Graph", "Topological Sort"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u56fe", "\u62d3\u6251\u6392\u5e8f"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findOrder(int numCourses, vector>& prerequisites) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] findOrder(int numCourses, int[][] prerequisites) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findOrder(self, numCourses, prerequisites):\n \"\"\"\n :type numCourses: int\n :type prerequisites: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findOrder(self, numCourses: int, prerequisites: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* findOrder(int numCourses, int** prerequisites, int prerequisitesSize, int* prerequisitesColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] FindOrder(int numCourses, int[][] prerequisites) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} numCourses\n * @param {number[][]} prerequisites\n * @return {number[]}\n */\nvar findOrder = function(numCourses, prerequisites) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} num_courses\n# @param {Integer[][]} prerequisites\n# @return {Integer[]}\ndef find_order(num_courses, prerequisites)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findOrder(_ numCourses: Int, _ prerequisites: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findOrder(numCourses int, prerequisites [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findOrder(numCourses: Int, prerequisites: Array[Array[Int]]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findOrder(numCourses: Int, prerequisites: Array): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_order(num_courses: i32, prerequisites: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $numCourses\n * @param Integer[][] $prerequisites\n * @return Integer[]\n */\n function findOrder($numCourses, $prerequisites) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findOrder(numCourses: number, prerequisites: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-order numCourses prerequisites)\n (-> exact-integer? (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0210](https://leetcode-cn.com/problems/course-schedule-ii)", "[\u8bfe\u7a0b\u8868 II](/solution/0200-0299/0210.Course%20Schedule%20II/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u56fe`,`\u62d3\u6251\u6392\u5e8f`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0210](https://leetcode.com/problems/course-schedule-ii)", "[Course Schedule II](/solution/0200-0299/0210.Course%20Schedule%20II/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`,`Graph`,`Topological Sort`", "Medium", ""]}, {"question_id": "0209", "frontend_question_id": "0209", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-size-subarray-sum", "url_en": "https://leetcode.com/problems/minimum-size-subarray-sum", "relative_path_cn": "/solution/0200-0299/0209.Minimum%20Size%20Subarray%20Sum/README.md", "relative_path_en": "/solution/0200-0299/0209.Minimum%20Size%20Subarray%20Sum/README_EN.md", "title_cn": "\u957f\u5ea6\u6700\u5c0f\u7684\u5b50\u6570\u7ec4", "title_en": "Minimum Size Subarray Sum", "question_title_slug": "minimum-size-subarray-sum", "content_en": "

    Given an array of positive integers nums and a positive integer target, return the minimal length of a contiguous subarray [numsl, numsl+1, ..., numsr-1, numsr] of which the sum is greater than or equal to target. If there is no such subarray, return 0 instead.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: target = 7, nums = [2,3,1,2,4,3]\nOutput: 2\nExplanation: The subarray [4,3] has the minimal length under the problem constraint.\n
    \n\n

    Example 2:

    \n\n
    \nInput: target = 4, nums = [1,4,4]\nOutput: 1\n
    \n\n

    Example 3:

    \n\n
    \nInput: target = 11, nums = [1,1,1,1,1,1,1,1]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= target <= 109
    • \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • 1 <= nums[i] <= 105
    • \n
    \n\n

     

    \nFollow up: If you have figured out the O(n) solution, try coding another solution of which the time complexity is O(n log(n)).", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u542b\u6709\u00a0n\u00a0\u4e2a\u6b63\u6574\u6570\u7684\u6570\u7ec4\u548c\u4e00\u4e2a\u6b63\u6574\u6570 target \u3002

    \n\n

    \u627e\u51fa\u8be5\u6570\u7ec4\u4e2d\u6ee1\u8db3\u5176\u548c \u2265 target \u7684\u957f\u5ea6\u6700\u5c0f\u7684 \u8fde\u7eed\u5b50\u6570\u7ec4\u00a0[numsl, numsl+1, ..., numsr-1, numsr] \uff0c\u5e76\u8fd4\u56de\u5176\u957f\u5ea6\u3002\u5982\u679c\u4e0d\u5b58\u5728\u7b26\u5408\u6761\u4ef6\u7684\u5b50\u6570\u7ec4\uff0c\u8fd4\u56de 0 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1atarget = 7, nums = [2,3,1,2,4,3]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5b50\u6570\u7ec4\u00a0[4,3]\u00a0\u662f\u8be5\u6761\u4ef6\u4e0b\u7684\u957f\u5ea6\u6700\u5c0f\u7684\u5b50\u6570\u7ec4\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1atarget = 4, nums = [1,4,4]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1atarget = 11, nums = [1,1,1,1,1,1,1,1]\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= target <= 109
    • \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • 1 <= nums[i] <= 105
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u5982\u679c\u4f60\u5df2\u7ecf\u5b9e\u73b0 O(n) \u65f6\u95f4\u590d\u6742\u5ea6\u7684\u89e3\u6cd5, \u8bf7\u5c1d\u8bd5\u8bbe\u8ba1\u4e00\u4e2a O(n log(n)) \u65f6\u95f4\u590d\u6742\u5ea6\u7684\u89e3\u6cd5\u3002
    • \n
    \n", "tags_en": ["Array", "Two Pointers", "Binary Search"], "tags_cn": ["\u6570\u7ec4", "\u53cc\u6307\u9488", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minSubArrayLen(int target, vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minSubArrayLen(int target, int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minSubArrayLen(self, target, nums):\n \"\"\"\n :type target: int\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minSubArrayLen(self, target: int, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minSubArrayLen(int target, int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinSubArrayLen(int target, int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} target\n * @param {number[]} nums\n * @return {number}\n */\nvar minSubArrayLen = function(target, nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} target\n# @param {Integer[]} nums\n# @return {Integer}\ndef min_sub_array_len(target, nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minSubArrayLen(_ target: Int, _ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minSubArrayLen(target int, nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minSubArrayLen(target: Int, nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minSubArrayLen(target: Int, nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_sub_array_len(target: i32, nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $target\n * @param Integer[] $nums\n * @return Integer\n */\n function minSubArrayLen($target, $nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minSubArrayLen(target: number, nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-sub-array-len target nums)\n (-> exact-integer? (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0209](https://leetcode-cn.com/problems/minimum-size-subarray-sum)", "[\u957f\u5ea6\u6700\u5c0f\u7684\u5b50\u6570\u7ec4](/solution/0200-0299/0209.Minimum%20Size%20Subarray%20Sum/README.md)", "`\u6570\u7ec4`,`\u53cc\u6307\u9488`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0209](https://leetcode.com/problems/minimum-size-subarray-sum)", "[Minimum Size Subarray Sum](/solution/0200-0299/0209.Minimum%20Size%20Subarray%20Sum/README_EN.md)", "`Array`,`Two Pointers`,`Binary Search`", "Medium", ""]}, {"question_id": "0208", "frontend_question_id": "0208", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/implement-trie-prefix-tree", "url_en": "https://leetcode.com/problems/implement-trie-prefix-tree", "relative_path_cn": "/solution/0200-0299/0208.Implement%20Trie%20%28Prefix%20Tree%29/README.md", "relative_path_en": "/solution/0200-0299/0208.Implement%20Trie%20%28Prefix%20Tree%29/README_EN.md", "title_cn": "\u5b9e\u73b0 Trie (\u524d\u7f00\u6811)", "title_en": "Implement Trie (Prefix Tree)", "question_title_slug": "implement-trie-prefix-tree", "content_en": "

    A trie (pronounced as "try") or prefix tree is a tree data structure used to efficiently store and retrieve keys in a dataset of strings. There are various applications of this data structure, such as autocomplete and spellchecker.

    \n\n

    Implement the Trie class:

    \n\n
      \n\t
    • Trie() Initializes the trie object.
    • \n\t
    • void insert(String word) Inserts the string word into the trie.
    • \n\t
    • boolean search(String word) Returns true if the string word is in the trie (i.e., was inserted before), and false otherwise.
    • \n\t
    • boolean startsWith(String prefix) Returns true if there is a previously inserted string word that has the prefix prefix, and false otherwise.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["Trie", "insert", "search", "search", "startsWith", "insert", "search"]\n[[], ["apple"], ["apple"], ["app"], ["app"], ["app"], ["app"]]\nOutput\n[null, null, true, false, true, null, true]\n\nExplanation\nTrie trie = new Trie();\ntrie.insert("apple");\ntrie.search("apple");   // return True\ntrie.search("app");     // return False\ntrie.startsWith("app"); // return True\ntrie.insert("app");\ntrie.search("app");     // return True\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= word.length, prefix.length <= 2000
    • \n\t
    • word and prefix consist only of lowercase English letters.
    • \n\t
    • At most 3 * 104 calls in total will be made to insert, search, and startsWith.
    • \n
    \n", "content_cn": "

    Trie\uff08\u53d1\u97f3\u7c7b\u4f3c \"try\"\uff09\u6216\u8005\u8bf4 \u524d\u7f00\u6811 \u662f\u4e00\u79cd\u6811\u5f62\u6570\u636e\u7ed3\u6784\uff0c\u7528\u4e8e\u9ad8\u6548\u5730\u5b58\u50a8\u548c\u68c0\u7d22\u5b57\u7b26\u4e32\u6570\u636e\u96c6\u4e2d\u7684\u952e\u3002\u8fd9\u4e00\u6570\u636e\u7ed3\u6784\u6709\u76f8\u5f53\u591a\u7684\u5e94\u7528\u60c5\u666f\uff0c\u4f8b\u5982\u81ea\u52a8\u8865\u5b8c\u548c\u62fc\u5199\u68c0\u67e5\u3002

    \n\n

    \u8bf7\u4f60\u5b9e\u73b0 Trie \u7c7b\uff1a

    \n\n
      \n\t
    • Trie() \u521d\u59cb\u5316\u524d\u7f00\u6811\u5bf9\u8c61\u3002
    • \n\t
    • void insert(String word) \u5411\u524d\u7f00\u6811\u4e2d\u63d2\u5165\u5b57\u7b26\u4e32 word \u3002
    • \n\t
    • boolean search(String word) \u5982\u679c\u5b57\u7b26\u4e32 word \u5728\u524d\u7f00\u6811\u4e2d\uff0c\u8fd4\u56de true\uff08\u5373\uff0c\u5728\u68c0\u7d22\u4e4b\u524d\u5df2\u7ecf\u63d2\u5165\uff09\uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002
    • \n\t
    • boolean startsWith(String prefix) \u5982\u679c\u4e4b\u524d\u5df2\u7ecf\u63d2\u5165\u7684\u5b57\u7b26\u4e32\u00a0word \u7684\u524d\u7f00\u4e4b\u4e00\u4e3a prefix \uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\n[\"Trie\", \"insert\", \"search\", \"search\", \"startsWith\", \"insert\", \"search\"]\n[[], [\"apple\"], [\"apple\"], [\"app\"], [\"app\"], [\"app\"], [\"app\"]]\n\u8f93\u51fa\n[null, null, true, false, true, null, true]\n\n\u89e3\u91ca\nTrie trie = new Trie();\ntrie.insert(\"apple\");\ntrie.search(\"apple\");   // \u8fd4\u56de True\ntrie.search(\"app\");     // \u8fd4\u56de False\ntrie.startsWith(\"app\"); // \u8fd4\u56de True\ntrie.insert(\"app\");\ntrie.search(\"app\");     // \u8fd4\u56de True\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= word.length, prefix.length <= 2000
    • \n\t
    • word \u548c prefix \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n\t
    • insert\u3001search \u548c startsWith \u8c03\u7528\u6b21\u6570 \u603b\u8ba1 \u4e0d\u8d85\u8fc7 3 * 104 \u6b21
    • \n
    \n", "tags_en": ["Design", "Trie"], "tags_cn": ["\u8bbe\u8ba1", "\u5b57\u5178\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Trie {\npublic:\n /** Initialize your data structure here. */\n Trie() {\n\n }\n \n /** Inserts a word into the trie. */\n void insert(string word) {\n\n }\n \n /** Returns if the word is in the trie. */\n bool search(string word) {\n\n }\n \n /** Returns if there is any word in the trie that starts with the given prefix. */\n bool startsWith(string prefix) {\n\n }\n};\n\n/**\n * Your Trie object will be instantiated and called as such:\n * Trie* obj = new Trie();\n * obj->insert(word);\n * bool param_2 = obj->search(word);\n * bool param_3 = obj->startsWith(prefix);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Trie {\n\n /** Initialize your data structure here. */\n public Trie() {\n\n }\n \n /** Inserts a word into the trie. */\n public void insert(String word) {\n\n }\n \n /** Returns if the word is in the trie. */\n public boolean search(String word) {\n\n }\n \n /** Returns if there is any word in the trie that starts with the given prefix. */\n public boolean startsWith(String prefix) {\n\n }\n}\n\n/**\n * Your Trie object will be instantiated and called as such:\n * Trie obj = new Trie();\n * obj.insert(word);\n * boolean param_2 = obj.search(word);\n * boolean param_3 = obj.startsWith(prefix);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Trie(object):\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def insert(self, word):\n \"\"\"\n Inserts a word into the trie.\n :type word: str\n :rtype: None\n \"\"\"\n\n\n def search(self, word):\n \"\"\"\n Returns if the word is in the trie.\n :type word: str\n :rtype: bool\n \"\"\"\n\n\n def startsWith(self, prefix):\n \"\"\"\n Returns if there is any word in the trie that starts with the given prefix.\n :type prefix: str\n :rtype: bool\n \"\"\"\n\n\n\n# Your Trie object will be instantiated and called as such:\n# obj = Trie()\n# obj.insert(word)\n# param_2 = obj.search(word)\n# param_3 = obj.startsWith(prefix)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Trie:\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def insert(self, word: str) -> None:\n \"\"\"\n Inserts a word into the trie.\n \"\"\"\n\n\n def search(self, word: str) -> bool:\n \"\"\"\n Returns if the word is in the trie.\n \"\"\"\n\n\n def startsWith(self, prefix: str) -> bool:\n \"\"\"\n Returns if there is any word in the trie that starts with the given prefix.\n \"\"\"\n\n\n\n# Your Trie object will be instantiated and called as such:\n# obj = Trie()\n# obj.insert(word)\n# param_2 = obj.search(word)\n# param_3 = obj.startsWith(prefix)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n \n} Trie;\n\n/** Initialize your data structure here. */\n\nTrie* trieCreate() {\n \n}\n\n/** Inserts a word into the trie. */\nvoid trieInsert(Trie* obj, char * word) {\n \n}\n\n/** Returns if the word is in the trie. */\nbool trieSearch(Trie* obj, char * word) {\n \n}\n\n/** Returns if there is any word in the trie that starts with the given prefix. */\nbool trieStartsWith(Trie* obj, char * prefix) {\n \n}\n\nvoid trieFree(Trie* obj) {\n \n}\n\n/**\n * Your Trie struct will be instantiated and called as such:\n * Trie* obj = trieCreate();\n * trieInsert(obj, word);\n \n * bool param_2 = trieSearch(obj, word);\n \n * bool param_3 = trieStartsWith(obj, prefix);\n \n * trieFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Trie {\n\n /** Initialize your data structure here. */\n public Trie() {\n\n }\n \n /** Inserts a word into the trie. */\n public void Insert(string word) {\n\n }\n \n /** Returns if the word is in the trie. */\n public bool Search(string word) {\n\n }\n \n /** Returns if there is any word in the trie that starts with the given prefix. */\n public bool StartsWith(string prefix) {\n\n }\n}\n\n/**\n * Your Trie object will be instantiated and called as such:\n * Trie obj = new Trie();\n * obj.Insert(word);\n * bool param_2 = obj.Search(word);\n * bool param_3 = obj.StartsWith(prefix);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Initialize your data structure here.\n */\nvar Trie = function() {\n\n};\n\n/**\n * Inserts a word into the trie. \n * @param {string} word\n * @return {void}\n */\nTrie.prototype.insert = function(word) {\n\n};\n\n/**\n * Returns if the word is in the trie. \n * @param {string} word\n * @return {boolean}\n */\nTrie.prototype.search = function(word) {\n\n};\n\n/**\n * Returns if there is any word in the trie that starts with the given prefix. \n * @param {string} prefix\n * @return {boolean}\n */\nTrie.prototype.startsWith = function(prefix) {\n\n};\n\n/**\n * Your Trie object will be instantiated and called as such:\n * var obj = new Trie()\n * obj.insert(word)\n * var param_2 = obj.search(word)\n * var param_3 = obj.startsWith(prefix)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class Trie\n\n=begin\n Initialize your data structure here.\n=end\n def initialize()\n\n end\n\n\n=begin\n Inserts a word into the trie.\n :type word: String\n :rtype: Void\n=end\n def insert(word)\n\n end\n\n\n=begin\n Returns if the word is in the trie.\n :type word: String\n :rtype: Boolean\n=end\n def search(word)\n\n end\n\n\n=begin\n Returns if there is any word in the trie that starts with the given prefix.\n :type prefix: String\n :rtype: Boolean\n=end\n def starts_with(prefix)\n\n end\n\n\nend\n\n# Your Trie object will be instantiated and called as such:\n# obj = Trie.new()\n# obj.insert(word)\n# param_2 = obj.search(word)\n# param_3 = obj.starts_with(prefix)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass Trie {\n\n /** Initialize your data structure here. */\n init() {\n\n }\n \n /** Inserts a word into the trie. */\n func insert(_ word: String) {\n\n }\n \n /** Returns if the word is in the trie. */\n func search(_ word: String) -> Bool {\n\n }\n \n /** Returns if there is any word in the trie that starts with the given prefix. */\n func startsWith(_ prefix: String) -> Bool {\n\n }\n}\n\n/**\n * Your Trie object will be instantiated and called as such:\n * let obj = Trie()\n * obj.insert(word)\n * let ret_2: Bool = obj.search(word)\n * let ret_3: Bool = obj.startsWith(prefix)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type Trie struct {\n\n}\n\n\n/** Initialize your data structure here. */\nfunc Constructor() Trie {\n\n}\n\n\n/** Inserts a word into the trie. */\nfunc (this *Trie) Insert(word string) {\n\n}\n\n\n/** Returns if the word is in the trie. */\nfunc (this *Trie) Search(word string) bool {\n\n}\n\n\n/** Returns if there is any word in the trie that starts with the given prefix. */\nfunc (this *Trie) StartsWith(prefix string) bool {\n\n}\n\n\n/**\n * Your Trie object will be instantiated and called as such:\n * obj := Constructor();\n * obj.Insert(word);\n * param_2 := obj.Search(word);\n * param_3 := obj.StartsWith(prefix);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class Trie() {\n\n /** Initialize your data structure here. */\n\n\n /** Inserts a word into the trie. */\n def insert(word: String) {\n\n }\n\n /** Returns if the word is in the trie. */\n def search(word: String): Boolean = {\n\n }\n\n /** Returns if there is any word in the trie that starts with the given prefix. */\n def startsWith(prefix: String): Boolean = {\n\n }\n\n}\n\n/**\n * Your Trie object will be instantiated and called as such:\n * var obj = new Trie()\n * obj.insert(word)\n * var param_2 = obj.search(word)\n * var param_3 = obj.startsWith(prefix)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Trie() {\n\n /** Initialize your data structure here. */\n\n\n /** Inserts a word into the trie. */\n fun insert(word: String) {\n\n }\n\n /** Returns if the word is in the trie. */\n fun search(word: String): Boolean {\n\n }\n\n /** Returns if there is any word in the trie that starts with the given prefix. */\n fun startsWith(prefix: String): Boolean {\n\n }\n\n}\n\n/**\n * Your Trie object will be instantiated and called as such:\n * var obj = Trie()\n * obj.insert(word)\n * var param_2 = obj.search(word)\n * var param_3 = obj.startsWith(prefix)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct Trie {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl Trie {\n\n /** Initialize your data structure here. */\n fn new() -> Self {\n\n }\n \n /** Inserts a word into the trie. */\n fn insert(&self, word: String) {\n\n }\n \n /** Returns if the word is in the trie. */\n fn search(&self, word: String) -> bool {\n\n }\n \n /** Returns if there is any word in the trie that starts with the given prefix. */\n fn starts_with(&self, prefix: String) -> bool {\n\n }\n}\n\n/**\n * Your Trie object will be instantiated and called as such:\n * let obj = Trie::new();\n * obj.insert(word);\n * let ret_2: bool = obj.search(word);\n * let ret_3: bool = obj.starts_with(prefix);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Trie {\n /**\n * Initialize your data structure here.\n */\n function __construct() {\n\n }\n\n /**\n * Inserts a word into the trie.\n * @param String $word\n * @return NULL\n */\n function insert($word) {\n\n }\n\n /**\n * Returns if the word is in the trie.\n * @param String $word\n * @return Boolean\n */\n function search($word) {\n\n }\n\n /**\n * Returns if there is any word in the trie that starts with the given prefix.\n * @param String $prefix\n * @return Boolean\n */\n function startsWith($prefix) {\n\n }\n}\n\n/**\n * Your Trie object will be instantiated and called as such:\n * $obj = Trie();\n * $obj->insert($word);\n * $ret_2 = $obj->search($word);\n * $ret_3 = $obj->startsWith($prefix);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class Trie {\n constructor() {\n\n }\n\n insert(word: string): void {\n\n }\n\n search(word: string): boolean {\n\n }\n\n startsWith(prefix: string): boolean {\n\n }\n}\n\n/**\n * Your Trie object will be instantiated and called as such:\n * var obj = new Trie()\n * obj.insert(word)\n * var param_2 = obj.search(word)\n * var param_3 = obj.startsWith(prefix)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define trie%\n (class object%\n (super-new)\n (init-field)\n \n ; insert : string? -> void?\n (define/public (insert word)\n\n )\n ; search : string? -> boolean?\n (define/public (search word)\n\n )\n ; starts-with : string? -> boolean?\n (define/public (starts-with prefix)\n\n )))\n\n;; Your trie% object will be instantiated and called as such:\n;; (define obj (new trie%))\n;; (send obj insert word)\n;; (define param_2 (send obj search word))\n;; (define param_3 (send obj starts-with prefix))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0208](https://leetcode-cn.com/problems/implement-trie-prefix-tree)", "[\u5b9e\u73b0 Trie (\u524d\u7f00\u6811)](/solution/0200-0299/0208.Implement%20Trie%20%28Prefix%20Tree%29/README.md)", "`\u8bbe\u8ba1`,`\u5b57\u5178\u6811`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0208](https://leetcode.com/problems/implement-trie-prefix-tree)", "[Implement Trie (Prefix Tree)](/solution/0200-0299/0208.Implement%20Trie%20%28Prefix%20Tree%29/README_EN.md)", "`Design`,`Trie`", "Medium", ""]}, {"question_id": "0207", "frontend_question_id": "0207", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/course-schedule", "url_en": "https://leetcode.com/problems/course-schedule", "relative_path_cn": "/solution/0200-0299/0207.Course%20Schedule/README.md", "relative_path_en": "/solution/0200-0299/0207.Course%20Schedule/README_EN.md", "title_cn": "\u8bfe\u7a0b\u8868", "title_en": "Course Schedule", "question_title_slug": "course-schedule", "content_en": "

    There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i] = [ai, bi] indicates that you must take course bi first if you want to take course ai.

    \n\n
      \n\t
    • For example, the pair [0, 1], indicates that to take course 0 you have to first take course 1.
    • \n
    \n\n

    Return true if you can finish all courses. Otherwise, return false.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: numCourses = 2, prerequisites = [[1,0]]\nOutput: true\nExplanation: There are a total of 2 courses to take. \nTo take course 1 you should have finished course 0. So it is possible.\n
    \n\n

    Example 2:

    \n\n
    \nInput: numCourses = 2, prerequisites = [[1,0],[0,1]]\nOutput: false\nExplanation: There are a total of 2 courses to take. \nTo take course 1 you should have finished course 0, and to take course 0 you should also have finished course 1. So it is impossible.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= numCourses <= 105
    • \n\t
    • 0 <= prerequisites.length <= 5000
    • \n\t
    • prerequisites[i].length == 2
    • \n\t
    • 0 <= ai, bi < numCourses
    • \n\t
    • All the pairs prerequisites[i] are unique.
    • \n
    \n", "content_cn": "

    \u4f60\u8fd9\u4e2a\u5b66\u671f\u5fc5\u987b\u9009\u4fee numCourses \u95e8\u8bfe\u7a0b\uff0c\u8bb0\u4e3a\u00a00\u00a0\u5230\u00a0numCourses - 1 \u3002

    \n\n

    \u5728\u9009\u4fee\u67d0\u4e9b\u8bfe\u7a0b\u4e4b\u524d\u9700\u8981\u4e00\u4e9b\u5148\u4fee\u8bfe\u7a0b\u3002 \u5148\u4fee\u8bfe\u7a0b\u6309\u6570\u7ec4\u00a0prerequisites \u7ed9\u51fa\uff0c\u5176\u4e2d\u00a0prerequisites[i] = [ai, bi] \uff0c\u8868\u793a\u5982\u679c\u8981\u5b66\u4e60\u8bfe\u7a0b\u00a0ai \u5219 \u5fc5\u987b \u5148\u5b66\u4e60\u8bfe\u7a0b\u00a0 bi \u3002

    \n\n
      \n\t
    • \u4f8b\u5982\uff0c\u5148\u4fee\u8bfe\u7a0b\u5bf9\u00a0[0, 1] \u8868\u793a\uff1a\u60f3\u8981\u5b66\u4e60\u8bfe\u7a0b 0 \uff0c\u4f60\u9700\u8981\u5148\u5b8c\u6210\u8bfe\u7a0b 1 \u3002
    • \n
    \n\n

    \u8bf7\u4f60\u5224\u65ad\u662f\u5426\u53ef\u80fd\u5b8c\u6210\u6240\u6709\u8bfe\u7a0b\u7684\u5b66\u4e60\uff1f\u5982\u679c\u53ef\u4ee5\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anumCourses = 2, prerequisites = [[1,0]]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u603b\u5171\u6709 2 \u95e8\u8bfe\u7a0b\u3002\u5b66\u4e60\u8bfe\u7a0b 1 \u4e4b\u524d\uff0c\u4f60\u9700\u8981\u5b8c\u6210\u8bfe\u7a0b 0 \u3002\u8fd9\u662f\u53ef\u80fd\u7684\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anumCourses = 2, prerequisites = [[1,0],[0,1]]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u603b\u5171\u6709 2 \u95e8\u8bfe\u7a0b\u3002\u5b66\u4e60\u8bfe\u7a0b 1 \u4e4b\u524d\uff0c\u4f60\u9700\u8981\u5148\u5b8c\u6210\u200b\u8bfe\u7a0b 0 \uff1b\u5e76\u4e14\u5b66\u4e60\u8bfe\u7a0b 0 \u4e4b\u524d\uff0c\u4f60\u8fd8\u5e94\u5148\u5b8c\u6210\u8bfe\u7a0b 1 \u3002\u8fd9\u662f\u4e0d\u53ef\u80fd\u7684\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= numCourses <= 105
    • \n\t
    • 0 <= prerequisites.length <= 5000
    • \n\t
    • prerequisites[i].length == 2
    • \n\t
    • 0 <= ai, bi < numCourses
    • \n\t
    • prerequisites[i] \u4e2d\u7684\u6240\u6709\u8bfe\u7a0b\u5bf9 \u4e92\u4e0d\u76f8\u540c
    • \n
    \n", "tags_en": ["Depth-first Search", "Breadth-first Search", "Graph", "Topological Sort"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u56fe", "\u62d3\u6251\u6392\u5e8f"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canFinish(int numCourses, vector>& prerequisites) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canFinish(int numCourses, int[][] prerequisites) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canFinish(self, numCourses, prerequisites):\n \"\"\"\n :type numCourses: int\n :type prerequisites: List[List[int]]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canFinish(self, numCourses: int, prerequisites: List[List[int]]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canFinish(int numCourses, int** prerequisites, int prerequisitesSize, int* prerequisitesColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanFinish(int numCourses, int[][] prerequisites) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} numCourses\n * @param {number[][]} prerequisites\n * @return {boolean}\n */\nvar canFinish = function(numCourses, prerequisites) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} num_courses\n# @param {Integer[][]} prerequisites\n# @return {Boolean}\ndef can_finish(num_courses, prerequisites)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canFinish(_ numCourses: Int, _ prerequisites: [[Int]]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canFinish(numCourses int, prerequisites [][]int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canFinish(numCourses: Int, prerequisites: Array[Array[Int]]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canFinish(numCourses: Int, prerequisites: Array): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_finish(num_courses: i32, prerequisites: Vec>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $numCourses\n * @param Integer[][] $prerequisites\n * @return Boolean\n */\n function canFinish($numCourses, $prerequisites) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canFinish(numCourses: number, prerequisites: number[][]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-finish numCourses prerequisites)\n (-> exact-integer? (listof (listof exact-integer?)) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0207](https://leetcode-cn.com/problems/course-schedule)", "[\u8bfe\u7a0b\u8868](/solution/0200-0299/0207.Course%20Schedule/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u56fe`,`\u62d3\u6251\u6392\u5e8f`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0207](https://leetcode.com/problems/course-schedule)", "[Course Schedule](/solution/0200-0299/0207.Course%20Schedule/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`,`Graph`,`Topological Sort`", "Medium", ""]}, {"question_id": "0206", "frontend_question_id": "0206", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reverse-linked-list", "url_en": "https://leetcode.com/problems/reverse-linked-list", "relative_path_cn": "/solution/0200-0299/0206.Reverse%20Linked%20List/README.md", "relative_path_en": "/solution/0200-0299/0206.Reverse%20Linked%20List/README_EN.md", "title_cn": "\u53cd\u8f6c\u94fe\u8868", "title_en": "Reverse Linked List", "question_title_slug": "reverse-linked-list", "content_en": "

    Given the head of a singly linked list, reverse the list, and return the reversed list.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: head = [1,2,3,4,5]\nOutput: [5,4,3,2,1]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: head = [1,2]\nOutput: [2,1]\n
    \n\n

    Example 3:

    \n\n
    \nInput: head = []\nOutput: []\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the list is the range [0, 5000].
    • \n\t
    • -5000 <= Node.val <= 5000
    • \n
    \n\n

     

    \n

    Follow up: A linked list can be reversed either iteratively or recursively. Could you implement both?

    \n", "content_cn": "\u7ed9\u4f60\u5355\u94fe\u8868\u7684\u5934\u8282\u70b9 head \uff0c\u8bf7\u4f60\u53cd\u8f6c\u94fe\u8868\uff0c\u5e76\u8fd4\u56de\u53cd\u8f6c\u540e\u7684\u94fe\u8868\u3002\n
    \n
    \n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1ahead = [1,2,3,4,5]\n\u8f93\u51fa\uff1a[5,4,3,2,1]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1ahead = [1,2]\n\u8f93\u51fa\uff1a[2,1]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahead = []\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u94fe\u8868\u4e2d\u8282\u70b9\u7684\u6570\u76ee\u8303\u56f4\u662f [0, 5000]
    • \n\t
    • -5000 <= Node.val <= 5000
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u94fe\u8868\u53ef\u4ee5\u9009\u7528\u8fed\u4ee3\u6216\u9012\u5f52\u65b9\u5f0f\u5b8c\u6210\u53cd\u8f6c\u3002\u4f60\u80fd\u5426\u7528\u4e24\u79cd\u65b9\u6cd5\u89e3\u51b3\u8fd9\u9053\u9898\uff1f

    \n
    \n
    \n", "tags_en": ["Linked List"], "tags_cn": ["\u94fe\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n ListNode* reverseList(ListNode* head) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public ListNode reverseList(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def reverseList(self, head):\n \"\"\"\n :type head: ListNode\n :rtype: ListNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def reverseList(self, head: ListNode) -> ListNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nstruct ListNode* reverseList(struct ListNode* head){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public ListNode ReverseList(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} head\n * @return {ListNode}\n */\nvar reverseList = function(head) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode} head\n# @return {ListNode}\ndef reverse_list(head)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func reverseList(_ head: ListNode?) -> ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc reverseList(head *ListNode) *ListNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def reverseList(head: ListNode): ListNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun reverseList(head: ListNode?): ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn reverse_list(head: Option>) -> Option> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @return ListNode\n */\n function reverseList($head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction reverseList(head: ListNode | null): ListNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (reverse-list head)\n (-> (or/c list-node? #f) (or/c list-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0206](https://leetcode-cn.com/problems/reverse-linked-list)", "[\u53cd\u8f6c\u94fe\u8868](/solution/0200-0299/0206.Reverse%20Linked%20List/README.md)", "`\u94fe\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0206](https://leetcode.com/problems/reverse-linked-list)", "[Reverse Linked List](/solution/0200-0299/0206.Reverse%20Linked%20List/README_EN.md)", "`Linked List`", "Easy", ""]}, {"question_id": "0205", "frontend_question_id": "0205", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/isomorphic-strings", "url_en": "https://leetcode.com/problems/isomorphic-strings", "relative_path_cn": "/solution/0200-0299/0205.Isomorphic%20Strings/README.md", "relative_path_en": "/solution/0200-0299/0205.Isomorphic%20Strings/README_EN.md", "title_cn": "\u540c\u6784\u5b57\u7b26\u4e32", "title_en": "Isomorphic Strings", "question_title_slug": "isomorphic-strings", "content_en": "

    Given two strings s and t, determine if they are isomorphic.

    \n\n

    Two strings s and t are isomorphic if the characters in s can be replaced to get t.

    \n\n

    All occurrences of a character must be replaced with another character while preserving the order of characters. No two characters may map to the same character, but a character may map to itself.

    \n\n

     

    \n

    Example 1:

    \n
    Input: s = \"egg\", t = \"add\"\nOutput: true\n

    Example 2:

    \n
    Input: s = \"foo\", t = \"bar\"\nOutput: false\n

    Example 3:

    \n
    Input: s = \"paper\", t = \"title\"\nOutput: true\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 5 * 104
    • \n\t
    • t.length == s.length
    • \n\t
    • s and t consist of any valid ascii character.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u5b57\u7b26\u4e32\u00a0s\u00a0\u548c\u00a0t\uff0c\u5224\u65ad\u5b83\u4eec\u662f\u5426\u662f\u540c\u6784\u7684\u3002

    \n\n

    \u5982\u679c\u00a0s\u00a0\u4e2d\u7684\u5b57\u7b26\u53ef\u4ee5\u6309\u67d0\u79cd\u6620\u5c04\u5173\u7cfb\u66ff\u6362\u5f97\u5230\u00a0t\u00a0\uff0c\u90a3\u4e48\u8fd9\u4e24\u4e2a\u5b57\u7b26\u4e32\u662f\u540c\u6784\u7684\u3002

    \n\n

    \u6bcf\u4e2a\u51fa\u73b0\u7684\u5b57\u7b26\u90fd\u5e94\u5f53\u6620\u5c04\u5230\u53e6\u4e00\u4e2a\u5b57\u7b26\uff0c\u540c\u65f6\u4e0d\u6539\u53d8\u5b57\u7b26\u7684\u987a\u5e8f\u3002\u4e0d\u540c\u5b57\u7b26\u4e0d\u80fd\u6620\u5c04\u5230\u540c\u4e00\u4e2a\u5b57\u7b26\u4e0a\uff0c\u76f8\u540c\u5b57\u7b26\u53ea\u80fd\u6620\u5c04\u5230\u540c\u4e00\u4e2a\u5b57\u7b26\u4e0a\uff0c\u5b57\u7b26\u53ef\u4ee5\u6620\u5c04\u5230\u81ea\u5df1\u672c\u8eab\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165\uff1as = \"egg\", t = \"add\"\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"foo\", t = \"bar\"\n\u8f93\u51fa\uff1afalse
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"paper\", t = \"title\"\n\u8f93\u51fa\uff1atrue
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u53ef\u4ee5\u5047\u8bbe\u00a0s\u00a0\u548c t \u957f\u5ea6\u76f8\u540c\u3002
    • \n
    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isIsomorphic(string s, string t) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isIsomorphic(String s, String t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isIsomorphic(self, s, t):\n \"\"\"\n :type s: str\n :type t: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isIsomorphic(self, s: str, t: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isIsomorphic(char * s, char * t){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsIsomorphic(string s, string t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string} t\n * @return {boolean}\n */\nvar isIsomorphic = function(s, t) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String} t\n# @return {Boolean}\ndef is_isomorphic(s, t)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isIsomorphic(_ s: String, _ t: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isIsomorphic(s string, t string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isIsomorphic(s: String, t: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isIsomorphic(s: String, t: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_isomorphic(s: String, t: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String $t\n * @return Boolean\n */\n function isIsomorphic($s, $t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isIsomorphic(s: string, t: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-isomorphic s t)\n (-> string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0205](https://leetcode-cn.com/problems/isomorphic-strings)", "[\u540c\u6784\u5b57\u7b26\u4e32](/solution/0200-0299/0205.Isomorphic%20Strings/README.md)", "`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0205](https://leetcode.com/problems/isomorphic-strings)", "[Isomorphic Strings](/solution/0200-0299/0205.Isomorphic%20Strings/README_EN.md)", "`Hash Table`", "Easy", ""]}, {"question_id": "0204", "frontend_question_id": "0204", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-primes", "url_en": "https://leetcode.com/problems/count-primes", "relative_path_cn": "/solution/0200-0299/0204.Count%20Primes/README.md", "relative_path_en": "/solution/0200-0299/0204.Count%20Primes/README_EN.md", "title_cn": "\u8ba1\u6570\u8d28\u6570", "title_en": "Count Primes", "question_title_slug": "count-primes", "content_en": "

    Count the number of prime numbers less than a non-negative number, n.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 10\nOutput: 4\nExplanation: There are 4 prime numbers less than 10, they are 2, 3, 5, 7.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 0\nOutput: 0\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 1\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= n <= 5 * 106
    • \n
    \n", "content_cn": "

    \u7edf\u8ba1\u6240\u6709\u5c0f\u4e8e\u975e\u8d1f\u6574\u6570 n \u7684\u8d28\u6570\u7684\u6570\u91cf\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1an = 10\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u5c0f\u4e8e 10 \u7684\u8d28\u6570\u4e00\u5171\u6709 4 \u4e2a, \u5b83\u4eec\u662f 2, 3, 5, 7 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1an = 0\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1a0\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= n <= 5 * 106
    • \n
    \n", "tags_en": ["Hash Table", "Math"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int countPrimes(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int countPrimes(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countPrimes(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countPrimes(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint countPrimes(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CountPrimes(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar countPrimes = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef count_primes(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countPrimes(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countPrimes(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countPrimes(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countPrimes(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_primes(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function countPrimes($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countPrimes(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-primes n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0204](https://leetcode-cn.com/problems/count-primes)", "[\u8ba1\u6570\u8d28\u6570](/solution/0200-0299/0204.Count%20Primes/README.md)", "`\u54c8\u5e0c\u8868`,`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0204](https://leetcode.com/problems/count-primes)", "[Count Primes](/solution/0200-0299/0204.Count%20Primes/README_EN.md)", "`Hash Table`,`Math`", "Easy", ""]}, {"question_id": "0203", "frontend_question_id": "0203", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/remove-linked-list-elements", "url_en": "https://leetcode.com/problems/remove-linked-list-elements", "relative_path_cn": "/solution/0200-0299/0203.Remove%20Linked%20List%20Elements/README.md", "relative_path_en": "/solution/0200-0299/0203.Remove%20Linked%20List%20Elements/README_EN.md", "title_cn": "\u79fb\u9664\u94fe\u8868\u5143\u7d20", "title_en": "Remove Linked List Elements", "question_title_slug": "remove-linked-list-elements", "content_en": "

    Given the head of a linked list and an integer val, remove all the nodes of the linked list that has Node.val == val, and return the new head.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: head = [1,2,6,3,4,5,6], val = 6\nOutput: [1,2,3,4,5]\n
    \n\n

    Example 2:

    \n\n
    \nInput: head = [], val = 1\nOutput: []\n
    \n\n

    Example 3:

    \n\n
    \nInput: head = [7,7,7,7], val = 7\nOutput: []\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the list is in the range [0, 104].
    • \n\t
    • 1 <= Node.val <= 50
    • \n\t
    • 0 <= k <= 50
    • \n
    \n", "content_cn": "\u7ed9\u4f60\u4e00\u4e2a\u94fe\u8868\u7684\u5934\u8282\u70b9 head \u548c\u4e00\u4e2a\u6574\u6570 val \uff0c\u8bf7\u4f60\u5220\u9664\u94fe\u8868\u4e2d\u6240\u6709\u6ee1\u8db3 Node.val == val \u7684\u8282\u70b9\uff0c\u5e76\u8fd4\u56de \u65b0\u7684\u5934\u8282\u70b9 \u3002\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1ahead = [1,2,6,3,4,5,6], val = 6\n\u8f93\u51fa\uff1a[1,2,3,4,5]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahead = [], val = 1\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahead = [7,7,7,7], val = 7\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u5217\u8868\u4e2d\u7684\u8282\u70b9\u5728\u8303\u56f4 [0, 104] \u5185
    • \n\t
    • 1 <= Node.val <= 50
    • \n\t
    • 0 <= k <= 50
    • \n
    \n", "tags_en": ["Linked List"], "tags_cn": ["\u94fe\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n ListNode* removeElements(ListNode* head, int val) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public ListNode removeElements(ListNode head, int val) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def removeElements(self, head, val):\n \"\"\"\n :type head: ListNode\n :type val: int\n :rtype: ListNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def removeElements(self, head: ListNode, val: int) -> ListNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nstruct ListNode* removeElements(struct ListNode* head, int val){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public ListNode RemoveElements(ListNode head, int val) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} head\n * @param {number} val\n * @return {ListNode}\n */\nvar removeElements = function(head, val) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode} head\n# @param {Integer} val\n# @return {ListNode}\ndef remove_elements(head, val)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func removeElements(_ head: ListNode?, _ val: Int) -> ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc removeElements(head *ListNode, val int) *ListNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def removeElements(head: ListNode, `val`: Int): ListNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun removeElements(head: ListNode?, `val`: Int): ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn remove_elements(head: Option>, val: i32) -> Option> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @param Integer $val\n * @return ListNode\n */\n function removeElements($head, $val) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction removeElements(head: ListNode | null, val: number): ListNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (remove-elements head val)\n (-> (or/c list-node? #f) exact-integer? (or/c list-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0203](https://leetcode-cn.com/problems/remove-linked-list-elements)", "[\u79fb\u9664\u94fe\u8868\u5143\u7d20](/solution/0200-0299/0203.Remove%20Linked%20List%20Elements/README.md)", "`\u94fe\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0203](https://leetcode.com/problems/remove-linked-list-elements)", "[Remove Linked List Elements](/solution/0200-0299/0203.Remove%20Linked%20List%20Elements/README_EN.md)", "`Linked List`", "Easy", ""]}, {"question_id": "0202", "frontend_question_id": "0202", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/happy-number", "url_en": "https://leetcode.com/problems/happy-number", "relative_path_cn": "/solution/0200-0299/0202.Happy%20Number/README.md", "relative_path_en": "/solution/0200-0299/0202.Happy%20Number/README_EN.md", "title_cn": "\u5feb\u4e50\u6570", "title_en": "Happy Number", "question_title_slug": "happy-number", "content_en": "

    Write an algorithm to determine if a number n is happy.

    \n\n

    A happy number is a number defined by the following process:

    \n\n
      \n\t
    • Starting with any positive integer, replace the number by the sum of the squares of its digits.
    • \n\t
    • Repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1.
    • \n\t
    • Those numbers for which this process ends in 1 are happy.
    • \n
    \n\n

    Return true if n is a happy number, and false if not.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 19\nOutput: true\nExplanation:\n12 + 92 = 82\n82 + 22 = 68\n62 + 82 = 100\n12 + 02 + 02 = 1\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 2\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 231 - 1
    • \n
    \n", "content_cn": "

    \u7f16\u5199\u4e00\u4e2a\u7b97\u6cd5\u6765\u5224\u65ad\u4e00\u4e2a\u6570 n \u662f\u4e0d\u662f\u5feb\u4e50\u6570\u3002

    \n\n

    \u300c\u5feb\u4e50\u6570\u300d\u5b9a\u4e49\u4e3a\uff1a

    \n\n
      \n\t
    • \u5bf9\u4e8e\u4e00\u4e2a\u6b63\u6574\u6570\uff0c\u6bcf\u4e00\u6b21\u5c06\u8be5\u6570\u66ff\u6362\u4e3a\u5b83\u6bcf\u4e2a\u4f4d\u7f6e\u4e0a\u7684\u6570\u5b57\u7684\u5e73\u65b9\u548c\u3002
    • \n\t
    • \u7136\u540e\u91cd\u590d\u8fd9\u4e2a\u8fc7\u7a0b\u76f4\u5230\u8fd9\u4e2a\u6570\u53d8\u4e3a 1\uff0c\u4e5f\u53ef\u80fd\u662f \u65e0\u9650\u5faa\u73af \u4f46\u59cb\u7ec8\u53d8\u4e0d\u5230 1\u3002
    • \n\t
    • \u5982\u679c \u53ef\u4ee5\u53d8\u4e3a\u00a0 1\uff0c\u90a3\u4e48\u8fd9\u4e2a\u6570\u5c31\u662f\u5feb\u4e50\u6570\u3002
    • \n
    \n\n

    \u5982\u679c n \u662f\u5feb\u4e50\u6570\u5c31\u8fd4\u56de true \uff1b\u4e0d\u662f\uff0c\u5219\u8fd4\u56de false \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1a19\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\n12 + 92 = 82\n82 + 22 = 68\n62 + 82 = 100\n12 + 02 + 02 = 1\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 2\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 231 - 1
    • \n
    \n", "tags_en": ["Hash Table", "Math"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isHappy(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isHappy(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isHappy(self, n):\n \"\"\"\n :type n: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isHappy(self, n: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isHappy(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsHappy(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {boolean}\n */\nvar isHappy = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Boolean}\ndef is_happy(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isHappy(_ n: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isHappy(n int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isHappy(n: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isHappy(n: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_happy(n: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Boolean\n */\n function isHappy($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isHappy(n: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-happy n)\n (-> exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0202](https://leetcode-cn.com/problems/happy-number)", "[\u5feb\u4e50\u6570](/solution/0200-0299/0202.Happy%20Number/README.md)", "`\u54c8\u5e0c\u8868`,`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0202](https://leetcode.com/problems/happy-number)", "[Happy Number](/solution/0200-0299/0202.Happy%20Number/README_EN.md)", "`Hash Table`,`Math`", "Easy", ""]}, {"question_id": "0201", "frontend_question_id": "0201", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/bitwise-and-of-numbers-range", "url_en": "https://leetcode.com/problems/bitwise-and-of-numbers-range", "relative_path_cn": "/solution/0200-0299/0201.Bitwise%20AND%20of%20Numbers%20Range/README.md", "relative_path_en": "/solution/0200-0299/0201.Bitwise%20AND%20of%20Numbers%20Range/README_EN.md", "title_cn": "\u6570\u5b57\u8303\u56f4\u6309\u4f4d\u4e0e", "title_en": "Bitwise AND of Numbers Range", "question_title_slug": "bitwise-and-of-numbers-range", "content_en": "

    Given two integers left and right that represent the range [left, right], return the bitwise AND of all numbers in this range, inclusive.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: left = 5, right = 7\nOutput: 4\n
    \n\n

    Example 2:

    \n\n
    \nInput: left = 0, right = 0\nOutput: 0\n
    \n\n

    Example 3:

    \n\n
    \nInput: left = 1, right = 2147483647\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= left <= right <= 231 - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u6574\u6570 left \u548c right \uff0c\u8868\u793a\u533a\u95f4 [left, right] \uff0c\u8fd4\u56de\u6b64\u533a\u95f4\u5185\u6240\u6709\u6570\u5b57 \u6309\u4f4d\u4e0e \u7684\u7ed3\u679c\uff08\u5305\u542b left \u3001right \u7aef\u70b9\uff09\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aleft = 5, right = 7\n\u8f93\u51fa\uff1a4\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aleft = 0, right = 0\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aleft = 1, right = 2147483647\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= left <= right <= 231 - 1
    • \n
    \n", "tags_en": ["Bit Manipulation"], "tags_cn": ["\u4f4d\u8fd0\u7b97"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int rangeBitwiseAnd(int left, int right) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int rangeBitwiseAnd(int left, int right) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def rangeBitwiseAnd(self, left, right):\n \"\"\"\n :type left: int\n :type right: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def rangeBitwiseAnd(self, left: int, right: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint rangeBitwiseAnd(int left, int right){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int RangeBitwiseAnd(int left, int right) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} left\n * @param {number} right\n * @return {number}\n */\nvar rangeBitwiseAnd = function(left, right) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} left\n# @param {Integer} right\n# @return {Integer}\ndef range_bitwise_and(left, right)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func rangeBitwiseAnd(_ left: Int, _ right: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func rangeBitwiseAnd(left int, right int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def rangeBitwiseAnd(left: Int, right: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun rangeBitwiseAnd(left: Int, right: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn range_bitwise_and(left: i32, right: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $left\n * @param Integer $right\n * @return Integer\n */\n function rangeBitwiseAnd($left, $right) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function rangeBitwiseAnd(left: number, right: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (range-bitwise-and left right)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0201](https://leetcode-cn.com/problems/bitwise-and-of-numbers-range)", "[\u6570\u5b57\u8303\u56f4\u6309\u4f4d\u4e0e](/solution/0200-0299/0201.Bitwise%20AND%20of%20Numbers%20Range/README.md)", "`\u4f4d\u8fd0\u7b97`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0201](https://leetcode.com/problems/bitwise-and-of-numbers-range)", "[Bitwise AND of Numbers Range](/solution/0200-0299/0201.Bitwise%20AND%20of%20Numbers%20Range/README_EN.md)", "`Bit Manipulation`", "Medium", ""]}, {"question_id": "0200", "frontend_question_id": "0200", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-islands", "url_en": "https://leetcode.com/problems/number-of-islands", "relative_path_cn": "/solution/0200-0299/0200.Number%20of%20Islands/README.md", "relative_path_en": "/solution/0200-0299/0200.Number%20of%20Islands/README_EN.md", "title_cn": "\u5c9b\u5c7f\u6570\u91cf", "title_en": "Number of Islands", "question_title_slug": "number-of-islands", "content_en": "

    Given an m x n 2D binary grid grid which represents a map of '1's (land) and '0's (water), return the number of islands.

    \n\n

    An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surrounded by water.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: grid = [\n  ["1","1","1","1","0"],\n  ["1","1","0","1","0"],\n  ["1","1","0","0","0"],\n  ["0","0","0","0","0"]\n]\nOutput: 1\n
    \n\n

    Example 2:

    \n\n
    \nInput: grid = [\n  ["1","1","0","0","0"],\n  ["1","1","0","0","0"],\n  ["0","0","1","0","0"],\n  ["0","0","0","1","1"]\n]\nOutput: 3\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= m, n <= 300
    • \n\t
    • grid[i][j] is '0' or '1'.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u7531\u00a0'1'\uff08\u9646\u5730\uff09\u548c '0'\uff08\u6c34\uff09\u7ec4\u6210\u7684\u7684\u4e8c\u7ef4\u7f51\u683c\uff0c\u8bf7\u4f60\u8ba1\u7b97\u7f51\u683c\u4e2d\u5c9b\u5c7f\u7684\u6570\u91cf\u3002

    \n\n

    \u5c9b\u5c7f\u603b\u662f\u88ab\u6c34\u5305\u56f4\uff0c\u5e76\u4e14\u6bcf\u5ea7\u5c9b\u5c7f\u53ea\u80fd\u7531\u6c34\u5e73\u65b9\u5411\u548c/\u6216\u7ad6\u76f4\u65b9\u5411\u4e0a\u76f8\u90bb\u7684\u9646\u5730\u8fde\u63a5\u5f62\u6210\u3002

    \n\n

    \u6b64\u5916\uff0c\u4f60\u53ef\u4ee5\u5047\u8bbe\u8be5\u7f51\u683c\u7684\u56db\u6761\u8fb9\u5747\u88ab\u6c34\u5305\u56f4\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1agrid = [\n  [\"1\",\"1\",\"1\",\"1\",\"0\"],\n  [\"1\",\"1\",\"0\",\"1\",\"0\"],\n  [\"1\",\"1\",\"0\",\"0\",\"0\"],\n  [\"0\",\"0\",\"0\",\"0\",\"0\"]\n]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1agrid = [\n  [\"1\",\"1\",\"0\",\"0\",\"0\"],\n  [\"1\",\"1\",\"0\",\"0\",\"0\"],\n  [\"0\",\"0\",\"1\",\"0\",\"0\"],\n  [\"0\",\"0\",\"0\",\"1\",\"1\"]\n]\n\u8f93\u51fa\uff1a3\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= m, n <= 300
    • \n\t
    • grid[i][j] \u7684\u503c\u4e3a '0' \u6216 '1'
    • \n
    \n", "tags_en": ["Depth-first Search", "Breadth-first Search", "Union Find"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e76\u67e5\u96c6"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numIslands(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numIslands(char[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numIslands(self, grid):\n \"\"\"\n :type grid: List[List[str]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numIslands(self, grid: List[List[str]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numIslands(char** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumIslands(char[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {character[][]} grid\n * @return {number}\n */\nvar numIslands = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Character[][]} grid\n# @return {Integer}\ndef num_islands(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numIslands(_ grid: [[Character]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numIslands(grid [][]byte) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numIslands(grid: Array[Array[Char]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numIslands(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_islands(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $grid\n * @return Integer\n */\n function numIslands($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numIslands(grid: string[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-islands grid)\n (-> (listof (listof char?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0200](https://leetcode-cn.com/problems/number-of-islands)", "[\u5c9b\u5c7f\u6570\u91cf](/solution/0200-0299/0200.Number%20of%20Islands/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e76\u67e5\u96c6`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0200](https://leetcode.com/problems/number-of-islands)", "[Number of Islands](/solution/0200-0299/0200.Number%20of%20Islands/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`,`Union Find`", "Medium", ""]}, {"question_id": "0199", "frontend_question_id": "0199", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/binary-tree-right-side-view", "url_en": "https://leetcode.com/problems/binary-tree-right-side-view", "relative_path_cn": "/solution/0100-0199/0199.Binary%20Tree%20Right%20Side%20View/README.md", "relative_path_en": "/solution/0100-0199/0199.Binary%20Tree%20Right%20Side%20View/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u7684\u53f3\u89c6\u56fe", "title_en": "Binary Tree Right Side View", "question_title_slug": "binary-tree-right-side-view", "content_en": "

    Given the root of a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,2,3,null,5,null,4]\nOutput: [1,3,4]\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = [1,null,3]\nOutput: [1,3]\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = []\nOutput: []\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [0, 100].
    • \n\t
    • -100 <= Node.val <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u68f5\u4e8c\u53c9\u6811\uff0c\u60f3\u8c61\u81ea\u5df1\u7ad9\u5728\u5b83\u7684\u53f3\u4fa7\uff0c\u6309\u7167\u4ece\u9876\u90e8\u5230\u5e95\u90e8\u7684\u987a\u5e8f\uff0c\u8fd4\u56de\u4ece\u53f3\u4fa7\u6240\u80fd\u770b\u5230\u7684\u8282\u70b9\u503c\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: [1,2,3,null,5,null,4]\n\u8f93\u51fa: [1, 3, 4]\n\u89e3\u91ca:\n\n   1            <---\n /   \\\n2     3         <---\n \\     \\\n  5     4       <---\n
    \n", "tags_en": ["Tree", "Depth-first Search", "Breadth-first Search", "Recursion", "Queue"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u9012\u5f52", "\u961f\u5217"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector rightSideView(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public List rightSideView(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def rightSideView(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def rightSideView(self, root: TreeNode) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* rightSideView(struct TreeNode* root, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public IList RightSideView(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number[]}\n */\nvar rightSideView = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer[]}\ndef right_side_view(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func rightSideView(_ root: TreeNode?) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc rightSideView(root *TreeNode) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def rightSideView(root: TreeNode): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun rightSideView(root: TreeNode?): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn right_side_view(root: Option>>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer[]\n */\n function rightSideView($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction rightSideView(root: TreeNode | null): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (right-side-view root)\n (-> (or/c tree-node? #f) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0199](https://leetcode-cn.com/problems/binary-tree-right-side-view)", "[\u4e8c\u53c9\u6811\u7684\u53f3\u89c6\u56fe](/solution/0100-0199/0199.Binary%20Tree%20Right%20Side%20View/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u9012\u5f52`,`\u961f\u5217`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0199](https://leetcode.com/problems/binary-tree-right-side-view)", "[Binary Tree Right Side View](/solution/0100-0199/0199.Binary%20Tree%20Right%20Side%20View/README_EN.md)", "`Tree`,`Depth-first Search`,`Breadth-first Search`,`Recursion`,`Queue`", "Medium", ""]}, {"question_id": "0198", "frontend_question_id": "0198", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/house-robber", "url_en": "https://leetcode.com/problems/house-robber", "relative_path_cn": "/solution/0100-0199/0198.House%20Robber/README.md", "relative_path_en": "/solution/0100-0199/0198.House%20Robber/README_EN.md", "title_cn": "\u6253\u5bb6\u52ab\u820d", "title_en": "House Robber", "question_title_slug": "house-robber", "content_en": "

    You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security systems connected and it will automatically contact the police if two adjacent houses were broken into on the same night.

    \n\n

    Given an integer array nums representing the amount of money of each house, return the maximum amount of money you can rob tonight without alerting the police.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,3,1]\nOutput: 4\nExplanation: Rob house 1 (money = 1) and then rob house 3 (money = 3).\nTotal amount you can rob = 1 + 3 = 4.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [2,7,9,3,1]\nOutput: 12\nExplanation: Rob house 1 (money = 2), rob house 3 (money = 9) and rob house 5 (money = 1).\nTotal amount you can rob = 2 + 9 + 1 = 12.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 100
    • \n\t
    • 0 <= nums[i] <= 400
    • \n
    \n", "content_cn": "

    \u4f60\u662f\u4e00\u4e2a\u4e13\u4e1a\u7684\u5c0f\u5077\uff0c\u8ba1\u5212\u5077\u7a83\u6cbf\u8857\u7684\u623f\u5c4b\u3002\u6bcf\u95f4\u623f\u5185\u90fd\u85cf\u6709\u4e00\u5b9a\u7684\u73b0\u91d1\uff0c\u5f71\u54cd\u4f60\u5077\u7a83\u7684\u552f\u4e00\u5236\u7ea6\u56e0\u7d20\u5c31\u662f\u76f8\u90bb\u7684\u623f\u5c4b\u88c5\u6709\u76f8\u4e92\u8fde\u901a\u7684\u9632\u76d7\u7cfb\u7edf\uff0c\u5982\u679c\u4e24\u95f4\u76f8\u90bb\u7684\u623f\u5c4b\u5728\u540c\u4e00\u665a\u4e0a\u88ab\u5c0f\u5077\u95ef\u5165\uff0c\u7cfb\u7edf\u4f1a\u81ea\u52a8\u62a5\u8b66\u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u4ee3\u8868\u6bcf\u4e2a\u623f\u5c4b\u5b58\u653e\u91d1\u989d\u7684\u975e\u8d1f\u6574\u6570\u6570\u7ec4\uff0c\u8ba1\u7b97\u4f60 \u4e0d\u89e6\u52a8\u8b66\u62a5\u88c5\u7f6e\u7684\u60c5\u51b5\u4e0b \uff0c\u4e00\u591c\u4e4b\u5185\u80fd\u591f\u5077\u7a83\u5230\u7684\u6700\u9ad8\u91d1\u989d\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[1,2,3,1]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u5077\u7a83 1 \u53f7\u623f\u5c4b (\u91d1\u989d = 1) \uff0c\u7136\u540e\u5077\u7a83 3 \u53f7\u623f\u5c4b (\u91d1\u989d = 3)\u3002\n\u00a0    \u5077\u7a83\u5230\u7684\u6700\u9ad8\u91d1\u989d = 1 + 3 = 4 \u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[2,7,9,3,1]\n\u8f93\u51fa\uff1a12\n\u89e3\u91ca\uff1a\u5077\u7a83 1 \u53f7\u623f\u5c4b (\u91d1\u989d = 2), \u5077\u7a83 3 \u53f7\u623f\u5c4b (\u91d1\u989d = 9)\uff0c\u63a5\u7740\u5077\u7a83 5 \u53f7\u623f\u5c4b (\u91d1\u989d = 1)\u3002\n\u00a0    \u5077\u7a83\u5230\u7684\u6700\u9ad8\u91d1\u989d = 2 + 9 + 1 = 12 \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 100
    • \n\t
    • 0 <= nums[i] <= 400
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int rob(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int rob(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def rob(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def rob(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint rob(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int Rob(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar rob = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef rob(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func rob(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func rob(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def rob(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun rob(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn rob(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function rob($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function rob(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (rob nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0198](https://leetcode-cn.com/problems/house-robber)", "[\u6253\u5bb6\u52ab\u820d](/solution/0100-0199/0198.House%20Robber/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0198](https://leetcode.com/problems/house-robber)", "[House Robber](/solution/0100-0199/0198.House%20Robber/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0197", "frontend_question_id": "0197", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/rising-temperature", "url_en": "https://leetcode.com/problems/rising-temperature", "relative_path_cn": "/solution/0100-0199/0197.Rising%20Temperature/README.md", "relative_path_en": "/solution/0100-0199/0197.Rising%20Temperature/README_EN.md", "title_cn": "\u4e0a\u5347\u7684\u6e29\u5ea6", "title_en": "Rising Temperature", "question_title_slug": "rising-temperature", "content_en": "

    Table: Weather

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| recordDate    | date    |\n| temperature   | int     |\n+---------------+---------+\nid is the primary key for this table.\nThis table contains information about the temperature in a certain day.\n
    \n\n

     

    \n\n

    Write an SQL query to find all dates' id with higher temperature compared to its previous dates (yesterday).

    \n\n

    Return the result table in any order.

    \n\n

    The query result format is in the following example:

    \n\n
    \nWeather\n+----+------------+-------------+\n| id | recordDate | Temperature |\n+----+------------+-------------+\n| 1  | 2015-01-01 | 10          |\n| 2  | 2015-01-02 | 25          |\n| 3  | 2015-01-03 | 20          |\n| 4  | 2015-01-04 | 30          |\n+----+------------+-------------+\n\nResult table:\n+----+\n| id |\n+----+\n| 2  |\n| 4  |\n+----+\nIn 2015-01-02, temperature was higher than the previous day (10 -> 25).\nIn 2015-01-04, temperature was higher than the previous day (20 -> 30).\n
    \n", "content_cn": "
    \n
    \n

    \u8868 Weather

    \n\n
    \n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| recordDate    | date    |\n| temperature   | int     |\n+---------------+---------+\nid \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\n\u8be5\u8868\u5305\u542b\u7279\u5b9a\u65e5\u671f\u7684\u6e29\u5ea6\u4fe1\u606f
    \n\n

    \u00a0

    \n\n

    \u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\uff0c\u6765\u67e5\u627e\u4e0e\u4e4b\u524d\uff08\u6628\u5929\u7684\uff09\u65e5\u671f\u76f8\u6bd4\u6e29\u5ea6\u66f4\u9ad8\u7684\u6240\u6709\u65e5\u671f\u7684 id \u3002

    \n\n

    \u8fd4\u56de\u7ed3\u679c \u4e0d\u8981\u6c42\u987a\u5e8f \u3002

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\uff1a

    \n\n
    \nWeather\n+----+------------+-------------+\n| id | recordDate | Temperature |\n+----+------------+-------------+\n| 1  | 2015-01-01 | 10          |\n| 2  | 2015-01-02 | 25          |\n| 3  | 2015-01-03 | 20          |\n| 4  | 2015-01-04 | 30          |\n+----+------------+-------------+\n\nResult table:\n+----+\n| id |\n+----+\n| 2  |\n| 4  |\n+----+\n2015-01-02 \u7684\u6e29\u5ea6\u6bd4\u524d\u4e00\u5929\u9ad8\uff0810 -> 25\uff09\n2015-01-04 \u7684\u6e29\u5ea6\u6bd4\u524d\u4e00\u5929\u9ad8\uff0820 -> 30\uff09\n
    \n
    \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0197](https://leetcode-cn.com/problems/rising-temperature)", "[\u4e0a\u5347\u7684\u6e29\u5ea6](/solution/0100-0199/0197.Rising%20Temperature/README.md)", "", "\u7b80\u5355", ""], "md_table_row_en": ["[0197](https://leetcode.com/problems/rising-temperature)", "[Rising Temperature](/solution/0100-0199/0197.Rising%20Temperature/README_EN.md)", "", "Easy", ""]}, {"question_id": "0196", "frontend_question_id": "0196", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/delete-duplicate-emails", "url_en": "https://leetcode.com/problems/delete-duplicate-emails", "relative_path_cn": "/solution/0100-0199/0196.Delete%20Duplicate%20Emails/README.md", "relative_path_en": "/solution/0100-0199/0196.Delete%20Duplicate%20Emails/README_EN.md", "title_cn": "\u5220\u9664\u91cd\u590d\u7684\u7535\u5b50\u90ae\u7bb1", "title_en": "Delete Duplicate Emails", "question_title_slug": "delete-duplicate-emails", "content_en": "

    Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique emails based on its smallest Id.

    \r\n\r\n
    \r\n+----+------------------+\r\n| Id | Email            |\r\n+----+------------------+\r\n| 1  | john@example.com |\r\n| 2  | bob@example.com  |\r\n| 3  | john@example.com |\r\n+----+------------------+\r\nId is the primary key column for this table.\r\n
    \r\n\r\n

    For example, after running your query, the above Person table should have the following rows:

    \r\n\r\n
    \r\n+----+------------------+\r\n| Id | Email            |\r\n+----+------------------+\r\n| 1  | john@example.com |\r\n| 2  | bob@example.com  |\r\n+----+------------------+\r\n
    \r\n\r\n

    Note:

    \r\n\r\n

    Your output is the whole Person table after executing your sql. Use delete statement.

    \r\n", "content_cn": "

    \u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\uff0c\u6765\u5220\u9664 Person \u8868\u4e2d\u6240\u6709\u91cd\u590d\u7684\u7535\u5b50\u90ae\u7bb1\uff0c\u91cd\u590d\u7684\u90ae\u7bb1\u91cc\u53ea\u4fdd\u7559 Id \u6700\u5c0f \u7684\u90a3\u4e2a\u3002

    \n\n
    +----+------------------+\n| Id | Email            |\n+----+------------------+\n| 1  | john@example.com |\n| 2  | bob@example.com  |\n| 3  | john@example.com |\n+----+------------------+\nId \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\u3002\n
    \n\n

    \u4f8b\u5982\uff0c\u5728\u8fd0\u884c\u4f60\u7684\u67e5\u8be2\u8bed\u53e5\u4e4b\u540e\uff0c\u4e0a\u9762\u7684 Person \u8868\u5e94\u8fd4\u56de\u4ee5\u4e0b\u51e0\u884c:

    \n\n
    +----+------------------+\n| Id | Email            |\n+----+------------------+\n| 1  | john@example.com |\n| 2  | bob@example.com  |\n+----+------------------+\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6267\u884c SQL \u4e4b\u540e\uff0c\u8f93\u51fa\u662f\u6574\u4e2a Person \u8868\u3002
    • \n\t
    • \u4f7f\u7528 delete \u8bed\u53e5\u3002
    • \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0196](https://leetcode-cn.com/problems/delete-duplicate-emails)", "[\u5220\u9664\u91cd\u590d\u7684\u7535\u5b50\u90ae\u7bb1](/solution/0100-0199/0196.Delete%20Duplicate%20Emails/README.md)", "", "\u7b80\u5355", ""], "md_table_row_en": ["[0196](https://leetcode.com/problems/delete-duplicate-emails)", "[Delete Duplicate Emails](/solution/0100-0199/0196.Delete%20Duplicate%20Emails/README_EN.md)", "", "Easy", ""]}, {"question_id": "0195", "frontend_question_id": "0195", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/tenth-line", "url_en": "https://leetcode.com/problems/tenth-line", "relative_path_cn": "/solution/0100-0199/0195.Tenth%20Line/README.md", "relative_path_en": "/solution/0100-0199/0195.Tenth%20Line/README_EN.md", "title_cn": "\u7b2c\u5341\u884c", "title_en": "Tenth Line", "question_title_slug": "tenth-line", "content_en": "

    Given a text file file.txt, print just the 10th line of the file.

    \r\n\r\n

    Example:

    \r\n\r\n

    Assume that file.txt has the following content:

    \r\n\r\n
    \r\nLine 1\r\nLine 2\r\nLine 3\r\nLine 4\r\nLine 5\r\nLine 6\r\nLine 7\r\nLine 8\r\nLine 9\r\nLine 10\r\n
    \r\n\r\n

    Your script should output the tenth line, which is:

    \r\n\r\n
    \r\nLine 10\r\n
    \r\n\r\n
    Note:
    \r\n1. If the file contains less than 10 lines, what should you output?
    \r\n2. There's at least three different solutions. Try to explore all possibilities.
    \r\n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6587\u672c\u6587\u4ef6 file.txt\uff0c\u8bf7\u53ea\u6253\u5370\u8fd9\u4e2a\u6587\u4ef6\u4e2d\u7684\u7b2c\u5341\u884c\u3002

    \n\n

    \u793a\u4f8b:

    \n\n

    \u5047\u8bbe file.txt \u6709\u5982\u4e0b\u5185\u5bb9\uff1a

    \n\n
    Line 1\nLine 2\nLine 3\nLine 4\nLine 5\nLine 6\nLine 7\nLine 8\nLine 9\nLine 10\n
    \n\n

    \u4f60\u7684\u811a\u672c\u5e94\u5f53\u663e\u793a\u7b2c\u5341\u884c\uff1a

    \n\n
    Line 10\n
    \n\n

    \u8bf4\u660e:
    \n1. \u5982\u679c\u6587\u4ef6\u5c11\u4e8e\u5341\u884c\uff0c\u4f60\u5e94\u5f53\u8f93\u51fa\u4ec0\u4e48\uff1f
    \n2. \u81f3\u5c11\u6709\u4e09\u79cd\u4e0d\u540c\u7684\u89e3\u6cd5\uff0c\u8bf7\u5c1d\u8bd5\u5c3d\u53ef\u80fd\u591a\u7684\u65b9\u6cd5\u6765\u89e3\u9898\u3002

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "Bash", "langSlug": "bash", "code": "# Read from the file file.txt and output the tenth line to stdout.", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0195](https://leetcode-cn.com/problems/tenth-line)", "[\u7b2c\u5341\u884c](/solution/0100-0199/0195.Tenth%20Line/README.md)", "", "\u7b80\u5355", ""], "md_table_row_en": ["[0195](https://leetcode.com/problems/tenth-line)", "[Tenth Line](/solution/0100-0199/0195.Tenth%20Line/README_EN.md)", "", "Easy", ""]}, {"question_id": "0194", "frontend_question_id": "0194", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/transpose-file", "url_en": "https://leetcode.com/problems/transpose-file", "relative_path_cn": "/solution/0100-0199/0194.Transpose%20File/README.md", "relative_path_en": "/solution/0100-0199/0194.Transpose%20File/README_EN.md", "title_cn": "\u8f6c\u7f6e\u6587\u4ef6", "title_en": "Transpose File", "question_title_slug": "transpose-file", "content_en": "

    Given a text file file.txt, transpose its content.

    \n\n

    You may assume that each row has the same number of columns, and each field is separated by the ' ' character.

    \n\n

    Example:

    \n\n

    If file.txt has the following content:

    \n\n
    \nname age\nalice 21\nryan 30\n
    \n\n

    Output the following:

    \n\n
    \nname alice ryan\nage 21 30\n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6587\u4ef6\u00a0file.txt\uff0c\u8f6c\u7f6e\u5b83\u7684\u5185\u5bb9\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u5047\u8bbe\u6bcf\u884c\u5217\u6570\u76f8\u540c\uff0c\u5e76\u4e14\u6bcf\u4e2a\u5b57\u6bb5\u7531\u00a0' ' \u5206\u9694\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n

    \u5047\u8bbe\u00a0file.txt\u00a0\u6587\u4ef6\u5185\u5bb9\u5982\u4e0b\uff1a

    \n\n
    \nname age\nalice 21\nryan 30\n
    \n\n

    \u5e94\u5f53\u8f93\u51fa\uff1a

    \n\n
    \nname alice ryan\nage 21 30\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "Bash", "langSlug": "bash", "code": "# Read from the file file.txt and print its transposed content to stdout.", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0194](https://leetcode-cn.com/problems/transpose-file)", "[\u8f6c\u7f6e\u6587\u4ef6](/solution/0100-0199/0194.Transpose%20File/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0194](https://leetcode.com/problems/transpose-file)", "[Transpose File](/solution/0100-0199/0194.Transpose%20File/README_EN.md)", "", "Medium", ""]}, {"question_id": "0193", "frontend_question_id": "0193", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/valid-phone-numbers", "url_en": "https://leetcode.com/problems/valid-phone-numbers", "relative_path_cn": "/solution/0100-0199/0193.Valid%20Phone%20Numbers/README.md", "relative_path_en": "/solution/0100-0199/0193.Valid%20Phone%20Numbers/README_EN.md", "title_cn": "\u6709\u6548\u7535\u8bdd\u53f7\u7801", "title_en": "Valid Phone Numbers", "question_title_slug": "valid-phone-numbers", "content_en": "

    Given a text file file.txt that contains a list of phone numbers (one per line), write a one-liner bash script to print all valid phone numbers.

    \n\n

    You may assume that a valid phone number must appear in one of the following two formats: (xxx) xxx-xxxx or xxx-xxx-xxxx. (x means a digit)

    \n\n

    You may also assume each line in the text file must not contain leading or trailing white spaces.

    \n\n

    Example:

    \n\n

    Assume that file.txt has the following content:

    \n\n
    \n987-123-4567\n123 456 7890\n(123) 456-7890\n
    \n\n

    Your script should output the following valid phone numbers:

    \n\n
    \n987-123-4567\n(123) 456-7890\n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5305\u542b\u7535\u8bdd\u53f7\u7801\u5217\u8868\uff08\u4e00\u884c\u4e00\u4e2a\u7535\u8bdd\u53f7\u7801\uff09\u7684\u6587\u672c\u6587\u4ef6 file.txt\uff0c\u5199\u4e00\u4e2a\u5355\u884c bash \u811a\u672c\u8f93\u51fa\u6240\u6709\u6709\u6548\u7684\u7535\u8bdd\u53f7\u7801\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u5047\u8bbe\u4e00\u4e2a\u6709\u6548\u7684\u7535\u8bdd\u53f7\u7801\u5fc5\u987b\u6ee1\u8db3\u4ee5\u4e0b\u4e24\u79cd\u683c\u5f0f\uff1a (xxx) xxx-xxxx \u6216\u00a0xxx-xxx-xxxx\u3002\uff08x \u8868\u793a\u4e00\u4e2a\u6570\u5b57\uff09

    \n\n

    \u4f60\u4e5f\u53ef\u4ee5\u5047\u8bbe\u6bcf\u884c\u524d\u540e\u6ca1\u6709\u591a\u4f59\u7684\u7a7a\u683c\u5b57\u7b26\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n

    \u5047\u8bbe\u00a0file.txt\u00a0\u5185\u5bb9\u5982\u4e0b\uff1a

    \n\n
    \n987-123-4567\n123 456 7890\n(123) 456-7890\n
    \n\n

    \u4f60\u7684\u811a\u672c\u5e94\u5f53\u8f93\u51fa\u4e0b\u5217\u6709\u6548\u7684\u7535\u8bdd\u53f7\u7801\uff1a

    \n\n
    \n987-123-4567\n(123) 456-7890\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "Bash", "langSlug": "bash", "code": "# Read from the file file.txt and output all valid phone numbers to stdout.", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0193](https://leetcode-cn.com/problems/valid-phone-numbers)", "[\u6709\u6548\u7535\u8bdd\u53f7\u7801](/solution/0100-0199/0193.Valid%20Phone%20Numbers/README.md)", "", "\u7b80\u5355", ""], "md_table_row_en": ["[0193](https://leetcode.com/problems/valid-phone-numbers)", "[Valid Phone Numbers](/solution/0100-0199/0193.Valid%20Phone%20Numbers/README_EN.md)", "", "Easy", ""]}, {"question_id": "0192", "frontend_question_id": "0192", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/word-frequency", "url_en": "https://leetcode.com/problems/word-frequency", "relative_path_cn": "/solution/0100-0199/0192.Word%20Frequency/README.md", "relative_path_en": "/solution/0100-0199/0192.Word%20Frequency/README_EN.md", "title_cn": "\u7edf\u8ba1\u8bcd\u9891", "title_en": "Word Frequency", "question_title_slug": "word-frequency", "content_en": "

    Write a bash script to calculate the frequency of each word in a text file words.txt.

    \r\n\r\n

    For simplicity sake, you may assume:

    \r\n\r\n
      \r\n\t
    • words.txt contains only lowercase characters and space ' ' characters.
    • \r\n\t
    • Each word must consist of lowercase characters only.
    • \r\n\t
    • Words are separated by one or more whitespace characters.
    • \r\n
    \r\n\r\n

    Example:

    \r\n\r\n

    Assume that words.txt has the following content:

    \r\n\r\n
    \r\nthe day is sunny the the\r\nthe sunny is is\r\n
    \r\n\r\n

    Your script should output the following, sorted by descending frequency:

    \r\n\r\n
    \r\nthe 4\r\nis 3\r\nsunny 2\r\nday 1\r\n
    \r\n\r\n

    Note:

    \r\n\r\n
      \r\n\t
    • Don't worry about handling ties, it is guaranteed that each word's frequency count is unique.
    • \r\n\t
    • Could you write it in one-line using Unix pipes?
    • \r\n
    \r\n", "content_cn": "

    \u5199\u4e00\u4e2a bash \u811a\u672c\u4ee5\u7edf\u8ba1\u4e00\u4e2a\u6587\u672c\u6587\u4ef6 words.txt \u4e2d\u6bcf\u4e2a\u5355\u8bcd\u51fa\u73b0\u7684\u9891\u7387\u3002

    \n\n

    \u4e3a\u4e86\u7b80\u5355\u8d77\u89c1\uff0c\u4f60\u53ef\u4ee5\u5047\u8bbe\uff1a

    \n\n
      \n\t
    • words.txt\u53ea\u5305\u62ec\u5c0f\u5199\u5b57\u6bcd\u548c ' ' \u3002
    • \n\t
    • \u6bcf\u4e2a\u5355\u8bcd\u53ea\u7531\u5c0f\u5199\u5b57\u6bcd\u7ec4\u6210\u3002
    • \n\t
    • \u5355\u8bcd\u95f4\u7531\u4e00\u4e2a\u6216\u591a\u4e2a\u7a7a\u683c\u5b57\u7b26\u5206\u9694\u3002
    • \n
    \n\n

    \u793a\u4f8b:

    \n\n

    \u5047\u8bbe words.txt \u5185\u5bb9\u5982\u4e0b\uff1a

    \n\n
    the day is sunny the the\nthe sunny is is\n
    \n\n

    \u4f60\u7684\u811a\u672c\u5e94\u5f53\u8f93\u51fa\uff08\u4ee5\u8bcd\u9891\u964d\u5e8f\u6392\u5217\uff09\uff1a

    \n\n
    the 4\nis 3\nsunny 2\nday 1\n
    \n\n

    \u8bf4\u660e:

    \n\n
      \n\t
    • \u4e0d\u8981\u62c5\u5fc3\u8bcd\u9891\u76f8\u540c\u7684\u5355\u8bcd\u7684\u6392\u5e8f\u95ee\u9898\uff0c\u6bcf\u4e2a\u5355\u8bcd\u51fa\u73b0\u7684\u9891\u7387\u90fd\u662f\u552f\u4e00\u7684\u3002
    • \n\t
    • \u4f60\u53ef\u4ee5\u4f7f\u7528\u4e00\u884c Unix pipes \u5b9e\u73b0\u5417\uff1f
    • \n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "Bash", "langSlug": "bash", "code": "# Read from the file words.txt and output the word frequency list to stdout.", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0192](https://leetcode-cn.com/problems/word-frequency)", "[\u7edf\u8ba1\u8bcd\u9891](/solution/0100-0199/0192.Word%20Frequency/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0192](https://leetcode.com/problems/word-frequency)", "[Word Frequency](/solution/0100-0199/0192.Word%20Frequency/README_EN.md)", "", "Medium", ""]}, {"question_id": "0191", "frontend_question_id": "0191", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/number-of-1-bits", "url_en": "https://leetcode.com/problems/number-of-1-bits", "relative_path_cn": "/solution/0100-0199/0191.Number%20of%201%20Bits/README.md", "relative_path_en": "/solution/0100-0199/0191.Number%20of%201%20Bits/README_EN.md", "title_cn": "\u4f4d1\u7684\u4e2a\u6570", "title_en": "Number of 1 Bits", "question_title_slug": "number-of-1-bits", "content_en": "

    Write a function that takes an unsigned integer and returns the number of '1' bits it has (also known as the Hamming weight).

    \n\n

    Note:

    \n\n
      \n\t
    • Note that in some languages, such as Java, there is no unsigned integer type. In this case, the input will be given as a signed integer type. It should not affect your implementation, as the integer's internal binary representation is the same, whether it is signed or unsigned.
    • \n\t
    • In Java, the compiler represents the signed integers using 2's complement notation. Therefore, in Example 3, the input represents the signed integer. -3.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 00000000000000000000000000001011\nOutput: 3\nExplanation: The input binary string 00000000000000000000000000001011 has a total of three '1' bits.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 00000000000000000000000010000000\nOutput: 1\nExplanation: The input binary string 00000000000000000000000010000000 has a total of one '1' bit.\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 11111111111111111111111111111101\nOutput: 31\nExplanation: The input binary string 11111111111111111111111111111101 has a total of thirty one '1' bits.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The input must be a binary string of length 32.
    • \n
    \n\n

     

    \nFollow up: If this function is called many times, how would you optimize it?", "content_cn": "

    \u7f16\u5199\u4e00\u4e2a\u51fd\u6570\uff0c\u8f93\u5165\u662f\u4e00\u4e2a\u65e0\u7b26\u53f7\u6574\u6570\uff08\u4ee5\u4e8c\u8fdb\u5236\u4e32\u7684\u5f62\u5f0f\uff09\uff0c\u8fd4\u56de\u5176\u4e8c\u8fdb\u5236\u8868\u8fbe\u5f0f\u4e2d\u6570\u5b57\u4f4d\u6570\u4e3a '1' \u7684\u4e2a\u6570\uff08\u4e5f\u88ab\u79f0\u4e3a\u6c49\u660e\u91cd\u91cf\uff09\u3002

    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u8bf7\u6ce8\u610f\uff0c\u5728\u67d0\u4e9b\u8bed\u8a00\uff08\u5982 Java\uff09\u4e2d\uff0c\u6ca1\u6709\u65e0\u7b26\u53f7\u6574\u6570\u7c7b\u578b\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u8f93\u5165\u548c\u8f93\u51fa\u90fd\u5c06\u88ab\u6307\u5b9a\u4e3a\u6709\u7b26\u53f7\u6574\u6570\u7c7b\u578b\uff0c\u5e76\u4e14\u4e0d\u5e94\u5f71\u54cd\u60a8\u7684\u5b9e\u73b0\uff0c\u56e0\u4e3a\u65e0\u8bba\u6574\u6570\u662f\u6709\u7b26\u53f7\u7684\u8fd8\u662f\u65e0\u7b26\u53f7\u7684\uff0c\u5176\u5185\u90e8\u7684\u4e8c\u8fdb\u5236\u8868\u793a\u5f62\u5f0f\u90fd\u662f\u76f8\u540c\u7684\u3002
    • \n\t
    • \u5728 Java \u4e2d\uff0c\u7f16\u8bd1\u5668\u4f7f\u7528\u4e8c\u8fdb\u5236\u8865\u7801\u8bb0\u6cd5\u6765\u8868\u793a\u6709\u7b26\u53f7\u6574\u6570\u3002\u56e0\u6b64\uff0c\u5728\u4e0a\u9762\u7684\u00a0\u793a\u4f8b 3\u00a0\u4e2d\uff0c\u8f93\u5165\u8868\u793a\u6709\u7b26\u53f7\u6574\u6570 -3\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1a00000000000000000000000000001011\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u8f93\u5165\u7684\u4e8c\u8fdb\u5236\u4e32 00000000000000000000000000001011\u00a0\u4e2d\uff0c\u5171\u6709\u4e09\u4f4d\u4e3a '1'\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1a00000000000000000000000010000000\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u8f93\u5165\u7684\u4e8c\u8fdb\u5236\u4e32 00000000000000000000000010000000\u00a0\u4e2d\uff0c\u5171\u6709\u4e00\u4f4d\u4e3a '1'\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1a11111111111111111111111111111101\n\u8f93\u51fa\uff1a31\n\u89e3\u91ca\uff1a\u8f93\u5165\u7684\u4e8c\u8fdb\u5236\u4e32 11111111111111111111111111111101 \u4e2d\uff0c\u5171\u6709 31 \u4f4d\u4e3a '1'\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u8f93\u5165\u5fc5\u987b\u662f\u957f\u5ea6\u4e3a 32 \u7684 \u4e8c\u8fdb\u5236\u4e32 \u3002
    • \n
    \n\n
      \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u5982\u679c\u591a\u6b21\u8c03\u7528\u8fd9\u4e2a\u51fd\u6570\uff0c\u4f60\u5c06\u5982\u4f55\u4f18\u5316\u4f60\u7684\u7b97\u6cd5\uff1f
    • \n
    \n", "tags_en": ["Bit Manipulation"], "tags_cn": ["\u4f4d\u8fd0\u7b97"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int hammingWeight(uint32_t n) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "public class Solution {\n // you need to treat n as an unsigned value\n public int hammingWeight(int n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def hammingWeight(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def hammingWeight(self, n: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "int hammingWeight(uint32_t n) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int HammingWeight(uint n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n - a positive integer\n * @return {number}\n */\nvar hammingWeight = function(n) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n, a positive integer\n# @return {Integer}\ndef hamming_weight(n)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func hammingWeight(_ n: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func hammingWeight(num uint32) int {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n // you need treat n as an unsigned value\n def hammingWeight(n: Int): Int = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n // you need treat n as an unsigned value\n fun hammingWeight(n:Int):Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn hammingWeight (n: u32) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n /**\n * @param Integer $n\n * @return Integer\n */\n function hammingWeight($n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function hammingWeight(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0191](https://leetcode-cn.com/problems/number-of-1-bits)", "[\u4f4d1\u7684\u4e2a\u6570](/solution/0100-0199/0191.Number%20of%201%20Bits/README.md)", "`\u4f4d\u8fd0\u7b97`", "\u7b80\u5355", ""], "md_table_row_en": ["[0191](https://leetcode.com/problems/number-of-1-bits)", "[Number of 1 Bits](/solution/0100-0199/0191.Number%20of%201%20Bits/README_EN.md)", "`Bit Manipulation`", "Easy", ""]}, {"question_id": "0190", "frontend_question_id": "0190", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reverse-bits", "url_en": "https://leetcode.com/problems/reverse-bits", "relative_path_cn": "/solution/0100-0199/0190.Reverse%20Bits/README.md", "relative_path_en": "/solution/0100-0199/0190.Reverse%20Bits/README_EN.md", "title_cn": "\u98a0\u5012\u4e8c\u8fdb\u5236\u4f4d", "title_en": "Reverse Bits", "question_title_slug": "reverse-bits", "content_en": "

    Reverse bits of a given 32 bits unsigned integer.

    \n\n

    Note:

    \n\n
      \n\t
    • Note that in some languages such as Java, there is no unsigned integer type. In this case, both input and output will be given as a signed integer type. They should not affect your implementation, as the integer's internal binary representation is the same, whether it is signed or unsigned.
    • \n\t
    • In Java, the compiler represents the signed integers using 2's complement notation. Therefore, in Example 2 above, the input represents the signed integer -3 and the output represents the signed integer -1073741825.
    • \n
    \n\n

    Follow up:

    \n\n

    If this function is called many times, how would you optimize it?

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 00000010100101000001111010011100\nOutput:    964176192 (00111001011110000010100101000000)\nExplanation: The input binary string 00000010100101000001111010011100 represents the unsigned integer 43261596, so return 964176192 which its binary representation is 00111001011110000010100101000000.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 11111111111111111111111111111101\nOutput:   3221225471 (10111111111111111111111111111111)\nExplanation: The input binary string 11111111111111111111111111111101 represents the unsigned integer 4294967293, so return 3221225471 which its binary representation is 10111111111111111111111111111111.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The input must be a binary string of length 32
    • \n
    \n", "content_cn": "

    \u98a0\u5012\u7ed9\u5b9a\u7684 32 \u4f4d\u65e0\u7b26\u53f7\u6574\u6570\u7684\u4e8c\u8fdb\u5236\u4f4d\u3002

    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u8bf7\u6ce8\u610f\uff0c\u5728\u67d0\u4e9b\u8bed\u8a00\uff08\u5982 Java\uff09\u4e2d\uff0c\u6ca1\u6709\u65e0\u7b26\u53f7\u6574\u6570\u7c7b\u578b\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u8f93\u5165\u548c\u8f93\u51fa\u90fd\u5c06\u88ab\u6307\u5b9a\u4e3a\u6709\u7b26\u53f7\u6574\u6570\u7c7b\u578b\uff0c\u5e76\u4e14\u4e0d\u5e94\u5f71\u54cd\u60a8\u7684\u5b9e\u73b0\uff0c\u56e0\u4e3a\u65e0\u8bba\u6574\u6570\u662f\u6709\u7b26\u53f7\u7684\u8fd8\u662f\u65e0\u7b26\u53f7\u7684\uff0c\u5176\u5185\u90e8\u7684\u4e8c\u8fdb\u5236\u8868\u793a\u5f62\u5f0f\u90fd\u662f\u76f8\u540c\u7684\u3002
    • \n\t
    • \u5728 Java \u4e2d\uff0c\u7f16\u8bd1\u5668\u4f7f\u7528\u4e8c\u8fdb\u5236\u8865\u7801\u8bb0\u6cd5\u6765\u8868\u793a\u6709\u7b26\u53f7\u6574\u6570\u3002\u56e0\u6b64\uff0c\u5728\u4e0a\u9762\u7684\u00a0\u793a\u4f8b 2\u00a0\u4e2d\uff0c\u8f93\u5165\u8868\u793a\u6709\u7b26\u53f7\u6574\u6570 -3\uff0c\u8f93\u51fa\u8868\u793a\u6709\u7b26\u53f7\u6574\u6570 -1073741825\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636:
    \n\u5982\u679c\u591a\u6b21\u8c03\u7528\u8fd9\u4e2a\u51fd\u6570\uff0c\u4f60\u5c06\u5982\u4f55\u4f18\u5316\u4f60\u7684\u7b97\u6cd5\uff1f

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165: 00000010100101000001111010011100\n\u8f93\u51fa: 00111001011110000010100101000000\n\u89e3\u91ca: \u8f93\u5165\u7684\u4e8c\u8fdb\u5236\u4e32 00000010100101000001111010011100 \u8868\u793a\u65e0\u7b26\u53f7\u6574\u6570 43261596\uff0c\n     \u56e0\u6b64\u8fd4\u56de 964176192\uff0c\u5176\u4e8c\u8fdb\u5236\u8868\u793a\u5f62\u5f0f\u4e3a 00111001011110000010100101000000\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1a11111111111111111111111111111101\n\u8f93\u51fa\uff1a10111111111111111111111111111111\n\u89e3\u91ca\uff1a\u8f93\u5165\u7684\u4e8c\u8fdb\u5236\u4e32 11111111111111111111111111111101 \u8868\u793a\u65e0\u7b26\u53f7\u6574\u6570 4294967293\uff0c\n\u00a0    \u56e0\u6b64\u8fd4\u56de 3221225471 \u5176\u4e8c\u8fdb\u5236\u8868\u793a\u5f62\u5f0f\u4e3a 10111111111111111111111111111111 \u3002
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 00000010100101000001111010011100\n\u8f93\u51fa\uff1a964176192 (00111001011110000010100101000000)\n\u89e3\u91ca\uff1a\u8f93\u5165\u7684\u4e8c\u8fdb\u5236\u4e32 00000010100101000001111010011100 \u8868\u793a\u65e0\u7b26\u53f7\u6574\u6570 43261596\uff0c\n     \u56e0\u6b64\u8fd4\u56de 964176192\uff0c\u5176\u4e8c\u8fdb\u5236\u8868\u793a\u5f62\u5f0f\u4e3a 00111001011110000010100101000000\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 11111111111111111111111111111101\n\u8f93\u51fa\uff1a3221225471 (10111111111111111111111111111111)\n\u89e3\u91ca\uff1a\u8f93\u5165\u7684\u4e8c\u8fdb\u5236\u4e32 11111111111111111111111111111101 \u8868\u793a\u65e0\u7b26\u53f7\u6574\u6570 4294967293\uff0c\n   \u00a0 \u56e0\u6b64\u8fd4\u56de 3221225471 \u5176\u4e8c\u8fdb\u5236\u8868\u793a\u5f62\u5f0f\u4e3a 10111111111111111111111111111111 \u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u8f93\u5165\u662f\u4e00\u4e2a\u957f\u5ea6\u4e3a 32 \u7684\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32
    • \n
    \n", "tags_en": ["Bit Manipulation"], "tags_cn": ["\u4f4d\u8fd0\u7b97"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n uint32_t reverseBits(uint32_t n) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "public class Solution {\n // you need treat n as an unsigned value\n public int reverseBits(int n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution:\n # @param n, an integer\n # @return an integer\n def reverseBits(self, n):\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def reverseBits(self, n: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "uint32_t reverseBits(uint32_t n) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public uint reverseBits(uint n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n - a positive integer\n * @return {number} - a positive integer\n */\nvar reverseBits = function(n) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n, a positive integer\n# @return {Integer}\ndef reverse_bits(n)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func reverseBits(_ n: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func reverseBits(num uint32) uint32 {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n // you need treat n as an unsigned value\n def reverseBits(x: Int): Int = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n // you need treat n as an unsigned value\n fun reverseBits(n:Int):Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn reverse_bits(x: u32) -> u32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n /**\n * @param Integer $n\n * @return Integer\n */\n function reverseBits($n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function reverseBits(n: number): number {\n\t\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0190](https://leetcode-cn.com/problems/reverse-bits)", "[\u98a0\u5012\u4e8c\u8fdb\u5236\u4f4d](/solution/0100-0199/0190.Reverse%20Bits/README.md)", "`\u4f4d\u8fd0\u7b97`", "\u7b80\u5355", ""], "md_table_row_en": ["[0190](https://leetcode.com/problems/reverse-bits)", "[Reverse Bits](/solution/0100-0199/0190.Reverse%20Bits/README_EN.md)", "`Bit Manipulation`", "Easy", ""]}, {"question_id": "0189", "frontend_question_id": "0189", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/rotate-array", "url_en": "https://leetcode.com/problems/rotate-array", "relative_path_cn": "/solution/0100-0199/0189.Rotate%20Array/README.md", "relative_path_en": "/solution/0100-0199/0189.Rotate%20Array/README_EN.md", "title_cn": "\u65cb\u8f6c\u6570\u7ec4", "title_en": "Rotate Array", "question_title_slug": "rotate-array", "content_en": "

    Given an array, rotate the array to the right by k steps, where k is non-negative.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,3,4,5,6,7], k = 3\nOutput: [5,6,7,1,2,3,4]\nExplanation:\nrotate 1 steps to the right: [7,1,2,3,4,5,6]\nrotate 2 steps to the right: [6,7,1,2,3,4,5]\nrotate 3 steps to the right: [5,6,7,1,2,3,4]\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [-1,-100,3,99], k = 2\nOutput: [3,99,-1,-100]\nExplanation: \nrotate 1 steps to the right: [99,-1,-100,3]\nrotate 2 steps to the right: [3,99,-1,-100]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 105
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n\t
    • 0 <= k <= 105
    • \n
    \n\n

     

    \n

    Follow up:

    \n\n
      \n\t
    • Try to come up with as many solutions as you can. There are at least three different ways to solve this problem.
    • \n\t
    • Could you do it in-place with O(1) extra space?
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6570\u7ec4\uff0c\u5c06\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u5411\u53f3\u79fb\u52a8\u00a0k\u00a0\u4e2a\u4f4d\u7f6e\uff0c\u5176\u4e2d\u00a0k\u00a0\u662f\u975e\u8d1f\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u5c3d\u53ef\u80fd\u60f3\u51fa\u66f4\u591a\u7684\u89e3\u51b3\u65b9\u6848\uff0c\u81f3\u5c11\u6709\u4e09\u79cd\u4e0d\u540c\u7684\u65b9\u6cd5\u53ef\u4ee5\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u3002
    • \n\t
    • \u4f60\u53ef\u4ee5\u4f7f\u7528\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a\u00a0O(1) \u7684\u00a0\u539f\u5730\u00a0\u7b97\u6cd5\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u5417\uff1f
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: nums = [1,2,3,4,5,6,7], k = 3\n\u8f93\u51fa: [5,6,7,1,2,3,4]\n\u89e3\u91ca:\n\u5411\u53f3\u65cb\u8f6c 1 \u6b65: [7,1,2,3,4,5,6]\n\u5411\u53f3\u65cb\u8f6c 2 \u6b65: [6,7,1,2,3,4,5]\n\u5411\u53f3\u65cb\u8f6c 3 \u6b65: [5,6,7,1,2,3,4]\n
    \n\n

    \u793a\u4f8b\u00a02:

    \n\n
    \n\u8f93\u5165\uff1anums = [-1,-100,3,99], k = 2\n\u8f93\u51fa\uff1a[3,99,-1,-100]\n\u89e3\u91ca: \n\u5411\u53f3\u65cb\u8f6c 1 \u6b65: [99,-1,-100,3]\n\u5411\u53f3\u65cb\u8f6c 2 \u6b65: [3,99,-1,-100]
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 2 * 104
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n\t
    • 0 <= k <= 105
    • \n
    \n\n
      \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n void rotate(vector& nums, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public void rotate(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def rotate(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: None Do not return anything, modify nums in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def rotate(self, nums: List[int], k: int) -> None:\n \"\"\"\n Do not return anything, modify nums in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nvoid rotate(int* nums, int numsSize, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public void Rotate(int[] nums, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} k\n * @return {void} Do not return anything, modify nums in-place instead.\n */\nvar rotate = function(nums, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} k\n# @return {Void} Do not return anything, modify nums in-place instead.\ndef rotate(nums, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func rotate(_ nums: inout [Int], _ k: Int) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func rotate(nums []int, k int) {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def rotate(nums: Array[Int], k: Int): Unit = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun rotate(nums: IntArray, k: Int): Unit {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn rotate(nums: &mut Vec, k: i32) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $k\n * @return NULL\n */\n function rotate(&$nums, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n Do not return anything, modify nums in-place instead.\n */\nfunction rotate(nums: number[], k: number): void {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0189](https://leetcode-cn.com/problems/rotate-array)", "[\u65cb\u8f6c\u6570\u7ec4](/solution/0100-0199/0189.Rotate%20Array/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0189](https://leetcode.com/problems/rotate-array)", "[Rotate Array](/solution/0100-0199/0189.Rotate%20Array/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0188", "frontend_question_id": "0188", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-iv", "url_en": "https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iv", "relative_path_cn": "/solution/0100-0199/0188.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20IV/README.md", "relative_path_en": "/solution/0100-0199/0188.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20IV/README_EN.md", "title_cn": "\u4e70\u5356\u80a1\u7968\u7684\u6700\u4f73\u65f6\u673a IV", "title_en": "Best Time to Buy and Sell Stock IV", "question_title_slug": "best-time-to-buy-and-sell-stock-iv", "content_en": "

    You are given an integer array prices where prices[i] is the price of a given stock on the ith day, and an integer k.

    \n\n

    Find the maximum profit you can achieve. You may complete at most k transactions.

    \n\n

    Note: You may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again).

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: k = 2, prices = [2,4,1]\nOutput: 2\nExplanation: Buy on day 1 (price = 2) and sell on day 2 (price = 4), profit = 4-2 = 2.\n
    \n\n

    Example 2:

    \n\n
    \nInput: k = 2, prices = [3,2,6,5,0,3]\nOutput: 7\nExplanation: Buy on day 2 (price = 2) and sell on day 3 (price = 6), profit = 6-2 = 4. Then buy on day 5 (price = 0) and sell on day 6 (price = 3), profit = 3-0 = 3.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= k <= 100
    • \n\t
    • 0 <= prices.length <= 1000
    • \n\t
    • 0 <= prices[i] <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0prices \uff0c\u5b83\u7684\u7b2c i \u4e2a\u5143\u7d20\u00a0prices[i] \u662f\u4e00\u652f\u7ed9\u5b9a\u7684\u80a1\u7968\u5728\u7b2c i \u5929\u7684\u4ef7\u683c\u3002

    \n\n

    \u8bbe\u8ba1\u4e00\u4e2a\u7b97\u6cd5\u6765\u8ba1\u7b97\u4f60\u6240\u80fd\u83b7\u53d6\u7684\u6700\u5927\u5229\u6da6\u3002\u4f60\u6700\u591a\u53ef\u4ee5\u5b8c\u6210 k \u7b14\u4ea4\u6613\u3002

    \n\n

    \u6ce8\u610f\uff1a\u4f60\u4e0d\u80fd\u540c\u65f6\u53c2\u4e0e\u591a\u7b14\u4ea4\u6613\uff08\u4f60\u5fc5\u987b\u5728\u518d\u6b21\u8d2d\u4e70\u524d\u51fa\u552e\u6389\u4e4b\u524d\u7684\u80a1\u7968\uff09\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1ak = 2, prices = [2,4,1]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5728\u7b2c 1 \u5929 (\u80a1\u7968\u4ef7\u683c = 2) \u7684\u65f6\u5019\u4e70\u5165\uff0c\u5728\u7b2c 2 \u5929 (\u80a1\u7968\u4ef7\u683c = 4) \u7684\u65f6\u5019\u5356\u51fa\uff0c\u8fd9\u7b14\u4ea4\u6613\u6240\u80fd\u83b7\u5f97\u5229\u6da6 = 4-2 = 2 \u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1ak = 2, prices = [3,2,6,5,0,3]\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\u5728\u7b2c 2 \u5929 (\u80a1\u7968\u4ef7\u683c = 2) \u7684\u65f6\u5019\u4e70\u5165\uff0c\u5728\u7b2c 3 \u5929 (\u80a1\u7968\u4ef7\u683c = 6) \u7684\u65f6\u5019\u5356\u51fa, \u8fd9\u7b14\u4ea4\u6613\u6240\u80fd\u83b7\u5f97\u5229\u6da6 = 6-2 = 4 \u3002\n     \u968f\u540e\uff0c\u5728\u7b2c 5 \u5929 (\u80a1\u7968\u4ef7\u683c = 0) \u7684\u65f6\u5019\u4e70\u5165\uff0c\u5728\u7b2c 6 \u5929 (\u80a1\u7968\u4ef7\u683c = 3) \u7684\u65f6\u5019\u5356\u51fa, \u8fd9\u7b14\u4ea4\u6613\u6240\u80fd\u83b7\u5f97\u5229\u6da6 = 3-0 = 3 \u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= k <= 100
    • \n\t
    • 0 <= prices.length <= 1000
    • \n\t
    • 0 <= prices[i] <= 1000
    • \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxProfit(int k, vector& prices) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxProfit(int k, int[] prices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxProfit(self, k, prices):\n \"\"\"\n :type k: int\n :type prices: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxProfit(self, k: int, prices: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxProfit(int k, int* prices, int pricesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxProfit(int k, int[] prices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} k\n * @param {number[]} prices\n * @return {number}\n */\nvar maxProfit = function(k, prices) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} k\n# @param {Integer[]} prices\n# @return {Integer}\ndef max_profit(k, prices)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxProfit(_ k: Int, _ prices: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxProfit(k int, prices []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxProfit(k: Int, prices: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxProfit(k: Int, prices: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_profit(k: i32, prices: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $k\n * @param Integer[] $prices\n * @return Integer\n */\n function maxProfit($k, $prices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxProfit(k: number, prices: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-profit k prices)\n (-> exact-integer? (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0188](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-iv)", "[\u4e70\u5356\u80a1\u7968\u7684\u6700\u4f73\u65f6\u673a IV](/solution/0100-0199/0188.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20IV/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0188](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iv)", "[Best Time to Buy and Sell Stock IV](/solution/0100-0199/0188.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20IV/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "0187", "frontend_question_id": "0187", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/repeated-dna-sequences", "url_en": "https://leetcode.com/problems/repeated-dna-sequences", "relative_path_cn": "/solution/0100-0199/0187.Repeated%20DNA%20Sequences/README.md", "relative_path_en": "/solution/0100-0199/0187.Repeated%20DNA%20Sequences/README_EN.md", "title_cn": "\u91cd\u590d\u7684DNA\u5e8f\u5217", "title_en": "Repeated DNA Sequences", "question_title_slug": "repeated-dna-sequences", "content_en": "

    The DNA sequence is composed of a series of nucleotides abbreviated as 'A', 'C', 'G', and 'T'.

    \n\n
      \n\t
    • For example, "ACGAATTCCG" is a DNA sequence.
    • \n
    \n\n

    When studying DNA, it is useful to identify repeated sequences within the DNA.

    \n\n

    Given a string s that represents a DNA sequence, return all the 10-letter-long sequences (substrings) that occur more than once in a DNA molecule. You may return the answer in any order.

    \n\n

     

    \n

    Example 1:

    \n
    Input: s = \"AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT\"\nOutput: [\"AAAAACCCCC\",\"CCCCCAAAAA\"]\n

    Example 2:

    \n
    Input: s = \"AAAAAAAAAAAAA\"\nOutput: [\"AAAAAAAAAA\"]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 105
    • \n\t
    • s[i] is either 'A', 'C', 'G', or 'T'.
    • \n
    \n", "content_cn": "

    \u6240\u6709 DNA \u90fd\u7531\u4e00\u7cfb\u5217\u7f29\u5199\u4e3a 'A'\uff0c'C'\uff0c'G' \u548c 'T' \u7684\u6838\u82f7\u9178\u7ec4\u6210\uff0c\u4f8b\u5982\uff1a\"ACGAATTCCG\"\u3002\u5728\u7814\u7a76 DNA \u65f6\uff0c\u8bc6\u522b DNA \u4e2d\u7684\u91cd\u590d\u5e8f\u5217\u6709\u65f6\u4f1a\u5bf9\u7814\u7a76\u975e\u5e38\u6709\u5e2e\u52a9\u3002

    \n\n

    \u7f16\u5199\u4e00\u4e2a\u51fd\u6570\u6765\u627e\u51fa\u6240\u6709\u76ee\u6807\u5b50\u4e32\uff0c\u76ee\u6807\u5b50\u4e32\u7684\u957f\u5ea6\u4e3a 10\uff0c\u4e14\u5728 DNA \u5b57\u7b26\u4e32 s \u4e2d\u51fa\u73b0\u6b21\u6570\u8d85\u8fc7\u4e00\u6b21\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT\"\n\u8f93\u51fa\uff1a[\"AAAAACCCCC\",\"CCCCCAAAAA\"]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"AAAAAAAAAAAAA\"\n\u8f93\u51fa\uff1a[\"AAAAAAAAAA\"]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= s.length <= 105
    • \n\t
    • s[i] \u4e3a 'A'\u3001'C'\u3001'G' \u6216 'T'
    • \n
    \n", "tags_en": ["Bit Manipulation", "Hash Table"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findRepeatedDnaSequences(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List findRepeatedDnaSequences(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findRepeatedDnaSequences(self, s):\n \"\"\"\n :type s: str\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findRepeatedDnaSequences(self, s: str) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** findRepeatedDnaSequences(char * s, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList FindRepeatedDnaSequences(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string[]}\n */\nvar findRepeatedDnaSequences = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String[]}\ndef find_repeated_dna_sequences(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findRepeatedDnaSequences(_ s: String) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findRepeatedDnaSequences(s string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findRepeatedDnaSequences(s: String): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findRepeatedDnaSequences(s: String): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_repeated_dna_sequences(s: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String[]\n */\n function findRepeatedDnaSequences($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findRepeatedDnaSequences(s: string): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-repeated-dna-sequences s)\n (-> string? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0187](https://leetcode-cn.com/problems/repeated-dna-sequences)", "[\u91cd\u590d\u7684DNA\u5e8f\u5217](/solution/0100-0199/0187.Repeated%20DNA%20Sequences/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0187](https://leetcode.com/problems/repeated-dna-sequences)", "[Repeated DNA Sequences](/solution/0100-0199/0187.Repeated%20DNA%20Sequences/README_EN.md)", "`Bit Manipulation`,`Hash Table`", "Medium", ""]}, {"question_id": "0186", "frontend_question_id": "0186", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/reverse-words-in-a-string-ii", "url_en": "https://leetcode.com/problems/reverse-words-in-a-string-ii", "relative_path_cn": "/solution/0100-0199/0186.Reverse%20Words%20in%20a%20String%20II/README.md", "relative_path_en": "/solution/0100-0199/0186.Reverse%20Words%20in%20a%20String%20II/README_EN.md", "title_cn": "\u7ffb\u8f6c\u5b57\u7b26\u4e32\u91cc\u7684\u5355\u8bcd II", "title_en": "Reverse Words in a String II", "question_title_slug": "reverse-words-in-a-string-ii", "content_en": "

    Given a character array s, reverse the order of the words.

    \n\n

    A word is defined as a sequence of non-space characters. The words in s will be separated by a single space.

    \n\n

    Your code must solve the problem in-place, i.e. without allocating extra space.

    \n\n

     

    \n

    Example 1:

    \n
    Input: s = [\"t\",\"h\",\"e\",\" \",\"s\",\"k\",\"y\",\" \",\"i\",\"s\",\" \",\"b\",\"l\",\"u\",\"e\"]\nOutput: [\"b\",\"l\",\"u\",\"e\",\" \",\"i\",\"s\",\" \",\"s\",\"k\",\"y\",\" \",\"t\",\"h\",\"e\"]\n

    Example 2:

    \n
    Input: s = [\"a\"]\nOutput: [\"a\"]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 105
    • \n\t
    • s[i] is an English letter (uppercase or lowercase), digit, or space ' '.
    • \n\t
    • There is at least one word in s.
    • \n\t
    • s does not contain leading or trailing spaces.
    • \n\t
    • All the words in s are guaranteed to be separated by a single space.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u9010\u4e2a\u7ffb\u8f6c\u5b57\u7b26\u4e32\u4e2d\u7684\u6bcf\u4e2a\u5355\u8bcd\u3002

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165: ["t","h","e"," ","s","k","y"," ","i","s"," ","b","l","u","e"]\n\u8f93\u51fa: ["b","l","u","e"," ","i","s"," ","s","k","y"," ","t","h","e"]
    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    • \u5355\u8bcd\u7684\u5b9a\u4e49\u662f\u4e0d\u5305\u542b\u7a7a\u683c\u7684\u4e00\u7cfb\u5217\u5b57\u7b26
    • \n\t
    • \u8f93\u5165\u5b57\u7b26\u4e32\u4e2d\u4e0d\u4f1a\u5305\u542b\u524d\u7f6e\u6216\u5c3e\u968f\u7684\u7a7a\u683c
    • \n\t
    • \u5355\u8bcd\u4e0e\u5355\u8bcd\u4e4b\u95f4\u6c38\u8fdc\u662f\u4ee5\u5355\u4e2a\u7a7a\u683c\u9694\u5f00\u7684
    • \n
    \n\n

    \u8fdb\u9636\uff1a\u4f7f\u7528 O(1) \u989d\u5916\u7a7a\u95f4\u590d\u6742\u5ea6\u7684\u539f\u5730\u89e3\u6cd5\u3002

    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n void reverseWords(vector& s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public void reverseWords(char[] s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def reverseWords(self, s):\n \"\"\"\n :type s: List[str]\n :rtype: None Do not return anything, modify s in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def reverseWords(self, s: List[str]) -> None:\n \"\"\"\n Do not return anything, modify s in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nvoid reverseWords(char* s, int sSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public void ReverseWords(char[] s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {character[]} s\n * @return {void} Do not return anything, modify s in-place instead.\n */\nvar reverseWords = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Character[]} s\n# @return {Void} Do not return anything, modify s in-place instead.\ndef reverse_words(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func reverseWords(_ s: inout [Character]) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func reverseWords(s []byte) {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def reverseWords(s: Array[Char]): Unit = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun reverseWords(s: CharArray): Unit {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn reverse_words(s: &mut Vec) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $s\n * @return NULL\n */\n function reverseWords(&$s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n Do not return anything, modify s in-place instead.\n */\nfunction reverseWords(s: string[]): void {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0186](https://leetcode-cn.com/problems/reverse-words-in-a-string-ii)", "[\u7ffb\u8f6c\u5b57\u7b26\u4e32\u91cc\u7684\u5355\u8bcd II](/solution/0100-0199/0186.Reverse%20Words%20in%20a%20String%20II/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0186](https://leetcode.com/problems/reverse-words-in-a-string-ii)", "[Reverse Words in a String II](/solution/0100-0199/0186.Reverse%20Words%20in%20a%20String%20II/README_EN.md)", "`String`", "Medium", "\ud83d\udd12"]}, {"question_id": "0185", "frontend_question_id": "0185", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/department-top-three-salaries", "url_en": "https://leetcode.com/problems/department-top-three-salaries", "relative_path_cn": "/solution/0100-0199/0185.Department%20Top%20Three%20Salaries/README.md", "relative_path_en": "/solution/0100-0199/0185.Department%20Top%20Three%20Salaries/README_EN.md", "title_cn": "\u90e8\u95e8\u5de5\u8d44\u524d\u4e09\u9ad8\u7684\u6240\u6709\u5458\u5de5", "title_en": "Department Top Three Salaries", "question_title_slug": "department-top-three-salaries", "content_en": "

    Table: Employee

    \n\n
    \n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| Id           | int     |\n| Name         | varchar |\n| Salary       | int     |\n| DepartmentId | int     |\n+--------------+---------+\nId is the primary key for this table.\nEach row contains the ID, name, salary, and department of one employee.\n
    \n\n

     

    \n\n

    Table: Department

    \n\n
    \n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| Id          | int     |\n| Name        | varchar |\n+-------------+---------+\nId is the primary key for this table.\nEach row contains the ID and the name of one department.\n
    \n\n

     

    \n\n

    A company's executives are interested in seeing who earns the most money in each of the company's departments. A high earner in a department is an employee who has a salary in the top three unique salaries for that department.

    \n\n

    Write an SQL query to find the employees who are high earners in each of the departments.

    \n\n

    Return the result table in any order.

    \n\n

    The query result format is in the following example:

    \n\n

     

    \n\n
    \nEmployee table:\n+----+-------+--------+--------------+\n| Id | Name  | Salary | DepartmentId |\n+----+-------+--------+--------------+\n| 1  | Joe   | 85000  | 1            |\n| 2  | Henry | 80000  | 2            |\n| 3  | Sam   | 60000  | 2            |\n| 4  | Max   | 90000  | 1            |\n| 5  | Janet | 69000  | 1            |\n| 6  | Randy | 85000  | 1            |\n| 7  | Will  | 70000  | 1            |\n+----+-------+--------+--------------+\n\nDepartment table:\n+----+-------+\n| Id | Name  |\n+----+-------+\n| 1  | IT    |\n| 2  | Sales |\n+----+-------+\n\nResult table:\n+------------+----------+--------+\n| Department | Employee | Salary |\n+------------+----------+--------+\n| IT         | Max      | 90000  |\n| IT         | Joe      | 85000  |\n| IT         | Randy    | 85000  |\n| IT         | Will     | 70000  |\n| Sales      | Henry    | 80000  |\n| Sales      | Sam      | 60000  |\n+------------+----------+--------+\n\nIn the IT department:\n- Max earns the highest unique salary\n- Both Randy and Joe earn the second-highest unique salary\n- Will earns the third-highest unique salary\n\nIn the Sales department:\n- Henry earns the highest salary\n- Sam earns the second-highest salary\n- There is no third-highest salary as there are only two employees
    \n", "content_cn": "

    Employee \u8868\u5305\u542b\u6240\u6709\u5458\u5de5\u4fe1\u606f\uff0c\u6bcf\u4e2a\u5458\u5de5\u6709\u5176\u5bf9\u5e94\u7684\u5de5\u53f7 Id\uff0c\u59d3\u540d Name\uff0c\u5de5\u8d44 Salary \u548c\u90e8\u95e8\u7f16\u53f7 DepartmentId \u3002

    \n\n
    +----+-------+--------+--------------+\n| Id | Name  | Salary | DepartmentId |\n+----+-------+--------+--------------+\n| 1  | Joe   | 85000  | 1            |\n| 2  | Henry | 80000  | 2            |\n| 3  | Sam   | 60000  | 2            |\n| 4  | Max   | 90000  | 1            |\n| 5  | Janet | 69000  | 1            |\n| 6  | Randy | 85000  | 1            |\n| 7  | Will  | 70000  | 1            |\n+----+-------+--------+--------------+
    \n\n

    Department \u8868\u5305\u542b\u516c\u53f8\u6240\u6709\u90e8\u95e8\u7684\u4fe1\u606f\u3002

    \n\n
    +----+----------+\n| Id | Name     |\n+----+----------+\n| 1  | IT       |\n| 2  | Sales    |\n+----+----------+
    \n\n

    \u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\uff0c\u627e\u51fa\u6bcf\u4e2a\u90e8\u95e8\u83b7\u5f97\u524d\u4e09\u9ad8\u5de5\u8d44\u7684\u6240\u6709\u5458\u5de5\u3002\u4f8b\u5982\uff0c\u6839\u636e\u4e0a\u8ff0\u7ed9\u5b9a\u7684\u8868\uff0c\u67e5\u8be2\u7ed3\u679c\u5e94\u8fd4\u56de\uff1a

    \n\n
    +------------+----------+--------+\n| Department | Employee | Salary |\n+------------+----------+--------+\n| IT         | Max      | 90000  |\n| IT         | Randy    | 85000  |\n| IT         | Joe      | 85000  |\n| IT         | Will     | 70000  |\n| Sales      | Henry    | 80000  |\n| Sales      | Sam      | 60000  |\n+------------+----------+--------+
    \n\n

    \u89e3\u91ca\uff1a

    \n\n

    IT \u90e8\u95e8\u4e2d\uff0cMax \u83b7\u5f97\u4e86\u6700\u9ad8\u7684\u5de5\u8d44\uff0cRandy \u548c Joe \u90fd\u62ff\u5230\u4e86\u7b2c\u4e8c\u9ad8\u7684\u5de5\u8d44\uff0cWill \u7684\u5de5\u8d44\u6392\u7b2c\u4e09\u3002\u9500\u552e\u90e8\u95e8\uff08Sales\uff09\u53ea\u6709\u4e24\u540d\u5458\u5de5\uff0cHenry \u7684\u5de5\u8d44\u6700\u9ad8\uff0cSam \u7684\u5de5\u8d44\u6392\u7b2c\u4e8c\u3002

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0185](https://leetcode-cn.com/problems/department-top-three-salaries)", "[\u90e8\u95e8\u5de5\u8d44\u524d\u4e09\u9ad8\u7684\u6240\u6709\u5458\u5de5](/solution/0100-0199/0185.Department%20Top%20Three%20Salaries/README.md)", "", "\u56f0\u96be", ""], "md_table_row_en": ["[0185](https://leetcode.com/problems/department-top-three-salaries)", "[Department Top Three Salaries](/solution/0100-0199/0185.Department%20Top%20Three%20Salaries/README_EN.md)", "", "Hard", ""]}, {"question_id": "0184", "frontend_question_id": "0184", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/department-highest-salary", "url_en": "https://leetcode.com/problems/department-highest-salary", "relative_path_cn": "/solution/0100-0199/0184.Department%20Highest%20Salary/README.md", "relative_path_en": "/solution/0100-0199/0184.Department%20Highest%20Salary/README_EN.md", "title_cn": "\u90e8\u95e8\u5de5\u8d44\u6700\u9ad8\u7684\u5458\u5de5", "title_en": "Department Highest Salary", "question_title_slug": "department-highest-salary", "content_en": "

    The Employee table holds all employees. Every employee has an Id, a salary, and there is also a column for the department Id.

    \r\n\r\n
    \r\n+----+-------+--------+--------------+\r\n| Id | Name  | Salary | DepartmentId |\r\n+----+-------+--------+--------------+\r\n| 1  | Joe   | 70000  | 1            |\r\n| 2  | Jim   | 90000  | 1            |\r\n| 3  | Henry | 80000  | 2            |\r\n| 4  | Sam   | 60000  | 2            |\r\n| 5  | Max   | 90000  | 1            |\r\n+----+-------+--------+--------------+\r\n
    \r\n\r\n

    The Department table holds all departments of the company.

    \r\n\r\n
    \r\n+----+----------+\r\n| Id | Name     |\r\n+----+----------+\r\n| 1  | IT       |\r\n| 2  | Sales    |\r\n+----+----------+\r\n
    \r\n\r\n

    Write a SQL query to find employees who have the highest salary in each of the departments. For the above tables, your SQL query should return the following rows (order of rows does not matter).

    \r\n\r\n
    \r\n+------------+----------+--------+\r\n| Department | Employee | Salary |\r\n+------------+----------+--------+\r\n| IT         | Max      | 90000  |\r\n| IT         | Jim      | 90000  |\r\n| Sales      | Henry    | 80000  |\r\n+------------+----------+--------+\r\n
    \r\n\r\n

    Explanation:

    \r\n\r\n

    Max and Jim both have the highest salary in the IT department and Henry has the highest salary in the Sales department.

    \r\n", "content_cn": "

    Employee \u8868\u5305\u542b\u6240\u6709\u5458\u5de5\u4fe1\u606f\uff0c\u6bcf\u4e2a\u5458\u5de5\u6709\u5176\u5bf9\u5e94\u7684 Id, salary \u548c department Id\u3002

    \n\n
    +----+-------+--------+--------------+\n| Id | Name  | Salary | DepartmentId |\n+----+-------+--------+--------------+\n| 1  | Joe   | 70000  | 1            |\n| 2  | Jim   | 90000  | 1            |\n| 3  | Henry | 80000  | 2            |\n| 4  | Sam   | 60000  | 2            |\n| 5  | Max   | 90000  | 1            |\n+----+-------+--------+--------------+
    \n\n

    Department \u8868\u5305\u542b\u516c\u53f8\u6240\u6709\u90e8\u95e8\u7684\u4fe1\u606f\u3002

    \n\n
    +----+----------+\n| Id | Name     |\n+----+----------+\n| 1  | IT       |\n| 2  | Sales    |\n+----+----------+
    \n\n

    \u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\uff0c\u627e\u51fa\u6bcf\u4e2a\u90e8\u95e8\u5de5\u8d44\u6700\u9ad8\u7684\u5458\u5de5\u3002\u5bf9\u4e8e\u4e0a\u8ff0\u8868\uff0c\u60a8\u7684 SQL \u67e5\u8be2\u5e94\u8fd4\u56de\u4ee5\u4e0b\u884c\uff08\u884c\u7684\u987a\u5e8f\u65e0\u5173\u7d27\u8981\uff09\u3002

    \n\n
    +------------+----------+--------+\n| Department | Employee | Salary |\n+------------+----------+--------+\n| IT         | Max      | 90000  |\n| IT         | Jim      | 90000  |\n| Sales      | Henry    | 80000  |\n+------------+----------+--------+
    \n\n

    \u89e3\u91ca\uff1a

    \n\n

    Max \u548c Jim \u5728 IT \u90e8\u95e8\u7684\u5de5\u8d44\u90fd\u662f\u6700\u9ad8\u7684\uff0cHenry \u5728\u9500\u552e\u90e8\u7684\u5de5\u8d44\u6700\u9ad8\u3002

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0184](https://leetcode-cn.com/problems/department-highest-salary)", "[\u90e8\u95e8\u5de5\u8d44\u6700\u9ad8\u7684\u5458\u5de5](/solution/0100-0199/0184.Department%20Highest%20Salary/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0184](https://leetcode.com/problems/department-highest-salary)", "[Department Highest Salary](/solution/0100-0199/0184.Department%20Highest%20Salary/README_EN.md)", "", "Medium", ""]}, {"question_id": "0183", "frontend_question_id": "0183", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/customers-who-never-order", "url_en": "https://leetcode.com/problems/customers-who-never-order", "relative_path_cn": "/solution/0100-0199/0183.Customers%20Who%20Never%20Order/README.md", "relative_path_en": "/solution/0100-0199/0183.Customers%20Who%20Never%20Order/README_EN.md", "title_cn": "\u4ece\u4e0d\u8ba2\u8d2d\u7684\u5ba2\u6237", "title_en": "Customers Who Never Order", "question_title_slug": "customers-who-never-order", "content_en": "

    Suppose that a website contains two tables, the Customers table and the Orders table. Write a SQL query to find all customers who never order anything.

    \r\n\r\n

    Table: Customers.

    \r\n\r\n
    \r\n+----+-------+\r\n| Id | Name  |\r\n+----+-------+\r\n| 1  | Joe   |\r\n| 2  | Henry |\r\n| 3  | Sam   |\r\n| 4  | Max   |\r\n+----+-------+\r\n
    \r\n\r\n

    Table: Orders.

    \r\n\r\n
    \r\n+----+------------+\r\n| Id | CustomerId |\r\n+----+------------+\r\n| 1  | 3          |\r\n| 2  | 1          |\r\n+----+------------+\r\n
    \r\n\r\n

    Using the above tables as example, return the following:

    \r\n\r\n
    \r\n+-----------+\r\n| Customers |\r\n+-----------+\r\n| Henry     |\r\n| Max       |\r\n+-----------+\r\n
    \r\n", "content_cn": "

    \u67d0\u7f51\u7ad9\u5305\u542b\u4e24\u4e2a\u8868\uff0cCustomers \u8868\u548c Orders \u8868\u3002\u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\uff0c\u627e\u51fa\u6240\u6709\u4ece\u4e0d\u8ba2\u8d2d\u4efb\u4f55\u4e1c\u897f\u7684\u5ba2\u6237\u3002

    \n\n

    Customers \u8868\uff1a

    \n\n
    +----+-------+\n| Id | Name  |\n+----+-------+\n| 1  | Joe   |\n| 2  | Henry |\n| 3  | Sam   |\n| 4  | Max   |\n+----+-------+\n
    \n\n

    Orders \u8868\uff1a

    \n\n
    +----+------------+\n| Id | CustomerId |\n+----+------------+\n| 1  | 3          |\n| 2  | 1          |\n+----+------------+\n
    \n\n

    \u4f8b\u5982\u7ed9\u5b9a\u4e0a\u8ff0\u8868\u683c\uff0c\u4f60\u7684\u67e5\u8be2\u5e94\u8fd4\u56de\uff1a

    \n\n
    +-----------+\n| Customers |\n+-----------+\n| Henry     |\n| Max       |\n+-----------+\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0183](https://leetcode-cn.com/problems/customers-who-never-order)", "[\u4ece\u4e0d\u8ba2\u8d2d\u7684\u5ba2\u6237](/solution/0100-0199/0183.Customers%20Who%20Never%20Order/README.md)", "", "\u7b80\u5355", ""], "md_table_row_en": ["[0183](https://leetcode.com/problems/customers-who-never-order)", "[Customers Who Never Order](/solution/0100-0199/0183.Customers%20Who%20Never%20Order/README_EN.md)", "", "Easy", ""]}, {"question_id": "0182", "frontend_question_id": "0182", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/duplicate-emails", "url_en": "https://leetcode.com/problems/duplicate-emails", "relative_path_cn": "/solution/0100-0199/0182.Duplicate%20Emails/README.md", "relative_path_en": "/solution/0100-0199/0182.Duplicate%20Emails/README_EN.md", "title_cn": "\u67e5\u627e\u91cd\u590d\u7684\u7535\u5b50\u90ae\u7bb1", "title_en": "Duplicate Emails", "question_title_slug": "duplicate-emails", "content_en": "

    Write a SQL query to find all duplicate emails in a table named Person.

    \r\n\r\n
    \r\n+----+---------+\r\n| Id | Email   |\r\n+----+---------+\r\n| 1  | a@b.com |\r\n| 2  | c@d.com |\r\n| 3  | a@b.com |\r\n+----+---------+\r\n
    \r\n\r\n

    For example, your query should return the following for the above table:

    \r\n\r\n
    \r\n+---------+\r\n| Email   |\r\n+---------+\r\n| a@b.com |\r\n+---------+\r\n
    \r\n\r\n

    Note: All emails are in lowercase.

    \r\n", "content_cn": "

    \u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\uff0c\u67e5\u627e Person \u8868\u4e2d\u6240\u6709\u91cd\u590d\u7684\u7535\u5b50\u90ae\u7bb1\u3002

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    +----+---------+\n| Id | Email   |\n+----+---------+\n| 1  | a@b.com |\n| 2  | c@d.com |\n| 3  | a@b.com |\n+----+---------+\n
    \n\n

    \u6839\u636e\u4ee5\u4e0a\u8f93\u5165\uff0c\u4f60\u7684\u67e5\u8be2\u5e94\u8fd4\u56de\u4ee5\u4e0b\u7ed3\u679c\uff1a

    \n\n
    +---------+\n| Email   |\n+---------+\n| a@b.com |\n+---------+\n
    \n\n

    \u8bf4\u660e\uff1a\u6240\u6709\u7535\u5b50\u90ae\u7bb1\u90fd\u662f\u5c0f\u5199\u5b57\u6bcd\u3002

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0182](https://leetcode-cn.com/problems/duplicate-emails)", "[\u67e5\u627e\u91cd\u590d\u7684\u7535\u5b50\u90ae\u7bb1](/solution/0100-0199/0182.Duplicate%20Emails/README.md)", "", "\u7b80\u5355", ""], "md_table_row_en": ["[0182](https://leetcode.com/problems/duplicate-emails)", "[Duplicate Emails](/solution/0100-0199/0182.Duplicate%20Emails/README_EN.md)", "", "Easy", ""]}, {"question_id": "0181", "frontend_question_id": "0181", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/employees-earning-more-than-their-managers", "url_en": "https://leetcode.com/problems/employees-earning-more-than-their-managers", "relative_path_cn": "/solution/0100-0199/0181.Employees%20Earning%20More%20Than%20Their%20Managers/README.md", "relative_path_en": "/solution/0100-0199/0181.Employees%20Earning%20More%20Than%20Their%20Managers/README_EN.md", "title_cn": "\u8d85\u8fc7\u7ecf\u7406\u6536\u5165\u7684\u5458\u5de5", "title_en": "Employees Earning More Than Their Managers", "question_title_slug": "employees-earning-more-than-their-managers", "content_en": "

    The Employee table holds all employees including their managers. Every employee has an Id, and there is also a column for the manager Id.

    \r\n\r\n
    \r\n+----+-------+--------+-----------+\r\n| Id | Name  | Salary | ManagerId |\r\n+----+-------+--------+-----------+\r\n| 1  | Joe   | 70000  | 3         |\r\n| 2  | Henry | 80000  | 4         |\r\n| 3  | Sam   | 60000  | NULL      |\r\n| 4  | Max   | 90000  | NULL      |\r\n+----+-------+--------+-----------+\r\n
    \r\n\r\n

    Given the Employee table, write a SQL query that finds out employees who earn more than their managers. For the above table, Joe is the only employee who earns more than his manager.

    \r\n\r\n
    \r\n+----------+\r\n| Employee |\r\n+----------+\r\n| Joe      |\r\n+----------+\r\n
    \r\n", "content_cn": "

    Employee \u8868\u5305\u542b\u6240\u6709\u5458\u5de5\uff0c\u4ed6\u4eec\u7684\u7ecf\u7406\u4e5f\u5c5e\u4e8e\u5458\u5de5\u3002\u6bcf\u4e2a\u5458\u5de5\u90fd\u6709\u4e00\u4e2a Id\uff0c\u6b64\u5916\u8fd8\u6709\u4e00\u5217\u5bf9\u5e94\u5458\u5de5\u7684\u7ecf\u7406\u7684 Id\u3002

    \n\n
    +----+-------+--------+-----------+\n| Id | Name  | Salary | ManagerId |\n+----+-------+--------+-----------+\n| 1  | Joe   | 70000  | 3         |\n| 2  | Henry | 80000  | 4         |\n| 3  | Sam   | 60000  | NULL      |\n| 4  | Max   | 90000  | NULL      |\n+----+-------+--------+-----------+\n
    \n\n

    \u7ed9\u5b9a Employee \u8868\uff0c\u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\uff0c\u8be5\u67e5\u8be2\u53ef\u4ee5\u83b7\u53d6\u6536\u5165\u8d85\u8fc7\u4ed6\u4eec\u7ecf\u7406\u7684\u5458\u5de5\u7684\u59d3\u540d\u3002\u5728\u4e0a\u9762\u7684\u8868\u683c\u4e2d\uff0cJoe \u662f\u552f\u4e00\u4e00\u4e2a\u6536\u5165\u8d85\u8fc7\u4ed6\u7684\u7ecf\u7406\u7684\u5458\u5de5\u3002

    \n\n
    +----------+\n| Employee |\n+----------+\n| Joe      |\n+----------+\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0181](https://leetcode-cn.com/problems/employees-earning-more-than-their-managers)", "[\u8d85\u8fc7\u7ecf\u7406\u6536\u5165\u7684\u5458\u5de5](/solution/0100-0199/0181.Employees%20Earning%20More%20Than%20Their%20Managers/README.md)", "", "\u7b80\u5355", ""], "md_table_row_en": ["[0181](https://leetcode.com/problems/employees-earning-more-than-their-managers)", "[Employees Earning More Than Their Managers](/solution/0100-0199/0181.Employees%20Earning%20More%20Than%20Their%20Managers/README_EN.md)", "", "Easy", ""]}, {"question_id": "0180", "frontend_question_id": "0180", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/consecutive-numbers", "url_en": "https://leetcode.com/problems/consecutive-numbers", "relative_path_cn": "/solution/0100-0199/0180.Consecutive%20Numbers/README.md", "relative_path_en": "/solution/0100-0199/0180.Consecutive%20Numbers/README_EN.md", "title_cn": "\u8fde\u7eed\u51fa\u73b0\u7684\u6570\u5b57", "title_en": "Consecutive Numbers", "question_title_slug": "consecutive-numbers", "content_en": "

    Table: Logs

    \n\n
    \n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| id          | int     |\n| num         | varchar |\n+-------------+---------+\nid is the primary key for this table.\n
    \n\n

     

    \n\n

    Write an SQL query to find all numbers that appear at least three times consecutively.

    \n\n

    Return the result table in any order.

    \n\n

    The query result format is in the following example:

    \n\n

     

    \n\n
    \nLogs table:\n+----+-----+\n| Id | Num |\n+----+-----+\n| 1  | 1   |\n| 2  | 1   |\n| 3  | 1   |\n| 4  | 2   |\n| 5  | 1   |\n| 6  | 2   |\n| 7  | 2   |\n+----+-----+\n\nResult table:\n+-----------------+\n| ConsecutiveNums |\n+-----------------+\n| 1               |\n+-----------------+\n1 is the only number that appears consecutively for at least three times.\n
    \n", "content_cn": "

    \u8868\uff1aLogs

    \n\n
    \n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| id          | int     |\n| num         | varchar |\n+-------------+---------+\nid \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\u3002
    \n\n

    \u00a0

    \n\n

    \u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\uff0c\u67e5\u627e\u6240\u6709\u81f3\u5c11\u8fde\u7eed\u51fa\u73b0\u4e09\u6b21\u7684\u6570\u5b57\u3002

    \n\n

    \u8fd4\u56de\u7684\u7ed3\u679c\u8868\u4e2d\u7684\u6570\u636e\u53ef\u4ee5\u6309 \u4efb\u610f\u987a\u5e8f \u6392\u5217\u3002

    \n\n

    \u00a0

    \n\n

    \u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u9762\u7684\u4f8b\u5b50\u6240\u793a\uff1a

    \n\n

    \u00a0

    \n\n
    \nLogs \u8868\uff1a\n+----+-----+\n| Id | Num |\n+----+-----+\n| 1  | 1   |\n| 2  | 1   |\n| 3  | 1   |\n| 4  | 2   |\n| 5  | 1   |\n| 6  | 2   |\n| 7  | 2   |\n+----+-----+\n\nResult \u8868\uff1a\n+-----------------+\n| ConsecutiveNums |\n+-----------------+\n| 1               |\n+-----------------+\n1 \u662f\u552f\u4e00\u8fde\u7eed\u51fa\u73b0\u81f3\u5c11\u4e09\u6b21\u7684\u6570\u5b57\u3002\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0180](https://leetcode-cn.com/problems/consecutive-numbers)", "[\u8fde\u7eed\u51fa\u73b0\u7684\u6570\u5b57](/solution/0100-0199/0180.Consecutive%20Numbers/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0180](https://leetcode.com/problems/consecutive-numbers)", "[Consecutive Numbers](/solution/0100-0199/0180.Consecutive%20Numbers/README_EN.md)", "", "Medium", ""]}, {"question_id": "0179", "frontend_question_id": "0179", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/largest-number", "url_en": "https://leetcode.com/problems/largest-number", "relative_path_cn": "/solution/0100-0199/0179.Largest%20Number/README.md", "relative_path_en": "/solution/0100-0199/0179.Largest%20Number/README_EN.md", "title_cn": "\u6700\u5927\u6570", "title_en": "Largest Number", "question_title_slug": "largest-number", "content_en": "

    Given a list of non-negative integers nums, arrange them such that they form the largest number.

    \n\n

    Note: The result may be very large, so you need to return a string instead of an integer.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [10,2]\nOutput: "210"\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [3,30,34,5,9]\nOutput: "9534330"\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [1]\nOutput: "1"\n
    \n\n

    Example 4:

    \n\n
    \nInput: nums = [10]\nOutput: "10"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 100
    • \n\t
    • 0 <= nums[i] <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u7ec4\u975e\u8d1f\u6574\u6570 nums\uff0c\u91cd\u65b0\u6392\u5217\u6bcf\u4e2a\u6570\u7684\u987a\u5e8f\uff08\u6bcf\u4e2a\u6570\u4e0d\u53ef\u62c6\u5206\uff09\u4f7f\u4e4b\u7ec4\u6210\u4e00\u4e2a\u6700\u5927\u7684\u6574\u6570\u3002

    \n\n

    \u6ce8\u610f\uff1a\u8f93\u51fa\u7ed3\u679c\u53ef\u80fd\u975e\u5e38\u5927\uff0c\u6240\u4ee5\u4f60\u9700\u8981\u8fd4\u56de\u4e00\u4e2a\u5b57\u7b26\u4e32\u800c\u4e0d\u662f\u6574\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [10,2]\n\u8f93\u51fa\uff1a\"210\"
    \n\n

    \u793a\u4f8b\u00a02\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [3,30,34,5,9]\n\u8f93\u51fa\uff1a\"9534330\"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1]\n\u8f93\u51fa\uff1a\"1\"\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [10]\n\u8f93\u51fa\uff1a\"10\"\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 100
    • \n\t
    • 0 <= nums[i] <= 109
    • \n
    \n", "tags_en": ["Sort"], "tags_cn": ["\u6392\u5e8f"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string largestNumber(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String largestNumber(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def largestNumber(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def largestNumber(self, nums: List[int]) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * largestNumber(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string LargestNumber(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {string}\n */\nvar largestNumber = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {String}\ndef largest_number(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func largestNumber(_ nums: [Int]) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func largestNumber(nums []int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def largestNumber(nums: Array[Int]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun largestNumber(nums: IntArray): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn largest_number(nums: Vec) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return String\n */\n function largestNumber($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function largestNumber(nums: number[]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (largest-number nums)\n (-> (listof exact-integer?) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0179](https://leetcode-cn.com/problems/largest-number)", "[\u6700\u5927\u6570](/solution/0100-0199/0179.Largest%20Number/README.md)", "`\u6392\u5e8f`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0179](https://leetcode.com/problems/largest-number)", "[Largest Number](/solution/0100-0199/0179.Largest%20Number/README_EN.md)", "`Sort`", "Medium", ""]}, {"question_id": "0178", "frontend_question_id": "0178", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/rank-scores", "url_en": "https://leetcode.com/problems/rank-scores", "relative_path_cn": "/solution/0100-0199/0178.Rank%20Scores/README.md", "relative_path_en": "/solution/0100-0199/0178.Rank%20Scores/README_EN.md", "title_cn": "\u5206\u6570\u6392\u540d", "title_en": "Rank Scores", "question_title_slug": "rank-scores", "content_en": "

    Write a SQL query to rank scores. If there is a tie between two scores, both should have the same ranking. Note that after a tie, the next ranking number should be the next consecutive integer value. In other words, there should be no "holes" between ranks.

    \n\n
    \n+----+-------+\n| Id | Score |\n+----+-------+\n| 1  | 3.50  |\n| 2  | 3.65  |\n| 3  | 4.00  |\n| 4  | 3.85  |\n| 5  | 4.00  |\n| 6  | 3.65  |\n+----+-------+\n
    \n\n

    For example, given the above Scores table, your query should generate the following report (order by highest score):

    \n\n
    \n+-------+---------+\n| score | Rank    |\n+-------+---------+\n| 4.00  | 1       |\n| 4.00  | 1       |\n| 3.85  | 2       |\n| 3.65  | 3       |\n| 3.65  | 3       |\n| 3.50  | 4       |\n+-------+---------+\n
    \n\n

    Important Note: For MySQL solutions, to escape reserved words used as column names, you can use an apostrophe before and after the keyword. For example `Rank`.

    \n", "content_cn": "

    \u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\u6765\u5b9e\u73b0\u5206\u6570\u6392\u540d\u3002

    \n\n

    \u5982\u679c\u4e24\u4e2a\u5206\u6570\u76f8\u540c\uff0c\u5219\u4e24\u4e2a\u5206\u6570\u6392\u540d\uff08Rank\uff09\u76f8\u540c\u3002\u8bf7\u6ce8\u610f\uff0c\u5e73\u5206\u540e\u7684\u4e0b\u4e00\u4e2a\u540d\u6b21\u5e94\u8be5\u662f\u4e0b\u4e00\u4e2a\u8fde\u7eed\u7684\u6574\u6570\u503c\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u540d\u6b21\u4e4b\u95f4\u4e0d\u5e94\u8be5\u6709“\u95f4\u9694”\u3002

    \n\n
    +----+-------+\n| Id | Score |\n+----+-------+\n| 1  | 3.50  |\n| 2  | 3.65  |\n| 3  | 4.00  |\n| 4  | 3.85  |\n| 5  | 4.00  |\n| 6  | 3.65  |\n+----+-------+\n
    \n\n

    \u4f8b\u5982\uff0c\u6839\u636e\u4e0a\u8ff0\u7ed9\u5b9a\u7684 Scores \u8868\uff0c\u4f60\u7684\u67e5\u8be2\u5e94\u8be5\u8fd4\u56de\uff08\u6309\u5206\u6570\u4ece\u9ad8\u5230\u4f4e\u6392\u5217\uff09\uff1a

    \n\n
    +-------+------+\n| Score | Rank |\n+-------+------+\n| 4.00  | 1    |\n| 4.00  | 1    |\n| 3.85  | 2    |\n| 3.65  | 3    |\n| 3.65  | 3    |\n| 3.50  | 4    |\n+-------+------+\n
    \n\n

    \u91cd\u8981\u63d0\u793a\uff1a\u5bf9\u4e8e MySQL \u89e3\u51b3\u65b9\u6848\uff0c\u5982\u679c\u8981\u8f6c\u4e49\u7528\u4f5c\u5217\u540d\u7684\u4fdd\u7559\u5b57\uff0c\u53ef\u4ee5\u5728\u5173\u952e\u5b57\u4e4b\u524d\u548c\u4e4b\u540e\u4f7f\u7528\u6487\u53f7\u3002\u4f8b\u5982 `Rank`

    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0178](https://leetcode-cn.com/problems/rank-scores)", "[\u5206\u6570\u6392\u540d](/solution/0100-0199/0178.Rank%20Scores/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0178](https://leetcode.com/problems/rank-scores)", "[Rank Scores](/solution/0100-0199/0178.Rank%20Scores/README_EN.md)", "", "Medium", ""]}, {"question_id": "0177", "frontend_question_id": "0177", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/nth-highest-salary", "url_en": "https://leetcode.com/problems/nth-highest-salary", "relative_path_cn": "/solution/0100-0199/0177.Nth%20Highest%20Salary/README.md", "relative_path_en": "/solution/0100-0199/0177.Nth%20Highest%20Salary/README_EN.md", "title_cn": "\u7b2cN\u9ad8\u7684\u85aa\u6c34", "title_en": "Nth Highest Salary", "question_title_slug": "nth-highest-salary", "content_en": "

    Write a SQL query to get the nth highest salary from the Employee table.

    \r\n\r\n
    \r\n+----+--------+\r\n| Id | Salary |\r\n+----+--------+\r\n| 1  | 100    |\r\n| 2  | 200    |\r\n| 3  | 300    |\r\n+----+--------+\r\n
    \r\n\r\n

    For example, given the above Employee table, the nth highest salary where n = 2 is 200. If there is no nth highest salary, then the query should return null.

    \r\n\r\n
    \r\n+------------------------+\r\n| getNthHighestSalary(2) |\r\n+------------------------+\r\n| 200                    |\r\n+------------------------+\r\n
    \r\n", "content_cn": "

    \u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\uff0c\u83b7\u53d6 Employee \u8868\u4e2d\u7b2c \u9ad8\u7684\u85aa\u6c34\uff08Salary\uff09\u3002

    \n\n
    +----+--------+\n| Id | Salary |\n+----+--------+\n| 1  | 100    |\n| 2  | 200    |\n| 3  | 300    |\n+----+--------+\n
    \n\n

    \u4f8b\u5982\u4e0a\u8ff0 Employee \u8868\uff0cn = 2 \u65f6\uff0c\u5e94\u8fd4\u56de\u7b2c\u4e8c\u9ad8\u7684\u85aa\u6c34 200\u3002\u5982\u679c\u4e0d\u5b58\u5728\u7b2c \u9ad8\u7684\u85aa\u6c34\uff0c\u90a3\u4e48\u67e5\u8be2\u5e94\u8fd4\u56de null\u3002

    \n\n
    +------------------------+\n| getNthHighestSalary(2) |\n+------------------------+\n| 200                    |\n+------------------------+\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT\nBEGIN\n RETURN (\n # Write your MySQL query statement below.\n \n );\nEND", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "CREATE FUNCTION getNthHighestSalary(@N INT) RETURNS INT AS\nBEGIN\n RETURN (\n /* Write your T-SQL query statement below. */\n \n );\nEND", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "CREATE FUNCTION getNthHighestSalary(N IN NUMBER) RETURN NUMBER IS\nresult NUMBER;\nBEGIN\n /* Write your PL/SQL query statement below */\n \n RETURN result;\nEND;", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0177](https://leetcode-cn.com/problems/nth-highest-salary)", "[\u7b2cN\u9ad8\u7684\u85aa\u6c34](/solution/0100-0199/0177.Nth%20Highest%20Salary/README.md)", "", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0177](https://leetcode.com/problems/nth-highest-salary)", "[Nth Highest Salary](/solution/0100-0199/0177.Nth%20Highest%20Salary/README_EN.md)", "", "Medium", ""]}, {"question_id": "0176", "frontend_question_id": "0176", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/second-highest-salary", "url_en": "https://leetcode.com/problems/second-highest-salary", "relative_path_cn": "/solution/0100-0199/0176.Second%20Highest%20Salary/README.md", "relative_path_en": "/solution/0100-0199/0176.Second%20Highest%20Salary/README_EN.md", "title_cn": "\u7b2c\u4e8c\u9ad8\u7684\u85aa\u6c34", "title_en": "Second Highest Salary", "question_title_slug": "second-highest-salary", "content_en": "

    Write a SQL query to get the second highest salary from the Employee table.

    \r\n\r\n
    \r\n+----+--------+\r\n| Id | Salary |\r\n+----+--------+\r\n| 1  | 100    |\r\n| 2  | 200    |\r\n| 3  | 300    |\r\n+----+--------+\r\n
    \r\n\r\n

    For example, given the above Employee table, the query should return 200 as the second highest salary. If there is no second highest salary, then the query should return null.

    \r\n\r\n
    \r\n+---------------------+\r\n| SecondHighestSalary |\r\n+---------------------+\r\n| 200                 |\r\n+---------------------+\r\n
    \r\n", "content_cn": "

    \u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\uff0c\u83b7\u53d6 Employee \u8868\u4e2d\u7b2c\u4e8c\u9ad8\u7684\u85aa\u6c34\uff08Salary\uff09 \u3002

    \n\n
    +----+--------+\n| Id | Salary |\n+----+--------+\n| 1  | 100    |\n| 2  | 200    |\n| 3  | 300    |\n+----+--------+\n
    \n\n

    \u4f8b\u5982\u4e0a\u8ff0 Employee \u8868\uff0cSQL\u67e5\u8be2\u5e94\u8be5\u8fd4\u56de 200 \u4f5c\u4e3a\u7b2c\u4e8c\u9ad8\u7684\u85aa\u6c34\u3002\u5982\u679c\u4e0d\u5b58\u5728\u7b2c\u4e8c\u9ad8\u7684\u85aa\u6c34\uff0c\u90a3\u4e48\u67e5\u8be2\u5e94\u8fd4\u56de null\u3002

    \n\n
    +---------------------+\n| SecondHighestSalary |\n+---------------------+\n| 200                 |\n+---------------------+\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0176](https://leetcode-cn.com/problems/second-highest-salary)", "[\u7b2c\u4e8c\u9ad8\u7684\u85aa\u6c34](/solution/0100-0199/0176.Second%20Highest%20Salary/README.md)", "", "\u7b80\u5355", ""], "md_table_row_en": ["[0176](https://leetcode.com/problems/second-highest-salary)", "[Second Highest Salary](/solution/0100-0199/0176.Second%20Highest%20Salary/README_EN.md)", "", "Easy", ""]}, {"question_id": "0175", "frontend_question_id": "0175", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/combine-two-tables", "url_en": "https://leetcode.com/problems/combine-two-tables", "relative_path_cn": "/solution/0100-0199/0175.Combine%20Two%20Tables/README.md", "relative_path_en": "/solution/0100-0199/0175.Combine%20Two%20Tables/README_EN.md", "title_cn": "\u7ec4\u5408\u4e24\u4e2a\u8868", "title_en": "Combine Two Tables", "question_title_slug": "combine-two-tables", "content_en": "

    Table: Person

    \r\n\r\n
    \r\n+-------------+---------+\r\n| Column Name | Type    |\r\n+-------------+---------+\r\n| PersonId    | int     |\r\n| FirstName   | varchar |\r\n| LastName    | varchar |\r\n+-------------+---------+\r\nPersonId is the primary key column for this table.\r\n
    \r\n\r\n

    Table: Address

    \r\n\r\n
    \r\n+-------------+---------+\r\n| Column Name | Type    |\r\n+-------------+---------+\r\n| AddressId   | int     |\r\n| PersonId    | int     |\r\n| City        | varchar |\r\n| State       | varchar |\r\n+-------------+---------+\r\nAddressId is the primary key column for this table.\r\n
    \r\n\r\n

     

    \r\n\r\n

    Write a SQL query for a report that provides the following information for each person in the Person table, regardless if there is an address for each of those people:

    \r\n\r\n
    \r\nFirstName, LastName, City, State\r\n
    \r\n", "content_cn": "

    \u88681: Person

    \n\n
    +-------------+---------+\n| \u5217\u540d         | \u7c7b\u578b     |\n+-------------+---------+\n| PersonId    | int     |\n| FirstName   | varchar |\n| LastName    | varchar |\n+-------------+---------+\nPersonId \u662f\u4e0a\u8868\u4e3b\u952e\n
    \n\n

    \u88682: Address

    \n\n
    +-------------+---------+\n| \u5217\u540d         | \u7c7b\u578b    |\n+-------------+---------+\n| AddressId   | int     |\n| PersonId    | int     |\n| City        | varchar |\n| State       | varchar |\n+-------------+---------+\nAddressId \u662f\u4e0a\u8868\u4e3b\u952e\n
    \n\n

     

    \n\n

    \u7f16\u5199\u4e00\u4e2a SQL \u67e5\u8be2\uff0c\u6ee1\u8db3\u6761\u4ef6\uff1a\u65e0\u8bba person \u662f\u5426\u6709\u5730\u5740\u4fe1\u606f\uff0c\u90fd\u9700\u8981\u57fa\u4e8e\u4e0a\u8ff0\u4e24\u8868\u63d0\u4f9b person \u7684\u4ee5\u4e0b\u4fe1\u606f\uff1a

    \n\n

     

    \n\n
    FirstName, LastName, City, State\n
    \n", "tags_en": [], "tags_cn": [], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode"}, {"lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode"}, {"lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0175](https://leetcode-cn.com/problems/combine-two-tables)", "[\u7ec4\u5408\u4e24\u4e2a\u8868](/solution/0100-0199/0175.Combine%20Two%20Tables/README.md)", "", "\u7b80\u5355", ""], "md_table_row_en": ["[0175](https://leetcode.com/problems/combine-two-tables)", "[Combine Two Tables](/solution/0100-0199/0175.Combine%20Two%20Tables/README_EN.md)", "", "Easy", ""]}, {"question_id": "0174", "frontend_question_id": "0174", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/dungeon-game", "url_en": "https://leetcode.com/problems/dungeon-game", "relative_path_cn": "/solution/0100-0199/0174.Dungeon%20Game/README.md", "relative_path_en": "/solution/0100-0199/0174.Dungeon%20Game/README_EN.md", "title_cn": "\u5730\u4e0b\u57ce\u6e38\u620f", "title_en": "Dungeon Game", "question_title_slug": "dungeon-game", "content_en": "

    The demons had captured the princess and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of m x n rooms laid out in a 2D grid. Our valiant knight was initially positioned in the top-left room and must fight his way through dungeon to rescue the princess.

    \n\n

    The knight has an initial health point represented by a positive integer. If at any point his health point drops to 0 or below, he dies immediately.

    \n\n

    Some of the rooms are guarded by demons (represented by negative integers), so the knight loses health upon entering these rooms; other rooms are either empty (represented as 0) or contain magic orbs that increase the knight's health (represented by positive integers).

    \n\n

    To reach the princess as quickly as possible, the knight decides to move only rightward or downward in each step.

    \n\n

    Return the knight's minimum initial health so that he can rescue the princess.

    \n\n

    Note that any room can contain threats or power-ups, even the first room the knight enters and the bottom-right room where the princess is imprisoned.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: dungeon = [[-2,-3,3],[-5,-10,1],[10,30,-5]]\nOutput: 7\nExplanation: The initial health of the knight must be at least 7 if he follows the optimal path: RIGHT-> RIGHT -> DOWN -> DOWN.\n
    \n\n

    Example 2:

    \n\n
    \nInput: dungeon = [[0]]\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == dungeon.length
    • \n\t
    • n == dungeon[i].length
    • \n\t
    • 1 <= m, n <= 200
    • \n\t
    • -1000 <= dungeon[i][j] <= 1000
    • \n
    \n", "content_cn": "\r\n\r\n

    \u4e00\u4e9b\u6076\u9b54\u6293\u4f4f\u4e86\u516c\u4e3b\uff08P\uff09\u5e76\u5c06\u5979\u5173\u5728\u4e86\u5730\u4e0b\u57ce\u7684\u53f3\u4e0b\u89d2\u3002\u5730\u4e0b\u57ce\u662f\u7531 M x N \u4e2a\u623f\u95f4\u7ec4\u6210\u7684\u4e8c\u7ef4\u7f51\u683c\u3002\u6211\u4eec\u82f1\u52c7\u7684\u9a91\u58eb\uff08K\uff09\u6700\u521d\u88ab\u5b89\u7f6e\u5728\u5de6\u4e0a\u89d2\u7684\u623f\u95f4\u91cc\uff0c\u4ed6\u5fc5\u987b\u7a7f\u8fc7\u5730\u4e0b\u57ce\u5e76\u901a\u8fc7\u5bf9\u6297\u6076\u9b54\u6765\u62ef\u6551\u516c\u4e3b\u3002

    \r\n\r\n

    \u9a91\u58eb\u7684\u521d\u59cb\u5065\u5eb7\u70b9\u6570\u4e3a\u4e00\u4e2a\u6b63\u6574\u6570\u3002\u5982\u679c\u4ed6\u7684\u5065\u5eb7\u70b9\u6570\u5728\u67d0\u4e00\u65f6\u523b\u964d\u81f3 0 \u6216\u4ee5\u4e0b\uff0c\u4ed6\u4f1a\u7acb\u5373\u6b7b\u4ea1\u3002

    \r\n\r\n

    \u6709\u4e9b\u623f\u95f4\u7531\u6076\u9b54\u5b88\u536b\uff0c\u56e0\u6b64\u9a91\u58eb\u5728\u8fdb\u5165\u8fd9\u4e9b\u623f\u95f4\u65f6\u4f1a\u5931\u53bb\u5065\u5eb7\u70b9\u6570\uff08\u82e5\u623f\u95f4\u91cc\u7684\u503c\u4e3a\u8d1f\u6574\u6570\uff0c\u5219\u8868\u793a\u9a91\u58eb\u5c06\u635f\u5931\u5065\u5eb7\u70b9\u6570\uff09\uff1b\u5176\u4ed6\u623f\u95f4\u8981\u4e48\u662f\u7a7a\u7684\uff08\u623f\u95f4\u91cc\u7684\u503c\u4e3a 0\uff09\uff0c\u8981\u4e48\u5305\u542b\u589e\u52a0\u9a91\u58eb\u5065\u5eb7\u70b9\u6570\u7684\u9b54\u6cd5\u7403\uff08\u82e5\u623f\u95f4\u91cc\u7684\u503c\u4e3a\u6b63\u6574\u6570\uff0c\u5219\u8868\u793a\u9a91\u58eb\u5c06\u589e\u52a0\u5065\u5eb7\u70b9\u6570\uff09\u3002

    \r\n\r\n

    \u4e3a\u4e86\u5c3d\u5feb\u5230\u8fbe\u516c\u4e3b\uff0c\u9a91\u58eb\u51b3\u5b9a\u6bcf\u6b21\u53ea\u5411\u53f3\u6216\u5411\u4e0b\u79fb\u52a8\u4e00\u6b65\u3002

    \r\n\r\n

     

    \r\n\r\n

    \u7f16\u5199\u4e00\u4e2a\u51fd\u6570\u6765\u8ba1\u7b97\u786e\u4fdd\u9a91\u58eb\u80fd\u591f\u62ef\u6551\u5230\u516c\u4e3b\u6240\u9700\u7684\u6700\u4f4e\u521d\u59cb\u5065\u5eb7\u70b9\u6570\u3002

    \r\n\r\n

    \u4f8b\u5982\uff0c\u8003\u8651\u5230\u5982\u4e0b\u5e03\u5c40\u7684\u5730\u4e0b\u57ce\uff0c\u5982\u679c\u9a91\u58eb\u9075\u5faa\u6700\u4f73\u8def\u5f84 \u53f3 -> \u53f3 -> \u4e0b -> \u4e0b\uff0c\u5219\u9a91\u58eb\u7684\u521d\u59cb\u5065\u5eb7\u70b9\u6570\u81f3\u5c11\u4e3a 7\u3002

    \r\n\r\n\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
    -2 (K)-33
    -5-101
    1030-5 (P)
    \r\n\r\n\r\n

     

    \r\n\r\n

    \u8bf4\u660e:

    \r\n\r\n
      \r\n\t
    • \r\n\t

      \u9a91\u58eb\u7684\u5065\u5eb7\u70b9\u6570\u6ca1\u6709\u4e0a\u9650\u3002

      \r\n\t
    • \r\n\t
    • \u4efb\u4f55\u623f\u95f4\u90fd\u53ef\u80fd\u5bf9\u9a91\u58eb\u7684\u5065\u5eb7\u70b9\u6570\u9020\u6210\u5a01\u80c1\uff0c\u4e5f\u53ef\u80fd\u589e\u52a0\u9a91\u58eb\u7684\u5065\u5eb7\u70b9\u6570\uff0c\u5305\u62ec\u9a91\u58eb\u8fdb\u5165\u7684\u5de6\u4e0a\u89d2\u623f\u95f4\u4ee5\u53ca\u516c\u4e3b\u88ab\u76d1\u7981\u7684\u53f3\u4e0b\u89d2\u623f\u95f4\u3002
    • \r\n
    ", "tags_en": ["Binary Search", "Dynamic Programming"], "tags_cn": ["\u4e8c\u5206\u67e5\u627e", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int calculateMinimumHP(vector>& dungeon) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int calculateMinimumHP(int[][] dungeon) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def calculateMinimumHP(self, dungeon):\n \"\"\"\n :type dungeon: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def calculateMinimumHP(self, dungeon: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint calculateMinimumHP(int** dungeon, int dungeonSize, int* dungeonColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CalculateMinimumHP(int[][] dungeon) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} dungeon\n * @return {number}\n */\nvar calculateMinimumHP = function(dungeon) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} dungeon\n# @return {Integer}\ndef calculate_minimum_hp(dungeon)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func calculateMinimumHP(_ dungeon: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func calculateMinimumHP(dungeon [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def calculateMinimumHP(dungeon: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun calculateMinimumHP(dungeon: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn calculate_minimum_hp(dungeon: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $dungeon\n * @return Integer\n */\n function calculateMinimumHP($dungeon) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function calculateMinimumHP(dungeon: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (calculate-minimum-hp dungeon)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0174](https://leetcode-cn.com/problems/dungeon-game)", "[\u5730\u4e0b\u57ce\u6e38\u620f](/solution/0100-0199/0174.Dungeon%20Game/README.md)", "`\u4e8c\u5206\u67e5\u627e`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0174](https://leetcode.com/problems/dungeon-game)", "[Dungeon Game](/solution/0100-0199/0174.Dungeon%20Game/README_EN.md)", "`Binary Search`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0173", "frontend_question_id": "0173", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/binary-search-tree-iterator", "url_en": "https://leetcode.com/problems/binary-search-tree-iterator", "relative_path_cn": "/solution/0100-0199/0173.Binary%20Search%20Tree%20Iterator/README.md", "relative_path_en": "/solution/0100-0199/0173.Binary%20Search%20Tree%20Iterator/README_EN.md", "title_cn": "\u4e8c\u53c9\u641c\u7d22\u6811\u8fed\u4ee3\u5668", "title_en": "Binary Search Tree Iterator", "question_title_slug": "binary-search-tree-iterator", "content_en": "

    Implement the BSTIterator class that represents an iterator over the in-order traversal of a binary search tree (BST):

    \n\n
      \n\t
    • BSTIterator(TreeNode root) Initializes an object of the BSTIterator class. The root of the BST is given as part of the constructor. The pointer should be initialized to a non-existent number smaller than any element in the BST.
    • \n\t
    • boolean hasNext() Returns true if there exists a number in the traversal to the right of the pointer, otherwise returns false.
    • \n\t
    • int next() Moves the pointer to the right, then returns the number at the pointer.
    • \n
    \n\n

    Notice that by initializing the pointer to a non-existent smallest number, the first call to next() will return the smallest element in the BST.

    \n\n

    You may assume that next() calls will always be valid. That is, there will be at least a next number in the in-order traversal when next() is called.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput\n["BSTIterator", "next", "next", "hasNext", "next", "hasNext", "next", "hasNext", "next", "hasNext"]\n[[[7, 3, 15, null, null, 9, 20]], [], [], [], [], [], [], [], [], []]\nOutput\n[null, 3, 7, true, 9, true, 15, true, 20, false]\n\nExplanation\nBSTIterator bSTIterator = new BSTIterator([7, 3, 15, null, null, 9, 20]);\nbSTIterator.next();    // return 3\nbSTIterator.next();    // return 7\nbSTIterator.hasNext(); // return True\nbSTIterator.next();    // return 9\nbSTIterator.hasNext(); // return True\nbSTIterator.next();    // return 15\nbSTIterator.hasNext(); // return True\nbSTIterator.next();    // return 20\nbSTIterator.hasNext(); // return False\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 105].
    • \n\t
    • 0 <= Node.val <= 106
    • \n\t
    • At most 105 calls will be made to hasNext, and next.
    • \n
    \n\n

     

    \n

    Follow up:

    \n\n
      \n\t
    • Could you implement next() and hasNext() to run in average O(1) time and use O(h) memory, where h is the height of the tree?
    • \n
    \n", "content_cn": "\u5b9e\u73b0\u4e00\u4e2a\u4e8c\u53c9\u641c\u7d22\u6811\u8fed\u4ee3\u5668\u7c7bBSTIterator \uff0c\u8868\u793a\u4e00\u4e2a\u6309\u4e2d\u5e8f\u904d\u5386\u4e8c\u53c9\u641c\u7d22\u6811\uff08BST\uff09\u7684\u8fed\u4ee3\u5668\uff1a\n
    \n
    \n
      \n\t
    • BSTIterator(TreeNode root) \u521d\u59cb\u5316 BSTIterator \u7c7b\u7684\u4e00\u4e2a\u5bf9\u8c61\u3002BST \u7684\u6839\u8282\u70b9 root \u4f1a\u4f5c\u4e3a\u6784\u9020\u51fd\u6570\u7684\u4e00\u90e8\u5206\u7ed9\u51fa\u3002\u6307\u9488\u5e94\u521d\u59cb\u5316\u4e3a\u4e00\u4e2a\u4e0d\u5b58\u5728\u4e8e BST \u4e2d\u7684\u6570\u5b57\uff0c\u4e14\u8be5\u6570\u5b57\u5c0f\u4e8e BST \u4e2d\u7684\u4efb\u4f55\u5143\u7d20\u3002
    • \n\t
    • boolean hasNext() \u5982\u679c\u5411\u6307\u9488\u53f3\u4fa7\u904d\u5386\u5b58\u5728\u6570\u5b57\uff0c\u5219\u8fd4\u56de true \uff1b\u5426\u5219\u8fd4\u56de false \u3002
    • \n\t
    • int next()\u5c06\u6307\u9488\u5411\u53f3\u79fb\u52a8\uff0c\u7136\u540e\u8fd4\u56de\u6307\u9488\u5904\u7684\u6570\u5b57\u3002
    • \n
    \n\n

    \u6ce8\u610f\uff0c\u6307\u9488\u521d\u59cb\u5316\u4e3a\u4e00\u4e2a\u4e0d\u5b58\u5728\u4e8e BST \u4e2d\u7684\u6570\u5b57\uff0c\u6240\u4ee5\u5bf9 next() \u7684\u9996\u6b21\u8c03\u7528\u5c06\u8fd4\u56de BST \u4e2d\u7684\u6700\u5c0f\u5143\u7d20\u3002

    \n
    \n
    \n\n

    \u4f60\u53ef\u4ee5\u5047\u8bbe\u00a0next()\u00a0\u8c03\u7528\u603b\u662f\u6709\u6548\u7684\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u5f53\u8c03\u7528 next()\u00a0\u65f6\uff0cBST \u7684\u4e2d\u5e8f\u904d\u5386\u4e2d\u81f3\u5c11\u5b58\u5728\u4e00\u4e2a\u4e0b\u4e00\u4e2a\u6570\u5b57\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\"\"\n
    \n\u8f93\u5165\n[\"BSTIterator\", \"next\", \"next\", \"hasNext\", \"next\", \"hasNext\", \"next\", \"hasNext\", \"next\", \"hasNext\"]\n[[[7, 3, 15, null, null, 9, 20]], [], [], [], [], [], [], [], [], []]\n\u8f93\u51fa\n[null, 3, 7, true, 9, true, 15, true, 20, false]\n\n\u89e3\u91ca\nBSTIterator bSTIterator = new BSTIterator([7, 3, 15, null, null, 9, 20]);\nbSTIterator.next();    // \u8fd4\u56de 3\nbSTIterator.next();    // \u8fd4\u56de 7\nbSTIterator.hasNext(); // \u8fd4\u56de True\nbSTIterator.next();    // \u8fd4\u56de 9\nbSTIterator.hasNext(); // \u8fd4\u56de True\nbSTIterator.next();    // \u8fd4\u56de 15\nbSTIterator.hasNext(); // \u8fd4\u56de True\nbSTIterator.next();    // \u8fd4\u56de 20\nbSTIterator.hasNext(); // \u8fd4\u56de False\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u7684\u6570\u76ee\u5728\u8303\u56f4 [1, 105] \u5185
    • \n\t
    • 0 <= Node.val <= 106
    • \n\t
    • \u6700\u591a\u8c03\u7528 105 \u6b21 hasNext \u548c next \u64cd\u4f5c
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u4f60\u53ef\u4ee5\u8bbe\u8ba1\u4e00\u4e2a\u6ee1\u8db3\u4e0b\u8ff0\u6761\u4ef6\u7684\u89e3\u51b3\u65b9\u6848\u5417\uff1fnext() \u548c hasNext() \u64cd\u4f5c\u5747\u644a\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(1) \uff0c\u5e76\u4f7f\u7528 O(h) \u5185\u5b58\u3002\u5176\u4e2d h \u662f\u6811\u7684\u9ad8\u5ea6\u3002
    • \n
    \n", "tags_en": ["Stack", "Tree", "Design"], "tags_cn": ["\u6808", "\u6811", "\u8bbe\u8ba1"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass BSTIterator {\npublic:\n BSTIterator(TreeNode* root) {\n\n }\n \n int next() {\n\n }\n \n bool hasNext() {\n\n }\n};\n\n/**\n * Your BSTIterator object will be instantiated and called as such:\n * BSTIterator* obj = new BSTIterator(root);\n * int param_1 = obj->next();\n * bool param_2 = obj->hasNext();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass BSTIterator {\n\n public BSTIterator(TreeNode root) {\n\n }\n \n public int next() {\n\n }\n \n public boolean hasNext() {\n\n }\n}\n\n/**\n * Your BSTIterator object will be instantiated and called as such:\n * BSTIterator obj = new BSTIterator(root);\n * int param_1 = obj.next();\n * boolean param_2 = obj.hasNext();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass BSTIterator(object):\n\n def __init__(self, root):\n \"\"\"\n :type root: TreeNode\n \"\"\"\n\n\n def next(self):\n \"\"\"\n :rtype: int\n \"\"\"\n\n\n def hasNext(self):\n \"\"\"\n :rtype: bool\n \"\"\"\n\n\n\n# Your BSTIterator object will be instantiated and called as such:\n# obj = BSTIterator(root)\n# param_1 = obj.next()\n# param_2 = obj.hasNext()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass BSTIterator:\n\n def __init__(self, root: TreeNode):\n\n\n def next(self) -> int:\n\n\n def hasNext(self) -> bool:\n\n\n\n# Your BSTIterator object will be instantiated and called as such:\n# obj = BSTIterator(root)\n# param_1 = obj.next()\n# param_2 = obj.hasNext()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n\ntypedef struct {\n\n} BSTIterator;\n\n\nBSTIterator* bSTIteratorCreate(struct TreeNode* root) {\n\n}\n\nint bSTIteratorNext(BSTIterator* obj) {\n\n}\n\nbool bSTIteratorHasNext(BSTIterator* obj) {\n\n}\n\nvoid bSTIteratorFree(BSTIterator* obj) {\n\n}\n\n/**\n * Your BSTIterator struct will be instantiated and called as such:\n * BSTIterator* obj = bSTIteratorCreate(root);\n * int param_1 = bSTIteratorNext(obj);\n \n * bool param_2 = bSTIteratorHasNext(obj);\n \n * bSTIteratorFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class BSTIterator {\n\n public BSTIterator(TreeNode root) {\n\n }\n \n public int Next() {\n\n }\n \n public bool HasNext() {\n\n }\n}\n\n/**\n * Your BSTIterator object will be instantiated and called as such:\n * BSTIterator obj = new BSTIterator(root);\n * int param_1 = obj.Next();\n * bool param_2 = obj.HasNext();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n */\nvar BSTIterator = function(root) {\n\n};\n\n/**\n * @return {number}\n */\nBSTIterator.prototype.next = function() {\n\n};\n\n/**\n * @return {boolean}\n */\nBSTIterator.prototype.hasNext = function() {\n\n};\n\n/**\n * Your BSTIterator object will be instantiated and called as such:\n * var obj = new BSTIterator(root)\n * var param_1 = obj.next()\n * var param_2 = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\nclass BSTIterator\n\n=begin\n :type root: TreeNode\n=end\n def initialize(root)\n\n end\n\n\n=begin\n :rtype: Integer\n=end\n def next()\n\n end\n\n\n=begin\n :rtype: Boolean\n=end\n def has_next()\n\n end\n\n\nend\n\n# Your BSTIterator object will be instantiated and called as such:\n# obj = BSTIterator.new(root)\n# param_1 = obj.next()\n# param_2 = obj.has_next()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\n\nclass BSTIterator {\n\n init(_ root: TreeNode?) {\n\n }\n \n func next() -> Int {\n\n }\n \n func hasNext() -> Bool {\n\n }\n}\n\n/**\n * Your BSTIterator object will be instantiated and called as such:\n * let obj = BSTIterator(root)\n * let ret_1: Int = obj.next()\n * let ret_2: Bool = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\ntype BSTIterator struct {\n\n}\n\n\nfunc Constructor(root *TreeNode) BSTIterator {\n\n}\n\n\nfunc (this *BSTIterator) Next() int {\n\n}\n\n\nfunc (this *BSTIterator) HasNext() bool {\n\n}\n\n\n/**\n * Your BSTIterator object will be instantiated and called as such:\n * obj := Constructor(root);\n * param_1 := obj.Next();\n * param_2 := obj.HasNext();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nclass BSTIterator(_root: TreeNode) {\n\n def next(): Int = {\n\n }\n\n def hasNext(): Boolean = {\n\n }\n\n}\n\n/**\n * Your BSTIterator object will be instantiated and called as such:\n * var obj = new BSTIterator(root)\n * var param_1 = obj.next()\n * var param_2 = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass BSTIterator(root: TreeNode?) {\n\n fun next(): Int {\n\n }\n\n fun hasNext(): Boolean {\n\n }\n\n}\n\n/**\n * Your BSTIterator object will be instantiated and called as such:\n * var obj = BSTIterator(root)\n * var param_1 = obj.next()\n * var param_2 = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nstruct BSTIterator {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl BSTIterator {\n\n fn new(root: Option>>) -> Self {\n\n }\n \n fn next(&self) -> i32 {\n\n }\n \n fn has_next(&self) -> bool {\n\n }\n}\n\n/**\n * Your BSTIterator object will be instantiated and called as such:\n * let obj = BSTIterator::new(root);\n * let ret_1: i32 = obj.next();\n * let ret_2: bool = obj.has_next();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass BSTIterator {\n /**\n * @param TreeNode $root\n */\n function __construct($root) {\n\n }\n\n /**\n * @return Integer\n */\n function next() {\n\n }\n\n /**\n * @return Boolean\n */\n function hasNext() {\n\n }\n}\n\n/**\n * Your BSTIterator object will be instantiated and called as such:\n * $obj = BSTIterator($root);\n * $ret_1 = $obj->next();\n * $ret_2 = $obj->hasNext();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nclass BSTIterator {\n constructor(root: TreeNode | null) {\n\n }\n\n next(): number {\n\n }\n\n hasNext(): boolean {\n\n }\n}\n\n/**\n * Your BSTIterator object will be instantiated and called as such:\n * var obj = new BSTIterator(root)\n * var param_1 = obj.next()\n * var param_2 = obj.hasNext()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define bst-iterator%\n (class object%\n (super-new)\n\n ; root : (or/c tree-node? #f)\n (init-field\n root)\n \n ; next : -> exact-integer?\n (define/public (next)\n\n )\n ; has-next : -> boolean?\n (define/public (has-next)\n\n )))\n\n;; Your bst-iterator% object will be instantiated and called as such:\n;; (define obj (new bst-iterator% [root root]))\n;; (define param_1 (send obj next))\n;; (define param_2 (send obj has-next))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0173](https://leetcode-cn.com/problems/binary-search-tree-iterator)", "[\u4e8c\u53c9\u641c\u7d22\u6811\u8fed\u4ee3\u5668](/solution/0100-0199/0173.Binary%20Search%20Tree%20Iterator/README.md)", "`\u6808`,`\u6811`,`\u8bbe\u8ba1`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0173](https://leetcode.com/problems/binary-search-tree-iterator)", "[Binary Search Tree Iterator](/solution/0100-0199/0173.Binary%20Search%20Tree%20Iterator/README_EN.md)", "`Stack`,`Tree`,`Design`", "Medium", ""]}, {"question_id": "0172", "frontend_question_id": "0172", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/factorial-trailing-zeroes", "url_en": "https://leetcode.com/problems/factorial-trailing-zeroes", "relative_path_cn": "/solution/0100-0199/0172.Factorial%20Trailing%20Zeroes/README.md", "relative_path_en": "/solution/0100-0199/0172.Factorial%20Trailing%20Zeroes/README_EN.md", "title_cn": "\u9636\u4e58\u540e\u7684\u96f6", "title_en": "Factorial Trailing Zeroes", "question_title_slug": "factorial-trailing-zeroes", "content_en": "

    Given an integer n, return the number of trailing zeroes in n!.

    \n\n

    Follow up: Could you write a solution that works in logarithmic time complexity?

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 3\nOutput: 0\nExplanation: 3! = 6, no trailing zero.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 5\nOutput: 1\nExplanation: 5! = 120, one trailing zero.\n
    \n\n

    Example 3:

    \n\n
    \nInput: n = 0\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= n <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570 n\uff0c\u8fd4\u56de n! \u7ed3\u679c\u5c3e\u6570\u4e2d\u96f6\u7684\u6570\u91cf\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: 3\n\u8f93\u51fa: 0\n\u89e3\u91ca: 3! = 6, \u5c3e\u6570\u4e2d\u6ca1\u6709\u96f6\u3002
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: 5\n\u8f93\u51fa: 1\n\u89e3\u91ca: 5! = 120, \u5c3e\u6570\u4e2d\u6709 1 \u4e2a\u96f6.
    \n\n

    \u8bf4\u660e: \u4f60\u7b97\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u5e94\u4e3a O(log n) \u3002

    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int trailingZeroes(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int trailingZeroes(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def trailingZeroes(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def trailingZeroes(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint trailingZeroes(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int TrailingZeroes(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar trailingZeroes = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef trailing_zeroes(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func trailingZeroes(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func trailingZeroes(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def trailingZeroes(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun trailingZeroes(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn trailing_zeroes(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function trailingZeroes($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function trailingZeroes(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (trailing-zeroes n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0172](https://leetcode-cn.com/problems/factorial-trailing-zeroes)", "[\u9636\u4e58\u540e\u7684\u96f6](/solution/0100-0199/0172.Factorial%20Trailing%20Zeroes/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0172](https://leetcode.com/problems/factorial-trailing-zeroes)", "[Factorial Trailing Zeroes](/solution/0100-0199/0172.Factorial%20Trailing%20Zeroes/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "0171", "frontend_question_id": "0171", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/excel-sheet-column-number", "url_en": "https://leetcode.com/problems/excel-sheet-column-number", "relative_path_cn": "/solution/0100-0199/0171.Excel%20Sheet%20Column%20Number/README.md", "relative_path_en": "/solution/0100-0199/0171.Excel%20Sheet%20Column%20Number/README_EN.md", "title_cn": "Excel\u8868\u5217\u5e8f\u53f7", "title_en": "Excel Sheet Column Number", "question_title_slug": "excel-sheet-column-number", "content_en": "

    Given a string columnTitle that represents the column title as appear in an Excel sheet, return its corresponding column number.

    \n\n

    For example:

    \n\n
    \nA -> 1\nB -> 2\nC -> 3\n...\nZ -> 26\nAA -> 27\nAB -> 28 \n...\n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: columnTitle = "A"\nOutput: 1\n
    \n\n

    Example 2:

    \n\n
    \nInput: columnTitle = "AB"\nOutput: 28\n
    \n\n

    Example 3:

    \n\n
    \nInput: columnTitle = "ZY"\nOutput: 701\n
    \n\n

    Example 4:

    \n\n
    \nInput: columnTitle = "FXSHRXW"\nOutput: 2147483647\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= columnTitle.length <= 7
    • \n\t
    • columnTitle consists only of uppercase English letters.
    • \n\t
    • columnTitle is in the range ["A", "FXSHRXW"].
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2aExcel\u8868\u683c\u4e2d\u7684\u5217\u540d\u79f0\uff0c\u8fd4\u56de\u5176\u76f8\u5e94\u7684\u5217\u5e8f\u53f7\u3002

    \n\n

    \u4f8b\u5982\uff0c

    \n\n
        A -> 1\n    B -> 2\n    C -> 3\n    ...\n    Z -> 26\n    AA -> 27\n    AB -> 28 \n    ...\n
    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: "A"\n\u8f93\u51fa: 1\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: "AB"\n\u8f93\u51fa: 28\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u8f93\u5165: "ZY"\n\u8f93\u51fa: 701
    \n\n

    \u81f4\u8c22\uff1a
    \n\u7279\u522b\u611f\u8c22 @ts \u6dfb\u52a0\u6b64\u95ee\u9898\u5e76\u521b\u5efa\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002

    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int titleToNumber(string columnTitle) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int titleToNumber(String columnTitle) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def titleToNumber(self, columnTitle):\n \"\"\"\n :type columnTitle: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def titleToNumber(self, columnTitle: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint titleToNumber(char * columnTitle){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int TitleToNumber(string columnTitle) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} columnTitle\n * @return {number}\n */\nvar titleToNumber = function(columnTitle) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} column_title\n# @return {Integer}\ndef title_to_number(column_title)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func titleToNumber(_ columnTitle: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func titleToNumber(columnTitle string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def titleToNumber(columnTitle: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun titleToNumber(columnTitle: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn title_to_number(column_title: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $columnTitle\n * @return Integer\n */\n function titleToNumber($columnTitle) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function titleToNumber(columnTitle: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (title-to-number columnTitle)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0171](https://leetcode-cn.com/problems/excel-sheet-column-number)", "[Excel\u8868\u5217\u5e8f\u53f7](/solution/0100-0199/0171.Excel%20Sheet%20Column%20Number/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0171](https://leetcode.com/problems/excel-sheet-column-number)", "[Excel Sheet Column Number](/solution/0100-0199/0171.Excel%20Sheet%20Column%20Number/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "0170", "frontend_question_id": "0170", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/two-sum-iii-data-structure-design", "url_en": "https://leetcode.com/problems/two-sum-iii-data-structure-design", "relative_path_cn": "/solution/0100-0199/0170.Two%20Sum%20III%20-%20Data%20structure%20design/README.md", "relative_path_en": "/solution/0100-0199/0170.Two%20Sum%20III%20-%20Data%20structure%20design/README_EN.md", "title_cn": "\u4e24\u6570\u4e4b\u548c III - \u6570\u636e\u7ed3\u6784\u8bbe\u8ba1", "title_en": "Two Sum III - Data structure design", "question_title_slug": "two-sum-iii-data-structure-design", "content_en": "

    Design a data structure that accepts a stream of integers and checks if it has a pair of integers that sum up to a particular value.

    \n\n

    Implement the TwoSum class:

    \n\n
      \n\t
    • TwoSum() Initializes the TwoSum object, with an empty array initially.
    • \n\t
    • void add(int number) Adds number to the data structure.
    • \n\t
    • boolean find(int value) Returns true if there exists any pair of numbers whose sum is equal to value, otherwise, it returns false.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["TwoSum", "add", "add", "add", "find", "find"]\n[[], [1], [3], [5], [4], [7]]\nOutput\n[null, null, null, null, true, false]\n\nExplanation\nTwoSum twoSum = new TwoSum();\ntwoSum.add(1);   // [] --> [1]\ntwoSum.add(3);   // [1] --> [1,3]\ntwoSum.add(5);   // [1,3] --> [1,3,5]\ntwoSum.find(4);  // 1 + 3 = 4, return true\ntwoSum.find(7);  // No two integers sum up to 7, return false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • -105 <= number <= 105
    • \n\t
    • -231 <= value <= 231 - 1
    • \n\t
    • At most 5 * 104 calls will be made to add and find.
    • \n
    \n", "content_cn": "

    \u8bbe\u8ba1\u4e00\u4e2a\u63a5\u6536\u6574\u6570\u6d41\u7684\u6570\u636e\u7ed3\u6784\uff0c\u8be5\u6570\u636e\u7ed3\u6784\u652f\u6301\u68c0\u67e5\u662f\u5426\u5b58\u5728\u4e24\u6570\u4e4b\u548c\u7b49\u4e8e\u7279\u5b9a\u503c\u3002

    \n\n

    \u5b9e\u73b0 TwoSum \u7c7b\uff1a

    \n\n
      \n\t
    • TwoSum() \u4f7f\u7528\u7a7a\u6570\u7ec4\u521d\u59cb\u5316 TwoSum \u5bf9\u8c61
    • \n\t
    • void add(int number) \u5411\u6570\u636e\u7ed3\u6784\u6dfb\u52a0\u4e00\u4e2a\u6570 number
    • \n\t
    • boolean find(int value) \u5bfb\u627e\u6570\u636e\u7ed3\u6784\u4e2d\u662f\u5426\u5b58\u5728\u4e00\u5bf9\u6574\u6570\uff0c\u4f7f\u5f97\u4e24\u6570\u4e4b\u548c\u4e0e\u7ed9\u5b9a\u7684\u503c\u76f8\u7b49\u3002\u5982\u679c\u5b58\u5728\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1a\n[\"TwoSum\", \"add\", \"add\", \"add\", \"find\", \"find\"]\n[[], [1], [3], [5], [4], [7]]\n\u8f93\u51fa\uff1a\n[null, null, null, null, true, false]\n\n\u89e3\u91ca\uff1a\nTwoSum twoSum = new TwoSum();\ntwoSum.add(1);   // [] --> [1]\ntwoSum.add(3);   // [1] --> [1,3]\ntwoSum.add(5);   // [1,3] --> [1,3,5]\ntwoSum.find(4);  // 1 + 3 = 4\uff0c\u8fd4\u56de true\ntwoSum.find(7);  // \u6ca1\u6709\u4e24\u4e2a\u6574\u6570\u52a0\u8d77\u6765\u7b49\u4e8e 7 \uff0c\u8fd4\u56de false
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • -105 <= number <= 105
    • \n\t
    • -231 <= value <= 231 - 1
    • \n\t
    • \u6700\u591a\u8c03\u7528 5 * 104 \u6b21 add \u548c find
    • \n
    \n", "tags_en": ["Design", "Hash Table"], "tags_cn": ["\u8bbe\u8ba1", "\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class TwoSum {\npublic:\n /** Initialize your data structure here. */\n TwoSum() {\n\n }\n \n /** Add the number to an internal data structure.. */\n void add(int number) {\n\n }\n \n /** Find if there exists any pair of numbers which sum is equal to the value. */\n bool find(int value) {\n\n }\n};\n\n/**\n * Your TwoSum object will be instantiated and called as such:\n * TwoSum* obj = new TwoSum();\n * obj->add(number);\n * bool param_2 = obj->find(value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class TwoSum {\n\n /** Initialize your data structure here. */\n public TwoSum() {\n\n }\n \n /** Add the number to an internal data structure.. */\n public void add(int number) {\n\n }\n \n /** Find if there exists any pair of numbers which sum is equal to the value. */\n public boolean find(int value) {\n\n }\n}\n\n/**\n * Your TwoSum object will be instantiated and called as such:\n * TwoSum obj = new TwoSum();\n * obj.add(number);\n * boolean param_2 = obj.find(value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class TwoSum(object):\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def add(self, number):\n \"\"\"\n Add the number to an internal data structure..\n :type number: int\n :rtype: None\n \"\"\"\n\n\n def find(self, value):\n \"\"\"\n Find if there exists any pair of numbers which sum is equal to the value.\n :type value: int\n :rtype: bool\n \"\"\"\n\n\n\n# Your TwoSum object will be instantiated and called as such:\n# obj = TwoSum()\n# obj.add(number)\n# param_2 = obj.find(value)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class TwoSum:\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n\n\n def add(self, number: int) -> None:\n \"\"\"\n Add the number to an internal data structure..\n \"\"\"\n\n\n def find(self, value: int) -> bool:\n \"\"\"\n Find if there exists any pair of numbers which sum is equal to the value.\n \"\"\"\n\n\n\n# Your TwoSum object will be instantiated and called as such:\n# obj = TwoSum()\n# obj.add(number)\n# param_2 = obj.find(value)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} TwoSum;\n\n/** Initialize your data structure here. */\n\nTwoSum* twoSumCreate() {\n\n}\n\n/** Add the number to an internal data structure.. */\nvoid twoSumAdd(TwoSum* obj, int number) {\n\n}\n\n/** Find if there exists any pair of numbers which sum is equal to the value. */\nbool twoSumFind(TwoSum* obj, int value) {\n\n}\n\nvoid twoSumFree(TwoSum* obj) {\n\n}\n\n/**\n * Your TwoSum struct will be instantiated and called as such:\n * TwoSum* obj = twoSumCreate();\n * twoSumAdd(obj, number);\n \n * bool param_2 = twoSumFind(obj, value);\n \n * twoSumFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class TwoSum {\n\n /** Initialize your data structure here. */\n public TwoSum() {\n\n }\n \n /** Add the number to an internal data structure.. */\n public void Add(int number) {\n\n }\n \n /** Find if there exists any pair of numbers which sum is equal to the value. */\n public bool Find(int value) {\n\n }\n}\n\n/**\n * Your TwoSum object will be instantiated and called as such:\n * TwoSum obj = new TwoSum();\n * obj.Add(number);\n * bool param_2 = obj.Find(value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Initialize your data structure here.\n */\nvar TwoSum = function() {\n\n};\n\n/**\n * Add the number to an internal data structure.. \n * @param {number} number\n * @return {void}\n */\nTwoSum.prototype.add = function(number) {\n\n};\n\n/**\n * Find if there exists any pair of numbers which sum is equal to the value. \n * @param {number} value\n * @return {boolean}\n */\nTwoSum.prototype.find = function(value) {\n\n};\n\n/**\n * Your TwoSum object will be instantiated and called as such:\n * var obj = new TwoSum()\n * obj.add(number)\n * var param_2 = obj.find(value)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class TwoSum\n\n=begin\n Initialize your data structure here.\n=end\n def initialize()\n\n end\n\n\n=begin\n Add the number to an internal data structure..\n :type number: Integer\n :rtype: Void\n=end\n def add(number)\n\n end\n\n\n=begin\n Find if there exists any pair of numbers which sum is equal to the value.\n :type value: Integer\n :rtype: Boolean\n=end\n def find(value)\n\n end\n\n\nend\n\n# Your TwoSum object will be instantiated and called as such:\n# obj = TwoSum.new()\n# obj.add(number)\n# param_2 = obj.find(value)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass TwoSum {\n\n /** Initialize your data structure here. */\n init() {\n\n }\n \n /** Add the number to an internal data structure.. */\n func add(_ number: Int) {\n\n }\n \n /** Find if there exists any pair of numbers which sum is equal to the value. */\n func find(_ value: Int) -> Bool {\n\n }\n}\n\n/**\n * Your TwoSum object will be instantiated and called as such:\n * let obj = TwoSum()\n * obj.add(number)\n * let ret_2: Bool = obj.find(value)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type TwoSum struct {\n\n}\n\n\n/** Initialize your data structure here. */\nfunc Constructor() TwoSum {\n\n}\n\n\n/** Add the number to an internal data structure.. */\nfunc (this *TwoSum) Add(number int) {\n\n}\n\n\n/** Find if there exists any pair of numbers which sum is equal to the value. */\nfunc (this *TwoSum) Find(value int) bool {\n\n}\n\n\n/**\n * Your TwoSum object will be instantiated and called as such:\n * obj := Constructor();\n * obj.Add(number);\n * param_2 := obj.Find(value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class TwoSum() {\n\n /** Initialize your data structure here. */\n\n\n /** Add the number to an internal data structure.. */\n def add(number: Int) {\n\n }\n\n /** Find if there exists any pair of numbers which sum is equal to the value. */\n def find(value: Int): Boolean = {\n\n }\n\n}\n\n/**\n * Your TwoSum object will be instantiated and called as such:\n * var obj = new TwoSum()\n * obj.add(number)\n * var param_2 = obj.find(value)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class TwoSum() {\n\n /** Initialize your data structure here. */\n\n\n /** Add the number to an internal data structure.. */\n fun add(number: Int) {\n\n }\n\n /** Find if there exists any pair of numbers which sum is equal to the value. */\n fun find(value: Int): Boolean {\n\n }\n\n}\n\n/**\n * Your TwoSum object will be instantiated and called as such:\n * var obj = TwoSum()\n * obj.add(number)\n * var param_2 = obj.find(value)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct TwoSum {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl TwoSum {\n\n /** Initialize your data structure here. */\n fn new() -> Self {\n\n }\n \n /** Add the number to an internal data structure.. */\n fn add(&self, number: i32) {\n\n }\n \n /** Find if there exists any pair of numbers which sum is equal to the value. */\n fn find(&self, value: i32) -> bool {\n\n }\n}\n\n/**\n * Your TwoSum object will be instantiated and called as such:\n * let obj = TwoSum::new();\n * obj.add(number);\n * let ret_2: bool = obj.find(value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class TwoSum {\n /**\n * Initialize your data structure here.\n */\n function __construct() {\n\n }\n\n /**\n * Add the number to an internal data structure..\n * @param Integer $number\n * @return NULL\n */\n function add($number) {\n\n }\n\n /**\n * Find if there exists any pair of numbers which sum is equal to the value.\n * @param Integer $value\n * @return Boolean\n */\n function find($value) {\n\n }\n}\n\n/**\n * Your TwoSum object will be instantiated and called as such:\n * $obj = TwoSum();\n * $obj->add($number);\n * $ret_2 = $obj->find($value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class TwoSum {\n constructor() {\n\n }\n\n add(number: number): void {\n\n }\n\n find(value: number): boolean {\n\n }\n}\n\n/**\n * Your TwoSum object will be instantiated and called as such:\n * var obj = new TwoSum()\n * obj.add(number)\n * var param_2 = obj.find(value)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define two-sum%\n (class object%\n (super-new)\n (init-field)\n \n ; add : exact-integer? -> void?\n (define/public (add number)\n\n )\n ; find : exact-integer? -> boolean?\n (define/public (find value)\n\n )))\n\n;; Your two-sum% object will be instantiated and called as such:\n;; (define obj (new two-sum%))\n;; (send obj add number)\n;; (define param_2 (send obj find value))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0170](https://leetcode-cn.com/problems/two-sum-iii-data-structure-design)", "[\u4e24\u6570\u4e4b\u548c III - \u6570\u636e\u7ed3\u6784\u8bbe\u8ba1](/solution/0100-0199/0170.Two%20Sum%20III%20-%20Data%20structure%20design/README.md)", "`\u8bbe\u8ba1`,`\u54c8\u5e0c\u8868`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0170](https://leetcode.com/problems/two-sum-iii-data-structure-design)", "[Two Sum III - Data structure design](/solution/0100-0199/0170.Two%20Sum%20III%20-%20Data%20structure%20design/README_EN.md)", "`Design`,`Hash Table`", "Easy", "\ud83d\udd12"]}, {"question_id": "0169", "frontend_question_id": "0169", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/majority-element", "url_en": "https://leetcode.com/problems/majority-element", "relative_path_cn": "/solution/0100-0199/0169.Majority%20Element/README.md", "relative_path_en": "/solution/0100-0199/0169.Majority%20Element/README_EN.md", "title_cn": "\u591a\u6570\u5143\u7d20", "title_en": "Majority Element", "question_title_slug": "majority-element", "content_en": "

    Given an array nums of size n, return the majority element.

    \n\n

    The majority element is the element that appears more than ⌊n / 2⌋ times. You may assume that the majority element always exists in the array.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [3,2,3]\nOutput: 3\n

    Example 2:

    \n
    Input: nums = [2,2,1,1,1,2,2]\nOutput: 2\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= n <= 5 * 104
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n
    \n\n

     

    \nFollow-up: Could you solve the problem in linear time and in O(1) space?", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5927\u5c0f\u4e3a n \u7684\u6570\u7ec4\uff0c\u627e\u5230\u5176\u4e2d\u7684\u591a\u6570\u5143\u7d20\u3002\u591a\u6570\u5143\u7d20\u662f\u6307\u5728\u6570\u7ec4\u4e2d\u51fa\u73b0\u6b21\u6570 \u5927\u4e8e\u00a0\u230a n/2 \u230b\u00a0\u7684\u5143\u7d20\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u5047\u8bbe\u6570\u7ec4\u662f\u975e\u7a7a\u7684\uff0c\u5e76\u4e14\u7ed9\u5b9a\u7684\u6570\u7ec4\u603b\u662f\u5b58\u5728\u591a\u6570\u5143\u7d20\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\u00a01\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[3,2,3]\n\u8f93\u51fa\uff1a3
    \n\n

    \u793a\u4f8b\u00a02\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[2,2,1,1,1,2,2]\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u5c1d\u8bd5\u8bbe\u8ba1\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\u3001\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a O(1) \u7684\u7b97\u6cd5\u89e3\u51b3\u6b64\u95ee\u9898\u3002
    • \n
    \n", "tags_en": ["Bit Manipulation", "Array", "Divide and Conquer"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u6570\u7ec4", "\u5206\u6cbb\u7b97\u6cd5"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int majorityElement(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int majorityElement(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def majorityElement(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def majorityElement(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint majorityElement(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MajorityElement(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar majorityElement = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef majority_element(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func majorityElement(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func majorityElement(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def majorityElement(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun majorityElement(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn majority_element(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function majorityElement($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function majorityElement(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (majority-element nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0169](https://leetcode-cn.com/problems/majority-element)", "[\u591a\u6570\u5143\u7d20](/solution/0100-0199/0169.Majority%20Element/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u6570\u7ec4`,`\u5206\u6cbb\u7b97\u6cd5`", "\u7b80\u5355", ""], "md_table_row_en": ["[0169](https://leetcode.com/problems/majority-element)", "[Majority Element](/solution/0100-0199/0169.Majority%20Element/README_EN.md)", "`Bit Manipulation`,`Array`,`Divide and Conquer`", "Easy", ""]}, {"question_id": "0168", "frontend_question_id": "0168", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/excel-sheet-column-title", "url_en": "https://leetcode.com/problems/excel-sheet-column-title", "relative_path_cn": "/solution/0100-0199/0168.Excel%20Sheet%20Column%20Title/README.md", "relative_path_en": "/solution/0100-0199/0168.Excel%20Sheet%20Column%20Title/README_EN.md", "title_cn": "Excel\u8868\u5217\u540d\u79f0", "title_en": "Excel Sheet Column Title", "question_title_slug": "excel-sheet-column-title", "content_en": "

    Given an integer columnNumber, return its corresponding column title as it appears in an Excel sheet.

    \n\n

    For example:

    \n\n
    \nA -> 1\nB -> 2\nC -> 3\n...\nZ -> 26\nAA -> 27\nAB -> 28 \n...\n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: columnNumber = 1\nOutput: "A"\n
    \n\n

    Example 2:

    \n\n
    \nInput: columnNumber = 28\nOutput: "AB"\n
    \n\n

    Example 3:

    \n\n
    \nInput: columnNumber = 701\nOutput: "ZY"\n
    \n\n

    Example 4:

    \n\n
    \nInput: columnNumber = 2147483647\nOutput: "FXSHRXW"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= columnNumber <= 231 - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6b63\u6574\u6570\uff0c\u8fd4\u56de\u5b83\u5728 Excel \u8868\u4e2d\u76f8\u5bf9\u5e94\u7684\u5217\u540d\u79f0\u3002

    \n\n

    \u4f8b\u5982\uff0c

    \n\n
        1 -> A\n    2 -> B\n    3 -> C\n    ...\n    26 -> Z\n    27 -> AA\n    28 -> AB \n    ...\n
    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: 1\n\u8f93\u51fa: "A"\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: 28\n\u8f93\u51fa: "AB"\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u8f93\u5165: 701\n\u8f93\u51fa: "ZY"\n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string convertToTitle(int columnNumber) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String convertToTitle(int columnNumber) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def convertToTitle(self, columnNumber):\n \"\"\"\n :type columnNumber: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def convertToTitle(self, columnNumber: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * convertToTitle(int columnNumber){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ConvertToTitle(int columnNumber) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} columnNumber\n * @return {string}\n */\nvar convertToTitle = function(columnNumber) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} column_number\n# @return {String}\ndef convert_to_title(column_number)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func convertToTitle(_ columnNumber: Int) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func convertToTitle(columnNumber int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def convertToTitle(columnNumber: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun convertToTitle(columnNumber: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn convert_to_title(column_number: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $columnNumber\n * @return String\n */\n function convertToTitle($columnNumber) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function convertToTitle(columnNumber: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (convert-to-title columnNumber)\n (-> exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0168](https://leetcode-cn.com/problems/excel-sheet-column-title)", "[Excel\u8868\u5217\u540d\u79f0](/solution/0100-0199/0168.Excel%20Sheet%20Column%20Title/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0168](https://leetcode.com/problems/excel-sheet-column-title)", "[Excel Sheet Column Title](/solution/0100-0199/0168.Excel%20Sheet%20Column%20Title/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "0167", "frontend_question_id": "0167", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/two-sum-ii-input-array-is-sorted", "url_en": "https://leetcode.com/problems/two-sum-ii-input-array-is-sorted", "relative_path_cn": "/solution/0100-0199/0167.Two%20Sum%20II%20-%20Input%20array%20is%20sorted/README.md", "relative_path_en": "/solution/0100-0199/0167.Two%20Sum%20II%20-%20Input%20array%20is%20sorted/README_EN.md", "title_cn": "\u4e24\u6570\u4e4b\u548c II - \u8f93\u5165\u6709\u5e8f\u6570\u7ec4", "title_en": "Two Sum II - Input array is sorted", "question_title_slug": "two-sum-ii-input-array-is-sorted", "content_en": "

    Given an array of integers numbers that is already sorted in non-decreasing order, find two numbers such that they add up to a specific target number.

    \n\n

    Return the indices of the two numbers (1-indexed) as an integer array answer of size 2, where 1 <= answer[0] < answer[1] <= numbers.length.

    \n\n

    The tests are generated such that there is exactly one solution. You may not use the same element twice.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: numbers = [2,7,11,15], target = 9\nOutput: [1,2]\nExplanation: The sum of 2 and 7 is 9. Therefore index1 = 1, index2 = 2.\n
    \n\n

    Example 2:

    \n\n
    \nInput: numbers = [2,3,4], target = 6\nOutput: [1,3]\n
    \n\n

    Example 3:

    \n\n
    \nInput: numbers = [-1,0], target = -1\nOutput: [1,2]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= numbers.length <= 3 * 104
    • \n\t
    • -1000 <= numbers[i] <= 1000
    • \n\t
    • numbers is sorted in non-decreasing order.
    • \n\t
    • -1000 <= target <= 1000
    • \n\t
    • The tests are generated such that there is exactly one solution.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5df2\u6309\u7167 \u5347\u5e8f\u6392\u5217\u00a0 \u7684\u6574\u6570\u6570\u7ec4\u00a0numbers \uff0c\u8bf7\u4f60\u4ece\u6570\u7ec4\u4e2d\u627e\u51fa\u4e24\u4e2a\u6570\u6ee1\u8db3\u76f8\u52a0\u4e4b\u548c\u7b49\u4e8e\u76ee\u6807\u6570\u00a0target \u3002

    \n\n

    \u51fd\u6570\u5e94\u8be5\u4ee5\u957f\u5ea6\u4e3a 2 \u7684\u6574\u6570\u6570\u7ec4\u7684\u5f62\u5f0f\u8fd4\u56de\u8fd9\u4e24\u4e2a\u6570\u7684\u4e0b\u6807\u503c\u3002numbers \u7684\u4e0b\u6807 \u4ece 1 \u5f00\u59cb\u8ba1\u6570 \uff0c\u6240\u4ee5\u7b54\u6848\u6570\u7ec4\u5e94\u5f53\u6ee1\u8db3 1 <= answer[0] < answer[1] <= numbers.length \u3002

    \n\n

    \u4f60\u53ef\u4ee5\u5047\u8bbe\u6bcf\u4e2a\u8f93\u5165\u53ea\u5bf9\u5e94\u552f\u4e00\u7684\u7b54\u6848\uff0c\u800c\u4e14\u4f60\u4e0d\u53ef\u4ee5\u91cd\u590d\u4f7f\u7528\u76f8\u540c\u7684\u5143\u7d20\u3002

    \n\u00a0\n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anumbers = [2,7,11,15], target = 9\n\u8f93\u51fa\uff1a[1,2]\n\u89e3\u91ca\uff1a2 \u4e0e 7 \u4e4b\u548c\u7b49\u4e8e\u76ee\u6807\u6570 9 \u3002\u56e0\u6b64 index1 = 1, index2 = 2 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anumbers = [2,3,4], target = 6\n\u8f93\u51fa\uff1a[1,3]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anumbers = [-1,0], target = -1\n\u8f93\u51fa\uff1a[1,2]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= numbers.length <= 3 * 104
    • \n\t
    • -1000 <= numbers[i] <= 1000
    • \n\t
    • numbers \u6309 \u9012\u589e\u987a\u5e8f \u6392\u5217
    • \n\t
    • -1000 <= target <= 1000
    • \n\t
    • \u4ec5\u5b58\u5728\u4e00\u4e2a\u6709\u6548\u7b54\u6848
    • \n
    \n", "tags_en": ["Array", "Two Pointers", "Binary Search"], "tags_cn": ["\u6570\u7ec4", "\u53cc\u6307\u9488", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector twoSum(vector& numbers, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] twoSum(int[] numbers, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def twoSum(self, numbers, target):\n \"\"\"\n :type numbers: List[int]\n :type target: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def twoSum(self, numbers: List[int], target: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* twoSum(int* numbers, int numbersSize, int target, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] TwoSum(int[] numbers, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} numbers\n * @param {number} target\n * @return {number[]}\n */\nvar twoSum = function(numbers, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} numbers\n# @param {Integer} target\n# @return {Integer[]}\ndef two_sum(numbers, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func twoSum(_ numbers: [Int], _ target: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func twoSum(numbers []int, target int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def twoSum(numbers: Array[Int], target: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun twoSum(numbers: IntArray, target: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn two_sum(numbers: Vec, target: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $numbers\n * @param Integer $target\n * @return Integer[]\n */\n function twoSum($numbers, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function twoSum(numbers: number[], target: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (two-sum numbers target)\n (-> (listof exact-integer?) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0167](https://leetcode-cn.com/problems/two-sum-ii-input-array-is-sorted)", "[\u4e24\u6570\u4e4b\u548c II - \u8f93\u5165\u6709\u5e8f\u6570\u7ec4](/solution/0100-0199/0167.Two%20Sum%20II%20-%20Input%20array%20is%20sorted/README.md)", "`\u6570\u7ec4`,`\u53cc\u6307\u9488`,`\u4e8c\u5206\u67e5\u627e`", "\u7b80\u5355", ""], "md_table_row_en": ["[0167](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted)", "[Two Sum II - Input array is sorted](/solution/0100-0199/0167.Two%20Sum%20II%20-%20Input%20array%20is%20sorted/README_EN.md)", "`Array`,`Two Pointers`,`Binary Search`", "Easy", ""]}, {"question_id": "0166", "frontend_question_id": "0166", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/fraction-to-recurring-decimal", "url_en": "https://leetcode.com/problems/fraction-to-recurring-decimal", "relative_path_cn": "/solution/0100-0199/0166.Fraction%20to%20Recurring%20Decimal/README.md", "relative_path_en": "/solution/0100-0199/0166.Fraction%20to%20Recurring%20Decimal/README_EN.md", "title_cn": "\u5206\u6570\u5230\u5c0f\u6570", "title_en": "Fraction to Recurring Decimal", "question_title_slug": "fraction-to-recurring-decimal", "content_en": "

    Given two integers representing the numerator and denominator of a fraction, return the fraction in string format.

    \n\n

    If the fractional part is repeating, enclose the repeating part in parentheses.

    \n\n

    If multiple answers are possible, return any of them.

    \n\n

    It is guaranteed that the length of the answer string is less than 104 for all the given inputs.

    \n\n

     

    \n

    Example 1:

    \n
    Input: numerator = 1, denominator = 2\nOutput: \"0.5\"\n

    Example 2:

    \n
    Input: numerator = 2, denominator = 1\nOutput: \"2\"\n

    Example 3:

    \n
    Input: numerator = 2, denominator = 3\nOutput: \"0.(6)\"\n

    Example 4:

    \n
    Input: numerator = 4, denominator = 333\nOutput: \"0.(012)\"\n

    Example 5:

    \n
    Input: numerator = 1, denominator = 5\nOutput: \"0.2\"\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • -231 <= numerator, denominator <= 231 - 1
    • \n\t
    • denominator != 0
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u6574\u6570\uff0c\u5206\u522b\u8868\u793a\u5206\u6570\u7684\u5206\u5b50\u00a0numerator \u548c\u5206\u6bcd denominator\uff0c\u4ee5 \u5b57\u7b26\u4e32\u5f62\u5f0f\u8fd4\u56de\u5c0f\u6570 \u3002

    \n\n

    \u5982\u679c\u5c0f\u6570\u90e8\u5206\u4e3a\u5faa\u73af\u5c0f\u6570\uff0c\u5219\u5c06\u5faa\u73af\u7684\u90e8\u5206\u62ec\u5728\u62ec\u53f7\u5185\u3002

    \n\n

    \u5982\u679c\u5b58\u5728\u591a\u4e2a\u7b54\u6848\uff0c\u53ea\u9700\u8fd4\u56de \u4efb\u610f\u4e00\u4e2a \u3002

    \n\n

    \u5bf9\u4e8e\u6240\u6709\u7ed9\u5b9a\u7684\u8f93\u5165\uff0c\u4fdd\u8bc1 \u7b54\u6848\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u5c0f\u4e8e 104 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anumerator = 1, denominator = 2\n\u8f93\u51fa\uff1a\"0.5\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anumerator = 2, denominator = 1\n\u8f93\u51fa\uff1a\"2\"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anumerator = 2, denominator = 3\n\u8f93\u51fa\uff1a\"0.(6)\"\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1anumerator = 4, denominator = 333\n\u8f93\u51fa\uff1a\"0.(012)\"\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1anumerator = 1, denominator = 5\n\u8f93\u51fa\uff1a\"0.2\"\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • -231 <=\u00a0numerator, denominator <= 231 - 1
    • \n\t
    • denominator != 0
    • \n
    \n", "tags_en": ["Hash Table", "Math"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string fractionToDecimal(int numerator, int denominator) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String fractionToDecimal(int numerator, int denominator) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def fractionToDecimal(self, numerator, denominator):\n \"\"\"\n :type numerator: int\n :type denominator: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def fractionToDecimal(self, numerator: int, denominator: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * fractionToDecimal(int numerator, int denominator){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string FractionToDecimal(int numerator, int denominator) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} numerator\n * @param {number} denominator\n * @return {string}\n */\nvar fractionToDecimal = function(numerator, denominator) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} numerator\n# @param {Integer} denominator\n# @return {String}\ndef fraction_to_decimal(numerator, denominator)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func fractionToDecimal(_ numerator: Int, _ denominator: Int) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func fractionToDecimal(numerator int, denominator int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def fractionToDecimal(numerator: Int, denominator: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun fractionToDecimal(numerator: Int, denominator: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn fraction_to_decimal(numerator: i32, denominator: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $numerator\n * @param Integer $denominator\n * @return String\n */\n function fractionToDecimal($numerator, $denominator) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function fractionToDecimal(numerator: number, denominator: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (fraction-to-decimal numerator denominator)\n (-> exact-integer? exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0166](https://leetcode-cn.com/problems/fraction-to-recurring-decimal)", "[\u5206\u6570\u5230\u5c0f\u6570](/solution/0100-0199/0166.Fraction%20to%20Recurring%20Decimal/README.md)", "`\u54c8\u5e0c\u8868`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0166](https://leetcode.com/problems/fraction-to-recurring-decimal)", "[Fraction to Recurring Decimal](/solution/0100-0199/0166.Fraction%20to%20Recurring%20Decimal/README_EN.md)", "`Hash Table`,`Math`", "Medium", ""]}, {"question_id": "0165", "frontend_question_id": "0165", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/compare-version-numbers", "url_en": "https://leetcode.com/problems/compare-version-numbers", "relative_path_cn": "/solution/0100-0199/0165.Compare%20Version%20Numbers/README.md", "relative_path_en": "/solution/0100-0199/0165.Compare%20Version%20Numbers/README_EN.md", "title_cn": "\u6bd4\u8f83\u7248\u672c\u53f7", "title_en": "Compare Version Numbers", "question_title_slug": "compare-version-numbers", "content_en": "

    Given two version numbers, version1 and version2, compare them.

    \n\n
      \n
    \n\n

    Version numbers consist of one or more revisions joined by a dot '.'. Each revision consists of digits and may contain leading zeros. Every revision contains at least one character. Revisions are 0-indexed from left to right, with the leftmost revision being revision 0, the next revision being revision 1, and so on. For example 2.5.33 and 0.1 are valid version numbers.

    \n\n

    To compare version numbers, compare their revisions in left-to-right order. Revisions are compared using their integer value ignoring any leading zeros. This means that revisions 1 and 001 are considered equal. If a version number does not specify a revision at an index, then treat the revision as 0. For example, version 1.0 is less than version 1.1 because their revision 0s are the same, but their revision 1s are 0 and 1 respectively, and 0 < 1.

    \n\n

    Return the following:

    \n\n
      \n\t
    • If version1 < version2, return -1.
    • \n\t
    • If version1 > version2, return 1.
    • \n\t
    • Otherwise, return 0.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: version1 = "1.01", version2 = "1.001"\nOutput: 0\nExplanation: Ignoring leading zeroes, both "01" and "001" represent the same integer "1".\n
    \n\n

    Example 2:

    \n\n
    \nInput: version1 = "1.0", version2 = "1.0.0"\nOutput: 0\nExplanation: version1 does not specify revision 2, which means it is treated as "0".\n
    \n\n

    Example 3:

    \n\n
    \nInput: version1 = "0.1", version2 = "1.1"\nOutput: -1\nExplanation: version1's revision 0 is "0", while version2's revision 0 is "1". 0 < 1, so version1 < version2.\n
    \n\n

    Example 4:

    \n\n
    \nInput: version1 = "1.0.1", version2 = "1"\nOutput: 1\n
    \n\n

    Example 5:

    \n\n
    \nInput: version1 = "7.5.2.4", version2 = "7.5.3"\nOutput: -1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= version1.length, version2.length <= 500
    • \n\t
    • version1 and version2 only contain digits and '.'.
    • \n\t
    • version1 and version2 are valid version numbers.
    • \n\t
    • All the given revisions in version1 and version2 can be stored in a 32-bit integer.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u7248\u672c\u53f7 version1 \u548c version2 \uff0c\u8bf7\u4f60\u6bd4\u8f83\u5b83\u4eec\u3002

    \n\n

    \u7248\u672c\u53f7\u7531\u4e00\u4e2a\u6216\u591a\u4e2a\u4fee\u8ba2\u53f7\u7ec4\u6210\uff0c\u5404\u4fee\u8ba2\u53f7\u7531\u4e00\u4e2a '.' \u8fde\u63a5\u3002\u6bcf\u4e2a\u4fee\u8ba2\u53f7\u7531 \u591a\u4f4d\u6570\u5b57 \u7ec4\u6210\uff0c\u53ef\u80fd\u5305\u542b \u524d\u5bfc\u96f6 \u3002\u6bcf\u4e2a\u7248\u672c\u53f7\u81f3\u5c11\u5305\u542b\u4e00\u4e2a\u5b57\u7b26\u3002\u4fee\u8ba2\u53f7\u4ece\u5de6\u5230\u53f3\u7f16\u53f7\uff0c\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff0c\u6700\u5de6\u8fb9\u7684\u4fee\u8ba2\u53f7\u4e0b\u6807\u4e3a 0 \uff0c\u4e0b\u4e00\u4e2a\u4fee\u8ba2\u53f7\u4e0b\u6807\u4e3a 1 \uff0c\u4ee5\u6b64\u7c7b\u63a8\u3002\u4f8b\u5982\uff0c2.5.33 \u548c 0.1 \u90fd\u662f\u6709\u6548\u7684\u7248\u672c\u53f7\u3002

    \n\n

    \u6bd4\u8f83\u7248\u672c\u53f7\u65f6\uff0c\u8bf7\u6309\u4ece\u5de6\u5230\u53f3\u7684\u987a\u5e8f\u4f9d\u6b21\u6bd4\u8f83\u5b83\u4eec\u7684\u4fee\u8ba2\u53f7\u3002\u6bd4\u8f83\u4fee\u8ba2\u53f7\u65f6\uff0c\u53ea\u9700\u6bd4\u8f83 \u5ffd\u7565\u4efb\u4f55\u524d\u5bfc\u96f6\u540e\u7684\u6574\u6570\u503c \u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u4fee\u8ba2\u53f7 1 \u548c\u4fee\u8ba2\u53f7 001 \u76f8\u7b49 \u3002\u5982\u679c\u7248\u672c\u53f7\u6ca1\u6709\u6307\u5b9a\u67d0\u4e2a\u4e0b\u6807\u5904\u7684\u4fee\u8ba2\u53f7\uff0c\u5219\u8be5\u4fee\u8ba2\u53f7\u89c6\u4e3a 0 \u3002\u4f8b\u5982\uff0c\u7248\u672c 1.0 \u5c0f\u4e8e\u7248\u672c 1.1 \uff0c\u56e0\u4e3a\u5b83\u4eec\u4e0b\u6807\u4e3a 0 \u7684\u4fee\u8ba2\u53f7\u76f8\u540c\uff0c\u800c\u4e0b\u6807\u4e3a 1 \u7684\u4fee\u8ba2\u53f7\u5206\u522b\u4e3a 0 \u548c 1 \uff0c0 < 1 \u3002

    \n\n

    \u8fd4\u56de\u89c4\u5219\u5982\u4e0b\uff1a

    \n\n
      \n\t
    • \u5982\u679c\u00a0version1\u00a0>\u00a0version2\u00a0\u8fd4\u56de\u00a01\uff0c
    • \n\t
    • \u5982\u679c\u00a0version1\u00a0<\u00a0version2 \u8fd4\u56de -1\uff0c
    • \n\t
    • \u9664\u6b64\u4e4b\u5916\u8fd4\u56de 0\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aversion1 = \"1.01\", version2 = \"1.001\"\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u5ffd\u7565\u524d\u5bfc\u96f6\uff0c\"01\" \u548c \"001\" \u90fd\u8868\u793a\u76f8\u540c\u7684\u6574\u6570 \"1\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aversion1 = \"1.0\", version2 = \"1.0.0\"\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1aversion1 \u6ca1\u6709\u6307\u5b9a\u4e0b\u6807\u4e3a 2 \u7684\u4fee\u8ba2\u53f7\uff0c\u5373\u89c6\u4e3a \"0\"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aversion1 = \"0.1\", version2 = \"1.1\"\n\u8f93\u51fa\uff1a-1\n\u89e3\u91ca\uff1aversion1 \u4e2d\u4e0b\u6807\u4e3a 0 \u7684\u4fee\u8ba2\u53f7\u662f \"0\"\uff0cversion2 \u4e2d\u4e0b\u6807\u4e3a 0 \u7684\u4fee\u8ba2\u53f7\u662f \"1\" \u30020 < 1\uff0c\u6240\u4ee5 version1 < version2\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1aversion1 = \"1.0.1\", version2 = \"1\"\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1aversion1 = \"7.5.2.4\", version2 = \"7.5.3\"\n\u8f93\u51fa\uff1a-1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= version1.length, version2.length <= 500
    • \n\t
    • version1 \u548c version2 \u4ec5\u5305\u542b\u6570\u5b57\u548c '.'
    • \n\t
    • version1 \u548c version2 \u90fd\u662f \u6709\u6548\u7248\u672c\u53f7
    • \n\t
    • version1 \u548c version2 \u7684\u6240\u6709\u4fee\u8ba2\u53f7\u90fd\u53ef\u4ee5\u5b58\u50a8\u5728 32 \u4f4d\u6574\u6570 \u4e2d
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int compareVersion(string version1, string version2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int compareVersion(String version1, String version2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def compareVersion(self, version1, version2):\n \"\"\"\n :type version1: str\n :type version2: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def compareVersion(self, version1: str, version2: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint compareVersion(char * version1, char * version2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CompareVersion(string version1, string version2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} version1\n * @param {string} version2\n * @return {number}\n */\nvar compareVersion = function(version1, version2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} version1\n# @param {String} version2\n# @return {Integer}\ndef compare_version(version1, version2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func compareVersion(_ version1: String, _ version2: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func compareVersion(version1 string, version2 string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def compareVersion(version1: String, version2: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun compareVersion(version1: String, version2: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn compare_version(version1: String, version2: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $version1\n * @param String $version2\n * @return Integer\n */\n function compareVersion($version1, $version2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function compareVersion(version1: string, version2: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (compare-version version1 version2)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0165](https://leetcode-cn.com/problems/compare-version-numbers)", "[\u6bd4\u8f83\u7248\u672c\u53f7](/solution/0100-0199/0165.Compare%20Version%20Numbers/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0165](https://leetcode.com/problems/compare-version-numbers)", "[Compare Version Numbers](/solution/0100-0199/0165.Compare%20Version%20Numbers/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "0164", "frontend_question_id": "0164", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-gap", "url_en": "https://leetcode.com/problems/maximum-gap", "relative_path_cn": "/solution/0100-0199/0164.Maximum%20Gap/README.md", "relative_path_en": "/solution/0100-0199/0164.Maximum%20Gap/README_EN.md", "title_cn": "\u6700\u5927\u95f4\u8ddd", "title_en": "Maximum Gap", "question_title_slug": "maximum-gap", "content_en": "

    Given an integer array nums, return the maximum difference between two successive elements in its sorted form. If the array contains less than two elements, return 0.

    \n\n

    You must write an algorithm that runs in linear time and uses linear extra space.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [3,6,9,1]\nOutput: 3\nExplanation: The sorted form of the array is [1,3,6,9], either (3,6) or (6,9) has the maximum difference 3.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [10]\nOutput: 0\nExplanation: The array contains less than 2 elements, therefore return 0.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 104
    • \n\t
    • 0 <= nums[i] <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u65e0\u5e8f\u7684\u6570\u7ec4\uff0c\u627e\u51fa\u6570\u7ec4\u5728\u6392\u5e8f\u4e4b\u540e\uff0c\u76f8\u90bb\u5143\u7d20\u4e4b\u95f4\u6700\u5927\u7684\u5dee\u503c\u3002

    \n\n

    \u5982\u679c\u6570\u7ec4\u5143\u7d20\u4e2a\u6570\u5c0f\u4e8e 2\uff0c\u5219\u8fd4\u56de 0\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: [3,6,9,1]\n\u8f93\u51fa: 3\n\u89e3\u91ca: \u6392\u5e8f\u540e\u7684\u6570\u7ec4\u662f [1,3,6,9], \u5176\u4e2d\u76f8\u90bb\u5143\u7d20 (3,6) \u548c (6,9) \u4e4b\u95f4\u90fd\u5b58\u5728\u6700\u5927\u5dee\u503c 3\u3002
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: [10]\n\u8f93\u51fa: 0\n\u89e3\u91ca: \u6570\u7ec4\u5143\u7d20\u4e2a\u6570\u5c0f\u4e8e 2\uff0c\u56e0\u6b64\u8fd4\u56de 0\u3002
    \n\n

    \u8bf4\u660e:

    \n\n
      \n\t
    • \u4f60\u53ef\u4ee5\u5047\u8bbe\u6570\u7ec4\u4e2d\u6240\u6709\u5143\u7d20\u90fd\u662f\u975e\u8d1f\u6574\u6570\uff0c\u4e14\u6570\u503c\u5728 32 \u4f4d\u6709\u7b26\u53f7\u6574\u6570\u8303\u56f4\u5185\u3002
    • \n\t
    • \u8bf7\u5c1d\u8bd5\u5728\u7ebf\u6027\u65f6\u95f4\u590d\u6742\u5ea6\u548c\u7a7a\u95f4\u590d\u6742\u5ea6\u7684\u6761\u4ef6\u4e0b\u89e3\u51b3\u6b64\u95ee\u9898\u3002
    • \n
    \n", "tags_en": ["Sort"], "tags_cn": ["\u6392\u5e8f"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maximumGap(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maximumGap(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximumGap(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximumGap(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maximumGap(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaximumGap(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar maximumGap = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef maximum_gap(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximumGap(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximumGap(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximumGap(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximumGap(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximum_gap(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function maximumGap($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximumGap(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximum-gap nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0164](https://leetcode-cn.com/problems/maximum-gap)", "[\u6700\u5927\u95f4\u8ddd](/solution/0100-0199/0164.Maximum%20Gap/README.md)", "`\u6392\u5e8f`", "\u56f0\u96be", ""], "md_table_row_en": ["[0164](https://leetcode.com/problems/maximum-gap)", "[Maximum Gap](/solution/0100-0199/0164.Maximum%20Gap/README_EN.md)", "`Sort`", "Hard", ""]}, {"question_id": "0163", "frontend_question_id": "0163", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/missing-ranges", "url_en": "https://leetcode.com/problems/missing-ranges", "relative_path_cn": "/solution/0100-0199/0163.Missing%20Ranges/README.md", "relative_path_en": "/solution/0100-0199/0163.Missing%20Ranges/README_EN.md", "title_cn": "\u7f3a\u5931\u7684\u533a\u95f4", "title_en": "Missing Ranges", "question_title_slug": "missing-ranges", "content_en": "

    You are given an inclusive range [lower, upper] and a sorted unique integer array nums, where all elements are in the inclusive range.

    \n\n

    A number x is considered missing if x is in the range [lower, upper] and x is not in nums.

    \n\n

    Return the smallest sorted list of ranges that cover every missing number exactly. That is, no element of nums is in any of the ranges, and each missing number is in one of the ranges.

    \n\n

    Each range [a,b] in the list should be output as:

    \n\n
      \n\t
    • "a->b" if a != b
    • \n\t
    • "a" if a == b
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [0,1,3,50,75], lower = 0, upper = 99\nOutput: ["2","4->49","51->74","76->99"]\nExplanation: The ranges are:\n[2,2] --> "2"\n[4,49] --> "4->49"\n[51,74] --> "51->74"\n[76,99] --> "76->99"\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [], lower = 1, upper = 1\nOutput: ["1"]\nExplanation: The only missing range is [1,1], which becomes "1".\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [], lower = -3, upper = -1\nOutput: ["-3->-1"]\nExplanation: The only missing range is [-3,-1], which becomes "-3->-1".\n
    \n\n

    Example 4:

    \n\n
    \nInput: nums = [-1], lower = -1, upper = -1\nOutput: []\nExplanation: There are no missing ranges since there are no missing numbers.\n
    \n\n

    Example 5:

    \n\n
    \nInput: nums = [-1], lower = -2, upper = -1\nOutput: ["-2"]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • -109 <= lower <= upper <= 109
    • \n\t
    • 0 <= nums.length <= 100
    • \n\t
    • lower <= nums[i] <= upper
    • \n\t
    • All the values of nums are unique.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6392\u5e8f\u7684\u6574\u6570\u6570\u7ec4 nums \uff0c\u5176\u4e2d\u5143\u7d20\u7684\u8303\u56f4\u5728 \u95ed\u533a\u95f4 [lower, upper] \u5f53\u4e2d\uff0c\u8fd4\u56de\u4e0d\u5305\u542b\u5728\u6570\u7ec4\u4e2d\u7684\u7f3a\u5931\u533a\u95f4\u3002

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165: nums = [0, 1, 3, 50, 75], lower = 0 \u548c upper = 99,\n\u8f93\u51fa: ["2", "4->49", "51->74", "76->99"]\n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findMissingRanges(vector& nums, int lower, int upper) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List findMissingRanges(int[] nums, int lower, int upper) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findMissingRanges(self, nums, lower, upper):\n \"\"\"\n :type nums: List[int]\n :type lower: int\n :type upper: int\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findMissingRanges(self, nums: List[int], lower: int, upper: int) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** findMissingRanges(int* nums, int numsSize, int lower, int upper, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList FindMissingRanges(int[] nums, int lower, int upper) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} lower\n * @param {number} upper\n * @return {string[]}\n */\nvar findMissingRanges = function(nums, lower, upper) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} lower\n# @param {Integer} upper\n# @return {String[]}\ndef find_missing_ranges(nums, lower, upper)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findMissingRanges(_ nums: [Int], _ lower: Int, _ upper: Int) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findMissingRanges(nums []int, lower int, upper int) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findMissingRanges(nums: Array[Int], lower: Int, upper: Int): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findMissingRanges(nums: IntArray, lower: Int, upper: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_missing_ranges(nums: Vec, lower: i32, upper: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $lower\n * @param Integer $upper\n * @return String[]\n */\n function findMissingRanges($nums, $lower, $upper) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findMissingRanges(nums: number[], lower: number, upper: number): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-missing-ranges nums lower upper)\n (-> (listof exact-integer?) exact-integer? exact-integer? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0163](https://leetcode-cn.com/problems/missing-ranges)", "[\u7f3a\u5931\u7684\u533a\u95f4](/solution/0100-0199/0163.Missing%20Ranges/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0163](https://leetcode.com/problems/missing-ranges)", "[Missing Ranges](/solution/0100-0199/0163.Missing%20Ranges/README_EN.md)", "`Array`", "Easy", "\ud83d\udd12"]}, {"question_id": "0162", "frontend_question_id": "0162", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-peak-element", "url_en": "https://leetcode.com/problems/find-peak-element", "relative_path_cn": "/solution/0100-0199/0162.Find%20Peak%20Element/README.md", "relative_path_en": "/solution/0100-0199/0162.Find%20Peak%20Element/README_EN.md", "title_cn": "\u5bfb\u627e\u5cf0\u503c", "title_en": "Find Peak Element", "question_title_slug": "find-peak-element", "content_en": "

    A peak element is an element that is strictly greater than its neighbors.

    \n\n

    Given an integer array nums, find a peak element, and return its index. If the array contains multiple peaks, return the index to any of the peaks.

    \n\n

    You may imagine that nums[-1] = nums[n] = -∞.

    \n\n

    You must write an algorithm that runs in O(log n) time.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,3,1]\nOutput: 2\nExplanation: 3 is a peak element and your function should return the index number 2.
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,2,1,3,5,6,4]\nOutput: 5\nExplanation: Your function can return either index number 1 where the peak element is 2, or index number 5 where the peak element is 6.
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 1000
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n\t
    • nums[i] != nums[i + 1] for all valid i.
    • \n
    \n", "content_cn": "

    \u5cf0\u503c\u5143\u7d20\u662f\u6307\u5176\u503c\u5927\u4e8e\u5de6\u53f3\u76f8\u90bb\u503c\u7684\u5143\u7d20\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u8f93\u5165\u6570\u7ec4\u00a0nums\uff0c\u627e\u5230\u5cf0\u503c\u5143\u7d20\u5e76\u8fd4\u56de\u5176\u7d22\u5f15\u3002\u6570\u7ec4\u53ef\u80fd\u5305\u542b\u591a\u4e2a\u5cf0\u503c\uff0c\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u8fd4\u56de \u4efb\u4f55\u4e00\u4e2a\u5cf0\u503c \u6240\u5728\u4f4d\u7f6e\u5373\u53ef\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u5047\u8bbe\u00a0nums[-1] = nums[n] = -\u221e \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,3,1]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a3 \u662f\u5cf0\u503c\u5143\u7d20\uff0c\u4f60\u7684\u51fd\u6570\u5e94\u8be5\u8fd4\u56de\u5176\u7d22\u5f15 2\u3002
    \n\n

    \u793a\u4f8b\u00a02\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,1,3,5,6,4]\n\u8f93\u51fa\uff1a1 \u6216 5 \n\u89e3\u91ca\uff1a\u4f60\u7684\u51fd\u6570\u53ef\u4ee5\u8fd4\u56de\u7d22\u5f15 1\uff0c\u5176\u5cf0\u503c\u5143\u7d20\u4e3a 2\uff1b\n\u00a0    \u6216\u8005\u8fd4\u56de\u7d22\u5f15 5\uff0c \u5176\u5cf0\u503c\u5143\u7d20\u4e3a 6\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 1000
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n\t
    • \u5bf9\u4e8e\u6240\u6709\u6709\u6548\u7684 i \u90fd\u6709 nums[i] != nums[i + 1]
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u53ef\u4ee5\u5b9e\u73b0\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(logN) \u7684\u89e3\u51b3\u65b9\u6848\u5417\uff1f

    \n", "tags_en": ["Array", "Binary Search"], "tags_cn": ["\u6570\u7ec4", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findPeakElement(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findPeakElement(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findPeakElement(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findPeakElement(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findPeakElement(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindPeakElement(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar findPeakElement = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef find_peak_element(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findPeakElement(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findPeakElement(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findPeakElement(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findPeakElement(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_peak_element(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function findPeakElement($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findPeakElement(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-peak-element nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0162](https://leetcode-cn.com/problems/find-peak-element)", "[\u5bfb\u627e\u5cf0\u503c](/solution/0100-0199/0162.Find%20Peak%20Element/README.md)", "`\u6570\u7ec4`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0162](https://leetcode.com/problems/find-peak-element)", "[Find Peak Element](/solution/0100-0199/0162.Find%20Peak%20Element/README_EN.md)", "`Array`,`Binary Search`", "Medium", ""]}, {"question_id": "0161", "frontend_question_id": "0161", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/one-edit-distance", "url_en": "https://leetcode.com/problems/one-edit-distance", "relative_path_cn": "/solution/0100-0199/0161.One%20Edit%20Distance/README.md", "relative_path_en": "/solution/0100-0199/0161.One%20Edit%20Distance/README_EN.md", "title_cn": "\u76f8\u9694\u4e3a 1 \u7684\u7f16\u8f91\u8ddd\u79bb", "title_en": "One Edit Distance", "question_title_slug": "one-edit-distance", "content_en": "

    Given two strings s and t, return true if they are both one edit distance apart, otherwise return false.

    \n\n

    A string s is said to be one distance apart from a string t if you can:

    \n\n
      \n\t
    • Insert exactly one character into s to get t.
    • \n\t
    • Delete exactly one character from s to get t.
    • \n\t
    • Replace exactly one character of s with a different character to get t.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "ab", t = "acb"\nOutput: true\nExplanation: We can insert 'c' into s to get t.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "", t = ""\nOutput: false\nExplanation: We cannot get t from s by only one step.\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "a", t = ""\nOutput: true\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "", t = "A"\nOutput: true\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= s.length <= 104
    • \n\t
    • 0 <= t.length <= 104
    • \n\t
    • s and t consist of lower-case letters, upper-case letters and/or digits.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u5b57\u7b26\u4e32 s \u548c t\uff0c\u5224\u65ad\u4ed6\u4eec\u7684\u7f16\u8f91\u8ddd\u79bb\u662f\u5426\u4e3a 1\u3002

    \n\n

    \u6ce8\u610f\uff1a

    \n\n

    \u6ee1\u8db3\u7f16\u8f91\u8ddd\u79bb\u7b49\u4e8e 1 \u6709\u4e09\u79cd\u53ef\u80fd\u7684\u60c5\u5f62\uff1a

    \n\n
      \n\t
    1. \u5f80 s \u4e2d\u63d2\u5165\u4e00\u4e2a\u5b57\u7b26\u5f97\u5230 t
    2. \n\t
    3. \u4ece s \u4e2d\u5220\u9664\u4e00\u4e2a\u5b57\u7b26\u5f97\u5230 t
    4. \n\t
    5. \u5728 s \u4e2d\u66ff\u6362\u4e00\u4e2a\u5b57\u7b26\u5f97\u5230 t
    6. \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165: s = "ab", t = "acb"\n\u8f93\u51fa: true\n\u89e3\u91ca: \u53ef\u4ee5\u5c06 'c' \u63d2\u5165\u5b57\u7b26\u4e32 s \u6765\u5f97\u5230 t\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: s = "cab", t = "ad"\n\u8f93\u51fa: false\n\u89e3\u91ca: \u65e0\u6cd5\u901a\u8fc7 1 \u6b65\u64cd\u4f5c\u4f7f s \u53d8\u4e3a t\u3002
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u8f93\u5165: s = "1203", t = "1213"\n\u8f93\u51fa: true\n\u89e3\u91ca: \u53ef\u4ee5\u5c06\u5b57\u7b26\u4e32 s \u4e2d\u7684 '0' \u66ff\u6362\u4e3a '1' \u6765\u5f97\u5230 t\u3002
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isOneEditDistance(string s, string t) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isOneEditDistance(String s, String t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isOneEditDistance(self, s, t):\n \"\"\"\n :type s: str\n :type t: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isOneEditDistance(self, s: str, t: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isOneEditDistance(char * s, char * t){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsOneEditDistance(string s, string t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string} t\n * @return {boolean}\n */\nvar isOneEditDistance = function(s, t) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String} t\n# @return {Boolean}\ndef is_one_edit_distance(s, t)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isOneEditDistance(_ s: String, _ t: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isOneEditDistance(s string, t string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isOneEditDistance(s: String, t: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isOneEditDistance(s: String, t: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_one_edit_distance(s: String, t: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String $t\n * @return Boolean\n */\n function isOneEditDistance($s, $t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isOneEditDistance(s: string, t: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-one-edit-distance s t)\n (-> string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0161](https://leetcode-cn.com/problems/one-edit-distance)", "[\u76f8\u9694\u4e3a 1 \u7684\u7f16\u8f91\u8ddd\u79bb](/solution/0100-0199/0161.One%20Edit%20Distance/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0161](https://leetcode.com/problems/one-edit-distance)", "[One Edit Distance](/solution/0100-0199/0161.One%20Edit%20Distance/README_EN.md)", "`String`", "Medium", "\ud83d\udd12"]}, {"question_id": "0160", "frontend_question_id": "0160", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/intersection-of-two-linked-lists", "url_en": "https://leetcode.com/problems/intersection-of-two-linked-lists", "relative_path_cn": "/solution/0100-0199/0160.Intersection%20of%20Two%20Linked%20Lists/README.md", "relative_path_en": "/solution/0100-0199/0160.Intersection%20of%20Two%20Linked%20Lists/README_EN.md", "title_cn": "\u76f8\u4ea4\u94fe\u8868", "title_en": "Intersection of Two Linked Lists", "question_title_slug": "intersection-of-two-linked-lists", "content_en": "

    Given the heads of two singly linked-lists headA and headB, return the node at which the two lists intersect. If the two linked lists have no intersection at all, return null.

    \n\n

    For example, the following two linked lists begin to intersect at node c1:

    \n\"\"\n

    It is guaranteed that there are no cycles anywhere in the entire linked structure.

    \n\n

    Note that the linked lists must retain their original structure after the function returns.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: intersectVal = 8, listA = [4,1,8,4,5], listB = [5,6,1,8,4,5], skipA = 2, skipB = 3\nOutput: Intersected at '8'\nExplanation: The intersected node's value is 8 (note that this must not be 0 if the two lists intersect).\nFrom the head of A, it reads as [4,1,8,4,5]. From the head of B, it reads as [5,6,1,8,4,5]. There are 2 nodes before the intersected node in A; There are 3 nodes before the intersected node in B.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: intersectVal = 2, listA = [1,9,1,2,4], listB = [3,2,4], skipA = 3, skipB = 1\nOutput: Intersected at '2'\nExplanation: The intersected node's value is 2 (note that this must not be 0 if the two lists intersect).\nFrom the head of A, it reads as [1,9,1,2,4]. From the head of B, it reads as [3,2,4]. There are 3 nodes before the intersected node in A; There are 1 node before the intersected node in B.\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: intersectVal = 0, listA = [2,6,4], listB = [1,5], skipA = 3, skipB = 2\nOutput: No intersection\nExplanation: From the head of A, it reads as [2,6,4]. From the head of B, it reads as [1,5]. Since the two lists do not intersect, intersectVal must be 0, while skipA and skipB can be arbitrary values.\nExplanation: The two lists do not intersect, so return null.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes of listA is in the m.
    • \n\t
    • The number of nodes of listB is in the n.
    • \n\t
    • 0 <= m, n <= 3 * 104
    • \n\t
    • 1 <= Node.val <= 105
    • \n\t
    • 0 <= skipA <= m
    • \n\t
    • 0 <= skipB <= n
    • \n\t
    • intersectVal is 0 if listA and listB do not intersect.
    • \n\t
    • intersectVal == listA[skipA + 1] == listB[skipB + 1] if listA and listB intersect.
    • \n
    \n\n

     

    \nFollow up: Could you write a solution that runs in O(n) time and use only O(1) memory?", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u5355\u94fe\u8868\u7684\u5934\u8282\u70b9\u00a0headA \u548c headB \uff0c\u8bf7\u4f60\u627e\u51fa\u5e76\u8fd4\u56de\u4e24\u4e2a\u5355\u94fe\u8868\u76f8\u4ea4\u7684\u8d77\u59cb\u8282\u70b9\u3002\u5982\u679c\u4e24\u4e2a\u94fe\u8868\u6ca1\u6709\u4ea4\u70b9\uff0c\u8fd4\u56de null \u3002

    \n\n

    \u56fe\u793a\u4e24\u4e2a\u94fe\u8868\u5728\u8282\u70b9 c1 \u5f00\u59cb\u76f8\u4ea4\uff1a

    \n\n

    \"\"

    \n\n

    \u9898\u76ee\u6570\u636e \u4fdd\u8bc1 \u6574\u4e2a\u94fe\u5f0f\u7ed3\u6784\u4e2d\u4e0d\u5b58\u5728\u73af\u3002

    \n\n

    \u6ce8\u610f\uff0c\u51fd\u6570\u8fd4\u56de\u7ed3\u679c\u540e\uff0c\u94fe\u8868\u5fc5\u987b \u4fdd\u6301\u5176\u539f\u59cb\u7ed3\u6784 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aintersectVal = 8, listA = [4,1,8,4,5], listB = [5,0,1,8,4,5], skipA = 2, skipB = 3\n\u8f93\u51fa\uff1aIntersected at '8'\n\u89e3\u91ca\uff1a\u76f8\u4ea4\u8282\u70b9\u7684\u503c\u4e3a 8 \uff08\u6ce8\u610f\uff0c\u5982\u679c\u4e24\u4e2a\u94fe\u8868\u76f8\u4ea4\u5219\u4e0d\u80fd\u4e3a 0\uff09\u3002\n\u4ece\u5404\u81ea\u7684\u8868\u5934\u5f00\u59cb\u7b97\u8d77\uff0c\u94fe\u8868 A \u4e3a [4,1,8,4,5]\uff0c\u94fe\u8868 B \u4e3a [5,0,1,8,4,5]\u3002\n\u5728 A \u4e2d\uff0c\u76f8\u4ea4\u8282\u70b9\u524d\u6709 2 \u4e2a\u8282\u70b9\uff1b\u5728 B \u4e2d\uff0c\u76f8\u4ea4\u8282\u70b9\u524d\u6709 3 \u4e2a\u8282\u70b9\u3002\n
    \n\n

    \u793a\u4f8b\u00a02\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aintersectVal\u00a0= 2, listA = [0,9,1,2,4], listB = [3,2,4], skipA = 3, skipB = 1\n\u8f93\u51fa\uff1aIntersected at '2'\n\u89e3\u91ca\uff1a\u76f8\u4ea4\u8282\u70b9\u7684\u503c\u4e3a 2 \uff08\u6ce8\u610f\uff0c\u5982\u679c\u4e24\u4e2a\u94fe\u8868\u76f8\u4ea4\u5219\u4e0d\u80fd\u4e3a 0\uff09\u3002\n\u4ece\u5404\u81ea\u7684\u8868\u5934\u5f00\u59cb\u7b97\u8d77\uff0c\u94fe\u8868 A \u4e3a [0,9,1,2,4]\uff0c\u94fe\u8868 B \u4e3a [3,2,4]\u3002\n\u5728 A \u4e2d\uff0c\u76f8\u4ea4\u8282\u70b9\u524d\u6709 3 \u4e2a\u8282\u70b9\uff1b\u5728 B \u4e2d\uff0c\u76f8\u4ea4\u8282\u70b9\u524d\u6709 1 \u4e2a\u8282\u70b9\u3002\n
    \n\n

    \u793a\u4f8b\u00a03\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aintersectVal = 0, listA = [2,6,4], listB = [1,5], skipA = 3, skipB = 2\n\u8f93\u51fa\uff1anull\n\u89e3\u91ca\uff1a\u4ece\u5404\u81ea\u7684\u8868\u5934\u5f00\u59cb\u7b97\u8d77\uff0c\u94fe\u8868 A \u4e3a [2,6,4]\uff0c\u94fe\u8868 B \u4e3a [1,5]\u3002\n\u7531\u4e8e\u8fd9\u4e24\u4e2a\u94fe\u8868\u4e0d\u76f8\u4ea4\uff0c\u6240\u4ee5 intersectVal \u5fc5\u987b\u4e3a 0\uff0c\u800c skipA \u548c skipB \u53ef\u4ee5\u662f\u4efb\u610f\u503c\u3002\n\u8fd9\u4e24\u4e2a\u94fe\u8868\u4e0d\u76f8\u4ea4\uff0c\u56e0\u6b64\u8fd4\u56de null \u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • listA \u4e2d\u8282\u70b9\u6570\u76ee\u4e3a m
    • \n\t
    • listB \u4e2d\u8282\u70b9\u6570\u76ee\u4e3a n
    • \n\t
    • 0 <= m, n <= 3 * 104
    • \n\t
    • 1 <= Node.val <= 105
    • \n\t
    • 0 <= skipA <= m
    • \n\t
    • 0 <= skipB <= n
    • \n\t
    • \u5982\u679c listA \u548c listB \u6ca1\u6709\u4ea4\u70b9\uff0cintersectVal \u4e3a 0
    • \n\t
    • \u5982\u679c listA \u548c listB \u6709\u4ea4\u70b9\uff0cintersectVal == listA[skipA + 1] == listB[skipB + 1]
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u80fd\u5426\u8bbe\u8ba1\u4e00\u4e2a\u65f6\u95f4\u590d\u6742\u5ea6 O(n) \u3001\u4ec5\u7528 O(1) \u5185\u5b58\u7684\u89e3\u51b3\u65b9\u6848\uff1f

    \n", "tags_en": ["Linked List"], "tags_cn": ["\u94fe\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\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 ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode(int x) {\n * val = x;\n * next = null;\n * }\n * }\n */\npublic class Solution {\n public ListNode getIntersectionNode(ListNode headA, ListNode headB) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.next = None\n\nclass Solution(object):\n def getIntersectionNode(self, headA, headB):\n \"\"\"\n :type head1, head1: ListNode\n :rtype: ListNode\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, x):\n# self.val = x\n# self.next = None\n\nclass Solution:\n def getIntersectionNode(self, headA: ListNode, headB: ListNode) -> ListNode:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\nstruct ListNode *getIntersectionNode(struct ListNode *headA, struct ListNode *headB) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int x) { val = x; }\n * }\n */\npublic class Solution {\n public ListNode GetIntersectionNode(ListNode headA, ListNode headB) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val) {\n * this.val = val;\n * this.next = null;\n * }\n */\n\n/**\n * @param {ListNode} headA\n * @param {ListNode} headB\n * @return {ListNode}\n */\nvar getIntersectionNode = function(headA, headB) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val)\n# @val = val\n# @next = nil\n# end\n# end\n\n# @param {ListNode} headA\n# @param {ListNode} headB\n# @return {ListNode}\ndef getIntersectionNode(headA, headB)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.next = nil\n * }\n * }\n */\n\nclass Solution {\n func getIntersectionNode(_ headA: ListNode?, _ headB: ListNode?) -> ListNode? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc getIntersectionNode(headA, headB *ListNode) *ListNode {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(var _x: Int = 0) {\n * var next: ListNode = null\n * var x: Int = _x\n * }\n */\n\nobject Solution {\n def getIntersectionNode(headA: ListNode, headB: ListNode): ListNode = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\n\nclass Solution {\n fun getIntersectionNode(headA:ListNode?, headB:ListNode?):ListNode? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val) { $this->val = $val; }\n * }\n */\n\nclass Solution {\n /**\n * @param ListNode $headA\n * @param ListNode $headB\n * @return ListNode\n */\n function getIntersectionNode($headA, $headB) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction getIntersectionNode(headA: ListNode | null, headB: ListNode | null): ListNode | null {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0160](https://leetcode-cn.com/problems/intersection-of-two-linked-lists)", "[\u76f8\u4ea4\u94fe\u8868](/solution/0100-0199/0160.Intersection%20of%20Two%20Linked%20Lists/README.md)", "`\u94fe\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0160](https://leetcode.com/problems/intersection-of-two-linked-lists)", "[Intersection of Two Linked Lists](/solution/0100-0199/0160.Intersection%20of%20Two%20Linked%20Lists/README_EN.md)", "`Linked List`", "Easy", ""]}, {"question_id": "0159", "frontend_question_id": "0159", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/longest-substring-with-at-most-two-distinct-characters", "url_en": "https://leetcode.com/problems/longest-substring-with-at-most-two-distinct-characters", "relative_path_cn": "/solution/0100-0199/0159.Longest%20Substring%20with%20At%20Most%20Two%20Distinct%20Characters/README.md", "relative_path_en": "/solution/0100-0199/0159.Longest%20Substring%20with%20At%20Most%20Two%20Distinct%20Characters/README_EN.md", "title_cn": "\u81f3\u591a\u5305\u542b\u4e24\u4e2a\u4e0d\u540c\u5b57\u7b26\u7684\u6700\u957f\u5b50\u4e32", "title_en": "Longest Substring with At Most Two Distinct Characters", "question_title_slug": "longest-substring-with-at-most-two-distinct-characters", "content_en": "

    Given a string s, return the length of the longest substring that contains at most two distinct characters.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "eceba"\nOutput: 3\nExplanation: The substring is "ece" which its length is 3.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "ccaabbb"\nOutput: 5\nExplanation: The substring is "aabbb" which its length is 5.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 104
    • \n\t
    • s consists of English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32 s \uff0c\u627e\u51fa \u81f3\u591a \u5305\u542b\u4e24\u4e2a\u4e0d\u540c\u5b57\u7b26\u7684\u6700\u957f\u5b50\u4e32 t \uff0c\u5e76\u8fd4\u56de\u8be5\u5b50\u4e32\u7684\u957f\u5ea6\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: "eceba"\n\u8f93\u51fa: 3\n\u89e3\u91ca: t \u662f "ece"\uff0c\u957f\u5ea6\u4e3a3\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: "ccaabbb"\n\u8f93\u51fa: 5\n\u89e3\u91ca: t \u662f "aabbb"\uff0c\u957f\u5ea6\u4e3a5\u3002\n
    \n", "tags_en": ["Hash Table", "Two Pointers", "String", "Sliding Window"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u53cc\u6307\u9488", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int lengthOfLongestSubstringTwoDistinct(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int lengthOfLongestSubstringTwoDistinct(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def lengthOfLongestSubstringTwoDistinct(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def lengthOfLongestSubstringTwoDistinct(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint lengthOfLongestSubstringTwoDistinct(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LengthOfLongestSubstringTwoDistinct(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar lengthOfLongestSubstringTwoDistinct = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef length_of_longest_substring_two_distinct(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func lengthOfLongestSubstringTwoDistinct(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func lengthOfLongestSubstringTwoDistinct(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def lengthOfLongestSubstringTwoDistinct(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun lengthOfLongestSubstringTwoDistinct(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn length_of_longest_substring_two_distinct(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function lengthOfLongestSubstringTwoDistinct($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function lengthOfLongestSubstringTwoDistinct(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (length-of-longest-substring-two-distinct s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0159](https://leetcode-cn.com/problems/longest-substring-with-at-most-two-distinct-characters)", "[\u81f3\u591a\u5305\u542b\u4e24\u4e2a\u4e0d\u540c\u5b57\u7b26\u7684\u6700\u957f\u5b50\u4e32](/solution/0100-0199/0159.Longest%20Substring%20with%20At%20Most%20Two%20Distinct%20Characters/README.md)", "`\u54c8\u5e0c\u8868`,`\u53cc\u6307\u9488`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0159](https://leetcode.com/problems/longest-substring-with-at-most-two-distinct-characters)", "[Longest Substring with At Most Two Distinct Characters](/solution/0100-0199/0159.Longest%20Substring%20with%20At%20Most%20Two%20Distinct%20Characters/README_EN.md)", "`Hash Table`,`Two Pointers`,`String`,`Sliding Window`", "Medium", "\ud83d\udd12"]}, {"question_id": "0158", "frontend_question_id": "0158", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/read-n-characters-given-read4-ii-call-multiple-times", "url_en": "https://leetcode.com/problems/read-n-characters-given-read4-ii-call-multiple-times", "relative_path_cn": "/solution/0100-0199/0158.Read%20N%20Characters%20Given%20Read4%20II%20-%20Call%20multiple%20times/README.md", "relative_path_en": "/solution/0100-0199/0158.Read%20N%20Characters%20Given%20Read4%20II%20-%20Call%20multiple%20times/README_EN.md", "title_cn": "\u7528 Read4 \u8bfb\u53d6 N \u4e2a\u5b57\u7b26 II", "title_en": "Read N Characters Given Read4 II - Call multiple times", "question_title_slug": "read-n-characters-given-read4-ii-call-multiple-times", "content_en": "

    Given a file and assume that you can only read the file using a given method read4, implement a method read to read n characters. Your method read may be called multiple times.

    \n\n

    Method read4:

    \n\n

    The API read4 reads four consecutive characters from file, then writes those characters into the buffer array buf4.

    \n\n

    The return value is the number of actual characters read.

    \n\n

    Note that read4() has its own file pointer, much like FILE *fp in C.

    \n\n

    Definition of read4:

    \n\n
    \n    Parameter:  char[] buf4\n    Returns:    int\n\nbuf4[] is a destination, not a source. The results from read4 will be copied to buf4[].\n
    \n\n

    Below is a high-level example of how read4 works:

    \n\"\"\n
    \nFile file("abcde"); // File is "abcde", initially file pointer (fp) points to 'a'\nchar[] buf4 = new char[4]; // Create buffer with enough space to store characters\nread4(buf4); // read4 returns 4. Now buf4 = "abcd", fp points to 'e'\nread4(buf4); // read4 returns 1. Now buf4 = "e", fp points to end of file\nread4(buf4); // read4 returns 0. Now buf4 = "", fp points to end of file\n
    \n\n

     

    \n\n

    Method read:

    \n\n

    By using the read4 method, implement the method read that reads n characters from file and store it in the buffer array buf. Consider that you cannot manipulate file directly.

    \n\n

    The return value is the number of actual characters read.

    \n\n

    Definition of read:

    \n\n
    \n    Parameters:\tchar[] buf, int n\n    Returns:\tint\n\nbuf[] is a destination, not a source. You will need to write the results to buf[].\n
    \n\n

    Note:

    \n\n
      \n\t
    • Consider that you cannot manipulate the file directly. The file is only accessible for read4 but not for read.
    • \n\t
    • The read function may be called multiple times.
    • \n\t
    • Please remember to RESET your class variables declared in Solution, as static/class variables are persisted across multiple test cases. Please see here for more details.
    • \n\t
    • You may assume the destination buffer array, buf, is guaranteed to have enough space for storing n characters.
    • \n\t
    • It is guaranteed that in a given test case the same buffer buf is called by read.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: file = "abc", queries = [1,2,1]\nOutput: [1,2,0]\nExplanation: The test case represents the following scenario:\nFile file("abc");\nSolution sol;\nsol.read(buf, 1); // After calling your read method, buf should contain "a". We read a total of 1 character from the file, so return 1.\nsol.read(buf, 2); // Now buf should contain "bc". We read a total of 2 characters from the file, so return 2.\nsol.read(buf, 1); // We have reached the end of file, no more characters can be read. So return 0.\nAssume buf is allocated and guaranteed to have enough space for storing all characters from the file.\n
    \n\n

    Example 2:

    \n\n
    \nInput: file = "abc", queries = [4,1]\nOutput: [3,0]\nExplanation: The test case represents the following scenario:\nFile file("abc");\nSolution sol;\nsol.read(buf, 4); // After calling your read method, buf should contain "abc". We read a total of 3 characters from the file, so return 3.\nsol.read(buf, 1); // We have reached the end of file, no more characters can be read. So return 0.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= file.length <= 500
    • \n\t
    • file consist of English letters and digits.
    • \n\t
    • 1 <= queries.length <= 10
    • \n\t
    • 1 <= queries[i] <= 500
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6587\u4ef6\uff0c\u5e76\u4e14\u8be5\u6587\u4ef6\u53ea\u80fd\u901a\u8fc7\u7ed9\u5b9a\u7684\u00a0read4\u00a0\u65b9\u6cd5\u6765\u8bfb\u53d6\uff0c\u8bf7\u5b9e\u73b0\u4e00\u4e2a\u65b9\u6cd5\u4f7f\u5176\u80fd\u591f\u8bfb\u53d6 n \u4e2a\u5b57\u7b26\u3002\u6ce8\u610f\uff1a\u4f60\u7684\u00a0read \u65b9\u6cd5\u53ef\u80fd\u4f1a\u88ab\u8c03\u7528\u591a\u6b21\u3002

    \n\n

    read4 \u7684\u5b9a\u4e49\uff1a

    \n\n

    read4 API \u4ece\u6587\u4ef6\u4e2d\u8bfb\u53d6 4 \u4e2a\u8fde\u7eed\u7684\u5b57\u7b26\uff0c\u7136\u540e\u5c06\u8fd9\u4e9b\u5b57\u7b26\u5199\u5165\u7f13\u51b2\u533a\u6570\u7ec4 buf4 \u3002

    \n\n

    \u8fd4\u56de\u503c\u662f\u8bfb\u53d6\u7684\u5b9e\u9645\u5b57\u7b26\u6570\u3002

    \n\n

    \u8bf7\u6ce8\u610f\uff0cread4() \u6709\u5176\u81ea\u5df1\u7684\u6587\u4ef6\u6307\u9488\uff0c\u7c7b\u4f3c\u4e8e C \u4e2d\u7684 FILE * fp \u3002

    \n\n
    \n\u53c2\u6570\u7c7b\u578b: char[] buf4\n\u8fd4\u56de\u7c7b\u578b: int\n\n\u6ce8\u610f: buf4[] \u662f\u76ee\u6807\u7f13\u5b58\u533a\u4e0d\u662f\u6e90\u7f13\u5b58\u533a\uff0cread4 \u7684\u8fd4\u56de\u7ed3\u679c\u5c06\u4f1a\u590d\u5236\u5230 buf4[] \u5f53\u4e2d\u3002\n
    \n\n

    \u4e0b\u5217\u662f\u4e00\u4e9b\u4f7f\u7528 read4 \u7684\u4f8b\u5b50\uff1a

    \n\n

    \"\"

    \n\n
    \nFile file(\"abcde\"); // \u6587\u4ef6\u540d\u4e3a \"abcde\"\uff0c \u521d\u59cb\u6587\u4ef6\u6307\u9488 (fp) \u6307\u5411 'a' \nchar[] buf4 = new char[4]; // \u521b\u5efa\u4e00\u4e2a\u7f13\u5b58\u533a\u4f7f\u5176\u80fd\u5bb9\u7eb3\u8db3\u591f\u7684\u5b57\u7b26\nread4(buf4); // read4 \u8fd4\u56de 4\u3002\u73b0\u5728 buf4 = \"abcd\"\uff0cfp \u6307\u5411 'e'\nread4(buf4); // read4 \u8fd4\u56de 1\u3002\u73b0\u5728 buf4 = \"e\"\uff0cfp \u6307\u5411\u6587\u4ef6\u672b\u5c3e\nread4(buf4); // read4 \u8fd4\u56de 0\u3002\u73b0\u5728 buf4 = \"\"\uff0cfp \u6307\u5411\u6587\u4ef6\u672b\u5c3e
    \n\n

    read \u65b9\u6cd5\uff1a

    \n\n

    \u901a\u8fc7\u4f7f\u7528 read4 \u65b9\u6cd5\uff0c\u5b9e\u73b0\u00a0read \u65b9\u6cd5\u3002\u8be5\u65b9\u6cd5\u53ef\u4ee5\u4ece\u6587\u4ef6\u4e2d\u8bfb\u53d6 n \u4e2a\u5b57\u7b26\u5e76\u5c06\u5176\u5b58\u50a8\u5230\u7f13\u5b58\u6570\u7ec4\u00a0buf \u4e2d\u3002\u60a8\u00a0\u4e0d\u80fd\u00a0\u76f4\u63a5\u64cd\u4f5c\u6587\u4ef6\u3002

    \n\n

    \u8fd4\u56de\u503c\u4e3a\u5b9e\u9645\u8bfb\u53d6\u7684\u5b57\u7b26\u3002

    \n\n

    read\u00a0\u7684\u5b9a\u4e49\uff1a

    \n\n
    \n\u53c2\u6570:   char[] buf, int n\n\u8fd4\u56de\u503c: int\n\n\u6ce8\u610f: buf[] \u662f\u76ee\u6807\u7f13\u5b58\u533a\u4e0d\u662f\u6e90\u7f13\u5b58\u533a\uff0c\u4f60\u9700\u8981\u5c06\u7ed3\u679c\u5199\u5165 buf[] \u4e2d\u3002\n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \nFile file(\"abc\");\nSolution sol;\n// \u5047\u5b9a buf \u5df2\u7ecf\u88ab\u5206\u914d\u4e86\u5185\u5b58\uff0c\u5e76\u4e14\u6709\u8db3\u591f\u7684\u7a7a\u95f4\u6765\u5b58\u50a8\u6587\u4ef6\u4e2d\u7684\u6240\u6709\u5b57\u7b26\u3002\nsol.read(buf, 1); // \u5f53\u8c03\u7528\u4e86\u60a8\u7684 read \u65b9\u6cd5\u540e\uff0cbuf \u9700\u8981\u5305\u542b \"a\"\u3002 \u4e00\u5171\u8bfb\u53d6 1 \u4e2a\u5b57\u7b26\uff0c\u56e0\u6b64\u8fd4\u56de 1\u3002\nsol.read(buf, 2); // \u73b0\u5728 buf \u9700\u8981\u5305\u542b \"bc\"\u3002\u4e00\u5171\u8bfb\u53d6 2 \u4e2a\u5b57\u7b26\uff0c\u56e0\u6b64\u8fd4\u56de 2\u3002\nsol.read(buf, 1); // \u7531\u4e8e\u5df2\u7ecf\u5230\u8fbe\u4e86\u6587\u4ef6\u672b\u5c3e\uff0c\u6ca1\u6709\u66f4\u591a\u7684\u5b57\u7b26\u53ef\u4ee5\u8bfb\u53d6\uff0c\u56e0\u6b64\u8fd4\u56de 0\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \nFile file(\"abc\");\nSolution sol;\nsol.read(buf, 4); // \u5f53\u8c03\u7528\u4e86\u60a8\u7684 read \u65b9\u6cd5\u540e\uff0cbuf \u9700\u8981\u5305\u542b \"abc\"\u3002 \u4e00\u5171\u53ea\u80fd\u8bfb\u53d6 3 \u4e2a\u5b57\u7b26\uff0c\u56e0\u6b64\u8fd4\u56de 3\u3002\nsol.read(buf, 1); // \u7531\u4e8e\u5df2\u7ecf\u5230\u8fbe\u4e86\u6587\u4ef6\u672b\u5c3e\uff0c\u6ca1\u6709\u66f4\u591a\u7684\u5b57\u7b26\u53ef\u4ee5\u8bfb\u53d6\uff0c\u56e0\u6b64\u8fd4\u56de 0\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u4f60 \u4e0d\u80fd \u76f4\u63a5\u64cd\u4f5c\u8be5\u6587\u4ef6\uff0c\u6587\u4ef6\u53ea\u80fd\u901a\u8fc7 read4 \u83b7\u53d6\u800c \u4e0d\u80fd \u901a\u8fc7 read\u3002
    • \n\t
    • read\u00a0 \u51fd\u6570\u53ef\u4ee5\u88ab\u8c03\u7528\u00a0\u591a\u6b21\u3002
    • \n\t
    • \u8bf7\u8bb0\u5f97\u00a0\u91cd\u7f6e\u00a0\u5728 Solution \u4e2d\u58f0\u660e\u7684\u7c7b\u53d8\u91cf\uff08\u9759\u6001\u53d8\u91cf\uff09\uff0c\u56e0\u4e3a\u7c7b\u53d8\u91cf\u4f1a\u00a0\u5728\u591a\u4e2a\u6d4b\u8bd5\u7528\u4f8b\u4e2d\u4fdd\u6301\u4e0d\u53d8\uff0c\u5f71\u54cd\u5224\u9898\u51c6\u786e\u3002\u8bf7 \u67e5\u9605 \u8fd9\u91cc\u3002
    • \n\t
    • \u4f60\u53ef\u4ee5\u5047\u5b9a\u76ee\u6807\u7f13\u5b58\u6570\u7ec4\u00a0buf \u4fdd\u8bc1\u6709\u8db3\u591f\u7684\u7a7a\u95f4\u5b58\u4e0b n \u4e2a\u5b57\u7b26\u3002\u00a0
    • \n\t
    • \u4fdd\u8bc1\u5728\u4e00\u4e2a\u7ed9\u5b9a\u6d4b\u8bd5\u7528\u4f8b\u4e2d\uff0cread \u51fd\u6570\u4f7f\u7528\u7684\u662f\u540c\u4e00\u4e2a buf\u3002
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * The read4 API is defined in the parent class Reader4.\n * int read4(char *buf4);\n */\n\nclass Solution {\npublic:\n /**\n * @param buf Destination buffer\n * @param n Number of characters to read\n * @return The number of actual characters read\n */\n int read(char *buf, int n) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * The read4 API is defined in the parent class Reader4.\n * int read4(char[] buf4); \n */\n\npublic class Solution extends Reader4 {\n /**\n * @param buf Destination buffer\n * @param n Number of characters to read\n * @return The number of actual characters read\n */\n public int read(char[] buf, int n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# The read4 API is already defined for you.\n# @param buf4, List[str]\n# @return an integer\n# def read4(buf4):\n\nclass Solution(object):\n def read(self, buf, n):\n \"\"\"\n :type buf: List[str]\n :type n: int\n :rtype: int\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# The read4 API is already defined for you.\n# def read4(buf4: List[str]) -> int:\n\nclass Solution:\n def read(self, buf: List[str], n: int) -> int:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * The read4 API is defined in the parent class Reader4.\n * int read4(char *buf4);\n */\n\ntypedef struct {\n \n} Solution;\n\n/** initialize your data structure here. */\nSolution* solutionCreate() {\n\n}\n\n/**\n * @param buf Destination buffer\n * @param n Number of characters to read\n * @return The number of actual characters read\n */\nint _read(Solution* obj, char* buf, int n) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * The Read4 API is defined in the parent class Reader4.\n * int Read4(char[] buf4);\n */\n\npublic class Solution : Reader4 {\n /**\n * @param buf Destination buffer\n * @param n Number of characters to read\n * @return The number of actual characters read\n */\n public int Read(char[] buf, int n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for read4()\n * \n * @param {character[]} buf Destination buffer\n * @return {number} The number of characters read\n * read4 = function(buf4) {\n * ...\n * };\n */\n\n/**\n * @param {function} read4()\n * @return {function}\n */\nvar solution = function(read4) {\n /**\n * @param {character[]} buf Destination buffer\n * @param {number} n Number of characters to read\n * @return {number} The number of actual characters read\n */\n return function(buf, n) {\n \n };\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# The read4 API is already defined for you.\n# Below is an example of how the read4 API can be called.\n# file = File.new(\"abcdefghijk\") File is \"abcdefghijk\", initially file pointer (fp) points to 'a'\n# buf4 = [' '] * 4 Create buffer with enough space to store characters\n# read4(buf4) # read4 returns 4. Now buf = ['a','b','c','d'], fp points to 'e'\n# read4(buf4) # read4 returns 4. Now buf = ['e','f','g','h'], fp points to 'i'\n# read4(buf4) # read4 returns 3. Now buf = ['i','j','k',...], fp points to end of file\n\nclass Solution\n # @param {List[str]} buf\n\t# @param {int} n\n\t# @return {int}\n def read(buf, n)\n \n end\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * The read4 API is defined in the parent class Reader4.\n * func read4(_ buf4: inout [Character]) -> Int;\n */\n\nclass Solution : Reader4 {\n\t/**\n * @param buf Destination buffer\n * @param n Number of characters to read\n * @return The number of actual characters read\n */\n func read(_ buf: inout [Character], _ n: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * The read4 API is already defined for you.\n *\n * read4 := func(buf4 []byte) int\n *\n * // Below is an example of how the read4 API can be called.\n * file := File(\"abcdefghijk\") // File is \"abcdefghijk\", initially file pointer (fp) points to 'a'\n * buf4 := make([]byte, 4) // Create buffer with enough space to store characters\n * read4(buf4) // read4 returns 4. Now buf = ['a','b','c','d'], fp points to 'e'\n * read4(buf4) // read4 returns 4. Now buf = ['e','f','g','h'], fp points to 'i'\n * read4(buf4) // read4 returns 3. Now buf = ['i','j','k',...], fp points to end of file\n */\n\nvar solution = func(read4 func([]byte) int) func([]byte, int) int {\n // implement read below.\n return func(buf []byte, n int) int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * The read4 API is defined in the parent class Reader4.\n * def read4(buf4: Array[Char]): Int = {}\n */\n\nclass Solution extends Reader4 {\n /**\n * @param buf Destination buffer\n \t * @param n Number of characters to read\n * @return The number of actual characters read\n */\n def read(buf: Array[Char], n: Int): Int = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n* The read4 API is defined in the parent class Reader4.\n* fun read4(buf4:CharArray): Int {}\n*/\n\nclass Solution:Reader4() {\n /**\n * @param buf Destination buffer\n * @param n Number of characters to read\n * @return The number of actual characters read\n */\n override fun read(buf:CharArray, n:Int): Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/* The read4 API is defined in the parent class Reader4.\n public function read4(&$buf4){} */\n\nclass Solution extends Reader4 {\n /**\n * @param Char[] &$buf\tDestination buffer\n * @param Integer $n\t\tNumber of characters to read\n * @return Integer \t\t\tThe number of actual characters read\n */\n function read(&$buf, $n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for read4()\n * read4 = function(buf4: string[]): number {\n * ...\n * };\n */\n\nvar solution = function(read4: any) {\n\n return function(buf: string[], n: number): number {\n \n };\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0158](https://leetcode-cn.com/problems/read-n-characters-given-read4-ii-call-multiple-times)", "[\u7528 Read4 \u8bfb\u53d6 N \u4e2a\u5b57\u7b26 II](/solution/0100-0199/0158.Read%20N%20Characters%20Given%20Read4%20II%20-%20Call%20multiple%20times/README.md)", "`\u5b57\u7b26\u4e32`", "\u56f0\u96be", "\ud83d\udd12"], "md_table_row_en": ["[0158](https://leetcode.com/problems/read-n-characters-given-read4-ii-call-multiple-times)", "[Read N Characters Given Read4 II - Call multiple times](/solution/0100-0199/0158.Read%20N%20Characters%20Given%20Read4%20II%20-%20Call%20multiple%20times/README_EN.md)", "`String`", "Hard", "\ud83d\udd12"]}, {"question_id": "0157", "frontend_question_id": "0157", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/read-n-characters-given-read4", "url_en": "https://leetcode.com/problems/read-n-characters-given-read4", "relative_path_cn": "/solution/0100-0199/0157.Read%20N%20Characters%20Given%20Read4/README.md", "relative_path_en": "/solution/0100-0199/0157.Read%20N%20Characters%20Given%20Read4/README_EN.md", "title_cn": "\u7528 Read4 \u8bfb\u53d6 N \u4e2a\u5b57\u7b26", "title_en": "Read N Characters Given Read4", "question_title_slug": "read-n-characters-given-read4", "content_en": "

    Given a file and assume that you can only read the file using a given method read4, implement a method to read n characters.

    \n\n

    Method read4:

    \n\n

    The API read4 reads four consecutive characters from file, then writes those characters into the buffer array buf4.

    \n\n

    The return value is the number of actual characters read.

    \n\n

    Note that read4() has its own file pointer, much like FILE *fp in C.

    \n\n

    Definition of read4:

    \n\n
    \n    Parameter:  char[] buf4\n    Returns:    int\n\nbuf4[] is a destination, not a source. The results from read4 will be copied to buf4[].\n
    \n\n

    Below is a high-level example of how read4 works:

    \n\"\"\n
    \nFile file("abcde"); // File is "abcde", initially file pointer (fp) points to 'a'\nchar[] buf4 = new char[4]; // Create buffer with enough space to store characters\nread4(buf4); // read4 returns 4. Now buf4 = "abcd", fp points to 'e'\nread4(buf4); // read4 returns 1. Now buf4 = "e", fp points to end of file\nread4(buf4); // read4 returns 0. Now buf4 = "", fp points to end of file\n
    \n\n

     

    \n\n

    Method read:

    \n\n

    By using the read4 method, implement the method read that reads n characters from file and store it in the buffer array buf. Consider that you cannot manipulate file directly.

    \n\n

    The return value is the number of actual characters read.

    \n\n

    Definition of read:

    \n\n
    \n    Parameters:\tchar[] buf, int n\n    Returns:\tint\n\nbuf[] is a destination, not a source. You will need to write the results to buf[].\n
    \n\n

    Note:

    \n\n
      \n\t
    • Consider that you cannot manipulate the file directly. The file is only accessible for read4 but not for read.
    • \n\t
    • The read function will only be called once for each test case.
    • \n\t
    • You may assume the destination buffer array, buf, is guaranteed to have enough space for storing n characters.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: file = "abc", n = 4\nOutput: 3\nExplanation: After calling your read method, buf should contain "abc". We read a total of 3 characters from the file, so return 3.\nNote that "abc" is the file's content, not buf. buf is the destination buffer that you will have to write the results to.\n
    \n\n

    Example 2:

    \n\n
    \nInput: file = "abcde", n = 5\nOutput: 5\nExplanation: After calling your read method, buf should contain "abcde". We read a total of 5 characters from the file, so return 5.\n
    \n\n

    Example 3:

    \n\n
    \nInput: file = "abcdABCD1234", n = 12\nOutput: 12\nExplanation: After calling your read method, buf should contain "abcdABCD1234". We read a total of 12 characters from the file, so return 12.\n
    \n\n

    Example 4:

    \n\n
    \nInput: file = "leetcode", n = 5\nOutput: 5\nExplanation: After calling your read method, buf should contain "leetc". We read a total of 5 characters from the file, so return 5.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= file.length <= 500
    • \n\t
    • file consist of English letters and digits.
    • \n\t
    • 1 <= n <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6587\u4ef6\uff0c\u5e76\u4e14\u8be5\u6587\u4ef6\u53ea\u80fd\u901a\u8fc7\u7ed9\u5b9a\u7684 read4 \u65b9\u6cd5\u6765\u8bfb\u53d6\uff0c\u8bf7\u5b9e\u73b0\u4e00\u4e2a\u65b9\u6cd5\u4f7f\u5176\u80fd\u591f\u8bfb\u53d6 n \u4e2a\u5b57\u7b26\u3002

    \n\n

    read4 \u65b9\u6cd5\uff1a

    \n\n

    API read4 \u53ef\u4ee5\u4ece\u6587\u4ef6\u4e2d\u8bfb\u53d6 4 \u4e2a\u8fde\u7eed\u7684\u5b57\u7b26\uff0c\u5e76\u4e14\u5c06\u5b83\u4eec\u5199\u5165\u7f13\u5b58\u6570\u7ec4 buf \u4e2d\u3002

    \n\n

    \u8fd4\u56de\u503c\u4e3a\u5b9e\u9645\u8bfb\u53d6\u7684\u5b57\u7b26\u4e2a\u6570\u3002

    \n\n

    \u6ce8\u610f read4() \u81ea\u8eab\u62e5\u6709\u6587\u4ef6\u6307\u9488\uff0c\u5f88\u7c7b\u4f3c\u4e8e C \u8bed\u8a00\u4e2d\u7684 FILE *fp \u3002

    \n\n

    read4 \u7684\u5b9a\u4e49\uff1a

    \n\n
    \u53c2\u6570\u7c7b\u578b: char[] buf4\n\u8fd4\u56de\u7c7b\u578b: int\n\n\u6ce8\u610f: buf4[] \u662f\u76ee\u6807\u7f13\u5b58\u533a\u4e0d\u662f\u6e90\u7f13\u5b58\u533a\uff0cread4 \u7684\u8fd4\u56de\u7ed3\u679c\u5c06\u4f1a\u590d\u5236\u5230 buf4[] \u5f53\u4e2d\u3002\n
    \n\n

    \u4e0b\u5217\u662f\u4e00\u4e9b\u4f7f\u7528 read4 \u7684\u4f8b\u5b50\uff1a

    \n\n

    \n\n
    File file("abcde"); // \u6587\u4ef6\u540d\u4e3a "abcde"\uff0c \u521d\u59cb\u6587\u4ef6\u6307\u9488 (fp) \u6307\u5411 'a' \nchar[] buf4 = new char[4]; // \u521b\u5efa\u4e00\u4e2a\u7f13\u5b58\u533a\u4f7f\u5176\u80fd\u5bb9\u7eb3\u8db3\u591f\u7684\u5b57\u7b26\nread4(buf4); // read4 \u8fd4\u56de 4\u3002\u73b0\u5728 buf4 = "abcd"\uff0cfp \u6307\u5411 'e'\nread4(buf4); // read4 \u8fd4\u56de 1\u3002\u73b0\u5728 buf4 = "e"\uff0cfp \u6307\u5411\u6587\u4ef6\u672b\u5c3e\nread4(buf4); // read4 \u8fd4\u56de 0\u3002\u73b0\u5728 buf = ""\uff0cfp \u6307\u5411\u6587\u4ef6\u672b\u5c3e
    \n\n

    read \u65b9\u6cd5\uff1a

    \n\n

    \u901a\u8fc7\u4f7f\u7528 read4 \u65b9\u6cd5\uff0c\u5b9e\u73b0 read \u65b9\u6cd5\u3002\u8be5\u65b9\u6cd5\u53ef\u4ee5\u4ece\u6587\u4ef6\u4e2d\u8bfb\u53d6 n \u4e2a\u5b57\u7b26\u5e76\u5c06\u5176\u5b58\u50a8\u5230\u7f13\u5b58\u6570\u7ec4 buf \u4e2d\u3002\u60a8 \u4e0d\u80fd \u76f4\u63a5\u64cd\u4f5c\u6587\u4ef6\u3002

    \n\n

    \u8fd4\u56de\u503c\u4e3a\u5b9e\u9645\u8bfb\u53d6\u7684\u5b57\u7b26\u3002

    \n\n

    read \u7684\u5b9a\u4e49\uff1a

    \n\n
    \u53c2\u6570\u7c7b\u578b:   char[] buf, int n\n\u8fd4\u56de\u7c7b\u578b:   int\n\n\u6ce8\u610f: buf[] \u662f\u76ee\u6807\u7f13\u5b58\u533a\u4e0d\u662f\u6e90\u7f13\u5b58\u533a\uff0c\u4f60\u9700\u8981\u5c06\u7ed3\u679c\u5199\u5165 buf[] \u4e2d\u3002\n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a file = "abc", n = 4\n\u8f93\u51fa\uff1a 3\n\u89e3\u91ca\uff1a \u5f53\u6267\u884c\u4f60\u7684 read \u65b9\u6cd5\u540e\uff0cbuf \u9700\u8981\u5305\u542b "abc"\u3002 \u6587\u4ef6\u4e00\u5171 3 \u4e2a\u5b57\u7b26\uff0c\u56e0\u6b64\u8fd4\u56de 3\u3002 \u6ce8\u610f "abc" \u662f\u6587\u4ef6\u7684\u5185\u5bb9\uff0c\u4e0d\u662f buf \u7684\u5185\u5bb9\uff0cbuf \u662f\u4f60\u9700\u8981\u5199\u5165\u7ed3\u679c\u7684\u76ee\u6807\u7f13\u5b58\u533a\u3002 
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a file = "abcde", n = 5\n\u8f93\u51fa\uff1a 5\n\u89e3\u91ca\uff1a \u5f53\u6267\u884c\u4f60\u7684 read \u65b9\u6cd5\u540e\uff0cbuf \u9700\u8981\u5305\u542b "abcde"\u3002\u6587\u4ef6\u5171 5 \u4e2a\u5b57\u7b26\uff0c\u56e0\u6b64\u8fd4\u56de 5\u3002\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u8f93\u5165\uff1a file = "abcdABCD1234", n = 12\n\u8f93\u51fa\uff1a 12\n\u89e3\u91ca\uff1a \u5f53\u6267\u884c\u4f60\u7684 read \u65b9\u6cd5\u540e\uff0cbuf \u9700\u8981\u5305\u542b "abcdABCD1234"\u3002\u6587\u4ef6\u4e00\u5171 12 \u4e2a\u5b57\u7b26\uff0c\u56e0\u6b64\u8fd4\u56de 12\u3002\n
    \n\n

    \u793a\u4f8b 4:

    \n\n
    \u8f93\u5165\uff1a file = "leetcode", n = 5\n\u8f93\u51fa\uff1a 5\n\u89e3\u91ca\uff1a \u5f53\u6267\u884c\u4f60\u7684 read \u65b9\u6cd5\u540e\uff0cbuf \u9700\u8981\u5305\u542b "leetc"\u3002\u6587\u4ef6\u4e2d\u4e00\u5171 5 \u4e2a\u5b57\u7b26\uff0c\u56e0\u6b64\u8fd4\u56de 5\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u4f60 \u4e0d\u80fd \u76f4\u63a5\u64cd\u4f5c\u8be5\u6587\u4ef6\uff0c\u6587\u4ef6\u53ea\u80fd\u901a\u8fc7 read4 \u83b7\u53d6\u800c \u4e0d\u80fd \u901a\u8fc7 read\u3002
    • \n\t
    • read  \u51fd\u6570\u53ea\u5728\u6bcf\u4e2a\u6d4b\u8bd5\u7528\u4f8b\u8c03\u7528\u4e00\u6b21\u3002
    • \n\t
    • \u4f60\u53ef\u4ee5\u5047\u5b9a\u76ee\u6807\u7f13\u5b58\u6570\u7ec4 buf \u4fdd\u8bc1\u6709\u8db3\u591f\u7684\u7a7a\u95f4\u5b58\u4e0b n \u4e2a\u5b57\u7b26\u3002 
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * The read4 API is defined in the parent class Reader4.\n * int read4(char *buf4);\n */\n\nclass Solution {\npublic:\n /**\n * @param buf Destination buffer\n * @param n Number of characters to read\n * @return The number of actual characters read\n */\n int read(char *buf, int n) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * The read4 API is defined in the parent class Reader4.\n * int read4(char[] buf4);\n */\n\npublic class Solution extends Reader4 {\n /**\n * @param buf Destination buffer\n * @param n Number of characters to read\n * @return The number of actual characters read\n */\n public int read(char[] buf, int n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "\"\"\"\nThe read4 API is already defined for you.\n\n @param buf4, a list of characters\n @return an integer\n def read4(buf4):\n\n# Below is an example of how the read4 API can be called.\nfile = File(\"abcdefghijk\") # File is \"abcdefghijk\", initially file pointer (fp) points to 'a'\nbuf4 = [' '] * 4 # Create buffer with enough space to store characters\nread4(buf4) # read4 returns 4. Now buf = ['a','b','c','d'], fp points to 'e'\nread4(buf4) # read4 returns 4. Now buf = ['e','f','g','h'], fp points to 'i'\nread4(buf4) # read4 returns 3. Now buf = ['i','j','k',...], fp points to end of file\n\"\"\"\n\nclass Solution(object):\n def read(self, buf, n):\n \"\"\"\n :type buf: Destination buffer (List[str])\n :type n: Number of characters to read (int)\n :rtype: The number of actual characters read (int)\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "\"\"\"\nThe read4 API is already defined for you.\n\n @param buf4, a list of characters\n @return an integer\n def read4(buf4):\n\n# Below is an example of how the read4 API can be called.\nfile = File(\"abcdefghijk\") # File is \"abcdefghijk\", initially file pointer (fp) points to 'a'\nbuf4 = [' '] * 4 # Create buffer with enough space to store characters\nread4(buf4) # read4 returns 4. Now buf = ['a','b','c','d'], fp points to 'e'\nread4(buf4) # read4 returns 4. Now buf = ['e','f','g','h'], fp points to 'i'\nread4(buf4) # read4 returns 3. Now buf = ['i','j','k',...], fp points to end of file\n\"\"\"\n\nclass Solution:\n def read(self, buf, n):\n \"\"\"\n :type buf: Destination buffer (List[str])\n :type n: Number of characters to read (int)\n :rtype: The number of actual characters read (int)\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * The read4 API is defined in the parent class Reader4.\n * int read4(char *buf4);\n */\n\n/**\n * @param buf Destination buffer\n * @param n Number of characters to read\n * @return The number of actual characters read\n */\nint _read(char* buf, int n) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * The Read4 API is defined in the parent class Reader4.\n * int Read4(char[] buf4);\n */\n\npublic class Solution : Reader4 {\n /**\n * @param buf Destination buffer\n * @param n Number of characters to read\n * @return The number of actual characters read\n */\n public int Read(char[] buf, int n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for read4()\n * \n * @param {character[]} buf4 Destination buffer\n * @return {number} The number of actual characters read\n * read4 = function(buf4) {\n * ...\n * };\n */\n\n/**\n * @param {function} read4()\n * @return {function}\n */\nvar solution = function(read4) {\n /**\n * @param {character[]} buf Destination buffer\n * @param {number} n Number of characters to read\n * @return {number} The number of actual characters read\n */\n return function(buf, n) {\n \n };\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# The read4 API is already defined for you.\n# Below is an example of how the read4 API can be called.\n# file = File.new(\"abcdefghijk\") File is \"abcdefghijk\", initially file pointer (fp) points to 'a'\n# buf4 = [' '] * 4 Create buffer with enough space to store characters\n# read4(buf4) # read4 returns 4. Now buf = ['a','b','c','d'], fp points to 'e'\n# read4(buf4) # read4 returns 4. Now buf = ['e','f','g','h'], fp points to 'i'\n# read4(buf4) # read4 returns 3. Now buf = ['i','j','k',...], fp points to end of file\n\n# @param {List[str]} buf\n# @param {int} n\n# @return {int}\ndef read(buf, n)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * The read4 API is defined in the parent class Reader4.\n * func read4(_ buf4: inout [Character]) -> Int;\n */\n\nclass Solution : Reader4 {\n\t/**\n * @param buf Destination buffer\n * @param n Number of characters to read\n * @return The number of actual characters read\n */\n func read(_ buf: inout [Character], _ n: Int) -> Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * The read4 API is already defined for you.\n *\n * read4 := func(buf4 []byte) int\n *\n * // Below is an example of how the read4 API can be called.\n * file := File(\"abcdefghijk\") // File is \"abcdefghijk\", initially file pointer (fp) points to 'a'\n * buf4 := make([]byte, 4) // Create buffer with enough space to store characters\n * read4(buf4) // read4 returns 4. Now buf = ['a','b','c','d'], fp points to 'e'\n * read4(buf4) // read4 returns 4. Now buf = ['e','f','g','h'], fp points to 'i'\n * read4(buf4) // read4 returns 3. Now buf = ['i','j','k',...], fp points to end of file\n */\n\nvar solution = func(read4 func([]byte) int) func([]byte, int) int {\n // implement read below.\n return func(buf []byte, n int) int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * The read4 API is defined in the parent class Reader4.\n * def read4(buf4: Array[Char]): Int = {}\n */\n\nclass Solution extends Reader4 {\n /**\n * @param buf Destination buffer\n \t * @param n Number of characters to read\n * @return The number of actual characters read\n */\n def read(buf: Array[Char], n: Int): Int = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n* The read4 API is defined in the parent class Reader4.\n* fun read4(buf4:CharArray): Int {}\n*/\n\nclass Solution:Reader4() {\n /**\n * @param buf Destination buffer\n * @param n Number of characters to read\n * @return The number of actual characters read\n */\n override fun read(buf:CharArray, n:Int): Int {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "/**\n * The read4 API is defined as.\n * fn read4(&self,buf4: &mut [char]) -> i32;\n * You can call it using self.read4(buf4)\n */\n\nimpl Solution {\n pub fn read(&self, buf: &mut [char], n: i32) -> i32 {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/* The read4 API is defined in the parent class Reader4.\n public function read4(&$buf4){} */\n\nclass Solution extends Reader4 {\n /**\n * @param Char[] &$buf\tDestination buffer\n * @param Integer $n\t\tNumber of characters to read\n * @return Integer \t\t\tThe number of actual characters read\n */\n function read(&$buf, $n) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for read4()\n * read4 = function(buf4: string[]): number {\n * ...\n * };\n */\n\nvar solution = function(read4: any) {\n\n return function(buf: string[], n: number): number {\n \n };\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0157](https://leetcode-cn.com/problems/read-n-characters-given-read4)", "[\u7528 Read4 \u8bfb\u53d6 N \u4e2a\u5b57\u7b26](/solution/0100-0199/0157.Read%20N%20Characters%20Given%20Read4/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", "\ud83d\udd12"], "md_table_row_en": ["[0157](https://leetcode.com/problems/read-n-characters-given-read4)", "[Read N Characters Given Read4](/solution/0100-0199/0157.Read%20N%20Characters%20Given%20Read4/README_EN.md)", "`String`", "Easy", "\ud83d\udd12"]}, {"question_id": "0156", "frontend_question_id": "0156", "paid_only": true, "paid_only_cn": true, "url_cn": "https://leetcode-cn.com/problems/binary-tree-upside-down", "url_en": "https://leetcode.com/problems/binary-tree-upside-down", "relative_path_cn": "/solution/0100-0199/0156.Binary%20Tree%20Upside%20Down/README.md", "relative_path_en": "/solution/0100-0199/0156.Binary%20Tree%20Upside%20Down/README_EN.md", "title_cn": "\u4e0a\u4e0b\u7ffb\u8f6c\u4e8c\u53c9\u6811", "title_en": "Binary Tree Upside Down", "question_title_slug": "binary-tree-upside-down", "content_en": "

    Given the root of a binary tree, turn the tree upside down and return the new root.

    \n\n

    You can turn a binary tree upside down with the following steps:

    \n\n
      \n\t
    1. The original left child becomes the new root.
    2. \n\t
    3. The original root becomes the new right child.
    4. \n\t
    5. The original right child becomes the new left child.
    6. \n
    \n\n

    \"\"

    \n\n

    The mentioned steps are done level by level, it is guaranteed that every node in the given tree has either 0 or 2 children.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,2,3,4,5]\nOutput: [4,5,2,null,null,3,1]\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = []\nOutput: []\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = [1]\nOutput: [1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree will be in the range [0, 10].
    • \n\t
    • 1 <= Node.val <= 10
    • \n\t
    • Every node has either 0 or 2 children.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811\uff0c\u5176\u4e2d\u6240\u6709\u7684\u53f3\u8282\u70b9\u8981\u4e48\u662f\u5177\u6709\u5144\u5f1f\u8282\u70b9\uff08\u62e5\u6709\u76f8\u540c\u7236\u8282\u70b9\u7684\u5de6\u8282\u70b9\uff09\u7684\u53f6\u8282\u70b9\uff0c\u8981\u4e48\u4e3a\u7a7a\uff0c\u5c06\u6b64\u4e8c\u53c9\u6811\u4e0a\u4e0b\u7ffb\u8f6c\u5e76\u5c06\u5b83\u53d8\u6210\u4e00\u68f5\u6811\uff0c \u539f\u6765\u7684\u53f3\u8282\u70b9\u5c06\u8f6c\u6362\u6210\u5de6\u53f6\u8282\u70b9\u3002\u8fd4\u56de\u65b0\u7684\u6839\u3002

    \n\n

    \u4f8b\u5b50:

    \n\n
    \u8f93\u5165: [1,2,3,4,5]\n\n    1\n   / \\\n  2   3\n / \\\n4   5\n\n\u8f93\u51fa: \u8fd4\u56de\u4e8c\u53c9\u6811\u7684\u6839 [4,5,2,#,#,3,1]\n\n   4\n  / \\\n 5   2\n    / \\\n   3   1  \n
    \n\n

    \u8bf4\u660e:

    \n\n

    \u5bf9 [4,5,2,#,#,3,1] \u611f\u5230\u56f0\u60d1? \u4e0b\u9762\u8be6\u7ec6\u4ecb\u7ecd\u8bf7\u67e5\u770b \u4e8c\u53c9\u6811\u662f\u5982\u4f55\u88ab\u5e8f\u5217\u5316\u7684\u3002

    \n\n

    \u4e8c\u53c9\u6811\u7684\u5e8f\u5217\u5316\u9075\u5faa\u5c42\u6b21\u904d\u5386\u89c4\u5219\uff0c\u5f53\u6ca1\u6709\u8282\u70b9\u5b58\u5728\u65f6\uff0c'#' \u8868\u793a\u8def\u5f84\u7ec8\u6b62\u7b26\u3002

    \n\n

    \u8fd9\u91cc\u6709\u4e00\u4e2a\u4f8b\u5b50:

    \n\n
       1\n  / \\\n 2   3\n    /\n   4\n    \\\n     5\n
    \n\n

    \u4e0a\u9762\u7684\u4e8c\u53c9\u6811\u5219\u88ab\u5e8f\u5217\u5316\u4e3a [1,2,3,#,#,4,#,#,5].

    \n", "tags_en": ["Tree"], "tags_cn": ["\u6811"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* upsideDownBinaryTree(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode upsideDownBinaryTree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def upsideDownBinaryTree(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: TreeNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def upsideDownBinaryTree(self, root: TreeNode) -> TreeNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* upsideDownBinaryTree(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode UpsideDownBinaryTree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {TreeNode}\n */\nvar upsideDownBinaryTree = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {TreeNode}\ndef upside_down_binary_tree(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func upsideDownBinaryTree(_ root: TreeNode?) -> TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc upsideDownBinaryTree(root *TreeNode) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def upsideDownBinaryTree(root: TreeNode): TreeNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun upsideDownBinaryTree(root: TreeNode?): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn upside_down_binary_tree(root: Option>>) -> Option>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return TreeNode\n */\n function upsideDownBinaryTree($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction upsideDownBinaryTree(root: TreeNode | null): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (upside-down-binary-tree root)\n (-> (or/c tree-node? #f) (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0156](https://leetcode-cn.com/problems/binary-tree-upside-down)", "[\u4e0a\u4e0b\u7ffb\u8f6c\u4e8c\u53c9\u6811](/solution/0100-0199/0156.Binary%20Tree%20Upside%20Down/README.md)", "`\u6811`", "\u4e2d\u7b49", "\ud83d\udd12"], "md_table_row_en": ["[0156](https://leetcode.com/problems/binary-tree-upside-down)", "[Binary Tree Upside Down](/solution/0100-0199/0156.Binary%20Tree%20Upside%20Down/README_EN.md)", "`Tree`", "Medium", "\ud83d\udd12"]}, {"question_id": "0155", "frontend_question_id": "0155", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/min-stack", "url_en": "https://leetcode.com/problems/min-stack", "relative_path_cn": "/solution/0100-0199/0155.Min%20Stack/README.md", "relative_path_en": "/solution/0100-0199/0155.Min%20Stack/README_EN.md", "title_cn": "\u6700\u5c0f\u6808", "title_en": "Min Stack", "question_title_slug": "min-stack", "content_en": "

    Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.

    \n\n

    Implement the MinStack class:

    \n\n
      \n\t
    • MinStack() initializes the stack object.
    • \n\t
    • void push(val) pushes the element val onto the stack.
    • \n\t
    • void pop() removes the element on the top of the stack.
    • \n\t
    • int top() gets the top element of the stack.
    • \n\t
    • int getMin() retrieves the minimum element in the stack.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["MinStack","push","push","push","getMin","pop","top","getMin"]\n[[],[-2],[0],[-3],[],[],[],[]]\n\nOutput\n[null,null,null,null,-3,null,0,-2]\n\nExplanation\nMinStack minStack = new MinStack();\nminStack.push(-2);\nminStack.push(0);\nminStack.push(-3);\nminStack.getMin(); // return -3\nminStack.pop();\nminStack.top();    // return 0\nminStack.getMin(); // return -2\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • -231 <= val <= 231 - 1
    • \n\t
    • Methods pop, top and getMin operations will always be called on non-empty stacks.
    • \n\t
    • At most 3 * 104 calls will be made to push, pop, top, and getMin.
    • \n
    \n", "content_cn": "

    \u8bbe\u8ba1\u4e00\u4e2a\u652f\u6301 push \uff0cpop \uff0ctop \u64cd\u4f5c\uff0c\u5e76\u80fd\u5728\u5e38\u6570\u65f6\u95f4\u5185\u68c0\u7d22\u5230\u6700\u5c0f\u5143\u7d20\u7684\u6808\u3002

    \n\n
      \n\t
    • push(x) —— \u5c06\u5143\u7d20 x \u63a8\u5165\u6808\u4e2d\u3002
    • \n\t
    • pop() —— \u5220\u9664\u6808\u9876\u7684\u5143\u7d20\u3002
    • \n\t
    • top() —— \u83b7\u53d6\u6808\u9876\u5143\u7d20\u3002
    • \n\t
    • getMin() —— \u68c0\u7d22\u6808\u4e2d\u7684\u6700\u5c0f\u5143\u7d20\u3002
    • \n
    \n\n

     

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165\uff1a\n["MinStack","push","push","push","getMin","pop","top","getMin"]\n[[],[-2],[0],[-3],[],[],[],[]]\n\n\u8f93\u51fa\uff1a\n[null,null,null,null,-3,null,0,-2]\n\n\u89e3\u91ca\uff1a\nMinStack minStack = new MinStack();\nminStack.push(-2);\nminStack.push(0);\nminStack.push(-3);\nminStack.getMin();   --> \u8fd4\u56de -3.\nminStack.pop();\nminStack.top();      --> \u8fd4\u56de 0.\nminStack.getMin();   --> \u8fd4\u56de -2.\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • pop\u3001top \u548c getMin \u64cd\u4f5c\u603b\u662f\u5728 \u975e\u7a7a\u6808 \u4e0a\u8c03\u7528\u3002
    • \n
    \n", "tags_en": ["Stack", "Design"], "tags_cn": ["\u6808", "\u8bbe\u8ba1"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class MinStack {\npublic:\n /** initialize your data structure here. */\n MinStack() {\n\n }\n \n void push(int val) {\n\n }\n \n void pop() {\n\n }\n \n int top() {\n\n }\n \n int getMin() {\n\n }\n};\n\n/**\n * Your MinStack object will be instantiated and called as such:\n * MinStack* obj = new MinStack();\n * obj->push(val);\n * obj->pop();\n * int param_3 = obj->top();\n * int param_4 = obj->getMin();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class MinStack {\n\n /** initialize your data structure here. */\n public MinStack() {\n\n }\n \n public void push(int val) {\n\n }\n \n public void pop() {\n\n }\n \n public int top() {\n\n }\n \n public int getMin() {\n\n }\n}\n\n/**\n * Your MinStack object will be instantiated and called as such:\n * MinStack obj = new MinStack();\n * obj.push(val);\n * obj.pop();\n * int param_3 = obj.top();\n * int param_4 = obj.getMin();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class MinStack(object):\n\n def __init__(self):\n \"\"\"\n initialize your data structure here.\n \"\"\"\n\n\n def push(self, val):\n \"\"\"\n :type val: int\n :rtype: None\n \"\"\"\n\n\n def pop(self):\n \"\"\"\n :rtype: None\n \"\"\"\n\n\n def top(self):\n \"\"\"\n :rtype: int\n \"\"\"\n\n\n def getMin(self):\n \"\"\"\n :rtype: int\n \"\"\"\n\n\n\n# Your MinStack object will be instantiated and called as such:\n# obj = MinStack()\n# obj.push(val)\n# obj.pop()\n# param_3 = obj.top()\n# param_4 = obj.getMin()", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class MinStack:\n\n def __init__(self):\n \"\"\"\n initialize your data structure here.\n \"\"\"\n\n\n def push(self, val: int) -> None:\n\n\n def pop(self) -> None:\n\n\n def top(self) -> int:\n\n\n def getMin(self) -> int:\n\n\n\n# Your MinStack object will be instantiated and called as such:\n# obj = MinStack()\n# obj.push(val)\n# obj.pop()\n# param_3 = obj.top()\n# param_4 = obj.getMin()", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} MinStack;\n\n/** initialize your data structure here. */\n\nMinStack* minStackCreate() {\n\n}\n\nvoid minStackPush(MinStack* obj, int val) {\n\n}\n\nvoid minStackPop(MinStack* obj) {\n\n}\n\nint minStackTop(MinStack* obj) {\n\n}\n\nint minStackGetMin(MinStack* obj) {\n\n}\n\nvoid minStackFree(MinStack* obj) {\n\n}\n\n/**\n * Your MinStack struct will be instantiated and called as such:\n * MinStack* obj = minStackCreate();\n * minStackPush(obj, val);\n \n * minStackPop(obj);\n \n * int param_3 = minStackTop(obj);\n \n * int param_4 = minStackGetMin(obj);\n \n * minStackFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class MinStack {\n\n /** initialize your data structure here. */\n public MinStack() {\n\n }\n \n public void Push(int val) {\n\n }\n \n public void Pop() {\n\n }\n \n public int Top() {\n\n }\n \n public int GetMin() {\n\n }\n}\n\n/**\n * Your MinStack object will be instantiated and called as such:\n * MinStack obj = new MinStack();\n * obj.Push(val);\n * obj.Pop();\n * int param_3 = obj.Top();\n * int param_4 = obj.GetMin();\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * initialize your data structure here.\n */\nvar MinStack = function() {\n\n};\n\n/** \n * @param {number} val\n * @return {void}\n */\nMinStack.prototype.push = function(val) {\n\n};\n\n/**\n * @return {void}\n */\nMinStack.prototype.pop = function() {\n\n};\n\n/**\n * @return {number}\n */\nMinStack.prototype.top = function() {\n\n};\n\n/**\n * @return {number}\n */\nMinStack.prototype.getMin = function() {\n\n};\n\n/**\n * Your MinStack object will be instantiated and called as such:\n * var obj = new MinStack()\n * obj.push(val)\n * obj.pop()\n * var param_3 = obj.top()\n * var param_4 = obj.getMin()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class MinStack\n\n=begin\n initialize your data structure here.\n=end\n def initialize()\n\n end\n\n\n=begin\n :type val: Integer\n :rtype: Void\n=end\n def push(val)\n\n end\n\n\n=begin\n :rtype: Void\n=end\n def pop()\n\n end\n\n\n=begin\n :rtype: Integer\n=end\n def top()\n\n end\n\n\n=begin\n :rtype: Integer\n=end\n def get_min()\n\n end\n\n\nend\n\n# Your MinStack object will be instantiated and called as such:\n# obj = MinStack.new()\n# obj.push(val)\n# obj.pop()\n# param_3 = obj.top()\n# param_4 = obj.get_min()", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass MinStack {\n\n /** initialize your data structure here. */\n init() {\n\n }\n \n func push(_ val: Int) {\n\n }\n \n func pop() {\n\n }\n \n func top() -> Int {\n\n }\n \n func getMin() -> Int {\n\n }\n}\n\n/**\n * Your MinStack object will be instantiated and called as such:\n * let obj = MinStack()\n * obj.push(val)\n * obj.pop()\n * let ret_3: Int = obj.top()\n * let ret_4: Int = obj.getMin()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type MinStack struct {\n\n}\n\n\n/** initialize your data structure here. */\nfunc Constructor() MinStack {\n\n}\n\n\nfunc (this *MinStack) Push(val int) {\n\n}\n\n\nfunc (this *MinStack) Pop() {\n\n}\n\n\nfunc (this *MinStack) Top() int {\n\n}\n\n\nfunc (this *MinStack) GetMin() int {\n\n}\n\n\n/**\n * Your MinStack object will be instantiated and called as such:\n * obj := Constructor();\n * obj.Push(val);\n * obj.Pop();\n * param_3 := obj.Top();\n * param_4 := obj.GetMin();\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class MinStack() {\n\n /** initialize your data structure here. */\n\n\n def push(`val`: Int) {\n\n }\n\n def pop() {\n\n }\n\n def top(): Int = {\n\n }\n\n def getMin(): Int = {\n\n }\n\n}\n\n/**\n * Your MinStack object will be instantiated and called as such:\n * var obj = new MinStack()\n * obj.push(`val`)\n * obj.pop()\n * var param_3 = obj.top()\n * var param_4 = obj.getMin()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class MinStack() {\n\n /** initialize your data structure here. */\n\n\n fun push(`val`: Int) {\n\n }\n\n fun pop() {\n\n }\n\n fun top(): Int {\n\n }\n\n fun getMin(): Int {\n\n }\n\n}\n\n/**\n * Your MinStack object will be instantiated and called as such:\n * var obj = MinStack()\n * obj.push(`val`)\n * obj.pop()\n * var param_3 = obj.top()\n * var param_4 = obj.getMin()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct MinStack {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl MinStack {\n\n /** initialize your data structure here. */\n fn new() -> Self {\n\n }\n \n fn push(&self, val: i32) {\n\n }\n \n fn pop(&self) {\n\n }\n \n fn top(&self) -> i32 {\n\n }\n \n fn get_min(&self) -> i32 {\n\n }\n}\n\n/**\n * Your MinStack object will be instantiated and called as such:\n * let obj = MinStack::new();\n * obj.push(val);\n * obj.pop();\n * let ret_3: i32 = obj.top();\n * let ret_4: i32 = obj.get_min();\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class MinStack {\n /**\n * initialize your data structure here.\n */\n function __construct() {\n\n }\n\n /**\n * @param Integer $val\n * @return NULL\n */\n function push($val) {\n\n }\n\n /**\n * @return NULL\n */\n function pop() {\n\n }\n\n /**\n * @return Integer\n */\n function top() {\n\n }\n\n /**\n * @return Integer\n */\n function getMin() {\n\n }\n}\n\n/**\n * Your MinStack object will be instantiated and called as such:\n * $obj = MinStack();\n * $obj->push($val);\n * $obj->pop();\n * $ret_3 = $obj->top();\n * $ret_4 = $obj->getMin();\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class MinStack {\n constructor() {\n\n }\n\n push(val: number): void {\n\n }\n\n pop(): void {\n\n }\n\n top(): number {\n\n }\n\n getMin(): number {\n\n }\n}\n\n/**\n * Your MinStack object will be instantiated and called as such:\n * var obj = new MinStack()\n * obj.push(val)\n * obj.pop()\n * var param_3 = obj.top()\n * var param_4 = obj.getMin()\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define min-stack%\n (class object%\n (super-new)\n (init-field)\n \n ; push : exact-integer? -> void?\n (define/public (push val)\n\n )\n ; pop : -> void?\n (define/public (pop)\n\n )\n ; top : -> exact-integer?\n (define/public (top)\n\n )\n ; get-min : -> exact-integer?\n (define/public (get-min)\n\n )))\n\n;; Your min-stack% object will be instantiated and called as such:\n;; (define obj (new min-stack%))\n;; (send obj push val)\n;; (send obj pop)\n;; (define param_3 (send obj top))\n;; (define param_4 (send obj get-min))", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0155](https://leetcode-cn.com/problems/min-stack)", "[\u6700\u5c0f\u6808](/solution/0100-0199/0155.Min%20Stack/README.md)", "`\u6808`,`\u8bbe\u8ba1`", "\u7b80\u5355", ""], "md_table_row_en": ["[0155](https://leetcode.com/problems/min-stack)", "[Min Stack](/solution/0100-0199/0155.Min%20Stack/README_EN.md)", "`Stack`,`Design`", "Easy", ""]}, {"question_id": "0154", "frontend_question_id": "0154", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array-ii", "url_en": "https://leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii", "relative_path_cn": "/solution/0100-0199/0154.Find%20Minimum%20in%20Rotated%20Sorted%20Array%20II/README.md", "relative_path_en": "/solution/0100-0199/0154.Find%20Minimum%20in%20Rotated%20Sorted%20Array%20II/README_EN.md", "title_cn": "\u5bfb\u627e\u65cb\u8f6c\u6392\u5e8f\u6570\u7ec4\u4e2d\u7684\u6700\u5c0f\u503c II", "title_en": "Find Minimum in Rotated Sorted Array II", "question_title_slug": "find-minimum-in-rotated-sorted-array-ii", "content_en": "

    Suppose an array of length n sorted in ascending order is rotated between 1 and n times. For example, the array nums = [0,1,4,4,5,6,7] might become:

    \n\n
      \n\t
    • [4,5,6,7,0,1,4] if it was rotated 4 times.
    • \n\t
    • [0,1,4,4,5,6,7] if it was rotated 7 times.
    • \n
    \n\n

    Notice that rotating an array [a[0], a[1], a[2], ..., a[n-1]] 1 time results in the array [a[n-1], a[0], a[1], a[2], ..., a[n-2]].

    \n\n

    Given the sorted rotated array nums that may contain duplicates, return the minimum element of this array.

    \n\n

    You must decrease the overall operation steps as much as possible.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [1,3,5]\nOutput: 1\n

    Example 2:

    \n
    Input: nums = [2,2,2,0,1]\nOutput: 0\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= n <= 5000
    • \n\t
    • -5000 <= nums[i] <= 5000
    • \n\t
    • nums is sorted and rotated between 1 and n times.
    • \n
    \n\n

     

    \n

    Follow up: This problem is similar to Find Minimum in Rotated Sorted Array, but nums may contain duplicates. Would this affect the runtime complexity? How and why?

    \n\n

     

    \n", "content_cn": "\u5df2\u77e5\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u6570\u7ec4\uff0c\u9884\u5148\u6309\u7167\u5347\u5e8f\u6392\u5217\uff0c\u7ecf\u7531 1 \u5230 n \u6b21 \u65cb\u8f6c \u540e\uff0c\u5f97\u5230\u8f93\u5165\u6570\u7ec4\u3002\u4f8b\u5982\uff0c\u539f\u6570\u7ec4 nums = [0,1,4,4,5,6,7] \u5728\u53d8\u5316\u540e\u53ef\u80fd\u5f97\u5230\uff1a\n
      \n\t
    • \u82e5\u65cb\u8f6c 4 \u6b21\uff0c\u5219\u53ef\u4ee5\u5f97\u5230 [4,5,6,7,0,1,4]
    • \n\t
    • \u82e5\u65cb\u8f6c 7 \u6b21\uff0c\u5219\u53ef\u4ee5\u5f97\u5230 [0,1,4,4,5,6,7]
    • \n
    \n\n

    \u6ce8\u610f\uff0c\u6570\u7ec4 [a[0], a[1], a[2], ..., a[n-1]] \u65cb\u8f6c\u4e00\u6b21 \u7684\u7ed3\u679c\u4e3a\u6570\u7ec4 [a[n-1], a[0], a[1], a[2], ..., a[n-2]] \u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u53ef\u80fd\u5b58\u5728 \u91cd\u590d \u5143\u7d20\u503c\u7684\u6570\u7ec4 nums \uff0c\u5b83\u539f\u6765\u662f\u4e00\u4e2a\u5347\u5e8f\u6392\u5217\u7684\u6570\u7ec4\uff0c\u5e76\u6309\u4e0a\u8ff0\u60c5\u5f62\u8fdb\u884c\u4e86\u591a\u6b21\u65cb\u8f6c\u3002\u8bf7\u4f60\u627e\u51fa\u5e76\u8fd4\u56de\u6570\u7ec4\u4e2d\u7684 \u6700\u5c0f\u5143\u7d20 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,3,5]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [2,2,2,0,1]\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= n <= 5000
    • \n\t
    • -5000 <= nums[i] <= 5000
    • \n\t
    • nums \u539f\u6765\u662f\u4e00\u4e2a\u5347\u5e8f\u6392\u5e8f\u7684\u6570\u7ec4\uff0c\u5e76\u8fdb\u884c\u4e86 1 \u81f3 n \u6b21\u65cb\u8f6c
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a

    \n\n\n", "tags_en": ["Array", "Binary Search"], "tags_cn": ["\u6570\u7ec4", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findMin(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findMin(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findMin(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findMin(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findMin(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindMin(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar findMin = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef find_min(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findMin(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findMin(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findMin(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findMin(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_min(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function findMin($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findMin(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-min nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0154](https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array-ii)", "[\u5bfb\u627e\u65cb\u8f6c\u6392\u5e8f\u6570\u7ec4\u4e2d\u7684\u6700\u5c0f\u503c II](/solution/0100-0199/0154.Find%20Minimum%20in%20Rotated%20Sorted%20Array%20II/README.md)", "`\u6570\u7ec4`,`\u4e8c\u5206\u67e5\u627e`", "\u56f0\u96be", ""], "md_table_row_en": ["[0154](https://leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii)", "[Find Minimum in Rotated Sorted Array II](/solution/0100-0199/0154.Find%20Minimum%20in%20Rotated%20Sorted%20Array%20II/README_EN.md)", "`Array`,`Binary Search`", "Hard", ""]}, {"question_id": "0153", "frontend_question_id": "0153", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array", "url_en": "https://leetcode.com/problems/find-minimum-in-rotated-sorted-array", "relative_path_cn": "/solution/0100-0199/0153.Find%20Minimum%20in%20Rotated%20Sorted%20Array/README.md", "relative_path_en": "/solution/0100-0199/0153.Find%20Minimum%20in%20Rotated%20Sorted%20Array/README_EN.md", "title_cn": "\u5bfb\u627e\u65cb\u8f6c\u6392\u5e8f\u6570\u7ec4\u4e2d\u7684\u6700\u5c0f\u503c", "title_en": "Find Minimum in Rotated Sorted Array", "question_title_slug": "find-minimum-in-rotated-sorted-array", "content_en": "

    Suppose an array of length n sorted in ascending order is rotated between 1 and n times. For example, the array nums = [0,1,2,4,5,6,7] might become:

    \n\n
      \n\t
    • [4,5,6,7,0,1,2] if it was rotated 4 times.
    • \n\t
    • [0,1,2,4,5,6,7] if it was rotated 7 times.
    • \n
    \n\n

    Notice that rotating an array [a[0], a[1], a[2], ..., a[n-1]] 1 time results in the array [a[n-1], a[0], a[1], a[2], ..., a[n-2]].

    \n\n

    Given the sorted rotated array nums of unique elements, return the minimum element of this array.

    \n\n

    You must write an algorithm that runs in O(log n) time.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [3,4,5,1,2]\nOutput: 1\nExplanation: The original array was [1,2,3,4,5] rotated 3 times.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [4,5,6,7,0,1,2]\nOutput: 0\nExplanation: The original array was [0,1,2,4,5,6,7] and it was rotated 4 times.\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [11,13,15,17]\nOutput: 11\nExplanation: The original array was [11,13,15,17] and it was rotated 4 times. \n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= n <= 5000
    • \n\t
    • -5000 <= nums[i] <= 5000
    • \n\t
    • All the integers of nums are unique.
    • \n\t
    • nums is sorted and rotated between 1 and n times.
    • \n
    \n", "content_cn": "\u5df2\u77e5\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u6570\u7ec4\uff0c\u9884\u5148\u6309\u7167\u5347\u5e8f\u6392\u5217\uff0c\u7ecf\u7531 1 \u5230 n \u6b21 \u65cb\u8f6c \u540e\uff0c\u5f97\u5230\u8f93\u5165\u6570\u7ec4\u3002\u4f8b\u5982\uff0c\u539f\u6570\u7ec4 nums = [0,1,2,4,5,6,7] \u5728\u53d8\u5316\u540e\u53ef\u80fd\u5f97\u5230\uff1a\n
      \n\t
    • \u82e5\u65cb\u8f6c 4 \u6b21\uff0c\u5219\u53ef\u4ee5\u5f97\u5230 [4,5,6,7,0,1,2]
    • \n\t
    • \u82e5\u65cb\u8f6c 7 \u6b21\uff0c\u5219\u53ef\u4ee5\u5f97\u5230 [0,1,2,4,5,6,7]
    • \n
    \n\n

    \u6ce8\u610f\uff0c\u6570\u7ec4 [a[0], a[1], a[2], ..., a[n-1]] \u65cb\u8f6c\u4e00\u6b21 \u7684\u7ed3\u679c\u4e3a\u6570\u7ec4 [a[n-1], a[0], a[1], a[2], ..., a[n-2]] \u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u5143\u7d20\u503c \u4e92\u4e0d\u76f8\u540c \u7684\u6570\u7ec4 nums \uff0c\u5b83\u539f\u6765\u662f\u4e00\u4e2a\u5347\u5e8f\u6392\u5217\u7684\u6570\u7ec4\uff0c\u5e76\u6309\u4e0a\u8ff0\u60c5\u5f62\u8fdb\u884c\u4e86\u591a\u6b21\u65cb\u8f6c\u3002\u8bf7\u4f60\u627e\u51fa\u5e76\u8fd4\u56de\u6570\u7ec4\u4e2d\u7684 \u6700\u5c0f\u5143\u7d20 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [3,4,5,1,2]\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u539f\u6570\u7ec4\u4e3a [1,2,3,4,5] \uff0c\u65cb\u8f6c 3 \u6b21\u5f97\u5230\u8f93\u5165\u6570\u7ec4\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [4,5,6,7,0,1,2]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u539f\u6570\u7ec4\u4e3a [0,1,2,4,5,6,7] \uff0c\u65cb\u8f6c 4 \u6b21\u5f97\u5230\u8f93\u5165\u6570\u7ec4\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [11,13,15,17]\n\u8f93\u51fa\uff1a11\n\u89e3\u91ca\uff1a\u539f\u6570\u7ec4\u4e3a [11,13,15,17] \uff0c\u65cb\u8f6c 4 \u6b21\u5f97\u5230\u8f93\u5165\u6570\u7ec4\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= n <= 5000
    • \n\t
    • -5000 <= nums[i] <= 5000
    • \n\t
    • nums \u4e2d\u7684\u6240\u6709\u6574\u6570 \u4e92\u4e0d\u76f8\u540c
    • \n\t
    • nums \u539f\u6765\u662f\u4e00\u4e2a\u5347\u5e8f\u6392\u5e8f\u7684\u6570\u7ec4\uff0c\u5e76\u8fdb\u884c\u4e86 1 \u81f3 n \u6b21\u65cb\u8f6c
    • \n
    \n", "tags_en": ["Array", "Binary Search"], "tags_cn": ["\u6570\u7ec4", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int findMin(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int findMin(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findMin(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findMin(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint findMin(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FindMin(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar findMin = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef find_min(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findMin(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findMin(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findMin(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findMin(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_min(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function findMin($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findMin(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-min nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0153](https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array)", "[\u5bfb\u627e\u65cb\u8f6c\u6392\u5e8f\u6570\u7ec4\u4e2d\u7684\u6700\u5c0f\u503c](/solution/0100-0199/0153.Find%20Minimum%20in%20Rotated%20Sorted%20Array/README.md)", "`\u6570\u7ec4`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0153](https://leetcode.com/problems/find-minimum-in-rotated-sorted-array)", "[Find Minimum in Rotated Sorted Array](/solution/0100-0199/0153.Find%20Minimum%20in%20Rotated%20Sorted%20Array/README_EN.md)", "`Array`,`Binary Search`", "Medium", ""]}, {"question_id": "0152", "frontend_question_id": "0152", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-product-subarray", "url_en": "https://leetcode.com/problems/maximum-product-subarray", "relative_path_cn": "/solution/0100-0199/0152.Maximum%20Product%20Subarray/README.md", "relative_path_en": "/solution/0100-0199/0152.Maximum%20Product%20Subarray/README_EN.md", "title_cn": "\u4e58\u79ef\u6700\u5927\u5b50\u6570\u7ec4", "title_en": "Maximum Product Subarray", "question_title_slug": "maximum-product-subarray", "content_en": "

    Given an integer array nums, find a contiguous non-empty subarray within the array that has the largest product, and return the product.

    \n\n

    It is guaranteed that the answer will fit in a 32-bit integer.

    \n\n

    A subarray is a contiguous subsequence of the array.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [2,3,-2,4]\nOutput: 6\nExplanation: [2,3] has the largest product 6.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [-2,0,-1]\nOutput: 0\nExplanation: The result cannot be 2, because [-2,-1] is not a subarray.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 2 * 104
    • \n\t
    • -10 <= nums[i] <= 10
    • \n\t
    • The product of any prefix or suffix of nums is guaranteed to fit in a 32-bit integer.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \uff0c\u8bf7\u4f60\u627e\u51fa\u6570\u7ec4\u4e2d\u4e58\u79ef\u6700\u5927\u7684\u8fde\u7eed\u5b50\u6570\u7ec4\uff08\u8be5\u5b50\u6570\u7ec4\u4e2d\u81f3\u5c11\u5305\u542b\u4e00\u4e2a\u6570\u5b57\uff09\uff0c\u5e76\u8fd4\u56de\u8be5\u5b50\u6570\u7ec4\u6240\u5bf9\u5e94\u7684\u4e58\u79ef\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: [2,3,-2,4]\n\u8f93\u51fa: 6\n\u89e3\u91ca: \u5b50\u6570\u7ec4 [2,3] \u6709\u6700\u5927\u4e58\u79ef 6\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: [-2,0,-1]\n\u8f93\u51fa: 0\n\u89e3\u91ca: \u7ed3\u679c\u4e0d\u80fd\u4e3a 2, \u56e0\u4e3a [-2,-1] \u4e0d\u662f\u5b50\u6570\u7ec4\u3002
    \n", "tags_en": ["Array", "Dynamic Programming"], "tags_cn": ["\u6570\u7ec4", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxProduct(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxProduct(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxProduct(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxProduct(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxProduct(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxProduct(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar maxProduct = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef max_product(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxProduct(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxProduct(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxProduct(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxProduct(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_product(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function maxProduct($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxProduct(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-product nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0152](https://leetcode-cn.com/problems/maximum-product-subarray)", "[\u4e58\u79ef\u6700\u5927\u5b50\u6570\u7ec4](/solution/0100-0199/0152.Maximum%20Product%20Subarray/README.md)", "`\u6570\u7ec4`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0152](https://leetcode.com/problems/maximum-product-subarray)", "[Maximum Product Subarray](/solution/0100-0199/0152.Maximum%20Product%20Subarray/README_EN.md)", "`Array`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0151", "frontend_question_id": "0151", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reverse-words-in-a-string", "url_en": "https://leetcode.com/problems/reverse-words-in-a-string", "relative_path_cn": "/solution/0100-0199/0151.Reverse%20Words%20in%20a%20String/README.md", "relative_path_en": "/solution/0100-0199/0151.Reverse%20Words%20in%20a%20String/README_EN.md", "title_cn": "\u7ffb\u8f6c\u5b57\u7b26\u4e32\u91cc\u7684\u5355\u8bcd", "title_en": "Reverse Words in a String", "question_title_slug": "reverse-words-in-a-string", "content_en": "

    Given an input string s, reverse the order of the words.

    \n\n

    A word is defined as a sequence of non-space characters. The words in s will be separated by at least one space.

    \n\n

    Return a string of the words in reverse order concatenated by a single space.

    \n\n

    Note that s may contain leading or trailing spaces or multiple spaces between two words. The returned string should only have a single space separating the words. Do not include any extra spaces.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "the sky is blue"\nOutput: "blue is sky the"\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "  hello world  "\nOutput: "world hello"\nExplanation: Your reversed string should not contain leading or trailing spaces.\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "a good   example"\nOutput: "example good a"\nExplanation: You need to reduce multiple spaces between two words to a single space in the reversed string.\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "  Bob    Loves  Alice   "\nOutput: "Alice Loves Bob"\n
    \n\n

    Example 5:

    \n\n
    \nInput: s = "Alice does not even like bob"\nOutput: "bob like even not does Alice"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 104
    • \n\t
    • s contains English letters (upper-case and lower-case), digits, and spaces ' '.
    • \n\t
    • There is at least one word in s.
    • \n
    \n\n

     

    \n

    Follow up: Could you solve it in-place with O(1) extra space?

    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \uff0c\u9010\u4e2a\u7ffb\u8f6c\u5b57\u7b26\u4e32\u4e2d\u7684\u6240\u6709 \u5355\u8bcd \u3002

    \n\n

    \u5355\u8bcd \u662f\u7531\u975e\u7a7a\u683c\u5b57\u7b26\u7ec4\u6210\u7684\u5b57\u7b26\u4e32\u3002s \u4e2d\u4f7f\u7528\u81f3\u5c11\u4e00\u4e2a\u7a7a\u683c\u5c06\u5b57\u7b26\u4e32\u4e2d\u7684 \u5355\u8bcd \u5206\u9694\u5f00\u3002

    \n\n

    \u8bf7\u4f60\u8fd4\u56de\u4e00\u4e2a\u7ffb\u8f6c s \u4e2d\u5355\u8bcd\u987a\u5e8f\u5e76\u7528\u5355\u4e2a\u7a7a\u683c\u76f8\u8fde\u7684\u5b57\u7b26\u4e32\u3002

    \n\n

    \u8bf4\u660e\uff1a

    \n\n
      \n\t
    • \u8f93\u5165\u5b57\u7b26\u4e32 s \u53ef\u4ee5\u5728\u524d\u9762\u3001\u540e\u9762\u6216\u8005\u5355\u8bcd\u95f4\u5305\u542b\u591a\u4f59\u7684\u7a7a\u683c\u3002
    • \n\t
    • \u7ffb\u8f6c\u540e\u5355\u8bcd\u95f4\u5e94\u5f53\u4ec5\u7528\u4e00\u4e2a\u7a7a\u683c\u5206\u9694\u3002
    • \n\t
    • \u7ffb\u8f6c\u540e\u7684\u5b57\u7b26\u4e32\u4e2d\u4e0d\u5e94\u5305\u542b\u989d\u5916\u7684\u7a7a\u683c\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"the sky is blue\"\n\u8f93\u51fa\uff1a\"blue is sky the\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \" \u00a0hello world \u00a0\"\n\u8f93\u51fa\uff1a\"world hello\"\n\u89e3\u91ca\uff1a\u8f93\u5165\u5b57\u7b26\u4e32\u53ef\u4ee5\u5728\u524d\u9762\u6216\u8005\u540e\u9762\u5305\u542b\u591a\u4f59\u7684\u7a7a\u683c\uff0c\u4f46\u662f\u7ffb\u8f6c\u540e\u7684\u5b57\u7b26\u4e0d\u80fd\u5305\u62ec\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"a good \u00a0 example\"\n\u8f93\u51fa\uff1a\"example good a\"\n\u89e3\u91ca\uff1a\u5982\u679c\u4e24\u4e2a\u5355\u8bcd\u95f4\u6709\u591a\u4f59\u7684\u7a7a\u683c\uff0c\u5c06\u7ffb\u8f6c\u540e\u5355\u8bcd\u95f4\u7684\u7a7a\u683c\u51cf\u5c11\u5230\u53ea\u542b\u4e00\u4e2a\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"  Bob    Loves  Alice   \"\n\u8f93\u51fa\uff1a\"Alice Loves Bob\"\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"Alice does not even like bob\"\n\u8f93\u51fa\uff1a\"bob like even not does Alice\"\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 104
    • \n\t
    • s \u5305\u542b\u82f1\u6587\u5927\u5c0f\u5199\u5b57\u6bcd\u3001\u6570\u5b57\u548c\u7a7a\u683c ' '
    • \n\t
    • s \u4e2d \u81f3\u5c11\u5b58\u5728\u4e00\u4e2a \u5355\u8bcd
    • \n
    \n\n
      \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u8bf7\u5c1d\u8bd5\u4f7f\u7528\u00a0O(1) \u989d\u5916\u7a7a\u95f4\u590d\u6742\u5ea6\u7684\u539f\u5730\u89e3\u6cd5\u3002
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string reverseWords(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String reverseWords(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def reverseWords(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def reverseWords(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * reverseWords(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string ReverseWords(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar reverseWords = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef reverse_words(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func reverseWords(_ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func reverseWords(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def reverseWords(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun reverseWords(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn reverse_words(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function reverseWords($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function reverseWords(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (reverse-words s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0151](https://leetcode-cn.com/problems/reverse-words-in-a-string)", "[\u7ffb\u8f6c\u5b57\u7b26\u4e32\u91cc\u7684\u5355\u8bcd](/solution/0100-0199/0151.Reverse%20Words%20in%20a%20String/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0151](https://leetcode.com/problems/reverse-words-in-a-string)", "[Reverse Words in a String](/solution/0100-0199/0151.Reverse%20Words%20in%20a%20String/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "0150", "frontend_question_id": "0150", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/evaluate-reverse-polish-notation", "url_en": "https://leetcode.com/problems/evaluate-reverse-polish-notation", "relative_path_cn": "/solution/0100-0199/0150.Evaluate%20Reverse%20Polish%20Notation/README.md", "relative_path_en": "/solution/0100-0199/0150.Evaluate%20Reverse%20Polish%20Notation/README_EN.md", "title_cn": "\u9006\u6ce2\u5170\u8868\u8fbe\u5f0f\u6c42\u503c", "title_en": "Evaluate Reverse Polish Notation", "question_title_slug": "evaluate-reverse-polish-notation", "content_en": "

    Evaluate the value of an arithmetic expression in Reverse Polish Notation.

    \n\n

    Valid operators are +, -, *, and /. Each operand may be an integer or another expression.

    \n\n

    Note that division between two integers should truncate toward zero.

    \n\n

    It is guaranteed that the given RPN expression is always valid. That means the expression would always evaluate to a result, and there will not be any division by zero operation.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: tokens = ["2","1","+","3","*"]\nOutput: 9\nExplanation: ((2 + 1) * 3) = 9\n
    \n\n

    Example 2:

    \n\n
    \nInput: tokens = ["4","13","5","/","+"]\nOutput: 6\nExplanation: (4 + (13 / 5)) = 6\n
    \n\n

    Example 3:

    \n\n
    \nInput: tokens = ["10","6","9","3","+","-11","*","/","*","17","+","5","+"]\nOutput: 22\nExplanation: ((10 * (6 / ((9 + 3) * -11))) + 17) + 5\n= ((10 * (6 / (12 * -11))) + 17) + 5\n= ((10 * (6 / -132)) + 17) + 5\n= ((10 * 0) + 17) + 5\n= (0 + 17) + 5\n= 17 + 5\n= 22\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= tokens.length <= 104
    • \n\t
    • tokens[i] is either an operator: "+", "-", "*", or "/", or an integer in the range [-200, 200].
    • \n
    \n", "content_cn": "

    \u6839\u636e \u9006\u6ce2\u5170\u8868\u793a\u6cd5\uff0c\u6c42\u8868\u8fbe\u5f0f\u7684\u503c\u3002

    \n\n

    \u6709\u6548\u7684\u7b97\u7b26\u5305\u62ec\u00a0+\u3001-\u3001*\u3001/\u00a0\u3002\u6bcf\u4e2a\u8fd0\u7b97\u5bf9\u8c61\u53ef\u4ee5\u662f\u6574\u6570\uff0c\u4e5f\u53ef\u4ee5\u662f\u53e6\u4e00\u4e2a\u9006\u6ce2\u5170\u8868\u8fbe\u5f0f\u3002

    \n\n

    \u00a0

    \n\n

    \u8bf4\u660e\uff1a

    \n\n
      \n\t
    • \u6574\u6570\u9664\u6cd5\u53ea\u4fdd\u7559\u6574\u6570\u90e8\u5206\u3002
    • \n\t
    • \u7ed9\u5b9a\u9006\u6ce2\u5170\u8868\u8fbe\u5f0f\u603b\u662f\u6709\u6548\u7684\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u8868\u8fbe\u5f0f\u603b\u4f1a\u5f97\u51fa\u6709\u6548\u6570\u503c\u4e14\u4e0d\u5b58\u5728\u9664\u6570\u4e3a 0 \u7684\u60c5\u51b5\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\u00a01\uff1a

    \n\n
    \n\u8f93\u5165\uff1atokens = [\"2\",\"1\",\"+\",\"3\",\"*\"]\n\u8f93\u51fa\uff1a9\n\u89e3\u91ca\uff1a\u8be5\u7b97\u5f0f\u8f6c\u5316\u4e3a\u5e38\u89c1\u7684\u4e2d\u7f00\u7b97\u672f\u8868\u8fbe\u5f0f\u4e3a\uff1a((2 + 1) * 3) = 9\n
    \n\n

    \u793a\u4f8b\u00a02\uff1a

    \n\n
    \n\u8f93\u5165\uff1atokens = [\"4\",\"13\",\"5\",\"/\",\"+\"]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u8be5\u7b97\u5f0f\u8f6c\u5316\u4e3a\u5e38\u89c1\u7684\u4e2d\u7f00\u7b97\u672f\u8868\u8fbe\u5f0f\u4e3a\uff1a(4 + (13 / 5)) = 6\n
    \n\n

    \u793a\u4f8b\u00a03\uff1a

    \n\n
    \n\u8f93\u5165\uff1atokens = [\"10\",\"6\",\"9\",\"3\",\"+\",\"-11\",\"*\",\"/\",\"*\",\"17\",\"+\",\"5\",\"+\"]\n\u8f93\u51fa\uff1a22\n\u89e3\u91ca\uff1a\n\u8be5\u7b97\u5f0f\u8f6c\u5316\u4e3a\u5e38\u89c1\u7684\u4e2d\u7f00\u7b97\u672f\u8868\u8fbe\u5f0f\u4e3a\uff1a\n  ((10 * (6 / ((9 + 3) * -11))) + 17) + 5\n= ((10 * (6 / (12 * -11))) + 17) + 5\n= ((10 * (6 / -132)) + 17) + 5\n= ((10 * 0) + 17) + 5\n= (0 + 17) + 5\n= 17 + 5\n= 22
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= tokens.length <= 104
    • \n\t
    • tokens[i] \u8981\u4e48\u662f\u4e00\u4e2a\u7b97\u7b26\uff08\"+\"\u3001\"-\"\u3001\"*\" \u6216 \"/\"\uff09\uff0c\u8981\u4e48\u662f\u4e00\u4e2a\u5728\u8303\u56f4 [-200, 200] \u5185\u7684\u6574\u6570
    • \n
    \n\n

    \u00a0

    \n\n

    \u9006\u6ce2\u5170\u8868\u8fbe\u5f0f\uff1a

    \n\n

    \u9006\u6ce2\u5170\u8868\u8fbe\u5f0f\u662f\u4e00\u79cd\u540e\u7f00\u8868\u8fbe\u5f0f\uff0c\u6240\u8c13\u540e\u7f00\u5c31\u662f\u6307\u7b97\u7b26\u5199\u5728\u540e\u9762\u3002

    \n\n
      \n\t
    • \u5e73\u5e38\u4f7f\u7528\u7684\u7b97\u5f0f\u5219\u662f\u4e00\u79cd\u4e2d\u7f00\u8868\u8fbe\u5f0f\uff0c\u5982 ( 1 + 2 ) * ( 3 + 4 ) \u3002
    • \n\t
    • \u8be5\u7b97\u5f0f\u7684\u9006\u6ce2\u5170\u8868\u8fbe\u5f0f\u5199\u6cd5\u4e3a ( ( 1 2 + ) ( 3 4 + ) * ) \u3002
    • \n
    \n\n

    \u9006\u6ce2\u5170\u8868\u8fbe\u5f0f\u4e3b\u8981\u6709\u4ee5\u4e0b\u4e24\u4e2a\u4f18\u70b9\uff1a

    \n\n
      \n\t
    • \u53bb\u6389\u62ec\u53f7\u540e\u8868\u8fbe\u5f0f\u65e0\u6b67\u4e49\uff0c\u4e0a\u5f0f\u5373\u4fbf\u5199\u6210 1 2 + 3 4 + * \u4e5f\u53ef\u4ee5\u4f9d\u636e\u6b21\u5e8f\u8ba1\u7b97\u51fa\u6b63\u786e\u7ed3\u679c\u3002
    • \n\t
    • \u9002\u5408\u7528\u6808\u64cd\u4f5c\u8fd0\u7b97\uff1a\u9047\u5230\u6570\u5b57\u5219\u5165\u6808\uff1b\u9047\u5230\u7b97\u7b26\u5219\u53d6\u51fa\u6808\u9876\u4e24\u4e2a\u6570\u5b57\u8fdb\u884c\u8ba1\u7b97\uff0c\u5e76\u5c06\u7ed3\u679c\u538b\u5165\u6808\u4e2d\u3002
    • \n
    \n", "tags_en": ["Stack"], "tags_cn": ["\u6808"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int evalRPN(vector& tokens) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int evalRPN(String[] tokens) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def evalRPN(self, tokens):\n \"\"\"\n :type tokens: List[str]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def evalRPN(self, tokens: List[str]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint evalRPN(char ** tokens, int tokensSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int EvalRPN(string[] tokens) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} tokens\n * @return {number}\n */\nvar evalRPN = function(tokens) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} tokens\n# @return {Integer}\ndef eval_rpn(tokens)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func evalRPN(_ tokens: [String]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func evalRPN(tokens []string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def evalRPN(tokens: Array[String]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun evalRPN(tokens: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn eval_rpn(tokens: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $tokens\n * @return Integer\n */\n function evalRPN($tokens) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function evalRPN(tokens: string[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (eval-rpn tokens)\n (-> (listof string?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0150](https://leetcode-cn.com/problems/evaluate-reverse-polish-notation)", "[\u9006\u6ce2\u5170\u8868\u8fbe\u5f0f\u6c42\u503c](/solution/0100-0199/0150.Evaluate%20Reverse%20Polish%20Notation/README.md)", "`\u6808`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0150](https://leetcode.com/problems/evaluate-reverse-polish-notation)", "[Evaluate Reverse Polish Notation](/solution/0100-0199/0150.Evaluate%20Reverse%20Polish%20Notation/README_EN.md)", "`Stack`", "Medium", ""]}, {"question_id": "0149", "frontend_question_id": "0149", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/max-points-on-a-line", "url_en": "https://leetcode.com/problems/max-points-on-a-line", "relative_path_cn": "/solution/0100-0199/0149.Max%20Points%20on%20a%20Line/README.md", "relative_path_en": "/solution/0100-0199/0149.Max%20Points%20on%20a%20Line/README_EN.md", "title_cn": "\u76f4\u7ebf\u4e0a\u6700\u591a\u7684\u70b9\u6570", "title_en": "Max Points on a Line", "question_title_slug": "max-points-on-a-line", "content_en": "

    Given an array of points where points[i] = [xi, yi] represents a point on the X-Y plane, return the maximum number of points that lie on the same straight line.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: points = [[1,1],[2,2],[3,3]]\nOutput: 3\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: points = [[1,1],[3,2],[5,3],[4,1],[2,3],[1,4]]\nOutput: 4\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= points.length <= 300
    • \n\t
    • points[i].length == 2
    • \n\t
    • -104 <= xi, yi <= 104
    • \n\t
    • All the points are unique.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u7ef4\u5e73\u9762\uff0c\u5e73\u9762\u4e0a\u6709 \u4e2a\u70b9\uff0c\u6c42\u6700\u591a\u6709\u591a\u5c11\u4e2a\u70b9\u5728\u540c\u4e00\u6761\u76f4\u7ebf\u4e0a\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: [[1,1],[2,2],[3,3]]\n\u8f93\u51fa: 3\n\u89e3\u91ca:\n^\n|\n|        o\n|     o\n|  o  \n+------------->\n0  1  2  3  4\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: [[1,1],[3,2],[5,3],[4,1],[2,3],[1,4]]\n\u8f93\u51fa: 4\n\u89e3\u91ca:\n^\n|\n|  o\n|     o        o\n|        o\n|  o        o\n+------------------->\n0  1  2  3  4  5  6
    \n", "tags_en": ["Hash Table", "Math"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u6570\u5b66"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxPoints(vector>& points) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxPoints(int[][] points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxPoints(self, points):\n \"\"\"\n :type points: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxPoints(self, points: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxPoints(int** points, int pointsSize, int* pointsColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxPoints(int[][] points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} points\n * @return {number}\n */\nvar maxPoints = function(points) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} points\n# @return {Integer}\ndef max_points(points)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxPoints(_ points: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxPoints(points [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxPoints(points: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxPoints(points: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_points(points: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $points\n * @return Integer\n */\n function maxPoints($points) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxPoints(points: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-points points)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0149](https://leetcode-cn.com/problems/max-points-on-a-line)", "[\u76f4\u7ebf\u4e0a\u6700\u591a\u7684\u70b9\u6570](/solution/0100-0199/0149.Max%20Points%20on%20a%20Line/README.md)", "`\u54c8\u5e0c\u8868`,`\u6570\u5b66`", "\u56f0\u96be", ""], "md_table_row_en": ["[0149](https://leetcode.com/problems/max-points-on-a-line)", "[Max Points on a Line](/solution/0100-0199/0149.Max%20Points%20on%20a%20Line/README_EN.md)", "`Hash Table`,`Math`", "Hard", ""]}, {"question_id": "0148", "frontend_question_id": "0148", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sort-list", "url_en": "https://leetcode.com/problems/sort-list", "relative_path_cn": "/solution/0100-0199/0148.Sort%20List/README.md", "relative_path_en": "/solution/0100-0199/0148.Sort%20List/README_EN.md", "title_cn": "\u6392\u5e8f\u94fe\u8868", "title_en": "Sort List", "question_title_slug": "sort-list", "content_en": "

    Given the head of a linked list, return the list after sorting it in ascending order.

    \n\n

    Follow up: Can you sort the linked list in O(n logn) time and O(1) memory (i.e. constant space)?

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: head = [4,2,1,3]\nOutput: [1,2,3,4]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: head = [-1,5,3,4,0]\nOutput: [-1,0,3,4,5]\n
    \n\n

    Example 3:

    \n\n
    \nInput: head = []\nOutput: []\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the list is in the range [0, 5 * 104].
    • \n\t
    • -105 <= Node.val <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u94fe\u8868\u7684\u5934\u7ed3\u70b9\u00a0head\u00a0\uff0c\u8bf7\u5c06\u5176\u6309 \u5347\u5e8f \u6392\u5217\u5e76\u8fd4\u56de \u6392\u5e8f\u540e\u7684\u94fe\u8868 \u3002

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u4f60\u53ef\u4ee5\u5728\u00a0O(n\u00a0log\u00a0n) \u65f6\u95f4\u590d\u6742\u5ea6\u548c\u5e38\u6570\u7ea7\u7a7a\u95f4\u590d\u6742\u5ea6\u4e0b\uff0c\u5bf9\u94fe\u8868\u8fdb\u884c\u6392\u5e8f\u5417\uff1f
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1ahead = [4,2,1,3]\n\u8f93\u51fa\uff1a[1,2,3,4]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1ahead = [-1,5,3,4,0]\n\u8f93\u51fa\uff1a[-1,0,3,4,5]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahead = []\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u94fe\u8868\u4e2d\u8282\u70b9\u7684\u6570\u76ee\u5728\u8303\u56f4\u00a0[0, 5 * 104]\u00a0\u5185
    • \n\t
    • -105\u00a0<= Node.val <= 105
    • \n
    \n", "tags_en": ["Sort", "Linked List"], "tags_cn": ["\u6392\u5e8f", "\u94fe\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n ListNode* sortList(ListNode* head) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public ListNode sortList(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def sortList(self, head):\n \"\"\"\n :type head: ListNode\n :rtype: ListNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def sortList(self, head: ListNode) -> ListNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nstruct ListNode* sortList(struct ListNode* head){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public ListNode SortList(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} head\n * @return {ListNode}\n */\nvar sortList = function(head) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode} head\n# @return {ListNode}\ndef sort_list(head)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func sortList(_ head: ListNode?) -> ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc sortList(head *ListNode) *ListNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def sortList(head: ListNode): ListNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun sortList(head: ListNode?): ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn sort_list(head: Option>) -> Option> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @return ListNode\n */\n function sortList($head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction sortList(head: ListNode | null): ListNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (sort-list head)\n (-> (or/c list-node? #f) (or/c list-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0148](https://leetcode-cn.com/problems/sort-list)", "[\u6392\u5e8f\u94fe\u8868](/solution/0100-0199/0148.Sort%20List/README.md)", "`\u6392\u5e8f`,`\u94fe\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0148](https://leetcode.com/problems/sort-list)", "[Sort List](/solution/0100-0199/0148.Sort%20List/README_EN.md)", "`Sort`,`Linked List`", "Medium", ""]}, {"question_id": "0147", "frontend_question_id": "0147", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/insertion-sort-list", "url_en": "https://leetcode.com/problems/insertion-sort-list", "relative_path_cn": "/solution/0100-0199/0147.Insertion%20Sort%20List/README.md", "relative_path_en": "/solution/0100-0199/0147.Insertion%20Sort%20List/README_EN.md", "title_cn": "\u5bf9\u94fe\u8868\u8fdb\u884c\u63d2\u5165\u6392\u5e8f", "title_en": "Insertion Sort List", "question_title_slug": "insertion-sort-list", "content_en": "

    Given the head of a singly linked list, sort the list using insertion sort, and return the sorted list's head.

    \n\n

    The steps of the insertion sort algorithm:

    \n\n
      \n\t
    1. Insertion sort iterates, consuming one input element each repetition and growing a sorted output list.
    2. \n\t
    3. At each iteration, insertion sort removes one element from the input data, finds the location it belongs within the sorted list and inserts it there.
    4. \n\t
    5. It repeats until no input elements remain.
    6. \n
    \n\n

    The following is a graphical example of the insertion sort algorithm. The partially sorted list (black) initially contains only the first element in the list. One element (red) is removed from the input data and inserted in-place into the sorted list with each iteration.

    \n\"\"\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: head = [4,2,1,3]\nOutput: [1,2,3,4]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: head = [-1,5,3,4,0]\nOutput: [-1,0,3,4,5]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the list is in the range [1, 5000].
    • \n\t
    • -5000 <= Node.val <= 5000
    • \n
    \n", "content_cn": "

    \u5bf9\u94fe\u8868\u8fdb\u884c\u63d2\u5165\u6392\u5e8f\u3002

    \n\n

    \"\"
    \n\u63d2\u5165\u6392\u5e8f\u7684\u52a8\u753b\u6f14\u793a\u5982\u4e0a\u3002\u4ece\u7b2c\u4e00\u4e2a\u5143\u7d20\u5f00\u59cb\uff0c\u8be5\u94fe\u8868\u53ef\u4ee5\u88ab\u8ba4\u4e3a\u5df2\u7ecf\u90e8\u5206\u6392\u5e8f\uff08\u7528\u9ed1\u8272\u8868\u793a\uff09\u3002
    \n\u6bcf\u6b21\u8fed\u4ee3\u65f6\uff0c\u4ece\u8f93\u5165\u6570\u636e\u4e2d\u79fb\u9664\u4e00\u4e2a\u5143\u7d20\uff08\u7528\u7ea2\u8272\u8868\u793a\uff09\uff0c\u5e76\u539f\u5730\u5c06\u5176\u63d2\u5165\u5230\u5df2\u6392\u597d\u5e8f\u7684\u94fe\u8868\u4e2d\u3002

    \n\n

     

    \n\n

    \u63d2\u5165\u6392\u5e8f\u7b97\u6cd5\uff1a

    \n\n
      \n\t
    1. \u63d2\u5165\u6392\u5e8f\u662f\u8fed\u4ee3\u7684\uff0c\u6bcf\u6b21\u53ea\u79fb\u52a8\u4e00\u4e2a\u5143\u7d20\uff0c\u76f4\u5230\u6240\u6709\u5143\u7d20\u53ef\u4ee5\u5f62\u6210\u4e00\u4e2a\u6709\u5e8f\u7684\u8f93\u51fa\u5217\u8868\u3002
    2. \n\t
    3. \u6bcf\u6b21\u8fed\u4ee3\u4e2d\uff0c\u63d2\u5165\u6392\u5e8f\u53ea\u4ece\u8f93\u5165\u6570\u636e\u4e2d\u79fb\u9664\u4e00\u4e2a\u5f85\u6392\u5e8f\u7684\u5143\u7d20\uff0c\u627e\u5230\u5b83\u5728\u5e8f\u5217\u4e2d\u9002\u5f53\u7684\u4f4d\u7f6e\uff0c\u5e76\u5c06\u5176\u63d2\u5165\u3002
    4. \n\t
    5. \u91cd\u590d\u76f4\u5230\u6240\u6709\u8f93\u5165\u6570\u636e\u63d2\u5165\u5b8c\u4e3a\u6b62\u3002
    6. \n
    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165: 4->2->1->3\n\u8f93\u51fa: 1->2->3->4\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165: -1->5->3->4->0\n\u8f93\u51fa: -1->0->3->4->5\n
    \n", "tags_en": ["Sort", "Linked List"], "tags_cn": ["\u6392\u5e8f", "\u94fe\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n ListNode* insertionSortList(ListNode* head) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public ListNode insertionSortList(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def insertionSortList(self, head):\n \"\"\"\n :type head: ListNode\n :rtype: ListNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def insertionSortList(self, head: ListNode) -> ListNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nstruct ListNode* insertionSortList(struct ListNode* head){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public ListNode InsertionSortList(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} head\n * @return {ListNode}\n */\nvar insertionSortList = function(head) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode} head\n# @return {ListNode}\ndef insertion_sort_list(head)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func insertionSortList(_ head: ListNode?) -> ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc insertionSortList(head *ListNode) *ListNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def insertionSortList(head: ListNode): ListNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun insertionSortList(head: ListNode?): ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn insertion_sort_list(head: Option>) -> Option> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @return ListNode\n */\n function insertionSortList($head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction insertionSortList(head: ListNode | null): ListNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (insertion-sort-list head)\n (-> (or/c list-node? #f) (or/c list-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0147](https://leetcode-cn.com/problems/insertion-sort-list)", "[\u5bf9\u94fe\u8868\u8fdb\u884c\u63d2\u5165\u6392\u5e8f](/solution/0100-0199/0147.Insertion%20Sort%20List/README.md)", "`\u6392\u5e8f`,`\u94fe\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0147](https://leetcode.com/problems/insertion-sort-list)", "[Insertion Sort List](/solution/0100-0199/0147.Insertion%20Sort%20List/README_EN.md)", "`Sort`,`Linked List`", "Medium", ""]}, {"question_id": "0146", "frontend_question_id": "0146", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/lru-cache", "url_en": "https://leetcode.com/problems/lru-cache", "relative_path_cn": "/solution/0100-0199/0146.LRU%20Cache/README.md", "relative_path_en": "/solution/0100-0199/0146.LRU%20Cache/README_EN.md", "title_cn": "LRU \u7f13\u5b58\u673a\u5236", "title_en": "LRU Cache", "question_title_slug": "lru-cache", "content_en": "

    Design a data structure that follows the constraints of a Least Recently Used (LRU) cache.

    \n\n

    Implement the LRUCache class:

    \n\n
      \n\t
    • LRUCache(int capacity) Initialize the LRU cache with positive size capacity.
    • \n\t
    • int get(int key) Return the value of the key if the key exists, otherwise return -1.
    • \n\t
    • void put(int key, int value) Update the value of the key if the key exists. Otherwise, add the key-value pair to the cache. If the number of keys exceeds the capacity from this operation, evict the least recently used key.
    • \n
    \n\n

    Follow up:
    \nCould you do get and put in O(1) time complexity?

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput\n["LRUCache", "put", "put", "get", "put", "get", "put", "get", "get", "get"]\n[[2], [1, 1], [2, 2], [1], [3, 3], [2], [4, 4], [1], [3], [4]]\nOutput\n[null, null, null, 1, null, -1, null, -1, 3, 4]\n\nExplanation\nLRUCache lRUCache = new LRUCache(2);\nlRUCache.put(1, 1); // cache is {1=1}\nlRUCache.put(2, 2); // cache is {1=1, 2=2}\nlRUCache.get(1);    // return 1\nlRUCache.put(3, 3); // LRU key was 2, evicts key 2, cache is {1=1, 3=3}\nlRUCache.get(2);    // returns -1 (not found)\nlRUCache.put(4, 4); // LRU key was 1, evicts key 1, cache is {4=4, 3=3}\nlRUCache.get(1);    // return -1 (not found)\nlRUCache.get(3);    // return 3\nlRUCache.get(4);    // return 4\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= capacity <= 3000
    • \n\t
    • 0 <= key <= 3000
    • \n\t
    • 0 <= value <= 104
    • \n\t
    • At most 3 * 104 calls will be made to get and put.
    • \n
    \n", "content_cn": "
    \u8fd0\u7528\u4f60\u6240\u638c\u63e1\u7684\u6570\u636e\u7ed3\u6784\uff0c\u8bbe\u8ba1\u548c\u5b9e\u73b0\u4e00\u4e2a\u00a0 LRU (\u6700\u8fd1\u6700\u5c11\u4f7f\u7528) \u7f13\u5b58\u673a\u5236 \u3002
    \n\n
    \n
    \n

    \u5b9e\u73b0 LRUCache \u7c7b\uff1a

    \n\n
      \n\t
    • LRUCache(int capacity) \u4ee5\u6b63\u6574\u6570\u4f5c\u4e3a\u5bb9\u91cf\u00a0capacity \u521d\u59cb\u5316 LRU \u7f13\u5b58
    • \n\t
    • int get(int key) \u5982\u679c\u5173\u952e\u5b57 key \u5b58\u5728\u4e8e\u7f13\u5b58\u4e2d\uff0c\u5219\u8fd4\u56de\u5173\u952e\u5b57\u7684\u503c\uff0c\u5426\u5219\u8fd4\u56de -1 \u3002
    • \n\t
    • void put(int key, int value)\u00a0\u5982\u679c\u5173\u952e\u5b57\u5df2\u7ecf\u5b58\u5728\uff0c\u5219\u53d8\u66f4\u5176\u6570\u636e\u503c\uff1b\u5982\u679c\u5173\u952e\u5b57\u4e0d\u5b58\u5728\uff0c\u5219\u63d2\u5165\u8be5\u7ec4\u300c\u5173\u952e\u5b57-\u503c\u300d\u3002\u5f53\u7f13\u5b58\u5bb9\u91cf\u8fbe\u5230\u4e0a\u9650\u65f6\uff0c\u5b83\u5e94\u8be5\u5728\u5199\u5165\u65b0\u6570\u636e\u4e4b\u524d\u5220\u9664\u6700\u4e45\u672a\u4f7f\u7528\u7684\u6570\u636e\u503c\uff0c\u4ece\u800c\u4e3a\u65b0\u7684\u6570\u636e\u503c\u7559\u51fa\u7a7a\u95f4\u3002
    • \n
    \n\n

    \u00a0

    \n
    \n
    \n\n

    \u8fdb\u9636\uff1a\u4f60\u662f\u5426\u53ef\u4ee5\u5728\u00a0O(1) \u65f6\u95f4\u590d\u6742\u5ea6\u5185\u5b8c\u6210\u8fd9\u4e24\u79cd\u64cd\u4f5c\uff1f

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\n[\"LRUCache\", \"put\", \"put\", \"get\", \"put\", \"get\", \"put\", \"get\", \"get\", \"get\"]\n[[2], [1, 1], [2, 2], [1], [3, 3], [2], [4, 4], [1], [3], [4]]\n\u8f93\u51fa\n[null, null, null, 1, null, -1, null, -1, 3, 4]\n\n\u89e3\u91ca\nLRUCache lRUCache = new LRUCache(2);\nlRUCache.put(1, 1); // \u7f13\u5b58\u662f {1=1}\nlRUCache.put(2, 2); // \u7f13\u5b58\u662f {1=1, 2=2}\nlRUCache.get(1);    // \u8fd4\u56de 1\nlRUCache.put(3, 3); // \u8be5\u64cd\u4f5c\u4f1a\u4f7f\u5f97\u5173\u952e\u5b57 2 \u4f5c\u5e9f\uff0c\u7f13\u5b58\u662f {1=1, 3=3}\nlRUCache.get(2);    // \u8fd4\u56de -1 (\u672a\u627e\u5230)\nlRUCache.put(4, 4); // \u8be5\u64cd\u4f5c\u4f1a\u4f7f\u5f97\u5173\u952e\u5b57 1 \u4f5c\u5e9f\uff0c\u7f13\u5b58\u662f {4=4, 3=3}\nlRUCache.get(1);    // \u8fd4\u56de -1 (\u672a\u627e\u5230)\nlRUCache.get(3);    // \u8fd4\u56de 3\nlRUCache.get(4);    // \u8fd4\u56de 4\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= capacity <= 3000
    • \n\t
    • 0 <= key <= 3000
    • \n\t
    • 0 <= value <= 104
    • \n\t
    • \u6700\u591a\u8c03\u7528 3 * 104 \u6b21 get \u548c put
    • \n
    \n", "tags_en": ["Design"], "tags_cn": ["\u8bbe\u8ba1"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class LRUCache {\npublic:\n LRUCache(int capacity) {\n\n }\n \n int get(int key) {\n\n }\n \n void put(int key, int value) {\n\n }\n};\n\n/**\n * Your LRUCache object will be instantiated and called as such:\n * LRUCache* obj = new LRUCache(capacity);\n * int param_1 = obj->get(key);\n * obj->put(key,value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class LRUCache {\n\n public LRUCache(int capacity) {\n\n }\n \n public int get(int key) {\n\n }\n \n public void put(int key, int value) {\n\n }\n}\n\n/**\n * Your LRUCache object will be instantiated and called as such:\n * LRUCache obj = new LRUCache(capacity);\n * int param_1 = obj.get(key);\n * obj.put(key,value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class LRUCache(object):\n\n def __init__(self, capacity):\n \"\"\"\n :type capacity: int\n \"\"\"\n\n\n def get(self, key):\n \"\"\"\n :type key: int\n :rtype: int\n \"\"\"\n\n\n def put(self, key, value):\n \"\"\"\n :type key: int\n :type value: int\n :rtype: None\n \"\"\"\n\n\n\n# Your LRUCache object will be instantiated and called as such:\n# obj = LRUCache(capacity)\n# param_1 = obj.get(key)\n# obj.put(key,value)", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class LRUCache:\n\n def __init__(self, capacity: int):\n\n\n def get(self, key: int) -> int:\n\n\n def put(self, key: int, value: int) -> None:\n\n\n\n# Your LRUCache object will be instantiated and called as such:\n# obj = LRUCache(capacity)\n# param_1 = obj.get(key)\n# obj.put(key,value)", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n\ntypedef struct {\n\n} LRUCache;\n\n\nLRUCache* lRUCacheCreate(int capacity) {\n\n}\n\nint lRUCacheGet(LRUCache* obj, int key) {\n\n}\n\nvoid lRUCachePut(LRUCache* obj, int key, int value) {\n\n}\n\nvoid lRUCacheFree(LRUCache* obj) {\n\n}\n\n/**\n * Your LRUCache struct will be instantiated and called as such:\n * LRUCache* obj = lRUCacheCreate(capacity);\n * int param_1 = lRUCacheGet(obj, key);\n \n * lRUCachePut(obj, key, value);\n \n * lRUCacheFree(obj);\n*/", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class LRUCache {\n\n public LRUCache(int capacity) {\n\n }\n \n public int Get(int key) {\n\n }\n \n public void Put(int key, int value) {\n\n }\n}\n\n/**\n * Your LRUCache object will be instantiated and called as such:\n * LRUCache obj = new LRUCache(capacity);\n * int param_1 = obj.Get(key);\n * obj.Put(key,value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} capacity\n */\nvar LRUCache = function(capacity) {\n\n};\n\n/** \n * @param {number} key\n * @return {number}\n */\nLRUCache.prototype.get = function(key) {\n\n};\n\n/** \n * @param {number} key \n * @param {number} value\n * @return {void}\n */\nLRUCache.prototype.put = function(key, value) {\n\n};\n\n/**\n * Your LRUCache object will be instantiated and called as such:\n * var obj = new LRUCache(capacity)\n * var param_1 = obj.get(key)\n * obj.put(key,value)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "class LRUCache\n\n=begin\n :type capacity: Integer\n=end\n def initialize(capacity)\n\n end\n\n\n=begin\n :type key: Integer\n :rtype: Integer\n=end\n def get(key)\n\n end\n\n\n=begin\n :type key: Integer\n :type value: Integer\n :rtype: Void\n=end\n def put(key, value)\n\n end\n\n\nend\n\n# Your LRUCache object will be instantiated and called as such:\n# obj = LRUCache.new(capacity)\n# param_1 = obj.get(key)\n# obj.put(key, value)", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "\nclass LRUCache {\n\n init(_ capacity: Int) {\n\n }\n \n func get(_ key: Int) -> Int {\n\n }\n \n func put(_ key: Int, _ value: Int) {\n\n }\n}\n\n/**\n * Your LRUCache object will be instantiated and called as such:\n * let obj = LRUCache(capacity)\n * let ret_1: Int = obj.get(key)\n * obj.put(key, value)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "type LRUCache struct {\n\n}\n\n\nfunc Constructor(capacity int) LRUCache {\n\n}\n\n\nfunc (this *LRUCache) Get(key int) int {\n\n}\n\n\nfunc (this *LRUCache) Put(key int, value int) {\n\n}\n\n\n/**\n * Your LRUCache object will be instantiated and called as such:\n * obj := Constructor(capacity);\n * param_1 := obj.Get(key);\n * obj.Put(key,value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "class LRUCache(_capacity: Int) {\n\n def get(key: Int): Int = {\n\n }\n\n def put(key: Int, value: Int) {\n\n }\n\n}\n\n/**\n * Your LRUCache object will be instantiated and called as such:\n * var obj = new LRUCache(capacity)\n * var param_1 = obj.get(key)\n * obj.put(key,value)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class LRUCache(capacity: Int) {\n\n fun get(key: Int): Int {\n\n }\n\n fun put(key: Int, value: Int) {\n\n }\n\n}\n\n/**\n * Your LRUCache object will be instantiated and called as such:\n * var obj = LRUCache(capacity)\n * var param_1 = obj.get(key)\n * obj.put(key,value)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "struct LRUCache {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl LRUCache {\n\n fn new(capacity: i32) -> Self {\n\n }\n \n fn get(&self, key: i32) -> i32 {\n\n }\n \n fn put(&self, key: i32, value: i32) {\n\n }\n}\n\n/**\n * Your LRUCache object will be instantiated and called as such:\n * let obj = LRUCache::new(capacity);\n * let ret_1: i32 = obj.get(key);\n * obj.put(key, value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class LRUCache {\n /**\n * @param Integer $capacity\n */\n function __construct($capacity) {\n\n }\n\n /**\n * @param Integer $key\n * @return Integer\n */\n function get($key) {\n\n }\n\n /**\n * @param Integer $key\n * @param Integer $value\n * @return NULL\n */\n function put($key, $value) {\n\n }\n}\n\n/**\n * Your LRUCache object will be instantiated and called as such:\n * $obj = LRUCache($capacity);\n * $ret_1 = $obj->get($key);\n * $obj->put($key, $value);\n */", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "class LRUCache {\n constructor(capacity: number) {\n\n }\n\n get(key: number): number {\n\n }\n\n put(key: number, value: number): void {\n\n }\n}\n\n/**\n * Your LRUCache object will be instantiated and called as such:\n * var obj = new LRUCache(capacity)\n * var param_1 = obj.get(key)\n * obj.put(key,value)\n */", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define lru-cache%\n (class object%\n (super-new)\n\n ; capacity : exact-integer?\n (init-field\n capacity)\n \n ; get : exact-integer? -> exact-integer?\n (define/public (get key)\n\n )\n ; put : exact-integer? exact-integer? -> void?\n (define/public (put key value)\n\n )))\n\n;; Your lru-cache% object will be instantiated and called as such:\n;; (define obj (new lru-cache% [capacity capacity]))\n;; (define param_1 (send obj get key))\n;; (send obj put key value)", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0146](https://leetcode-cn.com/problems/lru-cache)", "[LRU \u7f13\u5b58\u673a\u5236](/solution/0100-0199/0146.LRU%20Cache/README.md)", "`\u8bbe\u8ba1`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0146](https://leetcode.com/problems/lru-cache)", "[LRU Cache](/solution/0100-0199/0146.LRU%20Cache/README_EN.md)", "`Design`", "Medium", ""]}, {"question_id": "0145", "frontend_question_id": "0145", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/binary-tree-postorder-traversal", "url_en": "https://leetcode.com/problems/binary-tree-postorder-traversal", "relative_path_cn": "/solution/0100-0199/0145.Binary%20Tree%20Postorder%20Traversal/README.md", "relative_path_en": "/solution/0100-0199/0145.Binary%20Tree%20Postorder%20Traversal/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u7684\u540e\u5e8f\u904d\u5386", "title_en": "Binary Tree Postorder Traversal", "question_title_slug": "binary-tree-postorder-traversal", "content_en": "

    Given the root of a binary tree, return the postorder traversal of its nodes' values.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,null,2,3]\nOutput: [3,2,1]\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = []\nOutput: []\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = [1]\nOutput: [1]\n
    \n\n

    Example 4:

    \n\"\"\n
    \nInput: root = [1,2]\nOutput: [2,1]\n
    \n\n

    Example 5:

    \n\"\"\n
    \nInput: root = [1,null,2]\nOutput: [2,1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of the nodes in the tree is in the range [0, 100].
    • \n\t
    • -100 <= Node.val <= 100
    • \n
    \n\n

     

    \nFollow up: Recursive solution is trivial, could you do it iteratively?", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811\uff0c\u8fd4\u56de\u5b83\u7684 \u540e\u5e8f \u904d\u5386\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: [1,null,2,3]  \n   1\n    \\\n     2\n    /\n   3 \n\n\u8f93\u51fa: [3,2,1]
    \n\n

    \u8fdb\u9636: \u9012\u5f52\u7b97\u6cd5\u5f88\u7b80\u5355\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u8fed\u4ee3\u7b97\u6cd5\u5b8c\u6210\u5417\uff1f

    \n", "tags_en": ["Stack", "Tree"], "tags_cn": ["\u6808", "\u6811"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector postorderTraversal(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public List postorderTraversal(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def postorderTraversal(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def postorderTraversal(self, root: TreeNode) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* postorderTraversal(struct TreeNode* root, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public IList PostorderTraversal(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number[]}\n */\nvar postorderTraversal = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer[]}\ndef postorder_traversal(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func postorderTraversal(_ root: TreeNode?) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc postorderTraversal(root *TreeNode) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def postorderTraversal(root: TreeNode): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun postorderTraversal(root: TreeNode?): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn postorder_traversal(root: Option>>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer[]\n */\n function postorderTraversal($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction postorderTraversal(root: TreeNode | null): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (postorder-traversal root)\n (-> (or/c tree-node? #f) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0145](https://leetcode-cn.com/problems/binary-tree-postorder-traversal)", "[\u4e8c\u53c9\u6811\u7684\u540e\u5e8f\u904d\u5386](/solution/0100-0199/0145.Binary%20Tree%20Postorder%20Traversal/README.md)", "`\u6808`,`\u6811`", "\u7b80\u5355", ""], "md_table_row_en": ["[0145](https://leetcode.com/problems/binary-tree-postorder-traversal)", "[Binary Tree Postorder Traversal](/solution/0100-0199/0145.Binary%20Tree%20Postorder%20Traversal/README_EN.md)", "`Stack`,`Tree`", "Easy", ""]}, {"question_id": "0144", "frontend_question_id": "0144", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/binary-tree-preorder-traversal", "url_en": "https://leetcode.com/problems/binary-tree-preorder-traversal", "relative_path_cn": "/solution/0100-0199/0144.Binary%20Tree%20Preorder%20Traversal/README.md", "relative_path_en": "/solution/0100-0199/0144.Binary%20Tree%20Preorder%20Traversal/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u7684\u524d\u5e8f\u904d\u5386", "title_en": "Binary Tree Preorder Traversal", "question_title_slug": "binary-tree-preorder-traversal", "content_en": "

    Given the root of a binary tree, return the preorder traversal of its nodes' values.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,null,2,3]\nOutput: [1,2,3]\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = []\nOutput: []\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = [1]\nOutput: [1]\n
    \n\n

    Example 4:

    \n\"\"\n
    \nInput: root = [1,2]\nOutput: [1,2]\n
    \n\n

    Example 5:

    \n\"\"\n
    \nInput: root = [1,null,2]\nOutput: [1,2]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [0, 100].
    • \n\t
    • -100 <= Node.val <= 100
    • \n
    \n\n

     

    \n

    Follow up: Recursive solution is trivial, could you do it iteratively?

    \n", "content_cn": "

    \u7ed9\u4f60\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9 root \uff0c\u8fd4\u56de\u5b83\u8282\u70b9\u503c\u7684\u00a0\u524d\u5e8f\u00a0\u904d\u5386\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [1,null,2,3]\n\u8f93\u51fa\uff1a[1,2,3]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = []\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [1]\n\u8f93\u51fa\uff1a[1]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [1,2]\n\u8f93\u51fa\uff1a[1,2]\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [1,null,2]\n\u8f93\u51fa\uff1a[1,2]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u6570\u76ee\u5728\u8303\u56f4 [0, 100] \u5185
    • \n\t
    • -100 <= Node.val <= 100
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u9012\u5f52\u7b97\u6cd5\u5f88\u7b80\u5355\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u8fed\u4ee3\u7b97\u6cd5\u5b8c\u6210\u5417\uff1f

    \n", "tags_en": ["Stack", "Tree"], "tags_cn": ["\u6808", "\u6811"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector preorderTraversal(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public List preorderTraversal(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def preorderTraversal(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def preorderTraversal(self, root: TreeNode) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* preorderTraversal(struct TreeNode* root, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public IList PreorderTraversal(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number[]}\n */\nvar preorderTraversal = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer[]}\ndef preorder_traversal(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func preorderTraversal(_ root: TreeNode?) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc preorderTraversal(root *TreeNode) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def preorderTraversal(root: TreeNode): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun preorderTraversal(root: TreeNode?): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn preorder_traversal(root: Option>>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer[]\n */\n function preorderTraversal($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction preorderTraversal(root: TreeNode | null): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (preorder-traversal root)\n (-> (or/c tree-node? #f) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0144](https://leetcode-cn.com/problems/binary-tree-preorder-traversal)", "[\u4e8c\u53c9\u6811\u7684\u524d\u5e8f\u904d\u5386](/solution/0100-0199/0144.Binary%20Tree%20Preorder%20Traversal/README.md)", "`\u6808`,`\u6811`", "\u7b80\u5355", ""], "md_table_row_en": ["[0144](https://leetcode.com/problems/binary-tree-preorder-traversal)", "[Binary Tree Preorder Traversal](/solution/0100-0199/0144.Binary%20Tree%20Preorder%20Traversal/README_EN.md)", "`Stack`,`Tree`", "Easy", ""]}, {"question_id": "0143", "frontend_question_id": "0143", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reorder-list", "url_en": "https://leetcode.com/problems/reorder-list", "relative_path_cn": "/solution/0100-0199/0143.Reorder%20List/README.md", "relative_path_en": "/solution/0100-0199/0143.Reorder%20List/README_EN.md", "title_cn": "\u91cd\u6392\u94fe\u8868", "title_en": "Reorder List", "question_title_slug": "reorder-list", "content_en": "

    You are given the head of a singly linked-list. The list can be represented as:

    \n\n
    \nL0 → L1 → … → Ln - 1 → Ln\n
    \n\n

    Reorder the list to be on the following form:

    \n\n
    \nL0 → Ln → L1 → Ln - 1 → L2 → Ln - 2 → …\n
    \n\n

    You may not modify the values in the list's nodes. Only nodes themselves may be changed.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: head = [1,2,3,4]\nOutput: [1,4,2,3]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: head = [1,2,3,4,5]\nOutput: [1,5,2,4,3]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the list is in the range [1, 5 * 104].
    • \n\t
    • 1 <= Node.val <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5355\u94fe\u8868 L\uff1aL0L1→…→Ln-1Ln \uff0c
    \n\u5c06\u5176\u91cd\u65b0\u6392\u5217\u540e\u53d8\u4e3a\uff1a L0LnL1Ln-1L2Ln-2→…

    \n\n

    \u4f60\u4e0d\u80fd\u53ea\u662f\u5355\u7eaf\u7684\u6539\u53d8\u8282\u70b9\u5185\u90e8\u7684\u503c\uff0c\u800c\u662f\u9700\u8981\u5b9e\u9645\u7684\u8fdb\u884c\u8282\u70b9\u4ea4\u6362\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u7ed9\u5b9a\u94fe\u8868 1->2->3->4, \u91cd\u65b0\u6392\u5217\u4e3a 1->4->2->3.
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u7ed9\u5b9a\u94fe\u8868 1->2->3->4->5, \u91cd\u65b0\u6392\u5217\u4e3a 1->5->2->4->3.
    \n", "tags_en": ["Linked List"], "tags_cn": ["\u94fe\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n void reorderList(ListNode* head) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public void reorderList(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def reorderList(self, head):\n \"\"\"\n :type head: ListNode\n :rtype: None Do not return anything, modify head in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def reorderList(self, head: ListNode) -> None:\n \"\"\"\n Do not return anything, modify head in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nvoid reorderList(struct ListNode* head){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public void ReorderList(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} head\n * @return {void} Do not return anything, modify head in-place instead.\n */\nvar reorderList = function(head) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode} head\n# @return {Void} Do not return anything, modify head in-place instead.\ndef reorder_list(head)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func reorderList(_ head: ListNode?) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc reorderList(head *ListNode) {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def reorderList(head: ListNode): Unit = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun reorderList(head: ListNode?): Unit {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn reorder_list(head: &mut Option>) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @return NULL\n */\n function reorderList($head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\n/**\n Do not return anything, modify head in-place instead.\n */\nfunction reorderList(head: ListNode | null): void {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (reorder-list head)\n (-> (or/c list-node? #f) void?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0143](https://leetcode-cn.com/problems/reorder-list)", "[\u91cd\u6392\u94fe\u8868](/solution/0100-0199/0143.Reorder%20List/README.md)", "`\u94fe\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0143](https://leetcode.com/problems/reorder-list)", "[Reorder List](/solution/0100-0199/0143.Reorder%20List/README_EN.md)", "`Linked List`", "Medium", ""]}, {"question_id": "0142", "frontend_question_id": "0142", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/linked-list-cycle-ii", "url_en": "https://leetcode.com/problems/linked-list-cycle-ii", "relative_path_cn": "/solution/0100-0199/0142.Linked%20List%20Cycle%20II/README.md", "relative_path_en": "/solution/0100-0199/0142.Linked%20List%20Cycle%20II/README_EN.md", "title_cn": "\u73af\u5f62\u94fe\u8868 II", "title_en": "Linked List Cycle II", "question_title_slug": "linked-list-cycle-ii", "content_en": "

    Given a linked list, return the node where the cycle begins. If there is no cycle, return null.

    \n\n

    There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the next pointer. Internally, pos is used to denote the index of the node that tail's next pointer is connected to. Note that pos is not passed as a parameter.

    \n\n

    Notice that you should not modify the linked list.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: head = [3,2,0,-4], pos = 1\nOutput: tail connects to node index 1\nExplanation: There is a cycle in the linked list, where tail connects to the second node.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: head = [1,2], pos = 0\nOutput: tail connects to node index 0\nExplanation: There is a cycle in the linked list, where tail connects to the first node.\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: head = [1], pos = -1\nOutput: no cycle\nExplanation: There is no cycle in the linked list.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of the nodes in the list is in the range [0, 104].
    • \n\t
    • -105 <= Node.val <= 105
    • \n\t
    • pos is -1 or a valid index in the linked-list.
    • \n
    \n\n

     

    \n

    Follow up: Can you solve it using O(1) (i.e. constant) memory?

    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u94fe\u8868\uff0c\u8fd4\u56de\u94fe\u8868\u5f00\u59cb\u5165\u73af\u7684\u7b2c\u4e00\u4e2a\u8282\u70b9\u3002\u00a0\u5982\u679c\u94fe\u8868\u65e0\u73af\uff0c\u5219\u8fd4\u56de\u00a0null\u3002

    \n\n

    \u4e3a\u4e86\u8868\u793a\u7ed9\u5b9a\u94fe\u8868\u4e2d\u7684\u73af\uff0c\u6211\u4eec\u4f7f\u7528\u6574\u6570 pos \u6765\u8868\u793a\u94fe\u8868\u5c3e\u8fde\u63a5\u5230\u94fe\u8868\u4e2d\u7684\u4f4d\u7f6e\uff08\u7d22\u5f15\u4ece 0 \u5f00\u59cb\uff09\u3002 \u5982\u679c pos \u662f -1\uff0c\u5219\u5728\u8be5\u94fe\u8868\u4e2d\u6ca1\u6709\u73af\u3002\u6ce8\u610f\uff0cpos \u4ec5\u4ec5\u662f\u7528\u4e8e\u6807\u8bc6\u73af\u7684\u60c5\u51b5\uff0c\u5e76\u4e0d\u4f1a\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u5230\u51fd\u6570\u4e2d\u3002

    \n\n

    \u8bf4\u660e\uff1a\u4e0d\u5141\u8bb8\u4fee\u6539\u7ed9\u5b9a\u7684\u94fe\u8868\u3002

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u4f60\u662f\u5426\u53ef\u4ee5\u4f7f\u7528 O(1) \u7a7a\u95f4\u89e3\u51b3\u6b64\u9898\uff1f
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1ahead = [3,2,0,-4], pos = 1\n\u8f93\u51fa\uff1a\u8fd4\u56de\u7d22\u5f15\u4e3a 1 \u7684\u94fe\u8868\u8282\u70b9\n\u89e3\u91ca\uff1a\u94fe\u8868\u4e2d\u6709\u4e00\u4e2a\u73af\uff0c\u5176\u5c3e\u90e8\u8fde\u63a5\u5230\u7b2c\u4e8c\u4e2a\u8282\u70b9\u3002\n
    \n\n

    \u793a\u4f8b\u00a02\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1ahead = [1,2], pos = 0\n\u8f93\u51fa\uff1a\u8fd4\u56de\u7d22\u5f15\u4e3a 0 \u7684\u94fe\u8868\u8282\u70b9\n\u89e3\u91ca\uff1a\u94fe\u8868\u4e2d\u6709\u4e00\u4e2a\u73af\uff0c\u5176\u5c3e\u90e8\u8fde\u63a5\u5230\u7b2c\u4e00\u4e2a\u8282\u70b9\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1ahead = [1], pos = -1\n\u8f93\u51fa\uff1a\u8fd4\u56de null\n\u89e3\u91ca\uff1a\u94fe\u8868\u4e2d\u6ca1\u6709\u73af\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u94fe\u8868\u4e2d\u8282\u70b9\u7684\u6570\u76ee\u8303\u56f4\u5728\u8303\u56f4 [0, 104] \u5185
    • \n\t
    • -105 <= Node.val <= 105
    • \n\t
    • pos \u7684\u503c\u4e3a -1 \u6216\u8005\u94fe\u8868\u4e2d\u7684\u4e00\u4e2a\u6709\u6548\u7d22\u5f15
    • \n
    \n", "tags_en": ["Linked List", "Two Pointers"], "tags_cn": ["\u94fe\u8868", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\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 ListNode *detectCycle(ListNode *head) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * int val;\n * ListNode next;\n * ListNode(int x) {\n * val = x;\n * next = null;\n * }\n * }\n */\npublic class Solution {\n public ListNode detectCycle(ListNode head) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.next = None\n\nclass Solution(object):\n def detectCycle(self, head):\n \"\"\"\n :type head: ListNode\n :rtype: ListNode\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, x):\n# self.val = x\n# self.next = None\n\nclass Solution:\n def detectCycle(self, head: ListNode) -> ListNode:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\nstruct ListNode *detectCycle(struct ListNode *head) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int x) {\n * val = x;\n * next = null;\n * }\n * }\n */\npublic class Solution {\n public ListNode DetectCycle(ListNode head) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val) {\n * this.val = val;\n * this.next = null;\n * }\n */\n\n/**\n * @param {ListNode} head\n * @return {ListNode}\n */\nvar detectCycle = function(head) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val)\n# @val = val\n# @next = nil\n# end\n# end\n\n# @param {ListNode} head\n# @return {ListNode}\ndef detectCycle(head)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.next = nil\n * }\n * }\n */\n\nclass Solution {\n func detectCycle(_ head: ListNode?) -> ListNode? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc detectCycle(head *ListNode) *ListNode {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(var _x: Int = 0) {\n * var next: ListNode = null\n * var x: Int = _x\n * }\n */\n\nobject Solution {\n def detectCycle(head: ListNode): ListNode = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\n\nclass Solution {\n fun detectCycle(head: ListNode?): ListNode? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val) { $this->val = $val; }\n * }\n */\n\nclass Solution {\n /**\n * @param ListNode $head\n * @return ListNode\n */\n function detectCycle($head) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction detectCycle(head: ListNode | null): ListNode | null {\n \n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0142](https://leetcode-cn.com/problems/linked-list-cycle-ii)", "[\u73af\u5f62\u94fe\u8868 II](/solution/0100-0199/0142.Linked%20List%20Cycle%20II/README.md)", "`\u94fe\u8868`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0142](https://leetcode.com/problems/linked-list-cycle-ii)", "[Linked List Cycle II](/solution/0100-0199/0142.Linked%20List%20Cycle%20II/README_EN.md)", "`Linked List`,`Two Pointers`", "Medium", ""]}, {"question_id": "0141", "frontend_question_id": "0141", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/linked-list-cycle", "url_en": "https://leetcode.com/problems/linked-list-cycle", "relative_path_cn": "/solution/0100-0199/0141.Linked%20List%20Cycle/README.md", "relative_path_en": "/solution/0100-0199/0141.Linked%20List%20Cycle/README_EN.md", "title_cn": "\u73af\u5f62\u94fe\u8868", "title_en": "Linked List Cycle", "question_title_slug": "linked-list-cycle", "content_en": "

    Given head, the head of a linked list, determine if the linked list has a cycle in it.

    \n\n

    There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the next pointer. Internally, pos is used to denote the index of the node that tail's next pointer is connected to. Note that pos is not passed as a parameter.

    \n\n

    Return true if there is a cycle in the linked list. Otherwise, return false.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: head = [3,2,0,-4], pos = 1\nOutput: true\nExplanation: There is a cycle in the linked list, where the tail connects to the 1st node (0-indexed).\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: head = [1,2], pos = 0\nOutput: true\nExplanation: There is a cycle in the linked list, where the tail connects to the 0th node.\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: head = [1], pos = -1\nOutput: false\nExplanation: There is no cycle in the linked list.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of the nodes in the list is in the range [0, 104].
    • \n\t
    • -105 <= Node.val <= 105
    • \n\t
    • pos is -1 or a valid index in the linked-list.
    • \n
    \n\n

     

    \n

    Follow up: Can you solve it using O(1) (i.e. constant) memory?

    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u94fe\u8868\uff0c\u5224\u65ad\u94fe\u8868\u4e2d\u662f\u5426\u6709\u73af\u3002

    \n\n

    \u5982\u679c\u94fe\u8868\u4e2d\u6709\u67d0\u4e2a\u8282\u70b9\uff0c\u53ef\u4ee5\u901a\u8fc7\u8fde\u7eed\u8ddf\u8e2a next \u6307\u9488\u518d\u6b21\u5230\u8fbe\uff0c\u5219\u94fe\u8868\u4e2d\u5b58\u5728\u73af\u3002 \u4e3a\u4e86\u8868\u793a\u7ed9\u5b9a\u94fe\u8868\u4e2d\u7684\u73af\uff0c\u6211\u4eec\u4f7f\u7528\u6574\u6570 pos \u6765\u8868\u793a\u94fe\u8868\u5c3e\u8fde\u63a5\u5230\u94fe\u8868\u4e2d\u7684\u4f4d\u7f6e\uff08\u7d22\u5f15\u4ece 0 \u5f00\u59cb\uff09\u3002 \u5982\u679c pos \u662f -1\uff0c\u5219\u5728\u8be5\u94fe\u8868\u4e2d\u6ca1\u6709\u73af\u3002\u6ce8\u610f\uff1apos \u4e0d\u4f5c\u4e3a\u53c2\u6570\u8fdb\u884c\u4f20\u9012\uff0c\u4ec5\u4ec5\u662f\u4e3a\u4e86\u6807\u8bc6\u94fe\u8868\u7684\u5b9e\u9645\u60c5\u51b5\u3002

    \n\n

    \u5982\u679c\u94fe\u8868\u4e2d\u5b58\u5728\u73af\uff0c\u5219\u8fd4\u56de true \u3002 \u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n

     

    \n\n

    \u8fdb\u9636\uff1a

    \n\n

    \u4f60\u80fd\u7528 O(1)\uff08\u5373\uff0c\u5e38\u91cf\uff09\u5185\u5b58\u89e3\u51b3\u6b64\u95ee\u9898\u5417\uff1f

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1ahead = [3,2,0,-4], pos = 1\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u94fe\u8868\u4e2d\u6709\u4e00\u4e2a\u73af\uff0c\u5176\u5c3e\u90e8\u8fde\u63a5\u5230\u7b2c\u4e8c\u4e2a\u8282\u70b9\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1ahead = [1,2], pos = 0\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u94fe\u8868\u4e2d\u6709\u4e00\u4e2a\u73af\uff0c\u5176\u5c3e\u90e8\u8fde\u63a5\u5230\u7b2c\u4e00\u4e2a\u8282\u70b9\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1ahead = [1], pos = -1\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u94fe\u8868\u4e2d\u6ca1\u6709\u73af\u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u94fe\u8868\u4e2d\u8282\u70b9\u7684\u6570\u76ee\u8303\u56f4\u662f [0, 104]
    • \n\t
    • -105 <= Node.val <= 105
    • \n\t
    • pos \u4e3a -1 \u6216\u8005\u94fe\u8868\u4e2d\u7684\u4e00\u4e2a \u6709\u6548\u7d22\u5f15 \u3002
    • \n
    \n", "tags_en": ["Linked List", "Two Pointers"], "tags_cn": ["\u94fe\u8868", "\u53cc\u6307\u9488"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\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 bool hasCycle(ListNode *head) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * int val;\n * ListNode next;\n * ListNode(int x) {\n * val = x;\n * next = null;\n * }\n * }\n */\npublic class Solution {\n public boolean hasCycle(ListNode head) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, x):\n# self.val = x\n# self.next = None\n\nclass Solution(object):\n def hasCycle(self, head):\n \"\"\"\n :type head: ListNode\n :rtype: bool\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, x):\n# self.val = x\n# self.next = None\n\nclass Solution:\n def hasCycle(self, head: ListNode) -> bool:\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\nbool hasCycle(struct ListNode *head) {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int x) {\n * val = x;\n * next = null;\n * }\n * }\n */\npublic class Solution {\n public bool HasCycle(ListNode head) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val) {\n * this.val = val;\n * this.next = null;\n * }\n */\n\n/**\n * @param {ListNode} head\n * @return {boolean}\n */\nvar hasCycle = function(head) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val)\n# @val = val\n# @next = nil\n# end\n# end\n\n# @param {ListNode} head\n# @return {Boolean}\ndef hasCycle(head)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init(_ val: Int) {\n * self.val = val\n * self.next = nil\n * }\n * }\n */\n\nclass Solution {\n func hasCycle(_ head: ListNode?) -> Bool {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc hasCycle(head *ListNode) bool {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(var _x: Int = 0) {\n * var next: ListNode = null\n * var x: Int = _x\n * }\n */\n\nobject Solution {\n def hasCycle(head: ListNode): Boolean = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\n\nclass Solution {\n fun hasCycle(head: ListNode?): Boolean {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val) { $this->val = $val; }\n * }\n */\n\nclass Solution {\n /**\n * @param ListNode $head\n * @return Boolean\n */\n function hasCycle($head) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction hasCycle(head: ListNode | null): boolean {\n \n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0141](https://leetcode-cn.com/problems/linked-list-cycle)", "[\u73af\u5f62\u94fe\u8868](/solution/0100-0199/0141.Linked%20List%20Cycle/README.md)", "`\u94fe\u8868`,`\u53cc\u6307\u9488`", "\u7b80\u5355", ""], "md_table_row_en": ["[0141](https://leetcode.com/problems/linked-list-cycle)", "[Linked List Cycle](/solution/0100-0199/0141.Linked%20List%20Cycle/README_EN.md)", "`Linked List`,`Two Pointers`", "Easy", ""]}, {"question_id": "0140", "frontend_question_id": "0140", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/word-break-ii", "url_en": "https://leetcode.com/problems/word-break-ii", "relative_path_cn": "/solution/0100-0199/0140.Word%20Break%20II/README.md", "relative_path_en": "/solution/0100-0199/0140.Word%20Break%20II/README_EN.md", "title_cn": "\u5355\u8bcd\u62c6\u5206 II", "title_en": "Word Break II", "question_title_slug": "word-break-ii", "content_en": "

    Given a string s and a dictionary of strings wordDict, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible sentences in any order.

    \n\n

    Note that the same word in the dictionary may be reused multiple times in the segmentation.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "catsanddog", wordDict = ["cat","cats","and","sand","dog"]\nOutput: ["cats and dog","cat sand dog"]\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "pineapplepenapple", wordDict = ["apple","pen","applepen","pine","pineapple"]\nOutput: ["pine apple pen apple","pineapple pen apple","pine applepen apple"]\nExplanation: Note that you are allowed to reuse a dictionary word.\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "catsandog", wordDict = ["cats","dog","sand","and","cat"]\nOutput: []\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 20
    • \n\t
    • 1 <= wordDict.length <= 1000
    • \n\t
    • 1 <= wordDict[i].length <= 10
    • \n\t
    • s and wordDict[i] consist of only lowercase English letters.
    • \n\t
    • All the strings of wordDict are unique.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u7a7a\u5b57\u7b26\u4e32 s \u548c\u4e00\u4e2a\u5305\u542b\u975e\u7a7a\u5355\u8bcd\u5217\u8868\u7684\u5b57\u5178 wordDict\uff0c\u5728\u5b57\u7b26\u4e32\u4e2d\u589e\u52a0\u7a7a\u683c\u6765\u6784\u5efa\u4e00\u4e2a\u53e5\u5b50\uff0c\u4f7f\u5f97\u53e5\u5b50\u4e2d\u6240\u6709\u7684\u5355\u8bcd\u90fd\u5728\u8bcd\u5178\u4e2d\u3002\u8fd4\u56de\u6240\u6709\u8fd9\u4e9b\u53ef\u80fd\u7684\u53e5\u5b50\u3002

    \n\n

    \u8bf4\u660e\uff1a

    \n\n
      \n\t
    • \u5206\u9694\u65f6\u53ef\u4ee5\u91cd\u590d\u4f7f\u7528\u5b57\u5178\u4e2d\u7684\u5355\u8bcd\u3002
    • \n\t
    • \u4f60\u53ef\u4ee5\u5047\u8bbe\u5b57\u5178\u4e2d\u6ca1\u6709\u91cd\u590d\u7684\u5355\u8bcd\u3002
    • \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165:\ns = "catsanddog"\nwordDict = ["cat", "cats", "and", "sand", "dog"]\n\u8f93\u51fa:\n[\n  "cats and dog",\n  "cat sand dog"\n]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165:\ns = "pineapplepenapple"\nwordDict = ["apple", "pen", "applepen", "pine", "pineapple"]\n\u8f93\u51fa:\n[\n  "pine apple pen apple",\n  "pineapple pen apple",\n  "pine applepen apple"\n]\n\u89e3\u91ca: \u6ce8\u610f\u4f60\u53ef\u4ee5\u91cd\u590d\u4f7f\u7528\u5b57\u5178\u4e2d\u7684\u5355\u8bcd\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165:\ns = "catsandog"\nwordDict = ["cats", "dog", "sand", "and", "cat"]\n\u8f93\u51fa:\n[]\n
    \n", "tags_en": ["Dynamic Programming", "Backtracking"], "tags_cn": ["\u52a8\u6001\u89c4\u5212", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector wordBreak(string s, vector& wordDict) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List wordBreak(String s, List wordDict) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def wordBreak(self, s, wordDict):\n \"\"\"\n :type s: str\n :type wordDict: List[str]\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def wordBreak(self, s: str, wordDict: List[str]) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** wordBreak(char * s, char ** wordDict, int wordDictSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList WordBreak(string s, IList wordDict) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string[]} wordDict\n * @return {string[]}\n */\nvar wordBreak = function(s, wordDict) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String[]} word_dict\n# @return {String[]}\ndef word_break(s, word_dict)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func wordBreak(_ s: String, _ wordDict: [String]) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func wordBreak(s string, wordDict []string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def wordBreak(s: String, wordDict: List[String]): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun wordBreak(s: String, wordDict: List): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn word_break(s: String, word_dict: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String[] $wordDict\n * @return String[]\n */\n function wordBreak($s, $wordDict) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function wordBreak(s: string, wordDict: string[]): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (word-break s wordDict)\n (-> string? (listof string?) (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0140](https://leetcode-cn.com/problems/word-break-ii)", "[\u5355\u8bcd\u62c6\u5206 II](/solution/0100-0199/0140.Word%20Break%20II/README.md)", "`\u52a8\u6001\u89c4\u5212`,`\u56de\u6eaf\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[0140](https://leetcode.com/problems/word-break-ii)", "[Word Break II](/solution/0100-0199/0140.Word%20Break%20II/README_EN.md)", "`Dynamic Programming`,`Backtracking`", "Hard", ""]}, {"question_id": "0139", "frontend_question_id": "0139", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/word-break", "url_en": "https://leetcode.com/problems/word-break", "relative_path_cn": "/solution/0100-0199/0139.Word%20Break/README.md", "relative_path_en": "/solution/0100-0199/0139.Word%20Break/README_EN.md", "title_cn": "\u5355\u8bcd\u62c6\u5206", "title_en": "Word Break", "question_title_slug": "word-break", "content_en": "

    Given a string s and a dictionary of strings wordDict, return true if s can be segmented into a space-separated sequence of one or more dictionary words.

    \n\n

    Note that the same word in the dictionary may be reused multiple times in the segmentation.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "leetcode", wordDict = ["leet","code"]\nOutput: true\nExplanation: Return true because "leetcode" can be segmented as "leet code".\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "applepenapple", wordDict = ["apple","pen"]\nOutput: true\nExplanation: Return true because "applepenapple" can be segmented as "apple pen apple".\nNote that you are allowed to reuse a dictionary word.\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "catsandog", wordDict = ["cats","dog","sand","and","cat"]\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 300
    • \n\t
    • 1 <= wordDict.length <= 1000
    • \n\t
    • 1 <= wordDict[i].length <= 20
    • \n\t
    • s and wordDict[i] consist of only lowercase English letters.
    • \n\t
    • All the strings of wordDict are unique.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u7a7a\u5b57\u7b26\u4e32 s \u548c\u4e00\u4e2a\u5305\u542b\u975e\u7a7a\u5355\u8bcd\u7684\u5217\u8868 wordDict\uff0c\u5224\u5b9a s \u662f\u5426\u53ef\u4ee5\u88ab\u7a7a\u683c\u62c6\u5206\u4e3a\u4e00\u4e2a\u6216\u591a\u4e2a\u5728\u5b57\u5178\u4e2d\u51fa\u73b0\u7684\u5355\u8bcd\u3002

    \n\n

    \u8bf4\u660e\uff1a

    \n\n
      \n\t
    • \u62c6\u5206\u65f6\u53ef\u4ee5\u91cd\u590d\u4f7f\u7528\u5b57\u5178\u4e2d\u7684\u5355\u8bcd\u3002
    • \n\t
    • \u4f60\u53ef\u4ee5\u5047\u8bbe\u5b57\u5178\u4e2d\u6ca1\u6709\u91cd\u590d\u7684\u5355\u8bcd\u3002
    • \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165: s = "leetcode", wordDict = ["leet", "code"]\n\u8f93\u51fa: true\n\u89e3\u91ca: \u8fd4\u56de true \u56e0\u4e3a "leetcode" \u53ef\u4ee5\u88ab\u62c6\u5206\u6210 "leet code"\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165: s = "applepenapple", wordDict = ["apple", "pen"]\n\u8f93\u51fa: true\n\u89e3\u91ca: \u8fd4\u56de true \u56e0\u4e3a "applepenapple" \u53ef\u4ee5\u88ab\u62c6\u5206\u6210 "apple pen apple"\u3002\n     \u6ce8\u610f\u4f60\u53ef\u4ee5\u91cd\u590d\u4f7f\u7528\u5b57\u5178\u4e2d\u7684\u5355\u8bcd\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165: s = "catsandog", wordDict = ["cats", "dog", "sand", "and", "cat"]\n\u8f93\u51fa: false\n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool wordBreak(string s, vector& wordDict) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean wordBreak(String s, List wordDict) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def wordBreak(self, s, wordDict):\n \"\"\"\n :type s: str\n :type wordDict: List[str]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def wordBreak(self, s: str, wordDict: List[str]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool wordBreak(char * s, char ** wordDict, int wordDictSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool WordBreak(string s, IList wordDict) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string[]} wordDict\n * @return {boolean}\n */\nvar wordBreak = function(s, wordDict) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String[]} word_dict\n# @return {Boolean}\ndef word_break(s, word_dict)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func wordBreak(_ s: String, _ wordDict: [String]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func wordBreak(s string, wordDict []string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def wordBreak(s: String, wordDict: List[String]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun wordBreak(s: String, wordDict: List): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn word_break(s: String, word_dict: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String[] $wordDict\n * @return Boolean\n */\n function wordBreak($s, $wordDict) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function wordBreak(s: string, wordDict: string[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (word-break s wordDict)\n (-> string? (listof string?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0139](https://leetcode-cn.com/problems/word-break)", "[\u5355\u8bcd\u62c6\u5206](/solution/0100-0199/0139.Word%20Break/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0139](https://leetcode.com/problems/word-break)", "[Word Break](/solution/0100-0199/0139.Word%20Break/README_EN.md)", "`Dynamic Programming`", "Medium", ""]}, {"question_id": "0138", "frontend_question_id": "0138", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/copy-list-with-random-pointer", "url_en": "https://leetcode.com/problems/copy-list-with-random-pointer", "relative_path_cn": "/solution/0100-0199/0138.Copy%20List%20with%20Random%20Pointer/README.md", "relative_path_en": "/solution/0100-0199/0138.Copy%20List%20with%20Random%20Pointer/README_EN.md", "title_cn": "\u590d\u5236\u5e26\u968f\u673a\u6307\u9488\u7684\u94fe\u8868", "title_en": "Copy List with Random Pointer", "question_title_slug": "copy-list-with-random-pointer", "content_en": "

    A linked list of length n is given such that each node contains an additional random pointer, which could point to any node in the list, or null.

    \n\n

    Construct a deep copy of the list. The deep copy should consist of exactly n brand new nodes, where each new node has its value set to the value of its corresponding original node. Both the next and random pointer of the new nodes should point to new nodes in the copied list such that the pointers in the original list and copied list represent the same list state. None of the pointers in the new list should point to nodes in the original list.

    \n\n

    For example, if there are two nodes X and Y in the original list, where X.random --> Y, then for the corresponding two nodes x and y in the copied list, x.random --> y.

    \n\n

    Return the head of the copied linked list.

    \n\n

    The linked list is represented in the input/output as a list of n nodes. Each node is represented as a pair of [val, random_index] where:

    \n\n
      \n\t
    • val: an integer representing Node.val
    • \n\t
    • random_index: the index of the node (range from 0 to n-1) that the random pointer points to, or null if it does not point to any node.
    • \n
    \n\n

    Your code will only be given the head of the original linked list.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: head = [[7,null],[13,0],[11,4],[10,2],[1,0]]\nOutput: [[7,null],[13,0],[11,4],[10,2],[1,0]]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: head = [[1,1],[2,1]]\nOutput: [[1,1],[2,1]]\n
    \n\n

    Example 3:

    \n\n

    \"\"

    \n\n
    \nInput: head = [[3,null],[3,0],[3,null]]\nOutput: [[3,null],[3,0],[3,null]]\n
    \n\n

    Example 4:

    \n\n
    \nInput: head = []\nOutput: []\nExplanation: The given linked list is empty (null pointer), so return null.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= n <= 1000
    • \n\t
    • -10000 <= Node.val <= 10000
    • \n\t
    • Node.random is null or is pointing to some node in the linked list.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u94fe\u8868\uff0c\u6bcf\u4e2a\u8282\u70b9\u5305\u542b\u4e00\u4e2a\u989d\u5916\u589e\u52a0\u7684\u968f\u673a\u6307\u9488 random \uff0c\u8be5\u6307\u9488\u53ef\u4ee5\u6307\u5411\u94fe\u8868\u4e2d\u7684\u4efb\u4f55\u8282\u70b9\u6216\u7a7a\u8282\u70b9\u3002

    \n\n

    \u6784\u9020\u8fd9\u4e2a\u94fe\u8868\u7684\u00a0\u6df1\u62f7\u8d1d\u3002\u00a0\u6df1\u62f7\u8d1d\u5e94\u8be5\u6b63\u597d\u7531 n \u4e2a \u5168\u65b0 \u8282\u70b9\u7ec4\u6210\uff0c\u5176\u4e2d\u6bcf\u4e2a\u65b0\u8282\u70b9\u7684\u503c\u90fd\u8bbe\u4e3a\u5176\u5bf9\u5e94\u7684\u539f\u8282\u70b9\u7684\u503c\u3002\u65b0\u8282\u70b9\u7684 next \u6307\u9488\u548c random \u6307\u9488\u4e5f\u90fd\u5e94\u6307\u5411\u590d\u5236\u94fe\u8868\u4e2d\u7684\u65b0\u8282\u70b9\uff0c\u5e76\u4f7f\u539f\u94fe\u8868\u548c\u590d\u5236\u94fe\u8868\u4e2d\u7684\u8fd9\u4e9b\u6307\u9488\u80fd\u591f\u8868\u793a\u76f8\u540c\u7684\u94fe\u8868\u72b6\u6001\u3002\u590d\u5236\u94fe\u8868\u4e2d\u7684\u6307\u9488\u90fd\u4e0d\u5e94\u6307\u5411\u539f\u94fe\u8868\u4e2d\u7684\u8282\u70b9 \u3002

    \n\n

    \u4f8b\u5982\uff0c\u5982\u679c\u539f\u94fe\u8868\u4e2d\u6709 X \u548c Y \u4e24\u4e2a\u8282\u70b9\uff0c\u5176\u4e2d X.random --> Y \u3002\u90a3\u4e48\u5728\u590d\u5236\u94fe\u8868\u4e2d\u5bf9\u5e94\u7684\u4e24\u4e2a\u8282\u70b9 x \u548c y \uff0c\u540c\u6837\u6709 x.random --> y \u3002

    \n\n

    \u8fd4\u56de\u590d\u5236\u94fe\u8868\u7684\u5934\u8282\u70b9\u3002

    \n\n

    \u7528\u4e00\u4e2a\u7531\u00a0n\u00a0\u4e2a\u8282\u70b9\u7ec4\u6210\u7684\u94fe\u8868\u6765\u8868\u793a\u8f93\u5165/\u8f93\u51fa\u4e2d\u7684\u94fe\u8868\u3002\u6bcf\u4e2a\u8282\u70b9\u7528\u4e00\u4e2a\u00a0[val, random_index]\u00a0\u8868\u793a\uff1a

    \n\n
      \n\t
    • val\uff1a\u4e00\u4e2a\u8868\u793a\u00a0Node.val\u00a0\u7684\u6574\u6570\u3002
    • \n\t
    • random_index\uff1a\u968f\u673a\u6307\u9488\u6307\u5411\u7684\u8282\u70b9\u7d22\u5f15\uff08\u8303\u56f4\u4ece\u00a00\u00a0\u5230\u00a0n-1\uff09\uff1b\u5982\u679c\u4e0d\u6307\u5411\u4efb\u4f55\u8282\u70b9\uff0c\u5219\u4e3a\u00a0\u00a0null\u00a0\u3002
    • \n
    \n\n

    \u4f60\u7684\u4ee3\u7801 \u53ea \u63a5\u53d7\u539f\u94fe\u8868\u7684\u5934\u8282\u70b9 head \u4f5c\u4e3a\u4f20\u5165\u53c2\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1ahead = [[7,null],[13,0],[11,4],[10,2],[1,0]]\n\u8f93\u51fa\uff1a[[7,null],[13,0],[11,4],[10,2],[1,0]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1ahead = [[1,1],[2,1]]\n\u8f93\u51fa\uff1a[[1,1],[2,1]]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1ahead = [[3,null],[3,0],[3,null]]\n\u8f93\u51fa\uff1a[[3,null],[3,0],[3,null]]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahead = []\n\u8f93\u51fa\uff1a[]\n\u89e3\u91ca\uff1a\u7ed9\u5b9a\u7684\u94fe\u8868\u4e3a\u7a7a\uff08\u7a7a\u6307\u9488\uff09\uff0c\u56e0\u6b64\u8fd4\u56de null\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= n <= 1000
    • \n\t
    • -10000 <= Node.val <= 10000
    • \n\t
    • Node.random\u00a0\u4e3a\u7a7a\uff08null\uff09\u6216\u6307\u5411\u94fe\u8868\u4e2d\u7684\u8282\u70b9\u3002
    • \n
    \n", "tags_en": ["Hash Table", "Linked List"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u94fe\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* next;\n Node* random;\n \n Node(int _val) {\n val = _val;\n next = NULL;\n random = NULL;\n }\n};\n*/\n\nclass Solution {\npublic:\n Node* copyRandomList(Node* head) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/*\n// Definition for a Node.\nclass Node {\n int val;\n Node next;\n Node random;\n\n public Node(int val) {\n this.val = val;\n this.next = null;\n this.random = null;\n }\n}\n*/\n\nclass Solution {\n public Node copyRandomList(Node head) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "\"\"\"\n# Definition for a Node.\nclass Node:\n def __init__(self, x, next=None, random=None):\n self.val = int(x)\n self.next = next\n self.random = random\n\"\"\"\n\nclass Solution(object):\n def copyRandomList(self, head):\n \"\"\"\n :type head: Node\n :rtype: Node\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "\"\"\"\n# Definition for a Node.\nclass Node:\n def __init__(self, x: int, next: 'Node' = None, random: 'Node' = None):\n self.val = int(x)\n self.next = next\n self.random = random\n\"\"\"\n\nclass Solution:\n def copyRandomList(self, head: 'Node') -> 'Node':\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a Node.\n * struct Node {\n * int val;\n * struct Node *next;\n * struct Node *random;\n * };\n */\n\nstruct Node* copyRandomList(struct Node* head) {\n\t\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/*\n// Definition for a Node.\npublic class Node {\n public int val;\n public Node next;\n public Node random;\n \n public Node(int _val) {\n val = _val;\n next = null;\n random = null;\n }\n}\n*/\n\npublic class Solution {\n public Node CopyRandomList(Node head) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // Definition for a Node.\n * function Node(val, next, random) {\n * this.val = val;\n * this.next = next;\n * this.random = random;\n * };\n */\n\n/**\n * @param {Node} head\n * @return {Node}\n */\nvar copyRandomList = function(head) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for Node.\n# class Node\n# attr_accessor :val, :next, :random\n# def initialize(val = 0)\n# @val = val\n#\t\t @next = nil\n#\t\t @random = nil\n# end\n# end\n\n# @param {Node} node\n# @return {Node}\ndef copyRandomList(head)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a Node.\n * public class Node {\n * public var val: Int\n * public var next: Node?\n * public var random: Node?\n * public init(_ val: Int) {\n * self.val = val\n * self.next = nil\n * \t self.random = nil\n * }\n * }\n */\n\nclass Solution {\n func copyRandomList(_ head: Node?) -> Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a Node.\n * type Node struct {\n * Val int\n * Next *Node\n * Random *Node\n * }\n */\n\nfunc copyRandomList(head *Node) *Node {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a Node.\n * class Node(var _value: Int) {\n * var value: Int = _value\n * var next: Node = null\n * var random: Node = null\n * }\n */\n\nobject Solution {\n def copyRandomList(head: Node): Node = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = Node(5)\n * var v = ti.`val`\n * Definition for a Node.\n * class Node(var `val`: Int) {\n * var next: Node? = null\n * var random: Node? = null\n * }\n */\n\nclass Solution {\n fun copyRandomList(node: Node?): Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a Node.\n * class Node {\n * public $val = null;\n * public $next = null;\n * public $random = null;\n * function __construct($val = 0) {\n * $this->val = $val;\n * $this->next = null;\n * $this->random = null;\n * }\n * }\n */\n\nclass Solution {\n /**\n * @param Node $head\n * @return Node\n */\n function copyRandomList($head) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for Node.\n * class Node {\n * val: number\n * next: Node | null\n * random: Node | null\n * constructor(val?: number, next?: Node, random?: Node) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * this.random = (random===undefined ? null : random)\n * }\n * }\n */\n\nfunction copyRandomList(head: Node | null): Node | null {\n \n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0138](https://leetcode-cn.com/problems/copy-list-with-random-pointer)", "[\u590d\u5236\u5e26\u968f\u673a\u6307\u9488\u7684\u94fe\u8868](/solution/0100-0199/0138.Copy%20List%20with%20Random%20Pointer/README.md)", "`\u54c8\u5e0c\u8868`,`\u94fe\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0138](https://leetcode.com/problems/copy-list-with-random-pointer)", "[Copy List with Random Pointer](/solution/0100-0199/0138.Copy%20List%20with%20Random%20Pointer/README_EN.md)", "`Hash Table`,`Linked List`", "Medium", ""]}, {"question_id": "0137", "frontend_question_id": "0137", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/single-number-ii", "url_en": "https://leetcode.com/problems/single-number-ii", "relative_path_cn": "/solution/0100-0199/0137.Single%20Number%20II/README.md", "relative_path_en": "/solution/0100-0199/0137.Single%20Number%20II/README_EN.md", "title_cn": "\u53ea\u51fa\u73b0\u4e00\u6b21\u7684\u6570\u5b57 II", "title_en": "Single Number II", "question_title_slug": "single-number-ii", "content_en": "

    Given an integer array nums where every element appears three times except for one, which appears exactly once. Find the single element and return it.

    \n\n

    You must implement a solution with a linear runtime complexity and use only constant extra space.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [2,2,3,2]\nOutput: 3\n

    Example 2:

    \n
    Input: nums = [0,1,0,1,0,1,99]\nOutput: 99\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 3 * 104
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n\t
    • Each element in nums appears exactly three times except for one element which appears once.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0nums \uff0c\u9664\u67d0\u4e2a\u5143\u7d20\u4ec5\u51fa\u73b0 \u4e00\u6b21 \u5916\uff0c\u5176\u4f59\u6bcf\u4e2a\u5143\u7d20\u90fd\u6070\u51fa\u73b0 \u4e09\u6b21 \u3002\u8bf7\u4f60\u627e\u51fa\u5e76\u8fd4\u56de\u90a3\u4e2a\u53ea\u51fa\u73b0\u4e86\u4e00\u6b21\u7684\u5143\u7d20\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [2,2,3,2]\n\u8f93\u51fa\uff1a3\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [0,1,0,1,0,1,99]\n\u8f93\u51fa\uff1a99\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 3 * 104
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n\t
    • nums \u4e2d\uff0c\u9664\u67d0\u4e2a\u5143\u7d20\u4ec5\u51fa\u73b0 \u4e00\u6b21 \u5916\uff0c\u5176\u4f59\u6bcf\u4e2a\u5143\u7d20\u90fd\u6070\u51fa\u73b0 \u4e09\u6b21
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u7684\u7b97\u6cd5\u5e94\u8be5\u5177\u6709\u7ebf\u6027\u65f6\u95f4\u590d\u6742\u5ea6\u3002 \u4f60\u53ef\u4ee5\u4e0d\u4f7f\u7528\u989d\u5916\u7a7a\u95f4\u6765\u5b9e\u73b0\u5417\uff1f

    \n", "tags_en": ["Bit Manipulation"], "tags_cn": ["\u4f4d\u8fd0\u7b97"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int singleNumber(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int singleNumber(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def singleNumber(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def singleNumber(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint singleNumber(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SingleNumber(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar singleNumber = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef single_number(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func singleNumber(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func singleNumber(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def singleNumber(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun singleNumber(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn single_number(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function singleNumber($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function singleNumber(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (single-number nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0137](https://leetcode-cn.com/problems/single-number-ii)", "[\u53ea\u51fa\u73b0\u4e00\u6b21\u7684\u6570\u5b57 II](/solution/0100-0199/0137.Single%20Number%20II/README.md)", "`\u4f4d\u8fd0\u7b97`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0137](https://leetcode.com/problems/single-number-ii)", "[Single Number II](/solution/0100-0199/0137.Single%20Number%20II/README_EN.md)", "`Bit Manipulation`", "Medium", ""]}, {"question_id": "0136", "frontend_question_id": "0136", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/single-number", "url_en": "https://leetcode.com/problems/single-number", "relative_path_cn": "/solution/0100-0199/0136.Single%20Number/README.md", "relative_path_en": "/solution/0100-0199/0136.Single%20Number/README_EN.md", "title_cn": "\u53ea\u51fa\u73b0\u4e00\u6b21\u7684\u6570\u5b57", "title_en": "Single Number", "question_title_slug": "single-number", "content_en": "

    Given a non-empty array of integers nums, every element appears twice except for one. Find that single one.

    \n\n

    You must implement a solution with a linear runtime complexity and use only constant extra space.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [2,2,1]\nOutput: 1\n

    Example 2:

    \n
    Input: nums = [4,1,2,1,2]\nOutput: 4\n

    Example 3:

    \n
    Input: nums = [1]\nOutput: 1\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 3 * 104
    • \n\t
    • -3 * 104 <= nums[i] <= 3 * 104
    • \n\t
    • Each element in the array appears twice except for one element which appears only once.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u7a7a\u6574\u6570\u6570\u7ec4\uff0c\u9664\u4e86\u67d0\u4e2a\u5143\u7d20\u53ea\u51fa\u73b0\u4e00\u6b21\u4ee5\u5916\uff0c\u5176\u4f59\u6bcf\u4e2a\u5143\u7d20\u5747\u51fa\u73b0\u4e24\u6b21\u3002\u627e\u51fa\u90a3\u4e2a\u53ea\u51fa\u73b0\u4e86\u4e00\u6b21\u7684\u5143\u7d20\u3002

    \n\n

    \u8bf4\u660e\uff1a

    \n\n

    \u4f60\u7684\u7b97\u6cd5\u5e94\u8be5\u5177\u6709\u7ebf\u6027\u65f6\u95f4\u590d\u6742\u5ea6\u3002 \u4f60\u53ef\u4ee5\u4e0d\u4f7f\u7528\u989d\u5916\u7a7a\u95f4\u6765\u5b9e\u73b0\u5417\uff1f

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: [2,2,1]\n\u8f93\u51fa: 1\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: [4,1,2,1,2]\n\u8f93\u51fa: 4
    \n", "tags_en": ["Bit Manipulation", "Hash Table"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int singleNumber(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int singleNumber(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def singleNumber(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def singleNumber(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint singleNumber(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SingleNumber(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar singleNumber = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef single_number(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func singleNumber(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func singleNumber(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def singleNumber(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun singleNumber(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn single_number(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function singleNumber($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function singleNumber(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (single-number nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0136](https://leetcode-cn.com/problems/single-number)", "[\u53ea\u51fa\u73b0\u4e00\u6b21\u7684\u6570\u5b57](/solution/0100-0199/0136.Single%20Number/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0136](https://leetcode.com/problems/single-number)", "[Single Number](/solution/0100-0199/0136.Single%20Number/README_EN.md)", "`Bit Manipulation`,`Hash Table`", "Easy", ""]}, {"question_id": "0135", "frontend_question_id": "0135", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/candy", "url_en": "https://leetcode.com/problems/candy", "relative_path_cn": "/solution/0100-0199/0135.Candy/README.md", "relative_path_en": "/solution/0100-0199/0135.Candy/README_EN.md", "title_cn": "\u5206\u53d1\u7cd6\u679c", "title_en": "Candy", "question_title_slug": "candy", "content_en": "

    There are n children standing in a line. Each child is assigned a rating value given in the integer array ratings.

    \n\n

    You are giving candies to these children subjected to the following requirements:

    \n\n
      \n\t
    • Each child must have at least one candy.
    • \n\t
    • Children with a higher rating get more candies than their neighbors.
    • \n
    \n\n

    Return the minimum number of candies you need to have to distribute the candies to the children.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: ratings = [1,0,2]\nOutput: 5\nExplanation: You can allocate to the first, second and third child with 2, 1, 2 candies respectively.\n
    \n\n

    Example 2:

    \n\n
    \nInput: ratings = [1,2,2]\nOutput: 4\nExplanation: You can allocate to the first, second and third child with 1, 2, 1 candies respectively.\nThe third child gets 1 candy because it satisfies the above two conditions.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == ratings.length
    • \n\t
    • 1 <= n <= 2 * 104
    • \n\t
    • 0 <= ratings[i] <= 2 * 104
    • \n
    \n", "content_cn": "

    \u8001\u5e08\u60f3\u7ed9\u5b69\u5b50\u4eec\u5206\u53d1\u7cd6\u679c\uff0c\u6709 N\u00a0\u4e2a\u5b69\u5b50\u7ad9\u6210\u4e86\u4e00\u6761\u76f4\u7ebf\uff0c\u8001\u5e08\u4f1a\u6839\u636e\u6bcf\u4e2a\u5b69\u5b50\u7684\u8868\u73b0\uff0c\u9884\u5148\u7ed9\u4ed6\u4eec\u8bc4\u5206\u3002

    \n\n

    \u4f60\u9700\u8981\u6309\u7167\u4ee5\u4e0b\u8981\u6c42\uff0c\u5e2e\u52a9\u8001\u5e08\u7ed9\u8fd9\u4e9b\u5b69\u5b50\u5206\u53d1\u7cd6\u679c\uff1a

    \n\n
      \n\t
    • \u6bcf\u4e2a\u5b69\u5b50\u81f3\u5c11\u5206\u914d\u5230 1 \u4e2a\u7cd6\u679c\u3002
    • \n\t
    • \u8bc4\u5206\u66f4\u9ad8\u7684\u5b69\u5b50\u5fc5\u987b\u6bd4\u4ed6\u4e24\u4fa7\u7684\u90bb\u4f4d\u5b69\u5b50\u83b7\u5f97\u66f4\u591a\u7684\u7cd6\u679c\u3002
    • \n
    \n\n

    \u90a3\u4e48\u8fd9\u6837\u4e0b\u6765\uff0c\u8001\u5e08\u81f3\u5c11\u9700\u8981\u51c6\u5907\u591a\u5c11\u9897\u7cd6\u679c\u5462\uff1f

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\u00a01\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[1,0,2]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u5206\u522b\u7ed9\u8fd9\u4e09\u4e2a\u5b69\u5b50\u5206\u53d1 2\u30011\u30012 \u9897\u7cd6\u679c\u3002\n
    \n\n

    \u793a\u4f8b\u00a02\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[1,2,2]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u4f60\u53ef\u4ee5\u5206\u522b\u7ed9\u8fd9\u4e09\u4e2a\u5b69\u5b50\u5206\u53d1 1\u30012\u30011 \u9897\u7cd6\u679c\u3002\n     \u7b2c\u4e09\u4e2a\u5b69\u5b50\u53ea\u5f97\u5230 1 \u9897\u7cd6\u679c\uff0c\u8fd9\u5df2\u6ee1\u8db3\u4e0a\u8ff0\u4e24\u4e2a\u6761\u4ef6\u3002
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int candy(vector& ratings) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int candy(int[] ratings) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def candy(self, ratings):\n \"\"\"\n :type ratings: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def candy(self, ratings: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint candy(int* ratings, int ratingsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int Candy(int[] ratings) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} ratings\n * @return {number}\n */\nvar candy = function(ratings) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} ratings\n# @return {Integer}\ndef candy(ratings)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func candy(_ ratings: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func candy(ratings []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def candy(ratings: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun candy(ratings: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn candy(ratings: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $ratings\n * @return Integer\n */\n function candy($ratings) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function candy(ratings: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (candy ratings)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0135](https://leetcode-cn.com/problems/candy)", "[\u5206\u53d1\u7cd6\u679c](/solution/0100-0199/0135.Candy/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[0135](https://leetcode.com/problems/candy)", "[Candy](/solution/0100-0199/0135.Candy/README_EN.md)", "`Greedy`", "Hard", ""]}, {"question_id": "0134", "frontend_question_id": "0134", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/gas-station", "url_en": "https://leetcode.com/problems/gas-station", "relative_path_cn": "/solution/0100-0199/0134.Gas%20Station/README.md", "relative_path_en": "/solution/0100-0199/0134.Gas%20Station/README_EN.md", "title_cn": "\u52a0\u6cb9\u7ad9", "title_en": "Gas Station", "question_title_slug": "gas-station", "content_en": "

    There are n gas stations along a circular route, where the amount of gas at the ith station is gas[i].

    \n\n

    You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from the ith station to its next (i + 1)th station. You begin the journey with an empty tank at one of the gas stations.

    \n\n

    Given two integer arrays gas and cost, return the starting gas station's index if you can travel around the circuit once in the clockwise direction, otherwise return -1. If there exists a solution, it is guaranteed to be unique

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: gas = [1,2,3,4,5], cost = [3,4,5,1,2]\nOutput: 3\nExplanation:\nStart at station 3 (index 3) and fill up with 4 unit of gas. Your tank = 0 + 4 = 4\nTravel to station 4. Your tank = 4 - 1 + 5 = 8\nTravel to station 0. Your tank = 8 - 2 + 1 = 7\nTravel to station 1. Your tank = 7 - 3 + 2 = 6\nTravel to station 2. Your tank = 6 - 4 + 3 = 5\nTravel to station 3. The cost is 5. Your gas is just enough to travel back to station 3.\nTherefore, return 3 as the starting index.\n
    \n\n

    Example 2:

    \n\n
    \nInput: gas = [2,3,4], cost = [3,4,3]\nOutput: -1\nExplanation:\nYou can't start at station 0 or 1, as there is not enough gas to travel to the next station.\nLet's start at station 2 and fill up with 4 unit of gas. Your tank = 0 + 4 = 4\nTravel to station 0. Your tank = 4 - 3 + 2 = 3\nTravel to station 1. Your tank = 3 - 3 + 3 = 3\nYou cannot travel back to station 2, as it requires 4 unit of gas but you only have 3.\nTherefore, you can't travel around the circuit once no matter where you start.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • gas.length == n
    • \n\t
    • cost.length == n
    • \n\t
    • 1 <= n <= 104
    • \n\t
    • 0 <= gas[i], cost[i] <= 104
    • \n
    \n", "content_cn": "

    \u5728\u4e00\u6761\u73af\u8def\u4e0a\u6709 N \u4e2a\u52a0\u6cb9\u7ad9\uff0c\u5176\u4e2d\u7b2c i \u4e2a\u52a0\u6cb9\u7ad9\u6709\u6c7d\u6cb9 gas[i] \u5347\u3002

    \n\n

    \u4f60\u6709\u4e00\u8f86\u6cb9\u7bb1\u5bb9\u91cf\u65e0\u9650\u7684\u7684\u6c7d\u8f66\uff0c\u4ece\u7b2c i \u4e2a\u52a0\u6cb9\u7ad9\u5f00\u5f80\u7b2c i+1 \u4e2a\u52a0\u6cb9\u7ad9\u9700\u8981\u6d88\u8017\u6c7d\u6cb9 cost[i] \u5347\u3002\u4f60\u4ece\u5176\u4e2d\u7684\u4e00\u4e2a\u52a0\u6cb9\u7ad9\u51fa\u53d1\uff0c\u5f00\u59cb\u65f6\u6cb9\u7bb1\u4e3a\u7a7a\u3002

    \n\n

    \u5982\u679c\u4f60\u53ef\u4ee5\u7ed5\u73af\u8def\u884c\u9a76\u4e00\u5468\uff0c\u5219\u8fd4\u56de\u51fa\u53d1\u65f6\u52a0\u6cb9\u7ad9\u7684\u7f16\u53f7\uff0c\u5426\u5219\u8fd4\u56de -1\u3002

    \n\n

    \u8bf4\u660e: 

    \n\n
      \n\t
    • \u5982\u679c\u9898\u76ee\u6709\u89e3\uff0c\u8be5\u7b54\u6848\u5373\u4e3a\u552f\u4e00\u7b54\u6848\u3002
    • \n\t
    • \u8f93\u5165\u6570\u7ec4\u5747\u4e3a\u975e\u7a7a\u6570\u7ec4\uff0c\u4e14\u957f\u5ea6\u76f8\u540c\u3002
    • \n\t
    • \u8f93\u5165\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u5747\u4e3a\u975e\u8d1f\u6570\u3002
    • \n
    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: \ngas  = [1,2,3,4,5]\ncost = [3,4,5,1,2]\n\n\u8f93\u51fa: 3\n\n\u89e3\u91ca:\n\u4ece 3 \u53f7\u52a0\u6cb9\u7ad9(\u7d22\u5f15\u4e3a 3 \u5904)\u51fa\u53d1\uff0c\u53ef\u83b7\u5f97 4 \u5347\u6c7d\u6cb9\u3002\u6b64\u65f6\u6cb9\u7bb1\u6709 = 0 + 4 = 4 \u5347\u6c7d\u6cb9\n\u5f00\u5f80 4 \u53f7\u52a0\u6cb9\u7ad9\uff0c\u6b64\u65f6\u6cb9\u7bb1\u6709 4 - 1 + 5 = 8 \u5347\u6c7d\u6cb9\n\u5f00\u5f80 0 \u53f7\u52a0\u6cb9\u7ad9\uff0c\u6b64\u65f6\u6cb9\u7bb1\u6709 8 - 2 + 1 = 7 \u5347\u6c7d\u6cb9\n\u5f00\u5f80 1 \u53f7\u52a0\u6cb9\u7ad9\uff0c\u6b64\u65f6\u6cb9\u7bb1\u6709 7 - 3 + 2 = 6 \u5347\u6c7d\u6cb9\n\u5f00\u5f80 2 \u53f7\u52a0\u6cb9\u7ad9\uff0c\u6b64\u65f6\u6cb9\u7bb1\u6709 6 - 4 + 3 = 5 \u5347\u6c7d\u6cb9\n\u5f00\u5f80 3 \u53f7\u52a0\u6cb9\u7ad9\uff0c\u4f60\u9700\u8981\u6d88\u8017 5 \u5347\u6c7d\u6cb9\uff0c\u6b63\u597d\u8db3\u591f\u4f60\u8fd4\u56de\u5230 3 \u53f7\u52a0\u6cb9\u7ad9\u3002\n\u56e0\u6b64\uff0c3 \u53ef\u4e3a\u8d77\u59cb\u7d22\u5f15\u3002
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: \ngas  = [2,3,4]\ncost = [3,4,3]\n\n\u8f93\u51fa: -1\n\n\u89e3\u91ca:\n\u4f60\u4e0d\u80fd\u4ece 0 \u53f7\u6216 1 \u53f7\u52a0\u6cb9\u7ad9\u51fa\u53d1\uff0c\u56e0\u4e3a\u6ca1\u6709\u8db3\u591f\u7684\u6c7d\u6cb9\u53ef\u4ee5\u8ba9\u4f60\u884c\u9a76\u5230\u4e0b\u4e00\u4e2a\u52a0\u6cb9\u7ad9\u3002\n\u6211\u4eec\u4ece 2 \u53f7\u52a0\u6cb9\u7ad9\u51fa\u53d1\uff0c\u53ef\u4ee5\u83b7\u5f97 4 \u5347\u6c7d\u6cb9\u3002 \u6b64\u65f6\u6cb9\u7bb1\u6709 = 0 + 4 = 4 \u5347\u6c7d\u6cb9\n\u5f00\u5f80 0 \u53f7\u52a0\u6cb9\u7ad9\uff0c\u6b64\u65f6\u6cb9\u7bb1\u6709 4 - 3 + 2 = 3 \u5347\u6c7d\u6cb9\n\u5f00\u5f80 1 \u53f7\u52a0\u6cb9\u7ad9\uff0c\u6b64\u65f6\u6cb9\u7bb1\u6709 3 - 3 + 3 = 3 \u5347\u6c7d\u6cb9\n\u4f60\u65e0\u6cd5\u8fd4\u56de 2 \u53f7\u52a0\u6cb9\u7ad9\uff0c\u56e0\u4e3a\u8fd4\u7a0b\u9700\u8981\u6d88\u8017 4 \u5347\u6c7d\u6cb9\uff0c\u4f46\u662f\u4f60\u7684\u6cb9\u7bb1\u53ea\u6709 3 \u5347\u6c7d\u6cb9\u3002\n\u56e0\u6b64\uff0c\u65e0\u8bba\u600e\u6837\uff0c\u4f60\u90fd\u4e0d\u53ef\u80fd\u7ed5\u73af\u8def\u884c\u9a76\u4e00\u5468\u3002
    \n", "tags_en": ["Greedy"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int canCompleteCircuit(vector& gas, vector& cost) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int canCompleteCircuit(int[] gas, int[] cost) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canCompleteCircuit(self, gas, cost):\n \"\"\"\n :type gas: List[int]\n :type cost: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canCompleteCircuit(self, gas: List[int], cost: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint canCompleteCircuit(int* gas, int gasSize, int* cost, int costSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int CanCompleteCircuit(int[] gas, int[] cost) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} gas\n * @param {number[]} cost\n * @return {number}\n */\nvar canCompleteCircuit = function(gas, cost) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} gas\n# @param {Integer[]} cost\n# @return {Integer}\ndef can_complete_circuit(gas, cost)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canCompleteCircuit(_ gas: [Int], _ cost: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canCompleteCircuit(gas []int, cost []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canCompleteCircuit(gas: Array[Int], cost: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canCompleteCircuit(gas: IntArray, cost: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_complete_circuit(gas: Vec, cost: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $gas\n * @param Integer[] $cost\n * @return Integer\n */\n function canCompleteCircuit($gas, $cost) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canCompleteCircuit(gas: number[], cost: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-complete-circuit gas cost)\n (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0134](https://leetcode-cn.com/problems/gas-station)", "[\u52a0\u6cb9\u7ad9](/solution/0100-0199/0134.Gas%20Station/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0134](https://leetcode.com/problems/gas-station)", "[Gas Station](/solution/0100-0199/0134.Gas%20Station/README_EN.md)", "`Greedy`", "Medium", ""]}, {"question_id": "0133", "frontend_question_id": "0133", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/clone-graph", "url_en": "https://leetcode.com/problems/clone-graph", "relative_path_cn": "/solution/0100-0199/0133.Clone%20Graph/README.md", "relative_path_en": "/solution/0100-0199/0133.Clone%20Graph/README_EN.md", "title_cn": "\u514b\u9686\u56fe", "title_en": "Clone Graph", "question_title_slug": "clone-graph", "content_en": "

    Given a reference of a node in a connected undirected graph.

    \n\n

    Return a deep copy (clone) of the graph.

    \n\n

    Each node in the graph contains a value (int) and a list (List[Node]) of its neighbors.

    \n\n
    \nclass Node {\n    public int val;\n    public List<Node> neighbors;\n}\n
    \n\n

     

    \n\n

    Test case format:

    \n\n

    For simplicity, each node's value is the same as the node's index (1-indexed). For example, the first node with val == 1, the second node with val == 2, and so on. The graph is represented in the test case using an adjacency list.

    \n\n

    An adjacency list is a collection of unordered lists used to represent a finite graph. Each list describes the set of neighbors of a node in the graph.

    \n\n

    The given node will always be the first node with val = 1. You must return the copy of the given node as a reference to the cloned graph.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: adjList = [[2,4],[1,3],[2,4],[1,3]]\nOutput: [[2,4],[1,3],[2,4],[1,3]]\nExplanation: There are 4 nodes in the graph.\n1st node (val = 1)'s neighbors are 2nd node (val = 2) and 4th node (val = 4).\n2nd node (val = 2)'s neighbors are 1st node (val = 1) and 3rd node (val = 3).\n3rd node (val = 3)'s neighbors are 2nd node (val = 2) and 4th node (val = 4).\n4th node (val = 4)'s neighbors are 1st node (val = 1) and 3rd node (val = 3).\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: adjList = [[]]\nOutput: [[]]\nExplanation: Note that the input contains one empty list. The graph consists of only one node with val = 1 and it does not have any neighbors.\n
    \n\n

    Example 3:

    \n\n
    \nInput: adjList = []\nOutput: []\nExplanation: This an empty graph, it does not have any nodes.\n
    \n\n

    Example 4:

    \n\"\"\n
    \nInput: adjList = [[2],[1]]\nOutput: [[2],[1]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the graph is in the range [0, 100].
    • \n\t
    • 1 <= Node.val <= 100
    • \n\t
    • Node.val is unique for each node.
    • \n\t
    • There are no repeated edges and no self-loops in the graph.
    • \n\t
    • The Graph is connected and all nodes can be visited starting from the given node.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u65e0\u5411 \u8fde\u901a \u56fe\u4e2d\u4e00\u4e2a\u8282\u70b9\u7684\u5f15\u7528\uff0c\u8bf7\u4f60\u8fd4\u56de\u8be5\u56fe\u7684 \u6df1\u62f7\u8d1d\uff08\u514b\u9686\uff09\u3002

    \n\n

    \u56fe\u4e2d\u7684\u6bcf\u4e2a\u8282\u70b9\u90fd\u5305\u542b\u5b83\u7684\u503c val\uff08int\uff09 \u548c\u5176\u90bb\u5c45\u7684\u5217\u8868\uff08list[Node]\uff09\u3002

    \n\n
    class Node {\n    public int val;\n    public List<Node> neighbors;\n}
    \n\n

     

    \n\n

    \u6d4b\u8bd5\u7528\u4f8b\u683c\u5f0f\uff1a

    \n\n

    \u7b80\u5355\u8d77\u89c1\uff0c\u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u90fd\u548c\u5b83\u7684\u7d22\u5f15\u76f8\u540c\u3002\u4f8b\u5982\uff0c\u7b2c\u4e00\u4e2a\u8282\u70b9\u503c\u4e3a 1\uff08val = 1\uff09\uff0c\u7b2c\u4e8c\u4e2a\u8282\u70b9\u503c\u4e3a 2\uff08val = 2\uff09\uff0c\u4ee5\u6b64\u7c7b\u63a8\u3002\u8be5\u56fe\u5728\u6d4b\u8bd5\u7528\u4f8b\u4e2d\u4f7f\u7528\u90bb\u63a5\u5217\u8868\u8868\u793a\u3002

    \n\n

    \u90bb\u63a5\u5217\u8868 \u662f\u7528\u4e8e\u8868\u793a\u6709\u9650\u56fe\u7684\u65e0\u5e8f\u5217\u8868\u7684\u96c6\u5408\u3002\u6bcf\u4e2a\u5217\u8868\u90fd\u63cf\u8ff0\u4e86\u56fe\u4e2d\u8282\u70b9\u7684\u90bb\u5c45\u96c6\u3002

    \n\n

    \u7ed9\u5b9a\u8282\u70b9\u5c06\u59cb\u7ec8\u662f\u56fe\u4e2d\u7684\u7b2c\u4e00\u4e2a\u8282\u70b9\uff08\u503c\u4e3a 1\uff09\u3002\u4f60\u5fc5\u987b\u5c06 \u7ed9\u5b9a\u8282\u70b9\u7684\u62f7\u8d1d \u4f5c\u4e3a\u5bf9\u514b\u9686\u56fe\u7684\u5f15\u7528\u8fd4\u56de\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1aadjList = [[2,4],[1,3],[2,4],[1,3]]\n\u8f93\u51fa\uff1a[[2,4],[1,3],[2,4],[1,3]]\n\u89e3\u91ca\uff1a\n\u56fe\u4e2d\u6709 4 \u4e2a\u8282\u70b9\u3002\n\u8282\u70b9 1 \u7684\u503c\u662f 1\uff0c\u5b83\u6709\u4e24\u4e2a\u90bb\u5c45\uff1a\u8282\u70b9 2 \u548c 4 \u3002\n\u8282\u70b9 2 \u7684\u503c\u662f 2\uff0c\u5b83\u6709\u4e24\u4e2a\u90bb\u5c45\uff1a\u8282\u70b9 1 \u548c 3 \u3002\n\u8282\u70b9 3 \u7684\u503c\u662f 3\uff0c\u5b83\u6709\u4e24\u4e2a\u90bb\u5c45\uff1a\u8282\u70b9 2 \u548c 4 \u3002\n\u8282\u70b9 4 \u7684\u503c\u662f 4\uff0c\u5b83\u6709\u4e24\u4e2a\u90bb\u5c45\uff1a\u8282\u70b9 1 \u548c 3 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1aadjList = [[]]\n\u8f93\u51fa\uff1a[[]]\n\u89e3\u91ca\uff1a\u8f93\u5165\u5305\u542b\u4e00\u4e2a\u7a7a\u5217\u8868\u3002\u8be5\u56fe\u4ec5\u4ec5\u53ea\u6709\u4e00\u4e2a\u503c\u4e3a 1 \u7684\u8282\u70b9\uff0c\u5b83\u6ca1\u6709\u4efb\u4f55\u90bb\u5c45\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1aadjList = []\n\u8f93\u51fa\uff1a[]\n\u89e3\u91ca\uff1a\u8fd9\u4e2a\u56fe\u662f\u7a7a\u7684\uff0c\u5b83\u4e0d\u542b\u4efb\u4f55\u8282\u70b9\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n

    \"\"

    \n\n
    \u8f93\u5165\uff1aadjList = [[2],[1]]\n\u8f93\u51fa\uff1a[[2],[1]]
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    1. \u8282\u70b9\u6570\u4e0d\u8d85\u8fc7 100 \u3002
    2. \n\t
    3. \u6bcf\u4e2a\u8282\u70b9\u503c Node.val \u90fd\u662f\u552f\u4e00\u7684\uff0c1 <= Node.val <= 100\u3002
    4. \n\t
    5. \u65e0\u5411\u56fe\u662f\u4e00\u4e2a\u7b80\u5355\u56fe\uff0c\u8fd9\u610f\u5473\u7740\u56fe\u4e2d\u6ca1\u6709\u91cd\u590d\u7684\u8fb9\uff0c\u4e5f\u6ca1\u6709\u81ea\u73af\u3002
    6. \n\t
    7. \u7531\u4e8e\u56fe\u662f\u65e0\u5411\u7684\uff0c\u5982\u679c\u8282\u70b9 p \u662f\u8282\u70b9 q \u7684\u90bb\u5c45\uff0c\u90a3\u4e48\u8282\u70b9 q \u4e5f\u5fc5\u987b\u662f\u8282\u70b9 p \u7684\u90bb\u5c45\u3002
    8. \n\t
    9. \u56fe\u662f\u8fde\u901a\u56fe\uff0c\u4f60\u53ef\u4ee5\u4ece\u7ed9\u5b9a\u8282\u70b9\u8bbf\u95ee\u5230\u6240\u6709\u8282\u70b9\u3002
    10. \n
    \n", "tags_en": ["Depth-first Search", "Breadth-first Search", "Graph"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u56fe"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n vector neighbors;\n Node() {\n val = 0;\n neighbors = vector();\n }\n Node(int _val) {\n val = _val;\n neighbors = vector();\n }\n Node(int _val, vector _neighbors) {\n val = _val;\n neighbors = _neighbors;\n }\n};\n*/\n\nclass Solution {\npublic:\n Node* cloneGraph(Node* node) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/*\n// Definition for a Node.\nclass Node {\n public int val;\n public List neighbors;\n public Node() {\n val = 0;\n neighbors = new ArrayList();\n }\n public Node(int _val) {\n val = _val;\n neighbors = new ArrayList();\n }\n public Node(int _val, ArrayList _neighbors) {\n val = _val;\n neighbors = _neighbors;\n }\n}\n*/\n\nclass Solution {\n public Node cloneGraph(Node node) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "\"\"\"\n# Definition for a Node.\nclass Node(object):\n def __init__(self, val = 0, neighbors = None):\n self.val = val\n self.neighbors = neighbors if neighbors is not None else []\n\"\"\"\n\nclass Solution(object):\n def cloneGraph(self, node):\n \"\"\"\n :type node: Node\n :rtype: Node\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "\"\"\"\n# Definition for a Node.\nclass Node:\n def __init__(self, val = 0, neighbors = None):\n self.val = val\n self.neighbors = neighbors if neighbors is not None else []\n\"\"\"\n\nclass Solution:\n def cloneGraph(self, node: 'Node') -> 'Node':\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a Node.\n * struct Node {\n * int val;\n * int numNeighbors;\n * struct Node** neighbors;\n * };\n */\n\nstruct Node *cloneGraph(struct Node *s) {\n\t\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/*\n// Definition for a Node.\npublic class Node {\n public int val;\n public IList neighbors;\n\n public Node() {\n val = 0;\n neighbors = new List();\n }\n\n public Node(int _val) {\n val = _val;\n neighbors = new List();\n }\n\n public Node(int _val, List _neighbors) {\n val = _val;\n neighbors = _neighbors;\n }\n}\n*/\n\npublic class Solution {\n public Node CloneGraph(Node node) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // Definition for a Node.\n * function Node(val, neighbors) {\n * this.val = val === undefined ? 0 : val;\n * this.neighbors = neighbors === undefined ? [] : neighbors;\n * };\n */\n\n/**\n * @param {Node} node\n * @return {Node}\n */\nvar cloneGraph = function(node) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a Node.\n# class Node\n# attr_accessor :val, :neighbors\n# def initialize(val = 0, neighbors = nil)\n#\t\t @val = val\n#\t\t neighbors = [] if neighbors.nil?\n# @neighbors = neighbors\n# end\n# end\n\n# @param {Node} node\n# @return {Node}\ndef cloneGraph(node)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a Node.\n * public class Node {\n * public var val: Int\n * public var neighbors: [Node?]\n * public init(_ val: Int) {\n * self.val = val\n * self.neighbors = []\n * }\n * }\n */\n\nclass Solution {\n func cloneGraph(_ node: Node?) -> Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a Node.\n * type Node struct {\n * Val int\n * Neighbors []*Node\n * }\n */\n\nfunc cloneGraph(node *Node) *Node {\n \n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a Node.\n * class Node(var _value: Int) {\n * var value: Int = _value\n * var neighbors: List[Node] = List()\n * }\n */\n\nobject Solution {\n def cloneGraph(graph: Node): Node = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a Node.\n * class Node(var `val`: Int) {\n * var neighbors: ArrayList = ArrayList()\n * }\n */\n\nclass Solution {\n fun cloneGraph(node: Node?): Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a Node.\n * class Node {\n * public $val = null;\n * public $neighbors = null;\n * function __construct($val = 0) {\n * $this->val = $val;\n * $this->neighbors = array();\n * }\n * }\n */\n\nclass Solution {\n /**\n * @param Node $node\n * @return Node\n */\n function cloneGraph($node) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for Node.\n * class Node {\n * val: number\n * neighbors: Node[]\n * constructor(val?: number, neighbors?: Node[]) {\n * this.val = (val===undefined ? 0 : val)\n * this.neighbors = (neighbors===undefined ? [] : neighbors)\n * }\n * }\n */\n\nfunction cloneGraph(node: Node | null): Node | null {\n\t\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0133](https://leetcode-cn.com/problems/clone-graph)", "[\u514b\u9686\u56fe](/solution/0100-0199/0133.Clone%20Graph/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u56fe`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0133](https://leetcode.com/problems/clone-graph)", "[Clone Graph](/solution/0100-0199/0133.Clone%20Graph/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`,`Graph`", "Medium", ""]}, {"question_id": "0132", "frontend_question_id": "0132", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/palindrome-partitioning-ii", "url_en": "https://leetcode.com/problems/palindrome-partitioning-ii", "relative_path_cn": "/solution/0100-0199/0132.Palindrome%20Partitioning%20II/README.md", "relative_path_en": "/solution/0100-0199/0132.Palindrome%20Partitioning%20II/README_EN.md", "title_cn": "\u5206\u5272\u56de\u6587\u4e32 II", "title_en": "Palindrome Partitioning II", "question_title_slug": "palindrome-partitioning-ii", "content_en": "

    Given a string s, partition s such that every substring of the partition is a palindrome.

    \n\n

    Return the minimum cuts needed for a palindrome partitioning of s.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "aab"\nOutput: 1\nExplanation: The palindrome partitioning ["aa","b"] could be produced using 1 cut.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "a"\nOutput: 0\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "ab"\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 2000
    • \n\t
    • s consists of lower-case English letters only.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s\uff0c\u8bf7\u4f60\u5c06 s \u5206\u5272\u6210\u4e00\u4e9b\u5b50\u4e32\uff0c\u4f7f\u6bcf\u4e2a\u5b50\u4e32\u90fd\u662f\u56de\u6587\u3002

    \n\n

    \u8fd4\u56de\u7b26\u5408\u8981\u6c42\u7684 \u6700\u5c11\u5206\u5272\u6b21\u6570 \u3002

    \n\n
    \n
    \n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"aab\"\n\u8f93\u51fa\uff1a1\n\u89e3\u91ca\uff1a\u53ea\u9700\u4e00\u6b21\u5206\u5272\u5c31\u53ef\u5c06\u00a0s \u5206\u5272\u6210 [\"aa\",\"b\"] \u8fd9\u6837\u4e24\u4e2a\u56de\u6587\u5b50\u4e32\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"a\"\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"ab\"\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 2000
    • \n\t
    • s \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n
    \n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minCut(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minCut(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minCut(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minCut(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minCut(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinCut(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar minCut = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef min_cut(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minCut(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minCut(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minCut(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minCut(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_cut(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function minCut($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minCut(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-cut s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0132](https://leetcode-cn.com/problems/palindrome-partitioning-ii)", "[\u5206\u5272\u56de\u6587\u4e32 II](/solution/0100-0199/0132.Palindrome%20Partitioning%20II/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0132](https://leetcode.com/problems/palindrome-partitioning-ii)", "[Palindrome Partitioning II](/solution/0100-0199/0132.Palindrome%20Partitioning%20II/README_EN.md)", "`Dynamic Programming`", "Hard", ""]}, {"question_id": "0131", "frontend_question_id": "0131", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/palindrome-partitioning", "url_en": "https://leetcode.com/problems/palindrome-partitioning", "relative_path_cn": "/solution/0100-0199/0131.Palindrome%20Partitioning/README.md", "relative_path_en": "/solution/0100-0199/0131.Palindrome%20Partitioning/README_EN.md", "title_cn": "\u5206\u5272\u56de\u6587\u4e32", "title_en": "Palindrome Partitioning", "question_title_slug": "palindrome-partitioning", "content_en": "

    Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s.

    \n\n

    A palindrome string is a string that reads the same backward as forward.

    \n\n

     

    \n

    Example 1:

    \n
    Input: s = \"aab\"\nOutput: [[\"a\",\"a\",\"b\"],[\"aa\",\"b\"]]\n

    Example 2:

    \n
    Input: s = \"a\"\nOutput: [[\"a\"]]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 16
    • \n\t
    • s contains only lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s\uff0c\u8bf7\u4f60\u5c06 s \u5206\u5272\u6210\u4e00\u4e9b\u5b50\u4e32\uff0c\u4f7f\u6bcf\u4e2a\u5b50\u4e32\u90fd\u662f \u56de\u6587\u4e32 \u3002\u8fd4\u56de s \u6240\u6709\u53ef\u80fd\u7684\u5206\u5272\u65b9\u6848\u3002

    \n\n

    \u56de\u6587\u4e32 \u662f\u6b63\u7740\u8bfb\u548c\u53cd\u7740\u8bfb\u90fd\u4e00\u6837\u7684\u5b57\u7b26\u4e32\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"aab\"\n\u8f93\u51fa\uff1a[[\"a\",\"a\",\"b\"],[\"aa\",\"b\"]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"a\"\n\u8f93\u51fa\uff1a[[\"a\"]]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 16
    • \n\t
    • s \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n", "tags_en": ["Depth-first Search", "Dynamic Programming", "Backtracking"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u52a8\u6001\u89c4\u5212", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> partition(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> partition(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def partition(self, s):\n \"\"\"\n :type s: str\n :rtype: List[List[str]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def partition(self, s: str) -> List[List[str]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nchar *** partition(char * s, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> Partition(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string[][]}\n */\nvar partition = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String[][]}\ndef partition(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func partition(_ s: String) -> [[String]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func partition(s string) [][]string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def partition(s: String): List[List[String]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun partition(s: String): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn partition(s: String) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String[][]\n */\n function partition($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function partition(s: string): string[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (partition s)\n (-> string? (listof (listof string?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0131](https://leetcode-cn.com/problems/palindrome-partitioning)", "[\u5206\u5272\u56de\u6587\u4e32](/solution/0100-0199/0131.Palindrome%20Partitioning/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u52a8\u6001\u89c4\u5212`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0131](https://leetcode.com/problems/palindrome-partitioning)", "[Palindrome Partitioning](/solution/0100-0199/0131.Palindrome%20Partitioning/README_EN.md)", "`Depth-first Search`,`Dynamic Programming`,`Backtracking`", "Medium", ""]}, {"question_id": "0130", "frontend_question_id": "0130", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/surrounded-regions", "url_en": "https://leetcode.com/problems/surrounded-regions", "relative_path_cn": "/solution/0100-0199/0130.Surrounded%20Regions/README.md", "relative_path_en": "/solution/0100-0199/0130.Surrounded%20Regions/README_EN.md", "title_cn": "\u88ab\u56f4\u7ed5\u7684\u533a\u57df", "title_en": "Surrounded Regions", "question_title_slug": "surrounded-regions", "content_en": "

    Given an m x n matrix board containing 'X' and 'O', capture all regions surrounded by 'X'.

    \n\n

    A region is captured by flipping all 'O's into 'X's in that surrounded region.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: board = [["X","X","X","X"],["X","O","O","X"],["X","X","O","X"],["X","O","X","X"]]\nOutput: [["X","X","X","X"],["X","X","X","X"],["X","X","X","X"],["X","O","X","X"]]\nExplanation: Surrounded regions should not be on the border, which means that any 'O' on the border of the board are not flipped to 'X'. Any 'O' that is not on the border and it is not connected to an 'O' on the border will be flipped to 'X'. Two cells are connected if they are adjacent cells connected horizontally or vertically.\n
    \n\n

    Example 2:

    \n\n
    \nInput: board = [["X"]]\nOutput: [["X"]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == board.length
    • \n\t
    • n == board[i].length
    • \n\t
    • 1 <= m, n <= 200
    • \n\t
    • board[i][j] is 'X' or 'O'.
    • \n
    \n", "content_cn": "\u7ed9\u4f60\u4e00\u4e2a m x n \u7684\u77e9\u9635 board \uff0c\u7531\u82e5\u5e72\u5b57\u7b26 'X' \u548c 'O' \uff0c\u627e\u5230\u6240\u6709\u88ab 'X' \u56f4\u7ed5\u7684\u533a\u57df\uff0c\u5e76\u5c06\u8fd9\u4e9b\u533a\u57df\u91cc\u6240\u6709\u7684\u00a0'O' \u7528 'X' \u586b\u5145\u3002\n
    \n
    \n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aboard = [[\"X\",\"X\",\"X\",\"X\"],[\"X\",\"O\",\"O\",\"X\"],[\"X\",\"X\",\"O\",\"X\"],[\"X\",\"O\",\"X\",\"X\"]]\n\u8f93\u51fa\uff1a[[\"X\",\"X\",\"X\",\"X\"],[\"X\",\"X\",\"X\",\"X\"],[\"X\",\"X\",\"X\",\"X\"],[\"X\",\"O\",\"X\",\"X\"]]\n\u89e3\u91ca\uff1a\u88ab\u56f4\u7ed5\u7684\u533a\u95f4\u4e0d\u4f1a\u5b58\u5728\u4e8e\u8fb9\u754c\u4e0a\uff0c\u6362\u53e5\u8bdd\u8bf4\uff0c\u4efb\u4f55\u8fb9\u754c\u4e0a\u7684\u00a0'O'\u00a0\u90fd\u4e0d\u4f1a\u88ab\u586b\u5145\u4e3a\u00a0'X'\u3002 \u4efb\u4f55\u4e0d\u5728\u8fb9\u754c\u4e0a\uff0c\u6216\u4e0d\u4e0e\u8fb9\u754c\u4e0a\u7684\u00a0'O'\u00a0\u76f8\u8fde\u7684\u00a0'O'\u00a0\u6700\u7ec8\u90fd\u4f1a\u88ab\u586b\u5145\u4e3a\u00a0'X'\u3002\u5982\u679c\u4e24\u4e2a\u5143\u7d20\u5728\u6c34\u5e73\u6216\u5782\u76f4\u65b9\u5411\u76f8\u90bb\uff0c\u5219\u79f0\u5b83\u4eec\u662f\u201c\u76f8\u8fde\u201d\u7684\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aboard = [[\"X\"]]\n\u8f93\u51fa\uff1a[[\"X\"]]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == board.length
    • \n\t
    • n == board[i].length
    • \n\t
    • 1 <= m, n <= 200
    • \n\t
    • board[i][j] \u4e3a 'X' \u6216 'O'
    • \n
    \n
    \n
    \n", "tags_en": ["Depth-first Search", "Breadth-first Search", "Union Find"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e76\u67e5\u96c6"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n void solve(vector>& board) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public void solve(char[][] board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def solve(self, board):\n \"\"\"\n :type board: List[List[str]]\n :rtype: None Do not return anything, modify board in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def solve(self, board: List[List[str]]) -> None:\n \"\"\"\n Do not return anything, modify board in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nvoid solve(char** board, int boardSize, int* boardColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public void Solve(char[][] board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {character[][]} board\n * @return {void} Do not return anything, modify board in-place instead.\n */\nvar solve = function(board) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Character[][]} board\n# @return {Void} Do not return anything, modify board in-place instead.\ndef solve(board)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func solve(_ board: inout [[Character]]) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func solve(board [][]byte) {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def solve(board: Array[Array[Char]]): Unit = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun solve(board: Array): Unit {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn solve(board: &mut Vec>) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $board\n * @return NULL\n */\n function solve(&$board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n Do not return anything, modify board in-place instead.\n */\nfunction solve(board: string[][]): void {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0130](https://leetcode-cn.com/problems/surrounded-regions)", "[\u88ab\u56f4\u7ed5\u7684\u533a\u57df](/solution/0100-0199/0130.Surrounded%20Regions/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e76\u67e5\u96c6`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0130](https://leetcode.com/problems/surrounded-regions)", "[Surrounded Regions](/solution/0100-0199/0130.Surrounded%20Regions/README_EN.md)", "`Depth-first Search`,`Breadth-first Search`,`Union Find`", "Medium", ""]}, {"question_id": "0129", "frontend_question_id": "0129", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sum-root-to-leaf-numbers", "url_en": "https://leetcode.com/problems/sum-root-to-leaf-numbers", "relative_path_cn": "/solution/0100-0199/0129.Sum%20Root%20to%20Leaf%20Numbers/README.md", "relative_path_en": "/solution/0100-0199/0129.Sum%20Root%20to%20Leaf%20Numbers/README_EN.md", "title_cn": "\u6c42\u6839\u8282\u70b9\u5230\u53f6\u8282\u70b9\u6570\u5b57\u4e4b\u548c", "title_en": "Sum Root to Leaf Numbers", "question_title_slug": "sum-root-to-leaf-numbers", "content_en": "

    You are given the root of a binary tree containing digits from 0 to 9 only.

    \n\n

    Each root-to-leaf path in the tree represents a number.

    \n\n
      \n\t
    • For example, the root-to-leaf path 1 -> 2 -> 3 represents the number 123.
    • \n
    \n\n

    Return the total sum of all root-to-leaf numbers. Test cases are generated so that the answer will fit in a 32-bit integer.

    \n\n

    A leaf node is a node with no children.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,2,3]\nOutput: 25\nExplanation:\nThe root-to-leaf path 1->2 represents the number 12.\nThe root-to-leaf path 1->3 represents the number 13.\nTherefore, sum = 12 + 13 = 25.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [4,9,0,5,1]\nOutput: 1026\nExplanation:\nThe root-to-leaf path 4->9->5 represents the number 495.\nThe root-to-leaf path 4->9->1 represents the number 491.\nThe root-to-leaf path 4->0 represents the number 40.\nTherefore, sum = 495 + 491 + 40 = 1026.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 1000].
    • \n\t
    • 0 <= Node.val <= 9
    • \n\t
    • The depth of the tree will not exceed 10.
    • \n
    \n", "content_cn": "\u7ed9\u4f60\u4e00\u4e2a\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9 root \uff0c\u6811\u4e2d\u6bcf\u4e2a\u8282\u70b9\u90fd\u5b58\u653e\u6709\u4e00\u4e2a 0 \u5230 9 \u4e4b\u95f4\u7684\u6570\u5b57\u3002\n
    \n
    \n

    \u6bcf\u6761\u4ece\u6839\u8282\u70b9\u5230\u53f6\u8282\u70b9\u7684\u8def\u5f84\u90fd\u4ee3\u8868\u4e00\u4e2a\u6570\u5b57\uff1a

    \n\n
      \n\t
    • \u4f8b\u5982\uff0c\u4ece\u6839\u8282\u70b9\u5230\u53f6\u8282\u70b9\u7684\u8def\u5f84 1 -> 2 -> 3 \u8868\u793a\u6570\u5b57 123 \u3002
    • \n
    \n\n

    \u8ba1\u7b97\u4ece\u6839\u8282\u70b9\u5230\u53f6\u8282\u70b9\u751f\u6210\u7684 \u6240\u6709\u6570\u5b57\u4e4b\u548c \u3002

    \n\n

    \u53f6\u8282\u70b9 \u662f\u6307\u6ca1\u6709\u5b50\u8282\u70b9\u7684\u8282\u70b9\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [1,2,3]\n\u8f93\u51fa\uff1a25\n\u89e3\u91ca\uff1a\n\u4ece\u6839\u5230\u53f6\u5b50\u8282\u70b9\u8def\u5f84 1->2 \u4ee3\u8868\u6570\u5b57 12\n\u4ece\u6839\u5230\u53f6\u5b50\u8282\u70b9\u8def\u5f84 1->3 \u4ee3\u8868\u6570\u5b57 13\n\u56e0\u6b64\uff0c\u6570\u5b57\u603b\u548c = 12 + 13 = 25
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [4,9,0,5,1]\n\u8f93\u51fa\uff1a1026\n\u89e3\u91ca\uff1a\n\u4ece\u6839\u5230\u53f6\u5b50\u8282\u70b9\u8def\u5f84 4->9->5 \u4ee3\u8868\u6570\u5b57 495\n\u4ece\u6839\u5230\u53f6\u5b50\u8282\u70b9\u8def\u5f84 4->9->1 \u4ee3\u8868\u6570\u5b57 491\n\u4ece\u6839\u5230\u53f6\u5b50\u8282\u70b9\u8def\u5f84 4->0 \u4ee3\u8868\u6570\u5b57 40\n\u56e0\u6b64\uff0c\u6570\u5b57\u603b\u548c = 495 + 491 + 40 = 1026\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u7684\u6570\u76ee\u5728\u8303\u56f4 [1, 1000] \u5185
    • \n\t
    • 0 <= Node.val <= 9
    • \n\t
    • \u6811\u7684\u6df1\u5ea6\u4e0d\u8d85\u8fc7 10
    • \n
    \n
    \n
    \n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int sumNumbers(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int sumNumbers(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def sumNumbers(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def sumNumbers(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint sumNumbers(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int SumNumbers(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar sumNumbers = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef sum_numbers(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func sumNumbers(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc sumNumbers(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def sumNumbers(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun sumNumbers(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn sum_numbers(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function sumNumbers($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction sumNumbers(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (sum-numbers root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0129](https://leetcode-cn.com/problems/sum-root-to-leaf-numbers)", "[\u6c42\u6839\u8282\u70b9\u5230\u53f6\u8282\u70b9\u6570\u5b57\u4e4b\u548c](/solution/0100-0199/0129.Sum%20Root%20to%20Leaf%20Numbers/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0129](https://leetcode.com/problems/sum-root-to-leaf-numbers)", "[Sum Root to Leaf Numbers](/solution/0100-0199/0129.Sum%20Root%20to%20Leaf%20Numbers/README_EN.md)", "`Tree`,`Depth-first Search`", "Medium", ""]}, {"question_id": "0128", "frontend_question_id": "0128", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-consecutive-sequence", "url_en": "https://leetcode.com/problems/longest-consecutive-sequence", "relative_path_cn": "/solution/0100-0199/0128.Longest%20Consecutive%20Sequence/README.md", "relative_path_en": "/solution/0100-0199/0128.Longest%20Consecutive%20Sequence/README_EN.md", "title_cn": "\u6700\u957f\u8fde\u7eed\u5e8f\u5217", "title_en": "Longest Consecutive Sequence", "question_title_slug": "longest-consecutive-sequence", "content_en": "

    Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence.

    \n\n

    You must write an algorithm that runs in O(n) time.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [100,4,200,1,3,2]\nOutput: 4\nExplanation: The longest consecutive elements sequence is [1, 2, 3, 4]. Therefore its length is 4.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [0,3,7,2,5,8,4,6,0,1]\nOutput: 9\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= nums.length <= 105
    • \n\t
    • -109 <= nums[i] <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u672a\u6392\u5e8f\u7684\u6574\u6570\u6570\u7ec4 nums \uff0c\u627e\u51fa\u6570\u5b57\u8fde\u7eed\u7684\u6700\u957f\u5e8f\u5217\uff08\u4e0d\u8981\u6c42\u5e8f\u5217\u5143\u7d20\u5728\u539f\u6570\u7ec4\u4e2d\u8fde\u7eed\uff09\u7684\u957f\u5ea6\u3002

    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u53ef\u4ee5\u8bbe\u8ba1\u5e76\u5b9e\u73b0\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a\u00a0O(n) \u7684\u89e3\u51b3\u65b9\u6848\u5417\uff1f

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [100,4,200,1,3,2]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u6700\u957f\u6570\u5b57\u8fde\u7eed\u5e8f\u5217\u662f [1, 2, 3, 4]\u3002\u5b83\u7684\u957f\u5ea6\u4e3a 4\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [0,3,7,2,5,8,4,6,0,1]\n\u8f93\u51fa\uff1a9\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= nums.length <= 104
    • \n\t
    • -109 <= nums[i] <= 109
    • \n
    \n", "tags_en": ["Union Find", "Array"], "tags_cn": ["\u5e76\u67e5\u96c6", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int longestConsecutive(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int longestConsecutive(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestConsecutive(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestConsecutive(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint longestConsecutive(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LongestConsecutive(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar longestConsecutive = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef longest_consecutive(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestConsecutive(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestConsecutive(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestConsecutive(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestConsecutive(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_consecutive(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function longestConsecutive($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestConsecutive(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-consecutive nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0128](https://leetcode-cn.com/problems/longest-consecutive-sequence)", "[\u6700\u957f\u8fde\u7eed\u5e8f\u5217](/solution/0100-0199/0128.Longest%20Consecutive%20Sequence/README.md)", "`\u5e76\u67e5\u96c6`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0128](https://leetcode.com/problems/longest-consecutive-sequence)", "[Longest Consecutive Sequence](/solution/0100-0199/0128.Longest%20Consecutive%20Sequence/README_EN.md)", "`Union Find`,`Array`", "Medium", ""]}, {"question_id": "0127", "frontend_question_id": "0127", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/word-ladder", "url_en": "https://leetcode.com/problems/word-ladder", "relative_path_cn": "/solution/0100-0199/0127.Word%20Ladder/README.md", "relative_path_en": "/solution/0100-0199/0127.Word%20Ladder/README_EN.md", "title_cn": "\u5355\u8bcd\u63a5\u9f99", "title_en": "Word Ladder", "question_title_slug": "word-ladder", "content_en": "

    A transformation sequence from word beginWord to word endWord using a dictionary wordList is a sequence of words beginWord -> s1 -> s2 -> ... -> sk such that:

    \n\n
      \n\t
    • Every adjacent pair of words differs by a single letter.
    • \n\t
    • Every si for 1 <= i <= k is in wordList. Note that beginWord does not need to be in wordList.
    • \n\t
    • sk == endWord
    • \n
    \n\n

    Given two words, beginWord and endWord, and a dictionary wordList, return the number of words in the shortest transformation sequence from beginWord to endWord, or 0 if no such sequence exists.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: beginWord = "hit", endWord = "cog", wordList = ["hot","dot","dog","lot","log","cog"]\nOutput: 5\nExplanation: One shortest transformation sequence is "hit" -> "hot" -> "dot" -> "dog" -> cog", which is 5 words long.\n
    \n\n

    Example 2:

    \n\n
    \nInput: beginWord = "hit", endWord = "cog", wordList = ["hot","dot","dog","lot","log"]\nOutput: 0\nExplanation: The endWord "cog" is not in wordList, therefore there is no valid transformation sequence.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= beginWord.length <= 10
    • \n\t
    • endWord.length == beginWord.length
    • \n\t
    • 1 <= wordList.length <= 5000
    • \n\t
    • wordList[i].length == beginWord.length
    • \n\t
    • beginWord, endWord, and wordList[i] consist of lowercase English letters.
    • \n\t
    • beginWord != endWord
    • \n\t
    • All the words in wordList are unique.
    • \n
    \n", "content_cn": "

    \u5b57\u5178\u00a0wordList \u4e2d\u4ece\u5355\u8bcd beginWord\u00a0\u548c endWord \u7684 \u8f6c\u6362\u5e8f\u5217 \u662f\u4e00\u4e2a\u6309\u4e0b\u8ff0\u89c4\u683c\u5f62\u6210\u7684\u5e8f\u5217\uff1a

    \n\n
      \n\t
    • \u5e8f\u5217\u4e2d\u7b2c\u4e00\u4e2a\u5355\u8bcd\u662f beginWord \u3002
    • \n\t
    • \u5e8f\u5217\u4e2d\u6700\u540e\u4e00\u4e2a\u5355\u8bcd\u662f endWord \u3002
    • \n\t
    • \u6bcf\u6b21\u8f6c\u6362\u53ea\u80fd\u6539\u53d8\u4e00\u4e2a\u5b57\u6bcd\u3002
    • \n\t
    • \u8f6c\u6362\u8fc7\u7a0b\u4e2d\u7684\u4e2d\u95f4\u5355\u8bcd\u5fc5\u987b\u662f\u5b57\u5178\u00a0wordList \u4e2d\u7684\u5355\u8bcd\u3002
    • \n
    \n\n

    \u7ed9\u4f60\u4e24\u4e2a\u5355\u8bcd beginWord\u00a0\u548c endWord \u548c\u4e00\u4e2a\u5b57\u5178 wordList \uff0c\u627e\u5230\u4ece\u00a0beginWord \u5230\u00a0endWord \u7684 \u6700\u77ed\u8f6c\u6362\u5e8f\u5217 \u4e2d\u7684 \u5355\u8bcd\u6570\u76ee \u3002\u5982\u679c\u4e0d\u5b58\u5728\u8fd9\u6837\u7684\u8f6c\u6362\u5e8f\u5217\uff0c\u8fd4\u56de 0\u3002

    \n\u00a0\n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1abeginWord = \"hit\", endWord = \"cog\", wordList = [\"hot\",\"dot\",\"dog\",\"lot\",\"log\",\"cog\"]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u4e00\u4e2a\u6700\u77ed\u8f6c\u6362\u5e8f\u5217\u662f \"hit\" -> \"hot\" -> \"dot\" -> \"dog\" -> \"cog\", \u8fd4\u56de\u5b83\u7684\u957f\u5ea6 5\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1abeginWord = \"hit\", endWord = \"cog\", wordList = [\"hot\",\"dot\",\"dog\",\"lot\",\"log\"]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1aendWord \"cog\" \u4e0d\u5728\u5b57\u5178\u4e2d\uff0c\u6240\u4ee5\u65e0\u6cd5\u8fdb\u884c\u8f6c\u6362\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= beginWord.length <= 10
    • \n\t
    • endWord.length == beginWord.length
    • \n\t
    • 1 <= wordList.length <= 5000
    • \n\t
    • wordList[i].length == beginWord.length
    • \n\t
    • beginWord\u3001endWord \u548c wordList[i] \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n\t
    • beginWord != endWord
    • \n\t
    • wordList \u4e2d\u7684\u6240\u6709\u5b57\u7b26\u4e32 \u4e92\u4e0d\u76f8\u540c
    • \n
    \n", "tags_en": ["Breadth-first Search"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int ladderLength(string beginWord, string endWord, vector& wordList) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int ladderLength(String beginWord, String endWord, List wordList) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def ladderLength(self, beginWord, endWord, wordList):\n \"\"\"\n :type beginWord: str\n :type endWord: str\n :type wordList: List[str]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def ladderLength(self, beginWord: str, endWord: str, wordList: List[str]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint ladderLength(char * beginWord, char * endWord, char ** wordList, int wordListSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LadderLength(string beginWord, string endWord, IList wordList) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} beginWord\n * @param {string} endWord\n * @param {string[]} wordList\n * @return {number}\n */\nvar ladderLength = function(beginWord, endWord, wordList) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} begin_word\n# @param {String} end_word\n# @param {String[]} word_list\n# @return {Integer}\ndef ladder_length(begin_word, end_word, word_list)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func ladderLength(_ beginWord: String, _ endWord: String, _ wordList: [String]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func ladderLength(beginWord string, endWord string, wordList []string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def ladderLength(beginWord: String, endWord: String, wordList: List[String]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun ladderLength(beginWord: String, endWord: String, wordList: List): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn ladder_length(begin_word: String, end_word: String, word_list: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $beginWord\n * @param String $endWord\n * @param String[] $wordList\n * @return Integer\n */\n function ladderLength($beginWord, $endWord, $wordList) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function ladderLength(beginWord: string, endWord: string, wordList: string[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (ladder-length beginWord endWord wordList)\n (-> string? string? (listof string?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0127](https://leetcode-cn.com/problems/word-ladder)", "[\u5355\u8bcd\u63a5\u9f99](/solution/0100-0199/0127.Word%20Ladder/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[0127](https://leetcode.com/problems/word-ladder)", "[Word Ladder](/solution/0100-0199/0127.Word%20Ladder/README_EN.md)", "`Breadth-first Search`", "Hard", ""]}, {"question_id": "0126", "frontend_question_id": "0126", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/word-ladder-ii", "url_en": "https://leetcode.com/problems/word-ladder-ii", "relative_path_cn": "/solution/0100-0199/0126.Word%20Ladder%20II/README.md", "relative_path_en": "/solution/0100-0199/0126.Word%20Ladder%20II/README_EN.md", "title_cn": "\u5355\u8bcd\u63a5\u9f99 II", "title_en": "Word Ladder II", "question_title_slug": "word-ladder-ii", "content_en": "

    A transformation sequence from word beginWord to word endWord using a dictionary wordList is a sequence of words beginWord -> s1 -> s2 -> ... -> sk such that:

    \n\n
      \n\t
    • Every adjacent pair of words differs by a single letter.
    • \n\t
    • Every si for 1 <= i <= k is in wordList. Note that beginWord does not need to be in wordList.
    • \n\t
    • sk == endWord
    • \n
    \n\n

    Given two words, beginWord and endWord, and a dictionary wordList, return all the shortest transformation sequences from beginWord to endWord, or an empty list if no such sequence exists. Each sequence should be returned as a list of the words [beginWord, s1, s2, ..., sk].

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: beginWord = "hit", endWord = "cog", wordList = ["hot","dot","dog","lot","log","cog"]\nOutput: [["hit","hot","dot","dog","cog"],["hit","hot","lot","log","cog"]]\nExplanation: There are 2 shortest transformation sequences:\n"hit" -> "hot" -> "dot" -> "dog" -> "cog"\n"hit" -> "hot" -> "lot" -> "log" -> "cog"\n
    \n\n

    Example 2:

    \n\n
    \nInput: beginWord = "hit", endWord = "cog", wordList = ["hot","dot","dog","lot","log"]\nOutput: []\nExplanation: The endWord "cog" is not in wordList, therefore there is no valid transformation sequence.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= beginWord.length <= 5
    • \n\t
    • endWord.length == beginWord.length
    • \n\t
    • 1 <= wordList.length <= 1000
    • \n\t
    • wordList[i].length == beginWord.length
    • \n\t
    • beginWord, endWord, and wordList[i] consist of lowercase English letters.
    • \n\t
    • beginWord != endWord
    • \n\t
    • All the words in wordList are unique.
    • \n
    \n", "content_cn": "

    \u6309\u5b57\u5178\u00a0wordList \u5b8c\u6210\u4ece\u5355\u8bcd beginWord \u5230\u5355\u8bcd endWord \u8f6c\u5316\uff0c\u4e00\u4e2a\u8868\u793a\u6b64\u8fc7\u7a0b\u7684 \u8f6c\u6362\u5e8f\u5217 \u662f\u5f62\u5f0f\u4e0a\u50cf beginWord -> s1 -> s2 -> ... -> sk \u8fd9\u6837\u7684\u5355\u8bcd\u5e8f\u5217\uff0c\u5e76\u6ee1\u8db3\uff1a

    \n\n
    \n
    \n
      \n\t
    • \u6bcf\u5bf9\u76f8\u90bb\u7684\u5355\u8bcd\u4e4b\u95f4\u4ec5\u6709\u5355\u4e2a\u5b57\u6bcd\u4e0d\u540c\u3002
    • \n\t
    • \u8f6c\u6362\u8fc7\u7a0b\u4e2d\u7684\u6bcf\u4e2a\u5355\u8bcd si\uff081 <= i <= k\uff09\u5fc5\u987b\u662f\u5b57\u5178\u00a0wordList \u4e2d\u7684\u5355\u8bcd\u3002\u6ce8\u610f\uff0cbeginWord \u4e0d\u5fc5\u662f\u5b57\u5178 wordList \u4e2d\u7684\u5355\u8bcd\u3002
    • \n\t
    • sk == endWord
    • \n
    \n\n

    \u7ed9\u4f60\u4e24\u4e2a\u5355\u8bcd beginWord \u548c endWord \uff0c\u4ee5\u53ca\u4e00\u4e2a\u5b57\u5178 wordList \u3002\u8bf7\u4f60\u627e\u51fa\u5e76\u8fd4\u56de\u6240\u6709\u4ece beginWord \u5230 endWord \u7684 \u6700\u77ed\u8f6c\u6362\u5e8f\u5217 \uff0c\u5982\u679c\u4e0d\u5b58\u5728\u8fd9\u6837\u7684\u8f6c\u6362\u5e8f\u5217\uff0c\u8fd4\u56de\u4e00\u4e2a\u7a7a\u5217\u8868\u3002\u6bcf\u4e2a\u5e8f\u5217\u90fd\u5e94\u8be5\u4ee5\u5355\u8bcd\u5217\u8868 [beginWord, s1, s2, ..., sk] \u7684\u5f62\u5f0f\u8fd4\u56de\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1abeginWord = \"hit\", endWord = \"cog\", wordList = [\"hot\",\"dot\",\"dog\",\"lot\",\"log\",\"cog\"]\n\u8f93\u51fa\uff1a[[\"hit\",\"hot\",\"dot\",\"dog\",\"cog\"],[\"hit\",\"hot\",\"lot\",\"log\",\"cog\"]]\n\u89e3\u91ca\uff1a\u5b58\u5728 2 \u79cd\u6700\u77ed\u7684\u8f6c\u6362\u5e8f\u5217\uff1a\n\"hit\" -> \"hot\" -> \"dot\" -> \"dog\" -> \"cog\"\n\"hit\" -> \"hot\" -> \"lot\" -> \"log\" -> \"cog\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1abeginWord = \"hit\", endWord = \"cog\", wordList = [\"hot\",\"dot\",\"dog\",\"lot\",\"log\"]\n\u8f93\u51fa\uff1a[]\n\u89e3\u91ca\uff1aendWord \"cog\" \u4e0d\u5728\u5b57\u5178 wordList \u4e2d\uff0c\u6240\u4ee5\u4e0d\u5b58\u5728\u7b26\u5408\u8981\u6c42\u7684\u8f6c\u6362\u5e8f\u5217\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= beginWord.length <= 7
    • \n\t
    • endWord.length == beginWord.length
    • \n\t
    • 1 <= wordList.length <= 5000
    • \n\t
    • wordList[i].length == beginWord.length
    • \n\t
    • beginWord\u3001endWord \u548c wordList[i] \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n\t
    • beginWord != endWord
    • \n\t
    • wordList \u4e2d\u7684\u6240\u6709\u5355\u8bcd \u4e92\u4e0d\u76f8\u540c
    • \n
    \n
    \n
    \n", "tags_en": ["Breadth-first Search", "Array", "String", "Backtracking"], "tags_cn": ["\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22", "\u6570\u7ec4", "\u5b57\u7b26\u4e32", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> findLadders(string beginWord, string endWord, vector& wordList) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> findLadders(String beginWord, String endWord, List wordList) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findLadders(self, beginWord, endWord, wordList):\n \"\"\"\n :type beginWord: str\n :type endWord: str\n :type wordList: List[str]\n :rtype: List[List[str]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findLadders(self, beginWord: str, endWord: str, wordList: List[str]) -> List[List[str]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nchar *** findLadders(char * beginWord, char * endWord, char ** wordList, int wordListSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> FindLadders(string beginWord, string endWord, IList wordList) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} beginWord\n * @param {string} endWord\n * @param {string[]} wordList\n * @return {string[][]}\n */\nvar findLadders = function(beginWord, endWord, wordList) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} begin_word\n# @param {String} end_word\n# @param {String[]} word_list\n# @return {String[][]}\ndef find_ladders(begin_word, end_word, word_list)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findLadders(_ beginWord: String, _ endWord: String, _ wordList: [String]) -> [[String]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findLadders(beginWord string, endWord string, wordList []string) [][]string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findLadders(beginWord: String, endWord: String, wordList: List[String]): List[List[String]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findLadders(beginWord: String, endWord: String, wordList: List): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_ladders(begin_word: String, end_word: String, word_list: Vec) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $beginWord\n * @param String $endWord\n * @param String[] $wordList\n * @return String[][]\n */\n function findLadders($beginWord, $endWord, $wordList) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findLadders(beginWord: string, endWord: string, wordList: string[]): string[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-ladders beginWord endWord wordList)\n (-> string? string? (listof string?) (listof (listof string?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0126](https://leetcode-cn.com/problems/word-ladder-ii)", "[\u5355\u8bcd\u63a5\u9f99 II](/solution/0100-0199/0126.Word%20Ladder%20II/README.md)", "`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`,`\u6570\u7ec4`,`\u5b57\u7b26\u4e32`,`\u56de\u6eaf\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[0126](https://leetcode.com/problems/word-ladder-ii)", "[Word Ladder II](/solution/0100-0199/0126.Word%20Ladder%20II/README_EN.md)", "`Breadth-first Search`,`Array`,`String`,`Backtracking`", "Hard", ""]}, {"question_id": "0125", "frontend_question_id": "0125", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/valid-palindrome", "url_en": "https://leetcode.com/problems/valid-palindrome", "relative_path_cn": "/solution/0100-0199/0125.Valid%20Palindrome/README.md", "relative_path_en": "/solution/0100-0199/0125.Valid%20Palindrome/README_EN.md", "title_cn": "\u9a8c\u8bc1\u56de\u6587\u4e32", "title_en": "Valid Palindrome", "question_title_slug": "valid-palindrome", "content_en": "

    Given a string s, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "A man, a plan, a canal: Panama"\nOutput: true\nExplanation: "amanaplanacanalpanama" is a palindrome.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "race a car"\nOutput: false\nExplanation: "raceacar" is not a palindrome.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 2 * 105
    • \n\t
    • s consists only of printable ASCII characters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u9a8c\u8bc1\u5b83\u662f\u5426\u662f\u56de\u6587\u4e32\uff0c\u53ea\u8003\u8651\u5b57\u6bcd\u548c\u6570\u5b57\u5b57\u7b26\uff0c\u53ef\u4ee5\u5ffd\u7565\u5b57\u6bcd\u7684\u5927\u5c0f\u5199\u3002

    \n\n

    \u8bf4\u660e\uff1a\u672c\u9898\u4e2d\uff0c\u6211\u4eec\u5c06\u7a7a\u5b57\u7b26\u4e32\u5b9a\u4e49\u4e3a\u6709\u6548\u7684\u56de\u6587\u4e32\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: "A man, a plan, a canal: Panama"\n\u8f93\u51fa: true\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: "race a car"\n\u8f93\u51fa: false\n
    \n", "tags_en": ["Two Pointers", "String"], "tags_cn": ["\u53cc\u6307\u9488", "\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isPalindrome(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isPalindrome(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isPalindrome(self, s):\n \"\"\"\n :type s: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isPalindrome(self, s: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isPalindrome(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsPalindrome(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {boolean}\n */\nvar isPalindrome = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Boolean}\ndef is_palindrome(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isPalindrome(_ s: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isPalindrome(s string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isPalindrome(s: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isPalindrome(s: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_palindrome(s: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Boolean\n */\n function isPalindrome($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isPalindrome(s: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-palindrome s)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0125](https://leetcode-cn.com/problems/valid-palindrome)", "[\u9a8c\u8bc1\u56de\u6587\u4e32](/solution/0100-0199/0125.Valid%20Palindrome/README.md)", "`\u53cc\u6307\u9488`,`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0125](https://leetcode.com/problems/valid-palindrome)", "[Valid Palindrome](/solution/0100-0199/0125.Valid%20Palindrome/README_EN.md)", "`Two Pointers`,`String`", "Easy", ""]}, {"question_id": "0124", "frontend_question_id": "0124", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/binary-tree-maximum-path-sum", "url_en": "https://leetcode.com/problems/binary-tree-maximum-path-sum", "relative_path_cn": "/solution/0100-0199/0124.Binary%20Tree%20Maximum%20Path%20Sum/README.md", "relative_path_en": "/solution/0100-0199/0124.Binary%20Tree%20Maximum%20Path%20Sum/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u4e2d\u7684\u6700\u5927\u8def\u5f84\u548c", "title_en": "Binary Tree Maximum Path Sum", "question_title_slug": "binary-tree-maximum-path-sum", "content_en": "

    A path in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence at most once. Note that the path does not need to pass through the root.

    \n\n

    The path sum of a path is the sum of the node's values in the path.

    \n\n

    Given the root of a binary tree, return the maximum path sum of any path.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,2,3]\nOutput: 6\nExplanation: The optimal path is 2 -> 1 -> 3 with a path sum of 2 + 1 + 3 = 6.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [-10,9,20,null,null,15,7]\nOutput: 42\nExplanation: The optimal path is 15 -> 20 -> 7 with a path sum of 15 + 20 + 7 = 42.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 3 * 104].
    • \n\t
    • -1000 <= Node.val <= 1000
    • \n
    \n", "content_cn": "

    \u8def\u5f84 \u88ab\u5b9a\u4e49\u4e3a\u4e00\u6761\u4ece\u6811\u4e2d\u4efb\u610f\u8282\u70b9\u51fa\u53d1\uff0c\u6cbf\u7236\u8282\u70b9-\u5b50\u8282\u70b9\u8fde\u63a5\uff0c\u8fbe\u5230\u4efb\u610f\u8282\u70b9\u7684\u5e8f\u5217\u3002\u540c\u4e00\u4e2a\u8282\u70b9\u5728\u4e00\u6761\u8def\u5f84\u5e8f\u5217\u4e2d \u81f3\u591a\u51fa\u73b0\u4e00\u6b21 \u3002\u8be5\u8def\u5f84 \u81f3\u5c11\u5305\u542b\u4e00\u4e2a \u8282\u70b9\uff0c\u4e14\u4e0d\u4e00\u5b9a\u7ecf\u8fc7\u6839\u8282\u70b9\u3002

    \n\n

    \u8def\u5f84\u548c \u662f\u8def\u5f84\u4e2d\u5404\u8282\u70b9\u503c\u7684\u603b\u548c\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9 root \uff0c\u8fd4\u56de\u5176 \u6700\u5927\u8def\u5f84\u548c \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [1,2,3]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u6700\u4f18\u8def\u5f84\u662f 2 -> 1 -> 3 \uff0c\u8def\u5f84\u548c\u4e3a 2 + 1 + 3 = 6
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [-10,9,20,null,null,15,7]\n\u8f93\u51fa\uff1a42\n\u89e3\u91ca\uff1a\u6700\u4f18\u8def\u5f84\u662f 15 -> 20 -> 7 \uff0c\u8def\u5f84\u548c\u4e3a 15 + 20 + 7 = 42\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u6570\u76ee\u8303\u56f4\u662f [1, 3 * 104]
    • \n\t
    • -1000 <= Node.val <= 1000
    • \n
    \n", "tags_en": ["Tree", "Depth-first Search", "Recursion"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u9012\u5f52"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int maxPathSum(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int maxPathSum(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def maxPathSum(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def maxPathSum(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint maxPathSum(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int MaxPathSum(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar maxPathSum = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef max_path_sum(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func maxPathSum(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc maxPathSum(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def maxPathSum(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun maxPathSum(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn max_path_sum(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function maxPathSum($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction maxPathSum(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (max-path-sum root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0124](https://leetcode-cn.com/problems/binary-tree-maximum-path-sum)", "[\u4e8c\u53c9\u6811\u4e2d\u7684\u6700\u5927\u8def\u5f84\u548c](/solution/0100-0199/0124.Binary%20Tree%20Maximum%20Path%20Sum/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u9012\u5f52`", "\u56f0\u96be", ""], "md_table_row_en": ["[0124](https://leetcode.com/problems/binary-tree-maximum-path-sum)", "[Binary Tree Maximum Path Sum](/solution/0100-0199/0124.Binary%20Tree%20Maximum%20Path%20Sum/README_EN.md)", "`Tree`,`Depth-first Search`,`Recursion`", "Hard", ""]}, {"question_id": "0123", "frontend_question_id": "0123", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-iii", "url_en": "https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iii", "relative_path_cn": "/solution/0100-0199/0123.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20III/README.md", "relative_path_en": "/solution/0100-0199/0123.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20III/README_EN.md", "title_cn": "\u4e70\u5356\u80a1\u7968\u7684\u6700\u4f73\u65f6\u673a III", "title_en": "Best Time to Buy and Sell Stock III", "question_title_slug": "best-time-to-buy-and-sell-stock-iii", "content_en": "

    You are given an array prices where prices[i] is the price of a given stock on the ith day.

    \n\n

    Find the maximum profit you can achieve. You may complete at most two transactions.

    \n\n

    Note: You may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again).

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: prices = [3,3,5,0,0,3,1,4]\nOutput: 6\nExplanation: Buy on day 4 (price = 0) and sell on day 6 (price = 3), profit = 3-0 = 3.\nThen buy on day 7 (price = 1) and sell on day 8 (price = 4), profit = 4-1 = 3.
    \n\n

    Example 2:

    \n\n
    \nInput: prices = [1,2,3,4,5]\nOutput: 4\nExplanation: Buy on day 1 (price = 1) and sell on day 5 (price = 5), profit = 5-1 = 4.\nNote that you cannot buy on day 1, buy on day 2 and sell them later, as you are engaging multiple transactions at the same time. You must sell before buying again.\n
    \n\n

    Example 3:

    \n\n
    \nInput: prices = [7,6,4,3,1]\nOutput: 0\nExplanation: In this case, no transaction is done, i.e. max profit = 0.\n
    \n\n

    Example 4:

    \n\n
    \nInput: prices = [1]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= prices.length <= 105
    • \n\t
    • 0 <= prices[i] <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6570\u7ec4\uff0c\u5b83\u7684\u7b2c i \u4e2a\u5143\u7d20\u662f\u4e00\u652f\u7ed9\u5b9a\u7684\u80a1\u7968\u5728\u7b2c i \u5929\u7684\u4ef7\u683c\u3002

    \n\n

    \u8bbe\u8ba1\u4e00\u4e2a\u7b97\u6cd5\u6765\u8ba1\u7b97\u4f60\u6240\u80fd\u83b7\u53d6\u7684\u6700\u5927\u5229\u6da6\u3002\u4f60\u6700\u591a\u53ef\u4ee5\u5b8c\u6210\u00a0\u4e24\u7b14\u00a0\u4ea4\u6613\u3002

    \n\n

    \u6ce8\u610f\uff1a\u4f60\u4e0d\u80fd\u540c\u65f6\u53c2\u4e0e\u591a\u7b14\u4ea4\u6613\uff08\u4f60\u5fc5\u987b\u5728\u518d\u6b21\u8d2d\u4e70\u524d\u51fa\u552e\u6389\u4e4b\u524d\u7684\u80a1\u7968\uff09\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\u00a01:

    \n\n
    \n\u8f93\u5165\uff1aprices = [3,3,5,0,0,3,1,4]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u5728\u7b2c 4 \u5929\uff08\u80a1\u7968\u4ef7\u683c = 0\uff09\u7684\u65f6\u5019\u4e70\u5165\uff0c\u5728\u7b2c 6 \u5929\uff08\u80a1\u7968\u4ef7\u683c = 3\uff09\u7684\u65f6\u5019\u5356\u51fa\uff0c\u8fd9\u7b14\u4ea4\u6613\u6240\u80fd\u83b7\u5f97\u5229\u6da6 = 3-0 = 3 \u3002\n\u00a0    \u968f\u540e\uff0c\u5728\u7b2c 7 \u5929\uff08\u80a1\u7968\u4ef7\u683c = 1\uff09\u7684\u65f6\u5019\u4e70\u5165\uff0c\u5728\u7b2c 8 \u5929 \uff08\u80a1\u7968\u4ef7\u683c = 4\uff09\u7684\u65f6\u5019\u5356\u51fa\uff0c\u8fd9\u7b14\u4ea4\u6613\u6240\u80fd\u83b7\u5f97\u5229\u6da6 = 4-1 = 3 \u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aprices = [1,2,3,4,5]\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u5728\u7b2c 1 \u5929\uff08\u80a1\u7968\u4ef7\u683c = 1\uff09\u7684\u65f6\u5019\u4e70\u5165\uff0c\u5728\u7b2c 5 \u5929 \uff08\u80a1\u7968\u4ef7\u683c = 5\uff09\u7684\u65f6\u5019\u5356\u51fa, \u8fd9\u7b14\u4ea4\u6613\u6240\u80fd\u83b7\u5f97\u5229\u6da6 = 5-1 = 4 \u3002 \u00a0 \n\u00a0    \u6ce8\u610f\u4f60\u4e0d\u80fd\u5728\u7b2c 1 \u5929\u548c\u7b2c 2 \u5929\u63a5\u8fde\u8d2d\u4e70\u80a1\u7968\uff0c\u4e4b\u540e\u518d\u5c06\u5b83\u4eec\u5356\u51fa\u3002 \u00a0 \n\u00a0    \u56e0\u4e3a\u8fd9\u6837\u5c5e\u4e8e\u540c\u65f6\u53c2\u4e0e\u4e86\u591a\u7b14\u4ea4\u6613\uff0c\u4f60\u5fc5\u987b\u5728\u518d\u6b21\u8d2d\u4e70\u524d\u51fa\u552e\u6389\u4e4b\u524d\u7684\u80a1\u7968\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aprices = [7,6,4,3,1] \n\u8f93\u51fa\uff1a0 \n\u89e3\u91ca\uff1a\u5728\u8fd9\u4e2a\u60c5\u51b5\u4e0b, \u6ca1\u6709\u4ea4\u6613\u5b8c\u6210, \u6240\u4ee5\u6700\u5927\u5229\u6da6\u4e3a 0\u3002
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1aprices = [1]\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <=\u00a0prices.length <= 105
    • \n\t
    • 0 <=\u00a0prices[i] <=\u00a0105
    • \n
    \n", "tags_en": ["Array", "Dynamic Programming"], "tags_cn": ["\u6570\u7ec4", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxProfit(vector& prices) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxProfit(int[] prices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxProfit(self, prices):\n \"\"\"\n :type prices: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxProfit(self, prices: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxProfit(int* prices, int pricesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxProfit(int[] prices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} prices\n * @return {number}\n */\nvar maxProfit = function(prices) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} prices\n# @return {Integer}\ndef max_profit(prices)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxProfit(_ prices: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxProfit(prices []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxProfit(prices: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxProfit(prices: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_profit(prices: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $prices\n * @return Integer\n */\n function maxProfit($prices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxProfit(prices: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-profit prices)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0123](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-iii)", "[\u4e70\u5356\u80a1\u7968\u7684\u6700\u4f73\u65f6\u673a III](/solution/0100-0199/0123.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20III/README.md)", "`\u6570\u7ec4`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0123](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iii)", "[Best Time to Buy and Sell Stock III](/solution/0100-0199/0123.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20III/README_EN.md)", "`Array`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0122", "frontend_question_id": "0122", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-ii", "url_en": "https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii", "relative_path_cn": "/solution/0100-0199/0122.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20II/README.md", "relative_path_en": "/solution/0100-0199/0122.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20II/README_EN.md", "title_cn": "\u4e70\u5356\u80a1\u7968\u7684\u6700\u4f73\u65f6\u673a II", "title_en": "Best Time to Buy and Sell Stock II", "question_title_slug": "best-time-to-buy-and-sell-stock-ii", "content_en": "

    You are given an array prices where prices[i] is the price of a given stock on the ith day.

    \n\n

    Find the maximum profit you can achieve. You may complete as many transactions as you like (i.e., buy one and sell one share of the stock multiple times).

    \n\n

    Note: You may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again).

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: prices = [7,1,5,3,6,4]\nOutput: 7\nExplanation: Buy on day 2 (price = 1) and sell on day 3 (price = 5), profit = 5-1 = 4.\nThen buy on day 4 (price = 3) and sell on day 5 (price = 6), profit = 6-3 = 3.\n
    \n\n

    Example 2:

    \n\n
    \nInput: prices = [1,2,3,4,5]\nOutput: 4\nExplanation: Buy on day 1 (price = 1) and sell on day 5 (price = 5), profit = 5-1 = 4.\nNote that you cannot buy on day 1, buy on day 2 and sell them later, as you are engaging multiple transactions at the same time. You must sell before buying again.\n
    \n\n

    Example 3:

    \n\n
    \nInput: prices = [7,6,4,3,1]\nOutput: 0\nExplanation: In this case, no transaction is done, i.e., max profit = 0.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= prices.length <= 3 * 104
    • \n\t
    • 0 <= prices[i] <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6570\u7ec4 prices \uff0c\u5176\u4e2d\u00a0prices[i] \u662f\u4e00\u652f\u7ed9\u5b9a\u80a1\u7968\u7b2c i \u5929\u7684\u4ef7\u683c\u3002

    \n\n

    \u8bbe\u8ba1\u4e00\u4e2a\u7b97\u6cd5\u6765\u8ba1\u7b97\u4f60\u6240\u80fd\u83b7\u53d6\u7684\u6700\u5927\u5229\u6da6\u3002\u4f60\u53ef\u4ee5\u5c3d\u53ef\u80fd\u5730\u5b8c\u6210\u66f4\u591a\u7684\u4ea4\u6613\uff08\u591a\u6b21\u4e70\u5356\u4e00\u652f\u80a1\u7968\uff09\u3002

    \n\n

    \u6ce8\u610f\uff1a\u4f60\u4e0d\u80fd\u540c\u65f6\u53c2\u4e0e\u591a\u7b14\u4ea4\u6613\uff08\u4f60\u5fc5\u987b\u5728\u518d\u6b21\u8d2d\u4e70\u524d\u51fa\u552e\u6389\u4e4b\u524d\u7684\u80a1\u7968\uff09\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: prices = [7,1,5,3,6,4]\n\u8f93\u51fa: 7\n\u89e3\u91ca: \u5728\u7b2c 2 \u5929\uff08\u80a1\u7968\u4ef7\u683c = 1\uff09\u7684\u65f6\u5019\u4e70\u5165\uff0c\u5728\u7b2c 3 \u5929\uff08\u80a1\u7968\u4ef7\u683c = 5\uff09\u7684\u65f6\u5019\u5356\u51fa, \u8fd9\u7b14\u4ea4\u6613\u6240\u80fd\u83b7\u5f97\u5229\u6da6 = 5-1 = 4 \u3002\n\u00a0    \u968f\u540e\uff0c\u5728\u7b2c 4 \u5929\uff08\u80a1\u7968\u4ef7\u683c = 3\uff09\u7684\u65f6\u5019\u4e70\u5165\uff0c\u5728\u7b2c 5 \u5929\uff08\u80a1\u7968\u4ef7\u683c = 6\uff09\u7684\u65f6\u5019\u5356\u51fa, \u8fd9\u7b14\u4ea4\u6613\u6240\u80fd\u83b7\u5f97\u5229\u6da6 = 6-3 = 3 \u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: prices = [1,2,3,4,5]\n\u8f93\u51fa: 4\n\u89e3\u91ca: \u5728\u7b2c 1 \u5929\uff08\u80a1\u7968\u4ef7\u683c = 1\uff09\u7684\u65f6\u5019\u4e70\u5165\uff0c\u5728\u7b2c 5 \u5929 \uff08\u80a1\u7968\u4ef7\u683c = 5\uff09\u7684\u65f6\u5019\u5356\u51fa, \u8fd9\u7b14\u4ea4\u6613\u6240\u80fd\u83b7\u5f97\u5229\u6da6 = 5-1 = 4 \u3002\n\u00a0    \u6ce8\u610f\u4f60\u4e0d\u80fd\u5728\u7b2c 1 \u5929\u548c\u7b2c 2 \u5929\u63a5\u8fde\u8d2d\u4e70\u80a1\u7968\uff0c\u4e4b\u540e\u518d\u5c06\u5b83\u4eec\u5356\u51fa\u3002\u56e0\u4e3a\u8fd9\u6837\u5c5e\u4e8e\u540c\u65f6\u53c2\u4e0e\u4e86\u591a\u7b14\u4ea4\u6613\uff0c\u4f60\u5fc5\u987b\u5728\u518d\u6b21\u8d2d\u4e70\u524d\u51fa\u552e\u6389\u4e4b\u524d\u7684\u80a1\u7968\u3002\n
    \n\n

    \u793a\u4f8b\u00a03:

    \n\n
    \n\u8f93\u5165: prices = [7,6,4,3,1]\n\u8f93\u51fa: 0\n\u89e3\u91ca: \u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b, \u6ca1\u6709\u4ea4\u6613\u5b8c\u6210, \u6240\u4ee5\u6700\u5927\u5229\u6da6\u4e3a 0\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= prices.length <= 3 * 104
    • \n\t
    • 0 <= prices[i] <= 104
    • \n
    \n", "tags_en": ["Greedy", "Array"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxProfit(vector& prices) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxProfit(int[] prices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxProfit(self, prices):\n \"\"\"\n :type prices: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxProfit(self, prices: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxProfit(int* prices, int pricesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxProfit(int[] prices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} prices\n * @return {number}\n */\nvar maxProfit = function(prices) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} prices\n# @return {Integer}\ndef max_profit(prices)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxProfit(_ prices: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxProfit(prices []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxProfit(prices: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxProfit(prices: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_profit(prices: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $prices\n * @return Integer\n */\n function maxProfit($prices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxProfit(prices: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-profit prices)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0122](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-ii)", "[\u4e70\u5356\u80a1\u7968\u7684\u6700\u4f73\u65f6\u673a II](/solution/0100-0199/0122.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20II/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0122](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii)", "[Best Time to Buy and Sell Stock II](/solution/0100-0199/0122.Best%20Time%20to%20Buy%20and%20Sell%20Stock%20II/README_EN.md)", "`Greedy`,`Array`", "Easy", ""]}, {"question_id": "0121", "frontend_question_id": "0121", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock", "url_en": "https://leetcode.com/problems/best-time-to-buy-and-sell-stock", "relative_path_cn": "/solution/0100-0199/0121.Best%20Time%20to%20Buy%20and%20Sell%20Stock/README.md", "relative_path_en": "/solution/0100-0199/0121.Best%20Time%20to%20Buy%20and%20Sell%20Stock/README_EN.md", "title_cn": "\u4e70\u5356\u80a1\u7968\u7684\u6700\u4f73\u65f6\u673a", "title_en": "Best Time to Buy and Sell Stock", "question_title_slug": "best-time-to-buy-and-sell-stock", "content_en": "

    You are given an array prices where prices[i] is the price of a given stock on the ith day.

    \n\n

    You want to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to sell that stock.

    \n\n

    Return the maximum profit you can achieve from this transaction. If you cannot achieve any profit, return 0.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: prices = [7,1,5,3,6,4]\nOutput: 5\nExplanation: Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6-1 = 5.\nNote that buying on day 2 and selling on day 1 is not allowed because you must buy before you sell.\n
    \n\n

    Example 2:

    \n\n
    \nInput: prices = [7,6,4,3,1]\nOutput: 0\nExplanation: In this case, no transactions are done and the max profit = 0.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= prices.length <= 105
    • \n\t
    • 0 <= prices[i] <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6570\u7ec4 prices \uff0c\u5b83\u7684\u7b2c\u00a0i \u4e2a\u5143\u7d20\u00a0prices[i] \u8868\u793a\u4e00\u652f\u7ed9\u5b9a\u80a1\u7968\u7b2c i \u5929\u7684\u4ef7\u683c\u3002

    \n\n

    \u4f60\u53ea\u80fd\u9009\u62e9 \u67d0\u4e00\u5929 \u4e70\u5165\u8fd9\u53ea\u80a1\u7968\uff0c\u5e76\u9009\u62e9\u5728 \u672a\u6765\u7684\u67d0\u4e00\u4e2a\u4e0d\u540c\u7684\u65e5\u5b50 \u5356\u51fa\u8be5\u80a1\u7968\u3002\u8bbe\u8ba1\u4e00\u4e2a\u7b97\u6cd5\u6765\u8ba1\u7b97\u4f60\u6240\u80fd\u83b7\u53d6\u7684\u6700\u5927\u5229\u6da6\u3002

    \n\n

    \u8fd4\u56de\u4f60\u53ef\u4ee5\u4ece\u8fd9\u7b14\u4ea4\u6613\u4e2d\u83b7\u53d6\u7684\u6700\u5927\u5229\u6da6\u3002\u5982\u679c\u4f60\u4e0d\u80fd\u83b7\u53d6\u4efb\u4f55\u5229\u6da6\uff0c\u8fd4\u56de 0 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1a[7,1,5,3,6,4]\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\u5728\u7b2c 2 \u5929\uff08\u80a1\u7968\u4ef7\u683c = 1\uff09\u7684\u65f6\u5019\u4e70\u5165\uff0c\u5728\u7b2c 5 \u5929\uff08\u80a1\u7968\u4ef7\u683c = 6\uff09\u7684\u65f6\u5019\u5356\u51fa\uff0c\u6700\u5927\u5229\u6da6 = 6-1 = 5 \u3002\n     \u6ce8\u610f\u5229\u6da6\u4e0d\u80fd\u662f 7-1 = 6, \u56e0\u4e3a\u5356\u51fa\u4ef7\u683c\u9700\u8981\u5927\u4e8e\u4e70\u5165\u4ef7\u683c\uff1b\u540c\u65f6\uff0c\u4f60\u4e0d\u80fd\u5728\u4e70\u5165\u524d\u5356\u51fa\u80a1\u7968\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aprices = [7,6,4,3,1]\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b, \u6ca1\u6709\u4ea4\u6613\u5b8c\u6210, \u6240\u4ee5\u6700\u5927\u5229\u6da6\u4e3a 0\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= prices.length <= 105
    • \n\t
    • 0 <= prices[i] <= 104
    • \n
    \n", "tags_en": ["Array", "Dynamic Programming"], "tags_cn": ["\u6570\u7ec4", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxProfit(vector& prices) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxProfit(int[] prices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxProfit(self, prices):\n \"\"\"\n :type prices: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxProfit(self, prices: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxProfit(int* prices, int pricesSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxProfit(int[] prices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} prices\n * @return {number}\n */\nvar maxProfit = function(prices) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} prices\n# @return {Integer}\ndef max_profit(prices)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxProfit(_ prices: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxProfit(prices []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxProfit(prices: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxProfit(prices: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_profit(prices: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $prices\n * @return Integer\n */\n function maxProfit($prices) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxProfit(prices: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-profit prices)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0121](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock)", "[\u4e70\u5356\u80a1\u7968\u7684\u6700\u4f73\u65f6\u673a](/solution/0100-0199/0121.Best%20Time%20to%20Buy%20and%20Sell%20Stock/README.md)", "`\u6570\u7ec4`,`\u52a8\u6001\u89c4\u5212`", "\u7b80\u5355", ""], "md_table_row_en": ["[0121](https://leetcode.com/problems/best-time-to-buy-and-sell-stock)", "[Best Time to Buy and Sell Stock](/solution/0100-0199/0121.Best%20Time%20to%20Buy%20and%20Sell%20Stock/README_EN.md)", "`Array`,`Dynamic Programming`", "Easy", ""]}, {"question_id": "0120", "frontend_question_id": "0120", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/triangle", "url_en": "https://leetcode.com/problems/triangle", "relative_path_cn": "/solution/0100-0199/0120.Triangle/README.md", "relative_path_en": "/solution/0100-0199/0120.Triangle/README_EN.md", "title_cn": "\u4e09\u89d2\u5f62\u6700\u5c0f\u8def\u5f84\u548c", "title_en": "Triangle", "question_title_slug": "triangle", "content_en": "

    Given a triangle array, return the minimum path sum from top to bottom.

    \n\n

    For each step, you may move to an adjacent number of the row below. More formally, if you are on index i on the current row, you may move to either index i or index i + 1 on the next row.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: triangle = [[2],[3,4],[6,5,7],[4,1,8,3]]\nOutput: 11\nExplanation: The triangle looks like:\n   2\n  3 4\n 6 5 7\n4 1 8 3\nThe minimum path sum from top to bottom is 2 + 3 + 5 + 1 = 11 (underlined above).\n
    \n\n

    Example 2:

    \n\n
    \nInput: triangle = [[-10]]\nOutput: -10\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= triangle.length <= 200
    • \n\t
    • triangle[0].length == 1
    • \n\t
    • triangle[i].length == triangle[i - 1].length + 1
    • \n\t
    • -104 <= triangle[i][j] <= 104
    • \n
    \n\n

     

    \nFollow up: Could you do this using only O(n) extra space, where n is the total number of rows in the triangle?", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e09\u89d2\u5f62 triangle \uff0c\u627e\u51fa\u81ea\u9876\u5411\u4e0b\u7684\u6700\u5c0f\u8def\u5f84\u548c\u3002

    \n\n

    \u6bcf\u4e00\u6b65\u53ea\u80fd\u79fb\u52a8\u5230\u4e0b\u4e00\u884c\u4e2d\u76f8\u90bb\u7684\u7ed3\u70b9\u4e0a\u3002\u76f8\u90bb\u7684\u7ed3\u70b9 \u5728\u8fd9\u91cc\u6307\u7684\u662f \u4e0b\u6807 \u4e0e \u4e0a\u4e00\u5c42\u7ed3\u70b9\u4e0b\u6807 \u76f8\u540c\u6216\u8005\u7b49\u4e8e \u4e0a\u4e00\u5c42\u7ed3\u70b9\u4e0b\u6807 + 1 \u7684\u4e24\u4e2a\u7ed3\u70b9\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u5982\u679c\u6b63\u4f4d\u4e8e\u5f53\u524d\u884c\u7684\u4e0b\u6807 i \uff0c\u90a3\u4e48\u4e0b\u4e00\u6b65\u53ef\u4ee5\u79fb\u52a8\u5230\u4e0b\u4e00\u884c\u7684\u4e0b\u6807 i \u6216 i + 1 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1atriangle = [[2],[3,4],[6,5,7],[4,1,8,3]]\n\u8f93\u51fa\uff1a11\n\u89e3\u91ca\uff1a\u5982\u4e0b\u9762\u7b80\u56fe\u6240\u793a\uff1a\n   2\n  3 4\n 6 5 7\n4 1 8 3\n\u81ea\u9876\u5411\u4e0b\u7684\u6700\u5c0f\u8def\u5f84\u548c\u4e3a\u00a011\uff08\u5373\uff0c2\u00a0+\u00a03\u00a0+\u00a05\u00a0+\u00a01\u00a0= 11\uff09\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1atriangle = [[-10]]\n\u8f93\u51fa\uff1a-10\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= triangle.length <= 200
    • \n\t
    • triangle[0].length == 1
    • \n\t
    • triangle[i].length == triangle[i - 1].length + 1
    • \n\t
    • -104 <= triangle[i][j] <= 104
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u4f60\u53ef\u4ee5\u53ea\u4f7f\u7528 O(n)\u00a0\u7684\u989d\u5916\u7a7a\u95f4\uff08n \u4e3a\u4e09\u89d2\u5f62\u7684\u603b\u884c\u6570\uff09\u6765\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u5417\uff1f
    • \n
    \n", "tags_en": ["Array", "Dynamic Programming"], "tags_cn": ["\u6570\u7ec4", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minimumTotal(vector>& triangle) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minimumTotal(List> triangle) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minimumTotal(self, triangle):\n \"\"\"\n :type triangle: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minimumTotal(self, triangle: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minimumTotal(int** triangle, int triangleSize, int* triangleColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinimumTotal(IList> triangle) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} triangle\n * @return {number}\n */\nvar minimumTotal = function(triangle) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} triangle\n# @return {Integer}\ndef minimum_total(triangle)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minimumTotal(_ triangle: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minimumTotal(triangle [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minimumTotal(triangle: List[List[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minimumTotal(triangle: List>): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn minimum_total(triangle: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $triangle\n * @return Integer\n */\n function minimumTotal($triangle) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minimumTotal(triangle: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (minimum-total triangle)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0120](https://leetcode-cn.com/problems/triangle)", "[\u4e09\u89d2\u5f62\u6700\u5c0f\u8def\u5f84\u548c](/solution/0100-0199/0120.Triangle/README.md)", "`\u6570\u7ec4`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0120](https://leetcode.com/problems/triangle)", "[Triangle](/solution/0100-0199/0120.Triangle/README_EN.md)", "`Array`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0119", "frontend_question_id": "0119", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/pascals-triangle-ii", "url_en": "https://leetcode.com/problems/pascals-triangle-ii", "relative_path_cn": "/solution/0100-0199/0119.Pascal%27s%20Triangle%20II/README.md", "relative_path_en": "/solution/0100-0199/0119.Pascal%27s%20Triangle%20II/README_EN.md", "title_cn": "\u6768\u8f89\u4e09\u89d2 II", "title_en": "Pascal's Triangle II", "question_title_slug": "pascals-triangle-ii", "content_en": "

    Given an integer rowIndex, return the rowIndexth (0-indexed) row of the Pascal's triangle.

    \n\n

    In Pascal's triangle, each number is the sum of the two numbers directly above it as shown:

    \n\"\"\n

     

    \n

    Example 1:

    \n
    Input: rowIndex = 3\nOutput: [1,3,3,1]\n

    Example 2:

    \n
    Input: rowIndex = 0\nOutput: [1]\n

    Example 3:

    \n
    Input: rowIndex = 1\nOutput: [1,1]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= rowIndex <= 33
    • \n
    \n\n

     

    \n

    Follow up: Could you optimize your algorithm to use only O(rowIndex) extra space?

    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u8d1f\u7d22\u5f15 k\uff0c\u5176\u4e2d k ≤ 33\uff0c\u8fd4\u56de\u6768\u8f89\u4e09\u89d2\u7684\u7b2c k \u884c\u3002

    \n\n

    \"\"

    \n\n

    \u5728\u6768\u8f89\u4e09\u89d2\u4e2d\uff0c\u6bcf\u4e2a\u6570\u662f\u5b83\u5de6\u4e0a\u65b9\u548c\u53f3\u4e0a\u65b9\u7684\u6570\u7684\u548c\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: 3\n\u8f93\u51fa: [1,3,3,1]\n
    \n\n

    \u8fdb\u9636\uff1a

    \n\n

    \u4f60\u53ef\u4ee5\u4f18\u5316\u4f60\u7684\u7b97\u6cd5\u5230 O(k) \u7a7a\u95f4\u590d\u6742\u5ea6\u5417\uff1f

    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector getRow(int rowIndex) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List getRow(int rowIndex) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getRow(self, rowIndex):\n \"\"\"\n :type rowIndex: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getRow(self, rowIndex: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* getRow(int rowIndex, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList GetRow(int rowIndex) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} rowIndex\n * @return {number[]}\n */\nvar getRow = function(rowIndex) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} row_index\n# @return {Integer[]}\ndef get_row(row_index)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getRow(_ rowIndex: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getRow(rowIndex int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getRow(rowIndex: Int): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getRow(rowIndex: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_row(row_index: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $rowIndex\n * @return Integer[]\n */\n function getRow($rowIndex) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getRow(rowIndex: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-row rowIndex)\n (-> exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0119](https://leetcode-cn.com/problems/pascals-triangle-ii)", "[\u6768\u8f89\u4e09\u89d2 II](/solution/0100-0199/0119.Pascal%27s%20Triangle%20II/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0119](https://leetcode.com/problems/pascals-triangle-ii)", "[Pascal's Triangle II](/solution/0100-0199/0119.Pascal%27s%20Triangle%20II/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0118", "frontend_question_id": "0118", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/pascals-triangle", "url_en": "https://leetcode.com/problems/pascals-triangle", "relative_path_cn": "/solution/0100-0199/0118.Pascal%27s%20Triangle/README.md", "relative_path_en": "/solution/0100-0199/0118.Pascal%27s%20Triangle/README_EN.md", "title_cn": "\u6768\u8f89\u4e09\u89d2", "title_en": "Pascal's Triangle", "question_title_slug": "pascals-triangle", "content_en": "

    Given an integer numRows, return the first numRows of Pascal's triangle.

    \n\n

    In Pascal's triangle, each number is the sum of the two numbers directly above it as shown:

    \n\"\"\n

     

    \n

    Example 1:

    \n
    Input: numRows = 5\nOutput: [[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1]]\n

    Example 2:

    \n
    Input: numRows = 1\nOutput: [[1]]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= numRows <= 30
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u8d1f\u6574\u6570 numRows\uff0c\u751f\u6210\u6768\u8f89\u4e09\u89d2\u7684\u524d numRows \u884c\u3002

    \n\n

    \"\"

    \n\n

    \u5728\u6768\u8f89\u4e09\u89d2\u4e2d\uff0c\u6bcf\u4e2a\u6570\u662f\u5b83\u5de6\u4e0a\u65b9\u548c\u53f3\u4e0a\u65b9\u7684\u6570\u7684\u548c\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: 5\n\u8f93\u51fa:\n[\n     [1],\n    [1,1],\n   [1,2,1],\n  [1,3,3,1],\n [1,4,6,4,1]\n]
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> generate(int numRows) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> generate(int numRows) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def generate(self, numRows):\n \"\"\"\n :type numRows: int\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def generate(self, numRows: int) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** generate(int numRows, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> Generate(int numRows) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} numRows\n * @return {number[][]}\n */\nvar generate = function(numRows) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} num_rows\n# @return {Integer[][]}\ndef generate(num_rows)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func generate(_ numRows: Int) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func generate(numRows int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def generate(numRows: Int): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun generate(numRows: Int): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn generate(num_rows: i32) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $numRows\n * @return Integer[][]\n */\n function generate($numRows) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function generate(numRows: number): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (generate numRows)\n (-> exact-integer? (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0118](https://leetcode-cn.com/problems/pascals-triangle)", "[\u6768\u8f89\u4e09\u89d2](/solution/0100-0199/0118.Pascal%27s%20Triangle/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0118](https://leetcode.com/problems/pascals-triangle)", "[Pascal's Triangle](/solution/0100-0199/0118.Pascal%27s%20Triangle/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0117", "frontend_question_id": "0117", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/populating-next-right-pointers-in-each-node-ii", "url_en": "https://leetcode.com/problems/populating-next-right-pointers-in-each-node-ii", "relative_path_cn": "/solution/0100-0199/0117.Populating%20Next%20Right%20Pointers%20in%20Each%20Node%20II/README.md", "relative_path_en": "/solution/0100-0199/0117.Populating%20Next%20Right%20Pointers%20in%20Each%20Node%20II/README_EN.md", "title_cn": "\u586b\u5145\u6bcf\u4e2a\u8282\u70b9\u7684\u4e0b\u4e00\u4e2a\u53f3\u4fa7\u8282\u70b9\u6307\u9488 II", "title_en": "Populating Next Right Pointers in Each Node II", "question_title_slug": "populating-next-right-pointers-in-each-node-ii", "content_en": "

    Given a binary tree

    \r\n\r\n
    \r\nstruct Node {\r\n  int val;\r\n  Node *left;\r\n  Node *right;\r\n  Node *next;\r\n}\r\n
    \r\n\r\n

    Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL.

    \r\n\r\n

    Initially, all next pointers are set to NULL.

    \r\n\r\n

     

    \r\n\r\n

    Follow up:

    \r\n\r\n
      \r\n\t
    • You may only use constant extra space.
    • \r\n\t
    • Recursive approach is fine, you may assume implicit stack space does not count as extra space for this problem.
    • \r\n
    \r\n\n

     

    \n

    Example 1:

    \n\n

    \"\"

    \n\n
    \nInput: root = [1,2,3,4,5,null,7]\nOutput: [1,#,2,3,#,4,5,7,#]\nExplanation: Given the above binary tree (Figure A), your function should populate each next pointer to point to its next right node, just like in Figure B. The serialized output is in level order as connected by the next pointers, with '#' signifying the end of each level.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the given tree is less than 6000.
    • \n\t
    • -100 <= node.val <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811

    \n\n
    \nstruct Node {\n  int val;\n  Node *left;\n  Node *right;\n  Node *next;\n}
    \n\n

    \u586b\u5145\u5b83\u7684\u6bcf\u4e2a next \u6307\u9488\uff0c\u8ba9\u8fd9\u4e2a\u6307\u9488\u6307\u5411\u5176\u4e0b\u4e00\u4e2a\u53f3\u4fa7\u8282\u70b9\u3002\u5982\u679c\u627e\u4e0d\u5230\u4e0b\u4e00\u4e2a\u53f3\u4fa7\u8282\u70b9\uff0c\u5219\u5c06 next \u6307\u9488\u8bbe\u7f6e\u4e3a NULL\u3002

    \n\n

    \u521d\u59cb\u72b6\u6001\u4e0b\uff0c\u6240\u6709\u00a0next \u6307\u9488\u90fd\u88ab\u8bbe\u7f6e\u4e3a NULL\u3002

    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u4f60\u53ea\u80fd\u4f7f\u7528\u5e38\u91cf\u7ea7\u989d\u5916\u7a7a\u95f4\u3002
    • \n\t
    • \u4f7f\u7528\u9012\u5f52\u89e3\u9898\u4e5f\u7b26\u5408\u8981\u6c42\uff0c\u672c\u9898\u4e2d\u9012\u5f52\u7a0b\u5e8f\u5360\u7528\u7684\u6808\u7a7a\u95f4\u4e0d\u7b97\u505a\u989d\u5916\u7684\u7a7a\u95f4\u590d\u6742\u5ea6\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aroot = [1,2,3,4,5,null,7]\n\u8f93\u51fa\uff1a[1,#,2,3,#,4,5,7,#]\n\u89e3\u91ca\uff1a\u7ed9\u5b9a\u4e8c\u53c9\u6811\u5982\u56fe A \u6240\u793a\uff0c\u4f60\u7684\u51fd\u6570\u5e94\u8be5\u586b\u5145\u5b83\u7684\u6bcf\u4e2a next \u6307\u9488\uff0c\u4ee5\u6307\u5411\u5176\u4e0b\u4e00\u4e2a\u53f3\u4fa7\u8282\u70b9\uff0c\u5982\u56fe B \u6240\u793a\u3002\u5e8f\u5217\u5316\u8f93\u51fa\u6309\u5c42\u5e8f\u904d\u5386\u987a\u5e8f\uff08\u7531 next \u6307\u9488\u8fde\u63a5\uff09\uff0c'#' \u8868\u793a\u6bcf\u5c42\u7684\u672b\u5c3e\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u7684\u8282\u70b9\u6570\u5c0f\u4e8e 6000
    • \n\t
    • -100\u00a0<= node.val <= 100
    • \n
    \n\n

    \u00a0

    \n\n
      \n
    \n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* next;\n\n Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val, Node* _left, Node* _right, Node* _next)\n : val(_val), left(_left), right(_right), next(_next) {}\n};\n*/\n\nclass Solution {\npublic:\n Node* connect(Node* root) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/*\n// Definition for a Node.\nclass Node {\n public int val;\n public Node left;\n public Node right;\n public Node next;\n\n public Node() {}\n \n public Node(int _val) {\n val = _val;\n }\n\n public Node(int _val, Node _left, Node _right, Node _next) {\n val = _val;\n left = _left;\n right = _right;\n next = _next;\n }\n};\n*/\n\nclass Solution {\n public Node connect(Node root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "\"\"\"\n# Definition for a Node.\nclass Node(object):\n def __init__(self, val=0, left=None, right=None, next=None):\n self.val = val\n self.left = left\n self.right = right\n self.next = next\n\"\"\"\n\nclass Solution(object):\n def connect(self, root):\n \"\"\"\n :type root: Node\n :rtype: Node\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "\"\"\"\n# Definition for a Node.\nclass Node:\n def __init__(self, val: int = 0, left: 'Node' = None, right: 'Node' = None, next: 'Node' = None):\n self.val = val\n self.left = left\n self.right = right\n self.next = next\n\"\"\"\n\nclass Solution:\n def connect(self, root: 'Node') -> 'Node':\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a Node.\n * struct Node {\n * int val;\n * struct Node *left;\n * struct Node *right;\n * struct Node *next;\n * };\n */\n\nstruct Node* connect(struct Node* root) {\n\t\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/*\n// Definition for a Node.\npublic class Node {\n public int val;\n public Node left;\n public Node right;\n public Node next;\n\n public Node() {}\n\n public Node(int _val) {\n val = _val;\n }\n\n public Node(int _val, Node _left, Node _right, Node _next) {\n val = _val;\n left = _left;\n right = _right;\n next = _next;\n }\n}\n*/\n\npublic class Solution {\n public Node Connect(Node root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // Definition for a Node.\n * function Node(val, left, right, next) {\n * this.val = val === undefined ? null : val;\n * this.left = left === undefined ? null : left;\n * this.right = right === undefined ? null : right;\n * this.next = next === undefined ? null : next;\n * };\n */\n\n/**\n * @param {Node} root\n * @return {Node}\n */\nvar connect = function(root) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a Node.\n# class Node\n# attr_accessor :val, :left, :right, :next\n# def initialize(val)\n# @val = val\n# @left, @right, @next = nil, nil, nil\n# end\n# end\n\n# @param {Node} root\n# @return {Node}\ndef connect(root)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a Node.\n * public class Node {\n * public var val: Int\n * public var left: Node?\n * public var right: Node?\n *\t public var next: Node?\n * public init(_ val: Int) {\n * self.val = val\n * self.left = nil\n * self.right = nil\n * self.next = nil\n * }\n * }\n */\n\nclass Solution {\n func connect(_ root: Node?) -> Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a Node.\n * type Node struct {\n * Val int\n * Left *Node\n * Right *Node\n * Next *Node\n * }\n */\n\nfunc connect(root *Node) *Node {\n\t\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a Node.\n * class Node(var _value: Int) {\n * var value: Int = _value\n * var left: Node = null\n * var right: Node = null\n * var next: Node = null\n * }\n */\n\nobject Solution {\n def connect(root: Node): Node = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a Node.\n * class Node(var `val`: Int) {\n * var left: Node? = null\n * var right: Node? = null\n * var next: Node? = null\n * }\n */\n\nclass Solution {\n fun connect(root: Node?): Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a Node.\n * class Node {\n * function __construct($val = 0) {\n * $this->val = $val;\n * $this->left = null;\n * $this->right = null;\n * $this->next = null;\n * }\n * }\n */\n\nclass Solution {\n /**\n * @param Node $root\n * @return Node\n */\n public function connect($root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for Node.\n * class Node {\n * val: number\n * left: Node | null\n * right: Node | null\n * next: Node | null\n * constructor(val?: number, left?: Node, right?: Node, next?: Node) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction connect(root: Node | null): Node | null {\n \n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0117](https://leetcode-cn.com/problems/populating-next-right-pointers-in-each-node-ii)", "[\u586b\u5145\u6bcf\u4e2a\u8282\u70b9\u7684\u4e0b\u4e00\u4e2a\u53f3\u4fa7\u8282\u70b9\u6307\u9488 II](/solution/0100-0199/0117.Populating%20Next%20Right%20Pointers%20in%20Each%20Node%20II/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0117](https://leetcode.com/problems/populating-next-right-pointers-in-each-node-ii)", "[Populating Next Right Pointers in Each Node II](/solution/0100-0199/0117.Populating%20Next%20Right%20Pointers%20in%20Each%20Node%20II/README_EN.md)", "`Tree`,`Depth-first Search`", "Medium", ""]}, {"question_id": "0116", "frontend_question_id": "0116", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/populating-next-right-pointers-in-each-node", "url_en": "https://leetcode.com/problems/populating-next-right-pointers-in-each-node", "relative_path_cn": "/solution/0100-0199/0116.Populating%20Next%20Right%20Pointers%20in%20Each%20Node/README.md", "relative_path_en": "/solution/0100-0199/0116.Populating%20Next%20Right%20Pointers%20in%20Each%20Node/README_EN.md", "title_cn": "\u586b\u5145\u6bcf\u4e2a\u8282\u70b9\u7684\u4e0b\u4e00\u4e2a\u53f3\u4fa7\u8282\u70b9\u6307\u9488", "title_en": "Populating Next Right Pointers in Each Node", "question_title_slug": "populating-next-right-pointers-in-each-node", "content_en": "

    You are given a perfect binary tree where all leaves are on the same level, and every parent has two children. The binary tree has the following definition:

    \r\n\r\n
    \r\nstruct Node {\r\n  int val;\r\n  Node *left;\r\n  Node *right;\r\n  Node *next;\r\n}\r\n
    \r\n\r\n

    Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL.

    \r\n\r\n

    Initially, all next pointers are set to NULL.

    \r\n\r\n

     

    \r\n\r\n

    Follow up:

    \r\n\r\n
      \r\n\t
    • You may only use constant extra space.
    • \r\n\t
    • Recursive approach is fine, you may assume implicit stack space does not count as extra space for this problem.
    • \r\n
    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\r\n

    \"\"

    \r\n\r\n
    \r\nInput: root = [1,2,3,4,5,6,7]\r\nOutput: [1,#,2,3,#,4,5,6,7,#]\r\nExplanation: Given the above perfect binary tree (Figure A), your function should populate each next pointer to point to its next right node, just like in Figure B. The serialized output is in level order as connected by the next pointers, with '#' signifying the end of each level.\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • The number of nodes in the given tree is less than 4096.
    • \r\n\t
    • -1000 <= node.val <= 1000
    • \r\n
    ", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u00a0\u5b8c\u7f8e\u4e8c\u53c9\u6811\u00a0\uff0c\u5176\u6240\u6709\u53f6\u5b50\u8282\u70b9\u90fd\u5728\u540c\u4e00\u5c42\uff0c\u6bcf\u4e2a\u7236\u8282\u70b9\u90fd\u6709\u4e24\u4e2a\u5b50\u8282\u70b9\u3002\u4e8c\u53c9\u6811\u5b9a\u4e49\u5982\u4e0b\uff1a

    \n\n
    \nstruct Node {\n  int val;\n  Node *left;\n  Node *right;\n  Node *next;\n}
    \n\n

    \u586b\u5145\u5b83\u7684\u6bcf\u4e2a next \u6307\u9488\uff0c\u8ba9\u8fd9\u4e2a\u6307\u9488\u6307\u5411\u5176\u4e0b\u4e00\u4e2a\u53f3\u4fa7\u8282\u70b9\u3002\u5982\u679c\u627e\u4e0d\u5230\u4e0b\u4e00\u4e2a\u53f3\u4fa7\u8282\u70b9\uff0c\u5219\u5c06 next \u6307\u9488\u8bbe\u7f6e\u4e3a NULL\u3002

    \n\n

    \u521d\u59cb\u72b6\u6001\u4e0b\uff0c\u6240\u6709\u00a0next \u6307\u9488\u90fd\u88ab\u8bbe\u7f6e\u4e3a NULL\u3002

    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u4f60\u53ea\u80fd\u4f7f\u7528\u5e38\u91cf\u7ea7\u989d\u5916\u7a7a\u95f4\u3002
    • \n\t
    • \u4f7f\u7528\u9012\u5f52\u89e3\u9898\u4e5f\u7b26\u5408\u8981\u6c42\uff0c\u672c\u9898\u4e2d\u9012\u5f52\u7a0b\u5e8f\u5360\u7528\u7684\u6808\u7a7a\u95f4\u4e0d\u7b97\u505a\u989d\u5916\u7684\u7a7a\u95f4\u590d\u6742\u5ea6\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1aroot = [1,2,3,4,5,6,7]\n\u8f93\u51fa\uff1a[1,#,2,3,#,4,5,6,7,#]\n\u89e3\u91ca\uff1a\u7ed9\u5b9a\u4e8c\u53c9\u6811\u5982\u56fe A \u6240\u793a\uff0c\u4f60\u7684\u51fd\u6570\u5e94\u8be5\u586b\u5145\u5b83\u7684\u6bcf\u4e2a next \u6307\u9488\uff0c\u4ee5\u6307\u5411\u5176\u4e0b\u4e00\u4e2a\u53f3\u4fa7\u8282\u70b9\uff0c\u5982\u56fe B \u6240\u793a\u3002\u5e8f\u5217\u5316\u7684\u8f93\u51fa\u6309\u5c42\u5e8f\u904d\u5386\u6392\u5217\uff0c\u540c\u4e00\u5c42\u8282\u70b9\u7531 next \u6307\u9488\u8fde\u63a5\uff0c'#' \u6807\u5fd7\u7740\u6bcf\u4e00\u5c42\u7684\u7ed3\u675f\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u7684\u6570\u91cf\u5c11\u4e8e\u00a04096
    • \n\t
    • -1000 <= node.val <= 1000
    • \n
    \n", "tags_en": ["Tree", "Depth-first Search", "Breadth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* next;\n\n Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val, Node* _left, Node* _right, Node* _next)\n : val(_val), left(_left), right(_right), next(_next) {}\n};\n*/\n\nclass Solution {\npublic:\n Node* connect(Node* root) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/*\n// Definition for a Node.\nclass Node {\n public int val;\n public Node left;\n public Node right;\n public Node next;\n\n public Node() {}\n \n public Node(int _val) {\n val = _val;\n }\n\n public Node(int _val, Node _left, Node _right, Node _next) {\n val = _val;\n left = _left;\n right = _right;\n next = _next;\n }\n};\n*/\n\nclass Solution {\n public Node connect(Node root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "\"\"\"\n# Definition for a Node.\nclass Node(object):\n def __init__(self, val=0, left=None, right=None, next=None):\n self.val = val\n self.left = left\n self.right = right\n self.next = next\n\"\"\"\n\nclass Solution(object):\n def connect(self, root):\n \"\"\"\n :type root: Node\n :rtype: Node\n \"\"\"\n ", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "\"\"\"\n# Definition for a Node.\nclass Node:\n def __init__(self, val: int = 0, left: 'Node' = None, right: 'Node' = None, next: 'Node' = None):\n self.val = val\n self.left = left\n self.right = right\n self.next = next\n\"\"\"\n\nclass Solution:\n def connect(self, root: 'Node') -> 'Node':\n ", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a Node.\n * struct Node {\n * int val;\n * struct Node *left;\n * struct Node *right;\n * struct Node *next;\n * };\n */\n\nstruct Node* connect(struct Node* root) {\n\t\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/*\n// Definition for a Node.\npublic class Node {\n public int val;\n public Node left;\n public Node right;\n public Node next;\n\n public Node() {}\n\n public Node(int _val) {\n val = _val;\n }\n\n public Node(int _val, Node _left, Node _right, Node _next) {\n val = _val;\n left = _left;\n right = _right;\n next = _next;\n }\n}\n*/\n\npublic class Solution {\n public Node Connect(Node root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * // Definition for a Node.\n * function Node(val, left, right, next) {\n * this.val = val === undefined ? null : val;\n * this.left = left === undefined ? null : left;\n * this.right = right === undefined ? null : right;\n * this.next = next === undefined ? null : next;\n * };\n */\n\n/**\n * @param {Node} root\n * @return {Node}\n */\nvar connect = function(root) {\n \n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for Node.\n# class Node\n# attr_accessor :val, :left, :right, :next\n# def initialize(val)\n# @val = val\n# @left, @right, @next = nil, nil, nil\n# end\n# end\n\n# @param {Node} root\n# @return {Node}\ndef connect(root)\n \nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a Node.\n * public class Node {\n * public var val: Int\n * public var left: Node?\n * public var right: Node?\n *\t public var next: Node?\n * public init(_ val: Int) {\n * self.val = val\n * self.left = nil\n * self.right = nil\n * self.next = nil\n * }\n * }\n */\n\nclass Solution {\n func connect(_ root: Node?) -> Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a Node.\n * type Node struct {\n * Val int\n * Left *Node\n * Right *Node\n * Next *Node\n * }\n */\n\nfunc connect(root *Node) *Node {\n\t\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a Node.\n * class Node(var _value: Int) {\n * var value: Int = _value\n * var left: Node = null\n * var right: Node = null\n * var next: Node = null\n * }\n */\n\nobject Solution {\n def connect(root: Node): Node = {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Definition for a Node.\n * class Node(var `val`: Int) {\n * var left: Node? = null\n * var right: Node? = null\n * var next: Node? = null\n * }\n */\n\nclass Solution {\n fun connect(root: Node?): Node? {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a Node.\n * class Node {\n * function __construct($val = 0) {\n * $this->val = $val;\n * $this->left = null;\n * $this->right = null;\n * $this->next = null;\n * }\n * }\n */\n\nclass Solution {\n /**\n * @param Node $root\n * @return Node\n */\n public function connect($root) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for Node.\n * class Node {\n * val: number\n * left: Node | null\n * right: Node | null\n * next: Node | null\n * constructor(val?: number, left?: Node, right?: Node, next?: Node) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction connect(root: Node | null): Node | null {\n \n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0116](https://leetcode-cn.com/problems/populating-next-right-pointers-in-each-node)", "[\u586b\u5145\u6bcf\u4e2a\u8282\u70b9\u7684\u4e0b\u4e00\u4e2a\u53f3\u4fa7\u8282\u70b9\u6307\u9488](/solution/0100-0199/0116.Populating%20Next%20Right%20Pointers%20in%20Each%20Node/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0116](https://leetcode.com/problems/populating-next-right-pointers-in-each-node)", "[Populating Next Right Pointers in Each Node](/solution/0100-0199/0116.Populating%20Next%20Right%20Pointers%20in%20Each%20Node/README_EN.md)", "`Tree`,`Depth-first Search`,`Breadth-first Search`", "Medium", ""]}, {"question_id": "0115", "frontend_question_id": "0115", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/distinct-subsequences", "url_en": "https://leetcode.com/problems/distinct-subsequences", "relative_path_cn": "/solution/0100-0199/0115.Distinct%20Subsequences/README.md", "relative_path_en": "/solution/0100-0199/0115.Distinct%20Subsequences/README_EN.md", "title_cn": "\u4e0d\u540c\u7684\u5b50\u5e8f\u5217", "title_en": "Distinct Subsequences", "question_title_slug": "distinct-subsequences", "content_en": "

    Given two strings s and t, return the number of distinct subsequences of s which equals t.

    \n\n

    A string's subsequence is a new string formed from the original string by deleting some (can be none) of the characters without disturbing the remaining characters' relative positions. (i.e., "ACE" is a subsequence of "ABCDE" while "AEC" is not).

    \n\n

    It is guaranteed the answer fits on a 32-bit signed integer.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "rabbbit", t = "rabbit"\nOutput: 3\nExplanation:\nAs shown below, there are 3 ways you can generate "rabbit" from S.\nrabbbit\nrabbbit\nrabbbit\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "babgbag", t = "bag"\nOutput: 5\nExplanation:\nAs shown below, there are 5 ways you can generate "bag" from S.\nbabgbag\nbabgbag\nbabgbag\nbabgbag\nbabgbag
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length, t.length <= 1000
    • \n\t
    • s and t consist of English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32 s \u548c\u4e00\u4e2a\u5b57\u7b26\u4e32 t \uff0c\u8ba1\u7b97\u5728 s \u7684\u5b50\u5e8f\u5217\u4e2d t \u51fa\u73b0\u7684\u4e2a\u6570\u3002

    \n\n

    \u5b57\u7b26\u4e32\u7684\u4e00\u4e2a \u5b50\u5e8f\u5217 \u662f\u6307\uff0c\u901a\u8fc7\u5220\u9664\u4e00\u4e9b\uff08\u4e5f\u53ef\u4ee5\u4e0d\u5220\u9664\uff09\u5b57\u7b26\u4e14\u4e0d\u5e72\u6270\u5269\u4f59\u5b57\u7b26\u76f8\u5bf9\u4f4d\u7f6e\u6240\u7ec4\u6210\u7684\u65b0\u5b57\u7b26\u4e32\u3002\uff08\u4f8b\u5982\uff0c\"ACE\"\u00a0\u662f\u00a0\"ABCDE\"\u00a0\u7684\u4e00\u4e2a\u5b50\u5e8f\u5217\uff0c\u800c\u00a0\"AEC\"\u00a0\u4e0d\u662f\uff09

    \n\n

    \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u7b54\u6848\u7b26\u5408 32 \u4f4d\u5e26\u7b26\u53f7\u6574\u6570\u8303\u56f4\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\u00a01\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"rabbbit\", t = \"rabbit\"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\n\u5982\u4e0b\u56fe\u6240\u793a, \u6709 3 \u79cd\u53ef\u4ee5\u4ece s \u4e2d\u5f97\u5230 \"rabbit\" \u7684\u65b9\u6848\u3002\n(\u4e0a\u7bad\u5934\u7b26\u53f7 ^ \u8868\u793a\u9009\u53d6\u7684\u5b57\u6bcd)\nrabbbit\n^^^^ ^^\nrabbbit\n^^ ^^^^\nrabbbit\n^^^ ^^^\n
    \n\n

    \u793a\u4f8b\u00a02\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"babgbag\", t = \"bag\"\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\n\u5982\u4e0b\u56fe\u6240\u793a, \u6709 5 \u79cd\u53ef\u4ee5\u4ece s \u4e2d\u5f97\u5230 \"bag\" \u7684\u65b9\u6848\u3002 \n(\u4e0a\u7bad\u5934\u7b26\u53f7 ^ \u8868\u793a\u9009\u53d6\u7684\u5b57\u6bcd)\nbabgbag\n^^ ^\nbabgbag\n^^    ^\nbabgbag\n^    ^^\nbabgbag\n  ^  ^^\nbabgbag\n    ^^^
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= s.length, t.length <= 1000
    • \n\t
    • s \u548c t \u7531\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n", "tags_en": ["String", "Dynamic Programming"], "tags_cn": ["\u5b57\u7b26\u4e32", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numDistinct(string s, string t) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numDistinct(String s, String t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numDistinct(self, s, t):\n \"\"\"\n :type s: str\n :type t: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numDistinct(self, s: str, t: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numDistinct(char * s, char * t){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumDistinct(string s, string t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string} t\n * @return {number}\n */\nvar numDistinct = function(s, t) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String} t\n# @return {Integer}\ndef num_distinct(s, t)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numDistinct(_ s: String, _ t: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numDistinct(s string, t string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numDistinct(s: String, t: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numDistinct(s: String, t: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_distinct(s: String, t: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String $t\n * @return Integer\n */\n function numDistinct($s, $t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numDistinct(s: string, t: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-distinct s t)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0115](https://leetcode-cn.com/problems/distinct-subsequences)", "[\u4e0d\u540c\u7684\u5b50\u5e8f\u5217](/solution/0100-0199/0115.Distinct%20Subsequences/README.md)", "`\u5b57\u7b26\u4e32`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0115](https://leetcode.com/problems/distinct-subsequences)", "[Distinct Subsequences](/solution/0100-0199/0115.Distinct%20Subsequences/README_EN.md)", "`String`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0114", "frontend_question_id": "0114", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/flatten-binary-tree-to-linked-list", "url_en": "https://leetcode.com/problems/flatten-binary-tree-to-linked-list", "relative_path_cn": "/solution/0100-0199/0114.Flatten%20Binary%20Tree%20to%20Linked%20List/README.md", "relative_path_en": "/solution/0100-0199/0114.Flatten%20Binary%20Tree%20to%20Linked%20List/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u5c55\u5f00\u4e3a\u94fe\u8868", "title_en": "Flatten Binary Tree to Linked List", "question_title_slug": "flatten-binary-tree-to-linked-list", "content_en": "

    Given the root of a binary tree, flatten the tree into a "linked list":

    \n\n
      \n\t
    • The "linked list" should use the same TreeNode class where the right child pointer points to the next node in the list and the left child pointer is always null.
    • \n\t
    • The "linked list" should be in the same order as a pre-order traversal of the binary tree.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,2,5,3,4,null,6]\nOutput: [1,null,2,null,3,null,4,null,5,null,6]\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = []\nOutput: []\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = [0]\nOutput: [0]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [0, 2000].
    • \n\t
    • -100 <= Node.val <= 100
    • \n
    \n\n

     

    \nFollow up: Can you flatten the tree in-place (with O(1) extra space)?", "content_cn": "

    \u7ed9\u4f60\u4e8c\u53c9\u6811\u7684\u6839\u7ed3\u70b9 root \uff0c\u8bf7\u4f60\u5c06\u5b83\u5c55\u5f00\u4e3a\u4e00\u4e2a\u5355\u94fe\u8868\uff1a

    \n\n
      \n\t
    • \u5c55\u5f00\u540e\u7684\u5355\u94fe\u8868\u5e94\u8be5\u540c\u6837\u4f7f\u7528 TreeNode \uff0c\u5176\u4e2d right \u5b50\u6307\u9488\u6307\u5411\u94fe\u8868\u4e2d\u4e0b\u4e00\u4e2a\u7ed3\u70b9\uff0c\u800c\u5de6\u5b50\u6307\u9488\u59cb\u7ec8\u4e3a null \u3002
    • \n\t
    • \u5c55\u5f00\u540e\u7684\u5355\u94fe\u8868\u5e94\u8be5\u4e0e\u4e8c\u53c9\u6811 \u5148\u5e8f\u904d\u5386 \u987a\u5e8f\u76f8\u540c\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [1,2,5,3,4,null,6]\n\u8f93\u51fa\uff1a[1,null,2,null,3,null,4,null,5,null,6]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = []\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [0]\n\u8f93\u51fa\uff1a[0]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u7ed3\u70b9\u6570\u5728\u8303\u56f4 [0, 2000] \u5185
    • \n\t
    • -100 <= Node.val <= 100
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u53ef\u4ee5\u4f7f\u7528\u539f\u5730\u7b97\u6cd5\uff08O(1) \u989d\u5916\u7a7a\u95f4\uff09\u5c55\u5f00\u8fd9\u68f5\u6811\u5417\uff1f

    \n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n void flatten(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public void flatten(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def flatten(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: None Do not return anything, modify root in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def flatten(self, root: TreeNode) -> None:\n \"\"\"\n Do not return anything, modify root in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nvoid flatten(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public void Flatten(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {void} Do not return anything, modify root in-place instead.\n */\nvar flatten = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Void} Do not return anything, modify root in-place instead.\ndef flatten(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func flatten(_ root: TreeNode?) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc flatten(root *TreeNode) {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def flatten(root: TreeNode): Unit = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun flatten(root: TreeNode?): Unit {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn flatten(root: &mut Option>>) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return NULL\n */\n function flatten($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\n/**\n Do not return anything, modify root in-place instead.\n */\nfunction flatten(root: TreeNode | null): void {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (flatten root)\n (-> (or/c tree-node? #f) void?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0114](https://leetcode-cn.com/problems/flatten-binary-tree-to-linked-list)", "[\u4e8c\u53c9\u6811\u5c55\u5f00\u4e3a\u94fe\u8868](/solution/0100-0199/0114.Flatten%20Binary%20Tree%20to%20Linked%20List/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0114](https://leetcode.com/problems/flatten-binary-tree-to-linked-list)", "[Flatten Binary Tree to Linked List](/solution/0100-0199/0114.Flatten%20Binary%20Tree%20to%20Linked%20List/README_EN.md)", "`Tree`,`Depth-first Search`", "Medium", ""]}, {"question_id": "0113", "frontend_question_id": "0113", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/path-sum-ii", "url_en": "https://leetcode.com/problems/path-sum-ii", "relative_path_cn": "/solution/0100-0199/0113.Path%20Sum%20II/README.md", "relative_path_en": "/solution/0100-0199/0113.Path%20Sum%20II/README_EN.md", "title_cn": "\u8def\u5f84\u603b\u548c II", "title_en": "Path Sum II", "question_title_slug": "path-sum-ii", "content_en": "

    Given the root of a binary tree and an integer targetSum, return all root-to-leaf paths where each path's sum equals targetSum.

    \n\n

    A leaf is a node with no children.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [5,4,8,11,null,13,4,7,2,null,null,5,1], targetSum = 22\nOutput: [[5,4,11,2],[5,8,4,5]]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [1,2,3], targetSum = 5\nOutput: []\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = [1,2], targetSum = 0\nOutput: []\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [0, 5000].
    • \n\t
    • -1000 <= Node.val <= 1000
    • \n\t
    • -1000 <= targetSum <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9 root \u548c\u4e00\u4e2a\u6574\u6570\u76ee\u6807\u548c targetSum \uff0c\u627e\u51fa\u6240\u6709 \u4ece\u6839\u8282\u70b9\u5230\u53f6\u5b50\u8282\u70b9 \u8def\u5f84\u603b\u548c\u7b49\u4e8e\u7ed9\u5b9a\u76ee\u6807\u548c\u7684\u8def\u5f84\u3002

    \n\n

    \u53f6\u5b50\u8282\u70b9 \u662f\u6307\u6ca1\u6709\u5b50\u8282\u70b9\u7684\u8282\u70b9\u3002

    \n\n
    \n
    \n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [5,4,8,11,null,13,4,7,2,null,null,5,1], targetSum = 22\n\u8f93\u51fa\uff1a[[5,4,11,2],[5,8,4,5]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [1,2,3], targetSum = 5\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [1,2], targetSum = 0\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u603b\u6570\u5728\u8303\u56f4 [0, 5000] \u5185
    • \n\t
    • -1000 <= Node.val <= 1000
    • \n\t
    • -1000 <= targetSum <= 1000
    • \n
    \n
    \n
    \n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector> pathSum(TreeNode* root, int targetSum) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public List> pathSum(TreeNode root, int targetSum) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def pathSum(self, root, targetSum):\n \"\"\"\n :type root: TreeNode\n :type targetSum: int\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def pathSum(self, root: TreeNode, targetSum: int) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** pathSum(struct TreeNode* root, int targetSum, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public IList> PathSum(TreeNode root, int targetSum) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number} targetSum\n * @return {number[][]}\n */\nvar pathSum = function(root, targetSum) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @param {Integer} target_sum\n# @return {Integer[][]}\ndef path_sum(root, target_sum)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func pathSum(_ root: TreeNode?, _ targetSum: Int) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc pathSum(root *TreeNode, targetSum int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def pathSum(root: TreeNode, targetSum: Int): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun pathSum(root: TreeNode?, targetSum: Int): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn path_sum(root: Option>>, target_sum: i32) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param Integer $targetSum\n * @return Integer[][]\n */\n function pathSum($root, $targetSum) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction pathSum(root: TreeNode | null, targetSum: number): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (path-sum root targetSum)\n (-> (or/c tree-node? #f) exact-integer? (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0113](https://leetcode-cn.com/problems/path-sum-ii)", "[\u8def\u5f84\u603b\u548c II](/solution/0100-0199/0113.Path%20Sum%20II/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0113](https://leetcode.com/problems/path-sum-ii)", "[Path Sum II](/solution/0100-0199/0113.Path%20Sum%20II/README_EN.md)", "`Tree`,`Depth-first Search`", "Medium", ""]}, {"question_id": "0112", "frontend_question_id": "0112", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/path-sum", "url_en": "https://leetcode.com/problems/path-sum", "relative_path_cn": "/solution/0100-0199/0112.Path%20Sum/README.md", "relative_path_en": "/solution/0100-0199/0112.Path%20Sum/README_EN.md", "title_cn": "\u8def\u5f84\u603b\u548c", "title_en": "Path Sum", "question_title_slug": "path-sum", "content_en": "

    Given the root of a binary tree and an integer targetSum, return true if the tree has a root-to-leaf path such that adding up all the values along the path equals targetSum.

    \n\n

    A leaf is a node with no children.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [5,4,8,11,null,13,4,7,2,null,null,null,1], targetSum = 22\nOutput: true\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [1,2,3], targetSum = 5\nOutput: false\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = [1,2], targetSum = 0\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [0, 5000].
    • \n\t
    • -1000 <= Node.val <= 1000
    • \n\t
    • -1000 <= targetSum <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9\u00a0root \u548c\u4e00\u4e2a\u8868\u793a\u76ee\u6807\u548c\u7684\u6574\u6570\u00a0targetSum \uff0c\u5224\u65ad\u8be5\u6811\u4e2d\u662f\u5426\u5b58\u5728 \u6839\u8282\u70b9\u5230\u53f6\u5b50\u8282\u70b9 \u7684\u8def\u5f84\uff0c\u8fd9\u6761\u8def\u5f84\u4e0a\u6240\u6709\u8282\u70b9\u503c\u76f8\u52a0\u7b49\u4e8e\u76ee\u6807\u548c\u00a0targetSum \u3002

    \n\n

    \u53f6\u5b50\u8282\u70b9 \u662f\u6307\u6ca1\u6709\u5b50\u8282\u70b9\u7684\u8282\u70b9\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [5,4,8,11,null,13,4,7,2,null,null,null,1], targetSum = 22\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [1,2,3], targetSum = 5\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [1,2], targetSum = 0\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u7684\u6570\u76ee\u5728\u8303\u56f4 [0, 5000] \u5185
    • \n\t
    • -1000 <= Node.val <= 1000
    • \n\t
    • -1000 <= targetSum <= 1000
    • \n
    \n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n bool hasPathSum(TreeNode* root, int targetSum) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public boolean hasPathSum(TreeNode root, int targetSum) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def hasPathSum(self, root, targetSum):\n \"\"\"\n :type root: TreeNode\n :type targetSum: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def hasPathSum(self, root: TreeNode, targetSum: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nbool hasPathSum(struct TreeNode* root, int targetSum){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public bool HasPathSum(TreeNode root, int targetSum) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number} targetSum\n * @return {boolean}\n */\nvar hasPathSum = function(root, targetSum) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @param {Integer} target_sum\n# @return {Boolean}\ndef has_path_sum(root, target_sum)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func hasPathSum(_ root: TreeNode?, _ targetSum: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc hasPathSum(root *TreeNode, targetSum int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def hasPathSum(root: TreeNode, targetSum: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun hasPathSum(root: TreeNode?, targetSum: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn has_path_sum(root: Option>>, target_sum: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @param Integer $targetSum\n * @return Boolean\n */\n function hasPathSum($root, $targetSum) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction hasPathSum(root: TreeNode | null, targetSum: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (has-path-sum root targetSum)\n (-> (or/c tree-node? #f) exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0112](https://leetcode-cn.com/problems/path-sum)", "[\u8def\u5f84\u603b\u548c](/solution/0100-0199/0112.Path%20Sum/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u7b80\u5355", ""], "md_table_row_en": ["[0112](https://leetcode.com/problems/path-sum)", "[Path Sum](/solution/0100-0199/0112.Path%20Sum/README_EN.md)", "`Tree`,`Depth-first Search`", "Easy", ""]}, {"question_id": "0111", "frontend_question_id": "0111", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-depth-of-binary-tree", "url_en": "https://leetcode.com/problems/minimum-depth-of-binary-tree", "relative_path_cn": "/solution/0100-0199/0111.Minimum%20Depth%20of%20Binary%20Tree/README.md", "relative_path_en": "/solution/0100-0199/0111.Minimum%20Depth%20of%20Binary%20Tree/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u7684\u6700\u5c0f\u6df1\u5ea6", "title_en": "Minimum Depth of Binary Tree", "question_title_slug": "minimum-depth-of-binary-tree", "content_en": "

    Given a binary tree, find its minimum depth.

    \n\n

    The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.

    \n\n

    Note: A leaf is a node with no children.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [3,9,20,null,null,15,7]\nOutput: 2\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = [2,null,3,null,4,null,5,null,6]\nOutput: 5\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [0, 105].
    • \n\t
    • -1000 <= Node.val <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811\uff0c\u627e\u51fa\u5176\u6700\u5c0f\u6df1\u5ea6\u3002

    \n\n

    \u6700\u5c0f\u6df1\u5ea6\u662f\u4ece\u6839\u8282\u70b9\u5230\u6700\u8fd1\u53f6\u5b50\u8282\u70b9\u7684\u6700\u77ed\u8def\u5f84\u4e0a\u7684\u8282\u70b9\u6570\u91cf\u3002

    \n\n

    \u8bf4\u660e\uff1a\u53f6\u5b50\u8282\u70b9\u662f\u6307\u6ca1\u6709\u5b50\u8282\u70b9\u7684\u8282\u70b9\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [3,9,20,null,null,15,7]\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [2,null,3,null,4,null,5,null,6]\n\u8f93\u51fa\uff1a5\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u6570\u7684\u8303\u56f4\u5728 [0, 105] \u5185
    • \n\t
    • -1000 <= Node.val <= 1000
    • \n
    \n", "tags_en": ["Tree", "Depth-first Search", "Breadth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int minDepth(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int minDepth(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def minDepth(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def minDepth(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint minDepth(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int MinDepth(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar minDepth = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef min_depth(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func minDepth(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc minDepth(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def minDepth(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun minDepth(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn min_depth(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function minDepth($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction minDepth(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (min-depth root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0111](https://leetcode-cn.com/problems/minimum-depth-of-binary-tree)", "[\u4e8c\u53c9\u6811\u7684\u6700\u5c0f\u6df1\u5ea6](/solution/0100-0199/0111.Minimum%20Depth%20of%20Binary%20Tree/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u7b80\u5355", ""], "md_table_row_en": ["[0111](https://leetcode.com/problems/minimum-depth-of-binary-tree)", "[Minimum Depth of Binary Tree](/solution/0100-0199/0111.Minimum%20Depth%20of%20Binary%20Tree/README_EN.md)", "`Tree`,`Depth-first Search`,`Breadth-first Search`", "Easy", ""]}, {"question_id": "0110", "frontend_question_id": "0110", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/balanced-binary-tree", "url_en": "https://leetcode.com/problems/balanced-binary-tree", "relative_path_cn": "/solution/0100-0199/0110.Balanced%20Binary%20Tree/README.md", "relative_path_en": "/solution/0100-0199/0110.Balanced%20Binary%20Tree/README_EN.md", "title_cn": "\u5e73\u8861\u4e8c\u53c9\u6811", "title_en": "Balanced Binary Tree", "question_title_slug": "balanced-binary-tree", "content_en": "

    Given a binary tree, determine if it is height-balanced.

    \n\n

    For this problem, a height-balanced binary tree is defined as:

    \n\n
    \n

    a binary tree in which the left and right subtrees of every node differ in height by no more than 1.

    \n
    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [3,9,20,null,null,15,7]\nOutput: true\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [1,2,2,3,3,null,null,4,4]\nOutput: false\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = []\nOutput: true\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [0, 5000].
    • \n\t
    • -104 <= Node.val <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811\uff0c\u5224\u65ad\u5b83\u662f\u5426\u662f\u9ad8\u5ea6\u5e73\u8861\u7684\u4e8c\u53c9\u6811\u3002

    \n\n

    \u672c\u9898\u4e2d\uff0c\u4e00\u68f5\u9ad8\u5ea6\u5e73\u8861\u4e8c\u53c9\u6811\u5b9a\u4e49\u4e3a\uff1a

    \n\n
    \n

    \u4e00\u4e2a\u4e8c\u53c9\u6811\u6bcf\u4e2a\u8282\u70b9\u00a0\u7684\u5de6\u53f3\u4e24\u4e2a\u5b50\u6811\u7684\u9ad8\u5ea6\u5dee\u7684\u7edd\u5bf9\u503c\u4e0d\u8d85\u8fc7 1 \u3002

    \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [3,9,20,null,null,15,7]\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [1,2,2,3,3,null,null,4,4]\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = []\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u7684\u8282\u70b9\u6570\u5728\u8303\u56f4 [0, 5000] \u5185
    • \n\t
    • -104 <= Node.val <= 104
    • \n
    \n", "tags_en": ["Tree", "Depth-first Search", "Recursion"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u9012\u5f52"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n bool isBalanced(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public boolean isBalanced(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def isBalanced(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def isBalanced(self, root: TreeNode) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nbool isBalanced(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public bool IsBalanced(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {boolean}\n */\nvar isBalanced = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Boolean}\ndef is_balanced(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func isBalanced(_ root: TreeNode?) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc isBalanced(root *TreeNode) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def isBalanced(root: TreeNode): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun isBalanced(root: TreeNode?): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn is_balanced(root: Option>>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Boolean\n */\n function isBalanced($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction isBalanced(root: TreeNode | null): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (is-balanced root)\n (-> (or/c tree-node? #f) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0110](https://leetcode-cn.com/problems/balanced-binary-tree)", "[\u5e73\u8861\u4e8c\u53c9\u6811](/solution/0100-0199/0110.Balanced%20Binary%20Tree/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u9012\u5f52`", "\u7b80\u5355", ""], "md_table_row_en": ["[0110](https://leetcode.com/problems/balanced-binary-tree)", "[Balanced Binary Tree](/solution/0100-0199/0110.Balanced%20Binary%20Tree/README_EN.md)", "`Tree`,`Depth-first Search`,`Recursion`", "Easy", ""]}, {"question_id": "0109", "frontend_question_id": "0109", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/convert-sorted-list-to-binary-search-tree", "url_en": "https://leetcode.com/problems/convert-sorted-list-to-binary-search-tree", "relative_path_cn": "/solution/0100-0199/0109.Convert%20Sorted%20List%20to%20Binary%20Search%20Tree/README.md", "relative_path_en": "/solution/0100-0199/0109.Convert%20Sorted%20List%20to%20Binary%20Search%20Tree/README_EN.md", "title_cn": "\u6709\u5e8f\u94fe\u8868\u8f6c\u6362\u4e8c\u53c9\u641c\u7d22\u6811", "title_en": "Convert Sorted List to Binary Search Tree", "question_title_slug": "convert-sorted-list-to-binary-search-tree", "content_en": "

    Given the head of a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.

    \n\n

    For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: head = [-10,-3,0,5,9]\nOutput: [0,-3,9,-10,null,5]\nExplanation: One possible answer is [0,-3,9,-10,null,5], which represents the shown height balanced BST.\n
    \n\n

    Example 2:

    \n\n
    \nInput: head = []\nOutput: []\n
    \n\n

    Example 3:

    \n\n
    \nInput: head = [0]\nOutput: [0]\n
    \n\n

    Example 4:

    \n\n
    \nInput: head = [1,3]\nOutput: [3,1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in head is in the range [0, 2 * 104].
    • \n\t
    • -105 <= Node.val <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5355\u94fe\u8868\uff0c\u5176\u4e2d\u7684\u5143\u7d20\u6309\u5347\u5e8f\u6392\u5e8f\uff0c\u5c06\u5176\u8f6c\u6362\u4e3a\u9ad8\u5ea6\u5e73\u8861\u7684\u4e8c\u53c9\u641c\u7d22\u6811\u3002

    \n\n

    \u672c\u9898\u4e2d\uff0c\u4e00\u4e2a\u9ad8\u5ea6\u5e73\u8861\u4e8c\u53c9\u6811\u662f\u6307\u4e00\u4e2a\u4e8c\u53c9\u6811\u6bcf\u4e2a\u8282\u70b9 \u7684\u5de6\u53f3\u4e24\u4e2a\u5b50\u6811\u7684\u9ad8\u5ea6\u5dee\u7684\u7edd\u5bf9\u503c\u4e0d\u8d85\u8fc7 1\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u7ed9\u5b9a\u7684\u6709\u5e8f\u94fe\u8868\uff1a [-10, -3, 0, 5, 9],\n\n\u4e00\u4e2a\u53ef\u80fd\u7684\u7b54\u6848\u662f\uff1a[0, -3, 9, -10, null, 5], \u5b83\u53ef\u4ee5\u8868\u793a\u4e0b\u9762\u8fd9\u4e2a\u9ad8\u5ea6\u5e73\u8861\u4e8c\u53c9\u641c\u7d22\u6811\uff1a\n\n      0\n     / \\\n   -3   9\n   /   /\n -10  5\n
    \n", "tags_en": ["Depth-first Search", "Linked List"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u94fe\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* sortedListToBST(ListNode* head) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode sortedListToBST(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\n# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def sortedListToBST(self, head):\n \"\"\"\n :type head: ListNode\n :rtype: TreeNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\n# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def sortedListToBST(self, head: ListNode) -> TreeNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* sortedListToBST(struct ListNode* head){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode SortedListToBST(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {ListNode} head\n * @return {TreeNode}\n */\nvar sortedListToBST = function(head) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {ListNode} head\n# @return {TreeNode}\ndef sorted_list_to_bst(head)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func sortedListToBST(_ head: ListNode?) -> TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\n/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc sortedListToBST(head *ListNode) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\n/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def sortedListToBST(head: ListNode): TreeNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\n/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun sortedListToBST(head: ListNode?): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\n// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn sorted_list_to_bst(head: Option>) -> Option>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\n/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @return TreeNode\n */\n function sortedListToBST($head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\n/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction sortedListToBST(head: ListNode | null): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (sorted-list-to-bst head)\n (-> (or/c list-node? #f) (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0109](https://leetcode-cn.com/problems/convert-sorted-list-to-binary-search-tree)", "[\u6709\u5e8f\u94fe\u8868\u8f6c\u6362\u4e8c\u53c9\u641c\u7d22\u6811](/solution/0100-0199/0109.Convert%20Sorted%20List%20to%20Binary%20Search%20Tree/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u94fe\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0109](https://leetcode.com/problems/convert-sorted-list-to-binary-search-tree)", "[Convert Sorted List to Binary Search Tree](/solution/0100-0199/0109.Convert%20Sorted%20List%20to%20Binary%20Search%20Tree/README_EN.md)", "`Depth-first Search`,`Linked List`", "Medium", ""]}, {"question_id": "0108", "frontend_question_id": "0108", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/convert-sorted-array-to-binary-search-tree", "url_en": "https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree", "relative_path_cn": "/solution/0100-0199/0108.Convert%20Sorted%20Array%20to%20Binary%20Search%20Tree/README.md", "relative_path_en": "/solution/0100-0199/0108.Convert%20Sorted%20Array%20to%20Binary%20Search%20Tree/README_EN.md", "title_cn": "\u5c06\u6709\u5e8f\u6570\u7ec4\u8f6c\u6362\u4e3a\u4e8c\u53c9\u641c\u7d22\u6811", "title_en": "Convert Sorted Array to Binary Search Tree", "question_title_slug": "convert-sorted-array-to-binary-search-tree", "content_en": "

    Given an integer array nums where the elements are sorted in ascending order, convert it to a height-balanced binary search tree.

    \n\n

    A height-balanced binary tree is a binary tree in which the depth of the two subtrees of every node never differs by more than one.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: nums = [-10,-3,0,5,9]\nOutput: [0,-3,9,-10,null,5]\nExplanation: [0,-10,5,null,-3,null,9] is also accepted:\n\"\"\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: nums = [1,3]\nOutput: [3,1]\nExplanation: [1,3] and [3,1] are both a height-balanced BSTs.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 104
    • \n\t
    • -104 <= nums[i] <= 104
    • \n\t
    • nums is sorted in a strictly increasing order.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \uff0c\u5176\u4e2d\u5143\u7d20\u5df2\u7ecf\u6309 \u5347\u5e8f \u6392\u5217\uff0c\u8bf7\u4f60\u5c06\u5176\u8f6c\u6362\u4e3a\u4e00\u68f5 \u9ad8\u5ea6\u5e73\u8861 \u4e8c\u53c9\u641c\u7d22\u6811\u3002

    \n\n

    \u9ad8\u5ea6\u5e73\u8861 \u4e8c\u53c9\u6811\u662f\u4e00\u68f5\u6ee1\u8db3\u300c\u6bcf\u4e2a\u8282\u70b9\u7684\u5de6\u53f3\u4e24\u4e2a\u5b50\u6811\u7684\u9ad8\u5ea6\u5dee\u7684\u7edd\u5bf9\u503c\u4e0d\u8d85\u8fc7 1 \u300d\u7684\u4e8c\u53c9\u6811\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1anums = [-10,-3,0,5,9]\n\u8f93\u51fa\uff1a[0,-3,9,-10,null,5]\n\u89e3\u91ca\uff1a[0,-10,5,null,-3,null,9] \u4e5f\u5c06\u88ab\u89c6\u4e3a\u6b63\u786e\u7b54\u6848\uff1a\n\"\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1anums = [1,3]\n\u8f93\u51fa\uff1a[3,1]\n\u89e3\u91ca\uff1a[1,3] \u548c [3,1] \u90fd\u662f\u9ad8\u5ea6\u5e73\u8861\u4e8c\u53c9\u641c\u7d22\u6811\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 104
    • \n\t
    • -104 <= nums[i] <= 104
    • \n\t
    • nums \u6309 \u4e25\u683c\u9012\u589e \u987a\u5e8f\u6392\u5217
    • \n
    \n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* sortedArrayToBST(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode sortedArrayToBST(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def sortedArrayToBST(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: TreeNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def sortedArrayToBST(self, nums: List[int]) -> TreeNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* sortedArrayToBST(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode SortedArrayToBST(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {number[]} nums\n * @return {TreeNode}\n */\nvar sortedArrayToBST = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {Integer[]} nums\n# @return {TreeNode}\ndef sorted_array_to_bst(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func sortedArrayToBST(_ nums: [Int]) -> TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc sortedArrayToBST(nums []int) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def sortedArrayToBST(nums: Array[Int]): TreeNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun sortedArrayToBST(nums: IntArray): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn sorted_array_to_bst(nums: Vec) -> Option>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param Integer[] $nums\n * @return TreeNode\n */\n function sortedArrayToBST($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction sortedArrayToBST(nums: number[]): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (sorted-array-to-bst nums)\n (-> (listof exact-integer?) (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0108](https://leetcode-cn.com/problems/convert-sorted-array-to-binary-search-tree)", "[\u5c06\u6709\u5e8f\u6570\u7ec4\u8f6c\u6362\u4e3a\u4e8c\u53c9\u641c\u7d22\u6811](/solution/0100-0199/0108.Convert%20Sorted%20Array%20to%20Binary%20Search%20Tree/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u7b80\u5355", ""], "md_table_row_en": ["[0108](https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree)", "[Convert Sorted Array to Binary Search Tree](/solution/0100-0199/0108.Convert%20Sorted%20Array%20to%20Binary%20Search%20Tree/README_EN.md)", "`Tree`,`Depth-first Search`", "Easy", ""]}, {"question_id": "0107", "frontend_question_id": "0107", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/binary-tree-level-order-traversal-ii", "url_en": "https://leetcode.com/problems/binary-tree-level-order-traversal-ii", "relative_path_cn": "/solution/0100-0199/0107.Binary%20Tree%20Level%20Order%20Traversal%20II/README.md", "relative_path_en": "/solution/0100-0199/0107.Binary%20Tree%20Level%20Order%20Traversal%20II/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u7684\u5c42\u5e8f\u904d\u5386 II", "title_en": "Binary Tree Level Order Traversal II", "question_title_slug": "binary-tree-level-order-traversal-ii", "content_en": "

    Given the root of a binary tree, return the bottom-up level order traversal of its nodes' values. (i.e., from left to right, level by level from leaf to root).

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [3,9,20,null,null,15,7]\nOutput: [[15,7],[9,20],[3]]\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = [1]\nOutput: [[1]]\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = []\nOutput: []\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [0, 2000].
    • \n\t
    • -1000 <= Node.val <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811\uff0c\u8fd4\u56de\u5176\u8282\u70b9\u503c\u81ea\u5e95\u5411\u4e0a\u7684\u5c42\u5e8f\u904d\u5386\u3002 \uff08\u5373\u6309\u4ece\u53f6\u5b50\u8282\u70b9\u6240\u5728\u5c42\u5230\u6839\u8282\u70b9\u6240\u5728\u7684\u5c42\uff0c\u9010\u5c42\u4ece\u5de6\u5411\u53f3\u904d\u5386\uff09

    \n\n

    \u4f8b\u5982\uff1a
    \n\u7ed9\u5b9a\u4e8c\u53c9\u6811 [3,9,20,null,null,15,7],

    \n\n
    \n    3\n   / \\\n  9  20\n    /  \\\n   15   7\n
    \n\n

    \u8fd4\u56de\u5176\u81ea\u5e95\u5411\u4e0a\u7684\u5c42\u5e8f\u904d\u5386\u4e3a\uff1a

    \n\n
    \n[\n  [15,7],\n  [9,20],\n  [3]\n]\n
    \n", "tags_en": ["Tree", "Breadth-first Search"], "tags_cn": ["\u6811", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector> levelOrderBottom(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public List> levelOrderBottom(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def levelOrderBottom(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def levelOrderBottom(self, root: TreeNode) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** levelOrderBottom(struct TreeNode* root, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public IList> LevelOrderBottom(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number[][]}\n */\nvar levelOrderBottom = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer[][]}\ndef level_order_bottom(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func levelOrderBottom(_ root: TreeNode?) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc levelOrderBottom(root *TreeNode) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def levelOrderBottom(root: TreeNode): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun levelOrderBottom(root: TreeNode?): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn level_order_bottom(root: Option>>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer[][]\n */\n function levelOrderBottom($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction levelOrderBottom(root: TreeNode | null): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (level-order-bottom root)\n (-> (or/c tree-node? #f) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0107](https://leetcode-cn.com/problems/binary-tree-level-order-traversal-ii)", "[\u4e8c\u53c9\u6811\u7684\u5c42\u5e8f\u904d\u5386 II](/solution/0100-0199/0107.Binary%20Tree%20Level%20Order%20Traversal%20II/README.md)", "`\u6811`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0107](https://leetcode.com/problems/binary-tree-level-order-traversal-ii)", "[Binary Tree Level Order Traversal II](/solution/0100-0199/0107.Binary%20Tree%20Level%20Order%20Traversal%20II/README_EN.md)", "`Tree`,`Breadth-first Search`", "Medium", ""]}, {"question_id": "0106", "frontend_question_id": "0106", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal", "url_en": "https://leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal", "relative_path_cn": "/solution/0100-0199/0106.Construct%20Binary%20Tree%20from%20Inorder%20and%20Postorder%20Traversal/README.md", "relative_path_en": "/solution/0100-0199/0106.Construct%20Binary%20Tree%20from%20Inorder%20and%20Postorder%20Traversal/README_EN.md", "title_cn": "\u4ece\u4e2d\u5e8f\u4e0e\u540e\u5e8f\u904d\u5386\u5e8f\u5217\u6784\u9020\u4e8c\u53c9\u6811", "title_en": "Construct Binary Tree from Inorder and Postorder Traversal", "question_title_slug": "construct-binary-tree-from-inorder-and-postorder-traversal", "content_en": "

    Given two integer arrays inorder and postorder where inorder is the inorder traversal of a binary tree and postorder is the postorder traversal of the same tree, construct and return the binary tree.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: inorder = [9,3,15,20,7], postorder = [9,15,7,20,3]\nOutput: [3,9,20,null,null,15,7]\n
    \n\n

    Example 2:

    \n\n
    \nInput: inorder = [-1], postorder = [-1]\nOutput: [-1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= inorder.length <= 3000
    • \n\t
    • postorder.length == inorder.length
    • \n\t
    • -3000 <= inorder[i], postorder[i] <= 3000
    • \n\t
    • inorder and postorder consist of unique values.
    • \n\t
    • Each value of postorder also appears in inorder.
    • \n\t
    • inorder is guaranteed to be the inorder traversal of the tree.
    • \n\t
    • postorder is guaranteed to be the postorder traversal of the tree.
    • \n
    \n", "content_cn": "

    \u6839\u636e\u4e00\u68f5\u6811\u7684\u4e2d\u5e8f\u904d\u5386\u4e0e\u540e\u5e8f\u904d\u5386\u6784\u9020\u4e8c\u53c9\u6811\u3002

    \n\n

    \u6ce8\u610f:
    \n\u4f60\u53ef\u4ee5\u5047\u8bbe\u6811\u4e2d\u6ca1\u6709\u91cd\u590d\u7684\u5143\u7d20\u3002

    \n\n

    \u4f8b\u5982\uff0c\u7ed9\u51fa

    \n\n
    \u4e2d\u5e8f\u904d\u5386 inorder = [9,3,15,20,7]\n\u540e\u5e8f\u904d\u5386 postorder = [9,15,7,20,3]
    \n\n

    \u8fd4\u56de\u5982\u4e0b\u7684\u4e8c\u53c9\u6811\uff1a

    \n\n
        3\n   / \\\n  9  20\n    /  \\\n   15   7\n
    \n", "tags_en": ["Tree", "Depth-first Search", "Array"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* buildTree(vector& inorder, vector& postorder) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode buildTree(int[] inorder, int[] postorder) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def buildTree(self, inorder, postorder):\n \"\"\"\n :type inorder: List[int]\n :type postorder: List[int]\n :rtype: TreeNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def buildTree(self, inorder: List[int], postorder: List[int]) -> TreeNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* buildTree(int* inorder, int inorderSize, int* postorder, int postorderSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode BuildTree(int[] inorder, int[] postorder) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {number[]} inorder\n * @param {number[]} postorder\n * @return {TreeNode}\n */\nvar buildTree = function(inorder, postorder) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {Integer[]} inorder\n# @param {Integer[]} postorder\n# @return {TreeNode}\ndef build_tree(inorder, postorder)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func buildTree(_ inorder: [Int], _ postorder: [Int]) -> TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc buildTree(inorder []int, postorder []int) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def buildTree(inorder: Array[Int], postorder: Array[Int]): TreeNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun buildTree(inorder: IntArray, postorder: IntArray): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn build_tree(inorder: Vec, postorder: Vec) -> Option>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param Integer[] $inorder\n * @param Integer[] $postorder\n * @return TreeNode\n */\n function buildTree($inorder, $postorder) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction buildTree(inorder: number[], postorder: number[]): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (build-tree inorder postorder)\n (-> (listof exact-integer?) (listof exact-integer?) (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0106](https://leetcode-cn.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal)", "[\u4ece\u4e2d\u5e8f\u4e0e\u540e\u5e8f\u904d\u5386\u5e8f\u5217\u6784\u9020\u4e8c\u53c9\u6811](/solution/0100-0199/0106.Construct%20Binary%20Tree%20from%20Inorder%20and%20Postorder%20Traversal/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0106](https://leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal)", "[Construct Binary Tree from Inorder and Postorder Traversal](/solution/0100-0199/0106.Construct%20Binary%20Tree%20from%20Inorder%20and%20Postorder%20Traversal/README_EN.md)", "`Tree`,`Depth-first Search`,`Array`", "Medium", ""]}, {"question_id": "0105", "frontend_question_id": "0105", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal", "url_en": "https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal", "relative_path_cn": "/solution/0100-0199/0105.Construct%20Binary%20Tree%20from%20Preorder%20and%20Inorder%20Traversal/README.md", "relative_path_en": "/solution/0100-0199/0105.Construct%20Binary%20Tree%20from%20Preorder%20and%20Inorder%20Traversal/README_EN.md", "title_cn": "\u4ece\u524d\u5e8f\u4e0e\u4e2d\u5e8f\u904d\u5386\u5e8f\u5217\u6784\u9020\u4e8c\u53c9\u6811", "title_en": "Construct Binary Tree from Preorder and Inorder Traversal", "question_title_slug": "construct-binary-tree-from-preorder-and-inorder-traversal", "content_en": "

    Given two integer arrays preorder and inorder where preorder is the preorder traversal of a binary tree and inorder is the inorder traversal of the same tree, construct and return the binary tree.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: preorder = [3,9,20,15,7], inorder = [9,3,15,20,7]\nOutput: [3,9,20,null,null,15,7]\n
    \n\n

    Example 2:

    \n\n
    \nInput: preorder = [-1], inorder = [-1]\nOutput: [-1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= preorder.length <= 3000
    • \n\t
    • inorder.length == preorder.length
    • \n\t
    • -3000 <= preorder[i], inorder[i] <= 3000
    • \n\t
    • preorder and inorder consist of unique values.
    • \n\t
    • Each value of inorder also appears in preorder.
    • \n\t
    • preorder is guaranteed to be the preorder traversal of the tree.
    • \n\t
    • inorder is guaranteed to be the inorder traversal of the tree.
    • \n
    \n", "content_cn": "

    \u6839\u636e\u4e00\u68f5\u6811\u7684\u524d\u5e8f\u904d\u5386\u4e0e\u4e2d\u5e8f\u904d\u5386\u6784\u9020\u4e8c\u53c9\u6811\u3002

    \n\n

    \u6ce8\u610f:
    \n\u4f60\u53ef\u4ee5\u5047\u8bbe\u6811\u4e2d\u6ca1\u6709\u91cd\u590d\u7684\u5143\u7d20\u3002

    \n\n

    \u4f8b\u5982\uff0c\u7ed9\u51fa

    \n\n
    \u524d\u5e8f\u904d\u5386 preorder = [3,9,20,15,7]\n\u4e2d\u5e8f\u904d\u5386 inorder = [9,3,15,20,7]
    \n\n

    \u8fd4\u56de\u5982\u4e0b\u7684\u4e8c\u53c9\u6811\uff1a

    \n\n
        3\n   / \\\n  9  20\n    /  \\\n   15   7
    \n", "tags_en": ["Tree", "Depth-first Search", "Array"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* buildTree(vector& preorder, vector& inorder) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public TreeNode buildTree(int[] preorder, int[] inorder) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def buildTree(self, preorder, inorder):\n \"\"\"\n :type preorder: List[int]\n :type inorder: List[int]\n :rtype: TreeNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def buildTree(self, preorder: List[int], inorder: List[int]) -> TreeNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nstruct TreeNode* buildTree(int* preorder, int preorderSize, int* inorder, int inorderSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public TreeNode BuildTree(int[] preorder, int[] inorder) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {number[]} preorder\n * @param {number[]} inorder\n * @return {TreeNode}\n */\nvar buildTree = function(preorder, inorder) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {Integer[]} preorder\n# @param {Integer[]} inorder\n# @return {TreeNode}\ndef build_tree(preorder, inorder)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func buildTree(_ preorder: [Int], _ inorder: [Int]) -> TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc buildTree(preorder []int, inorder []int) *TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def buildTree(preorder: Array[Int], inorder: Array[Int]): TreeNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun buildTree(preorder: IntArray, inorder: IntArray): TreeNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn build_tree(preorder: Vec, inorder: Vec) -> Option>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param Integer[] $preorder\n * @param Integer[] $inorder\n * @return TreeNode\n */\n function buildTree($preorder, $inorder) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction buildTree(preorder: number[], inorder: number[]): TreeNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (build-tree preorder inorder)\n (-> (listof exact-integer?) (listof exact-integer?) (or/c tree-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0105](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal)", "[\u4ece\u524d\u5e8f\u4e0e\u4e2d\u5e8f\u904d\u5386\u5e8f\u5217\u6784\u9020\u4e8c\u53c9\u6811](/solution/0100-0199/0105.Construct%20Binary%20Tree%20from%20Preorder%20and%20Inorder%20Traversal/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0105](https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal)", "[Construct Binary Tree from Preorder and Inorder Traversal](/solution/0100-0199/0105.Construct%20Binary%20Tree%20from%20Preorder%20and%20Inorder%20Traversal/README_EN.md)", "`Tree`,`Depth-first Search`,`Array`", "Medium", ""]}, {"question_id": "0104", "frontend_question_id": "0104", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-depth-of-binary-tree", "url_en": "https://leetcode.com/problems/maximum-depth-of-binary-tree", "relative_path_cn": "/solution/0100-0199/0104.Maximum%20Depth%20of%20Binary%20Tree/README.md", "relative_path_en": "/solution/0100-0199/0104.Maximum%20Depth%20of%20Binary%20Tree/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u7684\u6700\u5927\u6df1\u5ea6", "title_en": "Maximum Depth of Binary Tree", "question_title_slug": "maximum-depth-of-binary-tree", "content_en": "

    Given the root of a binary tree, return its maximum depth.

    \r\n\r\n

    A binary tree's maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.

    \r\n\r\n

     

    \r\n

    Example 1:

    \r\n\"\"\r\n
    \r\nInput: root = [3,9,20,null,null,15,7]\r\nOutput: 3\r\n
    \r\n\r\n

    Example 2:

    \r\n\r\n
    \r\nInput: root = [1,null,2]\r\nOutput: 2\r\n
    \r\n\r\n

    Example 3:

    \r\n\r\n
    \r\nInput: root = []\r\nOutput: 0\r\n
    \r\n\r\n

    Example 4:

    \r\n\r\n
    \r\nInput: root = [0]\r\nOutput: 1\r\n
    \r\n\r\n

     

    \r\n

    Constraints:

    \r\n\r\n
      \r\n\t
    • The number of nodes in the tree is in the range [0, 104].
    • \r\n\t
    • -100 <= Node.val <= 100
    • \r\n
    ", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811\uff0c\u627e\u51fa\u5176\u6700\u5927\u6df1\u5ea6\u3002

    \n\n

    \u4e8c\u53c9\u6811\u7684\u6df1\u5ea6\u4e3a\u6839\u8282\u70b9\u5230\u6700\u8fdc\u53f6\u5b50\u8282\u70b9\u7684\u6700\u957f\u8def\u5f84\u4e0a\u7684\u8282\u70b9\u6570\u3002

    \n\n

    \u8bf4\u660e: \u53f6\u5b50\u8282\u70b9\u662f\u6307\u6ca1\u6709\u5b50\u8282\u70b9\u7684\u8282\u70b9\u3002

    \n\n

    \u793a\u4f8b\uff1a
    \n\u7ed9\u5b9a\u4e8c\u53c9\u6811 [3,9,20,null,null,15,7]\uff0c

    \n\n
        3\n   / \\\n  9  20\n    /  \\\n   15   7
    \n\n

    \u8fd4\u56de\u5b83\u7684\u6700\u5927\u6df1\u5ea6 3 \u3002

    \n", "tags_en": ["Tree", "Depth-first Search", "Recursion"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u9012\u5f52"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int maxDepth(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public int maxDepth(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def maxDepth(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def maxDepth(self, root: TreeNode) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nint maxDepth(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public int MaxDepth(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar maxDepth = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer}\ndef max_depth(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func maxDepth(_ root: TreeNode?) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc maxDepth(root *TreeNode) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def maxDepth(root: TreeNode): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun maxDepth(root: TreeNode?): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn max_depth(root: Option>>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer\n */\n function maxDepth($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction maxDepth(root: TreeNode | null): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (max-depth root)\n (-> (or/c tree-node? #f) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0104](https://leetcode-cn.com/problems/maximum-depth-of-binary-tree)", "[\u4e8c\u53c9\u6811\u7684\u6700\u5927\u6df1\u5ea6](/solution/0100-0199/0104.Maximum%20Depth%20of%20Binary%20Tree/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u9012\u5f52`", "\u7b80\u5355", ""], "md_table_row_en": ["[0104](https://leetcode.com/problems/maximum-depth-of-binary-tree)", "[Maximum Depth of Binary Tree](/solution/0100-0199/0104.Maximum%20Depth%20of%20Binary%20Tree/README_EN.md)", "`Tree`,`Depth-first Search`,`Recursion`", "Easy", ""]}, {"question_id": "0103", "frontend_question_id": "0103", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/binary-tree-zigzag-level-order-traversal", "url_en": "https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal", "relative_path_cn": "/solution/0100-0199/0103.Binary%20Tree%20Zigzag%20Level%20Order%20Traversal/README.md", "relative_path_en": "/solution/0100-0199/0103.Binary%20Tree%20Zigzag%20Level%20Order%20Traversal/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u7684\u952f\u9f7f\u5f62\u5c42\u5e8f\u904d\u5386", "title_en": "Binary Tree Zigzag Level Order Traversal", "question_title_slug": "binary-tree-zigzag-level-order-traversal", "content_en": "

    Given the root of a binary tree, return the zigzag level order traversal of its nodes' values. (i.e., from left to right, then right to left for the next level and alternate between).

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [3,9,20,null,null,15,7]\nOutput: [[3],[20,9],[15,7]]\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = [1]\nOutput: [[1]]\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = []\nOutput: []\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [0, 2000].
    • \n\t
    • -100 <= Node.val <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811\uff0c\u8fd4\u56de\u5176\u8282\u70b9\u503c\u7684\u952f\u9f7f\u5f62\u5c42\u5e8f\u904d\u5386\u3002\uff08\u5373\u5148\u4ece\u5de6\u5f80\u53f3\uff0c\u518d\u4ece\u53f3\u5f80\u5de6\u8fdb\u884c\u4e0b\u4e00\u5c42\u904d\u5386\uff0c\u4ee5\u6b64\u7c7b\u63a8\uff0c\u5c42\u4e0e\u5c42\u4e4b\u95f4\u4ea4\u66ff\u8fdb\u884c\uff09\u3002

    \n\n

    \u4f8b\u5982\uff1a
    \n\u7ed9\u5b9a\u4e8c\u53c9\u6811\u00a0[3,9,20,null,null,15,7],

    \n\n
    \n    3\n   / \\\n  9  20\n    /  \\\n   15   7\n
    \n\n

    \u8fd4\u56de\u952f\u9f7f\u5f62\u5c42\u5e8f\u904d\u5386\u5982\u4e0b\uff1a

    \n\n
    \n[\n  [3],\n  [20,9],\n  [15,7]\n]\n
    \n", "tags_en": ["Stack", "Tree", "Breadth-first Search"], "tags_cn": ["\u6808", "\u6811", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector> zigzagLevelOrder(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public List> zigzagLevelOrder(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def zigzagLevelOrder(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def zigzagLevelOrder(self, root: TreeNode) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** zigzagLevelOrder(struct TreeNode* root, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public IList> ZigzagLevelOrder(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number[][]}\n */\nvar zigzagLevelOrder = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer[][]}\ndef zigzag_level_order(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func zigzagLevelOrder(_ root: TreeNode?) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc zigzagLevelOrder(root *TreeNode) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def zigzagLevelOrder(root: TreeNode): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun zigzagLevelOrder(root: TreeNode?): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn zigzag_level_order(root: Option>>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer[][]\n */\n function zigzagLevelOrder($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction zigzagLevelOrder(root: TreeNode | null): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (zigzag-level-order root)\n (-> (or/c tree-node? #f) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0103](https://leetcode-cn.com/problems/binary-tree-zigzag-level-order-traversal)", "[\u4e8c\u53c9\u6811\u7684\u952f\u9f7f\u5f62\u5c42\u5e8f\u904d\u5386](/solution/0100-0199/0103.Binary%20Tree%20Zigzag%20Level%20Order%20Traversal/README.md)", "`\u6808`,`\u6811`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0103](https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal)", "[Binary Tree Zigzag Level Order Traversal](/solution/0100-0199/0103.Binary%20Tree%20Zigzag%20Level%20Order%20Traversal/README_EN.md)", "`Stack`,`Tree`,`Breadth-first Search`", "Medium", ""]}, {"question_id": "0102", "frontend_question_id": "0102", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/binary-tree-level-order-traversal", "url_en": "https://leetcode.com/problems/binary-tree-level-order-traversal", "relative_path_cn": "/solution/0100-0199/0102.Binary%20Tree%20Level%20Order%20Traversal/README.md", "relative_path_en": "/solution/0100-0199/0102.Binary%20Tree%20Level%20Order%20Traversal/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u7684\u5c42\u5e8f\u904d\u5386", "title_en": "Binary Tree Level Order Traversal", "question_title_slug": "binary-tree-level-order-traversal", "content_en": "

    Given the root of a binary tree, return the level order traversal of its nodes' values. (i.e., from left to right, level by level).

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [3,9,20,null,null,15,7]\nOutput: [[3],[9,20],[15,7]]\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = [1]\nOutput: [[1]]\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = []\nOutput: []\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [0, 2000].
    • \n\t
    • -1000 <= Node.val <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u4e8c\u53c9\u6811\uff0c\u8bf7\u4f60\u8fd4\u56de\u5176\u6309 \u5c42\u5e8f\u904d\u5386 \u5f97\u5230\u7684\u8282\u70b9\u503c\u3002 \uff08\u5373\u9010\u5c42\u5730\uff0c\u4ece\u5de6\u5230\u53f3\u8bbf\u95ee\u6240\u6709\u8282\u70b9\uff09\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\uff1a
    \n\u4e8c\u53c9\u6811\uff1a[3,9,20,null,null,15,7],

    \n\n
    \n    3\n   / \\\n  9  20\n    /  \\\n   15   7\n
    \n\n

    \u8fd4\u56de\u5176\u5c42\u5e8f\u904d\u5386\u7ed3\u679c\uff1a

    \n\n
    \n[\n  [3],\n  [9,20],\n  [15,7]\n]\n
    \n", "tags_en": ["Tree", "Breadth-first Search"], "tags_cn": ["\u6811", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector> levelOrder(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public List> levelOrder(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def levelOrder(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def levelOrder(self, root: TreeNode) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** levelOrder(struct TreeNode* root, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public IList> LevelOrder(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number[][]}\n */\nvar levelOrder = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer[][]}\ndef level_order(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func levelOrder(_ root: TreeNode?) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc levelOrder(root *TreeNode) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def levelOrder(root: TreeNode): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun levelOrder(root: TreeNode?): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn level_order(root: Option>>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer[][]\n */\n function levelOrder($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction levelOrder(root: TreeNode | null): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (level-order root)\n (-> (or/c tree-node? #f) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0102](https://leetcode-cn.com/problems/binary-tree-level-order-traversal)", "[\u4e8c\u53c9\u6811\u7684\u5c42\u5e8f\u904d\u5386](/solution/0100-0199/0102.Binary%20Tree%20Level%20Order%20Traversal/README.md)", "`\u6811`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0102](https://leetcode.com/problems/binary-tree-level-order-traversal)", "[Binary Tree Level Order Traversal](/solution/0100-0199/0102.Binary%20Tree%20Level%20Order%20Traversal/README_EN.md)", "`Tree`,`Breadth-first Search`", "Medium", ""]}, {"question_id": "0101", "frontend_question_id": "0101", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/symmetric-tree", "url_en": "https://leetcode.com/problems/symmetric-tree", "relative_path_cn": "/solution/0100-0199/0101.Symmetric%20Tree/README.md", "relative_path_en": "/solution/0100-0199/0101.Symmetric%20Tree/README_EN.md", "title_cn": "\u5bf9\u79f0\u4e8c\u53c9\u6811", "title_en": "Symmetric Tree", "question_title_slug": "symmetric-tree", "content_en": "

    Given the root of a binary tree, check whether it is a mirror of itself (i.e., symmetric around its center).

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,2,2,3,4,4,3]\nOutput: true\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [1,2,2,null,3,null,3]\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 1000].
    • \n\t
    • -100 <= Node.val <= 100
    • \n
    \n\n

     

    \nFollow up: Could you solve it both recursively and iteratively?", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811\uff0c\u68c0\u67e5\u5b83\u662f\u5426\u662f\u955c\u50cf\u5bf9\u79f0\u7684\u3002

    \n\n

     

    \n\n

    \u4f8b\u5982\uff0c\u4e8c\u53c9\u6811 [1,2,2,3,4,4,3] \u662f\u5bf9\u79f0\u7684\u3002

    \n\n
        1\n   / \\\n  2   2\n / \\ / \\\n3  4 4  3\n
    \n\n

     

    \n\n

    \u4f46\u662f\u4e0b\u9762\u8fd9\u4e2a [1,2,2,null,3,null,3] \u5219\u4e0d\u662f\u955c\u50cf\u5bf9\u79f0\u7684:

    \n\n
        1\n   / \\\n  2   2\n   \\   \\\n   3    3\n
    \n\n

     

    \n\n

    \u8fdb\u9636\uff1a

    \n\n

    \u4f60\u53ef\u4ee5\u8fd0\u7528\u9012\u5f52\u548c\u8fed\u4ee3\u4e24\u79cd\u65b9\u6cd5\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u5417\uff1f

    \n", "tags_en": ["Tree", "Depth-first Search", "Breadth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n bool isSymmetric(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public boolean isSymmetric(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def isSymmetric(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def isSymmetric(self, root: TreeNode) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nbool isSymmetric(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public bool IsSymmetric(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {boolean}\n */\nvar isSymmetric = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Boolean}\ndef is_symmetric(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func isSymmetric(_ root: TreeNode?) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc isSymmetric(root *TreeNode) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def isSymmetric(root: TreeNode): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun isSymmetric(root: TreeNode?): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn is_symmetric(root: Option>>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Boolean\n */\n function isSymmetric($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction isSymmetric(root: TreeNode | null): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (is-symmetric root)\n (-> (or/c tree-node? #f) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0101](https://leetcode-cn.com/problems/symmetric-tree)", "[\u5bf9\u79f0\u4e8c\u53c9\u6811](/solution/0100-0199/0101.Symmetric%20Tree/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22`", "\u7b80\u5355", ""], "md_table_row_en": ["[0101](https://leetcode.com/problems/symmetric-tree)", "[Symmetric Tree](/solution/0100-0199/0101.Symmetric%20Tree/README_EN.md)", "`Tree`,`Depth-first Search`,`Breadth-first Search`", "Easy", ""]}, {"question_id": "0100", "frontend_question_id": "0100", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/same-tree", "url_en": "https://leetcode.com/problems/same-tree", "relative_path_cn": "/solution/0100-0199/0100.Same%20Tree/README.md", "relative_path_en": "/solution/0100-0199/0100.Same%20Tree/README_EN.md", "title_cn": "\u76f8\u540c\u7684\u6811", "title_en": "Same Tree", "question_title_slug": "same-tree", "content_en": "

    Given the roots of two binary trees p and q, write a function to check if they are the same or not.

    \n\n

    Two binary trees are considered the same if they are structurally identical, and the nodes have the same value.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: p = [1,2,3], q = [1,2,3]\nOutput: true\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: p = [1,2], q = [1,null,2]\nOutput: false\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: p = [1,2,1], q = [1,1,2]\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in both trees is in the range [0, 100].
    • \n\t
    • -104 <= Node.val <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u68f5\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9 p \u548c q \uff0c\u7f16\u5199\u4e00\u4e2a\u51fd\u6570\u6765\u68c0\u9a8c\u8fd9\u4e24\u68f5\u6811\u662f\u5426\u76f8\u540c\u3002

    \n\n

    \u5982\u679c\u4e24\u4e2a\u6811\u5728\u7ed3\u6784\u4e0a\u76f8\u540c\uff0c\u5e76\u4e14\u8282\u70b9\u5177\u6709\u76f8\u540c\u7684\u503c\uff0c\u5219\u8ba4\u4e3a\u5b83\u4eec\u662f\u76f8\u540c\u7684\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1ap = [1,2,3], q = [1,2,3]\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1ap = [1,2], q = [1,null,2]\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1ap = [1,2,1], q = [1,1,2]\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u4e24\u68f5\u6811\u4e0a\u7684\u8282\u70b9\u6570\u76ee\u90fd\u5728\u8303\u56f4 [0, 100] \u5185
    • \n\t
    • -104 <= Node.val <= 104
    • \n
    \n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n bool isSameTree(TreeNode* p, TreeNode* q) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public boolean isSameTree(TreeNode p, TreeNode q) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def isSameTree(self, p, q):\n \"\"\"\n :type p: TreeNode\n :type q: TreeNode\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def isSameTree(self, p: TreeNode, q: TreeNode) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nbool isSameTree(struct TreeNode* p, struct TreeNode* q){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public bool IsSameTree(TreeNode p, TreeNode q) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} p\n * @param {TreeNode} q\n * @return {boolean}\n */\nvar isSameTree = function(p, q) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} p\n# @param {TreeNode} q\n# @return {Boolean}\ndef is_same_tree(p, q)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func isSameTree(_ p: TreeNode?, _ q: TreeNode?) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc isSameTree(p *TreeNode, q *TreeNode) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def isSameTree(p: TreeNode, q: TreeNode): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun isSameTree(p: TreeNode?, q: TreeNode?): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn is_same_tree(p: Option>>, q: Option>>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $p\n * @param TreeNode $q\n * @return Boolean\n */\n function isSameTree($p, $q) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction isSameTree(p: TreeNode | null, q: TreeNode | null): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (is-same-tree p q)\n (-> (or/c tree-node? #f) (or/c tree-node? #f) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0100](https://leetcode-cn.com/problems/same-tree)", "[\u76f8\u540c\u7684\u6811](/solution/0100-0199/0100.Same%20Tree/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u7b80\u5355", ""], "md_table_row_en": ["[0100](https://leetcode.com/problems/same-tree)", "[Same Tree](/solution/0100-0199/0100.Same%20Tree/README_EN.md)", "`Tree`,`Depth-first Search`", "Easy", ""]}, {"question_id": "0099", "frontend_question_id": "0099", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/recover-binary-search-tree", "url_en": "https://leetcode.com/problems/recover-binary-search-tree", "relative_path_cn": "/solution/0000-0099/0099.Recover%20Binary%20Search%20Tree/README.md", "relative_path_en": "/solution/0000-0099/0099.Recover%20Binary%20Search%20Tree/README_EN.md", "title_cn": "\u6062\u590d\u4e8c\u53c9\u641c\u7d22\u6811", "title_en": "Recover Binary Search Tree", "question_title_slug": "recover-binary-search-tree", "content_en": "

    You are given the root of a binary search tree (BST), where exactly two nodes of the tree were swapped by mistake. Recover the tree without changing its structure.

    \n\n

    Follow up: A solution using O(n) space is pretty straight forward. Could you devise a constant space solution?

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,3,null,null,2]\nOutput: [3,1,null,null,2]\nExplanation: 3 cannot be a left child of 1 because 3 > 1. Swapping 1 and 3 makes the BST valid.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [3,1,4,null,null,2]\nOutput: [2,1,4,null,null,3]\nExplanation: 2 cannot be in the right subtree of 3 because 2 < 3. Swapping 2 and 3 makes the BST valid.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [2, 1000].
    • \n\t
    • -231 <= Node.val <= 231 - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6839\u8282\u70b9 root \uff0c\u8be5\u6811\u4e2d\u7684\u4e24\u4e2a\u8282\u70b9\u88ab\u9519\u8bef\u5730\u4ea4\u6362\u3002\u8bf7\u5728\u4e0d\u6539\u53d8\u5176\u7ed3\u6784\u7684\u60c5\u51b5\u4e0b\uff0c\u6062\u590d\u8fd9\u68f5\u6811\u3002

    \n\n

    \u8fdb\u9636\uff1a\u4f7f\u7528 O(n) \u7a7a\u95f4\u590d\u6742\u5ea6\u7684\u89e3\u6cd5\u5f88\u5bb9\u6613\u5b9e\u73b0\u3002\u4f60\u80fd\u60f3\u51fa\u4e00\u4e2a\u53ea\u4f7f\u7528\u5e38\u6570\u7a7a\u95f4\u7684\u89e3\u51b3\u65b9\u6848\u5417\uff1f

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [1,3,null,null,2]\n\u8f93\u51fa\uff1a[3,1,null,null,2]\n\u89e3\u91ca\uff1a3 \u4e0d\u80fd\u662f 1 \u5de6\u5b69\u5b50\uff0c\u56e0\u4e3a 3 > 1 \u3002\u4ea4\u6362 1 \u548c 3 \u4f7f\u4e8c\u53c9\u641c\u7d22\u6811\u6709\u6548\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [3,1,4,null,null,2]\n\u8f93\u51fa\uff1a[2,1,4,null,null,3]\n\u89e3\u91ca\uff1a2 \u4e0d\u80fd\u5728 3 \u7684\u53f3\u5b50\u6811\u4e2d\uff0c\u56e0\u4e3a 2 < 3 \u3002\u4ea4\u6362 2 \u548c 3 \u4f7f\u4e8c\u53c9\u641c\u7d22\u6811\u6709\u6548\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e0a\u8282\u70b9\u7684\u6570\u76ee\u5728\u8303\u56f4 [2, 1000] \u5185
    • \n\t
    • -231 <= Node.val <= 231 - 1
    • \n
    \n", "tags_en": ["Tree", "Depth-first Search"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n void recoverTree(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public void recoverTree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def recoverTree(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: None Do not return anything, modify root in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def recoverTree(self, root: TreeNode) -> None:\n \"\"\"\n Do not return anything, modify root in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nvoid recoverTree(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public void RecoverTree(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {void} Do not return anything, modify root in-place instead.\n */\nvar recoverTree = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Void} Do not return anything, modify root in-place instead.\ndef recover_tree(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func recoverTree(_ root: TreeNode?) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc recoverTree(root *TreeNode) {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def recoverTree(root: TreeNode): Unit = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun recoverTree(root: TreeNode?): Unit {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn recover_tree(root: &mut Option>>) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return NULL\n */\n function recoverTree($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\n/**\n Do not return anything, modify root in-place instead.\n */\nfunction recoverTree(root: TreeNode | null): void {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (recover-tree root)\n (-> (or/c tree-node? #f) void?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0099](https://leetcode-cn.com/problems/recover-binary-search-tree)", "[\u6062\u590d\u4e8c\u53c9\u641c\u7d22\u6811](/solution/0000-0099/0099.Recover%20Binary%20Search%20Tree/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`", "\u56f0\u96be", ""], "md_table_row_en": ["[0099](https://leetcode.com/problems/recover-binary-search-tree)", "[Recover Binary Search Tree](/solution/0000-0099/0099.Recover%20Binary%20Search%20Tree/README_EN.md)", "`Tree`,`Depth-first Search`", "Hard", ""]}, {"question_id": "0098", "frontend_question_id": "0098", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/validate-binary-search-tree", "url_en": "https://leetcode.com/problems/validate-binary-search-tree", "relative_path_cn": "/solution/0000-0099/0098.Validate%20Binary%20Search%20Tree/README.md", "relative_path_en": "/solution/0000-0099/0098.Validate%20Binary%20Search%20Tree/README_EN.md", "title_cn": "\u9a8c\u8bc1\u4e8c\u53c9\u641c\u7d22\u6811", "title_en": "Validate Binary Search Tree", "question_title_slug": "validate-binary-search-tree", "content_en": "

    Given the root of a binary tree, determine if it is a valid binary search tree (BST).

    \n\n

    A valid BST is defined as follows:

    \n\n
      \n\t
    • The left subtree of a node contains only nodes with keys less than the node's key.
    • \n\t
    • The right subtree of a node contains only nodes with keys greater than the node's key.
    • \n\t
    • Both the left and right subtrees must also be binary search trees.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [2,1,3]\nOutput: true\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: root = [5,1,4,null,null,3,6]\nOutput: false\nExplanation: The root node's value is 5 but its right child's value is 4.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [1, 104].
    • \n\t
    • -231 <= Node.val <= 231 - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811\uff0c\u5224\u65ad\u5176\u662f\u5426\u662f\u4e00\u4e2a\u6709\u6548\u7684\u4e8c\u53c9\u641c\u7d22\u6811\u3002

    \n\n

    \u5047\u8bbe\u4e00\u4e2a\u4e8c\u53c9\u641c\u7d22\u6811\u5177\u6709\u5982\u4e0b\u7279\u5f81\uff1a

    \n\n
      \n\t
    • \u8282\u70b9\u7684\u5de6\u5b50\u6811\u53ea\u5305\u542b\u5c0f\u4e8e\u5f53\u524d\u8282\u70b9\u7684\u6570\u3002
    • \n\t
    • \u8282\u70b9\u7684\u53f3\u5b50\u6811\u53ea\u5305\u542b\u5927\u4e8e\u5f53\u524d\u8282\u70b9\u7684\u6570\u3002
    • \n\t
    • \u6240\u6709\u5de6\u5b50\u6811\u548c\u53f3\u5b50\u6811\u81ea\u8eab\u5fc5\u987b\u4e5f\u662f\u4e8c\u53c9\u641c\u7d22\u6811\u3002
    • \n
    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165:\n    2\n   / \\\n  1   3\n\u8f93\u51fa: true\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165:\n    5\n   / \\\n  1   4\n     / \\\n    3   6\n\u8f93\u51fa: false\n\u89e3\u91ca: \u8f93\u5165\u4e3a: [5,1,4,null,null,3,6]\u3002\n     \u6839\u8282\u70b9\u7684\u503c\u4e3a 5 \uff0c\u4f46\u662f\u5176\u53f3\u5b50\u8282\u70b9\u503c\u4e3a 4 \u3002\n
    \n", "tags_en": ["Tree", "Depth-first Search", "Recursion"], "tags_cn": ["\u6811", "\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u9012\u5f52"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n bool isValidBST(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public boolean isValidBST(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def isValidBST(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def isValidBST(self, root: TreeNode) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\nbool isValidBST(struct TreeNode* root){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public bool IsValidBST(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {boolean}\n */\nvar isValidBST = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Boolean}\ndef is_valid_bst(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func isValidBST(_ root: TreeNode?) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc isValidBST(root *TreeNode) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def isValidBST(root: TreeNode): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun isValidBST(root: TreeNode?): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn is_valid_bst(root: Option>>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Boolean\n */\n function isValidBST($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction isValidBST(root: TreeNode | null): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (is-valid-bst root)\n (-> (or/c tree-node? #f) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0098](https://leetcode-cn.com/problems/validate-binary-search-tree)", "[\u9a8c\u8bc1\u4e8c\u53c9\u641c\u7d22\u6811](/solution/0000-0099/0098.Validate%20Binary%20Search%20Tree/README.md)", "`\u6811`,`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u9012\u5f52`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0098](https://leetcode.com/problems/validate-binary-search-tree)", "[Validate Binary Search Tree](/solution/0000-0099/0098.Validate%20Binary%20Search%20Tree/README_EN.md)", "`Tree`,`Depth-first Search`,`Recursion`", "Medium", ""]}, {"question_id": "0097", "frontend_question_id": "0097", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/interleaving-string", "url_en": "https://leetcode.com/problems/interleaving-string", "relative_path_cn": "/solution/0000-0099/0097.Interleaving%20String/README.md", "relative_path_en": "/solution/0000-0099/0097.Interleaving%20String/README_EN.md", "title_cn": "\u4ea4\u9519\u5b57\u7b26\u4e32", "title_en": "Interleaving String", "question_title_slug": "interleaving-string", "content_en": "

    Given strings s1, s2, and s3, find whether s3 is formed by an interleaving of s1 and s2.

    \n\n

    An interleaving of two strings s and t is a configuration where they are divided into non-empty substrings such that:

    \n\n
      \n\t
    • s = s1 + s2 + ... + sn
    • \n\t
    • t = t1 + t2 + ... + tm
    • \n\t
    • |n - m| <= 1
    • \n\t
    • The interleaving is s1 + t1 + s2 + t2 + s3 + t3 + ... or t1 + s1 + t2 + s2 + t3 + s3 + ...
    • \n
    \n\n

    Note: a + b is the concatenation of strings a and b.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: s1 = "aabcc", s2 = "dbbca", s3 = "aadbbcbcac"\nOutput: true\n
    \n\n

    Example 2:

    \n\n
    \nInput: s1 = "aabcc", s2 = "dbbca", s3 = "aadbbbaccc"\nOutput: false\n
    \n\n

    Example 3:

    \n\n
    \nInput: s1 = "", s2 = "", s3 = ""\nOutput: true\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= s1.length, s2.length <= 100
    • \n\t
    • 0 <= s3.length <= 200
    • \n\t
    • s1, s2, and s3 consist of lowercase English letters.
    • \n
    \n\n

     

    \n

    Follow up: Could you solve it using only O(s2.length) additional memory space?

    \n", "content_cn": "

    \u7ed9\u5b9a\u4e09\u4e2a\u5b57\u7b26\u4e32\u00a0s1\u3001s2\u3001s3\uff0c\u8bf7\u4f60\u5e2e\u5fd9\u9a8c\u8bc1\u00a0s3\u00a0\u662f\u5426\u662f\u7531\u00a0s1\u00a0\u548c\u00a0s2 \u4ea4\u9519 \u7ec4\u6210\u7684\u3002

    \n\n

    \u4e24\u4e2a\u5b57\u7b26\u4e32 s \u548c t \u4ea4\u9519 \u7684\u5b9a\u4e49\u4e0e\u8fc7\u7a0b\u5982\u4e0b\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5b57\u7b26\u4e32\u90fd\u4f1a\u88ab\u5206\u5272\u6210\u82e5\u5e72 \u975e\u7a7a \u5b50\u5b57\u7b26\u4e32\uff1a

    \n\n
      \n\t
    • s = s1 + s2 + ... + sn
    • \n\t
    • t = t1 + t2 + ... + tm
    • \n\t
    • |n - m| <= 1
    • \n\t
    • \u4ea4\u9519 \u662f s1 + t1 + s2 + t2 + s3 + t3 + ... \u6216\u8005 t1 + s1 + t2 + s2 + t3 + s3 + ...
    • \n
    \n\n

    \u63d0\u793a\uff1aa + b \u610f\u5473\u7740\u5b57\u7b26\u4e32 a \u548c b \u8fde\u63a5\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1as1 = \"aabcc\", s2 = \"dbbca\", s3 = \"aadbbcbcac\"\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as1 = \"aabcc\", s2 = \"dbbca\", s3 = \"aadbbbaccc\"\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as1 = \"\", s2 = \"\", s3 = \"\"\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= s1.length, s2.length <= 100
    • \n\t
    • 0 <= s3.length <= 200
    • \n\t
    • s1\u3001s2\u3001\u548c s3 \u90fd\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n", "tags_en": ["String", "Dynamic Programming"], "tags_cn": ["\u5b57\u7b26\u4e32", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isInterleave(string s1, string s2, string s3) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isInterleave(String s1, String s2, String s3) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isInterleave(self, s1, s2, s3):\n \"\"\"\n :type s1: str\n :type s2: str\n :type s3: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isInterleave(self, s1: str, s2: str, s3: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isInterleave(char * s1, char * s2, char * s3){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsInterleave(string s1, string s2, string s3) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s1\n * @param {string} s2\n * @param {string} s3\n * @return {boolean}\n */\nvar isInterleave = function(s1, s2, s3) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s1\n# @param {String} s2\n# @param {String} s3\n# @return {Boolean}\ndef is_interleave(s1, s2, s3)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isInterleave(_ s1: String, _ s2: String, _ s3: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isInterleave(s1 string, s2 string, s3 string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isInterleave(s1: String, s2: String, s3: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isInterleave(s1: String, s2: String, s3: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_interleave(s1: String, s2: String, s3: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s1\n * @param String $s2\n * @param String $s3\n * @return Boolean\n */\n function isInterleave($s1, $s2, $s3) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isInterleave(s1: string, s2: string, s3: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-interleave s1 s2 s3)\n (-> string? string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0097](https://leetcode-cn.com/problems/interleaving-string)", "[\u4ea4\u9519\u5b57\u7b26\u4e32](/solution/0000-0099/0097.Interleaving%20String/README.md)", "`\u5b57\u7b26\u4e32`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0097](https://leetcode.com/problems/interleaving-string)", "[Interleaving String](/solution/0000-0099/0097.Interleaving%20String/README_EN.md)", "`String`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0096", "frontend_question_id": "0096", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/unique-binary-search-trees", "url_en": "https://leetcode.com/problems/unique-binary-search-trees", "relative_path_cn": "/solution/0000-0099/0096.Unique%20Binary%20Search%20Trees/README.md", "relative_path_en": "/solution/0000-0099/0096.Unique%20Binary%20Search%20Trees/README_EN.md", "title_cn": "\u4e0d\u540c\u7684\u4e8c\u53c9\u641c\u7d22\u6811", "title_en": "Unique Binary Search Trees", "question_title_slug": "unique-binary-search-trees", "content_en": "

    Given an integer n, return the number of structurally unique BST's (binary search trees) which has exactly n nodes of unique values from 1 to n.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: n = 3\nOutput: 5\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 1\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 19
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n \uff0c\u6c42\u6070\u7531 n \u4e2a\u8282\u70b9\u7ec4\u6210\u4e14\u8282\u70b9\u503c\u4ece 1 \u5230 n \u4e92\u4e0d\u76f8\u540c\u7684 \u4e8c\u53c9\u641c\u7d22\u6811 \u6709\u591a\u5c11\u79cd\uff1f\u8fd4\u56de\u6ee1\u8db3\u9898\u610f\u7684\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u79cd\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1an = 3\n\u8f93\u51fa\uff1a5\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 19
    • \n
    \n", "tags_en": ["Tree", "Dynamic Programming"], "tags_cn": ["\u6811", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numTrees(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numTrees(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numTrees(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numTrees(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numTrees(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumTrees(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar numTrees = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef num_trees(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numTrees(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numTrees(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numTrees(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numTrees(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_trees(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function numTrees($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numTrees(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-trees n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0096](https://leetcode-cn.com/problems/unique-binary-search-trees)", "[\u4e0d\u540c\u7684\u4e8c\u53c9\u641c\u7d22\u6811](/solution/0000-0099/0096.Unique%20Binary%20Search%20Trees/README.md)", "`\u6811`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0096](https://leetcode.com/problems/unique-binary-search-trees)", "[Unique Binary Search Trees](/solution/0000-0099/0096.Unique%20Binary%20Search%20Trees/README_EN.md)", "`Tree`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0095", "frontend_question_id": "0095", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/unique-binary-search-trees-ii", "url_en": "https://leetcode.com/problems/unique-binary-search-trees-ii", "relative_path_cn": "/solution/0000-0099/0095.Unique%20Binary%20Search%20Trees%20II/README.md", "relative_path_en": "/solution/0000-0099/0095.Unique%20Binary%20Search%20Trees%20II/README_EN.md", "title_cn": "\u4e0d\u540c\u7684\u4e8c\u53c9\u641c\u7d22\u6811 II", "title_en": "Unique Binary Search Trees II", "question_title_slug": "unique-binary-search-trees-ii", "content_en": "

    Given an integer n, return all the structurally unique BST's (binary search trees), which has exactly n nodes of unique values from 1 to n. Return the answer in any order.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: n = 3\nOutput: [[1,null,2,null,3],[1,null,3,2],[2,1,3],[3,1,null,null,2],[3,2,null,1]]\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 1\nOutput: [[1]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 8
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n \uff0c\u8bf7\u4f60\u751f\u6210\u5e76\u8fd4\u56de\u6240\u6709\u7531 n \u4e2a\u8282\u70b9\u7ec4\u6210\u4e14\u8282\u70b9\u503c\u4ece 1 \u5230 n \u4e92\u4e0d\u76f8\u540c\u7684\u4e0d\u540c \u4e8c\u53c9\u641c\u7d22\u6811 \u3002\u53ef\u4ee5\u6309 \u4efb\u610f\u987a\u5e8f \u8fd4\u56de\u7b54\u6848\u3002

    \n\n

    \u00a0

    \n\n
    \n
    \n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1an = 3\n\u8f93\u51fa\uff1a[[1,null,2,null,3],[1,null,3,2],[2,1,3],[3,1,null,null,2],[3,2,null,1]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1a[[1]]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 8
    • \n
    \n
    \n
    \n", "tags_en": ["Tree", "Dynamic Programming"], "tags_cn": ["\u6811", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector generateTrees(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public List generateTrees(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def generateTrees(self, n):\n \"\"\"\n :type n: int\n :rtype: List[TreeNode]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def generateTrees(self, n: int) -> List[TreeNode]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nstruct TreeNode** generateTrees(int n, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public IList GenerateTrees(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {number} n\n * @return {TreeNode[]}\n */\nvar generateTrees = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {Integer} n\n# @return {TreeNode[]}\ndef generate_trees(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func generateTrees(_ n: Int) -> [TreeNode?] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc generateTrees(n int) []*TreeNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def generateTrees(n: Int): List[TreeNode] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun generateTrees(n: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn generate_trees(n: i32) -> Vec>>> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param Integer $n\n * @return TreeNode[]\n */\n function generateTrees($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction generateTrees(n: number): Array {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (generate-trees n)\n (-> exact-integer? (listof (or/c tree-node? #f)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0095](https://leetcode-cn.com/problems/unique-binary-search-trees-ii)", "[\u4e0d\u540c\u7684\u4e8c\u53c9\u641c\u7d22\u6811 II](/solution/0000-0099/0095.Unique%20Binary%20Search%20Trees%20II/README.md)", "`\u6811`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0095](https://leetcode.com/problems/unique-binary-search-trees-ii)", "[Unique Binary Search Trees II](/solution/0000-0099/0095.Unique%20Binary%20Search%20Trees%20II/README_EN.md)", "`Tree`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0094", "frontend_question_id": "0094", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/binary-tree-inorder-traversal", "url_en": "https://leetcode.com/problems/binary-tree-inorder-traversal", "relative_path_cn": "/solution/0000-0099/0094.Binary%20Tree%20Inorder%20Traversal/README.md", "relative_path_en": "/solution/0000-0099/0094.Binary%20Tree%20Inorder%20Traversal/README_EN.md", "title_cn": "\u4e8c\u53c9\u6811\u7684\u4e2d\u5e8f\u904d\u5386", "title_en": "Binary Tree Inorder Traversal", "question_title_slug": "binary-tree-inorder-traversal", "content_en": "

    Given the root of a binary tree, return the inorder traversal of its nodes' values.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: root = [1,null,2,3]\nOutput: [1,3,2]\n
    \n\n

    Example 2:

    \n\n
    \nInput: root = []\nOutput: []\n
    \n\n

    Example 3:

    \n\n
    \nInput: root = [1]\nOutput: [1]\n
    \n\n

    Example 4:

    \n\"\"\n
    \nInput: root = [1,2]\nOutput: [2,1]\n
    \n\n

    Example 5:

    \n\"\"\n
    \nInput: root = [1,null,2]\nOutput: [1,2]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the tree is in the range [0, 100].
    • \n\t
    • -100 <= Node.val <= 100
    • \n
    \n\n

     

    \nFollow up: Recursive solution is trivial, could you do it iteratively?", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9 root \uff0c\u8fd4\u56de\u5b83\u7684 \u4e2d\u5e8f\u00a0\u904d\u5386\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [1,null,2,3]\n\u8f93\u51fa\uff1a[1,3,2]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = []\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aroot = [1]\n\u8f93\u51fa\uff1a[1]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [1,2]\n\u8f93\u51fa\uff1a[2,1]\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aroot = [1,null,2]\n\u8f93\u51fa\uff1a[1,2]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6811\u4e2d\u8282\u70b9\u6570\u76ee\u5728\u8303\u56f4 [0, 100] \u5185
    • \n\t
    • -100 <= Node.val <= 100
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636:\u00a0\u9012\u5f52\u7b97\u6cd5\u5f88\u7b80\u5355\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u8fed\u4ee3\u7b97\u6cd5\u5b8c\u6210\u5417\uff1f

    \n", "tags_en": ["Stack", "Tree", "Hash Table"], "tags_cn": ["\u6808", "\u6811", "\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"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() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n vector inorderTraversal(TreeNode* root) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n public List inorderTraversal(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def inorderTraversal(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def inorderTraversal(self, root: TreeNode) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * struct TreeNode *left;\n * struct TreeNode *right;\n * };\n */\n\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* inorderTraversal(struct TreeNode* root, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public int val;\n * public TreeNode left;\n * public TreeNode right;\n * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\npublic class Solution {\n public IList InorderTraversal(TreeNode root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number[]}\n */\nvar inorderTraversal = function(root) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for a binary tree node.\n# class TreeNode\n# attr_accessor :val, :left, :right\n# def initialize(val = 0, left = nil, right = nil)\n# @val = val\n# @left = left\n# @right = right\n# end\n# end\n# @param {TreeNode} root\n# @return {Integer[]}\ndef inorder_traversal(root)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n * public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n * self.val = val\n * self.left = left\n * self.right = right\n * }\n * }\n */\nclass Solution {\n func inorderTraversal(_ root: TreeNode?) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n * Val int\n * Left *TreeNode\n * Right *TreeNode\n * }\n */\nfunc inorderTraversal(root *TreeNode) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode(_value: Int = 0, _left: TreeNode = null, _right: TreeNode = null) {\n * var value: Int = _value\n * var left: TreeNode = _left\n * var right: TreeNode = _right\n * }\n */\nobject Solution {\n def inorderTraversal(root: TreeNode): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n * var left: TreeNode? = null\n * var right: TreeNode? = null\n * }\n */\nclass Solution {\n fun inorderTraversal(root: TreeNode?): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for a binary tree node.\n// #[derive(Debug, PartialEq, Eq)]\n// pub struct TreeNode {\n// pub val: i32,\n// pub left: Option>>,\n// pub right: Option>>,\n// }\n//\n// impl TreeNode {\n// #[inline]\n// pub fn new(val: i32) -> Self {\n// TreeNode {\n// val,\n// left: None,\n// right: None\n// }\n// }\n// }\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn inorder_traversal(root: Option>>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * public $val = null;\n * public $left = null;\n * public $right = null;\n * function __construct($val = 0, $left = null, $right = null) {\n * $this->val = $val;\n * $this->left = $left;\n * $this->right = $right;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param TreeNode $root\n * @return Integer[]\n */\n function inorderTraversal($root) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for a binary tree node.\n * class TreeNode {\n * val: number\n * left: TreeNode | null\n * right: TreeNode | null\n * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n * }\n */\n\nfunction inorderTraversal(root: TreeNode | null): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for a binary tree node.\n#|\n\n; val : integer?\n; left : (or/c tree-node? #f)\n; right : (or/c tree-node? #f)\n(struct tree-node\n (val left right) #:mutable #:transparent)\n\n; constructor\n(define (make-tree-node [val 0])\n (tree-node val #f #f))\n\n|#\n\n(define/contract (inorder-traversal root)\n (-> (or/c tree-node? #f) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0094](https://leetcode-cn.com/problems/binary-tree-inorder-traversal)", "[\u4e8c\u53c9\u6811\u7684\u4e2d\u5e8f\u904d\u5386](/solution/0000-0099/0094.Binary%20Tree%20Inorder%20Traversal/README.md)", "`\u6808`,`\u6811`,`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0094](https://leetcode.com/problems/binary-tree-inorder-traversal)", "[Binary Tree Inorder Traversal](/solution/0000-0099/0094.Binary%20Tree%20Inorder%20Traversal/README_EN.md)", "`Stack`,`Tree`,`Hash Table`", "Easy", ""]}, {"question_id": "0093", "frontend_question_id": "0093", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/restore-ip-addresses", "url_en": "https://leetcode.com/problems/restore-ip-addresses", "relative_path_cn": "/solution/0000-0099/0093.Restore%20IP%20Addresses/README.md", "relative_path_en": "/solution/0000-0099/0093.Restore%20IP%20Addresses/README_EN.md", "title_cn": "\u590d\u539f IP \u5730\u5740", "title_en": "Restore IP Addresses", "question_title_slug": "restore-ip-addresses", "content_en": "

    Given a string s containing only digits, return all possible valid IP addresses that can be obtained from s. You can return them in any order.

    \n\n

    A valid IP address consists of exactly four integers, each integer is between 0 and 255, separated by single dots and cannot have leading zeros. For example, "0.1.2.201" and "192.168.1.1" are valid IP addresses and "0.011.255.245", "192.168.1.312" and "192.168@1.1" are invalid IP addresses. 

    \n\n

     

    \n

    Example 1:

    \n
    Input: s = \"25525511135\"\nOutput: [\"255.255.11.135\",\"255.255.111.35\"]\n

    Example 2:

    \n
    Input: s = \"0000\"\nOutput: [\"0.0.0.0\"]\n

    Example 3:

    \n
    Input: s = \"1111\"\nOutput: [\"1.1.1.1\"]\n

    Example 4:

    \n
    Input: s = \"010010\"\nOutput: [\"0.10.0.10\",\"0.100.1.0\"]\n

    Example 5:

    \n
    Input: s = \"101023\"\nOutput: [\"1.0.10.23\",\"1.0.102.3\",\"10.1.0.23\",\"10.10.2.3\",\"101.0.2.3\"]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= s.length <= 3000
    • \n\t
    • s consists of digits only.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u53ea\u5305\u542b\u6570\u5b57\u7684\u5b57\u7b26\u4e32\uff0c\u7528\u4ee5\u8868\u793a\u4e00\u4e2a IP \u5730\u5740\uff0c\u8fd4\u56de\u6240\u6709\u53ef\u80fd\u4ece s \u83b7\u5f97\u7684 \u6709\u6548 IP \u5730\u5740 \u3002\u4f60\u53ef\u4ee5\u6309\u4efb\u4f55\u987a\u5e8f\u8fd4\u56de\u7b54\u6848\u3002

    \n\n

    \u6709\u6548 IP \u5730\u5740 \u6b63\u597d\u7531\u56db\u4e2a\u6574\u6570\uff08\u6bcf\u4e2a\u6574\u6570\u4f4d\u4e8e 0 \u5230 255 \u4e4b\u95f4\u7ec4\u6210\uff0c\u4e14\u4e0d\u80fd\u542b\u6709\u524d\u5bfc 0\uff09\uff0c\u6574\u6570\u4e4b\u95f4\u7528 '.' \u5206\u9694\u3002

    \n\n

    \u4f8b\u5982\uff1a\"0.1.2.201\" \u548c \"192.168.1.1\" \u662f \u6709\u6548 IP \u5730\u5740\uff0c\u4f46\u662f \"0.011.255.245\"\u3001\"192.168.1.312\" \u548c \"192.168@1.1\" \u662f \u65e0\u6548 IP \u5730\u5740\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"25525511135\"\n\u8f93\u51fa\uff1a[\"255.255.11.135\",\"255.255.111.35\"]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"0000\"\n\u8f93\u51fa\uff1a[\"0.0.0.0\"]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"1111\"\n\u8f93\u51fa\uff1a[\"1.1.1.1\"]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"010010\"\n\u8f93\u51fa\uff1a[\"0.10.0.10\",\"0.100.1.0\"]\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"101023\"\n\u8f93\u51fa\uff1a[\"1.0.10.23\",\"1.0.102.3\",\"10.1.0.23\",\"10.10.2.3\",\"101.0.2.3\"]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= s.length <= 3000
    • \n\t
    • s \u4ec5\u7531\u6570\u5b57\u7ec4\u6210
    • \n
    \n", "tags_en": ["String", "Backtracking"], "tags_cn": ["\u5b57\u7b26\u4e32", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector restoreIpAddresses(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List restoreIpAddresses(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def restoreIpAddresses(self, s):\n \"\"\"\n :type s: str\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def restoreIpAddresses(self, s: str) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** restoreIpAddresses(char * s, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList RestoreIpAddresses(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string[]}\n */\nvar restoreIpAddresses = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String[]}\ndef restore_ip_addresses(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func restoreIpAddresses(_ s: String) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func restoreIpAddresses(s string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def restoreIpAddresses(s: String): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun restoreIpAddresses(s: String): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn restore_ip_addresses(s: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String[]\n */\n function restoreIpAddresses($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function restoreIpAddresses(s: string): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (restore-ip-addresses s)\n (-> string? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0093](https://leetcode-cn.com/problems/restore-ip-addresses)", "[\u590d\u539f IP \u5730\u5740](/solution/0000-0099/0093.Restore%20IP%20Addresses/README.md)", "`\u5b57\u7b26\u4e32`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0093](https://leetcode.com/problems/restore-ip-addresses)", "[Restore IP Addresses](/solution/0000-0099/0093.Restore%20IP%20Addresses/README_EN.md)", "`String`,`Backtracking`", "Medium", ""]}, {"question_id": "0092", "frontend_question_id": "0092", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reverse-linked-list-ii", "url_en": "https://leetcode.com/problems/reverse-linked-list-ii", "relative_path_cn": "/solution/0000-0099/0092.Reverse%20Linked%20List%20II/README.md", "relative_path_en": "/solution/0000-0099/0092.Reverse%20Linked%20List%20II/README_EN.md", "title_cn": "\u53cd\u8f6c\u94fe\u8868 II", "title_en": "Reverse Linked List II", "question_title_slug": "reverse-linked-list-ii", "content_en": "

    Given the head of a singly linked list and two integers left and right where left <= right, reverse the nodes of the list from position left to position right, and return the reversed list.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: head = [1,2,3,4,5], left = 2, right = 4\nOutput: [1,4,3,2,5]\n
    \n\n

    Example 2:

    \n\n
    \nInput: head = [5], left = 1, right = 1\nOutput: [5]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the list is n.
    • \n\t
    • 1 <= n <= 500
    • \n\t
    • -500 <= Node.val <= 500
    • \n\t
    • 1 <= left <= right <= n
    • \n
    \n\n

     

    \nFollow up: Could you do it in one pass?", "content_cn": "\u7ed9\u4f60\u5355\u94fe\u8868\u7684\u5934\u6307\u9488 head \u548c\u4e24\u4e2a\u6574\u6570\u00a0left \u548c right \uff0c\u5176\u4e2d\u00a0left <= right \u3002\u8bf7\u4f60\u53cd\u8f6c\u4ece\u4f4d\u7f6e left \u5230\u4f4d\u7f6e right \u7684\u94fe\u8868\u8282\u70b9\uff0c\u8fd4\u56de \u53cd\u8f6c\u540e\u7684\u94fe\u8868 \u3002\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1ahead = [1,2,3,4,5], left = 2, right = 4\n\u8f93\u51fa\uff1a[1,4,3,2,5]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahead = [5], left = 1, right = 1\n\u8f93\u51fa\uff1a[5]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u94fe\u8868\u4e2d\u8282\u70b9\u6570\u76ee\u4e3a n
    • \n\t
    • 1 <= n <= 500
    • \n\t
    • -500 <= Node.val <= 500
    • \n\t
    • 1 <= left <= right <= n
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a \u4f60\u53ef\u4ee5\u4f7f\u7528\u4e00\u8d9f\u626b\u63cf\u5b8c\u6210\u53cd\u8f6c\u5417\uff1f

    \n", "tags_en": ["Linked List"], "tags_cn": ["\u94fe\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n ListNode* reverseBetween(ListNode* head, int left, int right) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public ListNode reverseBetween(ListNode head, int left, int right) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def reverseBetween(self, head, left, right):\n \"\"\"\n :type head: ListNode\n :type left: int\n :type right: int\n :rtype: ListNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def reverseBetween(self, head: ListNode, left: int, right: int) -> ListNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nstruct ListNode* reverseBetween(struct ListNode* head, int left, int right){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public ListNode ReverseBetween(ListNode head, int left, int right) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} head\n * @param {number} left\n * @param {number} right\n * @return {ListNode}\n */\nvar reverseBetween = function(head, left, right) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode} head\n# @param {Integer} left\n# @param {Integer} right\n# @return {ListNode}\ndef reverse_between(head, left, right)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func reverseBetween(_ head: ListNode?, _ left: Int, _ right: Int) -> ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc reverseBetween(head *ListNode, left int, right int) *ListNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def reverseBetween(head: ListNode, left: Int, right: Int): ListNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun reverseBetween(head: ListNode?, left: Int, right: Int): ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn reverse_between(head: Option>, left: i32, right: i32) -> Option> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @param Integer $left\n * @param Integer $right\n * @return ListNode\n */\n function reverseBetween($head, $left, $right) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction reverseBetween(head: ListNode | null, left: number, right: number): ListNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (reverse-between head left right)\n (-> (or/c list-node? #f) exact-integer? exact-integer? (or/c list-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0092](https://leetcode-cn.com/problems/reverse-linked-list-ii)", "[\u53cd\u8f6c\u94fe\u8868 II](/solution/0000-0099/0092.Reverse%20Linked%20List%20II/README.md)", "`\u94fe\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0092](https://leetcode.com/problems/reverse-linked-list-ii)", "[Reverse Linked List II](/solution/0000-0099/0092.Reverse%20Linked%20List%20II/README_EN.md)", "`Linked List`", "Medium", ""]}, {"question_id": "0091", "frontend_question_id": "0091", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/decode-ways", "url_en": "https://leetcode.com/problems/decode-ways", "relative_path_cn": "/solution/0000-0099/0091.Decode%20Ways/README.md", "relative_path_en": "/solution/0000-0099/0091.Decode%20Ways/README_EN.md", "title_cn": "\u89e3\u7801\u65b9\u6cd5", "title_en": "Decode Ways", "question_title_slug": "decode-ways", "content_en": "

    A message containing letters from A-Z can be encoded into numbers using the following mapping:

    \n\n
    \n'A' -> "1"\n'B' -> "2"\n...\n'Z' -> "26"\n
    \n\n

    To decode an encoded message, all the digits must be grouped then mapped back into letters using the reverse of the mapping above (there may be multiple ways). For example, "11106" can be mapped into:

    \n\n
      \n\t
    • "AAJF" with the grouping (1 1 10 6)
    • \n\t
    • "KJF" with the grouping (11 10 6)
    • \n
    \n\n

    Note that the grouping (1 11 06) is invalid because "06" cannot be mapped into 'F' since "6" is different from "06".

    \n\n

    Given a string s containing only digits, return the number of ways to decode it.

    \n\n

    The answer is guaranteed to fit in a 32-bit integer.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "12"\nOutput: 2\nExplanation: "12" could be decoded as "AB" (1 2) or "L" (12).\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "226"\nOutput: 3\nExplanation: "226" could be decoded as "BZ" (2 26), "VF" (22 6), or "BBF" (2 2 6).\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "0"\nOutput: 0\nExplanation: There is no character that is mapped to a number starting with 0.\nThe only valid mappings with 0 are 'J' -> "10" and 'T' -> "20", neither of which start with 0.\nHence, there are no valid ways to decode this since all digits need to be mapped.\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "06"\nOutput: 0\nExplanation: "06" cannot be mapped to "F" because of the leading zero ("6" is different from "06").\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 100
    • \n\t
    • s contains only digits and may contain leading zero(s).
    • \n
    \n", "content_cn": "

    \u4e00\u6761\u5305\u542b\u5b57\u6bcd\u00a0A-Z \u7684\u6d88\u606f\u901a\u8fc7\u4ee5\u4e0b\u6620\u5c04\u8fdb\u884c\u4e86 \u7f16\u7801 \uff1a

    \n\n
    \n'A' -> 1\n'B' -> 2\n...\n'Z' -> 26\n
    \n\n

    \u8981 \u89e3\u7801 \u5df2\u7f16\u7801\u7684\u6d88\u606f\uff0c\u6240\u6709\u6570\u5b57\u5fc5\u987b\u57fa\u4e8e\u4e0a\u8ff0\u6620\u5c04\u7684\u65b9\u6cd5\uff0c\u53cd\u5411\u6620\u5c04\u56de\u5b57\u6bcd\uff08\u53ef\u80fd\u6709\u591a\u79cd\u65b9\u6cd5\uff09\u3002\u4f8b\u5982\uff0c\"11106\" \u53ef\u4ee5\u6620\u5c04\u4e3a\uff1a

    \n\n
      \n\t
    • \"AAJF\" \uff0c\u5c06\u6d88\u606f\u5206\u7ec4\u4e3a (1 1 10 6)
    • \n\t
    • \"KJF\" \uff0c\u5c06\u6d88\u606f\u5206\u7ec4\u4e3a (11 10 6)
    • \n
    \n\n

    \u6ce8\u610f\uff0c\u6d88\u606f\u4e0d\u80fd\u5206\u7ec4\u4e3a\u00a0 (1 11 06) \uff0c\u56e0\u4e3a \"06\" \u4e0d\u80fd\u6620\u5c04\u4e3a \"F\" \uff0c\u8fd9\u662f\u7531\u4e8e \"6\" \u548c \"06\" \u5728\u6620\u5c04\u4e2d\u5e76\u4e0d\u7b49\u4ef7\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u53ea\u542b\u6570\u5b57\u7684 \u975e\u7a7a \u5b57\u7b26\u4e32 s \uff0c\u8bf7\u8ba1\u7b97\u5e76\u8fd4\u56de \u89e3\u7801 \u65b9\u6cd5\u7684 \u603b\u6570 \u3002

    \n\n

    \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u7b54\u6848\u80af\u5b9a\u662f\u4e00\u4e2a 32 \u4f4d \u7684\u6574\u6570\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"12\"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5b83\u53ef\u4ee5\u89e3\u7801\u4e3a \"AB\"\uff081 2\uff09\u6216\u8005 \"L\"\uff0812\uff09\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"226\"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\u5b83\u53ef\u4ee5\u89e3\u7801\u4e3a \"BZ\" (2 26), \"VF\" (22 6), \u6216\u8005 \"BBF\" (2 2 6) \u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"0\"\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\u6ca1\u6709\u5b57\u7b26\u6620\u5c04\u5230\u4ee5 0 \u5f00\u5934\u7684\u6570\u5b57\u3002\n\u542b\u6709 0 \u7684\u6709\u6548\u6620\u5c04\u662f 'J' -> \"10\" \u548c 'T'-> \"20\" \u3002\n\u7531\u4e8e\u6ca1\u6709\u5b57\u7b26\uff0c\u56e0\u6b64\u6ca1\u6709\u6709\u6548\u7684\u65b9\u6cd5\u5bf9\u6b64\u8fdb\u884c\u89e3\u7801\uff0c\u56e0\u4e3a\u6240\u6709\u6570\u5b57\u90fd\u9700\u8981\u6620\u5c04\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"06\"\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\"06\" \u4e0d\u80fd\u6620\u5c04\u5230 \"F\" \uff0c\u56e0\u4e3a\u5b57\u7b26\u4e32\u542b\u6709\u524d\u5bfc 0\uff08\"6\" \u548c \"06\" \u5728\u6620\u5c04\u4e2d\u5e76\u4e0d\u7b49\u4ef7\uff09\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 100
    • \n\t
    • s \u53ea\u5305\u542b\u6570\u5b57\uff0c\u5e76\u4e14\u53ef\u80fd\u5305\u542b\u524d\u5bfc\u96f6\u3002
    • \n
    \n", "tags_en": ["String", "Dynamic Programming"], "tags_cn": ["\u5b57\u7b26\u4e32", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int numDecodings(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int numDecodings(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def numDecodings(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def numDecodings(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint numDecodings(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int NumDecodings(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar numDecodings = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef num_decodings(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func numDecodings(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func numDecodings(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def numDecodings(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun numDecodings(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn num_decodings(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function numDecodings($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function numDecodings(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (num-decodings s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0091](https://leetcode-cn.com/problems/decode-ways)", "[\u89e3\u7801\u65b9\u6cd5](/solution/0000-0099/0091.Decode%20Ways/README.md)", "`\u5b57\u7b26\u4e32`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0091](https://leetcode.com/problems/decode-ways)", "[Decode Ways](/solution/0000-0099/0091.Decode%20Ways/README_EN.md)", "`String`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0090", "frontend_question_id": "0090", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/subsets-ii", "url_en": "https://leetcode.com/problems/subsets-ii", "relative_path_cn": "/solution/0000-0099/0090.Subsets%20II/README.md", "relative_path_en": "/solution/0000-0099/0090.Subsets%20II/README_EN.md", "title_cn": "\u5b50\u96c6 II", "title_en": "Subsets II", "question_title_slug": "subsets-ii", "content_en": "

    Given an integer array nums that may contain duplicates, return all possible subsets (the power set).

    \n\n

    The solution set must not contain duplicate subsets. Return the solution in any order.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [1,2,2]\nOutput: [[],[1],[1,2],[1,2,2],[2],[2,2]]\n

    Example 2:

    \n
    Input: nums = [0]\nOutput: [[],[0]]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 10
    • \n\t
    • -10 <= nums[i] <= 10
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \uff0c\u5176\u4e2d\u53ef\u80fd\u5305\u542b\u91cd\u590d\u5143\u7d20\uff0c\u8bf7\u4f60\u8fd4\u56de\u8be5\u6570\u7ec4\u6240\u6709\u53ef\u80fd\u7684\u5b50\u96c6\uff08\u5e42\u96c6\uff09\u3002

    \n\n

    \u89e3\u96c6 \u4e0d\u80fd \u5305\u542b\u91cd\u590d\u7684\u5b50\u96c6\u3002\u8fd4\u56de\u7684\u89e3\u96c6\u4e2d\uff0c\u5b50\u96c6\u53ef\u4ee5\u6309 \u4efb\u610f\u987a\u5e8f \u6392\u5217\u3002

    \n\n
    \n
    \n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,2]\n\u8f93\u51fa\uff1a[[],[1],[1,2],[1,2,2],[2],[2,2]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [0]\n\u8f93\u51fa\uff1a[[],[0]]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 10
    • \n\t
    • -10 <= nums[i] <= 10
    • \n
    \n
    \n
    \n", "tags_en": ["Array", "Backtracking"], "tags_cn": ["\u6570\u7ec4", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> subsetsWithDup(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> subsetsWithDup(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def subsetsWithDup(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def subsetsWithDup(self, nums: List[int]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** subsetsWithDup(int* nums, int numsSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> SubsetsWithDup(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number[][]}\n */\nvar subsetsWithDup = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer[][]}\ndef subsets_with_dup(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func subsetsWithDup(_ nums: [Int]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func subsetsWithDup(nums []int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def subsetsWithDup(nums: Array[Int]): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun subsetsWithDup(nums: IntArray): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn subsets_with_dup(nums: Vec) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer[][]\n */\n function subsetsWithDup($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function subsetsWithDup(nums: number[]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (subsets-with-dup nums)\n (-> (listof exact-integer?) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0090](https://leetcode-cn.com/problems/subsets-ii)", "[\u5b50\u96c6 II](/solution/0000-0099/0090.Subsets%20II/README.md)", "`\u6570\u7ec4`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0090](https://leetcode.com/problems/subsets-ii)", "[Subsets II](/solution/0000-0099/0090.Subsets%20II/README_EN.md)", "`Array`,`Backtracking`", "Medium", ""]}, {"question_id": "0089", "frontend_question_id": "0089", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/gray-code", "url_en": "https://leetcode.com/problems/gray-code", "relative_path_cn": "/solution/0000-0099/0089.Gray%20Code/README.md", "relative_path_en": "/solution/0000-0099/0089.Gray%20Code/README_EN.md", "title_cn": "\u683c\u96f7\u7f16\u7801", "title_en": "Gray Code", "question_title_slug": "gray-code", "content_en": "

    An n-bit gray code sequence is a sequence of 2n integers where:

    \n\n
      \n\t
    • Every integer is in the inclusive range [0, 2n - 1],
    • \n\t
    • The first integer is 0,
    • \n\t
    • An integer appears no more than once in the sequence,
    • \n\t
    • The binary representation of every pair of adjacent integers differs by exactly one bit, and
    • \n\t
    • The binary representation of the first and last integers differs by exactly one bit.
    • \n
    \n\n

    Given an integer n, return any valid n-bit gray code sequence.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 2\nOutput: [0,1,3,2]\nExplanation:\nThe binary representation of [0,1,3,2] is [00,01,11,10].\n- 00 and 01 differ by one bit\n- 01 and 11 differ by one bit\n- 11 and 10 differ by one bit\n- 10 and 00 differ by one bit\n[0,2,3,1] is also a valid gray code sequence, whose binary representation is [00,10,11,01].\n- 00 and 10 differ by one bit\n- 10 and 11 differ by one bit\n- 11 and 01 differ by one bit\n- 01 and 00 differ by one bit\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 1\nOutput: [0,1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 16
    • \n
    \n", "content_cn": "

    \u683c\u96f7\u7f16\u7801\u662f\u4e00\u4e2a\u4e8c\u8fdb\u5236\u6570\u5b57\u7cfb\u7edf\uff0c\u5728\u8be5\u7cfb\u7edf\u4e2d\uff0c\u4e24\u4e2a\u8fde\u7eed\u7684\u6570\u503c\u4ec5\u6709\u4e00\u4e2a\u4f4d\u6570\u7684\u5dee\u5f02\u3002

    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u4ee3\u8868\u7f16\u7801\u603b\u4f4d\u6570\u7684\u975e\u8d1f\u6574\u6570 n\uff0c\u6253\u5370\u5176\u683c\u96f7\u7f16\u7801\u5e8f\u5217\u3002\u5373\u4f7f\u6709\u591a\u4e2a\u4e0d\u540c\u7b54\u6848\uff0c\u4f60\u4e5f\u53ea\u9700\u8981\u8fd4\u56de\u5176\u4e2d\u4e00\u79cd\u3002

    \n\n

    \u683c\u96f7\u7f16\u7801\u5e8f\u5217\u5fc5\u987b\u4ee5 0 \u5f00\u5934\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: 2\n\u8f93\u51fa: [0,1,3,2]\n\u89e3\u91ca:\n00 - 0\n01 - 1\n11 - 3\n10 - 2\n\n\u5bf9\u4e8e\u7ed9\u5b9a\u7684 n\uff0c\u5176\u683c\u96f7\u7f16\u7801\u5e8f\u5217\u5e76\u4e0d\u552f\u4e00\u3002\n\u4f8b\u5982\uff0c[0,2,3,1] \u4e5f\u662f\u4e00\u4e2a\u6709\u6548\u7684\u683c\u96f7\u7f16\u7801\u5e8f\u5217\u3002\n\n00 - 0\n10 - 2\n11 - 3\n01 - 1
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: 0\n\u8f93\u51fa: [0]\n\u89e3\u91ca: \u6211\u4eec\u5b9a\u4e49\u683c\u96f7\u7f16\u7801\u5e8f\u5217\u5fc5\u987b\u4ee5 0 \u5f00\u5934\u3002\n     \u7ed9\u5b9a\u7f16\u7801\u603b\u4f4d\u6570\u4e3a n \u7684\u683c\u96f7\u7f16\u7801\u5e8f\u5217\uff0c\u5176\u957f\u5ea6\u4e3a 2n\u3002\u5f53 n = 0 \u65f6\uff0c\u957f\u5ea6\u4e3a 20 = 1\u3002\n     \u56e0\u6b64\uff0c\u5f53 n = 0 \u65f6\uff0c\u5176\u683c\u96f7\u7f16\u7801\u5e8f\u5217\u4e3a [0]\u3002\n
    \n", "tags_en": ["Backtracking"], "tags_cn": ["\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector grayCode(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List grayCode(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def grayCode(self, n):\n \"\"\"\n :type n: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def grayCode(self, n: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* grayCode(int n, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList GrayCode(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number[]}\n */\nvar grayCode = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer[]}\ndef gray_code(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func grayCode(_ n: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func grayCode(n int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def grayCode(n: Int): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun grayCode(n: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn gray_code(n: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer[]\n */\n function grayCode($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function grayCode(n: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (gray-code n)\n (-> exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0089](https://leetcode-cn.com/problems/gray-code)", "[\u683c\u96f7\u7f16\u7801](/solution/0000-0099/0089.Gray%20Code/README.md)", "`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0089](https://leetcode.com/problems/gray-code)", "[Gray Code](/solution/0000-0099/0089.Gray%20Code/README_EN.md)", "`Backtracking`", "Medium", ""]}, {"question_id": "0088", "frontend_question_id": "0088", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/merge-sorted-array", "url_en": "https://leetcode.com/problems/merge-sorted-array", "relative_path_cn": "/solution/0000-0099/0088.Merge%20Sorted%20Array/README.md", "relative_path_en": "/solution/0000-0099/0088.Merge%20Sorted%20Array/README_EN.md", "title_cn": "\u5408\u5e76\u4e24\u4e2a\u6709\u5e8f\u6570\u7ec4", "title_en": "Merge Sorted Array", "question_title_slug": "merge-sorted-array", "content_en": "

    You are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in nums1 and nums2 respectively.

    \n\n

    Merge nums1 and nums2 into a single array sorted in non-decreasing order.

    \n\n

    The final sorted array should not be returned by the function, but instead be stored inside the array nums1. To accommodate this, nums1 has a length of m + n, where the first m elements denote the elements that should be merged, and the last n elements are set to 0 and should be ignored. nums2 has a length of n.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums1 = [1,2,3,0,0,0], m = 3, nums2 = [2,5,6], n = 3\nOutput: [1,2,2,3,5,6]\nExplanation: The arrays we are merging are [1,2,3] and [2,5,6].\nThe result of the merge is [1,2,2,3,5,6] with the underlined elements coming from nums1.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums1 = [1], m = 1, nums2 = [], n = 0\nOutput: [1]\nExplanation: The arrays we are merging are [1] and [].\nThe result of the merge is [1].\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums1 = [0], m = 0, nums2 = [1], n = 1\nOutput: [1]\nExplanation: The arrays we are merging are [] and [1].\nThe result of the merge is [1].\nNote that because m = 0, there are no elements in nums1. The 0 is only there to ensure the merge result can fit in nums1.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • nums1.length == m + n
    • \n\t
    • nums2.length == n
    • \n\t
    • 0 <= m, n <= 200
    • \n\t
    • 1 <= m + n <= 200
    • \n\t
    • -109 <= nums1[i], nums2[j] <= 109
    • \n
    \n\n

     

    \n

    Follow up: Can you come up with an algorithm that runs in O(m + n) time?

    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u6709\u5e8f\u6574\u6570\u6570\u7ec4\u00a0nums1 \u548c nums2\uff0c\u8bf7\u4f60\u5c06 nums2 \u5408\u5e76\u5230\u00a0nums1\u00a0\u4e2d\uff0c\u4f7f nums1 \u6210\u4e3a\u4e00\u4e2a\u6709\u5e8f\u6570\u7ec4\u3002

    \n\n

    \u521d\u59cb\u5316\u00a0nums1 \u548c nums2 \u7684\u5143\u7d20\u6570\u91cf\u5206\u522b\u4e3a\u00a0m \u548c n \u3002\u4f60\u53ef\u4ee5\u5047\u8bbe\u00a0nums1 \u7684\u7a7a\u95f4\u5927\u5c0f\u7b49\u4e8e\u00a0m + n\uff0c\u8fd9\u6837\u5b83\u5c31\u6709\u8db3\u591f\u7684\u7a7a\u95f4\u4fdd\u5b58\u6765\u81ea nums2 \u7684\u5143\u7d20\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums1 = [1,2,3,0,0,0], m = 3, nums2 = [2,5,6], n = 3\n\u8f93\u51fa\uff1a[1,2,2,3,5,6]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums1 = [1], m = 1, nums2 = [], n = 0\n\u8f93\u51fa\uff1a[1]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • nums1.length == m + n
    • \n\t
    • nums2.length == n
    • \n\t
    • 0 <= m, n <= 200
    • \n\t
    • 1 <= m + n <= 200
    • \n\t
    • -109 <= nums1[i], nums2[i] <= 109
    • \n
    \n", "tags_en": ["Array", "Two Pointers"], "tags_cn": ["\u6570\u7ec4", "\u53cc\u6307\u9488"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n void merge(vector& nums1, int m, vector& nums2, int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public void merge(int[] nums1, int m, int[] nums2, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def merge(self, nums1, m, nums2, n):\n \"\"\"\n :type nums1: List[int]\n :type m: int\n :type nums2: List[int]\n :type n: int\n :rtype: None Do not return anything, modify nums1 in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def merge(self, nums1: List[int], m: int, nums2: List[int], n: int) -> None:\n \"\"\"\n Do not return anything, modify nums1 in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nvoid merge(int* nums1, int nums1Size, int m, int* nums2, int nums2Size, int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public void Merge(int[] nums1, int m, int[] nums2, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums1\n * @param {number} m\n * @param {number[]} nums2\n * @param {number} n\n * @return {void} Do not return anything, modify nums1 in-place instead.\n */\nvar merge = function(nums1, m, nums2, n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums1\n# @param {Integer} m\n# @param {Integer[]} nums2\n# @param {Integer} n\n# @return {Void} Do not return anything, modify nums1 in-place instead.\ndef merge(nums1, m, nums2, n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func merge(_ nums1: inout [Int], _ m: Int, _ nums2: [Int], _ n: Int) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func merge(nums1 []int, m int, nums2 []int, n int) {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def merge(nums1: Array[Int], m: Int, nums2: Array[Int], n: Int): Unit = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun merge(nums1: IntArray, m: Int, nums2: IntArray, n: Int): Unit {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn merge(nums1: &mut Vec, m: i32, nums2: &mut Vec, n: i32) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums1\n * @param Integer $m\n * @param Integer[] $nums2\n * @param Integer $n\n * @return NULL\n */\n function merge(&$nums1, $m, $nums2, $n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n Do not return anything, modify nums1 in-place instead.\n */\nfunction merge(nums1: number[], m: number, nums2: number[], n: number): void {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0088](https://leetcode-cn.com/problems/merge-sorted-array)", "[\u5408\u5e76\u4e24\u4e2a\u6709\u5e8f\u6570\u7ec4](/solution/0000-0099/0088.Merge%20Sorted%20Array/README.md)", "`\u6570\u7ec4`,`\u53cc\u6307\u9488`", "\u7b80\u5355", ""], "md_table_row_en": ["[0088](https://leetcode.com/problems/merge-sorted-array)", "[Merge Sorted Array](/solution/0000-0099/0088.Merge%20Sorted%20Array/README_EN.md)", "`Array`,`Two Pointers`", "Easy", ""]}, {"question_id": "0087", "frontend_question_id": "0087", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/scramble-string", "url_en": "https://leetcode.com/problems/scramble-string", "relative_path_cn": "/solution/0000-0099/0087.Scramble%20String/README.md", "relative_path_en": "/solution/0000-0099/0087.Scramble%20String/README_EN.md", "title_cn": "\u6270\u4e71\u5b57\u7b26\u4e32", "title_en": "Scramble String", "question_title_slug": "scramble-string", "content_en": "

    We can scramble a string s to get a string t using the following algorithm:

    \n\n
      \n\t
    1. If the length of the string is 1, stop.
    2. \n\t
    3. If the length of the string is > 1, do the following:\n\t
        \n\t\t
      • Split the string into two non-empty substrings at a random index, i.e., if the string is s, divide it to x and y where s = x + y.
      • \n\t\t
      • Randomly decide to swap the two substrings or to keep them in the same order. i.e., after this step, s may become s = x + y or s = y + x.
      • \n\t\t
      • Apply step 1 recursively on each of the two substrings x and y.
      • \n\t
      \n\t
    4. \n
    \n\n

    Given two strings s1 and s2 of the same length, return true if s2 is a scrambled string of s1, otherwise, return false.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s1 = "great", s2 = "rgeat"\nOutput: true\nExplanation: One possible scenario applied on s1 is:\n"great" --> "gr/eat" // divide at random index.\n"gr/eat" --> "gr/eat" // random decision is not to swap the two substrings and keep them in order.\n"gr/eat" --> "g/r / e/at" // apply the same algorithm recursively on both substrings. divide at ranom index each of them.\n"g/r / e/at" --> "r/g / e/at" // random decision was to swap the first substring and to keep the second substring in the same order.\n"r/g / e/at" --> "r/g / e/ a/t" // again apply the algorithm recursively, divide "at" to "a/t".\n"r/g / e/ a/t" --> "r/g / e/ a/t" // random decision is to keep both substrings in the same order.\nThe algorithm stops now and the result string is "rgeat" which is s2.\nAs there is one possible scenario that led s1 to be scrambled to s2, we return true.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s1 = "abcde", s2 = "caebd"\nOutput: false\n
    \n\n

    Example 3:

    \n\n
    \nInput: s1 = "a", s2 = "a"\nOutput: true\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • s1.length == s2.length
    • \n\t
    • 1 <= s1.length <= 30
    • \n\t
    • s1 and s2 consist of lower-case English letters.
    • \n
    \n", "content_cn": "\u4f7f\u7528\u4e0b\u9762\u63cf\u8ff0\u7684\u7b97\u6cd5\u53ef\u4ee5\u6270\u4e71\u5b57\u7b26\u4e32 s \u5f97\u5230\u5b57\u7b26\u4e32 t \uff1a\n
      \n\t
    1. \u5982\u679c\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u4e3a 1 \uff0c\u7b97\u6cd5\u505c\u6b62
    2. \n\t
    3. \u5982\u679c\u5b57\u7b26\u4e32\u7684\u957f\u5ea6 > 1 \uff0c\u6267\u884c\u4e0b\u8ff0\u6b65\u9aa4\uff1a\n\t
        \n\t\t
      • \u5728\u4e00\u4e2a\u968f\u673a\u4e0b\u6807\u5904\u5c06\u5b57\u7b26\u4e32\u5206\u5272\u6210\u4e24\u4e2a\u975e\u7a7a\u7684\u5b50\u5b57\u7b26\u4e32\u3002\u5373\uff0c\u5982\u679c\u5df2\u77e5\u5b57\u7b26\u4e32 s \uff0c\u5219\u53ef\u4ee5\u5c06\u5176\u5206\u6210\u4e24\u4e2a\u5b50\u5b57\u7b26\u4e32 x \u548c y \uff0c\u4e14\u6ee1\u8db3 s = x + y \u3002
      • \n\t\t
      • \u968f\u673a \u51b3\u5b9a\u662f\u8981\u300c\u4ea4\u6362\u4e24\u4e2a\u5b50\u5b57\u7b26\u4e32\u300d\u8fd8\u662f\u8981\u300c\u4fdd\u6301\u8fd9\u4e24\u4e2a\u5b50\u5b57\u7b26\u4e32\u7684\u987a\u5e8f\u4e0d\u53d8\u300d\u3002\u5373\uff0c\u5728\u6267\u884c\u8fd9\u4e00\u6b65\u9aa4\u4e4b\u540e\uff0cs \u53ef\u80fd\u662f s = x + y \u6216\u8005 s = y + x \u3002
      • \n\t\t
      • \u5728 x \u548c y \u8fd9\u4e24\u4e2a\u5b50\u5b57\u7b26\u4e32\u4e0a\u7ee7\u7eed\u4ece\u6b65\u9aa4 1 \u5f00\u59cb\u9012\u5f52\u6267\u884c\u6b64\u7b97\u6cd5\u3002
      • \n\t
      \n\t
    4. \n
    \n\n

    \u7ed9\u4f60\u4e24\u4e2a \u957f\u5ea6\u76f8\u7b49 \u7684\u5b57\u7b26\u4e32 s1 \u548c\u00a0s2\uff0c\u5224\u65ad\u00a0s2\u00a0\u662f\u5426\u662f\u00a0s1\u00a0\u7684\u6270\u4e71\u5b57\u7b26\u4e32\u3002\u5982\u679c\u662f\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as1 = \"great\", s2 = \"rgeat\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1as1 \u4e0a\u53ef\u80fd\u53d1\u751f\u7684\u4e00\u79cd\u60c5\u5f62\u662f\uff1a\n\"great\" --> \"gr/eat\" // \u5728\u4e00\u4e2a\u968f\u673a\u4e0b\u6807\u5904\u5206\u5272\u5f97\u5230\u4e24\u4e2a\u5b50\u5b57\u7b26\u4e32\n\"gr/eat\" --> \"gr/eat\" // \u968f\u673a\u51b3\u5b9a\uff1a\u300c\u4fdd\u6301\u8fd9\u4e24\u4e2a\u5b50\u5b57\u7b26\u4e32\u7684\u987a\u5e8f\u4e0d\u53d8\u300d\n\"gr/eat\" --> \"g/r / e/at\" // \u5728\u5b50\u5b57\u7b26\u4e32\u4e0a\u9012\u5f52\u6267\u884c\u6b64\u7b97\u6cd5\u3002\u4e24\u4e2a\u5b50\u5b57\u7b26\u4e32\u5206\u522b\u5728\u968f\u673a\u4e0b\u6807\u5904\u8fdb\u884c\u4e00\u8f6e\u5206\u5272\n\"g/r / e/at\" --> \"r/g / e/at\" // \u968f\u673a\u51b3\u5b9a\uff1a\u7b2c\u4e00\u7ec4\u300c\u4ea4\u6362\u4e24\u4e2a\u5b50\u5b57\u7b26\u4e32\u300d\uff0c\u7b2c\u4e8c\u7ec4\u300c\u4fdd\u6301\u8fd9\u4e24\u4e2a\u5b50\u5b57\u7b26\u4e32\u7684\u987a\u5e8f\u4e0d\u53d8\u300d\n\"r/g / e/at\" --> \"r/g / e/ a/t\" // \u7ee7\u7eed\u9012\u5f52\u6267\u884c\u6b64\u7b97\u6cd5\uff0c\u5c06 \"at\" \u5206\u5272\u5f97\u5230 \"a/t\"\n\"r/g / e/ a/t\" --> \"r/g / e/ a/t\" // \u968f\u673a\u51b3\u5b9a\uff1a\u300c\u4fdd\u6301\u8fd9\u4e24\u4e2a\u5b50\u5b57\u7b26\u4e32\u7684\u987a\u5e8f\u4e0d\u53d8\u300d\n\u7b97\u6cd5\u7ec8\u6b62\uff0c\u7ed3\u679c\u5b57\u7b26\u4e32\u548c s2 \u76f8\u540c\uff0c\u90fd\u662f \"rgeat\"\n\u8fd9\u662f\u4e00\u79cd\u80fd\u591f\u6270\u4e71 s1 \u5f97\u5230 s2 \u7684\u60c5\u5f62\uff0c\u53ef\u4ee5\u8ba4\u4e3a s2 \u662f s1 \u7684\u6270\u4e71\u5b57\u7b26\u4e32\uff0c\u8fd4\u56de true\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as1 = \"abcde\", s2 = \"caebd\"\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as1 = \"a\", s2 = \"a\"\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • s1.length == s2.length
    • \n\t
    • 1 <= s1.length <= 30
    • \n\t
    • s1 \u548c s2 \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n", "tags_en": ["String", "Dynamic Programming"], "tags_cn": ["\u5b57\u7b26\u4e32", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isScramble(string s1, string s2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isScramble(String s1, String s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isScramble(self, s1, s2):\n \"\"\"\n :type s1: str\n :type s2: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isScramble(self, s1: str, s2: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isScramble(char * s1, char * s2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsScramble(string s1, string s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s1\n * @param {string} s2\n * @return {boolean}\n */\nvar isScramble = function(s1, s2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s1\n# @param {String} s2\n# @return {Boolean}\ndef is_scramble(s1, s2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isScramble(_ s1: String, _ s2: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isScramble(s1 string, s2 string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isScramble(s1: String, s2: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isScramble(s1: String, s2: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_scramble(s1: String, s2: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s1\n * @param String $s2\n * @return Boolean\n */\n function isScramble($s1, $s2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isScramble(s1: string, s2: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-scramble s1 s2)\n (-> string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0087](https://leetcode-cn.com/problems/scramble-string)", "[\u6270\u4e71\u5b57\u7b26\u4e32](/solution/0000-0099/0087.Scramble%20String/README.md)", "`\u5b57\u7b26\u4e32`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0087](https://leetcode.com/problems/scramble-string)", "[Scramble String](/solution/0000-0099/0087.Scramble%20String/README_EN.md)", "`String`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0086", "frontend_question_id": "0086", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/partition-list", "url_en": "https://leetcode.com/problems/partition-list", "relative_path_cn": "/solution/0000-0099/0086.Partition%20List/README.md", "relative_path_en": "/solution/0000-0099/0086.Partition%20List/README_EN.md", "title_cn": "\u5206\u9694\u94fe\u8868", "title_en": "Partition List", "question_title_slug": "partition-list", "content_en": "

    Given the head of a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.

    \n\n

    You should preserve the original relative order of the nodes in each of the two partitions.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: head = [1,4,3,2,5,2], x = 3\nOutput: [1,2,2,4,3,5]\n
    \n\n

    Example 2:

    \n\n
    \nInput: head = [2,1], x = 2\nOutput: [1,2]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the list is in the range [0, 200].
    • \n\t
    • -100 <= Node.val <= 100
    • \n\t
    • -200 <= x <= 200
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u94fe\u8868\u7684\u5934\u8282\u70b9 head \u548c\u4e00\u4e2a\u7279\u5b9a\u503c x \uff0c\u8bf7\u4f60\u5bf9\u94fe\u8868\u8fdb\u884c\u5206\u9694\uff0c\u4f7f\u5f97\u6240\u6709 \u5c0f\u4e8e x \u7684\u8282\u70b9\u90fd\u51fa\u73b0\u5728 \u5927\u4e8e\u6216\u7b49\u4e8e x \u7684\u8282\u70b9\u4e4b\u524d\u3002

    \n\n

    \u4f60\u5e94\u5f53 \u4fdd\u7559 \u4e24\u4e2a\u5206\u533a\u4e2d\u6bcf\u4e2a\u8282\u70b9\u7684\u521d\u59cb\u76f8\u5bf9\u4f4d\u7f6e\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1ahead = [1,4,3,2,5,2], x = 3\n\u8f93\u51fa\uff1a[1,2,2,4,3,5]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahead = [2,1], x = 2\n\u8f93\u51fa\uff1a[1,2]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u94fe\u8868\u4e2d\u8282\u70b9\u7684\u6570\u76ee\u5728\u8303\u56f4 [0, 200] \u5185
    • \n\t
    • -100 <= Node.val <= 100
    • \n\t
    • -200 <= x <= 200
    • \n
    \n", "tags_en": ["Linked List", "Two Pointers"], "tags_cn": ["\u94fe\u8868", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n ListNode* partition(ListNode* head, int x) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public ListNode partition(ListNode head, int x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def partition(self, head, x):\n \"\"\"\n :type head: ListNode\n :type x: int\n :rtype: ListNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def partition(self, head: ListNode, x: int) -> ListNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nstruct ListNode* partition(struct ListNode* head, int x){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public ListNode Partition(ListNode head, int x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} head\n * @param {number} x\n * @return {ListNode}\n */\nvar partition = function(head, x) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode} head\n# @param {Integer} x\n# @return {ListNode}\ndef partition(head, x)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func partition(_ head: ListNode?, _ x: Int) -> ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc partition(head *ListNode, x int) *ListNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def partition(head: ListNode, x: Int): ListNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun partition(head: ListNode?, x: Int): ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn partition(head: Option>, x: i32) -> Option> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @param Integer $x\n * @return ListNode\n */\n function partition($head, $x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction partition(head: ListNode | null, x: number): ListNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (partition head x)\n (-> (or/c list-node? #f) exact-integer? (or/c list-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0086](https://leetcode-cn.com/problems/partition-list)", "[\u5206\u9694\u94fe\u8868](/solution/0000-0099/0086.Partition%20List/README.md)", "`\u94fe\u8868`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0086](https://leetcode.com/problems/partition-list)", "[Partition List](/solution/0000-0099/0086.Partition%20List/README_EN.md)", "`Linked List`,`Two Pointers`", "Medium", ""]}, {"question_id": "0085", "frontend_question_id": "0085", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximal-rectangle", "url_en": "https://leetcode.com/problems/maximal-rectangle", "relative_path_cn": "/solution/0000-0099/0085.Maximal%20Rectangle/README.md", "relative_path_en": "/solution/0000-0099/0085.Maximal%20Rectangle/README_EN.md", "title_cn": "\u6700\u5927\u77e9\u5f62", "title_en": "Maximal Rectangle", "question_title_slug": "maximal-rectangle", "content_en": "

    Given a rows x cols binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: matrix = [["1","0","1","0","0"],["1","0","1","1","1"],["1","1","1","1","1"],["1","0","0","1","0"]]\nOutput: 6\nExplanation: The maximal rectangle is shown in the above picture.\n
    \n\n

    Example 2:

    \n\n
    \nInput: matrix = []\nOutput: 0\n
    \n\n

    Example 3:

    \n\n
    \nInput: matrix = [["0"]]\nOutput: 0\n
    \n\n

    Example 4:

    \n\n
    \nInput: matrix = [["1"]]\nOutput: 1\n
    \n\n

    Example 5:

    \n\n
    \nInput: matrix = [["0","0"]]\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • rows == matrix.length
    • \n\t
    • cols == matrix[i].length
    • \n\t
    • 0 <= row, cols <= 200
    • \n\t
    • matrix[i][j] is '0' or '1'.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4ec5\u5305\u542b\u00a00 \u548c 1 \u3001\u5927\u5c0f\u4e3a rows x cols \u7684\u4e8c\u7ef4\u4e8c\u8fdb\u5236\u77e9\u9635\uff0c\u627e\u51fa\u53ea\u5305\u542b 1 \u7684\u6700\u5927\u77e9\u5f62\uff0c\u5e76\u8fd4\u56de\u5176\u9762\u79ef\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1amatrix = [[\"1\",\"0\",\"1\",\"0\",\"0\"],[\"1\",\"0\",\"1\",\"1\",\"1\"],[\"1\",\"1\",\"1\",\"1\",\"1\"],[\"1\",\"0\",\"0\",\"1\",\"0\"]]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u6700\u5927\u77e9\u5f62\u5982\u4e0a\u56fe\u6240\u793a\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1amatrix = []\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1amatrix = [[\"0\"]]\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1amatrix = [[\"1\"]]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1amatrix = [[\"0\",\"0\"]]\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • rows == matrix.length
    • \n\t
    • cols == matrix[0].length
    • \n\t
    • 0 <= row, cols <= 200
    • \n\t
    • matrix[i][j] \u4e3a '0' \u6216 '1'
    • \n
    \n", "tags_en": ["Stack", "Array", "Hash Table", "Dynamic Programming"], "tags_cn": ["\u6808", "\u6570\u7ec4", "\u54c8\u5e0c\u8868", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maximalRectangle(vector>& matrix) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maximalRectangle(char[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maximalRectangle(self, matrix):\n \"\"\"\n :type matrix: List[List[str]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maximalRectangle(self, matrix: List[List[str]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maximalRectangle(char** matrix, int matrixSize, int* matrixColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaximalRectangle(char[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {character[][]} matrix\n * @return {number}\n */\nvar maximalRectangle = function(matrix) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Character[][]} matrix\n# @return {Integer}\ndef maximal_rectangle(matrix)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maximalRectangle(_ matrix: [[Character]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maximalRectangle(matrix [][]byte) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maximalRectangle(matrix: Array[Array[Char]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maximalRectangle(matrix: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn maximal_rectangle(matrix: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $matrix\n * @return Integer\n */\n function maximalRectangle($matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maximalRectangle(matrix: string[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (maximal-rectangle matrix)\n (-> (listof (listof char?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0085](https://leetcode-cn.com/problems/maximal-rectangle)", "[\u6700\u5927\u77e9\u5f62](/solution/0000-0099/0085.Maximal%20Rectangle/README.md)", "`\u6808`,`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0085](https://leetcode.com/problems/maximal-rectangle)", "[Maximal Rectangle](/solution/0000-0099/0085.Maximal%20Rectangle/README_EN.md)", "`Stack`,`Array`,`Hash Table`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0084", "frontend_question_id": "0084", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/largest-rectangle-in-histogram", "url_en": "https://leetcode.com/problems/largest-rectangle-in-histogram", "relative_path_cn": "/solution/0000-0099/0084.Largest%20Rectangle%20in%20Histogram/README.md", "relative_path_en": "/solution/0000-0099/0084.Largest%20Rectangle%20in%20Histogram/README_EN.md", "title_cn": "\u67f1\u72b6\u56fe\u4e2d\u6700\u5927\u7684\u77e9\u5f62", "title_en": "Largest Rectangle in Histogram", "question_title_slug": "largest-rectangle-in-histogram", "content_en": "

    Given an array of integers heights representing the histogram's bar height where the width of each bar is 1, return the area of the largest rectangle in the histogram.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: heights = [2,1,5,6,2,3]\nOutput: 10\nExplanation: The above is a histogram where width of each bar is 1.\nThe largest rectangle is shown in the red area, which has an area = 10 units.\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: heights = [2,4]\nOutput: 4\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= heights.length <= 105
    • \n\t
    • 0 <= heights[i] <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a n \u4e2a\u975e\u8d1f\u6574\u6570\uff0c\u7528\u6765\u8868\u793a\u67f1\u72b6\u56fe\u4e2d\u5404\u4e2a\u67f1\u5b50\u7684\u9ad8\u5ea6\u3002\u6bcf\u4e2a\u67f1\u5b50\u5f7c\u6b64\u76f8\u90bb\uff0c\u4e14\u5bbd\u5ea6\u4e3a 1 \u3002

    \n\n

    \u6c42\u5728\u8be5\u67f1\u72b6\u56fe\u4e2d\uff0c\u80fd\u591f\u52fe\u52d2\u51fa\u6765\u7684\u77e9\u5f62\u7684\u6700\u5927\u9762\u79ef\u3002

    \n\n

     

    \n\n

    \n\n

    \u4ee5\u4e0a\u662f\u67f1\u72b6\u56fe\u7684\u793a\u4f8b\uff0c\u5176\u4e2d\u6bcf\u4e2a\u67f1\u5b50\u7684\u5bbd\u5ea6\u4e3a 1\uff0c\u7ed9\u5b9a\u7684\u9ad8\u5ea6\u4e3a [2,1,5,6,2,3]\u3002

    \n\n

     

    \n\n

    \n\n

    \u56fe\u4e2d\u9634\u5f71\u90e8\u5206\u4e3a\u6240\u80fd\u52fe\u52d2\u51fa\u7684\u6700\u5927\u77e9\u5f62\u9762\u79ef\uff0c\u5176\u9762\u79ef\u4e3a 10 \u4e2a\u5355\u4f4d\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: [2,1,5,6,2,3]\n\u8f93\u51fa: 10
    \n", "tags_en": ["Stack", "Array"], "tags_cn": ["\u6808", "\u6570\u7ec4"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int largestRectangleArea(vector& heights) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int largestRectangleArea(int[] heights) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def largestRectangleArea(self, heights):\n \"\"\"\n :type heights: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def largestRectangleArea(self, heights: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint largestRectangleArea(int* heights, int heightsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LargestRectangleArea(int[] heights) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} heights\n * @return {number}\n */\nvar largestRectangleArea = function(heights) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} heights\n# @return {Integer}\ndef largest_rectangle_area(heights)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func largestRectangleArea(_ heights: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func largestRectangleArea(heights []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def largestRectangleArea(heights: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun largestRectangleArea(heights: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn largest_rectangle_area(heights: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $heights\n * @return Integer\n */\n function largestRectangleArea($heights) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function largestRectangleArea(heights: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (largest-rectangle-area heights)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0084](https://leetcode-cn.com/problems/largest-rectangle-in-histogram)", "[\u67f1\u72b6\u56fe\u4e2d\u6700\u5927\u7684\u77e9\u5f62](/solution/0000-0099/0084.Largest%20Rectangle%20in%20Histogram/README.md)", "`\u6808`,`\u6570\u7ec4`", "\u56f0\u96be", ""], "md_table_row_en": ["[0084](https://leetcode.com/problems/largest-rectangle-in-histogram)", "[Largest Rectangle in Histogram](/solution/0000-0099/0084.Largest%20Rectangle%20in%20Histogram/README_EN.md)", "`Stack`,`Array`", "Hard", ""]}, {"question_id": "0083", "frontend_question_id": "0083", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list", "url_en": "https://leetcode.com/problems/remove-duplicates-from-sorted-list", "relative_path_cn": "/solution/0000-0099/0083.Remove%20Duplicates%20from%20Sorted%20List/README.md", "relative_path_en": "/solution/0000-0099/0083.Remove%20Duplicates%20from%20Sorted%20List/README_EN.md", "title_cn": "\u5220\u9664\u6392\u5e8f\u94fe\u8868\u4e2d\u7684\u91cd\u590d\u5143\u7d20", "title_en": "Remove Duplicates from Sorted List", "question_title_slug": "remove-duplicates-from-sorted-list", "content_en": "

    Given the head of a sorted linked list, delete all duplicates such that each element appears only once. Return the linked list sorted as well.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: head = [1,1,2]\nOutput: [1,2]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: head = [1,1,2,3,3]\nOutput: [1,2,3]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the list is in the range [0, 300].
    • \n\t
    • -100 <= Node.val <= 100
    • \n\t
    • The list is guaranteed to be sorted in ascending order.
    • \n
    \n", "content_cn": "

    \u5b58\u5728\u4e00\u4e2a\u6309\u5347\u5e8f\u6392\u5217\u7684\u94fe\u8868\uff0c\u7ed9\u4f60\u8fd9\u4e2a\u94fe\u8868\u7684\u5934\u8282\u70b9 head \uff0c\u8bf7\u4f60\u5220\u9664\u6240\u6709\u91cd\u590d\u7684\u5143\u7d20\uff0c\u4f7f\u6bcf\u4e2a\u5143\u7d20 \u53ea\u51fa\u73b0\u4e00\u6b21 \u3002

    \n\n

    \u8fd4\u56de\u540c\u6837\u6309\u5347\u5e8f\u6392\u5217\u7684\u7ed3\u679c\u94fe\u8868\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1ahead = [1,1,2]\n\u8f93\u51fa\uff1a[1,2]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1ahead = [1,1,2,3,3]\n\u8f93\u51fa\uff1a[1,2,3]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u94fe\u8868\u4e2d\u8282\u70b9\u6570\u76ee\u5728\u8303\u56f4 [0, 300] \u5185
    • \n\t
    • -100 <= Node.val <= 100
    • \n\t
    • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u94fe\u8868\u5df2\u7ecf\u6309\u5347\u5e8f\u6392\u5217
    • \n
    \n", "tags_en": ["Linked List"], "tags_cn": ["\u94fe\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n ListNode* deleteDuplicates(ListNode* head) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public ListNode deleteDuplicates(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def deleteDuplicates(self, head):\n \"\"\"\n :type head: ListNode\n :rtype: ListNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def deleteDuplicates(self, head: ListNode) -> ListNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nstruct ListNode* deleteDuplicates(struct ListNode* head){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public ListNode DeleteDuplicates(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} head\n * @return {ListNode}\n */\nvar deleteDuplicates = function(head) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode} head\n# @return {ListNode}\ndef delete_duplicates(head)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func deleteDuplicates(_ head: ListNode?) -> ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc deleteDuplicates(head *ListNode) *ListNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def deleteDuplicates(head: ListNode): ListNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun deleteDuplicates(head: ListNode?): ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn delete_duplicates(head: Option>) -> Option> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @return ListNode\n */\n function deleteDuplicates($head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction deleteDuplicates(head: ListNode | null): ListNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (delete-duplicates head)\n (-> (or/c list-node? #f) (or/c list-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0083](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list)", "[\u5220\u9664\u6392\u5e8f\u94fe\u8868\u4e2d\u7684\u91cd\u590d\u5143\u7d20](/solution/0000-0099/0083.Remove%20Duplicates%20from%20Sorted%20List/README.md)", "`\u94fe\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0083](https://leetcode.com/problems/remove-duplicates-from-sorted-list)", "[Remove Duplicates from Sorted List](/solution/0000-0099/0083.Remove%20Duplicates%20from%20Sorted%20List/README_EN.md)", "`Linked List`", "Easy", ""]}, {"question_id": "0082", "frontend_question_id": "0082", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list-ii", "url_en": "https://leetcode.com/problems/remove-duplicates-from-sorted-list-ii", "relative_path_cn": "/solution/0000-0099/0082.Remove%20Duplicates%20from%20Sorted%20List%20II/README.md", "relative_path_en": "/solution/0000-0099/0082.Remove%20Duplicates%20from%20Sorted%20List%20II/README_EN.md", "title_cn": "\u5220\u9664\u6392\u5e8f\u94fe\u8868\u4e2d\u7684\u91cd\u590d\u5143\u7d20 II", "title_en": "Remove Duplicates from Sorted List II", "question_title_slug": "remove-duplicates-from-sorted-list-ii", "content_en": "

    Given the head of a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. Return the linked list sorted as well.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: head = [1,2,3,3,4,4,5]\nOutput: [1,2,5]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: head = [1,1,1,2,3]\nOutput: [2,3]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the list is in the range [0, 300].
    • \n\t
    • -100 <= Node.val <= 100
    • \n\t
    • The list is guaranteed to be sorted in ascending order.
    • \n
    \n", "content_cn": "

    \u5b58\u5728\u4e00\u4e2a\u6309\u5347\u5e8f\u6392\u5217\u7684\u94fe\u8868\uff0c\u7ed9\u4f60\u8fd9\u4e2a\u94fe\u8868\u7684\u5934\u8282\u70b9 head \uff0c\u8bf7\u4f60\u5220\u9664\u94fe\u8868\u4e2d\u6240\u6709\u5b58\u5728\u6570\u5b57\u91cd\u590d\u60c5\u51b5\u7684\u8282\u70b9\uff0c\u53ea\u4fdd\u7559\u539f\u59cb\u94fe\u8868\u4e2d\u00a0\u6ca1\u6709\u91cd\u590d\u51fa\u73b0\u00a0\u7684\u6570\u5b57\u3002

    \n\n

    \u8fd4\u56de\u540c\u6837\u6309\u5347\u5e8f\u6392\u5217\u7684\u7ed3\u679c\u94fe\u8868\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1ahead = [1,2,3,3,4,4,5]\n\u8f93\u51fa\uff1a[1,2,5]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1ahead = [1,1,1,2,3]\n\u8f93\u51fa\uff1a[2,3]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u94fe\u8868\u4e2d\u8282\u70b9\u6570\u76ee\u5728\u8303\u56f4 [0, 300] \u5185
    • \n\t
    • -100 <= Node.val <= 100
    • \n\t
    • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u94fe\u8868\u5df2\u7ecf\u6309\u5347\u5e8f\u6392\u5217
    • \n
    \n", "tags_en": ["Linked List"], "tags_cn": ["\u94fe\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n ListNode* deleteDuplicates(ListNode* head) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public ListNode deleteDuplicates(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def deleteDuplicates(self, head):\n \"\"\"\n :type head: ListNode\n :rtype: ListNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def deleteDuplicates(self, head: ListNode) -> ListNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nstruct ListNode* deleteDuplicates(struct ListNode* head){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public ListNode DeleteDuplicates(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} head\n * @return {ListNode}\n */\nvar deleteDuplicates = function(head) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode} head\n# @return {ListNode}\ndef delete_duplicates(head)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func deleteDuplicates(_ head: ListNode?) -> ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc deleteDuplicates(head *ListNode) *ListNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def deleteDuplicates(head: ListNode): ListNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun deleteDuplicates(head: ListNode?): ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn delete_duplicates(head: Option>) -> Option> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @return ListNode\n */\n function deleteDuplicates($head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction deleteDuplicates(head: ListNode | null): ListNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (delete-duplicates head)\n (-> (or/c list-node? #f) (or/c list-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0082](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list-ii)", "[\u5220\u9664\u6392\u5e8f\u94fe\u8868\u4e2d\u7684\u91cd\u590d\u5143\u7d20 II](/solution/0000-0099/0082.Remove%20Duplicates%20from%20Sorted%20List%20II/README.md)", "`\u94fe\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0082](https://leetcode.com/problems/remove-duplicates-from-sorted-list-ii)", "[Remove Duplicates from Sorted List II](/solution/0000-0099/0082.Remove%20Duplicates%20from%20Sorted%20List%20II/README_EN.md)", "`Linked List`", "Medium", ""]}, {"question_id": "0081", "frontend_question_id": "0081", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/search-in-rotated-sorted-array-ii", "url_en": "https://leetcode.com/problems/search-in-rotated-sorted-array-ii", "relative_path_cn": "/solution/0000-0099/0081.Search%20in%20Rotated%20Sorted%20Array%20II/README.md", "relative_path_en": "/solution/0000-0099/0081.Search%20in%20Rotated%20Sorted%20Array%20II/README_EN.md", "title_cn": "\u641c\u7d22\u65cb\u8f6c\u6392\u5e8f\u6570\u7ec4 II", "title_en": "Search in Rotated Sorted Array II", "question_title_slug": "search-in-rotated-sorted-array-ii", "content_en": "

    There is an integer array nums sorted in non-decreasing order (not necessarily with distinct values).

    \n\n

    Before being passed to your function, nums is rotated at an unknown pivot index k (0 <= k < nums.length) such that the resulting array is [nums[k], nums[k+1], ..., nums[n-1], nums[0], nums[1], ..., nums[k-1]] (0-indexed). For example, [0,1,2,4,4,4,5,6,6,7] might be rotated at pivot index 5 and become [4,5,6,6,7,0,1,2,4,4].

    \n\n

    Given the array nums after the rotation and an integer target, return true if target is in nums, or false if it is not in nums.

    \n\n

    You must decrease the overall operation steps as much as possible.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [2,5,6,0,0,1,2], target = 0\nOutput: true\n

    Example 2:

    \n
    Input: nums = [2,5,6,0,0,1,2], target = 3\nOutput: false\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 5000
    • \n\t
    • -104 <= nums[i] <= 104
    • \n\t
    • nums is guaranteed to be rotated at some pivot.
    • \n\t
    • -104 <= target <= 104
    • \n
    \n\n

     

    \n

    Follow up: This problem is similar to Search in Rotated Sorted Array, but nums may contain duplicates. Would this affect the runtime complexity? How and why?

    \n", "content_cn": "

    \u5df2\u77e5\u5b58\u5728\u4e00\u4e2a\u6309\u975e\u964d\u5e8f\u6392\u5217\u7684\u6574\u6570\u6570\u7ec4 nums \uff0c\u6570\u7ec4\u4e2d\u7684\u503c\u4e0d\u5fc5\u4e92\u4e0d\u76f8\u540c\u3002

    \n\n

    \u5728\u4f20\u9012\u7ed9\u51fd\u6570\u4e4b\u524d\uff0cnums \u5728\u9884\u5148\u672a\u77e5\u7684\u67d0\u4e2a\u4e0b\u6807 k\uff080 <= k < nums.length\uff09\u4e0a\u8fdb\u884c\u4e86 \u65cb\u8f6c \uff0c\u4f7f\u6570\u7ec4\u53d8\u4e3a [nums[k], nums[k+1], ..., nums[n-1], nums[0], nums[1], ..., nums[k-1]]\uff08\u4e0b\u6807 \u4ece 0 \u5f00\u59cb \u8ba1\u6570\uff09\u3002\u4f8b\u5982\uff0c [0,1,2,4,4,4,5,6,6,7] \u5728\u4e0b\u6807 5 \u5904\u7ecf\u65cb\u8f6c\u540e\u53ef\u80fd\u53d8\u4e3a [4,5,6,6,7,0,1,2,4,4] \u3002

    \n\n

    \u7ed9\u4f60 \u65cb\u8f6c\u540e \u7684\u6570\u7ec4 nums \u548c\u4e00\u4e2a\u6574\u6570 target \uff0c\u8bf7\u4f60\u7f16\u5199\u4e00\u4e2a\u51fd\u6570\u6765\u5224\u65ad\u7ed9\u5b9a\u7684\u76ee\u6807\u503c\u662f\u5426\u5b58\u5728\u4e8e\u6570\u7ec4\u4e2d\u3002\u5982\u679c nums \u4e2d\u5b58\u5728\u8fd9\u4e2a\u76ee\u6807\u503c target \uff0c\u5219\u8fd4\u56de true \uff0c\u5426\u5219\u8fd4\u56de false \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\u00a01\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [2,5,6,0,0,1,2], target = 0\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b\u00a02\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [2,5,6,0,0,1,2], target = 3\n\u8f93\u51fa\uff1afalse
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 5000
    • \n\t
    • -104 <= nums[i] <= 104
    • \n\t
    • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1 nums \u5728\u9884\u5148\u672a\u77e5\u7684\u67d0\u4e2a\u4e0b\u6807\u4e0a\u8fdb\u884c\u4e86\u65cb\u8f6c
    • \n\t
    • -104 <= target <= 104
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u8fd9\u662f \u641c\u7d22\u65cb\u8f6c\u6392\u5e8f\u6570\u7ec4\u00a0\u7684\u5ef6\u4f38\u9898\u76ee\uff0c\u672c\u9898\u4e2d\u7684\u00a0nums\u00a0 \u53ef\u80fd\u5305\u542b\u91cd\u590d\u5143\u7d20\u3002
    • \n\t
    • \u8fd9\u4f1a\u5f71\u54cd\u5230\u7a0b\u5e8f\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u5417\uff1f\u4f1a\u6709\u600e\u6837\u7684\u5f71\u54cd\uff0c\u4e3a\u4ec0\u4e48\uff1f
    • \n
    \n", "tags_en": ["Array", "Binary Search"], "tags_cn": ["\u6570\u7ec4", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool search(vector& nums, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean search(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def search(self, nums, target):\n \"\"\"\n :type nums: List[int]\n :type target: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def search(self, nums: List[int], target: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool search(int* nums, int numsSize, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool Search(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} target\n * @return {boolean}\n */\nvar search = function(nums, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} target\n# @return {Boolean}\ndef search(nums, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func search(_ nums: [Int], _ target: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func search(nums []int, target int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def search(nums: Array[Int], target: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun search(nums: IntArray, target: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn search(nums: Vec, target: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $target\n * @return Boolean\n */\n function search($nums, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function search(nums: number[], target: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (search nums target)\n (-> (listof exact-integer?) exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0081](https://leetcode-cn.com/problems/search-in-rotated-sorted-array-ii)", "[\u641c\u7d22\u65cb\u8f6c\u6392\u5e8f\u6570\u7ec4 II](/solution/0000-0099/0081.Search%20in%20Rotated%20Sorted%20Array%20II/README.md)", "`\u6570\u7ec4`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0081](https://leetcode.com/problems/search-in-rotated-sorted-array-ii)", "[Search in Rotated Sorted Array II](/solution/0000-0099/0081.Search%20in%20Rotated%20Sorted%20Array%20II/README_EN.md)", "`Array`,`Binary Search`", "Medium", ""]}, {"question_id": "0080", "frontend_question_id": "0080", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array-ii", "url_en": "https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii", "relative_path_cn": "/solution/0000-0099/0080.Remove%20Duplicates%20from%20Sorted%20Array%20II/README.md", "relative_path_en": "/solution/0000-0099/0080.Remove%20Duplicates%20from%20Sorted%20Array%20II/README_EN.md", "title_cn": "\u5220\u9664\u6709\u5e8f\u6570\u7ec4\u4e2d\u7684\u91cd\u590d\u9879 II", "title_en": "Remove Duplicates from Sorted Array II", "question_title_slug": "remove-duplicates-from-sorted-array-ii", "content_en": "

    Given a sorted array nums, remove the duplicates in-place such that duplicates appeared at most twice and return the new length.

    \n\n

    Do not allocate extra space for another array; you must do this by modifying the input array in-place with O(1) extra memory.

    \n\n

    Clarification:

    \n\n

    Confused why the returned value is an integer, but your answer is an array?

    \n\n

    Note that the input array is passed in by reference, which means a modification to the input array will be known to the caller.

    \n\n

    Internally you can think of this:

    \n\n
    \n// nums is passed in by reference. (i.e., without making a copy)\nint len = removeDuplicates(nums);\n\n// any modification to nums in your function would be known by the caller.\n// using the length returned by your function, it prints the first len elements.\nfor (int i = 0; i < len; i++) {\n    print(nums[i]);\n}\n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,1,1,2,2,3]\nOutput: 5, nums = [1,1,2,2,3]\nExplanation: Your function should return length = 5, with the first five elements of nums being 1, 1, 2, 2 and 3 respectively. It doesn't matter what you leave beyond the returned length.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [0,0,1,1,1,1,2,3,3]\nOutput: 7, nums = [0,0,1,1,2,3,3]\nExplanation: Your function should return length = 7, with the first seven elements of nums being modified to 0, 0, 1, 1, 2, 3 and 3 respectively. It doesn't matter what values are set beyond the returned length.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 3 * 104
    • \n\t
    • -104 <= nums[i] <= 104
    • \n\t
    • nums is sorted in ascending order.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6709\u5e8f\u6570\u7ec4 nums \uff0c\u8bf7\u4f60 \u539f\u5730 \u5220\u9664\u91cd\u590d\u51fa\u73b0\u7684\u5143\u7d20\uff0c\u4f7f\u6bcf\u4e2a\u5143\u7d20 \u6700\u591a\u51fa\u73b0\u4e24\u6b21 \uff0c\u8fd4\u56de\u5220\u9664\u540e\u6570\u7ec4\u7684\u65b0\u957f\u5ea6\u3002

    \n\n

    \u4e0d\u8981\u4f7f\u7528\u989d\u5916\u7684\u6570\u7ec4\u7a7a\u95f4\uff0c\u4f60\u5fc5\u987b\u5728 \u539f\u5730 \u4fee\u6539\u8f93\u5165\u6570\u7ec4 \u5e76\u5728\u4f7f\u7528 O(1) \u989d\u5916\u7a7a\u95f4\u7684\u6761\u4ef6\u4e0b\u5b8c\u6210\u3002

    \n\n

    \u00a0

    \n\n

    \u8bf4\u660e\uff1a

    \n\n

    \u4e3a\u4ec0\u4e48\u8fd4\u56de\u6570\u503c\u662f\u6574\u6570\uff0c\u4f46\u8f93\u51fa\u7684\u7b54\u6848\u662f\u6570\u7ec4\u5462\uff1f

    \n\n

    \u8bf7\u6ce8\u610f\uff0c\u8f93\u5165\u6570\u7ec4\u662f\u4ee5\u300c\u5f15\u7528\u300d\u65b9\u5f0f\u4f20\u9012\u7684\uff0c\u8fd9\u610f\u5473\u7740\u5728\u51fd\u6570\u91cc\u4fee\u6539\u8f93\u5165\u6570\u7ec4\u5bf9\u4e8e\u8c03\u7528\u8005\u662f\u53ef\u89c1\u7684\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u60f3\u8c61\u5185\u90e8\u64cd\u4f5c\u5982\u4e0b:

    \n\n
    \n// nums \u662f\u4ee5\u201c\u5f15\u7528\u201d\u65b9\u5f0f\u4f20\u9012\u7684\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u4e0d\u5bf9\u5b9e\u53c2\u505a\u4efb\u4f55\u62f7\u8d1d\nint len = removeDuplicates(nums);\n\n// \u5728\u51fd\u6570\u91cc\u4fee\u6539\u8f93\u5165\u6570\u7ec4\u5bf9\u4e8e\u8c03\u7528\u8005\u662f\u53ef\u89c1\u7684\u3002\n// \u6839\u636e\u4f60\u7684\u51fd\u6570\u8fd4\u56de\u7684\u957f\u5ea6, \u5b83\u4f1a\u6253\u5370\u51fa\u6570\u7ec4\u4e2d \u8be5\u957f\u5ea6\u8303\u56f4\u5185 \u7684\u6240\u6709\u5143\u7d20\u3002\nfor (int i = 0; i < len; i++) {\n\u00a0 \u00a0 print(nums[i]);\n}\n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,1,1,2,2,3]\n\u8f93\u51fa\uff1a5, nums = [1,1,2,2,3]\n\u89e3\u91ca\uff1a\u51fd\u6570\u5e94\u8fd4\u56de\u65b0\u957f\u5ea6 length = 5, \u5e76\u4e14\u539f\u6570\u7ec4\u7684\u524d\u4e94\u4e2a\u5143\u7d20\u88ab\u4fee\u6539\u4e3a 1, 1, 2, 2, 3 \u3002 \u4e0d\u9700\u8981\u8003\u8651\u6570\u7ec4\u4e2d\u8d85\u51fa\u65b0\u957f\u5ea6\u540e\u9762\u7684\u5143\u7d20\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [0,0,1,1,1,1,2,3,3]\n\u8f93\u51fa\uff1a7, nums = [0,0,1,1,2,3,3]\n\u89e3\u91ca\uff1a\u51fd\u6570\u5e94\u8fd4\u56de\u65b0\u957f\u5ea6 length = 7, \u5e76\u4e14\u539f\u6570\u7ec4\u7684\u524d\u4e94\u4e2a\u5143\u7d20\u88ab\u4fee\u6539\u4e3a\u00a00, 0, 1, 1, 2, 3, 3 \u3002 \u4e0d\u9700\u8981\u8003\u8651\u6570\u7ec4\u4e2d\u8d85\u51fa\u65b0\u957f\u5ea6\u540e\u9762\u7684\u5143\u7d20\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 3 * 104
    • \n\t
    • -104 <= nums[i] <= 104
    • \n\t
    • nums \u5df2\u6309\u5347\u5e8f\u6392\u5217
    • \n
    \n", "tags_en": ["Array", "Two Pointers"], "tags_cn": ["\u6570\u7ec4", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int removeDuplicates(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int removeDuplicates(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def removeDuplicates(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def removeDuplicates(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint removeDuplicates(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int RemoveDuplicates(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar removeDuplicates = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef remove_duplicates(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func removeDuplicates(_ nums: inout [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func removeDuplicates(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def removeDuplicates(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun removeDuplicates(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn remove_duplicates(nums: &mut Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function removeDuplicates(&$nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function removeDuplicates(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0080](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array-ii)", "[\u5220\u9664\u6709\u5e8f\u6570\u7ec4\u4e2d\u7684\u91cd\u590d\u9879 II](/solution/0000-0099/0080.Remove%20Duplicates%20from%20Sorted%20Array%20II/README.md)", "`\u6570\u7ec4`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0080](https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii)", "[Remove Duplicates from Sorted Array II](/solution/0000-0099/0080.Remove%20Duplicates%20from%20Sorted%20Array%20II/README_EN.md)", "`Array`,`Two Pointers`", "Medium", ""]}, {"question_id": "0079", "frontend_question_id": "0079", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/word-search", "url_en": "https://leetcode.com/problems/word-search", "relative_path_cn": "/solution/0000-0099/0079.Word%20Search/README.md", "relative_path_en": "/solution/0000-0099/0079.Word%20Search/README_EN.md", "title_cn": "\u5355\u8bcd\u641c\u7d22", "title_en": "Word Search", "question_title_slug": "word-search", "content_en": "

    Given an m x n grid of characters board and a string word, return true if word exists in the grid.

    \n\n

    The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically neighboring. The same letter cell may not be used more than once.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "ABCCED"\nOutput: true\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "SEE"\nOutput: true\n
    \n\n

    Example 3:

    \n\"\"\n
    \nInput: board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "ABCB"\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == board.length
    • \n\t
    • n = board[i].length
    • \n\t
    • 1 <= m, n <= 6
    • \n\t
    • 1 <= word.length <= 15
    • \n\t
    • board and word consists of only lowercase and uppercase English letters.
    • \n
    \n\n

     

    \n

    Follow up: Could you use search pruning to make your solution faster with a larger board?

    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u00a0m x n \u4e8c\u7ef4\u5b57\u7b26\u7f51\u683c\u00a0board \u548c\u4e00\u4e2a\u5b57\u7b26\u4e32\u5355\u8bcd\u00a0word \u3002\u5982\u679c\u00a0word \u5b58\u5728\u4e8e\u7f51\u683c\u4e2d\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n

    \u5355\u8bcd\u5fc5\u987b\u6309\u7167\u5b57\u6bcd\u987a\u5e8f\uff0c\u901a\u8fc7\u76f8\u90bb\u7684\u5355\u5143\u683c\u5185\u7684\u5b57\u6bcd\u6784\u6210\uff0c\u5176\u4e2d\u201c\u76f8\u90bb\u201d\u5355\u5143\u683c\u662f\u90a3\u4e9b\u6c34\u5e73\u76f8\u90bb\u6216\u5782\u76f4\u76f8\u90bb\u7684\u5355\u5143\u683c\u3002\u540c\u4e00\u4e2a\u5355\u5143\u683c\u5185\u7684\u5b57\u6bcd\u4e0d\u5141\u8bb8\u88ab\u91cd\u590d\u4f7f\u7528\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aboard = [[\"A\",\"B\",\"C\",\"E\"],[\"S\",\"F\",\"C\",\"S\"],[\"A\",\"D\",\"E\",\"E\"]], word = \"ABCCED\"\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aboard = [[\"A\",\"B\",\"C\",\"E\"],[\"S\",\"F\",\"C\",\"S\"],[\"A\",\"D\",\"E\",\"E\"]], word = \"SEE\"\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aboard = [[\"A\",\"B\",\"C\",\"E\"],[\"S\",\"F\",\"C\",\"S\"],[\"A\",\"D\",\"E\",\"E\"]], word = \"ABCB\"\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == board.length
    • \n\t
    • n = board[i].length
    • \n\t
    • 1 <= m, n <= 6
    • \n\t
    • 1 <= word.length <= 15
    • \n\t
    • board \u548c word \u4ec5\u7531\u5927\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u53ef\u4ee5\u4f7f\u7528\u641c\u7d22\u526a\u679d\u7684\u6280\u672f\u6765\u4f18\u5316\u89e3\u51b3\u65b9\u6848\uff0c\u4f7f\u5176\u5728 board \u66f4\u5927\u7684\u60c5\u51b5\u4e0b\u53ef\u4ee5\u66f4\u5feb\u89e3\u51b3\u95ee\u9898\uff1f

    \n", "tags_en": ["Array", "Backtracking"], "tags_cn": ["\u6570\u7ec4", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool exist(vector>& board, string word) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean exist(char[][] board, String word) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def exist(self, board, word):\n \"\"\"\n :type board: List[List[str]]\n :type word: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def exist(self, board: List[List[str]], word: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool exist(char** board, int boardSize, int* boardColSize, char * word){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool Exist(char[][] board, string word) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {character[][]} board\n * @param {string} word\n * @return {boolean}\n */\nvar exist = function(board, word) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Character[][]} board\n# @param {String} word\n# @return {Boolean}\ndef exist(board, word)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func exist(_ board: [[Character]], _ word: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func exist(board [][]byte, word string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def exist(board: Array[Array[Char]], word: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun exist(board: Array, word: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn exist(board: Vec>, word: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $board\n * @param String $word\n * @return Boolean\n */\n function exist($board, $word) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function exist(board: string[][], word: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (exist board word)\n (-> (listof (listof char?)) string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0079](https://leetcode-cn.com/problems/word-search)", "[\u5355\u8bcd\u641c\u7d22](/solution/0000-0099/0079.Word%20Search/README.md)", "`\u6570\u7ec4`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0079](https://leetcode.com/problems/word-search)", "[Word Search](/solution/0000-0099/0079.Word%20Search/README_EN.md)", "`Array`,`Backtracking`", "Medium", ""]}, {"question_id": "0078", "frontend_question_id": "0078", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/subsets", "url_en": "https://leetcode.com/problems/subsets", "relative_path_cn": "/solution/0000-0099/0078.Subsets/README.md", "relative_path_en": "/solution/0000-0099/0078.Subsets/README_EN.md", "title_cn": "\u5b50\u96c6", "title_en": "Subsets", "question_title_slug": "subsets", "content_en": "

    Given an integer array nums of unique elements, return all possible subsets (the power set).

    \n\n

    The solution set must not contain duplicate subsets. Return the solution in any order.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,2,3]\nOutput: [[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]]\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [0]\nOutput: [[],[0]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 10
    • \n\t
    • -10 <= nums[i] <= 10
    • \n\t
    • All the numbers of nums are unique.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u00a0nums \uff0c\u6570\u7ec4\u4e2d\u7684\u5143\u7d20 \u4e92\u4e0d\u76f8\u540c \u3002\u8fd4\u56de\u8be5\u6570\u7ec4\u6240\u6709\u53ef\u80fd\u7684\u5b50\u96c6\uff08\u5e42\u96c6\uff09\u3002

    \n\n

    \u89e3\u96c6 \u4e0d\u80fd \u5305\u542b\u91cd\u590d\u7684\u5b50\u96c6\u3002\u4f60\u53ef\u4ee5\u6309 \u4efb\u610f\u987a\u5e8f \u8fd4\u56de\u89e3\u96c6\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,3]\n\u8f93\u51fa\uff1a[[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [0]\n\u8f93\u51fa\uff1a[[],[0]]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 10
    • \n\t
    • -10 <= nums[i] <= 10
    • \n\t
    • nums \u4e2d\u7684\u6240\u6709\u5143\u7d20 \u4e92\u4e0d\u76f8\u540c
    • \n
    \n", "tags_en": ["Bit Manipulation", "Array", "Backtracking"], "tags_cn": ["\u4f4d\u8fd0\u7b97", "\u6570\u7ec4", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> subsets(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> subsets(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def subsets(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def subsets(self, nums: List[int]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** subsets(int* nums, int numsSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> Subsets(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number[][]}\n */\nvar subsets = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer[][]}\ndef subsets(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func subsets(_ nums: [Int]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func subsets(nums []int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def subsets(nums: Array[Int]): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun subsets(nums: IntArray): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn subsets(nums: Vec) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer[][]\n */\n function subsets($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function subsets(nums: number[]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (subsets nums)\n (-> (listof exact-integer?) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0078](https://leetcode-cn.com/problems/subsets)", "[\u5b50\u96c6](/solution/0000-0099/0078.Subsets/README.md)", "`\u4f4d\u8fd0\u7b97`,`\u6570\u7ec4`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0078](https://leetcode.com/problems/subsets)", "[Subsets](/solution/0000-0099/0078.Subsets/README_EN.md)", "`Bit Manipulation`,`Array`,`Backtracking`", "Medium", ""]}, {"question_id": "0077", "frontend_question_id": "0077", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/combinations", "url_en": "https://leetcode.com/problems/combinations", "relative_path_cn": "/solution/0000-0099/0077.Combinations/README.md", "relative_path_en": "/solution/0000-0099/0077.Combinations/README_EN.md", "title_cn": "\u7ec4\u5408", "title_en": "Combinations", "question_title_slug": "combinations", "content_en": "

    Given two integers n and k, return all possible combinations of k numbers out of the range [1, n].

    \n\n

    You may return the answer in any order.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 4, k = 2\nOutput:\n[\n  [2,4],\n  [3,4],\n  [2,3],\n  [1,2],\n  [1,3],\n  [1,4],\n]\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 1, k = 1\nOutput: [[1]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 20
    • \n\t
    • 1 <= k <= n
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u6574\u6570 n \u548c k\uff0c\u8fd4\u56de 1 ... n \u4e2d\u6240\u6709\u53ef\u80fd\u7684 k \u4e2a\u6570\u7684\u7ec4\u5408\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: n = 4, k = 2\n\u8f93\u51fa:\n[\n  [2,4],\n  [3,4],\n  [2,3],\n  [1,2],\n  [1,3],\n  [1,4],\n]
    \n", "tags_en": ["Backtracking"], "tags_cn": ["\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> combine(int n, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> combine(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def combine(self, n, k):\n \"\"\"\n :type n: int\n :type k: int\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def combine(self, n: int, k: int) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** combine(int n, int k, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> Combine(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} k\n * @return {number[][]}\n */\nvar combine = function(n, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} k\n# @return {Integer[][]}\ndef combine(n, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func combine(_ n: Int, _ k: Int) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func combine(n int, k int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def combine(n: Int, k: Int): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun combine(n: Int, k: Int): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn combine(n: i32, k: i32) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $k\n * @return Integer[][]\n */\n function combine($n, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function combine(n: number, k: number): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (combine n k)\n (-> exact-integer? exact-integer? (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0077](https://leetcode-cn.com/problems/combinations)", "[\u7ec4\u5408](/solution/0000-0099/0077.Combinations/README.md)", "`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0077](https://leetcode.com/problems/combinations)", "[Combinations](/solution/0000-0099/0077.Combinations/README_EN.md)", "`Backtracking`", "Medium", ""]}, {"question_id": "0076", "frontend_question_id": "0076", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-window-substring", "url_en": "https://leetcode.com/problems/minimum-window-substring", "relative_path_cn": "/solution/0000-0099/0076.Minimum%20Window%20Substring/README.md", "relative_path_en": "/solution/0000-0099/0076.Minimum%20Window%20Substring/README_EN.md", "title_cn": "\u6700\u5c0f\u8986\u76d6\u5b50\u4e32", "title_en": "Minimum Window Substring", "question_title_slug": "minimum-window-substring", "content_en": "

    Given two strings s and t of lengths m and n respectively, return the minimum window substring of s such that every character in t (including duplicates) is included in the window. If there is no such substring, return the empty string "".

    \n\n

    The testcases will be generated such that the answer is unique.

    \n\n

    A substring is a contiguous sequence of characters within the string.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "ADOBECODEBANC", t = "ABC"\nOutput: "BANC"\nExplanation: The minimum window substring "BANC" includes 'A', 'B', and 'C' from string t.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "a", t = "a"\nOutput: "a"\nExplanation: The entire string s is the minimum window.\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "a", t = "aa"\nOutput: ""\nExplanation: Both 'a's from t must be included in the window.\nSince the largest window of s only has one 'a', return empty string.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == s.length
    • \n\t
    • n == t.length
    • \n\t
    • 1 <= m, n <= 105
    • \n\t
    • s and t consist of uppercase and lowercase English letters.
    • \n
    \n\n

     

    \nFollow up: Could you find an algorithm that runs in O(m + n) time?", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \u3001\u4e00\u4e2a\u5b57\u7b26\u4e32 t \u3002\u8fd4\u56de s \u4e2d\u6db5\u76d6 t \u6240\u6709\u5b57\u7b26\u7684\u6700\u5c0f\u5b50\u4e32\u3002\u5982\u679c s \u4e2d\u4e0d\u5b58\u5728\u6db5\u76d6 t \u6240\u6709\u5b57\u7b26\u7684\u5b50\u4e32\uff0c\u5219\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32 \"\" \u3002

    \n\n

    \u6ce8\u610f\uff1a\u5982\u679c s \u4e2d\u5b58\u5728\u8fd9\u6837\u7684\u5b50\u4e32\uff0c\u6211\u4eec\u4fdd\u8bc1\u5b83\u662f\u552f\u4e00\u7684\u7b54\u6848\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"ADOBECODEBANC\", t = \"ABC\"\n\u8f93\u51fa\uff1a\"BANC\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"a\", t = \"a\"\n\u8f93\u51fa\uff1a\"a\"\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length, t.length <= 105
    • \n\t
    • s \u548c t \u7531\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n\n

    \u00a0

    \n\u8fdb\u9636\uff1a\u4f60\u80fd\u8bbe\u8ba1\u4e00\u4e2a\u5728 o(n) \u65f6\u95f4\u5185\u89e3\u51b3\u6b64\u95ee\u9898\u7684\u7b97\u6cd5\u5417\uff1f", "tags_en": ["Hash Table", "Two Pointers", "String", "Sliding Window"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u53cc\u6307\u9488", "\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string minWindow(string s, string t) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String minWindow(String s, String t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minWindow(self, s, t):\n \"\"\"\n :type s: str\n :type t: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minWindow(self, s: str, t: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * minWindow(char * s, char * t){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string MinWindow(string s, string t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string} t\n * @return {string}\n */\nvar minWindow = function(s, t) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String} t\n# @return {String}\ndef min_window(s, t)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minWindow(_ s: String, _ t: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minWindow(s string, t string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minWindow(s: String, t: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minWindow(s: String, t: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_window(s: String, t: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String $t\n * @return String\n */\n function minWindow($s, $t) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minWindow(s: string, t: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-window s t)\n (-> string? string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0076](https://leetcode-cn.com/problems/minimum-window-substring)", "[\u6700\u5c0f\u8986\u76d6\u5b50\u4e32](/solution/0000-0099/0076.Minimum%20Window%20Substring/README.md)", "`\u54c8\u5e0c\u8868`,`\u53cc\u6307\u9488`,`\u5b57\u7b26\u4e32`", "\u56f0\u96be", ""], "md_table_row_en": ["[0076](https://leetcode.com/problems/minimum-window-substring)", "[Minimum Window Substring](/solution/0000-0099/0076.Minimum%20Window%20Substring/README_EN.md)", "`Hash Table`,`Two Pointers`,`String`,`Sliding Window`", "Hard", ""]}, {"question_id": "0075", "frontend_question_id": "0075", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sort-colors", "url_en": "https://leetcode.com/problems/sort-colors", "relative_path_cn": "/solution/0000-0099/0075.Sort%20Colors/README.md", "relative_path_en": "/solution/0000-0099/0075.Sort%20Colors/README_EN.md", "title_cn": "\u989c\u8272\u5206\u7c7b", "title_en": "Sort Colors", "question_title_slug": "sort-colors", "content_en": "

    Given an array nums with n objects colored red, white, or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white, and blue.

    \n\n

    We will use the integers 0, 1, and 2 to represent the color red, white, and blue, respectively.

    \n\n

    You must solve this problem without using the library's sort function.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [2,0,2,1,1,0]\nOutput: [0,0,1,1,2,2]\n

    Example 2:

    \n
    Input: nums = [2,0,1]\nOutput: [0,1,2]\n

    Example 3:

    \n
    Input: nums = [0]\nOutput: [0]\n

    Example 4:

    \n
    Input: nums = [1]\nOutput: [1]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= n <= 300
    • \n\t
    • nums[i] is 0, 1, or 2.
    • \n
    \n\n

     

    \n

    Follow up: Could you come up with a one-pass algorithm using only constant extra space?

    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5305\u542b\u7ea2\u8272\u3001\u767d\u8272\u548c\u84dd\u8272\uff0c\u4e00\u5171\u00a0n \u4e2a\u5143\u7d20\u7684\u6570\u7ec4\uff0c\u539f\u5730\u5bf9\u5b83\u4eec\u8fdb\u884c\u6392\u5e8f\uff0c\u4f7f\u5f97\u76f8\u540c\u989c\u8272\u7684\u5143\u7d20\u76f8\u90bb\uff0c\u5e76\u6309\u7167\u7ea2\u8272\u3001\u767d\u8272\u3001\u84dd\u8272\u987a\u5e8f\u6392\u5217\u3002

    \n\n

    \u6b64\u9898\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u6574\u6570 0\u3001\u00a01 \u548c 2 \u5206\u522b\u8868\u793a\u7ea2\u8272\u3001\u767d\u8272\u548c\u84dd\u8272\u3002

    \n\n
      \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [2,0,2,1,1,0]\n\u8f93\u51fa\uff1a[0,0,1,1,2,2]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [2,0,1]\n\u8f93\u51fa\uff1a[0,1,2]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [0]\n\u8f93\u51fa\uff1a[0]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1]\n\u8f93\u51fa\uff1a[1]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == nums.length
    • \n\t
    • 1 <= n <= 300
    • \n\t
    • nums[i] \u4e3a 0\u30011 \u6216 2
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u4f60\u53ef\u4ee5\u4e0d\u4f7f\u7528\u4ee3\u7801\u5e93\u4e2d\u7684\u6392\u5e8f\u51fd\u6570\u6765\u89e3\u51b3\u8fd9\u9053\u9898\u5417\uff1f
    • \n\t
    • \u4f60\u80fd\u60f3\u51fa\u4e00\u4e2a\u4ec5\u4f7f\u7528\u5e38\u6570\u7a7a\u95f4\u7684\u4e00\u8d9f\u626b\u63cf\u7b97\u6cd5\u5417\uff1f
    • \n
    \n", "tags_en": ["Sort", "Array", "Two Pointers"], "tags_cn": ["\u6392\u5e8f", "\u6570\u7ec4", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n void sortColors(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public void sortColors(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def sortColors(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: None Do not return anything, modify nums in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def sortColors(self, nums: List[int]) -> None:\n \"\"\"\n Do not return anything, modify nums in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nvoid sortColors(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public void SortColors(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {void} Do not return anything, modify nums in-place instead.\n */\nvar sortColors = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Void} Do not return anything, modify nums in-place instead.\ndef sort_colors(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func sortColors(_ nums: inout [Int]) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func sortColors(nums []int) {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def sortColors(nums: Array[Int]): Unit = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun sortColors(nums: IntArray): Unit {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn sort_colors(nums: &mut Vec) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return NULL\n */\n function sortColors(&$nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n Do not return anything, modify nums in-place instead.\n */\nfunction sortColors(nums: number[]): void {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0075](https://leetcode-cn.com/problems/sort-colors)", "[\u989c\u8272\u5206\u7c7b](/solution/0000-0099/0075.Sort%20Colors/README.md)", "`\u6392\u5e8f`,`\u6570\u7ec4`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0075](https://leetcode.com/problems/sort-colors)", "[Sort Colors](/solution/0000-0099/0075.Sort%20Colors/README_EN.md)", "`Sort`,`Array`,`Two Pointers`", "Medium", ""]}, {"question_id": "0074", "frontend_question_id": "0074", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/search-a-2d-matrix", "url_en": "https://leetcode.com/problems/search-a-2d-matrix", "relative_path_cn": "/solution/0000-0099/0074.Search%20a%202D%20Matrix/README.md", "relative_path_en": "/solution/0000-0099/0074.Search%20a%202D%20Matrix/README_EN.md", "title_cn": "\u641c\u7d22\u4e8c\u7ef4\u77e9\u9635", "title_en": "Search a 2D Matrix", "question_title_slug": "search-a-2d-matrix", "content_en": "

    Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:

    \n\n
      \n\t
    • Integers in each row are sorted from left to right.
    • \n\t
    • The first integer of each row is greater than the last integer of the previous row.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 3\nOutput: true\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 13\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == matrix.length
    • \n\t
    • n == matrix[i].length
    • \n\t
    • 1 <= m, n <= 100
    • \n\t
    • -104 <= matrix[i][j], target <= 104
    • \n
    \n", "content_cn": "

    \u7f16\u5199\u4e00\u4e2a\u9ad8\u6548\u7684\u7b97\u6cd5\u6765\u5224\u65ad\u00a0m x n\u00a0\u77e9\u9635\u4e2d\uff0c\u662f\u5426\u5b58\u5728\u4e00\u4e2a\u76ee\u6807\u503c\u3002\u8be5\u77e9\u9635\u5177\u6709\u5982\u4e0b\u7279\u6027\uff1a

    \n\n
      \n\t
    • \u6bcf\u884c\u4e2d\u7684\u6574\u6570\u4ece\u5de6\u5230\u53f3\u6309\u5347\u5e8f\u6392\u5217\u3002
    • \n\t
    • \u6bcf\u884c\u7684\u7b2c\u4e00\u4e2a\u6574\u6570\u5927\u4e8e\u524d\u4e00\u884c\u7684\u6700\u540e\u4e00\u4e2a\u6574\u6570\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1amatrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 3\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1amatrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 13\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == matrix.length
    • \n\t
    • n == matrix[i].length
    • \n\t
    • 1 <= m, n <= 100
    • \n\t
    • -104 <= matrix[i][j], target <= 104
    • \n
    \n", "tags_en": ["Array", "Binary Search"], "tags_cn": ["\u6570\u7ec4", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool searchMatrix(vector>& matrix, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean searchMatrix(int[][] matrix, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def searchMatrix(self, matrix, target):\n \"\"\"\n :type matrix: List[List[int]]\n :type target: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def searchMatrix(self, matrix: List[List[int]], target: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool searchMatrix(int** matrix, int matrixSize, int* matrixColSize, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool SearchMatrix(int[][] matrix, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} matrix\n * @param {number} target\n * @return {boolean}\n */\nvar searchMatrix = function(matrix, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} matrix\n# @param {Integer} target\n# @return {Boolean}\ndef search_matrix(matrix, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func searchMatrix(_ matrix: [[Int]], _ target: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func searchMatrix(matrix [][]int, target int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def searchMatrix(matrix: Array[Array[Int]], target: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun searchMatrix(matrix: Array, target: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn search_matrix(matrix: Vec>, target: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $matrix\n * @param Integer $target\n * @return Boolean\n */\n function searchMatrix($matrix, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function searchMatrix(matrix: number[][], target: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (search-matrix matrix target)\n (-> (listof (listof exact-integer?)) exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0074](https://leetcode-cn.com/problems/search-a-2d-matrix)", "[\u641c\u7d22\u4e8c\u7ef4\u77e9\u9635](/solution/0000-0099/0074.Search%20a%202D%20Matrix/README.md)", "`\u6570\u7ec4`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0074](https://leetcode.com/problems/search-a-2d-matrix)", "[Search a 2D Matrix](/solution/0000-0099/0074.Search%20a%202D%20Matrix/README_EN.md)", "`Array`,`Binary Search`", "Medium", ""]}, {"question_id": "0073", "frontend_question_id": "0073", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/set-matrix-zeroes", "url_en": "https://leetcode.com/problems/set-matrix-zeroes", "relative_path_cn": "/solution/0000-0099/0073.Set%20Matrix%20Zeroes/README.md", "relative_path_en": "/solution/0000-0099/0073.Set%20Matrix%20Zeroes/README_EN.md", "title_cn": "\u77e9\u9635\u7f6e\u96f6", "title_en": "Set Matrix Zeroes", "question_title_slug": "set-matrix-zeroes", "content_en": "

    Given an m x n matrix. If an element is 0, set its entire row and column to 0. Do it in-place.

    \n\n

    Follow up:

    \n\n
      \n\t
    • A straight forward solution using O(mn) space is probably a bad idea.
    • \n\t
    • A simple improvement uses O(m + n) space, but still not the best solution.
    • \n\t
    • Could you devise a constant space solution?
    • \n
    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: matrix = [[1,1,1],[1,0,1],[1,1,1]]\nOutput: [[1,0,1],[0,0,0],[1,0,1]]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: matrix = [[0,1,2,0],[3,4,5,2],[1,3,1,5]]\nOutput: [[0,0,0,0],[0,4,5,0],[0,3,1,0]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == matrix.length
    • \n\t
    • n == matrix[0].length
    • \n\t
    • 1 <= m, n <= 200
    • \n\t
    • -231 <= matrix[i][j] <= 231 - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u00a0m x n \u7684\u77e9\u9635\uff0c\u5982\u679c\u4e00\u4e2a\u5143\u7d20\u4e3a 0 \uff0c\u5219\u5c06\u5176\u6240\u5728\u884c\u548c\u5217\u7684\u6240\u6709\u5143\u7d20\u90fd\u8bbe\u4e3a 0 \u3002\u8bf7\u4f7f\u7528 \u539f\u5730 \u7b97\u6cd5\u3002

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u4e00\u4e2a\u76f4\u89c2\u7684\u89e3\u51b3\u65b9\u6848\u662f\u4f7f\u7528 \u00a0O(mn)\u00a0\u7684\u989d\u5916\u7a7a\u95f4\uff0c\u4f46\u8fd9\u5e76\u4e0d\u662f\u4e00\u4e2a\u597d\u7684\u89e3\u51b3\u65b9\u6848\u3002
    • \n\t
    • \u4e00\u4e2a\u7b80\u5355\u7684\u6539\u8fdb\u65b9\u6848\u662f\u4f7f\u7528 O(m\u00a0+\u00a0n) \u7684\u989d\u5916\u7a7a\u95f4\uff0c\u4f46\u8fd9\u4ecd\u7136\u4e0d\u662f\u6700\u597d\u7684\u89e3\u51b3\u65b9\u6848\u3002
    • \n\t
    • \u4f60\u80fd\u60f3\u51fa\u4e00\u4e2a\u4ec5\u4f7f\u7528\u5e38\u91cf\u7a7a\u95f4\u7684\u89e3\u51b3\u65b9\u6848\u5417\uff1f
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1amatrix = [[1,1,1],[1,0,1],[1,1,1]]\n\u8f93\u51fa\uff1a[[1,0,1],[0,0,0],[1,0,1]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1amatrix = [[0,1,2,0],[3,4,5,2],[1,3,1,5]]\n\u8f93\u51fa\uff1a[[0,0,0,0],[0,4,5,0],[0,3,1,0]]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == matrix.length
    • \n\t
    • n == matrix[0].length
    • \n\t
    • 1 <= m, n <= 200
    • \n\t
    • -231 <= matrix[i][j] <= 231 - 1
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n void setZeroes(vector>& matrix) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public void setZeroes(int[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def setZeroes(self, matrix):\n \"\"\"\n :type matrix: List[List[int]]\n :rtype: None Do not return anything, modify matrix in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def setZeroes(self, matrix: List[List[int]]) -> None:\n \"\"\"\n Do not return anything, modify matrix in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nvoid setZeroes(int** matrix, int matrixSize, int* matrixColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public void SetZeroes(int[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} matrix\n * @return {void} Do not return anything, modify matrix in-place instead.\n */\nvar setZeroes = function(matrix) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} matrix\n# @return {Void} Do not return anything, modify matrix in-place instead.\ndef set_zeroes(matrix)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func setZeroes(_ matrix: inout [[Int]]) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func setZeroes(matrix [][]int) {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def setZeroes(matrix: Array[Array[Int]]): Unit = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun setZeroes(matrix: Array): Unit {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn set_zeroes(matrix: &mut Vec>) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $matrix\n * @return NULL\n */\n function setZeroes(&$matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n Do not return anything, modify matrix in-place instead.\n */\nfunction setZeroes(matrix: number[][]): void {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0073](https://leetcode-cn.com/problems/set-matrix-zeroes)", "[\u77e9\u9635\u7f6e\u96f6](/solution/0000-0099/0073.Set%20Matrix%20Zeroes/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0073](https://leetcode.com/problems/set-matrix-zeroes)", "[Set Matrix Zeroes](/solution/0000-0099/0073.Set%20Matrix%20Zeroes/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0072", "frontend_question_id": "0072", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/edit-distance", "url_en": "https://leetcode.com/problems/edit-distance", "relative_path_cn": "/solution/0000-0099/0072.Edit%20Distance/README.md", "relative_path_en": "/solution/0000-0099/0072.Edit%20Distance/README_EN.md", "title_cn": "\u7f16\u8f91\u8ddd\u79bb", "title_en": "Edit Distance", "question_title_slug": "edit-distance", "content_en": "

    Given two strings word1 and word2, return the minimum number of operations required to convert word1 to word2.

    \n\n

    You have the following three operations permitted on a word:

    \n\n
      \n\t
    • Insert a character
    • \n\t
    • Delete a character
    • \n\t
    • Replace a character
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: word1 = "horse", word2 = "ros"\nOutput: 3\nExplanation: \nhorse -> rorse (replace 'h' with 'r')\nrorse -> rose (remove 'r')\nrose -> ros (remove 'e')\n
    \n\n

    Example 2:

    \n\n
    \nInput: word1 = "intention", word2 = "execution"\nOutput: 5\nExplanation: \nintention -> inention (remove 't')\ninention -> enention (replace 'i' with 'e')\nenention -> exention (replace 'n' with 'x')\nexention -> exection (replace 'n' with 'c')\nexection -> execution (insert 'u')\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= word1.length, word2.length <= 500
    • \n\t
    • word1 and word2 consist of lowercase English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u5355\u8bcd\u00a0word1 \u548c\u00a0word2\uff0c\u8bf7\u4f60\u8ba1\u7b97\u51fa\u5c06\u00a0word1\u00a0\u8f6c\u6362\u6210\u00a0word2 \u6240\u4f7f\u7528\u7684\u6700\u5c11\u64cd\u4f5c\u6570\u00a0\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u5bf9\u4e00\u4e2a\u5355\u8bcd\u8fdb\u884c\u5982\u4e0b\u4e09\u79cd\u64cd\u4f5c\uff1a

    \n\n
      \n\t
    • \u63d2\u5165\u4e00\u4e2a\u5b57\u7b26
    • \n\t
    • \u5220\u9664\u4e00\u4e2a\u5b57\u7b26
    • \n\t
    • \u66ff\u6362\u4e00\u4e2a\u5b57\u7b26
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\u00a01\uff1a

    \n\n
    \n\u8f93\u5165\uff1aword1 = \"horse\", word2 = \"ros\"\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\nhorse -> rorse (\u5c06 'h' \u66ff\u6362\u4e3a 'r')\nrorse -> rose (\u5220\u9664 'r')\nrose -> ros (\u5220\u9664 'e')\n
    \n\n

    \u793a\u4f8b\u00a02\uff1a

    \n\n
    \n\u8f93\u5165\uff1aword1 = \"intention\", word2 = \"execution\"\n\u8f93\u51fa\uff1a5\n\u89e3\u91ca\uff1a\nintention -> inention (\u5220\u9664 't')\ninention -> enention (\u5c06 'i' \u66ff\u6362\u4e3a 'e')\nenention -> exention (\u5c06 'n' \u66ff\u6362\u4e3a 'x')\nexention -> exection (\u5c06 'n' \u66ff\u6362\u4e3a 'c')\nexection -> execution (\u63d2\u5165 'u')\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= word1.length, word2.length <= 500
    • \n\t
    • word1 \u548c word2 \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n", "tags_en": ["String", "Dynamic Programming"], "tags_cn": ["\u5b57\u7b26\u4e32", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minDistance(string word1, string word2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minDistance(String word1, String word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minDistance(self, word1, word2):\n \"\"\"\n :type word1: str\n :type word2: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minDistance(self, word1: str, word2: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minDistance(char * word1, char * word2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinDistance(string word1, string word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} word1\n * @param {string} word2\n * @return {number}\n */\nvar minDistance = function(word1, word2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} word1\n# @param {String} word2\n# @return {Integer}\ndef min_distance(word1, word2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minDistance(_ word1: String, _ word2: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minDistance(word1 string, word2 string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minDistance(word1: String, word2: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minDistance(word1: String, word2: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_distance(word1: String, word2: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $word1\n * @param String $word2\n * @return Integer\n */\n function minDistance($word1, $word2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minDistance(word1: string, word2: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-distance word1 word2)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0072](https://leetcode-cn.com/problems/edit-distance)", "[\u7f16\u8f91\u8ddd\u79bb](/solution/0000-0099/0072.Edit%20Distance/README.md)", "`\u5b57\u7b26\u4e32`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0072](https://leetcode.com/problems/edit-distance)", "[Edit Distance](/solution/0000-0099/0072.Edit%20Distance/README_EN.md)", "`String`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0071", "frontend_question_id": "0071", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/simplify-path", "url_en": "https://leetcode.com/problems/simplify-path", "relative_path_cn": "/solution/0000-0099/0071.Simplify%20Path/README.md", "relative_path_en": "/solution/0000-0099/0071.Simplify%20Path/README_EN.md", "title_cn": "\u7b80\u5316\u8def\u5f84", "title_en": "Simplify Path", "question_title_slug": "simplify-path", "content_en": "

    Given a string path, which is an absolute path (starting with a slash '/') to a file or directory in a Unix-style file system, convert it to the simplified canonical path.

    \n\n

    In a Unix-style file system, a period '.' refers to the current directory, a double period '..' refers to the directory up a level, and any multiple consecutive slashes (i.e. '//') are treated as a single slash '/'. For this problem, any other format of periods such as '...' are treated as file/directory names.

    \n\n

    The canonical path should have the following format:

    \n\n
      \n\t
    • The path starts with a single slash '/'.
    • \n\t
    • Any two directories are separated by a single slash '/'.
    • \n\t
    • The path does not end with a trailing '/'.
    • \n\t
    • The path only contains the directories on the path from the root directory to the target file or directory (i.e., no period '.' or double period '..')
    • \n
    \n\n

    Return the simplified canonical path.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: path = "/home/"\nOutput: "/home"\nExplanation: Note that there is no trailing slash after the last directory name.\n
    \n\n

    Example 2:

    \n\n
    \nInput: path = "/../"\nOutput: "/"\nExplanation: Going one level up from the root directory is a no-op, as the root level is the highest level you can go.\n
    \n\n

    Example 3:

    \n\n
    \nInput: path = "/home//foo/"\nOutput: "/home/foo"\nExplanation: In the canonical path, multiple consecutive slashes are replaced by a single one.\n
    \n\n

    Example 4:

    \n\n
    \nInput: path = "/a/./b/../../c/"\nOutput: "/c"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= path.length <= 3000
    • \n\t
    • path consists of English letters, digits, period '.', slash '/' or '_'.
    • \n\t
    • path is a valid absolute Unix path.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 path \uff0c\u8868\u793a\u6307\u5411\u67d0\u4e00\u6587\u4ef6\u6216\u76ee\u5f55\u7684\u00a0Unix \u98ce\u683c \u7edd\u5bf9\u8def\u5f84 \uff08\u4ee5 '/' \u5f00\u5934\uff09\uff0c\u8bf7\u4f60\u5c06\u5176\u8f6c\u5316\u4e3a\u66f4\u52a0\u7b80\u6d01\u7684\u89c4\u8303\u8def\u5f84\u3002

    \n\n

    \u5728 Unix \u98ce\u683c\u7684\u6587\u4ef6\u7cfb\u7edf\u4e2d\uff0c\u4e00\u4e2a\u70b9\uff08.\uff09\u8868\u793a\u5f53\u524d\u76ee\u5f55\u672c\u8eab\uff1b\u6b64\u5916\uff0c\u4e24\u4e2a\u70b9 \uff08..\uff09\u00a0\u8868\u793a\u5c06\u76ee\u5f55\u5207\u6362\u5230\u4e0a\u4e00\u7ea7\uff08\u6307\u5411\u7236\u76ee\u5f55\uff09\uff1b\u4e24\u8005\u90fd\u53ef\u4ee5\u662f\u590d\u6742\u76f8\u5bf9\u8def\u5f84\u7684\u7ec4\u6210\u90e8\u5206\u3002\u4efb\u610f\u591a\u4e2a\u8fde\u7eed\u7684\u659c\u6760\uff08\u5373\uff0c'//'\uff09\u90fd\u88ab\u89c6\u4e3a\u5355\u4e2a\u659c\u6760 '/' \u3002 \u5bf9\u4e8e\u6b64\u95ee\u9898\uff0c\u4efb\u4f55\u5176\u4ed6\u683c\u5f0f\u7684\u70b9\uff08\u4f8b\u5982\uff0c'...'\uff09\u5747\u88ab\u89c6\u4e3a\u6587\u4ef6/\u76ee\u5f55\u540d\u79f0\u3002

    \n\n

    \u8bf7\u6ce8\u610f\uff0c\u8fd4\u56de\u7684 \u89c4\u8303\u8def\u5f84 \u5fc5\u987b\u9075\u5faa\u4e0b\u8ff0\u683c\u5f0f\uff1a

    \n\n
      \n\t
    • \u59cb\u7ec8\u4ee5\u659c\u6760 '/' \u5f00\u5934\u3002
    • \n\t
    • \u4e24\u4e2a\u76ee\u5f55\u540d\u4e4b\u95f4\u5fc5\u987b\u53ea\u6709\u4e00\u4e2a\u659c\u6760 '/' \u3002
    • \n\t
    • \u6700\u540e\u4e00\u4e2a\u76ee\u5f55\u540d\uff08\u5982\u679c\u5b58\u5728\uff09\u4e0d\u80fd \u4ee5 '/' \u7ed3\u5c3e\u3002
    • \n\t
    • \u6b64\u5916\uff0c\u8def\u5f84\u4ec5\u5305\u542b\u4ece\u6839\u76ee\u5f55\u5230\u76ee\u6807\u6587\u4ef6\u6216\u76ee\u5f55\u7684\u8def\u5f84\u4e0a\u7684\u76ee\u5f55\uff08\u5373\uff0c\u4e0d\u542b '.' \u6216 '..'\uff09\u3002
    • \n
    \n\n

    \u8fd4\u56de\u7b80\u5316\u540e\u5f97\u5230\u7684 \u89c4\u8303\u8def\u5f84 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1apath = \"/home/\"\n\u8f93\u51fa\uff1a\"/home\"\n\u89e3\u91ca\uff1a\u6ce8\u610f\uff0c\u6700\u540e\u4e00\u4e2a\u76ee\u5f55\u540d\u540e\u9762\u6ca1\u6709\u659c\u6760\u3002 
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1apath = \"/../\"\n\u8f93\u51fa\uff1a\"/\"\n\u89e3\u91ca\uff1a\u4ece\u6839\u76ee\u5f55\u5411\u4e0a\u4e00\u7ea7\u662f\u4e0d\u53ef\u884c\u7684\uff0c\u56e0\u4e3a\u6839\u76ee\u5f55\u662f\u4f60\u53ef\u4ee5\u5230\u8fbe\u7684\u6700\u9ad8\u7ea7\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1apath = \"/home//foo/\"\n\u8f93\u51fa\uff1a\"/home/foo\"\n\u89e3\u91ca\uff1a\u5728\u89c4\u8303\u8def\u5f84\u4e2d\uff0c\u591a\u4e2a\u8fde\u7eed\u659c\u6760\u9700\u8981\u7528\u4e00\u4e2a\u659c\u6760\u66ff\u6362\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1apath = \"/a/./b/../../c/\"\n\u8f93\u51fa\uff1a\"/c\"\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= path.length <= 3000
    • \n\t
    • path \u7531\u82f1\u6587\u5b57\u6bcd\uff0c\u6570\u5b57\uff0c'.'\uff0c'/' \u6216 '_' \u7ec4\u6210\u3002
    • \n\t
    • path \u662f\u4e00\u4e2a\u6709\u6548\u7684 Unix \u98ce\u683c\u7edd\u5bf9\u8def\u5f84\u3002
    • \n
    \n", "tags_en": ["Stack", "String"], "tags_cn": ["\u6808", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string simplifyPath(string path) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String simplifyPath(String path) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def simplifyPath(self, path):\n \"\"\"\n :type path: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def simplifyPath(self, path: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * simplifyPath(char * path){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string SimplifyPath(string path) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} path\n * @return {string}\n */\nvar simplifyPath = function(path) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} path\n# @return {String}\ndef simplify_path(path)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func simplifyPath(_ path: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func simplifyPath(path string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def simplifyPath(path: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun simplifyPath(path: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn simplify_path(path: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $path\n * @return String\n */\n function simplifyPath($path) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function simplifyPath(path: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (simplify-path path)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0071](https://leetcode-cn.com/problems/simplify-path)", "[\u7b80\u5316\u8def\u5f84](/solution/0000-0099/0071.Simplify%20Path/README.md)", "`\u6808`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0071](https://leetcode.com/problems/simplify-path)", "[Simplify Path](/solution/0000-0099/0071.Simplify%20Path/README_EN.md)", "`Stack`,`String`", "Medium", ""]}, {"question_id": "0070", "frontend_question_id": "0070", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/climbing-stairs", "url_en": "https://leetcode.com/problems/climbing-stairs", "relative_path_cn": "/solution/0000-0099/0070.Climbing%20Stairs/README.md", "relative_path_en": "/solution/0000-0099/0070.Climbing%20Stairs/README_EN.md", "title_cn": "\u722c\u697c\u68af", "title_en": "Climbing Stairs", "question_title_slug": "climbing-stairs", "content_en": "

    You are climbing a staircase. It takes n steps to reach the top.

    \n\n

    Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 2\nOutput: 2\nExplanation: There are two ways to climb to the top.\n1. 1 step + 1 step\n2. 2 steps\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 3\nOutput: 3\nExplanation: There are three ways to climb to the top.\n1. 1 step + 1 step + 1 step\n2. 1 step + 2 steps\n3. 2 steps + 1 step\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 45
    • \n
    \n", "content_cn": "

    \u5047\u8bbe\u4f60\u6b63\u5728\u722c\u697c\u68af\u3002\u9700\u8981 n \u9636\u4f60\u624d\u80fd\u5230\u8fbe\u697c\u9876\u3002

    \n\n

    \u6bcf\u6b21\u4f60\u53ef\u4ee5\u722c 1 \u6216 2 \u4e2a\u53f0\u9636\u3002\u4f60\u6709\u591a\u5c11\u79cd\u4e0d\u540c\u7684\u65b9\u6cd5\u53ef\u4ee5\u722c\u5230\u697c\u9876\u5462\uff1f

    \n\n

    \u6ce8\u610f\uff1a\u7ed9\u5b9a n \u662f\u4e00\u4e2a\u6b63\u6574\u6570\u3002

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1a 2\n\u8f93\u51fa\uff1a 2\n\u89e3\u91ca\uff1a \u6709\u4e24\u79cd\u65b9\u6cd5\u53ef\u4ee5\u722c\u5230\u697c\u9876\u3002\n1.  1 \u9636 + 1 \u9636\n2.  2 \u9636
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1a 3\n\u8f93\u51fa\uff1a 3\n\u89e3\u91ca\uff1a \u6709\u4e09\u79cd\u65b9\u6cd5\u53ef\u4ee5\u722c\u5230\u697c\u9876\u3002\n1.  1 \u9636 + 1 \u9636 + 1 \u9636\n2.  1 \u9636 + 2 \u9636\n3.  2 \u9636 + 1 \u9636\n
    \n", "tags_en": ["Dynamic Programming"], "tags_cn": ["\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int climbStairs(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int climbStairs(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def climbStairs(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def climbStairs(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint climbStairs(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ClimbStairs(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar climbStairs = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef climb_stairs(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func climbStairs(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func climbStairs(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def climbStairs(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun climbStairs(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn climb_stairs(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function climbStairs($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function climbStairs(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (climb-stairs n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0070](https://leetcode-cn.com/problems/climbing-stairs)", "[\u722c\u697c\u68af](/solution/0000-0099/0070.Climbing%20Stairs/README.md)", "`\u52a8\u6001\u89c4\u5212`", "\u7b80\u5355", ""], "md_table_row_en": ["[0070](https://leetcode.com/problems/climbing-stairs)", "[Climbing Stairs](/solution/0000-0099/0070.Climbing%20Stairs/README_EN.md)", "`Dynamic Programming`", "Easy", ""]}, {"question_id": "0069", "frontend_question_id": "0069", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sqrtx", "url_en": "https://leetcode.com/problems/sqrtx", "relative_path_cn": "/solution/0000-0099/0069.Sqrt%28x%29/README.md", "relative_path_en": "/solution/0000-0099/0069.Sqrt%28x%29/README_EN.md", "title_cn": "x \u7684\u5e73\u65b9\u6839", "title_en": "Sqrt(x)", "question_title_slug": "sqrtx", "content_en": "

    Given a non-negative integer x, compute and return the square root of x.

    \n\n

    Since the return type is an integer, the decimal digits are truncated, and only the integer part of the result is returned.

    \n\n

    Note: You are not allowed to use any built-in exponent function or operator, such as pow(x, 0.5) or x ** 0.5.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: x = 4\nOutput: 2\n
    \n\n

    Example 2:

    \n\n
    \nInput: x = 8\nOutput: 2\nExplanation: The square root of 8 is 2.82842..., and since the decimal part is truncated, 2 is returned.
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= x <= 231 - 1
    • \n
    \n", "content_cn": "

    \u5b9e\u73b0 int sqrt(int x) \u51fd\u6570\u3002

    \n\n

    \u8ba1\u7b97\u5e76\u8fd4\u56de x \u7684\u5e73\u65b9\u6839\uff0c\u5176\u4e2d x \u662f\u975e\u8d1f\u6574\u6570\u3002

    \n\n

    \u7531\u4e8e\u8fd4\u56de\u7c7b\u578b\u662f\u6574\u6570\uff0c\u7ed3\u679c\u53ea\u4fdd\u7559\u6574\u6570\u7684\u90e8\u5206\uff0c\u5c0f\u6570\u90e8\u5206\u5c06\u88ab\u820d\u53bb\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: 4\n\u8f93\u51fa: 2\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: 8\n\u8f93\u51fa: 2\n\u8bf4\u660e: 8 \u7684\u5e73\u65b9\u6839\u662f 2.82842..., \n     \u7531\u4e8e\u8fd4\u56de\u7c7b\u578b\u662f\u6574\u6570\uff0c\u5c0f\u6570\u90e8\u5206\u5c06\u88ab\u820d\u53bb\u3002\n
    \n", "tags_en": ["Math", "Binary Search"], "tags_cn": ["\u6570\u5b66", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int mySqrt(int x) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int mySqrt(int x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def mySqrt(self, x):\n \"\"\"\n :type x: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def mySqrt(self, x: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint mySqrt(int x){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MySqrt(int x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} x\n * @return {number}\n */\nvar mySqrt = function(x) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} x\n# @return {Integer}\ndef my_sqrt(x)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func mySqrt(_ x: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func mySqrt(x int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def mySqrt(x: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun mySqrt(x: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn my_sqrt(x: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $x\n * @return Integer\n */\n function mySqrt($x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function mySqrt(x: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (my-sqrt x)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0069](https://leetcode-cn.com/problems/sqrtx)", "[x \u7684\u5e73\u65b9\u6839](/solution/0000-0099/0069.Sqrt%28x%29/README.md)", "`\u6570\u5b66`,`\u4e8c\u5206\u67e5\u627e`", "\u7b80\u5355", ""], "md_table_row_en": ["[0069](https://leetcode.com/problems/sqrtx)", "[Sqrt(x)](/solution/0000-0099/0069.Sqrt%28x%29/README_EN.md)", "`Math`,`Binary Search`", "Easy", ""]}, {"question_id": "0068", "frontend_question_id": "0068", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/text-justification", "url_en": "https://leetcode.com/problems/text-justification", "relative_path_cn": "/solution/0000-0099/0068.Text%20Justification/README.md", "relative_path_en": "/solution/0000-0099/0068.Text%20Justification/README_EN.md", "title_cn": "\u6587\u672c\u5de6\u53f3\u5bf9\u9f50", "title_en": "Text Justification", "question_title_slug": "text-justification", "content_en": "

    Given an array of words and a width maxWidth, format the text such that each line has exactly maxWidth characters and is fully (left and right) justified.

    \n\n

    You should pack your words in a greedy approach; that is, pack as many words as you can in each line. Pad extra spaces ' ' when necessary so that each line has exactly maxWidth characters.

    \n\n

    Extra spaces between words should be distributed as evenly as possible. If the number of spaces on a line do not divide evenly between words, the empty slots on the left will be assigned more spaces than the slots on the right.

    \n\n

    For the last line of text, it should be left justified and no extra space is inserted between words.

    \n\n

    Note:

    \n\n
      \n\t
    • A word is defined as a character sequence consisting of non-space characters only.
    • \n\t
    • Each word's length is guaranteed to be greater than 0 and not exceed maxWidth.
    • \n\t
    • The input array words contains at least one word.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: words = ["This", "is", "an", "example", "of", "text", "justification."], maxWidth = 16\nOutput:\n[\n   "This    is    an",\n   "example  of text",\n   "justification.  "\n]
    \n\n

    Example 2:

    \n\n
    \nInput: words = ["What","must","be","acknowledgment","shall","be"], maxWidth = 16\nOutput:\n[\n  "What   must   be",\n  "acknowledgment  ",\n  "shall be        "\n]\nExplanation: Note that the last line is "shall be    " instead of "shall     be", because the last line must be left-justified instead of fully-justified.\nNote that the second line is also left-justified becase it contains only one word.
    \n\n

    Example 3:

    \n\n
    \nInput: words = ["Science","is","what","we","understand","well","enough","to","explain","to","a","computer.","Art","is","everything","else","we","do"], maxWidth = 20\nOutput:\n[\n  "Science  is  what we",\n  "understand      well",\n  "enough to explain to",\n  "a  computer.  Art is",\n  "everything  else  we",\n  "do                  "\n]
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= words.length <= 300
    • \n\t
    • 1 <= words[i].length <= 20
    • \n\t
    • words[i] consists of only English letters and symbols.
    • \n\t
    • 1 <= maxWidth <= 100
    • \n\t
    • words[i].length <= maxWidth
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5355\u8bcd\u6570\u7ec4\u548c\u4e00\u4e2a\u957f\u5ea6 maxWidth\uff0c\u91cd\u65b0\u6392\u7248\u5355\u8bcd\uff0c\u4f7f\u5176\u6210\u4e3a\u6bcf\u884c\u6070\u597d\u6709 maxWidth \u4e2a\u5b57\u7b26\uff0c\u4e14\u5de6\u53f3\u4e24\u7aef\u5bf9\u9f50\u7684\u6587\u672c\u3002

    \n\n

    \u4f60\u5e94\u8be5\u4f7f\u7528“\u8d2a\u5fc3\u7b97\u6cd5”\u6765\u653e\u7f6e\u7ed9\u5b9a\u7684\u5355\u8bcd\uff1b\u4e5f\u5c31\u662f\u8bf4\uff0c\u5c3d\u53ef\u80fd\u591a\u5730\u5f80\u6bcf\u884c\u4e2d\u653e\u7f6e\u5355\u8bcd\u3002\u5fc5\u8981\u65f6\u53ef\u7528\u7a7a\u683c ' ' \u586b\u5145\uff0c\u4f7f\u5f97\u6bcf\u884c\u6070\u597d\u6709 maxWidth \u4e2a\u5b57\u7b26\u3002

    \n\n

    \u8981\u6c42\u5c3d\u53ef\u80fd\u5747\u5300\u5206\u914d\u5355\u8bcd\u95f4\u7684\u7a7a\u683c\u6570\u91cf\u3002\u5982\u679c\u67d0\u4e00\u884c\u5355\u8bcd\u95f4\u7684\u7a7a\u683c\u4e0d\u80fd\u5747\u5300\u5206\u914d\uff0c\u5219\u5de6\u4fa7\u653e\u7f6e\u7684\u7a7a\u683c\u6570\u8981\u591a\u4e8e\u53f3\u4fa7\u7684\u7a7a\u683c\u6570\u3002

    \n\n

    \u6587\u672c\u7684\u6700\u540e\u4e00\u884c\u5e94\u4e3a\u5de6\u5bf9\u9f50\uff0c\u4e14\u5355\u8bcd\u4e4b\u95f4\u4e0d\u63d2\u5165\u989d\u5916\u7684\u7a7a\u683c\u3002

    \n\n

    \u8bf4\u660e:

    \n\n
      \n\t
    • \u5355\u8bcd\u662f\u6307\u7531\u975e\u7a7a\u683c\u5b57\u7b26\u7ec4\u6210\u7684\u5b57\u7b26\u5e8f\u5217\u3002
    • \n\t
    • \u6bcf\u4e2a\u5355\u8bcd\u7684\u957f\u5ea6\u5927\u4e8e 0\uff0c\u5c0f\u4e8e\u7b49\u4e8e maxWidth\u3002
    • \n\t
    • \u8f93\u5165\u5355\u8bcd\u6570\u7ec4 words \u81f3\u5c11\u5305\u542b\u4e00\u4e2a\u5355\u8bcd\u3002
    • \n
    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165:\nwords = ["This", "is", "an", "example", "of", "text", "justification."]\nmaxWidth = 16\n\u8f93\u51fa:\n[\n   "This    is    an",\n   "example  of text",\n   "justification.  "\n]\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165:\nwords = ["What","must","be","acknowledgment","shall","be"]\nmaxWidth = 16\n\u8f93\u51fa:\n[\n  "What   must   be",\n  "acknowledgment  ",\n  "shall be        "\n]\n\u89e3\u91ca: \u6ce8\u610f\u6700\u540e\u4e00\u884c\u7684\u683c\u5f0f\u5e94\u4e3a "shall be    " \u800c\u4e0d\u662f "shall     be",\n     \u56e0\u4e3a\u6700\u540e\u4e00\u884c\u5e94\u4e3a\u5de6\u5bf9\u9f50\uff0c\u800c\u4e0d\u662f\u5de6\u53f3\u4e24\u7aef\u5bf9\u9f50\u3002       \n     \u7b2c\u4e8c\u884c\u540c\u6837\u4e3a\u5de6\u5bf9\u9f50\uff0c\u8fd9\u662f\u56e0\u4e3a\u8fd9\u884c\u53ea\u5305\u542b\u4e00\u4e2a\u5355\u8bcd\u3002\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u8f93\u5165:\nwords = ["Science","is","what","we","understand","well","enough","to","explain",\n         "to","a","computer.","Art","is","everything","else","we","do"]\nmaxWidth = 20\n\u8f93\u51fa:\n[\n  "Science  is  what we",\n  "understand      well",\n  "enough to explain to",\n  "a  computer.  Art is",\n  "everything  else  we",\n  "do                  "\n]\n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector fullJustify(vector& words, int maxWidth) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List fullJustify(String[] words, int maxWidth) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def fullJustify(self, words, maxWidth):\n \"\"\"\n :type words: List[str]\n :type maxWidth: int\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def fullJustify(self, words: List[str], maxWidth: int) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** fullJustify(char ** words, int wordsSize, int maxWidth, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList FullJustify(string[] words, int maxWidth) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} words\n * @param {number} maxWidth\n * @return {string[]}\n */\nvar fullJustify = function(words, maxWidth) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} words\n# @param {Integer} max_width\n# @return {String[]}\ndef full_justify(words, max_width)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func fullJustify(_ words: [String], _ maxWidth: Int) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func fullJustify(words []string, maxWidth int) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def fullJustify(words: Array[String], maxWidth: Int): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun fullJustify(words: Array, maxWidth: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn full_justify(words: Vec, max_width: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $words\n * @param Integer $maxWidth\n * @return String[]\n */\n function fullJustify($words, $maxWidth) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function fullJustify(words: string[], maxWidth: number): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (full-justify words maxWidth)\n (-> (listof string?) exact-integer? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0068](https://leetcode-cn.com/problems/text-justification)", "[\u6587\u672c\u5de6\u53f3\u5bf9\u9f50](/solution/0000-0099/0068.Text%20Justification/README.md)", "`\u5b57\u7b26\u4e32`", "\u56f0\u96be", ""], "md_table_row_en": ["[0068](https://leetcode.com/problems/text-justification)", "[Text Justification](/solution/0000-0099/0068.Text%20Justification/README_EN.md)", "`String`", "Hard", ""]}, {"question_id": "0067", "frontend_question_id": "0067", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/add-binary", "url_en": "https://leetcode.com/problems/add-binary", "relative_path_cn": "/solution/0000-0099/0067.Add%20Binary/README.md", "relative_path_en": "/solution/0000-0099/0067.Add%20Binary/README_EN.md", "title_cn": "\u4e8c\u8fdb\u5236\u6c42\u548c", "title_en": "Add Binary", "question_title_slug": "add-binary", "content_en": "

    Given two binary strings a and b, return their sum as a binary string.

    \n\n

     

    \n

    Example 1:

    \n
    Input: a = \"11\", b = \"1\"\nOutput: \"100\"\n

    Example 2:

    \n
    Input: a = \"1010\", b = \"1011\"\nOutput: \"10101\"\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= a.length, b.length <= 104
    • \n\t
    • a and b consist only of '0' or '1' characters.
    • \n\t
    • Each string does not contain leading zeros except for the zero itself.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32\uff0c\u8fd4\u56de\u5b83\u4eec\u7684\u548c\uff08\u7528\u4e8c\u8fdb\u5236\u8868\u793a\uff09\u3002

    \n\n

    \u8f93\u5165\u4e3a \u975e\u7a7a \u5b57\u7b26\u4e32\u4e14\u53ea\u5305\u542b\u6570\u5b57 1 \u548c 0\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: a = "11", b = "1"\n\u8f93\u51fa: "100"
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: a = "1010", b = "1011"\n\u8f93\u51fa: "10101"
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6bcf\u4e2a\u5b57\u7b26\u4e32\u4ec5\u7531\u5b57\u7b26 '0' \u6216 '1' \u7ec4\u6210\u3002
    • \n\t
    • 1 <= a.length, b.length <= 10^4
    • \n\t
    • \u5b57\u7b26\u4e32\u5982\u679c\u4e0d\u662f "0" \uff0c\u5c31\u90fd\u4e0d\u542b\u524d\u5bfc\u96f6\u3002
    • \n
    \n", "tags_en": ["Math", "String"], "tags_cn": ["\u6570\u5b66", "\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string addBinary(string a, string b) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String addBinary(String a, String b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def addBinary(self, a, b):\n \"\"\"\n :type a: str\n :type b: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def addBinary(self, a: str, b: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * addBinary(char * a, char * b){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string AddBinary(string a, string b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} a\n * @param {string} b\n * @return {string}\n */\nvar addBinary = function(a, b) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} a\n# @param {String} b\n# @return {String}\ndef add_binary(a, b)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func addBinary(_ a: String, _ b: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func addBinary(a string, b string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def addBinary(a: String, b: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun addBinary(a: String, b: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn add_binary(a: String, b: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $a\n * @param String $b\n * @return String\n */\n function addBinary($a, $b) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function addBinary(a: string, b: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (add-binary a b)\n (-> string? string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0067](https://leetcode-cn.com/problems/add-binary)", "[\u4e8c\u8fdb\u5236\u6c42\u548c](/solution/0000-0099/0067.Add%20Binary/README.md)", "`\u6570\u5b66`,`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0067](https://leetcode.com/problems/add-binary)", "[Add Binary](/solution/0000-0099/0067.Add%20Binary/README_EN.md)", "`Math`,`String`", "Easy", ""]}, {"question_id": "0066", "frontend_question_id": "0066", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/plus-one", "url_en": "https://leetcode.com/problems/plus-one", "relative_path_cn": "/solution/0000-0099/0066.Plus%20One/README.md", "relative_path_en": "/solution/0000-0099/0066.Plus%20One/README_EN.md", "title_cn": "\u52a0\u4e00", "title_en": "Plus One", "question_title_slug": "plus-one", "content_en": "

    Given a non-empty array of decimal digits representing a non-negative integer, increment one to the integer.

    \n\n

    The digits are stored such that the most significant digit is at the head of the list, and each element in the array contains a single digit.

    \n\n

    You may assume the integer does not contain any leading zero, except the number 0 itself.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: digits = [1,2,3]\nOutput: [1,2,4]\nExplanation: The array represents the integer 123.\n
    \n\n

    Example 2:

    \n\n
    \nInput: digits = [4,3,2,1]\nOutput: [4,3,2,2]\nExplanation: The array represents the integer 4321.\n
    \n\n

    Example 3:

    \n\n
    \nInput: digits = [0]\nOutput: [1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= digits.length <= 100
    • \n\t
    • 0 <= digits[i] <= 9
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u7531 \u6574\u6570 \u7ec4\u6210\u7684 \u975e\u7a7a \u6570\u7ec4\u6240\u8868\u793a\u7684\u975e\u8d1f\u6574\u6570\uff0c\u5728\u8be5\u6570\u7684\u57fa\u7840\u4e0a\u52a0\u4e00\u3002

    \n\n

    \u6700\u9ad8\u4f4d\u6570\u5b57\u5b58\u653e\u5728\u6570\u7ec4\u7684\u9996\u4f4d\uff0c \u6570\u7ec4\u4e2d\u6bcf\u4e2a\u5143\u7d20\u53ea\u5b58\u50a8\u5355\u4e2a\u6570\u5b57\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u5047\u8bbe\u9664\u4e86\u6574\u6570 0 \u4e4b\u5916\uff0c\u8fd9\u4e2a\u6574\u6570\u4e0d\u4f1a\u4ee5\u96f6\u5f00\u5934\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\u00a01\uff1a

    \n\n
    \n\u8f93\u5165\uff1adigits = [1,2,3]\n\u8f93\u51fa\uff1a[1,2,4]\n\u89e3\u91ca\uff1a\u8f93\u5165\u6570\u7ec4\u8868\u793a\u6570\u5b57 123\u3002\n
    \n\n

    \u793a\u4f8b\u00a02\uff1a

    \n\n
    \n\u8f93\u5165\uff1adigits = [4,3,2,1]\n\u8f93\u51fa\uff1a[4,3,2,2]\n\u89e3\u91ca\uff1a\u8f93\u5165\u6570\u7ec4\u8868\u793a\u6570\u5b57 4321\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1adigits = [0]\n\u8f93\u51fa\uff1a[1]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= digits.length <= 100
    • \n\t
    • 0 <= digits[i] <= 9
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector plusOne(vector& digits) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] plusOne(int[] digits) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def plusOne(self, digits):\n \"\"\"\n :type digits: List[int]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def plusOne(self, digits: List[int]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* plusOne(int* digits, int digitsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] PlusOne(int[] digits) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} digits\n * @return {number[]}\n */\nvar plusOne = function(digits) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} digits\n# @return {Integer[]}\ndef plus_one(digits)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func plusOne(_ digits: [Int]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func plusOne(digits []int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def plusOne(digits: Array[Int]): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun plusOne(digits: IntArray): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn plus_one(digits: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $digits\n * @return Integer[]\n */\n function plusOne($digits) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function plusOne(digits: number[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (plus-one digits)\n (-> (listof exact-integer?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0066](https://leetcode-cn.com/problems/plus-one)", "[\u52a0\u4e00](/solution/0000-0099/0066.Plus%20One/README.md)", "`\u6570\u7ec4`", "\u7b80\u5355", ""], "md_table_row_en": ["[0066](https://leetcode.com/problems/plus-one)", "[Plus One](/solution/0000-0099/0066.Plus%20One/README_EN.md)", "`Array`", "Easy", ""]}, {"question_id": "0065", "frontend_question_id": "0065", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/valid-number", "url_en": "https://leetcode.com/problems/valid-number", "relative_path_cn": "/solution/0000-0099/0065.Valid%20Number/README.md", "relative_path_en": "/solution/0000-0099/0065.Valid%20Number/README_EN.md", "title_cn": "\u6709\u6548\u6570\u5b57", "title_en": "Valid Number", "question_title_slug": "valid-number", "content_en": "

    A valid number can be split up into these components (in order):

    \n\n
      \n\t
    1. A decimal number or an integer.
    2. \n\t
    3. (Optional) An 'e' or 'E', followed by an integer.
    4. \n
    \n\n

    A decimal number can be split up into these components (in order):

    \n\n
      \n\t
    1. (Optional) A sign character (either '+' or '-').
    2. \n\t
    3. One of the following formats:\n\t
        \n\t\t
      1. One or more digits, followed by a dot '.'.
      2. \n\t\t
      3. One or more digits, followed by a dot '.', followed by one or more digits.
      4. \n\t\t
      5. A dot '.', followed by one or more digits.
      6. \n\t
      \n\t
    4. \n
    \n\n

    An integer can be split up into these components (in order):

    \n\n
      \n\t
    1. (Optional) A sign character (either '+' or '-').
    2. \n\t
    3. One or more digits.
    4. \n
    \n\n

    For example, all the following are valid numbers: ["2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7", "+6e-1", "53.5e93", "-123.456e789"], while the following are not valid numbers: ["abc", "1a", "1e", "e3", "99e2.5", "--6", "-+3", "95a54e53"].

    \n\n

    Given a string s, return true if s is a valid number.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "0"\nOutput: true\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "e"\nOutput: false\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "."\nOutput: false\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = ".1"\nOutput: true\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 20
    • \n\t
    • s consists of only English letters (both uppercase and lowercase), digits (0-9), plus '+', minus '-', or dot '.'.
    • \n
    \n", "content_cn": "

    \u6709\u6548\u6570\u5b57\uff08\u6309\u987a\u5e8f\uff09\u53ef\u4ee5\u5206\u6210\u4ee5\u4e0b\u51e0\u4e2a\u90e8\u5206\uff1a

    \n\n
      \n\t
    1. \u4e00\u4e2a \u5c0f\u6570 \u6216\u8005 \u6574\u6570
    2. \n\t
    3. \uff08\u53ef\u9009\uff09\u4e00\u4e2a 'e' \u6216 'E' \uff0c\u540e\u9762\u8ddf\u7740\u4e00\u4e2a \u6574\u6570
    4. \n
    \n\n

    \u5c0f\u6570\uff08\u6309\u987a\u5e8f\uff09\u53ef\u4ee5\u5206\u6210\u4ee5\u4e0b\u51e0\u4e2a\u90e8\u5206\uff1a

    \n\n
      \n\t
    1. \uff08\u53ef\u9009\uff09\u4e00\u4e2a\u7b26\u53f7\u5b57\u7b26\uff08'+' \u6216 '-'\uff09
    2. \n\t
    3. \u4e0b\u8ff0\u683c\u5f0f\u4e4b\u4e00\uff1a\n\t
        \n\t\t
      1. \u81f3\u5c11\u4e00\u4f4d\u6570\u5b57\uff0c\u540e\u9762\u8ddf\u7740\u4e00\u4e2a\u70b9 '.'
      2. \n\t\t
      3. \u81f3\u5c11\u4e00\u4f4d\u6570\u5b57\uff0c\u540e\u9762\u8ddf\u7740\u4e00\u4e2a\u70b9 '.' \uff0c\u540e\u9762\u518d\u8ddf\u7740\u81f3\u5c11\u4e00\u4f4d\u6570\u5b57
      4. \n\t\t
      5. \u4e00\u4e2a\u70b9 '.' \uff0c\u540e\u9762\u8ddf\u7740\u81f3\u5c11\u4e00\u4f4d\u6570\u5b57
      6. \n\t
      \n\t
    4. \n
    \n\n

    \u6574\u6570\uff08\u6309\u987a\u5e8f\uff09\u53ef\u4ee5\u5206\u6210\u4ee5\u4e0b\u51e0\u4e2a\u90e8\u5206\uff1a

    \n\n
      \n\t
    1. \uff08\u53ef\u9009\uff09\u4e00\u4e2a\u7b26\u53f7\u5b57\u7b26\uff08'+' \u6216 '-'\uff09
    2. \n\t
    3. \u81f3\u5c11\u4e00\u4f4d\u6570\u5b57
    4. \n
    \n\n

    \u90e8\u5206\u6709\u6548\u6570\u5b57\u5217\u4e3e\u5982\u4e0b\uff1a

    \n\n
      \n\t
    • [\"2\", \"0089\", \"-0.1\", \"+3.14\", \"4.\", \"-.9\", \"2e10\", \"-90E3\", \"3e+7\", \"+6e-1\", \"53.5e93\", \"-123.456e789\"]
    • \n
    \n\n

    \u90e8\u5206\u65e0\u6548\u6570\u5b57\u5217\u4e3e\u5982\u4e0b\uff1a

    \n\n
      \n\t
    • [\"abc\", \"1a\", \"1e\", \"e3\", \"99e2.5\", \"--6\", \"-+3\", \"95a54e53\"]
    • \n
    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s \uff0c\u5982\u679c s \u662f\u4e00\u4e2a \u6709\u6548\u6570\u5b57 \uff0c\u8bf7\u8fd4\u56de true \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"0\"\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"e\"\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \".\"\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \".1\"\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 20
    • \n\t
    • s \u4ec5\u542b\u82f1\u6587\u5b57\u6bcd\uff08\u5927\u5199\u548c\u5c0f\u5199\uff09\uff0c\u6570\u5b57\uff080-9\uff09\uff0c\u52a0\u53f7 '+' \uff0c\u51cf\u53f7 '-' \uff0c\u6216\u8005\u70b9 '.' \u3002
    • \n
    \n", "tags_en": ["Math", "String"], "tags_cn": ["\u6570\u5b66", "\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isNumber(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isNumber(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isNumber(self, s):\n \"\"\"\n :type s: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isNumber(self, s: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isNumber(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsNumber(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {boolean}\n */\nvar isNumber = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Boolean}\ndef is_number(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isNumber(_ s: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isNumber(s string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isNumber(s: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isNumber(s: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_number(s: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Boolean\n */\n function isNumber($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isNumber(s: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-number s)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0065](https://leetcode-cn.com/problems/valid-number)", "[\u6709\u6548\u6570\u5b57](/solution/0000-0099/0065.Valid%20Number/README.md)", "`\u6570\u5b66`,`\u5b57\u7b26\u4e32`", "\u56f0\u96be", ""], "md_table_row_en": ["[0065](https://leetcode.com/problems/valid-number)", "[Valid Number](/solution/0000-0099/0065.Valid%20Number/README_EN.md)", "`Math`,`String`", "Hard", ""]}, {"question_id": "0064", "frontend_question_id": "0064", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/minimum-path-sum", "url_en": "https://leetcode.com/problems/minimum-path-sum", "relative_path_cn": "/solution/0000-0099/0064.Minimum%20Path%20Sum/README.md", "relative_path_en": "/solution/0000-0099/0064.Minimum%20Path%20Sum/README_EN.md", "title_cn": "\u6700\u5c0f\u8def\u5f84\u548c", "title_en": "Minimum Path Sum", "question_title_slug": "minimum-path-sum", "content_en": "

    Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.

    \n\n

    Note: You can only move either down or right at any point in time.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: grid = [[1,3,1],[1,5,1],[4,2,1]]\nOutput: 7\nExplanation: Because the path 1 → 3 → 1 → 1 → 1 minimizes the sum.\n
    \n\n

    Example 2:

    \n\n
    \nInput: grid = [[1,2,3],[4,5,6]]\nOutput: 12\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= m, n <= 200
    • \n\t
    • 0 <= grid[i][j] <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5305\u542b\u975e\u8d1f\u6574\u6570\u7684 m\u00a0x\u00a0n\u00a0\u7f51\u683c\u00a0grid \uff0c\u8bf7\u627e\u51fa\u4e00\u6761\u4ece\u5de6\u4e0a\u89d2\u5230\u53f3\u4e0b\u89d2\u7684\u8def\u5f84\uff0c\u4f7f\u5f97\u8def\u5f84\u4e0a\u7684\u6570\u5b57\u603b\u548c\u4e3a\u6700\u5c0f\u3002

    \n\n

    \u8bf4\u660e\uff1a\u6bcf\u6b21\u53ea\u80fd\u5411\u4e0b\u6216\u8005\u5411\u53f3\u79fb\u52a8\u4e00\u6b65\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1agrid = [[1,3,1],[1,5,1],[4,2,1]]\n\u8f93\u51fa\uff1a7\n\u89e3\u91ca\uff1a\u56e0\u4e3a\u8def\u5f84 1\u21923\u21921\u21921\u21921 \u7684\u603b\u548c\u6700\u5c0f\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1agrid = [[1,2,3],[4,5,6]]\n\u8f93\u51fa\uff1a12\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == grid.length
    • \n\t
    • n == grid[i].length
    • \n\t
    • 1 <= m, n <= 200
    • \n\t
    • 0 <= grid[i][j] <= 100
    • \n
    \n", "tags_en": ["Array", "Dynamic Programming"], "tags_cn": ["\u6570\u7ec4", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int minPathSum(vector>& grid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int minPathSum(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def minPathSum(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def minPathSum(self, grid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint minPathSum(int** grid, int gridSize, int* gridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MinPathSum(int[][] grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar minPathSum = function(grid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} grid\n# @return {Integer}\ndef min_path_sum(grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func minPathSum(_ grid: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func minPathSum(grid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def minPathSum(grid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun minPathSum(grid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn min_path_sum(grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $grid\n * @return Integer\n */\n function minPathSum($grid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function minPathSum(grid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (min-path-sum grid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0064](https://leetcode-cn.com/problems/minimum-path-sum)", "[\u6700\u5c0f\u8def\u5f84\u548c](/solution/0000-0099/0064.Minimum%20Path%20Sum/README.md)", "`\u6570\u7ec4`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0064](https://leetcode.com/problems/minimum-path-sum)", "[Minimum Path Sum](/solution/0000-0099/0064.Minimum%20Path%20Sum/README_EN.md)", "`Array`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0063", "frontend_question_id": "0063", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/unique-paths-ii", "url_en": "https://leetcode.com/problems/unique-paths-ii", "relative_path_cn": "/solution/0000-0099/0063.Unique%20Paths%20II/README.md", "relative_path_en": "/solution/0000-0099/0063.Unique%20Paths%20II/README_EN.md", "title_cn": "\u4e0d\u540c\u8def\u5f84 II", "title_en": "Unique Paths II", "question_title_slug": "unique-paths-ii", "content_en": "

    A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).

    \n\n

    The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).

    \n\n

    Now consider if some obstacles are added to the grids. How many unique paths would there be?

    \n\n

    An obstacle and space is marked as 1 and 0 respectively in the grid.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: obstacleGrid = [[0,0,0],[0,1,0],[0,0,0]]\nOutput: 2\nExplanation: There is one obstacle in the middle of the 3x3 grid above.\nThere are two ways to reach the bottom-right corner:\n1. Right -> Right -> Down -> Down\n2. Down -> Down -> Right -> Right\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: obstacleGrid = [[0,1],[0,0]]\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == obstacleGrid.length
    • \n\t
    • n == obstacleGrid[i].length
    • \n\t
    • 1 <= m, n <= 100
    • \n\t
    • obstacleGrid[i][j] is 0 or 1.
    • \n
    \n", "content_cn": "

    \u4e00\u4e2a\u673a\u5668\u4eba\u4f4d\u4e8e\u4e00\u4e2a m x n \u7f51\u683c\u7684\u5de6\u4e0a\u89d2 \uff08\u8d77\u59cb\u70b9\u5728\u4e0b\u56fe\u4e2d\u6807\u8bb0\u4e3a\u201cStart\u201d \uff09\u3002

    \n\n

    \u673a\u5668\u4eba\u6bcf\u6b21\u53ea\u80fd\u5411\u4e0b\u6216\u8005\u5411\u53f3\u79fb\u52a8\u4e00\u6b65\u3002\u673a\u5668\u4eba\u8bd5\u56fe\u8fbe\u5230\u7f51\u683c\u7684\u53f3\u4e0b\u89d2\uff08\u5728\u4e0b\u56fe\u4e2d\u6807\u8bb0\u4e3a\u201cFinish\u201d\uff09\u3002

    \n\n

    \u73b0\u5728\u8003\u8651\u7f51\u683c\u4e2d\u6709\u969c\u788d\u7269\u3002\u90a3\u4e48\u4ece\u5de6\u4e0a\u89d2\u5230\u53f3\u4e0b\u89d2\u5c06\u4f1a\u6709\u591a\u5c11\u6761\u4e0d\u540c\u7684\u8def\u5f84\uff1f

    \n\n

    \n\n

    \u7f51\u683c\u4e2d\u7684\u969c\u788d\u7269\u548c\u7a7a\u4f4d\u7f6e\u5206\u522b\u7528 1 \u548c 0 \u6765\u8868\u793a\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aobstacleGrid = [[0,0,0],[0,1,0],[0,0,0]]\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\n3x3 \u7f51\u683c\u7684\u6b63\u4e2d\u95f4\u6709\u4e00\u4e2a\u969c\u788d\u7269\u3002\n\u4ece\u5de6\u4e0a\u89d2\u5230\u53f3\u4e0b\u89d2\u4e00\u5171\u6709 2 \u6761\u4e0d\u540c\u7684\u8def\u5f84\uff1a\n1. \u5411\u53f3 -> \u5411\u53f3 -> \u5411\u4e0b -> \u5411\u4e0b\n2. \u5411\u4e0b -> \u5411\u4e0b -> \u5411\u53f3 -> \u5411\u53f3\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1aobstacleGrid = [[0,1],[0,0]]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m ==\u00a0obstacleGrid.length
    • \n\t
    • n ==\u00a0obstacleGrid[i].length
    • \n\t
    • 1 <= m, n <= 100
    • \n\t
    • obstacleGrid[i][j] \u4e3a 0 \u6216 1
    • \n
    \n", "tags_en": ["Array", "Dynamic Programming"], "tags_cn": ["\u6570\u7ec4", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int uniquePathsWithObstacles(vector>& obstacleGrid) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int uniquePathsWithObstacles(int[][] obstacleGrid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def uniquePathsWithObstacles(self, obstacleGrid):\n \"\"\"\n :type obstacleGrid: List[List[int]]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def uniquePathsWithObstacles(self, obstacleGrid: List[List[int]]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint uniquePathsWithObstacles(int** obstacleGrid, int obstacleGridSize, int* obstacleGridColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int UniquePathsWithObstacles(int[][] obstacleGrid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} obstacleGrid\n * @return {number}\n */\nvar uniquePathsWithObstacles = function(obstacleGrid) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} obstacle_grid\n# @return {Integer}\ndef unique_paths_with_obstacles(obstacle_grid)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func uniquePathsWithObstacles(_ obstacleGrid: [[Int]]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func uniquePathsWithObstacles(obstacleGrid [][]int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def uniquePathsWithObstacles(obstacleGrid: Array[Array[Int]]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun uniquePathsWithObstacles(obstacleGrid: Array): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn unique_paths_with_obstacles(obstacle_grid: Vec>) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $obstacleGrid\n * @return Integer\n */\n function uniquePathsWithObstacles($obstacleGrid) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function uniquePathsWithObstacles(obstacleGrid: number[][]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (unique-paths-with-obstacles obstacleGrid)\n (-> (listof (listof exact-integer?)) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0063](https://leetcode-cn.com/problems/unique-paths-ii)", "[\u4e0d\u540c\u8def\u5f84 II](/solution/0000-0099/0063.Unique%20Paths%20II/README.md)", "`\u6570\u7ec4`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0063](https://leetcode.com/problems/unique-paths-ii)", "[Unique Paths II](/solution/0000-0099/0063.Unique%20Paths%20II/README_EN.md)", "`Array`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0062", "frontend_question_id": "0062", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/unique-paths", "url_en": "https://leetcode.com/problems/unique-paths", "relative_path_cn": "/solution/0000-0099/0062.Unique%20Paths/README.md", "relative_path_en": "/solution/0000-0099/0062.Unique%20Paths/README_EN.md", "title_cn": "\u4e0d\u540c\u8def\u5f84", "title_en": "Unique Paths", "question_title_slug": "unique-paths", "content_en": "

    A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).

    \n\n

    The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).

    \n\n

    How many possible unique paths are there?

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: m = 3, n = 7\nOutput: 28\n
    \n\n

    Example 2:

    \n\n
    \nInput: m = 3, n = 2\nOutput: 3\nExplanation:\nFrom the top-left corner, there are a total of 3 ways to reach the bottom-right corner:\n1. Right -> Down -> Down\n2. Down -> Down -> Right\n3. Down -> Right -> Down\n
    \n\n

    Example 3:

    \n\n
    \nInput: m = 7, n = 3\nOutput: 28\n
    \n\n

    Example 4:

    \n\n
    \nInput: m = 3, n = 3\nOutput: 6\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= m, n <= 100
    • \n\t
    • It's guaranteed that the answer will be less than or equal to 2 * 109.
    • \n
    \n", "content_cn": "

    \u4e00\u4e2a\u673a\u5668\u4eba\u4f4d\u4e8e\u4e00\u4e2a m x n\u00a0\u7f51\u683c\u7684\u5de6\u4e0a\u89d2 \uff08\u8d77\u59cb\u70b9\u5728\u4e0b\u56fe\u4e2d\u6807\u8bb0\u4e3a \u201cStart\u201d \uff09\u3002

    \n\n

    \u673a\u5668\u4eba\u6bcf\u6b21\u53ea\u80fd\u5411\u4e0b\u6216\u8005\u5411\u53f3\u79fb\u52a8\u4e00\u6b65\u3002\u673a\u5668\u4eba\u8bd5\u56fe\u8fbe\u5230\u7f51\u683c\u7684\u53f3\u4e0b\u89d2\uff08\u5728\u4e0b\u56fe\u4e2d\u6807\u8bb0\u4e3a \u201cFinish\u201d \uff09\u3002

    \n\n

    \u95ee\u603b\u5171\u6709\u591a\u5c11\u6761\u4e0d\u540c\u7684\u8def\u5f84\uff1f

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1am = 3, n = 7\n\u8f93\u51fa\uff1a28
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1am = 3, n = 2\n\u8f93\u51fa\uff1a3\n\u89e3\u91ca\uff1a\n\u4ece\u5de6\u4e0a\u89d2\u5f00\u59cb\uff0c\u603b\u5171\u6709 3 \u6761\u8def\u5f84\u53ef\u4ee5\u5230\u8fbe\u53f3\u4e0b\u89d2\u3002\n1. \u5411\u53f3 -> \u5411\u4e0b -> \u5411\u4e0b\n2. \u5411\u4e0b -> \u5411\u4e0b -> \u5411\u53f3\n3. \u5411\u4e0b -> \u5411\u53f3 -> \u5411\u4e0b\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1am = 7, n = 3\n\u8f93\u51fa\uff1a28\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1am = 3, n = 3\n\u8f93\u51fa\uff1a6
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= m, n <= 100
    • \n\t
    • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u7b54\u6848\u5c0f\u4e8e\u7b49\u4e8e 2 * 109
    • \n
    \n", "tags_en": ["Array", "Dynamic Programming"], "tags_cn": ["\u6570\u7ec4", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int uniquePaths(int m, int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int uniquePaths(int m, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def uniquePaths(self, m, n):\n \"\"\"\n :type m: int\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def uniquePaths(self, m: int, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint uniquePaths(int m, int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int UniquePaths(int m, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} m\n * @param {number} n\n * @return {number}\n */\nvar uniquePaths = function(m, n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} m\n# @param {Integer} n\n# @return {Integer}\ndef unique_paths(m, n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func uniquePaths(_ m: Int, _ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func uniquePaths(m int, n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def uniquePaths(m: Int, n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun uniquePaths(m: Int, n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn unique_paths(m: i32, n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $m\n * @param Integer $n\n * @return Integer\n */\n function uniquePaths($m, $n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function uniquePaths(m: number, n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (unique-paths m n)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0062](https://leetcode-cn.com/problems/unique-paths)", "[\u4e0d\u540c\u8def\u5f84](/solution/0000-0099/0062.Unique%20Paths/README.md)", "`\u6570\u7ec4`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0062](https://leetcode.com/problems/unique-paths)", "[Unique Paths](/solution/0000-0099/0062.Unique%20Paths/README_EN.md)", "`Array`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0061", "frontend_question_id": "0061", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/rotate-list", "url_en": "https://leetcode.com/problems/rotate-list", "relative_path_cn": "/solution/0000-0099/0061.Rotate%20List/README.md", "relative_path_en": "/solution/0000-0099/0061.Rotate%20List/README_EN.md", "title_cn": "\u65cb\u8f6c\u94fe\u8868", "title_en": "Rotate List", "question_title_slug": "rotate-list", "content_en": "

    Given the head of a linked list, rotate the list to the right by k places.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: head = [1,2,3,4,5], k = 2\nOutput: [4,5,1,2,3]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: head = [0,1,2], k = 4\nOutput: [2,0,1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the list is in the range [0, 500].
    • \n\t
    • -100 <= Node.val <= 100
    • \n\t
    • 0 <= k <= 2 * 109
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u94fe\u8868\u7684\u5934\u8282\u70b9 head \uff0c\u65cb\u8f6c\u94fe\u8868\uff0c\u5c06\u94fe\u8868\u6bcf\u4e2a\u8282\u70b9\u5411\u53f3\u79fb\u52a8\u00a0k\u00a0\u4e2a\u4f4d\u7f6e\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1ahead = [1,2,3,4,5], k = 2\n\u8f93\u51fa\uff1a[4,5,1,2,3]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1ahead = [0,1,2], k = 4\n\u8f93\u51fa\uff1a[2,0,1]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u94fe\u8868\u4e2d\u8282\u70b9\u7684\u6570\u76ee\u5728\u8303\u56f4 [0, 500] \u5185
    • \n\t
    • -100 <= Node.val <= 100
    • \n\t
    • 0 <= k <= 2 * 109
    • \n
    \n", "tags_en": ["Linked List", "Two Pointers"], "tags_cn": ["\u94fe\u8868", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n ListNode* rotateRight(ListNode* head, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public ListNode rotateRight(ListNode head, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def rotateRight(self, head, k):\n \"\"\"\n :type head: ListNode\n :type k: int\n :rtype: ListNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def rotateRight(self, head: ListNode, k: int) -> ListNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nstruct ListNode* rotateRight(struct ListNode* head, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public ListNode RotateRight(ListNode head, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} head\n * @param {number} k\n * @return {ListNode}\n */\nvar rotateRight = function(head, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode} head\n# @param {Integer} k\n# @return {ListNode}\ndef rotate_right(head, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func rotateRight(_ head: ListNode?, _ k: Int) -> ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc rotateRight(head *ListNode, k int) *ListNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def rotateRight(head: ListNode, k: Int): ListNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun rotateRight(head: ListNode?, k: Int): ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn rotate_right(head: Option>, k: i32) -> Option> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @param Integer $k\n * @return ListNode\n */\n function rotateRight($head, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction rotateRight(head: ListNode | null, k: number): ListNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (rotate-right head k)\n (-> (or/c list-node? #f) exact-integer? (or/c list-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0061](https://leetcode-cn.com/problems/rotate-list)", "[\u65cb\u8f6c\u94fe\u8868](/solution/0000-0099/0061.Rotate%20List/README.md)", "`\u94fe\u8868`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0061](https://leetcode.com/problems/rotate-list)", "[Rotate List](/solution/0000-0099/0061.Rotate%20List/README_EN.md)", "`Linked List`,`Two Pointers`", "Medium", ""]}, {"question_id": "0060", "frontend_question_id": "0060", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/permutation-sequence", "url_en": "https://leetcode.com/problems/permutation-sequence", "relative_path_cn": "/solution/0000-0099/0060.Permutation%20Sequence/README.md", "relative_path_en": "/solution/0000-0099/0060.Permutation%20Sequence/README_EN.md", "title_cn": "\u6392\u5217\u5e8f\u5217", "title_en": "Permutation Sequence", "question_title_slug": "permutation-sequence", "content_en": "

    The set [1, 2, 3, ..., n] contains a total of n! unique permutations.

    \n\n

    By listing and labeling all of the permutations in order, we get the following sequence for n = 3:

    \n\n
      \n\t
    1. "123"
    2. \n\t
    3. "132"
    4. \n\t
    5. "213"
    6. \n\t
    7. "231"
    8. \n\t
    9. "312"
    10. \n\t
    11. "321"
    12. \n
    \n\n

    Given n and k, return the kth permutation sequence.

    \n\n

     

    \n

    Example 1:

    \n
    Input: n = 3, k = 3\nOutput: \"213\"\n

    Example 2:

    \n
    Input: n = 4, k = 9\nOutput: \"2314\"\n

    Example 3:

    \n
    Input: n = 3, k = 1\nOutput: \"123\"\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 9
    • \n\t
    • 1 <= k <= n!
    • \n
    \n", "content_cn": "

    \u7ed9\u51fa\u96c6\u5408\u00a0[1,2,3,...,n]\uff0c\u5176\u6240\u6709\u5143\u7d20\u5171\u6709\u00a0n! \u79cd\u6392\u5217\u3002

    \n\n

    \u6309\u5927\u5c0f\u987a\u5e8f\u5217\u51fa\u6240\u6709\u6392\u5217\u60c5\u51b5\uff0c\u5e76\u4e00\u4e00\u6807\u8bb0\uff0c\u5f53\u00a0n = 3 \u65f6, \u6240\u6709\u6392\u5217\u5982\u4e0b\uff1a

    \n\n
      \n\t
    1. \"123\"
    2. \n\t
    3. \"132\"
    4. \n\t
    5. \"213\"
    6. \n\t
    7. \"231\"
    8. \n\t
    9. \"312\"
    10. \n\t
    11. \"321\"
    12. \n
    \n\n

    \u7ed9\u5b9a\u00a0n \u548c\u00a0k\uff0c\u8fd4\u56de\u7b2c\u00a0k\u00a0\u4e2a\u6392\u5217\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 3, k = 3\n\u8f93\u51fa\uff1a\"213\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 4, k = 9\n\u8f93\u51fa\uff1a\"2314\"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 3, k = 1\n\u8f93\u51fa\uff1a\"123\"\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 9
    • \n\t
    • 1 <= k <= n!
    • \n
    \n", "tags_en": ["Math", "Backtracking"], "tags_cn": ["\u6570\u5b66", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string getPermutation(int n, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String getPermutation(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def getPermutation(self, n, k):\n \"\"\"\n :type n: int\n :type k: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def getPermutation(self, n: int, k: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * getPermutation(int n, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string GetPermutation(int n, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @param {number} k\n * @return {string}\n */\nvar getPermutation = function(n, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @param {Integer} k\n# @return {String}\ndef get_permutation(n, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func getPermutation(_ n: Int, _ k: Int) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func getPermutation(n int, k int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def getPermutation(n: Int, k: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun getPermutation(n: Int, k: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn get_permutation(n: i32, k: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $k\n * @return String\n */\n function getPermutation($n, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function getPermutation(n: number, k: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (get-permutation n k)\n (-> exact-integer? exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0060](https://leetcode-cn.com/problems/permutation-sequence)", "[\u6392\u5217\u5e8f\u5217](/solution/0000-0099/0060.Permutation%20Sequence/README.md)", "`\u6570\u5b66`,`\u56de\u6eaf\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[0060](https://leetcode.com/problems/permutation-sequence)", "[Permutation Sequence](/solution/0000-0099/0060.Permutation%20Sequence/README_EN.md)", "`Math`,`Backtracking`", "Hard", ""]}, {"question_id": "0059", "frontend_question_id": "0059", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/spiral-matrix-ii", "url_en": "https://leetcode.com/problems/spiral-matrix-ii", "relative_path_cn": "/solution/0000-0099/0059.Spiral%20Matrix%20II/README.md", "relative_path_en": "/solution/0000-0099/0059.Spiral%20Matrix%20II/README_EN.md", "title_cn": "\u87ba\u65cb\u77e9\u9635 II", "title_en": "Spiral Matrix II", "question_title_slug": "spiral-matrix-ii", "content_en": "

    Given a positive integer n, generate an n x n matrix filled with elements from 1 to n2 in spiral order.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: n = 3\nOutput: [[1,2,3],[8,9,4],[7,6,5]]\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 1\nOutput: [[1]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 20
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6b63\u6574\u6570\u00a0n \uff0c\u751f\u6210\u4e00\u4e2a\u5305\u542b 1 \u5230\u00a0n2\u00a0\u6240\u6709\u5143\u7d20\uff0c\u4e14\u5143\u7d20\u6309\u987a\u65f6\u9488\u987a\u5e8f\u87ba\u65cb\u6392\u5217\u7684\u00a0n x n \u6b63\u65b9\u5f62\u77e9\u9635 matrix \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1an = 3\n\u8f93\u51fa\uff1a[[1,2,3],[8,9,4],[7,6,5]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1a[[1]]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 20
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> generateMatrix(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[][] generateMatrix(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def generateMatrix(self, n):\n \"\"\"\n :type n: int\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def generateMatrix(self, n: int) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** generateMatrix(int n, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[][] GenerateMatrix(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number[][]}\n */\nvar generateMatrix = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer[][]}\ndef generate_matrix(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func generateMatrix(_ n: Int) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func generateMatrix(n int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def generateMatrix(n: Int): Array[Array[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun generateMatrix(n: Int): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn generate_matrix(n: i32) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer[][]\n */\n function generateMatrix($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function generateMatrix(n: number): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (generate-matrix n)\n (-> exact-integer? (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0059](https://leetcode-cn.com/problems/spiral-matrix-ii)", "[\u87ba\u65cb\u77e9\u9635 II](/solution/0000-0099/0059.Spiral%20Matrix%20II/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0059](https://leetcode.com/problems/spiral-matrix-ii)", "[Spiral Matrix II](/solution/0000-0099/0059.Spiral%20Matrix%20II/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0058", "frontend_question_id": "0058", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/length-of-last-word", "url_en": "https://leetcode.com/problems/length-of-last-word", "relative_path_cn": "/solution/0000-0099/0058.Length%20of%20Last%20Word/README.md", "relative_path_en": "/solution/0000-0099/0058.Length%20of%20Last%20Word/README_EN.md", "title_cn": "\u6700\u540e\u4e00\u4e2a\u5355\u8bcd\u7684\u957f\u5ea6", "title_en": "Length of Last Word", "question_title_slug": "length-of-last-word", "content_en": "

    Given a string s consists of some words separated by spaces, return the length of the last word in the string. If the last word does not exist, return 0.

    \n\n

    A word is a maximal substring consisting of non-space characters only.

    \n\n

     

    \n

    Example 1:

    \n
    Input: s = \"Hello World\"\nOutput: 5\n

    Example 2:

    \n
    Input: s = \" \"\nOutput: 0\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 104
    • \n\t
    • s consists of only English letters and spaces ' '.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s\uff0c\u7531\u82e5\u5e72\u5355\u8bcd\u7ec4\u6210\uff0c\u5355\u8bcd\u4e4b\u95f4\u7528\u7a7a\u683c\u9694\u5f00\u3002\u8fd4\u56de\u5b57\u7b26\u4e32\u4e2d\u6700\u540e\u4e00\u4e2a\u5355\u8bcd\u7684\u957f\u5ea6\u3002\u5982\u679c\u4e0d\u5b58\u5728\u6700\u540e\u4e00\u4e2a\u5355\u8bcd\uff0c\u8bf7\u8fd4\u56de 0\u00a0\u3002

    \n\n

    \u5355\u8bcd \u662f\u6307\u4ec5\u7531\u5b57\u6bcd\u7ec4\u6210\u3001\u4e0d\u5305\u542b\u4efb\u4f55\u7a7a\u683c\u5b57\u7b26\u7684\u6700\u5927\u5b50\u5b57\u7b26\u4e32\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"Hello World\"\n\u8f93\u51fa\uff1a5\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \" \"\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 104
    • \n\t
    • s \u4ec5\u6709\u82f1\u6587\u5b57\u6bcd\u548c\u7a7a\u683c ' ' \u7ec4\u6210
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int lengthOfLastWord(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int lengthOfLastWord(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def lengthOfLastWord(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def lengthOfLastWord(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint lengthOfLastWord(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LengthOfLastWord(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar lengthOfLastWord = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef length_of_last_word(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func lengthOfLastWord(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func lengthOfLastWord(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def lengthOfLastWord(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun lengthOfLastWord(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn length_of_last_word(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function lengthOfLastWord($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function lengthOfLastWord(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (length-of-last-word s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0058](https://leetcode-cn.com/problems/length-of-last-word)", "[\u6700\u540e\u4e00\u4e2a\u5355\u8bcd\u7684\u957f\u5ea6](/solution/0000-0099/0058.Length%20of%20Last%20Word/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0058](https://leetcode.com/problems/length-of-last-word)", "[Length of Last Word](/solution/0000-0099/0058.Length%20of%20Last%20Word/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "0057", "frontend_question_id": "0057", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/insert-interval", "url_en": "https://leetcode.com/problems/insert-interval", "relative_path_cn": "/solution/0000-0099/0057.Insert%20Interval/README.md", "relative_path_en": "/solution/0000-0099/0057.Insert%20Interval/README_EN.md", "title_cn": "\u63d2\u5165\u533a\u95f4", "title_en": "Insert Interval", "question_title_slug": "insert-interval", "content_en": "

    Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).

    \n\n

    You may assume that the intervals were initially sorted according to their start times.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: intervals = [[1,3],[6,9]], newInterval = [2,5]\nOutput: [[1,5],[6,9]]\n
    \n\n

    Example 2:

    \n\n
    \nInput: intervals = [[1,2],[3,5],[6,7],[8,10],[12,16]], newInterval = [4,8]\nOutput: [[1,2],[3,10],[12,16]]\nExplanation: Because the new interval [4,8] overlaps with [3,5],[6,7],[8,10].
    \n\n

    Example 3:

    \n\n
    \nInput: intervals = [], newInterval = [5,7]\nOutput: [[5,7]]\n
    \n\n

    Example 4:

    \n\n
    \nInput: intervals = [[1,5]], newInterval = [2,3]\nOutput: [[1,5]]\n
    \n\n

    Example 5:

    \n\n
    \nInput: intervals = [[1,5]], newInterval = [2,7]\nOutput: [[1,7]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= intervals.length <= 104
    • \n\t
    • intervals[i].length == 2
    • \n\t
    • 0 <= intervals[i][0] <= intervals[i][1] <= 105
    • \n\t
    • intervals is sorted by intervals[i][0] in ascending order.
    • \n\t
    • newInterval.length == 2
    • \n\t
    • 0 <= newInterval[0] <= newInterval[1] <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a \u65e0\u91cd\u53e0\u7684 \uff0c\u6309\u7167\u533a\u95f4\u8d77\u59cb\u7aef\u70b9\u6392\u5e8f\u7684\u533a\u95f4\u5217\u8868\u3002

    \n\n

    \u5728\u5217\u8868\u4e2d\u63d2\u5165\u4e00\u4e2a\u65b0\u7684\u533a\u95f4\uff0c\u4f60\u9700\u8981\u786e\u4fdd\u5217\u8868\u4e2d\u7684\u533a\u95f4\u4ecd\u7136\u6709\u5e8f\u4e14\u4e0d\u91cd\u53e0\uff08\u5982\u679c\u6709\u5fc5\u8981\u7684\u8bdd\uff0c\u53ef\u4ee5\u5408\u5e76\u533a\u95f4\uff09\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\u00a01\uff1a

    \n\n
    \n\u8f93\u5165\uff1aintervals = [[1,3],[6,9]], newInterval = [2,5]\n\u8f93\u51fa\uff1a[[1,5],[6,9]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aintervals = [[1,2],[3,5],[6,7],[8,10],[12,16]], newInterval = [4,8]\n\u8f93\u51fa\uff1a[[1,2],[3,10],[12,16]]\n\u89e3\u91ca\uff1a\u8fd9\u662f\u56e0\u4e3a\u65b0\u7684\u533a\u95f4 [4,8] \u4e0e [3,5],[6,7],[8,10]\u00a0\u91cd\u53e0\u3002
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aintervals = [], newInterval = [5,7]\n\u8f93\u51fa\uff1a[[5,7]]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1aintervals = [[1,5]], newInterval = [2,3]\n\u8f93\u51fa\uff1a[[1,5]]\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1aintervals = [[1,5]], newInterval = [2,7]\n\u8f93\u51fa\uff1a[[1,7]]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= intervals.length <= 104
    • \n\t
    • intervals[i].length == 2
    • \n\t
    • 0 <=\u00a0intervals[i][0] <=\u00a0intervals[i][1] <= 105
    • \n\t
    • intervals \u6839\u636e intervals[i][0] \u6309 \u5347\u5e8f \u6392\u5217
    • \n\t
    • newInterval.length == 2
    • \n\t
    • 0 <=\u00a0newInterval[0] <=\u00a0newInterval[1] <= 105
    • \n
    \n", "tags_en": ["Sort", "Array"], "tags_cn": ["\u6392\u5e8f", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> insert(vector>& intervals, vector& newInterval) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[][] insert(int[][] intervals, int[] newInterval) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def insert(self, intervals, newInterval):\n \"\"\"\n :type intervals: List[List[int]]\n :type newInterval: List[int]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def insert(self, intervals: List[List[int]], newInterval: List[int]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** insert(int** intervals, int intervalsSize, int* intervalsColSize, int* newInterval, int newIntervalSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[][] Insert(int[][] intervals, int[] newInterval) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} intervals\n * @param {number[]} newInterval\n * @return {number[][]}\n */\nvar insert = function(intervals, newInterval) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} intervals\n# @param {Integer[]} new_interval\n# @return {Integer[][]}\ndef insert(intervals, new_interval)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func insert(_ intervals: [[Int]], _ newInterval: [Int]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func insert(intervals [][]int, newInterval []int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def insert(intervals: Array[Array[Int]], newInterval: Array[Int]): Array[Array[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun insert(intervals: Array, newInterval: IntArray): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn insert(intervals: Vec>, new_interval: Vec) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $intervals\n * @param Integer[] $newInterval\n * @return Integer[][]\n */\n function insert($intervals, $newInterval) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function insert(intervals: number[][], newInterval: number[]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (insert intervals newInterval)\n (-> (listof (listof exact-integer?)) (listof exact-integer?) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0057](https://leetcode-cn.com/problems/insert-interval)", "[\u63d2\u5165\u533a\u95f4](/solution/0000-0099/0057.Insert%20Interval/README.md)", "`\u6392\u5e8f`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0057](https://leetcode.com/problems/insert-interval)", "[Insert Interval](/solution/0000-0099/0057.Insert%20Interval/README_EN.md)", "`Sort`,`Array`", "Medium", ""]}, {"question_id": "0056", "frontend_question_id": "0056", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/merge-intervals", "url_en": "https://leetcode.com/problems/merge-intervals", "relative_path_cn": "/solution/0000-0099/0056.Merge%20Intervals/README.md", "relative_path_en": "/solution/0000-0099/0056.Merge%20Intervals/README_EN.md", "title_cn": "\u5408\u5e76\u533a\u95f4", "title_en": "Merge Intervals", "question_title_slug": "merge-intervals", "content_en": "

    Given an array of intervals where intervals[i] = [starti, endi], merge all overlapping intervals, and return an array of the non-overlapping intervals that cover all the intervals in the input.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: intervals = [[1,3],[2,6],[8,10],[15,18]]\nOutput: [[1,6],[8,10],[15,18]]\nExplanation: Since intervals [1,3] and [2,6] overlaps, merge them into [1,6].\n
    \n\n

    Example 2:

    \n\n
    \nInput: intervals = [[1,4],[4,5]]\nOutput: [[1,5]]\nExplanation: Intervals [1,4] and [4,5] are considered overlapping.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= intervals.length <= 104
    • \n\t
    • intervals[i].length == 2
    • \n\t
    • 0 <= starti <= endi <= 104
    • \n
    \n", "content_cn": "

    \u4ee5\u6570\u7ec4 intervals \u8868\u793a\u82e5\u5e72\u4e2a\u533a\u95f4\u7684\u96c6\u5408\uff0c\u5176\u4e2d\u5355\u4e2a\u533a\u95f4\u4e3a intervals[i] = [starti, endi] \u3002\u8bf7\u4f60\u5408\u5e76\u6240\u6709\u91cd\u53e0\u7684\u533a\u95f4\uff0c\u5e76\u8fd4\u56de\u4e00\u4e2a\u4e0d\u91cd\u53e0\u7684\u533a\u95f4\u6570\u7ec4\uff0c\u8be5\u6570\u7ec4\u9700\u6070\u597d\u8986\u76d6\u8f93\u5165\u4e2d\u7684\u6240\u6709\u533a\u95f4\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aintervals = [[1,3],[2,6],[8,10],[15,18]]\n\u8f93\u51fa\uff1a[[1,6],[8,10],[15,18]]\n\u89e3\u91ca\uff1a\u533a\u95f4 [1,3] \u548c [2,6] \u91cd\u53e0, \u5c06\u5b83\u4eec\u5408\u5e76\u4e3a [1,6].\n
    \n\n

    \u793a\u4f8b\u00a02\uff1a

    \n\n
    \n\u8f93\u5165\uff1aintervals = [[1,4],[4,5]]\n\u8f93\u51fa\uff1a[[1,5]]\n\u89e3\u91ca\uff1a\u533a\u95f4 [1,4] \u548c [4,5] \u53ef\u88ab\u89c6\u4e3a\u91cd\u53e0\u533a\u95f4\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= intervals.length <= 104
    • \n\t
    • intervals[i].length == 2
    • \n\t
    • 0 <= starti <= endi <= 104
    • \n
    \n", "tags_en": ["Sort", "Array"], "tags_cn": ["\u6392\u5e8f", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> merge(vector>& intervals) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[][] merge(int[][] intervals) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def merge(self, intervals):\n \"\"\"\n :type intervals: List[List[int]]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def merge(self, intervals: List[List[int]]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** merge(int** intervals, int intervalsSize, int* intervalsColSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[][] Merge(int[][] intervals) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} intervals\n * @return {number[][]}\n */\nvar merge = function(intervals) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} intervals\n# @return {Integer[][]}\ndef merge(intervals)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func merge(_ intervals: [[Int]]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func merge(intervals [][]int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def merge(intervals: Array[Array[Int]]): Array[Array[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun merge(intervals: Array): Array {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn merge(intervals: Vec>) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $intervals\n * @return Integer[][]\n */\n function merge($intervals) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function merge(intervals: number[][]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (merge intervals)\n (-> (listof (listof exact-integer?)) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0056](https://leetcode-cn.com/problems/merge-intervals)", "[\u5408\u5e76\u533a\u95f4](/solution/0000-0099/0056.Merge%20Intervals/README.md)", "`\u6392\u5e8f`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0056](https://leetcode.com/problems/merge-intervals)", "[Merge Intervals](/solution/0000-0099/0056.Merge%20Intervals/README_EN.md)", "`Sort`,`Array`", "Medium", ""]}, {"question_id": "0055", "frontend_question_id": "0055", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/jump-game", "url_en": "https://leetcode.com/problems/jump-game", "relative_path_cn": "/solution/0000-0099/0055.Jump%20Game/README.md", "relative_path_en": "/solution/0000-0099/0055.Jump%20Game/README_EN.md", "title_cn": "\u8df3\u8dc3\u6e38\u620f", "title_en": "Jump Game", "question_title_slug": "jump-game", "content_en": "

    Given an array of non-negative integers nums, you are initially positioned at the first index of the array.

    \n\n

    Each element in the array represents your maximum jump length at that position.

    \n\n

    Determine if you are able to reach the last index.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [2,3,1,1,4]\nOutput: true\nExplanation: Jump 1 step from index 0 to 1, then 3 steps to the last index.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [3,2,1,0,4]\nOutput: false\nExplanation: You will always arrive at index 3 no matter what. Its maximum jump length is 0, which makes it impossible to reach the last index.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 104
    • \n\t
    • 0 <= nums[i] <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\u6570\u7ec4\u00a0nums \uff0c\u4f60\u6700\u521d\u4f4d\u4e8e\u6570\u7ec4\u7684 \u7b2c\u4e00\u4e2a\u4e0b\u6807 \u3002

    \n\n

    \u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u4ee3\u8868\u4f60\u5728\u8be5\u4f4d\u7f6e\u53ef\u4ee5\u8df3\u8dc3\u7684\u6700\u5927\u957f\u5ea6\u3002

    \n\n

    \u5224\u65ad\u4f60\u662f\u5426\u80fd\u591f\u5230\u8fbe\u6700\u540e\u4e00\u4e2a\u4e0b\u6807\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\u00a01\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [2,3,1,1,4]\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u53ef\u4ee5\u5148\u8df3 1 \u6b65\uff0c\u4ece\u4e0b\u6807 0 \u5230\u8fbe\u4e0b\u6807 1, \u7136\u540e\u518d\u4ece\u4e0b\u6807 1 \u8df3 3 \u6b65\u5230\u8fbe\u6700\u540e\u4e00\u4e2a\u4e0b\u6807\u3002\n
    \n\n

    \u793a\u4f8b\u00a02\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [3,2,1,0,4]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u65e0\u8bba\u600e\u6837\uff0c\u603b\u4f1a\u5230\u8fbe\u4e0b\u6807\u4e3a 3 \u7684\u4f4d\u7f6e\u3002\u4f46\u8be5\u4e0b\u6807\u7684\u6700\u5927\u8df3\u8dc3\u957f\u5ea6\u662f 0 \uff0c \u6240\u4ee5\u6c38\u8fdc\u4e0d\u53ef\u80fd\u5230\u8fbe\u6700\u540e\u4e00\u4e2a\u4e0b\u6807\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 3 * 104
    • \n\t
    • 0 <= nums[i] <= 105
    • \n
    \n", "tags_en": ["Greedy", "Array"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool canJump(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean canJump(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def canJump(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def canJump(self, nums: List[int]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool canJump(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool CanJump(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {boolean}\n */\nvar canJump = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Boolean}\ndef can_jump(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func canJump(_ nums: [Int]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func canJump(nums []int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def canJump(nums: Array[Int]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun canJump(nums: IntArray): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn can_jump(nums: Vec) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Boolean\n */\n function canJump($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function canJump(nums: number[]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (can-jump nums)\n (-> (listof exact-integer?) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0055](https://leetcode-cn.com/problems/jump-game)", "[\u8df3\u8dc3\u6e38\u620f](/solution/0000-0099/0055.Jump%20Game/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0055](https://leetcode.com/problems/jump-game)", "[Jump Game](/solution/0000-0099/0055.Jump%20Game/README_EN.md)", "`Greedy`,`Array`", "Medium", ""]}, {"question_id": "0054", "frontend_question_id": "0054", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/spiral-matrix", "url_en": "https://leetcode.com/problems/spiral-matrix", "relative_path_cn": "/solution/0000-0099/0054.Spiral%20Matrix/README.md", "relative_path_en": "/solution/0000-0099/0054.Spiral%20Matrix/README_EN.md", "title_cn": "\u87ba\u65cb\u77e9\u9635", "title_en": "Spiral Matrix", "question_title_slug": "spiral-matrix", "content_en": "

    Given an m x n matrix, return all elements of the matrix in spiral order.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: matrix = [[1,2,3],[4,5,6],[7,8,9]]\nOutput: [1,2,3,6,9,8,7,4,5]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: matrix = [[1,2,3,4],[5,6,7,8],[9,10,11,12]]\nOutput: [1,2,3,4,8,12,11,10,9,5,6,7]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • m == matrix.length
    • \n\t
    • n == matrix[i].length
    • \n\t
    • 1 <= m, n <= 10
    • \n\t
    • -100 <= matrix[i][j] <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a m \u884c n \u5217\u7684\u77e9\u9635\u00a0matrix \uff0c\u8bf7\u6309\u7167 \u987a\u65f6\u9488\u87ba\u65cb\u987a\u5e8f \uff0c\u8fd4\u56de\u77e9\u9635\u4e2d\u7684\u6240\u6709\u5143\u7d20\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1amatrix = [[1,2,3],[4,5,6],[7,8,9]]\n\u8f93\u51fa\uff1a[1,2,3,6,9,8,7,4,5]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1amatrix = [[1,2,3,4],[5,6,7,8],[9,10,11,12]]\n\u8f93\u51fa\uff1a[1,2,3,4,8,12,11,10,9,5,6,7]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • m == matrix.length
    • \n\t
    • n == matrix[i].length
    • \n\t
    • 1 <= m, n <= 10
    • \n\t
    • -100 <= matrix[i][j] <= 100
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector spiralOrder(vector>& matrix) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List spiralOrder(int[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def spiralOrder(self, matrix):\n \"\"\"\n :type matrix: List[List[int]]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def spiralOrder(self, matrix: List[List[int]]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* spiralOrder(int** matrix, int matrixSize, int* matrixColSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList SpiralOrder(int[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} matrix\n * @return {number[]}\n */\nvar spiralOrder = function(matrix) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} matrix\n# @return {Integer[]}\ndef spiral_order(matrix)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func spiralOrder(_ matrix: [[Int]]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func spiralOrder(matrix [][]int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def spiralOrder(matrix: Array[Array[Int]]): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun spiralOrder(matrix: Array): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn spiral_order(matrix: Vec>) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $matrix\n * @return Integer[]\n */\n function spiralOrder($matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function spiralOrder(matrix: number[][]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (spiral-order matrix)\n (-> (listof (listof exact-integer?)) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0054](https://leetcode-cn.com/problems/spiral-matrix)", "[\u87ba\u65cb\u77e9\u9635](/solution/0000-0099/0054.Spiral%20Matrix/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0054](https://leetcode.com/problems/spiral-matrix)", "[Spiral Matrix](/solution/0000-0099/0054.Spiral%20Matrix/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0053", "frontend_question_id": "0053", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/maximum-subarray", "url_en": "https://leetcode.com/problems/maximum-subarray", "relative_path_cn": "/solution/0000-0099/0053.Maximum%20Subarray/README.md", "relative_path_en": "/solution/0000-0099/0053.Maximum%20Subarray/README_EN.md", "title_cn": "\u6700\u5927\u5b50\u5e8f\u548c", "title_en": "Maximum Subarray", "question_title_slug": "maximum-subarray", "content_en": "

    Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [-2,1,-3,4,-1,2,1,-5,4]\nOutput: 6\nExplanation: [4,-1,2,1] has the largest sum = 6.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1]\nOutput: 1\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [5,4,-1,7,8]\nOutput: 23\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 3 * 104
    • \n\t
    • -105 <= nums[i] <= 105
    • \n
    \n\n

     

    \nFollow up: If you have figured out the O(n) solution, try coding another solution using the divide and conquer approach, which is more subtle.", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums\u00a0\uff0c\u627e\u5230\u4e00\u4e2a\u5177\u6709\u6700\u5927\u548c\u7684\u8fde\u7eed\u5b50\u6570\u7ec4\uff08\u5b50\u6570\u7ec4\u6700\u5c11\u5305\u542b\u4e00\u4e2a\u5143\u7d20\uff09\uff0c\u8fd4\u56de\u5176\u6700\u5927\u548c\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [-2,1,-3,4,-1,2,1,-5,4]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u8fde\u7eed\u5b50\u6570\u7ec4\u00a0[4,-1,2,1] \u7684\u548c\u6700\u5927\uff0c\u4e3a\u00a06 \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [0]\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [-1]\n\u8f93\u51fa\uff1a-1\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [-100000]\n\u8f93\u51fa\uff1a-100000\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 3 * 104
    • \n\t
    • -105 <= nums[i] <= 105
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u5982\u679c\u4f60\u5df2\u7ecf\u5b9e\u73b0\u590d\u6742\u5ea6\u4e3a O(n) \u7684\u89e3\u6cd5\uff0c\u5c1d\u8bd5\u4f7f\u7528\u66f4\u4e3a\u7cbe\u5999\u7684 \u5206\u6cbb\u6cd5 \u6c42\u89e3\u3002

    \n", "tags_en": ["Array", "Divide and Conquer", "Dynamic Programming"], "tags_cn": ["\u6570\u7ec4", "\u5206\u6cbb\u7b97\u6cd5", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxSubArray(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxSubArray(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxSubArray(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxSubArray(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxSubArray(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxSubArray(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar maxSubArray = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef max_sub_array(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxSubArray(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxSubArray(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxSubArray(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxSubArray(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_sub_array(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function maxSubArray($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxSubArray(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-sub-array nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0053](https://leetcode-cn.com/problems/maximum-subarray)", "[\u6700\u5927\u5b50\u5e8f\u548c](/solution/0000-0099/0053.Maximum%20Subarray/README.md)", "`\u6570\u7ec4`,`\u5206\u6cbb\u7b97\u6cd5`,`\u52a8\u6001\u89c4\u5212`", "\u7b80\u5355", ""], "md_table_row_en": ["[0053](https://leetcode.com/problems/maximum-subarray)", "[Maximum Subarray](/solution/0000-0099/0053.Maximum%20Subarray/README_EN.md)", "`Array`,`Divide and Conquer`,`Dynamic Programming`", "Easy", ""]}, {"question_id": "0052", "frontend_question_id": "0052", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/n-queens-ii", "url_en": "https://leetcode.com/problems/n-queens-ii", "relative_path_cn": "/solution/0000-0099/0052.N-Queens%20II/README.md", "relative_path_en": "/solution/0000-0099/0052.N-Queens%20II/README_EN.md", "title_cn": "N\u7687\u540e II", "title_en": "N-Queens II", "question_title_slug": "n-queens-ii", "content_en": "

    The n-queens puzzle is the problem of placing n queens on an n x n chessboard such that no two queens attack each other.

    \n\n

    Given an integer n, return the number of distinct solutions to the n-queens puzzle.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: n = 4\nOutput: 2\nExplanation: There are two distinct solutions to the 4-queens puzzle as shown.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 1\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 9
    • \n
    \n", "content_cn": "

    n\u00a0\u7687\u540e\u95ee\u9898 \u7814\u7a76\u7684\u662f\u5982\u4f55\u5c06 n\u00a0\u4e2a\u7687\u540e\u653e\u7f6e\u5728 n\u00d7n \u7684\u68cb\u76d8\u4e0a\uff0c\u5e76\u4e14\u4f7f\u7687\u540e\u5f7c\u6b64\u4e4b\u95f4\u4e0d\u80fd\u76f8\u4e92\u653b\u51fb\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n \uff0c\u8fd4\u56de n \u7687\u540e\u95ee\u9898 \u4e0d\u540c\u7684\u89e3\u51b3\u65b9\u6848\u7684\u6570\u91cf\u3002

    \n\n

    \u00a0

    \n\n
    \n
    \n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1an = 4\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u5982\u4e0a\u56fe\u6240\u793a\uff0c4 \u7687\u540e\u95ee\u9898\u5b58\u5728\u4e24\u4e2a\u4e0d\u540c\u7684\u89e3\u6cd5\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 9
    • \n\t
    • \u7687\u540e\u5f7c\u6b64\u4e0d\u80fd\u76f8\u4e92\u653b\u51fb\uff0c\u4e5f\u5c31\u662f\u8bf4\uff1a\u4efb\u4f55\u4e24\u4e2a\u7687\u540e\u90fd\u4e0d\u80fd\u5904\u4e8e\u540c\u4e00\u6761\u6a2a\u884c\u3001\u7eb5\u884c\u6216\u659c\u7ebf\u4e0a\u3002
    • \n
    \n
    \n
    \n", "tags_en": ["Backtracking"], "tags_cn": ["\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int totalNQueens(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int totalNQueens(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def totalNQueens(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def totalNQueens(self, n: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint totalNQueens(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int TotalNQueens(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {number}\n */\nvar totalNQueens = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {Integer}\ndef total_n_queens(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func totalNQueens(_ n: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func totalNQueens(n int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def totalNQueens(n: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun totalNQueens(n: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn total_n_queens(n: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return Integer\n */\n function totalNQueens($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function totalNQueens(n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (total-n-queens n)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0052](https://leetcode-cn.com/problems/n-queens-ii)", "[N\u7687\u540e II](/solution/0000-0099/0052.N-Queens%20II/README.md)", "`\u56de\u6eaf\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[0052](https://leetcode.com/problems/n-queens-ii)", "[N-Queens II](/solution/0000-0099/0052.N-Queens%20II/README_EN.md)", "`Backtracking`", "Hard", ""]}, {"question_id": "0051", "frontend_question_id": "0051", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/n-queens", "url_en": "https://leetcode.com/problems/n-queens", "relative_path_cn": "/solution/0000-0099/0051.N-Queens/README.md", "relative_path_en": "/solution/0000-0099/0051.N-Queens/README_EN.md", "title_cn": "N \u7687\u540e", "title_en": "N-Queens", "question_title_slug": "n-queens", "content_en": "

    The n-queens puzzle is the problem of placing n queens on an n x n chessboard such that no two queens attack each other.

    \n\n

    Given an integer n, return all distinct solutions to the n-queens puzzle. You may return the answer in any order.

    \n\n

    Each solution contains a distinct board configuration of the n-queens' placement, where 'Q' and '.' both indicate a queen and an empty space, respectively.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: n = 4\nOutput: [[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]\nExplanation: There exist two distinct solutions to the 4-queens puzzle as shown above\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 1\nOutput: [["Q"]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 9
    • \n
    \n", "content_cn": "

    n\u00a0\u7687\u540e\u95ee\u9898 \u7814\u7a76\u7684\u662f\u5982\u4f55\u5c06 n\u00a0\u4e2a\u7687\u540e\u653e\u7f6e\u5728 n\u00d7n \u7684\u68cb\u76d8\u4e0a\uff0c\u5e76\u4e14\u4f7f\u7687\u540e\u5f7c\u6b64\u4e4b\u95f4\u4e0d\u80fd\u76f8\u4e92\u653b\u51fb\u3002

    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n \uff0c\u8fd4\u56de\u6240\u6709\u4e0d\u540c\u7684\u00a0n\u00a0\u7687\u540e\u95ee\u9898 \u7684\u89e3\u51b3\u65b9\u6848\u3002

    \n\n
    \n
    \n

    \u6bcf\u4e00\u79cd\u89e3\u6cd5\u5305\u542b\u4e00\u4e2a\u4e0d\u540c\u7684\u00a0n \u7687\u540e\u95ee\u9898 \u7684\u68cb\u5b50\u653e\u7f6e\u65b9\u6848\uff0c\u8be5\u65b9\u6848\u4e2d 'Q' \u548c '.' \u5206\u522b\u4ee3\u8868\u4e86\u7687\u540e\u548c\u7a7a\u4f4d\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1an = 4\n\u8f93\u51fa\uff1a[[\".Q..\",\"...Q\",\"Q...\",\"..Q.\"],[\"..Q.\",\"Q...\",\"...Q\",\".Q..\"]]\n\u89e3\u91ca\uff1a\u5982\u4e0a\u56fe\u6240\u793a\uff0c4 \u7687\u540e\u95ee\u9898\u5b58\u5728\u4e24\u4e2a\u4e0d\u540c\u7684\u89e3\u6cd5\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1a[[\"Q\"]]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 9
    • \n\t
    • \u7687\u540e\u5f7c\u6b64\u4e0d\u80fd\u76f8\u4e92\u653b\u51fb\uff0c\u4e5f\u5c31\u662f\u8bf4\uff1a\u4efb\u4f55\u4e24\u4e2a\u7687\u540e\u90fd\u4e0d\u80fd\u5904\u4e8e\u540c\u4e00\u6761\u6a2a\u884c\u3001\u7eb5\u884c\u6216\u659c\u7ebf\u4e0a\u3002
    • \n
    \n
    \n
    \n", "tags_en": ["Backtracking"], "tags_cn": ["\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> solveNQueens(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> solveNQueens(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def solveNQueens(self, n):\n \"\"\"\n :type n: int\n :rtype: List[List[str]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def solveNQueens(self, n: int) -> List[List[str]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nchar *** solveNQueens(int n, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> SolveNQueens(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {string[][]}\n */\nvar solveNQueens = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {String[][]}\ndef solve_n_queens(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func solveNQueens(_ n: Int) -> [[String]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func solveNQueens(n int) [][]string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def solveNQueens(n: Int): List[List[String]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun solveNQueens(n: Int): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn solve_n_queens(n: i32) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return String[][]\n */\n function solveNQueens($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function solveNQueens(n: number): string[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (solve-n-queens n)\n (-> exact-integer? (listof (listof string?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0051](https://leetcode-cn.com/problems/n-queens)", "[N \u7687\u540e](/solution/0000-0099/0051.N-Queens/README.md)", "`\u56de\u6eaf\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[0051](https://leetcode.com/problems/n-queens)", "[N-Queens](/solution/0000-0099/0051.N-Queens/README_EN.md)", "`Backtracking`", "Hard", ""]}, {"question_id": "0050", "frontend_question_id": "0050", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/powx-n", "url_en": "https://leetcode.com/problems/powx-n", "relative_path_cn": "/solution/0000-0099/0050.Pow%28x%2C%20n%29/README.md", "relative_path_en": "/solution/0000-0099/0050.Pow%28x%2C%20n%29/README_EN.md", "title_cn": "Pow(x, n)", "title_en": "Pow(x, n)", "question_title_slug": "powx-n", "content_en": "

    Implement pow(x, n), which calculates x raised to the power n (i.e., xn).

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: x = 2.00000, n = 10\nOutput: 1024.00000\n
    \n\n

    Example 2:

    \n\n
    \nInput: x = 2.10000, n = 3\nOutput: 9.26100\n
    \n\n

    Example 3:

    \n\n
    \nInput: x = 2.00000, n = -2\nOutput: 0.25000\nExplanation: 2-2 = 1/22 = 1/4 = 0.25\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • -100.0 < x < 100.0
    • \n\t
    • -231 <= n <= 231-1
    • \n\t
    • -104 <= xn <= 104
    • \n
    \n", "content_cn": "

    \u5b9e\u73b0\u00a0pow(x, n)\u00a0\uff0c\u5373\u8ba1\u7b97 x \u7684 n \u6b21\u5e42\u51fd\u6570\uff08\u5373\uff0cxn\uff09\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1ax = 2.00000, n = 10\n\u8f93\u51fa\uff1a1024.00000\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1ax = 2.10000, n = 3\n\u8f93\u51fa\uff1a9.26100\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1ax = 2.00000, n = -2\n\u8f93\u51fa\uff1a0.25000\n\u89e3\u91ca\uff1a2-2 = 1/22 = 1/4 = 0.25\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • -100.0 <\u00a0x\u00a0< 100.0
    • \n\t
    • -231\u00a0<= n <=\u00a0231-1
    • \n\t
    • -104 <= xn <= 104
    • \n
    \n", "tags_en": ["Math", "Binary Search"], "tags_cn": ["\u6570\u5b66", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n double myPow(double x, int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double myPow(double x, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def myPow(self, x, n):\n \"\"\"\n :type x: float\n :type n: int\n :rtype: float\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def myPow(self, x: float, n: int) -> float:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\ndouble myPow(double x, int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double MyPow(double x, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} x\n * @param {number} n\n * @return {number}\n */\nvar myPow = function(x, n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Float} x\n# @param {Integer} n\n# @return {Float}\ndef my_pow(x, n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func myPow(_ x: Double, _ n: Int) -> Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func myPow(x float64, n int) float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def myPow(x: Double, n: Int): Double = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun myPow(x: Double, n: Int): Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn my_pow(x: f64, n: i32) -> f64 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Float $x\n * @param Integer $n\n * @return Float\n */\n function myPow($x, $n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function myPow(x: number, n: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (my-pow x n)\n (-> flonum? exact-integer? flonum?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0050](https://leetcode-cn.com/problems/powx-n)", "[Pow(x, n)](/solution/0000-0099/0050.Pow%28x%2C%20n%29/README.md)", "`\u6570\u5b66`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0050](https://leetcode.com/problems/powx-n)", "[Pow(x, n)](/solution/0000-0099/0050.Pow%28x%2C%20n%29/README_EN.md)", "`Math`,`Binary Search`", "Medium", ""]}, {"question_id": "0049", "frontend_question_id": "0049", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/group-anagrams", "url_en": "https://leetcode.com/problems/group-anagrams", "relative_path_cn": "/solution/0000-0099/0049.Group%20Anagrams/README.md", "relative_path_en": "/solution/0000-0099/0049.Group%20Anagrams/README_EN.md", "title_cn": "\u5b57\u6bcd\u5f02\u4f4d\u8bcd\u5206\u7ec4", "title_en": "Group Anagrams", "question_title_slug": "group-anagrams", "content_en": "

    Given an array of strings strs, group the anagrams together. You can return the answer in any order.

    \n\n

    An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.

    \n\n

     

    \n

    Example 1:

    \n
    Input: strs = [\"eat\",\"tea\",\"tan\",\"ate\",\"nat\",\"bat\"]\nOutput: [[\"bat\"],[\"nat\",\"tan\"],[\"ate\",\"eat\",\"tea\"]]\n

    Example 2:

    \n
    Input: strs = [\"\"]\nOutput: [[\"\"]]\n

    Example 3:

    \n
    Input: strs = [\"a\"]\nOutput: [[\"a\"]]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= strs.length <= 104
    • \n\t
    • 0 <= strs[i].length <= 100
    • \n\t
    • strs[i] consists of lower-case English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4\uff0c\u5c06\u5b57\u6bcd\u5f02\u4f4d\u8bcd\u7ec4\u5408\u5728\u4e00\u8d77\u3002\u5b57\u6bcd\u5f02\u4f4d\u8bcd\u6307\u5b57\u6bcd\u76f8\u540c\uff0c\u4f46\u6392\u5217\u4e0d\u540c\u7684\u5b57\u7b26\u4e32\u3002

    \n\n

    \u793a\u4f8b:

    \n\n
    \u8f93\u5165: ["eat", "tea", "tan", "ate", "nat", "bat"]\n\u8f93\u51fa:\n[\n  ["ate","eat","tea"],\n  ["nat","tan"],\n  ["bat"]\n]
    \n\n

    \u8bf4\u660e\uff1a

    \n\n
      \n\t
    • \u6240\u6709\u8f93\u5165\u5747\u4e3a\u5c0f\u5199\u5b57\u6bcd\u3002
    • \n\t
    • \u4e0d\u8003\u8651\u7b54\u6848\u8f93\u51fa\u7684\u987a\u5e8f\u3002
    • \n
    \n", "tags_en": ["Hash Table", "String"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> groupAnagrams(vector& strs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> groupAnagrams(String[] strs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def groupAnagrams(self, strs):\n \"\"\"\n :type strs: List[str]\n :rtype: List[List[str]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def groupAnagrams(self, strs: List[str]) -> List[List[str]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nchar *** groupAnagrams(char ** strs, int strsSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> GroupAnagrams(string[] strs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} strs\n * @return {string[][]}\n */\nvar groupAnagrams = function(strs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} strs\n# @return {String[][]}\ndef group_anagrams(strs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func groupAnagrams(_ strs: [String]) -> [[String]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func groupAnagrams(strs []string) [][]string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def groupAnagrams(strs: Array[String]): List[List[String]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun groupAnagrams(strs: Array): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn group_anagrams(strs: Vec) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $strs\n * @return String[][]\n */\n function groupAnagrams($strs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function groupAnagrams(strs: string[]): string[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (group-anagrams strs)\n (-> (listof string?) (listof (listof string?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0049](https://leetcode-cn.com/problems/group-anagrams)", "[\u5b57\u6bcd\u5f02\u4f4d\u8bcd\u5206\u7ec4](/solution/0000-0099/0049.Group%20Anagrams/README.md)", "`\u54c8\u5e0c\u8868`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0049](https://leetcode.com/problems/group-anagrams)", "[Group Anagrams](/solution/0000-0099/0049.Group%20Anagrams/README_EN.md)", "`Hash Table`,`String`", "Medium", ""]}, {"question_id": "0048", "frontend_question_id": "0048", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/rotate-image", "url_en": "https://leetcode.com/problems/rotate-image", "relative_path_cn": "/solution/0000-0099/0048.Rotate%20Image/README.md", "relative_path_en": "/solution/0000-0099/0048.Rotate%20Image/README_EN.md", "title_cn": "\u65cb\u8f6c\u56fe\u50cf", "title_en": "Rotate Image", "question_title_slug": "rotate-image", "content_en": "

    You are given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise).

    \n\n

    You have to rotate the image in-place, which means you have to modify the input 2D matrix directly. DO NOT allocate another 2D matrix and do the rotation.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: matrix = [[1,2,3],[4,5,6],[7,8,9]]\nOutput: [[7,4,1],[8,5,2],[9,6,3]]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: matrix = [[5,1,9,11],[2,4,8,10],[13,3,6,7],[15,14,12,16]]\nOutput: [[15,13,2,5],[14,3,4,1],[12,6,8,9],[16,7,10,11]]\n
    \n\n

    Example 3:

    \n\n
    \nInput: matrix = [[1]]\nOutput: [[1]]\n
    \n\n

    Example 4:

    \n\n
    \nInput: matrix = [[1,2],[3,4]]\nOutput: [[3,1],[4,2]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • matrix.length == n
    • \n\t
    • matrix[i].length == n
    • \n\t
    • 1 <= n <= 20
    • \n\t
    • -1000 <= matrix[i][j] <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a n\u00a0\u00d7\u00a0n \u7684\u4e8c\u7ef4\u77e9\u9635\u00a0matrix \u8868\u793a\u4e00\u4e2a\u56fe\u50cf\u3002\u8bf7\u4f60\u5c06\u56fe\u50cf\u987a\u65f6\u9488\u65cb\u8f6c 90 \u5ea6\u3002

    \n\n

    \u4f60\u5fc5\u987b\u5728 \u539f\u5730 \u65cb\u8f6c\u56fe\u50cf\uff0c\u8fd9\u610f\u5473\u7740\u4f60\u9700\u8981\u76f4\u63a5\u4fee\u6539\u8f93\u5165\u7684\u4e8c\u7ef4\u77e9\u9635\u3002\u8bf7\u4e0d\u8981 \u4f7f\u7528\u53e6\u4e00\u4e2a\u77e9\u9635\u6765\u65cb\u8f6c\u56fe\u50cf\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1amatrix = [[1,2,3],[4,5,6],[7,8,9]]\n\u8f93\u51fa\uff1a[[7,4,1],[8,5,2],[9,6,3]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1amatrix = [[5,1,9,11],[2,4,8,10],[13,3,6,7],[15,14,12,16]]\n\u8f93\u51fa\uff1a[[15,13,2,5],[14,3,4,1],[12,6,8,9],[16,7,10,11]]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1amatrix = [[1]]\n\u8f93\u51fa\uff1a[[1]]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1amatrix = [[1,2],[3,4]]\n\u8f93\u51fa\uff1a[[3,1],[4,2]]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • matrix.length == n
    • \n\t
    • matrix[i].length == n
    • \n\t
    • 1 <= n <= 20
    • \n\t
    • -1000 <= matrix[i][j] <= 1000
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n void rotate(vector>& matrix) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public void rotate(int[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def rotate(self, matrix):\n \"\"\"\n :type matrix: List[List[int]]\n :rtype: None Do not return anything, modify matrix in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def rotate(self, matrix: List[List[int]]) -> None:\n \"\"\"\n Do not return anything, modify matrix in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nvoid rotate(int** matrix, int matrixSize, int* matrixColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public void Rotate(int[][] matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[][]} matrix\n * @return {void} Do not return anything, modify matrix in-place instead.\n */\nvar rotate = function(matrix) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[][]} matrix\n# @return {Void} Do not return anything, modify matrix in-place instead.\ndef rotate(matrix)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func rotate(_ matrix: inout [[Int]]) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func rotate(matrix [][]int) {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def rotate(matrix: Array[Array[Int]]): Unit = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun rotate(matrix: Array): Unit {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn rotate(matrix: &mut Vec>) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[][] $matrix\n * @return NULL\n */\n function rotate(&$matrix) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n Do not return anything, modify matrix in-place instead.\n */\nfunction rotate(matrix: number[][]): void {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0048](https://leetcode-cn.com/problems/rotate-image)", "[\u65cb\u8f6c\u56fe\u50cf](/solution/0000-0099/0048.Rotate%20Image/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0048](https://leetcode.com/problems/rotate-image)", "[Rotate Image](/solution/0000-0099/0048.Rotate%20Image/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0047", "frontend_question_id": "0047", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/permutations-ii", "url_en": "https://leetcode.com/problems/permutations-ii", "relative_path_cn": "/solution/0000-0099/0047.Permutations%20II/README.md", "relative_path_en": "/solution/0000-0099/0047.Permutations%20II/README_EN.md", "title_cn": "\u5168\u6392\u5217 II", "title_en": "Permutations II", "question_title_slug": "permutations-ii", "content_en": "

    Given a collection of numbers, nums, that might contain duplicates, return all possible unique permutations in any order.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,1,2]\nOutput:\n[[1,1,2],\n [1,2,1],\n [2,1,1]]\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [1,2,3]\nOutput: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 8
    • \n\t
    • -10 <= nums[i] <= 10
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u53ef\u5305\u542b\u91cd\u590d\u6570\u5b57\u7684\u5e8f\u5217 nums \uff0c\u6309\u4efb\u610f\u987a\u5e8f \u8fd4\u56de\u6240\u6709\u4e0d\u91cd\u590d\u7684\u5168\u6392\u5217\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,1,2]\n\u8f93\u51fa\uff1a\n[[1,1,2],\n [1,2,1],\n [2,1,1]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,3]\n\u8f93\u51fa\uff1a[[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 8
    • \n\t
    • -10 <= nums[i] <= 10
    • \n
    \n", "tags_en": ["Backtracking"], "tags_cn": ["\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> permuteUnique(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> permuteUnique(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def permuteUnique(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def permuteUnique(self, nums: List[int]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** permuteUnique(int* nums, int numsSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> PermuteUnique(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number[][]}\n */\nvar permuteUnique = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer[][]}\ndef permute_unique(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func permuteUnique(_ nums: [Int]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func permuteUnique(nums []int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def permuteUnique(nums: Array[Int]): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun permuteUnique(nums: IntArray): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn permute_unique(nums: Vec) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer[][]\n */\n function permuteUnique($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function permuteUnique(nums: number[]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (permute-unique nums)\n (-> (listof exact-integer?) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0047](https://leetcode-cn.com/problems/permutations-ii)", "[\u5168\u6392\u5217 II](/solution/0000-0099/0047.Permutations%20II/README.md)", "`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0047](https://leetcode.com/problems/permutations-ii)", "[Permutations II](/solution/0000-0099/0047.Permutations%20II/README_EN.md)", "`Backtracking`", "Medium", ""]}, {"question_id": "0046", "frontend_question_id": "0046", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/permutations", "url_en": "https://leetcode.com/problems/permutations", "relative_path_cn": "/solution/0000-0099/0046.Permutations/README.md", "relative_path_en": "/solution/0000-0099/0046.Permutations/README_EN.md", "title_cn": "\u5168\u6392\u5217", "title_en": "Permutations", "question_title_slug": "permutations", "content_en": "

    Given an array nums of distinct integers, return all the possible permutations. You can return the answer in any order.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [1,2,3]\nOutput: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]\n

    Example 2:

    \n
    Input: nums = [0,1]\nOutput: [[0,1],[1,0]]\n

    Example 3:

    \n
    Input: nums = [1]\nOutput: [[1]]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 6
    • \n\t
    • -10 <= nums[i] <= 10
    • \n\t
    • All the integers of nums are unique.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4e0d\u542b\u91cd\u590d\u6570\u5b57\u7684\u6570\u7ec4 nums \uff0c\u8fd4\u56de\u5176 \u6240\u6709\u53ef\u80fd\u7684\u5168\u6392\u5217 \u3002\u4f60\u53ef\u4ee5 \u6309\u4efb\u610f\u987a\u5e8f \u8fd4\u56de\u7b54\u6848\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,3]\n\u8f93\u51fa\uff1a[[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [0,1]\n\u8f93\u51fa\uff1a[[0,1],[1,0]]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1]\n\u8f93\u51fa\uff1a[[1]]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 6
    • \n\t
    • -10 <= nums[i] <= 10
    • \n\t
    • nums \u4e2d\u7684\u6240\u6709\u6574\u6570 \u4e92\u4e0d\u76f8\u540c
    • \n
    \n", "tags_en": ["Backtracking"], "tags_cn": ["\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> permute(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> permute(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def permute(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def permute(self, nums: List[int]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** permute(int* nums, int numsSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> Permute(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number[][]}\n */\nvar permute = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer[][]}\ndef permute(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func permute(_ nums: [Int]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func permute(nums []int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def permute(nums: Array[Int]): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun permute(nums: IntArray): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn permute(nums: Vec) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer[][]\n */\n function permute($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function permute(nums: number[]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (permute nums)\n (-> (listof exact-integer?) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0046](https://leetcode-cn.com/problems/permutations)", "[\u5168\u6392\u5217](/solution/0000-0099/0046.Permutations/README.md)", "`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0046](https://leetcode.com/problems/permutations)", "[Permutations](/solution/0000-0099/0046.Permutations/README_EN.md)", "`Backtracking`", "Medium", ""]}, {"question_id": "0045", "frontend_question_id": "0045", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/jump-game-ii", "url_en": "https://leetcode.com/problems/jump-game-ii", "relative_path_cn": "/solution/0000-0099/0045.Jump%20Game%20II/README.md", "relative_path_en": "/solution/0000-0099/0045.Jump%20Game%20II/README_EN.md", "title_cn": "\u8df3\u8dc3\u6e38\u620f II", "title_en": "Jump Game II", "question_title_slug": "jump-game-ii", "content_en": "

    Given an array of non-negative integers nums, you are initially positioned at the first index of the array.

    \n\n

    Each element in the array represents your maximum jump length at that position.

    \n\n

    Your goal is to reach the last index in the minimum number of jumps.

    \n\n

    You can assume that you can always reach the last index.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [2,3,1,1,4]\nOutput: 2\nExplanation: The minimum number of jumps to reach the last index is 2. Jump 1 step from index 0 to 1, then 3 steps to the last index.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [2,3,0,1,4]\nOutput: 2\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 104
    • \n\t
    • 0 <= nums[i] <= 1000
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\u6570\u7ec4\uff0c\u4f60\u6700\u521d\u4f4d\u4e8e\u6570\u7ec4\u7684\u7b2c\u4e00\u4e2a\u4f4d\u7f6e\u3002

    \n\n

    \u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u4ee3\u8868\u4f60\u5728\u8be5\u4f4d\u7f6e\u53ef\u4ee5\u8df3\u8dc3\u7684\u6700\u5927\u957f\u5ea6\u3002

    \n\n

    \u4f60\u7684\u76ee\u6807\u662f\u4f7f\u7528\u6700\u5c11\u7684\u8df3\u8dc3\u6b21\u6570\u5230\u8fbe\u6570\u7ec4\u7684\u6700\u540e\u4e00\u4e2a\u4f4d\u7f6e\u3002

    \n\n

    \u5047\u8bbe\u4f60\u603b\u662f\u53ef\u4ee5\u5230\u8fbe\u6570\u7ec4\u7684\u6700\u540e\u4e00\u4e2a\u4f4d\u7f6e\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \n\u8f93\u5165: [2,3,1,1,4]\n\u8f93\u51fa: 2\n\u89e3\u91ca: \u8df3\u5230\u6700\u540e\u4e00\u4e2a\u4f4d\u7f6e\u7684\u6700\u5c0f\u8df3\u8dc3\u6570\u662f 2\u3002\n\u00a0    \u4ece\u4e0b\u6807\u4e3a 0 \u8df3\u5230\u4e0b\u6807\u4e3a 1 \u7684\u4f4d\u7f6e\uff0c\u8df3\u00a01\u00a0\u6b65\uff0c\u7136\u540e\u8df3\u00a03\u00a0\u6b65\u5230\u8fbe\u6570\u7ec4\u7684\u6700\u540e\u4e00\u4e2a\u4f4d\u7f6e\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: [2,3,0,1,4]\n\u8f93\u51fa: 2\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a:

    \n\n
      \n\t
    • 1 <= nums.length <= 1000
    • \n\t
    • 0 <= nums[i] <= 105
    • \n
    \n", "tags_en": ["Greedy", "Array"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int jump(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int jump(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def jump(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def jump(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint jump(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int Jump(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar jump = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef jump(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func jump(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func jump(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def jump(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun jump(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn jump(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function jump($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function jump(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (jump nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0045](https://leetcode-cn.com/problems/jump-game-ii)", "[\u8df3\u8dc3\u6e38\u620f II](/solution/0000-0099/0045.Jump%20Game%20II/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0045](https://leetcode.com/problems/jump-game-ii)", "[Jump Game II](/solution/0000-0099/0045.Jump%20Game%20II/README_EN.md)", "`Greedy`,`Array`", "Medium", ""]}, {"question_id": "0044", "frontend_question_id": "0044", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/wildcard-matching", "url_en": "https://leetcode.com/problems/wildcard-matching", "relative_path_cn": "/solution/0000-0099/0044.Wildcard%20Matching/README.md", "relative_path_en": "/solution/0000-0099/0044.Wildcard%20Matching/README_EN.md", "title_cn": "\u901a\u914d\u7b26\u5339\u914d", "title_en": "Wildcard Matching", "question_title_slug": "wildcard-matching", "content_en": "

    Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for '?' and '*' where:

    \n\n
      \n\t
    • '?' Matches any single character.
    • \n\t
    • '*' Matches any sequence of characters (including the empty sequence).
    • \n
    \n\n

    The matching should cover the entire input string (not partial).

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "aa", p = "a"\nOutput: false\nExplanation: "a" does not match the entire string "aa".\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "aa", p = "*"\nOutput: true\nExplanation: '*' matches any sequence.\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "cb", p = "?a"\nOutput: false\nExplanation: '?' matches 'c', but the second letter is 'a', which does not match 'b'.\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "adceb", p = "*a*b"\nOutput: true\nExplanation: The first '*' matches the empty sequence, while the second '*' matches the substring "dce".\n
    \n\n

    Example 5:

    \n\n
    \nInput: s = "acdcb", p = "a*c?b"\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= s.length, p.length <= 2000
    • \n\t
    • s contains only lowercase English letters.
    • \n\t
    • p contains only lowercase English letters, '?' or '*'.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32 (s) \u548c\u4e00\u4e2a\u5b57\u7b26\u6a21\u5f0f (p) \uff0c\u5b9e\u73b0\u4e00\u4e2a\u652f\u6301 '?' \u548c '*' \u7684\u901a\u914d\u7b26\u5339\u914d\u3002

    \n\n
    '?' \u53ef\u4ee5\u5339\u914d\u4efb\u4f55\u5355\u4e2a\u5b57\u7b26\u3002\n'*' \u53ef\u4ee5\u5339\u914d\u4efb\u610f\u5b57\u7b26\u4e32\uff08\u5305\u62ec\u7a7a\u5b57\u7b26\u4e32\uff09\u3002\n
    \n\n

    \u4e24\u4e2a\u5b57\u7b26\u4e32\u5b8c\u5168\u5339\u914d\u624d\u7b97\u5339\u914d\u6210\u529f\u3002

    \n\n

    \u8bf4\u660e:

    \n\n
      \n\t
    • s \u53ef\u80fd\u4e3a\u7a7a\uff0c\u4e14\u53ea\u5305\u542b\u4ece a-z \u7684\u5c0f\u5199\u5b57\u6bcd\u3002
    • \n\t
    • p \u53ef\u80fd\u4e3a\u7a7a\uff0c\u4e14\u53ea\u5305\u542b\u4ece a-z \u7684\u5c0f\u5199\u5b57\u6bcd\uff0c\u4ee5\u53ca\u5b57\u7b26 ? \u548c *\u3002
    • \n
    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165:\ns = "aa"\np = "a"\n\u8f93\u51fa: false\n\u89e3\u91ca: "a" \u65e0\u6cd5\u5339\u914d "aa" \u6574\u4e2a\u5b57\u7b26\u4e32\u3002
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165:\ns = "aa"\np = "*"\n\u8f93\u51fa: true\n\u89e3\u91ca: '*' \u53ef\u4ee5\u5339\u914d\u4efb\u610f\u5b57\u7b26\u4e32\u3002\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u8f93\u5165:\ns = "cb"\np = "?a"\n\u8f93\u51fa: false\n\u89e3\u91ca: '?' \u53ef\u4ee5\u5339\u914d 'c', \u4f46\u7b2c\u4e8c\u4e2a 'a' \u65e0\u6cd5\u5339\u914d 'b'\u3002\n
    \n\n

    \u793a\u4f8b 4:

    \n\n
    \u8f93\u5165:\ns = "adceb"\np = "*a*b"\n\u8f93\u51fa: true\n\u89e3\u91ca: \u7b2c\u4e00\u4e2a '*' \u53ef\u4ee5\u5339\u914d\u7a7a\u5b57\u7b26\u4e32, \u7b2c\u4e8c\u4e2a '*' \u53ef\u4ee5\u5339\u914d\u5b57\u7b26\u4e32 "dce".\n
    \n\n

    \u793a\u4f8b 5:

    \n\n
    \u8f93\u5165:\ns = "acdcb"\np = "a*c?b"\n\u8f93\u51fa: false
    \n", "tags_en": ["Greedy", "String", "Dynamic Programming", "Backtracking"], "tags_cn": ["\u8d2a\u5fc3\u7b97\u6cd5", "\u5b57\u7b26\u4e32", "\u52a8\u6001\u89c4\u5212", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isMatch(string s, string p) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isMatch(String s, String p) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isMatch(self, s, p):\n \"\"\"\n :type s: str\n :type p: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isMatch(self, s: str, p: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isMatch(char * s, char * p){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsMatch(string s, string p) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string} p\n * @return {boolean}\n */\nvar isMatch = function(s, p) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String} p\n# @return {Boolean}\ndef is_match(s, p)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isMatch(_ s: String, _ p: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isMatch(s string, p string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isMatch(s: String, p: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isMatch(s: String, p: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_match(s: String, p: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String $p\n * @return Boolean\n */\n function isMatch($s, $p) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isMatch(s: string, p: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-match s p)\n (-> string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0044](https://leetcode-cn.com/problems/wildcard-matching)", "[\u901a\u914d\u7b26\u5339\u914d](/solution/0000-0099/0044.Wildcard%20Matching/README.md)", "`\u8d2a\u5fc3\u7b97\u6cd5`,`\u5b57\u7b26\u4e32`,`\u52a8\u6001\u89c4\u5212`,`\u56de\u6eaf\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[0044](https://leetcode.com/problems/wildcard-matching)", "[Wildcard Matching](/solution/0000-0099/0044.Wildcard%20Matching/README_EN.md)", "`Greedy`,`String`,`Dynamic Programming`,`Backtracking`", "Hard", ""]}, {"question_id": "0043", "frontend_question_id": "0043", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/multiply-strings", "url_en": "https://leetcode.com/problems/multiply-strings", "relative_path_cn": "/solution/0000-0099/0043.Multiply%20Strings/README.md", "relative_path_en": "/solution/0000-0099/0043.Multiply%20Strings/README_EN.md", "title_cn": "\u5b57\u7b26\u4e32\u76f8\u4e58", "title_en": "Multiply Strings", "question_title_slug": "multiply-strings", "content_en": "

    Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2, also represented as a string.

    \n\n

    Note: You must not use any built-in BigInteger library or convert the inputs to integer directly.

    \n\n

     

    \n

    Example 1:

    \n
    Input: num1 = \"2\", num2 = \"3\"\nOutput: \"6\"\n

    Example 2:

    \n
    Input: num1 = \"123\", num2 = \"456\"\nOutput: \"56088\"\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= num1.length, num2.length <= 200
    • \n\t
    • num1 and num2 consist of digits only.
    • \n\t
    • Both num1 and num2 do not contain any leading zero, except the number 0 itself.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u4ee5\u5b57\u7b26\u4e32\u5f62\u5f0f\u8868\u793a\u7684\u975e\u8d1f\u6574\u6570 num1 \u548c num2\uff0c\u8fd4\u56de num1 \u548c num2 \u7684\u4e58\u79ef\uff0c\u5b83\u4eec\u7684\u4e58\u79ef\u4e5f\u8868\u793a\u4e3a\u5b57\u7b26\u4e32\u5f62\u5f0f\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: num1 = "2", num2 = "3"\n\u8f93\u51fa: "6"
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: num1 = "123", num2 = "456"\n\u8f93\u51fa: "56088"
    \n\n

    \u8bf4\u660e\uff1a

    \n\n
      \n\t
    1. num1 \u548c num2 \u7684\u957f\u5ea6\u5c0f\u4e8e110\u3002
    2. \n\t
    3. num1 \u548c num2 \u53ea\u5305\u542b\u6570\u5b57 0-9\u3002
    4. \n\t
    5. num1 \u548c num2 \u5747\u4e0d\u4ee5\u96f6\u5f00\u5934\uff0c\u9664\u975e\u662f\u6570\u5b57 0 \u672c\u8eab\u3002
    6. \n\t
    7. \u4e0d\u80fd\u4f7f\u7528\u4efb\u4f55\u6807\u51c6\u5e93\u7684\u5927\u6570\u7c7b\u578b\uff08\u6bd4\u5982 BigInteger\uff09\u6216\u76f4\u63a5\u5c06\u8f93\u5165\u8f6c\u6362\u4e3a\u6574\u6570\u6765\u5904\u7406\u3002
    8. \n
    \n", "tags_en": ["Math", "String"], "tags_cn": ["\u6570\u5b66", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string multiply(string num1, string num2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String multiply(String num1, String num2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def multiply(self, num1, num2):\n \"\"\"\n :type num1: str\n :type num2: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def multiply(self, num1: str, num2: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * multiply(char * num1, char * num2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string Multiply(string num1, string num2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} num1\n * @param {string} num2\n * @return {string}\n */\nvar multiply = function(num1, num2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} num1\n# @param {String} num2\n# @return {String}\ndef multiply(num1, num2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func multiply(_ num1: String, _ num2: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func multiply(num1 string, num2 string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def multiply(num1: String, num2: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun multiply(num1: String, num2: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn multiply(num1: String, num2: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $num1\n * @param String $num2\n * @return String\n */\n function multiply($num1, $num2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function multiply(num1: string, num2: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (multiply num1 num2)\n (-> string? string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0043](https://leetcode-cn.com/problems/multiply-strings)", "[\u5b57\u7b26\u4e32\u76f8\u4e58](/solution/0000-0099/0043.Multiply%20Strings/README.md)", "`\u6570\u5b66`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0043](https://leetcode.com/problems/multiply-strings)", "[Multiply Strings](/solution/0000-0099/0043.Multiply%20Strings/README_EN.md)", "`Math`,`String`", "Medium", ""]}, {"question_id": "0042", "frontend_question_id": "0042", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/trapping-rain-water", "url_en": "https://leetcode.com/problems/trapping-rain-water", "relative_path_cn": "/solution/0000-0099/0042.Trapping%20Rain%20Water/README.md", "relative_path_en": "/solution/0000-0099/0042.Trapping%20Rain%20Water/README_EN.md", "title_cn": "\u63a5\u96e8\u6c34", "title_en": "Trapping Rain Water", "question_title_slug": "trapping-rain-water", "content_en": "

    Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: height = [0,1,0,2,1,0,1,3,2,1,2,1]\nOutput: 6\nExplanation: The above elevation map (black section) is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being trapped.\n
    \n\n

    Example 2:

    \n\n
    \nInput: height = [4,2,0,3,2,5]\nOutput: 9\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == height.length
    • \n\t
    • 0 <= n <= 3 * 104
    • \n\t
    • 0 <= height[i] <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u00a0n \u4e2a\u975e\u8d1f\u6574\u6570\u8868\u793a\u6bcf\u4e2a\u5bbd\u5ea6\u4e3a 1 \u7684\u67f1\u5b50\u7684\u9ad8\u5ea6\u56fe\uff0c\u8ba1\u7b97\u6309\u6b64\u6392\u5217\u7684\u67f1\u5b50\uff0c\u4e0b\u96e8\u4e4b\u540e\u80fd\u63a5\u591a\u5c11\u96e8\u6c34\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \n\n
    \n\u8f93\u5165\uff1aheight = [0,1,0,2,1,0,1,3,2,1,2,1]\n\u8f93\u51fa\uff1a6\n\u89e3\u91ca\uff1a\u4e0a\u9762\u662f\u7531\u6570\u7ec4 [0,1,0,2,1,0,1,3,2,1,2,1] \u8868\u793a\u7684\u9ad8\u5ea6\u56fe\uff0c\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u53ef\u4ee5\u63a5 6 \u4e2a\u5355\u4f4d\u7684\u96e8\u6c34\uff08\u84dd\u8272\u90e8\u5206\u8868\u793a\u96e8\u6c34\uff09\u3002 \n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aheight = [4,2,0,3,2,5]\n\u8f93\u51fa\uff1a9\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n == height.length
    • \n\t
    • 0 <= n <= 3 * 104
    • \n\t
    • 0 <= height[i] <= 105
    • \n
    \n", "tags_en": ["Stack", "Array", "Two Pointers", "Dynamic Programming"], "tags_cn": ["\u6808", "\u6570\u7ec4", "\u53cc\u6307\u9488", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int trap(vector& height) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int trap(int[] height) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def trap(self, height):\n \"\"\"\n :type height: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def trap(self, height: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint trap(int* height, int heightSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int Trap(int[] height) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} height\n * @return {number}\n */\nvar trap = function(height) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} height\n# @return {Integer}\ndef trap(height)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func trap(_ height: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func trap(height []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def trap(height: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun trap(height: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn trap(height: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $height\n * @return Integer\n */\n function trap($height) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function trap(height: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (trap height)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0042](https://leetcode-cn.com/problems/trapping-rain-water)", "[\u63a5\u96e8\u6c34](/solution/0000-0099/0042.Trapping%20Rain%20Water/README.md)", "`\u6808`,`\u6570\u7ec4`,`\u53cc\u6307\u9488`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0042](https://leetcode.com/problems/trapping-rain-water)", "[Trapping Rain Water](/solution/0000-0099/0042.Trapping%20Rain%20Water/README_EN.md)", "`Stack`,`Array`,`Two Pointers`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0041", "frontend_question_id": "0041", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/first-missing-positive", "url_en": "https://leetcode.com/problems/first-missing-positive", "relative_path_cn": "/solution/0000-0099/0041.First%20Missing%20Positive/README.md", "relative_path_en": "/solution/0000-0099/0041.First%20Missing%20Positive/README_EN.md", "title_cn": "\u7f3a\u5931\u7684\u7b2c\u4e00\u4e2a\u6b63\u6570", "title_en": "First Missing Positive", "question_title_slug": "first-missing-positive", "content_en": "

    Given an unsorted integer array nums, find the smallest missing positive integer.

    \n\n

    You must implement an algorithm that runs in O(n) time and uses constant extra space.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [1,2,0]\nOutput: 3\n

    Example 2:

    \n
    Input: nums = [3,4,-1,1]\nOutput: 2\n

    Example 3:

    \n
    Input: nums = [7,8,9,11,12]\nOutput: 1\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 5 * 105
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u672a\u6392\u5e8f\u7684\u6574\u6570\u6570\u7ec4 nums \uff0c\u8bf7\u4f60\u627e\u51fa\u5176\u4e2d\u6ca1\u6709\u51fa\u73b0\u7684\u6700\u5c0f\u7684\u6b63\u6574\u6570\u3002

    \n\u8bf7\u4f60\u5b9e\u73b0\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n) \u5e76\u4e14\u53ea\u4f7f\u7528\u5e38\u6570\u7ea7\u522b\u989d\u5916\u7a7a\u95f4\u7684\u89e3\u51b3\u65b9\u6848\u3002\n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,0]\n\u8f93\u51fa\uff1a3\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [3,4,-1,1]\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [7,8,9,11,12]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 5 * 105
    • \n\t
    • -231 <= nums[i] <= 231 - 1
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int firstMissingPositive(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int firstMissingPositive(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def firstMissingPositive(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def firstMissingPositive(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint firstMissingPositive(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int FirstMissingPositive(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar firstMissingPositive = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef first_missing_positive(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func firstMissingPositive(_ nums: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func firstMissingPositive(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def firstMissingPositive(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun firstMissingPositive(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn first_missing_positive(nums: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function firstMissingPositive($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function firstMissingPositive(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (first-missing-positive nums)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0041](https://leetcode-cn.com/problems/first-missing-positive)", "[\u7f3a\u5931\u7684\u7b2c\u4e00\u4e2a\u6b63\u6570](/solution/0000-0099/0041.First%20Missing%20Positive/README.md)", "`\u6570\u7ec4`", "\u56f0\u96be", ""], "md_table_row_en": ["[0041](https://leetcode.com/problems/first-missing-positive)", "[First Missing Positive](/solution/0000-0099/0041.First%20Missing%20Positive/README_EN.md)", "`Array`", "Hard", ""]}, {"question_id": "0040", "frontend_question_id": "0040", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/combination-sum-ii", "url_en": "https://leetcode.com/problems/combination-sum-ii", "relative_path_cn": "/solution/0000-0099/0040.Combination%20Sum%20II/README.md", "relative_path_en": "/solution/0000-0099/0040.Combination%20Sum%20II/README_EN.md", "title_cn": "\u7ec4\u5408\u603b\u548c II", "title_en": "Combination Sum II", "question_title_slug": "combination-sum-ii", "content_en": "

    Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numbers sum to target.

    \n\n

    Each number in candidates may only be used once in the combination.

    \n\n

    Note: The solution set must not contain duplicate combinations.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: candidates = [10,1,2,7,6,1,5], target = 8\nOutput: \n[\n[1,1,6],\n[1,2,5],\n[1,7],\n[2,6]\n]\n
    \n\n

    Example 2:

    \n\n
    \nInput: candidates = [2,5,2,1,2], target = 5\nOutput: \n[\n[1,2,2],\n[5]\n]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= candidates.length <= 100
    • \n\t
    • 1 <= candidates[i] <= 50
    • \n\t
    • 1 <= target <= 30
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6570\u7ec4 candidates \u548c\u4e00\u4e2a\u76ee\u6807\u6570 target \uff0c\u627e\u51fa candidates \u4e2d\u6240\u6709\u53ef\u4ee5\u4f7f\u6570\u5b57\u548c\u4e3a target \u7684\u7ec4\u5408\u3002

    \n\n

    candidates \u4e2d\u7684\u6bcf\u4e2a\u6570\u5b57\u5728\u6bcf\u4e2a\u7ec4\u5408\u4e2d\u53ea\u80fd\u4f7f\u7528\u4e00\u6b21\u3002

    \n\n

    \u8bf4\u660e\uff1a

    \n\n
      \n\t
    • \u6240\u6709\u6570\u5b57\uff08\u5305\u62ec\u76ee\u6807\u6570\uff09\u90fd\u662f\u6b63\u6574\u6570\u3002
    • \n\t
    • \u89e3\u96c6\u4e0d\u80fd\u5305\u542b\u91cd\u590d\u7684\u7ec4\u5408\u3002 
    • \n
    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: candidates = [10,1,2,7,6,1,5], target = 8,\n\u6240\u6c42\u89e3\u96c6\u4e3a:\n[\n  [1, 7],\n  [1, 2, 5],\n  [2, 6],\n  [1, 1, 6]\n]\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: candidates = [2,5,2,1,2], target = 5,\n\u6240\u6c42\u89e3\u96c6\u4e3a:\n[\n  [1,2,2],\n  [5]\n]
    \n", "tags_en": ["Array", "Backtracking"], "tags_cn": ["\u6570\u7ec4", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> combinationSum2(vector& candidates, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> combinationSum2(int[] candidates, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def combinationSum2(self, candidates, target):\n \"\"\"\n :type candidates: List[int]\n :type target: int\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def combinationSum2(self, candidates: List[int], target: int) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** combinationSum2(int* candidates, int candidatesSize, int target, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> CombinationSum2(int[] candidates, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} candidates\n * @param {number} target\n * @return {number[][]}\n */\nvar combinationSum2 = function(candidates, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} candidates\n# @param {Integer} target\n# @return {Integer[][]}\ndef combination_sum2(candidates, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func combinationSum2(_ candidates: [Int], _ target: Int) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func combinationSum2(candidates []int, target int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def combinationSum2(candidates: Array[Int], target: Int): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun combinationSum2(candidates: IntArray, target: Int): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn combination_sum2(candidates: Vec, target: i32) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $candidates\n * @param Integer $target\n * @return Integer[][]\n */\n function combinationSum2($candidates, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function combinationSum2(candidates: number[], target: number): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (combination-sum2 candidates target)\n (-> (listof exact-integer?) exact-integer? (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0040](https://leetcode-cn.com/problems/combination-sum-ii)", "[\u7ec4\u5408\u603b\u548c II](/solution/0000-0099/0040.Combination%20Sum%20II/README.md)", "`\u6570\u7ec4`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0040](https://leetcode.com/problems/combination-sum-ii)", "[Combination Sum II](/solution/0000-0099/0040.Combination%20Sum%20II/README_EN.md)", "`Array`,`Backtracking`", "Medium", ""]}, {"question_id": "0039", "frontend_question_id": "0039", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/combination-sum", "url_en": "https://leetcode.com/problems/combination-sum", "relative_path_cn": "/solution/0000-0099/0039.Combination%20Sum/README.md", "relative_path_en": "/solution/0000-0099/0039.Combination%20Sum/README_EN.md", "title_cn": "\u7ec4\u5408\u603b\u548c", "title_en": "Combination Sum", "question_title_slug": "combination-sum", "content_en": "

    Given an array of distinct integers candidates and a target integer target, return a list of all unique combinations of candidates where the chosen numbers sum to target. You may return the combinations in any order.

    \n\n

    The same number may be chosen from candidates an unlimited number of times. Two combinations are unique if the frequency of at least one of the chosen numbers is different.

    \n\n

    It is guaranteed that the number of unique combinations that sum up to target is less than 150 combinations for the given input.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: candidates = [2,3,6,7], target = 7\nOutput: [[2,2,3],[7]]\nExplanation:\n2 and 3 are candidates, and 2 + 2 + 3 = 7. Note that 2 can be used multiple times.\n7 is a candidate, and 7 = 7.\nThese are the only two combinations.\n
    \n\n

    Example 2:

    \n\n
    \nInput: candidates = [2,3,5], target = 8\nOutput: [[2,2,2,2],[2,3,3],[3,5]]\n
    \n\n

    Example 3:

    \n\n
    \nInput: candidates = [2], target = 1\nOutput: []\n
    \n\n

    Example 4:

    \n\n
    \nInput: candidates = [1], target = 1\nOutput: [[1]]\n
    \n\n

    Example 5:

    \n\n
    \nInput: candidates = [1], target = 2\nOutput: [[1,1]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= candidates.length <= 30
    • \n\t
    • 1 <= candidates[i] <= 200
    • \n\t
    • All elements of candidates are distinct.
    • \n\t
    • 1 <= target <= 500
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u65e0\u91cd\u590d\u5143\u7d20\u7684\u6570\u7ec4 candidates \u548c\u4e00\u4e2a\u76ee\u6807\u6570 target \uff0c\u627e\u51fa candidates \u4e2d\u6240\u6709\u53ef\u4ee5\u4f7f\u6570\u5b57\u548c\u4e3a target \u7684\u7ec4\u5408\u3002

    \n\n

    candidates \u4e2d\u7684\u6570\u5b57\u53ef\u4ee5\u65e0\u9650\u5236\u91cd\u590d\u88ab\u9009\u53d6\u3002

    \n\n

    \u8bf4\u660e\uff1a

    \n\n
      \n\t
    • \u6240\u6709\u6570\u5b57\uff08\u5305\u62ec target\uff09\u90fd\u662f\u6b63\u6574\u6570\u3002
    • \n\t
    • \u89e3\u96c6\u4e0d\u80fd\u5305\u542b\u91cd\u590d\u7684\u7ec4\u5408\u3002 
    • \n
    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1acandidates = [2,3,6,7], target = 7,\n\u6240\u6c42\u89e3\u96c6\u4e3a\uff1a\n[\n  [7],\n  [2,2,3]\n]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1acandidates = [2,3,5], target = 8,\n\u6240\u6c42\u89e3\u96c6\u4e3a\uff1a\n[\n  [2,2,2,2],\n  [2,3,3],\n  [3,5]\n]
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= candidates.length <= 30
    • \n\t
    • 1 <= candidates[i] <= 200
    • \n\t
    • candidate \u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u90fd\u662f\u72ec\u4e00\u65e0\u4e8c\u7684\u3002
    • \n\t
    • 1 <= target <= 500
    • \n
    \n", "tags_en": ["Array", "Backtracking"], "tags_cn": ["\u6570\u7ec4", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> combinationSum(vector& candidates, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> combinationSum(int[] candidates, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def combinationSum(self, candidates, target):\n \"\"\"\n :type candidates: List[int]\n :type target: int\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** combinationSum(int* candidates, int candidatesSize, int target, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> CombinationSum(int[] candidates, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} candidates\n * @param {number} target\n * @return {number[][]}\n */\nvar combinationSum = function(candidates, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} candidates\n# @param {Integer} target\n# @return {Integer[][]}\ndef combination_sum(candidates, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func combinationSum(_ candidates: [Int], _ target: Int) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func combinationSum(candidates []int, target int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def combinationSum(candidates: Array[Int], target: Int): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun combinationSum(candidates: IntArray, target: Int): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn combination_sum(candidates: Vec, target: i32) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $candidates\n * @param Integer $target\n * @return Integer[][]\n */\n function combinationSum($candidates, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function combinationSum(candidates: number[], target: number): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (combination-sum candidates target)\n (-> (listof exact-integer?) exact-integer? (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0039](https://leetcode-cn.com/problems/combination-sum)", "[\u7ec4\u5408\u603b\u548c](/solution/0000-0099/0039.Combination%20Sum/README.md)", "`\u6570\u7ec4`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0039](https://leetcode.com/problems/combination-sum)", "[Combination Sum](/solution/0000-0099/0039.Combination%20Sum/README_EN.md)", "`Array`,`Backtracking`", "Medium", ""]}, {"question_id": "0038", "frontend_question_id": "0038", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/count-and-say", "url_en": "https://leetcode.com/problems/count-and-say", "relative_path_cn": "/solution/0000-0099/0038.Count%20and%20Say/README.md", "relative_path_en": "/solution/0000-0099/0038.Count%20and%20Say/README_EN.md", "title_cn": "\u5916\u89c2\u6570\u5217", "title_en": "Count and Say", "question_title_slug": "count-and-say", "content_en": "

    The count-and-say sequence is a sequence of digit strings defined by the recursive formula:

    \n\n
      \n\t
    • countAndSay(1) = "1"
    • \n\t
    • countAndSay(n) is the way you would "say" the digit string from countAndSay(n-1), which is then converted into a different digit string.
    • \n
    \n\n

    To determine how you "say" a digit string, split it into the minimal number of groups so that each group is a contiguous section all of the same character. Then for each group, say the number of characters, then say the character. To convert the saying into a digit string, replace the counts with a number and concatenate every saying.

    \n\n

    For example, the saying and conversion for digit string "3322251":

    \n\"\"\n

    Given a positive integer n, return the nth term of the count-and-say sequence.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: n = 1\nOutput: "1"\nExplanation: This is the base case.\n
    \n\n

    Example 2:

    \n\n
    \nInput: n = 4\nOutput: "1211"\nExplanation:\ncountAndSay(1) = "1"\ncountAndSay(2) = say "1" = one 1 = "11"\ncountAndSay(3) = say "11" = two 1's = "21"\ncountAndSay(4) = say "21" = one 2 + one 1 = "12" + "11" = "1211"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 30
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6b63\u6574\u6570 n \uff0c\u8f93\u51fa\u5916\u89c2\u6570\u5217\u7684\u7b2c n \u9879\u3002

    \n\n

    \u300c\u5916\u89c2\u6570\u5217\u300d\u662f\u4e00\u4e2a\u6574\u6570\u5e8f\u5217\uff0c\u4ece\u6570\u5b57 1 \u5f00\u59cb\uff0c\u5e8f\u5217\u4e2d\u7684\u6bcf\u4e00\u9879\u90fd\u662f\u5bf9\u524d\u4e00\u9879\u7684\u63cf\u8ff0\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u5c06\u5176\u89c6\u4f5c\u662f\u7531\u9012\u5f52\u516c\u5f0f\u5b9a\u4e49\u7684\u6570\u5b57\u5b57\u7b26\u4e32\u5e8f\u5217\uff1a

    \n\n
      \n\t
    • countAndSay(1) = \"1\"
    • \n\t
    • countAndSay(n) \u662f\u5bf9 countAndSay(n-1) \u7684\u63cf\u8ff0\uff0c\u7136\u540e\u8f6c\u6362\u6210\u53e6\u4e00\u4e2a\u6570\u5b57\u5b57\u7b26\u4e32\u3002
    • \n
    \n\n

    \u524d\u4e94\u9879\u5982\u4e0b\uff1a

    \n\n
    \n1.     1\n2.     11\n3.     21\n4.     1211\n5.     111221\n\u7b2c\u4e00\u9879\u662f\u6570\u5b57 1 \n\u63cf\u8ff0\u524d\u4e00\u9879\uff0c\u8fd9\u4e2a\u6570\u662f 1 \u5373 \u201c \u4e00 \u4e2a 1 \u201d\uff0c\u8bb0\u4f5c \"11\"\n\u63cf\u8ff0\u524d\u4e00\u9879\uff0c\u8fd9\u4e2a\u6570\u662f 11 \u5373 \u201c \u4e8c \u4e2a 1 \u201d \uff0c\u8bb0\u4f5c \"21\"\n\u63cf\u8ff0\u524d\u4e00\u9879\uff0c\u8fd9\u4e2a\u6570\u662f 21 \u5373 \u201c \u4e00 \u4e2a 2 + \u4e00 \u4e2a 1 \u201d \uff0c\u8bb0\u4f5c \"1211\"\n\u63cf\u8ff0\u524d\u4e00\u9879\uff0c\u8fd9\u4e2a\u6570\u662f 1211 \u5373 \u201c \u4e00 \u4e2a 1 + \u4e00 \u4e2a 2 + \u4e8c \u4e2a 1 \u201d \uff0c\u8bb0\u4f5c \"111221\"\n
    \n\n

    \u8981 \u63cf\u8ff0 \u4e00\u4e2a\u6570\u5b57\u5b57\u7b26\u4e32\uff0c\u9996\u5148\u8981\u5c06\u5b57\u7b26\u4e32\u5206\u5272\u4e3a \u6700\u5c0f \u6570\u91cf\u7684\u7ec4\uff0c\u6bcf\u4e2a\u7ec4\u90fd\u7531\u8fde\u7eed\u7684\u6700\u591a \u76f8\u540c\u5b57\u7b26 \u7ec4\u6210\u3002\u7136\u540e\u5bf9\u4e8e\u6bcf\u4e2a\u7ec4\uff0c\u5148\u63cf\u8ff0\u5b57\u7b26\u7684\u6570\u91cf\uff0c\u7136\u540e\u63cf\u8ff0\u5b57\u7b26\uff0c\u5f62\u6210\u4e00\u4e2a\u63cf\u8ff0\u7ec4\u3002\u8981\u5c06\u63cf\u8ff0\u8f6c\u6362\u4e3a\u6570\u5b57\u5b57\u7b26\u4e32\uff0c\u5148\u5c06\u6bcf\u7ec4\u4e2d\u7684\u5b57\u7b26\u6570\u91cf\u7528\u6570\u5b57\u66ff\u6362\uff0c\u518d\u5c06\u6240\u6709\u63cf\u8ff0\u7ec4\u8fde\u63a5\u8d77\u6765\u3002

    \n\n

    \u4f8b\u5982\uff0c\u6570\u5b57\u5b57\u7b26\u4e32 \"3322251\" \u7684\u63cf\u8ff0\u5982\u4e0b\u56fe\uff1a

    \n\"\"\n
      \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1a\"1\"\n\u89e3\u91ca\uff1a\u8fd9\u662f\u4e00\u4e2a\u57fa\u672c\u6837\u4f8b\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 4\n\u8f93\u51fa\uff1a\"1211\"\n\u89e3\u91ca\uff1a\ncountAndSay(1) = \"1\"\ncountAndSay(2) = \u8bfb \"1\" = \u4e00 \u4e2a 1 = \"11\"\ncountAndSay(3) = \u8bfb \"11\" = \u4e8c \u4e2a 1 = \"21\"\ncountAndSay(4) = \u8bfb \"21\" = \u4e00 \u4e2a 2 + \u4e00 \u4e2a 1 = \"12\" + \"11\" = \"1211\"\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 30
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string countAndSay(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String countAndSay(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def countAndSay(self, n):\n \"\"\"\n :type n: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def countAndSay(self, n: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * countAndSay(int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string CountAndSay(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {string}\n */\nvar countAndSay = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {String}\ndef count_and_say(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func countAndSay(_ n: Int) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func countAndSay(n int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def countAndSay(n: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun countAndSay(n: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn count_and_say(n: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return String\n */\n function countAndSay($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function countAndSay(n: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (count-and-say n)\n (-> exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0038](https://leetcode-cn.com/problems/count-and-say)", "[\u5916\u89c2\u6570\u5217](/solution/0000-0099/0038.Count%20and%20Say/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0038](https://leetcode.com/problems/count-and-say)", "[Count and Say](/solution/0000-0099/0038.Count%20and%20Say/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "0037", "frontend_question_id": "0037", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/sudoku-solver", "url_en": "https://leetcode.com/problems/sudoku-solver", "relative_path_cn": "/solution/0000-0099/0037.Sudoku%20Solver/README.md", "relative_path_en": "/solution/0000-0099/0037.Sudoku%20Solver/README_EN.md", "title_cn": "\u89e3\u6570\u72ec", "title_en": "Sudoku Solver", "question_title_slug": "sudoku-solver", "content_en": "

    Write a program to solve a Sudoku puzzle by filling the empty cells.

    \n\n

    A sudoku solution must satisfy all of the following rules:

    \n\n
      \n\t
    1. Each of the digits 1-9 must occur exactly once in each row.
    2. \n\t
    3. Each of the digits 1-9 must occur exactly once in each column.
    4. \n\t
    5. Each of the digits 1-9 must occur exactly once in each of the 9 3x3 sub-boxes of the grid.
    6. \n
    \n\n

    The '.' character indicates empty cells.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: board = [["5","3",".",".","7",".",".",".","."],["6",".",".","1","9","5",".",".","."],[".","9","8",".",".",".",".","6","."],["8",".",".",".","6",".",".",".","3"],["4",".",".","8",".","3",".",".","1"],["7",".",".",".","2",".",".",".","6"],[".","6",".",".",".",".","2","8","."],[".",".",".","4","1","9",".",".","5"],[".",".",".",".","8",".",".","7","9"]]\nOutput: [["5","3","4","6","7","8","9","1","2"],["6","7","2","1","9","5","3","4","8"],["1","9","8","3","4","2","5","6","7"],["8","5","9","7","6","1","4","2","3"],["4","2","6","8","5","3","7","9","1"],["7","1","3","9","2","4","8","5","6"],["9","6","1","5","3","7","2","8","4"],["2","8","7","4","1","9","6","3","5"],["3","4","5","2","8","6","1","7","9"]]\nExplanation: The input board is shown above and the only valid solution is shown below:\n\n\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • board.length == 9
    • \n\t
    • board[i].length == 9
    • \n\t
    • board[i][j] is a digit or '.'.
    • \n\t
    • It is guaranteed that the input board has only one solution.
    • \n
    \n", "content_cn": "

    \u7f16\u5199\u4e00\u4e2a\u7a0b\u5e8f\uff0c\u901a\u8fc7\u586b\u5145\u7a7a\u683c\u6765\u89e3\u51b3\u6570\u72ec\u95ee\u9898\u3002

    \n\n

    \u6570\u72ec\u7684\u89e3\u6cd5\u9700 \u9075\u5faa\u5982\u4e0b\u89c4\u5219\uff1a

    \n\n
      \n\t
    1. \u6570\u5b57\u00a01-9\u00a0\u5728\u6bcf\u4e00\u884c\u53ea\u80fd\u51fa\u73b0\u4e00\u6b21\u3002
    2. \n\t
    3. \u6570\u5b57\u00a01-9\u00a0\u5728\u6bcf\u4e00\u5217\u53ea\u80fd\u51fa\u73b0\u4e00\u6b21\u3002
    4. \n\t
    5. \u6570\u5b57\u00a01-9\u00a0\u5728\u6bcf\u4e00\u4e2a\u4ee5\u7c97\u5b9e\u7ebf\u5206\u9694\u7684\u00a03x3\u00a0\u5bab\u5185\u53ea\u80fd\u51fa\u73b0\u4e00\u6b21\u3002\uff08\u8bf7\u53c2\u8003\u793a\u4f8b\u56fe\uff09
    6. \n
    \n\n

    \u6570\u72ec\u90e8\u5206\u7a7a\u683c\u5185\u5df2\u586b\u5165\u4e86\u6570\u5b57\uff0c\u7a7a\u767d\u683c\u7528\u00a0'.'\u00a0\u8868\u793a\u3002

    \n\n

    \u00a0

    \n\n
    \n
    \n
    \n

    \u793a\u4f8b\uff1a

    \n\n
    \n\u8f93\u5165\uff1aboard = [[\"5\",\"3\",\".\",\".\",\"7\",\".\",\".\",\".\",\".\"],[\"6\",\".\",\".\",\"1\",\"9\",\"5\",\".\",\".\",\".\"],[\".\",\"9\",\"8\",\".\",\".\",\".\",\".\",\"6\",\".\"],[\"8\",\".\",\".\",\".\",\"6\",\".\",\".\",\".\",\"3\"],[\"4\",\".\",\".\",\"8\",\".\",\"3\",\".\",\".\",\"1\"],[\"7\",\".\",\".\",\".\",\"2\",\".\",\".\",\".\",\"6\"],[\".\",\"6\",\".\",\".\",\".\",\".\",\"2\",\"8\",\".\"],[\".\",\".\",\".\",\"4\",\"1\",\"9\",\".\",\".\",\"5\"],[\".\",\".\",\".\",\".\",\"8\",\".\",\".\",\"7\",\"9\"]]\n\u8f93\u51fa\uff1a[[\"5\",\"3\",\"4\",\"6\",\"7\",\"8\",\"9\",\"1\",\"2\"],[\"6\",\"7\",\"2\",\"1\",\"9\",\"5\",\"3\",\"4\",\"8\"],[\"1\",\"9\",\"8\",\"3\",\"4\",\"2\",\"5\",\"6\",\"7\"],[\"8\",\"5\",\"9\",\"7\",\"6\",\"1\",\"4\",\"2\",\"3\"],[\"4\",\"2\",\"6\",\"8\",\"5\",\"3\",\"7\",\"9\",\"1\"],[\"7\",\"1\",\"3\",\"9\",\"2\",\"4\",\"8\",\"5\",\"6\"],[\"9\",\"6\",\"1\",\"5\",\"3\",\"7\",\"2\",\"8\",\"4\"],[\"2\",\"8\",\"7\",\"4\",\"1\",\"9\",\"6\",\"3\",\"5\"],[\"3\",\"4\",\"5\",\"2\",\"8\",\"6\",\"1\",\"7\",\"9\"]]\n\u89e3\u91ca\uff1a\u8f93\u5165\u7684\u6570\u72ec\u5982\u4e0a\u56fe\u6240\u793a\uff0c\u552f\u4e00\u6709\u6548\u7684\u89e3\u51b3\u65b9\u6848\u5982\u4e0b\u6240\u793a\uff1a\n\n\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • board.length == 9
    • \n\t
    • board[i].length == 9
    • \n\t
    • board[i][j] \u662f\u4e00\u4f4d\u6570\u5b57\u6216\u8005 '.'
    • \n\t
    • \u9898\u76ee\u6570\u636e \u4fdd\u8bc1 \u8f93\u5165\u6570\u72ec\u4ec5\u6709\u4e00\u4e2a\u89e3
    • \n
    \n
    \n
    \n
    \n", "tags_en": ["Hash Table", "Backtracking"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n void solveSudoku(vector>& board) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public void solveSudoku(char[][] board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def solveSudoku(self, board):\n \"\"\"\n :type board: List[List[str]]\n :rtype: None Do not return anything, modify board in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def solveSudoku(self, board: List[List[str]]) -> None:\n \"\"\"\n Do not return anything, modify board in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nvoid solveSudoku(char** board, int boardSize, int* boardColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public void SolveSudoku(char[][] board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {character[][]} board\n * @return {void} Do not return anything, modify board in-place instead.\n */\nvar solveSudoku = function(board) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Character[][]} board\n# @return {Void} Do not return anything, modify board in-place instead.\ndef solve_sudoku(board)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func solveSudoku(_ board: inout [[Character]]) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func solveSudoku(board [][]byte) {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def solveSudoku(board: Array[Array[Char]]): Unit = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun solveSudoku(board: Array): Unit {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn solve_sudoku(board: &mut Vec>) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $board\n * @return NULL\n */\n function solveSudoku(&$board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n Do not return anything, modify board in-place instead.\n */\nfunction solveSudoku(board: string[][]): void {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0037](https://leetcode-cn.com/problems/sudoku-solver)", "[\u89e3\u6570\u72ec](/solution/0000-0099/0037.Sudoku%20Solver/README.md)", "`\u54c8\u5e0c\u8868`,`\u56de\u6eaf\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[0037](https://leetcode.com/problems/sudoku-solver)", "[Sudoku Solver](/solution/0000-0099/0037.Sudoku%20Solver/README_EN.md)", "`Hash Table`,`Backtracking`", "Hard", ""]}, {"question_id": "0036", "frontend_question_id": "0036", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/valid-sudoku", "url_en": "https://leetcode.com/problems/valid-sudoku", "relative_path_cn": "/solution/0000-0099/0036.Valid%20Sudoku/README.md", "relative_path_en": "/solution/0000-0099/0036.Valid%20Sudoku/README_EN.md", "title_cn": "\u6709\u6548\u7684\u6570\u72ec", "title_en": "Valid Sudoku", "question_title_slug": "valid-sudoku", "content_en": "

    Determine if a 9 x 9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules:

    \n\n
      \n\t
    1. Each row must contain the digits 1-9 without repetition.
    2. \n\t
    3. Each column must contain the digits 1-9 without repetition.
    4. \n\t
    5. Each of the nine 3 x 3 sub-boxes of the grid must contain the digits 1-9 without repetition.
    6. \n
    \n\n

    Note:

    \n\n
      \n\t
    • A Sudoku board (partially filled) could be valid but is not necessarily solvable.
    • \n\t
    • Only the filled cells need to be validated according to the mentioned rules.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: board = \n[["5","3",".",".","7",".",".",".","."]\n,["6",".",".","1","9","5",".",".","."]\n,[".","9","8",".",".",".",".","6","."]\n,["8",".",".",".","6",".",".",".","3"]\n,["4",".",".","8",".","3",".",".","1"]\n,["7",".",".",".","2",".",".",".","6"]\n,[".","6",".",".",".",".","2","8","."]\n,[".",".",".","4","1","9",".",".","5"]\n,[".",".",".",".","8",".",".","7","9"]]\nOutput: true\n
    \n\n

    Example 2:

    \n\n
    \nInput: board = \n[["8","3",".",".","7",".",".",".","."]\n,["6",".",".","1","9","5",".",".","."]\n,[".","9","8",".",".",".",".","6","."]\n,["8",".",".",".","6",".",".",".","3"]\n,["4",".",".","8",".","3",".",".","1"]\n,["7",".",".",".","2",".",".",".","6"]\n,[".","6",".",".",".",".","2","8","."]\n,[".",".",".","4","1","9",".",".","5"]\n,[".",".",".",".","8",".",".","7","9"]]\nOutput: false\nExplanation: Same as Example 1, except with the 5 in the top left corner being modified to 8. Since there are two 8's in the top left 3x3 sub-box, it is invalid.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • board.length == 9
    • \n\t
    • board[i].length == 9
    • \n\t
    • board[i][j] is a digit or '.'.
    • \n
    \n", "content_cn": "

    \u8bf7\u4f60\u5224\u65ad\u4e00\u4e2a\u00a09x9 \u7684\u6570\u72ec\u662f\u5426\u6709\u6548\u3002\u53ea\u9700\u8981 \u6839\u636e\u4ee5\u4e0b\u89c4\u5219 \uff0c\u9a8c\u8bc1\u5df2\u7ecf\u586b\u5165\u7684\u6570\u5b57\u662f\u5426\u6709\u6548\u5373\u53ef\u3002

    \n\n
      \n\t
    1. \u6570\u5b57\u00a01-9\u00a0\u5728\u6bcf\u4e00\u884c\u53ea\u80fd\u51fa\u73b0\u4e00\u6b21\u3002
    2. \n\t
    3. \u6570\u5b57\u00a01-9\u00a0\u5728\u6bcf\u4e00\u5217\u53ea\u80fd\u51fa\u73b0\u4e00\u6b21\u3002
    4. \n\t
    5. \u6570\u5b57\u00a01-9\u00a0\u5728\u6bcf\u4e00\u4e2a\u4ee5\u7c97\u5b9e\u7ebf\u5206\u9694\u7684\u00a03x3\u00a0\u5bab\u5185\u53ea\u80fd\u51fa\u73b0\u4e00\u6b21\u3002\uff08\u8bf7\u53c2\u8003\u793a\u4f8b\u56fe\uff09
    6. \n
    \n\n

    \u6570\u72ec\u90e8\u5206\u7a7a\u683c\u5185\u5df2\u586b\u5165\u4e86\u6570\u5b57\uff0c\u7a7a\u767d\u683c\u7528\u00a0'.'\u00a0\u8868\u793a\u3002

    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    • \u4e00\u4e2a\u6709\u6548\u7684\u6570\u72ec\uff08\u90e8\u5206\u5df2\u88ab\u586b\u5145\uff09\u4e0d\u4e00\u5b9a\u662f\u53ef\u89e3\u7684\u3002
    • \n\t
    • \u53ea\u9700\u8981\u6839\u636e\u4ee5\u4e0a\u89c4\u5219\uff0c\u9a8c\u8bc1\u5df2\u7ecf\u586b\u5165\u7684\u6570\u5b57\u662f\u5426\u6709\u6548\u5373\u53ef\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1aboard = \n[[\"5\",\"3\",\".\",\".\",\"7\",\".\",\".\",\".\",\".\"]\n,[\"6\",\".\",\".\",\"1\",\"9\",\"5\",\".\",\".\",\".\"]\n,[\".\",\"9\",\"8\",\".\",\".\",\".\",\".\",\"6\",\".\"]\n,[\"8\",\".\",\".\",\".\",\"6\",\".\",\".\",\".\",\"3\"]\n,[\"4\",\".\",\".\",\"8\",\".\",\"3\",\".\",\".\",\"1\"]\n,[\"7\",\".\",\".\",\".\",\"2\",\".\",\".\",\".\",\"6\"]\n,[\".\",\"6\",\".\",\".\",\".\",\".\",\"2\",\"8\",\".\"]\n,[\".\",\".\",\".\",\"4\",\"1\",\"9\",\".\",\".\",\"5\"]\n,[\".\",\".\",\".\",\".\",\"8\",\".\",\".\",\"7\",\"9\"]]\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aboard = \n[[\"8\",\"3\",\".\",\".\",\"7\",\".\",\".\",\".\",\".\"]\n,[\"6\",\".\",\".\",\"1\",\"9\",\"5\",\".\",\".\",\".\"]\n,[\".\",\"9\",\"8\",\".\",\".\",\".\",\".\",\"6\",\".\"]\n,[\"8\",\".\",\".\",\".\",\"6\",\".\",\".\",\".\",\"3\"]\n,[\"4\",\".\",\".\",\"8\",\".\",\"3\",\".\",\".\",\"1\"]\n,[\"7\",\".\",\".\",\".\",\"2\",\".\",\".\",\".\",\"6\"]\n,[\".\",\"6\",\".\",\".\",\".\",\".\",\"2\",\"8\",\".\"]\n,[\".\",\".\",\".\",\"4\",\"1\",\"9\",\".\",\".\",\"5\"]\n,[\".\",\".\",\".\",\".\",\"8\",\".\",\".\",\"7\",\"9\"]]\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u9664\u4e86\u7b2c\u4e00\u884c\u7684\u7b2c\u4e00\u4e2a\u6570\u5b57\u4ece 5 \u6539\u4e3a 8 \u4ee5\u5916\uff0c\u7a7a\u683c\u5185\u5176\u4ed6\u6570\u5b57\u5747\u4e0e \u793a\u4f8b1 \u76f8\u540c\u3002 \u4f46\u7531\u4e8e\u4f4d\u4e8e\u5de6\u4e0a\u89d2\u7684 3x3 \u5bab\u5185\u6709\u4e24\u4e2a 8 \u5b58\u5728, \u56e0\u6b64\u8fd9\u4e2a\u6570\u72ec\u662f\u65e0\u6548\u7684\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • board.length == 9
    • \n\t
    • board[i].length == 9
    • \n\t
    • board[i][j] \u662f\u4e00\u4f4d\u6570\u5b57\u6216\u8005 '.'
    • \n
    \n", "tags_en": ["Hash Table"], "tags_cn": ["\u54c8\u5e0c\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isValidSudoku(vector>& board) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isValidSudoku(char[][] board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isValidSudoku(self, board):\n \"\"\"\n :type board: List[List[str]]\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isValidSudoku(self, board: List[List[str]]) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isValidSudoku(char** board, int boardSize, int* boardColSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsValidSudoku(char[][] board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {character[][]} board\n * @return {boolean}\n */\nvar isValidSudoku = function(board) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Character[][]} board\n# @return {Boolean}\ndef is_valid_sudoku(board)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isValidSudoku(_ board: [[Character]]) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isValidSudoku(board [][]byte) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isValidSudoku(board: Array[Array[Char]]): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isValidSudoku(board: Array): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_valid_sudoku(board: Vec>) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[][] $board\n * @return Boolean\n */\n function isValidSudoku($board) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isValidSudoku(board: string[][]): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-valid-sudoku board)\n (-> (listof (listof char?)) boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0036](https://leetcode-cn.com/problems/valid-sudoku)", "[\u6709\u6548\u7684\u6570\u72ec](/solution/0000-0099/0036.Valid%20Sudoku/README.md)", "`\u54c8\u5e0c\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0036](https://leetcode.com/problems/valid-sudoku)", "[Valid Sudoku](/solution/0000-0099/0036.Valid%20Sudoku/README_EN.md)", "`Hash Table`", "Medium", ""]}, {"question_id": "0035", "frontend_question_id": "0035", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/search-insert-position", "url_en": "https://leetcode.com/problems/search-insert-position", "relative_path_cn": "/solution/0000-0099/0035.Search%20Insert%20Position/README.md", "relative_path_en": "/solution/0000-0099/0035.Search%20Insert%20Position/README_EN.md", "title_cn": "\u641c\u7d22\u63d2\u5165\u4f4d\u7f6e", "title_en": "Search Insert Position", "question_title_slug": "search-insert-position", "content_en": "

    Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.

    \n\n

    You must write an algorithm with O(log n) runtime complexity.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [1,3,5,6], target = 5\nOutput: 2\n

    Example 2:

    \n
    Input: nums = [1,3,5,6], target = 2\nOutput: 1\n

    Example 3:

    \n
    Input: nums = [1,3,5,6], target = 7\nOutput: 4\n

    Example 4:

    \n
    Input: nums = [1,3,5,6], target = 0\nOutput: 0\n

    Example 5:

    \n
    Input: nums = [1], target = 0\nOutput: 0\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 104
    • \n\t
    • -104 <= nums[i] <= 104
    • \n\t
    • nums contains distinct values sorted in ascending order.
    • \n\t
    • -104 <= target <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6392\u5e8f\u6570\u7ec4\u548c\u4e00\u4e2a\u76ee\u6807\u503c\uff0c\u5728\u6570\u7ec4\u4e2d\u627e\u5230\u76ee\u6807\u503c\uff0c\u5e76\u8fd4\u56de\u5176\u7d22\u5f15\u3002\u5982\u679c\u76ee\u6807\u503c\u4e0d\u5b58\u5728\u4e8e\u6570\u7ec4\u4e2d\uff0c\u8fd4\u56de\u5b83\u5c06\u4f1a\u88ab\u6309\u987a\u5e8f\u63d2\u5165\u7684\u4f4d\u7f6e\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u5047\u8bbe\u6570\u7ec4\u4e2d\u65e0\u91cd\u590d\u5143\u7d20\u3002

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: [1,3,5,6], 5\n\u8f93\u51fa: 2\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: [1,3,5,6], 2\n\u8f93\u51fa: 1\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \u8f93\u5165: [1,3,5,6], 7\n\u8f93\u51fa: 4\n
    \n\n

    \u793a\u4f8b 4:

    \n\n
    \u8f93\u5165: [1,3,5,6], 0\n\u8f93\u51fa: 0\n
    \n", "tags_en": ["Array", "Binary Search"], "tags_cn": ["\u6570\u7ec4", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int searchInsert(vector& nums, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int searchInsert(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def searchInsert(self, nums, target):\n \"\"\"\n :type nums: List[int]\n :type target: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def searchInsert(self, nums: List[int], target: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint searchInsert(int* nums, int numsSize, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int SearchInsert(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} target\n * @return {number}\n */\nvar searchInsert = function(nums, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} target\n# @return {Integer}\ndef search_insert(nums, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func searchInsert(_ nums: [Int], _ target: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func searchInsert(nums []int, target int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def searchInsert(nums: Array[Int], target: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun searchInsert(nums: IntArray, target: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn search_insert(nums: Vec, target: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $target\n * @return Integer\n */\n function searchInsert($nums, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function searchInsert(nums: number[], target: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (search-insert nums target)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0035](https://leetcode-cn.com/problems/search-insert-position)", "[\u641c\u7d22\u63d2\u5165\u4f4d\u7f6e](/solution/0000-0099/0035.Search%20Insert%20Position/README.md)", "`\u6570\u7ec4`,`\u4e8c\u5206\u67e5\u627e`", "\u7b80\u5355", ""], "md_table_row_en": ["[0035](https://leetcode.com/problems/search-insert-position)", "[Search Insert Position](/solution/0000-0099/0035.Search%20Insert%20Position/README_EN.md)", "`Array`,`Binary Search`", "Easy", ""]}, {"question_id": "0034", "frontend_question_id": "0034", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/find-first-and-last-position-of-element-in-sorted-array", "url_en": "https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array", "relative_path_cn": "/solution/0000-0099/0034.Find%20First%20and%20Last%20Position%20of%20Element%20in%20Sorted%20Array/README.md", "relative_path_en": "/solution/0000-0099/0034.Find%20First%20and%20Last%20Position%20of%20Element%20in%20Sorted%20Array/README_EN.md", "title_cn": "\u5728\u6392\u5e8f\u6570\u7ec4\u4e2d\u67e5\u627e\u5143\u7d20\u7684\u7b2c\u4e00\u4e2a\u548c\u6700\u540e\u4e00\u4e2a\u4f4d\u7f6e", "title_en": "Find First and Last Position of Element in Sorted Array", "question_title_slug": "find-first-and-last-position-of-element-in-sorted-array", "content_en": "

    Given an array of integers nums sorted in ascending order, find the starting and ending position of a given target value.

    \n\n

    If target is not found in the array, return [-1, -1].

    \n\n

    You must write an algorithm with O(log n) runtime complexity.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [5,7,7,8,8,10], target = 8\nOutput: [3,4]\n

    Example 2:

    \n
    Input: nums = [5,7,7,8,8,10], target = 6\nOutput: [-1,-1]\n

    Example 3:

    \n
    Input: nums = [], target = 0\nOutput: [-1,-1]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= nums.length <= 105
    • \n\t
    • -109 <= nums[i] <= 109
    • \n\t
    • nums is a non-decreasing array.
    • \n\t
    • -109 <= target <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6309\u7167\u5347\u5e8f\u6392\u5217\u7684\u6574\u6570\u6570\u7ec4 nums\uff0c\u548c\u4e00\u4e2a\u76ee\u6807\u503c target\u3002\u627e\u51fa\u7ed9\u5b9a\u76ee\u6807\u503c\u5728\u6570\u7ec4\u4e2d\u7684\u5f00\u59cb\u4f4d\u7f6e\u548c\u7ed3\u675f\u4f4d\u7f6e\u3002

    \n\n

    \u5982\u679c\u6570\u7ec4\u4e2d\u4e0d\u5b58\u5728\u76ee\u6807\u503c target\uff0c\u8fd4\u56de\u00a0[-1, -1]\u3002

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u4f60\u53ef\u4ee5\u8bbe\u8ba1\u5e76\u5b9e\u73b0\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a\u00a0O(log n)\u00a0\u7684\u7b97\u6cd5\u89e3\u51b3\u6b64\u95ee\u9898\u5417\uff1f
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [5,7,7,8,8,10], target = 8\n\u8f93\u51fa\uff1a[3,4]
    \n\n

    \u793a\u4f8b\u00a02\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [5,7,7,8,8,10], target = 6\n\u8f93\u51fa\uff1a[-1,-1]
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [], target = 0\n\u8f93\u51fa\uff1a[-1,-1]
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= nums.length <= 105
    • \n\t
    • -109\u00a0<= nums[i]\u00a0<= 109
    • \n\t
    • nums\u00a0\u662f\u4e00\u4e2a\u975e\u9012\u51cf\u6570\u7ec4
    • \n\t
    • -109\u00a0<= target\u00a0<= 109
    • \n
    \n", "tags_en": ["Array", "Binary Search"], "tags_cn": ["\u6570\u7ec4", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector searchRange(vector& nums, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] searchRange(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def searchRange(self, nums, target):\n \"\"\"\n :type nums: List[int]\n :type target: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def searchRange(self, nums: List[int], target: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* searchRange(int* nums, int numsSize, int target, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] SearchRange(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} target\n * @return {number[]}\n */\nvar searchRange = function(nums, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} target\n# @return {Integer[]}\ndef search_range(nums, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func searchRange(_ nums: [Int], _ target: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func searchRange(nums []int, target int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def searchRange(nums: Array[Int], target: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun searchRange(nums: IntArray, target: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn search_range(nums: Vec, target: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $target\n * @return Integer[]\n */\n function searchRange($nums, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function searchRange(nums: number[], target: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (search-range nums target)\n (-> (listof exact-integer?) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0034](https://leetcode-cn.com/problems/find-first-and-last-position-of-element-in-sorted-array)", "[\u5728\u6392\u5e8f\u6570\u7ec4\u4e2d\u67e5\u627e\u5143\u7d20\u7684\u7b2c\u4e00\u4e2a\u548c\u6700\u540e\u4e00\u4e2a\u4f4d\u7f6e](/solution/0000-0099/0034.Find%20First%20and%20Last%20Position%20of%20Element%20in%20Sorted%20Array/README.md)", "`\u6570\u7ec4`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0034](https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array)", "[Find First and Last Position of Element in Sorted Array](/solution/0000-0099/0034.Find%20First%20and%20Last%20Position%20of%20Element%20in%20Sorted%20Array/README_EN.md)", "`Array`,`Binary Search`", "Medium", ""]}, {"question_id": "0033", "frontend_question_id": "0033", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/search-in-rotated-sorted-array", "url_en": "https://leetcode.com/problems/search-in-rotated-sorted-array", "relative_path_cn": "/solution/0000-0099/0033.Search%20in%20Rotated%20Sorted%20Array/README.md", "relative_path_en": "/solution/0000-0099/0033.Search%20in%20Rotated%20Sorted%20Array/README_EN.md", "title_cn": "\u641c\u7d22\u65cb\u8f6c\u6392\u5e8f\u6570\u7ec4", "title_en": "Search in Rotated Sorted Array", "question_title_slug": "search-in-rotated-sorted-array", "content_en": "

    There is an integer array nums sorted in ascending order (with distinct values).

    \n\n

    Prior to being passed to your function, nums is rotated at an unknown pivot index k (0 <= k < nums.length) such that the resulting array is [nums[k], nums[k+1], ..., nums[n-1], nums[0], nums[1], ..., nums[k-1]] (0-indexed). For example, [0,1,2,4,5,6,7] might be rotated at pivot index 3 and become [4,5,6,7,0,1,2].

    \n\n

    Given the array nums after the rotation and an integer target, return the index of target if it is in nums, or -1 if it is not in nums.

    \n\n

    You must write an algorithm with O(log n) runtime complexity.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [4,5,6,7,0,1,2], target = 0\nOutput: 4\n

    Example 2:

    \n
    Input: nums = [4,5,6,7,0,1,2], target = 3\nOutput: -1\n

    Example 3:

    \n
    Input: nums = [1], target = 0\nOutput: -1\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 5000
    • \n\t
    • -104 <= nums[i] <= 104
    • \n\t
    • All values of nums are unique.
    • \n\t
    • nums is guaranteed to be rotated at some pivot.
    • \n\t
    • -104 <= target <= 104
    • \n
    \n", "content_cn": "

    \u6574\u6570\u6570\u7ec4 nums \u6309\u5347\u5e8f\u6392\u5217\uff0c\u6570\u7ec4\u4e2d\u7684\u503c \u4e92\u4e0d\u76f8\u540c \u3002

    \n\n

    \u5728\u4f20\u9012\u7ed9\u51fd\u6570\u4e4b\u524d\uff0cnums \u5728\u9884\u5148\u672a\u77e5\u7684\u67d0\u4e2a\u4e0b\u6807 k\uff080 <= k < nums.length\uff09\u4e0a\u8fdb\u884c\u4e86 \u65cb\u8f6c\uff0c\u4f7f\u6570\u7ec4\u53d8\u4e3a [nums[k], nums[k+1], ..., nums[n-1], nums[0], nums[1], ..., nums[k-1]]\uff08\u4e0b\u6807 \u4ece 0 \u5f00\u59cb \u8ba1\u6570\uff09\u3002\u4f8b\u5982\uff0c [0,1,2,4,5,6,7] \u5728\u4e0b\u6807 3 \u5904\u7ecf\u65cb\u8f6c\u540e\u53ef\u80fd\u53d8\u4e3a\u00a0[4,5,6,7,0,1,2] \u3002

    \n\n

    \u7ed9\u4f60 \u65cb\u8f6c\u540e \u7684\u6570\u7ec4 nums \u548c\u4e00\u4e2a\u6574\u6570 target \uff0c\u5982\u679c nums \u4e2d\u5b58\u5728\u8fd9\u4e2a\u76ee\u6807\u503c target \uff0c\u5219\u8fd4\u56de\u5b83\u7684\u4e0b\u6807\uff0c\u5426\u5219\u8fd4\u56de\u00a0-1\u00a0\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [4,5,6,7,0,1,2], target = 0\n\u8f93\u51fa\uff1a4\n
    \n\n

    \u793a\u4f8b\u00a02\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [4,5,6,7,0,1,2], target = 3\n\u8f93\u51fa\uff1a-1
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1], target = 0\n\u8f93\u51fa\uff1a-1\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 5000
    • \n\t
    • -10^4 <= nums[i] <= 10^4
    • \n\t
    • nums \u4e2d\u7684\u6bcf\u4e2a\u503c\u90fd \u72ec\u4e00\u65e0\u4e8c
    • \n\t
    • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1 nums \u5728\u9884\u5148\u672a\u77e5\u7684\u67d0\u4e2a\u4e0b\u6807\u4e0a\u8fdb\u884c\u4e86\u65cb\u8f6c
    • \n\t
    • -10^4 <= target <= 10^4
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u53ef\u4ee5\u8bbe\u8ba1\u4e00\u4e2a\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(log n) \u7684\u89e3\u51b3\u65b9\u6848\u5417\uff1f

    \n", "tags_en": ["Array", "Binary Search"], "tags_cn": ["\u6570\u7ec4", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int search(vector& nums, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int search(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def search(self, nums, target):\n \"\"\"\n :type nums: List[int]\n :type target: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def search(self, nums: List[int], target: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint search(int* nums, int numsSize, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int Search(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} target\n * @return {number}\n */\nvar search = function(nums, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} target\n# @return {Integer}\ndef search(nums, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func search(_ nums: [Int], _ target: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func search(nums []int, target int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def search(nums: Array[Int], target: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun search(nums: IntArray, target: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn search(nums: Vec, target: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $target\n * @return Integer\n */\n function search($nums, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function search(nums: number[], target: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (search nums target)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0033](https://leetcode-cn.com/problems/search-in-rotated-sorted-array)", "[\u641c\u7d22\u65cb\u8f6c\u6392\u5e8f\u6570\u7ec4](/solution/0000-0099/0033.Search%20in%20Rotated%20Sorted%20Array/README.md)", "`\u6570\u7ec4`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0033](https://leetcode.com/problems/search-in-rotated-sorted-array)", "[Search in Rotated Sorted Array](/solution/0000-0099/0033.Search%20in%20Rotated%20Sorted%20Array/README_EN.md)", "`Array`,`Binary Search`", "Medium", ""]}, {"question_id": "0032", "frontend_question_id": "0032", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-valid-parentheses", "url_en": "https://leetcode.com/problems/longest-valid-parentheses", "relative_path_cn": "/solution/0000-0099/0032.Longest%20Valid%20Parentheses/README.md", "relative_path_en": "/solution/0000-0099/0032.Longest%20Valid%20Parentheses/README_EN.md", "title_cn": "\u6700\u957f\u6709\u6548\u62ec\u53f7", "title_en": "Longest Valid Parentheses", "question_title_slug": "longest-valid-parentheses", "content_en": "

    Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "(()"\nOutput: 2\nExplanation: The longest valid parentheses substring is "()".\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = ")()())"\nOutput: 4\nExplanation: The longest valid parentheses substring is "()()".\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = ""\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= s.length <= 3 * 104
    • \n\t
    • s[i] is '(', or ')'.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u53ea\u5305\u542b '('\u00a0\u548c ')'\u00a0\u7684\u5b57\u7b26\u4e32\uff0c\u627e\u51fa\u6700\u957f\u6709\u6548\uff08\u683c\u5f0f\u6b63\u786e\u4e14\u8fde\u7eed\uff09\u62ec\u53f7\u5b50\u4e32\u7684\u957f\u5ea6\u3002

    \n\n

    \u00a0

    \n\n
    \n
    \n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"(()\"\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u6700\u957f\u6709\u6548\u62ec\u53f7\u5b50\u4e32\u662f \"()\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \")()())\"\n\u8f93\u51fa\uff1a4\n\u89e3\u91ca\uff1a\u6700\u957f\u6709\u6548\u62ec\u53f7\u5b50\u4e32\u662f \"()()\"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"\"\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= s.length <= 3 * 104
    • \n\t
    • s[i] \u4e3a '(' \u6216 ')'
    • \n
    \n
    \n
    \n", "tags_en": ["String", "Dynamic Programming"], "tags_cn": ["\u5b57\u7b26\u4e32", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int longestValidParentheses(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int longestValidParentheses(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestValidParentheses(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestValidParentheses(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint longestValidParentheses(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LongestValidParentheses(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar longestValidParentheses = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef longest_valid_parentheses(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestValidParentheses(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestValidParentheses(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestValidParentheses(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestValidParentheses(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_valid_parentheses(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function longestValidParentheses($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestValidParentheses(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-valid-parentheses s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0032](https://leetcode-cn.com/problems/longest-valid-parentheses)", "[\u6700\u957f\u6709\u6548\u62ec\u53f7](/solution/0000-0099/0032.Longest%20Valid%20Parentheses/README.md)", "`\u5b57\u7b26\u4e32`,`\u52a8\u6001\u89c4\u5212`", "\u56f0\u96be", ""], "md_table_row_en": ["[0032](https://leetcode.com/problems/longest-valid-parentheses)", "[Longest Valid Parentheses](/solution/0000-0099/0032.Longest%20Valid%20Parentheses/README_EN.md)", "`String`,`Dynamic Programming`", "Hard", ""]}, {"question_id": "0031", "frontend_question_id": "0031", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/next-permutation", "url_en": "https://leetcode.com/problems/next-permutation", "relative_path_cn": "/solution/0000-0099/0031.Next%20Permutation/README.md", "relative_path_en": "/solution/0000-0099/0031.Next%20Permutation/README_EN.md", "title_cn": "\u4e0b\u4e00\u4e2a\u6392\u5217", "title_en": "Next Permutation", "question_title_slug": "next-permutation", "content_en": "

    Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.

    \n\n

    If such an arrangement is not possible, it must rearrange it as the lowest possible order (i.e., sorted in ascending order).

    \n\n

    The replacement must be in place and use only constant extra memory.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [1,2,3]\nOutput: [1,3,2]\n

    Example 2:

    \n
    Input: nums = [3,2,1]\nOutput: [1,2,3]\n

    Example 3:

    \n
    Input: nums = [1,1,5]\nOutput: [1,5,1]\n

    Example 4:

    \n
    Input: nums = [1]\nOutput: [1]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 100
    • \n\t
    • 0 <= nums[i] <= 100
    • \n
    \n", "content_cn": "

    \u5b9e\u73b0\u83b7\u53d6 \u4e0b\u4e00\u4e2a\u6392\u5217 \u7684\u51fd\u6570\uff0c\u7b97\u6cd5\u9700\u8981\u5c06\u7ed9\u5b9a\u6570\u5b57\u5e8f\u5217\u91cd\u65b0\u6392\u5217\u6210\u5b57\u5178\u5e8f\u4e2d\u4e0b\u4e00\u4e2a\u66f4\u5927\u7684\u6392\u5217\u3002

    \n\n

    \u5982\u679c\u4e0d\u5b58\u5728\u4e0b\u4e00\u4e2a\u66f4\u5927\u7684\u6392\u5217\uff0c\u5219\u5c06\u6570\u5b57\u91cd\u65b0\u6392\u5217\u6210\u6700\u5c0f\u7684\u6392\u5217\uff08\u5373\u5347\u5e8f\u6392\u5217\uff09\u3002

    \n\n

    \u5fc5\u987b \u539f\u5730 \u4fee\u6539\uff0c\u53ea\u5141\u8bb8\u4f7f\u7528\u989d\u5916\u5e38\u6570\u7a7a\u95f4\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,2,3]\n\u8f93\u51fa\uff1a[1,3,2]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [3,2,1]\n\u8f93\u51fa\uff1a[1,2,3]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,1,5]\n\u8f93\u51fa\uff1a[1,5,1]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1]\n\u8f93\u51fa\uff1a[1]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= nums.length <= 100
    • \n\t
    • 0 <= nums[i] <= 100
    • \n
    \n", "tags_en": ["Array"], "tags_cn": ["\u6570\u7ec4"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n void nextPermutation(vector& nums) {\n \n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public void nextPermutation(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def nextPermutation(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: None Do not return anything, modify nums in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def nextPermutation(self, nums: List[int]) -> None:\n \"\"\"\n Do not return anything, modify nums in-place instead.\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nvoid nextPermutation(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public void NextPermutation(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {void} Do not return anything, modify nums in-place instead.\n */\nvar nextPermutation = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Void} Do not return anything, modify nums in-place instead.\ndef next_permutation(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func nextPermutation(_ nums: inout [Int]) {\n \n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func nextPermutation(nums []int) {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def nextPermutation(nums: Array[Int]): Unit = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun nextPermutation(nums: IntArray): Unit {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn next_permutation(nums: &mut Vec) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return NULL\n */\n function nextPermutation(&$nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n Do not return anything, modify nums in-place instead.\n */\nfunction nextPermutation(nums: number[]): void {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0031](https://leetcode-cn.com/problems/next-permutation)", "[\u4e0b\u4e00\u4e2a\u6392\u5217](/solution/0000-0099/0031.Next%20Permutation/README.md)", "`\u6570\u7ec4`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0031](https://leetcode.com/problems/next-permutation)", "[Next Permutation](/solution/0000-0099/0031.Next%20Permutation/README_EN.md)", "`Array`", "Medium", ""]}, {"question_id": "0030", "frontend_question_id": "0030", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/substring-with-concatenation-of-all-words", "url_en": "https://leetcode.com/problems/substring-with-concatenation-of-all-words", "relative_path_cn": "/solution/0000-0099/0030.Substring%20with%20Concatenation%20of%20All%20Words/README.md", "relative_path_en": "/solution/0000-0099/0030.Substring%20with%20Concatenation%20of%20All%20Words/README_EN.md", "title_cn": "\u4e32\u8054\u6240\u6709\u5355\u8bcd\u7684\u5b50\u4e32", "title_en": "Substring with Concatenation of All Words", "question_title_slug": "substring-with-concatenation-of-all-words", "content_en": "

    You are given a string s and an array of strings words of the same length. Return all starting indices of substring(s) in s that is a concatenation of each word in words exactly once, in any order, and without any intervening characters.

    \n\n

    You can return the answer in any order.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "barfoothefoobarman", words = ["foo","bar"]\nOutput: [0,9]\nExplanation: Substrings starting at index 0 and 9 are "barfoo" and "foobar" respectively.\nThe output order does not matter, returning [9,0] is fine too.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "wordgoodgoodgoodbestword", words = ["word","good","best","word"]\nOutput: []\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "barfoofoobarthefoobarman", words = ["bar","foo","the"]\nOutput: [6,9,12]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 104
    • \n\t
    • s consists of lower-case English letters.
    • \n\t
    • 1 <= words.length <= 5000
    • \n\t
    • 1 <= words[i].length <= 30
    • \n\t
    • words[i] consists of lower-case English letters.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\u00a0s\u00a0\u548c\u4e00\u4e9b \u957f\u5ea6\u76f8\u540c \u7684\u5355\u8bcd\u00a0words \u3002\u627e\u51fa s \u4e2d\u6070\u597d\u53ef\u4ee5\u7531\u00a0words \u4e2d\u6240\u6709\u5355\u8bcd\u4e32\u8054\u5f62\u6210\u7684\u5b50\u4e32\u7684\u8d77\u59cb\u4f4d\u7f6e\u3002

    \n\n

    \u6ce8\u610f\u5b50\u4e32\u8981\u4e0e\u00a0words \u4e2d\u7684\u5355\u8bcd\u5b8c\u5168\u5339\u914d\uff0c\u4e2d\u95f4\u4e0d\u80fd\u6709\u5176\u4ed6\u5b57\u7b26 \uff0c\u4f46\u4e0d\u9700\u8981\u8003\u8651\u00a0words\u00a0\u4e2d\u5355\u8bcd\u4e32\u8054\u7684\u987a\u5e8f\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"barfoothefoobarman\", words = [\"foo\",\"bar\"]\n\u8f93\u51fa\uff1a[0,9]\n\u89e3\u91ca\uff1a\n\u4ece\u7d22\u5f15 0 \u548c 9 \u5f00\u59cb\u7684\u5b50\u4e32\u5206\u522b\u662f \"barfoo\" \u548c \"foobar\" \u3002\n\u8f93\u51fa\u7684\u987a\u5e8f\u4e0d\u91cd\u8981, [9,0] \u4e5f\u662f\u6709\u6548\u7b54\u6848\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"wordgoodgoodgoodbestword\", words = [\"word\",\"good\",\"best\",\"word\"]\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"barfoofoobarthefoobarman\", words = [\"bar\",\"foo\",\"the\"]\n\u8f93\u51fa\uff1a[6,9,12]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 104
    • \n\t
    • s \u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n\t
    • 1 <= words.length <= 5000
    • \n\t
    • 1 <= words[i].length <= 30
    • \n\t
    • words[i]\u00a0\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n", "tags_en": ["Hash Table", "Two Pointers", "String"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u53cc\u6307\u9488", "\u5b57\u7b26\u4e32"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector findSubstring(string s, vector& words) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List findSubstring(String s, String[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findSubstring(self, s, words):\n \"\"\"\n :type s: str\n :type words: List[str]\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findSubstring(self, s: str, words: List[str]) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* findSubstring(char * s, char ** words, int wordsSize, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList FindSubstring(string s, string[] words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string[]} words\n * @return {number[]}\n */\nvar findSubstring = function(s, words) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String[]} words\n# @return {Integer[]}\ndef find_substring(s, words)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findSubstring(_ s: String, _ words: [String]) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findSubstring(s string, words []string) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findSubstring(s: String, words: Array[String]): List[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findSubstring(s: String, words: Array): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_substring(s: String, words: Vec) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String[] $words\n * @return Integer[]\n */\n function findSubstring($s, $words) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findSubstring(s: string, words: string[]): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-substring s words)\n (-> string? (listof string?) (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0030](https://leetcode-cn.com/problems/substring-with-concatenation-of-all-words)", "[\u4e32\u8054\u6240\u6709\u5355\u8bcd\u7684\u5b50\u4e32](/solution/0000-0099/0030.Substring%20with%20Concatenation%20of%20All%20Words/README.md)", "`\u54c8\u5e0c\u8868`,`\u53cc\u6307\u9488`,`\u5b57\u7b26\u4e32`", "\u56f0\u96be", ""], "md_table_row_en": ["[0030](https://leetcode.com/problems/substring-with-concatenation-of-all-words)", "[Substring with Concatenation of All Words](/solution/0000-0099/0030.Substring%20with%20Concatenation%20of%20All%20Words/README_EN.md)", "`Hash Table`,`Two Pointers`,`String`", "Hard", ""]}, {"question_id": "0029", "frontend_question_id": "0029", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/divide-two-integers", "url_en": "https://leetcode.com/problems/divide-two-integers", "relative_path_cn": "/solution/0000-0099/0029.Divide%20Two%20Integers/README.md", "relative_path_en": "/solution/0000-0099/0029.Divide%20Two%20Integers/README_EN.md", "title_cn": "\u4e24\u6570\u76f8\u9664", "title_en": "Divide Two Integers", "question_title_slug": "divide-two-integers", "content_en": "

    Given two integers dividend and divisor, divide two integers without using multiplication, division, and mod operator.

    \n\n

    Return the quotient after dividing dividend by divisor.

    \n\n

    The integer division should truncate toward zero, which means losing its fractional part. For example, truncate(8.345) = 8 and truncate(-2.7335) = -2.

    \n\n

    Note: Assume we are dealing with an environment that could only store integers within the 32-bit signed integer range: [−231, 231 − 1]. For this problem, assume that your function returns 231 − 1 when the division result overflows.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: dividend = 10, divisor = 3\nOutput: 3\nExplanation: 10/3 = truncate(3.33333..) = 3.\n
    \n\n

    Example 2:

    \n\n
    \nInput: dividend = 7, divisor = -3\nOutput: -2\nExplanation: 7/-3 = truncate(-2.33333..) = -2.\n
    \n\n

    Example 3:

    \n\n
    \nInput: dividend = 0, divisor = 1\nOutput: 0\n
    \n\n

    Example 4:

    \n\n
    \nInput: dividend = 1, divisor = 1\nOutput: 1\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • -231 <= dividend, divisor <= 231 - 1
    • \n\t
    • divisor != 0
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u6574\u6570\uff0c\u88ab\u9664\u6570 dividend \u548c\u9664\u6570 divisor\u3002\u5c06\u4e24\u6570\u76f8\u9664\uff0c\u8981\u6c42\u4e0d\u4f7f\u7528\u4e58\u6cd5\u3001\u9664\u6cd5\u548c mod \u8fd0\u7b97\u7b26\u3002

    \n\n

    \u8fd4\u56de\u88ab\u9664\u6570 dividend \u9664\u4ee5\u9664\u6570 divisor \u5f97\u5230\u7684\u5546\u3002

    \n\n

    \u6574\u6570\u9664\u6cd5\u7684\u7ed3\u679c\u5e94\u5f53\u622a\u53bb\uff08truncate\uff09\u5176\u5c0f\u6570\u90e8\u5206\uff0c\u4f8b\u5982\uff1atruncate(8.345) = 8 \u4ee5\u53ca truncate(-2.7335) = -2

    \n\n

     

    \n\n

    \u793a\u4f8b 1:

    \n\n
    \u8f93\u5165: dividend = 10, divisor = 3\n\u8f93\u51fa: 3\n\u89e3\u91ca: 10/3 = truncate(3.33333..) = truncate(3) = 3
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \u8f93\u5165: dividend = 7, divisor = -3\n\u8f93\u51fa: -2\n\u89e3\u91ca: 7/-3 = truncate(-2.33333..) = -2
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u88ab\u9664\u6570\u548c\u9664\u6570\u5747\u4e3a 32 \u4f4d\u6709\u7b26\u53f7\u6574\u6570\u3002
    • \n\t
    • \u9664\u6570\u4e0d\u4e3a 0\u3002
    • \n\t
    • \u5047\u8bbe\u6211\u4eec\u7684\u73af\u5883\u53ea\u80fd\u5b58\u50a8 32 \u4f4d\u6709\u7b26\u53f7\u6574\u6570\uff0c\u5176\u6570\u503c\u8303\u56f4\u662f [−231,  231 − 1]\u3002\u672c\u9898\u4e2d\uff0c\u5982\u679c\u9664\u6cd5\u7ed3\u679c\u6ea2\u51fa\uff0c\u5219\u8fd4\u56de 231 − 1\u3002
    • \n
    \n", "tags_en": ["Math", "Binary Search"], "tags_cn": ["\u6570\u5b66", "\u4e8c\u5206\u67e5\u627e"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int divide(int dividend, int divisor) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int divide(int dividend, int divisor) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def divide(self, dividend, divisor):\n \"\"\"\n :type dividend: int\n :type divisor: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def divide(self, dividend: int, divisor: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint divide(int dividend, int divisor){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int Divide(int dividend, int divisor) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} dividend\n * @param {number} divisor\n * @return {number}\n */\nvar divide = function(dividend, divisor) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} dividend\n# @param {Integer} divisor\n# @return {Integer}\ndef divide(dividend, divisor)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func divide(_ dividend: Int, _ divisor: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func divide(dividend int, divisor int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def divide(dividend: Int, divisor: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun divide(dividend: Int, divisor: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn divide(dividend: i32, divisor: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $dividend\n * @param Integer $divisor\n * @return Integer\n */\n function divide($dividend, $divisor) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function divide(dividend: number, divisor: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (divide dividend divisor)\n (-> exact-integer? exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0029](https://leetcode-cn.com/problems/divide-two-integers)", "[\u4e24\u6570\u76f8\u9664](/solution/0000-0099/0029.Divide%20Two%20Integers/README.md)", "`\u6570\u5b66`,`\u4e8c\u5206\u67e5\u627e`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0029](https://leetcode.com/problems/divide-two-integers)", "[Divide Two Integers](/solution/0000-0099/0029.Divide%20Two%20Integers/README_EN.md)", "`Math`,`Binary Search`", "Medium", ""]}, {"question_id": "0028", "frontend_question_id": "0028", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/implement-strstr", "url_en": "https://leetcode.com/problems/implement-strstr", "relative_path_cn": "/solution/0000-0099/0028.Implement%20strStr%28%29/README.md", "relative_path_en": "/solution/0000-0099/0028.Implement%20strStr%28%29/README_EN.md", "title_cn": "\u5b9e\u73b0 strStr()", "title_en": "Implement strStr()", "question_title_slug": "implement-strstr", "content_en": "

    Implement strStr().

    \n\n

    Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.

    \n\n

    Clarification:

    \n\n

    What should we return when needle is an empty string? This is a great question to ask during an interview.

    \n\n

    For the purpose of this problem, we will return 0 when needle is an empty string. This is consistent to C's strstr() and Java's indexOf().

    \n\n

     

    \n

    Example 1:

    \n
    Input: haystack = \"hello\", needle = \"ll\"\nOutput: 2\n

    Example 2:

    \n
    Input: haystack = \"aaaaa\", needle = \"bba\"\nOutput: -1\n

    Example 3:

    \n
    Input: haystack = \"\", needle = \"\"\nOutput: 0\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= haystack.length, needle.length <= 5 * 104
    • \n\t
    • haystack and needle consist of only lower-case English characters.
    • \n
    \n", "content_cn": "

    \u5b9e\u73b0\u00a0strStr()\u00a0\u51fd\u6570\u3002

    \n\n

    \u7ed9\u4f60\u4e24\u4e2a\u5b57\u7b26\u4e32\u00a0haystack \u548c needle \uff0c\u8bf7\u4f60\u5728 haystack \u5b57\u7b26\u4e32\u4e2d\u627e\u51fa needle \u5b57\u7b26\u4e32\u51fa\u73b0\u7684\u7b2c\u4e00\u4e2a\u4f4d\u7f6e\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\u3002\u5982\u679c\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u00a0 -1 \u3002

    \n\n

    \u00a0

    \n\n

    \u8bf4\u660e\uff1a

    \n\n

    \u5f53\u00a0needle\u00a0\u662f\u7a7a\u5b57\u7b26\u4e32\u65f6\uff0c\u6211\u4eec\u5e94\u5f53\u8fd4\u56de\u4ec0\u4e48\u503c\u5462\uff1f\u8fd9\u662f\u4e00\u4e2a\u5728\u9762\u8bd5\u4e2d\u5f88\u597d\u7684\u95ee\u9898\u3002

    \n\n

    \u5bf9\u4e8e\u672c\u9898\u800c\u8a00\uff0c\u5f53\u00a0needle\u00a0\u662f\u7a7a\u5b57\u7b26\u4e32\u65f6\u6211\u4eec\u5e94\u5f53\u8fd4\u56de 0 \u3002\u8fd9\u4e0e C \u8bed\u8a00\u7684\u00a0strstr()\u00a0\u4ee5\u53ca Java \u7684\u00a0indexOf()\u00a0\u5b9a\u4e49\u76f8\u7b26\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahaystack = \"hello\", needle = \"ll\"\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahaystack = \"aaaaa\", needle = \"bba\"\n\u8f93\u51fa\uff1a-1\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahaystack = \"\", needle = \"\"\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= haystack.length, needle.length <= 5 * 104
    • \n\t
    • haystack \u548c needle \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u7b26\u7ec4\u6210
    • \n
    \n", "tags_en": ["Two Pointers", "String"], "tags_cn": ["\u53cc\u6307\u9488", "\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int strStr(string haystack, string needle) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int strStr(String haystack, String needle) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def strStr(self, haystack, needle):\n \"\"\"\n :type haystack: str\n :type needle: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def strStr(self, haystack: str, needle: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint strStr(char * haystack, char * needle){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int StrStr(string haystack, string needle) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} haystack\n * @param {string} needle\n * @return {number}\n */\nvar strStr = function(haystack, needle) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} haystack\n# @param {String} needle\n# @return {Integer}\ndef str_str(haystack, needle)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func strStr(_ haystack: String, _ needle: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func strStr(haystack string, needle string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def strStr(haystack: String, needle: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun strStr(haystack: String, needle: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn str_str(haystack: String, needle: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $haystack\n * @param String $needle\n * @return Integer\n */\n function strStr($haystack, $needle) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function strStr(haystack: string, needle: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (str-str haystack needle)\n (-> string? string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0028](https://leetcode-cn.com/problems/implement-strstr)", "[\u5b9e\u73b0 strStr()](/solution/0000-0099/0028.Implement%20strStr%28%29/README.md)", "`\u53cc\u6307\u9488`,`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0028](https://leetcode.com/problems/implement-strstr)", "[Implement strStr()](/solution/0000-0099/0028.Implement%20strStr%28%29/README_EN.md)", "`Two Pointers`,`String`", "Easy", ""]}, {"question_id": "0027", "frontend_question_id": "0027", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/remove-element", "url_en": "https://leetcode.com/problems/remove-element", "relative_path_cn": "/solution/0000-0099/0027.Remove%20Element/README.md", "relative_path_en": "/solution/0000-0099/0027.Remove%20Element/README_EN.md", "title_cn": "\u79fb\u9664\u5143\u7d20", "title_en": "Remove Element", "question_title_slug": "remove-element", "content_en": "

    Given an array nums and a value val, remove all instances of that value in-place and return the new length.

    \n\n

    Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.

    \n\n

    The order of elements can be changed. It doesn't matter what you leave beyond the new length.

    \n\n

    Clarification:

    \n\n

    Confused why the returned value is an integer but your answer is an array?

    \n\n

    Note that the input array is passed in by reference, which means a modification to the input array will be known to the caller as well.

    \n\n

    Internally you can think of this:

    \n\n
    \n// nums is passed in by reference. (i.e., without making a copy)\nint len = removeElement(nums, val);\n\n// any modification to nums in your function would be known by the caller.\n// using the length returned by your function, it prints the first len elements.\nfor (int i = 0; i < len; i++) {\n    print(nums[i]);\n}
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [3,2,2,3], val = 3\nOutput: 2, nums = [2,2]\nExplanation: Your function should return length = 2, with the first two elements of nums being 2.\nIt doesn't matter what you leave beyond the returned length. For example if you return 2 with nums = [2,2,3,3] or nums = [2,2,0,0], your answer will be accepted.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [0,1,2,2,3,0,4,2], val = 2\nOutput: 5, nums = [0,1,4,0,3]\nExplanation: Your function should return length = 5, with the first five elements of nums containing 0, 1, 3, 0, and 4. Note that the order of those five elements can be arbitrary. It doesn't matter what values are set beyond the returned length.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= nums.length <= 100
    • \n\t
    • 0 <= nums[i] <= 50
    • \n\t
    • 0 <= val <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6570\u7ec4 nums\u00a0\u548c\u4e00\u4e2a\u503c val\uff0c\u4f60\u9700\u8981 \u539f\u5730 \u79fb\u9664\u6240\u6709\u6570\u503c\u7b49\u4e8e\u00a0val\u00a0\u7684\u5143\u7d20\uff0c\u5e76\u8fd4\u56de\u79fb\u9664\u540e\u6570\u7ec4\u7684\u65b0\u957f\u5ea6\u3002

    \n\n

    \u4e0d\u8981\u4f7f\u7528\u989d\u5916\u7684\u6570\u7ec4\u7a7a\u95f4\uff0c\u4f60\u5fc5\u987b\u4ec5\u4f7f\u7528 O(1) \u989d\u5916\u7a7a\u95f4\u5e76 \u539f\u5730 \u4fee\u6539\u8f93\u5165\u6570\u7ec4\u3002

    \n\n

    \u5143\u7d20\u7684\u987a\u5e8f\u53ef\u4ee5\u6539\u53d8\u3002\u4f60\u4e0d\u9700\u8981\u8003\u8651\u6570\u7ec4\u4e2d\u8d85\u51fa\u65b0\u957f\u5ea6\u540e\u9762\u7684\u5143\u7d20\u3002

    \n\n

    \u00a0

    \n\n

    \u8bf4\u660e:

    \n\n

    \u4e3a\u4ec0\u4e48\u8fd4\u56de\u6570\u503c\u662f\u6574\u6570\uff0c\u4f46\u8f93\u51fa\u7684\u7b54\u6848\u662f\u6570\u7ec4\u5462?

    \n\n

    \u8bf7\u6ce8\u610f\uff0c\u8f93\u5165\u6570\u7ec4\u662f\u4ee5\u300c\u5f15\u7528\u300d\u65b9\u5f0f\u4f20\u9012\u7684\uff0c\u8fd9\u610f\u5473\u7740\u5728\u51fd\u6570\u91cc\u4fee\u6539\u8f93\u5165\u6570\u7ec4\u5bf9\u4e8e\u8c03\u7528\u8005\u662f\u53ef\u89c1\u7684\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u60f3\u8c61\u5185\u90e8\u64cd\u4f5c\u5982\u4e0b:

    \n\n
    \n// nums \u662f\u4ee5\u201c\u5f15\u7528\u201d\u65b9\u5f0f\u4f20\u9012\u7684\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u4e0d\u5bf9\u5b9e\u53c2\u4f5c\u4efb\u4f55\u62f7\u8d1d\nint len = removeElement(nums, val);\n\n// \u5728\u51fd\u6570\u91cc\u4fee\u6539\u8f93\u5165\u6570\u7ec4\u5bf9\u4e8e\u8c03\u7528\u8005\u662f\u53ef\u89c1\u7684\u3002\n// \u6839\u636e\u4f60\u7684\u51fd\u6570\u8fd4\u56de\u7684\u957f\u5ea6, \u5b83\u4f1a\u6253\u5370\u51fa\u6570\u7ec4\u4e2d \u8be5\u957f\u5ea6\u8303\u56f4\u5185 \u7684\u6240\u6709\u5143\u7d20\u3002\nfor (int i = 0; i < len; i++) {\n\u00a0 \u00a0 print(nums[i]);\n}\n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [3,2,2,3], val = 3\n\u8f93\u51fa\uff1a2, nums = [2,2]\n\u89e3\u91ca\uff1a\u51fd\u6570\u5e94\u8be5\u8fd4\u56de\u65b0\u7684\u957f\u5ea6 2, \u5e76\u4e14 nums \u4e2d\u7684\u524d\u4e24\u4e2a\u5143\u7d20\u5747\u4e3a 2\u3002\u4f60\u4e0d\u9700\u8981\u8003\u8651\u6570\u7ec4\u4e2d\u8d85\u51fa\u65b0\u957f\u5ea6\u540e\u9762\u7684\u5143\u7d20\u3002\u4f8b\u5982\uff0c\u51fd\u6570\u8fd4\u56de\u7684\u65b0\u957f\u5ea6\u4e3a 2 \uff0c\u800c nums = [2,2,3,3] \u6216 nums = [2,2,0,0]\uff0c\u4e5f\u4f1a\u88ab\u89c6\u4f5c\u6b63\u786e\u7b54\u6848\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [0,1,2,2,3,0,4,2], val = 2\n\u8f93\u51fa\uff1a5, nums = [0,1,4,0,3]\n\u89e3\u91ca\uff1a\u51fd\u6570\u5e94\u8be5\u8fd4\u56de\u65b0\u7684\u957f\u5ea6 5, \u5e76\u4e14 nums \u4e2d\u7684\u524d\u4e94\u4e2a\u5143\u7d20\u4e3a 0, 1, 3, 0, 4\u3002\u6ce8\u610f\u8fd9\u4e94\u4e2a\u5143\u7d20\u53ef\u4e3a\u4efb\u610f\u987a\u5e8f\u3002\u4f60\u4e0d\u9700\u8981\u8003\u8651\u6570\u7ec4\u4e2d\u8d85\u51fa\u65b0\u957f\u5ea6\u540e\u9762\u7684\u5143\u7d20\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= nums.length <= 100
    • \n\t
    • 0 <= nums[i] <= 50
    • \n\t
    • 0 <= val <= 100
    • \n
    \n", "tags_en": ["Array", "Two Pointers"], "tags_cn": ["\u6570\u7ec4", "\u53cc\u6307\u9488"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int removeElement(vector& nums, int val) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int removeElement(int[] nums, int val) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def removeElement(self, nums, val):\n \"\"\"\n :type nums: List[int]\n :type val: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def removeElement(self, nums: List[int], val: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint removeElement(int* nums, int numsSize, int val){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int RemoveElement(int[] nums, int val) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} val\n * @return {number}\n */\nvar removeElement = function(nums, val) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} val\n# @return {Integer}\ndef remove_element(nums, val)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func removeElement(_ nums: inout [Int], _ val: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func removeElement(nums []int, val int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def removeElement(nums: Array[Int], `val`: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun removeElement(nums: IntArray, `val`: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn remove_element(nums: &mut Vec, val: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $val\n * @return Integer\n */\n function removeElement(&$nums, $val) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function removeElement(nums: number[], val: number): number {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0027](https://leetcode-cn.com/problems/remove-element)", "[\u79fb\u9664\u5143\u7d20](/solution/0000-0099/0027.Remove%20Element/README.md)", "`\u6570\u7ec4`,`\u53cc\u6307\u9488`", "\u7b80\u5355", ""], "md_table_row_en": ["[0027](https://leetcode.com/problems/remove-element)", "[Remove Element](/solution/0000-0099/0027.Remove%20Element/README_EN.md)", "`Array`,`Two Pointers`", "Easy", ""]}, {"question_id": "0026", "frontend_question_id": "0026", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array", "url_en": "https://leetcode.com/problems/remove-duplicates-from-sorted-array", "relative_path_cn": "/solution/0000-0099/0026.Remove%20Duplicates%20from%20Sorted%20Array/README.md", "relative_path_en": "/solution/0000-0099/0026.Remove%20Duplicates%20from%20Sorted%20Array/README_EN.md", "title_cn": "\u5220\u9664\u6709\u5e8f\u6570\u7ec4\u4e2d\u7684\u91cd\u590d\u9879", "title_en": "Remove Duplicates from Sorted Array", "question_title_slug": "remove-duplicates-from-sorted-array", "content_en": "

    Given a sorted array nums, remove the duplicates in-place such that each element appears only once and returns the new length.

    \n\n

    Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.

    \n\n

    Clarification:

    \n\n

    Confused why the returned value is an integer but your answer is an array?

    \n\n

    Note that the input array is passed in by reference, which means a modification to the input array will be known to the caller as well.

    \n\n

    Internally you can think of this:

    \n\n
    \n// nums is passed in by reference. (i.e., without making a copy)\nint len = removeDuplicates(nums);\n\n// any modification to nums in your function would be known by the caller.\n// using the length returned by your function, it prints the first len elements.\nfor (int i = 0; i < len; i++) {\n    print(nums[i]);\n}\n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,1,2]\nOutput: 2, nums = [1,2]\nExplanation: Your function should return length = 2, with the first two elements of nums being 1 and 2 respectively. It doesn't matter what you leave beyond the returned length.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [0,0,1,1,1,2,2,3,3,4]\nOutput: 5, nums = [0,1,2,3,4]\nExplanation: Your function should return length = 5, with the first five elements of nums being modified to 0, 1, 2, 3, and 4 respectively. It doesn't matter what values are set beyond the returned length.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= nums.length <= 3 * 104
    • \n\t
    • -104 <= nums[i] <= 104
    • \n\t
    • nums is sorted in ascending order.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6709\u5e8f\u6570\u7ec4 nums \uff0c\u8bf7\u4f60 \u539f\u5730 \u5220\u9664\u91cd\u590d\u51fa\u73b0\u7684\u5143\u7d20\uff0c\u4f7f\u6bcf\u4e2a\u5143\u7d20 \u53ea\u51fa\u73b0\u4e00\u6b21 \uff0c\u8fd4\u56de\u5220\u9664\u540e\u6570\u7ec4\u7684\u65b0\u957f\u5ea6\u3002

    \n\n

    \u4e0d\u8981\u4f7f\u7528\u989d\u5916\u7684\u6570\u7ec4\u7a7a\u95f4\uff0c\u4f60\u5fc5\u987b\u5728 \u539f\u5730 \u4fee\u6539\u8f93\u5165\u6570\u7ec4 \u5e76\u5728\u4f7f\u7528 O(1) \u989d\u5916\u7a7a\u95f4\u7684\u6761\u4ef6\u4e0b\u5b8c\u6210\u3002

    \n\n

    \u00a0

    \n\n

    \u8bf4\u660e:

    \n\n

    \u4e3a\u4ec0\u4e48\u8fd4\u56de\u6570\u503c\u662f\u6574\u6570\uff0c\u4f46\u8f93\u51fa\u7684\u7b54\u6848\u662f\u6570\u7ec4\u5462?

    \n\n

    \u8bf7\u6ce8\u610f\uff0c\u8f93\u5165\u6570\u7ec4\u662f\u4ee5\u300c\u5f15\u7528\u300d\u65b9\u5f0f\u4f20\u9012\u7684\uff0c\u8fd9\u610f\u5473\u7740\u5728\u51fd\u6570\u91cc\u4fee\u6539\u8f93\u5165\u6570\u7ec4\u5bf9\u4e8e\u8c03\u7528\u8005\u662f\u53ef\u89c1\u7684\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u60f3\u8c61\u5185\u90e8\u64cd\u4f5c\u5982\u4e0b:

    \n\n
    \n// nums \u662f\u4ee5\u201c\u5f15\u7528\u201d\u65b9\u5f0f\u4f20\u9012\u7684\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u4e0d\u5bf9\u5b9e\u53c2\u505a\u4efb\u4f55\u62f7\u8d1d\nint len = removeDuplicates(nums);\n\n// \u5728\u51fd\u6570\u91cc\u4fee\u6539\u8f93\u5165\u6570\u7ec4\u5bf9\u4e8e\u8c03\u7528\u8005\u662f\u53ef\u89c1\u7684\u3002\n// \u6839\u636e\u4f60\u7684\u51fd\u6570\u8fd4\u56de\u7684\u957f\u5ea6, \u5b83\u4f1a\u6253\u5370\u51fa\u6570\u7ec4\u4e2d \u8be5\u957f\u5ea6\u8303\u56f4\u5185 \u7684\u6240\u6709\u5143\u7d20\u3002\nfor (int i = 0; i < len; i++) {\n\u00a0 \u00a0 print(nums[i]);\n}\n
    \n\u00a0\n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,1,2]\n\u8f93\u51fa\uff1a2, nums = [1,2]\n\u89e3\u91ca\uff1a\u51fd\u6570\u5e94\u8be5\u8fd4\u56de\u65b0\u7684\u957f\u5ea6 2 \uff0c\u5e76\u4e14\u539f\u6570\u7ec4 nums \u7684\u524d\u4e24\u4e2a\u5143\u7d20\u88ab\u4fee\u6539\u4e3a 1, 2 \u3002\u4e0d\u9700\u8981\u8003\u8651\u6570\u7ec4\u4e2d\u8d85\u51fa\u65b0\u957f\u5ea6\u540e\u9762\u7684\u5143\u7d20\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [0,0,1,1,1,2,2,3,3,4]\n\u8f93\u51fa\uff1a5, nums = [0,1,2,3,4]\n\u89e3\u91ca\uff1a\u51fd\u6570\u5e94\u8be5\u8fd4\u56de\u65b0\u7684\u957f\u5ea6 5 \uff0c \u5e76\u4e14\u539f\u6570\u7ec4 nums \u7684\u524d\u4e94\u4e2a\u5143\u7d20\u88ab\u4fee\u6539\u4e3a 0, 1, 2, 3, 4 \u3002\u4e0d\u9700\u8981\u8003\u8651\u6570\u7ec4\u4e2d\u8d85\u51fa\u65b0\u957f\u5ea6\u540e\u9762\u7684\u5143\u7d20\u3002\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= nums.length <= 3 * 104
    • \n\t
    • -104 <= nums[i] <= 104
    • \n\t
    • nums \u5df2\u6309\u5347\u5e8f\u6392\u5217
    • \n
    \n\n

    \u00a0

    \n", "tags_en": ["Array", "Two Pointers"], "tags_cn": ["\u6570\u7ec4", "\u53cc\u6307\u9488"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int removeDuplicates(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int removeDuplicates(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def removeDuplicates(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def removeDuplicates(self, nums: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint removeDuplicates(int* nums, int numsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int RemoveDuplicates(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number}\n */\nvar removeDuplicates = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer}\ndef remove_duplicates(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func removeDuplicates(_ nums: inout [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func removeDuplicates(nums []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def removeDuplicates(nums: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun removeDuplicates(nums: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn remove_duplicates(nums: &mut Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer\n */\n function removeDuplicates(&$nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function removeDuplicates(nums: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0026](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array)", "[\u5220\u9664\u6709\u5e8f\u6570\u7ec4\u4e2d\u7684\u91cd\u590d\u9879](/solution/0000-0099/0026.Remove%20Duplicates%20from%20Sorted%20Array/README.md)", "`\u6570\u7ec4`,`\u53cc\u6307\u9488`", "\u7b80\u5355", ""], "md_table_row_en": ["[0026](https://leetcode.com/problems/remove-duplicates-from-sorted-array)", "[Remove Duplicates from Sorted Array](/solution/0000-0099/0026.Remove%20Duplicates%20from%20Sorted%20Array/README_EN.md)", "`Array`,`Two Pointers`", "Easy", ""]}, {"question_id": "0025", "frontend_question_id": "0025", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reverse-nodes-in-k-group", "url_en": "https://leetcode.com/problems/reverse-nodes-in-k-group", "relative_path_cn": "/solution/0000-0099/0025.Reverse%20Nodes%20in%20k-Group/README.md", "relative_path_en": "/solution/0000-0099/0025.Reverse%20Nodes%20in%20k-Group/README_EN.md", "title_cn": "K \u4e2a\u4e00\u7ec4\u7ffb\u8f6c\u94fe\u8868", "title_en": "Reverse Nodes in k-Group", "question_title_slug": "reverse-nodes-in-k-group", "content_en": "

    Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.

    \n\n

    k is a positive integer and is less than or equal to the length of the linked list. If the number of nodes is not a multiple of k then left-out nodes, in the end, should remain as it is.

    \n\n

    You may not alter the values in the list's nodes, only nodes themselves may be changed.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: head = [1,2,3,4,5], k = 2\nOutput: [2,1,4,3,5]\n
    \n\n

    Example 2:

    \n\"\"\n
    \nInput: head = [1,2,3,4,5], k = 3\nOutput: [3,2,1,4,5]\n
    \n\n

    Example 3:

    \n\n
    \nInput: head = [1,2,3,4,5], k = 1\nOutput: [1,2,3,4,5]\n
    \n\n

    Example 4:

    \n\n
    \nInput: head = [1], k = 1\nOutput: [1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the list is in the range sz.
    • \n\t
    • 1 <= sz <= 5000
    • \n\t
    • 0 <= Node.val <= 1000
    • \n\t
    • 1 <= k <= sz
    • \n
    \n\n

     

    \nFollow-up: Can you solve the problem in O(1) extra memory space?", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u94fe\u8868\uff0c\u6bcf\u00a0k\u00a0\u4e2a\u8282\u70b9\u4e00\u7ec4\u8fdb\u884c\u7ffb\u8f6c\uff0c\u8bf7\u4f60\u8fd4\u56de\u7ffb\u8f6c\u540e\u7684\u94fe\u8868\u3002

    \n\n

    k\u00a0\u662f\u4e00\u4e2a\u6b63\u6574\u6570\uff0c\u5b83\u7684\u503c\u5c0f\u4e8e\u6216\u7b49\u4e8e\u94fe\u8868\u7684\u957f\u5ea6\u3002

    \n\n

    \u5982\u679c\u8282\u70b9\u603b\u6570\u4e0d\u662f\u00a0k\u00a0\u7684\u6574\u6570\u500d\uff0c\u90a3\u4e48\u8bf7\u5c06\u6700\u540e\u5269\u4f59\u7684\u8282\u70b9\u4fdd\u6301\u539f\u6709\u987a\u5e8f\u3002

    \n\n

    \u8fdb\u9636\uff1a

    \n\n
      \n\t
    • \u4f60\u53ef\u4ee5\u8bbe\u8ba1\u4e00\u4e2a\u53ea\u4f7f\u7528\u5e38\u6570\u989d\u5916\u7a7a\u95f4\u7684\u7b97\u6cd5\u6765\u89e3\u51b3\u6b64\u95ee\u9898\u5417\uff1f
    • \n\t
    • \u4f60\u4e0d\u80fd\u53ea\u662f\u5355\u7eaf\u7684\u6539\u53d8\u8282\u70b9\u5185\u90e8\u7684\u503c\uff0c\u800c\u662f\u9700\u8981\u5b9e\u9645\u8fdb\u884c\u8282\u70b9\u4ea4\u6362\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1ahead = [1,2,3,4,5], k = 2\n\u8f93\u51fa\uff1a[2,1,4,3,5]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1ahead = [1,2,3,4,5], k = 3\n\u8f93\u51fa\uff1a[3,2,1,4,5]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahead = [1,2,3,4,5], k = 1\n\u8f93\u51fa\uff1a[1,2,3,4,5]\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahead = [1], k = 1\n\u8f93\u51fa\uff1a[1]\n
    \n\n
      \n
    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u5217\u8868\u4e2d\u8282\u70b9\u7684\u6570\u91cf\u5728\u8303\u56f4 sz \u5185
    • \n\t
    • 1 <= sz <= 5000
    • \n\t
    • 0 <= Node.val <= 1000
    • \n\t
    • 1 <= k <= sz
    • \n
    \n", "tags_en": ["Linked List"], "tags_cn": ["\u94fe\u8868"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n ListNode* reverseKGroup(ListNode* head, int k) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public ListNode reverseKGroup(ListNode head, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def reverseKGroup(self, head, k):\n \"\"\"\n :type head: ListNode\n :type k: int\n :rtype: ListNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def reverseKGroup(self, head: ListNode, k: int) -> ListNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nstruct ListNode* reverseKGroup(struct ListNode* head, int k){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public ListNode ReverseKGroup(ListNode head, int k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} head\n * @param {number} k\n * @return {ListNode}\n */\nvar reverseKGroup = function(head, k) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode} head\n# @param {Integer} k\n# @return {ListNode}\ndef reverse_k_group(head, k)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func reverseKGroup(_ head: ListNode?, _ k: Int) -> ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc reverseKGroup(head *ListNode, k int) *ListNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def reverseKGroup(head: ListNode, k: Int): ListNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun reverseKGroup(head: ListNode?, k: Int): ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn reverse_k_group(head: Option>, k: i32) -> Option> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @param Integer $k\n * @return ListNode\n */\n function reverseKGroup($head, $k) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction reverseKGroup(head: ListNode | null, k: number): ListNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (reverse-k-group head k)\n (-> (or/c list-node? #f) exact-integer? (or/c list-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0025](https://leetcode-cn.com/problems/reverse-nodes-in-k-group)", "[K \u4e2a\u4e00\u7ec4\u7ffb\u8f6c\u94fe\u8868](/solution/0000-0099/0025.Reverse%20Nodes%20in%20k-Group/README.md)", "`\u94fe\u8868`", "\u56f0\u96be", ""], "md_table_row_en": ["[0025](https://leetcode.com/problems/reverse-nodes-in-k-group)", "[Reverse Nodes in k-Group](/solution/0000-0099/0025.Reverse%20Nodes%20in%20k-Group/README_EN.md)", "`Linked List`", "Hard", ""]}, {"question_id": "0024", "frontend_question_id": "0024", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/swap-nodes-in-pairs", "url_en": "https://leetcode.com/problems/swap-nodes-in-pairs", "relative_path_cn": "/solution/0000-0099/0024.Swap%20Nodes%20in%20Pairs/README.md", "relative_path_en": "/solution/0000-0099/0024.Swap%20Nodes%20in%20Pairs/README_EN.md", "title_cn": "\u4e24\u4e24\u4ea4\u6362\u94fe\u8868\u4e2d\u7684\u8282\u70b9", "title_en": "Swap Nodes in Pairs", "question_title_slug": "swap-nodes-in-pairs", "content_en": "

    Given a linked list, swap every two adjacent nodes and return its head. You must solve the problem without modifying the values in the list's nodes (i.e., only nodes themselves may be changed.)

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: head = [1,2,3,4]\nOutput: [2,1,4,3]\n
    \n\n

    Example 2:

    \n\n
    \nInput: head = []\nOutput: []\n
    \n\n

    Example 3:

    \n\n
    \nInput: head = [1]\nOutput: [1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the list is in the range [0, 100].
    • \n\t
    • 0 <= Node.val <= 100
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u94fe\u8868\uff0c\u4e24\u4e24\u4ea4\u6362\u5176\u4e2d\u76f8\u90bb\u7684\u8282\u70b9\uff0c\u5e76\u8fd4\u56de\u4ea4\u6362\u540e\u7684\u94fe\u8868\u3002

    \n\n

    \u4f60\u4e0d\u80fd\u53ea\u662f\u5355\u7eaf\u7684\u6539\u53d8\u8282\u70b9\u5185\u90e8\u7684\u503c\uff0c\u800c\u662f\u9700\u8981\u5b9e\u9645\u7684\u8fdb\u884c\u8282\u70b9\u4ea4\u6362\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1ahead = [1,2,3,4]\n\u8f93\u51fa\uff1a[2,1,4,3]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahead = []\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahead = [1]\n\u8f93\u51fa\uff1a[1]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u94fe\u8868\u4e2d\u8282\u70b9\u7684\u6570\u76ee\u5728\u8303\u56f4 [0, 100] \u5185
    • \n\t
    • 0 <= Node.val <= 100
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u80fd\u5728\u4e0d\u4fee\u6539\u94fe\u8868\u8282\u70b9\u503c\u7684\u60c5\u51b5\u4e0b\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u5417?\uff08\u4e5f\u5c31\u662f\u8bf4\uff0c\u4ec5\u4fee\u6539\u8282\u70b9\u672c\u8eab\u3002\uff09

    \n", "tags_en": ["Recursion", "Linked List"], "tags_cn": ["\u9012\u5f52", "\u94fe\u8868"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n ListNode* swapPairs(ListNode* head) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public ListNode swapPairs(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def swapPairs(self, head):\n \"\"\"\n :type head: ListNode\n :rtype: ListNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def swapPairs(self, head: ListNode) -> ListNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nstruct ListNode* swapPairs(struct ListNode* head){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public ListNode SwapPairs(ListNode head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} head\n * @return {ListNode}\n */\nvar swapPairs = function(head) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode} head\n# @return {ListNode}\ndef swap_pairs(head)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func swapPairs(_ head: ListNode?) -> ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc swapPairs(head *ListNode) *ListNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def swapPairs(head: ListNode): ListNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun swapPairs(head: ListNode?): ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn swap_pairs(head: Option>) -> Option> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @return ListNode\n */\n function swapPairs($head) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction swapPairs(head: ListNode | null): ListNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (swap-pairs head)\n (-> (or/c list-node? #f) (or/c list-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0024](https://leetcode-cn.com/problems/swap-nodes-in-pairs)", "[\u4e24\u4e24\u4ea4\u6362\u94fe\u8868\u4e2d\u7684\u8282\u70b9](/solution/0000-0099/0024.Swap%20Nodes%20in%20Pairs/README.md)", "`\u9012\u5f52`,`\u94fe\u8868`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0024](https://leetcode.com/problems/swap-nodes-in-pairs)", "[Swap Nodes in Pairs](/solution/0000-0099/0024.Swap%20Nodes%20in%20Pairs/README_EN.md)", "`Recursion`,`Linked List`", "Medium", ""]}, {"question_id": "0023", "frontend_question_id": "0023", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/merge-k-sorted-lists", "url_en": "https://leetcode.com/problems/merge-k-sorted-lists", "relative_path_cn": "/solution/0000-0099/0023.Merge%20k%20Sorted%20Lists/README.md", "relative_path_en": "/solution/0000-0099/0023.Merge%20k%20Sorted%20Lists/README_EN.md", "title_cn": "\u5408\u5e76K\u4e2a\u5347\u5e8f\u94fe\u8868", "title_en": "Merge k Sorted Lists", "question_title_slug": "merge-k-sorted-lists", "content_en": "

    You are given an array of k linked-lists lists, each linked-list is sorted in ascending order.

    \n\n

    Merge all the linked-lists into one sorted linked-list and return it.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: lists = [[1,4,5],[1,3,4],[2,6]]\nOutput: [1,1,2,3,4,4,5,6]\nExplanation: The linked-lists are:\n[\n  1->4->5,\n  1->3->4,\n  2->6\n]\nmerging them into one sorted list:\n1->1->2->3->4->4->5->6\n
    \n\n

    Example 2:

    \n\n
    \nInput: lists = []\nOutput: []\n
    \n\n

    Example 3:

    \n\n
    \nInput: lists = [[]]\nOutput: []\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • k == lists.length
    • \n\t
    • 0 <= k <= 10^4
    • \n\t
    • 0 <= lists[i].length <= 500
    • \n\t
    • -10^4 <= lists[i][j] <= 10^4
    • \n\t
    • lists[i] is sorted in ascending order.
    • \n\t
    • The sum of lists[i].length won't exceed 10^4.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u94fe\u8868\u6570\u7ec4\uff0c\u6bcf\u4e2a\u94fe\u8868\u90fd\u5df2\u7ecf\u6309\u5347\u5e8f\u6392\u5217\u3002

    \n\n

    \u8bf7\u4f60\u5c06\u6240\u6709\u94fe\u8868\u5408\u5e76\u5230\u4e00\u4e2a\u5347\u5e8f\u94fe\u8868\u4e2d\uff0c\u8fd4\u56de\u5408\u5e76\u540e\u7684\u94fe\u8868\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \u8f93\u5165\uff1alists = [[1,4,5],[1,3,4],[2,6]]\n\u8f93\u51fa\uff1a[1,1,2,3,4,4,5,6]\n\u89e3\u91ca\uff1a\u94fe\u8868\u6570\u7ec4\u5982\u4e0b\uff1a\n[\n  1->4->5,\n  1->3->4,\n  2->6\n]\n\u5c06\u5b83\u4eec\u5408\u5e76\u5230\u4e00\u4e2a\u6709\u5e8f\u94fe\u8868\u4e2d\u5f97\u5230\u3002\n1->1->2->3->4->4->5->6\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \u8f93\u5165\uff1alists = []\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \u8f93\u5165\uff1alists = [[]]\n\u8f93\u51fa\uff1a[]\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • k == lists.length
    • \n\t
    • 0 <= k <= 10^4
    • \n\t
    • 0 <= lists[i].length <= 500
    • \n\t
    • -10^4 <= lists[i][j] <= 10^4
    • \n\t
    • lists[i] \u6309 \u5347\u5e8f \u6392\u5217
    • \n\t
    • lists[i].length \u7684\u603b\u548c\u4e0d\u8d85\u8fc7 10^4
    • \n
    \n", "tags_en": ["Heap", "Linked List", "Divide and Conquer"], "tags_cn": ["\u5806", "\u94fe\u8868", "\u5206\u6cbb\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n ListNode* mergeKLists(vector& lists) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public ListNode mergeKLists(ListNode[] lists) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def mergeKLists(self, lists):\n \"\"\"\n :type lists: List[ListNode]\n :rtype: ListNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def mergeKLists(self, lists: List[ListNode]) -> ListNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nstruct ListNode* mergeKLists(struct ListNode** lists, int listsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public ListNode MergeKLists(ListNode[] lists) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode[]} lists\n * @return {ListNode}\n */\nvar mergeKLists = function(lists) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode[]} lists\n# @return {ListNode}\ndef merge_k_lists(lists)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func mergeKLists(_ lists: [ListNode?]) -> ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc mergeKLists(lists []*ListNode) *ListNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def mergeKLists(lists: Array[ListNode]): ListNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun mergeKLists(lists: Array): ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn merge_k_lists(lists: Vec>>) -> Option> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode[] $lists\n * @return ListNode\n */\n function mergeKLists($lists) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction mergeKLists(lists: Array): ListNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (merge-k-lists lists)\n (-> (listof (or/c list-node? #f)) (or/c list-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0023](https://leetcode-cn.com/problems/merge-k-sorted-lists)", "[\u5408\u5e76K\u4e2a\u5347\u5e8f\u94fe\u8868](/solution/0000-0099/0023.Merge%20k%20Sorted%20Lists/README.md)", "`\u5806`,`\u94fe\u8868`,`\u5206\u6cbb\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[0023](https://leetcode.com/problems/merge-k-sorted-lists)", "[Merge k Sorted Lists](/solution/0000-0099/0023.Merge%20k%20Sorted%20Lists/README_EN.md)", "`Heap`,`Linked List`,`Divide and Conquer`", "Hard", ""]}, {"question_id": "0022", "frontend_question_id": "0022", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/generate-parentheses", "url_en": "https://leetcode.com/problems/generate-parentheses", "relative_path_cn": "/solution/0000-0099/0022.Generate%20Parentheses/README.md", "relative_path_en": "/solution/0000-0099/0022.Generate%20Parentheses/README_EN.md", "title_cn": "\u62ec\u53f7\u751f\u6210", "title_en": "Generate Parentheses", "question_title_slug": "generate-parentheses", "content_en": "

    Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.

    \n\n

     

    \n

    Example 1:

    \n
    Input: n = 3\nOutput: [\"((()))\",\"(()())\",\"(())()\",\"()(())\",\"()()()\"]\n

    Example 2:

    \n
    Input: n = 1\nOutput: [\"()\"]\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= n <= 8
    • \n
    \n", "content_cn": "

    \u6570\u5b57 n\u00a0\u4ee3\u8868\u751f\u6210\u62ec\u53f7\u7684\u5bf9\u6570\uff0c\u8bf7\u4f60\u8bbe\u8ba1\u4e00\u4e2a\u51fd\u6570\uff0c\u7528\u4e8e\u80fd\u591f\u751f\u6210\u6240\u6709\u53ef\u80fd\u7684\u5e76\u4e14 \u6709\u6548\u7684 \u62ec\u53f7\u7ec4\u5408\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 3\n\u8f93\u51fa\uff1a[\"((()))\",\"(()())\",\"(())()\",\"()(())\",\"()()()\"]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1an = 1\n\u8f93\u51fa\uff1a[\"()\"]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= n <= 8
    • \n
    \n", "tags_en": ["String", "Backtracking"], "tags_cn": ["\u5b57\u7b26\u4e32", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector generateParenthesis(int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List generateParenthesis(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def generateParenthesis(self, n):\n \"\"\"\n :type n: int\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def generateParenthesis(self, n: int) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** generateParenthesis(int n, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList GenerateParenthesis(int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} n\n * @return {string[]}\n */\nvar generateParenthesis = function(n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} n\n# @return {String[]}\ndef generate_parenthesis(n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func generateParenthesis(_ n: Int) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func generateParenthesis(n int) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def generateParenthesis(n: Int): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun generateParenthesis(n: Int): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn generate_parenthesis(n: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $n\n * @return String[]\n */\n function generateParenthesis($n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function generateParenthesis(n: number): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (generate-parenthesis n)\n (-> exact-integer? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0022](https://leetcode-cn.com/problems/generate-parentheses)", "[\u62ec\u53f7\u751f\u6210](/solution/0000-0099/0022.Generate%20Parentheses/README.md)", "`\u5b57\u7b26\u4e32`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0022](https://leetcode.com/problems/generate-parentheses)", "[Generate Parentheses](/solution/0000-0099/0022.Generate%20Parentheses/README_EN.md)", "`String`,`Backtracking`", "Medium", ""]}, {"question_id": "0021", "frontend_question_id": "0021", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/merge-two-sorted-lists", "url_en": "https://leetcode.com/problems/merge-two-sorted-lists", "relative_path_cn": "/solution/0000-0099/0021.Merge%20Two%20Sorted%20Lists/README.md", "relative_path_en": "/solution/0000-0099/0021.Merge%20Two%20Sorted%20Lists/README_EN.md", "title_cn": "\u5408\u5e76\u4e24\u4e2a\u6709\u5e8f\u94fe\u8868", "title_en": "Merge Two Sorted Lists", "question_title_slug": "merge-two-sorted-lists", "content_en": "

    Merge two sorted linked lists and return it as a sorted list. The list should be made by splicing together the nodes of the first two lists.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: l1 = [1,2,4], l2 = [1,3,4]\nOutput: [1,1,2,3,4,4]\n
    \n\n

    Example 2:

    \n\n
    \nInput: l1 = [], l2 = []\nOutput: []\n
    \n\n

    Example 3:

    \n\n
    \nInput: l1 = [], l2 = [0]\nOutput: [0]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in both lists is in the range [0, 50].
    • \n\t
    • -100 <= Node.val <= 100
    • \n\t
    • Both l1 and l2 are sorted in non-decreasing order.
    • \n
    \n", "content_cn": "

    \u5c06\u4e24\u4e2a\u5347\u5e8f\u94fe\u8868\u5408\u5e76\u4e3a\u4e00\u4e2a\u65b0\u7684 \u5347\u5e8f \u94fe\u8868\u5e76\u8fd4\u56de\u3002\u65b0\u94fe\u8868\u662f\u901a\u8fc7\u62fc\u63a5\u7ed9\u5b9a\u7684\u4e24\u4e2a\u94fe\u8868\u7684\u6240\u6709\u8282\u70b9\u7ec4\u6210\u7684\u3002\u00a0

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1al1 = [1,2,4], l2 = [1,3,4]\n\u8f93\u51fa\uff1a[1,1,2,3,4,4]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1al1 = [], l2 = []\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1al1 = [], l2 = [0]\n\u8f93\u51fa\uff1a[0]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u4e24\u4e2a\u94fe\u8868\u7684\u8282\u70b9\u6570\u76ee\u8303\u56f4\u662f [0, 50]
    • \n\t
    • -100 <= Node.val <= 100
    • \n\t
    • l1 \u548c l2 \u5747\u6309 \u975e\u9012\u51cf\u987a\u5e8f \u6392\u5217
    • \n
    \n", "tags_en": ["Recursion", "Linked List"], "tags_cn": ["\u9012\u5f52", "\u94fe\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public ListNode mergeTwoLists(ListNode l1, ListNode l2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def mergeTwoLists(self, l1, l2):\n \"\"\"\n :type l1: ListNode\n :type l2: ListNode\n :rtype: ListNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def mergeTwoLists(self, l1: ListNode, l2: ListNode) -> ListNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nstruct ListNode* mergeTwoLists(struct ListNode* l1, struct ListNode* l2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public ListNode MergeTwoLists(ListNode l1, ListNode l2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} l1\n * @param {ListNode} l2\n * @return {ListNode}\n */\nvar mergeTwoLists = function(l1, l2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode} l1\n# @param {ListNode} l2\n# @return {ListNode}\ndef merge_two_lists(l1, l2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func mergeTwoLists(_ l1: ListNode?, _ l2: ListNode?) -> ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc mergeTwoLists(l1 *ListNode, l2 *ListNode) *ListNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def mergeTwoLists(l1: ListNode, l2: ListNode): ListNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun mergeTwoLists(l1: ListNode?, l2: ListNode?): ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn merge_two_lists(l1: Option>, l2: Option>) -> Option> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $l1\n * @param ListNode $l2\n * @return ListNode\n */\n function mergeTwoLists($l1, $l2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction mergeTwoLists(l1: ListNode | null, l2: ListNode | null): ListNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (merge-two-lists l1 l2)\n (-> (or/c list-node? #f) (or/c list-node? #f) (or/c list-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0021](https://leetcode-cn.com/problems/merge-two-sorted-lists)", "[\u5408\u5e76\u4e24\u4e2a\u6709\u5e8f\u94fe\u8868](/solution/0000-0099/0021.Merge%20Two%20Sorted%20Lists/README.md)", "`\u9012\u5f52`,`\u94fe\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0021](https://leetcode.com/problems/merge-two-sorted-lists)", "[Merge Two Sorted Lists](/solution/0000-0099/0021.Merge%20Two%20Sorted%20Lists/README_EN.md)", "`Recursion`,`Linked List`", "Easy", ""]}, {"question_id": "0020", "frontend_question_id": "0020", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/valid-parentheses", "url_en": "https://leetcode.com/problems/valid-parentheses", "relative_path_cn": "/solution/0000-0099/0020.Valid%20Parentheses/README.md", "relative_path_en": "/solution/0000-0099/0020.Valid%20Parentheses/README_EN.md", "title_cn": "\u6709\u6548\u7684\u62ec\u53f7", "title_en": "Valid Parentheses", "question_title_slug": "valid-parentheses", "content_en": "

    Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.

    \n\n

    An input string is valid if:

    \n\n
      \n\t
    1. Open brackets must be closed by the same type of brackets.
    2. \n\t
    3. Open brackets must be closed in the correct order.
    4. \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "()"\nOutput: true\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "()[]{}"\nOutput: true\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "(]"\nOutput: false\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "([)]"\nOutput: false\n
    \n\n

    Example 5:

    \n\n
    \nInput: s = "{[]}"\nOutput: true\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 104
    • \n\t
    • s consists of parentheses only '()[]{}'.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u53ea\u5305\u62ec '('\uff0c')'\uff0c'{'\uff0c'}'\uff0c'['\uff0c']'\u00a0\u7684\u5b57\u7b26\u4e32 s \uff0c\u5224\u65ad\u5b57\u7b26\u4e32\u662f\u5426\u6709\u6548\u3002

    \n\n

    \u6709\u6548\u5b57\u7b26\u4e32\u9700\u6ee1\u8db3\uff1a

    \n\n
      \n\t
    1. \u5de6\u62ec\u53f7\u5fc5\u987b\u7528\u76f8\u540c\u7c7b\u578b\u7684\u53f3\u62ec\u53f7\u95ed\u5408\u3002
    2. \n\t
    3. \u5de6\u62ec\u53f7\u5fc5\u987b\u4ee5\u6b63\u786e\u7684\u987a\u5e8f\u95ed\u5408\u3002
    4. \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"()\"\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b\u00a02\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"()[]{}\"\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b\u00a03\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"(]\"\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b\u00a04\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"([)]\"\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u793a\u4f8b\u00a05\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"{[]}\"\n\u8f93\u51fa\uff1atrue
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 104
    • \n\t
    • s \u4ec5\u7531\u62ec\u53f7 '()[]{}' \u7ec4\u6210
    • \n
    \n", "tags_en": ["Stack", "String"], "tags_cn": ["\u6808", "\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isValid(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isValid(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isValid(self, s):\n \"\"\"\n :type s: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isValid(self, s: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isValid(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsValid(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {boolean}\n */\nvar isValid = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Boolean}\ndef is_valid(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isValid(_ s: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isValid(s string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isValid(s: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isValid(s: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_valid(s: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Boolean\n */\n function isValid($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isValid(s: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-valid s)\n (-> string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0020](https://leetcode-cn.com/problems/valid-parentheses)", "[\u6709\u6548\u7684\u62ec\u53f7](/solution/0000-0099/0020.Valid%20Parentheses/README.md)", "`\u6808`,`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0020](https://leetcode.com/problems/valid-parentheses)", "[Valid Parentheses](/solution/0000-0099/0020.Valid%20Parentheses/README_EN.md)", "`Stack`,`String`", "Easy", ""]}, {"question_id": "0019", "frontend_question_id": "0019", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list", "url_en": "https://leetcode.com/problems/remove-nth-node-from-end-of-list", "relative_path_cn": "/solution/0000-0099/0019.Remove%20Nth%20Node%20From%20End%20of%20List/README.md", "relative_path_en": "/solution/0000-0099/0019.Remove%20Nth%20Node%20From%20End%20of%20List/README_EN.md", "title_cn": "\u5220\u9664\u94fe\u8868\u7684\u5012\u6570\u7b2c N \u4e2a\u7ed3\u70b9", "title_en": "Remove Nth Node From End of List", "question_title_slug": "remove-nth-node-from-end-of-list", "content_en": "

    Given the head of a linked list, remove the nth node from the end of the list and return its head.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: head = [1,2,3,4,5], n = 2\nOutput: [1,2,3,5]\n
    \n\n

    Example 2:

    \n\n
    \nInput: head = [1], n = 1\nOutput: []\n
    \n\n

    Example 3:

    \n\n
    \nInput: head = [1,2], n = 1\nOutput: [1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in the list is sz.
    • \n\t
    • 1 <= sz <= 30
    • \n\t
    • 0 <= Node.val <= 100
    • \n\t
    • 1 <= n <= sz
    • \n
    \n\n

     

    \n

    Follow up: Could you do this in one pass?

    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u94fe\u8868\uff0c\u5220\u9664\u94fe\u8868\u7684\u5012\u6570\u7b2c\u00a0n\u00a0\u4e2a\u7ed3\u70b9\uff0c\u5e76\u4e14\u8fd4\u56de\u94fe\u8868\u7684\u5934\u7ed3\u70b9\u3002

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u80fd\u5c1d\u8bd5\u4f7f\u7528\u4e00\u8d9f\u626b\u63cf\u5b9e\u73b0\u5417\uff1f

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1ahead = [1,2,3,4,5], n = 2\n\u8f93\u51fa\uff1a[1,2,3,5]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahead = [1], n = 1\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1ahead = [1,2], n = 1\n\u8f93\u51fa\uff1a[1]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u94fe\u8868\u4e2d\u7ed3\u70b9\u7684\u6570\u76ee\u4e3a sz
    • \n\t
    • 1 <= sz <= 30
    • \n\t
    • 0 <= Node.val <= 100
    • \n\t
    • 1 <= n <= sz
    • \n
    \n", "tags_en": ["Linked List", "Two Pointers"], "tags_cn": ["\u94fe\u8868", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n ListNode* removeNthFromEnd(ListNode* head, int n) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public ListNode removeNthFromEnd(ListNode head, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def removeNthFromEnd(self, head, n):\n \"\"\"\n :type head: ListNode\n :type n: int\n :rtype: ListNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def removeNthFromEnd(self, head: ListNode, n: int) -> ListNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nstruct ListNode* removeNthFromEnd(struct ListNode* head, int n){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public ListNode RemoveNthFromEnd(ListNode head, int n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} head\n * @param {number} n\n * @return {ListNode}\n */\nvar removeNthFromEnd = function(head, n) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode} head\n# @param {Integer} n\n# @return {ListNode}\ndef remove_nth_from_end(head, n)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func removeNthFromEnd(_ head: ListNode?, _ n: Int) -> ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc removeNthFromEnd(head *ListNode, n int) *ListNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def removeNthFromEnd(head: ListNode, n: Int): ListNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun removeNthFromEnd(head: ListNode?, n: Int): ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn remove_nth_from_end(head: Option>, n: i32) -> Option> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $head\n * @param Integer $n\n * @return ListNode\n */\n function removeNthFromEnd($head, $n) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction removeNthFromEnd(head: ListNode | null, n: number): ListNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (remove-nth-from-end head n)\n (-> (or/c list-node? #f) exact-integer? (or/c list-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0019](https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list)", "[\u5220\u9664\u94fe\u8868\u7684\u5012\u6570\u7b2c N \u4e2a\u7ed3\u70b9](/solution/0000-0099/0019.Remove%20Nth%20Node%20From%20End%20of%20List/README.md)", "`\u94fe\u8868`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0019](https://leetcode.com/problems/remove-nth-node-from-end-of-list)", "[Remove Nth Node From End of List](/solution/0000-0099/0019.Remove%20Nth%20Node%20From%20End%20of%20List/README_EN.md)", "`Linked List`,`Two Pointers`", "Medium", ""]}, {"question_id": "0018", "frontend_question_id": "0018", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/4sum", "url_en": "https://leetcode.com/problems/4sum", "relative_path_cn": "/solution/0000-0099/0018.4Sum/README.md", "relative_path_en": "/solution/0000-0099/0018.4Sum/README_EN.md", "title_cn": "\u56db\u6570\u4e4b\u548c", "title_en": "4Sum", "question_title_slug": "4sum", "content_en": "

    Given an array nums of n integers, return an array of all the unique quadruplets [nums[a], nums[b], nums[c], nums[d]] such that:

    \n\n
      \n\t
    • 0 <= a, b, c, d < n
    • \n\t
    • a, b, c, and d are distinct.
    • \n\t
    • nums[a] + nums[b] + nums[c] + nums[d] == target
    • \n
    \n\n

    You may return the answer in any order.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [1,0,-1,0,-2,2], target = 0\nOutput: [[-2,-1,1,2],[-2,0,0,2],[-1,0,0,1]]\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [2,2,2,2,2], target = 8\nOutput: [[2,2,2,2]]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= nums.length <= 200
    • \n\t
    • -109 <= nums[i] <= 109
    • \n\t
    • -109 <= target <= 109
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5305\u542b\u00a0n \u4e2a\u6574\u6570\u7684\u6570\u7ec4\u00a0nums\u00a0\u548c\u4e00\u4e2a\u76ee\u6807\u503c\u00a0target\uff0c\u5224\u65ad\u00a0nums\u00a0\u4e2d\u662f\u5426\u5b58\u5728\u56db\u4e2a\u5143\u7d20 a\uff0cb\uff0cc\u00a0\u548c d\u00a0\uff0c\u4f7f\u5f97\u00a0a + b + c + d\u00a0\u7684\u503c\u4e0e\u00a0target\u00a0\u76f8\u7b49\uff1f\u627e\u51fa\u6240\u6709\u6ee1\u8db3\u6761\u4ef6\u4e14\u4e0d\u91cd\u590d\u7684\u56db\u5143\u7ec4\u3002

    \n\n

    \u6ce8\u610f\uff1a\u7b54\u6848\u4e2d\u4e0d\u53ef\u4ee5\u5305\u542b\u91cd\u590d\u7684\u56db\u5143\u7ec4\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [1,0,-1,0,-2,2], target = 0\n\u8f93\u51fa\uff1a[[-2,-1,1,2],[-2,0,0,2],[-1,0,0,1]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [], target = 0\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= nums.length <= 200
    • \n\t
    • -109 <= nums[i] <= 109
    • \n\t
    • -109 <= target <= 109
    • \n
    \n", "tags_en": ["Array", "Hash Table", "Two Pointers"], "tags_cn": ["\u6570\u7ec4", "\u54c8\u5e0c\u8868", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> fourSum(vector& nums, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> fourSum(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def fourSum(self, nums, target):\n \"\"\"\n :type nums: List[int]\n :type target: int\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def fourSum(self, nums: List[int], target: int) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** fourSum(int* nums, int numsSize, int target, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> FourSum(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} target\n * @return {number[][]}\n */\nvar fourSum = function(nums, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} target\n# @return {Integer[][]}\ndef four_sum(nums, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func fourSum(_ nums: [Int], _ target: Int) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func fourSum(nums []int, target int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def fourSum(nums: Array[Int], target: Int): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun fourSum(nums: IntArray, target: Int): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn four_sum(nums: Vec, target: i32) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $target\n * @return Integer[][]\n */\n function fourSum($nums, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function fourSum(nums: number[], target: number): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (four-sum nums target)\n (-> (listof exact-integer?) exact-integer? (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0018](https://leetcode-cn.com/problems/4sum)", "[\u56db\u6570\u4e4b\u548c](/solution/0000-0099/0018.4Sum/README.md)", "`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0018](https://leetcode.com/problems/4sum)", "[4Sum](/solution/0000-0099/0018.4Sum/README_EN.md)", "`Array`,`Hash Table`,`Two Pointers`", "Medium", ""]}, {"question_id": "0017", "frontend_question_id": "0017", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number", "url_en": "https://leetcode.com/problems/letter-combinations-of-a-phone-number", "relative_path_cn": "/solution/0000-0099/0017.Letter%20Combinations%20of%20a%20Phone%20Number/README.md", "relative_path_en": "/solution/0000-0099/0017.Letter%20Combinations%20of%20a%20Phone%20Number/README_EN.md", "title_cn": "\u7535\u8bdd\u53f7\u7801\u7684\u5b57\u6bcd\u7ec4\u5408", "title_en": "Letter Combinations of a Phone Number", "question_title_slug": "letter-combinations-of-a-phone-number", "content_en": "

    Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. Return the answer in any order.

    \n\n

    A mapping of digit to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters.

    \n\n

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: digits = "23"\nOutput: ["ad","ae","af","bd","be","bf","cd","ce","cf"]\n
    \n\n

    Example 2:

    \n\n
    \nInput: digits = ""\nOutput: []\n
    \n\n

    Example 3:

    \n\n
    \nInput: digits = "2"\nOutput: ["a","b","c"]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= digits.length <= 4
    • \n\t
    • digits[i] is a digit in the range ['2', '9'].
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u4ec5\u5305\u542b\u6570\u5b57\u00a02-9\u00a0\u7684\u5b57\u7b26\u4e32\uff0c\u8fd4\u56de\u6240\u6709\u5b83\u80fd\u8868\u793a\u7684\u5b57\u6bcd\u7ec4\u5408\u3002\u7b54\u6848\u53ef\u4ee5\u6309 \u4efb\u610f\u987a\u5e8f \u8fd4\u56de\u3002

    \n\n

    \u7ed9\u51fa\u6570\u5b57\u5230\u5b57\u6bcd\u7684\u6620\u5c04\u5982\u4e0b\uff08\u4e0e\u7535\u8bdd\u6309\u952e\u76f8\u540c\uff09\u3002\u6ce8\u610f 1 \u4e0d\u5bf9\u5e94\u4efb\u4f55\u5b57\u6bcd\u3002

    \n\n

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1adigits = \"23\"\n\u8f93\u51fa\uff1a[\"ad\",\"ae\",\"af\",\"bd\",\"be\",\"bf\",\"cd\",\"ce\",\"cf\"]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1adigits = \"\"\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1adigits = \"2\"\n\u8f93\u51fa\uff1a[\"a\",\"b\",\"c\"]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= digits.length <= 4
    • \n\t
    • digits[i] \u662f\u8303\u56f4 ['2', '9'] \u7684\u4e00\u4e2a\u6570\u5b57\u3002
    • \n
    \n", "tags_en": ["Depth-first Search", "Recursion", "String", "Backtracking"], "tags_cn": ["\u6df1\u5ea6\u4f18\u5148\u641c\u7d22", "\u9012\u5f52", "\u5b57\u7b26\u4e32", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector letterCombinations(string digits) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List letterCombinations(String digits) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def letterCombinations(self, digits):\n \"\"\"\n :type digits: str\n :rtype: List[str]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def letterCombinations(self, digits: str) -> List[str]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** letterCombinations(char * digits, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList LetterCombinations(string digits) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} digits\n * @return {string[]}\n */\nvar letterCombinations = function(digits) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} digits\n# @return {String[]}\ndef letter_combinations(digits)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func letterCombinations(_ digits: String) -> [String] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func letterCombinations(digits string) []string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def letterCombinations(digits: String): List[String] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun letterCombinations(digits: String): List {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn letter_combinations(digits: String) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $digits\n * @return String[]\n */\n function letterCombinations($digits) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function letterCombinations(digits: string): string[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (letter-combinations digits)\n (-> string? (listof string?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0017](https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number)", "[\u7535\u8bdd\u53f7\u7801\u7684\u5b57\u6bcd\u7ec4\u5408](/solution/0000-0099/0017.Letter%20Combinations%20of%20a%20Phone%20Number/README.md)", "`\u6df1\u5ea6\u4f18\u5148\u641c\u7d22`,`\u9012\u5f52`,`\u5b57\u7b26\u4e32`,`\u56de\u6eaf\u7b97\u6cd5`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0017](https://leetcode.com/problems/letter-combinations-of-a-phone-number)", "[Letter Combinations of a Phone Number](/solution/0000-0099/0017.Letter%20Combinations%20of%20a%20Phone%20Number/README_EN.md)", "`Depth-first Search`,`Recursion`,`String`,`Backtracking`", "Medium", ""]}, {"question_id": "0016", "frontend_question_id": "0016", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/3sum-closest", "url_en": "https://leetcode.com/problems/3sum-closest", "relative_path_cn": "/solution/0000-0099/0016.3Sum%20Closest/README.md", "relative_path_en": "/solution/0000-0099/0016.3Sum%20Closest/README_EN.md", "title_cn": "\u6700\u63a5\u8fd1\u7684\u4e09\u6570\u4e4b\u548c", "title_en": "3Sum Closest", "question_title_slug": "3sum-closest", "content_en": "

    Given an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume that each input would have exactly one solution.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [-1,2,1,-4], target = 1\nOutput: 2\nExplanation: The sum that is closest to the target is 2. (-1 + 2 + 1 = 2).\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 3 <= nums.length <= 10^3
    • \n\t
    • -10^3 <= nums[i] <= 10^3
    • \n\t
    • -10^4 <= target <= 10^4
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5305\u62ec n \u4e2a\u6574\u6570\u7684\u6570\u7ec4 nums \u548c \u4e00\u4e2a\u76ee\u6807\u503c target\u3002\u627e\u51fa nums \u4e2d\u7684\u4e09\u4e2a\u6574\u6570\uff0c\u4f7f\u5f97\u5b83\u4eec\u7684\u548c\u4e0e target \u6700\u63a5\u8fd1\u3002\u8fd4\u56de\u8fd9\u4e09\u4e2a\u6570\u7684\u548c\u3002\u5047\u5b9a\u6bcf\u7ec4\u8f93\u5165\u53ea\u5b58\u5728\u552f\u4e00\u7b54\u6848\u3002

    \n\n

     

    \n\n

    \u793a\u4f8b\uff1a

    \n\n
    \u8f93\u5165\uff1anums = [-1,2,1,-4], target = 1\n\u8f93\u51fa\uff1a2\n\u89e3\u91ca\uff1a\u4e0e target \u6700\u63a5\u8fd1\u7684\u548c\u662f 2 (-1 + 2 + 1 = 2) \u3002\n
    \n\n

     

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 3 <= nums.length <= 10^3
    • \n\t
    • -10^3 <= nums[i] <= 10^3
    • \n\t
    • -10^4 <= target <= 10^4
    • \n
    \n", "tags_en": ["Array", "Two Pointers"], "tags_cn": ["\u6570\u7ec4", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int threeSumClosest(vector& nums, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int threeSumClosest(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def threeSumClosest(self, nums, target):\n \"\"\"\n :type nums: List[int]\n :type target: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def threeSumClosest(self, nums: List[int], target: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint threeSumClosest(int* nums, int numsSize, int target){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int ThreeSumClosest(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} target\n * @return {number}\n */\nvar threeSumClosest = function(nums, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} target\n# @return {Integer}\ndef three_sum_closest(nums, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func threeSumClosest(_ nums: [Int], _ target: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func threeSumClosest(nums []int, target int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def threeSumClosest(nums: Array[Int], target: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun threeSumClosest(nums: IntArray, target: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn three_sum_closest(nums: Vec, target: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $target\n * @return Integer\n */\n function threeSumClosest($nums, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function threeSumClosest(nums: number[], target: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (three-sum-closest nums target)\n (-> (listof exact-integer?) exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0016](https://leetcode-cn.com/problems/3sum-closest)", "[\u6700\u63a5\u8fd1\u7684\u4e09\u6570\u4e4b\u548c](/solution/0000-0099/0016.3Sum%20Closest/README.md)", "`\u6570\u7ec4`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0016](https://leetcode.com/problems/3sum-closest)", "[3Sum Closest](/solution/0000-0099/0016.3Sum%20Closest/README_EN.md)", "`Array`,`Two Pointers`", "Medium", ""]}, {"question_id": "0015", "frontend_question_id": "0015", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/3sum", "url_en": "https://leetcode.com/problems/3sum", "relative_path_cn": "/solution/0000-0099/0015.3Sum/README.md", "relative_path_en": "/solution/0000-0099/0015.3Sum/README_EN.md", "title_cn": "\u4e09\u6570\u4e4b\u548c", "title_en": "3Sum", "question_title_slug": "3sum", "content_en": "

    Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0.

    \n\n

    Notice that the solution set must not contain duplicate triplets.

    \n\n

     

    \n

    Example 1:

    \n
    Input: nums = [-1,0,1,2,-1,-4]\nOutput: [[-1,-1,2],[-1,0,1]]\n

    Example 2:

    \n
    Input: nums = []\nOutput: []\n

    Example 3:

    \n
    Input: nums = [0]\nOutput: []\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= nums.length <= 3000
    • \n\t
    • -105 <= nums[i] <= 105
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5305\u542b n \u4e2a\u6574\u6570\u7684\u6570\u7ec4\u00a0nums\uff0c\u5224\u65ad\u00a0nums\u00a0\u4e2d\u662f\u5426\u5b58\u5728\u4e09\u4e2a\u5143\u7d20 a\uff0cb\uff0cc \uff0c\u4f7f\u5f97\u00a0a + b + c = 0 \uff1f\u8bf7\u4f60\u627e\u51fa\u6240\u6709\u548c\u4e3a 0 \u4e14\u4e0d\u91cd\u590d\u7684\u4e09\u5143\u7ec4\u3002

    \n\n

    \u6ce8\u610f\uff1a\u7b54\u6848\u4e2d\u4e0d\u53ef\u4ee5\u5305\u542b\u91cd\u590d\u7684\u4e09\u5143\u7ec4\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [-1,0,1,2,-1,-4]\n\u8f93\u51fa\uff1a[[-1,-1,2],[-1,0,1]]\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = []\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [0]\n\u8f93\u51fa\uff1a[]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= nums.length <= 3000
    • \n\t
    • -105 <= nums[i] <= 105
    • \n
    \n", "tags_en": ["Array", "Two Pointers"], "tags_cn": ["\u6570\u7ec4", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector> threeSum(vector& nums) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public List> threeSum(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def threeSum(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[List[int]]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def threeSum(self, nums: List[int]) -> List[List[int]]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Return an array of arrays of size *returnSize.\n * The sizes of the arrays are returned as *returnColumnSizes array.\n * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().\n */\nint** threeSum(int* nums, int numsSize, int* returnSize, int** returnColumnSizes){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public IList> ThreeSum(int[] nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @return {number[][]}\n */\nvar threeSum = function(nums) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @return {Integer[][]}\ndef three_sum(nums)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func threeSum(_ nums: [Int]) -> [[Int]] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func threeSum(nums []int) [][]int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def threeSum(nums: Array[Int]): List[List[Int]] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun threeSum(nums: IntArray): List> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn three_sum(nums: Vec) -> Vec> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @return Integer[][]\n */\n function threeSum($nums) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function threeSum(nums: number[]): number[][] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (three-sum nums)\n (-> (listof exact-integer?) (listof (listof exact-integer?)))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0015](https://leetcode-cn.com/problems/3sum)", "[\u4e09\u6570\u4e4b\u548c](/solution/0000-0099/0015.3Sum/README.md)", "`\u6570\u7ec4`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0015](https://leetcode.com/problems/3sum)", "[3Sum](/solution/0000-0099/0015.3Sum/README_EN.md)", "`Array`,`Two Pointers`", "Medium", ""]}, {"question_id": "0014", "frontend_question_id": "0014", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-common-prefix", "url_en": "https://leetcode.com/problems/longest-common-prefix", "relative_path_cn": "/solution/0000-0099/0014.Longest%20Common%20Prefix/README.md", "relative_path_en": "/solution/0000-0099/0014.Longest%20Common%20Prefix/README_EN.md", "title_cn": "\u6700\u957f\u516c\u5171\u524d\u7f00", "title_en": "Longest Common Prefix", "question_title_slug": "longest-common-prefix", "content_en": "

    Write a function to find the longest common prefix string amongst an array of strings.

    \n\n

    If there is no common prefix, return an empty string "".

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: strs = ["flower","flow","flight"]\nOutput: "fl"\n
    \n\n

    Example 2:

    \n\n
    \nInput: strs = ["dog","racecar","car"]\nOutput: ""\nExplanation: There is no common prefix among the input strings.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= strs.length <= 200
    • \n\t
    • 0 <= strs[i].length <= 200
    • \n\t
    • strs[i] consists of only lower-case English letters.
    • \n
    \n", "content_cn": "

    \u7f16\u5199\u4e00\u4e2a\u51fd\u6570\u6765\u67e5\u627e\u5b57\u7b26\u4e32\u6570\u7ec4\u4e2d\u7684\u6700\u957f\u516c\u5171\u524d\u7f00\u3002

    \n\n

    \u5982\u679c\u4e0d\u5b58\u5728\u516c\u5171\u524d\u7f00\uff0c\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32\u00a0\"\"\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1astrs = [\"flower\",\"flow\",\"flight\"]\n\u8f93\u51fa\uff1a\"fl\"\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1astrs = [\"dog\",\"racecar\",\"car\"]\n\u8f93\u51fa\uff1a\"\"\n\u89e3\u91ca\uff1a\u8f93\u5165\u4e0d\u5b58\u5728\u516c\u5171\u524d\u7f00\u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= strs.length <= 200
    • \n\t
    • 0 <= strs[i].length <= 200
    • \n\t
    • strs[i] \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string longestCommonPrefix(vector& strs) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String longestCommonPrefix(String[] strs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestCommonPrefix(self, strs):\n \"\"\"\n :type strs: List[str]\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestCommonPrefix(self, strs: List[str]) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * longestCommonPrefix(char ** strs, int strsSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string LongestCommonPrefix(string[] strs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string[]} strs\n * @return {string}\n */\nvar longestCommonPrefix = function(strs) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String[]} strs\n# @return {String}\ndef longest_common_prefix(strs)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestCommonPrefix(_ strs: [String]) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestCommonPrefix(strs []string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestCommonPrefix(strs: Array[String]): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestCommonPrefix(strs: Array): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_common_prefix(strs: Vec) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String[] $strs\n * @return String\n */\n function longestCommonPrefix($strs) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestCommonPrefix(strs: string[]): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-common-prefix strs)\n (-> (listof string?) string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0014](https://leetcode-cn.com/problems/longest-common-prefix)", "[\u6700\u957f\u516c\u5171\u524d\u7f00](/solution/0000-0099/0014.Longest%20Common%20Prefix/README.md)", "`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0014](https://leetcode.com/problems/longest-common-prefix)", "[Longest Common Prefix](/solution/0000-0099/0014.Longest%20Common%20Prefix/README_EN.md)", "`String`", "Easy", ""]}, {"question_id": "0013", "frontend_question_id": "0013", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/roman-to-integer", "url_en": "https://leetcode.com/problems/roman-to-integer", "relative_path_cn": "/solution/0000-0099/0013.Roman%20to%20Integer/README.md", "relative_path_en": "/solution/0000-0099/0013.Roman%20to%20Integer/README_EN.md", "title_cn": "\u7f57\u9a6c\u6570\u5b57\u8f6c\u6574\u6570", "title_en": "Roman to Integer", "question_title_slug": "roman-to-integer", "content_en": "

    Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.

    \n\n
    \nSymbol       Value\nI             1\nV             5\nX             10\nL             50\nC             100\nD             500\nM             1000
    \n\n

    For example, 2 is written as II in Roman numeral, just two one's added together. 12 is written as XII, which is simply X + II. The number 27 is written as XXVII, which is XX + V + II.

    \n\n

    Roman numerals are usually written largest to smallest from left to right. However, the numeral for four is not IIII. Instead, the number four is written as IV. Because the one is before the five we subtract it making four. The same principle applies to the number nine, which is written as IX. There are six instances where subtraction is used:

    \n\n
      \n\t
    • I can be placed before V (5) and X (10) to make 4 and 9. 
    • \n\t
    • X can be placed before L (50) and C (100) to make 40 and 90. 
    • \n\t
    • C can be placed before D (500) and M (1000) to make 400 and 900.
    • \n
    \n\n

    Given a roman numeral, convert it to an integer.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "III"\nOutput: 3\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "IV"\nOutput: 4\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "IX"\nOutput: 9\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "LVIII"\nOutput: 58\nExplanation: L = 50, V= 5, III = 3.\n
    \n\n

    Example 5:

    \n\n
    \nInput: s = "MCMXCIV"\nOutput: 1994\nExplanation: M = 1000, CM = 900, XC = 90 and IV = 4.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 15
    • \n\t
    • s contains only the characters ('I', 'V', 'X', 'L', 'C', 'D', 'M').
    • \n\t
    • It is guaranteed that s is a valid roman numeral in the range [1, 3999].
    • \n
    \n", "content_cn": "

    \u7f57\u9a6c\u6570\u5b57\u5305\u542b\u4ee5\u4e0b\u4e03\u79cd\u5b57\u7b26:\u00a0I\uff0c\u00a0V\uff0c\u00a0X\uff0c\u00a0L\uff0cC\uff0cD\u00a0\u548c\u00a0M\u3002

    \n\n
    \n\u5b57\u7b26          \u6570\u503c\nI             1\nV             5\nX             10\nL             50\nC             100\nD             500\nM             1000
    \n\n

    \u4f8b\u5982\uff0c \u7f57\u9a6c\u6570\u5b57 2 \u5199\u505a\u00a0II\u00a0\uff0c\u5373\u4e3a\u4e24\u4e2a\u5e76\u5217\u7684 1\u300212 \u5199\u505a\u00a0XII\u00a0\uff0c\u5373\u4e3a\u00a0X\u00a0+\u00a0II\u00a0\u3002 27 \u5199\u505a\u00a0\u00a0XXVII, \u5373\u4e3a\u00a0XX\u00a0+\u00a0V\u00a0+\u00a0II\u00a0\u3002

    \n\n

    \u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u7f57\u9a6c\u6570\u5b57\u4e2d\u5c0f\u7684\u6570\u5b57\u5728\u5927\u7684\u6570\u5b57\u7684\u53f3\u8fb9\u3002\u4f46\u4e5f\u5b58\u5728\u7279\u4f8b\uff0c\u4f8b\u5982 4 \u4e0d\u5199\u505a\u00a0IIII\uff0c\u800c\u662f\u00a0IV\u3002\u6570\u5b57 1 \u5728\u6570\u5b57 5 \u7684\u5de6\u8fb9\uff0c\u6240\u8868\u793a\u7684\u6570\u7b49\u4e8e\u5927\u6570 5 \u51cf\u5c0f\u6570 1 \u5f97\u5230\u7684\u6570\u503c 4 \u3002\u540c\u6837\u5730\uff0c\u6570\u5b57 9 \u8868\u793a\u4e3a\u00a0IX\u3002\u8fd9\u4e2a\u7279\u6b8a\u7684\u89c4\u5219\u53ea\u9002\u7528\u4e8e\u4ee5\u4e0b\u516d\u79cd\u60c5\u51b5\uff1a

    \n\n
      \n\t
    • I\u00a0\u53ef\u4ee5\u653e\u5728\u00a0V\u00a0(5) \u548c\u00a0X\u00a0(10) \u7684\u5de6\u8fb9\uff0c\u6765\u8868\u793a 4 \u548c 9\u3002
    • \n\t
    • X\u00a0\u53ef\u4ee5\u653e\u5728\u00a0L\u00a0(50) \u548c\u00a0C\u00a0(100) \u7684\u5de6\u8fb9\uff0c\u6765\u8868\u793a 40 \u548c\u00a090\u3002\u00a0
    • \n\t
    • C\u00a0\u53ef\u4ee5\u653e\u5728\u00a0D\u00a0(500) \u548c\u00a0M\u00a0(1000) \u7684\u5de6\u8fb9\uff0c\u6765\u8868\u793a\u00a0400 \u548c\u00a0900\u3002
    • \n
    \n\n

    \u7ed9\u5b9a\u4e00\u4e2a\u7f57\u9a6c\u6570\u5b57\uff0c\u5c06\u5176\u8f6c\u6362\u6210\u6574\u6570\u3002\u8f93\u5165\u786e\u4fdd\u5728 1\u00a0\u5230 3999 \u7684\u8303\u56f4\u5185\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\u00a01:

    \n\n
    \n\u8f93\u5165:\u00a0\"III\"\n\u8f93\u51fa: 3
    \n\n

    \u793a\u4f8b\u00a02:

    \n\n
    \n\u8f93\u5165:\u00a0\"IV\"\n\u8f93\u51fa: 4
    \n\n

    \u793a\u4f8b\u00a03:

    \n\n
    \n\u8f93\u5165:\u00a0\"IX\"\n\u8f93\u51fa: 9
    \n\n

    \u793a\u4f8b\u00a04:

    \n\n
    \n\u8f93\u5165:\u00a0\"LVIII\"\n\u8f93\u51fa: 58\n\u89e3\u91ca: L = 50, V= 5, III = 3.\n
    \n\n

    \u793a\u4f8b\u00a05:

    \n\n
    \n\u8f93\u5165:\u00a0\"MCMXCIV\"\n\u8f93\u51fa: 1994\n\u89e3\u91ca: M = 1000, CM = 900, XC = 90, IV = 4.
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 15
    • \n\t
    • s \u4ec5\u542b\u5b57\u7b26 ('I', 'V', 'X', 'L', 'C', 'D', 'M')
    • \n\t
    • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1 s \u662f\u4e00\u4e2a\u6709\u6548\u7684\u7f57\u9a6c\u6570\u5b57\uff0c\u4e14\u8868\u793a\u6574\u6570\u5728\u8303\u56f4 [1, 3999] \u5185
    • \n\t
    • \u9898\u76ee\u6240\u7ed9\u6d4b\u8bd5\u7528\u4f8b\u7686\u7b26\u5408\u7f57\u9a6c\u6570\u5b57\u4e66\u5199\u89c4\u5219\uff0c\u4e0d\u4f1a\u51fa\u73b0\u8de8\u4f4d\u7b49\u60c5\u51b5\u3002
    • \n\t
    • IL \u548c IM \u8fd9\u6837\u7684\u4f8b\u5b50\u5e76\u4e0d\u7b26\u5408\u9898\u76ee\u8981\u6c42\uff0c49 \u5e94\u8be5\u5199\u4f5c XLIX\uff0c999 \u5e94\u8be5\u5199\u4f5c CMXCIX \u3002
    • \n\t
    • \u5173\u4e8e\u7f57\u9a6c\u6570\u5b57\u7684\u8be6\u5c3d\u4e66\u5199\u89c4\u5219\uff0c\u53ef\u4ee5\u53c2\u8003 \u7f57\u9a6c\u6570\u5b57 - Mathematics \u3002
    • \n
    \n", "tags_en": ["Math", "String"], "tags_cn": ["\u6570\u5b66", "\u5b57\u7b26\u4e32"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int romanToInt(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int romanToInt(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def romanToInt(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def romanToInt(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint romanToInt(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int RomanToInt(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar romanToInt = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef roman_to_int(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func romanToInt(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func romanToInt(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def romanToInt(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun romanToInt(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn roman_to_int(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function romanToInt($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function romanToInt(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (roman-to-int s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0013](https://leetcode-cn.com/problems/roman-to-integer)", "[\u7f57\u9a6c\u6570\u5b57\u8f6c\u6574\u6570](/solution/0000-0099/0013.Roman%20to%20Integer/README.md)", "`\u6570\u5b66`,`\u5b57\u7b26\u4e32`", "\u7b80\u5355", ""], "md_table_row_en": ["[0013](https://leetcode.com/problems/roman-to-integer)", "[Roman to Integer](/solution/0000-0099/0013.Roman%20to%20Integer/README_EN.md)", "`Math`,`String`", "Easy", ""]}, {"question_id": "0012", "frontend_question_id": "0012", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/integer-to-roman", "url_en": "https://leetcode.com/problems/integer-to-roman", "relative_path_cn": "/solution/0000-0099/0012.Integer%20to%20Roman/README.md", "relative_path_en": "/solution/0000-0099/0012.Integer%20to%20Roman/README_EN.md", "title_cn": "\u6574\u6570\u8f6c\u7f57\u9a6c\u6570\u5b57", "title_en": "Integer to Roman", "question_title_slug": "integer-to-roman", "content_en": "

    Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.

    \n\n
    \nSymbol       Value\nI             1\nV             5\nX             10\nL             50\nC             100\nD             500\nM             1000
    \n\n

    For example, 2 is written as II in Roman numeral, just two one's added together. 12 is written as XII, which is simply X + II. The number 27 is written as XXVII, which is XX + V + II.

    \n\n

    Roman numerals are usually written largest to smallest from left to right. However, the numeral for four is not IIII. Instead, the number four is written as IV. Because the one is before the five we subtract it making four. The same principle applies to the number nine, which is written as IX. There are six instances where subtraction is used:

    \n\n
      \n\t
    • I can be placed before V (5) and X (10) to make 4 and 9. 
    • \n\t
    • X can be placed before L (50) and C (100) to make 40 and 90. 
    • \n\t
    • C can be placed before D (500) and M (1000) to make 400 and 900.
    • \n
    \n\n

    Given an integer, convert it to a roman numeral.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: num = 3\nOutput: "III"\n
    \n\n

    Example 2:

    \n\n
    \nInput: num = 4\nOutput: "IV"\n
    \n\n

    Example 3:

    \n\n
    \nInput: num = 9\nOutput: "IX"\n
    \n\n

    Example 4:

    \n\n
    \nInput: num = 58\nOutput: "LVIII"\nExplanation: L = 50, V = 5, III = 3.\n
    \n\n

    Example 5:

    \n\n
    \nInput: num = 1994\nOutput: "MCMXCIV"\nExplanation: M = 1000, CM = 900, XC = 90 and IV = 4.\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= num <= 3999
    • \n
    \n", "content_cn": "

    \u7f57\u9a6c\u6570\u5b57\u5305\u542b\u4ee5\u4e0b\u4e03\u79cd\u5b57\u7b26\uff1a\u00a0I\uff0c\u00a0V\uff0c\u00a0X\uff0c\u00a0L\uff0cC\uff0cD\u00a0\u548c\u00a0M\u3002

    \n\n
    \n\u5b57\u7b26          \u6570\u503c\nI             1\nV             5\nX             10\nL             50\nC             100\nD             500\nM             1000
    \n\n

    \u4f8b\u5982\uff0c \u7f57\u9a6c\u6570\u5b57 2 \u5199\u505a\u00a0II\u00a0\uff0c\u5373\u4e3a\u4e24\u4e2a\u5e76\u5217\u7684 1\u300212 \u5199\u505a\u00a0XII\u00a0\uff0c\u5373\u4e3a\u00a0X\u00a0+\u00a0II\u00a0\u3002 27 \u5199\u505a\u00a0\u00a0XXVII, \u5373\u4e3a\u00a0XX\u00a0+\u00a0V\u00a0+\u00a0II\u00a0\u3002

    \n\n

    \u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u7f57\u9a6c\u6570\u5b57\u4e2d\u5c0f\u7684\u6570\u5b57\u5728\u5927\u7684\u6570\u5b57\u7684\u53f3\u8fb9\u3002\u4f46\u4e5f\u5b58\u5728\u7279\u4f8b\uff0c\u4f8b\u5982 4 \u4e0d\u5199\u505a\u00a0IIII\uff0c\u800c\u662f\u00a0IV\u3002\u6570\u5b57 1 \u5728\u6570\u5b57 5 \u7684\u5de6\u8fb9\uff0c\u6240\u8868\u793a\u7684\u6570\u7b49\u4e8e\u5927\u6570 5 \u51cf\u5c0f\u6570 1 \u5f97\u5230\u7684\u6570\u503c 4 \u3002\u540c\u6837\u5730\uff0c\u6570\u5b57 9 \u8868\u793a\u4e3a\u00a0IX\u3002\u8fd9\u4e2a\u7279\u6b8a\u7684\u89c4\u5219\u53ea\u9002\u7528\u4e8e\u4ee5\u4e0b\u516d\u79cd\u60c5\u51b5\uff1a

    \n\n
      \n\t
    • I\u00a0\u53ef\u4ee5\u653e\u5728\u00a0V\u00a0(5) \u548c\u00a0X\u00a0(10) \u7684\u5de6\u8fb9\uff0c\u6765\u8868\u793a 4 \u548c 9\u3002
    • \n\t
    • X\u00a0\u53ef\u4ee5\u653e\u5728\u00a0L\u00a0(50) \u548c\u00a0C\u00a0(100) \u7684\u5de6\u8fb9\uff0c\u6765\u8868\u793a 40 \u548c\u00a090\u3002\u00a0
    • \n\t
    • C\u00a0\u53ef\u4ee5\u653e\u5728\u00a0D\u00a0(500) \u548c\u00a0M\u00a0(1000) \u7684\u5de6\u8fb9\uff0c\u6765\u8868\u793a\u00a0400 \u548c\u00a0900\u3002
    • \n
    \n\n

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\uff0c\u5c06\u5176\u8f6c\u4e3a\u7f57\u9a6c\u6570\u5b57\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\u00a01:

    \n\n
    \n\u8f93\u5165:\u00a0num = 3\n\u8f93\u51fa: \"III\"
    \n\n

    \u793a\u4f8b\u00a02:

    \n\n
    \n\u8f93\u5165:\u00a0num = 4\n\u8f93\u51fa: \"IV\"
    \n\n

    \u793a\u4f8b\u00a03:

    \n\n
    \n\u8f93\u5165:\u00a0num = 9\n\u8f93\u51fa: \"IX\"
    \n\n

    \u793a\u4f8b\u00a04:

    \n\n
    \n\u8f93\u5165:\u00a0num = 58\n\u8f93\u51fa: \"LVIII\"\n\u89e3\u91ca: L = 50, V = 5, III = 3.\n
    \n\n

    \u793a\u4f8b\u00a05:

    \n\n
    \n\u8f93\u5165:\u00a0num = 1994\n\u8f93\u51fa: \"MCMXCIV\"\n\u89e3\u91ca: M = 1000, CM = 900, XC = 90, IV = 4.
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= num <= 3999
    • \n
    \n", "tags_en": ["Math", "String"], "tags_cn": ["\u6570\u5b66", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string intToRoman(int num) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String intToRoman(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def intToRoman(self, num):\n \"\"\"\n :type num: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def intToRoman(self, num: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * intToRoman(int num){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string IntToRoman(int num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} num\n * @return {string}\n */\nvar intToRoman = function(num) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} num\n# @return {String}\ndef int_to_roman(num)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func intToRoman(_ num: Int) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func intToRoman(num int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def intToRoman(num: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun intToRoman(num: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn int_to_roman(num: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $num\n * @return String\n */\n function intToRoman($num) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function intToRoman(num: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (int-to-roman num)\n (-> exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0012](https://leetcode-cn.com/problems/integer-to-roman)", "[\u6574\u6570\u8f6c\u7f57\u9a6c\u6570\u5b57](/solution/0000-0099/0012.Integer%20to%20Roman/README.md)", "`\u6570\u5b66`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0012](https://leetcode.com/problems/integer-to-roman)", "[Integer to Roman](/solution/0000-0099/0012.Integer%20to%20Roman/README_EN.md)", "`Math`,`String`", "Medium", ""]}, {"question_id": "0011", "frontend_question_id": "0011", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/container-with-most-water", "url_en": "https://leetcode.com/problems/container-with-most-water", "relative_path_cn": "/solution/0000-0099/0011.Container%20With%20Most%20Water/README.md", "relative_path_en": "/solution/0000-0099/0011.Container%20With%20Most%20Water/README_EN.md", "title_cn": "\u76db\u6700\u591a\u6c34\u7684\u5bb9\u5668", "title_en": "Container With Most Water", "question_title_slug": "container-with-most-water", "content_en": "

    Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of the line i is at (i, ai) and (i, 0). Find two lines, which, together with the x-axis forms a container, such that the container contains the most water.

    \n\n

    Notice that you may not slant the container.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: height = [1,8,6,2,5,4,8,3,7]\nOutput: 49\nExplanation: The above vertical lines are represented by array [1,8,6,2,5,4,8,3,7]. In this case, the max area of water (blue section) the container can contain is 49.\n
    \n\n

    Example 2:

    \n\n
    \nInput: height = [1,1]\nOutput: 1\n
    \n\n

    Example 3:

    \n\n
    \nInput: height = [4,3,2,1,4]\nOutput: 16\n
    \n\n

    Example 4:

    \n\n
    \nInput: height = [1,2,1]\nOutput: 2\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • n == height.length
    • \n\t
    • 2 <= n <= 105
    • \n\t
    • 0 <= height[i] <= 104
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60 n \u4e2a\u975e\u8d1f\u6574\u6570 a1\uff0ca2\uff0c...\uff0can\uff0c\u6bcf\u4e2a\u6570\u4ee3\u8868\u5750\u6807\u4e2d\u7684\u4e00\u4e2a\u70b9\u00a0(i,\u00a0ai) \u3002\u5728\u5750\u6807\u5185\u753b n \u6761\u5782\u76f4\u7ebf\uff0c\u5782\u76f4\u7ebf i\u00a0\u7684\u4e24\u4e2a\u7aef\u70b9\u5206\u522b\u4e3a\u00a0(i,\u00a0ai) \u548c (i, 0) \u3002\u627e\u51fa\u5176\u4e2d\u7684\u4e24\u6761\u7ebf\uff0c\u4f7f\u5f97\u5b83\u4eec\u4e0e\u00a0x\u00a0\u8f74\u5171\u540c\u6784\u6210\u7684\u5bb9\u5668\u53ef\u4ee5\u5bb9\u7eb3\u6700\u591a\u7684\u6c34\u3002

    \n\n

    \u8bf4\u660e\uff1a\u4f60\u4e0d\u80fd\u503e\u659c\u5bb9\u5668\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n

    \"\"

    \n\n
    \n\u8f93\u5165\uff1a[1,8,6,2,5,4,8,3,7]\n\u8f93\u51fa\uff1a49 \n\u89e3\u91ca\uff1a\u56fe\u4e2d\u5782\u76f4\u7ebf\u4ee3\u8868\u8f93\u5165\u6570\u7ec4 [1,8,6,2,5,4,8,3,7]\u3002\u5728\u6b64\u60c5\u51b5\u4e0b\uff0c\u5bb9\u5668\u80fd\u591f\u5bb9\u7eb3\u6c34\uff08\u8868\u793a\u4e3a\u84dd\u8272\u90e8\u5206\uff09\u7684\u6700\u5927\u503c\u4e3a\u00a049\u3002
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1aheight = [1,1]\n\u8f93\u51fa\uff1a1\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1aheight = [4,3,2,1,4]\n\u8f93\u51fa\uff1a16\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1aheight = [1,2,1]\n\u8f93\u51fa\uff1a2\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • n = height.length
    • \n\t
    • 2 <= n <= 3 * 104
    • \n\t
    • 0 <= height[i] <= 3 * 104
    • \n
    \n", "tags_en": ["Array", "Two Pointers"], "tags_cn": ["\u6570\u7ec4", "\u53cc\u6307\u9488"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int maxArea(vector& height) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int maxArea(int[] height) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def maxArea(self, height):\n \"\"\"\n :type height: List[int]\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def maxArea(self, height: List[int]) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint maxArea(int* height, int heightSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MaxArea(int[] height) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} height\n * @return {number}\n */\nvar maxArea = function(height) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} height\n# @return {Integer}\ndef max_area(height)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func maxArea(_ height: [Int]) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func maxArea(height []int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def maxArea(height: Array[Int]): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun maxArea(height: IntArray): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn max_area(height: Vec) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $height\n * @return Integer\n */\n function maxArea($height) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function maxArea(height: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (max-area height)\n (-> (listof exact-integer?) exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0011](https://leetcode-cn.com/problems/container-with-most-water)", "[\u76db\u6700\u591a\u6c34\u7684\u5bb9\u5668](/solution/0000-0099/0011.Container%20With%20Most%20Water/README.md)", "`\u6570\u7ec4`,`\u53cc\u6307\u9488`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0011](https://leetcode.com/problems/container-with-most-water)", "[Container With Most Water](/solution/0000-0099/0011.Container%20With%20Most%20Water/README_EN.md)", "`Array`,`Two Pointers`", "Medium", ""]}, {"question_id": "0010", "frontend_question_id": "0010", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/regular-expression-matching", "url_en": "https://leetcode.com/problems/regular-expression-matching", "relative_path_cn": "/solution/0000-0099/0010.Regular%20Expression%20Matching/README.md", "relative_path_en": "/solution/0000-0099/0010.Regular%20Expression%20Matching/README_EN.md", "title_cn": "\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d", "title_en": "Regular Expression Matching", "question_title_slug": "regular-expression-matching", "content_en": "

    Given an input string (s) and a pattern (p), implement regular expression matching with support for '.' and '*' where: 

    \n\n
      \n\t
    • '.' Matches any single character.\u200b\u200b\u200b\u200b
    • \n\t
    • '*' Matches zero or more of the preceding element.
    • \n
    \n\n

    The matching should cover the entire input string (not partial).

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "aa", p = "a"\nOutput: false\nExplanation: "a" does not match the entire string "aa".\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "aa", p = "a*"\nOutput: true\nExplanation: '*' means zero or more of the preceding element, 'a'. Therefore, by repeating 'a' once, it becomes "aa".\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "ab", p = ".*"\nOutput: true\nExplanation: ".*" means "zero or more (*) of any character (.)".\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "aab", p = "c*a*b"\nOutput: true\nExplanation: c can be repeated 0 times, a can be repeated 1 time. Therefore, it matches "aab".\n
    \n\n

    Example 5:

    \n\n
    \nInput: s = "mississippi", p = "mis*is*p*."\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= s.length <= 20
    • \n\t
    • 0 <= p.length <= 30
    • \n\t
    • s contains only lowercase English letters.
    • \n\t
    • p contains only lowercase English letters, '.', and '*'.
    • \n\t
    • It is guaranteed for each appearance of the character '*', there will be a previous valid character to match.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32\u00a0s\u00a0\u548c\u4e00\u4e2a\u5b57\u7b26\u89c4\u5f8b\u00a0p\uff0c\u8bf7\u4f60\u6765\u5b9e\u73b0\u4e00\u4e2a\u652f\u6301 '.'\u00a0\u548c\u00a0'*'\u00a0\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d\u3002

    \n\n
      \n\t
    • '.' \u5339\u914d\u4efb\u610f\u5355\u4e2a\u5b57\u7b26
    • \n\t
    • '*' \u5339\u914d\u96f6\u4e2a\u6216\u591a\u4e2a\u524d\u9762\u7684\u90a3\u4e00\u4e2a\u5143\u7d20
    • \n
    \n\n

    \u6240\u8c13\u5339\u914d\uff0c\u662f\u8981\u6db5\u76d6\u00a0\u6574\u4e2a\u00a0\u5b57\u7b26\u4e32\u00a0s\u7684\uff0c\u800c\u4e0d\u662f\u90e8\u5206\u5b57\u7b26\u4e32\u3002

    \n\u00a0\n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"aa\" p = \"a\"\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\"a\" \u65e0\u6cd5\u5339\u914d \"aa\" \u6574\u4e2a\u5b57\u7b26\u4e32\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165\uff1as = \"aa\" p = \"a*\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u56e0\u4e3a '*' \u4ee3\u8868\u53ef\u4ee5\u5339\u914d\u96f6\u4e2a\u6216\u591a\u4e2a\u524d\u9762\u7684\u90a3\u4e00\u4e2a\u5143\u7d20, \u5728\u8fd9\u91cc\u524d\u9762\u7684\u5143\u7d20\u5c31\u662f 'a'\u3002\u56e0\u6b64\uff0c\u5b57\u7b26\u4e32 \"aa\" \u53ef\u88ab\u89c6\u4e3a 'a' \u91cd\u590d\u4e86\u4e00\u6b21\u3002\n
    \n\n

    \u793a\u4f8b\u00a03\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"ab\" p = \".*\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\".*\" \u8868\u793a\u53ef\u5339\u914d\u96f6\u4e2a\u6216\u591a\u4e2a\uff08'*'\uff09\u4efb\u610f\u5b57\u7b26\uff08'.'\uff09\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"aab\" p = \"c*a*b\"\n\u8f93\u51fa\uff1atrue\n\u89e3\u91ca\uff1a\u56e0\u4e3a '*' \u8868\u793a\u96f6\u4e2a\u6216\u591a\u4e2a\uff0c\u8fd9\u91cc 'c' \u4e3a 0 \u4e2a, 'a' \u88ab\u91cd\u590d\u4e00\u6b21\u3002\u56e0\u6b64\u53ef\u4ee5\u5339\u914d\u5b57\u7b26\u4e32 \"aab\"\u3002\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"mississippi\" p = \"mis*is*p*.\"\n\u8f93\u51fa\uff1afalse
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= s.length\u00a0<= 20
    • \n\t
    • 0 <= p.length\u00a0<= 30
    • \n\t
    • s\u00a0\u53ef\u80fd\u4e3a\u7a7a\uff0c\u4e14\u53ea\u5305\u542b\u4ece\u00a0a-z\u00a0\u7684\u5c0f\u5199\u5b57\u6bcd\u3002
    • \n\t
    • p\u00a0\u53ef\u80fd\u4e3a\u7a7a\uff0c\u4e14\u53ea\u5305\u542b\u4ece\u00a0a-z\u00a0\u7684\u5c0f\u5199\u5b57\u6bcd\uff0c\u4ee5\u53ca\u5b57\u7b26\u00a0.\u00a0\u548c\u00a0*\u3002
    • \n\t
    • \u4fdd\u8bc1\u6bcf\u6b21\u51fa\u73b0\u5b57\u7b26\u00a0* \u65f6\uff0c\u524d\u9762\u90fd\u5339\u914d\u5230\u6709\u6548\u7684\u5b57\u7b26
    • \n
    \n", "tags_en": ["String", "Dynamic Programming", "Backtracking"], "tags_cn": ["\u5b57\u7b26\u4e32", "\u52a8\u6001\u89c4\u5212", "\u56de\u6eaf\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isMatch(string s, string p) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isMatch(String s, String p) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isMatch(self, s, p):\n \"\"\"\n :type s: str\n :type p: str\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isMatch(self, s: str, p: str) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isMatch(char * s, char * p){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsMatch(string s, string p) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {string} p\n * @return {boolean}\n */\nvar isMatch = function(s, p) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {String} p\n# @return {Boolean}\ndef is_match(s, p)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isMatch(_ s: String, _ p: String) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isMatch(s string, p string) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isMatch(s: String, p: String): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isMatch(s: String, p: String): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_match(s: String, p: String) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param String $p\n * @return Boolean\n */\n function isMatch($s, $p) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isMatch(s: string, p: string): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-match s p)\n (-> string? string? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0010](https://leetcode-cn.com/problems/regular-expression-matching)", "[\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d](/solution/0000-0099/0010.Regular%20Expression%20Matching/README.md)", "`\u5b57\u7b26\u4e32`,`\u52a8\u6001\u89c4\u5212`,`\u56de\u6eaf\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[0010](https://leetcode.com/problems/regular-expression-matching)", "[Regular Expression Matching](/solution/0000-0099/0010.Regular%20Expression%20Matching/README_EN.md)", "`String`,`Dynamic Programming`,`Backtracking`", "Hard", ""]}, {"question_id": "0009", "frontend_question_id": "0009", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/palindrome-number", "url_en": "https://leetcode.com/problems/palindrome-number", "relative_path_cn": "/solution/0000-0099/0009.Palindrome%20Number/README.md", "relative_path_en": "/solution/0000-0099/0009.Palindrome%20Number/README_EN.md", "title_cn": "\u56de\u6587\u6570", "title_en": "Palindrome Number", "question_title_slug": "palindrome-number", "content_en": "

    Given an integer x, return true if x is palindrome integer.

    \n\n

    An integer is a palindrome when it reads the same backward as forward. For example, 121 is palindrome while 123 is not.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: x = 121\nOutput: true\n
    \n\n

    Example 2:

    \n\n
    \nInput: x = -121\nOutput: false\nExplanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.\n
    \n\n

    Example 3:

    \n\n
    \nInput: x = 10\nOutput: false\nExplanation: Reads 01 from right to left. Therefore it is not a palindrome.\n
    \n\n

    Example 4:

    \n\n
    \nInput: x = -101\nOutput: false\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • -231 <= x <= 231 - 1
    • \n
    \n\n

     

    \nFollow up: Could you solve it without converting the integer to a string?", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 x \uff0c\u5982\u679c x \u662f\u4e00\u4e2a\u56de\u6587\u6574\u6570\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002

    \n\n

    \u56de\u6587\u6570\u662f\u6307\u6b63\u5e8f\uff08\u4ece\u5de6\u5411\u53f3\uff09\u548c\u5012\u5e8f\uff08\u4ece\u53f3\u5411\u5de6\uff09\u8bfb\u90fd\u662f\u4e00\u6837\u7684\u6574\u6570\u3002\u4f8b\u5982\uff0c121 \u662f\u56de\u6587\uff0c\u800c 123 \u4e0d\u662f\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1ax = 121\n\u8f93\u51fa\uff1atrue\n
    \n\n

    \u793a\u4f8b\u00a02\uff1a

    \n\n
    \n\u8f93\u5165\uff1ax = -121\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u4ece\u5de6\u5411\u53f3\u8bfb, \u4e3a -121 \u3002 \u4ece\u53f3\u5411\u5de6\u8bfb, \u4e3a 121- \u3002\u56e0\u6b64\u5b83\u4e0d\u662f\u4e00\u4e2a\u56de\u6587\u6570\u3002\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1ax = 10\n\u8f93\u51fa\uff1afalse\n\u89e3\u91ca\uff1a\u4ece\u53f3\u5411\u5de6\u8bfb, \u4e3a 01 \u3002\u56e0\u6b64\u5b83\u4e0d\u662f\u4e00\u4e2a\u56de\u6587\u6570\u3002\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1ax = -101\n\u8f93\u51fa\uff1afalse\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • -231\u00a0<= x <= 231\u00a0- 1
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u80fd\u4e0d\u5c06\u6574\u6570\u8f6c\u4e3a\u5b57\u7b26\u4e32\u6765\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u5417\uff1f

    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n bool isPalindrome(int x) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public boolean isPalindrome(int x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def isPalindrome(self, x):\n \"\"\"\n :type x: int\n :rtype: bool\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def isPalindrome(self, x: int) -> bool:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nbool isPalindrome(int x){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public bool IsPalindrome(int x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} x\n * @return {boolean}\n */\nvar isPalindrome = function(x) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} x\n# @return {Boolean}\ndef is_palindrome(x)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func isPalindrome(_ x: Int) -> Bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func isPalindrome(x int) bool {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def isPalindrome(x: Int): Boolean = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun isPalindrome(x: Int): Boolean {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn is_palindrome(x: i32) -> bool {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $x\n * @return Boolean\n */\n function isPalindrome($x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function isPalindrome(x: number): boolean {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (is-palindrome x)\n (-> exact-integer? boolean?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0009](https://leetcode-cn.com/problems/palindrome-number)", "[\u56de\u6587\u6570](/solution/0000-0099/0009.Palindrome%20Number/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0009](https://leetcode.com/problems/palindrome-number)", "[Palindrome Number](/solution/0000-0099/0009.Palindrome%20Number/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "0008", "frontend_question_id": "0008", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/string-to-integer-atoi", "url_en": "https://leetcode.com/problems/string-to-integer-atoi", "relative_path_cn": "/solution/0000-0099/0008.String%20to%20Integer%20%28atoi%29/README.md", "relative_path_en": "/solution/0000-0099/0008.String%20to%20Integer%20%28atoi%29/README_EN.md", "title_cn": "\u5b57\u7b26\u4e32\u8f6c\u6362\u6574\u6570 (atoi)", "title_en": "String to Integer (atoi)", "question_title_slug": "string-to-integer-atoi", "content_en": "

    Implement the myAtoi(string s) function, which converts a string to a 32-bit signed integer (similar to C/C++'s atoi function).

    \n\n

    The algorithm for myAtoi(string s) is as follows:

    \n\n
      \n\t
    1. Read in and ignore any leading whitespace.
    2. \n\t
    3. Check if the next character (if not already at the end of the string) is '-' or '+'. Read this character in if it is either. This determines if the final result is negative or positive respectively. Assume the result is positive if neither is present.
    4. \n\t
    5. Read in next the characters until the next non-digit charcter or the end of the input is reached. The rest of the string is ignored.
    6. \n\t
    7. Convert these digits into an integer (i.e. "123" -> 123, "0032" -> 32). If no digits were read, then the integer is 0. Change the sign as necessary (from step 2).
    8. \n\t
    9. If the integer is out of the 32-bit signed integer range [-231, 231 - 1], then clamp the integer so that it remains in the range. Specifically, integers less than -231 should be clamped to -231, and integers greater than 231 - 1 should be clamped to 231 - 1.
    10. \n\t
    11. Return the integer as the final result.
    12. \n
    \n\n

    Note:

    \n\n
      \n\t
    • Only the space character ' ' is considered a whitespace character.
    • \n\t
    • Do not ignore any characters other than the leading whitespace or the rest of the string after the digits.
    • \n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "42"\nOutput: 42\nExplanation: The underlined characters are what is read in, the caret is the current reader position.\nStep 1: "42" (no characters read because there is no leading whitespace)\n         ^\nStep 2: "42" (no characters read because there is neither a '-' nor '+')\n         ^\nStep 3: "42" ("42" is read in)\n           ^\nThe parsed integer is 42.\nSince 42 is in the range [-231, 231 - 1], the final result is 42.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "   -42"\nOutput: -42\nExplanation:\nStep 1: "   -42" (leading whitespace is read and ignored)\n            ^\nStep 2: "   -42" ('-' is read, so the result should be negative)\n             ^\nStep 3: "   -42" ("42" is read in)\n               ^\nThe parsed integer is -42.\nSince -42 is in the range [-231, 231 - 1], the final result is -42.\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "4193 with words"\nOutput: 4193\nExplanation:\nStep 1: "4193 with words" (no characters read because there is no leading whitespace)\n         ^\nStep 2: "4193 with words" (no characters read because there is neither a '-' nor '+')\n         ^\nStep 3: "4193 with words" ("4193" is read in; reading stops because the next character is a non-digit)\n             ^\nThe parsed integer is 4193.\nSince 4193 is in the range [-231, 231 - 1], the final result is 4193.\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "words and 987"\nOutput: 0\nExplanation:\nStep 1: "words and 987" (no characters read because there is no leading whitespace)\n         ^\nStep 2: "words and 987" (no characters read because there is neither a '-' nor '+')\n         ^\nStep 3: "words and 987" (reading stops immediately because there is a non-digit 'w')\n         ^\nThe parsed integer is 0 because no digits were read.\nSince 0 is in the range [-231, 231 - 1], the final result is 0.\n
    \n\n

    Example 5:

    \n\n
    \nInput: s = "-91283472332"\nOutput: -2147483648\nExplanation:\nStep 1: "-91283472332" (no characters read because there is no leading whitespace)\n         ^\nStep 2: "-91283472332" ('-' is read, so the result should be negative)\n          ^\nStep 3: "-91283472332" ("91283472332" is read in)\n                     ^\nThe parsed integer is -91283472332.\nSince -91283472332 is less than the lower bound of the range [-231, 231 - 1], the final result is clamped to -231 = -2147483648. \n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= s.length <= 200
    • \n\t
    • s consists of English letters (lower-case and upper-case), digits (0-9), ' ', '+', '-', and '.'.
    • \n
    \n", "content_cn": "

    \u8bf7\u4f60\u6765\u5b9e\u73b0\u4e00\u4e2a\u00a0myAtoi(string s)\u00a0\u51fd\u6570\uff0c\u4f7f\u5176\u80fd\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u6210\u4e00\u4e2a 32 \u4f4d\u6709\u7b26\u53f7\u6574\u6570\uff08\u7c7b\u4f3c C/C++ \u4e2d\u7684 atoi \u51fd\u6570\uff09\u3002

    \n\n

    \u51fd\u6570\u00a0myAtoi(string s) \u7684\u7b97\u6cd5\u5982\u4e0b\uff1a

    \n\n
      \n\t
    • \u8bfb\u5165\u5b57\u7b26\u4e32\u5e76\u4e22\u5f03\u65e0\u7528\u7684\u524d\u5bfc\u7a7a\u683c
    • \n\t
    • \u68c0\u67e5\u4e0b\u4e00\u4e2a\u5b57\u7b26\uff08\u5047\u8bbe\u8fd8\u672a\u5230\u5b57\u7b26\u672b\u5c3e\uff09\u4e3a\u6b63\u8fd8\u662f\u8d1f\u53f7\uff0c\u8bfb\u53d6\u8be5\u5b57\u7b26\uff08\u5982\u679c\u6709\uff09\u3002 \u786e\u5b9a\u6700\u7ec8\u7ed3\u679c\u662f\u8d1f\u6570\u8fd8\u662f\u6b63\u6570\u3002 \u5982\u679c\u4e24\u8005\u90fd\u4e0d\u5b58\u5728\uff0c\u5219\u5047\u5b9a\u7ed3\u679c\u4e3a\u6b63\u3002
    • \n\t
    • \u8bfb\u5165\u4e0b\u4e00\u4e2a\u5b57\u7b26\uff0c\u76f4\u5230\u5230\u8fbe\u4e0b\u4e00\u4e2a\u975e\u6570\u5b57\u5b57\u7b26\u6216\u5230\u8fbe\u8f93\u5165\u7684\u7ed3\u5c3e\u3002\u5b57\u7b26\u4e32\u7684\u5176\u4f59\u90e8\u5206\u5c06\u88ab\u5ffd\u7565\u3002
    • \n\t
    • \u5c06\u524d\u9762\u6b65\u9aa4\u8bfb\u5165\u7684\u8fd9\u4e9b\u6570\u5b57\u8f6c\u6362\u4e3a\u6574\u6570\uff08\u5373\uff0c\"123\" -> 123\uff0c \"0032\" -> 32\uff09\u3002\u5982\u679c\u6ca1\u6709\u8bfb\u5165\u6570\u5b57\uff0c\u5219\u6574\u6570\u4e3a 0 \u3002\u5fc5\u8981\u65f6\u66f4\u6539\u7b26\u53f7\uff08\u4ece\u6b65\u9aa4 2 \u5f00\u59cb\uff09\u3002
    • \n\t
    • \u5982\u679c\u6574\u6570\u6570\u8d85\u8fc7 32 \u4f4d\u6709\u7b26\u53f7\u6574\u6570\u8303\u56f4 [\u2212231,\u00a0 231\u00a0\u2212 1] \uff0c\u9700\u8981\u622a\u65ad\u8fd9\u4e2a\u6574\u6570\uff0c\u4f7f\u5176\u4fdd\u6301\u5728\u8fd9\u4e2a\u8303\u56f4\u5185\u3002\u5177\u4f53\u6765\u8bf4\uff0c\u5c0f\u4e8e \u2212231 \u7684\u6574\u6570\u5e94\u8be5\u88ab\u56fa\u5b9a\u4e3a \u2212231 \uff0c\u5927\u4e8e 231\u00a0\u2212 1 \u7684\u6574\u6570\u5e94\u8be5\u88ab\u56fa\u5b9a\u4e3a 231\u00a0\u2212 1 \u3002
    • \n\t
    • \u8fd4\u56de\u6574\u6570\u4f5c\u4e3a\u6700\u7ec8\u7ed3\u679c\u3002
    • \n
    \n\n

    \u6ce8\u610f\uff1a

    \n\n
      \n\t
    • \u672c\u9898\u4e2d\u7684\u7a7a\u767d\u5b57\u7b26\u53ea\u5305\u62ec\u7a7a\u683c\u5b57\u7b26 ' ' \u3002
    • \n\t
    • \u9664\u524d\u5bfc\u7a7a\u683c\u6216\u6570\u5b57\u540e\u7684\u5176\u4f59\u5b57\u7b26\u4e32\u5916\uff0c\u8bf7\u52ff\u5ffd\u7565 \u4efb\u4f55\u5176\u4ed6\u5b57\u7b26\u3002
    • \n
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\u00a01\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"42\"\n\u8f93\u51fa\uff1a42\n\u89e3\u91ca\uff1a\u52a0\u7c97\u7684\u5b57\u7b26\u4e32\u4e3a\u5df2\u7ecf\u8bfb\u5165\u7684\u5b57\u7b26\uff0c\u63d2\u5165\u7b26\u53f7\u662f\u5f53\u524d\u8bfb\u53d6\u7684\u5b57\u7b26\u3002\n\u7b2c 1 \u6b65\uff1a\"42\"\uff08\u5f53\u524d\u6ca1\u6709\u8bfb\u5165\u5b57\u7b26\uff0c\u56e0\u4e3a\u6ca1\u6709\u524d\u5bfc\u7a7a\u683c\uff09\n         ^\n\u7b2c 2 \u6b65\uff1a\"42\"\uff08\u5f53\u524d\u6ca1\u6709\u8bfb\u5165\u5b57\u7b26\uff0c\u56e0\u4e3a\u8fd9\u91cc\u4e0d\u5b58\u5728 '-' \u6216\u8005 '+'\uff09\n         ^\n\u7b2c 3 \u6b65\uff1a\"42\"\uff08\u8bfb\u5165 \"42\"\uff09\n           ^\n\u89e3\u6790\u5f97\u5230\u6574\u6570 42 \u3002\n\u7531\u4e8e \"42\" \u5728\u8303\u56f4 [-231, 231 - 1] \u5185\uff0c\u6700\u7ec8\u7ed3\u679c\u4e3a 42 \u3002
    \n\n

    \u793a\u4f8b\u00a02\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"   -42\"\n\u8f93\u51fa\uff1a-42\n\u89e3\u91ca\uff1a\n\u7b2c 1 \u6b65\uff1a\"   -42\"\uff08\u8bfb\u5165\u524d\u5bfc\u7a7a\u683c\uff0c\u4f46\u5ffd\u89c6\u6389\uff09\n            ^\n\u7b2c 2 \u6b65\uff1a\"   -42\"\uff08\u8bfb\u5165 '-' \u5b57\u7b26\uff0c\u6240\u4ee5\u7ed3\u679c\u5e94\u8be5\u662f\u8d1f\u6570\uff09\n             ^\n\u7b2c 3 \u6b65\uff1a\"   -42\"\uff08\u8bfb\u5165 \"42\"\uff09\n               ^\n\u89e3\u6790\u5f97\u5230\u6574\u6570 -42 \u3002\n\u7531\u4e8e \"-42\" \u5728\u8303\u56f4 [-231, 231 - 1] \u5185\uff0c\u6700\u7ec8\u7ed3\u679c\u4e3a -42 \u3002\n
    \n\n

    \u793a\u4f8b\u00a03\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"4193 with words\"\n\u8f93\u51fa\uff1a4193\n\u89e3\u91ca\uff1a\n\u7b2c 1 \u6b65\uff1a\"4193 with words\"\uff08\u5f53\u524d\u6ca1\u6709\u8bfb\u5165\u5b57\u7b26\uff0c\u56e0\u4e3a\u6ca1\u6709\u524d\u5bfc\u7a7a\u683c\uff09\n         ^\n\u7b2c 2 \u6b65\uff1a\"4193 with words\"\uff08\u5f53\u524d\u6ca1\u6709\u8bfb\u5165\u5b57\u7b26\uff0c\u56e0\u4e3a\u8fd9\u91cc\u4e0d\u5b58\u5728 '-' \u6216\u8005 '+'\uff09\n         ^\n\u7b2c 3 \u6b65\uff1a\"4193 with words\"\uff08\u8bfb\u5165 \"4193\"\uff1b\u7531\u4e8e\u4e0b\u4e00\u4e2a\u5b57\u7b26\u4e0d\u662f\u4e00\u4e2a\u6570\u5b57\uff0c\u6240\u4ee5\u8bfb\u5165\u505c\u6b62\uff09\n             ^\n\u89e3\u6790\u5f97\u5230\u6574\u6570 4193 \u3002\n\u7531\u4e8e \"4193\" \u5728\u8303\u56f4 [-231, 231 - 1] \u5185\uff0c\u6700\u7ec8\u7ed3\u679c\u4e3a 4193 \u3002\n
    \n\n

    \u793a\u4f8b\u00a04\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"words and 987\"\n\u8f93\u51fa\uff1a0\n\u89e3\u91ca\uff1a\n\u7b2c 1 \u6b65\uff1a\"words and 987\"\uff08\u5f53\u524d\u6ca1\u6709\u8bfb\u5165\u5b57\u7b26\uff0c\u56e0\u4e3a\u6ca1\u6709\u524d\u5bfc\u7a7a\u683c\uff09\n         ^\n\u7b2c 2 \u6b65\uff1a\"words and 987\"\uff08\u5f53\u524d\u6ca1\u6709\u8bfb\u5165\u5b57\u7b26\uff0c\u56e0\u4e3a\u8fd9\u91cc\u4e0d\u5b58\u5728 '-' \u6216\u8005 '+'\uff09\n         ^\n\u7b2c 3 \u6b65\uff1a\"words and 987\"\uff08\u7531\u4e8e\u5f53\u524d\u5b57\u7b26 'w' \u4e0d\u662f\u4e00\u4e2a\u6570\u5b57\uff0c\u6240\u4ee5\u8bfb\u5165\u505c\u6b62\uff09\n         ^\n\u89e3\u6790\u5f97\u5230\u6574\u6570 0 \uff0c\u56e0\u4e3a\u6ca1\u6709\u8bfb\u5165\u4efb\u4f55\u6570\u5b57\u3002\n\u7531\u4e8e 0 \u5728\u8303\u56f4 [-231, 231 - 1] \u5185\uff0c\u6700\u7ec8\u7ed3\u679c\u4e3a 0 \u3002
    \n\n

    \u793a\u4f8b\u00a05\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"-91283472332\"\n\u8f93\u51fa\uff1a-2147483648\n\u89e3\u91ca\uff1a\n\u7b2c 1 \u6b65\uff1a\"-91283472332\"\uff08\u5f53\u524d\u6ca1\u6709\u8bfb\u5165\u5b57\u7b26\uff0c\u56e0\u4e3a\u6ca1\u6709\u524d\u5bfc\u7a7a\u683c\uff09\n         ^\n\u7b2c 2 \u6b65\uff1a\"-91283472332\"\uff08\u8bfb\u5165 '-' \u5b57\u7b26\uff0c\u6240\u4ee5\u7ed3\u679c\u5e94\u8be5\u662f\u8d1f\u6570\uff09\n          ^\n\u7b2c 3 \u6b65\uff1a\"-91283472332\"\uff08\u8bfb\u5165 \"91283472332\"\uff09\n                     ^\n\u89e3\u6790\u5f97\u5230\u6574\u6570 -91283472332 \u3002\n\u7531\u4e8e -91283472332 \u5c0f\u4e8e\u8303\u56f4 [-231, 231 - 1] \u7684\u4e0b\u754c\uff0c\u6700\u7ec8\u7ed3\u679c\u88ab\u622a\u65ad\u4e3a -231 = -2147483648 \u3002
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= s.length <= 200
    • \n\t
    • s \u7531\u82f1\u6587\u5b57\u6bcd\uff08\u5927\u5199\u548c\u5c0f\u5199\uff09\u3001\u6570\u5b57\uff080-9\uff09\u3001' '\u3001'+'\u3001'-' \u548c '.' \u7ec4\u6210
    • \n
    \n", "tags_en": ["Math", "String"], "tags_cn": ["\u6570\u5b66", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int myAtoi(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int myAtoi(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def myAtoi(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def myAtoi(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint myAtoi(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int MyAtoi(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar myAtoi = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef my_atoi(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func myAtoi(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func myAtoi(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def myAtoi(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun myAtoi(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn my_atoi(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function myAtoi($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function myAtoi(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (my-atoi s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0008](https://leetcode-cn.com/problems/string-to-integer-atoi)", "[\u5b57\u7b26\u4e32\u8f6c\u6362\u6574\u6570 (atoi)](/solution/0000-0099/0008.String%20to%20Integer%20%28atoi%29/README.md)", "`\u6570\u5b66`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0008](https://leetcode.com/problems/string-to-integer-atoi)", "[String to Integer (atoi)](/solution/0000-0099/0008.String%20to%20Integer%20%28atoi%29/README_EN.md)", "`Math`,`String`", "Medium", ""]}, {"question_id": "0007", "frontend_question_id": "0007", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/reverse-integer", "url_en": "https://leetcode.com/problems/reverse-integer", "relative_path_cn": "/solution/0000-0099/0007.Reverse%20Integer/README.md", "relative_path_en": "/solution/0000-0099/0007.Reverse%20Integer/README_EN.md", "title_cn": "\u6574\u6570\u53cd\u8f6c", "title_en": "Reverse Integer", "question_title_slug": "reverse-integer", "content_en": "

    Given a signed 32-bit integer x, return x with its digits reversed. If reversing x causes the value to go outside the signed 32-bit integer range [-231, 231 - 1], then return 0.

    \n\n

    Assume the environment does not allow you to store 64-bit integers (signed or unsigned).

    \n\n

     

    \n

    Example 1:

    \n
    Input: x = 123\nOutput: 321\n

    Example 2:

    \n
    Input: x = -123\nOutput: -321\n

    Example 3:

    \n
    Input: x = 120\nOutput: 21\n

    Example 4:

    \n
    Input: x = 0\nOutput: 0\n
    \n

     

    \n

    Constraints:

    \n\n
      \n\t
    • -231 <= x <= 231 - 1
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a 32 \u4f4d\u7684\u6709\u7b26\u53f7\u6574\u6570 x \uff0c\u8fd4\u56de\u5c06 x \u4e2d\u7684\u6570\u5b57\u90e8\u5206\u53cd\u8f6c\u540e\u7684\u7ed3\u679c\u3002

    \n\n

    \u5982\u679c\u53cd\u8f6c\u540e\u6574\u6570\u8d85\u8fc7 32 \u4f4d\u7684\u6709\u7b26\u53f7\u6574\u6570\u7684\u8303\u56f4\u00a0[\u2212231,\u00a0 231\u00a0\u2212 1] \uff0c\u5c31\u8fd4\u56de 0\u3002

    \n\u5047\u8bbe\u73af\u5883\u4e0d\u5141\u8bb8\u5b58\u50a8 64 \u4f4d\u6574\u6570\uff08\u6709\u7b26\u53f7\u6216\u65e0\u7b26\u53f7\uff09\u3002\n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1ax = 123\n\u8f93\u51fa\uff1a321\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1ax = -123\n\u8f93\u51fa\uff1a-321\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1ax = 120\n\u8f93\u51fa\uff1a21\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1ax = 0\n\u8f93\u51fa\uff1a0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • -231 <= x <= 231 - 1
    • \n
    \n", "tags_en": ["Math"], "tags_cn": ["\u6570\u5b66"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int reverse(int x) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int reverse(int x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def reverse(self, x):\n \"\"\"\n :type x: int\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def reverse(self, x: int) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint reverse(int x){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int Reverse(int x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number} x\n * @return {number}\n */\nvar reverse = function(x) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer} x\n# @return {Integer}\ndef reverse(x)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func reverse(_ x: Int) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func reverse(x int) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def reverse(x: Int): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun reverse(x: Int): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn reverse(x: i32) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer $x\n * @return Integer\n */\n function reverse($x) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function reverse(x: number): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (reverse x)\n (-> exact-integer? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0007](https://leetcode-cn.com/problems/reverse-integer)", "[\u6574\u6570\u53cd\u8f6c](/solution/0000-0099/0007.Reverse%20Integer/README.md)", "`\u6570\u5b66`", "\u7b80\u5355", ""], "md_table_row_en": ["[0007](https://leetcode.com/problems/reverse-integer)", "[Reverse Integer](/solution/0000-0099/0007.Reverse%20Integer/README_EN.md)", "`Math`", "Easy", ""]}, {"question_id": "0006", "frontend_question_id": "0006", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/zigzag-conversion", "url_en": "https://leetcode.com/problems/zigzag-conversion", "relative_path_cn": "/solution/0000-0099/0006.ZigZag%20Conversion/README.md", "relative_path_en": "/solution/0000-0099/0006.ZigZag%20Conversion/README_EN.md", "title_cn": "Z \u5b57\u5f62\u53d8\u6362", "title_en": "ZigZag Conversion", "question_title_slug": "zigzag-conversion", "content_en": "

    The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)

    \n\n
    \nP   A   H   N\nA P L S I I G\nY   I   R\n
    \n\n

    And then read line by line: "PAHNAPLSIIGYIR"

    \n\n

    Write the code that will take a string and make this conversion given a number of rows:

    \n\n
    \nstring convert(string s, int numRows);\n
    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "PAYPALISHIRING", numRows = 3\nOutput: "PAHNAPLSIIGYIR"\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "PAYPALISHIRING", numRows = 4\nOutput: "PINALSIGYAHRPI"\nExplanation:\nP     I    N\nA   L S  I G\nY A   H R\nP     I\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "A", numRows = 1\nOutput: "A"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 1000
    • \n\t
    • s consists of English letters (lower-case and upper-case), ',' and '.'.
    • \n\t
    • 1 <= numRows <= 1000
    • \n
    \n", "content_cn": "

    \u5c06\u4e00\u4e2a\u7ed9\u5b9a\u5b57\u7b26\u4e32 s \u6839\u636e\u7ed9\u5b9a\u7684\u884c\u6570 numRows \uff0c\u4ee5\u4ece\u4e0a\u5f80\u4e0b\u3001\u4ece\u5de6\u5230\u53f3\u8fdb\u884c\u00a0Z \u5b57\u5f62\u6392\u5217\u3002

    \n\n

    \u6bd4\u5982\u8f93\u5165\u5b57\u7b26\u4e32\u4e3a \"PAYPALISHIRING\"\u00a0\u884c\u6570\u4e3a 3 \u65f6\uff0c\u6392\u5217\u5982\u4e0b\uff1a

    \n\n
    \nP   A   H   N\nA P L S I I G\nY   I   R
    \n\n

    \u4e4b\u540e\uff0c\u4f60\u7684\u8f93\u51fa\u9700\u8981\u4ece\u5de6\u5f80\u53f3\u9010\u884c\u8bfb\u53d6\uff0c\u4ea7\u751f\u51fa\u4e00\u4e2a\u65b0\u7684\u5b57\u7b26\u4e32\uff0c\u6bd4\u5982\uff1a\"PAHNAPLSIIGYIR\"\u3002

    \n\n

    \u8bf7\u4f60\u5b9e\u73b0\u8fd9\u4e2a\u5c06\u5b57\u7b26\u4e32\u8fdb\u884c\u6307\u5b9a\u884c\u6570\u53d8\u6362\u7684\u51fd\u6570\uff1a

    \n\n
    \nstring convert(string s, int numRows);
    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"PAYPALISHIRING\", numRows = 3\n\u8f93\u51fa\uff1a\"PAHNAPLSIIGYIR\"\n
    \n\u793a\u4f8b 2\uff1a\n\n
    \n\u8f93\u5165\uff1as = \"PAYPALISHIRING\", numRows = 4\n\u8f93\u51fa\uff1a\"PINALSIGYAHRPI\"\n\u89e3\u91ca\uff1a\nP     I    N\nA   L S  I G\nY A   H R\nP     I\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"A\", numRows = 1\n\u8f93\u51fa\uff1a\"A\"\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 1000
    • \n\t
    • s \u7531\u82f1\u6587\u5b57\u6bcd\uff08\u5c0f\u5199\u548c\u5927\u5199\uff09\u3001',' \u548c '.' \u7ec4\u6210
    • \n\t
    • 1 <= numRows <= 1000
    • \n
    \n", "tags_en": ["String"], "tags_cn": ["\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String convert(String s, int numRows) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def convert(self, s, numRows):\n \"\"\"\n :type s: str\n :type numRows: int\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def convert(self, s: str, numRows: int) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * convert(char * s, int numRows){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string Convert(string s, int numRows) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @param {number} numRows\n * @return {string}\n */\nvar convert = function(s, numRows) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @param {Integer} num_rows\n# @return {String}\ndef convert(s, num_rows)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func convert(_ s: String, _ numRows: Int) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func convert(s string, numRows int) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def convert(s: String, numRows: Int): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun convert(s: String, numRows: Int): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn convert(s: String, num_rows: i32) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @param Integer $numRows\n * @return String\n */\n function convert($s, $numRows) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function convert(s: string, numRows: number): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (convert s numRows)\n (-> string? exact-integer? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0006](https://leetcode-cn.com/problems/zigzag-conversion)", "[Z \u5b57\u5f62\u53d8\u6362](/solution/0000-0099/0006.ZigZag%20Conversion/README.md)", "`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0006](https://leetcode.com/problems/zigzag-conversion)", "[ZigZag Conversion](/solution/0000-0099/0006.ZigZag%20Conversion/README_EN.md)", "`String`", "Medium", ""]}, {"question_id": "0005", "frontend_question_id": "0005", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-palindromic-substring", "url_en": "https://leetcode.com/problems/longest-palindromic-substring", "relative_path_cn": "/solution/0000-0099/0005.Longest%20Palindromic%20Substring/README.md", "relative_path_en": "/solution/0000-0099/0005.Longest%20Palindromic%20Substring/README_EN.md", "title_cn": "\u6700\u957f\u56de\u6587\u5b50\u4e32", "title_en": "Longest Palindromic Substring", "question_title_slug": "longest-palindromic-substring", "content_en": "

    Given a string s, return the longest palindromic substring in s.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "babad"\nOutput: "bab"\nNote: "aba" is also a valid answer.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "cbbd"\nOutput: "bb"\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "a"\nOutput: "a"\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = "ac"\nOutput: "a"\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 1 <= s.length <= 1000
    • \n\t
    • s consist of only digits and English letters (lower-case and/or upper-case),
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s\uff0c\u627e\u5230 s \u4e2d\u6700\u957f\u7684\u56de\u6587\u5b50\u4e32\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"babad\"\n\u8f93\u51fa\uff1a\"bab\"\n\u89e3\u91ca\uff1a\"aba\" \u540c\u6837\u662f\u7b26\u5408\u9898\u610f\u7684\u7b54\u6848\u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"cbbd\"\n\u8f93\u51fa\uff1a\"bb\"\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"a\"\n\u8f93\u51fa\uff1a\"a\"\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1as = \"ac\"\n\u8f93\u51fa\uff1a\"a\"\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 1 <= s.length <= 1000
    • \n\t
    • s \u4ec5\u7531\u6570\u5b57\u548c\u82f1\u6587\u5b57\u6bcd\uff08\u5927\u5199\u548c/\u6216\u5c0f\u5199\uff09\u7ec4\u6210
    • \n
    \n", "tags_en": ["String", "Dynamic Programming"], "tags_cn": ["\u5b57\u7b26\u4e32", "\u52a8\u6001\u89c4\u5212"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n string longestPalindrome(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public String longestPalindrome(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def longestPalindrome(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def longestPalindrome(self, s: str) -> str:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nchar * longestPalindrome(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public string LongestPalindrome(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {string}\n */\nvar longestPalindrome = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {String}\ndef longest_palindrome(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func longestPalindrome(_ s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func longestPalindrome(s string) string {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def longestPalindrome(s: String): String = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun longestPalindrome(s: String): String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn longest_palindrome(s: String) -> String {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return String\n */\n function longestPalindrome($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function longestPalindrome(s: string): string {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (longest-palindrome s)\n (-> string? string?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0005](https://leetcode-cn.com/problems/longest-palindromic-substring)", "[\u6700\u957f\u56de\u6587\u5b50\u4e32](/solution/0000-0099/0005.Longest%20Palindromic%20Substring/README.md)", "`\u5b57\u7b26\u4e32`,`\u52a8\u6001\u89c4\u5212`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0005](https://leetcode.com/problems/longest-palindromic-substring)", "[Longest Palindromic Substring](/solution/0000-0099/0005.Longest%20Palindromic%20Substring/README_EN.md)", "`String`,`Dynamic Programming`", "Medium", ""]}, {"question_id": "0004", "frontend_question_id": "0004", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/median-of-two-sorted-arrays", "url_en": "https://leetcode.com/problems/median-of-two-sorted-arrays", "relative_path_cn": "/solution/0000-0099/0004.Median%20of%20Two%20Sorted%20Arrays/README.md", "relative_path_en": "/solution/0000-0099/0004.Median%20of%20Two%20Sorted%20Arrays/README_EN.md", "title_cn": "\u5bfb\u627e\u4e24\u4e2a\u6b63\u5e8f\u6570\u7ec4\u7684\u4e2d\u4f4d\u6570", "title_en": "Median of Two Sorted Arrays", "question_title_slug": "median-of-two-sorted-arrays", "content_en": "

    Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays.

    \n\n

    The overall run time complexity should be O(log (m+n)).

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums1 = [1,3], nums2 = [2]\nOutput: 2.00000\nExplanation: merged array = [1,2,3] and median is 2.\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums1 = [1,2], nums2 = [3,4]\nOutput: 2.50000\nExplanation: merged array = [1,2,3,4] and median is (2 + 3) / 2 = 2.5.\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums1 = [0,0], nums2 = [0,0]\nOutput: 0.00000\n
    \n\n

    Example 4:

    \n\n
    \nInput: nums1 = [], nums2 = [1]\nOutput: 1.00000\n
    \n\n

    Example 5:

    \n\n
    \nInput: nums1 = [2], nums2 = []\nOutput: 2.00000\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • nums1.length == m
    • \n\t
    • nums2.length == n
    • \n\t
    • 0 <= m <= 1000
    • \n\t
    • 0 <= n <= 1000
    • \n\t
    • 1 <= m + n <= 2000
    • \n\t
    • -106 <= nums1[i], nums2[i] <= 106
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e24\u4e2a\u5927\u5c0f\u5206\u522b\u4e3a m \u548c n \u7684\u6b63\u5e8f\uff08\u4ece\u5c0f\u5230\u5927\uff09\u6570\u7ec4\u00a0nums1 \u548c\u00a0nums2\u3002\u8bf7\u4f60\u627e\u51fa\u5e76\u8fd4\u56de\u8fd9\u4e24\u4e2a\u6b63\u5e8f\u6570\u7ec4\u7684 \u4e2d\u4f4d\u6570 \u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums1 = [1,3], nums2 = [2]\n\u8f93\u51fa\uff1a2.00000\n\u89e3\u91ca\uff1a\u5408\u5e76\u6570\u7ec4 = [1,2,3] \uff0c\u4e2d\u4f4d\u6570 2\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums1 = [1,2], nums2 = [3,4]\n\u8f93\u51fa\uff1a2.50000\n\u89e3\u91ca\uff1a\u5408\u5e76\u6570\u7ec4 = [1,2,3,4] \uff0c\u4e2d\u4f4d\u6570 (2 + 3) / 2 = 2.5\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums1 = [0,0], nums2 = [0,0]\n\u8f93\u51fa\uff1a0.00000\n
    \n\n

    \u793a\u4f8b 4\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums1 = [], nums2 = [1]\n\u8f93\u51fa\uff1a1.00000\n
    \n\n

    \u793a\u4f8b 5\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums1 = [2], nums2 = []\n\u8f93\u51fa\uff1a2.00000\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • nums1.length == m
    • \n\t
    • nums2.length == n
    • \n\t
    • 0 <= m <= 1000
    • \n\t
    • 0 <= n <= 1000
    • \n\t
    • 1 <= m + n <= 2000
    • \n\t
    • -106 <= nums1[i], nums2[i] <= 106
    • \n
    \n\n

    \u00a0

    \n\n

    \u8fdb\u9636\uff1a\u4f60\u80fd\u8bbe\u8ba1\u4e00\u4e2a\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(log (m+n)) \u7684\u7b97\u6cd5\u89e3\u51b3\u6b64\u95ee\u9898\u5417\uff1f

    \n", "tags_en": ["Array", "Binary Search", "Divide and Conquer"], "tags_cn": ["\u6570\u7ec4", "\u4e8c\u5206\u67e5\u627e", "\u5206\u6cbb\u7b97\u6cd5"], "difficulty_en": "Hard", "difficulty_cn": "\u56f0\u96be", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n double findMedianSortedArrays(vector& nums1, vector& nums2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public double findMedianSortedArrays(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def findMedianSortedArrays(self, nums1, nums2):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n :rtype: float\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def findMedianSortedArrays(self, nums1: List[int], nums2: List[int]) -> float:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\ndouble findMedianSortedArrays(int* nums1, int nums1Size, int* nums2, int nums2Size){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public double FindMedianSortedArrays(int[] nums1, int[] nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums1\n * @param {number[]} nums2\n * @return {number}\n */\nvar findMedianSortedArrays = function(nums1, nums2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums1\n# @param {Integer[]} nums2\n# @return {Float}\ndef find_median_sorted_arrays(nums1, nums2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func findMedianSortedArrays(_ nums1: [Int], _ nums2: [Int]) -> Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func findMedianSortedArrays(nums1 []int, nums2 []int) float64 {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def findMedianSortedArrays(nums1: Array[Int], nums2: Array[Int]): Double = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun findMedianSortedArrays(nums1: IntArray, nums2: IntArray): Double {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn find_median_sorted_arrays(nums1: Vec, nums2: Vec) -> f64 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums1\n * @param Integer[] $nums2\n * @return Float\n */\n function findMedianSortedArrays($nums1, $nums2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function findMedianSortedArrays(nums1: number[], nums2: number[]): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (find-median-sorted-arrays nums1 nums2)\n (-> (listof exact-integer?) (listof exact-integer?) flonum?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0004](https://leetcode-cn.com/problems/median-of-two-sorted-arrays)", "[\u5bfb\u627e\u4e24\u4e2a\u6b63\u5e8f\u6570\u7ec4\u7684\u4e2d\u4f4d\u6570](/solution/0000-0099/0004.Median%20of%20Two%20Sorted%20Arrays/README.md)", "`\u6570\u7ec4`,`\u4e8c\u5206\u67e5\u627e`,`\u5206\u6cbb\u7b97\u6cd5`", "\u56f0\u96be", ""], "md_table_row_en": ["[0004](https://leetcode.com/problems/median-of-two-sorted-arrays)", "[Median of Two Sorted Arrays](/solution/0000-0099/0004.Median%20of%20Two%20Sorted%20Arrays/README_EN.md)", "`Array`,`Binary Search`,`Divide and Conquer`", "Hard", ""]}, {"question_id": "0003", "frontend_question_id": "0003", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/longest-substring-without-repeating-characters", "url_en": "https://leetcode.com/problems/longest-substring-without-repeating-characters", "relative_path_cn": "/solution/0000-0099/0003.Longest%20Substring%20Without%20Repeating%20Characters/README.md", "relative_path_en": "/solution/0000-0099/0003.Longest%20Substring%20Without%20Repeating%20Characters/README_EN.md", "title_cn": "\u65e0\u91cd\u590d\u5b57\u7b26\u7684\u6700\u957f\u5b50\u4e32", "title_en": "Longest Substring Without Repeating Characters", "question_title_slug": "longest-substring-without-repeating-characters", "content_en": "

    Given a string s, find the length of the longest substring without repeating characters.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: s = "abcabcbb"\nOutput: 3\nExplanation: The answer is "abc", with the length of 3.\n
    \n\n

    Example 2:

    \n\n
    \nInput: s = "bbbbb"\nOutput: 1\nExplanation: The answer is "b", with the length of 1.\n
    \n\n

    Example 3:

    \n\n
    \nInput: s = "pwwkew"\nOutput: 3\nExplanation: The answer is "wke", with the length of 3.\nNotice that the answer must be a substring, "pwke" is a subsequence and not a substring.\n
    \n\n

    Example 4:

    \n\n
    \nInput: s = ""\nOutput: 0\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 0 <= s.length <= 5 * 104
    • \n\t
    • s consists of English letters, digits, symbols and spaces.
    • \n
    \n", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u8bf7\u4f60\u627e\u51fa\u5176\u4e2d\u4e0d\u542b\u6709\u91cd\u590d\u5b57\u7b26\u7684\u00a0\u6700\u957f\u5b50\u4e32\u00a0\u7684\u957f\u5ea6\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b\u00a01:

    \n\n
    \n\u8f93\u5165: s = \"abcabcbb\"\n\u8f93\u51fa: 3 \n\u89e3\u91ca: \u56e0\u4e3a\u65e0\u91cd\u590d\u5b57\u7b26\u7684\u6700\u957f\u5b50\u4e32\u662f \"abc\"\uff0c\u6240\u4ee5\u5176\u957f\u5ea6\u4e3a 3\u3002\n
    \n\n

    \u793a\u4f8b 2:

    \n\n
    \n\u8f93\u5165: s = \"bbbbb\"\n\u8f93\u51fa: 1\n\u89e3\u91ca: \u56e0\u4e3a\u65e0\u91cd\u590d\u5b57\u7b26\u7684\u6700\u957f\u5b50\u4e32\u662f \"b\"\uff0c\u6240\u4ee5\u5176\u957f\u5ea6\u4e3a 1\u3002\n
    \n\n

    \u793a\u4f8b 3:

    \n\n
    \n\u8f93\u5165: s = \"pwwkew\"\n\u8f93\u51fa: 3\n\u89e3\u91ca: \u56e0\u4e3a\u65e0\u91cd\u590d\u5b57\u7b26\u7684\u6700\u957f\u5b50\u4e32\u662f\u00a0\"wke\"\uff0c\u6240\u4ee5\u5176\u957f\u5ea6\u4e3a 3\u3002\n\u00a0    \u8bf7\u6ce8\u610f\uff0c\u4f60\u7684\u7b54\u6848\u5fc5\u987b\u662f \u5b50\u4e32 \u7684\u957f\u5ea6\uff0c\"pwke\"\u00a0\u662f\u4e00\u4e2a\u5b50\u5e8f\u5217\uff0c\u4e0d\u662f\u5b50\u4e32\u3002\n
    \n\n

    \u793a\u4f8b 4:

    \n\n
    \n\u8f93\u5165: s = \"\"\n\u8f93\u51fa: 0\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 0 <= s.length <= 5 * 104
    • \n\t
    • s\u00a0\u7531\u82f1\u6587\u5b57\u6bcd\u3001\u6570\u5b57\u3001\u7b26\u53f7\u548c\u7a7a\u683c\u7ec4\u6210
    • \n
    \n", "tags_en": ["Hash Table", "Two Pointers", "String", "Sliding Window"], "tags_cn": ["\u54c8\u5e0c\u8868", "\u53cc\u6307\u9488", "\u5b57\u7b26\u4e32"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int lengthOfLongestSubstring(String s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def lengthOfLongestSubstring(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def lengthOfLongestSubstring(self, s: str) -> int:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\nint lengthOfLongestSubstring(char * s){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int LengthOfLongestSubstring(string s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {string} s\n * @return {number}\n */\nvar lengthOfLongestSubstring = function(s) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {String} s\n# @return {Integer}\ndef length_of_longest_substring(s)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func lengthOfLongestSubstring(_ s: String) -> Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func lengthOfLongestSubstring(s string) int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def lengthOfLongestSubstring(s: String): Int = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun lengthOfLongestSubstring(s: String): Int {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn length_of_longest_substring(s: String) -> i32 {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function lengthOfLongestSubstring($s) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function lengthOfLongestSubstring(s: string): number {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (length-of-longest-substring s)\n (-> string? exact-integer?)\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0003](https://leetcode-cn.com/problems/longest-substring-without-repeating-characters)", "[\u65e0\u91cd\u590d\u5b57\u7b26\u7684\u6700\u957f\u5b50\u4e32](/solution/0000-0099/0003.Longest%20Substring%20Without%20Repeating%20Characters/README.md)", "`\u54c8\u5e0c\u8868`,`\u53cc\u6307\u9488`,`\u5b57\u7b26\u4e32`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0003](https://leetcode.com/problems/longest-substring-without-repeating-characters)", "[Longest Substring Without Repeating Characters](/solution/0000-0099/0003.Longest%20Substring%20Without%20Repeating%20Characters/README_EN.md)", "`Hash Table`,`Two Pointers`,`String`,`Sliding Window`", "Medium", ""]}, {"question_id": "0002", "frontend_question_id": "0002", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/add-two-numbers", "url_en": "https://leetcode.com/problems/add-two-numbers", "relative_path_cn": "/solution/0000-0099/0002.Add%20Two%20Numbers/README.md", "relative_path_en": "/solution/0000-0099/0002.Add%20Two%20Numbers/README_EN.md", "title_cn": "\u4e24\u6570\u76f8\u52a0", "title_en": "Add Two Numbers", "question_title_slug": "add-two-numbers", "content_en": "

    You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list.

    \n\n

    You may assume the two numbers do not contain any leading zero, except the number 0 itself.

    \n\n

     

    \n

    Example 1:

    \n\"\"\n
    \nInput: l1 = [2,4,3], l2 = [5,6,4]\nOutput: [7,0,8]\nExplanation: 342 + 465 = 807.\n
    \n\n

    Example 2:

    \n\n
    \nInput: l1 = [0], l2 = [0]\nOutput: [0]\n
    \n\n

    Example 3:

    \n\n
    \nInput: l1 = [9,9,9,9,9,9,9], l2 = [9,9,9,9]\nOutput: [8,9,9,9,0,0,0,1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • The number of nodes in each linked list is in the range [1, 100].
    • \n\t
    • 0 <= Node.val <= 9
    • \n\t
    • It is guaranteed that the list represents a number that does not have leading zeros.
    • \n
    \n", "content_cn": "

    \u7ed9\u4f60\u4e24\u4e2a\u00a0\u975e\u7a7a \u7684\u94fe\u8868\uff0c\u8868\u793a\u4e24\u4e2a\u975e\u8d1f\u7684\u6574\u6570\u3002\u5b83\u4eec\u6bcf\u4f4d\u6570\u5b57\u90fd\u662f\u6309\u7167\u00a0\u9006\u5e8f\u00a0\u7684\u65b9\u5f0f\u5b58\u50a8\u7684\uff0c\u5e76\u4e14\u6bcf\u4e2a\u8282\u70b9\u53ea\u80fd\u5b58\u50a8\u00a0\u4e00\u4f4d\u00a0\u6570\u5b57\u3002

    \n\n

    \u8bf7\u4f60\u5c06\u4e24\u4e2a\u6570\u76f8\u52a0\uff0c\u5e76\u4ee5\u76f8\u540c\u5f62\u5f0f\u8fd4\u56de\u4e00\u4e2a\u8868\u793a\u548c\u7684\u94fe\u8868\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u5047\u8bbe\u9664\u4e86\u6570\u5b57 0 \u4e4b\u5916\uff0c\u8fd9\u4e24\u4e2a\u6570\u90fd\u4e0d\u4f1a\u4ee5 0\u00a0\u5f00\u5934\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\"\"\n
    \n\u8f93\u5165\uff1al1 = [2,4,3], l2 = [5,6,4]\n\u8f93\u51fa\uff1a[7,0,8]\n\u89e3\u91ca\uff1a342 + 465 = 807.\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1al1 = [0], l2 = [0]\n\u8f93\u51fa\uff1a[0]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1al1 = [9,9,9,9,9,9,9], l2 = [9,9,9,9]\n\u8f93\u51fa\uff1a[8,9,9,9,0,0,0,1]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • \u6bcf\u4e2a\u94fe\u8868\u4e2d\u7684\u8282\u70b9\u6570\u5728\u8303\u56f4 [1, 100] \u5185
    • \n\t
    • 0 <= Node.val <= 9
    • \n\t
    • \u9898\u76ee\u6570\u636e\u4fdd\u8bc1\u5217\u8868\u8868\u793a\u7684\u6570\u5b57\u4e0d\u542b\u524d\u5bfc\u96f6
    • \n
    \n", "tags_en": ["Recursion", "Linked List", "Math"], "tags_cn": ["\u9012\u5f52", "\u94fe\u8868", "\u6570\u5b66"], "difficulty_en": "Medium", "difficulty_cn": "\u4e2d\u7b49", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n public ListNode addTwoNumbers(ListNode l1, ListNode l2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def addTwoNumbers(self, l1, l2):\n \"\"\"\n :type l1: ListNode\n :type l2: ListNode\n :rtype: ListNode\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * struct ListNode *next;\n * };\n */\n\n\nstruct ListNode* addTwoNumbers(struct ListNode* l1, struct ListNode* l2){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * public ListNode(int val=0, ListNode next=null) {\n * this.val = val;\n * this.next = next;\n * }\n * }\n */\npublic class Solution {\n public ListNode AddTwoNumbers(ListNode l1, ListNode l2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} l1\n * @param {ListNode} l2\n * @return {ListNode}\n */\nvar addTwoNumbers = function(l1, l2) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# Definition for singly-linked list.\n# class ListNode\n# attr_accessor :val, :next\n# def initialize(val = 0, _next = nil)\n# @val = val\n# @next = _next\n# end\n# end\n# @param {ListNode} l1\n# @param {ListNode} l2\n# @return {ListNode}\ndef add_two_numbers(l1, l2)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public var val: Int\n * public var next: ListNode?\n * public init() { self.val = 0; self.next = nil; }\n * public init(_ val: Int) { self.val = val; self.next = nil; }\n * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n func addTwoNumbers(_ l1: ListNode?, _ l2: ListNode?) -> ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "/**\n * Definition for singly-linked list.\n * type ListNode struct {\n * Val int\n * Next *ListNode\n * }\n */\nfunc addTwoNumbers(l1 *ListNode, l2 *ListNode) *ListNode {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "/**\n * Definition for singly-linked list.\n * class ListNode(_x: Int = 0, _next: ListNode = null) {\n * var next: ListNode = _next\n * var x: Int = _x\n * }\n */\nobject Solution {\n def addTwoNumbers(l1: ListNode, l2: ListNode): ListNode = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "/**\n * Example:\n * var li = ListNode(5)\n * var v = li.`val`\n * Definition for singly-linked list.\n * class ListNode(var `val`: Int) {\n * var next: ListNode? = null\n * }\n */\nclass Solution {\n fun addTwoNumbers(l1: ListNode?, l2: ListNode?): ListNode? {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "// Definition for singly-linked list.\n// #[derive(PartialEq, Eq, Clone, Debug)]\n// pub struct ListNode {\n// pub val: i32,\n// pub next: Option>\n// }\n//\n// impl ListNode {\n// #[inline]\n// fn new(val: i32) -> Self {\n// ListNode {\n// next: None,\n// val\n// }\n// }\n// }\nimpl Solution {\n pub fn add_two_numbers(l1: Option>, l2: Option>) -> Option> {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "/**\n * Definition for a singly-linked list.\n * class ListNode {\n * public $val = 0;\n * public $next = null;\n * function __construct($val = 0, $next = null) {\n * $this->val = $val;\n * $this->next = $next;\n * }\n * }\n */\nclass Solution {\n\n /**\n * @param ListNode $l1\n * @param ListNode $l2\n * @return ListNode\n */\n function addTwoNumbers($l1, $l2) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "/**\n * Definition for singly-linked list.\n * class ListNode {\n * val: number\n * next: ListNode | null\n * constructor(val?: number, next?: ListNode | null) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n * }\n */\n\nfunction addTwoNumbers(l1: ListNode | null, l2: ListNode | null): ListNode | null {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "; Definition for singly-linked list:\n#|\n\n; val : integer?\n; next : (or/c list-node? #f)\n(struct list-node\n (val next) #:mutable #:transparent)\n\n; constructor\n(define (make-list-node [val 0])\n (list-node val #f))\n\n|#\n\n(define/contract (add-two-numbers l1 l2)\n (-> (or/c list-node? #f) (or/c list-node? #f) (or/c list-node? #f))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0002](https://leetcode-cn.com/problems/add-two-numbers)", "[\u4e24\u6570\u76f8\u52a0](/solution/0000-0099/0002.Add%20Two%20Numbers/README.md)", "`\u9012\u5f52`,`\u94fe\u8868`,`\u6570\u5b66`", "\u4e2d\u7b49", ""], "md_table_row_en": ["[0002](https://leetcode.com/problems/add-two-numbers)", "[Add Two Numbers](/solution/0000-0099/0002.Add%20Two%20Numbers/README_EN.md)", "`Recursion`,`Linked List`,`Math`", "Medium", ""]}, {"question_id": "0001", "frontend_question_id": "0001", "paid_only": false, "paid_only_cn": false, "url_cn": "https://leetcode-cn.com/problems/two-sum", "url_en": "https://leetcode.com/problems/two-sum", "relative_path_cn": "/solution/0000-0099/0001.Two%20Sum/README.md", "relative_path_en": "/solution/0000-0099/0001.Two%20Sum/README_EN.md", "title_cn": "\u4e24\u6570\u4e4b\u548c", "title_en": "Two Sum", "question_title_slug": "two-sum", "content_en": "

    Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.

    \n\n

    You may assume that each input would have exactly one solution, and you may not use the same element twice.

    \n\n

    You can return the answer in any order.

    \n\n

     

    \n

    Example 1:

    \n\n
    \nInput: nums = [2,7,11,15], target = 9\nOutput: [0,1]\nOutput: Because nums[0] + nums[1] == 9, we return [0, 1].\n
    \n\n

    Example 2:

    \n\n
    \nInput: nums = [3,2,4], target = 6\nOutput: [1,2]\n
    \n\n

    Example 3:

    \n\n
    \nInput: nums = [3,3], target = 6\nOutput: [0,1]\n
    \n\n

     

    \n

    Constraints:

    \n\n
      \n\t
    • 2 <= nums.length <= 104
    • \n\t
    • -109 <= nums[i] <= 109
    • \n\t
    • -109 <= target <= 109
    • \n\t
    • Only one valid answer exists.
    • \n
    \n\n

     

    \nFollow-up: Can you come up with an algorithm that is less than O(n2time complexity?", "content_cn": "

    \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums\u00a0\u548c\u4e00\u4e2a\u6574\u6570\u76ee\u6807\u503c target\uff0c\u8bf7\u4f60\u5728\u8be5\u6570\u7ec4\u4e2d\u627e\u51fa \u548c\u4e3a\u76ee\u6807\u503c target\u00a0 \u7684\u90a3\u00a0\u4e24\u4e2a\u00a0\u6574\u6570\uff0c\u5e76\u8fd4\u56de\u5b83\u4eec\u7684\u6570\u7ec4\u4e0b\u6807\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u5047\u8bbe\u6bcf\u79cd\u8f93\u5165\u53ea\u4f1a\u5bf9\u5e94\u4e00\u4e2a\u7b54\u6848\u3002\u4f46\u662f\uff0c\u6570\u7ec4\u4e2d\u540c\u4e00\u4e2a\u5143\u7d20\u5728\u7b54\u6848\u91cc\u4e0d\u80fd\u91cd\u590d\u51fa\u73b0\u3002

    \n\n

    \u4f60\u53ef\u4ee5\u6309\u4efb\u610f\u987a\u5e8f\u8fd4\u56de\u7b54\u6848\u3002

    \n\n

    \u00a0

    \n\n

    \u793a\u4f8b 1\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [2,7,11,15], target = 9\n\u8f93\u51fa\uff1a[0,1]\n\u89e3\u91ca\uff1a\u56e0\u4e3a nums[0] + nums[1] == 9 \uff0c\u8fd4\u56de [0, 1] \u3002\n
    \n\n

    \u793a\u4f8b 2\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [3,2,4], target = 6\n\u8f93\u51fa\uff1a[1,2]\n
    \n\n

    \u793a\u4f8b 3\uff1a

    \n\n
    \n\u8f93\u5165\uff1anums = [3,3], target = 6\n\u8f93\u51fa\uff1a[0,1]\n
    \n\n

    \u00a0

    \n\n

    \u63d0\u793a\uff1a

    \n\n
      \n\t
    • 2 <= nums.length <= 104
    • \n\t
    • -109 <= nums[i] <= 109
    • \n\t
    • -109 <= target <= 109
    • \n\t
    • \u53ea\u4f1a\u5b58\u5728\u4e00\u4e2a\u6709\u6548\u7b54\u6848
    • \n
    \n\n

    \u8fdb\u9636\uff1a\u4f60\u53ef\u4ee5\u60f3\u51fa\u4e00\u4e2a\u65f6\u95f4\u590d\u6742\u5ea6\u5c0f\u4e8e O(n2) \u7684\u7b97\u6cd5\u5417\uff1f

    \n", "tags_en": ["Array", "Hash Table"], "tags_cn": ["\u6570\u7ec4", "\u54c8\u5e0c\u8868"], "difficulty_en": "Easy", "difficulty_cn": "\u7b80\u5355", "code_snippets": [{"lang": "C++", "langSlug": "cpp", "code": "class Solution {\npublic:\n vector twoSum(vector& nums, int target) {\n\n }\n};", "__typename": "CodeSnippetNode"}, {"lang": "Java", "langSlug": "java", "code": "class Solution {\n public int[] twoSum(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Python", "langSlug": "python", "code": "class Solution(object):\n def twoSum(self, nums, target):\n \"\"\"\n :type nums: List[int]\n :type target: int\n :rtype: List[int]\n \"\"\"", "__typename": "CodeSnippetNode"}, {"lang": "Python3", "langSlug": "python3", "code": "class Solution:\n def twoSum(self, nums: List[int], target: int) -> List[int]:", "__typename": "CodeSnippetNode"}, {"lang": "C", "langSlug": "c", "code": "\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* twoSum(int* nums, int numsSize, int target, int* returnSize){\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "C#", "langSlug": "csharp", "code": "public class Solution {\n public int[] TwoSum(int[] nums, int target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {number[]} nums\n * @param {number} target\n * @return {number[]}\n */\nvar twoSum = function(nums, target) {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Ruby", "langSlug": "ruby", "code": "# @param {Integer[]} nums\n# @param {Integer} target\n# @return {Integer[]}\ndef two_sum(nums, target)\n\nend", "__typename": "CodeSnippetNode"}, {"lang": "Swift", "langSlug": "swift", "code": "class Solution {\n func twoSum(_ nums: [Int], _ target: Int) -> [Int] {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Go", "langSlug": "golang", "code": "func twoSum(nums []int, target int) []int {\n\n}", "__typename": "CodeSnippetNode"}, {"lang": "Scala", "langSlug": "scala", "code": "object Solution {\n def twoSum(nums: Array[Int], target: Int): Array[Int] = {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Kotlin", "langSlug": "kotlin", "code": "class Solution {\n fun twoSum(nums: IntArray, target: Int): IntArray {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "Rust", "langSlug": "rust", "code": "impl Solution {\n pub fn two_sum(nums: Vec, target: i32) -> Vec {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "PHP", "langSlug": "php", "code": "class Solution {\n\n /**\n * @param Integer[] $nums\n * @param Integer $target\n * @return Integer[]\n */\n function twoSum($nums, $target) {\n\n }\n}", "__typename": "CodeSnippetNode"}, {"lang": "TypeScript", "langSlug": "typescript", "code": "function twoSum(nums: number[], target: number): number[] {\n\n};", "__typename": "CodeSnippetNode"}, {"lang": "Racket", "langSlug": "racket", "code": "(define/contract (two-sum nums target)\n (-> (listof exact-integer?) exact-integer? (listof exact-integer?))\n\n )", "__typename": "CodeSnippetNode"}], "md_table_row_cn": ["[0001](https://leetcode-cn.com/problems/two-sum)", "[\u4e24\u6570\u4e4b\u548c](/solution/0000-0099/0001.Two%20Sum/README.md)", "`\u6570\u7ec4`,`\u54c8\u5e0c\u8868`", "\u7b80\u5355", ""], "md_table_row_en": ["[0001](https://leetcode.com/problems/two-sum)", "[Two Sum](/solution/0000-0099/0001.Two%20Sum/README_EN.md)", "`Array`,`Hash Table`", "Easy", ""]}] \ No newline at end of file diff --git a/solution/summary.md b/solution/summary.md index 3b8614592d0e9..0d1315619684c 100644 --- a/solution/summary.md +++ b/solution/summary.md @@ -1920,3 +1920,7 @@ - [1882.Process Tasks Using Servers](/solution/1800-1899/1882.Process%20Tasks%20Using%20Servers/README.md) - [1883.Minimum Skips to Arrive at Meeting On Time](/solution/1800-1899/1883.Minimum%20Skips%20to%20Arrive%20at%20Meeting%20On%20Time/README.md) - [1884.Egg Drop With 2 Eggs and N Floors](/solution/1800-1899/1884.Egg%20Drop%20With%202%20Eggs%20and%20N%20Floors/README.md) + - [1886.Determine Whether Matrix Can Be Obtained By Rotation](/solution/1800-1899/1886.Determine%20Whether%20Matrix%20Can%20Be%20Obtained%20By%20Rotation/README.md) + - [1887.Reduction Operations to Make the Array Elements Equal](/solution/1800-1899/1887.Reduction%20Operations%20to%20Make%20the%20Array%20Elements%20Equal/README.md) + - [1888.Minimum Number of Flips to Make the Binary String Alternating](/solution/1800-1899/1888.Minimum%20Number%20of%20Flips%20to%20Make%20the%20Binary%20String%20Alternating/README.md) + - [1889.Minimum Space Wasted From Packaging](/solution/1800-1899/1889.Minimum%20Space%20Wasted%20From%20Packaging/README.md) diff --git a/solution/summary_en.md b/solution/summary_en.md index e48753c40e158..f8fe6c15a2327 100644 --- a/solution/summary_en.md +++ b/solution/summary_en.md @@ -1920,3 +1920,7 @@ - [1882.Process Tasks Using Servers](/solution/1800-1899/1882.Process%20Tasks%20Using%20Servers/README_EN.md) - [1883.Minimum Skips to Arrive at Meeting On Time](/solution/1800-1899/1883.Minimum%20Skips%20to%20Arrive%20at%20Meeting%20On%20Time/README_EN.md) - [1884.Egg Drop With 2 Eggs and N Floors](/solution/1800-1899/1884.Egg%20Drop%20With%202%20Eggs%20and%20N%20Floors/README_EN.md) + - [1886.Determine Whether Matrix Can Be Obtained By Rotation](/solution/1800-1899/1886.Determine%20Whether%20Matrix%20Can%20Be%20Obtained%20By%20Rotation/README_EN.md) + - [1887.Reduction Operations to Make the Array Elements Equal](/solution/1800-1899/1887.Reduction%20Operations%20to%20Make%20the%20Array%20Elements%20Equal/README_EN.md) + - [1888.Minimum Number of Flips to Make the Binary String Alternating](/solution/1800-1899/1888.Minimum%20Number%20of%20Flips%20to%20Make%20the%20Binary%20String%20Alternating/README_EN.md) + - [1889.Minimum Space Wasted From Packaging](/solution/1800-1899/1889.Minimum%20Space%20Wasted%20From%20Packaging/README_EN.md)